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 94B35A0C45; Wed, 22 Sep 2021 08:12:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E8E5411AE; Wed, 22 Sep 2021 08:12:35 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id B27314118D for ; Wed, 22 Sep 2021 08:12:27 +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 18LLFpF3022454 for ; Tue, 21 Sep 2021 23:12:27 -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-type; s=pfpt0220; bh=QfAu/MJ3rAXd3dtg0nOb2wBlS214tcczaP82bl4owv8=; b=gf3KD/kJpw9E1wKUTsRDRC1Mm3UoI2lpcfwigsVJemow9QMk+/AP/nAn584yq6yAIM/n hWaTi1SrR0FbG4HELXaVB7LXv96Lo2tLQiUVB8VF8h7SGC0FNTKglpomwM/pYNTYzPUS jdU0m8pkzOBBI9QO1TtfBthPOd1yNQAIGJE7nFreVAIsq8+pT9Ma7lRTXVvzlDNHZosO kg31FOeLdnqspqnyUcAV8hKhBb5/ZcTs+cKxuuiISl3yuMANIH97PgWc33vEbsXg3ECc n1SCdAAXyJSAMuC1cg/30J7nx1YLONKXC1PbsQB/2SBWSRyX3+B5WtfYd5P2iFLCNIIx zg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 3b7q5dhe7g-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 21 Sep 2021 23:12:26 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 21 Sep 2021 23:12:18 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Tue, 21 Sep 2021 23:12:18 -0700 Received: from cavium.marvell.com (cavium.marvell.com [10.28.34.244]) by maili.marvell.com (Postfix) with ESMTP id A30C33F7079; Tue, 21 Sep 2021 23:12:16 -0700 (PDT) From: To: Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao CC: Date: Wed, 22 Sep 2021 02:11:48 -0400 Message-ID: <1632291108-28780-9-git-send-email-skoteshwar@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1632291108-28780-1-git-send-email-skoteshwar@marvell.com> References: <1630516236-10526-1-git-send-email-skoteshwar@marvell.com> <1632291108-28780-1-git-send-email-skoteshwar@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: TJFhycff7AEFt1othSrwPXC0s5clfN5Q X-Proofpoint-ORIG-GUID: TJFhycff7AEFt1othSrwPXC0s5clfN5Q 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-22_01,2021-09-20_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH v3 8/8] net/cnxk: TM shaper and node operations 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: Satha Rao Implemented TM node, shaper profile, hierarchy_commit and statistic operations. Signed-off-by: Satha Rao Acked-by: Nithin Dabilpuram --- doc/guides/rel_notes/release_21_11.rst | 1 + drivers/net/cnxk/cnxk_tm.c | 353 +++++++++++++++++++++++++ drivers/net/cnxk/cnxk_tm.h | 5 + 3 files changed, 359 insertions(+) diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index b44c077fd6..7e732d003b 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -65,6 +65,7 @@ New Features * **Updated Marvell cnxk ethdev driver.** * Added rte_flow support for dual VLAN insert and strip actions + * Added rte_tm support * **Updated Marvell cnxk crypto PMD.** diff --git a/drivers/net/cnxk/cnxk_tm.c b/drivers/net/cnxk/cnxk_tm.c index 87fd8bec92..9015a452f8 100644 --- a/drivers/net/cnxk/cnxk_tm.c +++ b/drivers/net/cnxk/cnxk_tm.c @@ -259,11 +259,364 @@ cnxk_nix_tm_node_capa_get(struct rte_eth_dev *eth_dev, uint32_t node_id, return 0; } +static int +cnxk_nix_tm_shaper_profile_add(struct rte_eth_dev *eth_dev, uint32_t id, + struct rte_tm_shaper_params *params, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_nix_tm_shaper_profile *profile; + struct roc_nix *nix = &dev->nix; + int rc; + + if (roc_nix_tm_shaper_profile_get(nix, id)) { + error->type = RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID; + error->message = "shaper profile ID exist"; + return -EINVAL; + } + + profile = rte_zmalloc("cnxk_nix_tm_shaper_profile", + sizeof(struct cnxk_nix_tm_shaper_profile), 0); + if (!profile) + return -ENOMEM; + profile->profile.id = id; + profile->profile.commit_rate = params->committed.rate; + profile->profile.peak_rate = params->peak.rate; + profile->profile.commit_sz = params->committed.size; + profile->profile.peak_sz = params->peak.size; + /* If Byte mode, then convert to bps */ + if (!params->packet_mode) { + profile->profile.commit_rate *= 8; + profile->profile.peak_rate *= 8; + profile->profile.commit_sz *= 8; + profile->profile.peak_sz *= 8; + } + profile->profile.pkt_len_adj = params->pkt_length_adjust; + profile->profile.pkt_mode = params->packet_mode; + profile->profile.free_fn = rte_free; + rte_memcpy(&profile->params, params, + sizeof(struct rte_tm_shaper_params)); + + rc = roc_nix_tm_shaper_profile_add(nix, &profile->profile); + + /* fill error information based on return value */ + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + } + + return rc; +} + +static int +cnxk_nix_tm_shaper_profile_delete(struct rte_eth_dev *eth_dev, + uint32_t profile_id, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix *nix = &dev->nix; + int rc; + + rc = roc_nix_tm_shaper_profile_delete(nix, profile_id); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + } + + return rc; +} + +static int +cnxk_nix_tm_node_add(struct rte_eth_dev *eth_dev, uint32_t node_id, + uint32_t parent_node_id, uint32_t priority, + uint32_t weight, uint32_t lvl, + struct rte_tm_node_params *params, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix_tm_shaper_profile *profile; + struct roc_nix_tm_node *parent_node; + struct roc_nix *nix = &dev->nix; + struct cnxk_nix_tm_node *node; + int rc; + + /* we don't support dynamic updates */ + if (roc_nix_tm_is_user_hierarchy_enabled(nix)) { + error->type = RTE_TM_ERROR_TYPE_CAPABILITIES; + error->message = "dynamic update not supported"; + return -EIO; + } + + parent_node = roc_nix_tm_node_get(nix, parent_node_id); + /* find the right level */ + if (lvl == RTE_TM_NODE_LEVEL_ID_ANY) { + if (parent_node_id == RTE_TM_NODE_ID_NULL) { + lvl = ROC_TM_LVL_ROOT; + } else if (parent_node) { + lvl = parent_node->lvl + 1; + } else { + /* Neither proper parent nor proper level id given */ + error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID; + error->message = "invalid parent node id"; + return -ERANGE; + } + } + + node = rte_zmalloc("cnxk_nix_tm_node", sizeof(struct cnxk_nix_tm_node), + 0); + if (!node) + return -ENOMEM; + + rte_memcpy(&node->params, params, sizeof(struct rte_tm_node_params)); + + node->nix_node.id = node_id; + node->nix_node.parent_id = parent_node_id; + node->nix_node.priority = priority; + node->nix_node.weight = weight; + node->nix_node.lvl = lvl; + node->nix_node.shaper_profile_id = params->shaper_profile_id; + + profile = roc_nix_tm_shaper_profile_get(nix, params->shaper_profile_id); + /* Packet mode */ + if (!roc_nix_tm_lvl_is_leaf(nix, lvl) && + ((profile && profile->pkt_mode) || + (params->nonleaf.wfq_weight_mode && + params->nonleaf.n_sp_priorities && + !params->nonleaf.wfq_weight_mode[0]))) + node->nix_node.pkt_mode = 1; + + rc = roc_nix_tm_node_add(nix, &node->nix_node); + if (rc < 0) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + return rc; + } + error->type = RTE_TM_ERROR_TYPE_NONE; + roc_nix_tm_shaper_default_red_algo(&node->nix_node, profile); + + return 0; +} + +static int +cnxk_nix_tm_node_delete(struct rte_eth_dev *eth_dev, uint32_t node_id, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix *nix = &dev->nix; + struct cnxk_nix_tm_node *node; + int rc; + + /* we don't support dynamic updates yet */ + if (roc_nix_tm_is_user_hierarchy_enabled(nix)) { + error->type = RTE_TM_ERROR_TYPE_CAPABILITIES; + error->message = "hierarchy exists"; + return -EIO; + } + + if (node_id == RTE_TM_NODE_ID_NULL) { + error->type = RTE_TM_ERROR_TYPE_NODE_ID; + error->message = "invalid node id"; + return -EINVAL; + } + + node = (struct cnxk_nix_tm_node *)roc_nix_tm_node_get(nix, node_id); + + rc = roc_nix_tm_node_delete(nix, node_id, 0); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + } else { + rte_free(node); + } + + return rc; +} + +static int +cnxk_nix_tm_node_suspend(struct rte_eth_dev *eth_dev, uint32_t node_id, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + int rc; + + rc = roc_nix_tm_node_suspend_resume(&dev->nix, node_id, true); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + } + + return rc; +} + +static int +cnxk_nix_tm_node_resume(struct rte_eth_dev *eth_dev, uint32_t node_id, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + int rc; + + rc = roc_nix_tm_node_suspend_resume(&dev->nix, node_id, false); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + } + + return rc; +} + +static int +cnxk_nix_tm_hierarchy_commit(struct rte_eth_dev *eth_dev, + int clear_on_fail __rte_unused, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix *nix = &dev->nix; + int rc; + + if (roc_nix_tm_is_user_hierarchy_enabled(nix)) { + error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED; + error->message = "hierarchy exists"; + return -EIO; + } + + if (roc_nix_tm_leaf_cnt(nix) < dev->nb_txq) { + error->type = RTE_TM_ERROR_TYPE_UNSPECIFIED; + error->message = "incomplete hierarchy"; + return -EINVAL; + } + + rc = roc_nix_tm_hierarchy_disable(nix); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + return -EIO; + } + + rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_USER, true); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + return -EIO; + } + error->type = RTE_TM_ERROR_TYPE_NONE; + + return 0; +} + +static int +cnxk_nix_tm_node_shaper_update(struct rte_eth_dev *eth_dev, uint32_t node_id, + uint32_t profile_id, struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix_tm_shaper_profile *profile; + struct roc_nix *nix = &dev->nix; + struct roc_nix_tm_node *node; + int rc; + + rc = roc_nix_tm_node_shaper_update(nix, node_id, profile_id, false); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + return -EINVAL; + } + node = roc_nix_tm_node_get(nix, node_id); + if (!node) + return -EINVAL; + + profile = roc_nix_tm_shaper_profile_get(nix, profile_id); + roc_nix_tm_shaper_default_red_algo(node, profile); + + return 0; +} + +static int +cnxk_nix_tm_node_parent_update(struct rte_eth_dev *eth_dev, uint32_t node_id, + uint32_t new_parent_id, uint32_t priority, + uint32_t weight, struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix *nix = &dev->nix; + int rc; + + rc = roc_nix_tm_node_parent_update(nix, node_id, new_parent_id, + priority, weight); + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + return -EINVAL; + } + + return 0; +} + +static int +cnxk_nix_tm_node_stats_read(struct rte_eth_dev *eth_dev, uint32_t node_id, + struct rte_tm_node_stats *stats, + uint64_t *stats_mask, int clear, + struct rte_tm_error *error) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix_tm_node_stats nix_tm_stats; + struct roc_nix *nix = &dev->nix; + struct roc_nix_tm_node *node; + int rc; + + node = roc_nix_tm_node_get(nix, node_id); + if (!node) { + error->type = RTE_TM_ERROR_TYPE_NODE_ID; + error->message = "no such node"; + return -EINVAL; + } + + if (roc_nix_tm_lvl_is_leaf(nix, node->lvl)) { + struct roc_nix_stats_queue qstats; + + rc = roc_nix_stats_queue_get(nix, node->id, 0, &qstats); + if (!rc) { + stats->n_pkts = qstats.tx_pkts; + stats->n_bytes = qstats.tx_octs; + *stats_mask = + RTE_TM_STATS_N_PKTS | RTE_TM_STATS_N_BYTES; + } + goto exit; + } + + rc = roc_nix_tm_node_stats_get(nix, node_id, clear, &nix_tm_stats); + if (!rc) { + stats->leaf.n_pkts_dropped[RTE_COLOR_RED] = + nix_tm_stats.stats[ROC_NIX_TM_NODE_PKTS_DROPPED]; + stats->leaf.n_bytes_dropped[RTE_COLOR_RED] = + nix_tm_stats.stats[ROC_NIX_TM_NODE_BYTES_DROPPED]; + *stats_mask = RTE_TM_STATS_N_PKTS_RED_DROPPED | + RTE_TM_STATS_N_BYTES_RED_DROPPED; + } + +exit: + if (rc) { + error->type = roc_nix_tm_err_to_rte_err(rc); + error->message = roc_error_msg_get(rc); + } + return rc; +} + const struct rte_tm_ops cnxk_tm_ops = { .node_type_get = cnxk_nix_tm_node_type_get, .capabilities_get = cnxk_nix_tm_capa_get, .level_capabilities_get = cnxk_nix_tm_level_capa_get, .node_capabilities_get = cnxk_nix_tm_node_capa_get, + + .shaper_profile_add = cnxk_nix_tm_shaper_profile_add, + .shaper_profile_delete = cnxk_nix_tm_shaper_profile_delete, + + .node_add = cnxk_nix_tm_node_add, + .node_delete = cnxk_nix_tm_node_delete, + .node_suspend = cnxk_nix_tm_node_suspend, + .node_resume = cnxk_nix_tm_node_resume, + .hierarchy_commit = cnxk_nix_tm_hierarchy_commit, + + .node_shaper_update = cnxk_nix_tm_node_shaper_update, + .node_parent_update = cnxk_nix_tm_node_parent_update, + .node_stats_read = cnxk_nix_tm_node_stats_read, }; int diff --git a/drivers/net/cnxk/cnxk_tm.h b/drivers/net/cnxk/cnxk_tm.h index f7470c2634..419c551bcb 100644 --- a/drivers/net/cnxk/cnxk_tm.h +++ b/drivers/net/cnxk/cnxk_tm.h @@ -15,4 +15,9 @@ struct cnxk_nix_tm_node { struct rte_tm_node_params params; }; +struct cnxk_nix_tm_shaper_profile { + struct roc_nix_tm_shaper_profile profile; + struct rte_tm_shaper_params params; /* Rate in bits/sec */ +}; + #endif /* __CNXK_TM_H__ */ -- 2.25.1