mirror of https://lore.kernel.org/lkml/
 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-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, 0 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

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	[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-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, 0 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

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	[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
  2 siblings, 0 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

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	[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-06-04 13:16     ` Paolo Abeni
@ 2026-06-08  8:42       ` Jakub Raczynski
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Raczynski @ 2026-06-08  8:42 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, andrew+netdev, davem, edumazet, kuba, mcoquelin.stm32,
	alexandre.torgue, linux-kernel, k.domagalski, k.tegowski,
	cs0617.lee

[-- Attachment #1: Type: text/plain, Size: 2453 bytes --]

I will be rewriting this patch as discussed in other thread,
but will mention that IMO this AI review is generally invalid.
Below why.

On Thu, Jun 04, 2026 at 03:16:06PM +0200, Paolo Abeni wrote:
> From: AI Reviewer <ai@example.com>
> 
> 
> [Severity: High]
> Does increasing these limits to 16 cause undefined behavior and silent register
> truncation in the hardware configuration functions when queue >= 8?
> 
> In dwxgmac2_core.c:dwxgmac2_tx_queue_prio(), when queue >= 8, the logic
> only subtracts 4:
> 
>     if (queue >= 4)
>         queue -= 4;

This ignores previous check of queue > numtc, which is hardware returning
maximum value of 8 (0-7). This is not direct 'queue > 7 ' for AI so I get it,
but this is not possible, unless hardware would return wrong value.

> 
> Finally, dwmac4_core.c:dwmac4_map_mtl_dma() only maps queues up to 7 (using
> MAP0 and MAP1):
> 
>     if (queue < 4) {
>     ...
>     } else {
>         value = readl(ioaddr + MTL_RXQ_DMA_MAP1);
>         value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue - 4);

Correct, would probably be good to not forget about dwmac, although
GMAC does not return number of available TC's so check would be artificial.
Although no function checks that currently, will be fixed by last comment and
probably checking this stuff in upper layer.

> 
> [Severity: Critical]
> This is a pre-existing issue, but does missing bounds checking on the device
> tree properties expose an out-of-bounds array access during device probe?
> 
> In stmmac_platform.c:stmmac_mtl_setup(), the device tree property
> snps,tx-queues-to-use is parsed and clamped only to 255 (U8_MAX):
> 
>     if (!of_property_read_u32(tx_node, "snps,tx-queues-to-use", &value)) {
>         if (value > U8_MAX)
>             value = U8_MAX;
>         plat->tx_queues_to_use = value;
>     }

'Net' material, not for this patch (net-next), will probably send it later,
as this is valid

> 
> Later in stmmac_main.c:stmmac_hw_setup(), it attempts to dynamically clamp
> this value to the hardware capabilities:
> 
>     if (priv->dma_cap.number_tx_queues &&
>         priv->plat->tx_queues_to_use > priv->dma_cap.number_tx_queues) {
>         priv->plat->tx_queues_to_use = priv->dma_cap.number_tx_queues;
>     }

Well, XGMAC will correct incorrect value, so why not do the same for GMAC
even though it would be artificial > MTL_MAX_TX_QUEUES.
Same for RX. Although same as for above, probably 'net' material

BR
Jakub Raczynski

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ 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-06-01 16:25   ` [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16 Jakub Raczynski
@ 2026-06-04 13:16     ` Paolo Abeni
  2026-06-08  8:42       ` Jakub Raczynski
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Abeni @ 2026-06-04 13:16 UTC (permalink / raw)
  To: j.raczynski
  Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni,
	mcoquelin.stm32, alexandre.torgue, linux-kernel, k.domagalski,
	k.tegowski, cs0617.lee

From: AI Reviewer <ai@example.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/
---
include/stmmac: Increase max DMA/MTL channel count from 8 to 16

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

> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
> index 4430b967abdeb..a9d19e2c388c6 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

[Severity: High]
Does increasing these limits to 16 cause undefined behavior and silent register
truncation in the hardware configuration functions when queue >= 8?

In dwxgmac2_core.c:dwxgmac2_tx_queue_prio(), when queue >= 8, the logic
only subtracts 4:

    if (queue >= 4)
        queue -= 4;

This leaves queue >= 4, which causes XGMAC_PSTC_SHIFT(queue) to shift by >= 32
bits, overflowing the 32-bit integer.

A similar regression occurs in dwmac4_core.c:dwmac4_tx_queue_priority() where
it shifts by GMAC_TXQCTRL_PSTQX_SHIFT(queue).

Additionally, in dwmac4_core.c:dwmac4_rx_queue_routing(), the queue variable
is masked against a 3-bit bitmask, which silently truncates any queue >= 8:

    value |= (queue << route_possibilities[packet-1].reg_shift) & 
             route_possibilities[packet - 1].reg_mask;

Finally, dwmac4_core.c:dwmac4_map_mtl_dma() only maps queues up to 7 (using
MAP0 and MAP1):

    if (queue < 4) {
    ...
    } else {
        value = readl(ioaddr + MTL_RXQ_DMA_MAP1);
        value &= ~MTL_RXQ_DMA_QXMDMACH_MASK(queue - 4);

For queue >= 8, the shift calculation overflows and corrupts register data.
Should these hardware configuration functions be updated to handle the expanded
queue limits?

[Severity: Critical]
This is a pre-existing issue, but does missing bounds checking on the device
tree properties expose an out-of-bounds array access during device probe?

In stmmac_platform.c:stmmac_mtl_setup(), the device tree property
snps,tx-queues-to-use is parsed and clamped only to 255 (U8_MAX):

    if (!of_property_read_u32(tx_node, "snps,tx-queues-to-use", &value)) {
        if (value > U8_MAX)
            value = U8_MAX;
        plat->tx_queues_to_use = value;
    }

Later in stmmac_main.c:stmmac_hw_setup(), it attempts to dynamically clamp
this value to the hardware capabilities:

    if (priv->dma_cap.number_tx_queues &&
        priv->plat->tx_queues_to_use > priv->dma_cap.number_tx_queues) {
        priv->plat->tx_queues_to_use = priv->dma_cap.number_tx_queues;
    }

However, if the hardware feature registers report 0 (which happens for older
GMAC versions), this check is bypassed. The driver fails to clamp the
requested queues against the static internal array limit MTL_MAX_TX_QUEUES.

As a result, in stmmac_main.c:init_dma_tx_desc_rings(), the initialization
loop iterates up to the unvalidated tx_queues_to_use:

    for (queue = 0; queue < tx_queue_cnt; queue++)
        __init_dma_tx_desc_rings(priv, dma_conf, queue);

This will overrun the bounds of arrays embedded in struct stmmac_priv (like
dma_conf->tx_queue) if the device tree configuration exceeds the static array
limits. Should we add a strict bounds check against MTL_MAX_TX_QUEUES and
MTL_MAX_RX_QUEUES during probe?
-- 
This is an AI-generated review.


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

* [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16
       [not found] ` <CGME20260601162619eucas1p19788338440838a1c071367c1b8772726@eucas1p1.samsung.com>
@ 2026-06-01 16:25   ` Jakub Raczynski
  2026-06-04 13:16     ` Paolo Abeni
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Raczynski @ 2026-06-01 16:25 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
	alexandre.torgue, linux-kernel, k.domagalski, k.tegowski,
	cs0617.lee, Jakub Raczynski

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>
---
 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 4430b967abde..a9d19e2c388c 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	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-24  0:04 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-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
  -- strict thread matches above, loose matches on Subject: below --
2026-06-01 16:25 [PATCH net-next v2 0/3] xgmac: Support for 16 MTL/DMA queues Jakub Raczynski
     [not found] ` <CGME20260601162619eucas1p19788338440838a1c071367c1b8772726@eucas1p1.samsung.com>
2026-06-01 16:25   ` [PATCH net-next v2 3/3] include/stmmac: Increase max DMA/MTL channel count from 8 to 16 Jakub Raczynski
2026-06-04 13:16     ` Paolo Abeni
2026-06-08  8:42       ` Jakub Raczynski

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®