2 * Linux Ethernet device driver for the 3Com Etherlink Plus (3C505)
3 * By Craig Southeren, Juha Laiho and Philip Blundell
5 * 3c505.c This module implements an interface to the 3Com
6 * Etherlink Plus (3c505) Ethernet card. Linux device
7 * driver interface reverse engineered from the Linux 3C509
8 * device drivers. Some 3C505 information gleaned from
9 * the Crynwr packet driver. Still this driver would not
10 * be here without 3C505 technical reference provided by
13 * $Id: 3c505.c,v 1.10 1996/04/16 13:06:27 phil Exp $
15 * Authors: Linux 3c505 device driver by
16 * Craig Southeren, <craigs@ineluki.apana.org.au>
18 * Andrew Tridgell, <tridge@nimbus.anu.edu.au>
19 * Auto irq/address, tuning, cleanup and v1.1.4+ kernel mods by
20 * Juha Laiho, <jlaiho@ichaos.nullnet.fi>
21 * Linux 3C509 driver by
22 * Donald Becker, <becker@super.org>
23 * Crynwr packet driver by
24 * Krishnan Gopalan and Gregg Stefancik,
25 * Clemson University Engineering Computer Operations.
26 * Portions of the code have been adapted from the 3c505
27 * driver for NCSA Telnet by Bruce Orchard and later
28 * modified by Warren Van Houten and krus@diku.dk.
29 * 3C505 technical information provided by
30 * Terry Murphy, of 3Com Network Adapter Division
31 * Linux 1.3.0 changes by
32 * Alan Cox <Alan.Cox@linux.org>
33 * More debugging, DMA support, currently maintained by
34 * Philip Blundell <Philip.Blundell@pobox.com>
35 * Multicard/soft configurable dma channel/rev 2 hardware support
36 * by Christopher Collins <ccollins@pcug.org.au>
39 /* Theory of operation:
41 * The 3c505 is quite an intelligent board. All communication with it is done
42 * by means of Primary Command Blocks (PCBs); these are transferred using PIO
43 * through the command register. The card has 256k of on-board RAM, which is
44 * used to buffer received packets. It might seem at first that more buffers
45 * are better, but in fact this isn't true. From my tests, it seems that
46 * more than about 10 buffers are unnecessary, and there is a noticeable
47 * performance hit in having more active on the card. So the majority of the
48 * card's memory isn't, in fact, used. Sadly, the card only has one transmit
49 * buffer and, short of loading our own firmware into it (which is what some
50 * drivers resort to) there's nothing we can do about this.
52 * We keep up to 4 "receive packet" commands active on the board at a time.
53 * When a packet comes in, so long as there is a receive command active, the
54 * board will send us a "packet received" PCB and then add the data for that
55 * packet to the DMA queue. If a DMA transfer is not already in progress, we
56 * set one up to start uploading the data. We have to maintain a list of
57 * backlogged receive packets, because the card may decide to tell us about
58 * a newly-arrived packet at any time, and we may not be able to start a DMA
59 * transfer immediately (ie one may already be going on). We can't NAK the
60 * PCB, because then it would throw the packet away.
62 * Trying to send a PCB to the card at the wrong moment seems to have bad
63 * effects. If we send it a transmit PCB while a receive DMA is happening,
64 * it will just NAK the PCB and so we will have wasted our time. Worse, it
65 * sometimes seems to interrupt the transfer. The majority of the low-level
66 * code is protected by one huge semaphore -- "busy" -- which is set whenever
67 * it probably isn't safe to do anything to the card. The receive routine
68 * must gain a lock on "busy" before it can start a DMA transfer, and the
69 * transmit routine must gain a lock before it sends the first PCB to the card.
70 * The send_pcb() routine also has an internal semaphore to protect it against
71 * being re-entered (which would be disastrous) -- this is needed because
72 * several things can happen asynchronously (re-priming the receiver and
73 * asking the card for statistics, for example). send_pcb() will also refuse
74 * to talk to the card at all if a DMA upload is happening. The higher-level
75 * networking code will reschedule a later retry if some part of the driver
76 * is blocked. In practice, this doesn't seem to happen very often.
79 /* This driver may now work with revision 2.x hardware, since all the read
80 * operations on the HCR have been removed (we now keep our own softcopy).
81 * But I don't have an old card to test it on.
83 * This has had the bad effect that the autoprobe routine is now a bit
84 * less friendly to other devices. However, it was never very good.
85 * before, so I doubt it will hurt anybody.
88 /* The driver is a mess. I took Craig's and Juha's code, and hacked it firstly
89 * to make it more reliable, and secondly to add DMA mode. Many things could
90 * probably be done better; the concurrency protection is particularly awful.
93 #include <linux/module.h>
95 #include <linux/kernel.h>
96 #include <linux/sched.h>
97 #include <linux/string.h>
98 #include <linux/interrupt.h>
99 #include <linux/ptrace.h>
100 #include <linux/errno.h>
101 #include <linux/in.h>
102 #include <linux/malloc.h>
103 #include <linux/ioport.h>
104 #include <asm/bitops.h>
108 #include <linux/netdevice.h>
109 #include <linux/etherdevice.h>
110 #include <linux/skbuff.h>
111 #include <linux/init.h>
115 /*********************************************************
117 * define debug messages here as common strings to reduce space
119 *********************************************************/
121 static const char *filename
= __FILE__
;
123 static const char *timeout_msg
= "*** timeout at %s:%s (line %d) ***\n";
124 #define TIMEOUT_MSG(lineno) \
125 printk(timeout_msg, filename,__FUNCTION__,(lineno))
127 static const char *invalid_pcb_msg
=
128 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
129 #define INVALID_PCB_MSG(len) \
130 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
132 static const char *search_msg
= "%s: Looking for 3c505 adapter at address %#x...";
134 static const char *stilllooking_msg
= "still looking...";
136 static const char *found_msg
= "found.\n";
138 static const char *notfound_msg
= "not found (reason = %d)\n";
140 static const char *couldnot_msg
= "%s: 3c505 not found\n";
142 /*********************************************************
144 * various other debug stuff
146 *********************************************************/
149 static const int elp_debug
= ELP_DEBUG
;
151 static const int elp_debug
= 0;
155 * 0 = no messages (well, some)
156 * 1 = messages when high level commands performed
157 * 2 = messages when low level commands performed
158 * 3 = messages when interrupts received
161 /*****************************************************************
165 *****************************************************************/
176 /*****************************************************************
178 * List of I/O-addresses we try to auto-sense
179 * Last element MUST BE 0!
180 *****************************************************************/
182 static const int addr_list
[] __initdata
= {0x300, 0x280, 0x310, 0};
184 /* Dma Memory related stuff */
186 /* Pure 2^n version of get_order */
187 static inline int __get_order(unsigned long size
)
191 size
= (size
- 1) >> (PAGE_SHIFT
- 1);
200 static unsigned long dma_mem_alloc(int size
)
202 int order
= __get_order(size
);
204 return __get_dma_pages(GFP_KERNEL
, order
);
208 /*****************************************************************
210 * Functions for I/O (note the inline !)
212 *****************************************************************/
214 static inline unsigned char inb_status(unsigned int base_addr
)
216 return inb(base_addr
+ PORT_STATUS
);
219 static inline int inb_command(unsigned int base_addr
)
221 return inb(base_addr
+ PORT_COMMAND
);
224 static inline void outb_control(unsigned char val
, struct net_device
*dev
)
226 outb(val
, dev
->base_addr
+ PORT_CONTROL
);
227 ((elp_device
*)(dev
->priv
))->hcr_val
= val
;
230 #define HCR_VAL(x) (((elp_device *)((x)->priv))->hcr_val)
232 static inline void outb_command(unsigned char val
, unsigned int base_addr
)
234 outb(val
, base_addr
+ PORT_COMMAND
);
237 static inline unsigned int inw_data(unsigned int base_addr
)
239 return inw(base_addr
+ PORT_DATA
);
242 static inline void outw_data(unsigned int val
, unsigned int base_addr
)
244 outw(val
, base_addr
+ PORT_DATA
);
247 static inline unsigned int backlog_next(unsigned int n
)
249 return (n
+ 1) % BACKLOG_SIZE
;
252 /*****************************************************************
254 * useful functions for accessing the adapter
256 *****************************************************************/
259 * use this routine when accessing the ASF bits as they are
260 * changed asynchronously by the adapter
263 /* get adapter PCB status */
264 #define GET_ASF(addr) \
265 (get_status(addr)&ASF_PCB_MASK)
267 static inline int get_status(unsigned int base_addr
)
269 int timeout
= jiffies
+ 10*HZ
/100;
272 stat1
= inb_status(base_addr
);
273 } while (stat1
!= inb_status(base_addr
) && time_before(jiffies
, timeout
));
274 if (time_after_eq(jiffies
, timeout
))
275 TIMEOUT_MSG(__LINE__
);
279 static inline void set_hsf(struct net_device
*dev
, int hsf
)
282 outb_control((HCR_VAL(dev
) & ~HSF_PCB_MASK
) | hsf
, dev
);
286 static int start_receive(struct net_device
*, pcb_struct
*);
288 inline static void adapter_reset(struct net_device
*dev
)
291 elp_device
*adapter
= dev
->priv
;
292 unsigned char orig_hcr
= adapter
->hcr_val
;
294 outb_control(0, dev
);
296 if (inb_status(dev
->base_addr
) & ACRF
) {
298 inb_command(dev
->base_addr
);
299 timeout
= jiffies
+ 2*HZ
/100;
300 while (time_before_eq(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & ACRF
));
301 } while (inb_status(dev
->base_addr
) & ACRF
);
302 set_hsf(dev
, HSF_PCB_NAK
);
304 outb_control(adapter
->hcr_val
| ATTN
| DIR, dev
);
305 timeout
= jiffies
+ 1*HZ
/100;
306 while (time_before_eq(jiffies
, timeout
));
307 outb_control(adapter
->hcr_val
& ~ATTN
, dev
);
308 timeout
= jiffies
+ 1*HZ
/100;
309 while (time_before_eq(jiffies
, timeout
));
310 outb_control(adapter
->hcr_val
| FLSH
, dev
);
311 timeout
= jiffies
+ 1*HZ
/100;
312 while (time_before_eq(jiffies
, timeout
));
313 outb_control(adapter
->hcr_val
& ~FLSH
, dev
);
314 timeout
= jiffies
+ 1*HZ
/100;
315 while (time_before_eq(jiffies
, timeout
));
317 outb_control(orig_hcr
, dev
);
318 if (!start_receive(dev
, &adapter
->tx_pcb
))
319 printk("%s: start receive command failed \n", dev
->name
);
322 /* Check to make sure that a DMA transfer hasn't timed out. This should
323 * never happen in theory, but seems to occur occasionally if the card gets
324 * prodded at the wrong time.
326 static inline void check_3c505_dma(struct net_device
*dev
)
328 elp_device
*adapter
= dev
->priv
;
329 if (adapter
->dmaing
&& time_after(jiffies
, adapter
->current_dma
.start_time
+ 10)) {
330 unsigned long flags
, f
;
331 printk("%s: DMA %s timed out, %d bytes left\n", dev
->name
, adapter
->current_dma
.direction
? "download" : "upload", get_dma_residue(dev
->dma
));
338 disable_dma(dev
->dma
);
341 if (adapter
->rx_active
)
342 adapter
->rx_active
--;
343 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
344 restore_flags(flags
);
348 /* Primitive functions used by send_pcb() */
349 static inline unsigned int send_pcb_slow(unsigned int base_addr
, unsigned char byte
)
351 unsigned int timeout
;
352 outb_command(byte
, base_addr
);
353 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
354 if (inb_status(base_addr
) & HCRE
)
357 printk("3c505: send_pcb_slow timed out\n");
361 static inline unsigned int send_pcb_fast(unsigned int base_addr
, unsigned char byte
)
363 unsigned int timeout
;
364 outb_command(byte
, base_addr
);
365 for (timeout
= 0; timeout
< 40000; timeout
++) {
366 if (inb_status(base_addr
) & HCRE
)
369 printk("3c505: send_pcb_fast timed out\n");
373 /* Check to see if the receiver needs restarting, and kick it if so */
374 static inline void prime_rx(struct net_device
*dev
)
376 elp_device
*adapter
= dev
->priv
;
377 while (adapter
->rx_active
< ELP_RX_PCBS
&& dev
->start
) {
378 if (!start_receive(dev
, &adapter
->itx_pcb
))
383 /*****************************************************************
386 * Send a PCB to the adapter.
388 * output byte to command reg --<--+
389 * wait until HCRE is non zero |
390 * loop until all bytes sent -->--+
391 * set HSF1 and HSF2 to 1
393 * wait until ASF give ACK or NAK
394 * set HSF1 and HSF2 to 0
396 *****************************************************************/
398 /* This can be quite slow -- the adapter is allowed to take up to 40ms
399 * to respond to the initial interrupt.
401 * We run initially with interrupts turned on, but with a semaphore set
402 * so that nobody tries to re-enter this code. Once the first byte has
403 * gone through, we turn interrupts off and then send the others (the
404 * timeout is reduced to 500us).
407 static int send_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
411 elp_device
*adapter
= dev
->priv
;
413 check_3c505_dma(dev
);
415 if (adapter
->dmaing
&& adapter
->current_dma
.direction
== 0)
418 /* Avoid contention */
419 if (test_and_set_bit(1, &adapter
->send_pcb_semaphore
)) {
420 if (elp_debug
>= 3) {
421 printk("%s: send_pcb entered while threaded\n", dev
->name
);
426 * load each byte into the command register and
427 * wait for the HCRE bit to indicate the adapter
432 if (send_pcb_slow(dev
->base_addr
, pcb
->command
))
437 if (send_pcb_fast(dev
->base_addr
, pcb
->length
))
440 for (i
= 0; i
< pcb
->length
; i
++) {
441 if (send_pcb_fast(dev
->base_addr
, pcb
->data
.raw
[i
]))
445 outb_control(adapter
->hcr_val
| 3, dev
); /* signal end of PCB */
446 outb_command(2 + pcb
->length
, dev
->base_addr
);
448 /* now wait for the acknowledgement */
451 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
452 switch (GET_ASF(dev
->base_addr
)) {
454 adapter
->send_pcb_semaphore
= 0;
459 printk(KERN_DEBUG
"%s: send_pcb got NAK\n", dev
->name
);
467 printk("%s: timeout waiting for PCB acknowledge (status %02x)\n", dev
->name
, inb_status(dev
->base_addr
));
472 adapter
->send_pcb_semaphore
= 0;
477 /*****************************************************************
480 * Read a PCB from the adapter
482 * wait for ACRF to be non-zero ---<---+
484 * if ASF1 and ASF2 were not both one |
485 * before byte was read, loop --->---+
486 * set HSF1 and HSF2 for ack
488 *****************************************************************/
490 static int receive_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
497 elp_device
*adapter
= dev
->priv
;
501 /* get the command code */
502 timeout
= jiffies
+ 2*HZ
/100;
503 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
504 if (time_after_eq(jiffies
, timeout
)) {
505 TIMEOUT_MSG(__LINE__
);
508 pcb
->command
= inb_command(dev
->base_addr
);
510 /* read the data length */
511 timeout
= jiffies
+ 3*HZ
/100;
512 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
513 if (time_after_eq(jiffies
, timeout
)) {
514 TIMEOUT_MSG(__LINE__
);
515 printk("%s: status %02x\n", dev
->name
, stat
);
518 pcb
->length
= inb_command(dev
->base_addr
);
520 if (pcb
->length
> MAX_PCB_DATA
) {
521 INVALID_PCB_MSG(pcb
->length
);
530 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && j
++ < 20000);
531 pcb
->data
.raw
[i
++] = inb_command(dev
->base_addr
);
532 if (i
> MAX_PCB_DATA
)
534 } while ((stat
& ASF_PCB_MASK
) != ASF_PCB_END
&& j
< 20000);
537 TIMEOUT_MSG(__LINE__
);
540 /* woops, the last "data" byte was really the length! */
541 total_length
= pcb
->data
.raw
[--i
];
543 /* safety check total length vs data length */
544 if (total_length
!= (pcb
->length
+ 2)) {
546 printk("%s: mangled PCB received\n", dev
->name
);
547 set_hsf(dev
, HSF_PCB_NAK
);
551 if (pcb
->command
== CMD_RECEIVE_PACKET_COMPLETE
) {
552 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
553 if (backlog_next(adapter
->rx_backlog
.in
) == adapter
->rx_backlog
.out
) {
554 set_hsf(dev
, HSF_PCB_NAK
);
555 printk("%s: PCB rejected, transfer in progress and backlog full\n", dev
->name
);
563 set_hsf(dev
, HSF_PCB_ACK
);
567 /******************************************************
569 * queue a receive command on the adapter so we will get an
570 * interrupt when a packet is received.
572 ******************************************************/
574 static int start_receive(struct net_device
*dev
, pcb_struct
* tx_pcb
)
577 elp_device
*adapter
= dev
->priv
;
580 printk("%s: restarting receiver\n", dev
->name
);
581 tx_pcb
->command
= CMD_RECEIVE_PACKET
;
582 tx_pcb
->length
= sizeof(struct Rcv_pkt
);
583 tx_pcb
->data
.rcv_pkt
.buf_seg
584 = tx_pcb
->data
.rcv_pkt
.buf_ofs
= 0; /* Unused */
585 tx_pcb
->data
.rcv_pkt
.buf_len
= 1600;
586 tx_pcb
->data
.rcv_pkt
.timeout
= 0; /* set timeout to zero */
587 status
= send_pcb(dev
, tx_pcb
);
589 adapter
->rx_active
++;
593 /******************************************************
595 * extract a packet from the adapter
596 * this routine is only called from within the interrupt
597 * service routine, so no cli/sti calls are needed
598 * note that the length is always assumed to be even
600 ******************************************************/
602 static void receive_packet(struct net_device
*dev
, int len
)
605 elp_device
*adapter
= dev
->priv
;
610 rlen
= (len
+ 1) & ~1;
611 skb
= dev_alloc_skb(rlen
+ 2);
614 printk("%s: memory squeeze, dropping packet\n", dev
->name
);
615 target
= adapter
->dma_buffer
;
616 adapter
->current_dma
.target
= NULL
;
619 target
= skb_put(skb
, rlen
);
620 if (virt_to_bus(target
+ rlen
) >= MAX_DMA_ADDRESS
) {
621 adapter
->current_dma
.target
= target
;
622 target
= adapter
->dma_buffer
;
624 adapter
->current_dma
.target
= NULL
;
628 /* if this happens, we die */
629 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
630 printk("%s: rx blocked, DMA in progress, dir %d\n", dev
->name
, adapter
->current_dma
.direction
);
633 adapter
->current_dma
.direction
= 0;
634 adapter
->current_dma
.length
= rlen
;
635 adapter
->current_dma
.skb
= skb
;
636 adapter
->current_dma
.start_time
= jiffies
;
638 outb_control(adapter
->hcr_val
| DIR | TCEN
| DMAE
, dev
);
640 flags
=claim_dma_lock();
641 disable_dma(dev
->dma
);
642 clear_dma_ff(dev
->dma
);
643 set_dma_mode(dev
->dma
, 0x04); /* dma read */
644 set_dma_addr(dev
->dma
, virt_to_bus(target
));
645 set_dma_count(dev
->dma
, rlen
);
646 enable_dma(dev
->dma
);
647 release_dma_lock(flags
);
649 if (elp_debug
>= 3) {
650 printk("%s: rx DMA transfer started\n", dev
->name
);
653 if (adapter
->rx_active
)
654 adapter
->rx_active
--;
657 printk("%s: receive_packet called, busy not set.\n", dev
->name
);
660 /******************************************************
664 ******************************************************/
666 static void elp_interrupt(int irq
, void *dev_id
, struct pt_regs
*reg_ptr
)
671 struct net_device
*dev
;
675 if (irq
< 0 || irq
> 15) {
676 printk("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq
);
682 printk("elp_interrupt(): irq %d for unknown device.\n", irq
);
685 adapter
= (elp_device
*) dev
->priv
;
687 if (dev
->interrupt
) {
688 printk("%s: re-entering the interrupt handler!\n", dev
->name
);
695 * has a DMA transfer finished?
697 if (inb_status(dev
->base_addr
) & DONE
) {
698 if (!adapter
->dmaing
) {
699 printk("%s: phantom DMA completed\n", dev
->name
);
701 if (elp_debug
>= 3) {
702 printk("%s: %s DMA complete, status %02x\n", dev
->name
, adapter
->current_dma
.direction
? "tx" : "rx", inb_status(dev
->base_addr
));
705 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR),
707 if (adapter
->current_dma
.direction
) {
708 dev_kfree_skb(adapter
->current_dma
.skb
);
710 struct sk_buff
*skb
= adapter
->current_dma
.skb
;
712 if (adapter
->current_dma
.target
) {
713 /* have already done the skb_put() */
714 memcpy(adapter
->current_dma
.target
, adapter
->dma_buffer
, adapter
->current_dma
.length
);
716 skb
->protocol
= eth_type_trans(skb
,dev
);
717 adapter
->stats
.rx_bytes
+= skb
->len
;
722 if (adapter
->rx_backlog
.in
!= adapter
->rx_backlog
.out
) {
723 int t
= adapter
->rx_backlog
.length
[adapter
->rx_backlog
.out
];
724 adapter
->rx_backlog
.out
= backlog_next(adapter
->rx_backlog
.out
);
726 printk("%s: receiving backlogged packet (%d)\n", dev
->name
, t
);
727 receive_packet(dev
, t
);
732 /* has one timed out? */
733 check_3c505_dma(dev
);
739 * receive a PCB from the adapter
741 timeout
= jiffies
+ 3*HZ
/100;
742 while ((inb_status(dev
->base_addr
) & ACRF
) != 0 && time_before(jiffies
, timeout
)) {
743 if (receive_pcb(dev
, &adapter
->irx_pcb
)) {
744 switch (adapter
->irx_pcb
.command
) {
748 * received a packet - this must be handled fast
751 case CMD_RECEIVE_PACKET_COMPLETE
:
752 /* if the device isn't open, don't pass packets up the stack */
756 len
= adapter
->irx_pcb
.data
.rcv_resp
.pkt_len
;
757 dlen
= adapter
->irx_pcb
.data
.rcv_resp
.buf_len
;
758 if (adapter
->irx_pcb
.data
.rcv_resp
.timeout
!= 0) {
759 printk("%s: interrupt - packet not received correctly\n", dev
->name
);
762 if (elp_debug
>= 3) {
764 printk("%s: interrupt - packet received of length %i (%i)\n", dev
->name
, len
, dlen
);
767 if (adapter
->irx_pcb
.command
== 0xff) {
769 printk("%s: adding packet to backlog (len = %d)\n", dev
->name
, dlen
);
770 adapter
->rx_backlog
.length
[adapter
->rx_backlog
.in
] = dlen
;
771 adapter
->rx_backlog
.in
= backlog_next(adapter
->rx_backlog
.in
);
773 receive_packet(dev
, dlen
);
777 printk("%s: packet received\n", dev
->name
);
782 * 82586 configured correctly
784 case CMD_CONFIGURE_82586_RESPONSE
:
785 adapter
->got
[CMD_CONFIGURE_82586
] = 1;
787 printk("%s: interrupt - configure response received\n", dev
->name
);
791 * Adapter memory configuration
793 case CMD_CONFIGURE_ADAPTER_RESPONSE
:
794 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 1;
796 printk("%s: Adapter memory configuration %s.\n", dev
->name
,
797 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
801 * Multicast list loading
803 case CMD_LOAD_MULTICAST_RESPONSE
:
804 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 1;
806 printk("%s: Multicast address list loading %s.\n", dev
->name
,
807 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
811 * Station address setting
813 case CMD_SET_ADDRESS_RESPONSE
:
814 adapter
->got
[CMD_SET_STATION_ADDRESS
] = 1;
816 printk("%s: Ethernet address setting %s.\n", dev
->name
,
817 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
822 * received board statistics
824 case CMD_NETWORK_STATISTICS_RESPONSE
:
825 adapter
->stats
.rx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_recv
;
826 adapter
->stats
.tx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_xmit
;
827 adapter
->stats
.rx_crc_errors
+= adapter
->irx_pcb
.data
.netstat
.err_CRC
;
828 adapter
->stats
.rx_frame_errors
+= adapter
->irx_pcb
.data
.netstat
.err_align
;
829 adapter
->stats
.rx_fifo_errors
+= adapter
->irx_pcb
.data
.netstat
.err_ovrrun
;
830 adapter
->stats
.rx_over_errors
+= adapter
->irx_pcb
.data
.netstat
.err_res
;
831 adapter
->got
[CMD_NETWORK_STATISTICS
] = 1;
833 printk("%s: interrupt - statistics response received\n", dev
->name
);
839 case CMD_TRANSMIT_PACKET_COMPLETE
:
841 printk("%s: interrupt - packet sent\n", dev
->name
);
844 switch (adapter
->irx_pcb
.data
.xmit_resp
.c_stat
) {
846 adapter
->stats
.tx_aborted_errors
++;
847 printk(KERN_INFO
"%s: transmit timed out, network cable problem?\n", dev
->name
);
850 adapter
->stats
.tx_fifo_errors
++;
851 printk(KERN_INFO
"%s: transmit timed out, FIFO underrun\n", dev
->name
);
862 printk(KERN_DEBUG
"%s: unknown PCB received - %2.2x\n", dev
->name
, adapter
->irx_pcb
.command
);
866 printk("%s: failed to read PCB on interrupt\n", dev
->name
);
871 } while (icount
++ < 5 && (inb_status(dev
->base_addr
) & (ACRF
| DONE
)));
876 * indicate no longer in interrupt routine
882 /******************************************************
886 ******************************************************/
888 static int elp_open(struct net_device
*dev
)
895 printk("%s: request to open device\n", dev
->name
);
898 * make sure we actually found the device
900 if (adapter
== NULL
) {
901 printk("%s: Opening a non-existent physical device\n", dev
->name
);
905 * disable interrupts on the board
907 outb_control(0, dev
);
910 * clear any pending interrupts
912 inb_command(dev
->base_addr
);
916 * interrupt routine not entered
921 * transmitter not busy
926 * no receive PCBs active
928 adapter
->rx_active
= 0;
931 adapter
->send_pcb_semaphore
= 0;
932 adapter
->rx_backlog
.in
= 0;
933 adapter
->rx_backlog
.out
= 0;
936 * install our interrupt service routine
938 if (request_irq(dev
->irq
, &elp_interrupt
, 0, "3c505", dev
)) {
941 if (request_dma(dev
->dma
, "3c505")) {
942 printk("%s: could not allocate DMA channel\n", dev
->name
);
945 adapter
->dma_buffer
= (void *) dma_mem_alloc(DMA_BUFFER_SIZE
);
946 if (!adapter
->dma_buffer
) {
947 printk("Could not allocate DMA buffer\n");
952 * enable interrupts on the board
954 outb_control(CMDE
, dev
);
957 * configure adapter memory: we need 10 multicast addresses, default==0
960 printk("%s: sending 3c505 memory configuration command\n", dev
->name
);
961 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
962 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 10;
963 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 20;
964 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
965 adapter
->tx_pcb
.data
.memconf
.frame
= 20;
966 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 20;
967 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
968 adapter
->tx_pcb
.length
= sizeof(struct Memconf
);
969 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 0;
970 if (!send_pcb(dev
, &adapter
->tx_pcb
))
971 printk("%s: couldn't send memory configuration command\n", dev
->name
);
973 int timeout
= jiffies
+ TIMEOUT
;
974 while (adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] == 0 && time_before(jiffies
, timeout
));
975 if (time_after_eq(jiffies
, timeout
))
976 TIMEOUT_MSG(__LINE__
);
981 * configure adapter to receive broadcast messages and wait for response
984 printk("%s: sending 82586 configure command\n", dev
->name
);
985 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
986 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
987 adapter
->tx_pcb
.length
= 2;
988 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
989 if (!send_pcb(dev
, &adapter
->tx_pcb
))
990 printk("%s: couldn't send 82586 configure command\n", dev
->name
);
992 int timeout
= jiffies
+ TIMEOUT
;
993 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
994 if (time_after_eq(jiffies
, timeout
))
995 TIMEOUT_MSG(__LINE__
);
998 /* enable burst-mode DMA */
999 /* outb(0x1, dev->base_addr + PORT_AUXDMA); */
1002 * queue receive commands to provide buffering
1006 printk("%s: %d receive PCBs active\n", dev
->name
, adapter
->rx_active
);
1009 * device is now officially open!
1015 return 0; /* Always succeed */
1019 /******************************************************
1021 * send a packet to the adapter
1023 ******************************************************/
1025 static int send_packet(struct net_device
*dev
, struct sk_buff
*skb
)
1027 elp_device
*adapter
= dev
->priv
;
1028 unsigned long target
;
1029 unsigned long flags
;
1032 * make sure the length is even and no shorter than 60 bytes
1034 unsigned int nlen
= (((skb
->len
< 60) ? 60 : skb
->len
) + 1) & (~1);
1036 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
1038 printk("%s: transmit blocked\n", dev
->name
);
1042 adapter
->stats
.tx_bytes
+= nlen
;
1045 * send the adapter a transmit packet command. Ignore segment and offset
1046 * and make sure the length is even
1048 adapter
->tx_pcb
.command
= CMD_TRANSMIT_PACKET
;
1049 adapter
->tx_pcb
.length
= sizeof(struct Xmit_pkt
);
1050 adapter
->tx_pcb
.data
.xmit_pkt
.buf_ofs
1051 = adapter
->tx_pcb
.data
.xmit_pkt
.buf_seg
= 0; /* Unused */
1052 adapter
->tx_pcb
.data
.xmit_pkt
.pkt_len
= nlen
;
1054 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1058 /* if this happens, we die */
1059 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
1060 printk("%s: tx: DMA %d in progress\n", dev
->name
, adapter
->current_dma
.direction
);
1062 adapter
->current_dma
.direction
= 1;
1063 adapter
->current_dma
.start_time
= jiffies
;
1065 target
= virt_to_bus(skb
->data
);
1066 if ((target
+ nlen
) >= MAX_DMA_ADDRESS
) {
1067 memcpy(adapter
->dma_buffer
, skb
->data
, nlen
);
1068 target
= virt_to_bus(adapter
->dma_buffer
);
1070 adapter
->current_dma
.skb
= skb
;
1072 flags
=claim_dma_lock();
1073 disable_dma(dev
->dma
);
1074 clear_dma_ff(dev
->dma
);
1075 set_dma_mode(dev
->dma
, 0x48); /* dma memory -> io */
1076 set_dma_addr(dev
->dma
, target
);
1077 set_dma_count(dev
->dma
, nlen
);
1078 outb_control(adapter
->hcr_val
| DMAE
| TCEN
, dev
);
1079 enable_dma(dev
->dma
);
1080 release_dma_lock(flags
);
1083 printk("%s: DMA transfer started\n", dev
->name
);
1088 /******************************************************
1090 * start the transmitter
1091 * return 0 if sent OK, else return 1
1093 ******************************************************/
1095 static int elp_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1097 if (dev
->interrupt
) {
1098 printk("%s: start_xmit aborted (in irq)\n", dev
->name
);
1102 check_3c505_dma(dev
);
1105 * if the transmitter is still busy, we have a transmit timeout...
1108 elp_device
*adapter
= dev
->priv
;
1109 int tickssofar
= jiffies
- dev
->trans_start
;
1112 if (tickssofar
< 1000)
1115 stat
= inb_status(dev
->base_addr
);
1116 printk("%s: transmit timed out, lost %s?\n", dev
->name
, (stat
& ACRF
) ? "interrupt" : "command");
1118 printk("%s: status %#02x\n", dev
->name
, stat
);
1119 dev
->trans_start
= jiffies
;
1121 adapter
->stats
.tx_dropped
++;
1125 printk("%s: request to send packet of length %d\n", dev
->name
, (int) skb
->len
);
1127 if (test_and_set_bit(0, (void *) &dev
->tbusy
)) {
1128 printk("%s: transmitter access conflict\n", dev
->name
);
1132 * send the packet at skb->data for skb->len
1134 if (!send_packet(dev
, skb
)) {
1135 if (elp_debug
>= 2) {
1136 printk("%s: failed to transmit packet\n", dev
->name
);
1142 printk("%s: packet of length %d sent\n", dev
->name
, (int) skb
->len
);
1145 * start the transmit timeout
1147 dev
->trans_start
= jiffies
;
1154 /******************************************************
1156 * return statistics on the board
1158 ******************************************************/
1160 static struct net_device_stats
*elp_get_stats(struct net_device
*dev
)
1162 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1165 printk("%s: request for stats\n", dev
->name
);
1167 /* If the device is closed, just return the latest stats we have,
1168 - we cannot ask from the adapter without interrupts */
1170 return &adapter
->stats
;
1172 /* send a get statistics command to the board */
1173 adapter
->tx_pcb
.command
= CMD_NETWORK_STATISTICS
;
1174 adapter
->tx_pcb
.length
= 0;
1175 adapter
->got
[CMD_NETWORK_STATISTICS
] = 0;
1176 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1177 printk("%s: couldn't send get statistics command\n", dev
->name
);
1179 int timeout
= jiffies
+ TIMEOUT
;
1180 while (adapter
->got
[CMD_NETWORK_STATISTICS
] == 0 && time_before(jiffies
, timeout
));
1181 if (time_after_eq(jiffies
, timeout
)) {
1182 TIMEOUT_MSG(__LINE__
);
1183 return &adapter
->stats
;
1187 /* statistics are now up to date */
1188 return &adapter
->stats
;
1191 /******************************************************
1195 ******************************************************/
1197 static int elp_close(struct net_device
*dev
)
1199 elp_device
*adapter
;
1201 adapter
= dev
->priv
;
1204 printk("%s: request to close device\n", dev
->name
);
1206 /* Someone may request the device statistic information even when
1207 * the interface is closed. The following will update the statistics
1208 * structure in the driver, so we'll be able to give current statistics.
1210 (void) elp_get_stats(dev
);
1213 * disable interrupts on the board
1215 outb_control(0, dev
);
1218 * flag transmitter as busy (i.e. not available)
1223 * indicate device is closed
1230 free_irq(dev
->irq
, dev
);
1233 free_pages((unsigned long) adapter
->dma_buffer
, __get_order(DMA_BUFFER_SIZE
));
1241 /************************************************************
1243 * Set multicast list
1244 * num_addrs==0: clear mc_list
1245 * num_addrs==-1: set promiscuous mode
1246 * num_addrs>0: set mc_list
1248 ************************************************************/
1250 static void elp_set_mc_list(struct net_device
*dev
)
1252 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1253 struct dev_mc_list
*dmi
= dev
->mc_list
;
1257 printk("%s: request to set multicast list\n", dev
->name
);
1259 if (!(dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
))) {
1260 /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1261 /* if num_addrs==0 the list will be cleared */
1262 adapter
->tx_pcb
.command
= CMD_LOAD_MULTICAST_LIST
;
1263 adapter
->tx_pcb
.length
= 6 * dev
->mc_count
;
1264 for (i
= 0; i
< dev
->mc_count
; i
++) {
1265 memcpy(adapter
->tx_pcb
.data
.multicast
[i
], dmi
->dmi_addr
, 6);
1268 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 0;
1269 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1270 printk("%s: couldn't send set_multicast command\n", dev
->name
);
1272 int timeout
= jiffies
+ TIMEOUT
;
1273 while (adapter
->got
[CMD_LOAD_MULTICAST_LIST
] == 0 && time_before(jiffies
, timeout
));
1274 if (time_after_eq(jiffies
, timeout
)) {
1275 TIMEOUT_MSG(__LINE__
);
1279 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
| RECV_MULTI
;
1280 else /* num_addrs == 0 */
1281 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
1283 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_PROMISC
;
1285 * configure adapter to receive messages (as specified above)
1286 * and wait for response
1289 printk("%s: sending 82586 configure command\n", dev
->name
);
1290 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
1291 adapter
->tx_pcb
.length
= 2;
1292 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
1293 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1294 printk("%s: couldn't send 82586 configure command\n", dev
->name
);
1296 int timeout
= jiffies
+ TIMEOUT
;
1297 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
1298 if (time_after_eq(jiffies
, timeout
))
1299 TIMEOUT_MSG(__LINE__
);
1303 /******************************************************
1305 * initialise Etherlink Plus board
1307 ******************************************************/
1309 static inline void elp_init(struct net_device
*dev
)
1311 elp_device
*adapter
= dev
->priv
;
1314 * set ptrs to various functions
1316 dev
->open
= elp_open
; /* local */
1317 dev
->stop
= elp_close
; /* local */
1318 dev
->get_stats
= elp_get_stats
; /* local */
1319 dev
->hard_start_xmit
= elp_start_xmit
; /* local */
1320 dev
->set_multicast_list
= elp_set_mc_list
; /* local */
1322 /* Setup the generic properties */
1326 * setup ptr to adapter specific information
1328 memset(&(adapter
->stats
), 0, sizeof(struct net_device_stats
));
1331 * memory information
1333 dev
->mem_start
= dev
->mem_end
= dev
->rmem_end
= dev
->rmem_start
= 0;
1336 /************************************************************
1338 * A couple of tests to see if there's 3C505 or not
1339 * Called only by elp_autodetect
1340 ************************************************************/
1342 static int __init
elp_sense(struct net_device
*dev
)
1345 int addr
= dev
->base_addr
;
1346 const char *name
= dev
->name
;
1350 if (check_region(addr
, 0xf))
1353 orig_HSR
= inb_status(addr
);
1356 printk(search_msg
, name
, addr
);
1358 if (orig_HSR
== 0xff) {
1360 printk(notfound_msg
, 1);
1363 /* Enable interrupts - we need timers! */
1367 /* Wait for a while; the adapter may still be booting up */
1369 printk(stilllooking_msg
);
1371 if (orig_HSR
& DIR) {
1372 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1373 outb(0, dev
->base_addr
+ PORT_CONTROL
);
1374 timeout
= jiffies
+ 30*HZ
/100;
1375 while (time_before(jiffies
, timeout
));
1376 restore_flags(flags
);
1377 if (inb_status(addr
) & DIR) {
1379 printk(notfound_msg
, 2);
1383 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1384 outb(DIR, dev
->base_addr
+ PORT_CONTROL
);
1385 timeout
= jiffies
+ 30*HZ
/100;
1386 while (time_before(jiffies
, timeout
));
1387 restore_flags(flags
);
1388 if (!(inb_status(addr
) & DIR)) {
1390 printk(notfound_msg
, 3);
1395 * It certainly looks like a 3c505.
1403 /*************************************************************
1405 * Search through addr_list[] and try to find a 3C505
1406 * Called only by eplus_probe
1407 *************************************************************/
1409 static int __init
elp_autodetect(struct net_device
*dev
)
1413 /* if base address set, then only check that address
1414 otherwise, run through the table */
1415 if (dev
->base_addr
!= 0) { /* dev->base_addr == 0 ==> plain autodetect */
1416 if (elp_sense(dev
) == 0)
1417 return dev
->base_addr
;
1419 while ((dev
->base_addr
= addr_list
[idx
++])) {
1420 if (elp_sense(dev
) == 0)
1421 return dev
->base_addr
;
1424 /* could not find an adapter */
1426 printk(couldnot_msg
, dev
->name
);
1428 return 0; /* Because of this, the layer above will return -ENODEV */
1432 /******************************************************
1434 * probe for an Etherlink Plus board at the specified address
1436 ******************************************************/
1438 /* There are three situations we need to be able to detect here:
1440 * a) the card is idle
1441 * b) the card is still booting up
1442 * c) the card is stuck in a strange state (some DOS drivers do this)
1444 * In case (a), all is well. In case (b), we wait 10 seconds to see if the
1445 * card finishes booting, and carry on if so. In case (c), we do a hard reset,
1446 * loop round, and hope for the best.
1448 * This is all very unpleasant, but hopefully avoids the problems with the old
1449 * probe code (which had a 15-second delay if the card was idle, and didn't
1450 * work at all if it was in a weird state).
1453 int __init
elplus_probe(struct net_device
*dev
)
1455 elp_device
*adapter
;
1456 int i
, tries
, tries1
, timeout
, okay
;
1459 * setup adapter structure
1462 dev
->base_addr
= elp_autodetect(dev
);
1463 if (!(dev
->base_addr
))
1467 * setup ptr to adapter specific information
1469 adapter
= (elp_device
*) (dev
->priv
= kmalloc(sizeof(elp_device
), GFP_KERNEL
));
1470 if (adapter
== NULL
) {
1471 printk("%s: out of memory\n", dev
->name
);
1475 adapter
->send_pcb_semaphore
= 0;
1477 for (tries1
= 0; tries1
< 3; tries1
++) {
1478 outb_control((adapter
->hcr_val
| CMDE
) & ~DIR, dev
);
1479 /* First try to write just one byte, to see if the card is
1480 * responding at all normally.
1482 timeout
= jiffies
+ 5*HZ
/100;
1484 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1485 if ((inb_status(dev
->base_addr
) & HCRE
)) {
1486 outb_command(0, dev
->base_addr
); /* send a spurious byte */
1487 timeout
= jiffies
+ 5*HZ
/100;
1488 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1489 if (inb_status(dev
->base_addr
) & HCRE
)
1493 /* Nope, it's ignoring the command register. This means that
1494 * either it's still booting up, or it's died.
1496 printk("%s: command register wouldn't drain, ", dev
->name
);
1497 if ((inb_status(dev
->base_addr
) & 7) == 3) {
1498 /* If the adapter status is 3, it *could* still be booting.
1499 * Give it the benefit of the doubt for 10 seconds.
1501 printk("assuming 3c505 still starting\n");
1502 timeout
= jiffies
+ 10*HZ
;
1503 while (time_before(jiffies
, timeout
) && (inb_status(dev
->base_addr
) & 7));
1504 if (inb_status(dev
->base_addr
) & 7) {
1505 printk("%s: 3c505 failed to start\n", dev
->name
);
1507 okay
= 1; /* It started */
1510 /* Otherwise, it must just be in a strange
1511 * state. We probably need to kick it.
1513 printk("3c505 is sulking\n");
1516 for (tries
= 0; tries
< 5 && okay
; tries
++) {
1519 * Try to set the Ethernet address, to make sure that the board
1522 adapter
->tx_pcb
.command
= CMD_STATION_ADDRESS
;
1523 adapter
->tx_pcb
.length
= 0;
1525 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1526 printk("%s: could not send first PCB\n", dev
->name
);
1530 if (!receive_pcb(dev
, &adapter
->rx_pcb
)) {
1531 printk("%s: could not read first PCB\n", dev
->name
);
1535 if ((adapter
->rx_pcb
.command
!= CMD_ADDRESS_RESPONSE
) ||
1536 (adapter
->rx_pcb
.length
!= 6)) {
1537 printk("%s: first PCB wrong (%d, %d)\n", dev
->name
, adapter
->rx_pcb
.command
, adapter
->rx_pcb
.length
);
1543 /* It's broken. Do a hard reset to re-initialise the board,
1546 printk(KERN_INFO
"%s: resetting adapter\n", dev
->name
);
1547 outb_control(adapter
->hcr_val
| FLSH
| ATTN
, dev
);
1548 outb_control(adapter
->hcr_val
& ~(FLSH
| ATTN
), dev
);
1550 printk("%s: failed to initialise 3c505\n", dev
->name
);
1554 if (dev
->irq
) { /* Is there a preset IRQ? */
1555 int rpt
= autoirq_report(0);
1556 if (dev
->irq
!= rpt
) {
1557 printk("%s: warning, irq %d configured but %d detected\n", dev
->name
, dev
->irq
, rpt
);
1559 /* if dev->irq == autoirq_report(0), all is well */
1560 } else /* No preset IRQ; just use what we can detect */
1561 dev
->irq
= autoirq_report(0);
1562 switch (dev
->irq
) { /* Legal, sane? */
1564 printk("%s: IRQ probe failed: check 3c505 jumpers.\n",
1571 printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1572 dev
->name
, dev
->irq
);
1576 * Now we have the IRQ number so we can disable the interrupts from
1577 * the board until the board is opened.
1579 outb_control(adapter
->hcr_val
& ~CMDE
, dev
);
1582 * copy Ethernet address into structure
1584 for (i
= 0; i
< 6; i
++)
1585 dev
->dev_addr
[i
] = adapter
->rx_pcb
.data
.eth_addr
[i
];
1587 /* find a DMA channel */
1589 if (dev
->mem_start
) {
1590 dev
->dma
= dev
->mem_start
& 7;
1593 printk(KERN_WARNING
"%s: warning, DMA channel not specified, using default\n", dev
->name
);
1599 * print remainder of startup message
1601 printk("%s: 3c505 at %#lx, irq %d, dma %d, ",
1602 dev
->name
, dev
->base_addr
, dev
->irq
, dev
->dma
);
1603 printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ",
1604 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
1605 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
1608 * read more information from the adapter
1611 adapter
->tx_pcb
.command
= CMD_ADAPTER_INFO
;
1612 adapter
->tx_pcb
.length
= 0;
1613 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1614 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1615 (adapter
->rx_pcb
.command
!= CMD_ADAPTER_INFO_RESPONSE
) ||
1616 (adapter
->rx_pcb
.length
!= 10)) {
1617 printk("not responding to second PCB\n");
1619 printk("rev %d.%d, %dk\n", adapter
->rx_pcb
.data
.info
.major_vers
, adapter
->rx_pcb
.data
.info
.minor_vers
, adapter
->rx_pcb
.data
.info
.RAM_sz
);
1622 * reconfigure the adapter memory to better suit our purposes
1624 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
1625 adapter
->tx_pcb
.length
= 12;
1626 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 8;
1627 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 8;
1628 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
1629 adapter
->tx_pcb
.data
.memconf
.frame
= 10;
1630 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 10;
1631 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
1632 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1633 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1634 (adapter
->rx_pcb
.command
!= CMD_CONFIGURE_ADAPTER_RESPONSE
) ||
1635 (adapter
->rx_pcb
.length
!= 2)) {
1636 printk("%s: could not configure adapter memory\n", dev
->name
);
1638 if (adapter
->rx_pcb
.data
.configure
) {
1639 printk("%s: adapter configuration failed\n", dev
->name
);
1642 * and reserve the address region
1644 request_region(dev
->base_addr
, ELP_IO_EXTENT
, "3c505");
1647 * initialise the device
1656 static char devicename
[ELP_MAX_CARDS
][NAMELEN
] = {{0,}};
1657 static struct net_device dev_3c505
[ELP_MAX_CARDS
] =
1659 { NULL
, /* device name is inserted by net_init.c */
1662 0, 0, 0, NULL
, elplus_probe
},
1665 static int io
[ELP_MAX_CARDS
] = { 0, };
1666 static int irq
[ELP_MAX_CARDS
] = { 0, };
1667 static int dma
[ELP_MAX_CARDS
] = { 0, };
1668 MODULE_PARM(io
, "1-" __MODULE_STRING(ELP_MAX_CARDS
) "i");
1669 MODULE_PARM(irq
, "1-" __MODULE_STRING(ELP_MAX_CARDS
) "i");
1670 MODULE_PARM(dma
, "1-" __MODULE_STRING(ELP_MAX_CARDS
) "i");
1672 int init_module(void)
1674 int this_dev
, found
= 0;
1676 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1677 struct net_device
*dev
= &dev_3c505
[this_dev
];
1678 dev
->name
= devicename
[this_dev
];
1679 dev
->irq
= irq
[this_dev
];
1680 dev
->base_addr
= io
[this_dev
];
1681 if (dma
[this_dev
]) {
1682 dev
->dma
= dma
[this_dev
];
1685 printk(KERN_WARNING
"3c505.c: warning, using default DMA channel,\n");
1687 if (io
[this_dev
] == 0) {
1688 if (this_dev
) break;
1689 printk(KERN_NOTICE
"3c505.c: module autoprobe not recommended, give io=xx.\n");
1691 if (register_netdev(dev
) != 0) {
1692 printk(KERN_WARNING
"3c505.c: Failed to register card at 0x%x.\n", io
[this_dev
]);
1693 if (found
!= 0) return 0;
1701 void cleanup_module(void)
1705 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1706 struct net_device
*dev
= &dev_3c505
[this_dev
];
1707 if (dev
->priv
!= NULL
) {
1708 unregister_netdev(dev
);
1711 release_region(dev
->base_addr
, ELP_IO_EXTENT
);