Skip to contentSkip to conversation

ethtool mm API consolidation

PATCH Applied Vladimir Oltean 3 participants 22 messages Apr 18, 2023 – Apr 21, 2023

Subsystems (8)
lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

v2 cover ethtool mm API consolidation

This series consolidates the behavior of the 2 drivers that implement the ethtool MAC Merge layer by making NXP ENETC commit its preemptible traffic classes to hardware only when MM TX is active (same as Ocelot).

Then, after resolving an issue with the ENETC driver, it restricts user space from entering 2 states which don't make sense:

- pmac-enabled off tx-enabled on verify-enabled *
- pmac-enabled * tx-enabled off verify-enabled on

Then, it introduces a selftest (ethtool_mm.sh) which puts everything together and tests all valid configurations known to me.

This is simultaneously the v2 of "[PATCH net-next 0/2] ethtool mm API improvements":
https://lore.kernel.org/netdev/[email protected]/
which had caused some problems to openlldp. Those were solved in the meantime, see:
https://github.com/intel/openlldp/commit/11171b474f6f3cbccac5d608b7f26b32ff72c651

and of "[RFC PATCH net-next] selftests: forwarding: add a test for MAC Merge layer":
https://lore.kernel.org/netdev/[email protected]/

Petr Machata (2):
selftests: forwarding: sch_tbf_*: Add a pre-run hook
selftests: forwarding: generalize bail_on_lldpad from mlxsw

Vladimir Oltean (7):
net: enetc: fix MAC Merge layer remaining enabled until a link down
event
net: enetc: report mm tx-active based on tx-enabled and verify-status
net: enetc: only commit preemptible TCs to hardware when MM TX is
active
net: enetc: include MAC Merge / FP registers in register dump
net: ethtool: mm: sanitize some UAPI configurations
selftests: forwarding: introduce helper for standard ethtool counters
selftests: forwarding: add a test for MAC Merge layer

 drivers/net/ethernet/freescale/enetc/enetc.c  |  23 +-
 drivers/net/ethernet/freescale/enetc/enetc.h  |   5 +-
 .../ethernet/freescale/enetc/enetc_ethtool.c  |  94 +++++-
 .../net/ethernet/freescale/enetc/enetc_hw.h   |   3 +
 net/ethtool/mm.c                              |  10 +
 .../drivers/net/mlxsw/qos_headroom.sh         |   3 +-
 .../selftests/drivers/net/mlxsw/qos_lib.sh    |  28 --
 .../selftests/drivers/net/mlxsw/qos_pfc.sh    |   3 +-
 .../selftests/drivers/net/mlxsw/sch_ets.sh    |   3 +-
 .../drivers/net/mlxsw/sch_red_core.sh         |   1 -
 .../drivers/net/mlxsw/sch_red_ets.sh          |   2 +-
 .../drivers/net/mlxsw/sch_red_root.sh         |   2 +-
 .../drivers/net/mlxsw/sch_tbf_ets.sh          |   6 +-
 .../drivers/net/mlxsw/sch_tbf_prio.sh         |   6 +-
 .../drivers/net/mlxsw/sch_tbf_root.sh         |   6 +-
 .../testing/selftests/net/forwarding/Makefile |   1 +
 .../selftests/net/forwarding/ethtool_mm.sh    | 288 ++++++++++++++++++
 tools/testing/selftests/net/forwarding/lib.sh |  60 ++++
 .../net/forwarding/sch_tbf_etsprio.sh         |   4 +
 .../selftests/net/forwarding/sch_tbf_root.sh  |   4 +
 20 files changed, 486 insertions(+), 66 deletions(-)
 create mode 100755 tools/testing/selftests/net/forwarding/ethtool_mm.sh
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 1/9 net: enetc: fix MAC Merge layer remaining enabled until a link down event

Current enetc_set_mm() is designed to set the priv->active_offloads bit ENETC_F_QBU for enetc_mm_link_state_update() to act on, but if the link is already up, it modifies the ENETC_MMCSR_ME ("Merge Enable") bit directly.

The problem is that it only *sets* ENETC_MMCSR_ME if the link is up, it doesn't *clear* it if needed. So subsequent enetc_get_mm() calls still see tx-enabled as true, up until a link down event, which is when enetc_mm_link_state_update() will get called.

This is not a functional issue as far as I can assess. It has only come up because I'd like to uphold a simple API rule in core ethtool code:
the pMAC cannot be disabled if TX is going to be enabled. Currently, the fact that TX remains enabled for longer than expected (after the enetc_set_mm() call that disables it) is going to violate that rule, which is how it was caught.

---
v1->v2: none

 drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +7 -4
index 838750a03cf6..ee1ea71fe79e 100644
@@ -1041,10 +1041,13 @@ static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg,
 	else
 		priv->active_offloads &= ~ENETC_F_QBU;
 
-	/* If link is up, enable MAC Merge right away */
-	if (!!(priv->active_offloads & ENETC_F_QBU) &&
-	    !(val & ENETC_MMCSR_LINK_FAIL))
-		val |= ENETC_MMCSR_ME;
+	/* If link is up, enable/disable MAC Merge right away */
+	if (!(val & ENETC_MMCSR_LINK_FAIL)) {
+		if (!!(priv->active_offloads & ENETC_F_QBU))
+			val |= ENETC_MMCSR_ME;
+		else
+			val &= ~ENETC_MMCSR_ME;
+	}
 
 	val &= ~ENETC_MMCSR_VT_MASK;
 	val |= ENETC_MMCSR_VT(cfg->verify_time);
Signature · 1 line
2.34.1
Reviewed-by on v2 1/9
#2 lore raw

Re: [PATCH v2 net-next 1/9] net: enetc: fix MAC Merge layer remaining enabled until a link down event

Quoted 10 lines · Vladimir Oltean

Current enetc_set_mm() is designed to set the priv->active_offloads bit ENETC_F_QBU for enetc_mm_link_state_update() to act on, but if the link is already up, it modifies the ENETC_MMCSR_ME ("Merge Enable") bit directly.

The problem is that it only *sets* ENETC_MMCSR_ME if the link is up, it doesn't *clear* it if needed. So subsequent enetc_get_mm() calls still see tx-enabled as true, up until a link down event, which is when enetc_mm_link_state_update() will get called.

Quoted 8 lines

This is not a functional issue as far as I can assess. It has only come up because I'd like to uphold a simple API rule in core ethtool code:
the pMAC cannot be disabled if TX is going to be enabled. Currently, the fact that TX remains enabled for longer than expected (after the enetc_set_mm() call that disables it) is going to violate that rule, which is how it was caught.

Quoted 11 lines

---
v1->v2: none

 drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +0 -0
index 838750a03cf6..ee1ea71fe79e 100644

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg, · line 1046

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -4
@@ -1041,10 +1041,13 @@ static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg,
 	else
 		priv->active_offloads &= ~ENETC_F_QBU;
 
