wifi: ath9k: cut USB round trips on channel changes
v3 cover wifi: ath9k: cut USB round trips on channel changes
On the ath9k_htc devices every register access is a synchronous WMI round trip, so a channel change that is cheap on PCI costs tens of milliseconds over USB. This series removes round trips from that path without changing the register values written.
Patch 1 is a fix: a multi-read that fails over USB hands the caller uninitialised stack data; make it return all ones like a single read. Patch 2 gives the 8-register limit of REG_READ_MULTI() a name and checks it. Patch 3 replaces the per-queue ath9k_hw_numtxpending() loop in ath9k_hw_channel_change() with two multi-reads and needs patch 1 so that a failed read still counts as pending. Patch 4 wraps the read-modify-write runs in ar5008_hw_set_delta_slope() and ath9k_hw_start_nfcal() in the RMW buffer. Patch 5 skips the departing channel's noise floor readout on a fast channel change over USB.
Patches 3 and 4 touch code that PCI runs too, but there the multi-read is a loop of single reads and the RMW buffer callbacks are not installed, so the register traffic is unchanged. Patch 5 is limited to ATH_USB.
Measured on an AR9271 (0cf3:9271) with a local counter of WMI commands around the driver's channel change:
WMI commands time
full reset, unpatched 182 ~92 ms
fast channel change, patches 1-5 44 ~31 ms
The second row also depends on two changes outside this series: taking the fast path on same-band retunes, which mainline does only for off-channel scan hops, and the mac80211 change that makes a monitor retune one driver channel change instead of two [1]. On mainline the reduction therefore shows up on scan hops.
Two further patches that skipped the PCU re-initialisation and the WMI_SET_MODE on a fast change were dropped before v1: the receiver stopped delivering frames, because ath9k_host_rx_init() is what clears AR_DIAG_RX_DIS and AR_DIAG_RX_ABORT. With patches 1-5 the fast path delivered 90-97% of frames injected from a second AR9271 over coax on the 2.4 GHz channels, against 95-97% for a full reset on the same build. The spread is run-to-run drift of the rig; the fast path shows it first because it does not recalibrate, which is also why mainline limits that path to scan hops.
[1] https://lore.kernel.org/linux-wireless/[email protected]/
Changes in v3:
- Move the fail-safe multi-read fix to the front of the series and Cc stable, so it can be picked on its own.
- Patch 2: report an over-long multi-read as failed (all ones) instead of returning with the buffer untouched; comment reworded.
- Patch 3: kernel-doc for ath9k_hw_first_txpending().
- Add Assisted-by, rewrite the commit messages, rebase onto ath-next.
Changes in v2:
- New fail-safe multi-read patch: ath9k_multi_regread() copies an uninitialised buffer out when the command fails. In v1 that made the queue check random on a timeout; it also affects the ANI, EEPROM and register array callers, so it is fixed separately with a Fixes tag.
- Queue check: comment on why a failed read is safe.
- Other patches unchanged.
Nerijus Bendžiūnas (5):
wifi: ath9k_htc: report a failed multi-read as all ones
wifi: ath9k: name the register multi-read limit
wifi: ath9k: check all tx queues with one multi-read
wifi: ath9k: batch the read-modify-writes of a channel change
wifi: ath9k: skip the old channel's noise floor on USB fast changes
drivers/net/wireless/ath/ath9k/ar5008_phy.c | 2 + drivers/net/wireless/ath/ath9k/calib.c | 2 + drivers/net/wireless/ath/ath9k/htc_drv_init.c | 12 +++++- drivers/net/wireless/ath/ath9k/hw.c | 21 ++++++---- drivers/net/wireless/ath/ath9k/hw.h | 7 ++++ drivers/net/wireless/ath/ath9k/mac.c | 40 +++++++++++++++++++ drivers/net/wireless/ath/ath9k/mac.h | 1 + 7 files changed, 75 insertions(+), 10 deletions(-)
base-commit: 1d8e73163ef933624341075f576e2f36ef9133f7
Signature · 1 line
2.55.0
PATCH v3 1/5 wifi: ath9k_htc: report a failed multi-read as all ones
When the WMI command fails or times out, ath9k_multi_regread() logs the failure and still copies its result buffer to the caller, so the caller receives uninitialised stack data for every register it asked for. ath9k_hw_update_mibstats(), ath9k_hw_usb_gen_fill_eeprom() and ath9k_hw_read_array() all read through this path. ath9k_regread() reports the same failure as -1.
Fill the caller's buffer with all ones instead, so a failed multi-read looks like a failed single read. ath9k_hw_first_txpending(), added later in this series, relies on this: a timed-out tx queue status read must count as frames pending.
--- drivers/net/wireless/ath/ath9k/htc_drv_init.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/ath9k/htc_drv_init.c +3 -0
@@ -273,6 +273,9 @@ static void ath9k_multi_regread(void *hw_priv, u32 *addr,if (unlikely (ret)) {ath_dbg (common,WMI ,"Multiple REGISTER READ FAILED (count: %d)\n" , count); +/* Callers expect what a failed single read returns. */ +memset (val,0xff ,sizeof (*val) * count); +return ; }for (i =0 ; i < count; i++) {
Signature · 1 line
2.55.0
PATCH v3 2/5 wifi: ath9k: name the register multi-read limit
In reply to Nerijus Bendžiūnasath9k_multi_regread() converts the addresses and the results through fixed 8-entry arrays and does not check the count it is given, so every REG_READ_MULTI() caller has to stay at 8 or below, which nothing states. Two callers ask for exactly 8: ar9271_hw_pa_cal() through REG_READ_ARRAY() and ath9k_hw_usb_gen_fill_eeprom().
Define ATH9K_MULTI_READ_MAX next to REG_READ_MULTI() and size the arrays with it. A larger count warns once and is reported as a failed read, all ones, instead of writing past the arrays.
--- drivers/net/wireless/ath/ath9k/htc_drv_init.c | 9 +++++++-- drivers/net/wireless/ath/ath9k/hw.h | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath9k/htc_drv_init.c +7 -2
@@ -258,10 +258,15 @@ static void ath9k_multi_regread(void *hw_priv, u32 *addr,struct ath_hw *ah = hw_priv;struct ath_common *common =ath9k_hw_common (ah);struct ath9k_htc_priv *priv = common->priv; -__be32 tmpaddr[8 ]; -__be32 tmpval[8 ]; +__be32 tmpaddr[ATH9K_MULTI_READ_MAX ]; +__be32 tmpval[ATH9K_MULTI_READ_MAX ];int i, ret; +if (WARN_ON_ONCE (count >ATH9K_MULTI_READ_MAX )) { +memset (val,0xff ,sizeof (*val) * count); +return ; + } +for (i =0 ; i < count; i++) { tmpaddr[i] =cpu_to_be32 (addr[i]); }
drivers/net/wireless/ath/ath9k/hw.h +7 -0
@@ -83,6 +83,13 @@#define REG_READ (_ah, _reg) \ (_ah)->reg_ops.read((_ah), (_reg)) +/* +* Maximum number of registers one REG_READ_MULTI() may ask for. The ath9k_htc +* implementation converts the addresses and the results through fixed arrays +* of this size; callers must split larger reads themselves. +*/ +#define ATH9K_MULTI_READ_MAX 8 +#define REG_READ_MULTI (_ah, _addr, _val, _cnt) \ (_ah)->reg_ops.multi_read((_ah), (_addr), (_val), (_cnt))
Signature · 1 line
2.55.0
PATCH v3 3/5 wifi: ath9k: check all tx queues with one multi-read
In reply to Nerijus BendžiūnasBefore a channel change, ath9k_hw_channel_change() calls ath9k_hw_numtxpending() for each of the 10 queues. Each call reads AR_QSTS and then AR_Q_TXE, so confirming that the radio has drained takes up to 20 register reads. On the USB devices each read is a synchronous WMI round trip, paid on every channel change before tuning starts.
Add ath9k_hw_first_txpending(), which collects the 10 queue status registers and AR_Q_TXE with REG_READ_MULTI() and applies the same pending test. Use it in ath9k_hw_channel_change(). On PCI the multi-read is a loop of single reads, so the register traffic there is unchanged.
A multi-read that fails over USB returns all ones, which counts as pending, so a lost read still fails the fast channel change and the caller falls back to a full reset.
--- drivers/net/wireless/ath/ath9k/hw.c | 13 +++++---- drivers/net/wireless/ath/ath9k/mac.c | 40 ++++++++++++++++++++++++++++ drivers/net/wireless/ath/ath9k/mac.h | 1 + 3 files changed, 47 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath9k/hw.c +6 -7
@@ -1547,7 +1547,7 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,struct ath9k_hw_capabilities *pCap = &ah->caps;bool band_switch = false, mode_diff = false;u8 ini_reloaded =0 ; -u32 qnum; +int qnum;int r;if (pCap->hw_caps &ATH9K_HW_CAP_FCC_BAND_SWITCH ) {
@@ -1556,12 +1556,11 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah, mode_diff = !!(flags_diff & ~CHANNEL_HT ); } -for (qnum =0 ; qnum <AR_NUM_QCU ; qnum++) { -if (ath9k_hw_numtxpending (ah, qnum)) { -ath_dbg (common,QUEUE , -"Transmit frames pending on queue %d\n" , qnum); -return false; - } + qnum =ath9k_hw_first_txpending (ah); +if (qnum >=0 ) { +ath_dbg (common,QUEUE , +"Transmit frames pending on queue %d\n" , qnum); +return false; }if (!ath9k_hw_rfbus_req (ah)) {
drivers/net/wireless/ath/ath9k/mac.c +40 -0
@@ -77,6 +77,46 @@ u32 ath9k_hw_numtxpending(struct ath_hw *ah, u32 q) }EXPORT_SYMBOL (ath9k_hw_numtxpending); +/** +* ath9k_hw_first_txpending - find a tx queue that still has frames pending +* @ah: hardware +* +* Asking ath9k_hw_numtxpending() about each queue in turn costs up to two +* register reads per queue, and on the USB devices every one of those is a +* synchronous WMI round trip. Collect the queue status registers and AR_Q_TXE +* with the multi-read op instead, in chunks of ATH9K_MULTI_READ_MAX. A +* multi-read that fails over USB reads as all ones, which counts as pending, +* so a WMI timeout still refuses the fast channel change. +* +* Return: the first queue with frames pending, or -1 if all are drained. +*/ +int ath9k_hw_first_txpending (struct ath_hw *ah) +{ +u32 addr[AR_NUM_QCU +1 ]; +u32 val[AR_NUM_QCU +1 ]; +u32 q, txe, done =0 ; + +for (q =0 ; q <AR_NUM_QCU ; q++) + addr[q] =AR_QSTS (q); + addr[AR_NUM_QCU ] =AR_Q_TXE ; + +while (done <ARRAY_SIZE (addr)) { +u32 count =min_t (u32,ARRAY_SIZE (addr) - done, +ATH9K_MULTI_READ_MAX ); + +REG_READ_MULTI (ah, addr + done, val + done, count); + done += count; + } + + txe = val[AR_NUM_QCU ]; +for (q =0 ; q <AR_NUM_QCU ; q++) { +if ((val[q] &AR_Q_STS_PEND_FR_CNT ) || (txe &BIT (q))) +return q; + } + +return -1 ; +} +/** * ath9k_hw_updatetxtriglevel - adjusts the frame trigger level *
drivers/net/wireless/ath/ath9k/mac.h +1 -0
@@ -721,6 +721,7 @@ u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q);void ath9k_hw_puttxbuf (struct ath_hw *ah,u32 q,u32 txdp);void ath9k_hw_txstart (struct ath_hw *ah,u32 q);u32 ath9k_hw_numtxpending (struct ath_hw *ah,u32 q); +int ath9k_hw_first_txpending (struct ath_hw *ah);bool ath9k_hw_updatetxtriglevel (struct ath_hw *ah,bool bIncTrigLevel);bool ath9k_hw_stop_dma_queue (struct ath_hw *ah,u32 q);void ath9k_hw_abort_tx_dma (struct ath_hw *ah);
Signature · 1 line
2.55.0
PATCH v3 4/5 wifi: ath9k: batch the read-modify-writes of a channel change
In reply to Nerijus Bendžiūnasar5008_hw_set_delta_slope() and ath9k_hw_start_nfcal() each issue a run of read-modify-writes with no register read in between. Both run on every channel change, and on the USB devices each REG_RMW is a separate WMI command.
Wrap both runs in ENABLE_REG_RMW_BUFFER() and REG_RMW_BUFFER_FLUSH() so the USB transport sends each run as one command. PCI does not install the buffer callbacks, so the macros do nothing there and the writes are issued as before. The same holds for USB devices with firmware older than 1.4, which have no WMI_REG_RMW_CMDID. ar5008_hw_set_delta_slope() is the AR5008 and AR9002 callback; AR9003 has its own and is not touched.
--- drivers/net/wireless/ath/ath9k/ar5008_phy.c | 2 ++ drivers/net/wireless/ath/ath9k/calib.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/net/wireless/ath/ath9k/ar5008_phy.c +2 -0
@@ -868,6 +868,7 @@ static void ar5008_hw_set_delta_slope(struct ath_hw *ah,ath9k_hw_get_delta_slope_vals (ah, coef_scaled, &ds_coef_man, &ds_coef_exp); +ENABLE_REG_RMW_BUFFER (ah);REG_RMW_FIELD (ah,AR_PHY_TIMING3 ,AR_PHY_TIMING3_DSC_MAN , ds_coef_man); REG_RMW_FIELD(ah, AR_PHY_TIMING3,
@@ -882,6 +883,7 @@ static void ar5008_hw_set_delta_slope(struct ath_hw *ah, AR_PHY_HALFGI_DSC_MAN, ds_coef_man);REG_RMW_FIELD (ah,AR_PHY_HALFGI ,AR_PHY_HALFGI_DSC_EXP , ds_coef_exp); +REG_RMW_BUFFER_FLUSH (ah); }static bool ar5008_hw_rfbus_req (struct ath_hw *ah)
drivers/net/wireless/ath/ath9k/calib.c +2 -0
@@ -224,6 +224,7 @@ void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update)if (ah->caldata)set_bit (NFCAL_PENDING , &ah->caldata->cal_flags); +ENABLE_REG_RMW_BUFFER (ah);REG_SET_BIT (ah,AR_PHY_AGC_CONTROL (ah),AR_PHY_AGC_CONTROL_ENABLE_NF );
@@ -235,6 +236,7 @@ void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update) AR_PHY_AGC_CONTROL_NO_UPDATE_NF);REG_SET_BIT (ah,AR_PHY_AGC_CONTROL (ah),AR_PHY_AGC_CONTROL_NF ); +REG_RMW_BUFFER_FLUSH (ah); }int ath9k_hw_loadnf (struct ath_hw *ah,struct ath9k_channel *chan)
Signature · 1 line
2.55.0
PATCH v3 5/5 wifi: ath9k: skip the old channel's noise floor on USB fast changes
In reply to Nerijus Bendžiūnasath9k_hw_reset() reads the noise floor of the channel it is leaving to keep that channel's calibration history current. On a single-chain AR9271 that is three register reads, and on the USB devices each one is a synchronous WMI round trip paid on every channel change.
Skip the readout on a fast channel change over USB. The arriving channel's noise floor is loaded as before, and periodic calibration updates the history while a channel is in use. Only a channel that is left and revisited without a calibration in between sees an older history entry.
--- drivers/net/wireless/ath/ath9k/hw.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/hw.c +7 -1
@@ -1878,7 +1878,13 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,if (!ath9k_hw_setpower (ah,ATH9K_PM_AWAKE ))return -EIO ; -if (ah->curchan && !ah->chip_fullsleep) +/* +* Over USB the departing channel's noise-floor readout costs several +* round trips and only feeds its history; the fast path reloads the +* arriving channel's noise floor regardless. +*/ +if (ah->curchan && !ah->chip_fullsleep && + !(fastcc && common->bus_ops->ath_bus_type ==ATH_USB ))ath9k_hw_getnf (ah, ah->curchan); ah->caldata = caldata;
Signature · 1 line
2.55.0