Skip to content

Commit 11a3969

Browse files
rado17kartben
authored andcommitted
drivers: wifi: Introduce option to use K_HEAP
Provide option to revert to K_HEAP instead of using dedicated heaps in Wi-Fi driver. Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
1 parent dfc193f commit 11a3969

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

drivers/wifi/nrf_wifi/Kconfig.nrfwifi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,21 @@ config NRF70_RSSI_STALE_TIMEOUT_MS
570570
value as the driver does not store it and requires RPU to provide the
571571
information.
572572

573+
config NRF_WIFI_GLOBAL_HEAP
574+
bool "Use Zephyr kernel heap for Wi-Fi driver"
575+
depends on KERNEL_MEM_POOL && ((HEAP_MEM_POOL_SIZE > 0) || HEAP_MEM_POOL_IGNORE_MIN)
576+
help
577+
Enable this option to use K_HEAP for memory allocations in Wi-Fi driver.
578+
579+
if NRF_WIFI_GLOBAL_HEAP
580+
config HEAP_MEM_POOL_ADD_SIZE_NRF70
581+
# Use a maximum that works for typical use cases and boards, each sample/app can override
582+
# this value if needed by using CONFIG_HEAP_MEM_POOL_IGNORE_MIN
583+
def_int 25000 if NRF70_SCAN_ONLY
584+
def_int 150000
585+
endif # NRF_WIFI_GLOBAL_HEAP
586+
587+
if !NRF_WIFI_GLOBAL_HEAP
573588
config NRF_WIFI_CTRL_HEAP_SIZE
574589
int "Dedicated memory pool for control plane"
575590
default 20000
@@ -580,6 +595,7 @@ config NRF_WIFI_DATA_HEAP_SIZE
580595
default 8000 if NRF70_SCAN_ONLY
581596
default 110000 if !SOC_FAMILY_NORDIC_NRF
582597
default 130000
598+
endif
583599

584600
if NETWORKING
585601
# Finetune defaults for certain system components used by the driver

modules/nrf_wifi/os/shim.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@
3333
#include "common/hal_structs_common.h"
3434

3535
LOG_MODULE_REGISTER(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL);
36+
37+
#if !defined(CONFIG_NRF_WIFI_GLOBAL_HEAP)
3638
#if defined(CONFIG_NOCACHE_MEMORY)
3739
K_HEAP_DEFINE_NOCACHE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CTRL_HEAP_SIZE);
3840
K_HEAP_DEFINE_NOCACHE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_SIZE);
3941
#else
4042
K_HEAP_DEFINE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CTRL_HEAP_SIZE);
4143
K_HEAP_DEFINE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_SIZE);
4244
#endif /* CONFIG_NOCACHE_MEMORY */
45+
#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
46+
4347
#define WORD_SIZE 4
4448

4549
struct zep_shim_intr_priv *intr_priv;
@@ -48,14 +52,22 @@ static void *zep_shim_mem_alloc(size_t size)
4852
{
4953
size_t size_aligned = ROUND_UP(size, 4);
5054

55+
#if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP)
56+
return k_malloc(size_aligned);
57+
#else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
5158
return k_heap_aligned_alloc(&wifi_drv_ctrl_mem_pool, WORD_SIZE, size_aligned, K_FOREVER);
59+
#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
5260
}
5361

5462
static void *zep_shim_data_mem_alloc(size_t size)
5563
{
5664
size_t size_aligned = ROUND_UP(size, 4);
5765

66+
#if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP)
67+
return k_malloc(size_aligned);
68+
#else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
5869
return k_heap_aligned_alloc(&wifi_drv_data_mem_pool, WORD_SIZE, size_aligned, K_FOREVER);
70+
#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
5971
}
6072

6173
static void *zep_shim_mem_zalloc(size_t size)
@@ -99,14 +111,22 @@ static void *zep_shim_data_mem_zalloc(size_t size)
99111
static void zep_shim_mem_free(void *buf)
100112
{
101113
if (buf) {
114+
#if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP)
115+
k_free(buf);
116+
#else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
102117
k_heap_free(&wifi_drv_ctrl_mem_pool, buf);
118+
#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
103119
}
104120
}
105121

106122
static void zep_shim_data_mem_free(void *buf)
107123
{
108124
if (buf) {
125+
#if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP)
126+
k_free(buf);
127+
#else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
109128
k_heap_free(&wifi_drv_data_mem_pool, buf);
129+
#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
110130
}
111131
}
112132

@@ -197,7 +217,11 @@ static void *zep_shim_spinlock_alloc(void)
197217

198218
static void zep_shim_spinlock_free(void *lock)
199219
{
220+
#if defined(CONFIG_NRF_WIFI_GLOBAL_HEAP)
221+
k_free(lock);
222+
#else /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
200223
k_heap_free(&wifi_drv_ctrl_mem_pool, lock);
224+
#endif /* CONFIG_NRF_WIFI_GLOBAL_HEAP */
201225
}
202226

203227
static void zep_shim_spinlock_init(void *lock)

0 commit comments

Comments
 (0)