From: "claudiu beznea (tuxon)" <claudiu.beznea@tuxon.dev>
To: Vineeth Karumanchi <vineeth.karumanchi@amd.com>,
nicolas.ferre@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 3/6] net: macb: Add IEEE 802.1Qbv TAPRIO REPLACE command offload support
Date: Sat, 26 Jul 2025 15:25:57 +0300 [thread overview]
Message-ID: <64481774-9791-4453-ab81-e4f0c444a2a6@tuxon.dev> (raw)
In-Reply-To: <20250722154111.1871292-4-vineeth.karumanchi@amd.com>
On 7/22/25 18:41, Vineeth Karumanchi wrote:
> Implement Time-Aware Traffic Scheduling (TAPRIO) hardware offload for
> "tc qdisc replace" operations, enabling IEEE 802.1Qbv compliant gate
> scheduling on Cadence MACB/GEM controllers.
>
> Parameter validation checks performed:
> - Queue count bounds checking (1 < queues <= MACB_MAX_QUEUES)
> - TC entry limit validation against available hardware queues
> - Base time non-negativity enforcement
> - Speed-adaptive timing constraint verification
> - Cycle time vs. total gate time consistency checks
> - Single-queue gate mask enforcement per scheduling entry
>
> Hardware programming sequence:
> - GEM doesn't support changing register values if ENST is running,
> hence disable ENST before programming
> - Atomic timing register configuration (START_TIME, ON_TIME, OFF_TIME)
> - Enable the configured queues via ENST_CONTROL register
>
> This implementation ensures deterministic gate scheduling while preventing
> invalid configurations.
>
> Signed-off-by: Vineeth Karumanchi <vineeth.karumanchi@amd.com>
> ---
> drivers/net/ethernet/cadence/macb_main.c | 155 +++++++++++++++++++++++
> 1 file changed, 155 insertions(+)
>
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index ff87d3e1d8a0..4518b59168d5 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -36,6 +36,7 @@
> #include <linux/reset.h>
> #include <linux/firmware/xlnx-zynqmp.h>
> #include <linux/inetdevice.h>
> +#include <net/pkt_sched.h>
> #include "macb.h"
>
> /* This structure is only used for MACB on SiFive FU540 devices */
> @@ -4084,6 +4085,160 @@ static void macb_restore_features(struct macb *bp)
> macb_set_rxflow_feature(bp, features);
> }
>
> +static int macb_taprio_setup_replace(struct net_device *ndev,
> + struct tc_taprio_qopt_offload *conf)
This function is unused in this patch. Nothing mentions it.
> +{
> + u64 total_on_time = 0, start_time_sec = 0, start_time = conf->base_time;
> + struct queue_enst_configs *enst_queue;
Extra space here -----------------^
> + u32 configured_queues = 0, speed = 0;
> + struct tc_taprio_sched_entry *entry;
> + struct macb *bp = netdev_priv(ndev);
> + struct ethtool_link_ksettings kset;
> + struct macb_queue *queue;
> + unsigned long flags;
> + int err = 0, i;
No need to initialize err with zero.
size_t i;
as it is used along with conf->num_entries which has size_t type.
> +
> + /* Validate queue configuration */
> + if (bp->num_queues < 1 || bp->num_queues > MACB_MAX_QUEUES) {
Can this happen?
> + netdev_err(ndev, "Invalid number of queues: %d\n", bp->num_queues);
> + return -EINVAL;
> + }
> +
> + if (conf->num_entries > bp->num_queues) {
> + netdev_err(ndev, "Too many TAPRIO entries: %lu > %d queues\n",
> + conf->num_entries, bp->num_queues);
> + return -EINVAL;
> + }
> +
> + if (start_time < 0) {
> + netdev_err(ndev, "Invalid base_time: must be 0 or positive, got %lld\n",
> + conf->base_time);
> + return -ERANGE;
> + }
> +
> + /* Get the current link speed */
> + err = phylink_ethtool_ksettings_get(bp->phylink, &kset);
> + if (unlikely(err)) {
> + netdev_err(ndev, "Failed to get link settings: %d\n", err);
> + return err;
> + }
> +
> + speed = kset.base.speed;
> + if (unlikely(speed <= 0)) {
> + netdev_err(ndev, "Invalid speed: %d\n", speed);
> + return -EINVAL;
> + }
> +
> + enst_queue = kcalloc(conf->num_entries, sizeof(*enst_queue), GFP_KERNEL);
To simplify the error path you can use something like:
struct queue_enst_configs *enst_queue __free(kfree) = kcalloc(...);
and drop the "goto cleanup" below.
> + if (!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];
> +
> + if (entry->command != TC_TAPRIO_CMD_SET_GATES) {
> + netdev_err(ndev, "Entry %d: unsupported command %d\n",
> + i, entry->command);
> + err = -EOPNOTSUPP;
> + goto cleanup;
> + }
> +
> + /* Validate gate_mask: must be nonzero, single queue, and within range */
> + if (!is_power_of_2(entry->gate_mask)) {
> + netdev_err(ndev, "Entry %d: 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;
> + }
> +
> + /* gate_mask must not select queues outside the valid queue_mask */
> + if (entry->gate_mask & ~bp->queue_mask) {
> + netdev_err(ndev, "Entry %d: gate_mask 0x%x exceeds queue range (max_queues=%d)\n",
> + i, entry->gate_mask, bp->num_queues);
> + err = -EINVAL;
> + goto cleanup;
> + }
> +
> + /* Check for start time limits */
> + start_time_sec = div_u64(start_time, NSEC_PER_SEC);
> + if (start_time_sec > ENST_MAX_START_TIME_SEC) {
> + netdev_err(ndev, "Entry %d: Start time %llu s exceeds hardware limit\n",
> + i, start_time_sec);
> + err = -ERANGE;
> + goto cleanup;
> + }
> +
> + /* Check for on time limit*/
Missing one space here -------------------^
> + if (entry->interval > ENST_MAX_HW_INTERVAL(speed)) {
> + netdev_err(ndev, "Entry %d: interval %u ns exceeds hardware limit %lu ns\n",
> + i, entry->interval, ENST_MAX_HW_INTERVAL(speed));
> + err = -ERANGE;
> + goto cleanup;
> + }
> +
> + /* Check for off time limit*/
> + if ((conf->cycle_time - entry->interval) > ENST_MAX_HW_INTERVAL(speed)) {
> + netdev_err(ndev, "Entry %d: off_time %llu ns exceeds hardware limit %lu ns\n",
> + i, conf->cycle_time - entry->interval,
> + ENST_MAX_HW_INTERVAL(speed));
> + err = -ERANGE;
> + goto cleanup;
> + }
> +
> + enst_queue[i].queue_id = order_base_2(entry->gate_mask);
> + enst_queue[i].start_time_mask =
> + (start_time_sec << GEM_START_TIME_SEC_OFFSET) |
> + (start_time % NSEC_PER_SEC);
> + enst_queue[i].on_time_bytes =
> + ENST_NS_TO_HW_UNITS(entry->interval, speed);
> + enst_queue[i].off_time_bytes =
> + ENST_NS_TO_HW_UNITS(conf->cycle_time - entry->interval, speed);
> +
> + configured_queues |= entry->gate_mask;
> + total_on_time += entry->interval;
> + start_time += entry->interval;
> + }
> +
> + /* Check total interval doesn't exceed cycle time */
> + if (total_on_time > conf->cycle_time) {
> + netdev_err(ndev, "Total ON %llu ns exceeds cycle time %llu ns\n",
> + total_on_time, conf->cycle_time);
> + err = -EINVAL;
> + goto cleanup;
> + }
> +
> + netdev_dbg(ndev, "TAPRIO setup: %lu 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 */
> + spin_lock_irqsave(&bp->lock, flags);
You can use guard(spinlock_irqsave)(&bp->lock) or scoped_guard(spinlock_irqsave,
&bp->lock)
> +
> + /* Disable ENST queues if running before configuring */
> + if (gem_readl(bp, ENST_CONTROL))
Is this read necessary?
> + gem_writel(bp, ENST_CONTROL,
> + GENMASK(bp->num_queues - 1, 0) << GEM_ENST_DISABLE_QUEUE_OFFSET);
This could be replaced by GEM_BF(GENMASK(...), ENST_DISABLE_QUEUE) if you define
GEM_ENST_DISABLE_QUEUE_SIZE along with GEM_ENST_DISABLE_QUEUE_OFFSET.
> +
> + for (i = 0; i < conf->num_entries; i++) {
> + queue = &bp->queues[enst_queue[i].queue_id];
> + /* Configure queue timing registers */
> + queue_writel(queue, ENST_START_TIME, enst_queue[i].start_time_mask);
> + queue_writel(queue, ENST_ON_TIME, enst_queue[i].on_time_bytes);
> + queue_writel(queue, ENST_OFF_TIME, enst_queue[i].off_time_bytes);
> + }
> +
> + /* Enable ENST for all configured queues in one write */
> + gem_writel(bp, ENST_CONTROL, configured_queues);
Can this function be executed while other queues are configured? If so, would
the configured_queues contains it (as well as conf)?
> + spin_unlock_irqrestore(&bp->lock, flags);
> +
> + netdev_info(ndev, "TAPRIO configuration completed successfully: %lu entries, %d queues configured\n",
> + conf->num_entries, hweight32(configured_queues));
> +
> +cleanup:
> + kfree(enst_queue);
With the suggestions above, this could be dropped.
Thank you,
Claudiu
> + return err;
> +}
> +
> static const struct net_device_ops macb_netdev_ops = {
> .ndo_open = macb_open,
> .ndo_stop = macb_close,
next prev parent reply other threads:[~2025-07-26 12:26 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-22 15:41 [PATCH net-next 0/6] net: macb: Add TAPRIO traffic scheduling support Vineeth Karumanchi
2025-07-22 15:41 ` [PATCH net-next 1/6] net: macb: Define ENST hardware registers for time-aware scheduling Vineeth Karumanchi
2025-07-26 12:23 ` claudiu beznea (tuxon)
2025-07-22 15:41 ` [PATCH net-next 2/6] net: macb: Integrate ENST timing parameters and hardware unit conversion Vineeth Karumanchi
2025-07-26 12:24 ` claudiu beznea (tuxon)
2025-07-22 15:41 ` [PATCH net-next 3/6] net: macb: Add IEEE 802.1Qbv TAPRIO REPLACE command offload support Vineeth Karumanchi
2025-07-23 10:02 ` kernel test robot
2025-07-26 12:25 ` claudiu beznea (tuxon) [this message]
2025-07-26 15:32 ` Andrew Lunn
2025-07-29 8:59 ` Karumanchi, Vineeth
2025-07-31 9:07 ` Claudiu Beznea
2025-07-22 15:41 ` [PATCH net-next 4/6] net: macb: Implement TAPRIO DESTROY command offload for gate cleanup Vineeth Karumanchi
2025-07-26 12:26 ` claudiu beznea (tuxon)
2025-07-22 15:41 ` [PATCH net-next 5/6] net: macb: Implement TAPRIO TC offload command interface Vineeth Karumanchi
2025-07-26 12:29 ` claudiu beznea (tuxon)
2025-07-29 9:38 ` Karumanchi, Vineeth
2025-07-31 9:07 ` Claudiu Beznea
2025-07-28 16:31 ` kernel test robot
2025-07-22 15:41 ` [PATCH net-next 6/6] net: macb: Add MACB_CAPS_QBV capability flag for IEEE 802.1Qbv support Vineeth Karumanchi
2025-07-23 19:05 ` Simon Horman
2025-07-29 9:42 ` Karumanchi, Vineeth
2025-07-24 0:46 ` kernel test robot
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=64481774-9791-4453-ab81-e4f0c444a2a6@tuxon.dev \
--to=claudiu.beznea@tuxon.dev \
--cc=andrew+netdev@lunn.ch \
--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=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.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
all inboxes | Powered by JetHome®