From d05ded3830ea319b993e4276329a4e72371a62ad Mon Sep 17 00:00:00 2001 From: Ananya Gupta Date: Thu, 26 Nov 2020 23:31:19 +0530 Subject: [PATCH] qcacmn: Pre allocate pdev during attach Pre-allocate pdev context as size exceeds dynamic allocation threshold (4KB). Change-Id: Ida866275ed1ddea5a9b6aa1cf114ccd226ed0f22 CRs-Fixed: 2825110 --- dp/inc/cdp_txrx_ops.h | 3 +++ dp/wifi3.0/dp_internal.h | 37 +++++++++++++++++++++++++++++++ dp/wifi3.0/dp_main.c | 47 ++++++++++++++++++++++++++++++++++++++-- dp/wifi3.0/dp_types.h | 8 +++++++ 4 files changed, 93 insertions(+), 2 deletions(-) diff --git a/dp/inc/cdp_txrx_ops.h b/dp/inc/cdp_txrx_ops.h index cd9a4e295a73..aee7748674fa 100644 --- a/dp/inc/cdp_txrx_ops.h +++ b/dp/inc/cdp_txrx_ops.h @@ -1122,6 +1122,9 @@ struct ol_if_ops { uint8_t *peer_mac_addr); #endif #ifdef DP_MEM_PRE_ALLOC + void *(*dp_prealloc_get_context)(uint32_t ctxt_type); + + QDF_STATUS(*dp_prealloc_put_context)(uint32_t ctxt_type, void *vaddr); void *(*dp_prealloc_get_consistent)(uint32_t *size, void **base_vaddr_unaligned, qdf_dma_addr_t *paddr_unaligned, diff --git a/dp/wifi3.0/dp_internal.h b/dp/wifi3.0/dp_internal.h index 34d958c24cea..db55c47b8d30 100644 --- a/dp/wifi3.0/dp_internal.h +++ b/dp/wifi3.0/dp_internal.h @@ -2517,6 +2517,29 @@ QDF_STATUS dp_wds_ext_set_peer_rx(ol_txrx_soc_handle soc, #endif /* QCA_SUPPORT_WDS_EXTENDED */ #ifdef DP_MEM_PRE_ALLOC + +/** + * dp_context_alloc_mem() - allocate memory for DP context + * @soc: datapath soc handle + * @ctxt_type: DP context type + * @ctxt_size: DP context size + * + * Return: DP context address + */ +void *dp_context_alloc_mem(struct dp_soc *soc, enum dp_ctxt_type ctxt_type, + size_t ctxt_size); + +/** + * dp_context_free_mem() - Free memory of DP context + * @soc: datapath soc handle + * @ctxt_type: DP context type + * @vaddr: Address of context memory + * + * Return: None + */ +void dp_context_free_mem(struct dp_soc *soc, enum dp_ctxt_type ctxt_type, + void *vaddr); + /** * dp_desc_multi_pages_mem_alloc() - alloc memory over multiple pages * @soc: datapath soc handle @@ -2563,6 +2586,20 @@ void dp_desc_multi_pages_mem_free(struct dp_soc *soc, bool cacheable); #else +static inline +void *dp_context_alloc_mem(struct dp_soc *soc, enum dp_ctxt_type ctxt_type, + size_t ctxt_size) +{ + return qdf_mem_malloc(ctxt_size); +} + +static inline +void dp_context_free_mem(struct dp_soc *soc, enum dp_ctxt_type ctxt_type, + void *vaddr) +{ + qdf_mem_free(vaddr); +} + static inline void dp_desc_multi_pages_mem_alloc(struct dp_soc *soc, enum dp_desc_type desc_type, diff --git a/dp/wifi3.0/dp_main.c b/dp/wifi3.0/dp_main.c index ba59361376c3..e9240d637286 100644 --- a/dp/wifi3.0/dp_main.c +++ b/dp/wifi3.0/dp_main.c @@ -1445,6 +1445,49 @@ dp_srng_configure_interrupt_thresholds(struct dp_soc *soc, #endif #ifdef DP_MEM_PRE_ALLOC + +void *dp_context_alloc_mem(struct dp_soc *soc, enum dp_ctxt_type ctxt_type, + size_t ctxt_size) +{ + void *ctxt_mem; + + if (!soc->cdp_soc.ol_ops->dp_prealloc_get_context) { + dp_warn("dp_prealloc_get_context null!"); + goto dynamic_alloc; + } + + ctxt_mem = soc->cdp_soc.ol_ops->dp_prealloc_get_context(ctxt_type); + + if (ctxt_mem) + goto end; + +dynamic_alloc: + dp_info("Pre-alloc of ctxt failed. Dynamic allocation"); + ctxt_mem = qdf_mem_malloc(ctxt_size); +end: + return ctxt_mem; +} + +void dp_context_free_mem(struct dp_soc *soc, enum dp_ctxt_type ctxt_type, + void *vaddr) +{ + QDF_STATUS status; + + if (soc->cdp_soc.ol_ops->dp_prealloc_put_context) { + status = soc->cdp_soc.ol_ops->dp_prealloc_put_context( + DP_PDEV_TYPE, + vaddr); + } else { + dp_warn("dp_prealloc_get_context null!"); + status = QDF_STATUS_E_NOSUPPORT; + } + + if (QDF_IS_STATUS_ERROR(status)) { + dp_info("Context not pre-allocated"); + qdf_mem_free(vaddr); + } +} + static inline void *dp_srng_aligned_mem_alloc_consistent(struct dp_soc *soc, struct dp_srng *srng, @@ -4192,7 +4235,7 @@ static inline QDF_STATUS dp_pdev_attach_wifi3(struct cdp_soc_t *txrx_soc, struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx; int nss_cfg; - pdev = qdf_mem_malloc(sizeof(*pdev)); + pdev = dp_context_alloc_mem(soc, DP_PDEV_TYPE, sizeof(*pdev)); if (!pdev) { QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR, FL("DP PDEV memory allocation failed")); @@ -4539,7 +4582,7 @@ static void dp_pdev_detach(struct cdp_pdev *txrx_pdev, int force) wlan_cfg_pdev_detach(pdev->wlan_cfg_ctx); wlan_minidump_remove(pdev); - qdf_mem_free(pdev); + dp_context_free_mem(soc, DP_PDEV_TYPE, pdev); } /* diff --git a/dp/wifi3.0/dp_types.h b/dp/wifi3.0/dp_types.h index 34e57e353dfa..3072d9477b42 100644 --- a/dp/wifi3.0/dp_types.h +++ b/dp/wifi3.0/dp_types.h @@ -367,6 +367,14 @@ struct dp_rx_nbuf_frag_info { } virt_addr; }; +/** + * enum dp_ctxt - context type + * @DP_PDEV_TYPE: PDEV context + */ +enum dp_ctxt_type { + DP_PDEV_TYPE +}; + /** * enum dp_desc_type - source type for multiple pages allocation * @DP_TX_DESC_TYPE: DP SW TX descriptor