Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/3] net: stmmac: support up to 16 MTL/DMA queues on XGMAC
@ 2026-11-24  0:04 Sagar Cheluvegowda
  2026-11-24  0:04 ` [PATCH net-next v2 1/3] net: stmmac: separate the TC count from the queue count " Sagar Cheluvegowda
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sagar Cheluvegowda @ 2026-11-24  0:04 UTC (permalink / raw)
  To: j.raczynski
  Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
	mcoquelin.stm32, alexandre.torgue, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-arm-msm, cs0617.lee,
	k.domagalski, k.tegowski, abhishek.chauhan, lorenzo.bianconi,
	sarosh.hasan, hongmei.xu, sagar.cheluvegowda

This series continues Jakub Raczynski's v2 series "Extend MTL/DMA
support to 16 queues":
https://lore.kernel.org/netdev/20260601162537.553512-1-j.raczynski@samsung.com/

Newer XGMAC hardware can have more queues than traffic classes: Qualcomm
Nord is a 25GMAC-based SoC with 12 queues enabled (the core supports 16)
and 8 TCs. The driver assumes one TC per queue and bounds every TC
register write by the number of queues, so the DMA/queue count and the
TC count need to be separated before the queue limit can be raised. This
was raised in the review of the v2 1/3.

 1/3: separate the TC count from the queue count. Bound the per TC
      registers (ETS, CBS, weight, TC_PRTY) by the number of TCs and
      the per priority registers (Qx_TX_FLOW_CTRL, PSRQ) by the 8
      priorities, and do the checks in the callers so that errors are
      returned to the user. This is a rework of Jakub's v2 1/3.
      tc_setup_cbs() is not changed: CBS offload on queues without their
      own TC needs the HDMA support, which is not upstream yet.
 2/3: extend the RX queue to DMA channel mapping to 16 queues (MAP2/MAP3).
      Jakub's v2 2/3 with netdev_err() replaced by WARN_ON(), authorship and
      sign-offs kept.
 3/3: raise the maximum number of queues to 16. Jakub's v2 3/3 as it was.

The review of Jakub's v2 3/3 asked whether the other cores, whose per queue
registers only cover 8 queues, could now be configured with more. They
cannot: stmmac_hw_init() already limits the number of queues to the
count reported by the HW feature register, which is at most 8 on those
cores.

Changes in v2:
- v1 was the MAP2/MAP3 patch on its own:
  https://lore.kernel.org/netdev/20261016193823.2711773-1-sagar.cheluvegowda@oss.qualcomm.com/
  Following Jakub's review of it:
  https://lore.kernel.org/netdev/atXhR0sgdW84YxcQ@AMDC4622.eu.corp.samsungelectronics.net/
  - add 1/3, which splits the TC count from the queue count, as Nord
    has 12 queues (the core supports 16) and 8 TCs
  - add 3/3, which raises the queue limits, so the MAP2/MAP3 mapping
    in 2/3 can be reached
  - 2/3 is unchanged


Jakub Raczynski (2):
  net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues
  include/stmmac: Increase max DMA/MTL channel count from 8 to 16

Sagar Cheluvegowda (1):
  net: stmmac: separate the TC count from the queue count on XGMAC

 .../net/ethernet/stmicro/stmmac/dwxgmac2.h    |  3 +++
 .../ethernet/stmicro/stmmac/dwxgmac2_core.c   | 23 ++++++++++++++++---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  | 17 ++++++++++++++
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 22 +++++++++++-------
 .../net/ethernet/stmicro/stmmac/stmmac_tc.c   | 21 ++++++++++-------
 include/linux/stmmac.h                        |  6 ++---
 6 files changed, 70 insertions(+), 22 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/3] net: stmmac: separate the TC count from the queue count on XGMAC
  2026-11-24  0:04 [PATCH net-next v2 0/3] net: stmmac: support up to 16 MTL/DMA queues on XGMAC Sagar Cheluvegowda
@ 2026-11-24  0:04 ` Sagar Cheluvegowda
  2026-11-25  0:09   ` netdev-bot+sashiko
  2026-11-24  0:04 ` [PATCH net-next v2 2/3] net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues Sagar Cheluvegowda
  2026-11-24  0:04 ` [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16 Sagar Cheluvegowda
  2 siblings, 1 reply; 7+ messages in thread
From: Sagar Cheluvegowda @ 2026-11-24  0:04 UTC (permalink / raw)
  To: j.raczynski
  Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
	mcoquelin.stm32, alexandre.torgue, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-arm-msm, cs0617.lee,
	k.domagalski, k.tegowski, abhishek.chauhan, lorenzo.bianconi,
	sarosh.hasan, hongmei.xu, sagar.cheluvegowda

The driver assumes one traffic class per queue and bounds every TC
based register write by {rx,tx}_queues_to_use. Newer XGMAC hardware
has more queues than traffic classes (up to 16 queues and 8 TCs),
and the number of TCs is reported separately by the HW feature
register. The result is writes to TC registers that do not exist.

Add stmmac_num_tc(), which returns the number of TCs for the queues
in use and falls back to the number of TX queues on cores that do not
report it, and use it where the register is per TC:

- TX queue weight, CBS (replay on resume) and TX priority (TC_PRTY):
  configure only the existing TCs.
- ETS: the loop was bound by MTL_MAX_TX_QUEUES, use the 8 TCs the
  hardware can have. This also keeps it from walking off the TC
  registers when the macro is raised.

Other registers are per queue and only exist for the first 8 queues
because they are per 802.1Q priority: Qx_TX_FLOW_CTRL and the PSRQ
fields. Bound them by STMMAC_NUM_PRIO_QUEUES instead of the TC count,
as the TC count is not the limit for them. Writing Qx_TX_FLOW_CTRL
past queue 7 would hit RX_FLOW_CTRL and MAC_RxQ_Ctrl4/5. Reject VLAN
priority filters that name a queue outside this range, and only walk
those queues when updating the PSRQ assignments.

The checks are in the callers, which can return an error to the user,
instead of in the callbacks, which are void.

Link: https://lore.kernel.org/netdev/20260601162537.553512-2-j.raczynski@samsung.com/
Signed-off-by: Sagar Cheluvegowda <sagar.cheluvegowda@oss.qualcomm.com>
---
 .../net/ethernet/stmicro/stmmac/dwxgmac2.h    |  1 +
 .../ethernet/stmicro/stmmac/dwxgmac2_core.c   |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac.h  | 17 ++++++++++++++
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 22 ++++++++++++-------
 .../net/ethernet/stmicro/stmmac/stmmac_tc.c   | 21 +++++++++++-------
 5 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index f8ab347f7b5b..77a54792893b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -291,6 +291,7 @@
 #define XGMAC_TTC			GENMASK(6, 4)
 #define XGMAC_TXQEN			GENMASK(3, 2)
 #define XGMAC_TSF			BIT(1)
+#define XGMAC_MAX_TC			8
 #define XGMAC_MTL_TCx_ETS_CONTROL(x)	(0x00001110 + (0x80 * (x)))
 #define XGMAC_MTL_TCx_QUANTUM_WEIGHT(x)	(0x00001118 + (0x80 * (x)))
 #define XGMAC_MTL_TCx_SENDSLOPE(x)	(0x0000111c + (0x80 * (x)))
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index 09194b9d8322..e50c0f4c482d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -235,7 +235,7 @@ static void dwxgmac2_prog_mtl_tx_algorithms(struct mac_device_info *hw,
 	writel(value, ioaddr + XGMAC_MTL_OPMODE);
 
 	/* Set ETS if desired */
-	for (i = 0; i < MTL_MAX_TX_QUEUES; i++) {
+	for (i = 0; i < XGMAC_MAX_TC; i++) {
 		value = readl(ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(i));
 		value &= ~XGMAC_TSA;
 		if (ets)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index fcc395321816..24bbe72e0071 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -57,6 +57,11 @@ struct stmmac_tx_info {
 	bool is_jumbo;
 };
 
+/* Number of 802.1Q priorities. This is also the number of queues that have a
+ * per-priority register (PSRQ field, Qx_TX_FLOW_CTRL) on DWMAC4/XGMAC.
+ */
+#define STMMAC_NUM_PRIO_QUEUES	8
+
 #define STMMAC_TBS_AVAIL	BIT(0)
 #define STMMAC_TBS_EN		BIT(1)
 
@@ -441,6 +446,18 @@ static inline bool stmmac_check_timestamp_cap(struct stmmac_priv *priv)
 	return priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp;
 }
 
+/* Most cores have one traffic class per queue, but newer XGMAC can have more
+ * queues than traffic classes (the number of TCs is reported by the HW
+ * feature register).
+ */
+static inline u32 stmmac_num_tc(const struct stmmac_priv *priv)
+{
+	if (!priv->dma_cap.numtc)
+		return priv->plat->tx_queues_to_use;
+
+	return min_t(u32, priv->dma_cap.numtc, priv->plat->tx_queues_to_use);
+}
+
 static inline bool stmmac_xdp_is_enabled(struct stmmac_priv *priv)
 {
 	return !!priv->xdp_prog;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ca4c7fb11b73..5d02f7034a7a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1023,7 +1023,11 @@ static int stmmac_legacy_serdes_power_up(struct stmmac_priv *priv)
 static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex,
 				 unsigned int flow_ctrl)
 {
-	u8 tx_cnt = priv->plat->tx_queues_to_use;
+	/* The per-queue flow control registers exist for the first
+	 * STMMAC_NUM_PRIO_QUEUES queues only.
+	 */
+	u8 tx_cnt = min_t(u8, priv->plat->tx_queues_to_use,
+			  STMMAC_NUM_PRIO_QUEUES);
 
 	stmmac_flow_ctrl(priv, priv->hw, duplex, flow_ctrl, priv->pause_time,
 			 tx_cnt);
@@ -3531,11 +3535,11 @@ static void stmmac_set_rings_length(struct stmmac_priv *priv)
  */
 static void stmmac_set_tx_queue_weight(struct stmmac_priv *priv)
 {
-	u8 tx_queues_count = priv->plat->tx_queues_to_use;
+	u8 num_tc = stmmac_num_tc(priv);
 	u32 weight;
 	u8 queue;
 
-	for (queue = 0; queue < tx_queues_count; queue++) {
+	for (queue = 0; queue < num_tc; queue++) {
 		weight = priv->plat->tx_queues_cfg[queue].weight;
 		stmmac_set_mtl_tx_queue_weight(priv, priv->hw, weight, queue);
 	}
@@ -3548,12 +3552,12 @@ static void stmmac_set_tx_queue_weight(struct stmmac_priv *priv)
  */
 void stmmac_configure_cbs(struct stmmac_priv *priv)
 {
-	u8 tx_queues_count = priv->plat->tx_queues_to_use;
+	u8 num_tc = stmmac_num_tc(priv);
 	u32 mode_to_use;
 	u8 queue;
 
 	/* queue 0 is reserved for legacy traffic */
-	for (queue = 1; queue < tx_queues_count; queue++) {
+	for (queue = 1; queue < num_tc; queue++) {
 		mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use;
 		if (mode_to_use == MTL_QUEUE_DCB)
 			continue;
@@ -3591,7 +3595,8 @@ static void stmmac_rx_queue_dma_chan_map(struct stmmac_priv *priv)
  */
 static void stmmac_mac_config_rx_queues_prio(struct stmmac_priv *priv)
 {
-	u8 rx_queues_count = priv->plat->rx_queues_to_use;
+	u8 rx_queues_count = min_t(u8, priv->plat->rx_queues_to_use,
+				   STMMAC_NUM_PRIO_QUEUES);
 	u8 queue;
 	u32 prio;
 
@@ -3611,9 +3616,10 @@ static void stmmac_mac_config_rx_queues_prio(struct stmmac_priv *priv)
  */
 static void stmmac_mac_config_tx_queues_prio(struct stmmac_priv *priv)
 {
-	int i;
+	u32 num_tc = stmmac_num_tc(priv);
+	u32 i;
 
-	for (i = 0; i < priv->plat->tx_queues_to_use; i++)
+	for (i = 0; i < num_tc; i++)
 		stmmac_tx_queue_prio(priv, priv->hw,
 				     priv->xmit_qdisc.prio[i], i);
 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
index 5df6ef1dd438..d18d064b42ad 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
@@ -686,12 +686,16 @@ static struct stmmac_rfs_entry *tc_find_rfs(struct stmmac_priv *priv,
 
 static void tc_update_vlan_prio(struct stmmac_priv *priv, u8 prio)
 {
-	u8 prios[MTL_MAX_RX_QUEUES] = {};
+	u8 prios[STMMAC_NUM_PRIO_QUEUES] = {};
 	struct stmmac_rfs_entry *entry;
+	unsigned int rx_cnt = min_t(unsigned int, priv->plat->rx_queues_to_use,
+				    STMMAC_NUM_PRIO_QUEUES);
 	unsigned int queue, i;
 
-	/* Restore platform assignments with the same precedence as setup. */
-	for (queue = 0; queue < priv->plat->rx_queues_to_use; queue++) {
+	/* Restore platform assignments with the same precedence as setup. Only
+	 * the first STMMAC_NUM_PRIO_QUEUES queues have a PSRQ field.
+	 */
+	for (queue = 0; queue < rx_cnt; queue++) {
 		if (!priv->plat->rx_queues_cfg[queue].use_prio)
 			continue;
 
@@ -706,19 +710,19 @@ static void tc_update_vlan_prio(struct stmmac_priv *priv, u8 prio)
 	 */
 	list_for_each_entry(entry, &priv->vlan_prio, vlan_node) {
 		/* The RX queue count may have been reduced with ethtool. */
-		if (entry->tc >= priv->plat->rx_queues_to_use)
+		if (entry->tc >= rx_cnt)
 			continue;
 
-		for (queue = 0; queue < priv->plat->rx_queues_to_use; queue++)
+		for (queue = 0; queue < rx_cnt; queue++)
 			prios[queue] &= ~entry->vlan_prio;
 		prios[entry->tc] |= entry->vlan_prio;
 	}
 
 	/* Install the new assignment before clearing the previous queue. */
-	for (queue = 0; queue < priv->plat->rx_queues_to_use; queue++)
+	for (queue = 0; queue < rx_cnt; queue++)
 		if (prios[queue] & prio)
 			stmmac_rx_queue_prio(priv, priv->hw, prios[queue], queue);
-	for (queue = 0; queue < priv->plat->rx_queues_to_use; queue++)
+	for (queue = 0; queue < rx_cnt; queue++)
 		if (!(prios[queue] & prio))
 			stmmac_rx_queue_prio(priv, priv->hw, prios[queue], queue);
 }
@@ -749,7 +753,8 @@ static int tc_add_vlan_flow(struct stmmac_priv *priv,
 	if (!dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_VLAN))
 		return -EINVAL;
 
-	if (tc < 0 || tc >= priv->plat->rx_queues_to_use) {
+	if (tc < 0 || tc >= priv->plat->rx_queues_to_use ||
+	    tc >= STMMAC_NUM_PRIO_QUEUES) {
 		netdev_err(priv->dev, "Invalid traffic class\n");
 		return -EINVAL;
 	}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/3] net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues
  2026-11-24  0:04 [PATCH net-next v2 0/3] net: stmmac: support up to 16 MTL/DMA queues on XGMAC Sagar Cheluvegowda
  2026-11-24  0:04 ` [PATCH net-next v2 1/3] net: stmmac: separate the TC count from the queue count " Sagar Cheluvegowda
