History

RDMA/mlx5: Add flow actions support to raw create flow

Support attaching flow actions to a flow rule via raw create flow. For now only NIC RX path is supported. This change requires to export flow resources management functions so we can maintain proper bookkeeping of flow actions.

Mark Bloch committed 8 years ago

Commit fa76d241 parent b823dd64 files · +50 −8Browse files

Unified · Split

4 files
  1. drivers/infiniband/core/uverbs_cmd.c +7 −4
  2. drivers/infiniband/hw/mlx5/flow.c +36 −4
  3. include/rdma/uverbs_std_types.h +6 −0
  4. include/uapi/rdma/mlx5_user_ioctl_cmds.h +1 −0
drivers/infiniband/core/uverbs_cmd.c+7−4
@@ -2747,7 +2747,7 @@ out_put: · 2746 unmodified lines
2747 return ret ? ret : in_len;2747 return ret ? ret : in_len;
2748}2748}
2749 2749
2750static struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)2750struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
2751{2751{
2752 struct ib_uflow_resources *resources;2752 struct ib_uflow_resources *resources;
2753 2753
@@ -2777,6 +2777,7 @@ err: · 23 unmodified lines
2777 2777
2778 return NULL;2778 return NULL;
2779}2779}
2780EXPORT_SYMBOL(flow_resources_alloc);
2780 2781
2781void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res)2782void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res)
2782{2783{
@@ -2795,10 +2796,11 @@ void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res) · 12 unmodified lines
2795 kfree(uflow_res->counters);2796 kfree(uflow_res->counters);
2796 kfree(uflow_res);2797 kfree(uflow_res);
2797}2798}
2799EXPORT_SYMBOL(ib_uverbs_flow_resources_free);
2798 2800
2799static void flow_resources_add(struct ib_uflow_resources *uflow_res,2801void flow_resources_add(struct ib_uflow_resources *uflow_res,
2800 enum ib_flow_spec_type type,2802 enum ib_flow_spec_type type,
2801 void *ibobj)2803 void *ibobj)
2802{2804{
2803 WARN_ON(uflow_res->num >= uflow_res->max);2805 WARN_ON(uflow_res->num >= uflow_res->max);
2804 2806
@@ -2819,6 +2821,7 @@ static void flow_resources_add(struct ib_uflow_resources *uflow_res, · 14 unmodified lines
2819 2821
2820 uflow_res->num++;2822 uflow_res->num++;
2821}2823}
2824EXPORT_SYMBOL(flow_resources_add);
2822 2825
2823static int kern_spec_to_ib_spec_action(struct ib_uverbs_file *ufile,2826static int kern_spec_to_ib_spec_action(struct ib_uverbs_file *ufile,
2824 struct ib_uverbs_flow_spec *kern_spec,2827 struct ib_uverbs_flow_spec *kern_spec,
drivers/infiniband/hw/mlx5/flow.c+36−4
@@ -58,12 +58,15 @@ static const struct uverbs_attr_spec mlx5_ib_flow_type[] = { · 57 unmodified lines
58 },58 },
59};59};
60 60
61#define MLX5_IB_CREATE_FLOW_MAX_FLOW_ACTIONS 2
61static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(62static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
62 struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)63 struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
63{64{
64 struct mlx5_flow_act flow_act = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG};65 struct mlx5_flow_act flow_act = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG};
65 struct mlx5_ib_flow_handler *flow_handler;66 struct mlx5_ib_flow_handler *flow_handler;
66 struct mlx5_ib_flow_matcher *fs_matcher;67 struct mlx5_ib_flow_matcher *fs_matcher;
68 struct ib_uobject **arr_flow_actions;
69 struct ib_uflow_resources *uflow_res;
67 void *devx_obj;70 void *devx_obj;
68 int dest_id, dest_type;71 int dest_id, dest_type;
69 void *cmd_in;72 void *cmd_in;
@@ -73,6 +76,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)( · 3 unmodified lines
73 struct ib_uobject *uobj =76 struct ib_uobject *uobj =
74 uverbs_attr_get_uobject(attrs, MLX5_IB_ATTR_CREATE_FLOW_HANDLE);77 uverbs_attr_get_uobject(attrs, MLX5_IB_ATTR_CREATE_FLOW_HANDLE);
75 struct mlx5_ib_dev *dev = to_mdev(uobj->context->device);78 struct mlx5_ib_dev *dev = to_mdev(uobj->context->device);
79 int len, ret, i;
76 80
77 if (!capable(CAP_NET_RAW))81 if (!capable(CAP_NET_RAW))
78 return -EPERM;82 return -EPERM;
@@ -124,15 +128,38 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)( · 45 unmodified lines
124 MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE);128 MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE);
125 fs_matcher = uverbs_attr_get_obj(attrs,129 fs_matcher = uverbs_attr_get_obj(attrs,
126 MLX5_IB_ATTR_CREATE_FLOW_MATCHER);130 MLX5_IB_ATTR_CREATE_FLOW_MATCHER);
131
132 uflow_res = flow_resources_alloc(MLX5_IB_CREATE_FLOW_MAX_FLOW_ACTIONS);
133 if (!uflow_res)
134 return -ENOMEM;
135
136 len = uverbs_attr_get_uobjs_arr(attrs,
137 MLX5_IB_ATTR_CREATE_FLOW_ARR_FLOW_ACTIONS, &arr_flow_actions);
138 for (i = 0; i < len; i++) {
139 struct mlx5_ib_flow_action *maction =
140 to_mflow_act(arr_flow_actions[i]->object);
141
142 ret = parse_flow_flow_action(maction, false, &flow_act);
143 if (ret)
144 goto err_out;
145 flow_resources_add(uflow_res, IB_FLOW_SPEC_ACTION_HANDLE,
146 arr_flow_actions[i]->object);
147 }
148
127 flow_handler = mlx5_ib_raw_fs_rule_add(dev, fs_matcher, &flow_act,149 flow_handler = mlx5_ib_raw_fs_rule_add(dev, fs_matcher, &flow_act,
128 cmd_in, inlen,150 cmd_in, inlen,
129 dest_id, dest_type);151 dest_id, dest_type);
130 if (IS_ERR(flow_handler))152 if (IS_ERR(flow_handler)) {
131 return PTR_ERR(flow_handler);153 ret = PTR_ERR(flow_handler);
154 goto err_out;
155 }
132 156
133 ib_set_flow(uobj, &flow_handler->ibflow, qp, &dev->ib_dev, NULL);157 ib_set_flow(uobj, &flow_handler->ibflow, qp, &dev->ib_dev, uflow_res);
134 158
135 return 0;159 return 0;
160err_out:
161 ib_uverbs_flow_resources_free(uflow_res);
162 return ret;
136}163}
137 164
138static int flow_matcher_cleanup(struct ib_uobject *uobject,165static int flow_matcher_cleanup(struct ib_uobject *uobject,
@@ -459,7 +486,12 @@ DECLARE_UVERBS_NAMED_METHOD( · 320 unmodified lines
459 UVERBS_ACCESS_READ),486 UVERBS_ACCESS_READ),
460 UVERBS_ATTR_IDR(MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX,487 UVERBS_ATTR_IDR(MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX,
461 MLX5_IB_OBJECT_DEVX_OBJ,488 MLX5_IB_OBJECT_DEVX_OBJ,
462 UVERBS_ACCESS_READ));489 UVERBS_ACCESS_READ),
490 UVERBS_ATTR_IDRS_ARR(MLX5_IB_ATTR_CREATE_FLOW_ARR_FLOW_ACTIONS,
491 UVERBS_OBJECT_FLOW_ACTION,
492 UVERBS_ACCESS_READ, 1,
493 MLX5_IB_CREATE_FLOW_MAX_FLOW_ACTIONS,
494 UA_OPTIONAL));
463 495
464DECLARE_UVERBS_NAMED_METHOD_DESTROY(496DECLARE_UVERBS_NAMED_METHOD_DESTROY(
465 MLX5_IB_METHOD_DESTROY_FLOW,497 MLX5_IB_METHOD_DESTROY_FLOW,
include/rdma/uverbs_std_types.h+6−0
@@ -166,6 +166,12 @@ struct ib_uflow_object { · 165 unmodified lines
166 struct ib_uflow_resources *resources;166 struct ib_uflow_resources *resources;
167};167};
168 168
169struct ib_uflow_resources *flow_resources_alloc(size_t num_specs);
170void flow_resources_add(struct ib_uflow_resources *uflow_res,
171 enum ib_flow_spec_type type,
172 void *ibobj);
173void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res);
174
169static inline void ib_set_flow(struct ib_uobject *uobj, struct ib_flow *ibflow,175static inline void ib_set_flow(struct ib_uobject *uobj, struct ib_flow *ibflow,
170 struct ib_qp *qp, struct ib_device *device,176 struct ib_qp *qp, struct ib_device *device,
171 struct ib_uflow_resources *uflow_res)177 struct ib_uflow_resources *uflow_res)
include/uapi/rdma/mlx5_user_ioctl_cmds.h+1−0
@@ -155,6 +155,7 @@ enum mlx5_ib_create_flow_attrs { · 154 unmodified lines
155 MLX5_IB_ATTR_CREATE_FLOW_DEST_QP,155 MLX5_IB_ATTR_CREATE_FLOW_DEST_QP,
156 MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX,156 MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX,
157 MLX5_IB_ATTR_CREATE_FLOW_MATCHER,157 MLX5_IB_ATTR_CREATE_FLOW_MATCHER,
158 MLX5_IB_ATTR_CREATE_FLOW_ARR_FLOW_ACTIONS,
158};159};
159 160
160enum mlx5_ib_destoy_flow_attrs {161enum mlx5_ib_destoy_flow_attrs {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t