From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by dpdk.org (Postfix) with ESMTP id 57BA31B54B for ; Thu, 12 Jul 2018 11:31:31 +0200 (CEST) Received: by mail-wr1-f66.google.com with SMTP id c4-v6so8291190wrs.12 for ; Thu, 12 Jul 2018 02:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4/MwwaAcjueWvkzwEy1f8cYFY2ubKDzmrqgq64IhCck=; b=GAhngPESUPaUPGD5LVwYEGj2KTIAaiLm0ffdlXGhgonoUqZ/vOX+RyTrlp+CFt3sSM v93xDNkJdcQNyIDlGIbqj0QRIjI2tFmz7K176Vsr7akmnlK1EBzl8dRzoXhL8O7UmGFw TgGOUaX57Kq/PSME7UAKPv5+9nOe7lz/+uD8hIH2fyJ9mCDv3S8/vaYKOtvefAHu4Xy7 WS2q1djhIpVHsIqYWpe74tl5WC43qc6jDdaDleaPPtaangOb2fQb+nmlW+/7/YdIZf9K US/nJ9mzkA3DbF9PuYTqzKS3bYXTQIVa1gXAI04CNA5THwEy0OPUjQVLG3+dC0tQfV4g s3Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4/MwwaAcjueWvkzwEy1f8cYFY2ubKDzmrqgq64IhCck=; b=WBgQR2UYwdq3COFS/rfBJlqjR5mnhjG3rYsNTFroGKhYzK6ohdZFZHvT+qkS3H3NSE G4dWfTn6cl7GSIRCOMZ06ZSA4WMs9ISYGmtcKhILSLbmG59vzepBIexziFv7JHQrRhi3 y8f8hEpvnkQHewNBPIbS+HtGog8jEfFKnwVCfUbI/E9OV9eaTYVqKXJKdMRJo5nCj3HD NlvIzKEFTQi/j3Z3DlSZ3uVvT6SGnL5xozzNf+hIQMdGLKLx1Z2YIztL2PxL2L33YALW k1OFFqBI+RpxHRcn9VNrheh40kOUlrlJ1p5gdoGob38jEQ/FyunusCL32qot5TTY53kF +TPA== X-Gm-Message-State: AOUpUlHG6/kUOR349HoRMvG27vlo2KSTiBSw6pJF4ZWv6wqGuJKR1D/m 8m9rrlqvIIzNKEYKnci90FXfdywU1A== X-Google-Smtp-Source: AAOMgpcU9VgxGzr+ZSHJqo7E4/hotFt4SU72KscyIg3dsdhP+7D4PZGC/Kttb/gOlC0c43c0eod+zA== X-Received: by 2002:a5d:480d:: with SMTP id l13-v6mr1224354wrq.234.1531387890865; Thu, 12 Jul 2018 02:31:30 -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 s2-v6sm18717603wrn.75.2018.07.12.02.31.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 02:31:30 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Yongseok Koh Cc: Adrien Mazarguil Date: Thu, 12 Jul 2018 11:30:53 +0200 Message-Id: <2cc2794bf1301975f3af6691ffc1c888355ecfcc.1531387413.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 07/21] 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: Thu, 12 Jul 2018 09:31:31 -0000 Signed-off-by: Nelio Laranjeiro Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_flow.c | 127 +++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 77f1bd5cc..659979283 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -382,6 +382,130 @@ mlx5_flow_item_eth(const struct rte_flow_item *item, struct rte_flow *flow, return size; } +/** + * Update the VLAN tag in the Verbs Ethernet specification. + * + * @param[in, out] attr + * Pointer to Verbs attributes structure. + * @param[in] eth + * 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; + e->val.ether_type = eth->val.ether_type; + e->mask.ether_type = eth->mask.ether_type; + break; + } + hdr = (struct ibv_spec_header *)((uint8_t *)hdr + hdr->size); + } +} + +/** + * Convert the @p item into @p flow (or by updating the already present + * Ethernet Verbs) specification after ensuring the NIC will understand and + * process it correctly. + * If the necessary size for the conversion is greater than the @p flow_size, + * nothing is written in @p flow, the validation is still performed. + * + * @param[in] item + * Item specification. + * @param[in, out] flow + * Pointer to flow structure. + * @param[in] flow_size + * Size in bytes of the available space in @p flow, if too small, nothing is + * written. + * @param[out] error + * Pointer to error structure. + * + * @return + * On success the number of bytes consumed/necessary, if the returned value + * is lesser or equal to @p flow_size, the @p item has fully been converted, + * otherwise another call with this returned memory size should be done. + * On error, a negative errno value is returned and rte_errno is set. + */ +static int +mlx5_flow_item_vlan(const struct rte_flow_item *item, struct rte_flow *flow, + const size_t flow_size, 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), + .inner_type = RTE_BE16(0xffff), + }; + 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 l34m = MLX5_FLOW_LAYER_OUTER_L3 | + MLX5_FLOW_LAYER_OUTER_L4; + const uint32_t vlanm = MLX5_FLOW_LAYER_OUTER_VLAN; + const uint32_t l2m = MLX5_FLOW_LAYER_OUTER_L2; + + if (flow->layers & vlanm) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "VLAN layer already configured"); + else if ((flow->layers & l34m) != 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_acceptable + (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"); + if (!(flow->layers & l2m)) { + if (size <= flow_size) + mlx5_flow_spec_verbs_add(flow, ð, size); + } else { + if (flow->verbs.attr) + mlx5_flow_item_vlan_update(flow->verbs.attr, ð); + size = 0; /* Only an update is done in eth specification. */ + } + flow->layers |= MLX5_FLOW_LAYER_OUTER_L2 | + MLX5_FLOW_LAYER_OUTER_VLAN; + return size; +} + /** * Convert the @p pattern into a Verbs specifications after ensuring the NIC * will understand and process it correctly. @@ -424,6 +548,9 @@ mlx5_flow_items(const struct rte_flow_item pattern[], case RTE_FLOW_ITEM_TYPE_ETH: ret = mlx5_flow_item_eth(pattern, flow, remain, error); break; + case RTE_FLOW_ITEM_TYPE_VLAN: + ret = mlx5_flow_item_vlan(pattern, flow, remain, error); + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, -- 2.18.0