@ 2026-11-24  0:04 ` Sagar Cheluvegowda
  2026-11-25  0:09   ` netdev-bot+sashiko
  2026-11-24  0:04 ` [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16 Sagar Cheluvegowda
  2 siblings, 1 reply; 7+ messages in thread
From: Sagar Cheluvegowda @ 2026-11-24  0:04 UTC (permalink / raw)
  To: j.raczynski
  Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
	mcoquelin.stm32, alexandre.torgue, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-arm-msm, cs0617.lee,
	k.domagalski, k.tegowski, abhishek.chauhan, lorenzo.bianconi,
	sarosh.hasan, hongmei.xu, sagar.cheluvegowda

From: Jakub Raczynski <j.raczynski@samsung.com>

New datasheets for XGMAC (3.20a and 3.40a, depending on product)
support up to 16 MTL/DMA queues. Before we increase max amount
through macro, prepare dwxgmac functions to handle that.

The only caller, stmmac_rx_queue_dma_chan_map(), walks the queues
below rx_queues_to_use, which the devicetree parser limits to
MTL_MAX_RX_QUEUES. A queue above 15 is therefore a driver bug, not
bad input. v2 reported it with netdev_err() through hw->priv_data,
but that back-pointer was only added by v2 1/3, which this series
replaces, and a log line from a void callback does not stop the
caller from carrying on. Use WARN_ON() instead: it needs no
net_device and its backtrace points at the caller.

Co-developed-by: Chang-Sub Lee <cs0617.lee@samsung.com>
Signed-off-by: Chang-Sub Lee <cs0617.lee@samsung.com>
Signed-off-by: Jakub Raczynski <j.raczynski@samsung.com>
Co-developed-by: Sagar Cheluvegowda <sagar.cheluvegowda@oss.qualcomm.com>
Signed-off-by: Sagar Cheluvegowda <sagar.cheluvegowda@oss.qualcomm.com>
---
 .../net/ethernet/stmicro/stmmac/dwxgmac2.h    |  2 ++
 .../ethernet/stmicro/stmmac/dwxgmac2_core.c   | 21 +++++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
index 77a54792893b..5b83fe07c1e4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h
@@ -257,6 +257,8 @@
 #define XGMAC_MTL_INT_STATUS		0x00001020
 #define XGMAC_MTL_RXQ_DMA_MAP0		0x00001030
 #define XGMAC_MTL_RXQ_DMA_MAP1		0x00001034
+#define XGMAC_MTL_RXQ_DMA_MAP2		0x00001038
+#define XGMAC_MTL_RXQ_DMA_MAP3		0x0000103c
 #define XGMAC_QxMDMACH(x)		GENMASK((x) * 8 + 7, (x) * 8)
 #define XGMAC_QxMDMACH_SHIFT(x)		((x) * 8)
 #define XGMAC_QDDMACH			BIT(7)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index e50c0f4c482d..8aa69647a207 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -259,9 +259,26 @@ static void dwxgmac2_map_mtl_to_dma(struct mac_device_info *hw, u32 queue,
 	void __iomem *ioaddr = hw->pcsr;
 	u32 value, reg;
 
-	reg = (queue < 4) ? XGMAC_MTL_RXQ_DMA_MAP0 : XGMAC_MTL_RXQ_DMA_MAP1;
-	if (queue >= 4)
+	switch (queue) {
+	case 0 ... 3:
+		reg = XGMAC_MTL_RXQ_DMA_MAP0;
+		break;
+	case 4 ... 7:
+		reg = XGMAC_MTL_RXQ_DMA_MAP1;
 		queue -= 4;
+		break;
+	case 8 ... 11:
+		reg = XGMAC_MTL_RXQ_DMA_MAP2;
+		queue -= 8;
+		break;
+	case 12 ... 15:
+		reg = XGMAC_MTL_RXQ_DMA_MAP3;
+		queue -= 12;
+		break;
+	default:
+		WARN_ON(1);
+		return;
+	}
 
 	value = readl(ioaddr + reg);
 	value &= ~XGMAC_QxMDMACH(queue);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16
  2026-11-24  0:04 [PATCH net-next v2 0/3] net: stmmac: support up to 16 MTL/DMA queues on XGMAC Sagar Cheluvegowda
  2026-11-24  0:04 ` [PATCH net-next v2 1/3] net: stmmac: separate the TC count from the queue count " Sagar Cheluvegowda
  2026-11-24  0:04 ` [PATCH net-next v2 2/3] net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues Sagar Cheluvegowda
@ 2026-11-24  0:04 ` Sagar Cheluvegowda
  2026-11-25  0:09   ` netdev-bot+sashiko
  2 siblings, 1 reply; 7+ messages in thread
From: Sagar Cheluvegowda @ 2026-11-24  0:04 UTC (permalink / raw)
  To: j.raczynski
  Cc: maxime.chevallier, andrew+netdev, davem, edumazet, kuba, pabeni,
	mcoquelin.stm32, alexandre.torgue, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-arm-msm, cs0617.lee,
	k.domagalski, k.tegowski, abhishek.chauhan, lorenzo.bianconi,
	sarosh.hasan, hongmei.xu, sagar.cheluvegowda

From: Jakub Raczynski <j.raczynski@samsung.com>

Newer XGMAC hardware does support up to 16 DMA/MTL queues.
Add support for these after previous modifications of driver to accommodate
for that.

Co-developed-by: Chang-Sub Lee <cs0617.lee@samsung.com>
Signed-off-by: Chang-Sub Lee <cs0617.lee@samsung.com>
Signed-off-by: Jakub Raczynski <j.raczynski@samsung.com>
Signed-off-by: Sagar Cheluvegowda <sagar.cheluvegowda@oss.qualcomm.com>
---
 include/linux/stmmac.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 00be2df63d22..b91c8d069dc2 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -15,9 +15,9 @@
 #include <linux/platform_device.h>
 #include <linux/phylink.h>
 
-#define MTL_MAX_RX_QUEUES	8
-#define MTL_MAX_TX_QUEUES	8
-#define STMMAC_CH_MAX		8
+#define MTL_MAX_RX_QUEUES	16
+#define MTL_MAX_TX_QUEUES	16
+#define STMMAC_CH_MAX		16
 
 #define STMMAC_RX_COE_NONE	0
 #define STMMAC_RX_COE_TYPE1	1
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 1/3] net: stmmac: separate the TC count from the queue count on XGMAC
  2026-11-24  0:04 ` [PATCH net-next v2 1/3] net: stmmac: separate the TC count from the queue count " Sagar Cheluvegowda
