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
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
|
/* $NetBSD: ixv.c,v 1.183 2022/07/06 06:31:47 msaitoh Exp $ */
/******************************************************************************
Copyright (c) 2001-2017, 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: head/sys/dev/ixgbe/if_ixv.c 331224 2018-03-19 20:55:05Z erj $*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ixv.c,v 1.183 2022/07/06 06:31:47 msaitoh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_net_mpsafe.h"
#endif
#include "ixgbe.h"
/************************************************************************
* Driver version
************************************************************************/
static const char ixv_driver_version[] = "2.0.1-k";
/* XXX NetBSD: + 1.5.17 */
/************************************************************************
* PCI Device ID Table
*
* Used by probe to select devices to load on
* Last field stores an index into ixv_strings
* Last entry must be all 0s
*
* { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
************************************************************************/
static const ixgbe_vendor_info_t ixv_vendor_info_array[] =
{
{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF, 0, 0, 0},
{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF, 0, 0, 0},
{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF, 0, 0, 0},
{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF, 0, 0, 0},
{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF, 0, 0, 0},
/* required last entry */
{0, 0, 0, 0, 0}
};
/************************************************************************
* Table of branding strings
************************************************************************/
static const char *ixv_strings[] = {
"Intel(R) PRO/10GbE Virtual Function Network Driver"
};
/*********************************************************************
* Function prototypes
*********************************************************************/
static int ixv_probe(device_t, cfdata_t, void *);
static void ixv_attach(device_t, device_t, void *);
static int ixv_detach(device_t, int);
#if 0
static int ixv_shutdown(device_t);
#endif
static int ixv_ifflags_cb(struct ethercom *);
static int ixv_ioctl(struct ifnet *, u_long, void *);
static int ixv_init(struct ifnet *);
static void ixv_init_locked(struct adapter *);
static void ixv_ifstop(struct ifnet *, int);
static void ixv_stop_locked(void *);
static void ixv_init_device_features(struct adapter *);
static void ixv_media_status(struct ifnet *, struct ifmediareq *);
static int ixv_media_change(struct ifnet *);
static int ixv_allocate_pci_resources(struct adapter *,
const struct pci_attach_args *);
static void ixv_free_deferred_handlers(struct adapter *);
static int ixv_allocate_msix(struct adapter *,
const struct pci_attach_args *);
static int ixv_configure_interrupts(struct adapter *);
static void ixv_free_pci_resources(struct adapter *);
static void ixv_local_timer(void *);
static void ixv_handle_timer(struct work *, void *);
static int ixv_setup_interface(device_t, struct adapter *);
static void ixv_schedule_admin_tasklet(struct adapter *);
static int ixv_negotiate_api(struct adapter *);
static void ixv_initialize_transmit_units(struct adapter *);
static void ixv_initialize_receive_units(struct adapter *);
static void ixv_initialize_rss_mapping(struct adapter *);
static s32 ixv_check_link(struct adapter *);
static void ixv_enable_intr(struct adapter *);
static void ixv_disable_intr(struct adapter *);
static int ixv_set_rxfilter(struct adapter *);
static void ixv_update_link_status(struct adapter *);
static int ixv_sysctl_debug(SYSCTLFN_PROTO);
static void ixv_set_ivar(struct adapter *, u8, u8, s8);
static void ixv_configure_ivars(struct adapter *);
static u8 * ixv_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
static void ixv_eitr_write(struct adapter *, uint32_t, uint32_t);
static void ixv_setup_vlan_tagging(struct adapter *);
static int ixv_setup_vlan_support(struct adapter *);
static int ixv_vlan_cb(struct ethercom *, uint16_t, bool);
static int ixv_register_vlan(struct adapter *, u16);
static int ixv_unregister_vlan(struct adapter *, u16);
static void ixv_add_device_sysctls(struct adapter *);
static void ixv_init_stats(struct adapter *);
static void ixv_update_stats(struct adapter *);
static void ixv_add_stats_sysctls(struct adapter *);
static void ixv_clear_evcnt(struct adapter *);
/* Sysctl handlers */
static int ixv_sysctl_interrupt_rate_handler(SYSCTLFN_PROTO);
static int ixv_sysctl_next_to_check_handler(SYSCTLFN_PROTO);
static int ixv_sysctl_next_to_refresh_handler(SYSCTLFN_PROTO);
static int ixv_sysctl_rdh_handler(SYSCTLFN_PROTO);
static int ixv_sysctl_rdt_handler(SYSCTLFN_PROTO);
static int ixv_sysctl_tdt_handler(SYSCTLFN_PROTO);
static int ixv_sysctl_tdh_handler(SYSCTLFN_PROTO);
static int ixv_sysctl_tx_process_limit(SYSCTLFN_PROTO);
static int ixv_sysctl_rx_process_limit(SYSCTLFN_PROTO);
static int ixv_sysctl_rx_copy_len(SYSCTLFN_PROTO);
/* The MSI-X Interrupt handlers */
static int ixv_msix_que(void *);
static int ixv_msix_mbx(void *);
/* Event handlers running on workqueue */
static void ixv_handle_que(void *);
/* Deferred workqueue handlers */
static void ixv_handle_admin(struct work *, void *);
static void ixv_handle_que_work(struct work *, void *);
const struct sysctlnode *ixv_sysctl_instance(struct adapter *);
static const ixgbe_vendor_info_t *ixv_lookup(const struct pci_attach_args *);
/************************************************************************
* NetBSD Device Interface Entry Points
************************************************************************/
CFATTACH_DECL3_NEW(ixv, sizeof(struct adapter),
ixv_probe, ixv_attach, ixv_detach, NULL, NULL, NULL,
DVF_DETACH_SHUTDOWN);
#if 0
static driver_t ixv_driver = {
"ixv", ixv_methods, sizeof(struct adapter),
};
devclass_t ixv_devclass;
DRIVER_MODULE(ixv, pci, ixv_driver, ixv_devclass, 0, 0);
MODULE_DEPEND(ixv, pci, 1, 1, 1);
MODULE_DEPEND(ixv, ether, 1, 1, 1);
#endif
/*
* TUNEABLE PARAMETERS:
*/
/* Number of Queues - do not exceed MSI-X vectors - 1 */
static int ixv_num_queues = 0;
#define TUNABLE_INT(__x, __y)
TUNABLE_INT("hw.ixv.num_queues", &ixv_num_queues);
/*
* AIM: Adaptive Interrupt Moderation
* which means that the interrupt rate
* is varied over time based on the
* traffic for that interrupt vector
*/
static bool ixv_enable_aim = false;
TUNABLE_INT("hw.ixv.enable_aim", &ixv_enable_aim);
static int ixv_max_interrupt_rate = (4000000 / IXGBE_LOW_LATENCY);
TUNABLE_INT("hw.ixv.max_interrupt_rate", &ixv_max_interrupt_rate);
/* How many packets rxeof tries to clean at a time */
static int ixv_rx_process_limit = 256;
TUNABLE_INT("hw.ixv.rx_process_limit", &ixv_rx_process_limit);
/* How many packets txeof tries to clean at a time */
static int ixv_tx_process_limit = 256;
TUNABLE_INT("hw.ixv.tx_process_limit", &ixv_tx_process_limit);
/* Which packet processing uses workqueue or softint */
static bool ixv_txrx_workqueue = false;
/*
* Number of TX descriptors per ring,
* setting higher than RX as this seems
* the better performing choice.
*/
static int ixv_txd = PERFORM_TXD;
TUNABLE_INT("hw.ixv.txd", &ixv_txd);
/* Number of RX descriptors per ring */
static int ixv_rxd = PERFORM_RXD;
TUNABLE_INT("hw.ixv.rxd", &ixv_rxd);
/* Legacy Transmit (single queue) */
static int ixv_enable_legacy_tx = 0;
TUNABLE_INT("hw.ixv.enable_legacy_tx", &ixv_enable_legacy_tx);
#ifdef NET_MPSAFE
#define IXGBE_MPSAFE 1
#define IXGBE_CALLOUT_FLAGS CALLOUT_MPSAFE
#define IXGBE_SOFTINT_FLAGS SOFTINT_MPSAFE
#define IXGBE_WORKQUEUE_FLAGS WQ_PERCPU | WQ_MPSAFE
#define IXGBE_TASKLET_WQ_FLAGS WQ_MPSAFE
#else
#define IXGBE_CALLOUT_FLAGS 0
#define IXGBE_SOFTINT_FLAGS 0
#define IXGBE_WORKQUEUE_FLAGS WQ_PERCPU
#define IXGBE_TASKLET_WQ_FLAGS 0
#endif
#define IXGBE_WORKQUEUE_PRI PRI_SOFTNET
#if 0
static int (*ixv_start_locked)(struct ifnet *, struct tx_ring *);
static int (*ixv_ring_empty)(struct ifnet *, struct buf_ring *);
#endif
/************************************************************************
* ixv_probe - Device identification routine
*
* Determines if the driver should be loaded on
* adapter based on its PCI vendor/device ID.
*
* return BUS_PROBE_DEFAULT on success, positive on failure
************************************************************************/
static int
ixv_probe(device_t dev, cfdata_t cf, void *aux)
{
#ifdef __HAVE_PCI_MSI_MSIX
const struct pci_attach_args *pa = aux;
return (ixv_lookup(pa) != NULL) ? 1 : 0;
#else
return 0;
#endif
} /* ixv_probe */
static const ixgbe_vendor_info_t *
ixv_lookup(const struct pci_attach_args *pa)
{
const ixgbe_vendor_info_t *ent;
pcireg_t subid;
INIT_DEBUGOUT("ixv_lookup: begin");
if (PCI_VENDOR(pa->pa_id) != IXGBE_INTEL_VENDOR_ID)
return NULL;
subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
for (ent = ixv_vendor_info_array; ent->vendor_id != 0; ent++) {
if ((PCI_VENDOR(pa->pa_id) == ent->vendor_id) &&
(PCI_PRODUCT(pa->pa_id) == ent->device_id) &&
((PCI_SUBSYS_VENDOR(subid) == ent->subvendor_id) ||
(ent->subvendor_id == 0)) &&
((PCI_SUBSYS_ID(subid) == ent->subdevice_id) ||
(ent->subdevice_id == 0))) {
return ent;
}
}
return NULL;
}
/************************************************************************
* ixv_attach - Device initialization routine
*
* Called when the driver is being loaded.
* Identifies the type of hardware, allocates all resources
* and initializes the hardware.
*
* return 0 on success, positive on failure
************************************************************************/
static void
ixv_attach(device_t parent, device_t dev, void *aux)
{
struct adapter *adapter;
struct ixgbe_hw *hw;
int error = 0;
pcireg_t id, subid;
const ixgbe_vendor_info_t *ent;
const struct pci_attach_args *pa = aux;
const char *apivstr;
const char *str;
char wqname[MAXCOMLEN];
char buf[256];
INIT_DEBUGOUT("ixv_attach: begin");
/*
* Make sure BUSMASTER is set, on a VM under
* KVM it may not be and will break things.
*/
ixgbe_pci_enable_busmaster(pa->pa_pc, pa->pa_tag);
/* Allocate, clear, and link in our adapter structure */
adapter = device_private(dev);
adapter->hw.back = adapter;
adapter->dev = dev;
hw = &adapter->hw;
adapter->init_locked = ixv_init_locked;
adapter->stop_locked = ixv_stop_locked;
adapter->osdep.pc = pa->pa_pc;
adapter->osdep.tag = pa->pa_tag;
if (pci_dma64_available(pa))
adapter->osdep.dmat = pa->pa_dmat64;
else
adapter->osdep.dmat = pa->pa_dmat;
adapter->osdep.attached = false;
ent = ixv_lookup(pa);
KASSERT(ent != NULL);
aprint_normal(": %s, Version - %s\n",
ixv_strings[ent->index], ixv_driver_version);
/* Core Lock Init */
IXGBE_CORE_LOCK_INIT(adapter, device_xname(dev));
/* Do base PCI setup - map BAR0 */
if (ixv_allocate_pci_resources(adapter, pa)) {
aprint_error_dev(dev, "ixv_allocate_pci_resources() failed!\n");
error = ENXIO;
goto err_out;
}
/* SYSCTL APIs */
ixv_add_device_sysctls(adapter);
/* Set up the timer callout and workqueue */
callout_init(&adapter->timer, IXGBE_CALLOUT_FLAGS);
snprintf(wqname, sizeof(wqname), "%s-timer", device_xname(dev));
error = workqueue_create(&adapter->timer_wq, wqname,
ixv_handle_timer, adapter, IXGBE_WORKQUEUE_PRI, IPL_NET,
IXGBE_TASKLET_WQ_FLAGS);
if (error) {
aprint_error_dev(dev,
"could not create timer workqueue (%d)\n", error);
goto err_out;
}
/* Save off the information about this board */
id = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_ID_REG);
subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
hw->vendor_id = PCI_VENDOR(id);
hw->device_id = PCI_PRODUCT(id);
hw->revision_id =
PCI_REVISION(pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG));
hw->subsystem_vendor_id = PCI_SUBSYS_VENDOR(subid);
hw->subsystem_device_id = PCI_SUBSYS_ID(subid);
/* A subset of set_mac_type */
switch (hw->device_id) {
case IXGBE_DEV_ID_82599_VF:
hw->mac.type = ixgbe_mac_82599_vf;
str = "82599 VF";
break;
case IXGBE_DEV_ID_X540_VF:
hw->mac.type = ixgbe_mac_X540_vf;
str = "X540 VF";
break;
case IXGBE_DEV_ID_X550_VF:
hw->mac.type = ixgbe_mac_X550_vf;
str = "X550 VF";
break;
case IXGBE_DEV_ID_X550EM_X_VF:
hw->mac.type = ixgbe_mac_X550EM_x_vf;
str = "X550EM X VF";
break;
case IXGBE_DEV_ID_X550EM_A_VF:
hw->mac.type = ixgbe_mac_X550EM_a_vf;
str = "X550EM A VF";
break;
default:
/* Shouldn't get here since probe succeeded */
aprint_error_dev(dev, "Unknown device ID!\n");
error = ENXIO;
goto err_out;
break;
}
aprint_normal_dev(dev, "device %s\n", str);
ixv_init_device_features(adapter);
/* Initialize the shared code */
error = ixgbe_init_ops_vf(hw);
if (error) {
aprint_error_dev(dev, "ixgbe_init_ops_vf() failed!\n");
error = EIO;
goto err_out;
}
/* Setup the mailbox */
ixgbe_init_mbx_params_vf(hw);
/* Set the right number of segments */
KASSERT(IXGBE_82599_SCATTER_MAX >= IXGBE_SCATTER_DEFAULT);
adapter->num_segs = IXGBE_SCATTER_DEFAULT;
/* Reset mbox api to 1.0 */
error = hw->mac.ops.reset_hw(hw);
if (error == IXGBE_ERR_RESET_FAILED)
aprint_error_dev(dev, "...reset_hw() failure: Reset Failed!\n");
else if (error)
aprint_error_dev(dev, "...reset_hw() failed with error %d\n",
error);
if (error) {
error = EIO;
goto err_out;
}
error = hw->mac.ops.init_hw(hw);
if (error) {
aprint_error_dev(dev, "...init_hw() failed!\n");
error = EIO;
goto err_out;
}
/* Negotiate mailbox API version */
error = ixv_negotiate_api(adapter);
if (error)
aprint_normal_dev(dev,
"MBX API negotiation failed during attach!\n");
switch (hw->api_version) {
case ixgbe_mbox_api_10:
apivstr = "1.0";
break;
case ixgbe_mbox_api_20:
apivstr = "2.0";
break;
case ixgbe_mbox_api_11:
apivstr = "1.1";
break;
case ixgbe_mbox_api_12:
apivstr = "1.2";
break;
case ixgbe_mbox_api_13:
apivstr = "1.3";
break;
case ixgbe_mbox_api_14:
apivstr = "1.4";
break;
case ixgbe_mbox_api_15:
apivstr = "1.5";
break;
default:
apivstr = "unknown";
break;
}
aprint_normal_dev(dev, "Mailbox API %s\n", apivstr);
/* If no mac address was assigned, make a random one */
if (!ixv_check_ether_addr(hw->mac.addr)) {
u8 addr[ETHER_ADDR_LEN];
uint64_t rndval = cprng_strong64();
memcpy(addr, &rndval, sizeof(addr));
addr[0] &= 0xFE;
addr[0] |= 0x02;
bcopy(addr, hw->mac.addr, sizeof(addr));
}
/* Register for VLAN events */
ether_set_vlan_cb(&adapter->osdep.ec, ixv_vlan_cb);
/* Do descriptor calc and sanity checks */
if (((ixv_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
ixv_txd < MIN_TXD || ixv_txd > MAX_TXD) {
aprint_error_dev(dev, "TXD config issue, using default!\n");
adapter->num_tx_desc = DEFAULT_TXD;
} else
adapter->num_tx_desc = ixv_txd;
if (((ixv_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
ixv_rxd < MIN_RXD || ixv_rxd > MAX_RXD) {
aprint_error_dev(dev, "RXD config issue, using default!\n");
adapter->num_rx_desc = DEFAULT_RXD;
} else
adapter->num_rx_desc = ixv_rxd;
/* Sysctls for limiting the amount of work done in the taskqueues */
adapter->rx_process_limit
= (ixv_rx_process_limit <= adapter->num_rx_desc)
? ixv_rx_process_limit : adapter->num_rx_desc;
adapter->tx_process_limit
= (ixv_tx_process_limit <= adapter->num_tx_desc)
? ixv_tx_process_limit : adapter->num_tx_desc;
/* Set default high limit of copying mbuf in rxeof */
adapter->rx_copy_len = IXGBE_RX_COPY_LEN_MAX;
/* Setup MSI-X */
error = ixv_configure_interrupts(adapter);
if (error)
goto err_out;
/* Allocate our TX/RX Queues */
if (ixgbe_allocate_queues(adapter)) {
aprint_error_dev(dev, "ixgbe_allocate_queues() failed!\n");
error = ENOMEM;
goto err_out;
}
/* hw.ix defaults init */
adapter->enable_aim = ixv_enable_aim;
adapter->txrx_use_workqueue = ixv_txrx_workqueue;
error = ixv_allocate_msix(adapter, pa);
if (error) {
aprint_error_dev(dev, "ixv_allocate_msix() failed!\n");
goto err_late;
}
/* Setup OS specific network interface */
error = ixv_setup_interface(dev, adapter);
if (error != 0) {
aprint_error_dev(dev, "ixv_setup_interface() failed!\n");
goto err_late;
}
/* Allocate multicast array memory */
adapter->mta = malloc(sizeof(*adapter->mta) *
IXGBE_MAX_VF_MC, M_DEVBUF, M_WAITOK);
/* Do the stats setup */
ixv_init_stats(adapter);
ixv_add_stats_sysctls(adapter);
if (adapter->feat_en & IXGBE_FEATURE_NETMAP)
ixgbe_netmap_attach(adapter);
snprintb(buf, sizeof(buf), IXGBE_FEATURE_FLAGS, adapter->feat_cap);
aprint_verbose_dev(dev, "feature cap %s\n", buf);
snprintb(buf, sizeof(buf), IXGBE_FEATURE_FLAGS, adapter->feat_en);
aprint_verbose_dev(dev, "feature ena %s\n", buf);
INIT_DEBUGOUT("ixv_attach: end");
adapter->osdep.attached = true;
return;
err_late:
ixgbe_free_queues(adapter);
err_out:
ixv_free_pci_resources(adapter);
IXGBE_CORE_LOCK_DESTROY(adapter);
return;
} /* ixv_attach */
/************************************************************************
* ixv_detach - Device removal routine
*
* Called when the driver is being removed.
* Stops the adapter and deallocates all the resources
* that were allocated for driver operation.
*
* return 0 on success, positive on failure
************************************************************************/
static int
ixv_detach(device_t dev, int flags)
{
struct adapter *adapter = device_private(dev);
struct ixgbe_hw *hw = &adapter->hw;
struct tx_ring *txr = adapter->tx_rings;
struct rx_ring *rxr = adapter->rx_rings;
struct ixgbevf_hw_stats *stats = &adapter->stats.vf;
INIT_DEBUGOUT("ixv_detach: begin");
if (adapter->osdep.attached == false)
return 0;
/* Stop the interface. Callouts are stopped in it. */
ixv_ifstop(adapter->ifp, 1);
if (VLAN_ATTACHED(&adapter->osdep.ec) &&
(flags & (DETACH_SHUTDOWN | DETACH_FORCE)) == 0) {
aprint_error_dev(dev, "VLANs in use, detach first\n");
return EBUSY;
}
ether_ifdetach(adapter->ifp);
callout_halt(&adapter->timer, NULL);
ixv_free_deferred_handlers(adapter);
if (adapter->feat_en & IXGBE_FEATURE_NETMAP)
netmap_detach(adapter->ifp);
ixv_free_pci_resources(adapter);
#if 0 /* XXX the NetBSD port is probably missing something here */
bus_generic_detach(dev);
#endif
if_detach(adapter->ifp);
ifmedia_fini(&adapter->media);
if_percpuq_destroy(adapter->ipq);
sysctl_teardown(&adapter->sysctllog);
evcnt_detach(&adapter->efbig_tx_dma_setup);
evcnt_detach(&adapter->mbuf_defrag_failed);
evcnt_detach(&adapter->efbig2_tx_dma_setup);
evcnt_detach(&adapter->einval_tx_dma_setup);
evcnt_detach(&adapter->other_tx_dma_setup);
evcnt_detach(&adapter->eagain_tx_dma_setup);
evcnt_detach(&adapter->enomem_tx_dma_setup);
evcnt_detach(&adapter->watchdog_events);
evcnt_detach(&adapter->tso_err);
evcnt_detach(&adapter->admin_irqev);
evcnt_detach(&adapter->link_workev);
txr = adapter->tx_rings;
for (int i = 0; i < adapter->num_queues; i++, rxr++, txr++) {
evcnt_detach(&adapter->queues[i].irqs);
evcnt_detach(&adapter->queues[i].handleq);
evcnt_detach(&adapter->queues[i].req);
evcnt_detach(&txr->no_desc_avail);
evcnt_detach(&txr->total_packets);
evcnt_detach(&txr->tso_tx);
#ifndef IXGBE_LEGACY_TX
evcnt_detach(&txr->pcq_drops);
#endif
evcnt_detach(&rxr->rx_packets);
evcnt_detach(&rxr->rx_bytes);
evcnt_detach(&rxr->rx_copies);
evcnt_detach(&rxr->no_mbuf);
evcnt_detach(&rxr->rx_discarded);
}
evcnt_detach(&stats->ipcs);
evcnt_detach(&stats->l4cs);
evcnt_detach(&stats->ipcs_bad);
evcnt_detach(&stats->l4cs_bad);
/* Packet Reception Stats */
evcnt_detach(&stats->vfgorc);
evcnt_detach(&stats->vfgprc);
evcnt_detach(&stats->vfmprc);
/* Packet Transmission Stats */
evcnt_detach(&stats->vfgotc);
evcnt_detach(&stats->vfgptc);
/* Mailbox Stats */
evcnt_detach(&hw->mbx.stats.msgs_tx);
evcnt_detach(&hw->mbx.stats.msgs_rx);
evcnt_detach(&hw->mbx.stats.acks);
evcnt_detach(&hw->mbx.stats.reqs);
evcnt_detach(&hw->mbx.stats.rsts);
ixgbe_free_queues(adapter);
IXGBE_CORE_LOCK_DESTROY(adapter);
return (0);
} /* ixv_detach */
/************************************************************************
* ixv_init_locked - Init entry point
*
* Used in two ways: It is used by the stack as an 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
ixv_init_locked(struct adapter *adapter)
{
struct ifnet *ifp = adapter->ifp;
device_t dev = adapter->dev;
struct ixgbe_hw *hw = &adapter->hw;
struct ix_queue *que;
int error = 0;
uint32_t mask;
int i;
INIT_DEBUGOUT("ixv_init_locked: begin");
KASSERT(mutex_owned(&adapter->core_mtx));
hw->adapter_stopped = FALSE;
hw->mac.ops.stop_adapter(hw);
callout_stop(&adapter->timer);
for (i = 0, que = adapter->queues; i < adapter->num_queues; i++, que++)
que->disabled_count = 0;
adapter->max_frame_size =
ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
/* reprogram the RAR[0] in case user changed it. */
hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
/* Get the latest mac address, User can use a LAA */
memcpy(hw->mac.addr, CLLADDR(ifp->if_sadl),
IXGBE_ETH_LENGTH_OF_ADDRESS);
hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, 1);
/* Prepare transmit descriptors and buffers */
if (ixgbe_setup_transmit_structures(adapter)) {
aprint_error_dev(dev, "Could not setup transmit structures\n");
ixv_stop_locked(adapter);
return;
}
/* Reset VF and renegotiate mailbox API version */
hw->mac.ops.reset_hw(hw);
hw->mac.ops.start_hw(hw);
error = ixv_negotiate_api(adapter);
if (error)
device_printf(dev,
"Mailbox API negotiation failed in init_locked!\n");
ixv_initialize_transmit_units(adapter);
/* Setup Multicast table */
ixv_set_rxfilter(adapter);
/* Use fixed buffer size, even for jumbo frames */
adapter->rx_mbuf_sz = MCLBYTES;
/* Prepare receive descriptors and buffers */
error = ixgbe_setup_receive_structures(adapter);
if (error) {
device_printf(dev,
"Could not setup receive structures (err = %d)\n", error);
ixv_stop_locked(adapter);
return;
}
/* Configure RX settings */
ixv_initialize_receive_units(adapter);
/* Initialize variable holding task enqueue requests interrupts */
adapter->task_requests = 0;
/* Set up VLAN offload and filter */
ixv_setup_vlan_support(adapter);
/* Set up MSI-X routing */
ixv_configure_ivars(adapter);
/* Set up auto-mask */
mask = (1 << adapter->vector);
for (i = 0, que = adapter->queues; i < adapter->num_queues; i++, que++)
mask |= (1 << que->msix);
IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, mask);
/* Set moderation on the Link interrupt */
ixv_eitr_write(adapter, adapter->vector, IXGBE_LINK_ITR);
/* Stats init */
ixv_init_stats(adapter);
/* Config/Enable Link */
hw->mac.get_link_status = TRUE;
hw->mac.ops.check_link(hw, &adapter->link_speed, &adapter->link_up,
FALSE);
/* Start watchdog */
callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
atomic_store_relaxed(&adapter->timer_pending, 0);
/* OK to schedule workqueues. */
adapter->schedule_wqs_ok = true;
/* And now turn on interrupts */
ixv_enable_intr(adapter);
/* Update saved flags. See ixgbe_ifflags_cb() */
adapter->if_flags = ifp->if_flags;
adapter->ec_capenable = adapter->osdep.ec.ec_capenable;
/* Now inform the stack we're ready */
ifp->if_flags |= IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE;
return;
} /* ixv_init_locked */
/************************************************************************
* ixv_enable_queue
************************************************************************/
static inline void
ixv_enable_queue(struct adapter *adapter, u32 vector)
{
struct ixgbe_hw *hw = &adapter->hw;
struct ix_queue *que = &adapter->queues[vector];
u32 queue = 1UL << vector;
u32 mask;
mutex_enter(&que->dc_mtx);
if (que->disabled_count > 0 && --que->disabled_count > 0)
goto out;
mask = (IXGBE_EIMS_RTX_QUEUE & queue);
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
out:
mutex_exit(&que->dc_mtx);
} /* ixv_enable_queue */
/************************************************************************
* ixv_disable_queue
************************************************************************/
static inline void
ixv_disable_queue(struct adapter *adapter, u32 vector)
{
struct ixgbe_hw *hw = &adapter->hw;
struct ix_queue *que = &adapter->queues[vector];
u32 queue = 1UL << vector;
u32 mask;
mutex_enter(&que->dc_mtx);
if (que->disabled_count++ > 0)
goto out;
mask = (IXGBE_EIMS_RTX_QUEUE & queue);
IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, mask);
out:
mutex_exit(&que->dc_mtx);
} /* ixv_disable_queue */
#if 0
static inline void
ixv_rearm_queues(struct adapter *adapter, u64 queues)
{
u32 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEICS, mask);
} /* ixv_rearm_queues */
#endif
/************************************************************************
* ixv_msix_que - MSI-X Queue Interrupt Service routine
************************************************************************/
static int
ixv_msix_que(void *arg)
{
struct ix_queue *que = arg;
struct adapter *adapter = que->adapter;
struct tx_ring *txr = que->txr;
struct rx_ring *rxr = que->rxr;
bool more;
u32 newitr = 0;
ixv_disable_queue(adapter, que->msix);
IXGBE_EVC_ADD(&que->irqs, 1);
#ifdef __NetBSD__
/* Don't run ixgbe_rxeof in interrupt context */
more = true;
#else
more = ixgbe_rxeof(que);
#endif
IXGBE_TX_LOCK(txr);
ixgbe_txeof(txr);
IXGBE_TX_UNLOCK(txr);
/* Do AIM now? */
if (adapter->enable_aim == false)
goto no_calc;
/*
* Do Adaptive Interrupt Moderation:
* - Write out last calculated setting
* - Calculate based on average size over
* the last interval.
*/
if (que->eitr_setting)
ixv_eitr_write(adapter, que->msix, que->eitr_setting);
que->eitr_setting = 0;
/* Idle, do nothing */
if ((txr->bytes == 0) && (rxr->bytes == 0))
goto no_calc;
if ((txr->bytes) && (txr->packets))
newitr = txr->bytes/txr->packets;
if ((rxr->bytes) && (rxr->packets))
newitr = uimax(newitr, (rxr->bytes / rxr->packets));
newitr += 24; /* account for hardware frame, crc */
/* set an upper boundary */
newitr = uimin(newitr, 3000);
/* Be nice to the mid range */
if ((newitr > 300) && (newitr < 1200))
newitr = (newitr / 3);
else
newitr = (newitr / 2);
/*
* When RSC is used, ITR interval must be larger than RSC_DELAY.
* Currently, we use 2us for RSC_DELAY. The minimum value is always
* greater than 2us on 100M (and 10M?(not documented)), but it's not
* on 1G and higher.
*/
if ((adapter->link_speed != IXGBE_LINK_SPEED_100_FULL)
&& (adapter->link_speed != IXGBE_LINK_SPEED_10_FULL)) {
if (newitr < IXGBE_MIN_RSC_EITR_10G1G)
newitr = IXGBE_MIN_RSC_EITR_10G1G;
}
/* save for next interrupt */
que->eitr_setting = newitr;
/* Reset state */
txr->bytes = 0;
txr->packets = 0;
rxr->bytes = 0;
rxr->packets = 0;
no_calc:
if (more)
softint_schedule(que->que_si);
else /* Re-enable this interrupt */
ixv_enable_queue(adapter, que->msix);
return 1;
} /* ixv_msix_que */
/************************************************************************
* ixv_msix_mbx
************************************************************************/
static int
ixv_msix_mbx(void *arg)
{
struct adapter *adapter = arg;
struct ixgbe_hw *hw = &adapter->hw;
IXGBE_EVC_ADD(&adapter->admin_irqev, 1);
/* NetBSD: We use auto-clear, so it's not required to write VTEICR */
/* Link status change */
hw->mac.get_link_status = TRUE;
atomic_or_32(&adapter->task_requests, IXGBE_REQUEST_TASK_MBX);
ixv_schedule_admin_tasklet(adapter);
return 1;
} /* ixv_msix_mbx */
static void
ixv_eitr_write(struct adapter *adapter, uint32_t index, uint32_t itr)
{
/*
* Newer devices than 82598 have VF function, so this function is
* simple.
*/
itr |= IXGBE_EITR_CNT_WDIS;
IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEITR(index), itr);
}
/************************************************************************
* ixv_media_status - Media Ioctl callback
*
* Called whenever the user queries the status of
* the interface using ifconfig.
************************************************************************/
static void
ixv_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
{
struct adapter *adapter = ifp->if_softc;
INIT_DEBUGOUT("ixv_media_status: begin");
ixv_update_link_status(adapter);
ifmr->ifm_status = IFM_AVALID;
ifmr->ifm_active = IFM_ETHER;
if (adapter->link_active != LINK_STATE_UP) {
ifmr->ifm_active |= IFM_NONE;
return;
}
ifmr->ifm_status |= IFM_ACTIVE;
switch (adapter->link_speed) {
case IXGBE_LINK_SPEED_10GB_FULL:
ifmr->ifm_active |= IFM_10G_T | IFM_FDX;
break;
case IXGBE_LINK_SPEED_5GB_FULL:
ifmr->ifm_active |= IFM_5000_T | IFM_FDX;
break;
case IXGBE_LINK_SPEED_2_5GB_FULL:
ifmr->ifm_active |= IFM_2500_T | IFM_FDX;
break;
case IXGBE_LINK_SPEED_1GB_FULL:
ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
break;
case IXGBE_LINK_SPEED_100_FULL:
ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
break;
case IXGBE_LINK_SPEED_10_FULL:
ifmr->ifm_active |= IFM_10_T | IFM_FDX;
break;
}
ifp->if_baudrate = ifmedia_baudrate(ifmr->ifm_active);
} /* ixv_media_status */
/************************************************************************
* ixv_media_change - Media Ioctl callback
*
* Called when the user changes speed/duplex using
* media/mediopt option with ifconfig.
************************************************************************/
static int
ixv_media_change(struct ifnet *ifp)
{
struct adapter *adapter = ifp->if_softc;
struct ifmedia *ifm = &adapter->media;
INIT_DEBUGOUT("ixv_media_change: begin");
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
return (EINVAL);
switch (IFM_SUBTYPE(ifm->ifm_media)) {
case IFM_AUTO:
break;
default:
device_printf(adapter->dev, "Only auto media type\n");
return (EINVAL);
}
return (0);
} /* ixv_media_change */
static void
ixv_schedule_admin_tasklet(struct adapter *adapter)
{
if (adapter->schedule_wqs_ok) {
if (atomic_cas_uint(&adapter->admin_pending, 0, 1) == 0)
workqueue_enqueue(adapter->admin_wq,
&adapter->admin_wc, NULL);
}
}
/************************************************************************
* ixv_negotiate_api
*
* Negotiate the Mailbox API with the PF;
* start with the most featured API first.
************************************************************************/
static int
ixv_negotiate_api(struct adapter *adapter)
{
struct ixgbe_hw *hw = &adapter->hw;
int mbx_api[] = { ixgbe_mbox_api_15,
ixgbe_mbox_api_13,
ixgbe_mbox_api_12,
ixgbe_mbox_api_11,
ixgbe_mbox_api_10,
ixgbe_mbox_api_unknown };
int i = 0;
while (mbx_api[i] != ixgbe_mbox_api_unknown) {
if (ixgbevf_negotiate_api_version(hw, mbx_api[i]) == 0) {
if (hw->api_version >= ixgbe_mbox_api_15)
ixgbe_upgrade_mbx_params_vf(hw);
return (0);
}
i++;
}
return (EINVAL);
} /* ixv_negotiate_api */
/************************************************************************
* ixv_set_rxfilter - Multicast Update
*
* Called whenever multicast address list is updated.
************************************************************************/
static int
ixv_set_rxfilter(struct adapter *adapter)
{
struct ixgbe_mc_addr *mta;
struct ifnet *ifp = adapter->ifp;
struct ixgbe_hw *hw = &adapter->hw;
u8 *update_ptr;
int mcnt = 0;
struct ethercom *ec = &adapter->osdep.ec;
struct ether_multi *enm;
struct ether_multistep step;
bool overflow = false;
int error, rc = 0;
KASSERT(mutex_owned(&adapter->core_mtx));
IOCTL_DEBUGOUT("ixv_set_rxfilter: begin");
mta = adapter->mta;
bzero(mta, sizeof(*mta) * IXGBE_MAX_VF_MC);
/* 1: For PROMISC */
if (ifp->if_flags & IFF_PROMISC) {
error = hw->mac.ops.update_xcast_mode(hw,
IXGBEVF_XCAST_MODE_PROMISC);
if (error == IXGBE_ERR_NOT_TRUSTED) {
device_printf(adapter->dev,
"this interface is not trusted\n");
error = EPERM;
} else if (error == IXGBE_ERR_FEATURE_NOT_SUPPORTED) {
device_printf(adapter->dev,
"the PF doesn't support promisc mode\n");
error = EOPNOTSUPP;
} else if (error == IXGBE_ERR_NOT_IN_PROMISC) {
device_printf(adapter->dev,
"the PF may not in promisc mode\n");
error = EINVAL;
} else if (error) {
device_printf(adapter->dev,
"failed to set promisc mode. error = %d\n",
error);
error = EIO;
} else
return 0;
rc = error;
}
/* 2: For ALLMULTI or normal */
ETHER_LOCK(ec);
ETHER_FIRST_MULTI(step, ec, enm);
while (enm != NULL) {
if ((mcnt >= IXGBE_MAX_VF_MC) ||
(memcmp(enm->enm_addrlo, enm->enm_addrhi,
ETHER_ADDR_LEN) != 0)) {
overflow = true;
break;
}
bcopy(enm->enm_addrlo,
mta[mcnt].addr, IXGBE_ETH_LENGTH_OF_ADDRESS);
mcnt++;
ETHER_NEXT_MULTI(step, enm);
}
ETHER_UNLOCK(ec);
/* 3: For ALLMULTI */
if (overflow) {
error = hw->mac.ops.update_xcast_mode(hw,
IXGBEVF_XCAST_MODE_ALLMULTI);
if (error == IXGBE_ERR_NOT_TRUSTED) {
device_printf(adapter->dev,
"this interface is not trusted\n");
error = EPERM;
} else if (error == IXGBE_ERR_FEATURE_NOT_SUPPORTED) {
device_printf(adapter->dev,
"the PF doesn't support allmulti mode\n");
error = EOPNOTSUPP;
} else if (error) {
device_printf(adapter->dev,
"number of Ethernet multicast addresses "
"exceeds the limit (%d). error = %d\n",
IXGBE_MAX_VF_MC, error);
error = ENOSPC;
} else {
ETHER_LOCK(ec);
ec->ec_flags |= ETHER_F_ALLMULTI;
ETHER_UNLOCK(ec);
return rc; /* Promisc might have failed */
}
if (rc == 0)
rc = error;
/* Continue to update the multicast table as many as we can */
}
/* 4: For normal operation */
error = hw->mac.ops.update_xcast_mode(hw, IXGBEVF_XCAST_MODE_MULTI);
if ((error == IXGBE_ERR_FEATURE_NOT_SUPPORTED) || (error == 0)) {
/* Normal operation */
ETHER_LOCK(ec);
ec->ec_flags &= ~ETHER_F_ALLMULTI;
ETHER_UNLOCK(ec);
error = 0;
} else if (error) {
device_printf(adapter->dev,
"failed to set Ethernet multicast address "
"operation to normal. error = %d\n", error);
}
update_ptr = (u8 *)mta;
error = adapter->hw.mac.ops.update_mc_addr_list(&adapter->hw,
update_ptr, mcnt, ixv_mc_array_itr, TRUE);
if (rc == 0)
rc = error;
return rc;
} /* ixv_set_rxfilter */
/************************************************************************
* ixv_mc_array_itr
*
* An iterator function needed by the multicast shared code.
* It feeds the shared code routine the addresses in the
* array of ixv_set_rxfilter() one by one.
************************************************************************/
static u8 *
ixv_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
{
struct ixgbe_mc_addr *mta;
mta = (struct ixgbe_mc_addr *)*update_ptr;
*vmdq = 0;
*update_ptr = (u8*)(mta + 1);
return (mta->addr);
} /* ixv_mc_array_itr */
/************************************************************************
* ixv_local_timer - Timer routine
*
* Checks for link status, updates statistics,
* and runs the watchdog check.
************************************************************************/
static void
ixv_local_timer(void *arg)
{
struct adapter *adapter = arg;
if (adapter->schedule_wqs_ok) {
if (atomic_cas_uint(&adapter->timer_pending, 0, 1) == 0)
workqueue_enqueue(adapter->timer_wq,
&adapter->timer_wc, NULL);
}
}
static void
ixv_handle_timer(struct work *wk, void *context)
{
struct adapter *adapter = context;
device_t dev = adapter->dev;
struct ix_queue *que = adapter->queues;
u64 queues = 0;
u64 v0, v1, v2, v3, v4, v5, v6, v7;
int hung = 0;
int i;
IXGBE_CORE_LOCK(adapter);
if (ixv_check_link(adapter)) {
ixv_init_locked(adapter);
IXGBE_CORE_UNLOCK(adapter);
return;
}
/* Stats Update */
ixv_update_stats(adapter);
/* Update some event counters */
v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = 0;
que = adapter->queues;
for (i = 0; i < adapter->num_queues; i++, que++) {
struct tx_ring *txr = que->txr;
v0 += txr->q_efbig_tx_dma_setup;
v1 += txr->q_mbuf_defrag_failed;
v2 += txr->q_efbig2_tx_dma_setup;
v3 += txr->q_einval_tx_dma_setup;
v4 += txr->q_other_tx_dma_setup;
v5 += txr->q_eagain_tx_dma_setup;
v6 += txr->q_enomem_tx_dma_setup;
v7 += txr->q_tso_err;
}
IXGBE_EVC_STORE(&adapter->efbig_tx_dma_setup, v0);
IXGBE_EVC_STORE(&adapter->mbuf_defrag_failed, v1);
IXGBE_EVC_STORE(&adapter->efbig2_tx_dma_setup, v2);
IXGBE_EVC_STORE(&adapter->einval_tx_dma_setup, v3);
IXGBE_EVC_STORE(&adapter->other_tx_dma_setup, v4);
IXGBE_EVC_STORE(&adapter->eagain_tx_dma_setup, v5);
IXGBE_EVC_STORE(&adapter->enomem_tx_dma_setup, v6);
IXGBE_EVC_STORE(&adapter->tso_err, v7);
/*
* Check the TX queues status
* - mark hung queues so we don't schedule on them
* - watchdog only if all queues show hung
*/
que = adapter->queues;
for (i = 0; i < adapter->num_queues; i++, que++) {
/* Keep track of queues with work for soft irq */
if (que->txr->busy)
queues |= ((u64)1 << que->me);
/*
* Each time txeof runs without cleaning, but there
* are uncleaned descriptors it increments busy. If
* we get to the MAX we declare it hung.
*/
if (que->busy == IXGBE_QUEUE_HUNG) {
++hung;
/* Mark the queue as inactive */
adapter->active_queues &= ~((u64)1 << que->me);
continue;
} else {
/* Check if we've come back from hung */
if ((adapter->active_queues & ((u64)1 << que->me)) == 0)
adapter->active_queues |= ((u64)1 << que->me);
}
if (que->busy >= IXGBE_MAX_TX_BUSY) {
device_printf(dev,
"Warning queue %d appears to be hung!\n", i);
que->txr->busy = IXGBE_QUEUE_HUNG;
++hung;
}
}
/* Only truly watchdog if all queues show hung */
if (hung == adapter->num_queues)
goto watchdog;
#if 0
else if (queues != 0) { /* Force an IRQ on queues with work */
ixv_rearm_queues(adapter, queues);
}
#endif
atomic_store_relaxed(&adapter->timer_pending, 0);
IXGBE_CORE_UNLOCK(adapter);
callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);
return;
watchdog:
device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
adapter->ifp->if_flags &= ~IFF_RUNNING;
IXGBE_EVC_ADD(&adapter->watchdog_events, 1);
ixv_init_locked(adapter);
IXGBE_CORE_UNLOCK(adapter);
} /* ixv_handle_timer */
/************************************************************************
* ixv_update_link_status - Update OS on link state
*
* Note: Only updates the OS on the cached link state.
* The real check of the hardware only happens with
* a link interrupt.
************************************************************************/
static void
ixv_update_link_status(struct adapter *adapter)
{
struct ifnet *ifp = adapter->ifp;
device_t dev = adapter->dev;
KASSERT(mutex_owned(&adapter->core_mtx));
if (adapter->link_up) {
if (adapter->link_active != LINK_STATE_UP) {
if (bootverbose) {
const char *bpsmsg;
switch (adapter->link_speed) {
case IXGBE_LINK_SPEED_10GB_FULL:
bpsmsg = "10 Gbps";
break;
case IXGBE_LINK_SPEED_5GB_FULL:
bpsmsg = "5 Gbps";
break;
case IXGBE_LINK_SPEED_2_5GB_FULL:
bpsmsg = "2.5 Gbps";
break;
case IXGBE_LINK_SPEED_1GB_FULL:
bpsmsg = "1 Gbps";
break;
case IXGBE_LINK_SPEED_100_FULL:
bpsmsg = "100 Mbps";
break;
case IXGBE_LINK_SPEED_10_FULL:
bpsmsg = "10 Mbps";
break;
default:
bpsmsg = "unknown speed";
break;
}
device_printf(dev, "Link is up %s %s \n",
bpsmsg, "Full Duplex");
}
adapter->link_active = LINK_STATE_UP;
if_link_state_change(ifp, LINK_STATE_UP);
}
} else {
/*
* Do it when link active changes to DOWN. i.e.
* a) LINK_STATE_UNKNOWN -> LINK_STATE_DOWN
* b) LINK_STATE_UP -> LINK_STATE_DOWN
*/
if (adapter->link_active != LINK_STATE_DOWN) {
if (bootverbose)
device_printf(dev, "Link is Down\n");
if_link_state_change(ifp, LINK_STATE_DOWN);
adapter->link_active = LINK_STATE_DOWN;
}
}
} /* ixv_update_link_status */
/************************************************************************
* ixv_stop - Stop the hardware
*
* Disables all traffic on the adapter by issuing a
* global reset on the MAC and deallocates TX/RX buffers.
************************************************************************/
static void
ixv_ifstop(struct ifnet *ifp, int disable)
{
struct adapter *adapter = ifp->if_softc;
IXGBE_CORE_LOCK(adapter);
ixv_stop_locked(adapter);
IXGBE_CORE_UNLOCK(adapter);
workqueue_wait(adapter->admin_wq, &adapter->admin_wc);
atomic_store_relaxed(&adapter->admin_pending, 0);
workqueue_wait(adapter->timer_wq, &adapter->timer_wc);
atomic_store_relaxed(&adapter->timer_pending, 0);
}
static void
ixv_stop_locked(void *arg)
{
struct ifnet *ifp;
struct adapter *adapter = arg;
struct ixgbe_hw *hw = &adapter->hw;
ifp = adapter->ifp;
KASSERT(mutex_owned(&adapter->core_mtx));
INIT_DEBUGOUT("ixv_stop_locked: begin\n");
ixv_disable_intr(adapter);
/* Tell the stack that the interface is no longer active */
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
hw->mac.ops.reset_hw(hw);
adapter->hw.adapter_stopped = FALSE;
hw->mac.ops.stop_adapter(hw);
callout_stop(&adapter->timer);
/* Don't schedule workqueues. */
adapter->schedule_wqs_ok = false;
/* reprogram the RAR[0] in case user changed it. */
hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
return;
} /* ixv_stop_locked */
/************************************************************************
* ixv_allocate_pci_resources
************************************************************************/
static int
ixv_allocate_pci_resources(struct adapter *adapter,
const struct pci_attach_args *pa)
{
pcireg_t memtype, csr;
device_t dev = adapter->dev;
bus_addr_t addr;
int flags;
memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, PCI_BAR(0));
switch (memtype) {
case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
adapter->osdep.mem_bus_space_tag = pa->pa_memt;
if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, PCI_BAR(0),
memtype, &addr, &adapter->osdep.mem_size, &flags) != 0)
goto map_err;
if ((flags & BUS_SPACE_MAP_PREFETCHABLE) != 0) {
aprint_normal_dev(dev, "clearing prefetchable bit\n");
flags &= ~BUS_SPACE_MAP_PREFETCHABLE;
}
if (bus_space_map(adapter->osdep.mem_bus_space_tag, addr,
adapter->osdep.mem_size, flags,
&adapter->osdep.mem_bus_space_handle) != 0) {
map_err:
adapter->osdep.mem_size = 0;
aprint_error_dev(dev, "unable to map BAR0\n");
return ENXIO;
}
/*
* Enable address decoding for memory range in case it's not
* set.
*/
csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
PCI_COMMAND_STATUS_REG);
csr |= PCI_COMMAND_MEM_ENABLE;
pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
csr);
break;
default:
aprint_error_dev(dev, "unexpected type on BAR0\n");
return ENXIO;
}
/* Pick up the tuneable queues */
adapter->num_queues = ixv_num_queues;
return (0);
} /* ixv_allocate_pci_resources */
static void
ixv_free_deferred_handlers(struct adapter *adapter)
{
struct ix_queue *que = adapter->queues;
struct tx_ring *txr = adapter->tx_rings;
int i;
for (i = 0; i < adapter->num_queues; i++, que++, txr++) {
if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)) {
if (txr->txr_si != NULL)
softint_disestablish(txr->txr_si);
}
if (que->que_si != NULL)
softint_disestablish(que->que_si);
}
if (adapter->txr_wq != NULL)
workqueue_destroy(adapter->txr_wq);
if (adapter->txr_wq_enqueued != NULL)
percpu_free(adapter->txr_wq_enqueued, sizeof(u_int));
if (adapter->que_wq != NULL)
workqueue_destroy(adapter->que_wq);
/* Drain the Mailbox(link) queue */
if (adapter->admin_wq != NULL) {
workqueue_destroy(adapter->admin_wq);
adapter->admin_wq = NULL;
}
if (adapter->timer_wq != NULL) {
workqueue_destroy(adapter->timer_wq);
adapter->timer_wq = NULL;
}
} /* ixv_free_deferred_handlers */
/************************************************************************
* ixv_free_pci_resources
************************************************************************/
static void
ixv_free_pci_resources(struct adapter * adapter)
{
struct ix_queue *que = adapter->queues;
int rid;
/*
* Release all msix queue resources:
*/
for (int i = 0; i < adapter->num_queues; i++, que++) {
if (que->res != NULL)
pci_intr_disestablish(adapter->osdep.pc,
adapter->osdep.ihs[i]);
}
/* Clean the Mailbox interrupt last */
rid = adapter->vector;
if (adapter->osdep.ihs[rid] != NULL) {
pci_intr_disestablish(adapter->osdep.pc,
adapter->osdep.ihs[rid]);
adapter->osdep.ihs[rid] = NULL;
}
pci_intr_release(adapter->osdep.pc, adapter->osdep.intrs,
adapter->osdep.nintrs);
if (adapter->osdep.mem_size != 0) {
bus_space_unmap(adapter->osdep.mem_bus_space_tag,
adapter->osdep.mem_bus_space_handle,
adapter->osdep.mem_size);
}
return;
} /* ixv_free_pci_resources */
/************************************************************************
* ixv_setup_interface
*
* Setup networking device structure and register an interface.
************************************************************************/
static int
ixv_setup_interface(device_t dev, struct adapter *adapter)
{
struct ethercom *ec = &adapter->osdep.ec;
struct ifnet *ifp;
INIT_DEBUGOUT("ixv_setup_interface: begin");
ifp = adapter->ifp = &ec->ec_if;
strlcpy(ifp->if_xname, device_xname(dev), IFNAMSIZ);
ifp->if_baudrate = IF_Gbps(10);
ifp->if_init = ixv_init;
ifp->if_stop = ixv_ifstop;
ifp->if_softc = adapter;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
#ifdef IXGBE_MPSAFE
ifp->if_extflags = IFEF_MPSAFE;
#endif
ifp->if_ioctl = ixv_ioctl;
if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) {
#if 0
ixv_start_locked = ixgbe_legacy_start_locked;
#endif
} else {
ifp->if_transmit = ixgbe_mq_start;
#if 0
ixv_start_locked = ixgbe_mq_start_locked;
#endif
}
ifp->if_start = ixgbe_legacy_start;
IFQ_SET_MAXLEN(&ifp->if_snd, adapter->num_tx_desc - 2);
IFQ_SET_READY(&ifp->if_snd);
if_initialize(ifp);
adapter->ipq = if_percpuq_create(&adapter->osdep.ec.ec_if);
ether_ifattach(ifp, adapter->hw.mac.addr);
aprint_normal_dev(dev, "Ethernet address %s\n",
ether_sprintf(adapter->hw.mac.addr));
/*
* We use per TX queue softint, so if_deferred_start_init() isn't
* used.
*/
ether_set_ifflags_cb(ec, ixv_ifflags_cb);
adapter->max_frame_size = ifp->if_mtu + IXGBE_MTU_HDR;
/*
* Tell the upper layer(s) we support long frames.
*/
ifp->if_hdrlen = sizeof(struct ether_vlan_header);
/* Set capability flags */
ifp->if_capabilities |= IFCAP_HWCSUM
| IFCAP_TSOv4
| IFCAP_TSOv6;
ifp->if_capenable = 0;
ec->ec_capabilities |= ETHERCAP_VLAN_HWFILTER
| ETHERCAP_VLAN_HWTAGGING
| ETHERCAP_VLAN_HWCSUM
| ETHERCAP_JUMBO_MTU
| ETHERCAP_VLAN_MTU;
/* Enable the above capabilities by default */
ec->ec_capenable = ec->ec_capabilities;
/* Don't enable LRO by default */
#if 0
/* NetBSD doesn't support LRO yet */
ifp->if_capabilities |= IFCAP_LRO;
#endif
/*
* Specify the media types supported by this adapter and register
* callbacks to update media and link information
*/
ec->ec_ifmedia = &adapter->media;
ifmedia_init_with_lock(&adapter->media, IFM_IMASK, ixv_media_change,
ixv_media_status, &adapter->core_mtx);
ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
if_register(ifp);
return 0;
} /* ixv_setup_interface */
/************************************************************************
* ixv_initialize_transmit_units - Enable transmit unit.
************************************************************************/
static void
ixv_initialize_transmit_units(struct adapter *adapter)
{
struct tx_ring *txr = adapter->tx_rings;
struct ixgbe_hw *hw = &adapter->hw;
int i;
for (i = 0; i < adapter->num_queues; i++, txr++) {
u64 tdba = txr->txdma.dma_paddr;
u32 txctrl, txdctl;
int j = txr->me;
/* Set WTHRESH to 8, burst writeback */
txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
txdctl |= IXGBE_TX_WTHRESH << IXGBE_TXDCTL_WTHRESH_SHIFT;
IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
/* Set the HW Tx Head and Tail indices */
IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDH(j), 0);
IXGBE_WRITE_REG(&adapter->hw, IXGBE_VFTDT(j), 0);
/* Set Tx Tail register */
txr->tail = IXGBE_VFTDT(j);
txr->txr_no_space = false;
/* Set Ring parameters */
IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(j),
(tdba & 0x00000000ffffffffULL));
IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(j), (tdba >> 32));
IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j),
adapter->num_tx_desc * sizeof(struct ixgbe_legacy_tx_desc));
txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(j));
txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(j), txctrl);
/* Now enable */
txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
txdctl |= IXGBE_TXDCTL_ENABLE;
IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
}
return;
} /* ixv_initialize_transmit_units */
/************************************************************************
* ixv_initialize_rss_mapping
************************************************************************/
static void
ixv_initialize_rss_mapping(struct adapter *adapter)
{
struct ixgbe_hw *hw = &adapter->hw;
u32 reta = 0, mrqc, rss_key[10];
int queue_id;
int i, j;
u32 rss_hash_config;
/* force use default RSS key. */
#ifdef __NetBSD__
rss_getkey((uint8_t *) &rss_key);
#else
if (adapter->feat_en & IXGBE_FEATURE_RSS) {
/* Fetch the configured RSS key */
rss_getkey((uint8_t *)&rss_key);
} else {
/* set up random bits */
cprng_fast(&rss_key, sizeof(rss_key));
}
#endif
/* Now fill out hash function seeds */
for (i = 0; i < 10; i++)
IXGBE_WRITE_REG(hw, IXGBE_VFRSSRK(i), rss_key[i]);
/* Set up the redirection table */
for (i = 0, j = 0; i < 64; i++, j++) {
if (j == adapter->num_queues)
j = 0;
if (adapter->feat_en & IXGBE_FEATURE_RSS) {
/*
* Fetch the RSS bucket id for the given indirection
* entry. Cap it at the number of configured buckets
* (which is num_queues.)
*/
queue_id = rss_get_indirection_to_bucket(i);
queue_id = queue_id % adapter->num_queues;
} else
queue_id = j;
/*
* The low 8 bits are for hash value (n+0);
* The next 8 bits are for hash value (n+1), etc.
*/
reta >>= 8;
reta |= ((uint32_t)queue_id) << 24;
if ((i & 3) == 3) {
IXGBE_WRITE_REG(hw, IXGBE_VFRETA(i >> 2), reta);
reta = 0;
}
}
/* Perform hash on these packet types */
if (adapter->feat_en & IXGBE_FEATURE_RSS)
rss_hash_config = rss_gethashconfig();
else {
/*
* Disable UDP - IP fragments aren't currently being handled
* and so we end up with a mix of 2-tuple and 4-tuple
* traffic.
*/
rss_hash_config = RSS_HASHTYPE_RSS_IPV4
| RSS_HASHTYPE_RSS_TCP_IPV4
| RSS_HASHTYPE_RSS_IPV6
| RSS_HASHTYPE_RSS_TCP_IPV6;
}
mrqc = IXGBE_MRQC_RSSEN;
if (rss_hash_config & RSS_HASHTYPE_RSS_IPV4)
mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4;
if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV4)
mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_TCP;
if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6)
mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6;
if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6)
mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6_EX)
device_printf(adapter->dev, "%s: RSS_HASHTYPE_RSS_IPV6_EX "
"defined, but not supported\n", __func__);
if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6_EX)
device_printf(adapter->dev, "%s: RSS_HASHTYPE_RSS_TCP_IPV6_EX "
"defined, but not supported\n", __func__);
if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV4)
mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV6)
mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV6_EX)
device_printf(adapter->dev, "%s: RSS_HASHTYPE_RSS_UDP_IPV6_EX "
"defined, but not supported\n", __func__);
IXGBE_WRITE_REG(hw, IXGBE_VFMRQC, mrqc);
} /* ixv_initialize_rss_mapping */
/************************************************************************
* ixv_initialize_receive_units - Setup receive registers and features.
************************************************************************/
static void
ixv_initialize_receive_units(struct adapter *adapter)
{
struct rx_ring *rxr = adapter->rx_rings;
struct ixgbe_hw *hw = &adapter->hw;
struct ifnet *ifp = adapter->ifp;
u32 bufsz, psrtype;
if (ifp->if_mtu > ETHERMTU)
bufsz = 4096 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
else
bufsz = 2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
psrtype = IXGBE_PSRTYPE_TCPHDR
| IXGBE_PSRTYPE_UDPHDR
| IXGBE_PSRTYPE_IPV4HDR
| IXGBE_PSRTYPE_IPV6HDR
| IXGBE_PSRTYPE_L2HDR;
if (adapter->num_queues > 1)
psrtype |= 1 << 29;
IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
/* Tell PF our max_frame size */
if (ixgbevf_rlpml_set_vf(hw, adapter->max_frame_size) != 0) {
device_printf(adapter->dev, "There is a problem with the PF "
"setup. It is likely the receive unit for this VF will "
"not function correctly.\n");
}
for (int i = 0; i < adapter->num_queues; i++, rxr++) {
u64 rdba = rxr->rxdma.dma_paddr;
u32 reg, rxdctl;
int j = rxr->me;
/* Disable the queue */
rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j));
rxdctl &= ~IXGBE_RXDCTL_ENABLE;
IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(j), rxdctl);
for (int k = 0; k < 10; k++) {
if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j)) &
IXGBE_RXDCTL_ENABLE)
msec_delay(1);
else
break;
}
IXGBE_WRITE_BARRIER(hw);
/* Setup the Base and Length of the Rx Descriptor Ring */
IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j),
(rdba & 0x00000000ffffffffULL));
IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32));
IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j),
adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
/* Reset the ring indices */
IXGBE_WRITE_REG(hw, IXGBE_VFRDH(rxr->me), 0);
IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me), 0);
/* Set up the SRRCTL register */
reg = IXGBE_READ_REG(hw, IXGBE_VFSRRCTL(j));
reg &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
reg &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
reg |= bufsz;
reg |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(j), reg);
/* Capture Rx Tail index */
rxr->tail = IXGBE_VFRDT(rxr->me);
/* Do the queue enabling last */
rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME;
IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(j), rxdctl);
for (int k = 0; k < 10; k++) {
if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j)) &
IXGBE_RXDCTL_ENABLE)
break;
msec_delay(1);
}
IXGBE_WRITE_BARRIER(hw);
/* Set the Tail Pointer */
#ifdef DEV_NETMAP
/*
* In netmap mode, we must preserve the buffers made
* available to userspace before the if_init()
* (this is true by default on the TX side, because
* init makes all buffers available to userspace).
*
* netmap_reset() and the device specific routines
* (e.g. ixgbe_setup_receive_rings()) map these
* buffers at the end of the NIC ring, so here we
* must set the RDT (tail) register to make sure
* they are not overwritten.
*
* In this driver the NIC ring starts at RDH = 0,
* RDT points to the last slot available for reception (?),
* so RDT = num_rx_desc - 1 means the whole ring is available.
*/
if ((adapter->feat_en & IXGBE_FEATURE_NETMAP) &&
(ifp->if_capenable & IFCAP_NETMAP)) {
struct netmap_adapter *na = NA(adapter->ifp);
struct netmap_kring *kring = na->rx_rings[i];
int t = na->num_rx_desc - 1 - nm_kr_rxspace(kring);
IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me), t);
} else
#endif /* DEV_NETMAP */
IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me),
adapter->num_rx_desc - 1);
}
if (adapter->hw.mac.type >= ixgbe_mac_X550_vf)
ixv_initialize_rss_mapping(adapter);
} /* ixv_initialize_receive_units */
/************************************************************************
* ixv_sysctl_tdh_handler - Transmit Descriptor Head handler function
*
* Retrieves the TDH value from the hardware
************************************************************************/
static int
ixv_sysctl_tdh_handler(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct tx_ring *txr = (struct tx_ring *)node.sysctl_data;
uint32_t val;
if (!txr)
return (0);
val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_VFTDH(txr->me));
node.sysctl_data = &val;
return sysctl_lookup(SYSCTLFN_CALL(&node));
} /* ixv_sysctl_tdh_handler */
/************************************************************************
* ixgbe_sysctl_tdt_handler - Transmit Descriptor Tail handler function
*
* Retrieves the TDT value from the hardware
************************************************************************/
static int
ixv_sysctl_tdt_handler(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct tx_ring *txr = (struct tx_ring *)node.sysctl_data;
uint32_t val;
if (!txr)
return (0);
val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_VFTDT(txr->me));
node.sysctl_data = &val;
return sysctl_lookup(SYSCTLFN_CALL(&node));
} /* ixv_sysctl_tdt_handler */
/************************************************************************
* ixv_sysctl_next_to_check_handler - Receive Descriptor next to check
* handler function
*
* Retrieves the next_to_check value
************************************************************************/
static int
ixv_sysctl_next_to_check_handler(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct rx_ring *rxr = (struct rx_ring *)node.sysctl_data;
uint32_t val;
if (!rxr)
return (0);
val = rxr->next_to_check;
node.sysctl_data = &val;
return sysctl_lookup(SYSCTLFN_CALL(&node));
} /* ixv_sysctl_next_to_check_handler */
/************************************************************************
* ixv_sysctl_next_to_refresh_handler - Receive Descriptor next to refresh
* handler function
*
* Retrieves the next_to_refresh value
************************************************************************/
static int
ixv_sysctl_next_to_refresh_handler(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct rx_ring *rxr = (struct rx_ring *)node.sysctl_data;
struct adapter *adapter;
uint32_t val;
if (!rxr)
return (0);
adapter = rxr->adapter;
if (ixgbe_fw_recovery_mode_swflag(adapter))
return (EPERM);
val = rxr->next_to_refresh;
node.sysctl_data = &val;
return sysctl_lookup(SYSCTLFN_CALL(&node));
} /* ixv_sysctl_next_to_refresh_handler */
/************************************************************************
* ixv_sysctl_rdh_handler - Receive Descriptor Head handler function
*
* Retrieves the RDH value from the hardware
************************************************************************/
static int
ixv_sysctl_rdh_handler(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct rx_ring *rxr = (struct rx_ring *)node.sysctl_data;
uint32_t val;
if (!rxr)
return (0);
val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_VFRDH(rxr->me));
node.sysctl_data = &val;
return sysctl_lookup(SYSCTLFN_CALL(&node));
} /* ixv_sysctl_rdh_handler */
/************************************************************************
* ixv_sysctl_rdt_handler - Receive Descriptor Tail handler function
*
* Retrieves the RDT value from the hardware
************************************************************************/
static int
ixv_sysctl_rdt_handler(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct rx_ring *rxr = (struct rx_ring *)node.sysctl_data;
uint32_t val;
if (!rxr)
return (0);
val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_VFRDT(rxr->me));
node.sysctl_data = &val;
return sysctl_lookup(SYSCTLFN_CALL(&node));
} /* ixv_sysctl_rdt_handler */
static void
ixv_setup_vlan_tagging(struct adapter *adapter)
{
struct ethercom *ec = &adapter->osdep.ec;
struct ixgbe_hw *hw = &adapter->hw;
struct rx_ring *rxr;
u32 ctrl;
int i;
bool hwtagging;
/* Enable HW tagging only if any vlan is attached */
hwtagging = (ec->ec_capenable & ETHERCAP_VLAN_HWTAGGING)
&& VLAN_ATTACHED(ec);
/* Enable the queues */
for (i = 0; i < adapter->num_queues; i++) {
rxr = &adapter->rx_rings[i];
ctrl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(rxr->me));
if (hwtagging)
ctrl |= IXGBE_RXDCTL_VME;
else
ctrl &= ~IXGBE_RXDCTL_VME;
IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(rxr->me), ctrl);
/*
* Let Rx path know that it needs to store VLAN tag
* as part of extra mbuf info.
*/
rxr->vtag_strip = hwtagging ? TRUE : FALSE;
}
} /* ixv_setup_vlan_tagging */
/************************************************************************
* ixv_setup_vlan_support
************************************************************************/
static int
ixv_setup_vlan_support(struct adapter *adapter)
{
struct ethercom *ec = &adapter->osdep.ec;
struct ixgbe_hw *hw = &adapter->hw;
u32 vid, vfta, retry;
struct vlanid_list *vlanidp;
int rv, error = 0;
/*
* This function is called from both if_init and ifflags_cb()
* on NetBSD.
*/
/*
* Part 1:
* Setup VLAN HW tagging
*/
ixv_setup_vlan_tagging(adapter);
if (!VLAN_ATTACHED(ec))
return 0;
/*
* Part 2:
* Setup VLAN HW filter
*/
/* Cleanup shadow_vfta */
for (int i = 0; i < IXGBE_VFTA_SIZE; i++)
adapter->shadow_vfta[i] = 0;
/* Generate shadow_vfta from ec_vids */
ETHER_LOCK(ec);
SIMPLEQ_FOREACH(vlanidp, &ec->ec_vids, vid_list) {
uint32_t idx;
idx = vlanidp->vid / 32;
KASSERT(idx < IXGBE_VFTA_SIZE);
adapter->shadow_vfta[idx] |= (u32)1 << (vlanidp->vid % 32);
}
ETHER_UNLOCK(ec);
/*
* A soft reset zero's out the VFTA, so
* we need to repopulate it now.
*/
for (int i = 0; i < IXGBE_VFTA_SIZE; i++) {
if (adapter->shadow_vfta[i] == 0)
continue;
vfta = adapter->shadow_vfta[i];
/*
* Reconstruct the vlan id's
* based on the bits set in each
* of the array ints.
*/
for (int j = 0; j < 32; j++) {
retry = 0;
if ((vfta & ((u32)1 << j)) == 0)
continue;
vid = (i * 32) + j;
/* Call the shared code mailbox routine */
while ((rv = hw->mac.ops.set_vfta(hw, vid, 0, TRUE,
FALSE)) != 0) {
if (++retry > 5) {
device_printf(adapter->dev,
"%s: max retry exceeded\n",
__func__);
break;
}
}
if (rv != 0) {
device_printf(adapter->dev,
"failed to set vlan %d\n", vid);
error = EACCES;
}
}
}
return error;
} /* ixv_setup_vlan_support */
static int
ixv_vlan_cb(struct ethercom *ec, uint16_t vid, bool set)
{
struct ifnet *ifp = &ec->ec_if;
struct adapter *adapter = ifp->if_softc;
int rv;
if (set)
rv = ixv_register_vlan(adapter, vid);
else
rv = ixv_unregister_vlan(adapter, vid);
if (rv != 0)
return rv;
/*
* Control VLAN HW tagging when ec_nvlan is changed from 1 to 0
* or 0 to 1.
*/
if ((set && (ec->ec_nvlans == 1)) || (!set && (ec->ec_nvlans == 0)))
ixv_setup_vlan_tagging(adapter);
return rv;
}
/************************************************************************
* ixv_register_vlan
*
* Run via a vlan config EVENT, it enables us to use the
* HW Filter table since we can get the vlan id. This just
* creates the entry in the soft version of the VFTA, init
* will repopulate the real table.
************************************************************************/
static int
ixv_register_vlan(struct adapter *adapter, u16 vtag)
{
struct ixgbe_hw *hw = &adapter->hw;
u16 index, bit;
int error;
if ((vtag == 0) || (vtag > 4095)) /* Invalid */
return EINVAL;
IXGBE_CORE_LOCK(adapter);
index = (vtag >> 5) & 0x7F;
bit = vtag & 0x1F;
adapter->shadow_vfta[index] |= ((u32)1 << bit);
error = hw->mac.ops.set_vfta(hw, vtag, 0, true, false);
IXGBE_CORE_UNLOCK(adapter);
if (error != 0) {
device_printf(adapter->dev, "failed to register vlan %hu\n",
vtag);
error = EACCES;
}
return error;
} /* ixv_register_vlan */
/************************************************************************
* ixv_unregister_vlan
*
* Run via a vlan unconfig EVENT, remove our entry
* in the soft vfta.
************************************************************************/
static int
ixv_unregister_vlan(struct adapter *adapter, u16 vtag)
{
struct ixgbe_hw *hw = &adapter->hw;
u16 index, bit;
int error;
if ((vtag == 0) || (vtag > 4095)) /* Invalid */
return EINVAL;
IXGBE_CORE_LOCK(adapter);
index = (vtag >> 5) & 0x7F;
bit = vtag & 0x1F;
adapter->shadow_vfta[index] &= ~((u32)1 << bit);
error = hw->mac.ops.set_vfta(hw, vtag, 0, false, false);
IXGBE_CORE_UNLOCK(adapter);
if (error != 0) {
device_printf(adapter->dev, "failed to unregister vlan %hu\n",
vtag);
error = EIO;
}
return error;
} /* ixv_unregister_vlan */
/************************************************************************
* ixv_enable_intr
************************************************************************/
static void
ixv_enable_intr(struct adapter *adapter)
{
struct ixgbe_hw *hw = &adapter->hw;
struct ix_queue *que = adapter->queues;
u32 mask;
int i;
/* For VTEIAC */
mask = (1 << adapter->vector);
for (i = 0; i < adapter->num_queues; i++, que++)
mask |= (1 << que->msix);
IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, mask);
/* For VTEIMS */
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, (1 << adapter->vector));
que = adapter->queues;
for (i = 0; i < adapter->num_queues; i++, que++)
ixv_enable_queue(adapter, que->msix);
IXGBE_WRITE_FLUSH(hw);
} /* ixv_enable_intr */
/************************************************************************
* ixv_disable_intr
************************************************************************/
static void
ixv_disable_intr(struct adapter *adapter)
{
struct ix_queue *que = adapter->queues;
IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIAC, 0);
/* disable interrupts other than queues */
IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIMC, adapter->vector);
for (int i = 0; i < adapter->num_queues; i++, que++)
ixv_disable_queue(adapter, que->msix);
IXGBE_WRITE_FLUSH(&adapter->hw);
} /* ixv_disable_intr */
/************************************************************************
* ixv_set_ivar
*
* Setup the correct IVAR register for a particular MSI-X interrupt
* - entry is the register array entry
* - vector is the MSI-X vector for this queue
* - type is RX/TX/MISC
************************************************************************/
static void
ixv_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
{
struct ixgbe_hw *hw = &adapter->hw;
u32 ivar, index;
vector |= IXGBE_IVAR_ALLOC_VAL;
if (type == -1) { /* MISC IVAR */
ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
ivar &= ~0xFF;
ivar |= vector;
IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
} else { /* RX/TX IVARS */
index = (16 * (entry & 1)) + (8 * type);
ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(entry >> 1));
ivar &= ~(0xffUL << index);
ivar |= ((u32)vector << index);
IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(entry >> 1), ivar);
}
} /* ixv_set_ivar */
/************************************************************************
* ixv_configure_ivars
************************************************************************/
static void
ixv_configure_ivars(struct adapter *adapter)
{
struct ix_queue *que = adapter->queues;
/* XXX We should sync EITR value calculation with ixgbe.c? */
for (int i = 0; i < adapter->num_queues; i++, que++) {
/* First the RX queue entry */
ixv_set_ivar(adapter, i, que->msix, 0);
/* ... and the TX */
ixv_set_ivar(adapter, i, que->msix, 1);
/* Set an initial value in EITR */
ixv_eitr_write(adapter, que->msix, IXGBE_EITR_DEFAULT);
}
/* For the mailbox interrupt */
ixv_set_ivar(adapter, 1, adapter->vector, -1);
} /* ixv_configure_ivars */
/************************************************************************
* ixv_init_stats
*
* The VF stats registers never have a truly virgin
* starting point, so this routine save initial vaules to
* last_<REGNAME>.
************************************************************************/
static void
ixv_init_stats(struct adapter *adapter)
{
struct ixgbe_hw *hw = &adapter->hw;
adapter->stats.vf.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
adapter->stats.vf.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
adapter->stats.vf.last_vfgorc |=
(((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
adapter->stats.vf.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
adapter->stats.vf.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
adapter->stats.vf.last_vfgotc |=
(((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
adapter->stats.vf.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
} /* ixv_init_stats */
#define UPDATE_STAT_32(reg, last, count) \
{ \
u32 current = IXGBE_READ_REG(hw, (reg)); \
IXGBE_EVC_ADD(&count, current - (last)); \
(last) = current; \
}
#define UPDATE_STAT_36(lsb, msb, last, count) \
{ \
u64 cur_lsb = IXGBE_READ_REG(hw, (lsb)); \
u64 cur_msb = IXGBE_READ_REG(hw, (msb)); \
u64 current = ((cur_msb << 32) | cur_lsb); \
if (current < (last)) \
IXGBE_EVC_ADD(&count, current + __BIT(36) - (last)); \
else \
IXGBE_EVC_ADD(&count, current - (last)); \
(last) = current; \
}
/************************************************************************
* ixv_update_stats - Update the board statistics counters.
************************************************************************/
void
ixv_update_stats(struct adapter *adapter)
{
struct ixgbe_hw *hw = &adapter->hw;
struct ixgbevf_hw_stats *stats = &adapter->stats.vf;
UPDATE_STAT_32(IXGBE_VFGPRC, stats->last_vfgprc, stats->vfgprc);
UPDATE_STAT_32(IXGBE_VFGPTC, stats->last_vfgptc, stats->vfgptc);
UPDATE_STAT_36(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB, stats->last_vfgorc,
stats->vfgorc);
UPDATE_STAT_36(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB, stats->last_vfgotc,
stats->vfgotc);
UPDATE_STAT_32(IXGBE_VFMPRC, stats->last_vfmprc, stats->vfmprc);
/* VF doesn't count errors by hardware */
} /* ixv_update_stats */
/************************************************************************
* ixv_sysctl_interrupt_rate_handler
************************************************************************/
static int
ixv_sysctl_interrupt_rate_handler(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct ix_queue *que = (struct ix_queue *)node.sysctl_data;
struct adapter *adapter = que->adapter;
uint32_t reg, usec, rate;
int error;
if (que == NULL)
return 0;
reg = IXGBE_READ_REG(&que->adapter->hw, IXGBE_VTEITR(que->msix));
usec = ((reg & 0x0FF8) >> 3);
if (usec > 0)
rate = 500000 / usec;
else
rate = 0;
node.sysctl_data = &rate;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return error;
reg &= ~0xfff; /* default, no limitation */
if (rate > 0 && rate < 500000) {
if (rate < 1000)
rate = 1000;
reg |= ((4000000 / rate) & 0xff8);
/*
* When RSC is used, ITR interval must be larger than
* RSC_DELAY. Currently, we use 2us for RSC_DELAY.
* The minimum value is always greater than 2us on 100M
* (and 10M?(not documented)), but it's not on 1G and higher.
*/
if ((adapter->link_speed != IXGBE_LINK_SPEED_100_FULL)
&& (adapter->link_speed != IXGBE_LINK_SPEED_10_FULL)) {
if ((adapter->num_queues > 1)
&& (reg < IXGBE_MIN_RSC_EITR_10G1G))
return EINVAL;
}
ixv_max_interrupt_rate = rate;
} else
ixv_max_interrupt_rate = 0;
ixv_eitr_write(adapter, que->msix, reg);
return (0);
} /* ixv_sysctl_interrupt_rate_handler */
const struct sysctlnode *
ixv_sysctl_instance(struct adapter *adapter)
{
const char *dvname;
struct sysctllog **log;
int rc;
const struct sysctlnode *rnode;
log = &adapter->sysctllog;
dvname = device_xname(adapter->dev);
if ((rc = sysctl_createv(log, 0, NULL, &rnode,
0, CTLTYPE_NODE, dvname,
SYSCTL_DESCR("ixv information and settings"),
NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0)
goto err;
return rnode;
err:
device_printf(adapter->dev,
"%s: sysctl_createv failed, rc = %d\n", __func__, rc);
return NULL;
}
static void
ixv_add_device_sysctls(struct adapter *adapter)
{
struct sysctllog **log;
const struct sysctlnode *rnode, *cnode;
device_t dev;
dev = adapter->dev;
log = &adapter->sysctllog;
if ((rnode = ixv_sysctl_instance(adapter)) == NULL) {
aprint_error_dev(dev, "could not create sysctl root\n");
return;
}
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READWRITE, CTLTYPE_INT, "debug",
SYSCTL_DESCR("Debug Info"),
ixv_sysctl_debug, 0, (void *)adapter, 0, CTL_CREATE, CTL_EOL) != 0)
aprint_error_dev(dev, "could not create sysctl\n");
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READWRITE, CTLTYPE_INT,
"rx_copy_len", SYSCTL_DESCR("RX Copy Length"),
ixv_sysctl_rx_copy_len, 0,
(void *)adapter, 0, CTL_CREATE, CTL_EOL) != 0)
aprint_error_dev(dev, "could not create sysctl\n");
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT,
"num_tx_desc", SYSCTL_DESCR("Number of TX descriptors"),
NULL, 0, &adapter->num_tx_desc, 0, CTL_CREATE, CTL_EOL) != 0)
aprint_error_dev(dev, "could not create sysctl\n");
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT,
"num_rx_desc", SYSCTL_DESCR("Number of RX descriptors"),
NULL, 0, &adapter->num_rx_desc, 0, CTL_CREATE, CTL_EOL) != 0)
aprint_error_dev(dev, "could not create sysctl\n");
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READWRITE, CTLTYPE_INT, "rx_process_limit",
SYSCTL_DESCR("max number of RX packets to process"),
ixv_sysctl_rx_process_limit, 0, (void *)adapter, 0, CTL_CREATE,
CTL_EOL) != 0)
aprint_error_dev(dev, "could not create sysctl\n");
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READWRITE, CTLTYPE_INT, "tx_process_limit",
SYSCTL_DESCR("max number of TX packets to process"),
ixv_sysctl_tx_process_limit, 0, (void *)adapter, 0, CTL_CREATE,
CTL_EOL) != 0)
aprint_error_dev(dev, "could not create sysctl\n");
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READWRITE, CTLTYPE_BOOL, "enable_aim",
SYSCTL_DESCR("Interrupt Moderation"),
NULL, 0, &adapter->enable_aim, 0, CTL_CREATE, CTL_EOL) != 0)
aprint_error_dev(dev, "could not create sysctl\n");
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READWRITE, CTLTYPE_BOOL, "txrx_workqueue",
SYSCTL_DESCR("Use workqueue for packet processing"),
NULL, 0, &adapter->txrx_use_workqueue, 0, CTL_CREATE, CTL_EOL)
!= 0)
aprint_error_dev(dev, "could not create sysctl\n");
}
/************************************************************************
* ixv_add_stats_sysctls - Add statistic sysctls for the VF.
************************************************************************/
static void
ixv_add_stats_sysctls(struct adapter *adapter)
{
device_t dev = adapter->dev;
struct tx_ring *txr = adapter->tx_rings;
struct rx_ring *rxr = adapter->rx_rings;
struct ixgbevf_hw_stats *stats = &adapter->stats.vf;
struct ixgbe_hw *hw = &adapter->hw;
const struct sysctlnode *rnode, *cnode;
struct sysctllog **log = &adapter->sysctllog;
const char *xname = device_xname(dev);
/* Driver Statistics */
evcnt_attach_dynamic(&adapter->efbig_tx_dma_setup, EVCNT_TYPE_MISC,
NULL, xname, "Driver tx dma soft fail EFBIG");
evcnt_attach_dynamic(&adapter->mbuf_defrag_failed, EVCNT_TYPE_MISC,
NULL, xname, "m_defrag() failed");
evcnt_attach_dynamic(&adapter->efbig2_tx_dma_setup, EVCNT_TYPE_MISC,
NULL, xname, "Driver tx dma hard fail EFBIG");
evcnt_attach_dynamic(&adapter->einval_tx_dma_setup, EVCNT_TYPE_MISC,
NULL, xname, "Driver tx dma hard fail EINVAL");
evcnt_attach_dynamic(&adapter->other_tx_dma_setup, EVCNT_TYPE_MISC,
NULL, xname, "Driver tx dma hard fail other");
evcnt_attach_dynamic(&adapter->eagain_tx_dma_setup, EVCNT_TYPE_MISC,
NULL, xname, "Driver tx dma soft fail EAGAIN");
evcnt_attach_dynamic(&adapter->enomem_tx_dma_setup, EVCNT_TYPE_MISC,
NULL, xname, "Driver tx dma soft fail ENOMEM");
evcnt_attach_dynamic(&adapter->watchdog_events, EVCNT_TYPE_MISC,
NULL, xname, "Watchdog timeouts");
evcnt_attach_dynamic(&adapter->tso_err, EVCNT_TYPE_MISC,
NULL, xname, "TSO errors");
evcnt_attach_dynamic(&adapter->admin_irqev, EVCNT_TYPE_INTR,
NULL, xname, "Admin MSI-X IRQ Handled");
evcnt_attach_dynamic(&adapter->link_workev, EVCNT_TYPE_INTR,
NULL, xname, "Admin event");
for (int i = 0; i < adapter->num_queues; i++, rxr++, txr++) {
snprintf(adapter->queues[i].evnamebuf,
sizeof(adapter->queues[i].evnamebuf), "%s q%d", xname, i);
snprintf(adapter->queues[i].namebuf,
sizeof(adapter->queues[i].namebuf), "q%d", i);
if ((rnode = ixv_sysctl_instance(adapter)) == NULL) {
aprint_error_dev(dev,
"could not create sysctl root\n");
break;
}
if (sysctl_createv(log, 0, &rnode, &rnode,
0, CTLTYPE_NODE,
adapter->queues[i].namebuf, SYSCTL_DESCR("Queue Name"),
NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL) != 0)
break;
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READWRITE, CTLTYPE_INT,
"interrupt_rate", SYSCTL_DESCR("Interrupt Rate"),
ixv_sysctl_interrupt_rate_handler, 0,
(void *)&adapter->queues[i], 0, CTL_CREATE, CTL_EOL) != 0)
break;
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT,
"txd_head", SYSCTL_DESCR("Transmit Descriptor Head"),
ixv_sysctl_tdh_handler, 0, (void *)txr,
0, CTL_CREATE, CTL_EOL) != 0)
break;
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT,
"txd_tail", SYSCTL_DESCR("Transmit Descriptor Tail"),
ixv_sysctl_tdt_handler, 0, (void *)txr,
0, CTL_CREATE, CTL_EOL) != 0)
break;
evcnt_attach_dynamic(&adapter->queues[i].irqs, EVCNT_TYPE_INTR,
NULL, adapter->queues[i].evnamebuf, "IRQs on queue");
evcnt_attach_dynamic(&adapter->queues[i].handleq,
EVCNT_TYPE_MISC, NULL, adapter->queues[i].evnamebuf,
"Handled queue in softint");
evcnt_attach_dynamic(&adapter->queues[i].req, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf, "Requeued in softint");
evcnt_attach_dynamic(&txr->tso_tx, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf, "TSO");
evcnt_attach_dynamic(&txr->no_desc_avail, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf,
"TX Queue No Descriptor Available");
evcnt_attach_dynamic(&txr->total_packets, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf,
"Queue Packets Transmitted");
#ifndef IXGBE_LEGACY_TX
evcnt_attach_dynamic(&txr->pcq_drops, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf,
"Packets dropped in pcq");
#endif
#ifdef LRO
struct lro_ctrl *lro = &rxr->lro;
#endif /* LRO */
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT, "rxd_nxck",
SYSCTL_DESCR("Receive Descriptor next to check"),
ixv_sysctl_next_to_check_handler, 0, (void *)rxr, 0,
CTL_CREATE, CTL_EOL) != 0)
break;
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT, "rxd_nxrf",
SYSCTL_DESCR("Receive Descriptor next to refresh"),
ixv_sysctl_next_to_refresh_handler, 0, (void *)rxr, 0,
CTL_CREATE, CTL_EOL) != 0)
break;
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT, "rxd_head",
SYSCTL_DESCR("Receive Descriptor Head"),
ixv_sysctl_rdh_handler, 0, (void *)rxr, 0,
CTL_CREATE, CTL_EOL) != 0)
break;
if (sysctl_createv(log, 0, &rnode, &cnode,
CTLFLAG_READONLY, CTLTYPE_INT, "rxd_tail",
SYSCTL_DESCR("Receive Descriptor Tail"),
ixv_sysctl_rdt_handler, 0, (void *)rxr, 0,
CTL_CREATE, CTL_EOL) != 0)
break;
evcnt_attach_dynamic(&rxr->rx_packets, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf,
"Queue Packets Received");
evcnt_attach_dynamic(&rxr->rx_bytes, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf,
"Queue Bytes Received");
evcnt_attach_dynamic(&rxr->rx_copies, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf, "Copied RX Frames");
evcnt_attach_dynamic(&rxr->no_mbuf, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf, "Rx no mbuf");
evcnt_attach_dynamic(&rxr->rx_discarded, EVCNT_TYPE_MISC,
NULL, adapter->queues[i].evnamebuf, "Rx discarded");
#ifdef LRO
SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_queued",
CTLFLAG_RD, &lro->lro_queued, 0,
"LRO Queued");
SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_flushed",
CTLFLAG_RD, &lro->lro_flushed, 0,
"LRO Flushed");
#endif /* LRO */
}
/* MAC stats get their own sub node */
snprintf(stats->namebuf,
sizeof(stats->namebuf), "%s MAC Statistics", xname);
evcnt_attach_dynamic(&stats->ipcs, EVCNT_TYPE_MISC, NULL,
stats->namebuf, "rx csum offload - IP");
evcnt_attach_dynamic(&stats->l4cs, EVCNT_TYPE_MISC, NULL,
stats->namebuf, "rx csum offload - L4");
evcnt_attach_dynamic(&stats->ipcs_bad, EVCNT_TYPE_MISC, NULL,
stats->namebuf, "rx csum offload - IP bad");
evcnt_attach_dynamic(&stats->l4cs_bad, EVCNT_TYPE_MISC, NULL,
stats->namebuf, "rx csum offload - L4 bad");
/* Packet Reception Stats */
evcnt_attach_dynamic(&stats->vfgprc, EVCNT_TYPE_MISC, NULL,
xname, "Good Packets Received");
evcnt_attach_dynamic(&stats->vfgorc, EVCNT_TYPE_MISC, NULL,
xname, "Good Octets Received");
evcnt_attach_dynamic(&stats->vfmprc, EVCNT_TYPE_MISC, NULL,
xname, "Multicast Packets Received");
evcnt_attach_dynamic(&stats->vfgptc, EVCNT_TYPE_MISC, NULL,
xname, "Good Packets Transmitted");
evcnt_attach_dynamic(&stats->vfgotc, EVCNT_TYPE_MISC, NULL,
xname, "Good Octets Transmitted");
/* Mailbox Stats */
evcnt_attach_dynamic(&hw->mbx.stats.msgs_tx, EVCNT_TYPE_MISC, NULL,
xname, "message TXs");
evcnt_attach_dynamic(&hw->mbx.stats.msgs_rx, EVCNT_TYPE_MISC, NULL,
xname, "message RXs");
evcnt_attach_dynamic(&hw->mbx.stats.acks, EVCNT_TYPE_MISC, NULL,
xname, "ACKs");
evcnt_attach_dynamic(&hw->mbx.stats.reqs, EVCNT_TYPE_MISC, NULL,
xname, "REQs");
evcnt_attach_dynamic(&hw->mbx.stats.rsts, EVCNT_TYPE_MISC, NULL,
xname, "RSTs");
} /* ixv_add_stats_sysctls */
static void
ixv_clear_evcnt(struct adapter *adapter)
{
struct tx_ring *txr = adapter->tx_rings;
struct rx_ring *rxr = adapter->rx_rings;
struct ixgbevf_hw_stats *stats = &adapter->stats.vf;
struct ixgbe_hw *hw = &adapter->hw;
int i;
/* Driver Statistics */
IXGBE_EVC_STORE(&adapter->efbig_tx_dma_setup, 0);
IXGBE_EVC_STORE(&adapter->mbuf_defrag_failed, 0);
IXGBE_EVC_STORE(&adapter->efbig2_tx_dma_setup, 0);
IXGBE_EVC_STORE(&adapter->einval_tx_dma_setup, 0);
IXGBE_EVC_STORE(&adapter->other_tx_dma_setup, 0);
IXGBE_EVC_STORE(&adapter->eagain_tx_dma_setup, 0);
IXGBE_EVC_STORE(&adapter->enomem_tx_dma_setup, 0);
IXGBE_EVC_STORE(&adapter->watchdog_events, 0);
IXGBE_EVC_STORE(&adapter->tso_err, 0);
IXGBE_EVC_STORE(&adapter->admin_irqev, 0);
IXGBE_EVC_STORE(&adapter->link_workev, 0);
for (i = 0; i < adapter->num_queues; i++, rxr++, txr++) {
IXGBE_EVC_STORE(&adapter->queues[i].irqs, 0);
IXGBE_EVC_STORE(&adapter->queues[i].handleq, 0);
IXGBE_EVC_STORE(&adapter->queues[i].req, 0);
IXGBE_EVC_STORE(&txr->tso_tx, 0);
IXGBE_EVC_STORE(&txr->no_desc_avail, 0);
IXGBE_EVC_STORE(&txr->total_packets, 0);
#ifndef IXGBE_LEGACY_TX
IXGBE_EVC_STORE(&txr->pcq_drops, 0);
#endif
txr->q_efbig_tx_dma_setup = 0;
txr->q_mbuf_defrag_failed = 0;
txr->q_efbig2_tx_dma_setup = 0;
txr->q_einval_tx_dma_setup = 0;
txr->q_other_tx_dma_setup = 0;
txr->q_eagain_tx_dma_setup = 0;
txr->q_enomem_tx_dma_setup = 0;
txr->q_tso_err = 0;
IXGBE_EVC_STORE(&rxr->rx_packets, 0);
IXGBE_EVC_STORE(&rxr->rx_bytes, 0);
IXGBE_EVC_STORE(&rxr->rx_copies, 0);
IXGBE_EVC_STORE(&rxr->no_mbuf, 0);
IXGBE_EVC_STORE(&rxr->rx_discarded, 0);
}
/* MAC stats get their own sub node */
IXGBE_EVC_STORE(&stats->ipcs, 0);
IXGBE_EVC_STORE(&stats->l4cs, 0);
IXGBE_EVC_STORE(&stats->ipcs_bad, 0);
IXGBE_EVC_STORE(&stats->l4cs_bad, 0);
/*
* Packet Reception Stats.
* Call ixv_init_stats() to save last VF counters' values.
*/
ixv_init_stats(adapter);
IXGBE_EVC_STORE(&stats->vfgprc, 0);
IXGBE_EVC_STORE(&stats->vfgorc, 0);
IXGBE_EVC_STORE(&stats->vfmprc, 0);
IXGBE_EVC_STORE(&stats->vfgptc, 0);
IXGBE_EVC_STORE(&stats->vfgotc, 0);
/* Mailbox Stats */
IXGBE_EVC_STORE(&hw->mbx.stats.msgs_tx, 0);
IXGBE_EVC_STORE(&hw->mbx.stats.msgs_rx, 0);
IXGBE_EVC_STORE(&hw->mbx.stats.acks, 0);
IXGBE_EVC_STORE(&hw->mbx.stats.reqs, 0);
IXGBE_EVC_STORE(&hw->mbx.stats.rsts, 0);
} /* ixv_clear_evcnt */
#define PRINTQS(adapter, regname) \
do { \
struct ixgbe_hw *_hw = &(adapter)->hw; \
int _i; \
\
printf("%s: %s", device_xname((adapter)->dev), #regname); \
for (_i = 0; _i < (adapter)->num_queues; _i++) { \
printf((_i == 0) ? "\t" : " "); \
printf("%08x", IXGBE_READ_REG(_hw, \
IXGBE_##regname(_i))); \
} \
printf("\n"); \
} while (0)
/************************************************************************
* ixv_print_debug_info
*
* Provides a way to take a look at important statistics
* maintained by the driver and hardware.
************************************************************************/
static void
ixv_print_debug_info(struct adapter *adapter)
{
device_t dev = adapter->dev;
struct ixgbe_hw *hw = &adapter->hw;
int i;
device_printf(dev, "queue:");
for (i = 0; i < adapter->num_queues; i++) {
printf((i == 0) ? "\t" : " ");
printf("%8d", i);
}
printf("\n");
PRINTQS(adapter, VFRDBAL);
PRINTQS(adapter, VFRDBAH);
PRINTQS(adapter, VFRDLEN);
PRINTQS(adapter, VFSRRCTL);
PRINTQS(adapter, VFRDH);
PRINTQS(adapter, VFRDT);
PRINTQS(adapter, VFRXDCTL);
device_printf(dev, "EIMS:\t%08x\n", IXGBE_READ_REG(hw, IXGBE_VTEIMS));
device_printf(dev, "EIAM:\t%08x\n", IXGBE_READ_REG(hw, IXGBE_VTEIAM));
device_printf(dev, "EIAC:\t%08x\n", IXGBE_READ_REG(hw, IXGBE_VTEIAC));
} /* ixv_print_debug_info */
/************************************************************************
* ixv_sysctl_debug
************************************************************************/
static int
ixv_sysctl_debug(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct adapter *adapter = (struct adapter *)node.sysctl_data;
int error, result = 0;
node.sysctl_data = &result;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return error;
if (result == 1)
ixv_print_debug_info(adapter);
return 0;
} /* ixv_sysctl_debug */
/************************************************************************
* ixv_sysctl_rx_copy_len
************************************************************************/
static int
ixv_sysctl_rx_copy_len(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct adapter *adapter = (struct adapter *)node.sysctl_data;
int error;
int result = adapter->rx_copy_len;
node.sysctl_data = &result;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return error;
if ((result < 0) || (result > IXGBE_RX_COPY_LEN_MAX))
return EINVAL;
adapter->rx_copy_len = result;
return 0;
} /* ixv_sysctl_rx_copy_len */
/************************************************************************
* ixv_sysctl_tx_process_limit
************************************************************************/
static int
ixv_sysctl_tx_process_limit(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct adapter *adapter = (struct adapter *)node.sysctl_data;
int error;
int result = adapter->tx_process_limit;
node.sysctl_data = &result;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return error;
if ((result <= 0) || (result > adapter->num_tx_desc))
return EINVAL;
adapter->tx_process_limit = result;
return 0;
} /* ixv_sysctl_tx_process_limit */
/************************************************************************
* ixv_sysctl_rx_process_limit
************************************************************************/
static int
ixv_sysctl_rx_process_limit(SYSCTLFN_ARGS)
{
struct sysctlnode node = *rnode;
struct adapter *adapter = (struct adapter *)node.sysctl_data;
int error;
int result = adapter->rx_process_limit;
node.sysctl_data = &result;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return error;
if ((result <= 0) || (result > adapter->num_rx_desc))
return EINVAL;
adapter->rx_process_limit = result;
return 0;
} /* ixv_sysctl_rx_process_limit */
/************************************************************************
* ixv_init_device_features
************************************************************************/
static void
ixv_init_device_features(struct adapter *adapter)
{
adapter->feat_cap = IXGBE_FEATURE_NETMAP
| IXGBE_FEATURE_VF
| IXGBE_FEATURE_RSS
| IXGBE_FEATURE_LEGACY_TX;
/* A tad short on feature flags for VFs, atm. */
switch (adapter->hw.mac.type) {
case ixgbe_mac_82599_vf:
break;
case ixgbe_mac_X540_vf:
break;
case ixgbe_mac_X550_vf:
case ixgbe_mac_X550EM_x_vf:
case ixgbe_mac_X550EM_a_vf:
adapter->feat_cap |= IXGBE_FEATURE_NEEDS_CTXD;
break;
default:
break;
}
/* Enabled by default... */
/* Is a virtual function (VF) */
if (adapter->feat_cap & IXGBE_FEATURE_VF)
adapter->feat_en |= IXGBE_FEATURE_VF;
/* Netmap */
if (adapter->feat_cap & IXGBE_FEATURE_NETMAP)
adapter->feat_en |= IXGBE_FEATURE_NETMAP;
/* Receive-Side Scaling (RSS) */
if (adapter->feat_cap & IXGBE_FEATURE_RSS)
adapter->feat_en |= IXGBE_FEATURE_RSS;
/* Needs advanced context descriptor regardless of offloads req'd */
if (adapter->feat_cap & IXGBE_FEATURE_NEEDS_CTXD)
adapter->feat_en |= IXGBE_FEATURE_NEEDS_CTXD;
/* Enabled via sysctl... */
/* Legacy (single queue) transmit */
if ((adapter->feat_cap & IXGBE_FEATURE_LEGACY_TX) &&
ixv_enable_legacy_tx)
adapter->feat_en |= IXGBE_FEATURE_LEGACY_TX;
} /* ixv_init_device_features */
/************************************************************************
* ixv_shutdown - Shutdown entry point
************************************************************************/
#if 0 /* XXX NetBSD ought to register something like this through pmf(9) */
static int
ixv_shutdown(device_t dev)
{
struct adapter *adapter = device_private(dev);
IXGBE_CORE_LOCK(adapter);
ixv_stop_locked(adapter);
IXGBE_CORE_UNLOCK(adapter);
return (0);
} /* ixv_shutdown */
#endif
static int
ixv_ifflags_cb(struct ethercom *ec)
{
struct ifnet *ifp = &ec->ec_if;
struct adapter *adapter = ifp->if_softc;
u_short saved_flags;
u_short change;
int rv = 0;
IXGBE_CORE_LOCK(adapter);
saved_flags = adapter->if_flags;
change = ifp->if_flags ^ adapter->if_flags;
if (change != 0)
adapter->if_flags = ifp->if_flags;
if ((change & ~(IFF_CANTCHANGE | IFF_DEBUG)) != 0) {
rv = ENETRESET;
goto out;
} else if ((change & IFF_PROMISC) != 0) {
rv = ixv_set_rxfilter(adapter);
if (rv != 0) {
/* Restore previous */
adapter->if_flags = saved_flags;
goto out;
}
}
/* Check for ec_capenable. */
change = ec->ec_capenable ^ adapter->ec_capenable;
adapter->ec_capenable = ec->ec_capenable;
if ((change & ~(ETHERCAP_VLAN_MTU | ETHERCAP_VLAN_HWTAGGING
| ETHERCAP_VLAN_HWFILTER)) != 0) {
rv = ENETRESET;
goto out;
}
/*
* Special handling is not required for ETHERCAP_VLAN_MTU.
* PF's MAXFRS(MHADD) does not include the 4bytes of the VLAN header.
*/
/* Set up VLAN support and filter */
if ((change & (ETHERCAP_VLAN_HWTAGGING | ETHERCAP_VLAN_HWFILTER)) != 0)
rv = ixv_setup_vlan_support(adapter);
out:
IXGBE_CORE_UNLOCK(adapter);
return rv;
}
/************************************************************************
* ixv_ioctl - Ioctl entry point
*
* Called when the user wants to configure the interface.
*
* return 0 on success, positive on failure
************************************************************************/
static int
ixv_ioctl(struct ifnet *ifp, u_long command, void *data)
{
struct adapter *adapter = ifp->if_softc;
struct ixgbe_hw *hw = &adapter->hw;
struct ifcapreq *ifcr = data;
int error;
int l4csum_en;
const int l4csum = IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_UDPv4_Rx |
IFCAP_CSUM_TCPv6_Rx | IFCAP_CSUM_UDPv6_Rx;
switch (command) {
case SIOCSIFFLAGS:
IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
break;
case SIOCADDMULTI: {
struct ether_multi *enm;
struct ether_multistep step;
struct ethercom *ec = &adapter->osdep.ec;
bool overflow = false;
int mcnt = 0;
/*
* Check the number of multicast address. If it exceeds,
* return ENOSPC.
* Update this code when we support API 1.3.
*/
ETHER_LOCK(ec);
ETHER_FIRST_MULTI(step, ec, enm);
while (enm != NULL) {
mcnt++;
/*
* This code is before adding, so one room is required
* at least.
*/
if (mcnt > (IXGBE_MAX_VF_MC - 1)) {
overflow = true;
break;
}
ETHER_NEXT_MULTI(step, enm);
}
ETHER_UNLOCK(ec);
error = 0;
if (overflow && ((ec->ec_flags & ETHER_F_ALLMULTI) == 0)) {
error = hw->mac.ops.update_xcast_mode(hw,
IXGBEVF_XCAST_MODE_ALLMULTI);
if (error == IXGBE_ERR_NOT_TRUSTED) {
device_printf(adapter->dev,
"this interface is not trusted\n");
error = EPERM;
} else if (error == IXGBE_ERR_FEATURE_NOT_SUPPORTED) {
device_printf(adapter->dev,
"the PF doesn't support allmulti mode\n");
error = EOPNOTSUPP;
} else if (error) {
device_printf(adapter->dev,
"number of Ethernet multicast addresses "
"exceeds the limit (%d). error = %d\n",
IXGBE_MAX_VF_MC, error);
error = ENOSPC;
} else
ec->ec_flags |= ETHER_F_ALLMULTI;
}
if (error)
return error;
}
/*FALLTHROUGH*/
case SIOCDELMULTI:
IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
break;
case SIOCSIFMEDIA:
case SIOCGIFMEDIA:
IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
break;
case SIOCSIFCAP:
IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
break;
case SIOCSIFMTU:
IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
break;
case SIOCZIFDATA:
IOCTL_DEBUGOUT("ioctl: SIOCZIFDATA (Zero counter)");
ixv_update_stats(adapter);
ixv_clear_evcnt(adapter);
break;
default:
IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)", (int)command);
break;
}
switch (command) {
case SIOCSIFCAP:
/* Layer-4 Rx checksum offload has to be turned on and
* off as a unit.
*/
l4csum_en = ifcr->ifcr_capenable & l4csum;
if (l4csum_en != l4csum && l4csum_en != 0)
return EINVAL;
/*FALLTHROUGH*/
case SIOCADDMULTI:
case SIOCDELMULTI:
case SIOCSIFFLAGS:
case SIOCSIFMTU:
default:
if ((error = ether_ioctl(ifp, command, data)) != ENETRESET)
return error;
if ((ifp->if_flags & IFF_RUNNING) == 0)
;
else if (command == SIOCSIFCAP || command == SIOCSIFMTU) {
IXGBE_CORE_LOCK(adapter);
ixv_init_locked(adapter);
IXGBE_CORE_UNLOCK(adapter);
} else if (command == SIOCADDMULTI || command == SIOCDELMULTI) {
/*
* Multicast list has changed; set the hardware filter
* accordingly.
*/
IXGBE_CORE_LOCK(adapter);
ixv_disable_intr(adapter);
ixv_set_rxfilter(adapter);
ixv_enable_intr(adapter);
IXGBE_CORE_UNLOCK(adapter);
}
return 0;
}
} /* ixv_ioctl */
/************************************************************************
* ixv_init
************************************************************************/
static int
ixv_init(struct ifnet *ifp)
{
struct adapter *adapter = ifp->if_softc;
IXGBE_CORE_LOCK(adapter);
ixv_init_locked(adapter);
IXGBE_CORE_UNLOCK(adapter);
return 0;
} /* ixv_init */
/************************************************************************
* ixv_handle_que
************************************************************************/
static void
ixv_handle_que(void *context)
{
struct ix_queue *que = context;
struct adapter *adapter = que->adapter;
struct tx_ring *txr = que->txr;
struct ifnet *ifp = adapter->ifp;
bool more;
IXGBE_EVC_ADD(&que->handleq, 1);
if (ifp->if_flags & IFF_RUNNING) {
IXGBE_TX_LOCK(txr);
more = ixgbe_txeof(txr);
if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX))
if (!ixgbe_mq_ring_empty(ifp, txr->txr_interq))
ixgbe_mq_start_locked(ifp, txr);
/* Only for queue 0 */
/* NetBSD still needs this for CBQ */
if ((&adapter->queues[0] == que)
&& (!ixgbe_legacy_ring_empty(ifp, NULL)))
ixgbe_legacy_start_locked(ifp, txr);
IXGBE_TX_UNLOCK(txr);
more |= ixgbe_rxeof(que);
if (more) {
IXGBE_EVC_ADD(&que->req, 1);
if (adapter->txrx_use_workqueue) {
/*
* "enqueued flag" is not required here
* the same as ixg(4). See ixgbe_msix_que().
*/
workqueue_enqueue(adapter->que_wq,
&que->wq_cookie, curcpu());
} else
softint_schedule(que->que_si);
return;
}
}
/* Re-enable this interrupt */
ixv_enable_queue(adapter, que->msix);
return;
} /* ixv_handle_que */
/************************************************************************
* ixv_handle_que_work
************************************************************************/
static void
ixv_handle_que_work(struct work *wk, void *context)
{
struct ix_queue *que = container_of(wk, struct ix_queue, wq_cookie);
/*
* "enqueued flag" is not required here the same as ixg(4).
* See ixgbe_msix_que().
*/
ixv_handle_que(que);
}
/************************************************************************
* ixv_allocate_msix - Setup MSI-X Interrupt resources and handlers
************************************************************************/
static int
ixv_allocate_msix(struct adapter *adapter, const struct pci_attach_args *pa)
{
device_t dev = adapter->dev;
struct ix_queue *que = adapter->queues;
struct tx_ring *txr = adapter->tx_rings;
int error, msix_ctrl, rid, vector = 0;
pci_chipset_tag_t pc;
pcitag_t tag;
char intrbuf[PCI_INTRSTR_LEN];
char wqname[MAXCOMLEN];
char intr_xname[32];
const char *intrstr = NULL;
kcpuset_t *affinity;
int cpu_id = 0;
pc = adapter->osdep.pc;
tag = adapter->osdep.tag;
adapter->osdep.nintrs = adapter->num_queues + 1;
if (pci_msix_alloc_exact(pa, &adapter->osdep.intrs,
adapter->osdep.nintrs) != 0) {
aprint_error_dev(dev,
"failed to allocate MSI-X interrupt\n");
return (ENXIO);
}
kcpuset_create(&affinity, false);
for (int i = 0; i < adapter->num_queues; i++, vector++, que++, txr++) {
snprintf(intr_xname, sizeof(intr_xname), "%s TXRX%d",
device_xname(dev), i);
intrstr = pci_intr_string(pc, adapter->osdep.intrs[i], intrbuf,
sizeof(intrbuf));
#ifdef IXGBE_MPSAFE
pci_intr_setattr(pc, &adapter->osdep.intrs[i], PCI_INTR_MPSAFE,
true);
#endif
/* Set the handler function */
que->res = adapter->osdep.ihs[i] = pci_intr_establish_xname(pc,
adapter->osdep.intrs[i], IPL_NET, ixv_msix_que, que,
intr_xname);
if (que->res == NULL) {
pci_intr_release(pc, adapter->osdep.intrs,
adapter->osdep.nintrs);
aprint_error_dev(dev,
"Failed to register QUE handler\n");
kcpuset_destroy(affinity);
return (ENXIO);
}
que->msix = vector;
adapter->active_queues |= (u64)(1 << que->msix);
cpu_id = i;
/* Round-robin affinity */
kcpuset_zero(affinity);
kcpuset_set(affinity, cpu_id % ncpu);
error = interrupt_distribute(adapter->osdep.ihs[i], affinity,
NULL);
aprint_normal_dev(dev, "for TX/RX, interrupting at %s",
intrstr);
if (error == 0)
aprint_normal(", bound queue %d to cpu %d\n",
i, cpu_id % ncpu);
else
aprint_normal("\n");
#ifndef IXGBE_LEGACY_TX
txr->txr_si
= softint_establish(SOFTINT_NET | IXGBE_SOFTINT_FLAGS,
ixgbe_deferred_mq_start, txr);
#endif
que->que_si
= softint_establish(SOFTINT_NET | IXGBE_SOFTINT_FLAGS,
ixv_handle_que, que);
if (que->que_si == NULL) {
aprint_error_dev(dev,
"could not establish software interrupt\n");
}
}
snprintf(wqname, sizeof(wqname), "%sdeferTx", device_xname(dev));
error = workqueue_create(&adapter->txr_wq, wqname,
ixgbe_deferred_mq_start_work, adapter, IXGBE_WORKQUEUE_PRI, IPL_NET,
IXGBE_WORKQUEUE_FLAGS);
if (error) {
aprint_error_dev(dev,
"couldn't create workqueue for deferred Tx\n");
}
adapter->txr_wq_enqueued = percpu_alloc(sizeof(u_int));
snprintf(wqname, sizeof(wqname), "%sTxRx", device_xname(dev));
error = workqueue_create(&adapter->que_wq, wqname,
ixv_handle_que_work, adapter, IXGBE_WORKQUEUE_PRI, IPL_NET,
IXGBE_WORKQUEUE_FLAGS);
if (error) {
aprint_error_dev(dev, "couldn't create workqueue for Tx/Rx\n");
}
/* and Mailbox */
cpu_id++;
snprintf(intr_xname, sizeof(intr_xname), "%s link", device_xname(dev));
adapter->vector = vector;
intrstr = pci_intr_string(pc, adapter->osdep.intrs[vector], intrbuf,
sizeof(intrbuf));
#ifdef IXGBE_MPSAFE
pci_intr_setattr(pc, &adapter->osdep.intrs[vector], PCI_INTR_MPSAFE,
true);
#endif
/* Set the mbx handler function */
adapter->osdep.ihs[vector] = pci_intr_establish_xname(pc,
adapter->osdep.intrs[vector], IPL_NET, ixv_msix_mbx, adapter,
intr_xname);
if (adapter->osdep.ihs[vector] == NULL) {
aprint_error_dev(dev, "Failed to register LINK handler\n");
kcpuset_destroy(affinity);
return (ENXIO);
}
/* Round-robin affinity */
kcpuset_zero(affinity);
kcpuset_set(affinity, cpu_id % ncpu);
error = interrupt_distribute(adapter->osdep.ihs[vector], affinity,
NULL);
aprint_normal_dev(dev,
"for link, interrupting at %s", intrstr);
if (error == 0)
aprint_normal(", affinity to cpu %d\n", cpu_id % ncpu);
else
aprint_normal("\n");
/* Tasklets for Mailbox */
snprintf(wqname, sizeof(wqname), "%s-admin", device_xname(dev));
error = workqueue_create(&adapter->admin_wq, wqname,
ixv_handle_admin, adapter, IXGBE_WORKQUEUE_PRI, IPL_NET,
IXGBE_TASKLET_WQ_FLAGS);
if (error) {
aprint_error_dev(dev,
"could not create admin workqueue (%d)\n", error);
goto err_out;
}
/*
* Due to a broken design QEMU will fail to properly
* enable the guest for MSI-X unless the vectors in
* the table are all set up, so we must rewrite the
* ENABLE in the MSI-X control register again at this
* point to cause it to successfully initialize us.
*/
if (adapter->hw.mac.type == ixgbe_mac_82599_vf) {
pci_get_capability(pc, tag, PCI_CAP_MSIX, &rid, NULL);
rid += PCI_MSIX_CTL;
msix_ctrl = pci_conf_read(pc, tag, rid);
msix_ctrl |= PCI_MSIX_CTL_ENABLE;
pci_conf_write(pc, tag, rid, msix_ctrl);
}
kcpuset_destroy(affinity);
return (0);
err_out:
kcpuset_destroy(affinity);
ixv_free_deferred_handlers(adapter);
ixv_free_pci_resources(adapter);
return (error);
} /* ixv_allocate_msix */
/************************************************************************
* ixv_configure_interrupts - Setup MSI-X resources
*
* Note: The VF device MUST use MSI-X, there is no fallback.
************************************************************************/
static int
ixv_configure_interrupts(struct adapter *adapter)
{
device_t dev = adapter->dev;
int want, queues, msgs;
/* Must have at least 2 MSI-X vectors */
msgs = pci_msix_count(adapter->osdep.pc, adapter->osdep.tag);
if (msgs < 2) {
aprint_error_dev(dev, "MSIX config error\n");
return (ENXIO);
}
msgs = MIN(msgs, IXG_MAX_NINTR);
/* Figure out a reasonable auto config value */
queues = (ncpu > (msgs - 1)) ? (msgs - 1) : ncpu;
if (ixv_num_queues != 0)
queues = ixv_num_queues;
else if ((ixv_num_queues == 0) && (queues > IXGBE_VF_MAX_TX_QUEUES))
queues = IXGBE_VF_MAX_TX_QUEUES;
/*
* Want vectors for the queues,
* plus an additional for mailbox.
*/
want = queues + 1;
if (msgs >= want)
msgs = want;
else {
aprint_error_dev(dev,
"MSI-X Configuration Problem, "
"%d vectors but %d queues wanted!\n", msgs, want);
return -1;
}
aprint_normal_dev(dev,
"Using MSI-X interrupts with %d vectors\n", msgs);
adapter->num_queues = queues;
return (0);
} /* ixv_configure_interrupts */
/************************************************************************
* ixv_handle_admin - Tasklet handler for MSI-X MBX interrupts
*
* Done outside of interrupt context since the driver might sleep
************************************************************************/
static void
ixv_handle_admin(struct work *wk, void *context)
{
struct adapter *adapter = context;
struct ixgbe_hw *hw = &adapter->hw;
IXGBE_CORE_LOCK(adapter);
IXGBE_EVC_ADD(&adapter->link_workev, 1);
adapter->hw.mac.ops.check_link(&adapter->hw, &adapter->link_speed,
&adapter->link_up, FALSE);
ixv_update_link_status(adapter);
adapter->task_requests = 0;
atomic_store_relaxed(&adapter->admin_pending, 0);
/* Re-enable interrupts */
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, (1 << adapter->vector));
IXGBE_CORE_UNLOCK(adapter);
} /* ixv_handle_admin */
/************************************************************************
* ixv_check_link - Used in the local timer to poll for link changes
************************************************************************/
static s32
ixv_check_link(struct adapter *adapter)
{
s32 error;
KASSERT(mutex_owned(&adapter->core_mtx));
adapter->hw.mac.get_link_status = TRUE;
error = adapter->hw.mac.ops.check_link(&adapter->hw,
&adapter->link_speed, &adapter->link_up, FALSE);
ixv_update_link_status(adapter);
return error;
} /* ixv_check_link */
|