Skip to content

Commit

Permalink
drivers: wifi: Use mutex for spinlock
Browse files Browse the repository at this point in the history
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 <Chaitanya.Tata@nordicsemi.no>
  • Loading branch information
krish2718 committed Sep 6, 2024
1 parent 8a2d7d3 commit 1e7c1d1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/wifi/nrf700x/zephyr/src/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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)
Expand Down

0 comments on commit 1e7c1d1

Please sign in to comment.