Skip to content

Commit

Permalink
nrf_wifi: Create dedicated memory pools for Wi-Fi
Browse files Browse the repository at this point in the history
Create dedicated memory pools for Wi-Fi data and
management paths. Introduce corresponding memory
allocation/deallocation calls.

Signed-off-by: Ravi Dondaputi <[email protected]>
  • Loading branch information
rado17 committed May 3, 2024
1 parent 646a678 commit c3f919a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
8 changes: 4 additions & 4 deletions nrf_wifi/fw_if/umac_if/src/default/fmac_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static enum nrf_wifi_status nrf_wifi_fmac_init_tx(struct nrf_wifi_fmac_dev_ctx *
def_priv->data_config.max_tx_aggregation *
sizeof(struct nrf_wifi_fmac_buf_map_info));

def_dev_ctx->tx_buf_info = nrf_wifi_osal_mem_zalloc(fmac_dev_ctx->fpriv->opriv,
def_dev_ctx->tx_buf_info = nrf_wifi_osal_pkt_mem_zalloc(fmac_dev_ctx->fpriv->opriv,
size);

if (!def_dev_ctx->tx_buf_info) {
Expand Down Expand Up @@ -88,7 +88,7 @@ static void nrf_wifi_fmac_deinit_tx(struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx)

tx_deinit(fmac_dev_ctx);

nrf_wifi_osal_mem_free(fmac_dev_ctx->fpriv->opriv,
nrf_wifi_osal_pkt_mem_free(fmac_dev_ctx->fpriv->opriv,
def_dev_ctx->tx_buf_info);
}

Expand All @@ -109,7 +109,7 @@ static enum nrf_wifi_status nrf_wifi_fmac_init_rx(struct nrf_wifi_fmac_dev_ctx *

size = (def_priv->num_rx_bufs * sizeof(struct nrf_wifi_fmac_buf_map_info));

def_dev_ctx->rx_buf_info = nrf_wifi_osal_mem_zalloc(fmac_dev_ctx->fpriv->opriv,
def_dev_ctx->rx_buf_info = nrf_wifi_osal_pkt_mem_zalloc(fmac_dev_ctx->fpriv->opriv,
size);

if (!def_dev_ctx->rx_buf_info) {
Expand Down Expand Up @@ -195,7 +195,7 @@ static enum nrf_wifi_status nrf_wifi_fmac_deinit_rx(struct nrf_wifi_fmac_dev_ctx
}
}

nrf_wifi_osal_mem_free(fmac_dev_ctx->fpriv->opriv,
nrf_wifi_osal_pkt_mem_free(fmac_dev_ctx->fpriv->opriv,
def_dev_ctx->rx_buf_info);

def_dev_ctx->rx_buf_info = NULL;
Expand Down
34 changes: 33 additions & 1 deletion nrf_wifi/os_if/inc/osal_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void *nrf_wifi_osal_mem_alloc(struct nrf_wifi_osal_priv *opriv,
size_t size);

/**
* nrf_wifi_osal_mem_zalloc() - Allocated zero-initialized memory.
* nrf_wifi_osal_mem_zalloc() - Allocated zero-initialized memory for configuration.
* @opriv: Pointer to the OSAL context returned by the @nrf_wifi_osal_init API.
* @size: Size of the memory to be allocated in bytes.
*
Expand All @@ -77,6 +77,23 @@ void *nrf_wifi_osal_mem_alloc(struct nrf_wifi_osal_priv *opriv,
void *nrf_wifi_osal_mem_zalloc(struct nrf_wifi_osal_priv *opriv,
size_t size);


/**
* nrf_wifi_osal_pkmem_zalloc() - Allocated zero-initialized memory for data.
* @opriv: Pointer to the OSAL context returned by the @nrf_wifi_osal_init API.
* @size: Size of the memory to be allocated in bytes.
*
* Allocates memory of @size bytes, zeroes it out and returns a pointer to the
* start of the memory allocated.
*
* Return:
* Pass: Pointer to start of allocated memory.
* Error: NULL.
*/
void *nrf_wifi_osal_pkt_mem_zalloc(struct nrf_wifi_osal_priv *opriv,
size_t size);


/**
* nrf_wifi_osal_mem_free() - Free previously allocated memory.
* @opriv: Pointer to the OSAL context returned by the @nrf_wifi_osal_init API.
Expand All @@ -90,6 +107,21 @@ void *nrf_wifi_osal_mem_zalloc(struct nrf_wifi_osal_priv *opriv,
void nrf_wifi_osal_mem_free(struct nrf_wifi_osal_priv *opriv,
void *buf);


/**
* nrf_wifi_osal_pkt_mem_free() - Free previously allocated memory for data.
* @opriv: Pointer to the OSAL context returned by the @nrf_wifi_osal_init API.
* @buf: Pointer to the memory to be freed.
*
* Free up memory which has been allocated using @nrf_wifi_osal_mem_alloc or
* @nrf_wifi_osal_mem_zalloc.
*
* Return: None.
*/
void nrf_wifi_osal_pkt_mem_free(struct nrf_wifi_osal_priv *opriv,
void *buf);


/**
* nrf_wifi_osal_mem_cpy() - Copy contents from one memory location to another.
* @opriv: Pointer to the OSAL context returned by the @nrf_wifi_osal_init API.
Expand Down
6 changes: 6 additions & 0 deletions nrf_wifi/os_if/inc/osal_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
* of the memory allocated.
* @mem_zalloc: Allocate memory of @size bytes, zero out the memory and return
* a pointer to the start of the zeroed out memory.
* @pkt_mem_zalloc: Allocate memory of @size bytes, zero out the memory and return
* a pointer to the start of the zeroed out memory.
* @mem_free: Free up memory which has been allocated using @mem_alloc or
* @mem_zalloc.
* @pkt_mem_free: Free up memory which has been allocated using @pkt_mem_alloc or
* @pkt_mem_zalloc.
* @mem_cpy: Copy @count number of bytes from @src location in memory to @dest
* location in memory.
* @mem_set: Fill a block of memory of @size bytes starting at @start with a
Expand Down Expand Up @@ -182,7 +186,9 @@
struct nrf_wifi_osal_ops {
void *(*mem_alloc)(size_t size);
void *(*mem_zalloc)(size_t size);
void *(*pkt_mem_zalloc)(size_t size);
void (*mem_free)(void *buf);
void (*pkt_mem_free)(void *buf);
void *(*mem_cpy)(void *dest, const void *src, size_t count);
void *(*mem_set)(void *start, int val, size_t size);
int (*mem_cmp)(const void *addr1, const void *addr2, size_t size);
Expand Down
14 changes: 14 additions & 0 deletions nrf_wifi/os_if/src/osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,27 @@ void *nrf_wifi_osal_mem_zalloc(struct nrf_wifi_osal_priv *opriv,
}


void *nrf_wifi_osal_pkt_mem_zalloc(struct nrf_wifi_osal_priv *opriv,
size_t size)
{
return opriv->ops->pkt_mem_zalloc(size);
}


void nrf_wifi_osal_mem_free(struct nrf_wifi_osal_priv *opriv,
void *buf)
{
opriv->ops->mem_free(buf);
}


void nrf_wifi_osal_pkt_mem_free(struct nrf_wifi_osal_priv *opriv,
void *buf)
{
opriv->ops->pkt_mem_free(buf);
}


void *nrf_wifi_osal_mem_cpy(struct nrf_wifi_osal_priv *opriv,
void *dest,
const void *src,
Expand Down

0 comments on commit c3f919a

Please sign in to comment.