[v5,21/80] net/ntnic: add action VLAN

Message ID 20241030213940.3470062-22-sil-plv@napatech.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series Provide flow filter and statistics support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Serhii Iliushyk Oct. 30, 2024, 9:38 p.m. UTC
From: Danylo Vodopianov <dvo-plv@napatech.com>

Add possibility to use RTE_FLOW_ITEM_TYPE_VLAN.

Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
 doc/guides/nics/features/ntnic.ini            |  1 +
 doc/guides/nics/ntnic.rst                     |  1 +
 drivers/net/ntnic/include/hw_mod_backend.h    |  1 +
 .../profile_inline/flow_api_profile_inline.c  | 95 +++++++++++++++++++
 4 files changed, 98 insertions(+)
  

Patch

diff --git a/doc/guides/nics/features/ntnic.ini b/doc/guides/nics/features/ntnic.ini
index e3c3982895..8b4821d6d0 100644
--- a/doc/guides/nics/features/ntnic.ini
+++ b/doc/guides/nics/features/ntnic.ini
@@ -21,6 +21,7 @@  ipv4                 = Y
 port_id              = Y
 tcp                  = Y
 udp                  = Y
+vlan                 = Y
 
 [rte_flow actions]
 drop                 = Y
diff --git a/doc/guides/nics/ntnic.rst b/doc/guides/nics/ntnic.rst
index d43706b2ee..f2ce941fe9 100644
--- a/doc/guides/nics/ntnic.rst
+++ b/doc/guides/nics/ntnic.rst
@@ -46,6 +46,7 @@  Features
 - Scattered and gather for TX and RX.
 - Jumbo frame support.
 - Traffic mirroring.
+- VLAN filtering.
 
 Limitations
 ~~~~~~~~~~~
diff --git a/drivers/net/ntnic/include/hw_mod_backend.h b/drivers/net/ntnic/include/hw_mod_backend.h
index a1aa74caf5..82ac3d0ff3 100644
--- a/drivers/net/ntnic/include/hw_mod_backend.h
+++ b/drivers/net/ntnic/include/hw_mod_backend.h
@@ -134,6 +134,7 @@  static inline int is_non_zero(const void *addr, size_t n)
 
 enum frame_offs_e {
 	DYN_L2 = 1,
+	DYN_FIRST_VLAN = 2,
 	DYN_L3 = 4,
 	DYN_L4 = 7,
 	DYN_L4_PAYLOAD = 8,
diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
index 4c3844e9b8..627d32047b 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
@@ -504,6 +504,20 @@  static int interpret_flow_elements(const struct flow_eth_dev *dev,
 		return -1;
 	}
 
+	if (implicit_vlan_vid > 0) {
+		uint32_t *sw_data = &packet_data[1 - sw_counter];
+		uint32_t *sw_mask = &packet_mask[1 - sw_counter];
+
+		sw_mask[0] = 0x0fff;
+		sw_data[0] = implicit_vlan_vid & sw_mask[0];
+
+		km_add_match_elem(&fd->km, &sw_data[0], &sw_mask[0], 1, DYN_FIRST_VLAN, 0);
+		set_key_def_sw(key_def, sw_counter, DYN_FIRST_VLAN, 0);
+		sw_counter += 1;
+
+		fd->vlans += 1;
+	}
+
 	int qw_reserved_mac = 0;
 	int qw_reserved_ipv6 = 0;
 
@@ -664,6 +678,87 @@  static int interpret_flow_elements(const struct flow_eth_dev *dev,
 
 			break;
 
+		case RTE_FLOW_ITEM_TYPE_VLAN:
+			NT_LOG(DBG, FILTER, "Adap %i, Port %i: RTE_FLOW_ITEM_TYPE_VLAN",
+				dev->ndev->adapter_no, dev->port);
+			{
+				const struct rte_vlan_hdr *vlan_spec =
+					(const struct rte_vlan_hdr *)elem[eidx].spec;
+				const struct rte_vlan_hdr *vlan_mask =
+					(const struct rte_vlan_hdr *)elem[eidx].mask;
+
+				if (vlan_spec == NULL || vlan_mask == NULL) {
+					fd->vlans += 1;
+					break;
+				}
+
+				if (!vlan_mask->vlan_tci && !vlan_mask->eth_proto)
+					break;
+
+				if (implicit_vlan_vid > 0) {
+					NT_LOG(ERR, FILTER,
+						"Multiple VLANs not supported for implicit VLAN patterns.");
+					flow_nic_set_error(ERR_MATCH_INVALID_OR_UNSUPPORTED_ELEM,
+						error);
+					return -1;
+				}
+
+				if (sw_counter < 2) {
+					uint32_t *sw_data = &packet_data[1 - sw_counter];
+					uint32_t *sw_mask = &packet_mask[1 - sw_counter];
+
+					sw_mask[0] = ntohs(vlan_mask->vlan_tci) << 16 |
+						ntohs(vlan_mask->eth_proto);
+					sw_data[0] = ntohs(vlan_spec->vlan_tci) << 16 |
+						ntohs(vlan_spec->eth_proto);
+					sw_data[0] &= sw_mask[0];
+
+					km_add_match_elem(&fd->km, &sw_data[0], &sw_mask[0], 1,
+						DYN_FIRST_VLAN, 2 + 4 * fd->vlans);
+					set_key_def_sw(key_def, sw_counter, DYN_FIRST_VLAN,
+						2 + 4 * fd->vlans);
+					sw_counter += 1;
+
+				} else if (qw_counter < 2 && qw_free > 0) {
+					uint32_t *qw_data = &packet_data[2 + 4 - qw_counter * 4];
+					uint32_t *qw_mask = &packet_mask[2 + 4 - qw_counter * 4];
+
+					qw_data[0] = ntohs(vlan_spec->vlan_tci) << 16 |
+						ntohs(vlan_spec->eth_proto);
+					qw_data[1] = 0;
+					qw_data[2] = 0;
+					qw_data[3] = 0;
+
+					qw_mask[0] = ntohs(vlan_mask->vlan_tci) << 16 |
+						ntohs(vlan_mask->eth_proto);
+					qw_mask[1] = 0;
+					qw_mask[2] = 0;
+					qw_mask[3] = 0;
+
+					qw_data[0] &= qw_mask[0];
+					qw_data[1] &= qw_mask[1];
+					qw_data[2] &= qw_mask[2];
+					qw_data[3] &= qw_mask[3];
+
+					km_add_match_elem(&fd->km, &qw_data[0], &qw_mask[0], 4,
+						DYN_FIRST_VLAN, 2 + 4 * fd->vlans);
+					set_key_def_qw(key_def, qw_counter, DYN_FIRST_VLAN,
+						2 + 4 * fd->vlans);
+					qw_counter += 1;
+					qw_free -= 1;
+
+				} else {
+					NT_LOG(ERR, FILTER,
+						"Key size too big. Out of SW-QW resources.");
+					flow_nic_set_error(ERR_FAILED, error);
+					return -1;
+				}
+
+				fd->vlans += 1;
+			}
+
+			break;
+
 		case RTE_FLOW_ITEM_TYPE_IPV4:
 			NT_LOG(DBG, FILTER, "Adap %i, Port %i: RTE_FLOW_ITEM_TYPE_IPV4",
 				dev->ndev->adapter_no, dev->port);