49 #include <linux/module.h>
50 #include <linux/kernel.h>
51 #include <linux/types.h>
52 #include <linux/fcntl.h>
56 #include <linux/slab.h>
57 #include <linux/string.h>
58 #include <linux/errno.h>
59 #include <linux/netdevice.h>
62 #include <linux/device.h>
65 #include <linux/bitops.h>
77 static int ether3_rx(
struct net_device *
dev,
unsigned int maxcnt);
102 static inline void ether3_outb(
int v,
void __iomem *
r)
108 static inline void ether3_outw(
int v,
void __iomem *
r)
113 #define ether3_inb(r) ({ unsigned int __v = readb((r)); udelay(1); __v; })
114 #define ether3_inw(r) ({ unsigned int __v = readw((r)); udelay(1); __v; })
127 priv(dev)->broken = 1;
146 #define ether3_writebuffer(dev,data,length) \
147 writesw(REG_BUFWIN, (data), (length) >> 1)
149 #define ether3_writeword(dev,data) \
150 writew((data), REG_BUFWIN)
152 #define ether3_writelong(dev,data) { \
153 void __iomem *reg_bufwin = REG_BUFWIN; \
154 writew((data), reg_bufwin); \
155 writew((data) >> 16, reg_bufwin); \
161 #define ether3_readbuffer(dev,data,length) \
162 readsw(REG_BUFWIN, (data), (length) >> 1)
164 #define ether3_readword(dev) \
167 #define ether3_readlong(dev) \
168 readw(REG_BUFWIN) | (readw(REG_BUFWIN) << 16)
173 static void ether3_ledoff(
unsigned long data)
186 priv(dev)->timer.data = (
unsigned long)dev;
187 priv(dev)->timer.function = ether3_ledoff;
205 for (i = 0; i<6; i++) {
207 if (*s != (i==5?
')' :
':' ))
216 printk(
KERN_ERR "ether3: Couldn't read a valid MAC address from card.\n");
244 for (i = 0; i <
RX_END; i++) {
245 if (buffer[i] != byte) {
246 if (max_errors > 0 && bad != buffer[i]) {
247 printk(
"%s: RAM failed with (%02X instead of %02X) at 0x%04X",
248 dev->
name, buffer[i], byte, i);
256 printk(
" - 0x%04X\n", i - 1);
277 priv(dev)->regs.command = 0;
283 for (i = 0; i < 6; i++)
307 i = ether3_ramtest(dev, 0x5A);
310 i = ether3_ramtest(dev, 0x1E);
328 priv(dev)->regs.command = 0;
334 for (i = 0; i < 6; i++)
337 priv(dev)->tx_head = 0;
338 priv(dev)->tx_tail = 0;
360 int write_low, write_high, read_low, read_high;
362 write_low = val & 255;
363 write_high = val >> 8;
365 printk(
KERN_DEBUG "ether3_probe: write8 [%02X:%02X]", write_high, write_low);
373 printk(
", read8 [%02X:%02X]\n", read_high, read_low);
375 return read_low == write_low && read_high == write_high;
386 printk(
KERN_DEBUG "ether3_probe: write16 [%04X], read16 [%04X]\n", val, read_val);
388 return read_val ==
val;
402 if (!is_valid_ether_addr(dev->
dev_addr)) {
411 ether3_init_for_open(dev);
413 netif_start_queue(dev);
424 netif_stop_queue(dev);
429 priv(dev)->regs.command = 0;
446 static void ether3_setmulticastlist(
struct net_device *dev)
461 static void ether3_timeout(
struct net_device *dev)
474 priv(dev)->tx_head,
priv(dev)->tx_tail);
480 dev->
stats.tx_errors += 1;
482 priv(dev)->tx_head =
priv(dev)->tx_tail = 0;
484 netif_wake_queue(dev);
495 unsigned int ptr, next_ptr;
497 if (
priv(dev)->broken) {
499 dev->
stats.tx_dropped++;
500 netif_start_queue(dev);
504 length = (length + 1) & ~1;
505 if (length != skb->
len) {
506 if (skb_padto(skb, length))
510 next_ptr = (
priv(dev)->tx_head + 1) & 15;
514 if (
priv(dev)->tx_tail == next_ptr) {
519 ptr = 0x600 *
priv(dev)->tx_head;
520 priv(dev)->tx_head = next_ptr;
523 #define TXHDR_FLAGS (TXHDR_TRANSMIT|TXHDR_CHAINCONTINUE|TXHDR_DATAFOLLOWS|TXHDR_ENSUCCESS)
542 next_ptr = (
priv(dev)->tx_head + 1) & 15;
547 if (
priv(dev)->tx_tail == next_ptr)
548 netif_stop_queue(dev);
555 ether3_interrupt(
int irq,
void *
dev_id)
562 printk(
"eth3irq: %d ", irq);
589 static int ether3_rx(
struct net_device *dev,
unsigned int maxcnt)
591 unsigned int next_ptr =
priv(dev)->rx_head, received = 0;
596 unsigned int this_ptr,
status;
597 unsigned char addrs[16];
606 unsigned int temp_ptr;
614 this_ptr = next_ptr + 4;
615 next_ptr =
ntohs(temp_ptr);
620 if (next_ptr < RX_START || next_ptr >= RX_END) {
622 printk(
"%s: bad next pointer @%04X: ", dev->
name,
priv(dev)->rx_head);
623 printk(
"%02X %02X %02X %02X ", next_ptr >> 8, next_ptr & 255, status & 255, status >> 8);
624 for (i = 2; i < 14; i++)
625 printk(
"%02X ", addrs[i]);
627 next_ptr =
priv(dev)->rx_head;
633 if (!(*(
unsigned long *)&dev->
dev_addr[0] ^ *(
unsigned long *)&addrs[2+6]) &&
634 !(*(
unsigned short *)&dev->
dev_addr[4] ^ *(
unsigned short *)&addrs[2+10])) {
639 unsigned int length = next_ptr - this_ptr;
642 if (next_ptr <= this_ptr)
645 skb = netdev_alloc_skb(dev, length + 2);
653 *(
unsigned short *)(buf + 0) = *(
unsigned short *)(addrs + 2);
654 *(
unsigned long *)(buf + 2) = *(
unsigned long *)(addrs + 4);
655 *(
unsigned long *)(buf + 6) = *(
unsigned long *)(addrs + 8);
656 *(
unsigned short *)(buf + 10) = *(
unsigned short *)(addrs + 12);
675 dev->
stats.rx_packets += received;
676 priv(dev)->rx_head = next_ptr;
682 dev->
stats.rx_dropped++;
690 static unsigned long last_warned;
698 printk(
"%s: memory squeeze, dropping packet.\n", dev->
name);
700 dev->
stats.rx_dropped++;
710 unsigned int tx_tail =
priv(dev)->tx_tail;
719 ether3_setbuffer(dev,
buffer_read, tx_tail * 0x600);
733 dev->
stats.tx_packets++;
735 dev->
stats.tx_errors++;
737 dev->
stats.collisions += 16;
739 dev->
stats.tx_fifo_errors++;
742 tx_tail = (tx_tail + 1) & 15;
743 }
while (--max_work);
745 if (
priv(dev)->tx_tail != tx_tail) {
746 priv(dev)->tx_tail = tx_tail;
747 netif_wake_queue(dev);
751 static void __devinit ether3_banner(
void)
753 static unsigned version_printed = 0;
760 .ndo_open = ether3_open,
761 .ndo_stop = ether3_close,
762 .ndo_start_xmit = ether3_sendpacket,
763 .ndo_set_rx_mode = ether3_setmulticastlist,
764 .ndo_tx_timeout = ether3_timeout,
783 dev = alloc_etherdev(
sizeof(
struct dev_priv));
792 if (!
priv(dev)->base) {
816 if (ether3_probe_bus_8(dev, 0x100) &&
817 ether3_probe_bus_8(dev, 0x201))
821 ether3_probe_bus_16(dev, 0x101) &&
822 ether3_probe_bus_16(dev, 0x201))
833 "8-bit card\n", dev->
name, data->
name);
841 if (ether3_init_2(dev)) {
853 printk(
"%s: %s in slot %d, %pM\n",
885 .base_offset = 0x800,
888 static const struct ecard_id ether3_ids[] = {
896 .probe = ether3_probe,
898 .id_table = ether3_ids,
904 static int __init ether3_init(
void)
909 static void __exit ether3_exit(
void)