* [dpdk-dev] [PATCH] common/cnxk: add ROC API to free MCAM entry
@ 2022-06-03 3:34 psatheesh
2022-06-03 11:10 ` Ray Kinsella
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: psatheesh @ 2022-06-03 3:34 UTC (permalink / raw)
To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
Ray Kinsella
Cc: dev, Satheesh Paul, Jerin Jacob Kollanukkaran
From: Satheesh Paul <psatheesh@marvell.com>
Add ROC API to free the given MCAM entry. If the MCAM
entry has flow counter associated, this API will clear
and free the flow counter.
Signed-off-by: Satheesh Paul <psatheesh@marvell.com>
Reviewed-by: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
---
drivers/common/cnxk/roc_npc.c | 63 +++++++++++++++++++++++------
drivers/common/cnxk/roc_npc.h | 7 ++++
drivers/common/cnxk/roc_npc_mcam.c | 39 ++++++++++++++----
drivers/common/cnxk/roc_npc_priv.h | 2 +
drivers/common/cnxk/roc_npc_utils.c | 15 +++----
drivers/common/cnxk/version.map | 3 ++
6 files changed, 100 insertions(+), 29 deletions(-)
diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
index da5b96242e..02624856e0 100644
--- a/drivers/common/cnxk/roc_npc.c
+++ b/drivers/common/cnxk/roc_npc.c
@@ -55,6 +55,53 @@ roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry)
return npc_mcam_free_entry(npc, entry);
}
+int
+roc_npc_mcam_free(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
+{
+ int rc = 0;
+
+ if (mcam->use_ctr) {
+ rc = roc_npc_mcam_clear_counter(roc_npc, mcam->ctr_id);
+ if (rc)
+ return rc;
+
+ rc = roc_npc_mcam_free_counter(roc_npc, mcam->ctr_id);
+ if (rc)
+ return rc;
+ }
+
+ return roc_npc_mcam_free_entry(roc_npc, mcam->mcam_id);
+}
+
+int
+roc_npc_mcam_init(struct roc_npc *roc_npc, struct roc_npc_flow *flow,
+ int mcam_id)
+{
+ struct npc *npc = roc_npc_to_npc_priv(roc_npc);
+ int rc = 0;
+
+ rc = npc_mcam_init(npc, flow, mcam_id);
+ if (rc != 0) {
+ plt_err("npc: mcam initialisation write failed");
+ return rc;
+ }
+ return 0;
+}
+
+int
+roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent, uint16_t new_ent)
+{
+ struct npc *npc = roc_npc_to_npc_priv(roc_npc);
+ struct mbox *mbox = npc->mbox;
+ int rc = -ENOSPC;
+
+ rc = npc_mcam_move(mbox, old_ent, new_ent);
+ if (rc)
+ return rc;
+
+ return 0;
+}
+
int
roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
{
@@ -383,7 +430,7 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
case ROC_NPC_ACTION_TYPE_COUNT:
/* Indicates, need a counter */
- flow->ctr_id = 1;
+ flow->use_ctr = 1;
req_act |= ROC_NPC_ACTION_TYPE_COUNT;
break;
@@ -1268,7 +1315,7 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
return flow;
set_rss_failed:
- rc = npc_mcam_free_entry(npc, flow->mcam_id);
+ rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
if (rc != 0) {
*errcode = rc;
plt_free(flow);
@@ -1314,17 +1361,7 @@ roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
return rc;
}
- if (flow->ctr_id != NPC_COUNTER_NONE) {
- rc = roc_npc_mcam_clear_counter(roc_npc, flow->ctr_id);
- if (rc != 0)
- return rc;
-
- rc = npc_mcam_free_counter(npc, flow->ctr_id);
- if (rc != 0)
- return rc;
- }
-
- rc = npc_mcam_free_entry(npc, flow->mcam_id);
+ rc = roc_npc_mcam_free(roc_npc, flow);
if (rc != 0)
return rc;
diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
index f92c2a633c..1b4e5521cb 100644
--- a/drivers/common/cnxk/roc_npc.h
+++ b/drivers/common/cnxk/roc_npc.h
@@ -246,6 +246,7 @@ struct roc_npc_flow {
uint8_t nix_intf;
uint8_t enable;
uint32_t mcam_id;
+ uint8_t use_ctr;
int32_t ctr_id;
uint32_t priority;
uint32_t mtr_id;
@@ -329,6 +330,8 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
const struct roc_npc_action actions[], int *errcode);
int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
struct roc_npc_flow *flow);
+int __roc_api roc_npc_mcam_free(struct roc_npc *roc_npc,
+ struct roc_npc_flow *mcam);
int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
int __roc_api roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc,
bool enable);
@@ -367,4 +370,8 @@ int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
struct roc_npc_flow *flow);
int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
struct roc_npc *roc_npc_dst);
+int __roc_api roc_npc_mcam_init(struct roc_npc *roc_npc,
+ struct roc_npc_flow *flow, int mcam_id);
+int __roc_api roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent,
+ uint16_t new_ent);
#endif /* _ROC_NPC_H_ */
diff --git a/drivers/common/cnxk/roc_npc_mcam.c b/drivers/common/cnxk/roc_npc_mcam.c
index bccbaaa51f..c5db25322a 100644
--- a/drivers/common/cnxk/roc_npc_mcam.c
+++ b/drivers/common/cnxk/roc_npc_mcam.c
@@ -401,16 +401,37 @@ npc_mcam_write_entry(struct npc *npc, struct roc_npc_flow *mcam)
struct mbox *mbox = npc->mbox;
struct mbox_msghdr *rsp;
int rc = -ENOSPC;
+ uint16_t ctr = 0;
int i;
+ if (mcam->use_ctr && mcam->ctr_id == NPC_COUNTER_NONE) {
+ rc = npc_mcam_alloc_counter(npc, &ctr);
+ if (rc)
+ return rc;
+ mcam->ctr_id = ctr;
+
+ rc = npc_mcam_clear_counter(npc, mcam->ctr_id);
+ if (rc)
+ return rc;
+ }
+
req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
- if (req == NULL)
+ if (req == NULL) {
+ if (mcam->use_ctr)
+ npc_mcam_free_counter(npc, ctr);
+
return rc;
+ }
req->entry = mcam->mcam_id;
req->intf = mcam->nix_intf;
req->enable_entry = mcam->enable;
req->entry_data.action = mcam->npc_action;
req->entry_data.vtag_action = mcam->vtag_action;
+ if (mcam->use_ctr) {
+ req->set_cntr = 1;
+ req->cntr = mcam->ctr_id;
+ }
+
for (i = 0; i < NPC_MCAM_KEY_X4_WORDS; i++) {
req->entry_data.kw[i] = mcam->mcam_data[i];
req->entry_data.kw_mask[i] = mcam->mcam_mask[i];
@@ -533,7 +554,6 @@ int
npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
struct npc_parse_state *pst)
{
- int use_ctr = (flow->ctr_id == NPC_COUNTER_NONE ? 0 : 1);
struct npc_mcam_write_entry_req *req;
struct nix_inl_dev *inl_dev = NULL;
struct mbox *mbox = npc->mbox;
@@ -546,15 +566,20 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
PLT_SET_USED(pst);
- if (use_ctr) {
+ if (flow->use_ctr) {
rc = npc_mcam_alloc_counter(npc, &ctr);
if (rc)
return rc;
+
+ flow->ctr_id = ctr;
+ rc = npc_mcam_clear_counter(npc, flow->ctr_id);
+ if (rc)
+ return rc;
}
entry = npc_get_free_mcam_entry(mbox, flow, npc);
if (entry < 0) {
- if (use_ctr)
+ if (flow->use_ctr)
npc_mcam_free_counter(npc, ctr);
return NPC_ERR_MCAM_ALLOC;
}
@@ -562,8 +587,8 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
if (req == NULL)
return -ENOSPC;
- req->set_cntr = use_ctr;
- req->cntr = ctr;
+ req->set_cntr = flow->use_ctr;
+ req->cntr = flow->ctr_id;
req->entry = entry;
req->intf = (flow->nix_intf == NIX_INTF_RX) ? NPC_MCAM_RX : NPC_MCAM_TX;
@@ -630,7 +655,7 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
flow->mcam_id = entry;
- if (use_ctr)
+ if (flow->use_ctr)
flow->ctr_id = ctr;
return 0;
}
diff --git a/drivers/common/cnxk/roc_npc_priv.h b/drivers/common/cnxk/roc_npc_priv.h
index 78d6ee844d..b08539d8f8 100644
--- a/drivers/common/cnxk/roc_npc_priv.h
+++ b/drivers/common/cnxk/roc_npc_priv.h
@@ -453,4 +453,6 @@ int npc_rss_action_program(struct roc_npc *roc_npc,
const struct roc_npc_action actions[],
struct roc_npc_flow *flow);
int npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow);
+int npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id);
+int npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent);
#endif /* _ROC_NPC_PRIV_H_ */
diff --git a/drivers/common/cnxk/roc_npc_utils.c b/drivers/common/cnxk/roc_npc_utils.c
index e36a312576..cbc6200fec 100644
--- a/drivers/common/cnxk/roc_npc_utils.c
+++ b/drivers/common/cnxk/roc_npc_utils.c
@@ -264,9 +264,8 @@ npc_update_parse_state(struct npc_parse_state *pst,
return 0;
}
-static int
-npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
- int mcam_id)
+int
+npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id)
{
struct npc_mcam_write_entry_req *req;
struct npc_mcam_write_entry_rsq *rsp;
@@ -308,8 +307,8 @@ npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
return 0;
}
-static int
-npc_shift_mcam_entry(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
+int
+npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
{
struct npc_mcam_shift_entry_req *req;
struct npc_mcam_shift_entry_rsp *rsp;
@@ -365,12 +364,10 @@ npc_slide_mcam_entries(struct mbox *mbox, struct npc *npc, int prio,
* Initialise and enable before moving an entry into
* this mcam.
*/
- rc = npc_initialise_mcam_entry(npc, curr->flow,
- to_mcam_id);
+ rc = npc_mcam_init(npc, curr->flow, to_mcam_id);
if (rc)
return rc;
- rc = npc_shift_mcam_entry(mbox, from_mcam_id,
- to_mcam_id);
+ rc = npc_mcam_move(mbox, from_mcam_id, to_mcam_id);
if (rc)
return rc;
curr->flow->mcam_id = to_mcam_id;
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index a77f3f6e3c..bbde990440 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -325,7 +325,10 @@ INTERNAL {
roc_npc_mcam_ena_dis_entry;
roc_npc_mcam_free_all_resources;
roc_npc_mcam_free_counter;
+ roc_npc_mcam_free;
roc_npc_mcam_free_entry;
+ roc_npc_mcam_init;
+ roc_npc_mcam_move;
roc_npc_mcam_merge_base_steering_rule;
roc_npc_mcam_write_entry;
roc_npc_mcam_read_counter;
--
2.35.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH] common/cnxk: add ROC API to free MCAM entry
2022-06-03 3:34 [dpdk-dev] [PATCH] common/cnxk: add ROC API to free MCAM entry psatheesh
@ 2022-06-03 11:10 ` Ray Kinsella
2022-06-15 13:00 ` Jerin Jacob
2022-06-15 13:57 ` [dpdk-dev] [PATCH v2] " psatheesh
2 siblings, 0 replies; 5+ messages in thread
From: Ray Kinsella @ 2022-06-03 11:10 UTC (permalink / raw)
To: psatheesh
Cc: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
dev, Jerin Jacob Kollanukkaran
<psatheesh@marvell.com> writes:
> From: Satheesh Paul <psatheesh@marvell.com>
>
> Add ROC API to free the given MCAM entry. If the MCAM
> entry has flow counter associated, this API will clear
> and free the flow counter.
>
> Signed-off-by: Satheesh Paul <psatheesh@marvell.com>
> Reviewed-by: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
> ---
> drivers/common/cnxk/roc_npc.c | 63 +++++++++++++++++++++++------
> drivers/common/cnxk/roc_npc.h | 7 ++++
> drivers/common/cnxk/roc_npc_mcam.c | 39 ++++++++++++++----
> drivers/common/cnxk/roc_npc_priv.h | 2 +
> drivers/common/cnxk/roc_npc_utils.c | 15 +++----
> drivers/common/cnxk/version.map | 3 ++
> 6 files changed, 100 insertions(+), 29 deletions(-)
>
Acked-by: Ray Kinsella <mdr@ashroe.eu>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH] common/cnxk: add ROC API to free MCAM entry
2022-06-03 3:34 [dpdk-dev] [PATCH] common/cnxk: add ROC API to free MCAM entry psatheesh
2022-06-03 11:10 ` Ray Kinsella
@ 2022-06-15 13:00 ` Jerin Jacob
2022-06-15 13:57 ` [dpdk-dev] [PATCH v2] " psatheesh
2 siblings, 0 replies; 5+ messages in thread
From: Jerin Jacob @ 2022-06-15 13:00 UTC (permalink / raw)
To: Satheesh Paul
Cc: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
Ray Kinsella, dpdk-dev, Jerin Jacob Kollanukkaran
On Fri, Jun 3, 2022 at 9:06 AM <psatheesh@marvell.com> wrote:
>
> From: Satheesh Paul <psatheesh@marvell.com>
>
> Add ROC API to free the given MCAM entry. If the MCAM
> entry has flow counter associated, this API will clear
> and free the flow counter.
>
> Signed-off-by: Satheesh Paul <psatheesh@marvell.com>
> Reviewed-by: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
> ---
> drivers/common/cnxk/roc_npc.c | 63 +++++++++++++++++++++++------
> drivers/common/cnxk/roc_npc.h | 7 ++++
> drivers/common/cnxk/roc_npc_mcam.c | 39 ++++++++++++++----
> drivers/common/cnxk/roc_npc_priv.h | 2 +
> drivers/common/cnxk/roc_npc_utils.c | 15 +++----
> drivers/common/cnxk/version.map | 3 ++
> 6 files changed, 100 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
> index da5b96242e..02624856e0 100644
> --- a/drivers/common/cnxk/roc_npc.c
> +++ b/drivers/common/cnxk/roc_npc.c
> @@ -55,6 +55,53 @@ roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry)
> return npc_mcam_free_entry(npc, entry);
> }
>
> +int
> +roc_npc_mcam_free(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
> +{
> + int rc = 0;
> +
> + if (mcam->use_ctr) {
> + rc = roc_npc_mcam_clear_counter(roc_npc, mcam->ctr_id);
> + if (rc)
> + return rc;
> +
> + rc = roc_npc_mcam_free_counter(roc_npc, mcam->ctr_id);
> + if (rc)
> + return rc;
> + }
> +
> + return roc_npc_mcam_free_entry(roc_npc, mcam->mcam_id);
> +}
> +
> +int
> +roc_npc_mcam_init(struct roc_npc *roc_npc, struct roc_npc_flow *flow,
> + int mcam_id)
> +{
> + struct npc *npc = roc_npc_to_npc_priv(roc_npc);
> + int rc = 0;
No need to assign to zero as the next line is overwriting it.
> +
> + rc = npc_mcam_init(npc, flow, mcam_id);
> + if (rc != 0) {
> + plt_err("npc: mcam initialisation write failed");
> + return rc;
> + }
> + return 0;
> +}
> +
> +int
> +roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent, uint16_t new_ent)
> +{
> + struct npc *npc = roc_npc_to_npc_priv(roc_npc);
> + struct mbox *mbox = npc->mbox;
> + int rc = -ENOSPC;
No need to assign to value as the next line is overwriting it.
> +
> + rc = npc_mcam_move(mbox, old_ent, new_ent);
> + if (rc)
> + return rc;
> +
> + return 0;
> +}
> +
> int
> roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
> {
> @@ -383,7 +430,7 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
>
> case ROC_NPC_ACTION_TYPE_COUNT:
> /* Indicates, need a counter */
> - flow->ctr_id = 1;
> + flow->use_ctr = 1;
> req_act |= ROC_NPC_ACTION_TYPE_COUNT;
> break;
>
> @@ -1268,7 +1315,7 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
> return flow;
>
> set_rss_failed:
> - rc = npc_mcam_free_entry(npc, flow->mcam_id);
> + rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
> if (rc != 0) {
> *errcode = rc;
> plt_free(flow);
> @@ -1314,17 +1361,7 @@ roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
> return rc;
> }
>
> - if (flow->ctr_id != NPC_COUNTER_NONE) {
> - rc = roc_npc_mcam_clear_counter(roc_npc, flow->ctr_id);
> - if (rc != 0)
> - return rc;
> -
> - rc = npc_mcam_free_counter(npc, flow->ctr_id);
> - if (rc != 0)
> - return rc;
> - }
> -
> - rc = npc_mcam_free_entry(npc, flow->mcam_id);
> + rc = roc_npc_mcam_free(roc_npc, flow);
> if (rc != 0)
> return rc;
>
> diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
> index f92c2a633c..1b4e5521cb 100644
> --- a/drivers/common/cnxk/roc_npc.h
> +++ b/drivers/common/cnxk/roc_npc.h
> @@ -246,6 +246,7 @@ struct roc_npc_flow {
> uint8_t nix_intf;
> uint8_t enable;
> uint32_t mcam_id;
> + uint8_t use_ctr;
> int32_t ctr_id;
> uint32_t priority;
> uint32_t mtr_id;
> @@ -329,6 +330,8 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
> const struct roc_npc_action actions[], int *errcode);
> int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
> struct roc_npc_flow *flow);
> +int __roc_api roc_npc_mcam_free(struct roc_npc *roc_npc,
> + struct roc_npc_flow *mcam);
> int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
> int __roc_api roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc,
> bool enable);
> @@ -367,4 +370,8 @@ int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
> struct roc_npc_flow *flow);
> int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
> struct roc_npc *roc_npc_dst);
> +int __roc_api roc_npc_mcam_init(struct roc_npc *roc_npc,
> + struct roc_npc_flow *flow, int mcam_id);
> +int __roc_api roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent,
> + uint16_t new_ent);
> #endif /* _ROC_NPC_H_ */
> diff --git a/drivers/common/cnxk/roc_npc_mcam.c b/drivers/common/cnxk/roc_npc_mcam.c
> index bccbaaa51f..c5db25322a 100644
> --- a/drivers/common/cnxk/roc_npc_mcam.c
> +++ b/drivers/common/cnxk/roc_npc_mcam.c
> @@ -401,16 +401,37 @@ npc_mcam_write_entry(struct npc *npc, struct roc_npc_flow *mcam)
> struct mbox *mbox = npc->mbox;
> struct mbox_msghdr *rsp;
> int rc = -ENOSPC;
> + uint16_t ctr = 0;
> int i;
>
> + if (mcam->use_ctr && mcam->ctr_id == NPC_COUNTER_NONE) {
> + rc = npc_mcam_alloc_counter(npc, &ctr);
> + if (rc)
> + return rc;
> + mcam->ctr_id = ctr;
> +
> + rc = npc_mcam_clear_counter(npc, mcam->ctr_id);
> + if (rc)
> + return rc;
> + }
> +
> req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
> - if (req == NULL)
> + if (req == NULL) {
> + if (mcam->use_ctr)
> + npc_mcam_free_counter(npc, ctr);
> +
> return rc;
> + }
> req->entry = mcam->mcam_id;
> req->intf = mcam->nix_intf;
> req->enable_entry = mcam->enable;
> req->entry_data.action = mcam->npc_action;
> req->entry_data.vtag_action = mcam->vtag_action;
> + if (mcam->use_ctr) {
> + req->set_cntr = 1;
> + req->cntr = mcam->ctr_id;
> + }
> +
> for (i = 0; i < NPC_MCAM_KEY_X4_WORDS; i++) {
> req->entry_data.kw[i] = mcam->mcam_data[i];
> req->entry_data.kw_mask[i] = mcam->mcam_mask[i];
> @@ -533,7 +554,6 @@ int
> npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
> struct npc_parse_state *pst)
> {
> - int use_ctr = (flow->ctr_id == NPC_COUNTER_NONE ? 0 : 1);
> struct npc_mcam_write_entry_req *req;
> struct nix_inl_dev *inl_dev = NULL;
> struct mbox *mbox = npc->mbox;
> @@ -546,15 +566,20 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
>
> PLT_SET_USED(pst);
>
> - if (use_ctr) {
> + if (flow->use_ctr) {
> rc = npc_mcam_alloc_counter(npc, &ctr);
> if (rc)
> return rc;
> +
> + flow->ctr_id = ctr;
> + rc = npc_mcam_clear_counter(npc, flow->ctr_id);
> + if (rc)
> + return rc;
> }
>
> entry = npc_get_free_mcam_entry(mbox, flow, npc);
> if (entry < 0) {
> - if (use_ctr)
> + if (flow->use_ctr)
> npc_mcam_free_counter(npc, ctr);
> return NPC_ERR_MCAM_ALLOC;
> }
> @@ -562,8 +587,8 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
> req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
> if (req == NULL)
> return -ENOSPC;
> - req->set_cntr = use_ctr;
> - req->cntr = ctr;
> + req->set_cntr = flow->use_ctr;
> + req->cntr = flow->ctr_id;
> req->entry = entry;
>
> req->intf = (flow->nix_intf == NIX_INTF_RX) ? NPC_MCAM_RX : NPC_MCAM_TX;
> @@ -630,7 +655,7 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
>
> flow->mcam_id = entry;
>
> - if (use_ctr)
> + if (flow->use_ctr)
> flow->ctr_id = ctr;
> return 0;
> }
> diff --git a/drivers/common/cnxk/roc_npc_priv.h b/drivers/common/cnxk/roc_npc_priv.h
> index 78d6ee844d..b08539d8f8 100644
> --- a/drivers/common/cnxk/roc_npc_priv.h
> +++ b/drivers/common/cnxk/roc_npc_priv.h
> @@ -453,4 +453,6 @@ int npc_rss_action_program(struct roc_npc *roc_npc,
> const struct roc_npc_action actions[],
> struct roc_npc_flow *flow);
> int npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow);
> +int npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id);
> +int npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent);
> #endif /* _ROC_NPC_PRIV_H_ */
> diff --git a/drivers/common/cnxk/roc_npc_utils.c b/drivers/common/cnxk/roc_npc_utils.c
> index e36a312576..cbc6200fec 100644
> --- a/drivers/common/cnxk/roc_npc_utils.c
> +++ b/drivers/common/cnxk/roc_npc_utils.c
> @@ -264,9 +264,8 @@ npc_update_parse_state(struct npc_parse_state *pst,
> return 0;
> }
>
> -static int
> -npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
> - int mcam_id)
> +int
> +npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id)
> {
> struct npc_mcam_write_entry_req *req;
> struct npc_mcam_write_entry_rsq *rsp;
> @@ -308,8 +307,8 @@ npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
> return 0;
> }
>
> -static int
> -npc_shift_mcam_entry(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
> +int
> +npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
> {
> struct npc_mcam_shift_entry_req *req;
> struct npc_mcam_shift_entry_rsp *rsp;
> @@ -365,12 +364,10 @@ npc_slide_mcam_entries(struct mbox *mbox, struct npc *npc, int prio,
> * Initialise and enable before moving an entry into
> * this mcam.
> */
> - rc = npc_initialise_mcam_entry(npc, curr->flow,
> - to_mcam_id);
> + rc = npc_mcam_init(npc, curr->flow, to_mcam_id);
> if (rc)
> return rc;
> - rc = npc_shift_mcam_entry(mbox, from_mcam_id,
> - to_mcam_id);
> + rc = npc_mcam_move(mbox, from_mcam_id, to_mcam_id);
> if (rc)
> return rc;
> curr->flow->mcam_id = to_mcam_id;
> diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
> index a77f3f6e3c..bbde990440 100644
> --- a/drivers/common/cnxk/version.map
> +++ b/drivers/common/cnxk/version.map
> @@ -325,7 +325,10 @@ INTERNAL {
> roc_npc_mcam_ena_dis_entry;
> roc_npc_mcam_free_all_resources;
> roc_npc_mcam_free_counter;
> + roc_npc_mcam_free;
> roc_npc_mcam_free_entry;
> + roc_npc_mcam_init;
> + roc_npc_mcam_move;
> roc_npc_mcam_merge_base_steering_rule;
> roc_npc_mcam_write_entry;
> roc_npc_mcam_read_counter;
> --
> 2.35.3
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [PATCH v2] common/cnxk: add ROC API to free MCAM entry
2022-06-03 3:34 [dpdk-dev] [PATCH] common/cnxk: add ROC API to free MCAM entry psatheesh
2022-06-03 11:10 ` Ray Kinsella
2022-06-15 13:00 ` Jerin Jacob
@ 2022-06-15 13:57 ` psatheesh
2022-06-17 12:54 ` Jerin Jacob
2 siblings, 1 reply; 5+ messages in thread
From: psatheesh @ 2022-06-15 13:57 UTC (permalink / raw)
To: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
Ray Kinsella
Cc: dev, Satheesh Paul, Jerin Jacob
From: Satheesh Paul <psatheesh@marvell.com>
Add ROC API to free the given MCAM entry. If the MCAM
entry has flow counter associated, this API will clear
and free the flow counter.
Signed-off-by: Satheesh Paul <psatheesh@marvell.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
---
v2:
* Removed unnecessary variable initialization
drivers/common/cnxk/roc_npc.c | 63 +++++++++++++++++++++++------
drivers/common/cnxk/roc_npc.h | 7 ++++
drivers/common/cnxk/roc_npc_mcam.c | 39 ++++++++++++++----
drivers/common/cnxk/roc_npc_priv.h | 2 +
drivers/common/cnxk/roc_npc_utils.c | 15 +++----
drivers/common/cnxk/version.map | 3 ++
6 files changed, 100 insertions(+), 29 deletions(-)
diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
index da5b96242e..b38389b18a 100644
--- a/drivers/common/cnxk/roc_npc.c
+++ b/drivers/common/cnxk/roc_npc.c
@@ -55,6 +55,53 @@ roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry)
return npc_mcam_free_entry(npc, entry);
}
+int
+roc_npc_mcam_free(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
+{
+ int rc = 0;
+
+ if (mcam->use_ctr) {
+ rc = roc_npc_mcam_clear_counter(roc_npc, mcam->ctr_id);
+ if (rc)
+ return rc;
+
+ rc = roc_npc_mcam_free_counter(roc_npc, mcam->ctr_id);
+ if (rc)
+ return rc;
+ }
+
+ return roc_npc_mcam_free_entry(roc_npc, mcam->mcam_id);
+}
+
+int
+roc_npc_mcam_init(struct roc_npc *roc_npc, struct roc_npc_flow *flow,
+ int mcam_id)
+{
+ struct npc *npc = roc_npc_to_npc_priv(roc_npc);
+ int rc;
+
+ rc = npc_mcam_init(npc, flow, mcam_id);
+ if (rc != 0) {
+ plt_err("npc: mcam initialisation write failed");
+ return rc;
+ }
+ return 0;
+}
+
+int
+roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent, uint16_t new_ent)
+{
+ struct npc *npc = roc_npc_to_npc_priv(roc_npc);
+ struct mbox *mbox = npc->mbox;
+ int rc;
+
+ rc = npc_mcam_move(mbox, old_ent, new_ent);
+ if (rc)
+ return rc;
+
+ return 0;
+}
+
int
roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
{
@@ -383,7 +430,7 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
case ROC_NPC_ACTION_TYPE_COUNT:
/* Indicates, need a counter */
- flow->ctr_id = 1;
+ flow->use_ctr = 1;
req_act |= ROC_NPC_ACTION_TYPE_COUNT;
break;
@@ -1268,7 +1315,7 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
return flow;
set_rss_failed:
- rc = npc_mcam_free_entry(npc, flow->mcam_id);
+ rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
if (rc != 0) {
*errcode = rc;
plt_free(flow);
@@ -1314,17 +1361,7 @@ roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
return rc;
}
- if (flow->ctr_id != NPC_COUNTER_NONE) {
- rc = roc_npc_mcam_clear_counter(roc_npc, flow->ctr_id);
- if (rc != 0)
- return rc;
-
- rc = npc_mcam_free_counter(npc, flow->ctr_id);
- if (rc != 0)
- return rc;
- }
-
- rc = npc_mcam_free_entry(npc, flow->mcam_id);
+ rc = roc_npc_mcam_free(roc_npc, flow);
if (rc != 0)
return rc;
diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
index f92c2a633c..1b4e5521cb 100644
--- a/drivers/common/cnxk/roc_npc.h
+++ b/drivers/common/cnxk/roc_npc.h
@@ -246,6 +246,7 @@ struct roc_npc_flow {
uint8_t nix_intf;
uint8_t enable;
uint32_t mcam_id;
+ uint8_t use_ctr;
int32_t ctr_id;
uint32_t priority;
uint32_t mtr_id;
@@ -329,6 +330,8 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
const struct roc_npc_action actions[], int *errcode);
int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
struct roc_npc_flow *flow);
+int __roc_api roc_npc_mcam_free(struct roc_npc *roc_npc,
+ struct roc_npc_flow *mcam);
int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
int __roc_api roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc,
bool enable);
@@ -367,4 +370,8 @@ int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
struct roc_npc_flow *flow);
int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
struct roc_npc *roc_npc_dst);
+int __roc_api roc_npc_mcam_init(struct roc_npc *roc_npc,
+ struct roc_npc_flow *flow, int mcam_id);
+int __roc_api roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent,
+ uint16_t new_ent);
#endif /* _ROC_NPC_H_ */
diff --git a/drivers/common/cnxk/roc_npc_mcam.c b/drivers/common/cnxk/roc_npc_mcam.c
index 0ae58da0ba..245eeb0107 100644
--- a/drivers/common/cnxk/roc_npc_mcam.c
+++ b/drivers/common/cnxk/roc_npc_mcam.c
@@ -401,16 +401,37 @@ npc_mcam_write_entry(struct npc *npc, struct roc_npc_flow *mcam)
struct mbox *mbox = npc->mbox;
struct mbox_msghdr *rsp;
int rc = -ENOSPC;
+ uint16_t ctr = 0;
int i;
+ if (mcam->use_ctr && mcam->ctr_id == NPC_COUNTER_NONE) {
+ rc = npc_mcam_alloc_counter(npc, &ctr);
+ if (rc)
+ return rc;
+ mcam->ctr_id = ctr;
+
+ rc = npc_mcam_clear_counter(npc, mcam->ctr_id);
+ if (rc)
+ return rc;
+ }
+
req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
- if (req == NULL)
+ if (req == NULL) {
+ if (mcam->use_ctr)
+ npc_mcam_free_counter(npc, ctr);
+
return rc;
+ }
req->entry = mcam->mcam_id;
req->intf = mcam->nix_intf;
req->enable_entry = mcam->enable;
req->entry_data.action = mcam->npc_action;
req->entry_data.vtag_action = mcam->vtag_action;
+ if (mcam->use_ctr) {
+ req->set_cntr = 1;
+ req->cntr = mcam->ctr_id;
+ }
+
for (i = 0; i < NPC_MCAM_KEY_X4_WORDS; i++) {
req->entry_data.kw[i] = mcam->mcam_data[i];
req->entry_data.kw_mask[i] = mcam->mcam_mask[i];
@@ -539,7 +560,6 @@ int
npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
struct npc_parse_state *pst)
{
- int use_ctr = (flow->ctr_id == NPC_COUNTER_NONE ? 0 : 1);
struct npc_mcam_write_entry_req *req;
struct nix_inl_dev *inl_dev = NULL;
struct mbox *mbox = npc->mbox;
@@ -552,15 +572,20 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
PLT_SET_USED(pst);
- if (use_ctr) {
+ if (flow->use_ctr) {
rc = npc_mcam_alloc_counter(npc, &ctr);
if (rc)
return rc;
+
+ flow->ctr_id = ctr;
+ rc = npc_mcam_clear_counter(npc, flow->ctr_id);
+ if (rc)
+ return rc;
}
entry = npc_get_free_mcam_entry(mbox, flow, npc);
if (entry < 0) {
- if (use_ctr)
+ if (flow->use_ctr)
npc_mcam_free_counter(npc, ctr);
return NPC_ERR_MCAM_ALLOC;
}
@@ -568,8 +593,8 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
if (req == NULL)
return -ENOSPC;
- req->set_cntr = use_ctr;
- req->cntr = ctr;
+ req->set_cntr = flow->use_ctr;
+ req->cntr = flow->ctr_id;
req->entry = entry;
req->intf = (flow->nix_intf == NIX_INTF_RX) ? NPC_MCAM_RX : NPC_MCAM_TX;
@@ -636,7 +661,7 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
flow->mcam_id = entry;
- if (use_ctr)
+ if (flow->use_ctr)
flow->ctr_id = ctr;
return 0;
}
diff --git a/drivers/common/cnxk/roc_npc_priv.h b/drivers/common/cnxk/roc_npc_priv.h
index 78d6ee844d..b08539d8f8 100644
--- a/drivers/common/cnxk/roc_npc_priv.h
+++ b/drivers/common/cnxk/roc_npc_priv.h
@@ -453,4 +453,6 @@ int npc_rss_action_program(struct roc_npc *roc_npc,
const struct roc_npc_action actions[],
struct roc_npc_flow *flow);
int npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow);
+int npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id);
+int npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent);
#endif /* _ROC_NPC_PRIV_H_ */
diff --git a/drivers/common/cnxk/roc_npc_utils.c b/drivers/common/cnxk/roc_npc_utils.c
index e36a312576..cbc6200fec 100644
--- a/drivers/common/cnxk/roc_npc_utils.c
+++ b/drivers/common/cnxk/roc_npc_utils.c
@@ -264,9 +264,8 @@ npc_update_parse_state(struct npc_parse_state *pst,
return 0;
}
-static int
-npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
- int mcam_id)
+int
+npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id)
{
struct npc_mcam_write_entry_req *req;
struct npc_mcam_write_entry_rsq *rsp;
@@ -308,8 +307,8 @@ npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
return 0;
}
-static int
-npc_shift_mcam_entry(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
+int
+npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
{
struct npc_mcam_shift_entry_req *req;
struct npc_mcam_shift_entry_rsp *rsp;
@@ -365,12 +364,10 @@ npc_slide_mcam_entries(struct mbox *mbox, struct npc *npc, int prio,
* Initialise and enable before moving an entry into
* this mcam.
*/
- rc = npc_initialise_mcam_entry(npc, curr->flow,
- to_mcam_id);
+ rc = npc_mcam_init(npc, curr->flow, to_mcam_id);
if (rc)
return rc;
- rc = npc_shift_mcam_entry(mbox, from_mcam_id,
- to_mcam_id);
+ rc = npc_mcam_move(mbox, from_mcam_id, to_mcam_id);
if (rc)
return rc;
curr->flow->mcam_id = to_mcam_id;
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index a77f3f6e3c..bbde990440 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -325,7 +325,10 @@ INTERNAL {
roc_npc_mcam_ena_dis_entry;
roc_npc_mcam_free_all_resources;
roc_npc_mcam_free_counter;
+ roc_npc_mcam_free;
roc_npc_mcam_free_entry;
+ roc_npc_mcam_init;
+ roc_npc_mcam_move;
roc_npc_mcam_merge_base_steering_rule;
roc_npc_mcam_write_entry;
roc_npc_mcam_read_counter;
--
2.35.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH v2] common/cnxk: add ROC API to free MCAM entry
2022-06-15 13:57 ` [dpdk-dev] [PATCH v2] " psatheesh
@ 2022-06-17 12:54 ` Jerin Jacob
0 siblings, 0 replies; 5+ messages in thread
From: Jerin Jacob @ 2022-06-17 12:54 UTC (permalink / raw)
To: Satheesh Paul
Cc: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
Ray Kinsella, dpdk-dev, Jerin Jacob
On Wed, Jun 15, 2022 at 7:29 PM <psatheesh@marvell.com> wrote:
>
> From: Satheesh Paul <psatheesh@marvell.com>
>
> Add ROC API to free the given MCAM entry. If the MCAM
> entry has flow counter associated, this API will clear
> and free the flow counter.
>
> Signed-off-by: Satheesh Paul <psatheesh@marvell.com>
> Reviewed-by: Jerin Jacob <jerinj@marvell.com>
Applied to dpdk-next-net-mrvl/for-next-net. Thanks
> ---
> v2:
> * Removed unnecessary variable initialization
>
> drivers/common/cnxk/roc_npc.c | 63 +++++++++++++++++++++++------
> drivers/common/cnxk/roc_npc.h | 7 ++++
> drivers/common/cnxk/roc_npc_mcam.c | 39 ++++++++++++++----
> drivers/common/cnxk/roc_npc_priv.h | 2 +
> drivers/common/cnxk/roc_npc_utils.c | 15 +++----
> drivers/common/cnxk/version.map | 3 ++
> 6 files changed, 100 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
> index da5b96242e..b38389b18a 100644
> --- a/drivers/common/cnxk/roc_npc.c
> +++ b/drivers/common/cnxk/roc_npc.c
> @@ -55,6 +55,53 @@ roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry)
> return npc_mcam_free_entry(npc, entry);
> }
>
> +int
> +roc_npc_mcam_free(struct roc_npc *roc_npc, struct roc_npc_flow *mcam)
> +{
> + int rc = 0;
> +
> + if (mcam->use_ctr) {
> + rc = roc_npc_mcam_clear_counter(roc_npc, mcam->ctr_id);
> + if (rc)
> + return rc;
> +
> + rc = roc_npc_mcam_free_counter(roc_npc, mcam->ctr_id);
> + if (rc)
> + return rc;
> + }
> +
> + return roc_npc_mcam_free_entry(roc_npc, mcam->mcam_id);
> +}
> +
> +int
> +roc_npc_mcam_init(struct roc_npc *roc_npc, struct roc_npc_flow *flow,
> + int mcam_id)
> +{
> + struct npc *npc = roc_npc_to_npc_priv(roc_npc);
> + int rc;
> +
> + rc = npc_mcam_init(npc, flow, mcam_id);
> + if (rc != 0) {
> + plt_err("npc: mcam initialisation write failed");
> + return rc;
> + }
> + return 0;
> +}
> +
> +int
> +roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent, uint16_t new_ent)
> +{
> + struct npc *npc = roc_npc_to_npc_priv(roc_npc);
> + struct mbox *mbox = npc->mbox;
> + int rc;
> +
> + rc = npc_mcam_move(mbox, old_ent, new_ent);
> + if (rc)
> + return rc;
> +
> + return 0;
> +}
> +
> int
> roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc)
> {
> @@ -383,7 +430,7 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
>
> case ROC_NPC_ACTION_TYPE_COUNT:
> /* Indicates, need a counter */
> - flow->ctr_id = 1;
> + flow->use_ctr = 1;
> req_act |= ROC_NPC_ACTION_TYPE_COUNT;
> break;
>
> @@ -1268,7 +1315,7 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
> return flow;
>
> set_rss_failed:
> - rc = npc_mcam_free_entry(npc, flow->mcam_id);
> + rc = roc_npc_mcam_free_entry(roc_npc, flow->mcam_id);
> if (rc != 0) {
> *errcode = rc;
> plt_free(flow);
> @@ -1314,17 +1361,7 @@ roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
> return rc;
> }
>
> - if (flow->ctr_id != NPC_COUNTER_NONE) {
> - rc = roc_npc_mcam_clear_counter(roc_npc, flow->ctr_id);
> - if (rc != 0)
> - return rc;
> -
> - rc = npc_mcam_free_counter(npc, flow->ctr_id);
> - if (rc != 0)
> - return rc;
> - }
> -
> - rc = npc_mcam_free_entry(npc, flow->mcam_id);
> + rc = roc_npc_mcam_free(roc_npc, flow);
> if (rc != 0)
> return rc;
>
> diff --git a/drivers/common/cnxk/roc_npc.h b/drivers/common/cnxk/roc_npc.h
> index f92c2a633c..1b4e5521cb 100644
> --- a/drivers/common/cnxk/roc_npc.h
> +++ b/drivers/common/cnxk/roc_npc.h
> @@ -246,6 +246,7 @@ struct roc_npc_flow {
> uint8_t nix_intf;
> uint8_t enable;
> uint32_t mcam_id;
> + uint8_t use_ctr;
> int32_t ctr_id;
> uint32_t priority;
> uint32_t mtr_id;
> @@ -329,6 +330,8 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
> const struct roc_npc_action actions[], int *errcode);
> int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
> struct roc_npc_flow *flow);
> +int __roc_api roc_npc_mcam_free(struct roc_npc *roc_npc,
> + struct roc_npc_flow *mcam);
> int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
> int __roc_api roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc,
> bool enable);
> @@ -367,4 +370,8 @@ int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
> struct roc_npc_flow *flow);
> int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
> struct roc_npc *roc_npc_dst);
> +int __roc_api roc_npc_mcam_init(struct roc_npc *roc_npc,
> + struct roc_npc_flow *flow, int mcam_id);
> +int __roc_api roc_npc_mcam_move(struct roc_npc *roc_npc, uint16_t old_ent,
> + uint16_t new_ent);
> #endif /* _ROC_NPC_H_ */
> diff --git a/drivers/common/cnxk/roc_npc_mcam.c b/drivers/common/cnxk/roc_npc_mcam.c
> index 0ae58da0ba..245eeb0107 100644
> --- a/drivers/common/cnxk/roc_npc_mcam.c
> +++ b/drivers/common/cnxk/roc_npc_mcam.c
> @@ -401,16 +401,37 @@ npc_mcam_write_entry(struct npc *npc, struct roc_npc_flow *mcam)
> struct mbox *mbox = npc->mbox;
> struct mbox_msghdr *rsp;
> int rc = -ENOSPC;
> + uint16_t ctr = 0;
> int i;
>
> + if (mcam->use_ctr && mcam->ctr_id == NPC_COUNTER_NONE) {
> + rc = npc_mcam_alloc_counter(npc, &ctr);
> + if (rc)
> + return rc;
> + mcam->ctr_id = ctr;
> +
> + rc = npc_mcam_clear_counter(npc, mcam->ctr_id);
> + if (rc)
> + return rc;
> + }
> +
> req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
> - if (req == NULL)
> + if (req == NULL) {
> + if (mcam->use_ctr)
> + npc_mcam_free_counter(npc, ctr);
> +
> return rc;
> + }
> req->entry = mcam->mcam_id;
> req->intf = mcam->nix_intf;
> req->enable_entry = mcam->enable;
> req->entry_data.action = mcam->npc_action;
> req->entry_data.vtag_action = mcam->vtag_action;
> + if (mcam->use_ctr) {
> + req->set_cntr = 1;
> + req->cntr = mcam->ctr_id;
> + }
> +
> for (i = 0; i < NPC_MCAM_KEY_X4_WORDS; i++) {
> req->entry_data.kw[i] = mcam->mcam_data[i];
> req->entry_data.kw_mask[i] = mcam->mcam_mask[i];
> @@ -539,7 +560,6 @@ int
> npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
> struct npc_parse_state *pst)
> {
> - int use_ctr = (flow->ctr_id == NPC_COUNTER_NONE ? 0 : 1);
> struct npc_mcam_write_entry_req *req;
> struct nix_inl_dev *inl_dev = NULL;
> struct mbox *mbox = npc->mbox;
> @@ -552,15 +572,20 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
>
> PLT_SET_USED(pst);
>
> - if (use_ctr) {
> + if (flow->use_ctr) {
> rc = npc_mcam_alloc_counter(npc, &ctr);
> if (rc)
> return rc;
> +
> + flow->ctr_id = ctr;
> + rc = npc_mcam_clear_counter(npc, flow->ctr_id);
> + if (rc)
> + return rc;
> }
>
> entry = npc_get_free_mcam_entry(mbox, flow, npc);
> if (entry < 0) {
> - if (use_ctr)
> + if (flow->use_ctr)
> npc_mcam_free_counter(npc, ctr);
> return NPC_ERR_MCAM_ALLOC;
> }
> @@ -568,8 +593,8 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
> req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
> if (req == NULL)
> return -ENOSPC;
> - req->set_cntr = use_ctr;
> - req->cntr = ctr;
> + req->set_cntr = flow->use_ctr;
> + req->cntr = flow->ctr_id;
> req->entry = entry;
>
> req->intf = (flow->nix_intf == NIX_INTF_RX) ? NPC_MCAM_RX : NPC_MCAM_TX;
> @@ -636,7 +661,7 @@ npc_mcam_alloc_and_write(struct npc *npc, struct roc_npc_flow *flow,
>
> flow->mcam_id = entry;
>
> - if (use_ctr)
> + if (flow->use_ctr)
> flow->ctr_id = ctr;
> return 0;
> }
> diff --git a/drivers/common/cnxk/roc_npc_priv.h b/drivers/common/cnxk/roc_npc_priv.h
> index 78d6ee844d..b08539d8f8 100644
> --- a/drivers/common/cnxk/roc_npc_priv.h
> +++ b/drivers/common/cnxk/roc_npc_priv.h
> @@ -453,4 +453,6 @@ int npc_rss_action_program(struct roc_npc *roc_npc,
> const struct roc_npc_action actions[],
> struct roc_npc_flow *flow);
> int npc_rss_group_free(struct npc *npc, struct roc_npc_flow *flow);
> +int npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id);
> +int npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent);
> #endif /* _ROC_NPC_PRIV_H_ */
> diff --git a/drivers/common/cnxk/roc_npc_utils.c b/drivers/common/cnxk/roc_npc_utils.c
> index e36a312576..cbc6200fec 100644
> --- a/drivers/common/cnxk/roc_npc_utils.c
> +++ b/drivers/common/cnxk/roc_npc_utils.c
> @@ -264,9 +264,8 @@ npc_update_parse_state(struct npc_parse_state *pst,
> return 0;
> }
>
> -static int
> -npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
> - int mcam_id)
> +int
> +npc_mcam_init(struct npc *npc, struct roc_npc_flow *flow, int mcam_id)
> {
> struct npc_mcam_write_entry_req *req;
> struct npc_mcam_write_entry_rsq *rsp;
> @@ -308,8 +307,8 @@ npc_initialise_mcam_entry(struct npc *npc, struct roc_npc_flow *flow,
> return 0;
> }
>
> -static int
> -npc_shift_mcam_entry(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
> +int
> +npc_mcam_move(struct mbox *mbox, uint16_t old_ent, uint16_t new_ent)
> {
> struct npc_mcam_shift_entry_req *req;
> struct npc_mcam_shift_entry_rsp *rsp;
> @@ -365,12 +364,10 @@ npc_slide_mcam_entries(struct mbox *mbox, struct npc *npc, int prio,
> * Initialise and enable before moving an entry into
> * this mcam.
> */
> - rc = npc_initialise_mcam_entry(npc, curr->flow,
> - to_mcam_id);
> + rc = npc_mcam_init(npc, curr->flow, to_mcam_id);
> if (rc)
> return rc;
> - rc = npc_shift_mcam_entry(mbox, from_mcam_id,
> - to_mcam_id);
> + rc = npc_mcam_move(mbox, from_mcam_id, to_mcam_id);
> if (rc)
> return rc;
> curr->flow->mcam_id = to_mcam_id;
> diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
> index a77f3f6e3c..bbde990440 100644
> --- a/drivers/common/cnxk/version.map
> +++ b/drivers/common/cnxk/version.map
> @@ -325,7 +325,10 @@ INTERNAL {
> roc_npc_mcam_ena_dis_entry;
> roc_npc_mcam_free_all_resources;
> roc_npc_mcam_free_counter;
> + roc_npc_mcam_free;
> roc_npc_mcam_free_entry;
> + roc_npc_mcam_init;
> + roc_npc_mcam_move;
> roc_npc_mcam_merge_base_steering_rule;
> roc_npc_mcam_write_entry;
> roc_npc_mcam_read_counter;
> --
> 2.35.3
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-06-17 12:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-03 3:34 [dpdk-dev] [PATCH] common/cnxk: add ROC API to free MCAM entry psatheesh
2022-06-03 11:10 ` Ray Kinsella
2022-06-15 13:00 ` Jerin Jacob
2022-06-15 13:57 ` [dpdk-dev] [PATCH v2] " psatheesh
2022-06-17 12:54 ` Jerin Jacob
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).