summaryrefslogtreecommitdiff
path: root/drivers/net/bcm570x.c
blob: 185764ef5e96b7ab20dd79fd6dc474d5f3bc5fdf (plain)
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
/*
 * Broadcom BCM570x Ethernet Driver for U-Boot.
 * Support 5701, 5702, 5703, and 5704. Single instance driver.
 * Copyright (C) 2002 James F. Dougherty (jfd@broadcom.com)
 */

#include <common.h>

#ifdef CONFIG_BMW
#include <mpc824x.h>
#endif
#include <net.h>
#include "bcm570x_mm.h"
#include "bcm570x_autoneg.h"
#include <pci.h>
#include <malloc.h>

/*
 * PCI Registers and definitions.
 */
#define PCI_CMD_MASK	0xffff0000	/* mask to save status bits */
#define PCI_ANY_ID (~0)

/*
 * PCI memory base for Ethernet device as well as device Interrupt.
 */
#define BCM570X_MBAR	0x80100000
#define BCM570X_ILINE   1

#define SECOND_USEC	1000000
#define MAX_PACKET_SIZE 1600
#define MAX_UNITS       4

/* Globals to this module */
int initialized = 0;
unsigned int ioBase = 0;
volatile PLM_DEVICE_BLOCK pDevice = NULL;	/* 570x softc */
volatile PUM_DEVICE_BLOCK pUmDevice = NULL;

/* Used to pass the full-duplex flag, etc. */
int line_speed[MAX_UNITS] = { 0, 0, 0, 0 };
static int full_duplex[MAX_UNITS] = { 1, 1, 1, 1 };
static int rx_flow_control[MAX_UNITS] = { 0, 0, 0, 0 };
static int tx_flow_control[MAX_UNITS] = { 0, 0, 0, 0 };
static int auto_flow_control[MAX_UNITS] = { 0, 0, 0, 0 };
static int tx_checksum[MAX_UNITS] = { 1, 1, 1, 1 };
static int rx_checksum[MAX_UNITS] = { 1, 1, 1, 1 };
static int auto_speed[MAX_UNITS] = { 1, 1, 1, 1 };

#if JUMBO_FRAMES
/* Jumbo MTU for interfaces. */
static int mtu[MAX_UNITS] = { 0, 0, 0, 0 };
#endif

/* Turn on Wake-on lan for a device unit */
static int enable_wol[MAX_UNITS] = { 0, 0, 0, 0 };

#define TX_DESC_CNT DEFAULT_TX_PACKET_DESC_COUNT
static unsigned int tx_pkt_desc_cnt[MAX_UNITS] =
    { TX_DESC_CNT, TX_DESC_CNT, TX_DESC_CNT, TX_DESC_CNT };

#define RX_DESC_CNT DEFAULT_STD_RCV_DESC_COUNT
static unsigned int rx_std_desc_cnt[MAX_UNITS] =
    { RX_DESC_CNT, RX_DESC_CNT, RX_DESC_CNT, RX_DESC_CNT };

static unsigned int rx_adaptive_coalesce[MAX_UNITS] = { 1, 1, 1, 1 };

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
#define JBO_DESC_CNT DEFAULT_JUMBO_RCV_DESC_COUNT
static unsigned int rx_jumbo_desc_cnt[MAX_UNITS] =
    { JBO_DESC_CNT, JBO_DESC_CNT, JBO_DESC_CNT, JBO_DESC_CNT };
#endif
#define RX_COAL_TK DEFAULT_RX_COALESCING_TICKS
static unsigned int rx_coalesce_ticks[MAX_UNITS] =
    { RX_COAL_TK, RX_COAL_TK, RX_COAL_TK, RX_COAL_TK };

#define RX_COAL_FM DEFAULT_RX_MAX_COALESCED_FRAMES
static unsigned int rx_max_coalesce_frames[MAX_UNITS] =
    { RX_COAL_FM, RX_COAL_FM, RX_COAL_FM, RX_COAL_FM };

#define TX_COAL_TK DEFAULT_TX_COALESCING_TICKS
static unsigned int tx_coalesce_ticks[MAX_UNITS] =
    { TX_COAL_TK, TX_COAL_TK, TX_COAL_TK, TX_COAL_TK };

#define TX_COAL_FM DEFAULT_TX_MAX_COALESCED_FRAMES
static unsigned int tx_max_coalesce_frames[MAX_UNITS] =
    { TX_COAL_FM, TX_COAL_FM, TX_COAL_FM, TX_COAL_FM };

#define ST_COAL_TK DEFAULT_STATS_COALESCING_TICKS
static unsigned int stats_coalesce_ticks[MAX_UNITS] =
    { ST_COAL_TK, ST_COAL_TK, ST_COAL_TK, ST_COAL_TK };

/*
 * Legitimate values for BCM570x device types
 */
typedef enum {
	BCM5700VIGIL = 0,
	BCM5700A6,
	BCM5700T6,
	BCM5700A9,
	BCM5700T9,
	BCM5700,
	BCM5701A5,
	BCM5701T1,
	BCM5701T8,
	BCM5701A7,
	BCM5701A10,
	BCM5701A12,
	BCM5701,
	BCM5702,
	BCM5703,
	BCM5703A31,
	TC996T,
	TC996ST,
	TC996SSX,
	TC996SX,
	TC996BT,
	TC997T,
	TC997SX,
	TC1000T,
	TC940BR01,
	TC942BR01,
	NC6770,
	NC7760,
	NC7770,
	NC7780
} board_t;

/* Chip-Rev names for each device-type */
static struct {
	char *name;
} chip_rev[] = {
	{
	"BCM5700VIGIL"}, {
	"BCM5700A6"}, {
	"BCM5700T6"}, {
	"BCM5700A9"}, {
	"BCM5700T9"}, {
	"BCM5700"}, {
	"BCM5701A5"}, {
	"BCM5701T1"}, {
	"BCM5701T8"}, {
	"BCM5701A7"}, {
	"BCM5701A10"}, {
	"BCM5701A12"}, {
	"BCM5701"}, {
	"BCM5702"}, {
	"BCM5703"}, {
	"BCM5703A31"}, {
	"TC996T"}, {
	"TC996ST"}, {
	"TC996SSX"}, {
	"TC996SX"}, {
	"TC996BT"}, {
	"TC997T"}, {
	"TC997SX"}, {
	"TC1000T"}, {
	"TC940BR01"}, {
	"TC942BR01"}, {
	"NC6770"}, {
	"NC7760"}, {
	"NC7770"}, {
	"NC7780"}, {
	0}
};

