diff --git a/drivers/wifi/nrfwifi/Kconfig.nrfwifi b/drivers/wifi/nrfwifi/Kconfig.nrfwifi index cf423082b4e321..02ea7f3a268b9c 100644 --- a/drivers/wifi/nrfwifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrfwifi/Kconfig.nrfwifi @@ -541,6 +541,15 @@ config NRF70_RSSI_STALE_TIMEOUT_MS if NETWORKING # Finetune defaults for certain system components used by the driver + +config NRF_WIFI_CTRL_HEAP_SIZE + int "Dedicated memory pool for control path" + default 20480 + +config NRF_WIFI_DATA_HEAP_SIZE + int "Dedicated memory pool for data plane" + default 61440 + config SYSTEM_WORKQUEUE_STACK_SIZE default 4096 diff --git a/drivers/wifi/nrfwifi/src/shim.c b/drivers/wifi/nrfwifi/src/shim.c index 1c62d22905517b..4700ce0b818c4f 100644 --- a/drivers/wifi/nrfwifi/src/shim.c +++ b/drivers/wifi/nrfwifi/src/shim.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "rpu_hw_if.h" #include "shim.h" @@ -27,21 +28,79 @@ #include "qspi_if.h" LOG_MODULE_REGISTER(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); +#if defined(CONFIG_NOCACHE_MEMORY) +K_HEAP_DEFINE_NOCACHE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CTRL_HEAP_SIZE); +K_HEAP_DEFINE_NOCACHE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_SIZE); +#else +K_HEAP_DEFINE(wifi_drv_ctrl_mem_pool, CONFIG_NRF_WIFI_CTRL_HEAP_SIZE); +K_HEAP_DEFINE(wifi_drv_data_mem_pool, CONFIG_NRF_WIFI_DATA_HEAP_SIZE); +#endif /* CONFIG_NOCACHE_MEMORY */ +#define WORD_SIZE 4 struct zep_shim_intr_priv *intr_priv; static void *zep_shim_mem_alloc(size_t size) { - size_t size_aligned = ROUND_UP(size, 4); + size = (size + 4) & 0xfffffffc; + return k_heap_aligned_alloc(&wifi_drv_ctrl_mem_pool, WORD_SIZE, size, K_FOREVER); +} - return k_malloc(size_aligned); +static void *zep_shim_data_mem_alloc(size_t size) +{ + size = (size + 4) & 0xfffffffc; + return k_heap_aligned_alloc(&wifi_drv_data_mem_pool, WORD_SIZE, size, K_FOREVER); } static void *zep_shim_mem_zalloc(size_t size) { - size_t size_aligned = ROUND_UP(size, 4); + void *ret; + size_t bounds; + + size = (size + 4) & 0xfffffffc; + + if (size_mul_overflow(size, sizeof(char), &bounds)) { + return NULL; + } + + ret = zep_shim_mem_alloc(bounds); + if (ret != NULL) { + (void)memset(ret, 0, bounds); + } + + return ret; +} + +static void *zep_shim_data_mem_zalloc(size_t size) +{ + void *ret; + size_t bounds; + + size = (size + 4) & 0xfffffffc; + + if (size_mul_overflow(size, sizeof(char), &bounds)) { + return NULL; + } + + ret = zep_shim_data_mem_alloc(bounds); + if (ret != NULL) { + (void)memset(ret, 0, bounds); + } + + return ret; +} + +static void zep_shim_mem_free(void *buf) +{ + if (buf) { + k_heap_free(&wifi_drv_ctrl_mem_pool, buf); + } +} - return k_calloc(size_aligned, sizeof(char)); +static void zep_shim_data_mem_free(void *buf) +{ + if (buf) { + k_heap_free(&wifi_drv_data_mem_pool, buf); + } } static void *zep_shim_mem_cpy(void *dest, const void *src, size_t count) @@ -877,7 +936,9 @@ static unsigned int zep_shim_strlen(const void *str) const struct nrf_wifi_osal_ops nrf_wifi_os_zep_ops = { .mem_alloc = zep_shim_mem_alloc, .mem_zalloc = zep_shim_mem_zalloc, - .mem_free = k_free, + .data_mem_zalloc = zep_shim_data_mem_zalloc, + .mem_free = zep_shim_mem_free, + .data_mem_free = zep_shim_data_mem_free, .mem_cpy = zep_shim_mem_cpy, .mem_set = zep_shim_mem_set, .mem_cmp = zep_shim_mem_cmp, diff --git a/west.yml b/west.yml index 3dbc398e3af591..a2f6eb78809d11 100644 --- a/west.yml +++ b/west.yml @@ -188,7 +188,7 @@ manifest: groups: - hal - name: hal_nordic - revision: af7b21c4f875bea26689307daa8e52e9a8e8323c + revision: pull/213/head path: modules/hal/nordic groups: - hal