diff mbox series

[v2,12/13] net/mlx5: separate VLAN strip modification

Message ID 20200825093116.26538-13-ophirmu@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers show
Series mlx5 PMD multi OS support - part #4 | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ophir Munk Aug. 25, 2020, 9:31 a.m. UTC
From: Ophir Munk <ophirmu@mellanox.com>

When updating a queue vlan stripping offload - either the WQ is modified
in Verbs or the RQ is modified in DevX.  Add a vlan stripping modify
callback to 'struct mlx5_obj_ops' and assign it with the specific Verbs
and DevX implementations: 'rxq_obj_modify_wq_vlan_strip' and
'rxq_obj_modify_rq_vlan_strip' respectively.

Signed-off-by: Ophir Munk <ophirmu@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
---
 drivers/net/mlx5/linux/mlx5_verbs.c | 28 ++++++++++++++++++++++
 drivers/net/mlx5/mlx5.h             |  6 +++++
 drivers/net/mlx5/mlx5_devx.c        | 48 +++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_devx.h        | 12 ++++++++++
 drivers/net/mlx5/mlx5_vlan.c        | 27 ++++-----------------
 5 files changed, 98 insertions(+), 23 deletions(-)
 create mode 100644 drivers/net/mlx5/mlx5_devx.c
 create mode 100644 drivers/net/mlx5/mlx5_devx.h
diff mbox series

Patch

diff --git a/drivers/net/mlx5/linux/mlx5_verbs.c b/drivers/net/mlx5/linux/mlx5_verbs.c
index d41b0fe..6271f0f 100644
--- a/drivers/net/mlx5/linux/mlx5_verbs.c
+++ b/drivers/net/mlx5/linux/mlx5_verbs.c
@@ -19,6 +19,7 @@ 
 #include <mlx5_glue.h>
 #include <mlx5_common.h>
 #include <mlx5_common_mr.h>
