Skip to content

Commit

Permalink
drivers: wifi: Create dedicated mem pool for Wi-Fi driver
Browse files Browse the repository at this point in the history
Create dedicated memory pools for Wi-Fi management and
data operations (defaults: 20KB for management and 130KB for data).

Remove the `HEAP_MEM_POOL_ADD_SIZE_NRF70` hint since we are
creating separate heaps for driver and not allocating from
system heap.

Signed-off-by: Ravi Dondaputi <[email protected]>
  • Loading branch information
rado17 committed Jan 23, 2025
1 parent 763e6a8 commit 0c1cc2a
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 52 deletions.
16 changes: 10 additions & 6 deletions drivers/wifi/nrf_wifi/Kconfig.nrfwifi
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ config NRF70_SYSTEM_MODE_COMMON
config NET_L2_ETHERNET
default y if (!NRF70_RADIO_TEST && !NRF70_OFFLOADED_RAW_TX)

config HEAP_MEM_POOL_ADD_SIZE_NRF70
# Use a maximum that works for typical use cases and boards, each sample/app can override
# this value if needed by using CONFIG_HEAP_MEM_POOL_IGNORE_MIN
def_int 25000 if NRF70_SCAN_ONLY
def_int 150000

if NRF70_SYSTEM_MODE || NRF70_SYSTEM_WITH_RAW_MODES
config NRF70_STA_MODE
bool "nRF70 STA mode"
Expand Down Expand Up @@ -552,6 +546,16 @@ 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 20000

config NRF_WIFI_DATA_HEAP_SIZE
int "Dedicated memory pool for data plane"
default 6000 if NRF70_SCAN_ONLY
default 100000

config SYSTEM_WORKQUEUE_STACK_SIZE
default 4096

Expand Down
7 changes: 4 additions & 3 deletions drivers/wifi/nrf_wifi/src/fmac_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ void reg_change_callbk_fn(void *vif_ctx,
return;
}

fmac_dev_ctx->reg_change = k_malloc(sizeof(struct nrf_wifi_event_regulatory_change));
fmac_dev_ctx->reg_change = nrf_wifi_osal_mem_alloc(sizeof(struct
nrf_wifi_event_regulatory_change));
if (!fmac_dev_ctx->reg_change) {
LOG_ERR("%s: Failed to allocate memory for reg_change", __func__);
return;
Expand Down Expand Up @@ -675,9 +676,9 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv
nrf_wifi_fmac_dev_rem(rpu_ctx_zep->rpu_ctx);
#endif /* CONFIG_NRF70_RADIO_TEST */

k_free(rpu_ctx_zep->extended_capa);
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa);
rpu_ctx_zep->extended_capa = NULL;
k_free(rpu_ctx_zep->extended_capa_mask);
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa_mask);
rpu_ctx_zep->extended_capa_mask = NULL;

rpu_ctx_zep->rpu_ctx = NULL;
Expand Down
4 changes: 2 additions & 2 deletions drivers/wifi/nrf_wifi/src/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ static void ip_maddr_event_handler(struct net_if *iface,
goto unlock;
}

mcast_info = k_calloc(sizeof(*mcast_info), sizeof(char));
mcast_info = nrf_wifi_osal_mem_zalloc(sizeof(*mcast_info));

if (!mcast_info) {
LOG_ERR("%s: Unable to allocate memory of size %d "
Expand Down Expand Up @@ -502,7 +502,7 @@ static void ip_maddr_event_handler(struct net_if *iface,
sizeof(mac_string_buf)));
}
unlock:
k_free(mcast_info);
nrf_wifi_osal_mem_free(mcast_info);
k_mutex_unlock(&vif_ctx_zep->vif_lock);
}
#endif /* CONFIG_NRF70_STA_MODE */
Expand Down
7 changes: 3 additions & 4 deletions drivers/wifi/nrf_wifi/src/wifi_mgmt_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ int nrf_wifi_disp_scan_zep(const struct device *dev, struct wifi_scan_params *pa

vif_ctx_zep->disp_scan_cb = cb;

scan_info = k_calloc(sizeof(*scan_info) +
scan_info = nrf_wifi_osal_mem_zalloc(sizeof(*scan_info) +
(num_scan_channels *
sizeof(scan_info->scan_params.center_frequency[0])),
sizeof(char));
sizeof(scan_info->scan_params.center_frequency[0])));

