This source file includes following definitions.
- init_module
- tc59x_probe
- vortex_scan
- vortex_found_device
- vortex_probe1
- vortex_open
- vortex_timer
- vortex_start_xmit
- vortex_interrupt
- vortex_rx
- vortex_close
- vortex_get_stats
- update_stats
- set_multicast_list
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 static char *version = "3c59x.c:v0.13 2/13/96 becker@cesdis.gsfc.nasa.gov\n";
18
19
20
21
22
23 #define VORTEX_BUS_MASTER
24
25
26 #define VORTEX_DEBUG 1
27
28 #include <linux/module.h>
29
30 #include <linux/kernel.h>
31 #include <linux/sched.h>
32 #include <linux/string.h>
33 #include <linux/ptrace.h>
34 #include <linux/errno.h>
35 #include <linux/in.h>
36 #include <linux/ioport.h>
37 #include <linux/malloc.h>
38 #include <linux/interrupt.h>
39 #include <linux/pci.h>
40 #include <linux/bios32.h>
41 #include <linux/timer.h>
42 #include <asm/bitops.h>
43 #include <asm/io.h>
44
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48
49 #ifdef HAVE_SHARED_IRQ
50 #define USE_SHARED_IRQ
51 #include <linux/shared_irq.h>
52 #endif
53
54
55
56 #define VORTEX_TOTAL_SIZE 0x20
57
58 #ifdef HAVE_DEVLIST
59 struct netdev_entry tc59x_drv =
60 {"Vortex", vortex_pci_probe, VORTEX_TOTAL_SIZE, NULL};
61 #endif
62
63 #ifdef VORTEX_DEBUG
64 int vortex_debug = VORTEX_DEBUG;
65 #else
66 int vortex_debug = 1;
67 #endif
68
69 static int product_ids[] = {0x5900, 0x5950, 0x5951, 0x5952, 0, 0};
70 static const char *product_names[] = {
71 "3c590 Vortex 10Mbps",
72 "3c595 Vortex 100baseTX",
73 "3c595 Vortex 100baseT4",
74 "3c595 Vortex 100base-MII",
75 "EISA Vortex 3c597",
76 };
77 #define DEMON_INDEX 5
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 #define TCOM_VENDOR_ID 0x10B7
129
130
131
132
133
134
135
136
137 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
138 #define EL3_CMD 0x0e
139 #define EL3_STATUS 0x0e
140
141
142
143
144
145
146
147 enum vortex_cmd {
148 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
149 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11, RxDiscard = 8<<11,
150 TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
151 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
152 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
153 SetTxThreshold = 18<<11, SetTxStart = 19<<11,
154 StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
155 StatsDisable = 22<<11, StopCoax = 23<<11,};
156
157
158 enum RxFilter {
159 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
160
161
162 enum vortex_status {
163 IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
164 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
165 IntReq = 0x0040, StatsFull = 0x0080, DMADone = 1<<8,
166 DMAInProgress = 1<<11,
167 CmdInProgress = 1<<12,
168 };
169
170
171
172 enum Window1 {
173 TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
174 RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
175 TxFree = 0x1C,
176 };
177 enum Window0 {
178 Wn0EepromCmd = 10,
179 };
180 enum Win0_EEPROM_bits {
181 EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
182 EEPROM_EWENB = 0x30,
183 EEPROM_EWDIS = 0x00,
184 };
185
186 enum eeprom_offset {
187 PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
188 EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
189 NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
190 DriverTune=13, Checksum=15};
191
192 enum Window3 {
193 Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
194 };
195 union wn3_config {
196 int i;
197 struct w3_config_fields {
198 unsigned int ram_size:3, ram_width:1, ram_speed:2, rom_size:2;
199 int pad8:8;
200 unsigned int ram_split:2, pad18:2, xcvr:3, pad21:1, autoselect:1;
201 int pad24:8;
202 } u;
203 };
204
205 enum Window4 {
206 Wn4_Media = 0x0A,
207 };
208 enum Win4_Media_bits {
209 Media_TP = 0x00C0,
210 };
211 enum Window7 {
212 Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
213 };
214
215 struct vortex_private {
216 char devname[8];
217 const char *product_name;
218 struct device *next_module;
219 struct enet_statistics stats;
220 #ifdef VORTEX_BUS_MASTER
221 struct sk_buff *tx_skb;
222 #endif
223 struct timer_list timer;
224 int options;
225 unsigned int media_override:3, full_duplex:1, bus_master:1, autoselect:1;
226 };
227
228 static char *if_names[] = {
229 "10baseT", "10Mbs AUI", "undefined", "10base2",
230 "100baseTX", "100baseFX", "MII", "undefined"};
231
232 static int vortex_scan(struct device *dev);
233 static int vortex_found_device(struct device *dev, int ioaddr, int irq,
234 int product_index, int options);
235 static int vortex_probe1(struct device *dev);
236 static int vortex_open(struct device *dev);
237 static void vortex_timer(unsigned long arg);
238 static int vortex_start_xmit(struct sk_buff *skb, struct device *dev);
239 static int vortex_rx(struct device *dev);
240 static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs);
241 static int vortex_close(struct device *dev);
242 static void update_stats(int addr, struct device *dev);
243 static struct enet_statistics *vortex_get_stats(struct device *dev);
244 static void set_multicast_list(struct device *dev);
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263 int options[8] = { -1, -1, -1, -1, -1, -1, -1, -1,};
264
265 #ifdef MODULE
266 static int debug = -1;
267
268 static struct device *root_vortex_dev = NULL;
269
270 int
271 init_module(void)
272 {
273 int cards_found;
274
275 if (debug >= 0)
276 vortex_debug = debug;
277 if (vortex_debug)
278 printk(version);
279
280 root_vortex_dev = NULL;
281 cards_found = vortex_scan(0);
282 return cards_found < 0 ? cards_found : 0;
283 }
284
285 #else
286 unsigned long tc59x_probe(struct device *dev)
287 {
288 int cards_found = 0;
289
290 cards_found = vortex_scan(dev);
291
292 if (vortex_debug > 0 && cards_found)
293 printk(version);
294
295 return cards_found ? 0 : -ENODEV;
296 }
297 #endif
298
299 static int vortex_scan(struct device *dev)
300 {
301 int cards_found = 0;
302
303 if (pcibios_present()) {
304 static int pci_index = 0;
305 for (; pci_index < 8; pci_index++) {
306 unsigned char pci_bus, pci_device_fn, pci_irq_line, pci_latency;
307 unsigned int pci_ioaddr;
308 unsigned short pci_command;
309 int index;
310
311 for (index = 0; product_ids[index]; index++) {
312 if ( ! pcibios_find_device(TCOM_VENDOR_ID, product_ids[index],
313 pci_index, &pci_bus,
314 &pci_device_fn))
315 break;
316 }
317 if ( ! product_ids[index])
318 break;
319
320 pcibios_read_config_byte(pci_bus, pci_device_fn,
321 PCI_INTERRUPT_LINE, &pci_irq_line);
322 pcibios_read_config_dword(pci_bus, pci_device_fn,
323 PCI_BASE_ADDRESS_0, &pci_ioaddr);
324
325 pci_ioaddr &= ~3;
326
327 #ifdef VORTEX_BUS_MASTER
328
329
330
331
332
333 pcibios_read_config_word(pci_bus, pci_device_fn,
334 PCI_COMMAND, &pci_command);
335 if ( ! (pci_command & PCI_COMMAND_MASTER)) {
336 printk(" PCI Master Bit has not been set! Setting...\n");
337 pci_command |= PCI_COMMAND_MASTER;
338 pcibios_write_config_word(pci_bus, pci_device_fn,
339 PCI_COMMAND, pci_command);
340 }
341 pcibios_read_config_byte(pci_bus, pci_device_fn,
342 PCI_LATENCY_TIMER, &pci_latency);
343 if (pci_latency != 255) {
344 printk(" Overriding PCI latency timer (CFLT) setting of %d, new value is 255.\n", pci_latency);
345 pcibios_write_config_byte(pci_bus, pci_device_fn,
346 PCI_LATENCY_TIMER, 255);
347 }
348 #endif
349 vortex_found_device(dev, pci_ioaddr, pci_irq_line, index,
350 dev && dev->mem_start ? dev->mem_start
351 : options[cards_found]);
352 dev = 0;
353 cards_found++;
354 }
355 }
356
357
358 if (EISA_bus) {
359 static int ioaddr = 0x1000;
360 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
361
362 if (inw(ioaddr + 0xC80) != 0x6d50)
363 continue;
364
365 if ((inw(ioaddr + 0xC82) & 0xFFF0) != 0x5970
366 && (inw(ioaddr + 0xC82) & 0xFFF0) != 0x5920)
367 continue;
368 vortex_found_device(dev, ioaddr, inw(ioaddr + 0xC88) >> 12,
369 DEMON_INDEX, dev && dev->mem_start
370 ? dev->mem_start : options[cards_found]);
371 dev = 0;
372 cards_found++;
373 }
374 }
375
376 return cards_found;
377 }
378
379 static int vortex_found_device(struct device *dev, int ioaddr, int irq,
380 int product_index, int options)
381 {
382 struct vortex_private *vp;
383
384 #ifdef MODULE
385
386 int dev_size = sizeof(struct device) +
387 sizeof(struct vortex_private);
388
389 dev = (struct device *) kmalloc(dev_size, GFP_KERNEL);
390 memset(dev, 0, dev_size);
391 dev->priv = ((void *)dev) + sizeof(struct device);
392 vp = (struct vortex_private *)dev->priv;
393 dev->name = vp->devname;
394 dev->base_addr = ioaddr;
395 dev->irq = irq;
396 dev->init = vortex_probe1;
397 vp->product_name = product_names[product_index];
398 vp->options = options;
399 if (options >= 0) {
400 vp->media_override = ((options & 7) == 2) ? 0 : options & 7;
401 vp->full_duplex = (options & 8) ? 1 : 0;
402 vp->bus_master = (options & 16) ? 1 : 0;
403 } else {
404 vp->media_override = 7;
405 vp->full_duplex = 0;
406 vp->bus_master = 0;
407 }
408 ether_setup(dev);
409 vp->next_module = root_vortex_dev;
410 root_vortex_dev = dev;
411 if (register_netdev(dev) != 0)
412 return -EIO;
413 #else
414 if (dev) {
415 dev->priv = kmalloc(sizeof (struct vortex_private), GFP_KERNEL);
416 memset(dev->priv, 0, sizeof (struct vortex_private));
417 }
418 dev = init_etherdev(dev, sizeof(struct vortex_private));
419 dev->base_addr = ioaddr;
420 dev->irq = irq;
421 vp = (struct vortex_private *)dev->priv;
422 vp->product_name = product_names[product_index];
423 vp->options = options;
424 if (options >= 0) {
425 vp->media_override = ((options & 7) == 2) ? 0 : options & 7;
426 vp->full_duplex = (options & 8) ? 1 : 0;
427 vp->bus_master = (options & 16) ? 1 : 0;
428 } else {
429 vp->media_override = 7;
430 vp->full_duplex = 0;
431 vp->bus_master = 0;
432 }
433
434 vortex_probe1(dev);
435 #endif
436 return 0;
437 }
438
439 static int vortex_probe1(struct device *dev)
440 {
441 int ioaddr = dev->base_addr;
442 struct vortex_private *vp = (struct vortex_private *)dev->priv;
443 int i;
444
445 printk("%s: 3Com %s at %#3x,", dev->name,
446 vp->product_name, ioaddr);
447
448
449 EL3WINDOW(0);
450 for (i = 0; i < 3; i++) {
451 short *phys_addr = (short *)dev->dev_addr;
452 int timer;
453 outw(EEPROM_Read + PhysAddr01 + i, ioaddr + Wn0EepromCmd);
454
455 for (timer = 0; timer < 162*4 + 400; timer++) {
456 SLOW_DOWN_IO;
457 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
458 break;
459 }
460 phys_addr[i] = htons(inw(ioaddr + 12));
461 }
462 for (i = 0; i < 6; i++)
463 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
464 printk(", IRQ %d\n", dev->irq);
465
466 if (vortex_debug && (dev->irq <= 0 || dev->irq > 15))
467 printk(" *** Warning: this IRQ is unlikely to work!\n");
468
469 {
470 char *ram_split[] = {"5:3", "3:1", "1:1", "invalid"};
471 union wn3_config config;
472 EL3WINDOW(3);
473 config.i = inl(ioaddr + Wn3_Config);
474 if (vortex_debug > 1)
475 printk(" Internal config register is %4.4x, transceivers %#x.\n",
476 config.i, inw(ioaddr + Wn3_Options));
477 printk(" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
478 8 << config.u.ram_size,
479 config.u.ram_width ? "word" : "byte",
480 ram_split[config.u.ram_split],
481 config.u.autoselect ? "autoselect/" : "",
482 if_names[config.u.xcvr]);
483 dev->if_port = config.u.xcvr;
484 vp->autoselect = config.u.autoselect;
485 }
486
487
488 request_region(ioaddr, VORTEX_TOTAL_SIZE, vp->product_name);
489
490
491 dev->open = &vortex_open;
492 dev->hard_start_xmit = &vortex_start_xmit;
493 dev->stop = &vortex_close;
494 dev->get_stats = &vortex_get_stats;
495 dev->set_multicast_list = &set_multicast_list;
496 #if defined (HAVE_SET_MAC_ADDR) && 0
497 dev->set_mac_address = &set_mac_address;
498 #endif
499
500 return 0;
501 }
502
503
504 static int
505 vortex_open(struct device *dev)
506 {
507 int ioaddr = dev->base_addr;
508 struct vortex_private *vp = (struct vortex_private *)dev->priv;
509 union wn3_config config;
510 int i;
511
512
513 EL3WINDOW(3);
514 if (vp->full_duplex)
515 outb(0x20, ioaddr + Wn3_MAC_Ctrl);
516 config.i = inl(ioaddr + Wn3_Config);
517
518 if (vp->media_override != 7) {
519 if (vortex_debug > 1)
520 printk("%s: Media override to transceiver %d (%s).\n",
521 dev->name, vp->media_override, if_names[vp->media_override]);
522 config.u.xcvr = vp->media_override;
523 dev->if_port = vp->media_override;
524 outl(config.i, ioaddr + Wn3_Config);
525 }
526
527 if (vortex_debug > 1) {
528 printk("%s: vortex_open() InternalConfig %8.8x.\n",
529 dev->name, config.i);
530 }
531
532 outw(TxReset, ioaddr + EL3_CMD);
533 for (i = 20; i >= 0 ; i--)
534 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
535 break;
536
537 outw(RxReset, ioaddr + EL3_CMD);
538
539 for (i = 20; i >= 0 ; i--)
540 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
541 break;
542
543 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
544
545 #ifdef USE_SHARED_IRQ
546 i = request_shared_irq(dev->irq, &vortex_interrupt, dev, vp->product_name);
547 if (i)
548 return i;
549 #else
550 if (dev->irq == 0 || irq2dev_map[dev->irq] != NULL)
551 return -EAGAIN;
552 irq2dev_map[dev->irq] = dev;
553 if (request_irq(dev->irq, &vortex_interrupt, 0, vp->product_name, NULL)) {
554 irq2dev_map[dev->irq] = NULL;
555 return -EAGAIN;
556 }
557 #endif
558
559 if (vortex_debug > 1) {
560 EL3WINDOW(4);
561 printk("%s: vortex_open() irq %d media status %4.4x.\n",
562 dev->name, dev->irq, inw(ioaddr + Wn4_Media));
563 }
564
565
566 EL3WINDOW(2);
567 for (i = 0; i < 6; i++)
568 outb(dev->dev_addr[i], ioaddr + i);
569 for (; i < 12; i+=2)
570 outw(0, ioaddr + i);
571
572 if (dev->if_port == 3)
573
574 outw(StartCoax, ioaddr + EL3_CMD);
575 else if (dev->if_port == 0) {
576
577 EL3WINDOW(4);
578 outw(inw(ioaddr + Wn4_Media) | Media_TP, ioaddr + Wn4_Media);
579 }
580
581
582 outw(StatsDisable, ioaddr + EL3_CMD);
583 EL3WINDOW(6);
584 for (i = 0; i < 10; i++)
585 inb(ioaddr + i);
586 inw(ioaddr + 10);
587 inw(ioaddr + 12);
588
589 EL3WINDOW(4);
590 inb(ioaddr + 12);
591
592
593 EL3WINDOW(7);
594
595
596 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
597 outw(StatsEnable, ioaddr + EL3_CMD);
598
599 dev->tbusy = 0;
600 dev->interrupt = 0;
601 dev->start = 1;
602
603 outw(RxEnable, ioaddr + EL3_CMD);
604 outw(TxEnable, ioaddr + EL3_CMD);
605
606 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
607
608 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
609 ioaddr + EL3_CMD);
610 outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
611 | DMADone, ioaddr + EL3_CMD);
612
613 #ifdef MODULE
614 MOD_INC_USE_COUNT;
615 #endif
616
617 if (vp->autoselect) {
618 init_timer(&vp->timer);
619 vp->timer.expires = (14*HZ)/10;
620 vp->timer.data = (unsigned long)dev;
621 vp->timer.function = &vortex_timer;
622 add_timer(&vp->timer);
623 }
624 return 0;
625 }
626
627 static void vortex_timer(unsigned long data)
628 {
629 struct device *dev = (struct device *)data;
630 if (vortex_debug > 2)
631 printk("%s: Media selection timer tick happened.\n", dev->name);
632
633 }
634
635 static int
636 vortex_start_xmit(struct sk_buff *skb, struct device *dev)
637 {
638 struct vortex_private *vp = (struct vortex_private *)dev->priv;
639 int ioaddr = dev->base_addr;
640
641
642 if (dev->tbusy) {
643 int tickssofar = jiffies - dev->trans_start;
644 if (tickssofar < 40)
645 return 1;
646 printk("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
647 dev->name, inb(ioaddr + TxStatus), inw(ioaddr + EL3_STATUS));
648 vp->stats.tx_errors++;
649
650 outw(TxReset, ioaddr + EL3_CMD);
651 {
652 int i;
653 for (i = 20; i >= 0 ; i--)
654 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
655 break;
656 }
657 outw(TxEnable, ioaddr + EL3_CMD);
658 dev->trans_start = jiffies;
659 dev->tbusy = 0;
660 return 0;
661 }
662
663 if (skb == NULL || skb->len <= 0) {
664 printk("%s: Obsolete driver layer request made: skbuff==NULL.\n",
665 dev->name);
666 dev_tint(dev);
667 return 0;
668 }
669
670
671
672
673 if (set_bit(0, (void*)&dev->tbusy) != 0) {
674 printk("%s: Transmitter access conflict.\n", dev->name);
675 return 1;
676 }
677
678
679 outl(skb->len, ioaddr + TX_FIFO);
680 #ifdef VORTEX_BUS_MASTER
681 if (vp->bus_master) {
682
683 outl((int)(skb->data), ioaddr + Wn7_MasterAddr);
684 outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
685 vp->tx_skb = skb;
686 outw(StartDMADown, ioaddr + EL3_CMD);
687 } else {
688
689 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
690 dev_kfree_skb (skb, FREE_WRITE);
691 if (inw(ioaddr + TxFree) > 1536) {
692 dev->tbusy = 0;
693 } else
694
695 outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
696 }
697 #else
698
699 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
700 dev_kfree_skb (skb, FREE_WRITE);
701 if (inw(ioaddr + TxFree) > 1536) {
702 dev->tbusy = 0;
703 } else
704
705 outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
706 #endif
707
708 dev->trans_start = jiffies;
709
710
711 {
712 short tx_status;
713 int i = 4;
714
715 while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
716 if (tx_status & 0x3C) {
717 if (vortex_debug > 2)
718 printk("%s: Tx error, status %2.2x.\n",
719 dev->name, tx_status);
720 if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
721 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
722 if (tx_status & 0x30) {
723 int j;
724 outw(TxReset, ioaddr + EL3_CMD);
725 for (j = 20; j >= 0 ; j--)
726 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
727 break;
728 }
729 outw(TxEnable, ioaddr + EL3_CMD);
730 }
731 outb(0x00, ioaddr + TxStatus);
732 }
733 }
734 return 0;
735 }
736
737
738
739 static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
740 {
741 #ifdef USE_SHARED_IRQ
742 struct device *dev = (struct device *)(irq == 0 ? regs : irq2dev_map[irq]);
743 #else
744 struct device *dev = (struct device *)(irq2dev_map[irq]);
745 #endif
746 struct vortex_private *lp;
747 int ioaddr, status;
748 int latency;
749 int i = 0;
750
751 if (dev == NULL) {
752 printk ("vortex_interrupt(): irq %d for unknown device.\n", irq);
753 return;
754 }
755
756 if (dev->interrupt)
757 printk("%s: Re-entering the interrupt handler.\n", dev->name);
758 dev->interrupt = 1;
759
760 ioaddr = dev->base_addr;
761 latency = inb(ioaddr + Timer);
762 lp = (struct vortex_private *)dev->priv;
763
764 status = inw(ioaddr + EL3_STATUS);
765
766 if (vortex_debug > 4)
767 printk("%s: interrupt, status %4.4x, timer %d.\n", dev->name,
768 status, latency);
769 if ((status & 0xE000) != 0xE000) {
770 static int donedidthis=0;
771
772
773
774 if (donedidthis++ > 1) {
775 printk("%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
776 dev->name, status, dev->start);
777 free_irq(dev->irq, NULL);
778 }
779 }
780
781 do {
782 if (vortex_debug > 5)
783 printk("%s: In interrupt loop, status %4.4x.\n",
784 dev->name, status);
785 if (status & RxComplete)
786 vortex_rx(dev);
787
788 if (status & TxAvailable) {
789 if (vortex_debug > 5)
790 printk(" TX room bit was handled.\n");
791
792 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
793 dev->tbusy = 0;
794 mark_bh(NET_BH);
795 }
796 #ifdef VORTEX_BUS_MASTER
797 if (status & DMADone) {
798 outw(0x1000, ioaddr + Wn7_MasterStatus);
799 dev->tbusy = 0;
800 mark_bh(NET_BH);
801 }
802 #endif
803 if (status & (AdapterFailure | RxEarly | StatsFull)) {
804
805 if (status & RxEarly) {
806 vortex_rx(dev);
807 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
808 }
809 if (status & StatsFull) {
810 static int DoneDidThat = 0;
811 if (vortex_debug > 4)
812 printk("%s: Updating stats.\n", dev->name);
813 update_stats(ioaddr, dev);
814
815
816 if (DoneDidThat == 0 &&
817 inw(ioaddr + EL3_STATUS) & StatsFull) {
818 int win, reg;
819 printk("%s: Updating stats failed, disabling stats as an"
820 " interrupt source.\n", dev->name);
821 for (win = 0; win < 8; win++) {
822 EL3WINDOW(win);
823 printk("\n Vortex window %d:", win);
824 for (reg = 0; reg < 16; reg++)
825 printk(" %2.2x", inb(ioaddr+reg));
826 }
827 EL3WINDOW(7);
828 outw(SetIntrEnb | 0x18, ioaddr + EL3_CMD);
829 DoneDidThat++;
830 }
831 }
832 if (status & AdapterFailure) {
833
834 outw(RxReset, ioaddr + EL3_CMD);
835
836 outw(SetRxFilter | RxStation | RxBroadcast
837 | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
838 | (dev->flags & IFF_PROMISC ? RxProm : 0),
839 ioaddr + EL3_CMD);
840 outw(RxEnable, ioaddr + EL3_CMD);
841 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
842 }
843 }
844
845 if (++i > 10) {
846 printk("%s: Infinite loop in interrupt, status %4.4x. "
847 "Disabling functions (%4.4x).\n",
848 dev->name, status, SetStatusEnb | ((~status) & 0xFE));
849
850 outw(SetStatusEnb | ((~status) & 0xFE), ioaddr + EL3_CMD);
851 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
852 break;
853 }
854
855 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
856
857 } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
858
859 if (vortex_debug > 4)
860 printk("%s: exiting interrupt, status %4.4x.\n", dev->name, status);
861
862 dev->interrupt = 0;
863 return;
864 }
865
866 static int
867 vortex_rx(struct device *dev)
868 {
869 struct vortex_private *vp = (struct vortex_private *)dev->priv;
870 int ioaddr = dev->base_addr;
871 int i;
872 short rx_status;
873
874 if (vortex_debug > 5)
875 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
876 inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
877 while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
878 if (rx_status & 0x4000) {
879 unsigned char rx_error = inb(ioaddr + RxErrors);
880 if (vortex_debug > 4)
881 printk(" Rx error: status %2.2x.\n", rx_error);
882 vp->stats.rx_errors++;
883 if (rx_error & 0x01) vp->stats.rx_over_errors++;
884 if (rx_error & 0x02) vp->stats.rx_length_errors++;
885 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
886 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
887 if (rx_error & 0x10) vp->stats.rx_length_errors++;
888 } else {
889
890 short pkt_len = rx_status & 0x1fff;
891 struct sk_buff *skb;
892
893 skb = dev_alloc_skb(pkt_len + 5);
894 if (vortex_debug > 4)
895 printk("Receiving packet size %d status %4.4x.\n",
896 pkt_len, rx_status);
897 if (skb != NULL) {
898 skb->dev = dev;
899 skb_reserve(skb, 2);
900
901 insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
902 (pkt_len + 3) >> 2);
903 skb->protocol = eth_type_trans(skb, dev);
904 netif_rx(skb);
905 outw(RxDiscard, ioaddr + EL3_CMD);
906
907 for (i = 200; i >= 0; i--)
908 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
909 break;
910 vp->stats.rx_packets++;
911 continue;
912 } else if (vortex_debug)
913 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
914 dev->name, pkt_len);
915 }
916 vp->stats.rx_dropped++;
917 outw(RxDiscard, ioaddr + EL3_CMD);
918
919 for (i = 200; i >= 0; i--)
920 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
921 break;
922 }
923
924 return 0;
925 }
926
927 static int
928 vortex_close(struct device *dev)
929 {
930 int ioaddr = dev->base_addr;
931
932 dev->start = 0;
933 dev->tbusy = 1;
934
935 if (vortex_debug > 1)
936 printk("%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
937 dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
938
939
940 outw(StatsDisable, ioaddr + EL3_CMD);
941
942
943 outw(RxDisable, ioaddr + EL3_CMD);
944 outw(TxDisable, ioaddr + EL3_CMD);
945
946 if (dev->if_port == 3)
947
948 outw(StopCoax, ioaddr + EL3_CMD);
949 else if (dev->if_port == 0) {
950
951 EL3WINDOW(4);
952 outw(inw(ioaddr + Wn4_Media) & ~Media_TP, ioaddr + Wn4_Media);
953 }
954
955 #ifdef USE_SHARED_IRQ
956 free_shared_irq(dev->irq, dev);
957 #else
958 free_irq(dev->irq, NULL);
959
960 irq2dev_map[dev->irq] = 0;
961 #endif
962
963 update_stats(ioaddr, dev);
964 #ifdef MODULE
965 MOD_DEC_USE_COUNT;
966 #endif
967
968 return 0;
969 }
970
971 static struct enet_statistics *
972 vortex_get_stats(struct device *dev)
973 {
974 struct vortex_private *vp = (struct vortex_private *)dev->priv;
975 unsigned long flags;
976
977 save_flags(flags);
978 cli();
979 update_stats(dev->base_addr, dev);
980 restore_flags(flags);
981 return &vp->stats;
982 }
983
984
985
986
987
988
989
990
991 static void update_stats(int ioaddr, struct device *dev)
992 {
993 struct vortex_private *vp = (struct vortex_private *)dev->priv;
994
995
996
997 EL3WINDOW(6);
998 vp->stats.tx_carrier_errors += inb(ioaddr + 0);
999 vp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1000 inb(ioaddr + 2);
1001 vp->stats.collisions += inb(ioaddr + 3);
1002 vp->stats.tx_window_errors += inb(ioaddr + 4);
1003 vp->stats.rx_fifo_errors += inb(ioaddr + 5);
1004 vp->stats.tx_packets += inb(ioaddr + 6);
1005 vp->stats.tx_packets += (inb(ioaddr + 9)&0x30) << 4;
1006 inb(ioaddr + 7);
1007 inb(ioaddr + 8);
1008
1009
1010
1011 inw(ioaddr + 10);
1012 inw(ioaddr + 12);
1013
1014 EL3WINDOW(4);
1015 inb(ioaddr + 12);
1016
1017
1018 EL3WINDOW(7);
1019 return;
1020 }
1021
1022
1023
1024 static void
1025 set_multicast_list(struct device *dev)
1026 {
1027 short ioaddr = dev->base_addr;
1028
1029 if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
1030 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
1031 if (vortex_debug > 3) {
1032 printk("%s: Setting Rx multicast mode, %d addresses.\n",
1033 dev->name, dev->mc_count);
1034 }
1035 } else if (dev->flags & IFF_PROMISC) {
1036 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
1037 ioaddr + EL3_CMD);
1038 } else
1039 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1040 }
1041
1042
1043 #ifdef MODULE
1044 void
1045 cleanup_module(void)
1046 {
1047 struct device *next_dev;
1048
1049
1050 while (root_vortex_dev) {
1051 next_dev = ((struct vortex_private *)root_vortex_dev->priv)->next_module;
1052 unregister_netdev(root_vortex_dev);
1053 release_region(root_vortex_dev->base_addr, VORTEX_TOTAL_SIZE);
1054 kfree(root_vortex_dev);
1055 root_vortex_dev = next_dev;
1056 }
1057 }
1058 #endif
1059
1060
1061
1062
1063
1064
1065
1066