[PATCH ath-next v5 01/12] wifi: ath10k: fix SDIO aux workqueue starvation in recovery detection

From: Kang Yang

Date: Wed Dec 02 2026 - 01:09:35 EST


Recovery monitoring runs on workqueue_aux, which is also
used by SDIO RX dispatch and WMI SERVICE_READY handling.

A single firmware crash may generate multiple recovery
triggers. Recovery detection currently handles each one by
waiting for recovery completion on workqueue_aux. On SDIO,
this blocks the same workqueue needed to deliver recovery
traffic, preventing recovery from completing.

As a result, otherwise recoverable firmware crashes fail
with:
ctl_resp never came in (-110)

Treat duplicate triggers as part of the same recovery attempt. Use an
atomic compare-and-exchange on pending_recovery so only the first
trigger starts restart_work.

Convert the recovery monitor to self-rearming delayed work. While
recovery remains pending, the monitor periodically checks its state
without blocking workqueue_aux. Cancel the monitor when recovery
succeeds or the device is stopped.

The monitor is armed for every trigger, so ath10k_core_restart() must
also disarm it when the device is in ATH10K_STATE_OFF and there is
nothing to restart, for example because ath10k_start() failed after the
firmware crashed while booting. Otherwise the stale pending_recovery
blocks the next real recovery and the monitor eventually marks the
device WEDGED even though it is only not started. Clear it there, and
arm the monitor before queueing restart_work so the cancel cannot run
before the monitor is armed. This case was found by code inspection and
has not been reproduced.

Tested-on: QCA6174 hw3.2 PCI WLAN.RM.4.4.1-00288-QCARMSWPZ-1
Tested-on: QCA6174 hw3.2 SDIO WLAN.RMH.4.4.1-00189

Fixes: f35a07a4842a ("wifi: ath10k: move recovery check logic into a new work")
Signed-off-by: Kang Yang <kang.yang@xxxxxxxxxxxxxxxx>
---
drivers/net/wireless/ath/ath10k/core.c | 71 +++++++++++++++++++---------------
drivers/net/wireless/ath/ath10k/core.h | 2 +-
drivers/net/wireless/ath/ath10k/mac.c | 9 ++++-
3 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
index 2aa18adb31cc..ab461aaf5c01 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -2535,48 +2535,51 @@ static int ath10k_init_hw_params(struct ath10k *ar)

