mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v9 0/2] Add Frame Preemption MAC Merge support for ICSSG
@ 2026-11-21 14:46 Meghana Malladi
  2026-11-21 14:46 ` [PATCH net-next v9 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
  2026-11-21 14:46 ` [PATCH net-next v9 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge Meghana Malladi
  0 siblings, 2 replies; 5+ messages in thread
From: Meghana Malladi @ 2026-11-21 14:46 UTC (permalink / raw)
  To: marco.crivellari, haokexin, kees+treewide, laixiangwu, m-malladi,
	arnd, horms, basharath, parvathi, vladimir.oltean, rogerq,
	danishanwar, pabeni, kuba, edumazet, davem, andrew+netdev
  Cc: linux-arm-kernel, netdev, linux-kernel, srk, Vignesh Raghavendra

This patch series adds QoS support to the ICSSG PRUETH driver.
The first patch implements mqprio qdisc handling and TC offload hooks
so userspace can request TC mappings and queue counts.

It also integrates a driver-side mechanism to program the firmware
with the IET/FPE preemption mask and to kick the firmware verify state
machine when frame preemption is enabled. The second patch adds ethtool
perations for the MAC Merge (Frame Preemption) sublayer, exposing .get_mm,
.set_mm and .get_mm_stats so admins can view and change MAC Merge
parameters and retrieve preemption statistics.

v8: https://lore.kernel.org/all/20260915063052.2274986-1-m-malladi@ti.com/

MD Danish Anwar (2):
  net: ti: icssg-prueth: Add Frame Preemption MAC Merge support
  net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge

 drivers/net/ethernet/ti/Makefile              |   3 +-
 drivers/net/ethernet/ti/icssg/icssg_config.h  |   9 -
 drivers/net/ethernet/ti/icssg/icssg_ethtool.c | 127 ++++++-
 drivers/net/ethernet/ti/icssg/icssg_prueth.c  |  16 +-
 drivers/net/ethernet/ti/icssg/icssg_prueth.h  |  19 +-
 drivers/net/ethernet/ti/icssg/icssg_qos.c     | 328 ++++++++++++++++++
 drivers/net/ethernet/ti/icssg/icssg_qos.h     |  99 ++++++
 drivers/net/ethernet/ti/icssg/icssg_stats.h   |  86 +++--
 .../net/ethernet/ti/icssg/icssg_switch_map.h  |   5 +
 9 files changed, 633 insertions(+), 59 deletions(-)
 create mode 100644 drivers/net/ethernet/ti/icssg/icssg_qos.c
 create mode 100644 drivers/net/ethernet/ti/icssg/icssg_qos.h


base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v9 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support
  2026-11-21 14:46 [PATCH net-next v9 0/2] Add Frame Preemption MAC Merge support for ICSSG Meghana Malladi
@ 2026-11-21 14:46 ` Meghana Malladi
  2026-11-25 15:08   ` netdev-bot+sashiko
  2026-11-21 14:46 ` [PATCH net-next v9 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge Meghana Malladi
  1 sibling, 1 reply; 5+ messages in thread
From: Meghana Malladi @ 2026-11-21 14:46 UTC (permalink / raw)
  To: marco.crivellari, haokexin, kees+treewide, laixiangwu, m-malladi,
	arnd, horms, basharath, parvathi, vladimir.oltean, rogerq,
	danishanwar, pabeni, kuba, edumazet, davem, andrew+netdev
  Cc: linux-arm-kernel, netdev, linux-kernel, srk, Vignesh Raghavendra

From: MD Danish Anwar <danishanwar@ti.com>

Introduce QoS infrastructure for Frame Preemption (FPE) support in
the ICSSG Ethernet driver.

prueth_qos_iet tracks FPE enable/active state and verify state
machine status via firmware-reported enum icssg_ietfpe_verify_states.
icssg_config_ietfpe() configures IET FPE in firmware, triggers
verify state machine based on ethtool MAC Merge parameters.
Polls firmware verify status up to 3 times with verify_time_ms
intervals and driver handles timeout by logging error and returning.
In case of any failure during configuration for enable/disable,
IET FPE falls back to disabled state.

For MQPRIO qdisc support all queues are express by default later
gets override by user-provided preemptible_tcs bitmask via tc
qdisc mask. Preempt mask configuration: Maps traffic classes to
queue express/preemptible state and applied only when FPE is
active (Tx enabled).

Verify state machine re-triggers on link up/down events based on
fpe_enabled and fpe_active flags, and for memory protection,
fpe_lock serializes all FPE state mutations, preventing races
between ethtool config, qdisc setup, and link events.

Default values for verify_time_ms and tx_min_frag_size are set
during init to ensure get_mm() returns valid state before the
MAC Merge ethtool uAPI (.get_mm()/.set_mm()) is wired up in the
following patch.

Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Signed-off-by: Meghana Malladi <m-malladi@ti.com>
---

v9-v8 changelog:
Sashiko comments addressed:
  - Fix mutex_destroy/mutex_init asymmetry: add icssg_qos_exit(),
    remove mutex_destroy from shared prueth_netdev_exit()     
  - Clear PRE_EMPTION_ENABLE_TX and PRE_EMPTION_ENABLE_VERIFY in
    firmware on link-down to prevent HW/driver divergence                      
  - Fix plain emac->link = 0 store with WRITE_ONCE() in
    prueth_emac_common_start()                                                        
  - Fix EXPRESS_PRE_EMPTIVE_Q_MASK encoding: initialise prempt_mask to
    ICSSG_EXPRESS_Q_MASK_ALL and subtract preemptible queues, so unmanaged
    queues remain express      
  - Add rollback in emac_tc_setup_mqprio() on firmware config failure           
  - Update commit message to note MAC Merge ethtool uAPI (.get_mm()/.set_mm())
    is wired up in the following patch

Sashiko comments skipped:
 - enable path is intentionally unreachable within this patch; uAPI lands
   in the next patch (false positive)

 drivers/net/ethernet/ti/Makefile             |   3 +-
 drivers/net/ethernet/ti/icssg/icssg_config.h |   9 -
 drivers/net/ethernet/ti/icssg/icssg_prueth.c |  16 +-
 drivers/net/ethernet/ti/icssg/icssg_prueth.h |   8 +-
 drivers/net/ethernet/ti/icssg/icssg_qos.c    | 327 +++++++++++++++++++
 drivers/net/ethernet/ti/icssg/icssg_qos.h    |  69 ++++
 6 files changed, 416 insertions(+), 16 deletions(-)
 create mode 100644 drivers/net/ethernet/ti/icssg/icssg_qos.c
 create mode 100644 drivers/net/ethernet/ti/icssg/icssg_qos.h

diff --git a/drivers/net/ethernet/ti/Makefile b/drivers/net/ethernet/ti/Makefile
index f4276c9a77620..d19bcd25c9d07 100644
--- a/drivers/net/ethernet/ti/Makefile
+++ b/drivers/net/ethernet/ti/Makefile
@@ -46,6 +46,7 @@ icssg-y := icssg/icssg_common.o \
 	   icssg/icssg_config.o \
 	   icssg/icssg_mii_cfg.o \
 	   icssg/icssg_stats.o \
-	   icssg/icssg_ethtool.o
+	   icssg/icssg_ethtool.o \
+	   icssg/icssg_qos.o
 
 obj-$(CONFIG_TI_ICSS_IEP) += icssg/icss_iep.o
diff --git a/drivers/net/ethernet/ti/icssg/icssg_config.h b/drivers/net/ethernet/ti/icssg/icssg_config.h
index 60d69744ffae2..1ac202f855ed4 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_config.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_config.h
@@ -323,13 +323,4 @@ struct prueth_fdb_slot {
 	u8 fid;
 	u8 fid_c2;
 } __packed;
-
-enum icssg_ietfpe_verify_states {
-	ICSSG_IETFPE_STATE_UNKNOWN = 0,
-	ICSSG_IETFPE_STATE_INITIAL,
-	ICSSG_IETFPE_STATE_VERIFYING,
-	ICSSG_IETFPE_STATE_SUCCEEDED,
-	ICSSG_IETFPE_STATE_FAILED,
-	ICSSG_IETFPE_STATE_DISABLED
-};
 #endif /* __NET_TI_ICSSG_CONFIG_H */
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index 9bb67e185a3ea..d8431132c34b0 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -285,7 +285,7 @@ static int prueth_emac_common_start(struct prueth *prueth)
 		 * change and will skip critical configuration like writing
 		 * speed to firmware.
 		 */
-		emac->link = 0;
+		WRITE_ONCE(emac->link, 0);
 
 		mutex_lock(&emac->ndev->phydev->lock);
 		emac_adjust_link(emac->ndev);
@@ -357,11 +357,11 @@ static void emac_adjust_link(struct net_device *ndev)
 		}
 		if (!emac->link) {
 			new_state = true;
-			emac->link = 1;
+			WRITE_ONCE(emac->link, 1);
 		}
 	} else if (emac->link) {
 		new_state = true;
-		emac->link = 0;
+		WRITE_ONCE(emac->link, 0);
 
 		/* f/w should support 100 & 1000 */
 		emac->speed = SPEED_1000;
@@ -392,6 +392,8 @@ static void emac_adjust_link(struct net_device *ndev)
 		} else {
 			icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
 		}
+
+		icssg_qos_link_state_update(ndev);
 	}
 
 	if (emac->link) {
@@ -1652,6 +1654,7 @@ static const struct net_device_ops emac_netdev_ops = {
 	.ndo_hwtstamp_get = icssg_ndo_get_ts_config,
 	.ndo_hwtstamp_set = icssg_ndo_set_ts_config,
 	.ndo_xsk_wakeup = prueth_xsk_wakeup,
+	.ndo_setup_tc = icssg_qos_ndo_setup_tc,
 };
 
 static int prueth_netdev_init(struct prueth *prueth,
@@ -1686,6 +1689,8 @@ static int prueth_netdev_init(struct prueth *prueth,
 
 	INIT_DELAYED_WORK(&emac->stats_work, icssg_stats_work_handler);
 
+	icssg_qos_init(ndev);
+
 	ret = pruss_request_mem_region(prueth->pruss,
 				       port == PRUETH_PORT_MII0 ?
 				       PRUSS_MEM_DRAM0 : PRUSS_MEM_DRAM1,
@@ -1793,6 +1798,7 @@ static int prueth_netdev_init(struct prueth *prueth,
 free:
 	pruss_release_mem_region(prueth->pruss, &emac->dram);
 free_ndev:
+	icssg_qos_exit(ndev);
 	emac->ndev = NULL;
 	prueth->emac[mac] = NULL;
 	free_netdev(ndev);
@@ -2475,6 +2481,8 @@ static int prueth_probe(struct platform_device *pdev)
 		if (!eth_node)
 			continue;
 
+		if (prueth->emac[i])
+			icssg_qos_exit(prueth->emac[i]->ndev);
 		prueth_netdev_exit(prueth, eth_node);
 	}
 
@@ -2534,6 +2542,8 @@ static void prueth_remove(struct platform_device *pdev)
 		if (!eth_node)
 			continue;
 
+		if (prueth->emac[i])
+			icssg_qos_exit(prueth->emac[i]->ndev);
 		prueth_netdev_exit(prueth, eth_node);
 	}
 
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
index df93d15c5b786..f73b8f5fca956 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -44,10 +44,11 @@
 #include "icssg_config.h"
 #include "icss_iep.h"
 #include "icssg_switch_map.h"
+#include "icssg_qos.h"
 
-#define PRUETH_MAX_MTU          (2000 - ETH_HLEN - ETH_FCS_LEN)
-#define PRUETH_MIN_PKT_SIZE     (VLAN_ETH_ZLEN)
-#define PRUETH_MAX_PKT_SIZE     (PRUETH_MAX_MTU + ETH_HLEN + ETH_FCS_LEN)
+#define PRUETH_MAX_MTU		(2000 - ETH_HLEN - ETH_FCS_LEN)
+#define PRUETH_MIN_PKT_SIZE	(VLAN_ETH_ZLEN)
+#define PRUETH_MAX_PKT_SIZE	(PRUETH_MAX_MTU + ETH_HLEN + ETH_FCS_LEN)
 
 #define ICSS_SLICE0	0
 #define ICSS_SLICE1	1
@@ -254,6 +255,7 @@ struct prueth_emac {
 	struct bpf_prog *xdp_prog;
 	struct xdp_attachment_info xdpi;
 	int xsk_qid;
+	struct prueth_qos qos;
 };
 
 /* The buf includes headroom compatible with both skb and xdpf */
diff --git a/drivers/net/ethernet/ti/icssg/icssg_qos.c b/drivers/net/ethernet/ti/icssg/icssg_qos.c
new file mode 100644
index 0000000000000..55ddf7669530c
--- /dev/null
+++ b/drivers/net/ethernet/ti/icssg/icssg_qos.c
@@ -0,0 +1,327 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Texas Instruments ICSSG PRUETH QoS submodule
+ * Copyright (C) 2023 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include "icssg_prueth.h"
+#include "icssg_switch_map.h"
+
+static void icssg_iet_set_preempt_mask(struct prueth_emac *emac)
+{
+	void __iomem *config = emac->dram.va + ICSSG_CONFIG_OFFSET;
+	struct prueth_qos_mqprio *p_mqprio = &emac->qos.mqprio;
+	struct tc_mqprio_qopt *qopt = &p_mqprio->qopt;
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	int prempt_mask = 0, i;
+	u8 tc, num_tc;
+
+	if (!iet->preemptible_tcs)
+		goto reset_hw;
+
+	if (iet->fpe_active) {
+		/* Reset all Q_MAP entries first to clear any stale preemptible
+		 * entries from a prior wider TC mapping.
+		 */
+		for (i = 0; i < ICSSG_MAX_TC_QUEUES; i++)
+			writeb(0, config + EXPRESS_PRE_EMPTIVE_Q_MAP + i);
+
+		/* Start with all queues express. Only clear bits for queues
+		 * that are explicitly mapped to a preemptible TC. Queues not
+		 * covered by any TC (untagged, XDP, special priority) remain
+		 * express by default.
+		 */
+		prempt_mask = ICSSG_EXPRESS_Q_MASK_ALL;
+		num_tc = p_mqprio->qopt.num_tc;
+		for (tc = 0; tc < num_tc; tc++) {
+			if (iet->preemptible_tcs & BIT(tc)) {
+				for (i = qopt->offset[tc]; i < qopt->offset[tc] + qopt->count[tc]; i++) {
+					writeb(BIT(4),
+					       config + EXPRESS_PRE_EMPTIVE_Q_MAP + i);
+					prempt_mask &= ~BIT(i);
+				}
+			}
+		}
+		writeb(prempt_mask, config + EXPRESS_PRE_EMPTIVE_Q_MASK);
+		return;
+	}
+
+reset_hw:
+	/* Reset to default: all queues as express */
+	for (i = 0; i < ICSSG_MAX_TC_QUEUES; i++)
+		writeb(0, config + EXPRESS_PRE_EMPTIVE_Q_MAP + i);
+	writeb(ICSSG_EXPRESS_Q_MASK_ALL, config + EXPRESS_PRE_EMPTIVE_Q_MASK);
+}
+
+static int icssg_iet_verify_wait(struct prueth_emac *emac)
+{
+	void __iomem *config = emac->dram.va + ICSSG_CONFIG_OFFSET;
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	unsigned long delay_us, timeout_us;
+	u32 status;
+	int ret;
+
+	delay_us = iet->verify_time_ms * 1000;
+	timeout_us = delay_us * ICSSG_IET_VERIFY_ATTEMPTS;
+
+	ret = readb_poll_timeout(config + PRE_EMPTION_VERIFY_STATUS,
+				 status,
+				 status == ICSSG_IETFPE_STATE_SUCCEEDED ||
+				 status == ICSSG_IETFPE_STATE_FAILED,
+				 delay_us,
+				 timeout_us);
+
+	iet->verify_status = status;
+	if (!ret && status == ICSSG_IETFPE_STATE_FAILED)
+		return -EIO;
+	return ret;
+}
+
+/* Direct synchronous configuration of IET FPE.
+ * Caller must hold iet->fpe_lock.
+ */
+int icssg_config_ietfpe(struct net_device *ndev, bool enable)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	void __iomem *config = emac->dram.va + ICSSG_CONFIG_OFFSET;
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	int ret;
+	u8 val;
+
+	lockdep_assert_held(&iet->fpe_lock);
+
+	if (!READ_ONCE(emac->link)) {
+		netdev_dbg(ndev, "cannot change IET/FPE state when interface is down\n");
+		return 0;
+	}
+
+	/* Update FPE Tx enable bit (PRE_EMPTION_ENABLE_TX) if
+	 * fpe_enabled is set to enable MM in Tx direction
+	 */
+	writeb(enable ? 1 : 0, config + PRE_EMPTION_ENABLE_TX);
+	writew(iet->tx_min_frag_size + ETH_FCS_LEN,
+	       config + PRE_EMPTION_ADD_FRAG_SIZE_LOCAL);
+
+	/* If FPE is to be enabled, first configure MAC Verify state
+	 * machine in firmware as firmware kicks the Verify process
+	 * as soon as ICSSG_EMAC_PORT_PREMPT_TX_ENABLE command is
+	 * received.
+	 */
+	if (enable && iet->mac_verify_configure) {
+		writeb(1, config + PRE_EMPTION_ENABLE_VERIFY);
+		writel(iet->verify_time_ms, config + PRE_EMPTION_VERIFY_TIME);
+	} else {
+		writeb(0, config + PRE_EMPTION_ENABLE_VERIFY);
+		iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
+	}
+
+	/* Send command to enable FPE Tx side. Rx is always enabled */
+	ret = icssg_set_port_state(emac,
+				   enable ? ICSSG_EMAC_PORT_PREMPT_TX_ENABLE :
+					    ICSSG_EMAC_PORT_PREMPT_TX_DISABLE);
+	if (ret) {
+		netdev_err(ndev, "TX preempt %s command failed\n",
+			   str_enable_disable(enable));
+		goto fallback;
+	}
+
+	if (enable && iet->mac_verify_configure) {
+		ret = icssg_iet_verify_wait(emac);
+		if (ret) {
+			netdev_err(ndev, "MAC Merge verification failed: %s\n",
+				   iet->verify_status == ICSSG_IETFPE_STATE_FAILED ?
+				   "link partner rejected" : "timeout");
+			goto disable_tx;
+		}
+	} else if (enable) {
+		/* Give firmware some time to update
+		 * PRE_EMPTION_ACTIVE_TX state
+		 */
+		usleep_range(100, 200);
+	}
+
+	if (enable) {
+		val = readb(config + PRE_EMPTION_ACTIVE_TX);
+		if (val != 1) {
+			netdev_err(ndev,
+				   "Firmware fails to activate IET/FPE\n");
+			ret = -EIO;
+			goto disable_tx;
+		}
+		iet->fpe_active = true;
+	} else {
+		iet->fpe_active = false;
+	}
+
+	icssg_iet_set_preempt_mask(emac);
+	netdev_dbg(ndev, "IET FPE %s successfully\n",
+		   str_enable_disable(enable));
+	return 0;
+
+disable_tx:
+	icssg_set_port_state(emac, ICSSG_EMAC_PORT_PREMPT_TX_DISABLE);
+fallback:
+	writeb(0, config + PRE_EMPTION_ENABLE_TX);
+	writeb(0, config + PRE_EMPTION_ENABLE_VERIFY);
+	iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
+	iet->fpe_active = false;
+	icssg_iet_set_preempt_mask(emac);
+	return ret;
+}
+
+void icssg_qos_init(struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+
+	mutex_init(&iet->fpe_lock);
+	/* Set default values to prevent garbage values during .get_mm() */
+	iet->verify_time_ms = ICSSG_IET_MAX_VERIFY_TIME;
+	iet->tx_min_frag_size = ETH_ZLEN;
+}
+EXPORT_SYMBOL_GPL(icssg_qos_init);
+
+void icssg_qos_exit(struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+
+	mutex_destroy(&emac->qos.iet.fpe_lock);
+}
+EXPORT_SYMBOL_GPL(icssg_qos_exit);
+
+static int icssg_iet_change_preemptible_tcs(struct prueth_emac *emac)
+{
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	int ret;
+
+	mutex_lock(&iet->fpe_lock);
+	if (!iet->fpe_enabled && !iet->preemptible_tcs) {
+		mutex_unlock(&iet->fpe_lock);
+		return 0;
+	}
+	ret = icssg_config_ietfpe(emac->ndev, iet->fpe_enabled);
+	mutex_unlock(&iet->fpe_lock);
+
+	return ret;
+}
+
+static int emac_tc_query_caps(struct net_device *ndev, void *type_data)
+{
+	struct tc_query_caps_base *base = type_data;
+
+	switch (base->type) {
+	case TC_SETUP_QDISC_MQPRIO: {
+		struct tc_mqprio_caps *caps = base->caps;
+
+		caps->validate_queue_counts = true;
+		return 0;
+	}
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int emac_tc_setup_mqprio(struct net_device *ndev, void *type_data)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_qos_mqprio *p_mqprio = &emac->qos.mqprio;
+	struct tc_mqprio_qopt_offload *mqprio = type_data;
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	struct tc_mqprio_qopt *qopt = &mqprio->qopt;
+	int tc, offset, count, ret;
+
+	/* Validate parameters */
+	if (qopt->num_tc > ICSSG_MAX_TC_QUEUES) {
+		netdev_err(ndev, "Number of traffic classes (%u) exceeds hardware limit\n",
+			   qopt->num_tc);
+		return -EOPNOTSUPP;
+	}
+
+	if (mqprio->flags & TC_MQPRIO_F_SHAPER) {
+		netdev_err(ndev, "traffic shaping is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (mqprio->flags & (TC_MQPRIO_F_MIN_RATE | TC_MQPRIO_F_MAX_RATE)) {
+		netdev_err(ndev, "per-queue rate limiting is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (!qopt->num_tc) {
+		netdev_reset_tc(ndev);
+	} else {
+		netdev_set_num_tc(ndev, qopt->num_tc);
+
+		for (tc = 0; tc < qopt->num_tc; tc++) {
+			count = qopt->count[tc];
+			offset = qopt->offset[tc];
+			netdev_set_tc_queue(ndev, tc, count, offset);
+		}
+	}
+
+	mutex_lock(&iet->fpe_lock);
+	if (!qopt->num_tc) {
+		iet->preemptible_tcs = 0;
+	} else {
+		memcpy(&p_mqprio->qopt, qopt, sizeof(*qopt));
+		iet->preemptible_tcs = mqprio->preemptible_tcs;
+	}
+	mutex_unlock(&iet->fpe_lock);
+
+	netdev_dbg(ndev, "dev->num_tc %u dev->real_num_tx_queues %u\n",
+		   ndev->num_tc, ndev->real_num_tx_queues);
+
+	ret = icssg_iet_change_preemptible_tcs(emac);
+	if (ret) {
+		mutex_lock(&iet->fpe_lock);
+		iet->preemptible_tcs = 0;
+		memset(&p_mqprio->qopt, 0, sizeof(p_mqprio->qopt));
+		mutex_unlock(&iet->fpe_lock);
+		netdev_reset_tc(ndev);
+	}
+	return ret;
+}
+
+int icssg_qos_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type,
+			   void *type_data)
+{
+	switch (type) {
+	case TC_QUERY_CAPS:
+		return emac_tc_query_caps(ndev, type_data);
+	case TC_SETUP_QDISC_MQPRIO:
+		return emac_tc_setup_mqprio(ndev, type_data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+EXPORT_SYMBOL_GPL(icssg_qos_ndo_setup_tc);
+
+void icssg_qos_link_state_update(struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	int ret;
+
+	if (!READ_ONCE(emac->link)) {
+		void __iomem *config = emac->dram.va + ICSSG_CONFIG_OFFSET;
+
+		/* Clear FPE active state on link-down so get_mm() reports
+		 * accurate tx_active and verify_status while link is down.
+		 * Also zero the FW preemption registers to prevent divergence
+		 * if a concurrent enable was interrupted by link-down.
+		 */
+		mutex_lock(&iet->fpe_lock);
+		writeb(0, config + PRE_EMPTION_ENABLE_TX);
+		writeb(0, config + PRE_EMPTION_ENABLE_VERIFY);
+		iet->fpe_active = false;
+		iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
+		icssg_iet_set_preempt_mask(emac);
+		mutex_unlock(&iet->fpe_lock);
+		return;
+	}
+
+	ret = icssg_iet_change_preemptible_tcs(emac);
+	if (ret)
+		netdev_dbg(ndev, "IET FPE %s failed\n",
+			   str_enable_disable(iet->fpe_enabled));
+}
+EXPORT_SYMBOL_GPL(icssg_qos_link_state_update);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_qos.h b/drivers/net/ethernet/ti/icssg/icssg_qos.h
new file mode 100644
index 0000000000000..0a375c125f4b8
--- /dev/null
+++ b/drivers/net/ethernet/ti/icssg/icssg_qos.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2023 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#ifndef __NET_TI_ICSSG_QOS_H
+#define __NET_TI_ICSSG_QOS_H
+
+#include <linux/atomic.h>
+#include <linux/netdevice.h>
+#include <net/pkt_sched.h>
+
+#define ICSSG_MAX_TC_QUEUES			8
+#define ICSSG_EXPRESS_Q_MASK_ALL		0xFF
+#define ICSSG_IET_MAX_VERIFY_TIME		128
+#define ICSSG_IET_MIN_VERIFY_TIME		1
+#define ICSSG_IET_VERIFY_ATTEMPTS		3
+
+/**
+ * enum icssg_ietfpe_verify_states - status of MM Verify returned by firmware
+ * @ICSSG_IETFPE_STATE_UNKNOWN:
+ *	verification status is unknown
+ * @ICSSG_IETFPE_STATE_INITIAL:
+ *	Firmware returns this if verify state diagram is idle
+ * @ICSSG_IETFPE_STATE_VERIFYING:
+ *	Firmware returns this if verification is ongoing
+ * @ICSSG_IETFPE_STATE_SUCCEEDED:
+ *	Firmware returns this if verify state diagram completes verification
+ * @ICSSG_IETFPE_STATE_FAILED:
+ *	Firmware returns this if verify state diagram fails during verification
+ * @ICSSG_IETFPE_STATE_DISABLED:
+ *	verification is disabled by the driver
+ */
+enum icssg_ietfpe_verify_states {
+	ICSSG_IETFPE_STATE_UNKNOWN = 0,
+	ICSSG_IETFPE_STATE_INITIAL,
+	ICSSG_IETFPE_STATE_VERIFYING,
+	ICSSG_IETFPE_STATE_SUCCEEDED,
+	ICSSG_IETFPE_STATE_FAILED,
+	ICSSG_IETFPE_STATE_DISABLED
+};
+
+struct prueth_qos_mqprio {
+	struct tc_mqprio_qopt qopt;
+};
+
+struct prueth_qos_iet {
+	bool fpe_enabled;
+	bool mac_verify_configure;
+	u32 tx_min_frag_size;
+	u32 verify_time_ms;
+	bool fpe_active;
+	enum icssg_ietfpe_verify_states verify_status;
+	/* fpe mutex protects all FPE operations for synchronization */
+	struct mutex fpe_lock;
+	u8 preemptible_tcs;
+};
+
+struct prueth_qos {
+	struct prueth_qos_iet iet;
+	struct prueth_qos_mqprio mqprio;
+};
+
+void icssg_qos_init(struct net_device *ndev);
+void icssg_qos_exit(struct net_device *ndev);
+void icssg_qos_link_state_update(struct net_device *ndev);
+int icssg_qos_ndo_setup_tc(struct net_device *ndev, enum tc_setup_type type,
+			   void *type_data);
+int icssg_config_ietfpe(struct net_device *ndev, bool enable);
+#endif /* __NET_TI_ICSSG_QOS_H */
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v9 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge
  2026-11-21 14:46 [PATCH net-next v9 0/2] Add Frame Preemption MAC Merge support for ICSSG Meghana Malladi
  2026-11-21 14:46 ` [PATCH net-next v9 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
@ 2026-11-21 14:46 ` Meghana Malladi
  2026-11-25 15:08   ` netdev-bot+sashiko
  1 sibling, 1 reply; 5+ messages in thread
From: Meghana Malladi @ 2026-11-21 14:46 UTC (permalink / raw)
  To: marco.crivellari, haokexin, kees+treewide, laixiangwu, m-malladi,
	arnd, horms, basharath, parvathi, vladimir.oltean, rogerq,
	danishanwar, pabeni, kuba, edumazet, davem, andrew+netdev
  Cc: linux-arm-kernel, netdev, linux-kernel, srk, Vignesh Raghavendra

From: MD Danish Anwar <danishanwar@ti.com>

Adds .get_mm(), .set_mm() and .get_mm_stats() to the icssg ethtool ops,
along with new PA stats registers for the preemption counters. Also
moves the stat table sizes to ARRAY_SIZE() so the counts stay in sync
with the tables automatically.

emac_set_mm() programs all config fields into hardware before invoking
icssg_config_ietfpe(). On failure the fallback path in
icssg_config_ietfpe() already disables TX preemption in hardware, so
only fpe_enabled is forced off; the other fields (tx_min_frag_size,
verify_time_ms, mac_verify_configure) are kept as programmed to keep
driver and hardware state consistent.

tx_min_frag_size is validated against the four addFragSize-representable
values (60/124/188/252) before being programmed, since the firmware
requires the fragment size including FCS to be a multiple of 64 bytes.

verify_status is initialized to ICSSG_IETFPE_STATE_DISABLED in
icssg_qos_init() so that get_mm() reports DISABLED rather than UNKNOWN
on a freshly probed interface.

icssg_stats.h is made self-contained by directly including linux/ethtool.h,
linux/stddef.h, and icssg_switch_map.h, which it uses but previously
relied on icssg_prueth.h to pull in transitively.

Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Signed-off-by: Meghana Malladi <m-malladi@ti.com>
---

v9-v8 changelog:
Sashiko comments addressed:
  - Fix emac_set_mm() error path: on icssg_config_ietfpe() failure
    only force fpe_enabled = false to match hardware state (TX preempt off);
    retain other config fields as already programmed in HW registers — prevents
    silent re-enable on next link event and fixes ethnl_set_mm() retry becoming a no-op                                   
  - Add icssg_qos_validate_tx_min_frag_size(): reject non-addFragSize-representable values
    (only 60/124/188/252 valid) with extack before touching any state
  - Initialise iet->verify_status = ICSSG_IETFPE_STATE_DISABLED in icssg_qos_init()
    so fresh interface reports DISABLED not UNKNOWN                                      
  - Make icssg_stats.h self-contained                                                         
  - Mutex lifecycle asymmetry on SR1: already fixed in patch 1

Sashiko commens skipped:
  - Pre-existing stats readers without stats_lock: pre-existing issue, not introduced by this 
  series — will be tracked separately                                                                                                                                               
  - emac_get_stat_by_name() return type int → will be posted separately as bug fix

 drivers/net/ethernet/ti/icssg/icssg_ethtool.c | 127 +++++++++++++++++-
 drivers/net/ethernet/ti/icssg/icssg_prueth.h  |  11 +-
 drivers/net/ethernet/ti/icssg/icssg_qos.c     |   1 +
 drivers/net/ethernet/ti/icssg/icssg_qos.h     |  30 +++++
 drivers/net/ethernet/ti/icssg/icssg_stats.h   |  86 +++++++-----
 .../net/ethernet/ti/icssg/icssg_switch_map.h  |   5 +
 6 files changed, 217 insertions(+), 43 deletions(-)

diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
index b715af21d23ac..26892b603e1db 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
@@ -74,7 +74,8 @@ static int emac_get_sset_count(struct net_device *ndev, int stringset)
 		if (emac->prueth->pa_stats)
 			return ICSSG_NUM_ETHTOOL_STATS;
 		else
-			return ICSSG_NUM_ETHTOOL_STATS - ICSSG_NUM_PA_STATS;
+			return ICSSG_NUM_ETHTOOL_STATS -
+			       (ICSSG_NUM_PA_STATS - ICSSG_NUM_PA_STANDARD_STATS);
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -93,7 +94,8 @@ static void emac_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 				ethtool_puts(&p, icssg_all_miig_stats[i].name);
 		if (emac->prueth->pa_stats)
 			for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++)
-				ethtool_puts(&p, icssg_all_pa_stats[i].name);
+				if (!icssg_all_pa_stats[i].standard_stats)
+					ethtool_puts(&p, icssg_all_pa_stats[i].name);
 		break;
 	default:
 		break;
@@ -114,7 +116,8 @@ static void emac_get_ethtool_stats(struct net_device *ndev,
 
 	if (emac->prueth->pa_stats)
 		for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++)
-			*(data++) = emac->pa_stats[i];
+			if (!icssg_all_pa_stats[i].standard_stats)
+				*(data++) = emac->pa_stats[i];
 }
 
 static int emac_get_ts_info(struct net_device *ndev,
@@ -294,6 +297,121 @@ static int emac_set_per_queue_coalesce(struct net_device *ndev, u32 queue,
 	return 0;
 }
 
+static int emac_get_mm(struct net_device *ndev, struct ethtool_mm_state *state)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	enum icssg_ietfpe_verify_states verify_status;
+
+	if (emac->is_sr1)
+		return -EOPNOTSUPP;
+
+	mutex_lock(&iet->fpe_lock);
+	state->tx_enabled = iet->fpe_enabled;
+	state->tx_min_frag_size = iet->tx_min_frag_size;
+	state->verify_enabled = iet->mac_verify_configure;
+	state->verify_time = iet->verify_time_ms;
+	state->tx_active = iet->fpe_active;
+	verify_status = iet->verify_status;
+	mutex_unlock(&iet->fpe_lock);
+
+	state->rx_min_frag_size = ETH_ZLEN;
+	state->pmac_enabled = true;
+
+	switch (verify_status) {
+	case ICSSG_IETFPE_STATE_DISABLED:
+		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
+		break;
+	case ICSSG_IETFPE_STATE_INITIAL:
+		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_INITIAL;
+		break;
+	case ICSSG_IETFPE_STATE_VERIFYING:
+		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING;
+		break;
+	case ICSSG_IETFPE_STATE_SUCCEEDED:
+		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED;
+		break;
+	case ICSSG_IETFPE_STATE_FAILED:
+		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
+		break;
+	default:
+		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_UNKNOWN;
+		break;
+	}
+
+	/* 802.3-2018 clause 30.14.1.6, says that the aMACMergeVerifyTime
+	 * variable has a range between 1 and 128 ms inclusive. Limit to that.
+	 */
+	state->max_verify_time = ETHTOOL_MM_MAX_VERIFY_TIME_MS;
+
+	return 0;
+}
+
+static int emac_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg,
+		       struct netlink_ext_ack *extack)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_qos_iet *iet = &emac->qos.iet;
+	int err;
+
+	if (emac->is_sr1)
+		return -EOPNOTSUPP;
+
+	if (!cfg->pmac_enabled) {
+		NL_SET_ERR_MSG_MOD(extack, "preemptible MAC is always enabled");
+		return -EOPNOTSUPP;
+	}
+
+	err = icssg_qos_validate_tx_min_frag_size(cfg->tx_min_frag_size, extack);
+	if (err)
+		return err;
+
+	mutex_lock(&iet->fpe_lock);
+	iet->verify_time_ms = cfg->verify_time;
+	iet->tx_min_frag_size = cfg->tx_min_frag_size;
+	iet->fpe_enabled = cfg->tx_enabled;
+	iet->mac_verify_configure = cfg->verify_enabled;
+	err = icssg_config_ietfpe(ndev, cfg->tx_enabled);
+	if (err) {
+		/* icssg_config_ietfpe fallback disabled TX preemption in HW.
+		 * New config values are already programmed in HW registers,
+		 * so keep them. Only force fpe_enabled off to match HW state
+		 * and prevent silent re-enable on the next link event.
+		 */
+		iet->fpe_enabled = false;
+	}
+	mutex_unlock(&iet->fpe_lock);
+
+	return err;
+}
+
+static void emac_get_mm_stats(struct net_device *ndev,
+			      struct ethtool_mm_stats *s)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+
+	if (emac->is_sr1)
+		return;
+
+	if (!emac->prueth->pa_stats)
+		return;
+
+	emac_update_hardware_stats(emac);
+
+	/* Hold stats_lock to prevent icssg_stats_work_handler from updating
+	 * pa_stats[] between reads, which could yield a torn u64 value on
+	 * 32-bit architectures.
+	 */
+	spin_lock(&emac->prueth->stats_lock);
+	/* MACMergeHoldCount stats is not tracked by the firmware */
+	s->MACMergeFrameAssOkCount = emac_get_stat_by_name(emac, "FW_PREEMPT_ASSEMBLY_OK");
+	s->MACMergeFrameAssErrorCount = emac_get_stat_by_name(emac, "FW_PREEMPT_ASSEMBLY_ERR");
+	s->MACMergeFragCountRx = emac_get_stat_by_name(emac, "FW_PREEMPT_FRAG_CNT_RX");
+	s->MACMergeFragCountTx = emac_get_stat_by_name(emac, "FW_PREEMPT_FRAG_CNT_TX");
+	s->MACMergeFrameSmdErrorCount = emac_get_stat_by_name(emac, "FW_PREEMPT_BAD_FRAG");
+	spin_unlock(&emac->prueth->stats_lock);
+}
+
 const struct ethtool_ops icssg_ethtool_ops = {
 	.get_drvinfo = emac_get_drvinfo,
 	.get_msglevel = emac_get_msglevel,
@@ -317,5 +435,8 @@ const struct ethtool_ops icssg_ethtool_ops = {
 	.set_eee = emac_set_eee,
 	.nway_reset = emac_nway_reset,
 	.get_rmon_stats = emac_get_rmon_stats,
+	.get_mm = emac_get_mm,
+	.set_mm = emac_set_mm,
+	.get_mm_stats = emac_get_mm_stats,
 };
 EXPORT_SYMBOL_GPL(icssg_ethtool_ops);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
index f73b8f5fca956..549489a631cc3 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -45,6 +45,7 @@
 #include "icss_iep.h"
 #include "icssg_switch_map.h"
 #include "icssg_qos.h"
+#include "icssg_stats.h"
 
 #define PRUETH_MAX_MTU		(2000 - ETH_HLEN - ETH_FCS_LEN)
 #define PRUETH_MIN_PKT_SIZE	(VLAN_ETH_ZLEN)
@@ -58,12 +59,16 @@
 
 #define ICSSG_MAX_RFLOWS	8	/* per slice */
 
-#define ICSSG_NUM_PA_STATS	32
-#define ICSSG_NUM_MIIG_STATS	60
+#define ICSSG_NUM_PA_STATS	ARRAY_SIZE(icssg_all_pa_stats)
+#define ICSSG_NUM_MIIG_STATS	ARRAY_SIZE(icssg_all_miig_stats)
 /* Number of ICSSG related stats */
 #define ICSSG_NUM_STATS (ICSSG_NUM_MIIG_STATS + ICSSG_NUM_PA_STATS)
+/* MIIG stats with standard uAPI equivalents (excluded from ethtool -S) */
 #define ICSSG_NUM_STANDARD_STATS 31
-#define ICSSG_NUM_ETHTOOL_STATS (ICSSG_NUM_STATS - ICSSG_NUM_STANDARD_STATS)
+/* PA stats with standard uAPI equivalents, exposed via get_mm_stats only */
+#define ICSSG_NUM_PA_STANDARD_STATS 5
+#define ICSSG_NUM_ETHTOOL_STATS (ICSSG_NUM_STATS - ICSSG_NUM_STANDARD_STATS - \
+				 ICSSG_NUM_PA_STANDARD_STATS)
 
 #define IEP_DEFAULT_CYCLE_TIME_NS	1000000	/* 1 ms */
 