/* indexed by board_t, above */
static struct {
	char *name;
} board_info[] = {
	{
	"Broadcom Vigil B5700 1000Base-T"}, {
	"Broadcom BCM5700 1000Base-T"}, {
	"Broadcom BCM5700 1000Base-SX"}, {
	"Broadcom BCM5700 1000Base-SX"}, {
	"Broadcom BCM5700 1000Base-T"}, {
	"Broadcom BCM5700"}, {
	"Broadcom BCM5701 1000Base-T"}, {
	"Broadcom BCM5701 1000Base-T"}, {
	"Broadcom BCM5701 1000Base-T"}, {
	"Broadcom BCM5701 1000Base-SX"}, {
	"Broadcom BCM5701 1000Base-T"}, {
	"Broadcom BCM5701 1000Base-T"}, {
	"Broadcom BCM5701"}, {
	"Broadcom BCM5702 1000Base-T"}, {
	"Broadcom BCM5703 1000Base-T"}, {
	"Broadcom BCM5703 1000Base-SX"}, {
	"3Com 3C996 10/100/1000 Server NIC"}, {
	"3Com 3C996 10/100/1000 Server NIC"}, {
	"3Com 3C996 Gigabit Fiber-SX Server NIC"}, {
	"3Com 3C996 Gigabit Fiber-SX Server NIC"}, {
	"3Com 3C996B Gigabit Server NIC"}, {
	"3Com 3C997 Gigabit Server NIC"}, {
	"3Com 3C997 Gigabit Fiber-SX Server NIC"}, {
	"3Com 3C1000 Gigabit NIC"}, {
	"3Com 3C940 Gigabit LOM (21X21)"}, {
	"3Com 3C942 Gigabit LOM (31X31)"}, {
	"Compaq NC6770 Gigabit Server Adapter"}, {
	"Compaq NC7760 Gigabit Server Adapter"}, {
	"Compaq NC7770 Gigabit Server Adapter"}, {
	"Compaq NC7780 Gigabit Server Adapter"}, {
0},};

/* PCI Devices which use the 570x chipset */
struct pci_device_table {
	unsigned short vendor_id, device_id;	/* Vendor/DeviceID */
	unsigned short subvendor, subdevice;	/* Subsystem ID's or PCI_ANY_ID */
	unsigned int class, class_mask;	/* (class,subclass,prog-if) triplet */
	unsigned long board_id;	/* Data private to the driver */
	int io_size, min_latency;
} bcm570xDevices[] = {
	{
	0x14e4, 0x1644, 0x1014, 0x0277, 0, 0, BCM5700VIGIL, 128, 32}, {
	0x14e4, 0x1644, 0x14e4, 0x1644, 0, 0, BCM5700A6, 128, 32}, {
	0x14e4, 0x1644, 0x14e4, 0x2, 0, 0, BCM5700T6, 128, 32}, {
	0x14e4, 0x1644, 0x14e4, 0x3, 0, 0, BCM5700A9, 128, 32}, {
	0x14e4, 0x1644, 0x14e4, 0x4, 0, 0, BCM5700T9, 128, 32}, {
	0x14e4, 0x1644, 0x1028, 0xd1, 0, 0, BCM5700, 128, 32}, {
	0x14e4, 0x1644, 0x1028, 0x0106, 0, 0, BCM5700, 128, 32}, {
	0x14e4, 0x1644, 0x1028, 0x0109, 0, 0, BCM5700, 128, 32}, {
	0x14e4, 0x1644, 0x1028, 0x010a, 0, 0, BCM5700, 128, 32}, {
	0x14e4, 0x1644, 0x10b7, 0x1000, 0, 0, TC996T, 128, 32}, {
	0x14e4, 0x1644, 0x10b7, 0x1001, 0, 0, TC996ST, 128, 32}, {
	0x14e4, 0x1644, 0x10b7, 0x1002, 0, 0, TC996SSX, 128, 32}, {
	0x14e4, 0x1644, 0x10b7, 0x1003, 0, 0, TC997T, 128, 32}, {
	0x14e4, 0x1644, 0x10b7, 0x1005, 0, 0, TC997SX, 128, 32}, {
	0x14e4, 0x1644, 0x10b7, 0x1008, 0, 0, TC942BR01, 128, 32}, {
	0x14e4, 0x1644, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5700, 128, 32}, {
	0x14e4, 0x1645, 0x14e4, 1, 0, 0, BCM5701A5, 128, 32}, {
	0x14e4, 0x1645, 0x14e4, 5, 0, 0, BCM5701T1, 128, 32}, {
	0x14e4, 0x1645, 0x14e4, 6, 0, 0, BCM5701T8, 128, 32}, {
	0x14e4, 0x1645, 0x14e4, 7, 0, 0, BCM5701A7, 128, 32}, {
	0x14e4, 0x1645, 0x14e4, 8, 0, 0, BCM5701A10, 128, 32}, {
	0x14e4, 0x1645, 0x14e4, 0x8008, 0, 0, BCM5701A12, 128, 32}, {
	0x14e4, 0x1645, 0x0e11, 0xc1, 0, 0, NC6770, 128, 32}, {
	0x14e4, 0x1645, 0x0e11, 0x7c, 0, 0, NC7770, 128, 32}, {
	0x14e4, 0x1645, 0x0e11, 0x85, 0, 0, NC7780, 128, 32}, {
	0x14e4, 0x1645, 0x1028, 0x0121, 0, 0, BCM5701, 128, 32}, {
	0x14e4, 0x1645, 0x10b7, 0x1004, 0, 0, TC996SX, 128, 32}, {
	0x14e4, 0x1645, 0x10b7, 0x1006, 0, 0, TC996BT, 128, 32}, {
	0x14e4, 0x1645, 0x10b7, 0x1007, 0, 0, TC1000T, 128, 32}, {
	0x14e4, 0x1645, 0x10b7, 0x1008, 0, 0, TC940BR01, 128, 32}, {
	0x14e4, 0x1645, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5701, 128, 32}, {
	0x14e4, 0x1646, 0x14e4, 0x8009, 0, 0, BCM5702, 128, 32}, {
	0x14e4, 0x1646, 0x0e11, 0xbb, 0, 0, NC7760, 128, 32}, {
	0x14e4, 0x1646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702, 128, 32}, {
	0x14e4, 0x16a6, 0x14e4, 0x8009, 0, 0, BCM5702, 128, 32}, {
	0x14e4, 0x16a6, 0x0e11, 0xbb, 0, 0, NC7760, 128, 32}, {
	0x14e4, 0x16a6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5702, 128, 32}, {
	0x14e4, 0x1647, 0x14e4, 0x0009, 0, 0, BCM5703, 128, 32}, {
	0x14e4, 0x1647, 0x14e4, 0x000a, 0, 0, BCM5703A31, 128, 32}, {
	0x14e4, 0x1647, 0x14e4, 0x000b, 0, 0, BCM5703, 128, 32}, {
	0x14e4, 0x1647, 0x14e4, 0x800a, 0, 0, BCM5703, 128, 32}, {
	0x14e4, 0x1647, 0x0e11, 0x9a, 0, 0, NC7770, 128, 32}, {
	0x14e4, 0x1647, 0x0e11, 0x99, 0, 0, NC7780, 128, 32}, {
	0x14e4, 0x1647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703, 128, 32}, {
	0x14e4, 0x16a7, 0x14e4, 0x0009, 0, 0, BCM5703, 128, 32}, {
	0x14e4, 0x16a7, 0x14e4, 0x000a, 0, 0, BCM5703A31, 128, 32}, {
	0x14e4, 0x16a7, 0x14e4, 0x000b, 0, 0, BCM5703, 128, 32}, {
	0x14e4, 0x16a7, 0x14e4, 0x800a, 0, 0, BCM5703, 128, 32}, {
	0x14e4, 0x16a7, 0x0e11, 0x9a, 0, 0, NC7770, 128, 32}, {
	0x14e4, 0x16a7, 0x0e11, 0x99, 0, 0, NC7780, 128, 32}, {
	0x14e4, 0x16a7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5703, 128, 32}
};

