From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <nelio.laranjeiro@6wind.com>
Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68])
 by dpdk.org (Postfix) with ESMTP id 0DF321BFAF
 for <dev@dpdk.org>; Wed, 27 Jun 2018 17:07:43 +0200 (CEST)
Received: by mail-wm0-f68.google.com with SMTP id e69-v6so3320740wme.2
 for <dev@dpdk.org>; Wed, 27 Jun 2018 08:07:43 -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;
 bh=GFq7GfnL0me8dT1JBjk6Uu7HN9fJE+EdqLCBFZDmsak=;
 b=OaC8iOnri//XQ8pU2oFYs/7kz0cqyqirKpErs4lmV7of1IhQaIAE4IxdYKj2JM/6z1
 gcyuWUN4u8aBs25hGZBdTqEnnW3UcFr7aGM77jb3gY6wNGSHnezDNsXNN5XZM4DI3Wyn
 B6xSwnp0cZbUVM/O+2vAamCPFYuSUb88BE5mx6i5nto0/dT7HaJn9EP4fv8m4C/8zpWy
 qeCCAeMUCKtZljhlD0Nmohw3FRthxgefIZh75HSfjkbFKt5G0wSJm84TGmzMmYSIhKPy
 XLhX5ZRPzv/JN9xVzXa/0l2elz7kj+Z4Nt/jTj98fEwfIhjB+QeEeVcicbbzxQQ2UxH3
 D/zA==
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;
 bh=GFq7GfnL0me8dT1JBjk6Uu7HN9fJE+EdqLCBFZDmsak=;
 b=U/6jikUpiK+rLR9SPhyaUK2cdVyr0RA4+mVCG6/74MXUWn93IOpYIqgp28W3axmt8L
 v5IA+GhDNcBBhS4n35KeLaxYg/EZRfpFGuGbG6eWmFTToJGy3h4YzLNCIb6iK440w0Ug
 BgpmGgfvJMrZoWXFeSJ/ySrIIcJonMnbKXjF2Bi0E84fb5TBrBJl79xWYhtGEmzWxPyg
 QmUIHu47h5/0x7YBmRbeu4NuP9xAunVfKmuIVMOfhJvPVfAGca4Pv8Ed3ZQNwigAajrA
 3ASBm3TAUaMjOYV76QDlYqmnsB19A6449Mz36NiS7nsFXrdoh+8YHYx4T9GyWHMmqeYn
 okPg==
X-Gm-Message-State: APt69E2Ac584hVEZvhxY8RuUpU7CHRSUF6E4FbOOLew+Kg09Hr8yj6TV
 +1Kr7g6YyNMBR6zLLEHfal38hiHqvw==
X-Google-Smtp-Source: AAOMgpf91yj0T/kcsbc2Um2DoB9BTtawMHAX9Xkb/1b1l3Vut/YlTsMrlVS06lXqJms4sSG4Nz/LMQ==
X-Received: by 2002:a1c:944e:: with SMTP id
 w75-v6mr3048781wmd.105.1530112062574; 
 Wed, 27 Jun 2018 08:07:42 -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 k17-v6sm4872513wrp.19.2018.06.27.08.07.41
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Wed, 27 Jun 2018 08:07:41 -0700 (PDT)
From: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
To: dev@dpdk.org, Adrien Mazarguil <adrien.mazarguil@6wind.com>,
 Yongseok Koh <yskoh@mellanox.com>
Date: Wed, 27 Jun 2018 17:07:41 +0200
Message-Id: <7bc5b0becafaeaf59c3e97a5ecdc955689a41bed.1530111623.git.nelio.laranjeiro@6wind.com>
X-Mailer: git-send-email 2.18.0
In-Reply-To: <cover.1530111623.git.nelio.laranjeiro@6wind.com>
References: <cover.1527506071.git.nelio.laranjeiro@6wind.com>
 <cover.1530111623.git.nelio.laranjeiro@6wind.com>
Subject: [dpdk-dev] [PATCH v2 09/20] net/mlx5: add flow IPv6 item
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 27 Jun 2018 15:07:43 -0000

Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
---
 drivers/net/mlx5/mlx5_flow.c | 108 +++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 8e7a0bb5a..4e018400a 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -620,6 +620,111 @@ mlx5_flow_item_ipv4(const struct rte_flow_item *item, struct rte_flow *flow,
 	return size;
 }
 