diff --git a/drivers/net/ethernet/ti/icssg/icssg_qos.c b/drivers/net/ethernet/ti/icssg/icssg_qos.c
index 55ddf7669530c..cb6842d296ce0 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_qos.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_qos.c
@@ -177,6 +177,7 @@ void icssg_qos_init(struct net_device *ndev)
 	/* Set default values to prevent garbage values during .get_mm() */
 	iet->verify_time_ms = ICSSG_IET_MAX_VERIFY_TIME;
 	iet->tx_min_frag_size = ETH_ZLEN;
+	iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
 }
 EXPORT_SYMBOL_GPL(icssg_qos_init);
 
diff --git a/drivers/net/ethernet/ti/icssg/icssg_qos.h b/drivers/net/ethernet/ti/icssg/icssg_qos.h
index 0a375c125f4b8..bb0d6e2950dfc 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_qos.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_qos.h
@@ -14,6 +14,7 @@
 #define ICSSG_IET_MAX_VERIFY_TIME		128
 #define ICSSG_IET_MIN_VERIFY_TIME		1
 #define ICSSG_IET_VERIFY_ATTEMPTS		3
+#define ICSSG_IET_MAX_TX_MIN_FRAG_SIZE		252
 
 /**
  * enum icssg_ietfpe_verify_states - status of MM Verify returned by firmware
@@ -60,6 +61,35 @@ struct prueth_qos {
 	struct prueth_qos_mqprio mqprio;
 };
 
+static inline int icssg_qos_validate_tx_min_frag_size(u32 min_frag_size,
+						      struct netlink_ext_ack *extack)
+{
+	/* Firmware takes min_frag_size including FCS length.
+	 * The firmware requires the fragment size (including FCS) to be
+	 * a multiple of 64 bytes. Since 64 bytes = ETH_ZLEN + ETH_FCS_LEN,
+	 * valid user-facing values are: 60, 124, 188, 252.
+	 */
+	if (min_frag_size < ETH_ZLEN) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "tx_min_frag_size must be at least 60 bytes");
+		return -EINVAL;
+	}
+
+	if (min_frag_size > ICSSG_IET_MAX_TX_MIN_FRAG_SIZE) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "tx_min_frag_size must not exceed 252 bytes");
+		return -EINVAL;
+	}
+
+	if ((min_frag_size + ETH_FCS_LEN) % (ETH_ZLEN + ETH_FCS_LEN)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "tx_min_frag_size must be a multiple of 64 bytes minus 4");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 void icssg_qos_init(struct net_device *ndev);
 void icssg_qos_exit(struct net_device *ndev);
 void icssg_qos_link_state_update(struct net_device *ndev);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.h b/drivers/net/ethernet/ti/icssg/icssg_stats.h
