DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yongseok Koh <yskoh@mellanox.com>
To: Thomas Monjalon <thomas@monjalon.net>,
	Shahaf Shuler <shahafs@mellanox.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, Ori Kam <orika@mellanox.com>
Subject: [dpdk-dev] [PATCH v3 10/11] net/mlx5: add Direct Verbs final functions
Date: Mon, 24 Sep 2018 23:17:52 +0000	[thread overview]
Message-ID: <20180924231721.15799-11-yskoh@mellanox.com> (raw)
In-Reply-To: <20180924231721.15799-1-yskoh@mellanox.com>

From: Ori Kam <orika@mellanox.com>

This commits add the missing function which are apply, remove, and
destroy.

Signed-off-by: Ori Kam <orika@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.c    |   4 +
 drivers/net/mlx5/mlx5_flow.h    |   2 +
 drivers/net/mlx5/mlx5_flow_dv.c | 192 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 194 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 5632e31c5..c6c145021 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -2489,5 +2489,9 @@ mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
 void
 mlx5_flow_init_driver_ops(struct rte_eth_dev *dev __rte_unused)
 {
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
+	mlx5_flow_dv_get_driver_ops(&nic_ops);
+#else
 	mlx5_flow_verbs_get_driver_ops(&nic_ops);
+#endif
 }
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index ec860ef4b..53c0eeb56 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -189,7 +189,9 @@ struct mlx5_flow {
 	struct rte_flow *flow; /**< Pointer to the main flow. */
 	uint32_t layers; /**< Bit-fields that holds the detected layers. */
 	union {
+#ifdef HAVE_IBV_FLOW_DV_SUPPORT
 		struct mlx5_flow_dv dv;
+#endif
 		struct mlx5_flow_verbs verbs;
 	};
 };
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 916989988..71af410b2 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -2,6 +2,7 @@
  * Copyright 2018 Mellanox Technologies, Ltd
  */
 
+
 #include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
