diff mbox

[rdma-core,3/4] mlx5: Introduce flow matcher and its related DV APIs

Message ID 1531151530-19188-4-git-send-email-yishaih@mellanox.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Yishai Hadas July 9, 2018, 3:52 p.m. UTC
Introduce mlx5 flow matcher object and its related DV APIs.
The flow matcher object matches to the device specification and enables
creating a flow object that supports the device options.

Downstream patches from this series use the matcher object as part of
flow creation.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
---
 debian/ibverbs-providers.symbols |  3 ++
 providers/mlx5/CMakeLists.txt    |  2 +-
 providers/mlx5/libmlx5.map       |  6 ++++
 providers/mlx5/mlx5.h            |  5 +++
 providers/mlx5/mlx5dv.h          | 22 +++++++++++++
 providers/mlx5/verbs.c           | 69 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 106 insertions(+), 1 deletion(-)

Comments

Jason Gunthorpe July 9, 2018, 4:50 p.m. UTC | #1
On Mon, Jul 09, 2018 at 06:52:09PM +0300, Yishai Hadas wrote:
> +struct mlx5dv_flow_matcher *
> +mlx5dv_create_flow_matcher(struct ibv_context *context,
> +			   struct mlx5dv_flow_matcher_attr *attr)
> +{
> +	DECLARE_COMMAND_BUFFER_LINK(cmd, MLX5_IB_OBJECT_FLOW_MATCHER,
> +				    MLX5_IB_METHOD_FLOW_MATCHER_CREATE,
> +				    4,
> +				    NULL);

Why is this using the LINK varient of the macro?

> +int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *flow_matcher)
> +{
> +	DECLARE_COMMAND_BUFFER(cmd, MLX5_IB_OBJECT_FLOW_MATCHER,
> +			       MLX5_IB_METHOD_FLOW_MATCHER_DESTROY,
> +			       1);
> +	int ret;

Why not like this?

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yishai Hadas July 10, 2018, 11:04 a.m. UTC | #2
On 7/9/2018 7:50 PM, Jason Gunthorpe wrote:
> On Mon, Jul 09, 2018 at 06:52:09PM +0300, Yishai Hadas wrote:
>> +struct mlx5dv_flow_matcher *
>> +mlx5dv_create_flow_matcher(struct ibv_context *context,
>> +			   struct mlx5dv_flow_matcher_attr *attr)
>> +{
>> +	DECLARE_COMMAND_BUFFER_LINK(cmd, MLX5_IB_OBJECT_FLOW_MATCHER,
>> +				    MLX5_IB_METHOD_FLOW_MATCHER_CREATE,
>> +				    4,
>> +				    NULL);
> 
> Why is this using the LINK varient of the macro?
> 

Thanks, the PR [1] was updated to use the DECLARE_COMMAND_BUFFER variant.

[1] https://github.com/linux-rdma/rdma-core/pull/356
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols
index 3143f6f..f0c54f8 100644
--- a/debian/ibverbs-providers.symbols
+++ b/debian/ibverbs-providers.symbols
@@ -11,6 +11,7 @@  libmlx5.so.1 ibverbs-providers #MINVER#
  MLX5_1.3@MLX5_1.3 16
  MLX5_1.4@MLX5_1.4 17
  MLX5_1.5@MLX5_1.5 18
+ MLX5_1.6@MLX5_1.6 20
  mlx5dv_init_obj@MLX5_1.0 13
  mlx5dv_init_obj@MLX5_1.2 15
  mlx5dv_query_device@MLX5_1.0 13
@@ -20,3 +21,5 @@  libmlx5.so.1 ibverbs-providers #MINVER#
  mlx5dv_create_wq@MLX5_1.3 16
  mlx5dv_get_clock_info@MLX5_1.4 17
  mlx5dv_create_flow_action_esp@MLX5_1.5 18
+ mlx5dv_create_flow_matcher@MLX5_1.6 20
+ mlx5dv_destroy_flow_matcher@MLX5_1.6 20
diff --git a/providers/mlx5/CMakeLists.txt b/providers/mlx5/CMakeLists.txt
index 5a4b47f..7328c56 100644
--- a/providers/mlx5/CMakeLists.txt
+++ b/providers/mlx5/CMakeLists.txt
@@ -11,7 +11,7 @@  if (MLX5_MW_DEBUG)
 endif()
 
 rdma_shared_provider(mlx5 libmlx5.map
-  1 1.5.${PACKAGE_VERSION}
+  1 1.6.${PACKAGE_VERSION}
   buf.c
   cq.c
   dbrec.c
diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map
index 410cc0e..8538f5e 100644
--- a/providers/mlx5/libmlx5.map
+++ b/providers/mlx5/libmlx5.map
@@ -33,3 +33,9 @@  MLX5_1.5 {
 	global:
 		mlx5dv_create_flow_action_esp;
 } MLX5_1.4;
+
+MLX5_1.6 {
+        global:
+		mlx5dv_create_flow_matcher;
+		mlx5dv_destroy_flow_matcher;
+} MLX5_1.5;
diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h
index 16ce2cc..16404a8 100644
--- a/providers/mlx5/mlx5.h
+++ b/providers/mlx5/mlx5.h
@@ -557,6 +557,11 @@  struct mlx5_flow {
 	struct mlx5_counters *mcounters;
 };
 
+struct mlx5dv_flow_matcher {
+	struct ibv_context *context;
+	uint32_t handle;
+};
+
 static inline int mlx5_ilog2(int n)
 {
 	int t;
diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h
index acf0a13..9710133 100644
--- a/providers/mlx5/mlx5dv.h
+++ b/providers/mlx5/mlx5dv.h
@@ -194,6 +194,28 @@  struct mlx5dv_flow_action_esp {
 	uint32_t action_flags; /* Use enum mlx5dv_flow_action_flags */
 };
 
+struct mlx5dv_flow_match_parameters {
+	size_t match_sz;
+	uint64_t match_buf[]; /* Device spec format */
+};
+
+struct mlx5dv_flow_matcher_attr {
+	enum ibv_flow_attr_type type;
+	uint32_t flags; /* From enum ibv_flow_flags */
+	uint16_t priority;
+	uint8_t match_criteria_enable; /* Device spec format */
+	struct mlx5dv_flow_match_parameters *match_mask;
+	uint64_t comp_mask;
+};
+
+struct mlx5dv_flow_matcher;
+
+struct mlx5dv_flow_matcher *
+mlx5dv_create_flow_matcher(struct ibv_context *context,
+			   struct mlx5dv_flow_matcher_attr *matcher_attr);
+
+int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *matcher);
+
 struct ibv_flow_action *mlx5dv_create_flow_action_esp(struct ibv_context *ctx,
 						      struct ibv_flow_action_esp_attr *esp,
 						      struct mlx5dv_flow_action_esp *mlx5_attr);
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
index e95cdb8..2654c45 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -3542,3 +3542,72 @@  int mlx5_read_counters(struct ibv_counters *counters,
 				     NULL);
 
 }
+
+struct mlx5dv_flow_matcher *
+mlx5dv_create_flow_matcher(struct ibv_context *context,
+			   struct mlx5dv_flow_matcher_attr *attr)
+{
+	DECLARE_COMMAND_BUFFER_LINK(cmd, MLX5_IB_OBJECT_FLOW_MATCHER,
+				    MLX5_IB_METHOD_FLOW_MATCHER_CREATE,
+				    4,
+				    NULL);
+	struct mlx5dv_flow_matcher *flow_matcher;
+	struct ib_uverbs_attr *handle;
+	int ret;
+
+	if (!check_comp_mask(attr->comp_mask, 0)) {
+		errno = EOPNOTSUPP;
+		return NULL;
+	}
+
+	flow_matcher = calloc(1, sizeof(*flow_matcher));
+	if (!flow_matcher) {
+		errno = ENOMEM;
+		return NULL;
+	}
+
+	if (attr->type !=  IBV_FLOW_ATTR_NORMAL) {
+		errno = EOPNOTSUPP;
+		goto err;
+	}
+
+	handle = fill_attr_out_obj(cmd, MLX5_IB_ATTR_FLOW_MATCHER_CREATE_HANDLE);
+	fill_attr_in(cmd, MLX5_IB_ATTR_FLOW_MATCHER_MATCH_MASK,
+		     attr->match_mask->match_buf,
+		     attr->match_mask->match_sz);
+	fill_attr_in(cmd, MLX5_IB_ATTR_FLOW_MATCHER_MATCH_CRITERIA,
+		     &attr->match_criteria_enable, sizeof(attr->match_criteria_enable));
+	fill_attr_in_enum(cmd, MLX5_IB_ATTR_FLOW_MATCHER_FLOW_TYPE,
+			  IBV_FLOW_ATTR_NORMAL, &attr->priority,
+			  sizeof(attr->priority));
+
+	ret = execute_ioctl(context, cmd);
+	if (ret)
+		goto err;
+
+	flow_matcher->context = context;
+	flow_matcher->handle = read_attr_obj(MLX5_IB_ATTR_FLOW_MATCHER_CREATE_HANDLE, handle);
+
+	return flow_matcher;
+
+err:
+	free(flow_matcher);
+	return NULL;
+}
+
+int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *flow_matcher)
+{
+	DECLARE_COMMAND_BUFFER(cmd, MLX5_IB_OBJECT_FLOW_MATCHER,
+			       MLX5_IB_METHOD_FLOW_MATCHER_DESTROY,
+			       1);
+	int ret;
+
+	fill_attr_in_obj(cmd, MLX5_IB_ATTR_FLOW_MATCHER_DESTROY_HANDLE, flow_matcher->handle);
+	ret = execute_ioctl(flow_matcher->context, cmd);
+
+	if (ret)
+		return ret;
+
+	free(flow_matcher);
+	return 0;
+}