xref: /wlan-dirver/qca-wifi-host-cmn/target_if/direct_buf_rx/src/target_if_direct_buf_rx_main.h (revision 503663c6daafffe652fa360bde17243568cd6d2a)
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  * enum DBR_RING_DEBUG_EVENT - DMA ring debug event
93  * @DBR_RING_DEBUG_EVENT_NONE: Not a real value, just a place holder for
94  * no entry
95  * @DBR_RING_DEBUG_EVENT_RX: DBR Rx event
96  * @DBR_RING_DEBUG_EVENT_REPLENISH_RING: DBR replenish event
97  * @DBR_RING_DEBUG_EVENT_MAX: Not a real value, just a place holder for max
98  */
99 enum DBR_RING_DEBUG_EVENT {
100 	DBR_RING_DEBUG_EVENT_NONE = 0,
101 	DBR_RING_DEBUG_EVENT_RX,
102 	DBR_RING_DEBUG_EVENT_REPLENISH_RING,
103 	DBR_RING_DEBUG_EVENT_MAX,
104 };
105 
106 #define DIRECT_BUF_RX_MAX_RING_DEBUG_ENTRIES (1024)
107 /**
108  * struct direct_buf_rx_ring_debug_entry - DBR ring debug entry
109  * @head_idx: Head index of the DMA ring
110  * @tail_idx: Tail index of the DMA ring
111  * @timestamp: Timestamp at the time of logging
112  * @event: Name of the event
113  */
114 struct direct_buf_rx_ring_debug_entry {
115 	uint32_t head_idx;
116 	uint32_t tail_idx;
117 	uint64_t timestamp;
118 	enum DBR_RING_DEBUG_EVENT event;
119 };
120 
121 #ifdef WLAN_DEBUGFS
122 /**
123  * struct dbr_debugfs_priv - Private data for DBR ring debugfs
124  * @dbr_pdev_obj: Pointer to the pdev obj of Direct buffer rx module
125  * @mod_id: Pointer to the registered module ID
126  * @srng_id: srng ID
127  */
128 struct dbr_debugfs_priv {
129 	struct direct_buf_rx_pdev_obj *dbr_pdev_obj;
130 	enum DBR_MODULE mod_id;
131 	uint8_t srng_id;
132 };
133 #endif
134 
135 /**
136  * struct direct_buf_rx_ring_debug - DMA ring debug of a module
137  * @entries: Pointer to the array of ring debug entries
138  * @ring_debug_idx: Current index in the array of ring debug entries
139  * @num_ring_debug_entries: Total ring debug entries
140  * @debugfs_entry: Debugfs entry for this ring
141  * @debugfs_priv: Debugfs ops for this ring
142  */
143 struct direct_buf_rx_ring_debug {
144 	struct direct_buf_rx_ring_debug_entry *entries;
145 	uint32_t ring_debug_idx;
146 	uint32_t num_ring_debug_entries;
147 #ifdef WLAN_DEBUGFS
148 	qdf_dentry_t debugfs_entry;
149 	struct qdf_debugfs_fops *debugfs_fops;
150 #endif
151 };
152 
153 /**
154  * struct direct_buf_rx_module_debug - Debug of a module subscribed to DBR
155  * @dbr_ring_debug: Array of ring debug structers corresponding to each srng
156  * @poisoning_enabled: Whether buffer poisoning is enabled for this module
157  * @poison_value: Value with which buffers should be poisoned
158  * @debugfs_entry: Debugfs entry for this module
159  */
160 struct direct_buf_rx_module_debug {
161 	struct direct_buf_rx_ring_debug dbr_ring_debug[DBR_SRNG_NUM];
162 	bool poisoning_enabled;
163 	uint32_t poison_value;
164 #ifdef WLAN_DEBUGFS
165 	qdf_dentry_t debugfs_entry;
166 #endif
167 };
168 
169 /**
170  * struct direct_buf_rx_module_param - DMA module param
171  * @mod_id: Module ID
172  * @pdev_id: pdev ID
173  * @dbr_config: Pointer to dirct buf rx module configuration struct
174  * @dbr_ring_cap: Pointer to direct buf rx ring capabilities struct
175  * @dbr_ring_cfg: Pointer to direct buf rx ring config struct
176  * @dbr_buf_pool: Pointer to direct buf rx buffer pool struct
177  * @dbr_rsp_handler: Pointer to direct buf rx response handler for the module
178  */
179 struct direct_buf_rx_module_param {
180 	enum DBR_MODULE mod_id;
181 	uint8_t pdev_id;
182 	uint8_t srng_id;
183 	struct dbr_module_config dbr_config;
184 	struct direct_buf_rx_ring_cap *dbr_ring_cap;
185 	struct direct_buf_rx_ring_cfg *dbr_ring_cfg;
186 	struct direct_buf_rx_buf_info *dbr_buf_pool;
187 	bool (*dbr_rsp_handler)(struct wlan_objmgr_pdev *pdev,
188 				struct direct_buf_rx_data *dbr_data);
189 };
190 
191 /**
192  * struct direct_buf_rx_pdev_obj - Direct Buf RX pdev object struct
193  * @num_modules: Number of modules registered to DBR for the pdev
194  * @dbr_mod_param: Pointer to direct buf rx module param struct
195  * @dbr_mod_debug: Pointer to the array of DBR module debug structures
196  * @debugfs_entry: DBR debugfs entry of this radio
197  */
198 struct direct_buf_rx_pdev_obj {
199 	uint32_t num_modules;
200 	struct direct_buf_rx_module_param (*dbr_mod_param)[DBR_SRNG_NUM];
201 #ifdef DIRECT_BUF_RX_DEBUG
202 	struct direct_buf_rx_module_debug *dbr_mod_debug;
203 #ifdef WLAN_DEBUGFS
204 	qdf_dentry_t debugfs_entry;
205 #endif
206 #endif
207 };
208 
209 /**
210  * struct direct_buf_rx_psoc_obj - Direct Buf RX psoc object struct
211  * @hal_soc: Opaque HAL SOC handle
212  * @osdev: QDF os device handle
213  * @dbr_pdev_objs: array of DBR pdev objects
214  */
215 struct direct_buf_rx_psoc_obj {
216 	void *hal_soc;
217 	qdf_device_t osdev;
218 	struct direct_buf_rx_pdev_obj *dbr_pdev_obj[WLAN_UMAC_MAX_PDEVS];
219 };
220 
221 /**
222  * struct module_ring_params - Direct buf ring params for module
223  * @num_bufs: Number of buffers alloted to this module
224  * @buf_size: size of buffers
225  */
226 struct module_ring_params {
227 	uint32_t num_bufs;
228 	uint32_t buf_size;
229 };
230 
231 /**
232  * target_if_direct_buf_rx_register_events() - Register WMI events to direct
233  *                                             buffer rx module
234  * @psoc: pointer to psoc object
235  *
236  * Return : QDF status of operation
237  */
238 QDF_STATUS target_if_direct_buf_rx_register_events(
239 				struct wlan_objmgr_psoc *psoc);
240 
241 /**
242  * target_if_direct_buf_rx_unregister_events() - Unregister WMI events to direct
243  *                                               buffer rx module
244  * @psoc: pointer to psoc object
245  *
246  * Return : QDF status of operation
247  */
248 QDF_STATUS target_if_direct_buf_rx_unregister_events(
249 				struct wlan_objmgr_psoc *psoc);
250 
251 /**
252  * target_if_direct_buf_rx_print_ring_stat() - Print ring status for each
253  *                                             module in the pdev
254  * @pdev: pointer to pdev object
255  *
256  * Return : QDF status of operation
257  */
258 QDF_STATUS target_if_direct_buf_rx_print_ring_stat(
259 				struct wlan_objmgr_pdev *pdev);
260 
261 /**
262  * target_if_direct_buf_rx_pdev_create_handler() - Handler to be invoked for
263  *                                                 direct buffer rx module
264  *                                                 during pdev object create
265  * @pdev: pointer to pdev object
266  * @data: pointer to data
267  *
268  * Return : QDF status of operation
269  */
270 QDF_STATUS target_if_direct_buf_rx_pdev_create_handler(
271 				struct wlan_objmgr_pdev *pdev, void *data);
272 
273 /**
274  * target_if_direct_buf_rx_pdev_destroy_handler() - Handler to be invoked for
275  *                                                  direct buffer rx module
276  *                                                  during pdev object destroy
277  * @pdev: pointer to pdev object
278  * @data: pointer to data
279  *
280  * Return : QDF status of operation
281  */
282 QDF_STATUS target_if_direct_buf_rx_pdev_destroy_handler(
283 				struct wlan_objmgr_pdev *pdev, void *data);
284 
285 /**
286  * target_if_direct_buf_rx_psoc_create_handler() - Handler invoked for
287  *                                                 direct buffer rx module
288  *                                                 during attach
289  * @pdev: pointer to psoc object
290  *
291  * Return : QDF status of operation
292  */
293 QDF_STATUS target_if_direct_buf_rx_psoc_create_handler(
294 				struct wlan_objmgr_psoc *psoc, void *data);
295 
296 /**
297  * target_if_direct_buf_rx_psoc_destroy_handler() - Handler invoked for
298  *                                                  direct buffer rx module
299  *                                                  during detach
300  * @pdev: pointer to psoc object
301  *
302  * Return : QDF status of operation
303  */
304 QDF_STATUS target_if_direct_buf_rx_psoc_destroy_handler(
305 				struct wlan_objmgr_psoc *psoc, void *data);
306 
307 /**
308  * target_if_deinit_dbr_ring() - Function to deinitialize buffers and ring
309  *                               allocated for direct buffer rx module
310  * @pdev: pointer to pdev object
311  * @dbr_pdev_obj: pointer to direct buffer rx module pdev obj
312  * @mod_id: module id indicating the module using direct buffer rx framework
313  * @srng_id: srng ID
314  *
315  * Return : QDF status of operation
316  */
317 QDF_STATUS target_if_deinit_dbr_ring(struct wlan_objmgr_pdev *pdev,
318 				struct direct_buf_rx_pdev_obj *dbr_pdev_obj,
319 				enum DBR_MODULE mod_id, uint8_t srng_id);
320 /**
321  * target_if_direct_buf_rx_module_register() - Function to register to direct
322  *                                             buffer rx module
323  * @pdev: pointer to pdev object
324  * @mod_id: module id indicating the module using direct buffer rx framework
325  * @dbr_config: dbr module configuration params
326  * @dbr_rsp_handler: function pointer pointing to the response handler to be
327  *                   invoked for the module registering to direct buffer rx
328  *                   module
329  *
330  * Return: QDF status of operation
331  */
332 QDF_STATUS target_if_direct_buf_rx_module_register(
333 			struct wlan_objmgr_pdev *pdev, uint8_t mod_id,
334 			struct dbr_module_config *dbr_config,
335 			bool (*dbr_rsp_handler)
336 			     (struct wlan_objmgr_pdev *pdev,
337 			      struct direct_buf_rx_data *dbr_data));
338 
339 /**
340  * target_if_direct_buf_rx_module_unregister() - Function to unregister to
341  *                                               direct buffer rx module
342  * @pdev: pointer to pdev object
343  * @mod_id: module id indicating the module using direct buffer rx framework
344  *
345  * Return: QDF status of operation
346  */
347 QDF_STATUS target_if_direct_buf_rx_module_unregister(
348 			struct wlan_objmgr_pdev *pdev, uint8_t mod_id);
349 
350 /**
351  * target_if_direct_buf_rx_get_ring_params() - Function to get ring parameters
352  *                                             for module_id
353  * @pdev: pointer to pdev object
354  * @module_ring_params: pointer to store ring params
355  * @mod_id: module idindicating module using direct buffer rx framework
356  * @srng_id: srng ID
357  */
358 QDF_STATUS
359 target_if_direct_buf_rx_get_ring_params(struct wlan_objmgr_pdev *pdev,
360 					struct module_ring_params *param,
361 					uint8_t mod_id, uint8_t srng_id);
362 
363 /**
364  * target_if_dbr_start_ring_debug() - Start DBR ring debug
365  * @pdev: pointer to pdev object
366  * @mod_id: module ID indicating the module using direct buffer rx framework
367  * @num_ring_debug_entries: Size of the ring debug entries
368  */
369 QDF_STATUS target_if_dbr_start_ring_debug(struct wlan_objmgr_pdev *pdev,
370 					  uint8_t mod_id,
371 					  uint32_t num_ring_debug_entries);
372 
373 /**
374  * target_if_dbr_stop_ring_debug() - Stop DBR ring debug
375  * @pdev: pointer to pdev object
376  * @mod_id: module ID indicating the module using direct buffer rx framework
377  */
378 QDF_STATUS target_if_dbr_stop_ring_debug(struct wlan_objmgr_pdev *pdev,
379 					 uint8_t mod_id);
380 
381 /**
382  * target_if_dbr_start_buffer_poisoning() - Start DBR buffer poisoning
383  * @pdev: pointer to pdev object
384  * @mod_id: module ID indicating the module using direct buffer rx framework
385  * @value: Value with which buffers should be poisoned
386  *
387  * Only those buffers which are going to be mapped to the device after this
388  * API call are guaranteed to be poisoned. If user wants all the buffers in
389  * the ring to be poisoned from their creation time then this API should be
390  * called before module's registration to the DBR.
391  *
392  */
393 QDF_STATUS target_if_dbr_start_buffer_poisoning(struct wlan_objmgr_pdev *pdev,
394 						uint8_t mod_id, uint32_t value);
395 
396 /**
397  * target_if_dbr_stop_buffer_poisoning() - Stop DBR buffer poisoning
398  * @pdev: pointer to pdev object
399  * @mod_id: module ID indicating the module using direct buffer rx framework
400  */
401 QDF_STATUS target_if_dbr_stop_buffer_poisoning(struct wlan_objmgr_pdev *pdev,
402 					       uint8_t mod_id);
403 #endif /* _TARGET_IF_DIRECT_BUF_RX_MAIN_H_ */
404