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
|
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2024 Intel Corporation */
#include "ice_common.h"
struct ice_pkg_sect_hdr {
__le16 count;
__le16 offset;
};
/**
* ice_parser_sect_item_get - parse an item from a section
* @sect_type: section type
* @section: section object
* @index: index of the item to get
* @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
*
* Return: a pointer to the item or NULL.
*/
static void *ice_parser_sect_item_get(u32 sect_type, void *section,
u32 index, u32 __maybe_unused *offset)
{
size_t data_off = ICE_SEC_DATA_OFFSET;
struct ice_pkg_sect_hdr *hdr;
size_t size;
if (!section)
return NULL;
switch (sect_type) {
case ICE_SID_RXPARSER_IMEM:
size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_METADATA_INIT:
size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_CAM:
size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_PG_SPILL:
size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_NOMATCH_CAM:
size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_NOMATCH_SPILL:
size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_BOOST_TCAM:
size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
break;
case ICE_SID_LBL_RXPARSER_TMEM:
data_off = ICE_SEC_LBL_DATA_OFFSET;
size = ICE_SID_LBL_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_MARKER_PTYPE:
size = ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_MARKER_GRP:
size = ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_PROTO_GRP:
size = ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE;
break;
case ICE_SID_RXPARSER_FLAG_REDIR:
size = ICE_SID_RXPARSER_FLAG_REDIR_ENTRY_SIZE;
break;
default:
return NULL;
}
hdr = section;
if (index >= le16_to_cpu(hdr->count))
return NULL;
return section + data_off + index * size;
}
/**
* ice_parser_create_table - create an item table from a section
* @hw: pointer to the hardware structure
* @sect_type: section type
* @item_size: item size in bytes
* @length: number of items in the table to create
* @parse_item: the function to parse the item
* @no_offset: ignore header offset, calculate index from 0
*
* Return: a pointer to the allocated table or ERR_PTR.
*/
static void *
ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
u32 item_size, u32 length,
void (*parse_item)(struct ice_hw *hw, u16 idx,
void *item, void *data,
int size), bool no_offset)
{
struct ice_pkg_enum state = {};
struct ice_seg *seg = hw->seg;
void *table, *data, *item;
u16 idx = 0;
if (!seg)
return ERR_PTR(-EINVAL);
table = kzalloc(item_size * length, GFP_KERNEL);
if (!table)
return ERR_PTR(-ENOMEM);
do {
data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
ice_parser_sect_item_get);
seg = NULL;
if (data) {
struct ice_pkg_sect_hdr *hdr = state.sect;
if (!no_offset)
idx = le16_to_cpu(hdr->offset) +
state.entry_idx;
item = (void *)((uintptr_t)table + idx * item_size);
parse_item(hw, idx, item, data, item_size);
if (no_offset)
idx++;
}
} while (data);
return table;
}
/*** ICE_SID_RXPARSER_IMEM section ***/
static void ice_imem_bst_bm_dump(struct ice_hw *hw, struct ice_bst_main *bm)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "boost main:\n");
dev_info(dev, "\talu0 = %d\n", bm->alu0);
dev_info(dev, "\talu1 = %d\n", bm->alu1);
dev_info(dev, "\talu2 = %d\n", bm->alu2);
dev_info(dev, "\tpg = %d\n", bm->pg);
}
static void ice_imem_bst_kb_dump(struct ice_hw *hw,
struct ice_bst_keybuilder *kb)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "boost key builder:\n");
dev_info(dev, "\tpriority = %d\n", kb->prio);
dev_info(dev, "\ttsr_ctrl = %d\n", kb->tsr_ctrl);
}
static void ice_imem_np_kb_dump(struct ice_hw *hw,
struct ice_np_keybuilder *kb)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "next proto key builder:\n");
dev_info(dev, "\topc = %d\n", kb->opc);
dev_info(dev, "\tstart_or_reg0 = %d\n", kb->start_reg0);
dev_info(dev, "\tlen_or_reg1 = %d\n", kb->len_reg1);
}
static void ice_imem_pg_kb_dump(struct ice_hw *hw,
struct ice_pg_keybuilder *kb)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "parse graph key builder:\n");
dev_info(dev, "\tflag0_ena = %d\n", kb->flag0_ena);
dev_info(dev, "\tflag1_ena = %d\n", kb->flag1_ena);
dev_info(dev, "\tflag2_ena = %d\n", kb->flag2_ena);
dev_info(dev, "\tflag3_ena = %d\n", kb->flag3_ena);
dev_info(dev, "\tflag0_idx = %d\n", kb->flag0_idx);
dev_info(dev, "\tflag1_idx = %d\n", kb->flag1_idx);
dev_info(dev, "\tflag2_idx = %d\n", kb->flag2_idx);
dev_info(dev, "\tflag3_idx = %d\n", kb->flag3_idx);
dev_info(dev, "\talu_reg_idx = %d\n", kb->alu_reg_idx);
}
static void ice_imem_alu_dump(struct ice_hw *hw,
struct ice_alu *alu, int index)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "alu%d:\n", index);
dev_info(dev, "\topc = %d\n", alu->opc);
dev_info(dev, "\tsrc_start = %d\n", alu->src_start);
dev_info(dev, "\tsrc_len = %d\n", alu->src_len);
dev_info(dev, "\tshift_xlate_sel = %d\n", alu->shift_xlate_sel);
dev_info(dev, "\tshift_xlate_key = %d\n", alu->shift_xlate_key);
dev_info(dev, "\tsrc_reg_id = %d\n", alu->src_reg_id);
dev_info(dev, "\tdst_reg_id = %d\n", alu->dst_reg_id);
dev_info(dev, "\tinc0 = %d\n", alu->inc0);
dev_info(dev, "\tinc1 = %d\n", alu->inc1);
dev_info(dev, "\tproto_offset_opc = %d\n", alu->proto_offset_opc);
dev_info(dev, "\tproto_offset = %d\n", alu->proto_offset);
dev_info(dev, "\tbranch_addr = %d\n", alu->branch_addr);
dev_info(dev, "\timm = %d\n", alu->imm);
dev_info(dev, "\tdst_start = %d\n", alu->dst_start);
dev_info(dev, "\tdst_len = %d\n", alu->dst_len);
dev_info(dev, "\tflags_extr_imm = %d\n", alu->flags_extr_imm);
dev_info(dev, "\tflags_start_imm= %d\n", alu->flags_start_imm);
}
/**
* ice_imem_dump - dump an imem item info
* @hw: pointer to the hardware structure
* @item: imem item to dump
*/
static void ice_imem_dump(struct ice_hw *hw, struct ice_imem_item *item)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "index = %d\n", item->idx);
ice_imem_bst_bm_dump(hw, &item->b_m);
ice_imem_bst_kb_dump(hw, &item->b_kb);
dev_info(dev, "pg priority = %d\n", item->pg_prio);
ice_imem_np_kb_dump(hw, &item->np_kb);
ice_imem_pg_kb_dump(hw, &item->pg_kb);
ice_imem_alu_dump(hw, &item->alu0, 0);
ice_imem_alu_dump(hw, &item->alu1, 1);
ice_imem_alu_dump(hw, &item->alu2, 2);
}
#define ICE_IM_BM_ALU0 BIT(0)
#define ICE_IM_BM_ALU1 BIT(1)
#define ICE_IM_BM_ALU2 BIT(2)
#define ICE_IM_BM_PG BIT(3)
/**
* ice_imem_bm_init - parse 4 bits of Boost Main
* @bm: pointer to the Boost Main structure
* @data: Boost Main data to be parsed
*/
static void ice_imem_bm_init(struct ice_bst_main *bm, u8 data)
{
bm->alu0 = FIELD_GET(ICE_IM_BM_ALU0, data);
bm->alu1 = FIELD_GET(ICE_IM_BM_ALU1, data);
bm->alu2 = FIELD_GET(ICE_IM_BM_ALU2, data);
bm->pg = FIELD_GET(ICE_IM_BM_PG, data);
}
#define ICE_IM_BKB_PRIO GENMASK(7, 0)
#define ICE_IM_BKB_TSR_CTRL BIT(8)
/**
* ice_imem_bkb_init - parse 10 bits of Boost Main Build
* @bkb: pointer to the Boost Main Build structure
* @data: Boost Main Build data to be parsed
*/
static void ice_imem_bkb_init(struct ice_bst_keybuilder *bkb, u16 data)
{
bkb->prio = FIELD_GET(ICE_IM_BKB_PRIO, data);
bkb->tsr_ctrl = FIELD_GET(ICE_IM_BKB_TSR_CTRL, data);
}
#define ICE_IM_NPKB_OPC GENMASK(1, 0)
#define ICE_IM_NPKB_S_R0 GENMASK(9, 2)
#define ICE_IM_NPKB_L_R1 GENMASK(17, 10)
/**
* ice_imem_npkb_init - parse 18 bits of Next Protocol Key Build
* @kb: pointer to the Next Protocol Key Build structure
* @data: Next Protocol Key Build data to be parsed
*/
static void ice_imem_npkb_init(struct ice_np_keybuilder *kb, u32 data)
{
kb->opc = FIELD_GET(ICE_IM_NPKB_OPC, data);
kb->start_reg0 = FIELD_GET(ICE_IM_NPKB_S_R0, data);
kb->len_reg1 = FIELD_GET(ICE_IM_NPKB_L_R1, data);
}
#define ICE_IM_PGKB_F0_ENA BIT_ULL(0)
#define ICE_IM_PGKB_F0_IDX GENMASK_ULL(6, 1)
#define ICE_IM_PGKB_F1_ENA BIT_ULL(7)
#define ICE_IM_PGKB_F1_IDX GENMASK_ULL(13, 8)
#define ICE_IM_PGKB_F2_ENA BIT_ULL(14)
#define ICE_IM_PGKB_F2_IDX GENMASK_ULL(20, 15)
#define ICE_IM_PGKB_F3_ENA BIT_ULL(21)
#define ICE_IM_PGKB_F3_IDX GENMASK_ULL(27, 22)
#define ICE_IM_PGKB_AR_IDX GENMASK_ULL(34, 28)
/**
* ice_imem_pgkb_init - parse 35 bits of Parse Graph Key Build
* @kb: pointer to the Parse Graph Key Build structure
* @data: Parse Graph Key Build data to be parsed
*/
static void ice_imem_pgkb_init(struct ice_pg_keybuilder *kb, u64 data)
{
kb->flag0_ena = FIELD_GET(ICE_IM_PGKB_F0_ENA, data);
kb->flag0_idx = FIELD_GET(ICE_IM_PGKB_F0_IDX, data);
kb->flag1_ena = FIELD_GET(ICE_IM_PGKB_F1_ENA, data);
kb->flag1_idx = FIELD_GET(ICE_IM_PGKB_F1_IDX, data);
kb->flag2_ena = FIELD_GET(ICE_IM_PGKB_F2_ENA, data);
kb->flag2_idx = FIELD_GET(ICE_IM_PGKB_F2_IDX, data);
kb->flag3_ena = FIELD_GET(ICE_IM_PGKB_F3_ENA, data);
kb->flag3_idx = FIELD_GET(ICE_IM_PGKB_F3_IDX, data);
kb->alu_reg_idx = FIELD_GET(ICE_IM_PGKB_AR_IDX, data);
}
#define ICE_IM_ALU_OPC GENMASK_ULL(5, 0)
#define ICE_IM_ALU_SS GENMASK_ULL(13, 6)
#define ICE_IM_ALU_SL GENMASK_ULL(18, 14)
#define ICE_IM_ALU_SXS BIT_ULL(19)
#define ICE_IM_ALU_SXK GENMASK_ULL(23, 20)
#define ICE_IM_ALU_SRID GENMASK_ULL(30, 24)
#define ICE_IM_ALU_DRID GENMASK_ULL(37, 31)
#define ICE_IM_ALU_INC0 BIT_ULL(38)
#define ICE_IM_ALU_INC1 BIT_ULL(39)
#define ICE_IM_ALU_POO GENMASK_ULL(41, 40)
#define ICE_IM_ALU_PO GENMASK_ULL(49, 42)
#define ICE_IM_ALU_BA_S 50 /* offset for the 2nd 64-bits field */
#define ICE_IM_ALU_BA GENMASK_ULL(57 - ICE_IM_ALU_BA_S, \
50 - ICE_IM_ALU_BA_S)
#define ICE_IM_ALU_IMM GENMASK_ULL(73 - ICE_IM_ALU_BA_S, \
58 - ICE_IM_ALU_BA_S)
#define ICE_IM_ALU_DFE BIT_ULL(74 - ICE_IM_ALU_BA_S)
#define ICE_IM_ALU_DS GENMASK_ULL(80 - ICE_IM_ALU_BA_S, \
75 - ICE_IM_ALU_BA_S)
#define ICE_IM_ALU_DL GENMASK_ULL(86 - ICE_IM_ALU_BA_S, \
81 - ICE_IM_ALU_BA_S)
#define ICE_IM_ALU_FEI BIT_ULL(87 - ICE_IM_ALU_BA_S)
#define ICE_IM_ALU_FSI GENMASK_ULL(95 - ICE_IM_ALU_BA_S, \
88 - ICE_IM_ALU_BA_S)
/**
* ice_imem_alu_init - parse 96 bits of ALU entry
* @alu: pointer to the ALU entry structure
* @data: ALU entry data to be parsed
* @off: offset of the ALU entry data
*/
static void ice_imem_alu_init(struct ice_alu *alu, u8 *data, u8 off)
{
u64 d64;
u8 idd;
d64 = *((u64 *)data) >> off;
alu->opc = FIELD_GET(ICE_IM_ALU_OPC, d64);
alu->src_start = FIELD_GET(ICE_IM_ALU_SS, d64);
alu->src_len = FIELD_GET(ICE_IM_ALU_SL, d64);
alu->shift_xlate_sel = FIELD_GET(ICE_IM_ALU_SXS, d64);
alu->shift_xlate_key = FIELD_GET(ICE_IM_ALU_SXK, d64);
alu->src_reg_id = FIELD_GET(ICE_IM_ALU_SRID, d64);
alu->dst_reg_id = FIELD_GET(ICE_IM_ALU_DRID, d64);
alu->inc0 = FIELD_GET(ICE_IM_ALU_INC0, d64);
alu->inc1 = FIELD_GET(ICE_IM_ALU_INC1, d64);
alu->proto_offset_opc = FIELD_GET(ICE_IM_ALU_POO, d64);
alu->proto_offset = FIELD_GET(ICE_IM_ALU_PO, d64);
idd = (ICE_IM_ALU_BA_S + off) / BITS_PER_BYTE;
off = (ICE_IM_ALU_BA_S + off) % BITS_PER_BYTE;
d64 = *((u64 *)(&data[idd])) >> off;
alu->branch_addr = FIELD_GET(ICE_IM_ALU_BA, d64);
alu->imm = FIELD_GET(ICE_IM_ALU_IMM, d64);
alu->dedicate_flags_ena = FIELD_GET(ICE_IM_ALU_DFE, d64);
alu->dst_start = FIELD_GET(ICE_IM_ALU_DS, d64);
alu->dst_len = FIELD_GET(ICE_IM_ALU_DL, d64);
alu->flags_extr_imm = FIELD_GET(ICE_IM_ALU_FEI, d64);
alu->flags_start_imm = FIELD_GET(ICE_IM_ALU_FSI, d64);
}
#define ICE_IMEM_BM_S 0
#define ICE_IMEM_BKB_S 4
#define ICE_IMEM_BKB_IDD (ICE_IMEM_BKB_S / BITS_PER_BYTE)
#define ICE_IMEM_BKB_OFF (ICE_IMEM_BKB_S % BITS_PER_BYTE)
#define ICE_IMEM_PGP GENMASK(15, 14)
#define ICE_IMEM_NPKB_S 16
#define ICE_IMEM_NPKB_IDD (ICE_IMEM_NPKB_S / BITS_PER_BYTE)
#define ICE_IMEM_NPKB_OFF (ICE_IMEM_NPKB_S % BITS_PER_BYTE)
#define ICE_IMEM_PGKB_S 34
#define ICE_IMEM_PGKB_IDD (ICE_IMEM_PGKB_S / BITS_PER_BYTE)
#define ICE_IMEM_PGKB_OFF (ICE_IMEM_PGKB_S % BITS_PER_BYTE)
#define ICE_IMEM_ALU0_S 69
#define ICE_IMEM_ALU0_IDD (ICE_IMEM_ALU0_S / BITS_PER_BYTE)
#define ICE_IMEM_ALU0_OFF (ICE_IMEM_ALU0_S % BITS_PER_BYTE)
#define ICE_IMEM_ALU1_S 165
#define ICE_IMEM_ALU1_IDD (ICE_IMEM_ALU1_S / BITS_PER_BYTE)
#define ICE_IMEM_ALU1_OFF (ICE_IMEM_ALU1_S % BITS_PER_BYTE)
#define ICE_IMEM_ALU2_S 357
#define ICE_IMEM_ALU2_IDD (ICE_IMEM_ALU2_S / BITS_PER_BYTE)
#define ICE_IMEM_ALU2_OFF (ICE_IMEM_ALU2_S % BITS_PER_BYTE)
/**
* ice_imem_parse_item - parse 384 bits of IMEM entry
* @hw: pointer to the hardware structure
* @idx: index of IMEM entry
* @item: item of IMEM entry
* @data: IMEM entry data to be parsed
* @size: size of IMEM entry
*/
static void ice_imem_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_imem_item *ii = item;
u8 *buf = data;
ii->idx = idx;
ice_imem_bm_init(&ii->b_m, *(u8 *)buf);
ice_imem_bkb_init(&ii->b_kb,
*((u16 *)(&buf[ICE_IMEM_BKB_IDD])) >>
ICE_IMEM_BKB_OFF);
ii->pg_prio = FIELD_GET(ICE_IMEM_PGP, *(u16 *)buf);
ice_imem_npkb_init(&ii->np_kb,
*((u32 *)(&buf[ICE_IMEM_NPKB_IDD])) >>
ICE_IMEM_NPKB_OFF);
ice_imem_pgkb_init(&ii->pg_kb,
*((u64 *)(&buf[ICE_IMEM_PGKB_IDD])) >>
ICE_IMEM_PGKB_OFF);
ice_imem_alu_init(&ii->alu0,
&buf[ICE_IMEM_ALU0_IDD],
ICE_IMEM_ALU0_OFF);
ice_imem_alu_init(&ii->alu1,
&buf[ICE_IMEM_ALU1_IDD],
ICE_IMEM_ALU1_OFF);
ice_imem_alu_init(&ii->alu2,
&buf[ICE_IMEM_ALU2_IDD],
ICE_IMEM_ALU2_OFF);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_imem_dump(hw, ii);
}
/**
* ice_imem_table_get - create an imem table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated IMEM table.
*/
static struct ice_imem_item *ice_imem_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_IMEM,
sizeof(struct ice_imem_item),
ICE_IMEM_TABLE_SIZE,
ice_imem_parse_item, false);
}
/*** ICE_SID_RXPARSER_METADATA_INIT section ***/
/**
* ice_metainit_dump - dump an metainit item info
* @hw: pointer to the hardware structure
* @item: metainit item to dump
*/
static void ice_metainit_dump(struct ice_hw *hw, struct ice_metainit_item *item)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "index = %d\n", item->idx);
dev_info(dev, "tsr = %d\n", item->tsr);
dev_info(dev, "ho = %d\n", item->ho);
dev_info(dev, "pc = %d\n", item->pc);
dev_info(dev, "pg_rn = %d\n", item->pg_rn);
dev_info(dev, "cd = %d\n", item->cd);
dev_info(dev, "gpr_a_ctrl = %d\n", item->gpr_a_ctrl);
dev_info(dev, "gpr_a_data_mdid = %d\n", item->gpr_a_data_mdid);
dev_info(dev, "gpr_a_data_start = %d\n", item->gpr_a_data_start);
dev_info(dev, "gpr_a_data_len = %d\n", item->gpr_a_data_len);
dev_info(dev, "gpr_a_id = %d\n", item->gpr_a_id);
dev_info(dev, "gpr_b_ctrl = %d\n", item->gpr_b_ctrl);
dev_info(dev, "gpr_b_data_mdid = %d\n", item->gpr_b_data_mdid);
dev_info(dev, "gpr_b_data_start = %d\n", item->gpr_b_data_start);
dev_info(dev, "gpr_b_data_len = %d\n", item->gpr_b_data_len);
dev_info(dev, "gpr_b_id = %d\n", item->gpr_b_id);
dev_info(dev, "gpr_c_ctrl = %d\n", item->gpr_c_ctrl);
dev_info(dev, "gpr_c_data_mdid = %d\n", item->gpr_c_data_mdid);
dev_info(dev, "gpr_c_data_start = %d\n", item->gpr_c_data_start);
dev_info(dev, "gpr_c_data_len = %d\n", item->gpr_c_data_len);
dev_info(dev, "gpr_c_id = %d\n", item->gpr_c_id);
dev_info(dev, "gpr_d_ctrl = %d\n", item->gpr_d_ctrl);
dev_info(dev, "gpr_d_data_mdid = %d\n", item->gpr_d_data_mdid);
dev_info(dev, "gpr_d_data_start = %d\n", item->gpr_d_data_start);
dev_info(dev, "gpr_d_data_len = %d\n", item->gpr_d_data_len);
dev_info(dev, "gpr_d_id = %d\n", item->gpr_d_id);
dev_info(dev, "flags = 0x%llx\n", (unsigned long long)(item->flags));
}
#define ICE_MI_TSR GENMASK_ULL(7, 0)
#define ICE_MI_HO GENMASK_ULL(16, 8)
#define ICE_MI_PC GENMASK_ULL(24, 17)
#define ICE_MI_PGRN GENMASK_ULL(35, 25)
#define ICE_MI_CD GENMASK_ULL(38, 36)
#define ICE_MI_GAC BIT_ULL(39)
#define ICE_MI_GADM GENMASK_ULL(44, 40)
#define ICE_MI_GADS GENMASK_ULL(48, 45)
#define ICE_MI_GADL GENMASK_ULL(53, 49)
#define ICE_MI_GAI GENMASK_ULL(59, 56)
#define ICE_MI_GBC BIT_ULL(60)
#define ICE_MI_GBDM_S 61 /* offset for the 2nd 64-bits field */
#define ICE_MI_GBDM_IDD (ICE_MI_GBDM_S / BITS_PER_BYTE)
#define ICE_MI_GBDM_OFF (ICE_MI_GBDM_S % BITS_PER_BYTE)
#define ICE_MI_GBDM_GENMASK_ULL(high, low) \
GENMASK_ULL((high) - ICE_MI_GBDM_S, (low) - ICE_MI_GBDM_S)
#define ICE_MI_GBDM ICE_MI_GBDM_GENMASK_ULL(65, 61)
#define ICE_MI_GBDS ICE_MI_GBDM_GENMASK_ULL(69, 66)
#define ICE_MI_GBDL ICE_MI_GBDM_GENMASK_ULL(74, 70)
#define ICE_MI_GBI ICE_MI_GBDM_GENMASK_ULL(80, 77)
#define ICE_MI_GCC BIT_ULL(81 - ICE_MI_GBDM_S)
#define ICE_MI_GCDM ICE_MI_GBDM_GENMASK_ULL(86, 82)
#define ICE_MI_GCDS ICE_MI_GBDM_GENMASK_ULL(90, 87)
#define ICE_MI_GCDL ICE_MI_GBDM_GENMASK_ULL(95, 91)
#define ICE_MI_GCI ICE_MI_GBDM_GENMASK_ULL(101, 98)
#define ICE_MI_GDC BIT_ULL(102 - ICE_MI_GBDM_S)
#define ICE_MI_GDDM ICE_MI_GBDM_GENMASK_ULL(107, 103)
#define ICE_MI_GDDS ICE_MI_GBDM_GENMASK_ULL(111, 108)
#define ICE_MI_GDDL ICE_MI_GBDM_GENMASK_ULL(116, 112)
#define ICE_MI_GDI ICE_MI_GBDM_GENMASK_ULL(122, 119)
#define ICE_MI_FLAG_S 123 /* offset for the 3rd 64-bits field */
#define ICE_MI_FLAG_IDD (ICE_MI_FLAG_S / BITS_PER_BYTE)
#define ICE_MI_FLAG_OFF (ICE_MI_FLAG_S % BITS_PER_BYTE)
#define ICE_MI_FLAG GENMASK_ULL(186 - ICE_MI_FLAG_S, \
123 - ICE_MI_FLAG_S)
/**
* ice_metainit_parse_item - parse 192 bits of Metadata Init entry
* @hw: pointer to the hardware structure
* @idx: index of Metadata Init entry
* @item: item of Metadata Init entry
* @data: Metadata Init entry data to be parsed
* @size: size of Metadata Init entry
*/
static void ice_metainit_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_metainit_item *mi = item;
u8 *buf = data;
u64 d64;
mi->idx = idx;
d64 = *(u64 *)buf;
mi->tsr = FIELD_GET(ICE_MI_TSR, d64);
mi->ho = FIELD_GET(ICE_MI_HO, d64);
mi->pc = FIELD_GET(ICE_MI_PC, d64);
mi->pg_rn = FIELD_GET(ICE_MI_PGRN, d64);
mi->cd = FIELD_GET(ICE_MI_CD, d64);
mi->gpr_a_ctrl = FIELD_GET(ICE_MI_GAC, d64);
mi->gpr_a_data_mdid = FIELD_GET(ICE_MI_GADM, d64);
mi->gpr_a_data_start = FIELD_GET(ICE_MI_GADS, d64);
mi->gpr_a_data_len = FIELD_GET(ICE_MI_GADL, d64);
mi->gpr_a_id = FIELD_GET(ICE_MI_GAI, d64);
mi->gpr_b_ctrl = FIELD_GET(ICE_MI_GBC, d64);
d64 = *((u64 *)&buf[ICE_MI_GBDM_IDD]) >> ICE_MI_GBDM_OFF;
mi->gpr_b_data_mdid = FIELD_GET(ICE_MI_GBDM, d64);
mi->gpr_b_data_start = FIELD_GET(ICE_MI_GBDS, d64);
mi->gpr_b_data_len = FIELD_GET(ICE_MI_GBDL, d64);
mi->gpr_b_id = FIELD_GET(ICE_MI_GBI, d64);
mi->gpr_c_ctrl = FIELD_GET(ICE_MI_GCC, d64);
mi->gpr_c_data_mdid = FIELD_GET(ICE_MI_GCDM, d64);
mi->gpr_c_data_start = FIELD_GET(ICE_MI_GCDS, d64);
mi->gpr_c_data_len = FIELD_GET(ICE_MI_GCDL, d64);
mi->gpr_c_id = FIELD_GET(ICE_MI_GCI, d64);
mi->gpr_d_ctrl = FIELD_GET(ICE_MI_GDC, d64);
mi->gpr_d_data_mdid = FIELD_GET(ICE_MI_GDDM, d64);
mi->gpr_d_data_start = FIELD_GET(ICE_MI_GDDS, d64);
mi->gpr_d_data_len = FIELD_GET(ICE_MI_GDDL, d64);
mi->gpr_d_id = FIELD_GET(ICE_MI_GDI, d64);
d64 = *((u64 *)&buf[ICE_MI_FLAG_IDD]) >> ICE_MI_FLAG_OFF;
mi->flags = FIELD_GET(ICE_MI_FLAG, d64);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_metainit_dump(hw, mi);
}
/**
* ice_metainit_table_get - create a metainit table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Metadata initialization table.
*/
static struct ice_metainit_item *ice_metainit_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_METADATA_INIT,
sizeof(struct ice_metainit_item),
ICE_METAINIT_TABLE_SIZE,
ice_metainit_parse_item, false);
}
/**
* ice_bst_tcam_search - find a TCAM item with specific type
* @tcam_table: the TCAM table
* @lbl_table: the lbl table to search
* @type: the type we need to match against
* @start: start searching from this index
*
* Return: a pointer to the matching BOOST TCAM item or NULL.
*/
struct ice_bst_tcam_item *
ice_bst_tcam_search(struct ice_bst_tcam_item *tcam_table,
struct ice_lbl_item *lbl_table,
enum ice_lbl_type type, u16 *start)
{
u16 i = *start;
for (; i < ICE_BST_TCAM_TABLE_SIZE; i++) {
if (lbl_table[i].type == type) {
*start = i;
return &tcam_table[lbl_table[i].idx];
}
}
return NULL;
}
/*** ICE_SID_RXPARSER_CAM, ICE_SID_RXPARSER_PG_SPILL,
* ICE_SID_RXPARSER_NOMATCH_CAM and ICE_SID_RXPARSER_NOMATCH_CAM
* sections ***/
static void ice_pg_cam_key_dump(struct ice_hw *hw, struct ice_pg_cam_key *key)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "key:\n");
dev_info(dev, "\tvalid = %d\n", key->valid);
dev_info(dev, "\tnode_id = %d\n", key->node_id);
dev_info(dev, "\tflag0 = %d\n", key->flag0);
dev_info(dev, "\tflag1 = %d\n", key->flag1);
dev_info(dev, "\tflag2 = %d\n", key->flag2);
dev_info(dev, "\tflag3 = %d\n", key->flag3);
dev_info(dev, "\tboost_idx = %d\n", key->boost_idx);
dev_info(dev, "\talu_reg = 0x%04x\n", key->alu_reg);
dev_info(dev, "\tnext_proto = 0x%08x\n", key->next_proto);
}
static void ice_pg_nm_cam_key_dump(struct ice_hw *hw,
struct ice_pg_nm_cam_key *key)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "key:\n");
dev_info(dev, "\tvalid = %d\n", key->valid);
dev_info(dev, "\tnode_id = %d\n", key->node_id);
dev_info(dev, "\tflag0 = %d\n", key->flag0);
dev_info(dev, "\tflag1 = %d\n", key->flag1);
dev_info(dev, "\tflag2 = %d\n", key->flag2);
dev_info(dev, "\tflag3 = %d\n", key->flag3);
dev_info(dev, "\tboost_idx = %d\n", key->boost_idx);
dev_info(dev, "\talu_reg = 0x%04x\n", key->alu_reg);
}
static void ice_pg_cam_action_dump(struct ice_hw *hw,
struct ice_pg_cam_action *action)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "action:\n");
dev_info(dev, "\tnext_node = %d\n", action->next_node);
dev_info(dev, "\tnext_pc = %d\n", action->next_pc);
dev_info(dev, "\tis_pg = %d\n", action->is_pg);
dev_info(dev, "\tproto_id = %d\n", action->proto_id);
dev_info(dev, "\tis_mg = %d\n", action->is_mg);
dev_info(dev, "\tmarker_id = %d\n", action->marker_id);
dev_info(dev, "\tis_last_round = %d\n", action->is_last_round);
dev_info(dev, "\tho_polarity = %d\n", action->ho_polarity);
dev_info(dev, "\tho_inc = %d\n", action->ho_inc);
}
/**
* ice_pg_cam_dump - dump an parse graph cam info
* @hw: pointer to the hardware structure
* @item: parse graph cam to dump
*/
static void ice_pg_cam_dump(struct ice_hw *hw, struct ice_pg_cam_item *item)
{
dev_info(ice_hw_to_dev(hw), "index = %d\n", item->idx);
ice_pg_cam_key_dump(hw, &item->key);
ice_pg_cam_action_dump(hw, &item->action);
}
/**
* ice_pg_nm_cam_dump - dump an parse graph no match cam info
* @hw: pointer to the hardware structure
* @item: parse graph no match cam to dump
*/
static void ice_pg_nm_cam_dump(struct ice_hw *hw,
struct ice_pg_nm_cam_item *item)
{
dev_info(ice_hw_to_dev(hw), "index = %d\n", item->idx);
ice_pg_nm_cam_key_dump(hw, &item->key);
ice_pg_cam_action_dump(hw, &item->action);
}
#define ICE_PGCA_NN GENMASK_ULL(10, 0)
#define ICE_PGCA_NPC GENMASK_ULL(18, 11)
#define ICE_PGCA_IPG BIT_ULL(19)
#define ICE_PGCA_PID GENMASK_ULL(30, 23)
#define ICE_PGCA_IMG BIT_ULL(31)
#define ICE_PGCA_MID GENMASK_ULL(39, 32)
#define ICE_PGCA_ILR BIT_ULL(40)
#define ICE_PGCA_HOP BIT_ULL(41)
#define ICE_PGCA_HOI GENMASK_ULL(50, 42)
/**
* ice_pg_cam_action_init - parse 55 bits of Parse Graph CAM Action
* @action: pointer to the Parse Graph CAM Action structure
* @data: Parse Graph CAM Action data to be parsed
*/
static void ice_pg_cam_action_init(struct ice_pg_cam_action *action, u64 data)
{
action->next_node = FIELD_GET(ICE_PGCA_NN, data);
action->next_pc = FIELD_GET(ICE_PGCA_NPC, data);
action->is_pg = FIELD_GET(ICE_PGCA_IPG, data);
action->proto_id = FIELD_GET(ICE_PGCA_PID, data);
action->is_mg = FIELD_GET(ICE_PGCA_IMG, data);
action->marker_id = FIELD_GET(ICE_PGCA_MID, data);
action->is_last_round = FIELD_GET(ICE_PGCA_ILR, data);
action->ho_polarity = FIELD_GET(ICE_PGCA_HOP, data);
action->ho_inc = FIELD_GET(ICE_PGCA_HOI, data);
}
#define ICE_PGNCK_VLD BIT_ULL(0)
#define ICE_PGNCK_NID GENMASK_ULL(11, 1)
#define ICE_PGNCK_F0 BIT_ULL(12)
#define ICE_PGNCK_F1 BIT_ULL(13)
#define ICE_PGNCK_F2 BIT_ULL(14)
#define ICE_PGNCK_F3 BIT_ULL(15)
#define ICE_PGNCK_BH BIT_ULL(16)
#define ICE_PGNCK_BI GENMASK_ULL(24, 17)
#define ICE_PGNCK_AR GENMASK_ULL(40, 25)
/**
* ice_pg_nm_cam_key_init - parse 41 bits of Parse Graph NoMatch CAM Key
* @key: pointer to the Parse Graph NoMatch CAM Key structure
* @data: Parse Graph NoMatch CAM Key data to be parsed
*/
static void ice_pg_nm_cam_key_init(struct ice_pg_nm_cam_key *key, u64 data)
{
key->valid = FIELD_GET(ICE_PGNCK_VLD, data);
key->node_id = FIELD_GET(ICE_PGNCK_NID, data);
key->flag0 = FIELD_GET(ICE_PGNCK_F0, data);
key->flag1 = FIELD_GET(ICE_PGNCK_F1, data);
key->flag2 = FIELD_GET(ICE_PGNCK_F2, data);
key->flag3 = FIELD_GET(ICE_PGNCK_F3, data);
if (FIELD_GET(ICE_PGNCK_BH, data))
key->boost_idx = FIELD_GET(ICE_PGNCK_BI, data);
else
key->boost_idx = 0;
key->alu_reg = FIELD_GET(ICE_PGNCK_AR, data);
}
#define ICE_PGCK_VLD BIT_ULL(0)
#define ICE_PGCK_NID GENMASK_ULL(11, 1)
#define ICE_PGCK_F0 BIT_ULL(12)
#define ICE_PGCK_F1 BIT_ULL(13)
#define ICE_PGCK_F2 BIT_ULL(14)
#define ICE_PGCK_F3 BIT_ULL(15)
#define ICE_PGCK_BH BIT_ULL(16)
#define ICE_PGCK_BI GENMASK_ULL(24, 17)
#define ICE_PGCK_AR GENMASK_ULL(40, 25)
#define ICE_PGCK_NPK_S 41 /* offset for the 2nd 64-bits field */
#define ICE_PGCK_NPK_IDD (ICE_PGCK_NPK_S / BITS_PER_BYTE)
#define ICE_PGCK_NPK_OFF (ICE_PGCK_NPK_S % BITS_PER_BYTE)
#define ICE_PGCK_NPK GENMASK_ULL(72 - ICE_PGCK_NPK_S, \
41 - ICE_PGCK_NPK_S)
/**
* ice_pg_cam_key_init - parse 73 bits of Parse Graph CAM Key
* @key: pointer to the Parse Graph CAM Key structure
* @data: Parse Graph CAM Key data to be parsed
*/
static void ice_pg_cam_key_init(struct ice_pg_cam_key *key, u8 *data)
{
u64 d64 = *(u64 *)data;
key->valid = FIELD_GET(ICE_PGCK_VLD, d64);
key->node_id = FIELD_GET(ICE_PGCK_NID, d64);
key->flag0 = FIELD_GET(ICE_PGCK_F0, d64);
key->flag1 = FIELD_GET(ICE_PGCK_F1, d64);
key->flag2 = FIELD_GET(ICE_PGCK_F2, d64);
key->flag3 = FIELD_GET(ICE_PGCK_F3, d64);
if (FIELD_GET(ICE_PGCK_BH, d64))
key->boost_idx = FIELD_GET(ICE_PGCK_BI, d64);
else
key->boost_idx = 0;
key->alu_reg = FIELD_GET(ICE_PGCK_AR, d64);
d64 = *((u64 *)&data[ICE_PGCK_NPK_IDD]) >> ICE_PGCK_NPK_OFF;
key->next_proto = FIELD_GET(ICE_PGCK_NPK, d64);
}
#define ICE_PG_CAM_ACT_S 73
#define ICE_PG_CAM_ACT_IDD (ICE_PG_CAM_ACT_S / BITS_PER_BYTE)
#define ICE_PG_CAM_ACT_OFF (ICE_PG_CAM_ACT_S % BITS_PER_BYTE)
/**
* ice_pg_cam_parse_item - parse 128 bits of Parse Graph CAM Entry
* @hw: pointer to the hardware structure
* @idx: index of Parse Graph CAM Entry
* @item: item of Parse Graph CAM Entry
* @data: Parse Graph CAM Entry data to be parsed
* @size: size of Parse Graph CAM Entry
*/
static void ice_pg_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_pg_cam_item *ci = item;
u8 *buf = data;
u64 d64;
ci->idx = idx;
ice_pg_cam_key_init(&ci->key, buf);
d64 = *((u64 *)&buf[ICE_PG_CAM_ACT_IDD]) >> ICE_PG_CAM_ACT_OFF;
ice_pg_cam_action_init(&ci->action, d64);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_pg_cam_dump(hw, ci);
}
#define ICE_PG_SP_CAM_KEY_S 56
#define ICE_PG_SP_CAM_KEY_IDD (ICE_PG_SP_CAM_KEY_S / BITS_PER_BYTE)
/**
* ice_pg_sp_cam_parse_item - parse 136 bits of Parse Graph Spill CAM Entry
* @hw: pointer to the hardware structure
* @idx: index of Parse Graph Spill CAM Entry
* @item: item of Parse Graph Spill CAM Entry
* @data: Parse Graph Spill CAM Entry data to be parsed
* @size: size of Parse Graph Spill CAM Entry
*/
static void ice_pg_sp_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_pg_cam_item *ci = item;
u8 *buf = data;
u64 d64;
ci->idx = idx;
d64 = *(u64 *)buf;
ice_pg_cam_action_init(&ci->action, d64);
ice_pg_cam_key_init(&ci->key, &buf[ICE_PG_SP_CAM_KEY_IDD]);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_pg_cam_dump(hw, ci);
}
#define ICE_PG_NM_CAM_ACT_S 41
#define ICE_PG_NM_CAM_ACT_IDD (ICE_PG_NM_CAM_ACT_S / BITS_PER_BYTE)
#define ICE_PG_NM_CAM_ACT_OFF (ICE_PG_NM_CAM_ACT_S % BITS_PER_BYTE)
/**
* ice_pg_nm_cam_parse_item - parse 96 bits of Parse Graph NoMatch CAM Entry
* @hw: pointer to the hardware structure
* @idx: index of Parse Graph NoMatch CAM Entry
* @item: item of Parse Graph NoMatch CAM Entry
* @data: Parse Graph NoMatch CAM Entry data to be parsed
* @size: size of Parse Graph NoMatch CAM Entry
*/
static void ice_pg_nm_cam_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_pg_nm_cam_item *ci = item;
u8 *buf = data;
u64 d64;
ci->idx = idx;
d64 = *(u64 *)buf;
ice_pg_nm_cam_key_init(&ci->key, d64);
d64 = *((u64 *)&buf[ICE_PG_NM_CAM_ACT_IDD]) >> ICE_PG_NM_CAM_ACT_OFF;
ice_pg_cam_action_init(&ci->action, d64);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_pg_nm_cam_dump(hw, ci);
}
#define ICE_PG_NM_SP_CAM_ACT_S 56
#define ICE_PG_NM_SP_CAM_ACT_IDD (ICE_PG_NM_SP_CAM_ACT_S / BITS_PER_BYTE)
#define ICE_PG_NM_SP_CAM_ACT_OFF (ICE_PG_NM_SP_CAM_ACT_S % BITS_PER_BYTE)
/**
* ice_pg_nm_sp_cam_parse_item - parse 104 bits of Parse Graph NoMatch Spill
* CAM Entry
* @hw: pointer to the hardware structure
* @idx: index of Parse Graph NoMatch Spill CAM Entry
* @item: item of Parse Graph NoMatch Spill CAM Entry
* @data: Parse Graph NoMatch Spill CAM Entry data to be parsed
* @size: size of Parse Graph NoMatch Spill CAM Entry
*/
static void ice_pg_nm_sp_cam_parse_item(struct ice_hw *hw, u16 idx,
void *item, void *data,
int __maybe_unused size)
{
struct ice_pg_nm_cam_item *ci = item;
u8 *buf = data;
u64 d64;
ci->idx = idx;
d64 = *(u64 *)buf;
ice_pg_cam_action_init(&ci->action, d64);
d64 = *((u64 *)&buf[ICE_PG_NM_SP_CAM_ACT_IDD]) >>
ICE_PG_NM_SP_CAM_ACT_OFF;
ice_pg_nm_cam_key_init(&ci->key, d64);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_pg_nm_cam_dump(hw, ci);
}
/**
* ice_pg_cam_table_get - create a parse graph cam table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Parse Graph CAM table.
*/
static struct ice_pg_cam_item *ice_pg_cam_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_CAM,
sizeof(struct ice_pg_cam_item),
ICE_PG_CAM_TABLE_SIZE,
ice_pg_cam_parse_item, false);
}
/**
* ice_pg_sp_cam_table_get - create a parse graph spill cam table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Parse Graph Spill CAM table.
*/
static struct ice_pg_cam_item *ice_pg_sp_cam_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_PG_SPILL,
sizeof(struct ice_pg_cam_item),
ICE_PG_SP_CAM_TABLE_SIZE,
ice_pg_sp_cam_parse_item, false);
}
/**
* ice_pg_nm_cam_table_get - create a parse graph no match cam table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Parse Graph No Match CAM table.
*/
static struct ice_pg_nm_cam_item *ice_pg_nm_cam_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_NOMATCH_CAM,
sizeof(struct ice_pg_nm_cam_item),
ICE_PG_NM_CAM_TABLE_SIZE,
ice_pg_nm_cam_parse_item, false);
}
/**
* ice_pg_nm_sp_cam_table_get - create a parse graph no match spill cam table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Parse Graph No Match Spill CAM table.
*/
static struct ice_pg_nm_cam_item *ice_pg_nm_sp_cam_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_NOMATCH_SPILL,
sizeof(struct ice_pg_nm_cam_item),
ICE_PG_NM_SP_CAM_TABLE_SIZE,
ice_pg_nm_sp_cam_parse_item, false);
}
static bool __ice_pg_cam_match(struct ice_pg_cam_item *item,
struct ice_pg_cam_key *key)
{
return (item->key.valid &&
!memcmp(&item->key.val, &key->val, sizeof(key->val)));
}
static bool __ice_pg_nm_cam_match(struct ice_pg_nm_cam_item *item,
struct ice_pg_cam_key *key)
{
return (item->key.valid &&
!memcmp(&item->key.val, &key->val, sizeof(item->key.val)));
}
/**
* ice_pg_cam_match - search parse graph cam table by key
* @table: parse graph cam table to search
* @size: cam table size
* @key: search key
*
* Return: a pointer to the matching PG CAM item or NULL.
*/
struct ice_pg_cam_item *ice_pg_cam_match(struct ice_pg_cam_item *table,
int size, struct ice_pg_cam_key *key)
{
int i;
for (i = 0; i < size; i++) {
struct ice_pg_cam_item *item = &table[i];
if (__ice_pg_cam_match(item, key))
return item;
}
return NULL;
}
/**
* ice_pg_nm_cam_match - search parse graph no match cam table by key
* @table: parse graph no match cam table to search
* @size: cam table size
* @key: search key
*
* Return: a pointer to the matching PG No Match CAM item or NULL.
*/
struct ice_pg_nm_cam_item *
ice_pg_nm_cam_match(struct ice_pg_nm_cam_item *table, int size,
struct ice_pg_cam_key *key)
{
int i;
for (i = 0; i < size; i++) {
struct ice_pg_nm_cam_item *item = &table[i];
if (__ice_pg_nm_cam_match(item, key))
return item;
}
return NULL;
}
/*** Ternary match ***/
/* Perform a ternary match on a 1-byte pattern (@pat) given @key and @key_inv
* Rules (per bit):
* Key == 0 and Key_inv == 0 : Never match (Don't care)
* Key == 0 and Key_inv == 1 : Match on bit == 1
* Key == 1 and Key_inv == 0 : Match on bit == 0
* Key == 1 and Key_inv == 1 : Always match (Don't care)
*
* Return: true if all bits match, false otherwise.
*/
static bool ice_ternary_match_byte(u8 key, u8 key_inv, u8 pat)
{
u8 bit_key, bit_key_inv, bit_pat;
int i;
for (i = 0; i < BITS_PER_BYTE; i++) {
bit_key = key & BIT(i);
bit_key_inv = key_inv & BIT(i);
bit_pat = pat & BIT(i);
if (bit_key != 0 && bit_key_inv != 0)
continue;
if ((bit_key == 0 && bit_key_inv == 0) || bit_key == bit_pat)
return false;
}
return true;
}
static bool ice_ternary_match(const u8 *key, const u8 *key_inv,
const u8 *pat, int len)
{
int i;
for (i = 0; i < len; i++)
if (!ice_ternary_match_byte(key[i], key_inv[i], pat[i]))
return false;
return true;
}
/*** ICE_SID_RXPARSER_BOOST_TCAM and ICE_SID_LBL_RXPARSER_TMEM sections ***/
static void ice_bst_np_kb_dump(struct ice_hw *hw, struct ice_np_keybuilder *kb)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "next proto key builder:\n");
dev_info(dev, "\topc = %d\n", kb->opc);
dev_info(dev, "\tstart_reg0 = %d\n", kb->start_reg0);
dev_info(dev, "\tlen_reg1 = %d\n", kb->len_reg1);
}
static void ice_bst_pg_kb_dump(struct ice_hw *hw, struct ice_pg_keybuilder *kb)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "parse graph key builder:\n");
dev_info(dev, "\tflag0_ena = %d\n", kb->flag0_ena);
dev_info(dev, "\tflag1_ena = %d\n", kb->flag1_ena);
dev_info(dev, "\tflag2_ena = %d\n", kb->flag2_ena);
dev_info(dev, "\tflag3_ena = %d\n", kb->flag3_ena);
dev_info(dev, "\tflag0_idx = %d\n", kb->flag0_idx);
dev_info(dev, "\tflag1_idx = %d\n", kb->flag1_idx);
dev_info(dev, "\tflag2_idx = %d\n", kb->flag2_idx);
dev_info(dev, "\tflag3_idx = %d\n", kb->flag3_idx);
dev_info(dev, "\talu_reg_idx = %d\n", kb->alu_reg_idx);
}
static void ice_bst_alu_dump(struct ice_hw *hw, struct ice_alu *alu, int idx)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "alu%d:\n", idx);
dev_info(dev, "\topc = %d\n", alu->opc);
dev_info(dev, "\tsrc_start = %d\n", alu->src_start);
dev_info(dev, "\tsrc_len = %d\n", alu->src_len);
dev_info(dev, "\tshift_xlate_sel = %d\n", alu->shift_xlate_sel);
dev_info(dev, "\tshift_xlate_key = %d\n", alu->shift_xlate_key);
dev_info(dev, "\tsrc_reg_id = %d\n", alu->src_reg_id);
dev_info(dev, "\tdst_reg_id = %d\n", alu->dst_reg_id);
dev_info(dev, "\tinc0 = %d\n", alu->inc0);
dev_info(dev, "\tinc1 = %d\n", alu->inc1);
dev_info(dev, "\tproto_offset_opc = %d\n", alu->proto_offset_opc);
dev_info(dev, "\tproto_offset = %d\n", alu->proto_offset);
dev_info(dev, "\tbranch_addr = %d\n", alu->branch_addr);
dev_info(dev, "\timm = %d\n", alu->imm);
dev_info(dev, "\tdst_start = %d\n", alu->dst_start);
dev_info(dev, "\tdst_len = %d\n", alu->dst_len);
dev_info(dev, "\tflags_extr_imm = %d\n", alu->flags_extr_imm);
dev_info(dev, "\tflags_start_imm= %d\n", alu->flags_start_imm);
}
/**
* ice_bst_tcam_dump - dump a boost tcam info
* @hw: pointer to the hardware structure
* @item: boost tcam to dump
*/
static void ice_bst_tcam_dump(struct ice_hw *hw, struct ice_bst_tcam_item *item)
{
struct device *dev = ice_hw_to_dev(hw);
int i;
dev_info(dev, "addr = %d\n", item->addr);
dev_info(dev, "key : ");
for (i = 0; i < ICE_BST_TCAM_KEY_SIZE; i++)
dev_info(dev, "%02x ", item->key[i]);
dev_info(dev, "\n");
dev_info(dev, "key_inv: ");
for (i = 0; i < ICE_BST_TCAM_KEY_SIZE; i++)
dev_info(dev, "%02x ", item->key_inv[i]);
dev_info(dev, "\n");
dev_info(dev, "hit_idx_grp = %d\n", item->hit_idx_grp);
dev_info(dev, "pg_prio = %d\n", item->pg_prio);
ice_bst_np_kb_dump(hw, &item->np_kb);
ice_bst_pg_kb_dump(hw, &item->pg_kb);
ice_bst_alu_dump(hw, &item->alu0, ICE_ALU0_IDX);
ice_bst_alu_dump(hw, &item->alu1, ICE_ALU1_IDX);
ice_bst_alu_dump(hw, &item->alu2, ICE_ALU2_IDX);
}
static void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "index = %u\n", item->idx);
dev_info(dev, "type = %u\n", item->type);
dev_info(dev, "label = %s\n", item->label);
}
#define ICE_BST_ALU_OPC GENMASK_ULL(5, 0)
#define ICE_BST_ALU_SS GENMASK_ULL(13, 6)
#define ICE_BST_ALU_SL GENMASK_ULL(18, 14)
#define ICE_BST_ALU_SXS BIT_ULL(19)
#define ICE_BST_ALU_SXK GENMASK_ULL(23, 20)
#define ICE_BST_ALU_SRID GENMASK_ULL(30, 24)
#define ICE_BST_ALU_DRID GENMASK_ULL(37, 31)
#define ICE_BST_ALU_INC0 BIT_ULL(38)
#define ICE_BST_ALU_INC1 BIT_ULL(39)
#define ICE_BST_ALU_POO GENMASK_ULL(41, 40)
#define ICE_BST_ALU_PO GENMASK_ULL(49, 42)
#define ICE_BST_ALU_BA_S 50 /* offset for the 2nd 64-bits field */
#define ICE_BST_ALU_BA GENMASK_ULL(57 - ICE_BST_ALU_BA_S, \
50 - ICE_BST_ALU_BA_S)
#define ICE_BST_ALU_IMM GENMASK_ULL(73 - ICE_BST_ALU_BA_S, \
58 - ICE_BST_ALU_BA_S)
#define ICE_BST_ALU_DFE BIT_ULL(74 - ICE_BST_ALU_BA_S)
#define ICE_BST_ALU_DS GENMASK_ULL(80 - ICE_BST_ALU_BA_S, \
75 - ICE_BST_ALU_BA_S)
#define ICE_BST_ALU_DL GENMASK_ULL(86 - ICE_BST_ALU_BA_S, \
81 - ICE_BST_ALU_BA_S)
#define ICE_BST_ALU_FEI BIT_ULL(87 - ICE_BST_ALU_BA_S)
#define ICE_BST_ALU_FSI GENMASK_ULL(95 - ICE_BST_ALU_BA_S, \
88 - ICE_BST_ALU_BA_S)
/**
* ice_bst_alu_init - parse 96 bits of ALU entry
* @alu: pointer to the ALU entry structure
* @data: ALU entry data to be parsed
* @off: offset of the ALU entry data
*/
static void ice_bst_alu_init(struct ice_alu *alu, u8 *data, u8 off)
{
u64 d64;
u8 idd;
d64 = *((u64 *)data) >> off;
alu->opc = FIELD_GET(ICE_BST_ALU_OPC, d64);
alu->src_start = FIELD_GET(ICE_BST_ALU_SS, d64);
alu->src_len = FIELD_GET(ICE_BST_ALU_SL, d64);
alu->shift_xlate_sel = FIELD_GET(ICE_BST_ALU_SXS, d64);
alu->shift_xlate_key = FIELD_GET(ICE_BST_ALU_SXK, d64);
alu->src_reg_id = FIELD_GET(ICE_BST_ALU_SRID, d64);
alu->dst_reg_id = FIELD_GET(ICE_BST_ALU_DRID, d64);
alu->inc0 = FIELD_GET(ICE_BST_ALU_INC0, d64);
alu->inc1 = FIELD_GET(ICE_BST_ALU_INC1, d64);
alu->proto_offset_opc = FIELD_GET(ICE_BST_ALU_POO, d64);
alu->proto_offset = FIELD_GET(ICE_BST_ALU_PO, d64);
idd = (ICE_BST_ALU_BA_S + off) / BITS_PER_BYTE;
off = (ICE_BST_ALU_BA_S + off) % BITS_PER_BYTE;
d64 = *((u64 *)(&data[idd])) >> off;
alu->branch_addr = FIELD_GET(ICE_BST_ALU_BA, d64);
alu->imm = FIELD_GET(ICE_BST_ALU_IMM, d64);
alu->dedicate_flags_ena = FIELD_GET(ICE_BST_ALU_DFE, d64);
alu->dst_start = FIELD_GET(ICE_BST_ALU_DS, d64);
alu->dst_len = FIELD_GET(ICE_BST_ALU_DL, d64);
alu->flags_extr_imm = FIELD_GET(ICE_BST_ALU_FEI, d64);
alu->flags_start_imm = FIELD_GET(ICE_BST_ALU_FSI, d64);
}
#define ICE_BST_PGKB_F0_ENA BIT_ULL(0)
#define ICE_BST_PGKB_F0_IDX GENMASK_ULL(6, 1)
#define ICE_BST_PGKB_F1_ENA BIT_ULL(7)
#define ICE_BST_PGKB_F1_IDX GENMASK_ULL(13, 8)
#define ICE_BST_PGKB_F2_ENA BIT_ULL(14)
#define ICE_BST_PGKB_F2_IDX GENMASK_ULL(20, 15)
#define ICE_BST_PGKB_F3_ENA BIT_ULL(21)
#define ICE_BST_PGKB_F3_IDX GENMASK_ULL(27, 22)
#define ICE_BST_PGKB_AR_IDX GENMASK_ULL(34, 28)
/**
* ice_bst_pgkb_init - parse 35 bits of Parse Graph Key Build
* @kb: pointer to the Parse Graph Key Build structure
* @data: Parse Graph Key Build data to be parsed
*/
static void ice_bst_pgkb_init(struct ice_pg_keybuilder *kb, u64 data)
{
kb->flag0_ena = FIELD_GET(ICE_BST_PGKB_F0_ENA, data);
kb->flag0_idx = FIELD_GET(ICE_BST_PGKB_F0_IDX, data);
kb->flag1_ena = FIELD_GET(ICE_BST_PGKB_F1_ENA, data);
kb->flag1_idx = FIELD_GET(ICE_BST_PGKB_F1_IDX, data);
kb->flag2_ena = FIELD_GET(ICE_BST_PGKB_F2_ENA, data);
kb->flag2_idx = FIELD_GET(ICE_BST_PGKB_F2_IDX, data);
kb->flag3_ena = FIELD_GET(ICE_BST_PGKB_F3_ENA, data);
kb->flag3_idx = FIELD_GET(ICE_BST_PGKB_F3_IDX, data);
kb->alu_reg_idx = FIELD_GET(ICE_BST_PGKB_AR_IDX, data);
}
#define ICE_BST_NPKB_OPC GENMASK(1, 0)
#define ICE_BST_NPKB_S_R0 GENMASK(9, 2)
#define ICE_BST_NPKB_L_R1 GENMASK(17, 10)
/**
* ice_bst_npkb_init - parse 18 bits of Next Protocol Key Build
* @kb: pointer to the Next Protocol Key Build structure
* @data: Next Protocol Key Build data to be parsed
*/
static void ice_bst_npkb_init(struct ice_np_keybuilder *kb, u32 data)
{
kb->opc = FIELD_GET(ICE_BST_NPKB_OPC, data);
kb->start_reg0 = FIELD_GET(ICE_BST_NPKB_S_R0, data);
kb->len_reg1 = FIELD_GET(ICE_BST_NPKB_L_R1, data);
}
#define ICE_BT_KEY_S 32
#define ICE_BT_KEY_IDD (ICE_BT_KEY_S / BITS_PER_BYTE)
#define ICE_BT_KIV_S 192
#define ICE_BT_KIV_IDD (ICE_BT_KIV_S / BITS_PER_BYTE)
#define ICE_BT_HIG_S 352
#define ICE_BT_HIG_IDD (ICE_BT_HIG_S / BITS_PER_BYTE)
#define ICE_BT_PGP_S 360
#define ICE_BT_PGP_IDD (ICE_BT_PGP_S / BITS_PER_BYTE)
#define ICE_BT_PGP_M GENMASK(361 - ICE_BT_PGP_S, 360 - ICE_BT_PGP_S)
#define ICE_BT_NPKB_S 362
#define ICE_BT_NPKB_IDD (ICE_BT_NPKB_S / BITS_PER_BYTE)
#define ICE_BT_NPKB_OFF (ICE_BT_NPKB_S % BITS_PER_BYTE)
#define ICE_BT_PGKB_S 380
#define ICE_BT_PGKB_IDD (ICE_BT_PGKB_S / BITS_PER_BYTE)
#define ICE_BT_PGKB_OFF (ICE_BT_PGKB_S % BITS_PER_BYTE)
#define ICE_BT_ALU0_S 415
#define ICE_BT_ALU0_IDD (ICE_BT_ALU0_S / BITS_PER_BYTE)
#define ICE_BT_ALU0_OFF (ICE_BT_ALU0_S % BITS_PER_BYTE)
#define ICE_BT_ALU1_S 511
#define ICE_BT_ALU1_IDD (ICE_BT_ALU1_S / BITS_PER_BYTE)
#define ICE_BT_ALU1_OFF (ICE_BT_ALU1_S % BITS_PER_BYTE)
#define ICE_BT_ALU2_S 607
#define ICE_BT_ALU2_IDD (ICE_BT_ALU2_S / BITS_PER_BYTE)
#define ICE_BT_ALU2_OFF (ICE_BT_ALU2_S % BITS_PER_BYTE)
/**
* ice_bst_parse_item - parse 704 bits of Boost TCAM entry
* @hw: pointer to the hardware structure
* @idx: index of Boost TCAM entry
* @item: item of Boost TCAM entry
* @data: Boost TCAM entry data to be parsed
* @size: size of Boost TCAM entry
*/
static void ice_bst_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_bst_tcam_item *ti = item;
u8 *buf = (u8 *)data;
int i;
ti->addr = *(u16 *)buf;
for (i = 0; i < ICE_BST_TCAM_KEY_SIZE; i++) {
ti->key[i] = buf[ICE_BT_KEY_IDD + i];
ti->key_inv[i] = buf[ICE_BT_KIV_IDD + i];
}
ti->hit_idx_grp = buf[ICE_BT_HIG_IDD];
ti->pg_prio = buf[ICE_BT_PGP_IDD] & ICE_BT_PGP_M;
ice_bst_npkb_init(&ti->np_kb,
*((u32 *)(&buf[ICE_BT_NPKB_IDD])) >>
ICE_BT_NPKB_OFF);
ice_bst_pgkb_init(&ti->pg_kb,
*((u64 *)(&buf[ICE_BT_PGKB_IDD])) >>
ICE_BT_PGKB_OFF);
ice_bst_alu_init(&ti->alu0, &buf[ICE_BT_ALU0_IDD], ICE_BT_ALU0_OFF);
ice_bst_alu_init(&ti->alu1, &buf[ICE_BT_ALU1_IDD], ICE_BT_ALU1_OFF);
ice_bst_alu_init(&ti->alu2, &buf[ICE_BT_ALU2_IDD], ICE_BT_ALU2_OFF);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_bst_tcam_dump(hw, ti);
}
/**
* ice_bst_tcam_table_get - create a boost tcam table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Boost TCAM table.
*/
static struct ice_bst_tcam_item *ice_bst_tcam_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_BOOST_TCAM,
sizeof(struct ice_bst_tcam_item),
ICE_BST_TCAM_TABLE_SIZE,
ice_bst_parse_item, true);
}
static void ice_parse_lbl_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_lbl_item *lbl_item = item;
struct ice_lbl_item *lbl_data = data;
lbl_item->idx = lbl_data->idx;
memcpy(lbl_item->label, lbl_data->label, sizeof(lbl_item->label));
if (strstarts(lbl_item->label, ICE_LBL_BST_DVM))
lbl_item->type = ICE_LBL_BST_TYPE_DVM;
else if (strstarts(lbl_item->label, ICE_LBL_BST_SVM))
lbl_item->type = ICE_LBL_BST_TYPE_SVM;
else if (strstarts(lbl_item->label, ICE_LBL_TNL_VXLAN))
lbl_item->type = ICE_LBL_BST_TYPE_VXLAN;
else if (strstarts(lbl_item->label, ICE_LBL_TNL_GENEVE))
lbl_item->type = ICE_LBL_BST_TYPE_GENEVE;
else if (strstarts(lbl_item->label, ICE_LBL_TNL_UDP_ECPRI))
lbl_item->type = ICE_LBL_BST_TYPE_UDP_ECPRI;
if (hw->debug_mask & ICE_DBG_PARSER)
ice_lbl_dump(hw, lbl_item);
}
/**
* ice_bst_lbl_table_get - create a boost label table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Boost label table.
*/
static struct ice_lbl_item *ice_bst_lbl_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_LBL_RXPARSER_TMEM,
sizeof(struct ice_lbl_item),
ICE_BST_TCAM_TABLE_SIZE,
ice_parse_lbl_item, true);
}
/**
* ice_bst_tcam_match - match a pattern on the boost tcam table
* @tcam_table: boost tcam table to search
* @pat: pattern to match
*
* Return: a pointer to the matching Boost TCAM item or NULL.
*/
struct ice_bst_tcam_item *
ice_bst_tcam_match(struct ice_bst_tcam_item *tcam_table, u8 *pat)
{
int i;
for (i = 0; i < ICE_BST_TCAM_TABLE_SIZE; i++) {
struct ice_bst_tcam_item *item = &tcam_table[i];
if (item->hit_idx_grp == 0)
continue;
if (ice_ternary_match(item->key, item->key_inv, pat,
ICE_BST_TCAM_KEY_SIZE))
return item;
}
return NULL;
}
/*** ICE_SID_RXPARSER_MARKER_PTYPE section ***/
/**
* ice_ptype_mk_tcam_dump - dump an ptype marker tcam info
* @hw: pointer to the hardware structure
* @item: ptype marker tcam to dump
*/
static void ice_ptype_mk_tcam_dump(struct ice_hw *hw,
struct ice_ptype_mk_tcam_item *item)
{
struct device *dev = ice_hw_to_dev(hw);
int i;
dev_info(dev, "address = %d\n", item->address);
dev_info(dev, "ptype = %d\n", item->ptype);
dev_info(dev, "key :");
for (i = 0; i < ICE_PTYPE_MK_TCAM_KEY_SIZE; i++)
dev_info(dev, "%02x ", item->key[i]);
dev_info(dev, "\n");
dev_info(dev, "key_inv:");
for (i = 0; i < ICE_PTYPE_MK_TCAM_KEY_SIZE; i++)
dev_info(dev, "%02x ", item->key_inv[i]);
dev_info(dev, "\n");
}
static void ice_parse_ptype_mk_tcam_item(struct ice_hw *hw, u16 idx,
void *item, void *data, int size)
{
memcpy(item, data, size);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_ptype_mk_tcam_dump(hw,
(struct ice_ptype_mk_tcam_item *)item);
}
/**
* ice_ptype_mk_tcam_table_get - create a ptype marker tcam table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Marker PType TCAM table.
*/
static
struct ice_ptype_mk_tcam_item *ice_ptype_mk_tcam_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_MARKER_PTYPE,
sizeof(struct ice_ptype_mk_tcam_item),
ICE_PTYPE_MK_TCAM_TABLE_SIZE,
ice_parse_ptype_mk_tcam_item, true);
}
/**
* ice_ptype_mk_tcam_match - match a pattern on a ptype marker tcam table
* @table: ptype marker tcam table to search
* @pat: pattern to match
* @len: length of the pattern
*
* Return: a pointer to the matching Marker PType item or NULL.
*/
struct ice_ptype_mk_tcam_item *
ice_ptype_mk_tcam_match(struct ice_ptype_mk_tcam_item *table,
u8 *pat, int len)
{
int i;
for (i = 0; i < ICE_PTYPE_MK_TCAM_TABLE_SIZE; i++) {
struct ice_ptype_mk_tcam_item *item = &table[i];
if (ice_ternary_match(item->key, item->key_inv, pat, len))
return item;
}
return NULL;
}
/*** ICE_SID_RXPARSER_MARKER_GRP section ***/
/**
* ice_mk_grp_dump - dump an marker group item info
* @hw: pointer to the hardware structure
* @item: marker group item to dump
*/
static void ice_mk_grp_dump(struct ice_hw *hw, struct ice_mk_grp_item *item)
{
struct device *dev = ice_hw_to_dev(hw);
int i;
dev_info(dev, "index = %d\n", item->idx);
dev_info(dev, "markers: ");
for (i = 0; i < ICE_MK_COUNT_PER_GRP; i++)
dev_info(dev, "%d ", item->markers[i]);
dev_info(dev, "\n");
}
static void ice_mk_grp_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_mk_grp_item *grp = item;
u8 *buf = data;
int i;
grp->idx = idx;
for (i = 0; i < ICE_MK_COUNT_PER_GRP; i++)
grp->markers[i] = buf[i];
if (hw->debug_mask & ICE_DBG_PARSER)
ice_mk_grp_dump(hw, grp);
}
/**
* ice_mk_grp_table_get - create a marker group table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Marker Group ID table.
*/
static struct ice_mk_grp_item *ice_mk_grp_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_MARKER_GRP,
sizeof(struct ice_mk_grp_item),
ICE_MK_GRP_TABLE_SIZE,
ice_mk_grp_parse_item, false);
}
/*** ICE_SID_RXPARSER_PROTO_GRP section ***/
static void ice_proto_off_dump(struct ice_hw *hw,
struct ice_proto_off *po, int idx)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "proto %d\n", idx);
dev_info(dev, "\tpolarity = %d\n", po->polarity);
dev_info(dev, "\tproto_id = %d\n", po->proto_id);
dev_info(dev, "\toffset = %d\n", po->offset);
}
/**
* ice_proto_grp_dump - dump a proto group item info
* @hw: pointer to the hardware structure
* @item: proto group item to dump
*/
static void ice_proto_grp_dump(struct ice_hw *hw,
struct ice_proto_grp_item *item)
{
int i;
dev_info(ice_hw_to_dev(hw), "index = %d\n", item->idx);
for (i = 0; i < ICE_PROTO_COUNT_PER_GRP; i++)
ice_proto_off_dump(hw, &item->po[i], i);
}
#define ICE_PO_POL BIT(0)
#define ICE_PO_PID GENMASK(8, 1)
#define ICE_PO_OFF GENMASK(21, 12)
/**
* ice_proto_off_parse - parse 22 bits of Protocol entry
* @po: pointer to the Protocol entry structure
* @data: Protocol entry data to be parsed
*/
static void ice_proto_off_parse(struct ice_proto_off *po, u32 data)
{
po->polarity = FIELD_GET(ICE_PO_POL, data);
po->proto_id = FIELD_GET(ICE_PO_PID, data);
po->offset = FIELD_GET(ICE_PO_OFF, data);
}
/**
* ice_proto_grp_parse_item - parse 192 bits of Protocol Group Table entry
* @hw: pointer to the hardware structure
* @idx: index of Protocol Group Table entry
* @item: item of Protocol Group Table entry
* @data: Protocol Group Table entry data to be parsed
* @size: size of Protocol Group Table entry
*/
static void ice_proto_grp_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_proto_grp_item *grp = item;
u8 *buf = (u8 *)data;
u8 idd, off;
u32 d32;
int i;
grp->idx = idx;
for (i = 0; i < ICE_PROTO_COUNT_PER_GRP; i++) {
idd = (ICE_PROTO_GRP_ITEM_SIZE * i) / BITS_PER_BYTE;
off = (ICE_PROTO_GRP_ITEM_SIZE * i) % BITS_PER_BYTE;
d32 = *((u32 *)&buf[idd]) >> off;
ice_proto_off_parse(&grp->po[i], d32);
}
if (hw->debug_mask & ICE_DBG_PARSER)
ice_proto_grp_dump(hw, grp);
}
/**
* ice_proto_grp_table_get - create a proto group table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Protocol Group table.
*/
static struct ice_proto_grp_item *ice_proto_grp_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_PROTO_GRP,
sizeof(struct ice_proto_grp_item),
ICE_PROTO_GRP_TABLE_SIZE,
ice_proto_grp_parse_item, false);
}
/*** ICE_SID_RXPARSER_FLAG_REDIR section ***/
/**
* ice_flg_rd_dump - dump a flag redirect item info
* @hw: pointer to the hardware structure
* @item: flag redirect item to dump
*/
static void ice_flg_rd_dump(struct ice_hw *hw, struct ice_flg_rd_item *item)
{
struct device *dev = ice_hw_to_dev(hw);
dev_info(dev, "index = %d\n", item->idx);
dev_info(dev, "expose = %d\n", item->expose);
dev_info(dev, "intr_flg_id = %d\n", item->intr_flg_id);
}
#define ICE_FRT_EXPO BIT(0)
#define ICE_FRT_IFID GENMASK(6, 1)
/**
* ice_flg_rd_parse_item - parse 8 bits of Flag Redirect Table entry
* @hw: pointer to the hardware structure
* @idx: index of Flag Redirect Table entry
* @item: item of Flag Redirect Table entry
* @data: Flag Redirect Table entry data to be parsed
* @size: size of Flag Redirect Table entry
*/
static void ice_flg_rd_parse_item(struct ice_hw *hw, u16 idx, void *item,
void *data, int __maybe_unused size)
{
struct ice_flg_rd_item *rdi = item;
u8 d8 = *(u8 *)data;
rdi->idx = idx;
rdi->expose = FIELD_GET(ICE_FRT_EXPO, d8);
rdi->intr_flg_id = FIELD_GET(ICE_FRT_IFID, d8);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_flg_rd_dump(hw, rdi);
}
/**
* ice_flg_rd_table_get - create a flag redirect table
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Flags Redirection table.
*/
static struct ice_flg_rd_item *ice_flg_rd_table_get(struct ice_hw *hw)
{
return ice_parser_create_table(hw, ICE_SID_RXPARSER_FLAG_REDIR,
sizeof(struct ice_flg_rd_item),
ICE_FLG_RD_TABLE_SIZE,
ice_flg_rd_parse_item, false);
}
/**
* ice_flg_redirect - redirect a parser flag to packet flag
* @table: flag redirect table
* @psr_flg: parser flag to redirect
*
* Return: flag or 0 if @psr_flag = 0.
*/
u64 ice_flg_redirect(struct ice_flg_rd_item *table, u64 psr_flg)
{
u64 flg = 0;
int i;
for (i = 0; i < ICE_FLG_RDT_SIZE; i++) {
struct ice_flg_rd_item *item = &table[i];
if (!item->expose)
continue;
if (psr_flg & BIT(item->intr_flg_id))
flg |= BIT(i);
}
return flg;
}
/*** ICE_SID_XLT_KEY_BUILDER_SW, ICE_SID_XLT_KEY_BUILDER_ACL,
* ICE_SID_XLT_KEY_BUILDER_FD and ICE_SID_XLT_KEY_BUILDER_RSS
* sections ***/
static void ice_xlt_kb_entry_dump(struct ice_hw *hw,
struct ice_xlt_kb_entry *entry, int idx)
{
struct device *dev = ice_hw_to_dev(hw);
int i;
dev_info(dev, "key builder entry %d\n", idx);
dev_info(dev, "\txlt1_ad_sel = %d\n", entry->xlt1_ad_sel);
dev_info(dev, "\txlt2_ad_sel = %d\n", entry->xlt2_ad_sel);
for (i = 0; i < ICE_XLT_KB_FLAG0_14_CNT; i++)
dev_info(dev, "\tflg%d_sel = %d\n", i, entry->flg0_14_sel[i]);
dev_info(dev, "\txlt1_md_sel = %d\n", entry->xlt1_md_sel);
dev_info(dev, "\txlt2_md_sel = %d\n", entry->xlt2_md_sel);
}
/**
* ice_xlt_kb_dump - dump a xlt key build info
* @hw: pointer to the hardware structure
* @kb: key build to dump
*/
static void ice_xlt_kb_dump(struct ice_hw *hw, struct ice_xlt_kb *kb)
{
struct device *dev = ice_hw_to_dev(hw);
int i;
dev_info(dev, "xlt1_pm = %d\n", kb->xlt1_pm);
dev_info(dev, "xlt2_pm = %d\n", kb->xlt2_pm);
dev_info(dev, "prof_id_pm = %d\n", kb->prof_id_pm);
dev_info(dev, "flag15 lo = 0x%08x\n", (u32)kb->flag15);
dev_info(dev, "flag15 hi = 0x%08x\n",
(u32)(kb->flag15 >> (sizeof(u32) * BITS_PER_BYTE)));
for (i = 0; i < ICE_XLT_KB_TBL_CNT; i++)
ice_xlt_kb_entry_dump(hw, &kb->entries[i], i);
}
#define ICE_XLT_KB_X1AS_S 32 /* offset for the 1st 64-bits field */
#define ICE_XLT_KB_X1AS_IDD (ICE_XLT_KB_X1AS_S / BITS_PER_BYTE)
#define ICE_XLT_KB_X1AS_OFF (ICE_XLT_KB_X1AS_S % BITS_PER_BYTE)
#define ICE_XLT_KB_X1AS GENMASK_ULL(34 - ICE_XLT_KB_X1AS_S, \
32 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_X2AS GENMASK_ULL(37 - ICE_XLT_KB_X1AS_S, \
35 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_FL00 GENMASK_ULL(46 - ICE_XLT_KB_X1AS_S, \
38 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_FL01 GENMASK_ULL(55 - ICE_XLT_KB_X1AS_S, \
47 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_FL02 GENMASK_ULL(64 - ICE_XLT_KB_X1AS_S, \
56 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_FL03 GENMASK_ULL(73 - ICE_XLT_KB_X1AS_S, \
65 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_FL04 GENMASK_ULL(82 - ICE_XLT_KB_X1AS_S, \
74 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_FL05 GENMASK_ULL(91 - ICE_XLT_KB_X1AS_S, \
83 - ICE_XLT_KB_X1AS_S)
#define ICE_XLT_KB_FL06_S 92 /* offset for the 2nd 64-bits field */
#define ICE_XLT_KB_FL06_IDD (ICE_XLT_KB_FL06_S / BITS_PER_BYTE)
#define ICE_XLT_KB_FL06_OFF (ICE_XLT_KB_FL06_S % BITS_PER_BYTE)
#define ICE_XLT_KB_FL06 GENMASK_ULL(100 - ICE_XLT_KB_FL06_S, \
92 - ICE_XLT_KB_FL06_S)
#define ICE_XLT_KB_FL07 GENMASK_ULL(109 - ICE_XLT_KB_FL06_S, \
101 - ICE_XLT_KB_FL06_S)
#define ICE_XLT_KB_FL08 GENMASK_ULL(118 - ICE_XLT_KB_FL06_S, \
110 - ICE_XLT_KB_FL06_S)
#define ICE_XLT_KB_FL09 GENMASK_ULL(127 - ICE_XLT_KB_FL06_S, \
119 - ICE_XLT_KB_FL06_S)
#define ICE_XLT_KB_FL10 GENMASK_ULL(136 - ICE_XLT_KB_FL06_S, \
128 - ICE_XLT_KB_FL06_S)
#define ICE_XLT_KB_FL11 GENMASK_ULL(145 - ICE_XLT_KB_FL06_S, \
137 - ICE_XLT_KB_FL06_S)
#define ICE_XLT_KB_FL12_S 146 /* offset for the 3rd 64-bits field */
#define ICE_XLT_KB_FL12_IDD (ICE_XLT_KB_FL12_S / BITS_PER_BYTE)
#define ICE_XLT_KB_FL12_OFF (ICE_XLT_KB_FL12_S % BITS_PER_BYTE)
#define ICE_XLT_KB_FL12 GENMASK_ULL(154 - ICE_XLT_KB_FL12_S, \
146 - ICE_XLT_KB_FL12_S)
#define ICE_XLT_KB_FL13 GENMASK_ULL(163 - ICE_XLT_KB_FL12_S, \
155 - ICE_XLT_KB_FL12_S)
#define ICE_XLT_KB_FL14 GENMASK_ULL(181 - ICE_XLT_KB_FL12_S, \
164 - ICE_XLT_KB_FL12_S)
#define ICE_XLT_KB_X1MS GENMASK_ULL(186 - ICE_XLT_KB_FL12_S, \
182 - ICE_XLT_KB_FL12_S)
#define ICE_XLT_KB_X2MS GENMASK_ULL(191 - ICE_XLT_KB_FL12_S, \
187 - ICE_XLT_KB_FL12_S)
/**
* ice_kb_entry_init - parse 192 bits of XLT Key Builder entry
* @entry: pointer to the XLT Key Builder entry structure
* @data: XLT Key Builder entry data to be parsed
*/
static void ice_kb_entry_init(struct ice_xlt_kb_entry *entry, u8 *data)
{
u8 i = 0;
u64 d64;
d64 = *((u64 *)&data[ICE_XLT_KB_X1AS_IDD]) >> ICE_XLT_KB_X1AS_OFF;
entry->xlt1_ad_sel = FIELD_GET(ICE_XLT_KB_X1AS, d64);
entry->xlt2_ad_sel = FIELD_GET(ICE_XLT_KB_X2AS, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL00, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL01, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL02, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL03, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL04, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL05, d64);
d64 = *((u64 *)&data[ICE_XLT_KB_FL06_IDD]) >> ICE_XLT_KB_FL06_OFF;
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL06, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL07, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL08, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL09, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL10, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL11, d64);
d64 = *((u64 *)&data[ICE_XLT_KB_FL12_IDD]) >> ICE_XLT_KB_FL12_OFF;
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL12, d64);
entry->flg0_14_sel[i++] = FIELD_GET(ICE_XLT_KB_FL13, d64);
entry->flg0_14_sel[i] = FIELD_GET(ICE_XLT_KB_FL14, d64);
entry->xlt1_md_sel = FIELD_GET(ICE_XLT_KB_X1MS, d64);
entry->xlt2_md_sel = FIELD_GET(ICE_XLT_KB_X2MS, d64);
}
#define ICE_XLT_KB_X1PM_OFF 0
#define ICE_XLT_KB_X2PM_OFF 1
#define ICE_XLT_KB_PIPM_OFF 2
#define ICE_XLT_KB_FL15_OFF 4
#define ICE_XLT_KB_TBL_OFF 12
/**
* ice_parse_kb_data - parse 204 bits of XLT Key Build Table
* @hw: pointer to the hardware structure
* @kb: pointer to the XLT Key Build Table structure
* @data: XLT Key Build Table data to be parsed
*/
static void ice_parse_kb_data(struct ice_hw *hw, struct ice_xlt_kb *kb,
void *data)
{
u8 *buf = data;
int i;
kb->xlt1_pm = buf[ICE_XLT_KB_X1PM_OFF];
kb->xlt2_pm = buf[ICE_XLT_KB_X2PM_OFF];
kb->prof_id_pm = buf[ICE_XLT_KB_PIPM_OFF];
kb->flag15 = *(u64 *)&buf[ICE_XLT_KB_FL15_OFF];
for (i = 0; i < ICE_XLT_KB_TBL_CNT; i++)
ice_kb_entry_init(&kb->entries[i],
&buf[ICE_XLT_KB_TBL_OFF +
i * ICE_XLT_KB_TBL_ENTRY_SIZE]);
if (hw->debug_mask & ICE_DBG_PARSER)
ice_xlt_kb_dump(hw, kb);
}
static struct ice_xlt_kb *ice_xlt_kb_get(struct ice_hw *hw, u32 sect_type)
{
struct ice_pkg_enum state = {};
struct ice_seg *seg = hw->seg;
struct ice_xlt_kb *kb;
void *data;
if (!seg)
return ERR_PTR(-EINVAL);
kb = kzalloc(sizeof(*kb), GFP_KERNEL);
if (!kb)
return ERR_PTR(-ENOMEM);
data = ice_pkg_enum_section(seg, &state, sect_type);
if (!data) {
ice_debug(hw, ICE_DBG_PARSER, "failed to find section type %d.\n",
sect_type);
kfree(kb);
return ERR_PTR(-EINVAL);
}
ice_parse_kb_data(hw, kb, data);
return kb;
}
/**
* ice_xlt_kb_get_sw - create switch xlt key build
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Key Builder table for Switch.
*/
static struct ice_xlt_kb *ice_xlt_kb_get_sw(struct ice_hw *hw)
{
return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_SW);
}
/**
* ice_xlt_kb_get_acl - create acl xlt key build
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Key Builder table for ACL.
*/
static struct ice_xlt_kb *ice_xlt_kb_get_acl(struct ice_hw *hw)
{
return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_ACL);
}
/**
* ice_xlt_kb_get_fd - create fdir xlt key build
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Key Builder table for Flow Director.
*/
static struct ice_xlt_kb *ice_xlt_kb_get_fd(struct ice_hw *hw)
{
return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_FD);
}
/**
* ice_xlt_kb_get_rss - create rss xlt key build
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated Key Builder table for RSS.
*/
static struct ice_xlt_kb *ice_xlt_kb_get_rss(struct ice_hw *hw)
{
return ice_xlt_kb_get(hw, ICE_SID_XLT_KEY_BUILDER_RSS);
}
#define ICE_XLT_KB_MASK GENMASK_ULL(5, 0)
/**
* ice_xlt_kb_flag_get - aggregate 64 bits packet flag into 16 bits xlt flag
* @kb: xlt key build
* @pkt_flag: 64 bits packet flag
*
* Return: XLT flag or 0 if @pkt_flag = 0.
*/
u16 ice_xlt_kb_flag_get(struct ice_xlt_kb *kb, u64 pkt_flag)
{
struct ice_xlt_kb_entry *entry = &kb->entries[0];
u16 flag = 0;
int i;
/* check flag 15 */
if (kb->flag15 & pkt_flag)
flag = BIT(ICE_XLT_KB_FLAG0_14_CNT);
/* check flag 0 - 14 */
for (i = 0; i < ICE_XLT_KB_FLAG0_14_CNT; i++) {
/* only check first entry */
u16 idx = entry->flg0_14_sel[i] & ICE_XLT_KB_MASK;
if (pkt_flag & BIT(idx))
flag |= (u16)BIT(i);
}
return flag;
}
/*** Parser API ***/
/**
* ice_parser_create - create a parser instance
* @hw: pointer to the hardware structure
*
* Return: a pointer to the allocated parser instance or ERR_PTR
* in case of error.
*/
struct ice_parser *ice_parser_create(struct ice_hw *hw)
{
struct ice_parser *p;
void *err;
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p)
return ERR_PTR(-ENOMEM);
p->hw = hw;
p->rt.psr = p;
p->imem_table = ice_imem_table_get(hw);
if (IS_ERR(p->imem_table)) {
err = p->imem_table;
goto err;
}
p->mi_table = ice_metainit_table_get(hw);
if (IS_ERR(p->mi_table)) {
err = p->mi_table;
goto err;
}
p->pg_cam_table = ice_pg_cam_table_get(hw);
if (IS_ERR(p->pg_cam_table)) {
err = p->pg_cam_table;
goto err;
}
p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
if (IS_ERR(p->pg_sp_cam_table)) {
err = p->pg_sp_cam_table;
goto err;
}
p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
if (IS_ERR(p->pg_nm_cam_table)) {
err = p->pg_nm_cam_table;
goto err;
}
p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
if (IS_ERR(p->pg_nm_sp_cam_table)) {
err = p->pg_nm_sp_cam_table;
goto err;
}
p->bst_tcam_table = ice_bst_tcam_table_get(hw);
if (IS_ERR(p->bst_tcam_table)) {
err = p->bst_tcam_table;
goto err;
}
p->bst_lbl_table = ice_bst_lbl_table_get(hw);
if (IS_ERR(p->bst_lbl_table)) {
err = p->bst_lbl_table;
goto err;
}
p->ptype_mk_tcam_table = ice_ptype_mk_tcam_table_get(hw);
if (IS_ERR(p->ptype_mk_tcam_table)) {
err = p->ptype_mk_tcam_table;
goto err;
}
p->mk_grp_table = ice_mk_grp_table_get(hw);
if (IS_ERR(p->mk_grp_table)) {
err = p->mk_grp_table;
goto err;
}
p->proto_grp_table = ice_proto_grp_table_get(hw);
if (IS_ERR(p->proto_grp_table)) {
err = p->proto_grp_table;
goto err;
}
p->flg_rd_table = ice_flg_rd_table_get(hw);
if (IS_ERR(p->flg_rd_table)) {
err = p->flg_rd_table;
goto err;
}
p->xlt_kb_sw = ice_xlt_kb_get_sw(hw);
if (IS_ERR(p->xlt_kb_sw)) {
err = p->xlt_kb_sw;
goto err;
}
p->xlt_kb_acl = ice_xlt_kb_get_acl(hw);
if (IS_ERR(p->xlt_kb_acl)) {
err = p->xlt_kb_acl;
goto err;
}
p->xlt_kb_fd = ice_xlt_kb_get_fd(hw);
if (IS_ERR(p->xlt_kb_fd)) {
err = p->xlt_kb_fd;
goto err;
}
p->xlt_kb_rss = ice_xlt_kb_get_rss(hw);
if (IS_ERR(p->xlt_kb_rss)) {
err = p->xlt_kb_rss;
goto err;
}
return p;
err:
ice_parser_destroy(p);
return err;
}
/**
* ice_parser_destroy - destroy a parser instance
* @psr: pointer to a parser instance
*/
void ice_parser_destroy(struct ice_parser *psr)
{
kfree(psr->imem_table);
kfree(psr->mi_table);
kfree(psr->pg_cam_table);
kfree(psr->pg_sp_cam_table);
kfree(psr->pg_nm_cam_table);
kfree(psr->pg_nm_sp_cam_table);
kfree(psr->bst_tcam_table);
kfree(psr->bst_lbl_table);
kfree(psr->ptype_mk_tcam_table);
kfree(psr->mk_grp_table);
kfree(psr->proto_grp_table);
kfree(psr->flg_rd_table);
kfree(psr->xlt_kb_sw);
kfree(psr->xlt_kb_acl);
kfree(psr->xlt_kb_fd);
kfree(psr->xlt_kb_rss);
kfree(psr);
}
/**
* ice_parser_run - parse on a packet in binary and return the result
* @psr: pointer to a parser instance
* @pkt_buf: packet data
* @pkt_len: packet length
* @rslt: input/output parameter to save parser result.
*
* Return: 0 on success or errno.
*/
int ice_parser_run(struct ice_parser *psr, const u8 *pkt_buf,
int pkt_len, struct ice_parser_result *rslt)
{
ice_parser_rt_reset(&psr->rt);
ice_parser_rt_pktbuf_set(&psr->rt, pkt_buf, pkt_len);
return ice_parser_rt_execute(&psr->rt, rslt);
}
/**
* ice_parser_result_dump - dump a parser result info
* @hw: pointer to the hardware structure
* @rslt: parser result info to dump
*/
void ice_parser_result_dump(struct ice_hw *hw, struct ice_parser_result *rslt)
{
struct device *dev = ice_hw_to_dev(hw);
int i;
dev_info(dev, "ptype = %d\n", rslt->ptype);
for (i = 0; i < rslt->po_num; i++)
dev_info(dev, "proto = %d, offset = %d\n",
rslt->po[i].proto_id, rslt->po[i].offset);
dev_info(dev, "flags_psr = 0x%016llx\n", rslt->flags_psr);
dev_info(dev, "flags_pkt = 0x%016llx\n", rslt->flags_pkt);
dev_info(dev, "flags_sw = 0x%04x\n", rslt->flags_sw);
dev_info(dev, "flags_fd = 0x%04x\n", rslt->flags_fd);
dev_info(dev, "flags_rss = 0x%04x\n", rslt->flags_rss);
}
#define ICE_BT_VLD_KEY 0xFF
#define ICE_BT_INV_KEY 0xFE
static void ice_bst_dvm_set(struct ice_parser *psr, enum ice_lbl_type type,
bool on)
{
u16 i = 0;
while (true) {
struct ice_bst_tcam_item *item;
u8 key;
item = ice_bst_tcam_search(psr->bst_tcam_table,
psr->bst_lbl_table,
type, &i);
if (!item)
break;
key = on ? ICE_BT_VLD_KEY : ICE_BT_INV_KEY;
item->key[ICE_BT_VM_OFF] = key;
item->key_inv[ICE_BT_VM_OFF] = key;
i++;
}
}
/**
* ice_parser_dvm_set - configure double vlan mode for parser
* @psr: pointer to a parser instance
* @on: true to turn on; false to turn off
*/
void ice_parser_dvm_set(struct ice_parser *psr, bool on)
{
ice_bst_dvm_set(psr, ICE_LBL_BST_TYPE_DVM, on);
ice_bst_dvm_set(psr, ICE_LBL_BST_TYPE_SVM, !on);
}
static int ice_tunnel_port_set(struct ice_parser *psr, enum ice_lbl_type type,
u16 udp_port, bool on)
{
u8 *buf = (u8 *)&udp_port;
u16 i = 0;
while (true) {
struct ice_bst_tcam_item *item;
item = ice_bst_tcam_search(psr->bst_tcam_table,
psr->bst_lbl_table,
type, &i);
if (!item)
break;
/* found empty slot to add */
if (on && item->key[ICE_BT_TUN_PORT_OFF_H] == ICE_BT_INV_KEY &&
item->key_inv[ICE_BT_TUN_PORT_OFF_H] == ICE_BT_INV_KEY) {
item->key_inv[ICE_BT_TUN_PORT_OFF_L] =
buf[ICE_UDP_PORT_OFF_L];
item->key_inv[ICE_BT_TUN_PORT_OFF_H] =
buf[ICE_UDP_PORT_OFF_H];
item->key[ICE_BT_TUN_PORT_OFF_L] =
ICE_BT_VLD_KEY - buf[ICE_UDP_PORT_OFF_L];
item->key[ICE_BT_TUN_PORT_OFF_H] =
ICE_BT_VLD_KEY - buf[ICE_UDP_PORT_OFF_H];
return 0;
/* found a matched slot to delete */
} else if (!on &&
(item->key_inv[ICE_BT_TUN_PORT_OFF_L] ==
buf[ICE_UDP_PORT_OFF_L] ||
item->key_inv[ICE_BT_TUN_PORT_OFF_H] ==
buf[ICE_UDP_PORT_OFF_H])) {
item->key_inv[ICE_BT_TUN_PORT_OFF_L] = ICE_BT_VLD_KEY;
item->key_inv[ICE_BT_TUN_PORT_OFF_H] = ICE_BT_INV_KEY;
item->key[ICE_BT_TUN_PORT_OFF_L] = ICE_BT_VLD_KEY;
item->key[ICE_BT_TUN_PORT_OFF_H] = ICE_BT_INV_KEY;
return 0;
}
i++;
}
return -EINVAL;
}
/**
* ice_parser_vxlan_tunnel_set - configure vxlan tunnel for parser
* @psr: pointer to a parser instance
* @udp_port: vxlan tunnel port in UDP header
* @on: true to turn on; false to turn off
*
* Return: 0 on success or errno on failure.
*/
int ice_parser_vxlan_tunnel_set(struct ice_parser *psr,
u16 udp_port, bool on)
{
return ice_tunnel_port_set(psr, ICE_LBL_BST_TYPE_VXLAN, udp_port, on);
}
/**
* ice_parser_geneve_tunnel_set - configure geneve tunnel for parser
* @psr: pointer to a parser instance
* @udp_port: geneve tunnel port in UDP header
* @on: true to turn on; false to turn off
*
* Return: 0 on success or errno on failure.
*/
int ice_parser_geneve_tunnel_set(struct ice_parser *psr,
u16 udp_port, bool on)
{
return ice_tunnel_port_set(psr, ICE_LBL_BST_TYPE_GENEVE, udp_port, on);
}
/**
* ice_parser_ecpri_tunnel_set - configure ecpri tunnel for parser
* @psr: pointer to a parser instance
* @udp_port: ecpri tunnel port in UDP header
* @on: true to turn on; false to turn off
*
* Return: 0 on success or errno on failure.
*/
int ice_parser_ecpri_tunnel_set(struct ice_parser *psr,
u16 udp_port, bool on)
{
return ice_tunnel_port_set(psr, ICE_LBL_BST_TYPE_UDP_ECPRI,
udp_port, on);
}
/**
* ice_nearest_proto_id - find nearest protocol ID
* @rslt: pointer to a parser result instance
* @offset: a min value for the protocol offset
* @proto_id: the protocol ID (output)
* @proto_off: the protocol offset (output)
*
* From the protocols in @rslt, find the nearest protocol that has offset
* larger than @offset.
*
* Return: if true, the protocol's ID and offset
*/
static bool ice_nearest_proto_id(struct ice_parser_result *rslt, u16 offset,
u8 *proto_id, u16 *proto_off)
{
u16 dist = U16_MAX;
u8 proto = 0;
int i;
for (i = 0; i < rslt->po_num; i++) {
if (offset < rslt->po[i].offset)
continue;
if (offset - rslt->po[i].offset < dist) {
proto = rslt->po[i].proto_id;
dist = offset - rslt->po[i].offset;
}
}
if (dist % 2)
return false;
*proto_id = proto;
*proto_off = dist;
return true;
}
/* default flag mask to cover GTP_EH_PDU, GTP_EH_PDU_LINK and TUN2
* In future, the flag masks should learn from DDP
*/
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_SW 0x4002
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_ACL 0x0000
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_FD 0x6080
#define ICE_KEYBUILD_FLAG_MASK_DEFAULT_RSS 0x6010
/**
* ice_parser_profile_init - initialize a FXP profile based on parser result
* @rslt: a instance of a parser result
* @pkt_buf: packet data buffer
* @msk_buf: packet mask buffer
* @buf_len: packet length
* @blk: FXP pipeline stage
* @prof: input/output parameter to save the profile
*
* Return: 0 on success or errno on failure.
*/
int ice_parser_profile_init(struct ice_parser_result *rslt,
const u8 *pkt_buf, const u8 *msk_buf,
int buf_len, enum ice_block blk,
struct ice_parser_profile *prof)
{
u8 proto_id = U8_MAX;
u16 proto_off = 0;
u16 off;
memset(prof, 0, sizeof(*prof));
set_bit(rslt->ptype, prof->ptypes);
if (blk == ICE_BLK_SW) {
prof->flags = rslt->flags_sw;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_SW;
} else if (blk == ICE_BLK_ACL) {
prof->flags = rslt->flags_acl;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_ACL;
} else if (blk == ICE_BLK_FD) {
prof->flags = rslt->flags_fd;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_FD;
} else if (blk == ICE_BLK_RSS) {
prof->flags = rslt->flags_rss;
prof->flags_msk = ICE_KEYBUILD_FLAG_MASK_DEFAULT_RSS;
} else {
return -EINVAL;
}
for (off = 0; off < buf_len - 1; off++) {
if (msk_buf[off] == 0 && msk_buf[off + 1] == 0)
continue;
if (!ice_nearest_proto_id(rslt, off, &proto_id, &proto_off))
continue;
if (prof->fv_num >= ICE_PARSER_FV_MAX)
return -EINVAL;
prof->fv[prof->fv_num].proto_id = proto_id;
prof->fv[prof->fv_num].offset = proto_off;
prof->fv[prof->fv_num].spec = *(const u16 *)&pkt_buf[off];
prof->fv[prof->fv_num].msk = *(const u16 *)&msk_buf[off];
prof->fv_num++;
}
return 0;
}
/**
* ice_parser_profile_dump - dump an FXP profile info
* @hw: pointer to the hardware structure
* @prof: profile info to dump
*/
void ice_parser_profile_dump(struct ice_hw *hw,
struct ice_parser_profile *prof)
{
struct device *dev = ice_hw_to_dev(hw);
u16 i;
dev_info(dev, "ptypes:\n");
for (i = 0; i < ICE_FLOW_PTYPE_MAX; i++)
if (test_bit(i, prof->ptypes))
dev_info(dev, "\t%u\n", i);
for (i = 0; i < prof->fv_num; i++)
dev_info(dev, "proto = %u, offset = %2u, spec = 0x%04x, mask = 0x%04x\n",
prof->fv[i].proto_id, prof->fv[i].offset,
prof->fv[i].spec, prof->fv[i].msk);
dev_info(dev, "flags = 0x%04x\n", prof->flags);
dev_info(dev, "flags_msk = 0x%04x\n", prof->flags_msk);
}
|