From patchwork Sat Sep 18 14:31:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Satha Koteswara Rao Kottidi X-Patchwork-Id: 99294 X-Patchwork-Delegate: jerinj@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EEE64A0C45; Sat, 18 Sep 2021 16:33:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 69BA24111E; Sat, 18 Sep 2021 16:32:37 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id B77C6410ED for ; Sat, 18 Sep 2021 16:32:32 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18IBJPZl000487 for ; Sat, 18 Sep 2021 07:32:32 -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=yuF1tGq//K9Xoqg4a/vTx0w5NrOyPH/+f4t2iMszw1Q=; b=BghiGLWqOI45tZghgMXZ/3Ynlcpj0NashITkyOMhfVX3q+uNBGxcWkzdqCFOddT/I0Jt FKHp0PCYz5xYkM1TAlhe91ZKomsFDnCzYTcAxkV7zKL5Wg2IvMOSODTEdCzKg8p0MtFF LYY/o8AkNlR0D+CKauDNldJ4yPxRA279NKs1VSZushlfenTCqyrdOr3CNBv6pUPiUxWG aHsKcrK9GcKFvlnDjtnh+gM9PfLJo1xBL3eI97Ct+vIi/XUuMm4M5waVnOXSVxwxTX/Q QMpWYCRJ/w3tsPPGSGMiZrzHWnQwG3j8cK4fgcKXCf5mmFxtUZJVeqIsDCDkqbp0zClK KA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3b5dfp0hpn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 18 Sep 2021 07:32:31 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 18 Sep 2021 07:32:29 -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; Sat, 18 Sep 2021 07:32:29 -0700 Received: from cavium.marvell.com (unknown [10.28.34.244]) by maili.marvell.com (Postfix) with ESMTP id 87B183F7057; Sat, 18 Sep 2021 07:32:28 -0700 (PDT) From: To: Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao CC: Date: Sat, 18 Sep 2021 10:31:58 -0400 Message-ID: <1631975519-30924-9-git-send-email-skoteshwar@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1631975519-30924-1-git-send-email-skoteshwar@marvell.com> References: <1630516236-10526-1-git-send-email-skoteshwar@marvell.com> <1631975519-30924-1-git-send-email-skoteshwar@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 3ZfGLEZ-XRLiF8X0e_eI6F1TcNIicmX7 X-Proofpoint-GUID: 3ZfGLEZ-XRLiF8X0e_eI6F1TcNIicmX7 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-18_05,2021-09-17_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH v2 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 --- 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 df4ffc3..36b1f65 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -85,6 +85,7 @@ New Features * **Updated Marvell cnxk ethdev driver.** * Added rte_flow support for dual VLAN insert and strip actions + * Added rte_tm support * **Added multi-process support for testpmd.** diff --git a/drivers/net/cnxk/cnxk_tm.c b/drivers/net/cnxk/cnxk_tm.c index 87fd8be..9015a45 100644 --- a/drivers/net/cnxk/cnxk_tm.c +++ b/drivers/net/cnxk/cnxk_tm.c @@ -259,11 +259,364 @@ 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 f7470c2..419c551 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__ */