Skip to contentSkip to conversation

ice: Support flow director ether type filters

PATCH Superseded Lukasz Plachno 5 participants 8 messages Jan 24, 2024 – Jan 31, 2024

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover ice: Support flow director ether type filters

Ethtool allows creating rules with type=ether, add support for such filters in ice driver.
Patch 1 allows extending ice_fdir_comp_rules() with handling additional type of filters.

v4: added warning explaining that masks other than broadcast and unicast
are not supported, added check for empty filters
v3: fixed possible use of uninitialized variable "perfect_filter"
v2: fixed compilation warning by moving default: case between commits Jakub Buchocki (1):
ice: Implement 'flow-type ether' rules

Lukasz Plachno (1):
ice: Remove unnecessary argument from ice_fdir_comp_rules()

 .../net/ethernet/intel/ice/ice_ethtool_fdir.c | 140 +++++++++++++++++-
 drivers/net/ethernet/intel/ice/ice_fdir.c     | 112 ++++++++------
 drivers/net/ethernet/intel/ice/ice_fdir.h     |  11 ++
 drivers/net/ethernet/intel/ice/ice_type.h     |   1 +
 4 files changed, 217 insertions(+), 47 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/2 ice: Remove unnecessary argument from ice_fdir_comp_rules()

Passing v6 argument is unnecessary as flow_type is still analyzed inside the function.

---
 drivers/net/ethernet/intel/ice/ice_fdir.c | 85 +++++++++++------------
 1 file changed, 39 insertions(+), 46 deletions(-)
drivers/net/ethernet/intel/ice/ice_fdir.c +39 -46
index 5840c3e04a5b..1f7b26f38818 100644
@@ -1189,52 +1189,54 @@ static int ice_cmp_ipv6_addr(__be32 *a, __be32 *b)
  * ice_fdir_comp_rules - compare 2 filters
  * @a: a Flow Director filter data structure
  * @b: a Flow Director filter data structure
- * @v6: bool true if v6 filter
  *
  * Returns true if the filters match
  */
 static bool
-ice_fdir_comp_rules(struct ice_fdir_fltr *a,  struct ice_fdir_fltr *b, bool v6)
+ice_fdir_comp_rules(struct ice_fdir_fltr *a,  struct ice_fdir_fltr *b)
 {
 	enum ice_fltr_ptype flow_type = a->flow_type;
 
 	/* The calling function already checks that the two filters have the
 	 * same flow_type.
 	 */
-	if (!v6) {
-		if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP ||
-		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP ||
-		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP) {
-			if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
-			    a->ip.v4.src_ip == b->ip.v4.src_ip &&
-			    a->ip.v4.dst_port == b->ip.v4.dst_port &&
-			    a->ip.v4.src_port == b->ip.v4.src_port)
-				return true;
-		} else if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER) {
-			if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
-			    a->ip.v4.src_ip == b->ip.v4.src_ip &&
-			    a->ip.v4.l4_header == b->ip.v4.l4_header &&
-			    a->ip.v4.proto == b->ip.v4.proto &&
-			    a->ip.v4.ip_ver == b->ip.v4.ip_ver &&
-			    a->ip.v4.tos == b->ip.v4.tos)
-				return true;
-		}
-	} else {
-		if (flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP ||
-		    flow_type == ICE_FLTR_PTYPE_NONF_IPV6_TCP ||
-		    flow_type == ICE_FLTR_PTYPE_NONF_IPV6_SCTP) {
-			if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
-			    a->ip.v6.src_port == b->ip.v6.src_port &&
-			    !ice_cmp_ipv6_addr(a->ip.v6.dst_ip,
-					       b->ip.v6.dst_ip) &&
-			    !ice_cmp_ipv6_addr(a->ip.v6.src_ip,
-					       b->ip.v6.src_ip))
-				return true;
-		} else if (flow_type == ICE_FLTR_PTYPE_NONF_IPV6_OTHER) {
-			if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
-			    a->ip.v6.src_port == b->ip.v6.src_port)
-				return true;
-		}
+	switch (flow_type) {
+	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
+	case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
+	case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
+		if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
+		    a->ip.v4.src_ip == b->ip.v4.src_ip &&
+		    a->ip.v4.dst_port == b->ip.v4.dst_port &&
+		    a->ip.v4.src_port == b->ip.v4.src_port)
+			return true;
+		break;
+	case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
+		if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
+		    a->ip.v4.src_ip == b->ip.v4.src_ip &&
+		    a->ip.v4.l4_header == b->ip.v4.l4_header &&
+		    a->ip.v4.proto == b->ip.v4.proto &&
+		    a->ip.v4.ip_ver == b->ip.v4.ip_ver &&
+		    a->ip.v4.tos == b->ip.v4.tos)
+			return true;
+		break;
+	case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
+	case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
+	case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
+		if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
+		    a->ip.v6.src_port == b->ip.v6.src_port &&
+		    !ice_cmp_ipv6_addr(a->ip.v6.dst_ip,
+				       b->ip.v6.dst_ip) &&
+		    !ice_cmp_ipv6_addr(a->ip.v6.src_ip,
+				       b->ip.v6.src_ip))
+			return true;
+		break;
+	case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
+		if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
+		    a->ip.v6.src_port == b->ip.v6.src_port)
+			return true;
+		break;
+	default:
+		break;
 	}
 
 	return false;
