RDMA/mlx5: Allow creating a matcher for a NIC TX flow table
authorMark Bloch <markb@mellanox.com>
Thu, 6 Sep 2018 14:27:08 +0000 (17:27 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 11 Sep 2018 15:28:07 +0000 (09:28 -0600)
Currently a matcher can only be created and attached to a NIC RX flow
table. Extend it to allow it on NIC TX flow tables as well.

In order to achieve that, we:

1) Expose a new attribute: MLX5_IB_ATTR_FLOW_MATCHER_FLOW_FLAGS.
   enum ib_flow_flags is used as valid flags. Only
   IB_FLOW_ATTR_FLAGS_EGRESS is supported.

2) Remove the requirement to have a DEVX or QP destination when creating a
   flow. A flow added to NIC TX flow table will forward the packet outside
   of the vport (Wire or E-Switch in the SR-iOV case).

Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx5/flow.c
drivers/infiniband/hw/mlx5/main.c
include/uapi/rdma/mlx5_user_ioctl_cmds.h

index 16e677c..4ee4af4 100644 (file)
@@ -86,7 +86,14 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
        dest_qp = uverbs_attr_is_valid(attrs,
                                       MLX5_IB_ATTR_CREATE_FLOW_DEST_QP);
 
-       if ((dest_devx && dest_qp) || (!dest_devx && !dest_qp))
+       fs_matcher = uverbs_attr_get_obj(attrs,
+                                        MLX5_IB_ATTR_CREATE_FLOW_MATCHER);
+       if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_BYPASS &&
+           ((dest_devx && dest_qp) || (!dest_devx && !dest_qp)))
+               return -EINVAL;
+
+       if (fs_matcher->ns_type == MLX5_FLOW_NAMESPACE_EGRESS &&
+           (dest_devx || dest_qp))
                return -EINVAL;
 
        if (dest_devx) {
@@ -100,7 +107,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
                 */
                if (!mlx5_ib_devx_is_flow_dest(devx_obj, &dest_id, &dest_type))
                        return -EINVAL;
-       } else {
+       } else if (dest_qp) {
                struct mlx5_ib_qp *mqp;
 
                qp = uverbs_attr_get_obj(attrs,
@@ -117,6 +124,8 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
                else
                        dest_id = mqp->raw_packet_qp.rq.tirn;
                dest_type = MLX5_FLOW_DESTINATION_TYPE_TIR;
+       } else {
+               dest_type = MLX5_FLOW_DESTINATION_TYPE_PORT;
        }
 
        if (dev->rep)
@@ -126,8 +135,6 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
                attrs, MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE);
        inlen = uverbs_attr_get_len(attrs,
                                    MLX5_IB_ATTR_CREATE_FLOW_MATCH_VALUE);
-       fs_matcher = uverbs_attr_get_obj(attrs,
-                                        MLX5_IB_ATTR_CREATE_FLOW_MATCHER);
 
        uflow_res = flow_resources_alloc(MLX5_IB_CREATE_FLOW_MAX_FLOW_ACTIONS);
        if (!uflow_res)
@@ -183,6 +190,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_FLOW_MATCHER_CREATE)(
                attrs, MLX5_IB_ATTR_FLOW_MATCHER_CREATE_HANDLE);
        struct mlx5_ib_dev *dev = to_mdev(uobj->context->device);
        struct mlx5_ib_flow_matcher *obj;
+       u32 flags;
        int err;
 
        obj = kzalloc(sizeof(struct mlx5_ib_flow_matcher), GFP_KERNEL);
@@ -215,6 +223,19 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_FLOW_MATCHER_CREATE)(
        if (err)
                goto end;
 
+       err = uverbs_get_flags32(&flags, attrs,
+                                MLX5_IB_ATTR_FLOW_MATCHER_FLOW_FLAGS,
+                                IB_FLOW_ATTR_FLAGS_EGRESS);
+       if (err)
+               goto end;
+
+       if (flags) {
+               err = mlx5_ib_ft_type_to_namespace(
+                       MLX5_IB_UAPI_FLOW_TABLE_TYPE_NIC_TX, &obj->ns_type);
+               if (err)
+                       goto end;
+       }
+
        uobj->object = obj;
        obj->mdev = dev->mdev;
        atomic_set(&obj->usecnt, 0);
@@ -559,7 +580,10 @@ DECLARE_UVERBS_NAMED_METHOD(
                            UA_MANDATORY),
        UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_FLOW_MATCHER_MATCH_CRITERIA,
                           UVERBS_ATTR_TYPE(u8),
-                          UA_MANDATORY));
+                          UA_MANDATORY),
+       UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_FLOW_MATCHER_FLOW_FLAGS,
+                            enum ib_flow_flags,
+                            UA_OPTIONAL));
 
 DECLARE_UVERBS_NAMED_METHOD_DESTROY(
        MLX5_IB_METHOD_FLOW_MATCHER_DESTROY,
index e311b6f..2be6a43 100644 (file)
@@ -3892,10 +3892,13 @@ mlx5_ib_raw_fs_rule_add(struct mlx5_ib_dev *dev,
                dst->type = dest_type;
                dst->tir_num = dest_id;
                flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
-       } else {
+       } else if (dest_type == MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE) {
                dst->type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE_NUM;
                dst->ft_num = dest_id;
                flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
+       } else {
+               dst->type = MLX5_FLOW_DESTINATION_TYPE_PORT;
+               flow_act->action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW;
        }
 
        handler = _create_raw_flow_rule(dev, ft_prio, dst, fs_matcher, flow_act,
index 91c3d42..fb4a8b1 100644 (file)
@@ -125,6 +125,7 @@ enum mlx5_ib_flow_matcher_create_attrs {
        MLX5_IB_ATTR_FLOW_MATCHER_MATCH_MASK,
        MLX5_IB_ATTR_FLOW_MATCHER_FLOW_TYPE,
        MLX5_IB_ATTR_FLOW_MATCHER_MATCH_CRITERIA,
+       MLX5_IB_ATTR_FLOW_MATCHER_FLOW_FLAGS,
 };
 
 enum mlx5_ib_flow_matcher_destroy_attrs {