#define n570xDevices   (sizeof(bcm570xDevices)/sizeof(bcm570xDevices[0]))

/*
 * Allocate a packet buffer from the bcm570x packet pool.
 */
void *bcm570xPktAlloc (int u, int pksize)
{
	return malloc (pksize);
}

/*
 * Free a packet previously allocated from the bcm570x packet
 * buffer pool.
 */
void bcm570xPktFree (int u, void *p)
{
	free (p);
}

int bcm570xReplenishRxBuffers (PUM_DEVICE_BLOCK pUmDevice)
{
	PLM_PACKET pPacket;
	PUM_PACKET pUmPacket;
	void *skb;
	int queue_rx = 0;
	int ret = 0;

	while ((pUmPacket = (PUM_PACKET)
		QQ_PopHead (&pUmDevice->rx_out_of_buf_q.Container)) != 0) {

		pPacket = (PLM_PACKET) pUmPacket;

		/* reuse an old skb */
		if (pUmPacket->skbuff) {
			QQ_PushTail (&pDevice->RxPacketFreeQ.Container,
				     pPacket);
			queue_rx = 1;
			continue;
		}
		if ((skb = bcm570xPktAlloc (pUmDevice->index,
					    pPacket->u.Rx.RxBufferSize + 2)) ==
		    0) {
			QQ_PushHead (&pUmDevice->rx_out_of_buf_q.Container,
				     pPacket);
			printf ("NOTICE: Out of RX memory.\n");
			ret = 1;
			break;
		}

		pUmPacket->skbuff = skb;
		QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
		queue_rx = 1;
	}

	if (queue_rx) {
		LM_QueueRxPackets (pDevice);
	}

	return ret;
}

/*
 * Probe, Map, and Init 570x device.
 */
