[PATCH ath-next 3/3] wifi: ath11k: set the AQL limits of a station from its PPDUs

From: Julius Bairaktaris

Date: Sun Nov 29 2026 - 09:42:46 EST


With the same 12 ms AQL high limit for every station, a station that
the AP is the bottleneck for keeps up to 12 ms of airtime queued in
the firmware, and each of its frames waits behind it. The firmware
needs much less to stay busy: two of the station's PPDUs, one on the
air and one being built, and the airtime of the frames on the air until
their TX completion is reaped, which for a lone completion waits for
the completion interrupt timer (1000 us).

Set each station's high limit per access category with
ieee80211_sta_set_aql_limits() from what the PPDU statistics show:

high = 2 x PPDU duration x charge per air time + 1000 us

and at least 2 ms, with the low limit at half of it. mac80211 caps it
at the radio's limit. The PPDU duration is the average fes_duration of
the station's PPDUs. mac80211 charges a frame from the last reported
rate and an assumed aggregate size, not from the PPDU it goes out in,
so the PPDU term is scaled by what mac80211 charged for the frames
dequeued for the station over 20 ms against the on-air time of the
station's PPDUs that started in those 20 ms. A limit is only set when
it moves by an eighth or more, and at most every 20 ms.


Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1

Signed-off-by: Julius Bairaktaris <julius@xxxxxxxxxxxxxx>
---
drivers/net/wireless/ath/ath11k/core.h | 33 +++++++
drivers/net/wireless/ath/ath11k/dp_rx.c | 125 ++++++++++++++++++++++++
drivers/net/wireless/ath/ath11k/mac.c | 10 ++
3 files changed, 168 insertions(+)

diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
index 16bea4c4d9bc9..d9643bca20668 100644
--- a/drivers/net/wireless/ath/ath11k/core.h
+++ b/drivers/net/wireless/ath/ath11k/core.h
@@ -535,6 +535,38 @@ struct ath11k_per_ppdu_tx_stats {
DECLARE_EWMA(avg_rssi, 10, 8)
/* a bitrate in 100 kbit/s, over about the last 16 PPDUs */
DECLARE_EWMA(txrate, 4, 16)
+/* over about the last 8 samples */
+DECLARE_EWMA(aql, 4, 8)
+
+/**
+ * struct ath11k_sta_aql - what sets the AQL limits of a station for an AC
+ * @charged: the airtime mac80211 charged for the frames the driver
+ * dequeued, in usec; written under ar->txq_lock of the access category,
+ * and only the difference of two reads is used, so it may wrap
+ * @ppdu_us: the on-air time of the station's PPDUs, in usec
+ * @charge_per_air: the charge per usec of the station's on-air time, in
+ * 1/1000
+ * @win_start: start of the window @charge_per_air is sampled over, in usec
+ * of the firmware's PPDU start times
+ * @win_air_us: on-air time of the PPDUs that started in the window
+ * @win_charged: @charged at the start of the window
+ * @win_on: the window has started
+ * @high_us: the high limit last set
+ * @set_jiffies: when @high_us was set
+ *
+ * All but @charged are protected by ab->base_lock.
+ */
+struct ath11k_sta_aql {
+ u32 charged;
+ struct ewma_aql ppdu_us;
+ struct ewma_aql charge_per_air;
+ u32 win_start;
+ u32 win_air_us;
+ u32 win_charged;
+ bool win_on;
+ u32 high_us;
+ unsigned long set_jiffies;
+};

struct ath11k_per_peer_cfr_capture {
enum ath11k_cfr_capture_method cfr_method;
@@ -561,6 +593,7 @@ struct ath11k_sta {
struct rate_info last_txrate;
struct ewma_txrate txrate_avg;
u8 txrate_low;
+ struct ath11k_sta_aql aql[IEEE80211_NUM_ACS];
u64 rx_duration;
u64 tx_duration;
u8 rssi_comb;
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index 2c80bd8066fed..15c40f943403a 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -1364,6 +1364,112 @@ int ath11k_dp_htt_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len,
return 0;
}

+/* The firmware keeps a station busy with this many of its PPDUs queued */
+#define ATH11K_AQL_PPDUS 2
+/* The lowest high limit set, in usec */
+#define ATH11K_AQL_MIN_US 2000
+/* charge_per_air is sampled over windows of this long */
+#define ATH11K_AQL_WINDOW_US 20000
+/* A longer window is the station going idle, and gives no sample */
+#define ATH11K_AQL_IDLE_US 100000
+/* The on-air time a window needs to give a sample */
+#define ATH11K_AQL_MIN_AIR_US 2000
+/* A smaller change of the high limit, or one this soon, is not set */
+#define ATH11K_AQL_INTERVAL_MS 20
+
+static u8 ath11k_dp_tid_to_ac(u8 tid)
+{
+ switch (tid & 7) {
+ case 1:
+ case 2:
+ return IEEE80211_AC_BK;
+ case 4:
+ case 5:
+ return IEEE80211_AC_VI;
+ case 6:
+ case 7:
+ return IEEE80211_AC_VO;
+ default:
+ return IEEE80211_AC_BE;
+ }
+}
+
+/**
+ * ath11k_dp_aql_ppdu() - derive the AQL high limit of a station from a PPDU
+ * @aql: the station's state for the access category of the PPDU
+ * @start: the PPDU's start time, in usec of the firmware's clock
+ * @air_us: the PPDU's on-air time, in usec
+ * @high_us: the high limit to set
+ *
+ * The firmware keeps a station busy while it holds about two of its PPDUs,
+ * one on the air and one being built, and mac80211 refunds the airtime of
+ * the frames on the air only once their completion is reaped, which for a
+ * lone completion waits for the TX completion interrupt timer. The high
+ * limit is that need, in the usec of mac80211's charge that AQL compares:
+ *
+ * high = ATH11K_AQL_PPDUS x ppdu_us x charge_per_air / 1000 + timer
+ *
+ * at least ATH11K_AQL_MIN_US. mac80211 charges a frame from the last
+ * reported rate and an assumed aggregate, so its charge is not the on-air
+ * time: charge_per_air is the airtime charged for the frames dequeued over
+ * a window against the on-air time of the PPDUs that started in it.
+ *
+ * Context: holds ab->base_lock.
+ *
+ * Return: true when @high_us is to be set.
+ */
+static bool ath11k_dp_aql_ppdu(struct ath11k_sta_aql *aql, u32 start,
+ u32 air_us, u32 *high_us)
+{
+ u32 charged = READ_ONCE(aql->charged);
+ unsigned long ratio;
+ u32 elapsed, want;
+ u64 sample;
+
+ ewma_aql_add(&aql->ppdu_us, air_us);
+
+ if (!aql->win_on) {
+ aql->win_on = true;
+ aql->win_start = start;
+ aql->win_air_us = air_us;
+ aql->win_charged = charged;
+ } else {
+ elapsed = start - aql->win_start;
+ if (elapsed < ATH11K_AQL_WINDOW_US) {
+ aql->win_air_us += air_us;
+ } else {
+ if (elapsed <= ATH11K_AQL_IDLE_US &&
+ aql->win_air_us >= ATH11K_AQL_MIN_AIR_US &&
+ charged != aql->win_charged) {
+ sample = (u64)(charged - aql->win_charged) * 1000;
+ sample = div_u64(sample, aql->win_air_us);
+ ewma_aql_add(&aql->charge_per_air,
+ clamp_t(u64, sample, 50, 4000));
+ }
+ aql->win_start = start;
+ aql->win_air_us = air_us;
+ aql->win_charged = charged;
+ }
+ }
+
+ ratio = ewma_aql_read(&aql->charge_per_air) ?: 1000;
+ want = ATH11K_AQL_PPDUS * ewma_aql_read(&aql->ppdu_us) * ratio / 1000 +
+ HAL_SRNG_INT_TIMER_THRESHOLD_TX;
+ want = max_t(u32, want, ATH11K_AQL_MIN_US);
+
+ if (aql->high_us &&
+ (abs_diff(want, aql->high_us) < aql->high_us / 8 ||
+ time_before(jiffies, aql->set_jiffies +
+ msecs_to_jiffies(ATH11K_AQL_INTERVAL_MS))))
+ return false;
+
+ aql->high_us = want;
+ aql->set_jiffies = jiffies;
+ *high_us = want;
+
+ return true;
+}
+
static void
ath11k_update_per_peer_tx_stats(struct ath11k *ar,
struct htt_ppdu_stats *ppdu_stats, u8 user)
@@ -1384,6 +1490,9 @@ ath11k_update_per_peer_tx_stats(struct ath11k *ar,
u8 tid = HTT_PPDU_STATS_NON_QOS_TID;
u8 airtime_tid;
bool is_ampdu = false;
+ bool aql_set = false;
+ u32 aql_high = 0;
+ u8 aql_ac = 0;

if (!(usr_stats->tlv_flags & BIT(HTT_PPDU_STATS_TAG_USR_RATE)))
return;
@@ -1511,6 +1620,18 @@ ath11k_update_per_peer_tx_stats(struct ath11k *ar,
if (tx_duration)
ieee80211_sta_register_airtime(sta, airtime_tid, tx_duration, 0);

+ /*
+ * The frames of every user of an MU PPDU are on the air for all of
+ * it, so the limit takes the whole duration.
+ */
+ if (tid < HTT_PPDU_STATS_NON_QOS_TID && common->fes_duration_us) {
+ aql_ac = ath11k_dp_tid_to_ac(tid);
+ aql_set = ath11k_dp_aql_ppdu(&arsta->aql[aql_ac],
+ common->ppdu_start_tstmp_us,
+ common->fes_duration_us,
+ &aql_high);
+ }
+
ath11k_mac_sta_report_txrate(arsta);

/* PPDU stats reported for mgmt packet doesn't have valid tx bytes.
@@ -1530,6 +1651,10 @@ ath11k_update_per_peer_tx_stats(struct ath11k *ar,
ath11k_debugfs_sta_add_tx_stats(arsta, peer_stats, rate_idx);
}

+ /* mac80211 frees the station once the peer has dropped it */
+ if (aql_set)
+ ieee80211_sta_set_aql_limits(sta, aql_ac, aql_high / 2, aql_high);
+
spin_unlock_bh(&ab->base_lock);
rcu_read_unlock();
}
diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index b7b9ebfacf3ec..f991b08a1ce14 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -10154,6 +10154,7 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq)
.sta = txq->sta,
};
struct ieee80211_hw *hw = ar->hw;
+ struct ath11k_sta_aql *aql = NULL;
struct dp_tx_ring *tx_ring;
struct hal_srng *tcl_ring;
struct sk_buff *skb;
@@ -10162,6 +10163,11 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq)
int ret;
u8 ring_id;

+ lockdep_assert_held(&ar->txq_lock[txq->ac]);
+
+ if (txq->sta)
+ aql = &ath11k_sta_to_arsta(txq->sta)->aql[txq->ac];
+
ring_selector = ar->ab->hw_params.hw_ops->get_ring_selector(txq->ac);
ring_id = ring_selector % ar->ab->hw_params.hal_params->num_tx_rings;
tx_ring = &ar->ab->dp.tx_ring[ring_id];
@@ -10197,6 +10203,10 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq)
break;
}

+ if (aql)
+ WRITE_ONCE(aql->charged, aql->charged +
+ ieee80211_info_get_tx_time_est(IEEE80211_SKB_CB(skb)));
+
ret = ath11k_mac_tx(hw, &control, skb);

spin_unlock_bh(&tx_ring->wake_tx_lock);
--
2.53.0