Skip to content

Commit 3571fe0

Browse files
rkannoth1kuba-moo
authored andcommitted
octeontx2-af: Drop rules for NPC MCAM
NPC exact match table installs drop on hit rules in NPC mcam for each channel. This rule has broadcast and multicast bits cleared. Exact match bit cleared and channel bits set. If exact match table hit bit is 0, corresponding NPC mcam drop rule will be hit for the packet and will be dropped. Signed-off-by: Ratheesh Kannoth <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bab9eed commit 3571fe0

File tree

6 files changed

+481
-6
lines changed

6 files changed

+481
-6
lines changed

drivers/net/ethernet/marvell/octeontx2/af/rvu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,12 @@ static int rvu_setup_hw_resources(struct rvu *rvu)
11281128
goto cgx_err;
11291129
}
11301130

1131+
err = rvu_npc_exact_init(rvu);
1132+
if (err) {
1133+
dev_err(rvu->dev, "failed to initialize exact match table\n");
1134+
return err;
1135+
}
1136+
11311137
/* Assign MACs for CGX mapped functions */
11321138
rvu_setup_pfvf_macaddress(rvu);
11331139

drivers/net/ethernet/marvell/octeontx2/af/rvu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ void rvu_npc_enable_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
791791
void npc_enadis_default_mce_entry(struct rvu *rvu, u16 pcifunc,
792792
int nixlf, int type, bool enable);
793793
void rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
794+
bool rvu_npc_enable_mcam_by_entry_index(struct rvu *rvu, int entry, int intf, bool enable);
794795
void rvu_npc_free_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
795796
void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
796797
void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
@@ -835,6 +836,7 @@ int rvu_npc_init(struct rvu *rvu);
835836
int npc_install_mcam_drop_rule(struct rvu *rvu, int mcam_idx, u16 *counter_idx,
836837
u64 chan_val, u64 chan_mask, u64 exact_val, u64 exact_mask,
837838
u64 bcast_mcast_val, u64 bcast_mcast_mask);
839+
void npc_mcam_rsrcs_reserve(struct rvu *rvu, int blkaddr, int entry_idx);
838840

839841
/* CPT APIs */
840842
int rvu_cpt_register_interrupts(struct rvu *rvu);

drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,34 @@ void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
11061106
NIXLF_PROMISC_ENTRY, false);
11071107
}
11081108

1109+
bool rvu_npc_enable_mcam_by_entry_index(struct rvu *rvu, int entry, int intf, bool enable)
1110+
{
1111+
int blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1112+
struct npc_mcam *mcam = &rvu->hw->mcam;
1113+
struct rvu_npc_mcam_rule *rule, *tmp;
1114+
1115+
mutex_lock(&mcam->lock);
1116+
1117+
list_for_each_entry_safe(rule, tmp, &mcam->mcam_rules, list) {
1118+
if (rule->intf != intf)
1119+
continue;
1120+
1121+
if (rule->entry != entry)
1122+
continue;
1123+
1124+
rule->enable = enable;
1125+
mutex_unlock(&mcam->lock);
1126+
1127+
npc_enable_mcam_entry(rvu, mcam, blkaddr,
1128+
entry, enable);
1129+
1130+
return true;
1131+
}
1132+
1133+
mutex_unlock(&mcam->lock);
1134+
return false;
1135+
}
1136+
11091137
void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf)
11101138
{
11111139
/* Enables only broadcast match entry. Promisc/Allmulti are enabled
@@ -1816,7 +1844,6 @@ static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
18161844
mcam->hprio_count = mcam->lprio_count;
18171845
mcam->hprio_end = mcam->hprio_count;
18181846

1819-
18201847
/* Allocate bitmap for managing MCAM counters and memory
18211848
* for saving counter to RVU PFFUNC allocation mapping.
18221849
*/
@@ -2560,6 +2587,14 @@ static int npc_mcam_alloc_entries(struct npc_mcam *mcam, u16 pcifunc,
25602587
return 0;
25612588
}
25622589

2590+
/* Marks bitmaps to reserved the mcam slot */
2591+
void npc_mcam_rsrcs_reserve(struct rvu *rvu, int blkaddr, int entry_idx)
2592+
{
2593+
struct npc_mcam *mcam = &rvu->hw->mcam;
2594+
2595+
npc_mcam_set_bit(mcam, entry_idx);
2596+
}
2597+
25632598
int rvu_mbox_handler_npc_mcam_alloc_entry(struct rvu *rvu,
25642599
struct npc_mcam_alloc_entry_req *req,
25652600
struct npc_mcam_alloc_entry_rsp *rsp)

drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "rvu_reg.h"
1111
#include "rvu.h"
1212
#include "npc.h"
13-
#include "rvu_npc_hash.h"
1413
#include "rvu_npc_fs.h"
14+
#include "rvu_npc_hash.h"
1515

1616
#define NPC_BYTESM GENMASK_ULL(19, 16)
1717
#define NPC_HDR_OFFSET GENMASK_ULL(15, 8)
@@ -297,6 +297,7 @@ static void npc_scan_parse_result(struct npc_mcam *mcam, u8 bit_number,
297297
default:
298298
return;
299299
}
300+
300301
npc_set_kw_masks(mcam, type, nr_bits, kwi, offset, intf);
301302
}
302303

