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