From: "Karumanchi, Vineeth" <vineeth@amd.com>
To: "Théo Lebrun" <theo.lebrun@bootlin.com>,
"Vineeth Karumanchi" <vineeth.karumanchi@amd.com>,
conor.dooley@microchip.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: git@amd.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 4/4] net: macb: Add TSN CBS TC offload support
Date: Thu, 8 Oct 2026 20:57:50 +0530 [thread overview]
Message-ID: <a04aa4d5-335b-47c1-b969-e89b18c9b142@amd.com> (raw)
In-Reply-To: <DLHHKM7ZOTWD.1W25GJL8Z0G7Q@bootlin.com>
Hi Théo,
On 9/17/2026 3:02 PM, Théo Lebrun wrote:
> Hello Vineeth,
>
> On Wed Sep 9, 2026 at 4:20 PM CEST, Vineeth Karumanchi wrote:
>> Add Credit-Based Shaper (CBS/IEEE 802.1Qav) TC offload support for
>> time-sensitive networking on GEM hardware. CBS is restricted to the
>> two highest-priority queues: Queue A (num_queues - 1) and Queue B
>> (num_queues - 2), matching hardware capability.
>>
>> Validate that idleslope is positive and does not exceed the link
>> speed, preventing negative values from bypassing the bounds check
>> due to signed-to-unsigned promotion.
>>
>> The idle slope register value is computed differently based on hardware
>> variant:
>>
>> High-speed GEM: scale idleslope linearly to the full 32-bit register
>> range relative to link speed.
>>
>> Standard MACB: convert the kbps idleslope into the register's native
>> unit, which depends on the interface width:
>> - 1G (8-bit GMII): bytes/sec, scale kbps by 1000/8 (125)
>> - 10/100M (4-bit MII): nibbles/sec, scale kbps by 1000/4 (250)
>>
>> Signed-off-by: Vineeth Karumanchi <vineeth.karumanchi@amd.com>
>> ---
>> Changes in v2:
>> - macb_cbs_get_queue_params() now returns the idleslope register offset
>> (u32 *idleslope_reg) instead of a bool flag, and the idleslope is
>> programmed via bp->macb_reg_writel(), dropping the per-queue if/else
>> that open-coded gem_writel(CBS_IDLESLOPE_Q_A/Q_B).
>> - Expanded the idleslope kbps-to-hardware-unit conversion comment.
>> - Zero-initialize kset in macb_cbs_add() so an unpopulated link speed
>> reads as 0 and is rejected; reorder locals to keep the declarations
>> in reverse-christmas-tree order.
>> - Rebased on net-next, which renamed the struct net_device pointer to
>> "netdev" (was "dev"/"ndev").
>>
>> drivers/net/ethernet/cadence/macb.h | 9 ++
>> drivers/net/ethernet/cadence/macb_main.c | 116 +++++++++++++++++++++++
>> 2 files changed, 125 insertions(+)
>>
> [...]
>> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
>> index 67150ff03066..00c1c619dea8 100644
>> --- a/drivers/net/ethernet/cadence/macb_main.c
>> +++ b/drivers/net/ethernet/cadence/macb_main.c
>> +static int macb_cbs_add(struct net_device *netdev,
>> + struct tc_cbs_qopt_offload *qopt)
>> +{
> [...]
>> + scoped_guard(spinlock_irqsave, &bp->lock) {
>> + /* Disable CBS for the queue before updating idleslope */
>> + ctrl = gem_readl(bp, CBS_CONTROL) & ~enable_bit;
>> + gem_writel(bp, CBS_CONTROL, ctrl);
>> + /* Update idleslope for the queue */
>> + bp->macb_reg_writel(bp, idleslope_reg, idleslope);
>> + /* Re-enable CBS for the queue with new idleslope */
>> + gem_writel(bp, CBS_CONTROL, ctrl | enable_bit);
>> + }
>> +
>> + netdev_dbg(netdev, "CBS: Configured queue %d with idleslope 0x%x\n",
>> + qopt->queue, idleslope);
>> +
>> + return 0;
>> +}
>> +
>> +static void macb_cbs_destroy(struct net_device *netdev, u8 queue_num)
>> +{
>> + struct macb *bp = netdev_priv(netdev);
>> + u32 enable_bit, idleslope_reg;
>> +
>> + if (macb_cbs_get_queue_params(bp, queue_num, &enable_bit, &idleslope_reg))
>> + return;
>> +
>> + scoped_guard(spinlock_irqsave, &bp->lock) {
>> + gem_writel(bp, CBS_CONTROL, gem_readl(bp, CBS_CONTROL) & ~enable_bit);
>> + bp->macb_reg_writel(bp, idleslope_reg, 0);
>> + }
>> +
>> + netdev_dbg(netdev, "CBS: Disabled queue %d\n", queue_num);
>> +}
>
> 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).
>
> 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.
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.
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.
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.
- 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 invoke macb_init_hw().
Please let me know your thoughts on these approaches.
Thanks,
> [...]
>
> Thanks,
>
> --
> Théo Lebrun, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
--
🙏 Vineeth
prev parent reply other threads:[~2026-10-08 15:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 14:20 [PATCH net-next v2 0/4] net: macb: Add TSN MQPRIO and CBS traffic-class offload Vineeth Karumanchi
2026-09-09 14:20 ` [PATCH net-next v2 1/4] net: macb: Rename MACB_CAPS_QBV to MACB_CAPS_TC Vineeth Karumanchi
2026-09-17 9:37 ` Théo Lebrun
2026-09-09 14:20 ` [PATCH net-next v2 2/4] net: macb: Move TC capability and PM checks to macb_setup_tc() Vineeth Karumanchi
2026-09-10 14:44 ` netdev-bot+sashiko
2026-09-15 13:40 ` Karumanchi, Vineeth
2026-09-09 14:20 ` [PATCH net-next v2 3/4] net: macb: Add MQPRIO qdisc hardware offload support Vineeth Karumanchi
2026-09-10 14:44 ` netdev-bot+sashiko
2026-09-17 9:22 ` Théo Lebrun
2026-09-17 13:57 ` Karumanchi, Vineeth
2026-09-09 14:20 ` [PATCH net-next v2 4/4] net: macb: Add TSN CBS TC " Vineeth Karumanchi
2026-09-10 14:44 ` netdev-bot+sashiko
2026-09-17 9:32 ` Théo Lebrun
2026-10-08 15:27 ` Karumanchi, Vineeth [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a04aa4d5-335b-47c1-b969-e89b18c9b142@amd.com \
--to=vineeth@amd.com \
--cc=andrew+netdev@lunn.ch \
--cc=conor.dooley@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=git@amd.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=theo.lebrun@bootlin.com \
--cc=vineeth.karumanchi@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox