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
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.
Module Name:
Vmq.c
Abstract:
This module implements the VMQ related functionality for the adapter.
--*/
#include "netvmin6.h"
#include "vmq.tmh"
NDIS_STATUS
FreeAdapterQueueInfo(
_In_ PMP_ADAPTER Adapter,
USHORT QueueId,
_In_opt_ PNDIS_OID_REQUEST NdisSetRequest);
NDIS_STATUS
InitializeAdapterQueueInfo(
_In_ PMP_ADAPTER Adapter,
_In_opt_ PNDIS_RECEIVE_QUEUE_PARAMETERS QueueParams,
_Out_ PMP_ADAPTER_QUEUE QueueInfo);
NDIS_STATUS
AllocateRxQueueReceiveMemory(
_Inout_ struct _MP_ADAPTER *Adapter,
PMP_ADAPTER_QUEUE Queue);
NDIS_IO_WORKITEM_FUNCTION FreeRxQueuesWorkItem;
NDIS_STATUS
AllocateVMQData(
_Inout_ struct _MP_ADAPTER *Adapter)
/*++
Routine Description:
This routine will initialize the basic fields necessary for a MP_ADAPTER_VMQ_DATA structure. The function
should be called during adapter initialization, before any queues or filter requests are fielded.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER_VMQ_DATA VMQData = &Adapter->VMQData;
UINT i;
DEBUGP(MP_TRACE, "[%p] ---> AllocateVMQData\n", Adapter);
do
{
NdisZeroMemory(VMQData, sizeof(MP_ADAPTER_VMQ_DATA));
//
// Initialize the locks for the queues
//
for(i=0; i<NIC_SUPPORTED_NUM_QUEUES;i++)
{
VMQData->RxQueues[i].QueueLock = NdisAllocateRWLock(Adapter->AdapterHandle);
if(!VMQData->RxQueues[i].QueueLock)
{
DEBUGP(MP_ERROR, "[%p] NdisAllocateRWLock failed for Queue %i.\n", Adapter, i);
Status = NDIS_STATUS_RESOURCES;
break;
}
}
if(Status != NDIS_STATUS_SUCCESS)
{
//
// Failed allocating the locks, need to fail this allocation
//
break;
}
}while(FALSE);
DEBUGP(MP_TRACE, "<--- [%p] AllocateVMQData Status 0x%08x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
AllocateDefaultRxQueue(
_Inout_ struct _MP_ADAPTER *Adapter)
/*++
Routine Description:
This routine will allocate the default receive queue (MP_ADAPTER_QUEUE). The function
should be called during adapter initialization, before any queues or filter requests are fielded.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER_VMQ_DATA VMQData = &Adapter->VMQData;
do
{
//
// Initialize the default queue.
// No need to take lock since this is done during adapter initialization. We won't be fielding receives until this is complete.
//
Status = InitializeAdapterQueueInfo(Adapter, NULL, &VMQData->RxQueues[0]);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] Failed to initialize the default queue.\n", Adapter);
break;
}
//
// Allocate the receive memory (no shared memory is necessary)
//
Status = AllocateRxQueueReceiveMemory(Adapter, &VMQData->RxQueues[0]);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] Failed to allocate the receive memory for the default queue.\n", Adapter);
break;
}
//
// Set default as completed. At this point the queue is ready for receives.
//
QUEUE_SET_FLAG(&VMQData->RxQueues[0], fMPAQI_COMPLETION_FINISHED);
} while(FALSE);
return Status;
}
NDIS_STATUS
ReadRxQueueConfig(
_In_ NDIS_HANDLE ConfigurationHandle,
_Inout_ struct _MP_ADAPTER *Adapter)
/*++
Routine Description:
This routine will read the VMQ configuration from the NDIS registry, and set the results to the VMQData flags field.
Arguments:
ConfigurationHandle - Adapter configuration handle
Adapter - Pointer to our adapter
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PNDIS_CONFIGURATION_PARAMETER Parameter = NULL;
NDIS_STRING VMQKeyword = NDIS_STRING_CONST("*VMQ"),
LookaheadKeyword = NDIS_STRING_CONST("*VMQLookaheadSplit"),
FilteringKeyword = NDIS_STRING_CONST("*VMQVlanFiltering");
DEBUGP(MP_TRACE, "[%p] ---> ReadRxQueueConfig\n", Adapter);
do
{
//
// Read the *VMQ flag (whether VMQ is enabled on the adapter).
// Note: RSS and VMQ cannot be active simultaneously. If the miniport supports
// RSS, and the *RSS keyword is set to 1, then the *RssOrVmqPreference keyword
// must be used to determine which technology should be enabled on the adapter
// (0: enabled RSS, disable VMQ, 1: disable RSS, enable VMQ).
//
//
NdisReadConfiguration(
&Status,
&Parameter,
ConfigurationHandle,
&VMQKeyword,
NdisParameterInteger);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] NdisReadConfiguration for *VMQ failed Status 0x%08x, defaulting to disabled.\n", Adapter, Status);
Status = NDIS_STATUS_SUCCESS;
break;
}
if(Parameter->ParameterData.IntegerData==1)
{
VMQ_SET_FLAG(Adapter, fMPVMQD_FILTERING_ENABLED);
}
//
// Read the *VMQLookaheadSplit flag (whether lookahead split is enabled on the adapter)
//
NdisReadConfiguration(
&Status,
&Parameter,
ConfigurationHandle,
&LookaheadKeyword,
NdisParameterInteger);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] NdisReadConfiguration for *VMQLookaheadSplit failed Status 0x%08x, defaulting to disabled.\n", Adapter, Status);
Status = NDIS_STATUS_SUCCESS;
}
else if(Parameter->ParameterData.IntegerData==1)
{
VMQ_SET_FLAG(Adapter, fMPVMQD_LOOKAHEAD_ENABLED);
}
//
// Read the *VMQVlanFiltering flag (whether lookahead split is enabled on the adapter)
//
NdisReadConfiguration(
&Status,
&Parameter,
ConfigurationHandle,
&FilteringKeyword,
NdisParameterInteger);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] NdisReadConfiguration for *VMQVlanFiltering failed Status 0x%08x, defaulting to disabled.\n", Adapter, Status);
Status = NDIS_STATUS_SUCCESS;
}
else if(Parameter->ParameterData.IntegerData==1)
{
VMQ_SET_FLAG(Adapter, fMPVMQD_VLANFILTER_ENABLED);
}
} while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- ReadRxQueueConfig Status 0x%08x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
InitializeRxQueueMPConfig(
_Inout_ struct _MP_ADAPTER *Adapter)
/*++
Routine Description:
This routine will set the supported and actual VMQ configuration for the miniport calling NdisMSetMiniportAttributes.
Arguments:
Adapter - Pointer to our adapter
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
NDIS_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES HardwareAssistAttributes;
NDIS_RECEIVE_FILTER_CAPABILITIES HwCapabilities, CurrentCapabilities;
NDIS_NIC_SWITCH_CAPABILITIES HwSwitchCapabilities, CurrentSwitchCapabilities;
DEBUGP(MP_TRACE, "[%p] ---> InitializeRxQueueMPConfig\n", Adapter);
do
{
//
// Set the VMQ adapter capabilities.
//
NdisZeroMemory(&HardwareAssistAttributes, sizeof(HardwareAssistAttributes));
{C_ASSERT(sizeof(HardwareAssistAttributes) >= NDIS_SIZEOF_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES_REVISION_2);}
HardwareAssistAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES;
HardwareAssistAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES_REVISION_2;
HardwareAssistAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_HARDWARE_ASSIST_ATTRIBUTES_REVISION_2;
//
// Filter capabilities for VMQ
//
NdisZeroMemory(&HwCapabilities, sizeof(HwCapabilities));
//
// header fields
//
HwCapabilities.Header.Revision = NDIS_RECEIVE_FILTER_CAPABILITIES_REVISION_1;
HwCapabilities.Header.Size = NDIS_SIZEOF_RECEIVE_FILTER_CAPABILITIES_REVISION_1;
HwCapabilities.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
//
// enable VMQ filters
//
HwCapabilities.EnabledFilterTypes = NDIS_RECEIVE_FILTER_VMQ_FILTERS_ENABLED;
//
// enable VMQ queues
//
HwCapabilities.EnabledQueueTypes = NDIS_RECEIVE_FILTER_VM_QUEUES_ENABLED;
//
// queue properties
//
HwCapabilities.NumQueues = NIC_SUPPORTED_NUM_QUEUES - 1;// First queue reserved for default
HwCapabilities.SupportedQueueProperties = NDIS_RECEIVE_FILTER_VM_QUEUE_SUPPORTED | NDIS_RECEIVE_FILTER_LOOKAHEAD_SPLIT_SUPPORTED;
#if (NDIS_SUPPORT_NDIS630)
HwCapabilities.SupportedQueueProperties |= NDIS_RECEIVE_FILTER_DYNAMIC_PROCESSOR_AFFINITY_CHANGE_SUPPORTED;
#endif
HwCapabilities.SupportedFilterTests = NDIS_RECEIVE_FILTER_TEST_HEADER_FIELD_EQUAL_SUPPORTED;
HwCapabilities.SupportedHeaders = NDIS_RECEIVE_FILTER_MAC_HEADER_SUPPORTED;
HwCapabilities.SupportedMacHeaderFields = NDIS_RECEIVE_FILTER_MAC_HEADER_DEST_ADDR_SUPPORTED | NDIS_RECEIVE_FILTER_MAC_HEADER_VLAN_ID_SUPPORTED;
HwCapabilities.MaxMacHeaderFilters = NIC_MAX_HEADER_FILTERS;
HwCapabilities.MinLookaheadSplitSize = NIC_MIN_LOOKAHEAD_SPLIT;
HwCapabilities.MaxLookaheadSplitSize = NIC_MAX_LOOKAHEAD_SPLIT;
HardwareAssistAttributes.HardwareReceiveFilterCapabilities = &HwCapabilities;
//
// Set the actual VMQ adapter configuration.
//
NdisZeroMemory(&CurrentCapabilities, sizeof(CurrentCapabilities));
//
// header fields
//
CurrentCapabilities.Header.Revision = NDIS_RECEIVE_FILTER_CAPABILITIES_REVISION_1;
CurrentCapabilities.Header.Size = NDIS_SIZEOF_RECEIVE_FILTER_CAPABILITIES_REVISION_1;
CurrentCapabilities.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
if(VMQ_ENABLED(Adapter))
{
//
//set equal to HW capabilities, which has all the supported options set, and then remove optional disabled capabilties
//
memcpy(&CurrentCapabilities, &HwCapabilities, sizeof(CurrentCapabilities));
if(!LOOKAHEAD_SPLIT_ENABLED(Adapter))
{
//
// Remove lookahead split capability flag, as it's disabled in the driver configuration
//
CurrentCapabilities.SupportedQueueProperties &= ~NDIS_RECEIVE_FILTER_LOOKAHEAD_SPLIT_SUPPORTED;
}
if(!VLAN_FILTER_ENABLED(Adapter))
{
//
// Remove lookahead vlan filtering capability flag, as it's disabled in the driver configuration
//
CurrentCapabilities.SupportedMacHeaderFields &= ~NDIS_RECEIVE_FILTER_MAC_HEADER_VLAN_ID_SUPPORTED;
}
}
//
// Set NIC switch adapter capabilities.
//
HardwareAssistAttributes.CurrentReceiveFilterCapabilities = &CurrentCapabilities;
NdisZeroMemory(&HwSwitchCapabilities, sizeof(HwSwitchCapabilities));
HwSwitchCapabilities.Header.Revision = NDIS_NIC_SWITCH_CAPABILITIES_REVISION_1;
HwSwitchCapabilities.Header.Size = NDIS_SIZEOF_NIC_SWITCH_CAPABILITIES_REVISION_1;
HwSwitchCapabilities.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
//
// The NIC's limits corresponds to the maximum number of filters supported.
//
HwSwitchCapabilities.NumTotalMacAddresses = NIC_MAX_HEADER_FILTERS;
HwSwitchCapabilities.NumMacAddressesPerPort = NIC_MAX_HEADER_FILTERS;
HwSwitchCapabilities.NumVlansPerPort = NIC_MAX_HEADER_FILTERS;
HardwareAssistAttributes.HardwareNicSwitchCapabilities = &HwSwitchCapabilities;
//
// Set the actual NIC switch adapter configuration.
//
NdisZeroMemory(&CurrentSwitchCapabilities, sizeof(CurrentSwitchCapabilities));
CurrentSwitchCapabilities.Header.Revision = NDIS_NIC_SWITCH_CAPABILITIES_REVISION_1;
CurrentSwitchCapabilities.Header.Size = NDIS_SIZEOF_NIC_SWITCH_CAPABILITIES_REVISION_1;
CurrentSwitchCapabilities.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
if(VMQ_ENABLED(Adapter))
{
//
// Set equal to HW capabilities, which has all the supported options set.
//
memcpy(&CurrentSwitchCapabilities, &HwSwitchCapabilities, sizeof(CurrentSwitchCapabilities));
}
HardwareAssistAttributes.CurrentNicSwitchCapabilities = &CurrentSwitchCapabilities;
Status = NdisMSetMiniportAttributes(
Adapter->AdapterHandle,
(PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&HardwareAssistAttributes);
if (NDIS_STATUS_SUCCESS != Status)
{
DEBUGP(MP_ERROR, "[%p] NdisMSetMiniportAttributes Status 0x%08x\n", Adapter, Status);
break;
}
}while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- InitializeRxQueueMPConfig Status 0x%08x\n", Adapter, Status);
return Status;
}
BOOLEAN
ValidGroupAffinity(
_In_ PGROUP_AFFINITY GroupAffinity)
/*++
Routine Description:
This routine will verify that the passed in group affinity contains valid values.
Runs at any IRQL.
Arguments:
GroupAffinity - Affinity to verify
Return Value:
TRUE - Affinity is valid
FALSE - Affinity is invalid
--*/
{
//
// GetActiveProcessorCount will validate the group value
//
#pragma warning( suppress: 28193 ) // we check ProcessorNumber result later in code
UCHAR ProcessorNumber = RtlFindLeastSignificantBit((ULONGLONG)GroupAffinity->Mask);
ULONG ActiveProcessors = KeQueryActiveProcessorCountEx(GroupAffinity->Group);
if(!ActiveProcessors)
{
//
// Group was invalid
//
DEBUGP(MP_TRACE, "ValidGroupAffinity failed (KeQueryActiveProcessorCountEx error). Group: 0x%x, Mask: 0x%I64x\n",
GroupAffinity->Group, GroupAffinity->Mask);
return FALSE;
}
if(ProcessorNumber == -1)
{
//
// The affinity mask must be non-zero (RtlFindLeastSignificantBit returns -1 if there aren't any non-zero bits)
//
DEBUGP(MP_TRACE, "ValidGroupAffinity failed (zero mask). Group: 0x%x, Mask: 0x%I64x\n", GroupAffinity->Group, GroupAffinity->Mask);
return FALSE;
}
if(ProcessorNumber >= ActiveProcessors)
{
//
// The processor number is out of range
//
DEBUGP(MP_TRACE, "ValidGroupAffinity failed (processor number out of range). Group: 0x%x, Mask: 0x%I64x, ProcessorNumber: %i, ActiveProcessors: %i\n",
GroupAffinity->Group, GroupAffinity->Mask, ProcessorNumber, ActiveProcessors);
return FALSE;
}
return TRUE;
}
NDIS_STATUS
InitializeAdapterQueueInfo(
_In_ PMP_ADAPTER Adapter,
_In_opt_ PNDIS_RECEIVE_QUEUE_PARAMETERS QueueParams,
_Out_ PMP_ADAPTER_QUEUE QueueInfo)
/*++
Routine Description:
This routine will allocate the PMP_ADAPTER_QUEUE structure passed in using the QueueParams specified.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
QueueParams - NDIS_RECEIVE_QUEUE_PARAMETERS data that define the configuration for the queue
QueueInfo - Pointer to PMP_ADAPTER_QUEUE to derefence and allocate
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
NDIS_RECEIVE_QUEUE_ID QueueId = 0;
DEBUGP(MP_TRACE, "[%p] ---> InitializeAdapterQueueInfo\n", Adapter);
do
{
if(QueueParams)
{
if(!ValidGroupAffinity(&QueueParams->ProcessorAffinity))
{
DEBUGP(MP_ERROR, "[%p] Requested group affinity failed validation\n", Adapter);
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
QueueId = QueueParams->QueueId;
//
// Copy relevant data from the request
//
QueueInfo->QueueId = QueueId;
QueueInfo->NumSuggestedReceiveBuffers = QueueParams->NumSuggestedReceiveBuffers;
if(QueueParams->LookaheadSize)
{
if(QueueParams->LookaheadSize<NIC_MIN_LOOKAHEAD_SPLIT)
{
//
// A smaller lookahead has been requested than what's supported, use our supported minimum
//
QueueInfo->LookaheadSize = NIC_MIN_LOOKAHEAD_SPLIT;
DEBUGP(MP_INFO, "[%p] Requested LA size (%i) for Queue %i is too small, using our minium (%i)\n", Adapter, QueueParams->LookaheadSize, QueueId, NIC_MIN_LOOKAHEAD_SPLIT);
}
else if(QueueParams->LookaheadSize>NIC_MAX_LOOKAHEAD_SPLIT)
{
Status = NDIS_STATUS_NOT_SUPPORTED;
DEBUGP(MP_ERROR, "[%p] Requested LA size (%i) for Queue %i is above our maximum (%i), the request has failed.\n", Adapter, QueueParams->LookaheadSize, QueueId, NIC_MAX_LOOKAHEAD_SPLIT);
break;
}
else
{
QueueInfo->LookaheadSize = QueueParams->LookaheadSize;
}
}
QueueInfo->NdisFlags = QueueParams->Flags & (~NDIS_RECEIVE_QUEUE_PARAMETERS_CHANGE_MASK);
QueueInfo->ProcessorAffinity = QueueParams->ProcessorAffinity;
}
//
// Please note that for PCI hardware, rather than maintaining DPCs with differing affinities for receives as we do in this
// software implementation, the affinity information would instead be applied to the MSI-X configuration.
//
if(QueueParams)
{
//
// Set processor affininty for receive DPC
//
PROCESSOR_NUMBER ProcNumber = {0};
ProcNumber.Group = QueueInfo->ProcessorAffinity.Group;
ProcNumber.Number = RtlFindLeastSignificantBit((ULONGLONG)QueueInfo->ProcessorAffinity.Mask);
ASSERT(ProcNumber.Number != -1);
if(ProcNumber.Number == -1)
{
//
// Queue has no affinity bits set.
//
Status = NDIS_STATUS_INVALID_PARAMETER;
DEBUGP(MP_ERROR,
"[%p] Queue %i has no affinity bits set.\n",
Adapter,
QueueId);
break;
}
QueueInfo->ReceiveDpc = NICAllocReceiveDpc(Adapter, ProcNumber.Number, ProcNumber.Group, QueueId);
if(!QueueInfo->ReceiveDpc)
{
//
// Could not allocate DPC
//
Status = NDIS_STATUS_RESOURCES;
DEBUGP(MP_ERROR, "[%p] Could not allocate receive DPC for Queue %i\n", Adapter, QueueId);
break;
}
}
else
{
//
// No configuration specified, use this is the default queue so use default DPC
//
QueueInfo->ReceiveDpc = NICGetDefaultReceiveDpc(Adapter, QueueId);
}
//
// Initialize the receive block for the specified queue
//
Status = NICInitializeReceiveBlock(Adapter, QueueId);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] Could not initialize receive block for Queue %i\n", Adapter, QueueId);
break;
}
//
// Mark the Queue as initialized. It will not be used for receives until it is marked as completed.
//
QUEUE_SET_FLAG(QueueInfo, fMPAQI_INITIALIZED);
} while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- InitializeAdapterQueueInfo Status 0x%08x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
AllocateRxQueue(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ PNDIS_RECEIVE_QUEUE_PARAMETERS QueueParams
)
/*++
Routine Description:
This routine will allocate the corresponding queue in the passed in QueueParams,
and persist any relevant configuration from the request.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
QueueParams - Pointer to the queue allocation parameters
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER_VMQ_DATA VMQData = &Adapter->VMQData;
PMP_ADAPTER_QUEUE QueueInfo = &VMQData->RxQueues[QueueParams->QueueId];
LOCK_STATE_EX LockState;
BOOLEAN ReleaseLock = FALSE;
DEBUGP(MP_TRACE, "[%p] ---> AllocateRxQueue\n", Adapter);
do
{
//
// Verify queue is within the range of supported queues, and that it has not already
// been allocated
//
if(QueueParams->QueueId>=NIC_SUPPORTED_NUM_QUEUES)
{
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
//
// Synchronize assigning of allocated memory
//
NdisAcquireRWLockWrite(VMQData->RxQueues[QueueParams->QueueId].QueueLock, &LockState, 0);
ReleaseLock = TRUE;
if(QUEUE_INITIALIZED(QueueInfo))
{
//
// For this sample, changes are not supported. To support changes check whether
// Flags&NDIS_RECEIVE_QUEUE_PARAMETERS_CHANGE_MASK != 0. The
// NDIS_RECEIVE_QUEUE_PARAMETERS_*_CHANGED flags can be checked against
// to determine which fields are being updated, and apply those changes.
//
DEBUGP(MP_ERROR, "[%p] Queue %i already allocated, failing request.\n", Adapter, QueueParams->QueueId);
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
else if(QUEUE_FREEING(QueueInfo))
{
DEBUGP(MP_ERROR, "[%p] Queue %i is in the process of being freed (RefCount of %i).\n", Adapter, QueueParams->QueueId, RECEIVE_BLOCK_REFERENCE_COUNT(Adapter, QueueParams->QueueId));
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
//
// Initialize the queue information
//
Status = InitializeAdapterQueueInfo(Adapter, QueueParams, QueueInfo);
} while(FALSE);
if(ReleaseLock)
{
NdisReleaseRWLock(VMQData->RxQueues[QueueParams->QueueId].QueueLock, &LockState);
}
DEBUGP(MP_TRACE, "[%p] <--- AllocateRxQueue Status 0x%08x\n", Adapter, Status);
return Status;
}
VOID
FreeQueueReceiveSharedMemory(
_In_ PMP_ADAPTER Adapter,
ULONG EntryCount,
_In_reads_bytes_(EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)) PUCHAR MemoryBlock,
PLIST_ENTRY AllocationList)
/*++
Routine Description:
This routine frees up the passed in receive shared and tracking memory.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
EntryCount - Number of memory block entries
MemoryBlock - MP_ADAPTER_SHARED_MEMORY_BLOCK memory allocated to track shared memory
AllocationList - List of PMP_ADAPTER_SHARED_MEMORY allocations that build up the total amount of shared memory available for receive
Return Value:
VOID
--*/
{
ULONG BlockIndex;
PLIST_ENTRY CurrentAllocation;
DEBUGP(MP_TRACE, "[%p] ---> FreeQueueReceiveSharedMemory.\n", Adapter);
if(MemoryBlock)
{
//
// Free the MDLs for the shared memory blocks
//
for(BlockIndex = 0; BlockIndex < EntryCount; ++BlockIndex)
{
PMP_ADAPTER_SHARED_MEMORY_BLOCK SMBlock = ((PMP_ADAPTER_SHARED_MEMORY_BLOCK)MemoryBlock)+BlockIndex;
#pragma prefast(suppress: 6001, "PREfast doees not believe the MDL is initialized.")
NdisFreeMdl(SMBlock->Mdl);
}
//
// Free the tracking buffers
//
NdisFreeMemory(MemoryBlock, EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK), 0);
}
//
// Free the shared memory
//
for(CurrentAllocation = RemoveTailList(AllocationList);
CurrentAllocation != AllocationList;
CurrentAllocation = RemoveTailList(AllocationList))
{
PMP_ADAPTER_SHARED_MEMORY CurrentSharedMemory = CONTAINING_RECORD(CurrentAllocation, MP_ADAPTER_SHARED_MEMORY, Entry);
NdisFreeSharedMemory(Adapter->AdapterHandle, CurrentSharedMemory->AllocationHandle);
NdisFreeMemory(CurrentSharedMemory, sizeof(MP_ADAPTER_SHARED_MEMORY), 0);
}
DEBUGP(MP_TRACE, "[%p] <--- FreeQueueReceiveSharedMemory.\n", Adapter);
}
VOID
FreeRxQueueReceiveMemory(
_Inout_ PMP_ADAPTER Adapter,
PMP_ADAPTER_QUEUE QueueInfo)
/*++
Routine Description:
This routine frees up any receive shared memory and tracking memory allocated for this queue.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
QueueInfo - Pointer to shared memory owner queue
Return Value:
VOID
--*/
{
DEBUGP(MP_TRACE, "[%p] ---> FreeRxQueueReceiveMemory. QueueId: %i\n", Adapter, QueueInfo->QueueId);
//
// Free lookahead memory and clear values
//
FreeQueueReceiveSharedMemory(
Adapter,
QueueInfo->NumPostLookaheadBlocks,
QueueInfo->PostLookaheadBlocks,
&QueueInfo->PostLookaheadSharedMemoryList);
QueueInfo->PostLookaheadBlocks = NULL;
QueueInfo->NumPostLookaheadBlocks = 0;
//
// Free postlookahead memory and clear values
//
FreeQueueReceiveSharedMemory(
Adapter,
QueueInfo->NumLookaheadBlocks,
QueueInfo->LookaheadBlocks,
&QueueInfo->LookaheadSharedMemoryList);
QueueInfo->LookaheadBlocks = NULL;
QueueInfo->NumLookaheadBlocks = 0;
DEBUGP(MP_TRACE, "[%p] <--- FreeRxQueueReceiveMemory.\n", Adapter);
}
NDIS_STATUS
AssociateSharedMemoryAndBlocks(
_Inout_ struct _MP_ADAPTER *Adapter,
ULONG EntryCount,
ULONG EntrySize,
ULONG OffsetSize,
_In_ PLIST_ENTRY AllocationList,
_In_reads_bytes_(EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)) PUCHAR MemoryBlock)
/*++
Routine Description:
This routine populates each MP_ADAPTER_SHARED_MEMORY_BLOCK entry with its corresponding shared memory allocation.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
EntryCount - Number of memory block entries
EntrySize - Unaligned size of each shared memory entry (the actual size is aligned up to a memory aligned size)
OffsetSize - If this is a postlookahead buffer, this is the offset from the start of the buffer that must be left for lookahead
AllocationList - List of PMP_ADAPTER_SHARED_MEMORY allocations that build up the total amount of shared memory available for receive
MemoryBlock - MP_ADAPTER_SHARED_MEMORY_BLOCK memory allocated to track shared memory
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
DEBUGP(MP_TRACE, "[%p] ---> AssociateSharedMemoryAndBlocks.\n", Adapter);
do
{
ULONG BlockIndex, AllocationIndex, AlignedEntrySize = ALIGN_UP_BY(EntrySize, NdisGetSharedDataAlignment());
PLIST_ENTRY CurrentAllocation = AllocationList->Flink;
PMP_ADAPTER_SHARED_MEMORY CurrentSharedMemory;
//
// We should have at least one allocation
//
ASSERT(CurrentAllocation != AllocationList);
CurrentSharedMemory = CONTAINING_RECORD(CurrentAllocation, MP_ADAPTER_SHARED_MEMORY, Entry);
//
// Populate the shared memory tracking blocks with the necessary information (MDL, NET_BUFFER_SHARED_MEM macros)
//
for(BlockIndex = 0, AllocationIndex = 0; BlockIndex < EntryCount; ++BlockIndex, ++AllocationIndex)
{
PMP_ADAPTER_SHARED_MEMORY_BLOCK CurrentBlock = (PMP_ADAPTER_SHARED_MEMORY_BLOCK)((MemoryBlock) + (BlockIndex*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)));
//
// Find the next free shared memory buffer
//
if(AllocationIndex >= CurrentSharedMemory->NumberOfEntries)
{
//
// We've exhausted the current shared memory allocation, need to index off of the next one
//
CurrentAllocation = CurrentAllocation->Flink;
ASSERT(CurrentAllocation != AllocationList);
AllocationIndex = 0;
CurrentSharedMemory = CONTAINING_RECORD(CurrentAllocation, MP_ADAPTER_SHARED_MEMORY, Entry);
}
CurrentBlock->Buffer = CurrentSharedMemory->Buffer+(AllocationIndex*AlignedEntrySize);
//
// Sanity check that the pointer is cache aligned
//
ASSERT(((ULONG_PTR)CurrentBlock->Buffer)%NdisGetSharedDataAlignment() == 0);
//
// Allocate the MDL
//
CurrentBlock->Mdl = NdisAllocateMdl(Adapter->AdapterHandle,
CurrentBlock->Buffer + OffsetSize,
EntrySize - OffsetSize);
if(!CurrentBlock->Mdl)
{
DEBUGP(MP_ERROR, "[%p] Failed to allocate shared memory MDL.\n", Adapter);
Status = NDIS_STATUS_RESOURCES;
break;
}
//
// Populate the NET_BUFFER_SHARED_MEMORY information
//
NET_BUFFER_SHARED_MEM_HANDLE(&CurrentBlock->BufferSharedMemoryData) = CurrentSharedMemory->MemoryHandle;
NET_BUFFER_SHARED_MEM_LENGTH(&CurrentBlock->BufferSharedMemoryData) = EntrySize - OffsetSize;
NET_BUFFER_SHARED_MEM_OFFSET(&CurrentBlock->BufferSharedMemoryData) = (ULONG)((CurrentBlock->Buffer + OffsetSize) - CurrentSharedMemory->Buffer);
//
// For now clear next segment field. If lookahead and postlookahead are allocated, the segment and MDLs are linked once allocation is complete
//
NET_BUFFER_SHARED_MEM_NEXT_SEGMENT(&CurrentBlock->BufferSharedMemoryData) = NULL;
}
} while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- AssociateSharedMemoryAndBlocks. Status=0x%x\n", Adapter, Status);
return Status;
}
VOID
ChainMemoryBlocks(
ULONG EntryCount,
_In_reads_bytes_(EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)) PUCHAR LookaheadBlock,
_In_reads_bytes_(EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK))PUCHAR PostLookaheadBlock)
/*++
Routine Description:
This routine steps through each entry in the lookahead and postlookahead memory blocks and sets up their
relationship by linking pointing the lookahead's MDL and NET_BUFFER_SHARED_MEM next fields to the postlookahead.
Arguments:
EntryCount - Number of entris to step through in the memory block
LookaheadBlock - Lookahead tracking memory block
PostLookaheadBlock - Postlookahead tracking memory block
Return Value:
VOID
--*/
{
ULONG BlockIndex;
ASSERT(LookaheadBlock);
for(BlockIndex = 0; BlockIndex < EntryCount; ++BlockIndex)
{
PMP_ADAPTER_SHARED_MEMORY_BLOCK CurrentLookaheadBlock = (PMP_ADAPTER_SHARED_MEMORY_BLOCK)((LookaheadBlock) + (BlockIndex*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)));
PMP_ADAPTER_SHARED_MEMORY_BLOCK CurrentPostLookaheadBlock = (PMP_ADAPTER_SHARED_MEMORY_BLOCK)((PostLookaheadBlock) + (BlockIndex*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)));
//
// link MDLs
//
CurrentLookaheadBlock->Mdl->Next = CurrentPostLookaheadBlock->Mdl;
//
// link shared memory info so that lookahead points to the postlookahead block
//
NET_BUFFER_SHARED_MEM_NEXT_SEGMENT(&CurrentLookaheadBlock->BufferSharedMemoryData) = &CurrentPostLookaheadBlock->BufferSharedMemoryData;
}
}
_Success_(return == NDIS_STATUS_SUCCESS)
NDIS_STATUS
AllocateSharedMemory(
_In_ PMP_ADAPTER Adapter,
NDIS_RECEIVE_QUEUE_ID QueueId,
NDIS_SHARED_MEMORY_USAGE Usage,
ULONG BlockSize,
_Out_ PNDIS_HANDLE AllocationHandle,
_Out_ PNDIS_HANDLE MemoryHandle,
_Outptr_result_bytebuffer_(BlockSize) PUCHAR *SharedBuffer
)
/*++
Routine Description:
This routine allocates shared memory for the specified QueueId (the default queue is not valid here,
since no shared memory is used). This should be called through AllocateRxSharedMemory, to get failure recovery.
Runs at IRQL = PASSIVE_LEVEL.
Arguments:
Adapter - Pointer to our adapter
QueueId - QueueId owning the shared memory
Usage - Usage of the shared memory (lookahead, postlookahead, receive)
BlockSize - Size of the block to allocate
AllocationHandle - Receives the Allocation handle returned from NdisAllocateSharedMemory
MemoryHandle - Receives the Memory handle returned from NdisAllocateSharedMemory
SharedBuffer - Receives the allocated shared memory
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
NDIS_SHARED_MEMORY_PARAMETERS MemoryParams;
PSCATTER_GATHER_LIST SGListBuffer = NULL;
ULONG SGListSize, SGListNumElements;
DEBUGP(MP_TRACE, "[%p] ---> AllocateSharedMemory\n", Adapter);
*MemoryHandle = NULL;
*SharedBuffer = NULL;
do
{
//
// Build the scatter gather list
//
//
// Calculate the number of pages that would be necessary for the specified block size.
//
SGListNumElements = BYTES_TO_PAGES(BlockSize);
//
// Allocate gather list elements to hold information for each of these pages.
//
SGListSize = sizeof(SCATTER_GATHER_LIST) + sizeof(SCATTER_GATHER_ELEMENT) * SGListNumElements;
SGListBuffer = NdisAllocateMemoryWithTagPriority(NdisDriverHandle,
SGListSize,
NIC_TAG_QUEUE_SG_LIST,
NormalPoolPriority);
if(SGListBuffer == NULL)
{
DEBUGP(MP_ERROR, "Failed to allocate scatter gather memory.\n");
Status = NDIS_STATUS_RESOURCES;
break;
}
SGListBuffer->NumberOfElements = SGListNumElements;
//
// Prepare the shared memory parameters to be passed in to the NDIS allocation function
//
NdisZeroMemory(&MemoryParams, sizeof(NDIS_SHARED_MEMORY_PARAMETERS));
MemoryParams.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
MemoryParams.Header.Revision = NDIS_SHARED_MEMORY_PARAMETERS_REVISION_1;
MemoryParams.Header.Size = NDIS_SIZEOF_SHARED_MEMORY_PARAMETERS_REVISION_1;
//
// Memory characteristics
//
MemoryParams.Length = BlockSize;
MemoryParams.QueueId = QueueId;
MemoryParams.Usage = Usage;
//
// Scatter gather buffer
//
MemoryParams.SGListBufferLength = SGListSize;
MemoryParams.SGListBuffer = SGListBuffer;
//
// Allocate the memory
//
Status = NdisAllocateSharedMemory(Adapter->AdapterHandle,
&MemoryParams,
AllocationHandle);
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] NdisAllocateSharedMemory failed Status 0x%x.\n", Adapter, Status);
break;
}
//
// Set the buffer to return
//
*SharedBuffer = MemoryParams.VirtualAddress;
*MemoryHandle = MemoryParams.SharedMemoryHandle;
NdisZeroMemory(*SharedBuffer, BlockSize);
} while(FALSE);
if(SGListBuffer)
{
//
// This virtual miniport does not actually do DMA, so no need to preserve the SG information
//
NdisFreeMemoryWithTagPriority(NdisDriverHandle, SGListBuffer, NIC_TAG_QUEUE_SG_LIST);
}
DEBUGP(MP_TRACE, "[%p] <--- AllocateSharedMemory. Status=0x%x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
AllocateRxSharedMemory(
_In_ PMP_ADAPTER Adapter,
NDIS_RECEIVE_QUEUE_ID QueueId,
NDIS_SHARED_MEMORY_USAGE Usage,
_Inout_ ULONG *EntryCount,
ULONG EntrySize,
ULONG OffsetSize,
_In_ PLIST_ENTRY AllocationList,
_Outptr_result_bytebuffer_(*EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)) PUCHAR *MemoryBlock
)
/*++
Routine Description:
This routine wraps the call to AllocateSharedMemory providing failover if the allocation fails. If the original
requested number of entries fails to allocate, we try to allocate the same buffer size in smaller chunks.
Runs at IRQL APC_PASSIVE
Arguments:
Adapter - Pointer to our adapter
QueueId - QueueId owning the shared memory
Usage - Usage of the shared memory (lookahead, postlookahead, receive)
EntryCount - Number of Entries worth of shared memory to allocate
EntrySize - Size of each entry
AllocationList - LIST_ENTRY to receive all blocks allocated (MP_ADAPTER_SHARED_MEMORY)
MemoryBlock - Receives allocated and populated MP_ADAPTER_SHARED_MEMORY_BLOCK buffer with bookkeeping data on shared memory
Return Value:
NDIS_STATUS
On failure, caller needs to call FreeRxQueueReceiveMemory to free any allocations made during the function
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
DEBUGP(MP_TRACE, "[%p] ---> AllocateRxSharedMemory.\n", Adapter);
do
{
ULONG AllocatedEntryCount = 0, CurAllocationTarget = *EntryCount;
//
// Make sure the entry size results in cache aligned segments
//
ULONG AlignedEntrySize = ALIGN_UP_BY(EntrySize, NdisGetSharedDataAlignment());
PMP_ADAPTER_SHARED_MEMORY CurMemory = NULL;
while(AllocatedEntryCount < *EntryCount)
{
//
// Entry size will be cache aligned, allocate enough memory so that we can be sure the entries start at
// a cache boundary
//
ULONG TotalAllocationSize = (CurAllocationTarget*AlignedEntrySize) + NdisGetSharedDataAlignment();
if(!CurMemory)
{
//
// Allocate MP_ADAPTER_SHARED_MEMORY we use to track this particular allocation
//
CurMemory = NdisAllocateMemoryWithTagPriority(NdisDriverHandle,
sizeof(MP_ADAPTER_SHARED_MEMORY),
NIC_TAG_QUEUE_SHARED_MEM,
NormalPoolPriority);
if(!CurMemory)
{
break;
}
NdisZeroMemory(CurMemory, sizeof(MP_ADAPTER_SHARED_MEMORY));
}
//
// Attempt to allocate shared memory block of (EntryCount * EntrySize) size
//
Status = AllocateSharedMemory(Adapter,
QueueId,
Usage,
TotalAllocationSize,
&CurMemory->AllocationHandle,
&CurMemory->MemoryHandle,
&CurMemory->Buffer);
if(Status != NDIS_STATUS_SUCCESS)
{
//
// Allocation failed, lets try multiple smaller allocation
//
CurAllocationTarget /= 2;
if(CurAllocationTarget >= NIC_MIN_RECV_ENTRY_ALLOCATION_COUNT)
{
DEBUGP(MP_ERROR, "[%p] AllocateSharedMemory failed, will attempt to allocate %i units of memory.\n", Adapter, CurAllocationTarget);
}
else
{
DEBUGP(MP_ERROR, "[%p] AllocateSharedMemory failed, reached minimum allocation size. Failing allocation. \n", Adapter);
NdisFreeMemory(CurMemory, sizeof(MP_ADAPTER_SHARED_MEMORY), 0);
CurMemory = NULL;
break;
}
}
else
{
//
// Move base buffer pointer up to a cache aligned boundary
//
CurMemory->Buffer = ALIGN_UP_POINTER_BY(CurMemory->Buffer, NdisGetSharedDataAlignment());
//
// Store away successful allocation
//
CurMemory->EntrySize = AlignedEntrySize;
CurMemory->NumberOfEntries = CurAllocationTarget;
AllocatedEntryCount += CurAllocationTarget;
InsertTailList(AllocationList, &CurMemory->Entry);
CurMemory = NULL;
}
}
//
// Verify that we were at least able to allocate up to our minimum number of receive blocks. If not, then we fail the
// allocation altogether.
//
if(AllocatedEntryCount<NIC_MIN_BUSY_RECVS)
{
Status = NDIS_STATUS_RESOURCES;
break;
}
//
// Now that the shared memory buffers have been allocated, we need to split them into
// individual MP_ADAPTER_SHARED_MEMORY_BLOCK items used for tracking the memory in NB
//
//
// Allocate the necessary MP_ADAPTER_SHARED_MEMORY_BLOCK items to track the shared memory
//
*MemoryBlock = NdisAllocateMemoryWithTagPriority(
NdisDriverHandle,
AllocatedEntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK),
NIC_TAG_QUEUE_SHARED_MEM_BLOCK,
NormalPoolPriority);
if(!*MemoryBlock)
{
DEBUGP(MP_ERROR, "[%p] NdisAllocateMemoryWithTagPriority for shared memory block failed.\n", Adapter);
Status = NDIS_STATUS_RESOURCES;
break;
}
NdisZeroMemory(*MemoryBlock, AllocatedEntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK));
//
// Associate each ADAPTER_SHARED_MEMOR_BLOCK entry with their corresponding ADAPTER_SHARED_MEMORY buffer segment.
//
Status = AssociateSharedMemoryAndBlocks(
Adapter,
*EntryCount,
EntrySize,
OffsetSize,
AllocationList,
*MemoryBlock);
}while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- AllocateRxSharedMemory. Status=0x%x\n", Adapter, Status);
return Status;
}
VOID
AssociateSharedMemoryAndRCBs(
_In_ ULONG QueueId,
_In_reads_bytes_opt_(EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)) PUCHAR LookaheadBlock,
_In_reads_bytes_(EntryCount*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)) PUCHAR PostLookaheadBlock,
_In_reads_bytes_(EntryCount*sizeof(RCB)) PUCHAR RcbMemoryBlock,
ULONG EntryCount)
/*++
Routine Description:
This routine associates populates the fields in each RCB with its corresponding shared memory information
contained in the lookahead and postlookahead memory block. Once this function runs, each RCB is ready to
be used for receives (all that needs to happen on receive is to copy the receive data to the lookahead and
postlookahead memory locations for each RCB).
Arguments:
QueueId - ID of the queue which owns the various pieces of memory
LookaheadBlock - Lookahead shared memory tracking blocks (can be NULL if no lookahead)
PostLookaheadBlock - Postlookahead shared memory tracking blocks
RcbMemoryBlock - RCB memory blocks
Return Value:
VOID
--*/
{
ULONG BlockIndex;
for(BlockIndex = 0; BlockIndex < EntryCount; ++BlockIndex)
{
//
// Populate the RCB NBLs with the queue's shared memory.
//
PRCB Rcb = (PRCB)(RcbMemoryBlock+(BlockIndex*sizeof(RCB)));
PNET_BUFFER NetBuffer = NET_BUFFER_LIST_FIRST_NB(Rcb->Nbl);
PMP_ADAPTER_SHARED_MEMORY_BLOCK CurrentPostLookaheadBlock = (PMP_ADAPTER_SHARED_MEMORY_BLOCK)((PostLookaheadBlock) + (BlockIndex*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)));
Rcb->Data = CurrentPostLookaheadBlock;
if(LookaheadBlock)
{
PMP_ADAPTER_SHARED_MEMORY_BLOCK CurrentLookaheadBlock = (PMP_ADAPTER_SHARED_MEMORY_BLOCK)((LookaheadBlock) + (BlockIndex*sizeof(MP_ADAPTER_SHARED_MEMORY_BLOCK)));
Rcb->LookaheadData = CurrentLookaheadBlock;
//
// Set the shared memory and MDL information
//
NET_BUFFER_FIRST_SHARED_MEM_INFO(NetBuffer) = &CurrentLookaheadBlock->BufferSharedMemoryData;
NET_BUFFER_FIRST_MDL(NetBuffer) = CurrentLookaheadBlock->Mdl;
}
else
{
//
// Set the shared memory and MDL information
//
NET_BUFFER_FIRST_SHARED_MEM_INFO(NetBuffer) = &CurrentPostLookaheadBlock->BufferSharedMemoryData;
NET_BUFFER_FIRST_MDL(NetBuffer) = CurrentPostLookaheadBlock->Mdl;
}
//
// Set the remaining NBL fields
//
NET_BUFFER_DATA_OFFSET(NetBuffer) = 0;
NET_BUFFER_CURRENT_MDL(NetBuffer) = NET_BUFFER_FIRST_MDL(NetBuffer);
NET_BUFFER_CURRENT_MDL_OFFSET(NetBuffer) = 0;
NET_BUFFER_LIST_RECEIVE_QUEUE_ID(Rcb->Nbl) = (USHORT)QueueId;
NET_BUFFER_LIST_RECEIVE_FILTER_ID(Rcb->Nbl) = 0;
}
}
NDIS_STATUS
AllocateRxQueueReceiveMemory(
_Inout_ struct _MP_ADAPTER *Adapter,
PMP_ADAPTER_QUEUE QueueInfo)
/*++
Routine Description:
This routine allocates the necessary receive memory for the specified Queue.
Runs at IRQL APC_PASSIVE
Arguments:
Adapter - Pointer to our adapter
Queue - Queue to allocate
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
do
{
NDIS_SHARED_MEMORY_USAGE postMemoryUsage = NdisSharedMemoryUsageReceive;
//
// Queue should already be initialized
//
if(!QUEUE_INITIALIZED(QueueInfo))
{
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
if(QueueInfo->NumSuggestedReceiveBuffers)
{
//
// If the number of receive buffers has been passed down for the queue, then we will allocate that suggested amount (as long as it's not below our minimum required amount of receive buffers),
// otherwise we use our minimum.
//
QueueInfo->NumReceiveBuffers = max(QueueInfo->NumSuggestedReceiveBuffers, NIC_MIN_BUSY_RECVS);
}
else
{
//
// No suggested receive buffer count was set for the queue, so we our preferred maximum amount
//
QueueInfo->NumReceiveBuffers = NIC_MAX_BUSY_RECVS;
}
//
// Initialize the shared memory allocation tracking lists
//
InitializeListHead(&QueueInfo->LookaheadSharedMemoryList);
InitializeListHead(&QueueInfo->PostLookaheadSharedMemoryList);
//
// Initialize list and lock of the free Rcb list
//
NdisInitializeListHead(&QueueInfo->FreeRcbList);
NdisAllocateSpinLock(&QueueInfo->FreeRcbListLock);
//
// In our implementation receive memory is only necessary for non-default queues. For default queue
// we reuse the Frame copy made during send.
//
if(QueueInfo->QueueId)
{
ULONG LookaheadSize=0, PostLookaheadSize=HW_MAX_FRAME_SIZE;
if(LOOKAHEAD_SPLIT_REQUIRED(QueueInfo))
{
ASSERT(QueueInfo->LookaheadSize);
LookaheadSize = QueueInfo->LookaheadSize;
}
//
// Allocate the shared memory that will be used to receive on this non-default queue.
//
if(LookaheadSize)
{
//
// Lookahead memory
//
Status = AllocateRxSharedMemory(
Adapter,
QueueInfo->QueueId,
NdisSharedMemoryUsageReceiveLookahead,
&QueueInfo->NumReceiveBuffers,
LookaheadSize,
0,
&QueueInfo->LookaheadSharedMemoryList,
&QueueInfo->LookaheadBlocks);
if(Status != NDIS_STATUS_SUCCESS)
{
break;
}
QueueInfo->NumLookaheadBlocks = QueueInfo->NumReceiveBuffers;
//
// We're doing lookahead split, so the usage for the Postlookahead needs to be
// explicitly postlookahead.
//
postMemoryUsage = NdisSharedMemoryUsageReceivePostLookahead;
}
//
// Allocate postlookahead memory
//
Status = AllocateRxSharedMemory(
Adapter,
QueueInfo->QueueId,
postMemoryUsage,
&QueueInfo->NumReceiveBuffers,
PostLookaheadSize,
LookaheadSize,
&QueueInfo->PostLookaheadSharedMemoryList,
&QueueInfo->PostLookaheadBlocks);
if(Status != NDIS_STATUS_SUCCESS)
{
break;
}
QueueInfo->NumPostLookaheadBlocks = QueueInfo->NumReceiveBuffers;
if(LookaheadSize)
{
//
// Now that we have both lookahead and post-lookahead allocated we need to chain
// a few of their fields together
//
ChainMemoryBlocks(
QueueInfo->NumReceiveBuffers,
QueueInfo->LookaheadBlocks,
QueueInfo->PostLookaheadBlocks);
}
}
//
// To finalize the allocation, we need to allocate the RCB & NBL blocks used for receive, and populated them
// with the appropriate shared memory data (if non-default queue).
//
//
// Ready to allocate the RCB blocks
//
Status = NICAllocRCBData(
Adapter,
QueueInfo->NumReceiveBuffers,
&QueueInfo->RcbMemoryBlock,
&QueueInfo->FreeRcbList,
&QueueInfo->FreeRcbListLock,
&QueueInfo->RecvNblPoolHandle
);
if(QueueInfo->QueueId && Status == NDIS_STATUS_SUCCESS)
{
//
// Populate the RCB NBLs with the queue's shared memory.
//
AssociateSharedMemoryAndRCBs(
QueueInfo->QueueId,
QueueInfo->LookaheadBlocks,
QueueInfo->PostLookaheadBlocks,
QueueInfo->RcbMemoryBlock,
QueueInfo->NumReceiveBuffers);
}
//
// At this point, all that is left to do on receive is for the shared memory to get populated with real frame data (e.g. DMA), and set the frame length.
// This avoids any expensive allocations on receive.
//
}while(FALSE);
if(Status != NDIS_STATUS_SUCCESS && QUEUE_INITIALIZED(QueueInfo))
{
//
// Cleanup any left over allocated receive resources from this function
//
FreeRxQueueReceiveMemory(Adapter, QueueInfo);
}
DEBUGP(MP_TRACE, "[%p] <--- AllocateRxQueueReceiveMemory. Status=0x%x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
CompleteAllocationRxQueue(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ PNDIS_RECEIVE_QUEUE_ALLOCATION_COMPLETE_ARRAY CompleteArray
)
/*++
Routine Description:
This routine will complete the process of queue allocation, allocating shared mmemory and
flagging queues as complete. Once a Queue is complete, receive indications can begin on it.
Runs at IRQL APC_PASSIVE
Arguments:
Adapter - Pointer to our Adapter
CompleteArray - Pointer to the complete allocation parameters
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER_VMQ_DATA VMQData = &Adapter->VMQData;
PNDIS_RECEIVE_QUEUE_ALLOCATION_COMPLETE_PARAMETERS CompleteParamArray = (PNDIS_RECEIVE_QUEUE_ALLOCATION_COMPLETE_PARAMETERS)((PUCHAR)CompleteArray + CompleteArray->FirstElementOffset);
ULONG index;
LOCK_STATE_EX LockState;
DEBUGP(MP_TRACE, "[%p] ---> CompleteAllocationRxQueue\n", Adapter);
//
// Iterate through each complete entry in the parameter array
//
for (index=0; index<CompleteArray->NumElements; index++)
{
PMP_ADAPTER_QUEUE CurrentQueue;
if(CompleteParamArray[index].QueueId >= NIC_SUPPORTED_NUM_QUEUES)
{
//
// Queue out of range
//
CompleteParamArray[index].CompletionStatus = NDIS_STATUS_INVALID_PARAMETER;
continue;
}
//
// Verify that the queue is initialized, and not already being completed (or complete)
//
//
// Synchronize access to queue status
//
CurrentQueue = &VMQData->RxQueues[CompleteParamArray[index].QueueId];
NdisAcquireRWLockWrite(CurrentQueue->QueueLock, &LockState, 0);
if(!QUEUE_INITIALIZED(CurrentQueue) ||
QUEUE_COMPLETING(CurrentQueue) ||
QUEUE_FREEING(CurrentQueue))
{
//
// Queue should have already been initialized, and should not be already completed or freed.
//
DEBUGP(MP_ERROR, "[%p] Queue %i does not have the correct status for completion (QueueInfoFlags: 0x%x).\n", Adapter, CompleteParamArray[index].QueueId, CurrentQueue->QueueInfoFlags);
CompleteParamArray[index].CompletionStatus = NDIS_STATUS_INVALID_PARAMETER;
NdisReleaseRWLock(CurrentQueue->QueueLock, &LockState);
continue;
}
//
// Mark that completion has started for the queue
//
QUEUE_SET_FLAG(CurrentQueue, fMPAQI_COMPLETION_STARTED);
NdisReleaseRWLock(CurrentQueue->QueueLock, &LockState);
Status = AllocateRxQueueReceiveMemory(Adapter, CurrentQueue);
CompleteParamArray[index].CompletionStatus = Status;
if(Status != NDIS_STATUS_SUCCESS)
{
DEBUGP(MP_ERROR, "[%p] Failed while allocating receive memory for Queue %i\n", Adapter, CompleteParamArray[index].QueueId);
QUEUE_CLEAR_FLAG(CurrentQueue,fMPAQI_COMPLETION_STARTED);
continue;
}
//
// Completion done. Update queue status in a synchronized block.
//
NdisAcquireRWLockWrite(CurrentQueue->QueueLock, &LockState, 0);
QUEUE_SET_FLAG(CurrentQueue,fMPAQI_COMPLETION_FINISHED);
NdisReleaseRWLock(CurrentQueue->QueueLock, &LockState);
}
DEBUGP(MP_TRACE, "[%p] <--- CompleteAllocationRxQueue Status 0x%08x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
UpdateRxQueue(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ PNDIS_RECEIVE_QUEUE_PARAMETERS QueueParams
)
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
NDIS_RECEIVE_QUEUE_ID QueueId = QueueParams->QueueId;
PMP_ADAPTER_QUEUE QueueInfo;
DEBUGP(MP_TRACE, "[%p] ---> UpdateRxQueue\n", Adapter);
do
{
if(QueueId >= NIC_SUPPORTED_NUM_QUEUES)
{
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
QueueInfo = &Adapter->VMQData.RxQueues[QueueId];
if(QueueParams->Flags&NDIS_RECEIVE_QUEUE_PARAMETERS_CHANGE_MASK)
{
if (QueueParams->Flags & NDIS_RECEIVE_QUEUE_PARAMETERS_PROCESSOR_AFFINITY_CHANGED)
{
//
// Change the owner DPC
//
PMP_ADAPTER_RECEIVE_DPC NewDpc;
PROCESSOR_NUMBER ProcNumber = {0};
if(!ValidGroupAffinity(&QueueParams->ProcessorAffinity))
{
DEBUGP(MP_ERROR, "[%p] Requested group affinity failed validation\n", Adapter);
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
ProcNumber.Group = QueueParams->ProcessorAffinity.Group;
ProcNumber.Number = RtlFindLeastSignificantBit((ULONGLONG)QueueParams->ProcessorAffinity.Mask);
ASSERT(ProcNumber.Number != -1);
DEBUGP(MP_INFO, "[%p] Updating Queue Affinity Group: 0x%x, Number: 0x%x\n", Adapter, ProcNumber.Group, ProcNumber.Number);
//
// Get the new DPC with different affinity (if one already exists, will reuse it)
//
NewDpc = NICAllocReceiveDpc(Adapter, ProcNumber.Number, ProcNumber.Group, QueueId);
if(!NewDpc)
{
//
// Could not allocate DPC
//
Status = NDIS_STATUS_RESOURCES;
DEBUGP(MP_ERROR, "[%p] Could not allocate receive DPC for Queue %i, will keep original DPC\n", Adapter, QueueId);
break;
}
if(NewDpc != QueueInfo->ReceiveDpc)
{
//
// This is a new DPC for the queue, update the existing owner DPC and replace
//
NICReceiveDpcRemoveOwnership(QueueInfo->ReceiveDpc, QueueId);
//
// Store new DPC
//
QueueInfo->ReceiveDpc = NewDpc;
//
// Check whether there are any pending receives on the queue, if there are, then schedule the
// new DPC to make sure they are not lost
//
if(!IsListEmpty(&Adapter->ReceiveBlock[QueueId].ReceiveList))
{
DEBUGP(MP_INFO, "[%p] Receive Block %i: Receives were pending, queued new DPC.\n", Adapter, QueueId);
KeInsertQueueDpc(&QueueInfo->ReceiveDpc->Dpc, QueueInfo->ReceiveDpc, NULL);
}
}
}
if (QueueParams->Flags & NDIS_RECEIVE_QUEUE_PARAMETERS_FLAGS_CHANGED)
{
ULONG Flags = QueueParams->Flags & ~NDIS_RECEIVE_QUEUE_PARAMETERS_CHANGE_MASK;
DEBUGP(MP_INFO, "[%p] Updating Queue flags: 0x%x\n", Adapter, Flags);
if(Flags&NDIS_RECEIVE_QUEUE_PARAMETERS_LOOKAHEAD_SPLIT_REQUIRED
&& !LOOKAHEAD_SPLIT_REQUIRED(QueueInfo)
&& QUEUE_COMPLETE(QueueInfo))
{
//
// Our implementation does not support enabling lookahead after the queue is complete
// since our complete handler would not have allocated the lookahead memory.
//
DEBUGP(MP_ERROR, "[%p] Queue was already completed without lookahead split. Did not update flags. \n", Adapter);
Status = NDIS_STATUS_NOT_SUPPORTED;
break;
}
else
{
QueueInfo->NdisFlags = Flags;
}
}
if (QueueParams->Flags & NDIS_RECEIVE_QUEUE_PARAMETERS_SUGGESTED_RECV_BUFFER_NUMBERS_CHANGED)
{
DEBUGP(MP_INFO, "[%p] Updating Queue number of suggested receive buffers: %i\n", Adapter, QueueParams->NumSuggestedReceiveBuffers);
QueueInfo->NumSuggestedReceiveBuffers = QueueParams->NumSuggestedReceiveBuffers;
}
}
}while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- UpdateRxQueue Status 0x%08x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
FreeAdapterQueueInfo(
_In_ PMP_ADAPTER Adapter,
USHORT QueueId,
_In_opt_ PNDIS_OID_REQUEST NdisSetRequest)
/*++
Routine Description:
This routine will clean up the memory for the specified queue, and reset it to uninitialized. If the
queue still has active references on it (e.g. - still in use), the function does not clean up the queue
and instead returns NDIS_STATUS_PENDING. Callers should handle attempting the free at a later time.
Runs at IRQL = PASSIVE_LEVEL
Arguments:
Adapter - Pointer to our adapter
QueueId - Queue to free
NdisSetRequest - The OID for the free request (NULL if the call is not due to an OID request)
Return Value:
Void
--*/
{
LOCK_STATE_EX QueueLockState;
PMP_ADAPTER_QUEUE QueueInfo = &Adapter->VMQData.RxQueues[QueueId];
LONG ReferenceCount = 0;
BOOLEAN DmaInProgress;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PLIST_ENTRY Entry;
do
{
//
// Check (and possibly update) queue status in synchronized block
//
NdisAcquireRWLockWrite(QueueInfo->QueueLock, &QueueLockState, 0);
if(!QueueInfo->QueueInfoFlags)
{
//
// Queue has already been freed, no need to do anything.
//
Status = NDIS_STATUS_SUCCESS;
NdisReleaseRWLock(QueueInfo->QueueLock, &QueueLockState);
break;
}
//
// Reset the flags to "freeing". This way we will not accumulate any more receives on the queue.
//
QUEUE_SET_FLAG(QueueInfo,fMPAQI_FREEING);
//
// Make sure the freeing state set operation happens before the DMA in progress check
//
KeMemoryBarrier();
//
// Check whether the queue has a DMA in progress. This value check has to occur *after* we've updated
// the queue state to freeing. The receive code depends on this ordering of operations to avoid taking locks
// on its "DMA" path (see CopyFrameToRxQueue).
//
DmaInProgress = QUEUE_DMA_IN_PROGRESS(QueueInfo);
if(!DmaInProgress)
{
//
// There are no DMA's in progress. Update the flags of the queue to DMA stopped to avoid pending receive code
// from indicating DMA stopped state later. The indication to NDIS of this change happens outside of our synchronized
// block to avoid holding the lock for too long.
//
QUEUE_SET_FLAG(QueueInfo,fMPAQI_DMA_STOPPED);
}
//
// Get the reference count
//
ReferenceCount = RECEIVE_BLOCK_REFERENCE_COUNT(Adapter, QueueId);
if(ReferenceCount != 0)
{
//
// Still have outstanding usage of the queue, so we must pend the free request.
//
if(NdisSetRequest)
{
//
// Store the OID so that we can complete it later
//
SetPendingRxQueueFree(Adapter, NdisSetRequest);
}
else
{
//
// The queue free should only pend on OID request. If this free call came from halt or other operation,
// the queue should have been ready to free already, so check that we have a pending request.
//
ASSERT(Adapter->PendingRequest);
}
}
NdisReleaseRWLock(QueueInfo->QueueLock, &QueueLockState);
if(!DmaInProgress)
{
//
// There were no DMA's in progress when we updated that state to freeing, and no more DMA's will occur, so it's safe to indicate that queue DMA is stopped.
// Any pending receives that have already completed their copies will still be indicated.
//
IndicateRxQueue(
Adapter,
QueueId,
NdisReceiveQueueOperationalStateDmaStopped);
}
if(ReferenceCount != 0)
{
//
// Bail out of the free path. Once the ref count reaches zero on the queue and there are no in-progress DMA's, the queue will be freed and the OID will complete.
//
DEBUGP(MP_LOUD, "[%p] Queue %i has pending references (RefCount %i), returning NDIS_STATUS_PENDING for the free request.\n", Adapter, QueueId, ReferenceCount);
Status = NDIS_STATUS_PENDING;
break;
}
DEBUGP(MP_LOUD, "[%p] Queue %i has no outstanding references, queue memory has been freed.\n", Adapter, QueueId);
NICReceiveDpcRemoveOwnership(QueueInfo->ReceiveDpc, QueueId);
QueueInfo->ReceiveDpc = NULL;
//
// Free the RCB & NBL data
//
if(QueueInfo->FreeRcbList.Flink)
{
while (NULL != (Entry = NdisInterlockedRemoveHeadList(
&QueueInfo->FreeRcbList,
&QueueInfo->FreeRcbListLock)))
{
PRCB Rcb = CONTAINING_RECORD(Entry, RCB, RcbLink);
NdisFreeNetBufferList(Rcb->Nbl);
}
NdisFreeSpinLock(&QueueInfo->FreeRcbListLock);
}
if (QueueInfo->RecvNblPoolHandle)
{
NdisFreeNetBufferListPool(QueueInfo->RecvNblPoolHandle);
QueueInfo->RecvNblPoolHandle = NULL;
}
if (QueueInfo->RcbMemoryBlock)
{
NdisFreeMemory(
QueueInfo->RcbMemoryBlock,
sizeof(RCB)*QueueInfo->NumReceiveBuffers,
0);
QueueInfo->RcbMemoryBlock = NULL;
}
if(QUEUE_COMPLETE(QueueInfo))
{
FreeRxQueueReceiveMemory(
Adapter,
QueueInfo);
}
//
// Completed free, clear flags altogether
//
QueueInfo->QueueInfoFlags = 0;
if(Adapter->PendingRequest)
{
PNDIS_OID_REQUEST Request = Adapter->PendingRequest;
Adapter->PendingRequest = NULL;
NdisMOidRequestComplete(Adapter->AdapterHandle,
Request,
Status);
}
} while(FALSE);
return Status;
}
NDIS_STATUS
FreeRxQueue(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ PNDIS_RECEIVE_QUEUE_FREE_PARAMETERS QueueFreeParams,
_In_opt_ PNDIS_OID_REQUEST NdisSetRequest
)
/*++
Routine Description:
This routine will clean up the memory for the specified queue. Queue should already been indicated as DMA stopped
using IndicateRxQueue. Callers should handle attempting the free at a later time if NDIS_STATUS_PENDING is returned.
Runs at IRQL = PASSIVE_LEVEL
Arguments:
Adapter - Pointer to our adapter
QueueFreeParams - Pointer to the complete allocation parameters
NdisSetRequest - The OID for the free request (NULL if the call is not due to an OID request)
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
DEBUGP(MP_TRACE, "[%p] ---> FreeRxQueue\n", Adapter);
//
// Verify within valid range
//
if(QueueFreeParams->QueueId>=NIC_SUPPORTED_NUM_QUEUES)
{
Status = NDIS_STATUS_INVALID_PARAMETER;
}
else
{
//
// Attempt to free the queue (pending will be returned if queue still in use)
//
Status = FreeAdapterQueueInfo(Adapter, (USHORT)QueueFreeParams->QueueId, NdisSetRequest);
}
DEBUGP(MP_TRACE, "[%p] <--- FreeRxQueue Status 0x%08x\n", Adapter, Status);
return Status;
}
_Use_decl_annotations_
VOID
FreeRxQueuesWorkItem(
PVOID WorkItemContext,
NDIS_HANDLE NdisIoWorkItemHandle
)
/*++
Routine Description:
This routine retrieves the pending free request (there can only be one at a time), and frees the queue. The work item is used
when we pend a queue free OID (because the reference count is non-zero), and when the reference count is finally reduced to
zero we are not at PASSIVE_LEVEL.
Runs at IRQL = PASSIVE_LEVEL
Arguments:
WorkItemContext - Context for work item (PMP_ADAPTER)
NdisIoWorkItemHandle - Work item handle
Return Value:
None
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER Adapter;
PNDIS_OID_REQUEST Request;
Adapter = MP_ADAPTER_FROM_CONTEXT(WorkItemContext);
ASSERT(Adapter != NULL);
_Analysis_assume_(Adapter != NULL);
DEBUGP(MP_TRACE, "[%p] ---> FreeRxQueuesWorkItem\n", Adapter);
Request = Adapter->PendingRequest;
if(Request != NULL)
{
switch(Request->DATA.SET_INFORMATION.Oid)
{
case OID_RECEIVE_FILTER_FREE_QUEUE:
Status = FreeRxQueue(
Adapter,
(PNDIS_RECEIVE_QUEUE_FREE_PARAMETERS)Request->DATA.SET_INFORMATION.InformationBuffer,
NULL //OID should already be held in pending OID member of adapter
);
//
// Should only be called once reference count has reached zero, it should succeed
//
ASSERT(Status == NDIS_STATUS_SUCCESS);
break;
default:
ASSERT(!"Unsupported Set OID added to pending list");
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
}
NdisFreeIoWorkItem(NdisIoWorkItemHandle);
DEBUGP(MP_TRACE, "[%p] <-- FreeRxQueuesWorkItem. Status=0x%x\n", Adapter, Status);
}
VOID
FreeVMQData(
_Inout_ struct _MP_ADAPTER *Adapter)
/*++
Routine Description:
This routine will clean up the memory for all the queues in the passed in VMQData. It should only be called
when all pending receives have stopped (e.g. - miniport halt).
Runs at IRQL = PASSIVE_LEVEL
Arguments:
Adapter - Pointer to our adapter
Return Value:
NDIS_STATUS
--*/
{
USHORT index;
PMP_ADAPTER_VMQ_DATA VMQData = &Adapter->VMQData;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
for(index=0; index<NIC_SUPPORTED_NUM_QUEUES; index++)
{
if(VMQData->RxQueues[index].QueueLock != NULL)
{
#pragma warning( suppress: 28931 ) // unused assignment of variable Status OK in Fre build
Status = FreeAdapterQueueInfo(Adapter, index, NULL);
ASSERT(Status == NDIS_STATUS_SUCCESS);
NdisFreeRWLock(VMQData->RxQueues[index].QueueLock);
}
}
}
VOID
IndicateRxQueue(
_In_ PMP_ADAPTER Adapter,
NDIS_RECEIVE_QUEUE_ID QueueId,
NDIS_RECEIVE_QUEUE_OPERATIONAL_STATE State)
/*++
Routine Description:
This routine will indicate to NDIS the state of the queue.
Arguments:
Adapter - Pointer to our adapter
QueueId - Queue to indicate
State - Current state of Queue
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS_INDICATION Status;
NDIS_RECEIVE_QUEUE_STATE QueueState;
DEBUGP(MP_TRACE, "[%p] ---> IndicateRxQueue ID: %i, State: 0x%x\n", Adapter, QueueId, State);
NdisZeroMemory(&Status, sizeof(Status));
NdisZeroMemory(&QueueState, sizeof(QueueState));
QueueState.Header.Revision = NDIS_RECEIVE_QUEUE_STATE_REVISION_1;
QueueState.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
QueueState.Header.Size = NDIS_SIZEOF_NDIS_RECEIVE_QUEUE_STATE_REVISION_1;
QueueState.QueueId = QueueId;
QueueState.QueueState = State;
Status.Header.Type = NDIS_OBJECT_TYPE_STATUS_INDICATION;
Status.Header.Revision = NDIS_STATUS_INDICATION_REVISION_1;
Status.Header.Size = NDIS_SIZEOF_STATUS_INDICATION_REVISION_1;
Status.StatusCode = NDIS_STATUS_RECEIVE_QUEUE_STATE;
Status.StatusBuffer = &QueueState;
Status.StatusBufferSize = QueueState.Header.Size;
NdisMIndicateStatusEx(
Adapter->AdapterHandle,
&Status);
DEBUGP(MP_TRACE, "[%p] <--- IndicateRxQueue\n", Adapter);
}
BOOLEAN
IsSupportedRxFilter(
_In_ PMP_ADAPTER Adapter,
_In_ PNDIS_RECEIVE_FILTER_PARAMETERS FilterParams,
_In_ PNDIS_RECEIVE_FILTER_FIELD_PARAMETERS FilterCriteria)
/*++
Routine Description:
This routine will verify whether the filter is well formed and supported by this adapter.
Arguments:
Adapter - Pointer to our adapter
FilterParams - Filter Parameters
FilterCriteria - Filter Field Parameters
Return Value:
TRUE - filter is supported
FALSE - filter is not not
--*/
{
BOOLEAN Supported = TRUE;
ULONG index;
BOOLEAN VlanFilterPresent = FALSE, VlanUntaggedOrZeroFlagPresent = FALSE;
DEBUGP(MP_TRACE, "[%p] ---> IsSupportedRxFilter. FilterParams: QueueId: %i, FilterId: %i, Flags: 0x%x\n",
Adapter, FilterParams->QueueId, FilterParams->FilterId, FilterParams->Flags);
//
// Check all criteria for the filter
//
for(index = 0; index < FilterParams->FieldParametersArrayNumElements && Supported; index++)
{
DEBUGP(MP_TRACE, "[%p] FilterCriteris[%i]: FrameHeader: %i, ReceiveFilterTest: %i, MacHeaderField: %i\n",
Adapter,
index, FilterCriteria[index].FrameHeader, FilterCriteria[index].ReceiveFilterTest,
FilterCriteria[index].HeaderField.MacHeaderField);
//
// Verify frame header
//
if(FilterCriteria[index].FrameHeader != NdisFrameHeaderMac)
{
DEBUGP(MP_ERROR, "[%p] Unknown filter FrameHeader type %x\n", Adapter, FilterCriteria[index].FrameHeader);
Supported = FALSE;
break;
}
//
// Verify that filter test type is supported
//
switch(FilterCriteria[index].ReceiveFilterTest)
{
case NdisReceiveFilterTestEqual:
Supported = TRUE;
break;
default:
Supported=FALSE;
DEBUGP(MP_ERROR, "[%p] ReceiveFilterTest 0x%x not supported.\n", Adapter, FilterCriteria[index].ReceiveFilterTest);
break;
};
if(!Supported)
{
break;
}
//
// Verify header field
//
switch(FilterCriteria[index].HeaderField.MacHeaderField)
{
case NdisMacHeaderFieldDestinationAddress:
VlanUntaggedOrZeroFlagPresent = FilterCriteria->Flags&NDIS_RECEIVE_FILTER_FIELD_MAC_HEADER_VLAN_UNTAGGED_OR_ZERO;
Supported = TRUE;
break;
case NdisMacHeaderFieldVlanId:
VlanFilterPresent = TRUE;
Supported = TRUE;
break;
default:
Supported = FALSE;
DEBUGP(MP_ERROR, "[%p] MacHeaderField 0x%x not supported.\n", Adapter, FilterCriteria[index].HeaderField.MacHeaderField);
break;
};
}
if(Supported)
{
//
// NDIS_RECEIVE_FILTER_FIELD_MAC_HEADER_VLAN_UNTAGGED_OR_ZERO should not be set if VLAN filter is specified,
// and should be set if no VLAN filter is specified.
//
if(VlanFilterPresent == VlanUntaggedOrZeroFlagPresent)
{
//
// Both are specified, this is not correct.
//
DEBUGP(MP_ERROR, "[%p] Invalid VMQ filter configuration. NDIS_RECEIVE_FILTER_FIELD_MAC_HEADER_VLAN_UNTAGGED_OR_ZERO (%s), Vlan ID filter present (%s). Filter not accepted.\n",
Adapter,
VlanFilterPresent?"TRUE":"FALSE",
VlanUntaggedOrZeroFlagPresent?"TRUE":"FALSE");
Supported = FALSE;
}
else if(!VLAN_FILTER_ENABLED(Adapter) && VlanFilterPresent)
{
//
// VLAN based filtering not configured on the adapter
//
DEBUGP(MP_ERROR, "[%p] Invalid VMQ filter configuration. *VMQVlanFiltering is not set, and Vlan ID filter was specified.\n", Adapter);
Supported = FALSE;
}
}
DEBUGP(MP_TRACE, "[%p] <--- IsSupportedRxFilter %s\n", Adapter, Supported?"TRUE":"FALSE");
return Supported;
}
NDIS_STATUS
SetRxFilter(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ PNDIS_RECEIVE_FILTER_PARAMETERS FilterParams
)
/*++
Routine Description:
This routine will assign a filter to the specified queue, after verifying that the filter is valid.
Arguments:
Adapter - Pointer to our adapter
FilterParams - Filter data
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER_VMQ_DATA VMQData = &Adapter->VMQData;
PNDIS_RECEIVE_FILTER_FIELD_PARAMETERS FilterCriteria = (PNDIS_RECEIVE_FILTER_FIELD_PARAMETERS)((PUCHAR)FilterParams + FilterParams->FieldParametersArrayOffset);
UINT FilterIndex = MP_ADAPTER_FILTER_INDEX(FilterParams->FilterId);
UINT CriteriaIndex;
DEBUGP(MP_TRACE, "[%p] ---> SetRxFilter\n", Adapter);
do
{
//
// Verify the requested queue is within supported range and is initialized
//
if(FilterParams->QueueId>=NIC_SUPPORTED_NUM_QUEUES
||
FilterIndex>=NIC_MAX_HEADER_FILTERS
||
!QUEUE_INITIALIZED(&VMQData->RxQueues[FilterParams->QueueId]))
{
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
//
// Verify that the filter itself is valid, and that it hasn't already been set
//
if(!IsSupportedRxFilter(Adapter, FilterParams, FilterCriteria)
||
VMQData->RxFilters[FilterIndex].Valid)
{
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
//
// Make sure filter data is all zero at the outset
//
NdisZeroMemory(&VMQData->RxFilters[FilterIndex], sizeof(MP_ADAPTER_FILTER));
//
// Copy filter information. IsSupportedRxFilter will have already verified that this filter definition
// only contains MAC and VLAN ID definitions, and equals match criteria.
//
for(CriteriaIndex = 0; CriteriaIndex < FilterParams->FieldParametersArrayNumElements; CriteriaIndex++)
{
if(FilterCriteria[CriteriaIndex].HeaderField.MacHeaderField == NdisMacHeaderFieldDestinationAddress)
{
//
// MAC field
//
memcpy(&VMQData->RxFilters[FilterIndex].MacAddress, FilterCriteria[CriteriaIndex].FieldValue.FieldByteArrayValue, NIC_MACADDR_SIZE);
DEBUGP(MP_TRACE, "[%p] Filter Destination: %02x-%02x-%02x-%02x\n",
Adapter,
VMQData->RxFilters[FilterIndex].MacAddress[0], VMQData->RxFilters[FilterIndex].MacAddress[1],
VMQData->RxFilters[FilterIndex].MacAddress[2], VMQData->RxFilters[FilterIndex].MacAddress[3]);
}
else
{
//
// Vlan ID field
//
VMQData->RxFilters[FilterIndex].VlanId = FilterCriteria[CriteriaIndex].FieldValue.FieldShortValue;
DEBUGP(MP_TRACE, "[%p] Filter VlanId: %i\n", Adapter, VMQData->RxFilters[FilterIndex].VlanId);
}
if(FilterCriteria[CriteriaIndex].Flags&NDIS_RECEIVE_FILTER_FIELD_MAC_HEADER_VLAN_UNTAGGED_OR_ZERO)
{
VMQData->RxFilters[FilterIndex].VlanUntaggedOrZero = TRUE;
DEBUGP(MP_TRACE, "[%p] Filter VlanUntaggedOrZero is TRUE\n", Adapter);
}
}
//
// Store the QueueId
//
VMQData->RxFilters[FilterIndex].QueueId = (USHORT)FilterParams->QueueId;
//
// Set to valid
//
VMQData->RxFilters[FilterIndex].Valid = TRUE;
} while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- SetRxFilter Status 0x%08x\n", Adapter, Status);
return Status;
}
NDIS_STATUS
ClearRxFilter(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ PNDIS_RECEIVE_FILTER_CLEAR_PARAMETERS FilterParams
)
/*++
Routine Description:
This routine will remove the specified filter from a particular queue.
Arguments:
Adapter - Pointer to our adapter
FilterParams - Parameters for freeing filter
Return Value:
NDIS_STATUS
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER_VMQ_DATA VMQData = &Adapter->VMQData;
UINT FilterIndex = MP_ADAPTER_FILTER_INDEX(FilterParams->FilterId);
DEBUGP(MP_TRACE, "[%p] ---> ClearRxFilter. FilterParams: QueueId: %i, FilterId: %i\n",
Adapter, FilterParams->QueueId, FilterParams->FilterId);
do
{
//
// Make sure the filter id is within the valid range
//
if(FilterParams->QueueId>=NIC_SUPPORTED_NUM_QUEUES
||
FilterIndex>=NIC_MAX_HEADER_FILTERS)
{
DEBUGP(MP_ERROR, "[%p] Filter Clear request out of valid range. QueueId: %i, FilterId: %i\n",
Adapter, FilterParams->QueueId, FilterParams->FilterId);
Status = NDIS_STATUS_INVALID_PARAMETER;
break;
}
if(!VMQData->RxFilters[FilterIndex].Valid)
{
//
// The filter is not valid.
//
DEBUGP(MP_ERROR, "[%p] Filter was not set. QueueId: %i, FilterId: %i\n",
Adapter, FilterParams->QueueId, FilterParams->FilterId);
Status = NDIS_STATUS_INVALID_PARAMETER;
}
else
{
//
// Reset the filter to invalid
//
VMQData->RxFilters[FilterIndex].Valid = FALSE;
}
} while(FALSE);
DEBUGP(MP_TRACE, "[%p] <--- ClearRxFilter Status 0x%08x\n", Adapter, Status);
return Status;
}
BOOLEAN
MatchRxFilter(
_In_ PMP_ADAPTER Adapter,
_In_reads_bytes_(NIC_MACADDR_SIZE) PUCHAR DestAddress,
_In_ PNDIS_NET_BUFFER_LIST_8021Q_INFO Nbl1QInfo,
_In_ PMP_ADAPTER_FILTER Filter)
/*++
Routine Description:
This routine will check whether a particular filter matches the specified destination address
and VLAN ID.
Arguments:
DestAddress - Destination MAC address
Nbl1QInfo - VLAN information
Filter - Filter to check against
Return Value:
TRUE - Data matches filter
FALSE - Data did not match filter
--*/
{
BOOLEAN MatchResult;
DEBUGP(MP_TRACE, "[%p] ---> MatchRxFilter\n", Adapter);
DEBUGP(MP_TRACE, "[%p] NBL Destination: %02x-%02x-%02x-%02x, Filter Destination: %02x-%02x-%02x-%02x\n",
Adapter,
DestAddress[0],DestAddress[1],DestAddress[2],DestAddress[3],
Filter->MacAddress[0], Filter->MacAddress[1],
Filter->MacAddress[2], Filter->MacAddress[3]);
//
// Match MAC address
//
MatchResult = NIC_ADDR_EQUAL(Filter->MacAddress, DestAddress);
if(MatchResult)
{
if(Filter->VlanUntaggedOrZero)
{
//
// VLAN ID should be zero or untagged for match
//
DEBUGP(MP_TRACE, "[%p] Destination Matched. Making sure VLAN is untagged or zero.\n", Adapter);
if(Nbl1QInfo->Value)
{
MatchResult = (Nbl1QInfo->Value == 0 || Nbl1QInfo->TagHeader.VlanId == 0);
if(Nbl1QInfo->Value)
{
DEBUGP(MP_TRACE, "[%p] NBL Vlan ID: %i\n", Adapter, Nbl1QInfo->TagHeader.VlanId);
}
}
}
else
{
//
// Match VLAN ID
//
if(Nbl1QInfo->Value)
{
MatchResult = (Nbl1QInfo->TagHeader.VlanId == Filter->VlanId);
DEBUGP(MP_TRACE, "[%p] NBL Vlan ID: %i, Filter Vlan ID: %i\n",
Adapter,
Nbl1QInfo->TagHeader.VlanId, Filter->VlanId);
}
else
{
MatchResult = FALSE;
DEBUGP(MP_TRACE, "[%p] NBL without VLAN TAG. Filter Vlan ID: %i\n",
Adapter,
Filter->VlanId);
}
}
}
DEBUGP(MP_TRACE, "[%p] <--- MatchRxFilter MatchResult %s\n", Adapter, MatchResult?"TRUE":"FALSE");
return MatchResult;
}
BOOLEAN
FindRxQueueRecipient(
_In_ struct _MP_ADAPTER *Adapter,
_In_ struct _FRAME *Frame,
_In_ PNDIS_NET_BUFFER_LIST_8021Q_INFO Nbl1QInfo,
_Out_ USHORT *QueueId)
/*++
Routine Description:
This routine will return the matching QueueId and FilterId for a particular Frame and its 802.1Q data.
Arguments:
Adapter - Pointer to our adapter
Frame - Receive frame
Nbl1QInfo - Receive VLAN information
QueueId - Is assigned the matching QueueId (NDIS_DEFAULT_RECEIVE_QUEUE_GROUP_ID if no queue matches)
Return Value:
TRUE - Matched a specific queue (even default queue, if filters present on it)
FALSE - No queue matched
--*/
{
USHORT index;
BOOLEAN Matched=FALSE;
DEBUGP(MP_TRACE, "[%p] ---> FindRxQueueRecipient\n", Adapter);
//
// Iterate through all the filters and check whether a match exists
//
*QueueId = NDIS_DEFAULT_RECEIVE_QUEUE_ID;
for(index = 0; index < NIC_MAX_HEADER_FILTERS; index++)
{
//
// Only attempt to match a filter when it is valid and its queue has been completed
//
if(Adapter->VMQData.RxFilters[index].Valid
&&
QUEUE_COMPLETE(&Adapter->VMQData.RxQueues[Adapter->VMQData.RxFilters[index].QueueId])
&&
MatchRxFilter(Adapter, ((PNIC_FRAME_HEADER)Frame->Data)->DestAddress, Nbl1QInfo, &Adapter->VMQData.RxFilters[index]))
{
DEBUGP(MP_TRACE, "[%p] Match Found.\n", Adapter);
Matched = TRUE;
*QueueId = Adapter->VMQData.RxFilters[index].QueueId;
break;
}
}
if(!Matched)
{
UCHAR DestAddress[NIC_MACADDR_SIZE];
ULONG FrameType;
//
// No queue matched, if the packet is destinaed specifically for this NIC we indicate it on the default queue
//
GET_DESTINATION_OF_FRAME(DestAddress, Frame->Data);
FrameType = NICGetFrameTypeFromDestination(DestAddress);
Matched = HWIsFrameAcceptedByPacketFilter(Adapter, DestAddress, FrameType);
}
DEBUGP(MP_TRACE, "[%p] <-- FindRxQueueRecipient QueueId: %i, Matched: %i\n", Adapter, *QueueId, Matched);
return Matched;
}
BOOLEAN
AcquireRxQueueReference(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ _In_range_(0, NIC_SUPPORTED_NUM_QUEUES-1) USHORT QueueId,
BOOLEAN RequireComplete
)
/*++
Routine Description:
This routine will increase the reference count on a queue, as long as it is still valid.
Arguments:
Adapter - Pointer to our adapter
QueueId - The Queue to take reference
RequireComplete - If TRUE, the queue needs to be Completed to be considered valid, otherwise
Initialized is enough
Return Value:
TRUE - Queue was valid, ref count increased
FALSE - Queue was not valid, ref count not changed
--*/
{
NDIS_STATUS Status = NDIS_STATUS_FAILURE;
PMP_ADAPTER_QUEUE QueueInfo = &Adapter->VMQData.RxQueues[QueueId];
LOCK_STATE_EX LockState;
DEBUGP(MP_TRACE, "[%p] ---> AcquireRxQueueReference. QueueId: %i\n", Adapter, QueueId);
ASSERT(QueueId < NIC_SUPPORTED_NUM_QUEUES);
//
// Acquire read lock on queue to verify that it is valid
//
NdisAcquireRWLockRead(QueueInfo->QueueLock, &LockState, 0);
do
{
//
// Verify queue is initialized and optionally completed before taking reference
//
if(!QUEUE_INITIALIZED(QueueInfo)
||
(RequireComplete && !QUEUE_COMPLETE(QueueInfo)))
{
DEBUGP(MP_LOUD, "[%p] Queue not in correct state to take reference. QueueInfoFlags: 0x%x.\n", Adapter, QueueInfo->QueueInfoFlags);
break;
}
//
// Queue is ready for use. Increment the reference count for the receive block.
//
Status = NICReferenceReceiveBlock(Adapter, QueueInfo->QueueId);
} while(FALSE);
NdisReleaseRWLock(QueueInfo->QueueLock, &LockState);
DEBUGP(MP_TRACE, "[%p] <--- AcquireRxQueueReference.\n", Adapter);
return Status == NDIS_STATUS_SUCCESS;
}
VOID
ReleaseRxQueueReference(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ _In_range_(0, NIC_SUPPORTED_NUM_QUEUES-1) USHORT QueueId)
/*++
Routine Description:
This routine will decrease the reference count on a queue
Arguments:
Adapter - Pointer to our adapter
QueueId - The Queue to take reference
Return Value:
None
--*/
{
ULONG RefCount = 0;
PMP_ADAPTER_QUEUE QueueInfo;
LOCK_STATE_EX LockState;
BOOLEAN PerformFree;
DEBUGP(MP_TRACE, "[%p] ---> ReleaseRxQueueReference. QueueId: %i\n", Adapter, QueueId);
ASSERT(QueueId < NIC_SUPPORTED_NUM_QUEUES);
QueueInfo = &Adapter->VMQData.RxQueues[QueueId];
//
// Acquire read lock on queue to synchronize our check whether the queue free was pended because reference count was not at zero
//
NdisAcquireRWLockRead(QueueInfo->QueueLock, &LockState, 0);
//
// Reduce the reference count
//
NICDereferenceReceiveBlock(Adapter, QueueId, &RefCount);
//
// If the reference count is zero, and the queue is tagged as freeing (which was pended earlier)
// then execute the free.
//
PerformFree = (RefCount == 0 && QUEUE_FREEING(QueueInfo));
//
// Done dereferencing and checking queue state
//
NdisReleaseRWLock(QueueInfo->QueueLock, &LockState);
if(PerformFree)
{
DEBUGP(MP_LOUD, "[%p] RefCount has reached zero and the queue is marked for free. Freeing Queue %i.\n", Adapter, QueueId);
//
// We've already gotten the call to free this queue, but references were still
// active on it. Call the free function now that we're at zero references.
//
if(NDIS_CURRENT_IRQL() < DISPATCH_LEVEL)
{
NDIS_STATUS Status = FreeAdapterQueueInfo(Adapter, QueueId, NULL);
ASSERT(Status == NDIS_STATUS_SUCCESS);
UNREFERENCED_PARAMETER(Status);
}
else
{
NDIS_HANDLE WorkItemHandle = NdisAllocateIoWorkItem(Adapter->AdapterHandle);
DEBUGP(MP_LOUD, "[%p] Currently at DISPATCH, queueing work item to free Queue %i.\n", Adapter, QueueId);
if(WorkItemHandle)
{
NdisQueueIoWorkItem(WorkItemHandle, FreeRxQueuesWorkItem, Adapter);
}
else
{
DEBUGP(MP_ERROR, "[%p] Could not allocate IoWorkItem to free queue.\n", Adapter);
}
}
}
DEBUGP(MP_TRACE, "[%p] <--- ReleaseRxQueueReference.\n", Adapter);
}
VOID
SetPendingRxQueueFree(
_Inout_ struct _MP_ADAPTER *Adapter,
_In_ PNDIS_OID_REQUEST NdisSetRequest
)
/*++
Routine Description:
This routine stores the pending queue free OID request, so that it can be completed
at a later time.
Arguments:
Adapter - Pointer to our adapter
QueueId - The Queue to take reference
Return Value:
None
--*/
{
DEBUGP(MP_TRACE, "[%p] ---> SetPendingRxQueueFree\n", Adapter);
ASSERT(!Adapter->PendingRequest);
Adapter->PendingRequest = NdisSetRequest;
DEBUGP(MP_TRACE, "[%p] <--- SetPendingRxQueueFree\n", Adapter);
}
VOID
GetRcbForRxQueue(
_In_ struct _MP_ADAPTER *Adapter,
_In_ struct _FRAME *Frame,
_In_ PNDIS_NET_BUFFER_LIST_8021Q_INFO Nbl1QInfo,
_Outptr_result_maybenull_ PRCB *Rcb)
/*++
Routine Description:
This routine returns an RCB for the passed in Frame & VLAN info. The RCB will originate from the
matching queue.
Arguments:
Adapter - Pointer to our adapter
Frame - Data Frame
Nbl1QInfo - VLAN information for Frame
Return Value:
RCB pointer if matched
NULL if not matched
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
USHORT QueueId = 0;
DEBUGP(MP_TRACE, "[%p] ---> GetRcbForRxQueue. Frame: 0x%p.\n", Adapter, Frame);
*Rcb = NULL;
//
// Find the matching queue for the Frame
//
if(FindRxQueueRecipient(Adapter, Frame, Nbl1QInfo, &QueueId))
{
//
// Get a reference to the Queue to make sure it is kept valid throughout the receive
//
if(AcquireRxQueueReference(Adapter, QueueId, TRUE))
{
PMP_ADAPTER_QUEUE Queue = &Adapter->VMQData.RxQueues[QueueId];
//
// Get RCB from Queue
//
PLIST_ENTRY pEntry = NdisInterlockedRemoveHeadList(
&Queue->FreeRcbList,
&Queue->FreeRcbListLock);
if (pEntry)
{
*Rcb = CONTAINING_RECORD(pEntry, RCB, RcbLink);
}
else
{
DEBUGP(MP_ERROR, "[%p] Queue %i has run out of available RCBs for receive.\n", Adapter, QueueId);
//
// release the acquired reference on the queue
//
ReleaseRxQueueReference(Adapter, QueueId);
Status = NDIS_STATUS_RESOURCES;
}
}
}
else
{
DEBUGP(MP_LOUD, "[%p] No queue matched Frame: 0x%p.\n", Adapter, Frame);
}
DEBUGP(MP_TRACE, "[%p] <--- GetRcbForRxQueue. RCB: %p\n", Adapter, Rcb);
return;
}
NDIS_STATUS
CopyFrameToRxQueueRcb(
_In_ struct _MP_ADAPTER *Adapter,
_In_ struct _FRAME *Frame,
_In_ PNDIS_NET_BUFFER_LIST_8021Q_INFO Nbl1QInfo,
_Inout_ struct _RCB *Rcb,
_Out_ BOOLEAN *Copied)
/*++
Routine Description:
This routine copies the Frame and VLAN information to the passed in RCB. On a real NIC this copy would
occur through a HW DMA.
Arguments:
Adapter - Pointer to our adapter
Frame - Data Frame
Nbl1QInfo - VLAN information for Frame
Rcb - RCB to receive the data
Copied - TRUE if the frame was copied to shared memory
Return Value:
NDIS_STATUS_SUCCESS if copy succeeded.
NDIS_STATUS_ADAPTER_NOT_READY if we can no longer copy data to the RCB due to the queue being in freeing state (DMA stopped)
--*/
{
USHORT QueueId = NET_BUFFER_LIST_RECEIVE_QUEUE_ID(Rcb->Nbl);
PMP_ADAPTER_QUEUE Queue = &Adapter->VMQData.RxQueues[QueueId];
PNET_BUFFER NetBuffer = NET_BUFFER_LIST_FIRST_NB(Rcb->Nbl);
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
BOOLEAN DMAEnabled = TRUE;
*Copied = FALSE;
DEBUGP(MP_TRACE, "[%p] ---> CopyFrameToRxQueueRcb. RCB: %p\n", Adapter, Rcb);
//
// Mark the queue as having an in progress DMA. This avoids a queue free OID request from causing the queue to
// enter DMA stopped state prematurely.
//
QUEUE_SET_FLAG(Queue,fMPAQI_DMA_IN_PROGRESS);
//
// Make sure the DMA progress set operation happends before the queue freeing check
//
KeMemoryBarrier();
//
// Verify that the queue is in a state where we can modify receive memory. Please note we set the DMA in progress
// first, then check freeing state. The freeing code sets freeing state first, then checks DMA in progress flag. With this
// approach, it's safe to check freeing state without synchronization and perform DMA if it's not yet set. If it gets updated
// to the pending freeing state after the below check, the freeing code (FreeAdapterQueueInfo) will see the DMA in progress flag
// and not set the DMA stopped state.
//
if(QUEUE_FREEING(Queue))
{
LOCK_STATE_EX LockState;
BOOLEAN InDMAStoppedState;
//
// A free OID was issued on the queue, which is now pending until reference count reaches zero (we must have
// at least one reference to have reached this point). Verify whether we should update the queue to DMA stopped state
// (a DMA in progress may have prevented the free code from updating the state).
//
NdisAcquireRWLockWrite(Queue->QueueLock, &LockState, 0);
InDMAStoppedState = QUEUE_DMA_STOPPED(Queue);
if(!InDMAStoppedState)
{
// Set the DMA stopped sate. The indication to NDIS of this change happens outside of our synchronized
// block to avoid holding the lock for too long.
QUEUE_SET_FLAG(Queue,fMPAQI_DMA_STOPPED);
}
NdisReleaseRWLock(Queue->QueueLock, &LockState);
if(!InDMAStoppedState)
{
//
// The queue was marked for free, but a pending DMA prevented it from entering DMA stopped. Enter
// DMA stopped state now, as we will not perform any more copies.
//
IndicateRxQueue(
Adapter,
QueueId,
NdisReceiveQueueOperationalStateDmaStopped);
}
//
// Once we've entered the queue free state, we should not perform any more copies to the receive buffers
//
DMAEnabled = FALSE;
}
if(DMAEnabled)
{
if(QueueId)
{
PMP_ADAPTER_SHARED_MEMORY_BLOCK PostLookaheadBlock = Rcb->Data, LookaheadBlock = Rcb->LookaheadData;
ULONG LookaheadSize = 0;
if(LOOKAHEAD_SPLIT_REQUIRED(Queue))
{
LookaheadSize = Queue->LookaheadSize;
}
if(LookaheadSize < Frame->ulSize)
{
//
// Copy the PostLookahead data
//
memcpy(((PUCHAR)PostLookaheadBlock->Buffer) + LookaheadSize, ((PUCHAR)Frame->Data) + LookaheadSize, Frame->ulSize - LookaheadSize);
//
// Update the MDL to reflect the amount of data present
//
NdisAdjustMdlLength(PostLookaheadBlock->Mdl, Frame->ulSize - LookaheadSize);
}
if(LookaheadSize)
{
//
// Copy the Lookahead
//
ULONG DataSize = min(LookaheadSize,Frame->ulSize);
memcpy(LookaheadBlock->Buffer, Frame->Data, DataSize);
//
// Update MDL to reflect the amount of data present
//
NdisAdjustMdlLength(LookaheadBlock->Mdl, DataSize);
}
*Copied = TRUE;
NET_BUFFER_DATA_LENGTH(NetBuffer) = Frame->ulSize;
}
//
// Set the OOB VLAN Information
//
if(Nbl1QInfo->Value)
{
NET_BUFFER_LIST_INFO(Rcb->Nbl, Ieee8021QNetBufferListInfo) = Nbl1QInfo->Value;
}
}
else
{
//
// We are not in a state where we can copy data to receive buffers
//
Status = NDIS_STATUS_ADAPTER_NOT_READY;
}
//
// Clear the DMA in progress flag
//
QUEUE_CLEAR_FLAG(Queue,fMPAQI_DMA_IN_PROGRESS);
DEBUGP(MP_TRACE, "[%p] <--- CopyFrameToRxQueueRcb. Copied: %i, Status 0x%08x\n", Adapter, *Copied, Status);
return Status;
}
VOID
RecoverRxQueueRcb(
_In_ struct _MP_ADAPTER *Adapter,
_In_ struct _RCB *Rcb)
/*++
Routine Description:
This routine returns an RCB to its owner VMQ Queue, releasing any references held.
Arguments:
Adapter - Pointer to our adapter
Rcb - RCB to recover
Return Value:
None
--*/
{
//
// Return RCB to owner Queue
//
PMP_ADAPTER_QUEUE Queue = NULL;
USHORT QueueId = NET_BUFFER_LIST_RECEIVE_QUEUE_ID(Rcb->Nbl);
DEBUGP(MP_TRACE, "[%p] ---> RecoverRxQueueRcb. RCB: %p\n", Adapter, Rcb);
if(QueueId>=NIC_SUPPORTED_NUM_QUEUES)
{
DEBUGP(MP_ERROR, "[%p] RCB could not be recovered. The NBL QueueId was out of range: %i\n", Adapter, QueueId);
ASSERT(FALSE);
return;
}
Queue = &Adapter->VMQData.RxQueues[QueueId];
if(!QueueId)
{
//
// Default queue uses the send frame, rather than copying the data. Release
// the frame reference.
//
HWFrameRelease((PFRAME)Rcb->Data);
Rcb->Data = NULL;
}
//
// Add RCB back to free pool
//
NdisInterlockedInsertTailList(
&Queue->FreeRcbList,
&Rcb->RcbLink,
&Queue->FreeRcbListLock);
//
// Release reference to queue that we took when indicating the NBL
//
ReleaseRxQueueReference(Adapter, QueueId);
DEBUGP(MP_TRACE, "[%p] <--- RecoverRxQueueRcb\n", Adapter);
}
VOID
AddPendingRcbToRxQueue(
_In_ struct _MP_ADAPTER *Adapter,
_In_ struct _RCB *Rcb)
/*++
Routine Description:
This routine adds an RCB to the pending receive list for its owner VMQ queue.
Arguments:
Adapter - Pointer to our adapter
Rcb - RCB to queue for receive
Return Value:
None
--*/
{
NDIS_RECEIVE_QUEUE_ID QueueId = NET_BUFFER_LIST_RECEIVE_QUEUE_ID(Rcb->Nbl);
DEBUGP(MP_TRACE, "[%p] ---> AddPendingRcbToRxQueue. RCB: %p\n", Adapter, Rcb);
NdisInterlockedInsertTailList(
&Adapter->ReceiveBlock[QueueId].ReceiveList,
&Rcb->RcbLink,
&Adapter->ReceiveBlock[QueueId].ReceiveListLock);
DEBUGP(MP_TRACE, "[%p] <--- AddPendingRcbToRxQueue\n", Adapter);
}
|