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
|
/*
* 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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include <sys/nxge/nxge_impl.h>
#include <sys/nxge/nxge_mac.h>
#include <sys/nxge/nxge_hio.h>
/*
* Local defines for FWARC 2006/556
*/
#define NXGE_NIU_TDMA_PROP_LEN 2
#define NXGE_NIU_RDMA_PROP_LEN 2
#define NXGE_NIU_0_INTR_PROP_LEN 19
#define NXGE_NIU_1_INTR_PROP_LEN 17
/*
* Local functions.
*/
static void nxge_get_niu_property(dev_info_t *, niu_type_t *);
static nxge_status_t nxge_get_mac_addr_properties(p_nxge_t);
static nxge_status_t nxge_use_cfg_n2niu_properties(p_nxge_t);
static void nxge_use_cfg_neptune_properties(p_nxge_t);
static void nxge_use_cfg_dma_config(p_nxge_t);
static void nxge_use_cfg_vlan_class_config(p_nxge_t);
static void nxge_use_cfg_mac_class_config(p_nxge_t);
static void nxge_use_cfg_class_config(p_nxge_t);
static void nxge_use_cfg_link_cfg(p_nxge_t);
static void nxge_set_hw_dma_config(p_nxge_t);
static void nxge_set_hw_vlan_class_config(p_nxge_t);
static void nxge_set_hw_mac_class_config(p_nxge_t);
static void nxge_set_hw_class_config(p_nxge_t);
static nxge_status_t nxge_use_default_dma_config_n2(p_nxge_t);
static void nxge_ldgv_setup(p_nxge_ldg_t *, p_nxge_ldv_t *, uint8_t,
uint8_t, int *);
static void nxge_init_mmac(p_nxge_t, boolean_t);
static void nxge_set_rdc_intr_property(p_nxge_t);
uint32_t nxge_use_hw_property = 1;
uint32_t nxge_groups_per_port = 2;
extern uint32_t nxge_use_partition;
extern uint32_t nxge_dma_obp_props_only;
extern uint_t nxge_rx_intr(void *, void *);
extern uint_t nxge_tx_intr(void *, void *);
extern uint_t nxge_mif_intr(void *, void *);
extern uint_t nxge_mac_intr(void *, void *);
extern uint_t nxge_syserr_intr(void *, void *);
extern void *nxge_list;
#define NXGE_SHARED_REG_SW_SIM
#ifdef NXGE_SHARED_REG_SW_SIM
uint64_t global_dev_ctrl = 0;
#endif
#define MAX_SIBLINGS NXGE_MAX_PORTS
extern uint32_t nxge_rbr_size;
extern uint32_t nxge_rcr_size;
extern uint32_t nxge_tx_ring_size;
extern uint32_t nxge_rbr_spare_size;
extern npi_status_t npi_mac_altaddr_disable(npi_handle_t, uint8_t, uint8_t);
static uint8_t p2_tx_fair[2] = {12, 12};
static uint8_t p2_tx_equal[2] = {12, 12};
static uint8_t p4_tx_fair[4] = {6, 6, 6, 6};
static uint8_t p4_tx_equal[4] = {6, 6, 6, 6};
static uint8_t p2_rx_fair[2] = {8, 8};
static uint8_t p2_rx_equal[2] = {8, 8};
static uint8_t p4_rx_fair[4] = {4, 4, 4, 4};
static uint8_t p4_rx_equal[4] = {4, 4, 4, 4};
static uint8_t p2_rdcgrp_fair[2] = {4, 4};
static uint8_t p2_rdcgrp_equal[2] = {4, 4};
static uint8_t p4_rdcgrp_fair[4] = {2, 2, 1, 1};
static uint8_t p4_rdcgrp_equal[4] = {2, 2, 2, 2};
static uint8_t p2_rdcgrp_cls[2] = {1, 1};
static uint8_t p4_rdcgrp_cls[4] = {1, 1, 1, 1};
static uint8_t rx_4_1G[4] = {4, 4, 4, 4};
static uint8_t rx_2_10G[2] = {8, 8};
static uint8_t rx_2_10G_2_1G[4] = {6, 6, 2, 2};
static uint8_t rx_1_10G_3_1G[4] = {10, 2, 2, 2};
static uint8_t rx_1_1G_1_10G_2_1G[4] = {2, 10, 2, 2};
static uint8_t tx_4_1G[4] = {6, 6, 6, 6};
static uint8_t tx_2_10G[2] = {12, 12};
static uint8_t tx_2_10G_2_1G[4] = {10, 10, 2, 2};
static uint8_t tx_1_10G_3_1G[4] = {12, 4, 4, 4};
static uint8_t tx_1_1G_1_10G_2_1G[4] = {4, 12, 4, 4};
typedef enum {
DEFAULT = 0,
EQUAL,
FAIR,
CUSTOM,
CLASSIFY,
L2_CLASSIFY,
L3_DISTRIBUTE,
L3_CLASSIFY,
L3_TCAM,
CONFIG_TOKEN_NONE
} config_token_t;
static char *token_names[] = {
"default",
"equal",
"fair",
"custom",
"classify",
"l2_classify",
"l3_distribute",
"l3_classify",
"l3_tcam",
"none",
};
void nxge_virint_regs_dump(p_nxge_t nxgep);
void
nxge_virint_regs_dump(p_nxge_t nxgep)
{
npi_handle_t handle;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_virint_regs_dump"));
handle = NXGE_DEV_NPI_HANDLE(nxgep);
(void) npi_vir_dump_pio_fzc_regs_one(handle);
(void) npi_vir_dump_ldgnum(handle);
(void) npi_vir_dump_ldsv(handle);
(void) npi_vir_dump_imask0(handle);
(void) npi_vir_dump_sid(handle);
(void) npi_mac_dump_regs(handle, nxgep->function_num);
(void) npi_ipp_dump_regs(handle, nxgep->function_num);
(void) npi_fflp_dump_regs(handle);
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_virint_regs_dump"));
}
/*
* For now: we hard coded the DMA configurations.
* and assume for one partition only.
*
* OBP. Then OBP will pass this partition's
* Neptune configurations to fcode to create
* properties for them.
*
* Since Neptune(PCI-E) and NIU (Niagara-2) has
* different bus interfaces, the driver needs
* to know which bus it is connected to.
* Ravinder suggested: create a device property.
* In partitioning environment, we cannot
* use .conf file (need to check). If conf changes,
* need to reboot the system.
* The following function assumes that we will
* retrieve its properties from a virtualized nexus driver.
*/
nxge_status_t
nxge_cntlops(dev_info_t *dip, nxge_ctl_enum_t ctlop, void *arg, void *result)
{
nxge_status_t status = NXGE_OK;
int instance;
p_nxge_t nxgep;
#ifndef NXGE_SHARED_REG_SW_SIM
npi_handle_t handle;
uint16_t sr16, cr16;
#endif
instance = ddi_get_instance(dip);
NXGE_DEBUG_MSG((NULL, VIR_CTL, "Instance %d ", instance));
if (nxge_list == NULL) {
NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
"nxge_cntlops: nxge_list null"));
return (NXGE_ERROR);
}
nxgep = (p_nxge_t)ddi_get_soft_state(nxge_list, instance);
if (nxgep == NULL) {
NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
"nxge_cntlops: nxgep null"));
return (NXGE_ERROR);
}
#ifndef NXGE_SHARED_REG_SW_SIM
handle = nxgep->npi_reg_handle;
#endif
switch (ctlop) {
case NXGE_CTLOPS_NIUTYPE:
nxge_get_niu_property(dip, (niu_type_t *)result);
return (status);
case NXGE_CTLOPS_GET_SHARED_REG:
#ifdef NXGE_SHARED_REG_SW_SIM
*(uint64_t *)result = global_dev_ctrl;
return (0);
#else
status = npi_dev_func_sr_sr_get(handle, &sr16);
*(uint16_t *)result = sr16;
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_GET_SHARED_REG"));
return (0);
#endif
case NXGE_CTLOPS_SET_SHARED_REG_LOCK:
#ifdef NXGE_SHARED_REG_SW_SIM
global_dev_ctrl = *(uint64_t *)arg;
return (0);
#else
status = NPI_FAILURE;
while (status != NPI_SUCCESS)
status = npi_dev_func_sr_lock_enter(handle);
sr16 = *(uint16_t *)arg;
status = npi_dev_func_sr_sr_set_only(handle, &sr16);
status = npi_dev_func_sr_lock_free(handle);
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
return (0);
#endif
case NXGE_CTLOPS_UPDATE_SHARED_REG:
#ifdef NXGE_SHARED_REG_SW_SIM
global_dev_ctrl |= *(uint64_t *)arg;
return (0);
#else
status = NPI_FAILURE;
while (status != NPI_SUCCESS)
status = npi_dev_func_sr_lock_enter(handle);
status = npi_dev_func_sr_sr_get(handle, &sr16);
sr16 |= *(uint16_t *)arg;
status = npi_dev_func_sr_sr_set_only(handle, &sr16);
status = npi_dev_func_sr_lock_free(handle);
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
return (0);
#endif
case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG_UL:
#ifdef NXGE_SHARED_REG_SW_SIM
global_dev_ctrl |= *(uint64_t *)arg;
return (0);
#else
status = npi_dev_func_sr_sr_get(handle, &sr16);
cr16 = *(uint16_t *)arg;
sr16 &= ~cr16;
status = npi_dev_func_sr_sr_set_only(handle, &sr16);
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
return (0);
#endif
case NXGE_CTLOPS_CLEAR_BIT_SHARED_REG:
#ifdef NXGE_SHARED_REG_SW_SIM
global_dev_ctrl |= *(uint64_t *)arg;
return (0);
#else
status = NPI_FAILURE;
while (status != NPI_SUCCESS)
status = npi_dev_func_sr_lock_enter(handle);
status = npi_dev_func_sr_sr_get(handle, &sr16);
cr16 = *(uint16_t *)arg;
sr16 &= ~cr16;
status = npi_dev_func_sr_sr_set_only(handle, &sr16);
status = npi_dev_func_sr_lock_free(handle);
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_SET_SHARED_REG"));
return (0);
#endif
case NXGE_CTLOPS_GET_LOCK_BLOCK:
#ifdef NXGE_SHARED_REG_SW_SIM
global_dev_ctrl |= *(uint64_t *)arg;
return (0);
#else
status = NPI_FAILURE;
while (status != NPI_SUCCESS)
status = npi_dev_func_sr_lock_enter(handle);
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_GET_LOCK_BLOCK"));
return (0);
#endif
case NXGE_CTLOPS_GET_LOCK_TRY:
#ifdef NXGE_SHARED_REG_SW_SIM
global_dev_ctrl |= *(uint64_t *)arg;
return (0);
#else
status = npi_dev_func_sr_lock_enter(handle);
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_GET_LOCK_TRY"));
if (status == NPI_SUCCESS)
return (NXGE_OK);
else
return (NXGE_ERROR);
#endif
case NXGE_CTLOPS_FREE_LOCK:
#ifdef NXGE_SHARED_REG_SW_SIM
global_dev_ctrl |= *(uint64_t *)arg;
return (0);
#else
status = npi_dev_func_sr_lock_free(handle);
NXGE_DEBUG_MSG((NULL, VIR_CTL,
"nxge_cntlops: NXGE_CTLOPS_GET_LOCK_FREE"));
if (status == NPI_SUCCESS)
return (NXGE_OK);
else
return (NXGE_ERROR);
#endif
default:
status = NXGE_ERROR;
}
return (status);
}
void
nxge_common_lock_get(p_nxge_t nxgep)
{
uint32_t status = NPI_FAILURE;
npi_handle_t handle;
#if defined(NXGE_SHARE_REG_SW_SIM)
return;
#endif
handle = nxgep->npi_reg_handle;
while (status != NPI_SUCCESS)
status = npi_dev_func_sr_lock_enter(handle);
}
void
nxge_common_lock_free(p_nxge_t nxgep)
{
npi_handle_t handle;
#if defined(NXGE_SHARE_REG_SW_SIM)
return;
#endif
handle = nxgep->npi_reg_handle;
(void) npi_dev_func_sr_lock_free(handle);
}
static void
nxge_get_niu_property(dev_info_t *dip, niu_type_t *niu_type)
{
uchar_t *prop_val;
uint_t prop_len;
*niu_type = NIU_TYPE_NONE;
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0,
"niu-type", (uchar_t **)&prop_val,
&prop_len) == DDI_PROP_SUCCESS) {
if (strncmp("niu", (caddr_t)prop_val, (size_t)prop_len) == 0) {
*niu_type = N2_NIU;
}
ddi_prop_free(prop_val);
}
}
static config_token_t
nxge_get_config_token(char *prop)
{
config_token_t token = DEFAULT;
while (token < CONFIG_TOKEN_NONE) {
if (strncmp(prop, token_names[token], 4) == 0)
break;
token++;
}
return (token);
}
/* per port */
static nxge_status_t
nxge_update_rxdma_grp_properties(p_nxge_t nxgep, config_token_t token,
dev_info_t *s_dip[])
{
nxge_status_t status = NXGE_OK;
int ddi_status;
int num_ports = nxgep->nports;
int port, bits, j;
uint8_t start_grp = 0, num_grps = 0;
p_nxge_param_t param_arr;
uint32_t grp_bitmap[MAX_SIBLINGS];
int custom_start_grp[MAX_SIBLINGS];
int custom_num_grp[MAX_SIBLINGS];
uint8_t bad_config = B_FALSE;
char *start_prop, *num_prop, *cfg_prop;
start_grp = 0;
param_arr = nxgep->param_arr;
start_prop = param_arr[param_rdc_grps_start].fcode_name;
num_prop = param_arr[param_rx_rdc_grps].fcode_name;
switch (token) {
case FAIR:
cfg_prop = "fair";
for (port = 0; port < num_ports; port++) {
custom_num_grp[port] =
(num_ports == 4) ?
p4_rdcgrp_fair[port] :
p2_rdcgrp_fair[port];
custom_start_grp[port] = start_grp;
start_grp += custom_num_grp[port];
}
break;
case EQUAL:
cfg_prop = "equal";
for (port = 0; port < num_ports; port++) {
custom_num_grp[port] =
(num_ports == 4) ?
p4_rdcgrp_equal[port] :
p2_rdcgrp_equal[port];
custom_start_grp[port] = start_grp;
start_grp += custom_num_grp[port];
}
break;
case CLASSIFY:
cfg_prop = "classify";
for (port = 0; port < num_ports; port++) {
custom_num_grp[port] = (num_ports == 4) ?
p4_rdcgrp_cls[port] : p2_rdcgrp_cls[port];
custom_start_grp[port] = start_grp;
start_grp += custom_num_grp[port];
}
break;
case CUSTOM:
cfg_prop = "custom";
/* See if it is good config */
num_grps = 0;
for (port = 0; port < num_ports; port++) {
custom_start_grp[port] =
ddi_prop_get_int(DDI_DEV_T_NONE, s_dip[port],
DDI_PROP_DONTPASS, start_prop, -1);
if ((custom_start_grp[port] == -1) ||
(custom_start_grp[port] >=
NXGE_MAX_RDC_GRPS)) {
bad_config = B_TRUE;
break;
}
custom_num_grp[port] = ddi_prop_get_int(
DDI_DEV_T_NONE,
s_dip[port],
DDI_PROP_DONTPASS,
num_prop, -1);
if ((custom_num_grp[port] == -1) ||
(custom_num_grp[port] >
NXGE_MAX_RDC_GRPS) ||
((custom_num_grp[port] +
custom_start_grp[port]) >=
NXGE_MAX_RDC_GRPS)) {
bad_config = B_TRUE;
break;
}
num_grps += custom_num_grp[port];
if (num_grps > NXGE_MAX_RDC_GRPS) {
bad_config = B_TRUE;
break;
}
grp_bitmap[port] = 0;
for (bits = 0;
bits < custom_num_grp[port];
bits++) {
grp_bitmap[port] |=
(1 << (bits + custom_start_grp[port]));
}
}
if (bad_config == B_FALSE) {
/* check for overlap */
for (port = 0; port < num_ports - 1; port++) {
for (j = port + 1; j < num_ports; j++) {
if (grp_bitmap[port] &
grp_bitmap[j]) {
bad_config = B_TRUE;
break;
}
}
if (bad_config == B_TRUE)
break;
}
}
if (bad_config == B_TRUE) {
/* use default config */
for (port = 0; port < num_ports; port++) {
custom_num_grp[port] =
(num_ports == 4) ?
p4_rx_fair[port] : p2_rx_fair[port];
custom_start_grp[port] = start_grp;
start_grp += custom_num_grp[port];
}
}
break;
default:
/* use default config */
cfg_prop = "fair";
for (port = 0; port < num_ports; port++) {
custom_num_grp[port] = (num_ports == 4) ?
p4_rx_fair[port] : p2_rx_fair[port];
custom_start_grp[port] = start_grp;
start_grp += custom_num_grp[port];
}
break;
}
/* Now Update the rx properties */
for (port = 0; port < num_ports; port++) {
ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
"rxdma-grp-cfg", cfg_prop);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating",
cfg_prop));
status |= NXGE_DDI_FAILED;
}
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
num_prop, custom_num_grp[port]);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating",
num_prop));
status |= NXGE_DDI_FAILED;
}
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
start_prop, custom_start_grp[port]);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating",
start_prop));
status |= NXGE_DDI_FAILED;
}
}
if (status & NXGE_DDI_FAILED)
status |= NXGE_ERROR;
return (status);
}
static nxge_status_t
nxge_update_rxdma_properties(p_nxge_t nxgep, config_token_t token,
dev_info_t *s_dip[])
{
nxge_status_t status = NXGE_OK;
int ddi_status;
int num_ports = nxgep->nports;
int port, bits, j;
uint8_t start_rdc = 0, num_rdc = 0;
p_nxge_param_t param_arr;
uint32_t rdc_bitmap[MAX_SIBLINGS];
int custom_start_rdc[MAX_SIBLINGS];
int custom_num_rdc[MAX_SIBLINGS];
uint8_t bad_config = B_FALSE;
int *prop_val;
uint_t prop_len;
char *start_rdc_prop, *num_rdc_prop, *cfg_prop;
start_rdc = 0;
param_arr = nxgep->param_arr;
start_rdc_prop = param_arr[param_rxdma_channels_begin].fcode_name;
num_rdc_prop = param_arr[param_rxdma_channels].fcode_name;
switch (token) {
case FAIR:
cfg_prop = "fair";
for (port = 0; port < num_ports; port++) {
custom_num_rdc[port] = (num_ports == 4) ?
p4_rx_fair[port] : p2_rx_fair[port];
custom_start_rdc[port] = start_rdc;
start_rdc += custom_num_rdc[port];
}
break;
case EQUAL:
cfg_prop = "equal";
for (port = 0; port < num_ports; port++) {
custom_num_rdc[port] = (num_ports == 4) ?
p4_rx_equal[port] :
p2_rx_equal[port];
custom_start_rdc[port] = start_rdc;
start_rdc += custom_num_rdc[port];
}
break;
case CUSTOM:
cfg_prop = "custom";
/* See if it is good config */
num_rdc = 0;
for (port = 0; port < num_ports; port++) {
ddi_status = ddi_prop_lookup_int_array(
DDI_DEV_T_ANY,
s_dip[port], 0,
start_rdc_prop,
&prop_val,
&prop_len);
if (ddi_status == DDI_SUCCESS)
custom_start_rdc[port] = *prop_val;
else {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom start port %d"
" read failed ",
" rxdma-cfg", port));
bad_config = B_TRUE;
status |= NXGE_DDI_FAILED;
}
if ((custom_start_rdc[port] == -1) ||
(custom_start_rdc[port] >=
NXGE_MAX_RDCS)) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom start %d"
" out of range %x ",
" rxdma-cfg",
port,
custom_start_rdc[port]));
bad_config = B_TRUE;
break;
}
ddi_status = ddi_prop_lookup_int_array(
DDI_DEV_T_ANY,
s_dip[port],
0,
num_rdc_prop,
&prop_val,
&prop_len);
if (ddi_status == DDI_SUCCESS)
custom_num_rdc[port] = *prop_val;
else {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom num port %d"
" read failed ",
"rxdma-cfg", port));
bad_config = B_TRUE;
status |= NXGE_DDI_FAILED;
}
if ((custom_num_rdc[port] == -1) ||
(custom_num_rdc[port] >
NXGE_MAX_RDCS) ||
((custom_num_rdc[port] +
custom_start_rdc[port]) >
NXGE_MAX_RDCS)) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom num %d"
" out of range %x ",
" rxdma-cfg",
port, custom_num_rdc[port]));
bad_config = B_TRUE;
break;
}
num_rdc += custom_num_rdc[port];
if (num_rdc > NXGE_MAX_RDCS) {
bad_config = B_TRUE;
break;
}
rdc_bitmap[port] = 0;
for (bits = 0;
bits < custom_num_rdc[port]; bits++) {
rdc_bitmap[port] |=
(1 << (bits + custom_start_rdc[port]));
}
}
if (bad_config == B_FALSE) {
/* check for overlap */
for (port = 0; port < num_ports - 1; port++) {
for (j = port + 1; j < num_ports; j++) {
if (rdc_bitmap[port] &
rdc_bitmap[j]) {
NXGE_DEBUG_MSG((nxgep,
CFG_CTL,
" rxdma-cfg"
" property custom"
" bit overlap"
" %d %d ",
port, j));
bad_config = B_TRUE;
break;
}
}
if (bad_config == B_TRUE)
break;
}
}
if (bad_config == B_TRUE) {
/* use default config */
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" rxdma-cfg property:"
" bad custom config:"
" use default"));
for (port = 0; port < num_ports; port++) {
custom_num_rdc[port] =
(num_ports == 4) ?
p4_rx_fair[port] :
p2_rx_fair[port];
custom_start_rdc[port] = start_rdc;
start_rdc += custom_num_rdc[port];
}
}
break;
default:
/* use default config */
cfg_prop = "fair";
for (port = 0; port < num_ports; port++) {
custom_num_rdc[port] = (num_ports == 4) ?
p4_rx_fair[port] : p2_rx_fair[port];
custom_start_rdc[port] = start_rdc;
start_rdc += custom_num_rdc[port];
}
break;
}
/* Now Update the rx properties */
for (port = 0; port < num_ports; port++) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" update property rxdma-cfg with %s ", cfg_prop));
ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
"rxdma-cfg", cfg_prop);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property rxdma-cfg is not updating to %s",
cfg_prop));
status |= NXGE_DDI_FAILED;
}
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
num_rdc_prop, custom_num_rdc[port]));
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
num_rdc_prop, custom_num_rdc[port]);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating with %d",
num_rdc_prop, custom_num_rdc[port]));
status |= NXGE_DDI_FAILED;
}
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
start_rdc_prop, custom_start_rdc[port]));
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
start_rdc_prop, custom_start_rdc[port]);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating with %d ",
start_rdc_prop, custom_start_rdc[port]));
status |= NXGE_DDI_FAILED;
}
}
if (status & NXGE_DDI_FAILED)
status |= NXGE_ERROR;
return (status);
}
static nxge_status_t
nxge_update_txdma_properties(p_nxge_t nxgep, config_token_t token,
dev_info_t *s_dip[])
{
nxge_status_t status = NXGE_OK;
int ddi_status = DDI_SUCCESS;
int num_ports = nxgep->nports;
int port, bits, j;
uint8_t start_tdc, num_tdc = 0;
p_nxge_param_t param_arr;
uint32_t tdc_bitmap[MAX_SIBLINGS];
int custom_start_tdc[MAX_SIBLINGS];
int custom_num_tdc[MAX_SIBLINGS];
uint8_t bad_config = B_FALSE;
int *prop_val;
uint_t prop_len;
char *start_tdc_prop, *num_tdc_prop, *cfg_prop;
start_tdc = 0;
param_arr = nxgep->param_arr;
start_tdc_prop = param_arr[param_txdma_channels_begin].fcode_name;
num_tdc_prop = param_arr[param_txdma_channels].fcode_name;
switch (token) {
case FAIR:
cfg_prop = "fair";
for (port = 0; port < num_ports; port++) {
custom_num_tdc[port] = (num_ports == 4) ?
p4_tx_fair[port] : p2_tx_fair[port];
custom_start_tdc[port] = start_tdc;
start_tdc += custom_num_tdc[port];
}
break;
case EQUAL:
cfg_prop = "equal";
for (port = 0; port < num_ports; port++) {
custom_num_tdc[port] = (num_ports == 4) ?
p4_tx_equal[port] : p2_tx_equal[port];
custom_start_tdc[port] = start_tdc;
start_tdc += custom_num_tdc[port];
}
break;
case CUSTOM:
cfg_prop = "custom";
/* See if it is good config */
num_tdc = 0;
for (port = 0; port < num_ports; port++) {
ddi_status = ddi_prop_lookup_int_array(
DDI_DEV_T_ANY, s_dip[port], 0, start_tdc_prop,
&prop_val, &prop_len);
if (ddi_status == DDI_SUCCESS)
custom_start_tdc[port] = *prop_val;
else {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom start port %d"
" read failed ", " txdma-cfg", port));
bad_config = B_TRUE;
status |= NXGE_DDI_FAILED;
}
if ((custom_start_tdc[port] == -1) ||
(custom_start_tdc[port] >=
NXGE_MAX_RDCS)) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom start %d"
" out of range %x ", " txdma-cfg",
port, custom_start_tdc[port]));
bad_config = B_TRUE;
break;
}
ddi_status = ddi_prop_lookup_int_array(
DDI_DEV_T_ANY, s_dip[port], 0, num_tdc_prop,
&prop_val, &prop_len);
if (ddi_status == DDI_SUCCESS)
custom_num_tdc[port] = *prop_val;
else {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom num port %d"
" read failed ", " txdma-cfg", port));
bad_config = B_TRUE;
status |= NXGE_DDI_FAILED;
}
if ((custom_num_tdc[port] == -1) ||
(custom_num_tdc[port] >
NXGE_MAX_TDCS) ||
((custom_num_tdc[port] +
custom_start_tdc[port]) >
NXGE_MAX_TDCS)) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s custom num %d"
" out of range %x ", " rxdma-cfg",
port, custom_num_tdc[port]));
bad_config = B_TRUE;
break;
}
num_tdc += custom_num_tdc[port];
if (num_tdc > NXGE_MAX_TDCS) {
bad_config = B_TRUE;
break;
}
tdc_bitmap[port] = 0;
for (bits = 0;
bits < custom_num_tdc[port]; bits++) {
tdc_bitmap[port] |=
(1 <<
(bits + custom_start_tdc[port]));
}
}
if (bad_config == B_FALSE) {
/* check for overlap */
for (port = 0; port < num_ports - 1; port++) {
for (j = port + 1; j < num_ports; j++) {
if (tdc_bitmap[port] &
tdc_bitmap[j]) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" rxdma-cfg"
" property custom"
" bit overlap"
" %d %d ",
port, j));
bad_config = B_TRUE;
break;
}
}
if (bad_config == B_TRUE)
break;
}
}
if (bad_config == B_TRUE) {
/* use default config */
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" txdma-cfg property:"
" bad custom config:" " use default"));
for (port = 0; port < num_ports; port++) {
custom_num_tdc[port] = (num_ports == 4) ?
p4_tx_fair[port] : p2_tx_fair[port];
custom_start_tdc[port] = start_tdc;
start_tdc += custom_num_tdc[port];
}
}
break;
default:
/* use default config */
cfg_prop = "fair";
for (port = 0; port < num_ports; port++) {
custom_num_tdc[port] = (num_ports == 4) ?
p4_tx_fair[port] : p2_tx_fair[port];
custom_start_tdc[port] = start_tdc;
start_tdc += custom_num_tdc[port];
}
break;
}
/* Now Update the tx properties */
for (port = 0; port < num_ports; port++) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" update property txdma-cfg with %s ", cfg_prop));
ddi_status = ddi_prop_update_string(DDI_DEV_T_NONE, s_dip[port],
"txdma-cfg", cfg_prop);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property txdma-cfg is not updating to %s",
cfg_prop));
status |= NXGE_DDI_FAILED;
}
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
num_tdc_prop, custom_num_tdc[port]));
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
num_tdc_prop, custom_num_tdc[port]);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating with %d",
num_tdc_prop,
custom_num_tdc[port]));
status |= NXGE_DDI_FAILED;
}
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " update property %s with %d ",
start_tdc_prop, custom_start_tdc[port]));
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, s_dip[port],
start_tdc_prop, custom_start_tdc[port]);
if (ddi_status != DDI_PROP_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating with %d ",
start_tdc_prop, custom_start_tdc[port]));
status |= NXGE_DDI_FAILED;
}
}
if (status & NXGE_DDI_FAILED)
status |= NXGE_ERROR;
return (status);
}
static nxge_status_t
nxge_update_cfg_properties(p_nxge_t nxgep, uint32_t flags,
config_token_t token, dev_info_t *s_dip[])
{
nxge_status_t status = NXGE_OK;
switch (flags) {
case COMMON_TXDMA_CFG:
if (nxge_dma_obp_props_only == 0)
status = nxge_update_txdma_properties(nxgep,
token, s_dip);
break;
case COMMON_RXDMA_CFG:
if (nxge_dma_obp_props_only == 0)
status = nxge_update_rxdma_properties(nxgep,
token, s_dip);
break;
case COMMON_RXDMA_GRP_CFG:
status = nxge_update_rxdma_grp_properties(nxgep,
token, s_dip);
break;
default:
return (NXGE_ERROR);
}
return (status);
}
/*
* verify consistence.
* (May require publishing the properties on all the ports.
*
* What if properties are published on function 0 device only?
*
*
* rxdma-cfg, txdma-cfg, rxdma-grp-cfg (required )
* What about class configs?
*
* If consistent, update the property on all the siblings.
* set a flag on hardware shared register
* The rest of the siblings will check the flag
* if the flag is set, they will use the updated property
* without doing any validation.
*/
nxge_status_t
nxge_cfg_verify_set_classify_prop(p_nxge_t nxgep, char *prop,
uint64_t known_cfg, uint32_t override, dev_info_t *c_dip[])
{
nxge_status_t status = NXGE_OK;
int ddi_status = DDI_SUCCESS;
int i = 0, found = 0, update_prop = B_TRUE;
int *cfg_val;
uint_t new_value, cfg_value[MAX_SIBLINGS];
uint_t prop_len;
uint_t known_cfg_value;
known_cfg_value = (uint_t)known_cfg;
if (override == B_TRUE) {
new_value = known_cfg_value;
for (i = 0; i < nxgep->nports; i++) {
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
c_dip[i], prop, new_value);
#ifdef NXGE_DEBUG_ERROR
if (ddi_status != DDI_PROP_SUCCESS)
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s failed update ", prop));
#endif
}
if (ddi_status != DDI_PROP_SUCCESS)
return (NXGE_ERROR | NXGE_DDI_FAILED);
}
for (i = 0; i < nxgep->nports; i++) {
cfg_value[i] = known_cfg_value;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, c_dip[i], 0,
prop, &cfg_val,
&prop_len) == DDI_PROP_SUCCESS) {
cfg_value[i] = *cfg_val;
ddi_prop_free(cfg_val);
found++;
}
}
if (found != i) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property %s not specified on all ports", prop));
if (found == 0) {
/* not specified: Use default */
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property %s not specified on any port:"
" Using default", prop));
new_value = known_cfg_value;
} else {
/* specified on some */
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property %s not specified"
" on some ports: Using default", prop));
/* ? use p0 value instead ? */
new_value = known_cfg_value;
}
} else {
/* check type and consistence */
/* found on all devices */
for (i = 1; i < found; i++) {
if (cfg_value[i] != cfg_value[i - 1]) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property %s inconsistent:"
" Using default", prop));
new_value = known_cfg_value;
break;
}
/*
* Found on all the ports and consistent. Nothing to
* do.
*/
update_prop = B_FALSE;
}
}
if (update_prop == B_TRUE) {
for (i = 0; i < nxgep->nports; i++) {
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE,
c_dip[i], prop, new_value);
#ifdef NXGE_DEBUG_ERROR
if (ddi_status != DDI_SUCCESS)
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" property %s not updating with %d"
" Using default",
prop, new_value));
#endif
if (ddi_status != DDI_PROP_SUCCESS)
status |= NXGE_DDI_FAILED;
}
}
if (status & NXGE_DDI_FAILED)
status |= NXGE_ERROR;
return (status);
}
static uint64_t
nxge_class_get_known_cfg(p_nxge_t nxgep, int class_prop, int rx_quick_cfg)
{
int start_prop;
uint64_t cfg_value;
p_nxge_param_t param_arr;
param_arr = nxgep->param_arr;
cfg_value = param_arr[class_prop].value;
start_prop = param_h1_init_value;
/* update the properties per quick config */
switch (rx_quick_cfg) {
case CFG_L3_WEB:
case CFG_L3_DISTRIBUTE:
cfg_value = nxge_classify_get_cfg_value(nxgep,
rx_quick_cfg, class_prop - start_prop);
break;
default:
cfg_value = param_arr[class_prop].value;
break;
}
return (cfg_value);
}
static nxge_status_t
nxge_cfg_verify_set_classify(p_nxge_t nxgep, dev_info_t *c_dip[])
{
nxge_status_t status = NXGE_OK;
int rx_quick_cfg, class_prop, start_prop, end_prop;
char *prop_name;
int override = B_TRUE;
uint64_t cfg_value;
p_nxge_param_t param_arr;
param_arr = nxgep->param_arr;
rx_quick_cfg = param_arr[param_rx_quick_cfg].value;
start_prop = param_h1_init_value;
end_prop = param_class_opt_ipv6_sctp;
/* update the properties per quick config */
if (rx_quick_cfg == CFG_NOT_SPECIFIED)
override = B_FALSE;
/*
* these parameter affect the classification outcome.
* these parameters are used to configure the Flow key and
* the TCAM key for each of the IP classes.
* Included here are also the H1 and H2 initial values
* which affect the distribution as well as final hash value
* (hence the offset into RDC table and FCRAM bucket location)
*
*/
for (class_prop = start_prop; class_prop <= end_prop; class_prop++) {
prop_name = param_arr[class_prop].fcode_name;
cfg_value = nxge_class_get_known_cfg(nxgep,
class_prop, rx_quick_cfg);
status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
cfg_value, override, c_dip);
}
/*
* these properties do not affect the actual classification outcome.
* used to enable/disable or tune the fflp hardware
*
* fcram_access_ratio, tcam_access_ratio, tcam_enable, llc_snap_enable
*
*/
override = B_FALSE;
for (class_prop = param_fcram_access_ratio;
class_prop <= param_llc_snap_enable; class_prop++) {
prop_name = param_arr[class_prop].fcode_name;
cfg_value = param_arr[class_prop].value;
status = nxge_cfg_verify_set_classify_prop(nxgep, prop_name,
cfg_value, override, c_dip);
}
return (status);
}
nxge_status_t
nxge_cfg_verify_set(p_nxge_t nxgep, uint32_t flag)
{
nxge_status_t status = NXGE_OK;
int i = 0, found = 0;
int num_siblings;
dev_info_t *c_dip[MAX_SIBLINGS + 1];
char *prop_val[MAX_SIBLINGS];
config_token_t c_token[MAX_SIBLINGS];
char *prop;
if (nxge_dma_obp_props_only)
return (NXGE_OK);
num_siblings = 0;
c_dip[num_siblings] = ddi_get_child(nxgep->p_dip);
while (c_dip[num_siblings]) {
c_dip[num_siblings + 1] =
ddi_get_next_sibling(c_dip[num_siblings]);
num_siblings++;
}
switch (flag) {
case COMMON_TXDMA_CFG:
prop = "txdma-cfg";
break;
case COMMON_RXDMA_CFG:
prop = "rxdma-cfg";
break;
case COMMON_RXDMA_GRP_CFG:
prop = "rxdma-grp-cfg";
break;
case COMMON_CLASS_CFG:
status = nxge_cfg_verify_set_classify(nxgep, c_dip);
return (status);
default:
return (NXGE_ERROR);
}
i = 0;
while (i < num_siblings) {
if (ddi_prop_lookup_string(DDI_DEV_T_ANY, c_dip[i], 0, prop,
(char **)&prop_val[i]) == DDI_PROP_SUCCESS) {
c_token[i] = nxge_get_config_token(prop_val[i]);
ddi_prop_free(prop_val[i]);
found++;
} else
c_token[i] = CONFIG_TOKEN_NONE;
i++;
}
if (found != i) {
if (found == 0) {
/* not specified: Use default */
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property %s not specified on any port:"
" Using default", prop));
status = nxge_update_cfg_properties(nxgep,
flag, FAIR, c_dip);
return (status);
} else {
/*
* if the convention is to use function 0 device then
* populate the other devices with this configuration.
*
* The other alternative is to use the default config.
*/
/* not specified: Use default */
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property %s not specified on some ports:"
" Using default", prop));
status = nxge_update_cfg_properties(nxgep,
flag, FAIR, c_dip);
return (status);
}
}
/* check type and consistence */
/* found on all devices */
for (i = 1; i < found; i++) {
if (c_token[i] != c_token[i - 1]) {
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" property %s inconsistent:"
" Using default", prop));
status = nxge_update_cfg_properties(nxgep,
flag, FAIR, c_dip);
return (status);
}
}
/*
* Found on all the ports check if it is custom configuration. if
* custom, then verify consistence
*
* finally create soft properties
*/
status = nxge_update_cfg_properties(nxgep, flag, c_token[0], c_dip);
return (status);
}
nxge_status_t
nxge_cfg_verify_set_quick_config(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
int ddi_status = DDI_SUCCESS;
char *prop_val;
char *rx_prop;
char *prop;
uint32_t cfg_value = CFG_NOT_SPECIFIED;
p_nxge_param_t param_arr;
param_arr = nxgep->param_arr;
rx_prop = param_arr[param_rx_quick_cfg].fcode_name;
prop = "rx-quick-cfg";
/*
* good value are
*
* "web-server" "generic-server" "l3-classify" "flow-classify"
*/
if (ddi_prop_lookup_string(DDI_DEV_T_ANY, nxgep->dip, 0,
prop, (char **)&prop_val) != DDI_PROP_SUCCESS) {
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
" property %s not specified: using default ", prop));
cfg_value = CFG_NOT_SPECIFIED;
} else {
cfg_value = CFG_L3_DISTRIBUTE;
if (strncmp("web-server", (caddr_t)prop_val, 8) == 0) {
cfg_value = CFG_L3_WEB;
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s: web server ", prop));
}
if (strncmp("generic-server", (caddr_t)prop_val, 8) == 0) {
cfg_value = CFG_L3_DISTRIBUTE;
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
" %s: distribute ", prop));
}
/* more */
ddi_prop_free(prop_val);
}
ddi_status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
rx_prop, cfg_value);
if (ddi_status != DDI_PROP_SUCCESS)
status |= NXGE_DDI_FAILED;
/* now handle specified cases: */
if (status & NXGE_DDI_FAILED)
status |= NXGE_ERROR;
return (status);
}
/*
* Device properties adv-autoneg-cap etc are defined by FWARC
* http://sac.sfbay/FWARC/2002/345/20020610_asif.haswarey
*/
static void
nxge_use_cfg_link_cfg(p_nxge_t nxgep)
{
int *prop_val;
uint_t prop_len;
dev_info_t *dip;
int speed;
int duplex;
int adv_autoneg_cap;
int adv_10gfdx_cap;
int adv_10ghdx_cap;
int adv_1000fdx_cap;
int adv_1000hdx_cap;
int adv_100fdx_cap;
int adv_100hdx_cap;
int adv_10fdx_cap;
int adv_10hdx_cap;
int status = DDI_SUCCESS;
dip = nxgep->dip;
/*
* first find out the card type and the supported link speeds and
* features
*/
/* add code for card type */
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-autoneg-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10gfdx-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000hdx-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-1000fdx-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100fdx-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-100hdx-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10fdx-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, "adv-10hdx-cap",
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
ddi_prop_free(prop_val);
return;
}
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "speed",
(uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if (strncmp("10000", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
speed = 10000;
} else if (strncmp("1000", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
speed = 1000;
} else if (strncmp("100", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
speed = 100;
} else if (strncmp("10", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
speed = 10;
} else if (strncmp("auto", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
speed = 0;
} else {
NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
"speed property is invalid reverting to auto"));
speed = 0;
}
ddi_prop_free(prop_val);
} else
speed = 0;
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, 0, "duplex",
(uchar_t **)&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if (strncmp("full", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
duplex = 2;
} else if (strncmp("half", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
duplex = 1;
} else if (strncmp("auto", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
duplex = 0;
} else {
NXGE_ERROR_MSG((nxgep, NXGE_NOTE,
"duplex property is invalid"
" reverting to auto"));
duplex = 0;
}
ddi_prop_free(prop_val);
} else
duplex = 0;
/* speed == 0 or duplex == 0 means auto negotiation. */
adv_autoneg_cap = (speed == 0) || (duplex == 0);
if (adv_autoneg_cap == 0) {
adv_10gfdx_cap = ((speed == 10000) && (duplex == 2));
adv_10ghdx_cap = adv_10gfdx_cap;
adv_10ghdx_cap |= ((speed == 10000) && (duplex == 1));
adv_1000fdx_cap = adv_10ghdx_cap;
adv_1000fdx_cap |= ((speed == 1000) && (duplex == 2));
adv_1000hdx_cap = adv_1000fdx_cap;
adv_1000hdx_cap |= ((speed == 1000) && (duplex == 1));
adv_100fdx_cap = adv_1000hdx_cap;
adv_100fdx_cap |= ((speed == 100) && (duplex == 2));
adv_100hdx_cap = adv_100fdx_cap;
adv_100hdx_cap |= ((speed == 100) && (duplex == 1));
adv_10fdx_cap = adv_100hdx_cap;
adv_10fdx_cap |= ((speed == 10) && (duplex == 2));
adv_10hdx_cap = adv_10fdx_cap;
adv_10hdx_cap |= ((speed == 10) && (duplex == 1));
} else if (speed == 0) {
adv_10gfdx_cap = (duplex == 2);
adv_10ghdx_cap = (duplex == 1);
adv_1000fdx_cap = (duplex == 2);
adv_1000hdx_cap = (duplex == 1);
adv_100fdx_cap = (duplex == 2);
adv_100hdx_cap = (duplex == 1);
adv_10fdx_cap = (duplex == 2);
adv_10hdx_cap = (duplex == 1);
}
if (duplex == 0) {
adv_10gfdx_cap = (speed == 0);
adv_10gfdx_cap |= (speed == 10000);
adv_10ghdx_cap = adv_10gfdx_cap;
adv_10ghdx_cap |= (speed == 10000);
adv_1000fdx_cap = adv_10ghdx_cap;
adv_1000fdx_cap |= (speed == 1000);
adv_1000hdx_cap = adv_1000fdx_cap;
adv_1000hdx_cap |= (speed == 1000);
adv_100fdx_cap = adv_1000hdx_cap;
adv_100fdx_cap |= (speed == 100);
adv_100hdx_cap = adv_100fdx_cap;
adv_100hdx_cap |= (speed == 100);
adv_10fdx_cap = adv_100hdx_cap;
adv_10fdx_cap |= (speed == 10);
adv_10hdx_cap = adv_10fdx_cap;
adv_10hdx_cap |= (speed == 10);
}
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-autoneg-cap", &adv_autoneg_cap, 1);
if (status)
return;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-10gfdx-cap", &adv_10gfdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail1;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-10ghdx-cap", &adv_10ghdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail2;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-1000fdx-cap", &adv_1000fdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail3;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-1000hdx-cap", &adv_1000hdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail4;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-100fdx-cap", &adv_100fdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail5;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-100hdx-cap", &adv_100hdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail6;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-10fdx-cap", &adv_10fdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail7;
status = ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
"adv-10hdx-cap", &adv_10hdx_cap, 1);
if (status)
goto nxge_map_myargs_to_gmii_fail8;
return;
nxge_map_myargs_to_gmii_fail9:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10hdx-cap");
nxge_map_myargs_to_gmii_fail8:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10fdx-cap");
nxge_map_myargs_to_gmii_fail7:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100hdx-cap");
nxge_map_myargs_to_gmii_fail6:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-100fdx-cap");
nxge_map_myargs_to_gmii_fail5:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000hdx-cap");
nxge_map_myargs_to_gmii_fail4:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-1000fdx-cap");
nxge_map_myargs_to_gmii_fail3:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10ghdx-cap");
nxge_map_myargs_to_gmii_fail2:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-10gfdx-cap");
nxge_map_myargs_to_gmii_fail1:
(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "adv-autoneg-cap");
}
nxge_status_t
nxge_get_config_properties(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
p_nxge_hw_list_t hw_p;
char **prop_val;
uint_t prop_len;
uint_t i;
NXGE_DEBUG_MSG((nxgep, VPD_CTL, " ==> nxge_get_config_properties"));
if ((hw_p = nxgep->nxge_hw_p) == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_get_config_properties:"
" common hardware not set", nxgep->niu_type));
return (NXGE_ERROR);
}
/*
* Get info on how many ports Neptune card has.
*/
nxgep->nports = nxge_get_nports(nxgep);
if (nxgep->nports <= 0) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<==nxge_get_config_properties: Invalid Neptune type 0x%x",
nxgep->niu_type));
return (NXGE_ERROR);
}
nxgep->classifier.tcam_size = TCAM_NIU_TCAM_MAX_ENTRY;
if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
nxgep->classifier.tcam_size = TCAM_NXGE_TCAM_MAX_ENTRY;
}
if (nxgep->function_num >= nxgep->nports) {
return (NXGE_ERROR);
}
status = nxge_get_mac_addr_properties(nxgep);
if (status != NXGE_OK)
return (NXGE_ERROR);
/*
* read the configuration type. If none is specified, used default.
* Config types: equal: (default) DMA channels, RDC groups, TCAM, FCRAM
* are shared equally across all the ports.
*
* Fair: DMA channels, RDC groups, TCAM, FCRAM are shared proportional
* to the port speed.
*
*
* custom: DMA channels, RDC groups, TCAM, FCRAM partition is
* specified in nxge.conf. Need to read each parameter and set
* up the parameters in nxge structures.
*
*/
switch (nxgep->niu_type) {
case N2_NIU:
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
" ==> nxge_get_config_properties: N2"));
MUTEX_ENTER(&hw_p->nxge_cfg_lock);
if ((hw_p->flags & COMMON_CFG_VALID) !=
COMMON_CFG_VALID) {
status = nxge_cfg_verify_set(nxgep,
COMMON_RXDMA_GRP_CFG);
status = nxge_cfg_verify_set(nxgep,
COMMON_CLASS_CFG);
hw_p->flags |= COMMON_CFG_VALID;
}
MUTEX_EXIT(&hw_p->nxge_cfg_lock);
status = nxge_use_cfg_n2niu_properties(nxgep);
break;
default:
if (!NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_get_config_properties:"
" unknown NIU type 0x%x", nxgep->niu_type));
return (NXGE_ERROR);
}
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
" ==> nxge_get_config_properties: Neptune"));
status = nxge_cfg_verify_set_quick_config(nxgep);
MUTEX_ENTER(&hw_p->nxge_cfg_lock);
if ((hw_p->flags & COMMON_CFG_VALID) !=
COMMON_CFG_VALID) {
status = nxge_cfg_verify_set(nxgep,
COMMON_TXDMA_CFG);
status = nxge_cfg_verify_set(nxgep,
COMMON_RXDMA_CFG);
status = nxge_cfg_verify_set(nxgep,
COMMON_RXDMA_GRP_CFG);
status = nxge_cfg_verify_set(nxgep,
COMMON_CLASS_CFG);
hw_p->flags |= COMMON_CFG_VALID;
}
MUTEX_EXIT(&hw_p->nxge_cfg_lock);
nxge_use_cfg_neptune_properties(nxgep);
status = NXGE_OK;
break;
}
/*
* Get the software LSO enable flag property from the
* driver configuration file (nxge.conf).
* This flag will be set to disable (0) if this property
* does not exist.
*/
nxgep->soft_lso_enable = ddi_prop_get_int(DDI_DEV_T_ANY, nxgep->dip,
DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "soft-lso-enable", 0);
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"nxge_get_config_properties: software lso %d\n",
nxgep->soft_lso_enable));
nxgep->niu_hw_type = NIU_HW_TYPE_DEFAULT;
if (nxgep->niu_type == N2_NIU) {
uchar_t *s_prop_val;
/*
* For NIU, the next generation KT has
* a few differences in features that the
* driver needs to handle them
* accordingly.
*/
if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"compatible", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
for (i = 0; i < prop_len; i++) {
if ((strcmp((caddr_t)prop_val[i],
KT_NIU_COMPATIBLE) == 0)) {
nxgep->niu_hw_type = NIU_HW_TYPE_RF;
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"NIU type %d", nxgep->niu_hw_type));
break;
}
}
}
ddi_prop_free(prop_val);
/*
* Some Serdes and PHY properties may also be provided as OBP
* properties
*/
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"tx-cfg-l", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
nxgep->srds_prop.tx_cfg_l =
(uint16_t)(*(uint32_t *)s_prop_val);
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"nxge_get_config_properties: "
"tx_cfg_l 0x%x, Read from OBP",
nxgep->srds_prop.tx_cfg_l));
nxgep->srds_prop.prop_set |= NXGE_SRDS_TXCFGL;
ddi_prop_free(s_prop_val);
}
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"tx-cfg-h", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
nxgep->srds_prop.tx_cfg_h =
(uint16_t)(*(uint32_t *)s_prop_val);
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"nxge_get_config_properties: "
"tx_cfg_h 0x%x, Read from OBP",
nxgep->srds_prop.tx_cfg_h));
nxgep->srds_prop.prop_set |= NXGE_SRDS_TXCFGH;
ddi_prop_free(s_prop_val);
}
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"rx-cfg-l", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
nxgep->srds_prop.rx_cfg_l =
(uint16_t)(*(uint32_t *)s_prop_val);
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"nxge_get_config_properties: "
"rx_cfg_l 0x%x, Read from OBP",
nxgep->srds_prop.rx_cfg_l));
nxgep->srds_prop.prop_set |= NXGE_SRDS_RXCFGL;
ddi_prop_free(s_prop_val);
}
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"rx-cfg-h", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
nxgep->srds_prop.rx_cfg_h =
(uint16_t)(*(uint32_t *)s_prop_val);
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"nxge_get_config_properties: "
"rx_cfg_h 0x%x, Read from OBP",
nxgep->srds_prop.rx_cfg_h));
nxgep->srds_prop.prop_set |= NXGE_SRDS_RXCFGH;
ddi_prop_free(s_prop_val);
}
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"pll-cfg", &s_prop_val, &prop_len) == DDI_PROP_SUCCESS) {
nxgep->srds_prop.pll_cfg_l =
(uint16_t)(*(uint32_t *)s_prop_val);
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"nxge_get_config_properties: "
"pll_cfg_l 0x%x, Read from OBP",
nxgep->srds_prop.pll_cfg_l));
nxgep->srds_prop.prop_set |= NXGE_SRDS_PLLCFGL;
ddi_prop_free(s_prop_val);
}
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"phy-reg-values", &s_prop_val, &prop_len) ==
DDI_PROP_SUCCESS) {
int tun_cnt, i;
uchar_t *arr = s_prop_val;
tun_cnt = prop_len / 6; /* 3 values, 2 bytes each */
nxgep->phy_prop.arr =
KMEM_ZALLOC(sizeof (nxge_phy_mdio_val_t) * tun_cnt,
KM_SLEEP);
nxgep->phy_prop.cnt = tun_cnt;
for (i = 0; i < tun_cnt; i++) {
nxgep->phy_prop.arr[i].dev = *(uint16_t *)arr;
arr += 2;
nxgep->phy_prop.arr[i].reg = *(uint16_t *)arr;
arr += 2;
nxgep->phy_prop.arr[i].val = *(uint16_t *)arr;
arr += 2;
NXGE_DEBUG_MSG((nxgep, VPD_CTL,
"nxge_get_config_properties: From OBP, "
"read PHY <dev.reg.val> = "
"<0x%x.0x%x.0x%x>",
nxgep->phy_prop.arr[i].dev,
nxgep->phy_prop.arr[i].reg,
nxgep->phy_prop.arr[i].val));
}
ddi_prop_free(s_prop_val);
}
}
NXGE_DEBUG_MSG((nxgep, VPD_CTL, " <== nxge_get_config_properties"));
return (status);
}
static nxge_status_t
nxge_use_cfg_n2niu_properties(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_n2niu_properties"));
status = nxge_use_default_dma_config_n2(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" ==> nxge_use_cfg_n2niu_properties (err 0x%x)",
status));
return (status | NXGE_ERROR);
}
(void) nxge_use_cfg_vlan_class_config(nxgep);
(void) nxge_use_cfg_mac_class_config(nxgep);
(void) nxge_use_cfg_class_config(nxgep);
(void) nxge_use_cfg_link_cfg(nxgep);
/*
* Read in the hardware (fcode) properties. Use the ndd array to read
* each property.
*/
(void) nxge_get_param_soft_properties(nxgep);
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_n2niu_properties"));
return (status);
}
static void
nxge_use_cfg_neptune_properties(p_nxge_t nxgep)
{
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_neptune_properties"));
(void) nxge_use_cfg_dma_config(nxgep);
(void) nxge_use_cfg_vlan_class_config(nxgep);
(void) nxge_use_cfg_mac_class_config(nxgep);
(void) nxge_use_cfg_class_config(nxgep);
(void) nxge_use_cfg_link_cfg(nxgep);
/*
* Read in the hardware (fcode) properties. Use the ndd array to read
* each property.
*/
(void) nxge_get_param_soft_properties(nxgep);
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_neptune_properties"));
}
/*
* FWARC 2006/556 for N2 NIU. Get the properties
* from the prom.
*/
static nxge_status_t
nxge_use_default_dma_config_n2(p_nxge_t nxgep)
{
int ndmas;
uint8_t func;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
int *prop_val;
uint_t prop_len;
int i;
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
func = nxgep->function_num;
p_cfgp->function_number = func;
ndmas = NXGE_TDMA_PER_NIU_PORT;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"tx-dma-channels", (int **)&prop_val,
&prop_len) == DDI_PROP_SUCCESS) {
if (prop_len != NXGE_NIU_TDMA_PROP_LEN) {
ddi_prop_free(prop_val);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_use_default_dma_config_n2: "
"invalid tx-dma-channels property for the NIU, "
"using defaults"));
/*
* Just failover to defaults
*/
p_cfgp->tdc.start = (func * NXGE_TDMA_PER_NIU_PORT);
ndmas = NXGE_TDMA_PER_NIU_PORT;
} else {
p_cfgp->tdc.start = prop_val[0];
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2: tdc starts %d "
"(#%d)", p_cfgp->tdc.start, prop_len));
ndmas = prop_val[1];
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2: #tdc %d (#%d)",
ndmas, prop_len));
ddi_prop_free(prop_val);
}
} else {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_use_default_dma_config_n2: "
"get tx-dma-channels failed"));
return (NXGE_DDI_FAILED);
}
p_cfgp->tdc.count = ndmas;
p_cfgp->tdc.owned = p_cfgp->tdc.count;
NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
"p_cfgp 0x%llx max_tdcs %d start %d",
p_cfgp, p_cfgp->tdc.count, p_cfgp->tdc.start));
/* Receive DMA */
ndmas = NXGE_RDMA_PER_NIU_PORT;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"rx-dma-channels", (int **)&prop_val,
&prop_len) == DDI_PROP_SUCCESS) {
if (prop_len != NXGE_NIU_RDMA_PROP_LEN) {
ddi_prop_free(prop_val);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_use_default_dma_config_n2: "
"invalid rx-dma-channels property for the NIU, "
"using defaults"));
/*
* Just failover to defaults
*/
p_cfgp->start_rdc = (func * NXGE_RDMA_PER_NIU_PORT);
ndmas = NXGE_RDMA_PER_NIU_PORT;
} else {
p_cfgp->start_rdc = prop_val[0];
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2(obp):"
" rdc start %d (#%d)",
p_cfgp->start_rdc, prop_len));
ndmas = prop_val[1];
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2(obp): "
"#rdc %d (#%d)", ndmas, prop_len));
ddi_prop_free(prop_val);
}
} else {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_use_default_dma_config_n2: "
"get rx-dma-channel failed"));
return (NXGE_DDI_FAILED);
}
p_cfgp->max_rdcs = ndmas;
nxgep->rdc_mask = (ndmas - 1);
/* Hypervisor: rdc # and group # use the same # !! */
p_cfgp->max_grpids = p_cfgp->max_rdcs + p_cfgp->tdc.owned;
p_cfgp->mif_ldvid = p_cfgp->mac_ldvid = p_cfgp->ser_ldvid = 0;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"interrupts", (int **)&prop_val,
&prop_len) == DDI_PROP_SUCCESS) {
if ((prop_len != NXGE_NIU_0_INTR_PROP_LEN) &&
(prop_len != NXGE_NIU_1_INTR_PROP_LEN)) {
ddi_prop_free(prop_val);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_use_default_dma_config_n2: "
"get interrupts failed"));
return (NXGE_DDI_FAILED);
}
/*
* For each device assigned, the content of each interrupts
* property is its logical device group.
*
* Assignment of interrupts property is in the the following
* order:
*
* MAC MIF (if configured) SYSTEM ERROR (if configured) first
* receive channel next channel...... last receive channel
* first transmit channel next channel...... last transmit
* channel
*
* prop_len should be at least for one mac and total # of rx and
* tx channels. Function 0 owns MIF and ERROR
*/
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2(obp): "
"# interrupts %d", prop_len));
switch (func) {
case 0:
p_cfgp->ldg_chn_start = 3;
p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT0;
p_cfgp->mif_ldvid = NXGE_MIF_LD;
p_cfgp->ser_ldvid = NXGE_SYS_ERROR_LD;
break;
case 1:
p_cfgp->ldg_chn_start = 1;
p_cfgp->mac_ldvid = NXGE_MAC_LD_PORT1;
break;
default:
status = NXGE_DDI_FAILED;
break;
}
if (status != NXGE_OK)
return (status);
for (i = 0; i < prop_len; i++) {
p_cfgp->ldg[i] = prop_val[i];
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2(obp): "
"F%d: interrupt #%d, ldg %d",
nxgep->function_num, i, p_cfgp->ldg[i]));
}
p_cfgp->max_grpids = prop_len;
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2(obp): %d "
"(#%d) maxgrpids %d channel starts %d",
p_cfgp->mac_ldvid, i, p_cfgp->max_grpids,
p_cfgp->ldg_chn_start));
ddi_prop_free(prop_val);
} else {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_use_default_dma_config_n2: "
"get interrupts failed"));
return (NXGE_DDI_FAILED);
}
p_cfgp->max_ldgs = p_cfgp->max_grpids;
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"==> nxge_use_default_dma_config_n2: p_cfgp 0x%llx max_rdcs %d "
"max_grpids %d macid %d mifid %d serrid %d",
p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
p_cfgp->mac_ldvid, p_cfgp->mif_ldvid, p_cfgp->ser_ldvid));
NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
"p_cfgp p%p start_ldg %d nxgep->max_ldgs %d",
p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs));
/*
* RDC groups and the beginning RDC group assigned to this function.
*/
p_cfgp->max_rdc_grpids = NXGE_MAX_RDC_GROUPS / nxgep->nports;
p_cfgp->def_mac_rxdma_grpid =
nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
p_cfgp->def_mac_txdma_grpid =
nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
NXGE_ERROR_MSG((nxgep, CFG_CTL,
"nxge_use_default_dma_config_n2(): "
"nxge_fzc_rdc_tbl_bind failed"));
return (NXGE_DDI_FAILED);
}
status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
"rx-rdc-grps", p_cfgp->max_rdc_grpids);
if (status) {
return (NXGE_DDI_FAILED);
}
status = ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
"rx-rdc-grps-begin", p_cfgp->def_mac_rxdma_grpid);
if (status) {
(void) ddi_prop_remove(DDI_DEV_T_NONE, nxgep->dip,
"rx-rdc-grps");
return (NXGE_DDI_FAILED);
}
NXGE_DEBUG_MSG((nxgep, OBP_CTL, "==> nxge_use_default_dma_config_n2: "
"p_cfgp $%p # rdc groups %d start rdc group id %d",
p_cfgp, p_cfgp->max_rdc_grpids,
p_cfgp->def_mac_rxdma_grpid));
nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"rxdma-intr-time", (int **)&prop_val, &prop_len) ==
DDI_PROP_SUCCESS) {
if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
nxgep->intr_timeout = prop_val[0];
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, "rxdma-intr-time", prop_val, prop_len);
}
ddi_prop_free(prop_val);
}
nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"rxdma-intr-pkts", (int **)&prop_val, &prop_len) ==
DDI_PROP_SUCCESS) {
if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
nxgep->intr_threshold = prop_val[0];
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, "rxdma-intr-pkts", prop_val, prop_len);
}
ddi_prop_free(prop_val);
}
nxge_set_hw_dma_config(nxgep);
NXGE_DEBUG_MSG((nxgep, OBP_CTL, "<== nxge_use_default_dma_config_n2"));
return (status);
}
static void
nxge_use_cfg_dma_config(p_nxge_t nxgep)
{
int tx_ndmas, rx_ndmas, nrxgp, st_txdma, st_rxdma;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
dev_info_t *dip;
p_nxge_param_t param_arr;
char *prop;
int *prop_val;
uint_t prop_len;
int i;
uint8_t *ch_arr_p;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_dma_config"));
param_arr = nxgep->param_arr;
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
dip = nxgep->dip;
p_cfgp->function_number = nxgep->function_num;
prop = param_arr[param_txdma_channels_begin].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
p_cfgp->tdc.start = *prop_val;
ddi_prop_free(prop_val);
} else {
switch (nxgep->niu_type) {
case NEPTUNE_4_1GC:
ch_arr_p = &tx_4_1G[0];
break;
case NEPTUNE_2_10GF:
ch_arr_p = &tx_2_10G[0];
break;
case NEPTUNE_2_10GF_2_1GC:
case NEPTUNE_2_10GF_2_1GRF:
ch_arr_p = &tx_2_10G_2_1G[0];
break;
case NEPTUNE_1_10GF_3_1GC:
ch_arr_p = &tx_1_10G_3_1G[0];
break;
case NEPTUNE_1_1GC_1_10GF_2_1GC:
ch_arr_p = &tx_1_1G_1_10G_2_1G[0];
break;
default:
switch (nxgep->platform_type) {
case P_NEPTUNE_ALONSO:
ch_arr_p = &tx_2_10G_2_1G[0];
break;
default:
ch_arr_p = &p4_tx_equal[0];
break;
}
break;
}
st_txdma = 0;
for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
st_txdma += *ch_arr_p;
(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
prop, st_txdma);
p_cfgp->tdc.start = st_txdma;
}
prop = param_arr[param_txdma_channels].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
tx_ndmas = *prop_val;
ddi_prop_free(prop_val);
} else {
switch (nxgep->niu_type) {
case NEPTUNE_4_1GC:
tx_ndmas = tx_4_1G[nxgep->function_num];
break;
case NEPTUNE_2_10GF:
tx_ndmas = tx_2_10G[nxgep->function_num];
break;
case NEPTUNE_2_10GF_2_1GC:
case NEPTUNE_2_10GF_2_1GRF:
tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
break;
case NEPTUNE_1_10GF_3_1GC:
tx_ndmas = tx_1_10G_3_1G[nxgep->function_num];
break;
case NEPTUNE_1_1GC_1_10GF_2_1GC:
tx_ndmas = tx_1_1G_1_10G_2_1G[nxgep->function_num];
break;
default:
switch (nxgep->platform_type) {
case P_NEPTUNE_ALONSO:
tx_ndmas = tx_2_10G_2_1G[nxgep->function_num];
break;
default:
tx_ndmas = p4_tx_equal[nxgep->function_num];
break;
}
break;
}
(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
prop, tx_ndmas);
}
p_cfgp->tdc.count = tx_ndmas;
p_cfgp->tdc.owned = p_cfgp->tdc.count;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
"p_cfgp 0x%llx max_tdcs %d", p_cfgp, p_cfgp->tdc.count));
prop = param_arr[param_rxdma_channels_begin].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
p_cfgp->start_rdc = *prop_val;
ddi_prop_free(prop_val);
} else {
switch (nxgep->niu_type) {
case NEPTUNE_4_1GC:
ch_arr_p = &rx_4_1G[0];
break;
case NEPTUNE_2_10GF:
ch_arr_p = &rx_2_10G[0];
break;
case NEPTUNE_2_10GF_2_1GC:
case NEPTUNE_2_10GF_2_1GRF:
ch_arr_p = &rx_2_10G_2_1G[0];
break;
case NEPTUNE_1_10GF_3_1GC:
ch_arr_p = &rx_1_10G_3_1G[0];
break;
case NEPTUNE_1_1GC_1_10GF_2_1GC:
ch_arr_p = &rx_1_1G_1_10G_2_1G[0];
break;
default:
switch (nxgep->platform_type) {
case P_NEPTUNE_ALONSO:
ch_arr_p = &rx_2_10G_2_1G[0];
break;
default:
ch_arr_p = &p4_rx_equal[0];
break;
}
break;
}
st_rxdma = 0;
for (i = 0; i < nxgep->function_num; i++, ch_arr_p++)
st_rxdma += *ch_arr_p;
(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
prop, st_rxdma);
p_cfgp->start_rdc = st_rxdma;
}
prop = param_arr[param_rxdma_channels].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
rx_ndmas = *prop_val;
ddi_prop_free(prop_val);
} else {
switch (nxgep->niu_type) {
case NEPTUNE_4_1GC:
rx_ndmas = rx_4_1G[nxgep->function_num];
break;
case NEPTUNE_2_10GF:
rx_ndmas = rx_2_10G[nxgep->function_num];
break;
case NEPTUNE_2_10GF_2_1GC:
case NEPTUNE_2_10GF_2_1GRF:
rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
break;
case NEPTUNE_1_10GF_3_1GC:
rx_ndmas = rx_1_10G_3_1G[nxgep->function_num];
break;
case NEPTUNE_1_1GC_1_10GF_2_1GC:
rx_ndmas = rx_1_1G_1_10G_2_1G[nxgep->function_num];
break;
default:
switch (nxgep->platform_type) {
case P_NEPTUNE_ALONSO:
rx_ndmas = rx_2_10G_2_1G[nxgep->function_num];
break;
default:
rx_ndmas = p4_rx_equal[nxgep->function_num];
break;
}
break;
}
(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
prop, rx_ndmas);
}
p_cfgp->max_rdcs = rx_ndmas;
/*
* RDC groups and the beginning RDC group assigned to this function.
* XXX: this may be wrong if prop value is used.
*/
p_cfgp->def_mac_rxdma_grpid =
nxgep->function_num * NXGE_MAX_RDC_GROUPS / nxgep->nports;
p_cfgp->def_mac_txdma_grpid =
nxgep->function_num * NXGE_MAX_TDC_GROUPS / nxgep->nports;
if ((p_cfgp->def_mac_rxdma_grpid = nxge_fzc_rdc_tbl_bind(nxgep,
p_cfgp->def_mac_rxdma_grpid, B_TRUE)) >= NXGE_MAX_RDC_GRPS) {
NXGE_ERROR_MSG((nxgep, CFG_CTL,
"nxge_use_default_dma_config2(): "
"nxge_fzc_rdc_tbl_bind failed"));
goto nxge_use_cfg_dma_config_exit;
}
prop = param_arr[param_rx_rdc_grps].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
nrxgp = *prop_val;
ddi_prop_free(prop_val);
} else {
nrxgp = NXGE_MAX_RDC_GRPS / nxgep->nports;
(void) ddi_prop_update_int(DDI_DEV_T_NONE, nxgep->dip,
prop, nrxgp);
NXGE_DEBUG_MSG((nxgep, CFG_CTL,
"==> nxge_use_default_dma_config: "
"num_rdc_grpid not found: use def:# of "
"rdc groups %d\n", nrxgp));
}
p_cfgp->max_rdc_grpids = nrxgp;
/*
* 2/4 ports have the same hard-wired logical groups assigned.
*/
p_cfgp->start_ldg = nxgep->function_num * NXGE_LDGRP_PER_4PORTS;
p_cfgp->max_ldgs = NXGE_LDGRP_PER_4PORTS;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_default_dma_config: "
"p_cfgp 0x%llx max_rdcs %d max_grpids %d default_grpid %d",
p_cfgp, p_cfgp->max_rdcs, p_cfgp->max_grpids,
p_cfgp->def_mac_rxdma_grpid));
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_dma_config: "
"p_cfgp 0x%016llx start_ldg %d nxgep->max_ldgs %d "
"def_mac_rxdma_grpid %d",
p_cfgp, p_cfgp->start_ldg, p_cfgp->max_ldgs,
p_cfgp->def_mac_rxdma_grpid));
nxgep->intr_timeout = NXGE_RDC_RCR_TIMEOUT;
prop = param_arr[param_rxdma_intr_time].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
nxgep->intr_timeout = prop_val[0];
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, prop, prop_val, prop_len);
}
ddi_prop_free(prop_val);
}
nxgep->intr_threshold = NXGE_RDC_RCR_THRESHOLD;
prop = param_arr[param_rxdma_intr_pkts].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 0, prop,
&prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if ((prop_len > 0) && (prop_len <= p_cfgp->max_rdcs)) {
nxgep->intr_threshold = prop_val[0];
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, prop, prop_val, prop_len);
}
ddi_prop_free(prop_val);
}
nxge_set_hw_dma_config(nxgep);
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config: "
"sTDC[%d] nTDC[%d] sRDC[%d] nRDC[%d]",
p_cfgp->tdc.start, p_cfgp->tdc.count,
p_cfgp->start_rdc, p_cfgp->max_rdcs));
nxge_use_cfg_dma_config_exit:
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_use_cfg_dma_config"));
}
void
nxge_get_logical_props(p_nxge_t nxgep)
{
nxge_dma_pt_cfg_t *port = &nxgep->pt_config;
nxge_hw_pt_cfg_t *hardware;
nxge_rdc_grp_t *group;
(void) memset(port, 0, sizeof (*port));
port->mac_port = nxgep->function_num; /* := function number */
/*
* alloc_buf_size:
* dead variables.
*/
port->rbr_size = nxge_rbr_size;
port->rcr_size = nxge_rcr_size;
port->tx_dma_map = 0; /* Transmit DMA channel bit map */
nxge_set_rdc_intr_property(nxgep);
port->rcr_full_header = NXGE_RCR_FULL_HEADER;
port->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
/* ----------------------------------------------------- */
hardware = &port->hw_config;
(void) memset(hardware, 0, sizeof (*hardware));
/*
* partition_id, read_write_mode:
* dead variables.
*/
/*
* drr_wt, rx_full_header, *_ldg?, start_mac_entry,
* mac_pref, def_mac_rxdma_grpid, start_vlan, max_vlans,
* start_ldgs, max_ldgs, max_ldvs,
* vlan_pref, def_vlan_rxdma_grpid are meaningful only
* in the service domain.
*/
group = &port->rdc_grps[0];
group->flag = B_TRUE; /* configured */
group->config_method = RDC_TABLE_ENTRY_METHOD_REP;
group->port = NXGE_GET_PORT_NUM(nxgep->function_num);
/* HIO futures: this is still an open question. */
hardware->max_macs = 1;
}
static void
nxge_use_cfg_vlan_class_config(p_nxge_t nxgep)
{
uint_t vlan_cnt;
int *vlan_cfg_val;
int status;
p_nxge_param_t param_arr;
char *prop;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_use_cfg_vlan_config"));
param_arr = nxgep->param_arr;
prop = param_arr[param_vlan_2rdc_grp].fcode_name;
status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
&vlan_cfg_val, &vlan_cnt);
if (status == DDI_PROP_SUCCESS) {
status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, prop, vlan_cfg_val, vlan_cnt);
ddi_prop_free(vlan_cfg_val);
}
nxge_set_hw_vlan_class_config(nxgep);
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_vlan_config"));
}
static void
nxge_use_cfg_mac_class_config(p_nxge_t nxgep)
{
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
uint_t mac_cnt;
int *mac_cfg_val;
int status;
p_nxge_param_t param_arr;
char *prop;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_use_cfg_mac_class_config"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
p_cfgp->start_mac_entry = 0;
param_arr = nxgep->param_arr;
prop = param_arr[param_mac_2rdc_grp].fcode_name;
switch (nxgep->function_num) {
case 0:
case 1:
/* 10G ports */
p_cfgp->max_macs = NXGE_MAX_MACS_XMACS;
break;
case 2:
case 3:
/* 1G ports */
default:
p_cfgp->max_macs = NXGE_MAX_MACS_BMACS;
break;
}
p_cfgp->mac_pref = 1;
NXGE_DEBUG_MSG((nxgep, OBP_CTL,
"== nxge_use_cfg_mac_class_config: "
" mac_pref bit set def_mac_rxdma_grpid %d",
p_cfgp->def_mac_rxdma_grpid));
status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
&mac_cfg_val, &mac_cnt);
if (status == DDI_PROP_SUCCESS) {
if (mac_cnt <= p_cfgp->max_macs)
status = ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, prop, mac_cfg_val, mac_cnt);
ddi_prop_free(mac_cfg_val);
}
nxge_set_hw_mac_class_config(nxgep);
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_use_cfg_mac_class_config"));
}
static void
nxge_use_cfg_class_config(p_nxge_t nxgep)
{
nxge_set_hw_class_config(nxgep);
}
static void
nxge_set_rdc_intr_property(p_nxge_t nxgep)
{
int i;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_rdc_intr_property"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
for (i = 0; i < NXGE_MAX_RDCS; i++) {
p_dma_cfgp->rcr_timeout[i] = nxgep->intr_timeout;
p_dma_cfgp->rcr_threshold[i] = nxgep->intr_threshold;
}
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_rdc_intr_property"));
}
static void
nxge_set_hw_dma_config(p_nxge_t nxgep)
{
int i, j, ngrps, bitmap, end, st_rdc;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
p_nxge_rdc_grp_t rdc_grp_p;
p_nxge_tdc_grp_t tdc_grp_p;
nxge_grp_t *group;
uint8_t nrdcs;
dc_map_t map = 0;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_dma_config"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
switch (nxgep->niu_type) {
case NEPTUNE_4_1GC:
case NEPTUNE_2_10GF_2_1GC:
case NEPTUNE_1_10GF_3_1GC:
case NEPTUNE_1_1GC_1_10GF_2_1GC:
case NEPTUNE_2_10GF_2_1GRF:
default:
ngrps = 2;
break;
case NEPTUNE_2_10GF:
case NEPTUNE_2_1GRF:
case N2_NIU:
ngrps = 4;
break;
}
/*
* Setup TDC groups
*/
bitmap = 0;
end = p_cfgp->tdc.start + p_cfgp->tdc.owned;
for (i = p_cfgp->tdc.start; i < end; i++) {
bitmap |= (1 << i);
}
nxgep->tx_set.owned.map |= bitmap; /* Owned, & not shared. */
nxgep->tx_set.owned.count = p_cfgp->tdc.owned;
p_dma_cfgp->tx_dma_map = bitmap;
for (i = 0; i < ngrps; i++) {
group = (nxge_grp_t *)nxge_grp_add(nxgep,
NXGE_TRANSMIT_GROUP);
tdc_grp_p = &p_dma_cfgp->tdc_grps[
p_cfgp->def_mac_txdma_grpid + i];
if (i == 0)
tdc_grp_p->map = bitmap;
else
tdc_grp_p->map = 0;
/* no ring is associated with a group initially */
tdc_grp_p->start_tdc = 0;
tdc_grp_p->max_tdcs = 0;
tdc_grp_p->grp_index = group->index;
}
/*
* Setup RDC groups
*/
st_rdc = p_cfgp->start_rdc;
for (i = 0; i < ngrps; i++) {
/*
* All rings are associated with the default group initially
*/
if (i == 0) {
/* default group */
switch (nxgep->niu_type) {
case NEPTUNE_4_1GC:
nrdcs = rx_4_1G[nxgep->function_num];
break;
case N2_NIU:
case NEPTUNE_2_10GF:
nrdcs = rx_2_10G[nxgep->function_num];
break;
case NEPTUNE_2_10GF_2_1GC:
nrdcs = rx_2_10G_2_1G[nxgep->function_num];
break;
case NEPTUNE_1_10GF_3_1GC:
nrdcs = rx_1_10G_3_1G[nxgep->function_num];
break;
case NEPTUNE_1_1GC_1_10GF_2_1GC:
nrdcs = rx_1_1G_1_10G_2_1G[nxgep->function_num];
break;
default:
switch (nxgep->platform_type) {
case P_NEPTUNE_ALONSO:
nrdcs =
rx_2_10G_2_1G[nxgep->function_num];
break;
default:
nrdcs = rx_4_1G[nxgep->function_num];
break;
}
break;
}
if (p_cfgp->max_rdcs < nrdcs)
nrdcs = p_cfgp->max_rdcs;
} else {
nrdcs = 0;
}
rdc_grp_p = &p_dma_cfgp->rdc_grps[
p_cfgp->def_mac_rxdma_grpid + i];
rdc_grp_p->start_rdc = st_rdc;
rdc_grp_p->max_rdcs = nrdcs;
rdc_grp_p->def_rdc = rdc_grp_p->start_rdc;
/* default to: 0, 1, 2, 3, ...., 0, 1, 2, 3.... */
if (nrdcs != 0) {
for (j = 0; j < nrdcs; j++) {
map |= (1 << j);
}
map <<= rdc_grp_p->start_rdc;
} else
map = 0;
rdc_grp_p->map = map;
nxgep->rx_set.owned.map |= map; /* Owned, & not shared. */
nxgep->rx_set.owned.count = nrdcs;
group = (nxge_grp_t *)nxge_grp_add(nxgep, NXGE_RECEIVE_GROUP);
rdc_grp_p->config_method = RDC_TABLE_ENTRY_METHOD_SEQ;
rdc_grp_p->flag = B_TRUE; /* This group has been configured. */
rdc_grp_p->grp_index = group->index;
rdc_grp_p->port = NXGE_GET_PORT_NUM(nxgep->function_num);
map = 0;
}
/* default RDC */
p_cfgp->def_rdc = p_cfgp->start_rdc;
nxgep->def_rdc = p_cfgp->start_rdc;
/* full 18 byte header ? */
p_dma_cfgp->rcr_full_header = NXGE_RCR_FULL_HEADER;
p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_10G;
if (nxgep->function_num > 1)
p_dma_cfgp->rx_drr_weight = PT_DRR_WT_DEFAULT_1G;
p_dma_cfgp->rbr_size = nxge_rbr_size;
p_dma_cfgp->rcr_size = nxge_rcr_size;
nxge_set_rdc_intr_property(nxgep);
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_dma_config"));
}
boolean_t
nxge_check_rxdma_port_member(p_nxge_t nxgep, uint8_t rdc)
{
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
int status = B_TRUE;
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rxdma_port_member"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
/* Receive DMA Channels */
if (rdc < p_cfgp->max_rdcs)
status = B_TRUE;
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rxdma_port_member"));
return (status);
}
boolean_t
nxge_check_txdma_port_member(p_nxge_t nxgep, uint8_t tdc)
{
int status = B_FALSE;
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_txdma_port_member"));
if (tdc >= nxgep->pt_config.hw_config.tdc.start &&
tdc < nxgep->pt_config.hw_config.tdc.count)
status = B_TRUE;
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_txdma_port_member"));
return (status);
}
boolean_t
nxge_check_rxdma_rdcgrp_member(p_nxge_t nxgep, uint8_t rdc_grp, uint8_t rdc)
{
p_nxge_dma_pt_cfg_t p_dma_cfgp;
int status = B_TRUE;
p_nxge_rdc_grp_t rdc_grp_p;
NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
" ==> nxge_check_rxdma_rdcgrp_member"));
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " nxge_check_rxdma_rdcgrp_member"
" rdc %d group %d", rdc, rdc_grp));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
rdc_grp_p = &p_dma_cfgp->rdc_grps[rdc_grp];
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " max %d ", rdc_grp_p->max_rdcs));
if (rdc >= rdc_grp_p->max_rdcs) {
status = B_FALSE;
}
NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
" <== nxge_check_rxdma_rdcgrp_member"));
return (status);
}
boolean_t
nxge_check_rdcgrp_port_member(p_nxge_t nxgep, uint8_t rdc_grp)
{
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
int status = B_TRUE;
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, "==> nxge_check_rdcgrp_port_member"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
if (rdc_grp >= p_cfgp->max_rdc_grpids)
status = B_FALSE;
NXGE_DEBUG_MSG((nxgep, CFG2_CTL, " <== nxge_check_rdcgrp_port_member"));
return (status);
}
static void
nxge_set_hw_vlan_class_config(p_nxge_t nxgep)
{
int i;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
p_nxge_param_t param_arr;
uint_t vlan_cnt;
int *vlan_cfg_val;
nxge_param_map_t *vmap;
char *prop;
p_nxge_class_pt_cfg_t p_class_cfgp;
uint32_t good_cfg[32];
int good_count = 0;
nxge_mv_cfg_t *vlan_tbl;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_vlan_config"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
param_arr = nxgep->param_arr;
prop = param_arr[param_vlan_2rdc_grp].fcode_name;
/*
* By default, VLAN to RDC group mapping is disabled Need to read HW or
* .conf properties to find out if mapping is required
*
* Format
*
* uint32_t array, each array entry specifying the VLAN id and the
* mapping
*
* bit[30] = add bit[29] = remove bit[28] = preference bits[23-16] =
* rdcgrp bits[15-0] = VLAN ID ( )
*/
for (i = 0; i < NXGE_MAX_VLANS; i++) {
p_class_cfgp->vlan_tbl[i].flag = 0;
}
vlan_tbl = (nxge_mv_cfg_t *)&p_class_cfgp->vlan_tbl[0];
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
&vlan_cfg_val, &vlan_cnt) == DDI_PROP_SUCCESS) {
for (i = 0; i < vlan_cnt; i++) {
vmap = (nxge_param_map_t *)&vlan_cfg_val[i];
if ((vmap->param_id) &&
(vmap->param_id < NXGE_MAX_VLANS) &&
(vmap->map_to <
p_cfgp->max_rdc_grpids) &&
(vmap->map_to >= (uint8_t)0)) {
NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
" nxge_vlan_config mapping"
" id %d grp %d",
vmap->param_id, vmap->map_to));
good_cfg[good_count] = vlan_cfg_val[i];
if (vlan_tbl[vmap->param_id].flag == 0)
good_count++;
vlan_tbl[vmap->param_id].flag = 1;
vlan_tbl[vmap->param_id].rdctbl =
vmap->map_to + p_cfgp->def_mac_rxdma_grpid;
vlan_tbl[vmap->param_id].mpr_npr = vmap->pref;
}
}
ddi_prop_free(vlan_cfg_val);
if (good_count != vlan_cnt) {
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, prop, (int *)good_cfg, good_count);
}
}
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_vlan_config"));
}
static void
nxge_set_hw_mac_class_config(p_nxge_t nxgep)
{
int i;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
p_nxge_param_t param_arr;
uint_t mac_cnt;
int *mac_cfg_val;
nxge_param_map_t *mac_map;
char *prop;
p_nxge_class_pt_cfg_t p_class_cfgp;
int good_count = 0;
int good_cfg[NXGE_MAX_MACS];
nxge_mv_cfg_t *mac_host_info;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_set_hw_mac_config"));
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
mac_host_info = (nxge_mv_cfg_t *)&p_class_cfgp->mac_host_info[0];
param_arr = nxgep->param_arr;
prop = param_arr[param_mac_2rdc_grp].fcode_name;
for (i = 0; i < NXGE_MAX_MACS; i++) {
p_class_cfgp->mac_host_info[i].flag = 0;
p_class_cfgp->mac_host_info[i].rdctbl =
p_cfgp->def_mac_rxdma_grpid;
}
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
&mac_cfg_val, &mac_cnt) == DDI_PROP_SUCCESS) {
for (i = 0; i < mac_cnt; i++) {
mac_map = (nxge_param_map_t *)&mac_cfg_val[i];
if ((mac_map->param_id < p_cfgp->max_macs) &&
(mac_map->map_to <
p_cfgp->max_rdc_grpids) &&
(mac_map->map_to >= (uint8_t)0)) {
NXGE_DEBUG_MSG((nxgep, CFG2_CTL,
" nxge_mac_config mapping"
" id %d grp %d",
mac_map->param_id, mac_map->map_to));
mac_host_info[mac_map->param_id].mpr_npr =
p_cfgp->mac_pref;
mac_host_info[mac_map->param_id].rdctbl =
mac_map->map_to +
p_cfgp->def_mac_rxdma_grpid;
good_cfg[good_count] = mac_cfg_val[i];
if (mac_host_info[mac_map->param_id].flag == 0)
good_count++;
mac_host_info[mac_map->param_id].flag = 1;
}
}
ddi_prop_free(mac_cfg_val);
if (good_count != mac_cnt) {
(void) ddi_prop_update_int_array(DDI_DEV_T_NONE,
nxgep->dip, prop, good_cfg, good_count);
}
}
NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_set_hw_mac_config"));
}
static void
nxge_set_hw_class_config(p_nxge_t nxgep)
{
int i;
p_nxge_param_t param_arr;
int *int_prop_val;
uint32_t cfg_value;
char *prop;
p_nxge_class_pt_cfg_t p_class_cfgp;
int start_prop, end_prop;
uint_t prop_cnt;
int start_class, j = 0;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " ==> nxge_set_hw_class_config"));
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
param_arr = nxgep->param_arr;
start_prop = param_class_opt_ipv4_tcp;
end_prop = param_class_opt_ipv6_sctp;
start_class = TCAM_CLASS_TCP_IPV4;
for (i = start_prop, j = 0; i <= end_prop; i++, j++) {
prop = param_arr[i].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip,
0, prop, &int_prop_val,
&prop_cnt) == DDI_PROP_SUCCESS) {
cfg_value = (uint32_t)*int_prop_val;
ddi_prop_free(int_prop_val);
} else {
cfg_value = (uint32_t)param_arr[i].value;
}
p_class_cfgp->class_cfg[start_class + j] = cfg_value;
}
prop = param_arr[param_h1_init_value].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
&int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
cfg_value = (uint32_t)*int_prop_val;
ddi_prop_free(int_prop_val);
} else {
cfg_value = (uint32_t)param_arr[param_h1_init_value].value;
}
p_class_cfgp->init_h1 = (uint32_t)cfg_value;
prop = param_arr[param_h2_init_value].fcode_name;
if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, nxgep->dip, 0, prop,
&int_prop_val, &prop_cnt) == DDI_PROP_SUCCESS) {
cfg_value = (uint32_t)*int_prop_val;
ddi_prop_free(int_prop_val);
} else {
cfg_value = (uint32_t)param_arr[param_h2_init_value].value;
}
p_class_cfgp->init_h2 = (uint16_t)cfg_value;
NXGE_DEBUG_MSG((nxgep, CFG_CTL, " <== nxge_set_hw_class_config"));
}
nxge_status_t
nxge_ldgv_init_n2(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
{
int i, maxldvs, maxldgs, nldvs;
int ldv, endldg;
uint8_t func;
uint8_t channel;
uint8_t chn_start;
boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
p_nxge_ldgv_t ldgvp;
p_nxge_ldg_t ldgp, ptr;
p_nxge_ldv_t ldvp, sysldvp;
nxge_status_t status = NXGE_OK;
nxge_grp_set_t *set;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2"));
if (!*navail_p) {
*nrequired_p = 0;
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_ldgv_init:no avail"));
return (NXGE_ERROR);
}
/*
* N2/NIU: one logical device owns one logical group. and each
* device/group will be assigned one vector by Hypervisor.
*/
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
maxldgs = p_cfgp->max_ldgs;
if (!maxldgs) {
/* No devices configured. */
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init_n2: "
"no logical groups configured."));
return (NXGE_ERROR);
} else {
maxldvs = maxldgs + 1;
}
/*
* If function zero instance, it needs to handle the system and MIF
* error interrupts. MIF interrupt may not be needed for N2/NIU.
*/
func = nxgep->function_num;
if (func == 0) {
own_sys_err = B_TRUE;
if (!p_cfgp->ser_ldvid) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_ldgv_init_n2: func 0, ERR ID not set!"));
}
/* MIF interrupt */
if (!p_cfgp->mif_ldvid) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_ldgv_init_n2: func 0, MIF ID not set!"));
}
}
/*
* Assume single partition, each function owns mac.
*/
if (!nxge_use_partition)
own_fzc = B_TRUE;
ldgvp = nxgep->ldgvp;
if (ldgvp == NULL) {
ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
nxgep->ldgvp = ldgvp;
ldgvp->maxldgs = (uint8_t)maxldgs;
ldgvp->maxldvs = (uint8_t)maxldvs;
ldgp = ldgvp->ldgp = KMEM_ZALLOC(
sizeof (nxge_ldg_t) * maxldgs, KM_SLEEP);
ldvp = ldgvp->ldvp = KMEM_ZALLOC(
sizeof (nxge_ldv_t) * maxldvs, KM_SLEEP);
} else {
ldgp = ldgvp->ldgp;
ldvp = ldgvp->ldvp;
}
ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
ldgvp->tmres = NXGE_TIMER_RESO;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d",
maxldvs, maxldgs));
/* logical start_ldg is ldv */
ptr = ldgp;
for (i = 0; i < maxldgs; i++) {
ptr->func = func;
ptr->arm = B_TRUE;
ptr->vldg_index = (uint8_t)i;
ptr->ldg_timer = NXGE_TIMER_LDG;
ptr->ldg = p_cfgp->ldg[i];
ptr->sys_intr_handler = nxge_intr;
ptr->nldvs = 0;
ptr->ldvp = NULL;
ptr->nxgep = nxgep;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init_n2: maxldvs %d maxldgs %d "
"ldg %d ldgptr $%p",
maxldvs, maxldgs, ptr->ldg, ptr));
ptr++;
}
endldg = NXGE_INT_MAX_LDG;
nldvs = 0;
ldgvp->nldvs = 0;
ldgp->ldvp = NULL;
*nrequired_p = 0;
/*
* logical device group table is organized in the following order (same
* as what interrupt property has). function 0: owns MAC, MIF, error,
* rx, tx. function 1: owns MAC, rx, tx.
*/
if (own_fzc && p_cfgp->mac_ldvid) {
/* Each function should own MAC interrupt */
ldv = p_cfgp->mac_ldvid;
ldvp->ldv = (uint8_t)ldv;
ldvp->is_mac = B_TRUE;
ldvp->ldv_intr_handler = nxge_mac_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->nxgep = nxgep;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init_n2(mac): maxldvs %d ldv %d "
"ldg %d ldgptr $%p ldvptr $%p",
maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
}
if (own_fzc && p_cfgp->mif_ldvid) {
ldv = p_cfgp->mif_ldvid;
ldvp->ldv = (uint8_t)ldv;
ldvp->is_mif = B_TRUE;
ldvp->ldv_intr_handler = nxge_mif_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->nxgep = nxgep;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init_n2(mif): maxldvs %d ldv %d "
"ldg %d ldgptr $%p ldvptr $%p",
maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
}
/*
* HW based syserr interrupt for port0, and SW based syserr interrupt
* for port1
*/
if (own_sys_err && p_cfgp->ser_ldvid) {
ldv = p_cfgp->ser_ldvid;
/*
* Unmask the system interrupt states.
*/
(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
SYS_ERR_ZCP_MASK);
ldvp->use_timer = B_TRUE;
ldvp->ldv = (uint8_t)ldv;
ldvp->is_syserr = B_TRUE;
ldvp->ldv_intr_handler = nxge_syserr_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->nxgep = nxgep;
ldgvp->ldvp_syserr = ldvp;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init_n2(syserr): maxldvs %d ldv %d "
"ldg %d ldgptr $%p ldvptr p%p",
maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
} else {
/*
* SW based: allocate the ldv for the syserr since the vector
* should not be consumed for port1
*/
sysldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t), KM_SLEEP);
sysldvp->use_timer = B_TRUE;
sysldvp->ldv = NXGE_SYS_ERROR_LD;
sysldvp->is_syserr = B_TRUE;
sysldvp->ldv_intr_handler = nxge_syserr_intr;
sysldvp->ldv_ldf_masks = 0;
sysldvp->nxgep = nxgep;
ldgvp->ldvp_syserr = sysldvp;
ldgvp->ldvp_syserr_alloced = B_TRUE;
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
"(before rx) func %d nldvs %d navail %d nrequired %d",
func, nldvs, *navail_p, *nrequired_p));
/*
* Start with RDC to configure logical devices for each group.
*/
chn_start = p_cfgp->ldg_chn_start;
set = &nxgep->rx_set;
for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
if ((1 << channel) & set->owned.map) {
ldvp->is_rxdma = B_TRUE;
ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
ldvp->channel = channel;
ldvp->vdma_index = (uint8_t)channel;
ldvp->ldv_intr_handler = nxge_rx_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->nxgep = nxgep;
ldgp->ldg = p_cfgp->ldg[chn_start];
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init_n2(rx%d): maxldvs %d ldv %d "
"ldg %d ldgptr 0x%016llx ldvptr 0x%016llx",
i, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
endldg, nrequired_p);
nldvs++;
chn_start++;
}
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
"func %d nldvs %d navail %d nrequired %d",
func, nldvs, *navail_p, *nrequired_p));
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
"func %d nldvs %d navail %d nrequired %d ldgp 0x%llx "
"ldvp 0x%llx",
func, nldvs, *navail_p, *nrequired_p, ldgp, ldvp));
/*
* Transmit DMA channels.
*/
chn_start = p_cfgp->ldg_chn_start + 8;
set = &nxgep->tx_set;
for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
if ((1 << channel) & set->owned.map) {
ldvp->is_txdma = B_TRUE;
ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
ldvp->channel = channel;
ldvp->vdma_index = (uint8_t)channel;
ldvp->ldv_intr_handler = nxge_tx_intr;
ldvp->ldv_ldf_masks = 0;
ldgp->ldg = p_cfgp->ldg[chn_start];
ldvp->nxgep = nxgep;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init_n2(tx%d): maxldvs %d ldv %d "
"ldg %d ldgptr %p ldvptr %p",
channel, maxldvs, ldv, ldgp->ldg, ldgp, ldvp));
nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
endldg, nrequired_p);
nldvs++;
chn_start++;
}
}
ldgvp->ldg_intrs = *nrequired_p;
ldgvp->nldvs = (uint8_t)nldvs;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init_n2: "
"func %d nldvs %d maxgrps %d navail %d nrequired %d",
func, nldvs, maxldgs, *navail_p, *nrequired_p));
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init_n2"));
return (status);
}
/*
* Interrupts related interface functions.
*/
nxge_status_t
nxge_ldgv_init(p_nxge_t nxgep, int *navail_p, int *nrequired_p)
{
int i, maxldvs, maxldgs, nldvs;
int ldv, ldg, endldg, ngrps;
uint8_t func;
uint8_t channel;
boolean_t own_sys_err = B_FALSE, own_fzc = B_FALSE;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
p_nxge_ldgv_t ldgvp;
p_nxge_ldg_t ldgp, ptr;
p_nxge_ldv_t ldvp;
nxge_grp_set_t *set;
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init"));
if (!*navail_p) {
*nrequired_p = 0;
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_ldgv_init:no avail"));
return (NXGE_ERROR);
}
p_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
nldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
/*
* If function zero instance, it needs to handle the system error
* interrupts.
*/
func = nxgep->function_num;
if (func == 0) {
nldvs++;
own_sys_err = B_TRUE;
} else {
/* use timer */
nldvs++;
}
/*
* Assume single partition, each function owns mac.
*/
if (!nxge_use_partition) {
/* mac */
nldvs++;
/* MIF */
nldvs++;
own_fzc = B_TRUE;
}
maxldvs = nldvs;
maxldgs = p_cfgp->max_ldgs;
if (!maxldvs || !maxldgs) {
/* No devices configured. */
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_init: "
"no logical devices or groups configured."));
return (NXGE_ERROR);
}
ldgvp = nxgep->ldgvp;
if (ldgvp == NULL) {
ldgvp = KMEM_ZALLOC(sizeof (nxge_ldgv_t), KM_SLEEP);
nxgep->ldgvp = ldgvp;
ldgvp->maxldgs = (uint8_t)maxldgs;
ldgvp->maxldvs = (uint8_t)maxldvs;
ldgp = ldgvp->ldgp = KMEM_ZALLOC(sizeof (nxge_ldg_t) * maxldgs,
KM_SLEEP);
ldvp = ldgvp->ldvp = KMEM_ZALLOC(sizeof (nxge_ldv_t) * maxldvs,
KM_SLEEP);
}
ldgvp->ndma_ldvs = p_cfgp->tdc.owned + p_cfgp->max_rdcs;
ldgvp->tmres = NXGE_TIMER_RESO;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init: maxldvs %d maxldgs %d nldvs %d",
maxldvs, maxldgs, nldvs));
ldg = p_cfgp->start_ldg;
ptr = ldgp;
for (i = 0; i < maxldgs; i++) {
ptr->func = func;
ptr->arm = B_TRUE;
ptr->vldg_index = (uint8_t)i;
ptr->ldg_timer = NXGE_TIMER_LDG;
ptr->ldg = ldg++;
ptr->sys_intr_handler = nxge_intr;
ptr->nldvs = 0;
ptr->nxgep = nxgep;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_ldgv_init: maxldvs %d maxldgs %d ldg %d",
maxldvs, maxldgs, ptr->ldg));
ptr++;
}
ldg = p_cfgp->start_ldg;
if (maxldgs > *navail_p) {
ngrps = *navail_p;
} else {
ngrps = maxldgs;
}
endldg = ldg + ngrps;
/*
* Receive DMA channels.
*/
nldvs = 0;
ldgvp->nldvs = 0;
ldgp->ldvp = NULL;
*nrequired_p = 0;
/*
* Start with RDC to configure logical devices for each group.
*/
set = &nxgep->rx_set;
for (channel = 0; channel < NXGE_MAX_RDCS; channel++) {
if ((1 << channel) & set->owned.map) {
/* For now, <channel & <vdma_index> are the same. */
ldvp->is_rxdma = B_TRUE;
ldvp->ldv = (uint8_t)channel + NXGE_RDMA_LD_START;
ldvp->channel = channel;
ldvp->vdma_index = (uint8_t)channel;
ldvp->ldv_intr_handler = nxge_rx_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->use_timer = B_FALSE;
ldvp->nxgep = nxgep;
nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
endldg, nrequired_p);
nldvs++;
}
}
/*
* Transmit DMA channels.
*/
set = &nxgep->tx_set;
for (channel = 0; channel < NXGE_MAX_TDCS; channel++) {
if ((1 << channel) & set->owned.map) {
/* For now, <channel & <vdma_index> are the same. */
ldvp->is_txdma = B_TRUE;
ldvp->ldv = (uint8_t)channel + NXGE_TDMA_LD_START;
ldvp->channel = channel;
ldvp->vdma_index = (uint8_t)channel;
ldvp->ldv_intr_handler = nxge_tx_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->use_timer = B_FALSE;
ldvp->nxgep = nxgep;
nxge_ldgv_setup(&ldgp, &ldvp, ldvp->ldv,
endldg, nrequired_p);
nldvs++;
}
}
if (own_fzc) {
ldv = NXGE_MIF_LD;
ldvp->ldv = (uint8_t)ldv;
ldvp->is_mif = B_TRUE;
ldvp->ldv_intr_handler = nxge_mif_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->use_timer = B_FALSE;
ldvp->nxgep = nxgep;
nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
}
/*
* MAC port (function zero control)
*/
if (own_fzc) {
ldvp->is_mac = B_TRUE;
ldvp->ldv_intr_handler = nxge_mac_intr;
ldvp->ldv_ldf_masks = 0;
ldv = func + NXGE_MAC_LD_START;
ldvp->ldv = (uint8_t)ldv;
ldvp->use_timer = B_FALSE;
ldvp->nxgep = nxgep;
nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
"func %d nldvs %d navail %d nrequired %d",
func, nldvs, *navail_p, *nrequired_p));
/*
* Function 0 owns system error interrupts.
*/
ldvp->use_timer = B_TRUE;
if (own_sys_err) {
ldv = NXGE_SYS_ERROR_LD;
ldvp->ldv = (uint8_t)ldv;
ldvp->is_syserr = B_TRUE;
ldvp->ldv_intr_handler = nxge_syserr_intr;
ldvp->ldv_ldf_masks = 0;
ldvp->nxgep = nxgep;
ldgvp->ldvp_syserr = ldvp;
/*
* Unmask the system interrupt states.
*/
(void) nxge_fzc_sys_err_mask_set(nxgep, SYS_ERR_SMX_MASK |
SYS_ERR_IPP_MASK | SYS_ERR_TXC_MASK |
SYS_ERR_ZCP_MASK);
(void) nxge_ldgv_setup(&ldgp, &ldvp, ldv, endldg, nrequired_p);
nldvs++;
} else {
ldv = NXGE_SYS_ERROR_LD;
ldvp->ldv = (uint8_t)ldv;
ldvp->is_syserr = B_TRUE;
ldvp->ldv_intr_handler = nxge_syserr_intr;
ldvp->nxgep = nxgep;
ldvp->ldv_ldf_masks = 0;
ldgvp->ldvp_syserr = ldvp;
}
ldgvp->ldg_intrs = *nrequired_p;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_init: "
"func %d nldvs %d navail %d nrequired %d",
func, nldvs, *navail_p, *nrequired_p));
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_init"));
return (status);
}
nxge_status_t
nxge_ldgv_uninit(p_nxge_t nxgep)
{
p_nxge_ldgv_t ldgvp;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_ldgv_uninit"));
ldgvp = nxgep->ldgvp;
if (ldgvp == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "<== nxge_ldgv_uninit: "
"no logical group configured."));
return (NXGE_OK);
}
if (ldgvp->ldvp_syserr_alloced == B_TRUE) {
KMEM_FREE(ldgvp->ldvp_syserr, sizeof (nxge_ldv_t));
}
if (ldgvp->ldgp) {
KMEM_FREE(ldgvp->ldgp, sizeof (nxge_ldg_t) * ldgvp->maxldgs);
}
if (ldgvp->ldvp) {
KMEM_FREE(ldgvp->ldvp, sizeof (nxge_ldv_t) * ldgvp->maxldvs);
}
KMEM_FREE(ldgvp, sizeof (nxge_ldgv_t));
nxgep->ldgvp = NULL;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_ldgv_uninit"));
return (NXGE_OK);
}
nxge_status_t
nxge_intr_ldgv_init(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_ldgv_init"));
/*
* Configure the logical device group numbers, state vectors and
* interrupt masks for each logical device.
*/
status = nxge_fzc_intr_init(nxgep);
/*
* Configure logical device masks and timers.
*/
status = nxge_intr_mask_mgmt(nxgep);
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_ldgv_init"));
return (status);
}
nxge_status_t
nxge_intr_mask_mgmt(p_nxge_t nxgep)
{
p_nxge_ldgv_t ldgvp;
p_nxge_ldg_t ldgp;
p_nxge_ldv_t ldvp;
npi_handle_t handle;
int i, j;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, INT_CTL, "==> nxge_intr_mask_mgmt"));
if ((ldgvp = nxgep->ldgvp) == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_intr_mask_mgmt: Null ldgvp"));
return (NXGE_ERROR);
}
handle = NXGE_DEV_NPI_HANDLE(nxgep);
ldgp = ldgvp->ldgp;
ldvp = ldgvp->ldvp;
if (ldgp == NULL || ldvp == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_intr_mask_mgmt: Null ldgp or ldvp"));
return (NXGE_ERROR);
}
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt: # of intrs %d ", ldgvp->ldg_intrs));
/* Initialize masks. */
if (nxgep->niu_type != N2_NIU) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt(Neptune): # intrs %d ",
ldgvp->ldg_intrs));
for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt(Neptune): # ldv %d "
"in group %d", ldgp->nldvs, ldgp->ldg));
for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt: set ldv # %d "
"for ldg %d", ldvp->ldv, ldgp->ldg));
rs = npi_intr_mask_set(handle, ldvp->ldv,
ldvp->ldv_ldf_masks);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_intr_mask_mgmt: "
"set mask failed "
" rs 0x%x ldv %d mask 0x%x",
rs, ldvp->ldv,
ldvp->ldv_ldf_masks));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt: "
"set mask OK "
" rs 0x%x ldv %d mask 0x%x",
rs, ldvp->ldv,
ldvp->ldv_ldf_masks));
}
}
}
ldgp = ldgvp->ldgp;
/* Configure timer and arm bit */
for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
ldgp->arm, ldgp->ldg_timer);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_intr_mask_mgmt: "
"set timer failed "
" rs 0x%x dg %d timer 0x%x",
rs, ldgp->ldg, ldgp->ldg_timer));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt: "
"set timer OK "
" rs 0x%x ldg %d timer 0x%x",
rs, ldgp->ldg, ldgp->ldg_timer));
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_fzc_intr_mask_mgmt"));
return (NXGE_OK);
}
nxge_status_t
nxge_intr_mask_mgmt_set(p_nxge_t nxgep, boolean_t on)
{
p_nxge_ldgv_t ldgvp;
p_nxge_ldg_t ldgp;
p_nxge_ldv_t ldvp;
npi_handle_t handle;
int i, j;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt_set (%d)", on));
if (nxgep->niu_type == N2_NIU) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"<== nxge_intr_mask_mgmt_set (%d) not set (N2/NIU)",
on));
return (NXGE_ERROR);
}
if ((ldgvp = nxgep->ldgvp) == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_intr_mask_mgmt_set: Null ldgvp"));
return (NXGE_ERROR);
}
handle = NXGE_DEV_NPI_HANDLE(nxgep);
ldgp = ldgvp->ldgp;
ldvp = ldgvp->ldvp;
if (ldgp == NULL || ldvp == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_intr_mask_mgmt_set: Null ldgp or ldvp"));
return (NXGE_ERROR);
}
/* set masks. */
for (i = 0; i < ldgvp->ldg_intrs; i++, ldgp++) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt_set: flag %d ldg %d"
"set mask nldvs %d", on, ldgp->ldg, ldgp->nldvs));
for (j = 0; j < ldgp->nldvs; j++, ldvp++) {
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt_set: "
"for %d %d flag %d", i, j, on));
if (on) {
ldvp->ldv_ldf_masks = 0;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt_set: "
"ON mask off"));
} else if (!on) {
ldvp->ldv_ldf_masks = (uint8_t)LD_IM1_MASK;
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt_set:mask on"));
}
rs = npi_intr_mask_set(handle, ldvp->ldv,
ldvp->ldv_ldf_masks);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"==> nxge_intr_mask_mgmt_set: "
"set mask failed "
" rs 0x%x ldv %d mask 0x%x",
rs, ldvp->ldv, ldvp->ldv_ldf_masks));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt_set: flag %d"
"set mask OK "
" ldv %d mask 0x%x",
on, ldvp->ldv, ldvp->ldv_ldf_masks));
}
}
ldgp = ldgvp->ldgp;
/* set the arm bit */
for (i = 0; i < nxgep->ldgvp->ldg_intrs; i++, ldgp++) {
if (on && !ldgp->arm) {
ldgp->arm = B_TRUE;
} else if (!on && ldgp->arm) {
ldgp->arm = B_FALSE;
}
rs = npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
ldgp->arm, ldgp->ldg_timer);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_intr_mask_mgmt_set: "
"set timer failed "
" rs 0x%x ldg %d timer 0x%x",
rs, ldgp->ldg, ldgp->ldg_timer));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, INT_CTL,
"==> nxge_intr_mask_mgmt_set: OK (flag %d) "
"set timer "
" ldg %d timer 0x%x",
on, ldgp->ldg, ldgp->ldg_timer));
}
NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_intr_mask_mgmt_set"));
return (NXGE_OK);
}
static nxge_status_t
nxge_get_mac_addr_properties(p_nxge_t nxgep)
{
#if defined(_BIG_ENDIAN)
uchar_t *prop_val;
uint_t prop_len;
uint_t j;
#endif
uint_t i;
uint8_t func_num;
boolean_t compute_macs = B_TRUE;
NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_mac_addr_properties "));
#if defined(_BIG_ENDIAN)
/*
* Get the ethernet address.
*/
(void) localetheraddr((struct ether_addr *)NULL, &nxgep->ouraddr);
/*
* Check if it is an adapter with its own local mac address If it is
* present, override the system mac address.
*/
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"local-mac-address", &prop_val,
&prop_len) == DDI_PROP_SUCCESS) {
if (prop_len == ETHERADDRL) {
nxgep->factaddr = *(p_ether_addr_t)prop_val;
NXGE_DEBUG_MSG((nxgep, DDI_CTL, "Local mac address = "
"%02x:%02x:%02x:%02x:%02x:%02x",
prop_val[0], prop_val[1], prop_val[2],
prop_val[3], prop_val[4], prop_val[5]));
}
ddi_prop_free(prop_val);
}
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"local-mac-address?", &prop_val,
&prop_len) == DDI_PROP_SUCCESS) {
if (strncmp("true", (caddr_t)prop_val, (size_t)prop_len) == 0) {
nxgep->ouraddr = nxgep->factaddr;
NXGE_DEBUG_MSG((nxgep, DDI_CTL,
"Using local MAC address"));
}
ddi_prop_free(prop_val);
} else {
nxgep->ouraddr = nxgep->factaddr;
}
if ((!nxgep->vpd_info.present) ||
(nxge_is_valid_local_mac(nxgep->factaddr)))
goto got_mac_addr;
NXGE_DEBUG_MSG((nxgep, DDI_CTL, "nxge_get_mac_addr_properties: "
"MAC address from properties is not valid...reading from PROM"));
#endif
if (!nxgep->vpd_info.ver_valid) {
(void) nxge_espc_mac_addrs_get(nxgep);
if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
"MAC address"));
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
"[%s] invalid...please update",
nxgep->vpd_info.ver));
return (NXGE_ERROR);
}
nxgep->ouraddr = nxgep->factaddr;
goto got_mac_addr;
}
/*
* First get the MAC address from the info in the VPD data read
* from the EEPROM.
*/
nxge_espc_get_next_mac_addr(nxgep->vpd_info.mac_addr,
nxgep->function_num, &nxgep->factaddr);
if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
NXGE_DEBUG_MSG((nxgep, DDI_CTL,
"nxge_get_mac_addr_properties: "
"MAC address in EEPROM VPD data not valid"
"...reading from NCR registers"));
(void) nxge_espc_mac_addrs_get(nxgep);
if (!nxge_is_valid_local_mac(nxgep->factaddr)) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Failed to get "
"MAC address"));
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "EEPROM version "
"[%s] invalid...please update",
nxgep->vpd_info.ver));
return (NXGE_ERROR);
}
}
nxgep->ouraddr = nxgep->factaddr;
got_mac_addr:
func_num = nxgep->function_num;
/*
* Note: mac-addresses property is the list of mac addresses for a
* port. NXGE_MAX_MMAC_ADDRS is the total number of MAC addresses
* allocated for a board.
*/
nxgep->nxge_mmac_info.total_factory_macs = NXGE_MAX_MMAC_ADDRS;
#if defined(_BIG_ENDIAN)
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"mac-addresses", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
/*
* XAUI may have up to 18 MACs, more than the XMAC can
* use (1 unique MAC plus 16 alternate MACs)
*/
nxgep->nxge_mmac_info.num_factory_mmac =
prop_len / ETHERADDRL - 1;
if (nxgep->nxge_mmac_info.num_factory_mmac >
XMAC_MAX_ALT_ADDR_ENTRY) {
nxgep->nxge_mmac_info.num_factory_mmac =
XMAC_MAX_ALT_ADDR_ENTRY;
}
for (i = 1; i <= nxgep->nxge_mmac_info.num_factory_mmac; i++) {
for (j = 0; j < ETHERADDRL; j++) {
nxgep->nxge_mmac_info.factory_mac_pool[i][j] =
*(prop_val + (i * ETHERADDRL) + j);
}
NXGE_DEBUG_MSG((nxgep, DDI_CTL,
"nxge_get_mac_addr_properties: Alt mac[%d] from "
"mac-addresses property[%2x:%2x:%2x:%2x:%2x:%2x]",
i, nxgep->nxge_mmac_info.factory_mac_pool[i][0],
nxgep->nxge_mmac_info.factory_mac_pool[i][1],
nxgep->nxge_mmac_info.factory_mac_pool[i][2],
nxgep->nxge_mmac_info.factory_mac_pool[i][3],
nxgep->nxge_mmac_info.factory_mac_pool[i][4],
nxgep->nxge_mmac_info.factory_mac_pool[i][5]));
}
compute_macs = B_FALSE;
ddi_prop_free(prop_val);
goto got_mmac_info;
}
#endif
/*
* total_factory_macs = 32
* num_factory_mmac = (32 >> (nports/2)) - 1
* So if nports = 4, then num_factory_mmac = 7
* if nports = 2, then num_factory_mmac = 15
*/
nxgep->nxge_mmac_info.num_factory_mmac =
((nxgep->nxge_mmac_info.total_factory_macs >>
(nxgep->nports >> 1))) - 1;
got_mmac_info:
if ((nxgep->function_num < 2) &&
(nxgep->nxge_mmac_info.num_factory_mmac >
XMAC_MAX_ALT_ADDR_ENTRY)) {
nxgep->nxge_mmac_info.num_factory_mmac =
XMAC_MAX_ALT_ADDR_ENTRY;
} else if ((nxgep->function_num > 1) &&
(nxgep->nxge_mmac_info.num_factory_mmac >
BMAC_MAX_ALT_ADDR_ENTRY)) {
nxgep->nxge_mmac_info.num_factory_mmac =
BMAC_MAX_ALT_ADDR_ENTRY;
}
for (i = 0; i <= nxgep->nxge_mmac_info.num_mmac; i++) {
(void) npi_mac_altaddr_disable(nxgep->npi_handle,
NXGE_GET_PORT_NUM(func_num), i);
}
(void) nxge_init_mmac(nxgep, compute_macs);
return (NXGE_OK);
}
void
nxge_get_xcvr_properties(p_nxge_t nxgep)
{
uchar_t *prop_val;
uint_t prop_len;
NXGE_DEBUG_MSG((nxgep, DDI_CTL, "==> nxge_get_xcvr_properties"));
/*
* Read the type of physical layer interface being used.
*/
nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"phy-type", &prop_val, &prop_len) == DDI_PROP_SUCCESS) {
if (strncmp("pcs", (caddr_t)prop_val,
(size_t)prop_len) == 0) {
nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
} else {
nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
}
ddi_prop_free(prop_val);
} else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, nxgep->dip, 0,
"phy-interface", &prop_val,
&prop_len) == DDI_PROP_SUCCESS) {
if (strncmp("pcs", (caddr_t)prop_val, (size_t)prop_len) == 0) {
nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
} else {
nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
}
ddi_prop_free(prop_val);
}
}
/*
* Static functions start here.
*/
static void
nxge_ldgv_setup(p_nxge_ldg_t *ldgp, p_nxge_ldv_t *ldvp, uint8_t ldv,
uint8_t endldg, int *ngrps)
{
NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup"));
/* Assign the group number for each device. */
(*ldvp)->ldg_assigned = (*ldgp)->ldg;
(*ldvp)->ldgp = *ldgp;
(*ldvp)->ldv = ldv;
NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
"ldv %d endldg %d ldg %d, ldvp $%p",
ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
(*ldgp)->nldvs++;
if ((*ldgp)->ldg == (endldg - 1)) {
if ((*ldgp)->ldvp == NULL) {
(*ldgp)->ldvp = *ldvp;
*ngrps += 1;
NXGE_DEBUG_MSG((NULL, INT_CTL,
"==> nxge_ldgv_setup: ngrps %d", *ngrps));
}
NXGE_DEBUG_MSG((NULL, INT_CTL,
"==> nxge_ldgv_setup: ldvp $%p ngrps %d",
*ldvp, *ngrps));
++*ldvp;
} else {
(*ldgp)->ldvp = *ldvp;
*ngrps += 1;
NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup(done): "
"ldv %d endldg %d ldg %d, ldvp $%p",
ldv, endldg, (*ldgp)->ldg, (*ldgp)->ldvp));
++*ldvp;
++*ldgp;
NXGE_DEBUG_MSG((NULL, INT_CTL,
"==> nxge_ldgv_setup: new ngrps %d", *ngrps));
}
NXGE_DEBUG_MSG((NULL, INT_CTL, "==> nxge_ldgv_setup: "
"ldv %d ldvp $%p endldg %d ngrps %d",
ldv, ldvp, endldg, *ngrps));
NXGE_DEBUG_MSG((NULL, INT_CTL, "<== nxge_ldgv_setup"));
}
/*
* Note: This function assumes the following distribution of mac
* addresses among 4 ports in neptune:
*
* -------------
* 0| |0 - local-mac-address for fn 0
* -------------
* 1| |1 - local-mac-address for fn 1
* -------------
* 2| |2 - local-mac-address for fn 2
* -------------
* 3| |3 - local-mac-address for fn 3
* -------------
* | |4 - Start of alt. mac addr. for fn 0
* | |
* | |
* | |10
* --------------
* | |11 - Start of alt. mac addr. for fn 1
* | |
* | |
* | |17
* --------------
* | |18 - Start of alt. mac addr. for fn 2
* | |
* | |
* | |24
* --------------
* | |25 - Start of alt. mac addr. for fn 3
* | |
* | |
* | |31
* --------------
*
* For N2/NIU the mac addresses is from XAUI card.
*
* When 'compute_addrs' is true, the alternate mac addresses are computed
* using the unique mac address as base. Otherwise the alternate addresses
* are assigned from the list read off the 'mac-addresses' property.
*/
static void
nxge_init_mmac(p_nxge_t nxgep, boolean_t compute_addrs)
{
int slot;
uint8_t func_num;
uint16_t *base_mmac_addr;
uint32_t alt_mac_ls4b;
uint16_t *mmac_addr;
uint32_t base_mac_ls4b; /* least significant 4 bytes */
nxge_mmac_t *mmac_info;
npi_mac_addr_t mac_addr;
func_num = nxgep->function_num;
base_mmac_addr = (uint16_t *)&nxgep->factaddr;
mmac_info = (nxge_mmac_t *)&nxgep->nxge_mmac_info;
if (compute_addrs) {
base_mac_ls4b = ((uint32_t)base_mmac_addr[1]) << 16 |
base_mmac_addr[2];
if (nxgep->niu_type == N2_NIU) {
/* ls4b of 1st altmac */
alt_mac_ls4b = base_mac_ls4b + 1;
} else { /* Neptune */
alt_mac_ls4b = base_mac_ls4b +
(nxgep->nports - func_num) +
(func_num * (mmac_info->num_factory_mmac));
}
}
/* Set flags for unique MAC */
mmac_info->mac_pool[0].flags |= MMAC_SLOT_USED | MMAC_VENDOR_ADDR;
/* Clear flags of all alternate MAC slots */
for (slot = 1; slot <= mmac_info->num_mmac; slot++) {
if (slot <= mmac_info->num_factory_mmac)
mmac_info->mac_pool[slot].flags = MMAC_VENDOR_ADDR;
else
mmac_info->mac_pool[slot].flags = 0;
}
/* Generate and store factory alternate MACs */
for (slot = 1; slot <= mmac_info->num_factory_mmac; slot++) {
mmac_addr = (uint16_t *)&mmac_info->factory_mac_pool[slot];
if (compute_addrs) {
mmac_addr[0] = base_mmac_addr[0];
mac_addr.w2 = mmac_addr[0];
mmac_addr[1] = (alt_mac_ls4b >> 16) & 0x0FFFF;
mac_addr.w1 = mmac_addr[1];
mmac_addr[2] = alt_mac_ls4b & 0x0FFFF;
mac_addr.w0 = mmac_addr[2];
alt_mac_ls4b++;
} else {
mac_addr.w2 = mmac_addr[0];
mac_addr.w1 = mmac_addr[1];
mac_addr.w0 = mmac_addr[2];
}
NXGE_DEBUG_MSG((nxgep, DDI_CTL,
"mac_pool_addr[%2x:%2x:%2x:%2x:%2x:%2x] npi_addr[%x%x%x]",
mmac_info->factory_mac_pool[slot][0],
mmac_info->factory_mac_pool[slot][1],
mmac_info->factory_mac_pool[slot][2],
mmac_info->factory_mac_pool[slot][3],
mmac_info->factory_mac_pool[slot][4],
mmac_info->factory_mac_pool[slot][5],
mac_addr.w0, mac_addr.w1, mac_addr.w2));
/*
* slot minus 1 because npi_mac_altaddr_entry expects 0
* for the first alternate mac address.
*/
(void) npi_mac_altaddr_entry(nxgep->npi_handle, OP_SET,
NXGE_GET_PORT_NUM(func_num), slot - 1, &mac_addr);
}
/* Initialize the first two parameters for mmac kstat */
nxgep->statsp->mmac_stats.mmac_max_cnt = mmac_info->num_mmac;
nxgep->statsp->mmac_stats.mmac_avail_cnt = mmac_info->num_mmac;
}
/*
* Convert an RDC group index into a port ring index. That is, map
* <groupid> to an index into nxgep->rx_ring_handles.
* (group ring index -> port ring index)
*/
int
nxge_get_rxring_index(p_nxge_t nxgep, int groupid, int ringidx)
{
int i;
int index = 0;
p_nxge_rdc_grp_t rdc_grp_p;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
p_dma_cfgp = &nxgep->pt_config;
p_cfgp = &p_dma_cfgp->hw_config;
if (isLDOMguest(nxgep))
return (ringidx);
for (i = 0; i < groupid; i++) {
rdc_grp_p =
&p_dma_cfgp->rdc_grps[p_cfgp->def_mac_rxdma_grpid + i];
index += rdc_grp_p->max_rdcs;
}
return (index + ringidx);
}
|