index 5ec0b38e0c67d..4e73ee04cb1cd 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_stats.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_stats.h
@@ -8,7 +8,9 @@
 #ifndef __NET_TI_ICSSG_STATS_H
 #define __NET_TI_ICSSG_STATS_H
 
-#include "icssg_prueth.h"
+#include <linux/ethtool.h>
+#include <linux/stddef.h>
+#include "icssg_switch_map.h"
 
 #define STATS_TIME_LIMIT_1G_MS    25000    /* 25 seconds @ 1G */
 
@@ -155,50 +157,60 @@ static const struct icssg_miig_stats icssg_all_miig_stats[] = {
 	ICSSG_MIIG_STATS(tx_bytes, true),
 };
 
-#define ICSSG_PA_STATS(field)	\
-{				\
-	#field,			\
-	field,			\
+#define ICSSG_PA_STATS(field, std)	\
+{					\
+	#field,				\
+	field,				\
+	std,				\
 }
 
 struct icssg_pa_stats {
 	char name[ETH_GSTRING_LEN];
 	u32 offset;
+	bool standard_stats;
 };
 
 static const struct icssg_pa_stats icssg_all_pa_stats[] = {
-	ICSSG_PA_STATS(FW_RTU_PKT_DROP),
-	ICSSG_PA_STATS(FW_Q0_OVERFLOW),
-	ICSSG_PA_STATS(FW_Q1_OVERFLOW),
-	ICSSG_PA_STATS(FW_Q2_OVERFLOW),
-	ICSSG_PA_STATS(FW_Q3_OVERFLOW),
-	ICSSG_PA_STATS(FW_Q4_OVERFLOW),
-	ICSSG_PA_STATS(FW_Q5_OVERFLOW),
-	ICSSG_PA_STATS(FW_Q6_OVERFLOW),
-	ICSSG_PA_STATS(FW_Q7_OVERFLOW),
-	ICSSG_PA_STATS(FW_DROPPED_PKT),
-	ICSSG_PA_STATS(FW_RX_ERROR),
-	ICSSG_PA_STATS(FW_RX_DS_INVALID),
-	ICSSG_PA_STATS(FW_TX_DROPPED_PACKET),
-	ICSSG_PA_STATS(FW_TX_TS_DROPPED_PACKET),
-	ICSSG_PA_STATS(FW_INF_PORT_DISABLED),
-	ICSSG_PA_STATS(FW_INF_SAV),
-	ICSSG_PA_STATS(FW_INF_SA_DL),
-	ICSSG_PA_STATS(FW_INF_PORT_BLOCKED),
-	ICSSG_PA_STATS(FW_INF_DROP_TAGGED),
-	ICSSG_PA_STATS(FW_INF_DROP_PRIOTAGGED),
-	ICSSG_PA_STATS(FW_INF_DROP_NOTAG),
-	ICSSG_PA_STATS(FW_INF_DROP_NOTMEMBER),
-	ICSSG_PA_STATS(FW_RX_EOF_SHORT_FRMERR),
-	ICSSG_PA_STATS(FW_RX_B0_DROP_EARLY_EOF),
-	ICSSG_PA_STATS(FW_TX_JUMBO_FRM_CUTOFF),
-	ICSSG_PA_STATS(FW_RX_EXP_FRAG_Q_DROP),
-	ICSSG_PA_STATS(FW_RX_FIFO_OVERRUN),
-	ICSSG_PA_STATS(FW_CUT_THR_PKT),
-	ICSSG_PA_STATS(FW_HOST_RX_PKT_CNT),
-	ICSSG_PA_STATS(FW_HOST_TX_PKT_CNT),
-	ICSSG_PA_STATS(FW_HOST_EGRESS_Q_PRE_OVERFLOW),
-	ICSSG_PA_STATS(FW_HOST_EGRESS_Q_EXP_OVERFLOW),
+	ICSSG_PA_STATS(FW_RTU_PKT_DROP, false),
+	ICSSG_PA_STATS(FW_Q0_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_Q1_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_Q2_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_Q3_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_Q4_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_Q5_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_Q6_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_Q7_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_DROPPED_PKT, false),
+	ICSSG_PA_STATS(FW_RX_ERROR, false),
+	ICSSG_PA_STATS(FW_RX_DS_INVALID, false),
+	ICSSG_PA_STATS(FW_TX_DROPPED_PACKET, false),
+	ICSSG_PA_STATS(FW_TX_TS_DROPPED_PACKET, false),
+	ICSSG_PA_STATS(FW_INF_PORT_DISABLED, false),
+	ICSSG_PA_STATS(FW_INF_SAV, false),
+	ICSSG_PA_STATS(FW_INF_SA_DL, false),
+	ICSSG_PA_STATS(FW_INF_PORT_BLOCKED, false),
+	ICSSG_PA_STATS(FW_INF_DROP_TAGGED, false),
+	ICSSG_PA_STATS(FW_INF_DROP_PRIOTAGGED, false),
+	ICSSG_PA_STATS(FW_INF_DROP_NOTAG, false),
+	ICSSG_PA_STATS(FW_INF_DROP_NOTMEMBER, false),
+	/* MAC Merge counters: exposed via .get_mm_stats standard uAPI,
+	 * not duplicated in the private ethtool -S table.
+	 */
+	ICSSG_PA_STATS(FW_PREEMPT_BAD_FRAG, true),
+	ICSSG_PA_STATS(FW_PREEMPT_ASSEMBLY_ERR, true),
+	ICSSG_PA_STATS(FW_PREEMPT_FRAG_CNT_TX, true),
+	ICSSG_PA_STATS(FW_PREEMPT_ASSEMBLY_OK, true),
+	ICSSG_PA_STATS(FW_PREEMPT_FRAG_CNT_RX, true),
+	ICSSG_PA_STATS(FW_RX_EOF_SHORT_FRMERR, false),
+	ICSSG_PA_STATS(FW_RX_B0_DROP_EARLY_EOF, false),
+	ICSSG_PA_STATS(FW_TX_JUMBO_FRM_CUTOFF, false),
+	ICSSG_PA_STATS(FW_RX_EXP_FRAG_Q_DROP, false),
+	ICSSG_PA_STATS(FW_RX_FIFO_OVERRUN, false),
+	ICSSG_PA_STATS(FW_CUT_THR_PKT, false),
+	ICSSG_PA_STATS(FW_HOST_RX_PKT_CNT, false),
+	ICSSG_PA_STATS(FW_HOST_TX_PKT_CNT, false),
+	ICSSG_PA_STATS(FW_HOST_EGRESS_Q_PRE_OVERFLOW, false),
+	ICSSG_PA_STATS(FW_HOST_EGRESS_Q_EXP_OVERFLOW, false),
 };
 
 #endif /* __NET_TI_ICSSG_STATS_H */
diff --git a/drivers/net/ethernet/ti/icssg/icssg_switch_map.h b/drivers/net/ethernet/ti/icssg/icssg_switch_map.h
index 7e053b8af3ece..855fd4ed0b3f6 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_switch_map.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_switch_map.h
@@ -256,6 +256,11 @@
 #define FW_INF_DROP_PRIOTAGGED		0x0148
 #define FW_INF_DROP_NOTAG		0x0150
 #define FW_INF_DROP_NOTMEMBER		0x0158
+#define FW_PREEMPT_BAD_FRAG		0x0160
+#define FW_PREEMPT_ASSEMBLY_ERR		0x0168
+#define FW_PREEMPT_FRAG_CNT_TX		0x0170
+#define FW_PREEMPT_ASSEMBLY_OK		0x0178
+#define FW_PREEMPT_FRAG_CNT_RX		0x0180
 #define FW_RX_EOF_SHORT_FRMERR		0x0188
 #define FW_RX_B0_DROP_EARLY_EOF		0x0190
 #define FW_TX_JUMBO_FRM_CUTOFF		0x0198
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v9 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support
  2026-11-21 14:46 ` [PATCH net-next v9 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
@ 2026-11-25 15:08   ` netdev-bot+sashiko
  0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 15:08 UTC (permalink / raw)
  To: m-malladi
  Cc: marco.crivellari, haokexin, kees+treewide, laixiangwu, arnd,
	horms, basharath, parvathi, vladimir.oltean, rogerq, danishanwar,
	pabeni, kuba, edumazet, davem, andrew+netdev, linux-arm-kernel,
	netdev, linux-kernel, srk, vigneshr

Thank you for your contribution! Sashiko AI review found 11 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 5 · Low: 6

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] After a firmware restart while the link is up
  (prueth_emac_restart(), which runs when ports join or leave a bridge…
- [Medium] emac_tc_setup_mqprio() always finishes by calling
  icssg_iet_change_preemptible_tcs().
- [Medium] icssg_config_ietfpe() decides whether to program FPE by
  reading emac->link (`if (!READ_ONCE(emac->link)) return 0;`) while…
- [Medium] Several things here depend on firmware state the driver never
  resets.
- [Medium] FPE TX is turned on by the R30 command
  ICSSG_EMAC_PORT_PREMPT_TX_ENABLE; the driver's own comment says the…
- [Low] emac_tc_setup_mqprio() splits a single logical update into three
  separate fpe_lock critical sections.
- [Low] On every link-down, icssg_qos_link_state_update() writes the
  firmware config bytes PRE_EMPTION_ENABLE_TX=0 and…
- [Low] emac_tc_setup_mqprio() reports user-triggerable configuration
  errors with netdev_err() instead of NL_SET_ERR_MSG_MOD(mqprio->extack,…
- [Low] Two changes unrelated to FPE are folded into the patch without
  mention in the commit message.
- [Low] The register-map comment for EXPRESS_PRE_EMPTIVE_Q_MAP in
  icssg_switch_map.h still reads "For marking Packet as priority/express…
- [Low] icssg_qos_link_state_update() reads iet->fpe_enabled for its
  debug message after icssg_iet_change_preemptible_tcs() has dropped…

--

net: ti: icssg-prueth: Add Frame Preemption MAC Merge support

This commit adds a QoS submodule to the ICSSG driver. It configures IET
Frame Preemption in firmware, including the verify state machine and the
express/preemptible queue mask. It also hooks mqprio offload through
ndo_setup_tc and re-applies FPE state on link up/down from
emac_adjust_link(). The ethtool MAC Merge ops are wired up in the
following patch.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 9bb67e185a3ea..d8431132c34b0 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c

[ ... ]

> @@ -392,6 +392,8 @@ static void emac_adjust_link(struct net_device *ndev)
>  		} else {
>  			icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
>  		}
> +
> +		icssg_qos_link_state_update(ndev);
>  	}