@@ -1095,7 +1096,7 @@ flow_dv_matcher_register(struct rte_eth_dev *dev,
 	if (matcher->egress)
 		dv_attr.flags |= IBV_FLOW_ATTR_FLAGS_EGRESS;
 	cache->cache.resource =
-		mlx5dv_create_flow_matcher(priv->ctx, &dv_attr);
+		mlx5_glue->dv_create_flow_matcher(priv->ctx, &dv_attr);
 	if (!cache->cache.resource)
 		return rte_flow_error_set(error, ENOMEM,
 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
@@ -1168,6 +1169,189 @@ flow_dv_translate(struct rte_eth_dev *dev,
 }
 
 /**
+ * Apply the flow to the NIC.
+ *
+ * @param[in] dev
+ *   Pointer to the Ethernet device structure.
+ * @param[in, out] flow
+ *   Pointer to flow structure.
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
+	      struct rte_flow_error *error)
+{
+	struct mlx5_flow_dv *dv;
+	struct mlx5_flow *dev_flow;
+	int n;
+	int err;
+
+	LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
+		dv = &dev_flow->dv;
+		n = dv->actions_n;
+		if (flow->actions & MLX5_ACTION_DROP) {
+			dv->hrxq = mlx5_hrxq_drop_new(dev);
+			if (!dv->hrxq) {
+				rte_flow_error_set
+					(error, errno,
+					 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					 "cannot get drop hash queue");
+				goto error;
+			}
+			dv->actions[n].type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
+			dv->actions[n].qp = dv->hrxq->qp;
+			n++;
+		} else {
+			struct mlx5_hrxq *hrxq;
+			hrxq = mlx5_hrxq_get(dev, flow->key,
+					     MLX5_RSS_HASH_KEY_LEN,
+					     dv->hash_fields,
+					     (*flow->queue),
+					     flow->rss.queue_num);
+			if (!hrxq)
+				hrxq = mlx5_hrxq_new
+					(dev, flow->key, MLX5_RSS_HASH_KEY_LEN,
+					 dv->hash_fields, (*flow->queue),
+					 flow->rss.queue_num,
+					 !!(flow->layers &
+					    MLX5_FLOW_LAYER_TUNNEL));
+			if (!hrxq) {
+				rte_flow_error_set
+					(error, rte_errno,
+					 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					 "cannot get hash queue");
+				goto error;
+			}
+			dv->hrxq = hrxq;
+			dv->actions[n].type = MLX5DV_FLOW_ACTION_DEST_IBV_QP;
+			dv->actions[n].qp = hrxq->qp;
+			n++;
+		}
+		dv->flow =
+			mlx5_glue->dv_create_flow(dv->matcher->cache.resource,
+						  (void *)&dv->value, n,
+						  dv->actions);
+		if (!dv->flow) {
+			rte_flow_error_set(error, errno,
+					   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					   NULL,
+					   "hardware refuses to create flow");
+			goto error;
+		}
+	}
+	return 0;
+error:
+	err = rte_errno; /* Save rte_errno before cleanup. */
+	LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
+		struct mlx5_flow_dv *dv = &dev_flow->dv;
+		if (dv->hrxq) {
+			if (flow->actions & MLX5_FLOW_FATE_DROP)
+				mlx5_hrxq_drop_release(dev);
+			else
+				mlx5_hrxq_release(dev, dv->hrxq);
+			dv->hrxq = NULL;
+		}
+	}
+	rte_errno = err; /* Restore rte_errno. */
+	return -rte_errno;
+}
+
+/**
+ * Release the flow matcher.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param matcher
+ *   Pointer to flow matcher.
+ *
+ * @return
+ *   1 while a reference on it exists, 0 when freed.
+ */
+static int
+flow_dv_matcher_release(struct rte_eth_dev *dev,
+			struct mlx5_flow_dv_matcher *matcher)
+{
+	struct mlx5_cache *cache = &matcher->cache;
+
+	assert(cache->resource);
+	DRV_LOG(DEBUG, "port %u matcher %p: refcnt %d--",
+		dev->data->port_id, (void *)cache,
+		rte_atomic32_read(&cache->refcnt));
+	if (rte_atomic32_dec_and_test(&cache->refcnt)) {
+		claim_zero(mlx5_glue->dv_destroy_flow_matcher(cache->resource));
+		LIST_REMOVE(cache, next);
+		rte_free(cache);
+		DRV_LOG(DEBUG, "port %u matcher %p: removed",
+			dev->data->port_id, (void *)cache);
+		return 0;
+	}
+	return 1;
+}
+
+/**
+ * Remove the flow from the NIC but keeps it in memory.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
+ * @param[in, out] flow
+ *   Pointer to flow structure.
+ */
+static void
+flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
+{
+	struct mlx5_flow_dv *dv;
+	struct mlx5_flow *dev_flow;
+
+	if (!flow)
+		return;
+	LIST_FOREACH(dev_flow, &flow->dev_flows, next) {
+		dv = &dev_flow->dv;
+		if (dv->flow) {
+			claim_zero(mlx5_glue->destroy_flow(dv->flow));
+			dv->flow = NULL;
+		}
+		if (dv->hrxq) {
+			if (flow->actions & MLX5_ACTION_DROP)
+				mlx5_hrxq_drop_release(dev);
+			else
+				mlx5_hrxq_release(dev, dv->hrxq);
+			dv->hrxq = NULL;
+		}
+	}
+	if (flow->counter)
+		flow->counter = NULL;
+}
+
+/**
+ * Remove the flow from the NIC and the memory.
+ *
+ * @param[in] dev
+ *   Pointer to the Ethernet device structure.
+ * @param[in, out] flow
+ *   Pointer to flow structure.
+ */
+static void
+flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
+{
+	struct mlx5_flow *dev_flow;
+
+	if (!flow)
+		return;
+	flow_dv_remove(dev, flow);
+	while (!LIST_EMPTY(&flow->dev_flows)) {
+		dev_flow = LIST_FIRST(&flow->dev_flows);
+		LIST_REMOVE(dev_flow, next);
+		if (dev_flow->dv.matcher)
+			flow_dv_matcher_release(dev, dev_flow->dv.matcher);
+		rte_free(dev_flow);
+	}
+}
+
+/**
  * Fills the flow_ops with the function pointers.
  *
  * @param[out] flow_ops
@@ -1180,9 +1364,9 @@ mlx5_flow_dv_get_driver_ops(struct mlx5_flow_driver_ops *flow_ops)
 		.validate = flow_dv_validate,
 		.prepare = flow_dv_prepare,
 		.translate = flow_dv_translate,
-		.apply = NULL,
-		.remove = NULL,
-		.destroy = NULL,
+		.apply = flow_dv_apply,
+		.remove = flow_dv_remove,
+		.destroy = flow_dv_destroy,
 	};
 }
 
-- 
2.11.0

  parent reply	other threads:[~2018-09-24 23:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-19  7:21 [dpdk-dev] [PATCH 0/3] migrate Linux TC flower driver to new flow engine Yongseok Koh
2018-09-19  7:21 ` [dpdk-dev] [PATCH 1/3] net/mlx5: add abstraction for multiple flow drivers Yongseok Koh
2018-09-19  7:21 ` [dpdk-dev] [PATCH 2/3] net/mlx5: remove Netlink flow driver Yongseok Koh
2018-09-19  7:21 ` [dpdk-dev] [PATCH 3/3] net/mlx5: add Linux TC flower driver for E-Switch flow Yongseok Koh
2018-09-24 19:55 ` [dpdk-dev] [PATCH v2 0/3] net/mlx5: migrate Linux TC flower driver to new flow engine Yongseok Koh
2018-09-24 19:55   ` [dpdk-dev] [PATCH v2 1/3] net/mlx5: add abstraction for multiple flow drivers Yongseok Koh
2018-09-24 19:55   ` [dpdk-dev] [PATCH v2 2/3] net/mlx5: remove Netlink flow driver Yongseok Koh
2018-09-24 19:55   ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: add Linux TC flower driver for E-Switch flow Yongseok Koh
2018-10-04 16:16   ` [dpdk-dev] [PATCH v2 0/3] net/mlx5: migrate Linux TC flower driver to new flow engine Thomas Monjalon
2018-09-24 23:17 ` [dpdk-dev] [PATCH v3 00/11] net/mlx5: add Direct Verbs flow driver support Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 01/11] net/mlx5: split flow validation to dedicated function Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 02/11] net/mlx5: add flow prepare function Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 03/11] net/mlx5: add flow translate function Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 04/11] net/mlx5: add support for multiple flow drivers Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 05/11] net/mlx5: add Direct Verbs validation function Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 06/11] net/mlx5: add Direct Verbs prepare function Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 07/11] net/mlx5: add Direct Verbs translate items Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 08/11] net/mlx5: add Direct Verbs translate actions Yongseok Koh
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 09/11] net/mlx5: add Direct Verbs driver to glue Yongseok Koh
2018-09-24 23:17   ` Yongseok Koh [this message]
2018-09-24 23:17   ` [dpdk-dev] [PATCH v3 11/11] net/mlx5: add runtime parameter to enable Direct Verbs Yongseok Koh
2018-10-04 16:17   ` [dpdk-dev] [PATCH v3 00/11] net/mlx5: add Direct Verbs flow driver support Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180924231721.15799-11-yskoh@mellanox.com \
    --to=yskoh@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=orika@mellanox.com \
    --cc=shahafs@mellanox.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).