1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195#define DRV_NAME "3c59x"
196#define DRV_VERSION "LK1.1.18"
197#define DRV_RELDATE "1 Jul 2002"
198
199
200
201
202
203#define TX_RING_SIZE 16
204#define RX_RING_SIZE 32
205#define PKT_BUF_SZ 1536
206
207
208
209
210#ifndef __arm__
211static const int rx_copybreak = 200;
212#else
213
214
215static const int rx_copybreak = 1513;
216#endif
217
218static const int mtu = 1500;
219
220static int max_interrupt_work = 32;
221
222static int watchdog = 5000;
223
224
225
226
227
228#define tx_interrupt_mitigation 1
229
230
231#define vortex_debug debug
232#ifdef VORTEX_DEBUG
233static int vortex_debug = VORTEX_DEBUG;
234#else
235static int vortex_debug = 1;
236#endif
237
238#ifndef __OPTIMIZE__
239#error You must compile this file with the correct options!
240#error See the last lines of the source file.
241#error You must compile this driver with "-O".
242#endif
243
244#include <linux/config.h>
245#include <linux/module.h>
246#include <linux/kernel.h>
247#include <linux/sched.h>
248#include <linux/string.h>
249#include <linux/timer.h>
250#include <linux/errno.h>
251#include <linux/in.h>
252#include <linux/ioport.h>
253#include <linux/slab.h>
254#include <linux/interrupt.h>
255#include <linux/pci.h>
256#include <linux/mii.h>
257#include <linux/init.h>
258#include <linux/netdevice.h>
259#include <linux/etherdevice.h>
260#include <linux/skbuff.h>
261#include <linux/ethtool.h>
262#include <linux/highmem.h>
263#include <asm/irq.h>
264#include <asm/bitops.h>
265#include <asm/io.h>
266#include <asm/uaccess.h>
267
268
269
270
271#define RUN_AT(x) (jiffies + (x))
272
273#include <linux/delay.h>
274
275
276static char version[] __devinitdata =
277DRV_NAME ": Donald Becker and others. www.scyld.com/network/vortex.html\n";
278
279MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
280MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver "
281 DRV_VERSION " " DRV_RELDATE);
282MODULE_LICENSE("GPL");
283
284MODULE_PARM(debug, "i");
285MODULE_PARM(global_options, "i");
286MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
287MODULE_PARM(global_full_duplex, "i");
288MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
289MODULE_PARM(hw_checksums, "1-" __MODULE_STRING(8) "i");
290MODULE_PARM(flow_ctrl, "1-" __MODULE_STRING(8) "i");
291MODULE_PARM(global_enable_wol, "i");
292MODULE_PARM(enable_wol, "1-" __MODULE_STRING(8) "i");
293MODULE_PARM(rx_copybreak, "i");
294MODULE_PARM(max_interrupt_work, "i");
295MODULE_PARM(compaq_ioaddr, "i");
296MODULE_PARM(compaq_irq, "i");
297MODULE_PARM(compaq_device_id, "i");
298MODULE_PARM(watchdog, "i");
299MODULE_PARM_DESC(debug, "3c59x debug level (0-6)");
300MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex");
301MODULE_PARM_DESC(global_options, "3c59x: same as options, but applies to all NICs if options is unset");
302MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)");
303MODULE_PARM_DESC(global_full_duplex, "3c59x: same as full_duplex, but applies to all NICs if options is unset");
304MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)");
305MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)");
306MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)");
307MODULE_PARM_DESC(global_enable_wol, "3c59x: same as enable_wol, but applies to all NICs if options is unset");
308MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames");
309MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt");
310MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)");
311MODULE_PARM_DESC(compaq_irq, "3c59x PCI IRQ number (Compaq BIOS problem workaround)");
312MODULE_PARM_DESC(compaq_device_id, "3c59x PCI device ID (Compaq BIOS problem workaround)");
313MODULE_PARM_DESC(watchdog, "3c59x transmit timeout in milliseconds");
314
315
316
317
318
319
320
321#define VORTEX_TOTAL_SIZE 0x20
322#define BOOMERANG_TOTAL_SIZE 0x40
323
324
325
326
327static char mii_preamble_required;
328
329#define PFX DRV_NAME ": "
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412enum pci_flags_bit {
413 PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
414 PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
415};
416
417enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8,
418 EEPROM_8BIT=0x10,
419 HAS_PWR_CTRL=0x20, HAS_MII=0x40, HAS_NWAY=0x80, HAS_CB_FNS=0x100,
420 INVERT_MII_PWR=0x200, INVERT_LED_PWR=0x400, MAX_COLLISION_RESET=0x800,
421 EEPROM_OFFSET=0x1000, HAS_HWCKSM=0x2000, WNO_XCVR_PWR=0x4000,
422 EXTRA_PREAMBLE=0x8000, };
423
424enum vortex_chips {
425 CH_3C590 = 0,
426 CH_3C592,
427 CH_3C597,
428 CH_3C595_1,
429 CH_3C595_2,
430
431 CH_3C595_3,
432 CH_3C900_1,
433 CH_3C900_2,
434 CH_3C900_3,
435 CH_3C900_4,
436
437 CH_3C900_5,
438 CH_3C900B_FL,
439 CH_3C905_1,
440 CH_3C905_2,
441 CH_3C905B_1,
442
443 CH_3C905B_2,
444 CH_3C905B_FX,
445 CH_3C905C,
446 CH_3C980,
447 CH_3C9805,
448
449 CH_3CSOHO100_TX,
450 CH_3C555,
451 CH_3C556,
452 CH_3C556B,
453 CH_3C575,
454
455 CH_3C575_1,
456 CH_3CCFE575,
457 CH_3CCFE575CT,
458 CH_3CCFE656,
459 CH_3CCFEM656,
460
461 CH_3CCFEM656_1,
462 CH_3C450,
463};
464
465
466
467
468
469
470static struct vortex_chip_info {
471 const char *name;
472 int flags;
473 int drv_flags;
474 int io_size;
475} vortex_info_tbl[] __devinitdata = {
476#define EISA_TBL_OFFSET 0
477 {"3c590 Vortex 10Mbps",
478 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
479 {"3c592 EISA 10Mbps Demon/Vortex",
480 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
481 {"3c597 EISA Fast Demon/Vortex",
482 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
483 {"3c595 Vortex 100baseTx",
484 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
485 {"3c595 Vortex 100baseT4",
486 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
487
488 {"3c595 Vortex 100base-MII",
489 PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
490 {"3c900 Boomerang 10baseT",
491 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, },
492 {"3c900 Boomerang 10Mbps Combo",
493 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, },
494 {"3c900 Cyclone 10Mbps TPO",
495 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
496 {"3c900 Cyclone 10Mbps Combo",
497 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
498
499 {"3c900 Cyclone 10Mbps TPC",
500 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
501 {"3c900B-FL Cyclone 10base-FL",
502 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
503 {"3c905 Boomerang 100baseTx",
504 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, },
505 {"3c905 Boomerang 100baseT4",
506 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, },
507 {"3c905B Cyclone 100baseTx",
508 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
509
510 {"3c905B Cyclone 10/100/BNC",
511 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
512 {"3c905B-FX Cyclone 100baseFx",
513 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
514 {"3c905C Tornado",
515 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
516 {"3c980 Cyclone",
517 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
518 {"3c980C Python-T",
519 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
520
521 {"3cSOHO100-TX Hurricane",
522 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
523 {"3c555 Laptop Hurricane",
524 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|EEPROM_8BIT|HAS_HWCKSM, 128, },
525 {"3c556 Laptop Tornado",
526 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_8BIT|HAS_CB_FNS|INVERT_MII_PWR|
527 HAS_HWCKSM, 128, },
528 {"3c556B Laptop Hurricane",
529 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_OFFSET|HAS_CB_FNS|INVERT_MII_PWR|
530 WNO_XCVR_PWR|HAS_HWCKSM, 128, },
531 {"3c575 [Megahertz] 10/100 LAN CardBus",
532 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
533
534 {"3c575 Boomerang CardBus",
535 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
536 {"3CCFE575BT Cyclone CardBus",
537 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|
538 INVERT_LED_PWR|HAS_HWCKSM, 128, },
539 {"3CCFE575CT Tornado CardBus",
540 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
541 MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
542 {"3CCFE656 Cyclone CardBus",
543 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
544 INVERT_LED_PWR|HAS_HWCKSM, 128, },
545 {"3CCFEM656B Cyclone+Winmodem CardBus",
546 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
547 INVERT_LED_PWR|HAS_HWCKSM, 128, },
548
549 {"3CXFEM656C Tornado+Winmodem CardBus",
550 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
551 MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
552 {"3c450 HomePNA Tornado",
553 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
554 {0,},
555};
556
557
558static struct pci_device_id vortex_pci_tbl[] __devinitdata = {
559 { 0x10B7, 0x5900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C590 },
560 { 0x10B7, 0x5920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C592 },
561 { 0x10B7, 0x5970, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C597 },
562 { 0x10B7, 0x5950, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_1 },
563 { 0x10B7, 0x5951, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_2 },
564
565 { 0x10B7, 0x5952, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_3 },
566 { 0x10B7, 0x9000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_1 },
567 { 0x10B7, 0x9001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_2 },
568 { 0x10B7, 0x9004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_3 },
569 { 0x10B7, 0x9005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_4 },
570
571 { 0x10B7, 0x9006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_5 },
572 { 0x10B7, 0x900A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900B_FL },
573 { 0x10B7, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_1 },
574 { 0x10B7, 0x9051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_2 },
575 { 0x10B7, 0x9055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_1 },
576
577 { 0x10B7, 0x9058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_2 },
578 { 0x10B7, 0x905A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_FX },
579 { 0x10B7, 0x9200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905C },
580 { 0x10B7, 0x9800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C980 },
581 { 0x10B7, 0x9805, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9805 },
582
583 { 0x10B7, 0x7646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CSOHO100_TX },
584 { 0x10B7, 0x5055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C555 },
585 { 0x10B7, 0x6055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556 },
586 { 0x10B7, 0x6056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556B },
587 { 0x10B7, 0x5b57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575 },
588
589 { 0x10B7, 0x5057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575_1 },
590 { 0x10B7, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575 },
591 { 0x10B7, 0x5257, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575CT },
592 { 0x10B7, 0x6560, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE656 },
593 { 0x10B7, 0x6562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656 },
594
595 { 0x10B7, 0x6564, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656_1 },
596 { 0x10B7, 0x4500, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C450 },
597 {0,}
598};
599MODULE_DEVICE_TABLE(pci, vortex_pci_tbl);
600
601
602
603
604
605
606
607
608
609#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
610#define EL3_CMD 0x0e
611#define EL3_STATUS 0x0e
612
613
614
615
616
617
618
619enum vortex_cmd {
620 TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
621 RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
622 UpStall = 6<<11, UpUnstall = (6<<11)+1,
623 DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
624 RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
625 FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
626 SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
627 SetTxThreshold = 18<<11, SetTxStart = 19<<11,
628 StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
629 StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11,};
630
631
632enum RxFilter {
633 RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
634
635
636enum vortex_status {
637 IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004,
638 TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
639 IntReq = 0x0040, StatsFull = 0x0080,
640 DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
641 DMAInProgress = 1<<11,
642 CmdInProgress = 1<<12,
643};
644
645
646
647enum Window1 {
648 TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
649 RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
650 TxFree = 0x1C,
651};
652enum Window0 {
653 Wn0EepromCmd = 10,
654 Wn0EepromData = 12,
655 IntrStatus=0x0E,
656};
657enum Win0_EEPROM_bits {
658 EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
659 EEPROM_EWENB = 0x30,
660 EEPROM_EWDIS = 0x00,
661};
662
663enum eeprom_offset {
664 PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
665 EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
666 NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
667 DriverTune=13, Checksum=15};
668
669enum Window2 {
670 Wn2_ResetOptions=12,
671};
672enum Window3 {
673 Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
674};
675
676#define BFEXT(value, offset, bitcount) \
677 ((((unsigned long)(value)) >> (offset)) & ((1 << (bitcount)) - 1))
678
679#define BFINS(lhs, rhs, offset, bitcount) \
680 (((lhs) & ~((((1 << (bitcount)) - 1)) << (offset))) | \
681 (((rhs) & ((1 << (bitcount)) - 1)) << (offset)))
682
683#define RAM_SIZE(v) BFEXT(v, 0, 3)
684#define RAM_WIDTH(v) BFEXT(v, 3, 1)
685#define RAM_SPEED(v) BFEXT(v, 4, 2)
686#define ROM_SIZE(v) BFEXT(v, 6, 2)
687#define RAM_SPLIT(v) BFEXT(v, 16, 2)
688#define XCVR(v) BFEXT(v, 20, 4)
689#define AUTOSELECT(v) BFEXT(v, 24, 1)
690
691enum Window4 {
692 Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
693};
694enum Win4_Media_bits {
695 Media_SQE = 0x0008,
696 Media_10TP = 0x00C0,
697 Media_Lnk = 0x0080,
698 Media_LnkBeat = 0x0800,
699};
700enum Window7 {
701 Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
702};
703
704enum MasterCtrl {
705 PktStatus = 0x20, DownListPtr = 0x24, FragAddr = 0x28, FragLen = 0x2c,
706 TxFreeThreshold = 0x2f, UpPktStatus = 0x30, UpListPtr = 0x38,
707};
708
709
710
711
712#define LAST_FRAG 0x80000000
713#define DN_COMPLETE 0x00010000
714struct boom_rx_desc {
715 u32 next;
716 s32 status;
717 u32 addr;
718 s32 length;
719};
720
721enum rx_desc_status {
722 RxDComplete=0x00008000, RxDError=0x4000,
723
724 IPChksumErr=1<<25, TCPChksumErr=1<<26, UDPChksumErr=1<<27,
725 IPChksumValid=1<<29, TCPChksumValid=1<<30, UDPChksumValid=1<<31,
726};
727
728#ifdef MAX_SKB_FRAGS
729#define DO_ZEROCOPY 1
730#else
731#define DO_ZEROCOPY 0
732#endif
733
734struct boom_tx_desc {
735 u32 next;
736 s32 status;
737#if DO_ZEROCOPY
738 struct {
739 u32 addr;
740 s32 length;
741 } frag[1+MAX_SKB_FRAGS];
742#else
743 u32 addr;
744 s32 length;
745#endif
746};
747
748
749enum tx_desc_status {
750 CRCDisable=0x2000, TxDComplete=0x8000,
751 AddIPChksum=0x02000000, AddTCPChksum=0x04000000, AddUDPChksum=0x08000000,
752 TxIntrUploaded=0x80000000,
753};
754
755
756enum ChipCaps { CapBusMaster=0x20, CapPwrMgmt=0x2000 };
757
758struct vortex_private {
759
760 struct boom_rx_desc* rx_ring;
761 struct boom_tx_desc* tx_ring;
762 dma_addr_t rx_ring_dma;
763 dma_addr_t tx_ring_dma;
764
765 struct sk_buff* rx_skbuff[RX_RING_SIZE];
766 struct sk_buff* tx_skbuff[TX_RING_SIZE];
767 struct net_device *next_module;
768 unsigned int cur_rx, cur_tx;
769 unsigned int dirty_rx, dirty_tx;
770 struct net_device_stats stats;
771 struct sk_buff *tx_skb;
772 dma_addr_t tx_skb_dma;
773
774
775 struct pci_dev *pdev;
776 char *cb_fn_base;
777
778
779 int rx_nocopy, rx_copy, queued_packet, rx_csumhits;
780 int card_idx;
781
782
783 struct timer_list timer;
784 struct timer_list rx_oom_timer;
785 int options;
786 unsigned int media_override:4,
787 default_media:4,
788 full_duplex:1, force_fd:1, autoselect:1,
789 bus_master:1,
790 full_bus_master_tx:1, full_bus_master_rx:2,
791 flow_ctrl:1,
792 partner_flow_ctrl:1,
793 has_nway:1,
794 enable_wol:1,
795 pm_state_valid:1,
796 open:1,
797 medialock:1,
798 must_free_region:1;
799 int drv_flags;
800 u16 status_enable;
801 u16 intr_enable;
802 u16 available_media;
803 u16 capabilities, info1, info2;
804 u16 advertising;
805 unsigned char phys[2];
806 u16 deferred;
807
808 u16 io_size;
809 spinlock_t lock;
810 spinlock_t mdio_lock;
811 u32 power_state[16];
812};
813
814
815
816
817enum xcvr_types {
818 XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
819 XCVR_100baseFx, XCVR_MII=6, XCVR_NWAY=8, XCVR_ExtMII=9, XCVR_Default=10,
820};
821
822static struct media_table {
823 char *name;
824 unsigned int media_bits:16,
825 mask:8,
826 next:8;
827 int wait;
828} media_tbl[] = {
829 { "10baseT", Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
830 { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
831 { "undefined", 0, 0x80, XCVR_10baseT, 10000},
832 { "10base2", 0, 0x10, XCVR_AUI, (1*HZ)/10},
833 { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
834 { "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14*HZ)/10},
835 { "MII", 0, 0x41, XCVR_10baseT, 3*HZ },
836 { "undefined", 0, 0x01, XCVR_10baseT, 10000},
837 { "Autonegotiate", 0, 0x41, XCVR_10baseT, 3*HZ},
838 { "MII-External", 0, 0x41, XCVR_10baseT, 3*HZ },
839 { "Default", 0, 0xFF, XCVR_10baseT, 10000},
840};
841
842static int vortex_probe1(struct pci_dev *pdev, long ioaddr, int irq,
843 int chip_idx, int card_idx);
844static void vortex_up(struct net_device *dev);
845static void vortex_down(struct net_device *dev);
846static int vortex_open(struct net_device *dev);
847static void mdio_sync(long ioaddr, int bits);
848static int mdio_read(struct net_device *dev, int phy_id, int location);
849static void mdio_write(struct net_device *vp, int phy_id, int location, int value);
850static void vortex_timer(unsigned long arg);
851static void rx_oom_timer(unsigned long arg);
852static int vortex_start_xmit(struct sk_buff *skb, struct net_device *dev);
853static int boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev);
854static int vortex_rx(struct net_device *dev);
855static int boomerang_rx(struct net_device *dev);
856static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs);
857static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs);
858static int vortex_close(struct net_device *dev);
859static void dump_tx_ring(struct net_device *dev);
860static void update_stats(long ioaddr, struct net_device *dev);
861static struct net_device_stats *vortex_get_stats(struct net_device *dev);
862static void set_rx_mode(struct net_device *dev);
863static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
864static void vortex_tx_timeout(struct net_device *dev);
865static void acpi_set_WOL(struct net_device *dev);
866
867
868
869#define MAX_UNITS 8
870static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1,};
871static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
872static int hw_checksums[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
873static int flow_ctrl[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
874static int enable_wol[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
875static int global_options = -1;
876static int global_full_duplex = -1;
877static int global_enable_wol = -1;
878
879
880
881
882static struct net_device *root_vortex_eisa_dev;
883
884
885static int compaq_ioaddr, compaq_irq, compaq_device_id = 0x5900;
886
887static int vortex_cards_found;
888
889#ifdef CONFIG_PM
890
891static int vortex_suspend (struct pci_dev *pdev, u32 state)
892{
893 struct net_device *dev = pci_get_drvdata(pdev);
894
895 if (dev && dev->priv) {
896 if (netif_running(dev)) {
897 netif_device_detach(dev);
898 vortex_down(dev);
899 }
900 }
901 return 0;
902}
903
904static int vortex_resume (struct pci_dev *pdev)
905{
906 struct net_device *dev = pci_get_drvdata(pdev);
907
908 if (dev && dev->priv) {
909 if (netif_running(dev)) {
910 vortex_up(dev);
911 netif_device_attach(dev);
912 }
913 }
914 return 0;
915}
916
917#endif
918
919
920static int __init vortex_eisa_init (void)
921{
922 long ioaddr;
923 int rc;
924 int orig_cards_found = vortex_cards_found;
925
926
927 if (!EISA_bus)
928 return 0;
929
930 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
931 int device_id;
932
933 if (request_region(ioaddr, VORTEX_TOTAL_SIZE, DRV_NAME) == NULL)
934 continue;
935
936
937 if (inw(ioaddr + 0xC80) != 0x6d50) {
938 release_region (ioaddr, VORTEX_TOTAL_SIZE);
939 continue;
940 }
941
942
943 device_id = (inb(ioaddr + 0xC82)<<8) + inb(ioaddr + 0xC83);
944 if ((device_id & 0xFF00) != 0x5900) {
945 release_region (ioaddr, VORTEX_TOTAL_SIZE);
946 continue;
947 }
948
949 rc = vortex_probe1(NULL, ioaddr, inw(ioaddr + 0xC88) >> 12,
950 EISA_TBL_OFFSET, vortex_cards_found);
951 if (rc == 0)
952 vortex_cards_found++;
953 else
954 release_region (ioaddr, VORTEX_TOTAL_SIZE);
955 }
956
957
958 if (compaq_ioaddr) {
959 vortex_probe1(NULL, compaq_ioaddr, compaq_irq,
960 compaq_device_id, vortex_cards_found++);
961 }
962
963 return vortex_cards_found - orig_cards_found;
964}
965
966
967static int __devinit vortex_init_one (struct pci_dev *pdev,
968 const struct pci_device_id *ent)
969{
970 int rc;
971
972
973 if (pci_enable_device (pdev)) {
974 rc = -EIO;
975 } else {
976 rc = vortex_probe1 (pdev, pci_resource_start (pdev, 0), pdev->irq,
977 ent->driver_data, vortex_cards_found);
978 if (rc == 0)
979 vortex_cards_found++;
980 }
981 return rc;
982}
983
984
985
986
987
988
989
990static int __devinit vortex_probe1(struct pci_dev *pdev,
991 long ioaddr, int irq,
992 int chip_idx, int card_idx)
993{
994 struct vortex_private *vp;
995 int option;
996 unsigned int eeprom[0x40], checksum = 0;
997 int i, step;
998 struct net_device *dev;
999 static int printed_version;
1000 int retval, print_info;
1001 struct vortex_chip_info * const vci = &vortex_info_tbl[chip_idx];
1002 char *print_name;
1003
1004 if (!printed_version) {
1005 printk (version);
1006 printed_version = 1;
1007 }
1008
1009 print_name = pdev ? pdev->slot_name : "3c59x";
1010
1011 dev = alloc_etherdev(sizeof(*vp));
1012 retval = -ENOMEM;
1013 if (!dev) {
1014 printk (KERN_ERR PFX "unable to allocate etherdev, aborting\n");
1015 goto out;
1016 }
1017 SET_MODULE_OWNER(dev);
1018 vp = dev->priv;
1019
1020 option = global_options;
1021
1022
1023 if (dev->mem_start) {
1024
1025
1026
1027
1028 option = dev->mem_start;
1029 }
1030 else if (card_idx < MAX_UNITS) {
1031 if (options[card_idx] >= 0)
1032 option = options[card_idx];
1033 }
1034
1035 if (option > 0) {
1036 if (option & 0x8000)
1037 vortex_debug = 7;
1038 if (option & 0x4000)
1039 vortex_debug = 2;
1040 if (option & 0x0400)
1041 vp->enable_wol = 1;
1042 }
1043
1044 print_info = (vortex_debug > 1);
1045 if (print_info)
1046 printk (KERN_INFO "See Documentation/networking/vortex.txt\n");
1047
1048 printk(KERN_INFO "%s: 3Com %s %s at 0x%lx. Vers " DRV_VERSION "\n",
1049 print_name,
1050 pdev ? "PCI" : "EISA",
1051 vci->name,
1052 ioaddr);
1053
1054 dev->base_addr = ioaddr;
1055 dev->irq = irq;
1056 dev->mtu = mtu;
1057 vp->drv_flags = vci->drv_flags;
1058 vp->has_nway = (vci->drv_flags & HAS_NWAY) ? 1 : 0;
1059 vp->io_size = vci->io_size;
1060 vp->card_idx = card_idx;
1061
1062
1063 if (pdev == NULL) {
1064 vp->next_module = root_vortex_eisa_dev;
1065 root_vortex_eisa_dev = dev;
1066 }
1067
1068
1069 if (pdev) {
1070
1071
1072 if (request_region(ioaddr, vci->io_size, print_name) != NULL)
1073 vp->must_free_region = 1;
1074
1075
1076 if (vci->flags & PCI_USES_MASTER)
1077 pci_set_master (pdev);
1078
1079 if (vci->drv_flags & IS_VORTEX) {
1080 u8 pci_latency;
1081 u8 new_latency = 248;
1082
1083
1084
1085
1086
1087 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
1088 if (pci_latency < new_latency) {
1089 printk(KERN_INFO "%s: Overriding PCI latency"
1090 " timer (CFLT) setting of %d, new value is %d.\n",
1091 print_name, pci_latency, new_latency);
1092 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, new_latency);
1093 }
1094 }
1095 }
1096
1097 spin_lock_init(&vp->lock);
1098 spin_lock_init(&vp->mdio_lock);
1099 vp->pdev = pdev;
1100
1101
1102 vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
1103 + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
1104 &vp->rx_ring_dma);
1105 retval = -ENOMEM;
1106 if (vp->rx_ring == 0)
1107 goto free_region;
1108
1109 vp->tx_ring = (struct boom_tx_desc *)(vp->rx_ring + RX_RING_SIZE);
1110 vp->tx_ring_dma = vp->rx_ring_dma + sizeof(struct boom_rx_desc) * RX_RING_SIZE;
1111
1112
1113
1114 if (pdev)
1115 pci_set_drvdata(pdev, dev);
1116
1117 vp->media_override = 7;
1118 if (option >= 0) {
1119 vp->media_override = ((option & 7) == 2) ? 0 : option & 15;
1120 if (vp->media_override != 7)
1121 vp->medialock = 1;
1122 vp->full_duplex = (option & 0x200) ? 1 : 0;
1123 vp->bus_master = (option & 16) ? 1 : 0;
1124 }
1125
1126 if (global_full_duplex > 0)
1127 vp->full_duplex = 1;
1128 if (global_enable_wol > 0)
1129 vp->enable_wol = 1;
1130
1131 if (card_idx < MAX_UNITS) {
1132 if (full_duplex[card_idx] > 0)
1133 vp->full_duplex = 1;
1134 if (flow_ctrl[card_idx] > 0)
1135 vp->flow_ctrl = 1;
1136 if (enable_wol[card_idx] > 0)
1137 vp->enable_wol = 1;
1138 }
1139
1140 vp->force_fd = vp->full_duplex;
1141 vp->options = option;
1142
1143 EL3WINDOW(0);
1144 {
1145 int base;
1146
1147 if (vci->drv_flags & EEPROM_8BIT)
1148 base = 0x230;
1149 else if (vci->drv_flags & EEPROM_OFFSET)
1150 base = EEPROM_Read + 0x30;
1151 else
1152 base = EEPROM_Read;
1153
1154 for (i = 0; i < 0x40; i++) {
1155 int timer;
1156 outw(base + i, ioaddr + Wn0EepromCmd);
1157
1158 for (timer = 10; timer >= 0; timer--) {
1159 udelay(162);
1160 if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
1161 break;
1162 }
1163 eeprom[i] = inw(ioaddr + Wn0EepromData);
1164 }
1165 }
1166 for (i = 0; i < 0x18; i++)
1167 checksum ^= eeprom[i];
1168 checksum = (checksum ^ (checksum >> 8)) & 0xff;
1169 if (checksum != 0x00) {
1170 while (i < 0x21)
1171 checksum ^= eeprom[i++];
1172 checksum = (checksum ^ (checksum >> 8)) & 0xff;
1173 }
1174 if ((checksum != 0x00) && !(vci->drv_flags & IS_TORNADO))
1175 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
1176 for (i = 0; i < 3; i++)
1177 ((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
1178 if (print_info) {
1179 for (i = 0; i < 6; i++)
1180 printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
1181 }
1182 EL3WINDOW(2);
1183 for (i = 0; i < 6; i++)
1184 outb(dev->dev_addr[i], ioaddr + i);
1185
1186#ifdef __sparc__
1187 if (print_info)
1188 printk(", IRQ %s\n", __irq_itoa(dev->irq));
1189#else
1190 if (print_info)
1191 printk(", IRQ %d\n", dev->irq);
1192
1193 if (dev->irq <= 0 || dev->irq >= NR_IRQS)
1194 printk(KERN_WARNING " *** Warning: IRQ %d is unlikely to work! ***\n",
1195 dev->irq);
1196#endif
1197
1198 EL3WINDOW(4);
1199 step = (inb(ioaddr + Wn4_NetDiag) & 0x1e) >> 1;
1200 if (print_info) {
1201 printk(KERN_INFO " product code %02x%02x rev %02x.%d date %02d-"
1202 "%02d-%02d\n", eeprom[6]&0xff, eeprom[6]>>8, eeprom[0x14],
1203 step, (eeprom[4]>>5) & 15, eeprom[4] & 31, eeprom[4]>>9);
1204 }
1205
1206
1207 if (pdev && vci->drv_flags & HAS_CB_FNS) {
1208 unsigned long fn_st_addr;
1209 unsigned short n;
1210
1211 fn_st_addr = pci_resource_start (pdev, 2);
1212 if (fn_st_addr) {
1213 vp->cb_fn_base = ioremap(fn_st_addr, 128);
1214 retval = -ENOMEM;
1215 if (!vp->cb_fn_base)
1216 goto free_ring;
1217 }
1218 if (print_info) {
1219 printk(KERN_INFO "%s: CardBus functions mapped %8.8lx->%p\n",
1220 print_name, fn_st_addr, vp->cb_fn_base);
1221 }
1222 EL3WINDOW(2);
1223
1224 n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010;
1225 if (vp->drv_flags & INVERT_LED_PWR)
1226 n |= 0x10;
1227 if (vp->drv_flags & INVERT_MII_PWR)
1228 n |= 0x4000;
1229 outw(n, ioaddr + Wn2_ResetOptions);
1230 if (vp->drv_flags & WNO_XCVR_PWR) {
1231 EL3WINDOW(0);
1232 outw(0x0800, ioaddr);
1233 }
1234 }
1235
1236
1237 vp->info1 = eeprom[13];
1238 vp->info2 = eeprom[15];
1239 vp->capabilities = eeprom[16];
1240
1241 if (vp->info1 & 0x8000) {
1242 vp->full_duplex = 1;
1243 if (print_info)
1244 printk(KERN_INFO "Full duplex capable\n");
1245 }
1246
1247 {
1248 static const char * ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
1249 unsigned int config;
1250 EL3WINDOW(3);
1251 vp->available_media = inw(ioaddr + Wn3_Options);
1252 if ((vp->available_media & 0xff) == 0)
1253 vp->available_media = 0x40;
1254 config = inl(ioaddr + Wn3_Config);
1255 if (print_info) {
1256 printk(KERN_DEBUG " Internal config register is %4.4x, "
1257 "transceivers %#x.\n", config, inw(ioaddr + Wn3_Options));
1258 printk(KERN_INFO " %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
1259 8 << RAM_SIZE(config),
1260 RAM_WIDTH(config) ? "word" : "byte",
1261 ram_split[RAM_SPLIT(config)],
1262 AUTOSELECT(config) ? "autoselect/" : "",
1263 XCVR(config) > XCVR_ExtMII ? "<invalid transceiver>" :
1264 media_tbl[XCVR(config)].name);
1265 }
1266 vp->default_media = XCVR(config);
1267 if (vp->default_media == XCVR_NWAY)
1268 vp->has_nway = 1;
1269 vp->autoselect = AUTOSELECT(config);
1270 }
1271
1272 if (vp->media_override != 7) {
1273 printk(KERN_INFO "%s: Media override to transceiver type %d (%s).\n",
1274 print_name, vp->media_override,
1275 media_tbl[vp->media_override].name);
1276 dev->if_port = vp->media_override;
1277 } else
1278 dev->if_port = vp->default_media;
1279
1280 if ((vp->available_media & 0x4b) || (vci->drv_flags & HAS_NWAY) ||
1281 dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1282 int phy, phy_idx = 0;
1283 EL3WINDOW(4);
1284 mii_preamble_required++;
1285 if (vp->drv_flags & EXTRA_PREAMBLE)
1286 mii_preamble_required++;
1287 mdio_sync(ioaddr, 32);
1288 mdio_read(dev, 24, 1);
1289 for (phy = 0; phy < 32 && phy_idx < 1; phy++) {
1290 int mii_status, phyx;
1291
1292
1293
1294
1295
1296 if (phy == 0)
1297 phyx = 24;
1298 else if (phy <= 24)
1299 phyx = phy - 1;
1300 else
1301 phyx = phy;
1302 mii_status = mdio_read(dev, phyx, 1);
1303 printk("phy=%d, phyx=%d, mii_status=0x%04x\n",
1304 phy, phyx, mii_status);
1305 if (mii_status && mii_status != 0xffff) {
1306 vp->phys[phy_idx++] = phyx;
1307 if (print_info) {
1308 printk(KERN_INFO " MII transceiver found at address %d,"
1309 " status %4x.\n", phyx, mii_status);
1310 }
1311 if ((mii_status & 0x0040) == 0)
1312 mii_preamble_required++;
1313 }
1314 }
1315 mii_preamble_required--;
1316 if (phy_idx == 0) {
1317 printk(KERN_WARNING" ***WARNING*** No MII transceivers found!\n");
1318 vp->phys[0] = 24;
1319 } else {
1320 vp->advertising = mdio_read(dev, vp->phys[0], 4);
1321 if (vp->full_duplex) {
1322
1323 vp->advertising &= ~0x02A0;
1324 mdio_write(dev, vp->phys[0], 4, vp->advertising);
1325 }
1326 }
1327 }
1328
1329 if (vp->capabilities & CapBusMaster) {
1330 vp->full_bus_master_tx = 1;
1331 if (print_info) {
1332 printk(KERN_INFO " Enabling bus-master transmits and %s receives.\n",
1333 (vp->info2 & 1) ? "early" : "whole-frame" );
1334 }
1335 vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;
1336 vp->bus_master = 0;
1337 }
1338
1339
1340 dev->open = vortex_open;
1341 if (vp->full_bus_master_tx) {
1342 dev->hard_start_xmit = boomerang_start_xmit;
1343
1344 dev->features |= NETIF_F_SG;
1345 if (((hw_checksums[card_idx] == -1) && (vp->drv_flags & HAS_HWCKSM)) ||
1346 (hw_checksums[card_idx] == 1)) {
1347 dev->features |= NETIF_F_IP_CSUM;
1348 }
1349 } else {
1350 dev->hard_start_xmit = vortex_start_xmit;
1351 }
1352
1353 if (print_info) {
1354 printk(KERN_INFO "%s: scatter/gather %sabled. h/w checksums %sabled\n",
1355 print_name,
1356 (dev->features & NETIF_F_SG) ? "en":"dis",
1357 (dev->features & NETIF_F_IP_CSUM) ? "en":"dis");
1358 }
1359
1360 dev->stop = vortex_close;
1361 dev->get_stats = vortex_get_stats;
1362 dev->do_ioctl = vortex_ioctl;
1363 dev->set_multicast_list = set_rx_mode;
1364 dev->tx_timeout = vortex_tx_timeout;
1365 dev->watchdog_timeo = (watchdog * HZ) / 1000;
1366 if (pdev && vp->enable_wol) {
1367 vp->pm_state_valid = 1;
1368 pci_save_state(vp->pdev, vp->power_state);
1369 acpi_set_WOL(dev);
1370 }
1371 retval = register_netdev(dev);
1372 if (retval == 0)
1373 return 0;
1374
1375free_ring:
1376 pci_free_consistent(pdev,
1377 sizeof(struct boom_rx_desc) * RX_RING_SIZE
1378 + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
1379 vp->rx_ring,
1380 vp->rx_ring_dma);
1381free_region:
1382 if (vp->must_free_region)
1383 release_region(ioaddr, vci->io_size);
1384 kfree (dev);
1385 printk(KERN_ERR PFX "vortex_probe1 fails. Returns %d\n", retval);
1386out:
1387 return retval;
1388}
1389
1390static void
1391issue_and_wait(struct net_device *dev, int cmd)
1392{
1393 int i;
1394
1395 outw(cmd, dev->base_addr + EL3_CMD);
1396 for (i = 0; i < 2000; i++) {
1397 if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress))
1398 return;
1399 }
1400
1401
1402 for (i = 0; i < 100000; i++) {
1403 if (!(inw(dev->base_addr + EL3_STATUS) & CmdInProgress)) {
1404 if (vortex_debug > 1)
1405 printk(KERN_INFO "%s: command 0x%04x took %d usecs\n",
1406 dev->name, cmd, i * 10);
1407 return;
1408 }
1409 udelay(10);
1410 }
1411 printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n",
1412 dev->name, cmd, inw(dev->base_addr + EL3_STATUS));
1413}
1414
1415static void
1416vortex_up(struct net_device *dev)
1417{
1418 long ioaddr = dev->base_addr;
1419 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1420 unsigned int config;
1421 int i;
1422
1423 if (vp->pdev && vp->enable_wol) {
1424 pci_set_power_state(vp->pdev, 0);
1425 pci_restore_state(vp->pdev, vp->power_state);
1426 }
1427
1428
1429 EL3WINDOW(3);
1430 config = inl(ioaddr + Wn3_Config);
1431
1432 if (vp->media_override != 7) {
1433 printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
1434 dev->name, vp->media_override,
1435 media_tbl[vp->media_override].name);
1436 dev->if_port = vp->media_override;
1437 } else if (vp->autoselect) {
1438 if (vp->has_nway) {
1439 if (vortex_debug > 1)
1440 printk(KERN_INFO "%s: using NWAY device table, not %d\n",
1441 dev->name, dev->if_port);
1442 dev->if_port = XCVR_NWAY;
1443 } else {
1444
1445 dev->if_port = XCVR_100baseTx;
1446 while (! (vp->available_media & media_tbl[dev->if_port].mask))
1447 dev->if_port = media_tbl[dev->if_port].next;
1448 if (vortex_debug > 1)
1449 printk(KERN_INFO "%s: first available media type: %s\n",
1450 dev->name, media_tbl[dev->if_port].name);
1451 }
1452 } else {
1453 dev->if_port = vp->default_media;
1454 if (vortex_debug > 1)
1455 printk(KERN_INFO "%s: using default media %s\n",
1456 dev->name, media_tbl[dev->if_port].name);
1457 }
1458
1459 init_timer(&vp->timer);
1460 vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
1461 vp->timer.data = (unsigned long)dev;
1462 vp->timer.function = vortex_timer;
1463 add_timer(&vp->timer);
1464
1465 init_timer(&vp->rx_oom_timer);
1466 vp->rx_oom_timer.data = (unsigned long)dev;
1467 vp->rx_oom_timer.function = rx_oom_timer;
1468
1469 if (vortex_debug > 1)
1470 printk(KERN_DEBUG "%s: Initial media type %s.\n",
1471 dev->name, media_tbl[dev->if_port].name);
1472
1473 vp->full_duplex = vp->force_fd;
1474 config = BFINS(config, dev->if_port, 20, 4);
1475 if (vortex_debug > 6)
1476 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config);
1477 outl(config, ioaddr + Wn3_Config);
1478
1479 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1480 int mii_reg1, mii_reg5;
1481 EL3WINDOW(4);
1482
1483 mii_reg1 = mdio_read(dev, vp->phys[0], 1);
1484 mii_reg5 = mdio_read(dev, vp->phys[0], 5);
1485 if (mii_reg5 == 0xffff || mii_reg5 == 0x0000) {
1486 netif_carrier_off(dev);
1487 } else {
1488 mii_reg5 &= vp->advertising;
1489 if ((mii_reg5 & 0x0100) != 0
1490 || (mii_reg5 & 0x00C0) == 0x0040)
1491 vp->full_duplex = 1;
1492 netif_carrier_on(dev);
1493 }
1494 vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
1495 if (vortex_debug > 1)
1496 printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
1497 " info1 %04x, setting %s-duplex.\n",
1498 dev->name, vp->phys[0],
1499 mii_reg1, mii_reg5,
1500 vp->info1, ((vp->info1 & 0x8000) || vp->full_duplex) ? "full" : "half");
1501 EL3WINDOW(3);
1502 }
1503
1504
1505 outw( ((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
1506 (dev->mtu > 1500 ? 0x40 : 0) |
1507 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1508 ioaddr + Wn3_MAC_Ctrl);
1509
1510 if (vortex_debug > 1) {
1511 printk(KERN_DEBUG "%s: vortex_up() InternalConfig %8.8x.\n",
1512 dev->name, config);
1513 }
1514
1515 issue_and_wait(dev, TxReset);
1516
1517
1518
1519 issue_and_wait(dev, RxReset|0x04);
1520
1521 outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
1522
1523 if (vortex_debug > 1) {
1524 EL3WINDOW(4);
1525 printk(KERN_DEBUG "%s: vortex_up() irq %d media status %4.4x.\n",
1526 dev->name, dev->irq, inw(ioaddr + Wn4_Media));
1527 }
1528
1529
1530 EL3WINDOW(2);
1531 for (i = 0; i < 6; i++)
1532 outb(dev->dev_addr[i], ioaddr + i);
1533 for (; i < 12; i+=2)
1534 outw(0, ioaddr + i);
1535
1536 if (vp->cb_fn_base) {
1537 unsigned short n = inw(ioaddr + Wn2_ResetOptions) & ~0x4010;
1538 if (vp->drv_flags & INVERT_LED_PWR)
1539 n |= 0x10;
1540 if (vp->drv_flags & INVERT_MII_PWR)
1541 n |= 0x4000;
1542 outw(n, ioaddr + Wn2_ResetOptions);
1543 }
1544
1545 if (dev->if_port == XCVR_10base2)
1546
1547 outw(StartCoax, ioaddr + EL3_CMD);
1548 if (dev->if_port != XCVR_NWAY) {
1549 EL3WINDOW(4);
1550 outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
1551 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1552 }
1553
1554
1555 outw(StatsDisable, ioaddr + EL3_CMD);
1556 EL3WINDOW(6);
1557 for (i = 0; i < 10; i++)
1558 inb(ioaddr + i);
1559 inw(ioaddr + 10);
1560 inw(ioaddr + 12);
1561
1562 EL3WINDOW(4);
1563 inb(ioaddr + 12);
1564
1565 outw(0x0040, ioaddr + Wn4_NetDiag);
1566
1567
1568 EL3WINDOW(7);
1569
1570 if (vp->full_bus_master_rx) {
1571 vp->cur_rx = vp->dirty_rx = 0;
1572
1573 outw(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
1574 outl(0x0020, ioaddr + PktStatus);
1575 outl(vp->rx_ring_dma, ioaddr + UpListPtr);
1576 }
1577 if (vp->full_bus_master_tx) {
1578 vp->cur_tx = vp->dirty_tx = 0;
1579 if (vp->drv_flags & IS_BOOMERANG)
1580 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
1581
1582 for (i = 0; i < RX_RING_SIZE; i++)
1583 vp->rx_ring[i].status = 0;
1584 for (i = 0; i < TX_RING_SIZE; i++)
1585 vp->tx_skbuff[i] = 0;
1586 outl(0, ioaddr + DownListPtr);
1587 }
1588
1589 set_rx_mode(dev);
1590 outw(StatsEnable, ioaddr + EL3_CMD);
1591
1592
1593 outw(RxEnable, ioaddr + EL3_CMD);
1594 outw(TxEnable, ioaddr + EL3_CMD);
1595
1596 vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
1597 (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
1598 (vp->full_bus_master_rx ? UpComplete : RxComplete) |
1599 (vp->bus_master ? DMADone : 0);
1600 vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable |
1601 (vp->full_bus_master_rx ? 0 : RxComplete) |
1602 StatsFull | HostError | TxComplete | IntReq
1603 | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
1604 outw(vp->status_enable, ioaddr + EL3_CMD);
1605
1606 outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
1607 ioaddr + EL3_CMD);
1608 outw(vp->intr_enable, ioaddr + EL3_CMD);
1609 if (vp->cb_fn_base)
1610 writel(0x8000, vp->cb_fn_base + 4);
1611 netif_start_queue (dev);
1612}
1613
1614static int
1615vortex_open(struct net_device *dev)
1616{
1617 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1618 int i;
1619 int retval;
1620
1621
1622 if ((retval = request_irq(dev->irq, vp->full_bus_master_rx ?
1623 &boomerang_interrupt : &vortex_interrupt, SA_SHIRQ, dev->name, dev))) {
1624 printk(KERN_ERR "%s: Could not reserve IRQ %d\n", dev->name, dev->irq);
1625 goto out;
1626 }
1627
1628 if (vp->full_bus_master_rx) {
1629 if (vortex_debug > 2)
1630 printk(KERN_DEBUG "%s: Filling in the Rx ring.\n", dev->name);
1631 for (i = 0; i < RX_RING_SIZE; i++) {
1632 struct sk_buff *skb;
1633 vp->rx_ring[i].next = cpu_to_le32(vp->rx_ring_dma + sizeof(struct boom_rx_desc) * (i+1));
1634 vp->rx_ring[i].status = 0;
1635 vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);
1636 skb = dev_alloc_skb(PKT_BUF_SZ);
1637 vp->rx_skbuff[i] = skb;
1638 if (skb == NULL)
1639 break;
1640 skb->dev = dev;
1641 skb_reserve(skb, 2);
1642 vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
1643 }
1644 if (i != RX_RING_SIZE) {
1645 int j;
1646 printk(KERN_EMERG "%s: no memory for rx ring\n", dev->name);
1647 for (j = 0; j < i; j++) {
1648 if (vp->rx_skbuff[j]) {
1649 dev_kfree_skb(vp->rx_skbuff[j]);
1650 vp->rx_skbuff[j] = 0;
1651 }
1652 }
1653 retval = -ENOMEM;
1654 goto out_free_irq;
1655 }
1656
1657 vp->rx_ring[i-1].next = cpu_to_le32(vp->rx_ring_dma);
1658 }
1659
1660 vortex_up(dev);
1661 return 0;
1662
1663out_free_irq:
1664 free_irq(dev->irq, dev);
1665out:
1666 if (vortex_debug > 1)
1667 printk(KERN_ERR "%s: vortex_open() fails: returning %d\n", dev->name, retval);
1668 return retval;
1669}
1670
1671static void
1672vortex_timer(unsigned long data)
1673{
1674 struct net_device *dev = (struct net_device *)data;
1675 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1676 long ioaddr = dev->base_addr;
1677 int next_tick = 60*HZ;
1678 int ok = 0;
1679 int media_status, mii_status, old_window;
1680
1681 if (vortex_debug > 2) {
1682 printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",
1683 dev->name, media_tbl[dev->if_port].name);
1684 printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo);
1685 }
1686
1687 if (vp->medialock)
1688 goto leave_media_alone;
1689 disable_irq(dev->irq);
1690 old_window = inw(ioaddr + EL3_CMD) >> 13;
1691 EL3WINDOW(4);
1692 media_status = inw(ioaddr + Wn4_Media);
1693 switch (dev->if_port) {
1694 case XCVR_10baseT: case XCVR_100baseTx: case XCVR_100baseFx:
1695 if (media_status & Media_LnkBeat) {
1696 netif_carrier_on(dev);
1697 ok = 1;
1698 if (vortex_debug > 1)
1699 printk(KERN_DEBUG "%s: Media %s has link beat, %x.\n",
1700 dev->name, media_tbl[dev->if_port].name, media_status);
1701 } else if (vortex_debug > 1) {
1702 netif_carrier_off(dev);
1703 printk(KERN_DEBUG "%s: Media %s has no link beat, %x.\n",
1704 dev->name, media_tbl[dev->if_port].name, media_status);
1705 }
1706 break;
1707 case XCVR_MII: case XCVR_NWAY:
1708 {
1709 mii_status = mdio_read(dev, vp->phys[0], 1);
1710 ok = 1;
1711 if (vortex_debug > 2)
1712 printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",
1713 dev->name, mii_status);
1714 if (mii_status & BMSR_LSTATUS) {
1715 int mii_reg5 = mdio_read(dev, vp->phys[0], 5);
1716 if (! vp->force_fd && mii_reg5 != 0xffff) {
1717 int duplex;
1718
1719 mii_reg5 &= vp->advertising;
1720 duplex = (mii_reg5&0x0100) || (mii_reg5 & 0x01C0) == 0x0040;
1721 if (vp->full_duplex != duplex) {
1722 vp->full_duplex = duplex;
1723 printk(KERN_INFO "%s: Setting %s-duplex based on MII "
1724 "#%d link partner capability of %4.4x.\n",
1725 dev->name, vp->full_duplex ? "full" : "half",
1726 vp->phys[0], mii_reg5);
1727
1728 EL3WINDOW(3);
1729 outw( (vp->full_duplex ? 0x20 : 0) |
1730 (dev->mtu > 1500 ? 0x40 : 0) |
1731 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 0x100 : 0),
1732 ioaddr + Wn3_MAC_Ctrl);
1733 if (vortex_debug > 1)
1734 printk(KERN_DEBUG "Setting duplex in Wn3_MAC_Ctrl\n");
1735
1736 }
1737 }
1738 netif_carrier_on(dev);
1739 } else {
1740 netif_carrier_off(dev);
1741 }
1742 }
1743 break;
1744 default:
1745 if (vortex_debug > 1)
1746 printk(KERN_DEBUG "%s: Media %s has no indication, %x.\n",
1747 dev->name, media_tbl[dev->if_port].name, media_status);
1748 ok = 1;
1749 }
1750 if ( ! ok) {
1751 unsigned int config;
1752
1753 do {
1754 dev->if_port = media_tbl[dev->if_port].next;
1755 } while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
1756 if (dev->if_port == XCVR_Default) {
1757 dev->if_port = vp->default_media;
1758 if (vortex_debug > 1)
1759 printk(KERN_DEBUG "%s: Media selection failing, using default "
1760 "%s port.\n",
1761 dev->name, media_tbl[dev->if_port].name);
1762 } else {
1763 if (vortex_debug > 1)
1764 printk(KERN_DEBUG "%s: Media selection failed, now trying "
1765 "%s port.\n",
1766 dev->name, media_tbl[dev->if_port].name);
1767 next_tick = media_tbl[dev->if_port].wait;
1768 }
1769 outw((media_status & ~(Media_10TP|Media_SQE)) |
1770 media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
1771
1772 EL3WINDOW(3);
1773 config = inl(ioaddr + Wn3_Config);
1774 config = BFINS(config, dev->if_port, 20, 4);
1775 outl(config, ioaddr + Wn3_Config);
1776
1777 outw(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
1778 ioaddr + EL3_CMD);
1779 if (vortex_debug > 1)
1780 printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config);
1781
1782 }
1783 EL3WINDOW(old_window);
1784 enable_irq(dev->irq);
1785
1786leave_media_alone:
1787 if (vortex_debug > 2)
1788 printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n",
1789 dev->name, media_tbl[dev->if_port].name);
1790
1791 mod_timer(&vp->timer, RUN_AT(next_tick));
1792 if (vp->deferred)
1793 outw(FakeIntr, ioaddr + EL3_CMD);
1794 return;
1795}
1796
1797static void vortex_tx_timeout(struct net_device *dev)
1798{
1799 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1800 long ioaddr = dev->base_addr;
1801
1802 printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
1803 dev->name, inb(ioaddr + TxStatus),
1804 inw(ioaddr + EL3_STATUS));
1805 EL3WINDOW(4);
1806 printk(KERN_ERR " diagnostics: net %04x media %04x dma %08x fifo %04x\n",
1807 inw(ioaddr + Wn4_NetDiag),
1808 inw(ioaddr + Wn4_Media),
1809 inl(ioaddr + PktStatus),
1810 inw(ioaddr + Wn4_FIFODiag));
1811
1812 if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
1813 printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
1814 " network cable problem?\n", dev->name);
1815 if (inw(ioaddr + EL3_STATUS) & IntLatch) {
1816 printk(KERN_ERR "%s: Interrupt posted but not delivered --"
1817 " IRQ blocked by another device?\n", dev->name);
1818
1819 {
1820
1821
1822
1823 unsigned long flags;
1824 local_irq_save(flags);
1825 if (vp->full_bus_master_tx)
1826 boomerang_interrupt(dev->irq, dev, 0);
1827 else
1828 vortex_interrupt(dev->irq, dev, 0);
1829 local_irq_restore(flags);
1830 }
1831 }
1832
1833 if (vortex_debug > 0)
1834 dump_tx_ring(dev);
1835
1836 issue_and_wait(dev, TxReset);
1837
1838 vp->stats.tx_errors++;
1839 if (vp->full_bus_master_tx) {
1840 printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n", dev->name);
1841 if (vp->cur_tx - vp->dirty_tx > 0 && inl(ioaddr + DownListPtr) == 0)
1842 outl(vp->tx_ring_dma + (vp->dirty_tx % TX_RING_SIZE) * sizeof(struct boom_tx_desc),
1843 ioaddr + DownListPtr);
1844 if (vp->cur_tx - vp->dirty_tx < TX_RING_SIZE)
1845 netif_wake_queue (dev);
1846 if (vp->drv_flags & IS_BOOMERANG)
1847 outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
1848 outw(DownUnstall, ioaddr + EL3_CMD);
1849 } else {
1850 vp->stats.tx_dropped++;
1851 netif_wake_queue(dev);
1852 }
1853
1854
1855 outw(TxEnable, ioaddr + EL3_CMD);
1856 dev->trans_start = jiffies;
1857
1858
1859 EL3WINDOW(7);
1860}
1861
1862
1863
1864
1865
1866static void
1867vortex_error(struct net_device *dev, int status)
1868{
1869 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1870 long ioaddr = dev->base_addr;
1871 int do_tx_reset = 0, reset_mask = 0;
1872 unsigned char tx_status = 0;
1873
1874 if (vortex_debug > 2) {
1875 printk(KERN_ERR "%s: vortex_error(), status=0x%x\n", dev->name, status);
1876 }
1877
1878 if (status & TxComplete) {
1879 tx_status = inb(ioaddr + TxStatus);
1880
1881 if (vortex_debug > 2
1882 || (tx_status != 0x88 && vortex_debug > 0)) {
1883 printk(KERN_ERR "%s: Transmit error, Tx status register %2.2x.\n",
1884 dev->name, tx_status);
1885 if (tx_status == 0x82) {
1886 printk(KERN_ERR "Probably a duplex mismatch. See "
1887 "Documentation/networking/vortex.txt\n");
1888 }
1889 dump_tx_ring(dev);
1890 }
1891 if (tx_status & 0x14) vp->stats.tx_fifo_errors++;
1892 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
1893 outb(0, ioaddr + TxStatus);
1894 if (tx_status & 0x30) {
1895 do_tx_reset = 1;
1896 } else if ((tx_status & 0x08) && (vp->drv_flags & MAX_COLLISION_RESET)) {
1897 do_tx_reset = 1;
1898 reset_mask = 0x0108;
1899 } else {
1900 outw(TxEnable, ioaddr + EL3_CMD);
1901 }
1902 }
1903
1904 if (status & RxEarly) {
1905 vortex_rx(dev);
1906 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
1907 }
1908 if (status & StatsFull) {
1909 static int DoneDidThat;
1910 if (vortex_debug > 4)
1911 printk(KERN_DEBUG "%s: Updating stats.\n", dev->name);
1912 update_stats(ioaddr, dev);
1913
1914
1915 if (DoneDidThat == 0 &&
1916 inw(ioaddr + EL3_STATUS) & StatsFull) {
1917 printk(KERN_WARNING "%s: Updating statistics failed, disabling "
1918 "stats as an interrupt source.\n", dev->name);
1919 EL3WINDOW(5);
1920 outw(SetIntrEnb | (inw(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD);
1921 vp->intr_enable &= ~StatsFull;
1922 EL3WINDOW(7);
1923 DoneDidThat++;
1924 }
1925 }
1926 if (status & IntReq) {
1927 outw(vp->status_enable, ioaddr + EL3_CMD);
1928 outw(vp->intr_enable, ioaddr + EL3_CMD);
1929 }
1930 if (status & HostError) {
1931 u16 fifo_diag;
1932 EL3WINDOW(4);
1933 fifo_diag = inw(ioaddr + Wn4_FIFODiag);
1934 printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n",
1935 dev->name, fifo_diag);
1936
1937 if (vp->full_bus_master_tx) {
1938 int bus_status = inl(ioaddr + PktStatus);
1939
1940
1941 if (vortex_debug)
1942 printk(KERN_ERR "%s: PCI bus error, bus status %8.8x\n", dev->name, bus_status);
1943
1944
1945 vortex_down(dev);
1946 issue_and_wait(dev, TotalReset | 0xff);
1947 vortex_up(dev);
1948 } else if (fifo_diag & 0x0400)
1949 do_tx_reset = 1;
1950 if (fifo_diag & 0x3000) {
1951
1952 issue_and_wait(dev, RxReset|0x07);
1953
1954 set_rx_mode(dev);
1955 outw(RxEnable, ioaddr + EL3_CMD);
1956 outw(AckIntr | HostError, ioaddr + EL3_CMD);
1957 }
1958 }
1959
1960 if (do_tx_reset) {
1961 issue_and_wait(dev, TxReset|reset_mask);
1962 outw(TxEnable, ioaddr + EL3_CMD);
1963 if (!vp->full_bus_master_tx)
1964 netif_wake_queue(dev);
1965 }
1966}
1967
1968static int
1969vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
1970{
1971 struct vortex_private *vp = (struct vortex_private *)dev->priv;
1972 long ioaddr = dev->base_addr;
1973
1974
1975 outl(skb->len, ioaddr + TX_FIFO);
1976 if (vp->bus_master) {
1977
1978 int len = (skb->len + 3) & ~3;
1979 outl( vp->tx_skb_dma = pci_map_single(vp->pdev, skb->data, len, PCI_DMA_TODEVICE),
1980 ioaddr + Wn7_MasterAddr);
1981 outw(len, ioaddr + Wn7_MasterLen);
1982 vp->tx_skb = skb;
1983 outw(StartDMADown, ioaddr + EL3_CMD);
1984
1985 } else {
1986
1987 outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
1988 dev_kfree_skb (skb);
1989 if (inw(ioaddr + TxFree) > 1536) {
1990 netif_start_queue (dev);
1991 } else {
1992
1993 netif_stop_queue(dev);
1994 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
1995 }
1996 }
1997
1998 dev->trans_start = jiffies;
1999
2000
2001 {
2002 int tx_status;
2003 int i = 32;
2004
2005 while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
2006 if (tx_status & 0x3C) {
2007 if (vortex_debug > 2)
2008 printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n",
2009 dev->name, tx_status);
2010 if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
2011 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
2012 if (tx_status & 0x30) {
2013 issue_and_wait(dev, TxReset);
2014 }
2015 outw(TxEnable, ioaddr + EL3_CMD);
2016 }
2017 outb(0x00, ioaddr + TxStatus);
2018 }
2019 }
2020 return 0;
2021}
2022
2023static int
2024boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
2025{
2026 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2027 long ioaddr = dev->base_addr;
2028
2029 int entry = vp->cur_tx % TX_RING_SIZE;
2030 struct boom_tx_desc *prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
2031 unsigned long flags;
2032
2033 if (vortex_debug > 6) {
2034 printk(KERN_DEBUG "boomerang_start_xmit()\n");
2035 if (vortex_debug > 3)
2036 printk(KERN_DEBUG "%s: Trying to send a packet, Tx index %d.\n",
2037 dev->name, vp->cur_tx);
2038 }
2039
2040 if (vp->cur_tx - vp->dirty_tx >= TX_RING_SIZE) {
2041 if (vortex_debug > 0)
2042 printk(KERN_WARNING "%s: BUG! Tx Ring full, refusing to send buffer.\n",
2043 dev->name);
2044 netif_stop_queue(dev);
2045 return 1;
2046 }
2047
2048 vp->tx_skbuff[entry] = skb;
2049
2050 vp->tx_ring[entry].next = 0;
2051#if DO_ZEROCOPY
2052 if (skb->ip_summed != CHECKSUM_HW)
2053 vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
2054 else
2055 vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded | AddTCPChksum);
2056
2057 if (!skb_shinfo(skb)->nr_frags) {
2058 vp->tx_ring[entry].frag[0].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->data,
2059 skb->len, PCI_DMA_TODEVICE));
2060 vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb->len | LAST_FRAG);
2061 } else {
2062 int i;
2063
2064 vp->tx_ring[entry].frag[0].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->data,
2065 skb->len-skb->data_len, PCI_DMA_TODEVICE));
2066 vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb->len-skb->data_len);
2067
2068 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2069 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2070
2071 vp->tx_ring[entry].frag[i+1].addr =
2072 cpu_to_le32(pci_map_single(vp->pdev,
2073 (void*)page_address(frag->page) + frag->page_offset,
2074 frag->size, PCI_DMA_TODEVICE));
2075
2076 if (i == skb_shinfo(skb)->nr_frags-1)
2077 vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(frag->size|LAST_FRAG);
2078 else
2079 vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(frag->size);
2080 }
2081 }
2082#else
2083 vp->tx_ring[entry].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->data, skb->len, PCI_DMA_TODEVICE));
2084 vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
2085 vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
2086#endif
2087
2088 spin_lock_irqsave(&vp->lock, flags);
2089
2090 issue_and_wait(dev, DownStall);
2091 prev_entry->next = cpu_to_le32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc));
2092 if (inl(ioaddr + DownListPtr) == 0) {
2093 outl(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc), ioaddr + DownListPtr);
2094 vp->queued_packet++;
2095 }
2096
2097 vp->cur_tx++;
2098 if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1) {
2099 netif_stop_queue (dev);
2100 } else {
2101#if defined(tx_interrupt_mitigation)
2102
2103
2104
2105 prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
2106#endif
2107 }
2108 outw(DownUnstall, ioaddr + EL3_CMD);
2109 spin_unlock_irqrestore(&vp->lock, flags);
2110 dev->trans_start = jiffies;
2111 return 0;
2112}
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2123{
2124 struct net_device *dev = dev_id;
2125 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2126 long ioaddr;
2127 int status;
2128 int work_done = max_interrupt_work;
2129
2130 ioaddr = dev->base_addr;
2131 spin_lock(&vp->lock);
2132
2133 status = inw(ioaddr + EL3_STATUS);
2134
2135 if (vortex_debug > 6)
2136 printk("vortex_interrupt(). status=0x%4x\n", status);
2137
2138 if ((status & IntLatch) == 0)
2139 goto handler_exit;
2140
2141 if (status & IntReq) {
2142 status |= vp->deferred;
2143 vp->deferred = 0;
2144 }
2145
2146 if (status == 0xffff)
2147 goto handler_exit;
2148
2149 if (vortex_debug > 4)
2150 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
2151 dev->name, status, inb(ioaddr + Timer));
2152
2153 do {
2154 if (vortex_debug > 5)
2155 printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
2156 dev->name, status);
2157 if (status & RxComplete)
2158 vortex_rx(dev);
2159
2160 if (status & TxAvailable) {
2161 if (vortex_debug > 5)
2162 printk(KERN_DEBUG " TX room bit was handled.\n");
2163
2164 outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
2165 netif_wake_queue (dev);
2166 }
2167
2168 if (status & DMADone) {
2169 if (inw(ioaddr + Wn7_MasterStatus) & 0x1000) {
2170 outw(0x1000, ioaddr + Wn7_MasterStatus);
2171 pci_unmap_single(vp->pdev, vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE);
2172 dev_kfree_skb_irq(vp->tx_skb);
2173 if (inw(ioaddr + TxFree) > 1536) {
2174
2175
2176
2177
2178
2179 netif_wake_queue(dev);
2180 } else {
2181 outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
2182 netif_stop_queue(dev);
2183 }
2184 }
2185 }
2186
2187 if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
2188 if (status == 0xffff)
2189 break;
2190 vortex_error(dev, status);
2191 }
2192
2193 if (--work_done < 0) {
2194 printk(KERN_WARNING "%s: Too much work in interrupt, status "
2195 "%4.4x.\n", dev->name, status);
2196
2197 do {
2198 vp->deferred |= status;
2199 outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
2200 ioaddr + EL3_CMD);
2201 outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
2202 } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
2203
2204 mod_timer(&vp->timer, jiffies + 1*HZ);
2205 break;
2206 }
2207
2208 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
2209 } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
2210
2211 if (vortex_debug > 4)
2212 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
2213 dev->name, status);
2214handler_exit:
2215 spin_unlock(&vp->lock);
2216}
2217
2218
2219
2220
2221
2222
2223static void boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2224{
2225 struct net_device *dev = dev_id;
2226 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2227 long ioaddr;
2228 int status;
2229 int work_done = max_interrupt_work;
2230
2231 ioaddr = dev->base_addr;
2232
2233
2234
2235
2236
2237 spin_lock(&vp->lock);
2238
2239 status = inw(ioaddr + EL3_STATUS);
2240
2241 if (vortex_debug > 6)
2242 printk(KERN_DEBUG "boomerang_interrupt. status=0x%4x\n", status);
2243
2244 if ((status & IntLatch) == 0)
2245 goto handler_exit;
2246
2247 if (status == 0xffff) {
2248 if (vortex_debug > 1)
2249 printk(KERN_DEBUG "boomerang_interrupt(1): status = 0xffff\n");
2250 goto handler_exit;
2251 }
2252
2253 if (status & IntReq) {
2254 status |= vp->deferred;
2255 vp->deferred = 0;
2256 }
2257
2258 if (vortex_debug > 4)
2259 printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
2260 dev->name, status, inb(ioaddr + Timer));
2261 do {
2262 if (vortex_debug > 5)
2263 printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
2264 dev->name, status);
2265 if (status & UpComplete) {
2266 outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
2267 if (vortex_debug > 5)
2268 printk(KERN_DEBUG "boomerang_interrupt->boomerang_rx\n");
2269 boomerang_rx(dev);
2270 }
2271
2272 if (status & DownComplete) {
2273 unsigned int dirty_tx = vp->dirty_tx;
2274
2275 outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
2276 while (vp->cur_tx - dirty_tx > 0) {
2277 int entry = dirty_tx % TX_RING_SIZE;
2278#if 1
2279 if (inl(ioaddr + DownListPtr) ==
2280 vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc))
2281 break;
2282#else
2283 if ((vp->tx_ring[entry].status & DN_COMPLETE) == 0)
2284 break;
2285#endif
2286
2287 if (vp->tx_skbuff[entry]) {
2288 struct sk_buff *skb = vp->tx_skbuff[entry];
2289#if DO_ZEROCOPY
2290 int i;
2291 for (i=0; i<=skb_shinfo(skb)->nr_frags; i++)
2292 pci_unmap_single(vp->pdev,
2293 le32_to_cpu(vp->tx_ring[entry].frag[i].addr),
2294 le32_to_cpu(vp->tx_ring[entry].frag[i].length)&0xFFF,
2295 PCI_DMA_TODEVICE);
2296#else
2297 pci_unmap_single(vp->pdev,
2298 le32_to_cpu(vp->tx_ring[entry].addr), skb->len, PCI_DMA_TODEVICE);
2299#endif
2300 dev_kfree_skb_irq(skb);
2301 vp->tx_skbuff[entry] = 0;
2302 } else {
2303 printk(KERN_DEBUG "boomerang_interrupt: no skb!\n");
2304 }
2305
2306 dirty_tx++;
2307 }
2308 vp->dirty_tx = dirty_tx;
2309 if (vp->cur_tx - dirty_tx <= TX_RING_SIZE - 1) {
2310 if (vortex_debug > 6)
2311 printk(KERN_DEBUG "boomerang_interrupt: wake queue\n");
2312 netif_wake_queue (dev);
2313 }
2314 }
2315
2316
2317 if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq))
2318 vortex_error(dev, status);
2319
2320 if (--work_done < 0) {
2321 printk(KERN_WARNING "%s: Too much work in interrupt, status "
2322 "%4.4x.\n", dev->name, status);
2323
2324 do {
2325 vp->deferred |= status;
2326 outw(SetStatusEnb | (~vp->deferred & vp->status_enable),
2327 ioaddr + EL3_CMD);
2328 outw(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
2329 } while ((status = inw(ioaddr + EL3_CMD)) & IntLatch);
2330
2331 mod_timer(&vp->timer, jiffies + 1*HZ);
2332 break;
2333 }
2334
2335 outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
2336 if (vp->cb_fn_base)
2337 writel(0x8000, vp->cb_fn_base + 4);
2338
2339 } while ((status = inw(ioaddr + EL3_STATUS)) & IntLatch);
2340
2341 if (vortex_debug > 4)
2342 printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
2343 dev->name, status);
2344handler_exit:
2345 spin_unlock(&vp->lock);
2346}
2347
2348static int vortex_rx(struct net_device *dev)
2349{
2350 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2351 long ioaddr = dev->base_addr;
2352 int i;
2353 short rx_status;
2354
2355 if (vortex_debug > 5)
2356 printk(KERN_DEBUG "vortex_rx(): status %4.4x, rx_status %4.4x.\n",
2357 inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
2358 while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
2359 if (rx_status & 0x4000) {
2360 unsigned char rx_error = inb(ioaddr + RxErrors);
2361 if (vortex_debug > 2)
2362 printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
2363 vp->stats.rx_errors++;
2364 if (rx_error & 0x01) vp->stats.rx_over_errors++;
2365 if (rx_error & 0x02) vp->stats.rx_length_errors++;
2366 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
2367 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
2368 if (rx_error & 0x10) vp->stats.rx_length_errors++;
2369 } else {
2370
2371 int pkt_len = rx_status & 0x1fff;
2372 struct sk_buff *skb;
2373
2374 skb = dev_alloc_skb(pkt_len + 5);
2375 if (vortex_debug > 4)
2376 printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
2377 pkt_len, rx_status);
2378 if (skb != NULL) {
2379 skb->dev = dev;
2380 skb_reserve(skb, 2);
2381
2382 if (vp->bus_master &&
2383 ! (inw(ioaddr + Wn7_MasterStatus) & 0x8000)) {
2384 dma_addr_t dma = pci_map_single(vp->pdev, skb_put(skb, pkt_len),
2385 pkt_len, PCI_DMA_FROMDEVICE);
2386 outl(dma, ioaddr + Wn7_MasterAddr);
2387 outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
2388 outw(StartDMAUp, ioaddr + EL3_CMD);
2389 while (inw(ioaddr + Wn7_MasterStatus) & 0x8000)
2390 ;
2391 pci_unmap_single(vp->pdev, dma, pkt_len, PCI_DMA_FROMDEVICE);
2392 } else {
2393 insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
2394 (pkt_len + 3) >> 2);
2395 }
2396 outw(RxDiscard, ioaddr + EL3_CMD);
2397 skb->protocol = eth_type_trans(skb, dev);
2398 netif_rx(skb);
2399 dev->last_rx = jiffies;
2400 vp->stats.rx_packets++;
2401
2402 for (i = 200; i >= 0; i--)
2403 if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
2404 break;
2405 continue;
2406 } else if (vortex_debug > 0)
2407 printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of "
2408 "size %d.\n", dev->name, pkt_len);
2409 }
2410 vp->stats.rx_dropped++;
2411 issue_and_wait(dev, RxDiscard);
2412 }
2413
2414 return 0;
2415}
2416
2417static int
2418boomerang_rx(struct net_device *dev)
2419{
2420 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2421 int entry = vp->cur_rx % RX_RING_SIZE;
2422 long ioaddr = dev->base_addr;
2423 int rx_status;
2424 int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
2425
2426 if (vortex_debug > 5)
2427 printk(KERN_DEBUG "boomerang_rx(): status %4.4x\n", inw(ioaddr+EL3_STATUS));
2428
2429 while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
2430 if (--rx_work_limit < 0)
2431 break;
2432 if (rx_status & RxDError) {
2433 unsigned char rx_error = rx_status >> 16;
2434 if (vortex_debug > 2)
2435 printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
2436 vp->stats.rx_errors++;
2437 if (rx_error & 0x01) vp->stats.rx_over_errors++;
2438 if (rx_error & 0x02) vp->stats.rx_length_errors++;
2439 if (rx_error & 0x04) vp->stats.rx_frame_errors++;
2440 if (rx_error & 0x08) vp->stats.rx_crc_errors++;
2441 if (rx_error & 0x10) vp->stats.rx_length_errors++;
2442 } else {
2443
2444 int pkt_len = rx_status & 0x1fff;
2445 struct sk_buff *skb;
2446 dma_addr_t dma = le32_to_cpu(vp->rx_ring[entry].addr);
2447
2448 if (vortex_debug > 4)
2449 printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
2450 pkt_len, rx_status);
2451
2452
2453
2454 if (pkt_len < rx_copybreak && (skb = dev_alloc_skb(pkt_len + 2)) != 0) {
2455 skb->dev = dev;
2456 skb_reserve(skb, 2);
2457 pci_dma_sync_single(vp->pdev, dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2458
2459 memcpy(skb_put(skb, pkt_len),
2460 vp->rx_skbuff[entry]->tail,
2461 pkt_len);
2462 vp->rx_copy++;
2463 } else {
2464
2465 skb = vp->rx_skbuff[entry];
2466 vp->rx_skbuff[entry] = NULL;
2467 skb_put(skb, pkt_len);
2468 pci_unmap_single(vp->pdev, dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2469 vp->rx_nocopy++;
2470 }
2471 skb->protocol = eth_type_trans(skb, dev);
2472 {
2473 int csum_bits = rx_status & 0xee000000;
2474 if (csum_bits &&
2475 (csum_bits == (IPChksumValid | TCPChksumValid) ||
2476 csum_bits == (IPChksumValid | UDPChksumValid))) {
2477 skb->ip_summed = CHECKSUM_UNNECESSARY;
2478 vp->rx_csumhits++;
2479 }
2480 }
2481 netif_rx(skb);
2482 dev->last_rx = jiffies;
2483 vp->stats.rx_packets++;
2484 }
2485 entry = (++vp->cur_rx) % RX_RING_SIZE;
2486 }
2487
2488 for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
2489 struct sk_buff *skb;
2490 entry = vp->dirty_rx % RX_RING_SIZE;
2491 if (vp->rx_skbuff[entry] == NULL) {
2492 skb = dev_alloc_skb(PKT_BUF_SZ);
2493 if (skb == NULL) {
2494 static unsigned long last_jif;
2495 if ((jiffies - last_jif) > 10 * HZ) {
2496 printk(KERN_WARNING "%s: memory shortage\n", dev->name);
2497 last_jif = jiffies;
2498 }
2499 if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)
2500 mod_timer(&vp->rx_oom_timer, RUN_AT(HZ * 1));
2501 break;
2502 }
2503 skb->dev = dev;
2504 skb_reserve(skb, 2);
2505 vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(vp->pdev, skb->tail, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
2506 vp->rx_skbuff[entry] = skb;
2507 }
2508 vp->rx_ring[entry].status = 0;
2509 outw(UpUnstall, ioaddr + EL3_CMD);
2510 }
2511 return 0;
2512}
2513
2514
2515
2516
2517
2518static void
2519rx_oom_timer(unsigned long arg)
2520{
2521 struct net_device *dev = (struct net_device *)arg;
2522 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2523
2524 spin_lock_irq(&vp->lock);
2525 if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)
2526 boomerang_rx(dev);
2527 if (vortex_debug > 1) {
2528 printk(KERN_DEBUG "%s: rx_oom_timer %s\n", dev->name,
2529 ((vp->cur_rx - vp->dirty_rx) != RX_RING_SIZE) ? "succeeded" : "retrying");
2530 }
2531 spin_unlock_irq(&vp->lock);
2532}
2533
2534static void
2535vortex_down(struct net_device *dev)
2536{
2537 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2538 long ioaddr = dev->base_addr;
2539
2540 netif_stop_queue (dev);
2541
2542 del_timer_sync(&vp->rx_oom_timer);
2543 del_timer_sync(&vp->timer);
2544
2545
2546 outw(StatsDisable, ioaddr + EL3_CMD);
2547
2548
2549 outw(RxDisable, ioaddr + EL3_CMD);
2550 outw(TxDisable, ioaddr + EL3_CMD);
2551
2552 if (dev->if_port == XCVR_10base2)
2553
2554 outw(StopCoax, ioaddr + EL3_CMD);
2555
2556 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
2557
2558 update_stats(ioaddr, dev);
2559 if (vp->full_bus_master_rx)
2560 outl(0, ioaddr + UpListPtr);
2561 if (vp->full_bus_master_tx)
2562 outl(0, ioaddr + DownListPtr);
2563
2564 if (vp->pdev && vp->enable_wol) {
2565 pci_save_state(vp->pdev, vp->power_state);
2566 acpi_set_WOL(dev);
2567 }
2568}
2569
2570static int
2571vortex_close(struct net_device *dev)
2572{
2573 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2574 long ioaddr = dev->base_addr;
2575 int i;
2576
2577 if (netif_device_present(dev))
2578 vortex_down(dev);
2579
2580 if (vortex_debug > 1) {
2581 printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
2582 dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
2583 printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d"
2584 " tx_queued %d Rx pre-checksummed %d.\n",
2585 dev->name, vp->rx_nocopy, vp->rx_copy, vp->queued_packet, vp->rx_csumhits);
2586 }
2587
2588#if DO_ZEROCOPY
2589 if ( vp->rx_csumhits &&
2590 ((vp->drv_flags & HAS_HWCKSM) == 0) &&
2591 (hw_checksums[vp->card_idx] == -1)) {
2592 printk(KERN_WARNING "%s supports hardware checksums, and we're not using them!\n", dev->name);
2593 }
2594#endif
2595
2596 free_irq(dev->irq, dev);
2597
2598 if (vp->full_bus_master_rx) {
2599 for (i = 0; i < RX_RING_SIZE; i++)
2600 if (vp->rx_skbuff[i]) {
2601 pci_unmap_single( vp->pdev, le32_to_cpu(vp->rx_ring[i].addr),
2602 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
2603 dev_kfree_skb(vp->rx_skbuff[i]);
2604 vp->rx_skbuff[i] = 0;
2605 }
2606 }
2607 if (vp->full_bus_master_tx) {
2608 for (i = 0; i < TX_RING_SIZE; i++) {
2609 if (vp->tx_skbuff[i]) {
2610 struct sk_buff *skb = vp->tx_skbuff[i];
2611#if DO_ZEROCOPY
2612 int k;
2613
2614 for (k=0; k<=skb_shinfo(skb)->nr_frags; k++)
2615 pci_unmap_single(vp->pdev,
2616 le32_to_cpu(vp->tx_ring[i].frag[k].addr),
2617 le32_to_cpu(vp->tx_ring[i].frag[k].length)&0xFFF,
2618 PCI_DMA_TODEVICE);
2619#else
2620 pci_unmap_single(vp->pdev, le32_to_cpu(vp->tx_ring[i].addr), skb->len, PCI_DMA_TODEVICE);
2621#endif
2622 dev_kfree_skb(skb);
2623 vp->tx_skbuff[i] = 0;
2624 }
2625 }
2626 }
2627
2628 return 0;
2629}
2630
2631static void
2632dump_tx_ring(struct net_device *dev)
2633{
2634 if (vortex_debug > 0) {
2635 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2636 long ioaddr = dev->base_addr;
2637
2638 if (vp->full_bus_master_tx) {
2639 int i;
2640 int stalled = inl(ioaddr + PktStatus) & 0x04;
2641
2642 printk(KERN_ERR " Flags; bus-master %d, dirty %d(%d) current %d(%d)\n",
2643 vp->full_bus_master_tx,
2644 vp->dirty_tx, vp->dirty_tx % TX_RING_SIZE,
2645 vp->cur_tx, vp->cur_tx % TX_RING_SIZE);
2646 printk(KERN_ERR " Transmit list %8.8x vs. %p.\n",
2647 inl(ioaddr + DownListPtr),
2648 &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
2649 issue_and_wait(dev, DownStall);
2650 for (i = 0; i < TX_RING_SIZE; i++) {
2651 printk(KERN_ERR " %d: @%p length %8.8x status %8.8x\n", i,
2652 &vp->tx_ring[i],
2653#if DO_ZEROCOPY
2654 le32_to_cpu(vp->tx_ring[i].frag[0].length),
2655#else
2656 le32_to_cpu(vp->tx_ring[i].length),
2657#endif
2658 le32_to_cpu(vp->tx_ring[i].status));
2659 }
2660 if (!stalled)
2661 outw(DownUnstall, ioaddr + EL3_CMD);
2662 }
2663 }
2664}
2665
2666static struct net_device_stats *vortex_get_stats(struct net_device *dev)
2667{
2668 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2669 unsigned long flags;
2670
2671 if (netif_device_present(dev)) {
2672 spin_lock_irqsave (&vp->lock, flags);
2673 update_stats(dev->base_addr, dev);
2674 spin_unlock_irqrestore (&vp->lock, flags);
2675 }
2676 return &vp->stats;
2677}
2678
2679
2680
2681
2682
2683
2684
2685
2686static void update_stats(long ioaddr, struct net_device *dev)
2687{
2688 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2689 int old_window = inw(ioaddr + EL3_CMD);
2690
2691 if (old_window == 0xffff)
2692 return;
2693
2694
2695 EL3WINDOW(6);
2696 vp->stats.tx_carrier_errors += inb(ioaddr + 0);
2697 vp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
2698 inb(ioaddr + 2);
2699 vp->stats.collisions += inb(ioaddr + 3);
2700 vp->stats.tx_window_errors += inb(ioaddr + 4);
2701 vp->stats.rx_fifo_errors += inb(ioaddr + 5);
2702 vp->stats.tx_packets += inb(ioaddr + 6);
2703 vp->stats.tx_packets += (inb(ioaddr + 9)&0x30) << 4;
2704 inb(ioaddr + 7);
2705 inb(ioaddr + 8);
2706
2707
2708
2709 vp->stats.rx_bytes += inw(ioaddr + 10);
2710 vp->stats.tx_bytes += inw(ioaddr + 12);
2711
2712 EL3WINDOW(4);
2713 inb(ioaddr + 12);
2714
2715 {
2716 u8 up = inb(ioaddr + 13);
2717 vp->stats.rx_bytes += (up & 0x0f) << 16;
2718 vp->stats.tx_bytes += (up & 0xf0) << 12;
2719 }
2720
2721 EL3WINDOW(old_window >> 13);
2722 return;
2723}
2724
2725
2726static int netdev_ethtool_ioctl(struct net_device *dev, void *useraddr)
2727{
2728 struct vortex_private *vp = dev->priv;
2729 u32 ethcmd;
2730
2731 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
2732 return -EFAULT;
2733
2734 switch (ethcmd) {
2735 case ETHTOOL_GDRVINFO: {
2736 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
2737 strcpy(info.driver, DRV_NAME);
2738 strcpy(info.version, DRV_VERSION);
2739 if (vp->pdev)
2740 strcpy(info.bus_info, vp->pdev->slot_name);
2741 else
2742 sprintf(info.bus_info, "EISA 0x%lx %d",
2743 dev->base_addr, dev->irq);
2744 if (copy_to_user(useraddr, &info, sizeof(info)))
2745 return -EFAULT;
2746 return 0;
2747 }
2748
2749 }
2750
2751 return -EOPNOTSUPP;
2752}
2753
2754static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2755{
2756 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2757 long ioaddr = dev->base_addr;
2758 struct mii_ioctl_data *data = (struct mii_ioctl_data *)&rq->ifr_data;
2759 int phy = vp->phys[0] & 0x1f;
2760 int retval;
2761
2762 switch(cmd) {
2763 case SIOCETHTOOL:
2764 return netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
2765
2766 case SIOCGMIIPHY:
2767 data->phy_id = phy;
2768
2769 case SIOCGMIIREG:
2770 EL3WINDOW(4);
2771 data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
2772 retval = 0;
2773 break;
2774
2775 case SIOCSMIIREG:
2776 if (!capable(CAP_NET_ADMIN)) {
2777 retval = -EPERM;
2778 } else {
2779 EL3WINDOW(4);
2780 mdio_write(dev, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
2781 retval = 0;
2782 }
2783 break;
2784 default:
2785 retval = -EOPNOTSUPP;
2786 break;
2787 }
2788
2789 return retval;
2790}
2791
2792
2793
2794
2795static void set_rx_mode(struct net_device *dev)
2796{
2797 long ioaddr = dev->base_addr;
2798 int new_mode;
2799
2800 if (dev->flags & IFF_PROMISC) {
2801 if (vortex_debug > 0)
2802 printk(KERN_NOTICE "%s: Setting promiscuous mode.\n", dev->name);
2803 new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
2804 } else if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
2805 new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
2806 } else
2807 new_mode = SetRxFilter | RxStation | RxBroadcast;
2808
2809 outw(new_mode, ioaddr + EL3_CMD);
2810}
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820#define mdio_delay() inl(mdio_addr)
2821
2822#define MDIO_SHIFT_CLK 0x01
2823#define MDIO_DIR_WRITE 0x04
2824#define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
2825#define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
2826#define MDIO_DATA_READ 0x02
2827#define MDIO_ENB_IN 0x00
2828
2829
2830
2831static void mdio_sync(long ioaddr, int bits)
2832{
2833 long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2834
2835
2836 while (-- bits >= 0) {
2837 outw(MDIO_DATA_WRITE1, mdio_addr);
2838 mdio_delay();
2839 outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
2840 mdio_delay();
2841 }
2842}
2843
2844static int mdio_read(struct net_device *dev, int phy_id, int location)
2845{
2846 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2847 int i;
2848 long ioaddr = dev->base_addr;
2849 int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
2850 unsigned int retval = 0;
2851 long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2852
2853 spin_lock_bh(&vp->mdio_lock);
2854
2855 if (mii_preamble_required)
2856 mdio_sync(ioaddr, 32);
2857
2858
2859 for (i = 14; i >= 0; i--) {
2860 int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2861 outw(dataval, mdio_addr);
2862 mdio_delay();
2863 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2864 mdio_delay();
2865 }
2866
2867 for (i = 19; i > 0; i--) {
2868 outw(MDIO_ENB_IN, mdio_addr);
2869 mdio_delay();
2870 retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
2871 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2872 mdio_delay();
2873 }
2874 spin_unlock_bh(&vp->mdio_lock);
2875 return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
2876}
2877
2878static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
2879{
2880 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2881 long ioaddr = dev->base_addr;
2882 int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
2883 long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
2884 int i;
2885
2886 spin_lock_bh(&vp->mdio_lock);
2887
2888 if (mii_preamble_required)
2889 mdio_sync(ioaddr, 32);
2890
2891
2892 for (i = 31; i >= 0; i--) {
2893 int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
2894 outw(dataval, mdio_addr);
2895 mdio_delay();
2896 outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
2897 mdio_delay();
2898 }
2899
2900 for (i = 1; i >= 0; i--) {
2901 outw(MDIO_ENB_IN, mdio_addr);
2902 mdio_delay();
2903 outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
2904 mdio_delay();
2905 }
2906 spin_unlock_bh(&vp->mdio_lock);
2907 return;
2908}
2909
2910
2911
2912static void acpi_set_WOL(struct net_device *dev)
2913{
2914 struct vortex_private *vp = (struct vortex_private *)dev->priv;
2915 long ioaddr = dev->base_addr;
2916
2917
2918 EL3WINDOW(7);
2919 outw(2, ioaddr + 0x0c);
2920
2921 outw(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
2922 outw(RxEnable, ioaddr + EL3_CMD);
2923
2924
2925 pci_enable_wake(vp->pdev, 0, 1);
2926 pci_set_power_state(vp->pdev, 3);
2927}
2928
2929
2930static void __devexit vortex_remove_one (struct pci_dev *pdev)
2931{
2932 struct net_device *dev = pci_get_drvdata(pdev);
2933 struct vortex_private *vp;
2934
2935 if (!dev) {
2936 printk("vortex_remove_one called for EISA device!\n");
2937 BUG();
2938 }
2939
2940 vp = dev->priv;
2941
2942
2943
2944
2945
2946 unregister_netdev(dev);
2947
2948 outw(TotalReset|0x14, dev->base_addr + EL3_CMD);
2949
2950 if (vp->pdev && vp->enable_wol) {
2951 pci_set_power_state(vp->pdev, 0);
2952 if (vp->pm_state_valid)
2953 pci_restore_state(vp->pdev, vp->power_state);
2954 }
2955
2956 pci_free_consistent(pdev,
2957 sizeof(struct boom_rx_desc) * RX_RING_SIZE
2958 + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
2959 vp->rx_ring,
2960 vp->rx_ring_dma);
2961 if (vp->must_free_region)
2962 release_region(dev->base_addr, vp->io_size);
2963 kfree(dev);
2964}
2965
2966
2967static struct pci_driver vortex_driver = {
2968 .name = "3c59x",
2969 .probe = vortex_init_one,
2970 .remove = __devexit_p(vortex_remove_one),
2971 .id_table = vortex_pci_tbl,
2972#ifdef CONFIG_PM
2973 .suspend = vortex_suspend,
2974 .resume = vortex_resume,
2975#endif
2976};
2977
2978
2979static int vortex_have_pci;
2980static int vortex_have_eisa;
2981
2982
2983static int __init vortex_init (void)
2984{
2985 int pci_rc, eisa_rc;
2986
2987 pci_rc = pci_module_init(&vortex_driver);
2988 eisa_rc = vortex_eisa_init();
2989
2990 if (pci_rc == 0)
2991 vortex_have_pci = 1;
2992 if (eisa_rc > 0)
2993 vortex_have_eisa = 1;
2994
2995 return (vortex_have_pci + vortex_have_eisa) ? 0 : -ENODEV;
2996}
2997
2998
2999static void __exit vortex_eisa_cleanup (void)
3000{
3001 struct net_device *dev, *tmp;
3002 struct vortex_private *vp;
3003 long ioaddr;
3004
3005 dev = root_vortex_eisa_dev;
3006
3007 while (dev) {
3008 vp = dev->priv;
3009 ioaddr = dev->base_addr;
3010
3011 unregister_netdev (dev);
3012 outw (TotalReset, ioaddr + EL3_CMD);
3013 release_region (ioaddr, VORTEX_TOTAL_SIZE);
3014
3015 tmp = dev;
3016 dev = vp->next_module;
3017
3018 kfree (tmp);
3019 }
3020}
3021
3022
3023static void __exit vortex_cleanup (void)
3024{
3025 if (vortex_have_pci)
3026 pci_unregister_driver (&vortex_driver);
3027 if (vortex_have_eisa)
3028 vortex_eisa_cleanup ();
3029}
3030
3031
3032module_init(vortex_init);
3033module_exit(vortex_cleanup);
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043