[Severity: Medium]
Is FPE silently lost after a firmware restart while the link is up?

prueth_emac_restart() runs from icssg_change_mode() when ports join or
leave a bridge or HSR. It stops all cores and then calls
prueth_emac_common_start(). That runs icssg_config(), whose
memset_io(config, 0, TAS_GATE_MASK_LIST0) clears
EXPRESS_PRE_EMPTIVE_Q_MASK and Q_MAP. It then sets emac->link to 0 and
calls emac_adjust_link() before prueth_emac_start() has booted the
firmware.

With phydev->link set, the new hook then runs against halted firmware:

prueth_emac_common_start()
  emac_adjust_link()
    icssg_qos_link_state_update()
      icssg_iet_change_preemptible_tcs()
        icssg_config_ietfpe(ndev, true)
          icssg_set_port_state(emac, ICSSG_EMAC_PORT_PREMPT_TX_ENABLE)

The halted firmware can't acknowledge the R30 command, so the call times
out after 10 ms. The fallback path then clears ENABLE_TX/ENABLE_VERIFY,
sets fpe_active = false and resets the mask to all-express. The
unconsumed PREMPT command also stays in the mailbox.

Once the firmware is running, prueth_emac_restart() only re-sends
PORT_FORWARD:

	/* Enable forwarding for both PRUeth ports */
	ret = icssg_set_port_state(emac0, ICSSG_EMAC_PORT_FORWARD);
	ret |= icssg_set_port_state(emac1, ICSSG_EMAC_PORT_FORWARD);

