Netdev List
 help / color / mirror / Atom feed
From: Kordian Chmielewski <kudzo51@gmail.com>
To: netdev@vger.kernel.org
Cc: "Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Jonas Gorski" <jonas.gorski@gmail.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Vladimir Oltean" <olteanv@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"David S . Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>
Subject: [PATCH net] net: dsa: bcm_sf2: raise BCM4908 egress queue flow control thresholds
Date: Wed,  2 Dec 2026 10:57:25 +0100	[thread overview]
Message-ID: <20261202095725.157121-1-kudzo51@gmail.com> (raw)

bcm_sf2_port_setup() writes a pause threshold of 32 pages to
CORE_TXQ_THD_PAUSE_QN_PORT(port). On the BCM4908 switch these registers
of flow control page 0x0B hold per egress queue thresholds that all ports
share, so the write for each user port lands on the queue with the same
number. On a TP-Link Archer AX6000 v1, whose user ports are 0-3 and 7,
the switch reads back 32 pages for queues 0-3 and 7, and queue 0 carries
the traffic to the CPU. The frames that the CPU sends are accounted in
another set of thresholds, page 0x0D, which the driver does not touch
(pause thresholds of 199-255 pages there).

The switch runs in TX based flow control mode (PAUSE_DROP_CTRL, page
0x0A register 0x1C, reads 0x0fd9), and the WAN port, whose link came up
with flow control off, loses frames at ingress once their egress queue
is over its pause threshold. Measured on that router with iperf3, with
the thresholds changed at run time:

- a 2.5G host on the WAN port sending to the router, 4 TCP streams for
  15 s: queue 0 peaked at 40 pages and the router received 1386 Mbit/s.
  With the thresholds below, queue 0 peaked at 802 pages and the router
  received 1877 and 1876 Mbit/s in two runs, with about as many TCP
  retransmissions as before (15016 and 14177, against 16921). With only
  queue 0 changed, pause levels of 199 and 400 pages gave 1824 to 1871
  Mbit/s and levels from 700 to 1000 pages all gave 1875 to 1877 Mbit/s,
  while a hysteresis far below the pause level multiplied the
  retransmissions (35474 at 1000/500 pages, 10164 at 1000/968).

- a Wi-Fi client sending through the router to a host on a 1G LAN port,
  4 TCP streams for 15 s: with page 0x0D at its defaults, the busiest
  queues of that port peaked within 5 pages of their page 0x0D pause
  thresholds and the host received 377 and 540 Mbit/s in two runs. With
  page 0x0D at 800 pages, those queues went up to 804 pages and the host
  received 668 to 725 Mbit/s in four runs.

The router ran OpenWrt with Linux 6.12 and changes that are not in
mainline: for the WAN port, the 2.5G PHY behind it and the SerDes
between them, for the Wi-Fi chip, and for bcm4908_enet, among them
earlier versions of most of its fixes now in net.

On BCM4908, skip the 32-page write and program both pages: every egress
queue pauses at 800 pages and all queues together at 1300, below the
total drop thresholds of 1423-1527 pages, and each resumes 32 pages
lower. The drop thresholds keep their defaults.

Fixes: 73b7a6047971 ("net: dsa: bcm_sf2: support BCM4908's integrated switch")
Signed-off-by: Kordian Chmielewski <kudzo51@gmail.com>
---
Tested again on an Archer AX6000 v1 with OpenWrt, Linux 6.18.55 and
this version of the patch, with a device tree that has no WAN port and
no Wi-Fi yet, so the runs above could not be repeated: after boot the
switch reads back 800/768 pages for every queue and 1300/1268 for the
totals on both pages, with the drop thresholds at their defaults, and
TCP between the router and a host on a 1G LAN port ran at 941 Mbit/s in
both directions.

 drivers/net/dsa/bcm_sf2.c      | 44 ++++++++++++++++++++++++++++++++--
 drivers/net/dsa/bcm_sf2_regs.h | 11 +++++++++
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index cbaa5de9b107..f8b7d2b9ee7e 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -330,8 +330,11 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
 	if (port == priv->moca_port)
 		bcm_sf2_port_intr_enable(priv, port);
 
-	/* Set per-queue pause threshold to 32 */
-	core_writel(priv, 32, CORE_TXQ_THD_PAUSE_QN_PORT(port));
+	/* Set per-queue pause threshold to 32, except on BCM4908: see
+	 * bcm_sf2_4908_txq_thresholds()
+	 */
+	if (priv->type != BCM4908_DEVICE_ID)
+		core_writel(priv, 32, CORE_TXQ_THD_PAUSE_QN_PORT(port));
 
 	/* Set ACB threshold to 24 */
 	for (i = 0; i < SF2_NUM_EGRESS_QUEUES; i++) {
@@ -947,6 +950,41 @@ static void bcm_sf2_enable_acb(struct dsa_switch *ds)
 	acb_writel(priv, reg, ACB_CONTROL);
 }
 
