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 * (Now at <becker@scyld.com>)
24 * Crynwr packet driver by
25 * Krishnan Gopalan and Gregg Stefancik,
26 * Clemson University Engineering Computer Operations.
27 * Portions of the code have been adapted from the 3c505
28 * driver for NCSA Telnet by Bruce Orchard and later
29 * modified by Warren Van Houten and krus@diku.dk.
30 * 3C505 technical information provided by
31 * Terry Murphy, of 3Com Network Adapter Division
32 * Linux 1.3.0 changes by
33 * Alan Cox <Alan.Cox@linux.org>
34 * More debugging, DMA support, currently maintained by
35 * Philip Blundell <philb@gnu.org>
36 * Multicard/soft configurable dma channel/rev 2 hardware support
37 * by Christopher Collins <ccollins@pcug.org.au>
38 * Ethtool support (jgarzik), 11/17/2001
41 #define DRV_NAME "3c505"
42 #define DRV_VERSION "1.10a"
45 /* Theory of operation:
47 * The 3c505 is quite an intelligent board. All communication with it is done
48 * by means of Primary Command Blocks (PCBs); these are transferred using PIO
49 * through the command register. The card has 256k of on-board RAM, which is
50 * used to buffer received packets. It might seem at first that more buffers
51 * are better, but in fact this isn't true. From my tests, it seems that
52 * more than about 10 buffers are unnecessary, and there is a noticeable
53 * performance hit in having more active on the card. So the majority of the
54 * card's memory isn't, in fact, used. Sadly, the card only has one transmit
55 * buffer and, short of loading our own firmware into it (which is what some
56 * drivers resort to) there's nothing we can do about this.
58 * We keep up to 4 "receive packet" commands active on the board at a time.
59 * When a packet comes in, so long as there is a receive command active, the
60 * board will send us a "packet received" PCB and then add the data for that
61 * packet to the DMA queue. If a DMA transfer is not already in progress, we
62 * set one up to start uploading the data. We have to maintain a list of
63 * backlogged receive packets, because the card may decide to tell us about
64 * a newly-arrived packet at any time, and we may not be able to start a DMA
65 * transfer immediately (ie one may already be going on). We can't NAK the
66 * PCB, because then it would throw the packet away.
68 * Trying to send a PCB to the card at the wrong moment seems to have bad
69 * effects. If we send it a transmit PCB while a receive DMA is happening,
70 * it will just NAK the PCB and so we will have wasted our time. Worse, it
71 * sometimes seems to interrupt the transfer. The majority of the low-level
72 * code is protected by one huge semaphore -- "busy" -- which is set whenever
73 * it probably isn't safe to do anything to the card. The receive routine
74 * must gain a lock on "busy" before it can start a DMA transfer, and the
75 * transmit routine must gain a lock before it sends the first PCB to the card.
76 * The send_pcb() routine also has an internal semaphore to protect it against
77 * being re-entered (which would be disastrous) -- this is needed because
78 * several things can happen asynchronously (re-priming the receiver and
79 * asking the card for statistics, for example). send_pcb() will also refuse
80 * to talk to the card at all if a DMA upload is happening. The higher-level
81 * networking code will reschedule a later retry if some part of the driver
82 * is blocked. In practice, this doesn't seem to happen very often.
85 /* This driver may now work with revision 2.x hardware, since all the read
86 * operations on the HCR have been removed (we now keep our own softcopy).
87 * But I don't have an old card to test it on.
89 * This has had the bad effect that the autoprobe routine is now a bit
90 * less friendly to other devices. However, it was never very good.
91 * before, so I doubt it will hurt anybody.
94 /* The driver is a mess. I took Craig's and Juha's code, and hacked it firstly
95 * to make it more reliable, and secondly to add DMA mode. Many things could
96 * probably be done better; the concurrency protection is particularly awful.
99 #include <linux/module.h>
100 #include <linux/kernel.h>
101 #include <linux/string.h>
102 #include <linux/interrupt.h>
103 #include <linux/errno.h>
104 #include <linux/in.h>
105 #include <linux/slab.h>
106 #include <linux/ioport.h>
107 #include <linux/spinlock.h>
108 #include <linux/ethtool.h>
109 #include <linux/delay.h>
110 #include <linux/bitops.h>
112 #include <asm/uaccess.h>
116 #include <linux/netdevice.h>
117 #include <linux/etherdevice.h>
118 #include <linux/skbuff.h>
119 #include <linux/init.h>
123 /*********************************************************
125 * define debug messages here as common strings to reduce space
127 *********************************************************/
129 static const char filename
[] = __FILE__
;
131 static const char timeout_msg
[] = "*** timeout at %s:%s (line %d) ***\n";
132 #define TIMEOUT_MSG(lineno) \
133 printk(timeout_msg, filename,__FUNCTION__,(lineno))
135 static const char invalid_pcb_msg
[] =
136 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
137 #define INVALID_PCB_MSG(len) \
138 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
140 static char search_msg
[] __initdata
= KERN_INFO
"%s: Looking for 3c505 adapter at address %#x...";
142 static char stilllooking_msg
[] __initdata
= "still looking...";
144 static char found_msg
[] __initdata
= "found.\n";
146 static char notfound_msg
[] __initdata
= "not found (reason = %d)\n";
148 static char couldnot_msg
[] __initdata
= KERN_INFO
"%s: 3c505 not found\n";
150 /*********************************************************
152 * various other debug stuff
154 *********************************************************/
157 static int elp_debug
= ELP_DEBUG
;
159 static int elp_debug
;
161 #define debug elp_debug
164 * 0 = no messages (well, some)
165 * 1 = messages when high level commands performed
166 * 2 = messages when low level commands performed
167 * 3 = messages when interrupts received
170 /*****************************************************************
174 *****************************************************************/
185 /*****************************************************************
187 * List of I/O-addresses we try to auto-sense
188 * Last element MUST BE 0!
189 *****************************************************************/
191 static int addr_list
[] __initdata
= {0x300, 0x280, 0x310, 0};
193 /* Dma Memory related stuff */
195 static unsigned long dma_mem_alloc(int size
)
197 int order
= get_order(size
);
198 return __get_dma_pages(GFP_KERNEL
, order
);
202 /*****************************************************************
204 * Functions for I/O (note the inline !)
206 *****************************************************************/
208 static inline unsigned char inb_status(unsigned int base_addr
)
210 return inb(base_addr
+ PORT_STATUS
);
213 static inline int inb_command(unsigned int base_addr
)
215 return inb(base_addr
+ PORT_COMMAND
);
218 static inline void outb_control(unsigned char val
, struct net_device
*dev
)
220 outb(val
, dev
->base_addr
+ PORT_CONTROL
);
221 ((elp_device
*)(dev
->priv
))->hcr_val
= val
;
224 #define HCR_VAL(x) (((elp_device *)((x)->priv))->hcr_val)
226 static inline void outb_command(unsigned char val
, unsigned int base_addr
)
228 outb(val
, base_addr
+ PORT_COMMAND
);
231 static inline unsigned int backlog_next(unsigned int n
)
233 return (n
+ 1) % BACKLOG_SIZE
;
236 /*****************************************************************
238 * useful functions for accessing the adapter
240 *****************************************************************/
243 * use this routine when accessing the ASF bits as they are
244 * changed asynchronously by the adapter
247 /* get adapter PCB status */
248 #define GET_ASF(addr) \
249 (get_status(addr)&ASF_PCB_MASK)
251 static inline int get_status(unsigned int base_addr
)
253 unsigned long timeout
= jiffies
+ 10*HZ
/100;
256 stat1
= inb_status(base_addr
);
257 } while (stat1
!= inb_status(base_addr
) && time_before(jiffies
, timeout
));
258 if (time_after_eq(jiffies
, timeout
))
259 TIMEOUT_MSG(__LINE__
);
263 static inline void set_hsf(struct net_device
*dev
, int hsf
)
265 elp_device
*adapter
= dev
->priv
;
268 spin_lock_irqsave(&adapter
->lock
, flags
);
269 outb_control((HCR_VAL(dev
) & ~HSF_PCB_MASK
) | hsf
, dev
);
270 spin_unlock_irqrestore(&adapter
->lock
, flags
);
273 static int start_receive(struct net_device
*, pcb_struct
*);
275 static inline void adapter_reset(struct net_device
*dev
)
277 unsigned long timeout
;
278 elp_device
*adapter
= dev
->priv
;
279 unsigned char orig_hcr
= adapter
->hcr_val
;
281 outb_control(0, dev
);
283 if (inb_status(dev
->base_addr
) & ACRF
) {
285 inb_command(dev
->base_addr
);
286 timeout
= jiffies
+ 2*HZ
/100;
287 while (time_before_eq(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & ACRF
));
288 } while (inb_status(dev
->base_addr
) & ACRF
);
289 set_hsf(dev
, HSF_PCB_NAK
);
291 outb_control(adapter
->hcr_val
| ATTN
| DIR, dev
);
293 outb_control(adapter
->hcr_val
& ~ATTN
, dev
);
295 outb_control(adapter
->hcr_val
| FLSH
, dev
);
297 outb_control(adapter
->hcr_val
& ~FLSH
, dev
);
300 outb_control(orig_hcr
, dev
);
301 if (!start_receive(dev
, &adapter
->tx_pcb
))
302 printk(KERN_ERR
"%s: start receive command failed \n", dev
->name
);
305 /* Check to make sure that a DMA transfer hasn't timed out. This should
306 * never happen in theory, but seems to occur occasionally if the card gets
307 * prodded at the wrong time.
309 static inline void check_3c505_dma(struct net_device
*dev
)
311 elp_device
*adapter
= dev
->priv
;
312 if (adapter
->dmaing
&& time_after(jiffies
, adapter
->current_dma
.start_time
+ 10)) {
313 unsigned long flags
, f
;
314 printk(KERN_ERR
"%s: DMA %s timed out, %d bytes left\n", dev
->name
, adapter
->current_dma
.direction
? "download" : "upload", get_dma_residue(dev
->dma
));
315 spin_lock_irqsave(&adapter
->lock
, flags
);
320 disable_dma(dev
->dma
);
323 if (adapter
->rx_active
)
324 adapter
->rx_active
--;
325 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
326 spin_unlock_irqrestore(&adapter
->lock
, flags
);
330 /* Primitive functions used by send_pcb() */
331 static inline unsigned int send_pcb_slow(unsigned int base_addr
, unsigned char byte
)
333 unsigned long timeout
;
334 outb_command(byte
, base_addr
);
335 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
336 if (inb_status(base_addr
) & HCRE
)
339 printk(KERN_WARNING
"3c505: send_pcb_slow timed out\n");
343 static inline unsigned int send_pcb_fast(unsigned int base_addr
, unsigned char byte
)
345 unsigned int timeout
;
346 outb_command(byte
, base_addr
);
347 for (timeout
= 0; timeout
< 40000; timeout
++) {
348 if (inb_status(base_addr
) & HCRE
)
351 printk(KERN_WARNING
"3c505: send_pcb_fast timed out\n");
355 /* Check to see if the receiver needs restarting, and kick it if so */
356 static inline void prime_rx(struct net_device
*dev
)
358 elp_device
*adapter
= dev
->priv
;
359 while (adapter
->rx_active
< ELP_RX_PCBS
&& netif_running(dev
)) {
360 if (!start_receive(dev
, &adapter
->itx_pcb
))
365 /*****************************************************************
368 * Send a PCB to the adapter.
370 * output byte to command reg --<--+
371 * wait until HCRE is non zero |
372 * loop until all bytes sent -->--+
373 * set HSF1 and HSF2 to 1
375 * wait until ASF give ACK or NAK
376 * set HSF1 and HSF2 to 0
378 *****************************************************************/
380 /* This can be quite slow -- the adapter is allowed to take up to 40ms
381 * to respond to the initial interrupt.
383 * We run initially with interrupts turned on, but with a semaphore set
384 * so that nobody tries to re-enter this code. Once the first byte has
385 * gone through, we turn interrupts off and then send the others (the
386 * timeout is reduced to 500us).
389 static int send_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
392 unsigned long timeout
;
393 elp_device
*adapter
= dev
->priv
;
396 check_3c505_dma(dev
);
398 if (adapter
->dmaing
&& adapter
->current_dma
.direction
== 0)
401 /* Avoid contention */
402 if (test_and_set_bit(1, &adapter
->send_pcb_semaphore
)) {
403 if (elp_debug
>= 3) {
404 printk(KERN_DEBUG
"%s: send_pcb entered while threaded\n", dev
->name
);
409 * load each byte into the command register and
410 * wait for the HCRE bit to indicate the adapter
415 if (send_pcb_slow(dev
->base_addr
, pcb
->command
))
418 spin_lock_irqsave(&adapter
->lock
, flags
);
420 if (send_pcb_fast(dev
->base_addr
, pcb
->length
))
423 for (i
= 0; i
< pcb
->length
; i
++) {
424 if (send_pcb_fast(dev
->base_addr
, pcb
->data
.raw
[i
]))
428 outb_control(adapter
->hcr_val
| 3, dev
); /* signal end of PCB */
429 outb_command(2 + pcb
->length
, dev
->base_addr
);
431 /* now wait for the acknowledgement */
432 spin_unlock_irqrestore(&adapter
->lock
, flags
);
434 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
435 switch (GET_ASF(dev
->base_addr
)) {
437 adapter
->send_pcb_semaphore
= 0;
442 printk(KERN_DEBUG
"%s: send_pcb got NAK\n", dev
->name
);
449 printk(KERN_DEBUG
"%s: timeout waiting for PCB acknowledge (status %02x)\n", dev
->name
, inb_status(dev
->base_addr
));
453 spin_unlock_irqrestore(&adapter
->lock
, flags
);
455 adapter
->send_pcb_semaphore
= 0;
460 /*****************************************************************
463 * Read a PCB from the adapter
465 * wait for ACRF to be non-zero ---<---+
467 * if ASF1 and ASF2 were not both one |
468 * before byte was read, loop --->---+
469 * set HSF1 and HSF2 for ack
471 *****************************************************************/
473 static int receive_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
478 unsigned long timeout
;
481 elp_device
*adapter
= dev
->priv
;
485 /* get the command code */
486 timeout
= jiffies
+ 2*HZ
/100;
487 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
488 if (time_after_eq(jiffies
, timeout
)) {
489 TIMEOUT_MSG(__LINE__
);
492 pcb
->command
= inb_command(dev
->base_addr
);
494 /* read the data length */
495 timeout
= jiffies
+ 3*HZ
/100;
496 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
497 if (time_after_eq(jiffies
, timeout
)) {
498 TIMEOUT_MSG(__LINE__
);
499 printk(KERN_INFO
"%s: status %02x\n", dev
->name
, stat
);
502 pcb
->length
= inb_command(dev
->base_addr
);
504 if (pcb
->length
> MAX_PCB_DATA
) {
505 INVALID_PCB_MSG(pcb
->length
);
510 spin_lock_irqsave(&adapter
->lock
, flags
);
514 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && j
++ < 20000);
515 pcb
->data
.raw
[i
++] = inb_command(dev
->base_addr
);
516 if (i
> MAX_PCB_DATA
)
518 } while ((stat
& ASF_PCB_MASK
) != ASF_PCB_END
&& j
< 20000);
519 spin_unlock_irqrestore(&adapter
->lock
, flags
);
521 TIMEOUT_MSG(__LINE__
);
524 /* woops, the last "data" byte was really the length! */
525 total_length
= pcb
->data
.raw
[--i
];
527 /* safety check total length vs data length */
528 if (total_length
!= (pcb
->length
+ 2)) {
530 printk(KERN_WARNING
"%s: mangled PCB received\n", dev
->name
);
531 set_hsf(dev
, HSF_PCB_NAK
);
535 if (pcb
->command
== CMD_RECEIVE_PACKET_COMPLETE
) {
536 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
537 if (backlog_next(adapter
->rx_backlog
.in
) == adapter
->rx_backlog
.out
) {
538 set_hsf(dev
, HSF_PCB_NAK
);
539 printk(KERN_WARNING
"%s: PCB rejected, transfer in progress and backlog full\n", dev
->name
);
547 set_hsf(dev
, HSF_PCB_ACK
);
551 /******************************************************
553 * queue a receive command on the adapter so we will get an
554 * interrupt when a packet is received.
556 ******************************************************/
558 static int start_receive(struct net_device
*dev
, pcb_struct
* tx_pcb
)
561 elp_device
*adapter
= dev
->priv
;
564 printk(KERN_DEBUG
"%s: restarting receiver\n", dev
->name
);
565 tx_pcb
->command
= CMD_RECEIVE_PACKET
;
566 tx_pcb
->length
= sizeof(struct Rcv_pkt
);
567 tx_pcb
->data
.rcv_pkt
.buf_seg
568 = tx_pcb
->data
.rcv_pkt
.buf_ofs
= 0; /* Unused */
569 tx_pcb
->data
.rcv_pkt
.buf_len
= 1600;
570 tx_pcb
->data
.rcv_pkt
.timeout
= 0; /* set timeout to zero */
571 status
= send_pcb(dev
, tx_pcb
);
573 adapter
->rx_active
++;
577 /******************************************************
579 * extract a packet from the adapter
580 * this routine is only called from within the interrupt
581 * service routine, so no cli/sti calls are needed
582 * note that the length is always assumed to be even
584 ******************************************************/
586 static void receive_packet(struct net_device
*dev
, int len
)
589 elp_device
*adapter
= dev
->priv
;
594 rlen
= (len
+ 1) & ~1;
595 skb
= dev_alloc_skb(rlen
+ 2);
598 printk(KERN_WARNING
"%s: memory squeeze, dropping packet\n", dev
->name
);
599 target
= adapter
->dma_buffer
;
600 adapter
->current_dma
.target
= NULL
;
606 target
= skb_put(skb
, rlen
);
607 if ((unsigned long)(target
+ rlen
) >= MAX_DMA_ADDRESS
) {
608 adapter
->current_dma
.target
= target
;
609 target
= adapter
->dma_buffer
;
611 adapter
->current_dma
.target
= NULL
;
614 /* if this happens, we die */
615 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
616 printk(KERN_ERR
"%s: rx blocked, DMA in progress, dir %d\n", dev
->name
, adapter
->current_dma
.direction
);
618 adapter
->current_dma
.direction
= 0;
619 adapter
->current_dma
.length
= rlen
;
620 adapter
->current_dma
.skb
= skb
;
621 adapter
->current_dma
.start_time
= jiffies
;
623 outb_control(adapter
->hcr_val
| DIR | TCEN
| DMAE
, dev
);
625 flags
=claim_dma_lock();
626 disable_dma(dev
->dma
);
627 clear_dma_ff(dev
->dma
);
628 set_dma_mode(dev
->dma
, 0x04); /* dma read */
629 set_dma_addr(dev
->dma
, isa_virt_to_bus(target
));
630 set_dma_count(dev
->dma
, rlen
);
631 enable_dma(dev
->dma
);
632 release_dma_lock(flags
);
634 if (elp_debug
>= 3) {
635 printk(KERN_DEBUG
"%s: rx DMA transfer started\n", dev
->name
);
638 if (adapter
->rx_active
)
639 adapter
->rx_active
--;
642 printk(KERN_WARNING
"%s: receive_packet called, busy not set.\n", dev
->name
);
645 /******************************************************
649 ******************************************************/
651 static irqreturn_t
elp_interrupt(int irq
, void *dev_id
)
656 struct net_device
*dev
;
658 unsigned long timeout
;
661 adapter
= (elp_device
*) dev
->priv
;
663 spin_lock(&adapter
->lock
);
667 * has a DMA transfer finished?
669 if (inb_status(dev
->base_addr
) & DONE
) {
670 if (!adapter
->dmaing
) {
671 printk(KERN_WARNING
"%s: phantom DMA completed\n", dev
->name
);
673 if (elp_debug
>= 3) {
674 printk(KERN_DEBUG
"%s: %s DMA complete, status %02x\n", dev
->name
, adapter
->current_dma
.direction
? "tx" : "rx", inb_status(dev
->base_addr
));
677 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
678 if (adapter
->current_dma
.direction
) {
679 dev_kfree_skb_irq(adapter
->current_dma
.skb
);
681 struct sk_buff
*skb
= adapter
->current_dma
.skb
;
683 if (adapter
->current_dma
.target
) {
684 /* have already done the skb_put() */
685 memcpy(adapter
->current_dma
.target
, adapter
->dma_buffer
, adapter
->current_dma
.length
);
687 skb
->protocol
= eth_type_trans(skb
,dev
);
688 adapter
->stats
.rx_bytes
+= skb
->len
;
690 dev
->last_rx
= jiffies
;
694 if (adapter
->rx_backlog
.in
!= adapter
->rx_backlog
.out
) {
695 int t
= adapter
->rx_backlog
.length
[adapter
->rx_backlog
.out
];
696 adapter
->rx_backlog
.out
= backlog_next(adapter
->rx_backlog
.out
);
698 printk(KERN_DEBUG
"%s: receiving backlogged packet (%d)\n", dev
->name
, t
);
699 receive_packet(dev
, t
);
704 /* has one timed out? */
705 check_3c505_dma(dev
);
709 * receive a PCB from the adapter
711 timeout
= jiffies
+ 3*HZ
/100;
712 while ((inb_status(dev
->base_addr
) & ACRF
) != 0 && time_before(jiffies
, timeout
)) {
713 if (receive_pcb(dev
, &adapter
->irx_pcb
)) {
714 switch (adapter
->irx_pcb
.command
)
719 * received a packet - this must be handled fast
722 case CMD_RECEIVE_PACKET_COMPLETE
:
723 /* if the device isn't open, don't pass packets up the stack */
724 if (!netif_running(dev
))
726 len
= adapter
->irx_pcb
.data
.rcv_resp
.pkt_len
;
727 dlen
= adapter
->irx_pcb
.data
.rcv_resp
.buf_len
;
728 if (adapter
->irx_pcb
.data
.rcv_resp
.timeout
!= 0) {
729 printk(KERN_ERR
"%s: interrupt - packet not received correctly\n", dev
->name
);
731 if (elp_debug
>= 3) {
732 printk(KERN_DEBUG
"%s: interrupt - packet received of length %i (%i)\n", dev
->name
, len
, dlen
);
734 if (adapter
->irx_pcb
.command
== 0xff) {
736 printk(KERN_DEBUG
"%s: adding packet to backlog (len = %d)\n", dev
->name
, dlen
);
737 adapter
->rx_backlog
.length
[adapter
->rx_backlog
.in
] = dlen
;
738 adapter
->rx_backlog
.in
= backlog_next(adapter
->rx_backlog
.in
);
740 receive_packet(dev
, dlen
);
743 printk(KERN_DEBUG
"%s: packet received\n", dev
->name
);
748 * 82586 configured correctly
750 case CMD_CONFIGURE_82586_RESPONSE
:
751 adapter
->got
[CMD_CONFIGURE_82586
] = 1;
753 printk(KERN_DEBUG
"%s: interrupt - configure response received\n", dev
->name
);
757 * Adapter memory configuration
759 case CMD_CONFIGURE_ADAPTER_RESPONSE
:
760 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 1;
762 printk(KERN_DEBUG
"%s: Adapter memory configuration %s.\n", dev
->name
,
763 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
767 * Multicast list loading
769 case CMD_LOAD_MULTICAST_RESPONSE
:
770 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 1;
772 printk(KERN_DEBUG
"%s: Multicast address list loading %s.\n", dev
->name
,
773 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
777 * Station address setting
779 case CMD_SET_ADDRESS_RESPONSE
:
780 adapter
->got
[CMD_SET_STATION_ADDRESS
] = 1;
782 printk(KERN_DEBUG
"%s: Ethernet address setting %s.\n", dev
->name
,
783 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
788 * received board statistics
790 case CMD_NETWORK_STATISTICS_RESPONSE
:
791 adapter
->stats
.rx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_recv
;
792 adapter
->stats
.tx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_xmit
;
793 adapter
->stats
.rx_crc_errors
+= adapter
->irx_pcb
.data
.netstat
.err_CRC
;
794 adapter
->stats
.rx_frame_errors
+= adapter
->irx_pcb
.data
.netstat
.err_align
;
795 adapter
->stats
.rx_fifo_errors
+= adapter
->irx_pcb
.data
.netstat
.err_ovrrun
;
796 adapter
->stats
.rx_over_errors
+= adapter
->irx_pcb
.data
.netstat
.err_res
;
797 adapter
->got
[CMD_NETWORK_STATISTICS
] = 1;
799 printk(KERN_DEBUG
"%s: interrupt - statistics response received\n", dev
->name
);
805 case CMD_TRANSMIT_PACKET_COMPLETE
:
807 printk(KERN_DEBUG
"%s: interrupt - packet sent\n", dev
->name
);
808 if (!netif_running(dev
))
810 switch (adapter
->irx_pcb
.data
.xmit_resp
.c_stat
) {
812 adapter
->stats
.tx_aborted_errors
++;
813 printk(KERN_INFO
"%s: transmit timed out, network cable problem?\n", dev
->name
);
816 adapter
->stats
.tx_fifo_errors
++;
817 printk(KERN_INFO
"%s: transmit timed out, FIFO underrun\n", dev
->name
);
820 netif_wake_queue(dev
);
827 printk(KERN_DEBUG
"%s: unknown PCB received - %2.2x\n", dev
->name
, adapter
->irx_pcb
.command
);
831 printk(KERN_WARNING
"%s: failed to read PCB on interrupt\n", dev
->name
);
836 } while (icount
++ < 5 && (inb_status(dev
->base_addr
) & (ACRF
| DONE
)));
841 * indicate no longer in interrupt routine
843 spin_unlock(&adapter
->lock
);
848 /******************************************************
852 ******************************************************/
854 static int elp_open(struct net_device
*dev
)
862 printk(KERN_DEBUG
"%s: request to open device\n", dev
->name
);
865 * make sure we actually found the device
867 if (adapter
== NULL
) {
868 printk(KERN_ERR
"%s: Opening a non-existent physical device\n", dev
->name
);
872 * disable interrupts on the board
874 outb_control(0, dev
);
877 * clear any pending interrupts
879 inb_command(dev
->base_addr
);
883 * no receive PCBs active
885 adapter
->rx_active
= 0;
888 adapter
->send_pcb_semaphore
= 0;
889 adapter
->rx_backlog
.in
= 0;
890 adapter
->rx_backlog
.out
= 0;
892 spin_lock_init(&adapter
->lock
);
895 * install our interrupt service routine
897 if ((retval
= request_irq(dev
->irq
, &elp_interrupt
, 0, dev
->name
, dev
))) {
898 printk(KERN_ERR
"%s: could not allocate IRQ%d\n", dev
->name
, dev
->irq
);
901 if ((retval
= request_dma(dev
->dma
, dev
->name
))) {
902 free_irq(dev
->irq
, dev
);
903 printk(KERN_ERR
"%s: could not allocate DMA%d channel\n", dev
->name
, dev
->dma
);
906 adapter
->dma_buffer
= (void *) dma_mem_alloc(DMA_BUFFER_SIZE
);
907 if (!adapter
->dma_buffer
) {
908 printk(KERN_ERR
"%s: could not allocate DMA buffer\n", dev
->name
);
910 free_irq(dev
->irq
, dev
);
916 * enable interrupts on the board
918 outb_control(CMDE
, dev
);
921 * configure adapter memory: we need 10 multicast addresses, default==0
924 printk(KERN_DEBUG
"%s: sending 3c505 memory configuration command\n", dev
->name
);
925 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
926 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 10;
927 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 20;
928 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
929 adapter
->tx_pcb
.data
.memconf
.frame
= 20;
930 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 20;
931 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
932 adapter
->tx_pcb
.length
= sizeof(struct Memconf
);
933 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 0;
934 if (!send_pcb(dev
, &adapter
->tx_pcb
))
935 printk(KERN_ERR
"%s: couldn't send memory configuration command\n", dev
->name
);
937 unsigned long timeout
= jiffies
+ TIMEOUT
;
938 while (adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] == 0 && time_before(jiffies
, timeout
));
939 if (time_after_eq(jiffies
, timeout
))
940 TIMEOUT_MSG(__LINE__
);
945 * configure adapter to receive broadcast messages and wait for response
948 printk(KERN_DEBUG
"%s: sending 82586 configure command\n", dev
->name
);
949 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
950 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
951 adapter
->tx_pcb
.length
= 2;
952 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
953 if (!send_pcb(dev
, &adapter
->tx_pcb
))
954 printk(KERN_ERR
"%s: couldn't send 82586 configure command\n", dev
->name
);
956 unsigned long timeout
= jiffies
+ TIMEOUT
;
957 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
958 if (time_after_eq(jiffies
, timeout
))
959 TIMEOUT_MSG(__LINE__
);
962 /* enable burst-mode DMA */
963 /* outb(0x1, dev->base_addr + PORT_AUXDMA); */
966 * queue receive commands to provide buffering
970 printk(KERN_DEBUG
"%s: %d receive PCBs active\n", dev
->name
, adapter
->rx_active
);
973 * device is now officially open!
976 netif_start_queue(dev
);
981 /******************************************************
983 * send a packet to the adapter
985 ******************************************************/
987 static int send_packet(struct net_device
*dev
, struct sk_buff
*skb
)
989 elp_device
*adapter
= dev
->priv
;
990 unsigned long target
;
994 * make sure the length is even and no shorter than 60 bytes
996 unsigned int nlen
= (((skb
->len
< 60) ? 60 : skb
->len
) + 1) & (~1);
998 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
1000 printk(KERN_DEBUG
"%s: transmit blocked\n", dev
->name
);
1004 adapter
->stats
.tx_bytes
+= nlen
;
1007 * send the adapter a transmit packet command. Ignore segment and offset
1008 * and make sure the length is even
1010 adapter
->tx_pcb
.command
= CMD_TRANSMIT_PACKET
;
1011 adapter
->tx_pcb
.length
= sizeof(struct Xmit_pkt
);
1012 adapter
->tx_pcb
.data
.xmit_pkt
.buf_ofs
1013 = adapter
->tx_pcb
.data
.xmit_pkt
.buf_seg
= 0; /* Unused */
1014 adapter
->tx_pcb
.data
.xmit_pkt
.pkt_len
= nlen
;
1016 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1020 /* if this happens, we die */
1021 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
1022 printk(KERN_DEBUG
"%s: tx: DMA %d in progress\n", dev
->name
, adapter
->current_dma
.direction
);
1024 adapter
->current_dma
.direction
= 1;
1025 adapter
->current_dma
.start_time
= jiffies
;
1027 if ((unsigned long)(skb
->data
+ nlen
) >= MAX_DMA_ADDRESS
|| nlen
!= skb
->len
) {
1028 skb_copy_from_linear_data(skb
, adapter
->dma_buffer
, nlen
);
1029 memset(adapter
->dma_buffer
+skb
->len
, 0, nlen
-skb
->len
);
1030 target
= isa_virt_to_bus(adapter
->dma_buffer
);
1033 target
= isa_virt_to_bus(skb
->data
);
1035 adapter
->current_dma
.skb
= skb
;
1037 flags
=claim_dma_lock();
1038 disable_dma(dev
->dma
);
1039 clear_dma_ff(dev
->dma
);
1040 set_dma_mode(dev
->dma
, 0x48); /* dma memory -> io */
1041 set_dma_addr(dev
->dma
, target
);
1042 set_dma_count(dev
->dma
, nlen
);
1043 outb_control(adapter
->hcr_val
| DMAE
| TCEN
, dev
);
1044 enable_dma(dev
->dma
);
1045 release_dma_lock(flags
);
1048 printk(KERN_DEBUG
"%s: DMA transfer started\n", dev
->name
);
1054 * The upper layer thinks we timed out
1057 static void elp_timeout(struct net_device
*dev
)
1059 elp_device
*adapter
= dev
->priv
;
1062 stat
= inb_status(dev
->base_addr
);
1063 printk(KERN_WARNING
"%s: transmit timed out, lost %s?\n", dev
->name
, (stat
& ACRF
) ? "interrupt" : "command");
1065 printk(KERN_DEBUG
"%s: status %#02x\n", dev
->name
, stat
);
1066 dev
->trans_start
= jiffies
;
1067 adapter
->stats
.tx_dropped
++;
1068 netif_wake_queue(dev
);
1071 /******************************************************
1073 * start the transmitter
1074 * return 0 if sent OK, else return 1
1076 ******************************************************/
1078 static int elp_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1080 unsigned long flags
;
1081 elp_device
*adapter
= dev
->priv
;
1083 spin_lock_irqsave(&adapter
->lock
, flags
);
1084 check_3c505_dma(dev
);
1087 printk(KERN_DEBUG
"%s: request to send packet of length %d\n", dev
->name
, (int) skb
->len
);
1089 netif_stop_queue(dev
);
1092 * send the packet at skb->data for skb->len
1094 if (!send_packet(dev
, skb
)) {
1095 if (elp_debug
>= 2) {
1096 printk(KERN_DEBUG
"%s: failed to transmit packet\n", dev
->name
);
1098 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1102 printk(KERN_DEBUG
"%s: packet of length %d sent\n", dev
->name
, (int) skb
->len
);
1105 * start the transmit timeout
1107 dev
->trans_start
= jiffies
;
1110 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1111 netif_start_queue(dev
);
1115 /******************************************************
1117 * return statistics on the board
1119 ******************************************************/
1121 static struct net_device_stats
*elp_get_stats(struct net_device
*dev
)
1123 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1126 printk(KERN_DEBUG
"%s: request for stats\n", dev
->name
);
1128 /* If the device is closed, just return the latest stats we have,
1129 - we cannot ask from the adapter without interrupts */
1130 if (!netif_running(dev
))
1131 return &adapter
->stats
;
1133 /* send a get statistics command to the board */
1134 adapter
->tx_pcb
.command
= CMD_NETWORK_STATISTICS
;
1135 adapter
->tx_pcb
.length
= 0;
1136 adapter
->got
[CMD_NETWORK_STATISTICS
] = 0;
1137 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1138 printk(KERN_ERR
"%s: couldn't send get statistics command\n", dev
->name
);
1140 unsigned long timeout
= jiffies
+ TIMEOUT
;
1141 while (adapter
->got
[CMD_NETWORK_STATISTICS
] == 0 && time_before(jiffies
, timeout
));
1142 if (time_after_eq(jiffies
, timeout
)) {
1143 TIMEOUT_MSG(__LINE__
);
1144 return &adapter
->stats
;
1148 /* statistics are now up to date */
1149 return &adapter
->stats
;
1153 static void netdev_get_drvinfo(struct net_device
*dev
,
1154 struct ethtool_drvinfo
*info
)
1156 strcpy(info
->driver
, DRV_NAME
);
1157 strcpy(info
->version
, DRV_VERSION
);
1158 sprintf(info
->bus_info
, "ISA 0x%lx", dev
->base_addr
);
1161 static u32
netdev_get_msglevel(struct net_device
*dev
)
1166 static void netdev_set_msglevel(struct net_device
*dev
, u32 level
)
1171 static const struct ethtool_ops netdev_ethtool_ops
= {
1172 .get_drvinfo
= netdev_get_drvinfo
,
1173 .get_msglevel
= netdev_get_msglevel
,
1174 .set_msglevel
= netdev_set_msglevel
,
1177 /******************************************************
1181 ******************************************************/
1183 static int elp_close(struct net_device
*dev
)
1185 elp_device
*adapter
;
1187 adapter
= dev
->priv
;
1190 printk(KERN_DEBUG
"%s: request to close device\n", dev
->name
);
1192 netif_stop_queue(dev
);
1194 /* Someone may request the device statistic information even when
1195 * the interface is closed. The following will update the statistics
1196 * structure in the driver, so we'll be able to give current statistics.
1198 (void) elp_get_stats(dev
);
1201 * disable interrupts on the board
1203 outb_control(0, dev
);
1208 free_irq(dev
->irq
, dev
);
1211 free_pages((unsigned long) adapter
->dma_buffer
, get_order(DMA_BUFFER_SIZE
));
1217 /************************************************************
1219 * Set multicast list
1220 * num_addrs==0: clear mc_list
1221 * num_addrs==-1: set promiscuous mode
1222 * num_addrs>0: set mc_list
1224 ************************************************************/
1226 static void elp_set_mc_list(struct net_device
*dev
)
1228 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1229 struct dev_mc_list
*dmi
= dev
->mc_list
;
1231 unsigned long flags
;
1234 printk(KERN_DEBUG
"%s: request to set multicast list\n", dev
->name
);
1236 spin_lock_irqsave(&adapter
->lock
, flags
);
1238 if (!(dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
))) {
1239 /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1240 /* if num_addrs==0 the list will be cleared */
1241 adapter
->tx_pcb
.command
= CMD_LOAD_MULTICAST_LIST
;
1242 adapter
->tx_pcb
.length
= 6 * dev
->mc_count
;
1243 for (i
= 0; i
< dev
->mc_count
; i
++) {
1244 memcpy(adapter
->tx_pcb
.data
.multicast
[i
], dmi
->dmi_addr
, 6);
1247 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 0;
1248 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1249 printk(KERN_ERR
"%s: couldn't send set_multicast command\n", dev
->name
);
1251 unsigned long timeout
= jiffies
+ TIMEOUT
;
1252 while (adapter
->got
[CMD_LOAD_MULTICAST_LIST
] == 0 && time_before(jiffies
, timeout
));
1253 if (time_after_eq(jiffies
, timeout
)) {
1254 TIMEOUT_MSG(__LINE__
);
1258 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
| RECV_MULTI
;
1259 else /* num_addrs == 0 */
1260 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
1262 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_PROMISC
;
1264 * configure adapter to receive messages (as specified above)
1265 * and wait for response
1268 printk(KERN_DEBUG
"%s: sending 82586 configure command\n", dev
->name
);
1269 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
1270 adapter
->tx_pcb
.length
= 2;
1271 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
1272 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1274 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1275 printk(KERN_ERR
"%s: couldn't send 82586 configure command\n", dev
->name
);
1278 unsigned long timeout
= jiffies
+ TIMEOUT
;
1279 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1280 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
1281 if (time_after_eq(jiffies
, timeout
))
1282 TIMEOUT_MSG(__LINE__
);
1286 /************************************************************
1288 * A couple of tests to see if there's 3C505 or not
1289 * Called only by elp_autodetect
1290 ************************************************************/
1292 static int __init
elp_sense(struct net_device
*dev
)
1294 int addr
= dev
->base_addr
;
1295 const char *name
= dev
->name
;
1298 if (!request_region(addr
, ELP_IO_EXTENT
, "3c505"))
1301 orig_HSR
= inb_status(addr
);
1304 printk(search_msg
, name
, addr
);
1306 if (orig_HSR
== 0xff) {
1308 printk(notfound_msg
, 1);
1312 /* Wait for a while; the adapter may still be booting up */
1314 printk(stilllooking_msg
);
1316 if (orig_HSR
& DIR) {
1317 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1318 outb(0, dev
->base_addr
+ PORT_CONTROL
);
1320 if (inb_status(addr
) & DIR) {
1322 printk(notfound_msg
, 2);
1326 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1327 outb(DIR, dev
->base_addr
+ PORT_CONTROL
);
1329 if (!(inb_status(addr
) & DIR)) {
1331 printk(notfound_msg
, 3);
1336 * It certainly looks like a 3c505.
1343 release_region(addr
, ELP_IO_EXTENT
);
1347 /*************************************************************
1349 * Search through addr_list[] and try to find a 3C505
1350 * Called only by eplus_probe
1351 *************************************************************/
1353 static int __init
elp_autodetect(struct net_device
*dev
)
1357 /* if base address set, then only check that address
1358 otherwise, run through the table */
1359 if (dev
->base_addr
!= 0) { /* dev->base_addr == 0 ==> plain autodetect */
1360 if (elp_sense(dev
) == 0)
1361 return dev
->base_addr
;
1363 while ((dev
->base_addr
= addr_list
[idx
++])) {
1364 if (elp_sense(dev
) == 0)
1365 return dev
->base_addr
;
1368 /* could not find an adapter */
1370 printk(couldnot_msg
, dev
->name
);
1372 return 0; /* Because of this, the layer above will return -ENODEV */
1376 /******************************************************
1378 * probe for an Etherlink Plus board at the specified address
1380 ******************************************************/
1382 /* There are three situations we need to be able to detect here:
1384 * a) the card is idle
1385 * b) the card is still booting up
1386 * c) the card is stuck in a strange state (some DOS drivers do this)
1388 * In case (a), all is well. In case (b), we wait 10 seconds to see if the
1389 * card finishes booting, and carry on if so. In case (c), we do a hard reset,
1390 * loop round, and hope for the best.
1392 * This is all very unpleasant, but hopefully avoids the problems with the old
1393 * probe code (which had a 15-second delay if the card was idle, and didn't
1394 * work at all if it was in a weird state).
1397 static int __init
elplus_setup(struct net_device
*dev
)
1399 elp_device
*adapter
= dev
->priv
;
1400 int i
, tries
, tries1
, okay
;
1401 unsigned long timeout
;
1402 unsigned long cookie
= 0;
1405 SET_MODULE_OWNER(dev
);
1408 * setup adapter structure
1411 dev
->base_addr
= elp_autodetect(dev
);
1412 if (!dev
->base_addr
)
1415 adapter
->send_pcb_semaphore
= 0;
1417 for (tries1
= 0; tries1
< 3; tries1
++) {
1418 outb_control((adapter
->hcr_val
| CMDE
) & ~DIR, dev
);
1419 /* First try to write just one byte, to see if the card is
1420 * responding at all normally.
1422 timeout
= jiffies
+ 5*HZ
/100;
1424 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1425 if ((inb_status(dev
->base_addr
) & HCRE
)) {
1426 outb_command(0, dev
->base_addr
); /* send a spurious byte */
1427 timeout
= jiffies
+ 5*HZ
/100;
1428 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1429 if (inb_status(dev
->base_addr
) & HCRE
)
1433 /* Nope, it's ignoring the command register. This means that
1434 * either it's still booting up, or it's died.
1436 printk(KERN_ERR
"%s: command register wouldn't drain, ", dev
->name
);
1437 if ((inb_status(dev
->base_addr
) & 7) == 3) {
1438 /* If the adapter status is 3, it *could* still be booting.
1439 * Give it the benefit of the doubt for 10 seconds.
1441 printk("assuming 3c505 still starting\n");
1442 timeout
= jiffies
+ 10*HZ
;
1443 while (time_before(jiffies
, timeout
) && (inb_status(dev
->base_addr
) & 7));
1444 if (inb_status(dev
->base_addr
) & 7) {
1445 printk(KERN_ERR
"%s: 3c505 failed to start\n", dev
->name
);
1447 okay
= 1; /* It started */
1450 /* Otherwise, it must just be in a strange
1451 * state. We probably need to kick it.
1453 printk("3c505 is sulking\n");
1456 for (tries
= 0; tries
< 5 && okay
; tries
++) {
1459 * Try to set the Ethernet address, to make sure that the board
1462 adapter
->tx_pcb
.command
= CMD_STATION_ADDRESS
;
1463 adapter
->tx_pcb
.length
= 0;
1464 cookie
= probe_irq_on();
1465 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1466 printk(KERN_ERR
"%s: could not send first PCB\n", dev
->name
);
1467 probe_irq_off(cookie
);
1470 if (!receive_pcb(dev
, &adapter
->rx_pcb
)) {
1471 printk(KERN_ERR
"%s: could not read first PCB\n", dev
->name
);
1472 probe_irq_off(cookie
);
1475 if ((adapter
->rx_pcb
.command
!= CMD_ADDRESS_RESPONSE
) ||
1476 (adapter
->rx_pcb
.length
!= 6)) {
1477 printk(KERN_ERR
"%s: first PCB wrong (%d, %d)\n", dev
->name
, adapter
->rx_pcb
.command
, adapter
->rx_pcb
.length
);
1478 probe_irq_off(cookie
);
1483 /* It's broken. Do a hard reset to re-initialise the board,
1486 printk(KERN_INFO
"%s: resetting adapter\n", dev
->name
);
1487 outb_control(adapter
->hcr_val
| FLSH
| ATTN
, dev
);
1488 outb_control(adapter
->hcr_val
& ~(FLSH
| ATTN
), dev
);
1490 printk(KERN_ERR
"%s: failed to initialise 3c505\n", dev
->name
);
1494 if (dev
->irq
) { /* Is there a preset IRQ? */
1495 int rpt
= probe_irq_off(cookie
);
1496 if (dev
->irq
!= rpt
) {
1497 printk(KERN_WARNING
"%s: warning, irq %d configured but %d detected\n", dev
->name
, dev
->irq
, rpt
);
1499 /* if dev->irq == probe_irq_off(cookie), all is well */
1500 } else /* No preset IRQ; just use what we can detect */
1501 dev
->irq
= probe_irq_off(cookie
);
1502 switch (dev
->irq
) { /* Legal, sane? */
1504 printk(KERN_ERR
"%s: IRQ probe failed: check 3c505 jumpers.\n",
1511 printk(KERN_ERR
"%s: Impossible IRQ %d reported by probe_irq_off().\n",
1512 dev
->name
, dev
->irq
);
1516 * Now we have the IRQ number so we can disable the interrupts from
1517 * the board until the board is opened.
1519 outb_control(adapter
->hcr_val
& ~CMDE
, dev
);
1522 * copy Ethernet address into structure
1524 for (i
= 0; i
< 6; i
++)
1525 dev
->dev_addr
[i
] = adapter
->rx_pcb
.data
.eth_addr
[i
];
1527 /* find a DMA channel */
1529 if (dev
->mem_start
) {
1530 dev
->dma
= dev
->mem_start
& 7;
1533 printk(KERN_WARNING
"%s: warning, DMA channel not specified, using default\n", dev
->name
);
1539 * print remainder of startup message
1541 printk(KERN_INFO
"%s: 3c505 at %#lx, irq %d, dma %d, ",
1542 dev
->name
, dev
->base_addr
, dev
->irq
, dev
->dma
);
1543 printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ",
1544 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
1545 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
1548 * read more information from the adapter
1551 adapter
->tx_pcb
.command
= CMD_ADAPTER_INFO
;
1552 adapter
->tx_pcb
.length
= 0;
1553 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1554 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1555 (adapter
->rx_pcb
.command
!= CMD_ADAPTER_INFO_RESPONSE
) ||
1556 (adapter
->rx_pcb
.length
!= 10)) {
1557 printk("not responding to second PCB\n");
1559 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
);
1562 * reconfigure the adapter memory to better suit our purposes
1564 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
1565 adapter
->tx_pcb
.length
= 12;
1566 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 8;
1567 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 8;
1568 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
1569 adapter
->tx_pcb
.data
.memconf
.frame
= 10;
1570 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 10;
1571 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
1572 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1573 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1574 (adapter
->rx_pcb
.command
!= CMD_CONFIGURE_ADAPTER_RESPONSE
) ||
1575 (adapter
->rx_pcb
.length
!= 2)) {
1576 printk(KERN_ERR
"%s: could not configure adapter memory\n", dev
->name
);
1578 if (adapter
->rx_pcb
.data
.configure
) {
1579 printk(KERN_ERR
"%s: adapter configuration failed\n", dev
->name
);
1582 dev
->open
= elp_open
; /* local */
1583 dev
->stop
= elp_close
; /* local */
1584 dev
->get_stats
= elp_get_stats
; /* local */
1585 dev
->hard_start_xmit
= elp_start_xmit
; /* local */
1586 dev
->tx_timeout
= elp_timeout
; /* local */
1587 dev
->watchdog_timeo
= 10*HZ
;
1588 dev
->set_multicast_list
= elp_set_mc_list
; /* local */
1589 dev
->ethtool_ops
= &netdev_ethtool_ops
; /* local */
1591 memset(&(adapter
->stats
), 0, sizeof(struct net_device_stats
));
1592 dev
->mem_start
= dev
->mem_end
= 0;
1594 err
= register_netdev(dev
);
1600 release_region(dev
->base_addr
, ELP_IO_EXTENT
);
1605 struct net_device
* __init
elplus_probe(int unit
)
1607 struct net_device
*dev
= alloc_etherdev(sizeof(elp_device
));
1610 return ERR_PTR(-ENOMEM
);
1612 sprintf(dev
->name
, "eth%d", unit
);
1613 netdev_boot_setup_check(dev
);
1615 err
= elplus_setup(dev
);
1618 return ERR_PTR(err
);
1624 static struct net_device
*dev_3c505
[ELP_MAX_CARDS
];
1625 static int io
[ELP_MAX_CARDS
];
1626 static int irq
[ELP_MAX_CARDS
];
1627 static int dma
[ELP_MAX_CARDS
];
1628 module_param_array(io
, int, NULL
, 0);
1629 module_param_array(irq
, int, NULL
, 0);
1630 module_param_array(dma
, int, NULL
, 0);
1631 MODULE_PARM_DESC(io
, "EtherLink Plus I/O base address(es)");
1632 MODULE_PARM_DESC(irq
, "EtherLink Plus IRQ number(s) (assigned)");
1633 MODULE_PARM_DESC(dma
, "EtherLink Plus DMA channel(s)");
1635 int __init
init_module(void)
1637 int this_dev
, found
= 0;
1639 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1640 struct net_device
*dev
= alloc_etherdev(sizeof(elp_device
));
1644 dev
->irq
= irq
[this_dev
];
1645 dev
->base_addr
= io
[this_dev
];
1646 if (dma
[this_dev
]) {
1647 dev
->dma
= dma
[this_dev
];
1650 printk(KERN_WARNING
"3c505.c: warning, using default DMA channel,\n");
1652 if (io
[this_dev
] == 0) {
1657 printk(KERN_NOTICE
"3c505.c: module autoprobe not recommended, give io=xx.\n");
1659 if (elplus_setup(dev
) != 0) {
1660 printk(KERN_WARNING
"3c505.c: Failed to register card at 0x%x.\n", io
[this_dev
]);
1664 dev_3c505
[this_dev
] = dev
;
1672 void __exit
cleanup_module(void)
1676 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1677 struct net_device
*dev
= dev_3c505
[this_dev
];
1679 unregister_netdev(dev
);
1680 release_region(dev
->base_addr
, ELP_IO_EXTENT
);
1687 MODULE_LICENSE("GPL");