1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2014-2023 Broadcom
* All rights reserved.
*/
#include <rte_log.h>
#include <rte_malloc.h>
#include "bnxt.h"
#include "ulp_template_db_enum.h"
#include "ulp_template_struct.h"
#include "bnxt_tf_common.h"
#include "ulp_utils.h"
#include "bnxt_ulp.h"
#include "bnxt_ulp_utils.h"
#include "tfp.h"
#include "tf_ext_flow_handle.h"
#include "ulp_mark_mgr.h"
#include "ulp_mapper.h"
#include "ulp_flow_db.h"
#include "tf_util.h"
#include "ulp_template_db_tbl.h"
#include "ulp_port_db.h"
#include "ulp_ha_mgr.h"
#include "bnxt_tf_pmd_shim.h"
#ifdef TF_FLOW_SCALE_QUERY
#include "tf_resources.h"
#include "tfc_resources.h"
#endif /* TF_FLOW_SCALE_QUERY */
static uint8_t mapper_fld_zeros[16] = { 0 };
static uint8_t mapper_fld_ones[16] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
static uint8_t mapper_fld_one[16] = {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
};
static int32_t
ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_cond_list_info *info,
int32_t *res);
static const struct ulp_mapper_core_ops *
bnxt_ulp_mapper_ops_get(struct bnxt *bp)
{
int32_t rc;
enum bnxt_ulp_device_id dev_id;
const struct ulp_mapper_core_ops *func_ops;
rc = bnxt_ulp_devid_get(bp, &dev_id);
if (unlikely(rc))
return NULL;
switch (dev_id) {
case BNXT_ULP_DEVICE_ID_THOR2:
func_ops = &ulp_mapper_tfc_core_ops;
break;
case BNXT_ULP_DEVICE_ID_THOR:
case BNXT_ULP_DEVICE_ID_STINGRAY:
case BNXT_ULP_DEVICE_ID_WH_PLUS:
func_ops = &ulp_mapper_tf_core_ops;
break;
default:
func_ops = NULL;
break;
}
return func_ops;
}
static const char *
ulp_mapper_tmpl_name_str(enum bnxt_ulp_template_type tmpl_type)
{
switch (tmpl_type) {
case BNXT_ULP_TEMPLATE_TYPE_CLASS:
return "class";
case BNXT_ULP_TEMPLATE_TYPE_ACTION:
return "action";
default:
return "invalid template type";
}
}
static struct bnxt_ulp_glb_resource_info *
ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
{
if (unlikely(!num_entries))
return NULL;
*num_entries = BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
return ulp_glb_resource_tbl;
}
/*
* Read the global resource from the mapper global resource list
*
* The regval is always returned in big-endian.
*
* returns 0 on success
*/
int32_t
ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
enum tf_dir dir,
uint16_t idx,
uint64_t *regval,
bool *shared)
{
if (unlikely(!mapper_data || !regval || !shared ||
dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_RF_IDX_LAST))
return -EINVAL;
*regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
*shared = mapper_data->glb_res_tbl[dir][idx].shared;
return 0;
}
/*
* Write a global resource to the mapper global resource list
*
* The regval value must be in big-endian.
*
* return 0 on success.
*/
int32_t
ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
struct bnxt_ulp_glb_resource_info *res,
uint64_t regval, bool shared)
{
struct bnxt_ulp_mapper_glb_resource_entry *ent;
/* validate the arguments */
if (unlikely(!data || res->direction >= TF_DIR_MAX ||
res->glb_regfile_index >= BNXT_ULP_GLB_RF_IDX_LAST))
return -EINVAL;
/* write to the mapper data */
ent = &data->glb_res_tbl[res->direction][res->glb_regfile_index];
ent->resource_func = res->resource_func;
ent->resource_type = res->resource_type;
ent->resource_hndl = regval;
ent->shared = shared;
return 0;
}
/*
* Internal function to allocate identity resource and store it in mapper data.
*
* returns 0 on success
*/
int32_t
ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_mapper_data *mapper_data,
struct bnxt_ulp_glb_resource_info *glb_res,
bool shared)
{
const struct ulp_mapper_core_ops *op = mapper_data->mapper_oper;
uint32_t session_type = BNXT_ULP_SESSION_TYPE_DEFAULT;
struct ulp_flow_db_res_params res = { 0 };
uint64_t regval, id = 0;
int32_t rc = 0;
session_type = shared ? BNXT_ULP_SESSION_TYPE_SHARED :
BNXT_ULP_SESSION_TYPE_DEFAULT;
/* Global identifiers are tracked by session */
rc = op->ulp_mapper_core_ident_alloc_process(ulp_ctx,
session_type,
glb_res->resource_type,
glb_res->direction,
CFA_TRACK_TYPE_SID,
&id);
if (unlikely(rc))
return rc;
/* entries are stored as big-endian format */
regval = tfp_cpu_to_be_64(id);
/*
* write to the mapper global resource
* Shared resources are never allocated through this method, so the
* shared flag is always false.
*/
rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, shared);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to write to global resource id\n");
/* Free the identifier when update failed */
res.direction = glb_res->direction;
res.resource_type = glb_res->resource_type;
res.resource_hndl = id;
op->ulp_mapper_core_ident_free(ulp_ctx, &res);
return rc;
}
return rc;
}
/*
* Internal function to allocate index tbl resource and store it in mapper data.
*
* returns 0 on success
*/
int32_t
ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_mapper_data *mapper_data,
struct bnxt_ulp_glb_resource_info *glb_res,
bool shared)
{
const struct ulp_mapper_core_ops *op = mapper_data->mapper_oper;
uint32_t session_type = BNXT_ULP_SESSION_TYPE_DEFAULT;
struct ulp_flow_db_res_params res = { 0 };
uint64_t regval, index = 0;
int32_t rc = 0;
session_type = shared ? BNXT_ULP_SESSION_TYPE_SHARED :
BNXT_ULP_SESSION_TYPE_DEFAULT;
op->ulp_mapper_core_index_tbl_alloc_process(ulp_ctx, session_type,
glb_res->resource_type,
glb_res->direction, &index);
/* entries are stored as big-endian format */
regval = tfp_cpu_to_be_64((uint64_t)index);
/*
* write to the mapper global resource
* Shared resources are never allocated through this method, so the
* shared flag is always false.
*/
rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, shared);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to write to global resource id\n");
/* Free the index when update failed */
res.direction = glb_res->direction;
res.resource_type = glb_res->resource_type;
res.resource_hndl = index;
rc = op->ulp_mapper_core_cmm_entry_free(ulp_ctx, &res, NULL);
return rc;
}
return rc;
}
static int32_t
ulp_mapper_glb_field_tbl_get(struct bnxt_ulp_mapper_parms *parms,
uint32_t operand,
uint8_t *val)
{
uint32_t t_idx;
if (unlikely(operand >= BNXT_ULP_GLB_FIELD_TBL_SIZE)) {
BNXT_DRV_DBG(ERR, "Invalid hdr field index %x:%x\n",
parms->class_tid, operand);
*val = 0;
return -EINVAL; /* error */
}
t_idx = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_HDR_SIG_ID);
*val = ulp_class_match_list[t_idx].field_list[operand];
return 0;
}
/*
* Get the size of the action property for a given index.
*
* idx [in] The index for the action property
*
* returns the size of the action property.
*/
static uint32_t
ulp_mapper_act_prop_size_get(uint32_t idx)
{
if (unlikely(idx >= BNXT_ULP_ACT_PROP_IDX_LAST))
return 0;
return ulp_act_prop_map_table[idx];
}
static struct bnxt_ulp_mapper_cond_list_info *
ulp_mapper_tmpl_reject_list_get(struct bnxt_ulp_mapper_parms *mparms,
uint32_t tid)
{
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
return &dev_tbls->tmpl_list[tid].reject_info;
}
static struct bnxt_ulp_mapper_cond_list_info *
ulp_mapper_cond_oper_list_get(struct bnxt_ulp_mapper_parms *mparms,
uint32_t idx)
{
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
if (unlikely(idx >= dev_tbls->cond_oper_list_size))
return NULL;
return &dev_tbls->cond_oper_list[idx];
}
static struct bnxt_ulp_mapper_cond_info *
ulp_mapper_tmpl_cond_list_get(struct bnxt_ulp_mapper_parms *mparms,
uint32_t idx)
{
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
if (unlikely(idx >= dev_tbls->cond_list_size))
return NULL;
return &dev_tbls->cond_list[idx];
}
/*
* Get a list of classifier tables that implement the flow
* Gets a device dependent list of tables that implement the class template id
*
* mparms [in] The mappers parms with data related to the flow.
*
* tid [in] The template id that matches the flow
*
* num_tbls [out] The number of classifier tables in the returned array
*
* returns An array of classifier tables to implement the flow, or NULL on
* error
*/
static struct bnxt_ulp_mapper_tbl_info *
ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
uint32_t tid,
uint32_t *num_tbls)
{
uint32_t idx;
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
*num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
return &dev_tbls->tbl_list[idx];
}
/*
* Get the list of key fields that implement the flow.
*
* mparms [in] The mapper parms with information about the flow
*
* tbl [in] A single table instance to get the key fields from
*
* num_flds [out] The number of key fields in the returned array
*
* Returns array of Key fields, or NULL on error.
*/
struct bnxt_ulp_mapper_key_info *
ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint32_t *num_flds)
{
uint32_t idx;
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
if (unlikely(!dev_tbls->key_info_list)) {
*num_flds = 0;
return NULL;
}
idx = tbl->key_start_idx;
*num_flds = tbl->key_num_fields;
return &dev_tbls->key_info_list[idx];
}
/*
* Get the list of partial key fields that implement the flow.
*
* mparms [in] The mapper parms with information about the flow
*
* tbl [in] A single table instance to get the key fields from
*
* Return number of partial fields.return 0 if no partial fields
*/
uint32_t
ulp_mapper_partial_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
if (!dev_tbls->key_info_list)
return 0;
return tbl->partial_key_num_fields;
}
/*
* Get the list of data fields that implement the flow.
*
* mparms [in] The mapper parms with information about the flow
*
* tbl [in] A single table instance to get the data fields from
*
* num_flds [out] The number of data fields in the returned array.
*
* num_encap_flds [out] The number of encap fields in the returned array.
*
* Returns array of data fields, or NULL on error.
*/
static struct bnxt_ulp_mapper_field_info *
ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint32_t *num_flds,
uint32_t *num_encap_flds)
{
uint32_t idx;
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
if (unlikely(!dev_tbls->result_field_list)) {
*num_flds = 0;
*num_encap_flds = 0;
return NULL;
}
idx = tbl->result_start_idx;
*num_flds = tbl->result_num_fields;
*num_encap_flds = tbl->encap_num_fields;
return &dev_tbls->result_field_list[idx];
}
/*
* Get the list of ident fields that implement the flow
*
* tbl [in] A single table instance to get the ident fields from
*
* num_flds [out] The number of ident fields in the returned array
*
* returns array of ident fields, or NULL on error
*/
static struct bnxt_ulp_mapper_ident_info *
ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint32_t *num_flds)
{
uint32_t idx;
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
if (unlikely(!dev_tbls->ident_list)) {
*num_flds = 0;
return NULL;
}
idx = tbl->ident_start_idx;
*num_flds = tbl->ident_nums;
return &dev_tbls->ident_list[idx];
}
static struct bnxt_ulp_mapper_field_info *
ulp_mapper_tmpl_key_ext_list_get(struct bnxt_ulp_mapper_parms *mparms,
uint32_t idx)
{
const struct bnxt_ulp_template_device_tbls *dev_tbls;
dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
if (unlikely(idx >= dev_tbls->key_ext_list_size))
return NULL;
return &dev_tbls->key_ext_list[idx];
}
static inline int32_t
ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
struct ulp_flow_db_res_params *res)
{
return ulp_mark_db_mark_del(ulp,
res->resource_type,
res->resource_hndl);
}
static inline int32_t
ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
uint32_t parent_fid,
struct ulp_flow_db_res_params *res)
{
uint32_t pc_idx;
pc_idx = (uint32_t)res->resource_hndl;
/* reset the child flow bitset*/
if (unlikely(ulp_flow_db_pc_db_parent_flow_set(ulp, pc_idx, parent_fid, 0))) {
BNXT_DRV_DBG(ERR, "error in reset parent flow bitset %x:%x\n",
pc_idx, parent_fid);
return -EINVAL;
}
return 0;
}
static inline int32_t
ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
uint32_t child_fid,
struct ulp_flow_db_res_params *res)
{
uint32_t pc_idx;
pc_idx = (uint32_t)res->resource_hndl;
/* reset the child flow bitset*/
if (unlikely(ulp_flow_db_pc_db_child_flow_set(ulp, pc_idx, child_fid, 0))) {
BNXT_DRV_DBG(ERR,
"error in resetting child flow bitset %x:%x\n",
pc_idx, child_fid);
return -EINVAL;
}
return 0;
}
/*
* Process the flow database opcode alloc action.
* returns 0 on success
*/
static int32_t
ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
uint32_t rid = 0;
uint64_t val64;
int32_t rc = 0;
/* allocate a new fid */
rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
BNXT_ULP_FDB_TYPE_RID,
0, &rid);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Unable to allocate flow table entry\n");
return -EINVAL;
}
/* Store the allocated fid in regfile*/
val64 = rid;
rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
tfp_cpu_to_be_64(val64));
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Write regfile[%d] failed\n",
tbl->fdb_operand);
ulp_flow_db_fid_free(parms->ulp_ctx,
BNXT_ULP_FDB_TYPE_RID, rid);
return -EINVAL;
}
/* save the rid into the parms in case a flow fails before pushing the
* rid into the fid
*/
parms->rid = rid;
return 0;
}
/*
* Process the flow database opcode action.
* returns 0 on success.
*/
int32_t
ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
struct ulp_flow_db_res_params *fid_parms)
{
uint32_t push_fid;
uint64_t val64 = 0;
enum bnxt_ulp_fdb_type flow_type;
int32_t rc = 0;
switch (tbl->fdb_opcode) {
case BNXT_ULP_FDB_OPC_PUSH_FID:
push_fid = parms->flow_id;
flow_type = parms->flow_type;
break;
case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
/* get the fid from the regfile */
rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
&val64);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "regfile[%d] read oob\n",
tbl->fdb_operand);
return -EINVAL;
}
/* Use the extracted fid to update the flow resource */
push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
flow_type = BNXT_ULP_FDB_TYPE_RID;
break;
case BNXT_ULP_FDB_OPC_PUSH_FID_SW_ONLY:
push_fid = parms->flow_id;
flow_type = parms->flow_type;
fid_parms->fdb_flags = ULP_FDB_FLAG_SW_ONLY;
break;
default:
return rc; /* Nothing to be done */
}
/* Add the resource to the flow database */
rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
push_fid, fid_parms);
if (unlikely(rc))
BNXT_DRV_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
push_fid, rc);
return rc;
}
/*
* Process the flow database opcode action.
* returns 0 on success.
*/
int32_t
ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint32_t *priority)
{
uint64_t regval = 0;
int32_t rc = 0;
switch (tbl->pri_opcode) {
case BNXT_ULP_PRI_OPC_NOT_USED:
*priority = bnxt_ulp_default_app_priority_get(parms->ulp_ctx);
break;
case BNXT_ULP_PRI_OPC_CONST:
*priority = tbl->pri_operand;
break;
case BNXT_ULP_PRI_OPC_APP_PRI:
*priority = parms->app_priority;
break;
case BNXT_ULP_PRI_OPC_APP_PRI_OR_CONST:
if (parms->app_priority)
*priority = parms->app_priority;
else
*priority = tbl->pri_operand;
break;
case BNXT_ULP_PRI_OPC_REGFILE:
if (unlikely(ulp_regfile_read(parms->regfile, tbl->pri_operand,
®val))) {
BNXT_DRV_DBG(ERR, "regfile[%u] read oob\n",
tbl->pri_operand);
rc = -EINVAL;
}
*priority = (uint32_t)tfp_be_to_cpu_64(regval);
break;
case BNXT_ULP_PRI_OPC_COMP_FIELD:
if (likely(tbl->pri_operand < BNXT_ULP_CF_IDX_LAST)) {
regval = ULP_COMP_FLD_IDX_RD(parms, tbl->pri_operand);
*priority = regval;
} else {
BNXT_DRV_DBG(ERR, "comp field out of bounds %u\n",
tbl->pri_operand);
rc = -EINVAL;
}
break;
default:
BNXT_DRV_DBG(ERR, "Priority opcode not supported %d\n",
tbl->pri_opcode);
rc = -EINVAL;
break;
}
return rc;
}
/*
* Process the identifier list in the given table.
* Extract the ident from the table entry and
* write it to the reg file.
* returns 0 on success.
*/
int32_t
ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint8_t *byte_data,
uint32_t byte_data_size,
enum bnxt_ulp_byte_order byte_order)
{
struct bnxt_ulp_mapper_ident_info *idents;
uint32_t i, num_idents = 0;
uint64_t val64;
/* validate the null arguments */
if (unlikely(!byte_data)) {
BNXT_DRV_DBG(ERR, "invalid argument\n");
return -EINVAL;
}
/* Get the ident list and process each one */
idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
for (i = 0; i < num_idents; i++) {
/* check the size of the buffer for validation */
if (unlikely((idents[i].ident_bit_pos + idents[i].ident_bit_size) >
ULP_BYTE_2_BITS(byte_data_size) ||
idents[i].ident_bit_size > ULP_BYTE_2_BITS(sizeof(val64)))) {
BNXT_DRV_DBG(ERR, "invalid offset or length %x:%x:%x\n",
idents[i].ident_bit_pos,
idents[i].ident_bit_size,
byte_data_size);
return -EINVAL;
}
val64 = 0;
if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
sizeof(val64),
idents[i].ident_bit_pos,
idents[i].ident_bit_size);
else
ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
idents[i].ident_bit_pos,
idents[i].ident_bit_size);
/* Write it to the regfile, val64 is already in big-endian*/
if (unlikely(ulp_regfile_write(parms->regfile,
idents[i].regfile_idx, val64))) {
BNXT_DRV_DBG(ERR, "Regfile[%d] write failed.\n",
idents[i].regfile_idx);
return -EINVAL;
}
}
return 0;
}
/*
* Process the identifier instruction and either store it in the flow database
* or return it in the val (if not NULL) on success. If val is NULL, the
* identifier is to be stored in the flow database.
*/
static int32_t
ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
struct ulp_blob *key,
struct bnxt_ulp_mapper_ident_info *ident,
uint16_t *val)
{
const struct ulp_mapper_core_ops *op = parms->mapper_data->mapper_oper;
struct ulp_flow_db_res_params fid_parms = { 0 };
bool global = false;
uint64_t id = 0;
uint8_t *context;
uint16_t tmplen = 0;
int32_t idx;
int rc;
fid_parms.direction = tbl->direction;
fid_parms.resource_func = ident->resource_func;
fid_parms.resource_type = ident->ident_type;
fid_parms.critical_resource = tbl->critical_resource;
if (tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_GLOBAL_IDENTIFIER)
global = true;
if (!global) {
ulp_flow_db_shared_session_set(&fid_parms, tbl->session_type);
rc = op->ulp_mapper_core_ident_alloc_process(parms->ulp_ctx,
tbl->session_type,
ident->ident_type,
tbl->direction,
tbl->track_type,
&id);
} else {
context = ulp_blob_data_get(key, &tmplen);
tmplen = ULP_BITS_2_BYTE(tmplen);
rc = op->ulp_mapper_core_global_ident_alloc(parms->ulp_ctx,
ident->ident_type,
tbl->direction,
context,
tmplen,
&id);
fid_parms.resource_func = tbl->resource_func;
}
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "identifier process failed\n");
return rc;
}
fid_parms.resource_hndl = id;
idx = ident->regfile_idx;
if (unlikely(ulp_regfile_write(parms->regfile, idx, tfp_cpu_to_be_64(id)))) {
BNXT_DRV_DBG(ERR, "Regfile[%d] write failed.\n", idx);
rc = -EINVAL;
/* Need to free the identifier, so goto error */
goto error;
}
/* Link the resource to the flow in the flow db */
if (!val) {
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to link res to flow rc = %d\n",
rc);
/* Need to free the identifier, so goto error */
goto error;
}
} else {
*val = id;
}
return 0;
error:
/* Need to free the identifier */
if (!global)
op->ulp_mapper_core_ident_free(parms->ulp_ctx, &fid_parms);
else
op->ulp_mapper_core_global_ident_free(parms->ulp_ctx,
&fid_parms);
return rc;
}
static int32_t
ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
uint32_t port_id,
uint16_t val16,
uint8_t **val)
{
enum bnxt_ulp_port_table port_data = val16;
switch (port_data) {
case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
if (unlikely(ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
val))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
if (unlikely(ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
val))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
if (unlikely(ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
val))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
case BNXT_ULP_PORT_TABLE_PORT_IS_PF:
if (unlikely(ulp_port_db_port_is_pf_get(parms->ulp_ctx, port_id,
val))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
case BNXT_ULP_PORT_TABLE_VF_FUNC_METADATA:
if (unlikely(ulp_port_db_port_meta_data_get(parms->ulp_ctx, port_id,
val))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
case BNXT_ULP_PORT_TABLE_TABLE_SCOPE:
if (unlikely(ulp_port_db_port_table_scope_get(parms->ulp_ctx,
port_id, val))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
case BNXT_ULP_PORT_TABLE_VF_FUNC_FID:
if (unlikely(ulp_port_db_port_vf_fid_get(parms->ulp_ctx, port_id, val))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
default:
BNXT_DRV_DBG(ERR, "Invalid port_data %d\n", port_data);
return -EINVAL;
}
return 0;
}
static int32_t
ulp_mapper_field_port_db_write(struct bnxt_ulp_mapper_parms *parms,
uint32_t port_id,
uint16_t idx,
uint8_t *val,
uint32_t length)
{
enum bnxt_ulp_port_table port_data = idx;
uint32_t val32;
switch (port_data) {
case BNXT_ULP_PORT_TABLE_PHY_PORT_MIRROR_ID:
if (ULP_BITS_2_BYTE(length) > sizeof(val32)) {
BNXT_DRV_DBG(ERR, "Invalid data length %u\n", length);
return -EINVAL;
}
memcpy(&val32, val, ULP_BITS_2_BYTE(length));
if (unlikely(ulp_port_db_port_table_mirror_set(parms->ulp_ctx,
port_id,
val32))) {
BNXT_DRV_DBG(ERR, "Invalid port id %u\n", port_id);
return -EINVAL;
}
break;
default:
BNXT_DRV_DBG(ERR, "Invalid port_data %d\n", port_data);
return -EINVAL;
}
return 0;
}
static int32_t
ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
enum bnxt_ulp_field_src field_src,
uint8_t *field_opr,
enum tf_dir dir,
uint8_t is_key,
uint32_t bitlen,
uint8_t **val,
uint32_t *val_len,
uint64_t *value)
{
struct bnxt_ulp_mapper_cond_list_info info = { 0 };
struct bnxt_ulp_mapper_data *m;
uint8_t bit;
uint32_t port_id, val_size, field_size;
uint16_t idx = 0, size_idx = 0, offset = 0;
uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
uint8_t *buffer;
uint64_t lregval;
int32_t cond_res;
bool shared;
uint8_t i = 0;
*val_len = bitlen;
*value = 0;
/* Perform the action */
switch (field_src) {
case BNXT_ULP_FIELD_SRC_ZERO:
*val = mapper_fld_zeros;
break;
case BNXT_ULP_FIELD_SRC_CONST:
*val = field_opr;
break;
case BNXT_ULP_FIELD_SRC_ONES:
*val = mapper_fld_ones;
*value = 1;
break;
case BNXT_ULP_FIELD_SRC_CF:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "CF operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (unlikely(idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t))) {
BNXT_DRV_DBG(ERR, "comp field [%d] read oob %d\n", idx,
bytelen);
return -EINVAL;
}
buffer = (uint8_t *)&parms->comp_fld[idx];
*val = &buffer[sizeof(uint64_t) - bytelen];
*value = ULP_COMP_FLD_IDX_RD(parms, idx);
break;
case BNXT_ULP_FIELD_SRC_RF:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "RF operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
/* Uninitialized regfile entries return 0 */
if (unlikely(ulp_regfile_read(parms->regfile, idx, &lregval)) ||
sizeof(uint64_t) < bytelen) {
BNXT_DRV_DBG(ERR, "regfile[%d] read oob %u\n", idx,
bytelen);
return -EINVAL;
}
buffer = (uint8_t *)&parms->regfile->entry[idx].data;
*val = &buffer[sizeof(uint64_t) - bytelen];
*value = tfp_be_to_cpu_64(lregval);
break;
case BNXT_ULP_FIELD_SRC_ACT_PROP:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Action operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (unlikely(idx >= BNXT_ULP_ACT_PROP_IDX_LAST)) {
BNXT_DRV_DBG(ERR, "act_prop[%d] oob\n", idx);
return -EINVAL;
}
buffer = &parms->act_prop->act_details[idx];
field_size = ulp_mapper_act_prop_size_get(idx);
if (unlikely(bytelen > field_size)) {
BNXT_DRV_DBG(ERR, "act_prop[%d] field size small %u\n",
idx, field_size);
return -EINVAL;
}
*val = &buffer[field_size - bytelen];
if (sizeof(*value) >= field_size) {
*value = buffer[0];
for (i = 1; i < field_size; i++)
*value = (*value << 8) | buffer[i];
}
break;
case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Action sz operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (unlikely(idx >= BNXT_ULP_ACT_PROP_IDX_LAST)) {
BNXT_DRV_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
return -EINVAL;
}
*val = &parms->act_prop->act_details[idx];
/* get the size index next */
if (unlikely(ulp_operand_read(&field_opr[sizeof(uint16_t)],
(uint8_t *)&size_idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Action sz operand read failed\n");
return -EINVAL;
}
size_idx = tfp_be_to_cpu_16(size_idx);
if (unlikely(size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST)) {
BNXT_DRV_DBG(ERR, "act_prop[%d] oob\n", size_idx);
return -EINVAL;
}
memcpy(&val_size, &parms->act_prop->act_details[size_idx],
sizeof(uint32_t));
val_size = tfp_be_to_cpu_32(val_size);
*val_len = ULP_BYTE_2_BITS(val_size);
break;
case BNXT_ULP_FIELD_SRC_GLB_RF:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Global regfile read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (unlikely(ulp_mapper_glb_resource_read(parms->mapper_data,
dir, idx, &lregval, &shared) ||
sizeof(uint64_t) < bytelen)) {
BNXT_DRV_DBG(ERR, "Global regfile[%d] read failed %u\n",
idx, bytelen);
return -EINVAL;
}
m = parms->mapper_data;
buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
*val = &buffer[sizeof(uint64_t) - bytelen];
*value = tfp_be_to_cpu_64(lregval);
break;
case BNXT_ULP_FIELD_SRC_HF:
case BNXT_ULP_FIELD_SRC_SUB_HF:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Header field read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
/* get the index from the global field list */
if (unlikely(ulp_mapper_glb_field_tbl_get(parms, idx, &bit))) {
BNXT_DRV_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
idx);
return -EINVAL;
}
if (is_key)
buffer = parms->hdr_field[bit].spec;
else
buffer = parms->hdr_field[bit].mask;
field_size = parms->hdr_field[bit].size;
if (!field_size) {
/* To support field processing of undefined fields */
*val = mapper_fld_zeros;
break;
} else if (unlikely(bytelen > field_size)) {
BNXT_DRV_DBG(ERR, "Hdr field[%d] size small %u\n",
bit, field_size);
return -EINVAL;
}
if (field_src == BNXT_ULP_FIELD_SRC_HF) {
*val = &buffer[field_size - bytelen];
} else {
/* get the offset next */
if (unlikely(ulp_operand_read(&field_opr[sizeof(uint16_t)],
(uint8_t *)&offset,
sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Hdr fld size read failed\n");
return -EINVAL;
}
offset = tfp_be_to_cpu_16(offset);
offset = ULP_BITS_2_BYTE_NR(offset);
if (unlikely((offset + bytelen) > field_size)) {
BNXT_DRV_DBG(ERR, "Hdr field[%d] oob\n", bit);
return -EINVAL;
}
*val = &buffer[offset];
}
break;
case BNXT_ULP_FIELD_SRC_HDR_BIT:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&lregval, sizeof(uint64_t)))) {
BNXT_DRV_DBG(ERR, "Header bit read failed\n");
return -EINVAL;
}
lregval = tfp_be_to_cpu_64(lregval);
if (unlikely(ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval))) {
*val = mapper_fld_one;
*value = 1;
} else {
*val = mapper_fld_zeros;
}
break;
case BNXT_ULP_FIELD_SRC_ACT_BIT:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&lregval, sizeof(uint64_t)))) {
BNXT_DRV_DBG(ERR, "Action bit read failed\n");
return -EINVAL;
}
lregval = tfp_be_to_cpu_64(lregval);
if (unlikely(ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval))) {
*val = mapper_fld_one;
*value = 1;
} else {
*val = mapper_fld_zeros;
}
break;
case BNXT_ULP_FIELD_SRC_FIELD_BIT:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Field bit read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
/* get the index from the global field list */
if (unlikely(ulp_mapper_glb_field_tbl_get(parms, idx, &bit))) {
BNXT_DRV_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
idx);
return -EINVAL;
}
if (unlikely(ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit))) {
*val = mapper_fld_one;
*value = 1;
} else {
*val = mapper_fld_zeros;
}
break;
case BNXT_ULP_FIELD_SRC_PORT_TABLE:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "CF operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (unlikely(idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t))) {
BNXT_DRV_DBG(ERR, "comp field [%d] read oob %d\n", idx,
bytelen);
return -EINVAL;
}
/* The port id is present in the comp field list */
port_id = ULP_COMP_FLD_IDX_RD(parms, idx);
/* get the port table enum */
if (unlikely(ulp_operand_read(field_opr + sizeof(uint16_t),
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Port table enum read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (unlikely(ulp_mapper_field_port_db_process(parms, port_id, idx,
val))) {
BNXT_DRV_DBG(ERR, "field port table failed\n");
return -EINVAL;
}
break;
case BNXT_ULP_FIELD_SRC_ENC_HDR_BIT:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&lregval, sizeof(uint64_t)))) {
BNXT_DRV_DBG(ERR, "Header bit read failed\n");
return -EINVAL;
}
lregval = tfp_be_to_cpu_64(lregval);
if (ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits, lregval)) {
*val = mapper_fld_one;
*value = 1;
} else {
*val = mapper_fld_zeros;
}
break;
case BNXT_ULP_FIELD_SRC_ENC_FIELD:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Header field read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
/* get the index from the global field list */
if (unlikely(idx >= BNXT_ULP_ENC_FIELD_LAST)) {
BNXT_DRV_DBG(ERR, "invalid encap field tbl idx %d\n",
idx);
return -EINVAL;
}
buffer = parms->enc_field[idx].spec;
field_size = parms->enc_field[idx].size;
if (unlikely(bytelen > field_size)) {
BNXT_DRV_DBG(ERR, "Encap field[%d] size small %u\n",
idx, field_size);
return -EINVAL;
}
*val = &buffer[field_size - bytelen];
break;
case BNXT_ULP_FIELD_SRC_SKIP:
/* do nothing */
*val = mapper_fld_zeros;
*val_len = 0;
break;
case BNXT_ULP_FIELD_SRC_REJECT:
return -EINVAL;
case BNXT_ULP_FIELD_SRC_LIST_AND:
case BNXT_ULP_FIELD_SRC_LIST_OR:
/* read the cond table index and count */
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Cond idx operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
if (unlikely(ulp_operand_read(field_opr + sizeof(uint16_t),
(uint8_t *)&size_idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "Cond count operand read failed\n");
return -EINVAL;
}
size_idx = tfp_be_to_cpu_16(size_idx);
/* populate the extracted vales to create a temp cond list */
if (field_src == BNXT_ULP_FIELD_SRC_LIST_AND)
info.cond_list_opcode = BNXT_ULP_COND_LIST_OPC_AND;
else
info.cond_list_opcode = BNXT_ULP_COND_LIST_OPC_OR;
info.cond_start_idx = idx;
info.cond_nums = size_idx;
if (unlikely(ulp_mapper_cond_opc_list_process(parms, &info, &cond_res))) {
BNXT_DRV_DBG(ERR, "Cond evaluation failed\n");
return -EINVAL;
}
if (cond_res) {
*val = mapper_fld_one;
*value = 1;
} else {
*val = mapper_fld_zeros;
*value = 0;
}
break;
case BNXT_ULP_FIELD_SRC_CF_BIT:
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&lregval, sizeof(uint64_t)))) {
BNXT_DRV_DBG(ERR, "CF operand read failed\n");
return -EINVAL;
}
lregval = tfp_be_to_cpu_64(lregval);
if (unlikely(ULP_BITMAP_ISSET(parms->cf_bitmap, lregval))) {
*val = mapper_fld_one;
*value = 1;
} else {
*val = mapper_fld_zeros;
}
break;
default:
BNXT_DRV_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
return -EINVAL;
}
return 0;
}
static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
uint64_t *output)
{
uint16_t val_16;
uint32_t val_32;
uint64_t val_64;
uint32_t bytelen;
bytelen = ULP_BITS_2_BYTE(bitlen);
if (bytelen == sizeof(uint8_t)) {
*output = *((uint8_t *)buffer);
} else if (bytelen == sizeof(uint16_t)) {
val_16 = *((uint16_t *)buffer);
*output = tfp_be_to_cpu_16(val_16);
} else if (bytelen == sizeof(uint32_t)) {
val_32 = *((uint32_t *)buffer);
*output = tfp_be_to_cpu_32(val_32);
} else if (bytelen == sizeof(val_64)) {
val_64 = *((uint64_t *)buffer);
*output = tfp_be_to_cpu_64(val_64);
} else {
*output = 0;
return -EINVAL;
}
return 0;
}
static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
struct ulp_blob *blob,
uint8_t *val,
uint32_t val_len,
uint8_t **out_val)
{
if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
if (unlikely(ulp_blob_pad_push(blob, val_len) < 0)) {
BNXT_DRV_DBG(ERR, "too large for blob\n");
return -EINVAL;
}
} else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
if (unlikely(ulp_blob_push_encap(blob, val, val_len) < 0)) {
BNXT_DRV_DBG(ERR, "encap blob push failed\n");
return -EINVAL;
}
} else if (fld_src == BNXT_ULP_FIELD_SRC_SKIP) {
/* do nothing */
} else {
if (unlikely(ulp_blob_push(blob, val, val_len))) {
BNXT_DRV_DBG(ERR, "push of val1 failed\n");
return -EINVAL;
}
}
*out_val = val;
return 0;
}
static int32_t
ulp_mapper_field_opc_next(struct bnxt_ulp_mapper_parms *parms,
enum tf_dir dir,
uint8_t *field_opr,
struct ulp_blob *blob,
uint8_t is_key,
const char *name)
{
struct bnxt_ulp_mapper_field_info *field_info;
uint16_t idx = 0;
/* read the cond table index and count */
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "field idx operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
field_info = ulp_mapper_tmpl_key_ext_list_get(parms, idx);
if (unlikely(field_info == NULL)) {
BNXT_DRV_DBG(ERR, "Invalid field idx %d\n", idx);
return -EINVAL;
}
return ulp_mapper_field_opc_process(parms, dir, field_info,
blob, is_key, name);
}
static void
ulp_mapper_key_recipe_tbl_deinit(struct bnxt_ulp_mapper_data *mdata)
{
struct bnxt_ulp_key_recipe_entry **recipes;
enum bnxt_ulp_direction dir;
uint32_t idx, ftype;
/* If recipe table is not initialized then exit */
if (!mdata->key_recipe_info.num_recipes)
return;
for (dir = 0; dir < BNXT_ULP_DIRECTION_LAST; dir++) {
for (ftype = 0; ftype < ULP_RECIPE_TYPE_MAX; ftype++) {
recipes = mdata->key_recipe_info.recipes[dir][ftype];
for (idx = 0; idx < mdata->key_recipe_info.num_recipes;
idx++) {
rte_free(recipes[idx]);
}
rte_free(mdata->key_recipe_info.recipes[dir][ftype]);
mdata->key_recipe_info.recipes[dir][ftype] = NULL;
rte_free(mdata->key_recipe_info.recipe_ba[dir][ftype]);
mdata->key_recipe_info.recipe_ba[dir][ftype] = NULL;
}
}
mdata->key_recipe_info.num_recipes = 0;
}
static int32_t
ulp_mapper_key_recipe_tbl_init(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_mapper_data *mdata)
{
struct bnxt_ulp_key_recipe_entry **recipes;
enum bnxt_ulp_direction dir;
uint32_t dev_id = 0, size_val;
uint32_t num_recipes, ftype, pool_size;
int32_t rc = 0;
struct bitalloc *recipe_ba;
rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Unable to get device id from ulp.\n");
return -EINVAL;
}
num_recipes = bnxt_ulp_num_key_recipes_get(ulp_ctx);
if (!num_recipes)
return rc;
/* Need to write these values so that a failure will result in freeing
* the memory in the deinit
*/
mdata->key_recipe_info.num_recipes = num_recipes;
mdata->key_recipe_info.max_fields = BNXT_ULP_KEY_RECIPE_MAX_FLDS;
size_val = sizeof(struct bnxt_ulp_key_recipe_entry *);
pool_size = BITALLOC_SIZEOF(num_recipes);
/* The caller will deinit if failures occur, so just return fail instead
* of attempting to free allocated memory
**/
for (dir = 0; dir < BNXT_ULP_DIRECTION_LAST; dir++) {
for (ftype = 0; ftype < ULP_RECIPE_TYPE_MAX; ftype++) {
recipes = rte_zmalloc("key_recipe_list",
size_val * num_recipes, 0);
if (unlikely(!recipes)) {
BNXT_DRV_DBG(ERR, "Unable to alloc memory\n");
return -ENOMEM;
}
mdata->key_recipe_info.recipes[dir][ftype] = recipes;
recipe_ba = rte_malloc("key_recipe_ba", pool_size, 0);
if (unlikely(!recipe_ba)) {
BNXT_DRV_DBG(ERR, "Unable to alloc memory\n");
return -ENOMEM;
}
mdata->key_recipe_info.recipe_ba[dir][ftype] =
recipe_ba;
rc = ba_init(recipe_ba, num_recipes, true);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Unable to alloc recipe ba\n");
return -ENOMEM;
}
}
}
return rc;
}
static struct bnxt_ulp_mapper_data *
ulp_mapper_key_recipe_args_validate(struct bnxt_ulp_context *ulp_ctx,
enum bnxt_ulp_direction dir,
enum bnxt_ulp_resource_sub_type stype,
uint32_t recipe_id)
{
struct bnxt_ulp_mapper_data *mdata;
mdata = (struct bnxt_ulp_mapper_data *)
bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
if (unlikely(!mdata)) {
BNXT_DRV_DBG(ERR, "Unable to get mapper data.\n");
return NULL;
}
if (unlikely(dir >= BNXT_ULP_DIRECTION_LAST)) {
BNXT_DRV_DBG(ERR, "Invalid dir (%d) in key recipe\n", dir);
return NULL;
}
if (unlikely(mdata->key_recipe_info.num_recipes == 0)) {
BNXT_DRV_DBG(ERR, "Recipes are not supported\n");
return NULL;
}
if (unlikely(stype != BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_WM &&
stype != BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_EM)) {
BNXT_DRV_DBG(ERR, "Invalid type (%d) in key recipe\n", stype);
return NULL;
}
if (unlikely(recipe_id >= mdata->key_recipe_info.num_recipes ||
!mdata->key_recipe_info.num_recipes)) {
BNXT_DRV_DBG(ERR, "Key recipe id out of range(%u >= %u)\n",
recipe_id, mdata->key_recipe_info.num_recipes);
return NULL;
}
return mdata;
}
static struct bnxt_ulp_key_recipe_entry *
ulp_mapper_key_recipe_alloc(struct bnxt_ulp_context *ulp_ctx,
enum bnxt_ulp_direction dir,
enum bnxt_ulp_resource_sub_type stype,
uint32_t recipe_id, bool alloc_only,
uint8_t *max_fields)
{
struct bnxt_ulp_key_recipe_entry **recipes;
struct bnxt_ulp_mapper_data *mdata = NULL;
uint32_t size_s = sizeof(struct bnxt_ulp_key_recipe_entry);
mdata = ulp_mapper_key_recipe_args_validate(ulp_ctx, dir,
stype, recipe_id);
if (unlikely(mdata == NULL))
return NULL;
recipes = mdata->key_recipe_info.recipes[dir][stype];
if (alloc_only && recipes[recipe_id] == NULL) {
recipes[recipe_id] = rte_zmalloc("key_recipe_entry", size_s, 0);
if (recipes[recipe_id] == NULL) {
BNXT_DRV_DBG(ERR, "Unable to alloc key recipe\n");
return NULL;
}
} else if (alloc_only) {
BNXT_DRV_DBG(ERR, "Recipe ID (%d) already allocated\n",
recipe_id);
}
*max_fields = mdata->key_recipe_info.max_fields;
return recipes[recipe_id];
}
/* The free just marks the entry as not in use and resets the number of entries
* to zero.
*/
static int32_t
ulp_mapper_key_recipe_free(struct bnxt_ulp_context *ulp_ctx,
uint8_t dir,
enum bnxt_ulp_resource_sub_type stype,
uint32_t index)
{
struct bnxt_ulp_key_recipe_entry **recipes;
struct bnxt_ulp_mapper_data *mdata = NULL;
struct bitalloc *recipe_ba = NULL;
int32_t rc;
mdata = ulp_mapper_key_recipe_args_validate(ulp_ctx, dir,
stype, index);
if (unlikely(mdata == NULL))
return -EINVAL;
recipe_ba = mdata->key_recipe_info.recipe_ba[dir][stype];
rc = ba_free(recipe_ba, index);
if (unlikely(rc < 0))
BNXT_DRV_DBG(DEBUG, "Unable to free recipe id[%s][%u] = (%d)\n",
(dir == BNXT_ULP_DIRECTION_INGRESS) ? "rx" : "tx",
stype, index);
recipes = mdata->key_recipe_info.recipes[dir][stype];
if (unlikely(recipes[index] == NULL)) {
BNXT_DRV_DBG(DEBUG, "recipe id[%s][%u] = (%d) already freed\n",
(dir == BNXT_ULP_DIRECTION_INGRESS) ? "rx" : "tx",
stype, index);
return 0;
}
rte_free(recipes[index]);
recipes[index] = NULL;
return 0;
}
static void
ulp_mapper_key_recipe_copy_to_src1(struct bnxt_ulp_mapper_field_info *dst,
enum bnxt_ulp_field_src field_src,
uint8_t *field_opr,
struct bnxt_ulp_mapper_field_info *src,
bool *written)
{
if (field_src != BNXT_ULP_FIELD_SRC_SKIP) {
dst->field_opc = BNXT_ULP_FIELD_OPC_SRC1;
dst->field_src1 = field_src;
memcpy(dst->field_opr1, field_opr, 16);
memcpy(dst->description, src->description, 64);
dst->field_bit_size = src->field_bit_size;
*written = true;
}
}
struct bnxt_ulp_mapper_key_info *
ulp_mapper_key_recipe_fields_get(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint32_t *num_flds)
{
struct bnxt_ulp_key_recipe_entry **recipes;
enum bnxt_ulp_resource_sub_type stype;
struct bnxt_ulp_mapper_data *mdata = NULL;
uint64_t regval = 0;
uint32_t recipe_id = 0;
/* Don't like this, but need to convert from a tbl resource func to the
* subtype for key_recipes.
*/
switch (tbl->resource_func) {
case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
stype = BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_EM;
break;
case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
stype = BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_WM;
break;
default:
BNXT_DRV_DBG(ERR, "Invalid res func(%d) for recipe fields\n",
tbl->resource_func);
return NULL;
};
/* Get the recipe index from the registry file */
if (ulp_regfile_read(parms->regfile, tbl->key_recipe_operand,
®val)) {
BNXT_DRV_DBG(ERR, "Failed to get tbl idx from regfile[%d].\n",
tbl->tbl_operand);
return NULL;
}
recipe_id = (uint32_t)tfp_be_to_cpu_64(regval);
mdata = ulp_mapper_key_recipe_args_validate(parms->ulp_ctx,
tbl->direction,
stype, recipe_id);
if (mdata == NULL)
return NULL;
recipes = mdata->key_recipe_info.recipes[tbl->direction][stype];
if (recipes[recipe_id] == NULL)
return NULL;
*num_flds = recipes[recipe_id]->cnt;
return &recipes[recipe_id]->flds[0];
}
static int32_t
ulp_mapper_key_recipe_field_opc_next(struct bnxt_ulp_mapper_parms *parms,
enum bnxt_ulp_direction dir,
uint8_t *field_opr,
uint8_t is_key,
const char *name,
bool *written,
struct bnxt_ulp_mapper_field_info *ofld)
{
struct bnxt_ulp_mapper_field_info *field_info;
uint16_t idx = 0;
/* read the cond table index and count */
if (unlikely(ulp_operand_read(field_opr,
(uint8_t *)&idx, sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR, "field idx operand read failed\n");
return -EINVAL;
}
idx = tfp_be_to_cpu_16(idx);
field_info = ulp_mapper_tmpl_key_ext_list_get(parms, idx);
if (unlikely(field_info == NULL)) {
BNXT_DRV_DBG(ERR, "Invalid field idx %d\n", idx);
return -EINVAL;
}
return ulp_mapper_key_recipe_field_opc_process(parms, dir, field_info,
is_key, name,
written, ofld);
}
int32_t
ulp_mapper_key_recipe_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
uint8_t dir,
struct bnxt_ulp_mapper_field_info *fld,
uint8_t is_key,
const char *name,
bool *written,
struct bnxt_ulp_mapper_field_info *ofld)
{
uint8_t process_src1 = 0;
uint32_t val1_len = 0;
uint64_t value1 = 0;
int32_t rc = 0;
uint8_t *val1;
/* prepare the field source and values */
switch (fld->field_opc) {
case BNXT_ULP_FIELD_OPC_SRC1:
/* No logic, just take SRC1 and return */
ulp_mapper_key_recipe_copy_to_src1(ofld, fld->field_src1,
fld->field_opr1, fld,
written);
return rc;
case BNXT_ULP_FIELD_OPC_SKIP:
*written = false;
return rc;
case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
case BNXT_ULP_FIELD_OPC_TERNARY_LIST:
process_src1 = 1;
break;
default:
BNXT_DRV_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
rc = -EINVAL;
return rc;
}
/* process the src1 opcode */
if (process_src1) {
if (unlikely(ulp_mapper_field_src_process(parms, fld->field_src1,
fld->field_opr1, dir, is_key,
fld->field_bit_size, &val1,
&val1_len, &value1))) {
BNXT_DRV_DBG(ERR, "fld src1 process failed\n");
return -EINVAL;
}
}
if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
if (value1)
ulp_mapper_key_recipe_copy_to_src1(ofld,
fld->field_src2,
fld->field_opr2,
fld, written);
else
ulp_mapper_key_recipe_copy_to_src1(ofld,
fld->field_src3,
fld->field_opr3,
fld, written);
} else if (fld->field_opc == BNXT_ULP_FIELD_OPC_TERNARY_LIST) {
if (value1) {
/* check if src2 is next */
if (fld->field_src2 == BNXT_ULP_FIELD_SRC_NEXT) {
/* get the next field info */
if (unlikely(ulp_mapper_key_recipe_field_opc_next(parms,
dir,
fld->field_opr2,
is_key,
name,
written,
ofld))) {
BNXT_DRV_DBG(ERR,
"recipe fld next process fail\n");
return -EINVAL;
} else {
return rc;
}
} else {
ulp_mapper_key_recipe_copy_to_src1(ofld,
fld->field_src2,
fld->field_opr2,
fld, written);
}
} else {
/* check if src3 is next */
if (fld->field_src3 == BNXT_ULP_FIELD_SRC_NEXT) {
/* get the next field info */
if (unlikely(ulp_mapper_key_recipe_field_opc_next(parms,
dir,
fld->field_opr3,
is_key,
name,
written,
ofld))) {
BNXT_DRV_DBG(ERR,
"recipt fld next process fail\n");
return -EINVAL;
} else {
return rc;
}
} else {
ulp_mapper_key_recipe_copy_to_src1(ofld,
fld->field_src3,
fld->field_opr3,
fld, written);
}
}
}
return rc;
}
static int32_t
ulp_mapper_key_recipe_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
bool alloc = false, write = false, regfile = false;
struct bnxt_ulp_mapper_key_info *kflds, *rflds;
struct bnxt_ulp_mapper_field_info *kfld, *rfld;
struct bnxt_ulp_mapper_data *mdata = NULL;
struct bnxt_ulp_key_recipe_entry *recipe;
struct ulp_flow_db_res_params fid_parms;
int32_t rc = 0, free_rc, tmp_recipe_id;
enum bnxt_ulp_resource_sub_type stype;
uint8_t max_rflds = 0, rnum_flds = 0;
enum bnxt_ulp_direction dir;
struct bitalloc *recipe_ba = NULL;
uint32_t recipe_id = 0;
uint32_t i, num_kflds;
bool written = false;
uint64_t regval = 0;
dir = tbl->direction;
stype = tbl->resource_sub_type;
switch (tbl->tbl_opcode) {
case BNXT_ULP_KEY_RECIPE_TBL_OPC_ALLOC_WR_REGFILE:
alloc = true;
write = true;
regfile = true;
break;
case BNXT_ULP_KEY_RECIPE_TBL_OPC_ALLOC_REGFILE:
alloc = true;
regfile = true;
break;
case BNXT_ULP_KEY_RECIPE_TBL_OPC_WR_REGFILE:
alloc = false;
regfile = true;
write = true;
break;
default:
BNXT_DRV_DBG(ERR, "Invalid recipe table opcode %d\n",
tbl->tbl_opcode);
return -EINVAL;
};
/* Get the recipe_id from the regfile */
if (!alloc && regfile) {
if (unlikely(ulp_regfile_read(parms->regfile,
tbl->tbl_operand,
®val))) {
BNXT_DRV_DBG(ERR,
"Fail to get tbl idx from regfile[%d].\n",
tbl->tbl_operand);
return -EINVAL;
}
recipe_id = rte_be_to_cpu_64(regval);
}
if (alloc) {
/* Allocate a recipe id based on the direction and type
* only supported types are EM and WC for now.
*/
mdata = ulp_mapper_key_recipe_args_validate(parms->ulp_ctx, dir,
stype, 0);
if (unlikely(mdata == NULL))
return -EINVAL;
recipe_ba = mdata->key_recipe_info.recipe_ba[dir][stype];
tmp_recipe_id = ba_alloc(recipe_ba);
if (unlikely(tmp_recipe_id < 0)) {
BNXT_DRV_DBG(ERR, "Failed to allocate a recipe id\n");
return -EINVAL;
} else if (unlikely((uint32_t)tmp_recipe_id >=
mdata->key_recipe_info.num_recipes)) {
/* Shouldn't get here, but could be an issue with the
* allocator, so free the recipe_id
*/
BNXT_DRV_DBG(ERR,
"Allocated recipe id(%d) >= max(%d)\n",
tmp_recipe_id,
mdata->key_recipe_info.num_recipes);
(void)ba_free(recipe_ba, tmp_recipe_id);
return -EINVAL;
}
/* any error after this must goto error in order to free
* the recipe_id
*/
recipe_id = tmp_recipe_id;
}
if (alloc && regfile) {
regval = rte_cpu_to_be_64(recipe_id);
rc = ulp_regfile_write(parms->regfile, tbl->tbl_operand,
regval);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to write regfile[%d] rc=%d\n",
tbl->tbl_operand, rc);
if (recipe_ba)
(void)ba_free(recipe_ba, recipe_id);
return -EINVAL;
}
}
/* allocate or Get the recipe entry based on alloc */
recipe = ulp_mapper_key_recipe_alloc(parms->ulp_ctx, dir, stype,
recipe_id, alloc, &max_rflds);
if (unlikely(!recipe || !max_rflds)) {
BNXT_DRV_DBG(ERR, "Failed to get the recipe slot\n");
if (recipe_ba)
(void)ba_free(recipe_ba, recipe_id);
return -EINVAL;
}
/* We have a recipe_id by now, write the data */
if (write) {
/* Get the key fields to process */
kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
if (unlikely(!kflds || !num_kflds)) {
BNXT_DRV_DBG(ERR, "Failed to get the key fields\n");
rc = -EINVAL;
goto error;
}
rflds = &recipe->flds[0];
/* iterate over the key fields and write the recipe */
for (i = 0; i < num_kflds; i++) {
if (unlikely(rnum_flds >= max_rflds)) {
BNXT_DRV_DBG(ERR,
"Max recipe fields exceeded (%d)\n",
rnum_flds);
goto error;
}
written = false;
kfld = &kflds[i].field_info_spec;
rfld = &rflds[rnum_flds].field_info_spec;
rc = ulp_mapper_key_recipe_field_opc_process(parms,
dir,
kfld, 1,
"KEY",
&written,
rfld);
if (unlikely(rc))
goto error;
if (stype ==
BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_WM) {
kfld = &kflds[i].field_info_mask;
rfld = &rflds[rnum_flds].field_info_mask;
rc = ulp_mapper_key_recipe_field_opc_process(parms,
dir,
kfld,
0,
"MASK",
&written,
rfld);
if (unlikely(rc))
goto error;
}
if (written)
rnum_flds++;
}
recipe->cnt = rnum_flds;
}
memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_type = tbl->resource_type;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = recipe_id;
fid_parms.critical_resource = tbl->critical_resource;
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to link resource to flow rc = %d\n",
rc);
goto error;
}
return rc;
error:
/* Free the actual recipe */
free_rc = ulp_mapper_key_recipe_free(parms->ulp_ctx, tbl->direction,
tbl->resource_sub_type, recipe_id);
if (free_rc)
BNXT_DRV_DBG(ERR, "Failed to free recipe on error: %d\n",
free_rc);
return rc;
}
int32_t
ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
enum tf_dir dir,
struct bnxt_ulp_mapper_field_info *fld,
struct ulp_blob *blob,
uint8_t is_key,
const char *name)
{
uint16_t write_idx = blob->write_idx;
uint8_t *val = NULL, *val1, *val2, *val3;
uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
uint64_t value1 = 0, value2 = 0, value3 = 0;
int32_t rc = 0;
/* prepare the field source and values */
switch (fld->field_opc) {
case BNXT_ULP_FIELD_OPC_SRC1:
process_src1 = 1;
break;
case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
case BNXT_ULP_FIELD_OPC_TERNARY_LIST:
process_src1 = 1;
break;
case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
process_src3 = 1;
eval_src3 = 1;
process_src1 = 1;
process_src2 = 1;
eval_src1 = 1;
eval_src2 = 1;
break;
case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
process_src1 = 1;
process_src2 = 1;
eval_src1 = 1;
eval_src2 = 1;
break;
default:
break;
}
/* process the src1 opcode */
if (process_src1) {
if (unlikely(ulp_mapper_field_src_process(parms, fld->field_src1,
fld->field_opr1, dir, is_key,
fld->field_bit_size, &val1,
&val1_len, &value1))) {
BNXT_DRV_DBG(ERR, "fld src1 process failed\n");
goto error;
}
if (eval_src1) {
if (unlikely(ulp_mapper_field_buffer_eval(val1, val1_len,
&val1_int))) {
BNXT_DRV_DBG(ERR, "fld src1 eval failed\n");
goto error;
}
}
}
/* for "if then clause" set the correct process */
if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
if (value1)
process_src2 = 1;
else
process_src3 = 1;
} else if (fld->field_opc == BNXT_ULP_FIELD_OPC_TERNARY_LIST) {
if (value1) {
/* check if src2 is next */
if (fld->field_src2 == BNXT_ULP_FIELD_SRC_NEXT) {
/* get the next field info */
if (unlikely(ulp_mapper_field_opc_next(parms, dir,
fld->field_opr2,
blob, is_key,
name))) {
BNXT_DRV_DBG(ERR,
"fld next process fail\n");
goto error;
} else {
return rc;
}
} else {
process_src2 = 1;
}
} else {
/* check if src2 is next */
if (fld->field_src3 == BNXT_ULP_FIELD_SRC_NEXT) {
/* get the next field info */
if (unlikely(ulp_mapper_field_opc_next(parms, dir,
fld->field_opr3,
blob, is_key,
name))) {
BNXT_DRV_DBG(ERR,
"fld next process fail\n");
goto error;
} else {
return rc;
}
} else {
process_src3 = 1;
}
}
}
/* process src2 opcode */
if (process_src2) {
if (unlikely(ulp_mapper_field_src_process(parms, fld->field_src2,
fld->field_opr2, dir, is_key,
fld->field_bit_size, &val2,
&val2_len, &value2))) {
BNXT_DRV_DBG(ERR, "fld src2 process failed\n");
goto error;
}
if (eval_src2) {
if (unlikely(ulp_mapper_field_buffer_eval(val2, val2_len,
&val2_int))) {
BNXT_DRV_DBG(ERR, "fld src2 eval failed\n");
goto error;
}
}
}
/* process src3 opcode */
if (process_src3) {
if (unlikely(ulp_mapper_field_src_process(parms, fld->field_src3,
fld->field_opr3, dir, is_key,
fld->field_bit_size, &val3,
&val3_len, &value3))) {
BNXT_DRV_DBG(ERR, "fld src3 process failed\n");
goto error;
}
if (eval_src3) {
if (unlikely(ulp_mapper_field_buffer_eval(val3, val3_len,
&val3_int))) {
BNXT_DRV_DBG(ERR, "fld src3 eval failed\n");
goto error;
}
}
}
val_len = fld->field_bit_size;
/* process the field opcodes */
switch (fld->field_opc) {
case BNXT_ULP_FIELD_OPC_SRC1:
rc = ulp_mapper_field_blob_write(fld->field_src1,
blob, val1, val1_len, &val);
val_len = val1_len;
break;
case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
case BNXT_ULP_FIELD_OPC_TERNARY_LIST:
if (value1) {
rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
val2, val2_len, &val);
val_len = val2_len;
} else {
rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
val3, val3_len, &val);
val_len = val3_len;
}
break;
case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
val_int = val1_int + val2_int;
val_int = tfp_cpu_to_be_64(val_int);
val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
if (unlikely(!val))
rc = -EINVAL;
break;
case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
val_int = val1_int - val2_int;
val_int = tfp_cpu_to_be_64(val_int);
val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
if (unlikely(!val))
rc = -EINVAL;
break;
case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
val_int = val1_int | val2_int;
val_int = tfp_cpu_to_be_64(val_int);
val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
if (unlikely(!val))
rc = -EINVAL;
break;
case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
val_int = val1_int | val2_int | val3_int;
val_int = tfp_cpu_to_be_64(val_int);
val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
if (unlikely(!val))
rc = -EINVAL;
break;
case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
val_int = val1_int & val2_int;
val_int = tfp_cpu_to_be_64(val_int);
val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
if (unlikely(!val))
rc = -EINVAL;
break;
case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
val_int = val1_int & (val2_int | val3_int);
val_int = tfp_cpu_to_be_64(val_int);
val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
if (unlikely(!val))
rc = -EINVAL;
break;
case BNXT_ULP_FIELD_OPC_SKIP:
break;
default:
BNXT_DRV_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
rc = -EINVAL;
break;
}
if (!rc)
return rc;
error:
BNXT_DRV_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
fld->description, (val) ? write_idx : 0, val_len);
return -EINVAL;
}
/*
* Result table process and fill the result blob.
* data [out] - the result blob data
*/
int32_t
ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
struct ulp_blob *data,
const char *name)
{
struct bnxt_ulp_mapper_field_info *dflds;
uint32_t i = 0, num_flds = 0, encap_flds = 0;
const struct ulp_mapper_core_ops *oper;
struct ulp_blob encap_blob;
int32_t rc = 0;
/* Get the result field list */
dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
&encap_flds);
/* validate the result field list counts */
if (unlikely(!dflds || (!num_flds && !encap_flds))) {
BNXT_DRV_DBG(ERR, "Failed to get data fields %x:%x\n",
num_flds, encap_flds);
return -EINVAL;
}
/* process the result fields */
for (i = 0; i < num_flds; i++) {
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&dflds[i], data, 0, name);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "result field processing failed\n");
return rc;
}
}
/* process encap fields if any */
if (encap_flds) {
uint32_t pad = 0;
/* Initialize the encap blob */
if (unlikely(ulp_blob_init(&encap_blob,
ULP_BYTE_2_BITS(tbl->record_size),
parms->device_params->encap_byte_order))) {
BNXT_DRV_DBG(ERR, "blob inits failed.\n");
return -EINVAL;
}
for (; i < encap_flds; i++) {
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&dflds[i],
&encap_blob, 0, name);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"encap field processing failed\n");
return rc;
}
}
/* add the dynamic pad push */
if (parms->device_params->dynamic_sram_en) {
uint16_t rec_s = ULP_BYTE_2_BITS(tbl->record_size);
uint16_t blob_len;
oper = parms->mapper_data->mapper_oper;
blob_len = ulp_blob_data_len_get(&encap_blob);
/* Get the padding size */
oper->ulp_mapper_core_dyn_tbl_type_get(parms, tbl,
blob_len,
&rec_s);
pad = rec_s - blob_len;
} else {
pad = ULP_BYTE_2_BITS(tbl->record_size) -
ulp_blob_data_len_get(&encap_blob);
}
if (unlikely(ulp_blob_pad_push(&encap_blob, pad) < 0)) {
BNXT_DRV_DBG(ERR, "encap buffer padding failed\n");
return -EINVAL;
}
/* perform the 64 bit byte swap */
ulp_blob_perform_64B_byte_swap(&encap_blob);
/* Append encap blob to the result blob */
rc = ulp_blob_buffer_copy(data, &encap_blob);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "encap buffer copy failed\n");
return rc;
}
}
return rc;
}
int32_t
ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint64_t flow_id)
{
struct ulp_flow_db_res_params fid_parms;
uint32_t mark, gfid, mark_flag;
enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
int32_t rc = 0;
if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
!(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
ULP_BITMAP_ISSET(parms->act_bitmap->bits,
BNXT_ULP_ACT_BIT_MARK)))
return rc; /* no need to perform gfid process */
/* Get the mark id details from action property */
memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
sizeof(mark));
mark = tfp_be_to_cpu_32(mark);
TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
gfid, mark);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to add mark to flow\n");
return rc;
}
fid_parms.direction = tbl->direction;
fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_type = mark_flag;
fid_parms.resource_hndl = gfid;
ulp_flow_db_shared_session_set(&fid_parms, tbl->session_type);
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc))
BNXT_DRV_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
return rc;
}
int32_t
ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms;
uint32_t act_idx, mark, mark_flag;
uint64_t val64 = 0;
enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
int32_t rc = 0;
if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
!(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
ULP_BITMAP_ISSET(parms->act_bitmap->bits,
BNXT_ULP_ACT_BIT_MARK)))
return rc; /* no need to perform mark action process */
/* Get the mark id details from action property */
memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
sizeof(mark));
mark = tfp_be_to_cpu_32(mark);
if (unlikely(ulp_regfile_read(parms->regfile,
BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
&val64))) {
BNXT_DRV_DBG(ERR, "read action ptr main failed\n");
return -EINVAL;
}
act_idx = tfp_be_to_cpu_64(val64);
mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
act_idx, mark);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to add mark to flow\n");
return rc;
}
fid_parms.direction = tbl->direction;
fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_type = mark_flag;
fid_parms.resource_hndl = act_idx;
ulp_flow_db_shared_session_set(&fid_parms, tbl->session_type);
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc))
BNXT_DRV_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
return rc;
}
int32_t
ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms;
uint32_t act_idx, mark, mark_flag;
uint64_t val64 = 0;
enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
int32_t rc = 0;
if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
return rc; /* no need to perform mark action process */
/* Get the mark id details from the computed field of dev port id */
mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
/* Get the main action pointer */
if (unlikely(ulp_regfile_read(parms->regfile,
BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
&val64))) {
BNXT_DRV_DBG(ERR, "read action ptr main failed\n");
return -EINVAL;
}
act_idx = tfp_be_to_cpu_64(val64);
/* Set the mark flag to local fid and vfr flag */
mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
act_idx, mark);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to add mark to flow\n");
return rc;
}
fid_parms.direction = tbl->direction;
fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_type = mark_flag;
fid_parms.resource_hndl = act_idx;
ulp_flow_db_shared_session_set(&fid_parms, tbl->session_type);
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc))
BNXT_DRV_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
return rc;
}
/* Tcam table scan the identifier list and allocate each identifier */
int32_t
ulp_mapper_tcam_tbl_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct bnxt_ulp_mapper_ident_info *idents;
uint32_t num_idents;
uint32_t i;
idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
for (i = 0; i < num_idents; i++) {
if (unlikely(ulp_mapper_ident_process(parms, tbl, NULL,
&idents[i], NULL)))
return -EINVAL;
}
return 0;
}
/*
* internal function to post process key/mask blobs for dynamic pad WC tcam tbl
*
* parms [in] The mappers parms with data related to the flow.
*
* key [in] The original key to be transformed
*
* mask [in] The original mask to be transformed
*
* tkey [in/out] The transformed key
*
* tmask [in/out] The transformed mask
*
* returns zero on success, non-zero on failure
*/
uint32_t
ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
struct ulp_blob *key,
struct ulp_blob *mask,
struct ulp_blob *tkey,
struct ulp_blob *tmask)
{
uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
uint32_t cword, i, rc;
int32_t pad;
uint8_t *val;
slice_width = dparms->wc_slice_width;
clen = dparms->wc_ctl_size_bits;
max_slices = dparms->wc_max_slices;
blen = ulp_blob_data_len_get(key);
/* Get the length of the key based on number of slices and width */
num_slices = 1;
tlen = slice_width;
while (tlen < blen &&
num_slices <= max_slices) {
num_slices = num_slices << 1;
tlen = tlen << 1;
}
if (unlikely(num_slices > max_slices)) {
BNXT_DRV_DBG(ERR, "Key size (%d) too large for WC\n", blen);
return -EINVAL;
}
/* The key/mask may not be on a natural slice boundary, pad it */
pad = tlen - blen;
if (unlikely(ulp_blob_pad_push(key, pad) < 0 ||
ulp_blob_pad_push(mask, pad) < 0)) {
BNXT_DRV_DBG(ERR, "Unable to pad key/mask\n");
return -EINVAL;
}
/* The new length accounts for the ctrl word length and num slices */
tlen = tlen + clen * num_slices;
if (unlikely(ulp_blob_init(tkey, tlen, key->byte_order) ||
ulp_blob_init(tmask, tlen, mask->byte_order))) {
BNXT_DRV_DBG(ERR, "Unable to post process wc tcam entry\n");
return -EINVAL;
}
/* Build the transformed key/mask */
cword = dparms->wc_mode_list[num_slices - 1];
cword = tfp_cpu_to_be_32(cword);
offset = 0;
for (i = 0; i < num_slices; i++) {
val = ulp_blob_push_32(tkey, &cword, clen);
if (unlikely(!val)) {
BNXT_DRV_DBG(ERR, "Key ctrl word push failed\n");
return -EINVAL;
}
val = ulp_blob_push_32(tmask, &cword, clen);
if (unlikely(!val)) {
BNXT_DRV_DBG(ERR, "Mask ctrl word push failed\n");
return -EINVAL;
}
rc = ulp_blob_append(tkey, key, offset, slice_width);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Key blob append failed\n");
return rc;
}
rc = ulp_blob_append(tmask, mask, offset, slice_width);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Mask blob append failed\n");
return rc;
}
offset += slice_width;
}
/* The key/mask are byte reversed on every 4 byte chunk */
ulp_blob_perform_byte_reverse(tkey, 4);
ulp_blob_perform_byte_reverse(tmask, 4);
return 0;
}
/* Post process the key/mask blobs for wildcard tcam tbl */
void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
{
ulp_blob_perform_64B_word_swap(blob);
ulp_blob_perform_64B_byte_swap(blob);
}
static int32_t
ulp_mapper_gen_tbl_ref_cnt_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
struct ulp_mapper_gen_tbl_entry *entry)
{
int32_t rc = 0;
uint64_t val64;
/* Allow the template to manage the reference count */
switch (tbl->ref_cnt_opcode) {
case BNXT_ULP_REF_CNT_OPC_INC:
ULP_GEN_TBL_REF_CNT_INC(entry);
break;
case BNXT_ULP_REF_CNT_OPC_DEC:
/* writes never decrement the ref count */
if (tbl->tbl_opcode == BNXT_ULP_GENERIC_TBL_OPC_WRITE)
return -EINVAL;
ULP_GEN_TBL_REF_CNT_DEC(entry);
break;
case BNXT_ULP_REF_CNT_OPC_NOP:
/* Nothing to be done, generally used when
* template gets the ref_cnt to make a decision
*/
break;
case BNXT_ULP_REF_CNT_OPC_DEFAULT:
/* This is the default case and is backward
* compatible with older templates
*/
if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP)
ULP_GEN_TBL_REF_CNT_INC(entry);
break;
default:
BNXT_DRV_DBG(ERR, "Invalid REF_CNT_OPC %d\n",
tbl->ref_cnt_opcode);
return -EINVAL;
}
if (tbl->tbl_opcode == BNXT_ULP_GENERIC_TBL_OPC_READ) {
/* Add ref_cnt to the regfile for template to use. */
val64 = (uint32_t)ULP_GEN_TBL_REF_CNT(entry);
val64 = tfp_cpu_to_be_64(val64);
rc = ulp_regfile_write(parms->regfile,
BNXT_ULP_RF_IDX_REF_CNT,
val64);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to write regfile[ref_cnt]\n");
return rc;
}
}
return rc;
}
static int32_t
ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_mapper_gen_tbl_list *gen_tbl_list;
struct bnxt_ulp_mapper_key_info *kflds;
struct ulp_flow_db_res_params fid_parms;
struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
struct ulp_gen_hash_entry_params hash_entry;
enum ulp_gen_list_search_flag list_srch = ULP_GEN_LIST_SEARCH_MISSED;
uint16_t keylen, datalen = 0;
struct ulp_blob key, data;
uint8_t *cache_key;
int32_t tbl_idx;
uint32_t i, num_kflds = 0, key_index = 0, num_par_kflds = 0, pad = 0;
uint32_t gen_tbl_miss = 1, fdb_write = 0;
uint8_t *byte_data;
uint64_t regval = 0;
int32_t rc = 0;
/* Get the key fields list and build the key. */
kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
if (unlikely(!kflds || !num_kflds)) {
BNXT_DRV_DBG(ERR, "Failed to get key fields\n");
return -EINVAL;
}
/* Get the partial key list number*/
num_par_kflds = ulp_mapper_partial_key_fields_get(parms, tbl);
if (num_par_kflds)
pad = ULP_BYTE_2_BITS(sizeof(uint8_t)) -
ULP_BITS_IS_BYTE_NOT_ALIGNED(tbl->key_bit_size);
if (unlikely(ulp_blob_init(&key, tbl->key_bit_size + pad +
tbl->partial_key_bit_size,
parms->device_params->key_byte_order))) {
BNXT_DRV_DBG(ERR, "Failed to alloc blob\n");
return -EINVAL;
}
for (i = 0; i < num_kflds + num_par_kflds; i++) {
/* Setup the key */
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&kflds[i].field_info_spec,
&key, 1, "Gen Tbl Key");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to create key for Gen tbl rc=%d\n",
rc);
return -EINVAL;
}
/* pad for the alignment between exact key and partial key */
if (num_par_kflds && i == num_kflds - 1) {
if (unlikely(ulp_blob_pad_push(&key, pad) < 0)) {
BNXT_DRV_DBG(ERR, "key padding failed\n");
return -EINVAL;
}
}
}
/* Calculate the table index for the generic table*/
tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
tbl->direction);
if (unlikely(tbl_idx < 0)) {
BNXT_DRV_DBG(ERR, "Invalid table index %x:%x\n",
tbl->resource_sub_type, tbl->direction);
return -EINVAL;
}
/* The_key is a byte array convert it to a search index */
cache_key = ulp_blob_data_get(&key, &keylen);
/* get the generic table */
gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
/* perform basic validation of generic table */
if (unlikely((gen_tbl_list->tbl_type == BNXT_ULP_GEN_TBL_TYPE_HASH_LIST &&
gen_tbl_list->hash_tbl == NULL) ||
gen_tbl_list->mem_data == NULL)) {
BNXT_DRV_DBG(ERR, "Uninitialized gen table index %x:%x\n",
tbl->resource_sub_type, tbl->direction);
return -EINVAL;
}
/* Check if generic hash table */
if (gen_tbl_list->tbl_type == BNXT_ULP_GEN_TBL_TYPE_HASH_LIST) {
if (unlikely(tbl->gen_tbl_lkup_type !=
BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH)) {
BNXT_DRV_DBG(ERR, "%s: Invalid template lkup type\n",
gen_tbl_list->gen_tbl_name);
return -EINVAL;
}
hash_entry.key_data = cache_key;
hash_entry.key_length = ULP_BITS_2_BYTE(keylen);
rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
&hash_entry);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "%s: hash tbl search failed\n",
gen_tbl_list->gen_tbl_name);
return rc;
}
if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
key_index = hash_entry.key_idx;
/* Get the generic table entry */
if (unlikely(ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
key_index,
&gen_tbl_ent)))
return -EINVAL;
/* store the hash index in the fdb */
key_index = hash_entry.hash_index;
}
} else if (gen_tbl_list->tbl_type == BNXT_ULP_GEN_TBL_TYPE_KEY_LIST) {
/* convert key to index directly */
if (unlikely(ULP_BITS_2_BYTE(keylen) > (int32_t)sizeof(key_index))) {
BNXT_DRV_DBG(ERR, "%s: keysize is bigger then 4 bytes\n",
gen_tbl_list->gen_tbl_name);
return -EINVAL;
}
memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(keylen));
/* Get the generic table entry */
if (unlikely(ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
&gen_tbl_ent)))
return -EINVAL;
} else if (gen_tbl_list->tbl_type ==
BNXT_ULP_GEN_TBL_TYPE_SIMPLE_LIST &&
tbl->tbl_opcode !=
BNXT_ULP_GENERIC_TBL_OPC_ITERATE) {
list_srch = ulp_gen_tbl_simple_list_search(gen_tbl_list,
cache_key,
&key_index);
/* Get the generic table entry */
if (unlikely(ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
key_index,
&gen_tbl_ent)))
return -EINVAL;
}
switch (tbl->tbl_opcode) {
case BNXT_ULP_GENERIC_TBL_OPC_READ:
if (gen_tbl_list->tbl_type == BNXT_ULP_GEN_TBL_TYPE_HASH_LIST &&
gen_tbl_list->hash_tbl) {
if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
break; /* nothing to be done , no entry */
} else if (gen_tbl_list->tbl_type ==
BNXT_ULP_GEN_TBL_TYPE_SIMPLE_LIST) {
if (list_srch == ULP_GEN_LIST_SEARCH_MISSED ||
list_srch == ULP_GEN_LIST_SEARCH_FULL)
break;
}
/* check the reference count */
if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
g = &gen_tbl_ent;
/* Scan ident list and create the result blob*/
rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
g->byte_data,
g->byte_data_size,
g->byte_order);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to scan ident list\n");
return -EINVAL;
}
/* it is a hit */
gen_tbl_miss = 0;
fdb_write = 1;
}
break;
case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
if (gen_tbl_list->tbl_type == BNXT_ULP_GEN_TBL_TYPE_HASH_LIST &&
gen_tbl_list->hash_tbl) {
rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
&hash_entry,
&gen_tbl_ent);
if (unlikely(rc))
return rc;
/* store the hash index in the fdb */
key_index = hash_entry.hash_index;
} else if (gen_tbl_list->tbl_type ==
BNXT_ULP_GEN_TBL_TYPE_SIMPLE_LIST) {
if (unlikely(list_srch == ULP_GEN_LIST_SEARCH_FULL)) {
BNXT_DRV_DBG(ERR, "failed to add gen entry\n");
return -ENOMEM;
}
}
/* check the reference count and ignore ref_cnt if NOP.
* NOP allows a write as an update.
*/
if (unlikely(tbl->ref_cnt_opcode != BNXT_ULP_REF_CNT_OPC_NOP &&
ULP_GEN_TBL_REF_CNT(&gen_tbl_ent))) {
/* a hit then error */
BNXT_DRV_DBG(ERR, "generic entry already present\n");
return -EINVAL; /* success */
}
/* Initialize the blob data */
if (unlikely(ulp_blob_init(&data, tbl->result_bit_size,
gen_tbl_ent.byte_order))) {
BNXT_DRV_DBG(ERR, "Failed initial index table blob\n");
return -EINVAL;
}
/* Get the result fields list */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
"Gen tbl Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
byte_data = ulp_blob_data_get(&data, &datalen);
rc = ulp_mapper_gen_tbl_entry_data_set(gen_tbl_list,
&gen_tbl_ent,
cache_key,
ULP_BITS_2_BYTE(keylen),
byte_data,
ULP_BITS_2_BYTE(datalen)
);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to write generic table\n");
return -EINVAL;
}
fdb_write = 1;
parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
break;
case BNXT_ULP_GENERIC_TBL_OPC_ITERATE:
if (gen_tbl_list->tbl_type !=
BNXT_ULP_GEN_TBL_TYPE_SIMPLE_LIST) {
BNXT_DRV_DBG(ERR, "%s: Invalid table opcode\n",
gen_tbl_list->gen_tbl_name);
return -EINVAL;
}
/* read the gen table index */
if (unlikely(ulp_regfile_read(parms->regfile,
tbl->tbl_operand,
®val))) {
BNXT_DRV_DBG(ERR,
"Fail to get tbl idx from regfile[%d].\n",
BNXT_ULP_RF_IDX_GENERIC_TBL_INDEX);
return -EINVAL;
}
key_index = (uint32_t)rte_be_to_cpu_64(regval);
/* get the next index from the simple list table */
rc = ulp_gen_tbl_simple_list_get_next(gen_tbl_list, &key_index);
if (rc == ULP_GEN_LIST_SEARCH_FOUND) {
gen_tbl_miss = 0; /* entry exits */
regval = key_index;
(void)ulp_regfile_write(parms->regfile,
tbl->tbl_operand,
tfp_cpu_to_be_64(regval));
g = &gen_tbl_ent;
rc = ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
key_index,
&gen_tbl_ent);
if (rc)
return rc;
/* scan the result list and update the regfile values */
rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
g->byte_data,
g->byte_data_size,
g->byte_order);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Fail to scan ident list\n");
return rc;
}
} else {
gen_tbl_miss = 1; /* no more entries */
}
fdb_write = 0;
break;
default:
BNXT_DRV_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
return -EINVAL;
}
/* Set the generic entry hit */
rc = ulp_regfile_write(parms->regfile,
BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
tfp_cpu_to_be_64(gen_tbl_miss));
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Write regfile[%d] failed\n",
BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
return -EIO;
}
/* add the entry to the flow database */
if (fdb_write) {
memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = key_index;
fid_parms.critical_resource = tbl->critical_resource;
ulp_flow_db_shared_session_set(&fid_parms, tbl->session_type);
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Fail to add gen ent flowdb %d\n",
rc);
return rc;
}
/* Reset the in-flight RID when generic table is written and the
* rid has been pushed into a handle (rid or fid). Once it has
* been written, we have persistent accounting of the resources.
*/
if (tbl->tbl_opcode == BNXT_ULP_GENERIC_TBL_OPC_WRITE &&
(tbl->fdb_opcode == BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE ||
tbl->fdb_opcode == BNXT_ULP_FDB_OPC_PUSH_FID))
parms->rid = 0;
rc = ulp_mapper_gen_tbl_ref_cnt_process(parms, tbl,
&gen_tbl_ent);
}
return rc;
}
static int32_t
ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
int32_t rc = 0;
uint64_t val64 = 0;
uint32_t rid;
/* process the fdb opcode for alloc push */
if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to do fdb alloc\n");
return rc;
}
} else if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_DELETE_RID_REGFILE) {
rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand, &val64);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to get RID from regfile\n");
return rc;
}
rid = (uint32_t)tfp_be_to_cpu_64(val64);
rc = ulp_mapper_resources_free(parms->ulp_ctx,
BNXT_ULP_FDB_TYPE_RID,
rid,
NULL);
}
return rc;
}
static int32_t
ulp_mapper_vnic_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms;
uint16_t vnic_idx = 0, vnic_id = 0;
int32_t rc = 0;
switch (tbl->resource_sub_type) {
case BNXT_ULP_RESOURCE_SUB_TYPE_VNIC_TABLE_RSS:
if (unlikely(tbl->tbl_opcode != BNXT_ULP_VNIC_TBL_OPC_ALLOC_WR_REGFILE)) {
BNXT_DRV_DBG(ERR, "Invalid vnic table opcode\n");
return -EINVAL;
}
rc = bnxt_pmd_rss_action_create(parms, &vnic_idx, &vnic_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed create rss action\n");
return rc;
}
break;
case BNXT_ULP_RESOURCE_SUB_TYPE_VNIC_TABLE_QUEUE:
if (unlikely(tbl->tbl_opcode != BNXT_ULP_VNIC_TBL_OPC_ALLOC_WR_REGFILE)) {
BNXT_DRV_DBG(ERR, "Invalid vnic table opcode\n");
return -EINVAL;
}
rc = bnxt_pmd_queue_action_create(parms, &vnic_idx, &vnic_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed create queue action\n");
return rc;
}
break;
default:
BNXT_DRV_DBG(ERR, "Invalid vnic table sub type\n");
return -EINVAL;
}
/* Link the created vnic to the flow in the flow db */
memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_type = tbl->resource_type;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = vnic_idx;
fid_parms.critical_resource = tbl->critical_resource;
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to link resource to flow rc = %d\n",
rc);
return rc;
}
rc = ulp_regfile_write(parms->regfile, tbl->tbl_operand,
(uint64_t)tfp_cpu_to_be_64(vnic_id));
if (unlikely(rc))
BNXT_DRV_DBG(ERR, "Failed to write regfile[%d] rc=%d\n",
tbl->tbl_operand, rc);
return rc;
}
static int32_t
ulp_mapper_stats_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms;
uint64_t counter_handle;
struct ulp_blob data;
uint16_t data_len = 0;
uint8_t *tmp_data;
int32_t rc = 0;
/* Initialize the blob data */
if (unlikely(ulp_blob_init(&data, tbl->result_bit_size,
BNXT_ULP_BYTE_ORDER_BE))) {
BNXT_DRV_DBG(ERR, "Failed initial ulp_global table blob\n");
return -EINVAL;
}
/* read the arguments from the result table */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
"ULP Global Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
tmp_data = ulp_blob_data_get(&data, &data_len);
counter_handle = *(uint64_t *)tmp_data;
counter_handle = tfp_be_to_cpu_64(counter_handle);
memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_type = tbl->resource_type;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = counter_handle;
fid_parms.critical_resource = tbl->critical_resource;
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to link resource to flow rc = %d\n",
rc);
return rc;
}
rc = ulp_sc_mgr_entry_alloc(parms, counter_handle, tbl);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to link resource to flow rc = %d\n",
rc);
return rc;
}
return rc;
}
static int32_t
ulp_mapper_stats_cache_tbl_res_free(struct bnxt_ulp_context *ulp,
uint32_t fid)
{
ulp_sc_mgr_entry_free(ulp, fid);
return 0;
}
static int32_t
ulp_mapper_global_identifier_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
int32_t rc = 0;
struct bnxt_ulp_mapper_ident_info *idents;
struct bnxt_ulp_mapper_key_info *kflds;
struct ulp_blob key;
uint32_t num_idents;
uint32_t num_kflds;
uint32_t i;
/* check the table opcode */
if (tbl->tbl_opcode != BNXT_ULP_GLOBAL_IDENTIFIER_TBL_OPC_ALLOC) {
BNXT_DRV_DBG(ERR, "Invalid global ident table opcode %d\n",
tbl->tbl_opcode);
return -EINVAL;
}
/* Create the key blob */
if (unlikely(ulp_blob_init(&key, tbl->blob_key_bit_size,
BNXT_ULP_BYTE_ORDER_BE))) {
BNXT_DRV_DBG(ERR, "blob init failed.\n");
return -EINVAL;
}
kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
for (i = 0; i < num_kflds; i++) {
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&kflds[i].field_info_spec,
&key, 1, "Global Id Context");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Key field set failed %s\n",
kflds[i].field_info_spec.description);
return rc;
}
}
/* Get the identifiers to process it */
idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
for (i = 0; i < num_idents; i++) {
if (unlikely(ulp_mapper_ident_process(parms, tbl, &key,
&idents[i], NULL)))
return -EINVAL;
}
return rc;
}
static int32_t
ulp_mapper_global_idx_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
const struct ulp_mapper_core_ops *op = parms->mapper_data->mapper_oper;
struct bnxt_ulp_glb_resource_info glb_res = { 0 };
struct ulp_flow_db_res_params fid_parms = { 0 };
struct bnxt_ulp_mapper_key_info *kflds;
struct ulp_blob key;
uint32_t num_kflds = 0;
uint16_t tmplen = 0;
uint64_t idx = 0;
uint8_t *context;
int32_t rc = 0;
uint32_t i;
/* check the table opcode */
if (tbl->tbl_opcode != BNXT_ULP_GLOBAL_IDX_TBL_OPC_ALLOC) {
BNXT_DRV_DBG(ERR, "Invalid global idx table opcode %d",
tbl->tbl_opcode);
return -EINVAL;
}
/* Create the key blob */
if (unlikely(ulp_blob_init(&key, tbl->blob_key_bit_size,
BNXT_ULP_BYTE_ORDER_BE))) {
BNXT_DRV_DBG(ERR, "blob init failed.");
return -EINVAL;
}
kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
for (i = 0; i < num_kflds; i++) {
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&kflds[i].field_info_spec,
&key, 1,
"Global Idx Context");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Key field set failed %s",
kflds[i].field_info_spec.description);
return rc;
}
}
context = ulp_blob_data_get(&key, &tmplen);
tmplen = ULP_BITS_2_BYTE(tmplen);
if (unlikely(!op->ulp_mapper_core_glb_idx_tbl_alloc)) {
BNXT_DRV_DBG(ERR, "global idx tbl process not supported");
return -EINVAL;
}
rc = op->ulp_mapper_core_glb_idx_tbl_alloc(parms->ulp_ctx,
tbl->resource_type,
tbl->direction, context,
tmplen, &idx);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "global idx tbl process failed");
return rc;
}
/* Add the table index to the flow db */
memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_type = tbl->resource_type;
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_hndl = idx;
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Fail to link res to flow rc = %d", rc);
goto error;
}
rc = bnxt_ulp_cntxt_dev_id_get(parms->ulp_ctx, &glb_res.device_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to get device id (%d)", rc);
goto error;
}
rc = bnxt_ulp_cntxt_app_id_get(parms->ulp_ctx, &glb_res.app_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to get app id (%d)", rc);
goto error;
}
glb_res.direction = tbl->direction;
glb_res.resource_func = tbl->resource_func;
glb_res.resource_type = tbl->resource_type;
glb_res.glb_regfile_index = tbl->tbl_operand;
/* Write the table index into the regfile*/
if (ulp_mapper_glb_resource_write(parms->mapper_data, &glb_res,
tfp_cpu_to_be_64(idx), false)) {
BNXT_DRV_DBG(ERR, "Glb Regfile[%d] write failed.",
tbl->tbl_operand);
rc = -EINVAL;
goto error;
}
return rc;
error:
(void)op->ulp_mapper_core_glb_idx_tbl_free(parms->ulp_ctx, &fid_parms);
return rc;
}
/* Free the vnic resource */
static int32_t
ulp_mapper_vnic_tbl_res_free(struct bnxt_ulp_context *ulp __rte_unused,
struct bnxt *bp,
struct ulp_flow_db_res_params *res)
{
uint16_t vnic_idx = res->resource_hndl;
if (res->resource_sub_type ==
BNXT_ULP_RESOURCE_SUB_TYPE_VNIC_TABLE_QUEUE)
return bnxt_pmd_queue_action_delete(bp, vnic_idx);
else
return bnxt_pmd_rss_action_delete(bp, vnic_idx);
}
static int32_t
ulp_mapper_global_res_free(struct bnxt_ulp_context *ulp,
struct bnxt *bp __rte_unused,
struct ulp_flow_db_res_params *res)
{
uint64_t handle = res->resource_hndl;
return bnxt_pmd_global_tunnel_set(ulp, 0, res->resource_sub_type,
0, &handle);
}
static int32_t
ulp_mapper_global_register_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms = { 0 };
struct ulp_blob data;
uint16_t data_len = 0;
uint8_t *tmp_data;
uint16_t udp_port;
uint64_t handle;
int32_t rc = 0, write_reg = 0;
/* Initialize the blob data */
if (unlikely(ulp_blob_init(&data, tbl->result_bit_size,
BNXT_ULP_BYTE_ORDER_BE))) {
BNXT_DRV_DBG(ERR, "Failed initial ulp_global table blob\n");
return -EINVAL;
}
/* read the arguments from the result table */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
"ULP Global Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
switch (tbl->tbl_opcode) {
case BNXT_ULP_GLOBAL_REGISTER_TBL_OPC_WR_REGFILE:
write_reg = 1;
break;
case BNXT_ULP_GLOBAL_REGISTER_TBL_OPC_NOT_USED:
break;
default:
BNXT_DRV_DBG(ERR, "Invalid global table opcode %d\n",
tbl->tbl_opcode);
return -EINVAL;
}
tmp_data = ulp_blob_data_get(&data, &data_len);
udp_port = *((uint16_t *)tmp_data);
udp_port = tfp_be_to_cpu_16(udp_port);
rc = bnxt_pmd_global_tunnel_set(parms->ulp_ctx,
parms->port_id, tbl->resource_sub_type,
udp_port, &handle);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Unable to set Type %d port\n",
tbl->resource_sub_type);
return rc;
}
/* Set the common pieces of fid parms */
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_hndl = handle;
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc))
return rc;
/* write to the regfile if opcode is set */
if (write_reg) {
rc = ulp_regfile_write(parms->regfile,
tbl->tbl_operand,
tfp_cpu_to_be_64(handle));
if (rc)
BNXT_DRV_DBG(ERR, "Regfile[%d] write failed.\n",
tbl->tbl_operand);
}
return rc;
}
static int32_t
ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_mapper_data *mapper_data)
{
struct bnxt_ulp_glb_resource_info *glb_res;
uint32_t num_entries = 0, idx, dev_id;
uint8_t app_id;
int32_t rc = 0;
glb_res = ulp_mapper_glb_resource_info_list_get(&num_entries);
/* Check if there are no resources */
if (!num_entries)
return 0;
rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to get device id for glb init (%d)\n",
rc);
return rc;
}
rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to get app id for glb init (%d)\n",
rc);
return rc;
}
/* Iterate the global resources and process each one */
for (idx = 0; idx < num_entries; idx++) {
if (dev_id != glb_res[idx].device_id ||
glb_res[idx].app_id != app_id)
continue;
switch (glb_res[idx].resource_func) {
case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
mapper_data,
&glb_res[idx],
false);
break;
case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
mapper_data,
&glb_res[idx],
false);
break;
default:
BNXT_DRV_DBG(ERR, "Global resource %x not supported\n",
glb_res[idx].resource_func);
rc = -EINVAL;
break;
}
if (rc)
return rc;
}
return rc;
}
/*
* Iterate over the shared resources assigned during tf_open_session and store
* them in the global regfile with the shared flag.
*/
static int32_t
ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_mapper_data *mapper_data)
{
const struct ulp_mapper_core_ops *op = mapper_data->mapper_oper;
return op->ulp_mapper_core_app_glb_res_info_init(ulp_ctx, mapper_data);
}
/*
* Common conditional opcode process routine that is used for both the template
* rejection and table conditional execution.
*/
static int32_t
ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
enum bnxt_ulp_cond_opc opc,
uint64_t operand,
int32_t *res)
{
enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
uint32_t field_size = 0;
int32_t rc = 0;
uint8_t bit, tmp;
uint64_t regval = 0, result = 0;
switch (opc) {
case BNXT_ULP_COND_OPC_CF_IS_SET:
if (operand < BNXT_ULP_CF_IDX_LAST) {
result = ULP_COMP_FLD_IDX_RD(parms, operand);
} else {
BNXT_DRV_DBG(ERR,
"comp field out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_CF_NOT_SET:
if (likely(operand < BNXT_ULP_CF_IDX_LAST)) {
result = !ULP_COMP_FLD_IDX_RD(parms, operand);
} else {
BNXT_DRV_DBG(ERR,
"comp field out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
if (likely(operand < BNXT_ULP_ACT_BIT_LAST)) {
result = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
operand);
} else {
BNXT_DRV_DBG(ERR,
"action bit out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
if (likely(operand < BNXT_ULP_ACT_BIT_LAST)) {
result = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
operand);
} else {
BNXT_DRV_DBG(ERR,
"action bit out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
if (likely(operand < BNXT_ULP_HDR_BIT_LAST)) {
result = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
operand);
} else {
BNXT_DRV_DBG(ERR,
"header bit out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
if (likely(operand < BNXT_ULP_HDR_BIT_LAST)) {
result = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
operand);
} else {
BNXT_DRV_DBG(ERR,
"header bit out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"invalid ulp_glb_field_tbl idx %" PRIu64 "\n",
operand);
return -EINVAL;
}
result = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
break;
case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"invalid ulp_glb_field_tbl idx %" PRIu64 "\n",
operand);
return -EINVAL;
}
result = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
break;
case BNXT_ULP_COND_OPC_RF_IS_SET:
if (ulp_regfile_read(parms->regfile, operand, ®val)) {
BNXT_DRV_DBG(ERR,
"regfile[%" PRIu64 "] read oob\n",
operand);
return -EINVAL;
}
result = regval != 0;
break;
case BNXT_ULP_COND_OPC_RF_NOT_SET:
if (unlikely(ulp_regfile_read(parms->regfile, operand, ®val))) {
BNXT_DRV_DBG(ERR,
"regfile[%" PRIu64 "] read oob\n", operand);
return -EINVAL;
}
result = regval == 0;
break;
case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
result = parms->flow_pattern_id == operand;
break;
case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
result = parms->act_pattern_id == operand;
break;
case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
if (unlikely(bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype))) {
BNXT_DRV_DBG(ERR, "Failed to get the mem type\n");
return -EINVAL;
}
result = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
break;
case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
if (unlikely(bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype))) {
BNXT_DRV_DBG(ERR, "Failed to get the mem type\n");
return -EINVAL;
}
result = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
break;
case BNXT_ULP_COND_OPC_ENC_HDR_BIT_IS_SET:
if (likely(operand < BNXT_ULP_HDR_BIT_LAST)) {
result = ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
operand);
} else {
BNXT_DRV_DBG(ERR,
"header bit out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_ENC_HDR_BIT_NOT_SET:
if (likely(operand < BNXT_ULP_HDR_BIT_LAST)) {
result = !ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
operand);
} else {
BNXT_DRV_DBG(ERR,
"header bit out of bounds %" PRIu64 "\n",
operand);
rc = -EINVAL;
}
break;
case BNXT_ULP_COND_OPC_ACT_PROP_IS_SET:
case BNXT_ULP_COND_OPC_ACT_PROP_NOT_SET:
/* only supporting 1-byte action properties for now */
if (unlikely(operand >= BNXT_ULP_ACT_PROP_IDX_LAST)) {
BNXT_DRV_DBG(ERR,
"act_prop[%" PRIu64 "] oob\n", operand);
return -EINVAL;
}
field_size = ulp_mapper_act_prop_size_get(operand);
if (unlikely(sizeof(tmp) != field_size)) {
BNXT_DRV_DBG(ERR,
"act_prop[%" PRIu64 "] field mismatch %u\n",
operand, field_size);
return -EINVAL;
}
tmp = parms->act_prop->act_details[operand];
if (opc == BNXT_ULP_COND_OPC_ACT_PROP_IS_SET)
result = (int32_t)(tmp);
else
result = (int32_t)(!tmp);
break;
case BNXT_ULP_COND_OPC_CF_BIT_IS_SET:
case BNXT_ULP_COND_OPC_CF_BIT_NOT_SET:
if (likely(operand < BNXT_ULP_CF_BIT_LAST)) {
result = ULP_BITMAP_ISSET(parms->cf_bitmap, operand);
} else {
BNXT_DRV_DBG(ERR,
"CF bit out of bounds %" PRIx64 "\n",
operand);
rc = -EINVAL;
}
if (opc == BNXT_ULP_COND_OPC_CF_BIT_NOT_SET)
result = !result;
break;
case BNXT_ULP_COND_OPC_WC_FIELD_BIT_IS_SET:
case BNXT_ULP_COND_OPC_WC_FIELD_BIT_NOT_SET:
rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"invalid ulp_glb_field idx %" PRIu64 "\n",
operand);
return -EINVAL;
}
result = ULP_INDEX_BITMAP_GET(parms->wc_field_bitmap, bit);
if (opc == BNXT_ULP_COND_OPC_WC_FIELD_BIT_NOT_SET)
result = !result;
break;
case BNXT_ULP_COND_OPC_EXCLUDE_FIELD_BIT_IS_SET:
case BNXT_ULP_COND_OPC_EXCLUDE_FIELD_BIT_NOT_SET:
rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"invalid ulp_glb_field idx %" PRIu64 "\n",
operand);
return -EINVAL;
}
result = ULP_INDEX_BITMAP_GET(parms->exclude_field_bitmap, bit);
if (opc == BNXT_ULP_COND_OPC_EXCLUDE_FIELD_BIT_NOT_SET)
result = !result;
break;
case BNXT_ULP_COND_OPC_FEATURE_BIT_IS_SET:
case BNXT_ULP_COND_OPC_FEATURE_BIT_NOT_SET:
regval = bnxt_ulp_feature_bits_get(parms->ulp_ctx);
result = ULP_BITMAP_ISSET(regval, operand);
if (opc == BNXT_ULP_COND_OPC_FEATURE_BIT_NOT_SET)
result = !ULP_BITMAP_ISSET(regval, operand);
break;
default:
BNXT_DRV_DBG(ERR, "Invalid conditional opcode %d\n", opc);
rc = -EINVAL;
break;
}
*res = !!result;
return (rc);
}
static int32_t
ulp_mapper_func_opr_compute(struct bnxt_ulp_mapper_parms *parms,
enum tf_dir dir,
enum bnxt_ulp_func_src func_src,
uint64_t func_opr,
uint64_t *result)
{
uint64_t regval;
bool shared;
*result = false;
switch (func_src) {
case BNXT_ULP_FUNC_SRC_COMP_FIELD:
if (unlikely(func_opr >= BNXT_ULP_CF_IDX_LAST)) {
BNXT_DRV_DBG(ERR, "invalid index %u\n",
(uint32_t)func_opr);
return -EINVAL;
}
*result = ULP_COMP_FLD_IDX_RD(parms, func_opr);
break;
case BNXT_ULP_FUNC_SRC_REGFILE:
if (unlikely(ulp_regfile_read(parms->regfile, func_opr, ®val))) {
BNXT_DRV_DBG(ERR, "regfile[%d] read oob\n",
(uint32_t)func_opr);
return -EINVAL;
}
*result = tfp_be_to_cpu_64(regval);
break;
case BNXT_ULP_FUNC_SRC_GLB_REGFILE:
if (unlikely(ulp_mapper_glb_resource_read(parms->mapper_data, dir,
func_opr, ®val, &shared))) {
BNXT_DRV_DBG(ERR, "global regfile[%d] read failed.\n",
(uint32_t)func_opr);
return -EINVAL;
}
*result = tfp_be_to_cpu_64(regval);
break;
case BNXT_ULP_FUNC_SRC_CONST:
*result = func_opr;
break;
case BNXT_ULP_FUNC_SRC_ACTION_BITMAP:
*result = parms->act_bitmap->bits;
break;
case BNXT_ULP_FUNC_SRC_HEADER_BITMAP:
*result = parms->hdr_bitmap->bits;
break;
default:
BNXT_DRV_DBG(ERR, "invalid src code %u\n", func_src);
return -EINVAL;
}
return 0;
}
static int32_t
ulp_mapper_vfr_mark_set(struct bnxt_ulp_mapper_parms *parms,
uint32_t key, uint16_t port_id,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms;
uint32_t mark_flag;
int32_t rc;
/* Set the mark flag to local fid and vfr flag */
mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
key, port_id);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to add mark to flow\n");
return rc;
}
fid_parms.direction = tbl->direction;
fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
fid_parms.critical_resource = tbl->critical_resource;
fid_parms.resource_type = mark_flag;
fid_parms.resource_hndl = key;
fid_parms.resource_sub_type = 0;
ulp_flow_db_shared_session_set(&fid_parms, tbl->session_type);
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (rc) {
int32_t trc = 0;
BNXT_DRV_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
trc = ulp_mark_db_mark_del(parms->ulp_ctx, mark_flag, key);
if (trc)
BNXT_DRV_DBG(ERR,
"Failed to cleanup mark rc = %d\n", rc);
}
return rc;
}
static int32_t
ulp_mapper_bd_act_set(struct bnxt_ulp_mapper_parms *parms __rte_unused,
uint16_t port_id, uint32_t action)
{
return bnxt_pmd_bd_act_set(port_id, action);
}
/* oper size is in bits and res size are in bytes */
static int32_t
ulp_mapper_func_cond_list_process(struct bnxt_ulp_mapper_parms *parms,
uint32_t idx, uint8_t dir,
uint32_t oper_size, uint64_t *res,
uint32_t res_size)
{
struct bnxt_ulp_mapper_field_info *fld;
uint8_t *val = NULL;
uint32_t val_len = 0;
uint64_t value = 0;
uint16_t ext_idx = 0;
uint8_t *res_local = (uint8_t *)res;
/* Get the field info from the key ext list */
fld = ulp_mapper_tmpl_key_ext_list_get(parms, idx);
if (unlikely(fld == NULL || fld->field_opc !=
BNXT_ULP_FIELD_OPC_TERNARY_LIST)) {
BNXT_DRV_DBG(ERR, "Invalid field idx %d\n", idx);
return -EINVAL;
}
/* process the condition list */
if (unlikely(ulp_mapper_field_src_process(parms, fld->field_src1,
fld->field_opr1, dir,
1, oper_size, &val,
&val_len, &value))) {
BNXT_DRV_DBG(ERR, "error processing func opcode %u\n",
idx);
return -EINVAL;
}
if (value) {
if (fld->field_src2 == BNXT_ULP_FIELD_SRC_NEXT) {
/* read the next key ext table index */
if (unlikely(ulp_operand_read(fld->field_opr2,
(uint8_t *)&ext_idx,
sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR,
"field idx operand read failed\n");
return -EINVAL;
}
ext_idx = tfp_be_to_cpu_16(ext_idx);
return ulp_mapper_func_cond_list_process(parms, ext_idx,
dir, oper_size,
res, res_size);
} else {
/* get the value from then part */
if (unlikely(ulp_mapper_field_src_process(parms, fld->field_src2,
fld->field_opr2, dir,
1, oper_size,
&val, &val_len,
&value))) {
BNXT_DRV_DBG(ERR,
"error processing func oper %u\n",
ext_idx);
return -EINVAL;
}
}
} else {
if (fld->field_src3 == BNXT_ULP_FIELD_SRC_NEXT) {
/* read the next key ext table index */
if (unlikely(ulp_operand_read(fld->field_opr3,
(uint8_t *)&ext_idx,
sizeof(uint16_t)))) {
BNXT_DRV_DBG(ERR,
"field idx operand read failed\n");
return -EINVAL;
}
ext_idx = tfp_be_to_cpu_16(ext_idx);
return ulp_mapper_func_cond_list_process(parms, ext_idx,
dir, oper_size,
res, res_size);
} else {
/* get the value from else part */
if (unlikely(ulp_mapper_field_src_process(parms, fld->field_src3,
fld->field_opr3, dir,
1, oper_size,
&val, &val_len,
&value))) {
BNXT_DRV_DBG(ERR,
"error processing func oper %u\n",
ext_idx);
return -EINVAL;
}
}
}
/* write the value into result */
if (unlikely(ulp_operand_read(val, res_local + res_size -
ULP_BITS_2_BYTE_NR(oper_size),
ULP_BITS_2_BYTE_NR(val_len)))) {
BNXT_DRV_DBG(ERR,
"field idx operand read failed\n");
return -EINVAL;
}
/* convert the data to cpu format */
*res = tfp_be_to_cpu_64(*res);
return 0;
}
static int32_t
ulp_mapper_func_info_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
const struct ulp_mapper_core_ops *op = parms->mapper_data->mapper_oper;
struct bnxt_ulp_mapper_func_info *func_info = &tbl->func_info;
uint64_t res = 0, res1 = 0, res2 = 0;
int32_t rc = 0;
uint32_t process_src1 = 0, process_src2 = 0;
/* determine which functional operands to compute */
switch (func_info->func_opc) {
case BNXT_ULP_FUNC_OPC_NOP:
return rc;
case BNXT_ULP_FUNC_OPC_EQ:
case BNXT_ULP_FUNC_OPC_NE:
case BNXT_ULP_FUNC_OPC_GE:
case BNXT_ULP_FUNC_OPC_GT:
case BNXT_ULP_FUNC_OPC_LE:
case BNXT_ULP_FUNC_OPC_LT:
case BNXT_ULP_FUNC_OPC_LEFT_SHIFT:
case BNXT_ULP_FUNC_OPC_RIGHT_SHIFT:
case BNXT_ULP_FUNC_OPC_BIT_OR:
case BNXT_ULP_FUNC_OPC_BIT_AND:
case BNXT_ULP_FUNC_OPC_BIT_XOR:
case BNXT_ULP_FUNC_OPC_LOG_OR:
case BNXT_ULP_FUNC_OPC_LOG_AND:
case BNXT_ULP_FUNC_OPC_ADD:
case BNXT_ULP_FUNC_OPC_SUB:
process_src1 = 1;
process_src2 = 1;
break;
case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
process_src1 = 1;
break;
case BNXT_ULP_FUNC_OPC_HANDLE_TO_OFFSET:
case BNXT_ULP_FUNC_OPC_VFR_MARK_SET:
case BNXT_ULP_FUNC_OPC_BD_ACT_SET:
case BNXT_ULP_FUNC_OPC_MTR_ID_TO_STATS_HANDLE:
case BNXT_ULP_FUNC_OPC_TCAM_SET_PRIORITY:
process_src1 = 1;
process_src2 = 1;
break;
case BNXT_ULP_FUNC_OPC_NOT_NOT:
process_src1 = 1;
case BNXT_ULP_FUNC_OPC_COND_LIST:
case BNXT_ULP_FUNC_OPC_APP_PRIORITY:
case BNXT_ULP_FUNC_OPC_GET_HA_PRIORITY:
break;
case BNXT_ULP_FUNC_OPC_PORT_TABLE:
process_src1 = 1;
process_src2 = 1;
break;
default:
break;
}
if (process_src1) {
rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
func_info->func_src1,
func_info->func_opr1, &res1);
if (rc)
return rc;
}
if (process_src2) {
rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
func_info->func_src2,
func_info->func_opr2, &res2);
if (rc)
return rc;
}
/* perform the functional opcode operations */
switch (func_info->func_opc) {
case BNXT_ULP_FUNC_OPC_EQ:
if (res1 == res2)
res = 1;
break;
case BNXT_ULP_FUNC_OPC_NE:
if (res1 != res2)
res = 1;
break;
case BNXT_ULP_FUNC_OPC_GE:
if (res1 >= res2)
res = 1;
break;
case BNXT_ULP_FUNC_OPC_GT:
if (res1 > res2)
res = 1;
break;
case BNXT_ULP_FUNC_OPC_LE:
if (res1 <= res2)
res = 1;
break;
case BNXT_ULP_FUNC_OPC_LT:
if (res1 < res2)
res = 1;
break;
case BNXT_ULP_FUNC_OPC_LEFT_SHIFT:
res = res1 << res2;
break;
case BNXT_ULP_FUNC_OPC_RIGHT_SHIFT:
res = res1 >> res2;
break;
case BNXT_ULP_FUNC_OPC_ADD:
res = res1 + res2;
break;
case BNXT_ULP_FUNC_OPC_SUB:
res = res1 - res2;
break;
case BNXT_ULP_FUNC_OPC_NOT_NOT:
res = !!res1;
break;
case BNXT_ULP_FUNC_OPC_BIT_AND:
res = res1 & res2;
break;
case BNXT_ULP_FUNC_OPC_BIT_OR:
res = res1 | res2;
break;
case BNXT_ULP_FUNC_OPC_BIT_XOR:
res = res1 ^ res2;
break;
case BNXT_ULP_FUNC_OPC_LOG_AND:
res = res1 && res2;
break;
case BNXT_ULP_FUNC_OPC_LOG_OR:
res = res1 || res2;
break;
case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
res = res1;
break;
case BNXT_ULP_FUNC_OPC_RSS_CONFIG:
/* apply the rss config using pmd method */
return bnxt_rss_config_action_apply(parms);
case BNXT_ULP_FUNC_OPC_GET_PARENT_MAC_ADDR:
rc = bnxt_pmd_get_parent_mac_addr(parms, (uint8_t *)&res);
if (unlikely(rc))
return -EINVAL;
res = tfp_be_to_cpu_64(res);
break;
case BNXT_ULP_FUNC_OPC_HANDLE_TO_OFFSET:
rc = op->ulp_mapper_core_handle_to_offset(parms, res1,
res2, &res);
break;
case BNXT_ULP_FUNC_OPC_VFR_MARK_SET:
/* res1 is key, res2 is portid */
return ulp_mapper_vfr_mark_set(parms, res1, res2, tbl);
case BNXT_ULP_FUNC_OPC_BD_ACT_SET:
/* res1 is port_id, res2 is action */
return ulp_mapper_bd_act_set(parms, res1, res2);
case BNXT_ULP_FUNC_OPC_COND_LIST:
if (unlikely(func_info->func_src1 != BNXT_ULP_FUNC_SRC_KEY_EXT_LIST)) {
BNXT_DRV_DBG(ERR, "invalid func source %u\n",
func_info->func_opc);
return -EINVAL;
}
if (ulp_mapper_func_cond_list_process(parms,
func_info->func_opr1,
tbl->direction,
func_info->func_oper_size,
&res, sizeof(res)))
return -EINVAL;
break;
case BNXT_ULP_FUNC_OPC_PORT_TABLE:
rc = ulp_mapper_field_port_db_write(parms, res1,
func_info->func_dst_opr,
(uint8_t *)&res2,
func_info->func_oper_size);
return rc;
case BNXT_ULP_FUNC_OPC_MTR_ID_TO_STATS_HANDLE:
/* res1 is mtr_id, res2 is stats_id */
return op->ulp_mapper_mtr_stats_hndl_set(parms, res1, res2);
case BNXT_ULP_FUNC_OPC_APP_PRIORITY:
res = parms->app_priority;
break;
case BNXT_ULP_FUNC_OPC_TCAM_SET_PRIORITY:
return op->ulp_mapper_core_tcam_prio_update(parms,
tbl->direction,
tbl->track_type,
CFA_RSUBTYPE_TCAM_WC,
(uint32_t)res1,
(uint16_t)res2);
case BNXT_ULP_FUNC_OPC_GET_HA_PRIORITY:
res = bnxt_ulp_ha_priority_id_get(parms->ulp_ctx);
break;
default:
BNXT_DRV_DBG(ERR, "invalid func code %u\n",
func_info->func_opc);
return -EINVAL;
}
if (unlikely(ulp_regfile_write(parms->regfile, func_info->func_dst_opr,
tfp_cpu_to_be_64(res)))) {
BNXT_DRV_DBG(ERR, "Failed write the func_opc %u\n",
func_info->func_dst_opr);
return -EINVAL;
}
return rc;
}
/*
* Processes a list of conditions and returns both a status and result of the
* list. The status must be checked prior to verifying the result.
*
* returns 0 for success, negative on failure
* returns res = 1 for true, res = 0 for false.
*/
static int32_t
ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_cond_list_info *info,
int32_t *res)
{
struct bnxt_ulp_mapper_cond_info *cond_list;
int32_t rc = 0, trc = 0;
uint32_t i;
switch (info->cond_list_opcode) {
case BNXT_ULP_COND_LIST_OPC_AND:
/* AND Defaults to true. */
*res = 1;
break;
case BNXT_ULP_COND_LIST_OPC_OR:
/* OR Defaults to false. */
*res = 0;
break;
case BNXT_ULP_COND_LIST_OPC_TRUE:
*res = 1;
return rc;
case BNXT_ULP_COND_LIST_OPC_FALSE:
*res = 0;
return rc;
default:
BNXT_DRV_DBG(ERR, "Invalid conditional list opcode %d\n",
info->cond_list_opcode);
*res = 0;
return -EINVAL;
}
cond_list = ulp_mapper_tmpl_cond_list_get(parms, info->cond_start_idx);
for (i = 0; i < info->cond_nums; i++) {
rc = ulp_mapper_cond_opc_process(parms,
cond_list[i].cond_opcode,
cond_list[i].cond_operand,
&trc);
if (unlikely(rc))
return rc;
if (info->cond_list_opcode == BNXT_ULP_COND_LIST_OPC_AND) {
/* early return if result is ever zero */
if (!trc) {
*res = trc;
return rc;
}
} else {
/* early return if result is ever non-zero */
if (trc) {
*res = trc;
return rc;
}
}
}
return rc;
}
static int32_t
ulp_mapper_cond_reject_list_process(struct bnxt_ulp_mapper_parms *parms,
uint32_t tid, int32_t *res)
{
struct bnxt_ulp_mapper_cond_list_info *reject_info;
struct bnxt_ulp_mapper_cond_list_info *oper;
int32_t cond_list_res = 0, cond_res = 0, rc = 0;
uint32_t idx;
/* set the rejection result to accept */
*res = 0;
/* get the reject condition list */
reject_info = ulp_mapper_tmpl_reject_list_get(parms, tid);
if (reject_info->cond_list_opcode == BNXT_ULP_COND_LIST_OPC_TRUE) {
cond_list_res = 1;
goto jump_exit;
}
/* If there are no reject conditions then skip */
if (!reject_info->cond_nums)
return rc;
/* Iterate the list to process the conditions */
if (reject_info->cond_list_opcode == BNXT_ULP_COND_LIST_OPC_LIST_AND ||
reject_info->cond_list_opcode == BNXT_ULP_COND_LIST_OPC_LIST_OR) {
/* Initialize the cond result */
if (reject_info->cond_list_opcode ==
BNXT_ULP_COND_LIST_OPC_LIST_AND)
cond_res = 1;
for (idx = reject_info->cond_start_idx;
idx < reject_info->cond_start_idx +
reject_info->cond_nums; idx++) {
oper = ulp_mapper_cond_oper_list_get(parms, idx);
if (unlikely(!oper)) {
BNXT_DRV_DBG(ERR,
"Invalid cond oper idx %d\n",
idx);
return -EINVAL;
}
rc = ulp_mapper_cond_opc_list_process(parms, oper,
&cond_list_res);
/* if any error, then return */
if (rc)
goto jump_exit;
/* early return if result is ever zero */
if (cond_res /*and */ && !cond_list_res /*false*/)
goto jump_exit;
/* early return if result is ever non-zero */
if (!cond_res /*or */ && cond_list_res /*true*/)
goto jump_exit;
}
} else {
rc = ulp_mapper_cond_opc_list_process(parms, reject_info,
&cond_list_res);
}
jump_exit:
*res = cond_list_res;
/* Reject the template if True */
if (cond_list_res)
BNXT_DRV_DBG(ERR, "%s Template %d rejected.\n",
ulp_mapper_tmpl_name_str(parms->tmpl_type), tid);
return rc;
}
static int32_t
ulp_mapper_cond_execute_list_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
int32_t *res)
{
struct bnxt_ulp_mapper_cond_list_info *execute_info;
struct bnxt_ulp_mapper_cond_list_info *oper;
int32_t cond_list_res = 0, cond_res = 0, rc = 0;
uint32_t idx;
/* set the execute result to true */
*res = 1;
execute_info = &tbl->execute_info;
/* If there are no execute conditions then skip */
if (!execute_info->cond_nums)
return rc;
/* Iterate the list to process the conditions */
if (execute_info->cond_list_opcode == BNXT_ULP_COND_LIST_OPC_LIST_AND ||
execute_info->cond_list_opcode == BNXT_ULP_COND_LIST_OPC_LIST_OR) {
/* Initialize the cond result */
if (execute_info->cond_list_opcode ==
BNXT_ULP_COND_LIST_OPC_LIST_AND)
cond_res = 1;
for (idx = execute_info->cond_start_idx;
idx < execute_info->cond_start_idx +
execute_info->cond_nums; idx++) {
oper = ulp_mapper_cond_oper_list_get(parms, idx);
if (unlikely(!oper)) {
BNXT_DRV_DBG(ERR,
"Invalid cond oper idx %d\n",
idx);
return -EINVAL;
}
rc = ulp_mapper_cond_opc_list_process(parms, oper,
&cond_list_res);
/* if any error, then return */
if (rc)
goto jump_exit;
/* early return if result is ever zero */
if (cond_res /*and */ && !cond_list_res /*false*/)
goto jump_exit;
/* early return if result is ever non-zero */
if (!cond_res /*or */ && cond_list_res /*true*/)
goto jump_exit;
}
} else {
rc = ulp_mapper_cond_opc_list_process(parms, execute_info,
&cond_list_res);
}
jump_exit:
*res = cond_list_res;
return rc;
}
/*
* Processes conflict resolution and returns both a status and result.
* The status must be checked prior to verifying the result.
*
* returns 0 for success, negative on failure
* returns res = 1 for true, res = 0 for false.
*/
static int32_t
ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
int32_t *res)
{
int32_t rc = 0;
uint64_t regval = 0;
uint64_t comp_sig;
*res = 0;
switch (tbl->accept_opcode) {
case BNXT_ULP_ACCEPT_OPC_ALWAYS:
*res = 1;
break;
case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
/* perform the signature validation*/
if (tbl->resource_func ==
BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
/* Perform the check that generic table is hit or not */
if (unlikely(ulp_regfile_read(parms->regfile,
BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
®val))) {
BNXT_DRV_DBG(ERR, "regfile[%d] read oob\n",
BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
return -EINVAL;
}
if (regval) {
/* not a hit so no need to check flow sign*/
*res = 1;
return rc;
}
}
/* compare the new flow signature against stored one */
if (unlikely(ulp_regfile_read(parms->regfile,
BNXT_ULP_RF_IDX_FLOW_SIG_ID,
®val))) {
BNXT_DRV_DBG(ERR, "regfile[%d] read oob\n",
BNXT_ULP_RF_IDX_FLOW_SIG_ID);
return -EINVAL;
}
comp_sig = ULP_COMP_FLD_IDX_RD(parms,
BNXT_ULP_CF_IDX_FLOW_SIG_ID);
regval = tfp_be_to_cpu_64(regval);
if (likely(comp_sig == regval))
*res = 1;
else
BNXT_DRV_DBG(ERR, "failed signature match 0x%016"
PRIX64 ":%x\n", comp_sig, (uint32_t)regval);
break;
default:
BNXT_DRV_DBG(ERR, "Invalid accept opcode %d\n",
tbl->accept_opcode);
return -EINVAL;
}
return rc;
}
static int32_t
ulp_mapper_allocator_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_flow_db_res_params fid_parms;
int32_t alloc_index, rc = 0;
uint64_t regval = 0;
/* Only Alloc opcode is supported for now */
if (tbl->tbl_opcode != BNXT_ULP_ALLOC_TBL_OPC_ALLOC)
return 0; /* nothing to done */
/* allocate the index from the allocator */
rc = ulp_allocator_tbl_list_alloc(parms->mapper_data,
tbl->resource_sub_type,
tbl->direction, &alloc_index);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "unable to alloc index %x:%x\n",
tbl->resource_sub_type, tbl->direction);
return -EINVAL;
}
/* Write to the regfile */
regval = rte_cpu_to_be_64(alloc_index);
rc = ulp_regfile_write(parms->regfile, tbl->tbl_operand, regval);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to write regfile[%d] rc=%d\n",
tbl->tbl_operand, rc);
return -EINVAL;
}
/* update the flow database */
memset(&fid_parms, 0, sizeof(fid_parms));
fid_parms.direction = tbl->direction;
fid_parms.resource_func = tbl->resource_func;
fid_parms.resource_type = tbl->resource_type;
fid_parms.resource_sub_type = tbl->resource_sub_type;
fid_parms.resource_hndl = alloc_index;
fid_parms.critical_resource = tbl->critical_resource;
rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to link resource to flow rc = %d\n",
rc);
goto error;
}
return rc;
error:
/* Free the allocated index */
(void)ulp_allocator_tbl_list_free(parms->mapper_data,
tbl->resource_sub_type,
tbl->direction, alloc_index);
return rc;
}
static int32_t
ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, void *error)
{
struct bnxt_ulp_mapper_tbl_info *tbls;
struct bnxt_ulp_mapper_tbl_info *tbl;
uint32_t num_tbls, tbl_idx;
const struct ulp_mapper_core_ops *oper;
int32_t rc = -EINVAL, cond_rc = 0;
int32_t cond_goto = 1;
uint32_t tid;
oper = parms->mapper_data->mapper_oper;
/* assign the template id based on template type */
tid = (parms->tmpl_type == BNXT_ULP_TEMPLATE_TYPE_ACTION) ?
parms->act_tid : parms->class_tid;
rc = ulp_mapper_cond_reject_list_process(parms, tid, &cond_rc);
/* if rc is failure or cond_rc is a reject then exit tbl processing */
if (unlikely(rc || cond_rc))
return -EINVAL;
tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
if (unlikely(!tbls || !num_tbls)) {
BNXT_DRV_DBG(ERR, "No %s tables for %d:%d\n",
ulp_mapper_tmpl_name_str(parms->tmpl_type),
parms->dev_id, tid);
return -EINVAL;
}
for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
tbl = &tbls[tbl_idx];
cond_goto = tbl->execute_info.cond_true_goto;
/* Process the conditional func code opcodes */
if (unlikely(ulp_mapper_func_info_process(parms, tbl))) {
BNXT_DRV_DBG(ERR, "Failed to process cond update\n");
rc = -EINVAL;
goto error;
}
/* process the execute info of the table */
rc = ulp_mapper_cond_execute_list_process(parms, tbl, &cond_rc);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to proc cond opc list (%d)\n",
rc);
goto error;
}
/* Skip the table if False */
if (!cond_rc) {
cond_goto = tbl->execute_info.cond_false_goto;
goto next_iteration;
}
switch (tbl->resource_func) {
case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
rc = oper->ulp_mapper_core_tcam_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
rc = oper->ulp_mapper_core_em_tbl_process(parms, tbl,
error);
break;
case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
rc = oper->ulp_mapper_core_index_tbl_process(parms,
tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
rc = oper->ulp_mapper_core_if_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
rc = ulp_mapper_gen_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_VNIC_TABLE:
rc = ulp_mapper_vnic_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_GLOBAL_REGISTER_TABLE:
rc = ulp_mapper_global_register_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_CMM_TABLE:
case BNXT_ULP_RESOURCE_FUNC_CMM_STAT:
rc = oper->ulp_mapper_core_cmm_tbl_process(parms, tbl,
error);
break;
case BNXT_ULP_RESOURCE_FUNC_INVALID:
rc = 0;
break;
case BNXT_ULP_RESOURCE_FUNC_KEY_RECIPE_TABLE:
rc = ulp_mapper_key_recipe_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_ALLOCATOR_TABLE:
rc = ulp_mapper_allocator_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_STATS_CACHE:
rc = ulp_mapper_stats_cache_tbl_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_GLOBAL_IDENTIFIER:
rc = ulp_mapper_global_identifier_process(parms, tbl);
break;
case BNXT_ULP_RESOURCE_FUNC_GLOBAL_IDX_TBL:
rc = ulp_mapper_global_idx_tbl_process(parms, tbl);
break;
default:
BNXT_DRV_DBG(ERR, "Unexpected mapper resource %d\n",
tbl->resource_func);
rc = -EINVAL;
goto error;
}
if (rc) {
BNXT_DRV_DBG(ERR, "Resource type %d failed\n",
tbl->resource_func);
goto error;
}
/* perform the post table process */
rc = ulp_mapper_conflict_resolution_process(parms, tbl,
&cond_rc);
if (unlikely(rc || !cond_rc)) {
BNXT_DRV_DBG(ERR, "Failed due to conflict resolution\n");
rc = -EINVAL;
goto error;
}
next_iteration:
if (cond_goto < 0) {
if (unlikely(((int32_t)tbl_idx + cond_goto) < 0)) {
BNXT_DRV_DBG(ERR,
"invalid conditional goto %d\n",
cond_goto);
goto error;
}
} else if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
if (tbl->false_message || tbl->true_message) {
const char *msg = (tbl->false_message) ?
tbl->false_message :
tbl->true_message;
BNXT_DRV_DBG(DEBUG, "%s\n", msg);
if (unlikely(error))
rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ITEM,
NULL, msg);
return -EINVAL;
}
BNXT_DRV_DBG(ERR, "reject the flow\n");
rc = -EINVAL;
goto error;
} else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
int32_t rf_idx;
uint64_t regval = 0;
/* least significant 16 bits from reg_file index */
rf_idx = (int32_t)(cond_goto & 0xFFFF);
if (unlikely(ulp_regfile_read(parms->regfile, rf_idx,
®val))) {
BNXT_DRV_DBG(ERR, "regfile[%d] read oob\n",
rf_idx);
rc = -EINVAL;
goto error;
}
cond_goto = (int32_t)regval;
}
tbl_idx += cond_goto;
}
return rc;
error:
BNXT_DRV_DBG(ERR, "%s tables failed operation for %d:%d\n",
ulp_mapper_tmpl_name_str(parms->tmpl_type),
parms->dev_id, tid);
return rc;
}
static int32_t
ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
uint32_t fid,
struct ulp_flow_db_res_params *res,
void *error)
{
const struct ulp_mapper_core_ops *mapper_op;
struct bnxt_ulp_mapper_data *mdata;
int32_t rc = 0;
if (unlikely(!res || !ulp)) {
BNXT_DRV_DBG(ERR, "Unable to free resource\n ");
return -EINVAL;
}
mapper_op = ulp_mapper_data_oper_get(ulp);
switch (res->resource_func) {
case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
rc = mapper_op->ulp_mapper_core_tcam_entry_free(ulp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
rc = mapper_op->ulp_mapper_core_em_entry_free(ulp, res, error);
break;
case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
rc = mapper_op->ulp_mapper_core_index_entry_free(ulp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_CMM_TABLE:
case BNXT_ULP_RESOURCE_FUNC_CMM_STAT:
rc = mapper_op->ulp_mapper_core_cmm_entry_free(ulp, res, error);
break;
case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
rc = mapper_op->ulp_mapper_core_ident_free(ulp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_HW_FID:
rc = ulp_mapper_mark_free(ulp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
rc = ulp_mapper_parent_flow_free(ulp, fid, res);
break;
case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
rc = ulp_mapper_child_flow_free(ulp, fid, res);
break;
case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
rc = ulp_mapper_gen_tbl_res_free(ulp, fid, res);
break;
case BNXT_ULP_RESOURCE_FUNC_VNIC_TABLE:
rc = ulp_mapper_vnic_tbl_res_free(ulp, ulp->bp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_GLOBAL_REGISTER_TABLE:
rc = ulp_mapper_global_res_free(ulp, ulp->bp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_KEY_RECIPE_TABLE:
rc = ulp_mapper_key_recipe_free(ulp, res->direction,
res->resource_sub_type,
res->resource_hndl);
break;
case BNXT_ULP_RESOURCE_FUNC_ALLOCATOR_TABLE:
mdata = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp);
if (unlikely(!mdata)) {
BNXT_DRV_DBG(ERR, "Unable to get mapper data\n");
return -EINVAL;
}
rc = ulp_allocator_tbl_list_free(mdata,
res->resource_sub_type,
res->direction,
res->resource_hndl);
break;
case BNXT_ULP_RESOURCE_FUNC_STATS_CACHE:
rc = ulp_mapper_stats_cache_tbl_res_free(ulp,
fid);
break;
case BNXT_ULP_RESOURCE_FUNC_GLOBAL_IDENTIFIER:
rc = mapper_op->ulp_mapper_core_global_ident_free(ulp, res);
break;
case BNXT_ULP_RESOURCE_FUNC_GLOBAL_IDX_TBL:
rc = mapper_op->ulp_mapper_core_glb_idx_tbl_free(ulp, res);
break;
default:
break;
}
return rc;
}
int32_t
ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
enum bnxt_ulp_fdb_type flow_type,
uint32_t fid,
void *error)
{
struct ulp_flow_db_res_params res_parms = { 0 };
int32_t rc, trc, frc = 0;
if (unlikely(!ulp_ctx)) {
BNXT_DRV_DBG(ERR, "Invalid parms, unable to free flow\n");
return -EINVAL;
}
/*
* Set the critical resource on the first resource del, then iterate
* while status is good
*/
res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
if (rc) {
/*
* This is unexpected on the first call to resource del.
* It likely means that the flow did not exist in the flow db.
*/
BNXT_DRV_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
flow_type, fid, rc);
return rc;
}
while (!rc) {
trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms, error);
if (trc) {
/*
* On fail, we still need to attempt to free the
* remaining resources. Don't return
*/
BNXT_DRV_DBG(ERR,
"Flow[%d][0x%x] Res[%d][0x%016" PRIX64
"] failed rc=%d.\n",
flow_type, fid, res_parms.resource_func,
res_parms.resource_hndl, trc);
/* Capture error in final rc */
frc = trc;
}
/* All subsequent call require the non-critical_resource */
res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
rc = ulp_flow_db_resource_del(ulp_ctx,
flow_type,
fid,
&res_parms);
}
/* Expected that flow_db should return no entry */
if (rc != -ENOENT)
frc = rc;
/* Free the Flow ID since we've removed all resources */
rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
/* Ensure that any error will be reported */
if (rc)
frc = rc;
#ifdef TF_FLOW_SCALE_QUERY
/* update for regular flows only */
if (flow_type == BNXT_ULP_FDB_TYPE_REGULAR)
ulp_resc_usage_sync(ulp_ctx);
#endif /* TF_FLOW_SCALE_QUERY */
return frc;
}
static void
ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_mapper_data *mapper_data)
{
struct bnxt_ulp_mapper_glb_resource_entry *ent;
struct ulp_flow_db_res_params res;
uint32_t dir, idx;
/* Iterate the global resources and process each one */
for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
ent = &mapper_data->glb_res_tbl[dir][idx];
if (ent->resource_func ==
BNXT_ULP_RESOURCE_FUNC_INVALID ||
ent->shared)
continue;
memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
res.resource_func = ent->resource_func;
res.direction = dir;
res.resource_type = ent->resource_type;
/*convert it from BE to cpu */
res.resource_hndl =
tfp_be_to_cpu_64(ent->resource_hndl);
ulp_mapper_resource_free(ulp_ctx, 0, &res, NULL);
}
}
}
int32_t
ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
enum bnxt_ulp_fdb_type flow_type,
uint32_t fid,
void *error)
{
int32_t rc;
if (unlikely(!ulp_ctx)) {
BNXT_DRV_DBG(ERR, "Invalid parms, unable to free flow\n");
return -EINVAL;
}
rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid, error);
return rc;
}
/* Function to handle the mapping of the Flow to be compatible
* with the underlying hardware.
*/
int32_t
ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
struct bnxt_ulp_mapper_parms *parms, void *error)
{
const struct ulp_mapper_core_ops *oper;
struct ulp_regfile regfile;
int32_t rc = 0, trc;
if (unlikely(!ulp_ctx || !parms))
return -EINVAL;
parms->regfile = ®file;
parms->ulp_ctx = ulp_ctx;
oper = ulp_mapper_data_oper_get(ulp_ctx);
/* Get the device id from the ulp context */
if (unlikely(bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms->dev_id))) {
BNXT_DRV_DBG(ERR, "Invalid ulp context\n");
return -EINVAL;
}
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &parms->fw_fid))) {
BNXT_DRV_DBG(ERR, "Unable to get the func_id\n");
return -EINVAL;
}
/* Get the device params, it will be used in later processing */
parms->device_params = bnxt_ulp_device_params_get(parms->dev_id);
if (unlikely(!parms->device_params)) {
BNXT_DRV_DBG(ERR, "No device parms for device id %d\n",
parms->dev_id);
return -EINVAL;
}
/*
* Get the mapper data for dynamic mapper data such as default
* ids.
*/
parms->mapper_data = (struct bnxt_ulp_mapper_data *)
bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
if (unlikely(!parms->mapper_data)) {
BNXT_DRV_DBG(ERR, "Failed to get the ulp mapper data\n");
return -EINVAL;
}
/* initialize the registry file for further processing */
if (unlikely(ulp_regfile_init(parms->regfile))) {
BNXT_DRV_DBG(ERR, "regfile initialization failed.\n");
return -EINVAL;
}
/* Start batching */
rc = oper->ulp_mapper_mpc_batch_start(&parms->batch_info);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "MPC Batch start failed\n");
return -EINVAL;
}
/* Process the action template list from the selected action table*/
if (parms->act_tid) {
parms->tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
/* Process the action template tables */
rc = ulp_mapper_tbls_process(parms, error);
if (unlikely(rc))
goto batch_error;
}
if (parms->class_tid) {
parms->tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
/* Process the class template tables.*/
rc = ulp_mapper_tbls_process(parms, error);
if (unlikely(rc))
goto batch_error;
}
if (oper->ulp_mapper_mpc_batch_started(&parms->batch_info)) {
/* Should only get here is there were no EM inserts */
rc = oper->ulp_mapper_mpc_batch_end(&ulp_ctx->bp->tfcp,
&parms->batch_info);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "MPC Batch end failed\n");
goto flow_error;
}
}
/* setup the parent-child details */
if (parms->parent_flow) {
/* create a parent flow details */
rc = ulp_flow_db_parent_flow_create(parms);
if (unlikely(rc))
goto flow_error;
} else if (parms->child_flow) {
/* create a child flow details */
rc = ulp_flow_db_child_flow_create(parms);
if (unlikely(rc))
goto flow_error;
}
#ifdef TF_FLOW_SCALE_QUERY
ulp_resc_usage_sync(ulp_ctx);
#endif /* TF_FLOW_SCALE_QUERY */
return rc;
batch_error:
/*
* An error occurred after batching had started but before it
* ended. Call batch end and ignore any errors.
*/
if (oper->ulp_mapper_mpc_batch_started(&parms->batch_info))
oper->ulp_mapper_mpc_batch_end(&ulp_ctx->bp->tfcp,
&parms->batch_info);
flow_error:
if (parms->rid) {
/* An RID was in-flight but not pushed, free the resources */
trc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_RID,
parms->rid, NULL);
if (trc)
BNXT_DRV_DBG(ERR,
"Failed to free resources rid=0x%08x rc=%d\n",
parms->rid, trc);
parms->rid = 0;
}
/* Free all resources that were allocated during flow creation */
if (parms->flow_id) {
trc = ulp_mapper_flow_destroy(ulp_ctx, parms->flow_type,
parms->flow_id, NULL);
if (trc)
BNXT_DRV_DBG(ERR,
"Failed to free resources fid=0x%08x rc=%d\n",
parms->flow_id, trc);
}
return rc;
}
#ifdef TF_FLOW_SCALE_QUERY
/* Sync resource usage state with firmware */
int ulp_resc_usage_sync(struct bnxt_ulp_context *ulp_ctx)
{
uint32_t dev_id;
if (unlikely(bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id))) {
BNXT_DRV_DBG(ERR, "Invalid ulp context\n");
return -EINVAL;
}
if (dev_id == BNXT_ULP_DEVICE_ID_THOR) {
tf_resc_resume_usage_update();
tf_resc_usage_update_all(ulp_ctx->bp);
} else if (dev_id == BNXT_ULP_DEVICE_ID_THOR2) {
tfc_resc_usage_query_all(ulp_ctx->bp);
}
return 0;
}
#endif /* TF_FLOW_SCALE_QUERY */
int32_t
ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
{
struct bnxt_ulp_mapper_data *data;
int32_t rc;
if (!ulp_ctx)
return -EINVAL;
data = rte_zmalloc("ulp_mapper_data",
sizeof(struct bnxt_ulp_mapper_data), 0);
if (unlikely(!data)) {
BNXT_DRV_DBG(ERR, "Failed to allocate the mapper data\n");
return -ENOMEM;
}
/* set the mapper operations for the current platform */
data->mapper_oper = bnxt_ulp_mapper_ops_get(ulp_ctx->bp);
if (unlikely(data->mapper_oper == NULL)) {
rte_free(data);
BNXT_DRV_DBG(ERR, "Failed to get mapper ops\n");
return -ENOMEM;
}
if (unlikely(bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data))) {
BNXT_DRV_DBG(ERR, "Failed to set mapper data in context\n");
/* Don't call deinit since the prof_func wasn't allocated. */
rte_free(data);
return -ENOMEM;
}
/* Allocate the global resource ids */
rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to initialize global resource ids\n");
goto error;
}
/*
* Only initialize the app global resources if a shared session was
* created.
*/
if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to init app glb resources\n");
goto error;
}
}
/* Allocate the generic table list */
rc = ulp_mapper_generic_tbl_list_init(ulp_ctx, data);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to initialize generic tbl list\n");
goto error;
}
rc = ulp_mapper_key_recipe_tbl_init(ulp_ctx, data);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to initialize key_recipe tbl\n");
goto error;
}
rc = ulp_allocator_tbl_list_init(ulp_ctx, data);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to initialize allocator tbl\n");
goto error;
}
return 0;
error:
/* Ignore the return code in favor of returning the original error. */
ulp_mapper_deinit(ulp_ctx);
return rc;
}
void
ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
{
struct bnxt_ulp_mapper_data *data;
if (unlikely(!ulp_ctx)) {
BNXT_DRV_DBG(ERR,
"Failed to acquire ulp context, so data may not be released.\n");
return;
}
data = (struct bnxt_ulp_mapper_data *)
bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
if (unlikely(!data)) {
/* Go ahead and return since there is no allocated data. */
BNXT_DRV_DBG(ERR, "No data appears to have been allocated.\n");
return;
}
/* Free the global resource info table entries */
ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
/* Free the generic table */
(void)ulp_mapper_generic_tbl_list_deinit(data);
/* Free the key recipe table */
(void)ulp_mapper_key_recipe_tbl_deinit(data);
/* Free the allocator table */
(void)ulp_allocator_tbl_list_deinit(data);
rte_free(data);
/* Reset the data pointer within the ulp_ctx. */
bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);
}
|