+/**
+ * Validate IPv6 layer and possibly create the Verbs specification.
+ *
+ * @param item[in]
+ *   Item specification.
+ * @param flow[in, out]
+ *   Pointer to flow structure.
+ * @param flow_size[in]
+ *   Size in bytes of the available space for to store the flow information.
+ * @param error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   size in bytes necessary for the conversion, a negative errno value
+ *   otherwise and rte_errno is set.
+ */
+static int
+mlx5_flow_item_ipv6(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_ipv6 *spec = item->spec;
+	const struct rte_flow_item_ipv6 *mask = item->mask;
+	const struct rte_flow_item_ipv6 nic_mask = {
+		.hdr = {
+			.src_addr =
+				"\xff\xff\xff\xff\xff\xff\xff\xff"
+				"\xff\xff\xff\xff\xff\xff\xff\xff",
+			.dst_addr =
+				"\xff\xff\xff\xff\xff\xff\xff\xff"
+				"\xff\xff\xff\xff\xff\xff\xff\xff",
+			.vtc_flow = RTE_BE32(0xffffffff),
+			.proto = 0xff,
+			.hop_limits = 0xff,
+		},
+	};
+	unsigned int size = sizeof(struct ibv_flow_spec_ipv6);
+	struct ibv_flow_spec_ipv6 ipv6 = {
+		.type = IBV_FLOW_SPEC_IPV6,
+		.size = size,
+	};
+	int ret;
+
+	if (flow->layers & MLX5_FLOW_LAYER_OUTER_L3)
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ITEM,
+					  item,
+					  "multiple L3 layers not supported");
+	else if (flow->layers & MLX5_FLOW_LAYER_OUTER_L4)
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ITEM,
+					  item,
+					  "L3 cannot follow an L4 layer.");
+	if (!mask)
+		mask = &rte_flow_item_ipv6_mask;
+	ret = mlx5_flow_item_validate(item, (const uint8_t *)mask,
+				      (const uint8_t *)&nic_mask,
+				      sizeof(struct rte_flow_item_ipv6), error);
+	if (ret < 0)
+		return ret;
+	flow->layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
+	if (size > flow_size)
+		return size;
+	if (spec) {
+		unsigned int i;
+		uint32_t vtc_flow_val;
+		uint32_t vtc_flow_mask;
+
+		memcpy(&ipv6.val.src_ip, spec->hdr.src_addr,
+		       RTE_DIM(ipv6.val.src_ip));
+		memcpy(&ipv6.val.dst_ip, spec->hdr.dst_addr,
+		       RTE_DIM(ipv6.val.dst_ip));
+		memcpy(&ipv6.mask.src_ip, mask->hdr.src_addr,
+		       RTE_DIM(ipv6.mask.src_ip));
+		memcpy(&ipv6.mask.dst_ip, mask->hdr.dst_addr,
+		       RTE_DIM(ipv6.mask.dst_ip));
+		vtc_flow_val = rte_be_to_cpu_32(spec->hdr.vtc_flow);
+		vtc_flow_mask = rte_be_to_cpu_32(mask->hdr.vtc_flow);
+		ipv6.val.flow_label =
+			rte_cpu_to_be_32((vtc_flow_val & IPV6_HDR_FL_MASK) >>
+					 IPV6_HDR_FL_SHIFT);
+		ipv6.val.traffic_class = (vtc_flow_val & IPV6_HDR_TC_MASK) >>
+					 IPV6_HDR_TC_SHIFT;
+		ipv6.val.next_hdr = spec->hdr.proto;
+		ipv6.val.hop_limit = spec->hdr.hop_limits;
+		ipv6.mask.flow_label =
+			rte_cpu_to_be_32((vtc_flow_mask & IPV6_HDR_FL_MASK) >>
+					 IPV6_HDR_FL_SHIFT);
+		ipv6.mask.traffic_class = (vtc_flow_mask & IPV6_HDR_TC_MASK) >>
+					  IPV6_HDR_TC_SHIFT;
+		ipv6.mask.next_hdr = mask->hdr.proto;
+		ipv6.mask.hop_limit = mask->hdr.hop_limits;
+		/* Remove unwanted bits from values. */
+		for (i = 0; i < RTE_DIM(ipv6.val.src_ip); ++i) {
+			ipv6.val.src_ip[i] &= ipv6.mask.src_ip[i];
+			ipv6.val.dst_ip[i] &= ipv6.mask.dst_ip[i];
+		}
+		ipv6.val.flow_label &= ipv6.mask.flow_label;
+		ipv6.val.traffic_class &= ipv6.mask.traffic_class;
+		ipv6.val.next_hdr &= ipv6.mask.next_hdr;
+		ipv6.val.hop_limit &= ipv6.mask.hop_limit;
+	}
+	mlx5_flow_spec_verbs_add(flow, &ipv6, size);
+	return size;
+}
+
 /**
  * Validate items provided by the user.
  *
@@ -659,6 +764,9 @@ mlx5_flow_items(const struct rte_flow_item items[],
 		case RTE_FLOW_ITEM_TYPE_IPV4:
 			ret = mlx5_flow_item_ipv4(items, flow, remain, error);
 			break;
+		case RTE_FLOW_ITEM_TYPE_IPV6:
+			ret = mlx5_flow_item_ipv6(items, flow, remain, error);
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ITEM,
-- 
2.18.0