@@ -1253,19 +1255,10 @@ bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input)
 	bool ret = false;
 
 	list_for_each_entry(rule, &hw->fdir_list_head, fltr_node) {
-		enum ice_fltr_ptype flow_type;
-
 		if (rule->flow_type != input->flow_type)
 			continue;
 
-		flow_type = input->flow_type;
-		if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP ||
-		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP ||
-		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP ||
-		    flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER)
-			ret = ice_fdir_comp_rules(rule, input, false);
-		else
-			ret = ice_fdir_comp_rules(rule, input, true);
+		ret = ice_fdir_comp_rules(rule, input);
 		if (ret) {
 			if (rule->fltr_id == input->fltr_id &&
 			    rule->q_index != input->q_index)
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/2 ice: Implement 'flow-type ether' rules

In reply to Lukasz Plachno

From: Jakub Buchocki <[email protected]>

Add support for 'flow-type ether' Flow Director rules via ethtool.

Rules not containing masks are processed by the Flow Director, and support the following set of input parameters in all combinations:
src, dst, proto, vlan-etype, vlan, action.

It is possible to specify address mask in ethtool parameters but only 00:00:00:00:00 and FF:FF:FF:FF:FF are valid.
The same applies to proto, vlan-etype and vlan masks:
only 0x0000 and 0xffff masks are valid.

---
 .../net/ethernet/intel/ice/ice_ethtool_fdir.c | 140 +++++++++++++++++-
 drivers/net/ethernet/intel/ice/ice_fdir.c     |  27 ++++
 drivers/net/ethernet/intel/ice/ice_fdir.h     |  11 ++
 drivers/net/ethernet/intel/ice/ice_type.h     |   1 +
 4 files changed, 178 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +139 -1
index 9a1a04f5f146..d6fadc65a7a6 100644
@@ -41,6 +41,8 @@ static struct in6_addr zero_ipv6_addr_mask = {
 static int ice_fltr_to_ethtool_flow(enum ice_fltr_ptype flow)
 {
 	switch (flow) {
+	case ICE_FLTR_PTYPE_NONF_ETH:
+		return ETHER_FLOW;
 	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
 		return TCP_V4_FLOW;
 	case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
@@ -72,6 +74,8 @@ static int ice_fltr_to_ethtool_flow(enum ice_fltr_ptype flow)
 static enum ice_fltr_ptype ice_ethtool_flow_to_fltr(int eth)
 {
 	switch (eth) {
+	case ETHER_FLOW:
+		return ICE_FLTR_PTYPE_NONF_ETH;
 	case TCP_V4_FLOW:
 		return ICE_FLTR_PTYPE_NONF_IPV4_TCP;
 	case UDP_V4_FLOW:
@@ -137,6 +141,15 @@ int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd)
 	memset(&fsp->m_ext, 0, sizeof(fsp->m_ext));
 
 	switch (fsp->flow_type) {
+	case ETHER_FLOW:
+		fsp->h_u.ether_spec.h_proto = rule->eth.type;
+		fsp->m_u.ether_spec.h_proto = rule->eth_mask.type;
+		ether_addr_copy(fsp->h_u.ether_spec.h_dest, rule->eth.dst);
+		ether_addr_copy(fsp->m_u.ether_spec.h_dest, rule->eth_mask.dst);
+		ether_addr_copy(fsp->h_u.ether_spec.h_source, rule->eth.src);
+		ether_addr_copy(fsp->m_u.ether_spec.h_source,
+				rule->eth_mask.src);
+		break;
 	case IPV4_USER_FLOW:
 		fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
 		fsp->h_u.usr_ip4_spec.proto = 0;
@@ -1193,6 +1206,111 @@ ice_set_fdir_ip6_usr_seg(struct ice_flow_seg_info *seg,
 	return 0;
 }
 
+/**
+ * ice_fdir_vlan_valid - validate VLAN data for Flow Director rule
+ * @fsp: pointer to ethtool Rx flow specification
+ *
+ * Return: true if vlan data is valid, false otherwise
+ */
+static bool ice_fdir_vlan_valid(struct ethtool_rx_flow_spec *fsp)
+{
+	if (fsp->m_ext.vlan_etype && !eth_type_vlan(fsp->h_ext.vlan_etype))
+		return false;
+
+	if (fsp->m_ext.vlan_tci &&
+	    ntohs(fsp->h_ext.vlan_tci) >= VLAN_N_VID)
+		return false;
+
+	return true;
+}
+
+/**
+ * ice_set_ether_flow_seg
+ * @seg: flow segment for programming
+ * @eth_spec: mask data from ethtool
+ *
+ * Return: 0 on success and errno in case of error.
+ */
+static int ice_set_ether_flow_seg(struct device *dev,
+				  struct ice_flow_seg_info *seg,
+				  struct ethhdr *eth_spec)
+{
+	ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH);
+
+	/* empty rules are not valid */
+	if (is_zero_ether_addr(eth_spec->h_source) &&
+	    is_zero_ether_addr(eth_spec->h_dest) &&
+	    !eth_spec->h_proto)
+		return -EINVAL;
+
+	/* Ethertype */
+	if (eth_spec->h_proto == htons(0xFFFF)) {
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_TYPE,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	} else if (eth_spec->h_proto) {
+		dev_warn(dev, "Only 0x0000 or 0xffff proto mask is allowed for flow-type ether");
+		return -EOPNOTSUPP;
+	}
+
+	/* Source MAC address */
+	if (is_broadcast_ether_addr(eth_spec->h_source))
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_SA,
+				 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	else if (!is_zero_ether_addr(eth_spec->h_source))
+		goto err_mask;
+
+	/* Destination MAC address */
+	if (is_broadcast_ether_addr(eth_spec->h_dest))
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_DA,
+				 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	else if (!is_zero_ether_addr(eth_spec->h_dest))
+		goto err_mask;
+
+	return 0;
+
+err_mask:
+	dev_warn(dev, "Only 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff MAC address mask is allowed for flow-type ether");
+	return -EOPNOTSUPP;
+}
+
+/**
+ * ice_set_fdir_vlan_seg
+ * @seg: flow segment for programming
+ * @ext_masks: masks for additional RX flow fields
+ */
+static int
+ice_set_fdir_vlan_seg(struct ice_flow_seg_info *seg,
+		      struct ethtool_flow_ext *ext_masks)
+{
+	ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_VLAN);
+
+	if (ext_masks->vlan_etype) {
+		if (ext_masks->vlan_etype != htons(0xFFFF))
+			return -EOPNOTSUPP;
+
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_S_VLAN,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	}
+
+	if (ext_masks->vlan_tci) {
+		if (ext_masks->vlan_tci != htons(0xFFFF))
+			return -EOPNOTSUPP;
+
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_C_VLAN,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	}
+
+	return 0;
+}
+
 /**
  * ice_cfg_fdir_xtrct_seq - Configure extraction sequence for the given filter
  * @pf: PF structure
@@ -1209,7 +1327,7 @@ ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, struct ethtool_rx_flow_spec *fsp,
 	struct device *dev = ice_pf_to_dev(pf);
 	enum ice_fltr_ptype fltr_idx;
 	struct ice_hw *hw = &pf->hw;
-	bool perfect_filter;
+	bool perfect_filter = false;
 	int ret;
 
 	seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL);
@@ -1262,6 +1380,16 @@ ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, struct ethtool_rx_flow_spec *fsp,
 		ret = ice_set_fdir_ip6_usr_seg(seg, &fsp->m_u.usr_ip6_spec,
 					       &perfect_filter);
 		break;
+	case ETHER_FLOW:
+		ret = ice_set_ether_flow_seg(dev, seg, &fsp->m_u.ether_spec);
+		if (!ret && (fsp->m_ext.vlan_etype || fsp->m_ext.vlan_tci)) {
+			if (!ice_fdir_vlan_valid(fsp)) {
+				ret = -EINVAL;
+				break;
+			}
+			ret = ice_set_fdir_vlan_seg(seg, &fsp->m_ext);
+		}
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1823,6 +1951,16 @@ ice_set_fdir_input_set(struct ice_vsi *vsi, struct ethtool_rx_flow_spec *fsp,
 		input->mask.v6.tc = fsp->m_u.usr_ip6_spec.tclass;
 		input->mask.v6.proto = fsp->m_u.usr_ip6_spec.l4_proto;
 		break;
+	case ETHER_FLOW:
+		ether_addr_copy(input->eth.dst, fsp->h_u.ether_spec.h_dest);
+		ether_addr_copy(input->eth.src, fsp->h_u.ether_spec.h_source);
+		ether_addr_copy(input->eth_mask.dst,
+				fsp->m_u.ether_spec.h_dest);
+		ether_addr_copy(input->eth_mask.src,
+				fsp->m_u.ether_spec.h_source);
+		input->eth.type = fsp->h_u.ether_spec.h_proto;
+		input->eth_mask.type = fsp->m_u.ether_spec.h_proto;
+		break;
 	default:
 		/* not doing un-parsed flow types */
 		return -EINVAL;
drivers/net/ethernet/intel/ice/ice_fdir.c +27 -0
index 1f7b26f38818..5fe0bad00fd7 100644
@@ -4,6 +4,8 @@
 #include "ice_common.h"
 
 /* These are training packet headers used to program flow director filters. */
+static const u8 ice_fdir_eth_pkt[22] = {0};
+
 static const u8 ice_fdir_tcpv4_pkt[] = {
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
@@ -416,6 +418,11 @@ static const u8 ice_fdir_ip6_tun_pkt[] = {
 
 /* Flow Director no-op training packet table */
 static const struct ice_fdir_base_pkt ice_fdir_pkt[] = {
+	{
+		ICE_FLTR_PTYPE_NONF_ETH,
+		sizeof(ice_fdir_eth_pkt), ice_fdir_eth_pkt,
+		sizeof(ice_fdir_eth_pkt), ice_fdir_eth_pkt,
+	},
 	{
 		ICE_FLTR_PTYPE_NONF_IPV4_TCP,
 		sizeof(ice_fdir_tcpv4_pkt), ice_fdir_tcpv4_pkt,
@@ -914,6 +921,22 @@ ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
 	 * perspective. The input from user is from Rx filter perspective.
 	 */
 	switch (flow) {
+	case ICE_FLTR_PTYPE_NONF_ETH:
+		ice_pkt_insert_mac_addr(loc, input->eth.dst);
+		ice_pkt_insert_mac_addr(loc + ETH_ALEN, input->eth.src);
+		if (input->ext_data.vlan_tag ||
+		    input->ext_data.vlan_type) {
+			ice_pkt_insert_u16(loc, ICE_ETH_TYPE_F_OFFSET,
+					   input->ext_data.vlan_type);
+			ice_pkt_insert_u16(loc, ICE_ETH_VLAN_TCI_OFFSET,
+					   input->ext_data.vlan_tag);
+			ice_pkt_insert_u16(loc, ICE_ETH_TYPE_VLAN_OFFSET,
+					   input->eth.type);
+		} else {
+			ice_pkt_insert_u16(loc, ICE_ETH_TYPE_F_OFFSET,
+					   input->eth.type);
+		}
+		break;
 	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
 		ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
 				   input->ip.v4.src_ip);
@@ -1201,6 +1224,10 @@ ice_fdir_comp_rules(struct ice_fdir_fltr *a,  struct ice_fdir_fltr *b)
 	 * same flow_type.
 	 */
 	switch (flow_type) {
+	case ICE_FLTR_PTYPE_NONF_ETH:
+		if (!memcmp(&a->eth, &b->eth, sizeof(a->eth)))
+			return true;
+		break;
 	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
 	case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
 	case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
drivers/net/ethernet/intel/ice/ice_fdir.h +11 -0
index 1b9b84490689..0c90865a36c5 100644
@@ -8,6 +8,9 @@
 #define ICE_FDIR_MAX_RAW_PKT_SIZE	(512 + ICE_FDIR_TUN_PKT_OFF)
 
 /* macros for offsets into packets for flow director programming */
+#define ICE_ETH_TYPE_F_OFFSET		12
+#define ICE_ETH_VLAN_TCI_OFFSET		14
+#define ICE_ETH_TYPE_VLAN_OFFSET	16
 #define ICE_IPV4_SRC_ADDR_OFFSET	26
 #define ICE_IPV4_DST_ADDR_OFFSET	30
 #define ICE_IPV4_TCP_SRC_PORT_OFFSET	34
@@ -97,6 +100,12 @@ struct ice_rx_flow_userdef {
 	u16 flex_fltr;
 };
 
+struct ice_fdir_eth {
+	u8 dst[ETH_ALEN];
+	u8 src[ETH_ALEN];
+	__be16 type;
+};
+
 struct ice_fdir_v4 {
 	__be32 dst_ip;
 	__be32 src_ip;
@@ -159,6 +168,8 @@ struct ice_fdir_fltr {
 	struct list_head fltr_node;
 	enum ice_fltr_ptype flow_type;
 
+	struct ice_fdir_eth eth, eth_mask;
+
 	union {
 		struct ice_fdir_v4 v4;
 		struct ice_fdir_v6 v6;
drivers/net/ethernet/intel/ice/ice_type.h +1 -0
index 6df7c4487ad0..391e48d2bb92 100644
@@ -203,6 +203,7 @@ struct ice_phy_info {
 enum ice_fltr_ptype {
 	/* NONE - used for undef/error */
 	ICE_FLTR_PTYPE_NONF_NONE = 0,
+	ICE_FLTR_PTYPE_NONF_ETH,
 	ICE_FLTR_PTYPE_NONF_IPV4_UDP,
 	ICE_FLTR_PTYPE_NONF_IPV4_TCP,
 	ICE_FLTR_PTYPE_NONF_IPV4_SCTP,
Signature · 1 line
2.34.1
Reviewed-by on v4 2/2
#3 lore raw

Re: [PATCH iwl-next v4 2/2] ice: Implement 'flow-type ether' rules

Quoted 21 lines · Lukasz Plachno

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

From: Jakub Buchocki <[email protected]>

Add support for 'flow-type ether' Flow Director rules via ethtool.

Rules not containing masks are processed by the Flow Director, and support the following set of input parameters in all combinations:
src, dst, proto, vlan-etype, vlan, action.

It is possible to specify address mask in ethtool parameters but only 00:00:00:00:00 and FF:FF:FF:FF:FF are valid.
The same applies to proto, vlan-etype and vlan masks:
only 0x0000 and 0xffff masks are valid.

Quoted 6 lines
---
  .../net/ethernet/intel/ice/ice_ethtool_fdir.c | 140 +++++++++++++++++-
  drivers/net/ethernet/intel/ice/ice_fdir.c     |  27 ++++
  drivers/net/ethernet/intel/ice/ice_fdir.h     |  11 ++
  drivers/net/ethernet/intel/ice/ice_type.h     |   1 +
  4 files changed, 178 insertions(+), 1 deletion(-)

FWIW, Seems okay to me. Thanks for adding the warning prints.

[...]

#4 lore raw

Re: [Intel-wired-lan] [PATCH iwl-next v4 2/2] ice: Implement 'flow-type ether' rules

In reply to Lukasz Plachno

Dear Lukasz, dear Jakub, dear Mateusz,

Thank you for your patch.

Am 24.01.24 um 16:21 schrieb Lukasz Plachno:

Quoted 3 lines

From: Jakub Buchocki <[email protected]>

Add support for 'flow-type ether' Flow Director rules via ethtool.

Can you please elaborate on the implementation?

Quoted 8 lines

Rules not containing masks are processed by the Flow Director, and support the following set of input parameters in all combinations:
src, dst, proto, vlan-etype, vlan, action.

It is possible to specify address mask in ethtool parameters but only 00:00:00:00:00 and FF:FF:FF:FF:FF are valid.
The same applies to proto, vlan-etype and vlan masks:
only 0x0000 and 0xffff masks are valid.

It’d be great, if you gave an example, how you tested this.

Kind regards,

Paul

Quoted 312 lines
---
  .../net/ethernet/intel/ice/ice_ethtool_fdir.c | 140 +++++++++++++++++-
  drivers/net/ethernet/intel/ice/ice_fdir.c     |  27 ++++
  drivers/net/ethernet/intel/ice/ice_fdir.h     |  11 ++
  drivers/net/ethernet/intel/ice/ice_type.h     |   1 +
  4 files changed, 178 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +139 -1
index 9a1a04f5f146..d6fadc65a7a6 100644
@@ -41,6 +41,8 @@ static struct in6_addr zero_ipv6_addr_mask = {
  static int ice_fltr_to_ethtool_flow(enum ice_fltr_ptype flow)
  {
  	switch (flow) {
+	case ICE_FLTR_PTYPE_NONF_ETH:
+		return ETHER_FLOW;
  	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
  		return TCP_V4_FLOW;
  	case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
@@ -72,6 +74,8 @@ static int ice_fltr_to_ethtool_flow(enum ice_fltr_ptype flow)
  static enum ice_fltr_ptype ice_ethtool_flow_to_fltr(int eth)
  {
  	switch (eth) {
+	case ETHER_FLOW:
+		return ICE_FLTR_PTYPE_NONF_ETH;
  	case TCP_V4_FLOW:
  		return ICE_FLTR_PTYPE_NONF_IPV4_TCP;
  	case UDP_V4_FLOW:
@@ -137,6 +141,15 @@ int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd)
  	memset(&fsp->m_ext, 0, sizeof(fsp->m_ext));
 
  	switch (fsp->flow_type) {
+	case ETHER_FLOW:
+		fsp->h_u.ether_spec.h_proto = rule->eth.type;
+		fsp->m_u.ether_spec.h_proto = rule->eth_mask.type;
+		ether_addr_copy(fsp->h_u.ether_spec.h_dest, rule->eth.dst);
+		ether_addr_copy(fsp->m_u.ether_spec.h_dest, rule->eth_mask.dst);
+		ether_addr_copy(fsp->h_u.ether_spec.h_source, rule->eth.src);
+		ether_addr_copy(fsp->m_u.ether_spec.h_source,
+				rule->eth_mask.src);
+		break;
  	case IPV4_USER_FLOW:
  		fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  		fsp->h_u.usr_ip4_spec.proto = 0;
@@ -1193,6 +1206,111 @@ ice_set_fdir_ip6_usr_seg(struct ice_flow_seg_info *seg,
  	return 0;
  }
 
+/**
+ * ice_fdir_vlan_valid - validate VLAN data for Flow Director rule
+ * @fsp: pointer to ethtool Rx flow specification
+ *
+ * Return: true if vlan data is valid, false otherwise
+ */
+static bool ice_fdir_vlan_valid(struct ethtool_rx_flow_spec *fsp)
+{
+	if (fsp->m_ext.vlan_etype && !eth_type_vlan(fsp->h_ext.vlan_etype))
+		return false;
+
+	if (fsp->m_ext.vlan_tci &&
+	    ntohs(fsp->h_ext.vlan_tci) >= VLAN_N_VID)
+		return false;
+
+	return true;
+}
+
+/**
+ * ice_set_ether_flow_seg
+ * @seg: flow segment for programming
+ * @eth_spec: mask data from ethtool
+ *
+ * Return: 0 on success and errno in case of error.
+ */
+static int ice_set_ether_flow_seg(struct device *dev,
+				  struct ice_flow_seg_info *seg,
+				  struct ethhdr *eth_spec)
+{
+	ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH);
+
+	/* empty rules are not valid */
+	if (is_zero_ether_addr(eth_spec->h_source) &&
+	    is_zero_ether_addr(eth_spec->h_dest) &&
+	    !eth_spec->h_proto)
+		return -EINVAL;
+
+	/* Ethertype */
+	if (eth_spec->h_proto == htons(0xFFFF)) {
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_TYPE,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	} else if (eth_spec->h_proto) {
+		dev_warn(dev, "Only 0x0000 or 0xffff proto mask is allowed for flow-type ether");
+		return -EOPNOTSUPP;
+	}
+
+	/* Source MAC address */
+	if (is_broadcast_ether_addr(eth_spec->h_source))
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_SA,
+				 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	else if (!is_zero_ether_addr(eth_spec->h_source))
+		goto err_mask;
+
+	/* Destination MAC address */
+	if (is_broadcast_ether_addr(eth_spec->h_dest))
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_DA,
+				 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	else if (!is_zero_ether_addr(eth_spec->h_dest))
+		goto err_mask;
+
+	return 0;
+
+err_mask:
+	dev_warn(dev, "Only 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff MAC address mask is allowed for flow-type ether");
+	return -EOPNOTSUPP;
+}
+
+/**
+ * ice_set_fdir_vlan_seg
+ * @seg: flow segment for programming
+ * @ext_masks: masks for additional RX flow fields
+ */
+static int
+ice_set_fdir_vlan_seg(struct ice_flow_seg_info *seg,
+		      struct ethtool_flow_ext *ext_masks)
+{
+	ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_VLAN);
+
+	if (ext_masks->vlan_etype) {
+		if (ext_masks->vlan_etype != htons(0xFFFF))
+			return -EOPNOTSUPP;
+
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_S_VLAN,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	}
+
+	if (ext_masks->vlan_tci) {
+		if (ext_masks->vlan_tci != htons(0xFFFF))
+			return -EOPNOTSUPP;
+
+		ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_C_VLAN,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL,
+				 ICE_FLOW_FLD_OFF_INVAL, false);
+	}
+
+	return 0;
+}
+
  /**
   * ice_cfg_fdir_xtrct_seq - Configure extraction sequence for the given filter
   * @pf: PF structure
@@ -1209,7 +1327,7 @@ ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, struct ethtool_rx_flow_spec *fsp,
  	struct device *dev = ice_pf_to_dev(pf);
  	enum ice_fltr_ptype fltr_idx;
  	struct ice_hw *hw = &pf->hw;
-	bool perfect_filter;
+	bool perfect_filter = false;
  	int ret;
 
  	seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL);
@@ -1262,6 +1380,16 @@ ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, struct ethtool_rx_flow_spec *fsp,
  		ret = ice_set_fdir_ip6_usr_seg(seg, &fsp->m_u.usr_ip6_spec,
  					       &perfect_filter);
  		break;
+	case ETHER_FLOW:
+		ret = ice_set_ether_flow_seg(dev, seg, &fsp->m_u.ether_spec);
+		if (!ret && (fsp->m_ext.vlan_etype || fsp->m_ext.vlan_tci)) {
+			if (!ice_fdir_vlan_valid(fsp)) {
+				ret = -EINVAL;
+				break;
+			}
+			ret = ice_set_fdir_vlan_seg(seg, &fsp->m_ext);
+		}
+		break;
  	default:
  		ret = -EINVAL;
  	}
@@ -1823,6 +1951,16 @@ ice_set_fdir_input_set(struct ice_vsi *vsi, struct ethtool_rx_flow_spec *fsp,
  		input->mask.v6.tc = fsp->m_u.usr_ip6_spec.tclass;
  		input->mask.v6.proto = fsp->m_u.usr_ip6_spec.l4_proto;
  		break;
+	case ETHER_FLOW:
+		ether_addr_copy(input->eth.dst, fsp->h_u.ether_spec.h_dest);
+		ether_addr_copy(input->eth.src, fsp->h_u.ether_spec.h_source);
+		ether_addr_copy(input->eth_mask.dst,
+				fsp->m_u.ether_spec.h_dest);
+		ether_addr_copy(input->eth_mask.src,
+				fsp->m_u.ether_spec.h_source);
+		input->eth.type = fsp->h_u.ether_spec.h_proto;
+		input->eth_mask.type = fsp->m_u.ether_spec.h_proto;
+		break;
  	default:
  		/* not doing un-parsed flow types */
  		return -EINVAL;
drivers/net/ethernet/intel/ice/ice_fdir.c +27 -0
index 1f7b26f38818..5fe0bad00fd7 100644
@@ -4,6 +4,8 @@
  #include "ice_common.h"
 
  /* These are training packet headers used to program flow director filters. */
+static const u8 ice_fdir_eth_pkt[22] = {0};
+
  static const u8 ice_fdir_tcpv4_pkt[] = {
  	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
@@ -416,6 +418,11 @@ static const u8 ice_fdir_ip6_tun_pkt[] = {
 
  /* Flow Director no-op training packet table */
  static const struct ice_fdir_base_pkt ice_fdir_pkt[] = {
+	{
+		ICE_FLTR_PTYPE_NONF_ETH,
+		sizeof(ice_fdir_eth_pkt), ice_fdir_eth_pkt,
+		sizeof(ice_fdir_eth_pkt), ice_fdir_eth_pkt,
+	},
  	{
  		ICE_FLTR_PTYPE_NONF_IPV4_TCP,
  		sizeof(ice_fdir_tcpv4_pkt), ice_fdir_tcpv4_pkt,
@@ -914,6 +921,22 @@ ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
  	 * perspective. The input from user is from Rx filter perspective.
  	 */
  	switch (flow) {
+	case ICE_FLTR_PTYPE_NONF_ETH:
+		ice_pkt_insert_mac_addr(loc, input->eth.dst);
+		ice_pkt_insert_mac_addr(loc + ETH_ALEN, input->eth.src);
+		if (input->ext_data.vlan_tag ||
+		    input->ext_data.vlan_type) {
+			ice_pkt_insert_u16(loc, ICE_ETH_TYPE_F_OFFSET,
+					   input->ext_data.vlan_type);
+			ice_pkt_insert_u16(loc, ICE_ETH_VLAN_TCI_OFFSET,
+					   input->ext_data.vlan_tag);
+			ice_pkt_insert_u16(loc, ICE_ETH_TYPE_VLAN_OFFSET,
+					   input->eth.type);
+		} else {
+			ice_pkt_insert_u16(loc, ICE_ETH_TYPE_F_OFFSET,
+					   input->eth.type);
+		}
+		break;
  	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
  		ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
  				   input->ip.v4.src_ip);
@@ -1201,6 +1224,10 @@ ice_fdir_comp_rules(struct ice_fdir_fltr *a,  struct ice_fdir_fltr *b)
  	 * same flow_type.
  	 */
  	switch (flow_type) {
+	case ICE_FLTR_PTYPE_NONF_ETH:
+		if (!memcmp(&a->eth, &b->eth, sizeof(a->eth)))
+			return true;
+		break;
  	case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
  	case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
  	case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
drivers/net/ethernet/intel/ice/ice_fdir.h +11 -0
index 1b9b84490689..0c90865a36c5 100644
@@ -8,6 +8,9 @@
  #define ICE_FDIR_MAX_RAW_PKT_SIZE	(512 + ICE_FDIR_TUN_PKT_OFF)
 
  /* macros for offsets into packets for flow director programming */
+#define ICE_ETH_TYPE_F_OFFSET		12
+#define ICE_ETH_VLAN_TCI_OFFSET		14
+#define ICE_ETH_TYPE_VLAN_OFFSET	16
  #define ICE_IPV4_SRC_ADDR_OFFSET	26
  #define ICE_IPV4_DST_ADDR_OFFSET	30
  #define ICE_IPV4_TCP_SRC_PORT_OFFSET	34
@@ -97,6 +100,12 @@ struct ice_rx_flow_userdef {
  	u16 flex_fltr;
  };
 
+struct ice_fdir_eth {
+	u8 dst[ETH_ALEN];
+	u8 src[ETH_ALEN];
+	__be16 type;
+};
+
  struct ice_fdir_v4 {
  	__be32 dst_ip;
  	__be32 src_ip;
@@ -159,6 +168,8 @@ struct ice_fdir_fltr {
  	struct list_head fltr_node;
  	enum ice_fltr_ptype flow_type;
 
+	struct ice_fdir_eth eth, eth_mask;
+
  	union {
  		struct ice_fdir_v4 v4;
  		struct ice_fdir_v6 v6;
drivers/net/ethernet/intel/ice/ice_type.h +1 -0
index 6df7c4487ad0..391e48d2bb92 100644
@@ -203,6 +203,7 @@ struct ice_phy_info {
  enum ice_fltr_ptype {
  	/* NONE - used for undef/error */
  	ICE_FLTR_PTYPE_NONF_NONE = 0,
+	ICE_FLTR_PTYPE_NONF_ETH,
  	ICE_FLTR_PTYPE_NONF_IPV4_UDP,
  	ICE_FLTR_PTYPE_NONF_IPV4_TCP,
  	ICE_FLTR_PTYPE_NONF_IPV4_SCTP,
#5 lore raw

Re: [Intel-wired-lan] [PATCH iwl-next v4 2/2] ice: Implement 'flow-type ether' rules

Quoted 12 lines · Paul Menzel

Dear Lukasz, dear Jakub, dear Mateusz,

Thank you for your patch.

Am 24.01.24 um 16:21 schrieb Lukasz Plachno:

Quoted 3 lines

From: Jakub Buchocki <[email protected]>

Add support for 'flow-type ether' Flow Director rules via ethtool.

Can you please elaborate on the implementation?

New commit message below

Quoted 11 lines
Quoted 8 lines

Rules not containing masks are processed by the Flow Director, and support the following set of input parameters in all combinations:
src, dst, proto, vlan-etype, vlan, action.

It is possible to specify address mask in ethtool parameters but only 00:00:00:00:00 and FF:FF:FF:FF:FF are valid.
The same applies to proto, vlan-etype and vlan masks:
only 0x0000 and 0xffff masks are valid.

It’d be great, if you gave an example, how you tested this.

Example at the bottom, let me know if such commit message is OK for you.

ice: Implement 'flow-type ether' rules

Add support for 'flow-type ether' Flow Director rules via ethtool.

Create packet segment info for filter configuration based on ethtool command parameters.
Reuse infrastructure already created for ipv4 and ipv6 flows to convert
packet segment into extraction sequence, which is later used to program the filter inside Flow Director block of the Rx pipeline.

Rules not containing masks are processed by the Flow Director, and support the following set of input parameters in all
combinations: src, dst, proto, vlan-etype, vlan, action.

It is possible to specify address mask in ethtool parameters but only 00:00:00:00:00 and FF:FF:FF:FF:FF are valid.
The same applies to proto, vlan-etype and vlan masks:
only 0x0000 and 0xffff masks are valid.

Testing:
# (DUT) iperf3 -s
# (DUT) ethtool -U ens785f0np0 flow-type ether dst 00:00:00:00:01:00 action 10 # (DUT) watch 'ethtool -S ens785f0np0 | grep rx_queue'
# (LP) iperf3 -c ${DUT_IP}

Counters increase only for:
'rx_queue_10_packets'
'rx_queue_10_bytes'

Thanks,
Łukasz

Quoted 316 lines
Quoted 316 lines

---
  .../net/ethernet/intel/ice/ice_ethtool_fdir.c | 140 +++++++++++++++++-

  drivers/net/ethernet/intel/ice/ice_fdir.c     |  27 ++++
  drivers/net/ethernet/intel/ice/ice_fdir.h     |  11 ++
  drivers/net/ethernet/intel/ice/ice_type.h     |   1 +
  4 files changed, 178 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +2 -0
index 9a1a04f5f146..d6fadc65a7a6 100644
@@ -41,6 +41,8 @@ static struct in6_addr zero_ipv6_addr_mask = {
   static int ice_fltr_to_ethtool_flow(enum ice_fltr_ptype flow)
   {
       switch (flow) {
+    case ICE_FLTR_PTYPE_NONF_ETH:
+        return ETHER_FLOW;

      case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
          return TCP_V4_FLOW;
      case ICE_FLTR_PTYPE_NONF_IPV4_UDP:

drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +2 -0
@@ -72,6 +74,8 @@ static int ice_fltr_to_ethtool_flow(enum 
 ice_fltr_ptype flow)
   static enum ice_fltr_ptype ice_ethtool_flow_to_fltr(int eth)
   {
       switch (eth) {
+    case ETHER_FLOW:
+        return ICE_FLTR_PTYPE_NONF_ETH;

      case TCP_V4_FLOW:
          return ICE_FLTR_PTYPE_NONF_IPV4_TCP;
      case UDP_V4_FLOW:

drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +9 -0
@@ -137,6 +141,15 @@ int ice_get_ethtool_fdir_entry(struct ice_hw *hw, 
 struct ethtool_rxnfc *cmd)
       memset(&fsp->m_ext, 0, sizeof(fsp->m_ext));
       switch (fsp->flow_type) {
+    case ETHER_FLOW:
+        fsp->h_u.ether_spec.h_proto = rule->eth.type;
+        fsp->m_u.ether_spec.h_proto = rule->eth_mask.type;
+        ether_addr_copy(fsp->h_u.ether_spec.h_dest, rule->eth.dst);
+        ether_addr_copy(fsp->m_u.ether_spec.h_dest, rule->eth_mask.dst);
+        ether_addr_copy(fsp->h_u.ether_spec.h_source, rule->eth.src);
+        ether_addr_copy(fsp->m_u.ether_spec.h_source,
+                rule->eth_mask.src);
+        break;

      case IPV4_USER_FLOW:
          fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; fsp->h_u.usr_ip4_spec.proto = 0;

drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +105 -0
@@ -1193,6 +1206,111 @@ ice_set_fdir_ip6_usr_seg(struct 
 ice_flow_seg_info *seg,
       return 0;
   }
+/**
+ * ice_fdir_vlan_valid - validate VLAN data for Flow Director rule
+ * @fsp: pointer to ethtool Rx flow specification
+ *
+ * Return: true if vlan data is valid, false otherwise
+ */
+static bool ice_fdir_vlan_valid(struct ethtool_rx_flow_spec *fsp)
+{
+    if (fsp->m_ext.vlan_etype && !eth_type_vlan(fsp->h_ext.vlan_etype))
+        return false;
+
+    if (fsp->m_ext.vlan_tci &&
+        ntohs(fsp->h_ext.vlan_tci) >= VLAN_N_VID)
+        return false;
+
+    return true;
+}
+
+/**
+ * ice_set_ether_flow_seg
+ * @seg: flow segment for programming
+ * @eth_spec: mask data from ethtool
+ *
+ * Return: 0 on success and errno in case of error.
+ */
+static int ice_set_ether_flow_seg(struct device *dev,
+                  struct ice_flow_seg_info *seg,
+                  struct ethhdr *eth_spec)
+{
+    ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH);
+
+    /* empty rules are not valid */
+    if (is_zero_ether_addr(eth_spec->h_source) &&
+        is_zero_ether_addr(eth_spec->h_dest) &&
+        !eth_spec->h_proto)
+        return -EINVAL;
+
+    /* Ethertype */
+    if (eth_spec->h_proto == htons(0xFFFF)) {
+        ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_TYPE,
+                 ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL, false);
+    } else if (eth_spec->h_proto) {
+        dev_warn(dev, "Only 0x0000 or 0xffff proto mask is allowed 
 for flow-type ether");
+        return -EOPNOTSUPP;
+    }
+
+    /* Source MAC address */
+    if (is_broadcast_ether_addr(eth_spec->h_source))
+        ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_SA,
+                 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL, false);
+    else if (!is_zero_ether_addr(eth_spec->h_source))
+        goto err_mask;
+
+    /* Destination MAC address */
+    if (is_broadcast_ether_addr(eth_spec->h_dest))
+        ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_DA,
+                 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL, false);
+    else if (!is_zero_ether_addr(eth_spec->h_dest))
+        goto err_mask;
+
+    return 0;
+
+err_mask:
+    dev_warn(dev, "Only 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff MAC 
 address mask is allowed for flow-type ether");
+    return -EOPNOTSUPP;
+}
+
+/**
+ * ice_set_fdir_vlan_seg
+ * @seg: flow segment for programming
+ * @ext_masks: masks for additional RX flow fields
+ */
+static int
+ice_set_fdir_vlan_seg(struct ice_flow_seg_info *seg,
+              struct ethtool_flow_ext *ext_masks)
+{
+    ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_VLAN);
+
+    if (ext_masks->vlan_etype) {
+        if (ext_masks->vlan_etype != htons(0xFFFF))
+            return -EOPNOTSUPP;
+
+        ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_S_VLAN,
+                 ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL, false);
+    }
+
+    if (ext_masks->vlan_tci) {
+        if (ext_masks->vlan_tci != htons(0xFFFF))
+            return -EOPNOTSUPP;
+
+        ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_C_VLAN,
+                 ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL,
+                 ICE_FLOW_FLD_OFF_INVAL, false);
+    }
+
+    return 0;
+}
+
   /**

   * ice_cfg_fdir_xtrct_seq - Configure extraction sequence for the given filter
   * @pf: PF structure

drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +11 -1
@@ -1209,7 +1327,7 @@ ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, struct 
 ethtool_rx_flow_spec *fsp,
       struct device *dev = ice_pf_to_dev(pf);
       enum ice_fltr_ptype fltr_idx;
       struct ice_hw *hw = &pf->hw;
-    bool perfect_filter;
+    bool perfect_filter = false;
       int ret;
       seg = devm_kzalloc(dev, sizeof(*seg), GFP_KERNEL);
@@ -1262,6 +1380,16 @@ ice_cfg_fdir_xtrct_seq(struct ice_pf *pf, 
 struct ethtool_rx_flow_spec *fsp,
           ret = ice_set_fdir_ip6_usr_seg(seg, &fsp->m_u.usr_ip6_spec,
                              &perfect_filter);
           break;
+    case ETHER_FLOW:
+        ret = ice_set_ether_flow_seg(dev, seg, &fsp->m_u.ether_spec);
+        if (!ret && (fsp->m_ext.vlan_etype || fsp->m_ext.vlan_tci)) {
+            if (!ice_fdir_vlan_valid(fsp)) {
+                ret = -EINVAL;
+                break;
+            }
+            ret = ice_set_fdir_vlan_seg(seg, &fsp->m_ext);
+        }
+        break;

      default:
          ret = -EINVAL;
      }

drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +10 -0
@@ -1823,6 +1951,16 @@ ice_set_fdir_input_set(struct ice_vsi *vsi, 
 struct ethtool_rx_flow_spec *fsp,
           input->mask.v6.tc = fsp->m_u.usr_ip6_spec.tclass;
           input->mask.v6.proto = fsp->m_u.usr_ip6_spec.l4_proto;
           break;
+    case ETHER_FLOW:
+        ether_addr_copy(input->eth.dst, fsp->h_u.ether_spec.h_dest);
+        ether_addr_copy(input->eth.src, fsp->h_u.ether_spec.h_source);
+        ether_addr_copy(input->eth_mask.dst,
+                fsp->m_u.ether_spec.h_dest);
+        ether_addr_copy(input->eth_mask.src,
+                fsp->m_u.ether_spec.h_source);
+        input->eth.type = fsp->h_u.ether_spec.h_proto;
+        input->eth_mask.type = fsp->m_u.ether_spec.h_proto;
+        break;

      default:
          /* not doing un-parsed flow types */
          return -EINVAL;

drivers/net/ethernet/intel/ice/ice_fdir.c +23 -0
index 1f7b26f38818..5fe0bad00fd7 100644
@@ -4,6 +4,8 @@
   #include "ice_common.h"
   /* These are training packet headers used to program flow director filters. */
+static const u8 ice_fdir_eth_pkt[22] = {0};
+
   static const u8 ice_fdir_tcpv4_pkt[] = {
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
@@ -416,6 +418,11 @@ static const u8 ice_fdir_ip6_tun_pkt[] = {
   /* Flow Director no-op training packet table */
   static const struct ice_fdir_base_pkt ice_fdir_pkt[] = {
+    {
+        ICE_FLTR_PTYPE_NONF_ETH,
+        sizeof(ice_fdir_eth_pkt), ice_fdir_eth_pkt,
+        sizeof(ice_fdir_eth_pkt), ice_fdir_eth_pkt,
+    },
       {
           ICE_FLTR_PTYPE_NONF_IPV4_TCP,
           sizeof(ice_fdir_tcpv4_pkt), ice_fdir_tcpv4_pkt,
@@ -914,6 +921,22 @@ ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, 
 struct ice_fdir_fltr *input,
        * perspective. The input from user is from Rx filter perspective.
        */
       switch (flow) {
+    case ICE_FLTR_PTYPE_NONF_ETH:
+        ice_pkt_insert_mac_addr(loc, input->eth.dst);
+        ice_pkt_insert_mac_addr(loc + ETH_ALEN, input->eth.src);
+        if (input->ext_data.vlan_tag ||
+            input->ext_data.vlan_type) {
+            ice_pkt_insert_u16(loc, ICE_ETH_TYPE_F_OFFSET,
+                       input->ext_data.vlan_type);
+            ice_pkt_insert_u16(loc, ICE_ETH_VLAN_TCI_OFFSET,
+                       input->ext_data.vlan_tag);
+            ice_pkt_insert_u16(loc, ICE_ETH_TYPE_VLAN_OFFSET,
+                       input->eth.type);
+        } else {
+            ice_pkt_insert_u16(loc, ICE_ETH_TYPE_F_OFFSET,
+                       input->eth.type);
+        }
+        break;

      case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
          ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET, input->ip.v4.src_ip);

drivers/net/ethernet/intel/ice/ice_fdir.c +4 -0
@@ -1201,6 +1224,10 @@ ice_fdir_comp_rules(struct ice_fdir_fltr *a,  
 struct ice_fdir_fltr *b)
        * same flow_type.
        */
       switch (flow_type) {
+    case ICE_FLTR_PTYPE_NONF_ETH:
+        if (!memcmp(&a->eth, &b->eth, sizeof(a->eth)))
+            return true;
+        break;

      case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
      case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
      case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:

drivers/net/ethernet/intel/ice/ice_fdir.h +11 -0
index 1b9b84490689..0c90865a36c5 100644
@@ -8,6 +8,9 @@
   #define ICE_FDIR_MAX_RAW_PKT_SIZE    (512 + ICE_FDIR_TUN_PKT_OFF)
   /* macros for offsets into packets for flow director programming */
+#define ICE_ETH_TYPE_F_OFFSET        12
+#define ICE_ETH_VLAN_TCI_OFFSET        14
+#define ICE_ETH_TYPE_VLAN_OFFSET    16
   #define ICE_IPV4_SRC_ADDR_OFFSET    26
   #define ICE_IPV4_DST_ADDR_OFFSET    30
   #define ICE_IPV4_TCP_SRC_PORT_OFFSET    34
@@ -97,6 +100,12 @@ struct ice_rx_flow_userdef {
       u16 flex_fltr;
   };
+struct ice_fdir_eth {
+    u8 dst[ETH_ALEN];
+    u8 src[ETH_ALEN];
+    __be16 type;
+};
+
   struct ice_fdir_v4 {
       __be32 dst_ip;
       __be32 src_ip;
@@ -159,6 +168,8 @@ struct ice_fdir_fltr {
       struct list_head fltr_node;
       enum ice_fltr_ptype flow_type;
+    struct ice_fdir_eth eth, eth_mask;
+
       union {
           struct ice_fdir_v4 v4;
           struct ice_fdir_v6 v6;
drivers/net/ethernet/intel/ice/ice_type.h +1 -0
index 6df7c4487ad0..391e48d2bb92 100644
@@ -203,6 +203,7 @@ struct ice_phy_info {
   enum ice_fltr_ptype {
       /* NONE - used for undef/error */
       ICE_FLTR_PTYPE_NONF_NONE = 0,
+    ICE_FLTR_PTYPE_NONF_ETH,
       ICE_FLTR_PTYPE_NONF_IPV4_UDP,
       ICE_FLTR_PTYPE_NONF_IPV4_TCP,
       ICE_FLTR_PTYPE_NONF_IPV4_SCTP,
#6 lore raw

Re: [PATCH iwl-next v4 2/2] ice: Implement 'flow-type ether' rules

In reply to Lukasz Plachno
kernel test robot noticed the following build warnings:

Hi Lukasz,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tnguy-next-queue/dev-queue]

url:    https://github.com/intel-lab-lkp/linux/commits/Lukasz-Plachno/ice-Remove-unnecessary-argument-from-ice_fdir_comp_rules/20240125-054019
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue.git dev-queue
patch link:    https://lore.kernel.org/r/20240124152141.15077-3-lukasz.plachno%40intel.com
patch subject: [PATCH iwl-next v4 2/2] ice: Implement 'flow-type ether' rules
config: i386-randconfig-001-20240125 (https://download.01.org/0day-ci/archive/20240125/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240125/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c:1237: warning: Function parameter or struct member 'dev' not described in 'ice_set_ether_flow_seg'

vim +1237 drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c

1226
1227 /**
1228 * ice_set_ether_flow_seg
1229 * @seg: flow segment for programming
1230 * @eth_spec: mask data from ethtool
1231 *
1232 * Return: 0 on success and errno in case of error.
1233 */
1234 static int ice_set_ether_flow_seg(struct device *dev,
1235 struct ice_flow_seg_info *seg,
1236 struct ethhdr *eth_spec)

> 1237	{

1238 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH);
1239
1240 /* empty rules are not valid */
1241 if (is_zero_ether_addr(eth_spec->h_source) &&
1242 is_zero_ether_addr(eth_spec->h_dest) &&
1243 !eth_spec->h_proto)
1244 return -EINVAL;
1245
1246 /* Ethertype */
1247 if (eth_spec->h_proto == htons(0xFFFF)) {
1248 ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_TYPE,
1249 ICE_FLOW_FLD_OFF_INVAL,
1250 ICE_FLOW_FLD_OFF_INVAL,
1251 ICE_FLOW_FLD_OFF_INVAL, false);
1252 } else if (eth_spec->h_proto) {
1253 dev_warn(dev, "Only 0x0000 or 0xffff proto mask is allowed for flow-type ether");
1254 return -EOPNOTSUPP;
1255 }
1256
1257 /* Source MAC address */
1258 if (is_broadcast_ether_addr(eth_spec->h_source))
1259 ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_SA,
1260 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
1261 ICE_FLOW_FLD_OFF_INVAL, false);
1262 else if (!is_zero_ether_addr(eth_spec->h_source))
1263 goto err_mask;
1264
1265 /* Destination MAC address */
1266 if (is_broadcast_ether_addr(eth_spec->h_dest))
1267 ice_flow_set_fld(seg, ICE_FLOW_FIELD_IDX_ETH_DA,
1268 ICE_FLOW_FLD_OFF_INVAL, ICE_FLOW_FLD_OFF_INVAL,
1269 ICE_FLOW_FLD_OFF_INVAL, false);
1270 else if (!is_zero_ether_addr(eth_spec->h_dest))
1271 goto err_mask;
1272
1273 return 0;
1274
1275 err_mask:
1276 dev_warn(dev, "Only 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff MAC address mask is allowed for flow-type ether");
1277 return -EOPNOTSUPP;
1278 }
1279

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
reviewer
#7 lore raw

Re: [PATCH iwl-next v4 2/2] ice: Implement 'flow-type ether' rules

In reply to Lukasz Plachno
Quoted 18 lines · Lukasz Plachno

From: Jakub Buchocki <[email protected]>

Add support for 'flow-type ether' Flow Director rules via ethtool.

Rules not containing masks are processed by the Flow Director, and support the following set of input parameters in all combinations:
src, dst, proto, vlan-etype, vlan, action.

It is possible to specify address mask in ethtool parameters but only 00:00:00:00:00 and FF:FF:FF:FF:FF are valid.
The same applies to proto, vlan-etype and vlan masks:
only 0x0000 and 0xffff masks are valid.

...

Quoted 2 lines

+/**
+ * ice_set_ether_flow_seg

nit: @dev should be documented here.

Quoted 8 lines

+ * @seg: flow segment for programming
+ * @eth_spec: mask data from ethtool
+ *
+ * Return: 0 on success and errno in case of error.
+ */

drivers/net/ethernet/intel/ice/ice_ethtool_fdir.c +3 -0
+static int ice_set_ether_flow_seg(struct device *dev,
+				  struct ice_flow_seg_info *seg,
+				  struct ethhdr *eth_spec)

...