int eth_init (bd_t * bis)
{
	int i, rv, devFound = FALSE;
	pci_dev_t devbusfn;
	unsigned short status;

	/* Find PCI device, if it exists, configure ...  */
	for (i = 0; i < n570xDevices; i++) {
		devbusfn = pci_find_device (bcm570xDevices[i].vendor_id,
					    bcm570xDevices[i].device_id, 0);
		if (devbusfn == -1) {
			continue;	/* No device of that vendor/device ID */
		} else {

			/* Set ILINE */
			pci_write_config_byte (devbusfn,
					       PCI_INTERRUPT_LINE,
					       BCM570X_ILINE);

			/*
			 * 0x10 - 0x14 define one 64-bit MBAR.
			 * 0x14 is the higher-order address bits of the BAR.
			 */
			pci_write_config_dword (devbusfn,
						PCI_BASE_ADDRESS_1, 0);

			ioBase = BCM570X_MBAR;

			pci_write_config_dword (devbusfn,
						PCI_BASE_ADDRESS_0, ioBase);

			/*
			 * Enable PCI memory, IO, and Master -- don't
			 * reset any status bits in doing so.
			 */
			pci_read_config_word (devbusfn, PCI_COMMAND, &status);

			status |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;

			pci_write_config_word (devbusfn, PCI_COMMAND, status);

			printf
			    ("\n%s: bus %d, device %d, function %d: MBAR=0x%x\n",
			     board_info[bcm570xDevices[i].board_id].name,
			     PCI_BUS (devbusfn), PCI_DEV (devbusfn),
			     PCI_FUNC (devbusfn), ioBase);

			/* Allocate once, but always clear on init */
			if (!pDevice) {
				pDevice = malloc (sizeof (UM_DEVICE_BLOCK));
				pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
				memset (pDevice, 0x0, sizeof (UM_DEVICE_BLOCK));
			}

			/* Configure pci dev structure */
			pUmDevice->pdev = devbusfn;
			pUmDevice->index = 0;
			pUmDevice->tx_pkt = 0;
			pUmDevice->rx_pkt = 0;
			devFound = TRUE;
			break;
		}
	}

	if (!devFound) {
		printf
		    ("eth_init: FAILURE: no BCM570x Ethernet devices found.\n");
		return -1;
	}

	/* Setup defaults for chip */
	pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;

	if (pDevice->ChipRevId == T3_CHIP_ID_5700_B0) {
		pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;
	} else {

		if (rx_checksum[i]) {
			pDevice->TaskToOffload |=
			    LM_TASK_OFFLOAD_RX_TCP_CHECKSUM |
			    LM_TASK_OFFLOAD_RX_UDP_CHECKSUM;
		}

		if (tx_checksum[i]) {
			pDevice->TaskToOffload |=
			    LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
			    LM_TASK_OFFLOAD_TX_UDP_CHECKSUM;
			pDevice->NoTxPseudoHdrChksum = TRUE;
		}
	}

	/* Set Device PCI Memory base address */
	pDevice->pMappedMemBase = (PLM_UINT8) ioBase;

	/* Pull down adapter info */
	if ((rv = LM_GetAdapterInfo (pDevice)) != LM_STATUS_SUCCESS) {
		printf ("bcm570xEnd: LM_GetAdapterInfo failed: rv=%d!\n", rv);
		return -2;
	}

	/* Lock not needed */
	pUmDevice->do_global_lock = 0;

	if (T3_ASIC_REV (pUmDevice->lm_dev.ChipRevId) == T3_ASIC_REV_5700) {
		/* The 5700 chip works best without interleaved register */
		/* accesses on certain machines. */
		pUmDevice->do_global_lock = 1;
	}

	/* Setup timer delays */
	if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
		pDevice->UseTaggedStatus = TRUE;
		pUmDevice->timer_interval = CONFIG_SYS_HZ;
	} else {
		pUmDevice->timer_interval = CONFIG_SYS_HZ / 50;
	}

	/* Grab name .... */
	pUmDevice->name =
	    (char *)malloc (strlen (board_info[bcm570xDevices[i].board_id].name)
			    + 1);
	strcpy (pUmDevice->name, board_info[bcm570xDevices[i].board_id].name);

	memcpy (pDevice->NodeAddress, bis->bi_enetaddr, 6);
	LM_SetMacAddress (pDevice, bis->bi_enetaddr);
	/* Init queues  .. */
	QQ_InitQueue (&pUmDevice->rx_out_of_buf_q.Container,
		      MAX_RX_PACKET_DESC_COUNT);
	pUmDevice->rx_last_cnt = pUmDevice->tx_last_cnt = 0;

	/* delay for 4 seconds */
	pUmDevice->delayed_link_ind = (4 * CONFIG_SYS_HZ) / pUmDevice->timer_interval;

	pUmDevice->adaptive_expiry = CONFIG_SYS_HZ / pUmDevice->timer_interval;

	/* Sometimes we get spurious ints. after reset when link is down. */
	/* This field tells the isr to service the int. even if there is */
	/* no status block update. */
	pUmDevice->adapter_just_inited =
	    (3 * CONFIG_SYS_HZ) / pUmDevice->timer_interval;

	/* Initialize 570x */
	if (LM_InitializeAdapter (pDevice) != LM_STATUS_SUCCESS) {
		printf ("ERROR: Adapter initialization failed.\n");
		return ERROR;
	}

	/* Enable chip ISR */
	LM_EnableInterrupt (pDevice);

	/* Clear MC table */
	LM_MulticastClear (pDevice);

	/* Enable Multicast */
	LM_SetReceiveMask (pDevice,
			   pDevice->ReceiveMask | LM_ACCEPT_ALL_MULTICAST);

	pUmDevice->opened = 1;
	pUmDevice->tx_full = 0;
	pUmDevice->tx_pkt = 0;
	pUmDevice->rx_pkt = 0;
	printf ("eth%d: %s @0x%lx,",
		pDevice->index, pUmDevice->name, (unsigned long)ioBase);
	printf ("node addr ");
	for (i = 0; i < 6; i++) {
		printf ("%2.2x", pDevice->NodeAddress[i]);
	}
	printf ("\n");

	printf ("eth%d: ", pDevice->index);
	printf ("%s with ", chip_rev[bcm570xDevices[i].board_id].name);

	if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5400_PHY_ID)
		printf ("Broadcom BCM5400 Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID)
		printf ("Broadcom BCM5401 Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5411_PHY_ID)
		printf ("Broadcom BCM5411 Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5701_PHY_ID)
		printf ("Broadcom BCM5701 Integrated Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5703_PHY_ID)
		printf ("Broadcom BCM5703 Integrated Copper ");
	else if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM8002_PHY_ID)
		printf ("Broadcom BCM8002 SerDes ");
	else if (pDevice->EnableTbi)
		printf ("Agilent HDMP-1636 SerDes ");
	else
		printf ("Unknown ");
	printf ("transceiver found\n");

	printf ("eth%d: %s, MTU: %d,",
		pDevice->index, pDevice->BusSpeedStr, 1500);

	if ((pDevice->ChipRevId != T3_CHIP_ID_5700_B0) && rx_checksum[i])
		printf ("Rx Checksum ON\n");
	else
		printf ("Rx Checksum OFF\n");
	initialized++;

	return 0;
}

/* Ethernet Interrupt service routine */
void eth_isr (void)
{
	LM_UINT32 oldtag, newtag;
	int i;

	pUmDevice->interrupt = 1;

	if (pDevice->UseTaggedStatus) {
		if ((pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) ||
		    pUmDevice->adapter_just_inited) {
			MB_REG_WR (pDevice, Mailbox.Interrupt[0].Low, 1);
			oldtag = pDevice->pStatusBlkVirt->StatusTag;

			for (i = 0;; i++) {
				pDevice->pStatusBlkVirt->Status &=
				    ~STATUS_BLOCK_UPDATED;
				LM_ServiceInterrupts (pDevice);
				newtag = pDevice->pStatusBlkVirt->StatusTag;
				if ((newtag == oldtag) || (i > 50)) {
					MB_REG_WR (pDevice,
						   Mailbox.Interrupt[0].Low,
						   newtag << 24);
					if (pDevice->UndiFix) {
						REG_WR (pDevice, Grc.LocalCtrl,
							pDevice->
							GrcLocalCtrl | 0x2);
					}
					break;
				}
				oldtag = newtag;
			}
		}
	} else {
		while (pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) {
			unsigned int dummy;

			pDevice->pMemView->Mailbox.Interrupt[0].Low = 1;
			pDevice->pStatusBlkVirt->Status &=
			    ~STATUS_BLOCK_UPDATED;
			LM_ServiceInterrupts (pDevice);
			pDevice->pMemView->Mailbox.Interrupt[0].Low = 0;
			dummy = pDevice->pMemView->Mailbox.Interrupt[0].Low;
		}
	}

	/* Allocate new RX buffers */
	if (QQ_GetEntryCnt (&pUmDevice->rx_out_of_buf_q.Container)) {
		bcm570xReplenishRxBuffers (pUmDevice);
	}

	/* Queue packets */
	if (QQ_GetEntryCnt (&pDevice->RxPacketFreeQ.Container)) {
		LM_QueueRxPackets (pDevice);
	}

	if (pUmDevice->tx_queued) {
		pUmDevice->tx_queued = 0;
	}

	if (pUmDevice->tx_full) {
		if (pDevice->LinkStatus != LM_STATUS_LINK_DOWN) {
			printf
			    ("NOTICE: tx was previously blocked, restarting MUX\n");
			pUmDevice->tx_full = 0;
		}
	}

	pUmDevice->interrupt = 0;

}

int eth_send (volatile void *packet, int length)
{
	int status = 0;
#if ET_DEBUG
	unsigned char *ptr = (unsigned char *)packet;
#endif
	PLM_PACKET pPacket;
	PUM_PACKET pUmPacket;

	/* Link down, return */
	while (pDevice->LinkStatus == LM_STATUS_LINK_DOWN) {
#if 0
		printf ("eth%d: link down - check cable or link partner.\n",
			pUmDevice->index);
#endif
		eth_isr ();

		/* Wait to see link for one-half a second before sending ... */
		udelay (1500000);

	}

	/* Clear sent flag */
	pUmDevice->tx_pkt = 0;

	/* Previously blocked */
	if (pUmDevice->tx_full) {
		printf ("eth%d: tx blocked.\n", pUmDevice->index);
		return 0;
	}

	pPacket = (PLM_PACKET)
	    QQ_PopHead (&pDevice->TxPacketFreeQ.Container);

	if (pPacket == 0) {
		pUmDevice->tx_full = 1;
		printf ("bcm570xEndSend: TX full!\n");
		return 0;
	}

	if (pDevice->SendBdLeft.counter == 0) {
		pUmDevice->tx_full = 1;
		printf ("bcm570xEndSend: no more TX descriptors!\n");
		QQ_PushHead (&pDevice->TxPacketFreeQ.Container, pPacket);
		return 0;
	}

	if (length <= 0) {
		printf ("eth: bad packet size: %d\n", length);
		goto out;
	}

	/* Get packet buffers and fragment list */
	pUmPacket = (PUM_PACKET) pPacket;
	/* Single DMA Descriptor transmit.
	 * Fragments may be provided, but one DMA descriptor max is
	 * used to send the packet.
	 */
	if (MM_CoalesceTxBuffer (pDevice, pPacket) != LM_STATUS_SUCCESS) {
		if (pUmPacket->skbuff == NULL) {
			/* Packet was discarded */
			printf ("TX: failed (1)\n");
			status = 1;
		} else {
			printf ("TX: failed (2)\n");
			status = 2;
		}
		QQ_PushHead (&pDevice->TxPacketFreeQ.Container, pPacket);
		return status;
	}

	/* Copy packet to DMA buffer */
	memset (pUmPacket->skbuff, 0x0, MAX_PACKET_SIZE);
	memcpy ((void *)pUmPacket->skbuff, (void *)packet, length);
	pPacket->PacketSize = length;
	pPacket->Flags |= SND_BD_FLAG_END | SND_BD_FLAG_COAL_NOW;
	pPacket->u.Tx.FragCount = 1;
	/* We've already provided a frame ready for transmission */
	pPacket->Flags &= ~SND_BD_FLAG_TCP_UDP_CKSUM;

	if (LM_SendPacket (pDevice, pPacket) == LM_STATUS_FAILURE) {
		/*
		 *  A lower level send failure will push the packet descriptor back
		 *  in the free queue, so just deal with the VxWorks clusters.
		 */
		if (pUmPacket->skbuff == NULL) {
			printf ("TX failed (1)!\n");
			/* Packet was discarded */
			status = 3;
		} else {
			/* A resource problem ... */
			printf ("TX failed (2)!\n");
			status = 4;
		}

		if (QQ_GetEntryCnt (&pDevice->TxPacketFreeQ.Container) == 0) {
			printf ("TX: emptyQ!\n");
			pUmDevice->tx_full = 1;
		}
	}

	while (pUmDevice->tx_pkt == 0) {
		/* Service TX */
		eth_isr ();
	}
#if ET_DEBUG
	printf ("eth_send: 0x%x, %d bytes\n"
		"[%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x] ...\n",
		(int)pPacket, length,
		ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5],
		ptr[6], ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12],
		ptr[13], ptr[14], ptr[15]);
#endif
	pUmDevice->tx_pkt = 0;
	QQ_PushHead (&pDevice->TxPacketFreeQ.Container, pPacket);

	/* Done with send */
      out:
	return status;
}

/* Ethernet receive */
int eth_rx (void)
{
	PLM_PACKET pPacket = NULL;
	PUM_PACKET pUmPacket = NULL;
	void *skb;
	int size = 0;

	while (TRUE) {

	      bcm570x_service_isr:
		/* Pull down packet if it is there */
		eth_isr ();

		/* Indicate RX packets called */
		if (pUmDevice->rx_pkt) {
			/* printf("eth_rx: got a packet...\n"); */
			pUmDevice->rx_pkt = 0;
		} else {
			/* printf("eth_rx: waiting for packet...\n"); */
			goto bcm570x_service_isr;
		}

		pPacket = (PLM_PACKET)
		    QQ_PopHead (&pDevice->RxPacketReceivedQ.Container);

		if (pPacket == 0) {
			printf ("eth_rx: empty packet!\n");
			goto bcm570x_service_isr;
		}

		pUmPacket = (PUM_PACKET) pPacket;
#if ET_DEBUG
		printf ("eth_rx: packet @0x%x\n", (int)pPacket);
#endif
		/* If the packet generated an error, reuse buffer */
		if ((pPacket->PacketStatus != LM_STATUS_SUCCESS) ||
		    ((size = pPacket->PacketSize) > pDevice->RxMtu)) {

			/* reuse skb */
			QQ_PushTail (&pDevice->RxPacketFreeQ.Container,
				     pPacket);
			printf ("eth_rx: error in packet dma!\n");
			goto bcm570x_service_isr;
		}

		/* Set size and address */
		skb = pUmPacket->skbuff;
		size = pPacket->PacketSize;

		/* Pass the packet up to the protocol
		 * layers.
		 */
		NetReceive (skb, size);

		/* Free packet buffer */
		bcm570xPktFree (pUmDevice->index, skb);
		pUmPacket->skbuff = NULL;

		/* Reuse SKB */
		QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);

		return 0;	/* Got a packet, bail ... */
	}
	return size;
}

/* Shut down device */
void eth_halt (void)
{
	int i;
	if (initialized)
		if (pDevice && pUmDevice && pUmDevice->opened) {
			printf ("\neth%d:%s,", pUmDevice->index,
				pUmDevice->name);
			printf ("HALT,");
			/* stop device */
			LM_Halt (pDevice);
			printf ("POWER DOWN,");
			LM_SetPowerState (pDevice, LM_POWER_STATE_D3);

			/* Free the memory allocated by the device in tigon3 */
			for (i = 0; i < pUmDevice->mem_list_num; i++) {
				if (pUmDevice->mem_list[i]) {
					/* sanity check */
					if (pUmDevice->dma_list[i]) {	/* cache-safe memory */
						free (pUmDevice->mem_list[i]);
					} else {
						free (pUmDevice->mem_list[i]);	/* normal memory   */
					}
				}
			}
			pUmDevice->opened = 0;
			free (pDevice);
			pDevice = NULL;
			pUmDevice = NULL;
			initialized = 0;
			printf ("done - offline.\n");
		}
}

/*
 *
 * Middle Module: Interface between the HW driver (tigon3 modules) and
 * the native (SENS) driver.  These routines implement the system
 * interface for tigon3 on VxWorks.
 */

/* Middle module dependency - size of a packet descriptor */
int MM_Packet_Desc_Size = sizeof (UM_PACKET);

