Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames
@ 2026-10-28 17:16 Tomas Tonhauser
  2026-10-28 17:16 ` [PATCH v2 1/2] wifi: ath9k: clear destination mask for " Tomas Tonhauser
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tomas Tonhauser @ 2026-10-28 17:16 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: linux-wireless, Felix Fietkau, linux-kernel, Tomas Tonhauser

Non-aggregate frames (stations without an A-MPDU session, e.g.
non-WMM ESP8266 clients) are lost on ath9k in two ways:

 1. The hardware filters them (ATH9K_TXERR_FILT) while the station
    is awake, and mac80211 retries a filtered frame only once.
    Patch 1 sets CLRDMASK on every non-aggregate frame.

 2. Frames that exhaust the hardware retry chain are dropped, as
    there is no software retry for non-aggregate frames. Patch 2
    re-queues failed and filtered frames on tid->retry_q, as the
    aggregate path does.

Toke, I know you were not keen on clearing the filter
unconditionally, so I first tested your suggestion (patch 2) alone.
On a weak link it did much worse than patch 1 alone, and the two
together did best. If you would prefer patch 1 limited, e.g. to
stations that are not sleeping, I can rework it.

Setup: TP-Link EAP225 v3 (QCA9563, 2.4 GHz), OpenWrt 25.12.5,
backports 6.18.26. ESP8266 clients running Tasmota, non-WMM, legacy
rates, modem sleep on (PS_STA toggling constantly).

Weak client (-75 dBm), ping -s 1000 -i 0.05, 500 pings per run:

                     loss         TXERR Filtered   avg RTT
  patch 2 only       52-80%       +544 per run     0.6-1.4 s
  patch 1 only       0-1 pings    0                13 ms

Same client, patches 1+2 plus a test-only module parameter to switch
the software retry at runtime, 12 alternating runs in 11 minutes:

                     lost         tx failed
  retry off (1)      127/3000     130
  retry on (1+2)     1/3000       1

At 1 ping/s, 3 x 25 pings each: 5/75 lost with retry off, 0/75 on.

Other tests with patches 1+2:
 - 500 pings to each of five ESP8266 clients: 0 lost
 - client restarts during ping floods, OTA updates: no issues
 - WMM/HT clients (ESP32, IP camera, tablet): no change
 - 67 h soak: no warnings or resets, MemAvailable flat, ath9k
   queues drain to 0, 3 TXERR Filtered in total

Felix, on the open question from the RFC: on the weak link, filtered
frames appeared together with XRETRY failures, but on the original
good-signal setup they appeared without any. Do you know what sets
the destination mask for an awake station?

Changes since RFC:
 - Patch 1: code unchanged, commit message updated
 - Patch 2: new, alternative 2 from the RFC (Toke)

RFC: https://lore.kernel.org/linux-wireless/20261003192957.761090-1-t.tonhauser@pobox.sk/

The driver analysis and write-up were done with help from an LLM.
Tests and measurements were done by me.

Tomas Tonhauser (2):
  wifi: ath9k: clear destination mask for non-aggregate frames
  wifi: ath9k: retry failed non-aggregate frames in software

 drivers/net/wireless/ath/ath9k/xmit.c | 58 +++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 4 deletions(-)


base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b
-- 
2.34.1


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

* [PATCH v2 1/2] wifi: ath9k: clear destination mask for non-aggregate frames
  2026-10-28 17:16 [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames Tomas Tonhauser
@ 2026-10-28 17:16 ` Tomas Tonhauser
  2026-10-28 17:16 ` [PATCH v2 2/2] wifi: ath9k: retry failed non-aggregate frames in software Tomas Tonhauser
  2026-11-17  9:09 ` [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames Toke Høiland-Jørgensen
  2 siblings, 0 replies; 4+ messages in thread
From: Tomas Tonhauser @ 2026-10-28 17:16 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: linux-wireless, Felix Fietkau, linux-kernel, Tomas Tonhauser

Frames to stations without an A-MPDU session (e.g. non-WMM/non-HT
clients) use the non-aggregate path. The hardware may complete such
frames with ATH9K_TXERR_FILT while the station is awake. They are
then reported to mac80211 as IEEE80211_TX_STAT_TX_FILTERED, and
ieee80211_handle_filtered_frame() retries them only once for a
station that is not in powersave.

The aggregate path re-queues filtered subframes on tid->retry_q and
sets tid->clear_ps_filter, so they are retransmitted until they get
through.

The result is downlink loss to awake non-WMM stations, while WMM/HT
stations on the same radio are unaffected. On a QCA9563 AP with
ESP8266 clients this caused 20-40% ping loss.

Set CLRDMASK on every non-aggregate frame. This restores the
behaviour from before commit 5519541d5a5f ("ath9k: fix powersave
frame filtering/buffering in AP mode") for the non-aggregate path
only. The trade-off is that non-aggregate frames already queued in
hardware when a station enters powersave may be sent to the sleeping
station instead of being filtered.

Assisted-by: LLM
Signed-off-by: Tomas Tonhauser <t.tonhauser@pobox.sk>
---

Notes:
    v2: code unchanged, commit message updated

 drivers/net/wireless/ath/ath9k/xmit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 3413bb4906d4..913aa280ae2a 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1432,7 +1432,7 @@ static void ath_tx_fill_desc(struct ath_softc *sc, struct ath_buf *bf,
 			if (!sc->tx99_state)
 				info.flags = ATH9K_TXDESC_INTREQ;
 			if ((tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) ||
-			    txq == sc->tx.uapsdq)
+			    txq == sc->tx.uapsdq || !aggr)
 				info.flags |= ATH9K_TXDESC_CLRDMASK;
 
 			if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
-- 
2.34.1


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

* [PATCH v2 2/2] wifi: ath9k: retry failed non-aggregate frames in software
  2026-10-28 17:16 [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames Tomas Tonhauser
  2026-10-28 17:16 ` [PATCH v2 1/2] wifi: ath9k: clear destination mask for " Tomas Tonhauser
@ 2026-10-28 17:16 ` Tomas Tonhauser
  2026-11-17  9:09 ` [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames Toke Høiland-Jørgensen
  2 siblings, 0 replies; 4+ messages in thread
From: Tomas Tonhauser @ 2026-10-28 17:16 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: linux-wireless, Felix Fietkau, linux-kernel, Tomas Tonhauser

Aggregate frames that fail or are filtered by the hardware are put
back on tid->retry_q and retransmitted until ATH_MAX_SW_RETRIES is
reached. Non-aggregate frames have no such software retry: a frame
that exhausts the hardware retry chain is completed as failed, and a
filtered one is handed to mac80211, which retries it only once for
stations that are not in powersave.

On weak links this shows up as downlink loss to clients without an
A-MPDU session. With an ESP8266 client at about -75 dBm, 1000-byte
ping floods lost 4.2% of frames, all after ATH9K_TXERR_XRETRY.

Re-queue failed and filtered non-aggregate data frames to awake
stations on tid->retry_q, using the same retry accounting and limit
as the aggregate path. Frames to sleeping stations, management
frames, no-ack frames and frames sent on other queues keep the
current behaviour.

Suggested-by: Toke Høiland-Jørgensen <toke@toke.dk>
Assisted-by: LLM
Signed-off-by: Tomas Tonhauser <t.tonhauser@pobox.sk>
---

Notes:
    v2: new patch
    
    Open points:
     - As in the aggregate path, rate control only gets status for the
       final attempt of a re-queued frame.
     - ath_tx_set_retry() counts the retry as "AMPDUs Retried" in
       debugfs.

 drivers/net/wireless/ath/ath9k/xmit.c | 56 +++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 913aa280ae2a..d141292612b9 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -722,6 +722,55 @@ static void ath_tx_count_airtime(struct ath_softc *sc,
 	ieee80211_sta_register_airtime(sta, tid, airtime, 0);
 }
 
+static bool ath_tx_retry_buf(struct ath_softc *sc, struct ath_txq *txq,
+			     struct ath_buf *bf, struct ieee80211_sta *sta,
+			     struct ath_atx_tid *tid, struct ath_tx_status *ts)
+{
+	struct sk_buff *skb = bf->bf_mpdu;
+	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
+	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
+	struct ath_frame_info *fi = get_frame_info(skb);
+	struct ath_node *an;
+	int i, retries;
+
+	if (!sta || tid->txq != txq)
+		return false;
+
+	if (!(ts->ts_status & (ATH9K_TXERR_FILT | ATH9K_TXERR_XRETRY)))
+		return false;
+
+	if (!ieee80211_is_data_present(hdr->frame_control) ||
+	    (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) ||
+	    bf->bf_state.bfs_paprd)
+		return false;
+
+	an = (struct ath_node *)sta->drv_priv;
+	if (an->sleeping || fi->retries >= ATH_MAX_SW_RETRIES)
+		return false;
+
+	retries = ts->ts_longretry + 1;
+	for (i = 0; i < ts->ts_rateindex; i++)
+		retries += bf->rates[i].count;
+
+	if (bf->bf_state.stale) {
+		struct ath_buf *tbf = ath_clone_txbuf(sc, bf);
+
+		if (!tbf)
+			return false;
+		fi->bf = tbf;
+	} else {
+		list_del_init(&bf->list);
+	}
+
+	ath_tx_set_retry(sc, txq, skb, retries);
+	if (ts->ts_status & ATH9K_TXERR_FILT)
+		TX_STAT_INC(sc, txq->axq_qnum, txerr_filtered);
+
+	__skb_queue_tail(&tid->retry_q, skb);
+	ath_tx_queue_tid(sc, tid);
+	return true;
+}
+
 static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq,
 				  struct ath_tx_status *ts, struct ath_buf *bf,
 				  struct list_head *bf_head)
@@ -754,7 +803,9 @@ static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq,
 			tid->clear_ps_filter = true;
 	}
 
-	if (!bf_isampdu(bf)) {
+	if (bf_isampdu(bf)) {
+		ath_tx_complete_aggr(sc, txq, bf, bf_head, sta, tid, ts, txok);
+	} else if (flush || !ath_tx_retry_buf(sc, txq, bf, sta, tid, ts)) {
 		if (!flush) {
 			info = IEEE80211_SKB_CB(bf->bf_mpdu);
 			memcpy(info->control.rates, bf->rates,
@@ -764,8 +815,7 @@ static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq,
 						sta);
 		}
 		ath_tx_complete_buf(sc, bf, txq, bf_head, sta, ts, txok);
-	} else
-		ath_tx_complete_aggr(sc, txq, bf, bf_head, sta, tid, ts, txok);
+	}
 
 	if (!flush)
 		ath_txq_schedule(sc, txq);
-- 
2.34.1


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

* Re: [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames
  2026-10-28 17:16 [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames Tomas Tonhauser
  2026-10-28 17:16 ` [PATCH v2 1/2] wifi: ath9k: clear destination mask for " Tomas Tonhauser
  2026-10-28 17:16 ` [PATCH v2 2/2] wifi: ath9k: retry failed non-aggregate frames in software Tomas Tonhauser
@ 2026-11-17  9:09 ` Toke Høiland-Jørgensen
  2 siblings, 0 replies; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2026-11-17  9:09 UTC (permalink / raw)
  To: Tomas Tonhauser
  Cc: linux-wireless, Felix Fietkau, linux-kernel, Tomas Tonhauser

Tomas Tonhauser <t.tonhauser@pobox.sk> writes:

> Non-aggregate frames (stations without an A-MPDU session, e.g.
> non-WMM ESP8266 clients) are lost on ath9k in two ways:
>
>  1. The hardware filters them (ATH9K_TXERR_FILT) while the station
>     is awake, and mac80211 retries a filtered frame only once.
>     Patch 1 sets CLRDMASK on every non-aggregate frame.
>
>  2. Frames that exhaust the hardware retry chain are dropped, as
>     there is no software retry for non-aggregate frames. Patch 2
>     re-queues failed and filtered frames on tid->retry_q, as the
>     aggregate path does.
>
> Toke, I know you were not keen on clearing the filter
> unconditionally, so I first tested your suggestion (patch 2) alone.
> On a weak link it did much worse than patch 1 alone, and the two
> together did best. If you would prefer patch 1 limited, e.g. to
> stations that are not sleeping, I can rework it.

So an alternative solution to what appears to be the same problem your
patch 1 is solving appeared:

https://lore.kernel.org/r/20261110170459.31857-1-dominikengelhardt@ymail.com

Could you please check if this approach works in your tests (with or
without patch 2)?

Thanks!

-Toke

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

end of thread, other threads:[~2026-11-17  9:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 17:16 [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames Tomas Tonhauser
2026-10-28 17:16 ` [PATCH v2 1/2] wifi: ath9k: clear destination mask for " Tomas Tonhauser
2026-10-28 17:16 ` [PATCH v2 2/2] wifi: ath9k: retry failed non-aggregate frames in software Tomas Tonhauser
2026-11-17  9:09 ` [PATCH v2 0/2] wifi: ath9k: fix loss of non-aggregate frames Toke Høiland-Jørgensen

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