xref: /wlan-dirver/qca-wifi-host-cmn/target_if/direct_buf_rx/src/target_if_direct_buf_rx_main.h (revision 11f5a63a6cbdda84849a730de22f0a71e635d58c)
1 /*
2  * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _TARGET_IF_DIRECT_BUF_RX_MAIN_H_
20 #define _TARGET_IF_DIRECT_BUF_RX_MAIN_H_
21 
22 #include "qdf_types.h"
23 #include "qdf_status.h"
24 #include <target_if_direct_buf_rx_api.h>
25 
26 struct wlan_objmgr_psoc;
27 struct wlan_lmac_if_tx_ops;
28 struct direct_buf_rx_data;
29 
30 #define DBR_RING_BASE_ALIGN 8
31 
32 #ifdef DBR_MULTI_SRNG_ENABLE
33 #define DBR_SRNG_NUM 2
34 #define dbr_get_pdev_id(srng_id, pdev_id) (srng_id)
35 #else
36 #define DBR_SRNG_NUM 1
37 #define dbr_get_pdev_id(srng_id, pdev_id) (pdev_id)
38 #endif
39 
40 /**
41  * struct direct_buf_rx_info - direct buffer rx operation info struct
42  * @cookie: SW cookie used to get the virtual address
43  * @paddr: Physical address pointer for DMA operation
44  * @vaddr: Virtual address pointer
45  * @offset: Offset of aligned address from unaligned
46  */
47 struct direct_buf_rx_buf_info {
48 	uint32_t cookie;
49 	qdf_dma_addr_t paddr;
50 	void *vaddr;
51 	uint8_t offset;
52 };
53 
54 /**
55  * struct direct_buf_rx_ring_cfg - DMA ring config parameters
56  * @num_ptr: Depth or the number of physical address pointers in the ring
57  * @ring_alloc_size: Size of the HAL ring
58  * @base_paddr_unaligned: base physical addr unaligned
59  * @base_vaddr_unaligned: base virtual addr unaligned
60  * @base_paddr_aligned: base physical addr aligned
61  * @base_vaddr_aligned: base virtual addr unaligned
62  * @head_idx_addr: head index addr
63  * @tail_idx_addr: tail index addr
64  * @srng: HAL srng context
65  */
66 struct direct_buf_rx_ring_cfg {
67 	uint32_t num_ptr;
68 	uint32_t ring_alloc_size;
69 	qdf_dma_addr_t base_paddr_unaligned;
70 	void *base_vaddr_unaligned;
71 	qdf_dma_addr_t base_paddr_aligned;
72 	void *base_vaddr_aligned;
73 	qdf_dma_addr_t head_idx_addr;
74 	qdf_dma_addr_t tail_idx_addr;
75 	void *srng;
76 	uint32_t buf_size;
77 };
78 
79 /**
80  * struct direct_buf_rx_ring_cap - DMA ring capabilities
81  * @ring_elems_min: Minimum number of pointers in the ring
82  * @min_buf_size: Minimum size of each buffer entry in the ring
83  * @min_buf_align: Minimum alignment of the addresses in the ring
84  */
85 struct direct_buf_rx_ring_cap {
86 	uint32_t ring_elems_min;
87 	uint32_t min_buf_size;
88 	uint32_t min_buf_align;
89 };
90 
91 /**
92  * struct direct_buf_rx_module_param - DMA module param
93  * @mod_id: Module ID
94  * @pdev_id: pdev ID
95  * @dbr_config: Pointer to dirct buf rx module configuration struct
96  * @dbr_ring_cap: Pointer to direct buf rx ring capabilities struct
97  * @dbr_ring_cfg: Pointer to direct buf rx ring config struct
98  * @dbr_buf_pool: Pointer to direct buf rx buffer pool struct
99  * @dbr_rsp_handler: Pointer to direct buf rx response handler for the module
100  */
101 struct direct_buf_rx_module_param {
102 	enum DBR_MODULE mod_id;
103 	uint8_t pdev_id;
104 	struct dbr_module_config dbr_config;
105 	struct direct_buf_rx_ring_cap *dbr_ring_cap;
106 	struct direct_buf_rx_ring_cfg *dbr_ring_cfg;
107 	struct direct_buf_rx_buf_info *dbr_buf_pool;
108 	bool (*dbr_rsp_handler)(struct wlan_objmgr_pdev *pdev,
109 				struct direct_buf_rx_data *dbr_data);
110 };
111 
112 /**
113  * struct direct_buf_rx_pdev_obj - Direct Buf RX pdev object struct
114  * @num_modules: Number of modules registered to DBR for the pdev
115  * @dbr_mod_param: Pointer to direct buf rx module param struct
116  */
117 struct direct_buf_rx_pdev_obj {
118 	uint32_t num_modules;
119 	struct direct_buf_rx_module_param (*dbr_mod_param)[DBR_SRNG_NUM];
120 };
121 
122 /**
123  * struct direct_buf_rx_psoc_obj - Direct Buf RX psoc object struct
124  * @hal_soc: Opaque HAL SOC handle
125  * @osdev: QDF os device handle
126  */
127 struct direct_buf_rx_psoc_obj {
128 	void *hal_soc;
129 	qdf_device_t osdev;
130 };
131 
132 /**
133  * struct module_ring_params - Direct buf ring params for module
134  * @num_bufs: Number of buffers alloted to this module
135  * @buf_size: size of buffers
136  */
137 struct module_ring_params {
138 	uint32_t num_bufs;
139 	uint32_t buf_size;
140 };
141 
142 /**
143  * target_if_direct_buf_rx_register_events() - Register WMI events to direct
144  *                                             buffer rx module
145  * @psoc: pointer to psoc object
146  *
147  * Return : QDF status of operation
148  */
149 QDF_STATUS target_if_direct_buf_rx_register_events(
150 				struct wlan_objmgr_psoc *psoc);
151 
152 /**
153  * target_if_direct_buf_rx_unregister_events() - Unregister WMI events to direct
154  *                                               buffer rx module
155  * @psoc: pointer to psoc object
156  *
157  * Return : QDF status of operation
158  */
159 QDF_STATUS target_if_direct_buf_rx_unregister_events(
160 				struct wlan_objmgr_psoc *psoc);
161 
162 /**
163  * target_if_direct_buf_rx_print_ring_stat() - Print ring status for each
164  *                                             module in the pdev
165  * @pdev: pointer to pdev object
166  *
167  * Return : QDF status of operation
168  */
169 QDF_STATUS target_if_direct_buf_rx_print_ring_stat(
170 				struct wlan_objmgr_pdev *pdev);
171 
172 /**
173  * target_if_direct_buf_rx_pdev_create_handler() - Handler to be invoked for
174  *                                                 direct buffer rx module
175  *                                                 during pdev object create
176  * @pdev: pointer to pdev object
177  * @data: pointer to data
178  *
179  * Return : QDF status of operation
180  */
181 QDF_STATUS target_if_direct_buf_rx_pdev_create_handler(
182 				struct wlan_objmgr_pdev *pdev, void *data);
183 
184 /**
185  * target_if_direct_buf_rx_pdev_destroy_handler() - Handler to be invoked for
186  *                                                  direct buffer rx module
187  *                                                  during pdev object destroy
188  * @pdev: pointer to pdev object
189  * @data: pointer to data
190  *
191  * Return : QDF status of operation
192  */
193 QDF_STATUS target_if_direct_buf_rx_pdev_destroy_handler(
194 				struct wlan_objmgr_pdev *pdev, void *data);
195 
196 /**
197  * target_if_direct_buf_rx_psoc_create_handler() - Handler invoked for
198  *                                                 direct buffer rx module
199  *                                                 during attach
200  * @pdev: pointer to psoc object
201  *
202  * Return : QDF status of operation
203  */
204 QDF_STATUS target_if_direct_buf_rx_psoc_create_handler(
205 				struct wlan_objmgr_psoc *psoc, void *data);
206 
207 /**
208  * target_if_direct_buf_rx_psoc_destroy_handler() - Handler invoked for
209  *                                                  direct buffer rx module
210  *                                                  during detach
211  * @pdev: pointer to psoc object
212  *
213  * Return : QDF status of operation
214  */
215 QDF_STATUS target_if_direct_buf_rx_psoc_destroy_handler(
216 				struct wlan_objmgr_psoc *psoc, void *data);
217 
218 /**
219  * target_if_deinit_dbr_ring() - Function to deinitialize buffers and ring
220  *                               allocated for direct buffer rx module
221  * @pdev: pointer to pdev object
222  * @dbr_pdev_obj: pointer to direct buffer rx module pdev obj
223  * @mod_id: module id indicating the module using direct buffer rx framework
224  * @srng_id: srng ID
225  *
226  * Return : QDF status of operation
227  */
228 QDF_STATUS target_if_deinit_dbr_ring(struct wlan_objmgr_pdev *pdev,
229 				struct direct_buf_rx_pdev_obj *dbr_pdev_obj,
230 				enum DBR_MODULE mod_id, uint8_t srng_id);
231 /**
232  * target_if_direct_buf_rx_module_register() - Function to register to direct
233  *                                             buffer rx module
234  * @pdev: pointer to pdev object
235  * @mod_id: module id indicating the module using direct buffer rx framework
236  * @dbr_config: dbr module configuration params
237  * @dbr_rsp_handler: function pointer pointing to the response handler to be
238  *                   invoked for the module registering to direct buffer rx
239  *                   module
240  *
241  * Return: QDF status of operation
242  */
243 QDF_STATUS target_if_direct_buf_rx_module_register(
244 			struct wlan_objmgr_pdev *pdev, uint8_t mod_id,
245 			struct dbr_module_config *dbr_config,
246 			bool (*dbr_rsp_handler)
247 			     (struct wlan_objmgr_pdev *pdev,
248 			      struct direct_buf_rx_data *dbr_data));
249 
250 /**
251  * target_if_direct_buf_rx_module_unregister() - Function to unregister to
252  *                                               direct buffer rx module
253  * @pdev: pointer to pdev object
254  * @mod_id: module id indicating the module using direct buffer rx framework
255  *
256  * Return: QDF status of operation
257  */
258 QDF_STATUS target_if_direct_buf_rx_module_unregister(
259 			struct wlan_objmgr_pdev *pdev, uint8_t mod_id);
260 
261 /**
262  * target_if_direct_buf_rx_get_ring_params() - Function to get ring parameters
263  *                                             for module_id
264  * @pdev: pointer to pdev object
265  * @module_ring_params: pointer to store ring params
266  * @mod_id: module idindicating module using direct buffer rx framework
267  * @srng_id: srng ID
268  */
269 QDF_STATUS
270 target_if_direct_buf_rx_get_ring_params(struct wlan_objmgr_pdev *pdev,
271 					struct module_ring_params *param,
272 					uint8_t mod_id, uint8_t srng_id);
273 
274 #endif /* _TARGET_IF_DIRECT_BUF_RX_MAIN_H_ */
275