IB/mlx5: Add support for MPLS flow specification
authorAriel Levkovich <lariel@mellanox.com>
Sun, 13 May 2018 11:33:34 +0000 (14:33 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Thu, 17 May 2018 03:32:55 +0000 (21:32 -0600)
This patch introduces support for the MPLS flow spec and
allows the creation of rules that are matching on the
MPLS label.

Applying the rule matching depends on the flow specs order and
the location of the MPLS in the spec list as there are different
configurations to be made in the device in the cases of MPLSoGRE
and MPLSoUDP vs. non-encapsulated MPLS.

Reviewed-by: Mark Bloch <markb@mellanox.com>
Signed-off-by: Ariel Levkovich <lariel@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx5/main.c
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
include/linux/mlx5/device.h
include/linux/mlx5/mlx5_ifc.h

index 81f696b2135684903aef373f98a491f4c86cf985..8792248034cbfa1c7a2254da227a577c48f67e94 100644 (file)
@@ -2386,7 +2386,8 @@ static int mlx5_ib_dealloc_pd(struct ib_pd *pd)
 enum {
        MATCH_CRITERIA_ENABLE_OUTER_BIT,
        MATCH_CRITERIA_ENABLE_MISC_BIT,
-       MATCH_CRITERIA_ENABLE_INNER_BIT
+       MATCH_CRITERIA_ENABLE_INNER_BIT,
+       MATCH_CRITERIA_ENABLE_MISC2_BIT
 };
 
 #define HEADER_IS_ZERO(match_criteria, headers)                                   \
@@ -2406,6 +2407,9 @@ static u8 get_match_criteria_enable(u32 *match_criteria)
        match_criteria_enable |=
                (!HEADER_IS_ZERO(match_criteria, inner_headers)) <<
                MATCH_CRITERIA_ENABLE_INNER_BIT;
+       match_criteria_enable |=
+               (!HEADER_IS_ZERO(match_criteria, misc_parameters_2)) <<
+               MATCH_CRITERIA_ENABLE_MISC2_BIT;
 
        return match_criteria_enable;
 }
@@ -2440,6 +2444,27 @@ static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val)
        MLX5_SET(fte_match_set_lyr_2_4, outer_v, ip_dscp, val >> 2);
 }
 
+static int check_mpls_supp_fields(u32 field_support, const __be32 *set_mask)
+{
+       if (MLX5_GET(fte_match_mpls, set_mask, mpls_label) &&
+           !(field_support & MLX5_FIELD_SUPPORT_MPLS_LABEL))
+               return -EOPNOTSUPP;
+
+       if (MLX5_GET(fte_match_mpls, set_mask, mpls_exp) &&
+           !(field_support & MLX5_FIELD_SUPPORT_MPLS_EXP))
+               return -EOPNOTSUPP;
+
+       if (MLX5_GET(fte_match_mpls, set_mask, mpls_s_bos) &&
+           !(field_support & MLX5_FIELD_SUPPORT_MPLS_S_BOS))
+               return -EOPNOTSUPP;
+
+       if (MLX5_GET(fte_match_mpls, set_mask, mpls_ttl) &&
+           !(field_support & MLX5_FIELD_SUPPORT_MPLS_TTL))
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
 #define LAST_ETH_FIELD vlan_tag
 #define LAST_IB_FIELD sl
 #define LAST_IPV4_FIELD tos
@@ -2480,12 +2505,16 @@ static int parse_flow_flow_action(const union ib_flow_spec *ib_spec,
 static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c,
                           u32 *match_v, const union ib_flow_spec *ib_spec,
                           const struct ib_flow_attr *flow_attr,
-                          struct mlx5_flow_act *action)
+                          struct mlx5_flow_act *action, u32 prev_type)
 {
        void *misc_params_c = MLX5_ADDR_OF(fte_match_param, match_c,
                                           misc_parameters);
        void *misc_params_v = MLX5_ADDR_OF(fte_match_param, match_v,
                                           misc_parameters);
+       void *misc_params2_c = MLX5_ADDR_OF(fte_match_param, match_c,
+                                           misc_parameters_2);
+       void *misc_params2_v = MLX5_ADDR_OF(fte_match_param, match_v,
+                                           misc_parameters_2);
        void *headers_c;
        void *headers_v;
        int match_ipv;
@@ -2713,6 +2742,70 @@ static int parse_flow_attr(struct mlx5_core_dev *mdev, u32 *match_c,
                       &ib_spec->gre.val.key,
                       sizeof(ib_spec->gre.val.key));
                break;
+       case IB_FLOW_SPEC_MPLS:
+               switch (prev_type) {
+               case IB_FLOW_SPEC_UDP:
+                       if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev,
+                                                  ft_field_support.outer_first_mpls_over_udp),
+                                                  &ib_spec->mpls.mask.tag))
+                               return -EOPNOTSUPP;
+
+                       memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v,
+                                           outer_first_mpls_over_udp),
+                              &ib_spec->mpls.val.tag,
+                              sizeof(ib_spec->mpls.val.tag));
+                       memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c,
+                                           outer_first_mpls_over_udp),
+                              &ib_spec->mpls.mask.tag,
+                              sizeof(ib_spec->mpls.mask.tag));
+                       break;
+               case IB_FLOW_SPEC_GRE:
+                       if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev,
+                                                  ft_field_support.outer_first_mpls_over_gre),
+                                                  &ib_spec->mpls.mask.tag))
+                               return -EOPNOTSUPP;
+
+                       memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v,
+                                           outer_first_mpls_over_gre),
+                              &ib_spec->mpls.val.tag,
+                              sizeof(ib_spec->mpls.val.tag));
+                       memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c,
+                                           outer_first_mpls_over_gre),
+                              &ib_spec->mpls.mask.tag,
+                              sizeof(ib_spec->mpls.mask.tag));
+                       break;
+               default:
+                       if (ib_spec->type & IB_FLOW_SPEC_INNER) {
+                               if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev,
+                                                          ft_field_support.inner_first_mpls),
+                                                          &ib_spec->mpls.mask.tag))
+                                       return -EOPNOTSUPP;
+
+                               memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v,
+                                                   inner_first_mpls),
+                                      &ib_spec->mpls.val.tag,
+                                      sizeof(ib_spec->mpls.val.tag));
+                               memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c,
+                                                   inner_first_mpls),
+                                      &ib_spec->mpls.mask.tag,
+                                      sizeof(ib_spec->mpls.mask.tag));
+                       } else {
+                               if (check_mpls_supp_fields(MLX5_CAP_FLOWTABLE_NIC_RX(mdev,
+                                                          ft_field_support.outer_first_mpls),
+                                                          &ib_spec->mpls.mask.tag))
+                                       return -EOPNOTSUPP;
+
+                               memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_v,
+                                                   outer_first_mpls),
+                                      &ib_spec->mpls.val.tag,
+                                      sizeof(ib_spec->mpls.val.tag));
+                               memcpy(MLX5_ADDR_OF(fte_match_set_misc2, misc_params2_c,
+                                                   outer_first_mpls),
+                                      &ib_spec->mpls.mask.tag,
+                                      sizeof(ib_spec->mpls.mask.tag));
+                       }
+               }
+               break;
        case IB_FLOW_SPEC_VXLAN_TUNNEL:
                if (FIELDS_NOT_SUPPORTED(ib_spec->tunnel.mask,
                                         LAST_TUNNEL_FIELD))
