xref: /wlan-driver/qcacld-3.0/components/dp/core/inc/wlan_dp_prealloc.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef _WLAN_DP_PREALLOC_H
19 #define _WLAN_DP_PREALLOC_H
20 
21 #include <wlan_objmgr_psoc_obj.h>
22 #include <wlan_dp_rx_thread.h>
23 #include <qdf_trace.h>
24 #include <cdp_txrx_cmn_struct.h>
25 #include <cdp_txrx_cmn.h>
26 
27 #ifdef DP_MEM_PRE_ALLOC
28 /**
29  * dp_prealloc_init() - Pre-allocate DP memory
30  * @ctrl_psoc: objmgr psoc
31  *
32  * Return: QDF_STATUS_SUCCESS on success, error qdf status on failure
33  */
34 QDF_STATUS dp_prealloc_init(struct cdp_ctrl_objmgr_psoc *ctrl_psoc);
35 
36 /**
37  * dp_prealloc_deinit() - Free pre-alloced DP memory
38  *
39  * Return: None
40  */
41 void dp_prealloc_deinit(void);
42 
43 /**
44  * dp_prealloc_get_context_memory() - gets pre-alloc DP context memory from
45  *				      global pool
46  * @ctxt_type: type of DP context
47  * @ctxt_size: size of memory needed
48  *
49  * This is done only as part of init happening in a single context. Hence
50  * no lock is used for protection
51  *
52  * Return: Address of context
53  */
54 void *dp_prealloc_get_context_memory(uint32_t ctxt_type, qdf_size_t ctxt_size);
55 
56 /**
57  * dp_prealloc_put_context_memory() - puts back pre-alloc DP context memory to
58  *				      global pool
59  * @ctxt_type: type of DP context
60  * @vaddr: address of DP context
61  *
62  * This is done only as part of de-init happening in a single context. Hence
63  * no lock is used for protection
64  *
65  * Return: Failure if address not found
66  */
67 QDF_STATUS dp_prealloc_put_context_memory(uint32_t ctxt_type, void *vaddr);
68 
69 /**
70  * dp_prealloc_get_coherent() - gets pre-alloc DP memory
71  * @size: size of memory needed
72  * @base_vaddr_unaligned: Unaligned virtual address.
73  * @paddr_unaligned: Unaligned physical address.
74  * @paddr_aligned: Aligned physical address.
75  * @align: Base address alignment.
76  * @align: alignment needed
77  * @ring_type: HAL ring type
78  *
79  * The function does not handle concurrent access to pre-alloc memory.
80  * All ring memory allocation from pre-alloc memory should happen from single
81  * context to avoid race conditions.
82  *
83  * Return: unaligned virtual address if success or null if memory alloc fails.
84  */
85 void *dp_prealloc_get_coherent(uint32_t *size, void **base_vaddr_unaligned,
86 			       qdf_dma_addr_t *paddr_unaligned,
87 			       qdf_dma_addr_t *paddr_aligned,
88 			       uint32_t align,
89 			       uint32_t ring_type);
90 
91 /**
92  * dp_prealloc_put_coherent() - puts back pre-alloc DP memory
93  * @size: size of memory to be returned
94  * @vaddr_unligned: Unaligned virtual address.
95  * @paddr: Physical address
96  *
97  * Return: None
98  */
99 void dp_prealloc_put_coherent(qdf_size_t size, void *vaddr_unligned,
100 			      qdf_dma_addr_t paddr);
101 
102 /**
103  * dp_prealloc_get_multi_pages() - gets pre-alloc DP multi-pages memory
104  * @src_type: the source that do memory allocation
105  * @element_size: single element size
106  * @element_num: total number of elements should be allocated
107  * @pages: multi page information storage
108  * @cacheable: coherent memory or cacheable memory
109  *
110  * Return: None.
111  */
112 void dp_prealloc_get_multi_pages(uint32_t src_type,
113 				 qdf_size_t element_size,
114 				 uint16_t element_num,
115 				 struct qdf_mem_multi_page_t *pages,
116 				 bool cacheable);
117 
118 /**
119  * dp_prealloc_put_multi_pages() - puts back pre-alloc DP multi-pages memory
120  * @src_type: the source that do memory freement
121  * @pages: multi page information storage
122  *
123  * Return: None
124  */
125 void dp_prealloc_put_multi_pages(uint32_t src_type,
126 				 struct qdf_mem_multi_page_t *pages);
127 
128 /**
129  * dp_prealloc_get_consistent_mem_unaligned() - gets pre-alloc unaligned
130  *						consistent memory
131  * @size: total memory size
132  * @base_addr: pointer to dma address
133  * @ring_type: HAL ring type that requires memory
134  *
135  * Return: memory virtual address pointer on success, NULL on failure
136  */
137 void *dp_prealloc_get_consistent_mem_unaligned(qdf_size_t size,
138 					       qdf_dma_addr_t *base_addr,
139 					       uint32_t ring_type);
140 
141 /**
142  * dp_prealloc_put_consistent_mem_unaligned() - puts back pre-alloc unaligned
143  *						consistent memory
144  * @va_unaligned: memory virtual address pointer
145  *
146  * Return: None
147  */
148 void dp_prealloc_put_consistent_mem_unaligned(void *va_unaligned);
149 
150 #else
151 static inline
dp_prealloc_init(struct cdp_ctrl_objmgr_psoc * ctrl_psoc)152 QDF_STATUS dp_prealloc_init(struct cdp_ctrl_objmgr_psoc *ctrl_psoc)
153 {
154 	return QDF_STATUS_SUCCESS;
155 }
156 
dp_prealloc_deinit(void)157 static inline void dp_prealloc_deinit(void) { }
158 
159 #endif
160 
161 uint32_t dp_get_tx_inqueue(ol_txrx_soc_handle soc);
162 
163 #endif /* _WLAN_DP_PREALLOC_H */
164