emac->link is already 1, so phylib reports no change and
icssg_qos_link_state_update() is not called again.

Would preemption and the preemptible queue mapping then stay off until
the next link flap? Meanwhile fpe_enabled stays true, so get_mm() (added
in the next patch, "Add ethtool ops for Frame Preemption MAC Merge")
would report tx_enabled=1, tx_active=0. This doesn't appear to be fixed
later in the series either.

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
> index df93d15c5b786..f73b8f5fca956 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
> @@ -44,10 +44,11 @@
>  #include "icssg_config.h"
>  #include "icss_iep.h"
>  #include "icssg_switch_map.h"
> +#include "icssg_qos.h"
>  
> -#define PRUETH_MAX_MTU          (2000 - ETH_HLEN - ETH_FCS_LEN)
> -#define PRUETH_MIN_PKT_SIZE     (VLAN_ETH_ZLEN)
> -#define PRUETH_MAX_PKT_SIZE     (PRUETH_MAX_MTU + ETH_HLEN + ETH_FCS_LEN)
> +#define PRUETH_MAX_MTU		(2000 - ETH_HLEN - ETH_FCS_LEN)
> +#define PRUETH_MIN_PKT_SIZE	(VLAN_ETH_ZLEN)
> +#define PRUETH_MAX_PKT_SIZE	(PRUETH_MAX_MTU + ETH_HLEN + ETH_FCS_LEN)