static void ath10k_core_recovery_check_work(struct work_struct *work)
{
- struct ath10k *ar = container_of(work, struct ath10k, recovery_check_work);
- long time_left;
+ struct ath10k *ar = container_of(work, struct ath10k,
+ recovery_check_work.work);
+ int fail_count;

- /* Sometimes the recovery will fail and then the next all recovery fail,
- * so avoid infinite recovery.
- */
- if (atomic_read(&ar->fail_cont_count) >= ATH10K_RECOVERY_MAX_FAIL_COUNT) {
- ath10k_err(ar, "consecutive fail %d times, will shutdown driver!",
- atomic_read(&ar->fail_cont_count));
- ar->state = ATH10K_STATE_WEDGED;
+ if (ar->state == ATH10K_STATE_WEDGED)
return;
- }

- ath10k_dbg(ar, ATH10K_DBG_BOOT, "total recovery count: %d", ++ar->recovery_count);
-
- if (atomic_read(&ar->pending_recovery)) {
- /* Sometimes it happened another recovery work before the previous one
- * completed, then the second recovery work will destroy the previous
- * one, thus below is to avoid that.
- */
- time_left = wait_for_completion_timeout(&ar->driver_recovery,
- ATH10K_RECOVERY_TIMEOUT_HZ);
- if (time_left) {
- ath10k_warn(ar, "previous recovery succeeded, skip this!\n");
- return;
- }
+ /*
+ * Pure monitor: only ath10k_core_start_recovery() starts a fresh
+ * cycle. Bail if there is nothing in flight.
+ */
+ if (!atomic_read(&ar->pending_recovery))
+ return;

- /* Record the continuous recovery fail count when recovery failed. */
- atomic_inc(&ar->fail_cont_count);
+ /* Record the continuous recovery fail count when recovery is late. */
+ fail_count = atomic_inc_return(&ar->fail_cont_count);

- /* Avoid having multiple recoveries at the same time. */
+ if (fail_count >= ATH10K_RECOVERY_MAX_FAIL_COUNT) {
+ ath10k_err(ar, "consecutive fail %d times, will shutdown driver!",
+ fail_count);
+ ar->state = ATH10K_STATE_WEDGED;
return;
}

- atomic_inc(&ar->pending_recovery);
- queue_work(ar->workqueue, &ar->restart_work);
+ /* Recovery still in flight; check again later. */
+ queue_delayed_work(ar->workqueue_aux, &ar->recovery_check_work,
+ ATH10K_RECOVERY_TIMEOUT_HZ);
}

void ath10k_core_start_recovery(struct ath10k *ar)
{
- /* Use workqueue_aux to avoid blocking recovery tracking */
- queue_work(ar->workqueue_aux, &ar->recovery_check_work);
+ if (ar->state == ATH10K_STATE_WEDGED)
+ return;
+
+ /* SDIO raises several triggers per crash; only the first one wins. */
+ if (atomic_cmpxchg(&ar->pending_recovery, 0, 1) != 0)
+ return;
+ ath10k_dbg(ar, ATH10K_DBG_BOOT, "total recovery count: %d",
+ ++ar->recovery_count);
+ /* Start a fresh failure budget; the last cycle may not have completed. */
+ atomic_set(&ar->fail_cont_count, 0);
+ /* Arm the monitor first; restart_work may cancel it. */
+ queue_delayed_work(ar->workqueue_aux, &ar->recovery_check_work,
+ ATH10K_RECOVERY_TIMEOUT_HZ);
+ queue_work(ar->workqueue, &ar->restart_work);
}
EXPORT_SYMBOL(ath10k_core_start_recovery);

@@ -2655,6 +2658,9 @@ static void ath10k_core_restart(struct work_struct *work)
* or if the crash happens during FW probing
*/
ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
+ /* Nothing to restart; drop the stale pending_recovery. */
+ cancel_delayed_work(&ar->recovery_check_work);
+ atomic_set(&ar->pending_recovery, 0);
break;
case ATH10K_STATE_RESTARTING:
/* hw restart might be requested from multiple places */
@@ -3769,7 +3775,7 @@ struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,

INIT_WORK(&ar->register_work, ath10k_core_register_work);
INIT_WORK(&ar->restart_work, ath10k_core_restart);
- INIT_WORK(&ar->recovery_check_work, ath10k_core_recovery_check_work);
+ INIT_DELAYED_WORK(&ar->recovery_check_work, ath10k_core_recovery_check_work);
INIT_WORK(&ar->set_coverage_class_work,
ath10k_core_set_coverage_class_work);

@@ -3806,6 +3812,9 @@ EXPORT_SYMBOL(ath10k_core_create);

void ath10k_core_destroy(struct ath10k *ar)
{
+ cancel_work_sync(&ar->restart_work);
+ cancel_delayed_work_sync(&ar->recovery_check_work);
+
destroy_workqueue(ar->workqueue);

destroy_workqueue(ar->workqueue_aux);
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index dfee432615eb..e8fcbef38ca6 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -1207,7 +1207,7 @@ struct ath10k {

struct work_struct register_work;
struct work_struct restart_work;
- struct work_struct recovery_check_work;
+ struct delayed_work recovery_check_work;
struct work_struct bundle_tx_work;
struct work_struct tx_complete_work;

diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index 8e604697d6c2..c224d3db10f6 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -5427,7 +5427,11 @@ static void ath10k_stop(struct ieee80211_hw *hw, bool suspend)
cancel_work_sync(&ar->set_coverage_class_work);
cancel_delayed_work_sync(&ar->scan.timeout);
cancel_work_sync(&ar->restart_work);
- cancel_work_sync(&ar->recovery_check_work);
+ cancel_delayed_work_sync(&ar->recovery_check_work);
+
+ /* Works are cancelled; clear stale recovery state for next start. */
+ atomic_set(&ar->fail_cont_count, 0);
+ atomic_set(&ar->pending_recovery, 0);
}

static int ath10k_config_ps(struct ath10k *ar)
@@ -8170,6 +8174,9 @@ static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
ar->state = ATH10K_STATE_ON;
ieee80211_wake_queues(ar->hw);

+ /* Cancel the monitor first so it cannot bump the count after reset. */
+ cancel_delayed_work_sync(&ar->recovery_check_work);
+
/* Clear recovery state. */
complete(&ar->driver_recovery);
atomic_set(&ar->fail_cont_count, 0);

--
2.34.1