+#include <mlx5_rxtx.h>
 #include <mlx5_verbs.h>
 /**
  * Register mr. Given protection domain pointer, pointer to addr and length
@@ -61,3 +62,30 @@  const struct mlx5_verbs_ops mlx5_verbs_ops = {
 	.reg_mr = mlx5_reg_mr,
 	.dereg_mr = mlx5_dereg_mr,
 };
+
+/**
+ * Modify Rx WQ vlan stripping offload
+ *
+ * @param rxq_obj
+ *   Rx queue object.
+ *
+ * @return 0 on success, non-0 otherwise
+ */
+static int
+mlx5_rxq_obj_modify_wq_vlan_strip(struct mlx5_rxq_obj *rxq_obj, int on)
+{
+	uint16_t vlan_offloads =
+		(on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
+		0;
+	struct ibv_wq_attr mod;
+	mod = (struct ibv_wq_attr){
+		.attr_mask = IBV_WQ_ATTR_FLAGS,
+		.flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
+		.flags = vlan_offloads,
+	};
+	return mlx5_glue->modify_wq(rxq_obj->wq, &mod);
+}
+
+struct mlx5_obj_ops ibv_obj_ops = {
+	.rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_wq_vlan_strip,
+};
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 34d7a15..431f861 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -676,6 +676,11 @@  TAILQ_HEAD(mlx5_flow_meters, mlx5_flow_meter);
 #define MLX5_PROC_PRIV(port_id) \
 	((struct mlx5_proc_priv *)rte_eth_devices[port_id].process_private)
 
+/* HW objects operations structure. */
+struct mlx5_obj_ops {
+	int (*rxq_obj_modify_vlan_strip)(struct mlx5_rxq_obj *rxq_obj, int on);
+};
+
 struct mlx5_priv {
 	struct rte_eth_dev_data *dev_data;  /* Pointer to device data. */
 	struct mlx5_dev_ctx_shared *sh; /* Shared device context. */
@@ -719,6 +724,7 @@  struct mlx5_priv {
 	void *rss_desc; /* Intermediate rss description resources. */
 	int flow_idx; /* Intermediate device flow index. */
 	int flow_nested_idx; /* Intermediate device flow index, nested. */
+	struct mlx5_obj_ops *obj_ops; /* HW objects operations. */
 	LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */
 	LIST_HEAD(rxqobj, mlx5_rxq_obj) rxqsobj; /* Verbs/DevX Rx queues. */
 	uint32_t hrxqs; /* Verbs Hash Rx queues. */
diff --git a/drivers/net/mlx5/mlx5_devx.c b/drivers/net/mlx5/mlx5_devx.c
new file mode 100644
index 0000000..7340412
--- /dev/null
+++ b/drivers/net/mlx5/mlx5_devx.c
@@ -0,0 +1,48 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#include <stddef.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <sys/queue.h>
+
+#include <rte_malloc.h>
+#include <rte_common.h>
+#include <rte_eal_paging.h>
+
+#include <mlx5_glue.h>
+#include <mlx5_devx_cmds.h>
+#include <mlx5_malloc.h>
+
+#include "mlx5.h"
+#include "mlx5_common_os.h"
+#include "mlx5_rxtx.h"
+#include "mlx5_utils.h"
+#include "mlx5_devx.h"
+
+/**
+ * Modify RQ vlan stripping offload
+ *
+ * @param rxq_obj
+ *   Rx queue object.
+ *
+ * @return 0 on success, non-0 otherwise
+ */
+static int
+mlx5_rxq_obj_modify_rq_vlan_strip(struct mlx5_rxq_obj *rxq_obj, int on)
+{
+	struct mlx5_devx_modify_rq_attr rq_attr;
+
+	memset(&rq_attr, 0, sizeof(rq_attr));
+	rq_attr.rq_state = MLX5_RQC_STATE_RDY;
+	rq_attr.state = MLX5_RQC_STATE_RDY;
+	rq_attr.vsd = (on ? 0 : 1);
+	rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD;
+	return mlx5_devx_cmd_modify_rq(rxq_obj->rq, &rq_attr);
+}
+
+struct mlx5_obj_ops devx_obj_ops = {
+	.rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip,
+};
diff --git a/drivers/net/mlx5/mlx5_devx.h b/drivers/net/mlx5/mlx5_devx.h
new file mode 100644
index 0000000..844985c
--- /dev/null
+++ b/drivers/net/mlx5/mlx5_devx.h
@@ -0,0 +1,12 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+
+#ifndef RTE_PMD_MLX5_DEVX_H_
+#define RTE_PMD_MLX5_DEVX_H_
+
+#include "mlx5.h"
+
+extern struct mlx5_obj_ops devx_obj_ops;
+
+#endif /* RTE_PMD_MLX5_DEVX_H_ */
diff --git a/drivers/net/mlx5/mlx5_vlan.c b/drivers/net/mlx5/mlx5_vlan.c
index 89983a4..ea89599 100644
--- a/drivers/net/mlx5/mlx5_vlan.c
+++ b/drivers/net/mlx5/mlx5_vlan.c
@@ -22,6 +22,7 @@ 
 #include "mlx5_autoconf.h"
 #include "mlx5_rxtx.h"
 #include "mlx5_utils.h"
+#include "mlx5_devx.h"
 
 /**
  * DPDK callback to configure a VLAN filter.
@@ -97,10 +98,6 @@  mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
 	struct mlx5_rxq_data *rxq = (*priv->rxqs)[queue];
 	struct mlx5_rxq_ctrl *rxq_ctrl =
 		container_of(rxq, struct mlx5_rxq_ctrl, rxq);
-	struct ibv_wq_attr mod;
-	uint16_t vlan_offloads =
-		(on ? IBV_WQ_FLAGS_CVLAN_STRIPPING : 0) |
-		0;
 	int ret = 0;
 
 	/* Validate hw support */
@@ -115,30 +112,14 @@  mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
 			dev->data->port_id, queue);
 		return;
 	}
-	DRV_LOG(DEBUG, "port %u set VLAN offloads 0x%x for port %uqueue %d",
-		dev->data->port_id, vlan_offloads, rxq->port_id, queue);
+	DRV_LOG(DEBUG, "port %u set VLAN stripping offloads %d for port %uqueue %d",
+		dev->data->port_id, on, rxq->port_id, queue);
 	if (!rxq_ctrl->obj) {
 		/* Update related bits in RX queue. */
 		rxq->vlan_strip = !!on;
 		return;
 	}
-	if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_IBV) {
-		mod = (struct ibv_wq_attr){
-			.attr_mask = IBV_WQ_ATTR_FLAGS,
-			.flags_mask = IBV_WQ_FLAGS_CVLAN_STRIPPING,
-			.flags = vlan_offloads,
-		};
-		ret = mlx5_glue->modify_wq(rxq_ctrl->obj->wq, &mod);
-	} else if (rxq_ctrl->obj->type == MLX5_RXQ_OBJ_TYPE_DEVX_RQ) {
-		struct mlx5_devx_modify_rq_attr rq_attr;
-
-		memset(&rq_attr, 0, sizeof(rq_attr));
-		rq_attr.rq_state = MLX5_RQC_STATE_RDY;
-		rq_attr.state = MLX5_RQC_STATE_RDY;
-		rq_attr.vsd = (on ? 0 : 1);
-		rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD;
-		ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq, &rq_attr);
-	}
+	ret = priv->obj_ops->rxq_obj_modify_vlan_strip(rxq_ctrl->obj, on);
 	if (ret) {
 		DRV_LOG(ERR, "port %u failed to modify object %d stripping "
 			"mode: %s", dev->data->port_id,