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 #define filename __FILE__
131 #define timeout_msg "*** timeout at %s:%s (line %d) ***\n"
132 #define TIMEOUT_MSG(lineno) \
133 pr_notice(timeout_msg, filename, __func__, (lineno))
135 #define invalid_pcb_msg "*** invalid pcb length %d at %s:%s (line %d) ***\n"
136 #define INVALID_PCB_MSG(len) \
137 pr_notice(invalid_pcb_msg, (len), filename, __func__, __LINE__)
139 #define search_msg "%s: Looking for 3c505 adapter at address %#x..."
141 #define stilllooking_msg "still looking..."
143 #define found_msg "found.\n"
145 #define notfound_msg "not found (reason = %d)\n"
147 #define couldnot_msg "%s: 3c505 not found\n"
149 /*********************************************************
151 * various other debug stuff
153 *********************************************************/
156 static int elp_debug
= ELP_DEBUG
;
158 static int elp_debug
;
160 #define debug elp_debug
163 * 0 = no messages (well, some)
164 * 1 = messages when high level commands performed
165 * 2 = messages when low level commands performed
166 * 3 = messages when interrupts received
169 /*****************************************************************
171 * List of I/O-addresses we try to auto-sense
172 * Last element MUST BE 0!
173 *****************************************************************/
175 static int addr_list
[] __initdata
= {0x300, 0x280, 0x310, 0};
177 /* Dma Memory related stuff */
179 static unsigned long dma_mem_alloc(int size
)
181 int order
= get_order(size
);
182 return __get_dma_pages(GFP_KERNEL
, order
);
186 /*****************************************************************
188 * Functions for I/O (note the inline !)
190 *****************************************************************/
192 static inline unsigned char inb_status(unsigned int base_addr
)
194 return inb(base_addr
+ PORT_STATUS
);
197 static inline int inb_command(unsigned int base_addr
)
199 return inb(base_addr
+ PORT_COMMAND
);
202 static inline void outb_control(unsigned char val
, struct net_device
*dev
)
204 outb(val
, dev
->base_addr
+ PORT_CONTROL
);
205 ((elp_device
*)(netdev_priv(dev
)))->hcr_val
= val
;
208 #define HCR_VAL(x) (((elp_device *)(netdev_priv(x)))->hcr_val)
210 static inline void outb_command(unsigned char val
, unsigned int base_addr
)
212 outb(val
, base_addr
+ PORT_COMMAND
);
215 static inline unsigned int backlog_next(unsigned int n
)
217 return (n
+ 1) % BACKLOG_SIZE
;
220 /*****************************************************************
222 * useful functions for accessing the adapter
224 *****************************************************************/
227 * use this routine when accessing the ASF bits as they are
228 * changed asynchronously by the adapter
231 /* get adapter PCB status */
232 #define GET_ASF(addr) \
233 (get_status(addr)&ASF_PCB_MASK)
235 static inline int get_status(unsigned int base_addr
)
237 unsigned long timeout
= jiffies
+ 10*HZ
/100;
240 stat1
= inb_status(base_addr
);
241 } while (stat1
!= inb_status(base_addr
) && time_before(jiffies
, timeout
));
242 if (time_after_eq(jiffies
, timeout
))
243 TIMEOUT_MSG(__LINE__
);
247 static inline void set_hsf(struct net_device
*dev
, int hsf
)
249 elp_device
*adapter
= netdev_priv(dev
);
252 spin_lock_irqsave(&adapter
->lock
, flags
);
253 outb_control((HCR_VAL(dev
) & ~HSF_PCB_MASK
) | hsf
, dev
);
254 spin_unlock_irqrestore(&adapter
->lock
, flags
);
257 static bool start_receive(struct net_device
*, pcb_struct
*);
259 static inline void adapter_reset(struct net_device
*dev
)
261 unsigned long timeout
;
262 elp_device
*adapter
= netdev_priv(dev
);
263 unsigned char orig_hcr
= adapter
->hcr_val
;
265 outb_control(0, dev
);
267 if (inb_status(dev
->base_addr
) & ACRF
) {
269 inb_command(dev
->base_addr
);
270 timeout
= jiffies
+ 2*HZ
/100;
271 while (time_before_eq(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & ACRF
));
272 } while (inb_status(dev
->base_addr
) & ACRF
);
273 set_hsf(dev
, HSF_PCB_NAK
);
275 outb_control(adapter
->hcr_val
| ATTN
| DIR, dev
);
277 outb_control(adapter
->hcr_val
& ~ATTN
, dev
);
279 outb_control(adapter
->hcr_val
| FLSH
, dev
);
281 outb_control(adapter
->hcr_val
& ~FLSH
, dev
);
284 outb_control(orig_hcr
, dev
);
285 if (!start_receive(dev
, &adapter
->tx_pcb
))
286 pr_err("%s: start receive command failed\n", dev
->name
);
289 /* Check to make sure that a DMA transfer hasn't timed out. This should
290 * never happen in theory, but seems to occur occasionally if the card gets
291 * prodded at the wrong time.
293 static inline void check_3c505_dma(struct net_device
*dev
)
295 elp_device
*adapter
= netdev_priv(dev
);
296 if (adapter
->dmaing
&& time_after(jiffies
, adapter
->current_dma
.start_time
+ 10)) {
297 unsigned long flags
, f
;
298 pr_err("%s: DMA %s timed out, %d bytes left\n", dev
->name
,
299 adapter
->current_dma
.direction
? "download" : "upload",
300 get_dma_residue(dev
->dma
));
301 spin_lock_irqsave(&adapter
->lock
, flags
);
306 disable_dma(dev
->dma
);
309 if (adapter
->rx_active
)
310 adapter
->rx_active
--;
311 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
312 spin_unlock_irqrestore(&adapter
->lock
, flags
);
316 /* Primitive functions used by send_pcb() */
317 static inline bool send_pcb_slow(unsigned int base_addr
, unsigned char byte
)
319 unsigned long timeout
;
320 outb_command(byte
, base_addr
);
321 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
322 if (inb_status(base_addr
) & HCRE
)
325 pr_warning("3c505: send_pcb_slow timed out\n");
329 static inline bool send_pcb_fast(unsigned int base_addr
, unsigned char byte
)
331 unsigned int timeout
;
332 outb_command(byte
, base_addr
);
333 for (timeout
= 0; timeout
< 40000; timeout
++) {
334 if (inb_status(base_addr
) & HCRE
)
337 pr_warning("3c505: send_pcb_fast timed out\n");
341 /* Check to see if the receiver needs restarting, and kick it if so */
342 static inline void prime_rx(struct net_device
*dev
)
344 elp_device
*adapter
= netdev_priv(dev
);
345 while (adapter
->rx_active
< ELP_RX_PCBS
&& netif_running(dev
)) {
346 if (!start_receive(dev
, &adapter
->itx_pcb
))
351 /*****************************************************************
354 * Send a PCB to the adapter.
356 * output byte to command reg --<--+
357 * wait until HCRE is non zero |
358 * loop until all bytes sent -->--+
359 * set HSF1 and HSF2 to 1
361 * wait until ASF give ACK or NAK
362 * set HSF1 and HSF2 to 0
364 *****************************************************************/
366 /* This can be quite slow -- the adapter is allowed to take up to 40ms
367 * to respond to the initial interrupt.
369 * We run initially with interrupts turned on, but with a semaphore set
370 * so that nobody tries to re-enter this code. Once the first byte has
371 * gone through, we turn interrupts off and then send the others (the
372 * timeout is reduced to 500us).
375 static bool send_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
378 unsigned long timeout
;
379 elp_device
*adapter
= netdev_priv(dev
);
382 check_3c505_dma(dev
);
384 if (adapter
->dmaing
&& adapter
->current_dma
.direction
== 0)
387 /* Avoid contention */
388 if (test_and_set_bit(1, &adapter
->send_pcb_semaphore
)) {
389 if (elp_debug
>= 3) {
390 pr_debug("%s: send_pcb entered while threaded\n", dev
->name
);
395 * load each byte into the command register and
396 * wait for the HCRE bit to indicate the adapter
401 if (send_pcb_slow(dev
->base_addr
, pcb
->command
))
404 spin_lock_irqsave(&adapter
->lock
, flags
);
406 if (send_pcb_fast(dev
->base_addr
, pcb
->length
))
409 for (i
= 0; i
< pcb
->length
; i
++) {
410 if (send_pcb_fast(dev
->base_addr
, pcb
->data
.raw
[i
]))
414 outb_control(adapter
->hcr_val
| 3, dev
); /* signal end of PCB */
415 outb_command(2 + pcb
->length
, dev
->base_addr
);
417 /* now wait for the acknowledgement */
418 spin_unlock_irqrestore(&adapter
->lock
, flags
);
420 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
421 switch (GET_ASF(dev
->base_addr
)) {
423 adapter
->send_pcb_semaphore
= 0;
428 pr_debug("%s: send_pcb got NAK\n", dev
->name
);
435 pr_debug("%s: timeout waiting for PCB acknowledge (status %02x)\n",
436 dev
->name
, inb_status(dev
->base_addr
));
440 spin_unlock_irqrestore(&adapter
->lock
, flags
);
442 adapter
->send_pcb_semaphore
= 0;
447 /*****************************************************************
450 * Read a PCB from the adapter
452 * wait for ACRF to be non-zero ---<---+
454 * if ASF1 and ASF2 were not both one |
455 * before byte was read, loop --->---+
456 * set HSF1 and HSF2 for ack
458 *****************************************************************/
460 static bool receive_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
465 unsigned long timeout
;
468 elp_device
*adapter
= netdev_priv(dev
);
472 /* get the command code */
473 timeout
= jiffies
+ 2*HZ
/100;
474 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
475 if (time_after_eq(jiffies
, timeout
)) {
476 TIMEOUT_MSG(__LINE__
);
479 pcb
->command
= inb_command(dev
->base_addr
);
481 /* read the data length */
482 timeout
= jiffies
+ 3*HZ
/100;
483 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
484 if (time_after_eq(jiffies
, timeout
)) {
485 TIMEOUT_MSG(__LINE__
);
486 pr_info("%s: status %02x\n", dev
->name
, stat
);
489 pcb
->length
= inb_command(dev
->base_addr
);
491 if (pcb
->length
> MAX_PCB_DATA
) {
492 INVALID_PCB_MSG(pcb
->length
);
497 spin_lock_irqsave(&adapter
->lock
, flags
);
498 for (i
= 0; i
< MAX_PCB_DATA
; i
++) {
499 for (j
= 0; j
< 20000; j
++) {
500 stat
= get_status(dev
->base_addr
);
504 pcb
->data
.raw
[i
] = inb_command(dev
->base_addr
);
505 if ((stat
& ASF_PCB_MASK
) == ASF_PCB_END
|| j
>= 20000)
508 spin_unlock_irqrestore(&adapter
->lock
, flags
);
509 if (i
>= MAX_PCB_DATA
) {
514 TIMEOUT_MSG(__LINE__
);
517 /* the last "data" byte was really the length! */
518 total_length
= pcb
->data
.raw
[i
];
520 /* safety check total length vs data length */
521 if (total_length
!= (pcb
->length
+ 2)) {
523 pr_warning("%s: mangled PCB received\n", dev
->name
);
524 set_hsf(dev
, HSF_PCB_NAK
);
528 if (pcb
->command
== CMD_RECEIVE_PACKET_COMPLETE
) {
529 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
530 if (backlog_next(adapter
->rx_backlog
.in
) == adapter
->rx_backlog
.out
) {
531 set_hsf(dev
, HSF_PCB_NAK
);
532 pr_warning("%s: PCB rejected, transfer in progress and backlog full\n", dev
->name
);
540 set_hsf(dev
, HSF_PCB_ACK
);
544 /******************************************************
546 * queue a receive command on the adapter so we will get an
547 * interrupt when a packet is received.
549 ******************************************************/
551 static bool start_receive(struct net_device
*dev
, pcb_struct
* tx_pcb
)
554 elp_device
*adapter
= netdev_priv(dev
);
557 pr_debug("%s: restarting receiver\n", dev
->name
);
558 tx_pcb
->command
= CMD_RECEIVE_PACKET
;
559 tx_pcb
->length
= sizeof(struct Rcv_pkt
);
560 tx_pcb
->data
.rcv_pkt
.buf_seg
561 = tx_pcb
->data
.rcv_pkt
.buf_ofs
= 0; /* Unused */
562 tx_pcb
->data
.rcv_pkt
.buf_len
= 1600;
563 tx_pcb
->data
.rcv_pkt
.timeout
= 0; /* set timeout to zero */
564 status
= send_pcb(dev
, tx_pcb
);
566 adapter
->rx_active
++;
570 /******************************************************
572 * extract a packet from the adapter
573 * this routine is only called from within the interrupt
574 * service routine, so no cli/sti calls are needed
575 * note that the length is always assumed to be even
577 ******************************************************/
579 static void receive_packet(struct net_device
*dev
, int len
)
582 elp_device
*adapter
= netdev_priv(dev
);
587 rlen
= (len
+ 1) & ~1;
588 skb
= dev_alloc_skb(rlen
+ 2);
591 pr_warning("%s: memory squeeze, dropping packet\n", dev
->name
);
592 target
= adapter
->dma_buffer
;
593 adapter
->current_dma
.target
= NULL
;
599 target
= skb_put(skb
, rlen
);
600 if ((unsigned long)(target
+ rlen
) >= MAX_DMA_ADDRESS
) {
601 adapter
->current_dma
.target
= target
;
602 target
= adapter
->dma_buffer
;
604 adapter
->current_dma
.target
= NULL
;
607 /* if this happens, we die */
608 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
609 pr_err("%s: rx blocked, DMA in progress, dir %d\n",
610 dev
->name
, adapter
->current_dma
.direction
);
612 adapter
->current_dma
.direction
= 0;
613 adapter
->current_dma
.length
= rlen
;
614 adapter
->current_dma
.skb
= skb
;
615 adapter
->current_dma
.start_time
= jiffies
;
617 outb_control(adapter
->hcr_val
| DIR | TCEN
| DMAE
, dev
);
619 flags
=claim_dma_lock();
620 disable_dma(dev
->dma
);
621 clear_dma_ff(dev
->dma
);
622 set_dma_mode(dev
->dma
, 0x04); /* dma read */
623 set_dma_addr(dev
->dma
, isa_virt_to_bus(target
));
624 set_dma_count(dev
->dma
, rlen
);
625 enable_dma(dev
->dma
);
626 release_dma_lock(flags
);
628 if (elp_debug
>= 3) {
629 pr_debug("%s: rx DMA transfer started\n", dev
->name
);
632 if (adapter
->rx_active
)
633 adapter
->rx_active
--;
636 pr_warning("%s: receive_packet called, busy not set.\n", dev
->name
);
639 /******************************************************
643 ******************************************************/
645 static irqreturn_t
elp_interrupt(int irq
, void *dev_id
)
650 struct net_device
*dev
= dev_id
;
651 elp_device
*adapter
= netdev_priv(dev
);
652 unsigned long timeout
;
654 spin_lock(&adapter
->lock
);
658 * has a DMA transfer finished?
660 if (inb_status(dev
->base_addr
) & DONE
) {
661 if (!adapter
->dmaing
)
662 pr_warning("%s: phantom DMA completed\n", dev
->name
);
665 pr_debug("%s: %s DMA complete, status %02x\n", dev
->name
,
666 adapter
->current_dma
.direction
? "tx" : "rx",
667 inb_status(dev
->base_addr
));
669 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
670 if (adapter
->current_dma
.direction
) {
671 dev_kfree_skb_irq(adapter
->current_dma
.skb
);
673 struct sk_buff
*skb
= adapter
->current_dma
.skb
;
675 if (adapter
->current_dma
.target
) {
676 /* have already done the skb_put() */
677 memcpy(adapter
->current_dma
.target
, adapter
->dma_buffer
, adapter
->current_dma
.length
);
679 skb
->protocol
= eth_type_trans(skb
,dev
);
680 dev
->stats
.rx_bytes
+= skb
->len
;
685 if (adapter
->rx_backlog
.in
!= adapter
->rx_backlog
.out
) {
686 int t
= adapter
->rx_backlog
.length
[adapter
->rx_backlog
.out
];
687 adapter
->rx_backlog
.out
= backlog_next(adapter
->rx_backlog
.out
);
689 pr_debug("%s: receiving backlogged packet (%d)\n", dev
->name
, t
);
690 receive_packet(dev
, t
);
695 /* has one timed out? */
696 check_3c505_dma(dev
);
700 * receive a PCB from the adapter
702 timeout
= jiffies
+ 3*HZ
/100;
703 while ((inb_status(dev
->base_addr
) & ACRF
) != 0 && time_before(jiffies
, timeout
)) {
704 if (receive_pcb(dev
, &adapter
->irx_pcb
)) {
705 switch (adapter
->irx_pcb
.command
)
710 * received a packet - this must be handled fast
713 case CMD_RECEIVE_PACKET_COMPLETE
:
714 /* if the device isn't open, don't pass packets up the stack */
715 if (!netif_running(dev
))
717 len
= adapter
->irx_pcb
.data
.rcv_resp
.pkt_len
;
718 dlen
= adapter
->irx_pcb
.data
.rcv_resp
.buf_len
;
719 if (adapter
->irx_pcb
.data
.rcv_resp
.timeout
!= 0) {
720 pr_err("%s: interrupt - packet not received correctly\n", dev
->name
);
722 if (elp_debug
>= 3) {
723 pr_debug("%s: interrupt - packet received of length %i (%i)\n",
724 dev
->name
, len
, dlen
);
726 if (adapter
->irx_pcb
.command
== 0xff) {
728 pr_debug("%s: adding packet to backlog (len = %d)\n",
730 adapter
->rx_backlog
.length
[adapter
->rx_backlog
.in
] = dlen
;
731 adapter
->rx_backlog
.in
= backlog_next(adapter
->rx_backlog
.in
);
733 receive_packet(dev
, dlen
);
736 pr_debug("%s: packet received\n", dev
->name
);
741 * 82586 configured correctly
743 case CMD_CONFIGURE_82586_RESPONSE
:
744 adapter
->got
[CMD_CONFIGURE_82586
] = 1;
746 pr_debug("%s: interrupt - configure response received\n", dev
->name
);
750 * Adapter memory configuration
752 case CMD_CONFIGURE_ADAPTER_RESPONSE
:
753 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 1;
755 pr_debug("%s: Adapter memory configuration %s.\n", dev
->name
,
756 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
760 * Multicast list loading
762 case CMD_LOAD_MULTICAST_RESPONSE
:
763 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 1;
765 pr_debug("%s: Multicast address list loading %s.\n", dev
->name
,
766 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
770 * Station address setting
772 case CMD_SET_ADDRESS_RESPONSE
:
773 adapter
->got
[CMD_SET_STATION_ADDRESS
] = 1;
775 pr_debug("%s: Ethernet address setting %s.\n", dev
->name
,
776 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
781 * received board statistics
783 case CMD_NETWORK_STATISTICS_RESPONSE
:
784 dev
->stats
.rx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_recv
;
785 dev
->stats
.tx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_xmit
;
786 dev
->stats
.rx_crc_errors
+= adapter
->irx_pcb
.data
.netstat
.err_CRC
;
787 dev
->stats
.rx_frame_errors
+= adapter
->irx_pcb
.data
.netstat
.err_align
;
788 dev
->stats
.rx_fifo_errors
+= adapter
->irx_pcb
.data
.netstat
.err_ovrrun
;
789 dev
->stats
.rx_over_errors
+= adapter
->irx_pcb
.data
.netstat
.err_res
;
790 adapter
->got
[CMD_NETWORK_STATISTICS
] = 1;
792 pr_debug("%s: interrupt - statistics response received\n", dev
->name
);
798 case CMD_TRANSMIT_PACKET_COMPLETE
:
800 pr_debug("%s: interrupt - packet sent\n", dev
->name
);
801 if (!netif_running(dev
))
803 switch (adapter
->irx_pcb
.data
.xmit_resp
.c_stat
) {
805 dev
->stats
.tx_aborted_errors
++;
806 pr_info("%s: transmit timed out, network cable problem?\n", dev
->name
);
809 dev
->stats
.tx_fifo_errors
++;
810 pr_info("%s: transmit timed out, FIFO underrun\n", dev
->name
);
813 netif_wake_queue(dev
);
820 pr_debug("%s: unknown PCB received - %2.2x\n",
821 dev
->name
, adapter
->irx_pcb
.command
);
825 pr_warning("%s: failed to read PCB on interrupt\n", dev
->name
);
830 } while (icount
++ < 5 && (inb_status(dev
->base_addr
) & (ACRF
| DONE
)));
835 * indicate no longer in interrupt routine
837 spin_unlock(&adapter
->lock
);
842 /******************************************************
846 ******************************************************/
848 static int elp_open(struct net_device
*dev
)
850 elp_device
*adapter
= netdev_priv(dev
);
854 pr_debug("%s: request to open device\n", dev
->name
);
857 * make sure we actually found the device
859 if (adapter
== NULL
) {
860 pr_err("%s: Opening a non-existent physical device\n", dev
->name
);
864 * disable interrupts on the board
866 outb_control(0, dev
);
869 * clear any pending interrupts
871 inb_command(dev
->base_addr
);
875 * no receive PCBs active
877 adapter
->rx_active
= 0;
880 adapter
->send_pcb_semaphore
= 0;
881 adapter
->rx_backlog
.in
= 0;
882 adapter
->rx_backlog
.out
= 0;
884 spin_lock_init(&adapter
->lock
);
887 * install our interrupt service routine
889 if ((retval
= request_irq(dev
->irq
, &elp_interrupt
, 0, dev
->name
, dev
))) {
890 pr_err("%s: could not allocate IRQ%d\n", dev
->name
, dev
->irq
);
893 if ((retval
= request_dma(dev
->dma
, dev
->name
))) {
894 free_irq(dev
->irq
, dev
);
895 pr_err("%s: could not allocate DMA%d channel\n", dev
->name
, dev
->dma
);
898 adapter
->dma_buffer
= (void *) dma_mem_alloc(DMA_BUFFER_SIZE
);
899 if (!adapter
->dma_buffer
) {
900 pr_err("%s: could not allocate DMA buffer\n", dev
->name
);
902 free_irq(dev
->irq
, dev
);
908 * enable interrupts on the board
910 outb_control(CMDE
, dev
);
913 * configure adapter memory: we need 10 multicast addresses, default==0
916 pr_debug("%s: sending 3c505 memory configuration command\n", dev
->name
);
917 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
918 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 10;
919 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 20;
920 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
921 adapter
->tx_pcb
.data
.memconf
.frame
= 20;
922 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 20;
923 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
924 adapter
->tx_pcb
.length
= sizeof(struct Memconf
);
925 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 0;
926 if (!send_pcb(dev
, &adapter
->tx_pcb
))
927 pr_err("%s: couldn't send memory configuration command\n", dev
->name
);
929 unsigned long timeout
= jiffies
+ TIMEOUT
;
930 while (adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] == 0 && time_before(jiffies
, timeout
));
931 if (time_after_eq(jiffies
, timeout
))
932 TIMEOUT_MSG(__LINE__
);
937 * configure adapter to receive broadcast messages and wait for response
940 pr_debug("%s: sending 82586 configure command\n", dev
->name
);
941 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
942 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
943 adapter
->tx_pcb
.length
= 2;
944 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
945 if (!send_pcb(dev
, &adapter
->tx_pcb
))
946 pr_err("%s: couldn't send 82586 configure command\n", dev
->name
);
948 unsigned long timeout
= jiffies
+ TIMEOUT
;
949 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
950 if (time_after_eq(jiffies
, timeout
))
951 TIMEOUT_MSG(__LINE__
);
954 /* enable burst-mode DMA */
955 /* outb(0x1, dev->base_addr + PORT_AUXDMA); */
958 * queue receive commands to provide buffering
962 pr_debug("%s: %d receive PCBs active\n", dev
->name
, adapter
->rx_active
);
965 * device is now officially open!
968 netif_start_queue(dev
);
973 /******************************************************
975 * send a packet to the adapter
977 ******************************************************/
979 static bool send_packet(struct net_device
*dev
, struct sk_buff
*skb
)
981 elp_device
*adapter
= netdev_priv(dev
);
982 unsigned long target
;
986 * make sure the length is even and no shorter than 60 bytes
988 unsigned int nlen
= (((skb
->len
< 60) ? 60 : skb
->len
) + 1) & (~1);
990 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
992 pr_debug("%s: transmit blocked\n", dev
->name
);
996 dev
->stats
.tx_bytes
+= nlen
;
999 * send the adapter a transmit packet command. Ignore segment and offset
1000 * and make sure the length is even
1002 adapter
->tx_pcb
.command
= CMD_TRANSMIT_PACKET
;
1003 adapter
->tx_pcb
.length
= sizeof(struct Xmit_pkt
);
1004 adapter
->tx_pcb
.data
.xmit_pkt
.buf_ofs
1005 = adapter
->tx_pcb
.data
.xmit_pkt
.buf_seg
= 0; /* Unused */
1006 adapter
->tx_pcb
.data
.xmit_pkt
.pkt_len
= nlen
;
1008 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1012 /* if this happens, we die */
1013 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
1014 pr_debug("%s: tx: DMA %d in progress\n", dev
->name
, adapter
->current_dma
.direction
);
1016 adapter
->current_dma
.direction
= 1;
1017 adapter
->current_dma
.start_time
= jiffies
;
1019 if ((unsigned long)(skb
->data
+ nlen
) >= MAX_DMA_ADDRESS
|| nlen
!= skb
->len
) {
1020 skb_copy_from_linear_data(skb
, adapter
->dma_buffer
, nlen
);
1021 memset(adapter
->dma_buffer
+skb
->len
, 0, nlen
-skb
->len
);
1022 target
= isa_virt_to_bus(adapter
->dma_buffer
);
1025 target
= isa_virt_to_bus(skb
->data
);
1027 adapter
->current_dma
.skb
= skb
;
1029 flags
=claim_dma_lock();
1030 disable_dma(dev
->dma
);
1031 clear_dma_ff(dev
->dma
);
1032 set_dma_mode(dev
->dma
, 0x48); /* dma memory -> io */
1033 set_dma_addr(dev
->dma
, target
);
1034 set_dma_count(dev
->dma
, nlen
);
1035 outb_control(adapter
->hcr_val
| DMAE
| TCEN
, dev
);
1036 enable_dma(dev
->dma
);
1037 release_dma_lock(flags
);
1040 pr_debug("%s: DMA transfer started\n", dev
->name
);
1046 * The upper layer thinks we timed out
1049 static void elp_timeout(struct net_device
*dev
)
1053 stat
= inb_status(dev
->base_addr
);
1054 pr_warning("%s: transmit timed out, lost %s?\n", dev
->name
,
1055 (stat
& ACRF
) ? "interrupt" : "command");
1057 pr_debug("%s: status %#02x\n", dev
->name
, stat
);
1058 dev
->trans_start
= jiffies
;
1059 dev
->stats
.tx_dropped
++;
1060 netif_wake_queue(dev
);
1063 /******************************************************
1065 * start the transmitter
1066 * return 0 if sent OK, else return 1
1068 ******************************************************/
1070 static int elp_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1072 unsigned long flags
;
1073 elp_device
*adapter
= netdev_priv(dev
);
1075 spin_lock_irqsave(&adapter
->lock
, flags
);
1076 check_3c505_dma(dev
);
1079 pr_debug("%s: request to send packet of length %d\n", dev
->name
, (int) skb
->len
);
1081 netif_stop_queue(dev
);
1084 * send the packet at skb->data for skb->len
1086 if (!send_packet(dev
, skb
)) {
1087 if (elp_debug
>= 2) {
1088 pr_debug("%s: failed to transmit packet\n", dev
->name
);
1090 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1091 return NETDEV_TX_BUSY
;
1094 pr_debug("%s: packet of length %d sent\n", dev
->name
, (int) skb
->len
);
1097 * start the transmit timeout
1099 dev
->trans_start
= jiffies
;
1102 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1103 netif_start_queue(dev
);
1104 return NETDEV_TX_OK
;
1107 /******************************************************
1109 * return statistics on the board
1111 ******************************************************/
1113 static struct net_device_stats
*elp_get_stats(struct net_device
*dev
)
1115 elp_device
*adapter
= netdev_priv(dev
);
1118 pr_debug("%s: request for stats\n", dev
->name
);
1120 /* If the device is closed, just return the latest stats we have,
1121 - we cannot ask from the adapter without interrupts */
1122 if (!netif_running(dev
))
1125 /* send a get statistics command to the board */
1126 adapter
->tx_pcb
.command
= CMD_NETWORK_STATISTICS
;
1127 adapter
->tx_pcb
.length
= 0;
1128 adapter
->got
[CMD_NETWORK_STATISTICS
] = 0;
1129 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1130 pr_err("%s: couldn't send get statistics command\n", dev
->name
);
1132 unsigned long timeout
= jiffies
+ TIMEOUT
;
1133 while (adapter
->got
[CMD_NETWORK_STATISTICS
] == 0 && time_before(jiffies
, timeout
));
1134 if (time_after_eq(jiffies
, timeout
)) {
1135 TIMEOUT_MSG(__LINE__
);
1140 /* statistics are now up to date */
1145 static void netdev_get_drvinfo(struct net_device
*dev
,
1146 struct ethtool_drvinfo
*info
)
1148 strcpy(info
->driver
, DRV_NAME
);
1149 strcpy(info
->version
, DRV_VERSION
);
1150 sprintf(info
->bus_info
, "ISA 0x%lx", dev
->base_addr
);
1153 static u32
netdev_get_msglevel(struct net_device
*dev
)
1158 static void netdev_set_msglevel(struct net_device
*dev
, u32 level
)
1163 static const struct ethtool_ops netdev_ethtool_ops
= {
1164 .get_drvinfo
= netdev_get_drvinfo
,
1165 .get_msglevel
= netdev_get_msglevel
,
1166 .set_msglevel
= netdev_set_msglevel
,
1169 /******************************************************
1173 ******************************************************/
1175 static int elp_close(struct net_device
*dev
)
1177 elp_device
*adapter
= netdev_priv(dev
);
1180 pr_debug("%s: request to close device\n", dev
->name
);
1182 netif_stop_queue(dev
);
1184 /* Someone may request the device statistic information even when
1185 * the interface is closed. The following will update the statistics
1186 * structure in the driver, so we'll be able to give current statistics.
1188 (void) elp_get_stats(dev
);
1191 * disable interrupts on the board
1193 outb_control(0, dev
);
1198 free_irq(dev
->irq
, dev
);
1201 free_pages((unsigned long) adapter
->dma_buffer
, get_order(DMA_BUFFER_SIZE
));
1207 /************************************************************
1209 * Set multicast list
1210 * num_addrs==0: clear mc_list
1211 * num_addrs==-1: set promiscuous mode
1212 * num_addrs>0: set mc_list
1214 ************************************************************/
1216 static void elp_set_mc_list(struct net_device
*dev
)
1218 elp_device
*adapter
= netdev_priv(dev
);
1219 struct dev_mc_list
*dmi
= dev
->mc_list
;
1221 unsigned long flags
;
1224 pr_debug("%s: request to set multicast list\n", dev
->name
);
1226 spin_lock_irqsave(&adapter
->lock
, flags
);
1228 if (!(dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
))) {
1229 /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1230 /* if num_addrs==0 the list will be cleared */
1231 adapter
->tx_pcb
.command
= CMD_LOAD_MULTICAST_LIST
;
1232 adapter
->tx_pcb
.length
= 6 * dev
->mc_count
;
1233 for (i
= 0; i
< dev
->mc_count
; i
++) {
1234 memcpy(adapter
->tx_pcb
.data
.multicast
[i
], dmi
->dmi_addr
, 6);
1237 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 0;
1238 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1239 pr_err("%s: couldn't send set_multicast command\n", dev
->name
);
1241 unsigned long timeout
= jiffies
+ TIMEOUT
;
1242 while (adapter
->got
[CMD_LOAD_MULTICAST_LIST
] == 0 && time_before(jiffies
, timeout
));
1243 if (time_after_eq(jiffies
, timeout
)) {
1244 TIMEOUT_MSG(__LINE__
);
1248 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
| RECV_MULTI
;
1249 else /* num_addrs == 0 */
1250 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
1252 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_PROMISC
;
1254 * configure adapter to receive messages (as specified above)
1255 * and wait for response
1258 pr_debug("%s: sending 82586 configure command\n", dev
->name
);
1259 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
1260 adapter
->tx_pcb
.length
= 2;
1261 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
1262 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1264 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1265 pr_err("%s: couldn't send 82586 configure command\n", dev
->name
);
1268 unsigned long timeout
= jiffies
+ TIMEOUT
;
1269 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1270 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
1271 if (time_after_eq(jiffies
, timeout
))
1272 TIMEOUT_MSG(__LINE__
);
1276 /************************************************************
1278 * A couple of tests to see if there's 3C505 or not
1279 * Called only by elp_autodetect
1280 ************************************************************/
1282 static int __init
elp_sense(struct net_device
*dev
)
1284 int addr
= dev
->base_addr
;
1285 const char *name
= dev
->name
;
1288 if (!request_region(addr
, ELP_IO_EXTENT
, "3c505"))
1291 orig_HSR
= inb_status(addr
);
1294 pr_debug(search_msg
, name
, addr
);
1296 if (orig_HSR
== 0xff) {
1298 pr_cont(notfound_msg
, 1);
1302 /* Wait for a while; the adapter may still be booting up */
1304 pr_cont(stilllooking_msg
);
1306 if (orig_HSR
& DIR) {
1307 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1308 outb(0, dev
->base_addr
+ PORT_CONTROL
);
1310 if (inb_status(addr
) & DIR) {
1312 pr_cont(notfound_msg
, 2);
1316 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1317 outb(DIR, dev
->base_addr
+ PORT_CONTROL
);
1319 if (!(inb_status(addr
) & DIR)) {
1321 pr_cont(notfound_msg
, 3);
1326 * It certainly looks like a 3c505.
1333 release_region(addr
, ELP_IO_EXTENT
);
1337 /*************************************************************
1339 * Search through addr_list[] and try to find a 3C505
1340 * Called only by eplus_probe
1341 *************************************************************/
1343 static int __init
elp_autodetect(struct net_device
*dev
)
1347 /* if base address set, then only check that address
1348 otherwise, run through the table */
1349 if (dev
->base_addr
!= 0) { /* dev->base_addr == 0 ==> plain autodetect */
1350 if (elp_sense(dev
) == 0)
1351 return dev
->base_addr
;
1353 while ((dev
->base_addr
= addr_list
[idx
++])) {
1354 if (elp_sense(dev
) == 0)
1355 return dev
->base_addr
;
1358 /* could not find an adapter */
1360 pr_debug(couldnot_msg
, dev
->name
);
1362 return 0; /* Because of this, the layer above will return -ENODEV */
1365 static const struct net_device_ops elp_netdev_ops
= {
1366 .ndo_open
= elp_open
,
1367 .ndo_stop
= elp_close
,
1368 .ndo_get_stats
= elp_get_stats
,
1369 .ndo_start_xmit
= elp_start_xmit
,
1370 .ndo_tx_timeout
= elp_timeout
,
1371 .ndo_set_multicast_list
= elp_set_mc_list
,
1372 .ndo_change_mtu
= eth_change_mtu
,
1373 .ndo_set_mac_address
= eth_mac_addr
,
1374 .ndo_validate_addr
= eth_validate_addr
,
1377 /******************************************************
1379 * probe for an Etherlink Plus board at the specified address
1381 ******************************************************/
1383 /* There are three situations we need to be able to detect here:
1385 * a) the card is idle
1386 * b) the card is still booting up
1387 * c) the card is stuck in a strange state (some DOS drivers do this)
1389 * In case (a), all is well. In case (b), we wait 10 seconds to see if the
1390 * card finishes booting, and carry on if so. In case (c), we do a hard reset,
1391 * loop round, and hope for the best.
1393 * This is all very unpleasant, but hopefully avoids the problems with the old
1394 * probe code (which had a 15-second delay if the card was idle, and didn't
1395 * work at all if it was in a weird state).
1398 static int __init
elplus_setup(struct net_device
*dev
)
1400 elp_device
*adapter
= netdev_priv(dev
);
1401 int i
, tries
, tries1
, okay
;
1402 unsigned long timeout
;
1403 unsigned long cookie
= 0;
1407 * setup adapter structure
1410 dev
->base_addr
= elp_autodetect(dev
);
1411 if (!dev
->base_addr
)
1414 adapter
->send_pcb_semaphore
= 0;
1416 for (tries1
= 0; tries1
< 3; tries1
++) {
1417 outb_control((adapter
->hcr_val
| CMDE
) & ~DIR, dev
);
1418 /* First try to write just one byte, to see if the card is
1419 * responding at all normally.
1421 timeout
= jiffies
+ 5*HZ
/100;
1423 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1424 if ((inb_status(dev
->base_addr
) & HCRE
)) {
1425 outb_command(0, dev
->base_addr
); /* send a spurious byte */
1426 timeout
= jiffies
+ 5*HZ
/100;
1427 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1428 if (inb_status(dev
->base_addr
) & HCRE
)
1432 /* Nope, it's ignoring the command register. This means that
1433 * either it's still booting up, or it's died.
1435 pr_err("%s: command register wouldn't drain, ", dev
->name
);
1436 if ((inb_status(dev
->base_addr
) & 7) == 3) {
1437 /* If the adapter status is 3, it *could* still be booting.
1438 * Give it the benefit of the doubt for 10 seconds.
1440 pr_cont("assuming 3c505 still starting\n");
1441 timeout
= jiffies
+ 10*HZ
;
1442 while (time_before(jiffies
, timeout
) && (inb_status(dev
->base_addr
) & 7));
1443 if (inb_status(dev
->base_addr
) & 7) {
1444 pr_err("%s: 3c505 failed to start\n", dev
->name
);
1446 okay
= 1; /* It started */
1449 /* Otherwise, it must just be in a strange
1450 * state. We probably need to kick it.
1452 pr_cont("3c505 is sulking\n");
1455 for (tries
= 0; tries
< 5 && okay
; tries
++) {
1458 * Try to set the Ethernet address, to make sure that the board
1461 adapter
->tx_pcb
.command
= CMD_STATION_ADDRESS
;
1462 adapter
->tx_pcb
.length
= 0;
1463 cookie
= probe_irq_on();
1464 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1465 pr_err("%s: could not send first PCB\n", dev
->name
);
1466 probe_irq_off(cookie
);
1469 if (!receive_pcb(dev
, &adapter
->rx_pcb
)) {
1470 pr_err("%s: could not read first PCB\n", dev
->name
);
1471 probe_irq_off(cookie
);
1474 if ((adapter
->rx_pcb
.command
!= CMD_ADDRESS_RESPONSE
) ||
1475 (adapter
->rx_pcb
.length
!= 6)) {
1476 pr_err("%s: first PCB wrong (%d, %d)\n", dev
->name
,
1477 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 pr_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 pr_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 pr_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 pr_err("%s: IRQ probe failed: check 3c505 jumpers.\n",
1511 pr_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 pr_warning("%s: warning, DMA channel not specified, using default\n", dev
->name
);
1539 * print remainder of startup message
1541 pr_info("%s: 3c505 at %#lx, irq %d, dma %d, addr %pM, ",
1542 dev
->name
, dev
->base_addr
, dev
->irq
, dev
->dma
, dev
->dev_addr
);
1544 * read more information from the adapter
1547 adapter
->tx_pcb
.command
= CMD_ADAPTER_INFO
;
1548 adapter
->tx_pcb
.length
= 0;
1549 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1550 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1551 (adapter
->rx_pcb
.command
!= CMD_ADAPTER_INFO_RESPONSE
) ||
1552 (adapter
->rx_pcb
.length
!= 10)) {
1553 pr_cont("not responding to second PCB\n");
1555 pr_cont("rev %d.%d, %dk\n", adapter
->rx_pcb
.data
.info
.major_vers
,
1556 adapter
->rx_pcb
.data
.info
.minor_vers
, adapter
->rx_pcb
.data
.info
.RAM_sz
);
1559 * reconfigure the adapter memory to better suit our purposes
1561 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
1562 adapter
->tx_pcb
.length
= 12;
1563 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 8;
1564 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 8;
1565 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
1566 adapter
->tx_pcb
.data
.memconf
.frame
= 10;
1567 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 10;
1568 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
1569 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1570 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1571 (adapter
->rx_pcb
.command
!= CMD_CONFIGURE_ADAPTER_RESPONSE
) ||
1572 (adapter
->rx_pcb
.length
!= 2)) {
1573 pr_err("%s: could not configure adapter memory\n", dev
->name
);
1575 if (adapter
->rx_pcb
.data
.configure
) {
1576 pr_err("%s: adapter configuration failed\n", dev
->name
);
1579 dev
->netdev_ops
= &elp_netdev_ops
;
1580 dev
->watchdog_timeo
= 10*HZ
;
1581 dev
->ethtool_ops
= &netdev_ethtool_ops
; /* local */
1583 dev
->mem_start
= dev
->mem_end
= 0;
1585 err
= register_netdev(dev
);
1591 release_region(dev
->base_addr
, ELP_IO_EXTENT
);
1596 struct net_device
* __init
elplus_probe(int unit
)
1598 struct net_device
*dev
= alloc_etherdev(sizeof(elp_device
));
1601 return ERR_PTR(-ENOMEM
);
1603 sprintf(dev
->name
, "eth%d", unit
);
1604 netdev_boot_setup_check(dev
);
1606 err
= elplus_setup(dev
);
1609 return ERR_PTR(err
);
1615 static struct net_device
*dev_3c505
[ELP_MAX_CARDS
];
1616 static int io
[ELP_MAX_CARDS
];
1617 static int irq
[ELP_MAX_CARDS
];
1618 static int dma
[ELP_MAX_CARDS
];
1619 module_param_array(io
, int, NULL
, 0);
1620 module_param_array(irq
, int, NULL
, 0);
1621 module_param_array(dma
, int, NULL
, 0);
1622 MODULE_PARM_DESC(io
, "EtherLink Plus I/O base address(es)");
1623 MODULE_PARM_DESC(irq
, "EtherLink Plus IRQ number(s) (assigned)");
1624 MODULE_PARM_DESC(dma
, "EtherLink Plus DMA channel(s)");
1626 int __init
init_module(void)
1628 int this_dev
, found
= 0;
1630 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1631 struct net_device
*dev
= alloc_etherdev(sizeof(elp_device
));
1635 dev
->irq
= irq
[this_dev
];
1636 dev
->base_addr
= io
[this_dev
];
1637 if (dma
[this_dev
]) {
1638 dev
->dma
= dma
[this_dev
];
1641 pr_warning("3c505.c: warning, using default DMA channel,\n");
1643 if (io
[this_dev
] == 0) {
1648 pr_notice("3c505.c: module autoprobe not recommended, give io=xx.\n");
1650 if (elplus_setup(dev
) != 0) {
1651 pr_warning("3c505.c: Failed to register card at 0x%x.\n", io
[this_dev
]);
1655 dev_3c505
[this_dev
] = dev
;
1663 void __exit
cleanup_module(void)
1667 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1668 struct net_device
*dev
= dev_3c505
[this_dev
];
1670 unregister_netdev(dev
);
1671 release_region(dev
->base_addr
, ELP_IO_EXTENT
);
1678 MODULE_LICENSE("GPL");