get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/44215/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 44215,
    "url": "http://patches.dpdk.org/api/patches/44215/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1536045016-32008-7-git-send-email-tdu@semihalf.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1536045016-32008-7-git-send-email-tdu@semihalf.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1536045016-32008-7-git-send-email-tdu@semihalf.com",
    "date": "2018-09-04T07:10:14",
    "name": "[6/8] net/mvpp2: add traffic manager support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "46aade5023429c696fbe769f6b82b4e860ff7598",
    "submitter": {
        "id": 846,
        "url": "http://patches.dpdk.org/api/people/846/?format=api",
        "name": "Tomasz Duszynski",
        "email": "tdu@semihalf.com"
    },
    "delegate": {
        "id": 319,
        "url": "http://patches.dpdk.org/api/users/319/?format=api",
        "username": "fyigit",
        "first_name": "Ferruh",
        "last_name": "Yigit",
        "email": "ferruh.yigit@amd.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1536045016-32008-7-git-send-email-tdu@semihalf.com/mbox/",
    "series": [
        {
            "id": 1165,
            "url": "http://patches.dpdk.org/api/series/1165/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1165",
            "date": "2018-09-04T07:10:08",
            "name": "net/mvpp2: add new features",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/1165/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/44215/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/44215/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 990B9325F;\n\tTue,  4 Sep 2018 09:10:48 +0200 (CEST)",
            "from mail-pg1-f194.google.com (mail-pg1-f194.google.com\n\t[209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 20584325F\n\tfor <dev@dpdk.org>; Tue,  4 Sep 2018 09:10:46 +0200 (CEST)",
            "by mail-pg1-f194.google.com with SMTP id s15-v6so1193266pgv.8\n\tfor <dev@dpdk.org>; Tue, 04 Sep 2018 00:10:46 -0700 (PDT)",
            "from sh.semihalf.local (31-172-191-173.noc.fibertech.net.pl.\n\t[31.172.191.173]) by smtp.gmail.com with ESMTPSA id\n\tl79-v6sm31229451pfb.111.2018.09.04.00.10.42\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tTue, 04 Sep 2018 00:10:44 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=semihalf-com.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=fIafgEIxECBIfJTho83JgbTda30Dmxn9ZApXp0Z/VFc=;\n\tb=Sm0TRnQlq/OzYaPdUYBo9yrEX8PQAPQMLnFXoR8VN9cPPYDQJEbx2zQQ2Ihmp2XAJb\n\tjg2GMjgzZj3H2aY1sKfrcvvVBOo1cWlmbbM2V7wSUPybC3lHMibL7nG0jRh8HE84+8QA\n\tXdMuvML0G+jAEcfNUIJxpMiSOdtCSLPWUax/pjyOxL7hyA3flfBTpJJfN99S9FIWmxQT\n\tifad8lU0vq7CAAl35d/oNsSZ6kupKceXnlAi4eGF7QS8ZnF2KWFRo6Lk8lm8JGR2KcIy\n\tJu32/JJfvW608q2F3jq4GzQO9vpVioAncgAXPMQo+0acOPFzh4NsFL/w1PJ4Q/IQ6qAx\n\tf0jg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=fIafgEIxECBIfJTho83JgbTda30Dmxn9ZApXp0Z/VFc=;\n\tb=C+zH+5WCnRbbbxqkSzvsUCjA7Su0bkhjnDdcTW8uGNx79nnNGZtW0Eg1OrZF9pcGWv\n\tJO59EEDazHWan/WNwnx/54Th3Cc+fT56VyXlsNe0ocASDy937GYGAJRReYafuRSRxpAY\n\t2e4ySObeswhWiEmPZbE4jDtOzQ/hFBlaPufgMa8HtcsJ59v6Wy4YRZIq5Xjpj00MbUFS\n\t3QyXwzZc8VuGfVEi+8gpMOvpc8zorEwJq+Cbms1tbkmfQ1VcwLaz0SUMYZVDnUYTV9tE\n\tqrkd/k6DBONE/sl3oLOKM+JY02W5Vw5vkSIgPDAYDYM5KFp2w4krxelcIQh3a4GI/UfL\n\t0wNQ==",
        "X-Gm-Message-State": "APzg51AMX9TzUvDvZN41tOk8EYtB7N8GFQVCxWVBXRB0OoGtTV8iM7n7\n\tR+RzoBYuKPg+ExrW+KP//vVEhcNkdL53cA==",
        "X-Google-Smtp-Source": "ANB0VdannODrVCEGjBC/TJYdHFGo7nhuxBYlMD4oVjzvkFAOtizYHMgbox8OC0wSyXiaCVqCewdLWw==",
        "X-Received": "by 2002:a63:60c1:: with SMTP id\n\tu184-v6mr30032416pgb.266.1536045045275; \n\tTue, 04 Sep 2018 00:10:45 -0700 (PDT)",
        "From": "Tomasz Duszynski <tdu@semihalf.com>",
        "To": "dev@dpdk.org",
        "Cc": "nsamsono@marvell.com, mw@semihalf.com,\n\tTomasz Duszynski <tdu@semihalf.com>",
        "Date": "Tue,  4 Sep 2018 09:10:14 +0200",
        "Message-Id": "<1536045016-32008-7-git-send-email-tdu@semihalf.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1536045016-32008-1-git-send-email-tdu@semihalf.com>",
        "References": "<1536045016-32008-1-git-send-email-tdu@semihalf.com>",
        "Subject": "[dpdk-dev] [PATCH 6/8] net/mvpp2: add traffic manager support",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Add traffic manager support.\n\nSigned-off-by: Tomasz Duszynski <tdu@semihalf.com>\nSigned-off-by: Natalie Samsonov <nsamsono@marvell.com>\nReviewed-by: Liron Himi <lironh@marvell.com>\n---\n drivers/net/mvpp2/Makefile      |    1 +\n drivers/net/mvpp2/meson.build   |    3 +-\n drivers/net/mvpp2/mrvl_ethdev.c |   26 +\n drivers/net/mvpp2/mrvl_ethdev.h |   31 ++\n drivers/net/mvpp2/mrvl_tm.c     | 1009 +++++++++++++++++++++++++++++++++++++++\n drivers/net/mvpp2/mrvl_tm.h     |   15 +\n 6 files changed, 1084 insertions(+), 1 deletion(-)\n create mode 100644 drivers/net/mvpp2/mrvl_tm.c\n create mode 100644 drivers/net/mvpp2/mrvl_tm.h",
    "diff": "diff --git a/drivers/net/mvpp2/Makefile b/drivers/net/mvpp2/Makefile\nindex 4848d65..661d2cd 100644\n--- a/drivers/net/mvpp2/Makefile\n+++ b/drivers/net/mvpp2/Makefile\n@@ -40,5 +40,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_MVPP2_PMD) += mrvl_ethdev.c\n SRCS-$(CONFIG_RTE_LIBRTE_MVPP2_PMD) += mrvl_qos.c\n SRCS-$(CONFIG_RTE_LIBRTE_MVPP2_PMD) += mrvl_flow.c\n SRCS-$(CONFIG_RTE_LIBRTE_MVPP2_PMD) += mrvl_mtr.c\n+SRCS-$(CONFIG_RTE_LIBRTE_MVPP2_PMD) += mrvl_tm.c\n \n include $(RTE_SDK)/mk/rte.lib.mk\ndiff --git a/drivers/net/mvpp2/meson.build b/drivers/net/mvpp2/meson.build\nindex f475511..70ef2d6 100644\n--- a/drivers/net/mvpp2/meson.build\n+++ b/drivers/net/mvpp2/meson.build\n@@ -20,7 +20,8 @@ sources = files(\n \t'mrvl_ethdev.c',\n \t'mrvl_flow.c',\n \t'mrvl_qos.c',\n-\t'mrvl_mtr.c'\n+\t'mrvl_mtr.c',\n+\t'mrvl_tm.c'\n )\n \n deps += ['cfgfile', 'common_mvep']\ndiff --git a/drivers/net/mvpp2/mrvl_ethdev.c b/drivers/net/mvpp2/mrvl_ethdev.c\nindex 5e3a106..a1dc6b1 100644\n--- a/drivers/net/mvpp2/mrvl_ethdev.c\n+++ b/drivers/net/mvpp2/mrvl_ethdev.c\n@@ -25,6 +25,7 @@\n #include \"mrvl_qos.h\"\n #include \"mrvl_flow.h\"\n #include \"mrvl_mtr.h\"\n+#include \"mrvl_tm.h\"\n \n /* bitmask with reserved hifs */\n #define MRVL_MUSDK_HIFS_RESERVED 0x0F\n@@ -340,6 +341,10 @@ mrvl_dev_configure(struct rte_eth_dev *dev)\n \tpriv->ppio_params.maintain_stats = 1;\n \tpriv->nb_rx_queues = dev->data->nb_rx_queues;\n \n+\tret = mrvl_tm_init(dev);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n \tif (dev->data->nb_rx_queues == 1 &&\n \t    dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {\n \t\tMRVL_LOG(WARNING, \"Disabling hash for 1 rx queue\");\n@@ -794,6 +799,7 @@ mrvl_dev_close(struct rte_eth_dev *dev)\n \t}\n \n \tmrvl_flush_bpool(dev);\n+\tmrvl_tm_deinit(dev);\n \n \tif (priv->ppio) {\n \t\tpp2_ppio_deinit(priv->ppio);\n@@ -1894,6 +1900,25 @@ mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)\n \treturn 0;\n }\n \n+/**\n+ * DPDK callback to get rte_tm callbacks.\n+ *\n+ * @param dev\n+ *   Pointer to the device structure.\n+ * @param ops\n+ *   Pointer to pass the tm ops.\n+ *\n+ * @return\n+ *   Always 0.\n+ */\n+static int\n+mrvl_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)\n+{\n+\t*(const void **)ops = &mrvl_tm_ops;\n+\n+\treturn 0;\n+}\n+\n static const struct eth_dev_ops mrvl_ops = {\n \t.dev_configure = mrvl_dev_configure,\n \t.dev_start = mrvl_dev_start,\n@@ -1932,6 +1957,7 @@ static const struct eth_dev_ops mrvl_ops = {\n \t.rss_hash_conf_get = mrvl_rss_hash_conf_get,\n \t.filter_ctrl = mrvl_eth_filter_ctrl,\n \t.mtr_ops_get = mrvl_mtr_ops_get,\n+\t.tm_ops_get = mrvl_tm_ops_get,\n };\n \n /**\ndiff --git a/drivers/net/mvpp2/mrvl_ethdev.h b/drivers/net/mvpp2/mrvl_ethdev.h\nindex de423a9..984f31e 100644\n--- a/drivers/net/mvpp2/mrvl_ethdev.h\n+++ b/drivers/net/mvpp2/mrvl_ethdev.h\n@@ -10,6 +10,7 @@\n #include <rte_spinlock.h>\n #include <rte_flow_driver.h>\n #include <rte_mtr_driver.h>\n+#include <rte_tm_driver.h>\n \n /*\n  * container_of is defined by both DPDK and MUSDK,\n@@ -134,6 +135,29 @@ struct mrvl_mtr {\n \tstruct pp2_cls_plcr *plcr;\n };\n \n+struct mrvl_tm_shaper_profile {\n+\tLIST_ENTRY(mrvl_tm_shaper_profile) next;\n+\tuint32_t id;\n+\tint refcnt;\n+\tstruct rte_tm_shaper_params params;\n+};\n+\n+enum {\n+\tMRVL_NODE_PORT,\n+\tMRVL_NODE_QUEUE,\n+};\n+\n+struct mrvl_tm_node {\n+\tLIST_ENTRY(mrvl_tm_node) next;\n+\tuint32_t id;\n+\tuint32_t type;\n+\tint refcnt;\n+\tstruct mrvl_tm_node *parent;\n+\tstruct mrvl_tm_shaper_profile *profile;\n+\tuint8_t weight;\n+\tuint64_t stats_mask;\n+};\n+\n struct mrvl_priv {\n \t/* Hot fields, used in fast path. */\n \tstruct pp2_bpool *bpool;  /**< BPool pointer */\n@@ -173,6 +197,10 @@ struct mrvl_priv {\n \tLIST_HEAD(profiles, mrvl_mtr_profile) profiles;\n \tLIST_HEAD(mtrs, mrvl_mtr) mtrs;\n \tuint32_t used_plcrs;\n+\n+\tLIST_HEAD(shaper_profiles, mrvl_tm_shaper_profile) shaper_profiles;\n+\tLIST_HEAD(nodes, mrvl_tm_node) nodes;\n+\tuint64_t rate_max;\n };\n \n /** Flow operations forward declaration. */\n@@ -181,6 +209,9 @@ extern const struct rte_flow_ops mrvl_flow_ops;\n /** Meter operations forward declaration. */\n extern const struct rte_mtr_ops mrvl_mtr_ops;\n \n+/** Traffic manager operations forward declaration. */\n+extern const struct rte_tm_ops mrvl_tm_ops;\n+\n /** Current log type. */\n extern int mrvl_logtype;\n \ndiff --git a/drivers/net/mvpp2/mrvl_tm.c b/drivers/net/mvpp2/mrvl_tm.c\nnew file mode 100644\nindex 0000000..3de8997\n--- /dev/null\n+++ b/drivers/net/mvpp2/mrvl_tm.c\n@@ -0,0 +1,1009 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018 Marvell International Ltd.\n+ * Copyright(c) 2018 Semihalf.\n+ * All rights reserved.\n+ */\n+\n+#include <rte_malloc.h>\n+\n+#include <linux/ethtool.h>\n+#include <linux/sockios.h>\n+#include <net/if.h>\n+#include <sys/ioctl.h>\n+\n+#include \"mrvl_tm.h\"\n+\n+/** Minimum rate value in Bytes/s */\n+#define MRVL_RATE_MIN (PP2_PPIO_MIN_CIR * 1000 / 8)\n+\n+/** Minimum burst size in Bytes */\n+#define MRVL_BURST_MIN (PP2_PPIO_MIN_CBS * 1000)\n+\n+/** Maximum burst size in Bytes */\n+#define MRVL_BURST_MAX 256000000\n+\n+/** Maximum WRR weight */\n+#define MRVL_WEIGHT_MAX 255\n+\n+/**\n+ * Get maximum port rate in Bytes/s.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param rate Pointer to the rate.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_get_max_rate(struct rte_eth_dev *dev, uint64_t *rate)\n+{\n+\tstruct ethtool_cmd edata;\n+\tstruct ifreq req;\n+\tint ret, fd;\n+\n+\tmemset(&edata, 0, sizeof(edata));\n+\tmemset(&req, 0, sizeof(req));\n+\tedata.cmd = ETHTOOL_GSET;\n+\tstrcpy(req.ifr_name, dev->data->name);\n+\treq.ifr_data = (void *)&edata;\n+\n+\tfd = socket(AF_INET, SOCK_DGRAM, 0);\n+\tif (fd == -1)\n+\t\treturn -1;\n+\n+\tret = ioctl(fd, SIOCETHTOOL, &req);\n+\tif (ret == -1) {\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\tclose(fd);\n+\n+\t*rate = ethtool_cmd_speed(&edata) * 1000 * 1000 / 8;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Initialize traffic manager related data.\n+ *\n+ * @param dev Pointer to the device.\n+ * @returns 0 on success, failure otherwise.\n+ */\n+int\n+mrvl_tm_init(struct rte_eth_dev *dev)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\n+\tLIST_INIT(&priv->shaper_profiles);\n+\tLIST_INIT(&priv->nodes);\n+\n+\tif (priv->rate_max)\n+\t\treturn 0;\n+\n+\treturn mrvl_get_max_rate(dev, &priv->rate_max);\n+}\n+\n+/**\n+ * Cleanup traffic manager related data.\n+ *\n+ * @param dev Pointer to the device.\n+ */\n+void mrvl_tm_deinit(struct rte_eth_dev *dev)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_shaper_profile *profile =\n+\t\tLIST_FIRST(&priv->shaper_profiles);\n+\tstruct mrvl_tm_node *node = LIST_FIRST(&priv->nodes);\n+\n+\twhile (profile) {\n+\t\tstruct mrvl_tm_shaper_profile *next = LIST_NEXT(profile, next);\n+\n+\t\tLIST_REMOVE(profile, next);\n+\t\trte_free(profile);\n+\t\tprofile = next;\n+\t}\n+\n+\twhile (node) {\n+\t\tstruct mrvl_tm_node *next = LIST_NEXT(node, next);\n+\n+\t\tLIST_REMOVE(node, next);\n+\t\trte_free(node);\n+\t\tnode = next;\n+\t}\n+}\n+\n+/**\n+ * Get node using its id.\n+ *\n+ * @param priv Pointer to the port's private data.\n+ * @param node_id Id used by this node.\n+ * @returns Pointer to the node if exists, NULL otherwise.\n+ */\n+static struct mrvl_tm_node *\n+mrvl_node_from_id(struct mrvl_priv *priv, uint32_t node_id)\n+{\n+\tstruct mrvl_tm_node *node;\n+\n+\tLIST_FOREACH(node, &priv->nodes, next)\n+\t\tif (node->id == node_id)\n+\t\t\treturn node;\n+\n+\treturn NULL;\n+}\n+\n+/**\n+ * Check whether node is leaf or root.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id used by this node.\n+ * @param is_leaf Pointer to flag indicating whether node is a leaf.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_type_get(struct rte_eth_dev *dev, uint32_t node_id, int *is_leaf,\n+\t\t   struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node;\n+\n+\tif (!is_leaf)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, NULL);\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id does not exist\\n\");\n+\n+\t*is_leaf = node->type == MRVL_NODE_QUEUE ? 1 : 0;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Get traffic manager capabilities.\n+ *\n+ * @param dev Pointer to the device (unused).\n+ * @param cap Pointer to the capabilities.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_capabilities_get(struct rte_eth_dev *dev,\n+\t\t      struct rte_tm_capabilities *cap,\n+\t\t      struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\n+\tif (!cap)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, \"Capabilities are missing\\n\");\n+\n+\tmemset(cap, 0, sizeof(*cap));\n+\n+\tcap->n_nodes_max = 1 + dev->data->nb_tx_queues; /* port + txqs number */\n+\tcap->n_levels_max = 2; /* port level + txqs level */\n+\tcap->non_leaf_nodes_identical = 1;\n+\tcap->leaf_nodes_identical = 1;\n+\n+\tcap->shaper_n_max = cap->n_nodes_max;\n+\tcap->shaper_private_n_max = cap->shaper_n_max;\n+\tcap->shaper_private_rate_min = MRVL_RATE_MIN;\n+\tcap->shaper_private_rate_max = priv->rate_max;\n+\n+\tcap->sched_n_children_max = dev->data->nb_tx_queues;\n+\tcap->sched_sp_n_priorities_max = dev->data->nb_tx_queues;\n+\tcap->sched_wfq_n_children_per_group_max = dev->data->nb_tx_queues;\n+\tcap->sched_wfq_n_groups_max = 1;\n+\tcap->sched_wfq_weight_max = MRVL_WEIGHT_MAX;\n+\n+\tcap->dynamic_update_mask = RTE_TM_UPDATE_NODE_SUSPEND_RESUME |\n+\t\t\t\t   RTE_TM_UPDATE_NODE_STATS;\n+\tcap->stats_mask = RTE_TM_STATS_N_PKTS | RTE_TM_STATS_N_BYTES;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Get traffic manager hierarchy level capabilities.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param level_id Id of the level.\n+ * @param cap Pointer to the level capabilities.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_level_capabilities_get(struct rte_eth_dev *dev,\n+\t\t\t    uint32_t level_id,\n+\t\t\t    struct rte_tm_level_capabilities *cap,\n+\t\t\t    struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\n+\tif (!cap)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, NULL);\n+\n+\tmemset(cap, 0, sizeof(*cap));\n+\n+\tif (level_id != MRVL_NODE_PORT && level_id != MRVL_NODE_QUEUE)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_LEVEL_ID,\n+\t\t\t\t\t NULL, \"Wrong level id\\n\");\n+\n+\tif (level_id == MRVL_NODE_PORT) {\n+\t\tcap->n_nodes_max = 1;\n+\t\tcap->n_nodes_nonleaf_max = 1;\n+\t\tcap->non_leaf_nodes_identical = 1;\n+\n+\t\tcap->nonleaf.shaper_private_supported = 1;\n+\t\tcap->nonleaf.shaper_private_rate_min = MRVL_RATE_MIN;\n+\t\tcap->nonleaf.shaper_private_rate_max = priv->rate_max;\n+\n+\t\tcap->nonleaf.sched_n_children_max = dev->data->nb_tx_queues;\n+\t\tcap->nonleaf.sched_sp_n_priorities_max = 1;\n+\t\tcap->nonleaf.sched_wfq_n_children_per_group_max =\n+\t\t\tdev->data->nb_tx_queues;\n+\t\tcap->nonleaf.sched_wfq_n_groups_max = 1;\n+\t\tcap->nonleaf.sched_wfq_weight_max = MRVL_WEIGHT_MAX;\n+\t\tcap->nonleaf.stats_mask = RTE_TM_STATS_N_PKTS |\n+\t\t\t\t\t  RTE_TM_STATS_N_BYTES;\n+\t} else { /* level_id == MRVL_NODE_QUEUE */\n+\t\tcap->n_nodes_max = dev->data->nb_tx_queues;\n+\t\tcap->n_nodes_leaf_max = dev->data->nb_tx_queues;\n+\t\tcap->leaf_nodes_identical = 1;\n+\n+\t\tcap->leaf.shaper_private_supported = 1;\n+\t\tcap->leaf.shaper_private_rate_min = MRVL_RATE_MIN;\n+\t\tcap->leaf.shaper_private_rate_max = priv->rate_max;\n+\t\tcap->leaf.stats_mask = RTE_TM_STATS_N_PKTS;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Get node capabilities.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id of the node.\n+ * @param cap Pointer to the capabilities.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_capabilities_get(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t\t   struct rte_tm_node_capabilities *cap,\n+\t\t\t   struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node;\n+\n+\tif (!cap)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, NULL);\n+\n+\tmemset(cap, 0, sizeof(*cap));\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id does not exist\\n\");\n+\n+\tcap->shaper_private_supported = 1;\n+\tcap->shaper_private_rate_min = MRVL_RATE_MIN;\n+\tcap->shaper_private_rate_max = priv->rate_max;\n+\n+\tif (node->type == MRVL_NODE_PORT) {\n+\t\tcap->nonleaf.sched_n_children_max = dev->data->nb_tx_queues;\n+\t\tcap->nonleaf.sched_sp_n_priorities_max = 1;\n+\t\tcap->nonleaf.sched_wfq_n_children_per_group_max =\n+\t\t\tdev->data->nb_tx_queues;\n+\t\tcap->nonleaf.sched_wfq_n_groups_max = 1;\n+\t\tcap->nonleaf.sched_wfq_weight_max = MRVL_WEIGHT_MAX;\n+\t\tcap->stats_mask = RTE_TM_STATS_N_PKTS | RTE_TM_STATS_N_BYTES;\n+\t} else {\n+\t\tcap->stats_mask = RTE_TM_STATS_N_PKTS;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Get shaper profile using its id.\n+ *\n+ * @param priv Pointer to the port's private data.\n+ * @param shaper_profile_id Id used by the shaper.\n+ * @returns Pointer to the shaper profile if exists, NULL otherwise.\n+ */\n+static struct mrvl_tm_shaper_profile *\n+mrvl_shaper_profile_from_id(struct mrvl_priv *priv, uint32_t shaper_profile_id)\n+{\n+\tstruct mrvl_tm_shaper_profile *profile;\n+\n+\tLIST_FOREACH(profile, &priv->shaper_profiles, next)\n+\t\tif (profile->id == shaper_profile_id)\n+\t\t\treturn profile;\n+\n+\treturn NULL;\n+}\n+\n+/**\n+ * Add a new shaper profile.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param shaper_profile_id Id of the new profile.\n+ * @param params Pointer to the shaper profile parameters.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_shaper_profile_add(struct rte_eth_dev *dev, uint32_t shaper_profile_id,\n+\t\t\tstruct rte_tm_shaper_params *params,\n+\t\t\tstruct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_shaper_profile *profile;\n+\n+\tif (!params)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, NULL);\n+\n+\tif (params->committed.rate)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE,\n+\t\t\t\tNULL, \"Committed rate not supported\\n\");\n+\n+\tif (params->committed.size)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE,\n+\t\t\t\tNULL, \"Committed bucket size not supported\\n\");\n+\n+\tif (params->peak.rate < MRVL_RATE_MIN ||\n+\t    params->peak.rate > priv->rate_max)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE,\n+\t\t\t\tNULL, \"Peak rate is out of range\\n\");\n+\n+\tif (params->peak.size < MRVL_BURST_MIN ||\n+\t    params->peak.size > MRVL_BURST_MAX)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE,\n+\t\t\t\tNULL, \"Peak size is out of range\\n\");\n+\n+\tif (shaper_profile_id == RTE_TM_SHAPER_PROFILE_ID_NONE)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,\n+\t\t\t\t\t NULL, \"Wrong shaper profile id\\n\");\n+\n+\tprofile = mrvl_shaper_profile_from_id(priv, shaper_profile_id);\n+\tif (profile)\n+\t\treturn -rte_tm_error_set(error, EEXIST,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,\n+\t\t\t\t\t NULL, \"Profile id already exists\\n\");\n+\n+\tprofile = rte_zmalloc_socket(NULL, sizeof(*profile), 0,\n+\t\t\t\t     rte_socket_id());\n+\tif (!profile)\n+\t\treturn -rte_tm_error_set(error, ENOMEM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, NULL);\n+\n+\tprofile->id = shaper_profile_id;\n+\trte_memcpy(&profile->params, params, sizeof(profile->params));\n+\n+\tLIST_INSERT_HEAD(&priv->shaper_profiles, profile, next);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Remove a shaper profile.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param shaper_profile_id Id of the shaper profile.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_shaper_profile_delete(struct rte_eth_dev *dev, uint32_t shaper_profile_id,\n+\t\t\t   struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_shaper_profile *profile;\n+\n+\tprofile = mrvl_shaper_profile_from_id(priv, shaper_profile_id);\n+\tif (!profile)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,\n+\t\t\t\t\t NULL, \"Profile id does not exist\\n\");\n+\n+\tif (profile->refcnt)\n+\t\treturn -rte_tm_error_set(error, EPERM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,\n+\t\t\t\t\t NULL, \"Profile is used\\n\");\n+\n+\tLIST_REMOVE(profile, next);\n+\trte_free(profile);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Check node parameters.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id used by the node.\n+ * @param priority Priority value.\n+ * @param weight Weight value.\n+ * @param level_id Id of the level.\n+ * @param params Pointer to the node parameters.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_check_params(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t       uint32_t priority, uint32_t weight, uint32_t level_id,\n+\t\t       struct rte_tm_node_params *params,\n+\t\t       struct rte_tm_error *error)\n+{\n+\tif (node_id == RTE_TM_NODE_ID_NULL)\n+\t\treturn -rte_tm_error_set(error, EINVAL, RTE_TM_NODE_ID_NULL,\n+\t\t\t\t\t NULL, \"Node id is invalid\\n\");\n+\n+\tif (priority)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_PRIORITY,\n+\t\t\t\t\t NULL, \"Priority should be 0\\n\");\n+\n+\tif (weight > MRVL_WEIGHT_MAX)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_WEIGHT,\n+\t\t\t\t\t NULL, \"Weight is out of range\\n\");\n+\n+\tif (level_id != MRVL_NODE_PORT && level_id != MRVL_NODE_QUEUE)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_LEVEL_ID,\n+\t\t\t\t\t NULL, \"Wrong level id\\n\");\n+\n+\tif (!params)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, NULL);\n+\n+\tif (params->shared_shaper_id)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID,\n+\t\t\t\tNULL, \"Shared shaper is not supported\\n\");\n+\n+\tif (params->n_shared_shapers)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS,\n+\t\t\t\tNULL, \"Shared shaper is not supported\\n\");\n+\n+\t/* verify port (root node) settings */\n+\tif (node_id >= dev->data->nb_tx_queues) {\n+\t\tif (params->nonleaf.wfq_weight_mode)\n+\t\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE,\n+\t\t\t\tNULL, \"WFQ is not supported\\n\");\n+\n+\t\tif (params->nonleaf.n_sp_priorities != 1)\n+\t\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES,\n+\t\t\t\tNULL, \"SP is not supported\\n\");\n+\n+\t\tif (params->stats_mask & ~(RTE_TM_STATS_N_PKTS |\n+\t\t\t\t\t   RTE_TM_STATS_N_BYTES))\n+\t\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,\n+\t\t\t\tNULL,\n+\t\t\t\t\"Requested port stats are not supported\\n\");\n+\n+\t\treturn 0;\n+\t}\n+\n+\t/* verify txq (leaf node) settings */\n+\tif (params->leaf.cman)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN,\n+\t\t\t\t\t NULL,\n+\t\t\t\t\t \"Congestion mngmt is not supported\\n\");\n+\n+\tif (params->leaf.wred.wred_profile_id)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID,\n+\t\t\t\tNULL, \"WRED is not supported\\n\");\n+\n+\tif (params->leaf.wred.shared_wred_context_id)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID,\n+\t\t\tNULL, \"WRED is not supported\\n\");\n+\n+\tif (params->leaf.wred.n_shared_wred_contexts)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS,\n+\t\t\tNULL, \"WRED is not supported\\n\");\n+\n+\tif (params->stats_mask & ~RTE_TM_STATS_N_PKTS)\n+\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,\n+\t\t\tNULL,\n+\t\t\t\"Requested txq stats are not supported\\n\");\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Add a new node.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id of the node.\n+ * @param parent_node_id Id of the parent node.\n+ * @param priority Priority value.\n+ * @param weight Weight value.\n+ * @param level_id Id of the level.\n+ * @param params Pointer to the node parameters.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_add(struct rte_eth_dev *dev, uint32_t node_id,\n+\t      uint32_t parent_node_id, uint32_t priority, uint32_t weight,\n+\t      uint32_t level_id, struct rte_tm_node_params *params,\n+\t      struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_shaper_profile *profile = NULL;\n+\tstruct mrvl_tm_node *node, *parent = NULL;\n+\tint ret;\n+\n+\tif (priv->ppio)\n+\t\treturn -rte_tm_error_set(error, EPERM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, \"Port is already started\\n\");\n+\n+\tret = mrvl_node_check_params(dev, node_id, priority, weight, level_id,\n+\t\t\t\t     params, error);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (params->shaper_profile_id != RTE_TM_SHAPER_PROFILE_ID_NONE) {\n+\t\tprofile = mrvl_shaper_profile_from_id(priv,\n+\t\t\t\t\t\t params->shaper_profile_id);\n+\t\tif (!profile)\n+\t\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\tRTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID,\n+\t\t\t\t\tNULL, \"Shaper id does not exist\\n\");\n+\t}\n+\n+\tif (parent_node_id == RTE_TM_NODE_ID_NULL) {\n+\t\tLIST_FOREACH(node, &priv->nodes, next) {\n+\t\t\tif (node->type != MRVL_NODE_PORT)\n+\t\t\t\tcontinue;\n+\n+\t\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t\t NULL, \"Root node exists\\n\");\n+\t\t}\n+\t} else {\n+\t\tparent = mrvl_node_from_id(priv, parent_node_id);\n+\t\tif (!parent)\n+\t\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID,\n+\t\t\t\t\tNULL, \"Node id does not exist\\n\");\n+\t}\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id already exists\\n\");\n+\n+\tnode = rte_zmalloc_socket(NULL, sizeof(*node), 0, rte_socket_id());\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENOMEM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, NULL);\n+\n+\tnode->id = node_id;\n+\tnode->type = parent_node_id == RTE_TM_NODE_ID_NULL ? MRVL_NODE_PORT :\n+\t\t\t\t\t\t\t     MRVL_NODE_QUEUE;\n+\n+\tif (parent) {\n+\t\tnode->parent = parent;\n+\t\tparent->refcnt++;\n+\t}\n+\n+\tif (profile) {\n+\t\tnode->profile = profile;\n+\t\tprofile->refcnt++;\n+\t}\n+\n+\tnode->weight = weight;\n+\tnode->stats_mask = params->stats_mask;\n+\n+\tLIST_INSERT_HEAD(&priv->nodes, node, next);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Delete a node.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id of the node.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_delete(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node;\n+\n+\tif (priv->ppio) {\n+\t\treturn -rte_tm_error_set(error, EPERM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, \"Port is already started\\n\");\n+\t}\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id does not exist\\n\");\n+\n+\tif (node->refcnt)\n+\t\treturn -rte_tm_error_set(error, EPERM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id is used\\n\");\n+\n+\tif (node->parent)\n+\t\tnode->parent->refcnt--;\n+\n+\tif (node->profile)\n+\t\tnode->profile->refcnt--;\n+\n+\tLIST_REMOVE(node, next);\n+\trte_free(node);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Helper for suspending specific tx queue.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id used by this node.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int mrvl_node_suspend_one(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t\t\t struct rte_tm_error *error)\n+{\n+\tint ret = dev->dev_ops->tx_queue_stop(dev, node_id);\n+\tif (ret)\n+\t\treturn -rte_tm_error_set(error, ret,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, \"Failed to suspend a txq\\n\");\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Suspend a node.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id of the node.\n+ * @param error Pointer to the error.\n+ * returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_suspend(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t  struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node, *tmp;\n+\tint ret;\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id does not exist\\n\");\n+\n+\tif (!node->parent) {\n+\t\tLIST_FOREACH(tmp, &priv->nodes, next) {\n+\t\t\tif (!tmp->parent)\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (node != tmp->parent)\n+\t\t\t\tcontinue;\n+\n+\t\t\tret = mrvl_node_suspend_one(dev, tmp->id, error);\n+\t\t\tif (ret)\n+\t\t\t\treturn ret;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\treturn mrvl_node_suspend_one(dev, node_id, error);\n+}\n+\n+/**\n+ * Resume a node.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id of the node.\n+ * @param error Pointer to the error.\n+ * returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_resume(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node;\n+\tint ret;\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id does not exist\\n\");\n+\n+\n+\tif (!node->parent)\n+\t\treturn -rte_tm_error_set(error, EPERM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Cannot suspend a port\\n\");\n+\n+\tret = dev->dev_ops->tx_queue_start(dev, node_id);\n+\tif (ret)\n+\t\treturn -rte_tm_error_set(error, ret,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, \"Failed to resume a txq\\n\");\n+\treturn 0;\n+}\n+\n+/**\n+ * Apply traffic manager hierarchy.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param clear_on_fail Flag indicating whether to do cleanup on the failure.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_hierarchy_commit(struct rte_eth_dev *dev, int clear_on_fail,\n+\t\t      struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node;\n+\tint ret;\n+\n+\tif (priv->ppio) {\n+\t\tret = -rte_tm_error_set(error, EPERM,\n+\t\t\t\t\tRTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\tNULL, \"Port is already started\\n\");\n+\t\tgoto out;\n+\t}\n+\n+\tLIST_FOREACH(node, &priv->nodes, next) {\n+\t\tstruct pp2_ppio_outq_params *p;\n+\n+\t\tif (node->type == MRVL_NODE_PORT) {\n+\t\t\tif (!node->profile)\n+\t\t\t\tcontinue;\n+\n+\t\t\tpriv->ppio_params.rate_limit_enable = 1;\n+\t\t\tpriv->ppio_params.rate_limit_params.cir =\n+\t\t\t\tnode->profile->params.peak.rate * 8 / 1000;\n+\t\t\tpriv->ppio_params.rate_limit_params.cbs =\n+\t\t\t\tnode->profile->params.peak.size / 1000;\n+\n+\t\t\tMRVL_LOG(INFO,\n+\t\t\t\t\"Port rate limit overrides txqs rate limit\");\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tif (node->id >= dev->data->nb_tx_queues) {\n+\t\t\tret = -rte_tm_error_set(error, EINVAL,\n+\t\t\t\t\tRTE_TM_ERROR_TYPE_NODE_ID, NULL,\n+\t\t\t\t\t\"Not enough txqs are configured\\n\");\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tp = &priv->ppio_params.outqs_params.outqs_params[node->id];\n+\n+\t\tif (node->weight) {\n+\t\t\tp->sched_mode = PP2_PPIO_SCHED_M_WRR;\n+\t\t\tp->weight = node->weight;\n+\t\t} else {\n+\t\t\tp->sched_mode = PP2_PPIO_SCHED_M_SP;\n+\t\t\tp->weight = 0;\n+\t\t}\n+\n+\t\tif (node->profile) {\n+\t\t\tp->rate_limit_enable = 1;\n+\t\t\t/* convert Bytes/s to kilo bits/s */\n+\t\t\tp->rate_limit_params.cir =\n+\t\t\t\tnode->profile->params.peak.rate * 8 / 1000;\n+\t\t\t/* convert bits to kilo bits */\n+\t\t\tp->rate_limit_params.cbs =\n+\t\t\t\tnode->profile->params.peak.size / 1000;\n+\t\t} else {\n+\t\t\tp->rate_limit_enable = 0;\n+\t\t\tp->rate_limit_params.cir = 0;\n+\t\t\tp->rate_limit_params.cbs = 0;\n+\t\t}\n+\t}\n+\n+\t/* reset to defaults in case applied tm hierarchy is empty */\n+\tif (LIST_EMPTY(&priv->nodes)) {\n+\t\tint i;\n+\n+\t\tfor (i = 0; i < priv->ppio_params.outqs_params.num_outqs; i++) {\n+\t\t\tstruct pp2_ppio_outq_params *p =\n+\t\t\t\t&priv->ppio_params.outqs_params.outqs_params[i];\n+\n+\t\t\tp->sched_mode = PP2_PPIO_SCHED_M_WRR;\n+\t\t\tp->weight = 0;\n+\t\t\tp->rate_limit_enable = 0;\n+\t\t\tp->rate_limit_params.cir = 0;\n+\t\t\tp->rate_limit_params.cbs = 0;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+out:\n+\tif (clear_on_fail) {\n+\t\tmrvl_tm_deinit(dev);\n+\t\tmrvl_tm_init(dev);\n+\t}\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * Read statistics counters for current node.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id of the node.\n+ * @param stats Pointer to the statistics counters.\n+ * @param stats_mask Pointer to mask of enabled statistics counters\n+ *                   that are retrieved.\n+ * @param clear Flag indicating whether to clear statistics.\n+ *              Non-zero value clears statistics.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_stats_read(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t     struct rte_tm_node_stats *stats, uint64_t *stats_mask,\n+\t\t     int clear, struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node;\n+\tint ret;\n+\n+\tif (!priv->ppio) {\n+\t\treturn -rte_tm_error_set(error, EPERM,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t NULL, \"Port is not started\\n\");\n+\t}\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id does not exist\\n\");\n+\n+\tif (stats_mask)\n+\t\t*stats_mask = node->stats_mask;\n+\n+\tif (!stats)\n+\t\treturn 0;\n+\n+\tmemset(stats, 0, sizeof(*stats));\n+\n+\tif (!node->parent) {\n+\t\tstruct pp2_ppio_statistics s;\n+\n+\t\tmemset(&s, 0, sizeof(s));\n+\t\tret = pp2_ppio_get_statistics(priv->ppio, &s, clear);\n+\t\tif (ret)\n+\t\t\treturn -rte_tm_error_set(error, -ret,\n+\t\t\t\t\tRTE_TM_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t\t\"Failed to read port statistics\\n\");\n+\n+\t\tif (node->stats_mask & RTE_TM_STATS_N_PKTS)\n+\t\t\tstats->n_pkts = s.tx_packets;\n+\n+\t\tif (node->stats_mask & RTE_TM_STATS_N_BYTES)\n+\t\t\tstats->n_bytes = s.tx_bytes;\n+\t} else {\n+\t\tstruct pp2_ppio_outq_statistics s;\n+\n+\t\tmemset(&s, 0, sizeof(s));\n+\t\tret = pp2_ppio_outq_get_statistics(priv->ppio, node_id, &s,\n+\t\t\t\t\t\t   clear);\n+\t\tif (ret)\n+\t\t\treturn -rte_tm_error_set(error, -ret,\n+\t\t\t\t\tRTE_TM_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t\t\"Failed to read txq statistics\\n\");\n+\n+\t\tif (node->stats_mask & RTE_TM_STATS_N_PKTS)\n+\t\t\tstats->n_pkts = s.deq_desc;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Update node statistics.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param node_id Id of the node.\n+ * @param stats_mask Bitmask of statistics counters to be enabled.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_node_stats_update(struct rte_eth_dev *dev, uint32_t node_id,\n+\t\t       uint64_t stats_mask, struct rte_tm_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_tm_node *node;\n+\n+\tnode = mrvl_node_from_id(priv, node_id);\n+\tif (!node)\n+\t\treturn -rte_tm_error_set(error, ENODEV,\n+\t\t\t\t\t RTE_TM_ERROR_TYPE_NODE_ID,\n+\t\t\t\t\t NULL, \"Node id does not exist\\n\");\n+\n+\tif (!node->parent) {\n+\t\tif (stats_mask & ~(RTE_TM_STATS_N_PKTS | RTE_TM_STATS_N_BYTES))\n+\t\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,\n+\t\t\t\tNULL,\n+\t\t\t\t\"Requested port stats are not supported\\n\");\n+\t} else {\n+\t\tif (stats_mask & ~RTE_TM_STATS_N_PKTS)\n+\t\t\treturn -rte_tm_error_set(error, EINVAL,\n+\t\t\t\tRTE_TM_ERROR_TYPE_NODE_PARAMS_STATS,\n+\t\t\t\tNULL,\n+\t\t\t\t\"Requested txq stats are not supported\\n\");\n+\t}\n+\n+\tnode->stats_mask = stats_mask;\n+\n+\treturn 0;\n+}\n+\n+const struct rte_tm_ops mrvl_tm_ops = {\n+\t.node_type_get = mrvl_node_type_get,\n+\t.capabilities_get = mrvl_capabilities_get,\n+\t.level_capabilities_get = mrvl_level_capabilities_get,\n+\t.node_capabilities_get = mrvl_node_capabilities_get,\n+\t.shaper_profile_add = mrvl_shaper_profile_add,\n+\t.shaper_profile_delete = mrvl_shaper_profile_delete,\n+\t.node_add = mrvl_node_add,\n+\t.node_delete = mrvl_node_delete,\n+\t.node_suspend = mrvl_node_suspend,\n+\t.node_resume = mrvl_node_resume,\n+\t.hierarchy_commit = mrvl_hierarchy_commit,\n+\t.node_stats_update = mrvl_node_stats_update,\n+\t.node_stats_read = mrvl_node_stats_read,\n+};\ndiff --git a/drivers/net/mvpp2/mrvl_tm.h b/drivers/net/mvpp2/mrvl_tm.h\nnew file mode 100644\nindex 0000000..9d81ede\n--- /dev/null\n+++ b/drivers/net/mvpp2/mrvl_tm.h\n@@ -0,0 +1,15 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018 Marvell International Ltd.\n+ * Copyright(c) 2018 Semihalf.\n+ * All rights reserved.\n+ */\n+\n+#ifndef _MRVL_TM_H_\n+#define _MRVL_TM_H_\n+\n+#include \"mrvl_ethdev.h\"\n+\n+int mrvl_tm_init(struct rte_eth_dev *dev);\n+void mrvl_tm_deinit(struct rte_eth_dev *dev);\n+\n+#endif /* _MRVL_TM_H_ */\n",
    "prefixes": [
        "6/8"
    ]
}