Re: [PATCH net-next v10 2/2] net: ti: icssg-prueth: Add ethtool ops for Frame Preemption MAC Merge
From: netdev-bot+sashiko
Date: Thu Dec 03 2026 - 15:06:48 EST
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