1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2016 by Delphix. All rights reserved.
*/
/*
* gld - Generic LAN Driver Version 2, PSARC/1997/382
*
* This is a utility module that provides generic facilities for
* LAN drivers. The DLPI protocol and most STREAMS interfaces
* are handled here.
*
* It no longer provides compatibility with drivers
* implemented according to the GLD v0 documentation published
* in 1993. (See PSARC 2003/728)
*/
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/stropts.h>
#include <sys/stream.h>
#include <sys/kmem.h>
#include <sys/stat.h>
#include <sys/modctl.h>
#include <sys/kstat.h>
#include <sys/debug.h>
#include <sys/note.h>
#include <sys/sysmacros.h>
#include <sys/byteorder.h>
#include <sys/strsun.h>
#include <sys/strsubr.h>
#include <sys/dlpi.h>
#include <sys/pattr.h>
#include <sys/ethernet.h>
#include <sys/ib/clients/ibd/ibd.h>
#include <sys/policy.h>
#include <sys/atomic.h>
#include <sys/multidata.h>
#include <sys/gld.h>
#include <sys/gldpriv.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
/*
* Macros to increment statistics.
*/
/*
* Increase kstats. Note this operation is not atomic. It can be used when
* GLDM_LOCK_HELD_WRITE(macinfo).
*/
#define BUMP(stats, vstats, stat, delta) do { \
((stats)->stat) += (delta); \
_NOTE(CONSTANTCONDITION) \
if ((vstats) != NULL) \
((struct gld_stats *)(vstats))->stat += (delta); \
_NOTE(CONSTANTCONDITION) \
} while (0)
#define ATOMIC_BUMP_STAT(stat, delta) do { \
_NOTE(CONSTANTCONDITION) \
if (sizeof ((stat)) == sizeof (uint32_t)) { \
atomic_add_32((uint32_t *)&(stat), (delta)); \
_NOTE(CONSTANTCONDITION) \
} else if (sizeof ((stat)) == sizeof (uint64_t)) { \
atomic_add_64((uint64_t *)&(stat), (delta)); \
} \
_NOTE(CONSTANTCONDITION) \
} while (0)
#define ATOMIC_BUMP(stats, vstats, stat, delta) do { \
ATOMIC_BUMP_STAT((stats)->stat, (delta)); \
_NOTE(CONSTANTCONDITION) \
if ((vstats) != NULL) { \
ATOMIC_BUMP_STAT(((struct gld_stats *)(vstats))->stat, \
(delta)); \
} \
_NOTE(CONSTANTCONDITION) \
} while (0)
#define UPDATE_STATS(stats, vstats, pktinfo, delta) { \
if ((pktinfo).isBroadcast) { \
ATOMIC_BUMP((stats), (vstats), \
glds_brdcstxmt, (delta)); \
} else if ((pktinfo).isMulticast) { \
ATOMIC_BUMP((stats), (vstats), glds_multixmt, (delta)); \
} \
ATOMIC_BUMP((stats), (vstats), glds_bytexmt64, \
((pktinfo).pktLen)); \
ATOMIC_BUMP((stats), (vstats), glds_pktxmt64, (delta)); \
}
#ifdef GLD_DEBUG
int gld_debug = GLDERRS;
#endif
/* called from gld_register */
static int gld_initstats(gld_mac_info_t *);
/* called from kstat mechanism, and from wsrv's get_statistics */
static int gld_update_kstat(kstat_t *, int);
/* statistics for additional vlans */
static int gld_init_vlan_stats(gld_vlan_t *);
static int gld_update_vlan_kstat(kstat_t *, int);
/* called from gld_getinfo */
static dev_info_t *gld_finddevinfo(dev_t);
/* called from wput, wsrv, unidata, and v0_sched to send a packet */
/* also from the source routing stuff for sending RDE protocol packets */
static int gld_start(queue_t *, mblk_t *, int, uint32_t);
static int gld_start_mdt(queue_t *, mblk_t *, int);
/* called from gld_start[_mdt] to loopback packet(s) in promiscuous mode */
static void gld_precv(gld_mac_info_t *, mblk_t *, uint32_t, struct gld_stats *);
static void gld_precv_mdt(gld_mac_info_t *, gld_vlan_t *, mblk_t *,
pdesc_t *, pktinfo_t *);
/* receive group: called from gld_recv and gld_precv* with maclock held */
static void gld_sendup(gld_mac_info_t *, pktinfo_t *, mblk_t *,
int (*)());
static int gld_accept(gld_t *, pktinfo_t *);
static int gld_mcmatch(gld_t *, pktinfo_t *);
static int gld_multicast(unsigned char *, gld_t *);
static int gld_paccept(gld_t *, pktinfo_t *);
static void gld_passon(gld_t *, mblk_t *, pktinfo_t *,
void (*)(queue_t *, mblk_t *));
static mblk_t *gld_addudind(gld_t *, mblk_t *, pktinfo_t *, boolean_t);
/* wsrv group: called from wsrv, single threaded per queue */
static int gld_ioctl(queue_t *, mblk_t *);
static void gld_fastpath(gld_t *, queue_t *, mblk_t *);
static int gld_cmds(queue_t *, mblk_t *);
static mblk_t *gld_bindack(queue_t *, mblk_t *);
static int gld_notify_req(queue_t *, mblk_t *);
static int gld_udqos(queue_t *, mblk_t *);
static int gld_bind(queue_t *, mblk_t *);
static int gld_unbind(queue_t *, mblk_t *);
static int gld_inforeq(queue_t *, mblk_t *);
static int gld_unitdata(queue_t *, mblk_t *);
static int gldattach(queue_t *, mblk_t *);
static int gldunattach(queue_t *, mblk_t *);
static int gld_enable_multi(queue_t *, mblk_t *);
static int gld_disable_multi(queue_t *, mblk_t *);
static void gld_send_disable_multi(gld_mac_info_t *, gld_mcast_t *);
static int gld_promisc(queue_t *, mblk_t *, t_uscalar_t, boolean_t);
static int gld_physaddr(queue_t *, mblk_t *);
static int gld_setaddr(queue_t *, mblk_t *);
static int gld_get_statistics(queue_t *, mblk_t *);
static int gld_cap(queue_t *, mblk_t *);
static int gld_cap_ack(queue_t *, mblk_t *);
static int gld_cap_enable(queue_t *, mblk_t *);
/* misc utilities, some requiring various mutexes held */
static int gld_start_mac(gld_mac_info_t *);
static void gld_stop_mac(gld_mac_info_t *);
static void gld_set_ipq(gld_t *);
static void gld_flushqueue(queue_t *);
static glddev_t *gld_devlookup(int);
static int gld_findminor(glddev_t *);
static void gldinsque(void *, void *);
static void gldremque(void *);
void gld_bitrevcopy(caddr_t, caddr_t, size_t);
void gld_bitreverse(uchar_t *, size_t);
char *gld_macaddr_sprintf(char *, unsigned char *, int);
static gld_vlan_t *gld_add_vlan(gld_mac_info_t *, uint32_t vid);
static void gld_rem_vlan(gld_vlan_t *);
gld_vlan_t *gld_find_vlan(gld_mac_info_t *, uint32_t);
gld_vlan_t *gld_get_vlan(gld_mac_info_t *, uint32_t);
#ifdef GLD_DEBUG
static void gld_check_assertions(void);
extern void gld_sr_dump(gld_mac_info_t *);
#endif
/*
* Allocate and zero-out "number" structures each of type "structure" in
* kernel memory.
*/
#define GLD_GETSTRUCT(structure, number) \
(kmem_zalloc((uint_t)(sizeof (structure) * (number)), KM_NOSLEEP))
#define abs(a) ((a) < 0 ? -(a) : a)
uint32_t gld_global_options = GLD_OPT_NO_ETHRXSNAP;
/*
* The device is of DL_ETHER type and is able to support VLAN by itself.
*/
#define VLAN_CAPABLE(macinfo) \
((macinfo)->gldm_type == DL_ETHER && \
(macinfo)->gldm_send_tagged != NULL)
/*
* The set of notifications generatable by GLD itself, the additional
* set that can be generated if the MAC driver provide the link-state
* tracking callback capability, and the set supported by the GLD
* notification code below.
*
* PLEASE keep these in sync with what the code actually does!
*/
static const uint32_t gld_internal_notes = DL_NOTE_PROMISC_ON_PHYS |
DL_NOTE_PROMISC_OFF_PHYS |
DL_NOTE_PHYS_ADDR;
static const uint32_t gld_linkstate_notes = DL_NOTE_LINK_DOWN |
DL_NOTE_LINK_UP |
DL_NOTE_SPEED;
static const uint32_t gld_supported_notes = DL_NOTE_PROMISC_ON_PHYS |
DL_NOTE_PROMISC_OFF_PHYS |
DL_NOTE_PHYS_ADDR |
DL_NOTE_LINK_DOWN |
DL_NOTE_LINK_UP |
DL_NOTE_SPEED;
/* Media must correspond to #defines in gld.h */
static char *gld_media[] = {
"unknown", /* GLDM_UNKNOWN - driver cannot determine media */
"aui", /* GLDM_AUI */
"bnc", /* GLDM_BNC */
"twpair", /* GLDM_TP */
"fiber", /* GLDM_FIBER */
"100baseT", /* GLDM_100BT */
"100vgAnyLan", /* GLDM_VGANYLAN */
"10baseT", /* GLDM_10BT */
"ring4", /* GLDM_RING4 */
"ring16", /* GLDM_RING16 */
"PHY/MII", /* GLDM_PHYMII */
"100baseTX", /* GLDM_100BTX */
"100baseT4", /* GLDM_100BT4 */
"unknown", /* skip */
"ipib", /* GLDM_IB */
};
/* Must correspond to #defines in gld.h */
static char *gld_duplex[] = {
"unknown", /* GLD_DUPLEX_UNKNOWN - not known or not applicable */
"half", /* GLD_DUPLEX_HALF */
"full" /* GLD_DUPLEX_FULL */
};
/*
* Interface types currently supported by GLD.
* If you add new types, you must check all "XXX" strings in the GLD source
* for implementation issues that may affect the support of your new type.
* In particular, any type with gldm_addrlen > 6, or gldm_saplen != -2, will
* require generalizing this GLD source to handle the new cases. In other
* words there are assumptions built into the code in a few places that must
* be fixed. Be sure to turn on DEBUG/ASSERT code when testing a new type.
*/
static gld_interface_t interfaces[] = {
/* Ethernet Bus */
{
DL_ETHER,
(uint_t)-1,
sizeof (struct ether_header),
gld_interpret_ether,
NULL,
gld_fastpath_ether,
gld_unitdata_ether,
gld_init_ether,
gld_uninit_ether,
"ether"
},
/* Fiber Distributed data interface */
{
DL_FDDI,
4352,
sizeof (struct fddi_mac_frm),
gld_interpret_fddi,
NULL,
gld_fastpath_fddi,
gld_unitdata_fddi,
gld_init_fddi,
gld_uninit_fddi,
"fddi"
},
/* Token Ring interface */
{
DL_TPR,
17914,
-1, /* variable header size */
gld_interpret_tr,
NULL,
gld_fastpath_tr,
gld_unitdata_tr,
gld_init_tr,
gld_uninit_tr,
"tpr"
},
/* Infiniband */
{
DL_IB,
4092,
sizeof (struct ipoib_header),
gld_interpret_ib,
gld_interpret_mdt_ib,
gld_fastpath_ib,
gld_unitdata_ib,
gld_init_ib,
gld_uninit_ib,
"ipib"
},
};
/*
* bit reversal lookup table.
*/
static uchar_t bit_rev[] = {
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0,
0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4,
0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc,
0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca,
0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6,
0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1,
0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9,
0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd,
0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3,
0x33, 0xb3, 0x73, 0xf3, 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7,
0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf,
0x3f, 0xbf, 0x7f, 0xff,
};
/*
* User priorities, mapped from b_band.
*/
static uint32_t user_priority[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
};
#define UPRI(gld, band) ((band != 0) ? user_priority[(band)] : (gld)->gld_upri)
static struct glddevice gld_device_list; /* Per-system root of GLD tables */
/*
* Module linkage information for the kernel.
*/
static struct modldrv modlmisc = {
&mod_miscops, /* Type of module - a utility provider */
"Generic LAN Driver (" GLD_VERSION_STRING ")"
#ifdef GLD_DEBUG
" DEBUG"
#endif
};
static struct modlinkage modlinkage = {
MODREV_1, &modlmisc, NULL
};
int
_init(void)
{
int e;
/* initialize gld_device_list mutex */
mutex_init(&gld_device_list.gld_devlock, NULL, MUTEX_DRIVER, NULL);
/* initialize device driver (per-major) list */
gld_device_list.gld_next =
gld_device_list.gld_prev = &gld_device_list;
if ((e = mod_install(&modlinkage)) != 0)
mutex_destroy(&gld_device_list.gld_devlock);
return (e);
}
int
_fini(void)
{
int e;
if ((e = mod_remove(&modlinkage)) != 0)
return (e);
ASSERT(gld_device_list.gld_next ==
(glddev_t *)&gld_device_list.gld_next);
ASSERT(gld_device_list.gld_prev ==
(glddev_t *)&gld_device_list.gld_next);
mutex_destroy(&gld_device_list.gld_devlock);
return (e);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
/*
* GLD service routines
*/
/* So this gld binary maybe can be forward compatible with future v2 drivers */
#define GLD_MAC_RESERVED (16 * sizeof (caddr_t))
/*ARGSUSED*/
gld_mac_info_t *
gld_mac_alloc(dev_info_t *devinfo)
{
gld_mac_info_t *macinfo;
macinfo = kmem_zalloc(sizeof (gld_mac_info_t) + GLD_MAC_RESERVED,
KM_SLEEP);
/*
* The setting of gldm_driver_version will not be documented or allowed
* until a future release.
*/
macinfo->gldm_driver_version = GLD_VERSION_200;
/*
* GLD's version. This also is undocumented for now, but will be
* available if needed in the future.
*/
macinfo->gldm_GLD_version = GLD_VERSION;
return (macinfo);
}
/*
* gld_mac_free must be called after the driver has removed interrupts
* and completely stopped calling gld_recv() and gld_sched(). At that
* point the interrupt routine is guaranteed by the system to have been
* exited and the maclock is no longer needed. Of course, it is
* expected (required) that (assuming gld_register() succeeded),
* gld_unregister() was called before gld_mac_free().
*/
void
gld_mac_free(gld_mac_info_t *macinfo)
{
ASSERT(macinfo);
ASSERT(macinfo->gldm_GLD_version == GLD_VERSION);
/*
* Assert that if we made it through gld_register, then we must
* have unregistered.
*/
ASSERT(!GLDM_LOCK_INITED(macinfo) ||
(macinfo->gldm_GLD_flags & GLD_UNREGISTERED));
GLDM_LOCK_DESTROY(macinfo);
kmem_free(macinfo, sizeof (gld_mac_info_t) + GLD_MAC_RESERVED);
}
/*
* gld_register -- called once per device instance (PPA)
*
* During its attach routine, a real device driver will register with GLD
* so that later opens and dl_attach_reqs will work. The arguments are the
* devinfo pointer, the device name, and a macinfo structure describing the
* physical device instance.
*/
int
gld_register(dev_info_t *devinfo, char *devname, gld_mac_info_t *macinfo)
{
int mediatype;
int major = ddi_name_to_major(devname), i;
glddev_t *glddev;
gld_mac_pvt_t *mac_pvt;
char minordev[32];
char pbuf[3*GLD_MAX_ADDRLEN];
gld_interface_t *ifp;
ASSERT(devinfo != NULL);
ASSERT(macinfo != NULL);
if (macinfo->gldm_driver_version != GLD_VERSION)
return (DDI_FAILURE);
mediatype = macinfo->gldm_type;
/*
* Entry points should be ready for us.
* ioctl is optional.
* set_multicast and get_stats are optional in v0.
* intr is only required if you add an interrupt.
*/
ASSERT(macinfo->gldm_reset != NULL);
ASSERT(macinfo->gldm_start != NULL);
ASSERT(macinfo->gldm_stop != NULL);
ASSERT(macinfo->gldm_set_mac_addr != NULL);
ASSERT(macinfo->gldm_set_promiscuous != NULL);
ASSERT(macinfo->gldm_send != NULL);
ASSERT(macinfo->gldm_maxpkt >= macinfo->gldm_minpkt);
ASSERT(macinfo->gldm_GLD_version == GLD_VERSION);
ASSERT(macinfo->gldm_broadcast_addr != NULL);
ASSERT(macinfo->gldm_vendor_addr != NULL);
ASSERT(macinfo->gldm_ident != NULL);
if (macinfo->gldm_addrlen > GLD_MAX_ADDRLEN) {
cmn_err(CE_WARN, "GLD: %s driver gldm_addrlen %d > %d not sup"
"ported", devname, macinfo->gldm_addrlen, GLD_MAX_ADDRLEN);
return (DDI_FAILURE);
}
/*
* GLD only functions properly with saplen == -2
*/
if (macinfo->gldm_saplen != -2) {
cmn_err(CE_WARN, "GLD: %s driver gldm_saplen %d != -2 "
"not supported", devname, macinfo->gldm_saplen);
return (DDI_FAILURE);
}
/* see gld_rsrv() */
if (ddi_getprop(DDI_DEV_T_NONE, devinfo, 0, "fast_recv", 0))
macinfo->gldm_options |= GLDOPT_FAST_RECV;
mutex_enter(&gld_device_list.gld_devlock);
glddev = gld_devlookup(major);
/*
* Allocate per-driver (major) data structure if necessary
*/
if (glddev == NULL) {
/* first occurrence of this device name (major number) */
glddev = GLD_GETSTRUCT(glddev_t, 1);
if (glddev == NULL) {
mutex_exit(&gld_device_list.gld_devlock);
return (DDI_FAILURE);
}
(void) strncpy(glddev->gld_name, devname,
sizeof (glddev->gld_name) - 1);
glddev->gld_major = major;
glddev->gld_nextminor = GLD_MIN_CLONE_MINOR;
glddev->gld_mac_next = glddev->gld_mac_prev =
(gld_mac_info_t *)&glddev->gld_mac_next;
glddev->gld_str_next = glddev->gld_str_prev =
(gld_t *)&glddev->gld_str_next;
mutex_init(&glddev->gld_devlock, NULL, MUTEX_DRIVER, NULL);
/* allow increase of number of supported multicast addrs */
glddev->gld_multisize = ddi_getprop(DDI_DEV_T_NONE,
devinfo, 0, "multisize", GLD_MAX_MULTICAST);
/*
* Optionally restrict DLPI provider style
*
* -1 - don't create style 1 nodes
* -2 - don't create style 2 nodes
*/
glddev->gld_styles = ddi_getprop(DDI_DEV_T_NONE, devinfo, 0,
"gld-provider-styles", 0);
/* Stuff that's needed before any PPA gets attached */
glddev->gld_type = macinfo->gldm_type;
glddev->gld_minsdu = macinfo->gldm_minpkt;
glddev->gld_saplen = macinfo->gldm_saplen;
glddev->gld_addrlen = macinfo->gldm_addrlen;
glddev->gld_broadcast = kmem_zalloc(macinfo->gldm_addrlen,
KM_SLEEP);
bcopy(macinfo->gldm_broadcast_addr,
glddev->gld_broadcast, macinfo->gldm_addrlen);
glddev->gld_maxsdu = macinfo->gldm_maxpkt;
gldinsque(glddev, gld_device_list.gld_prev);
}
glddev->gld_ndevice++;
/* Now glddev can't go away until we unregister this mac (or fail) */
mutex_exit(&gld_device_list.gld_devlock);
/*
* Per-instance initialization
*/
/*
* Initialize per-mac structure that is private to GLD.
* Set up interface pointer. These are device class specific pointers
* used to handle FDDI/TR/ETHER/IPoIB specific packets.
*/
for (i = 0; i < sizeof (interfaces)/sizeof (*interfaces); i++) {
if (mediatype != interfaces[i].mac_type)
continue;
macinfo->gldm_mac_pvt = kmem_zalloc(sizeof (gld_mac_pvt_t),
KM_SLEEP);
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->interfacep = ifp =
&interfaces[i];
break;
}
if (ifp == NULL) {
cmn_err(CE_WARN, "GLD: this version does not support %s driver "
"of type %d", devname, mediatype);
goto failure;
}
/*
* Driver can only register MTU within legal media range.
*/
if (macinfo->gldm_maxpkt > ifp->mtu_size) {
cmn_err(CE_WARN, "GLD: oversize MTU is specified by driver %s",
devname);
goto failure;
}
/*
* Correct margin size if it is not set.
*/
if (VLAN_CAPABLE(macinfo) && (macinfo->gldm_margin == 0))
macinfo->gldm_margin = VTAG_SIZE;
/*
* For now, only Infiniband drivers can use MDT. Do not add
* support for Ethernet, FDDI or TR.
*/
if (macinfo->gldm_mdt_pre != NULL) {
if (mediatype != DL_IB) {
cmn_err(CE_WARN, "GLD: MDT not supported for %s "
"driver of type %d", devname, mediatype);
goto failure;
}
/*
* Validate entry points.
*/
if ((macinfo->gldm_mdt_send == NULL) ||
(macinfo->gldm_mdt_post == NULL)) {
cmn_err(CE_WARN, "GLD: invalid MDT entry points for "
"%s driver of type %d", devname, mediatype);
goto failure;
}
macinfo->gldm_options |= GLDOPT_MDT;
}
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
mac_pvt->major_dev = glddev;
mac_pvt->curr_macaddr = kmem_zalloc(macinfo->gldm_addrlen, KM_SLEEP);
/*
* XXX Do bit-reversed devices store gldm_vendor in canonical
* format or in wire format? Also gldm_broadcast. For now
* we are assuming canonical, but I'm not sure that makes the
* most sense for ease of driver implementation.
*/
bcopy(macinfo->gldm_vendor_addr, mac_pvt->curr_macaddr,
macinfo->gldm_addrlen);
mac_pvt->statistics = kmem_zalloc(sizeof (struct gld_stats), KM_SLEEP);
/*
* The available set of notifications is those generatable by GLD
* itself, plus those corresponding to the capabilities of the MAC
* driver, intersected with those supported by gld_notify_ind() above.
*/
mac_pvt->notifications = gld_internal_notes;
if (macinfo->gldm_capabilities & GLD_CAP_LINKSTATE)
mac_pvt->notifications |= gld_linkstate_notes;
mac_pvt->notifications &= gld_supported_notes;
GLDM_LOCK_INIT(macinfo);
ddi_set_driver_private(devinfo, macinfo);
/*
* Now atomically get a PPA and put ourselves on the mac list.
*/
mutex_enter(&glddev->gld_devlock);
#ifdef DEBUG
if (macinfo->gldm_ppa != ddi_get_instance(devinfo))
cmn_err(CE_WARN, "%s%d instance != ppa %d",
ddi_driver_name(devinfo), ddi_get_instance(devinfo),
macinfo->gldm_ppa);
#endif
/*
* Create style 2 node (gated by gld-provider-styles property).
*
* NOTE: When the CLONE_DEV flag is specified to
* ddi_create_minor_node() the minor number argument is
* immaterial. Opens of that node will go via the clone
* driver and gld_open() will always be passed a dev_t with
* minor of zero.
*/
if (glddev->gld_styles != -2) {
if (ddi_create_minor_node(devinfo, glddev->gld_name, S_IFCHR,
0, DDI_NT_NET, CLONE_DEV) == DDI_FAILURE) {
mutex_exit(&glddev->gld_devlock);
goto late_failure;
}
}
/*
* Create style 1 node (gated by gld-provider-styles property)
*/
if (glddev->gld_styles != -1) {
(void) sprintf(minordev, "%s%d", glddev->gld_name,
macinfo->gldm_ppa);
if (ddi_create_minor_node(devinfo, minordev, S_IFCHR,
GLD_STYLE1_PPA_TO_MINOR(macinfo->gldm_ppa), DDI_NT_NET,
0) != DDI_SUCCESS) {
mutex_exit(&glddev->gld_devlock);
goto late_failure;
}
}
/* add ourselves to this major device's linked list of instances */
gldinsque(macinfo, glddev->gld_mac_prev);
mutex_exit(&glddev->gld_devlock);
/*
* Unfortunately we need the ppa before we call gld_initstats();
* otherwise we would like to do this just above the mutex_enter
* above. In which case we could have set MAC_READY inside the
* mutex and we wouldn't have needed to check it in open and
* DL_ATTACH. We wouldn't like to do the initstats/kstat_create
* inside the mutex because it might get taken in our kstat_update
* routine and cause a deadlock with kstat_chain_lock.
*/
/* gld_initstats() calls (*ifp->init)() */
if (gld_initstats(macinfo) != GLD_SUCCESS) {
mutex_enter(&glddev->gld_devlock);
gldremque(macinfo);
mutex_exit(&glddev->gld_devlock);
goto late_failure;
}
/*
* Need to indicate we are NOW ready to process interrupts;
* any interrupt before this is set is for someone else.
* This flag is also now used to tell open, et. al. that this
* mac is now fully ready and available for use.
*/
GLDM_LOCK(macinfo, RW_WRITER);
macinfo->gldm_GLD_flags |= GLD_MAC_READY;
GLDM_UNLOCK(macinfo);
/* log local ethernet address -- XXX not DDI compliant */
if (macinfo->gldm_addrlen == sizeof (struct ether_addr))
(void) localetheraddr(
(struct ether_addr *)macinfo->gldm_vendor_addr, NULL);
/* now put announcement into the message buffer */
cmn_err(CE_CONT, "!%s%d: %s: type \"%s\" mac address %s\n",
glddev->gld_name,
macinfo->gldm_ppa, macinfo->gldm_ident,
mac_pvt->interfacep->mac_string,
gld_macaddr_sprintf(pbuf, macinfo->gldm_vendor_addr,
macinfo->gldm_addrlen));
ddi_report_dev(devinfo);
return (DDI_SUCCESS);
late_failure:
ddi_remove_minor_node(devinfo, NULL);
GLDM_LOCK_DESTROY(macinfo);
if (mac_pvt->curr_macaddr != NULL)
kmem_free(mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
if (mac_pvt->statistics != NULL)
kmem_free(mac_pvt->statistics, sizeof (struct gld_stats));
kmem_free(macinfo->gldm_mac_pvt, sizeof (gld_mac_pvt_t));
macinfo->gldm_mac_pvt = NULL;
failure:
mutex_enter(&gld_device_list.gld_devlock);
glddev->gld_ndevice--;
/*
* Note that just because this goes to zero here does not necessarily
* mean that we were the one who added the glddev above. It's
* possible that the first mac unattached while were were in here
* failing to attach the second mac. But we're now the last.
*/
if (glddev->gld_ndevice == 0) {
/* There should be no macinfos left */
ASSERT(glddev->gld_mac_next ==
(gld_mac_info_t *)&glddev->gld_mac_next);
ASSERT(glddev->gld_mac_prev ==
(gld_mac_info_t *)&glddev->gld_mac_next);
/*
* There should be no DL_UNATTACHED streams: the system
* should not have detached the "first" devinfo which has
* all the open style 2 streams.
*
* XXX This is not clear. See gld_getinfo and Bug 1165519
*/
ASSERT(glddev->gld_str_next == (gld_t *)&glddev->gld_str_next);
ASSERT(glddev->gld_str_prev == (gld_t *)&glddev->gld_str_next);
gldremque(glddev);
mutex_destroy(&glddev->gld_devlock);
if (glddev->gld_broadcast != NULL)
kmem_free(glddev->gld_broadcast, glddev->gld_addrlen);
kmem_free(glddev, sizeof (glddev_t));
}
mutex_exit(&gld_device_list.gld_devlock);
return (DDI_FAILURE);
}
/*
* gld_unregister (macinfo)
* remove the macinfo structure from local structures
* this is cleanup for a driver to be unloaded
*/
int
gld_unregister(gld_mac_info_t *macinfo)
{
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
glddev_t *glddev = mac_pvt->major_dev;
gld_interface_t *ifp;
int multisize = sizeof (gld_mcast_t) * glddev->gld_multisize;
mutex_enter(&glddev->gld_devlock);
GLDM_LOCK(macinfo, RW_WRITER);
if (mac_pvt->nvlan > 0) {
GLDM_UNLOCK(macinfo);
mutex_exit(&glddev->gld_devlock);
return (DDI_FAILURE);
}
#ifdef GLD_DEBUG
{
int i;
for (i = 0; i < VLAN_HASHSZ; i++) {
if ((mac_pvt->vlan_hash[i] != NULL))
cmn_err(CE_PANIC,
"%s, line %d: "
"mac_pvt->vlan_hash[%d] != NULL",
__FILE__, __LINE__, i);
}
}
#endif
/* Delete this mac */
gldremque(macinfo);
/* Disallow further entries to gld_recv() and gld_sched() */
macinfo->gldm_GLD_flags |= GLD_UNREGISTERED;
GLDM_UNLOCK(macinfo);
mutex_exit(&glddev->gld_devlock);
ifp = ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->interfacep;
(*ifp->uninit)(macinfo);
ASSERT(mac_pvt->kstatp);
kstat_delete(mac_pvt->kstatp);
ASSERT(GLDM_LOCK_INITED(macinfo));
kmem_free(mac_pvt->curr_macaddr, macinfo->gldm_addrlen);
kmem_free(mac_pvt->statistics, sizeof (struct gld_stats));
if (mac_pvt->mcast_table != NULL)
kmem_free(mac_pvt->mcast_table, multisize);
kmem_free(macinfo->gldm_mac_pvt, sizeof (gld_mac_pvt_t));
macinfo->gldm_mac_pvt = (caddr_t)NULL;
/* We now have one fewer instance for this major device */
mutex_enter(&gld_device_list.gld_devlock);
glddev->gld_ndevice--;
if (glddev->gld_ndevice == 0) {
/* There should be no macinfos left */
ASSERT(glddev->gld_mac_next ==
(gld_mac_info_t *)&glddev->gld_mac_next);
ASSERT(glddev->gld_mac_prev ==
(gld_mac_info_t *)&glddev->gld_mac_next);
/*
* There should be no DL_UNATTACHED streams: the system
* should not have detached the "first" devinfo which has
* all the open style 2 streams.
*
* XXX This is not clear. See gld_getinfo and Bug 1165519
*/
ASSERT(glddev->gld_str_next == (gld_t *)&glddev->gld_str_next);
ASSERT(glddev->gld_str_prev == (gld_t *)&glddev->gld_str_next);
ddi_remove_minor_node(macinfo->gldm_devinfo, NULL);
gldremque(glddev);
mutex_destroy(&glddev->gld_devlock);
if (glddev->gld_broadcast != NULL)
kmem_free(glddev->gld_broadcast, glddev->gld_addrlen);
kmem_free(glddev, sizeof (glddev_t));
}
mutex_exit(&gld_device_list.gld_devlock);
return (DDI_SUCCESS);
}
/*
* gld_initstats
* called from gld_register
*/
static int
gld_initstats(gld_mac_info_t *macinfo)
{
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
struct gldkstats *sp;
glddev_t *glddev;
kstat_t *ksp;
gld_interface_t *ifp;
glddev = mac_pvt->major_dev;
if ((ksp = kstat_create(glddev->gld_name, macinfo->gldm_ppa,
NULL, "net", KSTAT_TYPE_NAMED,
sizeof (struct gldkstats) / sizeof (kstat_named_t), 0)) == NULL) {
cmn_err(CE_WARN,
"GLD: failed to create kstat structure for %s%d",
glddev->gld_name, macinfo->gldm_ppa);
return (GLD_FAILURE);
}
mac_pvt->kstatp = ksp;
ksp->ks_update = gld_update_kstat;
ksp->ks_private = (void *)macinfo;
sp = ksp->ks_data;
kstat_named_init(&sp->glds_pktrcv, "ipackets", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_pktxmt, "opackets", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_errrcv, "ierrors", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_errxmt, "oerrors", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_bytexmt, "obytes", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_bytercv, "rbytes", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_multixmt, "multixmt", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_multircv, "multircv", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_brdcstxmt, "brdcstxmt", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_brdcstrcv, "brdcstrcv", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_blocked, "blocked", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_noxmtbuf, "noxmtbuf", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_norcvbuf, "norcvbuf", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_xmtretry, "xmtretry", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_intr, "intr", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_pktrcv64, "ipackets64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_pktxmt64, "opackets64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_bytexmt64, "obytes64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_bytercv64, "rbytes64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_unknowns, "unknowns", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_speed, "ifspeed", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_media, "media", KSTAT_DATA_CHAR);
kstat_named_init(&sp->glds_prom, "promisc", KSTAT_DATA_CHAR);
kstat_named_init(&sp->glds_overflow, "oflo", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_underflow, "uflo", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_missed, "missed", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_xmtbadinterp, "xmt_badinterp",
KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_rcvbadinterp, "rcv_badinterp",
KSTAT_DATA_UINT32);
ifp = ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->interfacep;
(*ifp->init)(macinfo);
kstat_install(ksp);
return (GLD_SUCCESS);
}
/* called from kstat mechanism, and from wsrv's get_statistics_req */
static int
gld_update_kstat(kstat_t *ksp, int rw)
{
gld_mac_info_t *macinfo;
gld_mac_pvt_t *mac_pvt;
struct gldkstats *gsp;
struct gld_stats *stats;
if (rw == KSTAT_WRITE)
return (EACCES);
macinfo = (gld_mac_info_t *)ksp->ks_private;
ASSERT(macinfo != NULL);
GLDM_LOCK(macinfo, RW_WRITER);
if (!(macinfo->gldm_GLD_flags & GLD_MAC_READY)) {
GLDM_UNLOCK(macinfo);
return (EIO); /* this one's not ready yet */
}
if (macinfo->gldm_GLD_flags & GLD_UNREGISTERED) {
GLDM_UNLOCK(macinfo);
return (EIO); /* this one's not ready any more */
}
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
gsp = mac_pvt->kstatp->ks_data;
ASSERT(gsp);
stats = mac_pvt->statistics;
if (macinfo->gldm_get_stats)
(void) (*macinfo->gldm_get_stats)(macinfo, stats);
gsp->glds_pktxmt.value.ui32 = stats->glds_pktxmt64 & 0xffffffff;
gsp->glds_bytexmt.value.ui32 = stats->glds_bytexmt64 & 0xffffffff;
gsp->glds_multixmt.value.ul = stats->glds_multixmt;
gsp->glds_brdcstxmt.value.ul = stats->glds_brdcstxmt;
gsp->glds_noxmtbuf.value.ul = stats->glds_noxmtbuf; /* 0 for now */
gsp->glds_xmtretry.value.ul = stats->glds_xmtretry;
gsp->glds_pktxmt64.value.ui64 = stats->glds_pktxmt64;
gsp->glds_bytexmt64.value.ui64 = stats->glds_bytexmt64;
gsp->glds_xmtbadinterp.value.ui32 = stats->glds_xmtbadinterp;
gsp->glds_pktrcv.value.ui32 = stats->glds_pktrcv64 & 0xffffffff;
gsp->glds_errxmt.value.ul = stats->glds_errxmt;
gsp->glds_errrcv.value.ul = stats->glds_errrcv;
gsp->glds_bytercv.value.ui32 = stats->glds_bytercv64 & 0xffffffff;
gsp->glds_multircv.value.ul = stats->glds_multircv;
gsp->glds_brdcstrcv.value.ul = stats->glds_brdcstrcv;
gsp->glds_blocked.value.ul = stats->glds_blocked;
gsp->glds_overflow.value.ul = stats->glds_overflow;
gsp->glds_underflow.value.ul = stats->glds_underflow;
gsp->glds_missed.value.ul = stats->glds_missed;
gsp->glds_norcvbuf.value.ul = stats->glds_norcvbuf +
stats->glds_gldnorcvbuf;
gsp->glds_intr.value.ul = stats->glds_intr;
gsp->glds_speed.value.ui64 = stats->glds_speed;
gsp->glds_unknowns.value.ul = stats->glds_unknowns;
gsp->glds_pktrcv64.value.ui64 = stats->glds_pktrcv64;
gsp->glds_bytercv64.value.ui64 = stats->glds_bytercv64;
gsp->glds_rcvbadinterp.value.ui32 = stats->glds_rcvbadinterp;
if (mac_pvt->nprom)
(void) strcpy(gsp->glds_prom.value.c, "phys");
else if (mac_pvt->nprom_multi)
(void) strcpy(gsp->glds_prom.value.c, "multi");
else
(void) strcpy(gsp->glds_prom.value.c, "off");
(void) strcpy(gsp->glds_media.value.c, gld_media[
stats->glds_media < sizeof (gld_media) / sizeof (gld_media[0])
? stats->glds_media : 0]);
switch (macinfo->gldm_type) {
case DL_ETHER:
gsp->glds_frame.value.ul = stats->glds_frame;
gsp->glds_crc.value.ul = stats->glds_crc;
gsp->glds_collisions.value.ul = stats->glds_collisions;
gsp->glds_excoll.value.ul = stats->glds_excoll;
gsp->glds_defer.value.ul = stats->glds_defer;
gsp->glds_short.value.ul = stats->glds_short;
gsp->glds_xmtlatecoll.value.ul = stats->glds_xmtlatecoll;
gsp->glds_nocarrier.value.ul = stats->glds_nocarrier;
gsp->glds_dot3_first_coll.value.ui32 =
stats->glds_dot3_first_coll;
gsp->glds_dot3_multi_coll.value.ui32 =
stats->glds_dot3_multi_coll;
gsp->glds_dot3_sqe_error.value.ui32 =
stats->glds_dot3_sqe_error;
gsp->glds_dot3_mac_xmt_error.value.ui32 =
stats->glds_dot3_mac_xmt_error;
gsp->glds_dot3_mac_rcv_error.value.ui32 =
stats->glds_dot3_mac_rcv_error;
gsp->glds_dot3_frame_too_long.value.ui32 =
stats->glds_dot3_frame_too_long;
(void) strcpy(gsp->glds_duplex.value.c, gld_duplex[
stats->glds_duplex <
sizeof (gld_duplex) / sizeof (gld_duplex[0]) ?
stats->glds_duplex : 0]);
break;
case DL_TPR:
gsp->glds_dot5_line_error.value.ui32 =
stats->glds_dot5_line_error;
gsp->glds_dot5_burst_error.value.ui32 =
stats->glds_dot5_burst_error;
gsp->glds_dot5_signal_loss.value.ui32 =
stats->glds_dot5_signal_loss;
gsp->glds_dot5_ace_error.value.ui32 =
stats->glds_dot5_ace_error;
gsp->glds_dot5_internal_error.value.ui32 =
stats->glds_dot5_internal_error;
gsp->glds_dot5_lost_frame_error.value.ui32 =
stats->glds_dot5_lost_frame_error;
gsp->glds_dot5_frame_copied_error.value.ui32 =
stats->glds_dot5_frame_copied_error;
gsp->glds_dot5_token_error.value.ui32 =
stats->glds_dot5_token_error;
gsp->glds_dot5_freq_error.value.ui32 =
stats->glds_dot5_freq_error;
break;
case DL_FDDI:
gsp->glds_fddi_mac_error.value.ui32 =
stats->glds_fddi_mac_error;
gsp->glds_fddi_mac_lost.value.ui32 =
stats->glds_fddi_mac_lost;
gsp->glds_fddi_mac_token.value.ui32 =
stats->glds_fddi_mac_token;
gsp->glds_fddi_mac_tvx_expired.value.ui32 =
stats->glds_fddi_mac_tvx_expired;
gsp->glds_fddi_mac_late.value.ui32 =
stats->glds_fddi_mac_late;
gsp->glds_fddi_mac_ring_op.value.ui32 =
stats->glds_fddi_mac_ring_op;
break;
case DL_IB:
break;
default:
break;
}
GLDM_UNLOCK(macinfo);
#ifdef GLD_DEBUG
gld_check_assertions();
if (gld_debug & GLDRDE)
gld_sr_dump(macinfo);
#endif
return (0);
}
static int
gld_init_vlan_stats(gld_vlan_t *vlan)
{
gld_mac_info_t *mac = vlan->gldv_mac;
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)mac->gldm_mac_pvt;
struct gldkstats *sp;
glddev_t *glddev;
kstat_t *ksp;
char *name;
int instance;
glddev = mac_pvt->major_dev;
name = glddev->gld_name;
instance = (vlan->gldv_id * GLD_VLAN_SCALE) + mac->gldm_ppa;
if ((ksp = kstat_create(name, instance,
NULL, "net", KSTAT_TYPE_NAMED,
sizeof (struct gldkstats) / sizeof (kstat_named_t), 0)) == NULL) {
cmn_err(CE_WARN,
"GLD: failed to create kstat structure for %s%d",
name, instance);
return (GLD_FAILURE);
}
vlan->gldv_kstatp = ksp;
ksp->ks_update = gld_update_vlan_kstat;
ksp->ks_private = (void *)vlan;
sp = ksp->ks_data;
kstat_named_init(&sp->glds_pktrcv, "ipackets", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_pktxmt, "opackets", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_errrcv, "ierrors", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_errxmt, "oerrors", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_bytexmt, "obytes", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_bytercv, "rbytes", KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_multixmt, "multixmt", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_multircv, "multircv", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_brdcstxmt, "brdcstxmt", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_brdcstrcv, "brdcstrcv", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_blocked, "blocked", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_noxmtbuf, "noxmtbuf", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_norcvbuf, "norcvbuf", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_xmtretry, "xmtretry", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_intr, "intr", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_pktrcv64, "ipackets64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_pktxmt64, "opackets64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_bytexmt64, "obytes64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_bytercv64, "rbytes64", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_unknowns, "unknowns", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_speed, "ifspeed", KSTAT_DATA_UINT64);
kstat_named_init(&sp->glds_media, "media", KSTAT_DATA_CHAR);
kstat_named_init(&sp->glds_prom, "promisc", KSTAT_DATA_CHAR);
kstat_named_init(&sp->glds_overflow, "oflo", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_underflow, "uflo", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_missed, "missed", KSTAT_DATA_ULONG);
kstat_named_init(&sp->glds_xmtbadinterp, "xmt_badinterp",
KSTAT_DATA_UINT32);
kstat_named_init(&sp->glds_rcvbadinterp, "rcv_badinterp",
KSTAT_DATA_UINT32);
kstat_install(ksp);
return (GLD_SUCCESS);
}
static int
gld_update_vlan_kstat(kstat_t *ksp, int rw)
{
gld_vlan_t *vlan;
gld_mac_info_t *macinfo;
struct gldkstats *gsp;
struct gld_stats *stats;
gld_mac_pvt_t *mac_pvt;
uint32_t media;
if (rw == KSTAT_WRITE)
return (EACCES);
vlan = (gld_vlan_t *)ksp->ks_private;
ASSERT(vlan != NULL);
macinfo = vlan->gldv_mac;
GLDM_LOCK(macinfo, RW_WRITER);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
gsp = vlan->gldv_kstatp->ks_data;
ASSERT(gsp);
stats = vlan->gldv_stats;
gsp->glds_pktxmt.value.ui32 = stats->glds_pktxmt64 & 0xffffffff;
gsp->glds_bytexmt.value.ui32 = stats->glds_bytexmt64 & 0xffffffff;
gsp->glds_errxmt.value.ul = stats->glds_errxmt;
gsp->glds_multixmt.value.ul = stats->glds_multixmt;
gsp->glds_brdcstxmt.value.ul = stats->glds_brdcstxmt;
gsp->glds_noxmtbuf.value.ul = stats->glds_noxmtbuf;
gsp->glds_xmtretry.value.ul = stats->glds_xmtretry;
gsp->glds_pktxmt64.value.ui64 = stats->glds_pktxmt64;
gsp->glds_bytexmt64.value.ui64 = stats->glds_bytexmt64;
gsp->glds_pktrcv.value.ui32 = stats->glds_pktrcv64 & 0xffffffff;
gsp->glds_bytercv.value.ui32 = stats->glds_bytercv64 & 0xffffffff;
gsp->glds_errrcv.value.ul = stats->glds_errrcv;
gsp->glds_multircv.value.ul = stats->glds_multircv;
gsp->glds_brdcstrcv.value.ul = stats->glds_brdcstrcv;
gsp->glds_blocked.value.ul = stats->glds_blocked;
gsp->glds_pktrcv64.value.ui64 = stats->glds_pktrcv64;
gsp->glds_bytercv64.value.ui64 = stats->glds_bytercv64;
gsp->glds_unknowns.value.ul = stats->glds_unknowns;
gsp->glds_xmtbadinterp.value.ui32 = stats->glds_xmtbadinterp;
gsp->glds_rcvbadinterp.value.ui32 = stats->glds_rcvbadinterp;
gsp->glds_speed.value.ui64 = mac_pvt->statistics->glds_speed;
media = mac_pvt->statistics->glds_media;
(void) strcpy(gsp->glds_media.value.c,
gld_media[media < sizeof (gld_media) / sizeof (gld_media[0]) ?
media : 0]);
GLDM_UNLOCK(macinfo);
return (0);
}
/*
* The device dependent driver specifies gld_getinfo as its getinfo routine.
*/
/*ARGSUSED*/
int
gld_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **resultp)
{
dev_info_t *devinfo;
minor_t minor = getminor((dev_t)arg);
int rc = DDI_FAILURE;
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
if ((devinfo = gld_finddevinfo((dev_t)arg)) != NULL) {
*(dev_info_t **)resultp = devinfo;
rc = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
/* Need static mapping for deferred attach */
if (minor == GLD_USE_STYLE2) {
/*
* Style 2: this minor number does not correspond to
* any particular instance number.
*/
rc = DDI_FAILURE;
} else if (minor <= GLD_MAX_STYLE1_MINOR) {
/* Style 1: calculate the PPA from the minor */
*resultp = (void *)(uintptr_t)
GLD_STYLE1_MINOR_TO_PPA(minor);
rc = DDI_SUCCESS;
} else {
/* Clone: look for it. Not a static mapping */
if ((devinfo = gld_finddevinfo((dev_t)arg)) != NULL) {
*resultp = (void *)(uintptr_t)
ddi_get_instance(devinfo);
rc = DDI_SUCCESS;
}
}
break;
}
return (rc);
}
/* called from gld_getinfo */
dev_info_t *
gld_finddevinfo(dev_t dev)
{
minor_t minor = getminor(dev);
glddev_t *device;
gld_mac_info_t *mac;
gld_vlan_t *vlan;
gld_t *str;
dev_info_t *devinfo = NULL;
int i;
if (minor == GLD_USE_STYLE2) {
/*
* Style 2: this minor number does not correspond to
* any particular instance number.
*
* XXX We don't know what to say. See Bug 1165519.
*/
return (NULL);
}
mutex_enter(&gld_device_list.gld_devlock); /* hold the device */
device = gld_devlookup(getmajor(dev));
if (device == NULL) {
/* There are no attached instances of this device */
mutex_exit(&gld_device_list.gld_devlock);
return (NULL);
}
/*
* Search all attached macs and streams.
*
* XXX We don't bother checking the DL_UNATTACHED streams since
* we don't know what devinfo we should report back even if we
* found the minor. Maybe we should associate streams that are
* not currently attached to a PPA with the "first" devinfo node
* of the major device to attach -- the one that created the
* minor node for the generic device.
*/
mutex_enter(&device->gld_devlock);
for (mac = device->gld_mac_next;
mac != (gld_mac_info_t *)&device->gld_mac_next;
mac = mac->gldm_next) {
gld_mac_pvt_t *pvt = (gld_mac_pvt_t *)mac->gldm_mac_pvt;
if (!(mac->gldm_GLD_flags & GLD_MAC_READY))
continue; /* this one's not ready yet */
if (minor <= GLD_MAX_STYLE1_MINOR) {
/* Style 1 -- look for the corresponding PPA */
if (minor == GLD_STYLE1_PPA_TO_MINOR(mac->gldm_ppa)) {
devinfo = mac->gldm_devinfo;
goto out; /* found it! */
} else
continue; /* not this PPA */
}
/* We are looking for a clone */
for (i = 0; i < VLAN_HASHSZ; i++) {
for (vlan = pvt->vlan_hash[i];
vlan != NULL; vlan = vlan->gldv_next) {
for (str = vlan->gldv_str_next;
str != (gld_t *)&vlan->gldv_str_next;
str = str->gld_next) {
ASSERT(str->gld_mac_info == mac);
if (minor == str->gld_minor) {
devinfo = mac->gldm_devinfo;
goto out;
}
}
}
}
}
out:
mutex_exit(&device->gld_devlock);
mutex_exit(&gld_device_list.gld_devlock);
return (devinfo);
}
/*
* STREAMS open routine. The device dependent driver specifies this as its
* open entry point.
*/
/*ARGSUSED2*/
int
gld_open(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *cred)
{
gld_mac_pvt_t *mac_pvt;
gld_t *gld;
glddev_t *glddev;
gld_mac_info_t *macinfo;
minor_t minor = getminor(*dev);
gld_vlan_t *vlan;
t_uscalar_t ppa;
ASSERT(q != NULL);
if (minor > GLD_MAX_STYLE1_MINOR)
return (ENXIO);
ASSERT(q->q_ptr == NULL); /* Clone device gives us a fresh Q */
/* Find our per-major glddev_t structure */
mutex_enter(&gld_device_list.gld_devlock);
glddev = gld_devlookup(getmajor(*dev));
/*
* This glddev will hang around since detach (and therefore
* gld_unregister) can't run while we're here in the open routine.
*/
mutex_exit(&gld_device_list.gld_devlock);
if (glddev == NULL)
return (ENXIO);
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT) {
if (minor == GLD_USE_STYLE2)
cmn_err(CE_NOTE, "gld_open(%p, Style 2)", (void *)q);
else
cmn_err(CE_NOTE, "gld_open(%p, Style 1, minor = %d)",
(void *)q, minor);
}
#endif
/*
* get a per-stream structure and link things together so we
* can easily find them later.
*/
gld = kmem_zalloc(sizeof (gld_t), KM_SLEEP);
/*
* fill in the structure and state info
*/
gld->gld_qptr = q;
gld->gld_device = glddev;
gld->gld_state = DL_UNATTACHED;
/*
* we must atomically find a free minor number and add the stream
* to a list, because gld_findminor has to traverse the lists to
* determine which minor numbers are free.
*/
mutex_enter(&glddev->gld_devlock);
/* find a free minor device number for the clone */
gld->gld_minor = gld_findminor(glddev);
if (gld->gld_minor == 0) {
mutex_exit(&glddev->gld_devlock);
kmem_free(gld, sizeof (gld_t));
return (ENOSR);
}
#ifdef GLD_VERBOSE_DEBUG
if (gld_debug & GLDPROT)
cmn_err(CE_NOTE, "gld_open() gld ptr: %p minor: %d",
(void *)gld, gld->gld_minor);
#endif
if (minor == GLD_USE_STYLE2) {
gld->gld_style = DL_STYLE2;
*dev = makedevice(getmajor(*dev), gld->gld_minor);
WR(q)->q_ptr = q->q_ptr = (caddr_t)gld;
gldinsque(gld, glddev->gld_str_prev);
#ifdef GLD_VERBOSE_DEBUG
if (gld_debug & GLDPROT)
cmn_err(CE_NOTE, "GLDstruct added to device list");
#endif
(void) qassociate(q, -1);
goto done;
}
gld->gld_style = DL_STYLE1;
/* the PPA is actually 1 less than the minordev */
ppa = GLD_STYLE1_MINOR_TO_PPA(minor);
for (macinfo = glddev->gld_mac_next;
macinfo != (gld_mac_info_t *)(&glddev->gld_mac_next);
macinfo = macinfo->gldm_next) {
ASSERT(macinfo != NULL);
if (macinfo->gldm_ppa != ppa)
continue;
if (!(macinfo->gldm_GLD_flags & GLD_MAC_READY))
continue; /* this one's not ready yet */
/*
* we found the correct PPA
*/
GLDM_LOCK(macinfo, RW_WRITER);
gld->gld_mac_info = macinfo;
if (macinfo->gldm_send_tagged != NULL)
gld->gld_send = macinfo->gldm_send_tagged;
else
gld->gld_send = macinfo->gldm_send;
/* now ready for action */
gld->gld_state = DL_UNBOUND;
if ((vlan = gld_get_vlan(macinfo, VLAN_VID_NONE)) == NULL) {
GLDM_UNLOCK(macinfo);
mutex_exit(&glddev->gld_devlock);
kmem_free(gld, sizeof (gld_t));
return (EIO);
}
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
if (!mac_pvt->started) {
if (gld_start_mac(macinfo) != GLD_SUCCESS) {
gld_rem_vlan(vlan);
GLDM_UNLOCK(macinfo);
mutex_exit(&glddev->gld_devlock);
kmem_free(gld, sizeof (gld_t));
return (EIO);
}
}
gld->gld_vlan = vlan;
vlan->gldv_nstreams++;
gldinsque(gld, vlan->gldv_str_prev);
*dev = makedevice(getmajor(*dev), gld->gld_minor);
WR(q)->q_ptr = q->q_ptr = (caddr_t)gld;
GLDM_UNLOCK(macinfo);
#ifdef GLD_VERBOSE_DEBUG
if (gld_debug & GLDPROT)
cmn_err(CE_NOTE,
"GLDstruct added to instance list");
#endif
break;
}
if (gld->gld_state == DL_UNATTACHED) {
mutex_exit(&glddev->gld_devlock);
kmem_free(gld, sizeof (gld_t));
return (ENXIO);
}
done:
mutex_exit(&glddev->gld_devlock);
noenable(WR(q)); /* We'll do the qenables manually */
qprocson(q); /* start the queues running */
qenable(WR(q));
return (0);
}
/*
* normal stream close call checks current status and cleans up
* data structures that were dynamically allocated
*/
/*ARGSUSED1*/
int
gld_close(queue_t *q, int flag, cred_t *cred)
{
gld_t *gld = (gld_t *)q->q_ptr;
glddev_t *glddev = gld->gld_device;
ASSERT(q);
ASSERT(gld);
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT) {
cmn_err(CE_NOTE, "gld_close(%p, Style %d)",
(void *)q, (gld->gld_style & 0x1) + 1);
}
#endif
/* Hold all device streams lists still while we check for a macinfo */
mutex_enter(&glddev->gld_devlock);
if (gld->gld_mac_info != NULL) {
/* If there's a macinfo, block recv while we change state */
GLDM_LOCK(gld->gld_mac_info, RW_WRITER);
gld->gld_flags |= GLD_STR_CLOSING; /* no more rcv putnexts */
GLDM_UNLOCK(gld->gld_mac_info);
} else {
/* no mac DL_ATTACHED right now */
gld->gld_flags |= GLD_STR_CLOSING;
}
mutex_exit(&glddev->gld_devlock);
/*
* qprocsoff before we call gld_unbind/gldunattach, so that
* we know wsrv isn't in there trying to undo what we're doing.
*/
qprocsoff(q);
ASSERT(gld->gld_wput_count == 0);
gld->gld_wput_count = 0; /* just in case */
if (gld->gld_state == DL_IDLE) {
/* Need to unbind */
ASSERT(gld->gld_mac_info != NULL);
(void) gld_unbind(WR(q), NULL);
}
if (gld->gld_state == DL_UNBOUND) {
/*
* Need to unattach
* For style 2 stream, gldunattach also
* associate queue with NULL dip
*/
ASSERT(gld->gld_mac_info != NULL);
(void) gldunattach(WR(q), NULL);
}
/* disassociate the stream from the device */
q->q_ptr = WR(q)->q_ptr = NULL;
/*
* Since we unattached above (if necessary), we know that we're
* on the per-major list of unattached streams, rather than a
* per-PPA list. So we know we should hold the devlock.
*/
mutex_enter(&glddev->gld_devlock);
gldremque(gld); /* remove from Style 2 list */
mutex_exit(&glddev->gld_devlock);
kmem_free(gld, sizeof (gld_t));
return (0);
}
/*
* gld_rsrv (q)
* simple read service procedure
* purpose is to avoid the time it takes for packets
* to move through IP so we can get them off the board
* as fast as possible due to limited PC resources.
*
* This is not normally used in the current implementation. It
* can be selected with the undocumented property "fast_recv".
* If that property is set, gld_recv will send the packet
* upstream with a putq() rather than a putnext(), thus causing
* this routine to be scheduled.
*/
int
gld_rsrv(queue_t *q)
{
mblk_t *mp;
while ((mp = getq(q)) != NULL) {
if (canputnext(q)) {
putnext(q, mp);
} else {
freemsg(mp);
}
}
return (0);
}
/*
* gld_wput (q, mp)
* general gld stream write put routine. Receives fastpath data from upper
* modules and processes it immediately. ioctl and M_PROTO/M_PCPROTO are
* queued for later processing by the service procedure.
*/
int
gld_wput(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)(q->q_ptr);
int rc;
boolean_t multidata = B_TRUE;
uint32_t upri;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_wput(%p %p): type %x",
(void *)q, (void *)mp, DB_TYPE(mp));
#endif
switch (DB_TYPE(mp)) {
case M_DATA:
/* fast data / raw support */
/* we must be DL_ATTACHED and DL_BOUND to do this */
/* Tricky to access memory without taking the mutex */
if ((gld->gld_flags & (GLD_RAW | GLD_FAST)) == 0 ||
gld->gld_state != DL_IDLE) {
merror(q, mp, EPROTO);
break;
}
/*
* Cleanup MBLK_VTAG in case it is set by other
* modules. MBLK_VTAG is used to save the vtag information.
*/
GLD_CLEAR_MBLK_VTAG(mp);
multidata = B_FALSE;
/* FALLTHROUGH */
case M_MULTIDATA:
/* Only call gld_start() directly if nothing queued ahead */
/* No guarantees about ordering with different threads */
if (q->q_first)
goto use_wsrv;
/*
* This can happen if wsrv has taken off the last mblk but
* is still processing it.
*/
membar_consumer();
if (gld->gld_in_wsrv)
goto use_wsrv;
/*
* Keep a count of current wput calls to start.
* Nonzero count delays any attempted DL_UNBIND.
* See comments above gld_start().
*/
atomic_inc_32((uint32_t *)&gld->gld_wput_count);
membar_enter();
/* Recheck state now wput_count is set to prevent DL_UNBIND */
/* If this Q is in process of DL_UNBIND, don't call start */
if (gld->gld_state != DL_IDLE || gld->gld_in_unbind) {
/* Extremely unlikely */
atomic_dec_32((uint32_t *)&gld->gld_wput_count);
goto use_wsrv;
}
/*
* Get the priority value. Note that in raw mode, the
* per-packet priority value kept in b_band is ignored.
*/
upri = (gld->gld_flags & GLD_RAW) ? gld->gld_upri :
UPRI(gld, mp->b_band);
rc = (multidata) ? gld_start_mdt(q, mp, GLD_WPUT) :
gld_start(q, mp, GLD_WPUT, upri);
/* Allow DL_UNBIND again */
membar_exit();
atomic_dec_32((uint32_t *)&gld->gld_wput_count);
if (rc == GLD_NORESOURCES)
qenable(q);
break; /* Done with this packet */
use_wsrv:
/* Q not empty, in DL_DETACH, or start gave NORESOURCES */
(void) putq(q, mp);
qenable(q);
break;
case M_IOCTL:
/* ioctl relies on wsrv single threading per queue */
(void) putq(q, mp);
qenable(q);
break;
case M_CTL:
(void) putq(q, mp);
qenable(q);
break;
case M_FLUSH: /* canonical flush handling */
/* XXX Should these be FLUSHALL? */
if (*mp->b_rptr & FLUSHW)
flushq(q, 0);
if (*mp->b_rptr & FLUSHR) {
flushq(RD(q), 0);
*mp->b_rptr &= ~FLUSHW;
qreply(q, mp);
} else
freemsg(mp);
break;
case M_PROTO:
case M_PCPROTO:
/* these rely on wsrv single threading per queue */
(void) putq(q, mp);
qenable(q);
break;
default:
#ifdef GLD_DEBUG
if (gld_debug & GLDETRACE)
cmn_err(CE_WARN,
"gld: Unexpected packet type from queue: 0x%x",
DB_TYPE(mp));
#endif
freemsg(mp);
}
return (0);
}
/*
* gld_wsrv - Incoming messages are processed according to the DLPI protocol
* specification.
*
* wsrv is single-threaded per Q. We make use of this to avoid taking the
* lock for reading data items that are only ever written by us.
*/
int
gld_wsrv(queue_t *q)
{
mblk_t *mp;
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo;
union DL_primitives *prim;
int err;
boolean_t multidata;
uint32_t upri;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_wsrv(%p)", (void *)q);
#endif
ASSERT(!gld->gld_in_wsrv);
gld->gld_xwait = B_FALSE; /* We are now going to process this Q */
if (q->q_first == NULL)
return (0);
macinfo = gld->gld_mac_info;
/*
* Help wput avoid a call to gld_start if there might be a message
* previously queued by that thread being processed here.
*/
gld->gld_in_wsrv = B_TRUE;
membar_enter();
while ((mp = getq(q)) != NULL) {
switch (DB_TYPE(mp)) {
case M_DATA:
case M_MULTIDATA:
multidata = (DB_TYPE(mp) == M_MULTIDATA);
/*
* retry of a previously processed UNITDATA_REQ
* or is a RAW or FAST message from above.
*/
if (macinfo == NULL) {
/* No longer attached to a PPA, drop packet */
freemsg(mp);
break;
}
gld->gld_sched_ran = B_FALSE;
membar_enter();
/*
* Get the priority value. Note that in raw mode, the
* per-packet priority value kept in b_band is ignored.
*/
upri = (gld->gld_flags & GLD_RAW) ? gld->gld_upri :
UPRI(gld, mp->b_band);
err = (multidata) ? gld_start_mdt(q, mp, GLD_WSRV) :
gld_start(q, mp, GLD_WSRV, upri);
if (err == GLD_NORESOURCES) {
/* gld_sched will qenable us later */
gld->gld_xwait = B_TRUE; /* want qenable */
membar_enter();
/*
* v2: we're not holding the lock; it's
* possible that the driver could have already
* called gld_sched (following up on its
* return of GLD_NORESOURCES), before we got a
* chance to do the putbq() and set gld_xwait.
* So if we saw a call to gld_sched that
* examined this queue, since our call to
* gld_start() above, then it's possible we've
* already seen the only call to gld_sched()
* we're ever going to see. So we better retry
* transmitting this packet right now.
*/
if (gld->gld_sched_ran) {
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_wsrv: "
"sched was called");
#endif
break; /* try again right now */
}
gld->gld_in_wsrv = B_FALSE;
return (0);
}
break;
case M_IOCTL:
(void) gld_ioctl(q, mp);
break;
case M_CTL:
if (macinfo == NULL) {
freemsg(mp);
break;
}
if (macinfo->gldm_mctl != NULL) {
GLDM_LOCK(macinfo, RW_WRITER);
(void) (*macinfo->gldm_mctl) (macinfo, q, mp);
GLDM_UNLOCK(macinfo);
} else {
/* This driver doesn't recognize, just drop */
freemsg(mp);
}
break;
case M_PROTO: /* Will be an DLPI message of some type */
case M_PCPROTO:
if ((err = gld_cmds(q, mp)) != GLDE_OK) {
if (err == GLDE_RETRY) {
gld->gld_in_wsrv = B_FALSE;
return (0); /* quit while we're ahead */
}
prim = (union DL_primitives *)mp->b_rptr;
dlerrorack(q, mp, prim->dl_primitive, err, 0);
}
break;
default:
/* This should never happen */
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_wsrv: db_type(%x) not supported",
mp->b_datap->db_type);
#endif
freemsg(mp); /* unknown types are discarded */
break;
}
}
membar_exit();
gld->gld_in_wsrv = B_FALSE;
return (0);
}
/*
* gld_start() can get called from gld_wput(), gld_wsrv(), or gld_unitdata().
*
* We only come directly from wput() in the GLD_FAST (fastpath) or RAW case.
*
* In particular, we must avoid calling gld_precv*() if we came from wput().
* gld_precv*() is where we, on the transmit side, loop back our outgoing
* packets to the receive side if we are in physical promiscuous mode.
* Since the receive side holds a lock across its call to the upstream
* putnext, and that upstream module could well have looped back to our
* wput() routine on the same thread, we cannot call gld_precv* from here
* for fear of causing a recursive lock entry in our receive code.
*
* There is a problem here when coming from gld_wput(). While wput
* only comes here if the queue is attached to a PPA and bound to a SAP
* and there are no messages on the queue ahead of the M_DATA that could
* change that, it is theoretically possible that another thread could
* now wput a DL_UNBIND and a DL_DETACH message, and the wsrv() routine
* could wake up and process them, before we finish processing this
* send of the M_DATA. This can only possibly happen on a Style 2 RAW or
* FAST (fastpath) stream: non RAW/FAST streams always go through wsrv(),
* and Style 1 streams only DL_DETACH in the close routine, where
* qprocsoff() protects us. If this happens we could end up calling
* gldm_send() after we have detached the stream and possibly called
* gldm_stop(). Worse, once the number of attached streams goes to zero,
* detach/unregister could be called, and the macinfo could go away entirely.
*
* No one has ever seen this happen.
*
* It is some trouble to fix this, and we would rather not add any mutex
* logic into the wput() routine, which is supposed to be a "fast"
* path.
*
* What I've done is use an atomic counter to keep a count of the number
* of threads currently calling gld_start() from wput() on this stream.
* If DL_DETACH sees this as nonzero, it putbqs the request back onto
* the queue and qenables, hoping to have better luck next time. Since
* people shouldn't be trying to send after they've asked to DL_DETACH,
* hopefully very soon all the wput=>start threads should have returned
* and the DL_DETACH will succeed. It's hard to test this since the odds
* of the failure even trying to happen are so small. I probably could
* have ignored the whole issue and never been the worse for it.
*
* Because some GLDv2 Ethernet drivers do not allow the size of transmitted
* packet to be greater than ETHERMAX, we must first strip the VLAN tag
* from a tagged packet before passing it to the driver's gld_send() entry
* point function, and pass the VLAN tag as a separate argument. The
* gld_send() function may fail. In that case, the packet will need to be
* queued in order to be processed again in GLD's service routine. As the
* VTAG has already been stripped at that time, we save the VTAG information
* in (the unused fields of) dblk using GLD_SAVE_MBLK_VTAG(), so that the
* VTAG can also be queued and be able to be got when gld_start() is called
* next time from gld_wsrv().
*
* Some rules to use GLD_{CLEAR|SAVE}_MBLK_VTAG macros:
*
* - GLD_SAVE_MBLK_VTAG() must be called to save the VTAG information each time
* the message is queued by putbq().
*
* - GLD_CLEAR_MBLK_VTAG() must be called to clear the bogus VTAG information
* (if any) in dblk before the message is passed to the gld_start() function.
*/
static int
gld_start(queue_t *q, mblk_t *mp, int caller, uint32_t upri)
{
mblk_t *nmp;
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo;
gld_mac_pvt_t *mac_pvt;
int rc;
gld_interface_t *ifp;
pktinfo_t pktinfo;
uint32_t vtag, vid;
uint32_t raw_vtag = 0;
gld_vlan_t *vlan;
struct gld_stats *stats0, *stats = NULL;
ASSERT(DB_TYPE(mp) == M_DATA);
macinfo = gld->gld_mac_info;
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
ifp = mac_pvt->interfacep;
vlan = (gld_vlan_t *)gld->gld_vlan;
vid = vlan->gldv_id;
/*
* If this interface is a VLAN, the kstats of corresponding
* "VLAN 0" should also be updated. Note that the gld_vlan_t
* structure for VLAN 0 might not exist if there are no DLPI
* consumers attaching on VLAN 0. Fortunately we can directly
* access VLAN 0's kstats from macinfo.
*
* Therefore, stats0 (VLAN 0's kstats) must always be
* updated, and stats must to be updated if it is not NULL.
*/
stats0 = mac_pvt->statistics;
if (vid != VLAN_VID_NONE)
stats = vlan->gldv_stats;
if ((*ifp->interpreter)(macinfo, mp, &pktinfo, GLD_TX) != 0) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_start: failed to interpret outbound packet");
#endif
goto badarg;
}
vtag = VLAN_VID_NONE;
raw_vtag = GLD_GET_MBLK_VTAG(mp);
if (GLD_VTAG_TCI(raw_vtag) != 0) {
uint16_t raw_pri, raw_vid, evid;
/*
* Tagged packet.
*/
raw_pri = GLD_VTAG_PRI(raw_vtag);
raw_vid = GLD_VTAG_VID(raw_vtag);
GLD_CLEAR_MBLK_VTAG(mp);
if (gld->gld_flags & GLD_RAW) {
/*
* In raw mode, we only expect untagged packets or
* special priority-tagged packets on a VLAN stream.
* Drop the packet if its VID is not zero.
*/
if (vid != VLAN_VID_NONE && raw_vid != VLAN_VID_NONE)
goto badarg;
/*
* If it is raw mode, use the per-stream priority if
* the priority is not specified in the packet.
* Otherwise, ignore the priority bits in the packet.
*/
upri = (raw_pri != 0) ? raw_pri : upri;
}
if (vid == VLAN_VID_NONE && vid != raw_vid) {
gld_vlan_t *tmp_vlan;
/*
* This link is a physical link but the packet is
* a VLAN tagged packet, the kstats of corresponding
* VLAN (if any) should also be updated.
*/
tmp_vlan = gld_find_vlan(macinfo, raw_vid);
if (tmp_vlan != NULL)
stats = tmp_vlan->gldv_stats;
}
evid = (vid == VLAN_VID_NONE) ? raw_vid : vid;
if (evid != VLAN_VID_NONE || upri != 0)
vtag = GLD_MAKE_VTAG(upri, VLAN_CFI_ETHER, evid);
} else {
/*
* Untagged packet:
* Get vtag from the attached PPA of this stream.
*/
if ((vid != VLAN_VID_NONE) ||
((macinfo->gldm_type == DL_ETHER) && (upri != 0))) {
vtag = GLD_MAKE_VTAG(upri, VLAN_CFI_ETHER, vid);
}
}
/*
* We're not holding the lock for this check. If the promiscuous
* state is in flux it doesn't matter much if we get this wrong.
*/
if (mac_pvt->nprom > 0) {
/*
* We want to loopback to the receive side, but to avoid
* recursive lock entry: if we came from wput(), which
* could have looped back via IP from our own receive
* interrupt thread, we decline this request. wput()
* will then queue the packet for wsrv(). This means
* that when snoop is running we don't get the advantage
* of the wput() multithreaded direct entry to the
* driver's send routine.
*/
if (caller == GLD_WPUT) {
GLD_SAVE_MBLK_VTAG(mp, raw_vtag);
(void) putbq(q, mp);
return (GLD_NORESOURCES);
}
if (macinfo->gldm_capabilities & GLD_CAP_ZEROCOPY)
nmp = dupmsg_noloan(mp);
else
nmp = dupmsg(mp);
} else
nmp = NULL; /* we need no loopback */
if (ifp->hdr_size > 0 &&
pktinfo.pktLen > ifp->hdr_size + (vtag == 0 ? 0 : VTAG_SIZE) +
macinfo->gldm_maxpkt) {
if (nmp)
freemsg(nmp); /* free the duped message */
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_start: oversize outbound packet, size %d,"
"max %d", pktinfo.pktLen,
ifp->hdr_size + (vtag == 0 ? 0 : VTAG_SIZE) +
macinfo->gldm_maxpkt);
#endif
goto badarg;
}
rc = (*gld->gld_send)(macinfo, mp, vtag);
if (rc != GLD_SUCCESS) {
if (rc == GLD_NORESOURCES) {
ATOMIC_BUMP(stats0, stats, glds_xmtretry, 1);
GLD_SAVE_MBLK_VTAG(mp, raw_vtag);
(void) putbq(q, mp);
} else {
/* transmit error; drop the packet */
freemsg(mp);
/* We're supposed to count failed attempts as well */
UPDATE_STATS(stats0, stats, pktinfo, 1);
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_start: gldm_send failed %d", rc);
#endif
}
if (nmp)
freemsg(nmp); /* free the dupped message */
return (rc);
}
UPDATE_STATS(stats0, stats, pktinfo, 1);
/*
* Loopback case. The message needs to be returned back on
* the read side. This would silently fail if the dupmsg fails
* above. This is probably OK, if there is no memory to dup the
* block, then there isn't much we could do anyway.
*/
if (nmp) {
GLDM_LOCK(macinfo, RW_WRITER);
gld_precv(macinfo, nmp, vtag, stats);
GLDM_UNLOCK(macinfo);
}
return (GLD_SUCCESS);
badarg:
freemsg(mp);
ATOMIC_BUMP(stats0, stats, glds_xmtbadinterp, 1);
return (GLD_BADARG);
}
/*
* With MDT V.2 a single message mp can have one header area and multiple
* payload areas. A packet is described by dl_pkt_info, and each packet can
* span multiple payload areas (currently with TCP, each packet will have one
* header and at the most two payload areas). MACs might have a limit on the
* number of payload segments (i.e. per packet scatter-gather limit), and
* MDT V.2 has a way of specifying that with mdt_span_limit; the MAC driver
* might also have a limit on the total number of payloads in a message, and
* that is specified by mdt_max_pld.
*/
static int
gld_start_mdt(queue_t *q, mblk_t *mp, int caller)
{
mblk_t *nextmp;
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo = gld->gld_mac_info;
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
int numpacks, mdtpacks;
gld_interface_t *ifp = mac_pvt->interfacep;
pktinfo_t pktinfo;
gld_vlan_t *vlan = (gld_vlan_t *)gld->gld_vlan;
boolean_t doloop = B_FALSE;
multidata_t *dlmdp;
pdescinfo_t pinfo;
pdesc_t *dl_pkt;
void *cookie;
uint_t totLen = 0;
ASSERT(DB_TYPE(mp) == M_MULTIDATA);
/*
* We're not holding the lock for this check. If the promiscuous
* state is in flux it doesn't matter much if we get this wrong.
*/
if (mac_pvt->nprom > 0) {
/*
* We want to loopback to the receive side, but to avoid
* recursive lock entry: if we came from wput(), which
* could have looped back via IP from our own receive
* interrupt thread, we decline this request. wput()
* will then queue the packet for wsrv(). This means
* that when snoop is running we don't get the advantage
* of the wput() multithreaded direct entry to the
* driver's send routine.
*/
if (caller == GLD_WPUT) {
(void) putbq(q, mp);
return (GLD_NORESOURCES);
}
doloop = B_TRUE;
/*
* unlike the M_DATA case, we don't have to call
* dupmsg_noloan here because mmd_transform
* (called by gld_precv_mdt) will make a copy of
* each dblk.
*/
}
while (mp != NULL) {
/*
* The lower layer driver only gets a single multidata
* message; this also makes it easier to handle noresources.
*/
nextmp = mp->b_cont;
mp->b_cont = NULL;
/*
* Get number of packets in this message; if nothing
* to transmit, go to next message.
*/
dlmdp = mmd_getmultidata(mp);
if ((mdtpacks = (int)mmd_getcnt(dlmdp, NULL, NULL)) == 0) {
freemsg(mp);
mp = nextmp;
continue;
}
/*
* Run interpreter to populate media specific pktinfo fields.
* This collects per MDT message information like sap,
* broad/multicast etc.
*/
(void) (*ifp->interpreter_mdt)(macinfo, mp, NULL, &pktinfo,
GLD_MDT_TX);
numpacks = (*macinfo->gldm_mdt_pre)(macinfo, mp, &cookie);
if (numpacks > 0) {
/*
* Driver indicates it can transmit at least 1, and
* possibly all, packets in MDT message.
*/
int count = numpacks;
for (dl_pkt = mmd_getfirstpdesc(dlmdp, &pinfo);
(dl_pkt != NULL);
dl_pkt = mmd_getnextpdesc(dl_pkt, &pinfo)) {
/*
* Format this packet by adding link header and
* adjusting pdescinfo to include it; get
* packet length.
*/
(void) (*ifp->interpreter_mdt)(macinfo, NULL,
&pinfo, &pktinfo, GLD_MDT_TXPKT);
totLen += pktinfo.pktLen;
/*
* Loop back packet before handing to the
* driver.
*/
if (doloop &&
mmd_adjpdesc(dl_pkt, &pinfo) != NULL) {
GLDM_LOCK(macinfo, RW_WRITER);
gld_precv_mdt(macinfo, vlan, mp,
dl_pkt, &pktinfo);
GLDM_UNLOCK(macinfo);
}
/*
* And send off to driver.
*/
(*macinfo->gldm_mdt_send)(macinfo, cookie,
&pinfo);
/*
* Be careful not to invoke getnextpdesc if we
* already sent the last packet, since driver
* might have posted it to hardware causing a
* completion and freemsg() so the MDT data
* structures might not be valid anymore.
*/
if (--count == 0)
break;
}
(*macinfo->gldm_mdt_post)(macinfo, mp, cookie);
pktinfo.pktLen = totLen;
UPDATE_STATS(vlan->gldv_stats, NULL, pktinfo, numpacks);
/*
* In the noresources case (when driver indicates it
* can not transmit all packets in the MDT message),
* adjust to skip the first few packets on retrial.
*/
if (numpacks != mdtpacks) {
/*
* Release already processed packet descriptors.
*/
for (count = 0; count < numpacks; count++) {
dl_pkt = mmd_getfirstpdesc(dlmdp,
&pinfo);
mmd_rempdesc(dl_pkt);
}
ATOMIC_BUMP(vlan->gldv_stats, NULL,
glds_xmtretry, 1);
mp->b_cont = nextmp;
(void) putbq(q, mp);
return (GLD_NORESOURCES);
}
} else if (numpacks == 0) {
/*
* Driver indicates it can not transmit any packets
* currently and will request retrial later.
*/
ATOMIC_BUMP(vlan->gldv_stats, NULL, glds_xmtretry, 1);
mp->b_cont = nextmp;
(void) putbq(q, mp);
return (GLD_NORESOURCES);
} else {
ASSERT(numpacks == -1);
/*
* We're supposed to count failed attempts as well.
*/
dl_pkt = mmd_getfirstpdesc(dlmdp, &pinfo);
while (dl_pkt != NULL) {
/*
* Call interpreter to determine total packet
* bytes that are being dropped.
*/
(void) (*ifp->interpreter_mdt)(macinfo, NULL,
&pinfo, &pktinfo, GLD_MDT_TXPKT);
totLen += pktinfo.pktLen;
dl_pkt = mmd_getnextpdesc(dl_pkt, &pinfo);
}
pktinfo.pktLen = totLen;
UPDATE_STATS(vlan->gldv_stats, NULL, pktinfo, mdtpacks);
/*
* Transmit error; drop the message, move on
* to the next one.
*/
freemsg(mp);
}
/*
* Process the next multidata block, if there is one.
*/
mp = nextmp;
}
return (GLD_SUCCESS);
}
/*
* gld_intr (macinfo)
*/
uint_t
gld_intr(gld_mac_info_t *macinfo)
{
ASSERT(macinfo != NULL);
if (!(macinfo->gldm_GLD_flags & GLD_MAC_READY))
return (DDI_INTR_UNCLAIMED);
return ((*macinfo->gldm_intr)(macinfo));
}
/*
* gld_sched (macinfo)
*
* This routine scans the streams that refer to a specific macinfo
* structure and causes the STREAMS scheduler to try to run them if
* they are marked as waiting for the transmit buffer.
*/
void
gld_sched(gld_mac_info_t *macinfo)
{
gld_mac_pvt_t *mac_pvt;
gld_t *gld;
gld_vlan_t *vlan;
int i;
ASSERT(macinfo != NULL);
GLDM_LOCK(macinfo, RW_WRITER);
if (macinfo->gldm_GLD_flags & GLD_UNREGISTERED) {
/* We're probably being called from a leftover interrupt */
GLDM_UNLOCK(macinfo);
return;
}
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
for (i = 0; i < VLAN_HASHSZ; i++) {
for (vlan = mac_pvt->vlan_hash[i];
vlan != NULL; vlan = vlan->gldv_next) {
for (gld = vlan->gldv_str_next;
gld != (gld_t *)&vlan->gldv_str_next;
gld = gld->gld_next) {
ASSERT(gld->gld_mac_info == macinfo);
gld->gld_sched_ran = B_TRUE;
membar_enter();
if (gld->gld_xwait) {
gld->gld_xwait = B_FALSE;
qenable(WR(gld->gld_qptr));
}
}
}
}
GLDM_UNLOCK(macinfo);
}
/*
* gld_precv (macinfo, mp, vtag, stats)
* called from gld_start to loopback a packet when in promiscuous mode
*
* VLAN 0's statistics need to be updated. If stats is not NULL,
* it needs to be updated as well.
*/
static void
gld_precv(gld_mac_info_t *macinfo, mblk_t *mp, uint32_t vtag,
struct gld_stats *stats)
{
gld_mac_pvt_t *mac_pvt;
gld_interface_t *ifp;
pktinfo_t pktinfo;
ASSERT(GLDM_LOCK_HELD_WRITE(macinfo));
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
ifp = mac_pvt->interfacep;
/*
* call the media specific packet interpreter routine
*/
if ((*ifp->interpreter)(macinfo, mp, &pktinfo, GLD_RXLOOP) != 0) {
freemsg(mp);
BUMP(mac_pvt->statistics, stats, glds_rcvbadinterp, 1);
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_precv: interpreter failed");
#endif
return;
}
/*
* Update the vtag information.
*/
pktinfo.isTagged = (vtag != VLAN_VID_NONE);
pktinfo.vid = GLD_VTAG_VID(vtag);
pktinfo.cfi = GLD_VTAG_CFI(vtag);
pktinfo.user_pri = GLD_VTAG_PRI(vtag);
gld_sendup(macinfo, &pktinfo, mp, gld_paccept);
}
/*
* Called from gld_start_mdt to loopback packet(s) when in promiscuous mode.
* Note that 'vlan' is always a physical link, because MDT can only be
* enabled on non-VLAN streams.
*/
/*ARGSUSED*/
static void
gld_precv_mdt(gld_mac_info_t *macinfo, gld_vlan_t *vlan, mblk_t *mp,
pdesc_t *dl_pkt, pktinfo_t *pktinfo)
{
mblk_t *adjmp;
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
gld_interface_t *ifp = mac_pvt->interfacep;
ASSERT(GLDM_LOCK_HELD_WRITE(macinfo));
/*
* Get source/destination.
*/
(void) (*ifp->interpreter_mdt)(macinfo, mp, NULL, pktinfo,
GLD_MDT_RXLOOP);
if ((adjmp = mmd_transform(dl_pkt)) != NULL)
gld_sendup(macinfo, pktinfo, adjmp, gld_paccept);
}
/*
* gld_recv (macinfo, mp)
* called with an mac-level packet in a mblock; take the maclock,
* try the ip4q and ip6q hack, and otherwise call gld_sendup.
*
* V0 drivers already are holding the mutex when they call us.
*/
void
gld_recv(gld_mac_info_t *macinfo, mblk_t *mp)
{
gld_recv_tagged(macinfo, mp, VLAN_VTAG_NONE);
}
void
gld_recv_tagged(gld_mac_info_t *macinfo, mblk_t *mp, uint32_t vtag)
{
gld_mac_pvt_t *mac_pvt;
char pbuf[3*GLD_MAX_ADDRLEN];
pktinfo_t pktinfo;
gld_interface_t *ifp;
queue_t *ipq = NULL;
gld_vlan_t *vlan = NULL, *vlan0 = NULL, *vlann = NULL;
struct gld_stats *stats0, *stats = NULL;
uint32_t vid;
int err;
ASSERT(macinfo != NULL);
ASSERT(mp->b_datap->db_ref);
GLDM_LOCK(macinfo, RW_READER);
if (macinfo->gldm_GLD_flags & GLD_UNREGISTERED) {
/* We're probably being called from a leftover interrupt */
freemsg(mp);
goto done;
}
/*
* If this packet is a VLAN tagged packet, the kstats of corresponding
* "VLAN 0" should also be updated. We can directly access VLAN 0's
* kstats from macinfo.
*
* Further, the packets needs to be passed to VLAN 0 if there is
* any DLPI consumer on VLAN 0 who is interested in tagged packets
* (DL_PROMISC_SAP is on or is bounded to ETHERTYPE_VLAN SAP).
*/
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
stats0 = mac_pvt->statistics;
vid = GLD_VTAG_VID(vtag);
vlan0 = gld_find_vlan(macinfo, VLAN_VID_NONE);
if (vid != VLAN_VID_NONE) {
/*
* If there are no physical DLPI consumers interested in the
* VLAN packet, clear vlan0.
*/
if ((vlan0 != NULL) && (vlan0->gldv_nvlan_sap == 0))
vlan0 = NULL;
/*
* vlann is the VLAN with the same VID as the VLAN packet.
*/
vlann = gld_find_vlan(macinfo, vid);
if (vlann != NULL)
stats = vlann->gldv_stats;
}
vlan = (vid == VLAN_VID_NONE) ? vlan0 : vlann;
ifp = mac_pvt->interfacep;
err = (*ifp->interpreter)(macinfo, mp, &pktinfo, GLD_RXQUICK);
BUMP(stats0, stats, glds_bytercv64, pktinfo.pktLen);
BUMP(stats0, stats, glds_pktrcv64, 1);
if ((vlann == NULL) && (vlan0 == NULL)) {
freemsg(mp);
goto done;
}
/*
* Check whether underlying media code supports the IPQ hack:
*
* - the interpreter could quickly parse the packet
* - the device type supports IPQ (ethernet and IPoIB)
* - there is one, and only one, IP stream bound (to this VLAN)
* - that stream is a "fastpath" stream
* - the packet is of type ETHERTYPE_IP or ETHERTYPE_IPV6
* - there are no streams in promiscuous mode (on this VLAN)
* - if this packet is tagged, there is no need to send this
* packet to physical streams
*/
if ((err != 0) && ((vlan != NULL) && (vlan->gldv_nprom == 0)) &&
(vlan == vlan0 || vlan0 == NULL)) {
switch (pktinfo.ethertype) {
case ETHERTYPE_IP:
ipq = vlan->gldv_ipq;
break;
case ETHERTYPE_IPV6:
ipq = vlan->gldv_ipv6q;
break;
}
}
/*
* Special case for IP; we can simply do the putnext here, if:
* o The IPQ hack is possible (ipq != NULL).
* o the packet is specifically for me, and therefore:
* - the packet is not multicast or broadcast (fastpath only
* wants unicast packets).
*
* o the stream is not asserting flow control.
*/
if (ipq != NULL &&
pktinfo.isForMe &&
canputnext(ipq)) {
/*
* Skip the mac header. We know there is no LLC1/SNAP header
* in this packet
*/
mp->b_rptr += pktinfo.macLen;
putnext(ipq, mp);
goto done;
}
/*
* call the media specific packet interpreter routine
*/
if ((*ifp->interpreter)(macinfo, mp, &pktinfo, GLD_RX) != 0) {
BUMP(stats0, stats, glds_rcvbadinterp, 1);
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_recv_tagged: interpreter failed");
#endif
freemsg(mp);
goto done;
}
/*
* This is safe even if vtag is VLAN_VTAG_NONE
*/
pktinfo.vid = vid;
pktinfo.cfi = GLD_VTAG_CFI(vtag);
#ifdef GLD_DEBUG
if (pktinfo.cfi != VLAN_CFI_ETHER)
cmn_err(CE_WARN, "gld_recv_tagged: non-ETHER CFI");
#endif
pktinfo.user_pri = GLD_VTAG_PRI(vtag);
pktinfo.isTagged = (vtag != VLAN_VID_NONE);
#ifdef GLD_DEBUG
if ((gld_debug & GLDRECV) &&
(!(gld_debug & GLDNOBR) ||
(!pktinfo.isBroadcast && !pktinfo.isMulticast))) {
char pbuf2[3*GLD_MAX_ADDRLEN];
cmn_err(CE_CONT, "gld_recv_tagged: machdr=<%s -> %s>\n",
gld_macaddr_sprintf(pbuf, pktinfo.shost,
macinfo->gldm_addrlen), gld_macaddr_sprintf(pbuf2,
pktinfo.dhost, macinfo->gldm_addrlen));
cmn_err(CE_CONT, "gld_recv_tagged: VlanId %d UserPri %d\n",
pktinfo.vid,
pktinfo.user_pri);
cmn_err(CE_CONT, "gld_recv_tagged: ethertype: %4x Len: %4d "
"Hdr: %d,%d isMulticast: %s\n",
pktinfo.ethertype,
pktinfo.pktLen,
pktinfo.macLen,
pktinfo.hdrLen,
pktinfo.isMulticast ? "Y" : "N");
}
#endif
gld_sendup(macinfo, &pktinfo, mp, gld_accept);
done:
GLDM_UNLOCK(macinfo);
}
/* =================================================================== */
/* receive group: called from gld_recv and gld_precv* with maclock held */
/* =================================================================== */
/*
* Search all the streams attached to the specified VLAN looking for
* those eligible to receive the packet.
* Note that in order to avoid an extra dupmsg(), if this is the first
* eligible stream, remember it (in fgldp) so that we can send up the
* message after this function.
*
* Return errno if fails. Currently the only error is ENOMEM.
*/
static int
gld_sendup_vlan(gld_vlan_t *vlan, pktinfo_t *pktinfo, mblk_t *mp,
int (*acceptfunc)(), void (*send)(), int (*cansend)(), gld_t **fgldp)
{
mblk_t *nmp;
gld_t *gld;
int err = 0;
ASSERT(vlan != NULL);
for (gld = vlan->gldv_str_next; gld != (gld_t *)&vlan->gldv_str_next;
gld = gld->gld_next) {
#ifdef GLD_VERBOSE_DEBUG
cmn_err(CE_NOTE, "gld_sendup_vlan: SAP: %4x QPTR: %p "
"QSTATE: %s", gld->gld_sap, (void *)gld->gld_qptr,
gld->gld_state == DL_IDLE ? "IDLE" : "NOT IDLE");
#endif
ASSERT(gld->gld_qptr != NULL);
ASSERT(gld->gld_state == DL_IDLE ||
gld->gld_state == DL_UNBOUND);
ASSERT(gld->gld_vlan == vlan);
if (gld->gld_state != DL_IDLE)
continue; /* not eligible to receive */
if (gld->gld_flags & GLD_STR_CLOSING)
continue; /* not eligible to receive */
#ifdef GLD_DEBUG
if ((gld_debug & GLDRECV) &&
(!(gld_debug & GLDNOBR) ||
(!pktinfo->isBroadcast && !pktinfo->isMulticast)))
cmn_err(CE_NOTE,
"gld_sendup: queue sap: %4x promis: %s %s %s",
gld->gld_sap,
gld->gld_flags & GLD_PROM_PHYS ? "phys " : " ",
gld->gld_flags & GLD_PROM_SAP ? "sap " : " ",
gld->gld_flags & GLD_PROM_MULT ? "multi" : " ");
#endif
/*
* The accept function differs depending on whether this is
* a packet that we received from the wire or a loopback.
*/
if ((*acceptfunc)(gld, pktinfo)) {
/* sap matches */
pktinfo->wasAccepted = 1; /* known protocol */
if (!(*cansend)(gld->gld_qptr)) {
/*
* Upper stream is not accepting messages, i.e.
* it is flow controlled, therefore we will
* forgo sending the message up this stream.
*/
#ifdef GLD_DEBUG
if (gld_debug & GLDETRACE)
cmn_err(CE_WARN,
"gld_sendup: canput failed");
#endif
BUMP(vlan->gldv_stats, NULL, glds_blocked, 1);
qenable(gld->gld_qptr);
continue;
}
/*
* In order to avoid an extra dupmsg(), remember this
* gld if this is the first eligible stream.
*/
if (*fgldp == NULL) {
*fgldp = gld;
continue;
}
/* duplicate the packet for this stream */
nmp = dupmsg(mp);
if (nmp == NULL) {
BUMP(vlan->gldv_stats, NULL,
glds_gldnorcvbuf, 1);
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_sendup: dupmsg failed");
#endif
/* couldn't get resources; drop it */
err = ENOMEM;
break;
}
/* pass the message up the stream */
gld_passon(gld, nmp, pktinfo, send);
}
}
return (err);
}
/*
* gld_sendup (macinfo, pktinfo, mp, acceptfunc)
* called with an ethernet packet in an mblk; must decide whether
* packet is for us and which streams to queue it to.
*/
static void
gld_sendup(gld_mac_info_t *macinfo, pktinfo_t *pktinfo,
mblk_t *mp, int (*acceptfunc)())
{
gld_t *fgld = NULL;
void (*send)(queue_t *qp, mblk_t *mp);
int (*cansend)(queue_t *qp);
gld_vlan_t *vlan0, *vlann = NULL;
struct gld_stats *stats0, *stats = NULL;
int err = 0;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_sendup(%p, %p)", (void *)mp,
(void *)macinfo);
#endif
ASSERT(mp != NULL);
ASSERT(macinfo != NULL);
ASSERT(pktinfo != NULL);
ASSERT(GLDM_LOCK_HELD(macinfo));
/*
* The tagged packets should also be looped back (transmit-side)
* or sent up (receive-side) to VLAN 0 if VLAN 0 is set to
* DL_PROMISC_SAP or there is any DLPI consumer bind to the
* ETHERTYPE_VLAN SAP. The kstats of VLAN 0 needs to be updated
* as well.
*/
stats0 = ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->statistics;
vlan0 = gld_find_vlan(macinfo, VLAN_VID_NONE);
if (pktinfo->vid != VLAN_VID_NONE) {
if ((vlan0 != NULL) && (vlan0->gldv_nvlan_sap == 0))
vlan0 = NULL;
vlann = gld_find_vlan(macinfo, pktinfo->vid);
if (vlann != NULL)
stats = vlann->gldv_stats;
}
ASSERT((vlan0 != NULL) || (vlann != NULL));
/*
* The "fast" in "GLDOPT_FAST_RECV" refers to the speed at which
* gld_recv returns to the caller's interrupt routine. The total
* network throughput would normally be lower when selecting this
* option, because we putq the messages and process them later,
* instead of sending them with putnext now. Some time critical
* device might need this, so it's here but undocumented.
*/
if (macinfo->gldm_options & GLDOPT_FAST_RECV) {
send = (void (*)(queue_t *, mblk_t *))(uintptr_t)putq;
cansend = canput;
} else {
send = putnext;
cansend = canputnext;
}
/*
* Send the packets for all eligible streams.
*/
if (vlan0 != NULL) {
err = gld_sendup_vlan(vlan0, pktinfo, mp, acceptfunc, send,
cansend, &fgld);
}
if ((err == 0) && (vlann != NULL)) {
err = gld_sendup_vlan(vlann, pktinfo, mp, acceptfunc, send,
cansend, &fgld);
}
ASSERT(mp);
/* send the original dup of the packet up the first stream found */
if (fgld)
gld_passon(fgld, mp, pktinfo, send);
else
freemsg(mp); /* no streams matched */
/* We do not count looped back packets */
if (acceptfunc == gld_paccept)
return; /* transmit loopback case */
if (pktinfo->isBroadcast)
BUMP(stats0, stats, glds_brdcstrcv, 1);
else if (pktinfo->isMulticast)
BUMP(stats0, stats, glds_multircv, 1);
/* No stream accepted this packet */
if (!pktinfo->wasAccepted)
BUMP(stats0, stats, glds_unknowns, 1);
}
#define GLD_IS_PHYS(gld) \
(((gld_vlan_t *)gld->gld_vlan)->gldv_id == VLAN_VID_NONE)
/*
* A packet matches a stream if:
* The stream's VLAN id is the same as the one in the packet.
* and the stream accepts EtherType encoded packets and the type matches
* or the stream accepts LLC packets and the packet is an LLC packet
*/
#define MATCH(stream, pktinfo) \
((((gld_vlan_t *)stream->gld_vlan)->gldv_id == pktinfo->vid) && \
((stream->gld_ethertype && stream->gld_sap == pktinfo->ethertype) || \
(!stream->gld_ethertype && pktinfo->isLLC)))
/*
* This function validates a packet for sending up a particular
* stream. The message header has been parsed and its characteristic
* are recorded in the pktinfo data structure. The streams stack info
* are presented in gld data structures.
*/
static int
gld_accept(gld_t *gld, pktinfo_t *pktinfo)
{
/*
* if there is no match do not bother checking further.
* Note that it is okay to examine gld_vlan because
* macinfo->gldm_lock is held.
*
* Because all tagged packets have SAP value ETHERTYPE_VLAN,
* these packets will pass the SAP filter check if the stream
* is a ETHERTYPE_VLAN listener.
*/
if ((!MATCH(gld, pktinfo) && !(gld->gld_flags & GLD_PROM_SAP) &&
!(GLD_IS_PHYS(gld) && gld->gld_sap == ETHERTYPE_VLAN &&
pktinfo->isTagged)))
return (0);
/*
* We don't accept any packet from the hardware if we originated it.
* (Contrast gld_paccept, the send-loopback accept function.)
*/
if (pktinfo->isLooped)
return (0);
/*
* If the packet is broadcast or sent to us directly we will accept it.
* Also we will accept multicast packets requested by the stream.
*/
if (pktinfo->isForMe || pktinfo->isBroadcast ||
gld_mcmatch(gld, pktinfo))
return (1);
/*
* Finally, accept anything else if we're in promiscuous mode
*/
if (gld->gld_flags & GLD_PROM_PHYS)
return (1);
return (0);
}
/*
* Return TRUE if the given multicast address is one
* of those that this particular Stream is interested in.
*/
static int
gld_mcmatch(gld_t *gld, pktinfo_t *pktinfo)
{
/*
* Return FALSE if not a multicast address.
*/
if (!pktinfo->isMulticast)
return (0);
/*
* Check if all multicasts have been enabled for this Stream
*/
if (gld->gld_flags & GLD_PROM_MULT)
return (1);
/*
* Return FALSE if no multicast addresses enabled for this Stream.
*/
if (!gld->gld_mcast)
return (0);
/*
* Otherwise, look for it in the table.
*/
return (gld_multicast(pktinfo->dhost, gld));
}
/*
* gld_multicast determines if the address is a multicast address for
* this stream.
*/
static int
gld_multicast(unsigned char *macaddr, gld_t *gld)
{
int i;
ASSERT(GLDM_LOCK_HELD(gld->gld_mac_info));
if (!gld->gld_mcast)
return (0);
for (i = 0; i < gld->gld_multicnt; i++) {
if (gld->gld_mcast[i]) {
ASSERT(gld->gld_mcast[i]->gldm_refcnt);
if (mac_eq(gld->gld_mcast[i]->gldm_addr, macaddr,
gld->gld_mac_info->gldm_addrlen))
return (1);
}
}
return (0);
}
/*
* accept function for looped back packets
*/
static int
gld_paccept(gld_t *gld, pktinfo_t *pktinfo)
{
/*
* Note that it is okay to examine gld_vlan because macinfo->gldm_lock
* is held.
*
* If a stream is a ETHERTYPE_VLAN listener, it must
* accept all tagged packets as those packets have SAP value
* ETHERTYPE_VLAN.
*/
return (gld->gld_flags & GLD_PROM_PHYS &&
(MATCH(gld, pktinfo) || gld->gld_flags & GLD_PROM_SAP ||
(GLD_IS_PHYS(gld) && gld->gld_sap == ETHERTYPE_VLAN &&
pktinfo->isTagged)));
}
static void
gld_passon(gld_t *gld, mblk_t *mp, pktinfo_t *pktinfo,
void (*send)(queue_t *qp, mblk_t *mp))
{
boolean_t is_phys = GLD_IS_PHYS(gld);
int skiplen;
boolean_t addtag = B_FALSE;
uint32_t vtag = 0;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_passon(%p, %p, %p)", (void *)gld,
(void *)mp, (void *)pktinfo);
if ((gld_debug & GLDRECV) && (!(gld_debug & GLDNOBR) ||
(!pktinfo->isBroadcast && !pktinfo->isMulticast)))
cmn_err(CE_NOTE, "gld_passon: q: %p mblk: %p minor: %d sap: %x",
(void *)gld->gld_qptr->q_next, (void *)mp, gld->gld_minor,
gld->gld_sap);
#endif
/*
* Figure out how much of the packet header to throw away.
*
* Normal DLPI (non RAW/FAST) streams also want the
* DL_UNITDATA_IND M_PROTO message block prepended to the M_DATA.
*/
if (gld->gld_flags & GLD_RAW) {
/*
* The packet will be tagged in the following cases:
* - if priority is not 0
* - a tagged packet sent on a physical link
*/
if ((pktinfo->isTagged && is_phys) || (pktinfo->user_pri != 0))
addtag = B_TRUE;
skiplen = 0;
} else {
/*
* The packet will be tagged if it meets all below conditions:
* - this is a physical stream
* - this packet is tagged packet
* - the stream is either a DL_PROMISC_SAP listener or a
* ETHERTYPE_VLAN listener
*/
if (is_phys && pktinfo->isTagged &&
((gld->gld_sap == ETHERTYPE_VLAN) ||
(gld->gld_flags & GLD_PROM_SAP))) {
addtag = B_TRUE;
}
skiplen = pktinfo->macLen; /* skip mac header */
if (gld->gld_ethertype)
skiplen += pktinfo->hdrLen; /* skip any extra */
}
if (skiplen >= pktinfo->pktLen) {
/*
* If the interpreter did its job right, then it cannot be
* asking us to skip more bytes than are in the packet!
* However, there could be zero data bytes left after the
* amount to skip. DLPI specifies that passed M_DATA blocks
* should contain at least one byte of data, so if we have
* none we just drop it.
*/
ASSERT(!(skiplen > pktinfo->pktLen));
freemsg(mp);
return;
}
if (addtag) {
mblk_t *savemp = mp;
vtag = GLD_MAKE_VTAG(pktinfo->user_pri, pktinfo->cfi,
is_phys ? pktinfo->vid : VLAN_VID_NONE);
if ((mp = gld_insert_vtag_ether(mp, vtag)) == NULL) {
freemsg(savemp);
return;
}
}
/*
* Skip over the header(s), taking care to possibly handle message
* fragments shorter than the amount we need to skip. Hopefully
* the driver will put the entire packet, or at least the entire
* header, into a single message block. But we handle it if not.
*/
while (skiplen >= MBLKL(mp)) {
mblk_t *savemp = mp;
skiplen -= MBLKL(mp);
mp = mp->b_cont;
ASSERT(mp != NULL); /* because skiplen < pktinfo->pktLen */
freeb(savemp);
}
mp->b_rptr += skiplen;
/* Add M_PROTO if necessary, and pass upstream */
if (((gld->gld_flags & GLD_FAST) && !pktinfo->isMulticast &&
!pktinfo->isBroadcast) || (gld->gld_flags & GLD_RAW)) {
/* RAW/FAST: just send up the M_DATA */
(*send)(gld->gld_qptr, mp);
} else {
/* everybody else wants to see a unitdata_ind structure */
mp = gld_addudind(gld, mp, pktinfo, addtag);
if (mp)
(*send)(gld->gld_qptr, mp);
/* if it failed, gld_addudind already bumped statistic */
}
}
/*
* gld_addudind(gld, mp, pktinfo)
* format a DL_UNITDATA_IND message to be sent upstream to the user
*/
static mblk_t *
gld_addudind(gld_t *gld, mblk_t *mp, pktinfo_t *pktinfo, boolean_t tagged)
{
gld_mac_info_t *macinfo = gld->gld_mac_info;
gld_vlan_t *vlan = (gld_vlan_t *)gld->gld_vlan;
dl_unitdata_ind_t *dludindp;
mblk_t *nmp;
int size;
int type;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_addudind(%p, %p, %p)", (void *)gld,
(void *)mp, (void *)pktinfo);
#endif
ASSERT(macinfo != NULL);
/*
* Allocate the DL_UNITDATA_IND M_PROTO header, if allocation fails
* might as well discard since we can't go further
*/
size = sizeof (dl_unitdata_ind_t) +
2 * (macinfo->gldm_addrlen + abs(macinfo->gldm_saplen));
if ((nmp = allocb(size, BPRI_MED)) == NULL) {
freemsg(mp);
BUMP(vlan->gldv_stats, NULL, glds_gldnorcvbuf, 1);
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_addudind: allocb failed");
#endif
return ((mblk_t *)NULL);
}
DB_TYPE(nmp) = M_PROTO;
nmp->b_rptr = nmp->b_datap->db_lim - size;
if (tagged)
type = ETHERTYPE_VLAN;
else
type = (gld->gld_ethertype) ? pktinfo->ethertype : 0;
/*
* now setup the DL_UNITDATA_IND header
*
* XXX This looks broken if the saps aren't two bytes.
*/
dludindp = (dl_unitdata_ind_t *)nmp->b_rptr;
dludindp->dl_primitive = DL_UNITDATA_IND;
dludindp->dl_src_addr_length =
dludindp->dl_dest_addr_length = macinfo->gldm_addrlen +
abs(macinfo->gldm_saplen);
dludindp->dl_dest_addr_offset = sizeof (dl_unitdata_ind_t);
dludindp->dl_src_addr_offset = dludindp->dl_dest_addr_offset +
dludindp->dl_dest_addr_length;
dludindp->dl_group_address = (pktinfo->isMulticast ||
pktinfo->isBroadcast);
nmp->b_wptr = nmp->b_rptr + dludindp->dl_dest_addr_offset;
mac_copy(pktinfo->dhost, nmp->b_wptr, macinfo->gldm_addrlen);
nmp->b_wptr += macinfo->gldm_addrlen;
ASSERT(macinfo->gldm_saplen == -2); /* XXX following code assumes */
*(ushort_t *)(nmp->b_wptr) = type;
nmp->b_wptr += abs(macinfo->gldm_saplen);
ASSERT(nmp->b_wptr == nmp->b_rptr + dludindp->dl_src_addr_offset);
mac_copy(pktinfo->shost, nmp->b_wptr, macinfo->gldm_addrlen);
nmp->b_wptr += macinfo->gldm_addrlen;
*(ushort_t *)(nmp->b_wptr) = type;
nmp->b_wptr += abs(macinfo->gldm_saplen);
if (pktinfo->nosource)
dludindp->dl_src_addr_offset = dludindp->dl_src_addr_length = 0;
linkb(nmp, mp);
return (nmp);
}
/* ======================================================= */
/* wsrv group: called from wsrv, single threaded per queue */
/* ======================================================= */
/*
* We go to some trouble to avoid taking the same lock during normal
* transmit processing as we do during normal receive processing.
*
* Elements of the per-instance macinfo and per-stream gld_t structures
* are for the most part protected by the GLDM_LOCK rwlock/mutex.
* (Elements of the gld_mac_pvt_t structure are considered part of the
* macinfo structure for purposes of this discussion).
*
* However, it is more complicated than that:
*
* Elements of the macinfo structure that are set before the macinfo
* structure is added to its device list by gld_register(), and never
* thereafter modified, are accessed without requiring taking the lock.
* A similar rule applies to those elements of the gld_t structure that
* are written by gld_open() before the stream is added to any list.
*
* Most other elements of the macinfo structure may only be read or
* written while holding the maclock.
*
* Most writable elements of the gld_t structure are written only
* within the single-threaded domain of wsrv() and subsidiaries.
* (This domain includes open/close while qprocs are not on.)
* The maclock need not be taken while within that domain
* simply to read those elements. Writing to them, even within
* that domain, or reading from it outside that domain, requires
* holding the maclock. Exception: if the stream is not
* presently attached to a PPA, there is no associated macinfo,
* and no maclock need be taken.
*
* The curr_macaddr element of the mac private structure is also
* protected by the GLDM_LOCK rwlock/mutex, like most other members
* of that structure. However, there are a few instances in the
* transmit path where we choose to forgo lock protection when
* reading this variable. This is to avoid lock contention between
* threads executing the DL_UNITDATA_REQ case and receive threads.
* In doing so we will take a small risk or a few corrupted packets
* during the short an rare times when someone is changing the interface's
* physical address. We consider the small cost in this rare case to be
* worth the benefit of reduced lock contention under normal operating
* conditions. The risk/cost is small because:
* 1. there is no guarantee at this layer of uncorrupted delivery.
* 2. the physaddr doesn't change very often - no performance hit.
* 3. if the physaddr changes, other stuff is going to be screwed
* up for a while anyway, while other sites refigure ARP, etc.,
* so losing a couple of packets is the least of our worries.
*
* The list of streams associated with a macinfo is protected by
* two locks: the per-macinfo maclock, and the per-major-device
* gld_devlock. Both must be held to modify the list, but either
* may be held to protect the list during reading/traversing. This
* allows independent locking for multiple instances in the receive
* path (using macinfo), while facilitating routines that must search
* the entire set of streams associated with a major device, such as
* gld_findminor(), gld_finddevinfo(), close(). The "nstreams"
* macinfo element, and the gld_mac_info gld_t element, are similarly
* protected, since they change at exactly the same time macinfo
* streams list does.
*
* The list of macinfo structures associated with a major device
* structure is protected by the gld_devlock, as is the per-major
* list of Style 2 streams in the DL_UNATTACHED state.
*
* The list of major devices is kept on a module-global list
* gld_device_list, which has its own lock to protect the list.
*
* When it is necessary to hold more than one lock at a time, they
* are acquired in this "outside in" order:
* gld_device_list.gld_devlock
* glddev->gld_devlock
* GLDM_LOCK(macinfo)
*
* Finally, there are some "volatile" elements of the gld_t structure
* used for synchronization between various routines that don't share
* the same mutexes. See the routines for details. These are:
* gld_xwait between gld_wsrv() and gld_sched()
* gld_sched_ran between gld_wsrv() and gld_sched()
* gld_in_unbind between gld_wput() and wsrv's gld_unbind()
* gld_wput_count between gld_wput() and wsrv's gld_unbind()
* gld_in_wsrv between gld_wput() and gld_wsrv()
* (used in conjunction with q->q_first)
*/
/*
* gld_ioctl (q, mp)
* handles all ioctl requests passed downstream. This routine is
* passed a pointer to the message block with the ioctl request in it, and a
* pointer to the queue so it can respond to the ioctl request with an ack.
*/
int
gld_ioctl(queue_t *q, mblk_t *mp)
{
struct iocblk *iocp;
gld_t *gld;
gld_mac_info_t *macinfo;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_ioctl(%p %p)", (void *)q, (void *)mp);
#endif
gld = (gld_t *)q->q_ptr;
iocp = (struct iocblk *)mp->b_rptr;
switch (iocp->ioc_cmd) {
case DLIOCRAW: /* raw M_DATA mode */
gld->gld_flags |= GLD_RAW;
DB_TYPE(mp) = M_IOCACK;
qreply(q, mp);
break;
case DL_IOC_HDR_INFO: /* fastpath */
/*
* DL_IOC_HDR_INFO should only come from IP. The one
* initiated from user-land should not be allowed.
*/
if ((gld_global_options & GLD_OPT_NO_FASTPATH) ||
(iocp->ioc_cr != kcred)) {
miocnak(q, mp, 0, EINVAL);
break;
}
gld_fastpath(gld, q, mp);
break;
case DLIOCMARGININFO: { /* margin size */
int err;
if ((macinfo = gld->gld_mac_info) == NULL) {
miocnak(q, mp, 0, EINVAL);
break;
}
if ((err = miocpullup(mp, sizeof (uint32_t))) != 0) {
miocnak(q, mp, 0, err);
break;
}
*((uint32_t *)mp->b_cont->b_rptr) = macinfo->gldm_margin;
miocack(q, mp, sizeof (uint32_t), 0);
break;
}
default:
macinfo = gld->gld_mac_info;
if (macinfo == NULL || macinfo->gldm_ioctl == NULL) {
miocnak(q, mp, 0, EINVAL);
break;
}
GLDM_LOCK(macinfo, RW_WRITER);
(void) (*macinfo->gldm_ioctl) (macinfo, q, mp);
GLDM_UNLOCK(macinfo);
break;
}
return (0);
}
/*
* Since the rules for "fastpath" mode don't seem to be documented
* anywhere, I will describe GLD's rules for fastpath users here:
*
* Once in this mode you remain there until close.
* If you unbind/rebind you should get a new header using DL_IOC_HDR_INFO.
* You must be bound (DL_IDLE) to transmit.
* There are other rules not listed above.
*/
static void
gld_fastpath(gld_t *gld, queue_t *q, mblk_t *mp)
{
gld_interface_t *ifp;
gld_mac_info_t *macinfo;
dl_unitdata_req_t *dludp;
mblk_t *nmp;
t_scalar_t off, len;
uint_t maclen;
int error;
if (gld->gld_state != DL_IDLE) {
miocnak(q, mp, 0, EINVAL);
return;
}
macinfo = gld->gld_mac_info;
ASSERT(macinfo != NULL);
maclen = macinfo->gldm_addrlen + abs(macinfo->gldm_saplen);
error = miocpullup(mp, sizeof (dl_unitdata_req_t) + maclen);
if (error != 0) {
miocnak(q, mp, 0, error);
return;
}
dludp = (dl_unitdata_req_t *)mp->b_cont->b_rptr;
off = dludp->dl_dest_addr_offset;
len = dludp->dl_dest_addr_length;
if (dludp->dl_primitive != DL_UNITDATA_REQ ||
!MBLKIN(mp->b_cont, off, len) || len != maclen) {
miocnak(q, mp, 0, EINVAL);
return;
}
/*
* We take the fastpath request as a declaration that they will accept
* M_DATA messages from us, whether or not we are willing to accept
* M_DATA from them. This allows us to have fastpath in one direction
* (flow upstream) even on media with Source Routing, where we are
* unable to provide a fixed MAC header to be prepended to downstream
* flowing packets. So we set GLD_FAST whether or not we decide to
* allow them to send M_DATA down to us.
*/
GLDM_LOCK(macinfo, RW_WRITER);
gld->gld_flags |= GLD_FAST;
GLDM_UNLOCK(macinfo);
ifp = ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->interfacep;
/* This will fail for Source Routing media */
/* Also on Ethernet on 802.2 SAPs */
if ((nmp = (*ifp->mkfastpath)(gld, mp)) == NULL) {
miocnak(q, mp, 0, ENOMEM);
return;
}
/*
* Link new mblk in after the "request" mblks.
*/
linkb(mp, nmp);
miocack(q, mp, msgdsize(mp->b_cont), 0);
}
/*
* gld_cmds (q, mp)
* process the DL commands as defined in dlpi.h
* note that the primitives return status which is passed back
* to the service procedure. If the value is GLDE_RETRY, then
* it is assumed that processing must stop and the primitive has
* been put back onto the queue. If the value is any other error,
* then an error ack is generated by the service procedure.
*/
static int
gld_cmds(queue_t *q, mblk_t *mp)
{
union DL_primitives *dlp = (union DL_primitives *)mp->b_rptr;
gld_t *gld = (gld_t *)(q->q_ptr);
int result = DL_BADPRIM;
int mblkl = MBLKL(mp);
t_uscalar_t dlreq;
/* Make sure we have at least dlp->dl_primitive */
if (mblkl < sizeof (dlp->dl_primitive))
return (DL_BADPRIM);
dlreq = dlp->dl_primitive;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE,
"gld_cmds(%p, %p):dlp=%p, dlp->dl_primitive=%d",
(void *)q, (void *)mp, (void *)dlp, dlreq);
#endif
switch (dlreq) {
case DL_UDQOS_REQ:
if (mblkl < DL_UDQOS_REQ_SIZE)
break;
result = gld_udqos(q, mp);
break;
case DL_BIND_REQ:
if (mblkl < DL_BIND_REQ_SIZE)
break;
result = gld_bind(q, mp);
break;
case DL_UNBIND_REQ:
if (mblkl < DL_UNBIND_REQ_SIZE)
break;
result = gld_unbind(q, mp);
break;
case DL_UNITDATA_REQ:
if (mblkl < DL_UNITDATA_REQ_SIZE)
break;
result = gld_unitdata(q, mp);
break;
case DL_INFO_REQ:
if (mblkl < DL_INFO_REQ_SIZE)
break;
result = gld_inforeq(q, mp);
break;
case DL_ATTACH_REQ:
if (mblkl < DL_ATTACH_REQ_SIZE)
break;
if (gld->gld_style == DL_STYLE2)
result = gldattach(q, mp);
else
result = DL_NOTSUPPORTED;
break;
case DL_DETACH_REQ:
if (mblkl < DL_DETACH_REQ_SIZE)
break;
if (gld->gld_style == DL_STYLE2)
result = gldunattach(q, mp);
else
result = DL_NOTSUPPORTED;
break;
case DL_ENABMULTI_REQ:
if (mblkl < DL_ENABMULTI_REQ_SIZE)
break;
result = gld_enable_multi(q, mp);
break;
case DL_DISABMULTI_REQ:
if (mblkl < DL_DISABMULTI_REQ_SIZE)
break;
result = gld_disable_multi(q, mp);
break;
case DL_PHYS_ADDR_REQ:
if (mblkl < DL_PHYS_ADDR_REQ_SIZE)
break;
result = gld_physaddr(q, mp);
break;
case DL_SET_PHYS_ADDR_REQ:
if (mblkl < DL_SET_PHYS_ADDR_REQ_SIZE)
break;
result = gld_setaddr(q, mp);
break;
case DL_PROMISCON_REQ:
if (mblkl < DL_PROMISCON_REQ_SIZE)
break;
result = gld_promisc(q, mp, dlreq, B_TRUE);
break;
case DL_PROMISCOFF_REQ:
if (mblkl < DL_PROMISCOFF_REQ_SIZE)
break;
result = gld_promisc(q, mp, dlreq, B_FALSE);
break;
case DL_GET_STATISTICS_REQ:
if (mblkl < DL_GET_STATISTICS_REQ_SIZE)
break;
result = gld_get_statistics(q, mp);
break;
case DL_CAPABILITY_REQ:
if (mblkl < DL_CAPABILITY_REQ_SIZE)
break;
result = gld_cap(q, mp);
break;
case DL_NOTIFY_REQ:
if (mblkl < DL_NOTIFY_REQ_SIZE)
break;
result = gld_notify_req(q, mp);
break;
case DL_XID_REQ:
case DL_XID_RES:
case DL_TEST_REQ:
case DL_TEST_RES:
case DL_CONTROL_REQ:
case DL_PASSIVE_REQ:
result = DL_NOTSUPPORTED;
break;
default:
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_WARN,
"gld_cmds: unknown M_PROTO message: %d",
dlreq);
#endif
result = DL_BADPRIM;
}
return (result);
}
static int
gld_cap(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
dl_capability_req_t *dlp = (dl_capability_req_t *)mp->b_rptr;
if (gld->gld_state == DL_UNATTACHED)
return (DL_OUTSTATE);
if (dlp->dl_sub_length == 0)
return (gld_cap_ack(q, mp));
return (gld_cap_enable(q, mp));
}
static int
gld_cap_ack(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo = gld->gld_mac_info;
gld_interface_t *ifp;
dl_capability_ack_t *dlap;
dl_capability_sub_t *dlsp;
size_t size = sizeof (dl_capability_ack_t);
size_t subsize = 0;
ifp = ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->interfacep;
if (macinfo->gldm_capabilities & GLD_CAP_CKSUM_ANY)
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_hcksum_t);
if (macinfo->gldm_capabilities & GLD_CAP_ZEROCOPY)
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_zerocopy_t);
if (macinfo->gldm_options & GLDOPT_MDT)
subsize += (sizeof (dl_capability_sub_t) +
sizeof (dl_capab_mdt_t));
if ((mp = mexchange(q, mp, size + subsize, M_PROTO,
DL_CAPABILITY_ACK)) == NULL)
return (GLDE_OK);
dlap = (dl_capability_ack_t *)mp->b_rptr;
dlap->dl_sub_offset = 0;
if ((dlap->dl_sub_length = subsize) != 0)
dlap->dl_sub_offset = sizeof (dl_capability_ack_t);
dlsp = (dl_capability_sub_t *)&dlap[1];
if (macinfo->gldm_capabilities & GLD_CAP_CKSUM_ANY) {
dl_capab_hcksum_t *dlhp = (dl_capab_hcksum_t *)&dlsp[1];
dlsp->dl_cap = DL_CAPAB_HCKSUM;
dlsp->dl_length = sizeof (dl_capab_hcksum_t);
dlhp->hcksum_version = HCKSUM_VERSION_1;
dlhp->hcksum_txflags = 0;
if (macinfo->gldm_capabilities & GLD_CAP_CKSUM_PARTIAL)
dlhp->hcksum_txflags |= HCKSUM_INET_PARTIAL;
if (macinfo->gldm_capabilities & GLD_CAP_CKSUM_FULL_V4)
dlhp->hcksum_txflags |= HCKSUM_INET_FULL_V4;
if (macinfo->gldm_capabilities & GLD_CAP_CKSUM_FULL_V6)
dlhp->hcksum_txflags |= HCKSUM_INET_FULL_V6;
if (macinfo->gldm_capabilities & GLD_CAP_CKSUM_IPHDR)
dlhp->hcksum_txflags |= HCKSUM_IPHDRCKSUM;
dlcapabsetqid(&(dlhp->hcksum_mid), RD(q));
dlsp = (dl_capability_sub_t *)&dlhp[1];
}
if (macinfo->gldm_capabilities & GLD_CAP_ZEROCOPY) {
dl_capab_zerocopy_t *dlzp = (dl_capab_zerocopy_t *)&dlsp[1];
dlsp->dl_cap = DL_CAPAB_ZEROCOPY;
dlsp->dl_length = sizeof (dl_capab_zerocopy_t);
dlzp->zerocopy_version = ZEROCOPY_VERSION_1;
dlzp->zerocopy_flags = DL_CAPAB_VMSAFE_MEM;
dlcapabsetqid(&(dlzp->zerocopy_mid), RD(q));
dlsp = (dl_capability_sub_t *)&dlzp[1];
}
if (macinfo->gldm_options & GLDOPT_MDT) {
dl_capab_mdt_t *dlmp = (dl_capab_mdt_t *)&dlsp[1];
dlsp->dl_cap = DL_CAPAB_MDT;
dlsp->dl_length = sizeof (dl_capab_mdt_t);
dlmp->mdt_version = MDT_VERSION_2;
dlmp->mdt_max_pld = macinfo->gldm_mdt_segs;
dlmp->mdt_span_limit = macinfo->gldm_mdt_sgl;
dlcapabsetqid(&dlmp->mdt_mid, OTHERQ(q));
dlmp->mdt_flags = DL_CAPAB_MDT_ENABLE;
dlmp->mdt_hdr_head = ifp->hdr_size;
dlmp->mdt_hdr_tail = 0;
}
qreply(q, mp);
return (GLDE_OK);
}
static int
gld_cap_enable(queue_t *q, mblk_t *mp)
{
dl_capability_req_t *dlp;
dl_capability_sub_t *dlsp;
dl_capab_hcksum_t *dlhp;
offset_t off;
size_t len;
size_t size;
offset_t end;
dlp = (dl_capability_req_t *)mp->b_rptr;
dlp->dl_primitive = DL_CAPABILITY_ACK;
off = dlp->dl_sub_offset;
len = dlp->dl_sub_length;
if (!MBLKIN(mp, off, len))
return (DL_BADPRIM);
end = off + len;
while (off < end) {
dlsp = (dl_capability_sub_t *)(mp->b_rptr + off);
size = sizeof (dl_capability_sub_t) + dlsp->dl_length;
if (off + size > end)
return (DL_BADPRIM);
switch (dlsp->dl_cap) {
case DL_CAPAB_HCKSUM:
dlhp = (dl_capab_hcksum_t *)&dlsp[1];
/* nothing useful we can do with the contents */
dlcapabsetqid(&(dlhp->hcksum_mid), RD(q));
break;
default:
break;
}
off += size;
}
qreply(q, mp);
return (GLDE_OK);
}
/*
* Send a copy of the DL_NOTIFY_IND message <mp> to each stream that has
* requested the specific <notification> that the message carries AND is
* eligible and ready to receive the notification immediately.
*
* This routine ignores flow control. Notifications will be sent regardless.
*
* In all cases, the original message passed in is freed at the end of
* the routine.
*/
static void
gld_notify_qs(gld_mac_info_t *macinfo, mblk_t *mp, uint32_t notification)
{
gld_mac_pvt_t *mac_pvt;
gld_vlan_t *vlan;
gld_t *gld;
mblk_t *nmp;
int i;
ASSERT(GLDM_LOCK_HELD_WRITE(macinfo));
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
/*
* Search all the streams attached to this macinfo looking
* for those eligible to receive the present notification.
*/
for (i = 0; i < VLAN_HASHSZ; i++) {
for (vlan = mac_pvt->vlan_hash[i];
vlan != NULL; vlan = vlan->gldv_next) {
for (gld = vlan->gldv_str_next;
gld != (gld_t *)&vlan->gldv_str_next;
gld = gld->gld_next) {
ASSERT(gld->gld_qptr != NULL);
ASSERT(gld->gld_state == DL_IDLE ||
gld->gld_state == DL_UNBOUND);
ASSERT(gld->gld_mac_info == macinfo);
if (gld->gld_flags & GLD_STR_CLOSING)
continue; /* not eligible - skip */
if (!(notification & gld->gld_notifications))
continue; /* not wanted - skip */
if ((nmp = dupmsg(mp)) == NULL)
continue; /* can't copy - skip */
/*
* All OK; send dup'd notification up this
* stream
*/
qreply(WR(gld->gld_qptr), nmp);
}
}
}
/*
* Drop the original message block now
*/
freemsg(mp);
}
/*
* For each (understood) bit in the <notifications> argument, contruct
* a DL_NOTIFY_IND message and send it to the specified <q>, or to all
* eligible queues if <q> is NULL.
*/
static void
gld_notify_ind(gld_mac_info_t *macinfo, uint32_t notifications, queue_t *q)
{
gld_mac_pvt_t *mac_pvt;
dl_notify_ind_t *dlnip;
struct gld_stats *stats;
mblk_t *mp;
size_t size;
uint32_t bit;
GLDM_LOCK(macinfo, RW_WRITER);
/*
* The following cases shouldn't happen, but just in case the
* MAC driver calls gld_linkstate() at an inappropriate time, we
* check anyway ...
*/
if (!(macinfo->gldm_GLD_flags & GLD_MAC_READY)) {
GLDM_UNLOCK(macinfo);
return; /* not ready yet */
}
if (macinfo->gldm_GLD_flags & GLD_UNREGISTERED) {
GLDM_UNLOCK(macinfo);
return; /* not ready anymore */
}
/*
* Make sure the kstats are up to date, 'cos we use some of
* the kstat values below, specifically the link speed ...
*/
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
stats = mac_pvt->statistics;
if (macinfo->gldm_get_stats)
(void) (*macinfo->gldm_get_stats)(macinfo, stats);
for (bit = 1; notifications != 0; bit <<= 1) {
if ((notifications & bit) == 0)
continue;
notifications &= ~bit;
size = DL_NOTIFY_IND_SIZE;
if (bit == DL_NOTE_PHYS_ADDR)
size += macinfo->gldm_addrlen;
if ((mp = allocb(size, BPRI_MED)) == NULL)
continue;
mp->b_datap->db_type = M_PROTO;
mp->b_wptr = mp->b_rptr + size;
dlnip = (dl_notify_ind_t *)mp->b_rptr;
dlnip->dl_primitive = DL_NOTIFY_IND;
dlnip->dl_notification = 0;
dlnip->dl_data = 0;
dlnip->dl_addr_length = 0;
dlnip->dl_addr_offset = 0;
switch (bit) {
case DL_NOTE_PROMISC_ON_PHYS:
case DL_NOTE_PROMISC_OFF_PHYS:
if (mac_pvt->nprom != 0)
dlnip->dl_notification = bit;
break;
case DL_NOTE_LINK_DOWN:
if (macinfo->gldm_linkstate == GLD_LINKSTATE_DOWN)
dlnip->dl_notification = bit;
break;
case DL_NOTE_LINK_UP:
if (macinfo->gldm_linkstate == GLD_LINKSTATE_UP)
dlnip->dl_notification = bit;
break;
case DL_NOTE_SPEED:
/*
* Conversion required here:
* GLD keeps the speed in bit/s in a uint64
* DLPI wants it in kb/s in a uint32
* Fortunately this is still big enough for 10Gb/s!
*/
dlnip->dl_notification = bit;
dlnip->dl_data = stats->glds_speed/1000ULL;
break;
case DL_NOTE_PHYS_ADDR:
dlnip->dl_notification = bit;
dlnip->dl_data = DL_CURR_PHYS_ADDR;
dlnip->dl_addr_offset = sizeof (dl_notify_ind_t);
dlnip->dl_addr_length = macinfo->gldm_addrlen +
abs(macinfo->gldm_saplen);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
mac_copy(mac_pvt->curr_macaddr,
mp->b_rptr + sizeof (dl_notify_ind_t),
macinfo->gldm_addrlen);
break;
default:
break;
}
if (dlnip->dl_notification == 0)
freemsg(mp);
else if (q != NULL)
qreply(q, mp);
else
gld_notify_qs(macinfo, mp, bit);
}
GLDM_UNLOCK(macinfo);
}
/*
* gld_notify_req - handle a DL_NOTIFY_REQ message
*/
static int
gld_notify_req(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo;
gld_mac_pvt_t *pvt;
dl_notify_req_t *dlnrp;
dl_notify_ack_t *dlnap;
ASSERT(gld != NULL);
ASSERT(gld->gld_qptr == RD(q));
dlnrp = (dl_notify_req_t *)mp->b_rptr;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_notify_req(%p %p)",
(void *)q, (void *)mp);
#endif
if (gld->gld_state == DL_UNATTACHED) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_NOTE, "gld_notify_req: wrong state (%d)",
gld->gld_state);
#endif
return (DL_OUTSTATE);
}
/*
* Remember what notifications are required by this stream
*/
macinfo = gld->gld_mac_info;
pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
gld->gld_notifications = dlnrp->dl_notifications & pvt->notifications;
/*
* The return DL_NOTIFY_ACK carries the bitset of notifications
* that this driver can provide, independently of which ones have
* previously been or are now being requested.
*/
if ((mp = mexchange(q, mp, sizeof (dl_notify_ack_t), M_PCPROTO,
DL_NOTIFY_ACK)) == NULL)
return (DL_SYSERR);
dlnap = (dl_notify_ack_t *)mp->b_rptr;
dlnap->dl_notifications = pvt->notifications;
qreply(q, mp);
/*
* A side effect of a DL_NOTIFY_REQ is that after the DL_NOTIFY_ACK
* reply, the the requestor gets zero or more DL_NOTIFY_IND messages
* that provide the current status.
*/
gld_notify_ind(macinfo, gld->gld_notifications, q);
return (GLDE_OK);
}
/*
* gld_linkstate()
* Called by driver to tell GLD the state of the physical link.
* As a side effect, sends a DL_NOTE_LINK_UP or DL_NOTE_LINK_DOWN
* notification to each client that has previously requested such
* notifications
*/
void
gld_linkstate(gld_mac_info_t *macinfo, int32_t newstate)
{
uint32_t notification;
switch (newstate) {
default:
return;
case GLD_LINKSTATE_DOWN:
notification = DL_NOTE_LINK_DOWN;
break;
case GLD_LINKSTATE_UP:
notification = DL_NOTE_LINK_UP | DL_NOTE_SPEED;
break;
case GLD_LINKSTATE_UNKNOWN:
notification = 0;
break;
}
GLDM_LOCK(macinfo, RW_WRITER);
if (macinfo->gldm_linkstate == newstate)
notification = 0;
else
macinfo->gldm_linkstate = newstate;
GLDM_UNLOCK(macinfo);
if (notification)
gld_notify_ind(macinfo, notification, NULL);
}
/*
* gld_udqos - set the current QoS parameters (priority only at the moment).
*/
static int
gld_udqos(queue_t *q, mblk_t *mp)
{
dl_udqos_req_t *dlp;
gld_t *gld = (gld_t *)q->q_ptr;
int off;
int len;
dl_qos_cl_sel1_t *selp;
ASSERT(gld);
ASSERT(gld->gld_qptr == RD(q));
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_udqos(%p %p)", (void *)q, (void *)mp);
#endif
if (gld->gld_state != DL_IDLE) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_NOTE, "gld_udqos: wrong state (%d)",
gld->gld_state);
#endif
return (DL_OUTSTATE);
}
dlp = (dl_udqos_req_t *)mp->b_rptr;
off = dlp->dl_qos_offset;
len = dlp->dl_qos_length;
if (len != sizeof (dl_qos_cl_sel1_t) || !MBLKIN(mp, off, len))
return (DL_BADQOSTYPE);
selp = (dl_qos_cl_sel1_t *)(mp->b_rptr + off);
if (selp->dl_qos_type != DL_QOS_CL_SEL1)
return (DL_BADQOSTYPE);
if (selp->dl_trans_delay != 0 &&
selp->dl_trans_delay != DL_QOS_DONT_CARE)
return (DL_BADQOSPARAM);
if (selp->dl_protection != 0 &&
selp->dl_protection != DL_QOS_DONT_CARE)
return (DL_BADQOSPARAM);
if (selp->dl_residual_error != 0 &&
selp->dl_residual_error != DL_QOS_DONT_CARE)
return (DL_BADQOSPARAM);
if (selp->dl_priority < 0 || selp->dl_priority > 7)
return (DL_BADQOSPARAM);
gld->gld_upri = selp->dl_priority;
dlokack(q, mp, DL_UDQOS_REQ);
return (GLDE_OK);
}
static mblk_t *
gld_bindack(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo = gld->gld_mac_info;
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
dl_bind_ack_t *dlp;
size_t size;
t_uscalar_t addrlen;
uchar_t *sapp;
addrlen = macinfo->gldm_addrlen + abs(macinfo->gldm_saplen);
size = sizeof (dl_bind_ack_t) + addrlen;
if ((mp = mexchange(q, mp, size, M_PCPROTO, DL_BIND_ACK)) == NULL)
return (NULL);
dlp = (dl_bind_ack_t *)mp->b_rptr;
dlp->dl_sap = gld->gld_sap;
dlp->dl_addr_length = addrlen;
dlp->dl_addr_offset = sizeof (dl_bind_ack_t);
dlp->dl_max_conind = 0;
dlp->dl_xidtest_flg = 0;
mac_copy(mac_pvt->curr_macaddr, (uchar_t *)&dlp[1],
macinfo->gldm_addrlen);
sapp = mp->b_rptr + dlp->dl_addr_offset + macinfo->gldm_addrlen;
*(ushort_t *)sapp = gld->gld_sap;
return (mp);
}
/*
* gld_bind - determine if a SAP is already allocated and whether it is legal
* to do the bind at this time
*/
static int
gld_bind(queue_t *q, mblk_t *mp)
{
ulong_t sap;
dl_bind_req_t *dlp;
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo = gld->gld_mac_info;
ASSERT(gld);
ASSERT(gld->gld_qptr == RD(q));
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_bind(%p %p)", (void *)q, (void *)mp);
#endif
dlp = (dl_bind_req_t *)mp->b_rptr;
sap = dlp->dl_sap;
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT)
cmn_err(CE_NOTE, "gld_bind: lsap=%lx", sap);
#endif
if (gld->gld_state != DL_UNBOUND) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_NOTE, "gld_bind: bound or not attached (%d)",
gld->gld_state);
#endif
return (DL_OUTSTATE);
}
ASSERT(macinfo);
if (dlp->dl_service_mode != DL_CLDLS) {
return (DL_UNSUPPORTED);
}
if (dlp->dl_xidtest_flg & (DL_AUTO_XID | DL_AUTO_TEST)) {
return (DL_NOAUTO);
}
/*
* Check sap validity and decide whether this stream accepts
* IEEE 802.2 (LLC) packets.
*/
if (sap > ETHERTYPE_MAX)
return (DL_BADSAP);
/*
* Decide whether the SAP value selects EtherType encoding/decoding.
* For compatibility with monolithic ethernet drivers, the range of
* SAP values is different for DL_ETHER media.
*/
switch (macinfo->gldm_type) {
case DL_ETHER:
gld->gld_ethertype = (sap > ETHERMTU);
break;
default:
gld->gld_ethertype = (sap > GLD_MAX_802_SAP);
break;
}
/* if we get to here, then the SAP is legal enough */
GLDM_LOCK(macinfo, RW_WRITER);
gld->gld_state = DL_IDLE; /* bound and ready */
gld->gld_sap = sap;
if ((macinfo->gldm_type == DL_ETHER) && (sap == ETHERTYPE_VLAN))
((gld_vlan_t *)gld->gld_vlan)->gldv_nvlan_sap++;
gld_set_ipq(gld);
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT)
cmn_err(CE_NOTE, "gld_bind: ok - sap = %d", gld->gld_sap);
#endif
/* ACK the BIND */
mp = gld_bindack(q, mp);
GLDM_UNLOCK(macinfo);
if (mp != NULL) {
qreply(q, mp);
return (GLDE_OK);
}
return (DL_SYSERR);
}
/*
* gld_unbind - perform an unbind of an LSAP or ether type on the stream.
* The stream is still open and can be re-bound.
*/
static int
gld_unbind(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo = gld->gld_mac_info;
ASSERT(gld);
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_unbind(%p %p)", (void *)q, (void *)mp);
#endif
if (gld->gld_state != DL_IDLE) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_NOTE, "gld_unbind: wrong state (%d)",
gld->gld_state);
#endif
return (DL_OUTSTATE);
}
ASSERT(macinfo);
/*
* Avoid unbinding (DL_UNBIND_REQ) while FAST/RAW is inside wput.
* See comments above gld_start().
*/
gld->gld_in_unbind = B_TRUE; /* disallow wput=>start */
membar_enter();
if (gld->gld_wput_count != 0) {
gld->gld_in_unbind = B_FALSE;
ASSERT(mp); /* we didn't come from close */
#ifdef GLD_DEBUG
if (gld_debug & GLDETRACE)
cmn_err(CE_NOTE, "gld_unbind: defer for wput");
#endif
(void) putbq(q, mp);
qenable(q); /* try again soon */
return (GLDE_RETRY);
}
GLDM_LOCK(macinfo, RW_WRITER);
if ((macinfo->gldm_type == DL_ETHER) &&
(gld->gld_sap == ETHERTYPE_VLAN)) {
((gld_vlan_t *)gld->gld_vlan)->gldv_nvlan_sap--;
}
gld->gld_state = DL_UNBOUND;
gld->gld_sap = 0;
gld_set_ipq(gld);
GLDM_UNLOCK(macinfo);
membar_exit();
gld->gld_in_unbind = B_FALSE;
/* mp is NULL if we came from close */
if (mp) {
gld_flushqueue(q); /* flush the queues */
dlokack(q, mp, DL_UNBIND_REQ);
}
return (GLDE_OK);
}
/*
* gld_inforeq - generate the response to an info request
*/
static int
gld_inforeq(queue_t *q, mblk_t *mp)
{
gld_t *gld;
dl_info_ack_t *dlp;
int bufsize;
glddev_t *glddev;
gld_mac_info_t *macinfo;
gld_mac_pvt_t *mac_pvt;
int sel_offset = 0;
int range_offset = 0;
int addr_offset;
int addr_length;
int sap_length;
int brdcst_offset;
int brdcst_length;
uchar_t *sapp;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_inforeq(%p %p)", (void *)q, (void *)mp);
#endif
gld = (gld_t *)q->q_ptr;
ASSERT(gld);
glddev = gld->gld_device;
ASSERT(glddev);
if (gld->gld_state == DL_IDLE || gld->gld_state == DL_UNBOUND) {
macinfo = gld->gld_mac_info;
ASSERT(macinfo != NULL);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
addr_length = macinfo->gldm_addrlen;
sap_length = macinfo->gldm_saplen;
brdcst_length = macinfo->gldm_addrlen;
} else {
addr_length = glddev->gld_addrlen;
sap_length = glddev->gld_saplen;
brdcst_length = glddev->gld_addrlen;
}
bufsize = sizeof (dl_info_ack_t);
addr_offset = bufsize;
bufsize += addr_length;
bufsize += abs(sap_length);
brdcst_offset = bufsize;
bufsize += brdcst_length;
if (((gld_vlan_t *)gld->gld_vlan) != NULL) {
sel_offset = P2ROUNDUP(bufsize, sizeof (int64_t));
bufsize = sel_offset + sizeof (dl_qos_cl_sel1_t);
range_offset = P2ROUNDUP(bufsize, sizeof (int64_t));
bufsize = range_offset + sizeof (dl_qos_cl_range1_t);
}
if ((mp = mexchange(q, mp, bufsize, M_PCPROTO, DL_INFO_ACK)) == NULL)
return (GLDE_OK); /* nothing more to be done */
bzero(mp->b_rptr, bufsize);
dlp = (dl_info_ack_t *)mp->b_rptr;
dlp->dl_primitive = DL_INFO_ACK;
dlp->dl_version = DL_VERSION_2;
dlp->dl_service_mode = DL_CLDLS;
dlp->dl_current_state = gld->gld_state;
dlp->dl_provider_style = gld->gld_style;
if (sel_offset != 0) {
dl_qos_cl_sel1_t *selp;
dl_qos_cl_range1_t *rangep;
ASSERT(range_offset != 0);
dlp->dl_qos_offset = sel_offset;
dlp->dl_qos_length = sizeof (dl_qos_cl_sel1_t);
dlp->dl_qos_range_offset = range_offset;
dlp->dl_qos_range_length = sizeof (dl_qos_cl_range1_t);
selp = (dl_qos_cl_sel1_t *)(mp->b_rptr + sel_offset);
selp->dl_qos_type = DL_QOS_CL_SEL1;
selp->dl_priority = gld->gld_upri;
rangep = (dl_qos_cl_range1_t *)(mp->b_rptr + range_offset);
rangep->dl_qos_type = DL_QOS_CL_RANGE1;
rangep->dl_priority.dl_min = 0;
rangep->dl_priority.dl_max = 7;
}
if (gld->gld_state == DL_IDLE || gld->gld_state == DL_UNBOUND) {
dlp->dl_min_sdu = macinfo->gldm_minpkt;
dlp->dl_max_sdu = macinfo->gldm_maxpkt;
dlp->dl_mac_type = macinfo->gldm_type;
dlp->dl_addr_length = addr_length + abs(sap_length);
dlp->dl_sap_length = sap_length;
if (gld->gld_state == DL_IDLE) {
/*
* If we are bound to a non-LLC SAP on any medium
* other than Ethernet, then we need room for a
* SNAP header. So we have to adjust the MTU size
* accordingly. XXX I suppose this should be done
* in gldutil.c, but it seems likely that this will
* always be true for everything GLD supports but
* Ethernet. Check this if you add another medium.
*/
if ((macinfo->gldm_type == DL_TPR ||
macinfo->gldm_type == DL_FDDI) &&
gld->gld_ethertype)
dlp->dl_max_sdu -= LLC_SNAP_HDR_LEN;
/* copy macaddr and sap */
dlp->dl_addr_offset = addr_offset;
mac_copy(mac_pvt->curr_macaddr, mp->b_rptr +
addr_offset, macinfo->gldm_addrlen);
sapp = mp->b_rptr + addr_offset +
macinfo->gldm_addrlen;
*(ushort_t *)sapp = gld->gld_sap;
} else {
dlp->dl_addr_offset = 0;
}
/* copy broadcast addr */
dlp->dl_brdcst_addr_length = macinfo->gldm_addrlen;
dlp->dl_brdcst_addr_offset = brdcst_offset;
mac_copy((caddr_t)macinfo->gldm_broadcast_addr,
mp->b_rptr + brdcst_offset, brdcst_length);
} else {
/*
* No PPA is attached.
* The best we can do is use the values provided
* by the first mac that called gld_register.
*/
dlp->dl_min_sdu = glddev->gld_minsdu;
dlp->dl_max_sdu = glddev->gld_maxsdu;
dlp->dl_mac_type = glddev->gld_type;
dlp->dl_addr_length = addr_length + abs(sap_length);
dlp->dl_sap_length = sap_length;
dlp->dl_addr_offset = 0;
dlp->dl_brdcst_addr_offset = brdcst_offset;
dlp->dl_brdcst_addr_length = brdcst_length;
mac_copy((caddr_t)glddev->gld_broadcast,
mp->b_rptr + brdcst_offset, brdcst_length);
}
qreply(q, mp);
return (GLDE_OK);
}
/*
* gld_unitdata (q, mp)
* send a datagram. Destination address/lsap is in M_PROTO
* message (first mblock), data is in remainder of message.
*
*/
static int
gld_unitdata(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
dl_unitdata_req_t *dlp = (dl_unitdata_req_t *)mp->b_rptr;
gld_mac_info_t *macinfo = gld->gld_mac_info;
size_t msglen;
mblk_t *nmp;
gld_interface_t *ifp;
uint32_t start;
uint32_t stuff;
uint32_t end;
uint32_t value;
uint32_t flags;
uint32_t upri;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_unitdata(%p %p)", (void *)q, (void *)mp);
#endif
if (gld->gld_state != DL_IDLE) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_NOTE, "gld_unitdata: wrong state (%d)",
gld->gld_state);
#endif
dluderrorind(q, mp, mp->b_rptr + dlp->dl_dest_addr_offset,
dlp->dl_dest_addr_length, DL_OUTSTATE, 0);
return (GLDE_OK);
}
ASSERT(macinfo != NULL);
if (!MBLKIN(mp, dlp->dl_dest_addr_offset, dlp->dl_dest_addr_length) ||
dlp->dl_dest_addr_length !=
macinfo->gldm_addrlen + abs(macinfo->gldm_saplen)) {
dluderrorind(q, mp, mp->b_rptr + dlp->dl_dest_addr_offset,
dlp->dl_dest_addr_length, DL_BADADDR, 0);
return (GLDE_OK);
}
upri = dlp->dl_priority.dl_max;
msglen = msgdsize(mp);
if (msglen == 0 || msglen > macinfo->gldm_maxpkt) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_NOTE, "gld_unitdata: bad msglen (%d)",
(int)msglen);
#endif
dluderrorind(q, mp, mp->b_rptr + dlp->dl_dest_addr_offset,
dlp->dl_dest_addr_length, DL_BADDATA, 0);
return (GLDE_OK);
}
ASSERT(mp->b_cont != NULL); /* because msgdsize(mp) is nonzero */
ifp = ((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->interfacep;
/* grab any checksum information that may be present */
hcksum_retrieve(mp->b_cont, NULL, NULL, &start, &stuff, &end,
&value, &flags);
/*
* Prepend a valid header for transmission
*/
if ((nmp = (*ifp->mkunitdata)(gld, mp)) == NULL) {
#ifdef GLD_DEBUG
if (gld_debug & GLDERRS)
cmn_err(CE_NOTE, "gld_unitdata: mkunitdata failed.");
#endif
dluderrorind(q, mp, mp->b_rptr + dlp->dl_dest_addr_offset,
dlp->dl_dest_addr_length, DL_SYSERR, ENOSR);
return (GLDE_OK);
}
/* apply any checksum information to the first block in the chain */
(void) hcksum_assoc(nmp, NULL, NULL, start, stuff, end, value,
flags, 0);
GLD_CLEAR_MBLK_VTAG(nmp);
if (gld_start(q, nmp, GLD_WSRV, upri) == GLD_NORESOURCES) {
qenable(q);
return (GLDE_RETRY);
}
return (GLDE_OK);
}
/*
* gldattach(q, mp)
* DLPI DL_ATTACH_REQ
* this attaches the stream to a PPA
*/
static int
gldattach(queue_t *q, mblk_t *mp)
{
dl_attach_req_t *at;
gld_mac_info_t *macinfo;
gld_t *gld = (gld_t *)q->q_ptr;
glddev_t *glddev;
gld_mac_pvt_t *mac_pvt;
uint32_t ppa;
uint32_t vid;
gld_vlan_t *vlan;
at = (dl_attach_req_t *)mp->b_rptr;
if (gld->gld_state != DL_UNATTACHED)
return (DL_OUTSTATE);
ASSERT(!gld->gld_mac_info);
ppa = at->dl_ppa % GLD_VLAN_SCALE; /* 0 .. 999 */
vid = at->dl_ppa / GLD_VLAN_SCALE; /* 0 .. 4094 */
if (vid > VLAN_VID_MAX)
return (DL_BADPPA);
glddev = gld->gld_device;
mutex_enter(&glddev->gld_devlock);
for (macinfo = glddev->gld_mac_next;
macinfo != (gld_mac_info_t *)&glddev->gld_mac_next;
macinfo = macinfo->gldm_next) {
int inst;
ASSERT(macinfo != NULL);
if (macinfo->gldm_ppa != ppa)
continue;
if (!(macinfo->gldm_GLD_flags & GLD_MAC_READY))
continue; /* this one's not ready yet */
/*
* VLAN sanity check
*/
if (vid != VLAN_VID_NONE && !VLAN_CAPABLE(macinfo)) {
mutex_exit(&glddev->gld_devlock);
return (DL_BADPPA);
}
/*
* We found the correct PPA, hold the instance
*/
inst = ddi_get_instance(macinfo->gldm_devinfo);
if (inst == -1 || qassociate(q, inst) != 0) {
mutex_exit(&glddev->gld_devlock);
return (DL_BADPPA);
}
/* Take the stream off the per-driver-class list */
gldremque(gld);
/*
* We must hold the lock to prevent multiple calls
* to the reset and start routines.
*/
GLDM_LOCK(macinfo, RW_WRITER);
gld->gld_mac_info = macinfo;
if (macinfo->gldm_send_tagged != NULL)
gld->gld_send = macinfo->gldm_send_tagged;
else
gld->gld_send = macinfo->gldm_send;
if ((vlan = gld_get_vlan(macinfo, vid)) == NULL) {
GLDM_UNLOCK(macinfo);
gldinsque(gld, glddev->gld_str_prev);
mutex_exit(&glddev->gld_devlock);
(void) qassociate(q, -1);
return (DL_BADPPA);
}
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
if (!mac_pvt->started) {
if (gld_start_mac(macinfo) != GLD_SUCCESS) {
gld_rem_vlan(vlan);
GLDM_UNLOCK(macinfo);
gldinsque(gld, glddev->gld_str_prev);
mutex_exit(&glddev->gld_devlock);
dlerrorack(q, mp, DL_ATTACH_REQ, DL_SYSERR,
EIO);
(void) qassociate(q, -1);
return (GLDE_OK);
}
}
gld->gld_vlan = vlan;
vlan->gldv_nstreams++;
gldinsque(gld, vlan->gldv_str_prev);
gld->gld_state = DL_UNBOUND;
GLDM_UNLOCK(macinfo);
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT) {
cmn_err(CE_NOTE, "gldattach(%p, %p, PPA = %d)",
(void *)q, (void *)mp, macinfo->gldm_ppa);
}
#endif
mutex_exit(&glddev->gld_devlock);
dlokack(q, mp, DL_ATTACH_REQ);
return (GLDE_OK);
}
mutex_exit(&glddev->gld_devlock);
return (DL_BADPPA);
}
/*
* gldunattach(q, mp)
* DLPI DL_DETACH_REQ
* detaches the mac layer from the stream
*/
int
gldunattach(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
glddev_t *glddev = gld->gld_device;
gld_mac_info_t *macinfo = gld->gld_mac_info;
int state = gld->gld_state;
int i;
gld_mac_pvt_t *mac_pvt;
gld_vlan_t *vlan;
boolean_t phys_off;
boolean_t mult_off;
int op = GLD_MAC_PROMISC_NOOP;
if (state != DL_UNBOUND)
return (DL_OUTSTATE);
ASSERT(macinfo != NULL);
ASSERT(gld->gld_sap == 0);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT) {
cmn_err(CE_NOTE, "gldunattach(%p, %p, PPA = %d)",
(void *)q, (void *)mp, macinfo->gldm_ppa);
}
#endif
GLDM_LOCK(macinfo, RW_WRITER);
if (gld->gld_mcast) {
for (i = 0; i < gld->gld_multicnt; i++) {
gld_mcast_t *mcast;
if ((mcast = gld->gld_mcast[i]) != NULL) {
ASSERT(mcast->gldm_refcnt);
gld_send_disable_multi(macinfo, mcast);
}
}
kmem_free(gld->gld_mcast,
sizeof (gld_mcast_t *) * gld->gld_multicnt);
gld->gld_mcast = NULL;
gld->gld_multicnt = 0;
}
/* decide if we need to turn off any promiscuity */
phys_off = (gld->gld_flags & GLD_PROM_PHYS &&
--mac_pvt->nprom == 0);
mult_off = (gld->gld_flags & GLD_PROM_MULT &&
--mac_pvt->nprom_multi == 0);
if (phys_off) {
op = (mac_pvt->nprom_multi == 0) ? GLD_MAC_PROMISC_NONE :
GLD_MAC_PROMISC_MULTI;
} else if (mult_off) {
op = (mac_pvt->nprom == 0) ? GLD_MAC_PROMISC_NONE :
GLD_MAC_PROMISC_NOOP; /* phys overrides multi */
}
if (op != GLD_MAC_PROMISC_NOOP)
(void) (*macinfo->gldm_set_promiscuous)(macinfo, op);
vlan = (gld_vlan_t *)gld->gld_vlan;
if (gld->gld_flags & GLD_PROM_PHYS)
vlan->gldv_nprom--;
if (gld->gld_flags & GLD_PROM_MULT)
vlan->gldv_nprom--;
if (gld->gld_flags & GLD_PROM_SAP) {
vlan->gldv_nprom--;
vlan->gldv_nvlan_sap--;
}
gld->gld_flags &= ~(GLD_PROM_PHYS | GLD_PROM_SAP | GLD_PROM_MULT);
GLDM_UNLOCK(macinfo);
if (phys_off)
gld_notify_ind(macinfo, DL_NOTE_PROMISC_OFF_PHYS, NULL);
/*
* We need to hold both locks when modifying the mac stream list
* to protect findminor as well as everyone else.
*/
mutex_enter(&glddev->gld_devlock);
GLDM_LOCK(macinfo, RW_WRITER);
/* disassociate this stream with its vlan and underlying mac */
gldremque(gld);
if (--vlan->gldv_nstreams == 0) {
gld_rem_vlan(vlan);
gld->gld_vlan = NULL;
}
gld->gld_mac_info = NULL;
gld->gld_state = DL_UNATTACHED;
/* cleanup mac layer if last vlan */
if (mac_pvt->nvlan == 0) {
gld_stop_mac(macinfo);
macinfo->gldm_GLD_flags &= ~GLD_INTR_WAIT;
}
/* make sure no references to this gld for gld_v0_sched */
if (mac_pvt->last_sched == gld)
mac_pvt->last_sched = NULL;
GLDM_UNLOCK(macinfo);
/* put the stream on the unattached Style 2 list */
gldinsque(gld, glddev->gld_str_prev);
mutex_exit(&glddev->gld_devlock);
/* There will be no mp if we were called from close */
if (mp) {
dlokack(q, mp, DL_DETACH_REQ);
}
if (gld->gld_style == DL_STYLE2)
(void) qassociate(q, -1);
return (GLDE_OK);
}
/*
* gld_enable_multi (q, mp)
* Enables multicast address on the stream. If the mac layer
* isn't enabled for this address, enable at that level as well.
*/
static int
gld_enable_multi(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
glddev_t *glddev;
gld_mac_info_t *macinfo = gld->gld_mac_info;
unsigned char *maddr;
dl_enabmulti_req_t *multi;
gld_mcast_t *mcast;
int i, rc;
gld_mac_pvt_t *mac_pvt;
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT) {
cmn_err(CE_NOTE, "gld_enable_multi(%p, %p)", (void *)q,
(void *)mp);
}
#endif
if (gld->gld_state == DL_UNATTACHED)
return (DL_OUTSTATE);
ASSERT(macinfo != NULL);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
if (macinfo->gldm_set_multicast == NULL) {
return (DL_UNSUPPORTED);
}
multi = (dl_enabmulti_req_t *)mp->b_rptr;
if (!MBLKIN(mp, multi->dl_addr_offset, multi->dl_addr_length) ||
multi->dl_addr_length != macinfo->gldm_addrlen)
return (DL_BADADDR);
/* request appears to be valid */
glddev = mac_pvt->major_dev;
ASSERT(glddev == gld->gld_device);
maddr = mp->b_rptr + multi->dl_addr_offset;
/*
* The multicast addresses live in a per-device table, along
* with a reference count. Each stream has a table that
* points to entries in the device table, with the reference
* count reflecting the number of streams pointing at it. If
* this multicast address is already in the per-device table,
* all we have to do is point at it.
*/
GLDM_LOCK(macinfo, RW_WRITER);
/* does this address appear in current table? */
if (gld->gld_mcast == NULL) {
/* no mcast addresses -- allocate table */
gld->gld_mcast = GLD_GETSTRUCT(gld_mcast_t *,
glddev->gld_multisize);
if (gld->gld_mcast == NULL) {
GLDM_UNLOCK(macinfo);
dlerrorack(q, mp, DL_ENABMULTI_REQ, DL_SYSERR, ENOSR);
return (GLDE_OK);
}
gld->gld_multicnt = glddev->gld_multisize;
} else {
for (i = 0; i < gld->gld_multicnt; i++) {
if (gld->gld_mcast[i] &&
mac_eq(gld->gld_mcast[i]->gldm_addr,
maddr, macinfo->gldm_addrlen)) {
/* this is a match -- just succeed */
ASSERT(gld->gld_mcast[i]->gldm_refcnt);
GLDM_UNLOCK(macinfo);
dlokack(q, mp, DL_ENABMULTI_REQ);
return (GLDE_OK);
}
}
}
/*
* it wasn't in the stream so check to see if the mac layer has it
*/
mcast = NULL;
if (mac_pvt->mcast_table == NULL) {
mac_pvt->mcast_table = GLD_GETSTRUCT(gld_mcast_t,
glddev->gld_multisize);
if (mac_pvt->mcast_table == NULL) {
GLDM_UNLOCK(macinfo);
dlerrorack(q, mp, DL_ENABMULTI_REQ, DL_SYSERR, ENOSR);
return (GLDE_OK);
}
} else {
for (i = 0; i < glddev->gld_multisize; i++) {
if (mac_pvt->mcast_table[i].gldm_refcnt &&
mac_eq(mac_pvt->mcast_table[i].gldm_addr,
maddr, macinfo->gldm_addrlen)) {
mcast = &mac_pvt->mcast_table[i];
break;
}
}
}
if (mcast == NULL) {
/* not in mac layer -- find an empty mac slot to fill in */
for (i = 0; i < glddev->gld_multisize; i++) {
if (mac_pvt->mcast_table[i].gldm_refcnt == 0) {
mcast = &mac_pvt->mcast_table[i];
mac_copy(maddr, mcast->gldm_addr,
macinfo->gldm_addrlen);
break;
}
}
}
if (mcast == NULL) {
/* couldn't get a mac layer slot */
GLDM_UNLOCK(macinfo);
return (DL_TOOMANY);
}
/* now we have a mac layer slot in mcast -- get a stream slot */
for (i = 0; i < gld->gld_multicnt; i++) {
if (gld->gld_mcast[i] != NULL)
continue;
/* found an empty slot */
if (!mcast->gldm_refcnt) {
/* set mcast in hardware */
unsigned char cmaddr[GLD_MAX_ADDRLEN];
ASSERT(sizeof (cmaddr) >= macinfo->gldm_addrlen);
cmac_copy(maddr, cmaddr,
macinfo->gldm_addrlen, macinfo);
rc = (*macinfo->gldm_set_multicast)
(macinfo, cmaddr, GLD_MULTI_ENABLE);
if (rc == GLD_NOTSUPPORTED) {
GLDM_UNLOCK(macinfo);
return (DL_NOTSUPPORTED);
} else if (rc == GLD_NORESOURCES) {
GLDM_UNLOCK(macinfo);
return (DL_TOOMANY);
} else if (rc == GLD_BADARG) {
GLDM_UNLOCK(macinfo);
return (DL_BADADDR);
} else if (rc == GLD_RETRY) {
/*
* The putbq and gld_xwait must be
* within the lock to prevent races
* with gld_sched.
*/
(void) putbq(q, mp);
gld->gld_xwait = B_TRUE;
GLDM_UNLOCK(macinfo);
return (GLDE_RETRY);
} else if (rc != GLD_SUCCESS) {
GLDM_UNLOCK(macinfo);
dlerrorack(q, mp, DL_ENABMULTI_REQ,
DL_SYSERR, EIO);
return (GLDE_OK);
}
}
gld->gld_mcast[i] = mcast;
mcast->gldm_refcnt++;
GLDM_UNLOCK(macinfo);
dlokack(q, mp, DL_ENABMULTI_REQ);
return (GLDE_OK);
}
/* couldn't get a stream slot */
GLDM_UNLOCK(macinfo);
return (DL_TOOMANY);
}
/*
* gld_disable_multi (q, mp)
* Disable the multicast address on the stream. If last
* reference for the mac layer, disable there as well.
*/
static int
gld_disable_multi(queue_t *q, mblk_t *mp)
{
gld_t *gld;
gld_mac_info_t *macinfo;
unsigned char *maddr;
dl_disabmulti_req_t *multi;
int i;
gld_mcast_t *mcast;
#ifdef GLD_DEBUG
if (gld_debug & GLDPROT) {
cmn_err(CE_NOTE, "gld_disable_multi(%p, %p)", (void *)q,
(void *)mp);
}
#endif
gld = (gld_t *)q->q_ptr;
if (gld->gld_state == DL_UNATTACHED)
return (DL_OUTSTATE);
macinfo = gld->gld_mac_info;
ASSERT(macinfo != NULL);
if (macinfo->gldm_set_multicast == NULL) {
return (DL_UNSUPPORTED);
}
multi = (dl_disabmulti_req_t *)mp->b_rptr;
if (!MBLKIN(mp, multi->dl_addr_offset, multi->dl_addr_length) ||
multi->dl_addr_length != macinfo->gldm_addrlen)
return (DL_BADADDR);
maddr = mp->b_rptr + multi->dl_addr_offset;
/* request appears to be valid */
/* does this address appear in current table? */
GLDM_LOCK(macinfo, RW_WRITER);
if (gld->gld_mcast != NULL) {
for (i = 0; i < gld->gld_multicnt; i++)
if (((mcast = gld->gld_mcast[i]) != NULL) &&
mac_eq(mcast->gldm_addr,
maddr, macinfo->gldm_addrlen)) {
ASSERT(mcast->gldm_refcnt);
gld_send_disable_multi(macinfo, mcast);
gld->gld_mcast[i] = NULL;
GLDM_UNLOCK(macinfo);
dlokack(q, mp, DL_DISABMULTI_REQ);
return (GLDE_OK);
}
}
GLDM_UNLOCK(macinfo);
return (DL_NOTENAB); /* not an enabled address */
}
/*
* gld_send_disable_multi(macinfo, mcast)
* this function is used to disable a multicast address if the reference
* count goes to zero. The disable request will then be forwarded to the
* lower stream.
*/
static void
gld_send_disable_multi(gld_mac_info_t *macinfo, gld_mcast_t *mcast)
{
ASSERT(macinfo != NULL);
ASSERT(GLDM_LOCK_HELD_WRITE(macinfo));
ASSERT(mcast != NULL);
ASSERT(mcast->gldm_refcnt);
if (!mcast->gldm_refcnt) {
return; /* "cannot happen" */
}
if (--mcast->gldm_refcnt > 0) {
return;
}
/*
* This must be converted from canonical form to device form.
* The refcnt is now zero so we can trash the data.
*/
if (macinfo->gldm_options & GLDOPT_CANONICAL_ADDR)
gld_bitreverse(mcast->gldm_addr, macinfo->gldm_addrlen);
/* XXX Ought to check for GLD_NORESOURCES or GLD_FAILURE */
(void) (*macinfo->gldm_set_multicast)
(macinfo, mcast->gldm_addr, GLD_MULTI_DISABLE);
}
/*
* gld_promisc (q, mp, req, on)
* enable or disable the use of promiscuous mode with the hardware
*/
static int
gld_promisc(queue_t *q, mblk_t *mp, t_uscalar_t req, boolean_t on)
{
gld_t *gld;
gld_mac_info_t *macinfo;
gld_mac_pvt_t *mac_pvt;
gld_vlan_t *vlan;
union DL_primitives *prim;
int macrc = GLD_SUCCESS;
int dlerr = GLDE_OK;
int op = GLD_MAC_PROMISC_NOOP;
#ifdef GLD_DEBUG
if (gld_debug & GLDTRACE)
cmn_err(CE_NOTE, "gld_promisc(%p, %p, %d, %d)",
(void *)q, (void *)mp, req, on);
#endif
ASSERT(mp != NULL);
prim = (union DL_primitives *)mp->b_rptr;
/* XXX I think spec allows promisc in unattached state */
gld = (gld_t *)q->q_ptr;
if (gld->gld_state == DL_UNATTACHED)
return (DL_OUTSTATE);
macinfo = gld->gld_mac_info;
ASSERT(macinfo != NULL);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
vlan = (gld_vlan_t *)gld->gld_vlan;
ASSERT(vlan != NULL);
GLDM_LOCK(macinfo, RW_WRITER);
/*
* Work out what request (if any) has to be made to the MAC layer
*/
if (on) {
switch (prim->promiscon_req.dl_level) {
default:
dlerr = DL_UNSUPPORTED; /* this is an error */
break;
case DL_PROMISC_PHYS:
if (mac_pvt->nprom == 0)
op = GLD_MAC_PROMISC_PHYS;
break;
case DL_PROMISC_MULTI:
if (mac_pvt->nprom_multi == 0)
if (mac_pvt->nprom == 0)
op = GLD_MAC_PROMISC_MULTI;
break;
case DL_PROMISC_SAP:
/* We can do this without reference to the MAC */
break;
}
} else {
switch (prim->promiscoff_req.dl_level) {
default:
dlerr = DL_UNSUPPORTED; /* this is an error */
break;
case DL_PROMISC_PHYS:
if (!(gld->gld_flags & GLD_PROM_PHYS))
dlerr = DL_NOTENAB;
else if (mac_pvt->nprom == 1)
if (mac_pvt->nprom_multi)
op = GLD_MAC_PROMISC_MULTI;
else
op = GLD_MAC_PROMISC_NONE;
break;
case DL_PROMISC_MULTI:
if (!(gld->gld_flags & GLD_PROM_MULT))
dlerr = DL_NOTENAB;
else if (mac_pvt->nprom_multi == 1)
if (mac_pvt->nprom == 0)
op = GLD_MAC_PROMISC_NONE;
break;
case DL_PROMISC_SAP:
if (!(gld->gld_flags & GLD_PROM_SAP))
dlerr = DL_NOTENAB;
/* We can do this without reference to the MAC */
break;
}
}
/*
* The request was invalid in some way so no need to continue.
*/
if (dlerr != GLDE_OK) {
GLDM_UNLOCK(macinfo);
return (dlerr);
}
/*
* Issue the request to the MAC layer, if required
*/
if (op != GLD_MAC_PROMISC_NOOP) {
macrc = (*macinfo->gldm_set_promiscuous)(macinfo, op);
}
/*
* On success, update the appropriate flags & refcounts
*/
if (macrc == GLD_SUCCESS) {
if (on) {
switch (prim->promiscon_req.dl_level) {
case DL_PROMISC_PHYS:
mac_pvt->nprom++;
vlan->gldv_nprom++;
gld->gld_flags |= GLD_PROM_PHYS;
break;
case DL_PROMISC_MULTI:
mac_pvt->nprom_multi++;
vlan->gldv_nprom++;
gld->gld_flags |= GLD_PROM_MULT;
break;
case DL_PROMISC_SAP:
gld->gld_flags |= GLD_PROM_SAP;
vlan->gldv_nprom++;
vlan->gldv_nvlan_sap++;
break;
default:
break;
}
} else {
switch (prim->promiscoff_req.dl_level) {
case DL_PROMISC_PHYS:
mac_pvt->nprom--;
vlan->gldv_nprom--;
gld->gld_flags &= ~GLD_PROM_PHYS;
break;
case DL_PROMISC_MULTI:
mac_pvt->nprom_multi--;
vlan->gldv_nprom--;
gld->gld_flags &= ~GLD_PROM_MULT;
break;
case DL_PROMISC_SAP:
gld->gld_flags &= ~GLD_PROM_SAP;
vlan->gldv_nvlan_sap--;
vlan->gldv_nprom--;
break;
default:
break;
}
}
} else if (macrc == GLD_RETRY) {
/*
* The putbq and gld_xwait must be within the lock to
* prevent races with gld_sched.
*/
(void) putbq(q, mp);
gld->gld_xwait = B_TRUE;
}
GLDM_UNLOCK(macinfo);
/*
* Finally, decide how to reply.
*
* If <macrc> is not GLD_SUCCESS, the request was put to the MAC
* layer but failed. In such cases, we can return a DL_* error
* code and let the caller send an error-ack reply upstream, or
* we can send a reply here and then return GLDE_OK so that the
* caller doesn't also respond.
*
* If physical-promiscuous mode was (successfully) switched on or
* off, send a notification (DL_NOTIFY_IND) to anyone interested.
*/
switch (macrc) {
case GLD_NOTSUPPORTED:
return (DL_NOTSUPPORTED);
case GLD_NORESOURCES:
dlerrorack(q, mp, req, DL_SYSERR, ENOSR);
return (GLDE_OK);
case GLD_RETRY:
return (GLDE_RETRY);
default:
dlerrorack(q, mp, req, DL_SYSERR, EIO);
return (GLDE_OK);
case GLD_SUCCESS:
dlokack(q, mp, req);
break;
}
switch (op) {
case GLD_MAC_PROMISC_NOOP:
break;
case GLD_MAC_PROMISC_PHYS:
gld_notify_ind(macinfo, DL_NOTE_PROMISC_ON_PHYS, NULL);
break;
default:
gld_notify_ind(macinfo, DL_NOTE_PROMISC_OFF_PHYS, NULL);
break;
}
return (GLDE_OK);
}
/*
* gld_physaddr()
* get the current or factory physical address value
*/
static int
gld_physaddr(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo;
union DL_primitives *prim = (union DL_primitives *)mp->b_rptr;
unsigned char addr[GLD_MAX_ADDRLEN];
if (gld->gld_state == DL_UNATTACHED)
return (DL_OUTSTATE);
macinfo = (gld_mac_info_t *)gld->gld_mac_info;
ASSERT(macinfo != NULL);
ASSERT(macinfo->gldm_addrlen <= GLD_MAX_ADDRLEN);
switch (prim->physaddr_req.dl_addr_type) {
case DL_FACT_PHYS_ADDR:
mac_copy((caddr_t)macinfo->gldm_vendor_addr,
(caddr_t)addr, macinfo->gldm_addrlen);
break;
case DL_CURR_PHYS_ADDR:
/* make a copy so we don't hold the lock across qreply */
GLDM_LOCK(macinfo, RW_WRITER);
mac_copy((caddr_t)
((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)->curr_macaddr,
(caddr_t)addr, macinfo->gldm_addrlen);
GLDM_UNLOCK(macinfo);
break;
default:
return (DL_BADPRIM);
}
dlphysaddrack(q, mp, (caddr_t)addr, macinfo->gldm_addrlen);
return (GLDE_OK);
}
/*
* gld_setaddr()
* change the hardware's physical address to a user specified value
*/
static int
gld_setaddr(queue_t *q, mblk_t *mp)
{
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo;
gld_mac_pvt_t *mac_pvt;
union DL_primitives *prim = (union DL_primitives *)mp->b_rptr;
unsigned char *addr;
unsigned char cmaddr[GLD_MAX_ADDRLEN];
int rc;
gld_vlan_t *vlan;
if (gld->gld_state == DL_UNATTACHED)
return (DL_OUTSTATE);
vlan = (gld_vlan_t *)gld->gld_vlan;
ASSERT(vlan != NULL);
if (vlan->gldv_id != VLAN_VID_NONE)
return (DL_NOTSUPPORTED);
macinfo = (gld_mac_info_t *)gld->gld_mac_info;
ASSERT(macinfo != NULL);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
if (!MBLKIN(mp, prim->set_physaddr_req.dl_addr_offset,
prim->set_physaddr_req.dl_addr_length) ||
prim->set_physaddr_req.dl_addr_length != macinfo->gldm_addrlen)
return (DL_BADADDR);
GLDM_LOCK(macinfo, RW_WRITER);
/* now do the set at the hardware level */
addr = mp->b_rptr + prim->set_physaddr_req.dl_addr_offset;
ASSERT(sizeof (cmaddr) >= macinfo->gldm_addrlen);
cmac_copy(addr, cmaddr, macinfo->gldm_addrlen, macinfo);
rc = (*macinfo->gldm_set_mac_addr)(macinfo, cmaddr);
if (rc == GLD_SUCCESS)
mac_copy(addr, mac_pvt->curr_macaddr,
macinfo->gldm_addrlen);
GLDM_UNLOCK(macinfo);
switch (rc) {
case GLD_SUCCESS:
break;
case GLD_NOTSUPPORTED:
return (DL_NOTSUPPORTED);
case GLD_BADARG:
return (DL_BADADDR);
case GLD_NORESOURCES:
dlerrorack(q, mp, DL_SET_PHYS_ADDR_REQ, DL_SYSERR, ENOSR);
return (GLDE_OK);
default:
dlerrorack(q, mp, DL_SET_PHYS_ADDR_REQ, DL_SYSERR, EIO);
return (GLDE_OK);
}
gld_notify_ind(macinfo, DL_NOTE_PHYS_ADDR, NULL);
dlokack(q, mp, DL_SET_PHYS_ADDR_REQ);
return (GLDE_OK);
}
int
gld_get_statistics(queue_t *q, mblk_t *mp)
{
dl_get_statistics_ack_t *dlsp;
gld_t *gld = (gld_t *)q->q_ptr;
gld_mac_info_t *macinfo = gld->gld_mac_info;
gld_mac_pvt_t *mac_pvt;
if (gld->gld_state == DL_UNATTACHED)
return (DL_OUTSTATE);
ASSERT(macinfo != NULL);
mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
(void) gld_update_kstat(mac_pvt->kstatp, KSTAT_READ);
mp = mexchange(q, mp, DL_GET_STATISTICS_ACK_SIZE +
sizeof (struct gldkstats), M_PCPROTO, DL_GET_STATISTICS_ACK);
if (mp == NULL)
return (GLDE_OK); /* mexchange already sent merror */
dlsp = (dl_get_statistics_ack_t *)mp->b_rptr;
dlsp->dl_primitive = DL_GET_STATISTICS_ACK;
dlsp->dl_stat_length = sizeof (struct gldkstats);
dlsp->dl_stat_offset = DL_GET_STATISTICS_ACK_SIZE;
GLDM_LOCK(macinfo, RW_WRITER);
bcopy(mac_pvt->kstatp->ks_data,
(mp->b_rptr + DL_GET_STATISTICS_ACK_SIZE),
sizeof (struct gldkstats));
GLDM_UNLOCK(macinfo);
qreply(q, mp);
return (GLDE_OK);
}
/* =================================================== */
/* misc utilities, some requiring various mutexes held */
/* =================================================== */
/*
* Initialize and start the driver.
*/
static int
gld_start_mac(gld_mac_info_t *macinfo)
{
int rc;
unsigned char cmaddr[GLD_MAX_ADDRLEN];
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
ASSERT(GLDM_LOCK_HELD_WRITE(macinfo));
ASSERT(!mac_pvt->started);
rc = (*macinfo->gldm_reset)(macinfo);
if (rc != GLD_SUCCESS)
return (GLD_FAILURE);
/* set the addr after we reset the device */
ASSERT(sizeof (cmaddr) >= macinfo->gldm_addrlen);
cmac_copy(((gld_mac_pvt_t *)macinfo->gldm_mac_pvt)
->curr_macaddr, cmaddr, macinfo->gldm_addrlen, macinfo);
rc = (*macinfo->gldm_set_mac_addr)(macinfo, cmaddr);
ASSERT(rc != GLD_BADARG); /* this address was good before */
if (rc != GLD_SUCCESS && rc != GLD_NOTSUPPORTED)
return (GLD_FAILURE);
rc = (*macinfo->gldm_start)(macinfo);
if (rc != GLD_SUCCESS)
return (GLD_FAILURE);
mac_pvt->started = B_TRUE;
return (GLD_SUCCESS);
}
/*
* Stop the driver.
*/
static void
gld_stop_mac(gld_mac_info_t *macinfo)
{
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
ASSERT(GLDM_LOCK_HELD_WRITE(macinfo));
ASSERT(mac_pvt->started);
(void) (*macinfo->gldm_stop)(macinfo);
mac_pvt->started = B_FALSE;
}
/*
* gld_set_ipq will set a pointer to the queue which is bound to the
* IP sap if:
* o the device type is ethernet or IPoIB.
* o there is no stream in SAP promiscuous mode.
* o there is exactly one stream bound to the IP sap.
* o the stream is in "fastpath" mode.
*/
static void
gld_set_ipq(gld_t *gld)
{
gld_vlan_t *vlan;
gld_mac_info_t *macinfo = gld->gld_mac_info;
gld_t *ip_gld = NULL;
uint_t ipq_candidates = 0;
gld_t *ipv6_gld = NULL;
uint_t ipv6q_candidates = 0;
ASSERT(GLDM_LOCK_HELD_WRITE(macinfo));
/* The ipq code in gld_recv() is intimate with ethernet/IPoIB */
if (((macinfo->gldm_type != DL_ETHER) &&
(macinfo->gldm_type != DL_IB)) ||
(gld_global_options & GLD_OPT_NO_IPQ))
return;
vlan = (gld_vlan_t *)gld->gld_vlan;
ASSERT(vlan != NULL);
/* clear down any previously defined ipqs */
vlan->gldv_ipq = NULL;
vlan->gldv_ipv6q = NULL;
/* Try to find a single stream eligible to receive IP packets */
for (gld = vlan->gldv_str_next;
gld != (gld_t *)&vlan->gldv_str_next; gld = gld->gld_next) {
if (gld->gld_state != DL_IDLE)
continue; /* not eligible to receive */
if (gld->gld_flags & GLD_STR_CLOSING)
continue; /* not eligible to receive */
if (gld->gld_sap == ETHERTYPE_IP) {
ip_gld = gld;
ipq_candidates++;
}
if (gld->gld_sap == ETHERTYPE_IPV6) {
ipv6_gld = gld;
ipv6q_candidates++;
}
}
if (ipq_candidates == 1) {
ASSERT(ip_gld != NULL);
if (ip_gld->gld_flags & GLD_FAST) /* eligible for ipq */
vlan->gldv_ipq = ip_gld->gld_qptr;
}
if (ipv6q_candidates == 1) {
ASSERT(ipv6_gld != NULL);
if (ipv6_gld->gld_flags & GLD_FAST) /* eligible for ipq */
vlan->gldv_ipv6q = ipv6_gld->gld_qptr;
}
}
/*
* gld_flushqueue (q)
* used by DLPI primitives that require flushing the queues.
* essentially, this is DL_UNBIND_REQ.
*/
static void
gld_flushqueue(queue_t *q)
{
/* flush all data in both queues */
/* XXX Should these be FLUSHALL? */
flushq(q, FLUSHDATA);
flushq(WR(q), FLUSHDATA);
/* flush all the queues upstream */
(void) putctl1(q, M_FLUSH, FLUSHRW);
}
/*
* gld_devlookup (major)
* search the device table for the device with specified
* major number and return a pointer to it if it exists
*/
static glddev_t *
gld_devlookup(int major)
{
struct glddevice *dev;
ASSERT(mutex_owned(&gld_device_list.gld_devlock));
for (dev = gld_device_list.gld_next;
dev != &gld_device_list;
dev = dev->gld_next) {
ASSERT(dev);
if (dev->gld_major == major)
return (dev);
}
return (NULL);
}
/*
* gld_findminor(device)
* Returns a minor number currently unused by any stream in the current
* device class (major) list.
*/
static int
gld_findminor(glddev_t *device)
{
gld_t *next;
gld_mac_info_t *nextmac;
gld_vlan_t *nextvlan;
int minor;
int i;
ASSERT(mutex_owned(&device->gld_devlock));
/* The fast way */
if (device->gld_nextminor >= GLD_MIN_CLONE_MINOR &&
device->gld_nextminor <= GLD_MAX_CLONE_MINOR)
return (device->gld_nextminor++);
/* The steady way */
for (minor = GLD_MIN_CLONE_MINOR; minor <= GLD_MAX_CLONE_MINOR;
minor++) {
/* Search all unattached streams */
for (next = device->gld_str_next;
next != (gld_t *)&device->gld_str_next;
next = next->gld_next) {
if (minor == next->gld_minor)
goto nextminor;
}
/* Search all attached streams; we don't need maclock because */
/* mac stream list is protected by devlock as well as maclock */
for (nextmac = device->gld_mac_next;
nextmac != (gld_mac_info_t *)&device->gld_mac_next;
nextmac = nextmac->gldm_next) {
gld_mac_pvt_t *pvt =
(gld_mac_pvt_t *)nextmac->gldm_mac_pvt;
if (!(nextmac->gldm_GLD_flags & GLD_MAC_READY))
continue; /* this one's not ready yet */
for (i = 0; i < VLAN_HASHSZ; i++) {
for (nextvlan = pvt->vlan_hash[i];
nextvlan != NULL;
nextvlan = nextvlan->gldv_next) {
for (next = nextvlan->gldv_str_next;
next !=
(gld_t *)&nextvlan->gldv_str_next;
next = next->gld_next) {
if (minor == next->gld_minor)
goto nextminor;
}
}
}
}
return (minor);
nextminor:
/* don't need to do anything */
;
}
cmn_err(CE_WARN, "GLD ran out of minor numbers for %s",
device->gld_name);
return (0);
}
/*
* version of insque/remque for use by this driver
*/
struct qelem {
struct qelem *q_forw;
struct qelem *q_back;
/* rest of structure */
};
static void
gldinsque(void *elem, void *pred)
{
struct qelem *pelem = elem;
struct qelem *ppred = pred;
struct qelem *pnext = ppred->q_forw;
pelem->q_forw = pnext;
pelem->q_back = ppred;
ppred->q_forw = pelem;
pnext->q_back = pelem;
}
static void
gldremque(void *arg)
{
struct qelem *pelem = arg;
struct qelem *elem = arg;
pelem->q_forw->q_back = pelem->q_back;
pelem->q_back->q_forw = pelem->q_forw;
elem->q_back = elem->q_forw = NULL;
}
static gld_vlan_t *
gld_add_vlan(gld_mac_info_t *macinfo, uint32_t vid)
{
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
gld_vlan_t **pp;
gld_vlan_t *p;
pp = &(mac_pvt->vlan_hash[vid % VLAN_HASHSZ]);
while ((p = *pp) != NULL) {
ASSERT(p->gldv_id != vid);
pp = &(p->gldv_next);
}
if ((p = kmem_zalloc(sizeof (gld_vlan_t), KM_NOSLEEP)) == NULL)
return (NULL);
p->gldv_mac = macinfo;
p->gldv_id = vid;
if (vid == VLAN_VID_NONE) {
p->gldv_ptag = VLAN_VTAG_NONE;
p->gldv_stats = mac_pvt->statistics;
p->gldv_kstatp = NULL;
} else {
p->gldv_ptag = GLD_MK_PTAG(VLAN_CFI_ETHER, vid);
p->gldv_stats = kmem_zalloc(sizeof (struct gld_stats),
KM_SLEEP);
if (gld_init_vlan_stats(p) != GLD_SUCCESS) {
kmem_free(p->gldv_stats, sizeof (struct gld_stats));
kmem_free(p, sizeof (gld_vlan_t));
return (NULL);
}
}
p->gldv_str_next = p->gldv_str_prev = (gld_t *)&p->gldv_str_next;
mac_pvt->nvlan++;
*pp = p;
return (p);
}
static void
gld_rem_vlan(gld_vlan_t *vlan)
{
gld_mac_info_t *macinfo = vlan->gldv_mac;
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
gld_vlan_t **pp;
gld_vlan_t *p;
pp = &(mac_pvt->vlan_hash[vlan->gldv_id % VLAN_HASHSZ]);
while ((p = *pp) != NULL) {
if (p->gldv_id == vlan->gldv_id)
break;
pp = &(p->gldv_next);
}
ASSERT(p != NULL);
*pp = p->gldv_next;
mac_pvt->nvlan--;
if (p->gldv_id != VLAN_VID_NONE) {
ASSERT(p->gldv_kstatp != NULL);
kstat_delete(p->gldv_kstatp);
kmem_free(p->gldv_stats, sizeof (struct gld_stats));
}
kmem_free(p, sizeof (gld_vlan_t));
}
gld_vlan_t *
gld_find_vlan(gld_mac_info_t *macinfo, uint32_t vid)
{
gld_mac_pvt_t *mac_pvt = (gld_mac_pvt_t *)macinfo->gldm_mac_pvt;
gld_vlan_t *p;
p = mac_pvt->vlan_hash[vid % VLAN_HASHSZ];
while (p != NULL) {
if (p->gldv_id == vid)
return (p);
p = p->gldv_next;
}
return (NULL);
}
gld_vlan_t *
gld_get_vlan(gld_mac_info_t *macinfo, uint32_t vid)
{
gld_vlan_t *vlan;
if ((vlan = gld_find_vlan(macinfo, vid)) == NULL)
vlan = gld_add_vlan(macinfo, vid);
return (vlan);
}
/*
* gld_bitrevcopy()
* This is essentially bcopy, with the ability to bit reverse the
* the source bytes. The MAC addresses bytes as transmitted by FDDI
* interfaces are bit reversed.
*/
void
gld_bitrevcopy(caddr_t src, caddr_t target, size_t n)
{
while (n--)
*target++ = bit_rev[(uchar_t)*src++];
}
/*
* gld_bitreverse()
* Convert the bit order by swaping all the bits, using a
* lookup table.
*/
void
gld_bitreverse(uchar_t *rptr, size_t n)
{
while (n--) {
*rptr = bit_rev[*rptr];
rptr++;
}
}
char *
gld_macaddr_sprintf(char *etherbuf, unsigned char *ap, int len)
{
int i;
char *cp = etherbuf;
static char digits[] = "0123456789abcdef";
for (i = 0; i < len; i++) {
*cp++ = digits[*ap >> 4];
*cp++ = digits[*ap++ & 0xf];
*cp++ = ':';
}
*--cp = 0;
return (etherbuf);
}
#ifdef GLD_DEBUG
static void
gld_check_assertions()
{
glddev_t *dev;
gld_mac_info_t *mac;
gld_t *str;
gld_vlan_t *vlan;
int i;
mutex_enter(&gld_device_list.gld_devlock);
for (dev = gld_device_list.gld_next;
dev != (glddev_t *)&gld_device_list.gld_next;
dev = dev->gld_next) {
mutex_enter(&dev->gld_devlock);
ASSERT(dev->gld_broadcast != NULL);
for (str = dev->gld_str_next;
str != (gld_t *)&dev->gld_str_next;
str = str->gld_next) {
ASSERT(str->gld_device == dev);
ASSERT(str->gld_mac_info == NULL);
ASSERT(str->gld_qptr != NULL);
ASSERT(str->gld_minor >= GLD_MIN_CLONE_MINOR);
ASSERT(str->gld_multicnt == 0);
ASSERT(str->gld_mcast == NULL);
ASSERT(!(str->gld_flags &
(GLD_PROM_PHYS|GLD_PROM_MULT|GLD_PROM_SAP)));
ASSERT(str->gld_sap == 0);
ASSERT(str->gld_state == DL_UNATTACHED);
}
for (mac = dev->gld_mac_next;
mac != (gld_mac_info_t *)&dev->gld_mac_next;
mac = mac->gldm_next) {
int nvlan = 0;
gld_mac_pvt_t *pvt = (gld_mac_pvt_t *)mac->gldm_mac_pvt;
if (!(mac->gldm_GLD_flags & GLD_MAC_READY))
continue; /* this one's not ready yet */
GLDM_LOCK(mac, RW_WRITER);
ASSERT(mac->gldm_devinfo != NULL);
ASSERT(mac->gldm_mac_pvt != NULL);
ASSERT(pvt->interfacep != NULL);
ASSERT(pvt->kstatp != NULL);
ASSERT(pvt->statistics != NULL);
ASSERT(pvt->major_dev == dev);
for (i = 0; i < VLAN_HASHSZ; i++) {
for (vlan = pvt->vlan_hash[i];
vlan != NULL; vlan = vlan->gldv_next) {
int nstr = 0;
ASSERT(vlan->gldv_mac == mac);
for (str = vlan->gldv_str_next;
str !=
(gld_t *)&vlan->gldv_str_next;
str = str->gld_next) {
ASSERT(str->gld_device == dev);
ASSERT(str->gld_mac_info ==
mac);
ASSERT(str->gld_qptr != NULL);
ASSERT(str->gld_minor >=
GLD_MIN_CLONE_MINOR);
ASSERT(
str->gld_multicnt == 0 ||
str->gld_mcast);
nstr++;
}
ASSERT(vlan->gldv_nstreams == nstr);
nvlan++;
}
}
ASSERT(pvt->nvlan == nvlan);
GLDM_UNLOCK(mac);
}
mutex_exit(&dev->gld_devlock);
}
mutex_exit(&gld_device_list.gld_devlock);
}
#endif
|