if (!scan_info) {
LOG_ERR("%s: Unable to allocate memory for scan_info (size: %d bytes)",
Expand Down Expand Up @@ -226,7 +225,7 @@ int nrf_wifi_disp_scan_zep(const struct device *dev, struct wifi_scan_params *pa
ret = 0;
out:
if (scan_info) {
k_free(scan_info);
nrf_wifi_osal_mem_free(scan_info);
}
k_mutex_unlock(&vif_ctx_zep->vif_lock);
return ret;
Expand Down
26 changes: 14 additions & 12 deletions drivers/wifi/nrf_wifi/src/wpa_supp_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void nrf_wifi_wpa_supp_event_proc_scan_res(void *if_priv,
beacon_ie_len = scan_res->beacon_ies_len;
}

r = k_calloc(sizeof(*r) + ie_len + beacon_ie_len, sizeof(char));
r = nrf_wifi_osal_mem_zalloc(sizeof(*r) + ie_len + beacon_ie_len);

if (!r) {
LOG_ERR("%s: Unable to allocate memory for scan result", __func__);
Expand Down Expand Up @@ -254,7 +254,7 @@ void nrf_wifi_wpa_supp_event_proc_scan_res(void *if_priv,
vif_ctx_zep->scan_in_progress = false;
}

k_free(r);
nrf_wifi_osal_mem_free(r);
}

void nrf_wifi_wpa_supp_event_proc_auth_resp(void *if_priv,
Expand Down Expand Up @@ -519,8 +519,8 @@ int nrf_wifi_wpa_supp_scan2(void *if_priv, struct wpa_driver_scan_params *params
}
}

scan_info = k_calloc(sizeof(*scan_info) + (num_freqs * sizeof(unsigned int)),
sizeof(char));
scan_info = nrf_wifi_osal_mem_zalloc(sizeof(*scan_info) +
(num_freqs * sizeof(unsigned int)));

if (!scan_info) {
LOG_ERR("%s: Unable to allocate memory for scan info", __func__);
Expand Down Expand Up @@ -579,7 +579,7 @@ int nrf_wifi_wpa_supp_scan2(void *if_priv, struct wpa_driver_scan_params *params
ret = 0;
out:
if (scan_info) {
k_free(scan_info);
nrf_wifi_osal_mem_free(scan_info);
}
k_mutex_unlock(&vif_ctx_zep->vif_lock);
return ret;
Expand Down Expand Up @@ -1410,7 +1410,7 @@ int nrf_wifi_nl80211_send_mlme(void *if_priv, const u8 *data,

k_mutex_lock(&mgmt_tx_lock, K_FOREVER);

mgmt_tx_info = k_calloc(sizeof(*mgmt_tx_info), sizeof(char));
mgmt_tx_info = nrf_wifi_osal_mem_zalloc(sizeof(*mgmt_tx_info));

if (!mgmt_tx_info) {
LOG_ERR("%s: Unable to allocate memory", __func__);
Expand Down Expand Up @@ -1487,7 +1487,7 @@ int nrf_wifi_nl80211_send_mlme(void *if_priv, const u8 *data,

out:
if (mgmt_tx_info) {
k_free(mgmt_tx_info);
nrf_wifi_osal_mem_free(mgmt_tx_info);
}
k_mutex_unlock(&mgmt_tx_lock);
k_mutex_unlock(&vif_ctx_zep->vif_lock);
Expand Down Expand Up @@ -1606,22 +1606,24 @@ void nrf_wifi_wpa_supp_event_get_wiphy(void *if_priv,

if ((wiphy_info->params_valid & NRF_WIFI_GET_WIPHY_VALID_EXTENDED_CAPABILITIES) &&
rpu_ctx_zep->extended_capa == NULL) {
/* To avoid overflowing the 100 column limit */
unsigned char ec_len = wiphy_info->extended_capabilities_len;

rpu_ctx_zep->extended_capa = k_malloc(wiphy_info->extended_capabilities_len);
rpu_ctx_zep->extended_capa = nrf_wifi_osal_mem_alloc(ec_len);

if (rpu_ctx_zep->extended_capa) {
memcpy(rpu_ctx_zep->extended_capa, wiphy_info->extended_capabilities,
wiphy_info->extended_capabilities_len);
ec_len);
}

rpu_ctx_zep->extended_capa_mask = k_malloc(wiphy_info->extended_capabilities_len);
rpu_ctx_zep->extended_capa_mask = nrf_wifi_osal_mem_alloc(ec_len);

if (rpu_ctx_zep->extended_capa_mask) {
memcpy(rpu_ctx_zep->extended_capa_mask,
wiphy_info->extended_capabilities_mask,
wiphy_info->extended_capabilities_len);
ec_len);
} else {
free(rpu_ctx_zep->extended_capa);
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa);
rpu_ctx_zep->extended_capa = NULL;
rpu_ctx_zep->extended_capa_len = 0;
}
Expand Down
5 changes: 3 additions & 2 deletions modules/nrf_wifi/bus/qspi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <hal/nrf_gpio.h>

#include "spi_nor.h"
#include "osal_api.h"

/* The QSPI bus node which the NRF70 is on */
#define QSPI_IF_BUS_NODE DT_NODELABEL(qspi)
Expand Down Expand Up @@ -1287,7 +1288,7 @@ int qspi_hl_readw(unsigned int addr, void *data)

len = len + (4 * qspi_cfg->qspi_slave_latency);

rxb = k_malloc(len);
rxb = nrf_wifi_osal_mem_alloc(len);

if (rxb == NULL) {
LOG_ERR("%s: ERROR ENOMEM line %d", __func__, __LINE__);
Expand All @@ -1306,7 +1307,7 @@ int qspi_hl_readw(unsigned int addr, void *data)

*(uint32_t *)data = *(uint32_t *)(rxb + (len - 4));

k_free(rxb);
nrf_wifi_osal_mem_free(rxb);

return status;
}
Expand Down
3 changes: 3 additions & 0 deletions modules/nrf_wifi/os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE
${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c
)

zephyr_library_named(nrf-wifi-shim)
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR})
zephyr_include_directories(${ZEPHYR_NRF_WIFI_MODULE_DIR}/os_if/inc)
zephyr_library_sources(
shim.c
timer.c
Expand Down
Loading

0 comments on commit 0c1cc2a

Please sign in to comment.