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
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2014-2023 Broadcom
* All rights reserved.
*/
#include <rte_byteorder.h>
#include "ulp_mapper.h"
#include "ulp_flow_db.h"
#include "cfa_resources.h"
#include "cfa_bld.h"
#include "tfc_util.h"
#include "bnxt_ulp_tfc.h"
#include "bnxt_ulp_utils.h"
#include "tfc_action_handle.h"
#define BNXT_METER_MAX_NUM 1024
static struct bnxt_mtr_stats_id_map mtr_stats[BNXT_METER_MAX_NUM];
static uint32_t CFA_RESTYPE_TO_BLKT(uint8_t idx_tbl_restype)
{
return (idx_tbl_restype > CFA_RSUBTYPE_IDX_TBL_MAX) ?
CFA_IDX_TBL_BLKTYPE_RXP : CFA_IDX_TBL_BLKTYPE_CFA;
}
/* Internal function to write the tcam entry */
static int32_t
ulp_mapper_tfc_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
struct ulp_blob *key,
struct ulp_blob *mask,
struct ulp_blob *remap,
uint16_t idx)
{
struct tfc_tcam_info tfc_info = {0};
struct tfc_tcam_data tfc_data = {0};
struct tfc *tfcp = NULL;
uint16_t key_size = 0, mask_size = 0, remap_size = 0;
int32_t rc;
uint16_t fw_fid;
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
rc = bnxt_ulp_cntxt_fid_get(parms->ulp_ctx, &fw_fid);
if (unlikely(rc))
return rc;
tfc_info.dir = tbl->direction;
tfc_info.rsubtype = tbl->resource_type;
tfc_info.id = idx;
tfc_data.key = ulp_blob_data_get(key, &key_size);
tfc_data.key_sz_in_bytes = ULP_BITS_2_BYTE(key_size);
tfc_data.mask = ulp_blob_data_get(mask, &mask_size);
tfc_data.remap = ulp_blob_data_get(remap, &remap_size);
remap_size = ULP_BITS_2_BYTE(remap_size);
tfc_data.remap_sz_in_bytes = remap_size;
if (unlikely(tfc_tcam_set(tfcp, fw_fid, &tfc_info, &tfc_data))) {
BNXT_DRV_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
tfc_tcam_2_str(tfc_info.rsubtype),
tfc_dir_2_str(tfc_info.dir), tfc_info.id);
return -EIO;
}
PMD_DRV_LOG_LINE(INFO, "tcam[%s][%s][%x] write success.",
tfc_tcam_2_str(tfc_info.rsubtype),
tfc_dir_2_str(tfc_info.dir), tfc_info.id);
/* Mark action */
rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "failed mark action processing\n");
return rc;
}
return rc;
}
static uint32_t
ulp_mapper_tfc_wc_tcam_post_process(struct bnxt_ulp_device_params *dparms,
struct ulp_blob *key,
struct ulp_blob *tkey)
{
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)) {
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 + 1) * num_slices;
if (unlikely(ulp_blob_init(tkey, tlen, key->byte_order))) {
BNXT_DRV_DBG(ERR, "Unable to post process wc tcam entry\n");
return -EINVAL;
}
/* pad any remaining bits to do byte alignment */
pad = (slice_width + clen) * num_slices;
pad = ULP_BYTE_ROUND_OFF_8(pad) - pad;
if (unlikely(ulp_blob_pad_push(tkey, pad) < 0)) {
BNXT_DRV_DBG(ERR, "Unable to pad key/mask\n");
return -EINVAL;
}
/* Build the transformed key/mask */
cword = dparms->wc_mode_list[num_slices - 1];
cword = rte_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;
}
rc = ulp_blob_append(tkey, key, offset, slice_width);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Key blob append failed\n");
return rc;
}
offset += slice_width;
}
blen = ulp_blob_data_len_get(tkey);
/* reverse the blob byte wise in reverse */
ulp_blob_perform_byte_reverse(tkey, ULP_BITS_2_BYTE(blen));
return 0;
}
static int32_t
ulp_mapper_tfc_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct bnxt_ulp_device_params *dparms = parms->device_params;
struct ulp_blob okey, omask, *key, *mask, data;
struct ulp_blob tkey, tmask; /* transform key and mask */
uint32_t alloc_tcam = 0, alloc_ident = 0, write_tcam = 0;
struct ulp_flow_db_res_params fid_parms = { 0 };
enum cfa_track_type tt = tbl->track_type;
enum bnxt_ulp_byte_order key_byte_order;
enum bnxt_ulp_byte_order res_byte_order;
struct bnxt_ulp_mapper_key_info *kflds;
struct tfc_tcam_info tfc_inf = {0};
uint16_t key_sz_in_words = 0, key_sz_in_bits = 0;
struct tfc *tfcp = NULL;
uint32_t num_kflds, i;
uint32_t priority;
int32_t rc = 0, free_rc = 0;
uint16_t fw_fid = 0;
/* Set the key and mask to the original key and mask. */
key = &okey;
mask = &omask;
switch (tbl->tbl_opcode) {
case BNXT_ULP_TCAM_TBL_OPC_ALLOC_IDENT:
alloc_ident = 1;
break;
case BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE:
alloc_ident = 1;
alloc_tcam = 1;
write_tcam = 1;
break;
case BNXT_ULP_TCAM_TBL_OPC_NOT_USED:
case BNXT_ULP_TCAM_TBL_OPC_LAST:
default:
BNXT_DRV_DBG(ERR, "Invalid tcam table opcode %d\n",
tbl->tbl_opcode);
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
PMD_DRV_LOG_LINE(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
if (unlikely(bnxt_ulp_cntxt_fid_get(parms->ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
/* Allocate the identifiers */
if (alloc_ident) {
rc = ulp_mapper_tcam_tbl_ident_alloc(parms, tbl);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to alloc identifier\n");
return rc;
}
}
/* If no allocation or write is needed, then just exit */
if (unlikely(!alloc_tcam && !write_tcam))
return rc;
/* Initialize the blobs for write */
if (tbl->resource_type == CFA_RSUBTYPE_TCAM_WC)
key_byte_order = dparms->wc_key_byte_order;
else
key_byte_order = dparms->key_byte_order;
res_byte_order = dparms->result_byte_order;
if (unlikely(ulp_blob_init(key, tbl->blob_key_bit_size, key_byte_order) ||
ulp_blob_init(mask, tbl->blob_key_bit_size, key_byte_order) ||
ulp_blob_init(&data, tbl->result_bit_size, res_byte_order))) {
BNXT_DRV_DBG(ERR, "blob inits failed.\n");
return -EINVAL;
}
/* Get the key fields and update the key blob */
if (tbl->key_recipe_opcode == BNXT_ULP_KEY_RECIPE_OPC_DYN_KEY)
kflds = ulp_mapper_key_recipe_fields_get(parms, tbl, &num_kflds);
else
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;
}
for (i = 0; i < num_kflds; i++) {
/* Setup the key */
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&kflds[i].field_info_spec,
key, 1, "TCAM Key");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Key field set failed %s\n",
kflds[i].field_info_spec.description);
return rc;
}
/* Setup the mask */
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&kflds[i].field_info_mask,
mask, 0, "TCAM Mask");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Mask field set failed %s\n",
kflds[i].field_info_mask.description);
return rc;
}
}
/* For wild card tcam perform the post process to swap the blob */
if (tbl->resource_type == CFA_RSUBTYPE_TCAM_WC) {
/* Sets up the slices for writing to the WC TCAM */
rc = ulp_mapper_tfc_wc_tcam_post_process(dparms, key, &tkey);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to post proc WC key.\n");
return rc;
}
/* Sets up the slices for writing to the WC TCAM */
rc = ulp_mapper_tfc_wc_tcam_post_process(dparms, mask, &tmask);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to post proc WC mask.\n");
return rc;
}
key = &tkey;
mask = &tmask;
}
if (alloc_tcam) {
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
PMD_DRV_LOG_LINE(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
/* calculate the entry priority*/
rc = ulp_mapper_priority_opc_process(parms, tbl,
&priority);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "entry priority process failed\n");
return rc;
}
/* allocate the tcam entry, only need the length */
(void)ulp_blob_data_get(key, &key_sz_in_bits);
key_sz_in_words = ULP_BITS_2_BYTE(key_sz_in_bits);
tfc_inf.dir = tbl->direction;
tfc_inf.rsubtype = tbl->resource_type;
rc = tfc_tcam_alloc(tfcp, fw_fid, tt, priority,
key_sz_in_words, &tfc_inf);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "TCAM Alloc failed, status:%d\n", rc);
return rc;
}
/* Write the tcam index into the regfile*/
if (unlikely(ulp_regfile_write(parms->regfile, tbl->tbl_operand,
(uint64_t)rte_cpu_to_be_64(tfc_inf.id)))) {
BNXT_DRV_DBG(ERR, "Regfile[%d] write failed.\n",
tbl->tbl_operand);
/* Need to free the tcam idx, so goto error */
goto error;
}
}
if (write_tcam) {
/* Create the result blob */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
"TCAM Result");
/* write the tcam entry */
if (!rc)
rc = ulp_mapper_tfc_tcam_tbl_entry_write(parms,
tbl, key,
mask, &data,
tfc_inf.id);
}
if (rc)
goto error;
/* Add the tcam index to the flow database */
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 = tfc_inf.id;
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, "Failed to link resource to flow rc = %d\n",
rc);
/* Need to free the identifier, so goto error */
goto error;
}
return 0;
error:
free_rc = tfc_tcam_free(tfcp, fw_fid, &tfc_inf);
if (free_rc)
BNXT_DRV_DBG(ERR, "TCAM free failed on error, status:%d\n",
free_rc);
return rc;
}
static const char * const mpc_error_str[] = {
"OK",
"Unsupported Opcode",
"Bad Format",
"Invalid Scope",
"Bad Address",
"Cache Error",
"EM Miss",
"Duplicate Entry",
"No Events",
"EM Abort"
};
/*
* TBD: Temporary swap until a more generic solution is designed
*
* blob [inout] A byte array that is being edited in-place
* block_sz [in] The size of the blocks in bytes to swap
*
* The length of the blob is assumed to be a multiple of block_sz
*/
static int32_t
ulp_mapper_blob_block_swap(struct ulp_blob *blob, uint32_t block_sz)
{
uint8_t data[block_sz]; /* size of a block for temp storage */
uint16_t num_words, data_sz;
uint8_t *pdata;
int i;
/* Shouldn't happen since it is internal function, but check anyway */
if (unlikely(blob == NULL || !block_sz)) {
BNXT_DRV_DBG(ERR, "Invalid arguments\n");
return -EINVAL;
}
pdata = ulp_blob_data_get(blob, &data_sz);
data_sz = ULP_BITS_2_BYTE(data_sz);
if (unlikely(!data_sz || (data_sz % block_sz) != 0)) {
BNXT_DRV_DBG(ERR, "length(%d) not a multiple of %d\n",
data_sz, block_sz);
return -EINVAL;
}
num_words = data_sz / block_sz;
for (i = 0; i < num_words / 2; i++) {
memcpy(data, &pdata[i * block_sz], block_sz);
memcpy(&pdata[i * block_sz],
&pdata[(num_words - 1 - i) * block_sz], block_sz);
memcpy(&pdata[(num_words - 1 - i) * block_sz],
data, block_sz);
}
return 0;
}
static int
ulp_mapper_tfc_mpc_batch_end(struct tfc *tfcp,
struct tfc_mpc_batch_info_t *batch_info)
{
uint32_t i;
int rc;
rc = tfc_mpc_batch_end(tfcp, batch_info);
if (unlikely(rc))
return rc;
for (i = 0; i < batch_info->count; i++) {
if (!batch_info->result[i])
continue;
switch (batch_info->comp_info[i].type) {
case TFC_MPC_EM_INSERT:
batch_info->em_error = batch_info->result[i];
break;
default:
if (batch_info->result[i] && !batch_info->error)
batch_info->error = batch_info->result[i];
break;
}
}
return rc;
}
static bool
ulp_mapper_tfc_mpc_batch_started(struct tfc_mpc_batch_info_t *batch_info)
{
return tfc_mpc_batch_started(batch_info);
}
static int32_t
ulp_mapper_tfc_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
void *error)
{
struct bnxt_ulp_device_params *dparms = parms->device_params;
struct bnxt_ulp_mapper_key_info *kflds;
struct tfc_em_delete_parms free_parms = { 0 };
struct tfc_em_insert_parms iparms = { 0 };
struct ulp_flow_db_res_params fid_parms = { 0 };
uint16_t tmplen, key_len, align_len_bits;
enum bnxt_ulp_byte_order byte_order;
struct ulp_blob key, data;
uint32_t i, num_kflds;
uint64_t handle = 0;
struct tfc *tfcp;
int32_t trc = 0;
uint8_t tsid = 0;
int32_t rc = 0;
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
if (tbl->key_recipe_opcode == BNXT_ULP_KEY_RECIPE_OPC_DYN_KEY)
kflds = ulp_mapper_key_recipe_fields_get(parms, tbl, &num_kflds);
else
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;
}
byte_order = dparms->em_byte_order;
/* Initialize the key/result blobs */
if (unlikely(ulp_blob_init(&key, tbl->blob_key_bit_size, byte_order) ||
ulp_blob_init(&data, tbl->result_bit_size, byte_order))) {
BNXT_DRV_DBG(ERR, "blob inits failed.\n");
return -EINVAL;
}
/* create the key */
for (i = 0; i < num_kflds; i++) {
/* Setup the key */
rc = ulp_mapper_field_opc_process(parms, tbl->direction,
&kflds[i].field_info_spec,
&key, 1, "EM Key");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Key field set failed.\n");
return rc;
}
}
/* add padding to make sure key is at record boundary */
key_len = ulp_blob_data_len_get(&key);
if (key_len > dparms->em_blk_align_bits) {
key_len = key_len - dparms->em_blk_align_bits;
align_len_bits = dparms->em_blk_size_bits -
(key_len % dparms->em_blk_size_bits);
} else {
align_len_bits = dparms->em_blk_align_bits - key_len;
}
ulp_blob_pad_push(&key, align_len_bits);
key_len = ULP_BITS_2_BYTE(ulp_blob_data_len_get(&key));
ulp_blob_perform_byte_reverse(&key, key_len);
/* Create the result data blob */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
ulp_blob_pad_align(&data, dparms->em_blk_align_bits);
key_len = ULP_BITS_2_BYTE(ulp_blob_data_len_get(&data));
ulp_blob_perform_byte_reverse(&data, key_len);
rc = ulp_blob_append(&key, &data, 0, dparms->em_blk_align_bits);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "EM Failed to append the result to key(%d)",
rc);
return rc;
}
/* TBD: Need to come up with a more generic way to know when to swap,
* this is fine for now as this driver only supports this device.
*/
rc = ulp_mapper_blob_block_swap(&key,
ULP_BITS_2_BYTE(dparms->em_blk_size_bits));
/* Error printed within function, just return on error */
if (unlikely(rc))
return rc;
iparms.dir = tbl->direction;
iparms.lkup_key_data = ulp_blob_data_get(&key, &tmplen);
iparms.lkup_key_sz_words = ULP_BITS_TO_32_BYTE_WORD(tmplen);
iparms.key_data = NULL;
iparms.key_sz_bits = 0;
iparms.flow_handle = &handle;
iparms.batch_info = &parms->batch_info;
rc = bnxt_ulp_cntxt_tsid_get(parms->ulp_ctx, &tsid);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to get the table scope\n");
return rc;
}
rc = tfc_em_insert(tfcp, tsid, &iparms);
if (likely(tfc_mpc_batch_started(&parms->batch_info))) {
int trc;
int em_index = parms->batch_info.count - 1;
parms->batch_info.em_hdl[em_index] = *iparms.flow_handle;
trc = ulp_mapper_tfc_mpc_batch_end(tfcp, &parms->batch_info);
if (unlikely(trc))
return trc;
*iparms.flow_handle = parms->batch_info.em_hdl[em_index];
/* Has there been an error? */
if (unlikely(parms->batch_info.error)) {
/* If there's not an EM error the entry will need to
* be deleted
*/
if (!parms->batch_info.em_error) {
rc = parms->batch_info.error;
goto error;
}
}
rc = parms->batch_info.em_error;
}
if (unlikely(rc)) {
/* Set the error flag in reg file */
if (tbl->tbl_opcode == BNXT_ULP_EM_TBL_OPC_WR_REGFILE) {
uint64_t val = 0;
/* hash collision */
if (unlikely(rc == -E2BIG))
BNXT_DRV_DBG(DEBUG, "Duplicate EM entry\n");
/* over max flows */
if (rc == -ENOMEM) {
val = 1;
rc = 0;
BNXT_DRV_DBG(DEBUG,
"Fail to insert EM, shall add to wc\n");
}
ulp_regfile_write(parms->regfile, tbl->tbl_operand,
rte_cpu_to_be_64(val));
}
if (rc && rc != -E2BIG)
BNXT_DRV_DBG(ERR,
"Failed to insert em entry rc=%d.\n", rc);
if (rc && error != NULL && tfc_is_mpc_error(rc))
rte_flow_error_set((struct rte_flow_error *)error, EIO,
RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
mpc_error_str[rc * -1]);
return rc;
}
/* Mark action process */
rc = ulp_mapper_mark_gfid_process(parms, tbl, *iparms.flow_handle);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to add mark to flow\n");
goto error;
}
/* Link the EM resource 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.critical_resource = tbl->critical_resource;
fid_parms.resource_hndl = *iparms.flow_handle;
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);
/* Need to free the identifier, so goto error */
goto error;
}
return 0;
error:
free_parms.dir = iparms.dir;
free_parms.flow_handle = *iparms.flow_handle;
free_parms.batch_info = &parms->batch_info;
trc = tfc_em_delete(tfcp, &free_parms);
if (trc)
BNXT_DRV_DBG(ERR, "Failed to delete EM entry on failed add\n");
return rc;
}
static int32_t
ulp_mapper_tfc_em_entry_free(struct bnxt_ulp_context *ulp,
struct ulp_flow_db_res_params *res,
void *error)
{
struct tfc_em_delete_parms free_parms = { 0 };
struct tfc *tfcp;
int32_t rc = 0;
uint16_t fw_fid = 0;
struct tfc_mpc_batch_info_t batch_info;
memset(&batch_info, 0, sizeof(batch_info));
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
free_parms.dir = (enum cfa_dir)res->direction;
free_parms.flow_handle = res->resource_hndl;
free_parms.batch_info = &batch_info;
rc = tfc_em_delete(tfcp, &free_parms);
if (rc) {
BNXT_DRV_DBG(ERR,
"Failed to delete EM entry, res = 0x%" PRIx64 "\n",
res->resource_hndl);
if (error != NULL && tfc_is_mpc_error(rc)) {
struct rte_flow_error *fe = (struct rte_flow_error *)error;
rte_flow_error_set(fe,
EIO,
RTE_FLOW_ERROR_TYPE_HANDLE,
NULL,
mpc_error_str[rc * -1]);
}
} else {
BNXT_DRV_DBG(DEBUG, "Deleted EM entry, res = 0x%" PRIx64 "\n",
res->resource_hndl);
}
return rc;
}
static uint16_t
ulp_mapper_tfc_dyn_blob_size_get(struct bnxt_ulp_mapper_parms *mparms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct bnxt_ulp_device_params *d_params = mparms->device_params;
if (d_params->dynamic_sram_en) {
switch (tbl->resource_type) {
/* TBD: add more types here */
case CFA_BLD_ACT_OBJ_TYPE_STAT:
case CFA_BLD_ACT_OBJ_TYPE_ENCAP:
case CFA_BLD_ACT_OBJ_TYPE_MODIFY:
/* return max size */
return BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
default:
break;
}
} else if (tbl->encap_num_fields) {
return BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
}
return tbl->result_bit_size;
}
static int32_t
ulp_mapper_tfc_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
bool alloc = false, write = false, global = false, regfile = false;
struct bnxt_ulp_glb_resource_info glb_res = { 0 };
uint16_t bit_size, wordlen = 0, tmplen = 0;
enum cfa_track_type tt = tbl->track_type;
struct ulp_flow_db_res_params fid_parms;
struct tfc_idx_tbl_info tbl_info = { 0 };
struct tfc *tfcp = NULL;
struct ulp_blob data;
uint64_t regval = 0;
bool shared = false;
uint32_t index = 0;
unsigned char *data_p;
int32_t rc = 0;
uint16_t fw_fid = 0;
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
PMD_DRV_LOG_LINE(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
if (unlikely(bnxt_ulp_cntxt_fid_get(parms->ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func id\n");
return -EINVAL;
}
/* compute the blob size */
bit_size = ulp_mapper_tfc_dyn_blob_size_get(parms, tbl);
/* Initialize the blob data */
if (unlikely(ulp_blob_init(&data, bit_size,
parms->device_params->result_byte_order))) {
BNXT_DRV_DBG(ERR, "Failed to initialize index table blob\n");
return -EINVAL;
}
switch (tbl->tbl_opcode) {
case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
alloc = true;
regfile = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
/*
* Build the entry, alloc an index, write the table, and store
* the data in the regfile.
*/
alloc = true;
write = true;
regfile = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
/*
* get the index to write to from the regfile and then write
* the table entry.
*/
regfile = true;
write = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
/*
* Build the entry, alloc an index, write the table, and store
* the data in the global regfile.
*/
alloc = true;
global = true;
write = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
if (unlikely(tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP)) {
BNXT_DRV_DBG(ERR, "Template error, wrong fdb opcode\n");
return -EINVAL;
}
/*
* get the index to write to from the global regfile and then
* write the table.
*/
if (unlikely(ulp_mapper_glb_resource_read(parms->mapper_data,
tbl->direction,
tbl->tbl_operand,
®val, &shared))) {
BNXT_DRV_DBG(ERR,
"Failed to get tbl idx from Glb RF[%d].\n",
tbl->tbl_operand);
return -EINVAL;
}
index = rte_be_to_cpu_64(regval);
/* check to see if any scope id changes needs to be done*/
write = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
/*
* The read is different from the rest and can be handled here
* instead of trying to use common code. Simply read the table
* with the index from the regfile, scan and store the
* identifiers, and return.
*/
if (unlikely(ulp_regfile_read(parms->regfile,
tbl->tbl_operand, ®val))) {
BNXT_DRV_DBG(ERR,
"Failed to get tbl idx from regfile[%d]\n",
tbl->tbl_operand);
return -EINVAL;
}
index = rte_be_to_cpu_64(regval);
tbl_info.dir = tbl->direction;
tbl_info.rsubtype = tbl->resource_type;
tbl_info.blktype = CFA_RESTYPE_TO_BLKT(tbl->resource_type);
tbl_info.id = index;
/* Nothing has been pushed to blob, so push bit_size */
tmplen = ulp_blob_pad_push(&data, bit_size);
data_p = ulp_blob_data_get(&data, &tmplen);
wordlen = ULP_BITS_2_BYTE(tmplen);
rc = tfc_idx_tbl_get(tfcp, fw_fid, &tbl_info, (uint32_t *)data_p,
(uint8_t *)&wordlen);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to read the tbl entry %d:%d\n",
tbl->resource_type, index);
return rc;
}
/* Scan the fields in the entry and push them into the regfile*/
rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl, data_p,
wordlen, data.byte_order);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to get flds on tbl read rc=%d\n",
rc);
return rc;
}
return 0;
case BNXT_ULP_INDEX_TBL_OPC_NOP_REGFILE:
/* Special case, where hw table processing is not being done */
/* but only for writing the regfile into the flow database */
regfile = true;
break;
default:
BNXT_DRV_DBG(ERR, "Invalid index table opcode %d\n",
tbl->tbl_opcode);
return -EINVAL;
}
/* read the CMM identifier from the regfile, it is not allocated */
if (!alloc && regfile) {
if (unlikely(ulp_regfile_read(parms->regfile,
tbl->tbl_operand,
®val))) {
BNXT_DRV_DBG(ERR,
"Failed to get tbl idx from regfile[%d].\n",
tbl->tbl_operand);
return -EINVAL;
}
index = rte_be_to_cpu_64(regval);
}
/* Allocate the Action CMM identifier */
if (alloc) {
tbl_info.dir = tbl->direction;
tbl_info.rsubtype = tbl->resource_type;
tbl_info.blktype = CFA_RESTYPE_TO_BLKT(tbl->resource_type);
/*
* Read back the operand and pass it into the
* alloc command if its a Dyn UPAR table.
*/
if (tbl_info.blktype == CFA_IDX_TBL_BLKTYPE_RXP) {
if (ulp_regfile_read(parms->regfile,
tbl->tbl_operand, ®val)) {
BNXT_DRV_DBG(ERR,
"Failed to get tbl idx from regfile[%d]\n",
tbl->tbl_operand);
return -EINVAL;
}
tbl_info.rsubtype = rte_be_to_cpu_64(regval);
}
rc = tfc_idx_tbl_alloc(tfcp, fw_fid, tt, &tbl_info);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
tfc_idx_tbl_2_str(tbl_info.rsubtype),
tfc_dir_2_str(tbl->direction), rc);
return rc;
}
index = tbl_info.id;
}
/* update the global register value */
if (alloc && global) {
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;
regval = rte_cpu_to_be_64(index);
/*
* Shared resources are never allocated through this
* method, so the shared flag is always false.
*/
rc = ulp_mapper_glb_resource_write(parms->mapper_data,
&glb_res, regval,
false);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to write %s regfile[%d] rc=%d\n",
(global) ? "global" : "reg",
tbl->tbl_operand, rc);
goto error;
}
}
/* update the local register value */
if (alloc && regfile) {
regval = rte_cpu_to_be_64(index);
rc = ulp_regfile_write(parms->regfile,
tbl->tbl_operand, regval);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to write %s regfile[%d] rc=%d\n",
(global) ? "global" : "reg",
tbl->tbl_operand, rc);
goto error;
}
}
if (write) {
/* Get the result fields list */
rc = ulp_mapper_tbl_result_build(parms,
tbl,
&data,
"Indexed Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
data_p = ulp_blob_data_get(&data, &tmplen);
tbl_info.dir = tbl->direction;
tbl_info.rsubtype = tbl->resource_type;
tbl_info.blktype = CFA_RESTYPE_TO_BLKT(tbl->resource_type);
tbl_info.id = index;
wordlen = ULP_BITS_2_BYTE(tmplen);
rc = tfc_idx_tbl_set(tfcp, fw_fid, &tbl_info,
(uint32_t *)data_p, wordlen);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Index table[%s][%s][%x] write fail %d\n",
tfc_idx_tbl_2_str(tbl_info.rsubtype),
tfc_dir_2_str(tbl_info.dir),
tbl_info.id, rc);
goto error;
}
BNXT_DRV_DBG(DEBUG,
"Index table[%s][%d][%x] write successful\n",
tfc_idx_tbl_2_str(tbl_info.rsubtype),
tbl_info.dir, tbl_info.id);
}
/* Link the resource 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 = 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, "Failed to link resource to flow rc = %d\n",
rc);
goto error;
}
/* Perform the VF rep action */
rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
goto error;
}
return rc;
error:
/* Shared resources are not freed */
if (shared)
return rc;
/*
* Free the allocated resource since we failed to either
* write to the entry or link the flow
*/
tbl_info.blktype = CFA_RESTYPE_TO_BLKT(tbl->resource_type);
if (tfc_idx_tbl_free(tfcp, fw_fid, &tbl_info))
BNXT_DRV_DBG(ERR, "Failed to free index entry on failure\n");
return rc;
}
static inline int32_t
ulp_mapper_tfc_index_entry_free(struct bnxt_ulp_context *ulp_ctx,
struct ulp_flow_db_res_params *res)
{
struct tfc *tfcp = NULL;
struct tfc_idx_tbl_info tbl_info = { 0 };
uint16_t fw_fid = 0;
int32_t rc;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
#ifndef ULP_MAPPER_TFC_TEST
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
#endif
tbl_info.dir = (enum cfa_dir)res->direction;
tbl_info.rsubtype = res->resource_type;
tbl_info.id = (uint16_t)res->resource_hndl;
tbl_info.blktype = CFA_RESTYPE_TO_BLKT(res->resource_type);
/* TBD: check to see if the memory needs to be cleaned as well*/
rc = tfc_idx_tbl_free(tfcp, fw_fid, &tbl_info);
return rc;
}
static int32_t
ulp_mapper_tfc_cmm_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl,
void *error)
{
bool alloc = false, write = false, global = false, regfile = false;
struct bnxt_ulp_glb_resource_info glb_res = { 0 };
uint16_t bit_size, act_wordlen = 0, tmplen = 0;
struct ulp_flow_db_res_params fid_parms;
struct tfc_cmm_info cmm_info = { 0 };
struct tfc *tfcp = NULL;
struct ulp_blob data;
uint64_t regval = 0;
bool shared = false;
uint64_t handle = 0;
const uint8_t *act_data;
uint64_t act_rec_size = 0;
uint8_t tsid = 0;
int32_t rc = 0;
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
PMD_DRV_LOG_LINE(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
/* compute the blob size */
bit_size = ulp_mapper_tfc_dyn_blob_size_get(parms, tbl);
/* Initialize the blob data */
if (unlikely(ulp_blob_init(&data, bit_size,
parms->device_params->result_byte_order))) {
BNXT_DRV_DBG(ERR, "Failed to initialize cmm table blob\n");
return -EINVAL;
}
switch (tbl->tbl_opcode) {
case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
regfile = true;
alloc = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
/*
* Build the entry, alloc an index, write the table, and store
* the data in the regfile.
*/
alloc = true;
write = true;
regfile = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
/*
* get the index to write to from the regfile and then write
* the table entry.
*/
regfile = true;
write = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
/*
* Build the entry, alloc an index, write the table, and store
* the data in the global regfile.
*/
alloc = true;
global = true;
write = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
if (unlikely(tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP)) {
BNXT_DRV_DBG(ERR, "Template error, wrong fdb opcode\n");
return -EINVAL;
}
/*
* get the index to write to from the global regfile and then
* write the table.
*/
if (unlikely(ulp_mapper_glb_resource_read(parms->mapper_data,
tbl->direction,
tbl->tbl_operand,
®val, &shared))) {
BNXT_DRV_DBG(ERR,
"Failed to get tbl idx from Glb RF[%d].\n",
tbl->tbl_operand);
return -EINVAL;
}
handle = rte_be_to_cpu_64(regval);
/* check to see if any scope id changes needs to be done*/
write = true;
break;
case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
/*
* The read is different from the rest and can be handled here
* instead of trying to use common code. Simply read the table
* with the index from the regfile, scan and store the
* identifiers, and return.
*/
if (unlikely(ulp_regfile_read(parms->regfile,
tbl->tbl_operand, ®val))) {
BNXT_DRV_DBG(ERR,
"Failed to get tbl idx from regfile[%d]\n",
tbl->tbl_operand);
return -EINVAL;
}
handle = rte_be_to_cpu_64(regval);
return 0;
case BNXT_ULP_INDEX_TBL_OPC_NOP_REGFILE:
regfile = true;
alloc = false;
break;
default:
BNXT_DRV_DBG(ERR, "Invalid cmm table opcode %d\n",
tbl->tbl_opcode);
return -EINVAL;
}
/* read the CMM handle from the regfile, it is not allocated */
if (!alloc && regfile) {
if (unlikely(ulp_regfile_read(parms->regfile,
tbl->tbl_operand,
®val))) {
BNXT_DRV_DBG(ERR,
"Failed to get tbl idx from regfile[%d].\n",
tbl->tbl_operand);
return -EINVAL;
}
handle = rte_be_to_cpu_64(regval);
}
/* Get the result fields list */
rc = ulp_mapper_tbl_result_build(parms,
tbl,
&data,
"Indexed Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
/* Allocate the Action CMM identifier */
if (alloc) {
cmm_info.dir = tbl->direction;
cmm_info.rsubtype = tbl->resource_type;
/* Only need the length for alloc, ignore the returned data */
act_data = ulp_blob_data_get(&data, &tmplen);
act_wordlen = ULP_BITS_TO_32_BYTE_WORD(tmplen);
rc = bnxt_ulp_cntxt_tsid_get(parms->ulp_ctx, &tsid);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to get the table scope\n");
return rc;
}
/* All failures after the alloc succeeds require a free */
rc = tfc_act_alloc(tfcp, tsid, &cmm_info, act_wordlen);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Alloc CMM [%d][%s] failed rc=%d\n",
cmm_info.rsubtype,
tfc_dir_2_str(cmm_info.dir), rc);
return rc;
}
handle = cmm_info.act_handle;
/* Counters need to be reset when allocated to ensure counter is
* zero
*/
if (tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_CMM_STAT) {
rc = tfc_act_set(tfcp,
&parms->batch_info,
&cmm_info, act_data,
act_wordlen);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Stat alloc/clear[%d][%s]"
"[0x%" PRIx64 "] failed rc=%d\n",
cmm_info.rsubtype,
tfc_dir_2_str(cmm_info.dir),
cmm_info.act_handle, rc);
if (error != NULL && tfc_is_mpc_error(rc)) {
struct rte_flow_error *fe =
(struct rte_flow_error *)error;
rte_flow_error_set(fe,
EIO,
RTE_FLOW_ERROR_TYPE_HANDLE,
NULL,
mpc_error_str[rc * -1]);
}
goto error;
}
}
}
/* update the global register value */
if (alloc && global) {
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;
regval = rte_cpu_to_be_64(handle);
/*
* Shared resources are never allocated through this
* method, so the shared flag is always false.
*/
rc = ulp_mapper_glb_resource_write(parms->mapper_data,
&glb_res, regval,
false);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to write %s regfile[%d] rc=%d\n",
(global) ? "global" : "reg",
tbl->tbl_operand, rc);
goto error;
}
}
/* update the local register value */
if (alloc && regfile) {
regval = rte_cpu_to_be_64(handle);
rc = ulp_regfile_write(parms->regfile,
tbl->tbl_operand, regval);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to write %s regfile[%d] rc=%d\n",
(global) ? "global" : "reg",
tbl->tbl_operand, rc);
goto error;
}
}
if (write) {
act_data = ulp_blob_data_get(&data, &tmplen);
cmm_info.dir = tbl->direction;
cmm_info.rsubtype = tbl->resource_type;
cmm_info.act_handle = handle;
act_wordlen = ULP_BITS_TO_32_BYTE_WORD(tmplen);
rc = tfc_act_set(tfcp, &parms->batch_info, &cmm_info, act_data, act_wordlen);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"CMM table[%d][%s][0x%" PRIx64
"] write fail %d\n",
cmm_info.rsubtype,
tfc_dir_2_str(cmm_info.dir),
handle, rc);
if (error != NULL && tfc_is_mpc_error(rc)) {
struct rte_flow_error *fe =
(struct rte_flow_error *)error;
rte_flow_error_set(fe,
EIO,
RTE_FLOW_ERROR_TYPE_HANDLE,
NULL,
mpc_error_str[rc * -1]);
}
goto error;
}
BNXT_DRV_DBG(DEBUG,
"CMM table[%d][%s][0x%" PRIx64
"] write successful\n",
cmm_info.rsubtype, tfc_dir_2_str(cmm_info.dir),
handle);
/* Calculate action record size */
if (tbl->resource_type == CFA_RSUBTYPE_CMM_ACT) {
act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
act_rec_size--;
if (ulp_regfile_write(parms->regfile,
BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
rte_cpu_to_be_64(act_rec_size)))
BNXT_DRV_DBG(ERR,
"Failed write the act rec size\n");
}
}
/* Link the resource 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 = handle;
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, "Failed to link resource to flow rc = %d\n",
rc);
goto error;
}
/* Perform the VF rep action */
rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
goto error;
}
return rc;
error:
/* Shared resources are not freed */
if (shared)
return rc;
/*
* Free the allocated resource since we failed to either
* write to the entry or link the flow
*/
if (tfc_act_free(tfcp, &cmm_info))
BNXT_DRV_DBG(ERR, "Failed to free cmm entry on failure\n");
return rc;
}
static int32_t
ulp_mapper_tfc_cmm_entry_free(struct bnxt_ulp_context *ulp_ctx,
struct ulp_flow_db_res_params *res,
void *error)
{
struct tfc *tfcp = NULL;
struct tfc_cmm_info cmm_info = { 0 };
uint16_t fw_fid = 0;
int32_t rc = 0;
/* skip cmm processing if fdb flag is sw only */
if (res->fdb_flags & ULP_FDB_FLAG_SW_ONLY)
return 0;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
cmm_info.dir = (enum cfa_dir)res->direction;
cmm_info.rsubtype = res->resource_type;
cmm_info.act_handle = res->resource_hndl;
/* TBD: check to see if the memory needs to be cleaned as well*/
rc = tfc_act_free(tfcp, &cmm_info);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to delete CMM entry,res = 0x%" PRIx64 "\n",
res->resource_hndl);
if (error != NULL && tfc_is_mpc_error(rc)) {
struct rte_flow_error *fe = (struct rte_flow_error *)error;
rte_flow_error_set(fe,
EIO,
RTE_FLOW_ERROR_TYPE_HANDLE,
NULL,
mpc_error_str[rc * -1]);
}
} else {
BNXT_DRV_DBG(DEBUG, "Deleted CMM entry,res = 0x%" PRIx64 "\n",
res->resource_hndl);
}
return rc;
}
static int32_t
ulp_mapper_tfc_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
struct bnxt_ulp_mapper_tbl_info *tbl)
{
struct ulp_blob data, res_blob;
uint64_t idx = 0;
int32_t rc = 0;
struct tfc *tfcp;
enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
uint32_t res_size;
struct tfc_if_tbl_info tbl_info = { 0 };
unsigned char *data_p;
uint16_t fw_fid = 0;
uint8_t data_size;
uint16_t tmplen;
if (unlikely(bnxt_ulp_cntxt_fid_get(parms->ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
PMD_DRV_LOG_LINE(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
/* Initialize the blob data */
if (unlikely(ulp_blob_init(&data, tbl->result_bit_size,
parms->device_params->result_byte_order))) {
BNXT_DRV_DBG(ERR, "Failed initial index table blob\n");
return -EINVAL;
}
/* create the result blob */
rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Failed to build the result blob\n");
return rc;
}
/* Get the index details */
switch (if_opc) {
case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
break;
case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
if (unlikely(ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx))) {
BNXT_DRV_DBG(ERR, "regfile[%d] read oob\n",
tbl->tbl_operand);
return -EINVAL;
}
idx = rte_be_to_cpu_64(idx);
break;
case BNXT_ULP_IF_TBL_OPC_WR_CONST:
idx = tbl->tbl_operand;
break;
case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
/* Initialize the result blob */
if (unlikely(ulp_blob_init(&res_blob, tbl->result_bit_size,
parms->device_params->result_byte_order))) {
BNXT_DRV_DBG(ERR, "Failed initial result blob\n");
return -EINVAL;
}
/* read the interface table */
idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
res_blob.data,
res_size,
res_blob.byte_order);
if (unlikely(rc))
BNXT_DRV_DBG(ERR, "Scan and extract failed rc=%d\n",
rc);
return rc;
case BNXT_ULP_IF_TBL_OPC_NOT_USED:
return rc; /* skip it */
default:
BNXT_DRV_DBG(ERR, "Invalid tbl index opcode\n");
return -EINVAL;
}
tbl_info.dir = tbl->direction;
tbl_info.rsubtype = tbl->resource_type;
tbl_info.id = (uint32_t)idx;
data_p = ulp_blob_data_get(&data, &tmplen);
data_size = ULP_BITS_2_BYTE(tmplen);
rc = tfc_if_tbl_set(tfcp, fw_fid, &tbl_info, (uint8_t *)data_p,
data_size);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR,
"Failed to write the if tbl entry %d:%d\n",
tbl->resource_type, (uint32_t)idx);
return rc;
}
return rc;
}
static int32_t
ulp_mapper_tfc_ident_alloc(struct bnxt_ulp_context *ulp_ctx,
uint32_t session_type __rte_unused,
uint16_t ident_type,
uint8_t direction,
enum cfa_track_type tt,
uint64_t *identifier_id)
{
struct tfc *tfcp = NULL;
struct tfc_identifier_info ident_info = { 0 };
int32_t rc = 0;
uint16_t fw_fid = 0;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
ident_info.dir = direction;
ident_info.rsubtype = ident_type;
rc = tfc_identifier_alloc(tfcp, fw_fid, tt, &ident_info);
if (unlikely(rc != 0)) {
BNXT_DRV_DBG(ERR, "alloc failed %d\n", rc);
return rc;
}
*identifier_id = ident_info.id;
return rc;
}
static int32_t
ulp_mapper_tfc_ident_free(struct bnxt_ulp_context *ulp_ctx,
struct ulp_flow_db_res_params *res)
{
struct tfc *tfcp = NULL;
struct tfc_identifier_info ident_info = { 0 };
int32_t rc = 0;
uint16_t fw_fid = 0;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
ident_info.dir = (enum cfa_dir)res->direction;
ident_info.rsubtype = res->resource_type;
ident_info.id = res->resource_hndl;
rc = tfc_identifier_free(tfcp, fw_fid, &ident_info);
if (unlikely(rc != 0)) {
BNXT_DRV_DBG(ERR, "free failed %d\n", rc);
return rc;
}
return rc;
}
static int32_t
ulp_mapper_tfc_global_ident_alloc(struct bnxt_ulp_context *ulp_ctx,
uint16_t ident_type,
uint8_t direction,
uint8_t *context_id,
uint16_t context_len,
uint64_t *identifier_id)
{
struct tfc *tfcp = NULL;
struct tfc_global_id_req glb_req = { 0 };
struct tfc_global_id glb_rsp = { 0 };
uint16_t fw_fid = 0;
int32_t rc = 0;
bool first = false;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
glb_req.rtype = CFA_RTYPE_IDENT;
glb_req.dir = direction;
glb_req.rsubtype = ident_type;
glb_req.context_len = context_len;
glb_req.context_id = context_id;
rc = tfc_global_id_alloc(tfcp, fw_fid, &glb_req, &glb_rsp, &first);
if (unlikely(rc != 0)) {
BNXT_DRV_DBG(ERR, "alloc failed %d\n", rc);
return rc;
}
*identifier_id = glb_rsp.id;
return rc;
}
static int32_t
ulp_mapper_tfc_global_ident_free(struct bnxt_ulp_context *ulp_ctx,
struct ulp_flow_db_res_params *res)
{
struct tfc_global_id_req glb_req = { 0 };
struct tfc *tfcp = NULL;
int32_t rc = 0;
uint16_t fw_fid = 0;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
glb_req.rtype = CFA_RTYPE_IDENT;
glb_req.dir = (enum cfa_dir)res->direction;
glb_req.rsubtype = res->resource_type;
glb_req.resource_id = (uint16_t)res->resource_hndl;
rc = tfc_global_id_free(tfcp, fw_fid, &glb_req);
if (unlikely(rc != 0)) {
BNXT_DRV_DBG(ERR, "free failed %d\n", rc);
return rc;
}
return rc;
}
static inline int32_t
ulp_mapper_tfc_tcam_entry_free(struct bnxt_ulp_context *ulp,
struct ulp_flow_db_res_params *res)
{
struct tfc *tfcp = NULL;
struct tfc_tcam_info tcam_info = { 0 };
uint16_t fw_fid = 0;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp);
if (unlikely(tfcp == NULL)) {
PMD_DRV_LOG_LINE(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
tcam_info.dir = (enum cfa_dir)res->direction;
tcam_info.rsubtype = res->resource_type;
tcam_info.id = (uint16_t)res->resource_hndl;
if (unlikely(!tfcp || tfc_tcam_free(tfcp, fw_fid, &tcam_info))) {
BNXT_DRV_DBG(ERR, "Unable to free tcam resource %u\n",
tcam_info.id);
return -EINVAL;
}
return 0;
}
static uint32_t
ulp_mapper_tfc_dyn_tbl_type_get(struct bnxt_ulp_mapper_parms *parm __rte_unused,
struct bnxt_ulp_mapper_tbl_info *tbl,
uint16_t blob_len,
uint16_t *out_len)
{
switch (tbl->resource_type) {
case CFA_RSUBTYPE_CMM_ACT:
*out_len = ULP_BITS_TO_32_BYTE_WORD(blob_len);
*out_len = *out_len * 256;
break;
default:
BNXT_DRV_DBG(ERR, "Not a dynamic table %d\n", tbl->resource_type);
*out_len = blob_len;
break;
}
return tbl->resource_type;
}
static int32_t
ulp_mapper_tfc_index_tbl_alloc_process(struct bnxt_ulp_context *ulp,
uint32_t session_type __rte_unused,
uint16_t table_type,
uint8_t direction,
uint64_t *index)
{
enum cfa_track_type tt = CFA_TRACK_TYPE_SID;
struct tfc_idx_tbl_info tbl_info = { 0 };
struct tfc *tfcp = NULL;
uint16_t fw_fid = 0;
int32_t rc = 0;
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer\n");
return -EINVAL;
}
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func id\n");
return -EINVAL;
}
tbl_info.rsubtype = table_type;
tbl_info.dir = direction;
rc = tfc_idx_tbl_alloc(tfcp, fw_fid, tt, &tbl_info);
if (unlikely(rc)) {
BNXT_DRV_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
tfc_idx_tbl_2_str(tbl_info.rsubtype),
tfc_dir_2_str(direction), rc);
return rc;
}
*index = tbl_info.id;
return rc;
}
static int32_t
ulp_mapper_tfc_app_glb_resource_info_init(struct bnxt_ulp_context
*ulp_ctx __rte_unused,
struct bnxt_ulp_mapper_data
*mapper_data __rte_unused)
{
/* Not supported Shared Apps yet on TFC API */
return 0;
}
static int32_t
ulp_mapper_tfc_handle_to_offset(struct bnxt_ulp_mapper_parms *parms __rte_unused,
uint64_t handle,
uint32_t offset,
uint64_t *result)
{
uint32_t val = 0;
int32_t rc = 0;
TFC_GET_32B_OFFSET_ACT_HANDLE(val, &handle);
switch (offset) {
case 0:
val = val << 5;
break;
case 4:
val = val << 3;
break;
case 8:
val = val << 2;
break;
case 16:
val = val << 1;
break;
case 32:
break;
default:
return -EINVAL;
}
*result = val;
return rc;
}
static int
ulp_mapper_tfc_mpc_batch_start(struct tfc_mpc_batch_info_t *batch_info)
{
return tfc_mpc_batch_start(batch_info);
}
static int32_t
ulp_mapper_tfc_mtr_stats_hndl_set(struct bnxt_ulp_mapper_parms *parms __rte_unused,
uint32_t mtr_id, uint64_t stats_hndl)
{
int32_t i, rc = -ENOMEM;
for (i = 0; i < BNXT_METER_MAX_NUM; i++)
if (!mtr_stats[i].valid) {
mtr_stats[i].mtr_id = mtr_id;
mtr_stats[i].stats_hndl = stats_hndl;
mtr_stats[i].valid = true;
rc = 0;
break;
}
return rc;
}
static int32_t
ulp_mapper_tfc_mtr_stats_hndl_get(uint32_t mtr_id, uint64_t *stats_hndl)
{
int32_t i, rc = -EINVAL;
for (i = 0; i < BNXT_METER_MAX_NUM; i++) {
if (mtr_stats[i].valid && mtr_stats[i].mtr_id == mtr_id) {
*stats_hndl = mtr_stats[i].stats_hndl;
rc = 0;
break;
}
}
return rc;
}
static int32_t
ulp_mapper_tfc_mtr_stats_hndl_del(uint32_t mtr_id)
{
int32_t i, rc = -EINVAL;
for (i = 0; i < BNXT_METER_MAX_NUM; i++)
if (mtr_stats[i].valid && mtr_stats[i].mtr_id == mtr_id) {
mtr_stats[i].valid = false;
rc = 0;
break;
}
return rc;
}
static int32_t
ulp_mapper_tfc_glb_idx_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
uint16_t sub_type, uint8_t direction,
uint8_t *context_id, uint16_t context_len,
uint64_t *idx_id)
{
struct tfc *tfcp = NULL;
struct tfc_global_id_req glb_req = { 0 };
struct tfc_global_id glb_rsp = { 0 };
uint16_t fw_fid = 0;
int32_t rc = 0;
bool first = false;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
glb_req.rtype = CFA_RTYPE_IDX_TBL;
glb_req.dir = direction;
glb_req.rsubtype = sub_type;
glb_req.context_len = context_len;
glb_req.context_id = context_id;
rc = tfc_global_id_alloc(tfcp, fw_fid, &glb_req, &glb_rsp, &first);
if (unlikely(rc != 0)) {
BNXT_DRV_DBG(ERR, "alloc failed %d", rc);
return rc;
}
*idx_id = glb_rsp.id;
return rc;
}
static int32_t
ulp_mapper_tfc_glb_idx_tbl_free(struct bnxt_ulp_context *ulp_ctx,
struct ulp_flow_db_res_params *res)
{
struct tfc_global_id_req glb_req = { 0 };
struct tfc *tfcp = NULL;
int32_t rc = 0;
uint16_t fw_fid = 0;
if (unlikely(bnxt_ulp_cntxt_fid_get(ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(ulp_ctx);
if (unlikely(tfcp == NULL)) {
BNXT_DRV_DBG(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
glb_req.rtype = CFA_RTYPE_IDX_TBL;
glb_req.dir = (enum cfa_dir)res->direction;
glb_req.rsubtype = res->resource_type;
glb_req.resource_id = (uint16_t)res->resource_hndl;
rc = tfc_global_id_free(tfcp, fw_fid, &glb_req);
if (unlikely(rc != 0)) {
BNXT_DRV_DBG(ERR, "free failed %d", rc);
return rc;
}
return rc;
}
static inline int32_t
ulp_mapper_tfc_tcam_prio_update(struct bnxt_ulp_mapper_parms *parms,
uint8_t dir,
enum cfa_track_type tt,
enum cfa_resource_subtype_tcam rtype,
uint32_t tcam_id,
uint16_t priority)
{
struct tfc *tfcp = NULL;
struct tfc_tcam_info tcam_info = { 0 };
uint16_t fw_fid = 0;
if (unlikely(bnxt_ulp_cntxt_fid_get(parms->ulp_ctx, &fw_fid))) {
BNXT_DRV_DBG(ERR, "Failed to get func_id\n");
return -EINVAL;
}
tfcp = bnxt_ulp_cntxt_tfcp_get(parms->ulp_ctx);
if (unlikely(tfcp == NULL)) {
PMD_DRV_LOG_LINE(ERR, "Failed to get tfcp pointer");
return -EINVAL;
}
tcam_info.dir = (enum cfa_dir)dir;
tcam_info.rsubtype = rtype;
tcam_info.id = (uint16_t)tcam_id;
if (unlikely(!tfcp || tfc_tcam_priority_update(tfcp, fw_fid, tt,
&tcam_info,
priority))) {
BNXT_DRV_DBG(ERR, "Unable to update tcam priority %u\n",
tcam_info.id);
return -EINVAL;
}
return 0;
}
const struct ulp_mapper_core_ops ulp_mapper_tfc_core_ops = {
.ulp_mapper_core_tcam_tbl_process = ulp_mapper_tfc_tcam_tbl_process,
.ulp_mapper_core_tcam_entry_free = ulp_mapper_tfc_tcam_entry_free,
.ulp_mapper_core_tcam_prio_update = ulp_mapper_tfc_tcam_prio_update,
.ulp_mapper_core_em_tbl_process = ulp_mapper_tfc_em_tbl_process,
.ulp_mapper_core_em_entry_free = ulp_mapper_tfc_em_entry_free,
.ulp_mapper_core_index_tbl_process = ulp_mapper_tfc_index_tbl_process,
.ulp_mapper_core_index_entry_free = ulp_mapper_tfc_index_entry_free,
.ulp_mapper_core_cmm_tbl_process = ulp_mapper_tfc_cmm_tbl_process,
.ulp_mapper_core_cmm_entry_free = ulp_mapper_tfc_cmm_entry_free,
.ulp_mapper_core_if_tbl_process = ulp_mapper_tfc_if_tbl_process,
.ulp_mapper_core_ident_alloc_process = ulp_mapper_tfc_ident_alloc,
.ulp_mapper_core_ident_free = ulp_mapper_tfc_ident_free,
.ulp_mapper_core_global_ident_alloc = ulp_mapper_tfc_global_ident_alloc,
.ulp_mapper_core_global_ident_free = ulp_mapper_tfc_global_ident_free,
.ulp_mapper_core_glb_idx_tbl_alloc = ulp_mapper_tfc_glb_idx_tbl_alloc,
.ulp_mapper_core_glb_idx_tbl_free = ulp_mapper_tfc_glb_idx_tbl_free,
.ulp_mapper_core_dyn_tbl_type_get = ulp_mapper_tfc_dyn_tbl_type_get,
.ulp_mapper_core_index_tbl_alloc_process =
ulp_mapper_tfc_index_tbl_alloc_process,
.ulp_mapper_core_app_glb_res_info_init =
ulp_mapper_tfc_app_glb_resource_info_init,
.ulp_mapper_core_handle_to_offset = ulp_mapper_tfc_handle_to_offset,
.ulp_mapper_mpc_batch_start = ulp_mapper_tfc_mpc_batch_start,
.ulp_mapper_mpc_batch_started = ulp_mapper_tfc_mpc_batch_started,
.ulp_mapper_mpc_batch_end = ulp_mapper_tfc_mpc_batch_end,
.ulp_mapper_mtr_stats_hndl_set = ulp_mapper_tfc_mtr_stats_hndl_set,
.ulp_mapper_mtr_stats_hndl_get = ulp_mapper_tfc_mtr_stats_hndl_get,
.ulp_mapper_mtr_stats_hndl_del = ulp_mapper_tfc_mtr_stats_hndl_del
};
|