IB/uverbs: Add support for flow tag
authorMoses Reuben <mosesr@mellanox.com>
Wed, 18 Jan 2017 12:59:49 +0000 (14:59 +0200)
committerDoug Ledford <dledford@redhat.com>
Tue, 14 Feb 2017 15:21:01 +0000 (10:21 -0500)
The struct ib_uverbs_flow_spec_action_tag associates a tag_id with the
flow defined by any number of other flow_spec entries which can reference
L2, L3, and L4 packet contents.

Use of ib_uverbs_flow_spec_action_tag allows the consumer to identify
the set of rules which where matched by
the packet by examining the tag_id in the CQE.

Signed-off-by: Moses Reuben <mosesr@mellanox.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/uverbs.h
drivers/infiniband/core/uverbs_cmd.c
include/uapi/rdma/ib_user_verbs.h

index 455034ac994e680c2825eb9d0a07a636fb5cb1f0..e1bedf0bac043d0335aaee5cdc5185d17574880a 100644 (file)
@@ -228,6 +228,7 @@ struct ib_uverbs_flow_spec {
                struct ib_uverbs_flow_spec_ipv4    ipv4;
                struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
                struct ib_uverbs_flow_spec_ipv6    ipv6;
+               struct ib_uverbs_flow_spec_action_tag   flow_tag;
        };
 };
 
index 70078220348383eec62b9b6252a5607f9255e9fa..0834dce0a490b6ce261b2ef0b47a39264b8f3969 100644 (file)
@@ -3143,6 +3143,25 @@ out_put:
        return ret ? ret : in_len;
 }
 
+static int kern_spec_to_ib_spec_action(struct ib_uverbs_flow_spec *kern_spec,
+                                      union ib_flow_spec *ib_spec)
+{
+       ib_spec->type = kern_spec->type;
+       switch (ib_spec->type) {
+       case IB_FLOW_SPEC_ACTION_TAG:
+               if (kern_spec->flow_tag.size !=
+                   sizeof(struct ib_uverbs_flow_spec_action_tag))
+                       return -EINVAL;
+
+               ib_spec->flow_tag.size = sizeof(struct ib_flow_spec_action_tag);
+               ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id;
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
 static size_t kern_spec_filter_sz(struct ib_uverbs_flow_spec_hdr *spec)
 {
        /* Returns user space filter size, includes padding */
@@ -3167,8 +3186,8 @@ static ssize_t spec_filter_size(void *kern_spec_filter, u16 kern_filter_size,
        return kern_filter_size;
 }
 
-static int kern_spec_to_ib_spec(struct ib_uverbs_flow_spec *kern_spec,
-                               union ib_flow_spec *ib_spec)
+static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec,
+                                      union ib_flow_spec *ib_spec)
 {
        ssize_t actual_filter_sz;
        ssize_t kern_filter_sz;
@@ -3263,6 +3282,18 @@ static int kern_spec_to_ib_spec(struct ib_uverbs_flow_spec *kern_spec,
        return 0;
 }
 
+static int kern_spec_to_ib_spec(struct ib_uverbs_flow_spec *kern_spec,
+                               union ib_flow_spec *ib_spec)
+{
+       if (kern_spec->reserved)
+               return -EINVAL;
+
+       if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG)
+               return kern_spec_to_ib_spec_action(kern_spec, ib_spec);
+       else
+               return kern_spec_to_ib_spec_filter(kern_spec, ib_spec);
+}
+
 int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file,
                           struct ib_device *ib_dev,
                           struct ib_udata *ucore,
index dfdfe4e92d3118c0ef42b5c5d64f240eba50dee5..b458fea590b6e3b7ad3368d3b178c92330361c02 100644 (file)
@@ -929,6 +929,19 @@ struct ib_uverbs_flow_spec_ipv6 {
        struct ib_uverbs_flow_ipv6_filter mask;
 };
 
+struct ib_uverbs_flow_spec_action_tag {
+       union {
+               struct ib_uverbs_flow_spec_hdr hdr;
+               struct {
+                       __u32 type;
+                       __u16 size;
+                       __u16 reserved;
+               };
+       };
+       __u32                         tag_id;
+       __u32                         reserved1;
+};
+
 struct ib_uverbs_flow_tunnel_filter {
        __be32 tunnel_id;
 };