-	/* If link is up, enable MAC Merge right away */
-	if (!!(priv->active_offloads & ENETC_F_QBU) &&
-	    !(val & ENETC_MMCSR_LINK_FAIL))
-		val |= ENETC_MMCSR_ME;
+	/* If link is up, enable/disable MAC Merge right away */
+	if (!(val & ENETC_MMCSR_LINK_FAIL)) {
+		if (!!(priv->active_offloads & ENETC_F_QBU))

nit: The !!() seems unnecessary,
I wonder if it can be written in a simpler way as:

if (priv->active_offloads & ENETC_F_QBU)

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +4 -0
+			val |= ENETC_MMCSR_ME;
+		else
+			val &= ~ENETC_MMCSR_ME;
+	}
 
 	val &= ~ENETC_MMCSR_VT_MASK;
 	val |= ENETC_MMCSR_VT(cfg->verify_time);
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

Re: [PATCH v2 net-next 1/9] net: enetc: fix MAC Merge layer remaining enabled until a link down event

Quoted 11 lines · Simon Horman

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg, · line 1046

Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -4
-	/* If link is up, enable MAC Merge right away */
-	if (!!(priv->active_offloads & ENETC_F_QBU) &&
-	    !(val & ENETC_MMCSR_LINK_FAIL))
-		val |= ENETC_MMCSR_ME;
+	/* If link is up, enable/disable MAC Merge right away */
+	if (!(val & ENETC_MMCSR_LINK_FAIL)) {
+		if (!!(priv->active_offloads & ENETC_F_QBU))

nit: The !!() seems unnecessary,
I wonder if it can be written in a simpler way as:

Quoted 1 line

if (priv->active_offloads & ENETC_F_QBU)

I agree. Normally I omit the double negation in simple statements like this. Here I didn't, because the expression was split into 2 "if" conditions, and I kept the individual terms as-is for some reason.

Since the generated object code is absolutely the same either way, I would not resend just for minor style comments such as this one, if you don't mind. However, I do appreciate the review and I'll pay more attention to this detail in the future.

#4 lore raw

Re: [PATCH v2 net-next 1/9] net: enetc: fix MAC Merge layer remaining enabled until a link down event

Quoted 14 lines · Vladimir Oltean
Quoted 11 lines · Simon Horman

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg, · line 1046

Quoted 7 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -4
-	/* If link is up, enable MAC Merge right away */
-	if (!!(priv->active_offloads & ENETC_F_QBU) &&
-	    !(val & ENETC_MMCSR_LINK_FAIL))
-		val |= ENETC_MMCSR_ME;
+	/* If link is up, enable/disable MAC Merge right away */
+	if (!(val & ENETC_MMCSR_LINK_FAIL)) {
+		if (!!(priv->active_offloads & ENETC_F_QBU))

nit: The !!() seems unnecessary,
I wonder if it can be written in a simpler way as:

Quoted 1 line

if (priv->active_offloads & ENETC_F_QBU)

Quoted 8 lines

I agree. Normally I omit the double negation in simple statements like this. Here I didn't, because the expression was split into 2 "if" conditions, and I kept the individual terms as-is for some reason.

Since the generated object code is absolutely the same either way, I would not resend just for minor style comments such as this one, if you don't mind. However, I do appreciate the review and I'll pay more attention to this detail in the future.

Thanks. I agree the result should be same.
No need to resend because of this.

author maintainer
#5 lore raw

PATCH v2 2/9 net: enetc: report mm tx-active based on tx-enabled and verify-status

In reply to Vladimir Oltean

The MMCSR register contains 2 fields with overlapping meaning:

- LPA (Local preemption active):
This read-only status bit indicates whether preemption is active for this port. This bit will be set if preemption is both enabled and has completed the verification process.
- TXSTS (Merge status):
This read-only status field provides the state of the MAC Merge sublayer transmit status as defined in IEEE Std 802.3-2018 Clause 99. 00 Transmit preemption is inactive
01 Transmit preemption is active
10 Reserved
11 Reserved

However none of these 2 fields offer reliable reporting to software.

When connecting ENETC to a link partner which is not capable of Frame Preemption, the expectation is that ENETC's verification should fail (VSTS=4) and its MM TX direction should be inactive (LPA=0, TXSTS=00) even though the MM TX is enabled (ME=1). But surprise, the LPA bit of MMCSR stays set even if VSTS=4 and ME=1.

OTOH, the TXSTS field has the opposite problem. I cannot get its value to change from 0, even when connecting to a link partner capable of frame preemption, which does respond to its verification frames (ME=1 and VSTS=3, "SUCCEEDED").

The only option with such buggy hardware seems to be to reimplement the formula for calculating tx-active in software, which is for tx-enabled to be true, and for the verify-status to be either SUCCEEDED, or DISABLED.

Without reliable tx-active reporting, we have no good indication when to commit the preemptible traffic classes to hardware, which makes it possible (but not desirable) to send preemptible traffic to a link partner incapable of receiving it. However, currently we do not have the logic to wait for TX to be active yet, so the impact is limited.

---
v1->v2: patch is new

 drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -1
index ee1ea71fe79e..deb674752851 100644
@@ -976,7 +976,9 @@ static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state)
 	lafs = ENETC_MMCSR_GET_LAFS(val);
 	state->rx_min_frag_size = ethtool_mm_frag_size_add_to_min(lafs);
 	state->tx_enabled = !!(val & ENETC_MMCSR_LPE); /* mirror of MMCSR_ME */
-	state->tx_active = !!(val & ENETC_MMCSR_LPA);
+	state->tx_active = state->tx_enabled &&
+			   (state->verify_status == ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED ||
+			    state->verify_status == ETHTOOL_MM_VERIFY_STATUS_DISABLED);
 	state->verify_enabled = !(val & ENETC_MMCSR_VDIS);
 	state->verify_time = ENETC_MMCSR_GET_VT(val);
 	/* A verifyTime of 128 ms would exceed the 7 bit width
Signature · 1 line
2.34.1
Reviewed-by on v2 2/9
#6 lore raw

Re: [PATCH v2 net-next 2/9] net: enetc: report mm tx-active based on tx-enabled and verify-status

Quoted 32 lines · Vladimir Oltean

The MMCSR register contains 2 fields with overlapping meaning:

- LPA (Local preemption active):
This read-only status bit indicates whether preemption is active for this port. This bit will be set if preemption is both enabled and has completed the verification process.
- TXSTS (Merge status):
This read-only status field provides the state of the MAC Merge sublayer transmit status as defined in IEEE Std 802.3-2018 Clause 99. 00 Transmit preemption is inactive
01 Transmit preemption is active
10 Reserved
11 Reserved

However none of these 2 fields offer reliable reporting to software.

When connecting ENETC to a link partner which is not capable of Frame Preemption, the expectation is that ENETC's verification should fail (VSTS=4) and its MM TX direction should be inactive (LPA=0, TXSTS=00) even though the MM TX is enabled (ME=1). But surprise, the LPA bit of MMCSR stays set even if VSTS=4 and ME=1.

OTOH, the TXSTS field has the opposite problem. I cannot get its value to change from 0, even when connecting to a link partner capable of frame preemption, which does respond to its verification frames (ME=1 and VSTS=3, "SUCCEEDED").

The only option with such buggy hardware seems to be to reimplement the formula for calculating tx-active in software, which is for tx-enabled to be true, and for the verify-status to be either SUCCEEDED, or DISABLED.

Quoted 7 lines

Without reliable tx-active reporting, we have no good indication when to commit the preemptible traffic classes to hardware, which makes it possible (but not desirable) to send preemptible traffic to a link partner incapable of receiving it. However, currently we do not have the logic to wait for TX to be active yet, so the impact is limited.

author maintainer
#7 lore raw

PATCH v2 3/9 net: enetc: only commit preemptible TCs to hardware when MM TX is active

In reply to Vladimir Oltean

This was left as TODO in commit 01e23b2b3bad ("net: enetc: add support for preemptible traffic classes") since it's relatively complicated.

Where this makes a difference is with a configuration as follows:

ethtool --set-mm eno0 pmac-enabled on tx-enabled on verify-enabled on

Preemptible packets should only be sent when the MAC Merge TX direction becomes active (i.o.w. when the verification process succeeds, aka when the link partner confirms it can process preemptible traffic). But the tc qdisc with the preemptible traffic classes is offloaded completely asynchronously w.r.t. the MM becoming active.

The ENETC manual does suggest that this should be handled in the driver:
"On startup, software should wait for the verification process to complete (MMCSR[VSTS]=011) before initiating traffic".

Adding the necessary logic allows future selftests to uphold the claim that an inactive or disabled MAC Merge layer should never send data packets through the pMAC.

This change moves enetc_set_ptcfpr() from enetc.c to enetc_ethtool.c, where its only caller is now - enetc_mm_commit_preemptible_tcs().

---
v1->v2: patch is new

 drivers/net/ethernet/freescale/enetc/enetc.c  | 23 ++-----
 drivers/net/ethernet/freescale/enetc/enetc.h  |  5 +-
 .../ethernet/freescale/enetc/enetc_ethtool.c  | 62 +++++++++++++++++++
 .../net/ethernet/freescale/enetc/enetc_hw.h   |  3 +
 4 files changed, 75 insertions(+), 18 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +6 -17
index 41c194c1672d..3c4fa26f0f9b 100644
@@ -25,23 +25,12 @@ void enetc_port_mac_wr(struct enetc_si *si, u32 reg, u32 val)
 }
 EXPORT_SYMBOL_GPL(enetc_port_mac_wr);
 
-void enetc_set_ptcfpr(struct enetc_hw *hw, unsigned long preemptible_tcs)
+static void enetc_change_preemptible_tcs(struct enetc_ndev_priv *priv,
+					 u8 preemptible_tcs)
 {
-	u32 val;
-	int tc;
-
-	for (tc = 0; tc < 8; tc++) {
-		val = enetc_port_rd(hw, ENETC_PTCFPR(tc));
-
-		if (preemptible_tcs & BIT(tc))
-			val |= ENETC_PTCFPR_FPE;
-		else
-			val &= ~ENETC_PTCFPR_FPE;
-
-		enetc_port_wr(hw, ENETC_PTCFPR(tc), val);
-	}
+	priv->preemptible_tcs = preemptible_tcs;
+	enetc_mm_commit_preemptible_tcs(priv);
 }
-EXPORT_SYMBOL_GPL(enetc_set_ptcfpr);
 
 static int enetc_num_stack_tx_queues(struct enetc_ndev_priv *priv)
 {
@@ -2659,7 +2648,7 @@ static void enetc_reset_tc_mqprio(struct net_device *ndev)
 
 	enetc_debug_tx_ring_prios(priv);
 
-	enetc_set_ptcfpr(hw, 0);
+	enetc_change_preemptible_tcs(priv, 0);
 }
 
 int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
@@ -2714,7 +2703,7 @@ int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
 
 	enetc_debug_tx_ring_prios(priv);
 
-	enetc_set_ptcfpr(hw, mqprio->preemptible_tcs);
+	enetc_change_preemptible_tcs(priv, mqprio->preemptible_tcs);
 
 	return 0;
 
drivers/net/ethernet/freescale/enetc/enetc.h +4 -1
index 143078a9ef16..c97a8e3d7a7f 100644
@@ -355,6 +355,9 @@ struct enetc_ndev_priv {
 	u16 rx_bd_count, tx_bd_count;
 
 	u16 msg_enable;
+
+	u8 preemptible_tcs;
+
 	enum enetc_active_offloads active_offloads;
 
 	u32 speed; /* store speed for compare update pspeed */
@@ -433,6 +436,7 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
 /* ethtool */
 void enetc_set_ethtool_ops(struct net_device *ndev);
 void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link);
