* [PATCH net-next v10 0/2] Add Frame Preemption MAC Merge support for ICSSG
@ 2026-12-02 19:12 Meghana Malladi
2026-12-02 19:12 ` [PATCH net-next v10 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
2026-12-02 19:12 ` [PATCH net-next v10 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-12-02 19:12 UTC (permalink / raw)
To: icheng, kees+treewide, marco.crivellari, haokexin, laixiangwu,
m-malladi, arnd, afd, basharath, parvathi, horms, 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.
v9: https://lore.kernel.org/all/20261121144618.180542-1-m-malladi@ti.com/
Meghana Malladi (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.c | 2 +
drivers/net/ethernet/ti/icssg/icssg_config.h | 9 -
drivers/net/ethernet/ti/icssg/icssg_ethtool.c | 129 ++++++-
drivers/net/ethernet/ti/icssg/icssg_prueth.c | 26 +-
drivers/net/ethernet/ti/icssg/icssg_prueth.h | 14 +-
drivers/net/ethernet/ti/icssg/icssg_qos.c | 346 ++++++++++++++++++
drivers/net/ethernet/ti/icssg/icssg_qos.h | 71 ++++
drivers/net/ethernet/ti/icssg/icssg_stats.c | 16 +
drivers/net/ethernet/ti/icssg/icssg_stats.h | 86 +++--
.../net/ethernet/ti/icssg/icssg_switch_map.h | 9 +-
11 files changed, 653 insertions(+), 58 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: 0a837a30e55bbea2afb01cf0b3ec0c1d789a73ad
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next v10 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support
2026-12-02 19:12 [PATCH net-next v10 0/2] Add Frame Preemption MAC Merge support for ICSSG Meghana Malladi
@ 2026-12-02 19:12 ` Meghana Malladi
2026-12-03 20:06 ` netdev-bot+sashiko
2026-12-02 19:12 ` [PATCH net-next v10 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-12-02 19:12 UTC (permalink / raw)
To: icheng, kees+treewide, marco.crivellari, haokexin, laixiangwu,
m-malladi, arnd, afd, basharath, parvathi, horms, vladimir.oltean,
rogerq, danishanwar, pabeni, kuba, edumazet, davem, andrew+netdev
Cc: linux-arm-kernel, netdev, linux-kernel, srk, Vignesh Raghavendra
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. FAILED verify status is
preserved through the fallback so get_mm() can report it accurately.
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. Callers that
do not already hold phydev->lock take it before fpe_lock to maintain
the phydev->lock -> fpe_lock ordering established by emac_adjust_link().
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.
Move enum icssg_ietfpe_verify_states from icssg_config.h to icssg_qos.h
where it belongs alongside the QoS state tracking structures.
Co-developed-by: MD Danish Anwar <danishanwar@ti.com>
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Signed-off-by: Meghana Malladi <m-malladi@ti.com>
---
Changelog for v10-v9:
- prueth_emac_restart(): re-apply FPE after firmware boot via icssg_qos_link_state_update()
for ports whose link is up
- icssg_iet_change_preemptible_tcs(): skip full enable/verify handshake when
fpe_active; update queue mask only
- icssg_config_ietfpe(): reset PRE_EMPTION_VERIFY_STATUS to ICSSG_IETFPE_STATE_UNKNOWN and
PRE_EMPTION_ACTIVE_TX to 0 before arming verify to avoid stale firmware state
- emac_tc_setup_mqprio(): acquire phydev->lock before fpe_lock and hold across entire
publish→apply→rollback; fixes lock ordering and rollback race with emac_adjust_link()
- emac_tc_setup_mqprio(): replace netdev_err() with NL_SET_ERR_MSG_MOD() for user-facing config errors
- icssg_switch_map.h: update EXPRESS_PRE_EMPTIVE_Q_MAP comment; add ICSSG_PREEMPTIBLE_Q_MARK named
constant for BIT(4)
- icssg_qos_link_state_update(): drop iet->fpe_enabled read outside fpe_lock in debug message
drivers/net/ethernet/ti/Makefile | 3 +-
drivers/net/ethernet/ti/icssg/icssg_config.c | 2 +
drivers/net/ethernet/ti/icssg/icssg_config.h | 9 -
drivers/net/ethernet/ti/icssg/icssg_prueth.c | 26 +-
drivers/net/ethernet/ti/icssg/icssg_prueth.h | 2 +
drivers/net/ethernet/ti/icssg/icssg_qos.c | 346 ++++++++++++++++++
drivers/net/ethernet/ti/icssg/icssg_qos.h | 70 ++++
.../net/ethernet/ti/icssg/icssg_switch_map.h | 4 +-
8 files changed, 447 insertions(+), 15 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.c b/drivers/net/ethernet/ti/icssg/icssg_config.c
index 3f8237c17d099..6202355b5a3d6 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_config.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_config.c
@@ -11,6 +11,7 @@
#include "icssg_prueth.h"
#include "icssg_switch_map.h"
#include "icssg_mii_rt.h"
+#include "icssg_qos.h"
/* TX IPG Values to be set for 100M link speed. These values are
* in ocp_clk cycles. So need change if ocp_clk is changed for a specific
@@ -513,6 +514,7 @@ int icssg_config(struct prueth *prueth, struct prueth_emac *emac, int slice)
int ret;
memset_io(config, 0, TAS_GATE_MASK_LIST0);
+ writeb(ICSSG_EXPRESS_Q_MASK_ALL, config + EXPRESS_PRE_EMPTIVE_Q_MASK);
icssg_miig_queues_init(prueth, slice);
emac->speed = SPEED_1000;
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..7a18e3650399c 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);
@@ -1867,6 +1873,16 @@ static int prueth_emac_restart(struct prueth *prueth)
ret = icssg_set_port_state(emac0, ICSSG_EMAC_PORT_FORWARD);
ret |= icssg_set_port_state(emac1, ICSSG_EMAC_PORT_FORWARD);
+ /* Re-apply FPE state after firmware restart. prueth_emac_common_start()
+ * fires emac_adjust_link() before the firmware is booted, so the R30
+ * command times out and fpe_active is cleared. The link state does not
+ * change again after boot, so re-apply here for any port that is up.
+ */
+ if (READ_ONCE(emac0->link))
+ icssg_qos_link_state_update(emac0->ndev);
+ if (READ_ONCE(emac1->link))
+ icssg_qos_link_state_update(emac1->ndev);
+
/* Attache net_device for both PRUeth ports */
netif_device_attach(emac0->ndev);
netif_device_attach(emac1->ndev);
@@ -2475,6 +2491,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 +2552,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..85f7017d2c8e7 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -44,6 +44,7 @@
#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)
@@ -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..f20a03111a1cb
--- /dev/null
+++ b/drivers/net/ethernet/ti/icssg/icssg_qos.c
@@ -0,0 +1,346 @@
+// 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(ICSSG_PREEMPTIBLE_Q_MARK,
+ 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(0, config + PRE_EMPTION_ACTIVE_TX);
+ writeb(ICSSG_IETFPE_STATE_UNKNOWN, config + PRE_EMPTION_VERIFY_STATUS);
+ 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);
+ if (iet->verify_status != ICSSG_IETFPE_STATE_FAILED)
+ 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;
+ iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
+}
+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) {
+ ret = icssg_config_ietfpe(emac->ndev, false);
+ mutex_unlock(&iet->fpe_lock);
+ return ret;
+ }
+
+ /* If FPE is already active, only the queue mask needs updating.
+ * Skip the full enable/verify handshake to avoid unnecessary
+ * verify cycles and to prevent mqprio from failing on a partner
+ * that rejects verify.
+ */
+ if (iet->fpe_active) {
+ icssg_iet_set_preempt_mask(emac);
+ 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) {
+ NL_SET_ERR_MSG_MOD(mqprio->extack,
+ "number of traffic classes exceeds hardware limit");
+ return -EOPNOTSUPP;
+ }
+
+ if (mqprio->flags & TC_MQPRIO_F_SHAPER) {
+ NL_SET_ERR_MSG_MOD(mqprio->extack, "traffic shaping is not supported");
+ return -EOPNOTSUPP;
+ }
+
+ if (mqprio->flags & (TC_MQPRIO_F_MIN_RATE | TC_MQPRIO_F_MAX_RATE)) {
+ NL_SET_ERR_MSG_MOD(mqprio->extack, "per-queue rate limiting is not supported");
+ 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);
+ }
+ }
+
+ netdev_dbg(ndev, "dev->num_tc %u dev->real_num_tx_queues %u\n",
+ ndev->num_tc, ndev->real_num_tx_queues);
+
+ mutex_lock(&ndev->phydev->lock);
+
+ 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);
+
+ 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);
+ }
+
+ mutex_unlock(&ndev->phydev->lock);
+ 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 configuration failed\n");
+}
+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..c1e3ef85cc581
--- /dev/null
+++ b/drivers/net/ethernet/ti/icssg/icssg_qos.h
@@ -0,0 +1,70 @@
+/* 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_PREEMPTIBLE_Q_MARK BIT(4)
+#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 */
diff --git a/drivers/net/ethernet/ti/icssg/icssg_switch_map.h b/drivers/net/ethernet/ti/icssg/icssg_switch_map.h
index 7e053b8af3ece..cd78142783149 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_switch_map.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_switch_map.h
@@ -169,8 +169,8 @@
/* Stores the table used for priority regeneration. 1B per PCP/Queue */
#define PORT_Q_PRIORITY_REGEN_OFFSET 0x002C
-/* For marking Packet as priority/express (this feature is disabled) or
- * cut-through/S&F.
+/* Per-queue preemption map. One byte per queue; set ICSSG_PREEMPTIBLE_Q_MARK
+ * to mark a queue as preemptible, 0 for express.
*/
#define EXPRESS_PRE_EMPTIVE_Q_MAP 0x0034
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v10 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge
2026-12-02 19:12 [PATCH net-next v10 0/2] Add Frame Preemption MAC Merge support for ICSSG Meghana Malladi
2026-12-02 19:12 ` [PATCH net-next v10 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
@ 2026-12-02 19:12 ` Meghana Malladi
2026-12-03 20:06 ` netdev-bot+sashiko
1 sibling, 1 reply; 5+ messages in thread
From: Meghana Malladi @ 2026-12-02 19:12 UTC (permalink / raw)
To: icheng, kees+treewide, marco.crivellari, haokexin, laixiangwu,
m-malladi, arnd, afd, basharath, parvathi, horms, vladimir.oltean,
rogerq, danishanwar, pabeni, kuba, edumazet, davem, andrew+netdev
Cc: linux-arm-kernel, netdev, linux-kernel, srk, Vignesh Raghavendra
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() assigns the user-supplied configuration to driver state
and then delegates all hardware programming to icssg_config_ietfpe().
fpe_enabled is kept as the administrative state and is not cleared on
failure; fpe_active and verify_status carry the operational result so
that get_mm() reports them accurately per the ethtool MM uAPI contract.
tx_min_frag_size is validated using ethtool_mm_frag_size_min_to_add(),
consistent with other MM drivers, since the firmware requires the
fragment size including FCS to be a multiple of 64 bytes.
emac_get_mm_stats() uses a u64-returning accessor to avoid truncating
the PA stats accumulators through the existing int-returning helper.
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.
Co-developed-by: MD Danish Anwar <danishanwar@ti.com>
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Signed-off-by: Meghana Malladi <m-malladi@ti.com>
---
Changelog for v10-v9:
- emac_get_mm_stats(): use emac_get_pa_stat_u64_by_name() (u64) instead of
emac_get_stat_by_name() (int) to avoid truncating PA stats
- emac_set_mm(): keep fpe_enabled as admin state on failure; fpe_active and
verify_status carry operational result per ethtool MM uAPI
- Fallback path: preserve ICSSG_IETFPE_STATE_FAILED in verify_status so get_mm()
can report verify failure
- emac_set_mm(): acquire phydev->lock before fpe_lock to match lock ordering of
emac_adjust_link()
- Replace icssg_qos_validate_tx_min_frag_size() with ethtool_mm_frag_size_min_to_add()
from the ethtool core
drivers/net/ethernet/ti/icssg/icssg_ethtool.c | 129 +++++++++++++++++-
drivers/net/ethernet/ti/icssg/icssg_prueth.h | 12 +-
drivers/net/ethernet/ti/icssg/icssg_qos.h | 1 +
drivers/net/ethernet/ti/icssg/icssg_stats.c | 16 +++
drivers/net/ethernet/ti/icssg/icssg_stats.h | 86 +++++++-----
.../net/ethernet/ti/icssg/icssg_switch_map.h | 5 +
6 files changed, 206 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..9eb14f4fc0b57 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,123 @@ 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;
+ u32 add_frag_size;
+ 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 = ethtool_mm_frag_size_min_to_add(cfg->tx_min_frag_size,
+ &add_frag_size, extack);
+ if (err)
+ return err;
+
+ mutex_lock(&ndev->phydev->lock);
+ 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) {
+ /* TX preemption failed. Keep fpe_enabled as admin state;
+ * fpe_active=false and verify_status report the operational
+ * result. Link-up will retry if fpe_enabled is true.
+ */
+ }
+ mutex_unlock(&iet->fpe_lock);
+ mutex_unlock(&ndev->phydev->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_pa_stat_u64_by_name(emac, "FW_PREEMPT_ASSEMBLY_OK");
+ s->MACMergeFrameAssErrorCount = emac_get_pa_stat_u64_by_name(emac, "FW_PREEMPT_ASSEMBLY_ERR");
+ s->MACMergeFragCountRx = emac_get_pa_stat_u64_by_name(emac, "FW_PREEMPT_FRAG_CNT_RX");
+ s->MACMergeFragCountTx = emac_get_pa_stat_u64_by_name(emac, "FW_PREEMPT_FRAG_CNT_TX");
+ s->MACMergeFrameSmdErrorCount = emac_get_pa_stat_u64_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 +437,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 85f7017d2c8e7..0f5b64ca18741 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 */
@@ -461,6 +466,7 @@ int emac_fdb_flow_id_updated(struct prueth_emac *emac);
void icssg_stats_work_handler(struct work_struct *work);
void emac_update_hardware_stats(struct prueth_emac *emac);
int emac_get_stat_by_name(struct prueth_emac *emac, char *stat_name);
+u64 emac_get_pa_stat_u64_by_name(struct prueth_emac *emac, char *stat_name);
/* Common functions */
void prueth_cleanup_rx_chns(struct prueth_emac *emac,
diff --git a/drivers/net/ethernet/ti/icssg/icssg_qos.h b/drivers/net/ethernet/ti/icssg/icssg_qos.h
index c1e3ef85cc581..96947bcb19668 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_qos.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_qos.h
@@ -61,6 +61,7 @@ struct prueth_qos {
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);
diff --git a/drivers/net/ethernet/ti/icssg/icssg_stats.c b/drivers/net/ethernet/ti/icssg/icssg_stats.c
index 7d6d6692d8192..7c912cd162676 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_stats.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_stats.c
@@ -93,3 +93,19 @@ int emac_get_stat_by_name(struct prueth_emac *emac, char *stat_name)
netdev_err(emac->ndev, "Invalid stats %s\n", stat_name);
return -EINVAL;
}
+
+u64 emac_get_pa_stat_u64_by_name(struct prueth_emac *emac, char *stat_name)
+{
+ int i;
+
+ if (!emac->prueth->pa_stats)
+ return 0;
+
+ for (i = 0; i < ARRAY_SIZE(icssg_all_pa_stats); i++) {
+ if (!strcmp(icssg_all_pa_stats[i].name, stat_name))
+ return emac->pa_stats[i];
+ }
+
+ netdev_err(emac->ndev, "Invalid PA stats %s\n", stat_name);
+ return 0;
+}
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 cd78142783149..6b43ee36ff573 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 related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v10 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support
2026-12-02 19:12 ` [PATCH net-next v10 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
@ 2026-12-03 20:06 ` netdev-bot+sashiko
0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 20:06 UTC (permalink / raw)
To: m-malladi
Cc: icheng, kees+treewide, marco.crivellari, haokexin, laixiangwu,
arnd, afd, basharath, parvathi, horms, 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 8 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 3 · 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).
- [High] emac_tc_setup_mqprio()
(drivers/net/ethernet/ti/icssg/icssg_qos.c) calls…
- [High] If FPE was active before prueth_emac_restart(), it is not re-
armed in the rebooted firmware.
- [Medium] The commit message says that callers which do not already hold
phydev->lock take it before fpe_lock, to keep the phydev->lock ->…
- [Medium] emac_adjust_link() now calls icssg_qos_link_state_update() on
every link transition.
- [Medium] The FPE verify handshake sleeps while phydev->lock is held.
- [Low] Concern: icssg_prueth_sr1.c uses the same struct prueth_emac, now
with qos.iet.fpe_lock, and the shared icssg_ethtool_ops, but never…
- [Low] In icssg_config_ietfpe(), the verify branch clears
PRE_EMPTION_ACTIVE_TX (and VERIFY_STATUS) before arming, to avoid…
- [Low] Concern: three paths clear the software FPE state without
confirming the firmware disarmed: (a) the link-down branch of…
--
net: ti: icssg-prueth: Add Frame Preemption MAC Merge support
This adds QoS infrastructure for IET Frame Preemption to the ICSSG driver.
It covers firmware FPE configuration with a verify handshake, and MQPRIO
offload that maps preemptible traffic classes to queues. FPE is re-applied
on link changes and after a firmware restart, serialized by a new fpe_lock
taken after phydev->lock.
> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 9bb67e185a3ea..7a18e3650399c 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
[ ... ]
> @@ -1867,6 +1873,16 @@ static int prueth_emac_restart(struct prueth *prueth)
> ret = icssg_set_port_state(emac0, ICSSG_EMAC_PORT_FORWARD);
> ret |= icssg_set_port_state(emac1, ICSSG_EMAC_PORT_FORWARD);
>
> + /* Re-apply FPE state after firmware restart. prueth_emac_common_start()
> + * fires emac_adjust_link() before the firmware is booted, so the R30
> + * command times out and fpe_active is cleared. The link state does not
> + * change again after boot, so re-apply here for any port that is up.
> + */
[Severity: High]
Does this comment still hold when FPE was already active before the
restart?
Nothing in the restart sequence clears iet->fpe_active.
prueth_emac_common_start() sets the link to 0 with WRITE_ONCE(), and
emac_adjust_link() then sees a 0->1 transition. The link-down branch of
icssg_qos_link_state_update(), which is what clears fpe_active, never runs.
So the pre-boot call and this post-boot re-apply both hit the new shortcut
in icssg_iet_change_preemptible_tcs():
if (iet->fpe_active) {
icssg_iet_set_preempt_mask(emac);
mutex_unlock(&iet->fpe_lock);
return 0;
}
No R30 command is sent. The rebooted firmware never gets
ICSSG_EMAC_PORT_PREMPT_TX_ENABLE or the verify setup, and
PRE_EMPTION_ACTIVE_TX is never checked.
Wouldn't the driver keep reporting tx_active through get_mm() and keep
marking queues preemptible in EXPRESS_PRE_EMPTIVE_Q_MASK/Q_MAP, while FPE
is not enabled in the firmware?
This becomes reachable once .set_mm is wired up in the next patch. For
example, ethtool --set-mm tx-enabled on followed by a bridge or HSR
join/leave goes through icssg_change_mode() -> prueth_emac_restart().
Should fpe_active be cleared when the firmware is restarted, so the
re-apply goes through icssg_config_ietfpe()?
> + if (READ_ONCE(emac0->link))
> + icssg_qos_link_state_update(emac0->ndev);
> + if (READ_ONCE(emac1->link))
> + icssg_qos_link_state_update(emac1->ndev);
[Severity: Medium]
The commit message says:
Callers that do not already hold phydev->lock take it before fpe_lock
to maintain the phydev->lock -> fpe_lock ordering established by
emac_adjust_link().
Should these calls take phydev->lock too?
prueth_emac_restart() runs under rtnl only, from icssg_change_mode(),
prueth_netdevice_port_unlink() and prueth_hsr_port_unlink(). The PHY state
machine is not stopped, so emac_adjust_link() can run at the same time
under phydev->lock.
emac_adjust_link() publishes the link before it configures the port:
if (!emac->link) {
new_state = true;
WRITE_ONCE(emac->link, 1);
}
...
icssg_update_rgmii_cfg(prueth->miig_rt, emac);
...
icssg_config_set_speed(emac);
icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
Can the restart path see link == 1 in that window? If so, it would send
PREMPT_TX_ENABLE and start verify before speed and FORWARD are set up.
icssg_qos_link_state_update() also reads emac->link outside fpe_lock and
picks its branch from that value. fpe_lock alone therefore doesn't
serialize FPE configuration against link processing here.
[ ... ]
> 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..f20a03111a1cb
> --- /dev/null
> +++ b/drivers/net/ethernet/ti/icssg/icssg_qos.c
[ ... ]
> +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);
[Severity: Medium]
The default verify_time_ms is ICSSG_IET_MAX_VERIFY_TIME (128). With that,
this poll can sleep for about 384 ms, plus up to 10 ms for the R30
command. Is it intended to sleep that long with phydev->lock held?
emac_adjust_link() now reaches this from phylib:
phy_state_machine() /* holds phydev->lock */
emac_adjust_link()
icssg_qos_link_state_update()
icssg_iet_change_preemptible_tcs()
icssg_config_ietfpe(ndev, true)
icssg_iet_verify_wait()
prueth_emac_common_start() and emac_tc_setup_mqprio() also hold
phydev->lock under rtnl for the same handshake, and so does emac_set_mm()
later in the series.
Each link-up with FPE and verify enabled could then stall the PHY state
machine for hundreds of milliseconds. Any rtnl holder that needs
phydev->lock, such as the ethtool link settings ops, would stall too.
This is worst with a link partner that never answers verify.
[ ... ]
> + if (enable && iet->mac_verify_configure) {
> + writeb(0, config + PRE_EMPTION_ACTIVE_TX);
> + writeb(ICSSG_IETFPE_STATE_UNKNOWN, config + PRE_EMPTION_VERIFY_STATUS);
> + 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;
> + }
[ ... ]
> + } 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;
[Severity: Low]
Can this read a stale PRE_EMPTION_ACTIVE_TX when verify is disabled?
Only the verify branch above clears PRE_EMPTION_ACTIVE_TX before sending
the command. With enable true and mac_verify_configure false, the register
is not reset. A value of 1 is then accepted after a 100-200 us sleep.
PRE_EMPTION_ACTIVE_TX (0x05A1) is outside the range that icssg_config()
clears with memset_io(config, 0, TAS_GATE_MASK_LIST0). The link-down path
only clears ENABLE_TX and ENABLE_VERIFY.
A 1 left over from an earlier FPE session could be taken as confirmation
even if the firmware did not activate preemption this time. It isn't clear
from the driver whether the firmware always rewrites this byte before it
completes the R30 command.
Would it be safer to clear PRE_EMPTION_ACTIVE_TX in both enable branches?
[ ... ]
> +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);
> + if (iet->verify_status != ICSSG_IETFPE_STATE_FAILED)
> + iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
> + iet->fpe_active = false;
> + icssg_iet_set_preempt_mask(emac);
> + return ret;
> +}
[Severity: Low]
This probably isn't a functional bug, but three paths clear the software
FPE state without confirming that the firmware has disarmed:
- the link-down branch of icssg_qos_link_state_update() only zeroes the
PRE_EMPTION_ENABLE_TX and PRE_EMPTION_ENABLE_VERIFY bytes
- disable_tx ignores the return value of PREMPT_TX_DISABLE
- fallback, reached after PREMPT_TX_ENABLE fails, never sends DISABLE
The next link-up always goes through icssg_config_ietfpe() and sends an
explicit enable or disable command. Fallback also ends with
icssg_iet_set_preempt_mask() with fpe_active false, which resets all
queues to express.
So there is no concrete impact visible from the driver side, but the
firmware behaviour can't be fully checked from here.
> +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);
[Severity: Low]
This isn't a bug at the end of the series, but icssg_prueth_sr1.c uses the
same struct prueth_emac (now including qos.iet.fpe_lock) and the shared
icssg_ethtool_ops. It never calls icssg_qos_init().
SR1 is safe today for these reasons:
- emac_get_mm(), emac_set_mm() and emac_get_mm_stats() return early on
emac->is_sr1
- .ndo_setup_tc is only set in the SR2 emac_netdev_ops
- icssg_qos_link_state_update() is only called from the SR2 driver
That leaves an uninitialized fpe_lock in SR1 that any future shared path
could reach without the is_sr1 check. Would it make sense to initialize it
for SR1 as well?
[ ... ]
> +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) {
> + ret = icssg_config_ietfpe(emac->ndev, false);
> + mutex_unlock(&iet->fpe_lock);
> + return ret;
> + }
[Severity: Medium]
When FPE was never configured, this still calls icssg_config_ietfpe(false).
That writes the PRE_EMPTION_* bytes and sends
ICSSG_EMAC_PORT_PREMPT_TX_DISABLE.
emac_adjust_link() now calls icssg_qos_link_state_update() on every link
transition. Does that mean an extra R30 command on each link-up, even for
users who never use FPE?
During a firmware restart this runs before the PRUs are booted:
prueth_emac_restart()
prueth_emac_common_start()
icssg_config()
WRITE_ONCE(emac->link, 0);
emac_adjust_link() /* link 0->1 */
icssg_qos_link_state_update()
icssg_iet_change_preemptible_tcs()
icssg_config_ietfpe(ndev, false)
icssg_set_port_state(PREMPT_TX_DISABLE) /* 10 ms timeout */
prueth_emac_start() /* firmware booted here */
If the PHY link is up, wouldn't each port wait out the timeout on every
switch or HSR mode change? It would also log "timeout waiting for command
done" and "TX preempt disable command failed", even if FPE was never
enabled.
The PREMPT_TX_DISABLE command words also stay in the R30 mailbox, in place
of the FORWARD command written just before.
Plain mqprio offload with no preemption now depends on this command too.
If it fails, emac_tc_setup_mqprio() rolls back and calls netdev_reset_tc().
Could this return early when there is nothing to disable?
[ ... ]
> +static int emac_tc_setup_mqprio(struct net_device *ndev, void *type_data)
> +{
[ ... ]
> + netdev_dbg(ndev, "dev->num_tc %u dev->real_num_tx_queues %u\n",
> + ndev->num_tc, ndev->real_num_tx_queues);
> +
> + mutex_lock(&ndev->phydev->lock);
[Severity: High]
Can ndev->phydev be NULL here?
prueth_remove() clears phydev before it unregisters the netdev.
unregister_netdev() then tears down an offloaded mqprio qdisc through
ndo_setup_tc():
prueth_remove()
phy_disconnect(prueth->emac[i]->ndev->phydev);
prueth->emac[i]->ndev->phydev = NULL;
unregister_netdev()
dev_shutdown()
qdisc_put()
mqprio_destroy()
mqprio_disable_offload()
ndo_setup_tc(dev, TC_SETUP_QDISC_MQPRIO, &mqprio)
emac_tc_setup_mqprio()
mutex_lock(&ndev->phydev->lock);
mqprio_disable_offload() passes a zeroed tc_mqprio_qopt_offload, so
num_tc is 0. Nothing returns early for num_tc == 0 before this lock.
Wouldn't unbinding the driver after "tc qdisc add ... mqprio ... hw 1"
then hit a NULL pointer dereference? The netdev_unregister unwind in
prueth_probe() clears phydev in the same order.
prueth_probe() also calls register_netdev() before emac_phy_connect(). A
tc request in that window would see phydev == NULL as well.
ndev->phydev is read again for the mutex_unlock() at the end of this
function. prueth_remove() clears it without rtnl, so could the lock and the
unlock see different pointers?
The same unchecked pattern is copied into emac_set_mm() in the later patch
"net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge".
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202191238.2221903-1-m-malladi%40ti.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v10 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge
2026-12-02 19:12 ` [PATCH net-next v10 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge Meghana Malladi
@ 2026-12-03 20:06 ` netdev-bot+sashiko
0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 20:06 UTC (permalink / raw)
To: m-malladi
Cc: icheng, kees+treewide, marco.crivellari, haokexin, laixiangwu,
arnd, afd, basharath, parvathi, horms, 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 9 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 6 · Low: 2
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).
- [High] emac_set_mm() calls `mutex_lock(&ndev->phydev->lock)` and later
`mutex_unlock(&ndev->phydev->lock)` without checking ndev->phydev for…
- [Medium] Adding .get_mm makes per-MAC statistics requests (`--src emac`
/ `--src pmac`) reach this driver, but emac_get_rmon_stats() ignores…
- [Medium] emac_set_mm() writes the new configuration into driver state
before calling icssg_config_ietfpe(), and keeps it if that call fails.
- [Medium] This patch makes the `enable == true` branch of
icssg_config_ietfpe() reachable for the first time.
- [Medium] emac_set_mm() calls icssg_config_ietfpe(ndev, cfg->tx_enabled)
unconditionally, including when FPE is already active (iet->fpe_active…
- [Medium] The user's tx_min_frag_size (the ethtool TX-side minimum non-
final fragment size, which should follow what the link partner can…
- [Medium] net: ti: icssg-prueth: wrong verify_status in emac_get_mm() on
timeout or down
- [Low] One paragraph of the commit message describes a change this
commit does not make.
- [Low] Two patch hygiene nits: 1.
--
net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge
This patch adds .get_mm(), .set_mm() and .get_mm_stats() to the ICSSG
ethtool ops. It also adds PA stats registers for the preemption counters
and hides those counters from ethtool -S. The stat table sizes now come
from ARRAY_SIZE(), and icssg_stats.h is made self-contained.
> 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.
[Severity: Low]
Is this paragraph still accurate for this patch? The patch doesn't touch
icssg_qos.c. This line in icssg_qos_init() was already added by the
parent commit "net: ti: icssg-prueth: Add Frame Preemption MAC Merge
support":
iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
The only QoS file change here is a blank line in icssg_qos.h.
Is the paragraph left over from an earlier revision?
> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index b715af21d23ac..9eb14f4fc0b57 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
[ ... ]
> @@ -294,6 +297,123 @@ static int emac_set_per_queue_coalesce(struct net_device *ndev, u32 queue,
[ ... ]
> +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;
> + u32 add_frag_size;
> + 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 = ethtool_mm_frag_size_min_to_add(cfg->tx_min_frag_size,
> + &add_frag_size, extack);
> + if (err)
> + return err;
[Severity: Medium]
add_frag_size is computed here and then thrown away. Is the raw byte
count really what the firmware expects?
icssg_config_ietfpe() writes only the LOCAL register, as a byte count:
writew(iet->tx_min_frag_size + ETH_FCS_LEN,
config + PRE_EMPTION_ADD_FRAG_SIZE_LOCAL);
icssg_switch_map.h describes the two registers like this:
/* Non Final Fragment Size supported by Link Partner */
#define PRE_EMPTION_ADD_FRAG_SIZE_REMOTE 0x05A4
/* Non Final Fragment Size supported by Firmware */
#define PRE_EMPTION_ADD_FRAG_SIZE_LOCAL 0x05A6
tx_min_frag_size is the TX-side minimum, which should follow what the
link partner can reassemble. Nothing in the driver writes
PRE_EMPTION_ADD_FRAG_SIZE_REMOTE.
The firmware might fragment TX according to REMOTE, or expect the 0..3
addFragSize encoding. In either case, would the configured value have no
effect while get_mm() still reports it?
> +
> + mutex_lock(&ndev->phydev->lock);
[Severity: High]
Can ndev->phydev be NULL here? Nothing checks it before the lock is
taken.
prueth_probe() registers the netdev before it connects the PHY:
drivers/net/ethernet/ti/icssg/icssg_prueth.c:prueth_probe() {
...
ret = register_netdev(prueth->emac[PRUETH_MAC0]->ndev);
...
ret = emac_phy_connect(prueth->emac[PRUETH_MAC0]);
if (ret) {
...
goto netdev_unregister;
}
...
}
So an ETHTOOL_MSG_MM_SET request can reach emac_set_mm() while phydev is
still NULL. It can also arrive after of_phy_connect() fails and before
the error path unregisters the netdev.
prueth_remove() clears the pointer before unregistering, without holding
rtnl:
phy_disconnect(prueth->emac[i]->ndev->phydev);
prueth->emac[i]->ndev->phydev = NULL;
unregister_netdev(prueth->registered_netdevs[i]);
ndev->phydev is read again for the unlock:
mutex_unlock(&ndev->phydev->lock);
If the pointer is cleared between the lock and the unlock, wouldn't the
unlock dereference NULL and leave the phydev mutex held?
emac_get_eee() and emac_set_eee() in the same file already guard this
case:
if (!ndev->phydev)
return -EOPNOTSUPP;
Should emac_set_mm() check for it too, and read the pointer only once?
> + 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;
[Severity: Medium]
This is the first code that sets fpe_enabled, so this patch makes the
enable branch of icssg_config_ietfpe() reachable. With tx_enabled on and
verify_enabled off, could a stale PRE_EMPTION_ACTIVE_TX value hide a
firmware activation failure?
The verify branch clears PRE_EMPTION_ACTIVE_TX before it sends the
enable command. The else branch doesn't:
} else {
writeb(0, config + PRE_EMPTION_ENABLE_VERIFY);
iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
}
The non-verify path then checks activation using that same byte:
val = readb(config + PRE_EMPTION_ACTIVE_TX);
if (val != 1) {
On link-down, icssg_qos_link_state_update() zeroes
PRE_EMPTION_ENABLE_TX and PRE_EMPTION_ENABLE_VERIFY. It doesn't clear
PRE_EMPTION_ACTIVE_TX or send ICSSG_EMAC_PORT_PREMPT_TX_DISABLE. Unless
the firmware resets the byte itself, a 1 from an earlier session could
survive a link flap.
In that case fpe_active becomes true and the preemptible queue mask is
programmed. get_mm() then reports tx_active = true even if the firmware
never activated preemption.
Should the non-verify path also clear PRE_EMPTION_ACTIVE_TX first?
> + iet->mac_verify_configure = cfg->verify_enabled;
> + err = icssg_config_ietfpe(ndev, cfg->tx_enabled);
[Severity: Medium]
If icssg_config_ietfpe() fails, verify_time_ms, tx_min_frag_size,
fpe_enabled and mac_verify_configure keep their new values. The error
is still returned to ethtool.
icssg_config_ietfpe() can fail in three ways:
- -ETIMEDOUT from icssg_iet_verify_wait()
- -EIO when the partner rejects verification, or when
PRE_EMPTION_ACTIVE_TX is not 1
- an error from icssg_set_port_state()
ethnl_set_mm() returns the negative error, so no ETHTOOL_MSG_MM_NTF is
sent and user space is told the request failed. A later get_mm still
reports the rejected config, for example tx_enabled = true.
On the next link-up, icssg_iet_change_preemptible_tcs() sees
fpe_enabled && !fpe_active and calls:
ret = icssg_config_ietfpe(emac->ndev, iet->fpe_enabled);
That reruns the verify handshake, for up to ICSSG_IET_VERIFY_ATTEMPTS
times verify_time, for a request that was reported as failed.
Should this return 0 and report the failure through tx_active and
verify_status? Or should it restore the previous config on error?
[Severity: Medium]
What happens if FPE is already active when this runs? ethnl_set_mm()
calls set_mm for any attribute change, for example a new verify-time on
a link that is working.
With verify enabled, icssg_config_ietfpe() overwrites the status bytes
the firmware owns. It then sends the enable command again without a
disable first:
if (enable && iet->mac_verify_configure) {
writeb(0, config + PRE_EMPTION_ACTIVE_TX);
writeb(ICSSG_IETFPE_STATE_UNKNOWN, config + PRE_EMPTION_VERIFY_STATUS);
...
}
...
ret = icssg_set_port_state(emac,
enable ? ICSSG_EMAC_PORT_PREMPT_TX_ENABLE :
ICSSG_EMAC_PORT_PREMPT_TX_DISABLE);
If the firmware ignores a repeated ICSSG_EMAC_PORT_PREMPT_TX_ENABLE,
PRE_EMPTION_VERIFY_STATUS stays UNKNOWN. icssg_iet_verify_wait() then
times out while rtnl and phydev->lock are held. The disable_tx/fallback
path would then tear down preemption that was working.
icssg_iet_change_preemptible_tcs() skips this handshake on purpose:
if (iet->fpe_active) {
icssg_iet_set_preempt_mask(emac);
mutex_unlock(&iet->fpe_lock);
return 0;
}
Does emac_set_mm() need a similar guard, or a disable-then-enable
sequence?
> + if (err) {
> + /* TX preemption failed. Keep fpe_enabled as admin state;
> + * fpe_active=false and verify_status report the operational
> + * result. Link-up will retry if fpe_enabled is true.
> + */
> + }
[Severity: Low]
This isn't a bug, but this if block contains only a comment and does
nothing. The behaviour it describes happens anyway, because nothing is
rolled back.
Also, the only change to icssg_qos.h is an extra blank line after
struct prueth_qos. That leaves two blank lines in a row, which
checkpatch --strict flags. Is it a rebase leftover?
> + mutex_unlock(&iet->fpe_lock);
> + mutex_unlock(&ndev->phydev->lock);
> +
> + return err;
> +}
[ ... ]
> @@ -317,5 +437,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,
[Severity: Medium]
With .get_mm implemented, __ethtool_dev_mm_supported() now returns true
for this device. So stats_prepare_data() no longer rejects
ETHTOOL_MAC_STATS_SRC_EMAC and ETHTOOL_MAC_STATS_SRC_PMAC requests:
if ((src == ETHTOOL_MAC_STATS_SRC_EMAC ||
src == ETHTOOL_MAC_STATS_SRC_PMAC) &&
!__ethtool_dev_mm_supported(dev)) {
Doesn't emac_get_rmon_stats() need to check rmon_stats->src now? It
always fills undersize_pkts, hist[] and hist_tx[] from the eMAC MIIG
counters:
rmon_stats->hist[0] = emac_get_stat_by_name(emac, "rx_bucket1_frames");
As a result, "ethtool -S <dev> --groups rmon --src pmac" would report
eMAC counters labelled as pMAC counters.
Other MM-capable drivers, such as enetc and ocelot, switch on
rmon_stats->src. They leave unsupported sources at
ETHTOOL_STAT_NOT_SET.
> + .set_mm = emac_set_mm,
> + .get_mm_stats = emac_get_mm_stats,
> };
[ ... ]
> @@ -294,6 +297,123 @@ 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;
> + u32 add_frag_size;
> + 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 = ethtool_mm_frag_size_min_to_add(cfg->tx_min_frag_size,
> + &add_frag_size, extack);
> + if (err)
> + return err;
> +
> + mutex_lock(&ndev->phydev->lock);
> + 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) {
> + /* TX preemption failed. Keep fpe_enabled as admin state;
> + * fpe_active=false and verify_status report the operational
> + * result. Link-up will retry if fpe_enabled is true.
> + */
> + }
> + mutex_unlock(&iet->fpe_lock);
> + mutex_unlock(&ndev->phydev->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_pa_stat_u64_by_name(emac, "FW_PREEMPT_ASSEMBLY_OK");
> + s->MACMergeFrameAssErrorCount = emac_get_pa_stat_u64_by_name(emac, "FW_PREEMPT_ASSEMBLY_ERR");
> + s->MACMergeFragCountRx = emac_get_pa_stat_u64_by_name(emac, "FW_PREEMPT_FRAG_CNT_RX");
> + s->MACMergeFragCountTx = emac_get_pa_stat_u64_by_name(emac, "FW_PREEMPT_FRAG_CNT_TX");
> + s->MACMergeFrameSmdErrorCount = emac_get_pa_stat_u64_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,
[Severity: Medium]
Can get_mm() report verify_status DISABLED while verify_enabled is
true? This patch is the first code that sets mac_verify_configure, so
the paths below become reachable from user space.
readb_poll_timeout() in icssg_iet_verify_wait() only stops early when
PRE_EMPTION_VERIFY_STATUS reads SUCCEEDED or FAILED. On -ETIMEDOUT
that condition was never met, so the value stored here can't be
FAILED. It is typically still VERIFYING:
iet->verify_status = status;
if (!ret && status == ICSSG_IETFPE_STATE_FAILED)
return -EIO;
The fallback path in icssg_config_ietfpe() then does:
if (iet->verify_status != ICSSG_IETFPE_STATE_FAILED)
iet->verify_status = ICSSG_IETFPE_STATE_DISABLED;
So a verify timeout reaches user space as DISABLED, not FAILED. The
driver timeout is 3 * verify_time_ms, which matches the firmware's
three attempts. That makes this the common failure case, not a
corner case.
Link-down looks similar. If set_mm is called with verify_enabled
while the link is down, icssg_config_ietfpe() returns 0 early.
verify_status then stays DISABLED from icssg_qos_init(). On link
down, icssg_qos_link_state_update() also sets verify_status to
DISABLED even when mac_verify_configure is true.
In the ethtool MM uAPI, DISABLED means the verification function is
turned off. The generic ethtool_mmsv code in net/ethtool/mm.c reports
INITIAL while the link is down. It reports FAILED once the verify
retries run out.
The opposite case exists too. With verify enabled,
icssg_config_ietfpe() writes ICSSG_IETFPE_STATE_UNKNOWN to
PRE_EMPTION_VERIFY_STATUS but leaves iet->verify_status alone. If
icssg_set_port_state() then fails, the fallback keeps a FAILED left
over from an earlier attempt.
Should the timeout path set FAILED explicitly? Should verify_status
also be reset at the start of icssg_config_ietfpe(), and derived from
mac_verify_configure on link down?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202191238.2221903-1-m-malladi%40ti.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 20:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 19:12 [PATCH net-next v10 0/2] Add Frame Preemption MAC Merge support for ICSSG Meghana Malladi
2026-12-02 19:12 ` [PATCH net-next v10 1/2] net: ti: icssg-prueth: Add Frame Preemption MAC Merge support Meghana Malladi
2026-12-03 20:06 ` netdev-bot+sashiko
2026-12-02 19:12 ` [PATCH net-next v10 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge Meghana Malladi
2026-12-03 20:06 ` 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