From: Ivan Malov Date: Tue, 20 Oct 2020 09:13:33 +0000 (+0100) Subject: net/sfc: support flow item TCP in transfer rules X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e0eb90cbf8eceb71700de07bde471a93ba58f0f5;p=dpdk.git net/sfc: support flow item TCP in transfer rules Add support for this flow item to MAE-specific RTE flow implementation. Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst index 0c7eea7e6e..58b81ea359 100644 --- a/doc/guides/nics/sfc_efx.rst +++ b/doc/guides/nics/sfc_efx.rst @@ -208,6 +208,8 @@ Supported pattern items (***transfer*** rules): - IPV6 (source/destination addresses, IP transport protocol, traffic class, hop limit) +- TCP (source/destination ports, TCP header length + TCP flags) + Supported actions (***transfer*** rules): - OF_POP_VLAN diff --git a/drivers/net/sfc/sfc_mae.c b/drivers/net/sfc/sfc_mae.c index 2b0121c0ac..59c53a96f3 100644 --- a/drivers/net/sfc/sfc_mae.c +++ b/drivers/net/sfc/sfc_mae.c @@ -396,6 +396,19 @@ sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx, if (rc != 0) goto fail; + if (pdata->l3_next_proto_restriction_mask == 0xff) { + if (pdata->l3_next_proto_mask == 0) { + pdata->l3_next_proto_mask = 0xff; + pdata->l3_next_proto_value = + pdata->l3_next_proto_restriction_value; + } else if (pdata->l3_next_proto_mask != 0xff || + pdata->l3_next_proto_value != + pdata->l3_next_proto_restriction_value) { + rc = EINVAL; + goto fail; + } + } + valuep = (const uint8_t *)&pdata->l3_next_proto_value; maskp = (const uint8_t *)&pdata->l3_next_proto_mask; rc = efx_mae_match_spec_field_set(efx_spec, EFX_MAE_FIELD_IP_PROTO, @@ -1045,6 +1058,63 @@ sfc_mae_rule_parse_item_ipv6(const struct rte_flow_item *item, return 0; } +static const struct sfc_mae_field_locator flocs_tcp[] = { + { + EFX_MAE_FIELD_L4_SPORT_BE, + RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.src_port), + offsetof(struct rte_flow_item_tcp, hdr.src_port), + }, + { + EFX_MAE_FIELD_L4_DPORT_BE, + RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.dst_port), + offsetof(struct rte_flow_item_tcp, hdr.dst_port), + }, + { + EFX_MAE_FIELD_TCP_FLAGS_BE, + /* + * The values have been picked intentionally since the + * target MAE field is oversize (16 bit). This mapping + * relies on the fact that the MAE field is big-endian. + */ + RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.data_off) + + RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.tcp_flags), + offsetof(struct rte_flow_item_tcp, hdr.data_off), + }, +}; + +static int +sfc_mae_rule_parse_item_tcp(const struct rte_flow_item *item, + struct sfc_flow_parse_ctx *ctx, + struct rte_flow_error *error) +{ + struct sfc_mae_parse_ctx *ctx_mae = ctx->mae; + struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data; + struct rte_flow_item_tcp supp_mask; + const uint8_t *spec = NULL; + const uint8_t *mask = NULL; + int rc; + + sfc_mae_item_build_supp_mask(flocs_tcp, RTE_DIM(flocs_tcp), + &supp_mask, sizeof(supp_mask)); + + rc = sfc_flow_parse_init(item, + (const void **)&spec, (const void **)&mask, + (const void *)&supp_mask, + &rte_flow_item_tcp_mask, + sizeof(struct rte_flow_item_tcp), error); + if (rc != 0) + return rc; + + pdata->l3_next_proto_restriction_value = IPPROTO_TCP; + pdata->l3_next_proto_restriction_mask = 0xff; + + if (spec == NULL) + return 0; + + return sfc_mae_parse_item(flocs_tcp, RTE_DIM(flocs_tcp), spec, mask, + ctx_mae->match_spec_action, error); +} + static const struct sfc_flow_item sfc_flow_items[] = { { .type = RTE_FLOW_ITEM_TYPE_PORT_ID, @@ -1118,6 +1188,13 @@ static const struct sfc_flow_item sfc_flow_items[] = { .ctx_type = SFC_FLOW_PARSE_CTX_MAE, .parse = sfc_mae_rule_parse_item_ipv6, }, + { + .type = RTE_FLOW_ITEM_TYPE_TCP, + .prev_layer = SFC_FLOW_ITEM_L3, + .layer = SFC_FLOW_ITEM_L4, + .ctx_type = SFC_FLOW_PARSE_CTX_MAE, + .parse = sfc_mae_rule_parse_item_tcp, + }, }; int diff --git a/drivers/net/sfc/sfc_mae.h b/drivers/net/sfc/sfc_mae.h index 993a377861..71046f2308 100644 --- a/drivers/net/sfc/sfc_mae.h +++ b/drivers/net/sfc/sfc_mae.h @@ -123,10 +123,23 @@ struct sfc_mae_pattern_data { /** * The following two fields keep track of L3 "proto" mask and value. * The corresponding fields get filled in MAE match specification - * at the end of parsing. + * at the end of parsing. Also, the information is used by a + * post-check to enforce consistency requirements: + * + * - If a L3 item is followed by an item TCP, the former has + * its "proto" set to either 0x06/0xff or 0x00/0x00. */ uint8_t l3_next_proto_value; uint8_t l3_next_proto_mask; + + /* + * L4 requirement for L3 item's "proto". + * This contains one of: + * - 0x06/0xff: TCP + * - 0x00/0x00: no L4 item + */ + uint8_t l3_next_proto_restriction_value; + uint8_t l3_next_proto_restriction_mask; }; struct sfc_mae_parse_ctx {