+void enetc_mm_commit_preemptible_tcs(struct enetc_ndev_priv *priv);
 
 /* control buffer descriptor ring (CBDR) */
 int enetc_setup_cbdr(struct device *dev, struct enetc_hw *hw, int bd_count,
@@ -486,7 +490,6 @@ static inline void enetc_cbd_free_data_mem(struct enetc_si *si, int size,
 
 void enetc_reset_ptcmsdur(struct enetc_hw *hw);
 void enetc_set_ptcmsdur(struct enetc_hw *hw, u32 *queue_max_sdu);
-void enetc_set_ptcfpr(struct enetc_hw *hw, unsigned long preemptible_tcs);
 
 #ifdef CONFIG_FSL_ENETC_QOS
 int enetc_qos_query_caps(struct net_device *ndev, void *type_data);
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +62 -0

80 lines not on this page · raw message

drivers/net/ethernet/freescale/enetc/enetc_hw.h +3 -0
index 36bb2d6d5658..1619943fb263 100644
@@ -3,6 +3,9 @@
 
 #include <linux/bitops.h>
 
+#define ENETC_MM_VERIFY_SLEEP_US	USEC_PER_MSEC
+#define ENETC_MM_VERIFY_RETRIES		3
+
 /* ENETC device IDs */
 #define ENETC_DEV_ID_PF		0xe100
 #define ENETC_DEV_ID_VF		0xef00
Signature · 1 line
2.34.1
Reviewed-by on v2 3/9
#8 lore raw

Re: [PATCH v2 net-next 3/9] net: enetc: only commit preemptible TCs to hardware when MM TX is active

Quoted 17 lines · Vladimir Oltean

This was left as TODO in commit 01e23b2b3bad ("net: enetc: add support for preemptible traffic classes") since it's relatively complicated.

Where this makes a difference is with a configuration as follows:

ethtool --set-mm eno0 pmac-enabled on tx-enabled on verify-enabled on

Preemptible packets should only be sent when the MAC Merge TX direction becomes active (i.o.w. when the verification process succeeds, aka when the link partner confirms it can process preemptible traffic). But the tc qdisc with the preemptible traffic classes is offloaded completely asynchronously w.r.t. the MM becoming active.

The ENETC manual does suggest that this should be handled in the driver:
"On startup, software should wait for the verification process to complete (MMCSR[VSTS]=011) before initiating traffic".

Quoted 8 lines

Adding the necessary logic allows future selftests to uphold the claim that an inactive or disabled MAC Merge layer should never send data packets through the pMAC.

This change moves enetc_set_ptcfpr() from enetc.c to enetc_ethtool.c, where its only caller is now - enetc_mm_commit_preemptible_tcs().

Quoted 10 lines

int enetc_qos_query_caps(struct net_device *ndev, void *type_data);

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +1 -0
index deb674752851..838a92131963 100644
@@ -991,6 +991,64 @@ static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state)
 	return 0;
 }
 
