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 /*****************************************************************
172 * List of I/O-addresses we try to auto-sense
173 * Last element MUST BE 0!
174 *****************************************************************/
176 static int addr_list
[] __initdata
= {0x300, 0x280, 0x310, 0};
178 /* Dma Memory related stuff */
180 static unsigned long dma_mem_alloc(int size
)
182 int order
= get_order(size
);
183 return __get_dma_pages(GFP_KERNEL
, order
);
187 /*****************************************************************
189 * Functions for I/O (note the inline !)
191 *****************************************************************/
193 static inline unsigned char inb_status(unsigned int base_addr
)
195 return inb(base_addr
+ PORT_STATUS
);
198 static inline int inb_command(unsigned int base_addr
)
200 return inb(base_addr
+ PORT_COMMAND
);
203 static inline void outb_control(unsigned char val
, struct net_device
*dev
)
205 outb(val
, dev
->base_addr
+ PORT_CONTROL
);
206 ((elp_device
*)(dev
->priv
))->hcr_val
= val
;
209 #define HCR_VAL(x) (((elp_device *)((x)->priv))->hcr_val)
211 static inline void outb_command(unsigned char val
, unsigned int base_addr
)
213 outb(val
, base_addr
+ PORT_COMMAND
);
216 static inline unsigned int backlog_next(unsigned int n
)
218 return (n
+ 1) % BACKLOG_SIZE
;
221 /*****************************************************************
223 * useful functions for accessing the adapter
225 *****************************************************************/
228 * use this routine when accessing the ASF bits as they are
229 * changed asynchronously by the adapter
232 /* get adapter PCB status */
233 #define GET_ASF(addr) \
234 (get_status(addr)&ASF_PCB_MASK)
236 static inline int get_status(unsigned int base_addr
)
238 unsigned long timeout
= jiffies
+ 10*HZ
/100;
241 stat1
= inb_status(base_addr
);
242 } while (stat1
!= inb_status(base_addr
) && time_before(jiffies
, timeout
));
243 if (time_after_eq(jiffies
, timeout
))
244 TIMEOUT_MSG(__LINE__
);
248 static inline void set_hsf(struct net_device
*dev
, int hsf
)
250 elp_device
*adapter
= dev
->priv
;
253 spin_lock_irqsave(&adapter
->lock
, flags
);
254 outb_control((HCR_VAL(dev
) & ~HSF_PCB_MASK
) | hsf
, dev
);
255 spin_unlock_irqrestore(&adapter
->lock
, flags
);
258 static bool start_receive(struct net_device
*, pcb_struct
*);
260 static inline void adapter_reset(struct net_device
*dev
)
262 unsigned long timeout
;
263 elp_device
*adapter
= dev
->priv
;
264 unsigned char orig_hcr
= adapter
->hcr_val
;
266 outb_control(0, dev
);
268 if (inb_status(dev
->base_addr
) & ACRF
) {
270 inb_command(dev
->base_addr
);
271 timeout
= jiffies
+ 2*HZ
/100;
272 while (time_before_eq(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & ACRF
));
273 } while (inb_status(dev
->base_addr
) & ACRF
);
274 set_hsf(dev
, HSF_PCB_NAK
);
276 outb_control(adapter
->hcr_val
| ATTN
| DIR, dev
);
278 outb_control(adapter
->hcr_val
& ~ATTN
, dev
);
280 outb_control(adapter
->hcr_val
| FLSH
, dev
);
282 outb_control(adapter
->hcr_val
& ~FLSH
, dev
);
285 outb_control(orig_hcr
, dev
);
286 if (!start_receive(dev
, &adapter
->tx_pcb
))
287 printk(KERN_ERR
"%s: start receive command failed \n", dev
->name
);
290 /* Check to make sure that a DMA transfer hasn't timed out. This should
291 * never happen in theory, but seems to occur occasionally if the card gets
292 * prodded at the wrong time.
294 static inline void check_3c505_dma(struct net_device
*dev
)
296 elp_device
*adapter
= dev
->priv
;
297 if (adapter
->dmaing
&& time_after(jiffies
, adapter
->current_dma
.start_time
+ 10)) {
298 unsigned long flags
, f
;
299 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
));
300 spin_lock_irqsave(&adapter
->lock
, flags
);
305 disable_dma(dev
->dma
);
308 if (adapter
->rx_active
)
309 adapter
->rx_active
--;
310 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
311 spin_unlock_irqrestore(&adapter
->lock
, flags
);
315 /* Primitive functions used by send_pcb() */
316 static inline bool send_pcb_slow(unsigned int base_addr
, unsigned char byte
)
318 unsigned long timeout
;
319 outb_command(byte
, base_addr
);
320 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
321 if (inb_status(base_addr
) & HCRE
)
324 printk(KERN_WARNING
"3c505: send_pcb_slow timed out\n");
328 static inline bool send_pcb_fast(unsigned int base_addr
, unsigned char byte
)
330 unsigned int timeout
;
331 outb_command(byte
, base_addr
);
332 for (timeout
= 0; timeout
< 40000; timeout
++) {
333 if (inb_status(base_addr
) & HCRE
)
336 printk(KERN_WARNING
"3c505: send_pcb_fast timed out\n");
340 /* Check to see if the receiver needs restarting, and kick it if so */
341 static inline void prime_rx(struct net_device
*dev
)
343 elp_device
*adapter
= dev
->priv
;
344 while (adapter
->rx_active
< ELP_RX_PCBS
&& netif_running(dev
)) {
345 if (!start_receive(dev
, &adapter
->itx_pcb
))
350 /*****************************************************************
353 * Send a PCB to the adapter.
355 * output byte to command reg --<--+
356 * wait until HCRE is non zero |
357 * loop until all bytes sent -->--+
358 * set HSF1 and HSF2 to 1
360 * wait until ASF give ACK or NAK
361 * set HSF1 and HSF2 to 0
363 *****************************************************************/
365 /* This can be quite slow -- the adapter is allowed to take up to 40ms
366 * to respond to the initial interrupt.
368 * We run initially with interrupts turned on, but with a semaphore set
369 * so that nobody tries to re-enter this code. Once the first byte has
370 * gone through, we turn interrupts off and then send the others (the
371 * timeout is reduced to 500us).
374 static bool send_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
377 unsigned long timeout
;
378 elp_device
*adapter
= dev
->priv
;
381 check_3c505_dma(dev
);
383 if (adapter
->dmaing
&& adapter
->current_dma
.direction
== 0)
386 /* Avoid contention */
387 if (test_and_set_bit(1, &adapter
->send_pcb_semaphore
)) {
388 if (elp_debug
>= 3) {
389 printk(KERN_DEBUG
"%s: send_pcb entered while threaded\n", dev
->name
);
394 * load each byte into the command register and
395 * wait for the HCRE bit to indicate the adapter
400 if (send_pcb_slow(dev
->base_addr
, pcb
->command
))
403 spin_lock_irqsave(&adapter
->lock
, flags
);
405 if (send_pcb_fast(dev
->base_addr
, pcb
->length
))
408 for (i
= 0; i
< pcb
->length
; i
++) {
409 if (send_pcb_fast(dev
->base_addr
, pcb
->data
.raw
[i
]))
413 outb_control(adapter
->hcr_val
| 3, dev
); /* signal end of PCB */
414 outb_command(2 + pcb
->length
, dev
->base_addr
);
416 /* now wait for the acknowledgement */
417 spin_unlock_irqrestore(&adapter
->lock
, flags
);
419 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
420 switch (GET_ASF(dev
->base_addr
)) {
422 adapter
->send_pcb_semaphore
= 0;
427 printk(KERN_DEBUG
"%s: send_pcb got NAK\n", dev
->name
);
434 printk(KERN_DEBUG
"%s: timeout waiting for PCB acknowledge (status %02x)\n", dev
->name
, inb_status(dev
->base_addr
));
438 spin_unlock_irqrestore(&adapter
->lock
, flags
);
440 adapter
->send_pcb_semaphore
= 0;
445 /*****************************************************************
448 * Read a PCB from the adapter
450 * wait for ACRF to be non-zero ---<---+
452 * if ASF1 and ASF2 were not both one |
453 * before byte was read, loop --->---+
454 * set HSF1 and HSF2 for ack
456 *****************************************************************/
458 static bool receive_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
463 unsigned long timeout
;
466 elp_device
*adapter
= dev
->priv
;
470 /* get the command code */
471 timeout
= jiffies
+ 2*HZ
/100;
472 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
473 if (time_after_eq(jiffies
, timeout
)) {
474 TIMEOUT_MSG(__LINE__
);
477 pcb
->command
= inb_command(dev
->base_addr
);
479 /* read the data length */
480 timeout
= jiffies
+ 3*HZ
/100;
481 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
482 if (time_after_eq(jiffies
, timeout
)) {
483 TIMEOUT_MSG(__LINE__
);
484 printk(KERN_INFO
"%s: status %02x\n", dev
->name
, stat
);
487 pcb
->length
= inb_command(dev
->base_addr
);
489 if (pcb
->length
> MAX_PCB_DATA
) {
490 INVALID_PCB_MSG(pcb
->length
);
495 spin_lock_irqsave(&adapter
->lock
, flags
);
499 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && j
++ < 20000);
500 pcb
->data
.raw
[i
++] = inb_command(dev
->base_addr
);
501 if (i
> MAX_PCB_DATA
)
503 } while ((stat
& ASF_PCB_MASK
) != ASF_PCB_END
&& j
< 20000);
504 spin_unlock_irqrestore(&adapter
->lock
, flags
);
506 TIMEOUT_MSG(__LINE__
);
509 /* woops, the last "data" byte was really the length! */
510 total_length
= pcb
->data
.raw
[--i
];
512 /* safety check total length vs data length */
513 if (total_length
!= (pcb
->length
+ 2)) {
515 printk(KERN_WARNING
"%s: mangled PCB received\n", dev
->name
);
516 set_hsf(dev
, HSF_PCB_NAK
);
520 if (pcb
->command
== CMD_RECEIVE_PACKET_COMPLETE
) {
521 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
522 if (backlog_next(adapter
->rx_backlog
.in
) == adapter
->rx_backlog
.out
) {
523 set_hsf(dev
, HSF_PCB_NAK
);
524 printk(KERN_WARNING
"%s: PCB rejected, transfer in progress and backlog full\n", dev
->name
);
532 set_hsf(dev
, HSF_PCB_ACK
);
536 /******************************************************
538 * queue a receive command on the adapter so we will get an
539 * interrupt when a packet is received.
541 ******************************************************/
543 static bool start_receive(struct net_device
*dev
, pcb_struct
* tx_pcb
)
546 elp_device
*adapter
= dev
->priv
;
549 printk(KERN_DEBUG
"%s: restarting receiver\n", dev
->name
);
550 tx_pcb
->command
= CMD_RECEIVE_PACKET
;
551 tx_pcb
->length
= sizeof(struct Rcv_pkt
);
552 tx_pcb
->data
.rcv_pkt
.buf_seg
553 = tx_pcb
->data
.rcv_pkt
.buf_ofs
= 0; /* Unused */
554 tx_pcb
->data
.rcv_pkt
.buf_len
= 1600;
555 tx_pcb
->data
.rcv_pkt
.timeout
= 0; /* set timeout to zero */
556 status
= send_pcb(dev
, tx_pcb
);
558 adapter
->rx_active
++;
562 /******************************************************
564 * extract a packet from the adapter
565 * this routine is only called from within the interrupt
566 * service routine, so no cli/sti calls are needed
567 * note that the length is always assumed to be even
569 ******************************************************/
571 static void receive_packet(struct net_device
*dev
, int len
)
574 elp_device
*adapter
= dev
->priv
;
579 rlen
= (len
+ 1) & ~1;
580 skb
= dev_alloc_skb(rlen
+ 2);
583 printk(KERN_WARNING
"%s: memory squeeze, dropping packet\n", dev
->name
);
584 target
= adapter
->dma_buffer
;
585 adapter
->current_dma
.target
= NULL
;
591 target
= skb_put(skb
, rlen
);
592 if ((unsigned long)(target
+ rlen
) >= MAX_DMA_ADDRESS
) {
593 adapter
->current_dma
.target
= target
;
594 target
= adapter
->dma_buffer
;
596 adapter
->current_dma
.target
= NULL
;
599 /* if this happens, we die */
600 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
601 printk(KERN_ERR
"%s: rx blocked, DMA in progress, dir %d\n", dev
->name
, adapter
->current_dma
.direction
);
603 adapter
->current_dma
.direction
= 0;
604 adapter
->current_dma
.length
= rlen
;
605 adapter
->current_dma
.skb
= skb
;
606 adapter
->current_dma
.start_time
= jiffies
;
608 outb_control(adapter
->hcr_val
| DIR | TCEN
| DMAE
, dev
);
610 flags
=claim_dma_lock();
611 disable_dma(dev
->dma
);
612 clear_dma_ff(dev
->dma
);
613 set_dma_mode(dev
->dma
, 0x04); /* dma read */
614 set_dma_addr(dev
->dma
, isa_virt_to_bus(target
));
615 set_dma_count(dev
->dma
, rlen
);
616 enable_dma(dev
->dma
);
617 release_dma_lock(flags
);
619 if (elp_debug
>= 3) {
620 printk(KERN_DEBUG
"%s: rx DMA transfer started\n", dev
->name
);
623 if (adapter
->rx_active
)
624 adapter
->rx_active
--;
627 printk(KERN_WARNING
"%s: receive_packet called, busy not set.\n", dev
->name
);
630 /******************************************************
634 ******************************************************/
636 static irqreturn_t
elp_interrupt(int irq
, void *dev_id
)
641 struct net_device
*dev
;
643 unsigned long timeout
;
646 adapter
= (elp_device
*) dev
->priv
;
648 spin_lock(&adapter
->lock
);
652 * has a DMA transfer finished?
654 if (inb_status(dev
->base_addr
) & DONE
) {
655 if (!adapter
->dmaing
) {
656 printk(KERN_WARNING
"%s: phantom DMA completed\n", dev
->name
);
658 if (elp_debug
>= 3) {
659 printk(KERN_DEBUG
"%s: %s DMA complete, status %02x\n", dev
->name
, adapter
->current_dma
.direction
? "tx" : "rx", inb_status(dev
->base_addr
));
662 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
663 if (adapter
->current_dma
.direction
) {
664 dev_kfree_skb_irq(adapter
->current_dma
.skb
);
666 struct sk_buff
*skb
= adapter
->current_dma
.skb
;
668 if (adapter
->current_dma
.target
) {
669 /* have already done the skb_put() */
670 memcpy(adapter
->current_dma
.target
, adapter
->dma_buffer
, adapter
->current_dma
.length
);
672 skb
->protocol
= eth_type_trans(skb
,dev
);
673 adapter
->stats
.rx_bytes
+= skb
->len
;
675 dev
->last_rx
= jiffies
;
679 if (adapter
->rx_backlog
.in
!= adapter
->rx_backlog
.out
) {
680 int t
= adapter
->rx_backlog
.length
[adapter
->rx_backlog
.out
];
681 adapter
->rx_backlog
.out
= backlog_next(adapter
->rx_backlog
.out
);
683 printk(KERN_DEBUG
"%s: receiving backlogged packet (%d)\n", dev
->name
, t
);
684 receive_packet(dev
, t
);
689 /* has one timed out? */
690 check_3c505_dma(dev
);
694 * receive a PCB from the adapter
696 timeout
= jiffies
+ 3*HZ
/100;
697 while ((inb_status(dev
->base_addr
) & ACRF
) != 0 && time_before(jiffies
, timeout
)) {
698 if (receive_pcb(dev
, &adapter
->irx_pcb
)) {
699 switch (adapter
->irx_pcb
.command
)
704 * received a packet - this must be handled fast
707 case CMD_RECEIVE_PACKET_COMPLETE
:
708 /* if the device isn't open, don't pass packets up the stack */
709 if (!netif_running(dev
))
711 len
= adapter
->irx_pcb
.data
.rcv_resp
.pkt_len
;
712 dlen
= adapter
->irx_pcb
.data
.rcv_resp
.buf_len
;
713 if (adapter
->irx_pcb
.data
.rcv_resp
.timeout
!= 0) {
714 printk(KERN_ERR
"%s: interrupt - packet not received correctly\n", dev
->name
);
716 if (elp_debug
>= 3) {
717 printk(KERN_DEBUG
"%s: interrupt - packet received of length %i (%i)\n", dev
->name
, len
, dlen
);
719 if (adapter
->irx_pcb
.command
== 0xff) {
721 printk(KERN_DEBUG
"%s: adding packet to backlog (len = %d)\n", dev
->name
, dlen
);
722 adapter
->rx_backlog
.length
[adapter
->rx_backlog
.in
] = dlen
;
723 adapter
->rx_backlog
.in
= backlog_next(adapter
->rx_backlog
.in
);
725 receive_packet(dev
, dlen
);
728 printk(KERN_DEBUG
"%s: packet received\n", dev
->name
);
733 * 82586 configured correctly
735 case CMD_CONFIGURE_82586_RESPONSE
:
736 adapter
->got
[CMD_CONFIGURE_82586
] = 1;
738 printk(KERN_DEBUG
"%s: interrupt - configure response received\n", dev
->name
);
742 * Adapter memory configuration
744 case CMD_CONFIGURE_ADAPTER_RESPONSE
:
745 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 1;
747 printk(KERN_DEBUG
"%s: Adapter memory configuration %s.\n", dev
->name
,
748 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
752 * Multicast list loading
754 case CMD_LOAD_MULTICAST_RESPONSE
:
755 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 1;
757 printk(KERN_DEBUG
"%s: Multicast address list loading %s.\n", dev
->name
,
758 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
762 * Station address setting
764 case CMD_SET_ADDRESS_RESPONSE
:
765 adapter
->got
[CMD_SET_STATION_ADDRESS
] = 1;
767 printk(KERN_DEBUG
"%s: Ethernet address setting %s.\n", dev
->name
,
768 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
773 * received board statistics
775 case CMD_NETWORK_STATISTICS_RESPONSE
:
776 adapter
->stats
.rx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_recv
;
777 adapter
->stats
.tx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_xmit
;
778 adapter
->stats
.rx_crc_errors
+= adapter
->irx_pcb
.data
.netstat
.err_CRC
;
779 adapter
->stats
.rx_frame_errors
+= adapter
->irx_pcb
.data
.netstat
.err_align
;
780 adapter
->stats
.rx_fifo_errors
+= adapter
->irx_pcb
.data
.netstat
.err_ovrrun
;
781 adapter
->stats
.rx_over_errors
+= adapter
->irx_pcb
.data
.netstat
.err_res
;
782 adapter
->got
[CMD_NETWORK_STATISTICS
] = 1;
784 printk(KERN_DEBUG
"%s: interrupt - statistics response received\n", dev
->name
);
790 case CMD_TRANSMIT_PACKET_COMPLETE
:
792 printk(KERN_DEBUG
"%s: interrupt - packet sent\n", dev
->name
);
793 if (!netif_running(dev
))
795 switch (adapter
->irx_pcb
.data
.xmit_resp
.c_stat
) {
797 adapter
->stats
.tx_aborted_errors
++;
798 printk(KERN_INFO
"%s: transmit timed out, network cable problem?\n", dev
->name
);
801 adapter
->stats
.tx_fifo_errors
++;
802 printk(KERN_INFO
"%s: transmit timed out, FIFO underrun\n", dev
->name
);
805 netif_wake_queue(dev
);
812 printk(KERN_DEBUG
"%s: unknown PCB received - %2.2x\n", dev
->name
, adapter
->irx_pcb
.command
);
816 printk(KERN_WARNING
"%s: failed to read PCB on interrupt\n", dev
->name
);
821 } while (icount
++ < 5 && (inb_status(dev
->base_addr
) & (ACRF
| DONE
)));
826 * indicate no longer in interrupt routine
828 spin_unlock(&adapter
->lock
);
833 /******************************************************
837 ******************************************************/
839 static int elp_open(struct net_device
*dev
)
847 printk(KERN_DEBUG
"%s: request to open device\n", dev
->name
);
850 * make sure we actually found the device
852 if (adapter
== NULL
) {
853 printk(KERN_ERR
"%s: Opening a non-existent physical device\n", dev
->name
);
857 * disable interrupts on the board
859 outb_control(0, dev
);
862 * clear any pending interrupts
864 inb_command(dev
->base_addr
);
868 * no receive PCBs active
870 adapter
->rx_active
= 0;
873 adapter
->send_pcb_semaphore
= 0;
874 adapter
->rx_backlog
.in
= 0;
875 adapter
->rx_backlog
.out
= 0;
877 spin_lock_init(&adapter
->lock
);
880 * install our interrupt service routine
882 if ((retval
= request_irq(dev
->irq
, &elp_interrupt
, 0, dev
->name
, dev
))) {
883 printk(KERN_ERR
"%s: could not allocate IRQ%d\n", dev
->name
, dev
->irq
);
886 if ((retval
= request_dma(dev
->dma
, dev
->name
))) {
887 free_irq(dev
->irq
, dev
);
888 printk(KERN_ERR
"%s: could not allocate DMA%d channel\n", dev
->name
, dev
->dma
);
891 adapter
->dma_buffer
= (void *) dma_mem_alloc(DMA_BUFFER_SIZE
);
892 if (!adapter
->dma_buffer
) {
893 printk(KERN_ERR
"%s: could not allocate DMA buffer\n", dev
->name
);
895 free_irq(dev
->irq
, dev
);
901 * enable interrupts on the board
903 outb_control(CMDE
, dev
);
906 * configure adapter memory: we need 10 multicast addresses, default==0
909 printk(KERN_DEBUG
"%s: sending 3c505 memory configuration command\n", dev
->name
);
910 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
911 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 10;
912 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 20;
913 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
914 adapter
->tx_pcb
.data
.memconf
.frame
= 20;
915 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 20;
916 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
917 adapter
->tx_pcb
.length
= sizeof(struct Memconf
);
918 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 0;
919 if (!send_pcb(dev
, &adapter
->tx_pcb
))
920 printk(KERN_ERR
"%s: couldn't send memory configuration command\n", dev
->name
);
922 unsigned long timeout
= jiffies
+ TIMEOUT
;
923 while (adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] == 0 && time_before(jiffies
, timeout
));
924 if (time_after_eq(jiffies
, timeout
))
925 TIMEOUT_MSG(__LINE__
);
930 * configure adapter to receive broadcast messages and wait for response
933 printk(KERN_DEBUG
"%s: sending 82586 configure command\n", dev
->name
);
934 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
935 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
936 adapter
->tx_pcb
.length
= 2;
937 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
938 if (!send_pcb(dev
, &adapter
->tx_pcb
))
939 printk(KERN_ERR
"%s: couldn't send 82586 configure command\n", dev
->name
);
941 unsigned long timeout
= jiffies
+ TIMEOUT
;
942 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
943 if (time_after_eq(jiffies
, timeout
))
944 TIMEOUT_MSG(__LINE__
);
947 /* enable burst-mode DMA */
948 /* outb(0x1, dev->base_addr + PORT_AUXDMA); */
951 * queue receive commands to provide buffering
955 printk(KERN_DEBUG
"%s: %d receive PCBs active\n", dev
->name
, adapter
->rx_active
);
958 * device is now officially open!
961 netif_start_queue(dev
);
966 /******************************************************
968 * send a packet to the adapter
970 ******************************************************/
972 static bool send_packet(struct net_device
*dev
, struct sk_buff
*skb
)
974 elp_device
*adapter
= dev
->priv
;
975 unsigned long target
;
979 * make sure the length is even and no shorter than 60 bytes
981 unsigned int nlen
= (((skb
->len
< 60) ? 60 : skb
->len
) + 1) & (~1);
983 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
985 printk(KERN_DEBUG
"%s: transmit blocked\n", dev
->name
);
989 adapter
->stats
.tx_bytes
+= nlen
;
992 * send the adapter a transmit packet command. Ignore segment and offset
993 * and make sure the length is even
995 adapter
->tx_pcb
.command
= CMD_TRANSMIT_PACKET
;
996 adapter
->tx_pcb
.length
= sizeof(struct Xmit_pkt
);
997 adapter
->tx_pcb
.data
.xmit_pkt
.buf_ofs
998 = adapter
->tx_pcb
.data
.xmit_pkt
.buf_seg
= 0; /* Unused */
999 adapter
->tx_pcb
.data
.xmit_pkt
.pkt_len
= nlen
;
1001 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1005 /* if this happens, we die */
1006 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
1007 printk(KERN_DEBUG
"%s: tx: DMA %d in progress\n", dev
->name
, adapter
->current_dma
.direction
);
1009 adapter
->current_dma
.direction
= 1;
1010 adapter
->current_dma
.start_time
= jiffies
;
1012 if ((unsigned long)(skb
->data
+ nlen
) >= MAX_DMA_ADDRESS
|| nlen
!= skb
->len
) {
1013 skb_copy_from_linear_data(skb
, adapter
->dma_buffer
, nlen
);
1014 memset(adapter
->dma_buffer
+skb
->len
, 0, nlen
-skb
->len
);
1015 target
= isa_virt_to_bus(adapter
->dma_buffer
);
1018 target
= isa_virt_to_bus(skb
->data
);
1020 adapter
->current_dma
.skb
= skb
;
1022 flags
=claim_dma_lock();
1023 disable_dma(dev
->dma
);
1024 clear_dma_ff(dev
->dma
);
1025 set_dma_mode(dev
->dma
, 0x48); /* dma memory -> io */
1026 set_dma_addr(dev
->dma
, target
);
1027 set_dma_count(dev
->dma
, nlen
);
1028 outb_control(adapter
->hcr_val
| DMAE
| TCEN
, dev
);
1029 enable_dma(dev
->dma
);
1030 release_dma_lock(flags
);
1033 printk(KERN_DEBUG
"%s: DMA transfer started\n", dev
->name
);
1039 * The upper layer thinks we timed out
1042 static void elp_timeout(struct net_device
*dev
)
1044 elp_device
*adapter
= dev
->priv
;
1047 stat
= inb_status(dev
->base_addr
);
1048 printk(KERN_WARNING
"%s: transmit timed out, lost %s?\n", dev
->name
, (stat
& ACRF
) ? "interrupt" : "command");
1050 printk(KERN_DEBUG
"%s: status %#02x\n", dev
->name
, stat
);
1051 dev
->trans_start
= jiffies
;
1052 adapter
->stats
.tx_dropped
++;
1053 netif_wake_queue(dev
);
1056 /******************************************************
1058 * start the transmitter
1059 * return 0 if sent OK, else return 1
1061 ******************************************************/
1063 static int elp_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1065 unsigned long flags
;
1066 elp_device
*adapter
= dev
->priv
;
1068 spin_lock_irqsave(&adapter
->lock
, flags
);
1069 check_3c505_dma(dev
);
1072 printk(KERN_DEBUG
"%s: request to send packet of length %d\n", dev
->name
, (int) skb
->len
);
1074 netif_stop_queue(dev
);
1077 * send the packet at skb->data for skb->len
1079 if (!send_packet(dev
, skb
)) {
1080 if (elp_debug
>= 2) {
1081 printk(KERN_DEBUG
"%s: failed to transmit packet\n", dev
->name
);
1083 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1087 printk(KERN_DEBUG
"%s: packet of length %d sent\n", dev
->name
, (int) skb
->len
);
1090 * start the transmit timeout
1092 dev
->trans_start
= jiffies
;
1095 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1096 netif_start_queue(dev
);
1100 /******************************************************
1102 * return statistics on the board
1104 ******************************************************/
1106 static struct net_device_stats
*elp_get_stats(struct net_device
*dev
)
1108 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1111 printk(KERN_DEBUG
"%s: request for stats\n", dev
->name
);
1113 /* If the device is closed, just return the latest stats we have,
1114 - we cannot ask from the adapter without interrupts */
1115 if (!netif_running(dev
))
1116 return &adapter
->stats
;
1118 /* send a get statistics command to the board */
1119 adapter
->tx_pcb
.command
= CMD_NETWORK_STATISTICS
;
1120 adapter
->tx_pcb
.length
= 0;
1121 adapter
->got
[CMD_NETWORK_STATISTICS
] = 0;
1122 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1123 printk(KERN_ERR
"%s: couldn't send get statistics command\n", dev
->name
);
1125 unsigned long timeout
= jiffies
+ TIMEOUT
;
1126 while (adapter
->got
[CMD_NETWORK_STATISTICS
] == 0 && time_before(jiffies
, timeout
));
1127 if (time_after_eq(jiffies
, timeout
)) {
1128 TIMEOUT_MSG(__LINE__
);
1129 return &adapter
->stats
;
1133 /* statistics are now up to date */
1134 return &adapter
->stats
;
1138 static void netdev_get_drvinfo(struct net_device
*dev
,
1139 struct ethtool_drvinfo
*info
)
1141 strcpy(info
->driver
, DRV_NAME
);
1142 strcpy(info
->version
, DRV_VERSION
);
1143 sprintf(info
->bus_info
, "ISA 0x%lx", dev
->base_addr
);
1146 static u32
netdev_get_msglevel(struct net_device
*dev
)
1151 static void netdev_set_msglevel(struct net_device
*dev
, u32 level
)
1156 static const struct ethtool_ops netdev_ethtool_ops
= {
1157 .get_drvinfo
= netdev_get_drvinfo
,
1158 .get_msglevel
= netdev_get_msglevel
,
1159 .set_msglevel
= netdev_set_msglevel
,
1162 /******************************************************
1166 ******************************************************/
1168 static int elp_close(struct net_device
*dev
)
1170 elp_device
*adapter
;
1172 adapter
= dev
->priv
;
1175 printk(KERN_DEBUG
"%s: request to close device\n", dev
->name
);
1177 netif_stop_queue(dev
);
1179 /* Someone may request the device statistic information even when
1180 * the interface is closed. The following will update the statistics
1181 * structure in the driver, so we'll be able to give current statistics.
1183 (void) elp_get_stats(dev
);
1186 * disable interrupts on the board
1188 outb_control(0, dev
);
1193 free_irq(dev
->irq
, dev
);
1196 free_pages((unsigned long) adapter
->dma_buffer
, get_order(DMA_BUFFER_SIZE
));
1202 /************************************************************
1204 * Set multicast list
1205 * num_addrs==0: clear mc_list
1206 * num_addrs==-1: set promiscuous mode
1207 * num_addrs>0: set mc_list
1209 ************************************************************/
1211 static void elp_set_mc_list(struct net_device
*dev
)
1213 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1214 struct dev_mc_list
*dmi
= dev
->mc_list
;
1216 unsigned long flags
;
1219 printk(KERN_DEBUG
"%s: request to set multicast list\n", dev
->name
);
1221 spin_lock_irqsave(&adapter
->lock
, flags
);
1223 if (!(dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
))) {
1224 /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1225 /* if num_addrs==0 the list will be cleared */
1226 adapter
->tx_pcb
.command
= CMD_LOAD_MULTICAST_LIST
;
1227 adapter
->tx_pcb
.length
= 6 * dev
->mc_count
;
1228 for (i
= 0; i
< dev
->mc_count
; i
++) {
1229 memcpy(adapter
->tx_pcb
.data
.multicast
[i
], dmi
->dmi_addr
, 6);
1232 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 0;
1233 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1234 printk(KERN_ERR
"%s: couldn't send set_multicast command\n", dev
->name
);
1236 unsigned long timeout
= jiffies
+ TIMEOUT
;
1237 while (adapter
->got
[CMD_LOAD_MULTICAST_LIST
] == 0 && time_before(jiffies
, timeout
));
1238 if (time_after_eq(jiffies
, timeout
)) {
1239 TIMEOUT_MSG(__LINE__
);
1243 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
| RECV_MULTI
;
1244 else /* num_addrs == 0 */
1245 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
1247 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_PROMISC
;
1249 * configure adapter to receive messages (as specified above)
1250 * and wait for response
1253 printk(KERN_DEBUG
"%s: sending 82586 configure command\n", dev
->name
);
1254 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
1255 adapter
->tx_pcb
.length
= 2;
1256 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
1257 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1259 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1260 printk(KERN_ERR
"%s: couldn't send 82586 configure command\n", dev
->name
);
1263 unsigned long timeout
= jiffies
+ TIMEOUT
;
1264 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1265 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
1266 if (time_after_eq(jiffies
, timeout
))
1267 TIMEOUT_MSG(__LINE__
);
1271 /************************************************************
1273 * A couple of tests to see if there's 3C505 or not
1274 * Called only by elp_autodetect
1275 ************************************************************/
1277 static int __init
elp_sense(struct net_device
*dev
)
1279 int addr
= dev
->base_addr
;
1280 const char *name
= dev
->name
;
1283 if (!request_region(addr
, ELP_IO_EXTENT
, "3c505"))
1286 orig_HSR
= inb_status(addr
);
1289 printk(search_msg
, name
, addr
);
1291 if (orig_HSR
== 0xff) {
1293 printk(notfound_msg
, 1);
1297 /* Wait for a while; the adapter may still be booting up */
1299 printk(stilllooking_msg
);
1301 if (orig_HSR
& DIR) {
1302 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1303 outb(0, dev
->base_addr
+ PORT_CONTROL
);
1305 if (inb_status(addr
) & DIR) {
1307 printk(notfound_msg
, 2);
1311 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1312 outb(DIR, dev
->base_addr
+ PORT_CONTROL
);
1314 if (!(inb_status(addr
) & DIR)) {
1316 printk(notfound_msg
, 3);
1321 * It certainly looks like a 3c505.
1328 release_region(addr
, ELP_IO_EXTENT
);
1332 /*************************************************************
1334 * Search through addr_list[] and try to find a 3C505
1335 * Called only by eplus_probe
1336 *************************************************************/
1338 static int __init
elp_autodetect(struct net_device
*dev
)
1342 /* if base address set, then only check that address
1343 otherwise, run through the table */
1344 if (dev
->base_addr
!= 0) { /* dev->base_addr == 0 ==> plain autodetect */
1345 if (elp_sense(dev
) == 0)
1346 return dev
->base_addr
;
1348 while ((dev
->base_addr
= addr_list
[idx
++])) {
1349 if (elp_sense(dev
) == 0)
1350 return dev
->base_addr
;
1353 /* could not find an adapter */
1355 printk(couldnot_msg
, dev
->name
);
1357 return 0; /* Because of this, the layer above will return -ENODEV */
1361 /******************************************************
1363 * probe for an Etherlink Plus board at the specified address
1365 ******************************************************/
1367 /* There are three situations we need to be able to detect here:
1369 * a) the card is idle
1370 * b) the card is still booting up
1371 * c) the card is stuck in a strange state (some DOS drivers do this)
1373 * In case (a), all is well. In case (b), we wait 10 seconds to see if the
1374 * card finishes booting, and carry on if so. In case (c), we do a hard reset,
1375 * loop round, and hope for the best.
1377 * This is all very unpleasant, but hopefully avoids the problems with the old
1378 * probe code (which had a 15-second delay if the card was idle, and didn't
1379 * work at all if it was in a weird state).
1382 static int __init
elplus_setup(struct net_device
*dev
)
1384 elp_device
*adapter
= dev
->priv
;
1385 int i
, tries
, tries1
, okay
;
1386 unsigned long timeout
;
1387 unsigned long cookie
= 0;
1389 DECLARE_MAC_BUF(mac
);
1392 * setup adapter structure
1395 dev
->base_addr
= elp_autodetect(dev
);
1396 if (!dev
->base_addr
)
1399 adapter
->send_pcb_semaphore
= 0;
1401 for (tries1
= 0; tries1
< 3; tries1
++) {
1402 outb_control((adapter
->hcr_val
| CMDE
) & ~DIR, dev
);
1403 /* First try to write just one byte, to see if the card is
1404 * responding at all normally.
1406 timeout
= jiffies
+ 5*HZ
/100;
1408 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1409 if ((inb_status(dev
->base_addr
) & HCRE
)) {
1410 outb_command(0, dev
->base_addr
); /* send a spurious byte */
1411 timeout
= jiffies
+ 5*HZ
/100;
1412 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1413 if (inb_status(dev
->base_addr
) & HCRE
)
1417 /* Nope, it's ignoring the command register. This means that
1418 * either it's still booting up, or it's died.
1420 printk(KERN_ERR
"%s: command register wouldn't drain, ", dev
->name
);
1421 if ((inb_status(dev
->base_addr
) & 7) == 3) {
1422 /* If the adapter status is 3, it *could* still be booting.
1423 * Give it the benefit of the doubt for 10 seconds.
1425 printk("assuming 3c505 still starting\n");
1426 timeout
= jiffies
+ 10*HZ
;
1427 while (time_before(jiffies
, timeout
) && (inb_status(dev
->base_addr
) & 7));
1428 if (inb_status(dev
->base_addr
) & 7) {
1429 printk(KERN_ERR
"%s: 3c505 failed to start\n", dev
->name
);
1431 okay
= 1; /* It started */
1434 /* Otherwise, it must just be in a strange
1435 * state. We probably need to kick it.
1437 printk("3c505 is sulking\n");
1440 for (tries
= 0; tries
< 5 && okay
; tries
++) {
1443 * Try to set the Ethernet address, to make sure that the board
1446 adapter
->tx_pcb
.command
= CMD_STATION_ADDRESS
;
1447 adapter
->tx_pcb
.length
= 0;
1448 cookie
= probe_irq_on();
1449 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1450 printk(KERN_ERR
"%s: could not send first PCB\n", dev
->name
);
1451 probe_irq_off(cookie
);
1454 if (!receive_pcb(dev
, &adapter
->rx_pcb
)) {
1455 printk(KERN_ERR
"%s: could not read first PCB\n", dev
->name
);
1456 probe_irq_off(cookie
);
1459 if ((adapter
->rx_pcb
.command
!= CMD_ADDRESS_RESPONSE
) ||
1460 (adapter
->rx_pcb
.length
!= 6)) {
1461 printk(KERN_ERR
"%s: first PCB wrong (%d, %d)\n", dev
->name
, adapter
->rx_pcb
.command
, adapter
->rx_pcb
.length
);
1462 probe_irq_off(cookie
);
1467 /* It's broken. Do a hard reset to re-initialise the board,
1470 printk(KERN_INFO
"%s: resetting adapter\n", dev
->name
);
1471 outb_control(adapter
->hcr_val
| FLSH
| ATTN
, dev
);
1472 outb_control(adapter
->hcr_val
& ~(FLSH
| ATTN
), dev
);
1474 printk(KERN_ERR
"%s: failed to initialise 3c505\n", dev
->name
);
1478 if (dev
->irq
) { /* Is there a preset IRQ? */
1479 int rpt
= probe_irq_off(cookie
);
1480 if (dev
->irq
!= rpt
) {
1481 printk(KERN_WARNING
"%s: warning, irq %d configured but %d detected\n", dev
->name
, dev
->irq
, rpt
);
1483 /* if dev->irq == probe_irq_off(cookie), all is well */
1484 } else /* No preset IRQ; just use what we can detect */
1485 dev
->irq
= probe_irq_off(cookie
);
1486 switch (dev
->irq
) { /* Legal, sane? */
1488 printk(KERN_ERR
"%s: IRQ probe failed: check 3c505 jumpers.\n",
1495 printk(KERN_ERR
"%s: Impossible IRQ %d reported by probe_irq_off().\n",
1496 dev
->name
, dev
->irq
);
1500 * Now we have the IRQ number so we can disable the interrupts from
1501 * the board until the board is opened.
1503 outb_control(adapter
->hcr_val
& ~CMDE
, dev
);
1506 * copy Ethernet address into structure
1508 for (i
= 0; i
< 6; i
++)
1509 dev
->dev_addr
[i
] = adapter
->rx_pcb
.data
.eth_addr
[i
];
1511 /* find a DMA channel */
1513 if (dev
->mem_start
) {
1514 dev
->dma
= dev
->mem_start
& 7;
1517 printk(KERN_WARNING
"%s: warning, DMA channel not specified, using default\n", dev
->name
);
1523 * print remainder of startup message
1525 printk(KERN_INFO
"%s: 3c505 at %#lx, irq %d, dma %d, "
1527 dev
->name
, dev
->base_addr
, dev
->irq
, dev
->dma
,
1528 print_mac(mac
, dev
->dev_addr
));
1531 * read more information from the adapter
1534 adapter
->tx_pcb
.command
= CMD_ADAPTER_INFO
;
1535 adapter
->tx_pcb
.length
= 0;
1536 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1537 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1538 (adapter
->rx_pcb
.command
!= CMD_ADAPTER_INFO_RESPONSE
) ||
1539 (adapter
->rx_pcb
.length
!= 10)) {
1540 printk("not responding to second PCB\n");
1542 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
);
1545 * reconfigure the adapter memory to better suit our purposes
1547 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
1548 adapter
->tx_pcb
.length
= 12;
1549 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 8;
1550 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 8;
1551 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
1552 adapter
->tx_pcb
.data
.memconf
.frame
= 10;
1553 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 10;
1554 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
1555 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1556 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1557 (adapter
->rx_pcb
.command
!= CMD_CONFIGURE_ADAPTER_RESPONSE
) ||
1558 (adapter
->rx_pcb
.length
!= 2)) {
1559 printk(KERN_ERR
"%s: could not configure adapter memory\n", dev
->name
);
1561 if (adapter
->rx_pcb
.data
.configure
) {
1562 printk(KERN_ERR
"%s: adapter configuration failed\n", dev
->name
);
1565 dev
->open
= elp_open
; /* local */
1566 dev
->stop
= elp_close
; /* local */
1567 dev
->get_stats
= elp_get_stats
; /* local */
1568 dev
->hard_start_xmit
= elp_start_xmit
; /* local */
1569 dev
->tx_timeout
= elp_timeout
; /* local */
1570 dev
->watchdog_timeo
= 10*HZ
;
1571 dev
->set_multicast_list
= elp_set_mc_list
; /* local */
1572 dev
->ethtool_ops
= &netdev_ethtool_ops
; /* local */
1574 memset(&(adapter
->stats
), 0, sizeof(struct net_device_stats
));
1575 dev
->mem_start
= dev
->mem_end
= 0;
1577 err
= register_netdev(dev
);
1583 release_region(dev
->base_addr
, ELP_IO_EXTENT
);
1588 struct net_device
* __init
elplus_probe(int unit
)
1590 struct net_device
*dev
= alloc_etherdev(sizeof(elp_device
));
1593 return ERR_PTR(-ENOMEM
);
1595 sprintf(dev
->name
, "eth%d", unit
);
1596 netdev_boot_setup_check(dev
);
1598 err
= elplus_setup(dev
);
1601 return ERR_PTR(err
);
1607 static struct net_device
*dev_3c505
[ELP_MAX_CARDS
];
1608 static int io
[ELP_MAX_CARDS
];
1609 static int irq
[ELP_MAX_CARDS
];
1610 static int dma
[ELP_MAX_CARDS
];
1611 module_param_array(io
, int, NULL
, 0);
1612 module_param_array(irq
, int, NULL
, 0);
1613 module_param_array(dma
, int, NULL
, 0);
1614 MODULE_PARM_DESC(io
, "EtherLink Plus I/O base address(es)");
1615 MODULE_PARM_DESC(irq
, "EtherLink Plus IRQ number(s) (assigned)");
1616 MODULE_PARM_DESC(dma
, "EtherLink Plus DMA channel(s)");
1618 int __init
init_module(void)
1620 int this_dev
, found
= 0;
1622 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1623 struct net_device
*dev
= alloc_etherdev(sizeof(elp_device
));
1627 dev
->irq
= irq
[this_dev
];
1628 dev
->base_addr
= io
[this_dev
];
1629 if (dma
[this_dev
]) {
1630 dev
->dma
= dma
[this_dev
];
1633 printk(KERN_WARNING
"3c505.c: warning, using default DMA channel,\n");
1635 if (io
[this_dev
] == 0) {
1640 printk(KERN_NOTICE
"3c505.c: module autoprobe not recommended, give io=xx.\n");
1642 if (elplus_setup(dev
) != 0) {
1643 printk(KERN_WARNING
"3c505.c: Failed to register card at 0x%x.\n", io
[this_dev
]);
1647 dev_3c505
[this_dev
] = dev
;
1655 void __exit
cleanup_module(void)
1659 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1660 struct net_device
*dev
= dev_3c505
[this_dev
];
1662 unregister_netdev(dev
);
1663 release_region(dev
->base_addr
, ELP_IO_EXTENT
);
1670 MODULE_LICENSE("GPL");