Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs

On some silicon variants the number of available CAM entries are
less. Reserving one entry for each NIX-LF for default DMAC based pkt
forwarding rules will reduce the number of available CAM entries
further. Hence add configurability via devlink to set maximum number of
NIX-LFs needed which inturn frees up some CAM entries.

Signed-off-by: Suman Ghosh <sumang@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Suman Ghosh and committed by
David S. Miller
dd784287 3a3af3ae

+133 -24
+2
drivers/net/ethernet/marvell/octeontx2/af/rvu.h
··· 949 949 u64 bcast_mcast_val, u64 bcast_mcast_mask); 950 950 void npc_mcam_rsrcs_reserve(struct rvu *rvu, int blkaddr, int entry_idx); 951 951 bool npc_is_feature_supported(struct rvu *rvu, u64 features, u8 intf); 952 + int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr); 953 + void npc_mcam_rsrcs_deinit(struct rvu *rvu); 952 954 953 955 /* CPT APIs */ 954 956 int rvu_cpt_register_interrupts(struct rvu *rvu);
+80
drivers/net/ethernet/marvell/octeontx2/af/rvu_devlink.c
··· 1237 1237 RVU_AF_DEVLINK_PARAM_ID_DWRR_MTU, 1238 1238 RVU_AF_DEVLINK_PARAM_ID_NPC_EXACT_FEATURE_DISABLE, 1239 1239 RVU_AF_DEVLINK_PARAM_ID_NPC_MCAM_ZONE_PERCENT, 1240 + RVU_AF_DEVLINK_PARAM_ID_NIX_MAXLF, 1240 1241 }; 1241 1242 1242 1243 static int rvu_af_npc_exact_feature_get(struct devlink *devlink, u32 id, ··· 1355 1354 return 0; 1356 1355 } 1357 1356 1357 + static int rvu_af_dl_nix_maxlf_get(struct devlink *devlink, u32 id, 1358 + struct devlink_param_gset_ctx *ctx) 1359 + { 1360 + struct rvu_devlink *rvu_dl = devlink_priv(devlink); 1361 + struct rvu *rvu = rvu_dl->rvu; 1362 + 1363 + ctx->val.vu16 = (u16)rvu_get_nixlf_count(rvu); 1364 + 1365 + return 0; 1366 + } 1367 + 1368 + static int rvu_af_dl_nix_maxlf_set(struct devlink *devlink, u32 id, 1369 + struct devlink_param_gset_ctx *ctx) 1370 + { 1371 + struct rvu_devlink *rvu_dl = devlink_priv(devlink); 1372 + struct rvu *rvu = rvu_dl->rvu; 1373 + struct rvu_block *block; 1374 + int blkaddr = 0; 1375 + 1376 + npc_mcam_rsrcs_deinit(rvu); 1377 + blkaddr = rvu_get_next_nix_blkaddr(rvu, blkaddr); 1378 + while (blkaddr) { 1379 + block = &rvu->hw->block[blkaddr]; 1380 + block->lf.max = ctx->val.vu16; 1381 + blkaddr = rvu_get_next_nix_blkaddr(rvu, blkaddr); 1382 + } 1383 + 1384 + blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); 1385 + npc_mcam_rsrcs_init(rvu, blkaddr); 1386 + 1387 + return 0; 1388 + } 1389 + 1390 + static int rvu_af_dl_nix_maxlf_validate(struct devlink *devlink, u32 id, 1391 + union devlink_param_value val, 1392 + struct netlink_ext_ack *extack) 1393 + { 1394 + struct rvu_devlink *rvu_dl = devlink_priv(devlink); 1395 + struct rvu *rvu = rvu_dl->rvu; 1396 + u16 max_nix0_lf, max_nix1_lf; 1397 + struct npc_mcam *mcam; 1398 + u64 cfg; 1399 + 1400 + cfg = rvu_read64(rvu, BLKADDR_NIX0, NIX_AF_CONST2); 1401 + max_nix0_lf = cfg & 0xFFF; 1402 + cfg = rvu_read64(rvu, BLKADDR_NIX1, NIX_AF_CONST2); 1403 + max_nix1_lf = cfg & 0xFFF; 1404 + 1405 + /* Do not allow user to modify maximum NIX LFs while mcam entries 1406 + * have already been assigned. 1407 + */ 1408 + mcam = &rvu->hw->mcam; 1409 + if (mcam->bmap_fcnt < mcam->bmap_entries) { 1410 + NL_SET_ERR_MSG_MOD(extack, 1411 + "mcam entries have already been assigned, can't resize"); 1412 + return -EPERM; 1413 + } 1414 + 1415 + if (max_nix0_lf && val.vu16 > max_nix0_lf) { 1416 + NL_SET_ERR_MSG_MOD(extack, 1417 + "requested nixlf is greater than the max supported nix0_lf"); 1418 + return -EPERM; 1419 + } 1420 + 1421 + if (max_nix1_lf && val.vu16 > max_nix1_lf) { 1422 + NL_SET_ERR_MSG_MOD(extack, 1423 + "requested nixlf is greater than the max supported nix1_lf"); 1424 + return -EINVAL; 1425 + } 1426 + 1427 + return 0; 1428 + } 1429 + 1358 1430 static const struct devlink_param rvu_af_dl_params[] = { 1359 1431 DEVLINK_PARAM_DRIVER(RVU_AF_DEVLINK_PARAM_ID_DWRR_MTU, 1360 1432 "dwrr_mtu", DEVLINK_PARAM_TYPE_U32, ··· 1449 1375 rvu_af_dl_npc_mcam_high_zone_percent_get, 1450 1376 rvu_af_dl_npc_mcam_high_zone_percent_set, 1451 1377 rvu_af_dl_npc_mcam_high_zone_percent_validate), 1378 + DEVLINK_PARAM_DRIVER(RVU_AF_DEVLINK_PARAM_ID_NIX_MAXLF, 1379 + "nix_maxlf", DEVLINK_PARAM_TYPE_U16, 1380 + BIT(DEVLINK_PARAM_CMODE_RUNTIME), 1381 + rvu_af_dl_nix_maxlf_get, 1382 + rvu_af_dl_nix_maxlf_set, 1383 + rvu_af_dl_nix_maxlf_validate), 1452 1384 }; 1453 1385 1454 1386 /* Devlink switch mode */
+51 -24
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
··· 1846 1846 npc_program_kpu_profile(rvu, blkaddr, idx, &rvu->kpu.kpu[idx]); 1847 1847 } 1848 1848 1849 - static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr) 1849 + void npc_mcam_rsrcs_deinit(struct rvu *rvu) 1850 + { 1851 + struct npc_mcam *mcam = &rvu->hw->mcam; 1852 + 1853 + kfree(mcam->bmap); 1854 + kfree(mcam->bmap_reverse); 1855 + kfree(mcam->entry2pfvf_map); 1856 + kfree(mcam->cntr2pfvf_map); 1857 + kfree(mcam->entry2cntr_map); 1858 + kfree(mcam->cntr_refcnt); 1859 + kfree(mcam->entry2target_pffunc); 1860 + kfree(mcam->counters.bmap); 1861 + } 1862 + 1863 + int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr) 1850 1864 { 1851 1865 int nixlf_count = rvu_get_nixlf_count(rvu); 1852 1866 struct npc_mcam *mcam = &rvu->hw->mcam; ··· 1904 1890 mcam->pf_offset = mcam->nixlf_offset + nixlf_count; 1905 1891 1906 1892 /* Allocate bitmaps for managing MCAM entries */ 1907 - mcam->bmap = devm_kcalloc(rvu->dev, BITS_TO_LONGS(mcam->bmap_entries), 1908 - sizeof(long), GFP_KERNEL); 1893 + mcam->bmap = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries), 1894 + sizeof(long), GFP_KERNEL); 1909 1895 if (!mcam->bmap) 1910 1896 return -ENOMEM; 1911 1897 1912 - mcam->bmap_reverse = devm_kcalloc(rvu->dev, 1913 - BITS_TO_LONGS(mcam->bmap_entries), 1914 - sizeof(long), GFP_KERNEL); 1898 + mcam->bmap_reverse = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries), 1899 + sizeof(long), GFP_KERNEL); 1915 1900 if (!mcam->bmap_reverse) 1916 - return -ENOMEM; 1901 + goto free_bmap; 1917 1902 1918 1903 mcam->bmap_fcnt = mcam->bmap_entries; 1919 1904 1920 1905 /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */ 1921 - mcam->entry2pfvf_map = devm_kcalloc(rvu->dev, mcam->bmap_entries, 1922 - sizeof(u16), GFP_KERNEL); 1906 + mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries, 1907 + sizeof(u16), GFP_KERNEL); 1923 1908 if (!mcam->entry2pfvf_map) 1924 - return -ENOMEM; 1909 + goto free_bmap_reverse; 1925 1910 1926 1911 /* Reserve 1/8th of MCAM entries at the bottom for low priority 1927 1912 * allocations and another 1/8th at the top for high priority ··· 1939 1926 */ 1940 1927 err = rvu_alloc_bitmap(&mcam->counters); 1941 1928 if (err) 1942 - return err; 1929 + goto free_entry_map; 1943 1930 1944 - mcam->cntr2pfvf_map = devm_kcalloc(rvu->dev, mcam->counters.max, 1945 - sizeof(u16), GFP_KERNEL); 1931 + mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max, 1932 + sizeof(u16), GFP_KERNEL); 1946 1933 if (!mcam->cntr2pfvf_map) 1947 - goto free_mem; 1934 + goto free_cntr_bmap; 1948 1935 1949 1936 /* Alloc memory for MCAM entry to counter mapping and for tracking 1950 1937 * counter's reference count. 1951 1938 */ 1952 - mcam->entry2cntr_map = devm_kcalloc(rvu->dev, mcam->bmap_entries, 1953 - sizeof(u16), GFP_KERNEL); 1939 + mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries, 1940 + sizeof(u16), GFP_KERNEL); 1954 1941 if (!mcam->entry2cntr_map) 1955 - goto free_mem; 1942 + goto free_cntr_map; 1956 1943 1957 - mcam->cntr_refcnt = devm_kcalloc(rvu->dev, mcam->counters.max, 1958 - sizeof(u16), GFP_KERNEL); 1944 + mcam->cntr_refcnt = kmalloc_array(mcam->counters.max, 1945 + sizeof(u16), GFP_KERNEL); 1959 1946 if (!mcam->cntr_refcnt) 1960 - goto free_mem; 1947 + goto free_entry_cntr_map; 1961 1948 1962 1949 /* Alloc memory for saving target device of mcam rule */ 1963 - mcam->entry2target_pffunc = devm_kcalloc(rvu->dev, mcam->total_entries, 1964 - sizeof(u16), GFP_KERNEL); 1950 + mcam->entry2target_pffunc = kmalloc_array(mcam->total_entries, 1951 + sizeof(u16), GFP_KERNEL); 1965 1952 if (!mcam->entry2target_pffunc) 1966 - goto free_mem; 1953 + goto free_cntr_refcnt; 1967 1954 1968 1955 for (index = 0; index < mcam->bmap_entries; index++) { 1969 1956 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP; ··· 1977 1964 1978 1965 return 0; 1979 1966 1980 - free_mem: 1967 + free_cntr_refcnt: 1968 + kfree(mcam->cntr_refcnt); 1969 + free_entry_cntr_map: 1970 + kfree(mcam->entry2cntr_map); 1971 + free_cntr_map: 1972 + kfree(mcam->cntr2pfvf_map); 1973 + free_cntr_bmap: 1981 1974 kfree(mcam->counters.bmap); 1975 + free_entry_map: 1976 + kfree(mcam->entry2pfvf_map); 1977 + free_bmap_reverse: 1978 + kfree(mcam->bmap_reverse); 1979 + free_bmap: 1980 + kfree(mcam->counters.bmap); 1981 + 1982 1982 return -ENOMEM; 1983 1983 } 1984 1984 ··· 2199 2173 struct npc_mcam *mcam = &rvu->hw->mcam; 2200 2174 2201 2175 kfree(pkind->rsrc.bmap); 2176 + npc_mcam_rsrcs_deinit(rvu); 2202 2177 kfree(mcam->counters.bmap); 2203 2178 if (rvu->kpu_prfl_addr) 2204 2179 iounmap(rvu->kpu_prfl_addr);