2 * Linux Ethernet device driver for the 3Com Etherlink Plus (3C505)
3 * By Craig Southeren, Juha Laiho and Philip Blundell
5 * 3c505.c This module implements an interface to the 3Com
6 * Etherlink Plus (3c505) Ethernet card. Linux device
7 * driver interface reverse engineered from the Linux 3C509
8 * device drivers. Some 3C505 information gleaned from
9 * the Crynwr packet driver. Still this driver would not
10 * be here without 3C505 technical reference provided by
13 * $Id: 3c505.c,v 1.10 1996/04/16 13:06:27 phil Exp $
15 * Authors: Linux 3c505 device driver by
16 * Craig Southeren, <craigs@ineluki.apana.org.au>
18 * Andrew Tridgell, <tridge@nimbus.anu.edu.au>
19 * Auto irq/address, tuning, cleanup and v1.1.4+ kernel mods by
20 * Juha Laiho, <jlaiho@ichaos.nullnet.fi>
21 * Linux 3C509 driver by
22 * Donald Becker, <becker@super.org>
23 * Crynwr packet driver by
24 * Krishnan Gopalan and Gregg Stefancik,
25 * Clemson University Engineering Computer Operations.
26 * Portions of the code have been adapted from the 3c505
27 * driver for NCSA Telnet by Bruce Orchard and later
28 * modified by Warren Van Houten and krus@diku.dk.
29 * 3C505 technical information provided by
30 * Terry Murphy, of 3Com Network Adapter Division
31 * Linux 1.3.0 changes by
32 * Alan Cox <Alan.Cox@linux.org>
33 * More debugging, DMA support, currently maintained by
34 * Philip Blundell <Philip.Blundell@pobox.com>
35 * Multicard/soft configurable dma channel/rev 2 hardware support
36 * by Christopher Collins <ccollins@pcug.org.au>
39 /* Theory of operation:
41 * The 3c505 is quite an intelligent board. All communication with it is done
42 * by means of Primary Command Blocks (PCBs); these are transferred using PIO
43 * through the command register. The card has 256k of on-board RAM, which is
44 * used to buffer received packets. It might seem at first that more buffers
45 * are better, but in fact this isn't true. From my tests, it seems that
46 * more than about 10 buffers are unnecessary, and there is a noticeable
47 * performance hit in having more active on the card. So the majority of the
48 * card's memory isn't, in fact, used. Sadly, the card only has one transmit
49 * buffer and, short of loading our own firmware into it (which is what some
50 * drivers resort to) there's nothing we can do about this.
52 * We keep up to 4 "receive packet" commands active on the board at a time.
53 * When a packet comes in, so long as there is a receive command active, the
54 * board will send us a "packet received" PCB and then add the data for that
55 * packet to the DMA queue. If a DMA transfer is not already in progress, we
56 * set one up to start uploading the data. We have to maintain a list of
57 * backlogged receive packets, because the card may decide to tell us about
58 * a newly-arrived packet at any time, and we may not be able to start a DMA
59 * transfer immediately (ie one may already be going on). We can't NAK the
60 * PCB, because then it would throw the packet away.
62 * Trying to send a PCB to the card at the wrong moment seems to have bad
63 * effects. If we send it a transmit PCB while a receive DMA is happening,
64 * it will just NAK the PCB and so we will have wasted our time. Worse, it
65 * sometimes seems to interrupt the transfer. The majority of the low-level
66 * code is protected by one huge semaphore -- "busy" -- which is set whenever
67 * it probably isn't safe to do anything to the card. The receive routine
68 * must gain a lock on "busy" before it can start a DMA transfer, and the
69 * transmit routine must gain a lock before it sends the first PCB to the card.
70 * The send_pcb() routine also has an internal semaphore to protect it against
71 * being re-entered (which would be disastrous) -- this is needed because
72 * several things can happen asynchronously (re-priming the receiver and
73 * asking the card for statistics, for example). send_pcb() will also refuse
74 * to talk to the card at all if a DMA upload is happening. The higher-level
75 * networking code will reschedule a later retry if some part of the driver
76 * is blocked. In practice, this doesn't seem to happen very often.
79 /* This driver may now work with revision 2.x hardware, since all the read
80 * operations on the HCR have been removed (we now keep our own softcopy).
81 * But I don't have an old card to test it on.
83 * This has had the bad effect that the autoprobe routine is now a bit
84 * less friendly to other devices. However, it was never very good.
85 * before, so I doubt it will hurt anybody.
88 /* The driver is a mess. I took Craig's and Juha's code, and hacked it firstly
89 * to make it more reliable, and secondly to add DMA mode. Many things could
90 * probably be done better; the concurrency protection is particularly awful.
93 #include <linux/module.h>
95 #include <linux/kernel.h>
96 #include <linux/sched.h>
97 #include <linux/string.h>
98 #include <linux/interrupt.h>
99 #include <linux/ptrace.h>
100 #include <linux/errno.h>
101 #include <linux/in.h>
102 #include <linux/malloc.h>
103 #include <linux/ioport.h>
104 #include <linux/spinlock.h>
105 #include <asm/bitops.h>
109 #include <linux/netdevice.h>
110 #include <linux/etherdevice.h>
111 #include <linux/skbuff.h>
112 #include <linux/init.h>
116 /*********************************************************
118 * define debug messages here as common strings to reduce space
120 *********************************************************/
122 static const char *filename
= __FILE__
;
124 static const char *timeout_msg
= "*** timeout at %s:%s (line %d) ***\n";
125 #define TIMEOUT_MSG(lineno) \
126 printk(timeout_msg, filename,__FUNCTION__,(lineno))
128 static const char *invalid_pcb_msg
=
129 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
130 #define INVALID_PCB_MSG(len) \
131 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
133 static const char *search_msg
= "%s: Looking for 3c505 adapter at address %#x...";
135 static const char *stilllooking_msg
= "still looking...";
137 static const char *found_msg
= "found.\n";
139 static const char *notfound_msg
= "not found (reason = %d)\n";
141 static const char *couldnot_msg
= "%s: 3c505 not found\n";
143 /*********************************************************
145 * various other debug stuff
147 *********************************************************/
150 static const int elp_debug
= ELP_DEBUG
;
152 static const int elp_debug
= 0;
156 * 0 = no messages (well, some)
157 * 1 = messages when high level commands performed
158 * 2 = messages when low level commands performed
159 * 3 = messages when interrupts received
162 /*****************************************************************
166 *****************************************************************/
177 /*****************************************************************
179 * List of I/O-addresses we try to auto-sense
180 * Last element MUST BE 0!
181 *****************************************************************/
183 static const int addr_list
[] __initdata
= {0x300, 0x280, 0x310, 0};
185 /* Dma Memory related stuff */
187 static unsigned long dma_mem_alloc(int size
)
189 int order
= get_order(size
);
191 return __get_dma_pages(GFP_KERNEL
, order
);
195 /*****************************************************************
197 * Functions for I/O (note the inline !)
199 *****************************************************************/
201 static inline unsigned char inb_status(unsigned int base_addr
)
203 return inb(base_addr
+ PORT_STATUS
);
206 static inline int inb_command(unsigned int base_addr
)
208 return inb(base_addr
+ PORT_COMMAND
);
211 static inline void outb_control(unsigned char val
, struct net_device
*dev
)
213 outb(val
, dev
->base_addr
+ PORT_CONTROL
);
214 ((elp_device
*)(dev
->priv
))->hcr_val
= val
;
217 #define HCR_VAL(x) (((elp_device *)((x)->priv))->hcr_val)
219 static inline void outb_command(unsigned char val
, unsigned int base_addr
)
221 outb(val
, base_addr
+ PORT_COMMAND
);
224 static inline unsigned int inw_data(unsigned int base_addr
)
226 return inw(base_addr
+ PORT_DATA
);
229 static inline void outw_data(unsigned int val
, unsigned int base_addr
)
231 outw(val
, base_addr
+ PORT_DATA
);
234 static inline unsigned int backlog_next(unsigned int n
)
236 return (n
+ 1) % BACKLOG_SIZE
;
239 /*****************************************************************
241 * useful functions for accessing the adapter
243 *****************************************************************/
246 * use this routine when accessing the ASF bits as they are
247 * changed asynchronously by the adapter
250 /* get adapter PCB status */
251 #define GET_ASF(addr) \
252 (get_status(addr)&ASF_PCB_MASK)
254 static inline int get_status(unsigned int base_addr
)
256 int timeout
= jiffies
+ 10*HZ
/100;
259 stat1
= inb_status(base_addr
);
260 } while (stat1
!= inb_status(base_addr
) && time_before(jiffies
, timeout
));
261 if (time_after_eq(jiffies
, timeout
))
262 TIMEOUT_MSG(__LINE__
);
266 static inline void set_hsf(struct net_device
*dev
, int hsf
)
269 outb_control((HCR_VAL(dev
) & ~HSF_PCB_MASK
) | hsf
, dev
);
273 static int start_receive(struct net_device
*, pcb_struct
*);
275 inline static void adapter_reset(struct net_device
*dev
)
278 elp_device
*adapter
= dev
->priv
;
279 unsigned char orig_hcr
= adapter
->hcr_val
;
281 outb_control(0, dev
);
283 if (inb_status(dev
->base_addr
) & ACRF
) {
285 inb_command(dev
->base_addr
);
286 timeout
= jiffies
+ 2*HZ
/100;
287 while (time_before_eq(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & ACRF
));
288 } while (inb_status(dev
->base_addr
) & ACRF
);
289 set_hsf(dev
, HSF_PCB_NAK
);
291 outb_control(adapter
->hcr_val
| ATTN
| DIR, dev
);
292 timeout
= jiffies
+ 1*HZ
/100;
293 while (time_before_eq(jiffies
, timeout
));
294 outb_control(adapter
->hcr_val
& ~ATTN
, dev
);
295 timeout
= jiffies
+ 1*HZ
/100;
296 while (time_before_eq(jiffies
, timeout
));
297 outb_control(adapter
->hcr_val
| FLSH
, dev
);
298 timeout
= jiffies
+ 1*HZ
/100;
299 while (time_before_eq(jiffies
, timeout
));
300 outb_control(adapter
->hcr_val
& ~FLSH
, dev
);
301 timeout
= jiffies
+ 1*HZ
/100;
302 while (time_before_eq(jiffies
, timeout
));
304 outb_control(orig_hcr
, dev
);
305 if (!start_receive(dev
, &adapter
->tx_pcb
))
306 printk("%s: start receive command failed \n", dev
->name
);
309 /* Check to make sure that a DMA transfer hasn't timed out. This should
310 * never happen in theory, but seems to occur occasionally if the card gets
311 * prodded at the wrong time.
313 static inline void check_3c505_dma(struct net_device
*dev
)
315 elp_device
*adapter
= dev
->priv
;
316 if (adapter
->dmaing
&& time_after(jiffies
, adapter
->current_dma
.start_time
+ 10)) {
317 unsigned long flags
, f
;
318 printk("%s: DMA %s timed out, %d bytes left\n", dev
->name
, adapter
->current_dma
.direction
? "download" : "upload", get_dma_residue(dev
->dma
));
325 disable_dma(dev
->dma
);
328 if (adapter
->rx_active
)
329 adapter
->rx_active
--;
330 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
331 restore_flags(flags
);
335 /* Primitive functions used by send_pcb() */
336 static inline unsigned int send_pcb_slow(unsigned int base_addr
, unsigned char byte
)
338 unsigned int timeout
;
339 outb_command(byte
, base_addr
);
340 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
341 if (inb_status(base_addr
) & HCRE
)
344 printk("3c505: send_pcb_slow timed out\n");
348 static inline unsigned int send_pcb_fast(unsigned int base_addr
, unsigned char byte
)
350 unsigned int timeout
;
351 outb_command(byte
, base_addr
);
352 for (timeout
= 0; timeout
< 40000; timeout
++) {
353 if (inb_status(base_addr
) & HCRE
)
356 printk("3c505: send_pcb_fast timed out\n");
360 /* Check to see if the receiver needs restarting, and kick it if so */
361 static inline void prime_rx(struct net_device
*dev
)
363 elp_device
*adapter
= dev
->priv
;
364 while (adapter
->rx_active
< ELP_RX_PCBS
&& netif_running(dev
)) {
365 if (!start_receive(dev
, &adapter
->itx_pcb
))
370 /*****************************************************************
373 * Send a PCB to the adapter.
375 * output byte to command reg --<--+
376 * wait until HCRE is non zero |
377 * loop until all bytes sent -->--+
378 * set HSF1 and HSF2 to 1
380 * wait until ASF give ACK or NAK
381 * set HSF1 and HSF2 to 0
383 *****************************************************************/
385 /* This can be quite slow -- the adapter is allowed to take up to 40ms
386 * to respond to the initial interrupt.
388 * We run initially with interrupts turned on, but with a semaphore set
389 * so that nobody tries to re-enter this code. Once the first byte has
390 * gone through, we turn interrupts off and then send the others (the
391 * timeout is reduced to 500us).
394 static int send_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
398 elp_device
*adapter
= dev
->priv
;
400 check_3c505_dma(dev
);
402 if (adapter
->dmaing
&& adapter
->current_dma
.direction
== 0)
405 /* Avoid contention */
406 if (test_and_set_bit(1, &adapter
->send_pcb_semaphore
)) {
407 if (elp_debug
>= 3) {
408 printk("%s: send_pcb entered while threaded\n", dev
->name
);
413 * load each byte into the command register and
414 * wait for the HCRE bit to indicate the adapter
419 if (send_pcb_slow(dev
->base_addr
, pcb
->command
))
424 if (send_pcb_fast(dev
->base_addr
, pcb
->length
))
427 for (i
= 0; i
< pcb
->length
; i
++) {
428 if (send_pcb_fast(dev
->base_addr
, pcb
->data
.raw
[i
]))
432 outb_control(adapter
->hcr_val
| 3, dev
); /* signal end of PCB */
433 outb_command(2 + pcb
->length
, dev
->base_addr
);
435 /* now wait for the acknowledgement */
438 for (timeout
= jiffies
+ 5*HZ
/100; time_before(jiffies
, timeout
);) {
439 switch (GET_ASF(dev
->base_addr
)) {
441 adapter
->send_pcb_semaphore
= 0;
446 printk(KERN_DEBUG
"%s: send_pcb got NAK\n", dev
->name
);
454 printk("%s: timeout waiting for PCB acknowledge (status %02x)\n", dev
->name
, inb_status(dev
->base_addr
));
459 adapter
->send_pcb_semaphore
= 0;
464 /*****************************************************************
467 * Read a PCB from the adapter
469 * wait for ACRF to be non-zero ---<---+
471 * if ASF1 and ASF2 were not both one |
472 * before byte was read, loop --->---+
473 * set HSF1 and HSF2 for ack
475 *****************************************************************/
477 static int receive_pcb(struct net_device
*dev
, pcb_struct
* pcb
)
484 elp_device
*adapter
= dev
->priv
;
488 /* get the command code */
489 timeout
= jiffies
+ 2*HZ
/100;
490 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
491 if (time_after_eq(jiffies
, timeout
)) {
492 TIMEOUT_MSG(__LINE__
);
495 pcb
->command
= inb_command(dev
->base_addr
);
497 /* read the data length */
498 timeout
= jiffies
+ 3*HZ
/100;
499 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && time_before(jiffies
, timeout
));
500 if (time_after_eq(jiffies
, timeout
)) {
501 TIMEOUT_MSG(__LINE__
);
502 printk("%s: status %02x\n", dev
->name
, stat
);
505 pcb
->length
= inb_command(dev
->base_addr
);
507 if (pcb
->length
> MAX_PCB_DATA
) {
508 INVALID_PCB_MSG(pcb
->length
);
517 while (((stat
= get_status(dev
->base_addr
)) & ACRF
) == 0 && j
++ < 20000);
518 pcb
->data
.raw
[i
++] = inb_command(dev
->base_addr
);
519 if (i
> MAX_PCB_DATA
)
521 } while ((stat
& ASF_PCB_MASK
) != ASF_PCB_END
&& j
< 20000);
524 TIMEOUT_MSG(__LINE__
);
527 /* woops, the last "data" byte was really the length! */
528 total_length
= pcb
->data
.raw
[--i
];
530 /* safety check total length vs data length */
531 if (total_length
!= (pcb
->length
+ 2)) {
533 printk("%s: mangled PCB received\n", dev
->name
);
534 set_hsf(dev
, HSF_PCB_NAK
);
538 if (pcb
->command
== CMD_RECEIVE_PACKET_COMPLETE
) {
539 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
540 if (backlog_next(adapter
->rx_backlog
.in
) == adapter
->rx_backlog
.out
) {
541 set_hsf(dev
, HSF_PCB_NAK
);
542 printk("%s: PCB rejected, transfer in progress and backlog full\n", dev
->name
);
550 set_hsf(dev
, HSF_PCB_ACK
);
554 /******************************************************
556 * queue a receive command on the adapter so we will get an
557 * interrupt when a packet is received.
559 ******************************************************/
561 static int start_receive(struct net_device
*dev
, pcb_struct
* tx_pcb
)
564 elp_device
*adapter
= dev
->priv
;
567 printk("%s: restarting receiver\n", dev
->name
);
568 tx_pcb
->command
= CMD_RECEIVE_PACKET
;
569 tx_pcb
->length
= sizeof(struct Rcv_pkt
);
570 tx_pcb
->data
.rcv_pkt
.buf_seg
571 = tx_pcb
->data
.rcv_pkt
.buf_ofs
= 0; /* Unused */
572 tx_pcb
->data
.rcv_pkt
.buf_len
= 1600;
573 tx_pcb
->data
.rcv_pkt
.timeout
= 0; /* set timeout to zero */
574 status
= send_pcb(dev
, tx_pcb
);
576 adapter
->rx_active
++;
580 /******************************************************
582 * extract a packet from the adapter
583 * this routine is only called from within the interrupt
584 * service routine, so no cli/sti calls are needed
585 * note that the length is always assumed to be even
587 ******************************************************/
589 static void receive_packet(struct net_device
*dev
, int len
)
592 elp_device
*adapter
= dev
->priv
;
597 rlen
= (len
+ 1) & ~1;
598 skb
= dev_alloc_skb(rlen
+ 2);
601 printk("%s: memory squeeze, dropping packet\n", dev
->name
);
602 target
= adapter
->dma_buffer
;
603 adapter
->current_dma
.target
= NULL
;
606 target
= skb_put(skb
, rlen
);
607 if (virt_to_bus(target
+ rlen
) >= MAX_DMA_ADDRESS
) {
608 adapter
->current_dma
.target
= target
;
609 target
= adapter
->dma_buffer
;
611 adapter
->current_dma
.target
= NULL
;
615 /* if this happens, we die */
616 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
617 printk("%s: rx blocked, DMA in progress, dir %d\n", dev
->name
, adapter
->current_dma
.direction
);
620 adapter
->current_dma
.direction
= 0;
621 adapter
->current_dma
.length
= rlen
;
622 adapter
->current_dma
.skb
= skb
;
623 adapter
->current_dma
.start_time
= jiffies
;
625 outb_control(adapter
->hcr_val
| DIR | TCEN
| DMAE
, dev
);
627 flags
=claim_dma_lock();
628 disable_dma(dev
->dma
);
629 clear_dma_ff(dev
->dma
);
630 set_dma_mode(dev
->dma
, 0x04); /* dma read */
631 set_dma_addr(dev
->dma
, virt_to_bus(target
));
632 set_dma_count(dev
->dma
, rlen
);
633 enable_dma(dev
->dma
);
634 release_dma_lock(flags
);
636 if (elp_debug
>= 3) {
637 printk("%s: rx DMA transfer started\n", dev
->name
);
640 if (adapter
->rx_active
)
641 adapter
->rx_active
--;
644 printk("%s: receive_packet called, busy not set.\n", dev
->name
);
647 /******************************************************
651 ******************************************************/
653 static void elp_interrupt(int irq
, void *dev_id
, struct pt_regs
*reg_ptr
)
658 struct net_device
*dev
;
663 adapter
= (elp_device
*) dev
->priv
;
665 spin_lock(&adapter
->lock
);
669 * has a DMA transfer finished?
671 if (inb_status(dev
->base_addr
) & DONE
) {
672 if (!adapter
->dmaing
) {
673 printk("%s: phantom DMA completed\n", dev
->name
);
675 if (elp_debug
>= 3) {
676 printk("%s: %s DMA complete, status %02x\n", dev
->name
, adapter
->current_dma
.direction
? "tx" : "rx", inb_status(dev
->base_addr
));
679 outb_control(adapter
->hcr_val
& ~(DMAE
| TCEN
| DIR), dev
);
680 if (adapter
->current_dma
.direction
) {
681 dev_kfree_skb_irq(adapter
->current_dma
.skb
);
683 struct sk_buff
*skb
= adapter
->current_dma
.skb
;
685 if (adapter
->current_dma
.target
) {
686 /* have already done the skb_put() */
687 memcpy(adapter
->current_dma
.target
, adapter
->dma_buffer
, adapter
->current_dma
.length
);
689 skb
->protocol
= eth_type_trans(skb
,dev
);
690 adapter
->stats
.rx_bytes
+= skb
->len
;
695 if (adapter
->rx_backlog
.in
!= adapter
->rx_backlog
.out
) {
696 int t
= adapter
->rx_backlog
.length
[adapter
->rx_backlog
.out
];
697 adapter
->rx_backlog
.out
= backlog_next(adapter
->rx_backlog
.out
);
699 printk("%s: receiving backlogged packet (%d)\n", dev
->name
, t
);
700 receive_packet(dev
, t
);
705 /* has one timed out? */
706 check_3c505_dma(dev
);
710 * receive a PCB from the adapter
712 timeout
= jiffies
+ 3*HZ
/100;
713 while ((inb_status(dev
->base_addr
) & ACRF
) != 0 && time_before(jiffies
, timeout
)) {
714 if (receive_pcb(dev
, &adapter
->irx_pcb
)) {
715 switch (adapter
->irx_pcb
.command
)
720 * received a packet - this must be handled fast
723 case CMD_RECEIVE_PACKET_COMPLETE
:
724 /* if the device isn't open, don't pass packets up the stack */
725 if (!netif_running(dev
))
727 len
= adapter
->irx_pcb
.data
.rcv_resp
.pkt_len
;
728 dlen
= adapter
->irx_pcb
.data
.rcv_resp
.buf_len
;
729 if (adapter
->irx_pcb
.data
.rcv_resp
.timeout
!= 0) {
730 printk(KERN_ERR
"%s: interrupt - packet not received correctly\n", dev
->name
);
732 if (elp_debug
>= 3) {
733 printk("%s: interrupt - packet received of length %i (%i)\n", dev
->name
, len
, dlen
);
735 if (adapter
->irx_pcb
.command
== 0xff) {
737 printk("%s: adding packet to backlog (len = %d)\n", dev
->name
, dlen
);
738 adapter
->rx_backlog
.length
[adapter
->rx_backlog
.in
] = dlen
;
739 adapter
->rx_backlog
.in
= backlog_next(adapter
->rx_backlog
.in
);
741 receive_packet(dev
, dlen
);
744 printk("%s: packet received\n", dev
->name
);
749 * 82586 configured correctly
751 case CMD_CONFIGURE_82586_RESPONSE
:
752 adapter
->got
[CMD_CONFIGURE_82586
] = 1;
754 printk("%s: interrupt - configure response received\n", dev
->name
);
758 * Adapter memory configuration
760 case CMD_CONFIGURE_ADAPTER_RESPONSE
:
761 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 1;
763 printk("%s: Adapter memory configuration %s.\n", dev
->name
,
764 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
768 * Multicast list loading
770 case CMD_LOAD_MULTICAST_RESPONSE
:
771 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 1;
773 printk("%s: Multicast address list loading %s.\n", dev
->name
,
774 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
778 * Station address setting
780 case CMD_SET_ADDRESS_RESPONSE
:
781 adapter
->got
[CMD_SET_STATION_ADDRESS
] = 1;
783 printk("%s: Ethernet address setting %s.\n", dev
->name
,
784 adapter
->irx_pcb
.data
.failed
? "failed" : "succeeded");
789 * received board statistics
791 case CMD_NETWORK_STATISTICS_RESPONSE
:
792 adapter
->stats
.rx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_recv
;
793 adapter
->stats
.tx_packets
+= adapter
->irx_pcb
.data
.netstat
.tot_xmit
;
794 adapter
->stats
.rx_crc_errors
+= adapter
->irx_pcb
.data
.netstat
.err_CRC
;
795 adapter
->stats
.rx_frame_errors
+= adapter
->irx_pcb
.data
.netstat
.err_align
;
796 adapter
->stats
.rx_fifo_errors
+= adapter
->irx_pcb
.data
.netstat
.err_ovrrun
;
797 adapter
->stats
.rx_over_errors
+= adapter
->irx_pcb
.data
.netstat
.err_res
;
798 adapter
->got
[CMD_NETWORK_STATISTICS
] = 1;
800 printk("%s: interrupt - statistics response received\n", dev
->name
);
806 case CMD_TRANSMIT_PACKET_COMPLETE
:
808 printk("%s: interrupt - packet sent\n", dev
->name
);
809 if (!netif_running(dev
))
811 switch (adapter
->irx_pcb
.data
.xmit_resp
.c_stat
) {
813 adapter
->stats
.tx_aborted_errors
++;
814 printk(KERN_INFO
"%s: transmit timed out, network cable problem?\n", dev
->name
);
817 adapter
->stats
.tx_fifo_errors
++;
818 printk(KERN_INFO
"%s: transmit timed out, FIFO underrun\n", dev
->name
);
821 netif_wake_queue(dev
);
828 printk(KERN_DEBUG
"%s: unknown PCB received - %2.2x\n", dev
->name
, adapter
->irx_pcb
.command
);
832 printk("%s: failed to read PCB on interrupt\n", dev
->name
);
837 } while (icount
++ < 5 && (inb_status(dev
->base_addr
) & (ACRF
| DONE
)));
842 * indicate no longer in interrupt routine
844 spin_unlock(&adapter
->lock
);
848 /******************************************************
852 ******************************************************/
854 static int elp_open(struct net_device
*dev
)
861 printk("%s: request to open device\n", dev
->name
);
864 * make sure we actually found the device
866 if (adapter
== NULL
) {
867 printk("%s: Opening a non-existent physical device\n", dev
->name
);
871 * disable interrupts on the board
873 outb_control(0, dev
);
876 * clear any pending interrupts
878 inb_command(dev
->base_addr
);
882 * no receive PCBs active
884 adapter
->rx_active
= 0;
887 adapter
->send_pcb_semaphore
= 0;
888 adapter
->rx_backlog
.in
= 0;
889 adapter
->rx_backlog
.out
= 0;
891 spin_lock_init(&adapter
->lock
);
894 * install our interrupt service routine
896 if (request_irq(dev
->irq
, &elp_interrupt
, 0, "3c505", dev
)) {
899 if (request_dma(dev
->dma
, "3c505")) {
900 printk("%s: could not allocate DMA channel\n", dev
->name
);
903 adapter
->dma_buffer
= (void *) dma_mem_alloc(DMA_BUFFER_SIZE
);
904 if (!adapter
->dma_buffer
) {
905 printk("Could not allocate DMA buffer\n");
910 * enable interrupts on the board
912 outb_control(CMDE
, dev
);
915 * configure adapter memory: we need 10 multicast addresses, default==0
918 printk("%s: sending 3c505 memory configuration command\n", dev
->name
);
919 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
920 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 10;
921 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 20;
922 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
923 adapter
->tx_pcb
.data
.memconf
.frame
= 20;
924 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 20;
925 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
926 adapter
->tx_pcb
.length
= sizeof(struct Memconf
);
927 adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] = 0;
928 if (!send_pcb(dev
, &adapter
->tx_pcb
))
929 printk("%s: couldn't send memory configuration command\n", dev
->name
);
931 int timeout
= jiffies
+ TIMEOUT
;
932 while (adapter
->got
[CMD_CONFIGURE_ADAPTER_MEMORY
] == 0 && time_before(jiffies
, timeout
));
933 if (time_after_eq(jiffies
, timeout
))
934 TIMEOUT_MSG(__LINE__
);
939 * configure adapter to receive broadcast messages and wait for response
942 printk("%s: sending 82586 configure command\n", dev
->name
);
943 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
944 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
945 adapter
->tx_pcb
.length
= 2;
946 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
947 if (!send_pcb(dev
, &adapter
->tx_pcb
))
948 printk("%s: couldn't send 82586 configure command\n", dev
->name
);
950 int timeout
= jiffies
+ TIMEOUT
;
951 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
952 if (time_after_eq(jiffies
, timeout
))
953 TIMEOUT_MSG(__LINE__
);
956 /* enable burst-mode DMA */
957 /* outb(0x1, dev->base_addr + PORT_AUXDMA); */
960 * queue receive commands to provide buffering
964 printk("%s: %d receive PCBs active\n", dev
->name
, adapter
->rx_active
);
967 * device is now officially open!
970 netif_wake_queue(dev
);
973 return 0; /* Always succeed */
977 /******************************************************
979 * send a packet to the adapter
981 ******************************************************/
983 static int send_packet(struct net_device
*dev
, struct sk_buff
*skb
)
985 elp_device
*adapter
= dev
->priv
;
986 unsigned long target
;
990 * make sure the length is even and no shorter than 60 bytes
992 unsigned int nlen
= (((skb
->len
< 60) ? 60 : skb
->len
) + 1) & (~1);
994 if (test_and_set_bit(0, (void *) &adapter
->busy
)) {
996 printk("%s: transmit blocked\n", dev
->name
);
1000 adapter
->stats
.tx_bytes
+= nlen
;
1003 * send the adapter a transmit packet command. Ignore segment and offset
1004 * and make sure the length is even
1006 adapter
->tx_pcb
.command
= CMD_TRANSMIT_PACKET
;
1007 adapter
->tx_pcb
.length
= sizeof(struct Xmit_pkt
);
1008 adapter
->tx_pcb
.data
.xmit_pkt
.buf_ofs
1009 = adapter
->tx_pcb
.data
.xmit_pkt
.buf_seg
= 0; /* Unused */
1010 adapter
->tx_pcb
.data
.xmit_pkt
.pkt_len
= nlen
;
1012 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1016 /* if this happens, we die */
1017 if (test_and_set_bit(0, (void *) &adapter
->dmaing
))
1018 printk("%s: tx: DMA %d in progress\n", dev
->name
, adapter
->current_dma
.direction
);
1020 adapter
->current_dma
.direction
= 1;
1021 adapter
->current_dma
.start_time
= jiffies
;
1023 target
= virt_to_bus(skb
->data
);
1024 if ((target
+ nlen
) >= MAX_DMA_ADDRESS
) {
1025 memcpy(adapter
->dma_buffer
, skb
->data
, nlen
);
1026 target
= virt_to_bus(adapter
->dma_buffer
);
1028 adapter
->current_dma
.skb
= skb
;
1030 flags
=claim_dma_lock();
1031 disable_dma(dev
->dma
);
1032 clear_dma_ff(dev
->dma
);
1033 set_dma_mode(dev
->dma
, 0x48); /* dma memory -> io */
1034 set_dma_addr(dev
->dma
, target
);
1035 set_dma_count(dev
->dma
, nlen
);
1036 outb_control(adapter
->hcr_val
| DMAE
| TCEN
, dev
);
1037 enable_dma(dev
->dma
);
1038 release_dma_lock(flags
);
1041 printk("%s: DMA transfer started\n", dev
->name
);
1047 * The upper layer thinks we timed out
1050 static void elp_timeout(struct net_device
*dev
)
1052 unsigned long flags
;
1053 elp_device
*adapter
= dev
->priv
;
1056 stat
= inb_status(dev
->base_addr
);
1057 printk(KERN_WARNING
"%s: transmit timed out, lost %s?\n", dev
->name
, (stat
& ACRF
) ? "interrupt" : "command");
1059 printk("%s: status %#02x\n", dev
->name
, stat
);
1060 dev
->trans_start
= jiffies
;
1061 adapter
->stats
.tx_dropped
++;
1062 netif_wake_queue(dev
);
1065 /******************************************************
1067 * start the transmitter
1068 * return 0 if sent OK, else return 1
1070 ******************************************************/
1072 static int elp_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1074 unsigned long flags
;
1075 elp_device
*adapter
= dev
->priv
;
1077 spin_lock_irqsave(&adapter
->lock
, flags
);
1078 check_3c505_dma(dev
);
1081 printk("%s: request to send packet of length %d\n", dev
->name
, (int) skb
->len
);
1083 netif_stop_queue(dev
);
1086 * send the packet at skb->data for skb->len
1088 if (!send_packet(dev
, skb
)) {
1089 if (elp_debug
>= 2) {
1090 printk("%s: failed to transmit packet\n", dev
->name
);
1092 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1096 printk("%s: packet of length %d sent\n", dev
->name
, (int) skb
->len
);
1099 * start the transmit timeout
1101 dev
->trans_start
= jiffies
;
1104 spin_unlock_irqrestore(&adapter
->lock
, flags
);
1105 netif_start_queue(dev
);
1109 /******************************************************
1111 * return statistics on the board
1113 ******************************************************/
1115 static struct net_device_stats
*elp_get_stats(struct net_device
*dev
)
1117 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1120 printk("%s: request for stats\n", dev
->name
);
1122 /* If the device is closed, just return the latest stats we have,
1123 - we cannot ask from the adapter without interrupts */
1124 if (!netif_running(dev
))
1125 return &adapter
->stats
;
1127 /* send a get statistics command to the board */
1128 adapter
->tx_pcb
.command
= CMD_NETWORK_STATISTICS
;
1129 adapter
->tx_pcb
.length
= 0;
1130 adapter
->got
[CMD_NETWORK_STATISTICS
] = 0;
1131 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1132 printk("%s: couldn't send get statistics command\n", dev
->name
);
1134 int timeout
= jiffies
+ TIMEOUT
;
1135 while (adapter
->got
[CMD_NETWORK_STATISTICS
] == 0 && time_before(jiffies
, timeout
));
1136 if (time_after_eq(jiffies
, timeout
)) {
1137 TIMEOUT_MSG(__LINE__
);
1138 return &adapter
->stats
;
1142 /* statistics are now up to date */
1143 return &adapter
->stats
;
1146 /******************************************************
1150 ******************************************************/
1152 static int elp_close(struct net_device
*dev
)
1154 elp_device
*adapter
;
1156 adapter
= dev
->priv
;
1159 printk("%s: request to close device\n", dev
->name
);
1161 netif_stop_queue(dev
);
1163 /* Someone may request the device statistic information even when
1164 * the interface is closed. The following will update the statistics
1165 * structure in the driver, so we'll be able to give current statistics.
1167 (void) elp_get_stats(dev
);
1170 * disable interrupts on the board
1172 outb_control(0, dev
);
1177 free_irq(dev
->irq
, dev
);
1180 free_pages((unsigned long) adapter
->dma_buffer
, get_order(DMA_BUFFER_SIZE
));
1188 /************************************************************
1190 * Set multicast list
1191 * num_addrs==0: clear mc_list
1192 * num_addrs==-1: set promiscuous mode
1193 * num_addrs>0: set mc_list
1195 ************************************************************/
1197 static void elp_set_mc_list(struct net_device
*dev
)
1199 elp_device
*adapter
= (elp_device
*) dev
->priv
;
1200 struct dev_mc_list
*dmi
= dev
->mc_list
;
1202 unsigned long flags
;
1205 printk("%s: request to set multicast list\n", dev
->name
);
1207 spin_lock_irqsave(&adapter
->lock
, flags
);
1209 if (!(dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
))) {
1210 /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1211 /* if num_addrs==0 the list will be cleared */
1212 adapter
->tx_pcb
.command
= CMD_LOAD_MULTICAST_LIST
;
1213 adapter
->tx_pcb
.length
= 6 * dev
->mc_count
;
1214 for (i
= 0; i
< dev
->mc_count
; i
++) {
1215 memcpy(adapter
->tx_pcb
.data
.multicast
[i
], dmi
->dmi_addr
, 6);
1218 adapter
->got
[CMD_LOAD_MULTICAST_LIST
] = 0;
1219 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1220 printk("%s: couldn't send set_multicast command\n", dev
->name
);
1222 int timeout
= jiffies
+ TIMEOUT
;
1223 while (adapter
->got
[CMD_LOAD_MULTICAST_LIST
] == 0 && time_before(jiffies
, timeout
));
1224 if (time_after_eq(jiffies
, timeout
)) {
1225 TIMEOUT_MSG(__LINE__
);
1229 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
| RECV_MULTI
;
1230 else /* num_addrs == 0 */
1231 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_BROAD
;
1233 adapter
->tx_pcb
.data
.configure
= NO_LOOPBACK
| RECV_PROMISC
;
1235 * configure adapter to receive messages (as specified above)
1236 * and wait for response
1239 printk("%s: sending 82586 configure command\n", dev
->name
);
1240 adapter
->tx_pcb
.command
= CMD_CONFIGURE_82586
;
1241 adapter
->tx_pcb
.length
= 2;
1242 adapter
->got
[CMD_CONFIGURE_82586
] = 0;
1243 if (!send_pcb(dev
, &adapter
->tx_pcb
))
1245 spin_unlock_irqrestore(&lp
->lock
, flags
);
1246 printk("%s: couldn't send 82586 configure command\n", dev
->name
);
1249 int timeout
= jiffies
+ TIMEOUT
;
1250 spin_unlock_irqrestore(&lp
->lock
, flags
);
1251 while (adapter
->got
[CMD_CONFIGURE_82586
] == 0 && time_before(jiffies
, timeout
));
1252 if (time_after_eq(jiffies
, timeout
))
1253 TIMEOUT_MSG(__LINE__
);
1257 /******************************************************
1259 * initialise Etherlink Plus board
1261 ******************************************************/
1263 static inline void elp_init(struct net_device
*dev
)
1265 elp_device
*adapter
= dev
->priv
;
1268 * set ptrs to various functions
1270 dev
->open
= elp_open
; /* local */
1271 dev
->stop
= elp_close
; /* local */
1272 dev
->get_stats
= elp_get_stats
; /* local */
1273 dev
->hard_start_xmit
= elp_start_xmit
; /* local */
1274 dev
->tx_timeout
= elp_timeout
; /* local */
1275 dev
->watchdog_timeo
= 10*HZ
;
1276 dev
->set_multicast_list
= elp_set_mc_list
; /* local */
1278 /* Setup the generic properties */
1282 * setup ptr to adapter specific information
1284 memset(&(adapter
->stats
), 0, sizeof(struct net_device_stats
));
1287 * memory information
1289 dev
->mem_start
= dev
->mem_end
= dev
->rmem_end
= dev
->rmem_start
= 0;
1292 /************************************************************
1294 * A couple of tests to see if there's 3C505 or not
1295 * Called only by elp_autodetect
1296 ************************************************************/
1298 static int __init
elp_sense(struct net_device
*dev
)
1301 int addr
= dev
->base_addr
;
1302 const char *name
= dev
->name
;
1306 if (check_region(addr
, 0xf))
1309 orig_HSR
= inb_status(addr
);
1312 printk(search_msg
, name
, addr
);
1314 if (orig_HSR
== 0xff) {
1316 printk(notfound_msg
, 1);
1319 /* Enable interrupts - we need timers! */
1323 /* Wait for a while; the adapter may still be booting up */
1325 printk(stilllooking_msg
);
1327 if (orig_HSR
& DIR) {
1328 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1329 outb(0, dev
->base_addr
+ PORT_CONTROL
);
1330 timeout
= jiffies
+ 30*HZ
/100;
1331 while (time_before(jiffies
, timeout
));
1332 restore_flags(flags
);
1333 if (inb_status(addr
) & DIR) {
1335 printk(notfound_msg
, 2);
1339 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1340 outb(DIR, dev
->base_addr
+ PORT_CONTROL
);
1341 timeout
= jiffies
+ 30*HZ
/100;
1342 while (time_before(jiffies
, timeout
));
1343 restore_flags(flags
);
1344 if (!(inb_status(addr
) & DIR)) {
1346 printk(notfound_msg
, 3);
1351 * It certainly looks like a 3c505.
1359 /*************************************************************
1361 * Search through addr_list[] and try to find a 3C505
1362 * Called only by eplus_probe
1363 *************************************************************/
1365 static int __init
elp_autodetect(struct net_device
*dev
)
1369 /* if base address set, then only check that address
1370 otherwise, run through the table */
1371 if (dev
->base_addr
!= 0) { /* dev->base_addr == 0 ==> plain autodetect */
1372 if (elp_sense(dev
) == 0)
1373 return dev
->base_addr
;
1375 while ((dev
->base_addr
= addr_list
[idx
++])) {
1376 if (elp_sense(dev
) == 0)
1377 return dev
->base_addr
;
1380 /* could not find an adapter */
1382 printk(couldnot_msg
, dev
->name
);
1384 return 0; /* Because of this, the layer above will return -ENODEV */
1388 /******************************************************
1390 * probe for an Etherlink Plus board at the specified address
1392 ******************************************************/
1394 /* There are three situations we need to be able to detect here:
1396 * a) the card is idle
1397 * b) the card is still booting up
1398 * c) the card is stuck in a strange state (some DOS drivers do this)
1400 * In case (a), all is well. In case (b), we wait 10 seconds to see if the
1401 * card finishes booting, and carry on if so. In case (c), we do a hard reset,
1402 * loop round, and hope for the best.
1404 * This is all very unpleasant, but hopefully avoids the problems with the old
1405 * probe code (which had a 15-second delay if the card was idle, and didn't
1406 * work at all if it was in a weird state).
1409 int __init
elplus_probe(struct net_device
*dev
)
1411 elp_device
*adapter
;
1412 int i
, tries
, tries1
, timeout
, okay
;
1415 * setup adapter structure
1418 dev
->base_addr
= elp_autodetect(dev
);
1419 if (!(dev
->base_addr
))
1423 * setup ptr to adapter specific information
1425 adapter
= (elp_device
*) (dev
->priv
= kmalloc(sizeof(elp_device
), GFP_KERNEL
));
1426 if (adapter
== NULL
) {
1427 printk("%s: out of memory\n", dev
->name
);
1431 adapter
->send_pcb_semaphore
= 0;
1433 for (tries1
= 0; tries1
< 3; tries1
++) {
1434 outb_control((adapter
->hcr_val
| CMDE
) & ~DIR, dev
);
1435 /* First try to write just one byte, to see if the card is
1436 * responding at all normally.
1438 timeout
= jiffies
+ 5*HZ
/100;
1440 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1441 if ((inb_status(dev
->base_addr
) & HCRE
)) {
1442 outb_command(0, dev
->base_addr
); /* send a spurious byte */
1443 timeout
= jiffies
+ 5*HZ
/100;
1444 while (time_before(jiffies
, timeout
) && !(inb_status(dev
->base_addr
) & HCRE
));
1445 if (inb_status(dev
->base_addr
) & HCRE
)
1449 /* Nope, it's ignoring the command register. This means that
1450 * either it's still booting up, or it's died.
1452 printk("%s: command register wouldn't drain, ", dev
->name
);
1453 if ((inb_status(dev
->base_addr
) & 7) == 3) {
1454 /* If the adapter status is 3, it *could* still be booting.
1455 * Give it the benefit of the doubt for 10 seconds.
1457 printk("assuming 3c505 still starting\n");
1458 timeout
= jiffies
+ 10*HZ
;
1459 while (time_before(jiffies
, timeout
) && (inb_status(dev
->base_addr
) & 7));
1460 if (inb_status(dev
->base_addr
) & 7) {
1461 printk("%s: 3c505 failed to start\n", dev
->name
);
1463 okay
= 1; /* It started */
1466 /* Otherwise, it must just be in a strange
1467 * state. We probably need to kick it.
1469 printk("3c505 is sulking\n");
1472 for (tries
= 0; tries
< 5 && okay
; tries
++) {
1475 * Try to set the Ethernet address, to make sure that the board
1478 adapter
->tx_pcb
.command
= CMD_STATION_ADDRESS
;
1479 adapter
->tx_pcb
.length
= 0;
1481 if (!send_pcb(dev
, &adapter
->tx_pcb
)) {
1482 printk("%s: could not send first PCB\n", dev
->name
);
1486 if (!receive_pcb(dev
, &adapter
->rx_pcb
)) {
1487 printk("%s: could not read first PCB\n", dev
->name
);
1491 if ((adapter
->rx_pcb
.command
!= CMD_ADDRESS_RESPONSE
) ||
1492 (adapter
->rx_pcb
.length
!= 6)) {
1493 printk("%s: first PCB wrong (%d, %d)\n", dev
->name
, adapter
->rx_pcb
.command
, adapter
->rx_pcb
.length
);
1499 /* It's broken. Do a hard reset to re-initialise the board,
1502 printk(KERN_INFO
"%s: resetting adapter\n", dev
->name
);
1503 outb_control(adapter
->hcr_val
| FLSH
| ATTN
, dev
);
1504 outb_control(adapter
->hcr_val
& ~(FLSH
| ATTN
), dev
);
1506 printk("%s: failed to initialise 3c505\n", dev
->name
);
1510 if (dev
->irq
) { /* Is there a preset IRQ? */
1511 int rpt
= autoirq_report(0);
1512 if (dev
->irq
!= rpt
) {
1513 printk("%s: warning, irq %d configured but %d detected\n", dev
->name
, dev
->irq
, rpt
);
1515 /* if dev->irq == autoirq_report(0), all is well */
1516 } else /* No preset IRQ; just use what we can detect */
1517 dev
->irq
= autoirq_report(0);
1518 switch (dev
->irq
) { /* Legal, sane? */
1520 printk("%s: IRQ probe failed: check 3c505 jumpers.\n",
1527 printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1528 dev
->name
, dev
->irq
);
1532 * Now we have the IRQ number so we can disable the interrupts from
1533 * the board until the board is opened.
1535 outb_control(adapter
->hcr_val
& ~CMDE
, dev
);
1538 * copy Ethernet address into structure
1540 for (i
= 0; i
< 6; i
++)
1541 dev
->dev_addr
[i
] = adapter
->rx_pcb
.data
.eth_addr
[i
];
1543 /* find a DMA channel */
1545 if (dev
->mem_start
) {
1546 dev
->dma
= dev
->mem_start
& 7;
1549 printk(KERN_WARNING
"%s: warning, DMA channel not specified, using default\n", dev
->name
);
1555 * print remainder of startup message
1557 printk("%s: 3c505 at %#lx, irq %d, dma %d, ",
1558 dev
->name
, dev
->base_addr
, dev
->irq
, dev
->dma
);
1559 printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ",
1560 dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
1561 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
1564 * read more information from the adapter
1567 adapter
->tx_pcb
.command
= CMD_ADAPTER_INFO
;
1568 adapter
->tx_pcb
.length
= 0;
1569 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1570 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1571 (adapter
->rx_pcb
.command
!= CMD_ADAPTER_INFO_RESPONSE
) ||
1572 (adapter
->rx_pcb
.length
!= 10)) {
1573 printk("not responding to second PCB\n");
1575 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
);
1578 * reconfigure the adapter memory to better suit our purposes
1580 adapter
->tx_pcb
.command
= CMD_CONFIGURE_ADAPTER_MEMORY
;
1581 adapter
->tx_pcb
.length
= 12;
1582 adapter
->tx_pcb
.data
.memconf
.cmd_q
= 8;
1583 adapter
->tx_pcb
.data
.memconf
.rcv_q
= 8;
1584 adapter
->tx_pcb
.data
.memconf
.mcast
= 10;
1585 adapter
->tx_pcb
.data
.memconf
.frame
= 10;
1586 adapter
->tx_pcb
.data
.memconf
.rcv_b
= 10;
1587 adapter
->tx_pcb
.data
.memconf
.progs
= 0;
1588 if (!send_pcb(dev
, &adapter
->tx_pcb
) ||
1589 !receive_pcb(dev
, &adapter
->rx_pcb
) ||
1590 (adapter
->rx_pcb
.command
!= CMD_CONFIGURE_ADAPTER_RESPONSE
) ||
1591 (adapter
->rx_pcb
.length
!= 2)) {
1592 printk("%s: could not configure adapter memory\n", dev
->name
);
1594 if (adapter
->rx_pcb
.data
.configure
) {
1595 printk("%s: adapter configuration failed\n", dev
->name
);
1598 * and reserve the address region
1600 request_region(dev
->base_addr
, ELP_IO_EXTENT
, "3c505");
1603 * initialise the device
1612 static char devicename
[ELP_MAX_CARDS
][NAMELEN
] = {{0,}};
1613 static struct net_device dev_3c505
[ELP_MAX_CARDS
] =
1615 { NULL
, /* device name is inserted by net_init.c */
1618 0, 0, 0, NULL
, elplus_probe
},
1621 static int io
[ELP_MAX_CARDS
] = { 0, };
1622 static int irq
[ELP_MAX_CARDS
] = { 0, };
1623 static int dma
[ELP_MAX_CARDS
] = { 0, };
1624 MODULE_PARM(io
, "1-" __MODULE_STRING(ELP_MAX_CARDS
) "i");
1625 MODULE_PARM(irq
, "1-" __MODULE_STRING(ELP_MAX_CARDS
) "i");
1626 MODULE_PARM(dma
, "1-" __MODULE_STRING(ELP_MAX_CARDS
) "i");
1628 int init_module(void)
1630 int this_dev
, found
= 0;
1632 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1633 struct net_device
*dev
= &dev_3c505
[this_dev
];
1634 dev
->name
= devicename
[this_dev
];
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 printk(KERN_WARNING
"3c505.c: warning, using default DMA channel,\n");
1643 if (io
[this_dev
] == 0) {
1644 if (this_dev
) break;
1645 printk(KERN_NOTICE
"3c505.c: module autoprobe not recommended, give io=xx.\n");
1647 if (register_netdev(dev
) != 0) {
1648 printk(KERN_WARNING
"3c505.c: Failed to register card at 0x%x.\n", io
[this_dev
]);
1649 if (found
!= 0) return 0;
1657 void cleanup_module(void)
1661 for (this_dev
= 0; this_dev
< ELP_MAX_CARDS
; this_dev
++) {
1662 struct net_device
*dev
= &dev_3c505
[this_dev
];
1663 if (dev
->priv
!= NULL
) {
1664 unregister_netdev(dev
);
1667 release_region(dev
->base_addr
, ELP_IO_EXTENT
);