[Severity: Low]
This isn't a bug, but two changes here aren't related to FPE and aren't
mentioned in the commit message: the whitespace-only change to these
three defines, and the move of enum icssg_ietfpe_verify_states from
icssg_config.h to icssg_qos.h. Could they be split out, or at least
noted in the commit message?

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_qos.c b/drivers/net/ethernet/ti/icssg/icssg_qos.c
> new file mode 100644
> index 0000000000000..55ddf7669530c
> --- /dev/null
> +++ b/drivers/net/ethernet/ti/icssg/icssg_qos.c
> @@ -0,0 +1,327 @@

[ ... ]

> +static void icssg_iet_set_preempt_mask(struct prueth_emac *emac)
> +{

[ ... ]

> +		for (tc = 0; tc < num_tc; tc++) {
> +			if (iet->preemptible_tcs & BIT(tc)) {
> +				for (i = qopt->offset[tc]; i < qopt->offset[tc] + qopt->count[tc]; i++) {
> +					writeb(BIT(4),
> +					       config + EXPRESS_PRE_EMPTIVE_Q_MAP + i);

[Severity: Low]
This isn't a bug, but the register map comment for this offset in
icssg_switch_map.h still says:

/* For marking Packet as priority/express (this feature is disabled) or
 * cut-through/S&F.
 */
#define EXPRESS_PRE_EMPTIVE_Q_MAP                          0x0034

This function now programs the region as a preemption map. It writes the
undocumented value BIT(4) for preemptible queues and writes 0 to all
ICSSG_MAX_TC_QUEUES entries on every reset. That reset would also clear
any cut-through/S&F encoding the comment says these bytes carry.

Could the comment be updated, and BIT(4) given a named constant?

> +					prempt_mask &= ~BIT(i);
> +				}
> +			}
> +		}
> +		writeb(prempt_mask, config + EXPRESS_PRE_EMPTIVE_Q_MASK);
> +		return;
> +	}
> +
> +reset_hw:
> +	/* Reset to default: all queues as express */
> +	for (i = 0; i < ICSSG_MAX_TC_QUEUES; i++)
> +		writeb(0, config + EXPRESS_PRE_EMPTIVE_Q_MAP + i);
> +	writeb(ICSSG_EXPRESS_Q_MASK_ALL, config + EXPRESS_PRE_EMPTIVE_Q_MASK);
> +}

[Severity: Low]
Is this reset meant to run on every link-down, whatever the FPE state?

The link-down branch of icssg_qos_link_state_update() always ends up
here. It doesn't check fpe_enabled, fpe_active or preemptible_tcs, and it
runs in every firmware mode (EMAC, switch, HSR/PRP).

icssg_config() leaves EXPRESS_PRE_EMPTIVE_Q_MASK at 0 after each firmware
start, and no init path programs it. So the byte reads 0 until the first
link-down and ICSSG_EXPRESS_Q_MASK_ALL afterwards, even when FPE is never
configured.

The commit message says link events are handled "based on fpe_enabled
and fpe_active flags". Would programming the default mask in
icssg_config(), or gating these writes on FPE state, keep it consistent?