+/* On BCM4908 the flow control thresholds are per egress queue and shared by
+ * all ports, in sets chosen by where a frame enters the switch: page 0x0B for
+ * the frames received on the user ports and page 0x0D for the frames sent by
+ * the CPU on port 8 (IMP0). A queue over its pause threshold drops what a port
+ * without flow control sends to it, and the 32 pages that
+ * bcm_sf2_port_setup() writes on other switches would land on the page 0x0B
+ * queues numbered like the user ports, queue 0 among them, which carries the
+ * traffic to the CPU. Pause each queue at 800 pages and all of them together
+ * at 1300, and resume 32 pages below each level. The drop thresholds keep
+ * their defaults.
+ */
+#define BCM4908_TXQ_PAUSE_THD	800
+#define BCM4908_TXQ_HYST_THD	(BCM4908_TXQ_PAUSE_THD - 32)
+#define BCM4908_TOTAL_PAUSE_THD	1300
+#define BCM4908_TOTAL_HYST_THD	(BCM4908_TOTAL_PAUSE_THD - 32)
+
+static void bcm_sf2_4908_txq_thresholds(struct bcm_sf2_priv *priv)
+{
+	static const u32 pages[] = { CORE_FC_LAN_TXQ, CORE_FC_IMP0_TXQ };
+	unsigned int i, q;
+
+	for (i = 0; i < ARRAY_SIZE(pages); i++) {
+		for (q = 0; q < SF2_NUM_EGRESS_QUEUES; q++) {
+			core_writel(priv, BCM4908_TXQ_PAUSE_THD,
+				    pages[i] + FC_TXQ_THD_PAUSE(q));
+			core_writel(priv, BCM4908_TXQ_HYST_THD,
+				    pages[i] + FC_TXQ_THD_HYST(q));
+			core_writel(priv, BCM4908_TOTAL_PAUSE_THD,
+				    pages[i] + FC_TOTAL_THD_PAUSE(q));
+			core_writel(priv, BCM4908_TOTAL_HYST_THD,
+				    pages[i] + FC_TOTAL_THD_HYST(q));
+		}
+	}
+}
+
 static int bcm_sf2_sw_suspend(struct dsa_switch *ds)
 {
 	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
@@ -1078,6 +1116,8 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
 
 	b53_configure_vlan(ds);
 	bcm_sf2_enable_acb(ds);
+	if (priv->type == BCM4908_DEVICE_ID)
+		bcm_sf2_4908_txq_thresholds(priv);
 
 	ret = b53_enable_mcast_snooping(priv->dev);
 	if (ret)
diff --git a/drivers/net/dsa/bcm_sf2_regs.h b/drivers/net/dsa/bcm_sf2_regs.h
index da0dedbd6555..27977d0a25cb 100644
--- a/drivers/net/dsa/bcm_sf2_regs.h
+++ b/drivers/net/dsa/bcm_sf2_regs.h
@@ -322,6 +322,17 @@ enum bcm_sf2_reg_offs {
 #define CORE_TXQ_THD_PAUSE_QN_PORT(x)	(CORE_TXQ_THD_PAUSE_QN_PORT_0 + \
 					(x) * 0x8)
 
+/* Flow control pages with per egress queue thresholds, shared by all ports,
+ * in 256-byte buffer pages: 0x0B for frames received on the user ports, 0x0D
+ * for frames sent by the CPU (IMP0)
+ */
+#define CORE_FC_LAN_TXQ			0x2c00
+#define CORE_FC_IMP0_TXQ		0x3400
+#define  FC_TXQ_THD_HYST(q)		(0x040 + (q) * 0x8)
+#define  FC_TXQ_THD_PAUSE(q)		(0x080 + (q) * 0x8)
+#define  FC_TOTAL_THD_HYST(q)		(0x100 + (q) * 0x8)
+#define  FC_TOTAL_THD_PAUSE(q)		(0x140 + (q) * 0x8)
+
 #define CORE_DEFAULT_1Q_TAG_P(x)	(0xd040 + ((x) * 8))
 #define  CFI_SHIFT			12
 #define  PRI_SHIFT			13

base-commit: 0d39bf81267861742b80d5f1c52e8a63e9ca0ca1
-- 
2.56.1


                 reply	other threads:[~2026-12-02  9:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202095725.157121-1-kudzo51@gmail.com \
    --to=kudzo51@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=jonas.gorski@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=rafal@milecki.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox