Skip to content

Commit 0c1cc2a

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). 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 763e6a8 commit 0c1cc2a

File tree

8 files changed

+125
-52
lines changed

8 files changed

+125
-52
lines changed

drivers/wifi/nrf_wifi/Kconfig.nrfwifi

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ config NRF70_SYSTEM_MODE_COMMON
8080
config NET_L2_ETHERNET
8181
default y if (!NRF70_RADIO_TEST && !NRF70_OFFLOADED_RAW_TX)
8282

83-
config HEAP_MEM_POOL_ADD_SIZE_NRF70
84-
# Use a maximum that works for typical use cases and boards, each sample/app can override
85-
# this value if needed by using CONFIG_HEAP_MEM_POOL_IGNORE_MIN
86-
def_int 25000 if NRF70_SCAN_ONLY
87-
def_int 150000
88-
8983
if NRF70_SYSTEM_MODE || NRF70_SYSTEM_WITH_RAW_MODES
9084
config NRF70_STA_MODE
9185
bool "nRF70 STA mode"
@@ -552,6 +546,16 @@ config NRF70_RSSI_STALE_TIMEOUT_MS
552546

553547
if NETWORKING
554548
# Finetune defaults for certain system components used by the driver
549+
550+
config NRF_WIFI_CTRL_HEAP_SIZE
551+
int "Dedicated memory pool for control path"
552+
default 20000
553+
554+
config NRF_WIFI_DATA_HEAP_SIZE
555+
int "Dedicated memory pool for data plane"
556+
default 6000 if NRF70_SCAN_ONLY
557+
default 100000
558+
555559
config SYSTEM_WORKQUEUE_STACK_SIZE
556560
default 4096
557561

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ void reg_change_callbk_fn(void *vif_ctx,
463463
return;
464464
}
465465

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

678-
k_free(rpu_ctx_zep->extended_capa);
679+
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa);
679680
rpu_ctx_zep->extended_capa = NULL;
680-
k_free(rpu_ctx_zep->extended_capa_mask);
681+
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa_mask);
681682
rpu_ctx_zep->extended_capa_mask = NULL;
682683

683684
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
@@ -460,7 +460,7 @@ static void ip_maddr_event_handler(struct net_if *iface,
460460
goto unlock;
461461
}
462462

463-
mcast_info = k_calloc(sizeof(*mcast_info), sizeof(char));
463+
mcast_info = nrf_wifi_osal_mem_zalloc(sizeof(*mcast_info));
464464

465465
if (!mcast_info) {
466466
LOG_ERR("%s: Unable to allocate memory of size %d "
@@ -502,7 +502,7 @@ static void ip_maddr_event_handler(struct net_if *iface,
502502
sizeof(mac_string_buf)));
503503
}
504504
unlock:
505-
k_free(mcast_info);
505+
nrf_wifi_osal_mem_free(mcast_info);
506506
k_mutex_unlock(&vif_ctx_zep->vif_lock);
507507
}
508508
#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;
@@ -1410,7 +1410,7 @@ int nrf_wifi_nl80211_send_mlme(void *if_priv, const u8 *data,
14101410

14111411
k_mutex_lock(&mgmt_tx_lock, K_FOREVER);
14121412

1413-
mgmt_tx_info = k_calloc(sizeof(*mgmt_tx_info), sizeof(char));
1413+
mgmt_tx_info = nrf_wifi_osal_mem_zalloc(sizeof(*mgmt_tx_info));
14141414

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

14881488
out:
14891489
if (mgmt_tx_info) {
1490-
k_free(mgmt_tx_info);
1490+
nrf_wifi_osal_mem_free(mgmt_tx_info);
14911491
}
14921492
k_mutex_unlock(&mgmt_tx_lock);
14931493
k_mutex_unlock(&vif_ctx_zep->vif_lock);
@@ -1606,22 +1606,24 @@ void nrf_wifi_wpa_supp_event_get_wiphy(void *if_priv,
16061606

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

1610-
rpu_ctx_zep->extended_capa = k_malloc(wiphy_info->extended_capabilities_len);
1612+
rpu_ctx_zep->extended_capa = nrf_wifi_osal_mem_alloc(ec_len);
16111613

16121614
if (rpu_ctx_zep->extended_capa) {
16131615
memcpy(rpu_ctx_zep->extended_capa, wiphy_info->extended_capabilities,
1614-
wiphy_info->extended_capabilities_len);
1616+
ec_len);
16151617
}
16161618

1617-
rpu_ctx_zep->extended_capa_mask = k_malloc(wiphy_info->extended_capabilities_len);
1619+
rpu_ctx_zep->extended_capa_mask = nrf_wifi_osal_mem_alloc(ec_len);
16181620

16191621
if (rpu_ctx_zep->extended_capa_mask) {
16201622
memcpy(rpu_ctx_zep->extended_capa_mask,
16211623
wiphy_info->extended_capabilities_mask,
1622-
wiphy_info->extended_capabilities_len);
1624+
ec_len);
16231625
} else {
1624-
free(rpu_ctx_zep->extended_capa);
1626+
nrf_wifi_osal_mem_free(rpu_ctx_zep->extended_capa);
16251627
rpu_ctx_zep->extended_capa = NULL;
16261628
rpu_ctx_zep->extended_capa_len = 0;
16271629
}

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE
176176
${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c
177177
)
178178

179+
zephyr_library_named(nrf-wifi-shim)
180+
zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR})
181+
zephyr_include_directories(${ZEPHYR_NRF_WIFI_MODULE_DIR}/os_if/inc)
179182
zephyr_library_sources(
180183
shim.c
181184
timer.c

0 commit comments

Comments
 (0)