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 if (options >= 0) {
417 vp->media_override = options & 7;
418 vp->full_duplex = (options & 8) ? 1 : 0;
419 vp->bus_master = (options & 16) ? 1 : 0;
420 } else {
421 vp->media_override = 7;
422 vp->full_duplex = 0;
423 vp->bus_master = 0;
424 }
425
426 vortex_probe1(dev);
427 #endif
428 return 0;
429 }
430
431 static int vortex_probe1(struct device *dev)
432 {
433 int ioaddr = dev->base_addr;
434 struct vortex_private *vp = (struct vortex_private *)dev->priv;
435 int i;
436
437 printk("%s: 3Com %s at %#3x,", dev->name,
438 vp->product_name, ioaddr);
439
440
441 EL3WINDOW(0);
442 for (i = 0; i < 3; i++) {
443 short *phys_addr = (short *)dev->dev_addr;
444 int timer;
445 outw(EEPROM_Read + PhysAddr01 + i, ioaddr + Wn0EepromCmd);
446
447 for (timer = 0; timer < 162*4 + 400; timer++) {
448 SLOW_DOWN_IO;
449 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
450 break;
451 }
452 phys_addr[i] = htons(inw(ioaddr + 12));
453 }
454 for (i = 0; i < 6; i++)
455 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
456 printk(", IRQ %d\n", dev->irq);
457
458 if (vortex_debug && (dev->irq <= 0 || dev->irq > 15))
459 printk(" *** Warning: this IRQ is unlikely to work!\n");
460
461 {
462 char *ram_split[] = {"5:3", "3:1", "1:1", "invalid"};
463 union wn3_config config;
464 EL3WINDOW(3);
465 config.i = inl(ioaddr + Wn3_Config);
466 if (vortex_debug > 1)
467 printk(" Internal config register is %4.4x, transceivers %#x.\n",
468 config.i, inw(ioaddr + Wn3_Options));
469 printk(" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
470 8 << config.u.ram_size,
471 config.u.ram_width ? "word" : "byte",
472 ram_split[config.u.ram_split],
473 config.u.autoselect ? "autoselect/" : "",
474 if_names[config.u.xcvr]);
475 dev->if_port = config.u.xcvr;
476 vp->autoselect = config.u.autoselect;
477 }
478
479
480 request_region(ioaddr, VORTEX_TOTAL_SIZE, vp->product_name);
481
482
483 dev->open = &vortex_open;
484 dev->hard_start_xmit = &vortex_start_xmit;
485 dev->stop = &vortex_close;
486 dev->get_stats = &vortex_get_stats;
487 dev->set_multicast_list = &set_multicast_list;
488 #if defined (HAVE_SET_MAC_ADDR) && 0
489 dev->set_mac_address = &set_mac_address;
490 #endif
491
492 return 0;
493 }
494
495
496 static int
497 vortex_open(struct device *dev)
498 {
499 int ioaddr = dev->base_addr;
500 struct vortex_private *vp = (struct vortex_private *)dev->priv;
501 union wn3_config config;
502 int i;
503
504
505 EL3WINDOW(3);
506 if (vp->full_duplex)
507 outb(0x20, ioaddr + Wn3_MAC_Ctrl);
508 config.i = inl(ioaddr + Wn3_Config);
509
510 if (vp->media_override != 7) {
511 if (vortex_debug > 1)
512 printk("%s: Media override to transceiver %d (%s).\n",
513 dev->name, vp->media_override, if_names[vp->media_override]);
514 config.u.xcvr = vp->media_override;
515 dev->if_port = vp->media_override;
516 outl(config.i, ioaddr + Wn3_Config);
517 }
518
519 if (vortex_debug > 1) {
520 printk("%s: vortex_open() InternalConfig %8.8x.\n",
521 dev->name, config.i);
522 }
523
524 outw(TxReset, ioaddr + EL3_CMD);
525 for (i = 20; i >= 0 ; i--)
526 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
527 break;
528
529 outw(RxReset, ioaddr + EL3_CMD);
530
531 for (i = 20; i >= 0 ; i--)
532 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
533 break;
534
535 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
536
537 if (irq2dev_map[dev->irq] != NULL
538 || (irq2dev_map[dev->irq] = dev) == NULL
539 || dev->irq == 0
540 || request_irq(dev->irq, &vortex_interrupt, 0, vp->product_name)) {
541 return -EAGAIN;
542 }
543
544 if (vortex_debug > 1) {
545 EL3WINDOW(4);
546 printk("%s: vortex_open() irq %d media status %4.4x.\n",
547 dev->name, dev->irq, inw(ioaddr + Wn4_Media));
548 }
549
550
551 EL3WINDOW(2);
552 for (i = 0; i < 6; i++)
553 outb(dev->dev_addr[i], ioaddr + i);
554 for (; i < 12; i+=2)
555 outw(0, ioaddr + i);
556
557 if (dev->if_port == 3)
558
559 outw(StartCoax, ioaddr + EL3_CMD);
560 else if (dev->if_port == 0) {
561
562 EL3WINDOW(4);
563 outw(inw(ioaddr + Wn4_Media) | Media_TP, ioaddr + Wn4_Media);
564 }
565
566
567 outw(StatsDisable, ioaddr + EL3_CMD);
568 EL3WINDOW(6);
569 for (i = 0; i < 10; i++)
570 inb(ioaddr + i);
571 inw(ioaddr + 10);
572 inw(ioaddr + 12);
573
574 EL3WINDOW(3);
575 inb(ioaddr + 12);
576
577
578 EL3WINDOW(7);
579
580
581 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
582 outw(StatsEnable, ioaddr + EL3_CMD);
583
584 dev->tbusy = 0;
585 dev->interrupt = 0;
586 dev->start = 1;
587
588 outw(RxEnable, ioaddr + EL3_CMD);
589 outw(TxEnable, ioaddr + EL3_CMD);
590
591 outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD);
592
593 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
594 ioaddr + EL3_CMD);
595 outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
596 | DMADone, ioaddr + EL3_CMD);
597
598 #ifdef MODULE
599 MOD_INC_USE_COUNT;
600 #endif
601
602 if (vp->autoselect) {
603 init_timer(&vp->timer);
604 vp->timer.expires = (14*HZ)/10;
605 vp->timer.data = (unsigned long)dev;
606 vp->timer.function = &vortex_timer;
607 add_timer(&vp->timer);
608 }
609 return 0;
610 }
611
612 static void vortex_timer(unsigned long data)
613 {
614 struct device *dev = (struct device *)data;
615 if (vortex_debug > 2)
616 printk("%s: Media selection timer tick happened.\n", dev->name);
617
618 }
619
620 static int
621 vortex_start_xmit(struct sk_buff *skb, struct device *dev)
622 {
623 struct vortex_private *vp = (struct vortex_private *)dev->priv;
624 int ioaddr = dev->base_addr;
625
626
627 if (dev->tbusy) {
628 int tickssofar = jiffies - dev->trans_start;
629 if (tickssofar < 40)
630 return 1;
631 printk("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
632 dev->name, inb(ioaddr + TxStatus), inw(ioaddr + EL3_STATUS));
633 vp->stats.tx_errors++;
634
635 outw(TxReset, ioaddr + EL3_CMD);
636 {
637 int i;
638 for (i = 20; i >= 0 ; i--)
639 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
640 break;
641 }
642 outw(TxEnable, ioaddr + EL3_CMD);
643 dev->trans_start = jiffies;
644 dev->tbusy = 0;
645 return 0;
646 }
647
648 if (skb == NULL || skb->len <= 0) {
649 printk("%s: Obsolete driver layer request made: skbuff==NULL.\n",
650 dev->name);
651 dev_tint(dev);
652 return 0;
653 }
654
655
656
657
658 if (set_bit(0, (void*)&dev->tbusy) != 0) {
659 printk("%s: Transmitter access conflict.\n", dev->name);
660 return 1;
661 }
662
663
664 outl(skb->len, ioaddr + TX_FIFO);
665 #ifdef VORTEX_BUS_MASTER
666 if (vp->bus_master) {
667
668 outl((int)(skb->data), ioaddr + Wn7_MasterAddr);
669 outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
670 vp->tx_skb = skb;
671 outw(StartDMADown, ioaddr + EL3_CMD);
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 }
682 #else
683
684 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
685 dev_kfree_skb (skb, FREE_WRITE);
686 if (inw(ioaddr + TxFree) > 1536) {
687 dev->tbusy = 0;
688 } else
689
690 outw(SetTxThreshold + 1536, ioaddr + EL3_CMD);
691 #endif
692
693 dev->trans_start = jiffies;
694
695
696 {
697 short tx_status;
698 int i = 4;
699
700 while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
701 if (tx_status & 0x3C) {
702 if (vortex_debug > 2)
703 printk("%s: Tx error, status %2.2x.\n",
704 dev->name, tx_status);
705 if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
706 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
707 if (tx_status & 0x30) {
708 int j;
709 outw(TxReset, ioaddr + EL3_CMD);
710 for (j = 20; j >= 0 ; j--)
711 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
712 break;
713 }
714 outw(TxEnable, ioaddr + EL3_CMD);
715 }
716 outb(0x00, ioaddr + TxStatus);
717 }
718 }
719 return 0;
720 }
721
722
723
724 static void vortex_interrupt(int irq, struct pt_regs *regs)
725 {
726 struct device *dev = (struct device *)(irq2dev_map[irq]);
727 struct vortex_private *lp;
728 int ioaddr, status;
729 int latency;
730 int i = 0;
731
732 if (dev == NULL) {
733 printk ("vortex_interrupt(): irq %d for unknown device.\n", irq);
734 return;
735 }
736
737 if (dev->interrupt)
738 printk("%s: Re-entering the interrupt handler.\n", dev->name);
739 dev->interrupt = 1;
740
741 ioaddr = dev->base_addr;
742 latency = inb(ioaddr + Timer);
743 lp = (struct vortex_private *)dev->priv;
744
745 status = inw(ioaddr + EL3_STATUS);
746
747 if (vortex_debug > 4)
748 printk("%s: interrupt, status %4.4x, timer %d.\n", dev->name,
749 status, latency);
750 if ((status & 0xE000) != 0xE000) {
751 static int donedidthis=0;
752
753
754
755 if (donedidthis++ > 1) {
756 printk("%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
757 dev->name, status, dev->start);
758 free_irq(dev->irq);
759 }
760 }
761
762 do {
763 if (vortex_debug > 5)
764 printk("%s: In interrupt loop, status %4.4x.\n",
765 dev->name, status);
766 if (status & RxComplete)
767 vortex_rx(dev);
768
769 if (status & TxAvailable) {
770 if (vortex_debug > 5)
771 printk(" TX room bit was handled.\n");
772
773 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
774 dev->tbusy = 0;
775 mark_bh(NET_BH);
776 }
777 #ifdef VORTEX_BUS_MASTER
778 if (status & DMADone) {
779 outw(0x1000, ioaddr + Wn7_MasterStatus);
780 dev->tbusy = 0;
781 mark_bh(NET_BH);
782 }
783 #endif
784 if (status & (AdapterFailure | RxEarly | StatsFull)) {
785
786 if (status & RxEarly) {
787 vortex_rx(dev);
788 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
789 }
790 if (status & StatsFull) {
791 static int DoneDidThat = 0;
792 if (vortex_debug > 4)
793 printk("%s: Updating stats.\n", dev->name);
794 update_stats(ioaddr, dev);
795
796
797 if (DoneDidThat == 0 &&
798 inw(ioaddr + EL3_STATUS) & StatsFull) {
799 int win, reg;
800 printk("%s: Updating stats failed, disabling stats as an"
801 " interrupt source.\n", dev->name);
802 for (win = 0; win < 8; win++) {
803 EL3WINDOW(win);
804 printk("\n Vortex window %d:", win);
805 for (reg = 0; reg < 16; reg++)
806 printk(" %2.2x", inb(ioaddr+reg));
807 }
808 EL3WINDOW(7);
809 outw(SetIntrEnb | 0x18, ioaddr + EL3_CMD);
810 DoneDidThat++;
811 }
812 }
813 if (status & AdapterFailure) {
814
815 outw(RxReset, ioaddr + EL3_CMD);
816
817 outw(SetRxFilter | RxStation | RxBroadcast
818 | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0)
819 | (dev->flags & IFF_PROMISC ? RxProm : 0),
820 ioaddr + EL3_CMD);
821 outw(RxEnable, ioaddr + EL3_CMD);
822 outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD);
823 }
824 }
825
826 if (++i > 10) {
827 printk("%s: Infinite loop in interrupt, status %4.4x. "
828 "Disabling functions (%4.4x).\n",
829 dev->name, status, SetStatusEnb | ((~status) & 0xFE));
830
831 outw(SetStatusEnb | ((~status) & 0xFE), ioaddr + EL3_CMD);
832 outw(AckIntr | 0xFF, ioaddr + EL3_CMD);
833 break;
834 }
835
836 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
837
838 } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
839
840 if (vortex_debug > 4)
841 printk("%s: exiting interrupt, status %4.4x.\n", dev->name, status);
842
843 dev->interrupt = 0;
844 return;
845 }
846
847 static int
848 vortex_rx(struct device *dev)
849 {
850 struct vortex_private *vp = (struct vortex_private *)dev->priv;
851 int ioaddr = dev->base_addr;
852 int i;
853 short rx_status;
854
855 if (vortex_debug > 5)
856 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
857 inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
858 while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
859 if (rx_status & 0x4000) {
860 unsigned char rx_error = inb(ioaddr + RxErrors);
861 if (vortex_debug > 4)
862 printk(" Rx error: status %2.2x.\n", rx_error);
863 vp->stats.rx_errors++;
864 if (rx_error & 0x01) vp->stats.rx_over_errors++;
865 if (rx_error & 0x02) vp->stats.rx_length_errors++;
866 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
867 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
868 if (rx_error & 0x10) vp->stats.rx_length_errors++;
869 } else {
870
871 short pkt_len = rx_status & 0x1fff;
872 struct sk_buff *skb;
873
874 skb = dev_alloc_skb(pkt_len + 5);
875 if (vortex_debug > 4)
876 printk("Receiving packet size %d status %4.4x.\n",
877 pkt_len, rx_status);
878 if (skb != NULL) {
879 skb->dev = dev;
880 skb_reserve(skb, 2);
881
882 insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
883 (pkt_len + 3) >> 2);
884 skb->protocol = eth_type_trans(skb, dev);
885 netif_rx(skb);
886 outw(RxDiscard, ioaddr + EL3_CMD);
887
888 for (i = 200; i >= 0; i--)
889 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
890 break;
891 vp->stats.rx_packets++;
892 continue;
893 } else if (vortex_debug)
894 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
895 dev->name, pkt_len);
896 }
897 vp->stats.rx_dropped++;
898 outw(RxDiscard, ioaddr + EL3_CMD);
899
900 for (i = 200; i >= 0; i--)
901 if ( ! inw(ioaddr + EL3_STATUS) & CmdInProgress)
902 break;
903 }
904
905 return 0;
906 }
907
908 static int
909 vortex_close(struct device *dev)
910 {
911 int ioaddr = dev->base_addr;
912
913 dev->start = 0;
914 dev->tbusy = 1;
915
916 if (vortex_debug > 1)
917 printk("%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
918 dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
919
920
921 outw(StatsDisable, ioaddr + EL3_CMD);
922
923
924 outw(RxDisable, ioaddr + EL3_CMD);
925 outw(TxDisable, ioaddr + EL3_CMD);
926
927 if (dev->if_port == 3)
928
929 outw(StopCoax, ioaddr + EL3_CMD);
930 else if (dev->if_port == 0) {
931
932 EL3WINDOW(4);
933 outw(inw(ioaddr + Wn4_Media) & ~Media_TP, ioaddr + Wn4_Media);
934 }
935
936 free_irq(dev->irq);
937
938 irq2dev_map[dev->irq] = 0;
939
940 update_stats(ioaddr, dev);
941 #ifdef MODULE
942 MOD_DEC_USE_COUNT;
943 #endif
944
945 return 0;
946 }
947
948 static struct enet_statistics *
949 vortex_get_stats(struct device *dev)
950 {
951 struct vortex_private *vp = (struct vortex_private *)dev->priv;
952 unsigned long flags;
953
954 save_flags(flags);
955 cli();
956 update_stats(dev->base_addr, dev);
957 restore_flags(flags);
958 return &vp->stats;
959 }
960
961
962
963
964
965
966
967
968 static void update_stats(int ioaddr, struct device *dev)
969 {
970 struct vortex_private *vp = (struct vortex_private *)dev->priv;
971
972
973
974 EL3WINDOW(6);
975 vp->stats.tx_carrier_errors += inb(ioaddr + 0);
976 vp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
977 inb(ioaddr + 2);
978 vp->stats.collisions += inb(ioaddr + 3);
979 vp->stats.tx_window_errors += inb(ioaddr + 4);
980 vp->stats.rx_fifo_errors += inb(ioaddr + 5);
981 vp->stats.tx_packets += inb(ioaddr + 6);
982 vp->stats.tx_packets += (inb(ioaddr + 9)&15) << 8;
983 inb(ioaddr + 7);
984 inb(ioaddr + 8);
985
986
987
988 inw(ioaddr + 10);
989 inw(ioaddr + 12);
990
991 EL3WINDOW(3);
992 inb(ioaddr + 12);
993
994
995 EL3WINDOW(7);
996 return;
997 }
998
999
1000
1001 static void
1002 set_multicast_list(struct device *dev)
1003 {
1004 short ioaddr = dev->base_addr;
1005
1006 if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
1007 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
1008 if (vortex_debug > 3) {
1009 printk("%s: Setting Rx multicast mode, %d addresses.\n",
1010 dev->name, dev->mc_count);
1011 }
1012 } else if (dev->flags & IFF_PROMISC) {
1013 outw(SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm,
1014 ioaddr + EL3_CMD);
1015 } else
1016 outw(SetRxFilter | RxStation | RxBroadcast, ioaddr + EL3_CMD);
1017 }
1018
1019
1020 #ifdef MODULE
1021 void
1022 cleanup_module(void)
1023 {
1024 struct device *next_dev;
1025
1026
1027 while (root_vortex_dev) {
1028 next_dev = ((struct vortex_private *)root_vortex_dev->priv)->next_module;
1029 unregister_netdev(root_vortex_dev);
1030 release_region(root_vortex_dev->base_addr, VORTEX_TOTAL_SIZE);
1031 kfree(root_vortex_dev);
1032 root_vortex_dev = next_dev;
1033 }
1034 }
1035 #endif
1036
1037
1038
1039
1040
1041
1042
1043