net: macb: implement ethtool set channels count operation
Subsystems (3)
Théo Lebrun
maintainerv8 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 v8:
- Reset BQL for all queues at swap end and at close. The minimal amount
of work would be to reset only the active queues, but let's be safe
about it. A bug here is a forever stale that will never resolve, not
even on close+open.
- Shuffle the TX ring on swap failure. The HW resets its cursors
automatically, so we must bring TX SKBs to the start of the ring
before restarting the TX engine.
- Fix a stale comment in gem_sram_distribute_segments().
- Rebased onto latest net-next/main (c2621b518b38); nothing to report.
- Link to v7: https://patch.msgid.link/[email protected]
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 | 514 +++++++++++++++++++++---------- 2 files changed, 399 insertions(+), 181 deletions(-)
---
base-commit: c2621b518b38ed38e280e008aa33e6c2d302f8cc
change-id: 20260305-macb-set-channels-5bf6e07f3270
Best regards,
Signature · 1 line
Théo Lebrun <[email protected]>
Théo Lebrun
maintainerPATCH v8 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
Théo Lebrun
maintainerPATCH v8 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 | 260 ++++++++++++++++++++++--------- 2 files changed, 193 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 +189 -71
593 lines not on this page · raw message
Signature · 1 line
2.56.1
Théo Lebrun
maintainerPATCH v8 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