diff mbox

[rdma-core,4/4] mlx5: Introduce mlx5dv_create_flow

Message ID 1531151530-19188-5-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 mlx5dv_create_flow API to be used for creating ibv_flow object
with device specific properties.

The common ibv_destroy_flow should be used to destroy the created
object.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
---
 debian/ibverbs-providers.symbols |  1 +
 providers/mlx5/libmlx5.map       |  1 +
 providers/mlx5/mlx5dv.h          | 24 ++++++++++++++++++
 providers/mlx5/verbs.c           | 55 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+)
diff mbox

Patch

diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols
index f0c54f8..11ea417 100644
--- a/debian/ibverbs-providers.symbols
+++ b/debian/ibverbs-providers.symbols
@@ -23,3 +23,4 @@  libmlx5.so.1 ibverbs-providers #MINVER#
  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
+ mlx5dv_create_flow@MLX5_1.6 20
diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map
index 8538f5e..7501fa7 100644
--- a/providers/mlx5/libmlx5.map
+++ b/providers/mlx5/libmlx5.map
@@ -38,4 +38,5 @@  MLX5_1.6 {
         global:
 		mlx5dv_create_flow_matcher;
 		mlx5dv_destroy_flow_matcher;
+		mlx5dv_create_flow;
 } MLX5_1.5;
diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h
index 9710133..fa0fca2 100644
--- a/providers/mlx5/mlx5dv.h
+++ b/providers/mlx5/mlx5dv.h
@@ -216,6 +216,30 @@  mlx5dv_create_flow_matcher(struct ibv_context *context,
 
 int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *matcher);
 
+enum mlx5dv_flow_action_type {
+	MLX5DV_FLOW_ACTION_DEST_IBV_QP,
+	MLX5DV_FLOW_ACTION_DROP,
+	MLX5DV_FLOW_ACTION_IBV_COUNTER,
+	MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION,
+	MLX5DV_FLOW_ACTION_TAG,
+};
+
+struct mlx5dv_flow_action_attr {
+	enum mlx5dv_flow_action_type type;
+	union {
+		struct ibv_qp *qp;
+		struct ibv_counters *counter;
+		struct ibv_flow_action *action;
+		uint32_t tag_value;
+	};
+};
+
+struct ibv_flow *
+mlx5dv_create_flow(struct mlx5dv_flow_matcher *matcher,
+		   struct mlx5dv_flow_match_parameters *match_value,
+		   size_t num_actions,
+		   struct mlx5dv_flow_action_attr actions_attr[]);
+
 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 2654c45..2913de5 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -3611,3 +3611,58 @@  int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *flow_matcher)
 	free(flow_matcher);
 	return 0;
 }
+
+struct ibv_flow *
+mlx5dv_create_flow(struct mlx5dv_flow_matcher *flow_matcher,
+		   struct mlx5dv_flow_match_parameters *match_value,
+		   size_t num_actions,
+		   struct mlx5dv_flow_action_attr actions_attr[])
+{
+	struct mlx5_flow *mflow;
+	int ret;
+	DECLARE_COMMAND_BUFFER_LINK(cmd, UVERBS_OBJECT_FLOW,
+				    MLX5_IB_METHOD_CREATE_FLOW,
+				    4,
+				    NULL);
+	struct ib_uverbs_attr *handle;
+	enum mlx5dv_flow_action_type type;
+
+	if (num_actions != 1) {
+		errno = EOPNOTSUPP;
+		return NULL;
+	}
+
+	mflow = calloc(1, sizeof(*mflow));
+	if (!mflow) {
+		errno = ENOMEM;
+		return NULL;
+	}
+
+	handle = fill_attr_out_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_HANDLE);
+	fill_attr_in(cmd, MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE,
+		    match_value->match_buf,
+		    match_value->match_sz);
+	fill_attr_in_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_MATCHER, flow_matcher->handle);
+
+	type = actions_attr[0].type;
+	switch (type) {
+	case MLX5DV_FLOW_ACTION_DEST_IBV_QP:
+		fill_attr_in_obj(cmd, MLX5_IB_ATTR_CREATE_FLOW_DEST_QP,
+				actions_attr[0].qp->handle);
+		break;
+	default:
+		errno = EOPNOTSUPP;
+		goto err;
+	}
+
+	ret = execute_ioctl(flow_matcher->context, cmd);
+	if (ret)
+		goto err;
+
+	mflow->flow_id.handle = read_attr_obj(MLX5_IB_ATTR_CREATE_FLOW_HANDLE, handle);
+	mflow->flow_id.context = flow_matcher->context;
+	return &mflow->flow_id;
+err:
+	free(mflow);
+	return NULL;
+}