[17/20] net/mlx5: using function to detect operation by DevX

Message ID 20220127153950.812953-18-michaelba@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series mlx5: refactor devargs management |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michael Baum Jan. 27, 2022, 3:39 p.m. UTC
Add inline function indicating whether HW objects operations can be
created by DevX. It makes the code more readable.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_os.c |  6 ++----
 drivers/net/mlx5/mlx5.h          | 24 ++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_ethdev.c   |  3 +--
 drivers/net/mlx5/mlx5_trigger.c  |  3 +--
 4 files changed, 28 insertions(+), 8 deletions(-)
  

Patch

diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 50cc287e73..c432cf0858 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -370,8 +370,7 @@  mlx5_os_capabilities_prepare(struct mlx5_dev_ctx_shared *sh)
 	sh->dev_cap.txpp_en = 0;
 #endif
 	/* Check for LRO support. */
-	if (sh->dev_cap.dest_tir && sh->dev_cap.dv_flow_en &&
-	    hca_attr->lro_cap) {
+	if (mlx5_devx_obj_ops_en(sh) && hca_attr->lro_cap) {
 		/* TBD check tunnel lro caps. */
 		sh->dev_cap.lro_supported = 1;
 		DRV_LOG(DEBUG, "Device supports LRO.");
@@ -1550,8 +1549,7 @@  mlx5_dev_spawn(struct rte_device *dpdk_dev,
 		if (mlx5_flex_item_port_init(eth_dev) < 0)
 			goto error;
 	}
-	if (sh->cdev->config.devx && sh->config.dv_flow_en &&
-	    sh->dev_cap.dest_tir) {
+	if (mlx5_devx_obj_ops_en(sh)) {
 		priv->obj_ops = devx_obj_ops;
 		mlx5_queue_counter_id_prepare(eth_dev);
 		priv->obj_ops.lb_dummy_queue_create =
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 5ca48ef68f..46fa5131a7 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -1496,6 +1496,30 @@  enum dr_dump_rec_type {
 	DR_DUMP_REC_TYPE_PMD_COUNTER = 4430,
 };
 
+/**
+ * Indicates whether HW objects operations can be created by DevX.
+ *
+ * This function is used for both:
+ *  Before creation - deciding whether to create HW objects operations by DevX.
+ *  After creation - indicator if HW objects operations were created by DevX.
+ *
+ * @param sh
+ *   Pointer to shared device context.
+ *
+ * @return
+ *   True if HW objects were created by DevX, False otherwise.
+ */
+static inline bool
+mlx5_devx_obj_ops_en(struct mlx5_dev_ctx_shared *sh)
+{
+	/*
+	 * When advanced DR API is available and DV flow is supported and
+	 * DevX is supported, HW objects operations are created by DevX.
+	 */
+	return (sh->cdev->config.devx && sh->config.dv_flow_en &&
+		sh->dev_cap.dest_tir);
+}
+
 /* mlx5.c */
 
 int mlx5_getenv_int(const char *);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 9e478db8df..d637dee98d 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -721,8 +721,7 @@  mlx5_hairpin_cap_get(struct rte_eth_dev *dev, struct rte_eth_hairpin_cap *cap)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
 
-	if (!priv->sh->cdev->config.devx || !priv->sh->dev_cap.dest_tir ||
-	    !priv->sh->config.dv_flow_en) {
+	if (!mlx5_devx_obj_ops_en(priv->sh)) {
 		rte_errno = ENOTSUP;
 		return -rte_errno;
 	}
diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c
index eb03e9f7b1..e234d11215 100644
--- a/drivers/net/mlx5/mlx5_trigger.c
+++ b/drivers/net/mlx5/mlx5_trigger.c
@@ -1104,8 +1104,7 @@  mlx5_dev_start(struct rte_eth_dev *dev)
 			dev->data->port_id, strerror(rte_errno));
 		goto error;
 	}
-	if ((priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en &&
-	     priv->sh->dev_cap.dest_tir) &&
+	if (mlx5_devx_obj_ops_en(priv->sh) &&
 	    priv->obj_ops.lb_dummy_queue_create) {
 		ret = priv->obj_ops.lb_dummy_queue_create(dev);
 		if (ret)