+static int enetc_mm_wait_tx_active(struct enetc_hw *hw, int verify_time)

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state) · line 1004

Quoted 10 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +10 -0
+{
+	int timeout = verify_time * USEC_PER_MSEC * ENETC_MM_VERIFY_RETRIES;
+	u32 val;
+
+	/* This will time out after the standard value of 3 verification
+	 * attempts. To not sleep forever, it relies on a non-zero verify_time,
+	 * guarantee which is provided by the ethtool nlattr policy.
+	 */
+	return read_poll_timeout(enetc_port_rd, val,
+				 ENETC_MMCSR_GET_VSTS(val) == 3,

nit: 3 is doing a lot of work here.
As a follow-up, perhaps it could become part of an enum?

Quoted 3 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +3 -0
+				 ENETC_MM_VERIFY_SLEEP_US, timeout,
+				 true, hw, ENETC_MMCSR);
+}

...

author maintainer
#9 lore raw

Re: [PATCH v2 net-next 3/9] net: enetc: only commit preemptible TCs to hardware when MM TX is active

Quoted 9 lines · Simon Horman

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state) · line 1004

Quoted 6 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +6 -0
+	/* This will time out after the standard value of 3 verification
+	 * attempts. To not sleep forever, it relies on a non-zero verify_time,
+	 * guarantee which is provided by the ethtool nlattr policy.
+	 */
+	return read_poll_timeout(enetc_port_rd, val,
+				 ENETC_MMCSR_GET_VSTS(val) == 3,

nit: 3 is doing a lot of work here.
As a follow-up, perhaps it could become part of an enum?

IMHO it's easy to abuse enums, when numbers could do just fine. I think that in context (seeing the entire enetc_ethtool.c), this is not as bad as just this patch makes it to be, because the other occurrence of ENETC_MMCSR_GET_VSTS() is:

	switch (ENETC_MMCSR_GET_VSTS(val)) {
	case 0:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
		break;
	case 2:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING;
		break;
	case 3:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED;
		break;
	case 4:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
		break;
	case 5:
	default:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_UNKNOWN;
		break;
	}

so it's immediately clear what the 3 represents (in vim I just press '*' to see the other occurrences of ENETC_MMCSR_GET_VSTS).

I considered it, but I don't feel an urgent necessity to add an enum here. Doing that would essentially transform the code into:

	return read_poll_timeout(enetc_port_rd, val,
				 ENETC_MMCSR_GET_VSTS(val) == ENETC_MM_VSTS_SUCCEEDED,

	switch (ENETC_MMCSR_GET_VSTS(val)) {
	case ENETC_MMCSR_VSTS_DISABLED:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
		break;
	case ENETC_MMCSR_VSTS_VERIFYING:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING;
		break;
	case ENETC_MMCSR_VSTS_SUCCEEDED:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED;
		break;
	case ENETC_MMCSR_VSTS_FAILED:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
		break;
	case ENETC_MMCSR_VSTS_UNKNOWN:
	default:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_UNKNOWN;
		break;
	}

which to my eye is more bloated.

#10 lore raw

Re: [PATCH v2 net-next 3/9] net: enetc: only commit preemptible TCs to hardware when MM TX is active

Quoted 35 lines · Vladimir Oltean
Quoted 9 lines · Simon Horman

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state) · line 1004

Quoted 6 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +6 -0
+	/* This will time out after the standard value of 3 verification
+	 * attempts. To not sleep forever, it relies on a non-zero verify_time,
+	 * guarantee which is provided by the ethtool nlattr policy.
+	 */
+	return read_poll_timeout(enetc_port_rd, val,
+				 ENETC_MMCSR_GET_VSTS(val) == 3,

nit: 3 is doing a lot of work here.
As a follow-up, perhaps it could become part of an enum?

IMHO it's easy to abuse enums, when numbers could do just fine. I think that in context (seeing the entire enetc_ethtool.c), this is not as bad as just this patch makes it to be, because the other occurrence of ENETC_MMCSR_GET_VSTS() is:

	switch (ENETC_MMCSR_GET_VSTS(val)) {
	case 0:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
		break;
	case 2:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING;
		break;
	case 3:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED;
		break;
	case 4:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
		break;
	case 5:
	default:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_UNKNOWN;
		break;
	}
Quoted 2 lines

so it's immediately clear what the 3 represents (in vim I just press '*' to see the other occurrences of ENETC_MMCSR_GET_VSTS).

Thanks.

I did see the code above, and I do agree it is informational wrt the meaning of the values.

Quoted 25 lines

I considered it, but I don't feel an urgent necessity to add an enum here. Doing that would essentially transform the code into:

	return read_poll_timeout(enetc_port_rd, val,
				 ENETC_MMCSR_GET_VSTS(val) == ENETC_MM_VSTS_SUCCEEDED,

	switch (ENETC_MMCSR_GET_VSTS(val)) {
	case ENETC_MMCSR_VSTS_DISABLED:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
		break;
	case ENETC_MMCSR_VSTS_VERIFYING:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING;
		break;
	case ENETC_MMCSR_VSTS_SUCCEEDED:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED;
		break;
	case ENETC_MMCSR_VSTS_FAILED:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
		break;
	case ENETC_MMCSR_VSTS_UNKNOWN:
	default:
		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_UNKNOWN;
		break;
	}
Quoted 1 line

which to my eye is more bloated.

I guess it's subjective.
I certainly don't feel strongly about this.
And I appreciate you taking the time to respond to my idea.

I have no objections to leaving this patch as is (with '3').

author maintainer
#11 lore raw

PATCH v2 4/9 net: enetc: include MAC Merge / FP registers in register dump

In reply to Vladimir Oltean

These have been useful in debugging various problems related to frame preemption, so make them available through ethtool --register-dump for later too.

---
v1->v2: patch is new

 .../ethernet/freescale/enetc/enetc_ethtool.c    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +17 -0
index 838a92131963..e993ed04ab57 100644
@@ -32,6 +32,12 @@ static const u32 enetc_port_regs[] = {
 	ENETC_PM0_CMD_CFG, ENETC_PM0_MAXFRM, ENETC_PM0_IF_MODE
 };
 
+static const u32 enetc_port_mm_regs[] = {
+	ENETC_MMCSR, ENETC_PFPMR, ENETC_PTCFPR(0), ENETC_PTCFPR(1),
+	ENETC_PTCFPR(2), ENETC_PTCFPR(3), ENETC_PTCFPR(4), ENETC_PTCFPR(5),
+	ENETC_PTCFPR(6), ENETC_PTCFPR(7),
+};
+
 static int enetc_get_reglen(struct net_device *ndev)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
@@ -45,6 +51,9 @@ static int enetc_get_reglen(struct net_device *ndev)
 	if (hw->port)
 		len += ARRAY_SIZE(enetc_port_regs);
 
+	if (hw->port && !!(priv->si->hw_features & ENETC_SI_F_QBU))
+		len += ARRAY_SIZE(enetc_port_mm_regs);
+
 	len *= sizeof(u32) * 2; /* store 2 entries per reg: addr and value */
 
 	return len;
@@ -90,6 +99,14 @@ static void enetc_get_regs(struct net_device *ndev, struct ethtool_regs *regs,
 		*buf++ = addr;
 		*buf++ = enetc_rd(hw, addr);
 	}
+
+	if (priv->si->hw_features & ENETC_SI_F_QBU) {
+		for (i = 0; i < ARRAY_SIZE(enetc_port_mm_regs); i++) {
+			addr = ENETC_PORT_BASE + enetc_port_mm_regs[i];
+			*buf++ = addr;
+			*buf++ = enetc_rd(hw, addr);
+		}
+	}
 }
 
 static const struct {
Signature · 1 line
2.34.1
Reviewed-by on v2 4/9
#12 lore raw

Re: [PATCH v2 net-next 4/9] net: enetc: include MAC Merge / FP registers in register dump

Quoted 5 lines · Vladimir Oltean

These have been useful in debugging various problems related to frame preemption, so make them available through ethtool --register-dump for later too.

Quoted 24 lines

---
v1->v2: patch is new

 .../ethernet/freescale/enetc/enetc_ethtool.c    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +6 -0
index 838a92131963..e993ed04ab57 100644
@@ -32,6 +32,12 @@ static const u32 enetc_port_regs[] = {
 	ENETC_PM0_CMD_CFG, ENETC_PM0_MAXFRM, ENETC_PM0_IF_MODE
 };
 
+static const u32 enetc_port_mm_regs[] = {
+	ENETC_MMCSR, ENETC_PFPMR, ENETC_PTCFPR(0), ENETC_PTCFPR(1),
+	ENETC_PTCFPR(2), ENETC_PTCFPR(3), ENETC_PTCFPR(4), ENETC_PTCFPR(5),
+	ENETC_PTCFPR(6), ENETC_PTCFPR(7),
+};
+
 static int enetc_get_reglen(struct net_device *ndev)
 {
 	struct enetc_ndev_priv *priv = netdev_priv(ndev);

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_reglen(struct net_device *ndev) · line 54

Quoted 4 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +1 -0
@@ -45,6 +51,9 @@ static int enetc_get_reglen(struct net_device *ndev)
 	if (hw->port)
 		len += ARRAY_SIZE(enetc_port_regs);
 
+	if (hw->port && !!(priv->si->hw_features & ENETC_SI_F_QBU))

nit: I think you could make the condition.

	if (hw->port && priv->si->hw_features & ENETC_SI_F_QBU)

which would be consistent with the condition in the next hunk.

Quoted 23 lines
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +10 -0
+		len += ARRAY_SIZE(enetc_port_mm_regs);
+
 	len *= sizeof(u32) * 2; /* store 2 entries per reg: addr and value */
 
 	return len;
@@ -90,6 +99,14 @@ static void enetc_get_regs(struct net_device *ndev, struct ethtool_regs *regs,
 		*buf++ = addr;
 		*buf++ = enetc_rd(hw, addr);
 	}
+
+	if (priv->si->hw_features & ENETC_SI_F_QBU) {
+		for (i = 0; i < ARRAY_SIZE(enetc_port_mm_regs); i++) {
+			addr = ENETC_PORT_BASE + enetc_port_mm_regs[i];
+			*buf++ = addr;
+			*buf++ = enetc_rd(hw, addr);
+		}
+	}
 }
 
 static const struct {
Signature · 1 line
2.34.1
author maintainer
#13 lore raw

Re: [PATCH v2 net-next 4/9] net: enetc: include MAC Merge / FP registers in register dump

Quoted 9 lines · Simon Horman

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_reglen(struct net_device *ndev) · line 54

Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +1 -0
+	if (hw->port && !!(priv->si->hw_features & ENETC_SI_F_QBU))

nit: I think you could make the condition.

	if (hw->port && priv->si->hw_features & ENETC_SI_F_QBU)

which would be consistent with the condition in the next hunk.

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static void enetc_get_regs(struct net_device *ndev, struct ethtool_regs *regs, · line 103

Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +1 -0
+	if (priv->si->hw_features & ENETC_SI_F_QBU) {

Maybe, but it generates the exact same object code (tested with "make drivers/net/ethernet/freescale/enetc/enetc_ethtool.lst").

When I'm debugging, I'm a bit of a conspiracy theorist when it comes to operator precedence (& vs &&), and so, "A && B & C" doesn't read particularly well to me, and would be one of my first suspects at hiding a bug. I do know it would have worked in this case though, and that modern gcc/clang usually complains about suspicious/ unintuitive precedence.

#14 lore raw

Re: [PATCH v2 net-next 4/9] net: enetc: include MAC Merge / FP registers in register dump

Quoted 14 lines · Vladimir Oltean
Quoted 9 lines · Simon Horman

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static int enetc_get_reglen(struct net_device *ndev) · line 54

Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +1 -0
+	if (hw->port && !!(priv->si->hw_features & ENETC_SI_F_QBU))

nit: I think you could make the condition.

	if (hw->port && priv->si->hw_features & ENETC_SI_F_QBU)

which would be consistent with the condition in the next hunk.

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c static void enetc_get_regs(struct net_device *ndev, struct ethtool_regs *regs, · line 103

Quoted 1 line
drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +1 -0
+	if (priv->si->hw_features & ENETC_SI_F_QBU) {

Maybe, but it generates the exact same object code (tested with "make drivers/net/ethernet/freescale/enetc/enetc_ethtool.lst").

Quoted 6 lines

When I'm debugging, I'm a bit of a conspiracy theorist when it comes to operator precedence (& vs &&), and so, "A && B & C" doesn't read particularly well to me, and would be one of my first suspects at hiding a bug. I do know it would have worked in this case though, and that modern gcc/clang usually complains about suspicious/ unintuitive precedence.

Thanks, I guess it's subjective.
And I do understand your point regarding & vs &&.

No need to resend because of this
(or update the code at all if that is your choice).

author maintainer
#15 lore raw

PATCH v2 5/9 net: ethtool: mm: sanitize some UAPI configurations

In reply to Vladimir Oltean

The verify-enabled boolean (ETHTOOL_A_MM_VERIFY_ENABLED) was intended to be a sub-setting of tx-enabled (ETHTOOL_A_MM_TX_ENABLED). IOW, MAC Merge TX can be enabled with or without verification, but verification with TX disabled makes no sense.

The pmac-enabled boolean (ETHTOOL_A_MM_PMAC_ENABLED) was intended to be a global toggle from an API perspective, whereas tx-enabled just handles the TX direction. IOW, the pMAC can be enabled with or without TX, but it doesn't make sense to enable TX if the pMAC is not enabled.

Add two checks which sanitize and reject these invalid cases.

---
v1->v2: add missing "Verification requires TX enabled" check which was
only mentioned in the commit message

 net/ethtool/mm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
net/ethtool/mm.c +10 -0
index e00d7d5cea7e..4058a557b5a4 100644
@@ -214,6 +214,16 @@ static int ethnl_set_mm(struct ethnl_req_info *req_info, struct genl_info *info)
 		return -ERANGE;
 	}
 
+	if (cfg.verify_enabled && !cfg.tx_enabled) {
+		NL_SET_ERR_MSG(extack, "Verification requires TX enabled");
+		return -EINVAL;
+	}
+
+	if (cfg.tx_enabled && !cfg.pmac_enabled) {
+		NL_SET_ERR_MSG(extack, "TX enabled requires pMAC enabled");
+		return -EINVAL;
+	}
+
 	ret = dev->ethtool_ops->set_mm(dev, &cfg, extack);
 	return ret < 0 ? ret : 1;
 }
Signature · 1 line
2.34.1
Reviewed-by on v2 5/9
#16 lore raw

Re: [PATCH v2 net-next 5/9] net: ethtool: mm: sanitize some UAPI configurations

Quoted 5 lines · Vladimir Oltean

The verify-enabled boolean (ETHTOOL_A_MM_VERIFY_ENABLED) was intended to be a sub-setting of tx-enabled (ETHTOOL_A_MM_TX_ENABLED). IOW, MAC Merge TX can be enabled with or without verification, but verification with TX disabled makes no sense.

Quoted 8 lines

The pmac-enabled boolean (ETHTOOL_A_MM_PMAC_ENABLED) was intended to be a global toggle from an API perspective, whereas tx-enabled just handles the TX direction. IOW, the pMAC can be enabled with or without TX, but it doesn't make sense to enable TX if the pMAC is not enabled.

Add two checks which sanitize and reject these invalid cases.

author maintainer
#17 lore raw

PATCH v2 6/9 selftests: forwarding: sch_tbf_*: Add a pre-run hook

In reply to Vladimir Oltean

From: Petr Machata <[email protected]>

The driver-specific wrappers of these selftests invoke bail_on_lldpad to make sure that LLDPAD doesn't trample the configuration. The function bail_on_lldpad is going to move to lib.sh in the next patch. With that, it won't be visible for the wrappers before sourcing the framework script. And after sourcing it, it is too late: the selftest will have run by then.

One option might be to source NUM_NETIFS=0 lib.sh from the wrapper, but even if that worked (it might, it might not), that seems cumbersome. lib.sh is doing fair amount of stuff, and even if it works today, it does not look particularly solid as a solution.

Instead, introduce a hook, sch_tbf_pre_hook(), that when available, gets invoked. Move the bail to the hook.

---
v1->v2: new patch from Petr

 tools/testing/selftests/drivers/net/mlxsw/sch_tbf_ets.sh  | 6 +++++-
 tools/testing/selftests/drivers/net/mlxsw/sch_tbf_prio.sh | 6 +++++-
 tools/testing/selftests/drivers/net/mlxsw/sch_tbf_root.sh | 6 +++++-
 tools/testing/selftests/net/forwarding/sch_tbf_etsprio.sh | 4 ++++
 tools/testing/selftests/net/forwarding/sch_tbf_root.sh    | 4 ++++
 5 files changed, 23 insertions(+), 3 deletions(-)
tools/testing/selftests/drivers/net/mlxsw/sch_tbf_ets.sh +5 -1
index c6ce0b448bf3..b9b4cdf14ceb 100755
@@ -2,7 +2,11 @@
 # SPDX-License-Identifier: GPL-2.0
 
 source qos_lib.sh
-bail_on_lldpad
+
+sch_tbf_pre_hook()
+{
+	bail_on_lldpad
+}
 
 lib_dir=$(dirname $0)/../../../net/forwarding
 TCFLAGS=skip_sw
tools/testing/selftests/drivers/net/mlxsw/sch_tbf_prio.sh +5 -1
index 8d245f331619..dff9810ee04f 100755
@@ -2,7 +2,11 @@
 # SPDX-License-Identifier: GPL-2.0
 
 source qos_lib.sh
-bail_on_lldpad
+
+sch_tbf_pre_hook()
+{
+	bail_on_lldpad
+}
 
 lib_dir=$(dirname $0)/../../../net/forwarding
 TCFLAGS=skip_sw
tools/testing/selftests/drivers/net/mlxsw/sch_tbf_root.sh +5 -1
index 013886061f15..75406bd7036e 100755
@@ -2,7 +2,11 @@
 # SPDX-License-Identifier: GPL-2.0
 
 source qos_lib.sh
-bail_on_lldpad
+
+sch_tbf_pre_hook()
+{
+	bail_on_lldpad
+}
 
 lib_dir=$(dirname $0)/../../../net/forwarding
 TCFLAGS=skip_sw
tools/testing/selftests/net/forwarding/sch_tbf_etsprio.sh +4 -0
index 75a37c189ef3..df9bcd6a811a 100644
@@ -57,6 +57,10 @@ tbf_root_test()
 	tc qdisc del dev $swp2 root
 }
 
+if type -t sch_tbf_pre_hook >/dev/null; then
+	sch_tbf_pre_hook
+fi
+
 trap cleanup EXIT
 
 setup_prepare
tools/testing/selftests/net/forwarding/sch_tbf_root.sh +4 -0
index 72aa21ba88c7..96c997be0d03 100755
@@ -23,6 +23,10 @@ tbf_test()
 	tc qdisc del dev $swp2 root
 }
 
+if type -t sch_tbf_pre_hook >/dev/null; then
+	sch_tbf_pre_hook
+fi
+
 trap cleanup EXIT
 
 setup_prepare
Signature · 1 line
2.34.1
author maintainer
#18 lore raw

PATCH v2 7/9 selftests: forwarding: generalize bail_on_lldpad from mlxsw

In reply to Vladimir Oltean

From: Petr Machata <[email protected]>

mlxsw selftests often invoke a bail_on_lldpad() helper to make sure LLDPAD is not running, to prevent conflicts between the QoS configuration applied through TC or DCB command line tool, and the DCB configuration that LLDPAD might apply. This helper might be useful to others. Move the function to lib.sh, and parameterize to make reusable in other contexts.

---
v1->v2: new patch from Petr

 .../drivers/net/mlxsw/qos_headroom.sh         |  3 +-
 .../selftests/drivers/net/mlxsw/qos_lib.sh    | 28 -----------------
 .../selftests/drivers/net/mlxsw/qos_pfc.sh    |  3 +-
 .../selftests/drivers/net/mlxsw/sch_ets.sh    |  3 +-
 .../drivers/net/mlxsw/sch_red_core.sh         |  1 -
 .../drivers/net/mlxsw/sch_red_ets.sh          |  2 +-
 .../drivers/net/mlxsw/sch_red_root.sh         |  2 +-
 .../drivers/net/mlxsw/sch_tbf_ets.sh          |  4 +--
 .../drivers/net/mlxsw/sch_tbf_prio.sh         |  4 +--
 .../drivers/net/mlxsw/sch_tbf_root.sh         |  4 +--
 tools/testing/selftests/net/forwarding/lib.sh | 31 +++++++++++++++++++
 11 files changed, 39 insertions(+), 46 deletions(-)
tools/testing/selftests/drivers/net/mlxsw/qos_headroom.sh +1 -2
index 3569ff45f7d5..88162b4027c0 100755
@@ -18,7 +18,6 @@ lib_dir=$(dirname $0)/../../../net/forwarding
 NUM_NETIFS=0
 source $lib_dir/lib.sh
 source $lib_dir/devlink_lib.sh
-source qos_lib.sh
 
 swp=$NETIF_NO_CABLE
 
@@ -371,7 +370,7 @@ test_tc_int_buf()
 	tc qdisc delete dev $swp root
 }
 
-bail_on_lldpad
+bail_on_lldpad "configure DCB" "configure Qdiscs"
 
 trap cleanup EXIT
 setup_wait
tools/testing/selftests/drivers/net/mlxsw/qos_lib.sh +0 -28
index faa51012cdac..5ad092b9bf10 100644
@@ -54,31 +54,3 @@ measure_rate()
 	echo $ir $er
 	return $ret
 }
-
-bail_on_lldpad()
-{
-	if systemctl is-active --quiet lldpad; then
-
-		cat >/dev/stderr <<-EOF
-		WARNING: lldpad is running
-
-			lldpad will likely configure DCB, and this test will
-			configure Qdiscs. mlxsw does not support both at the
-			same time, one of them is arbitrarily going to overwrite
-			the other. That will cause spurious failures (or,
-			unlikely, passes) of this test.
-		EOF
-
-		if [[ -z $ALLOW_LLDPAD ]]; then
-			cat >/dev/stderr <<-EOF
-
-				If you want to run the test anyway, please set
-				an environment variable ALLOW_LLDPAD to a
-				non-empty string.
-			EOF
-			exit 1
-		else
-			return
-		fi
-	fi
-}
tools/testing/selftests/drivers/net/mlxsw/qos_pfc.sh +1 -2
index f9858e221996..42ce602d8d49 100755
@@ -79,7 +79,6 @@ lib_dir=$(dirname $0)/../../../net/forwarding
 NUM_NETIFS=6
 source $lib_dir/lib.sh
 source $lib_dir/devlink_lib.sh
-source qos_lib.sh
 
 _1KB=1000
 _100KB=$((100 * _1KB))
@@ -393,7 +392,7 @@ test_qos_pfc()
 	log_test "PFC"
 }
 
-bail_on_lldpad
+bail_on_lldpad "configure DCB" "configure Qdiscs"
 
 trap cleanup EXIT
 setup_prepare
tools/testing/selftests/drivers/net/mlxsw/sch_ets.sh +1 -2
index ceaa76b17a43..139175fd03e7 100755
@@ -5,7 +5,6 @@
 lib_dir=$(dirname $0)/../../../net/forwarding
 source $lib_dir/sch_ets_core.sh
 source $lib_dir/devlink_lib.sh
-source qos_lib.sh
 
 ALL_TESTS="
 	ping_ipv4
@@ -78,5 +77,5 @@ collect_stats()
 	done
 }
 
