Skip to content

Commit 762588e

Browse files
committed
drivers: wifi: Create dedicated mem pool for Wi-Fi driver
Create dedicated memory pools for Wi-Fi management and data operations (defaults: 20KB for management and 130KB for data). Setting Data pool to 110KB for non-Nordic SOCs to resolve RAM overflows seen in twister runs. 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]>
1 parent b8795c0 commit 762588e

File tree

8 files changed

+144
-54
lines changed

8 files changed

+144
-54
lines changed

drivers/wifi/nrf_wifi/Kconfig.nrfwifi

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ endchoice
6666
config NET_L2_ETHERNET
6767
default y if (!NRF70_RADIO_TEST && !NRF70_OFFLOADED_RAW_TX)
6868

69-
config HEAP_MEM_POOL_ADD_SIZE_NRF70
70-
# Use a maximum that works for typical use cases and boards, each sample/app can override
71-
# this value if needed by using CONFIG_HEAP_MEM_POOL_IGNORE_MIN
72-
def_int 25000 if NRF70_SCAN_ONLY
73-
def_int 150000
74-
7569
if NRF70_SYSTEM_MODE
7670
config NRF70_STA_MODE
7771
bool "nRF70 STA mode"
@@ -529,8 +523,19 @@ config NRF70_RSSI_STALE_TIMEOUT_MS
529523
value as the driver does not store it and requires RPU to provide the
530524
information.
531525

526+
config NRF_WIFI_CTRL_HEAP_SIZE
527+
int "Dedicated memory pool for control plane"
528+
default 20000
529+
530+
config NRF_WIFI_DATA_HEAP_SIZE
531+
int "Dedicated memory pool for data plane"
532+
default 6000 if NRF70_SCAN_ONLY
533+
default 110000 if !SOC_FAMILY_NORDIC_NRF
534+
default 130000
535+
532536
if NETWORKING
533537
# Finetune defaults for certain system components used by the driver
538+
534539
config SYSTEM_WORKQUEUE_STACK_SIZE
535540
default 4096
536541

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ void reg_change_callbk_fn(void *vif_ctx,
465465
return;
466466
}
467467

468-
fmac_dev_ctx->reg_change = k_malloc(sizeof(struct nrf_wifi_event_regulatory_change));
468+
fmac_dev_ctx->reg_change = nrf_wifi_osal_mem_alloc(sizeof(struct
469+
nrf_wifi_event_regulatory_change));
469470
if (!fmac_dev_ctx->reg_change) {
470471
LOG_ERR("%s: Failed to allocate memory for reg_change", __func__);
471472
return;
@@ -675,11 +676,9 @@ enum nrf_wifi_status nrf_wifi_fmac_dev_rem_zep(struct nrf_wifi_drv_priv_zep *drv
675676
nrf_wifi_sys_fmac_dev_deinit(rpu_ctx_zep->rpu_ctx);
676677
#endif /* CONFIG_NRF70_RADIO_TEST */
677678

678-
nrf_wifi_fmac_dev_rem(rpu_ctx_zep->rpu_ctx);
679-
680-
k_free(rpu_ctx_zep->extended_capa);
679+
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa);
681680
rpu_ctx_zep->extended_capa = NULL;
682-
k_free(rpu_ctx_zep->extended_capa_mask);
681+
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa_mask);
683682
rpu_ctx_zep->extended_capa_mask = NULL;
684683

685684
rpu_ctx_zep->rpu_ctx = NULL;

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ static void ip_maddr_event_handler(struct net_if *iface,
459459
goto unlock;
460460
}
461461

462-
mcast_info = k_calloc(sizeof(*mcast_info), sizeof(char));
462+
mcast_info = nrf_wifi_osal_mem_zalloc(sizeof(*mcast_info));
463463

464464
if (!mcast_info) {
465465
LOG_ERR("%s: Unable to allocate memory of size %d "
@@ -501,7 +501,7 @@ static void ip_maddr_event_handler(struct net_if *iface,
501501
sizeof(mac_string_buf)));
502502
}
503503
unlock:
504-
k_free(mcast_info);
504+
nrf_wifi_osal_mem_free(mcast_info);
505505
k_mutex_unlock(&vif_ctx_zep->vif_lock);
506506
}
507507
#endif /* CONFIG_NRF70_STA_MODE */