@@ -3044,6 +3137,7 @@ static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev,
        struct mlx5_flow_destination *rule_dst = dst;
        const void *ib_flow = (const void *)flow_attr + sizeof(*flow_attr);
        unsigned int spec_index;
+       u32 prev_type = 0;
        int err = 0;
        int dest_num = 1;
        bool is_egress = flow_attr->flags & IB_FLOW_ATTR_FLAGS_EGRESS;
@@ -3063,10 +3157,12 @@ static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev,
        for (spec_index = 0; spec_index < flow_attr->num_of_specs; spec_index++) {
                err = parse_flow_attr(dev->mdev, spec->match_criteria,
                                      spec->match_value,
-                                     ib_flow, flow_attr, &flow_act);
+                                     ib_flow, flow_attr, &flow_act,
+                                     prev_type);
                if (err < 0)
                        goto free;
 
+               prev_type = ((union ib_flow_spec *)ib_flow)->type;
                ib_flow += ((union ib_flow_spec *)ib_flow)->size;
        }
 
index de51e7c39bc8b8ae02ea236afc9286b6e768cce5..556202b9256aafa47a424bb3d6071074f3f88de0 100644 (file)
@@ -324,7 +324,8 @@ static bool check_valid_mask(u8 match_criteria_enable, const u32 *match_criteria
        if (match_criteria_enable & ~(
                (1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS)   |
                (1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS) |
-               (1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS)))
+               (1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS) |
+               (1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS_2)))
                return false;
 
        if (!(match_criteria_enable &
@@ -360,6 +361,17 @@ static bool check_valid_mask(u8 match_criteria_enable, const u32 *match_criteria
                        return false;
        }
 
+       if (!(match_criteria_enable &
+             1 << MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS_2)) {
+               char *fg_type_mask = MLX5_ADDR_OF(fte_match_param,
+                                                 match_criteria, misc_parameters_2);
+
+               if (fg_type_mask[0] ||
+                   memcmp(fg_type_mask, fg_type_mask + 1,
+                          MLX5_ST_SZ_BYTES(fte_match_set_misc2) - 1))
+                       return false;
+       }
+
        return check_last_reserved(match_criteria);
 }
 
index e26d3e9d5f9f9b7210a0f1dae9b041a2686c415a..b6da322a8016967cff047c0b5a4f920ad5c9e884 100644 (file)
@@ -159,7 +159,7 @@ struct mlx5_ft_underlay_qp {
        u32 qpn;
 };
 
-#define MLX5_FTE_MATCH_PARAM_RESERVED  reserved_at_600
+#define MLX5_FTE_MATCH_PARAM_RESERVED  reserved_at_800
 /* Calculate the fte_match_param length and without the reserved length.
  * Make sure the reserved field is the last.
  */
index 2bc27f8c5b877dc81853e801706e558a031dc63e..fd1a9341edfacab79aece6e878620685cae7aba3 100644 (file)
@@ -994,6 +994,13 @@ enum mlx5_wol_mode {
        MLX5_WOL_PHY_ACTIVITY   = 1 << 7,
 };
 
+enum mlx5_mpls_supported_fields {
+       MLX5_FIELD_SUPPORT_MPLS_LABEL = 1 << 0,
+       MLX5_FIELD_SUPPORT_MPLS_EXP   = 1 << 1,
+       MLX5_FIELD_SUPPORT_MPLS_S_BOS = 1 << 2,
+       MLX5_FIELD_SUPPORT_MPLS_TTL   = 1 << 3
+};
+
 /* MLX5 DEV CAPs */
 
 /* TODO: EAT.ME */
index 1aad455538f40836635d352a06c20955d6ec5ef7..3fee2f74d09da23c29f276acc71e3136114f4ab3 100644 (file)
@@ -298,9 +298,15 @@ struct mlx5_ifc_flow_table_fields_supported_bits {
        u8         inner_tcp_dport[0x1];
        u8         inner_tcp_flags[0x1];
        u8         reserved_at_37[0x9];
-       u8         reserved_at_40[0x17];
+
+       u8         reserved_at_40[0x5];
+       u8         outer_first_mpls_over_udp[0x4];
+       u8         outer_first_mpls_over_gre[0x4];
+       u8         inner_first_mpls[0x4];
+       u8         outer_first_mpls[0x4];
+       u8         reserved_at_55[0x2];
        u8         outer_esp_spi[0x1];
-       u8         reserved_at_58[0x2];
+       u8         reserved_at_58[0x2];
        u8         bth_dst_qp[0x1];
 
        u8         reserved_at_5b[0x25];
@@ -450,6 +456,29 @@ struct mlx5_ifc_fte_match_set_misc_bits {
        u8         reserved_at_1a0[0x60];
 };
 
+struct mlx5_ifc_fte_match_mpls_bits {
+       u8         mpls_label[0x14];
+       u8         mpls_exp[0x3];
+       u8         mpls_s_bos[0x1];
+       u8         mpls_ttl[0x8];
+};
+
+struct mlx5_ifc_fte_match_set_misc2_bits {
+       struct mlx5_ifc_fte_match_mpls_bits outer_first_mpls;
+
+       struct mlx5_ifc_fte_match_mpls_bits inner_first_mpls;
+
+       struct mlx5_ifc_fte_match_mpls_bits outer_first_mpls_over_gre;
+
+       struct mlx5_ifc_fte_match_mpls_bits outer_first_mpls_over_udp;
+
+       u8         reserved_at_80[0x100];
+
+       u8         metadata_reg_a[0x20];
+
+       u8         reserved_at_1a0[0x60];
+};
+
 struct mlx5_ifc_cmd_pas_bits {
        u8         pa_h[0x20];
 
@@ -1170,7 +1199,9 @@ struct mlx5_ifc_fte_match_param_bits {
 
        struct mlx5_ifc_fte_match_set_lyr_2_4_bits inner_headers;
 
-       u8         reserved_at_600[0xa00];
+       struct mlx5_ifc_fte_match_set_misc2_bits misc_parameters_2;
+
+       u8         reserved_at_800[0x800];
 };
 
 enum {
@@ -4579,6 +4610,7 @@ enum {
        MLX5_QUERY_FLOW_GROUP_OUT_MATCH_CRITERIA_ENABLE_OUTER_HEADERS    = 0x0,
        MLX5_QUERY_FLOW_GROUP_OUT_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS  = 0x1,
        MLX5_QUERY_FLOW_GROUP_OUT_MATCH_CRITERIA_ENABLE_INNER_HEADERS    = 0x2,
+       MLX5_QUERY_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS_2 = 0X3,
 };
 
 struct mlx5_ifc_query_flow_group_out_bits {
@@ -6969,9 +7001,10 @@ struct mlx5_ifc_create_flow_group_out_bits {
 };
 
 enum {
-       MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS    = 0x0,
-       MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS  = 0x1,
-       MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS    = 0x2,
+       MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_OUTER_HEADERS     = 0x0,
+       MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS   = 0x1,
+       MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_INNER_HEADERS     = 0x2,
+       MLX5_CREATE_FLOW_GROUP_IN_MATCH_CRITERIA_ENABLE_MISC_PARAMETERS_2 = 0x3,
 };
 
 struct mlx5_ifc_create_flow_group_in_bits {