xref: /wlan-dirver/qca-wifi-host-cmn/target_if/direct_buf_rx/src/target_if_direct_buf_rx_main.h (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
1 /*
2  * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _TARGET_IF_DIRECT_BUF_RX_MAIN_H_
21 #define _TARGET_IF_DIRECT_BUF_RX_MAIN_H_
22 
23 #include "qdf_types.h"
24 #include "qdf_status.h"
25 #include <target_if_direct_buf_rx_api.h>
26 
27 struct wlan_objmgr_psoc;
28 struct wlan_lmac_if_tx_ops;
29 struct direct_buf_rx_data;
30 
31 #define DBR_RING_BASE_ALIGN 8
32 
33 #ifdef DBR_MULTI_SRNG_ENABLE
34 #define DBR_SRNG_NUM 2
35 #define dbr_get_pdev_id(srng_id, pdev_id) (srng_id)
36 #else
37 #define DBR_SRNG_NUM 1
38 #define dbr_get_pdev_id(srng_id, pdev_id) (pdev_id)
39 #endif
40 
41 /**
42  * struct direct_buf_rx_info - direct buffer rx operation info struct
43  * @cookie: SW cookie used to get the virtual address
44  * @paddr: Physical address pointer for DMA operation
45  * @vaddr: Virtual address pointer
46  * @offset: Offset of aligned address from unaligned
47  */
48 struct direct_buf_rx_buf_info {
49 	uint32_t cookie;
50 	qdf_dma_addr_t paddr;
51 	void *vaddr;
52 	uint8_t offset;
53 };
54 
55 /**
56  * struct direct_buf_rx_ring_cfg - DMA ring config parameters
57  * @num_ptr: Depth or the number of physical address pointers in the ring
58  * @ring_alloc_size: Size of the HAL ring
59  * @base_paddr_unaligned: base physical addr unaligned
60  * @base_vaddr_unaligned: base virtual addr unaligned
61  * @base_paddr_aligned: base physical addr aligned
62  * @base_vaddr_aligned: base virtual addr unaligned
63  * @head_idx_addr: head index addr
64  * @tail_idx_addr: tail index addr
65  * @srng: HAL srng context
66  */
67 struct direct_buf_rx_ring_cfg {
68 	uint32_t num_ptr;
69 	uint32_t ring_alloc_size;
70 	qdf_dma_addr_t base_paddr_unaligned;
71 	void *base_vaddr_unaligned;
72 	qdf_dma_addr_t base_paddr_aligned;
73 	void *base_vaddr_aligned;
74 	qdf_dma_addr_t head_idx_addr;
75 	qdf_dma_addr_t tail_idx_addr;
76 	void *srng;
77 	uint32_t buf_size;
78 };
79 
80 /**
81  * struct direct_buf_rx_ring_cap - DMA ring capabilities
82  * @ring_elems_min: Minimum number of pointers in the ring
83  * @min_buf_size: Minimum size of each buffer entry in the ring
84  * @min_buf_align: Minimum alignment of the addresses in the ring
85  */
86 struct direct_buf_rx_ring_cap {
87 	uint32_t ring_elems_min;
88 	uint32_t min_buf_size;
89 	uint32_t min_buf_align;
90 };
91 
92 /**
93  * enum DBR_RING_DEBUG_EVENT - DMA ring debug event
94  * @DBR_RING_DEBUG_EVENT_NONE: Not a real value, just a place holder for
95  * no entry
96  * @DBR_RING_DEBUG_EVENT_RX: DBR Rx event
97  * @DBR_RING_DEBUG_EVENT_REPLENISH_RING: DBR replenish event
98  * @DBR_RING_DEBUG_EVENT_MAX: Not a real value, just a place holder for max
99  */
100 enum DBR_RING_DEBUG_EVENT {
101 	DBR_RING_DEBUG_EVENT_NONE = 0,
102 	DBR_RING_DEBUG_EVENT_RX,
103 	DBR_RING_DEBUG_EVENT_REPLENISH_RING,
104 	DBR_RING_DEBUG_EVENT_MAX,
105 };
106 
107 #define DIRECT_BUF_RX_MAX_RING_DEBUG_ENTRIES (1024)
108 /**
109  * struct direct_buf_rx_ring_debug_entry - DBR ring debug entry
110  * @head_idx: Head index of the DMA ring
111  * @tail_idx: Tail index of the DMA ring
112  * @timestamp: Timestamp at the time of logging
113  * @event: Name of the event
114  */
115 struct direct_buf_rx_ring_debug_entry {
116 	uint32_t head_idx;
117 	uint32_t tail_idx;
118 	uint64_t timestamp;
119 	enum DBR_RING_DEBUG_EVENT event;
120 };
121 
122 #ifdef WLAN_DEBUGFS
123 /**
124  * struct dbr_debugfs_priv - Private data for DBR ring debugfs
125  * @dbr_pdev_obj: Pointer to the pdev obj of Direct buffer rx module
126  * @mod_id: Pointer to the registered module ID
127  * @srng_id: srng ID
128  */
129 struct dbr_debugfs_priv {
130 	struct direct_buf_rx_pdev_obj *dbr_pdev_obj;
131 	enum DBR_MODULE mod_id;
132 	uint8_t srng_id;
133 };
134 #endif
135 
136 /**
137  * struct direct_buf_rx_ring_debug - DMA ring debug of a module
138  * @entries: Pointer to the array of ring debug entries
139  * @ring_debug_idx: Current index in the array of ring debug entries
140  * @num_ring_debug_entries: Total ring debug entries
141  * @debugfs_entry: Debugfs entry for this ring
142  * @debugfs_priv: Debugfs ops for this ring
143  */
144 struct direct_buf_rx_ring_debug {
145 	struct direct_buf_rx_ring_debug_entry *entries;
146 	uint32_t ring_debug_idx;
147 	uint32_t num_ring_debug_entries;
148 #ifdef WLAN_DEBUGFS
149 	qdf_dentry_t debugfs_entry;
150 	struct qdf_debugfs_fops *debugfs_fops;
151 #endif
152 };
153 
154 /**
155  * struct direct_buf_rx_module_debug - Debug of a module subscribed to DBR
156  * @dbr_ring_debug: Array of ring debug structers corresponding to each srng
157  * @poisoning_enabled: Whether buffer poisoning is enabled for this module
158  * @poison_value: Value with which buffers should be poisoned
159  * @debugfs_entry: Debugfs entry for this module
160  */
161 struct direct_buf_rx_module_debug {
162 	struct direct_buf_rx_ring_debug dbr_ring_debug[DBR_SRNG_NUM];
163 	bool poisoning_enabled;
164 	uint32_t poison_value;
165 #ifdef WLAN_DEBUGFS
166 	qdf_dentry_t debugfs_entry;
167 #endif
168 };
169 
170 /**
171  * struct direct_buf_rx_module_param - DMA module param
172  * @mod_id: Module ID
173  * @pdev_id: pdev ID
174  * @dbr_config: Pointer to dirct buf rx module configuration struct
175  * @dbr_ring_cap: Pointer to direct buf rx ring capabilities struct
176  * @dbr_ring_cfg: Pointer to direct buf rx ring config struct
177  * @dbr_buf_pool: Pointer to direct buf rx buffer pool struct
178  * @dbr_rsp_handler: Pointer to direct buf rx response handler for the module
179  * @srng_initialized: Whether the DBR ring is successfully initialized for this
180  * @pdev_id @srng_id
181  */
182 struct direct_buf_rx_module_param {
183 	enum DBR_MODULE mod_id;
184 	uint8_t pdev_id;
185 	uint8_t srng_id;
186 	struct dbr_module_config dbr_config;
187 	struct direct_buf_rx_ring_cap *dbr_ring_cap;
188 	struct direct_buf_rx_ring_cfg *dbr_ring_cfg;
189 	struct direct_buf_rx_buf_info *dbr_buf_pool;
190 	bool (*dbr_rsp_handler)(struct wlan_objmgr_pdev *pdev,
191 				struct direct_buf_rx_data *dbr_data);
192 	bool srng_initialized;
193 };
194 
195 /**
196  * struct direct_buf_rx_pdev_obj - Direct Buf RX pdev object struct
197  * @num_modules: Number of modules registered to DBR for the pdev
198  * @dbr_mod_param: Pointer to direct buf rx module param struct
199  * @dbr_mod_debug: Pointer to the array of DBR module debug structures
200  * @debugfs_entry: DBR debugfs entry of this radio
201  */
202 struct direct_buf_rx_pdev_obj {
203 	uint32_t num_modules;
204 	struct direct_buf_rx_module_param (*dbr_mod_param)[DBR_SRNG_NUM];
205 #ifdef DIRECT_BUF_RX_DEBUG
206 	struct direct_buf_rx_module_debug *dbr_mod_debug;
207 #ifdef WLAN_DEBUGFS
208 	qdf_dentry_t debugfs_entry;
209 #endif
210 #endif
211 };
212 
213 /**
214  * struct direct_buf_rx_psoc_obj - Direct Buf RX psoc object struct
215  * @hal_soc: Opaque HAL SOC handle
216  * @osdev: QDF os device handle
217  * @dbr_pdev_objs: array of DBR pdev objects
218  * @mem_list: list for holding the large memories during the entire
219  *  PSOC lifetime
220  * @mem_list_lock: spin lock for the memory list
221  * handler_ctx: Direct DMA event handler context
222  */
223 struct direct_buf_rx_psoc_obj {
224 	void *hal_soc;
225 	qdf_device_t osdev;
226 	struct direct_buf_rx_pdev_obj *dbr_pdev_obj[WLAN_UMAC_MAX_PDEVS];
227 #if defined(DBR_HOLD_LARGE_MEM) && defined(CNSS_MEM_PRE_ALLOC)
228 	qdf_list_t mem_list[WLAN_UMAC_MAX_PDEVS];
229 	qdf_spinlock_t mem_list_lock;
230 #endif
231 	enum wmi_rx_exec_ctx handler_ctx;
232 };
233 
234 /**
235  * struct module_ring_params - Direct buf ring params for module
236  * @num_bufs: Number of buffers allotted to this module
237  * @buf_size: size of buffers
238  */
239 struct module_ring_params {
240 	uint32_t num_bufs;
241 	uint32_t buf_size;
242 };
243 
244 /**
245  * target_if_direct_buf_rx_register_events() - Register WMI events to direct
246  *                                             buffer rx module
247  * @psoc: pointer to psoc object
248  *
249  * Return : QDF status of operation
250  */
251 QDF_STATUS target_if_direct_buf_rx_register_events(
252 				struct wlan_objmgr_psoc *psoc);
253 
254 /**
255  * target_if_direct_buf_rx_unregister_events() - Unregister WMI events to direct
256  *                                               buffer rx module
257  * @psoc: pointer to psoc object
258  *
259  * Return : QDF status of operation
260  */
261 QDF_STATUS target_if_direct_buf_rx_unregister_events(
262 				struct wlan_objmgr_psoc *psoc);
263 
264 /**
265  * target_if_direct_buf_rx_print_ring_stat() - Print ring status for each
266  *                                             module in the pdev
267  * @pdev: pointer to pdev object
268  *
269  * Return : QDF status of operation
270  */
271 QDF_STATUS target_if_direct_buf_rx_print_ring_stat(
272 				struct wlan_objmgr_pdev *pdev);
273 
274 /**
275  * target_if_direct_buf_rx_pdev_create_handler() - Handler to be invoked for
276  *                                                 direct buffer rx module
277  *                                                 during pdev object create
278  * @pdev: pointer to pdev object
279  * @data: pointer to data
280  *
281  * Return : QDF status of operation
282  */
283 QDF_STATUS target_if_direct_buf_rx_pdev_create_handler(
284 				struct wlan_objmgr_pdev *pdev, void *data);
285 
286 /**
287  * target_if_direct_buf_rx_pdev_destroy_handler() - Handler to be invoked for
288  *                                                  direct buffer rx module
289  *                                                  during pdev object destroy
290  * @pdev: pointer to pdev object
291  * @data: pointer to data
292  *
293  * Return : QDF status of operation
294  */
295 QDF_STATUS target_if_direct_buf_rx_pdev_destroy_handler(
296 				struct wlan_objmgr_pdev *pdev, void *data);
297 
298 /**
299  * target_if_direct_buf_rx_psoc_create_handler() - Handler invoked for
300  *                                                 direct buffer rx module
301  *                                                 during attach
302  * @pdev: pointer to psoc object
303  *
304  * Return : QDF status of operation
305  */
306 QDF_STATUS target_if_direct_buf_rx_psoc_create_handler(
307 				struct wlan_objmgr_psoc *psoc, void *data);
308 
309 /**
310  * target_if_direct_buf_rx_psoc_destroy_handler() - Handler invoked for
311  *                                                  direct buffer rx module
312  *                                                  during detach
313  * @pdev: pointer to psoc object
314  *
315  * Return : QDF status of operation
316  */
317 QDF_STATUS target_if_direct_buf_rx_psoc_destroy_handler(
318 				struct wlan_objmgr_psoc *psoc, void *data);
319 
320 /**
321  * target_if_deinit_dbr_ring() - Function to deinitialize buffers and ring
322  *                               allocated for direct buffer rx module
323  * @pdev: pointer to pdev object
324  * @dbr_pdev_obj: pointer to direct buffer rx module pdev obj
325  * @mod_id: module id indicating the module using direct buffer rx framework
326  * @srng_id: srng ID
327  *
328  * Return : QDF status of operation
329  */
330 QDF_STATUS target_if_deinit_dbr_ring(struct wlan_objmgr_pdev *pdev,
331 				struct direct_buf_rx_pdev_obj *dbr_pdev_obj,
332 				enum DBR_MODULE mod_id, uint8_t srng_id);
333 /**
334  * target_if_direct_buf_rx_module_register() - Function to register to direct
335  *                                             buffer rx module
336  * @pdev: pointer to pdev object
337  * @mod_id: module id indicating the module using direct buffer rx framework
338  * @dbr_config: dbr module configuration params
339  * @dbr_rsp_handler: function pointer pointing to the response handler to be
340  *                   invoked for the module registering to direct buffer rx
341  *                   module
342  *
343  * Return: QDF status of operation
344  */
345 QDF_STATUS target_if_direct_buf_rx_module_register(
346 			struct wlan_objmgr_pdev *pdev, uint8_t mod_id,
347 			struct dbr_module_config *dbr_config,
348 			bool (*dbr_rsp_handler)
349 			     (struct wlan_objmgr_pdev *pdev,
350 			      struct direct_buf_rx_data *dbr_data));
351 
352 /**
353  * target_if_direct_buf_rx_module_unregister() - Function to unregister to
354  *                                               direct buffer rx module
355  * @pdev: pointer to pdev object
356  * @mod_id: module id indicating the module using direct buffer rx framework
357  *
358  * Return: QDF status of operation
359  */
360 QDF_STATUS target_if_direct_buf_rx_module_unregister(
361 			struct wlan_objmgr_pdev *pdev, uint8_t mod_id);
362 
363 /**
364  * target_if_direct_buf_rx_get_ring_params() - Function to get ring parameters
365  *                                             for module_id
366  * @pdev: pointer to pdev object
367  * @module_ring_params: pointer to store ring params
368  * @mod_id: module idindicating module using direct buffer rx framework
369  * @srng_id: srng ID
370  */
371 QDF_STATUS
372 target_if_direct_buf_rx_get_ring_params(struct wlan_objmgr_pdev *pdev,
373 					struct module_ring_params *param,
374 					uint8_t mod_id, uint8_t srng_id);
375 
376 /**
377  * target_if_dbr_start_ring_debug() - Start DBR ring debug
378  * @pdev: pointer to pdev object
379  * @mod_id: module ID indicating the module using direct buffer rx framework
380  * @num_ring_debug_entries: Size of the ring debug entries
381  */
382 QDF_STATUS target_if_dbr_start_ring_debug(struct wlan_objmgr_pdev *pdev,
383 					  uint8_t mod_id,
384 					  uint32_t num_ring_debug_entries);
385 
386 /**
387  * target_if_dbr_stop_ring_debug() - Stop DBR ring debug
388  * @pdev: pointer to pdev object
389  * @mod_id: module ID indicating the module using direct buffer rx framework
390  */
391 QDF_STATUS target_if_dbr_stop_ring_debug(struct wlan_objmgr_pdev *pdev,
392 					 uint8_t mod_id);
393 
394 /**
395  * target_if_dbr_start_buffer_poisoning() - Start DBR buffer poisoning
396  * @pdev: pointer to pdev object
397  * @mod_id: module ID indicating the module using direct buffer rx framework
398  * @value: Value with which buffers should be poisoned
399  *
400  * Only those buffers which are going to be mapped to the device after this
401  * API call are guaranteed to be poisoned. If user wants all the buffers in
402  * the ring to be poisoned from their creation time then this API should be
403  * called before module's registration to the DBR.
404  *
405  */
406 QDF_STATUS target_if_dbr_start_buffer_poisoning(struct wlan_objmgr_pdev *pdev,
407 						uint8_t mod_id, uint32_t value);
408 
409 /**
410  * target_if_dbr_stop_buffer_poisoning() - Stop DBR buffer poisoning
411  * @pdev: pointer to pdev object
412  * @mod_id: module ID indicating the module using direct buffer rx framework
413  */
414 QDF_STATUS target_if_dbr_stop_buffer_poisoning(struct wlan_objmgr_pdev *pdev,
415 					       uint8_t mod_id);
416 #endif /* _TARGET_IF_DIRECT_BUF_RX_MAIN_H_ */
417