-bail_on_lldpad
+bail_on_lldpad "configure DCB" "configure Qdiscs"
 ets_run
tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh +0 -1
index 45b41b8f3232..299e06a5808c 100644
@@ -74,7 +74,6 @@ lib_dir=$(dirname $0)/../../../net/forwarding
 source $lib_dir/lib.sh
 source $lib_dir/devlink_lib.sh
 source mlxsw_lib.sh
-source qos_lib.sh
 
 ipaddr()
 {
tools/testing/selftests/drivers/net/mlxsw/sch_red_ets.sh +1 -1
index 0d01c7cd82a1..8ecddafa79b3 100755
@@ -166,7 +166,7 @@ ecn_mirror_test()
 	uninstall_qdisc
 }
 
-bail_on_lldpad
+bail_on_lldpad "configure DCB" "configure Qdiscs"
 
 trap cleanup EXIT
 setup_prepare
tools/testing/selftests/drivers/net/mlxsw/sch_red_root.sh +1 -1
index 860205338e6f..159108d02895 100755
@@ -73,7 +73,7 @@ red_mirror_test()
 	uninstall_qdisc
 }
 
-bail_on_lldpad
+bail_on_lldpad "configure DCB" "configure Qdiscs"
 
 trap cleanup EXIT
 setup_prepare
