net: sparx5: add TAS offload
Subsystems (4)
Daniel Machon
maintainercover net: sparx5: add TAS offload
This series adds offload of the Time Aware Shaper (IEEE 802.1Qbv), configured through tc-taprio, on Sparx5 and lan969x, which are both served by the sparx5 driver.
In hardware, a TAS schedule is run by a TAS list, which steps through gate control list (GCL) entries taken from a pool shared by all ports. Sparx5 has 128 lists and 10000 GCL entries, lan969x has 60 lists and 3000 entries. An idle list is in the ADMIN state. Once started, it is PENDING until its base time, then OPERATING. A stopped list is TERMINATING until the end of its cycle, and then goes back to ADMIN.
The driver uses two lists per port, so a new schedule can be set up in one list while the current one keeps running in the other. When the new list reaches its base time, the hardware stops the old one.
The two chips differ in how a list addresses its entries: on Sparx5 a list is a contiguous range addressed relative to its base, on lan969x it is a linked list addressed by absolute pool index. The driver handles both.
Frame preemption is not supported yet, and every queue uses the default guard band of 1536 bytes. Making the guard band follow the MTU, and taprio queueMaxSDU, are left for a follow-up.
Patch #1 adds the registers used by TAS.
Patch #2 moves the existing TAS link speed configuration to a new sparx5_tas.c.
Patch #3 adds the taprio offload.
---
Daniel Machon (3):
net: sparx5: Add registers used by TAS
net: sparx5: Move TAS link speed configuration to sparx5_tas.c
net: sparx5: Add TAS offload support
drivers/net/ethernet/microchip/sparx5/Makefile | 2 +- .../ethernet/microchip/sparx5/lan969x/lan969x.c | 2 + .../microchip/sparx5/lan969x/lan969x_regs.c | 10 + .../net/ethernet/microchip/sparx5/sparx5_main.c | 2 + .../net/ethernet/microchip/sparx5/sparx5_main.h | 28 + .../ethernet/microchip/sparx5/sparx5_main_regs.h | 204 ++++++ drivers/net/ethernet/microchip/sparx5/sparx5_qos.c | 53 +- drivers/net/ethernet/microchip/sparx5/sparx5_qos.h | 1 - .../net/ethernet/microchip/sparx5/sparx5_regs.c | 10 + .../net/ethernet/microchip/sparx5/sparx5_regs.h | 10 + drivers/net/ethernet/microchip/sparx5/sparx5_tas.c | 806 +++++++++++++++++++++ drivers/net/ethernet/microchip/sparx5/sparx5_tc.c | 17 + 12 files changed, 1094 insertions(+), 51 deletions(-)
---
base-commit: a5e7d8e446af9803e37a3b6a4d416fb41178348f
change-id: 20261006-sparx5-tas-20de2210770d
Best regards,
Signature · 1 line
Daniel Machon <[email protected]>
Daniel Machon
maintainerPATCH 1/3 net: sparx5: Add registers used by TAS
Add the registers and offset definitions used to configure the Time Aware Shaper (802.1Qbv) in hardware, on both sparx5 and lan969x.
--- .../microchip/sparx5/lan969x/lan969x_regs.c | 10 + .../ethernet/microchip/sparx5/sparx5_main_regs.h | 204 +++++++++++++++++++++ .../net/ethernet/microchip/sparx5/sparx5_regs.c | 10 + .../net/ethernet/microchip/sparx5/sparx5_regs.h | 10 + 4 files changed, 234 insertions(+)
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c +10 -0
@@ -96,6 +96,9 @@ const unsigned int lan969x_gaddr[GADDR_LAST] = { [GA_HSCH_MMGT] = 36260, [GA_HSCH_TAS_CONFIG] = 37696, [GA_HSCH_TAS_PROFILE_CFG] = 37712, + [GA_HSCH_TAS_LIST_CFG] = 36288, + [GA_HSCH_TAS_GCL_CFG] = 36240, + [GA_HSCH_HSCH_TAS_STATE] = 36256, [GA_PTP_PTP_CFG] = 512, [GA_PTP_PTP_TOD_DOMAINS] = 528, [GA_PTP_PHASE_DETECTOR_CTRL] = 628,
@@ -147,6 +150,7 @@ const unsigned int lan969x_gsize[GSIZE_LAST] = { [GW_GCB_CHIP_REGS] = 180, [GW_HSCH_TAS_CONFIG] = 16, [GW_HSCH_TAS_PROFILE_CFG] = 68, + [GW_HSCH_TAS_GCL_CFG] = 16, [GW_PTP_PHASE_DETECTOR_CTRL] = 12, [GW_QSYS_PAUSE_CFG] = 988, };
@@ -201,6 +205,12 @@ const unsigned int lan969x_fsize[FSIZE_LAST] = { [FW_HSCH_HSCH_LEAK_CFG_LEAK_FIRST] = 14, [FW_HSCH_FLUSH_CTRL_FLUSH_PORT] = 6, [FW_HSCH_FLUSH_CTRL_FLUSH_HIER] = 14, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM_MAX] = 6, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM] = 6, + [FW_HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM] = 12, + [FW_HSCH_TAS_GATE_STATE_CTRL_HSCH_POS] = 11, + [FW_HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX] = 6, + [FW_HSCH_TAS_LIST_CFG_LIST_BASE_ADDR] = 12, [FW_LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_DIRECT_ROW] = 13, [FW_LRN_MAC_ACCESS_CFG_3_MAC_ENTRY_ISDX_LIMIT_IDX] = 8, [FW_LRN_AUTOAGE_CFG_2_NEXT_ROW] = 13,
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +204 -0
222 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_regs.c +10 -0
@@ -96,6 +96,9 @@ const unsigned int sparx5_gaddr[GADDR_LAST] = { [GA_HSCH_MMGT] = 162368, [GA_HSCH_TAS_CONFIG] = 162384, [GA_HSCH_TAS_PROFILE_CFG] = 188416, + [GA_HSCH_TAS_LIST_CFG] = 161600, + [GA_HSCH_TAS_GCL_CFG] = 161584, + [GA_HSCH_HSCH_TAS_STATE] = 161580, [GA_PTP_PTP_CFG] = 320, [GA_PTP_PTP_TOD_DOMAINS] = 336, [GA_PTP_PHASE_DETECTOR_CTRL] = 420,
@@ -147,6 +150,7 @@ const unsigned int sparx5_gsize[GSIZE_LAST] = { [GW_GCB_CHIP_REGS] = 424, [GW_HSCH_TAS_CONFIG] = 12, [GW_HSCH_TAS_PROFILE_CFG] = 64, + [GW_HSCH_TAS_GCL_CFG] = 8, [GW_PTP_PHASE_DETECTOR_CTRL] = 8, [GW_QSYS_PAUSE_CFG] = 1128, };
@@ -201,6 +205,12 @@ const unsigned int sparx5_fsize[FSIZE_LAST] = { [FW_HSCH_HSCH_LEAK_CFG_LEAK_FIRST] = 16, [FW_HSCH_FLUSH_CTRL_FLUSH_PORT] = 7, [FW_HSCH_FLUSH_CTRL_FLUSH_HIER] = 16, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM_MAX] = 7, + [FW_HSCH_TAS_CFG_CTRL_LIST_NUM] = 7, + [FW_HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM] = 14, + [FW_HSCH_TAS_GATE_STATE_CTRL_HSCH_POS] = 13, + [FW_HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX] = 7, + [FW_HSCH_TAS_LIST_CFG_LIST_BASE_ADDR] = 14, [FW_LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_DIRECT_ROW] = 14, [FW_LRN_MAC_ACCESS_CFG_3_MAC_ENTRY_ISDX_LIMIT_IDX] = 11, [FW_LRN_AUTOAGE_CFG_2_NEXT_ROW] = 14,
drivers/net/ethernet/microchip/sparx5/sparx5_regs.h +10 -0
@@ -105,6 +105,9 @@ enum sparx5_gaddr_enum {GA_HSCH_MMGT ,GA_HSCH_TAS_CONFIG ,GA_HSCH_TAS_PROFILE_CFG , +GA_HSCH_TAS_LIST_CFG , +GA_HSCH_TAS_GCL_CFG , +GA_HSCH_HSCH_TAS_STATE ,GA_PTP_PTP_CFG ,GA_PTP_PTP_TOD_DOMAINS , GA_PTP_PHASE_DETECTOR_CTRL,
@@ -158,6 +161,7 @@ enum sparx5_gsize_enum {GW_GCB_CHIP_REGS ,GW_HSCH_TAS_CONFIG ,GW_HSCH_TAS_PROFILE_CFG , +GW_HSCH_TAS_GCL_CFG ,GW_PTP_PHASE_DETECTOR_CTRL ,GW_QSYS_PAUSE_CFG , GSIZE_LAST,
@@ -214,6 +218,12 @@ enum sparx5_fsize_enum {FW_HSCH_HSCH_LEAK_CFG_LEAK_FIRST ,FW_HSCH_FLUSH_CTRL_FLUSH_PORT ,FW_HSCH_FLUSH_CTRL_FLUSH_HIER , +FW_HSCH_TAS_CFG_CTRL_LIST_NUM_MAX , +FW_HSCH_TAS_CFG_CTRL_LIST_NUM , +FW_HSCH_TAS_CFG_CTRL_GCL_ENTRY_NUM , +FW_HSCH_TAS_GATE_STATE_CTRL_HSCH_POS , +FW_HSCH_TAS_STARTUP_CFG_OBSOLETE_IDX , +FW_HSCH_TAS_LIST_CFG_LIST_BASE_ADDR ,FW_LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_DIRECT_ROW ,FW_LRN_MAC_ACCESS_CFG_3_MAC_ENTRY_ISDX_LIMIT_IDX , FW_LRN_AUTOAGE_CFG_2_NEXT_ROW,
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH 2/3 net: sparx5: Move TAS link speed configuration to sparx5_tas.c
In reply to Daniel MachonMove sparx5_tas_speed() and its link speed enum from sparx5_qos.c to a new sparx5_tas.c, which the following TAS offload patch builds on.
No functional change.
--- drivers/net/ethernet/microchip/sparx5/Makefile | 2 +- .../net/ethernet/microchip/sparx5/sparx5_main.h | 3 ++ drivers/net/ethernet/microchip/sparx5/sparx5_qos.c | 49 ------------------- drivers/net/ethernet/microchip/sparx5/sparx5_qos.h | 1 - drivers/net/ethernet/microchip/sparx5/sparx5_tas.c | 56 ++++++++++++++++++++++ 5 files changed, 60 insertions(+), 51 deletions(-)
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
@@ -11,7 +11,7 @@ sparx5-switch-y := sparx5_main.o sparx5_packet.o \ sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \ sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \ sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o sparx5_police.o \ - sparx5_psfp.o sparx5_mirror.o sparx5_regs.o + sparx5_psfp.o sparx5_mirror.o sparx5_regs.o sparx5_tas.o sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +3 -0
@@ -707,6 +707,9 @@ void sparx5_psfp_init(struct sparx5 *sparx5);void sparx5_new_base_time (struct sparx5 *sparx5,const u32 cycle_time,const ktime_t org_base_time,ktime_t *new_base_time); +/* sparx5_tas.c */ +void sparx5_tas_speed (struct sparx5_port *port,int speed); +/* sparx5_mirror.c */ int sparx5_mirror_add (struct sparx5_mall_entry *entry);void sparx5_mirror_del (struct sparx5_mall_entry *entry);
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +0 -49
58 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_qos.h +0 -1
@@ -60,7 +60,6 @@ struct sparx5_dwrr { };int sparx5_qos_init (struct sparx5 *sparx5); -void sparx5_tas_speed (struct sparx5_port *port,int speed);/* Multi-Queue Priority */ int sparx5_tc_mqprio_add (struct net_device *ndev,u8 num_tc);
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH 3/3 net: sparx5: Add TAS offload support
In reply to Daniel MachonThe Time Aware Shaper (TAS, IEEE 802.1Qbv) opens and closes the gates of a port's egress queues according to a repeating schedule, so that traffic classes are only sent in their own time windows.
In hardware, a schedule is run by a TAS list, which steps through gate control list (GCL) entries taken from a pool shared by all ports. A list is started with a base time, and it can stop another list when it takes over, which allows a schedule to be replaced without a gap.
Add TAS offload for sparx5 and lan969x, configured through tc-taprio. Use two TAS lists per port, so that a new schedule can be programmed in one list while the other is operating. Allocate the GCL entries of a schedule from the shared pool, and free them once their list is back in ADMIN. On lan969x, program the GCL as a linked list and address its entries by absolute index rather than relative to the list base.
sparx5 has 128 TAS lists for 65 ports, so with every port present the last port gets no TAS offload.
--- .../ethernet/microchip/sparx5/lan969x/lan969x.c | 2 + .../net/ethernet/microchip/sparx5/sparx5_main.c | 2 + .../net/ethernet/microchip/sparx5/sparx5_main.h | 25 + drivers/net/ethernet/microchip/sparx5/sparx5_qos.c | 4 + drivers/net/ethernet/microchip/sparx5/sparx5_tas.c | 750 +++++++++++++++++++++ drivers/net/ethernet/microchip/sparx5/sparx5_tc.c | 17 + 6 files changed, 800 insertions(+)
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c +2 -0
@@ -318,6 +318,8 @@ static const struct sparx5_consts lan969x_consts = { .n_gates = 256, .n_sdlbs = 496, .n_dsm_cal_taxis = 5, + .n_tas_gcl = 3000, + .n_tas_lists = 60, .buf_size = 1572864, .qres_max_prio_idx = 315, .qres_max_colour_idx = 323,
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +2 -0
@@ -1064,6 +1064,8 @@ static const struct sparx5_consts sparx5_consts = { .n_gates = 1024, .n_sdlbs = 4096, .n_dsm_cal_taxis = 8, + .n_tas_gcl = 10000, + .n_tas_lists = 128, .buf_size = 4194280, .qres_max_prio_idx = 630, .qres_max_colour_idx = 638,
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +25 -0
@@ -108,6 +108,7 @@ enum sparx5_feature {#define SPX5_PRIOS 8/* Number of priority queues */ #define SPX5_BUFFER_CELL_SZ 184/* Cell size */ #define SPX5_BUFFER_MEMORY 4194280/* 22795 words * 184 bytes */ +#define SPX5_TAS_ENTRIES_PER_PORT 2/* TAS lists per port */ #define XTR_QUEUE 0#define INJ_QUEUE 0
@@ -236,6 +237,11 @@ struct sparx5_port {struct sk_buff_head tx_skbs;bool is_mrouter;struct list_head tc_templates;/* list of TC templates on this port */ +/* TAS GCL entries owned by each of the port's two TAS lists. */ +struct { +int gcl_base; +int gcl_count; + } tas_lists[SPX5_TAS_ENTRIES_PER_PORT ]; };enum sparx5_core_clockfreq {
@@ -316,6 +322,8 @@ struct sparx5_consts {u32 n_gates;/* Number of PSFP gates */ u32 n_sdlbs;/* Number of service dual leaky buckets */ u32 n_dsm_cal_taxis;/* Number of DSM calendar taxis */ +u32 n_tas_gcl;/* Number of TAS gate control list entries */ +u32 n_tas_lists;/* Number of TAS lists */ u32 buf_size;/* Amount of QLIM watermark memory */ u32 qres_max_prio_idx;/* Maximum QRES prio index */ u32 qres_max_colour_idx;/* Maximum QRES colour index */
@@ -374,6 +382,8 @@ struct sparx5 {void __iomem *regs[NUM_TARGETS ];int port_count;struct mutex lock;/* MAC reg lock */ +struct mutex tas_lock;/* Time Aware Shaper lock */ +unsigned long *tas_gcl_bitmap;/* Allocated TAS GCL entries */ /* port structures are in net device */ struct sparx5_port *ports[SPX5_PORTS ];enum sparx5_core_clockfreq coreclock;
@@ -708,6 +718,21 @@ void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time, const ktime_t org_base_time, ktime_t *new_base_time);/* sparx5_tas.c */ +/* TAS list states, mirrors the HSCH_TAS_LIST_STATE_LIST_STATE HW field */ +enum sparx5_tas_state { +SPX5_TAS_STATE_ADMIN , +SPX5_TAS_STATE_ADVANCING , +SPX5_TAS_STATE_PENDING , +SPX5_TAS_STATE_OPERATING , +SPX5_TAS_STATE_TERMINATING , +SPX5_NUM_TAS_STATE , +}; + +int sparx5_tas_init (struct sparx5 *sparx5); +struct tc_taprio_qopt_offload ; +int sparx5_tas_enable (struct sparx5_port *port, +struct tc_taprio_qopt_offload *qopt); +int sparx5_tas_disable (struct sparx5_port *port);void sparx5_tas_speed (struct sparx5_port *port,int speed);/* sparx5_mirror.c */
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +4 -0
@@ -457,6 +457,10 @@ int sparx5_qos_init(struct sparx5 *sparx5)if (ret <0 )return ret; + ret =sparx5_tas_init (sparx5); +if (ret) +return ret; +sparx5_psfp_init (sparx5);return 0 ;
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +750 -0
763 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_tc.c +17 -0
@@ -154,6 +154,21 @@ static int sparx5_tc_setup_qdisc_ets(struct net_device *ndev,return -EOPNOTSUPP ; } +static int sparx5_tc_setup_qdisc_taprio (struct net_device *ndev, +struct tc_taprio_qopt_offload *qopt) +{ +struct sparx5_port *port =netdev_priv (ndev); + +switch (qopt->cmd) { +case TAPRIO_CMD_REPLACE : +return sparx5_tas_enable (port, qopt); +case TAPRIO_CMD_DESTROY : +return sparx5_tas_disable (port); +default : +return -EOPNOTSUPP ; + } +} +int sparx5_port_setup_tc (struct net_device *ndev,enum tc_setup_type type,void *type_data) {
@@ -166,6 +181,8 @@ int sparx5_port_setup_tc(struct net_device *ndev, enum tc_setup_type type,return sparx5_tc_setup_qdisc_tbf (ndev, type_data);case TC_SETUP_QDISC_ETS :return sparx5_tc_setup_qdisc_ets (ndev, type_data); +case TC_SETUP_QDISC_TAPRIO : +return sparx5_tc_setup_qdisc_taprio (ndev, type_data);default :return -EOPNOTSUPP ; }
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH net-next 3/3] net: sparx5: Add TAS offload support
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] If a TAPRIO_CMD_REPLACE fails, the schedule that was already pending in hardware is lost, but taprio still treats it as the current…
- [Medium] sparx5_tas_enable() computes the TAS base time with sparx5_new_base_time() at line 595.
- [Medium] sparx5_tas_shutdown_pending() reads LIST_STATE once (line 288).
- [Low] The comment in sparx5_tas_init() says 'There are only 128 (sparx5) / 60 (lan969x) TAS lists, not enough for the whole port…
- [Low] sparx5_tas_list_state_wait() (lines 249-261) and the startup loop in sparx5_tas_enable() (lines 661-673) poll HSCH_TAS_LIST_STATE /…
--
net: sparx5: Add TAS offload support
This commit adds Time Aware Shaper (802.1Qbv) offload for sparx5 and lan969x, configured through tc-taprio. Each port uses two hardware TAS lists, so a new schedule can be programmed while the other list is operating, and GCL entries come from a pool shared by all ports. On sparx5, the last port gets no TAS offload when all 65 ports are present.
Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +0
-0@@ -17,6 +20,753 @@ enum sparx5_tas_link_speed {
[ ... ]
Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +12
-0+static int sparx5_tas_list_state_wait(struct sparx5_port *port, int list, + int req, u32 done) +{ + struct sparx5 *sparx5 = port->sparx5; + unsigned long end; + int state; + + /* Do not wait forever for the state change */ + end = jiffies + msecs_to_jiffies(TAS_TIMEOUT_MS); + do { + if (req >= 0) + spx5_rmw(HSCH_TAS_LIST_STATE_LIST_STATE_SET(req),
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 261
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+HSCH_TAS_LIST_STATE_LIST_STATE , + sparx5, + HSCH_TAS_LIST_STATE); + + state =sparx5_tas_list_state_get (sparx5); +if (BIT (state) & done) +return 0 ; + +cond_resched (); + }while (!time_after (jiffies, end));
[Severity: Low]
This loop reads HSCH_TAS_LIST_STATE repeatedly with only cond_resched() between reads, for up to TAS_TIMEOUT_MS. It runs with RTNL and sparx5->tas_lock held.
Some of these waits are not short register settles. A TERMINATING list runs until the end of its cycle, and cycle_time can be close to 1s. sparx5_tas_disable() can chain several waits (pending stop, TERMINATING request, ADMIN wait) for each of the two lists.
Would read_poll_timeout() with a sleep between reads fit better here? The same applies to the startup polling loop in sparx5_tas_enable().
[ ... ]
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+static int sparx5_tas_shutdown_pending (struct sparx5_port *port) +{ +struct sparx5 *sparx5 = port->sparx5; +int i, list, state, err; + +for (i =0 ; i <SPX5_TAS_ENTRIES_PER_PORT ; i++) { + list =sparx5_tas_list_index (port, i); + spx5_rmw(HSCH_TAS_CFG_CTRL_LIST_NUM_SET(list), + HSCH_TAS_CFG_CTRL_LIST_NUM, + sparx5,
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 295
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+ HSCH_TAS_CFG_CTRL); + + state =sparx5_tas_list_state_get (sparx5); +if (state !=SPX5_TAS_STATE_ADVANCING && + state !=SPX5_TAS_STATE_PENDING ) +continue ; + + err =sparx5_tas_list_state_wait (port, list, +SPX5_TAS_STATE_ADMIN , +BIT (SPX5_TAS_STATE_ADMIN ));
[Severity: Medium]
Can the hardware move this list from PENDING to OPERATING between the state read above and the ADMIN request?
sparx5_tas_list_state_wait() writes LIST_STATE=ADMIN again on every iteration and does not check which state the list is in now:
if (req >= 0)
spx5_rmw(HSCH_TAS_LIST_STATE_LIST_STATE_SET(req), ...);If the pending list's base time arrives in that window, the list becomes OPERATING and obsoletes the list that was operating before. The next iteration would then write ADMIN to the only running list. That stops it mid-cycle without going through TERMINATING. If the hardware ignores the request instead, the wait times out with -ETIME.
On the replace path, sparx5_tas_list_find()->sparx5_tas_shutdown_pending() is not followed by sparx5_tas_shutdown_operating(). HSCH_TAS_GATE_STATE would then keep the gate mask of the stopped entry, possibly with queues closed, until the new list starts.
lan966x_taprio_list_shutdown() reads the state again on each iteration. It sends a list that has become OPERATING to TERMINATING and later restores all-queues-open. Should sparx5 handle this case the same way?
The same unconditional rewrite applies to the TERMINATING request in sparx5_tas_shutdown_operating(). A list that has already gone OPERATING->TERMINATING->ADMIN could then get a TERMINATING request while it is in ADMIN.
[ ... ]
Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +3
-0+int sparx5_tas_enable (struct sparx5_port *port, +struct tc_taprio_qopt_offload *qopt) +{
[ ... ]
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 595
Quoted 1 line
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +1
-0+sparx5_new_base_time (sparx5, cycle_time, qopt->base_time, &base_time);
[Severity: Medium]
Can this base time be stale by the time it is written to hardware?
sparx5_new_base_time() returns a time only 2-3 cycles of the new schedule ahead of the current PHC time. Two slow steps run after it:
- sparx5_tas_list_find() can wait up to TAS_TIMEOUT_MS for a pending list to reach ADMIN, or for a TERMINATING list to finish its current cycle (up to the old cycle_time).
- sparx5_tas_gcl_setup() programs up to n_tas_gcl entries, each with several indirect register accesses.
Only after these steps are HSCH_TAS_BASE_TIME_* written and ADVANCING requested. For example, a 100us cycle that replaces a 500ms cycle while the old list is TERMINATING has a margin of about 200-300us, but the wait can last hundreds of milliseconds.
That breaks the rule in the comment at the top of the file, "base time is at least current time + (2 * cycle time)". The likely result is a STARTUP_ERROR and -EIO.
lan966x_taprio_add() computes the base time after list selection and GCL programming. Could sparx5_new_base_time() be called just before the base time registers are written?
Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +6
-0+ +/* Allocate before sparx5_tas_list_find() stops a pending schedule, so +* running out of GCL entries fails the replace without touching +* hardware. +*/ + base =sparx5_tas_gcl_alloc (sparx5, qopt->num_entries);
[ ... ]
Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +6
-0+/* Select an appropriate entry to use */ + err =sparx5_tas_list_find (port, &new_list, &obsolete); +if (err) { +bitmap_clear (sparx5->tas_gcl_bitmap, base, qopt->num_entries); + goto out; + }
[ ... ]
Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +5
-0+if (HSCH_TAS_STARTUP_CFG_STARTUP_ERROR_GET (startup)) { +netdev_err (port->ndev,"TAS startup error in list %d\n" , + new_list); + err = -EIO ; + }else if (state ==SPX5_TAS_STATE_ADVANCING ) {
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 689
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+netdev_err (port->ndev,"Timeout starting TAS list %d\n" , + new_list); + err = -ETIME ; + } + +/* taprio sends no DESTROY for a failed offload, so do not leave a +* list behind that may still start. +*/ +if (err) +sparx5_tas_shutdown_pending (port);
[Severity: Medium]
Is the schedule that was already pending lost when the replace fails here?
sparx5_tas_list_find() first calls sparx5_tas_shutdown_pending(). That forces any ADVANCING or PENDING list of the port back to ADMIN and frees its GCL range. Several failures can happen after that point:
- the invalid state combination check in sparx5_tas_list_find()
(-EINVAL)
- sparx5_tas_wait_admin() timing out on a TERMINATING list
- a latched STARTUP_ERROR (-EIO)
- the ADVANCING timeout (-ETIME)
Each of these cleans up only the new list, either with bitmap_clear() or with the sparx5_tas_shutdown_pending() call above, and returns the error. The old pending schedule is not restored.
In taprio_change(), the previous schedule B was already promoted when it was installed. On an offload error, taprio_change() does goto free_sched and keeps B. Take A operating and B pending, then a replace with C that fails. Hardware keeps running A, taprio reports B, and B never starts.
The comment before sparx5_tas_gcl_alloc() covers the case where GCL entries run out. The later failures still seem to leave hardware and taprio out of sync. Could they be handled as well?
[ ... ]
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 729
Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +9
-0+int sparx5_tas_init (struct sparx5 *sparx5) +{ +const struct sparx5_consts *consts = sparx5->data->consts; +int i, num_ports, list_num_max; + +/* There are only 128 (sparx5) / 60 (lan969x) TAS lists, not enough +* for the whole port range. LIST_NUM_MAX is the highest list index +* processed, and the datasheet gives 24 as its minimum value. +*/
[Severity: Low]
This isn't a bug, but is this comment accurate for lan969x?
lan969x_consts sets n_ports = 30 and n_tas_lists = 60. With SPX5_TAS_ENTRIES_PER_PORT lists per port, every lan969x front port gets its two lists. Only sparx5 (65 ports, 128 lists) runs short, as the commit message says.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261006-sparx5-tas-v1-0-5eef1126dfd5%40microchip.com
Daniel Machon
maintainerRe: [PATCH net-next 3/3] net: sparx5: Add TAS offload support
Quoted 123 lines
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] If a
TAPRIO_CMD_REPLACEfails, the schedule that was already pending in hardware is lost, but taprio still treats it as the current…
- [Medium]sparx5_tas_enable()computes the TAS base time withsparx5_new_base_time()at line 595.
- [Medium]sparx5_tas_shutdown_pending()readsLIST_STATEonce (line 288).
- [Low] The comment insparx5_tas_init()says 'There are only 128 (sparx5) / 60 (lan969x) TAS lists, not enough for the whole port…
- [Low]sparx5_tas_list_state_wait()(lines 249-261) and the startup loop insparx5_tas_enable()(lines 661-673) pollHSCH_TAS_LIST_STATE/…--
net: sparx5: Add TAS offload support
This commit adds Time Aware Shaper (802.1Qbv) offload for sparx5 and lan969x, configured through tc-taprio. Each port uses two hardware TAS lists, so a new schedule can be programmed while the other list is operating, and GCL entries come from a pool shared by all ports. On sparx5, the last port gets no TAS offload when all 65 ports are present.
Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +0
-0[ ... ]
Quoted 1 line
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +0
-0@@ -17,6 +20,753 @@ enum sparx5_tas_link_speed {[ ... ]
Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +12
-0+static int sparx5_tas_list_state_wait(struct sparx5_port *port, int list, + int req, u32 done) +{ + struct sparx5 *sparx5 = port->sparx5; + unsigned long end; + int state; + + /* Do not wait forever for the state change */ + end = jiffies + msecs_to_jiffies(TAS_TIMEOUT_MS); + do { + if (req >= 0) + spx5_rmw(HSCH_TAS_LIST_STATE_LIST_STATE_SET(req),drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 261
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+HSCH_TAS_LIST_STATE_LIST_STATE , + sparx5, + HSCH_TAS_LIST_STATE); + + state =sparx5_tas_list_state_get (sparx5); +if (BIT (state) & done) +return 0 ; + +cond_resched (); + }while (!time_after (jiffies, end));[Severity: Low]
This loop readsHSCH_TAS_LIST_STATErepeatedly with onlycond_resched()between reads, for up toTAS_TIMEOUT_MS. It runs with RTNL andsparx5->tas_lockheld.Some of these waits are not short register settles. A TERMINATING list runs until the end of its cycle, and
cycle_timecan be close to 1s.sparx5_tas_disable()can chain several waits (pending stop, TERMINATING request, ADMIN wait) for each of the two lists.Would
read_poll_timeout()with a sleep between reads fit better here? The same applies to the startup polling loop insparx5_tas_enable().[ ... ]
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+static int sparx5_tas_shutdown_pending (struct sparx5_port *port) +{ +struct sparx5 *sparx5 = port->sparx5; +int i, list, state, err; + +for (i =0 ; i <SPX5_TAS_ENTRIES_PER_PORT ; i++) { + list =sparx5_tas_list_index (port, i); + spx5_rmw(HSCH_TAS_CFG_CTRL_LIST_NUM_SET(list), + HSCH_TAS_CFG_CTRL_LIST_NUM, + sparx5,drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 295
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+ HSCH_TAS_CFG_CTRL); + + state =sparx5_tas_list_state_get (sparx5); +if (state !=SPX5_TAS_STATE_ADVANCING && + state !=SPX5_TAS_STATE_PENDING ) +continue ; + + err =sparx5_tas_list_state_wait (port, list, +SPX5_TAS_STATE_ADMIN , +BIT (SPX5_TAS_STATE_ADMIN ));[Severity: Medium]
Can the hardware move this list from PENDING to OPERATING between the state read above and the ADMIN request?
sparx5_tas_list_state_wait()writes LIST_STATE=ADMIN again on every iteration and does not check which state the list is in now:if (req >= 0) spx5_rmw(HSCH_TAS_LIST_STATE_LIST_STATE_SET(req), ...);If the pending list's base time arrives in that window, the list becomes OPERATING and obsoletes the list that was operating before. The next iteration would then write ADMIN to the only running list. That stops it mid-cycle without going through TERMINATING. If the hardware ignores the request instead, the wait times out with
-ETIME.On the replace path, sparx5_tas_list_find()->sparx5_tas_shutdown_pending() is not followed by
sparx5_tas_shutdown_operating().HSCH_TAS_GATE_STATEwould then keep the gate mask of the stopped entry, possibly with queues closed, until the new list starts.
Quoted 8 lines
lan966x_taprio_list_shutdown()reads the state again on each iteration. It sends a list that has become OPERATING to TERMINATING and later restores all-queues-open. Should sparx5 handle this case the same way?The same unconditional rewrite applies to the TERMINATING request in
sparx5_tas_shutdown_operating(). A list that has already goneOPERATING->TERMINATING->ADMINcould then get a TERMINATING request while it is in ADMIN.
Speculative. But yes, the hardware gives no atomic way to cancel a PENDING list, so the state read and the ADMIN write can always race its move to OPERATING. Have been working the same way downstream for years, havent observed any issues.
Quoted 28 lines
[ ... ]
Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +3
-0+int sparx5_tas_enable (struct sparx5_port *port, +struct tc_taprio_qopt_offload *qopt) +{[ ... ]
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 595
Quoted 1 line
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +1
-0+sparx5_new_base_time (sparx5, cycle_time, qopt->base_time, &base_time);[Severity: Medium]
Can this base time be stale by the time it is written to hardware?
sparx5_new_base_time()returns a time only 2-3 cycles of the new schedule ahead of the current PHC time. Two slow steps run after it:-
sparx5_tas_list_find()can wait up toTAS_TIMEOUT_MSfor a pending list to reach ADMIN, or for a TERMINATING list to finish its current cycle (up to the oldcycle_time).
-sparx5_tas_gcl_setup()programs up ton_tas_gclentries, each with several indirect register accesses.Only after these steps are HSCH_TAS_BASE_TIME_* written and ADVANCING requested. For example, a 100us cycle that replaces a 500ms cycle while the old list is TERMINATING has a margin of about 200-300us, but the wait can last hundreds of milliseconds.
Quoted 8 lines
That breaks the rule in the comment at the top of the file, "base time is at least current time + (2 * cycle time)". The likely result is a
STARTUP_ERRORand-EIO.
lan966x_taprio_add()computes the base time after list selection and GCL programming. Couldsparx5_new_base_time()be called just before the base time registers are written?
This one is also flagged speculative. In practice it is harmless: a too-close or past BASE_TIME only makes the hardware skip whole cycles until it can start on a cycle boundary. Intended.
Quoted 52 lines
Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +6
-0+ +/* Allocate before sparx5_tas_list_find() stops a pending schedule, so +* running out of GCL entries fails the replace without touching +* hardware. +*/ + base =sparx5_tas_gcl_alloc (sparx5, qopt->num_entries);[ ... ]
Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +6
-0+/* Select an appropriate entry to use */ + err =sparx5_tas_list_find (port, &new_list, &obsolete); +if (err) { +bitmap_clear (sparx5->tas_gcl_bitmap, base, qopt->num_entries); + goto out; + }[ ... ]
Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +5
-0+if (HSCH_TAS_STARTUP_CFG_STARTUP_ERROR_GET (startup)) { +netdev_err (port->ndev,"TAS startup error in list %d\n" , + new_list); + err = -EIO ; + }else if (state ==SPX5_TAS_STATE_ADVANCING ) {drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 689
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +10
-0+netdev_err (port->ndev,"Timeout starting TAS list %d\n" , + new_list); + err = -ETIME ; + } + +/* taprio sends no DESTROY for a failed offload, so do not leave a +* list behind that may still start. +*/ +if (err) +sparx5_tas_shutdown_pending (port);[Severity: Medium]
Is the schedule that was already pending lost when the replace fails here?
sparx5_tas_list_find()first callssparx5_tas_shutdown_pending(). That forces any ADVANCING or PENDING list of the port back to ADMIN and frees its GCL range. Several failures can happen after that point:- the invalid state combination check in
sparx5_tas_list_find()(-EINVAL)-
sparx5_tas_wait_admin()timing out on a TERMINATING list
- a latchedSTARTUP_ERROR(-EIO)
- the ADVANCING timeout (-ETIME)Each of these cleans up only the new list, either with
bitmap_clear()or with thesparx5_tas_shutdown_pending()call above, and returns the error. The old pending schedule is not restored.
Quoted 9 lines
In
taprio_change(), the previous schedule B was already promoted when it was installed. On an offload error,taprio_change()does gotofree_schedand keeps B. Take A operating and B pending, then a replace with C that fails. Hardware keeps running A, taprio reports B, and B never starts.The comment before
sparx5_tas_gcl_alloc()covers the case where GCL entries run out. The later failures still seem to leave hardware and taprio out of sync. Could they be handled as well?
Yes, but only on a hardware failure. Every error a user can trigger, is returned before any TAS list is touched. I checked other taprio offload drivers and AFAICT, none restores a previous schedule after a hardware failure. Also, havent observed this issue.
Quoted 22 lines
[ ... ]
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c enum sparx5_tas_link_speed { · line 729
Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_tas.c +9
-0+int sparx5_tas_init (struct sparx5 *sparx5) +{ +const struct sparx5_consts *consts = sparx5->data->consts; +int i, num_ports, list_num_max; + +/* There are only 128 (sparx5) / 60 (lan969x) TAS lists, not enough +* for the whole port range. LIST_NUM_MAX is the highest list index +* processed, and the datasheet gives 24 as its minimum value. +*/ [Severity: Low]
This isn't a bug, but is this comment accurate for lan969x?
lan969x_constssetsn_ports= 30 andn_tas_lists= 60. WithSPX5_TAS_ENTRIES_PER_PORTlists per port, every lan969x front port gets its two lists. Only sparx5 (65 ports, 128 lists) runs short, as the commit message says.Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261006-sparx5-tas-v1-0-5eef1126dfd5%40microchip.com
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 4 lines · On Tue, 6 Oct 2026 15:51:05 +0200 you wrote:
This series adds offload of the Time Aware Shaper (IEEE 802.1Qbv), configured through tc-taprio, on Sparx5 and lan969x, which are both served by the sparx5 driver.
Quoted 8 lines
In hardware, a TAS schedule is run by a TAS list, which steps through gate control list (GCL) entries taken from a pool shared by all ports. Sparx5 has 128 lists and 10000 GCL entries, lan969x has 60 lists and 3000 entries. An idle list is in the ADMIN state. Once started, it is PENDING until its base time, then OPERATING. A stopped list is TERMINATING until the end of its cycle, and then goes back to ADMIN.
[...]
Here is the summary with links:
- [net-next,1/3] net: sparx5: Add registers used by TAS
https://git.kernel.org/netdev/net-next/c/48b7611964e1 - [net-next,2/3] net: sparx5: Move TAS link speed configuration to sparx5_tas.c https://git.kernel.org/netdev/net-next/c/966285085456 - [net-next,3/3] net: sparx5: Add TAS offload support https://git.kernel.org/netdev/net-next/c/a52629f85a3a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html