RDMA/mlx5: Refactor DV create flow

Move part of the code that get the destinations into function so the code
will be more readable.  In addition change the variables definition to be
in reversed christmas tree.

Link: https://lore.kernel.org/r/20200504053012.270689-4-leon@kernel.org
Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
Reviewed-by: Mark Zhang <markz@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:
Maor Gottlieb 2020-05-04 08:30:11 +03:00 committed by Jason Gunthorpe
parent 10c2615513
commit b9019507aa
1 changed files with 59 additions and 49 deletions

View File

@ -67,40 +67,18 @@ static const struct uverbs_attr_spec mlx5_ib_flow_type[] = {
}, },
}; };
#define MLX5_IB_CREATE_FLOW_MAX_FLOW_ACTIONS 2 static int get_dests(struct uverbs_attr_bundle *attrs,
static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)( struct mlx5_ib_flow_matcher *fs_matcher, int *dest_id,
struct uverbs_attr_bundle *attrs) int *dest_type, struct ib_qp **qp)
{ {
struct mlx5_flow_context flow_context = {.flow_tag = MLX5_FS_DEFAULT_FLOW_TAG};
struct mlx5_ib_flow_handler *flow_handler;
struct mlx5_ib_flow_matcher *fs_matcher;
struct ib_uobject **arr_flow_actions;
struct ib_uflow_resources *uflow_res;
struct mlx5_flow_act flow_act = {};
void *devx_obj;
int dest_id, dest_type;
void *cmd_in;
int inlen;
bool dest_devx, dest_qp; bool dest_devx, dest_qp;
struct ib_qp *qp = NULL; void *devx_obj;
struct ib_uobject *uobj =
uverbs_attr_get_uobject(attrs, MLX5_IB_ATTR_CREATE_FLOW_HANDLE);
struct mlx5_ib_dev *dev = mlx5_udata_to_mdev(&attrs->driver_udata);
int len, ret, i;
u32 counter_id = 0;
u32 *offset_attr;
u32 offset = 0;
if (!capable(CAP_NET_RAW)) dest_devx = uverbs_attr_is_valid(attrs,
return -EPERM; MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX);
dest_devx =
uverbs_attr_is_valid(attrs, MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX);
dest_qp = uverbs_attr_is_valid(attrs, dest_qp = uverbs_attr_is_valid(attrs,
MLX5_IB_ATTR_CREATE_FLOW_DEST_QP); MLX5_IB_ATTR_CREATE_FLOW_DEST_QP);
fs_matcher = uverbs_attr_get_obj(attrs,
MLX5_IB_ATTR_CREATE_FLOW_MATCHER);
if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS && if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS &&
((dest_devx && dest_qp) || (!dest_devx && !dest_qp))) ((dest_devx && dest_qp) || (!dest_devx && !dest_qp)))
return -EINVAL; return -EINVAL;
@ -114,43 +92,79 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
((!dest_devx && !dest_qp) || (dest_devx && dest_qp))) ((!dest_devx && !dest_qp) || (dest_devx && dest_qp)))
return -EINVAL; return -EINVAL;
*qp = NULL;
if (dest_devx) { if (dest_devx) {
devx_obj = uverbs_attr_get_obj( devx_obj =
attrs, MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX); uverbs_attr_get_obj(attrs,
if (IS_ERR(devx_obj)) MLX5_IB_ATTR_CREATE_FLOW_DEST_DEVX);
return PTR_ERR(devx_obj);
/* Verify that the given DEVX object is a flow /* Verify that the given DEVX object is a flow
* steering destination. * steering destination.
*/ */
if (!mlx5_ib_devx_is_flow_dest(devx_obj, &dest_id, &dest_type)) if (!mlx5_ib_devx_is_flow_dest(devx_obj, dest_id, dest_type))
return -EINVAL; return -EINVAL;
/* Allow only flow table as dest when inserting to FDB or RDMA_RX */ /* Allow only flow table as dest when inserting to FDB or RDMA_RX */
if ((fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_FDB || if ((fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_FDB ||
fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_RDMA_RX) && fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_RDMA_RX) &&
dest_type != MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) *dest_type != MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE)
return -EINVAL; return -EINVAL;
} else if (dest_qp) { } else if (dest_qp) {
struct mlx5_ib_qp *mqp; struct mlx5_ib_qp *mqp;
qp = uverbs_attr_get_obj(attrs, *qp = uverbs_attr_get_obj(attrs,
MLX5_IB_ATTR_CREATE_FLOW_DEST_QP); MLX5_IB_ATTR_CREATE_FLOW_DEST_QP);
if (IS_ERR(qp)) if (IS_ERR(*qp))
return PTR_ERR(qp); return PTR_ERR(*qp);
if (qp->qp_type != IB_QPT_RAW_PACKET) if ((*qp)->qp_type != IB_QPT_RAW_PACKET)
return -EINVAL; return -EINVAL;
mqp = to_mqp(qp); mqp = to_mqp(*qp);
if (mqp->is_rss) if (mqp->is_rss)
dest_id = mqp->rss_qp.tirn; *dest_id = mqp->rss_qp.tirn;
else else
dest_id = mqp->raw_packet_qp.rq.tirn; *dest_id = mqp->raw_packet_qp.rq.tirn;
dest_type = MLX5_FLOW_DESTINATION_TYPE_TIR; *dest_type = MLX5_FLOW_DESTINATION_TYPE_TIR;
} else { } else if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS) {
dest_type = MLX5_FLOW_DESTINATION_TYPE_PORT; *dest_type = MLX5_FLOW_DESTINATION_TYPE_PORT;
} }
if (*dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR &&
fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS)
return -EINVAL;
return 0;
}
#define MLX5_IB_CREATE_FLOW_MAX_FLOW_ACTIONS 2
static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
struct uverbs_attr_bundle *attrs)
{
struct mlx5_flow_context flow_context = {.flow_tag =
MLX5_FS_DEFAULT_FLOW_TAG};
u32 *offset_attr, offset = 0, counter_id = 0;
int dest_id, dest_type, inlen, len, ret, i;
struct mlx5_ib_flow_handler *flow_handler;
struct mlx5_ib_flow_matcher *fs_matcher;
struct ib_uobject **arr_flow_actions;
struct ib_uflow_resources *uflow_res;
struct mlx5_flow_act flow_act = {};
struct ib_qp *qp = NULL;
void *devx_obj, *cmd_in;
struct ib_uobject *uobj;
struct mlx5_ib_dev *dev;
if (!capable(CAP_NET_RAW))
return -EPERM;
fs_matcher = uverbs_attr_get_obj(attrs,
MLX5_IB_ATTR_CREATE_FLOW_MATCHER);
uobj = uverbs_attr_get_uobject(attrs, MLX5_IB_ATTR_CREATE_FLOW_HANDLE);
dev = mlx5_udata_to_mdev(&attrs->driver_udata);
if (get_dests(attrs, fs_matcher, &dest_id, &dest_type, &qp))
return -EINVAL;
len = uverbs_attr_get_uobjs_arr(attrs, len = uverbs_attr_get_uobjs_arr(attrs,
MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX, &arr_flow_actions); MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX, &arr_flow_actions);
if (len) { if (len) {
@ -180,10 +194,6 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
} }
if (dest_type == MLX5_FLOW_DESTINATION_TYPE_TIR &&
fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS)
return -EINVAL;
cmd_in = uverbs_attr_get_alloced_ptr( cmd_in = uverbs_attr_get_alloced_ptr(
attrs, MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE); attrs, MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE);
inlen = uverbs_attr_get_len(attrs, inlen = uverbs_attr_get_len(attrs,