> +
> +static int icssg_iet_verify_wait(struct prueth_emac *emac)
> +{

[ ... ]

> +	ret = readb_poll_timeout(config + PRE_EMPTION_VERIFY_STATUS,
> +				 status,
> +				 status == ICSSG_IETFPE_STATE_SUCCEEDED ||
> +				 status == ICSSG_IETFPE_STATE_FAILED,
> +				 delay_us,
> +				 timeout_us);

[Severity: Medium]
Can the first sample here be a stale SUCCEEDED left over from an earlier
session?

The firmware writes PRE_EMPTION_VERIFY_STATUS and PRE_EMPTION_ACTIVE_TX,
and the driver never resets them. They sit above TAS_GATE_MASK_LIST0, so
the memset_io(config, 0, TAS_GATE_MASK_LIST0) in icssg_config() doesn't
clear them. The link-down path in icssg_qos_link_state_update() only
clears ENABLE_TX/ENABLE_VERIFY and the software verify_status.

readb_poll_timeout() checks the condition on its first read, before any
sleep. A leftover SUCCEEDED would satisfy the poll at once, unless the
firmware has already overwritten VERIFY_STATUS by the time it
acknowledges PREMPT_TX_ENABLE.

icssg_config_ietfpe() would then read a possibly stale ACTIVE_TX, set
fpe_active = true and program the preemptible queues. That would happen
before verify has finished on the new link, possibly with a different
partner.

The same applies when FPE is re-enabled while already active. It also
applies to the no-verify path, which reads ACTIVE_TX once after
usleep_range(100, 200).

Does the firmware guarantee these bytes are cleared before the R30
acknowledgement, or should the driver reset them before re-arming?

[ ... ]

> +int icssg_config_ietfpe(struct net_device *ndev, bool enable)
> +{

[ ... ]

> +	lockdep_assert_held(&iet->fpe_lock);
> +
> +	if (!READ_ONCE(emac->link)) {
> +		netdev_dbg(ndev, "cannot change IET/FPE state when interface is down\n");
> +		return 0;
> +	}

[Severity: Medium]
Is this check actually serialized against link changes?

emac_adjust_link() writes emac->link under phydev->lock from the phylib
state machine, not under fpe_lock. It also publishes the new value and
sends PORT_DISABLE/PORT_FORWARD before it takes fpe_lock inside
icssg_qos_link_state_update().

On link-down, something like this looks possible:

tc / set_mm path                     phylib (phydev->lock held)
mutex_lock(&iet->fpe_lock)
READ_ONCE(emac->link) == 1
                                     WRITE_ONCE(emac->link, 0)
                                     icssg_set_port_state(PORT_DISABLE)
                                     icssg_qos_link_state_update()
                                       mutex_lock(&iet->fpe_lock) blocks
icssg_set_port_state(PREMPT_TX_ENABLE)
icssg_iet_verify_wait()

The tc/set_mm request would fail and roll back. The PHY state machine
would also stall for up to 3 * verify_time_ms (about 384 ms). Without
verify, ACTIVE_TX could read 1 and set fpe_active = true, and the
link-down branch never sends PREMPT_TX_DISABLE to undo it.

On link-up, a caller that sees link == 1 could send PREMPT_TX_ENABLE and
start verify before emac_adjust_link() has configured speed/IPG and sent
PORT_FORWARD. That could make the request fail spuriously.

The commit message says fpe_lock prevents "races between ethtool config,
qdisc setup, and link events". Does that hold, given that the link state
being tested is protected by a different lock?

[ ... ]

> +static int emac_tc_setup_mqprio(struct net_device *ndev, void *type_data)
> +{

[ ... ]

> +	/* Validate parameters */
> +	if (qopt->num_tc > ICSSG_MAX_TC_QUEUES) {
> +		netdev_err(ndev, "Number of traffic classes (%u) exceeds hardware limit\n",
> +			   qopt->num_tc);
> +		return -EOPNOTSUPP;
> +	}
> +
> +	if (mqprio->flags & TC_MQPRIO_F_SHAPER) {
> +		netdev_err(ndev, "traffic shaping is not supported\n");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	if (mqprio->flags & (TC_MQPRIO_F_MIN_RATE | TC_MQPRIO_F_MAX_RATE)) {
> +		netdev_err(ndev, "per-queue rate limiting is not supported\n");
> +		return -EOPNOTSUPP;
> +	}

[Severity: Low]
Could these use NL_SET_ERR_MSG_MOD(mqprio->extack, ...) instead of
netdev_err()? Users can trigger these errors, so tc only sees a bare
-EOPNOTSUPP while the kernel log gets an error on every attempt.

[ ... ]

> +	ret = icssg_iet_change_preemptible_tcs(emac);
> +	if (ret) {
> +		mutex_lock(&iet->fpe_lock);
> +		iet->preemptible_tcs = 0;
> +		memset(&p_mqprio->qopt, 0, sizeof(p_mqprio->qopt));
> +		mutex_unlock(&iet->fpe_lock);
> +		netdev_reset_tc(ndev);
> +	}
> +	return ret;
> +}

[Severity: Medium]
Should every mqprio offload change re-run the full FPE handshake?

When fpe_enabled is true, icssg_iet_change_preemptible_tcs() calls
icssg_config_ietfpe(ndev, true). That re-sends PREMPT_TX_ENABLE and, with
mac_verify_configure set, polls verify for up to 3 * verify_time_ms (up
to 384 ms).

This happens even when preemptible_tcs == 0 and on qdisc teardown
(num_tc == 0). In those cases only the all-express mask needs
programming.

If the handshake fails (verify rejected, timeout, or ACTIVE_TX != 1), the
qdisc install fails here and the TC mapping is reset. A failure on the
link-up path leaves fpe_enabled true. So after a link flap to a partner
that doesn't support verify, would every later "tc qdisc add ... mqprio
hw 1" fail, even with no preemptible TCs?

Each successful mqprio change also re-runs the enable sequence, which
cycles TX preemption as a side effect.

[Severity: Low]
A related question about locking here. The publish, apply and rollback
steps each take fpe_lock separately, and the rollback only restores
software state.

Suppose a link-up runs icssg_qos_link_state_update() between the failed
icssg_iet_change_preemptible_tcs() and this rollback, and succeeds. Then
icssg_iet_set_preempt_mask() would program Q_MAP/Q_MASK from the qopt and
preemptible_tcs that are about to be rejected.

After the rollback the kernel has no mqprio offload and preemptible_tcs
is 0. Would the firmware still treat those queues as preemptible until
the next reconfiguration or link-down?

[ ... ]

> +void icssg_qos_link_state_update(struct net_device *ndev)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +	struct prueth_qos_iet *iet = &emac->qos.iet;
> +	int ret;
> +
> +	if (!READ_ONCE(emac->link)) {
> +		void __iomem *config = emac->dram.va + ICSSG_CONFIG_OFFSET;
> +
> +		/* Clear FPE active state on link-down so get_mm() reports
> +		 * accurate tx_active and verify_status while link is down.
> +		 * Also zero the FW preemption registers to prevent divergence
> +		 * if a concurrent enable was interrupted by link-down.
> +		 */
> +		mutex_lock(&iet->fpe_lock);
> +		writeb(0, config + PRE_EMPTION_ENABLE_TX);
> +		writeb(0, config + PRE_EMPTION_ENABLE_VERIFY);
> +		iet->fpe_active = false;
> +		iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
> +		icssg_iet_set_preempt_mask(emac);
> +		mutex_unlock(&iet->fpe_lock);
> +		return;
> +	}

[Severity: Medium]
Should this link-down teardown also send
ICSSG_EMAC_PORT_PREMPT_TX_DISABLE?

The R30 PREMPT_TX_ENABLE command turns FPE TX on, and the firmware is
still running at this point. This teardown only zeroes the DRAM bytes.

Two later paths also skip the disable command. First, if FPE is turned
off while the link is down (set_mm with tx_enabled=0 in the next patch,
or clearing preemptible_tcs via mqprio), icssg_config_ietfpe() returns 0
from its !emac->link check without touching the hardware. Second, on the
next link-up, icssg_iet_change_preemptible_tcs() returns early:

	if (!iet->fpe_enabled && !iet->preemptible_tcs) {
		mutex_unlock(&iet->fpe_lock);
		return 0;
	}

Would the last preemption command the firmware saw then stay
PREMPT_TX_ENABLE indefinitely, while the driver and get_mm() report FPE
as disabled? The answer depends on whether the firmware acts on the last
R30 command or on the PRE_EMPTION_ENABLE_TX byte, which can't be seen
from the driver.

The v9 changelog says the link-down clearing prevents HW/driver
divergence, but the command-level state still seems to diverge.

> +
> +	ret = icssg_iet_change_preemptible_tcs(emac);
> +	if (ret)
> +		netdev_dbg(ndev, "IET FPE %s failed\n",
> +			   str_enable_disable(iet->fpe_enabled));
> +}

[Severity: Low]
This is minor, but fpe_enabled is read here after
icssg_iet_change_preemptible_tcs() has dropped fpe_lock. Later in the
series, emac_set_mm() writes it under fpe_lock from the ethtool path.
Could KCSAN report this plain read? The message could also describe a
different operation than the one that failed.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121144618.180542-1-m-malladi%40ti.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v9 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge
  2026-11-21 14:46 ` [PATCH net-next v9 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge Meghana Malladi
@ 2026-11-25 15:08   ` netdev-bot+sashiko
  0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 15:08 UTC (permalink / raw)
  To: m-malladi
  Cc: marco.crivellari, haokexin, kees+treewide, laixiangwu, arnd,
	horms, basharath, parvathi, vladimir.oltean, rogerq, danishanwar,
	pabeni, kuba, edumazet, davem, andrew+netdev, linux-arm-kernel,
	netdev, linux-kernel, srk, vigneshr

Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] emac_get_mm_stats()
  (drivers/net/ethernet/ti/icssg/icssg_ethtool.c) fills the u64 fields…
- [Medium] The new .get_mm()/.set_mm() report MAC Merge state in a way
  that breaks the ethtool MM uAPI contract.
- [Medium] After a failed emac_set_mm() with verification enabled, the
  driver is left with iet->fpe_enabled=false and…
- [Medium] PRE_EMPTION_VERIFY_STATUS is firmware-owned DRAM.
- [Low] The commit message says "emac_set_mm() programs all config fields
  into hardware before invoking icssg_config_ietfpe()", and the comment…
- [Low] icssg_qos_validate_tx_min_frag_size() in
  drivers/net/ethernet/ti/icssg/icssg_qos.h re-implements the core…
- [Low] The commit message says that on failure 'the fallback path in
  icssg_config_ietfpe() already disables TX preemption in hardware', and…

--

net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge

This adds .get_mm(), .set_mm() and .get_mm_stats() to the icssg ethtool
ops, along with PA stats registers for the preemption counters. It also
moves the stat table sizes to ARRAY_SIZE(), validates tx_min_frag_size,
and initializes verify_status to the disabled state in icssg_qos_init().

> emac_set_mm() programs all config fields into hardware before invoking
> icssg_config_ietfpe(). On failure the fallback path in
> icssg_config_ietfpe() already disables TX preemption in hardware, so
> only fpe_enabled is forced off; the other fields (tx_min_frag_size,
> verify_time_ms, mac_verify_configure) are kept as programmed to keep
> driver and hardware state consistent.

[Severity: Low]
Is this description accurate? emac_set_mm() does not touch any registers
itself. It only assigns iet->verify_time_ms, tx_min_frag_size,
fpe_enabled and mac_verify_configure.

All register writes happen inside icssg_config_ietfpe(), and only when
the link is up:

	if (!READ_ONCE(emac->link)) {
		netdev_dbg(ndev, "cannot change IET/FPE state when interface is down\n");
		return 0;
	}

PRE_EMPTION_VERIFY_TIME is written only when enable &&
iet->mac_verify_configure. The fallback path then clears verify enable
again:

fallback:
	writeb(0, config + PRE_EMPTION_ENABLE_TX);
	writeb(0, config + PRE_EMPTION_ENABLE_VERIFY);

So after a failure, the retained mac_verify_configure no longer matches
hardware. The comment in the emac_set_mm() error branch ("New config
values are already programmed in HW registers") has the same problem.

Could the commit message and the comment describe what the error path
actually does? A failed set_mm returns an error but leaves the new values
visible via get_mm.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index b715af21d23ac..26892b603e1db 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c

[ ... ]

> @@ -294,6 +297,121 @@ static int emac_set_per_queue_coalesce(struct net_device *ndev, u32 queue,
>  	return 0;
>  }
>  
> +static int emac_get_mm(struct net_device *ndev, struct ethtool_mm_state *state)
> +{

[ ... ]

> +	mutex_lock(&iet->fpe_lock);
> +	state->tx_enabled = iet->fpe_enabled;
> +	state->tx_min_frag_size = iet->tx_min_frag_size;
> +	state->verify_enabled = iet->mac_verify_configure;
> +	state->verify_time = iet->verify_time_ms;
> +	state->tx_active = iet->fpe_active;
> +	verify_status = iet->verify_status;
> +	mutex_unlock(&iet->fpe_lock);

[ ... ]

> +	case ICSSG_IETFPE_STATE_FAILED:
> +		state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
> +		break;

[Severity: Medium]
Can emac_get_mm() ever reach this case, or the VERIFYING and INITIAL
cases?

When verification fails, icssg_iet_verify_wait() stores
ICSSG_IETFPE_STATE_FAILED in iet->verify_status. icssg_config_ietfpe()
then goes through disable_tx to fallback and overwrites it while
fpe_lock is still held:

disable_tx:
	icssg_set_port_state(emac, ICSSG_EMAC_PORT_PREMPT_TX_DISABLE);
fallback:
	...
	iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;

emac_get_mm() reads verify_status under the same fpe_lock, so it looks
like it can only see the disabled or succeeded states.

emac_set_mm() also forces fpe_enabled to false and keeps
mac_verify_configure set. After "ethtool --set-mm ethX verify-enabled on
tx-enabled on" against a partner that does not support preemption,
MM_GET would report verify-enabled on, verify status disabled,
tx-enabled off and tx-active off.

Documentation/networking/ethtool-netlink.rst says that when
ETHTOOL_A_MM_VERIFY_ENABLED is true, the verify status should report
something other than initial or disabled. It also describes tx-enabled
as the administrative state, which may be inactive if verification
failed, with tx-active carrying the operational state.

The link-up and mqprio paths (icssg_qos_link_state_update() and
emac_tc_setup_mqprio() calling icssg_iet_change_preemptible_tcs(), which
calls icssg_config_ietfpe()) hit the same failure but leave fpe_enabled
true. So the same hardware outcome is reported differently depending on
the path.

Should the failed status be kept for get_mm, and tx_enabled be left as
the admin state?

> +
> +	/* 802.3-2018 clause 30.14.1.6, says that the aMACMergeVerifyTime
> +	 * variable has a range between 1 and 128 ms inclusive. Limit to that.
> +	 */
> +	state->max_verify_time = ETHTOOL_MM_MAX_VERIFY_TIME_MS;
> +
> +	return 0;
> +}
> +
> +static int emac_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg,
> +		       struct netlink_ext_ack *extack)
> +{

[ ... ]

> +	mutex_lock(&iet->fpe_lock);
> +	iet->verify_time_ms = cfg->verify_time;
> +	iet->tx_min_frag_size = cfg->tx_min_frag_size;
> +	iet->fpe_enabled = cfg->tx_enabled;
> +	iet->mac_verify_configure = cfg->verify_enabled;
> +	err = icssg_config_ietfpe(ndev, cfg->tx_enabled);

[Severity: Medium]
Is PRE_EMPTION_VERIFY_STATUS ever reset before a new verification
starts? icssg_iet_verify_wait() only polls it:

	ret = readb_poll_timeout(config + PRE_EMPTION_VERIFY_STATUS,
				 status,
				 status == ICSSG_IETFPE_STATE_SUCCEEDED ||
				 status == ICSSG_IETFPE_STATE_FAILED,
				 delay_us,
				 timeout_us);

readb_poll_timeout() reads before it sleeps, so the first read happens
right after icssg_set_port_state() returns. If the firmware updates this
byte some time after acking the R30 command, a value left over from an
earlier attempt would decide the result.

A stale failed value would make the next emac_set_mm() fail at once with
-EIO, even after the partner is fixed. A stale succeeded value (disable,
then re-enable towards a partner that no longer supports preemption)
would turn on preemption without a fresh verification.

The non-verify branch waits usleep_range(100, 200) for the firmware to
update PRE_EMPTION_ACTIVE_TX. The verify branch reads
PRE_EMPTION_ACTIVE_TX right after seeing the succeeded state, with no
settle delay.

This depends on firmware behaviour that the driver can't see. Before
this series nothing set fpe_enabled to true, so emac_set_mm() is the
first path that lets userspace re-run this sequence repeatedly.

Would writing a non-terminal value such as ICSSG_IETFPE_STATE_INITIAL to
the status byte before sending the command avoid this?

> +	if (err) {
> +		/* icssg_config_ietfpe fallback disabled TX preemption in HW.
> +		 * New config values are already programmed in HW registers,
> +		 * so keep them. Only force fpe_enabled off to match HW state
> +		 * and prevent silent re-enable on the next link event.
> +		 */
> +		iet->fpe_enabled = false;

[Severity: Medium]
Does leaving mac_verify_configure set here make later partial MM_SET
requests fail?

After a failed verification, emac_get_mm() reports tx_enabled=false and
verify_enabled=true. ethnl_set_mm() builds cfg from get_mm() through
mm_state_to_cfg() and overrides only the attributes the user supplied.
It then checks:

net/ethtool/mm.c:ethnl_set_mm() {
	...
	if (cfg.verify_enabled && !cfg.tx_enabled) {
		NL_SET_ERR_MSG(extack, "Verification requires TX enabled");
		return -EINVAL;
	}
	...
}

So a request like "ethtool --set-mm ethX verify-time 10" or
"tx-min-frag-size 124" gets -EINVAL until the user also passes
tx-enabled or verify-enabled.

Should this branch also clear mac_verify_configure, or restore both
fields together?

[Severity: Low]
Does the fallback really disable TX preemption in firmware when the
enable command itself fails? In icssg_config_ietfpe():

	ret = icssg_set_port_state(emac,
				   enable ? ICSSG_EMAC_PORT_PREMPT_TX_ENABLE :
					    ICSSG_EMAC_PORT_PREMPT_TX_DISABLE);
	if (ret) {
		netdev_err(ndev, "TX preempt %s command failed\n",
			   str_enable_disable(enable));
		goto fallback;
	}

This skips disable_tx, so no ICSSG_EMAC_PORT_PREMPT_TX_DISABLE command
is sent. The fallback only rewrites the PRE_EMPTION_ENABLE_TX and
PRE_EMPTION_ENABLE_VERIFY config bytes. icssg_set_port_state() returns
-ETIMEDOUT after polling and leaves the posted command words in place.

If the firmware was only slow and finishes the enable command later,
could firmware preemption become active while the driver records
fpe_enabled=false and fpe_active=false, and get_mm() reports
tx_active=false?

Whether the firmware acts on a timed-out command is not visible from the
driver. The impact looks small, because icssg_iet_set_preempt_mask()
with fpe_active=false keeps all queues express.

Would going through disable_tx on this failure be a safer rollback?

> +	}
> +	mutex_unlock(&iet->fpe_lock);
> +
> +	return err;
> +}
> +
> +static void emac_get_mm_stats(struct net_device *ndev,
> +			      struct ethtool_mm_stats *s)
> +{

[ ... ]

> +	spin_lock(&emac->prueth->stats_lock);
> +	/* MACMergeHoldCount stats is not tracked by the firmware */
> +	s->MACMergeFrameAssOkCount = emac_get_stat_by_name(emac, "FW_PREEMPT_ASSEMBLY_OK");
> +	s->MACMergeFrameAssErrorCount = emac_get_stat_by_name(emac, "FW_PREEMPT_ASSEMBLY_ERR");
> +	s->MACMergeFragCountRx = emac_get_stat_by_name(emac, "FW_PREEMPT_FRAG_CNT_RX");
> +	s->MACMergeFragCountTx = emac_get_stat_by_name(emac, "FW_PREEMPT_FRAG_CNT_TX");
> +	s->MACMergeFrameSmdErrorCount = emac_get_stat_by_name(emac, "FW_PREEMPT_BAD_FRAG");

[Severity: Medium]
Does this truncate the MAC Merge counters? emac_get_stat_by_name()
returns int:

int emac_get_stat_by_name(struct prueth_emac *emac, char *stat_name)
{
	...
			if (!strcmp(icssg_all_pa_stats[i].name, stat_name))
				return emac->pa_stats[i];
	...
}

emac->pa_stats[] are u64 accumulators, updated with emac->pa_stats[i] +=
val in emac_update_hardware_stats(). Each value is cut to a signed
32-bit int and then sign-extended into the u64 fields of struct
ethtool_mm_stats.

Once a counter passes INT_MAX, "ethtool --show-mm --include-statistics"
would show values near 2^64. Past 2^32 the counter wraps. Holding
stats_lock prevents torn reads, but the truncation happens after the
read.

The int return type predates this patch (the changelog says it will be
fixed separately). However, these five call sites are the first to
expose it through the standard MM stats uAPI.

Since stats_lock is already held, could this read emac->pa_stats[]
directly, or could the helper return u64?

> +	spin_unlock(&emac->prueth->stats_lock);
> +}

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_qos.h b/drivers/net/ethernet/ti/icssg/icssg_qos.h
> index 0a375c125f4b8..bb0d6e2950dfc 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_qos.h
> +++ b/drivers/net/ethernet/ti/icssg/icssg_qos.h

[ ... ]

> +static inline int icssg_qos_validate_tx_min_frag_size(u32 min_frag_size,
> +						      struct netlink_ext_ack *extack)
> +{
> +	/* Firmware takes min_frag_size including FCS length.
> +	 * The firmware requires the fragment size (including FCS) to be
> +	 * a multiple of 64 bytes. Since 64 bytes = ETH_ZLEN + ETH_FCS_LEN,
> +	 * valid user-facing values are: 60, 124, 188, 252.
> +	 */
> +	if (min_frag_size < ETH_ZLEN) {
> +		NL_SET_ERR_MSG_MOD(extack,
> +				   "tx_min_frag_size must be at least 60 bytes");
> +		return -EINVAL;
> +	}
> +
> +	if (min_frag_size > ICSSG_IET_MAX_TX_MIN_FRAG_SIZE) {
> +		NL_SET_ERR_MSG_MOD(extack,
> +				   "tx_min_frag_size must not exceed 252 bytes");
> +		return -EINVAL;
> +	}
> +
> +	if ((min_frag_size + ETH_FCS_LEN) % (ETH_ZLEN + ETH_FCS_LEN)) {
> +		NL_SET_ERR_MSG_MOD(extack,
> +				   "tx_min_frag_size must be a multiple of 64 bytes minus 4");
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}

[Severity: Low]
This isn't a bug, but could this use ethtool_mm_frag_size_min_to_add()
from include/linux/ethtool.h instead? It accepts the same
60/124/188/252 values. am65-cpsw, enetc, ocelot and stmmac all use it.

The two range checks here can never fire, because net/ethtool/mm.c
already enforces:

	[ETHTOOL_A_MM_TX_MIN_FRAG_SIZE]	= NLA_POLICY_RANGE(NLA_U32, 60, 252),

ethnl_set_mm() is the only caller of ->set_mm(). With the core helper,
ICSSG_IET_MAX_TX_MIN_FRAG_SIZE would no longer be needed, and the extack
messages would match the other MM drivers.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121144618.180542-1-m-malladi%40ti.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-25 15:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21 14:46 [PATCH net-next v9 0/2] Add Frame Preemption MAC Merge support for ICSSG Meghana Malladi
2026-11-21 14:46 ` [PATCH net-next v9 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
2026-11-25 15:08   ` netdev-bot+sashiko
2026-11-21 14:46 ` [PATCH net-next v9 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge Meghana Malladi
2026-11-25 15:08   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®