drivers/wifi/nrf_wifi/src/wifi_mgmt_scan.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ int nrf_wifi_disp_scan_zep(const struct device *dev, struct wifi_scan_params *pa
109109

110110
vif_ctx_zep->disp_scan_cb = cb;
111111

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

117116
if (!scan_info) {
118117
LOG_ERR("%s: Unable to allocate memory for scan_info (size: %d bytes)",
@@ -226,7 +225,7 @@ int nrf_wifi_disp_scan_zep(const struct device *dev, struct wifi_scan_params *pa
226225
ret = 0;
227226
out:
228227
if (scan_info) {
229-
k_free(scan_info);
228+
nrf_wifi_osal_mem_free(scan_info);
230229
}
231230
k_mutex_unlock(&vif_ctx_zep->vif_lock);
232231
return ret;

drivers/wifi/nrf_wifi/src/wpa_supp_if.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void nrf_wifi_wpa_supp_event_proc_scan_res(void *if_priv,
174174
beacon_ie_len = scan_res->beacon_ies_len;
175175
}
176176

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

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

257-
k_free(r);
257+
nrf_wifi_osal_mem_free(r);
258258
}
259259

260260
void nrf_wifi_wpa_supp_event_proc_auth_resp(void *if_priv,
@@ -519,8 +519,8 @@ int nrf_wifi_wpa_supp_scan2(void *if_priv, struct wpa_driver_scan_params *params
519519
}
520520
}
521521

522-
scan_info = k_calloc(sizeof(*scan_info) + (num_freqs * sizeof(unsigned int)),
523-
sizeof(char));
522+
scan_info = nrf_wifi_osal_mem_zalloc(sizeof(*scan_info) +
523+
(num_freqs * sizeof(unsigned int)));
524524

525525
if (!scan_info) {
526526
LOG_ERR("%s: Unable to allocate memory for scan info", __func__);
@@ -579,7 +579,7 @@ int nrf_wifi_wpa_supp_scan2(void *if_priv, struct wpa_driver_scan_params *params
579579
ret = 0;
580580
out:
581581
if (scan_info) {
582-
k_free(scan_info);
582+
nrf_wifi_osal_mem_free(scan_info);
583583
}
584584
k_mutex_unlock(&vif_ctx_zep->vif_lock);
585585
return ret;
@@ -1414,7 +1414,7 @@ int nrf_wifi_nl80211_send_mlme(void *if_priv, const u8 *data,
14141414

14151415
k_mutex_lock(&mgmt_tx_lock, K_FOREVER);
14161416

1417-
mgmt_tx_info = k_calloc(sizeof(*mgmt_tx_info), sizeof(char));
1417+
mgmt_tx_info = nrf_wifi_osal_mem_zalloc(sizeof(*mgmt_tx_info));
14181418

14191419
if (!mgmt_tx_info) {
14201420
LOG_ERR("%s: Unable to allocate memory", __func__);
@@ -1491,7 +1491,7 @@ int nrf_wifi_nl80211_send_mlme(void *if_priv, const u8 *data,
14911491

14921492
out:
14931493
if (mgmt_tx_info) {
1494-
k_free(mgmt_tx_info);
1494+
nrf_wifi_osal_mem_free(mgmt_tx_info);
14951495
}
14961496
k_mutex_unlock(&mgmt_tx_lock);
14971497
k_mutex_unlock(&vif_ctx_zep->vif_lock);
@@ -1610,22 +1610,24 @@ void nrf_wifi_wpa_supp_event_get_wiphy(void *if_priv,
16101610

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

1614-
rpu_ctx_zep->extended_capa = k_malloc(wiphy_info->extended_capabilities_len);
1616+
rpu_ctx_zep->extended_capa = nrf_wifi_osal_mem_alloc(ec_len);
16151617

16161618
if (rpu_ctx_zep->extended_capa) {
16171619
memcpy(rpu_ctx_zep->extended_capa, wiphy_info->extended_capabilities,
1618-
wiphy_info->extended_capabilities_len);
1620+
ec_len);
16191621
}
16201622

1621-
rpu_ctx_zep->extended_capa_mask = k_malloc(wiphy_info->extended_capabilities_len);
1623+
rpu_ctx_zep->extended_capa_mask = nrf_wifi_osal_mem_alloc(ec_len);
16221624

16231625
if (rpu_ctx_zep->extended_capa_mask) {
16241626
memcpy(rpu_ctx_zep->extended_capa_mask,
16251627
wiphy_info->extended_capabilities_mask,
1626-
wiphy_info->extended_capabilities_len);
1628+
ec_len);
16271629
} else {
1628-
free(rpu_ctx_zep->extended_capa);
1630+
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa);
16291631
rpu_ctx_zep->extended_capa = NULL;
16301632
rpu_ctx_zep->extended_capa_len = 0;
16311633
}

modules/nrf_wifi/bus/qspi_if.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <hal/nrf_gpio.h>
2525

2626
#include "spi_nor.h"
27+
#include "osal_api.h"
2728

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

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

1290-
rxb = k_malloc(len);
1291+
rxb = nrf_wifi_osal_mem_alloc(len);
12911292

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

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

1309-
k_free(rxb);
1310+
nrf_wifi_osal_mem_free(rxb);
13101311

13111312
return status;
13121313
}

modules/nrf_wifi/os/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_subdirectory(${ZEPHYR_NRF_WIFI_MODULE_DIR} nrf_wifi_osal)
99

1010
zephyr_library_named(nrf-wifi-shim)
1111
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR})
12+
zephyr_include_directories(${ZEPHYR_NRF_WIFI_MODULE_DIR}/os_if/inc)
1213
zephyr_library_sources(
1314
shim.c
1415
timer.c

0 commit comments

Comments
 (0)