Linux 3.4.102
[linux/fpc-iii.git] / drivers / net / ethernet / fujitsu / at1700.c
blob3d94797c8f9ba6efd583d5fe7060c64db981e0b8
1 /* at1700.c: A network device driver for the Allied Telesis AT1700.
3 Written 1993-98 by Donald Becker.
5 Copyright 1993 United States Government as represented by the
6 Director, National Security Agency.
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
11 The author may be reached as becker@scyld.com, or C/O
12 Scyld Computing Corporation
13 410 Severn Ave., Suite 210
14 Annapolis MD 21403
16 This is a device driver for the Allied Telesis AT1700, and
17 Fujitsu FMV-181/182/181A/182A/183/184/183A/184A, which are
18 straight-forward Fujitsu MB86965 implementations.
20 Modification for Fujitsu FMV-18X cards is done by Yutaka Tamiya
21 (tamy@flab.fujitsu.co.jp).
23 Sources:
24 The Fujitsu MB86965 datasheet.
26 After the initial version of this driver was written Gerry Sawkins of
27 ATI provided their EEPROM configuration code header file.
28 Thanks to NIIBE Yutaka <gniibe@mri.co.jp> for bug fixes.
30 MCA bus (AT1720) support by Rene Schmit <rene@bss.lu>
32 Bugs:
33 The MB86965 has a design flaw that makes all probes unreliable. Not
34 only is it difficult to detect, it also moves around in I/O space in
35 response to inb()s from other device probes!
38 #include <linux/errno.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/mca-legacy.h>
42 #include <linux/module.h>
43 #include <linux/kernel.h>
44 #include <linux/types.h>
45 #include <linux/fcntl.h>
46 #include <linux/interrupt.h>
47 #include <linux/ioport.h>
48 #include <linux/in.h>
49 #include <linux/skbuff.h>
50 #include <linux/string.h>
51 #include <linux/init.h>
52 #include <linux/crc32.h>
53 #include <linux/bitops.h>
55 #include <asm/io.h>
56 #include <asm/dma.h>
58 static char version[] __initdata =
59 "at1700.c:v1.16 9/11/06 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
61 #define DRV_NAME "at1700"
63 /* Tunable parameters. */
65 /* When to switch from the 64-entry multicast filter to Rx-all-multicast. */
66 #define MC_FILTERBREAK 64
68 /* These unusual address orders are used to verify the CONFIG register. */
70 static int fmv18x_probe_list[] __initdata = {
71 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x300, 0x340, 0
75 * ISA
78 static unsigned at1700_probe_list[] __initdata = {
79 0x260, 0x280, 0x2a0, 0x240, 0x340, 0x320, 0x380, 0x300, 0
83 * MCA
85 #ifdef CONFIG_MCA_LEGACY
86 static int at1700_ioaddr_pattern[] __initdata = {
87 0x00, 0x04, 0x01, 0x05, 0x02, 0x06, 0x03, 0x07
90 static int at1700_mca_probe_list[] __initdata = {
91 0x400, 0x1400, 0x2400, 0x3400, 0x4400, 0x5400, 0x6400, 0x7400, 0
94 static int at1700_irq_pattern[] __initdata = {
95 0x00, 0x00, 0x00, 0x30, 0x70, 0xb0, 0x00, 0x00,
96 0x00, 0xf0, 0x34, 0x74, 0xb4, 0x00, 0x00, 0xf4, 0x00
98 #endif
100 /* use 0 for production, 1 for verification, >2 for debug */
101 #ifndef NET_DEBUG
102 #define NET_DEBUG 1
103 #endif
104 static unsigned int net_debug = NET_DEBUG;
106 typedef unsigned char uchar;
108 /* Information that need to be kept for each board. */
109 struct net_local {
110 spinlock_t lock;
111 unsigned char mc_filter[8];
112 uint jumpered:1; /* Set iff the board has jumper config. */
113 uint tx_started:1; /* Packets are on the Tx queue. */
114 uint tx_queue_ready:1; /* Tx queue is ready to be sent. */
115 uint rx_started:1; /* Packets are Rxing. */
116 uchar tx_queue; /* Number of packet on the Tx queue. */
117 char mca_slot; /* -1 means ISA */
118 ushort tx_queue_len; /* Current length of the Tx queue. */
122 /* Offsets from the base address. */
123 #define STATUS 0
124 #define TX_STATUS 0
125 #define RX_STATUS 1
126 #define TX_INTR 2 /* Bit-mapped interrupt enable registers. */
127 #define RX_INTR 3
128 #define TX_MODE 4
129 #define RX_MODE 5
130 #define CONFIG_0 6 /* Misc. configuration settings. */
131 #define CONFIG_1 7
132 /* Run-time register bank 2 definitions. */
133 #define DATAPORT 8 /* Word-wide DMA or programmed-I/O dataport. */
134 #define TX_START 10
135 #define COL16CNTL 11 /* Control Reg for 16 collisions */
136 #define MODE13 13
137 #define RX_CTRL 14
138 /* Configuration registers only on the '865A/B chips. */
139 #define EEPROM_Ctrl 16
140 #define EEPROM_Data 17
141 #define CARDSTATUS 16 /* FMV-18x Card Status */
142 #define CARDSTATUS1 17 /* FMV-18x Card Status */
143 #define IOCONFIG 18 /* Either read the jumper, or move the I/O. */
144 #define IOCONFIG1 19
145 #define SAPROM 20 /* The station address PROM, if no EEPROM. */
146 #define MODE24 24
147 #define RESET 31 /* Write to reset some parts of the chip. */
148 #define AT1700_IO_EXTENT 32
149 #define PORT_OFFSET(o) (o)
152 #define TX_TIMEOUT (HZ/10)
155 /* Index to functions, as function prototypes. */
157 static int at1700_probe1(struct net_device *dev, int ioaddr);
158 static int read_eeprom(long ioaddr, int location);
159 static int net_open(struct net_device *dev);
160 static netdev_tx_t net_send_packet(struct sk_buff *skb,
161 struct net_device *dev);
162 static irqreturn_t net_interrupt(int irq, void *dev_id);
163 static void net_rx(struct net_device *dev);
164 static int net_close(struct net_device *dev);
165 static void set_rx_mode(struct net_device *dev);
166 static void net_tx_timeout (struct net_device *dev);
169 #ifdef CONFIG_MCA_LEGACY
170 struct at1720_mca_adapters_struct {
171 char* name;
172 int id;
174 /* rEnE : maybe there are others I don't know off... */
176 static struct at1720_mca_adapters_struct at1720_mca_adapters[] __initdata = {
177 { "Allied Telesys AT1720AT", 0x6410 },
178 { "Allied Telesys AT1720BT", 0x6413 },
179 { "Allied Telesys AT1720T", 0x6416 },
180 { NULL, 0 },
182 #endif
184 /* Check for a network adaptor of this type, and return '0' iff one exists.
185 If dev->base_addr == 0, probe all likely locations.
186 If dev->base_addr == 1, always return failure.
187 If dev->base_addr == 2, allocate space for the device and return success
188 (detachable devices only).
191 static int io = 0x260;
193 static int irq;
195 static void cleanup_card(struct net_device *dev)
197 #ifdef CONFIG_MCA_LEGACY
198 struct net_local *lp = netdev_priv(dev);
199 if (lp->mca_slot >= 0)
200 mca_mark_as_unused(lp->mca_slot);
201 #endif
202 free_irq(dev->irq, NULL);
203 release_region(dev->base_addr, AT1700_IO_EXTENT);
206 struct net_device * __init at1700_probe(int unit)
208 struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
209 unsigned *port;
210 int err = 0;
212 if (!dev)
213 return ERR_PTR(-ENODEV);
215 if (unit >= 0) {
216 sprintf(dev->name, "eth%d", unit);
217 netdev_boot_setup_check(dev);
218 io = dev->base_addr;
219 irq = dev->irq;
220 } else {
221 dev->base_addr = io;
222 dev->irq = irq;
225 if (io > 0x1ff) { /* Check a single specified location. */
226 err = at1700_probe1(dev, io);
227 } else if (io != 0) { /* Don't probe at all. */
228 err = -ENXIO;
229 } else {
230 for (port = at1700_probe_list; *port; port++) {
231 if (at1700_probe1(dev, *port) == 0)
232 break;
233 dev->irq = irq;
235 if (!*port)
236 err = -ENODEV;
238 if (err)
239 goto out;
240 err = register_netdev(dev);
241 if (err)
242 goto out1;
243 return dev;
244 out1:
245 cleanup_card(dev);
246 out:
247 free_netdev(dev);
248 return ERR_PTR(err);
251 static const struct net_device_ops at1700_netdev_ops = {
252 .ndo_open = net_open,
253 .ndo_stop = net_close,
254 .ndo_start_xmit = net_send_packet,
255 .ndo_set_rx_mode = set_rx_mode,
256 .ndo_tx_timeout = net_tx_timeout,
257 .ndo_change_mtu = eth_change_mtu,
258 .ndo_set_mac_address = eth_mac_addr,
259 .ndo_validate_addr = eth_validate_addr,
262 /* The Fujitsu datasheet suggests that the NIC be probed for by checking its
263 "signature", the default bit pattern after a reset. This *doesn't* work --
264 there is no way to reset the bus interface without a complete power-cycle!
266 It turns out that ATI came to the same conclusion I did: the only thing
267 that can be done is checking a few bits and then diving right into an
268 EEPROM read. */
270 static int __init at1700_probe1(struct net_device *dev, int ioaddr)
272 static const char fmv_irqmap[4] = {3, 7, 10, 15};
273 static const char fmv_irqmap_pnp[8] = {3, 4, 5, 7, 9, 10, 11, 15};
274 static const char at1700_irqmap[8] = {3, 4, 5, 9, 10, 11, 14, 15};
275 unsigned int i, irq, is_fmv18x = 0, is_at1700 = 0;
276 int slot, ret = -ENODEV;
277 struct net_local *lp = netdev_priv(dev);
279 if (!request_region(ioaddr, AT1700_IO_EXTENT, DRV_NAME))
280 return -EBUSY;
282 /* Resetting the chip doesn't reset the ISA interface, so don't bother.
283 That means we have to be careful with the register values we probe
284 for.
286 #ifdef notdef
287 printk("at1700 probe at %#x, eeprom is %4.4x %4.4x %4.4x ctrl %4.4x.\n",
288 ioaddr, read_eeprom(ioaddr, 4), read_eeprom(ioaddr, 5),
289 read_eeprom(ioaddr, 6), inw(ioaddr + EEPROM_Ctrl));
290 #endif
292 #ifdef CONFIG_MCA_LEGACY
293 /* rEnE (rene@bss.lu): got this from 3c509 driver source , adapted for AT1720 */
295 /* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch, heavily
296 modified by Chris Beauregard (cpbeaure@csclub.uwaterloo.ca)
297 to support standard MCA probing. */
299 /* redone for multi-card detection by ZP Gu (zpg@castle.net) */
300 /* now works as a module */
302 if (MCA_bus) {
303 int j;
304 int l_i;
305 u_char pos3, pos4;
307 for (j = 0; at1720_mca_adapters[j].name != NULL; j ++) {
308 slot = 0;
309 while (slot != MCA_NOTFOUND) {
311 slot = mca_find_unused_adapter( at1720_mca_adapters[j].id, slot );
312 if (slot == MCA_NOTFOUND) break;
314 /* if we get this far, an adapter has been detected and is
315 enabled */
317 pos3 = mca_read_stored_pos( slot, 3 );
318 pos4 = mca_read_stored_pos( slot, 4 );
320 for (l_i = 0; l_i < 8; l_i++)
321 if (( pos3 & 0x07) == at1700_ioaddr_pattern[l_i])
322 break;
323 ioaddr = at1700_mca_probe_list[l_i];
325 for (irq = 0; irq < 0x10; irq++)
326 if (((((pos4>>4) & 0x0f) | (pos3 & 0xf0)) & 0xff) == at1700_irq_pattern[irq])
327 break;
329 /* probing for a card at a particular IO/IRQ */
330 if ((dev->irq && dev->irq != irq) ||
331 (dev->base_addr && dev->base_addr != ioaddr)) {
332 slot++; /* probing next slot */
333 continue;
336 dev->irq = irq;
338 /* claim the slot */
339 mca_set_adapter_name( slot, at1720_mca_adapters[j].name );
340 mca_mark_as_used(slot);
342 goto found;
345 /* if we get here, we didn't find an MCA adapter - try ISA */
347 #endif
348 slot = -1;
349 /* We must check for the EEPROM-config boards first, else accessing
350 IOCONFIG0 will move the board! */
351 if (at1700_probe_list[inb(ioaddr + IOCONFIG1) & 0x07] == ioaddr &&
352 read_eeprom(ioaddr, 4) == 0x0000 &&
353 (read_eeprom(ioaddr, 5) & 0xff00) == 0xF400)
354 is_at1700 = 1;
355 else if (inb(ioaddr + SAPROM ) == 0x00 &&
356 inb(ioaddr + SAPROM + 1) == 0x00 &&
357 inb(ioaddr + SAPROM + 2) == 0x0e)
358 is_fmv18x = 1;
359 else {
360 goto err_out;
363 #ifdef CONFIG_MCA_LEGACY
364 found:
365 #endif
367 /* Reset the internal state machines. */
368 outb(0, ioaddr + RESET);
370 if (is_at1700) {
371 irq = at1700_irqmap[(read_eeprom(ioaddr, 12)&0x04)
372 | (read_eeprom(ioaddr, 0)>>14)];
373 } else {
374 /* Check PnP mode for FMV-183/184/183A/184A. */
375 /* This PnP routine is very poor. IO and IRQ should be known. */
376 if (inb(ioaddr + CARDSTATUS1) & 0x20) {
377 irq = dev->irq;
378 for (i = 0; i < 8; i++) {
379 if (irq == fmv_irqmap_pnp[i])
380 break;
382 if (i == 8) {
383 goto err_mca;
385 } else {
386 if (fmv18x_probe_list[inb(ioaddr + IOCONFIG) & 0x07] != ioaddr)
387 goto err_mca;
388 irq = fmv_irqmap[(inb(ioaddr + IOCONFIG)>>6) & 0x03];
392 printk("%s: %s found at %#3x, IRQ %d, address ", dev->name,
393 is_at1700 ? "AT1700" : "FMV-18X", ioaddr, irq);
395 dev->base_addr = ioaddr;
396 dev->irq = irq;
398 if (is_at1700) {
399 for(i = 0; i < 3; i++) {
400 unsigned short eeprom_val = read_eeprom(ioaddr, 4+i);
401 ((unsigned short *)dev->dev_addr)[i] = ntohs(eeprom_val);
403 } else {
404 for(i = 0; i < 6; i++) {
405 unsigned char val = inb(ioaddr + SAPROM + i);
406 dev->dev_addr[i] = val;
409 printk("%pM", dev->dev_addr);
411 /* The EEPROM word 12 bit 0x0400 means use regular 100 ohm 10baseT signals,
412 rather than 150 ohm shielded twisted pair compensation.
413 0x0000 == auto-sense the interface
414 0x0800 == use TP interface
415 0x1800 == use coax interface
418 const char *porttype[] = {"auto-sense", "10baseT", "auto-sense", "10base2"};
419 if (is_at1700) {
420 ushort setup_value = read_eeprom(ioaddr, 12);
421 dev->if_port = setup_value >> 8;
422 } else {
423 ushort setup_value = inb(ioaddr + CARDSTATUS);
424 switch (setup_value & 0x07) {
425 case 0x01: /* 10base5 */
426 case 0x02: /* 10base2 */
427 dev->if_port = 0x18; break;
428 case 0x04: /* 10baseT */
429 dev->if_port = 0x08; break;
430 default: /* auto-sense */
431 dev->if_port = 0x00; break;
434 printk(" %s interface.\n", porttype[(dev->if_port>>3) & 3]);
437 /* Set the configuration register 0 to 32K 100ns. byte-wide memory, 16 bit
438 bus access, two 4K Tx queues, and disabled Tx and Rx. */
439 outb(0xda, ioaddr + CONFIG_0);
441 /* Set the station address in bank zero. */
442 outb(0x00, ioaddr + CONFIG_1);
443 for (i = 0; i < 6; i++)
444 outb(dev->dev_addr[i], ioaddr + PORT_OFFSET(8 + i));
446 /* Switch to bank 1 and set the multicast table to accept none. */
447 outb(0x04, ioaddr + CONFIG_1);
448 for (i = 0; i < 8; i++)
449 outb(0x00, ioaddr + PORT_OFFSET(8 + i));
452 /* Switch to bank 2 */
453 /* Lock our I/O address, and set manual processing mode for 16 collisions. */
454 outb(0x08, ioaddr + CONFIG_1);
455 outb(dev->if_port, ioaddr + MODE13);
456 outb(0x00, ioaddr + COL16CNTL);
458 if (net_debug)
459 printk(version);
461 dev->netdev_ops = &at1700_netdev_ops;
462 dev->watchdog_timeo = TX_TIMEOUT;
464 spin_lock_init(&lp->lock);
466 lp->jumpered = is_fmv18x;
467 lp->mca_slot = slot;
468 /* Snarf the interrupt vector now. */
469 ret = request_irq(irq, net_interrupt, 0, DRV_NAME, dev);
470 if (ret) {
471 printk(KERN_ERR "AT1700 at %#3x is unusable due to a "
472 "conflict on IRQ %d.\n",
473 ioaddr, irq);
474 goto err_mca;
477 return 0;
479 err_mca:
480 #ifdef CONFIG_MCA_LEGACY
481 if (slot >= 0)
482 mca_mark_as_unused(slot);
483 #endif
484 err_out:
485 release_region(ioaddr, AT1700_IO_EXTENT);
486 return ret;
490 /* EEPROM_Ctrl bits. */
491 #define EE_SHIFT_CLK 0x40 /* EEPROM shift clock, in reg. 16. */
492 #define EE_CS 0x20 /* EEPROM chip select, in reg. 16. */
493 #define EE_DATA_WRITE 0x80 /* EEPROM chip data in, in reg. 17. */
494 #define EE_DATA_READ 0x80 /* EEPROM chip data out, in reg. 17. */
496 /* The EEPROM commands include the alway-set leading bit. */
497 #define EE_WRITE_CMD (5 << 6)
498 #define EE_READ_CMD (6 << 6)
499 #define EE_ERASE_CMD (7 << 6)
501 static int __init read_eeprom(long ioaddr, int location)
503 int i;
504 unsigned short retval = 0;
505 long ee_addr = ioaddr + EEPROM_Ctrl;
506 long ee_daddr = ioaddr + EEPROM_Data;
507 int read_cmd = location | EE_READ_CMD;
509 /* Shift the read command bits out. */
510 for (i = 9; i >= 0; i--) {
511 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
512 outb(EE_CS, ee_addr);
513 outb(dataval, ee_daddr);
514 outb(EE_CS | EE_SHIFT_CLK, ee_addr); /* EEPROM clock tick. */
516 outb(EE_DATA_WRITE, ee_daddr);
517 for (i = 16; i > 0; i--) {
518 outb(EE_CS, ee_addr);
519 outb(EE_CS | EE_SHIFT_CLK, ee_addr);
520 retval = (retval << 1) | ((inb(ee_daddr) & EE_DATA_READ) ? 1 : 0);
523 /* Terminate the EEPROM access. */
524 outb(EE_CS, ee_addr);
525 outb(EE_SHIFT_CLK, ee_addr);
526 outb(0, ee_addr);
527 return retval;
532 static int net_open(struct net_device *dev)
534 struct net_local *lp = netdev_priv(dev);
535 int ioaddr = dev->base_addr;
537 /* Set the configuration register 0 to 32K 100ns. byte-wide memory, 16 bit
538 bus access, and two 4K Tx queues. */
539 outb(0x5a, ioaddr + CONFIG_0);
541 /* Powerup, switch to register bank 2, and enable the Rx and Tx. */
542 outb(0xe8, ioaddr + CONFIG_1);
544 lp->tx_started = 0;
545 lp->tx_queue_ready = 1;
546 lp->rx_started = 0;
547 lp->tx_queue = 0;
548 lp->tx_queue_len = 0;
550 /* Turn on hardware Tx and Rx interrupts. */
551 outb(0x82, ioaddr + TX_INTR);
552 outb(0x81, ioaddr + RX_INTR);
554 /* Enable the IRQ on boards of fmv18x it is feasible. */
555 if (lp->jumpered) {
556 outb(0x80, ioaddr + IOCONFIG1);
559 netif_start_queue(dev);
560 return 0;
563 static void net_tx_timeout (struct net_device *dev)
565 struct net_local *lp = netdev_priv(dev);
566 int ioaddr = dev->base_addr;
568 printk ("%s: transmit timed out with status %04x, %s?\n", dev->name,
569 inw (ioaddr + STATUS), inb (ioaddr + TX_STATUS) & 0x80
570 ? "IRQ conflict" : "network cable problem");
571 printk ("%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n",
572 dev->name, inw(ioaddr + TX_STATUS), inw(ioaddr + TX_INTR), inw(ioaddr + TX_MODE),
573 inw(ioaddr + CONFIG_0), inw(ioaddr + DATAPORT), inw(ioaddr + TX_START),
574 inw(ioaddr + MODE13 - 1), inw(ioaddr + RX_CTRL));
575 dev->stats.tx_errors++;
576 /* ToDo: We should try to restart the adaptor... */
577 outw(0xffff, ioaddr + MODE24);
578 outw (0xffff, ioaddr + TX_STATUS);
579 outb (0x5a, ioaddr + CONFIG_0);
580 outb (0xe8, ioaddr + CONFIG_1);
581 outw (0x8182, ioaddr + TX_INTR);
582 outb (0x00, ioaddr + TX_START);
583 outb (0x03, ioaddr + COL16CNTL);
585 dev->trans_start = jiffies; /* prevent tx timeout */
587 lp->tx_started = 0;
588 lp->tx_queue_ready = 1;
589 lp->rx_started = 0;
590 lp->tx_queue = 0;
591 lp->tx_queue_len = 0;
593 netif_wake_queue(dev);
597 static netdev_tx_t net_send_packet (struct sk_buff *skb,
598 struct net_device *dev)
600 struct net_local *lp = netdev_priv(dev);
601 int ioaddr = dev->base_addr;
602 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
603 short len = skb->len;
604 unsigned char *buf = skb->data;
605 static u8 pad[ETH_ZLEN];
607 netif_stop_queue (dev);
609 /* We may not start transmitting unless we finish transferring
610 a packet into the Tx queue. During executing the following
611 codes we possibly catch a Tx interrupt. Thus we flag off
612 tx_queue_ready, so that we prevent the interrupt routine
613 (net_interrupt) to start transmitting. */
614 lp->tx_queue_ready = 0;
616 outw (length, ioaddr + DATAPORT);
617 /* Packet data */
618 outsw (ioaddr + DATAPORT, buf, len >> 1);
619 /* Check for dribble byte */
620 if (len & 1) {
621 outw(skb->data[skb->len-1], ioaddr + DATAPORT);
622 len++;
624 /* Check for packet padding */
625 if (length != skb->len)
626 outsw(ioaddr + DATAPORT, pad, (length - len + 1) >> 1);
628 lp->tx_queue++;
629 lp->tx_queue_len += length + 2;
631 lp->tx_queue_ready = 1;
633 if (lp->tx_started == 0) {
634 /* If the Tx is idle, always trigger a transmit. */
635 outb (0x80 | lp->tx_queue, ioaddr + TX_START);
636 lp->tx_queue = 0;
637 lp->tx_queue_len = 0;
638 lp->tx_started = 1;
639 netif_start_queue (dev);
640 } else if (lp->tx_queue_len < 4096 - 1502)
641 /* Yes, there is room for one more packet. */
642 netif_start_queue (dev);
643 dev_kfree_skb (skb);
645 return NETDEV_TX_OK;
648 /* The typical workload of the driver:
649 Handle the network interface interrupts. */
650 static irqreturn_t net_interrupt(int irq, void *dev_id)
652 struct net_device *dev = dev_id;
653 struct net_local *lp;
654 int ioaddr, status;
655 int handled = 0;
657 if (dev == NULL) {
658 printk ("at1700_interrupt(): irq %d for unknown device.\n", irq);
659 return IRQ_NONE;
662 ioaddr = dev->base_addr;
663 lp = netdev_priv(dev);
665 spin_lock (&lp->lock);
667 status = inw(ioaddr + TX_STATUS);
668 outw(status, ioaddr + TX_STATUS);
670 if (net_debug > 4)
671 printk("%s: Interrupt with status %04x.\n", dev->name, status);
672 if (lp->rx_started == 0 &&
673 (status & 0xff00 || (inb(ioaddr + RX_MODE) & 0x40) == 0)) {
674 /* Got a packet(s).
675 We cannot execute net_rx more than once at the same time for
676 the same device. During executing net_rx, we possibly catch a
677 Tx interrupt. Thus we flag on rx_started, so that we prevent
678 the interrupt routine (net_interrupt) to dive into net_rx
679 again. */
680 handled = 1;
681 lp->rx_started = 1;
682 outb(0x00, ioaddr + RX_INTR); /* Disable RX intr. */
683 net_rx(dev);
684 outb(0x81, ioaddr + RX_INTR); /* Enable RX intr. */
685 lp->rx_started = 0;
687 if (status & 0x00ff) {
688 handled = 1;
689 if (status & 0x02) {
690 /* More than 16 collisions occurred */
691 if (net_debug > 4)
692 printk("%s: 16 Collision occur during Txing.\n", dev->name);
693 /* Cancel sending a packet. */
694 outb(0x03, ioaddr + COL16CNTL);
695 dev->stats.collisions++;
697 if (status & 0x82) {
698 dev->stats.tx_packets++;
699 /* The Tx queue has any packets and is not being
700 transferred a packet from the host, start
701 transmitting. */
702 if (lp->tx_queue && lp->tx_queue_ready) {
703 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
704 lp->tx_queue = 0;
705 lp->tx_queue_len = 0;
706 dev->trans_start = jiffies;
707 netif_wake_queue (dev);
708 } else {
709 lp->tx_started = 0;
710 netif_wake_queue (dev);
715 spin_unlock (&lp->lock);
716 return IRQ_RETVAL(handled);
719 /* We have a good packet(s), get it/them out of the buffers. */
720 static void
721 net_rx(struct net_device *dev)
723 int ioaddr = dev->base_addr;
724 int boguscount = 5;
726 while ((inb(ioaddr + RX_MODE) & 0x40) == 0) {
727 ushort status = inw(ioaddr + DATAPORT);
728 ushort pkt_len = inw(ioaddr + DATAPORT);
730 if (net_debug > 4)
731 printk("%s: Rxing packet mode %02x status %04x.\n",
732 dev->name, inb(ioaddr + RX_MODE), status);
733 #ifndef final_version
734 if (status == 0) {
735 outb(0x05, ioaddr + RX_CTRL);
736 break;
738 #endif
740 if ((status & 0xF0) != 0x20) { /* There was an error. */
741 dev->stats.rx_errors++;
742 if (status & 0x08) dev->stats.rx_length_errors++;
743 if (status & 0x04) dev->stats.rx_frame_errors++;
744 if (status & 0x02) dev->stats.rx_crc_errors++;
745 if (status & 0x01) dev->stats.rx_over_errors++;
746 } else {
747 /* Malloc up new buffer. */
748 struct sk_buff *skb;
750 if (pkt_len > 1550) {
751 printk("%s: The AT1700 claimed a very large packet, size %d.\n",
752 dev->name, pkt_len);
753 /* Prime the FIFO and then flush the packet. */
754 inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
755 outb(0x05, ioaddr + RX_CTRL);
756 dev->stats.rx_errors++;
757 break;
759 skb = netdev_alloc_skb(dev, pkt_len + 3);
760 if (skb == NULL) {
761 printk("%s: Memory squeeze, dropping packet (len %d).\n",
762 dev->name, pkt_len);
763 /* Prime the FIFO and then flush the packet. */
764 inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
765 outb(0x05, ioaddr + RX_CTRL);
766 dev->stats.rx_dropped++;
767 break;
769 skb_reserve(skb,2);
771 insw(ioaddr + DATAPORT, skb_put(skb,pkt_len), (pkt_len + 1) >> 1);
772 skb->protocol=eth_type_trans(skb, dev);
773 netif_rx(skb);
774 dev->stats.rx_packets++;
775 dev->stats.rx_bytes += pkt_len;
777 if (--boguscount <= 0)
778 break;
781 /* If any worth-while packets have been received, dev_rint()
782 has done a mark_bh(NET_BH) for us and will work on them
783 when we get to the bottom-half routine. */
785 int i;
786 for (i = 0; i < 20; i++) {
787 if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40)
788 break;
789 inw(ioaddr + DATAPORT); /* dummy status read */
790 outb(0x05, ioaddr + RX_CTRL);
793 if (net_debug > 5)
794 printk("%s: Exint Rx packet with mode %02x after %d ticks.\n",
795 dev->name, inb(ioaddr + RX_MODE), i);
799 /* The inverse routine to net_open(). */
800 static int net_close(struct net_device *dev)
802 struct net_local *lp = netdev_priv(dev);
803 int ioaddr = dev->base_addr;
805 netif_stop_queue(dev);
807 /* Set configuration register 0 to disable Tx and Rx. */
808 outb(0xda, ioaddr + CONFIG_0);
810 /* No statistic counters on the chip to update. */
812 /* Disable the IRQ on boards of fmv18x where it is feasible. */
813 if (lp->jumpered)
814 outb(0x00, ioaddr + IOCONFIG1);
816 /* Power-down the chip. Green, green, green! */
817 outb(0x00, ioaddr + CONFIG_1);
818 return 0;
822 Set the multicast/promiscuous mode for this adaptor.
825 static void
826 set_rx_mode(struct net_device *dev)
828 int ioaddr = dev->base_addr;
829 struct net_local *lp = netdev_priv(dev);
830 unsigned char mc_filter[8]; /* Multicast hash filter */
831 unsigned long flags;
833 if (dev->flags & IFF_PROMISC) {
834 memset(mc_filter, 0xff, sizeof(mc_filter));
835 outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */
836 } else if (netdev_mc_count(dev) > MC_FILTERBREAK ||
837 (dev->flags & IFF_ALLMULTI)) {
838 /* Too many to filter perfectly -- accept all multicasts. */
839 memset(mc_filter, 0xff, sizeof(mc_filter));
840 outb(2, ioaddr + RX_MODE); /* Use normal mode. */
841 } else if (netdev_mc_empty(dev)) {
842 memset(mc_filter, 0x00, sizeof(mc_filter));
843 outb(1, ioaddr + RX_MODE); /* Ignore almost all multicasts. */
844 } else {
845 struct netdev_hw_addr *ha;
847 memset(mc_filter, 0, sizeof(mc_filter));
848 netdev_for_each_mc_addr(ha, dev) {
849 unsigned int bit =
850 ether_crc_le(ETH_ALEN, ha->addr) >> 26;
851 mc_filter[bit >> 3] |= (1 << bit);
853 outb(0x02, ioaddr + RX_MODE); /* Use normal mode. */
856 spin_lock_irqsave (&lp->lock, flags);
857 if (memcmp(mc_filter, lp->mc_filter, sizeof(mc_filter))) {
858 int i;
859 int saved_bank = inw(ioaddr + CONFIG_0);
860 /* Switch to bank 1 and set the multicast table. */
861 outw((saved_bank & ~0x0C00) | 0x0480, ioaddr + CONFIG_0);
862 for (i = 0; i < 8; i++)
863 outb(mc_filter[i], ioaddr + PORT_OFFSET(8 + i));
864 memcpy(lp->mc_filter, mc_filter, sizeof(mc_filter));
865 outw(saved_bank, ioaddr + CONFIG_0);
867 spin_unlock_irqrestore (&lp->lock, flags);
870 #ifdef MODULE
871 static struct net_device *dev_at1700;
873 module_param(io, int, 0);
874 module_param(irq, int, 0);
875 module_param(net_debug, int, 0);
876 MODULE_PARM_DESC(io, "AT1700/FMV18X I/O base address");
877 MODULE_PARM_DESC(irq, "AT1700/FMV18X IRQ number");
878 MODULE_PARM_DESC(net_debug, "AT1700/FMV18X debug level (0-6)");
880 static int __init at1700_module_init(void)
882 if (io == 0)
883 printk("at1700: You should not use auto-probing with insmod!\n");
884 dev_at1700 = at1700_probe(-1);
885 if (IS_ERR(dev_at1700))
886 return PTR_ERR(dev_at1700);
887 return 0;
890 static void __exit at1700_module_exit(void)
892 unregister_netdev(dev_at1700);
893 cleanup_card(dev_at1700);
894 free_netdev(dev_at1700);
896 module_init(at1700_module_init);
897 module_exit(at1700_module_exit);
898 #endif /* MODULE */
899 MODULE_LICENSE("GPL");