From 6ed11d60010e2960ea47d732b1ec790bd2190b11 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 5 Sep 2024 01:44:40 +0530 Subject: [PATCH] drivers: wifi: Use mutex for spinlock Ideally we should be using Zephyr spinlock APIs but that requires changes to shim API, so, for this maintenance release just replace with mutex to keep the context same and no API changes. This solves the locking issue that we see when control and data path are excited concurrently due to locking semantics of semaphores, the issue is not root caused but mutex enforce strict locking semantics for multiple threads and solve the issue. Signed-off-by: Chaitanya Tata --- drivers/wifi/nrf700x/zephyr/src/shim.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/wifi/nrf700x/zephyr/src/shim.c b/drivers/wifi/nrf700x/zephyr/src/shim.c index 5454c8be5ef3..beb1fb4a7427 100644 --- a/drivers/wifi/nrf700x/zephyr/src/shim.c +++ b/drivers/wifi/nrf700x/zephyr/src/shim.c @@ -120,7 +120,7 @@ static void zep_shim_qspi_cpy_to(void *priv, unsigned long addr, const void *src static void *zep_shim_spinlock_alloc(void) { - struct k_sem *lock = NULL; + struct k_mutex *lock = NULL; lock = k_malloc(sizeof(*lock)); @@ -138,27 +138,29 @@ static void zep_shim_spinlock_free(void *lock) static void zep_shim_spinlock_init(void *lock) { - k_sem_init(lock, 1, 1); + k_mutex_init(lock); } static void zep_shim_spinlock_take(void *lock) { - k_sem_take(lock, K_FOREVER); + k_mutex_lock(lock, K_FOREVER); } static void zep_shim_spinlock_rel(void *lock) { - k_sem_give(lock); + k_mutex_unlock(lock); } static void zep_shim_spinlock_irq_take(void *lock, unsigned long *flags) { - k_sem_take(lock, K_FOREVER); + ARG_UNUSED(flags); + k_mutex_lock(lock, K_FOREVER); } static void zep_shim_spinlock_irq_rel(void *lock, unsigned long *flags) { - k_sem_give(lock); + ARG_UNUSED(flags); + k_mutex_unlock(lock); } static int zep_shim_pr_dbg(const char *fmt, va_list args)