wifi: rtw88: sdio: faster and fairer TX for the 88xx chips
cover wifi: rtw88: sdio: faster and fairer TX for the 88xx chips
The RTL8822CS on a NanoPi R76S (RK3576, SDR104 at 198 MHz) sends at less than half the rate it receives at, and with traffic in both directions it hardly sends at all. These patches are about the 88xx chips (RTL8822BS, RTL8822CS, RTL8821CS); the 8051 chips keep their current paths.
1. keep the free page and AC output queue counts, as the RTL8723BS path does, and read the registers only when a transfer doesn't fit;
2. send up to 32 frames / 20 KiB of one access category per transfer;
3. stop the mac80211 queues when the driver's FIFO is deep, so the backlog stays in mac80211 (fq_codel) instead of an unbounded FIFO;
4. let the TX work have the host between RX reads while frames are waiting; the RX path otherwise takes most of the bus;
5. read HISR with RX0_REQ_LEN, and the three free page registers, with one transfer each.
R76S as AP, VHT80 1x1 (client 2x2, AX210), 2 m line of sight, iperf3 TCP between the client and a wired host on the AP's switch, Mbit/s (AP->client 30 s / client->AP 30 s / both directions at once 120 s), mean of 3 interleaved rounds:
down up bidir rtw-next 64 132 28 + 76 + 1-4 184 210 77 + 89 + 1-5 198 212 84 + 86 Realtek driver ~183 ~265 ~40 + 180 (FriendlyWrt, same board)
In the bidir runs, the share of 5 s intervals with the download below 40 Mbit/s went from 11-24 of 24 with rtw-next to 1-5 of 24 with the series.
The individual steps were measured in another set of runs, with the sender behind a path that reorders some TCP segments (which costs a little download throughput but doesn't change the ranking); RTT is ping AP->client during the download, median / 90th percentile:
down up bidir RTT under load rtw-next 89 164 23 + 119 34 / 91 ms + 1-2 189 220 37 + 167 22 / 51 ms + 1-3 181 214 30 + 176 10 / 29 ms + 1-4 194 198 79 + 91 11 / 25 ms + 1-5 190 202 73 + 100 13 / 47 ms
Patch 2 is the big step for one-way traffic, patch 3 halves the latency under load, and patch 4 is what makes both directions work at the same time (it costs some upload when that runs alone). Patch 5 is mainly about bus transfers; in a longer A/B (10 interleaved rounds, channel 149) it gave about 10 % more download than 1-4 (190 vs 171 Mbit/s), with up and bidir unchanged.
A soak with the full series, 30 120 s bidir transfers in a row, averaged 95 + 88 Mbit/s, the slowest download being 80 Mbit/s (10 of the 720 5 s intervals had the download below 40 Mbit/s). There were no kernel messages and the bus stayed at SDR104.
Known issue, not addressed here: when the client goes off-channel (for example for a background scan), the chip sometimes gives up on an MPDU of an A-MPDU session without sending a BAR, and keeps sending up to 64 frames past it. rtw88 reports every SDIO data frame as acked, so mac80211 doesn't know either and can't send a BAR. The client's reorder window then stalls until it is pushed past the hole, which costs a short throughput dip. With iwlwifi clients it turned into bursts of up to 63 lost frames per hole because of a reorder buffer bug there, for which I have sent fixes:
https://lore.kernel.org/linux-wireless/[email protected]/
I tried the hardware BAR settings (REG_BAR_MODE_CTRL thresholds, the BAR retry bits in the TX descriptor), a longer retry limit, MACID sleep for dozing clients, per-frame TX reports and a BAR sent by the driver after the client wakes up; none of them helped, and per-frame reports only came back for about one frame per A-MPDU. Ping-Ke, is there a way for the firmware to report which MPDU it dropped, or to send the BAR itself?
Tested on the RTL8822CS only. The RTL8822BS and RTL8821CS share the register layout and code paths; testing on them would be welcome.
Two series on the list touch the same code, and I'd like to make sure this one doesn't clash with them:
- Alastair D'Silva's "wifi: rtw88: sdio: Fix unhandled RX request interrupt storm" (v10) changes the RX interrupt handling that patches 4 and 5 touch. This series is based on rtw-next without it; I have a version rebased on top of it and will send that once it's applied.
https://lore.kernel.org/linux-wireless/[email protected]/
- Leonard Lausen's "wifi: rtw88: reduce RTL8822CS SDIO request overhead" (v2): his patch 1 (control frame filter) is independent of this series and applies on top of it. His patch 2 combines the free page register reads that patch 1 here replaces with cached counts, so only one of the two makes sense; Leonard, I'm happy to go with whatever you and Ping-Ke prefer.
https://lore.kernel.org/linux-wireless/[email protected]/
The bus speed itself needs 67a97316a31a ("mmc: core: sdio: skip CMD11 if signalling is already 1.8V") from mmc/next on this board; without it the card runs at 50 MHz and the gains are smaller.
The patches were generated with the help of an LLM; I have reviewed them (to the best of my ability), and tested them on actual hardware as described above.
David Härdeman (5):
wifi: rtw88: sdio: cache the free TX page counts of the 88xx chips
wifi: rtw88: sdio: aggregate TX frames of the 88xx chips
wifi: rtw88: sdio: limit the TX queue length of the 88xx chips
wifi: rtw88: sdio: let TX in while receiving on the 88xx chips
wifi: rtw88: sdio: read neighbouring registers of the 88xx chips at
once
drivers/net/wireless/realtek/rtw88/sdio.c | 574 +++++++++++++++++++--- drivers/net/wireless/realtek/rtw88/sdio.h | 13 + 2 files changed, 526 insertions(+), 61 deletions(-)
base-commit: 61a5eb87b2d9b4d5e353780b781cf691f39ba9e1
Signature · 1 line
2.47.3
PATCH 1/5 wifi: rtw88: sdio: cache the free TX page counts of the 88xx chips
Before every transfer, rtw_sdio_check_free_txpg() reads the three REG_SDIO_FREE_TXPG registers of the RTL8822BS, RTL8822CS and RTL8821CS to see whether the frame fits. That is three register reads per frame, more bus time than the transfer of a small frame takes, and the main reason why the RTL8822CS sends at only about a third of the rate it receives at.
The chip only ever frees pages, so counts read earlier and reduced by every transfer since then never exceed what is free. Keep the counts, reserve each transfer's pages from them, and read the registers again only when they say the frame does not fit, as the RTL8723BS path does and as Realtek's driver does for these chips. Pages are taken from the queue's dedicated pages first and then from the public ones, and the management queue, which goes to the extra FIFO on these chips, has its own count.
The same registers report the free entries of the AC output queue; track them too, one per frame of an AC queue, so that a later change can send several frames per transfer without overrunning it.
tx_credit_lock is held from the reservation until the transfer is done, so the counts are never read back while a transfer they were reduced for has not reached the chip yet. They are read again after start and stop, and after a failed transfer.
On a NanoPi R76S (RTL8822CS, SDR104) acting as an AP, TCP throughput to a client goes from about 87 to about 100 Mbit/s, and from the client from about 160 to about 185 Mbit/s.
--- drivers/net/wireless/realtek/rtw88/sdio.c | 201 ++++++++++++++++++---- drivers/net/wireless/realtek/rtw88/sdio.h | 3 + 2 files changed, 170 insertions(+), 34 deletions(-)
drivers/net/wireless/realtek/rtw88/sdio.c +167 -34
@@ -675,6 +675,135 @@ static atomic_t *rtw_sdio_8723bs_free_txpg(struct rtw_dev *rtwdev, u8 queue) } } +/* +* The other chips with a non-8051 MCU (RTL8822BS, RTL8822CS, RTL8821CS) report +* their free pages in three registers, one 12 bit count per FIFO, and the +* free entries of the AC output queue in the third. Reading them for every +* transfer costs three register reads, more bus time than the transfer of a +* small frame. The chip only frees pages and entries, so counts read earlier +* and reduced by every transfer since then never exceed what is really free: +* keep them and read the registers again only when they say a transfer does +* not fit. +*/ +static void rtw_sdio_88xx_sync_free_txpg (struct rtw_dev *rtwdev) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; +u32 free_txpg[3 ]; + +lockdep_assert_held (&rtwsdio->tx_credit_lock); + + free_txpg[0 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG ); + free_txpg[1 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +4 ); + free_txpg[2 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +8 ); + +atomic_set (&rtwsdio->free_pg_high, free_txpg[0 ] &0xfff ); +atomic_set (&rtwsdio->free_pg_normal, (free_txpg[0 ] >>16 ) &0xfff ); +atomic_set (&rtwsdio->free_pg_low, free_txpg[1 ] &0xfff ); +atomic_set (&rtwsdio->free_pg_pub, (free_txpg[1 ] >>16 ) &0xfff ); +atomic_set (&rtwsdio->free_pg_extra, free_txpg[2 ] &0xfff ); +atomic_set (&rtwsdio->tx_oqt_free, (free_txpg[2 ] >>16 ) &0xff ); + + rtwsdio->free_txpg_valid = true; +} + +static void rtw_sdio_88xx_invalidate_free_txpg (struct rtw_dev *rtwdev) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + +guard (mutex)(&rtwsdio->tx_credit_lock); + + rtwsdio->free_txpg_valid = false; +} + +static atomic_t *rtw_sdio_88xx_free_txpg (struct rtw_dev *rtwdev,u8 queue) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + +switch (queue) { +case RTW_TX_QUEUE_BCN : +case RTW_TX_QUEUE_H2C : +case RTW_TX_QUEUE_HI0 : +return &rtwsdio->free_pg_high; +case RTW_TX_QUEUE_VI : +case RTW_TX_QUEUE_VO : +return &rtwsdio->free_pg_normal; +case RTW_TX_QUEUE_BE : +case RTW_TX_QUEUE_BK : +return &rtwsdio->free_pg_low; +case RTW_TX_QUEUE_MGMT : +return &rtwsdio->free_pg_extra; +default : +return NULL ; + } +} + +static bool rtw_sdio_queue_is_ac (u8 queue) +{ +return queue <=RTW_TX_QUEUE_VO ; +} + +static bool rtw_sdio_88xx_txpg_fits (struct rtw_dev *rtwdev,atomic_t *dedicated, +u8 queue,unsigned int pages, +unsigned int frames) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; + +if (atomic_read (dedicated) +atomic_read (&rtwsdio->free_pg_pub) < pages) +return false; + +/* every frame of an AC queue takes an entry of the output queue */ +if (rtw_sdio_queue_is_ac (queue) && +atomic_read (&rtwsdio->tx_oqt_free) < frames) +return false; + +return true; +} + +/* +* Reserve the pages and output queue entries for a transfer of @frames frames +* needing @pages pages, from the queue's dedicated pages first and then from +* the public ones, as the chip charges them. The caller holds tx_credit_lock +* until the transfer is done, so that the counts are never read back from the +* chip while a transfer they were already reduced for has not reached it. +*/ +static int rtw_sdio_88xx_reserve_txpg (struct rtw_dev *rtwdev,u8 queue, +unsigned int pages,unsigned int frames) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; +atomic_t *dedicated; +unsigned int taken; + +lockdep_assert_held (&rtwsdio->tx_credit_lock); + + dedicated =rtw_sdio_88xx_free_txpg (rtwdev, queue); +if (!dedicated) { +rtw_warn (rtwdev,"Unknown mapping for queue %u\n" , queue); +return -EINVAL ; + } + +if (!rtwsdio->free_txpg_valid || + !rtw_sdio_88xx_txpg_fits (rtwdev, dedicated, queue, pages, frames)) +rtw_sdio_88xx_sync_free_txpg (rtwdev); + +if (!rtw_sdio_88xx_txpg_fits (rtwdev, dedicated, queue, pages, frames)) { +rtw_dbg (rtwdev,RTW_DBG_SDIO , +"Not enough free pages (%u needed, %u free) or output queue entries (%u needed, %u free) in queue %u\n" , + pages,atomic_read (dedicated) + +atomic_read (&rtwsdio->free_pg_pub), frames, +atomic_read (&rtwsdio->tx_oqt_free), queue); +return -EBUSY ; + } + + taken = min_t(unsigned int, pages, atomic_read(dedicated)); +atomic_sub (taken, dedicated); +atomic_sub (pages - taken, &rtwsdio->free_pg_pub); + +if (rtw_sdio_queue_is_ac (queue)) +atomic_sub (frames, &rtwsdio->tx_oqt_free); + +return 0 ; +} +static int rtw_sdio_check_free_txpg (struct rtw_dev *rtwdev,u8 queue,size_t count) {
@@ -727,40 +856,8 @@ static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue,/* add the pages from the public queue */ pages_free += (free_txpg >>24 ) &0xff ; }else { -u32 free_txpg[3 ]; - - free_txpg[0 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG ); - free_txpg[1 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +4 ); - free_txpg[2 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +8 ); - -switch (queue) { -case RTW_TX_QUEUE_BCN : -case RTW_TX_QUEUE_H2C : -case RTW_TX_QUEUE_HI0 : -/* high */ - pages_free = free_txpg[0 ] &0xfff ; -break ; -case RTW_TX_QUEUE_VI : -case RTW_TX_QUEUE_VO : -/* normal */ - pages_free = (free_txpg[0 ] >>16 ) &0xfff ; -break ; -case RTW_TX_QUEUE_BE : -case RTW_TX_QUEUE_BK : -/* low */ - pages_free = free_txpg[1 ] &0xfff ; -break ; -case RTW_TX_QUEUE_MGMT : -/* extra */ - pages_free = free_txpg[2 ] &0xfff ; -break ; -default : -rtw_warn (rtwdev,"Unknown mapping for queue %u\n" , queue); -return -EINVAL ; - } - -/* add the pages from the public queue */ - pages_free += (free_txpg[1 ] >>16 ) &0xfff ; +/* the other chips use rtw_sdio_88xx_reserve_txpg() */ +return -EINVAL ; } pages_needed =DIV_ROUND_UP (count, rtwdev->chip->page_size);
@@ -889,6 +986,32 @@ static int rtw_sdio_write_port_8723bs(struct rtw_dev *rtwdev,return 0 ; } +static int rtw_sdio_write_port_88xx (struct rtw_dev *rtwdev, +struct sk_buff *skb, +enum rtw_tx_queue_type queue,u32 txaddr, +size_t write_size) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; +unsigned int pages; +int ret; + +/* the chip charges pages by frame length, not by the padded transfer */ + pages =DIV_ROUND_UP (skb->len, rtwdev->chip->page_size); + +guard (mutex)(&rtwsdio->tx_credit_lock); + + ret =rtw_sdio_88xx_reserve_txpg (rtwdev, queue, pages,1 ); +if (ret) +return ret; + + ret =rtw_sdio_write_to_port (rtwdev, skb, queue, txaddr, write_size); +if (ret) +/* the pages may or may not have been used, read them again */ + rtwsdio->free_txpg_valid = false; + +return ret; +} + static int rtw_sdio_write_port_generic(struct rtw_dev *rtwdev, struct sk_buff *skb, enum rtw_tx_queue_type queue, u32 txaddr,
@@ -933,6 +1056,10 @@ static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb,return rtw_sdio_write_port_8723bs (rtwdev, skb, queue, txaddr, write_size); +if (!rtw_chip_wcpu_8051 (rtwdev)) +return rtw_sdio_write_port_88xx (rtwdev, skb, queue, txaddr, + write_size); +return rtw_sdio_write_port_generic (rtwdev, skb, queue, txaddr, write_size); }
@@ -1067,6 +1194,9 @@ static int rtw_sdio_start(struct rtw_dev *rtwdev)return ret; } +if (!rtw_chip_wcpu_8051 (rtwdev)) +rtw_sdio_88xx_invalidate_free_txpg (rtwdev); +rtw_sdio_enable_rx_aggregation (rtwdev);if (rtw_is_8723bs (rtwdev)) {
@@ -1083,6 +1213,9 @@ static int rtw_sdio_start(struct rtw_dev *rtwdev)static void rtw_sdio_stop (struct rtw_dev *rtwdev) {rtw_sdio_disable_interrupt (rtwdev); + +if (!rtw_chip_wcpu_8051 (rtwdev)) +rtw_sdio_88xx_invalidate_free_txpg (rtwdev); }static void rtw_sdio_deep_ps_enter (struct rtw_dev *rtwdev)
drivers/net/wireless/realtek/rtw88/sdio.h +3 -0
@@ -178,7 +178,10 @@ struct rtw_sdio {atomic_t free_pg_normal;atomic_t free_pg_low;atomic_t free_pg_pub; +atomic_t free_pg_extra;atomic_t tx_oqt_free; +/* the non-8051 chips' counters hold what the chip last reported */ +bool free_txpg_valid;/* one writer at a time between the credit check and the accounting */ struct mutex tx_credit_lock; };
Signature · 1 line
2.47.3
Re: [PATCH rtw-next 1/5] wifi: rtw88: sdio: cache the free TX page counts of the 88xx chips
Hi David,
Thanks for picking this up. One comment below.
Quoted 3 lines · David Härdeman
drivers/net/wireless/realtek/rtw88/sdio.c +3
-0+ free_txpg[0 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG ); + free_txpg[1 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +4 ); + free_txpg[2 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +8 );
[ ... ]
Quoted 1 line
+
rtwsdio->free_txpg_valid= true;
As far as I can see, a failed read can leave bogus credits cached here. While the chip is powered on, sdio_readl() returns 0xffffffff on an I/O error, and rtw_sdio_read32() only logs the error. That becomes 4095 pages in each affected page count.
The first frame can still fit the real page pool and be sent successfully. The cache then stays valid, so the next frame can be admitted using credits from the failed read even after the real pages have been consumed. Previously, the next transfer would read the registers again.
Could the sync return an error and leave the cache invalid unless all three reads succeed? The individual reads used as a fallback in patch 5 would need to preserve their errors too.
Best regards,
Luka Gejak
Re: [PATCH rtw-next 1/5] wifi: rtw88: sdio: cache the free TX page counts of the 88xx chips
Quoted 22 lines · Luka Gejak
Quoted 3 lines · David Härdeman
drivers/net/wireless/realtek/rtw88/sdio.c +3
-0+ free_txpg[0 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG ); + free_txpg[1 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +4 ); + free_txpg[2 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +8 );[ ... ]
Quoted 1 line
+
rtwsdio->free_txpg_valid= true;As far as I can see, a failed read can leave bogus credits cached here. While the chip is powered on,
sdio_readl()returns0xffffffffon an I/O error, andrtw_sdio_read32()only logs the error. That becomes 4095 pages in each affected page count.The first frame can still fit the real page pool and be sent successfully. The cache then stays valid, so the next frame can be admitted using credits from the failed read even after the real pages have been consumed. Previously, the next transfer would read the registers again.
Quoted 3 lines
Could the sync return an error and leave the cache invalid unless all three reads succeed? The individual reads used as a fallback in patch 5 would need to preserve their errors too.
Yes, I assume Leonard's patches will go in first, and there's already a read helper there, so when I rebase the patch set, this will be fixed.
Signature · 1 line
David Härdeman
PATCH 2/5 wifi: rtw88: sdio: aggregate TX frames of the 88xx chips
In reply to David HärdemanThe 88xx chips accept several frames in one transfer: the first TX descriptor carries the number of frames in DMA_TXAGG_NUM and every frame starts 8 byte aligned, as for USB TX aggregation. Realtek's driver sends up to about 32 KiB per transfer this way. rtw88 sends one frame per transfer, so a full sized frame costs a CMD53 and its interrupts, and the RTL8822CS cannot get near its PHY rate.
When an AC queue holds more than one frame, copy up to 32 frames or 20 KiB of the same access category into a buffer and send them with one transfer. The chip rejects aggregates that mix access categories; an AC queue only holds one, but the queue select of each frame is checked to be sure. Every frame is charged its own pages and output queue entry, so the aggregate is shrunk until it fits what is free. A frame too big for the buffer is sent on its own, as before.
The RTL8723BS and the other chips with an 8051 MCU keep sending one frame per transfer.
On a NanoPi R76S (RTL8822CS, SDR104) acting as an AP, TCP throughput to a client goes from about 100 to about 220 Mbit/s, and from the client from about 185 to about 245 Mbit/s. Realtek's driver reaches about 183 and 265 Mbit/s on the same setup.
--- drivers/net/wireless/realtek/rtw88/sdio.c | 181 +++++++++++++++++++++- drivers/net/wireless/realtek/rtw88/sdio.h | 6 + 2 files changed, 180 insertions(+), 7 deletions(-)
drivers/net/wireless/realtek/rtw88/sdio.c +174 -7
@@ -919,16 +919,16 @@ static void rtw_sdio_8723bs_consume_txpg(struct rtw_dev *rtwdev, u8 queue,atomic_set (&rtwsdio->free_pg_pub,0 ); } -static int rtw_sdio_write_to_port (struct rtw_dev *rtwdev,struct sk_buff *skb, -enum rtw_tx_queue_type queue,u32 txaddr, -size_t write_size) +static int rtw_sdio_write_buf_to_port (struct rtw_dev *rtwdev,void *buf, +enum rtw_tx_queue_type queue,u32 txaddr, +size_t write_size) {struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;bool bus_claim;int ret; -if (!IS_ALIGNED ((unsigned long )skb->data,RTW_SDIO_DATA_PTR_ALIGN )) -rtw_warn (rtwdev,"Got unaligned SKB in %s() for queue %u\n" , +if (!IS_ALIGNED ((unsigned long )buf,RTW_SDIO_DATA_PTR_ALIGN )) +rtw_warn (rtwdev,"Got unaligned buffer in %s() for queue %u\n" , __func__, queue); bus_claim =rtw_sdio_bus_claim_needed (rtwsdio);
@@ -936,8 +936,7 @@ static int rtw_sdio_write_to_port(struct rtw_dev *rtwdev, struct sk_buff *skb,if (bus_claim)sdio_claim_host (rtwsdio->sdio_func); - ret =sdio_memcpy_toio (rtwsdio->sdio_func, txaddr, skb->data, - write_size); + ret =sdio_memcpy_toio (rtwsdio->sdio_func, txaddr, buf, write_size);if (bus_claim)sdio_release_host (rtwsdio->sdio_func);
@@ -950,6 +949,14 @@ static int rtw_sdio_write_to_port(struct rtw_dev *rtwdev, struct sk_buff *skb,return ret; } +static int rtw_sdio_write_to_port (struct rtw_dev *rtwdev,struct sk_buff *skb, +enum rtw_tx_queue_type queue,u32 txaddr, +size_t write_size) +{ +return rtw_sdio_write_buf_to_port (rtwdev, skb->data, queue, txaddr, + write_size); +} + static int rtw_sdio_write_port_8723bs(struct rtw_dev *rtwdev, struct sk_buff *skb, enum rtw_tx_queue_type queue, u32 txaddr,
@@ -1760,6 +1767,148 @@ static void rtw_sdio_indicate_tx_status(struct rtw_dev *rtwdev,ieee80211_tx_status_irqsafe (hw, skb); } +/* the access category of a data frame's TX descriptor queue select (TID) */ +static u8 rtw_sdio_skb_qsel_ac (struct sk_buff *skb) +{ +static const u8 tid_to_ac[] = { +IEEE80211_AC_BE ,IEEE80211_AC_BK ,IEEE80211_AC_BK , +IEEE80211_AC_BE ,IEEE80211_AC_VI ,IEEE80211_AC_VI , +IEEE80211_AC_VO ,IEEE80211_AC_VO , + }; +struct rtw_tx_desc *tx_desc = (struct rtw_tx_desc *)skb->data; +u8 qsel =le32_get_bits (tx_desc->w1,RTW_TX_DESC_W1_QSEL ); + +return qsel <ARRAY_SIZE (tid_to_ac) ? tid_to_ac[qsel] :U8_MAX ; +} + +static unsigned int rtw_sdio_agg_pages (struct rtw_dev *rtwdev, +struct sk_buff_head *agg) +{ +unsigned int pages =0 ; +struct sk_buff *skb; + +/* the chip charges every frame of an aggregate its own pages */ +skb_queue_walk (agg, skb) + pages += DIV_ROUND_UP(skb->len, rtwdev->chip->page_size); + +return pages; +} + +/* +* Send several frames of an AC queue with one transfer, for the 88xx chips: +* each frame, TX descriptor and payload, starts 8 byte aligned and the first +* descriptor carries the number of frames, as for USB TX aggregation. This +* saves a transfer, and its interrupts, per frame. The chip takes the frames +* of one access category only, which an AC queue holds anyway, but check the +* queue select of every frame to be sure. +* +* Returns 0 when frames were written, 1 when the queue was empty, -E2BIG when +* the first frame does not fit the buffer and another negative errno when +* the write failed. In both error cases the frames are back in the queue. +*/ +static int rtw_sdio_process_tx_agg (struct rtw_dev *rtwdev, +enum rtw_tx_queue_type queue) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; +struct sk_buff_head *list = &rtwsdio->tx_queue[queue]; +struct rtw_tx_pkt_info pkt_info = {}; +u8 *buf = rtwsdio->tx_agg_buf; +struct rtw_tx_desc *tx_desc; +size_t len =0 , write_size; +struct sk_buff_head agg; +unsigned int num =0 ; +struct sk_buff *skb; +u8 ac =U8_MAX ; +u32 txaddr; +int ret; + +__skb_queue_head_init (&agg); + +while (num <RTW_SDIO_TX_AGG_MAX_NUM ) { + skb =skb_dequeue (list); +if (!skb) +break ; + +if (!num) { +if (skb->len >RTW_SDIO_TX_AGG_MAX_SIZE ) { +skb_queue_head (list, skb); +return -E2BIG ; + } + ac =rtw_sdio_skb_qsel_ac (skb); + }else if (ALIGN (len,8 ) + skb->len >RTW_SDIO_TX_AGG_MAX_SIZE || +rtw_sdio_skb_qsel_ac (skb) != ac) { +skb_queue_head (list, skb); +break ; + } + + len = (num ?ALIGN (len,8 ) :0 ) + skb->len; +__skb_queue_tail (&agg, skb); + num++; + } + +if (!num) +return 1 ; + +mutex_lock (&rtwsdio->tx_credit_lock); + +/* shrink the aggregate until it fits the free pages and entries */ +for (;;) { + ret =rtw_sdio_88xx_reserve_txpg (rtwdev, queue, +rtw_sdio_agg_pages (rtwdev, &agg), + num); +if (!ret) +break ; +if (ret != -EBUSY || num ==1 ) + goto err_requeue; + +skb_queue_head (list,__skb_dequeue_tail (&agg)); + num--; + } + + len =0 ; + skb_queue_walk(&agg, skb) { + len =ALIGN (len,8 ); +memcpy (buf + len, skb->data, skb->len); + len += skb->len; + } + +if (num >1 ) { + tx_desc = (struct rtw_tx_desc *)buf; +le32p_replace_bits (&tx_desc->w7, num, +RTW_TX_DESC_W7_DMA_TXAGG_NUM ); + pkt_info.pkt_offset =le32_get_bits (tx_desc->w1, +RTW_TX_DESC_W1_PKT_OFFSET ); +rtw_tx_fill_txdesc_checksum (rtwdev, &pkt_info, buf); + } + + txaddr =rtw_sdio_get_tx_addr (rtwdev, len, queue); + write_size =sdio_align_size (rtwsdio->sdio_func, len); +memset (buf + len,0 , write_size - len); + + ret =rtw_sdio_write_buf_to_port (rtwdev, buf, queue, txaddr, + write_size); +if (ret) { +/* the pages may or may not have been used, read them again */ + rtwsdio->free_txpg_valid = false; + goto err_requeue; + } + +mutex_unlock (&rtwsdio->tx_credit_lock); + +while ((skb =__skb_dequeue (&agg))) +rtw_sdio_indicate_tx_status (rtwdev, skb); + +return 0 ; + +err_requeue: +mutex_unlock (&rtwsdio->tx_credit_lock); + +while ((skb =__skb_dequeue_tail (&agg))) +skb_queue_head (list, skb); + +return ret; +} +/* * Send one frame from @queue. Returns 0 when a frame was written, 1 when the * queue was empty and a negative errno when the write failed, in which case
@@ -1773,6 +1922,13 @@ static int rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev,u16 q_map;int ret; +if (rtwsdio->tx_agg_buf &&rtw_sdio_queue_is_ac (queue) && +skb_queue_len (&rtwsdio->tx_queue[queue]) >1 ) { + ret =rtw_sdio_process_tx_agg (rtwdev, queue); +if (ret != -E2BIG ) +return ret; + } + skb =skb_dequeue (&rtwsdio->tx_queue[queue]);if (!skb)return 1 ;
@@ -1878,6 +2034,15 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)mutex_init (&rtwsdio->tx_credit_lock); +/* +* TX aggregation relies on the free page and output queue counts +* that only the non-8051 chips keep; without the buffer, frames are +* sent one by one. +*/ +if (!rtw_chip_wcpu_8051 (rtwdev)) + rtwsdio->tx_agg_buf =kmalloc (RTW_SDIO_TX_AGG_MAX_SIZE + +RTW_SDIO_BLOCK_SIZE ,GFP_KERNEL ); +for (i =0 ; i <RTK_MAX_TX_QUEUE_NUM ; i++) {skb_queue_head_init (&rtwsdio->tx_queue[i]); rtwsdio->tx_queue_stopped[i] = false;
@@ -1892,6 +2057,7 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)return 0 ; err_destroy_wq: +kfree (rtwsdio->tx_agg_buf);mutex_destroy (&rtwsdio->tx_credit_lock);destroy_workqueue (rtwsdio->txwq);return -ENOMEM ;
@@ -1909,6 +2075,7 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev)for (i =0 ; i <RTK_MAX_TX_QUEUE_NUM ; i++)ieee80211_purge_tx_queue (rtwdev->hw, &rtwsdio->tx_queue[i]); +kfree (rtwsdio->tx_agg_buf);mutex_destroy (&rtwsdio->tx_credit_lock); }
drivers/net/wireless/realtek/rtw88/sdio.h +6 -0
@@ -148,6 +148,10 @@#define RTW_SDIO_DATA_PTR_ALIGN 8 +/* TX aggregation of the 88xx chips: at most this much per transfer */ +#define RTW_SDIO_TX_AGG_MAX_SIZE (20 * 1024) +#define RTW_SDIO_TX_AGG_MAX_NUM 32 +struct sdio_func ;struct sdio_device_id ;
@@ -182,6 +186,8 @@ struct rtw_sdio {atomic_t tx_oqt_free;/* the non-8051 chips' counters hold what the chip last reported */ bool free_txpg_valid; +/* TX aggregation buffer of the non-8051 chips, under tx_credit_lock */ +u8 *tx_agg_buf;/* one writer at a time between the credit check and the accounting */ struct mutex tx_credit_lock; };
Signature · 1 line
2.47.3
PATCH 3/5 wifi: rtw88: sdio: limit the TX queue length of the 88xx chips
In reply to David HärdemanThe TX path pulls every frame mac80211 has queued into its own per-queue FIFO, and only the RTL8723BS stops the mac80211 queues when that FIFO grows. On the 88xx chips the FIFO is unbounded: the backlog builds up there instead of in mac80211, where fq_codel would keep it short and schedule it fairly between flows. On a NanoPi R76S (RTL8822CS) acting as an AP, the round trip time to a client goes up to more than a second during a single TCP download.
Stop the mac80211 queue of an access category above 64 frames in its FIFO and wake it again below 32, as is done for the RTL8723BS with lower watermarks. The 88xx chips send up to 32 frames per transfer and need the deeper FIFO to keep doing that. Also wake the queue after an aggregate is sent, which the single frame path already does.
A stopped queue is handed no further frames, so nothing would kick the TX work again if the chip stayed full for its whole retry loop. Requeue the work after a jiffy in that case, as the RTL8723BS path does.
With this, the round trip time during a download stays at about 12-30 ms on average (100-570 ms at most, mostly from the client), and the download throughput is unchanged at about 190-215 Mbit/s.
--- drivers/net/wireless/realtek/rtw88/sdio.c | 77 +++++++++++++++++++---- 1 file changed, 64 insertions(+), 13 deletions(-)
drivers/net/wireless/realtek/rtw88/sdio.c +64 -13
@@ -22,9 +22,16 @@#define RTW_SDIO_INDIRECT_RW_RETRIES 50#define RTW_SDIO_OQT_TIMEOUT_MS 1000 -/* Bounds the queueing latency of the unbounded per-AC software FIFO. */ +/* +* Bound the queueing latency of the per-AC software FIFO, so that the +* backlog stays in mac80211, where it is scheduled fairly between flows and +* stations. The 88xx chips send up to RTW_SDIO_TX_AGG_MAX_NUM frames per +* transfer and need a deeper FIFO to keep doing that. +*/ #define RTW_SDIO_TX_FIFO_HIWATER 16#define RTW_SDIO_TX_FIFO_LOWATER 8 +#define RTW_SDIO_88XX_TX_FIFO_HIWATER 64 +#define RTW_SDIO_88XX_TX_FIFO_LOWATER 32#define RTW_SDIO_TX_RETRY_DELAY msecs_to_jiffies(1)static bool rtw_sdio_is_bus_addr (u32 addr)
@@ -1391,19 +1398,43 @@ static int rtw_sdio_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)return rtw_sdio_write_data (rtwdev, &pkt_info, skb,RTW_TX_QUEUE_H2C ); } +static bool rtw_sdio_tx_queue_limited (struct rtw_dev *rtwdev, +enum rtw_tx_queue_type queue) +{ +if (queue >=RTW_TX_QUEUE_BCN ) +return false; + +return rtw_is_8723bs (rtwdev) || !rtw_chip_wcpu_8051 (rtwdev); +} + +static u32 rtw_sdio_tx_fifo_hiwater (struct rtw_dev *rtwdev) +{ +if (rtw_chip_wcpu_8051 (rtwdev)) +return RTW_SDIO_TX_FIFO_HIWATER ; + +return RTW_SDIO_88XX_TX_FIFO_HIWATER ; +} + +static u32 rtw_sdio_tx_fifo_lowater (struct rtw_dev *rtwdev) +{ +if (rtw_chip_wcpu_8051 (rtwdev)) +return RTW_SDIO_TX_FIFO_LOWATER ; + +return RTW_SDIO_88XX_TX_FIFO_LOWATER ; +} +/* * Both this and the wake below hold the TX queue lock across the length check * and the flag update, so a queue is only ever stopped while it really is * above the watermark, and the drain path always sees the flag the producer * set. */ -static void rtw_sdio_8723bs_stop_tx_queue (struct rtw_dev *rtwdev, -enum rtw_tx_queue_type queue, -u16 q_map) +static void rtw_sdio_stop_tx_queue (struct rtw_dev *rtwdev, +enum rtw_tx_queue_type queue,u16 q_map) {struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; -if (!rtw_is_8723bs (rtwdev) || queue >=RTW_TX_QUEUE_BCN ) +if (!rtw_sdio_tx_queue_limited (rtwdev, queue))return ;guard (spinlock_irqsave)(&rtwsdio->tx_queue[queue].lock);
@@ -1411,20 +1442,20 @@ static void rtw_sdio_8723bs_stop_tx_queue(struct rtw_dev *rtwdev,if (rtwsdio->tx_queue_stopped[queue])return ; -if (skb_queue_len (&rtwsdio->tx_queue[queue]) <RTW_SDIO_TX_FIFO_HIWATER ) +if (skb_queue_len (&rtwsdio->tx_queue[queue]) < +rtw_sdio_tx_fifo_hiwater (rtwdev))return ; rtwsdio->tx_queue_stopped[queue] = true;ieee80211_stop_queue (rtwdev->hw, q_map); } -static void rtw_sdio_8723bs_wake_tx_queue (struct rtw_dev *rtwdev, -enum rtw_tx_queue_type queue, -u16 q_map) +static void rtw_sdio_wake_tx_queue (struct rtw_dev *rtwdev, +enum rtw_tx_queue_type queue,u16 q_map) {struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; -if (!rtw_is_8723bs (rtwdev) || queue >=RTW_TX_QUEUE_BCN ) +if (!rtw_sdio_tx_queue_limited (rtwdev, queue))return ;guard (spinlock_irqsave)(&rtwsdio->tx_queue[queue].lock);
@@ -1432,7 +1463,8 @@ static void rtw_sdio_8723bs_wake_tx_queue(struct rtw_dev *rtwdev,if (!rtwsdio->tx_queue_stopped[queue])return ; -if (skb_queue_len (&rtwsdio->tx_queue[queue]) >RTW_SDIO_TX_FIFO_LOWATER ) +if (skb_queue_len (&rtwsdio->tx_queue[queue]) > +rtw_sdio_tx_fifo_lowater (rtwdev))return ; rtwsdio->tx_queue_stopped[queue] = false;
@@ -1456,7 +1488,7 @@ static int rtw_sdio_tx_write(struct rtw_dev *rtwdev,/* The TX worker may already have freed the skb, so do not touch it. */ skb_queue_tail (&rtwsdio->tx_queue[queue], skb); -rtw_sdio_8723bs_stop_tx_queue (rtwdev, queue, q_map); +rtw_sdio_stop_tx_queue (rtwdev, queue, q_map);return 0 ; }
@@ -1820,6 +1852,7 @@ static int rtw_sdio_process_tx_agg(struct rtw_dev *rtwdev,struct sk_buff *skb;u8 ac =U8_MAX ;u32 txaddr; +u16 q_map;int ret;__skb_queue_head_init (&agg);
@@ -1895,9 +1928,14 @@ static int rtw_sdio_process_tx_agg(struct rtw_dev *rtwdev,mutex_unlock (&rtwsdio->tx_credit_lock); +/* all frames are of the same AC, and the skbs are consumed below */ + q_map =skb_get_queue_mapping (skb_peek (&agg)); +while ((skb =__skb_dequeue (&agg)))rtw_sdio_indicate_tx_status (rtwdev, skb); +rtw_sdio_wake_tx_queue (rtwdev, queue, q_map); +return 0 ; err_requeue:
@@ -1944,7 +1982,7 @@ static int rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev,rtw_sdio_indicate_tx_status (rtwdev, skb); -rtw_sdio_8723bs_wake_tx_queue (rtwdev, queue, q_map); +rtw_sdio_wake_tx_queue (rtwdev, queue, q_map);return 0 ; }
@@ -1990,6 +2028,7 @@ static void rtw_sdio_tx_handler(struct work_struct *work)struct rtw_sdio *rtwsdio;struct rtw_dev *rtwdev;int limit, queue, ret; +bool resched = false; rtwdev = work_data->rtwdev; rtwsdio = (struct rtw_sdio *)rtwdev->priv;
@@ -2010,7 +2049,19 @@ static void rtw_sdio_tx_handler(struct work_struct *work)if (skb_queue_empty (&rtwsdio->tx_queue[queue]))break ; } + +/* +* A stopped queue is handed no further frames, so nothing +* else would kick this work item if the chip stayed full for +* the whole loop. +*/ +if (ret == -EBUSY && !rtw_chip_wcpu_8051 (rtwdev)) + resched = true; } + +if (resched) +queue_delayed_work (rtwsdio->txwq, &work_data->work, +RTW_SDIO_TX_RETRY_DELAY ); } static void rtw_sdio_free_irq(struct rtw_dev *rtwdev,
Signature · 1 line
2.47.3
Re: [PATCH rtw-next 3/5] wifi: rtw88: sdio: limit the TX queue length of the 88xx chips
Hi David,
drivers/net/wireless/realtek/rtw88/sdio.c static void rtw_sdio_tx_handler(struct work_struct *work) · line 2059
Quoted 2 lines · David Härdeman
drivers/net/wireless/realtek/rtw88/sdio.c +2
-0+if (ret == -EBUSY && !rtw_chip_wcpu_8051 (rtwdev)) + resched = true;
I think -ENOMEM needs a retry here too. mmc_io_rw_extended() allocates a scatterlist when a transfer needs more than one segment. For example, dw_mmc with IDMAC sets max_seg_size to 4096, so an aggregate larger than that can fail this allocation and return -ENOMEM.
The aggregate is put back in the queue on error. If the retry loop keeps failing while the queue is stopped, no further attempt is scheduled. Fresh TX callbacks can kick the worker again, including for the same AC, but if no more arrive, recovering memory alone leaves the queued frames stalled. The single frame fallback can also return -ENOMEM from __skb_pad().
Could this handle -ENOMEM as the RTL8723BS retry helper already does?
[ ... ]
drivers/net/wireless/realtek/rtw88/sdio.c static void rtw_sdio_tx_handler(struct work_struct *work) · line 2064
Quoted 3 lines
drivers/net/wireless/realtek/rtw88/sdio.c +3
-0+if (resched) +queue_delayed_work (rtwsdio->txwq, &work_data->work, +RTW_SDIO_TX_RETRY_DELAY );
So if I read it right, this also needs the work to be cancelled when the SDIO interface stops. The power off path is:
rtw_power_off()
rtw_hci_stop()
rtw_sdio_stop()
rtw_mac_power_off()rtw_sdio_stop() only disables interrupts and invalidates the credits. The cancellation is in rtw_sdio_deinit_tx(), which closing the interface does not call. The flush callback does not drain the SDIO software queues either, since the SDIO operations have no flush_queues callback.
A pending retry can therefore run after power off and keep rearming while credits are unavailable. The RTL8723BS retry helper seems to have the same lifetime gap already, so maybe the shared stop path is the right place to fix this before extending the retries to the other chips?
Best regards,
Luka Gejak
Re: [PATCH rtw-next 3/5] wifi: rtw88: sdio: limit the TX queue length of the 88xx chips
Quoted 10 lines · Luka Gejak
drivers/net/wireless/realtek/rtw88/sdio.c static void rtw_sdio_tx_handler(struct work_struct *work) · line 2059
Quoted 2 lines · David Härdeman
drivers/net/wireless/realtek/rtw88/sdio.c +2
-0+if (ret == -EBUSY && !rtw_chip_wcpu_8051 (rtwdev)) + resched = true;I think
-ENOMEMneeds a retry here too.mmc_io_rw_extended()allocates a scatterlist when a transfer needs more than one segment. For example,dw_mmcwith IDMAC setsmax_seg_sizeto 4096, so an aggregate larger than that can fail this allocation and return-ENOMEM.
You're right, I'll fix that in v2.
Quoted 17 lines
drivers/net/wireless/realtek/rtw88/sdio.c static void rtw_sdio_tx_handler(struct work_struct *work) · line 2064
Quoted 3 lines
drivers/net/wireless/realtek/rtw88/sdio.c +3
-0+if (resched) +queue_delayed_work (rtwsdio->txwq, &work_data->work, +RTW_SDIO_TX_RETRY_DELAY );So if I read it right, this also needs the work to be cancelled when the SDIO interface stops. The power off path is:
rtw_power_off() rtw_hci_stop() rtw_sdio_stop() rtw_mac_power_off()
rtw_sdio_stop()only disables interrupts and invalidates the credits. The cancellation is inrtw_sdio_deinit_tx(), which closing the interface does not call. The flush callback does not drain the SDIO software queues either, since the SDIO operations have noflush_queuescallback.
Quoted 4 lines
A pending retry can therefore run after power off and keep rearming while credits are unavailable. The RTL8723BS retry helper seems to have the same lifetime gap already, so maybe the shared stop path is the right place to fix this before extending the retries to the other chips?
Good catch, and I think this is fixed by Alastair's series, which I'll base the v2 on (+ Leonard's series).
Signature · 1 line
David Härdeman
PATCH 4/5 wifi: rtw88: sdio: let TX in while receiving on the 88xx chips
In reply to David HärdemanThe interrupt handler reads RX data for up to 64 KiB per interrupt while it holds the host, and the TX work waits for the host meanwhile. At SDR104 speeds an RTL8822CS spends most of the bus time on the per transfer overhead, so when a client sends at full rate, the RX path takes about 80% of the bus and leaves too little for TX. On a NanoPi R76S acting as an AP, with TCP traffic in both directions, the AP sends at only 20-35 Mbit/s while it receives at 165-220 Mbit/s.
When frames are waiting to be sent, stop reading after 8 KiB, about one RX aggregate, so the TX work gets the host between reads; the handler runs again for the rest. Without TX frames waiting, it still reads up to 64 KiB. The 8051 chips keep their behaviour.
With traffic in both directions, the R76S now sends at 70-85 Mbit/s while receiving at 100-120 Mbit/s, steadily over each run. The sum is somewhat lower, as sending costs more bus time than receiving, and one-way throughput doesn't change. Realtek's driver shows the same imbalance as before (about 40 + 180 Mbit/s on the same setup).
--- drivers/net/wireless/realtek/rtw88/sdio.c | 39 ++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/sdio.c +38 -1
@@ -34,6 +34,14 @@#define RTW_SDIO_88XX_TX_FIFO_LOWATER 32#define RTW_SDIO_TX_RETRY_DELAY msecs_to_jiffies(1) +/* +* The interrupt handler holds the host while it reads RX data. Bound how much +* it reads per interrupt, and with frames waiting to be sent, let the TX path +* have the host after a smaller amount. +*/ +#define RTW_SDIO_RX_BUDGET SZ_64K +#define RTW_SDIO_RX_BUDGET_TX_PENDING SZ_8K +static bool rtw_sdio_is_bus_addr (u32 addr) {return !!(addr &RTW_SDIO_BUS_MSK );
@@ -1597,6 +1605,34 @@ static void rtw_sdio_rxfifo_recv(struct rtw_dev *rtwdev, u32 rx_len) } } +static bool rtw_sdio_tx_pending (struct rtw_dev *rtwdev) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; +int queue; + +for (queue =0 ; queue <=RTW_TX_QUEUE_VO ; queue++) +if (!skb_queue_empty (&rtwsdio->tx_queue[queue])) +return true; + +return false; +} + +static bool rtw_sdio_rx_budget_left (struct rtw_dev *rtwdev,u32 rx_bytes) +{ +if (rx_bytes >=RTW_SDIO_RX_BUDGET ) +return false; + +/* +* The 8051 chips send one frame per transfer and are not limited by +* the bus in the same way, keep their behaviour. +*/ +if (rtw_chip_wcpu_8051 (rtwdev)) +return true; + +return rx_bytes <RTW_SDIO_RX_BUDGET_TX_PENDING || + !rtw_sdio_tx_pending (rtwdev); +} +static void rtw_sdio_rx_isr (struct rtw_dev *rtwdev) {u32 rx_len, hisr, total_rx_bytes =0 ;
@@ -1631,7 +1667,8 @@ static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev)*/ hisr =REG_SDIO_HISR_RX_REQUEST ; } - }while (total_rx_bytes <SZ_64K && hisr ®_SDIO_HISR_RX_REQUEST ); + }while (rtw_sdio_rx_budget_left (rtwdev, total_rx_bytes) && + hisr ®_SDIO_HISR_RX_REQUEST ); }static void rtw_sdio_handle_interrupt (struct sdio_func *sdio_func)
Signature · 1 line
2.47.3
PATCH 5/5 wifi: rtw88: sdio: read neighbouring registers of the 88xx chips at once
In reply to David HärdemanEvery register access costs a full SDIO command, about 40 us on a NanoPi R76S (RTL8822CS, SDR104), no matter how many bytes it moves. The interrupt handler reads HISR and then RX0_REQ_LEN, which follows it, and a free page sync reads the three REG_SDIO_FREE_TXPG words one by one.
Read HISR together with RX0_REQ_LEN, and the three free page words, with one transfer each, as Realtek's driver does. As in rtw_sdio_readl(), this is only done while the chip is powered on; before that, and if the small DMA-safe buffers this needs could not be allocated, the registers are read one by one as before.
On the R76S acting as an AP, TCP throughput to a client goes from about 170 to about 190 Mbit/s, the other directions are unchanged.
--- drivers/net/wireless/realtek/rtw88/sdio.c | 84 ++++++++++++++++++++--- drivers/net/wireless/realtek/rtw88/sdio.h | 4 ++ 2 files changed, 78 insertions(+), 10 deletions(-)
drivers/net/wireless/realtek/rtw88/sdio.c +74 -10
@@ -700,16 +700,59 @@ static atomic_t *rtw_sdio_8723bs_free_txpg(struct rtw_dev *rtwdev, u8 queue)* keep them and read the registers again only when they say a transfer does * not fit. */ +/* +* Read consecutive SDIO local registers with one transfer instead of one per +* register. buf must be DMA-safe. Like rtw_sdio_readl(), this only uses CMD53 +* while the chip is powered on; otherwise it fails with -EAGAIN and the caller +* reads the registers one by one. +*/ +static int rtw_sdio_read_local_regs (struct rtw_dev *rtwdev,u32 addr, +__le32 *buf,unsigned int num) +{ +struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; +bool bus_claim; +int ret; + +if (!rtw_sdio_use_memcpy_io (rtwdev, addr,4 )) +return -EAGAIN ; + + bus_claim =rtw_sdio_bus_claim_needed (rtwsdio); + +if (bus_claim) +sdio_claim_host (rtwsdio->sdio_func); + + ret =sdio_memcpy_fromio (rtwsdio->sdio_func, buf, +rtw_sdio_to_io_address (rtwdev, addr, true), + num *sizeof (*buf)); + +if (bus_claim) +sdio_release_host (rtwsdio->sdio_func); + +if (ret) +rtw_warn (rtwdev,"sdio read of %u registers at 0x%x failed: %d" , + num, addr, ret); + +return ret; +} +static void rtw_sdio_88xx_sync_free_txpg (struct rtw_dev *rtwdev) {struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv; +__le32 *regs = rtwsdio->txpg_regs;u32 free_txpg[3 ];lockdep_assert_held (&rtwsdio->tx_credit_lock); - free_txpg[0 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG ); - free_txpg[1 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +4 ); - free_txpg[2 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +8 ); +if (regs && !rtw_sdio_read_local_regs (rtwdev,REG_SDIO_FREE_TXPG , + regs,3 )) { + free_txpg[0 ] =le32_to_cpu (regs[0 ]); + free_txpg[1 ] =le32_to_cpu (regs[1 ]); + free_txpg[2 ] =le32_to_cpu (regs[2 ]); + }else { + free_txpg[0 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG ); + free_txpg[1 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +4 ); + free_txpg[2 ] =rtw_sdio_read32 (rtwdev,REG_SDIO_FREE_TXPG +8 ); + }atomic_set (&rtwsdio->free_pg_high, free_txpg[0 ] &0xfff );atomic_set (&rtwsdio->free_pg_normal, (free_txpg[0 ] >>16 ) &0xfff );
@@ -1633,12 +1676,15 @@ static bool rtw_sdio_rx_budget_left(struct rtw_dev *rtwdev, u32 rx_bytes) !rtw_sdio_tx_pending (rtwdev); } -static void rtw_sdio_rx_isr (struct rtw_dev *rtwdev) +/* rx_len: the RX request length if it was read together with HISR, or 0 */ +static void rtw_sdio_rx_isr (struct rtw_dev *rtwdev,u32 rx_len) { -u32 rx_len, hisr, total_rx_bytes =0 ; +u32 hisr, total_rx_bytes =0 ; do { - if (rtw_chip_wcpu_8051(rtwdev)) + if (rx_len) + ; + else if (rtw_chip_wcpu_8051(rtwdev)) rx_len = rtw_read16(rtwdev, REG_SDIO_RX0_REQ_LEN); else rx_len = rtw_read32(rtwdev, REG_SDIO_RX0_REQ_LEN);
@@ -1649,6 +1695,7 @@ static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev)rtw_sdio_rxfifo_recv (rtwdev, rx_len); total_rx_bytes += rx_len; + rx_len =0 ;if (rtw_chip_wcpu_8051 (rtwdev)) {/* Stop if no more RX requests are pending, even if
@@ -1676,20 +1723,28 @@ static void rtw_sdio_handle_interrupt(struct sdio_func *sdio_func)struct ieee80211_hw *hw =sdio_get_drvdata (sdio_func);struct rtw_sdio *rtwsdio;struct rtw_dev *rtwdev; -u32 hisr; +u32 hisr, rx_len =0 ; rtwdev = hw->priv; rtwsdio = (struct rtw_sdio *)rtwdev->priv; rtwsdio->irq_thread = current; - hisr =rtw_read32 (rtwdev,REG_SDIO_HISR ); +/* RX0_REQ_LEN follows HISR, read both at once where possible */ +if (rtwsdio->rx_regs && + !rtw_sdio_read_local_regs (rtwdev,REG_SDIO_HISR , + rtwsdio->rx_regs,2 )) { + hisr =le32_to_cpu (rtwsdio->rx_regs[0 ]); + rx_len =le32_to_cpu (rtwsdio->rx_regs[1 ]); + }else { + hisr =rtw_read32 (rtwdev,REG_SDIO_HISR ); + }if (hisr ®_SDIO_HISR_TXERR )rtw_sdio_tx_err_isr (rtwdev);if (hisr ®_SDIO_HISR_RX_REQUEST ) { hisr &= ~REG_SDIO_HISR_RX_REQUEST ; -rtw_sdio_rx_isr (rtwdev); +rtw_sdio_rx_isr (rtwdev, rx_len); }/*
@@ -2127,9 +2182,14 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)* that only the non-8051 chips keep; without the buffer, frames are * sent one by one. */ -if (!rtw_chip_wcpu_8051 (rtwdev)) +if (!rtw_chip_wcpu_8051 (rtwdev)) { rtwsdio->tx_agg_buf =kmalloc (RTW_SDIO_TX_AGG_MAX_SIZE +RTW_SDIO_BLOCK_SIZE ,GFP_KERNEL ); +/* without these, the registers are read one by one */ + rtwsdio->rx_regs =kmalloc_array (2 ,sizeof (__le32),GFP_KERNEL ); + rtwsdio->txpg_regs =kmalloc_array (3 ,sizeof (__le32), +GFP_KERNEL ); + }for (i =0 ; i <RTK_MAX_TX_QUEUE_NUM ; i++) {skb_queue_head_init (&rtwsdio->tx_queue[i]);
@@ -2146,6 +2206,8 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev) err_destroy_wq:kfree (rtwsdio->tx_agg_buf); +kfree (rtwsdio->rx_regs); +kfree (rtwsdio->txpg_regs);mutex_destroy (&rtwsdio->tx_credit_lock);destroy_workqueue (rtwsdio->txwq);return -ENOMEM ;
@@ -2164,6 +2226,8 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev)ieee80211_purge_tx_queue (rtwdev->hw, &rtwsdio->tx_queue[i]);kfree (rtwsdio->tx_agg_buf); +kfree (rtwsdio->rx_regs); +kfree (rtwsdio->txpg_regs);mutex_destroy (&rtwsdio->tx_credit_lock); }
drivers/net/wireless/realtek/rtw88/sdio.h +4 -0
@@ -188,6 +188,10 @@ struct rtw_sdio {bool free_txpg_valid;/* TX aggregation buffer of the non-8051 chips, under tx_credit_lock */ u8 *tx_agg_buf; +/* non-8051 chips: HISR + RX0_REQ_LEN, read by the interrupt handler */ +__le32 *rx_regs; +/* non-8051 chips: the REG_SDIO_FREE_TXPG words, under tx_credit_lock */ +__le32 *txpg_regs;/* one writer at a time between the credit check and the accounting */ struct mutex tx_credit_lock; };
Signature · 1 line
2.47.3
Re: [PATCH rtw-next 5/5] wifi: rtw88: sdio: read neighbouring registers of the 88xx chips at once
Quoted 20 lines · David Härdeman
Every register access costs a full SDIO command, about 40 us on a NanoPi R76S (RTL8822CS, SDR104), no matter how many bytes it moves. The interrupt handler reads HISR and then
RX0_REQ_LEN, which follows it, and a free page sync reads the threeREG_SDIO_FREE_TXPGwords one by one.Read HISR together with
RX0_REQ_LEN, and the three free page words, with one transfer each, as Realtek's driver does. As inrtw_sdio_readl(), this is only done while the chip is powered on; before that, and if the small DMA-safe buffers this needs could not be allocated, the registers are read one by one as before.On the R76S acting as an AP, TCP throughput to a client goes from about 170 to about 190 Mbit/s, the other directions are unchanged.
Signed-off-by David Härdeman <[email protected]>--- drivers/net/wireless/realtek/rtw88/sdio.c | 84 ++++++++++++++++++++--- drivers/net/wireless/realtek/rtw88/sdio.h | 4 ++ 2 files changed, 78 insertions(+), 10 deletions(-)
[...]
Quoted 5 lines
drivers/net/wireless/realtek/rtw88/sdio.h +0
-0
drivers/net/wireless/realtek/rtw88/sdio.h struct rtw_sdio { · line 197
Quoted 10 lines
drivers/net/wireless/realtek/rtw88/sdio.h +4
-0@@ -188,6 +188,10 @@ struct rtw_sdio {bool free_txpg_valid;/* TX aggregation buffer of the non-8051 chips, under tx_credit_lock */ u8 *tx_agg_buf; +/* non-8051 chips: HISR + RX0_REQ_LEN, read by the interrupt handler */ +__le32 *rx_regs; +/* non-8051 chips: the REG_SDIO_FREE_TXPG words, under tx_credit_lock */ +__le32 *txpg_regs;/* one writer at a time between the credit check and the accounting */ struct mutex tx_credit_lock; };
By the way, you can call them "3081 chips".
Hi David,
On November 16, 2026 8:01:40 PM GMT+01:00, "David Härdeman" <[email protected]> wrote:
[ ... ]
Quoted 10 lines
Two series on the list touch the same code, and I'd like to make sure this one doesn't clash with them:
- Alastair D'Silva's "wifi: rtw88: sdio: Fix unhandled RX request interrupt storm" (v10) changes the RX interrupt handling that patches 4 and 5 touch. This series is based on rtw-next without it; I have a version rebased on top of it and will send that once it's applied.
https://lore.kernel.org/linux-wireless/[email protected]/
Quoted 8 lines
- Leonard Lausen's "wifi: rtw88: reduce RTL8822CS SDIO request overhead" (v2): his patch 1 (control frame filter) is independent of this series and applies on top of it. His patch 2 combines the free page register reads that patch 1 here replaces with cached counts, so only one of the two makes sense; Leonard, I'm happy to go with whatever you and Ping-Ke prefer.
https://lore.kernel.org/linux-wireless/[email protected]/
These two will probably land before your series, as both had gone through couple(or more) versions and both carry my Reviewed-by tag.
Either way I will review it in the morning, so we will see then.
Best regards,
Luka Gejak
Ping-Ke Shih
maintainerQuoted 4 lines · David Härdeman
Known issue, not addressed here: when the client goes off-channel (for example for a background scan), the chip sometimes gives up on an MPDU of an A-MPDU session without sending a BAR, and keeps sending up to 64 frames past it.
What do you expect?
rtw88 client
TX A-MPDU -->
TX BAR -->
<-- BAI have not seen BAR for a long time. Do you really need it?
Quoted 2 lines
rtw88 reports every SDIO data frame as acked, so mac80211 doesn't know either and can't send a BAR.
Can you check air sniffer if the A-MPDU is actually acked, or firmware report incorrect ack?
I think mac80211 has no way to send a BAR. How can it do? Driver tells mac80211 once it TX a set of frames?
Quoted 3 lines
The client's
reorder window then stalls until it is pushed past the hole, which costs a short throughput dip.
Are there some frames get missed but hardware somehow considers it has acked them already? (I think need to check air sniffer)
Quoted 10 lines
With iwlwifi clients it turned into
bursts of up to 63 lost frames per hole because of a reorder buffer bug there, for which I have sent fixes:
https://lore.kernel.org/linux-wireless/[email protected]/
I tried the hardware BAR settings (REG_BAR_MODE_CTRLthresholds, the BAR retry bits in the TX descriptor), a longer retry limit, MACID sleep for dozing clients, per-frame TX reports and a BAR sent by the driver after the client wakes up; none of them helped, and per-frame reports only came back for about one frame per A-MPDU. Ping-Ke, is there a way for the firmware to report which MPDU it dropped,
I think hardware's retry buffer will do it properly. If a frame exceeds retry limit, TX report tells driver a frame is dropped. But this is only for specific frames with SN (see rtw_tx_report_enqueue()).
Quoted 2 lines
or to send the BAR
itself?
As I know BAR is to ask peer to send BA, what does your expectation if you can send BAR?
Quoted 6 lines · Ping-Ke Shih
Quoted 4 lines · David Härdeman
Known issue, not addressed here: when the client goes off-channel (for example for a background scan), the chip sometimes gives up on an MPDU of an A-MPDU session without sending a BAR, and keeps sending up to 64 frames past it.
Quoted 8 lines
What do you expect?
rtw88 client TX A-MPDU --> TX BAR --> <-- BAI have not seen BAR for a long time. Do you really need it?
First, I'm not a WiFi expert, so please excuse me if my understanding/explanation is wrong, weird, or both...
That said, I should have explained this better. What I see is:
1. The client (iwlwifi) goes off-channel for a scan, about 120 ms at a time. Here these were the background scans that NetworkManager sets up in wpa_supplicant to find roaming candidates, which run every 30 s while the signal is below a threshold.
2. The chip keeps retrying the frames it already has, gives up on one of them (SN n) when the retry limit is reached, and later continues with n+1 and onwards. SN n is never sent again.
3. The client's reorder buffer now has a hole at n. It holds n+1 and the following frames until its reorder timeout fires, or until a frame at n+64 or beyond pushes the window past the hole.
A BAR with starting sequence number n+1 after step 2 would tell the client that n won't come, so that it can release the frames it holds right away. That's the use I mean, not asking for a BA.
Quoted 5 lines
Quoted 2 lines
rtw88 reports every SDIO data frame as acked, so mac80211 doesn't know either and can't send a BAR.
Can you check air sniffer if the A-MPDU is actually acked, or firmware report incorrect ack?
I did use a second AP as a sniffer, but it was too far from the R76S to decode its VHT data frames. It did see the client's BAs, and no BAR from the AP. I can repeat the capture closer to the AP if you think it would help (I would have to wait until a time when I'm not interrupting the kids' gaming though).
What I have seen:
- On the client, a trace of every MPDU its firmware passed up showed that SN n never arrived (within +-500 ms, on any RX queue), while n+1 and onwards arrived as retries once the client was back.
- On the AP, a debug build of the driver that polls the firmware's per-MACID TX statistics every 2 s (H2C 0x43, C2H AP_REQ_TXRPT) saw failed frames only while the client was scanning (13 in four 2-minute runs, all during scans).
So I don't think the firmware considers these frames acked: it knows that it dropped them, but rtw88 doesn't learn which ones. The "acked" I wrote about is what rtw88 tells mac80211 for every SDIO data frame.
Quoted 2 lines
I think mac80211 has no way to send a BAR. How can it do? Driver tells mac80211 once it TX a set of frames?
From what I understand, mac80211 can, but only if the driver tells it which frame was dropped: the driver reports that frame as not acked, with IEEE80211_TX_STAT_AMPDU_NO_BACK set, and mac80211 then sends a BAR with SSN = SN + 1 (see net/mac80211/status.c). iwlwifi's mvm does this when a single frame of an A-MPDU fails.
rtw88 can't do that today, because it doesn't learn which frame the chip
dropped: for SDIO it reports every data frame as acked once it has been handed to the chip. That's why I asked if the firmware can report the dropped frames (or send the BAR itself).
Quoted 6 lines
Quoted 3 lines
The client's
reorder window then stalls until it is pushed past the hole, which costs a short throughput dip.Are there some frames get missed but hardware somehow considers it has acked them already? (I think need to check air sniffer)
See above: as far as I can tell, the frame is missed, and the firmware counts it as failed (so it must be aware).
Quoted 11 lines
Quoted 10 lines
With iwlwifi clients it turned into
bursts of up to 63 lost frames per hole because of a reorder buffer bug there, for which I have sent fixes:
https://lore.kernel.org/linux-wireless/[email protected]/
I tried the hardware BAR settings (REG_BAR_MODE_CTRLthresholds, the BAR retry bits in the TX descriptor), a longer retry limit, MACID sleep for dozing clients, per-frame TX reports and a BAR sent by the driver after the client wakes up; none of them helped, and per-frame reports only came back for about one frame per A-MPDU. Ping-Ke, is there a way for the firmware to report which MPDU it dropped,
Quoted 3 lines
I think hardware's retry buffer will do it properly. If a frame exceeds retry limit, TX report tells driver a frame is dropped. But this is only for specific frames with SN (see
rtw_tx_report_enqueue()).
I tried requesting that report for every QoS data frame: only about 7 % of the requests were answered, roughly one per A-MPDU, and download throughput dropped by about a third (~210 to ~140 Mbit/s). So per-frame reports don't seem usable for this. A report that only covers the dropped frames, with their SN, would be enough.
Quoted 5 lines
Quoted 2 lines
or to send the BAR
itself?As I know BAR is to ask peer to send BA, what does your expectation if you can send BAR?
As above, a BAR with SSN = n+1 moves the client's window past the dropped frame. REG_BAR_MODE_CTRL suggests that the MAC can send BARs by itself (BAR_EN is set on my chip), but lowering its thresholds made no difference to the losses.
As for whether it's needed: with the iwlwifi fix, the remaining cost is a throughput dip while the client scans, because it waits for the timeout or for the window to be pushed past the hole. So it isn't urgent, and this series doesn't try to fix it. I mentioned it as a known issue in case there is a firmware feature for it.
Signature · 1 line
David Härdeman
Hi David,
Thanks for your explanation, here is my two cents.
Quoted 3 lines · David Härdeman
I did use a second AP as a sniffer, but it was too far from the R76S to decode its VHT data frames. It did see the client's BAs, and no BAR from the AP.
I think the closer capture would still help, with the data frames and BA bitmap for the same TID around a scan. The client trace shows what its firmware passed up, and the per MACID failure count does not identify which MPDU failed. Matching those to the air capture would help check what happened to the particular hole.
[ ... ]
Quoted 4 lines
From what I understand, mac80211 can, but only if the driver tells it which frame was dropped: the driver reports that frame as not acked, with
IEEE80211_TX_STAT_AMPDU_NO_BACKset, and mac80211 then sends a BAR with SSN = SN + 1 (seenet/mac80211/status.c).
I checked the mac80211 status path, and it does send a BAR with the next sequence number for that QoS status. The current rtw88 report helper does not set AMPDU_NO_BACK, so requesting the reports alone would not exercise that recovery path.
[ ... ]
Quoted 5 lines
I tried requesting that report for every QoS data frame: only about 7 % of the requests were answered, roughly one per A-MPDU, and download throughput dropped by about a third (~210 to ~140 Mbit/s). So per-frame reports don't seem usable for this. A report that only covers the dropped frames, with their SN, would be enough.
One detail that might affect this experiment is that the sn passed to rtw_tx_report_enqueue() is a report cookie, rather than the frame's 802.11 sequence number. It has six usable bits:
pkt_info->sn = (atomic_inc_return(&tx_report->sn) << 2) & 0xfc;
As far as I can see, it repeats after 64 requests, and rtw_tx_report_handle() takes the first skb with a matching cookie. If an older request is still pending when its cookie is reused, a report for the newer frame can complete the older skb.
Was the 7% figure from raw C2H events or from completed skbs? This would affect frame attribution, but would not explain a shortage of raw C2H events. Maybe a short run with one request outstanding at a time, logging the cookie, QoS TID and seq_ctrl, would help check that part.
Best regards,
Luka Gejak
Quoted 5 lines · Luka Gejak
I think the closer capture would still help, with the data frames and BA bitmap for the same TID around a scan. The client trace shows what its firmware passed up, and the per MACID failure count does not identify which MPDU failed. Matching those to the air capture would help check what happened to the particular hole.
(Full disclosure: mostly LLM-generated content here, I tried to edit it down to a reasonable length, but I'm not 100% sure which parts to keep and not, sorry about the wall of text).
Thanks, the capture helped a lot. Short version: when a client is off-channel for longer than the chip's retry chain lasts, the chip discards the MPDU, nobody learns about it (rtw88 reports SDIO frames as acked), no BAR is sent, and the client's BA window stays at the hole. How long the chain lasts depends on the BE contention window:
with hostapd's default for the AP's own BE queue (CWmax 63), the 32 retries are over after about 85 ms, shorter than a scan dwell here (110-150 ms). With CWmax 1023, which is what rtw8822c.c initialises before mac80211 configures the queues and what Realtek's vendor driver keeps using, the retries outlast the dwell and the holes mostly go away. Details below.
Setup: an MT7915 (mt76) sniffer 1 m from the AP, an iwlwifi client 2 m away, a TCP download through the AP, a client scan forced every 20 s, 60 s per run. The sniffer passes up only part of the A-MPDU subframes, but practically all BlockAcks. On the client I logged the frames iwlwifi drops at its PN check (a kprobe), which gives the hole's SN for each loss burst; clocks were synced to within a few ms.
1. What happens to a hole. Example, SN 2971 (TID 0, seconds into the run):
22.0063 last BA before the scan: everything up to 2970 acked
22.0065 client sends a QoS Null with PM=1 and leaves the channel
22.0092 A-MPDU starting with SN 2971, no BA ... 2971 at the head of the A-MPDU 31 more times, about 2.5 ms apart (rate falling to 6 Mbit/s), never a BA
22.0926 last transmission of 2971; it is never sent again 22.1205 client back (PM=0), 28 ms too late
22.1607 first BA: SSN 2939, 2971 missing, 2972..3002 received 22.1652 the AP sends SN 3035 (= 2971 + 64)
22.1853 BA SSN 2990: the client's window has moved past 2971
22.196 iwlwifi drops 63 frames (the bug I sent fixes for)
This is the common case: in two runs where I matched every loss burst to the capture (18 holes, stock driver), 14 looked like this (1 + 32 transmissions during the dwell), 2 weren't in the capture, and no run had a single BAR.
2. It isn't the series and it isn't the client. The stock rtw-next driver shows the same pattern (the series has about half as many
holes: 3.5 vs. 6.7 per run over 11 runs each). With an mt7915 client instead of iwlwifi, the AP's firmware TX statistics count failed MPDUs only during forced scans (9 in 9 scans, 0 without).
3. The retry chain is too short for the dwell. With REG_RETRY_LIMIT at 48/48 the hole's retries last about 112 ms and end a few ms before the client returns; at 60/60, chains of 36-48 transmissions (up to about 125 ms) were acked after the client came back and the holes went from 4.3 to 2.6 per run. (63/63 stalls the chip's TX, so that's not a fix.) Putting the MACID to sleep from sta_notify doesn't help either: the register write is done within about 1 ms, but the chip keeps retrying the A-MPDU it has started.
4. What the vendor driver does differently. Realtek's vendor driver (rtl88x2cs v5.14.0.2-0-g4c549b2.20210914, built from
https://github.com/friendlyarm/rtl8822cs, branch nanopi-r2, which FriendlyElec ships for this board) on a second board of the same kind has about one hole per run. Neither its firmware (9.13.0; with rtw88's 9.9.15 patched into its module it behaves the same) nor its power save handling (it only moves queued frames to a sleep queue) explains that. What does is its turbo EDCA (rtw_hal_turbo_edca() in hal/hal_dm.c, run from the driver's 2 s watchdog): it overrides REG_EDCA_BE_PARAM with CWmax 1023 (0x005ea42b with mostly TX, 0x0000a42b with mostly RX), while rtw88's __rtw_conf_tx() writes mac80211's value, 0x005e642b (CWmax 63) with hostapd's defaults. Swapping the value on both drivers, alternating runs:
rtw88 + series, CWmax 1023 (hostapd
tx_queue_data2_cwmax=1023) 4 holes in 32 scans
rtw88 + series, CWmax 63 (default) 25 holes in 26 scans
vendor driver, CWmax 1023 (default) 3 holes in 16 scans
vendor driver, CWmax 63 83 holes in 17 scans
Throughput was the same with both values on both drivers.
A smaller second pattern remains with either value: when several MPDUs of an A-MPDU are outstanding, the chip retries them together about 7 times and then drops the older ones after about 8 transmissions, independent of REG_RETRY_LIMIT (WLAN_RA_TRY_RATE_AGG_LIMIT?).
I don't think rtw88 is wrong to apply CWmax 63: it's the value hostapd documents as the AP's own default for BE, and mac80211 passes it on as it should. CWmax 1023 only makes the retry chain long enough for typical scan dwells; a client that stays away longer would still lose the MPDU. The real gap is that the discard isn't reported: if mac80211 learned that the MPDU failed, it would send a BAR itself and the client's window would move on right away.
Ping-Ke, can the chip or the firmware report MPDUs it discards after the retry limit (or send a BAR itself), in a way rtw88 could use without requesting a TX report for every frame? Until there is a fix, tx_queue_data2_cwmax=1023 in hostapd is a workaround for users.
Quoted 4 lines
I checked the mac80211 status path, and it does send a BAR with the next sequence number for that QoS status. The current rtw88 report helper does not set
AMPDU_NO_BACK, so requesting the reports alone would not exercise that recovery path.
Right. My experiment had an option for the driver to call ieee80211_send_bar() itself when a report said the frame had failed, but with so few reports coming back, that wasn't a usable path.
Quoted 4 lines
One detail that might affect this experiment is that the sn passed to
rtw_tx_report_enqueue()is a report cookie, rather than the frame's 802.11 sequence number. It has six usable bits:
Quoted 8 lines
pkt_info->sn = (atomic_inc_return(&tx_report->sn) << 2) & 0xfc;As far as I can see, it repeats after 64 requests, and
rtw_tx_report_handle()takes the first skb with a matching cookie. If an older request is still pending when its cookie is reused, a report for the newer frame can complete the older skb.Was the 7% figure from raw C2H events or from completed skbs?
From raw C2H events. That experiment didn't use rtw_tx_report_enqueue():
it put the low six bits of the frame's 802.11 sequence number into the report field instead of a cookie, and counted every TX report the firmware sent, before any matching.
An earlier test, which requested a report for one in 16 QoS data frames, did use the normal cookie path, and there you're right: at that rate the cookies wrap after about 50 ms, so its numbers (3-9 % answered) may well be off. They agree with the raw count, though.
Quoted 4 lines
This would
affect frame attribution, but would not explain a shortage of raw C2H events. Maybe a short run with one request outstanding at a time, logging the cookie, QoS TID andseq_ctrl, would help check that part.
I tried that: a debug build that requests a report through the normal path for one unicast QoS data frame at a time, and only sends the next request once the report has arrived, or after 500 ms without one. The client was a phone streaming video, for three minutes per run:
run 1 run 2
requests 337 808
answered 258 750
given up (no answer >= 500 ms) 79 58
of these, answered later 0 6
reports with another cookie 3 8All answers reported success; in the second run the median time to the report was about 4 ms. So even with only one request outstanding, 7 to 23 % of the reports didn't arrive within 500 ms, and nearly all of those never arrived. I couldn't tie the missing ones to periods of heavier traffic.
Signature · 1 line
David Härdeman