Skip to content

Commit a1c5517

Browse files
committed
drivers: wifi: nrf71: Wait for IPC endpoint bind with timeout
Block in wifi_ipc_busyq_register() until the bound callback runs or CONFIG_NRF71_IPC_BIND_TIMEOUT_MS expires. Downgrade transient not-ready send errors to LOG_DBG once registration is expected to succeed. Assisted-by: Cursor:Auto Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
1 parent b534fb5 commit a1c5517

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

drivers/wifi/nrf71/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ config IPC_SERVICE_BACKEND_ICMSG
2929
config IPC_SERVICE_BACKEND_ICMSG_WQ_STACK_SIZE
3030
default 5600
3131

32+
config NRF71_IPC_BIND_TIMEOUT_MS
33+
int "IPC endpoint bind timeout (ms)"
34+
default 30000
35+
help
36+
Maximum time to wait for the IPC endpoint bound callback after
37+
registration. The Wi-Fi UMAC peer must register its endpoint before
38+
bind completes. On timeout ipc_register_rx_cb() fails.
39+
40+
config NRF71_IPC_SEND_TIMEOUT_MS
41+
int "IPC host TX send timeout (ms)"
42+
default 5000
43+
help
44+
Maximum time to wait for a transient IPC busy condition when sending
45+
a command or TX buffer after the endpoint is bound. On timeout
46+
ipc_send() returns -ETIMEDOUT.
47+
48+
config NRF71_IPC_SEND_RETRY_INTERVAL_US
49+
int "IPC host TX retry interval (us)"
50+
default 100
51+
help
52+
Delay between retries when the IPC busy queue is not ready.
53+
3254
choice NRF71_OPER_MODES
3355
bool "nRF70 operating modes"
3456
default NRF71_SYSTEM_MODE if !WIFI_USAGE_MODE_SCAN_ONLY

drivers/wifi/nrf71/bus/ipc_service.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,46 @@
88
* @brief IPC service layer of the nRF71 Wi-Fi driver.
99
*/
1010

11+
#include <errno.h>
12+
1113
#include <zephyr/kernel.h>
1214
#include <zephyr/logging/log.h>
1315

1416
LOG_MODULE_DECLARE(wifi_nrf, CONFIG_WIFI_NRF71_LOG_LEVEL);
1517

1618
#include "ipc_service.h"
1719

20+
static K_SEM_DEFINE(wifi_ipc_bind_sem, 0, 1);
21+
22+
static void wifi_ipc_signal_bound(void)
23+
{
24+
k_sem_give(&wifi_ipc_bind_sem);
25+
}
26+
27+
static int wifi_ipc_wait_bound(wifi_ipc_t *context)
28+
{
29+
if (context->busy_q.ipc_ready) {
30+
return 0;
31+
}
32+
33+
if (k_sem_take(&wifi_ipc_bind_sem,
34+
K_MSEC(CONFIG_NRF71_IPC_BIND_TIMEOUT_MS)) != 0 &&
35+
!context->busy_q.ipc_ready) {
36+
LOG_ERR("IPC endpoint not bound after %d ms (Wi-Fi core up? "
37+
"CONFIG_SOC_NRF71_WIFI_BOOT=y for TF-M builds)",
38+
CONFIG_NRF71_IPC_BIND_TIMEOUT_MS);
39+
return -ETIMEDOUT;
40+
}
41+
42+
return 0;
43+
}
44+
1845
static void wifi_ipc_ep_bound(void *priv)
1946
{
2047
wifi_ipc_t *context = (wifi_ipc_t *)priv;
2148

2249
context->busy_q.ipc_ready = true;
50+
wifi_ipc_signal_bound();
2351
}
2452

2553
/* For single-endpoint TX+RX bind: set both contexts ready when endpoint is bound */
@@ -33,6 +61,7 @@ static void wifi_ipc_ep_bound_tx_rx(void *priv)
3361
if (wifi_ipc_rx_ctx_shared != NULL) {
3462
wifi_ipc_rx_ctx_shared->busy_q.ipc_ready = true;
3563
}
64+
wifi_ipc_signal_bound();
3665
}
3766

3867
static void wifi_ipc_recv_callback(const void *data, size_t len, void *priv)
@@ -66,6 +95,8 @@ static wifi_ipc_status_t wifi_ipc_busyq_register(wifi_ipc_t *context)
6695
int ret;
6796
const struct device *ipc_instance = GET_IPC_INSTANCE(context->busy_q.ipc_inst);
6897

98+
k_sem_reset(&wifi_ipc_bind_sem);
99+
69100
ret = ipc_service_open_instance(ipc_instance);
70101
if (ret < 0) {
71102
return WIFI_IPC_STATUS_INIT_ERR;
@@ -80,6 +111,10 @@ static wifi_ipc_status_t wifi_ipc_busyq_register(wifi_ipc_t *context)
80111
return WIFI_IPC_STATUS_INIT_ERR;
81112
}
82113

114+
if (wifi_ipc_wait_bound(context) != 0) {
115+
return WIFI_IPC_STATUS_INIT_ERR;
116+
}
117+
83118
LOG_INF("IPC busy queue registered");
84119

85120
return WIFI_IPC_STATUS_OK;
@@ -103,6 +138,7 @@ wifi_ipc_status_t wifi_ipc_bind_ipc_service_tx_rx(wifi_ipc_t *tx_context,
103138
{
104139
wifi_ipc_status_t ret;
105140

141+
wifi_ipc_busyq_init(&rx_context->busy_q, ipc_inst, NULL, priv);
106142
wifi_ipc_rx_ctx_shared = rx_context;
107143
wifi_ipc_busyq_init(&tx_context->busy_q, ipc_inst, rx_cb, priv);
108144
tx_context->busy_q.ipc_ep_cfg.cb.bound = wifi_ipc_ep_bound_tx_rx;
@@ -119,7 +155,7 @@ static wifi_ipc_status_t wifi_ipc_busyq_send(wifi_ipc_t *context, const void *da
119155
wifi_ipc_busyq_t *busyq = &context->busy_q;
120156

121157
if (!busyq->ipc_ready) {
122-
LOG_ERR("IPC service is not ready");
158+
LOG_DBG("IPC service is not ready");
123159
return WIFI_IPC_STATUS_BUSYQ_NOTREADY;
124160
}
125161

0 commit comments

Comments
 (0)