2 * linux/drivers/acorn/net/ether3.c
4 * Copyright (C) 1995-2000 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * SEEQ nq8005 ethernet driver for Acorn/ANT Ether3 card
13 * By Russell King, with some suggestions from borris@ant.co.uk
16 * 1.04 RMK 29/02/1996 Won't pass packets that are from our ethernet
17 * address up to the higher levels - they're
18 * silently ignored. I/F can now be put into
19 * multicast mode. Receiver routine optimised.
20 * 1.05 RMK 30/02/1996 Now claims interrupt at open when part of
21 * the kernel rather than when a module.
22 * 1.06 RMK 02/03/1996 Various code cleanups
23 * 1.07 RMK 13/10/1996 Optimised interrupt routine and transmit
25 * 1.08 RMK 14/10/1996 Fixed problem with too many packets,
26 * prevented the kernel message about dropped
27 * packets appearing too many times a second.
28 * Now does not disable all IRQs, only the IRQ
30 * 1.09 RMK 10/11/1996 Only enables TX irq when buffer space is low,
31 * but we still service the TX queue if we get a
33 * 1.10 RMK 15/07/1997 Fixed autoprobing of NQ8004.
34 * 1.11 RMK 16/11/1997 Fixed autoprobing of NQ8005A.
35 * 1.12 RMK 31/12/1997 Removed reference to dev_tint for Linux 2.1.
36 * RMK 27/06/1998 Changed asm/delay.h to linux/delay.h.
37 * 1.13 RMK 29/06/1998 Fixed problem with transmission of packets.
38 * Chip seems to have a bug in, whereby if the
39 * packet starts two bytes from the end of the
40 * buffer, it corrupts the receiver chain, and
41 * never updates the transmit status correctly.
42 * 1.14 RMK 07/01/1998 Added initial code for ETHERB addressing.
43 * 1.15 RMK 30/04/1999 More fixes to the transmit routine for buggy
45 * 1.16 RMK 10/02/2000 Updated for 2.3.43
46 * 1.17 RMK 13/05/2000 Updated for 2.3.99-pre8
49 #include <linux/module.h>
50 #include <linux/kernel.h>
51 #include <linux/sched.h>
52 #include <linux/types.h>
53 #include <linux/fcntl.h>
54 #include <linux/interrupt.h>
55 #include <linux/ptrace.h>
56 #include <linux/ioport.h>
58 #include <linux/slab.h>
59 #include <linux/string.h>
60 #include <linux/errno.h>
61 #include <linux/netdevice.h>
62 #include <linux/etherdevice.h>
63 #include <linux/skbuff.h>
64 #include <linux/device.h>
65 #include <linux/init.h>
66 #include <linux/delay.h>
68 #include <asm/system.h>
69 #include <asm/bitops.h>
70 #include <asm/ecard.h>
74 static char version[] __initdata = "ether3 ethernet driver (c) 1995-2000 R.M.King v1.17\n";
78 static unsigned int net_debug = NET_DEBUG;
80 static void ether3_setmulticastlist(struct net_device *dev);
81 static int ether3_rx(struct net_device *dev, struct dev_priv *priv, unsigned int maxcnt);
82 static void ether3_tx(struct net_device *dev, struct dev_priv *priv);
83 static int ether3_open (struct net_device *dev);
84 static int ether3_sendpacket (struct sk_buff *skb, struct net_device *dev);
85 static irqreturn_t ether3_interrupt (int irq, void *dev_id, struct pt_regs *regs);
86 static int ether3_close (struct net_device *dev);
87 static struct net_device_stats *ether3_getstats (struct net_device *dev);
88 static void ether3_setmulticastlist (struct net_device *dev);
89 static void ether3_timeout(struct net_device *dev);
95 /* --------------------------------------------------------------------------- */
103 * ether3 read/write. Slow things down a bit...
104 * The SEEQ8005 doesn't like us writing to its registers
107 static inline void ether3_outb(int v, const int r)
113 static inline void ether3_outw(int v, const int r)
118 #define ether3_inb(r) ({ unsigned int __v = inb((r)); udelay(1); __v; })
119 #define ether3_inw(r) ({ unsigned int __v = inw((r)); udelay(1); __v; })
122 ether3_setbuffer(struct net_device *dev, buffer_rw_t read, int start)
124 struct dev_priv *priv = netdev_priv(dev);
127 ether3_outw(priv->regs.config1 | CFG1_LOCBUFMEM, REG_CONFIG1);
128 ether3_outw(priv->regs.command | CMD_FIFOWRITE, REG_COMMAND);
130 while ((ether3_inw(REG_STATUS) & STAT_FIFOEMPTY) == 0) {
132 printk("%s: setbuffer broken\n", dev->name);
139 if (read == buffer_read) {
140 ether3_outw(start, REG_DMAADDR);
141 ether3_outw(priv->regs.command | CMD_FIFOREAD, REG_COMMAND);
143 ether3_outw(priv->regs.command | CMD_FIFOWRITE, REG_COMMAND);
144 ether3_outw(start, REG_DMAADDR);
150 * write data to the buffer memory
152 #define ether3_writebuffer(dev,data,length) \
153 outsw(REG_BUFWIN, (data), (length) >> 1)
155 #define ether3_writeword(dev,data) \
156 outw((data), REG_BUFWIN)
158 #define ether3_writelong(dev,data) { \
159 unsigned long reg_bufwin = REG_BUFWIN; \
160 outw((data), reg_bufwin); \
161 outw((data) >> 16, reg_bufwin); \
165 * read data from the buffer memory
167 #define ether3_readbuffer(dev,data,length) \
168 insw(REG_BUFWIN, (data), (length) >> 1)
170 #define ether3_readword(dev) \
173 #define ether3_readlong(dev) \
174 inw(REG_BUFWIN) | (inw(REG_BUFWIN) << 16)
180 ether3_ledoff(unsigned long data)
182 struct net_device *dev = (struct net_device *)data;
183 struct dev_priv *priv = netdev_priv(dev);
184 ether3_outw(priv->regs.config2 |= CFG2_CTRLO, REG_CONFIG2);
191 ether3_ledon(struct net_device *dev, struct dev_priv *priv)
193 del_timer(&priv->timer);
194 priv->timer.expires = jiffies + HZ / 50; /* leave on for 1/50th second */
195 priv->timer.data = (unsigned long)dev;
196 priv->timer.function = ether3_ledoff;
197 add_timer(&priv->timer);
198 if (priv->regs.config2 & CFG2_CTRLO)
199 ether3_outw(priv->regs.config2 &= ~CFG2_CTRLO, REG_CONFIG2);
203 * Read the ethernet address string from the on board rom.
204 * This is an ascii string!!!
207 ether3_addr(char *addr, struct expansion_card *ec)
209 struct in_chunk_dir cd;
212 if (ecard_readchunk(&cd, ec, 0xf5, 0) && (s = strchr(cd.d.string, '('))) {
214 for (i = 0; i<6; i++) {
215 addr[i] = simple_strtoul(s + 1, &s, 0x10);
216 if (*s != (i==5?')' : ':' ))
222 /* I wonder if we should even let the user continue in this case
223 * - no, it would be better to disable the device
225 printk(KERN_ERR "ether3: Couldn't read a valid MAC address from card.\n");
229 /* --------------------------------------------------------------------------- */
232 ether3_ramtest(struct net_device *dev, unsigned char byte)
234 unsigned char *buffer = kmalloc(RX_END, GFP_KERNEL);
242 memset(buffer, byte, RX_END);
243 ether3_setbuffer(dev, buffer_write, 0);
244 ether3_writebuffer(dev, buffer, TX_END);
245 ether3_setbuffer(dev, buffer_write, RX_START);
246 ether3_writebuffer(dev, buffer + RX_START, RX_LEN);
247 memset(buffer, byte ^ 0xff, RX_END);
248 ether3_setbuffer(dev, buffer_read, 0);
249 ether3_readbuffer(dev, buffer, TX_END);
250 ether3_setbuffer(dev, buffer_read, RX_START);
251 ether3_readbuffer(dev, buffer + RX_START, RX_LEN);
253 for (i = 0; i < RX_END; i++) {
254 if (buffer[i] != byte) {
255 if (max_errors > 0 && bad != buffer[i]) {
256 printk("%s: RAM failed with (%02X instead of %02X) at 0x%04X",
257 dev->name, buffer[i], byte, i);
265 printk(" - 0x%04X\n", i - 1);
272 printk(" - 0xffff\n");
278 /* ------------------------------------------------------------------------------- */
281 ether3_init_2(struct net_device *dev)
283 struct dev_priv *priv = netdev_priv(dev);
286 priv->regs.config1 = CFG1_RECVCOMPSTAT0|CFG1_DMABURST8;
287 priv->regs.config2 = CFG2_CTRLO|CFG2_RECVCRC|CFG2_ERRENCRC;
288 priv->regs.command = 0;
291 * Set up our hardware address
293 ether3_outw(priv->regs.config1 | CFG1_BUFSELSTAT0, REG_CONFIG1);
294 for (i = 0; i < 6; i++)
295 ether3_outb(dev->dev_addr[i], REG_BUFWIN);
297 if (dev->flags & IFF_PROMISC)
298 priv->regs.config1 |= CFG1_RECVPROMISC;
299 else if (dev->flags & IFF_MULTICAST)
300 priv->regs.config1 |= CFG1_RECVSPECBRMULTI;
302 priv->regs.config1 |= CFG1_RECVSPECBROAD;
305 * There is a problem with the NQ8005 in that it occasionally loses the
306 * last two bytes. To get round this problem, we receive the CRC as
307 * well. That way, if we do lose the last two, then it doesn't matter.
309 ether3_outw(priv->regs.config1 | CFG1_TRANSEND, REG_CONFIG1);
310 ether3_outw((TX_END>>8) - 1, REG_BUFWIN);
311 ether3_outw(priv->rx_head, REG_RECVPTR);
312 ether3_outw(0, REG_TRANSMITPTR);
313 ether3_outw(priv->rx_head >> 8, REG_RECVEND);
314 ether3_outw(priv->regs.config2, REG_CONFIG2);
315 ether3_outw(priv->regs.config1 | CFG1_LOCBUFMEM, REG_CONFIG1);
316 ether3_outw(priv->regs.command, REG_COMMAND);
318 i = ether3_ramtest(dev, 0x5A);
321 i = ether3_ramtest(dev, 0x1E);
325 ether3_setbuffer(dev, buffer_write, 0);
326 ether3_writelong(dev, 0);
331 ether3_init_for_open(struct net_device *dev)
333 struct dev_priv *priv = netdev_priv(dev);
336 memset(&priv->stats, 0, sizeof(struct net_device_stats));
339 ether3_outw(CFG2_RESET, REG_CONFIG2);
342 priv->regs.command = 0;
343 ether3_outw(CMD_RXOFF|CMD_TXOFF, REG_COMMAND);
344 while (ether3_inw(REG_STATUS) & (STAT_RXON|STAT_TXON));
346 ether3_outw(priv->regs.config1 | CFG1_BUFSELSTAT0, REG_CONFIG1);
347 for (i = 0; i < 6; i++)
348 ether3_outb(dev->dev_addr[i], REG_BUFWIN);
352 priv->regs.config2 |= CFG2_CTRLO;
353 priv->rx_head = RX_START;
355 ether3_outw(priv->regs.config1 | CFG1_TRANSEND, REG_CONFIG1);
356 ether3_outw((TX_END>>8) - 1, REG_BUFWIN);
357 ether3_outw(priv->rx_head, REG_RECVPTR);
358 ether3_outw(priv->rx_head >> 8, REG_RECVEND);
359 ether3_outw(0, REG_TRANSMITPTR);
360 ether3_outw(priv->regs.config2, REG_CONFIG2);
361 ether3_outw(priv->regs.config1 | CFG1_LOCBUFMEM, REG_CONFIG1);
363 ether3_setbuffer(dev, buffer_write, 0);
364 ether3_writelong(dev, 0);
366 priv->regs.command = CMD_ENINTRX | CMD_ENINTTX;
367 ether3_outw(priv->regs.command | CMD_RXON, REG_COMMAND);
371 ether3_probe_bus_8(struct net_device *dev, int val)
373 int write_low, write_high, read_low, read_high;
375 write_low = val & 255;
376 write_high = val >> 8;
378 printk(KERN_DEBUG "ether3_probe: write8 [%02X:%02X]", write_high, write_low);
380 ether3_outb(write_low, REG_RECVPTR);
381 ether3_outb(write_high, REG_RECVPTR + 1);
383 read_low = ether3_inb(REG_RECVPTR);
384 read_high = ether3_inb(REG_RECVPTR + 1);
386 printk(", read8 [%02X:%02X]\n", read_high, read_low);
388 return read_low == write_low && read_high == write_high;
392 ether3_probe_bus_16(struct net_device *dev, int val)
396 ether3_outw(val, REG_RECVPTR);
397 read_val = ether3_inw(REG_RECVPTR);
399 printk(KERN_DEBUG "ether3_probe: write16 [%04X], read16 [%04X]\n", val, read_val);
401 return read_val == val;
405 * Open/initialize the board. This is called (in the current kernel)
406 * sometime after booting when the 'ifconfig' program is run.
408 * This routine should set everything up anew at each open, even
409 * registers that "should" only need to be set once at boot, so that
410 * there is non-reboot way to recover if something goes wrong.
413 ether3_open(struct net_device *dev)
415 if (!is_valid_ether_addr(dev->dev_addr)) {
416 printk(KERN_WARNING "%s: invalid ethernet MAC address\n",
421 if (request_irq(dev->irq, ether3_interrupt, 0, "ether3", dev))
424 ether3_init_for_open(dev);
426 netif_start_queue(dev);
432 * The inverse routine to ether3_open().
435 ether3_close(struct net_device *dev)
437 struct dev_priv *priv = netdev_priv(dev);
439 netif_stop_queue(dev);
441 disable_irq(dev->irq);
443 ether3_outw(CMD_RXOFF|CMD_TXOFF, REG_COMMAND);
444 priv->regs.command = 0;
445 while (ether3_inw(REG_STATUS) & (STAT_RXON|STAT_TXON));
446 ether3_outb(0x80, REG_CONFIG2 + 1);
447 ether3_outw(0, REG_COMMAND);
449 free_irq(dev->irq, dev);
455 * Get the current statistics. This may be called with the card open or
458 static struct net_device_stats *ether3_getstats(struct net_device *dev)
460 struct dev_priv *priv = netdev_priv(dev);
465 * Set or clear promiscuous/multicast mode filter for this adaptor.
467 * We don't attempt any packet filtering. The card may have a SEEQ 8004
468 * in which does not have the other ethernet address registers present...
470 static void ether3_setmulticastlist(struct net_device *dev)
472 struct dev_priv *priv = netdev_priv(dev);
474 priv->regs.config1 &= ~CFG1_RECVPROMISC;
476 if (dev->flags & IFF_PROMISC) {
477 /* promiscuous mode */
478 priv->regs.config1 |= CFG1_RECVPROMISC;
479 } else if (dev->flags & IFF_ALLMULTI) {
480 priv->regs.config1 |= CFG1_RECVSPECBRMULTI;
482 priv->regs.config1 |= CFG1_RECVSPECBROAD;
484 ether3_outw(priv->regs.config1 | CFG1_LOCBUFMEM, REG_CONFIG1);
488 ether3_timeout(struct net_device *dev)
490 struct dev_priv *priv = netdev_priv(dev);
493 del_timer(&priv->timer);
495 local_irq_save(flags);
496 printk(KERN_ERR "%s: transmit timed out, network cable problem?\n", dev->name);
497 printk(KERN_ERR "%s: state: { status=%04X cfg1=%04X cfg2=%04X }\n", dev->name,
498 ether3_inw(REG_STATUS), ether3_inw(REG_CONFIG1), ether3_inw(REG_CONFIG2));
499 printk(KERN_ERR "%s: { rpr=%04X rea=%04X tpr=%04X }\n", dev->name,
500 ether3_inw(REG_RECVPTR), ether3_inw(REG_RECVEND), ether3_inw(REG_TRANSMITPTR));
501 printk(KERN_ERR "%s: tx head=%X tx tail=%X\n", dev->name,
502 priv->tx_head, priv->tx_tail);
503 ether3_setbuffer(dev, buffer_read, priv->tx_tail);
504 printk(KERN_ERR "%s: packet status = %08X\n", dev->name, ether3_readlong(dev));
505 local_irq_restore(flags);
507 priv->regs.config2 |= CFG2_CTRLO;
508 priv->stats.tx_errors += 1;
509 ether3_outw(priv->regs.config2, REG_CONFIG2);
510 priv->tx_head = priv->tx_tail = 0;
512 netif_wake_queue(dev);
519 ether3_sendpacket(struct sk_buff *skb, struct net_device *dev)
521 struct dev_priv *priv = netdev_priv(dev);
523 unsigned int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
524 unsigned int ptr, next_ptr;
528 priv->stats.tx_dropped ++;
529 netif_start_queue(dev);
533 length = (length + 1) & ~1;
534 if (length != skb->len) {
535 skb = skb_padto(skb, length);
540 next_ptr = (priv->tx_head + 1) & 15;
542 local_irq_save(flags);
544 if (priv->tx_tail == next_ptr) {
545 local_irq_restore(flags);
546 return 1; /* unable to queue */
549 dev->trans_start = jiffies;
550 ptr = 0x600 * priv->tx_head;
551 priv->tx_head = next_ptr;
554 #define TXHDR_FLAGS (TXHDR_TRANSMIT|TXHDR_CHAINCONTINUE|TXHDR_DATAFOLLOWS|TXHDR_ENSUCCESS)
556 ether3_setbuffer(dev, buffer_write, next_ptr);
557 ether3_writelong(dev, 0);
558 ether3_setbuffer(dev, buffer_write, ptr);
559 ether3_writelong(dev, 0);
560 ether3_writebuffer(dev, skb->data, length);
561 ether3_writeword(dev, htons(next_ptr));
562 ether3_writeword(dev, TXHDR_CHAINCONTINUE >> 16);
563 ether3_setbuffer(dev, buffer_write, ptr);
564 ether3_writeword(dev, htons((ptr + length + 4)));
565 ether3_writeword(dev, TXHDR_FLAGS >> 16);
566 ether3_ledon(dev, priv);
568 if (!(ether3_inw(REG_STATUS) & STAT_TXON)) {
569 ether3_outw(ptr, REG_TRANSMITPTR);
570 ether3_outw(priv->regs.command | CMD_TXON, REG_COMMAND);
573 next_ptr = (priv->tx_head + 1) & 15;
574 local_irq_restore(flags);
578 if (priv->tx_tail == next_ptr)
579 netif_stop_queue(dev);
586 ether3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
588 struct net_device *dev = (struct net_device *)dev_id;
589 struct dev_priv *priv;
590 unsigned int status, handled = IRQ_NONE;
593 if(net_debug & DEBUG_INT)
594 printk("eth3irq: %d ", irq);
597 priv = netdev_priv(dev);
599 status = ether3_inw(REG_STATUS);
601 if (status & STAT_INTRX) {
602 ether3_outw(CMD_ACKINTRX | priv->regs.command, REG_COMMAND);
603 ether3_rx(dev, priv, 12);
604 handled = IRQ_HANDLED;
607 if (status & STAT_INTTX) {
608 ether3_outw(CMD_ACKINTTX | priv->regs.command, REG_COMMAND);
609 ether3_tx(dev, priv);
610 handled = IRQ_HANDLED;
614 if(net_debug & DEBUG_INT)
621 * If we have a good packet(s), get it/them out of the buffers.
624 ether3_rx(struct net_device *dev, struct dev_priv *priv, unsigned int maxcnt)
626 unsigned int next_ptr = priv->rx_head, received = 0;
627 ether3_ledon(dev, priv);
630 unsigned int this_ptr, status;
631 unsigned char addrs[16];
634 * read the first 16 bytes from the buffer.
635 * This contains the status bytes etc and ethernet addresses,
636 * and we also check the source ethernet address to see if
637 * it originated from us.
640 unsigned int temp_ptr;
641 ether3_setbuffer(dev, buffer_read, next_ptr);
642 temp_ptr = ether3_readword(dev);
643 status = ether3_readword(dev);
644 if ((status & (RXSTAT_DONE | RXHDR_CHAINCONTINUE | RXHDR_RECEIVE)) !=
645 (RXSTAT_DONE | RXHDR_CHAINCONTINUE) || !temp_ptr)
648 this_ptr = next_ptr + 4;
649 next_ptr = ntohs(temp_ptr);
651 ether3_setbuffer(dev, buffer_read, this_ptr);
652 ether3_readbuffer(dev, addrs+2, 12);
654 if (next_ptr < RX_START || next_ptr >= RX_END) {
656 printk("%s: bad next pointer @%04X: ", dev->name, priv->rx_head);
657 printk("%02X %02X %02X %02X ", next_ptr >> 8, next_ptr & 255, status & 255, status >> 8);
658 for (i = 2; i < 14; i++)
659 printk("%02X ", addrs[i]);
661 next_ptr = priv->rx_head;
665 * ignore our own packets...
667 if (!(*(unsigned long *)&dev->dev_addr[0] ^ *(unsigned long *)&addrs[2+6]) &&
668 !(*(unsigned short *)&dev->dev_addr[4] ^ *(unsigned short *)&addrs[2+10])) {
669 maxcnt ++; /* compensate for loopedback packet */
670 ether3_outw(next_ptr >> 8, REG_RECVEND);
672 if (!(status & (RXSTAT_OVERSIZE|RXSTAT_CRCERROR|RXSTAT_DRIBBLEERROR|RXSTAT_SHORTPACKET))) {
673 unsigned int length = next_ptr - this_ptr;
676 if (next_ptr <= this_ptr)
677 length += RX_END - RX_START;
679 skb = dev_alloc_skb(length + 2);
685 buf = skb_put(skb, length);
686 ether3_readbuffer(dev, buf + 12, length - 12);
687 ether3_outw(next_ptr >> 8, REG_RECVEND);
688 *(unsigned short *)(buf + 0) = *(unsigned short *)(addrs + 2);
689 *(unsigned long *)(buf + 2) = *(unsigned long *)(addrs + 4);
690 *(unsigned long *)(buf + 6) = *(unsigned long *)(addrs + 8);
691 *(unsigned short *)(buf + 10) = *(unsigned short *)(addrs + 12);
692 skb->protocol = eth_type_trans(skb, dev);
698 struct net_device_stats *stats = &priv->stats;
699 ether3_outw(next_ptr >> 8, REG_RECVEND);
700 if (status & RXSTAT_OVERSIZE) stats->rx_over_errors ++;
701 if (status & RXSTAT_CRCERROR) stats->rx_crc_errors ++;
702 if (status & RXSTAT_DRIBBLEERROR) stats->rx_fifo_errors ++;
703 if (status & RXSTAT_SHORTPACKET) stats->rx_length_errors ++;
710 priv->stats.rx_packets += received;
711 priv->rx_head = next_ptr;
713 * If rx went off line, then that means that the buffer may be full. We
714 * have dropped at least one packet.
716 if (!(ether3_inw(REG_STATUS) & STAT_RXON)) {
717 priv->stats.rx_dropped ++;
718 ether3_outw(next_ptr, REG_RECVPTR);
719 ether3_outw(priv->regs.command | CMD_RXON, REG_COMMAND);
725 static unsigned long last_warned;
727 ether3_outw(next_ptr >> 8, REG_RECVEND);
729 * Don't print this message too many times...
731 if (time_after(jiffies, last_warned + 10 * HZ)) {
732 last_warned = jiffies;
733 printk("%s: memory squeeze, dropping packet.\n", dev->name);
735 priv->stats.rx_dropped ++;
741 * Update stats for the transmitted packet(s)
744 ether3_tx(struct net_device *dev, struct dev_priv *priv)
746 unsigned int tx_tail = priv->tx_tail;
750 unsigned long status;
753 * Read the packet header
755 ether3_setbuffer(dev, buffer_read, tx_tail * 0x600);
756 status = ether3_readlong(dev);
759 * Check to see if this packet has been transmitted
761 if ((status & (TXSTAT_DONE | TXHDR_TRANSMIT)) !=
762 (TXSTAT_DONE | TXHDR_TRANSMIT))
768 if (!(status & (TXSTAT_BABBLED | TXSTAT_16COLLISIONS)))
769 priv->stats.tx_packets++;
771 priv->stats.tx_errors ++;
772 if (status & TXSTAT_16COLLISIONS) priv->stats.collisions += 16;
773 if (status & TXSTAT_BABBLED) priv->stats.tx_fifo_errors ++;
776 tx_tail = (tx_tail + 1) & 15;
777 } while (--max_work);
779 if (priv->tx_tail != tx_tail) {
780 priv->tx_tail = tx_tail;
781 netif_wake_queue(dev);
785 static void __init ether3_banner(void)
787 static unsigned version_printed = 0;
789 if (net_debug && version_printed++ == 0)
790 printk(KERN_INFO "%s", version);
793 static const char * __init
794 ether3_get_dev(struct net_device *dev, struct expansion_card *ec)
796 const char *name = "ether3";
798 dev->base_addr = ecard_address(ec, ECARD_MEMC, 0);
801 if (ec->cid.manufacturer == MANU_ANT &&
802 ec->cid.product == PROD_ANT_ETHERB) {
803 dev->base_addr += 0x200;
807 ec->irqaddr = (volatile unsigned char *)ioaddr(dev->base_addr);
810 ether3_addr(dev->dev_addr, ec);
816 ether3_probe(struct expansion_card *ec, const struct ecard_id *id)
818 struct net_device *dev;
819 struct dev_priv *priv;
821 int i, bus_type, ret;
825 dev = alloc_etherdev(sizeof(struct dev_priv));
831 SET_MODULE_OWNER(dev);
833 name = ether3_get_dev(dev, ec);
840 * this will not fail - the nature of the bus ensures this
842 if (!request_region(dev->base_addr, 128, dev->name)) {
847 priv = netdev_priv(dev);
848 init_timer(&priv->timer);
852 ether3_outb(0x80, REG_CONFIG2 + 1);
853 bus_type = BUS_UNKNOWN;
856 /* Test using Receive Pointer (16-bit register) to find out
857 * how the ether3 is connected to the bus...
859 if (ether3_probe_bus_8(dev, 0x100) &&
860 ether3_probe_bus_8(dev, 0x201))
863 if (bus_type == BUS_UNKNOWN &&
864 ether3_probe_bus_16(dev, 0x101) &&
865 ether3_probe_bus_16(dev, 0x201))
870 printk(KERN_ERR "%s: unable to identify bus width\n", dev->name);
875 printk(KERN_ERR "%s: %s found, but is an unsupported "
876 "8-bit card\n", dev->name, name);
884 if (ether3_init_2(dev)) {
889 dev->open = ether3_open;
890 dev->stop = ether3_close;
891 dev->hard_start_xmit = ether3_sendpacket;
892 dev->get_stats = ether3_getstats;
893 dev->set_multicast_list = ether3_setmulticastlist;
894 dev->tx_timeout = ether3_timeout;
895 dev->watchdog_timeo = 5 * HZ / 100;
897 ret = register_netdev(dev);
901 printk("%s: %s in slot %d, ", dev->name, name, ec->slot_no);
902 for (i = 0; i < 6; i++)
903 printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':');
905 ecard_set_drvdata(ec, dev);
909 release_region(dev->base_addr, 128);
916 static void __devexit ether3_remove(struct expansion_card *ec)
918 struct net_device *dev = ecard_get_drvdata(ec);
920 ecard_set_drvdata(ec, NULL);
922 unregister_netdev(dev);
923 release_region(dev->base_addr, 128);
927 static const struct ecard_id ether3_ids[] = {
928 { MANU_ANT2, PROD_ANT_ETHER3 },
929 { MANU_ANT, PROD_ANT_ETHER3 },
930 { MANU_ANT, PROD_ANT_ETHERB },
934 static struct ecard_driver ether3_driver = {
935 .probe = ether3_probe,
936 .remove = __devexit_p(ether3_remove),
937 .id_table = ether3_ids,
943 static int __init ether3_init(void)
945 return ecard_register_driver(ðer3_driver);
948 static void __exit ether3_exit(void)
950 ecard_remove_driver(ðer3_driver);
953 module_init(ether3_init);
954 module_exit(ether3_exit);
956 MODULE_LICENSE("GPL");