[RFC,16/21] common/mlx5: add HCA attributes to context device structure

Message ID 20210817134441.1966618-17-michaelba@nvidia.com (mailing list archive)
State RFC, archived
Delegated to: Raslan Darawsheh
Headers
Series mlx5: sharing global MR cache between drivers |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michael Baum Aug. 17, 2021, 1:44 p.m. UTC
  Add HCA attributes structure as a field of context device structure.
It query in common probing, and check if the device supports the chosen
classes.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
 drivers/common/mlx5/mlx5_common.c | 67 ++++++++++++++++++++++++++++++-
 drivers/common/mlx5/mlx5_common.h |  9 +++--
 2 files changed, 70 insertions(+), 6 deletions(-)
  

Patch

diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index b500e7834e..e4c1984700 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -310,6 +310,56 @@  mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size)
 #endif
 }
 
+/**
+ * Validate HCA attributes.
+ *
+ * @param attr
+ *   Attributes device values.
+ * @param classes
+ *   Chosen classes come from device arguments.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+mlx5_hca_attr_validate(struct mlx5_hca_attr *attr, uint32_t classes)
+{
+	if (classes & MLX5_CLASS_VDPA) {
+		if (!attr->vdpa.valid || !attr->vdpa.max_num_virtio_queues) {
+			DRV_LOG(ERR,
+				"Not enough capabilities to support vDPA, maybe old FW/OFED version?");
+			rte_errno = ENOTSUP;
+			return -rte_errno;
+		}
+	}
+	if (classes & MLX5_CLASS_REGEX) {
+		if (!attr->regex || attr->regexp_num_of_engines == 0) {
+			DRV_LOG(ERR,
+				"Not enough capabilities to support RegEx, maybe old FW/OFED version?");
+			rte_errno = ENOTSUP;
+			return -rte_errno;
+		}
+	}
+	if (classes & MLX5_CLASS_COMPRESS) {
+		if (attr->mmo_compress_en == 0 ||
+		    attr->mmo_decompress_en == 0 || attr->mmo_dma_en == 0) {
+			DRV_LOG(ERR,
+				"Not enough capabilities to support compress operations, maybe old FW/OFED version?");
+			rte_errno = ENOTSUP;
+			return -ENOTSUP;
+		}
+	}
+	if (classes & MLX5_CLASS_CRYPTO) {
+		if (attr->crypto == 0 || attr->aes_xts == 0) {
+			DRV_LOG(ERR,
+				"Not enough capabilities to support crypto operations, maybe old FW/OFED version?");
+			rte_errno = ENOTSUP;
+			return -ENOTSUP;
+		}
+	}
+	return 0;
+}
+
 /**
  * Uninitialize context device and release all its resources.
  *
@@ -379,6 +429,13 @@  mlx5_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev,
 	ret = mlx5_os_pd_create(dev_ctx);
 	if (ret)
 		goto error;
+	/* Query HCA attributes. */
+	ret = mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &dev_ctx->hca_attr);
+	if (ret) {
+		DRV_LOG(ERR, "Unable to read HCA capabilities.");
+		rte_errno = ENOTSUP;
+		goto error;
+	}
 	return ret;
 error:
 	mlx5_dev_ctx_release(dev_ctx);
@@ -507,13 +564,19 @@  mlx5_common_dev_probe(struct rte_device *eal_dev)
 		new_device = true;
 	} else {
 		/* Validate combination here. */
-		ret = is_valid_class_combination(classes |
-						 dev->classes_loaded);
+		ret = is_valid_class_combination(classes | dev->classes_loaded);
 		if (ret != 0) {
 			DRV_LOG(ERR, "Unsupported mlx5 classes combination.");
 			return ret;
 		}
 	}
+	if (dev->ctx.ctx) {
+		/* Validate HCA attributes here. */
+		ret = mlx5_hca_attr_validate(&dev->ctx.hca_attr,
+					     classes | dev->classes_loaded);
+		if (ret)
+			goto class_err;
+	}
 	ret = drivers_probe(dev, classes);
 	if (ret)
 		goto class_err;
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 644dc58bc9..da03e160d2 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -329,10 +329,11 @@  void mlx5_common_init(void);
  * Contains HW device objects which belong to same device with multiple drivers.
  */
 struct mlx5_dev_ctx {
-	void *ctx;	/* Verbs/DV/DevX context. */
-	void *pd;	/* Protection Domain. */
-	uint32_t pdn;	/* Protection Domain Number. */
-	int numa_node;	/* Numa node of device. */
+	void *ctx;			/* Verbs/DV/DevX context. */
+	void *pd;			/* Protection Domain. */
+	uint32_t pdn;			/* Protection Domain Number. */
+	int numa_node;			/* Numa node of device. */
+	struct mlx5_hca_attr hca_attr;  /* HCA attributes. */
 };
 
 struct mlx5_common_device {