From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 88F082BAC for ; Mon, 28 May 2018 13:21:44 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id a67-v6so31110851wmf.3 for ; Mon, 28 May 2018 04:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=E+Fgzwt68kiVdkqXfqLHjuY1Nbx6OJ3F+ihat7fDOK8=; b=go1bmP9QbzohztZ8c1mmT265EozMGTMCsuo3nz8SzAjUmWFMbWVgfeTji29WUnmgIA nljCQgxLPnVwBZEFeLwI1wNYIPLRcyyC4Myh8bXJhn8VBXqT8u6MmQjisTboSmUGzEpr 7n7QiNgMf6O1AxZ3XuKHsynCuk41TVSKGpesV+rhHfR+ChHgGpkrtkuPZTZiVmGRGtIj QZ5SOh0dfgu1S24kT9sEuTwFj2qfHltSuvD3pt9zmCeR8dgz4CviDdzTMjvE1R1jPLFa 1mDIdzqioFB/QI37pIZsXxsFzMQC8NFWoI0xoRlewN2gehuwreNQXoc9DHqp4XFWzi/o hAdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=E+Fgzwt68kiVdkqXfqLHjuY1Nbx6OJ3F+ihat7fDOK8=; b=T5sx8S2bBEucX3xWtIpL6qpg6DHN3ZFf3Io3HiO4Fg9RiucxT5TY/rme3J3RRClTnA 8vG2lYdVYDa0+07D6J4JFkz9z+zSrkV3NcmNZHwWsMnqkgiqrt2FTrZzHzt30bhvaY5D u8WHBHSjKtT2h2HyaJH4/gBCuA5nLZ7sGPWviZdUo3Vi8f85xmw5B+AZxxH+uO/ikVC3 xUlNTQm9j/H6RJB+3z/XU5Un3x2IkZuCSJ+FjhZF6o4oRBx+CZJYPH57cPeB0kKgbFkr 1cKrRzIPRbHRrqX/vAPbE/raraS/H96xMApHLQXc2gmWyJxAC8qbdBZ+pPCSlUz0gAHw vRTw== X-Gm-Message-State: ALKqPwfe7SwSdovR+5cxvdZIWTVzGs6wVJPa1MvROVhUw3RjlxU9XKSd nFjUheHllcrShW2wd2zbFn+CSNf+kA== X-Google-Smtp-Source: ADUXVKIh3RzOFOqgvKb9CwBpaDlAZuA3cV6BGpxm5MZ6XRZdS10bvOIBzFC0Ixjj+IlHSWi5ZboI0A== X-Received: by 2002:a1c:374f:: with SMTP id e76-v6mr7669994wma.141.1527506504043; Mon, 28 May 2018 04:21:44 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id q81-v6sm20755444wmd.14.2018.05.28.04.21.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 04:21:43 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Adrien Mazarguil , Yongseok Koh Date: Mon, 28 May 2018 13:21:39 +0200 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [DPDK 18.08 v1 06/12] net/mlx5: add flow VLAN item X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2018 11:21:44 -0000 Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 114 +++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 8c6309188..ed27914aa 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -368,6 +368,117 @@ mlx5_flow_item_eth(const struct rte_flow_item *item, struct rte_flow *flow, return 0; } +/** + * Update the VLAN tag in the Ethernet spec. + * + * @param attr[in, out] + * Pointer to Verbs attributes structure. + * @param eth[in] + * Verbs structure containing the VLAN information to copy. + */ +static void +mlx5_flow_item_vlan_update(struct ibv_flow_attr *attr, + struct ibv_flow_spec_eth *eth) +{ + unsigned int i; + enum ibv_flow_spec_type search = IBV_FLOW_SPEC_ETH; + struct ibv_spec_header *hdr = (struct ibv_spec_header *) + ((uint8_t *)attr + sizeof(struct ibv_flow_attr)); + + for (i = 0; i != attr->num_of_specs; ++i) { + if (hdr->type == search) { + struct ibv_flow_spec_eth *e = + (struct ibv_flow_spec_eth *)hdr; + + e->val.vlan_tag = eth->val.vlan_tag; + e->mask.vlan_tag = eth->mask.vlan_tag; + break; + } + hdr = (struct ibv_spec_header *)((uint8_t *)hdr + hdr->size); + } +} + +/** + * Validate VLAN layer and possibly create/modify the Verbs specification. + * + * @param item[in] + * Item specification. + * @param flow[in, out] + * Pointer to flow structure. + * @param error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_item_vlan(const struct rte_flow_item *item, struct rte_flow *flow, + struct rte_flow_error *error) +{ + const struct rte_flow_item_vlan *spec = item->spec; + const struct rte_flow_item_vlan *mask = item->mask; + const struct rte_flow_item_vlan nic_mask = { + .tci = RTE_BE16(0x0fff), + }; + const unsigned int size = sizeof(struct ibv_flow_spec_eth); + struct ibv_flow_spec_eth eth = { + .type = IBV_FLOW_SPEC_ETH, + .size = size, + }; + int ret; + const uint32_t lm = (MLX5_FLOW_LAYER_L3 | MLX5_FLOW_LAYER_L4); + const uint32_t vlanm = MLX5_FLOW_LAYER_VLAN; + const uint32_t l2m = MLX5_FLOW_LAYER_L2; + + if (flow->verbs.layers & vlanm) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "L2 layers already configured"); + else if ((flow->verbs.layers & lm) != 0) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "L2 layer cannot follow L3/L4 layer"); + if (!mask) + mask = &rte_flow_item_vlan_mask; + ret = mlx5_flow_item_validate(item, (const uint8_t *)mask, + (const uint8_t *)&nic_mask, + sizeof(struct rte_flow_item_vlan), error); + if (ret) + return ret; + if (spec) { + eth.val.vlan_tag = spec->tci; + eth.mask.vlan_tag = mask->tci; + eth.val.vlan_tag &= eth.mask.vlan_tag; + eth.val.ether_type = spec->inner_type; + eth.mask.ether_type = mask->inner_type; + eth.val.ether_type &= eth.mask.ether_type; + } + /* + * From verbs perspective an empty VLAN is equivalent + * to a packet without VLAN layer. + */ + if (!eth.mask.vlan_tag) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ITEM_SPEC, + item->spec, + "VLAN cannot be empty"); + /* Outer TPID cannot be matched. */ + if (eth.mask.ether_type) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM_SPEC, + item->spec, + "VLAN TPID matching is not" + " supported"); + if (!(flow->verbs.layers & l2m)) + mlx5_flow_spec_verbs_add(flow, ð, size); + else + mlx5_flow_item_vlan_update(flow->verbs.attr, ð); + flow->verbs.layers |= MLX5_FLOW_LAYER_L2 | MLX5_FLOW_LAYER_VLAN; + return 0; +} + /** * Validate items provided by the user. * @@ -395,6 +506,9 @@ mlx5_flow_items(const struct rte_flow_item items[], case RTE_FLOW_ITEM_TYPE_ETH: ret = mlx5_flow_item_eth(items, flow, error); break; + case RTE_FLOW_ITEM_TYPE_VLAN: + ret = mlx5_flow_item_vlan(items, flow, error); + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, -- 2.17.0