@@ -860,6 +861,7 @@ do { \
860861
} while (0)
861862

862863
NPC_WRITE_FLOW(NPC_DMAC, dmac, dmac_val, 0, dmac_mask, 0);
864+
863865
NPC_WRITE_FLOW(NPC_SMAC, smac, smac_val, 0, smac_mask, 0);
864866
NPC_WRITE_FLOW(NPC_ETYPE, etype, ntohs(pkt->etype), 0,
865867
ntohs(mask->etype), 0);
@@ -891,8 +893,7 @@ do { \
891893
pkt, mask, opkt, omask);
892894
}
893895

894-
static struct rvu_npc_mcam_rule *rvu_mcam_find_rule(struct npc_mcam *mcam,
895-
u16 entry)
896+
static struct rvu_npc_mcam_rule *rvu_mcam_find_rule(struct npc_mcam *mcam, u16 entry)
896897
{
897898
struct rvu_npc_mcam_rule *iter;
898899

@@ -1058,8 +1059,9 @@ static int npc_install_flow(struct rvu *rvu, int blkaddr, u16 target,
10581059
u16 owner = req->hdr.pcifunc;
10591060
struct msg_rsp write_rsp;
10601061
struct mcam_entry *entry;
1061-
int entry_index, err;
10621062
bool new = false;
1063+
u16 entry_index;
1064+
int err;
10631065

10641066
installed_features = req->features;
10651067
features = req->features;
@@ -1460,3 +1462,98 @@ void npc_mcam_disable_flows(struct rvu *rvu, u16 target)
14601462
}
14611463
mutex_unlock(&mcam->lock);
14621464
}
1465+
1466+
/* single drop on non hit rule starting from 0th index. This an extension
1467+
* to RPM mac filter to support more rules.
1468+
*/
1469+
int npc_install_mcam_drop_rule(struct rvu *rvu, int mcam_idx, u16 *counter_idx,
1470+
u64 chan_val, u64 chan_mask, u64 exact_val, u64 exact_mask,
1471+
u64 bcast_mcast_val, u64 bcast_mcast_mask)
1472+
{
1473+
struct npc_mcam_alloc_counter_req cntr_req = { 0 };
1474+
struct npc_mcam_alloc_counter_rsp cntr_rsp = { 0 };
1475+
struct npc_mcam_write_entry_req req = { 0 };
1476+
struct npc_mcam *mcam = &rvu->hw->mcam;
1477+
struct rvu_npc_mcam_rule *rule;
1478+
struct msg_rsp rsp;
1479+
bool enabled;
1480+
int blkaddr;
1481+
int err;
1482+
1483+
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1484+
if (blkaddr < 0) {
1485+
dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__);
1486+
return -ENODEV;
1487+
}
1488+
1489+
/* Bail out if no exact match support */
1490+
if (!rvu_npc_exact_has_match_table(rvu)) {
1491+
dev_info(rvu->dev, "%s: No support for exact match feature\n", __func__);
1492+
return -EINVAL;
1493+
}
1494+
1495+
/* If 0th entry is already used, return err */
1496+
enabled = is_mcam_entry_enabled(rvu, mcam, blkaddr, mcam_idx);
1497+
if (enabled) {
1498+
dev_err(rvu->dev, "%s: failed to add single drop on non hit rule at %d th index\n",
1499+
__func__, mcam_idx);
1500+
return -EINVAL;
1501+
}
1502+
1503+
/* Add this entry to mcam rules list */
1504+
rule = kzalloc(sizeof(*rule), GFP_KERNEL);
1505+
if (!rule)
1506+
return -ENOMEM;
1507+
1508+
/* Disable rule by default. Enable rule when first dmac filter is
1509+
* installed
1510+
*/
1511+
rule->enable = false;
1512+
rule->chan = chan_val;
1513+
rule->chan_mask = chan_mask;
1514+
rule->entry = mcam_idx;
1515+
rvu_mcam_add_rule(mcam, rule);
1516+
1517+
/* Reserve slot 0 */
1518+
npc_mcam_rsrcs_reserve(rvu, blkaddr, mcam_idx);
1519+
1520+
/* Allocate counter for this single drop on non hit rule */
1521+
cntr_req.hdr.pcifunc = 0; /* AF request */
1522+
cntr_req.contig = true;
1523+
cntr_req.count = 1;
1524+
err = rvu_mbox_handler_npc_mcam_alloc_counter(rvu, &cntr_req, &cntr_rsp);
1525+
if (err) {
1526+
dev_err(rvu->dev, "%s: Err to allocate cntr for drop rule (err=%d)\n",
1527+
__func__, err);
1528+
return -EFAULT;
1529+
}
1530+
*counter_idx = cntr_rsp.cntr;
1531+
1532+
/* Fill in fields for this mcam entry */
1533+
npc_update_entry(rvu, NPC_EXACT_RESULT, &req.entry_data, exact_val, 0,
1534+
exact_mask, 0, NIX_INTF_RX);
1535+
npc_update_entry(rvu, NPC_CHAN, &req.entry_data, chan_val, 0,
1536+
chan_mask, 0, NIX_INTF_RX);
1537+
npc_update_entry(rvu, NPC_LXMB, &req.entry_data, bcast_mcast_val, 0,
1538+
bcast_mcast_mask, 0, NIX_INTF_RX);
1539+
1540+
req.intf = NIX_INTF_RX;
1541+
req.set_cntr = true;
1542+
req.cntr = cntr_rsp.cntr;
1543+
req.entry = mcam_idx;
1544+
1545+
err = rvu_mbox_handler_npc_mcam_write_entry(rvu, &req, &rsp);
1546+
if (err) {
1547+
dev_err(rvu->dev, "%s: Installation of single drop on non hit rule at %d failed\n",
1548+
__func__, mcam_idx);
1549+
return err;
1550+
}
1551+
1552+
dev_err(rvu->dev, "%s: Installed single drop on non hit rule at %d, cntr=%d\n",
1553+
__func__, mcam_idx, req.cntr);
1554+
1555+
/* disable entry at Bank 0, index 0 */
1556+
npc_enable_mcam_entry(rvu, mcam, blkaddr, mcam_idx, false);
1557+
1558+
return 0;
1559+
}

0 commit comments

Comments
 (0)