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.1.1.1 2005/04/11 02:50:26 jack 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 <Philip.Blundell@pobox.com>
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>
101 #include <linux/kernel.h>
102 #include <linux/sched.h>
103 #include <linux/string.h>
104 #include <linux/interrupt.h>
105 #include <linux/ptrace.h>
106 #include <linux/errno.h>
107 #include <linux/in.h>
108 #include <linux/slab.h>
109 #include <linux/ioport.h>
110 #include <linux/spinlock.h>
111 #include <linux/ethtool.h>
113 #include <asm/uaccess.h>
114 #include <asm/bitops.h>
118 #include <linux/netdevice.h>
119 #include <linux/etherdevice.h>
120 #include <linux/skbuff.h>
121 #include <linux/init.h>
125 /*********************************************************
127 * define debug messages here as common strings to reduce space
129 *********************************************************/
131 static const char filename[] = __FILE__;
133 static const char timeout_msg[] = "*** timeout at %s:%s (line %d) ***\n";
134 #define TIMEOUT_MSG(lineno) \
135 printk(timeout_msg, filename,__FUNCTION__,(lineno))
137 static const char invalid_pcb_msg[] =
138 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
139 #define INVALID_PCB_MSG(len) \
140 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
142 static char search_msg[] __initdata = "%s: Looking for 3c505 adapter at address %#x...";
144 static char stilllooking_msg[] __initdata = "still looking...";
146 static char found_msg[] __initdata = "found.\n";
148 static char notfound_msg[] __initdata = "not found (reason = %d)\n";
150 static char couldnot_msg[] __initdata = "%s: 3c505 not found\n";
152 /*********************************************************
154 * various other debug stuff
156 *********************************************************/
159 static int elp_debug = ELP_DEBUG;
161 static int elp_debug;
163 #define debug elp_debug
166 * 0 = no messages (well, some)
167 * 1 = messages when high level commands performed
168 * 2 = messages when low level commands performed
169 * 3 = messages when interrupts received
172 /*****************************************************************
176 *****************************************************************/
187 /*****************************************************************
189 * List of I/O-addresses we try to auto-sense
190 * Last element MUST BE 0!
191 *****************************************************************/
193 static int addr_list[] __initdata = {0x300, 0x280, 0x310, 0};
195 /* Dma Memory related stuff */
197 static unsigned long dma_mem_alloc(int size)
199 int order = get_order(size);
201 return __get_dma_pages(GFP_KERNEL, order);
205 /*****************************************************************
207 * Functions for I/O (note the inline !)
209 *****************************************************************/
211 static inline unsigned char inb_status(unsigned int base_addr)
213 return inb(base_addr + PORT_STATUS);
216 static inline int inb_command(unsigned int base_addr)
218 return inb(base_addr + PORT_COMMAND);
221 static inline void outb_control(unsigned char val, struct net_device *dev)
223 outb(val, dev->base_addr + PORT_CONTROL);
224 ((elp_device *)(dev->priv))->hcr_val = val;
227 #define HCR_VAL(x) (((elp_device *)((x)->priv))->hcr_val)
229 static inline void outb_command(unsigned char val, unsigned int base_addr)
231 outb(val, base_addr + PORT_COMMAND);
234 static inline unsigned int inw_data(unsigned int base_addr)
236 return inw(base_addr + PORT_DATA);
239 static inline void outw_data(unsigned int val, unsigned int base_addr)
241 outw(val, base_addr + PORT_DATA);
244 static inline unsigned int backlog_next(unsigned int n)
246 return (n + 1) % BACKLOG_SIZE;
249 /*****************************************************************
251 * useful functions for accessing the adapter
253 *****************************************************************/
256 * use this routine when accessing the ASF bits as they are
257 * changed asynchronously by the adapter
260 /* get adapter PCB status */
261 #define GET_ASF(addr) \
262 (get_status(addr)&ASF_PCB_MASK)
264 static inline int get_status(unsigned int base_addr)
266 int timeout = jiffies + 10*HZ/100;
269 stat1 = inb_status(base_addr);
270 } while (stat1 != inb_status(base_addr) && time_before(jiffies, timeout));
271 if (time_after_eq(jiffies, timeout))
272 TIMEOUT_MSG(__LINE__);
276 static inline void set_hsf(struct net_device *dev, int hsf)
279 outb_control((HCR_VAL(dev) & ~HSF_PCB_MASK) | hsf, dev);
283 static int start_receive(struct net_device *, pcb_struct *);
285 inline static void adapter_reset(struct net_device *dev)
288 elp_device *adapter = dev->priv;
289 unsigned char orig_hcr = adapter->hcr_val;
291 outb_control(0, dev);
293 if (inb_status(dev->base_addr) & ACRF) {
295 inb_command(dev->base_addr);
296 timeout = jiffies + 2*HZ/100;
297 while (time_before_eq(jiffies, timeout) && !(inb_status(dev->base_addr) & ACRF));
298 } while (inb_status(dev->base_addr) & ACRF);
299 set_hsf(dev, HSF_PCB_NAK);
301 outb_control(adapter->hcr_val | ATTN | DIR, dev);
302 timeout = jiffies + 1*HZ/100;
303 while (time_before_eq(jiffies, timeout));
304 outb_control(adapter->hcr_val & ~ATTN, dev);
305 timeout = jiffies + 1*HZ/100;
306 while (time_before_eq(jiffies, timeout));
307 outb_control(adapter->hcr_val | FLSH, dev);
308 timeout = jiffies + 1*HZ/100;
309 while (time_before_eq(jiffies, timeout));
310 outb_control(adapter->hcr_val & ~FLSH, dev);
311 timeout = jiffies + 1*HZ/100;
312 while (time_before_eq(jiffies, timeout));
314 outb_control(orig_hcr, dev);
315 if (!start_receive(dev, &adapter->tx_pcb))
316 printk("%s: start receive command failed \n", dev->name);
319 /* Check to make sure that a DMA transfer hasn't timed out. This should
320 * never happen in theory, but seems to occur occasionally if the card gets
321 * prodded at the wrong time.
323 static inline void check_3c505_dma(struct net_device *dev)
325 elp_device *adapter = dev->priv;
326 if (adapter->dmaing && time_after(jiffies, adapter->current_dma.start_time + 10)) {
327 unsigned long flags, f;
328 printk("%s: DMA %s timed out, %d bytes left\n", dev->name, adapter->current_dma.direction ? "download" : "upload", get_dma_residue(dev->dma));
335 disable_dma(dev->dma);
338 if (adapter->rx_active)
339 adapter->rx_active--;
340 outb_control(adapter->hcr_val & ~(DMAE | TCEN | DIR), dev);
341 restore_flags(flags);
345 /* Primitive functions used by send_pcb() */
346 static inline unsigned int send_pcb_slow(unsigned int base_addr, unsigned char byte)
348 unsigned int timeout;
349 outb_command(byte, base_addr);
350 for (timeout = jiffies + 5*HZ/100; time_before(jiffies, timeout);) {
351 if (inb_status(base_addr) & HCRE)
354 printk("3c505: send_pcb_slow timed out\n");
358 static inline unsigned int send_pcb_fast(unsigned int base_addr, unsigned char byte)
360 unsigned int timeout;
361 outb_command(byte, base_addr);
362 for (timeout = 0; timeout < 40000; timeout++) {
363 if (inb_status(base_addr) & HCRE)
366 printk("3c505: send_pcb_fast timed out\n");
370 /* Check to see if the receiver needs restarting, and kick it if so */
371 static inline void prime_rx(struct net_device *dev)
373 elp_device *adapter = dev->priv;
374 while (adapter->rx_active < ELP_RX_PCBS && netif_running(dev)) {
375 if (!start_receive(dev, &adapter->itx_pcb))
380 /*****************************************************************
383 * Send a PCB to the adapter.
385 * output byte to command reg --<--+
386 * wait until HCRE is non zero |
387 * loop until all bytes sent -->--+
388 * set HSF1 and HSF2 to 1
390 * wait until ASF give ACK or NAK
391 * set HSF1 and HSF2 to 0
393 *****************************************************************/
395 /* This can be quite slow -- the adapter is allowed to take up to 40ms
396 * to respond to the initial interrupt.
398 * We run initially with interrupts turned on, but with a semaphore set
399 * so that nobody tries to re-enter this code. Once the first byte has
400 * gone through, we turn interrupts off and then send the others (the
401 * timeout is reduced to 500us).
404 static int send_pcb(struct net_device *dev, pcb_struct * pcb)
408 elp_device *adapter = dev->priv;
410 check_3c505_dma(dev);
412 if (adapter->dmaing && adapter->current_dma.direction == 0)
415 /* Avoid contention */
416 if (test_and_set_bit(1, &adapter->send_pcb_semaphore)) {
417 if (elp_debug >= 3) {
418 printk("%s: send_pcb entered while threaded\n", dev->name);
423 * load each byte into the command register and
424 * wait for the HCRE bit to indicate the adapter
429 if (send_pcb_slow(dev->base_addr, pcb->command))
434 if (send_pcb_fast(dev->base_addr, pcb->length))
437 for (i = 0; i < pcb->length; i++) {
438 if (send_pcb_fast(dev->base_addr, pcb->data.raw[i]))
442 outb_control(adapter->hcr_val | 3, dev); /* signal end of PCB */
443 outb_command(2 + pcb->length, dev->base_addr);
445 /* now wait for the acknowledgement */
448 for (timeout = jiffies + 5*HZ/100; time_before(jiffies, timeout);) {
449 switch (GET_ASF(dev->base_addr)) {
451 adapter->send_pcb_semaphore = 0;
456 printk(KERN_DEBUG "%s: send_pcb got NAK\n", dev->name);
464 printk("%s: timeout waiting for PCB acknowledge (status %02x)\n", dev->name, inb_status(dev->base_addr));
469 adapter->send_pcb_semaphore = 0;
474 /*****************************************************************
477 * Read a PCB from the adapter
479 * wait for ACRF to be non-zero ---<---+
481 * if ASF1 and ASF2 were not both one |
482 * before byte was read, loop --->---+
483 * set HSF1 and HSF2 for ack
485 *****************************************************************/
487 static int receive_pcb(struct net_device *dev, pcb_struct * pcb)
494 elp_device *adapter = dev->priv;
498 /* get the command code */
499 timeout = jiffies + 2*HZ/100;
500 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && time_before(jiffies, timeout));
501 if (time_after_eq(jiffies, timeout)) {
502 TIMEOUT_MSG(__LINE__);
505 pcb->command = inb_command(dev->base_addr);
507 /* read the data length */
508 timeout = jiffies + 3*HZ/100;
509 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && time_before(jiffies, timeout));
510 if (time_after_eq(jiffies, timeout)) {
511 TIMEOUT_MSG(__LINE__);
512 printk("%s: status %02x\n", dev->name, stat);
515 pcb->length = inb_command(dev->base_addr);
517 if (pcb->length > MAX_PCB_DATA) {
518 INVALID_PCB_MSG(pcb->length);
527 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
528 pcb->data.raw[i++] = inb_command(dev->base_addr);
529 if (i > MAX_PCB_DATA)
531 } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
534 TIMEOUT_MSG(__LINE__);
537 /* woops, the last "data" byte was really the length! */
538 total_length = pcb->data.raw[--i];
540 /* safety check total length vs data length */
541 if (total_length != (pcb->length + 2)) {
543 printk("%s: mangled PCB received\n", dev->name);
544 set_hsf(dev, HSF_PCB_NAK);
548 if (pcb->command == CMD_RECEIVE_PACKET_COMPLETE) {
549 if (test_and_set_bit(0, (void *) &adapter->busy)) {
550 if (backlog_next(adapter->rx_backlog.in) == adapter->rx_backlog.out) {
551 set_hsf(dev, HSF_PCB_NAK);
552 printk("%s: PCB rejected, transfer in progress and backlog full\n", dev->name);
560 set_hsf(dev, HSF_PCB_ACK);
564 /******************************************************
566 * queue a receive command on the adapter so we will get an
567 * interrupt when a packet is received.
569 ******************************************************/
571 static int start_receive(struct net_device *dev, pcb_struct * tx_pcb)
574 elp_device *adapter = dev->priv;
577 printk("%s: restarting receiver\n", dev->name);
578 tx_pcb->command = CMD_RECEIVE_PACKET;
579 tx_pcb->length = sizeof(struct Rcv_pkt);
580 tx_pcb->data.rcv_pkt.buf_seg
581 = tx_pcb->data.rcv_pkt.buf_ofs = 0; /* Unused */
582 tx_pcb->data.rcv_pkt.buf_len = 1600;
583 tx_pcb->data.rcv_pkt.timeout = 0; /* set timeout to zero */
584 status = send_pcb(dev, tx_pcb);
586 adapter->rx_active++;
590 /******************************************************
592 * extract a packet from the adapter
593 * this routine is only called from within the interrupt
594 * service routine, so no cli/sti calls are needed
595 * note that the length is always assumed to be even
597 ******************************************************/
599 static void receive_packet(struct net_device *dev, int len)
602 elp_device *adapter = dev->priv;
607 rlen = (len + 1) & ~1;
608 skb = dev_alloc_skb(rlen + 2);
611 printk("%s: memory squeeze, dropping packet\n", dev->name);
612 target = adapter->dma_buffer;
613 adapter->current_dma.target = NULL;
618 target = skb_put(skb, rlen);
619 if ((unsigned long)(target + rlen) >= MAX_DMA_ADDRESS) {
620 adapter->current_dma.target = target;
621 target = adapter->dma_buffer;
623 adapter->current_dma.target = NULL;
626 /* if this happens, we die */
627 if (test_and_set_bit(0, (void *) &adapter->dmaing))
628 printk("%s: rx blocked, DMA in progress, dir %d\n", dev->name, adapter->current_dma.direction);
631 adapter->current_dma.direction = 0;
632 adapter->current_dma.length = rlen;
633 adapter->current_dma.skb = skb;
634 adapter->current_dma.start_time = jiffies;
636 outb_control(adapter->hcr_val | DIR | TCEN | DMAE, dev);
638 flags=claim_dma_lock();
639 disable_dma(dev->dma);
640 clear_dma_ff(dev->dma);
641 set_dma_mode(dev->dma, 0x04); /* dma read */
642 set_dma_addr(dev->dma, virt_to_bus(target));
643 set_dma_count(dev->dma, rlen);
644 enable_dma(dev->dma);
645 release_dma_lock(flags);
647 if (elp_debug >= 3) {
648 printk("%s: rx DMA transfer started\n", dev->name);
651 if (adapter->rx_active)
652 adapter->rx_active--;
655 printk("%s: receive_packet called, busy not set.\n", dev->name);
658 /******************************************************
662 ******************************************************/
664 static void elp_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr)
669 struct net_device *dev;
674 adapter = (elp_device *) dev->priv;
676 spin_lock(&adapter->lock);
680 * has a DMA transfer finished?
682 if (inb_status(dev->base_addr) & DONE) {
683 if (!adapter->dmaing) {
684 printk("%s: phantom DMA completed\n", dev->name);
686 if (elp_debug >= 3) {
687 printk("%s: %s DMA complete, status %02x\n", dev->name, adapter->current_dma.direction ? "tx" : "rx", inb_status(dev->base_addr));
690 outb_control(adapter->hcr_val & ~(DMAE | TCEN | DIR), dev);
691 if (adapter->current_dma.direction) {
692 dev_kfree_skb_irq(adapter->current_dma.skb);
694 struct sk_buff *skb = adapter->current_dma.skb;
696 if (adapter->current_dma.target) {
697 /* have already done the skb_put() */
698 memcpy(adapter->current_dma.target, adapter->dma_buffer, adapter->current_dma.length);
700 skb->protocol = eth_type_trans(skb,dev);
701 adapter->stats.rx_bytes += skb->len;
703 dev->last_rx = jiffies;
707 if (adapter->rx_backlog.in != adapter->rx_backlog.out) {
708 int t = adapter->rx_backlog.length[adapter->rx_backlog.out];
709 adapter->rx_backlog.out = backlog_next(adapter->rx_backlog.out);
711 printk("%s: receiving backlogged packet (%d)\n", dev->name, t);
712 receive_packet(dev, t);
717 /* has one timed out? */
718 check_3c505_dma(dev);
722 * receive a PCB from the adapter
724 timeout = jiffies + 3*HZ/100;
725 while ((inb_status(dev->base_addr) & ACRF) != 0 && time_before(jiffies, timeout)) {
726 if (receive_pcb(dev, &adapter->irx_pcb)) {
727 switch (adapter->irx_pcb.command)
732 * received a packet - this must be handled fast
735 case CMD_RECEIVE_PACKET_COMPLETE:
736 /* if the device isn't open, don't pass packets up the stack */
737 if (!netif_running(dev))
739 len = adapter->irx_pcb.data.rcv_resp.pkt_len;
740 dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
741 if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
742 printk(KERN_ERR "%s: interrupt - packet not received correctly\n", dev->name);
744 if (elp_debug >= 3) {
745 printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
747 if (adapter->irx_pcb.command == 0xff) {
749 printk("%s: adding packet to backlog (len = %d)\n", dev->name, dlen);
750 adapter->rx_backlog.length[adapter->rx_backlog.in] = dlen;
751 adapter->rx_backlog.in = backlog_next(adapter->rx_backlog.in);
753 receive_packet(dev, dlen);
756 printk("%s: packet received\n", dev->name);
761 * 82586 configured correctly
763 case CMD_CONFIGURE_82586_RESPONSE:
764 adapter->got[CMD_CONFIGURE_82586] = 1;
766 printk("%s: interrupt - configure response received\n", dev->name);
770 * Adapter memory configuration
772 case CMD_CONFIGURE_ADAPTER_RESPONSE:
773 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
775 printk("%s: Adapter memory configuration %s.\n", dev->name,
776 adapter->irx_pcb.data.failed ? "failed" : "succeeded");
780 * Multicast list loading
782 case CMD_LOAD_MULTICAST_RESPONSE:
783 adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
785 printk("%s: Multicast address list loading %s.\n", dev->name,
786 adapter->irx_pcb.data.failed ? "failed" : "succeeded");
790 * Station address setting
792 case CMD_SET_ADDRESS_RESPONSE:
793 adapter->got[CMD_SET_STATION_ADDRESS] = 1;
795 printk("%s: Ethernet address setting %s.\n", dev->name,
796 adapter->irx_pcb.data.failed ? "failed" : "succeeded");
801 * received board statistics
803 case CMD_NETWORK_STATISTICS_RESPONSE:
804 adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
805 adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
806 adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
807 adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
808 adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
809 adapter->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res;
810 adapter->got[CMD_NETWORK_STATISTICS] = 1;
812 printk("%s: interrupt - statistics response received\n", dev->name);
818 case CMD_TRANSMIT_PACKET_COMPLETE:
820 printk("%s: interrupt - packet sent\n", dev->name);
821 if (!netif_running(dev))
823 switch (adapter->irx_pcb.data.xmit_resp.c_stat) {
825 adapter->stats.tx_aborted_errors++;
826 printk(KERN_INFO "%s: transmit timed out, network cable problem?\n", dev->name);
829 adapter->stats.tx_fifo_errors++;
830 printk(KERN_INFO "%s: transmit timed out, FIFO underrun\n", dev->name);
833 netif_wake_queue(dev);
840 printk(KERN_DEBUG "%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
844 printk("%s: failed to read PCB on interrupt\n", dev->name);
849 } while (icount++ < 5 && (inb_status(dev->base_addr) & (ACRF | DONE)));
854 * indicate no longer in interrupt routine
856 spin_unlock(&adapter->lock);
860 /******************************************************
864 ******************************************************/
866 static int elp_open(struct net_device *dev)
874 printk("%s: request to open device\n", dev->name);
877 * make sure we actually found the device
879 if (adapter == NULL) {
880 printk("%s: Opening a non-existent physical device\n", dev->name);
884 * disable interrupts on the board
886 outb_control(0, dev);
889 * clear any pending interrupts
891 inb_command(dev->base_addr);
895 * no receive PCBs active
897 adapter->rx_active = 0;
900 adapter->send_pcb_semaphore = 0;
901 adapter->rx_backlog.in = 0;
902 adapter->rx_backlog.out = 0;
904 spin_lock_init(&adapter->lock);
907 * install our interrupt service routine
909 if ((retval = request_irq(dev->irq, &elp_interrupt, 0, dev->name, dev))) {
910 printk(KERN_ERR "%s: could not allocate IRQ%d\n", dev->name, dev->irq);
913 if ((retval = request_dma(dev->dma, dev->name))) {
914 free_irq(dev->irq, dev);
915 printk(KERN_ERR "%s: could not allocate DMA%d channel\n", dev->name, dev->dma);
918 adapter->dma_buffer = (void *) dma_mem_alloc(DMA_BUFFER_SIZE);
919 if (!adapter->dma_buffer) {
920 printk(KERN_ERR "%s: could not allocate DMA buffer\n", dev->name);
922 free_irq(dev->irq, dev);
928 * enable interrupts on the board
930 outb_control(CMDE, dev);
933 * configure adapter memory: we need 10 multicast addresses, default==0
936 printk(KERN_DEBUG "%s: sending 3c505 memory configuration command\n", dev->name);
937 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
938 adapter->tx_pcb.data.memconf.cmd_q = 10;
939 adapter->tx_pcb.data.memconf.rcv_q = 20;
940 adapter->tx_pcb.data.memconf.mcast = 10;
941 adapter->tx_pcb.data.memconf.frame = 20;
942 adapter->tx_pcb.data.memconf.rcv_b = 20;
943 adapter->tx_pcb.data.memconf.progs = 0;
944 adapter->tx_pcb.length = sizeof(struct Memconf);
945 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
946 if (!send_pcb(dev, &adapter->tx_pcb))
947 printk("%s: couldn't send memory configuration command\n", dev->name);
949 int timeout = jiffies + TIMEOUT;
950 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && time_before(jiffies, timeout));
951 if (time_after_eq(jiffies, timeout))
952 TIMEOUT_MSG(__LINE__);
957 * configure adapter to receive broadcast messages and wait for response
960 printk("%s: sending 82586 configure command\n", dev->name);
961 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
962 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
963 adapter->tx_pcb.length = 2;
964 adapter->got[CMD_CONFIGURE_82586] = 0;
965 if (!send_pcb(dev, &adapter->tx_pcb))
966 printk("%s: couldn't send 82586 configure command\n", dev->name);
968 int timeout = jiffies + TIMEOUT;
969 while (adapter->got[CMD_CONFIGURE_82586] == 0 && time_before(jiffies, timeout));
970 if (time_after_eq(jiffies, timeout))
971 TIMEOUT_MSG(__LINE__);
974 /* enable burst-mode DMA */
975 /* outb(0x1, dev->base_addr + PORT_AUXDMA); */
978 * queue receive commands to provide buffering
982 printk("%s: %d receive PCBs active\n", dev->name, adapter->rx_active);
985 * device is now officially open!
988 netif_start_queue(dev);
993 /******************************************************
995 * send a packet to the adapter
997 ******************************************************/
999 static int send_packet(struct net_device *dev, struct sk_buff *skb)
1001 elp_device *adapter = dev->priv;
1002 unsigned long target;
1003 unsigned long flags;
1006 * make sure the length is even and no shorter than 60 bytes
1008 unsigned int nlen = (((skb->len < 60) ? 60 : skb->len) + 1) & (~1);
1010 if (test_and_set_bit(0, (void *) &adapter->busy)) {
1012 printk("%s: transmit blocked\n", dev->name);
1016 adapter->stats.tx_bytes += nlen;
1019 * send the adapter a transmit packet command. Ignore segment and offset
1020 * and make sure the length is even
1022 adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
1023 adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
1024 adapter->tx_pcb.data.xmit_pkt.buf_ofs
1025 = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0; /* Unused */
1026 adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
1028 if (!send_pcb(dev, &adapter->tx_pcb)) {
1032 /* if this happens, we die */
1033 if (test_and_set_bit(0, (void *) &adapter->dmaing))
1034 printk("%s: tx: DMA %d in progress\n", dev->name, adapter->current_dma.direction);
1036 adapter->current_dma.direction = 1;
1037 adapter->current_dma.start_time = jiffies;
1039 if ((unsigned long)(skb->data + nlen) >= MAX_DMA_ADDRESS || nlen != skb->len) {
1040 memcpy(adapter->dma_buffer, skb->data, skb->len);
1041 memset(adapter->dma_buffer+skb->len, 0, nlen-skb->len);
1042 target = virt_to_bus(adapter->dma_buffer);
1045 target = virt_to_bus(skb->data);
1047 adapter->current_dma.skb = skb;
1049 flags=claim_dma_lock();
1050 disable_dma(dev->dma);
1051 clear_dma_ff(dev->dma);
1052 set_dma_mode(dev->dma, 0x48); /* dma memory -> io */
1053 set_dma_addr(dev->dma, target);
1054 set_dma_count(dev->dma, nlen);
1055 outb_control(adapter->hcr_val | DMAE | TCEN, dev);
1056 enable_dma(dev->dma);
1057 release_dma_lock(flags);
1060 printk("%s: DMA transfer started\n", dev->name);
1066 * The upper layer thinks we timed out
1069 static void elp_timeout(struct net_device *dev)
1071 elp_device *adapter = dev->priv;
1074 stat = inb_status(dev->base_addr);
1075 printk(KERN_WARNING "%s: transmit timed out, lost %s?\n", dev->name, (stat & ACRF) ? "interrupt" : "command");
1077 printk("%s: status %#02x\n", dev->name, stat);
1078 dev->trans_start = jiffies;
1079 adapter->stats.tx_dropped++;
1080 netif_wake_queue(dev);
1083 /******************************************************
1085 * start the transmitter
1086 * return 0 if sent OK, else return 1
1088 ******************************************************/
1090 static int elp_start_xmit(struct sk_buff *skb, struct net_device *dev)
1092 unsigned long flags;
1093 elp_device *adapter = dev->priv;
1095 spin_lock_irqsave(&adapter->lock, flags);
1096 check_3c505_dma(dev);
1099 printk("%s: request to send packet of length %d\n", dev->name, (int) skb->len);
1101 netif_stop_queue(dev);
1104 * send the packet at skb->data for skb->len
1106 if (!send_packet(dev, skb)) {
1107 if (elp_debug >= 2) {
1108 printk("%s: failed to transmit packet\n", dev->name);
1110 spin_unlock_irqrestore(&adapter->lock, flags);
1114 printk("%s: packet of length %d sent\n", dev->name, (int) skb->len);
1117 * start the transmit timeout
1119 dev->trans_start = jiffies;
1122 spin_unlock_irqrestore(&adapter->lock, flags);
1123 netif_start_queue(dev);
1127 /******************************************************
1129 * return statistics on the board
1131 ******************************************************/
1133 static struct net_device_stats *elp_get_stats(struct net_device *dev)
1135 elp_device *adapter = (elp_device *) dev->priv;
1138 printk("%s: request for stats\n", dev->name);
1140 /* If the device is closed, just return the latest stats we have,
1141 - we cannot ask from the adapter without interrupts */
1142 if (!netif_running(dev))
1143 return &adapter->stats;
1145 /* send a get statistics command to the board */
1146 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1147 adapter->tx_pcb.length = 0;
1148 adapter->got[CMD_NETWORK_STATISTICS] = 0;
1149 if (!send_pcb(dev, &adapter->tx_pcb))
1150 printk("%s: couldn't send get statistics command\n", dev->name);
1152 int timeout = jiffies + TIMEOUT;
1153 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && time_before(jiffies, timeout));
1154 if (time_after_eq(jiffies, timeout)) {
1155 TIMEOUT_MSG(__LINE__);
1156 return &adapter->stats;
1160 /* statistics are now up to date */
1161 return &adapter->stats;
1164 /******************************************************
1168 ******************************************************/
1170 static int elp_close(struct net_device *dev)
1172 elp_device *adapter;
1174 adapter = dev->priv;
1177 printk("%s: request to close device\n", dev->name);
1179 netif_stop_queue(dev);
1181 /* Someone may request the device statistic information even when
1182 * the interface is closed. The following will update the statistics
1183 * structure in the driver, so we'll be able to give current statistics.
1185 (void) elp_get_stats(dev);
1188 * disable interrupts on the board
1190 outb_control(0, dev);
1195 free_irq(dev->irq, dev);
1198 free_pages((unsigned long) adapter->dma_buffer, get_order(DMA_BUFFER_SIZE));
1204 /************************************************************
1206 * Set multicast list
1207 * num_addrs==0: clear mc_list
1208 * num_addrs==-1: set promiscuous mode
1209 * num_addrs>0: set mc_list
1211 ************************************************************/
1213 static void elp_set_mc_list(struct net_device *dev)
1215 elp_device *adapter = (elp_device *) dev->priv;
1216 struct dev_mc_list *dmi = dev->mc_list;
1218 unsigned long flags;
1221 printk("%s: request to set multicast list\n", dev->name);
1223 spin_lock_irqsave(&adapter->lock, flags);
1225 if (!(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) {
1226 /* send a "load multicast list" command to the board, max 10 addrs/cmd */
1227 /* if num_addrs==0 the list will be cleared */
1228 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1229 adapter->tx_pcb.length = 6 * dev->mc_count;
1230 for (i = 0; i < dev->mc_count; i++) {
1231 memcpy(adapter->tx_pcb.data.multicast[i], dmi->dmi_addr, 6);
1234 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1235 if (!send_pcb(dev, &adapter->tx_pcb))
1236 printk("%s: couldn't send set_multicast command\n", dev->name);
1238 int timeout = jiffies + TIMEOUT;
1239 while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && time_before(jiffies, timeout));
1240 if (time_after_eq(jiffies, timeout)) {
1241 TIMEOUT_MSG(__LINE__);
1245 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1246 else /* num_addrs == 0 */
1247 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1249 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
1251 * configure adapter to receive messages (as specified above)
1252 * and wait for response
1255 printk("%s: sending 82586 configure command\n", dev->name);
1256 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1257 adapter->tx_pcb.length = 2;
1258 adapter->got[CMD_CONFIGURE_82586] = 0;
1259 if (!send_pcb(dev, &adapter->tx_pcb))
1261 spin_unlock_irqrestore(&adapter->lock, flags);
1262 printk("%s: couldn't send 82586 configure command\n", dev->name);
1265 int timeout = jiffies + TIMEOUT;
1266 spin_unlock_irqrestore(&adapter->lock, flags);
1267 while (adapter->got[CMD_CONFIGURE_82586] == 0 && time_before(jiffies, timeout));
1268 if (time_after_eq(jiffies, timeout))
1269 TIMEOUT_MSG(__LINE__);
1274 * netdev_ethtool_ioctl: Handle network interface SIOCETHTOOL ioctls
1275 * @dev: network interface on which out-of-band action is to be performed
1276 * @useraddr: userspace address to which data is to be read and returned
1278 * Process the various commands of the SIOCETHTOOL interface.
1281 static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr)
1285 /* dev_ioctl() in ../../net/core/dev.c has already checked
1286 capable(CAP_NET_ADMIN), so don't bother with that here. */
1288 if (get_user(ethcmd, (u32 *)useraddr))
1293 case ETHTOOL_GDRVINFO: {
1294 struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO };
1295 strcpy (info.driver, DRV_NAME);
1296 strcpy (info.version, DRV_VERSION);
1297 sprintf(info.bus_info, "ISA 0x%lx", dev->base_addr);
1298 if (copy_to_user (useraddr, &info, sizeof (info)))
1303 /* get message-level */
1304 case ETHTOOL_GMSGLVL: {
1305 struct ethtool_value edata = {ETHTOOL_GMSGLVL};
1307 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1311 /* set message-level */
1312 case ETHTOOL_SMSGLVL: {
1313 struct ethtool_value edata;
1314 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1328 * netdev_ioctl: Handle network interface ioctls
1329 * @dev: network interface on which out-of-band action is to be performed
1330 * @rq: user request data
1331 * @cmd: command issued by user
1333 * Process the various out-of-band ioctls passed to this driver.
1336 static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
1342 rc = netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
1354 /******************************************************
1356 * initialise Etherlink Plus board
1358 ******************************************************/
1360 static inline void elp_init(struct net_device *dev)
1362 elp_device *adapter = dev->priv;
1365 * set ptrs to various functions
1367 dev->open = elp_open; /* local */
1368 dev->stop = elp_close; /* local */
1369 dev->get_stats = elp_get_stats; /* local */
1370 dev->hard_start_xmit = elp_start_xmit; /* local */
1371 dev->tx_timeout = elp_timeout; /* local */
1372 dev->watchdog_timeo = 10*HZ;
1373 dev->set_multicast_list = elp_set_mc_list; /* local */
1374 dev->do_ioctl = netdev_ioctl; /* local */
1376 /* Setup the generic properties */
1380 * setup ptr to adapter specific information
1382 memset(&(adapter->stats), 0, sizeof(struct net_device_stats));
1385 * memory information
1387 dev->mem_start = dev->mem_end = dev->rmem_end = dev->rmem_start = 0;
1390 /************************************************************
1392 * A couple of tests to see if there's 3C505 or not
1393 * Called only by elp_autodetect
1394 ************************************************************/
1396 static int __init elp_sense(struct net_device *dev)
1399 int addr = dev->base_addr;
1400 const char *name = dev->name;
1401 unsigned long flags;
1404 if (!request_region(addr, ELP_IO_EXTENT, "3c505"))
1407 orig_HSR = inb_status(addr);
1410 printk(search_msg, name, addr);
1412 if (orig_HSR == 0xff) {
1414 printk(notfound_msg, 1);
1417 /* Enable interrupts - we need timers! */
1421 /* Wait for a while; the adapter may still be booting up */
1423 printk(stilllooking_msg);
1425 if (orig_HSR & DIR) {
1426 /* If HCR.DIR is up, we pull it down. HSR.DIR should follow. */
1427 outb(0, dev->base_addr + PORT_CONTROL);
1428 timeout = jiffies + 30*HZ/100;
1429 while (time_before(jiffies, timeout));
1430 restore_flags(flags);
1431 if (inb_status(addr) & DIR) {
1433 printk(notfound_msg, 2);
1437 /* If HCR.DIR is down, we pull it up. HSR.DIR should follow. */
1438 outb(DIR, dev->base_addr + PORT_CONTROL);
1439 timeout = jiffies + 30*HZ/100;
1440 while (time_before(jiffies, timeout));
1441 restore_flags(flags);
1442 if (!(inb_status(addr) & DIR)) {
1444 printk(notfound_msg, 3);
1449 * It certainly looks like a 3c505.
1456 release_region(addr, ELP_IO_EXTENT);
1460 /*************************************************************
1462 * Search through addr_list[] and try to find a 3C505
1463 * Called only by eplus_probe
1464 *************************************************************/
1466 static int __init elp_autodetect(struct net_device *dev)
1470 /* if base address set, then only check that address
1471 otherwise, run through the table */
1472 if (dev->base_addr != 0) { /* dev->base_addr == 0 ==> plain autodetect */
1473 if (elp_sense(dev) == 0)
1474 return dev->base_addr;
1476 while ((dev->base_addr = addr_list[idx++])) {
1477 if (elp_sense(dev) == 0)
1478 return dev->base_addr;
1481 /* could not find an adapter */
1483 printk(couldnot_msg, dev->name);
1485 return 0; /* Because of this, the layer above will return -ENODEV */
1489 /******************************************************
1491 * probe for an Etherlink Plus board at the specified address
1493 ******************************************************/
1495 /* There are three situations we need to be able to detect here:
1497 * a) the card is idle
1498 * b) the card is still booting up
1499 * c) the card is stuck in a strange state (some DOS drivers do this)
1501 * In case (a), all is well. In case (b), we wait 10 seconds to see if the
1502 * card finishes booting, and carry on if so. In case (c), we do a hard reset,
1503 * loop round, and hope for the best.
1505 * This is all very unpleasant, but hopefully avoids the problems with the old
1506 * probe code (which had a 15-second delay if the card was idle, and didn't
1507 * work at all if it was in a weird state).
1510 int __init elplus_probe(struct net_device *dev)
1512 elp_device *adapter;
1513 int i, tries, tries1, timeout, okay;
1514 unsigned long cookie = 0;
1516 SET_MODULE_OWNER(dev);
1519 * setup adapter structure
1522 dev->base_addr = elp_autodetect(dev);
1523 if (!(dev->base_addr))
1527 * setup ptr to adapter specific information
1529 adapter = (elp_device *) (dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1530 if (adapter == NULL) {
1531 printk("%s: out of memory\n", dev->name);
1535 adapter->send_pcb_semaphore = 0;
1537 for (tries1 = 0; tries1 < 3; tries1++) {
1538 outb_control((adapter->hcr_val | CMDE) & ~DIR, dev);
1539 /* First try to write just one byte, to see if the card is
1540 * responding at all normally.
1542 timeout = jiffies + 5*HZ/100;
1544 while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE));
1545 if ((inb_status(dev->base_addr) & HCRE)) {
1546 outb_command(0, dev->base_addr); /* send a spurious byte */
1547 timeout = jiffies + 5*HZ/100;
1548 while (time_before(jiffies, timeout) && !(inb_status(dev->base_addr) & HCRE));
1549 if (inb_status(dev->base_addr) & HCRE)
1553 /* Nope, it's ignoring the command register. This means that
1554 * either it's still booting up, or it's died.
1556 printk("%s: command register wouldn't drain, ", dev->name);
1557 if ((inb_status(dev->base_addr) & 7) == 3) {
1558 /* If the adapter status is 3, it *could* still be booting.
1559 * Give it the benefit of the doubt for 10 seconds.
1561 printk("assuming 3c505 still starting\n");
1562 timeout = jiffies + 10*HZ;
1563 while (time_before(jiffies, timeout) && (inb_status(dev->base_addr) & 7));
1564 if (inb_status(dev->base_addr) & 7) {
1565 printk("%s: 3c505 failed to start\n", dev->name);
1567 okay = 1; /* It started */
1570 /* Otherwise, it must just be in a strange
1571 * state. We probably need to kick it.
1573 printk("3c505 is sulking\n");
1576 for (tries = 0; tries < 5 && okay; tries++) {
1579 * Try to set the Ethernet address, to make sure that the board
1582 adapter->tx_pcb.command = CMD_STATION_ADDRESS;
1583 adapter->tx_pcb.length = 0;
1584 cookie = probe_irq_on();
1585 if (!send_pcb(dev, &adapter->tx_pcb)) {
1586 printk("%s: could not send first PCB\n", dev->name);
1587 probe_irq_off(cookie);
1590 if (!receive_pcb(dev, &adapter->rx_pcb)) {
1591 printk("%s: could not read first PCB\n", dev->name);
1592 probe_irq_off(cookie);
1595 if ((adapter->rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1596 (adapter->rx_pcb.length != 6)) {
1597 printk("%s: first PCB wrong (%d, %d)\n", dev->name, adapter->rx_pcb.command, adapter->rx_pcb.length);
1598 probe_irq_off(cookie);
1603 /* It's broken. Do a hard reset to re-initialise the board,
1606 printk(KERN_INFO "%s: resetting adapter\n", dev->name);
1607 outb_control(adapter->hcr_val | FLSH | ATTN, dev);
1608 outb_control(adapter->hcr_val & ~(FLSH | ATTN), dev);
1610 printk("%s: failed to initialise 3c505\n", dev->name);
1611 release_region(dev->base_addr, ELP_IO_EXTENT);
1615 if (dev->irq) { /* Is there a preset IRQ? */
1616 int rpt = probe_irq_off(cookie);
1617 if (dev->irq != rpt) {
1618 printk("%s: warning, irq %d configured but %d detected\n", dev->name, dev->irq, rpt);
1620 /* if dev->irq == probe_irq_off(cookie), all is well */
1621 } else /* No preset IRQ; just use what we can detect */
1622 dev->irq = probe_irq_off(cookie);
1623 switch (dev->irq) { /* Legal, sane? */
1625 printk("%s: IRQ probe failed: check 3c505 jumpers.\n",
1632 printk("%s: Impossible IRQ %d reported by probe_irq_off().\n",
1633 dev->name, dev->irq);
1637 * Now we have the IRQ number so we can disable the interrupts from
1638 * the board until the board is opened.
1640 outb_control(adapter->hcr_val & ~CMDE, dev);
1643 * copy Ethernet address into structure
1645 for (i = 0; i < 6; i++)
1646 dev->dev_addr[i] = adapter->rx_pcb.data.eth_addr[i];
1648 /* find a DMA channel */
1650 if (dev->mem_start) {
1651 dev->dma = dev->mem_start & 7;
1654 printk(KERN_WARNING "%s: warning, DMA channel not specified, using default\n", dev->name);
1660 * print remainder of startup message
1662 printk("%s: 3c505 at %#lx, irq %d, dma %d, ",
1663 dev->name, dev->base_addr, dev->irq, dev->dma);
1664 printk("addr %02x:%02x:%02x:%02x:%02x:%02x, ",
1665 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1666 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1669 * read more information from the adapter
1672 adapter->tx_pcb.command = CMD_ADAPTER_INFO;
1673 adapter->tx_pcb.length = 0;
1674 if (!send_pcb(dev, &adapter->tx_pcb) ||
1675 !receive_pcb(dev, &adapter->rx_pcb) ||
1676 (adapter->rx_pcb.command != CMD_ADAPTER_INFO_RESPONSE) ||
1677 (adapter->rx_pcb.length != 10)) {
1678 printk("not responding to second PCB\n");
1680 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);
1683 * reconfigure the adapter memory to better suit our purposes
1685 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
1686 adapter->tx_pcb.length = 12;
1687 adapter->tx_pcb.data.memconf.cmd_q = 8;
1688 adapter->tx_pcb.data.memconf.rcv_q = 8;
1689 adapter->tx_pcb.data.memconf.mcast = 10;
1690 adapter->tx_pcb.data.memconf.frame = 10;
1691 adapter->tx_pcb.data.memconf.rcv_b = 10;
1692 adapter->tx_pcb.data.memconf.progs = 0;
1693 if (!send_pcb(dev, &adapter->tx_pcb) ||
1694 !receive_pcb(dev, &adapter->rx_pcb) ||
1695 (adapter->rx_pcb.command != CMD_CONFIGURE_ADAPTER_RESPONSE) ||
1696 (adapter->rx_pcb.length != 2)) {
1697 printk("%s: could not configure adapter memory\n", dev->name);
1699 if (adapter->rx_pcb.data.configure) {
1700 printk("%s: adapter configuration failed\n", dev->name);
1704 * initialise the device
1712 static struct net_device dev_3c505[ELP_MAX_CARDS];
1713 static int io[ELP_MAX_CARDS];
1714 static int irq[ELP_MAX_CARDS];
1715 static int dma[ELP_MAX_CARDS];
1716 MODULE_PARM(io, "1-" __MODULE_STRING(ELP_MAX_CARDS) "i");
1717 MODULE_PARM(irq, "1-" __MODULE_STRING(ELP_MAX_CARDS) "i");
1718 MODULE_PARM(dma, "1-" __MODULE_STRING(ELP_MAX_CARDS) "i");
1719 MODULE_PARM_DESC(io, "EtherLink Plus I/O base address(es)");
1720 MODULE_PARM_DESC(irq, "EtherLink Plus IRQ number(s) (assigned)");
1721 MODULE_PARM_DESC(dma, "EtherLink Plus DMA channel(s)");
1723 int init_module(void)
1725 int this_dev, found = 0;
1727 for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) {
1728 struct net_device *dev = &dev_3c505[this_dev];
1729 dev->irq = irq[this_dev];
1730 dev->base_addr = io[this_dev];
1731 dev->init = elplus_probe;
1732 if (dma[this_dev]) {
1733 dev->dma = dma[this_dev];
1736 printk(KERN_WARNING "3c505.c: warning, using default DMA channel,\n");
1738 if (io[this_dev] == 0) {
1739 if (this_dev) break;
1740 printk(KERN_NOTICE "3c505.c: module autoprobe not recommended, give io=xx.\n");
1742 if (register_netdev(dev) != 0) {
1743 printk(KERN_WARNING "3c505.c: Failed to register card at 0x%x.\n", io[this_dev]);
1744 if (found != 0) return 0;
1752 void cleanup_module(void)
1756 for (this_dev = 0; this_dev < ELP_MAX_CARDS; this_dev++) {
1757 struct net_device *dev = &dev_3c505[this_dev];
1758 if (dev->priv != NULL) {
1759 unregister_netdev(dev);
1762 release_region(dev->base_addr, ELP_IO_EXTENT);
1768 MODULE_LICENSE("GPL");