[PATCH ath-next v3 03/13] wifi: ath11k: keep the srng allocations when a firmware recovery fails

From: Julius Bairaktaris

Date: Sat Nov 21 2026 - 18:07:54 EST


Since commit 32be3ca4cf78 ("wifi: ath11k: HAL SRNG: don't deinitialize
and re-initialize again") recovery zeroes the hal state instead of
freeing and reallocating it, but a failed recovery still calls
ath11k_hal_srng_deinit(). This frees the ring pointer buffers and the
ring configuration, which only probe allocates, while the rings still
point into them. Driver removal then walks the copy engine rings through
the freed buffers:

ath11k c000000.wifi: failed to reconfigure driver on crash recovery
...
Unable to handle kernel paging request at virtual address
ffffffc080ee5090
pc : ath11k_hal_srng_access_begin+0xc/0x60 [ath11k]
Call trace:
ath11k_hal_srng_access_begin+0xc/0x60 [ath11k] (P)
ath11k_ce_cleanup_pipes+0x16c/0x4cc [ath11k]
ath11k_ahb_stop+0x2c/0x3c [ath11k_ahb]
ath11k_core_deinit+0xec/0x168 [ath11k]
ath11k_ahb_remove+0x30/0x90 [ath11k_ahb]

Return the error and keep the allocations for ath11k_ahb_remove() and
ath11k_pci_remove() to free.

A recovery that fails before ath11k_ce_init_pipes() rebuilds the rings
leaves them as ath11k_hal_srng_clear() zeroed them, lock included, and
the same walk then reads the NULL tail pointer in
ath11k_ce_completed_send_next(), at removal or in the next recovery.
Nothing in dev_flags tells such a recovery from one that failed after
the rings were rebuilt. Set ATH11K_FLAG_CE_RINGS_SETUP once
ath11k_ce_init_pipes() has set the rings up, clear it where
ath11k_hal_srng_clear() zeroes them, and let ath11k_ce_cleanup_pipes(),
which every copy engine teardown goes through, return while it is clear.

The rx_replenish_retry timer posts buffers to the copy engine rings and
ath11k_core_reconfigure_on_crash() does not stop it, so it can fire on
the zeroed rings too. Stop it before the copy engine cleanup, as
ath11k_ahb_stop() does. Also test ATH11K_FLAG_CRASH_FLUSH in
ath11k_ce_send() before it reaps a ring rather than after.

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

Fixes: 32be3ca4cf78 ("wifi: ath11k: HAL SRNG: don't deinitialize and re-initialize again")
Signed-off-by: Julius Bairaktaris <julius@xxxxxxxxxxxxxx>
---
v3: record whether the CE rings are set up in ATH11K_FLAG_CE_RINGS_SETUP and
let ath11k_ce_cleanup_pipes() return while it is clear, instead of testing HAL
srng fields in the CE layer (Baochen Qiang, v1); stop rx_replenish_retry before
the CE cleanup; test CRASH_FLUSH in ath11k_ce_send() before reaping.

drivers/net/wireless/ath/ath11k/ce.c | 9 ++++++---
drivers/net/wireless/ath/ath11k/core.c | 10 +++++-----
drivers/net/wireless/ath/ath11k/core.h | 1 +
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/ce.c b/drivers/net/wireless/ath/ath11k/ce.c
index 1e08b0970b14..af08a2a24c6d 100644
--- a/drivers/net/wireless/ath/ath11k/ce.c
+++ b/drivers/net/wireless/ath/ath11k/ce.c
@@ -718,6 +718,9 @@ int ath11k_ce_send(struct ath11k_base *ab, struct sk_buff *skb, u8 pipe_id,
u8 byte_swap_data = 0;
int num_used;

+ if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))
+ return -ESHUTDOWN;
+
/* Check if some entries could be regained by handling tx completion if
* the CE has interrupts disabled and the used entries is more than the
* defined usage threshold.
@@ -740,9 +743,6 @@ int ath11k_ce_send(struct ath11k_base *ab, struct sk_buff *skb, u8 pipe_id,
ath11k_ce_poll_send_completed(ab, pipe->pipe_num);
}

- if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))
- return -ESHUTDOWN;
-
spin_lock_bh(&ab->ce.ce_lock);

write_index = pipe->src_ring->write_index;
@@ -866,6 +866,9 @@ void ath11k_ce_cleanup_pipes(struct ath11k_base *ab)
struct ath11k_ce_pipe *pipe;
int pipe_num;

+ if (!test_bit(ATH11K_FLAG_CE_RINGS_SETUP, &ab->dev_flags))
+ return;
+
ath11k_ce_stop_shadow_timers(ab);

for (pipe_num = 0; pipe_num < ab->hw_params.ce_count; pipe_num++) {
diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c
index 5f4e7fbe0b25..d6346e0ee047 100644
--- a/drivers/net/wireless/ath/ath11k/core.c
+++ b/drivers/net/wireless/ath/ath11k/core.c
@@ -2290,6 +2290,8 @@ int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab)
goto err_firmware_stop;
}

+ set_bit(ATH11K_FLAG_CE_RINGS_SETUP, &ab->dev_flags);
+
ret = ath11k_dp_alloc(ab);
if (ret) {
ath11k_err(ab, "failed to init DP: %d\n", ret);
@@ -2340,12 +2342,14 @@ static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab)
ath11k_dp_pdev_free(ab);
ath11k_cfr_deinit(ab);
ath11k_spectral_deinit(ab);
+ timer_delete_sync(&ab->rx_replenish_retry);
ath11k_ce_cleanup_pipes(ab);
ath11k_wmi_detach(ab);
ath11k_dp_pdev_reo_cleanup(ab);
mutex_unlock(&ab->core_lock);

ath11k_dp_free(ab);
+ clear_bit(ATH11K_FLAG_CE_RINGS_SETUP, &ab->dev_flags);
ath11k_hal_srng_clear(ab);

ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS(ab))) - 1;
@@ -2354,15 +2358,11 @@ static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab)

ret = ath11k_core_qmi_firmware_ready(ab);
if (ret)
- goto err_hal_srng_deinit;
+ return ret;

clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);

return 0;
-
-err_hal_srng_deinit:
- ath11k_hal_srng_deinit(ab);
- return ret;
}

void ath11k_core_halt(struct ath11k *ar)
diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
index a0d725923ef2..593e54c59737 100644
--- a/drivers/net/wireless/ath/ath11k/core.h
+++ b/drivers/net/wireless/ath/ath11k/core.h
@@ -288,6 +288,7 @@ enum ath11k_dev_flags {
ATH11K_FLAG_DEVICE_INIT_DONE,
ATH11K_FLAG_MULTI_MSI_VECTORS,
ATH11K_FLAG_FTM_SEGMENTED,
+ ATH11K_FLAG_CE_RINGS_SETUP,
};

enum ath11k_monitor_flags {
--
2.53.0