@ 2026-11-25  0:09   ` netdev-bot+sashiko
  0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25  0:09 UTC (permalink / raw)
  To: sagar.cheluvegowda
  Cc: j.raczynski, maxime.chevallier, andrew+netdev, davem, edumazet,
	kuba, pabeni, mcoquelin.stm32, alexandre.torgue, netdev,
	linux-stm32, linux-arm-kernel, linux-kernel, linux-arm-msm,
	cs0617.lee, k.domagalski, k.tegowski, abhishek.chauhan,
	lorenzo.bianconi, sarosh.hasan, hongmei.xu

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 2 · Medium: 1 · Low: 0

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).

- [High] The patch limits the CBS replay in stmmac_configure_cbs()
  (stmmac_main.c:3560) to stmmac_num_tc().
- [High] The patch limits stmmac_mac_config_tx_queues_prio()
  (stmmac_main.c:3622) to stmmac_num_tc() because TC_PRTY (PSTC) is per…
- [Medium] The patch is meant to stop the driver assuming one TC per
  queue on XGMAC, but the register that actually assigns a queue to a TC…

--

net: stmmac: separate the TC count from the queue count on XGMAC

This adds stmmac_num_tc(). It bounds the per-TC register writes (TX queue
weight, CBS replay, TC_PRTY) by the number of TCs the XGMAC reports
instead of by tx_queues_to_use. It also limits the ETS loop to 8 TCs and
bounds the per-priority registers (Qx_TX_FLOW_CTRL, PSRQ) by
STMMAC_NUM_PRIO_QUEUES.

Link: https://lore.kernel.org/netdev/20260601162537.553512-2-j.raczynski@samsung.com/

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
> index fcc395321816f..24bbe72e00719 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h

[ ... ]

> @@ -441,6 +446,18 @@ static inline bool stmmac_check_timestamp_cap(struct stmmac_priv *priv)
>  	return priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp;
>  }
>  
> +/* Most cores have one traffic class per queue, but newer XGMAC can have more
> + * queues than traffic classes (the number of TCs is reported by the HW
> + * feature register).
> + */
> +static inline u32 stmmac_num_tc(const struct stmmac_priv *priv)
> +{
> +	if (!priv->dma_cap.numtc)
> +		return priv->plat->tx_queues_to_use;
> +
> +	return min_t(u32, priv->dma_cap.numtc, priv->plat->tx_queues_to_use);
> +}

[Severity: Medium]
When numtc is smaller than tx_queues_to_use, which TC do the queues at
or above numtc end up on? The register that assigns a queue to a TC
still maps one TC per queue. In dwxgmac2_dma_tx_mode() in dwxgmac2_dma.c:

	/* Use static TC to Queue mapping */
	value |= FIELD_PREP(XGMAC_Q2TCMAP, channel);

The default map that dwxgmac3_fpe_map_preemption_class() in
stmmac_fpe.c restores does the same:

	for (u32 i = 0; i < priv->plat->tx_queues_to_use; i++) {
		val = readl(priv->ioaddr + XGMAC_MTL_TXQ_OPMODE(i));
		writel(u32_replace_bits(val, i, XGMAC_Q2TCMAP),
		       priv->ioaddr + XGMAC_MTL_TXQ_OPMODE(i));
	}

So queues numtc..N-1 are mapped to TC indexes the hardware does not
implement. Weights, CBS and TC_PRTY are now programmed only for TCs below
numtc, so those queues point at TCs that either have no scheduling state
or do not exist.

XGMAC_Q2TCMAP is GENMASK(10, 8). The later patch in the series
("include/stmmac: Increase max DMA/MTL channel count from 8 to 16") makes
channels 8..15 reachable. Would FIELD_PREP() then wrap them silently onto
TC0..7?

The driver code doesn't show how the hardware handles Q2TCMAP >= NUMTC,
so the exact effect on scheduling is uncertain.

There is also a pre-existing issue that this patch did not introduce:
the field is OR-ed in rather than replaced. This runtime path:

stmmac_bump_dma_threshold()->stmmac_set_dma_operation_mode()->
    dwxgmac2_dma_tx_mode()

can OR the channel number into a Q2TCMAP value that mqprio or FPE set
earlier. For example, TC 1 OR channel 2 gives TC 3.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index ca4c7fb11b73f..5d02f7034a7af 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

[ ... ]

> @@ -3548,12 +3552,12 @@ static void stmmac_set_tx_queue_weight(struct stmmac_priv *priv)
>   */
>  void stmmac_configure_cbs(struct stmmac_priv *priv)
>  {
> -	u8 tx_queues_count = priv->plat->tx_queues_to_use;
> +	u8 num_tc = stmmac_num_tc(priv);
>  	u32 mode_to_use;
>  	u8 queue;
>  
>  	/* queue 0 is reserved for legacy traffic */
> -	for (queue = 1; queue < tx_queues_count; queue++) {
> +	for (queue = 1; queue < num_tc; queue++) {
>  		mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use;
>  		if (mode_to_use == MTL_QUEUE_DCB)
>  			continue;

[Severity: High]
The replay path is now bounded by num_tc, but is the runtime CBS path
still unbounded? tc_setup_cbs() in stmmac_tc.c only checks against
tx_queues_to_use:

	u32 tx_queues_count = priv->plat->tx_queues_to_use;
	...
	/* Queue 0 is not AVB capable */
	if (queue <= 0 || queue >= tx_queues_count)
		return -EINVAL;

It then passes queue straight to stmmac_config_cbs(). On XGMAC that call
reaches dwxgmac2_config_cbs(), which uses the queue number as the TC
index:

	writel(send_slope, ioaddr + XGMAC_MTL_TCx_SENDSLOPE(queue));
	writel(idle_slope, ioaddr + XGMAC_MTL_TCx_QUANTUM_WEIGHT(queue));
	writel(high_credit, ioaddr + XGMAC_MTL_TCx_HICREDIT(queue));
	writel(low_credit, ioaddr + XGMAC_MTL_TCx_LOCREDIT(queue));
	...
	writel(value, ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(queue));

With numtc < tx_queues_to_use, a cbs offload qdisc on a queue >= numtc
still writes TC registers that don't exist. The later patch in the
series raises MTL_MAX_TX_QUEUES to 16. Since numtc is at most 8, queues
8..15 on any 16-queue XGMAC are then affected as well.

The commit message says:

    The checks are in the callers, which can return an error to the user,
    instead of in the callbacks, which are void.

tc_setup_cbs() returns int. Should it also reject queue >=
stmmac_num_tc()?

The runtime and replay paths also disagree now. tc_setup_cbs() leaves
tx_queues_cfg[queue].mode_to_use as MTL_QUEUE_AVB, so the queue goes back
to AVB mode on reopen or resume. This loop stops at num_tc, though, so
the slopes and credits for that queue are not replayed.

After resume, won't the hardware state differ from both the pre-suspend
state and tx_queues_cfg[]?

The later patches in the series don't appear to touch stmmac_tc.c.

[ ... ]

> @@ -3611,9 +3616,10 @@ static void stmmac_mac_config_rx_queues_prio(struct stmmac_priv *priv)
>   */
>  static void stmmac_mac_config_tx_queues_prio(struct stmmac_priv *priv)
>  {
> -	int i;
> +	u32 num_tc = stmmac_num_tc(priv);
> +	u32 i;
>  
> -	for (i = 0; i < priv->plat->tx_queues_to_use; i++)
> +	for (i = 0; i < num_tc; i++)
>  		stmmac_tx_queue_prio(priv, priv->hw,
>  				     priv->xmit_qdisc.prio[i], i);
>  }

[Severity: High]
This bounds one caller of the tx_queue_prio callback by num_tc. What
about the two mqprio callers in stmmac_tc.c? Both stmmac_reset_tc_mqprio()
and tc_mqprio_config_queue_prio() still do:

		priv->xmit_qdisc.prio[i] = prio;
		if (i < priv->plat->tx_queues_to_use)
			stmmac_tx_queue_prio(priv, priv->hw, prio, i);

tc_mqprio_validate_chan_mode() requires a 1:1 TC-to-queue map, but it
never compares qopt->num_tc with dma_cap.numtc.

dwxgmac2_tx_queue_prio() uses the index directly as a TC slot:

	reg = (queue < 4) ? XGMAC_TC_PRTY_MAP0 : XGMAC_TC_PRTY_MAP1;
	if (queue >= 4)
		queue -= 4;

	value = readl(ioaddr + reg);
	value &= ~XGMAC_PSTC(queue);
	value |= (prio << XGMAC_PSTC_SHIFT(queue)) & XGMAC_PSTC(queue);

On an XGMAC with numtc < tx_queues_to_use, setting up or tearing down
mqprio would still program PSTC fields for TCs that don't exist.

Once the series raises MTL_MAX_TX_QUEUES to 16, indexes 8..15 become
4..11 after the subtraction, and XGMAC_PSTC_SHIFT() gives 32..88. Is that
an out-of-range shift of the u32 prio (UBSAN shift-out-of-bounds)? Does
XGMAC_PSTC() also go past bit 31, so the priority mapping for those TCs
is silently lost?

The paths also disagree after this change. mqprio programs
xmit_qdisc.prio[] for every queue in use, but this function replays only
the first num_tc entries on open or resume.

Should the mqprio paths use stmmac_num_tc() as well? The later patches in
the series don't appear to change these callers.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124000415.4067701-1-sagar.cheluvegowda%40oss.qualcomm.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 2/3] net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues
  2026-11-24  0:04 ` [PATCH net-next v2 2/3] net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues Sagar Cheluvegowda