LM_STATUS
MM_ReadConfig32 (PLM_DEVICE_BLOCK pDevice,
		 LM_UINT32 Offset, LM_UINT32 * pValue32)
{
	UM_DEVICE_BLOCK *pUmDevice;
	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_read_config_dword (pUmDevice->pdev, Offset, (u32 *) pValue32);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_WriteConfig32 (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT32 Value32)
{
	UM_DEVICE_BLOCK *pUmDevice;
	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_write_config_dword (pUmDevice->pdev, Offset, Value32);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_ReadConfig16 (PLM_DEVICE_BLOCK pDevice,
		 LM_UINT32 Offset, LM_UINT16 * pValue16)
{
	UM_DEVICE_BLOCK *pUmDevice;
	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_read_config_word (pUmDevice->pdev, Offset, (u16 *) pValue16);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_WriteConfig16 (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT16 Value16)
{
	UM_DEVICE_BLOCK *pUmDevice;
	pUmDevice = (UM_DEVICE_BLOCK *) pDevice;
	pci_write_config_word (pUmDevice->pdev, Offset, Value16);
	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_AllocateSharedMemory (PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
			 PLM_VOID * pMemoryBlockVirt,
			 PLM_PHYSICAL_ADDRESS pMemoryBlockPhy, LM_BOOL Cached)
{
	PLM_VOID pvirt;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	dma_addr_t mapping;

	pvirt = malloc (BlockSize);
	mapping = (dma_addr_t) (pvirt);
	if (!pvirt)
		return LM_STATUS_FAILURE;

	pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
	pUmDevice->dma_list[pUmDevice->mem_list_num] = mapping;
	pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
	memset (pvirt, 0, BlockSize);

	*pMemoryBlockVirt = (PLM_VOID) pvirt;
	MM_SetAddr (pMemoryBlockPhy, (dma_addr_t) mapping);

	return LM_STATUS_SUCCESS;
}

LM_STATUS
MM_AllocateMemory (PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
		   PLM_VOID * pMemoryBlockVirt)
{
	PLM_VOID pvirt;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;

	pvirt = malloc (BlockSize);

	if (!pvirt)
		return LM_STATUS_FAILURE;

	pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
	pUmDevice->dma_list[pUmDevice->mem_list_num] = 0;
	pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
	memset (pvirt, 0, BlockSize);
	*pMemoryBlockVirt = pvirt;

	return LM_STATUS_SUCCESS;
}

LM_STATUS MM_MapMemBase (PLM_DEVICE_BLOCK pDevice)
{
	printf ("BCM570x PCI Memory base address @0x%x\n",
		(unsigned int)pDevice->pMappedMemBase);
	return LM_STATUS_SUCCESS;
}

LM_STATUS MM_InitializeUmPackets (PLM_DEVICE_BLOCK pDevice)
{
	int i;
	void *skb;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	PUM_PACKET pUmPacket = NULL;
	PLM_PACKET pPacket = NULL;

	for (i = 0; i < pDevice->RxPacketDescCnt; i++) {
		pPacket = QQ_PopHead (&pDevice->RxPacketFreeQ.Container);
		pUmPacket = (PUM_PACKET) pPacket;

		if (pPacket == 0) {
			printf ("MM_InitializeUmPackets: Bad RxPacketFreeQ\n");
		}

		skb = bcm570xPktAlloc (pUmDevice->index,
				       pPacket->u.Rx.RxBufferSize + 2);

		if (skb == 0) {
			pUmPacket->skbuff = 0;
			QQ_PushTail (&pUmDevice->rx_out_of_buf_q.Container,
				     pPacket);
			printf ("MM_InitializeUmPackets: out of buffer.\n");
			continue;
		}

		pUmPacket->skbuff = skb;
		QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
	}

	pUmDevice->rx_low_buf_thresh = pDevice->RxPacketDescCnt / 8;

	return LM_STATUS_SUCCESS;
}

LM_STATUS MM_GetConfig (PLM_DEVICE_BLOCK pDevice)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	int index = pDevice->index;

	if (auto_speed[index] == 0)
		pDevice->DisableAutoNeg = TRUE;
	else
		pDevice->DisableAutoNeg = FALSE;

	if (line_speed[index] == 0) {
		pDevice->RequestedMediaType = LM_REQUESTED_MEDIA_TYPE_AUTO;
		pDevice->DisableAutoNeg = FALSE;
	} else {
		if (line_speed[index] == 1000) {
			if (pDevice->EnableTbi) {
				pDevice->RequestedMediaType =
				    LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS_FULL_DUPLEX;
			} else if (full_duplex[index]) {
				pDevice->RequestedMediaType =
				    LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS_FULL_DUPLEX;
			} else {
				pDevice->RequestedMediaType =
				    LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS;
			}
			if (!pDevice->EnableTbi)
				pDevice->DisableAutoNeg = FALSE;
		} else if (line_speed[index] == 100) {
			if (full_duplex[index]) {
				pDevice->RequestedMediaType =
				    LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS_FULL_DUPLEX;
			} else {
				pDevice->RequestedMediaType =
				    LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS;
			}
		} else if (line_speed[index] == 10) {
			if (full_duplex[index]) {
				pDevice->RequestedMediaType =
				    LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS_FULL_DUPLEX;
			} else {
				pDevice->RequestedMediaType =
				    LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS;
			}
		} else {
			pDevice->RequestedMediaType =
			    LM_REQUESTED_MEDIA_TYPE_AUTO;
			pDevice->DisableAutoNeg = FALSE;
		}

	}
	pDevice->FlowControlCap = 0;
	if (rx_flow_control[index] != 0) {
		pDevice->FlowControlCap |= LM_FLOW_CONTROL_RECEIVE_PAUSE;
	}
	if (tx_flow_control[index] != 0) {
		pDevice->FlowControlCap |= LM_FLOW_CONTROL_TRANSMIT_PAUSE;
	}
	if ((auto_flow_control[index] != 0) &&
	    (pDevice->DisableAutoNeg == FALSE)) {

		pDevice->FlowControlCap |= LM_FLOW_CONTROL_AUTO_PAUSE;
		if ((tx_flow_control[index] == 0) &&
		    (rx_flow_control[index] == 0)) {
			pDevice->FlowControlCap |=
			    LM_FLOW_CONTROL_TRANSMIT_PAUSE |
			    LM_FLOW_CONTROL_RECEIVE_PAUSE;
		}
	}

	/* Default MTU for now */
	pUmDevice->mtu = 1500;

#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
	if (pUmDevice->mtu > 1500) {
		pDevice->RxMtu = pUmDevice->mtu;
		pDevice->RxJumboDescCnt = DEFAULT_JUMBO_RCV_DESC_COUNT;
	} else {
		pDevice->RxJumboDescCnt = 0;
	}
	pDevice->RxJumboDescCnt = rx_jumbo_desc_cnt[index];
#else
	pDevice->RxMtu = pUmDevice->mtu;
#endif

	if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
		pDevice->UseTaggedStatus = TRUE;
		pUmDevice->timer_interval = CONFIG_SYS_HZ;
	} else {
		pUmDevice->timer_interval = CONFIG_SYS_HZ / 50;
	}

	pDevice->TxPacketDescCnt = tx_pkt_desc_cnt[index];
	pDevice->RxStdDescCnt = rx_std_desc_cnt[index];
	/* Note:  adaptive coalescence really isn't adaptive in this driver */
	pUmDevice->rx_adaptive_coalesce = rx_adaptive_coalesce[index];
	if (!pUmDevice->rx_adaptive_coalesce) {
		pDevice->RxCoalescingTicks = rx_coalesce_ticks[index];
		if (pDevice->RxCoalescingTicks > MAX_RX_COALESCING_TICKS)
			pDevice->RxCoalescingTicks = MAX_RX_COALESCING_TICKS;
		pUmDevice->rx_curr_coalesce_ticks = pDevice->RxCoalescingTicks;

		pDevice->RxMaxCoalescedFrames = rx_max_coalesce_frames[index];
		if (pDevice->RxMaxCoalescedFrames > MAX_RX_MAX_COALESCED_FRAMES)
			pDevice->RxMaxCoalescedFrames =
			    MAX_RX_MAX_COALESCED_FRAMES;
		pUmDevice->rx_curr_coalesce_frames =
		    pDevice->RxMaxCoalescedFrames;
		pDevice->StatsCoalescingTicks = stats_coalesce_ticks[index];
		if (pDevice->StatsCoalescingTicks > MAX_STATS_COALESCING_TICKS)
			pDevice->StatsCoalescingTicks =
			    MAX_STATS_COALESCING_TICKS;
	} else {
		pUmDevice->rx_curr_coalesce_frames =
		    DEFAULT_RX_MAX_COALESCED_FRAMES;
		pUmDevice->rx_curr_coalesce_ticks = DEFAULT_RX_COALESCING_TICKS;
	}
	pDevice->TxCoalescingTicks = tx_coalesce_ticks[index];
	if (pDevice->TxCoalescingTicks > MAX_TX_COALESCING_TICKS)
		pDevice->TxCoalescingTicks = MAX_TX_COALESCING_TICKS;
	pDevice->TxMaxCoalescedFrames = tx_max_coalesce_frames[index];
	if (pDevice->TxMaxCoalescedFrames > MAX_TX_MAX_COALESCED_FRAMES)
		pDevice->TxMaxCoalescedFrames = MAX_TX_MAX_COALESCED_FRAMES;

	if (enable_wol[index]) {
		pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_MAGIC_PACKET;
		pDevice->WakeUpMode = LM_WAKE_UP_MODE_MAGIC_PACKET;
	}
	pDevice->NicSendBd = TRUE;

	/* Don't update status blocks during interrupt */
	pDevice->RxCoalescingTicksDuringInt = 0;
	pDevice->TxCoalescingTicksDuringInt = 0;

	return LM_STATUS_SUCCESS;

}

LM_STATUS MM_StartTxDma (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	printf ("Start TX DMA: dev=%d packet @0x%x\n",
		(int)pUmDevice->index, (unsigned int)pPacket);

	return LM_STATUS_SUCCESS;
}

LM_STATUS MM_CompleteTxDma (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	printf ("Complete TX DMA: dev=%d packet @0x%x\n",
		(int)pUmDevice->index, (unsigned int)pPacket);
	return LM_STATUS_SUCCESS;
}

LM_STATUS MM_IndicateStatus (PLM_DEVICE_BLOCK pDevice, LM_STATUS Status)
{
	char buf[128];
	char lcd[4];
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	LM_FLOW_CONTROL flow_control;

	pUmDevice->delayed_link_ind = 0;
	memset (lcd, 0x0, 4);

	if (Status == LM_STATUS_LINK_DOWN) {
		sprintf (buf, "eth%d: %s: NIC Link is down\n",
			 pUmDevice->index, pUmDevice->name);
		lcd[0] = 'L';
		lcd[1] = 'N';
		lcd[2] = 'K';
		lcd[3] = '?';
	} else if (Status == LM_STATUS_LINK_ACTIVE) {
		sprintf (buf, "eth%d:%s: ", pUmDevice->index, pUmDevice->name);

		if (pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS) {
			strcat (buf, "1000 Mbps ");
			lcd[0] = '1';
			lcd[1] = 'G';
			lcd[2] = 'B';
		} else if (pDevice->LineSpeed == LM_LINE_SPEED_100MBPS) {
			strcat (buf, "100 Mbps ");
			lcd[0] = '1';
			lcd[1] = '0';
			lcd[2] = '0';
		} else if (pDevice->LineSpeed == LM_LINE_SPEED_10MBPS) {
			strcat (buf, "10 Mbps ");
			lcd[0] = '1';
			lcd[1] = '0';
			lcd[2] = ' ';
		}
		if (pDevice->DuplexMode == LM_DUPLEX_MODE_FULL) {
			strcat (buf, "full duplex");
			lcd[3] = 'F';
		} else {
			strcat (buf, "half duplex");
			lcd[3] = 'H';
		}
		strcat (buf, " link up");

		flow_control = pDevice->FlowControl &
		    (LM_FLOW_CONTROL_RECEIVE_PAUSE |
		     LM_FLOW_CONTROL_TRANSMIT_PAUSE);

		if (flow_control) {
			if (flow_control & LM_FLOW_CONTROL_RECEIVE_PAUSE) {
				strcat (buf, ", receive ");
				if (flow_control &
				    LM_FLOW_CONTROL_TRANSMIT_PAUSE)
					strcat (buf, " & transmit ");
			} else {
				strcat (buf, ", transmit ");
			}
			strcat (buf, "flow control ON");
		} else {
			strcat (buf, ", flow control OFF");
		}
		strcat (buf, "\n");
		printf ("%s", buf);
	}
#if 0
	sysLedDsply (lcd[0], lcd[1], lcd[2], lcd[3]);
#endif
	return LM_STATUS_SUCCESS;
}

LM_STATUS MM_FreeRxBuffer (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{

	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	PUM_PACKET pUmPacket;
	void *skb;

	pUmPacket = (PUM_PACKET) pPacket;

	if ((skb = pUmPacket->skbuff))
		bcm570xPktFree (pUmDevice->index, skb);

	pUmPacket->skbuff = 0;

	return LM_STATUS_SUCCESS;
}

unsigned long MM_AnGetCurrentTime_us (PAN_STATE_INFO pAnInfo)
{
	return get_timer (0);
}

/*
 *   Transform an MBUF chain into a single MBUF.
 *   This routine will fail if the amount of data in the
 *   chain overflows a transmit buffer.  In that case,
 *   the incoming MBUF chain will be freed.  This routine can
 *   also fail by not being able to allocate a new MBUF (including
 *   cluster and mbuf headers).  In that case the failure is
 *   non-fatal.  The incoming cluster chain is not freed, giving
 *   the caller the choice of whether to try a retransmit later.
 */
LM_STATUS MM_CoalesceTxBuffer (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
	PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	void *skbnew;
	int len = 0;

	if (len == 0)
		return (LM_STATUS_SUCCESS);

	if (len > MAX_PACKET_SIZE) {
		printf ("eth%d: xmit frame discarded, too big!, size = %d\n",
			pUmDevice->index, len);
		return (LM_STATUS_FAILURE);
	}

	skbnew = bcm570xPktAlloc (pUmDevice->index, MAX_PACKET_SIZE);

	if (skbnew == NULL) {
		pUmDevice->tx_full = 1;
		printf ("eth%d: out of transmit buffers", pUmDevice->index);
		return (LM_STATUS_FAILURE);
	}

	/* New packet values */
	pUmPacket->skbuff = skbnew;
	pUmPacket->lm_packet.u.Tx.FragCount = 1;

	return (LM_STATUS_SUCCESS);
}

LM_STATUS MM_IndicateRxPackets (PLM_DEVICE_BLOCK pDevice)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	pUmDevice->rx_pkt = 1;
	return LM_STATUS_SUCCESS;
}

LM_STATUS MM_IndicateTxPackets (PLM_DEVICE_BLOCK pDevice)
{
	PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
	PLM_PACKET pPacket;
	PUM_PACKET pUmPacket;
	void *skb;
	while (TRUE) {

		pPacket = (PLM_PACKET)
		    QQ_PopHead (&pDevice->TxPacketXmittedQ.Container);

		if (pPacket == 0)
			break;

		pUmPacket = (PUM_PACKET) pPacket;
		skb = (void *)pUmPacket->skbuff;

		/*
		 * Free MBLK if we transmitted a fragmented packet or a
		 * non-fragmented packet straight from the VxWorks
		 * buffer pool. If packet was copied to a local transmit
		 * buffer, then there's no MBUF to free, just free
		 * the transmit buffer back to the cluster pool.
		 */

		if (skb)
			bcm570xPktFree (pUmDevice->index, skb);

		pUmPacket->skbuff = 0;
		QQ_PushTail (&pDevice->TxPacketFreeQ.Container, pPacket);
		pUmDevice->tx_pkt = 1;
	}
	if (pUmDevice->tx_full) {
		if (QQ_GetEntryCnt (&pDevice->TxPacketFreeQ.Container) >=
		    (QQ_GetSize (&pDevice->TxPacketFreeQ.Container) >> 1))
			pUmDevice->tx_full = 0;
	}
	return LM_STATUS_SUCCESS;
}

/*
 *  Scan an MBUF chain until we reach fragment number "frag"
 *  Return its length and physical address.
 */
void MM_MapTxDma
    (PLM_DEVICE_BLOCK pDevice,
     struct _LM_PACKET *pPacket,
     T3_64BIT_HOST_ADDR * paddr, LM_UINT32 * len, int frag) {
	PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
	*len = pPacket->PacketSize;
	MM_SetT3Addr (paddr, (dma_addr_t) pUmPacket->skbuff);
}

/*
 *  Convert an mbuf address, a CPU local virtual address,
 *  to a physical address as seen from a PCI device.  Store the
 *  result at paddr.
 */
void MM_MapRxDma (PLM_DEVICE_BLOCK pDevice,
		  struct _LM_PACKET *pPacket, T3_64BIT_HOST_ADDR * paddr)
{
	PUM_PACKET pUmPacket = (PUM_PACKET) pPacket;
	MM_SetT3Addr (paddr, (dma_addr_t) pUmPacket->skbuff);
}

void MM_SetAddr (LM_PHYSICAL_ADDRESS * paddr, dma_addr_t addr)
{
#if (BITS_PER_LONG == 64)
	paddr->High = ((unsigned long)addr) >> 32;
	paddr->Low = ((unsigned long)addr) & 0xffffffff;
#else
	paddr->High = 0;
	paddr->Low = (unsigned long)addr;
#endif
}

void MM_SetT3Addr (T3_64BIT_HOST_ADDR * paddr, dma_addr_t addr)
{
	unsigned long baddr = (unsigned long)addr;
#if (BITS_PER_LONG == 64)
	set_64bit_addr (paddr, baddr & 0xffffffff, baddr >> 32);
#else
	set_64bit_addr (paddr, baddr, 0);
#endif
}

/*
 * This combination of `inline' and `extern' has almost the effect of a
 * macro.  The way to use it is to put a function definition in a header
 * file with these keywords, and put another copy of the definition
 * (lacking `inline' and `extern') in a library file.  The definition in
 * the header file will cause most calls to the function to be inlined.
 * If any uses of the function remain, they will refer to the single copy
 * in the library.
 */
void atomic_set (atomic_t * entry, int val)
{
	entry->counter = val;
}

int atomic_read (atomic_t * entry)
{
	return entry->counter;
}

void atomic_inc (atomic_t * entry)
{
	if (entry)
		entry->counter++;
}

void atomic_dec (atomic_t * entry)
{
	if (entry)
		entry->counter--;
}

void atomic_sub (int a, atomic_t * entry)
{
	if (entry)
		entry->counter -= a;
}

void atomic_add (int a, atomic_t * entry)
{
	if (entry)
		entry->counter += a;
}

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
void QQ_InitQueue (PQQ_CONTAINER pQueue, unsigned int QueueSize)
{
	pQueue->Head = 0;
	pQueue->Tail = 0;
	pQueue->Size = QueueSize + 1;
	atomic_set (&pQueue->EntryCnt, 0);
}				/* QQ_InitQueue */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
char QQ_Full (PQQ_CONTAINER pQueue)
{
	unsigned int NewHead;

	NewHead = (pQueue->Head + 1) % pQueue->Size;

	return (NewHead == pQueue->Tail);
}				/* QQ_Full */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
char QQ_Empty (PQQ_CONTAINER pQueue)
{
	return (pQueue->Head == pQueue->Tail);
}				/* QQ_Empty */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
unsigned int QQ_GetSize (PQQ_CONTAINER pQueue)
{
	return pQueue->Size;
}				/* QQ_GetSize */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
unsigned int QQ_GetEntryCnt (PQQ_CONTAINER pQueue)
{
	return atomic_read (&pQueue->EntryCnt);
}				/* QQ_GetEntryCnt */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/*    TRUE entry was added successfully.                                      */
/*    FALSE queue is full.                                                    */
/******************************************************************************/
char QQ_PushHead (PQQ_CONTAINER pQueue, PQQ_ENTRY pEntry)
{
	unsigned int Head;

	Head = (pQueue->Head + 1) % pQueue->Size;

#if !defined(QQ_NO_OVERFLOW_CHECK)
	if (Head == pQueue->Tail) {
		return 0;
	}			/* if */
#endif				/* QQ_NO_OVERFLOW_CHECK */

	pQueue->Array[pQueue->Head] = pEntry;
	wmb ();
	pQueue->Head = Head;
	atomic_inc (&pQueue->EntryCnt);

	return -1;
}				/* QQ_PushHead */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/*    TRUE entry was added successfully.                                      */
/*    FALSE queue is full.                                                    */
/******************************************************************************/
char QQ_PushTail (PQQ_CONTAINER pQueue, PQQ_ENTRY pEntry)
{
	unsigned int Tail;

	Tail = pQueue->Tail;
	if (Tail == 0) {
		Tail = pQueue->Size;
	}			/* if */
	Tail--;

#if !defined(QQ_NO_OVERFLOW_CHECK)
	if (Tail == pQueue->Head) {
		return 0;
	}			/* if */
#endif				/* QQ_NO_OVERFLOW_CHECK */

	pQueue->Array[Tail] = pEntry;
	wmb ();
	pQueue->Tail = Tail;
	atomic_inc (&pQueue->EntryCnt);

	return -1;
}				/* QQ_PushTail */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY QQ_PopHead (PQQ_CONTAINER pQueue)
{
	unsigned int Head;
	PQQ_ENTRY Entry;

	Head = pQueue->Head;

#if !defined(QQ_NO_UNDERFLOW_CHECK)
	if (Head == pQueue->Tail) {
		return (PQQ_ENTRY) 0;
	}			/* if */
#endif				/* QQ_NO_UNDERFLOW_CHECK */

	if (Head == 0) {
		Head = pQueue->Size;
	}			/* if */
	Head--;

	Entry = pQueue->Array[Head];
	membar ();

	pQueue->Head = Head;
	atomic_dec (&pQueue->EntryCnt);

	return Entry;
}				/* QQ_PopHead */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY QQ_PopTail (PQQ_CONTAINER pQueue)
{
	unsigned int Tail;
	PQQ_ENTRY Entry;

	Tail = pQueue->Tail;

#if !defined(QQ_NO_UNDERFLOW_CHECK)
	if (Tail == pQueue->Head) {
		return (PQQ_ENTRY) 0;
	}			/* if */
#endif				/* QQ_NO_UNDERFLOW_CHECK */

	Entry = pQueue->Array[Tail];
	membar ();
	pQueue->Tail = (Tail + 1) % pQueue->Size;
	atomic_dec (&pQueue->EntryCnt);

	return Entry;
}				/* QQ_PopTail */

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY QQ_GetHead (PQQ_CONTAINER pQueue, unsigned int Idx)
{
	if (Idx >= atomic_read (&pQueue->EntryCnt)) {
		return (PQQ_ENTRY) 0;
	}

	if (pQueue->Head > Idx) {
		Idx = pQueue->Head - Idx;
	} else {
		Idx = pQueue->Size - (Idx - pQueue->Head);
	}
	Idx--;

	return pQueue->Array[Idx];
}

/******************************************************************************/
/* Description:                                                               */
/*                                                                            */
/* Return:                                                                    */
/******************************************************************************/
PQQ_ENTRY QQ_GetTail (PQQ_CONTAINER pQueue, unsigned int Idx)
{
	if (Idx >= atomic_read (&pQueue->EntryCnt)) {
		return (PQQ_ENTRY) 0;
	}

	Idx += pQueue->Tail;
	if (Idx >= pQueue->Size) {
		Idx = Idx - pQueue->Size;
	}

	return pQueue->Array[Idx];
}