[RFC] net/mlx5: support e-switch TCP-flags flow filter

Message ID 1534953307-8683-1-git-send-email-motih@mellanox.com (mailing list archive)
State Superseded, archived
Headers
Series [RFC] net/mlx5: support e-switch TCP-flags flow filter |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Moti Haimovsky Aug. 22, 2018, 3:55 p.m. UTC
  Today, it is possible to offload an interface flow rules to the hardware
using DPDK flow commands.
With mlx5 it is also possible to offload a limited set of flow rules to
the mlxsw (or e-switch) using the same DPDK flow commands.
A 'transfer' attribute was added to the flow rule creation command in
order to distinguish between configuring port flows and E-switch flows.
The commands destined for the switch are transposed to TC flower rules
and are send, as Netlink messages, to the mlx5 driver, or more precisely
to the netdev which represent the mlxsw port.
The limited set of e-switch flow rules also supports filtering according
to the values found in the TCP flags. but the mlx5 PMD does not
implement this filter.
The purpose of this RFC is to propose an enhancement to the e-switch
flow filtering rules to also include filtering according to the TCP
flags.

Below is the propose enhancement.

NOTE:
 This code is supposed to be applied on top of the flow steering
 rework not committed yet and therefore may be subject to changes.

Signed-off-by: Moti Haimovsky <motih@mellanox.com>
---
 drivers/net/mlx5/Makefile       | 10 ++++++++++
 drivers/net/mlx5/mlx5_nl_flow.c | 20 +++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile
index 2e70dec..02139ce 100644
--- a/drivers/net/mlx5/Makefile
+++ b/drivers/net/mlx5/Makefile
@@ -335,6 +335,16 @@  mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh
 		enum TCA_FLOWER_KEY_VLAN_ETH_TYPE \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_TCA_FLOWER_KEY_TCP_FLAGS \
+		linux/pkt_cls.h \
+		enum TCA_FLOWER_KEY_TCP_FLAGS \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
+		HAVE_TCA_FLOWER_KEY_TCP_FLAGS_MASK \
+		linux/pkt_cls.h \
+		enum TCA_FLOWER_KEY_TCP_FLAGS_MASK \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_TC_ACT_VLAN \
 		linux/tc_act/tc_vlan.h \
 		enum TCA_VLAN_PUSH_VLAN_PRIORITY \
diff --git a/drivers/net/mlx5/mlx5_nl_flow.c b/drivers/net/mlx5/mlx5_nl_flow.c
index beb03c9..af66ae1 100644
--- a/drivers/net/mlx5/mlx5_nl_flow.c
+++ b/drivers/net/mlx5/mlx5_nl_flow.c
@@ -146,6 +146,12 @@  struct tc_vlan {
 #ifndef HAVE_TCA_FLOWER_KEY_VLAN_ETH_TYPE
 #define TCA_FLOWER_KEY_VLAN_ETH_TYPE 25
 #endif
+#ifndef TCA_FLOWER_KEY_TCP_FLAGS
+#define TCA_FLOWER_KEY_TCP_FLAGS 71
+#endif
+#ifndef TCA_FLOWER_KEY_TCP_FLAGS_MASK
+#define TCA_FLOWER_KEY_TCP_FLAGS_MASK 72
+#endif
 
 /** Parser state definitions for mlx5_nl_flow_trans[]. */
 enum mlx5_nl_flow_trans {
@@ -258,6 +264,7 @@  enum mlx5_nl_flow_trans {
 	.tcp.hdr = {
 		.src_port = RTE_BE16(0xffff),
 		.dst_port = RTE_BE16(0xffff),
+		.tcp_flags = 0xff,
 	},
 	.udp.hdr = {
 		.src_port = RTE_BE16(0xffff),
@@ -812,7 +819,18 @@  enum mlx5_nl_flow_trans {
 					      spec.tcp->hdr.dst_port) ||
 		      !mnl_attr_put_u16_check(buf, size,
 					      TCA_FLOWER_KEY_TCP_DST_MASK,
-					      mask.tcp->hdr.dst_port))))
+					      mask.tcp->hdr.dst_port))) ||
+		    (mask.tcp->hdr.tcp_flags &&
+		     (!mnl_attr_put_u16_check
+				     (buf, size,
+				      TCA_FLOWER_KEY_TCP_FLAGS,
+				      rte_cpu_to_be_16
+						(spec.tcp->hdr.tcp_flags)) ||
+		      !mnl_attr_put_u16_check
+				     (buf, size,
+				      TCA_FLOWER_KEY_TCP_FLAGS_MASK,
+				      rte_cpu_to_be_16
+						(mask.tcp->hdr.tcp_flags)))))
 			goto error_nobufs;
 		++item;
 		break;