Skip to content

Commit c8a0df4

Browse files
committed
Race free sleep design
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
1 parent e269670 commit c8a0df4

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

hw_if/hal/src/common/hal_api_common.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ enum nrf_wifi_status hal_rpu_ps_wake(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx)
5959
if (!hal_dev_ctx->rpu_fw_booted)
6060
return NRF_WIFI_STATUS_SUCCESS;
6161

62+
/* Cancel any pending sleep timer to prevent it from firing
63+
* during the wake operation or subsequent register/memory access.
64+
* The timer will be rescheduled at the end of this function.
65+
*/
66+
nrf_wifi_osal_timer_kill(hal_dev_ctx->rpu_ps_timer);
67+
6268
if (hal_dev_ctx->rpu_ps_state == RPU_PS_STATE_AWAKE) {
6369
status = NRF_WIFI_STATUS_SUCCESS;
6470

@@ -121,9 +127,10 @@ enum nrf_wifi_status hal_rpu_ps_wake(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx)
121127
#endif /* NRF_WIFI_RPU_RECOVERY_PS_STATE_DEBUG */
122128

123129
out:
124-
125-
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
126-
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
130+
/* Note: Timer scheduling is done by the caller after releasing
131+
* the lock to prevent the timer from firing during subsequent
132+
* operations (register/memory reads/writes).
133+
*/
127134
return status;
128135
}
129136

hw_if/hal/src/common/hal_mem.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ static enum nrf_wifi_status rpu_mem_read_ram(struct nrf_wifi_hal_dev_ctx *hal_de
118118
out:
119119
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
120120
&flags);
121+
122+
/* Schedule sleep timer after releasing the lock to prevent
123+
* it from firing during the critical section.
124+
*/
125+
if (status == NRF_WIFI_STATUS_SUCCESS) {
126+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
127+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
128+
}
121129
#endif /* NRF_WIFI_LOW_POWER */
122130

123131
return status;
@@ -169,6 +177,14 @@ static enum nrf_wifi_status rpu_mem_write_ram(struct nrf_wifi_hal_dev_ctx *hal_d
169177
out:
170178
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
171179
&flags);
180+
181+
/* Schedule sleep timer after releasing the lock to prevent
182+
* it from firing during the critical section.
183+
*/
184+
if (status == NRF_WIFI_STATUS_SUCCESS) {
185+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
186+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
187+
}
172188
#endif /* NRF_WIFI_LOW_POWER */
173189

174190
return status;

hw_if/hal/src/common/hal_reg.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ enum nrf_wifi_status hal_rpu_reg_read(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx,
9191
#ifdef NRF_WIFI_LOW_POWER
9292
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
9393
&flags);
94+
95+
/* Schedule sleep timer after releasing the lock to prevent
96+
* it from firing during the critical section.
97+
*/
98+
if (status == NRF_WIFI_STATUS_SUCCESS) {
99+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
100+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
101+
}
94102
#endif /* NRF_WIFI_LOW_POWER */
95103

96104
return status;
@@ -151,6 +159,14 @@ enum nrf_wifi_status hal_rpu_reg_write(struct nrf_wifi_hal_dev_ctx *hal_dev_ctx,
151159
out:
152160
nrf_wifi_osal_spinlock_irq_rel(hal_dev_ctx->rpu_ps_lock,
153161
&flags);
162+
163+
/* Schedule sleep timer after releasing the lock to prevent
164+
* it from firing during the critical section.
165+
*/
166+
if (status == NRF_WIFI_STATUS_SUCCESS) {
167+
nrf_wifi_osal_timer_schedule(hal_dev_ctx->rpu_ps_timer,
168+
NRF70_RPU_PS_IDLE_TIMEOUT_MS);
169+
}
154170
#endif /* NRF_WIFI_LOW_POWER */
155171

156172
return status;

0 commit comments

Comments
 (0)