DPDK patches and discussions
 help / color / mirror / Atom feed
From: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
To: dev@dpdk.org, Yongseok Koh <yskoh@mellanox.com>
Cc: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Subject: [dpdk-dev] [PATCH v4 10/21] net/mlx5: add flow UDP item
Date: Thu, 12 Jul 2018 11:30:56 +0200	[thread overview]
Message-ID: <4da6a61eba9065a78a4af8f4fa78d7ccb7fced26.1531387413.git.nelio.laranjeiro@6wind.com> (raw)
In-Reply-To: <cover.1531387413.git.nelio.laranjeiro@6wind.com>

Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.c | 97 +++++++++++++++++++++++++++++++++---
 1 file changed, 91 insertions(+), 6 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 513f70d40..0096ed8a2 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -52,6 +52,9 @@ extern const struct eth_dev_ops mlx5_dev_ops_isolate;
 #define MLX5_FLOW_FATE_DROP (1u << 0)
 #define MLX5_FLOW_FATE_QUEUE (1u << 1)
 
+/* possible L3 layers protocols filtering. */
+#define MLX5_IP_PROTOCOL_UDP 17
+
 /** Handles information leading to a drop fate. */
 struct mlx5_flow_verbs {
 	unsigned int size; /**< Size of the attribute. */
@@ -68,10 +71,12 @@ struct mlx5_flow_verbs {
 struct rte_flow {
 	TAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */
 	struct rte_flow_attr attributes; /**< User flow attribute. */
+	uint32_t l3_protocol_en:1; /**< Protocol filtering requested. */
 	uint32_t layers;
 	/**< Bit-fields of present layers see MLX5_FLOW_LAYER_*. */
 	uint32_t fate;
 	/**< Bit-fields of present fate see MLX5_FLOW_FATE_*. */
+	uint8_t l3_protocol; /**< valid when l3_protocol_en is set. */
 	struct mlx5_flow_verbs verbs; /* Verbs flow. */
 	uint16_t queue; /**< Destination queue to redirect traffic to. */
 };
@@ -568,8 +573,6 @@ mlx5_flow_item_ipv4(const struct rte_flow_item *item, struct rte_flow *flow,
 	if (ret < 0)
 		return ret;
 	flow->layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
-	if (size > flow_size)
-		return size;
 	if (spec) {
 		ipv4.val = (struct ibv_flow_ipv4_ext_filter){
 			.src_ip = spec->hdr.src_addr,
@@ -589,7 +592,10 @@ mlx5_flow_item_ipv4(const struct rte_flow_item *item, struct rte_flow *flow,
 		ipv4.val.proto &= ipv4.mask.proto;
 		ipv4.val.tos &= ipv4.mask.tos;
 	}
-	mlx5_flow_spec_verbs_add(flow, &ipv4, size);
+	flow->l3_protocol_en = !!ipv4.mask.proto;
+	flow->l3_protocol = ipv4.val.proto;
+	if (size <= flow_size)
+		mlx5_flow_spec_verbs_add(flow, &ipv4, size);
 	return size;
 }
 
@@ -660,8 +666,6 @@ mlx5_flow_item_ipv6(const struct rte_flow_item *item, struct rte_flow *flow,
 	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;
@@ -701,7 +705,85 @@ mlx5_flow_item_ipv6(const struct rte_flow_item *item, struct rte_flow *flow,
 		ipv6.val.next_hdr &= ipv6.mask.next_hdr;
 		ipv6.val.hop_limit &= ipv6.mask.hop_limit;
 	}
-	mlx5_flow_spec_verbs_add(flow, &ipv6, size);
+	flow->l3_protocol_en = !!ipv6.mask.next_hdr;
+	flow->l3_protocol = ipv6.val.next_hdr;
+	if (size <= flow_size)
+		mlx5_flow_spec_verbs_add(flow, &ipv6, size);
+	return size;
+}
+
+/**
+ * Convert the @p item into a 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_udp(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_udp *spec = item->spec;
+	const struct rte_flow_item_udp *mask = item->mask;
+	unsigned int size = sizeof(struct ibv_flow_spec_tcp_udp);
+	struct ibv_flow_spec_tcp_udp udp = {
+		.type = IBV_FLOW_SPEC_UDP,
+		.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,
+					  "L3 is mandatory to filter on L4");
+	if (flow->layers & MLX5_FLOW_LAYER_OUTER_L4)
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ITEM,
+					  item,
+					  "L4 layer is already present");
+	if (flow->l3_protocol_en && flow->l3_protocol != MLX5_IP_PROTOCOL_UDP)
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_ITEM,
+					  item,
+					  "protocol filtering not compatible"
+					  " with UDP layer");
+	if (!mask)
+		mask = &rte_flow_item_udp_mask;
+	ret = mlx5_flow_item_acceptable
+		(item, (const uint8_t *)mask,
+		 (const uint8_t *)&rte_flow_item_udp_mask,
+		 sizeof(struct rte_flow_item_udp), error);
+	if (ret < 0)
+		return ret;
+	flow->layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
+	if (size > flow_size)
+		return size;
+	if (spec) {
+		udp.val.dst_port = spec->hdr.dst_port;
+		udp.val.src_port = spec->hdr.src_port;
+		udp.mask.dst_port = mask->hdr.dst_port;
+		udp.mask.src_port = mask->hdr.src_port;
+		/* Remove unwanted bits from values. */
+		udp.val.src_port &= udp.mask.src_port;
+		udp.val.dst_port &= udp.mask.dst_port;
+	}
+	mlx5_flow_spec_verbs_add(flow, &udp, size);
 	return size;
 }
 
@@ -756,6 +838,9 @@ mlx5_flow_items(const struct rte_flow_item pattern[],
 		case RTE_FLOW_ITEM_TYPE_IPV6:
 			ret = mlx5_flow_item_ipv6(pattern, flow, remain, error);
 			break;
+		case RTE_FLOW_ITEM_TYPE_UDP:
+			ret = mlx5_flow_item_udp(pattern, flow, remain, error);
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ITEM,
-- 
2.18.0

  parent reply	other threads:[~2018-07-12  9:31 UTC|newest]

Thread overview: 118+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-28 11:21 [dpdk-dev] [DPDK 18.08 v1 00/12] net/mlx5: flow rework Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 01/12] net/mlx5: remove flow support Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 02/12] net/mlx5: handle drop queues are regular queues Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 03/12] net/mlx5: support flow Ethernet item among with drop action Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 04/12] net/mlx5: add flow queue action Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 05/12] net/mlx5: add flow stop/start Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 06/12] net/mlx5: add flow VLAN item Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 07/12] net/mlx5: add flow IPv4 item Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 08/12] net/mlx5: add flow IPv6 item Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 09/12] net/mlx5: add flow UDP item Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 10/12] net/mlx5: add flow TCP item Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 11/12] net/mlx5: add mark/flag flow action Nelio Laranjeiro
2018-05-28 11:21 ` [dpdk-dev] [DPDK 18.08 v1 12/12] net/mlx5: add RSS " Nelio Laranjeiro
2018-05-28 13:32 ` [dpdk-dev] [DPDK 18.08 v1 00/12] net/mlx5: flow rework Wiles, Keith
2018-05-28 13:47   ` Ferruh Yigit
2018-05-28 13:50   ` Nélio Laranjeiro
2018-06-27 15:07 ` [dpdk-dev] [PATCH v2 00/20] " Nelio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 01/20] net/mlx5: remove flow support Nelio Laranjeiro
2018-07-02 21:53     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 02/20] net/mlx5: handle drop queues are regular queues Nelio Laranjeiro
2018-07-03  1:07     ` Yongseok Koh
2018-07-03  7:17       ` Nélio Laranjeiro
2018-07-03 17:05         ` Yongseok Koh
2018-07-04  6:44           ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 03/20] net/mlx5: replace verbs priorities by flow Nelio Laranjeiro
2018-07-03  1:40     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 04/20] net/mlx5: support flow Ethernet item among with drop action Nelio Laranjeiro
2018-07-03 22:27     ` Yongseok Koh
2018-07-04  9:24       ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 05/20] net/mlx5: add flow queue action Nelio Laranjeiro
2018-07-03 23:00     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 06/20] net/mlx5: add flow stop/start Nelio Laranjeiro
2018-07-03 23:08     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 07/20] net/mlx5: add flow VLAN item Nelio Laranjeiro
2018-07-03 23:56     ` Yongseok Koh
2018-07-04 12:03       ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 08/20] net/mlx5: add flow IPv4 item Nelio Laranjeiro
2018-07-04  0:12     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 09/20] net/mlx5: add flow IPv6 item Nelio Laranjeiro
2018-07-04  0:16     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 10/20] net/mlx5: add flow UDP item Nelio Laranjeiro
2018-07-04  0:17     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 11/20] net/mlx5: add flow TCP item Nelio Laranjeiro
2018-07-04  0:18     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 12/20] net/mlx5: add mark/flag flow action Nelio Laranjeiro
2018-07-04  8:34     ` Yongseok Koh
2018-07-05  8:47       ` Nélio Laranjeiro
2018-07-05 19:56         ` Yongseok Koh
2018-07-06  8:23           ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 13/20] net/mlx5: add RSS " Nelio Laranjeiro
2018-07-06  2:16     ` Yongseok Koh
2018-07-06 15:59       ` Nélio Laranjeiro
2018-07-06 17:35         ` Yongseok Koh
2018-07-09 13:09           ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 14/20] net/mlx5: remove useless arguments in hrxq API Nelio Laranjeiro
2018-07-06  2:18     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 15/20] net/mlx5: support inner RSS computation Nelio Laranjeiro
2018-07-06  8:16     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 16/20] net/mlx5: add flow VXLAN item Nelio Laranjeiro
2018-07-06 23:14     ` Yongseok Koh
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 17/20] net/mlx5: add flow VXLAN-GPE item Nelio Laranjeiro
2018-07-06 23:23     ` Yongseok Koh
2018-07-09 14:53       ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 18/20] net/mlx5: add flow GRE item Nelio Laranjeiro
2018-07-06 23:46     ` Yongseok Koh
2018-07-09 13:58       ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 19/20] net/mlx5: add flow MPLS item Nelio Laranjeiro
2018-07-07  0:11     ` Yongseok Koh
2018-07-09 15:00       ` Nélio Laranjeiro
2018-06-27 15:07   ` [dpdk-dev] [PATCH v2 20/20] net/mlx5: add count flow action Nelio Laranjeiro
2018-07-07  1:08     ` Yongseok Koh
2018-07-11  7:22   ` [dpdk-dev] [PATCH v3 00/21] net/mlx5: flow rework Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 01/21] net/mlx5: remove flow support Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 02/21] net/mlx5: handle drop queues as regular queues Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 03/21] net/mlx5: replace verbs priorities by flow Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 04/21] net/mlx5: support flow Ethernet item along with drop action Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 05/21] net/mlx5: add flow queue action Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 06/21] net/mlx5: add flow stop/start Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 07/21] net/mlx5: add flow VLAN item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 08/21] net/mlx5: add flow IPv4 item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 09/21] net/mlx5: add flow IPv6 item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 10/21] net/mlx5: add flow UDP item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 11/21] net/mlx5: add flow TCP item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 12/21] net/mlx5: add mark/flag flow action Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 13/21] net/mlx5: use a macro for the RSS key size Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 14/21] net/mlx5: add RSS flow action Nelio Laranjeiro
2018-07-11 19:57       ` Yongseok Koh
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 15/21] net/mlx5: remove useless arguments in hrxq API Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 16/21] net/mlx5: support inner RSS computation Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 17/21] net/mlx5: add flow VXLAN item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 18/21] net/mlx5: add flow VXLAN-GPE item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 19/21] net/mlx5: add flow GRE item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 20/21] net/mlx5: add flow MPLS item Nelio Laranjeiro
2018-07-11  7:22     ` [dpdk-dev] [PATCH v3 21/21] net/mlx5: add count flow action Nelio Laranjeiro
2018-07-11 20:00     ` [dpdk-dev] [PATCH v3 00/21] net/mlx5: flow rework Yongseok Koh
2018-07-12  9:30     ` [dpdk-dev] [PATCH v4 " Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 01/21] net/mlx5: remove flow support Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 02/21] net/mlx5: handle drop queues as regular queues Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 03/21] net/mlx5: replace verbs priorities by flow Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 04/21] net/mlx5: support flow Ethernet item along with drop action Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 05/21] net/mlx5: add flow queue action Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 06/21] net/mlx5: add flow stop/start Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 07/21] net/mlx5: add flow VLAN item Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 08/21] net/mlx5: add flow IPv4 item Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 09/21] net/mlx5: add flow IPv6 item Nelio Laranjeiro
2018-07-12  9:30       ` Nelio Laranjeiro [this message]
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 11/21] net/mlx5: add flow TCP item Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 12/21] net/mlx5: add mark/flag flow action Nelio Laranjeiro
2018-07-12  9:30       ` [dpdk-dev] [PATCH v4 13/21] net/mlx5: use a macro for the RSS key size Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 14/21] net/mlx5: add RSS flow action Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 15/21] net/mlx5: remove useless arguments in hrxq API Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 16/21] net/mlx5: support inner RSS computation Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 17/21] net/mlx5: add flow VXLAN item Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 18/21] net/mlx5: add flow VXLAN-GPE item Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 19/21] net/mlx5: add flow GRE item Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 20/21] net/mlx5: add flow MPLS item Nelio Laranjeiro
2018-07-12  9:31       ` [dpdk-dev] [PATCH v4 21/21] net/mlx5: add count flow action Nelio Laranjeiro
2018-07-12 10:44       ` [dpdk-dev] [PATCH v4 00/21] net/mlx5: flow rework Shahaf Shuler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4da6a61eba9065a78a4af8f4fa78d7ccb7fced26.1531387413.git.nelio.laranjeiro@6wind.com \
    --to=nelio.laranjeiro@6wind.com \
    --cc=adrien.mazarguil@6wind.com \
    --cc=dev@dpdk.org \
    --cc=yskoh@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).