net: dsa: bcm_sf2: raise BCM4908 egress queue flow control thresholds
PATCH 1/1 net: dsa: bcm_sf2: raise BCM4908 egress queue flow control thresholds
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.
---
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(-)
drivers/net/dsa/bcm_sf2.c +42 -2
@@ -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)
drivers/net/dsa/bcm_sf2_regs.h +11 -0
@@ -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
Signature · 1 line
2.56.1
Quoted 33 lines · Kordian Chmielewski
bcm_sf2_port_setup()writes a pause threshold of 32 pages toCORE_TXQ_THD_PAUSE_QN_PORT(port). On the BCM4908 switch these registers of flow control page0x0Bhold 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, page0x0D, 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, page0x0Aregister0x1C, reads0x0fd9), 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
0x0Dat its defaults, the busiest queues of that port peaked within 5 pages of their page0x0Dpause thresholds and the host received 377 and 540 Mbit/s in two runs. With page0x0Dat 800 pages, those queues went up to 804 pages and the host received 668 to 725 Mbit/s in four runs.
Quoted 4 lines
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 forbcm4908_enet, among them earlier versions of most of its fixes now in net.
Not sure if we need this paragraph in the commit message, it does and will respond to Sashiko I presume?
Quoted 8 lines
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 <[email protected]>
Quoted 8 lines
---
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.
This is broadly correct, just a few minor nits in case Sashiko has something to say and requires you to resubmit:
- ideally we should read the amount of pages from the mmu mem sel strap (128KB = 512 pages, 384KB = 1536 pages) but IIRC 4908 is always going to be strapped for 384KB
- the total ranges differ from the spec, which lists the defaults to 0x5C7 but the commit says 1479, probably another 409 specific difference
Signature · 1 line
Florian
Hi Florian,
Quoted 7 lines
Quoted 4 lines
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 forbcm4908_enet, among them earlier versions of most of its fixes now in net.Not sure if we need this paragraph in the commit message, it does and will respond to Sashiko I presume?
It is there so that nobody, Sashiko included, mistakes the numbers above for mainline results: each run needed the WAN port or the Wi-Fi, which only work with those out-of-tree changes. If there is a v2, I can move it below the --- line.
Quoted 3 lines
- ideally we should read the amount of pages from the mmu mem sel strap (128KB = 512 pages, 384KB = 1536 pages) but IIRC 4908 is always going to be strapped for 384KB
In the WAN runs on this board, queue 0 alone went up to 802 pages, more than the 512 of the 128KB setting.
Quoted 2 lines
- the total ranges differ from the spec, which lists the defaults to
0x5C7but the commit says 1479, probably another 409 specific difference
The commit message gives 1423-1527, the range over all eight queues of both pages. On this board, after boot, the total drop threshold on page 0x0B reads 1423 pages for queue 0 and 8 more for each queue after it, up to 1479 (0x5C7) for queue 7. Page 0x0D reads 1471 to 1527 the same way, so 0x5C7 is also the value of queue 1 there. The other fourteen values do differ from 0x5C7, and I cannot tell where that comes from. In any case, the total pause level of 1300 stays below all of them.
Thanks for the review.
Kordian