tools/testing/selftests/drivers/net/mlxsw/sch_tbf_ets.sh +1 -3
index b9b4cdf14ceb..ecc3664376b3 100755
@@ -1,11 +1,9 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
-source qos_lib.sh
-
 sch_tbf_pre_hook()
 {
-	bail_on_lldpad
+	bail_on_lldpad "configure DCB" "configure Qdiscs"
 }
 
 lib_dir=$(dirname $0)/../../../net/forwarding
tools/testing/selftests/drivers/net/mlxsw/sch_tbf_prio.sh +1 -3
index dff9810ee04f..2e0a4efb1703 100755
@@ -1,11 +1,9 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
-source qos_lib.sh
-
 sch_tbf_pre_hook()
 {
-	bail_on_lldpad
+	bail_on_lldpad "configure DCB" "configure Qdiscs"
 }
 
 lib_dir=$(dirname $0)/../../../net/forwarding
tools/testing/selftests/drivers/net/mlxsw/sch_tbf_root.sh +1 -3
index 75406bd7036e..6679a338dfc4 100755
@@ -1,11 +1,9 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
-source qos_lib.sh
-
 sch_tbf_pre_hook()
 {
-	bail_on_lldpad
+	bail_on_lldpad "configure DCB" "configure Qdiscs"
 }
 
 lib_dir=$(dirname $0)/../../../net/forwarding
tools/testing/selftests/net/forwarding/lib.sh +31 -0
index d47499ba81c7..efd48e1cadd2 100755
@@ -1887,3 +1887,34 @@ mldv1_done_get()
 
 	payload_template_expand_checksum "$hbh$icmpv6" $checksum
 }
+
+bail_on_lldpad()
+{
+	local reason1="$1"; shift
+	local reason2="$1"; shift
+
+	if systemctl is-active --quiet lldpad; then
+
+		cat >/dev/stderr <<-EOF
+		WARNING: lldpad is running
+
+			lldpad will likely $reason1, and this test will
+			$reason2. Both are not supported at the same time,
+			one of them is arbitrarily going to overwrite the
+			other. That will cause spurious failures (or, unlikely,
+			passes) of this test.
+		EOF
+
+		if [[ -z $ALLOW_LLDPAD ]]; then
+			cat >/dev/stderr <<-EOF
+
+				If you want to run the test anyway, please set
+				an environment variable ALLOW_LLDPAD to a
+				non-empty string.
+			EOF
+			exit 1
+		else
+			return
+		fi
+	fi
+}
Signature · 1 line
2.34.1
author maintainer
#19 lore raw

PATCH v2 8/9 selftests: forwarding: introduce helper for standard ethtool counters

In reply to Vladimir Oltean

Counters for the MAC Merge layer and preemptible MAC have standardized so far on using structured ethtool stats as opposed to the driver specific names and meanings.

Benefit from that rare opportunity and introduce a helper to lib.sh for querying standardized counters, in the hope that these will take off for other uses as well.

---
v1->v2: patch is new

 tools/testing/selftests/net/forwarding/lib.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/testing/selftests/net/forwarding/lib.sh +11 -0
index efd48e1cadd2..36e47c9d7cca 100755
@@ -787,6 +787,17 @@ ethtool_stats_get()
 	ethtool -S $dev | grep "^ *$stat:" | head -n 1 | cut -d: -f2
 }
 
+ethtool_std_stats_get()
+{
+	local dev=$1; shift
+	local grp=$1; shift
+	local name=$1; shift
+	local src=$1; shift
+
+	ethtool --json -S $dev --groups $grp -- --src $src | \
+		jq '.[]."'"$grp"'"."'$name'"'
+}
+
 qdisc_stats_get()
 {
 	local dev=$1; shift
Signature · 1 line
2.34.1
author maintainer
#20 lore raw

PATCH v2 9/9 selftests: forwarding: add a test for MAC Merge layer

In reply to Vladimir Oltean

The MAC Merge layer (IEEE 802.3-2018 clause 99) does all the heavy lifting for Frame Preemption (IEEE 802.1Q-2018 clause 6.7.2), a TSN feature for minimizing latency.

Preemptible traffic is different on the wire from normal traffic in incompatible ways. If we send a preemptible packet and the link partner doesn't support preemption, it will drop it as an error frame and we will never know. The MAC Merge layer has a control plane of its own, which can be manipulated (using ethtool) in order to negotiate this capability with the link partner (through LLDP).

Actually the TLV format for LLDP solves this problem only partly, because both partners only advertise:
- if they support preemption (RX and TX)
- if they have enabled preemption (TX)
so we cannot tell the link partner what to do - we cannot force it to enable reception of our preemptible packets.

That is fully solved by the verification feature, where the local device generates some small probe frames which look like preemptible frames with no useful content, and the link partner is obliged to respond to them if it supports the standard. If the verification times out, we know that preemption isn't active in our TX direction on the link.

Having clarified the definition, this selftest exercises the manual (ethtool) configuration path of 2 link partners (with and without verification), and the LLDP code path, using the openlldp project.

The test also verifies the TX activity of the MAC Merge layer by sending traffic through a traffic class configured as preemptible (using mqprio). There isn't a good way to make this really portable (user space cannot find out how many traffic classes there are for a device), but I chose num_tc 4 here, that should work reasonably well. I also know that some devices (stmmac) only permit TXQ0 to be preemptible, so this is why PREEMPTIBLE_PRIO was strategically chosen as 0. Even if other hardware is more configurable, this test should cover the baseline.

This is not really a "forwarding" selftest, but I put it near the other "ethtool" selftests.

$ ./ethtool_mm.sh eno0 swp0
TEST: Manual configuration with verification: eno0 to swp0          [ OK ]
TEST: Manual configuration with verification: swp0 to eno0          [ OK ]
TEST: Manual configuration without verification: eno0 to swp0       [ OK ]
TEST: Manual configuration without verification: swp0 to eno0       [ OK ]
TEST: Manual configuration with failed verification: eno0 to swp0   [ OK ]
TEST: Manual configuration with failed verification: swp0 to eno0   [ OK ]
TEST: LLDP                                                          [ OK ]

---
v1->v2:
- bail_on_lldpad is generic
- manual ethtool mm tests are bidirectional
- new "failed verification" test
- testing with traffic as well

 .../testing/selftests/net/forwarding/Makefile |   1 +
 .../selftests/net/forwarding/ethtool_mm.sh    | 288 ++++++++++++++++++
 tools/testing/selftests/net/forwarding/lib.sh |  18 ++
 3 files changed, 307 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/ethtool_mm.sh
tools/testing/selftests/net/forwarding/Makefile +1 -0
index 236f6b796a52..a474c60fe348 100644
@@ -15,6 +15,7 @@ TEST_PROGS = bridge_igmp.sh \
 	custom_multipath_hash.sh \
 	dual_vxlan_bridge.sh \
 	ethtool_extended_state.sh \
+	ethtool_mm.sh \
 	ethtool.sh \
 	gre_custom_multipath_hash.sh \
 	gre_inner_v4_multipath.sh \
tools/testing/selftests/net/forwarding/ethtool_mm.sh new file +288 -0

288 lines not on this page · raw message

tools/testing/selftests/net/forwarding/lib.sh +18 -0
index 36e47c9d7cca..057c3d0ad620 100755
@@ -120,6 +120,15 @@ check_tc_action_hw_stats_support()
 	fi
 }
 
+check_tc_fp_support()
+{
+	tc qdisc add dev lo mqprio help 2>&1 | grep -q "fp "
+	if [[ $? -ne 0 ]]; then
+		echo "SKIP: iproute2 too old; tc is missing frame preemption support"
+		exit $ksft_skip
+	fi
+}
+
 check_ethtool_lanes_support()
 {
 	ethtool --help 2>&1| grep lanes &> /dev/null
@@ -129,6 +138,15 @@ check_ethtool_lanes_support()
 	fi
 }
 
+check_ethtool_mm_support()
+{
+	ethtool --help 2>&1| grep -- '--show-mm' &> /dev/null
+	if [[ $? -ne 0 ]]; then
+		echo "SKIP: ethtool too old; it is missing MAC Merge layer support"
+		exit $ksft_skip
+	fi
+}
+
 check_locked_port_support()
 {
 	if ! bridge -d link show | grep -q " locked"; then
Signature · 1 line
2.34.1
#21 lore raw
In reply to Vladimir Oltean
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 18 Apr 2023 14:14:50 +0300 you wrote:

This series consolidates the behavior of the 2 drivers that implement the ethtool MAC Merge layer by making NXP ENETC commit its preemptible traffic classes to hardware only when MM TX is active (same as Ocelot).

Then, after resolving an issue with the ENETC driver, it restricts user space from entering 2 states which don't make sense:

[...]

Here is the summary with links:
- [v2,net-next,1/9] net: enetc: fix MAC Merge layer remaining enabled until a link down event

    https://git.kernel.org/netdev/net-next/c/59be75db5966
  - [v2,net-next,2/9] net: enetc: report mm tx-active based on tx-enabled and verify-status
    https://git.kernel.org/netdev/net-next/c/153b5b1d030d
  - [v2,net-next,3/9] net: enetc: only commit preemptible TCs to hardware when MM TX is active
    https://git.kernel.org/netdev/net-next/c/827145392a4a
  - [v2,net-next,4/9] net: enetc: include MAC Merge / FP registers in register dump
    https://git.kernel.org/netdev/net-next/c/16a2c7634442
  - [v2,net-next,5/9] net: ethtool: mm: sanitize some UAPI configurations
    https://git.kernel.org/netdev/net-next/c/35b288d6e3d4
  - [v2,net-next,6/9] selftests: forwarding: sch_tbf_*: Add a pre-run hook
    https://git.kernel.org/netdev/net-next/c/54e906f1639e
  - [v2,net-next,7/9] selftests: forwarding: generalize bail_on_lldpad from mlxsw
    https://git.kernel.org/netdev/net-next/c/8fcac79270ca
  - [v2,net-next,8/9] selftests: forwarding: introduce helper for standard ethtool counters
    https://git.kernel.org/netdev/net-next/c/b5bf7126a6a0
  - [v2,net-next,9/9] selftests: forwarding: add a test for MAC Merge layer
    https://git.kernel.org/netdev/net-next/c/e6991384ace5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html