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
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
|
/*******************************************************************************
Copyright (c) 2001-2004, Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
/*$FreeBSD$*/
#ifdef HAVE_KERNEL_OPTION_HEADERS
#include "opt_device_polling.h"
#endif
#include <dev/ixgb/if_ixgb.h>
/*********************************************************************
* Set this to one to display debug statistics
*********************************************************************/
int ixgb_display_debug_stats = 0;
/*********************************************************************
* Linked list of board private structures for all NICs found
*********************************************************************/
struct adapter *ixgb_adapter_list = NULL;
/*********************************************************************
* Driver version
*********************************************************************/
char ixgb_driver_version[] = "1.0.6";
char ixgb_copyright[] = "Copyright (c) 2001-2004 Intel Corporation.";
/*********************************************************************
* PCI Device ID Table
*
* Used by probe to select devices to load on
* Last field stores an index into ixgb_strings
* Last entry must be all 0s
*
* { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
*********************************************************************/
static ixgb_vendor_info_t ixgb_vendor_info_array[] =
{
/* Intel(R) PRO/10000 Network Connection */
{INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX, PCI_ANY_ID, PCI_ANY_ID, 0},
{INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR, PCI_ANY_ID, PCI_ANY_ID, 0},
/* required last entry */
{0, 0, 0, 0, 0}
};
/*********************************************************************
* Table of branding strings for all supported NICs.
*********************************************************************/
static char *ixgb_strings[] = {
"Intel(R) PRO/10GbE Network Driver"
};
/*********************************************************************
* Function prototypes
*********************************************************************/
static int ixgb_probe(device_t);
static int ixgb_attach(device_t);
static int ixgb_detach(device_t);
static int ixgb_shutdown(device_t);
static void ixgb_intr(void *);
static void ixgb_start(struct ifnet *);
static void ixgb_start_locked(struct ifnet *);
static int ixgb_ioctl(struct ifnet *, IOCTL_CMD_TYPE, caddr_t);
static void ixgb_watchdog(struct ifnet *);
static void ixgb_init(void *);
static void ixgb_init_locked(struct adapter *);
static void ixgb_stop(void *);
static void ixgb_media_status(struct ifnet *, struct ifmediareq *);
static int ixgb_media_change(struct ifnet *);
static void ixgb_identify_hardware(struct adapter *);
static int ixgb_allocate_pci_resources(struct adapter *);
static void ixgb_free_pci_resources(struct adapter *);
static void ixgb_local_timer(void *);
static int ixgb_hardware_init(struct adapter *);
static void ixgb_setup_interface(device_t, struct adapter *);
static int ixgb_setup_transmit_structures(struct adapter *);
static void ixgb_initialize_transmit_unit(struct adapter *);
static int ixgb_setup_receive_structures(struct adapter *);
static void ixgb_initialize_receive_unit(struct adapter *);
static void ixgb_enable_intr(struct adapter *);
static void ixgb_disable_intr(struct adapter *);
static void ixgb_free_transmit_structures(struct adapter *);
static void ixgb_free_receive_structures(struct adapter *);
static void ixgb_update_stats_counters(struct adapter *);
static void ixgb_clean_transmit_interrupts(struct adapter *);
static int ixgb_allocate_receive_structures(struct adapter *);
static int ixgb_allocate_transmit_structures(struct adapter *);
static void ixgb_process_receive_interrupts(struct adapter *, int);
static void
ixgb_receive_checksum(struct adapter *,
struct ixgb_rx_desc * rx_desc,
struct mbuf *);
static void
ixgb_transmit_checksum_setup(struct adapter *,
struct mbuf *,
u_int8_t *);
static void ixgb_set_promisc(struct adapter *);
static void ixgb_disable_promisc(struct adapter *);
static void ixgb_set_multi(struct adapter *);
static void ixgb_print_hw_stats(struct adapter *);
static void ixgb_print_link_status(struct adapter *);
static int
ixgb_get_buf(int i, struct adapter *,
struct mbuf *);
static void ixgb_enable_vlans(struct adapter * adapter);
static int ixgb_encap(struct adapter * adapter, struct mbuf * m_head);
static int ixgb_sysctl_stats(SYSCTL_HANDLER_ARGS);
static int
ixgb_dma_malloc(struct adapter *, bus_size_t,
struct ixgb_dma_alloc *, int);
static void ixgb_dma_free(struct adapter *, struct ixgb_dma_alloc *);
#ifdef DEVICE_POLLING
static poll_handler_t ixgb_poll;
#endif
/*********************************************************************
* FreeBSD Device Interface Entry Points
*********************************************************************/
static device_method_t ixgb_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, ixgb_probe),
DEVMETHOD(device_attach, ixgb_attach),
DEVMETHOD(device_detach, ixgb_detach),
DEVMETHOD(device_shutdown, ixgb_shutdown),
{0, 0}
};
static driver_t ixgb_driver = {
"ixgb", ixgb_methods, sizeof(struct adapter),
};
static devclass_t ixgb_devclass;
DRIVER_MODULE(if_ixgb, pci, ixgb_driver, ixgb_devclass, 0, 0);
MODULE_DEPEND(if_ixgb, pci, 1, 1, 1);
MODULE_DEPEND(if_ixgb, ether, 1, 1, 1);
/* some defines for controlling descriptor fetches in h/w */
#define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */
#define RXDCTL_HTHRESH_DEFAULT 16 /* chip will only prefetch if tail is
* pushed this many descriptors from
* head */
#define RXDCTL_WTHRESH_DEFAULT 0 /* chip writes back at this many or RXT0 */
/*********************************************************************
* Device identification routine
*
* ixgb_probe determines if the driver should be loaded on
* adapter based on PCI vendor/device id of the adapter.
*
* return 0 on success, positive on failure
*********************************************************************/
static int
ixgb_probe(device_t dev)
{
ixgb_vendor_info_t *ent;
u_int16_t pci_vendor_id = 0;
u_int16_t pci_device_id = 0;
u_int16_t pci_subvendor_id = 0;
u_int16_t pci_subdevice_id = 0;
char adapter_name[60];
INIT_DEBUGOUT("ixgb_probe: begin");
pci_vendor_id = pci_get_vendor(dev);
if (pci_vendor_id != IXGB_VENDOR_ID)
return (ENXIO);
pci_device_id = pci_get_device(dev);
pci_subvendor_id = pci_get_subvendor(dev);
pci_subdevice_id = pci_get_subdevice(dev);
ent = ixgb_vendor_info_array;
while (ent->vendor_id != 0) {
if ((pci_vendor_id == ent->vendor_id) &&
(pci_device_id == ent->device_id) &&
((pci_subvendor_id == ent->subvendor_id) ||
(ent->subvendor_id == PCI_ANY_ID)) &&
((pci_subdevice_id == ent->subdevice_id) ||
(ent->subdevice_id == PCI_ANY_ID))) {
sprintf(adapter_name, "%s, Version - %s",
ixgb_strings[ent->index],
ixgb_driver_version);
device_set_desc_copy(dev, adapter_name);
return (BUS_PROBE_DEFAULT);
}
ent++;
}
return (ENXIO);
}
/*********************************************************************
* Device initialization routine
*
* The attach entry point is called when the driver is being loaded.
* This routine identifies the type of hardware, allocates all resources
* and initializes the hardware.
*
* return 0 on success, positive on failure
*********************************************************************/
static int
ixgb_attach(device_t dev)
{
struct adapter *adapter;
int tsize, rsize;
int error = 0;
printf("ixgb%d: %s\n", device_get_unit(dev), ixgb_copyright);
INIT_DEBUGOUT("ixgb_attach: begin");
/* Allocate, clear, and link in our adapter structure */
if (!(adapter = device_get_softc(dev))) {
printf("ixgb: adapter structure allocation failed\n");
return (ENOMEM);
}
bzero(adapter, sizeof(struct adapter));
adapter->dev = dev;
adapter->osdep.dev = dev;
adapter->unit = device_get_unit(dev);
IXGB_LOCK_INIT(adapter, device_get_nameunit(dev));
if (ixgb_adapter_list != NULL)
ixgb_adapter_list->prev = adapter;
adapter->next = ixgb_adapter_list;
ixgb_adapter_list = adapter;
/* SYSCTL APIs */
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "stats", CTLTYPE_INT | CTLFLAG_RW,
(void *)adapter, 0,
ixgb_sysctl_stats, "I", "Statistics");
callout_init(&adapter->timer, CALLOUT_MPSAFE);
/* Determine hardware revision */
ixgb_identify_hardware(adapter);
/* Parameters (to be read from user) */
adapter->num_tx_desc = IXGB_MAX_TXD;
adapter->num_rx_desc = IXGB_MAX_RXD;
adapter->tx_int_delay = TIDV;
adapter->rx_int_delay = RDTR;
adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
adapter->hw.fc.high_water = FCRTH;
adapter->hw.fc.low_water = FCRTL;
adapter->hw.fc.pause_time = FCPAUSE;
adapter->hw.fc.send_xon = TRUE;
adapter->hw.fc.type = FLOW_CONTROL;
/* Set the max frame size assuming standard ethernet sized frames */
adapter->hw.max_frame_size =
ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN;
if (ixgb_allocate_pci_resources(adapter)) {
printf("ixgb%d: Allocation of PCI resources failed\n",
adapter->unit);
error = ENXIO;
goto err_pci;
}
tsize = IXGB_ROUNDUP(adapter->num_tx_desc *
sizeof(struct ixgb_tx_desc), 4096);
/* Allocate Transmit Descriptor ring */
if (ixgb_dma_malloc(adapter, tsize, &adapter->txdma, BUS_DMA_NOWAIT)) {
printf("ixgb%d: Unable to allocate TxDescriptor memory\n",
adapter->unit);
error = ENOMEM;
goto err_tx_desc;
}
adapter->tx_desc_base = (struct ixgb_tx_desc *) adapter->txdma.dma_vaddr;
rsize = IXGB_ROUNDUP(adapter->num_rx_desc *
sizeof(struct ixgb_rx_desc), 4096);
/* Allocate Receive Descriptor ring */
if (ixgb_dma_malloc(adapter, rsize, &adapter->rxdma, BUS_DMA_NOWAIT)) {
printf("ixgb%d: Unable to allocate rx_desc memory\n",
adapter->unit);
error = ENOMEM;
goto err_rx_desc;
}
adapter->rx_desc_base = (struct ixgb_rx_desc *) adapter->rxdma.dma_vaddr;
/* Initialize the hardware */
if (ixgb_hardware_init(adapter)) {
printf("ixgb%d: Unable to initialize the hardware\n",
adapter->unit);
error = EIO;
goto err_hw_init;
}
/* Setup OS specific network interface */
ixgb_setup_interface(dev, adapter);
/* Initialize statistics */
ixgb_clear_hw_cntrs(&adapter->hw);
ixgb_update_stats_counters(adapter);
INIT_DEBUGOUT("ixgb_attach: end");
return (0);
err_hw_init:
ixgb_dma_free(adapter, &adapter->rxdma);
err_rx_desc:
ixgb_dma_free(adapter, &adapter->txdma);
err_tx_desc:
err_pci:
ixgb_free_pci_resources(adapter);
sysctl_ctx_free(&adapter->sysctl_ctx);
return (error);
}
/*********************************************************************
* Device removal routine
*
* The detach entry point is called when the driver is being removed.
* This routine stops the adapter and deallocates all the resources
* that were allocated for driver operation.
*
* return 0 on success, positive on failure
*********************************************************************/
static int
ixgb_detach(device_t dev)
{
struct adapter *adapter = device_get_softc(dev);
struct ifnet *ifp = adapter->ifp;
INIT_DEBUGOUT("ixgb_detach: begin");
#ifdef DEVICE_POLLING
if (ifp->if_capenable & IFCAP_POLLING)
ether_poll_deregister(ifp);
#endif
IXGB_LOCK(adapter);
adapter->in_detach = 1;
ixgb_stop(adapter);
IXGB_UNLOCK(adapter);
#if __FreeBSD_version < 500000
ether_ifdetach(adapter->ifp, ETHER_BPF_SUPPORTED);
#else
ether_ifdetach(adapter->ifp);
#endif
ixgb_free_pci_resources(adapter);
#if __FreeBSD_version >= 500000
if_free(adapter->ifp);
#endif
/* Free Transmit Descriptor ring */
if (adapter->tx_desc_base) {
ixgb_dma_free(adapter, &adapter->txdma);
adapter->tx_desc_base = NULL;
}
/* Free Receive Descriptor ring */
if (adapter->rx_desc_base) {
ixgb_dma_free(adapter, &adapter->rxdma);
adapter->rx_desc_base = NULL;
}
/* Remove from the adapter list */
if (ixgb_adapter_list == adapter)
ixgb_adapter_list = adapter->next;
if (adapter->next != NULL)
adapter->next->prev = adapter->prev;
if (adapter->prev != NULL)
adapter->prev->next = adapter->next;
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
ifp->if_timer = 0;
IXGB_LOCK_DESTROY(adapter);
return (0);
}
/*********************************************************************
*
* Shutdown entry point
*
**********************************************************************/
static int
ixgb_shutdown(device_t dev)
{
struct adapter *adapter = device_get_softc(dev);
IXGB_LOCK(adapter);
ixgb_stop(adapter);
IXGB_UNLOCK(adapter);
return (0);
}
/*********************************************************************
* Transmit entry point
*
* ixgb_start is called by the stack to initiate a transmit.
* The driver will remain in this routine as long as there are
* packets to transmit and transmit resources are available.
* In case resources are not available stack is notified and
* the packet is requeued.
**********************************************************************/
static void
ixgb_start_locked(struct ifnet * ifp)
{
struct mbuf *m_head;
struct adapter *adapter = ifp->if_softc;
IXGB_LOCK_ASSERT(adapter);
if (!adapter->link_active)
return;
while (ifp->if_snd.ifq_head != NULL) {
IF_DEQUEUE(&ifp->if_snd, m_head);
if (m_head == NULL)
break;
if (ixgb_encap(adapter, m_head)) {
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
IF_PREPEND(&ifp->if_snd, m_head);
break;
}
/* Send a copy of the frame to the BPF listener */
#if __FreeBSD_version < 500000
if (ifp->if_bpf)
bpf_mtap(ifp, m_head);
#else
ETHER_BPF_MTAP(ifp, m_head);
#endif
/* Set timeout in case hardware has problems transmitting */
ifp->if_timer = IXGB_TX_TIMEOUT;
}
return;
}
static void
ixgb_start(struct ifnet *ifp)
{
struct adapter *adapter = ifp->if_softc;
IXGB_LOCK(adapter);
ixgb_start_locked(ifp);
IXGB_UNLOCK(adapter);
return;
}
/*********************************************************************
* Ioctl entry point
*
* ixgb_ioctl is called when the user wants to configure the
* interface.
*
* return 0 on success, positive on failure
**********************************************************************/
static int
ixgb_ioctl(struct ifnet * ifp, IOCTL_CMD_TYPE command, caddr_t data)
{
int mask, error = 0;
struct ifreq *ifr = (struct ifreq *) data;
struct adapter *adapter = ifp->if_softc;
if (adapter->in_detach)
goto out;
switch (command) {
case SIOCSIFADDR:
case SIOCGIFADDR:
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)");
ether_ioctl(ifp, command, data);
break;
case SIOCSIFMTU:
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFMTU (Set Interface MTU)");
if (ifr->ifr_mtu > IXGB_MAX_JUMBO_FRAME_SIZE - ETHER_HDR_LEN) {
error = EINVAL;
} else {
IXGB_LOCK(adapter);
ifp->if_mtu = ifr->ifr_mtu;
adapter->hw.max_frame_size =
ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
ixgb_init_locked(adapter);
IXGB_UNLOCK(adapter);
}
break;
case SIOCSIFFLAGS:
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFFLAGS (Set Interface Flags)");
IXGB_LOCK(adapter);
if (ifp->if_flags & IFF_UP) {
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
ixgb_init_locked(adapter);
}
ixgb_disable_promisc(adapter);
ixgb_set_promisc(adapter);
} else {
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
ixgb_stop(adapter);
}
}
IXGB_UNLOCK(adapter);
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
IOCTL_DEBUGOUT("ioctl rcv'd: SIOC(ADD|DEL)MULTI");
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
IXGB_LOCK(adapter);
ixgb_disable_intr(adapter);
ixgb_set_multi(adapter);
ixgb_enable_intr(adapter);
IXGB_UNLOCK(adapter);
}
break;
case SIOCSIFMEDIA:
case SIOCGIFMEDIA:
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFMEDIA (Get/Set Interface Media)");
error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
break;
case SIOCSIFCAP:
IOCTL_DEBUGOUT("ioctl rcv'd: SIOCSIFCAP (Set Capabilities)");
mask = ifr->ifr_reqcap ^ ifp->if_capenable;
#ifdef DEVICE_POLLING
if (mask & IFCAP_POLLING) {
if (ifr->ifr_reqcap & IFCAP_POLLING) {
error = ether_poll_register(ixgb_poll, ifp);
if (error)
return(error);
IXGB_LOCK(adapter);
ixgb_disable_intr(adapter);
ifp->if_capenable |= IFCAP_POLLING;
IXGB_UNLOCK(adapter);
} else {
error = ether_poll_deregister(ifp);
/* Enable interrupt even in error case */
IXGB_LOCK(adapter);
ixgb_enable_intr(adapter);
ifp->if_capenable &= ~IFCAP_POLLING;
IXGB_UNLOCK(adapter);
}
}
#endif /* DEVICE_POLLING */
if (mask & IFCAP_HWCSUM) {
if (IFCAP_HWCSUM & ifp->if_capenable)
ifp->if_capenable &= ~IFCAP_HWCSUM;
else
ifp->if_capenable |= IFCAP_HWCSUM;
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
ixgb_init(adapter);
}
break;
default:
IOCTL_DEBUGOUT1("ioctl received: UNKNOWN (0x%X)\n", (int)command);
error = EINVAL;
}
out:
return (error);
}
/*********************************************************************
* Watchdog entry point
*
* This routine is called whenever hardware quits transmitting.
*
**********************************************************************/
static void
ixgb_watchdog(struct ifnet * ifp)
{
struct adapter *adapter;
adapter = ifp->if_softc;
/*
* If we are in this routine because of pause frames, then don't
* reset the hardware.
*/
if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_TXOFF) {
ifp->if_timer = IXGB_TX_TIMEOUT;
return;
}
printf("ixgb%d: watchdog timeout -- resetting\n", adapter->unit);
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
ixgb_stop(adapter);
ixgb_init(adapter);
ifp->if_oerrors++;
return;
}
/*********************************************************************
* Init entry point
*
* This routine is used in two ways. It is used by the stack as
* init entry point in network interface structure. It is also used
* by the driver as a hw/sw initialization routine to get to a
* consistent state.
*
* return 0 on success, positive on failure
**********************************************************************/
static void
ixgb_init_locked(struct adapter *adapter)
{
struct ifnet *ifp;
INIT_DEBUGOUT("ixgb_init: begin");
IXGB_LOCK_ASSERT(adapter);
ixgb_stop(adapter);
/* Get the latest mac address, User can use a LAA */
bcopy(IF_LLADDR(adapter->ifp), adapter->hw.curr_mac_addr,
IXGB_ETH_LENGTH_OF_ADDRESS);
/* Initialize the hardware */
if (ixgb_hardware_init(adapter)) {
printf("ixgb%d: Unable to initialize the hardware\n",
adapter->unit);
return;
}
ixgb_enable_vlans(adapter);
/* Prepare transmit descriptors and buffers */
if (ixgb_setup_transmit_structures(adapter)) {
printf("ixgb%d: Could not setup transmit structures\n",
adapter->unit);
ixgb_stop(adapter);
return;
}
ixgb_initialize_transmit_unit(adapter);
/* Setup Multicast table */
ixgb_set_multi(adapter);
/* Prepare receive descriptors and buffers */
if (ixgb_setup_receive_structures(adapter)) {
printf("ixgb%d: Could not setup receive structures\n",
adapter->unit);
ixgb_stop(adapter);
return;
}
ixgb_initialize_receive_unit(adapter);
/* Don't lose promiscuous settings */
ixgb_set_promisc(adapter);
ifp = adapter->ifp;
ifp->if_drv_flags |= IFF_DRV_RUNNING;
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
if (ifp->if_capenable & IFCAP_TXCSUM)
ifp->if_hwassist = IXGB_CHECKSUM_FEATURES;
else
ifp->if_hwassist = 0;
/* Enable jumbo frames */
if (ifp->if_mtu > ETHERMTU) {
uint32_t temp_reg;
IXGB_WRITE_REG(&adapter->hw, MFS,
adapter->hw.max_frame_size << IXGB_MFS_SHIFT);
temp_reg = IXGB_READ_REG(&adapter->hw, CTRL0);
temp_reg |= IXGB_CTRL0_JFE;
IXGB_WRITE_REG(&adapter->hw, CTRL0, temp_reg);
}
callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter);
ixgb_clear_hw_cntrs(&adapter->hw);
#ifdef DEVICE_POLLING
/*
* Only disable interrupts if we are polling, make sure they are on
* otherwise.
*/
if (ifp->if_capenable & IFCAP_POLLING)
ixgb_disable_intr(adapter);
else
#endif
ixgb_enable_intr(adapter);
return;
}
static void
ixgb_init(void *arg)
{
struct adapter *adapter = arg;
IXGB_LOCK(adapter);
ixgb_init_locked(adapter);
IXGB_UNLOCK(adapter);
return;
}
#ifdef DEVICE_POLLING
static void
ixgb_poll_locked(struct ifnet * ifp, enum poll_cmd cmd, int count)
{
struct adapter *adapter = ifp->if_softc;
u_int32_t reg_icr;
IXGB_LOCK_ASSERT(adapter);
if (cmd == POLL_AND_CHECK_STATUS) {
reg_icr = IXGB_READ_REG(&adapter->hw, ICR);
if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) {
callout_stop(&adapter->timer);
ixgb_check_for_link(&adapter->hw);
ixgb_print_link_status(adapter);
callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer,
adapter);
}
}
ixgb_process_receive_interrupts(adapter, count);
ixgb_clean_transmit_interrupts(adapter);
if (ifp->if_snd.ifq_head != NULL)
ixgb_start_locked(ifp);
}
static void
ixgb_poll(struct ifnet * ifp, enum poll_cmd cmd, int count)
{
struct adapter *adapter = ifp->if_softc;
IXGB_LOCK(adapter);
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
ixgb_poll_locked(ifp, cmd, count);
IXGB_UNLOCK(adapter);
}
#endif /* DEVICE_POLLING */
/*********************************************************************
*
* Interrupt Service routine
*
**********************************************************************/
static void
ixgb_intr(void *arg)
{
u_int32_t loop_cnt = IXGB_MAX_INTR;
u_int32_t reg_icr;
struct ifnet *ifp;
struct adapter *adapter = arg;
boolean_t rxdmt0 = FALSE;
IXGB_LOCK(adapter);
ifp = adapter->ifp;
#ifdef DEVICE_POLLING
if (ifp->if_capenable & IFCAP_POLLING) {
IXGB_UNLOCK(adapter);
return;
}
#endif
reg_icr = IXGB_READ_REG(&adapter->hw, ICR);
if (reg_icr == 0) {
IXGB_UNLOCK(adapter);
return;
}
if (reg_icr & IXGB_INT_RXDMT0)
rxdmt0 = TRUE;
#ifdef _SV_
if (reg_icr & IXGB_INT_RXDMT0)
adapter->sv_stats.icr_rxdmt0++;
if (reg_icr & IXGB_INT_RXO)
adapter->sv_stats.icr_rxo++;
if (reg_icr & IXGB_INT_RXT0)
adapter->sv_stats.icr_rxt0++;
if (reg_icr & IXGB_INT_TXDW)
adapter->sv_stats.icr_TXDW++;
#endif /* _SV_ */
/* Link status change */
if (reg_icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)) {
callout_stop(&adapter->timer);
ixgb_check_for_link(&adapter->hw);
ixgb_print_link_status(adapter);
callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer,
adapter);
}
while (loop_cnt > 0) {
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
ixgb_process_receive_interrupts(adapter, -1);
ixgb_clean_transmit_interrupts(adapter);
}
loop_cnt--;
}
if (rxdmt0 && adapter->raidc) {
IXGB_WRITE_REG(&adapter->hw, IMC, IXGB_INT_RXDMT0);
IXGB_WRITE_REG(&adapter->hw, IMS, IXGB_INT_RXDMT0);
}
if (ifp->if_drv_flags & IFF_DRV_RUNNING && ifp->if_snd.ifq_head != NULL)
ixgb_start_locked(ifp);
IXGB_UNLOCK(adapter);
return;
}
/*********************************************************************
*
* Media Ioctl callback
*
* This routine is called whenever the user queries the status of
* the interface using ifconfig.
*
**********************************************************************/
static void
ixgb_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
{
struct adapter *adapter = ifp->if_softc;
INIT_DEBUGOUT("ixgb_media_status: begin");
ixgb_check_for_link(&adapter->hw);
ixgb_print_link_status(adapter);
ifmr->ifm_status = IFM_AVALID;
ifmr->ifm_active = IFM_ETHER;
if (!adapter->hw.link_up)
return;
ifmr->ifm_status |= IFM_ACTIVE;
ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
return;
}
/*********************************************************************
*
* Media Ioctl callback
*
* This routine is called when the user changes speed/duplex using
* media/mediopt option with ifconfig.
*
**********************************************************************/
static int
ixgb_media_change(struct ifnet * ifp)
{
struct adapter *adapter = ifp->if_softc;
struct ifmedia *ifm = &adapter->media;
INIT_DEBUGOUT("ixgb_media_change: begin");
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
return (EINVAL);
return (0);
}
/*********************************************************************
*
* This routine maps the mbufs to tx descriptors.
*
* return 0 on success, positive on failure
**********************************************************************/
static int
ixgb_encap(struct adapter * adapter, struct mbuf * m_head)
{
u_int8_t txd_popts;
int i, j, error, nsegs;
#if __FreeBSD_version < 500000
struct ifvlan *ifv = NULL;
#endif
bus_dma_segment_t segs[IXGB_MAX_SCATTER];
bus_dmamap_t map;
struct ixgb_buffer *tx_buffer = NULL;
struct ixgb_tx_desc *current_tx_desc = NULL;
struct ifnet *ifp = adapter->ifp;
/*
* Force a cleanup if number of TX descriptors available hits the
* threshold
*/
if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) {
ixgb_clean_transmit_interrupts(adapter);
}
if (adapter->num_tx_desc_avail <= IXGB_TX_CLEANUP_THRESHOLD) {
adapter->no_tx_desc_avail1++;
return (ENOBUFS);
}
/*
* Map the packet for DMA.
*/
if (bus_dmamap_create(adapter->txtag, BUS_DMA_NOWAIT, &map)) {
adapter->no_tx_map_avail++;
return (ENOMEM);
}
error = bus_dmamap_load_mbuf_sg(adapter->txtag, map, m_head, segs,
&nsegs, BUS_DMA_NOWAIT);
if (error != 0) {
adapter->no_tx_dma_setup++;
printf("ixgb%d: ixgb_encap: bus_dmamap_load_mbuf failed; "
"error %u\n", adapter->unit, error);
bus_dmamap_destroy(adapter->txtag, map);
return (error);
}
KASSERT(nsegs != 0, ("ixgb_encap: empty packet"));
if (nsegs > adapter->num_tx_desc_avail) {
adapter->no_tx_desc_avail2++;
bus_dmamap_destroy(adapter->txtag, map);
return (ENOBUFS);
}
if (ifp->if_hwassist > 0) {
ixgb_transmit_checksum_setup(adapter, m_head,
&txd_popts);
} else
txd_popts = 0;
/* Find out if we are in vlan mode */
#if __FreeBSD_version < 500000
if ((m_head->m_flags & (M_PROTO1 | M_PKTHDR)) == (M_PROTO1 | M_PKTHDR) &&
m_head->m_pkthdr.rcvif != NULL &&
m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
ifv = m_head->m_pkthdr.rcvif->if_softc;
#elseif __FreeBSD_version < 700000
mtag = VLAN_OUTPUT_TAG(ifp, m_head);
#endif
i = adapter->next_avail_tx_desc;
for (j = 0; j < nsegs; j++) {
tx_buffer = &adapter->tx_buffer_area[i];
current_tx_desc = &adapter->tx_desc_base[i];
current_tx_desc->buff_addr = htole64(segs[j].ds_addr);
current_tx_desc->cmd_type_len = (adapter->txd_cmd | segs[j].ds_len);
current_tx_desc->popts = txd_popts;
if (++i == adapter->num_tx_desc)
i = 0;
tx_buffer->m_head = NULL;
}
adapter->num_tx_desc_avail -= nsegs;
adapter->next_avail_tx_desc = i;
#if __FreeBSD_version < 500000
if (ifv != NULL) {
/* Set the vlan id */
current_tx_desc->vlan = ifv->ifv_tag;
#elseif __FreeBSD_version < 700000
if (mtag != NULL) {
/* Set the vlan id */
current_tx_desc->vlan = VLAN_TAG_VALUE(mtag);
#else
if (m_head->m_flags & M_VLANTAG) {
current_tx_desc->vlan = m_head->m_pkthdr.ether_vtag;
#endif
/* Tell hardware to add tag */
current_tx_desc->cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
}
tx_buffer->m_head = m_head;
tx_buffer->map = map;
bus_dmamap_sync(adapter->txtag, map, BUS_DMASYNC_PREWRITE);
/*
* Last Descriptor of Packet needs End Of Packet (EOP)
*/
current_tx_desc->cmd_type_len |= (IXGB_TX_DESC_CMD_EOP);
/*
* Advance the Transmit Descriptor Tail (Tdt), this tells the E1000
* that this frame is available to transmit.
*/
IXGB_WRITE_REG(&adapter->hw, TDT, i);
return (0);
}
static void
ixgb_set_promisc(struct adapter * adapter)
{
u_int32_t reg_rctl;
struct ifnet *ifp = adapter->ifp;
reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
if (ifp->if_flags & IFF_PROMISC) {
reg_rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
} else if (ifp->if_flags & IFF_ALLMULTI) {
reg_rctl |= IXGB_RCTL_MPE;
reg_rctl &= ~IXGB_RCTL_UPE;
IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
}
return;
}
static void
ixgb_disable_promisc(struct adapter * adapter)
{
u_int32_t reg_rctl;
reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
reg_rctl &= (~IXGB_RCTL_UPE);
reg_rctl &= (~IXGB_RCTL_MPE);
IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
return;
}
/*********************************************************************
* Multicast Update
*
* This routine is called whenever multicast address list is updated.
*
**********************************************************************/
static void
ixgb_set_multi(struct adapter * adapter)
{
u_int32_t reg_rctl = 0;
u_int8_t mta[MAX_NUM_MULTICAST_ADDRESSES * IXGB_ETH_LENGTH_OF_ADDRESS];
struct ifmultiaddr *ifma;
int mcnt = 0;
struct ifnet *ifp = adapter->ifp;
IOCTL_DEBUGOUT("ixgb_set_multi: begin");
IF_ADDR_LOCK(ifp);
#if __FreeBSD_version < 500000
LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
#else
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
#endif
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
&mta[mcnt * IXGB_ETH_LENGTH_OF_ADDRESS], IXGB_ETH_LENGTH_OF_ADDRESS);
mcnt++;
}
IF_ADDR_UNLOCK(ifp);
if (mcnt > MAX_NUM_MULTICAST_ADDRESSES) {
reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
reg_rctl |= IXGB_RCTL_MPE;
IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
} else
ixgb_mc_addr_list_update(&adapter->hw, mta, mcnt, 0);
return;
}
/*********************************************************************
* Timer routine
*
* This routine checks for link status and updates statistics.
*
**********************************************************************/
static void
ixgb_local_timer(void *arg)
{
struct ifnet *ifp;
struct adapter *adapter = arg;
ifp = adapter->ifp;
IXGB_LOCK(adapter);
ixgb_check_for_link(&adapter->hw);
ixgb_print_link_status(adapter);
ixgb_update_stats_counters(adapter);
if (ixgb_display_debug_stats && ifp->if_drv_flags & IFF_DRV_RUNNING) {
ixgb_print_hw_stats(adapter);
}
callout_reset(&adapter->timer, 2 * hz, ixgb_local_timer, adapter);
IXGB_UNLOCK(adapter);
return;
}
static void
ixgb_print_link_status(struct adapter * adapter)
{
if (adapter->hw.link_up) {
if (!adapter->link_active) {
printf("ixgb%d: Link is up %d Mbps %s \n",
adapter->unit,
10000,
"Full Duplex");
adapter->link_active = 1;
}
} else {
if (adapter->link_active) {
printf("ixgb%d: Link is Down \n", adapter->unit);
adapter->link_active = 0;
}
}
return;
}
/*********************************************************************
*
* This routine disables all traffic on the adapter by issuing a
* global reset on the MAC and deallocates TX/RX buffers.
*
**********************************************************************/
static void
ixgb_stop(void *arg)
{
struct ifnet *ifp;
struct adapter *adapter = arg;
ifp = adapter->ifp;
IXGB_LOCK_ASSERT(adapter);
INIT_DEBUGOUT("ixgb_stop: begin\n");
ixgb_disable_intr(adapter);
adapter->hw.adapter_stopped = FALSE;
ixgb_adapter_stop(&adapter->hw);
callout_stop(&adapter->timer);
ixgb_free_transmit_structures(adapter);
ixgb_free_receive_structures(adapter);
/* Tell the stack that the interface is no longer active */
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
return;
}
/*********************************************************************
*
* Determine hardware revision.
*
**********************************************************************/
static void
ixgb_identify_hardware(struct adapter * adapter)
{
device_t dev = adapter->dev;
/* Make sure our PCI config space has the necessary stuff set */
adapter->hw.pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2);
if (!((adapter->hw.pci_cmd_word & PCIM_CMD_BUSMASTEREN) &&
(adapter->hw.pci_cmd_word & PCIM_CMD_MEMEN))) {
printf("ixgb%d: Memory Access and/or Bus Master bits were not set!\n",
adapter->unit);
adapter->hw.pci_cmd_word |=
(PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN);
pci_write_config(dev, PCIR_COMMAND, adapter->hw.pci_cmd_word, 2);
}
/* Save off the information about this board */
adapter->hw.vendor_id = pci_get_vendor(dev);
adapter->hw.device_id = pci_get_device(dev);
adapter->hw.revision_id = pci_read_config(dev, PCIR_REVID, 1);
adapter->hw.subsystem_vendor_id = pci_read_config(dev, PCIR_SUBVEND_0, 2);
adapter->hw.subsystem_id = pci_read_config(dev, PCIR_SUBDEV_0, 2);
/* Set MacType, etc. based on this PCI info */
switch (adapter->hw.device_id) {
case IXGB_DEVICE_ID_82597EX:
case IXGB_DEVICE_ID_82597EX_SR:
adapter->hw.mac_type = ixgb_82597;
break;
default:
INIT_DEBUGOUT1("Unknown device if 0x%x", adapter->hw.device_id);
printf("ixgb%d: unsupported device id 0x%x\n", adapter->unit, adapter->hw.device_id);
}
return;
}
static int
ixgb_allocate_pci_resources(struct adapter * adapter)
{
int rid;
device_t dev = adapter->dev;
rid = IXGB_MMBA;
adapter->res_memory = bus_alloc_resource(dev, SYS_RES_MEMORY,
&rid, 0, ~0, 1,
RF_ACTIVE);
if (!(adapter->res_memory)) {
printf("ixgb%d: Unable to allocate bus resource: memory\n",
adapter->unit);
return (ENXIO);
}
adapter->osdep.mem_bus_space_tag =
rman_get_bustag(adapter->res_memory);
adapter->osdep.mem_bus_space_handle =
rman_get_bushandle(adapter->res_memory);
adapter->hw.hw_addr = (uint8_t *) & adapter->osdep.mem_bus_space_handle;
rid = 0x0;
adapter->res_interrupt = bus_alloc_resource(dev, SYS_RES_IRQ,
&rid, 0, ~0, 1,
RF_SHAREABLE | RF_ACTIVE);
if (!(adapter->res_interrupt)) {
printf("ixgb%d: Unable to allocate bus resource: interrupt\n",
adapter->unit);
return (ENXIO);
}
if (bus_setup_intr(dev, adapter->res_interrupt,
INTR_TYPE_NET | INTR_MPSAFE,
NULL, (void (*) (void *))ixgb_intr, adapter,
&adapter->int_handler_tag)) {
printf("ixgb%d: Error registering interrupt handler!\n",
adapter->unit);
return (ENXIO);
}
adapter->hw.back = &adapter->osdep;
return (0);
}
static void
ixgb_free_pci_resources(struct adapter * adapter)
{
device_t dev = adapter->dev;
if (adapter->res_interrupt != NULL) {
bus_teardown_intr(dev, adapter->res_interrupt,
adapter->int_handler_tag);
bus_release_resource(dev, SYS_RES_IRQ, 0,
adapter->res_interrupt);
}
if (adapter->res_memory != NULL) {
bus_release_resource(dev, SYS_RES_MEMORY, IXGB_MMBA,
adapter->res_memory);
}
if (adapter->res_ioport != NULL) {
bus_release_resource(dev, SYS_RES_IOPORT, adapter->io_rid,
adapter->res_ioport);
}
return;
}
/*********************************************************************
*
* Initialize the hardware to a configuration as specified by the
* adapter structure. The controller is reset, the EEPROM is
* verified, the MAC address is set, then the shared initialization
* routines are called.
*
**********************************************************************/
static int
ixgb_hardware_init(struct adapter * adapter)
{
/* Issue a global reset */
adapter->hw.adapter_stopped = FALSE;
ixgb_adapter_stop(&adapter->hw);
/* Make sure we have a good EEPROM before we read from it */
if (!ixgb_validate_eeprom_checksum(&adapter->hw)) {
printf("ixgb%d: The EEPROM Checksum Is Not Valid\n",
adapter->unit);
return (EIO);
}
if (!ixgb_init_hw(&adapter->hw)) {
printf("ixgb%d: Hardware Initialization Failed",
adapter->unit);
return (EIO);
}
return (0);
}
/*********************************************************************
*
* Setup networking device structure and register an interface.
*
**********************************************************************/
static void
ixgb_setup_interface(device_t dev, struct adapter * adapter)
{
struct ifnet *ifp;
INIT_DEBUGOUT("ixgb_setup_interface: begin");
ifp = adapter->ifp = if_alloc(IFT_ETHER);
if (ifp == NULL)
panic("%s: can not if_alloc()\n", device_get_nameunit(dev));
#if __FreeBSD_version >= 502000
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
#else
ifp->if_unit = adapter->unit;
ifp->if_name = "ixgb";
#endif
ifp->if_mtu = ETHERMTU;
ifp->if_baudrate = 1000000000;
ifp->if_init = ixgb_init;
ifp->if_softc = adapter;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_ioctl = ixgb_ioctl;
ifp->if_start = ixgb_start;
ifp->if_watchdog = ixgb_watchdog;
ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 1;
#if __FreeBSD_version < 500000
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
#else
ether_ifattach(ifp, adapter->hw.curr_mac_addr);
#endif
ifp->if_capabilities = IFCAP_HWCSUM;
/*
* Tell the upper layer(s) we support long frames.
*/
ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
#if __FreeBSD_version >= 500000
ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
#endif
ifp->if_capenable = ifp->if_capabilities;
#ifdef DEVICE_POLLING
ifp->if_capabilities |= IFCAP_POLLING;
#endif
/*
* Specify the media types supported by this adapter and register
* callbacks to update media and link information
*/
ifmedia_init(&adapter->media, IFM_IMASK, ixgb_media_change,
ixgb_media_status);
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX | IFM_FDX,
0, NULL);
ifmedia_add(&adapter->media, IFM_ETHER | IFM_1000_SX,
0, NULL);
ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
return;
}
/********************************************************************
* Manage DMA'able memory.
*******************************************************************/
static void
ixgb_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error)
{
if (error)
return;
*(bus_addr_t *) arg = segs->ds_addr;
return;
}
static int
ixgb_dma_malloc(struct adapter * adapter, bus_size_t size,
struct ixgb_dma_alloc * dma, int mapflags)
{
int r;
r = bus_dma_tag_create(NULL, /* parent */
PAGE_SIZE, 0, /* alignment, bounds */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
size, /* maxsize */
1, /* nsegments */
size, /* maxsegsize */
BUS_DMA_ALLOCNOW, /* flags */
#if __FreeBSD_version >= 502000
NULL, /* lockfunc */
NULL, /* lockfuncarg */
#endif
&dma->dma_tag);
if (r != 0) {
printf("ixgb%d: ixgb_dma_malloc: bus_dma_tag_create failed; "
"error %u\n", adapter->unit, r);
goto fail_0;
}
r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
BUS_DMA_NOWAIT, &dma->dma_map);
if (r != 0) {
printf("ixgb%d: ixgb_dma_malloc: bus_dmamem_alloc failed; "
"error %u\n", adapter->unit, r);
goto fail_1;
}
r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
size,
ixgb_dmamap_cb,
&dma->dma_paddr,
mapflags | BUS_DMA_NOWAIT);
if (r != 0) {
printf("ixgb%d: ixgb_dma_malloc: bus_dmamap_load failed; "
"error %u\n", adapter->unit, r);
goto fail_2;
}
dma->dma_size = size;
return (0);
fail_2:
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
fail_1:
bus_dma_tag_destroy(dma->dma_tag);
fail_0:
dma->dma_map = NULL;
dma->dma_tag = NULL;
return (r);
}
static void
ixgb_dma_free(struct adapter * adapter, struct ixgb_dma_alloc * dma)
{
bus_dmamap_unload(dma->dma_tag, dma->dma_map);
bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
bus_dma_tag_destroy(dma->dma_tag);
}
/*********************************************************************
*
* Allocate memory for tx_buffer structures. The tx_buffer stores all
* the information needed to transmit a packet on the wire.
*
**********************************************************************/
static int
ixgb_allocate_transmit_structures(struct adapter * adapter)
{
if (!(adapter->tx_buffer_area =
(struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) *
adapter->num_tx_desc, M_DEVBUF,
M_NOWAIT | M_ZERO))) {
printf("ixgb%d: Unable to allocate tx_buffer memory\n",
adapter->unit);
return ENOMEM;
}
bzero(adapter->tx_buffer_area,
sizeof(struct ixgb_buffer) * adapter->num_tx_desc);
return 0;
}
/*********************************************************************
*
* Allocate and initialize transmit structures.
*
**********************************************************************/
static int
ixgb_setup_transmit_structures(struct adapter * adapter)
{
/*
* Setup DMA descriptor areas.
*/
if (bus_dma_tag_create(NULL, /* parent */
PAGE_SIZE, 0, /* alignment, bounds */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
MCLBYTES * IXGB_MAX_SCATTER, /* maxsize */
IXGB_MAX_SCATTER, /* nsegments */
MCLBYTES, /* maxsegsize */
BUS_DMA_ALLOCNOW, /* flags */
#if __FreeBSD_version >= 502000
NULL, /* lockfunc */
NULL, /* lockfuncarg */
#endif
&adapter->txtag)) {
printf("ixgb%d: Unable to allocate TX DMA tag\n", adapter->unit);
return (ENOMEM);
}
if (ixgb_allocate_transmit_structures(adapter))
return ENOMEM;
bzero((void *)adapter->tx_desc_base,
(sizeof(struct ixgb_tx_desc)) * adapter->num_tx_desc);
adapter->next_avail_tx_desc = 0;
adapter->oldest_used_tx_desc = 0;
/* Set number of descriptors available */
adapter->num_tx_desc_avail = adapter->num_tx_desc;
/* Set checksum context */
adapter->active_checksum_context = OFFLOAD_NONE;
return 0;
}
/*********************************************************************
*
* Enable transmit unit.
*
**********************************************************************/
static void
ixgb_initialize_transmit_unit(struct adapter * adapter)
{
u_int32_t reg_tctl;
u_int64_t tdba = adapter->txdma.dma_paddr;
/* Setup the Base and Length of the Tx Descriptor Ring */
IXGB_WRITE_REG(&adapter->hw, TDBAL,
(tdba & 0x00000000ffffffffULL));
IXGB_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
IXGB_WRITE_REG(&adapter->hw, TDLEN,
adapter->num_tx_desc *
sizeof(struct ixgb_tx_desc));
/* Setup the HW Tx Head and Tail descriptor pointers */
IXGB_WRITE_REG(&adapter->hw, TDH, 0);
IXGB_WRITE_REG(&adapter->hw, TDT, 0);
HW_DEBUGOUT2("Base = %x, Length = %x\n",
IXGB_READ_REG(&adapter->hw, TDBAL),
IXGB_READ_REG(&adapter->hw, TDLEN));
IXGB_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
/* Program the Transmit Control Register */
reg_tctl = IXGB_READ_REG(&adapter->hw, TCTL);
reg_tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
IXGB_WRITE_REG(&adapter->hw, TCTL, reg_tctl);
/* Setup Transmit Descriptor Settings for this adapter */
adapter->txd_cmd = IXGB_TX_DESC_TYPE | IXGB_TX_DESC_CMD_RS;
if (adapter->tx_int_delay > 0)
adapter->txd_cmd |= IXGB_TX_DESC_CMD_IDE;
return;
}
/*********************************************************************
*
* Free all transmit related data structures.
*
**********************************************************************/
static void
ixgb_free_transmit_structures(struct adapter * adapter)
{
struct ixgb_buffer *tx_buffer;
int i;
INIT_DEBUGOUT("free_transmit_structures: begin");
if (adapter->tx_buffer_area != NULL) {
tx_buffer = adapter->tx_buffer_area;
for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
if (tx_buffer->m_head != NULL) {
bus_dmamap_unload(adapter->txtag, tx_buffer->map);
bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
m_freem(tx_buffer->m_head);
}
tx_buffer->m_head = NULL;
}
}
if (adapter->tx_buffer_area != NULL) {
free(adapter->tx_buffer_area, M_DEVBUF);
adapter->tx_buffer_area = NULL;
}
if (adapter->txtag != NULL) {
bus_dma_tag_destroy(adapter->txtag);
adapter->txtag = NULL;
}
return;
}
/*********************************************************************
*
* The offload context needs to be set when we transfer the first
* packet of a particular protocol (TCP/UDP). We change the
* context only if the protocol type changes.
*
**********************************************************************/
static void
ixgb_transmit_checksum_setup(struct adapter * adapter,
struct mbuf * mp,
u_int8_t * txd_popts)
{
struct ixgb_context_desc *TXD;
struct ixgb_buffer *tx_buffer;
int curr_txd;
if (mp->m_pkthdr.csum_flags) {
if (mp->m_pkthdr.csum_flags & CSUM_TCP) {
*txd_popts = IXGB_TX_DESC_POPTS_TXSM;
if (adapter->active_checksum_context == OFFLOAD_TCP_IP)
return;
else
adapter->active_checksum_context = OFFLOAD_TCP_IP;
} else if (mp->m_pkthdr.csum_flags & CSUM_UDP) {
*txd_popts = IXGB_TX_DESC_POPTS_TXSM;
if (adapter->active_checksum_context == OFFLOAD_UDP_IP)
return;
else
adapter->active_checksum_context = OFFLOAD_UDP_IP;
} else {
*txd_popts = 0;
return;
}
} else {
*txd_popts = 0;
return;
}
/*
* If we reach this point, the checksum offload context needs to be
* reset.
*/
curr_txd = adapter->next_avail_tx_desc;
tx_buffer = &adapter->tx_buffer_area[curr_txd];
TXD = (struct ixgb_context_desc *) & adapter->tx_desc_base[curr_txd];
TXD->tucss = ENET_HEADER_SIZE + sizeof(struct ip);
TXD->tucse = 0;
TXD->mss = 0;
if (adapter->active_checksum_context == OFFLOAD_TCP_IP) {
TXD->tucso =
ENET_HEADER_SIZE + sizeof(struct ip) +
offsetof(struct tcphdr, th_sum);
} else if (adapter->active_checksum_context == OFFLOAD_UDP_IP) {
TXD->tucso =
ENET_HEADER_SIZE + sizeof(struct ip) +
offsetof(struct udphdr, uh_sum);
}
TXD->cmd_type_len = IXGB_CONTEXT_DESC_CMD_TCP | IXGB_TX_DESC_CMD_RS | IXGB_CONTEXT_DESC_CMD_IDE;
tx_buffer->m_head = NULL;
if (++curr_txd == adapter->num_tx_desc)
curr_txd = 0;
adapter->num_tx_desc_avail--;
adapter->next_avail_tx_desc = curr_txd;
return;
}
/**********************************************************************
*
* Examine each tx_buffer in the used queue. If the hardware is done
* processing the packet then free associated resources. The
* tx_buffer is put back on the free queue.
*
**********************************************************************/
static void
ixgb_clean_transmit_interrupts(struct adapter * adapter)
{
int i, num_avail;
struct ixgb_buffer *tx_buffer;
struct ixgb_tx_desc *tx_desc;
IXGB_LOCK_ASSERT(adapter);
if (adapter->num_tx_desc_avail == adapter->num_tx_desc)
return;
#ifdef _SV_
adapter->clean_tx_interrupts++;
#endif
num_avail = adapter->num_tx_desc_avail;
i = adapter->oldest_used_tx_desc;
tx_buffer = &adapter->tx_buffer_area[i];
tx_desc = &adapter->tx_desc_base[i];
while (tx_desc->status & IXGB_TX_DESC_STATUS_DD) {
tx_desc->status = 0;
num_avail++;
if (tx_buffer->m_head) {
bus_dmamap_sync(adapter->txtag, tx_buffer->map,
BUS_DMASYNC_POSTWRITE);
bus_dmamap_unload(adapter->txtag, tx_buffer->map);
bus_dmamap_destroy(adapter->txtag, tx_buffer->map);
m_freem(tx_buffer->m_head);
tx_buffer->m_head = NULL;
}
if (++i == adapter->num_tx_desc)
i = 0;
tx_buffer = &adapter->tx_buffer_area[i];
tx_desc = &adapter->tx_desc_base[i];
}
adapter->oldest_used_tx_desc = i;
/*
* If we have enough room, clear IFF_DRV_OACTIVE to tell the stack that
* it is OK to send packets. If there are no pending descriptors,
* clear the timeout. Otherwise, if some descriptors have been freed,
* restart the timeout.
*/
if (num_avail > IXGB_TX_CLEANUP_THRESHOLD) {
struct ifnet *ifp = adapter->ifp;
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
if (num_avail == adapter->num_tx_desc)
ifp->if_timer = 0;
else if (num_avail == adapter->num_tx_desc_avail)
ifp->if_timer = IXGB_TX_TIMEOUT;
}
adapter->num_tx_desc_avail = num_avail;
return;
}
/*********************************************************************
*
* Get a buffer from system mbuf buffer pool.
*
**********************************************************************/
static int
ixgb_get_buf(int i, struct adapter * adapter,
struct mbuf * nmp)
{
register struct mbuf *mp = nmp;
struct ixgb_buffer *rx_buffer;
struct ifnet *ifp;
bus_addr_t paddr;
int error;
ifp = adapter->ifp;
if (mp == NULL) {
mp = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
if (mp == NULL) {
adapter->mbuf_alloc_failed++;
return (ENOBUFS);
}
mp->m_len = mp->m_pkthdr.len = MCLBYTES;
} else {
mp->m_len = mp->m_pkthdr.len = MCLBYTES;
mp->m_data = mp->m_ext.ext_buf;
mp->m_next = NULL;
}
if (ifp->if_mtu <= ETHERMTU) {
m_adj(mp, ETHER_ALIGN);
}
rx_buffer = &adapter->rx_buffer_area[i];
/*
* Using memory from the mbuf cluster pool, invoke the bus_dma
* machinery to arrange the memory mapping.
*/
error = bus_dmamap_load(adapter->rxtag, rx_buffer->map,
mtod(mp, void *), mp->m_len,
ixgb_dmamap_cb, &paddr, 0);
if (error) {
m_free(mp);
return (error);
}
rx_buffer->m_head = mp;
adapter->rx_desc_base[i].buff_addr = htole64(paddr);
bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD);
return (0);
}
/*********************************************************************
*
* Allocate memory for rx_buffer structures. Since we use one
* rx_buffer per received packet, the maximum number of rx_buffer's
* that we'll need is equal to the number of receive descriptors
* that we've allocated.
*
**********************************************************************/
static int
ixgb_allocate_receive_structures(struct adapter * adapter)
{
int i, error;
struct ixgb_buffer *rx_buffer;
if (!(adapter->rx_buffer_area =
(struct ixgb_buffer *) malloc(sizeof(struct ixgb_buffer) *
adapter->num_rx_desc, M_DEVBUF,
M_NOWAIT | M_ZERO))) {
printf("ixgb%d: Unable to allocate rx_buffer memory\n",
adapter->unit);
return (ENOMEM);
}
bzero(adapter->rx_buffer_area,
sizeof(struct ixgb_buffer) * adapter->num_rx_desc);
error = bus_dma_tag_create(NULL, /* parent */
PAGE_SIZE, 0, /* alignment, bounds */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
MCLBYTES, /* maxsize */
1, /* nsegments */
MCLBYTES, /* maxsegsize */
BUS_DMA_ALLOCNOW, /* flags */
#if __FreeBSD_version >= 502000
NULL, /* lockfunc */
NULL, /* lockfuncarg */
#endif
&adapter->rxtag);
if (error != 0) {
printf("ixgb%d: ixgb_allocate_receive_structures: "
"bus_dma_tag_create failed; error %u\n",
adapter->unit, error);
goto fail_0;
}
rx_buffer = adapter->rx_buffer_area;
for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
error = bus_dmamap_create(adapter->rxtag, BUS_DMA_NOWAIT,
&rx_buffer->map);
if (error != 0) {
printf("ixgb%d: ixgb_allocate_receive_structures: "
"bus_dmamap_create failed; error %u\n",
adapter->unit, error);
goto fail_1;
}
}
for (i = 0; i < adapter->num_rx_desc; i++) {
if (ixgb_get_buf(i, adapter, NULL) == ENOBUFS) {
adapter->rx_buffer_area[i].m_head = NULL;
adapter->rx_desc_base[i].buff_addr = 0;
return (ENOBUFS);
}
}
return (0);
fail_1:
bus_dma_tag_destroy(adapter->rxtag);
fail_0:
adapter->rxtag = NULL;
free(adapter->rx_buffer_area, M_DEVBUF);
adapter->rx_buffer_area = NULL;
return (error);
}
/*********************************************************************
*
* Allocate and initialize receive structures.
*
**********************************************************************/
static int
ixgb_setup_receive_structures(struct adapter * adapter)
{
bzero((void *)adapter->rx_desc_base,
(sizeof(struct ixgb_rx_desc)) * adapter->num_rx_desc);
if (ixgb_allocate_receive_structures(adapter))
return ENOMEM;
/* Setup our descriptor pointers */
adapter->next_rx_desc_to_check = 0;
adapter->next_rx_desc_to_use = 0;
return (0);
}
/*********************************************************************
*
* Enable receive unit.
*
**********************************************************************/
static void
ixgb_initialize_receive_unit(struct adapter * adapter)
{
u_int32_t reg_rctl;
u_int32_t reg_rxcsum;
u_int32_t reg_rxdctl;
struct ifnet *ifp;
u_int64_t rdba = adapter->rxdma.dma_paddr;
ifp = adapter->ifp;
/*
* Make sure receives are disabled while setting up the descriptor
* ring
*/
reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl & ~IXGB_RCTL_RXEN);
/* Set the Receive Delay Timer Register */
IXGB_WRITE_REG(&adapter->hw, RDTR,
adapter->rx_int_delay);
/* Setup the Base and Length of the Rx Descriptor Ring */
IXGB_WRITE_REG(&adapter->hw, RDBAL,
(rdba & 0x00000000ffffffffULL));
IXGB_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
IXGB_WRITE_REG(&adapter->hw, RDLEN, adapter->num_rx_desc *
sizeof(struct ixgb_rx_desc));
/* Setup the HW Rx Head and Tail Descriptor Pointers */
IXGB_WRITE_REG(&adapter->hw, RDH, 0);
IXGB_WRITE_REG(&adapter->hw, RDT, adapter->num_rx_desc - 1);
reg_rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT
| RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT
| RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
IXGB_WRITE_REG(&adapter->hw, RXDCTL, reg_rxdctl);
adapter->raidc = 1;
if (adapter->raidc) {
uint32_t raidc;
uint8_t poll_threshold;
#define IXGB_RAIDC_POLL_DEFAULT 120
poll_threshold = ((adapter->num_rx_desc - 1) >> 3);
poll_threshold >>= 1;
poll_threshold &= 0x3F;
raidc = IXGB_RAIDC_EN | IXGB_RAIDC_RXT_GATE |
(IXGB_RAIDC_POLL_DEFAULT << IXGB_RAIDC_POLL_SHIFT) |
(adapter->rx_int_delay << IXGB_RAIDC_DELAY_SHIFT) |
poll_threshold;
IXGB_WRITE_REG(&adapter->hw, RAIDC, raidc);
}
/* Enable Receive Checksum Offload for TCP and UDP ? */
if (ifp->if_capenable & IFCAP_RXCSUM) {
reg_rxcsum = IXGB_READ_REG(&adapter->hw, RXCSUM);
reg_rxcsum |= IXGB_RXCSUM_TUOFL;
IXGB_WRITE_REG(&adapter->hw, RXCSUM, reg_rxcsum);
}
/* Setup the Receive Control Register */
reg_rctl = IXGB_READ_REG(&adapter->hw, RCTL);
reg_rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
reg_rctl |= IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 | IXGB_RCTL_SECRC |
IXGB_RCTL_CFF |
(adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
switch (adapter->rx_buffer_len) {
default:
case IXGB_RXBUFFER_2048:
reg_rctl |= IXGB_RCTL_BSIZE_2048;
break;
case IXGB_RXBUFFER_4096:
reg_rctl |= IXGB_RCTL_BSIZE_4096;
break;
case IXGB_RXBUFFER_8192:
reg_rctl |= IXGB_RCTL_BSIZE_8192;
break;
case IXGB_RXBUFFER_16384:
reg_rctl |= IXGB_RCTL_BSIZE_16384;
break;
}
reg_rctl |= IXGB_RCTL_RXEN;
/* Enable Receives */
IXGB_WRITE_REG(&adapter->hw, RCTL, reg_rctl);
return;
}
/*********************************************************************
*
* Free receive related data structures.
*
**********************************************************************/
static void
ixgb_free_receive_structures(struct adapter * adapter)
{
struct ixgb_buffer *rx_buffer;
int i;
INIT_DEBUGOUT("free_receive_structures: begin");
if (adapter->rx_buffer_area != NULL) {
rx_buffer = adapter->rx_buffer_area;
for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
if (rx_buffer->map != NULL) {
bus_dmamap_unload(adapter->rxtag, rx_buffer->map);
bus_dmamap_destroy(adapter->rxtag, rx_buffer->map);
}
if (rx_buffer->m_head != NULL)
m_freem(rx_buffer->m_head);
rx_buffer->m_head = NULL;
}
}
if (adapter->rx_buffer_area != NULL) {
free(adapter->rx_buffer_area, M_DEVBUF);
adapter->rx_buffer_area = NULL;
}
if (adapter->rxtag != NULL) {
bus_dma_tag_destroy(adapter->rxtag);
adapter->rxtag = NULL;
}
return;
}
/*********************************************************************
*
* This routine executes in interrupt context. It replenishes
* the mbufs in the descriptor and sends data which has been
* dma'ed into host memory to upper layer.
*
* We loop at most count times if count is > 0, or until done if
* count < 0.
*
*********************************************************************/
static void
ixgb_process_receive_interrupts(struct adapter * adapter, int count)
{
struct ifnet *ifp;
struct mbuf *mp;
#if __FreeBSD_version < 500000
struct ether_header *eh;
#endif
int eop = 0;
int len;
u_int8_t accept_frame = 0;
int i;
int next_to_use = 0;
int eop_desc;
/* Pointer to the receive descriptor being examined. */
struct ixgb_rx_desc *current_desc;
IXGB_LOCK_ASSERT(adapter);
ifp = adapter->ifp;
i = adapter->next_rx_desc_to_check;
next_to_use = adapter->next_rx_desc_to_use;
eop_desc = adapter->next_rx_desc_to_check;
current_desc = &adapter->rx_desc_base[i];
if (!((current_desc->status) & IXGB_RX_DESC_STATUS_DD)) {
#ifdef _SV_
adapter->no_pkts_avail++;
#endif
return;
}
while ((current_desc->status & IXGB_RX_DESC_STATUS_DD) && (count != 0)) {
mp = adapter->rx_buffer_area[i].m_head;
bus_dmamap_sync(adapter->rxtag, adapter->rx_buffer_area[i].map,
BUS_DMASYNC_POSTREAD);
accept_frame = 1;
if (current_desc->status & IXGB_RX_DESC_STATUS_EOP) {
count--;
eop = 1;
} else {
eop = 0;
}
len = current_desc->length;
if (current_desc->errors & (IXGB_RX_DESC_ERRORS_CE |
IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P |
IXGB_RX_DESC_ERRORS_RXE)) {
accept_frame = 0;
}
if (accept_frame) {
/* Assign correct length to the current fragment */
mp->m_len = len;
if (adapter->fmp == NULL) {
mp->m_pkthdr.len = len;
adapter->fmp = mp; /* Store the first mbuf */
adapter->lmp = mp;
} else {
/* Chain mbuf's together */
mp->m_flags &= ~M_PKTHDR;
adapter->lmp->m_next = mp;
adapter->lmp = adapter->lmp->m_next;
adapter->fmp->m_pkthdr.len += len;
}
if (eop) {
eop_desc = i;
adapter->fmp->m_pkthdr.rcvif = ifp;
#if __FreeBSD_version < 500000
eh = mtod(adapter->fmp, struct ether_header *);
/* Remove ethernet header from mbuf */
m_adj(adapter->fmp, sizeof(struct ether_header));
ixgb_receive_checksum(adapter, current_desc,
adapter->fmp);
if (current_desc->status & IXGB_RX_DESC_STATUS_VP)
VLAN_INPUT_TAG(eh, adapter->fmp,
current_desc->special);
else
ether_input(ifp, eh, adapter->fmp);
#else
ixgb_receive_checksum(adapter, current_desc,
adapter->fmp);
#if __FreeBSD_version < 700000
if (current_desc->status & IXGB_RX_DESC_STATUS_VP)
VLAN_INPUT_TAG(ifp, adapter->fmp,
current_desc->special);
#else
if (current_desc->status & IXGB_RX_DESC_STATUS_VP) {
adapter->fmp->m_pkthdr.ether_vtag =
current_desc->special;
adapter->fmp->m_flags |= M_VLANTAG;
}
#endif
if (adapter->fmp != NULL) {
IXGB_UNLOCK(adapter);
(*ifp->if_input) (ifp, adapter->fmp);
IXGB_LOCK(adapter);
}
#endif
adapter->fmp = NULL;
adapter->lmp = NULL;
}
adapter->rx_buffer_area[i].m_head = NULL;
} else {
adapter->dropped_pkts++;
if (adapter->fmp != NULL)
m_freem(adapter->fmp);
adapter->fmp = NULL;
adapter->lmp = NULL;
}
/* Zero out the receive descriptors status */
current_desc->status = 0;
/* Advance our pointers to the next descriptor */
if (++i == adapter->num_rx_desc) {
i = 0;
current_desc = adapter->rx_desc_base;
} else
current_desc++;
}
adapter->next_rx_desc_to_check = i;
if (--i < 0)
i = (adapter->num_rx_desc - 1);
/*
* 82597EX: Workaround for redundent write back in receive descriptor ring (causes
* memory corruption). Avoid using and re-submitting the most recently received RX
* descriptor back to hardware.
*
* if(Last written back descriptor == EOP bit set descriptor)
* then avoid re-submitting the most recently received RX descriptor
* back to hardware.
* if(Last written back descriptor != EOP bit set descriptor)
* then avoid re-submitting the most recently received RX descriptors
* till last EOP bit set descriptor.
*/
if (eop_desc != i) {
if (++eop_desc == adapter->num_rx_desc)
eop_desc = 0;
i = eop_desc;
}
/* Replenish the descriptors with new mbufs till last EOP bit set descriptor */
while (next_to_use != i) {
current_desc = &adapter->rx_desc_base[next_to_use];
if ((current_desc->errors & (IXGB_RX_DESC_ERRORS_CE |
IXGB_RX_DESC_ERRORS_SE | IXGB_RX_DESC_ERRORS_P |
IXGB_RX_DESC_ERRORS_RXE))) {
mp = adapter->rx_buffer_area[next_to_use].m_head;
ixgb_get_buf(next_to_use, adapter, mp);
} else {
if (ixgb_get_buf(next_to_use, adapter, NULL) == ENOBUFS)
break;
}
/* Advance our pointers to the next descriptor */
if (++next_to_use == adapter->num_rx_desc) {
next_to_use = 0;
current_desc = adapter->rx_desc_base;
} else
current_desc++;
}
adapter->next_rx_desc_to_use = next_to_use;
if (--next_to_use < 0)
next_to_use = (adapter->num_rx_desc - 1);
/* Advance the IXGB's Receive Queue #0 "Tail Pointer" */
IXGB_WRITE_REG(&adapter->hw, RDT, next_to_use);
return;
}
/*********************************************************************
*
* Verify that the hardware indicated that the checksum is valid.
* Inform the stack about the status of checksum so that stack
* doesn't spend time verifying the checksum.
*
*********************************************************************/
static void
ixgb_receive_checksum(struct adapter * adapter,
struct ixgb_rx_desc * rx_desc,
struct mbuf * mp)
{
if (rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) {
mp->m_pkthdr.csum_flags = 0;
return;
}
if (rx_desc->status & IXGB_RX_DESC_STATUS_IPCS) {
/* Did it pass? */
if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_IPE)) {
/* IP Checksum Good */
mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
} else {
mp->m_pkthdr.csum_flags = 0;
}
}
if (rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS) {
/* Did it pass? */
if (!(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE)) {
mp->m_pkthdr.csum_flags |=
(CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
mp->m_pkthdr.csum_data = htons(0xffff);
}
}
return;
}
static void
ixgb_enable_vlans(struct adapter * adapter)
{
uint32_t ctrl;
ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
ctrl |= IXGB_CTRL0_VME;
IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
return;
}
static void
ixgb_enable_intr(struct adapter * adapter)
{
IXGB_WRITE_REG(&adapter->hw, IMS, (IXGB_INT_RXT0 | IXGB_INT_TXDW |
IXGB_INT_RXDMT0 | IXGB_INT_LSC | IXGB_INT_RXO));
return;
}
static void
ixgb_disable_intr(struct adapter * adapter)
{
IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
return;
}
void
ixgb_write_pci_cfg(struct ixgb_hw * hw,
uint32_t reg,
uint16_t * value)
{
pci_write_config(((struct ixgb_osdep *) hw->back)->dev, reg,
*value, 2);
}
/**********************************************************************
*
* Update the board statistics counters.
*
**********************************************************************/
static void
ixgb_update_stats_counters(struct adapter * adapter)
{
struct ifnet *ifp;
adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
ifp = adapter->ifp;
/* Fill out the OS statistics structure */
ifp->if_ipackets = adapter->stats.gprcl;
ifp->if_opackets = adapter->stats.gptcl;
ifp->if_ibytes = adapter->stats.gorcl;
ifp->if_obytes = adapter->stats.gotcl;
ifp->if_imcasts = adapter->stats.mprcl;
ifp->if_collisions = 0;
/* Rx Errors */
ifp->if_ierrors =
adapter->dropped_pkts +
adapter->stats.crcerrs +
adapter->stats.rnbc +
adapter->stats.mpc +
adapter->stats.rlec;
}
/**********************************************************************
*
* This routine is called only when ixgb_display_debug_stats is enabled.
* This routine provides a way to take a look at important statistics
* maintained by the driver and hardware.
*
**********************************************************************/
static void
ixgb_print_hw_stats(struct adapter * adapter)
{
char buf_speed[100], buf_type[100];
ixgb_bus_speed bus_speed;
ixgb_bus_type bus_type;
int unit = adapter->unit;
#ifdef _SV_
printf("ixgb%d: Packets not Avail = %ld\n", unit,
adapter->no_pkts_avail);
printf("ixgb%d: CleanTxInterrupts = %ld\n", unit,
adapter->clean_tx_interrupts);
printf("ixgb%d: ICR RXDMT0 = %lld\n", unit,
(long long)adapter->sv_stats.icr_rxdmt0);
printf("ixgb%d: ICR RXO = %lld\n", unit,
(long long)adapter->sv_stats.icr_rxo);
printf("ixgb%d: ICR RXT0 = %lld\n", unit,
(long long)adapter->sv_stats.icr_rxt0);
printf("ixgb%d: ICR TXDW = %lld\n", unit,
(long long)adapter->sv_stats.icr_TXDW);
#endif /* _SV_ */
bus_speed = adapter->hw.bus.speed;
bus_type = adapter->hw.bus.type;
sprintf(buf_speed,
bus_speed == ixgb_bus_speed_33 ? "33MHz" :
bus_speed == ixgb_bus_speed_66 ? "66MHz" :
bus_speed == ixgb_bus_speed_100 ? "100MHz" :
bus_speed == ixgb_bus_speed_133 ? "133MHz" :
"UNKNOWN");
printf("ixgb%d: PCI_Bus_Speed = %s\n", unit,
buf_speed);
sprintf(buf_type,
bus_type == ixgb_bus_type_pci ? "PCI" :
bus_type == ixgb_bus_type_pcix ? "PCI-X" :
"UNKNOWN");
printf("ixgb%d: PCI_Bus_Type = %s\n", unit,
buf_type);
printf("ixgb%d: Tx Descriptors not Avail1 = %ld\n", unit,
adapter->no_tx_desc_avail1);
printf("ixgb%d: Tx Descriptors not Avail2 = %ld\n", unit,
adapter->no_tx_desc_avail2);
printf("ixgb%d: Std Mbuf Failed = %ld\n", unit,
adapter->mbuf_alloc_failed);
printf("ixgb%d: Std Cluster Failed = %ld\n", unit,
adapter->mbuf_cluster_failed);
printf("ixgb%d: Defer count = %lld\n", unit,
(long long)adapter->stats.dc);
printf("ixgb%d: Missed Packets = %lld\n", unit,
(long long)adapter->stats.mpc);
printf("ixgb%d: Receive No Buffers = %lld\n", unit,
(long long)adapter->stats.rnbc);
printf("ixgb%d: Receive length errors = %lld\n", unit,
(long long)adapter->stats.rlec);
printf("ixgb%d: Crc errors = %lld\n", unit,
(long long)adapter->stats.crcerrs);
printf("ixgb%d: Driver dropped packets = %ld\n", unit,
adapter->dropped_pkts);
printf("ixgb%d: XON Rcvd = %lld\n", unit,
(long long)adapter->stats.xonrxc);
printf("ixgb%d: XON Xmtd = %lld\n", unit,
(long long)adapter->stats.xontxc);
printf("ixgb%d: XOFF Rcvd = %lld\n", unit,
(long long)adapter->stats.xoffrxc);
printf("ixgb%d: XOFF Xmtd = %lld\n", unit,
(long long)adapter->stats.xofftxc);
printf("ixgb%d: Good Packets Rcvd = %lld\n", unit,
(long long)adapter->stats.gprcl);
printf("ixgb%d: Good Packets Xmtd = %lld\n", unit,
(long long)adapter->stats.gptcl);
printf("ixgb%d: Jumbo frames recvd = %lld\n", unit,
(long long)adapter->stats.jprcl);
printf("ixgb%d: Jumbo frames Xmtd = %lld\n", unit,
(long long)adapter->stats.jptcl);
return;
}
static int
ixgb_sysctl_stats(SYSCTL_HANDLER_ARGS)
{
int error;
int result;
struct adapter *adapter;
result = -1;
error = sysctl_handle_int(oidp, &result, 0, req);
if (error || !req->newptr)
return (error);
if (result == 1) {
adapter = (struct adapter *) arg1;
ixgb_print_hw_stats(adapter);
}
return error;
}
|