From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nelio Laranjeiro Subject: [PATCH v2 4/4] net/mlx5: add VLAN filter support in rte_flow Date: Wed, 21 Dec 2016 11:01:14 +0100 Message-ID: <655c7b26837824f7e2d727adaa11663986afe2d6.1482314020.git.nelio.laranjeiro@6wind.com> References: Cc: Adrien Mazarguil To: dev@dpdk.org Return-path: Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by dpdk.org (Postfix) with ESMTP id CC04910BF1 for ; Wed, 21 Dec 2016 11:01:38 +0100 (CET) Received: by mail-wm0-f47.google.com with SMTP id t79so153885394wmt.0 for ; Wed, 21 Dec 2016 02:01:38 -0800 (PST) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 59 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 44e2fb8..fec1950 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -185,6 +185,9 @@ priv_flow_validate(struct priv *priv, .dst_port = -1, }, }; + const struct rte_flow_item_vlan vlan_mask = { + .tci = -1, + }; if (attr->group) { rte_flow_error_set(error, ENOTSUP, @@ -229,11 +232,32 @@ priv_flow_validate(struct priv *priv, sizeof(eth_mask)); if (err) goto exit_item_not_supported; - } else if (items->type == RTE_FLOW_ITEM_TYPE_IPV4) { + } else if (items->type == RTE_FLOW_ITEM_TYPE_VLAN) { if (!ilast) goto exit_item_not_supported; else if (ilast->type != RTE_FLOW_ITEM_TYPE_ETH) goto exit_item_not_supported; + if (((const struct rte_flow_item_vlan *)items)->tci > + ETHER_MAX_VLAN_ID) { + rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + items, + "wrong VLAN tci value"); + goto exit; + } + ilast = items; + err = mlx5_flow_item_validate( + items, + (const uint8_t *)&vlan_mask, + sizeof(vlan_mask)); + if (err) + goto exit_item_not_supported; + } else if (items->type == RTE_FLOW_ITEM_TYPE_IPV4) { + if (!ilast) + goto exit_item_not_supported; + else if (ilast->type != RTE_FLOW_ITEM_TYPE_ETH && + ilast->type != RTE_FLOW_ITEM_TYPE_VLAN) + goto exit_item_not_supported; ilast = items; err = mlx5_flow_item_validate( items, @@ -244,7 +268,8 @@ priv_flow_validate(struct priv *priv, } else if (items->type == RTE_FLOW_ITEM_TYPE_IPV6) { if (!ilast) goto exit_item_not_supported; - else if (ilast->type != RTE_FLOW_ITEM_TYPE_ETH) + else if (ilast->type != RTE_FLOW_ITEM_TYPE_ETH && + ilast->type != RTE_FLOW_ITEM_TYPE_VLAN) goto exit_item_not_supported; ilast = items; err = mlx5_flow_item_validate( @@ -376,6 +401,28 @@ mlx5_flow_create_eth(const struct rte_flow_item *item, } /** + * Convert VLAN item to Verbs specification. + * + * @param item[in] + * Item specification. + * @param eth[in, out] + * Verbs Ethernet specification structure. + */ +static void +mlx5_flow_create_vlan(const struct rte_flow_item *item, + struct ibv_exp_flow_spec_eth *eth) +{ + const struct rte_flow_item_vlan *spec = item->spec; + const struct rte_flow_item_vlan *mask = item->mask; + + if (spec) + eth->val.vlan_tag = spec->tci; + if (mask) + eth->mask.vlan_tag = mask->tci; + eth->val.vlan_tag &= eth->mask.vlan_tag; +} + +/** * Convert IPv4 item to Verbs specification. * * @param item[in] @@ -704,6 +751,14 @@ priv_flow_create(struct priv *priv, flow_size += eth_size; ++ibv_attr->num_of_specs; ibv_attr->priority = 2; + } else if (items->type == RTE_FLOW_ITEM_TYPE_VLAN) { + struct ibv_exp_flow_spec_eth *eth; + unsigned int eth_size = + sizeof(struct ibv_exp_flow_spec_eth); + + eth = (void *)((uintptr_t)ibv_attr + flow_size - + eth_size); + mlx5_flow_create_vlan(items, eth); } else if (items->type == RTE_FLOW_ITEM_TYPE_IPV4) { struct ibv_exp_flow_spec_ipv4 *ipv4; unsigned int ipv4_size = -- 2.1.4