@ 2026-11-25  0:09   ` netdev-bot+sashiko
  0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25  0:09 UTC (permalink / raw)
  To: sagar.cheluvegowda
  Cc: j.raczynski, maxime.chevallier, andrew+netdev, davem, edumazet,
	kuba, pabeni, mcoquelin.stm32, alexandre.torgue, netdev,
	linux-stm32, linux-arm-kernel, linux-kernel, linux-arm-msm,
	cs0617.lee, k.domagalski, k.tegowski, abhishek.chauhan,
	lorenzo.bianconi, sarosh.hasan, hongmei.xu

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · 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).

- [High] dwxgmac2_tx_queue_prio() in
  drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c still only handles…
- [Low] The commit message says "The only caller,
  stmmac_rx_queue_dma_chan_map(), walks the queues below…
- [Low] The commit body of "net/stmmac/dwxgmac: Extend MTL/DMA support to
  16 queues" contains revision history that only makes sense on the…

--

net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues

This commit extends dwxgmac2_map_mtl_to_dma() to cover 16 MTL/DMA queues.
It adds the XGMAC_MTL_RXQ_DMA_MAP2 and XGMAC_MTL_RXQ_DMA_MAP3 registers
ahead of raising the maximum queue count. Queue indices that are out of
range now trigger a WARN_ON() and return.

> The only caller, stmmac_rx_queue_dma_chan_map(), walks the queues
> below rx_queues_to_use, which the devicetree parser limits to
> MTL_MAX_RX_QUEUES. A queue above 15 is therefore a driver bug, not
> bad input.

[Severity: Low]
Is stmmac_rx_queue_dma_chan_map() really the only caller?
dwxgmac2_rss_configure() in dwxgmac2_core.c also calls
dwxgmac2_map_mtl_to_dma() directly. It does not go through the
stmmac_map_mtl_to_dma() callback:

dwxgmac2_rss_configure() {
    ...
	for (i = 0; i < num_rxq; i++)
		dwxgmac2_map_mtl_to_dma(hw, i, XGMAC_QDDMACH);
    ...
}

Here num_rxq is rx_queues_to_use. That value can also come from ethtool
set_channels, not only from the devicetree parser.

By the end of the series both paths are limited to at most 16 queues, so
the WARN_ON() still can't fire from either one. The reasoning in the
message is what is off, not the behaviour.

Could the commit message mention this second caller, given that the
WARN_ON() justification rests on the single-caller argument?

> bad input. v2 reported it with netdev_err() through hw->priv_data,
> but that back-pointer was only added by v2 1/3, which this series
> replaces, and a log line from a void callback does not stop the
> caller from carrying on. Use WARN_ON() instead: it needs no
> net_device and its backtrace points at the caller.

[Severity: Low]
This isn't a bug, but this text refers to "v2 1/3" and to an
hw->priv_data back-pointer. Neither will exist in the tree once the
patch is merged.

Could the version history go below the --- separator? The technical
reason for WARN_ON() (it needs no net_device and the backtrace points at
the caller) can stay in the message.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> index e50c0f4c482d0..8aa69647a207d 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> @@ -259,9 +259,26 @@ static void dwxgmac2_map_mtl_to_dma(struct mac_device_info *hw, u32 queue,
>  	void __iomem *ioaddr = hw->pcsr;
>  	u32 value, reg;
>  
> -	reg = (queue < 4) ? XGMAC_MTL_RXQ_DMA_MAP0 : XGMAC_MTL_RXQ_DMA_MAP1;
> -	if (queue >= 4)
> +	switch (queue) {
> +	case 0 ... 3:
> +		reg = XGMAC_MTL_RXQ_DMA_MAP0;
> +		break;
> +	case 4 ... 7:
> +		reg = XGMAC_MTL_RXQ_DMA_MAP1;
>  		queue -= 4;
> +		break;
> +	case 8 ... 11:
> +		reg = XGMAC_MTL_RXQ_DMA_MAP2;
> +		queue -= 8;
> +		break;
> +	case 12 ... 15:
> +		reg = XGMAC_MTL_RXQ_DMA_MAP3;
> +		queue -= 12;
> +		break;
> +	default:
> +		WARN_ON(1);
> +		return;
> +	}

[Severity: High]
The commit message says the dwxgmac functions are being prepared for 16
queues before the macro is raised. However, dwxgmac2_tx_queue_prio() in
the same file still handles only 8 entries:

dwxgmac2_tx_queue_prio() {
    ...
	reg = (queue < 4) ? XGMAC_TC_PRTY_MAP0 : XGMAC_TC_PRTY_MAP1;
	if (queue >= 4)
		queue -= 4;

	value = readl(ioaddr + reg);
	value &= ~XGMAC_PSTC(queue);
	value |= (prio << XGMAC_PSTC_SHIFT(queue)) & XGMAC_PSTC(queue);
    ...
}

At this patch ARRAY_SIZE(tx_queues_cfg) is still 8. The later patch
"include/stmmac: Increase max DMA/MTL channel count from 8 to 16" makes
it 16. After that, can the mqprio paths in stmmac_tc.c call this
function with queue indices 8 to 15?

Both tc_mqprio_config_queue_prio() and stmmac_reset_tc_mqprio() run this
loop:

	for (i = 0; i < ARRAY_SIZE(priv->plat->tx_queues_cfg); i++) {
		...
		if (i < priv->plat->tx_queues_to_use)
			stmmac_tx_queue_prio(priv, priv->hw, prio, i);
	}

tx_queues_to_use can be 16 there. The devicetree limit is
MTL_MAX_TX_QUEUES, and XGMAC_HWFEAT_TXQCNT is a 4-bit field plus 1.
Neither loop is bounded by qopt->num_tc or dma_cap.numtc.

For i = 8 to 15, queue is 4 to 11 after the subtraction. The expression
prio << XGMAC_PSTC_SHIFT(queue) then shifts a u32 by 32 to 88 bits. For
i >= 12, XGMAC_PSTC(queue) expands to GENMASK() with bit positions of 64
and above. Both shifts are undefined behaviour, and UBSAN reports them
as shift-out-of-bounds.

The hardware also ends up programmed wrongly:

  - For i = 8 to 11, the mask truncates to 0 in the u32, so nothing is
    written.
  - For i = 12 to 15 on x86-64 and arm64, the shift counts wrap. The
    write then likely lands on the PSTC4 to PSTC7 fields of
    XGMAC_TC_PRTY_MAP1 and overwrites the priorities already set for
    TCs 4 to 7, usually with 0.

A CAP_NET_ADMIN user triggers this by adding an mqprio qdisc with
hardware offload:

ndo_setup_tc
  -> tc_setup_dwmac510_mqprio()
    -> tc_mqprio_config_queue_prio()
      -> stmmac_tx_queue_prio()
        -> dwxgmac2_tx_queue_prio()

XGMAC uses dwmac510_tc_ops, whose setup_mqprio is
tc_setup_dwmac510_mqprio(). Removing the qdisc runs the same loop
through stmmac_reset_tc_mqprio().

The earlier patch "net: stmmac: separate the TC count from the queue
count on XGMAC" bounds the rx_queue_prio callers and
stmmac_mac_config_tx_queues_prio(). These two mqprio callers seem to
have been missed, so writes to TC_PRTY fields for TCs that don't exist
can still happen on XGMAC.

Should these loops be bounded by the TC count? Alternatively, should
dwxgmac2_tx_queue_prio() reject queue >= 8?

>  
>  	value = readl(ioaddr + reg);
>  	value &= ~XGMAC_QxMDMACH(queue);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124000415.4067701-1-sagar.cheluvegowda%40oss.qualcomm.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16
  2026-11-24  0:04 ` [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16 Sagar Cheluvegowda
@ 2026-11-25  0:09   ` netdev-bot+sashiko
  0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25  0:09 UTC (permalink / raw)
  To: sagar.cheluvegowda
  Cc: j.raczynski, maxime.chevallier, andrew+netdev, davem, edumazet,
	kuba, pabeni, mcoquelin.stm32, alexandre.torgue, netdev,
	linux-stm32, linux-arm-kernel, linux-kernel, linux-arm-msm,
	cs0617.lee, k.domagalski, k.tegowski, abhishek.chauhan,
	lorenzo.bianconi, sarosh.hasan, hongmei.xu

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] tc_setup_cbs() (stmmac_tc.c:343) checks the CBS queue only
  against tx_queues_to_use.
- [Medium] With up to 16 TX queues, tc_setup_dwmac510_mqprio()
  (stmmac_tc.c:1456-1464) checks only that offset+count <=…
- [Medium] dwxgmac2_tx_queue_prio() (dwxgmac2_core.c:140-155) handles
  only TX queues/TCs 0..7.
- [Low] net: stmmac: 3-bit queue mask truncation in
  EST_SZ_CAP_HBFQ_MASK()
- [Low] net: stmmac: signed shift overflow in dwxgmac2_rx_queue_enable()
  for queue 15

--

include/stmmac: Increase max DMA/MTL channel count from 8 to 16

This commit raises MTL_MAX_RX_QUEUES, MTL_MAX_TX_QUEUES and STMMAC_CH_MAX
from 8 to 16 so that newer XGMAC hardware with up to 16 DMA/MTL queues can
use all of them.

> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> index 00be2df63d220..b91c8d069dc28 100644
> --- a/include/linux/stmmac.h
> +++ b/include/linux/stmmac.h
> @@ -15,9 +15,9 @@
>  #include <linux/platform_device.h>
>  #include <linux/phylink.h>
>  
> -#define MTL_MAX_RX_QUEUES	8
> -#define MTL_MAX_TX_QUEUES	8
> -#define STMMAC_CH_MAX		8
> +#define MTL_MAX_RX_QUEUES	16
> +#define MTL_MAX_TX_QUEUES	16

[Severity: Low]
Can stmmac_mac_enable_rx_queues() now evaluate a signed shift into the
sign bit?

Both dwxgmac2_rx_queue_enable() and dwxlgmac2_rx_queue_enable() in
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c do:

	else if (mode == MTL_QUEUE_DCB)
		value |= 0x2 << XGMAC_RXQEN_SHIFT(queue);

XGMAC_RXQEN_SHIFT(x) is defined as ((x) * 2). With MTL_MAX_RX_QUEUES
at 16, rx_queues_to_use can be 16, and stmmac_mac_enable_rx_queues()
then passes queue 15, giving 0x2 << 30. Since 0x2 is a plain int, this
shifts a 1 into bit 31. That is undefined behaviour in C and can be
flagged by CONFIG_UBSAN_SHIFT.

MTL_QUEUE_DCB is the default rx queue mode, so this would be hit on
every interface bring-up through stmmac_hw_setup() on a 16-queue
XGMAC/XLGMAC configuration.

The register value most likely still comes out right with the kernel's
compiler flags. Could these constants be made unsigned (0x2U, or
FIELD_PREP() with XGMAC_RXQEN(queue)) as part of the preparatory
changes before the limit is raised?

[Severity: Low]
Now that tx_queues_to_use can be larger than 8, does est_irq_status()
still report the right queue on a head-of-line blocking event?

In drivers/net/ethernet/stmicro/stmmac/stmmac_est.c:est_irq_status(),
the EST_HLBF handling does:

	value = readl(est_addr + EST_FRM_SZ_CAP);
	hbfq = (value & EST_SZ_CAP_HBFQ_MASK(txqcnt)) >>
		EST_SZ_CAP_HBFQ_SHIFT;

txqcnt is priv->plat->tx_queues_to_use, passed down from
stmmac_common_interrupt(). EST_SZ_CAP_HBFQ_MASK() in stmmac_est.h only
knows about up to 8 queues:

	(_val > 4 ? GENMASK(18, 16) :
	 _val > 2 ? GENMASK(17, 16) :
	 BIT(16));

For txqcnt 9..16 the mask stays 3 bits wide and bit 19 is dropped.
An HLBF event on queues 8..15 is then logged in the "EST: HLB(size)
Queue %u" message as queue 0..7. That points the user at the wrong
queue when debugging a taprio schedule.

The impact is limited to the diagnostic message. Should
EST_SZ_CAP_HBFQ_MASK() gain a _val > 8 ? GENMASK(19, 16) branch? Can
you confirm the HBFQ field in EST_FRM_SZ_CAP really widens to 4 bits on
the 16-queue XGMAC cores?

[Severity: Medium]
Now that tx_queues_to_use can be larger than 8, can tc_setup_cbs() program
per-TC registers that do not exist on XGMAC?

In drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c:tc_setup_cbs(), the
only bound on the CBS queue is:

	/* Queue 0 is not AVB capable */
	if (queue <= 0 || queue >= tx_queues_count)
		return -EINVAL;

The queue is then used directly as a traffic class index. dwxgmac2_qmode()
does:

	writel(0, ioaddr + XGMAC_MTL_TCx_ETS_CONTROL(channel));

dwxgmac2_config_cbs() also writes XGMAC_MTL_TCx_SENDSLOPE(),
XGMAC_MTL_TCx_QUANTUM_WEIGHT(), XGMAC_MTL_TCx_HICREDIT(),
XGMAC_MTL_TCx_LOCREDIT() and XGMAC_MTL_TCx_ETS_CONTROL() using that same
queue. XGMAC has at most XGMAC_MAX_TC (8) traffic classes, and
dma_cap.numtc can be lower than that.

At the same time, dwxgmac2_dma_tx_mode() puts the queue into a 3-bit
field:

	value |= FIELD_PREP(XGMAC_Q2TCMAP, channel);

That means queue 9 is served by TC1. TC1's shaper is never touched, and
the tc command still returns success.

The path is:

  tc qdisc replace ... cbs ... offload 1
    stmmac_setup_tc()
      tc_setup_cbs()
        stmmac_dma_qmode() -> dwxgmac2_qmode()
        stmmac_config_cbs() -> dwxgmac2_config_cbs()

The earlier commit "net: stmmac: separate the TC count from the queue
count on XGMAC" described this as writes to TC registers that do not
exist. It bounded the resume replay in stmmac_configure_cbs() by
stmmac_num_tc():

	for (queue = 1; queue < num_tc; queue++) {

However, tc_setup_cbs() is still bounded only by tx_queues_to_use. As a
result, CBS state saved for queues >= num_tc is also silently not
restored.

Should tc_setup_cbs() reject queues >= stmmac_num_tc() as well?

[Severity: Medium]
With more than 8 TX queues, can dwxgmac3_fpe_map_preemption_class()
silently truncate both the TC number and the preemption class?

tc_setup_dwmac510_mqprio() only checks offset + count against
tx_queues_to_use. It therefore accepts num_tc up to 16 and queue ranges
that include queues 8..15. It then reaches this code in
drivers/net/ethernet/stmicro/stmmac/stmmac_fpe.c:

dwxgmac3_fpe_map_preemption_class() {
    ...
		for (u32 i = 0; i < count; i++) {
			val = readl(priv->ioaddr + XGMAC_MTL_TXQ_OPMODE(offset + i));
			writel(u32_replace_bits(val, tc, XGMAC_Q2TCMAP),
			       priv->ioaddr + XGMAC_MTL_TXQ_OPMODE(offset + i));
		}
    ...
}

XGMAC_Q2TCMAP is GENMASK(10, 8), so TC 8..15 alias onto hardware
TC 0..7.

The preemption class is written with:

	writel(u32_replace_bits(val, preemptible_txqs, FPE_MTL_PREEMPTION_CLASS),
	       priv->ioaddr + XGMAC_MTL_FPE_CTRL_STS);

FPE_MTL_PREEMPTION_CLASS is GENMASK(15, 8), so bits 8..15 of
preemptible_txqs are dropped. For example, with num_tc 2, TC1 on queues
8-15 and TC1 marked preemptible, preemptible_txqs is 0xFF00 and 0 is
written to the field.

When num_tc is 0, the default restore loop writes i, up to
tx_queues_to_use - 1, into the same 3-bit XGMAC_Q2TCMAP field.

No error is returned to the user in any of these cases. Should the
mqprio/FPE path reject configurations that do not fit these register
fields?

[Severity: Medium]
Does dwxgmac2_tx_queue_prio() handle queues 8 and above?

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c:dwxgmac2_tx_queue_prio() {
    ...
	reg = (queue < 4) ? XGMAC_TC_PRTY_MAP0 : XGMAC_TC_PRTY_MAP1;
	if (queue >= 4)
		queue -= 4;

	value = readl(ioaddr + reg);
	value &= ~XGMAC_PSTC(queue);
	value |= (prio << XGMAC_PSTC_SHIFT(queue)) & XGMAC_PSTC(queue);
    ...
}

For queues 8..15 the sub-index becomes 4..11. For queues 8..11, prio is a
u32 shifted by 32..56 bits. For queues 12..15, XGMAC_PSTC() also expands
to a GENMASK() past bit 63. Both are undefined behaviour.

On x86-64, queues 12..15 end up overwriting the TC4..TC7 fields of
XGMAC_TC_PRTY_MAP1.

These calls can now be reached from tc_mqprio_config_queue_prio() and
stmmac_reset_tc_mqprio(). Both loop over ARRAY_SIZE(tx_queues_cfg), which
is now 16, and do:

		if (i < priv->plat->tx_queues_to_use)
			stmmac_tx_queue_prio(priv, priv->hw, prio, i);

Neither loop is bounded by num_tc. By contrast, the boot-time
stmmac_mac_config_tx_queues_prio() is bounded by stmmac_num_tc().

The path is:

  tc qdisc add ... mqprio ... hw 1 mode channel
    tc_setup_dwmac510_mqprio()
      tc_mqprio_config_queue_prio()
        stmmac_tx_queue_prio() -> dwxgmac2_tx_queue_prio()

Should these mqprio loops also be limited to stmmac_num_tc()?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124000415.4067701-1-sagar.cheluvegowda%40oss.qualcomm.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-25  0:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  0:04 [PATCH net-next v2 0/3] net: stmmac: support up to 16 MTL/DMA queues on XGMAC Sagar Cheluvegowda
2026-11-24  0:04 ` [PATCH net-next v2 1/3] net: stmmac: separate the TC count from the queue count " Sagar Cheluvegowda
2026-11-25  0:09   ` netdev-bot+sashiko
2026-11-24  0:04 ` [PATCH net-next v2 2/3] net/stmmac/dwxgmac: Extend MTL/DMA support to 16 queues Sagar Cheluvegowda
2026-11-25  0:09   ` netdev-bot+sashiko
2026-11-24  0:04 ` [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16 Sagar Cheluvegowda
2026-11-25  0:09   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox