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
|
/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <npi_fflp.h>
#include <npi_mac.h>
#include <nxge_defs.h>
#include <nxge_flow.h>
#include <nxge_fflp.h>
#include <nxge_impl.h>
#include <nxge_fflp_hash.h>
#include <nxge_common.h>
/*
* Function prototypes
*/
static nxge_status_t nxge_fflp_vlan_tbl_clear_all(p_nxge_t);
static nxge_status_t nxge_fflp_tcam_invalidate_all(p_nxge_t);
static nxge_status_t nxge_fflp_tcam_init(p_nxge_t);
static nxge_status_t nxge_fflp_fcram_invalidate_all(p_nxge_t);
static nxge_status_t nxge_fflp_fcram_init(p_nxge_t);
static int nxge_flow_need_hash_lookup(p_nxge_t, flow_resource_t *);
static void nxge_fill_tcam_entry_tcp(p_nxge_t, flow_spec_t *, tcam_entry_t *);
static void nxge_fill_tcam_entry_udp(p_nxge_t, flow_spec_t *, tcam_entry_t *);
static void nxge_fill_tcam_entry_sctp(p_nxge_t, flow_spec_t *, tcam_entry_t *);
static void nxge_fill_tcam_entry_tcp_ipv6(p_nxge_t, flow_spec_t *,
tcam_entry_t *);
static void nxge_fill_tcam_entry_udp_ipv6(p_nxge_t, flow_spec_t *,
tcam_entry_t *);
static void nxge_fill_tcam_entry_sctp_ipv6(p_nxge_t, flow_spec_t *,
tcam_entry_t *);
static uint8_t nxge_get_rdc_offset(p_nxge_t, uint8_t, uint64_t);
static uint8_t nxge_get_rdc_group(p_nxge_t, uint8_t, uint64_t);
static uint16_t nxge_tcam_get_index(p_nxge_t, uint16_t);
static uint32_t nxge_tcam_cls_to_flow(uint32_t);
static uint8_t nxge_iptun_pkt_type_to_pid(uint8_t);
static npi_status_t nxge_set_iptun_usr_cls_reg(p_nxge_t, uint64_t,
iptun_cfg_t *);
static boolean_t nxge_is_iptun_cls_present(p_nxge_t, uint8_t, int *);
/*
* functions used outside this file
*/
nxge_status_t nxge_fflp_config_vlan_table(p_nxge_t, uint16_t);
nxge_status_t nxge_fflp_ip_class_config_all(p_nxge_t);
nxge_status_t nxge_add_flow(p_nxge_t, flow_resource_t *);
static nxge_status_t nxge_tcam_handle_ip_fragment(p_nxge_t);
nxge_status_t nxge_add_tcam_entry(p_nxge_t, flow_resource_t *);
nxge_status_t nxge_add_fcram_entry(p_nxge_t, flow_resource_t *);
nxge_status_t nxge_flow_get_hash(p_nxge_t, flow_resource_t *,
uint32_t *, uint16_t *);
int nxge_get_valid_tcam_cnt(p_nxge_t);
void nxge_get_tcam_entry_all(p_nxge_t, rx_class_cfg_t *);
void nxge_get_tcam_entry(p_nxge_t, flow_resource_t *);
void nxge_del_tcam_entry(p_nxge_t, uint32_t);
void nxge_add_iptun_class(p_nxge_t, iptun_cfg_t *, uint8_t *);
void nxge_cfg_iptun_hash(p_nxge_t, iptun_cfg_t *, uint8_t);
void nxge_del_iptun_class(p_nxge_t, uint8_t);
void nxge_get_iptun_class(p_nxge_t, iptun_cfg_t *, uint8_t);
void nxge_set_ip_cls_sym(p_nxge_t, uint8_t, uint8_t);
void nxge_get_ip_cls_sym(p_nxge_t, uint8_t, uint8_t *);
nxge_status_t
nxge_tcam_dump_entry(p_nxge_t nxgep, uint32_t location)
{
tcam_entry_t tcam_rdptr;
uint64_t asc_ram = 0;
npi_handle_t handle;
npi_status_t status;
handle = nxgep->npi_reg_handle;
bzero((char *)&tcam_rdptr, sizeof (struct tcam_entry));
status = npi_fflp_tcam_entry_read(handle, (tcam_location_t)location,
(struct tcam_entry *)&tcam_rdptr);
if (status & NPI_FAILURE) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_tcam_dump_entry:"
" tcam read failed at location %d ", location));
return (NXGE_ERROR);
}
status = npi_fflp_tcam_asc_ram_entry_read(handle,
(tcam_location_t)location, &asc_ram);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "location %x\n"
" key: %llx %llx %llx %llx \n"
" mask: %llx %llx %llx %llx \n"
" ASC RAM %llx \n", location,
tcam_rdptr.key0, tcam_rdptr.key1,
tcam_rdptr.key2, tcam_rdptr.key3,
tcam_rdptr.mask0, tcam_rdptr.mask1,
tcam_rdptr.mask2, tcam_rdptr.mask3, asc_ram));
return (NXGE_OK);
}
void
nxge_get_tcam(p_nxge_t nxgep, p_mblk_t mp)
{
uint32_t tcam_loc;
int *lptr;
int location;
uint32_t start_location = 0;
uint32_t stop_location = nxgep->classifier.tcam_size;
lptr = (int *)mp->b_rptr;
location = *lptr;
if ((location >= nxgep->classifier.tcam_size) || (location < -1)) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_tcam_dump: Invalid location %d \n", location));
return;
}
if (location == -1) {
start_location = 0;
stop_location = nxgep->classifier.tcam_size;
} else {
start_location = location;
stop_location = location + 1;
}
for (tcam_loc = start_location; tcam_loc < stop_location; tcam_loc++)
(void) nxge_tcam_dump_entry(nxgep, tcam_loc);
}
/*
* nxge_fflp_vlan_table_invalidate_all
* invalidates the vlan RDC table entries.
* INPUT
* nxge soft state data structure
* Return
* NXGE_OK
* NXGE_ERROR
*
*/
static nxge_status_t
nxge_fflp_vlan_tbl_clear_all(p_nxge_t nxgep)
{
vlan_id_t vlan_id;
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
vlan_id_t start = 0, stop = NXGE_MAX_VLANS;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_vlan_tbl_clear_all "));
handle = nxgep->npi_reg_handle;
for (vlan_id = start; vlan_id < stop; vlan_id++) {
rs = npi_fflp_cfg_vlan_table_clear(handle, vlan_id);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"VLAN Table invalidate failed for vlan id %d ",
vlan_id));
return (NXGE_ERROR | rs);
}
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_vlan_tbl_clear_all "));
return (NXGE_OK);
}
/*
* The following functions are used by other modules to init
* the fflp module.
* these functions are the basic API used to init
* the fflp modules (tcam, fcram etc ......)
*
* The TCAM search future would be disabled by default.
*/
static nxge_status_t
nxge_fflp_tcam_init(p_nxge_t nxgep)
{
uint8_t access_ratio;
tcam_class_t class;
npi_status_t rs = NPI_SUCCESS;
npi_handle_t handle;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_tcam_init"));
handle = nxgep->npi_reg_handle;
rs = npi_fflp_cfg_tcam_disable(handle);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "failed TCAM Disable\n"));
return (NXGE_ERROR | rs);
}
access_ratio = nxgep->param_arr[param_tcam_access_ratio].value;
rs = npi_fflp_cfg_tcam_access(handle, access_ratio);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed TCAM Access cfg\n"));
return (NXGE_ERROR | rs);
}
/* disable configurable classes */
/* disable the configurable ethernet classes; */
for (class = TCAM_CLASS_ETYPE_1;
class <= TCAM_CLASS_ETYPE_2; class++) {
rs = npi_fflp_cfg_enet_usr_cls_disable(handle, class);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"TCAM USR Ether Class config failed."));
return (NXGE_ERROR | rs);
}
}
/* disable the configurable ip classes; */
for (class = TCAM_CLASS_IP_USER_4;
class <= TCAM_CLASS_IP_USER_7; class++) {
rs = npi_fflp_cfg_ip_usr_cls_disable(handle, class);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"TCAM USR IP Class cnfg failed."));
return (NXGE_ERROR | rs);
}
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_tcam_init"));
return (NXGE_OK);
}
/*
* nxge_fflp_tcam_invalidate_all
* invalidates all the tcam entries.
* INPUT
* nxge soft state data structure
* Return
* NXGE_OK
* NXGE_ERROR
*
*/
static nxge_status_t
nxge_fflp_tcam_invalidate_all(p_nxge_t nxgep)
{
uint16_t location;
npi_status_t rs = NPI_SUCCESS;
npi_handle_t handle;
uint16_t start = 0, stop = nxgep->classifier.tcam_size;
p_nxge_hw_list_t hw_p;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"==> nxge_fflp_tcam_invalidate_all"));
handle = nxgep->npi_reg_handle;
if ((hw_p = nxgep->nxge_hw_p) == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_tcam_invalidate_all:"
" common hardware not set", nxgep->niu_type));
return (NXGE_ERROR);
}
MUTEX_ENTER(&hw_p->nxge_tcam_lock);
for (location = start; location < stop; location++) {
rs = npi_fflp_tcam_entry_invalidate(handle, location);
if (rs != NPI_SUCCESS) {
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"TCAM invalidate failed at loc %d ", location));
return (NXGE_ERROR | rs);
}
}
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"<== nxge_fflp_tcam_invalidate_all"));
return (NXGE_OK);
}
/*
* nxge_fflp_fcram_entry_invalidate_all
* invalidates all the FCRAM entries.
* INPUT
* nxge soft state data structure
* Return
* NXGE_OK
* NXGE_ERROR
*
*/
static nxge_status_t
nxge_fflp_fcram_invalidate_all(p_nxge_t nxgep)
{
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
part_id_t pid = 0;
uint8_t base_mask, base_reloc;
fcram_entry_t fc;
uint32_t location;
uint32_t increment, last_location;
/*
* (1) configure and enable partition 0 with no relocation
* (2) Assume the FCRAM is used as IPv4 exact match entry cells
* (3) Invalidate these cells by clearing the valid bit in
* the subareas 0 and 4
* (4) disable the partition
*
*/
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_fcram_invalidate_all"));
base_mask = base_reloc = 0x0;
handle = nxgep->npi_reg_handle;
rs = npi_fflp_cfg_fcram_partition(handle, pid, base_mask, base_reloc);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "failed partition cfg\n"));
return (NXGE_ERROR | rs);
}
rs = npi_fflp_cfg_fcram_partition_disable(handle, pid);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed partition enable\n"));
return (NXGE_ERROR | rs);
}
fc.dreg[0].value = 0;
fc.hash_hdr_valid = 0;
fc.hash_hdr_ext = 1; /* specify as IPV4 exact match entry */
increment = sizeof (hash_ipv4_t);
last_location = FCRAM_SIZE * 0x40;
for (location = 0; location < last_location; location += increment) {
rs = npi_fflp_fcram_subarea_write(handle, pid,
location, fc.value[0]);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed write at location %x ", location));
return (NXGE_ERROR | rs);
}
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_fcram_invalidate_all"));
return (NXGE_OK);
}
static nxge_status_t
nxge_fflp_fcram_init(p_nxge_t nxgep)
{
fflp_fcram_output_drive_t strength;
fflp_fcram_qs_t qs;
npi_status_t rs = NPI_SUCCESS;
uint8_t access_ratio;
int partition;
npi_handle_t handle;
uint32_t min_time, max_time, sys_time;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_fcram_init"));
/*
* Recommended values are needed.
*/
min_time = FCRAM_REFRESH_DEFAULT_MIN_TIME;
max_time = FCRAM_REFRESH_DEFAULT_MAX_TIME;
sys_time = FCRAM_REFRESH_DEFAULT_SYS_TIME;
handle = nxgep->npi_reg_handle;
strength = FCRAM_OUTDR_NORMAL;
qs = FCRAM_QS_MODE_QS;
rs = npi_fflp_cfg_fcram_reset(handle, strength, qs);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "failed FCRAM Reset. "));
return (NXGE_ERROR | rs);
}
access_ratio = nxgep->param_arr[param_fcram_access_ratio].value;
rs = npi_fflp_cfg_fcram_access(handle, access_ratio);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "failed FCRAM Access ratio"
"configuration \n"));
return (NXGE_ERROR | rs);
}
rs = npi_fflp_cfg_fcram_refresh_time(handle, min_time,
max_time, sys_time);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed FCRAM refresh cfg"));
return (NXGE_ERROR);
}
/* disable all the partitions until explicitly enabled */
for (partition = 0; partition < FFLP_FCRAM_MAX_PARTITION; partition++) {
rs = npi_fflp_cfg_fcram_partition_disable(handle, partition);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed FCRAM partition"
" enable for partition %d ", partition));
return (NXGE_ERROR | rs);
}
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_fcram_init"));
return (NXGE_OK);
}
nxge_status_t
nxge_logical_mac_assign_rdc_table(p_nxge_t nxgep, uint8_t alt_mac)
{
npi_status_t rs = NPI_SUCCESS;
hostinfo_t mac_rdc;
npi_handle_t handle;
p_nxge_class_pt_cfg_t p_class_cfgp;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
if (p_class_cfgp->mac_host_info[alt_mac].flag == 0) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_logical_mac_assign_rdc_table"
" unconfigured alt MAC addr %d ", alt_mac));
return (NXGE_ERROR);
}
handle = nxgep->npi_reg_handle;
mac_rdc.value = 0;
mac_rdc.bits.w0.rdc_tbl_num =
p_class_cfgp->mac_host_info[alt_mac].rdctbl;
mac_rdc.bits.w0.mac_pref = p_class_cfgp->mac_host_info[alt_mac].mpr_npr;
rs = npi_mac_hostinfo_entry(handle, OP_SET,
nxgep->function_num, alt_mac, &mac_rdc);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed Assign RDC table"));
return (NXGE_ERROR | rs);
}
return (NXGE_OK);
}
nxge_status_t
nxge_main_mac_assign_rdc_table(p_nxge_t nxgep)
{
npi_status_t rs = NPI_SUCCESS;
hostinfo_t mac_rdc;
npi_handle_t handle;
int i;
handle = nxgep->npi_reg_handle;
mac_rdc.value = 0;
mac_rdc.bits.w0.rdc_tbl_num = nxgep->class_config.mac_rdcgrp;
mac_rdc.bits.w0.mac_pref = 1;
switch (nxgep->function_num) {
case 0:
case 1:
/*
* Tests indicate that it is OK not to re-initialize the
* hostinfo registers for the XMAC's alternate MAC
* addresses. But that is necessary for BMAC (case 2
* and case 3 below)
*/
rs = npi_mac_hostinfo_entry(handle, OP_SET,
nxgep->function_num, XMAC_UNIQUE_HOST_INFO_ENTRY, &mac_rdc);
break;
case 2:
case 3:
rs = npi_mac_hostinfo_entry(handle, OP_SET,
nxgep->function_num, BMAC_UNIQUE_HOST_INFO_ENTRY, &mac_rdc);
for (i = 1; i <= BMAC_MAX_ALT_ADDR_ENTRY; i++)
rs |= npi_mac_hostinfo_entry(handle, OP_SET,
nxgep->function_num, i, &mac_rdc);
break;
default:
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed Assign RDC table (invalid function #)"));
return (NXGE_ERROR);
}
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed Assign RDC table"));
return (NXGE_ERROR | rs);
}
return (NXGE_OK);
}
/*
* Initialize hostinfo registers for alternate MAC addresses and
* multicast MAC address.
*/
nxge_status_t
nxge_alt_mcast_mac_assign_rdc_table(p_nxge_t nxgep)
{
npi_status_t rs = NPI_SUCCESS;
hostinfo_t mac_rdc;
npi_handle_t handle;
handle = nxgep->npi_reg_handle;
mac_rdc.value = 0;
mac_rdc.bits.w0.rdc_tbl_num = nxgep->class_config.mcast_rdcgrp;
mac_rdc.bits.w0.mac_pref = 1;
switch (nxgep->function_num) {
case 0:
case 1:
rs = npi_mac_hostinfo_entry(handle, OP_SET,
nxgep->function_num, XMAC_MULTI_HOST_INFO_ENTRY, &mac_rdc);
break;
case 2:
case 3:
rs = npi_mac_hostinfo_entry(handle, OP_SET,
nxgep->function_num, BMAC_MULTI_HOST_INFO_ENTRY, &mac_rdc);
break;
default:
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed Assign RDC table (invalid function #)"));
return (NXGE_ERROR);
}
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed Assign RDC table"));
return (NXGE_ERROR | rs);
}
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_init_hostinfo(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
status = nxge_alt_mcast_mac_assign_rdc_table(nxgep);
status |= nxge_main_mac_assign_rdc_table(nxgep);
return (status);
}
nxge_status_t
nxge_fflp_hw_reset(p_nxge_t nxgep)
{
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_fflp_hw_reset"));
if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
status = nxge_fflp_fcram_init(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" failed FCRAM init. "));
return (status);
}
}
status = nxge_fflp_tcam_init(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed TCAM init."));
return (status);
}
handle = nxgep->npi_reg_handle;
rs = npi_fflp_cfg_llcsnap_enable(handle);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed LLCSNAP enable. "));
return (NXGE_ERROR | rs);
}
rs = npi_fflp_cfg_cam_errorcheck_disable(handle);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed CAM Error Check enable. "));
return (NXGE_ERROR | rs);
}
/* init the hash generators */
rs = npi_fflp_cfg_hash_h1poly(handle, 0);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed H1 Poly Init. "));
return (NXGE_ERROR | rs);
}
rs = npi_fflp_cfg_hash_h2poly(handle, 0);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed H2 Poly Init. "));
return (NXGE_ERROR | rs);
}
/* invalidate TCAM entries */
status = nxge_fflp_tcam_invalidate_all(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed TCAM Entry Invalidate. "));
return (status);
}
/* invalidate FCRAM entries */
if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
status = nxge_fflp_fcram_invalidate_all(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed FCRAM Entry Invalidate."));
return (status);
}
}
/* invalidate VLAN RDC tables */
status = nxge_fflp_vlan_tbl_clear_all(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"failed VLAN Table Invalidate. "));
return (status);
}
nxgep->classifier.state |= NXGE_FFLP_HW_RESET;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_hw_reset"));
return (NXGE_OK);
}
nxge_status_t
nxge_cfg_ip_cls_flow_key(p_nxge_t nxgep, tcam_class_t l3_class,
uint32_t class_config)
{
flow_key_cfg_t fcfg;
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_cfg_ip_cls_flow_key"));
handle = nxgep->npi_reg_handle;
bzero(&fcfg, sizeof (flow_key_cfg_t));
if (class_config & NXGE_CLASS_FLOW_USE_PROTO)
fcfg.use_proto = 1;
if (class_config & NXGE_CLASS_FLOW_USE_DST_PORT)
fcfg.use_dport = 1;
if (class_config & NXGE_CLASS_FLOW_USE_SRC_PORT)
fcfg.use_sport = 1;
if (class_config & NXGE_CLASS_FLOW_USE_IPDST)
fcfg.use_daddr = 1;
if (class_config & NXGE_CLASS_FLOW_USE_IPSRC)
fcfg.use_saddr = 1;
if (class_config & NXGE_CLASS_FLOW_USE_VLAN)
fcfg.use_vlan = 1;
if (class_config & NXGE_CLASS_FLOW_USE_L2DA)
fcfg.use_l2da = 1;
if (class_config & NXGE_CLASS_FLOW_USE_PORTNUM)
fcfg.use_portnum = 1;
fcfg.ip_opts_exist = 0;
rs = npi_fflp_cfg_ip_cls_flow_key(handle, l3_class, &fcfg);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, " nxge_cfg_ip_cls_flow_key"
" opt %x for class %d failed ", class_config, l3_class));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " <== nxge_cfg_ip_cls_flow_key"));
return (NXGE_OK);
}
nxge_status_t
nxge_cfg_ip_cls_flow_key_get(p_nxge_t nxgep, tcam_class_t l3_class,
uint32_t *class_config)
{
flow_key_cfg_t fcfg;
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
uint32_t ccfg = 0;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_cfg_ip_cls_flow_key_get"));
handle = nxgep->npi_reg_handle;
bzero(&fcfg, sizeof (flow_key_cfg_t));
rs = npi_fflp_cfg_ip_cls_flow_key_get(handle, l3_class, &fcfg);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, " nxge_cfg_ip_cls_flow_key"
" opt %x for class %d failed ", class_config, l3_class));
return (NXGE_ERROR | rs);
}
if (fcfg.use_proto)
ccfg |= NXGE_CLASS_FLOW_USE_PROTO;
if (fcfg.use_dport)
ccfg |= NXGE_CLASS_FLOW_USE_DST_PORT;
if (fcfg.use_sport)
ccfg |= NXGE_CLASS_FLOW_USE_SRC_PORT;
if (fcfg.use_daddr)
ccfg |= NXGE_CLASS_FLOW_USE_IPDST;
if (fcfg.use_saddr)
ccfg |= NXGE_CLASS_FLOW_USE_IPSRC;
if (fcfg.use_vlan)
ccfg |= NXGE_CLASS_FLOW_USE_VLAN;
if (fcfg.use_l2da)
ccfg |= NXGE_CLASS_FLOW_USE_L2DA;
if (fcfg.use_portnum)
ccfg |= NXGE_CLASS_FLOW_USE_PORTNUM;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" nxge_cfg_ip_cls_flow_key_get %x", ccfg));
*class_config = ccfg;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" <== nxge_cfg_ip_cls_flow_key_get"));
return (NXGE_OK);
}
static nxge_status_t
nxge_cfg_tcam_ip_class_get(p_nxge_t nxgep, tcam_class_t class,
uint32_t *class_config)
{
npi_status_t rs = NPI_SUCCESS;
tcam_key_cfg_t cfg;
npi_handle_t handle;
uint32_t ccfg = 0;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_cfg_tcam_ip_class"));
bzero(&cfg, sizeof (tcam_key_cfg_t));
handle = nxgep->npi_reg_handle;
rs = npi_fflp_cfg_ip_cls_tcam_key_get(handle, class, &cfg);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, " nxge_cfg_tcam_ip_class"
" opt %x for class %d failed ", class_config, class));
return (NXGE_ERROR | rs);
}
if (cfg.discard)
ccfg |= NXGE_CLASS_DISCARD;
if (cfg.lookup_enable)
ccfg |= NXGE_CLASS_TCAM_LOOKUP;
if (cfg.use_ip_daddr)
ccfg |= NXGE_CLASS_TCAM_USE_SRC_ADDR;
*class_config = ccfg;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" ==> nxge_cfg_tcam_ip_class %x", ccfg));
return (NXGE_OK);
}
static nxge_status_t
nxge_cfg_tcam_ip_class(p_nxge_t nxgep, tcam_class_t class,
uint32_t class_config)
{
npi_status_t rs = NPI_SUCCESS;
tcam_key_cfg_t cfg;
npi_handle_t handle;
p_nxge_class_pt_cfg_t p_class_cfgp;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_cfg_tcam_ip_class"));
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
p_class_cfgp->class_cfg[class] = class_config;
bzero(&cfg, sizeof (tcam_key_cfg_t));
handle = nxgep->npi_reg_handle;
cfg.discard = 0;
cfg.lookup_enable = 0;
cfg.use_ip_daddr = 0;
if (class_config & NXGE_CLASS_DISCARD)
cfg.discard = 1;
if (class_config & NXGE_CLASS_TCAM_LOOKUP)
cfg.lookup_enable = 1;
if (class_config & NXGE_CLASS_TCAM_USE_SRC_ADDR)
cfg.use_ip_daddr = 1;
rs = npi_fflp_cfg_ip_cls_tcam_key(handle, class, &cfg);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, " nxge_cfg_tcam_ip_class"
" opt %x for class %d failed ", class_config, class));
return (NXGE_ERROR | rs);
}
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_set_hash1(p_nxge_t nxgep, uint32_t h1)
{
npi_status_t rs = NPI_SUCCESS;
npi_handle_t handle;
p_nxge_class_pt_cfg_t p_class_cfgp;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_fflp_init_h1"));
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
p_class_cfgp->init_h1 = h1;
handle = nxgep->npi_reg_handle;
rs = npi_fflp_cfg_hash_h1poly(handle, h1);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_init_h1 %x failed ", h1));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " <== nxge_fflp_init_h1"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_set_hash2(p_nxge_t nxgep, uint16_t h2)
{
npi_status_t rs = NPI_SUCCESS;
npi_handle_t handle;
p_nxge_class_pt_cfg_t p_class_cfgp;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_fflp_init_h2"));
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
p_class_cfgp->init_h2 = h2;
handle = nxgep->npi_reg_handle;
rs = npi_fflp_cfg_hash_h2poly(handle, h2);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_init_h2 %x failed ", h2));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " <== nxge_fflp_init_h2"));
return (NXGE_OK);
}
nxge_status_t
nxge_classify_init_sw(p_nxge_t nxgep)
{
nxge_classify_t *classify_ptr;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_classify_init_sw"));
classify_ptr = &nxgep->classifier;
if (classify_ptr->state & NXGE_FFLP_SW_INIT) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"nxge_classify_init_sw already init"));
return (NXGE_OK);
}
classify_ptr->tcam_size = nxgep->nxge_hw_p->tcam_size / nxgep->nports;
classify_ptr->tcam_entries = (tcam_flow_spec_t *)nxgep->nxge_hw_p->tcam;
classify_ptr->tcam_top = nxgep->function_num;
/* Init defaults */
/*
* add hacks required for HW shortcomings for example, code to handle
* fragmented packets
*/
nxge_init_h1_table();
nxge_crc_ccitt_init();
nxgep->classifier.tcam_location = nxgep->function_num;
nxgep->classifier.fragment_bug = 1;
classify_ptr->state |= NXGE_FFLP_SW_INIT;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_classify_init_sw"));
return (NXGE_OK);
}
nxge_status_t
nxge_classify_exit_sw(p_nxge_t nxgep)
{
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_classify_exit_sw"));
nxgep->classifier.state = 0;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_classify_exit_sw"));
return (NXGE_OK);
}
/*
* Figures out the RDC Group for the entry
*
* The current implementation is just a place holder and it
* returns 0.
* The real location determining algorithm would consider
* the partition etc ... before deciding w
*
*/
/* ARGSUSED */
static uint8_t
nxge_get_rdc_group(p_nxge_t nxgep, uint8_t class, uint64_t cookie)
{
int use_port_rdc_grp = 0;
uint8_t rdc_grp = 0;
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_dma_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_dma_cfgp->hw_config;
rdc_grp_p = &p_dma_cfgp->rdc_grps[use_port_rdc_grp];
rdc_grp = p_cfgp->def_mac_rxdma_grpid;
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_get_rdc_group: grp 0x%x real_grp %x grpp $%p\n",
cookie, rdc_grp, rdc_grp_p));
return (rdc_grp);
}
/* ARGSUSED */
static uint8_t
nxge_get_rdc_offset(p_nxge_t nxgep, uint8_t class, uint64_t cookie)
{
return ((uint8_t)cookie);
}
/* ARGSUSED */
static void
nxge_fill_tcam_entry_udp(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
udpip4_spec_t *fspec_key;
udpip4_spec_t *fspec_mask;
fspec_key = (udpip4_spec_t *)&flow_spec->uh.udpip4spec;
fspec_mask = (udpip4_spec_t *)&flow_spec->um.udpip4spec;
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_key, fspec_key->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_mask, fspec_mask->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_key, fspec_key->ip4src);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_mask, fspec_mask->ip4src);
TCAM_IP_PORTS(tcam_ptr->ip4_port_key,
fspec_key->pdst, fspec_key->psrc);
TCAM_IP_PORTS(tcam_ptr->ip4_port_mask,
fspec_mask->pdst, fspec_mask->psrc);
TCAM_IP_CLASS(tcam_ptr->ip4_class_key,
tcam_ptr->ip4_class_mask,
TCAM_CLASS_UDP_IPV4);
TCAM_IP_PROTO(tcam_ptr->ip4_proto_key,
tcam_ptr->ip4_proto_mask,
IPPROTO_UDP);
tcam_ptr->ip4_tos_key = fspec_key->tos;
tcam_ptr->ip4_tos_mask = fspec_mask->tos;
}
static void
nxge_fill_tcam_entry_udp_ipv6(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
udpip6_spec_t *fspec_key;
udpip6_spec_t *fspec_mask;
p_nxge_class_pt_cfg_t p_class_cfgp;
fspec_key = (udpip6_spec_t *)&flow_spec->uh.udpip6spec;
fspec_mask = (udpip6_spec_t *)&flow_spec->um.udpip6spec;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
if (p_class_cfgp->class_cfg[TCAM_CLASS_UDP_IPV6] &
NXGE_CLASS_TCAM_USE_SRC_ADDR) {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6src);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6src);
} else {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6dst);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6dst);
}
TCAM_IP_CLASS(tcam_ptr->ip6_class_key,
tcam_ptr->ip6_class_mask, TCAM_CLASS_UDP_IPV6);
TCAM_IP_PROTO(tcam_ptr->ip6_nxt_hdr_key,
tcam_ptr->ip6_nxt_hdr_mask, IPPROTO_UDP);
TCAM_IP_PORTS(tcam_ptr->ip6_port_key,
fspec_key->pdst, fspec_key->psrc);
TCAM_IP_PORTS(tcam_ptr->ip6_port_mask,
fspec_mask->pdst, fspec_mask->psrc);
tcam_ptr->ip6_tos_key = fspec_key->tos;
tcam_ptr->ip6_tos_mask = fspec_mask->tos;
}
/* ARGSUSED */
static void
nxge_fill_tcam_entry_tcp(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
tcpip4_spec_t *fspec_key;
tcpip4_spec_t *fspec_mask;
fspec_key = (tcpip4_spec_t *)&flow_spec->uh.tcpip4spec;
fspec_mask = (tcpip4_spec_t *)&flow_spec->um.tcpip4spec;
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_key, fspec_key->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_mask, fspec_mask->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_key, fspec_key->ip4src);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_mask, fspec_mask->ip4src);
TCAM_IP_PORTS(tcam_ptr->ip4_port_key,
fspec_key->pdst, fspec_key->psrc);
TCAM_IP_PORTS(tcam_ptr->ip4_port_mask,
fspec_mask->pdst, fspec_mask->psrc);
TCAM_IP_CLASS(tcam_ptr->ip4_class_key,
tcam_ptr->ip4_class_mask, TCAM_CLASS_TCP_IPV4);
TCAM_IP_PROTO(tcam_ptr->ip4_proto_key,
tcam_ptr->ip4_proto_mask, IPPROTO_TCP);
tcam_ptr->ip4_tos_key = fspec_key->tos;
tcam_ptr->ip4_tos_mask = fspec_mask->tos;
}
/* ARGSUSED */
static void
nxge_fill_tcam_entry_sctp(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
tcpip4_spec_t *fspec_key;
tcpip4_spec_t *fspec_mask;
fspec_key = (tcpip4_spec_t *)&flow_spec->uh.tcpip4spec;
fspec_mask = (tcpip4_spec_t *)&flow_spec->um.tcpip4spec;
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_key, fspec_key->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_mask, fspec_mask->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_key, fspec_key->ip4src);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_mask, fspec_mask->ip4src);
TCAM_IP_CLASS(tcam_ptr->ip4_class_key,
tcam_ptr->ip4_class_mask, TCAM_CLASS_SCTP_IPV4);
TCAM_IP_PROTO(tcam_ptr->ip4_proto_key,
tcam_ptr->ip4_proto_mask, IPPROTO_SCTP);
TCAM_IP_PORTS(tcam_ptr->ip4_port_key,
fspec_key->pdst, fspec_key->psrc);
TCAM_IP_PORTS(tcam_ptr->ip4_port_mask,
fspec_mask->pdst, fspec_mask->psrc);
tcam_ptr->ip4_tos_key = fspec_key->tos;
tcam_ptr->ip4_tos_mask = fspec_mask->tos;
}
static void
nxge_fill_tcam_entry_tcp_ipv6(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
tcpip6_spec_t *fspec_key;
tcpip6_spec_t *fspec_mask;
p_nxge_class_pt_cfg_t p_class_cfgp;
fspec_key = (tcpip6_spec_t *)&flow_spec->uh.tcpip6spec;
fspec_mask = (tcpip6_spec_t *)&flow_spec->um.tcpip6spec;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
if (p_class_cfgp->class_cfg[TCAM_CLASS_UDP_IPV6] &
NXGE_CLASS_TCAM_USE_SRC_ADDR) {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6src);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6src);
} else {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6dst);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6dst);
}
TCAM_IP_CLASS(tcam_ptr->ip6_class_key,
tcam_ptr->ip6_class_mask, TCAM_CLASS_TCP_IPV6);
TCAM_IP_PROTO(tcam_ptr->ip6_nxt_hdr_key,
tcam_ptr->ip6_nxt_hdr_mask, IPPROTO_TCP);
TCAM_IP_PORTS(tcam_ptr->ip6_port_key,
fspec_key->pdst, fspec_key->psrc);
TCAM_IP_PORTS(tcam_ptr->ip6_port_mask,
fspec_mask->pdst, fspec_mask->psrc);
tcam_ptr->ip6_tos_key = fspec_key->tos;
tcam_ptr->ip6_tos_mask = fspec_mask->tos;
}
static void
nxge_fill_tcam_entry_sctp_ipv6(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
tcpip6_spec_t *fspec_key;
tcpip6_spec_t *fspec_mask;
p_nxge_class_pt_cfg_t p_class_cfgp;
fspec_key = (tcpip6_spec_t *)&flow_spec->uh.tcpip6spec;
fspec_mask = (tcpip6_spec_t *)&flow_spec->um.tcpip6spec;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
if (p_class_cfgp->class_cfg[TCAM_CLASS_UDP_IPV6] &
NXGE_CLASS_TCAM_USE_SRC_ADDR) {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6src);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6src);
} else {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6dst);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6dst);
}
TCAM_IP_CLASS(tcam_ptr->ip6_class_key,
tcam_ptr->ip6_class_mask, TCAM_CLASS_SCTP_IPV6);
TCAM_IP_PROTO(tcam_ptr->ip6_nxt_hdr_key,
tcam_ptr->ip6_nxt_hdr_mask, IPPROTO_SCTP);
TCAM_IP_PORTS(tcam_ptr->ip6_port_key,
fspec_key->pdst, fspec_key->psrc);
TCAM_IP_PORTS(tcam_ptr->ip6_port_mask,
fspec_mask->pdst, fspec_mask->psrc);
tcam_ptr->ip6_tos_key = fspec_key->tos;
tcam_ptr->ip6_tos_mask = fspec_mask->tos;
}
/* ARGSUSED */
static void
nxge_fill_tcam_entry_ah_esp(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
ahip4_spec_t *fspec_key;
ahip4_spec_t *fspec_mask;
fspec_key = (ahip4_spec_t *)&flow_spec->uh.ahip4spec;
fspec_mask = (ahip4_spec_t *)&flow_spec->um.ahip4spec;
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_key, fspec_key->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_mask, fspec_mask->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_key, fspec_key->ip4src);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_mask, fspec_mask->ip4src);
tcam_ptr->ip4_port_key = fspec_key->spi;
tcam_ptr->ip4_port_mask = fspec_mask->spi;
TCAM_IP_CLASS(tcam_ptr->ip4_class_key,
tcam_ptr->ip4_class_mask,
TCAM_CLASS_AH_ESP_IPV4);
if (flow_spec->flow_type == FSPEC_AHIP4) {
TCAM_IP_PROTO(tcam_ptr->ip4_proto_key,
tcam_ptr->ip4_proto_mask, IPPROTO_AH);
} else {
TCAM_IP_PROTO(tcam_ptr->ip4_proto_key,
tcam_ptr->ip4_proto_mask, IPPROTO_ESP);
}
tcam_ptr->ip4_tos_key = fspec_key->tos;
tcam_ptr->ip4_tos_mask = fspec_mask->tos;
}
static void
nxge_fill_tcam_entry_ah_esp_ipv6(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr)
{
ahip6_spec_t *fspec_key;
ahip6_spec_t *fspec_mask;
p_nxge_class_pt_cfg_t p_class_cfgp;
fspec_key = (ahip6_spec_t *)&flow_spec->uh.ahip6spec;
fspec_mask = (ahip6_spec_t *)&flow_spec->um.ahip6spec;
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
if (p_class_cfgp->class_cfg[TCAM_CLASS_AH_ESP_IPV6] &
NXGE_CLASS_TCAM_USE_SRC_ADDR) {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6src);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6src);
} else {
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_key, fspec_key->ip6dst);
TCAM_IPV6_ADDR(tcam_ptr->ip6_ip_addr_mask, fspec_mask->ip6dst);
}
TCAM_IP_CLASS(tcam_ptr->ip6_class_key,
tcam_ptr->ip6_class_mask, TCAM_CLASS_AH_ESP_IPV6);
if (flow_spec->flow_type == FSPEC_AHIP6) {
TCAM_IP_PROTO(tcam_ptr->ip6_nxt_hdr_key,
tcam_ptr->ip6_nxt_hdr_mask, IPPROTO_AH);
} else {
TCAM_IP_PROTO(tcam_ptr->ip6_nxt_hdr_key,
tcam_ptr->ip6_nxt_hdr_mask, IPPROTO_ESP);
}
tcam_ptr->ip6_port_key = fspec_key->spi;
tcam_ptr->ip6_port_mask = fspec_mask->spi;
tcam_ptr->ip6_tos_key = fspec_key->tos;
tcam_ptr->ip6_tos_mask = fspec_mask->tos;
}
/* ARGSUSED */
static void
nxge_fill_tcam_entry_ip_usr(p_nxge_t nxgep, flow_spec_t *flow_spec,
tcam_entry_t *tcam_ptr, tcam_class_t class)
{
ip_user_spec_t *fspec_key;
ip_user_spec_t *fspec_mask;
fspec_key = (ip_user_spec_t *)&flow_spec->uh.ip_usr_spec;
fspec_mask = (ip_user_spec_t *)&flow_spec->um.ip_usr_spec;
if (fspec_key->ip_ver == FSPEC_IP4) {
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_key, fspec_key->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_dest_mask, fspec_mask->ip4dst);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_key, fspec_key->ip4src);
TCAM_IPV4_ADDR(tcam_ptr->ip4_src_mask, fspec_mask->ip4src);
tcam_ptr->ip4_port_key = fspec_key->l4_4_bytes;
tcam_ptr->ip4_port_mask = fspec_mask->l4_4_bytes;
TCAM_IP_CLASS(tcam_ptr->ip4_class_key,
tcam_ptr->ip4_class_mask, class);
tcam_ptr->ip4_proto_key = fspec_key->proto;
tcam_ptr->ip4_proto_mask = fspec_mask->proto;
tcam_ptr->ip4_tos_key = fspec_key->tos;
tcam_ptr->ip4_tos_mask = fspec_mask->tos;
}
}
nxge_status_t
nxge_flow_get_hash(p_nxge_t nxgep, flow_resource_t *flow_res,
uint32_t *H1, uint16_t *H2)
{
flow_spec_t *flow_spec;
uint32_t class_cfg;
flow_template_t ft;
p_nxge_class_pt_cfg_t p_class_cfgp;
int ft_size = sizeof (flow_template_t);
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_flow_get_hash"));
flow_spec = (flow_spec_t *)&flow_res->flow_spec;
bzero((char *)&ft, ft_size);
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
switch (flow_spec->flow_type) {
case FSPEC_TCPIP4:
class_cfg = p_class_cfgp->class_cfg[TCAM_CLASS_TCP_IPV4];
if (class_cfg & NXGE_CLASS_FLOW_USE_PROTO)
ft.ip_proto = IPPROTO_TCP;
if (class_cfg & NXGE_CLASS_FLOW_USE_IPSRC)
ft.ip4_saddr = flow_res->flow_spec.uh.tcpip4spec.ip4src;
if (class_cfg & NXGE_CLASS_FLOW_USE_IPDST)
ft.ip4_daddr = flow_res->flow_spec.uh.tcpip4spec.ip4dst;
if (class_cfg & NXGE_CLASS_FLOW_USE_SRC_PORT)
ft.ip_src_port = flow_res->flow_spec.uh.tcpip4spec.psrc;
if (class_cfg & NXGE_CLASS_FLOW_USE_DST_PORT)
ft.ip_dst_port = flow_res->flow_spec.uh.tcpip4spec.pdst;
break;
case FSPEC_UDPIP4:
class_cfg = p_class_cfgp->class_cfg[TCAM_CLASS_UDP_IPV4];
if (class_cfg & NXGE_CLASS_FLOW_USE_PROTO)
ft.ip_proto = IPPROTO_UDP;
if (class_cfg & NXGE_CLASS_FLOW_USE_IPSRC)
ft.ip4_saddr = flow_res->flow_spec.uh.udpip4spec.ip4src;
if (class_cfg & NXGE_CLASS_FLOW_USE_IPDST)
ft.ip4_daddr = flow_res->flow_spec.uh.udpip4spec.ip4dst;
if (class_cfg & NXGE_CLASS_FLOW_USE_SRC_PORT)
ft.ip_src_port = flow_res->flow_spec.uh.udpip4spec.psrc;
if (class_cfg & NXGE_CLASS_FLOW_USE_DST_PORT)
ft.ip_dst_port = flow_res->flow_spec.uh.udpip4spec.pdst;
break;
default:
return (NXGE_ERROR);
}
*H1 = nxge_compute_h1(p_class_cfgp->init_h1,
(uint32_t *)&ft, ft_size) & 0xfffff;
*H2 = nxge_compute_h2(p_class_cfgp->init_h2,
(uint8_t *)&ft, ft_size);
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_flow_get_hash"));
return (NXGE_OK);
}
nxge_status_t
nxge_add_fcram_entry(p_nxge_t nxgep, flow_resource_t *flow_res)
{
uint32_t H1;
uint16_t H2;
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_add_fcram_entry"));
status = nxge_flow_get_hash(nxgep, flow_res, &H1, &H2);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_add_fcram_entry failed "));
return (status);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_add_fcram_entry"));
return (NXGE_OK);
}
/*
* Already decided this flow goes into the tcam
*/
nxge_status_t
nxge_add_tcam_entry(p_nxge_t nxgep, flow_resource_t *flow_res)
{
npi_handle_t handle;
uint64_t channel_cookie;
uint64_t flow_cookie;
flow_spec_t *flow_spec;
npi_status_t rs = NPI_SUCCESS;
tcam_entry_t tcam_ptr;
tcam_location_t location;
uint8_t offset, rdc_grp;
p_nxge_hw_list_t hw_p;
uint64_t class;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_add_tcam_entry"));
handle = nxgep->npi_reg_handle;
bzero((void *)&tcam_ptr, sizeof (tcam_entry_t));
flow_spec = (flow_spec_t *)&flow_res->flow_spec;
flow_cookie = flow_res->flow_cookie;
channel_cookie = flow_res->channel_cookie;
location = (tcam_location_t)nxge_tcam_get_index(nxgep,
(uint16_t)flow_res->location);
if ((hw_p = nxgep->nxge_hw_p) == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_add_tcam_entry: common hardware not set",
nxgep->niu_type));
return (NXGE_ERROR);
}
if (flow_spec->flow_type == FSPEC_IP_USR) {
int i;
int add_usr_cls = 0;
int ipv6 = 0;
ip_user_spec_t *uspec = &flow_spec->uh.ip_usr_spec;
ip_user_spec_t *umask = &flow_spec->um.ip_usr_spec;
nxge_usr_l3_cls_t *l3_ucls_p;
MUTEX_ENTER(&hw_p->nxge_tcam_lock);
for (i = 0; i < NXGE_L3_PROG_CLS; i++) {
l3_ucls_p = &hw_p->tcam_l3_prog_cls[i];
if (l3_ucls_p->valid && l3_ucls_p->tcam_ref_cnt) {
if (uspec->proto == l3_ucls_p->pid) {
class = l3_ucls_p->cls;
l3_ucls_p->tcam_ref_cnt++;
add_usr_cls = 1;
break;
}
} else if (l3_ucls_p->valid == 0) {
/* Program new user IP class */
switch (i) {
case 0:
class = TCAM_CLASS_IP_USER_4;
break;
case 1:
class = TCAM_CLASS_IP_USER_5;
break;
case 2:
class = TCAM_CLASS_IP_USER_6;
break;
case 3:
class = TCAM_CLASS_IP_USER_7;
break;
default:
break;
}
if (uspec->ip_ver == FSPEC_IP6)
ipv6 = 1;
rs = npi_fflp_cfg_ip_usr_cls_set(handle,
(tcam_class_t)class, uspec->tos,
umask->tos, uspec->proto, ipv6);
if (rs != NPI_SUCCESS)
goto fail;
rs = npi_fflp_cfg_ip_usr_cls_enable(handle,
(tcam_class_t)class);
if (rs != NPI_SUCCESS)
goto fail;
l3_ucls_p->cls = class;
l3_ucls_p->pid = uspec->proto;
l3_ucls_p->tcam_ref_cnt++;
l3_ucls_p->valid = 1;
add_usr_cls = 1;
break;
} else if (l3_ucls_p->tcam_ref_cnt == 0 &&
uspec->proto == l3_ucls_p->pid) {
/*
* The class has already been programmed,
* probably for flow hash
*/
class = l3_ucls_p->cls;
if (uspec->ip_ver == FSPEC_IP6)
ipv6 = 1;
rs = npi_fflp_cfg_ip_usr_cls_set(handle,
(tcam_class_t)class, uspec->tos,
umask->tos, uspec->proto, ipv6);
if (rs != NPI_SUCCESS)
goto fail;
rs = npi_fflp_cfg_ip_usr_cls_enable(handle,
(tcam_class_t)class);
if (rs != NPI_SUCCESS)
goto fail;
l3_ucls_p->pid = uspec->proto;
l3_ucls_p->tcam_ref_cnt++;
add_usr_cls = 1;
break;
}
}
if (!add_usr_cls) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_add_tcam_entry: Could not find/insert class"
"for pid %d", uspec->proto));
goto fail;
}
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
}
switch (flow_spec->flow_type) {
case FSPEC_TCPIP4:
nxge_fill_tcam_entry_tcp(nxgep, flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep, TCAM_CLASS_TCP_IPV4,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep, TCAM_CLASS_TCP_IPV4,
channel_cookie);
break;
case FSPEC_UDPIP4:
nxge_fill_tcam_entry_udp(nxgep, flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep,
TCAM_CLASS_UDP_IPV4,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep,
TCAM_CLASS_UDP_IPV4,
channel_cookie);
break;
case FSPEC_TCPIP6:
nxge_fill_tcam_entry_tcp_ipv6(nxgep,
flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep, TCAM_CLASS_TCP_IPV6,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep, TCAM_CLASS_TCP_IPV6,
channel_cookie);
break;
case FSPEC_UDPIP6:
nxge_fill_tcam_entry_udp_ipv6(nxgep,
flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep,
TCAM_CLASS_UDP_IPV6,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep,
TCAM_CLASS_UDP_IPV6,
channel_cookie);
break;
case FSPEC_SCTPIP4:
nxge_fill_tcam_entry_sctp(nxgep, flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep,
TCAM_CLASS_SCTP_IPV4,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep,
TCAM_CLASS_SCTP_IPV4,
channel_cookie);
break;
case FSPEC_SCTPIP6:
nxge_fill_tcam_entry_sctp_ipv6(nxgep,
flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep,
TCAM_CLASS_SCTP_IPV6,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep,
TCAM_CLASS_SCTP_IPV6,
channel_cookie);
break;
case FSPEC_AHIP4:
case FSPEC_ESPIP4:
nxge_fill_tcam_entry_ah_esp(nxgep, flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep,
TCAM_CLASS_AH_ESP_IPV4,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep,
TCAM_CLASS_AH_ESP_IPV4,
channel_cookie);
break;
case FSPEC_AHIP6:
case FSPEC_ESPIP6:
nxge_fill_tcam_entry_ah_esp_ipv6(nxgep,
flow_spec, &tcam_ptr);
rdc_grp = nxge_get_rdc_group(nxgep,
TCAM_CLASS_AH_ESP_IPV6,
flow_cookie);
offset = nxge_get_rdc_offset(nxgep,
TCAM_CLASS_AH_ESP_IPV6,
channel_cookie);
break;
case FSPEC_IP_USR:
nxge_fill_tcam_entry_ip_usr(nxgep, flow_spec, &tcam_ptr,
(tcam_class_t)class);
rdc_grp = nxge_get_rdc_group(nxgep,
(tcam_class_t)class, flow_cookie);
offset = nxge_get_rdc_offset(nxgep,
(tcam_class_t)class, channel_cookie);
break;
default:
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_add_tcam_entry: Unknown flow spec 0x%x",
flow_spec->flow_type));
return (NXGE_ERROR);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" nxge_add_tcam_entry write"
" for location %d offset %d", location, offset));
MUTEX_ENTER(&hw_p->nxge_tcam_lock);
rs = npi_fflp_tcam_entry_write(handle, location, &tcam_ptr);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_add_tcam_entry write"
" failed for location %d", location));
goto fail;
}
tcam_ptr.match_action.value = 0;
tcam_ptr.match_action.bits.ldw.rdctbl = rdc_grp;
tcam_ptr.match_action.bits.ldw.offset = offset;
tcam_ptr.match_action.bits.ldw.tres =
TRES_TERM_OVRD_L2RDC;
if (channel_cookie == NXGE_PKT_DISCARD)
tcam_ptr.match_action.bits.ldw.disc = 1;
rs = npi_fflp_tcam_asc_ram_entry_write(handle,
location, tcam_ptr.match_action.value);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_add_tcam_entry write"
" failed for ASC RAM location %d", location));
goto fail;
}
bcopy((void *) &tcam_ptr,
(void *) &nxgep->classifier.tcam_entries[location].tce,
sizeof (tcam_entry_t));
nxgep->classifier.tcam_entry_cnt++;
nxgep->classifier.tcam_entries[location].valid = 1;
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_add_tcam_entry"));
return (NXGE_OK);
fail:
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_add_tcam_entry FAILED"));
return (NXGE_ERROR);
}
static nxge_status_t
nxge_tcam_handle_ip_fragment(p_nxge_t nxgep)
{
tcam_entry_t tcam_ptr;
tcam_location_t location;
uint8_t class;
uint32_t class_config;
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
p_nxge_hw_list_t hw_p;
nxge_status_t status = NXGE_OK;
handle = nxgep->npi_reg_handle;
class = 0;
bzero((void *)&tcam_ptr, sizeof (tcam_entry_t));
tcam_ptr.ip4_noport_key = 1;
tcam_ptr.ip4_noport_mask = 1;
location = nxgep->function_num;
nxgep->classifier.fragment_bug_location = location;
if ((hw_p = nxgep->nxge_hw_p) == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_tcam_handle_ip_fragment: common hardware not set",
nxgep->niu_type));
return (NXGE_ERROR);
}
MUTEX_ENTER(&hw_p->nxge_tcam_lock);
rs = npi_fflp_tcam_entry_write(handle,
location, &tcam_ptr);
if (rs & NPI_FFLP_ERROR) {
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_tcam_handle_ip_fragment "
" tcam_entry write"
" failed for location %d", location));
return (NXGE_ERROR);
}
tcam_ptr.match_action.bits.ldw.rdctbl = nxgep->class_config.mac_rdcgrp;
tcam_ptr.match_action.bits.ldw.offset = 0; /* use the default */
tcam_ptr.match_action.bits.ldw.tres =
TRES_TERM_USE_OFFSET;
rs = npi_fflp_tcam_asc_ram_entry_write(handle,
location, tcam_ptr.match_action.value);
if (rs & NPI_FFLP_ERROR) {
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_DEBUG_MSG((nxgep,
FFLP_CTL,
" nxge_tcam_handle_ip_fragment "
" tcam_entry write"
" failed for ASC RAM location %d", location));
return (NXGE_ERROR);
}
bcopy((void *) &tcam_ptr,
(void *) &nxgep->classifier.tcam_entries[location].tce,
sizeof (tcam_entry_t));
nxgep->classifier.tcam_entry_cnt++;
nxgep->classifier.tcam_entries[location].valid = 1;
for (class = TCAM_CLASS_TCP_IPV4;
class <= TCAM_CLASS_SCTP_IPV6; class++) {
class_config = nxgep->class_config.class_cfg[class];
class_config |= NXGE_CLASS_TCAM_LOOKUP;
status = nxge_fflp_ip_class_config(nxgep, class, class_config);
if (status & NPI_FFLP_ERROR) {
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_tcam_handle_ip_fragment "
"nxge_fflp_ip_class_config failed "
" class %d config %x ", class, class_config));
return (NXGE_ERROR);
}
}
rs = npi_fflp_cfg_tcam_enable(handle);
if (rs & NPI_FFLP_ERROR) {
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_tcam_handle_ip_fragment "
" nxge_fflp_config_tcam_enable failed"));
return (NXGE_ERROR);
}
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
return (NXGE_OK);
}
/* ARGSUSED */
static int
nxge_flow_need_hash_lookup(p_nxge_t nxgep, flow_resource_t *flow_res)
{
return (0);
}
nxge_status_t
nxge_add_flow(p_nxge_t nxgep, flow_resource_t *flow_res)
{
int insert_hash = 0;
nxge_status_t status = NXGE_OK;
if (NXGE_IS_VALID_NEPTUNE_TYPE(nxgep)) {
/* determine whether to do TCAM or Hash flow */
insert_hash = nxge_flow_need_hash_lookup(nxgep, flow_res);
}
if (insert_hash) {
status = nxge_add_fcram_entry(nxgep, flow_res);
} else {
status = nxge_add_tcam_entry(nxgep, flow_res);
}
return (status);
}
void
nxge_put_tcam(p_nxge_t nxgep, p_mblk_t mp)
{
flow_resource_t *fs;
fs = (flow_resource_t *)mp->b_rptr;
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_put_tcam addr fs $%p type %x offset %x",
fs, fs->flow_spec.flow_type, fs->channel_cookie));
(void) nxge_add_tcam_entry(nxgep, fs);
}
nxge_status_t
nxge_fflp_config_tcam_enable(p_nxge_t nxgep)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_fflp_config_tcam_enable"));
rs = npi_fflp_cfg_tcam_enable(handle);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_tcam_enable failed"));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " <== nxge_fflp_config_tcam_enable"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_config_tcam_disable(p_nxge_t nxgep)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" ==> nxge_fflp_config_tcam_disable"));
rs = npi_fflp_cfg_tcam_disable(handle);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_tcam_disable failed"));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" <== nxge_fflp_config_tcam_disable"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_config_hash_lookup_enable(p_nxge_t nxgep)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
uint8_t partition;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" ==> nxge_fflp_config_hash_lookup_enable"));
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;
for (partition = 0; partition < NXGE_MAX_RDC_GROUPS; partition++) {
if (p_cfgp->grpids[partition]) {
rs = npi_fflp_cfg_fcram_partition_enable(
handle, partition);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_hash_lookup_enable"
"failed FCRAM partition"
" enable for partition %d ", partition));
return (NXGE_ERROR | rs);
}
}
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" <== nxge_fflp_config_hash_lookup_enable"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_config_hash_lookup_disable(p_nxge_t nxgep)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
uint8_t partition;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" ==> nxge_fflp_config_hash_lookup_disable"));
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;
for (partition = 0; partition < NXGE_MAX_RDC_GROUPS; partition++) {
if (p_cfgp->grpids[partition]) {
rs = npi_fflp_cfg_fcram_partition_disable(handle,
partition);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_hash_lookup_disable"
" failed FCRAM partition"
" disable for partition %d ", partition));
return (NXGE_ERROR | rs);
}
}
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" <== nxge_fflp_config_hash_lookup_disable"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_config_llc_snap_enable(p_nxge_t nxgep)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" ==> nxge_fflp_config_llc_snap_enable"));
rs = npi_fflp_cfg_llcsnap_enable(handle);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_llc_snap_enable failed"));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" <== nxge_fflp_config_llc_snap_enable"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_config_llc_snap_disable(p_nxge_t nxgep)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" ==> nxge_fflp_config_llc_snap_disable"));
rs = npi_fflp_cfg_llcsnap_disable(handle);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_llc_snap_disable failed"));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" <== nxge_fflp_config_llc_snap_disable"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_ip_usr_class_config(p_nxge_t nxgep, tcam_class_t class,
uint32_t config)
{
npi_status_t rs = NPI_SUCCESS;
npi_handle_t handle = nxgep->npi_reg_handle;
uint8_t tos, tos_mask, proto, ver = 0;
uint8_t class_enable = 0;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_ip_usr_class_config"));
tos = (config & NXGE_CLASS_CFG_IP_TOS_MASK) >>
NXGE_CLASS_CFG_IP_TOS_SHIFT;
tos_mask = (config & NXGE_CLASS_CFG_IP_TOS_MASK_MASK) >>
NXGE_CLASS_CFG_IP_TOS_MASK_SHIFT;
proto = (config & NXGE_CLASS_CFG_IP_PROTO_MASK) >>
NXGE_CLASS_CFG_IP_PROTO_SHIFT;
if (config & NXGE_CLASS_CFG_IP_IPV6_MASK)
ver = 1;
if (config & NXGE_CLASS_CFG_IP_ENABLE_MASK)
class_enable = 1;
rs = npi_fflp_cfg_ip_usr_cls_set(handle, class, tos, tos_mask,
proto, ver);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_ip_usr_class_config"
" for class %d failed ", class));
return (NXGE_ERROR | rs);
}
if (class_enable)
rs = npi_fflp_cfg_ip_usr_cls_enable(handle, class);
else
rs = npi_fflp_cfg_ip_usr_cls_disable(handle, class);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_ip_usr_class_config"
" TCAM enable/disable for class %d failed ", class));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_ip_usr_class_config"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_ip_class_config(p_nxge_t nxgep, tcam_class_t class, uint32_t config)
{
uint32_t class_config;
nxge_status_t t_status = NXGE_OK;
nxge_status_t f_status = NXGE_OK;
p_nxge_class_pt_cfg_t p_class_cfgp;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_fflp_ip_class_config"));
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
class_config = p_class_cfgp->class_cfg[class];
if (class_config != config) {
p_class_cfgp->class_cfg[class] = config;
class_config = config;
}
t_status = nxge_cfg_tcam_ip_class(nxgep, class, class_config);
f_status = nxge_cfg_ip_cls_flow_key(nxgep, class, class_config);
if (t_status & NPI_FFLP_ERROR) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" nxge_fflp_ip_class_config %x"
" for class %d tcam failed", config, class));
return (t_status);
}
if (f_status & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_ip_class_config %x"
" for class %d flow key failed", config, class));
return (f_status);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_ip_class_config"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_ip_class_config_get(p_nxge_t nxgep, tcam_class_t class,
uint32_t *config)
{
uint32_t t_class_config, f_class_config;
int t_status = NXGE_OK;
int f_status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, " ==> nxge_fflp_ip_class_config"));
t_class_config = f_class_config = 0;
t_status = nxge_cfg_tcam_ip_class_get(nxgep, class, &t_class_config);
f_status = nxge_cfg_ip_cls_flow_key_get(nxgep, class, &f_class_config);
if (t_status & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_ip_class_config_get "
" for class %d tcam failed", class));
return (t_status);
}
if (f_status & NPI_FFLP_ERROR) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" nxge_fflp_ip_class_config_get "
" for class %d flow key failed", class));
return (f_status);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
" nxge_fflp_ip_class_config tcam %x flow %x",
t_class_config, f_class_config));
*config = t_class_config | f_class_config;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_ip_class_config_get"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_ip_class_config_all(p_nxge_t nxgep)
{
uint32_t class_config;
tcam_class_t class;
#ifdef NXGE_DEBUG
int status = NXGE_OK;
#endif
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_ip_class_config"));
for (class = TCAM_CLASS_TCP_IPV4;
class <= TCAM_CLASS_SCTP_IPV6; class++) {
class_config = nxgep->class_config.class_cfg[class];
#ifndef NXGE_DEBUG
(void) nxge_fflp_ip_class_config(nxgep, class, class_config);
#else
status = nxge_fflp_ip_class_config(nxgep, class, class_config);
if (status & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_fflp_ip_class_config failed "
" class %d config %x ",
class, class_config));
}
#endif
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_ip_class_config"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_config_vlan_table(p_nxge_t nxgep, uint16_t vlan_id)
{
uint8_t port, rdc_grp;
npi_handle_t handle;
npi_status_t rs = NPI_SUCCESS;
uint8_t priority = 1;
p_nxge_mv_cfg_t vlan_table;
p_nxge_class_pt_cfg_t p_class_cfgp;
p_nxge_hw_list_t hw_p;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_config_vlan_table"));
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
handle = nxgep->npi_reg_handle;
vlan_table = p_class_cfgp->vlan_tbl;
port = nxgep->function_num;
if (vlan_table[vlan_id].flag == 0) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_vlan_table"
" vlan id is not configured %d", vlan_id));
return (NXGE_ERROR);
}
if ((hw_p = nxgep->nxge_hw_p) == NULL) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
" nxge_fflp_config_vlan_table:"
" common hardware not set", nxgep->niu_type));
return (NXGE_ERROR);
}
MUTEX_ENTER(&hw_p->nxge_vlan_lock);
rdc_grp = vlan_table[vlan_id].rdctbl;
rs = npi_fflp_cfg_enet_vlan_table_assoc(handle,
port, vlan_id,
rdc_grp, priority);
MUTEX_EXIT(&hw_p->nxge_vlan_lock);
if (rs & NPI_FFLP_ERROR) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_fflp_config_vlan_table failed "
" Port %d vlan_id %d rdc_grp %d",
port, vlan_id, rdc_grp));
return (NXGE_ERROR | rs);
}
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_fflp_config_vlan_table"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_update_hw(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
p_nxge_param_t pa;
uint64_t cfgd_vlans;
uint64_t *val_ptr;
int i;
int num_macs;
uint8_t alt_mac;
nxge_param_map_t *p_map;
p_nxge_mv_cfg_t vlan_table;
p_nxge_class_pt_cfg_t p_class_cfgp;
p_nxge_dma_pt_cfg_t p_all_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_fflp_update_hw"));
p_class_cfgp = (p_nxge_class_pt_cfg_t)&nxgep->class_config;
p_all_cfgp = (p_nxge_dma_pt_cfg_t)&nxgep->pt_config;
p_cfgp = (p_nxge_hw_pt_cfg_t)&p_all_cfgp->hw_config;
status = nxge_fflp_set_hash1(nxgep, p_class_cfgp->init_h1);
if (status != NXGE_OK) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"nxge_fflp_set_hash1 Failed"));
return (NXGE_ERROR);
}
status = nxge_fflp_set_hash2(nxgep, p_class_cfgp->init_h2);
if (status != NXGE_OK) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"nxge_fflp_set_hash2 Failed"));
return (NXGE_ERROR);
}
vlan_table = p_class_cfgp->vlan_tbl;
/* configure vlan tables */
pa = (p_nxge_param_t)&nxgep->param_arr[param_vlan_2rdc_grp];
#if defined(__i386)
val_ptr = (uint64_t *)(uint32_t)pa->value;
#else
val_ptr = (uint64_t *)pa->value;
#endif
cfgd_vlans = ((pa->type & NXGE_PARAM_ARRAY_CNT_MASK) >>
NXGE_PARAM_ARRAY_CNT_SHIFT);
for (i = 0; i < cfgd_vlans; i++) {
p_map = (nxge_param_map_t *)&val_ptr[i];
if (vlan_table[p_map->param_id].flag) {
status = nxge_fflp_config_vlan_table(nxgep,
p_map->param_id);
if (status != NXGE_OK) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"nxge_fflp_config_vlan_table Failed"));
return (NXGE_ERROR);
}
}
}
/* config MAC addresses */
num_macs = p_cfgp->max_macs;
pa = (p_nxge_param_t)&nxgep->param_arr[param_mac_2rdc_grp];
#if defined(__i386)
val_ptr = (uint64_t *)(uint32_t)pa->value;
#else
val_ptr = (uint64_t *)pa->value;
#endif
for (alt_mac = 0; alt_mac < num_macs; alt_mac++) {
if (p_class_cfgp->mac_host_info[alt_mac].flag) {
status = nxge_logical_mac_assign_rdc_table(nxgep,
alt_mac);
if (status != NXGE_OK) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"nxge_logical_mac_assign_rdc_table"
" Failed"));
return (NXGE_ERROR);
}
}
}
/* Config Hash values */
/* config classes */
status = nxge_fflp_ip_class_config_all(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_fflp_ip_class_config_all Failed"));
return (NXGE_ERROR);
}
return (NXGE_OK);
}
nxge_status_t
nxge_classify_init_hw(p_nxge_t nxgep)
{
nxge_status_t status = NXGE_OK;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "==> nxge_classify_init_hw"));
if (nxgep->classifier.state & NXGE_FFLP_HW_INIT) {
NXGE_DEBUG_MSG((nxgep, FFLP_CTL,
"nxge_classify_init_hw already init"));
return (NXGE_OK);
}
/* Now do a real configuration */
status = nxge_fflp_update_hw(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_fflp_update_hw failed"));
return (NXGE_ERROR);
}
/* Init RDC tables? ? who should do that? rxdma or fflp ? */
/* attach rdc table to the MAC port. */
status = nxge_main_mac_assign_rdc_table(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_main_mac_assign_rdc_table failed"));
return (NXGE_ERROR);
}
status = nxge_alt_mcast_mac_assign_rdc_table(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_multicast_mac_assign_rdc_table failed"));
return (NXGE_ERROR);
}
if (nxgep->classifier.fragment_bug == 1) {
status = nxge_tcam_handle_ip_fragment(nxgep);
if (status != NXGE_OK) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_tcam_handle_ip_fragment failed"));
return (NXGE_ERROR);
}
}
nxgep->classifier.state |= NXGE_FFLP_HW_INIT;
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_classify_init_hw"));
return (NXGE_OK);
}
nxge_status_t
nxge_fflp_handle_sys_errors(p_nxge_t nxgep)
{
npi_handle_t handle;
p_nxge_fflp_stats_t statsp;
uint8_t portn, rdc_grp;
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
vlan_par_err_t vlan_err;
tcam_err_t tcam_err;
hash_lookup_err_log1_t fcram1_err;
hash_lookup_err_log2_t fcram2_err;
hash_tbl_data_log_t fcram_err;
handle = nxgep->npi_handle;
statsp = (p_nxge_fflp_stats_t)&nxgep->statsp->fflp_stats;
portn = nxgep->mac.portnum;
/*
* need to read the fflp error registers to figure out what the error
* is
*/
npi_fflp_vlan_error_get(handle, &vlan_err);
npi_fflp_tcam_error_get(handle, &tcam_err);
if (vlan_err.bits.ldw.m_err || vlan_err.bits.ldw.err) {
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" vlan table parity error on port %d"
" addr: 0x%x data: 0x%x",
portn, vlan_err.bits.ldw.addr,
vlan_err.bits.ldw.data));
statsp->vlan_parity_err++;
if (vlan_err.bits.ldw.m_err) {
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" vlan table multiple errors on port %d",
portn));
}
statsp->errlog.vlan = (uint32_t)vlan_err.value;
NXGE_FM_REPORT_ERROR(nxgep, 0, 0,
NXGE_FM_EREPORT_FFLP_VLAN_PAR_ERR);
npi_fflp_vlan_error_clear(handle);
}
if (tcam_err.bits.ldw.err) {
if (tcam_err.bits.ldw.p_ecc != 0) {
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" TCAM ECC error on port %d"
" TCAM entry: 0x%x syndrome: 0x%x",
portn, tcam_err.bits.ldw.addr,
tcam_err.bits.ldw.syndrome));
statsp->tcam_ecc_err++;
} else {
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" TCAM Parity error on port %d"
" addr: 0x%x parity value: 0x%x",
portn, tcam_err.bits.ldw.addr,
tcam_err.bits.ldw.syndrome));
statsp->tcam_parity_err++;
}
if (tcam_err.bits.ldw.mult) {
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" TCAM Multiple errors on port %d", portn));
} else {
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" TCAM PIO error on port %d", portn));
}
statsp->errlog.tcam = (uint32_t)tcam_err.value;
NXGE_FM_REPORT_ERROR(nxgep, 0, 0,
NXGE_FM_EREPORT_FFLP_TCAM_ERR);
npi_fflp_tcam_error_clear(handle);
}
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;
for (rdc_grp = 0; rdc_grp < NXGE_MAX_RDC_GROUPS; rdc_grp++) {
if (p_cfgp->grpids[rdc_grp]) {
npi_fflp_fcram_error_get(handle, &fcram_err, rdc_grp);
if (fcram_err.bits.ldw.pio_err) {
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" FCRAM PIO ECC error on port %d"
" rdc group: %d Hash Table addr: 0x%x"
" syndrome: 0x%x",
portn, rdc_grp,
fcram_err.bits.ldw.fcram_addr,
fcram_err.bits.ldw.syndrome));
statsp->hash_pio_err[rdc_grp]++;
statsp->errlog.hash_pio[rdc_grp] =
(uint32_t)fcram_err.value;
NXGE_FM_REPORT_ERROR(nxgep, 0, 0,
NXGE_FM_EREPORT_FFLP_HASHT_DATA_ERR);
npi_fflp_fcram_error_clear(handle, rdc_grp);
}
}
}
npi_fflp_fcram_error_log1_get(handle, &fcram1_err);
if (fcram1_err.bits.ldw.ecc_err) {
char *multi_str = "";
char *multi_bit_str = "";
npi_fflp_fcram_error_log2_get(handle, &fcram2_err);
if (fcram1_err.bits.ldw.mult_lk) {
multi_str = "multiple";
}
if (fcram1_err.bits.ldw.mult_bit) {
multi_bit_str = "multiple bits";
}
statsp->hash_lookup_err++;
NXGE_ERROR_MSG((nxgep, FFLP_CTL,
" FCRAM %s lookup %s ECC error on port %d"
" H1: 0x%x Subarea: 0x%x Syndrome: 0x%x",
multi_str, multi_bit_str, portn,
fcram2_err.bits.ldw.h1,
fcram2_err.bits.ldw.subarea,
fcram2_err.bits.ldw.syndrome));
NXGE_FM_REPORT_ERROR(nxgep, 0, 0,
NXGE_FM_EREPORT_FFLP_HASHT_LOOKUP_ERR);
}
statsp->errlog.hash_lookup1 = (uint32_t)fcram1_err.value;
statsp->errlog.hash_lookup2 = (uint32_t)fcram2_err.value;
return (NXGE_OK);
}
int
nxge_get_valid_tcam_cnt(p_nxge_t nxgep) {
return ((nxgep->classifier.fragment_bug == 1) ?
nxgep->classifier.tcam_entry_cnt - 1 :
nxgep->classifier.tcam_entry_cnt);
}
int
nxge_rxdma_channel_cnt(p_nxge_t nxgep)
{
p_nxge_dma_pt_cfg_t p_dma_cfgp;
p_nxge_hw_pt_cfg_t p_cfgp;
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;
return (p_cfgp->max_rdcs);
}
/* ARGSUSED */
int
nxge_rxclass_ioctl(p_nxge_t nxgep, queue_t *wq, mblk_t *mp)
{
uint32_t cmd;
rx_class_cfg_t *cfg_info = (rx_class_cfg_t *)mp->b_rptr;
if (nxgep == NULL) {
return (-1);
}
cmd = cfg_info->cmd;
switch (cmd) {
default:
return (-1);
case NXGE_RX_CLASS_GCHAN:
cfg_info->data = nxge_rxdma_channel_cnt(nxgep);
break;
case NXGE_RX_CLASS_GRULE_CNT:
MUTEX_ENTER(&nxgep->nxge_hw_p->nxge_tcam_lock);
cfg_info->rule_cnt = nxge_get_valid_tcam_cnt(nxgep);
MUTEX_EXIT(&nxgep->nxge_hw_p->nxge_tcam_lock);
break;
case NXGE_RX_CLASS_GRULE:
nxge_get_tcam_entry(nxgep, &cfg_info->fs);
break;
case NXGE_RX_CLASS_GRULE_ALL:
nxge_get_tcam_entry_all(nxgep, cfg_info);
break;
case NXGE_RX_CLASS_RULE_DEL:
nxge_del_tcam_entry(nxgep, cfg_info->fs.location);
break;
case NXGE_RX_CLASS_RULE_INS:
(void) nxge_add_tcam_entry(nxgep, &cfg_info->fs);
break;
}
return (0);
}
/* ARGSUSED */
int
nxge_rxhash_ioctl(p_nxge_t nxgep, queue_t *wq, mblk_t *mp)
{
uint32_t cmd;
cfg_cmd_t *cfg_info = (cfg_cmd_t *)mp->b_rptr;
if (nxgep == NULL) {
return (-1);
}
cmd = cfg_info->cmd;
switch (cmd) {
default:
return (-1);
case NXGE_IPTUN_CFG_ADD_CLS:
nxge_add_iptun_class(nxgep, &cfg_info->iptun_cfg,
&cfg_info->class_id);
break;
case NXGE_IPTUN_CFG_SET_HASH:
nxge_cfg_iptun_hash(nxgep, &cfg_info->iptun_cfg,
cfg_info->class_id);
break;
case NXGE_IPTUN_CFG_DEL_CLS:
nxge_del_iptun_class(nxgep, cfg_info->class_id);
break;
case NXGE_IPTUN_CFG_GET_CLS:
nxge_get_iptun_class(nxgep, &cfg_info->iptun_cfg,
cfg_info->class_id);
break;
case NXGE_CLS_CFG_SET_SYM:
nxge_set_ip_cls_sym(nxgep, cfg_info->class_id, cfg_info->sym);
break;
case NXGE_CLS_CFG_GET_SYM:
nxge_get_ip_cls_sym(nxgep, cfg_info->class_id, &cfg_info->sym);
break;
}
return (0);
}
void
nxge_get_tcam_entry_all(p_nxge_t nxgep, rx_class_cfg_t *cfgp)
{
nxge_classify_t *clasp = &nxgep->classifier;
uint16_t n_entries;
int i, j, k;
tcam_flow_spec_t *tcam_entryp;
cfgp->data = clasp->tcam_size;
MUTEX_ENTER(&nxgep->nxge_hw_p->nxge_tcam_lock);
n_entries = cfgp->rule_cnt;
for (i = 0, j = 0; j < cfgp->data; j++) {
k = nxge_tcam_get_index(nxgep, j);
tcam_entryp = &clasp->tcam_entries[k];
if (tcam_entryp->valid != 1)
continue;
cfgp->rule_locs[i] = j;
i++;
};
MUTEX_EXIT(&nxgep->nxge_hw_p->nxge_tcam_lock);
if (n_entries != i) {
/* print warning, this should not happen */
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_get_tcam_entry_all"
"n_entries[%d] != i[%d]!!!", n_entries, i));
}
}
/* Entries for the ports are interleaved in the TCAM */
static uint16_t
nxge_tcam_get_index(p_nxge_t nxgep, uint16_t index)
{
/* One entry reserved for IP fragment rule */
if (index >= (nxgep->classifier.tcam_size - 1))
index = 0;
if (nxgep->classifier.fragment_bug == 1)
index++;
return (nxgep->classifier.tcam_top + (index * nxgep->nports));
}
static uint32_t
nxge_tcam_cls_to_flow(uint32_t class_code) {
switch (class_code) {
case TCAM_CLASS_TCP_IPV4:
return (FSPEC_TCPIP4);
case TCAM_CLASS_UDP_IPV4:
return (FSPEC_UDPIP4);
case TCAM_CLASS_AH_ESP_IPV4:
return (FSPEC_AHIP4);
case TCAM_CLASS_SCTP_IPV4:
return (FSPEC_SCTPIP4);
case TCAM_CLASS_TCP_IPV6:
return (FSPEC_TCPIP6);
case TCAM_CLASS_UDP_IPV6:
return (FSPEC_UDPIP6);
case TCAM_CLASS_AH_ESP_IPV6:
return (FSPEC_AHIP6);
case TCAM_CLASS_SCTP_IPV6:
return (FSPEC_SCTPIP6);
case TCAM_CLASS_IP_USER_4:
case TCAM_CLASS_IP_USER_5:
case TCAM_CLASS_IP_USER_6:
case TCAM_CLASS_IP_USER_7:
return (FSPEC_IP_USR);
default:
NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL, "nxge_tcam_cls_to_flow"
": Unknown class code [0x%x]", class_code));
break;
}
return (0);
}
void
nxge_get_tcam_entry(p_nxge_t nxgep, flow_resource_t *fs)
{
uint16_t index;
tcam_flow_spec_t *tcam_ep;
tcam_entry_t *tp;
flow_spec_t *fspec;
tcpip4_spec_t *fspec_key;
tcpip4_spec_t *fspec_mask;
index = nxge_tcam_get_index(nxgep, (uint16_t)fs->location);
tcam_ep = &nxgep->classifier.tcam_entries[index];
if (tcam_ep->valid != 1) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_get_tcam_entry: :"
"Entry [%d] invalid for index [%d]", fs->location, index));
return;
}
/* Fill the flow spec entry */
tp = &tcam_ep->tce;
fspec = &fs->flow_spec;
fspec->flow_type = nxge_tcam_cls_to_flow(tp->ip4_class_key);
/* TODO - look at proto field to differentiate between AH and ESP */
if (fspec->flow_type == FSPEC_AHIP4) {
if (tp->ip4_proto_key == IPPROTO_ESP)
fspec->flow_type = FSPEC_ESPIP4;
}
switch (tp->ip4_class_key) {
case TCAM_CLASS_TCP_IPV4:
case TCAM_CLASS_UDP_IPV4:
case TCAM_CLASS_AH_ESP_IPV4:
case TCAM_CLASS_SCTP_IPV4:
fspec_key = (tcpip4_spec_t *)&fspec->uh.tcpip4spec;
fspec_mask = (tcpip4_spec_t *)&fspec->um.tcpip4spec;
FSPEC_IPV4_ADDR(fspec_key->ip4dst, tp->ip4_dest_key);
FSPEC_IPV4_ADDR(fspec_mask->ip4dst, tp->ip4_dest_mask);
FSPEC_IPV4_ADDR(fspec_key->ip4src, tp->ip4_src_key);
FSPEC_IPV4_ADDR(fspec_mask->ip4src, tp->ip4_src_mask);
fspec_key->tos = tp->ip4_tos_key;
fspec_mask->tos = tp->ip4_tos_mask;
break;
default:
break;
}
switch (tp->ip4_class_key) {
case TCAM_CLASS_TCP_IPV4:
case TCAM_CLASS_UDP_IPV4:
case TCAM_CLASS_SCTP_IPV4:
FSPEC_IP_PORTS(fspec_key->pdst, fspec_key->psrc,
tp->ip4_port_key);
FSPEC_IP_PORTS(fspec_mask->pdst, fspec_mask->psrc,
tp->ip4_port_mask);
break;
case TCAM_CLASS_AH_ESP_IPV4:
fspec->uh.ahip4spec.spi = tp->ip4_port_key;
fspec->um.ahip4spec.spi = tp->ip4_port_mask;
break;
case TCAM_CLASS_IP_USER_4:
case TCAM_CLASS_IP_USER_5:
case TCAM_CLASS_IP_USER_6:
case TCAM_CLASS_IP_USER_7:
fspec->uh.ip_usr_spec.l4_4_bytes = tp->ip4_port_key;
fspec->um.ip_usr_spec.l4_4_bytes = tp->ip4_port_mask;
fspec->uh.ip_usr_spec.ip_ver = FSPEC_IP4;
fspec->uh.ip_usr_spec.proto = tp->ip4_proto_key;
fspec->um.ip_usr_spec.proto = tp->ip4_proto_mask;
break;
default:
break;
}
if (tp->match_action.bits.ldw.disc == 1) {
fs->channel_cookie = NXGE_PKT_DISCARD;
} else {
fs->channel_cookie = tp->match_action.bits.ldw.offset;
}
}
void
nxge_del_tcam_entry(p_nxge_t nxgep, uint32_t location)
{
npi_status_t rs = NPI_SUCCESS;
uint16_t index;
tcam_flow_spec_t *tcam_ep;
tcam_entry_t *tp;
tcam_class_t class;
MUTEX_ENTER(&nxgep->nxge_hw_p->nxge_tcam_lock);
index = nxge_tcam_get_index(nxgep, (uint16_t)location);
tcam_ep = &nxgep->classifier.tcam_entries[index];
if (tcam_ep->valid != 1) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_del_tcam_entry: :"
"Entry [%d] invalid for index [%d]", location, index));
goto fail;
}
/* Fill the flow spec entry */
tp = &tcam_ep->tce;
class = tp->ip4_class_key;
if (class >= TCAM_CLASS_IP_USER_4 && class <= TCAM_CLASS_IP_USER_7) {
int i;
nxge_usr_l3_cls_t *l3_ucls_p;
p_nxge_hw_list_t hw_p = nxgep->nxge_hw_p;
for (i = 0; i < NXGE_L3_PROG_CLS; i++) {
l3_ucls_p = &hw_p->tcam_l3_prog_cls[i];
if (l3_ucls_p->valid) {
if (l3_ucls_p->cls == class &&
l3_ucls_p->tcam_ref_cnt) {
l3_ucls_p->tcam_ref_cnt--;
if (l3_ucls_p->tcam_ref_cnt > 0)
continue;
/* disable class */
rs = npi_fflp_cfg_ip_usr_cls_disable(
nxgep->npi_reg_handle,
(tcam_class_t)class);
if (rs != NPI_SUCCESS)
goto fail;
l3_ucls_p->cls = 0;
l3_ucls_p->pid = 0;
l3_ucls_p->valid = 0;
break;
}
}
}
if (i == NXGE_L3_PROG_CLS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_del_tcam_entry: Usr class "
"0x%llx not found", (unsigned long long) class));
goto fail;
}
}
rs = npi_fflp_tcam_entry_invalidate(nxgep->npi_reg_handle, index);
if (rs != NPI_SUCCESS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_del_tcam_entry: TCAM invalidate failed "
"at loc %d ", location));
goto fail;
}
nxgep->classifier.tcam_entries[index].valid = 0;
nxgep->classifier.tcam_entry_cnt--;
MUTEX_EXIT(&nxgep->nxge_hw_p->nxge_tcam_lock);
NXGE_DEBUG_MSG((nxgep, FFLP_CTL, "<== nxge_del_tcam_entry"));
return;
fail:
MUTEX_EXIT(&nxgep->nxge_hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"<== nxge_del_tcam_entry FAILED"));
}
static uint8_t
nxge_iptun_pkt_type_to_pid(uint8_t pkt_type)
{
uint8_t pid = 0;
switch (pkt_type) {
case IPTUN_PKT_IPV4:
pid = 4;
break;
case IPTUN_PKT_IPV6:
pid = 41;
break;
case IPTUN_PKT_GRE:
pid = 47;
break;
case IPTUN_PKT_GTP:
pid = 17;
break;
default:
NXGE_ERROR_MSG((NULL, NXGE_ERR_CTL,
"nxge_iptun_pkt_type_to_pid: Unknown pkt type 0x%x",
pkt_type));
break;
}
return (pid);
}
static npi_status_t
nxge_set_iptun_usr_cls_reg(p_nxge_t nxgep, uint64_t class,
iptun_cfg_t *iptunp)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
switch (iptunp->in_pkt_type) {
case IPTUN_PKT_IPV4:
case IPTUN_PKT_IPV6:
rs = npi_fflp_cfg_ip_usr_cls_set_iptun(handle,
(tcam_class_t)class, 0, 0, 0, 0);
break;
case IPTUN_PKT_GRE:
rs = npi_fflp_cfg_ip_usr_cls_set_iptun(handle,
(tcam_class_t)class, iptunp->l4b0_val,
iptunp->l4b0_mask, 0, 0);
break;
case IPTUN_PKT_GTP:
rs = npi_fflp_cfg_ip_usr_cls_set_iptun(handle,
(tcam_class_t)class, 0, 0, iptunp->l4b23_val,
(iptunp->l4b23_sel & 0x01));
break;
default:
rs = NPI_FFLP_TCAM_CLASS_INVALID;
break;
}
return (rs);
}
void
nxge_add_iptun_class(p_nxge_t nxgep, iptun_cfg_t *iptunp,
uint8_t *cls_idp)
{
int i, add_cls;
uint8_t pid;
uint64_t class;
p_nxge_hw_list_t hw_p = nxgep->nxge_hw_p;
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
pid = nxge_iptun_pkt_type_to_pid(iptunp->in_pkt_type);
if (pid == 0)
return;
add_cls = 0;
MUTEX_ENTER(&hw_p->nxge_tcam_lock);
/* Get an user programmable class ID */
for (i = 0; i < NXGE_L3_PROG_CLS; i++) {
if (hw_p->tcam_l3_prog_cls[i].valid == 0) {
/* todo add new usr class reg */
switch (i) {
case 0:
class = TCAM_CLASS_IP_USER_4;
break;
case 1:
class = TCAM_CLASS_IP_USER_5;
break;
case 2:
class = TCAM_CLASS_IP_USER_6;
break;
case 3:
class = TCAM_CLASS_IP_USER_7;
break;
default:
break;
}
rs = npi_fflp_cfg_ip_usr_cls_set(handle,
(tcam_class_t)class, 0, 0, pid, 0);
if (rs != NPI_SUCCESS)
goto fail;
rs = nxge_set_iptun_usr_cls_reg(nxgep, class, iptunp);
if (rs != NPI_SUCCESS)
goto fail;
rs = npi_fflp_cfg_ip_usr_cls_enable(handle,
(tcam_class_t)class);
if (rs != NPI_SUCCESS)
goto fail;
hw_p->tcam_l3_prog_cls[i].cls = class;
hw_p->tcam_l3_prog_cls[i].pid = pid;
hw_p->tcam_l3_prog_cls[i].flow_pkt_type =
iptunp->in_pkt_type;
hw_p->tcam_l3_prog_cls[i].valid = 1;
*cls_idp = (uint8_t)class;
add_cls = 1;
break;
} else if (hw_p->tcam_l3_prog_cls[i].pid == pid) {
if (hw_p->tcam_l3_prog_cls[i].flow_pkt_type == 0) {
/* there is no flow key */
/* todo program the existing usr class reg */
rs = nxge_set_iptun_usr_cls_reg(nxgep, class,
iptunp);
if (rs != NPI_SUCCESS)
goto fail;
rs = npi_fflp_cfg_ip_usr_cls_enable(handle,
(tcam_class_t)class);
if (rs != NPI_SUCCESS)
goto fail;
hw_p->tcam_l3_prog_cls[i].flow_pkt_type =
iptunp->in_pkt_type;
*cls_idp = (uint8_t)class;
add_cls = 1;
} else {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_add_iptun_class: L3 usr "
"programmable class with pid %d "
"already exists", pid));
}
break;
}
}
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
if (add_cls != 1) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_add_iptun_class: Could not add IP tunneling class"));
}
return;
fail:
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_add_iptun_class: FAILED"));
}
static boolean_t
nxge_is_iptun_cls_present(p_nxge_t nxgep, uint8_t cls_id, int *idx)
{
int i;
p_nxge_hw_list_t hw_p = nxgep->nxge_hw_p;
MUTEX_ENTER(&hw_p->nxge_tcam_lock);
for (i = 0; i < NXGE_L3_PROG_CLS; i++) {
if (hw_p->tcam_l3_prog_cls[i].valid &&
hw_p->tcam_l3_prog_cls[i].flow_pkt_type != 0) {
if (hw_p->tcam_l3_prog_cls[i].cls == cls_id)
break;
}
}
MUTEX_EXIT(&hw_p->nxge_tcam_lock);
if (i == NXGE_L3_PROG_CLS) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_is_iptun_cls_present: Invalid class %d", cls_id));
return (B_FALSE);
} else {
*idx = i;
return (B_TRUE);
}
}
void
nxge_cfg_iptun_hash(p_nxge_t nxgep, iptun_cfg_t *iptunp, uint8_t cls_id)
{
int idx;
npi_handle_t handle = nxgep->npi_reg_handle;
flow_key_cfg_t cfg;
/* check to see that this is a valid class ID */
if (!nxge_is_iptun_cls_present(nxgep, cls_id, &idx)) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_cfg_iptun_hash: nxge_is_iptun_cls_present "
"failed for cls_id %d", cls_id));
return;
}
bzero((void *)&cfg, sizeof (flow_key_cfg_t));
/*
* This ensures that all 4 bytes of the XOR value are loaded to the
* hash key.
*/
cfg.use_dport = cfg.use_sport = cfg.ip_opts_exist = 1;
cfg.l4_xor_sel = (iptunp->l4xor_sel & FL_KEY_USR_L4XOR_MSK);
cfg.use_l4_md = 1;
if (iptunp->hash_flags & HASH_L3PROTO)
cfg.use_proto = 1;
else if (iptunp->hash_flags & HASH_IPDA)
cfg.use_daddr = 1;
else if (iptunp->hash_flags & HASH_IPSA)
cfg.use_saddr = 1;
else if (iptunp->hash_flags & HASH_VLAN)
cfg.use_vlan = 1;
else if (iptunp->hash_flags & HASH_L2DA)
cfg.use_l2da = 1;
else if (iptunp->hash_flags & HASH_IFPORT)
cfg.use_portnum = 1;
(void) npi_fflp_cfg_ip_cls_flow_key_rfnl(handle, (tcam_class_t)cls_id,
&cfg);
}
void
nxge_del_iptun_class(p_nxge_t nxgep, uint8_t cls_id)
{
int i;
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
/* check to see that this is a valid class ID */
if (!nxge_is_iptun_cls_present(nxgep, cls_id, &i)) {
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_del_iptun_class: Invalid class ID 0x%x", cls_id));
return;
}
MUTEX_ENTER(&nxgep->nxge_hw_p->nxge_tcam_lock);
rs = npi_fflp_cfg_ip_usr_cls_disable(handle, (tcam_class_t)cls_id);
if (rs != NPI_SUCCESS)
goto fail;
nxgep->nxge_hw_p->tcam_l3_prog_cls[i].flow_pkt_type = 0;
if (nxgep->nxge_hw_p->tcam_l3_prog_cls[i].tcam_ref_cnt == 0)
nxgep->nxge_hw_p->tcam_l3_prog_cls[i].valid = 0;
MUTEX_EXIT(&nxgep->nxge_hw_p->nxge_tcam_lock);
return;
fail:
MUTEX_EXIT(&nxgep->nxge_hw_p->nxge_tcam_lock);
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_del_iptun_class: FAILED"));
}
void
nxge_get_iptun_class(p_nxge_t nxgep, iptun_cfg_t *iptunp, uint8_t cls_id)
{
int i;
uint8_t pid;
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
flow_key_cfg_t cfg;
/* check to see that this is a valid class ID */
if (!nxge_is_iptun_cls_present(nxgep, cls_id, &i))
return;
bzero((void *)iptunp, sizeof (iptun_cfg_t));
pid = nxgep->nxge_hw_p->tcam_l3_prog_cls[i].pid;
rs = npi_fflp_cfg_ip_usr_cls_get_iptun(handle, (tcam_class_t)cls_id,
&iptunp->l4b0_val, &iptunp->l4b0_mask, &iptunp->l4b23_val,
&iptunp->l4b23_sel);
if (rs != NPI_SUCCESS)
goto fail;
rs = npi_fflp_cfg_ip_cls_flow_key_get_rfnl(handle,
(tcam_class_t)cls_id, &cfg);
if (rs != NPI_SUCCESS)
goto fail;
iptunp->l4xor_sel = cfg.l4_xor_sel;
if (cfg.use_proto)
iptunp->hash_flags |= HASH_L3PROTO;
else if (cfg.use_daddr)
iptunp->hash_flags |= HASH_IPDA;
else if (cfg.use_saddr)
iptunp->hash_flags |= HASH_IPSA;
else if (cfg.use_vlan)
iptunp->hash_flags |= HASH_VLAN;
else if (cfg.use_l2da)
iptunp->hash_flags |= HASH_L2DA;
else if (cfg.use_portnum)
iptunp->hash_flags |= HASH_IFPORT;
switch (pid) {
case 4:
iptunp->in_pkt_type = IPTUN_PKT_IPV4;
break;
case 41:
iptunp->in_pkt_type = IPTUN_PKT_IPV6;
break;
case 47:
iptunp->in_pkt_type = IPTUN_PKT_GRE;
break;
case 17:
iptunp->in_pkt_type = IPTUN_PKT_GTP;
break;
default:
iptunp->in_pkt_type = 0;
break;
}
return;
fail:
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_get_iptun_class: FAILED"));
}
void
nxge_set_ip_cls_sym(p_nxge_t nxgep, uint8_t cls_id, uint8_t sym)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
boolean_t sym_en = (sym == 1) ? B_TRUE : B_FALSE;
rs = npi_fflp_cfg_sym_ip_cls_flow_key(handle, (tcam_class_t)cls_id,
sym_en);
if (rs != NPI_SUCCESS)
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
"nxge_set_ip_cls_sym: FAILED"));
}
void
nxge_get_ip_cls_sym(p_nxge_t nxgep, uint8_t cls_id, uint8_t *sym)
{
npi_handle_t handle = nxgep->npi_reg_handle;
npi_status_t rs = NPI_SUCCESS;
flow_key_cfg_t cfg;
rs = npi_fflp_cfg_ip_cls_flow_key_get_rfnl(handle,
(tcam_class_t)cls_id, &cfg);
if (rs != NPI_SUCCESS)
goto fail;
if (cfg.use_sym)
*sym = 1;
else
*sym = 0;
return;
fail:
NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_get_ip_cls_sym: FAILED"));
}
|