Skip to content

Commit 63be91c

Browse files
sgoutham-marvelldavem330
authored andcommitted
octeontx2-af: Alloc and config NPC MCAM entry at a time
A new mailbox message is added to support allocating a MCAM entry along with a counter and configuring it in one go. This reduces the amount of mailbox communication involved in installing a new MCAM rule. Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a958dd5 commit 63be91c

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ M(NPC_MCAM_CLEAR_COUNTER, 0x6009, npc_mcam_clear_counter, \
173173
M(NPC_MCAM_COUNTER_STATS, 0x600a, npc_mcam_counter_stats, \
174174
npc_mcam_oper_counter_req, \
175175
npc_mcam_oper_counter_rsp) \
176+
M(NPC_MCAM_ALLOC_AND_WRITE_ENTRY, 0x600b, npc_mcam_alloc_and_write_entry, \
177+
npc_mcam_alloc_and_write_entry_req, \
178+
npc_mcam_alloc_and_write_entry_rsp) \
176179
/* NIX mbox IDs (range 0x8000 - 0xFFFF) */ \
177180
M(NIX_LF_ALLOC, 0x8000, nix_lf_alloc, \
178181
nix_lf_alloc_req, nix_lf_alloc_rsp) \
@@ -680,4 +683,20 @@ struct npc_mcam_unmap_counter_req {
680683
u8 all; /* Unmap all entries using this counter ? */
681684
};
682685

686+
struct npc_mcam_alloc_and_write_entry_req {
687+
struct mbox_msghdr hdr;
688+
struct mcam_entry entry_data;
689+
u16 ref_entry;
690+
u8 priority; /* Lower or higher w.r.t ref_entry */
691+
u8 intf; /* Rx or Tx interface */
692+
u8 enable_entry;/* Enable this MCAM entry ? */
693+
u8 alloc_cntr; /* Allocate counter and map ? */
694+
};
695+
696+
struct npc_mcam_alloc_and_write_entry_rsp {
697+
struct mbox_msghdr hdr;
698+
u16 entry;
699+
u16 cntr;
700+
};
701+
683702
#endif /* MBOX_H */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,7 @@ int rvu_mbox_handler_npc_mcam_unmap_counter(struct rvu *rvu,
412412
int rvu_mbox_handler_npc_mcam_counter_stats(struct rvu *rvu,
413413
struct npc_mcam_oper_counter_req *req,
414414
struct npc_mcam_oper_counter_rsp *rsp);
415+
int rvu_mbox_handler_npc_mcam_alloc_and_write_entry(struct rvu *rvu,
416+
struct npc_mcam_alloc_and_write_entry_req *req,
417+
struct npc_mcam_alloc_and_write_entry_rsp *rsp);
415418
#endif /* RVU_H */

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,3 +1804,75 @@ int rvu_mbox_handler_npc_mcam_counter_stats(struct rvu *rvu,
18041804

18051805
return 0;
18061806
}
1807+
1808+
int rvu_mbox_handler_npc_mcam_alloc_and_write_entry(struct rvu *rvu,
1809+
struct npc_mcam_alloc_and_write_entry_req *req,
1810+
struct npc_mcam_alloc_and_write_entry_rsp *rsp)
1811+
{
1812+
struct npc_mcam_alloc_counter_req cntr_req;
1813+
struct npc_mcam_alloc_counter_rsp cntr_rsp;
1814+
struct npc_mcam_alloc_entry_req entry_req;
1815+
struct npc_mcam_alloc_entry_rsp entry_rsp;
1816+
struct npc_mcam *mcam = &rvu->hw->mcam;
1817+
u16 entry = NPC_MCAM_ENTRY_INVALID;
1818+
u16 cntr = NPC_MCAM_ENTRY_INVALID;
1819+
int blkaddr, rc;
1820+
1821+
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
1822+
if (blkaddr < 0)
1823+
return NPC_MCAM_INVALID_REQ;
1824+
1825+
if (req->intf != NIX_INTF_RX && req->intf != NIX_INTF_TX)
1826+
return NPC_MCAM_INVALID_REQ;
1827+
1828+
/* Try to allocate a MCAM entry */
1829+
entry_req.hdr.pcifunc = req->hdr.pcifunc;
1830+
entry_req.contig = true;
1831+
entry_req.priority = req->priority;
1832+
entry_req.ref_entry = req->ref_entry;
1833+
entry_req.count = 1;
1834+
1835+
rc = rvu_mbox_handler_npc_mcam_alloc_entry(rvu,
1836+
&entry_req, &entry_rsp);
1837+
if (rc)
1838+
return rc;
1839+
1840+
if (!entry_rsp.count)
1841+
return NPC_MCAM_ALLOC_FAILED;
1842+
1843+
entry = entry_rsp.entry;
1844+
1845+
if (!req->alloc_cntr)
1846+
goto write_entry;
1847+
1848+
/* Now allocate counter */
1849+
cntr_req.hdr.pcifunc = req->hdr.pcifunc;
1850+
cntr_req.contig = true;
1851+
cntr_req.count = 1;
1852+
1853+
rc = rvu_mbox_handler_npc_mcam_alloc_counter(rvu, &cntr_req, &cntr_rsp);
1854+
if (rc) {
1855+
/* Free allocated MCAM entry */
1856+
mutex_lock(&mcam->lock);
1857+
mcam->entry2pfvf_map[entry] = 0;
1858+
npc_mcam_clear_bit(mcam, entry);
1859+
mutex_unlock(&mcam->lock);
1860+
return rc;
1861+
}
1862+
1863+
cntr = cntr_rsp.cntr;
1864+
1865+
write_entry:
1866+
mutex_lock(&mcam->lock);
1867+
npc_config_mcam_entry(rvu, mcam, blkaddr, entry, req->intf,
1868+
&req->entry_data, req->enable_entry);
1869+
1870+
if (req->alloc_cntr)
1871+
npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr, entry, cntr);
1872+
mutex_unlock(&mcam->lock);
1873+
1874+
rsp->entry = entry;
1875+
rsp->cntr = cntr;
1876+
1877+
return 0;
1878+
}

0 commit comments

Comments
 (0)