net: macb: implement ethtool set channels count operation
Subsystems (3)
Théo Lebrun
maintainerv7 cover net: macb: implement ethtool set channels count operation
Add support for changing the active number of queues. Tested on Mobileye EyeQ5.
If the interface is running, use context swapping to realloc rings on the fly. To avoid introducing bugs with stale ENST config, we start by fixing how ENST config gets applied in the first patch.
One pretty significant change to our context swapping implementation:
the set_channels callback needs to be able to fail in the context swapping window. If it failed, then we keep using the old context and don't reconfigure HW. From its standpoint, it got disabled then re-enabled with no change to its rings.
I tried *not fixing* TAPRIO/ENST but that was hard, so instead I preface this series with a commit reworking how ENST works. We now handle close/open and refuse set_channels if a queue-to-be-disabled had an ENST schedule attached.
Have a nice day,
Thanks,
Théo
---
Changes in v7:
- Patch 1 (new ENST patch):
- Preface the series by a patch fixing TAPRIO ENST config across interface flap and context swap operations.
- It does so by storing a cached ENST config in bp and restoring it on context swap and link-up. Previously we could only write the ENST registers on TAPRIO callbacks.
- Patch 2 (ethtool set_channels implementation):
- Fix context swap rollback: if the window failed (set_channels is the first context swap that can fail), then we need to *not* write HW ring cursors and *not* reset DQL.
- macb_interrupt(): avoid NULL ptr deref when reading bp->ctx fields.
- macb_poll_controller(): avoid bp->ctx NULL ptr deref by using
bp->configured_num_queues rather than bp->ctx->num_queues.
- gem_get_rx_ring_count(): use bp->configured_num_queues rather than
bp->max_num_queues. - at91ether_open(): assign bp->ctx->num_queues = 1 to avoid breaking
shared code that iterates on queues (suspend PM ops mostly).
- Patch 3 (Tx SRAM segment distribution):
- DCFG6 register has 4 bits to tell us the # of segments, not 3.
- The config of the # of segments per queue is 3 bits (not 2): fix distribution algorithm to allow going up to the limit. I don't
know of any hardware on which this could have an incidence.
- SRAM segment distribution is also done at context swap end, for
this new set_channels callback.
- Rebase onto latest net-next/main (d6816d9a93b6); tiny conflict inside macb_config caps.
- Link to v6: https://patch.msgid.link/[email protected]
Changes in v6:
- Rebase onto latest net-next/main (573af8015529). This means rebasing
onto context swapping, which is now used on set_channels requests.
- Move the QUEUE_DISABLE caps patch out into a separate series.
https://lore.kernel.org/netdev/[email protected]/
- Drop kunit tests. Thanks Jakub.
- Fix the TAPRIO gate test if qdisc is destroyed while the interface is
down (because bp->taprio_gated_queues was stall in that case).
Thanks Nicolai.
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- New patch: add missing MACB_CAPS_QUEUE_DISABLE to 3 compatibles based
on publicly available datasheets. That means they can benefit from
the set_channels implementation.
- set_channels patch:
- Refuse set_channels if it disables a queue with active TAPRIO.
- Use TBQP.QUEUE_DISABLE bit to also disable transmit; previously we
only disabled the receive engine.
- Migrate code to newly introduced macb_queue_isr_clear() helper.
- Adapt to newly introduced macb_quiesce_start(), where we want to synchronize_irq() on all queues, even the disabled ones.
- IRQ handler now self-disarms on disabled queues.
- Drop old_count unused stack variable.
- Only allow TAPRIO rules on active queues.
- Fix comments style and text in macb_set_channels(); in particular
mention we'll use context-swapping once it is available.
- Distribute SRAM segments patch:
- Introduce GEM_TXQSEGALLOC_MASK(q) and use field_prep|get() macros.
- Introduce capability for this feature, as many publicly available
GEM datasheets don't document the registers.
- Remove upper register support. Lower register is enough to handle 8
queues, which is the max we support.
- Add edge case kunit for num_segments=128.
- Introduce static_assert(MACB_MAX_QUEUES == 8) in gem_sram_distribute_segments() to signal that code will need
updating if/when the constant changes.
- Update To/Cc list: drop Nicolas and Claudiu, add Conor and Nicolai.
- Rebase onto latest net-next/main (6b3e73774815).
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- macb_set_channels(): drop count == old_count check, it is redundant
with both netlink and ioctl codepaths. See early returns in ethnl_set_channels() and ethtool_set_channels(). Discussion @ V2.
- Rebase to latest net-next (8737d7194d6d); nothing to report.
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Makefile: fix compilation of kunit tests. This bug was hidden before
because everything was builtin so it ended up linked together anyway.
Now macb.o is the amalgation of macb_{main,ptp,utils}.o and
macb_test.o is the amalgation of macb_{kunit,utils}.o.
- Kconfig CONFIG_MACB_KUNIT_TEST entry:
- Turn into tristate; no good reason to restrict to bool.
- Drop "depends on MACB". We do not need to compile the full MACB
driver to test gem_sram_distribute_segments().
- Add usual MODULE_*() macros to macb_kunit.c.
- Drop unused init value of ret in macb_set_channels().
- Rebase to latest net-next; nothing to report.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Move gem_sram_distribute_segments() from macb_main.c to macb_utils.c
and kunit tests from macb_main.c to macb_kunit.c.
- macb_set_channels():
- Add comment about MACB_CAPS_QUEUE_DISABLE.
- Refuse operation if netif_running(), with code comment.
- Drop useless sanity checks on ch->{combined,rx,tx}_count.
- Add help text to CONFIG_MACB_KUNIT_TEST.
- Fix checkpatch --max-line-length=80 warnings.
- Rebase onto latest net-next; nothing to report.
- Link to v1: https://lore.kernel.org/r/[email protected]
To: Conor Dooley <[email protected]>
To: Andrew Lunn <[email protected]>
To: David S. Miller <[email protected]>
To: Eric Dumazet <[email protected]>
To: Jakub Kicinski <[email protected]>
To: Paolo Abeni <[email protected]>
To: Russell King <[email protected]>
---
Théo Lebrun (3):
net: macb: cache ENST config across link down/up
net: macb: implement ethtool_ops.get|set_channels()
net: macb: distribute evenly Tx SRAM segments
drivers/net/ethernet/cadence/macb.h | 66 +++- drivers/net/ethernet/cadence/macb_main.c | 512 +++++++++++++++++++++---------- 2 files changed, 397 insertions(+), 181 deletions(-)
---
base-commit: d6816d9a93b66a12bf01e10037e377f3333ad6cc
change-id: 20260305-macb-set-channels-5bf6e07f3270
Best regards,
Signature · 1 line
Théo Lebrun <[email protected]>
Théo Lebrun
maintainerPATCH v7 1/3 net: macb: cache ENST config across link down/up
Currently, ENST is not explicitly restored across interface close/open. If HW keeps its register state then ENST is kept, otherwise it is lost; but we do not write the ENST schedule again on open.
This causes trouble if the config is not compatible with the new open and link-up. The two issues that can occur are a link speed change (as all timings are configured in a unit relative to the link speed) or a change in the # of queues.
The latter is the main reason we do this change before implementing ethtool -L support.
If on link-up, the cached ENST config is invalid (link speed changed), then we drop the cached config, log a warning and explicitly override all ENST timings previously configured in the registers. If it is valid, we explicitly re-apply it.
Take this opportunity to replace a kmalloc in macb_taprio_setup_replace() with a simple and tiny (104b) stack value.
Drop the old hack of checking for pm_runtime_suspended(), which has little value because we could race with the runtime_suspend() call.
Synchronise our config using the existing bp->mac_cfg_lock mutex, taken by macb_taprio_setup_replace() and macb_taprio_destroy(). To avoid an ABBA deadlock between bp->mac_cfg_lock and phydev->lock taken by phylink_ethtool_ksettings_get(), cache the link speed as bp->speed_mbps.
--- drivers/net/ethernet/cadence/macb.h | 47 +++++--- drivers/net/ethernet/cadence/macb_main.c | 187 +++++++++++++++---------------- 2 files changed, 124 insertions(+), 110 deletions(-)
drivers/net/ethernet/cadence/macb.h +32 -15
@@ -1327,6 +1327,35 @@ struct macb_context {struct macb_txq txq[MACB_MAX_QUEUES ]; }; +/** +* struct macb_queue_enst_config - Configuration for Enhanced Scheduled Traffic +* @start_time_mask: Bitmask representing the start time for the queue +* @on_time_bytes: "on" time nsec expressed in bytes +* @off_time_bytes: "off" time nsec expressed in bytes +* +* This structure holds the configuration parameters for an ENST queue, +* used to control time-based transmission scheduling in the MACB driver. +*/ +struct macb_queue_enst_config { +u32 start_time_mask; +u32 on_time_bytes; +u32 off_time_bytes; +}; + +/** +* struct macb_enst - Cached Enhanced Scheduled Traffic configuration +* @queues: per-queue timing (zeroed for queues without schedule) +* @speed_mbps: link speed the timings were computed for, 0 if no schedule +* @queue_mask: queues enabled by the current schedule, 0 if no schedule +* +* The timings are expressed in bytes, so they depend on the link speed. +*/ +struct macb_enst { +struct macb_queue_enst_config queues[MACB_MAX_QUEUES ]; +u32 speed_mbps; +u32 queue_mask; +}; +struct macb {void __iomem *regs;bool native_io;
@@ -1427,11 +1456,14 @@ struct macb {/* Redundant to netif_carrier_ok(), but set under bp->mac_cfg_lock. */ bool link_up; +u32 speed_mbps;u32 rx_intr_mask;struct macb_pm_data pm_data;const struct macb_usrio_config *usrio; + +struct macb_enst enst; };#ifdef CONFIG_MACB_USE_HWSTAMP
@@ -1532,19 +1564,4 @@ struct macb_platform_data { struct clk *hclk; }; -/** -* struct macb_queue_enst_config - Configuration for Enhanced Scheduled Traffic -* @start_time_mask: Bitmask representing the start time for the queue -* @on_time_bytes: "on" time nsec expressed in bytes -* @off_time_bytes: "off" time nsec expressed in bytes -* -* This structure holds the configuration parameters for an ENST queue, -* used to control time-based transmission scheduling in the MACB driver. -*/ -struct macb_queue_enst_config { -u32 start_time_mask; -u32 on_time_bytes; -u32 off_time_bytes; -}; -#endif /* _MACB_H */
drivers/net/ethernet/cadence/macb_main.c +92 -95
299 lines not on this page · raw message
Signature · 1 line
2.56.1
Re: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
Quoted 23 lines · Théo Lebrun
Currently, ENST is not explicitly restored across interface close/open. If HW keeps its register state then ENST is kept, otherwise it is lost; but we do not write the ENST schedule again on open.
This causes trouble if the config is not compatible with the new open and link-up. The two issues that can occur are a link speed change (as all timings are configured in a unit relative to the link speed) or a change in the # of queues.
The latter is the main reason we do this change before implementing ethtool -L support.
If on link-up, the cached ENST config is invalid (link speed changed), then we drop the cached config, log a warning and explicitly override all ENST timings previously configured in the registers. If it is valid, we explicitly re-apply it.
Take this opportunity to replace a kmalloc in
macb_taprio_setup_replace()with a simple and tiny (104b) stack value.Drop the old hack of checking for
pm_runtime_suspended(), which has little value because we could race with theruntime_suspend()call.
Quoted 8 lines
Synchronise our config using the existing
bp->mac_cfg_lockmutex, taken bymacb_taprio_setup_replace()andmacb_taprio_destroy(). To avoid an ABBA deadlock betweenbp->mac_cfg_lockandphydev->locktaken byphylink_ethtool_ksettings_get(), cache the link speed asbp->speed_mbps.Signed-off-by Théo Lebrun <[email protected]>[...]
Re: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
In reply to Théo LebrunHi Théo,
Quoted 9 lines · Théo Lebrun
Currently, ENST is not explicitly restored across interface close/open. If HW keeps its register state then ENST is kept, otherwise it is lost; but we do not write the ENST schedule again on open.
This causes trouble if the config is not compatible with the new open and link-up. The two issues that can occur are a link speed change (as all timings are configured in a unit relative to the link speed) or a change in the # of queues.
Thanks for the patch.
We are working on the same problem for CBS, covering the four scenarios listed in:
https://lore.kernel.org/netdev/[email protected]/
Since this patch reworks how ENST state is kept and restored, it would be good to introduce a generic top-level tc structure here, which ENST, CBS and any later TSN offloads can share, instead of an ENST-specific one.
Quoted 52 lines
The latter is the main reason we do this change before implementing ethtool -L support.
If on link-up, the cached ENST config is invalid (link speed changed), then we drop the cached config, log a warning and explicitly override all ENST timings previously configured in the registers. If it is valid, we explicitly re-apply it.
Take this opportunity to replace a kmalloc in
macb_taprio_setup_replace()with a simple and tiny (104b) stack value.Drop the old hack of checking for
pm_runtime_suspended(), which has little value because we could race with theruntime_suspend()call.Synchronise our config using the existing
bp->mac_cfg_lockmutex, taken bymacb_taprio_setup_replace()andmacb_taprio_destroy(). To avoid an ABBA deadlock betweenbp->mac_cfg_lockandphydev->locktaken byphylink_ethtool_ksettings_get(), cache the link speed asbp->speed_mbps.Signed-off-by Théo Lebrun <[email protected]>--- drivers/net/ethernet/cadence/macb.h | 47 +++++--- drivers/net/ethernet/cadence/macb_main.c | 187 +++++++++++++++---------------- 2 files changed, 124 insertions(+), 110 deletions(-)drivers/net/ethernet/cadence/macb.h +19
-0@@ -1327,6 +1327,35 @@ struct macb_context {struct macb_txq txq[MACB_MAX_QUEUES ]; }; +/** +* struct macb_queue_enst_config - Configuration for Enhanced Scheduled Traffic +* @start_time_mask: Bitmask representing the start time for the queue +* @on_time_bytes: "on" time nsec expressed in bytes +* @off_time_bytes: "off" time nsec expressed in bytes +* +* This structure holds the configuration parameters for an ENST queue, +* used to control time-based transmission scheduling in the MACB driver. +*/ +struct macb_queue_enst_config { +u32 start_time_mask; +u32 on_time_bytes; +u32 off_time_bytes; +}; + +/** +* struct macb_enst - Cached Enhanced Scheduled Traffic configuration +* @queues: per-queue timing (zeroed for queues without schedule) +* @speed_mbps: link speed the timings were computed for, 0 if no schedule
drivers/net/ethernet/cadence/macb.h struct macb_context { · line 1358
Quoted 10 lines
drivers/net/ethernet/cadence/macb.h +10
-0+* @queue_mask: queues enabled by the current schedule, 0 if no schedule +* +* The timings are expressed in bytes, so they depend on the link speed. +*/ +struct macb_enst { +struct macb_queue_enst_config queues[MACB_MAX_QUEUES ]; +u32 speed_mbps; +u32 queue_mask; +}; +
Could this be a per-queue structure shared by all tc offloads, so that new features only add their own part?
For example:
struct macb_tc_queue {
struct {
u32 idleslope; /* kbps */
} cbs;
struct {
u32 start_time; /* ENST_START_TIME register value */
u32 on_time_ns; /* gate open interval */
u64 off_time_ns; /* gate closed interval */
} enst;
};
Quoted 103 lines
drivers/net/ethernet/cadence/macb.h +3
-15struct macb {void __iomem *regs;bool native_io;@@ -1427,11 +1456,14 @@ struct macb {/* Redundant to netif_carrier_ok(), but set under bp->mac_cfg_lock. */ bool link_up; +u32 speed_mbps;u32 rx_intr_mask;struct macb_pm_data pm_data;const struct macb_usrio_config *usrio; + +struct macb_enst enst; };#ifdef CONFIG_MACB_USE_HWSTAMP @@ -1532,19 +1564,4 @@ struct macb_platform_data { struct clk *hclk; }; -/** -* struct macb_queue_enst_config - Configuration for Enhanced Scheduled Traffic -* @start_time_mask: Bitmask representing the start time for the queue -* @on_time_bytes: "on" time nsec expressed in bytes -* @off_time_bytes: "off" time nsec expressed in bytes -* -* This structure holds the configuration parameters for an ENST queue, -* used to control time-based transmission scheduling in the MACB driver. -*/ -struct macb_queue_enst_config { -u32 start_time_mask; -u32 on_time_bytes; -u32 off_time_bytes; -}; -#endif /* _MACB_H */ drivers/net/ethernet/cadence/macb_main.c +39
-0@@ -847,6 +847,7 @@ static void macb_mac_link_down(struct phylink_config *config, unsigned int mode,mutex_lock (&bp->mac_cfg_lock); bp->link_up = false; + bp->speed_mbps =0 ;if (!(bp->caps &MACB_CAPS_MACB_IS_EMAC ))for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue)@@ -955,6 +956,43 @@ static void gem_shuffle_tx_rings(struct macb *bp)gem_shuffle_tx_one_ring (queue); } +static void macb_apply_enst_config (struct macb *bp) +{ +struct macb_queue_enst_config *config; +struct macb_queue *queue; +u32 queue_mask; +size_t q; + +/* Short-circuit to avoid writing to invalid register offsets */ +if (!(bp->caps &MACB_CAPS_QBV )) +return ; + +guard (spinlock_irqsave)(&bp->lock); + +/* Disable ENST for all queues. +* Reconfiguring timings must be done with ENST disabled. +*/ + queue_mask =BIT_U32 (bp->num_queues) -1 ; +gem_writel (bp,ENST_CONTROL , + queue_mask <<GEM_ENST_DISABLE_QUEUE_OFFSET ); + +for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { +/* Configure queue timing registers. +* +* Those fields must be zero if the queue has ENST disabled: +* notice we don't bother reading bp->enst.queue_mask & BIT(q). +*/ + config = &bp->enst.queues[q]; +queue_writel (queue,ENST_START_TIME , config->start_time_mask); +queue_writel (queue,ENST_ON_TIME , config->on_time_bytes); +queue_writel (queue,ENST_OFF_TIME , config->off_time_bytes); + } + +/* Enable ENST for all configured queues in one write */ +if (bp->enst.queue_mask) +gem_writel (bp,ENST_CONTROL , bp->enst.queue_mask); +} + static void macb_mac_link_up(struct phylink_config *config, struct phy_device *phydev, unsigned int mode, phy_interface_t interface,@@ -972,6 +1010,7 @@ static void macb_mac_link_up(struct phylink_config *config,spin_lock_irqsave (&bp->lock, flags); bp->link_up = true; + bp->speed_mbps = speed >0 ? speed :0 ; ctrl =macb_or_gem_readl (bp,NCFGR );
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1051
Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +1
-0@@ -1009,6 +1048,15 @@ static void macb_mac_link_up(struct phylink_config *config,spin_unlock_irqrestore (&bp->lock, flags); +if (bp->enst.speed_mbps && speed != bp->enst.speed_mbps) {
Why drop the schedule on a speed change? The taprio qdisc stays installed, so the user's configuration is still valid;
Could we instead recompute the ON/OFF times for the new speed on link-up, and only disable (with a warning) the queues whose intervals no longer fit the hardware range at that speed?
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1059
Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c +8
-0+netdev_warn (bp->netdev, +"TAPRIO dropped because link speed changed\n" ); + +memset (&bp->enst,0 ,sizeof (bp->enst)); + } + +macb_apply_enst_config (bp); +
Could this be a single macb_apply_tc_config() (or similar) that reprograms every enabled tc offload? CBS needs exactly the same handling, since idleslope is also relative to the link rate.
Thanks,
Quoted 236 lines
drivers/net/ethernet/cadence/macb_main.c +44
-95if (!(bp->caps &MACB_CAPS_MACB_IS_EMAC )) {macb_set_tx_clk (bp, speed);gem_shuffle_tx_rings (bp);@@ -4754,19 +4802,23 @@ static int macb_taprio_setup_replace(struct net_device *netdev, struct tc_taprio_qopt_offload *conf) {u64 total_on_time =0 , start_time_sec =0 , start_time = conf->base_time; -u32 configured_queues =0 , speed =0 , start_time_nsec; -struct macb_queue_enst_config *enst_queue; -struct ethtool_link_ksettings kset = {}; +u32 configured_queues =0 , start_time_nsec;struct macb *bp =netdev_priv (netdev);struct tc_taprio_sched_entry *entry; -struct macb_queue *queue; -u32 queue_mask; +struct macb_enst config = {};u8 queue_id; -size_t i, q; -int err; +u64 off; +size_t i; + +guard (mutex)(&bp->mac_cfg_lock); + +if (unlikely (!bp->speed_mbps)) { +netdev_err (netdev,"Invalid speed, link-down?\n" ); +return -EINVAL ; + }if (conf->num_entries > bp->num_queues) { -netdev_err (netdev,"Too many TAPRIO entries: %zu > %d queues\n" , +netdev_err (netdev,"Too many TAPRIO entries: %zu > %u active queues\n" , conf->num_entries, bp->num_queues);return -EINVAL ; }@@ -4777,23 +4829,6 @@ static int macb_taprio_setup_replace(struct net_device *netdev,return -ERANGE ; } -/* Get the current link speed */ - err =phylink_ethtool_ksettings_get (bp->phylink, &kset); -if (unlikely (err)) { -netdev_err (netdev,"Failed to get link settings: %d\n" , err); -return err; - } - - speed = kset.base.speed; -if (unlikely (speed ==SPEED_UNKNOWN || !speed)) { -netdev_err (netdev,"Invalid speed %d, link-down?\n" , speed); -return -EINVAL ; - } - - enst_queue =kzalloc_objs (*enst_queue, bp->num_queues); -if (unlikely (!enst_queue)) -return -ENOMEM ; -/* Pre-validate all entries before making any hardware changes */ for (i =0 ; i < conf->num_entries; i++) { entry = &conf->entries[i];@@ -4801,25 +4836,23 @@ static int macb_taprio_setup_replace(struct net_device *netdev,if (entry->command !=TC_TAPRIO_CMD_SET_GATES ) {netdev_err (netdev,"Entry %zu: unsupported command %d\n" , i, entry->command); - err = -EOPNOTSUPP ; - goto cleanup; +return -EOPNOTSUPP ; }/* Validate gate_mask: must be nonzero, single queue, and within range */ if (!is_power_of_2 (entry->gate_mask)) {netdev_err (netdev,"Entry %zu: gate_mask 0x%x is not a power of 2 (only one queue per entry allowed)\n" , i, entry->gate_mask); - err = -EINVAL ; - goto cleanup; +return -EINVAL ; }/* gate_mask must not select queues outside the valid queues */ queue_id =order_base_2 (entry->gate_mask);if (queue_id >= bp->num_queues) { -netdev_err (netdev,"Entry %zu: gate_mask 0x%x exceeds queue range (max_queues=%d)\n" , - i, entry->gate_mask, bp->num_queues); - err = -EINVAL ; - goto cleanup; +netdev_err (netdev,"Entry %zu: gate_mask 0x%x exceeds active queue range (num_queues=%u)\n" , + i, entry->gate_mask, + bp->num_queues); +return -EINVAL ; }/* Check for start time limits */ @@ -4828,34 +4861,33 @@ static int macb_taprio_setup_replace(struct net_device *netdev,if (start_time_sec >GENMASK (GEM_START_TIME_SEC_SIZE -1 ,0 )) {netdev_err (netdev,"Entry %zu: Start time %llu s exceeds hardware limit\n" , i, start_time_sec); - err = -ERANGE ; - goto cleanup; +return -ERANGE ; }/* Check for on time limit */ -if (entry->interval >enst_max_hw_interval (speed)) { +if (entry->interval >enst_max_hw_interval (bp->speed_mbps)) {netdev_err (netdev,"Entry %zu: interval %u ns exceeds hardware limit %llu ns\n" , - i, entry->interval,enst_max_hw_interval (speed)); - err = -ERANGE ; - goto cleanup; + i, entry->interval, +enst_max_hw_interval (bp->speed_mbps)); +return -ERANGE ; }/* Check for off time limit*/ -if ((conf->cycle_time - entry->interval) >enst_max_hw_interval (speed)) { + off = conf->cycle_time - entry->interval; +if (off >enst_max_hw_interval (bp->speed_mbps)) {netdev_err (netdev,"Entry %zu: off_time %llu ns exceeds hardware limit %llu ns\n" , - i, conf->cycle_time - entry->interval, -enst_max_hw_interval (speed)); - err = -ERANGE ; - goto cleanup; + i, off, +enst_max_hw_interval (bp->speed_mbps)); +return -ERANGE ; } - enst_queue[queue_id].start_time_mask = + config.queues[queue_id].start_time_mask = (start_time_sec <<GEM_START_TIME_SEC_OFFSET ) | start_time_nsec; - enst_queue[queue_id].on_time_bytes = -enst_ns_to_hw_units (entry->interval, speed); - enst_queue[queue_id].off_time_bytes = -enst_ns_to_hw_units (conf->cycle_time - entry->interval, speed); + config.queues[queue_id].on_time_bytes = +enst_ns_to_hw_units (entry->interval, bp->speed_mbps); + config.queues[queue_id].off_time_bytes = +enst_ns_to_hw_units (off, bp->speed_mbps); configured_queues |= entry->gate_mask; total_on_time += entry->interval;@@ -4866,82 +4898,47 @@ static int macb_taprio_setup_replace(struct net_device *netdev,if (total_on_time > conf->cycle_time) {netdev_err (netdev,"Total ON %llu ns exceeds cycle time %llu ns\n" , total_on_time, conf->cycle_time); - err = -EINVAL ; - goto cleanup; +return -EINVAL ; }netdev_dbg (netdev,"TAPRIO setup: %zu entries, base_time=%lld ns, cycle_time=%llu ns\n" , conf->num_entries, conf->base_time, conf->cycle_time); -/* All validations passed - proceed with hardware configuration */ - scoped_guard(spinlock_irqsave, &bp->lock) { -/* Disable ENST queues if running before configuring */ - queue_mask =BIT_U32 (bp->num_queues) -1 ; -gem_writel (bp,ENST_CONTROL , - queue_mask <<GEM_ENST_DISABLE_QUEUE_OFFSET ); + config.queue_mask = configured_queues; + config.speed_mbps = bp->speed_mbps; + bp->enst = config; -for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { -/* Configure queue timing registers */ -queue_writel (queue,ENST_START_TIME , - enst_queue[q].start_time_mask); -queue_writel (queue,ENST_ON_TIME , - enst_queue[q].on_time_bytes); -queue_writel (queue,ENST_OFF_TIME , - enst_queue[q].off_time_bytes); - } - -/* Enable ENST for all configured queues in one write */ -gem_writel (bp,ENST_CONTROL , configured_queues); - } +macb_apply_enst_config (bp);netdev_info (netdev,"TAPRIO configuration completed successfully: %zu entries, %d queues configured\n" , conf->num_entries,hweight32 (configured_queues)); -cleanup: -kfree (enst_queue); -return err; +return 0 ; }static void macb_taprio_destroy (struct net_device *netdev) {struct macb *bp =netdev_priv (netdev); -struct macb_queue *queue; -u32 queue_mask; -unsigned int q; + +guard (mutex)(&bp->mac_cfg_lock);netdev_reset_tc (netdev); - queue_mask =BIT_U32 (bp->num_queues) -1 ; +memset (&bp->enst,0 ,sizeof (bp->enst)); - scoped_guard(spinlock_irqsave, &bp->lock) { -/* Single disable command for all queues */ -gem_writel (bp,ENST_CONTROL , - queue_mask <<GEM_ENST_DISABLE_QUEUE_OFFSET ); +if (bp->link_up) +macb_apply_enst_config (bp); -/* Clear all queue ENST registers in batch */ -for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { -queue_writel (queue,ENST_START_TIME ,0 ); -queue_writel (queue,ENST_ON_TIME ,0 ); -queue_writel (queue,ENST_OFF_TIME ,0 ); - } - }netdev_info (netdev,"TAPRIO destroy: All gates disabled\n" ); }static int macb_setup_taprio (struct net_device *netdev,struct tc_taprio_qopt_offload *taprio) { -struct macb *bp =netdev_priv (netdev);int err =0 ;if (unlikely (!(netdev->hw_features &NETIF_F_HW_TC )))return -EOPNOTSUPP ; -/* Check if Device is in runtime suspend */ -if (unlikely (pm_runtime_suspended (&bp->pdev->dev))) { -netdev_err (netdev,"Device is in runtime suspend\n" ); -return -EOPNOTSUPP ; - } -switch (taprio->cmd) {case TAPRIO_CMD_REPLACE : err =macb_taprio_setup_replace (netdev, taprio);
Signature · 1 line
🙏 Vineeth
Théo Lebrun
maintainerRe: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
Hello Vineeth,
Quoted 15 lines · Vineeth Karumanchi
Hi Théo,
Quoted 9 lines · Théo Lebrun
Currently, ENST is not explicitly restored across interface close/open. If HW keeps its register state then ENST is kept, otherwise it is lost; but we do not write the ENST schedule again on open.
This causes trouble if the config is not compatible with the new open and link-up. The two issues that can occur are a link speed change (as all timings are configured in a unit relative to the link speed) or a change in the # of queues.
Thanks for the patch.
Quoted 7 lines
We are working on the same problem for CBS, covering the four scenarios listed in:
https://lore.kernel.org/netdev/[email protected]/Since this patch reworks how ENST state is kept and restored, it would be good to introduce a generic top-level tc structure here, which ENST, CBS and any later TSN offloads can share, instead of an ENST-specific one.
Sorry I forgot replying on that thread. It is still marked as unread in my mailbox!
Let me quote it here and reply:
Quoted 21 lines · Vineeth
Quoted 12 lines · Théo Lebrun
So we write cbs_control/0x04BC only on
ndo_setup_tc(TC_SETUP_QDISC_CBS)callback. As Sashiko pointed how I think that causes an issue with HW resets & suspend:
- what if configured then link down then link up?
- what if configured before link up?Also when not using CBS we hope tx_sched_ctrl/0x0580 is at its reset value (0b00, fixed priority) for all queues. I would expect an unconditional writel tx_sched_ctrl/0x0580 in
macb_init_hw(). This solves the down/up issue, the speed change and also ensures we don't inherit CBS or DWRR from the boot stages (super unlikely though).Quoted 5 lines
Also, it might be simpler to always use tx_sched_ctrl/0x0580 rather than sometimes tx_sched_ctrl/0x0580 and sometimes cbs_control/0x04BC, which are aliases.
What do you think?
Sorry for the delayed response.
Quoted 8 lines
I tested the current implementation in the following four scenarios:
1. Configuring CBS while the link is down: CBS cannot be programmed because the link speed is unknown.
2. Link down followed by link up: The hardware retains the CBS register values, and CBS is effective again after the link comes up at the same speed.
Here you talk about link-down followed by link-up.
But about a close then open: this behavior might be board specific. Runtime PM does suspend and this might shut off the IP on some platforms and not others. That would in turn mean the IP loses its state.
There is no easy way of knowing if that occurs on any platform that uses MACB. It sounds probable though.
Quoted 4 lines
3. Suspend/resume: The CBS register contents are lost after resume. However, the CBS child qdisc remains installed in the kernel and is still shown by tc as offloaded, leaving the software configuration inconsistent with the hardware state.
Again, this is platform specific. Some boards + suspend combo keep the SoC and its peripherals alive enough for them to keep their state.
A board with little runtime PM doing suspend-to-idle probably won't lose CBS register state. A board doing proper suspend-to-RAM will surely lose its state.
Quoted 14 lines
4. Link-speed change: The CBS register values are retained and shaping remains enabled. However, those values were calculated for the previous speed, so the resulting shaping bandwidth is incorrect.
I see two possible approaches:
- Retain the requested CBS parameters in the driver and restore the hardware configuration, following the saved-state approach used by IGB. For MACB, we would also recalculate the hardware idleslope on link-up using the negotiated speed.
If the saved request cannot be supported at the new speed, retain the request, leave CBS disabled for that queue, and warn the user that the configuration is invalid for the new link speed.
Quoted 7 lines
- Explicitly reset the scheduling configuration in
macb_init_hw()and require users to remove and recreate the CBS qdisc. This establishes a known hardware state, but leaves the installed qdisc inconsistent until users reconfigure it. It would also need handling for speed changes that do not invokemacb_init_hw().Please let me know your thoughts on these approaches.
Option 2 is not super doable. There is no API for the driver to say to the network stack and userspace "I'm dropping your qdisc, please re-enable one if you care".
So ideally we would do option 1, but dealing with link speed changes sounds complex. I'm super afraid of introducing bugs with code that recomputes the timings on the fly. I'm sure I will create rounding bugs in the edge cases.
That's why I made the cached state be in number of words and store the link speed alongside. This means we cannot introduce such bugs AND is less code overall AND is the common case.
It feels like easier and smaller incremental changes.
Now continuing onto the original quote:
Quoted 67 lines
Quoted 52 lines
The latter is the main reason we do this change before implementing ethtool -L support.
If on link-up, the cached ENST config is invalid (link speed changed), then we drop the cached config, log a warning and explicitly override all ENST timings previously configured in the registers. If it is valid, we explicitly re-apply it.
Take this opportunity to replace a kmalloc in
macb_taprio_setup_replace()with a simple and tiny (104b) stack value.Drop the old hack of checking for
pm_runtime_suspended(), which has little value because we could race with theruntime_suspend()call.Synchronise our config using the existing
bp->mac_cfg_lockmutex, taken bymacb_taprio_setup_replace()andmacb_taprio_destroy(). To avoid an ABBA deadlock betweenbp->mac_cfg_lockandphydev->locktaken byphylink_ethtool_ksettings_get(), cache the link speed asbp->speed_mbps.Signed-off-by Théo Lebrun <[email protected]>--- drivers/net/ethernet/cadence/macb.h | 47 +++++--- drivers/net/ethernet/cadence/macb_main.c | 187 +++++++++++++++---------------- 2 files changed, 124 insertions(+), 110 deletions(-)drivers/net/ethernet/cadence/macb.h +19
-0@@ -1327,6 +1327,35 @@ struct macb_context {struct macb_txq txq[MACB_MAX_QUEUES ]; }; +/** +* struct macb_queue_enst_config - Configuration for Enhanced Scheduled Traffic +* @start_time_mask: Bitmask representing the start time for the queue +* @on_time_bytes: "on" time nsec expressed in bytes +* @off_time_bytes: "off" time nsec expressed in bytes +* +* This structure holds the configuration parameters for an ENST queue, +* used to control time-based transmission scheduling in the MACB driver. +*/ +struct macb_queue_enst_config { +u32 start_time_mask; +u32 on_time_bytes; +u32 off_time_bytes; +}; + +/** +* struct macb_enst - Cached Enhanced Scheduled Traffic configuration +* @queues: per-queue timing (zeroed for queues without schedule) +* @speed_mbps: link speed the timings were computed for, 0 if no schedule drivers/net/ethernet/cadence/macb.h struct macb_context { · line 1358
Quoted 10 lines
drivers/net/ethernet/cadence/macb.h +10
-0+* @queue_mask: queues enabled by the current schedule, 0 if no schedule +* +* The timings are expressed in bytes, so they depend on the link speed. +*/ +struct macb_enst { +struct macb_queue_enst_config queues[MACB_MAX_QUEUES ]; +u32 speed_mbps; +u32 queue_mask; +}; +Could this be a per-queue structure shared by all tc offloads, so that new features only add their own part?
For example:
Quoted 10 lines
struct
macb_tc_queue{
struct {
u32 idleslope; /* kbps */
} cbs;
struct {
u32start_time; /*ENST_START_TIMEregister value */
u32on_time_ns; /* gate open interval */
u64off_time_ns; /* gate closed interval */
} enst;
};
Yes sure!
Either
// as you suggest struct macb_tc_queue tc_queues[MACB_MAX_QUEUES];
Or:
struct macb_enst_queue enst_queues[MACB_MAX_QUEUES]; struct macb_cbs_queue cbs_queues[MACB_MAX_QUEUES]; // ... etc ...
Both would work.
Quoted 107 lines
Quoted 107 lines
drivers/net/ethernet/cadence/macb.h +3
-15struct macb {void __iomem *regs;bool native_io;@@ -1427,11 +1456,14 @@ struct macb {/* Redundant to netif_carrier_ok(), but set under bp->mac_cfg_lock. */ bool link_up; +u32 speed_mbps;u32 rx_intr_mask;struct macb_pm_data pm_data;const struct macb_usrio_config *usrio; + +struct macb_enst enst; };#ifdef CONFIG_MACB_USE_HWSTAMP @@ -1532,19 +1564,4 @@ struct macb_platform_data { struct clk *hclk; }; -/** -* struct macb_queue_enst_config - Configuration for Enhanced Scheduled Traffic -* @start_time_mask: Bitmask representing the start time for the queue -* @on_time_bytes: "on" time nsec expressed in bytes -* @off_time_bytes: "off" time nsec expressed in bytes -* -* This structure holds the configuration parameters for an ENST queue, -* used to control time-based transmission scheduling in the MACB driver. -*/ -struct macb_queue_enst_config { -u32 start_time_mask; -u32 on_time_bytes; -u32 off_time_bytes; -}; -#endif /* _MACB_H */ drivers/net/ethernet/cadence/macb_main.c +39
-0@@ -847,6 +847,7 @@ static void macb_mac_link_down(struct phylink_config *config, unsigned int mode,mutex_lock (&bp->mac_cfg_lock); bp->link_up = false; + bp->speed_mbps =0 ;if (!(bp->caps &MACB_CAPS_MACB_IS_EMAC ))for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue)@@ -955,6 +956,43 @@ static void gem_shuffle_tx_rings(struct macb *bp)gem_shuffle_tx_one_ring (queue); } +static void macb_apply_enst_config (struct macb *bp) +{ +struct macb_queue_enst_config *config; +struct macb_queue *queue; +u32 queue_mask; +size_t q; + +/* Short-circuit to avoid writing to invalid register offsets */ +if (!(bp->caps &MACB_CAPS_QBV )) +return ; + +guard (spinlock_irqsave)(&bp->lock); + +/* Disable ENST for all queues. +* Reconfiguring timings must be done with ENST disabled. +*/ + queue_mask =BIT_U32 (bp->num_queues) -1 ; +gem_writel (bp,ENST_CONTROL , + queue_mask <<GEM_ENST_DISABLE_QUEUE_OFFSET ); + +for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { +/* Configure queue timing registers. +* +* Those fields must be zero if the queue has ENST disabled: +* notice we don't bother reading bp->enst.queue_mask & BIT(q). +*/ + config = &bp->enst.queues[q]; +queue_writel (queue,ENST_START_TIME , config->start_time_mask); +queue_writel (queue,ENST_ON_TIME , config->on_time_bytes); +queue_writel (queue,ENST_OFF_TIME , config->off_time_bytes); + } + +/* Enable ENST for all configured queues in one write */ +if (bp->enst.queue_mask) +gem_writel (bp,ENST_CONTROL , bp->enst.queue_mask); +} + static void macb_mac_link_up(struct phylink_config *config, struct phy_device *phydev, unsigned int mode, phy_interface_t interface,@@ -972,6 +1010,7 @@ static void macb_mac_link_up(struct phylink_config *config,spin_lock_irqsave (&bp->lock, flags); bp->link_up = true; + bp->speed_mbps = speed >0 ? speed :0 ; ctrl =macb_or_gem_readl (bp,NCFGR );@@ -1009,6 +1048,15 @@ static void macb_mac_link_up(struct phylink_config *config,spin_unlock_irqrestore (&bp->lock, flags);
Quoted 7 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1051
Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +1
-0+if (bp->enst.speed_mbps && speed != bp->enst.speed_mbps) {Why drop the schedule on a speed change? The taprio qdisc stays installed, so the user's configuration is still valid;
Could we instead recompute the ON/OFF times for the new speed on link-up, and only disable (with a warning) the queues whose intervals no longer fit the hardware range at that speed?
See explanation above. It felt like a good local maximum: simple code that probably doesn't introduce rounding bugs and solves it for most usecases.
In any case, we will sometimes have to drop the qdisc and warn about it.
Quoted 13 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1059
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +8
-0+netdev_warn (bp->netdev, +"TAPRIO dropped because link speed changed\n" ); + +memset (&bp->enst,0 ,sizeof (bp->enst)); + } + +macb_apply_enst_config (bp); +Could this be a single
macb_apply_tc_config()(or similar) that reprograms every enabled tc offload? CBS needs exactly the same handling, since idleslope is also relative to the link rate.
Yes sure!
Do you want to take over and handle this? You seem to be interested in those TC features. You can either copy the patch as-is or modify it under your own authorship, I don't mind.
Or if you prefer, I keep it here and iterate. But if I keep it, I'll continue with ENST and then at a later stage we'll add CBS & co onto it. This patch looks like a good starting point to add more onto it.
I'm mostly focused on getting a set_channels implementation (to then have XDP/XSK) and I fixed ENST along the way.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Théo Lebrun
maintainerRe: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
Hello Théo,
Quoted 117 lines · Théo Lebrun
Hello Vineeth,
Quoted 15 lines · Vineeth Karumanchi
Hi Théo,
Quoted 9 lines · Théo Lebrun
Currently, ENST is not explicitly restored across interface close/open. If HW keeps its register state then ENST is kept, otherwise it is lost; but we do not write the ENST schedule again on open.
This causes trouble if the config is not compatible with the new open and link-up. The two issues that can occur are a link speed change (as all timings are configured in a unit relative to the link speed) or a change in the # of queues.
Thanks for the patch.
Quoted 7 lines
We are working on the same problem for CBS, covering the four scenarios listed in:
https://lore.kernel.org/netdev/[email protected]/Since this patch reworks how ENST state is kept and restored, it would be good to introduce a generic top-level tc structure here, which ENST, CBS and any later TSN offloads can share, instead of an ENST-specific one.
Sorry I forgot replying on that thread. It is still marked as unread in my mailbox!
Let me quote it here and reply:
Quoted 21 lines · Vineeth
Quoted 12 lines · Théo Lebrun
So we write cbs_control/0x04BC only on
ndo_setup_tc(TC_SETUP_QDISC_CBS)callback. As Sashiko pointed how I think that causes an issue with HW resets & suspend:
- what if configured then link down then link up?
- what if configured before link up?Also when not using CBS we hope tx_sched_ctrl/0x0580 is at its reset value (0b00, fixed priority) for all queues. I would expect an unconditional writel tx_sched_ctrl/0x0580 in
macb_init_hw(). This solves the down/up issue, the speed change and also ensures we don't inherit CBS or DWRR from the boot stages (super unlikely though).Quoted 5 lines
Also, it might be simpler to always use tx_sched_ctrl/0x0580 rather than sometimes tx_sched_ctrl/0x0580 and sometimes cbs_control/0x04BC, which are aliases.
What do you think?
Sorry for the delayed response.
Quoted 8 lines
I tested the current implementation in the following four scenarios:
1. Configuring CBS while the link is down: CBS cannot be programmed because the link speed is unknown.
2. Link down followed by link up: The hardware retains the CBS register values, and CBS is effective again after the link comes up at the same speed.
Here you talk about link-down followed by link-up.
But about a close then open: this behavior might be board specific. Runtime PM does suspend and this might shut off the IP on some platforms and not others. That would in turn mean the IP loses its state.
There is no easy way of knowing if that occurs on any platform that uses MACB. It sounds probable though.
Quoted 4 lines
3. Suspend/resume: The CBS register contents are lost after resume. However, the CBS child qdisc remains installed in the kernel and is still shown by tc as offloaded, leaving the software configuration inconsistent with the hardware state.
Again, this is platform specific. Some boards + suspend combo keep the SoC and its peripherals alive enough for them to keep their state.
A board with little runtime PM doing suspend-to-idle probably won't lose CBS register state. A board doing proper suspend-to-RAM will surely lose its state.
Quoted 14 lines
4. Link-speed change: The CBS register values are retained and shaping remains enabled. However, those values were calculated for the previous speed, so the resulting shaping bandwidth is incorrect.
I see two possible approaches:
- Retain the requested CBS parameters in the driver and restore the hardware configuration, following the saved-state approach used by IGB. For MACB, we would also recalculate the hardware idleslope on link-up using the negotiated speed.
If the saved request cannot be supported at the new speed, retain the request, leave CBS disabled for that queue, and warn the user that the configuration is invalid for the new link speed.Quoted 7 lines
- Explicitly reset the scheduling configuration in
macb_init_hw()and require users to remove and recreate the CBS qdisc. This establishes a known hardware state, but leaves the installed qdisc inconsistent until users reconfigure it. It would also need handling for speed changes that do not invokemacb_init_hw().Please let me know your thoughts on these approaches.
Option 2 is not super doable. There is no API for the driver to say to the network stack and userspace "I'm dropping your qdisc, please re-enable one if you care".
So ideally we would do option 1, but dealing with link speed changes sounds complex. I'm super afraid of introducing bugs with code that recomputes the timings on the fly. I'm sure I will create rounding bugs in the edge cases.
Quoted 5 lines
That's why I made the cached state be in number of words and store the link speed alongside. This means we cannot introduce such bugs AND is less code overall AND is the common case.
It feels like easier and smaller incremental changes.
To expand with some numbers on this.
- For link speed increases, our trouble is the max on/off time interval that can be described. We might be asked for windows that we cannot express with our hardware registers.
- For link speed decreases, our trouble is the on/off time interval quantum. We risk introducing too much overlap when the desire was to have none (pretty common with ENST).
link speed │ 10M │ 100M │ 1G │ 2.5G │ 5G │ 10G
───────────┼────────┼───────┼──────┼────────┼────────┼───────
max on/off │ 105 ms │ 10 ms │ 1 ms │ 419 µs │ 210 µs │ 105 µs
───────────┼────────┼───────┼──────┼────────┼────────┼───────
quantum │ 800 ns │ 80 ns │ 8 ns │ 3.2 ns │ 1.6 ns │ 0.8 nsSo only ENST configs that have all timings in that .8µs - 105µs can safely-ish be described. But at 10M with the max on-time of 105µs, you cannot even transmit a full 1500 byte frame.
That is talking about the extremes; it is true that it could make more sense for less extreme link speed changes (eg from 100M to 1G).
Overall, this still conforts me in the current proposal: cache a link-speed specific config. Userspace must have had looked at the link speed to pick a sensible ENST schedule anyway.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
In reply to Théo LebrunHi Théo,
On 11/19/2026 9:10 PM, Théo Lebrun wrote:
<...>
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +1
-0@@ -972,6 +1010,7 @@ static void macb_mac_link_up(struct phylink_config *config,spin_lock_irqsave (&bp->lock, flags); bp->link_up = true; + bp->speed_mbps = speed >0 ? speed :0 ; ctrl =macb_or_gem_readl (bp,NCFGR );@@ -1009,6 +1048,15 @@ static void macb_mac_link_up(struct phylink_config *config,Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1051
Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +1
-0spin_unlock_irqrestore (&bp->lock, flags); +if (bp->enst.speed_mbps && speed != bp->enst.speed_mbps) {Why drop the schedule on a speed change? The taprio qdisc stays installed, so the user's configuration is still valid;
Could we instead recompute the ON/OFF times for the new speed on link-up, and only disable (with a warning) the queues whose intervals no longer fit the hardware range at that speed?
Quoted 6 lines
See explanation above. It felt like a good local maximum: simple code that probably doesn't introduce rounding bugs and solves it for most usecases.
In any case, we will sometimes have to drop the qdisc and warn about it.
yes agreed!.
I also looked at a few usage scenarios and at how other implementations handle this (with some AI assistance). They lean towards recalculating on link-up:
- taprio core: keeps the schedule on a speed change and recalculates its speed dependent values (picos_per_byte, max frame durations) from its NETDEV_UP/NETDEV_CHANGE notifier.
- felix / VSC9959 TAS: gates are in ns; on a speed change, vsc9959_sched_speed_set() updates the TAS link speed and calls vsc9959_tas_guard_bands_update() to recalculate the speed dependent parts.
Typical scenario:
- Autoneg downshift 1G -> 100M (damaged cable, 2-pair or M12 cabling, PHY downshift): fairly common in the field. Users expect best-effort traffic to keep flowing, a clear warning, and recovery once the cable is fixed.
That said, I am fine with either approach.
Quoted 13 lines
Quoted 11 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1059
Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c +8
-0+netdev_warn (bp->netdev, +"TAPRIO dropped because link speed changed\n" ); + +memset (&bp->enst,0 ,sizeof (bp->enst)); + } + +macb_apply_enst_config (bp); +Could this be a single
macb_apply_tc_config()(or similar) that reprograms every enabled tc offload? CBS needs exactly the same handling, since idleslope is also relative to the link rate.Yes sure!
Quoted 8 lines
Do you want to take over and handle this? You seem to be interested in those TC features. You can either copy the patch as-is or modify it under your own authorship, I don't mind.
Or if you prefer, I keep it here and iterate. But if I keep it, I'll continue with ENST and then at a later stage we'll add CBS & co onto it. This patch looks like a good starting point to add more onto it.
Your changes look good to me (after generic struct/api), and I am happy with either option. I can take over the patch and make any necessary adjustments alongside the CBS changes, or add CBS support after this series is merged.
Please let me know which you prefer.
Thanks,
Signature · 1 line
🙏 Vineeth
Théo Lebrun
maintainerRe: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
Quoted 41 lines · Vineeth Karumanchi
On 11/19/2026 9:10 PM, Théo Lebrun wrote:
<...>Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +1
-0@@ -972,6 +1010,7 @@ static void macb_mac_link_up(struct phylink_config *config,spin_lock_irqsave (&bp->lock, flags); bp->link_up = true; + bp->speed_mbps = speed >0 ? speed :0 ; ctrl =macb_or_gem_readl (bp,NCFGR );@@ -1009,6 +1048,15 @@ static void macb_mac_link_up(struct phylink_config *config,Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1051
Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +1
-0spin_unlock_irqrestore (&bp->lock, flags); +if (bp->enst.speed_mbps && speed != bp->enst.speed_mbps) {Why drop the schedule on a speed change? The taprio qdisc stays installed, so the user's configuration is still valid;
Could we instead recompute the ON/OFF times for the new speed on link-up, and only disable (with a warning) the queues whose intervals no longer fit the hardware range at that speed?Quoted 6 lines
See explanation above. It felt like a good local maximum: simple code that probably doesn't introduce rounding bugs and solves it for most usecases.
In any case, we will sometimes have to drop the qdisc and warn about it.
yes agreed!.
I also looked at a few usage scenarios and at how other implementations handle this (with some AI assistance). They lean towards recalculating on link-up:
- taprio core: keeps the schedule on a speed change and recalculates its speed dependent values (
picos_per_byte, max frame durations) from its NETDEV_UP/NETDEV_CHANGE notifier.- felix / VSC9959 TAS: gates are in ns; on a speed change,
vsc9959_sched_speed_set()updates the TAS link speed and callsvsc9959_tas_guard_bands_update()to recalculate the speed dependent parts.
Quoted 8 lines
Typical scenario:
- Autoneg downshift 1G -> 100M (damaged cable, 2-pair or M12 cabling, PHY downshift): fairly common in the field. Users expect best-effort traffic to keep flowing, a clear warning, and recovery once the cable is fixed.
That said, I am fine with either approach.
The more I think about it, the more I feel it is fine to drop the TAPRIO schedule as is being done by this patch.
Really, EnST on an unstable link that got downgraded to a lower speed makes no sense. It is used on Time Sensitive Networks and the link down is the major issue in that case, not the EnST schedule being off. Userspace must give us a new schedule that is computed from the link speed. It is just a bit sad we cannot report the qdisc got dropped.
Anyway, this patch is way better than the current situation, and we don't have an easy way to a perfect solution. So I say we go with this and improve if we feel like it is needed later on.
Quoted 23 lines
Quoted 14 lines
Quoted 12 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1059
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +8
-0+netdev_warn (bp->netdev, +"TAPRIO dropped because link speed changed\n" ); + +memset (&bp->enst,0 ,sizeof (bp->enst)); + } + +macb_apply_enst_config (bp); +Could this be a single
macb_apply_tc_config()(or similar) that reprograms every enabled tc offload? CBS needs exactly the same handling, since idleslope is also relative to the link rate.Yes sure!
Quoted 8 lines
Do you want to take over and handle this? You seem to be interested in those TC features. You can either copy the patch as-is or modify it under your own authorship, I don't mind.
Or if you prefer, I keep it here and iterate. But if I keep it, I'll continue with ENST and then at a later stage we'll add CBS & co onto it. This patch looks like a good starting point to add more onto it.
Quoted 6 lines
Your changes look good to me (after generic struct/api), and I am happy with either option. I can take over the patch and make any necessary adjustments alongside the CBS changes, or add CBS support after this series is merged.
Please let me know which you prefer.
Now that I have the patch I'll iterate on it! Thanks for the quick feedback; I'll make sure to CC you from now on.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Théo Lebrun
maintainerRe: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
Hello Théo,
Quoted 92 lines · Théo Lebrun
Quoted 41 lines · Vineeth Karumanchi
On 11/19/2026 9:10 PM, Théo Lebrun wrote:
<...>Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +1
-0@@ -972,6 +1010,7 @@ static void macb_mac_link_up(struct phylink_config *config,spin_lock_irqsave (&bp->lock, flags); bp->link_up = true; + bp->speed_mbps = speed >0 ? speed :0 ; ctrl =macb_or_gem_readl (bp,NCFGR );@@ -1009,6 +1048,15 @@ static void macb_mac_link_up(struct phylink_config *config,Quoted 8 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1051
Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +1
-0spin_unlock_irqrestore (&bp->lock, flags); +if (bp->enst.speed_mbps && speed != bp->enst.speed_mbps) {Why drop the schedule on a speed change? The taprio qdisc stays installed, so the user's configuration is still valid;
Could we instead recompute the ON/OFF times for the new speed on link-up, and only disable (with a warning) the queues whose intervals no longer fit the hardware range at that speed?Quoted 6 lines
See explanation above. It felt like a good local maximum: simple code that probably doesn't introduce rounding bugs and solves it for most usecases.
In any case, we will sometimes have to drop the qdisc and warn about it.
yes agreed!.
I also looked at a few usage scenarios and at how other implementations handle this (with some AI assistance). They lean towards recalculating on link-up:
- taprio core: keeps the schedule on a speed change and recalculates its speed dependent values (
picos_per_byte, max frame durations) from its NETDEV_UP/NETDEV_CHANGE notifier.- felix / VSC9959 TAS: gates are in ns; on a speed change,
vsc9959_sched_speed_set()updates the TAS link speed and callsvsc9959_tas_guard_bands_update()to recalculate the speed dependent parts.Quoted 8 lines
Typical scenario:
- Autoneg downshift 1G -> 100M (damaged cable, 2-pair or M12 cabling, PHY downshift): fairly common in the field. Users expect best-effort traffic to keep flowing, a clear warning, and recovery once the cable is fixed.
That said, I am fine with either approach.
The more I think about it, the more I feel it is fine to drop the TAPRIO schedule as is being done by this patch.
Really, EnST on an unstable link that got downgraded to a lower speed makes no sense. It is used on Time Sensitive Networks and the link down is the major issue in that case, not the EnST schedule being off. Userspace must give us a new schedule that is computed from the link speed. It is just a bit sad we cannot report the qdisc got dropped.
Anyway, this patch is way better than the current situation, and we don't have an easy way to a perfect solution. So I say we go with this and improve if we feel like it is needed later on.
Quoted 28 lines
Quoted 14 lines
Quoted 12 lines
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1059
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +8
-0+netdev_warn (bp->netdev, +"TAPRIO dropped because link speed changed\n" ); + +memset (&bp->enst,0 ,sizeof (bp->enst)); + } + +macb_apply_enst_config (bp); +Could this be a single
macb_apply_tc_config()(or similar) that reprograms every enabled tc offload? CBS needs exactly the same handling, since idleslope is also relative to the link rate.Yes sure!
Quoted 8 lines
Do you want to take over and handle this? You seem to be interested in those TC features. You can either copy the patch as-is or modify it under your own authorship, I don't mind.
Or if you prefer, I keep it here and iterate. But if I keep it, I'll continue with ENST and then at a later stage we'll add CBS & co onto it. This patch looks like a good starting point to add more onto it.
Your changes look good to me (after generic struct/api), and I am happy with either option. I can take over the patch and make any necessary adjustments alongside the CBS changes, or add CBS support after this series is merged.
Quoted 4 lines
Quoted 1 line
Please let me know which you prefer.
Now that I have the patch I'll iterate on it! Thanks for the quick feedback; I'll make sure to CC you from now on.
I just want to bounce back on the "after generic struct/api" you said. Your proposal was of the sort:
struct macb_tc_queue {
struct {
u32 idleslope; /* kbps */
} cbs;
struct {
u32 start_time; /* ENST_START_TIME register value */
u32 on_time_ns; /* gate open interval */
u64 off_time_ns; /* gate closed interval */
} enst;
};
struct macb_tc {
struct macb_tc_queue queues[MACB_MAX_QUEUES];
u32 enst_queue_mask;
// ... etc ...
};
struct macb {
// ... what already exists in struct macb ...
struct macb_tc tc;
};But actually I will keep my patch as-is, because I would much prefer:
// same for cbs, etc.
struct macb_queue_enst_config {
u32 start_time_mask;
u32 on_time_bytes;
u32 off_time_bytes;
};
// same for cbs, etc.
struct macb_enst {
struct macb_queue_enst_config queues[MACB_MAX_QUEUES];
u32 speed_mbps;
u32 queue_mask;
};
struct macb {
// ... what already exists in struct macb ...
struct macb_enst enst;
struct macb_cbs cbs;
// ... etc ...
};The benefit of the latter strategy is two-fold:
- The structs are independent: less patch conflicts and each part can be added one after the other.
- We can memset/memcpy a state; it is used quite a lot in the current patch version. With your proposal, it requires iterating over the queue loop to partially memset/memcpy (or equivalent) each queue.
I wanted this decision to be documented here before I send the next revision.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
[email protected]
AI reviewRe: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
In reply to Théo LebrunThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] In macb_mac_link_up() (drivers/net/ethernet/cadence/macb_main.c:1051), if the link comes…
- [Low] The commit message describes a user-visible defect in the existing TAPRIO offload, but the patch has no Fixes: tag.
--
net: macb: cache ENST config across link down/up
This patch caches the TAPRIO/ENST schedule in bp->enst and writes it again from macb_mac_link_up(). If the link speed has changed, the cached schedule is dropped instead. It also caches the link speed in bp->speed_mbps, serialises taprio replace/destroy with bp->mac_cfg_lock, moves the per-queue config from kmalloc to the stack, and removes the pm_runtime_suspended() check.
Quoted 4 lines
This causes trouble if the config is not compatible with the new open and link-up. The two issues that can occur are a link speed change (as all timings are configured in a unit relative to the link speed) or a change in the # of queues.
[Severity: Low]
Should this patch have a Fixes: tag?
The behaviour described here goes back to commit 89934dbf169e ("net:
macb: Add TAPRIO traffic scheduling support"). In that code, the ENST registers are written only from macb_taprio_setup_replace(), using the link speed at the time of the tc command. Nothing rewrites them on link-up.
So after the link renegotiates to a different speed, the byte-unit ON/OFF timings stay in hardware unchanged. The gate windows are then off by the speed ratio, for example 10x for 1000 -> 100. If register state is lost across close/open, the schedule silently stops being enforced.
This patch depends on newer infrastructure (bp->mac_cfg_lock, bp->link_up), so it may not backport as-is. Even so, would a Fixes: tag, or a note on why this is net-next only, help record that released kernels have this problem?
Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +0
-0
[ ... ]
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1059
Quoted 13 lines
drivers/net/ethernet/cadence/macb_main.c +9
-0@@ -1009,6 +1048,15 @@ static void macb_mac_link_up(struct phylink_config *config,spin_unlock_irqrestore (&bp->lock, flags); +if (bp->enst.speed_mbps && speed != bp->enst.speed_mbps) { +netdev_warn (bp->netdev, +"TAPRIO dropped because link speed changed\n" ); + +memset (&bp->enst,0 ,sizeof (bp->enst)); + } + +macb_apply_enst_config (bp); +
[Severity: Medium]
What happens to the installed taprio qdisc when this branch is taken?
If the link comes back up at a speed other than bp->enst.speed_mbps, the cache is zeroed. macb_apply_enst_config() then writes the disable bits for every queue into ENST_CONTROL and zeroes each queue's ENST_START_TIME, ENST_ON_TIME and ENST_OFF_TIME.
The taprio layer is not told about this. The qdisc stays installed in full offload mode, so tc keeps reporting a hardware-enforced gate schedule that the MAC no longer applies.
The schedule also does not come back if the link returns to its original speed. Take 1000 -> 100 -> 1000: after the first change, bp->enst.speed_mbps is 0, so this check is skipped and the zeroed cache is applied again. Gating stays off until the user reinstalls the qdisc.
Nothing can recompute the schedule later, because struct macb_enst only stores byte units. macb_taprio_setup_replace() converts the nanosecond values and then throws them away:
config.queues[queue_id].on_time_bytes =
enst_ns_to_hw_units(entry->interval, bp->speed_mbps);
config.queues[queue_id].off_time_bytes =
enst_ns_to_hw_units(off, bp->speed_mbps);Could entry->interval and off be cached in nanoseconds instead? Link-up could then recompute the byte values for the new speed with enst_ns_to_hw_units() and check them again against enst_max_hw_interval(). A lower speed only raises the hardware limit, so the schedule would only have to be dropped when it really no longer fits.
The later patches in this series that add set_channels and the Tx SRAM segment distribution do not change this path.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-macb-set-channels-v7-0-2dbc00f686af%40bootlin.com
Théo Lebrun
maintainerRe: [PATCH net-next v7 1/3] net: macb: cache ENST config across link down/up
Hello netdev-bot+sashiko,
Quoted 32 lines · CET,
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] In
macb_mac_link_up()(drivers/net/ethernet/cadence/macb_main.c:1051), if the link comes…
- [Low] The commit message describes a user-visible defect in the existing TAPRIO offload, but the patch has no Fixes: tag.--
net: macb: cache ENST config across link down/up
This patch caches the TAPRIO/ENST schedule in
bp->enstand writes it again frommacb_mac_link_up(). If the link speed has changed, the cached schedule is dropped instead. It also caches the link speed inbp->speed_mbps, serialises taprio replace/destroy withbp->mac_cfg_lock, moves the per-queue config from kmalloc to the stack, and removes thepm_runtime_suspended()check.Quoted 4 lines
This causes trouble if the config is not compatible with the new open and link-up. The two issues that can occur are a link speed change (as all timings are configured in a unit relative to the link speed) or a change in the # of queues.
Quoted 8 lines
[Severity: Low]
Should this patch have a Fixes: tag?The behaviour described here goes back to commit
89934dbf169e("net:
macb: Add TAPRIO traffic scheduling support"). In that code, the ENST registers are written only frommacb_taprio_setup_replace(), using the link speed at the time of the tc command. Nothing rewrites them on link-up.
[...]
Yes, I'll add a 'Fixes' trailer to reference the old commit but I'll mark it as 'Cc: stable+noautosel'; this feels more like a feature (capability to keep TAPRIO across close/open) and I don't think it is useful to backport.
Quoted 54 lines
Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +0
-0[ ... ]
drivers/net/ethernet/cadence/macb_main.c static void macb_mac_link_up(struct phylink_config *config, · line 1059
Quoted 13 lines
drivers/net/ethernet/cadence/macb_main.c +9
-0@@ -1009,6 +1048,15 @@ static void macb_mac_link_up(struct phylink_config *config,spin_unlock_irqrestore (&bp->lock, flags); +if (bp->enst.speed_mbps && speed != bp->enst.speed_mbps) { +netdev_warn (bp->netdev, +"TAPRIO dropped because link speed changed\n" ); + +memset (&bp->enst,0 ,sizeof (bp->enst)); + } + +macb_apply_enst_config (bp); +[Severity: Medium]
What happens to the installed taprio qdisc when this branch is taken?If the link comes back up at a speed other than
bp->enst.speed_mbps, the cache is zeroed.macb_apply_enst_config()then writes the disable bits for every queue intoENST_CONTROLand zeroes each queue'sENST_START_TIME,ENST_ON_TIMEandENST_OFF_TIME.The taprio layer is not told about this. The qdisc stays installed in full offload mode, so tc keeps reporting a hardware-enforced gate schedule that the MAC no longer applies.
The schedule also does not come back if the link returns to its original speed. Take 1000 -> 100 -> 1000: after the first change,
bp->enst.speed_mbpsis 0, so this check is skipped and the zeroed cache is applied again. Gating stays off until the user reinstalls the qdisc.Nothing can recompute the schedule later, because struct
macb_enstonly stores byte units.macb_taprio_setup_replace()converts the nanosecond values and then throws them away:config.queues[queue_id].on_time_bytes = enst_ns_to_hw_units(entry->interval, bp->speed_mbps); config.queues[queue_id].off_time_bytes = enst_ns_to_hw_units(off, bp->speed_mbps);Could
entry->intervaland off be cached in nanoseconds instead? Link-up could then recompute the byte values for the new speed withenst_ns_to_hw_units()and check them again againstenst_max_hw_interval(). A lower speed only raises the hardware limit, so the schedule would only have to be dropped when it really no longer fits.
Quoted 2 lines
The later patches in this series that add
set_channelsand the Tx SRAM segment distribution do not change this path.
So this whole paragraph is correct, see discussion thread with Vineeth. [0] When sending the series, I wasn't sure about my approach. More and more, I think it is the correct one.
- We have no API to drop a qdisc from driver code.
- An EnST schedule is, by definition, link speed sensitive. Userspace must have looked at the link speed to compute the first schedule. If link speed changes, userspace most probably wants another schedule.
- EnST is one part of TSN; the whole point is stable links and deterministic usage of that link. If you get a link speed change, the ENST schedule being wrong is the last of your worries.
So I will *keep my approach*: on TAPRIO_CMD_REPLACE command, we compute our schedule and attach it to a link speed. If we go down and back up at the same link speed, we restore the cached schedule. If the link speed changes, we warn and let userspace deal with it. Sadly we cannot properly drop the qdisc; we can only log a warning.
This is any way much better than the current approach. Currently the EnST registers are only written to on TAPRIO_CMD_{REPLACE,DESTROY}.
- the EnST schedule can be lost if HW resets with close+open
- the EnST schedule can be stale+invalid if the link speed changes
- DESTROY cannot land while link down
[0]: https://lore.kernel.org/all/[email protected]/
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Théo Lebrun
maintainerPATCH v7 2/3 net: macb: implement ethtool_ops.get|set_channels()
In reply to Théo Lebrunbp->num_queues is the total number of queues and is constant from probe. MACB/GEM does not know about Rx/Tx specific queues; it only has combined queues. Move bp->num_queues to ctx->num_queues as it now belongs to the currently active context (bp->ctx).
Also introduce bp->max_num_queues which takes the current role of bp->num_queues and allow 0 < ctx->num_queues <= bp->max_num_queues.
Lastly introduce bp->configured_num_queues to remember queue count across interface down+up cycles.
With all that, implement the .set_channels() operation. It ends up only being an assignment to bp->configured_num_queues plus a call into netif_set_real_num_queues(). However if the interface is running, we use a context swap window to safely realloc on the fly.
Note we refuse the operation if any ENST schedule is in place on a queue we would disable. If we allow the operation to take place, then a transmission window would be reserved but unusable.
Nit: fix an alignment issue inside gem_ethtool_ops which does not deserve its own patch.
--- drivers/net/ethernet/cadence/macb.h | 5 +- drivers/net/ethernet/cadence/macb_main.c | 258 ++++++++++++++++++++++--------- 2 files changed, 191 insertions(+), 72 deletions(-)
drivers/net/ethernet/cadence/macb.h +4 -1
@@ -1292,7 +1292,6 @@ struct macb_info {struct platform_device *pdev;struct net_device *netdev;struct macb_or_gem_ops macbgem_ops; -unsigned int num_queues;u32 caps;int rx_bd_rd_prefetch;int tx_bd_rd_prefetch;
@@ -1323,6 +1322,7 @@ struct macb_context {unsigned int rx_buffer_size;unsigned int rx_ring_size;unsigned int tx_ring_size; +unsigned int num_queues;struct macb_rxq rxq[MACB_MAX_QUEUES ];struct macb_txq txq[MACB_MAX_QUEUES ]; };
@@ -1381,6 +1381,9 @@ struct macb {unsigned int configured_tx_ring_size;struct macb_context *ctx; +unsigned int configured_num_queues; +unsigned int max_num_queues; +struct macb_dma_desc *rx_ring_tieoff;dma_addr_t rx_ring_tieoff_dma;
drivers/net/ethernet/cadence/macb_main.c +187 -71
591 lines not on this page · raw message
Signature · 1 line
2.56.1
Re: [PATCH net-next v7 2/3] net: macb: implement ethtool_ops.get|set_channels()
Hi Théo
Quoted 9 lines · Théo Lebrun
[...]
drivers/net/ethernet/cadence/macb_main.c +2
-0@@ -3376,7 +3398,7 @@ static void macb_context_swap_start(struct macb *bp) +if (new_ctx) { + old_ctx = bp->ctx;
drivers/net/ethernet/cadence/macb_main.c static void macb_context_swap_start(struct macb · line 3439
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+WRITE_ONCE (bp->ctx, new_ctx); +wmb ();/* ensure IRQ enabled below read the new context */ + +macb_init_buffers (bp); + +/* Clear DQL (only on successful context swap). */ +for (q =0 ; q < bp->ctx->num_queues; ++q) +netdev_tx_reset_queue (netdev_get_tx_queue (bp->netdev, + q)); + }
The queues we just dropped never get their BQL reset, not on close or open either. So after shrinking and growing again they can stay stuck.
Maybe just reset all max_num_queues here and in macb_close()?
drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4717
Quoted 12 lines
[...]
drivers/net/ethernet/cadence/macb_main.c +7
-0+static int macb_set_channels (struct net_device *netdev, + ret = netif_set_real_num_queues(bp->netdev, num_queues, num_queues); +if (ret) { +if (running) { +macb_free (new_ctx); +kfree (new_ctx); +macb_context_swap_end (bp,NULL );
swap_start() cleared TE, so HW is back at the ring start. Doesn't this needs a gem_shuffle_tx_rings() like link_up does, otherwise Tx stalls?
Quoted 1 line
[...]
Regards,
Nicolai
Théo Lebrun
maintainerRe: [PATCH net-next v7 2/3] net: macb: implement ethtool_ops.get|set_channels()
Quoted 16 lines · Nicolai Buchwitz
drivers/net/ethernet/cadence/macb_main.c static void macb_context_swap_end(struct macb *bp, · line 3439
Quoted 12 lines · Théo Lebrun
drivers/net/ethernet/cadence/macb_main.c +12
-0+if (new_ctx) { + old_ctx = bp->ctx; +WRITE_ONCE (bp->ctx, new_ctx); +wmb ();/* ensure IRQ enabled below read the new context */ + +macb_init_buffers (bp); + +/* Clear DQL (only on successful context swap). */ +for (q =0 ; q < bp->ctx->num_queues; ++q) +netdev_tx_reset_queue (netdev_get_tx_queue (bp->netdev, + q)); + }The queues we just dropped never get their BQL reset, not on close or open either. So after shrinking and growing again they can stay stuck.
Good catch.
Quoted 1 line
Maybe just reset all
max_num_queueshere and inmacb_close()?
That's the safe solution, agreed.
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4717
Quoted 6 lines
drivers/net/ethernet/cadence/macb_main.c +6
-0+ ret =netif_set_real_num_queues (bp->netdev, num_queues, num_queues); +if (ret) { +if (running) { +macb_free (new_ctx); +kfree (new_ctx); +macb_context_swap_end (bp,NULL );
swap_start()cleared TE, so HW is back at the ring start. Doesn't this needs agem_shuffle_tx_rings()likelink_updoes, otherwise Tx stalls?
Argh! I had missed (or forgotten) this implicit behavior when clearing the TE bit of NCR. Yes gem_shuffle_tx_rings() is meant for that.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
[email protected]
AI reviewRe: [PATCH net-next v7 2/3] net: macb: implement ethtool_ops.get|set_channels()
In reply to Théo LebrunThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
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] When TX queues are disabled, their BQL/DQL state is never reset, so they can stall after a later regrow.
- [Medium] The new rollback path in macb_set_channels() restarts TX on the old rings without realigning the hardware queue pointer.
- [Low] The new comment in macb_init_buffers() (line 514) says that "macb_set_channels(), which is the only way of writing to…
--
net: macb: implement ethtool_ops.get|set_channels()
This commit moves num_queues from struct macb into struct macb_context and adds bp->max_num_queues and bp->configured_num_queues. It then implements the ethtool get_channels/set_channels operations, using the existing context swap window to reallocate rings when the interface is running. Queues beyond the active count are disabled by writing QUEUE_DISABLE to their RBQP/TBQP registers.
Quoted 14 lines
drivers/net/ethernet/cadence/macb_main.c +1
-5@@ -504,11 +504,25 @@ static void macb_init_buffers(struct macb *bp)macb_writel (bp,TBQPH ,upper_32_bits (txq->ring_dma)); } -for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - rxq = &bp->ctx->rxq[q]; - txq = &bp->ctx->txq[q]; -queue_writel (queue,RBQP ,lower_32_bits (rxq->ring_dma)); -queue_writel (queue,TBQP ,lower_32_bits (txq->ring_dma)); +for (q =0 , queue = bp->queues; q < bp->max_num_queues; ++q, ++queue) {
drivers/net/ethernet/cadence/macb_main.c static void macb_init_buffers(struct macb *bp) · line 517
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+if (q < bp->ctx->num_queues) { + rxq = &bp->ctx->rxq[q]; + txq = &bp->ctx->txq[q]; +queue_writel (queue,RBQP ,lower_32_bits (rxq->ring_dma)); +queue_writel (queue,TBQP ,lower_32_bits (txq->ring_dma)); + }else { +/* macb_set_channels(), which is the only way of writing +* to bp->configured_num_queues, is only allowed if +* MACB_CAPS_QUEUE_DISABLE. +*/
[Severity: Low]
This isn't a bug, but is this comment accurate? macb_probe() also writes bp->configured_num_queues:
bp->max_num_queues = num_queues; bp->configured_num_queues = num_queues;
The else branch is still only reached on QUEUE_DISABLE hardware, because macb_set_channels() is the only path that can lower the count below bp->max_num_queues.
Could the comment say that instead?
[ ... ]
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +0
-4@@ -3359,10 +3385,6 @@ static void macb_context_swap_start(struct macb *bp)*/ netif_tx_disable (bp->netdev); -/* Now that everything is stopped, clear DQL. */ -for (q =0 ; q < bp->num_queues; ++q) -netdev_tx_reset_queue (netdev_get_tx_queue (bp->netdev, q)); -/* Safe to call outside bp->lock because bp->irq_quiesced ensures the IRQ
[ ... ]
Quoted 15 lines
drivers/net/ethernet/cadence/macb_main.c +5
-5@@ -3399,16 +3421,26 @@ static void macb_context_swap_end(struct macb *bp,lockdep_assert_held (&bp->mac_cfg_lock); -/* Swap contexts & give buffer pointers to HW. */ +/* Swap contexts & give buffer pointers to HW. +* !new_ctx means that the swap failed and we keep the old context. +*/ - old_ctx = bp->ctx; -WRITE_ONCE (bp->ctx, new_ctx); -wmb ();/* ensure IRQ enabled below read the new context */ -macb_init_buffers (bp); +if (new_ctx) { + old_ctx = bp->ctx;
drivers/net/ethernet/cadence/macb_main.c static void macb_context_swap_end(struct macb *bp, · line 3439
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+WRITE_ONCE (bp->ctx, new_ctx); +wmb ();/* ensure IRQ enabled below read the new context */ + +macb_init_buffers (bp); + +/* Clear DQL (only on successful context swap). */ +for (q =0 ; q < bp->ctx->num_queues; ++q) +netdev_tx_reset_queue (netdev_get_tx_queue (bp->netdev, + q)); + }
[Severity: Medium]
This reset runs after bp->ctx has been switched to new_ctx, so it only covers the new, smaller queue count. Take a running shrink such as "ethtool -L eth0 combined 2" on a 4-queue GEM. What resets the DQL state of queues 2 and 3?
macb_free(old_ctx) at the end of this function frees the in-flight skbs on all 4 old queues. netdev_tx_completed_queue() is never called for those bytes, so num_queued - num_completed stays non-zero on queues 2-3. If BQL had already stopped those queues, __QUEUE_STATE_STACK_XOFF also stays set.
macb_close() only resets the active context's queues:
for (q = 0; q < bp->ctx->num_queues; ++q) netdev_tx_reset_queue(netdev_get_tx_queue(netdev, q));
macb_open() has no reset. netif_set_real_num_tx_queues() does nothing with DQL when queues are re-enabled. So consider this sequence:
ethtool -L eth0 combined 2 (running, TX in flight on queues 2-3) ip link set eth0 down (resets queues 0-1 only) ethtool -L eth0 combined 4 (down, no swap, no reset) ip link set eth0 up (no reset)
Can queues 2-3 come back with stale in-flight bytes and STACK_XOFF still set? The hardware ring would have nothing to complete, and macb_tx_timeout()->macb_tx_restart() doesn't touch DQL. Flows hashed to those queues would stall. Even after a completion, the stale bytes keep dql_completed() from growing the limit.
Before this patch, macb_context_swap_start() and macb_close() both reset every hardware queue. Should these resets cover the old context's queue count, or bp->max_num_queues?
[ ... ]
Quoted 1 line
drivers/net/ethernet/cadence/macb_main.c +0
-0@@ -4618,6 +4658,75 @@ static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
[ ... ]
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +9
-0+if (running) { + new_ctx =macb_context_alloc (bp, num_queues, netdev->mtu, + bp->configured_rx_ring_size, + bp->configured_tx_ring_size); +if (IS_ERR (new_ctx)) +return PTR_ERR (new_ctx); + +macb_context_swap_start (bp); + }
drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4720
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+ + ret =netif_set_real_num_queues (bp->netdev, num_queues, num_queues); +if (ret) { +if (running) { +macb_free (new_ctx); +kfree (new_ctx); +macb_context_swap_end (bp,NULL ); + } +return ret; + }
[Severity: Medium]
Is it safe to restart TX on the old rings here? By this point macb_context_swap_start() has already cleared NCR.TE:
ctrl = macb_readl(bp, NCR); macb_writel(bp, NCR, ctrl & ~(MACB_BIT(RE) | MACB_BIT(TE)));
On GEM, clearing TE resets the transmit queue pointer to the TBQP base, i.e. descriptor 0. Commit 881a0263d502 ("net: macb: Shuffle the tx ring before enabling tx") relies on this, which is why macb_mac_link_up() calls gem_shuffle_tx_rings() before it sets TE again.
With new_ctx == NULL, macb_context_swap_end() skips macb_init_buffers() and doesn't rotate the rings. If bp->link_up is set, it goes straight to:
ctrl = macb_readl(bp, NCR); macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE));
The link never went down, so macb_mac_link_up() and its shuffle don't run.
Would the hardware then restart at descriptor 0 while txq->tail points somewhere else?
If descriptor 0 has TX_USED set, TX stops with TXUBR. macb_tx_restart() then keeps issuing TSTART because TBQP != head, and TX stalls for good.
If descriptor 0 is a middle descriptor of an earlier multi-descriptor (SG/TSO) frame, TX_USED is clear. The DMA would then fetch a buffer that macb_tx_unmap() has already unmapped.
This path is reached when channels are grown on a running, link-up interface and netif_set_real_num_queues() fails with -ENOMEM while allocating the queue kobjects. Does the !new_ctx path in macb_context_swap_end() need the same gem_shuffle_tx_rings() handling as macb_mac_link_up()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-macb-set-channels-v7-0-2dbc00f686af%40bootlin.com
Théo Lebrun
maintainerRe: [PATCH net-next v7 2/3] net: macb: implement ethtool_ops.get|set_channels()
Hello netdev-bot+sashiko,
Quoted 58 lines · CET,
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
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] When TX queues are disabled, their BQL/DQL state is never reset, so they can stall after a later regrow.
- [Medium] The new rollback path inmacb_set_channels()restarts TX on the old rings without realigning the hardware queue pointer.
- [Low] The new comment inmacb_init_buffers()(line 514) says that "macb_set_channels(), which is the only way of writing to…--
net: macb: implement ethtool_ops.get|set_channels()
This commit moves
num_queuesfrom struct macb into structmacb_contextand addsbp->max_num_queuesandbp->configured_num_queues. It then implements the ethtool get_channels/set_channels operations, using the existing context swap window to reallocate rings when the interface is running. Queues beyond the active count are disabled by writingQUEUE_DISABLEto their RBQP/TBQP registers.Quoted 14 lines
drivers/net/ethernet/cadence/macb_main.c +1
-5@@ -504,11 +504,25 @@ static void macb_init_buffers(struct macb *bp)macb_writel (bp,TBQPH ,upper_32_bits (txq->ring_dma)); } -for (q =0 , queue = bp->queues; q < bp->num_queues; ++q, ++queue) { - rxq = &bp->ctx->rxq[q]; - txq = &bp->ctx->txq[q]; -queue_writel (queue,RBQP ,lower_32_bits (rxq->ring_dma)); -queue_writel (queue,TBQP ,lower_32_bits (txq->ring_dma)); +for (q =0 , queue = bp->queues; q < bp->max_num_queues; ++q, ++queue) {drivers/net/ethernet/cadence/macb_main.c static void macb_init_buffers(struct macb *bp) · line 517
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+if (q < bp->ctx->num_queues) { + rxq = &bp->ctx->rxq[q]; + txq = &bp->ctx->txq[q]; +queue_writel (queue,RBQP ,lower_32_bits (rxq->ring_dma)); +queue_writel (queue,TBQP ,lower_32_bits (txq->ring_dma)); + }else { +/* macb_set_channels(), which is the only way of writing +* to bp->configured_num_queues, is only allowed if +* MACB_CAPS_QUEUE_DISABLE. +*/ [Severity: Low]
This isn't a bug, but is this comment accurate?macb_probe()also writesbp->configured_num_queues:
Quoted 8 lines
bp->max_num_queues = num_queues; bp->configured_num_queues = num_queues;The else branch is still only reached on
QUEUE_DISABLEhardware, becausemacb_set_channels()is the only path that can lower the count belowbp->max_num_queues.Could the comment say that instead?
Yes but that's nitpicking. Of course we init bp->configured_num_queues to the hardware's queue count. By saying
macb_set_channels is the only way of writing to configured_num_queues
we mean that macb_set_channels() is the only way to make
bp->configured_num_queues < bp->max_num_queues
Quoted 68 lines
Quoted 9 lines
drivers/net/ethernet/cadence/macb_main.c +0
-4@@ -3359,10 +3385,6 @@ static void macb_context_swap_start(struct macb *bp)*/ netif_tx_disable (bp->netdev); -/* Now that everything is stopped, clear DQL. */ -for (q =0 ; q < bp->num_queues; ++q) -netdev_tx_reset_queue (netdev_get_tx_queue (bp->netdev, q)); -/* Safe to call outside bp->lock because bp->irq_quiesced ensures the IRQ [ ... ]
Quoted 15 lines
drivers/net/ethernet/cadence/macb_main.c +5
-5@@ -3399,16 +3421,26 @@ static void macb_context_swap_end(struct macb *bp,lockdep_assert_held (&bp->mac_cfg_lock); -/* Swap contexts & give buffer pointers to HW. */ +/* Swap contexts & give buffer pointers to HW. +* !new_ctx means that the swap failed and we keep the old context. +*/ - old_ctx = bp->ctx; -WRITE_ONCE (bp->ctx, new_ctx); -wmb ();/* ensure IRQ enabled below read the new context */ -macb_init_buffers (bp); +if (new_ctx) { + old_ctx = bp->ctx;drivers/net/ethernet/cadence/macb_main.c static void macb_context_swap_end(struct macb *bp, · line 3439
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+WRITE_ONCE (bp->ctx, new_ctx); +wmb ();/* ensure IRQ enabled below read the new context */ + +macb_init_buffers (bp); + +/* Clear DQL (only on successful context swap). */ +for (q =0 ; q < bp->ctx->num_queues; ++q) +netdev_tx_reset_queue (netdev_get_tx_queue (bp->netdev, + q)); + }[Severity: Medium]
This reset runs afterbp->ctxhas been switched tonew_ctx, so it only covers the new, smaller queue count. Take a running shrink such as "ethtool -L eth0 combined 2" on a 4-queue GEM. What resets the DQL state of queues 2 and 3?
macb_free(old_ctx)at the end of this function frees the in-flight skbs on all 4 old queues.netdev_tx_completed_queue()is never called for those bytes, sonum_queued-num_completedstays non-zero on queues 2-3. If BQL had already stopped those queues,__QUEUE_STATE_STACK_XOFFalso stays set.
macb_close()only resets the active context's queues:for (q = 0; q < bp->ctx->num_queues; ++q) netdev_tx_reset_queue(netdev_get_tx_queue(netdev, q));
macb_open()has no reset.netif_set_real_num_tx_queues()does nothing with DQL when queues are re-enabled. So consider this sequence:ethtool -L eth0 combined 2 (running, TX in flight on queues 2-3) ip link set eth0 down (resets queues 0-1 only) ethtool -L eth0 combined 4 (down, no swap, no reset) ip link set eth0 up (no reset)Can queues 2-3 come back with stale in-flight bytes and
STACK_XOFFstill set? The hardware ring would have nothing to complete, and macb_tx_timeout()->macb_tx_restart() doesn't touch DQL. Flows hashed to those queues would stall. Even after a completion, the stale bytes keepdql_completed()from growing the limit.
Quoted 3 lines
Before this patch,
macb_context_swap_start()andmacb_close()both reset every hardware queue. Should these resets cover the old context's queue count, orbp->max_num_queues?
Yes, that is correct. Nicolai, a human, already reported that! [0]
V7 resets BQL on the new context queues (ie those that will be active soon) when we should be resetting the old context queues (ie those that were active until now).
To be safe, let's reset all queues here and at close. This will be a in-depth defense barrier if we ever reintroduce such a bug. Otherwise we risk queues that are stalled forever.
[0]: https://lore.kernel.org/all/[email protected]/
Quoted 51 lines
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +9
-0@@ -4618,6 +4658,75 @@ static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) +if (running) { + new_ctx =macb_context_alloc (bp, num_queues, netdev->mtu, + bp->configured_rx_ring_size, + bp->configured_tx_ring_size); +if (IS_ERR (new_ctx)) +return PTR_ERR (new_ctx); + +macb_context_swap_start (bp); + }drivers/net/ethernet/cadence/macb_main.c static int gem_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) · line 4676
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+ + ret =netif_set_real_num_queues (bp->netdev, num_queues, num_queues); +if (ret) { +if (running) { +macb_free (new_ctx); +kfree (new_ctx); +macb_context_swap_end (bp,NULL ); + } +return ret; + }[Severity: Medium]
Is it safe to restart TX on the old rings here? By this pointmacb_context_swap_start()has already cleared NCR.TE:ctrl = macb_readl(bp, NCR); macb_writel(bp, NCR, ctrl & ~(MACB_BIT(RE) | MACB_BIT(TE)));On GEM, clearing TE resets the transmit queue pointer to the TBQP base, i.e. descriptor 0. Commit
881a0263d502("net: macb: Shuffle the tx ring before enabling tx") relies on this, which is whymacb_mac_link_up()callsgem_shuffle_tx_rings()before it sets TE again.With
new_ctx== NULL,macb_context_swap_end()skipsmacb_init_buffers()and doesn't rotate the rings. Ifbp->link_upis set, it goes straight to:ctrl = macb_readl(bp, NCR); macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE));The link never went down, so
macb_mac_link_up()and its shuffle don't run.Would the hardware then restart at descriptor 0 while
txq->tailpoints somewhere else?If descriptor 0 has
TX_USEDset, TX stops with TXUBR.macb_tx_restart()then keeps issuing TSTART because TBQP != head, and TX stalls for good.If descriptor 0 is a middle descriptor of an earlier multi-descriptor (SG/TSO) frame,
TX_USEDis clear. The DMA would then fetch a buffer thatmacb_tx_unmap()has already unmapped.
Quoted 5 lines
This path is reached when channels are grown on a running, link-up interface and
netif_set_real_num_queues()fails with-ENOMEMwhile allocating the queue kobjects. Does the !new_ctx path inmacb_context_swap_end()need the samegem_shuffle_tx_rings()handling asmacb_mac_link_up()?
Yes. Again, Nicolai the human had caught that in his review! [0]
The short summary: stopping the MAC TX engine resets the hardware ring cursors. That means our TX SKBs are at some slot in the ring (like 42). When we restart the MAC TX engine, it will work on slot 0 and not 42.
We already have a solution for this: gem_shuffle_tx_rings(). So that is what's missing from the successful context swap end.
[0]: https://lore.kernel.org/all/[email protected]/
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Théo Lebrun
maintainerPATCH v7 3/3 net: macb: distribute evenly Tx SRAM segments
In reply to Théo LebrunGEM has registers to configure the Tx SRAM segments distribution across active queues. The reset value is appropriate (even spread) but we need to care if/when number of active queues is modified (or if we inherited unevenly initialised hardware from bootloader).
To distribute segments, we take as input the number of queues (current context num_queues) and the number of segments (found inside DCFG6). Its output is a number of segments for each queue, formatted as powers-of-two. For example, 2 for queue 0 means it has 2^2=4 segments.
We define register offset GEM_TXQSEGALLOC_UPPER which is never used. It shall be used when an IP supports >8 number of queues.
Note that the manual mentions explicitly that only active queues are taken into account. So when we write 0x1 in TXQSEGALLOC and a single queue is active, this means we assign (1<<1) == 2 segments to the first (active) queue and none on the others.
--- drivers/net/ethernet/cadence/macb.h | 14 ++++++ drivers/net/ethernet/cadence/macb_main.c | 73 +++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb.h +14 -0
@@ -194,6 +194,10 @@/* Screener Type 2 match registers */ #define GEM_SCRT2 0x540 +/* Tx queue segment allocation */ +#define GEM_TXQSEGALLOC_LOWER 0x05A0 +#define GEM_TXQSEGALLOC_UPPER 0x05A4 +/* EtherType registers */ #define GEM_ETHT 0x06E0
@@ -545,6 +549,8 @@#define GEM_PBUF_CUTTHRU_SIZE 1#define GEM_DAW64_OFFSET 23#define GEM_DAW64_SIZE 1 +#define GEM_SEGMENTS_BIT_SIZE_OFFSET 16 +#define GEM_SEGMENTS_BIT_SIZE_SIZE 4/* Bitfields in DCFG8. */ #define GEM_T1SCR_OFFSET 24
@@ -657,6 +663,13 @@#define GEM_CMPCEN_OFFSET 30/* Compare C Enable */ #define GEM_CMPCEN_SIZE 1 +/* Bitfields in TXQSEGALLOC (Q0 at 2:0, Q1 at 6:4, etc.) */ +#define GEM_TXQSEGALLOC_MASK (q_) \ + ({ \ + typeof(q_) q__ = (q_); \ + GENMASK(4 * (q__) + 2, 4 * (q__)); \ + }) +/* Bitfields in ETHT */ #define GEM_ETHTCMP_OFFSET 0/* EtherType compare value */ #define GEM_ETHTCMP_SIZE 16
@@ -785,6 +798,7 @@#define MACB_CAPS_USRIO_HAS_MII BIT(26)#define MACB_CAPS_USRIO_HAS_REFCLK_SOURCE BIT(27)#define MACB_CAPS_USRIO_HAS_TSUCLK_SOURCE BIT(28) +#define MACB_CAPS_TXQSEGALLOC BIT(29)/* LSO settings */ #define MACB_LSO_UFO_ENABLE 0x01
drivers/net/ethernet/cadence/macb_main.c +71 -2
109 lines not on this page · raw message
Signature · 1 line
2.56.1
Re: [PATCH net-next v7 3/3] net: macb: distribute evenly Tx SRAM segments
Hi Théo
Quoted 13 lines · Théo Lebrun
GEM has registers to configure the Tx SRAM segments distribution across active queues. The reset value is appropriate (even spread) but we need to care if/when number of active queues is modified (or if we inherited unevenly initialised hardware from bootloader).
To distribute segments, we take as input the number of queues (current context
num_queues) and the number of segments (found inside DCFG6). Its output is a number of segments for each queue, formatted as powers-of-two. For example, 2 for queue 0 means it has 2^2=4 segments.We define register offset
GEM_TXQSEGALLOC_UPPERwhich is never used. It shall be used when an IP supports >8 number of queues.
Quoted 8 lines
Note that the manual mentions explicitly that only active queues are taken into account. So when we write
0x1in TXQSEGALLOC and a single queue is active, this means we assign (1<<1) == 2 segments to the first (active) queue and none on the others.Signed-off-by Théo Lebrun <[email protected]>[...]
Thanks,
Nicolai
[email protected]
AI reviewRe: [PATCH net-next v7 3/3] net: macb: distribute evenly Tx SRAM segments
In reply to Théo LebrunThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] gem_sram_distribute_segments() in drivers/net/ethernet/cadence/macb_main.c handles num_queues >=…
- [Low] The comment above static_assert(MACB_MAX_QUEUES == 8) in gem_sram_distribute_segments()…
--
net: macb: distribute evenly Tx SRAM segments
This patch adds gem_sram_distribute_segments(). It programs the GEM TXQSEGALLOC register so that the Tx SRAM segments reported in DCFG6 are spread across the active queues as powers of two. It is called from macb_init_hw() and macb_context_swap_end(), and it is enabled for the zynqmp, versal and eyeq5 configs.
Quoted 12 lines
drivers/net/ethernet/cadence/macb_main.c +4
-0@@ -3319,6 +3319,69 @@ static u32 macb_dbw(struct macb *bp) } } +/* +* Distribute evenly available segments across active queues. The computation +* is complex because (1) segments are counted in powers of two and (2) a queue +* can only use up to 128 segments. There are four types of cases:
[ ... ]
Quoted 2 lines
+ * - Sharing all segments is not doable because not enough segments are
+ * available. Take num_queues=4 and num_segments=2.
[ ... ]
Quoted 6 lines
drivers/net/ethernet/cadence/macb_main.c +6
-0+static void gem_sram_distribute_segments (struct macb *bp) +{ +unsigned int num_segments, pow, remaining_segments, i; +unsigned int num_queues = bp->ctx->num_queues; +unsigned int num_advantaged_queues =0 ; +u32 val =0 ;
drivers/net/ethernet/cadence/macb_main.c static u32 macb_dbw(struct macb *bp) · line 3358
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+ +if (!(bp->caps &MACB_CAPS_TXQSEGALLOC )) +return ; + + num_segments =1U <<GEM_BFEXT (SEGMENTS_BIT_SIZE ,gem_readl (bp,DCFG6 )); + +/* When growing the max # of queues, make sure to return a u64 here and +* to write into GEM_TXQSEGALLOC_UPPER. +*/ +static_assert (MACB_MAX_QUEUES ==8 );
[Severity: Low]
This isn't a bug, but the comment talks about returning a u64. gem_sram_distribute_segments() is a static void function. It builds its result in the local u32 val and writes it with:
gem_writel(bp, TXQSEGALLOC_LOWER, val);
To support more than 8 queues, wouldn't the change be to widen (or split) val and add a second write to TXQSEGALLOC_UPPER, rather than to change a return type? Could the comment say that instead?
drivers/net/ethernet/cadence/macb_main.c static u32 macb_dbw(struct macb *bp) · line 3362
Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +4
-0+ +/* pow=0 for all queues. ilog2(0) is dangerous. */ +if (num_queues >= num_segments) + goto writel;
[Severity: Low]
What happens here when num_queues is strictly greater than num_segments?
TXQSEGALLOC fields hold log2 of the segment count. The commit message says "2 for queue 0 means it has 2^2=4 segments", so a field value of 0 means 1 segment, not zero segments.
When num_queues == num_segments, val = 0 gives each queue 1 segment and the total matches the SRAM size.
When num_queues > num_segments, every active queue still gets 1 segment. Take the example from the header comment, "num_queues=4 and num_segments=2". It ends up programmed as 4 x 1 = 4 segments, but DCFG6 reports only 2.
Doesn't that give the hardware more Tx SRAM segments than it has, with nothing logged? The header comment presents this case as handled.
Would it be better to limit the number of active queues to num_segments in this case? Another option is to warn and keep the reset value instead of writing 0.
Quoted 3 lines
drivers/net/ethernet/cadence/macb_main.c +3
-0+ + pow = min_t(unsigned int, ilog2(num_segments / num_queues), 7); + remaining_segments = num_segments - num_queues * (1U << pow);
[ ... ]
Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +4
-0+ +writel: +gem_writel (bp,TXQSEGALLOC_LOWER , val); +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-macb-set-channels-v7-0-2dbc00f686af%40bootlin.com
Théo Lebrun
maintainerRe: [PATCH net-next v7 3/3] net: macb: distribute evenly Tx SRAM segments
Hello netdev-bot+sashiko,
Quoted 63 lines · CET,
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low]
gem_sram_distribute_segments()indrivers/net/ethernet/cadence/macb_main.chandlesnum_queues>=…
- [Low] The comment abovestatic_assert(MACB_MAX_QUEUES == 8)in gem_sram_distribute_segments()…--
net: macb: distribute evenly Tx SRAM segments
This patch adds
gem_sram_distribute_segments(). It programs the GEM TXQSEGALLOC register so that the Tx SRAM segments reported in DCFG6 are spread across the active queues as powers of two. It is called frommacb_init_hw()andmacb_context_swap_end(), and it is enabled for the zynqmp, versal and eyeq5 configs.Quoted 12 lines
drivers/net/ethernet/cadence/macb_main.c +4
-0@@ -3319,6 +3319,69 @@ static u32 macb_dbw(struct macb *bp) } } +/* +* Distribute evenly available segments across active queues. The computation +* is complex because (1) segments are counted in powers of two and (2) a queue +* can only use up to 128 segments. There are four types of cases: [ ... ]
Quoted 2 lines
+ * - Sharing all segments is not doable because not enough segments are
+ * available. Take num_queues=4 and num_segments=2.[ ... ]
Quoted 6 lines
drivers/net/ethernet/cadence/macb_main.c +6
-0+static void gem_sram_distribute_segments (struct macb *bp) +{ +unsigned int num_segments, pow, remaining_segments, i; +unsigned int num_queues = bp->ctx->num_queues; +unsigned int num_advantaged_queues =0 ; +u32 val =0 ;drivers/net/ethernet/cadence/macb_main.c static u32 macb_dbw(struct macb *bp) · line 3358
Quoted 10 lines
drivers/net/ethernet/cadence/macb_main.c +10
-0+ +if (!(bp->caps &MACB_CAPS_TXQSEGALLOC )) +return ; + + num_segments =1U <<GEM_BFEXT (SEGMENTS_BIT_SIZE ,gem_readl (bp,DCFG6 )); + +/* When growing the max # of queues, make sure to return a u64 here and +* to write into GEM_TXQSEGALLOC_UPPER. +*/ +static_assert (MACB_MAX_QUEUES ==8 );[Severity: Low]
This isn't a bug, but the comment talks about returning a u64.gem_sram_distribute_segments()is a static void function. It builds its result in the local u32 val and writes it with:
Quoted 5 lines
gem_writel(bp, TXQSEGALLOC_LOWER, val);To support more than 8 queues, wouldn't the change be to widen (or split) val and add a second write to
TXQSEGALLOC_UPPER, rather than to change a return type? Could the comment say that instead?
Yes; we shall replace:
When growing the max # of queues, make sure to return a u64 here and to write into GEM_TXQSEGALLOC_UPPER.
By:
When growing the max # of queues, make sure to write into TXQSEGALLOC_UPPER.
For the full story for why this comment went stale:gem_sram_distribute_segments() used to return a u64 with the low 32 bits written into LOWER and the high 32 bits written into UPPER. That returned value was then writel() by the caller. But now that it can be called from two places, the writel() was moved into the function to avoid code duplication.
Quoted 7 lines
drivers/net/ethernet/cadence/macb_main.c static u32 macb_dbw(struct macb *bp) · line 3362
Quoted 4 lines
drivers/net/ethernet/cadence/macb_main.c +4
-0+ +/* pow=0 for all queues. ilog2(0) is dangerous. */ +if (num_queues >= num_segments) + goto writel;[Severity: Low]
What happens here whennum_queuesis strictly greater thannum_segments?
I don't know, but this is not our worry.
This check has been introduced to deal with the equality case. From my understanding, num_queues > num_segments is unreachable.
And if num_queues > num_segments ever occurs, yes, we give each active queue 1 segment by doing a:
writel(0, TXQSEGALLOC_LOWER)
We will *not* introduce code to lower max_num_queues if num_segments is found to be lower than the runtime detected queue count from macb_probe_queues(). This would be useless.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com