get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 45291,
    "url": "https://patches.dpdk.org/api/patches/45291/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1537859109-25659-4-git-send-email-amo@semihalf.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<1537859109-25659-4-git-send-email-amo@semihalf.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1537859109-25659-4-git-send-email-amo@semihalf.com",
    "date": "2018-09-25T07:04:59",
    "name": "[v3,03/13] net/mvpp2: add metering support",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "e22afc864565057df5430c1460d2ec638ad1a08b",
    "submitter": {
        "id": 1112,
        "url": "https://patches.dpdk.org/api/people/1112/?format=api",
        "name": "Andrzej Ostruszka",
        "email": "amo@semihalf.com"
    },
    "delegate": {
        "id": 319,
        "url": "https://patches.dpdk.org/api/users/319/?format=api",
        "username": "fyigit",
        "first_name": "Ferruh",
        "last_name": "Yigit",
        "email": "ferruh.yigit@amd.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1537859109-25659-4-git-send-email-amo@semihalf.com/mbox/",
    "series": [
        {
            "id": 1482,
            "url": "https://patches.dpdk.org/api/series/1482/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=1482",
            "date": "2018-09-25T07:04:56",
            "name": "net/mvpp2: add new features",
            "version": 3,
            "mbox": "https://patches.dpdk.org/series/1482/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/45291/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/45291/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 580E94F90;\n\tTue, 25 Sep 2018 09:05:24 +0200 (CEST)",
            "from mail-lj1-f193.google.com (mail-lj1-f193.google.com\n\t[209.85.208.193]) by dpdk.org (Postfix) with ESMTP id BD49E4CA5\n\tfor <dev@dpdk.org>; Tue, 25 Sep 2018 09:05:15 +0200 (CEST)",
            "by mail-lj1-f193.google.com with SMTP id v9-v6so20642046ljk.4\n\tfor <dev@dpdk.org>; Tue, 25 Sep 2018 00:05:15 -0700 (PDT)",
            "from amok.semihalf.local (31-172-191-173.noc.fibertech.net.pl.\n\t[31.172.191.173]) by smtp.googlemail.com with ESMTPSA id\n\t24-v6sm238306ljb.76.2018.09.25.00.05.13\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tTue, 25 Sep 2018 00:05:13 -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=ZYw6VhfUioHFugbU+/6Wx9gYddzDerpVnUiTDOv7/Nk=;\n\tb=PrzFCYQugV0DVhuWKprT5kRujtUafDrfNXvrZXsDlGxvbYplWqjYXzd3QV+N593NaJ\n\teNxQk7uC7kfPn6vqJYkjv/xB5/l12wlDdDtpHyAFbX/r4XmWMOwotdkn0elzbp1E4LiZ\n\tz3y/yGdvzEiU0ZEZXWVyGIGi8cmfuJSimlCO0HfNDQfIiUvPZgVImYPZ9mS+ApsPwigV\n\tuyqQPbH2dwscbOXXhZswGpf0fTXzxDnOuOFjtZzwEd3FsCraO/h5bjglUycBduYd0BDQ\n\tIC4YUiUx0hYNHUIsZFDusb8hjoqkvJVRam/eueTm6xz3tc13IokhcRUgUnxBjPxT4Zgl\n\tUCeg==",
        "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=ZYw6VhfUioHFugbU+/6Wx9gYddzDerpVnUiTDOv7/Nk=;\n\tb=G9nLn/o4ox5dzDdVuCd3LPxOks7uqBd/1Hhbi5CyFOdUY2kq5Me/htpHtkkXwg4CK7\n\t1Ky/zoRBjDdgdHMyCVFzbXwsY1RLFslHsD2ejgFuVt+OH6WM45hy1U3wWEEhEvlhVZJb\n\tweUvCJwaA9dKqWB6AgIB7UaFDN3+Gvbrx1P44aDCU8uQie0+7ibrRQIdDsxIKCYq150r\n\tqbYu95ewxdxy5RiYAH78Rg+AJSDhS8tmH3wovG3eCs3PaKUnNzCwgN9wW+g1FlzZGl9T\n\t9At9CbljdXfLZaqAPDeB0doT86UTM5/jlPQVZschltAt3bz5q8YgJhfB01yVq5AJGcKQ\n\txbWA==",
        "X-Gm-Message-State": "ABuFfohVNBSAz24UkXe/o9ByBBdeNEaeI+im+4Tpak8FeH6jCzGAsaZv\n\tNJQZYykB9KPwF63dwJaKLjsEeDc7QkNoEw==",
        "X-Google-Smtp-Source": "ACcGV604Lyqdb5F7XzblRt+0yNsomtPKr1OkF7ixUibwXJXvTiDV83Y8ftYjahbHzEGiVio93gZZKQ==",
        "X-Received": "by 2002:a2e:84c6:: with SMTP id\n\tq6-v6mr1699778ljh.65.1537859114718; \n\tTue, 25 Sep 2018 00:05:14 -0700 (PDT)",
        "From": "Andrzej Ostruszka <amo@semihalf.com>",
        "To": "dev@dpdk.org",
        "Cc": "mw@semihalf.com, nadavh@marvell.com, Tomasz Duszynski <tdu@semihalf.com>,\n\tNatalie Samsonov <nsamsono@marvell.com>",
        "Date": "Tue, 25 Sep 2018 09:04:59 +0200",
        "Message-Id": "<1537859109-25659-4-git-send-email-amo@semihalf.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1537859109-25659-1-git-send-email-amo@semihalf.com>",
        "References": "<1536068953-9352-1-git-send-email-tdu@semihalf.com>\n\t<1537859109-25659-1-git-send-email-amo@semihalf.com>",
        "Subject": "[dpdk-dev] [PATCH v3 03/13] net/mvpp2: add metering 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": "From: Tomasz Duszynski <tdu@semihalf.com>\n\nAdd support for configuring plcr via DPDK generic metering API.\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 |  24 ++\n drivers/net/mvpp2/mrvl_ethdev.h |  71 ++++++\n drivers/net/mvpp2/mrvl_flow.c   |  91 +++----\n drivers/net/mvpp2/mrvl_mtr.c    | 512 ++++++++++++++++++++++++++++++++++++++++\n drivers/net/mvpp2/mrvl_mtr.h    |  15 ++\n 7 files changed, 673 insertions(+), 44 deletions(-)\n create mode 100644 drivers/net/mvpp2/mrvl_mtr.c\n create mode 100644 drivers/net/mvpp2/mrvl_mtr.h",
    "diff": "diff --git a/drivers/net/mvpp2/Makefile b/drivers/net/mvpp2/Makefile\nindex 211d398..4848d65 100644\n--- a/drivers/net/mvpp2/Makefile\n+++ b/drivers/net/mvpp2/Makefile\n@@ -39,5 +39,6 @@ LDLIBS += -lrte_bus_vdev -lrte_common_mvep\n 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 \n include $(RTE_SDK)/mk/rte.lib.mk\ndiff --git a/drivers/net/mvpp2/meson.build b/drivers/net/mvpp2/meson.build\nindex 3620659..f475511 100644\n--- a/drivers/net/mvpp2/meson.build\n+++ b/drivers/net/mvpp2/meson.build\n@@ -19,7 +19,8 @@ endif\n sources = files(\n \t'mrvl_ethdev.c',\n \t'mrvl_flow.c',\n-\t'mrvl_qos.c'\n+\t'mrvl_qos.c',\n+\t'mrvl_mtr.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 c8c8548..a6cc550 100644\n--- a/drivers/net/mvpp2/mrvl_ethdev.c\n+++ b/drivers/net/mvpp2/mrvl_ethdev.c\n@@ -23,6 +23,7 @@\n #include <rte_mvep_common.h>\n #include \"mrvl_ethdev.h\"\n #include \"mrvl_qos.h\"\n+#include \"mrvl_mtr.h\"\n \n /* bitmask with reserved hifs */\n #define MRVL_MUSDK_HIFS_RESERVED 0x0F\n@@ -618,6 +619,8 @@ mrvl_dev_start(struct rte_eth_dev *dev)\n \t\t\tgoto out;\n \t}\n \n+\tmrvl_mtr_init(dev);\n+\n \treturn 0;\n out:\n \tMRVL_LOG(ERR, \"Failed to start device\");\n@@ -756,6 +759,7 @@ mrvl_dev_close(struct rte_eth_dev *dev)\n \n \tmrvl_flush_rx_queues(dev);\n \tmrvl_flush_tx_shadow_queues(dev);\n+\tmrvl_mtr_deinit(dev);\n \n \tfor (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {\n \t\tstruct pp2_ppio_tc_params *tc_params =\n@@ -1858,6 +1862,25 @@ mrvl_eth_filter_ctrl(struct rte_eth_dev *dev __rte_unused,\n \t}\n }\n \n+/**\n+ * DPDK callback to get rte_mtr callbacks.\n+ *\n+ * @param dev\n+ *   Pointer to the device structure.\n+ * @param ops\n+ *   Pointer to pass the mtr ops.\n+ *\n+ * @return\n+ *   Always 0.\n+ */\n+static int\n+mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)\n+{\n+\t*(const void **)ops = &mrvl_mtr_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@@ -1895,6 +1918,7 @@ static const struct eth_dev_ops mrvl_ops = {\n \t.rss_hash_update = mrvl_rss_hash_update,\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 };\n \n /**\ndiff --git a/drivers/net/mvpp2/mrvl_ethdev.h b/drivers/net/mvpp2/mrvl_ethdev.h\nindex 2204be2..ecb8fdc 100644\n--- a/drivers/net/mvpp2/mrvl_ethdev.h\n+++ b/drivers/net/mvpp2/mrvl_ethdev.h\n@@ -9,6 +9,7 @@\n \n #include <rte_spinlock.h>\n #include <rte_flow_driver.h>\n+#include <rte_mtr_driver.h>\n \n /*\n  * container_of is defined by both DPDK and MUSDK,\n@@ -70,6 +71,69 @@\n /** Minimum number of sent buffers to release from shadow queue to BM */\n #define MRVL_PP2_BUF_RELEASE_BURST_SIZE\t64\n \n+/** Maximum length of a match string */\n+#define MRVL_MATCH_LEN 16\n+\n+/** Parsed fields in processed rte_flow_item. */\n+enum mrvl_parsed_fields {\n+\t/* eth flags */\n+\tF_DMAC =         BIT(0),\n+\tF_SMAC =         BIT(1),\n+\tF_TYPE =         BIT(2),\n+\t/* vlan flags */\n+\tF_VLAN_PRI =     BIT(3),\n+\tF_VLAN_ID =      BIT(4),\n+\tF_VLAN_TCI =     BIT(5), /* not supported by MUSDK yet */\n+\t/* ip4 flags */\n+\tF_IP4_TOS =      BIT(6),\n+\tF_IP4_SIP =      BIT(7),\n+\tF_IP4_DIP =      BIT(8),\n+\tF_IP4_PROTO =    BIT(9),\n+\t/* ip6 flags */\n+\tF_IP6_TC =       BIT(10), /* not supported by MUSDK yet */\n+\tF_IP6_SIP =      BIT(11),\n+\tF_IP6_DIP =      BIT(12),\n+\tF_IP6_FLOW =     BIT(13),\n+\tF_IP6_NEXT_HDR = BIT(14),\n+\t/* tcp flags */\n+\tF_TCP_SPORT =    BIT(15),\n+\tF_TCP_DPORT =    BIT(16),\n+\t/* udp flags */\n+\tF_UDP_SPORT =    BIT(17),\n+\tF_UDP_DPORT =    BIT(18),\n+};\n+\n+/** PMD-specific definition of a flow rule handle. */\n+struct mrvl_mtr;\n+struct rte_flow {\n+\tLIST_ENTRY(rte_flow) next;\n+\tstruct mrvl_mtr *mtr;\n+\n+\tenum mrvl_parsed_fields pattern;\n+\n+\tstruct pp2_cls_tbl_rule rule;\n+\tstruct pp2_cls_cos_desc cos;\n+\tstruct pp2_cls_tbl_action action;\n+};\n+\n+struct mrvl_mtr_profile {\n+\tLIST_ENTRY(mrvl_mtr_profile) next;\n+\tuint32_t profile_id;\n+\tint refcnt;\n+\tstruct rte_mtr_meter_profile profile;\n+};\n+\n+struct mrvl_mtr {\n+\tLIST_ENTRY(mrvl_mtr) next;\n+\tuint32_t mtr_id;\n+\tint refcnt;\n+\tint shared;\n+\tint enabled;\n+\tint plcr_bit;\n+\tstruct mrvl_mtr_profile *profile;\n+\tstruct pp2_cls_plcr *plcr;\n+};\n+\n struct mrvl_priv {\n \t/* Hot fields, used in fast path. */\n \tstruct pp2_bpool *bpool;  /**< BPool pointer */\n@@ -105,11 +169,18 @@ struct mrvl_priv {\n \tLIST_HEAD(mrvl_flows, rte_flow) flows;\n \n \tstruct pp2_cls_plcr *policer;\n+\n+\tLIST_HEAD(profiles, mrvl_mtr_profile) profiles;\n+\tLIST_HEAD(mtrs, mrvl_mtr) mtrs;\n+\tuint32_t used_plcrs;\n };\n \n /** Flow operations forward declaration. */\n extern const struct rte_flow_ops mrvl_flow_ops;\n \n+/** Meter operations forward declaration. */\n+extern const struct rte_mtr_ops mrvl_mtr_ops;\n+\n /** Current log type. */\n extern int mrvl_logtype;\n \ndiff --git a/drivers/net/mvpp2/mrvl_flow.c b/drivers/net/mvpp2/mrvl_flow.c\nindex db750f4..e6953e4 100644\n--- a/drivers/net/mvpp2/mrvl_flow.c\n+++ b/drivers/net/mvpp2/mrvl_flow.c\n@@ -20,46 +20,6 @@\n /** Size of the classifier key and mask strings. */\n #define MRVL_CLS_STR_SIZE_MAX 40\n \n-/** Parsed fields in processed rte_flow_item. */\n-enum mrvl_parsed_fields {\n-\t/* eth flags */\n-\tF_DMAC =         BIT(0),\n-\tF_SMAC =         BIT(1),\n-\tF_TYPE =         BIT(2),\n-\t/* vlan flags */\n-\tF_VLAN_ID =      BIT(3),\n-\tF_VLAN_PRI =     BIT(4),\n-\tF_VLAN_TCI =     BIT(5), /* not supported by MUSDK yet */\n-\t/* ip4 flags */\n-\tF_IP4_TOS =      BIT(6),\n-\tF_IP4_SIP =      BIT(7),\n-\tF_IP4_DIP =      BIT(8),\n-\tF_IP4_PROTO =    BIT(9),\n-\t/* ip6 flags */\n-\tF_IP6_TC =       BIT(10), /* not supported by MUSDK yet */\n-\tF_IP6_SIP =      BIT(11),\n-\tF_IP6_DIP =      BIT(12),\n-\tF_IP6_FLOW =     BIT(13),\n-\tF_IP6_NEXT_HDR = BIT(14),\n-\t/* tcp flags */\n-\tF_TCP_SPORT =    BIT(15),\n-\tF_TCP_DPORT =    BIT(16),\n-\t/* udp flags */\n-\tF_UDP_SPORT =    BIT(17),\n-\tF_UDP_DPORT =    BIT(18),\n-};\n-\n-/** PMD-specific definition of a flow rule handle. */\n-struct rte_flow {\n-\tLIST_ENTRY(rte_flow) next;\n-\n-\tenum mrvl_parsed_fields pattern;\n-\n-\tstruct pp2_cls_tbl_rule rule;\n-\tstruct pp2_cls_cos_desc cos;\n-\tstruct pp2_cls_tbl_action action;\n-};\n-\n static const enum rte_flow_item_type pattern_eth[] = {\n \tRTE_FLOW_ITEM_TYPE_ETH,\n \tRTE_FLOW_ITEM_TYPE_END\n@@ -2295,19 +2255,59 @@ mrvl_flow_parse_actions(struct mrvl_priv *priv,\n \t\t\tflow->action.type = PP2_CLS_TBL_ACT_DONE;\n \t\t\tflow->action.cos = &flow->cos;\n \t\t\tspecified++;\n+\t\t} else if (action->type == RTE_FLOW_ACTION_TYPE_METER) {\n+\t\t\tconst struct rte_flow_action_meter *meter;\n+\t\t\tstruct mrvl_mtr *mtr;\n+\n+\t\t\tmeter = action->conf;\n+\t\t\tif (!meter)\n+\t\t\t\treturn -rte_flow_error_set(error, EINVAL,\n+\t\t\t\t\t\tRTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t\tNULL, \"Invalid meter\\n\");\n+\n+\t\t\tLIST_FOREACH(mtr, &priv->mtrs, next)\n+\t\t\t\tif (mtr->mtr_id == meter->mtr_id)\n+\t\t\t\t\tbreak;\n+\n+\t\t\tif (!mtr)\n+\t\t\t\treturn -rte_flow_error_set(error, EINVAL,\n+\t\t\t\t\t\tRTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t\tNULL,\n+\t\t\t\t\t\t\"Meter id does not exist\\n\");\n+\n+\t\t\tif (!mtr->shared && mtr->refcnt)\n+\t\t\t\treturn -rte_flow_error_set(error, EPERM,\n+\t\t\t\t\t\tRTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t\tNULL,\n+\t\t\t\t\t\t\"Meter cannot be shared\\n\");\n+\n+\t\t\t/*\n+\t\t\t * In case cos has already been set\n+\t\t\t * do not modify it.\n+\t\t\t */\n+\t\t\tif (!flow->cos.ppio) {\n+\t\t\t\tflow->cos.ppio = priv->ppio;\n+\t\t\t\tflow->cos.tc = 0;\n+\t\t\t}\n+\n+\t\t\tflow->action.type = PP2_CLS_TBL_ACT_DONE;\n+\t\t\tflow->action.cos = &flow->cos;\n+\t\t\tflow->action.plcr = mtr->enabled ? mtr->plcr : NULL;\n+\t\t\tflow->mtr = mtr;\n+\t\t\tmtr->refcnt++;\n+\t\t\tspecified++;\n \t\t} else {\n \t\t\trte_flow_error_set(error, ENOTSUP,\n \t\t\t\t\t   RTE_FLOW_ERROR_TYPE_ACTION, NULL,\n \t\t\t\t\t   \"Action not supported\");\n \t\t\treturn -rte_errno;\n \t\t}\n-\n \t}\n \n \tif (!specified) {\n \t\trte_flow_error_set(error, EINVAL,\n-\t\t\t\t   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,\n-\t\t\t\t   NULL, \"Action not specified\");\n+\t\t\t\t   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t   \"Action not specified\");\n \t\treturn -rte_errno;\n \t}\n \n@@ -2657,6 +2657,11 @@ mrvl_flow_remove(struct mrvl_priv *priv, struct rte_flow *flow,\n \n \tmrvl_free_all_key_mask(&flow->rule);\n \n+\tif (flow->mtr) {\n+\t\tflow->mtr->refcnt--;\n+\t\tflow->mtr = NULL;\n+\t}\n+\n \treturn 0;\n }\n \ndiff --git a/drivers/net/mvpp2/mrvl_mtr.c b/drivers/net/mvpp2/mrvl_mtr.c\nnew file mode 100644\nindex 0000000..9cd53be\n--- /dev/null\n+++ b/drivers/net/mvpp2/mrvl_mtr.c\n@@ -0,0 +1,512 @@\n+/*-\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_log.h>\n+#include <rte_malloc.h>\n+\n+#include \"mrvl_mtr.h\"\n+\n+/** Maximum meter rate */\n+#define MRVL_SRTCM_RFC2697_CIR_MAX 1023000\n+\n+/** Invalid plcr bit */\n+#define MRVL_PLCR_BIT_INVALID -1\n+\n+/**\n+ * Return meter object capabilities.\n+ *\n+ * @param dev Pointer to the device (unused).\n+ * @param cap Pointer to the meter object capabilities.\n+ * @param error Pointer to the error (unused).\n+ * @returns 0 always.\n+ */\n+static int\n+mrvl_capabilities_get(struct rte_eth_dev *dev __rte_unused,\n+\t\t\t  struct rte_mtr_capabilities *cap,\n+\t\t\t  struct rte_mtr_error *error __rte_unused)\n+{\n+\tstruct rte_mtr_capabilities capa = {\n+\t\t.n_max = PP2_CLS_PLCR_NUM,\n+\t\t.n_shared_max = PP2_CLS_PLCR_NUM,\n+\t\t.shared_n_flows_per_mtr_max = -1,\n+\t\t.meter_srtcm_rfc2697_n_max = PP2_CLS_PLCR_NUM,\n+\t\t.meter_rate_max = MRVL_SRTCM_RFC2697_CIR_MAX,\n+\t};\n+\n+\tmemcpy(cap, &capa, sizeof(capa));\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Get profile using it's id.\n+ *\n+ * @param priv Pointer to the port's private data.\n+ * @param meter_profile_id Profile id used by the meter.\n+ * @returns Pointer to the profile if exists, NULL otherwise.\n+ */\n+static struct mrvl_mtr_profile *\n+mrvl_mtr_profile_from_id(struct mrvl_priv *priv, uint32_t meter_profile_id)\n+{\n+\tstruct mrvl_mtr_profile *profile = NULL;\n+\n+\tLIST_FOREACH(profile, &priv->profiles, next)\n+\t\tif (profile->profile_id == meter_profile_id)\n+\t\t\tbreak;\n+\n+\treturn profile;\n+}\n+\n+/**\n+ * Add profile to the list of profiles.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param meter_profile_id Id of the new profile.\n+ * @param profile Pointer to the profile configuration.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_meter_profile_add(struct rte_eth_dev *dev, uint32_t meter_profile_id,\n+\t\t       struct rte_mtr_meter_profile *profile,\n+\t\t       struct rte_mtr_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr_profile *prof;\n+\n+\tif (!profile)\n+\t\treturn -rte_mtr_error_set(error, EINVAL,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, NULL);\n+\n+\tif (profile->alg != RTE_MTR_SRTCM_RFC2697)\n+\t\treturn -rte_mtr_error_set(error, EINVAL,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL,\n+\t\t\t\t\t  \"Only srTCM RFC 2697 is supported\\n\");\n+\n+\tprof = mrvl_mtr_profile_from_id(priv, meter_profile_id);\n+\tif (prof)\n+\t\treturn -rte_mtr_error_set(error, EEXIST,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,\n+\t\t\t\t\t  NULL, \"Profile id already exists\\n\");\n+\n+\tprof = rte_zmalloc_socket(NULL, sizeof(*prof), 0, rte_socket_id());\n+\tif (!prof)\n+\t\treturn -rte_mtr_error_set(error, ENOMEM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, NULL);\n+\n+\tprof->profile_id = meter_profile_id;\n+\tmemcpy(&prof->profile, profile, sizeof(*profile));\n+\n+\tLIST_INSERT_HEAD(&priv->profiles, prof, next);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Remove profile from the list of profiles.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param meter_profile_id Id of the profile to remove.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_meter_profile_delete(struct rte_eth_dev *dev,\n+\t\t\t      uint32_t meter_profile_id,\n+\t\t\t      struct rte_mtr_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr_profile *profile;\n+\n+\tprofile = mrvl_mtr_profile_from_id(priv, meter_profile_id);\n+\tif (!profile)\n+\t\treturn -rte_mtr_error_set(error, ENODEV,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,\n+\t\t\t\t\t  NULL, \"Profile id does not exist\\n\");\n+\n+\tif (profile->refcnt)\n+\t\treturn -rte_mtr_error_set(error, EPERM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_METER_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+ * Get meter using it's id.\n+ *\n+ * @param priv Pointer to port's private data.\n+ * @param mtr_id Id of the meter.\n+ * @returns Pointer to the meter if exists, NULL otherwise.\n+ */\n+static struct mrvl_mtr *\n+mrvl_mtr_from_id(struct mrvl_priv *priv, uint32_t mtr_id)\n+{\n+\tstruct mrvl_mtr *mtr = NULL;\n+\n+\tLIST_FOREACH(mtr, &priv->mtrs, next)\n+\t\tif (mtr->mtr_id == mtr_id)\n+\t\t\tbreak;\n+\n+\treturn mtr;\n+}\n+\n+/**\n+ * Reserve a policer bit in a bitmap.\n+ *\n+ * @param plcrs Pointer to the policers bitmap.\n+ * @returns Reserved bit number on success, negative value otherwise.\n+ */\n+static int\n+mrvl_reserve_plcr(uint32_t *plcrs)\n+{\n+\tuint32_t i, num;\n+\n+\tnum = PP2_CLS_PLCR_NUM;\n+\tif (num > sizeof(uint32_t) * 8) {\n+\t\tnum = sizeof(uint32_t) * 8;\n+\t\tMRVL_LOG(WARNING, \"Plcrs number was limited to 32.\");\n+\t}\n+\n+\tfor (i = 0; i < num; i++) {\n+\t\tuint32_t bit = BIT(i);\n+\n+\t\tif (!(*plcrs & bit)) {\n+\t\t\t*plcrs |= bit;\n+\n+\t\t\treturn i;\n+\t\t}\n+\t}\n+\n+\treturn -1;\n+}\n+\n+/**\n+ * Enable meter object.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param mtr_id Id of the meter.\n+ * @param error Pointer to the error.\n+ * @returns 0 in success, negative value otherwise.\n+ */\n+static int\n+mrvl_meter_enable(struct rte_eth_dev *dev, uint32_t mtr_id,\n+\t\t  struct rte_mtr_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr *mtr = mrvl_mtr_from_id(priv, mtr_id);\n+\tstruct pp2_cls_plcr_params params;\n+\tchar match[MRVL_MATCH_LEN];\n+\tstruct rte_flow *flow;\n+\tint ret;\n+\n+\tif (!priv->ppio)\n+\t\treturn -rte_mtr_error_set(error, EPERM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, \"Port is uninitialized\\n\");\n+\n+\tif (!mtr)\n+\t\treturn -rte_mtr_error_set(error, ENODEV,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,\n+\t\t\t\t\t  \"Meter id does not exist\\n\");\n+\n+\tif (mtr->plcr)\n+\t\tgoto skip;\n+\n+\tmtr->plcr_bit = mrvl_reserve_plcr(&priv->used_plcrs);\n+\tif (mtr->plcr_bit < 0)\n+\t\treturn -rte_mtr_error_set(error, ENOSPC,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL,\n+\t\t\t\t\t  \"Failed to reserve plcr entry\\n\");\n+\n+\tmemset(&params, 0, sizeof(params));\n+\tsnprintf(match, sizeof(match), \"policer-%d:%d\", priv->pp_id,\n+\t\t mtr->plcr_bit);\n+\tparams.match = match;\n+\tparams.token_unit = PP2_CLS_PLCR_BYTES_TOKEN_UNIT;\n+\tparams.color_mode = PP2_CLS_PLCR_COLOR_BLIND_MODE;\n+\tparams.cir = mtr->profile->profile.srtcm_rfc2697.cir;\n+\tparams.cbs = mtr->profile->profile.srtcm_rfc2697.cbs;\n+\tparams.ebs = mtr->profile->profile.srtcm_rfc2697.ebs;\n+\n+\tret = pp2_cls_plcr_init(&params, &mtr->plcr);\n+\tif (ret) {\n+\t\tpriv->used_plcrs &= ~BIT(mtr->plcr_bit);\n+\t\tmtr->plcr_bit = MRVL_PLCR_BIT_INVALID;\n+\n+\t\treturn -rte_mtr_error_set(error, -ret,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, \"Failed to setup policer\\n\");\n+\t}\n+\n+\tmtr->enabled = 1;\n+skip:\n+\t/* iterate over flows that have this mtr attached */\n+\tLIST_FOREACH(flow, &priv->flows, next) {\n+\t\tif (flow->mtr != mtr)\n+\t\t\tcontinue;\n+\n+\t\tflow->action.plcr = mtr->plcr;\n+\n+\t\tret = pp2_cls_tbl_modify_rule(priv->cls_tbl, &flow->rule,\n+\t\t\t\t\t      &flow->action);\n+\t\tif (ret)\n+\t\t\treturn -rte_mtr_error_set(error, -ret,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, \"Failed to update cls rule\\n\");\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Disable meter object.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param mtr Id of the meter.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_meter_disable(struct rte_eth_dev *dev, uint32_t mtr_id,\n+\t\t       struct rte_mtr_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr *mtr = mrvl_mtr_from_id(priv, mtr_id);\n+\tstruct rte_flow *flow;\n+\tint ret;\n+\n+\tif (!mtr)\n+\t\treturn -rte_mtr_error_set(error, ENODEV,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,\n+\t\t\t\t\t  \"Meter id does not exist\\n\");\n+\n+\tLIST_FOREACH(flow, &priv->flows, next) {\n+\t\tif (flow->mtr != mtr)\n+\t\t\tcontinue;\n+\n+\t\tflow->action.plcr = NULL;\n+\n+\t\tret = pp2_cls_tbl_modify_rule(priv->cls_tbl, &flow->rule,\n+\t\t\t\t\t      &flow->action);\n+\t\tif (ret)\n+\t\t\treturn -rte_mtr_error_set(error, -ret,\n+\t\t\t\t\tRTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\tNULL, \"Failed to disable meter\\n\");\n+\t}\n+\n+\tmtr->enabled = 0;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Create new meter.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param mtr_id Id of the meter.\n+ * @param params Pointer to the meter parameters.\n+ * @param shared Flags indicating whether meter is shared.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_create(struct rte_eth_dev *dev, uint32_t mtr_id,\n+\t    struct rte_mtr_params *params, int shared,\n+\t    struct rte_mtr_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr_profile *profile;\n+\tstruct mrvl_mtr *mtr;\n+\n+\tmtr = mrvl_mtr_from_id(priv, mtr_id);\n+\tif (mtr)\n+\t\treturn -rte_mtr_error_set(error, EEXIST,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,\n+\t\t\t\t\t  \"Meter id already exists\\n\");\n+\n+\tmtr = rte_zmalloc_socket(NULL, sizeof(*mtr), 0, rte_socket_id());\n+\tif (!mtr)\n+\t\treturn -rte_mtr_error_set(error, ENOMEM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, NULL);\n+\n+\tprofile = mrvl_mtr_profile_from_id(priv, params->meter_profile_id);\n+\tif (!profile)\n+\t\treturn -rte_mtr_error_set(error, EINVAL,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,\n+\t\t\t\t\t  NULL, \"Profile id does not exist\\n\");\n+\n+\tmtr->shared = shared;\n+\tmtr->mtr_id = mtr_id;\n+\tmtr->plcr_bit = MRVL_PLCR_BIT_INVALID;\n+\tmtr->profile = profile;\n+\tprofile->refcnt++;\n+\tLIST_INSERT_HEAD(&priv->mtrs, mtr, next);\n+\n+\tif (params->meter_enable)\n+\t\treturn mrvl_meter_enable(dev, mtr_id, error);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Destroy meter object.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param mtr_id Id of the meter object.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_destroy(struct rte_eth_dev *dev, uint32_t mtr_id,\n+\t\t struct rte_mtr_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr *mtr;\n+\n+\tif (!priv->ppio)\n+\t\treturn -rte_mtr_error_set(error, EPERM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, \"Port is uninitialized\\n\");\n+\n+\tmtr = mrvl_mtr_from_id(priv, mtr_id);\n+\tif (!mtr)\n+\t\treturn -rte_mtr_error_set(error, EEXIST,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,\n+\t\t\t\t\t  \"Meter id does not exist\\n\");\n+\n+\tif (mtr->refcnt)\n+\t\treturn -rte_mtr_error_set(error, EPERM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,\n+\t\t\t\t\t  \"Meter is used\\n\");\n+\n+\tLIST_REMOVE(mtr, next);\n+\tmtr->profile->refcnt--;\n+\n+\tif (mtr->plcr_bit != MRVL_PLCR_BIT_INVALID)\n+\t\tpriv->used_plcrs &= ~BIT(mtr->plcr_bit);\n+\n+\tif (mtr->plcr)\n+\t\tpp2_cls_plcr_deinit(mtr->plcr);\n+\n+\trte_free(mtr);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * Update profile used by the meter.\n+ *\n+ * @param dev Pointer to the device.\n+ * @param mtr_id Id of the meter object.\n+ * @param error Pointer to the error.\n+ * @returns 0 on success, negative value otherwise.\n+ */\n+static int\n+mrvl_meter_profile_update(struct rte_eth_dev *dev, uint32_t mtr_id,\n+\t\t\t  uint32_t meter_profile_id,\n+\t\t\t  struct rte_mtr_error *error)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr_profile *profile;\n+\tstruct mrvl_mtr *mtr;\n+\tint ret, enabled;\n+\n+\tif (!priv->ppio)\n+\t\treturn -rte_mtr_error_set(error, EPERM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL, \"Port is uninitialized\\n\");\n+\n+\tmtr = mrvl_mtr_from_id(priv, mtr_id);\n+\tif (!mtr)\n+\t\treturn -rte_mtr_error_set(error, EEXIST,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_MTR_ID, NULL,\n+\t\t\t\t\t  \"Meter id does not exist\\n\");\n+\n+\tprofile = mrvl_mtr_profile_from_id(priv, meter_profile_id);\n+\tif (!profile)\n+\t\treturn -rte_mtr_error_set(error, EINVAL,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,\n+\t\t\t\t\t  NULL, \"Profile id does not exist\\n\");\n+\n+\tret = mrvl_meter_disable(dev, mtr_id, error);\n+\tif (ret)\n+\t\treturn -rte_mtr_error_set(error, EPERM,\n+\t\t\t\t\t  RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t\t  NULL);\n+\n+\tif (mtr->plcr) {\n+\t\tenabled = 1;\n+\t\tpp2_cls_plcr_deinit(mtr->plcr);\n+\t\tmtr->plcr = NULL;\n+\t}\n+\n+\tmtr->profile->refcnt--;\n+\tmtr->profile = profile;\n+\tprofile->refcnt++;\n+\n+\tif (enabled)\n+\t\treturn mrvl_meter_enable(dev, mtr_id, error);\n+\n+\treturn 0;\n+}\n+\n+const struct rte_mtr_ops mrvl_mtr_ops = {\n+\t.capabilities_get = mrvl_capabilities_get,\n+\t.meter_profile_add = mrvl_meter_profile_add,\n+\t.meter_profile_delete = mrvl_meter_profile_delete,\n+\t.create = mrvl_create,\n+\t.destroy = mrvl_destroy,\n+\t.meter_enable = mrvl_meter_enable,\n+\t.meter_disable = mrvl_meter_disable,\n+\t.meter_profile_update = mrvl_meter_profile_update,\n+};\n+\n+/**\n+ * Initialize metering resources.\n+ *\n+ * @param dev Pointer to the device.\n+ */\n+void\n+mrvl_mtr_init(struct rte_eth_dev *dev)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\n+\tLIST_INIT(&priv->profiles);\n+\tLIST_INIT(&priv->mtrs);\n+}\n+\n+/**\n+ * Cleanup metering resources.\n+ *\n+ * @param dev Pointer to the device.\n+ */\n+void\n+mrvl_mtr_deinit(struct rte_eth_dev *dev)\n+{\n+\tstruct mrvl_priv *priv = dev->data->dev_private;\n+\tstruct mrvl_mtr_profile *profile, *tmp_profile;\n+\tstruct mrvl_mtr *mtr, *tmp_mtr;\n+\n+\tfor (mtr = LIST_FIRST(&priv->mtrs);\n+\t     mtr && (tmp_mtr = LIST_NEXT(mtr, next), 1);\n+\t     mtr = tmp_mtr)\n+\t\tmrvl_destroy(dev, mtr->mtr_id, NULL);\n+\n+\tfor (profile = LIST_FIRST(&priv->profiles);\n+\t     profile && (tmp_profile = LIST_NEXT(profile, next), 1);\n+\t     profile = tmp_profile)\n+\t\tmrvl_meter_profile_delete(dev, profile->profile_id, NULL);\n+}\ndiff --git a/drivers/net/mvpp2/mrvl_mtr.h b/drivers/net/mvpp2/mrvl_mtr.h\nnew file mode 100644\nindex 0000000..302a20f\n--- /dev/null\n+++ b/drivers/net/mvpp2/mrvl_mtr.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_MTR_H_\n+#define _MRVL_MTR_H_\n+\n+#include \"mrvl_ethdev.h\"\n+\n+void mrvl_mtr_init(struct rte_eth_dev *dev);\n+void mrvl_mtr_deinit(struct rte_eth_dev *dev);\n+\n+#endif /* _MRVL_MTR_H_ */\n",
    "prefixes": [
        "v3",
        "03/13"
    ]
}