get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 42814,
    "url": "http://patches.dpdk.org/api/patches/42814/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/f686816455875d962583cc88f410d2419b779671.1531293415.git.nelio.laranjeiro@6wind.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": "<f686816455875d962583cc88f410d2419b779671.1531293415.git.nelio.laranjeiro@6wind.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/f686816455875d962583cc88f410d2419b779671.1531293415.git.nelio.laranjeiro@6wind.com",
    "date": "2018-07-11T07:22:54",
    "name": "[v3,21/21] net/mlx5: add count flow action",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "573eef17eb4b8d11919c6fd9b2544722b7a8a921",
    "submitter": {
        "id": 243,
        "url": "http://patches.dpdk.org/api/people/243/?format=api",
        "name": "Nélio Laranjeiro",
        "email": "nelio.laranjeiro@6wind.com"
    },
    "delegate": {
        "id": 6624,
        "url": "http://patches.dpdk.org/api/users/6624/?format=api",
        "username": "shahafs",
        "first_name": "Shahaf",
        "last_name": "Shuler",
        "email": "shahafs@mellanox.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/f686816455875d962583cc88f410d2419b779671.1531293415.git.nelio.laranjeiro@6wind.com/mbox/",
    "series": [
        {
            "id": 512,
            "url": "http://patches.dpdk.org/api/series/512/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=512",
            "date": "2018-07-11T07:22:33",
            "name": "net/mlx5: flow rework",
            "version": 3,
            "mbox": "http://patches.dpdk.org/series/512/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/42814/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/42814/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 F3A4F1B599;\n\tWed, 11 Jul 2018 09:24:10 +0200 (CEST)",
            "from mail-wr1-f52.google.com (mail-wr1-f52.google.com\n\t[209.85.221.52]) by dpdk.org (Postfix) with ESMTP id 5EA671B4F5\n\tfor <dev@dpdk.org>; Wed, 11 Jul 2018 09:23:36 +0200 (CEST)",
            "by mail-wr1-f52.google.com with SMTP id r16-v6so17015587wrt.11\n\tfor <dev@dpdk.org>; Wed, 11 Jul 2018 00:23:36 -0700 (PDT)",
            "from laranjeiro-vm.dev.6wind.com\n\t(host.78.145.23.62.rev.coltfrance.com. [62.23.145.78])\n\tby smtp.gmail.com with ESMTPSA id\n\tt10-v6sm31314212wre.95.2018.07.11.00.23.35\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tWed, 11 Jul 2018 00:23:35 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=6wind-com.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=1gQw6f9oVc42vstXV4CQeEgttDFOGkY/ozLr86KpGLE=;\n\tb=honjJp4ehazIdpJIrbD3R3z/KMZboX+SnLHnn4YD9BZfM7ipBtxnGOnAeF8KDoSH1k\n\t/4ig0qJjIBgmkToCadxK13qJbvfBAxOLFE/1bcITBvJDAGPIvOE3HNOdZgfG+0hG/07S\n\t/Al48K2w5kOZ4EOYO+cmJ9f+uezXSUuJDulpHI4+7bF/V9scUK2bsa1AfWSW76LD76g2\n\tancyMG+Rmte9exKum8GZILO5256GCfcrL7d9G6OGZSGStQQ960mdZW3DiTCT3iWgUxgw\n\tcemwK7acJUwBbU/T2fo45UEYRh1M7F2lfPpK4hsLmqa5HUyS9Yi9ZeUz4e5ltdZx2Dr5\n\tsvvA==",
        "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=1gQw6f9oVc42vstXV4CQeEgttDFOGkY/ozLr86KpGLE=;\n\tb=Ta8mX7bxhngwTt5kTu2p4BK9/HNpyvxl+VsQq8VF9hkO0QqT2ByGkaikUirL3spYEX\n\tiWVZIUFT2hYEpzLcft8ZrDcJW4ldc66MXH6OcPFyQ+O7ViWZNFtOBFbOcaEXcZo2kpeN\n\t3+KTm8312J0Yj2rdnVxghKYx96zkY3Hv4bqkS5x8hbycH/62tFhz+HLB/S3OEe5qDyI0\n\t2ROMk4zvMEahZKxaU8N6andeZoqDDEusr7JQVmsS/qmF2rE95h6uvzY7JXS7ohIT156z\n\thWzJbjomcUpvWlFMZ+88FJ1orJ/wzt6znf6WYJzXGxs+ggO55PQcOeVA3E6wpEJL5XDl\n\tf+6w==",
        "X-Gm-Message-State": "APt69E3qmtnzy+zU6ydQIbbIW+7oEBrDFlzwrIMjrhn8iG4cNo0A4Y0X\n\tnfqyFCjFGGiJdiri/rXos/91YcZTLw==",
        "X-Google-Smtp-Source": "AAOMgpcfVjloFsVP2terSdHABg0i2AM6T6t6v0I7OlM5OsKeAbOeYoyOWWEme7JYNGZygGIu3Eg6VA==",
        "X-Received": "by 2002:a5d:4e49:: with SMTP id\n\tr9-v6mr18530018wrt.27.1531293815877; \n\tWed, 11 Jul 2018 00:23:35 -0700 (PDT)",
        "From": "Nelio Laranjeiro <nelio.laranjeiro@6wind.com>",
        "To": "dev@dpdk.org,\n\tYongseok Koh <yskoh@mellanox.com>",
        "Cc": "Adrien Mazarguil <adrien.mazarguil@6wind.com>",
        "Date": "Wed, 11 Jul 2018 09:22:54 +0200",
        "Message-Id": "<f686816455875d962583cc88f410d2419b779671.1531293415.git.nelio.laranjeiro@6wind.com>",
        "X-Mailer": "git-send-email 2.18.0",
        "In-Reply-To": "<cover.1531293415.git.nelio.laranjeiro@6wind.com>",
        "References": "<cover.1530111623.git.nelio.laranjeiro@6wind.com>\n\t<cover.1531293415.git.nelio.laranjeiro@6wind.com>",
        "Subject": "[dpdk-dev] [PATCH v3 21/21] net/mlx5: add count flow action",
        "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": "This is only supported by Mellanox OFED.\n\nSigned-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>\nAcked-by: Yongseok Koh <yskoh@mellanox.com>\n---\n drivers/net/mlx5/mlx5.h      |   2 +\n drivers/net/mlx5/mlx5_flow.c | 242 +++++++++++++++++++++++++++++++++++\n 2 files changed, 244 insertions(+)",
    "diff": "diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h\nindex 9949cd3fa..131be334c 100644\n--- a/drivers/net/mlx5/mlx5.h\n+++ b/drivers/net/mlx5/mlx5.h\n@@ -188,6 +188,8 @@ struct priv {\n \tstruct mlx5_drop drop_queue; /* Flow drop queues. */\n \tstruct mlx5_flows flows; /* RTE Flow rules. */\n \tstruct mlx5_flows ctrl_flows; /* Control flow rules. */\n+\tLIST_HEAD(counters, mlx5_flow_counter) flow_counters;\n+\t/* Flow counters. */\n \tstruct {\n \t\tuint32_t dev_gen; /* Generation number to flush local caches. */\n \t\trte_rwlock_t rwlock; /* MR Lock. */\ndiff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c\nindex 4ad581ed9..9ce4dddd7 100644\n--- a/drivers/net/mlx5/mlx5_flow.c\n+++ b/drivers/net/mlx5/mlx5_flow.c\n@@ -88,6 +88,7 @@ extern const struct eth_dev_ops mlx5_dev_ops_isolate;\n /* Modify a packet. */\n #define MLX5_FLOW_MOD_FLAG (1u << 0)\n #define MLX5_FLOW_MOD_MARK (1u << 1)\n+#define MLX5_FLOW_MOD_COUNT (1u << 2)\n \n /* possible L3 layers protocols filtering. */\n #define MLX5_IP_PROTOCOL_TCP 6\n@@ -249,6 +250,17 @@ struct mlx5_flow_verbs {\n \tuint64_t hash_fields; /**< Verbs hash Rx queue hash fields. */\n };\n \n+/* Counters information. */\n+struct mlx5_flow_counter {\n+\tLIST_ENTRY(mlx5_flow_counter) next; /**< Pointer to the next counter. */\n+\tuint32_t shared:1; /**< Share counter ID with other flow rules. */\n+\tuint32_t ref_cnt:31; /**< Reference counter. */\n+\tuint32_t id; /**< Counter ID. */\n+\tstruct ibv_counter_set *cs; /**< Holds the counters for the rule. */\n+\tuint64_t hits; /**< Number of packets matched by the rule. */\n+\tuint64_t bytes; /**< Number of bytes matched by the rule. */\n+};\n+\n /* Flow structure. */\n struct rte_flow {\n \tTAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */\n@@ -264,6 +276,7 @@ struct rte_flow {\n \tLIST_HEAD(verbs, mlx5_flow_verbs) verbs; /**< Verbs flows list. */\n \tstruct mlx5_flow_verbs *cur_verbs;\n \t/**< Current Verbs flow structure being filled. */\n+\tstruct mlx5_flow_counter *counter; /**< Holds Verbs flow counter. */\n \tstruct rte_flow_action_rss rss;/**< RSS context. */\n \tuint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */\n \tuint16_t (*queue)[]; /**< Destination queues to redirect traffic to. */\n@@ -275,6 +288,7 @@ static const struct rte_flow_ops mlx5_flow_ops = {\n \t.destroy = mlx5_flow_destroy,\n \t.flush = mlx5_flow_flush,\n \t.isolate = mlx5_flow_isolate,\n+\t.query = mlx5_flow_query,\n };\n \n /* Convert FDIR request to Generic flow. */\n@@ -454,6 +468,80 @@ mlx5_flow_adjust_priority(struct rte_eth_dev *dev, struct rte_flow *flow)\n \tflow->cur_verbs->attr->priority = priority;\n }\n \n+/**\n+ * Get a flow counter.\n+ *\n+ * @param[in] dev\n+ *   Pointer to Ethernet device.\n+ * @param[in] shared\n+ *   Indicate if this counter is shared with other flows.\n+ * @param[in] id\n+ *   Counter identifier.\n+ *\n+ * @return\n+ *   A pointer to the counter, NULL otherwise and rte_errno is set.\n+ */\n+static struct mlx5_flow_counter *\n+mlx5_flow_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id)\n+{\n+\tstruct priv *priv = dev->data->dev_private;\n+\tstruct mlx5_flow_counter *cnt;\n+\n+\tLIST_FOREACH(cnt, &priv->flow_counters, next) {\n+\t\tif (cnt->shared != shared)\n+\t\t\tcontinue;\n+\t\tif (cnt->id != id)\n+\t\t\tcontinue;\n+\t\tcnt->ref_cnt++;\n+\t\treturn cnt;\n+\t}\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\n+\tstruct mlx5_flow_counter tmpl = {\n+\t\t.shared = shared,\n+\t\t.id = id,\n+\t\t.cs = mlx5_glue->create_counter_set\n+\t\t\t(priv->ctx,\n+\t\t\t &(struct ibv_counter_set_init_attr){\n+\t\t\t\t .counter_set_id = id,\n+\t\t\t }),\n+\t\t.hits = 0,\n+\t\t.bytes = 0,\n+\t};\n+\n+\tif (!tmpl.cs) {\n+\t\trte_errno = errno;\n+\t\treturn NULL;\n+\t}\n+\tcnt = rte_calloc(__func__, 1, sizeof(*cnt), 0);\n+\tif (!cnt) {\n+\t\trte_errno = ENOMEM;\n+\t\treturn NULL;\n+\t}\n+\t*cnt = tmpl;\n+\tLIST_INSERT_HEAD(&priv->flow_counters, cnt, next);\n+\treturn cnt;\n+#endif\n+\trte_errno = ENOTSUP;\n+\treturn NULL;\n+}\n+\n+/**\n+ * Release a flow counter.\n+ *\n+ * @param[in] counter\n+ *   Pointer to the counter handler.\n+ */\n+static void\n+mlx5_flow_counter_release(struct mlx5_flow_counter *counter)\n+{\n+\tif (--counter->ref_cnt == 0) {\n+\t\tclaim_zero(mlx5_glue->destroy_counter_set(counter->cs));\n+\t\tLIST_REMOVE(counter, next);\n+\t\trte_free(counter);\n+\t}\n+}\n+\n /**\n  * Verify the @p attributes will be correctly understood by the NIC and store\n  * them in the @p flow if everything is correct.\n@@ -2121,6 +2209,70 @@ mlx5_flow_action_mark(const struct rte_flow_action *action,\n \treturn size;\n }\n \n+/**\n+ * Convert the @p action into a Verbs specification after ensuring the NIC\n+ * will understand and process it correctly.\n+ * If the necessary size for the conversion is greater than the @p flow_size,\n+ * nothing is written in @p flow, the validation is still performed.\n+ *\n+ * @param action[in]\n+ *   Action configuration.\n+ * @param flow[in, out]\n+ *   Pointer to flow structure.\n+ * @param flow_size[in]\n+ *   Size in bytes of the available space in @p flow, if too small, nothing is\n+ *   written.\n+ * @param error[int, out]\n+ *   Pointer to error structure.\n+ *\n+ * @return\n+ *   On success the number of bytes consumed/necessary, if the returned value\n+ *   is lesser or equal to @p flow_size, the @p action has fully been\n+ *   converted, otherwise another call with this returned memory size should\n+ *   be done.\n+ *   On error, a negative errno value is returned and rte_errno is set.\n+ */\n+static int\n+mlx5_flow_action_count(struct rte_eth_dev *dev,\n+\t\t       const struct rte_flow_action *action,\n+\t\t       struct rte_flow *flow,\n+\t\t       const size_t flow_size __rte_unused,\n+\t\t       struct rte_flow_error *error)\n+{\n+\tconst struct rte_flow_action_count *count = action->conf;\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\tunsigned int size = sizeof(struct ibv_flow_spec_counter_action);\n+\tstruct ibv_flow_spec_counter_action counter = {\n+\t\t.type = IBV_FLOW_SPEC_ACTION_COUNT,\n+\t\t.size = size,\n+\t};\n+#endif\n+\n+\tif (!flow->counter) {\n+\t\tflow->counter = mlx5_flow_counter_new(dev, count->shared,\n+\t\t\t\t\t\t      count->id);\n+\t\tif (!flow->counter)\n+\t\t\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t\t  action,\n+\t\t\t\t\t\t  \"cannot get counter\"\n+\t\t\t\t\t\t  \" context.\");\n+\t}\n+\tif (!((struct priv *)dev->data->dev_private)->config.flow_counter_en)\n+\t\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t  action,\n+\t\t\t\t\t  \"flow counters are not supported.\");\n+\tflow->modifier |= MLX5_FLOW_MOD_COUNT;\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\tcounter.counter_set_handle = flow->counter->cs->handle;\n+\tif (size <= flow_size)\n+\t\tmlx5_flow_spec_verbs_add(flow, &counter, size);\n+\treturn size;\n+#endif\n+\treturn 0;\n+}\n+\n /**\n  * Convert the @p action into @p flow after ensuring the NIC will understand\n  * and process it correctly.\n@@ -2180,6 +2332,10 @@ mlx5_flow_actions(struct rte_eth_dev *dev,\n \t\tcase RTE_FLOW_ACTION_TYPE_RSS:\n \t\t\tret = mlx5_flow_action_rss(dev, actions, flow, error);\n \t\t\tbreak;\n+\t\tcase RTE_FLOW_ACTION_TYPE_COUNT:\n+\t\t\tret = mlx5_flow_action_count(dev, actions, flow, remain,\n+\t\t\t\t\t\t     error);\n+\t\t\tbreak;\n \t\tdefault:\n \t\t\treturn rte_flow_error_set(error, ENOTSUP,\n \t\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n@@ -2557,6 +2713,10 @@ mlx5_flow_remove(struct rte_eth_dev *dev, struct rte_flow *flow)\n \t\t\tverbs->hrxq = NULL;\n \t\t}\n \t}\n+\tif (flow->counter) {\n+\t\tmlx5_flow_counter_release(flow->counter);\n+\t\tflow->counter = NULL;\n+\t}\n }\n \n /**\n@@ -3006,6 +3166,88 @@ mlx5_flow_isolate(struct rte_eth_dev *dev,\n \treturn 0;\n }\n \n+/**\n+ * Query flow counter.\n+ *\n+ * @param flow\n+ *   Pointer to the flow.\n+ *\n+ * @return\n+ *   0 on success, a negative errno value otherwise and rte_errno is set.\n+ */\n+static int\n+mlx5_flow_query_count(struct rte_flow *flow __rte_unused,\n+\t\t      void *data __rte_unused,\n+\t\t      struct rte_flow_error *error)\n+{\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\tstruct rte_flow_query_count *qc = data;\n+\tuint64_t counters[2] = {0, 0};\n+\tstruct ibv_query_counter_set_attr query_cs_attr = {\n+\t\t.cs = flow->counter->cs,\n+\t\t.query_flags = IBV_COUNTER_SET_FORCE_UPDATE,\n+\t};\n+\tstruct ibv_counter_set_data query_out = {\n+\t\t.out = counters,\n+\t\t.outlen = 2 * sizeof(uint64_t),\n+\t};\n+\tint err = mlx5_glue->query_counter_set(&query_cs_attr, &query_out);\n+\n+\tif (err)\n+\t\treturn rte_flow_error_set(error, err,\n+\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL,\n+\t\t\t\t\t  \"cannot read counter\");\n+\tqc->hits_set = 1;\n+\tqc->bytes_set = 1;\n+\tqc->hits = counters[0] - flow->counter->hits;\n+\tqc->bytes = counters[1] - flow->counter->bytes;\n+\tif (qc->reset) {\n+\t\tflow->counter->hits = counters[0];\n+\t\tflow->counter->bytes = counters[1];\n+\t}\n+\treturn 0;\n+#endif\n+\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t  NULL,\n+\t\t\t\t  \"counters are not available\");\n+}\n+\n+/**\n+ * Query a flows.\n+ *\n+ * @see rte_flow_query()\n+ * @see rte_flow_ops\n+ */\n+int\n+mlx5_flow_query(struct rte_eth_dev *dev __rte_unused,\n+\t\tstruct rte_flow *flow,\n+\t\tconst struct rte_flow_action *actions,\n+\t\tvoid *data,\n+\t\tstruct rte_flow_error *error)\n+{\n+\tint ret = 0;\n+\n+\tfor (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {\n+\t\tswitch (actions->type) {\n+\t\tcase RTE_FLOW_ACTION_TYPE_VOID:\n+\t\t\tbreak;\n+\t\tcase RTE_FLOW_ACTION_TYPE_COUNT:\n+\t\t\tret = mlx5_flow_query_count(flow, data, error);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t\t  actions,\n+\t\t\t\t\t\t  \"action not supported\");\n+\t\t}\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t}\n+\treturn 0;\n+}\n+\n /**\n  * Convert a flow director filter to a generic flow.\n  *\n",
    "prefixes": [
        "v3",
        "21/21"
    ]
}