From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DF125A0547; Mon, 27 Sep 2021 10:25:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 498AA4119B; Mon, 27 Sep 2021 10:23:37 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 4F2CA4119A for ; Mon, 27 Sep 2021 10:23:36 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18QLbnww025340 for ; Mon, 27 Sep 2021 01:23:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=Z6Pmueh7pccKyqfaQZgZ0ZO9OWvC2FteCIAJ2Hy4f8g=; b=VhdfpwU40Fl6RVGWVYfEHd29BmHoSQH83X0QDdwi5VYljGAgTgtzC8bi/Mb/HmYW9nlD oav0MntlveofULpisXO/2zynIVOknex0BBmVFfs4ywCmNzOz5AloPmkbEuuD7pZf+kDz btk5lIWDFjBUMIR7uy18WFqFjf5KT3Iu9bQexz+ANFR/MFZeG4XmDIfdAdJOfkDhJ87w 9G1po43MNEyNokLbu2RyHqHy/u/5ay/+AJiIYEXB9gfjv6EG7qoS1huife1TYsOqTWCX IZyfYzrQcpscK9jtnA7+0531Xtv0vHiJnwOFHASE2hECIZuiMoTvKbE9U6qLRnf2NXAB 9A== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3bavvuhtvy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 27 Sep 2021 01:23:34 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 27 Sep 2021 01:23:32 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 27 Sep 2021 01:23:32 -0700 Received: from localhost.localdomain (unknown [10.28.34.25]) by maili.marvell.com (Postfix) with ESMTP id 928F83F7043; Mon, 27 Sep 2021 01:23:30 -0700 (PDT) From: To: Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao CC: , Rakesh Kudurumalla Date: Mon, 27 Sep 2021 13:52:23 +0530 Message-ID: <20210927082223.757436-27-skori@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927082223.757436-1-skori@marvell.com> References: <20210927082223.757436-1-skori@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: WvYT7xCNPkpNMsJAxBkNVQeyR9rtavN4 X-Proofpoint-GUID: WvYT7xCNPkpNMsJAxBkNVQeyR9rtavN4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-27_02,2021-09-24_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 27/27] net/cnxk: support meter action to flow create X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Sunil Kumar Kori Meters are configured per flow using rte_flow_create API. Implement support for meter action applied on the flow. Signed-off-by: Sunil Kumar Kori Signed-off-by: Rakesh Kudurumalla --- v2: - Rebase support on latest DPDK - Handled multilevel chaining for linear hierarchy - Review comments incorporated doc/guides/nics/features/cnxk.ini | 1 + doc/guides/nics/features/cnxk_vf.ini | 1 + drivers/net/cnxk/cn10k_ethdev_mtr.c | 388 +++++++++++++++++++++++++++ drivers/net/cnxk/cn10k_rte_flow.c | 155 ++++++++++- drivers/net/cnxk/cnxk_ethdev.h | 15 ++ drivers/net/cnxk/cnxk_rte_flow.c | 4 + 6 files changed, 563 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/features/cnxk.ini b/doc/guides/nics/features/cnxk.ini index 5d456257bd..7bbce7dafc 100644 --- a/doc/guides/nics/features/cnxk.ini +++ b/doc/guides/nics/features/cnxk.ini @@ -78,6 +78,7 @@ count = Y drop = Y flag = Y mark = Y +meter = Y of_pop_vlan = Y of_push_vlan = Y of_set_vlan_pcp = Y diff --git a/doc/guides/nics/features/cnxk_vf.ini b/doc/guides/nics/features/cnxk_vf.ini index 7b4299f0be..89802a27f9 100644 --- a/doc/guides/nics/features/cnxk_vf.ini +++ b/doc/guides/nics/features/cnxk_vf.ini @@ -70,6 +70,7 @@ count = Y drop = Y flag = Y mark = Y +meter = Y of_pop_vlan = Y of_push_vlan = Y of_set_vlan_pcp = Y diff --git a/drivers/net/cnxk/cn10k_ethdev_mtr.c b/drivers/net/cnxk/cn10k_ethdev_mtr.c index c0482d1418..75193b3db1 100644 --- a/drivers/net/cnxk/cn10k_ethdev_mtr.c +++ b/drivers/net/cnxk/cn10k_ethdev_mtr.c @@ -790,3 +790,391 @@ cn10k_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops) *(const void **)ops = &nix_mtr_ops; return 0; } + +int +nix_mtr_validate(struct rte_eth_dev *eth_dev, uint32_t id) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_mtr_profile_node *profile; + struct cnxk_mtr_policy_node *policy; + struct cnxk_meter_node *mtr; + + mtr = nix_mtr_find(dev, id); + if (mtr == NULL) + return -EINVAL; + + profile = nix_mtr_profile_find(dev, mtr->params.meter_profile_id); + if (profile == NULL) + return -EINVAL; + + policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id); + if (policy == NULL) + return -EINVAL; + + return 0; +} + +int +nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id, + struct cnxk_mtr_policy_node **policy_act) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_mtr_policy_node *policy; + struct cnxk_meter_node *mtr; + + mtr = nix_mtr_find(dev, id); + if (mtr == NULL) + return -EINVAL; + + policy = nix_mtr_policy_find(dev, mtr->params.meter_policy_id); + if (policy == NULL) + return -EINVAL; + + *policy_act = policy; + + return 0; +} + +int +nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t queue_num, + const uint16_t *queue) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_meter_node *mtr; + uint32_t i; + + mtr = nix_mtr_find(dev, id); + if (mtr == NULL) + return -EINVAL; + + mtr->rq_id = plt_zmalloc(queue_num * sizeof(uint32_t), ROC_ALIGN); + if (mtr->rq_id == NULL) + return -ENOMEM; + + mtr->rq_num = queue_num; + for (i = 0; i < queue_num; i++) + mtr->rq_id[i] = queue[i]; + + return 0; +} + +int +nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id) +{ + struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0}; + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + uint32_t mtr_id = cur_id; + int i = 0; + + for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) { + mtr[i] = nix_mtr_find(dev, mtr_id); + if (mtr[i]) + mtr_id = mtr[i]->next_id; + } + for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) { + if (mtr[i]) { + mtr[i]->level = ROC_NIX_BPF_LEVEL_IDX_INVALID; + mtr[i]->prev_id = ROC_NIX_BPF_ID_INVALID; + mtr[i]->next_id = ROC_NIX_BPF_ID_INVALID; + mtr[i]->is_prev = false; + mtr[i]->is_next = false; + } + } + return 0; +} + +int +nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id, + uint32_t prev_id, uint32_t next_id) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_meter_node *mtr; + + mtr = nix_mtr_find(dev, cur_id); + if (mtr == NULL) + return -EINVAL; + + switch (lvl_map[mtr->level]) { + case ROC_NIX_BPF_LEVEL_F_LEAF: + mtr->prev_id = ROC_NIX_BPF_ID_INVALID; + mtr->next_id = next_id; + mtr->is_prev = false; + mtr->is_next = true; + break; + case ROC_NIX_BPF_LEVEL_F_MID: + mtr->prev_id = prev_id; + mtr->next_id = next_id; + mtr->is_prev = true; + mtr->is_next = true; + break; + case ROC_NIX_BPF_LEVEL_F_TOP: + mtr->prev_id = prev_id; + mtr->next_id = ROC_NIX_BPF_ID_INVALID; + mtr->is_prev = true; + mtr->is_next = false; + break; + default: + plt_err("Invalid meter level"); + return -EINVAL; + } + + return 0; +} + +int +nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id, uint32_t level) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_meter_node *mtr; + + mtr = nix_mtr_find(dev, id); + if (mtr == NULL) + return -EINVAL; + + mtr->level = level; + return 0; +} + +static void +nix_mtr_config_map(struct cnxk_meter_node *mtr, struct roc_nix_bpf_cfg *cfg) +{ + enum roc_nix_bpf_algo alg_map[] = { + ROC_NIX_BPF_ALGO_NONE, ROC_NIX_BPF_ALGO_2697, + ROC_NIX_BPF_ALGO_2698, ROC_NIX_BPF_ALGO_4115}; + struct cnxk_mtr_profile_node *profile = mtr->profile; + struct cnxk_mtr_policy_node *policy = mtr->policy; + + cfg->alg = alg_map[profile->profile.alg]; + cfg->lmode = profile->profile.packet_mode; + + switch (cfg->alg) { + case ROC_NIX_BPF_ALGO_2697: + cfg->algo2697.cir = profile->profile.srtcm_rfc2697.cir * 8; + cfg->algo2697.cbs = profile->profile.srtcm_rfc2697.cbs; + cfg->algo2697.ebs = profile->profile.srtcm_rfc2697.ebs; + break; + case ROC_NIX_BPF_ALGO_2698: + cfg->algo2698.cir = profile->profile.trtcm_rfc2698.cir * 8; + cfg->algo2698.pir = profile->profile.trtcm_rfc2698.pir * 8; + cfg->algo2698.cbs = profile->profile.trtcm_rfc2698.cbs; + cfg->algo2698.pbs = profile->profile.trtcm_rfc2698.pbs; + break; + case ROC_NIX_BPF_ALGO_4115: + cfg->algo4115.cir = profile->profile.trtcm_rfc4115.cir * 8; + cfg->algo4115.eir = profile->profile.trtcm_rfc4115.eir * 8; + cfg->algo4115.cbs = profile->profile.trtcm_rfc4115.cbs; + cfg->algo4115.ebs = profile->profile.trtcm_rfc4115.ebs; + break; + default: + break; + } + + cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_PASS; + cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_PASS; + cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_PASS; + + if (policy->actions[RTE_COLOR_GREEN].action_fate == + RTE_FLOW_ACTION_TYPE_DROP) + cfg->action[ROC_NIX_BPF_COLOR_GREEN] = ROC_NIX_BPF_ACTION_DROP; + + if (policy->actions[RTE_COLOR_YELLOW].action_fate == + RTE_FLOW_ACTION_TYPE_DROP) + cfg->action[ROC_NIX_BPF_COLOR_YELLOW] = ROC_NIX_BPF_ACTION_DROP; + + if (policy->actions[RTE_COLOR_RED].action_fate == + RTE_FLOW_ACTION_TYPE_DROP) + cfg->action[ROC_NIX_BPF_COLOR_RED] = ROC_NIX_BPF_ACTION_DROP; +} + +static void +nix_dscp_table_map(struct cnxk_meter_node *mtr, + struct roc_nix_bpf_precolor *tbl) +{ + enum roc_nix_bpf_color color_map[] = {ROC_NIX_BPF_COLOR_GREEN, + ROC_NIX_BPF_COLOR_YELLOW, + ROC_NIX_BPF_COLOR_RED}; + int i; + + tbl->count = ROC_NIX_BPF_PRE_COLOR_MAX; + tbl->mode = ROC_NIX_BPF_PC_MODE_DSCP_OUTER; + + for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++) + tbl->color[i] = ROC_NIX_BPF_COLOR_GREEN; + + if (mtr->params.dscp_table) { + for (i = 0; i < ROC_NIX_BPF_PRE_COLOR_MAX; i++) + tbl->color[i] = color_map[mtr->params.dscp_table[i]]; + } +} + +int +nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id) +{ + struct cnxk_meter_node *mtr[ROC_NIX_BPF_LEVEL_MAX] = {0}; + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix_bpf_objs profs[ROC_NIX_BPF_LEVEL_MAX]; + uint8_t idx0 = ROC_NIX_BPF_LEVEL_IDX_INVALID; + uint8_t idx1 = ROC_NIX_BPF_LEVEL_IDX_INVALID; + uint8_t idx2 = ROC_NIX_BPF_LEVEL_IDX_INVALID; + uint16_t per_lvl_cnt[ROC_NIX_BPF_LEVEL_MAX]; + int num_mtr[ROC_NIX_BPF_LEVEL_MAX] = {0}; + struct roc_nix *nix = &dev->nix; + struct roc_nix_bpf_precolor tbl; + struct roc_nix_bpf_cfg cfg; + struct roc_nix_rq *rq; + uint8_t lvl_mask; + uint32_t i; + uint32_t j; + int rc; + + mtr[0] = nix_mtr_find(dev, id); + if (mtr[0] == NULL) + return -EINVAL; + + num_mtr[0] = 1; + idx0 = roc_nix_bpf_level_to_idx(lvl_map[mtr[0]->level]); + if (idx0 == ROC_NIX_BPF_LEVEL_IDX_INVALID) + return -EINVAL; + + lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF; + per_lvl_cnt[idx0] = 1; + + if (mtr[0]->is_next) { + mtr[1] = nix_mtr_find(dev, mtr[0]->next_id); + if (mtr[1] == NULL) + return -EINVAL; + num_mtr[1] = 1; + idx1 = roc_nix_bpf_level_to_idx(lvl_map[mtr[1]->level]); + if (idx1 == ROC_NIX_BPF_LEVEL_IDX_INVALID) + return -EINVAL; + + lvl_mask |= ROC_NIX_BPF_LEVEL_F_MID; + per_lvl_cnt[idx1] = 1; + } + + if (mtr[1] && mtr[1]->is_next) { + mtr[2] = nix_mtr_find(dev, mtr[1]->next_id); + if (mtr[2] == NULL) + return -EINVAL; + + num_mtr[2] = 1; + idx2 = roc_nix_bpf_level_to_idx(lvl_map[mtr[2]->level]); + if (idx2 == ROC_NIX_BPF_LEVEL_IDX_INVALID) + return -EINVAL; + + lvl_mask |= ROC_NIX_BPF_LEVEL_F_TOP; + per_lvl_cnt[idx2] = 1; + } + + rc = roc_nix_bpf_alloc(nix, lvl_mask, per_lvl_cnt, profs); + if (rc) + return rc; + + mtr[0]->bpf_id = profs[idx0].ids[0]; + + if (num_mtr[0]) + if (mtr[0]->is_next && idx1 != ROC_NIX_BPF_LEVEL_IDX_INVALID) + mtr[1]->bpf_id = profs[idx1].ids[0]; + + if (num_mtr[1]) + if (mtr[1]->is_next && idx2 != ROC_NIX_BPF_LEVEL_IDX_INVALID) + mtr[2]->bpf_id = profs[idx2].ids[0]; + + for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++) { + if (num_mtr[i]) { + memset(&cfg, 0, sizeof(struct roc_nix_bpf_cfg)); + nix_mtr_config_map(mtr[i], &cfg); + rc = roc_nix_bpf_config(nix, mtr[i]->bpf_id, + lvl_map[mtr[i]->level], &cfg); + + memset(&tbl, 0, sizeof(struct roc_nix_bpf_precolor)); + nix_dscp_table_map(mtr[i], &tbl); + rc = roc_nix_bpf_pre_color_tbl_setup(nix, + mtr[i]->bpf_id, + lvl_map[mtr[i]->level], + &tbl); + + if (mtr[i]->params.meter_enable) { + for (j = 0; j < mtr[i]->rq_num; j++) { + rq = &dev->rqs[mtr[i]->rq_id[j]]; + rc = roc_nix_bpf_ena_dis(nix, + mtr[i]->bpf_id, rq, + true); + } + } + } + } + + return rc; +} + +int +nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id, + uint32_t *prev_id, uint32_t *next_id, + struct cnxk_mtr_policy_node *policy, + int *tree_level) +{ + uint32_t action_fate_red = policy->actions[RTE_COLOR_RED].action_fate; + uint32_t action_fate_green = + policy->actions[RTE_COLOR_GREEN].action_fate; + uint32_t action_fate_yellow = + policy->actions[RTE_COLOR_YELLOW].action_fate; + + uint32_t cur_mtr_id = *next_id; + uint32_t next_mtr_id = 0xffff; + uint32_t prev_mtr_id = 0xffff; + + if (action_fate_green == RTE_FLOW_ACTION_TYPE_METER) + next_mtr_id = policy->actions[RTE_COLOR_GREEN].mtr_id; + + if (action_fate_yellow == RTE_FLOW_ACTION_TYPE_METER) + next_mtr_id = policy->actions[RTE_COLOR_YELLOW].mtr_id; + + if (action_fate_red == RTE_FLOW_ACTION_TYPE_METER) + next_mtr_id = policy->actions[RTE_COLOR_RED].mtr_id; + + if (next_mtr_id != 0xffff) { + switch (*tree_level) { + case 0: + nix_mtr_level_update(eth_dev, cur_mtr_id, 0); + nix_mtr_chain_update(eth_dev, cur_mtr_id, -1, + next_mtr_id); + (*tree_level)++; + *next_id = next_mtr_id; + break; + case 1: + nix_mtr_level_update(eth_dev, cur_mtr_id, 1); + prev_mtr_id = id; + nix_mtr_chain_update(eth_dev, cur_mtr_id, prev_mtr_id, + next_mtr_id); + (*tree_level)++; + *next_id = next_mtr_id; + *prev_id = cur_mtr_id; + break; + case 2: + nix_mtr_chain_reset(eth_dev, id); + return -EINVAL; + } + } else { + switch (*tree_level) { + case 0: + nix_mtr_level_update(eth_dev, cur_mtr_id, 0); + break; + case 1: + nix_mtr_level_update(eth_dev, cur_mtr_id, 1); + prev_mtr_id = id; + nix_mtr_chain_update(eth_dev, cur_mtr_id, prev_mtr_id, + -1); + break; + case 2: + nix_mtr_level_update(eth_dev, cur_mtr_id, 2); + prev_mtr_id = *prev_id; + nix_mtr_chain_update(eth_dev, cur_mtr_id, prev_mtr_id, + -1); + break; + } + *next_id = 0xffff; + } + + return 0; +} diff --git a/drivers/net/cnxk/cn10k_rte_flow.c b/drivers/net/cnxk/cn10k_rte_flow.c index b04de6a7e6..128dc2dd4f 100644 --- a/drivers/net/cnxk/cn10k_rte_flow.c +++ b/drivers/net/cnxk/cn10k_rte_flow.c @@ -6,6 +6,107 @@ #include "cn10k_ethdev.h" #include "cn10k_rx.h" +static int +cn10k_mtr_configure(struct rte_eth_dev *eth_dev, + const struct rte_flow_action actions[]) +{ + uint32_t mtr_id = 0xffff, prev_mtr_id = 0xffff, next_mtr_id = 0xffff; + const struct rte_flow_action_meter *mtr_conf; + const struct rte_flow_action_queue *q_conf; + const struct rte_flow_action_rss *rss_conf; + struct cnxk_mtr_policy_node *policy; + bool is_mtr_act = false; + int tree_level = 0; + int rc = -EINVAL, i; + + for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) { + if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) { + mtr_conf = (const struct rte_flow_action_meter + *)(actions->conf); + mtr_id = mtr_conf->mtr_id; + is_mtr_act = true; + } + if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) { + q_conf = (const struct rte_flow_action_queue + *)(actions->conf); + if (is_mtr_act) + nix_mtr_rq_update(eth_dev, mtr_id, 1, + &q_conf->index); + } + if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) { + rss_conf = (const struct rte_flow_action_rss + *)(actions->conf); + if (is_mtr_act) + nix_mtr_rq_update(eth_dev, mtr_id, + rss_conf->queue_num, + rss_conf->queue); + } + } + + if (!is_mtr_act) + return rc; + + prev_mtr_id = mtr_id; + next_mtr_id = mtr_id; + while (next_mtr_id != 0xffff) { + rc = nix_mtr_validate(eth_dev, next_mtr_id); + if (rc) + return rc; + + rc = nix_mtr_policy_act_get(eth_dev, next_mtr_id, &policy); + if (rc) + return rc; + + rc = nix_mtr_color_action_validate(eth_dev, mtr_id, + &prev_mtr_id, &next_mtr_id, + policy, &tree_level); + if (rc) + return rc; + } + + return nix_mtr_configure(eth_dev, mtr_id); +} + +static int +cn10k_rss_action_validate(struct rte_eth_dev *eth_dev, + const struct rte_flow_attr *attr, + const struct rte_flow_action *act) +{ + const struct rte_flow_action_rss *rss; + + if (act == NULL) + return -EINVAL; + + rss = (const struct rte_flow_action_rss *)act->conf; + + if (attr->egress) { + plt_err("No support of RSS in egress"); + return -EINVAL; + } + + if (eth_dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) { + plt_err("multi-queue mode is disabled"); + return -ENOTSUP; + } + + if (!rss || !rss->queue_num) { + plt_err("no valid queues"); + return -EINVAL; + } + + if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT) { + plt_err("non-default RSS hash functions are not supported"); + return -ENOTSUP; + } + + if (rss->key_len && rss->key_len > ROC_NIX_RSS_KEY_LEN) { + plt_err("RSS hash key too large"); + return -ENOTSUP; + } + + return 0; +} + struct rte_flow * cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr, const struct rte_flow_item pattern[], @@ -13,13 +114,65 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr, struct rte_flow_error *error) { struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + const struct rte_flow_action *action_rss = NULL; + const struct rte_flow_action_meter *mtr = NULL; int mark_actions = 0, vtag_actions = 0; struct roc_npc *npc = &dev->npc; struct roc_npc_flow *flow; + uint32_t req_act = 0; + int i, rc; + + for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) { + if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) + req_act |= ROC_NPC_ACTION_TYPE_METER; + + if (actions[i].type == RTE_FLOW_ACTION_TYPE_QUEUE) + req_act |= ROC_NPC_ACTION_TYPE_QUEUE; + + if (actions[i].type == RTE_FLOW_ACTION_TYPE_RSS) { + req_act |= ROC_NPC_ACTION_TYPE_RSS; + action_rss = &actions[i]; + } + } + + if (req_act & ROC_NPC_ACTION_TYPE_METER) { + if ((req_act & ROC_NPC_ACTION_TYPE_RSS) && + ((req_act & ROC_NPC_ACTION_TYPE_QUEUE))) { + return NULL; + } + if (req_act & ROC_NPC_ACTION_TYPE_RSS) { + rc = cn10k_rss_action_validate(eth_dev, attr, + action_rss); + if (rc) + return NULL; + } else if (req_act & ROC_NPC_ACTION_TYPE_QUEUE) { + } else { + return NULL; + } + } + + for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) { + if (actions[i].type == RTE_FLOW_ACTION_TYPE_METER) { + mtr = (const struct rte_flow_action_meter *)actions[i] + .conf; + rc = cn10k_mtr_configure(eth_dev, actions); + if (rc) { + rte_flow_error_set(error, 0, + RTE_FLOW_ERROR_TYPE_ACTION, NULL, + "Failed to configure mtr "); + return NULL; + } + break; + } + } flow = cnxk_flow_create(eth_dev, attr, pattern, actions, error); - if (!flow) + if (!flow) { + if (mtr) + nix_mtr_chain_reset(eth_dev, mtr->mtr_id); + return NULL; + } mark_actions = roc_npc_mark_actions_get(npc); diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h index 0ad06f1536..2dce42e20c 100644 --- a/drivers/net/cnxk/cnxk_ethdev.h +++ b/drivers/net/cnxk/cnxk_ethdev.h @@ -454,6 +454,21 @@ int cnxk_nix_dev_get_reg(struct rte_eth_dev *eth_dev, /* Other private functions */ int nix_recalc_mtu(struct rte_eth_dev *eth_dev); +int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id); +int nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id, + struct cnxk_mtr_policy_node **policy); +int nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id, + uint32_t queue_num, const uint16_t *queue); +int nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id, + uint32_t prev_id, uint32_t next_id); +int nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id); +int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id, + uint32_t level); +int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id); +int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id, + uint32_t *prev_id, uint32_t *next_id, + struct cnxk_mtr_policy_node *policy, + int *tree_level); /* Inlines */ static __rte_always_inline uint64_t diff --git a/drivers/net/cnxk/cnxk_rte_flow.c b/drivers/net/cnxk/cnxk_rte_flow.c index 32c1b5dee5..56dcd36c61 100644 --- a/drivers/net/cnxk/cnxk_rte_flow.c +++ b/drivers/net/cnxk/cnxk_rte_flow.c @@ -195,6 +195,10 @@ cnxk_map_actions(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr, ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT; in_actions[i].conf = actions->conf; break; + case RTE_FLOW_ACTION_TYPE_METER: + in_actions[i].type = ROC_NPC_ACTION_TYPE_METER; + in_actions[i].conf = actions->conf; + break; default: plt_npc_dbg("Action is not supported = %d", actions->type); -- 2.25.1