Import 2.2.0pre6
[davej-history.git] / drivers / net / 3c515.c
blob7dc831e58f69f3c8cef7c1202a3a290025c0d8f7
1 /* 3c515.c: A 3Com ISA EtherLink XL "Corkscrew" ethernet driver for linux. */
2 /*
3 Written 1997-1998 by Donald Becker.
5 This software may be used and distributed according to the terms
6 of the GNU Public License, incorporated herein by reference.
8 This driver is for the 3Com ISA EtherLink XL "Corkscrew" 3c515 ethercard.
10 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
11 Center of Excellence in Space Data and Information Sciences
12 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
15 static char *version = "3c515.c:v0.99 4/7/98 becker@cesdis.gsfc.nasa.gov\n";
16 #define CORKSCREW 1
18 /* "Knobs" that adjust features and parameters. */
19 /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
20 Setting to > 1512 effectively disables this feature. */
21 static const int rx_copybreak = 200;
22 /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
23 static const int mtu = 1500;
24 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
25 static int max_interrupt_work = 20;
27 /* Enable the automatic media selection code -- usually set. */
28 #define AUTOMEDIA 1
30 /* Allow the use of fragment bus master transfers instead of only
31 programmed-I/O for Vortex cards. Full-bus-master transfers are always
32 enabled by default on Boomerang cards. If VORTEX_BUS_MASTER is defined,
33 the feature may be turned on using 'options'. */
34 #define VORTEX_BUS_MASTER
36 /* A few values that may be tweaked. */
37 /* Keep the ring sizes a power of two for efficiency. */
38 #define TX_RING_SIZE 16
39 #define RX_RING_SIZE 16
40 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
42 #include <linux/module.h>
43 #include <linux/version.h>
45 #include <linux/kernel.h>
46 #include <linux/sched.h>
47 #include <linux/string.h>
48 #include <linux/ptrace.h>
49 #include <linux/errno.h>
50 #include <linux/in.h>
51 #include <linux/ioport.h>
52 #include <linux/malloc.h>
53 #include <linux/interrupt.h>
54 #include <linux/timer.h>
55 #include <asm/bitops.h>
56 #include <asm/io.h>
57 #include <asm/dma.h>
59 #include <linux/netdevice.h>
60 #include <linux/etherdevice.h>
61 #include <linux/skbuff.h>
63 #define NEW_MULTICAST
64 #include <linux/delay.h>
66 /* Kernel version compatibility functions. */
67 #define RUN_AT(x) (jiffies + (x))
68 #define DEV_ALLOC_SKB(len) dev_alloc_skb(len + 2)
70 #define FREE_IRQ(irqnum, dev) free_irq(irqnum, dev)
71 #define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n, instance)
72 #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
74 #if (LINUX_VERSION_CODE < 0x20123)
75 #define test_and_set_bit(val, addr) set_bit(val, addr)
76 #elif defined(MODULE)
77 MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
78 MODULE_DESCRIPTION("3Com 3c515 Corkscrew driver");
79 MODULE_PARM(debug, "i");
80 MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
81 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
82 MODULE_PARM(rx_copybreak, "i");
83 MODULE_PARM(max_interrupt_work, "i");
84 #endif
86 /* "Knobs" for adjusting internal parameters. */
87 /* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */
88 #define DRIVER_DEBUG 1
89 /* Some values here only for performance evaluation and path-coverage
90 debugging. */
91 static int rx_nocopy = 0, rx_copy = 0, queued_packet = 0;
93 /* Number of times to check to see if the Tx FIFO has space, used in some
94 limited cases. */
95 #define WAIT_TX_AVAIL 200
97 /* Operational parameter that usually are not changed. */
98 #define TX_TIMEOUT 40 /* Time in jiffies before concluding Tx hung */
100 /* The size here is somewhat misleading: the Corkscrew also uses the ISA
101 aliased registers at <base>+0x400.
103 #define CORKSCREW_TOTAL_SIZE 0x20
105 #ifdef HAVE_DEVLIST
106 struct netdev_entry tc515_drv =
107 {"3c515", tc515_probe, CORKSCREW_TOTAL_SIZE, NULL};
108 #endif
110 #ifdef DRIVER_DEBUG
111 int vortex_debug = DRIVER_DEBUG;
112 #else
113 int vortex_debug = 1;
114 #endif
116 #define CORKSCREW_ID 10
119 Theory of Operation
121 I. Board Compatibility
123 This device driver is designed for the 3Com 3c515 ISA Fast EtherLink XL,
124 3Com's ISA bus adapter for Fast Ethernet. Due to the unique I/O port layout,
125 it's not practical to integrate this driver with the other EtherLink drivers.
127 II. Board-specific settings
129 The Corkscrew has an EEPROM for configuration, but no special settings are
130 needed for Linux.
132 III. Driver operation
134 The 3c515 series use an interface that's very similar to the 3c900 "Boomerang"
135 PCI cards, with the bus master interface extensively modified to work with
136 the ISA bus.
138 The card is capable of full-bus-master transfers with separate
139 lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
140 DEC Tulip and Intel Speedo3.
142 This driver uses a "RX_COPYBREAK" scheme rather than a fixed intermediate
143 receive buffer. This scheme allocates full-sized skbuffs as receive
144 buffers. The value RX_COPYBREAK is used as the copying breakpoint: it is
145 chosen to trade-off the memory wasted by passing the full-sized skbuff to
146 the queue layer for all frames vs. the copying cost of copying a frame to a
147 correctly-sized skbuff.
150 IIIC. Synchronization
151 The driver runs as two independent, single-threaded flows of control. One
152 is the send-packet routine, which enforces single-threaded use by the
153 dev->tbusy flag. The other thread is the interrupt handler, which is single
154 threaded by the hardware and other software.
156 IV. Notes
158 Thanks to Terry Murphy of 3Com for providing documentation and a development
159 board.
161 The names "Vortex", "Boomerang" and "Corkscrew" are the internal 3Com
162 project names. I use these names to eliminate confusion -- 3Com product
163 numbers and names are very similar and often confused.
165 The new chips support both ethernet (1.5K) and FDDI (4.5K) frame sizes!
166 This driver only supports ethernet frames because of the recent MTU limit
167 of 1.5K, but the changes to support 4.5K are minimal.
170 /* Operational definitions.
171 These are not used by other compilation units and thus are not
172 exported in a ".h" file.
174 First the windows. There are eight register windows, with the command
175 and status registers available in each.
177 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
178 #define EL3_CMD 0x0e
179 #define EL3_STATUS 0x0e
181 /* The top five bits written to EL3_CMD are a command, the lower
182 11 bits are the parameter, if applicable.
183 Note that 11 parameters bits was fine for ethernet, but the new chips
184 can handle FDDI length frames (~4500 octets) and now parameters count
185 32-bit 'Dwords' rather than octets. */
187 enum vortex_cmd {
188 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
189 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
190 UpStall = 6<<11, UpUnstall = (6<<11)+1,
191 DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
192 RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
193 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
194 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
195 SetTxThreshold = 18<<11, SetTxStart = 19<<11,
196 StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
197 StatsDisable = 22<<11, StopCoax = 23<<11,};
199 /* The SetRxFilter command accepts the following classes: */
200 enum RxFilter {
201 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
203 /* Bits in the general status register. */
204 enum vortex_status {
205 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
206 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
207 IntReq = 0x0040, StatsFull = 0x0080,
208 DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
209 DMAInProgress = 1<<11, /* DMA controller is still busy.*/
210 CmdInProgress = 1<<12, /* EL3_CMD is still busy.*/
213 /* Register window 1 offsets, the window used in normal operation.
214 On the Corkscrew this window is always mapped at offsets 0x10-0x1f. */
215 enum Window1 {
216 TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
217 RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
218 TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
220 enum Window0 {
221 Wn0IRQ = 0x08,
222 #if defined(CORKSCREW)
223 Wn0EepromCmd = 0x200A, /* Corkscrew EEPROM command register. */
224 Wn0EepromData = 0x200C, /* Corkscrew EEPROM results register. */
225 #else
226 Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */
227 Wn0EepromData = 12, /* Window 0: EEPROM results register. */
228 #endif
230 enum Win0_EEPROM_bits {
231 EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
232 EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
233 EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
235 /* EEPROM locations. */
236 enum eeprom_offset {
237 PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
238 EtherLink3ID=7, };
240 enum Window3 { /* Window 3: MAC/config bits. */
241 Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
243 union wn3_config {
244 int i;
245 struct w3_config_fields {
246 unsigned int ram_size:3, ram_width:1, ram_speed:2, rom_size:2;
247 int pad8:8;
248 unsigned int ram_split:2, pad18:2, xcvr:3, pad21:1, autoselect:1;
249 int pad24:7;
250 } u;
253 enum Window4 {
254 Wn4_NetDiag = 6, Wn4_Media = 10, /* Window 4: Xcvr/media bits. */
256 enum Win4_Media_bits {
257 Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */
258 Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */
259 Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
260 Media_LnkBeat = 0x0800,
262 enum Window7 { /* Window 7: Bus Master control. */
263 Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
265 /* Boomerang-style bus master control registers. Note ISA aliases! */
266 enum MasterCtrl {
267 PktStatus = 0x400, DownListPtr = 0x404, FragAddr = 0x408, FragLen = 0x40c,
268 TxFreeThreshold = 0x40f, UpPktStatus = 0x410, UpListPtr = 0x418,
271 /* The Rx and Tx descriptor lists.
272 Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
273 alignment contraint on tx_ring[] and rx_ring[]. */
274 struct boom_rx_desc {
275 u32 next;
276 s32 status;
277 u32 addr;
278 s32 length;
280 /* Values for the Rx status entry. */
281 enum rx_desc_status {
282 RxDComplete=0x00008000, RxDError=0x4000,
283 /* See boomerang_rx() for actual error bits */
286 struct boom_tx_desc {
287 u32 next;
288 s32 status;
289 u32 addr;
290 s32 length;
293 struct vortex_private {
294 char devname[8]; /* "ethN" string, also for kernel debug. */
295 const char *product_name;
296 struct device *next_module;
297 /* The Rx and Tx rings are here to keep them quad-word-aligned. */
298 struct boom_rx_desc rx_ring[RX_RING_SIZE];
299 struct boom_tx_desc tx_ring[TX_RING_SIZE];
300 /* The addresses of transmit- and receive-in-place skbuffs. */
301 struct sk_buff* rx_skbuff[RX_RING_SIZE];
302 struct sk_buff* tx_skbuff[TX_RING_SIZE];
303 unsigned int cur_rx, cur_tx; /* The next free ring entry */
304 unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
305 struct enet_statistics stats;
306 struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
307 struct timer_list timer; /* Media selection timer. */
308 int capabilities; /* Adapter capabilities word. */
309 int options; /* User-settable misc. driver options. */
310 int last_rx_packets; /* For media autoselection. */
311 unsigned int available_media:8, /* From Wn3_Options */
312 media_override:3, /* Passed-in media type. */
313 default_media:3, /* Read from the EEPROM. */
314 full_duplex:1, autoselect:1,
315 bus_master:1, /* Vortex can only do a fragment bus-m. */
316 full_bus_master_tx:1, full_bus_master_rx:1, /* Boomerang */
317 tx_full:1;
320 /* The action to take with a media selection timer tick.
321 Note that we deviate from the 3Com order by checking 10base2 before AUI.
323 enum xcvr_types {
324 XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
325 XCVR_100baseFx, XCVR_MII=6, XCVR_Default=8,
328 static struct media_table {
329 char *name;
330 unsigned int media_bits:16, /* Bits to set in Wn4_Media register. */
331 mask:8, /* The transceiver-present bit in Wn3_Config.*/
332 next:8; /* The media type to try next. */
333 short wait; /* Time before we check media status. */
334 } media_tbl[] = {
335 { "10baseT", Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
336 { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
337 { "undefined", 0, 0x80, XCVR_10baseT, 10000},
338 { "10base2", 0, 0x10, XCVR_AUI, (1*HZ)/10},
339 { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
340 { "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14*HZ)/10},
341 { "MII", 0, 0x40, XCVR_10baseT, 3*HZ },
342 { "undefined", 0, 0x01, XCVR_10baseT, 10000},
343 { "Default", 0, 0xFF, XCVR_10baseT, 10000},
346 static int vortex_scan(struct device *dev);
347 static struct device *vortex_found_device(struct device *dev, int ioaddr,
348 int irq, int product_index,
349 int options);
350 static int vortex_probe1(struct device *dev);
351 static int vortex_open(struct device *dev);
352 static void vortex_timer(unsigned long arg);
353 static int vortex_start_xmit(struct sk_buff *skb, struct device *dev);
354 static int vortex_rx(struct device *dev);
355 static int boomerang_rx(struct device *dev);
356 static void vortex_interrupt IRQ(int irq, void *dev_id, struct pt_regs *regs);
357 static int vortex_close(struct device *dev);
358 static void update_stats(int addr, struct device *dev);
359 static struct enet_statistics *vortex_get_stats(struct device *dev);
360 static void set_rx_mode(struct device *dev);
363 /* Unlike the other PCI cards the 59x cards don't need a large contiguous
364 memory region, so making the driver a loadable module is feasible.
366 Unfortunately maximizing the shared code between the integrated and
367 module version of the driver results in a complicated set of initialization
368 procedures.
369 init_module() -- modules / tc59x_init() -- built-in
370 The wrappers for vortex_scan()
371 vortex_scan() The common routine that scans for PCI and EISA cards
372 vortex_found_device() Allocate a device structure when we find a card.
373 Different versions exist for modules and built-in.
374 vortex_probe1() Fill in the device structure -- this is separated
375 so that the modules code can put it in dev->init.
377 /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
378 /* Note: this is the only limit on the number of cards supported!! */
379 static int options[8] = { -1, -1, -1, -1, -1, -1, -1, -1,};
381 #ifdef MODULE
382 static int debug = -1;
383 /* A list of all installed Vortex devices, for removing the driver module. */
384 static struct device *root_vortex_dev = NULL;
387 init_module(void)
389 int cards_found;
391 if (debug >= 0)
392 vortex_debug = debug;
393 if (vortex_debug)
394 printk(version);
396 root_vortex_dev = NULL;
397 cards_found = vortex_scan(0);
398 return cards_found ? 0 : -ENODEV;
401 #else
402 int tc515_probe(struct device *dev)
404 int cards_found = 0;
406 cards_found = vortex_scan(dev);
408 if (vortex_debug > 0 && cards_found)
409 printk(version);
411 return cards_found ? 0 : -ENODEV;
413 #endif /* not MODULE */
415 static int vortex_scan(struct device *dev)
417 int cards_found = 0;
418 static int ioaddr = 0x100;
420 /* Check all locations on the ISA bus -- evil! */
421 for (; ioaddr < 0x400; ioaddr += 0x20) {
422 int irq;
423 if (check_region(ioaddr, CORKSCREW_TOTAL_SIZE))
424 continue;
425 /* Check the resource configuration for a matching ioaddr. */
426 if ((inw(ioaddr + 0x2002) & 0x1f0) != (ioaddr & 0x1f0))
427 continue;
428 /* Verify by reading the device ID from the EEPROM. */
430 int timer;
431 outw(EEPROM_Read + 7, ioaddr + Wn0EepromCmd);
432 /* Pause for at least 162 us. for the read to take place. */
433 for (timer = 4; timer >= 0; timer--) {
434 udelay(162);
435 if ((inw(ioaddr + Wn0EepromCmd) & 0x0200) == 0)
436 break;
438 if (inw(ioaddr + Wn0EepromData) != 0x6d50)
439 continue;
441 printk("3c515 Resource configuraiton register %#4.4x, DCR %4.4x.\n",
442 inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
443 irq = inw(ioaddr + 0x2002) & 15;
444 vortex_found_device(dev, ioaddr, irq, CORKSCREW_ID, dev && dev->mem_start
445 ? dev->mem_start : options[cards_found]);
446 dev = 0;
447 cards_found++;
450 if (vortex_debug)
451 printk("%d 3c515 cards found.\n", cards_found);
452 return cards_found;
455 static struct device *vortex_found_device(struct device *dev, int ioaddr,
456 int irq, int product_index,
457 int options)
459 struct vortex_private *vp;
461 #ifdef MODULE
462 /* Allocate and fill new device structure. */
463 int dev_size = sizeof(struct device) +
464 sizeof(struct vortex_private) + 15; /* Pad for alignment */
466 dev = (struct device *) kmalloc(dev_size, GFP_KERNEL);
467 memset(dev, 0, dev_size);
468 /* Align the Rx and Tx ring entries. */
469 dev->priv = (void *)(((long)dev + sizeof(struct device) + 15) & ~15);
470 vp = (struct vortex_private *)dev->priv;
471 dev->name = vp->devname; /* An empty string. */
472 dev->base_addr = ioaddr;
473 dev->irq = irq;
474 dev->dma = (product_index == CORKSCREW_ID ? inw(ioaddr + 0x2000) & 7 : 0);
475 dev->init = vortex_probe1;
476 vp->product_name = "3c515";
477 vp->options = options;
478 if (options >= 0) {
479 vp->media_override = ((options & 7) == 2) ? 0 : options & 7;
480 vp->full_duplex = (options & 8) ? 1 : 0;
481 vp->bus_master = (options & 16) ? 1 : 0;
482 } else {
483 vp->media_override = 7;
484 vp->full_duplex = 0;
485 vp->bus_master = 0;
487 ether_setup(dev);
488 vp->next_module = root_vortex_dev;
489 root_vortex_dev = dev;
490 if (register_netdev(dev) != 0)
491 return 0;
492 #else /* not a MODULE */
493 if (dev) {
494 /* Caution: quad-word alignment required for rings! */
495 dev->priv = kmalloc(sizeof (struct vortex_private), GFP_KERNEL);
496 memset(dev->priv, 0, sizeof (struct vortex_private));
498 dev = init_etherdev(dev, sizeof(struct vortex_private));
499 dev->base_addr = ioaddr;
500 dev->irq = irq;
501 dev->dma = (product_index == CORKSCREW_ID ? inw(ioaddr + 0x2000) & 7 : 0);
502 vp = (struct vortex_private *)dev->priv;
503 vp->product_name = "3c515";
504 vp->options = options;
505 if (options >= 0) {
506 vp->media_override = ((options & 7) == 2) ? 0 : options & 7;
507 vp->full_duplex = (options & 8) ? 1 : 0;
508 vp->bus_master = (options & 16) ? 1 : 0;
509 } else {
510 vp->media_override = 7;
511 vp->full_duplex = 0;
512 vp->bus_master = 0;
515 vortex_probe1(dev);
516 #endif /* MODULE */
517 return dev;
520 static int vortex_probe1(struct device *dev)
522 int ioaddr = dev->base_addr;
523 struct vortex_private *vp = (struct vortex_private *)dev->priv;
524 unsigned int eeprom[0x40], checksum = 0; /* EEPROM contents */
525 int i;
527 printk("%s: 3Com %s at %#3x,", dev->name,
528 vp->product_name, ioaddr);
530 /* Read the station address from the EEPROM. */
531 EL3WINDOW(0);
532 for (i = 0; i < 0x18; i++) {
533 short *phys_addr = (short *)dev->dev_addr;
534 int timer;
535 outw(EEPROM_Read + i, ioaddr + Wn0EepromCmd);
536 /* Pause for at least 162 us. for the read to take place. */
537 for (timer = 4; timer >= 0; timer--) {
538 udelay(162);
539 if ((inw(ioaddr + Wn0EepromCmd) & 0x0200) == 0)
540 break;
542 eeprom[i] = inw(ioaddr + Wn0EepromData);
543 checksum ^= eeprom[i];
544 if (i < 3)
545 phys_addr[i] = htons(eeprom[i]);
547 checksum = (checksum ^ (checksum >> 8)) & 0xff;
548 if (checksum != 0x00)
549 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
550 for (i = 0; i < 6; i++)
551 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
552 if (eeprom[16] == 0x11c7) { /* Corkscrew */
553 if (request_dma(dev->dma, "3c515")) {
554 printk(", DMA %d allocation failed", dev->dma);
555 dev->dma = 0;
556 } else
557 printk(", DMA %d", dev->dma);
559 printk(", IRQ %d\n", dev->irq);
560 /* Tell them about an invalid IRQ. */
561 if (vortex_debug && (dev->irq <= 0 || dev->irq > 15))
562 printk(" *** Warning: this IRQ is unlikely to work! ***\n");
565 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
566 union wn3_config config;
567 EL3WINDOW(3);
568 vp->available_media = inw(ioaddr + Wn3_Options);
569 config.i = inl(ioaddr + Wn3_Config);
570 if (vortex_debug > 1)
571 printk(" Internal config register is %4.4x, transceivers %#x.\n",
572 config.i, inw(ioaddr + Wn3_Options));
573 printk(" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
574 8 << config.u.ram_size,
575 config.u.ram_width ? "word" : "byte",
576 ram_split[config.u.ram_split],
577 config.u.autoselect ? "autoselect/" : "",
578 media_tbl[config.u.xcvr].name);
579 dev->if_port = config.u.xcvr;
580 vp->default_media = config.u.xcvr;
581 vp->autoselect = config.u.autoselect;
583 if (vp->media_override != 7) {
584 printk(" Media override to transceiver type %d (%s).\n",
585 vp->media_override, media_tbl[vp->media_override].name);
586 dev->if_port = vp->media_override;
589 vp->capabilities = eeprom[16];
590 vp->full_bus_master_tx = (vp->capabilities & 0x20) ? 1 : 0;
591 /* Rx is broken at 10mbps, so we always disable it. */
592 /* vp->full_bus_master_rx = 0;*/
593 vp->full_bus_master_rx = (vp->capabilities & 0x20) ? 1 : 0;
595 /* We do a request_region() to register /proc/ioports info. */
596 request_region(ioaddr, CORKSCREW_TOTAL_SIZE, vp->product_name);
598 /* The 3c59x-specific entries in the device structure. */
599 dev->open = &vortex_open;
600 dev->hard_start_xmit = &vortex_start_xmit;
601 dev->stop = &vortex_close;
602 dev->get_stats = &vortex_get_stats;
603 dev->set_multicast_list = &set_rx_mode;
605 return 0;
609 static int
610 vortex_open(struct device *dev)
612 int ioaddr = dev->base_addr;
613 struct vortex_private *vp = (struct vortex_private *)dev->priv;
614 union wn3_config config;
615 int i;
617 /* Before initializing select the active media port. */
618 EL3WINDOW(3);
619 if (vp->full_duplex)
620 outb(0x20, ioaddr + Wn3_MAC_Ctrl); /* Set the full-duplex bit. */
621 config.i = inl(ioaddr + Wn3_Config);
623 if (vp->media_override != 7) {
624 if (vortex_debug > 1)
625 printk("%s: Media override to transceiver %d (%s).\n",
626 dev->name, vp->media_override,
627 media_tbl[vp->media_override].name);
628 dev->if_port = vp->media_override;
629 } else if (vp->autoselect) {
630 /* Find first available media type, starting with 100baseTx. */
631 dev->if_port = 4;
632 while (! (vp->available_media & media_tbl[dev->if_port].mask))
633 dev->if_port = media_tbl[dev->if_port].next;
635 if (vortex_debug > 1)
636 printk("%s: Initial media type %s.\n",
637 dev->name, media_tbl[dev->if_port].name);
639 init_timer(&vp->timer);
640 vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
641 vp->timer.data = (unsigned long)dev;
642 vp->timer.function = &vortex_timer; /* timer handler */
643 add_timer(&vp->timer);
644 } else
645 dev->if_port = vp->default_media;
647 config.u.xcvr = dev->if_port;
648 outl(config.i, ioaddr + Wn3_Config);
650 if (vortex_debug > 1) {
651 printk("%s: vortex_open() InternalConfig %8.8x.\n",
652 dev->name, config.i);
655 outw(TxReset, ioaddr + EL3_CMD);
656 for (i = 20; i >= 0 ; i--)
657 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
658 break;
660 outw(RxReset, ioaddr + EL3_CMD);
661 /* Wait a few ticks for the RxReset command to complete. */
662 for (i = 20; i >= 0 ; i--)
663 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
664 break;
666 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
668 /* Use the now-standard shared IRQ implementation. */
669 if (vp->capabilities == 0x11c7) {
670 /* Corkscrew: Cannot share ISA resources. */
671 if (dev->irq == 0
672 || dev->dma == 0
673 || request_irq(dev->irq, &vortex_interrupt, 0,
674 vp->product_name, dev))
675 return -EAGAIN;
676 enable_dma(dev->dma);
677 set_dma_mode(dev->dma, DMA_MODE_CASCADE);
678 } else if (request_irq(dev->irq, &vortex_interrupt, SA_SHIRQ,
679 vp->product_name, dev)) {
680 return -EAGAIN;
683 if (vortex_debug > 1) {
684 EL3WINDOW(4);
685 printk("%s: vortex_open() irq %d media status %4.4x.\n",
686 dev->name, dev->irq, inw(ioaddr + Wn4_Media));
689 /* Set the station address and mask in window 2 each time opened. */
690 EL3WINDOW(2);
691 for (i = 0; i < 6; i++)
692 outb(dev->dev_addr[i], ioaddr + i);
693 for (; i < 12; i+=2)
694 outw(0, ioaddr + i);
696 if (dev->if_port == 3)
697 /* Start the thinnet transceiver. We should really wait 50ms...*/
698 outw(StartCoax, ioaddr + EL3_CMD);
699 EL3WINDOW(4);
700 outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
701 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
703 /* Switch to the stats window, and clear all stats by reading. */
704 outw(StatsDisable, ioaddr + EL3_CMD);
705 EL3WINDOW(6);
706 for (i = 0; i < 10; i++)
707 inb(ioaddr + i);
708 inw(ioaddr + 10);
709 inw(ioaddr + 12);
710 /* New: On the Vortex we must also clear the BadSSD counter. */
711 EL3WINDOW(4);
712 inb(ioaddr + 12);
713 /* ..and on the Boomerang we enable the extra statistics bits. */
714 outw(0x0040, ioaddr + Wn4_NetDiag);
716 /* Switch to register set 7 for normal use. */
717 EL3WINDOW(7);
719 if (vp->full_bus_master_rx) { /* Boomerang bus master. */
720 vp->cur_rx = vp->dirty_rx = 0;
721 if (vortex_debug > 2)
722 printk("%s: Filling in the Rx ring.\n", dev->name);
723 for (i = 0; i < RX_RING_SIZE; i++) {
724 struct sk_buff *skb;
725 if (i < (RX_RING_SIZE - 1))
726 vp->rx_ring[i].next = virt_to_bus(&vp->rx_ring[i+1]);
727 else
728 vp->rx_ring[i].next = 0;
729 vp->rx_ring[i].status = 0; /* Clear complete bit. */
730 vp->rx_ring[i].length = PKT_BUF_SZ | 0x80000000;
731 skb = dev_alloc_skb(PKT_BUF_SZ);
732 vp->rx_skbuff[i] = skb;
733 if (skb == NULL)
734 break; /* Bad news! */
735 skb->dev = dev; /* Mark as being used by this device. */
736 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
737 vp->rx_ring[i].addr = virt_to_bus(skb->tail);
739 vp->rx_ring[i-1].next = virt_to_bus(&vp->rx_ring[0]); /* Wrap the ring. */
740 outl(virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr);
742 if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
743 vp->cur_tx = vp->dirty_tx = 0;
744 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
745 /* Clear the Tx ring. */
746 for (i = 0; i < TX_RING_SIZE; i++)
747 vp->tx_skbuff[i] = 0;
748 outl(0, ioaddr + DownListPtr);
750 /* Set receiver mode: presumably accept b-case and phys addr only. */
751 set_rx_mode(dev);
752 outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
754 dev->tbusy = 0;
755 dev->interrupt = 0;
756 dev->start = 1;
758 outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
759 outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
760 /* Allow status bits to be seen. */
761 outw(SetStatusEnb | AdapterFailure|IntReq|StatsFull |
762 (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
763 (vp->full_bus_master_rx ? UpComplete : RxComplete) |
764 (vp->bus_master ? DMADone : 0),
765 ioaddr + EL3_CMD);
766 /* Ack all pending events, and set active indicator mask. */
767 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
768 ioaddr + EL3_CMD);
769 outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
770 | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete,
771 ioaddr + EL3_CMD);
773 MOD_INC_USE_COUNT;
775 return 0;
778 static void vortex_timer(unsigned long data)
780 #ifdef AUTOMEDIA
781 struct device *dev = (struct device *)data;
782 struct vortex_private *vp = (struct vortex_private *)dev->priv;
783 int ioaddr = dev->base_addr;
784 unsigned long flags;
785 int ok = 0;
787 if (vortex_debug > 1)
788 printk("%s: Media selection timer tick happened, %s.\n",
789 dev->name, media_tbl[dev->if_port].name);
791 save_flags(flags); cli(); {
792 int old_window = inw(ioaddr + EL3_CMD) >> 13;
793 int media_status;
794 EL3WINDOW(4);
795 media_status = inw(ioaddr + Wn4_Media);
796 switch (dev->if_port) {
797 case 0: case 4: case 5: /* 10baseT, 100baseTX, 100baseFX */
798 if (media_status & Media_LnkBeat) {
799 ok = 1;
800 if (vortex_debug > 1)
801 printk("%s: Media %s has link beat, %x.\n",
802 dev->name, media_tbl[dev->if_port].name, media_status);
803 } else if (vortex_debug > 1)
804 printk("%s: Media %s is has no link beat, %x.\n",
805 dev->name, media_tbl[dev->if_port].name, media_status);
807 break;
808 default: /* Other media types handled by Tx timeouts. */
809 if (vortex_debug > 1)
810 printk("%s: Media %s is has no indication, %x.\n",
811 dev->name, media_tbl[dev->if_port].name, media_status);
812 ok = 1;
814 if ( ! ok) {
815 union wn3_config config;
817 do {
818 dev->if_port = media_tbl[dev->if_port].next;
819 } while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
820 if (dev->if_port == 8) { /* Go back to default. */
821 dev->if_port = vp->default_media;
822 if (vortex_debug > 1)
823 printk("%s: Media selection failing, using default %s port.\n",
824 dev->name, media_tbl[dev->if_port].name);
825 } else {
826 if (vortex_debug > 1)
827 printk("%s: Media selection failed, now trying %s port.\n",
828 dev->name, media_tbl[dev->if_port].name);
829 vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
830 add_timer(&vp->timer);
832 outw((media_status & ~(Media_10TP|Media_SQE)) |
833 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
835 EL3WINDOW(3);
836 config.i = inl(ioaddr + Wn3_Config);
837 config.u.xcvr = dev->if_port;
838 outl(config.i, ioaddr + Wn3_Config);
840 outw(dev->if_port == 3 ? StartCoax : StopCoax, ioaddr + EL3_CMD);
842 EL3WINDOW(old_window);
843 } restore_flags(flags);
844 if (vortex_debug > 1)
845 printk("%s: Media selection timer finished, %s.\n",
846 dev->name, media_tbl[dev->if_port].name);
848 #endif /* AUTOMEDIA*/
849 return;
852 static int
853 vortex_start_xmit(struct sk_buff *skb, struct device *dev)
855 struct vortex_private *vp = (struct vortex_private *)dev->priv;
856 int ioaddr = dev->base_addr;
858 if (dev->tbusy) {
859 int tickssofar = jiffies - dev->trans_start;
860 int i;
862 /* Min. wait before assuming a Tx failed == 400ms. */
864 if (tickssofar < 400*HZ/1000) /* We probably aren't empty. */
865 return 1;
866 printk("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
867 dev->name, inb(ioaddr + TxStatus),
868 inw(ioaddr + EL3_STATUS));
869 /* Slight code bloat to be user friendly. */
870 if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
871 printk("%s: Transmitter encountered 16 collisions -- network"
872 " network cable problem?\n", dev->name);
873 #ifndef final_version
874 printk(" Flags; bus-master %d, full %d; dirty %d current %d.\n",
875 vp->full_bus_master_tx, vp->tx_full, vp->dirty_tx, vp->cur_tx);
876 printk(" Down list %8.8x vs. %p.\n", inl(ioaddr + DownListPtr),
877 &vp->tx_ring[0]);
878 for (i = 0; i < TX_RING_SIZE; i++) {
879 printk(" %d: %p length %8.8x status %8.8x\n", i,
880 &vp->tx_ring[i],
881 vp->tx_ring[i].length,
882 vp->tx_ring[i].status);
884 #endif
885 /* Issue TX_RESET and TX_START commands. */
886 outw(TxReset, ioaddr + EL3_CMD);
887 for (i = 20; i >= 0 ; i--)
888 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
889 break;
890 outw(TxEnable, ioaddr + EL3_CMD);
891 dev->trans_start = jiffies;
892 /* dev->tbusy = 0;*/
893 vp->stats.tx_errors++;
894 vp->stats.tx_dropped++;
895 return 0; /* Yes, silently *drop* the packet! */
898 /* Block a timer-based transmit from overlapping. This could better be
899 done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
900 If this ever occurs the queue layer is doing something evil! */
901 if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
902 printk("%s: Transmitter access conflict.\n", dev->name);
903 return 1;
906 if (vp->full_bus_master_tx) { /* BOOMERANG bus-master */
907 /* Calculate the next Tx descriptor entry. */
908 int entry = vp->cur_tx % TX_RING_SIZE;
909 struct boom_tx_desc *prev_entry;
910 unsigned long flags, i;
912 if (vp->tx_full) /* No room to transmit with */
913 return 1;
914 if (vp->cur_tx != 0)
915 prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
916 else
917 prev_entry = NULL;
918 if (vortex_debug > 3)
919 printk("%s: Trying to send a packet, Tx index %d.\n",
920 dev->name, vp->cur_tx);
921 /* vp->tx_full = 1; */
922 vp->tx_skbuff[entry] = skb;
923 vp->tx_ring[entry].next = 0;
924 vp->tx_ring[entry].addr = virt_to_bus(skb->data);
925 vp->tx_ring[entry].length = skb->len | 0x80000000;
926 vp->tx_ring[entry].status = skb->len | 0x80000000;
928 save_flags(flags);
929 cli();
930 outw(DownStall, ioaddr + EL3_CMD);
931 /* Wait for the stall to complete. */
932 for (i = 20; i >= 0 ; i--)
933 if ( (inw(ioaddr + EL3_STATUS) & CmdInProgress) == 0)
934 break;
935 if (prev_entry)
936 prev_entry->next = virt_to_bus(&vp->tx_ring[entry]);
937 if (inl(ioaddr + DownListPtr) == 0) {
938 outl(virt_to_bus(&vp->tx_ring[entry]), ioaddr + DownListPtr);
939 queued_packet++;
941 outw(DownUnstall, ioaddr + EL3_CMD);
942 restore_flags(flags);
944 vp->cur_tx++;
945 if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1)
946 vp->tx_full = 1;
947 else { /* Clear previous interrupt enable. */
948 if (prev_entry)
949 prev_entry->status &= ~0x80000000;
950 dev->tbusy = 0;
952 dev->trans_start = jiffies;
953 return 0;
955 /* Put out the doubleword header... */
956 outl(skb->len, ioaddr + TX_FIFO);
957 #ifdef VORTEX_BUS_MASTER
958 if (vp->bus_master) {
959 /* Set the bus-master controller to transfer the packet. */
960 outl((int)(skb->data), ioaddr + Wn7_MasterAddr);
961 outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
962 vp->tx_skb = skb;
963 outw(StartDMADown, ioaddr + EL3_CMD);
964 /* dev->tbusy will be cleared at the DMADone interrupt. */
965 } else {
966 /* ... and the packet rounded to a doubleword. */
967 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
968 dev_kfree_skb (skb);
969 if (inw(ioaddr + TxFree) > 1536) {
970 dev->tbusy = 0;
971 } else
972 /* Interrupt us when the FIFO has room for max-sized packet. */
973 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
975 #else
976 /* ... and the packet rounded to a doubleword. */
977 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
978 dev_kfree_skb (skb);
979 if (inw(ioaddr + TxFree) > 1536) {
980 dev->tbusy = 0;
981 } else
982 /* Interrupt us when the FIFO has room for max-sized packet. */
983 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
984 #endif /* bus master */
986 dev->trans_start = jiffies;
988 /* Clear the Tx status stack. */
990 short tx_status;
991 int i = 4;
993 while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
994 if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */
995 if (vortex_debug > 2)
996 printk("%s: Tx error, status %2.2x.\n",
997 dev->name, tx_status);
998 if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
999 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
1000 if (tx_status & 0x30) {
1001 int j;
1002 outw(TxReset, ioaddr + EL3_CMD);
1003 for (j = 20; j >= 0 ; j--)
1004 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
1005 break;
1007 outw(TxEnable, ioaddr + EL3_CMD);
1009 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
1012 return 0;
1015 /* The interrupt handler does all of the Rx thread work and cleans up
1016 after the Tx thread. */
1017 static void vortex_interrupt IRQ(int irq, void *dev_id, struct pt_regs *regs)
1019 /* Use the now-standard shared IRQ implementation. */
1020 struct device *dev = dev_id;
1021 struct vortex_private *lp;
1022 int ioaddr, status;
1023 int latency;
1024 int i = max_interrupt_work;
1026 if (test_and_set_bit(0, (void*)&dev->interrupt)) {
1027 printk("%s: Re-entering the interrupt handler.\n", dev->name);
1028 return;
1031 ioaddr = dev->base_addr;
1032 latency = inb(ioaddr + Timer);
1033 lp = (struct vortex_private *)dev->priv;
1035 status = inw(ioaddr + EL3_STATUS);
1037 if (vortex_debug > 4)
1038 printk("%s: interrupt, status %4.4x, timer %d.\n", dev->name,
1039 status, latency);
1040 if ((status & 0xE000) != 0xE000) {
1041 static int donedidthis=0;
1042 /* Some interrupt controllers store a bogus interrupt from boot-time.
1043 Ignore a single early interrupt, but don't hang the machine for
1044 other interrupt problems. */
1045 if (donedidthis++ > 100) {
1046 printk("%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
1047 dev->name, status, dev->start);
1048 FREE_IRQ(dev->irq, dev);
1052 do {
1053 if (vortex_debug > 5)
1054 printk("%s: In interrupt loop, status %4.4x.\n",
1055 dev->name, status);
1056 if (status & RxComplete)
1057 vortex_rx(dev);
1059 if (status & TxAvailable) {
1060 if (vortex_debug > 5)
1061 printk(" TX room bit was handled.\n");
1062 /* There's room in the FIFO for a full-sized packet. */
1063 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
1064 dev->tbusy = 0;
1065 mark_bh(NET_BH);
1067 if (status & DownComplete) {
1068 unsigned int dirty_tx = lp->dirty_tx;
1070 while (lp->cur_tx - dirty_tx > 0) {
1071 int entry = dirty_tx % TX_RING_SIZE;
1072 if (inl(ioaddr + DownListPtr) ==
1073 virt_to_bus(&lp->tx_ring[entry]))
1074 break; /* It still hasn't been processed. */
1075 if (lp->tx_skbuff[entry]) {
1076 dev_kfree_skb(lp->tx_skbuff[entry]);
1077 lp->tx_skbuff[entry] = 0;
1079 dirty_tx++;
1081 lp->dirty_tx = dirty_tx;
1082 outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
1083 if (lp->tx_full && (lp->cur_tx - dirty_tx <= TX_RING_SIZE - 1)) {
1084 lp->tx_full= 0;
1085 dev->tbusy = 0;
1086 mark_bh(NET_BH);
1089 #ifdef VORTEX_BUS_MASTER
1090 if (status & DMADone) {
1091 outw(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
1092 dev->tbusy = 0;
1093 dev_kfree_skb (lp->tx_skb); /* Release the transfered buffer */
1094 mark_bh(NET_BH);
1096 #endif
1097 if (status & UpComplete) {
1098 boomerang_rx(dev);
1099 outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
1101 if (status & (AdapterFailure | RxEarly | StatsFull)) {
1102 /* Handle all uncommon interrupts at once. */
1103 if (status & RxEarly) { /* Rx early is unused. */
1104 vortex_rx(dev);
1105 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
1107 if (status & StatsFull) { /* Empty statistics. */
1108 static int DoneDidThat = 0;
1109 if (vortex_debug > 4)
1110 printk("%s: Updating stats.\n", dev->name);
1111 update_stats(ioaddr, dev);
1112 /* DEBUG HACK: Disable statistics as an interrupt source. */
1113 /* This occurs when we have the wrong media type! */
1114 if (DoneDidThat == 0 &&
1115 inw(ioaddr + EL3_STATUS) & StatsFull) {
1116 int win, reg;
1117 printk("%s: Updating stats failed, disabling stats as an"
1118 " interrupt source.\n", dev->name);
1119 for (win = 0; win < 8; win++) {
1120 EL3WINDOW(win);
1121 printk("\n Vortex window %d:", win);
1122 for (reg = 0; reg < 16; reg++)
1123 printk(" %2.2x", inb(ioaddr+reg));
1125 EL3WINDOW(7);
1126 outw(SetIntrEnb | TxAvailable | RxComplete | AdapterFailure
1127 | UpComplete | DownComplete | TxComplete,
1128 ioaddr + EL3_CMD);
1129 DoneDidThat++;
1132 if (status & AdapterFailure) {
1133 /* Adapter failure requires Rx reset and reinit. */
1134 outw(RxReset, ioaddr + EL3_CMD);
1135 /* Set the Rx filter to the current state. */
1136 set_rx_mode(dev);
1137 outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
1138 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
1142 if (--i < 0) {
1143 printk("%s: Too much work in interrupt, status %4.4x. "
1144 "Disabling functions (%4.4x).\n",
1145 dev->name, status, SetStatusEnb | ((~status) & 0x7FE));
1146 /* Disable all pending interrupts. */
1147 outw(SetStatusEnb | ((~status) & 0x7FE), ioaddr + EL3_CMD);
1148 outw(AckIntr | 0x7FF, ioaddr + EL3_CMD);
1149 break;
1151 /* Acknowledge the IRQ. */
1152 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
1154 } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
1156 if (vortex_debug > 4)
1157 printk("%s: exiting interrupt, status %4.4x.\n", dev->name, status);
1159 dev->interrupt = 0;
1160 return;
1163 static int
1164 vortex_rx(struct device *dev)
1166 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1167 int ioaddr = dev->base_addr;
1168 int i;
1169 short rx_status;
1171 if (vortex_debug > 5)
1172 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
1173 inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1174 while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
1175 if (rx_status & 0x4000) { /* Error, update stats. */
1176 unsigned char rx_error = inb(ioaddr + RxErrors);
1177 if (vortex_debug > 2)
1178 printk(" Rx error: status %2.2x.\n", rx_error);
1179 vp->stats.rx_errors++;
1180 if (rx_error & 0x01) vp->stats.rx_over_errors++;
1181 if (rx_error & 0x02) vp->stats.rx_length_errors++;
1182 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
1183 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
1184 if (rx_error & 0x10) vp->stats.rx_length_errors++;
1185 } else {
1186 /* The packet length: up to 4.5K!. */
1187 short pkt_len = rx_status & 0x1fff;
1188 struct sk_buff *skb;
1190 skb = DEV_ALLOC_SKB(pkt_len + 5);
1191 if (vortex_debug > 4)
1192 printk("Receiving packet size %d status %4.4x.\n",
1193 pkt_len, rx_status);
1194 if (skb != NULL) {
1195 skb->dev = dev;
1196 #if LINUX_VERSION_CODE >= 0x10300
1197 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1198 /* 'skb_put()' points to the start of sk_buff data area. */
1199 insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
1200 (pkt_len + 3) >> 2);
1201 outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
1202 skb->protocol = eth_type_trans(skb, dev);
1203 #else
1204 skb->len = pkt_len;
1205 /* 'skb->data' points to the start of sk_buff data area. */
1206 insl(ioaddr + RX_FIFO, skb->data, (pkt_len + 3) >> 2);
1207 outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
1208 #endif /* KERNEL_1_3_0 */
1209 netif_rx(skb);
1210 dev->last_rx = jiffies;
1211 vp->stats.rx_packets++;
1212 /* Wait a limited time to go to next packet. */
1213 for (i = 200; i >= 0; i--)
1214 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
1215 break;
1216 continue;
1217 } else if (vortex_debug)
1218 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
1219 dev->name, pkt_len);
1221 outw(RxDiscard, ioaddr + EL3_CMD);
1222 vp->stats.rx_dropped++;
1223 /* Wait a limited time to skip this packet. */
1224 for (i = 200; i >= 0; i--)
1225 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
1226 break;
1229 return 0;
1232 static int
1233 boomerang_rx(struct device *dev)
1235 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1236 int entry = vp->cur_rx % RX_RING_SIZE;
1237 int ioaddr = dev->base_addr;
1238 int rx_status;
1240 if (vortex_debug > 5)
1241 printk(" In boomerang_rx(), status %4.4x, rx_status %4.4x.\n",
1242 inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
1243 while ((rx_status = vp->rx_ring[entry].status) & RxDComplete) {
1244 if (rx_status & RxDError) { /* Error, update stats. */
1245 unsigned char rx_error = rx_status >> 16;
1246 if (vortex_debug > 2)
1247 printk(" Rx error: status %2.2x.\n", rx_error);
1248 vp->stats.rx_errors++;
1249 if (rx_error & 0x01) vp->stats.rx_over_errors++;
1250 if (rx_error & 0x02) vp->stats.rx_length_errors++;
1251 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
1252 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
1253 if (rx_error & 0x10) vp->stats.rx_length_errors++;
1254 } else {
1255 /* The packet length: up to 4.5K!. */
1256 short pkt_len = rx_status & 0x1fff;
1257 struct sk_buff *skb;
1259 if (vortex_debug > 4)
1260 printk("Receiving packet size %d status %4.4x.\n",
1261 pkt_len, rx_status);
1263 /* Check if the packet is long enough to just accept without
1264 copying to a properly sized skbuff. */
1265 if (pkt_len < rx_copybreak
1266 && (skb = DEV_ALLOC_SKB(pkt_len + 2)) != 0) {
1267 skb->dev = dev;
1268 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1269 /* 'skb_put()' points to the start of sk_buff data area. */
1270 memcpy(skb_put(skb, pkt_len),
1271 bus_to_virt(vp->rx_ring[entry].addr),
1272 pkt_len);
1273 rx_copy++;
1274 } else{
1275 void *temp;
1276 /* Pass up the skbuff already on the Rx ring. */
1277 skb = vp->rx_skbuff[entry];
1278 vp->rx_skbuff[entry] = NULL;
1279 temp = skb_put(skb, pkt_len);
1280 /* Remove this checking code for final release. */
1281 if (bus_to_virt(vp->rx_ring[entry].addr) != temp)
1282 printk("%s: Warning -- the skbuff addresses do not match"
1283 " in boomerang_rx: %p vs. %p / %p.\n", dev->name,
1284 bus_to_virt(vp->rx_ring[entry].addr),
1285 skb->head, temp);
1286 rx_nocopy++;
1288 #if LINUX_VERSION_CODE > 0x10300
1289 skb->protocol = eth_type_trans(skb, dev);
1290 #else
1291 skb->len = pkt_len;
1292 #endif
1293 netif_rx(skb);
1294 dev->last_rx = jiffies;
1295 vp->stats.rx_packets++;
1297 entry = (++vp->cur_rx) % RX_RING_SIZE;
1299 /* Refill the Rx ring buffers. */
1300 for (; vp->dirty_rx < vp->cur_rx; vp->dirty_rx++) {
1301 struct sk_buff *skb;
1302 entry = vp->dirty_rx % RX_RING_SIZE;
1303 if (vp->rx_skbuff[entry] == NULL) {
1304 skb = dev_alloc_skb(PKT_BUF_SZ);
1305 if (skb == NULL)
1306 break; /* Bad news! */
1307 skb->dev = dev; /* Mark as being used by this device. */
1308 #if LINUX_VERSION_CODE > 0x10300
1309 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
1310 vp->rx_ring[entry].addr = virt_to_bus(skb->tail);
1311 #else
1312 vp->rx_ring[entry].addr = virt_to_bus(skb->data);
1313 #endif
1314 vp->rx_skbuff[entry] = skb;
1316 vp->rx_ring[entry].status = 0; /* Clear complete bit. */
1318 return 0;
1321 static int
1322 vortex_close(struct device *dev)
1324 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1325 int ioaddr = dev->base_addr;
1326 int i;
1328 dev->start = 0;
1329 dev->tbusy = 1;
1331 if (vortex_debug > 1) {
1332 printk("%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
1333 dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
1334 printk("%s: vortex close stats: rx_nocopy %d rx_copy %d"
1335 " tx_queued %d.\n",
1336 dev->name, rx_nocopy, rx_copy, queued_packet);
1339 del_timer(&vp->timer);
1341 /* Turn off statistics ASAP. We update lp->stats below. */
1342 outw(StatsDisable, ioaddr + EL3_CMD);
1344 /* Disable the receiver and transmitter. */
1345 outw(RxDisable, ioaddr + EL3_CMD);
1346 outw(TxDisable, ioaddr + EL3_CMD);
1348 if (dev->if_port == XCVR_10base2)
1349 /* Turn off thinnet power. Green! */
1350 outw(StopCoax, ioaddr + EL3_CMD);
1352 #ifdef SA_SHIRQ
1353 free_irq(dev->irq, dev);
1354 #else
1355 free_irq(dev->irq);
1356 irq2dev_map[dev->irq] = 0;
1357 #endif
1359 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
1361 update_stats(ioaddr, dev);
1362 if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
1363 outl(0, ioaddr + UpListPtr);
1364 for (i = 0; i < RX_RING_SIZE; i++)
1365 if (vp->rx_skbuff[i]) {
1366 #if LINUX_VERSION_CODE < 0x20100
1367 vp->rx_skbuff[i]->free = 1;
1368 #endif
1369 dev_kfree_skb (vp->rx_skbuff[i]);
1370 vp->rx_skbuff[i] = 0;
1373 if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
1374 outl(0, ioaddr + DownListPtr);
1375 for (i = 0; i < TX_RING_SIZE; i++)
1376 if (vp->tx_skbuff[i]) {
1377 dev_kfree_skb(vp->tx_skbuff[i]);
1378 vp->tx_skbuff[i] = 0;
1382 MOD_DEC_USE_COUNT;
1384 return 0;
1387 static struct enet_statistics *
1388 vortex_get_stats(struct device *dev)
1390 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1391 unsigned long flags;
1393 if (dev->start) {
1394 save_flags(flags);
1395 cli();
1396 update_stats(dev->base_addr, dev);
1397 restore_flags(flags);
1399 return &vp->stats;
1402 /* Update statistics.
1403 Unlike with the EL3 we need not worry about interrupts changing
1404 the window setting from underneath us, but we must still guard
1405 against a race condition with a StatsUpdate interrupt updating the
1406 table. This is done by checking that the ASM (!) code generated uses
1407 atomic updates with '+='.
1409 static void update_stats(int ioaddr, struct device *dev)
1411 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1413 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
1414 /* Switch to the stats window, and read everything. */
1415 EL3WINDOW(6);
1416 vp->stats.tx_carrier_errors += inb(ioaddr + 0);
1417 vp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1418 /* Multiple collisions. */ inb(ioaddr + 2);
1419 vp->stats.collisions += inb(ioaddr + 3);
1420 vp->stats.tx_window_errors += inb(ioaddr + 4);
1421 vp->stats.rx_fifo_errors += inb(ioaddr + 5);
1422 vp->stats.tx_packets += inb(ioaddr + 6);
1423 vp->stats.tx_packets += (inb(ioaddr + 9)&0x30) << 4;
1424 /* Rx packets */ inb(ioaddr + 7); /* Must read to clear */
1425 /* Tx deferrals */ inb(ioaddr + 8);
1426 /* Don't bother with register 9, an extension of registers 6&7.
1427 If we do use the 6&7 values the atomic update assumption above
1428 is invalid. */
1429 inw(ioaddr + 10); /* Total Rx and Tx octets. */
1430 inw(ioaddr + 12);
1431 /* New: On the Vortex we must also clear the BadSSD counter. */
1432 EL3WINDOW(4);
1433 inb(ioaddr + 12);
1435 /* We change back to window 7 (not 1) with the Vortex. */
1436 EL3WINDOW(7);
1437 return;
1440 /* This new version of set_rx_mode() supports v1.4 kernels.
1441 The Vortex chip has no documented multicast filter, so the only
1442 multicast setting is to receive all multicast frames. At least
1443 the chip has a very clean way to set the mode, unlike many others. */
1444 static void
1445 set_rx_mode(struct device *dev)
1447 int ioaddr = dev->base_addr;
1448 short new_mode;
1450 if (dev->flags & IFF_PROMISC) {
1451 if (vortex_debug > 3)
1452 printk("%s: Setting promiscuous mode.\n", dev->name);
1453 new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
1454 } else if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
1455 new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
1456 } else
1457 new_mode = SetRxFilter | RxStation | RxBroadcast;
1459 outw(new_mode, ioaddr + EL3_CMD);
1462 #ifdef MODULE
1463 void
1464 cleanup_module(void)
1466 struct device *next_dev;
1468 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1469 while (root_vortex_dev) {
1470 next_dev = ((struct vortex_private *)root_vortex_dev->priv)->next_module;
1471 if (root_vortex_dev->dma)
1472 free_dma(root_vortex_dev->dma);
1473 unregister_netdev(root_vortex_dev);
1474 outw(TotalReset, root_vortex_dev->base_addr + EL3_CMD);
1475 release_region(root_vortex_dev->base_addr, CORKSCREW_TOTAL_SIZE);
1476 kfree(root_vortex_dev);
1477 root_vortex_dev = next_dev;
1480 #endif /* MODULE */
1483 * Local variables:
1484 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c515.c"
1485 * c-indent-level: 4
1486 * tab-width: 4
1487 * End: