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 * @registered: Whether the module @mod_id has successfully registered 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 registered; 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 */ 222 struct direct_buf_rx_psoc_obj { 223 void *hal_soc; 224 qdf_device_t osdev; 225 struct direct_buf_rx_pdev_obj *dbr_pdev_obj[WLAN_UMAC_MAX_PDEVS]; 226 #if defined(DBR_HOLD_LARGE_MEM) && defined(CNSS_MEM_PRE_ALLOC) 227 qdf_list_t mem_list[WLAN_UMAC_MAX_PDEVS]; 228 qdf_spinlock_t mem_list_lock; 229 #endif 230 }; 231 232 /** 233 * struct module_ring_params - Direct buf ring params for module 234 * @num_bufs: Number of buffers allotted to this module 235 * @buf_size: size of buffers 236 */ 237 struct module_ring_params { 238 uint32_t num_bufs; 239 uint32_t buf_size; 240 }; 241 242 /** 243 * target_if_direct_buf_rx_register_events() - Register WMI events to direct 244 * buffer rx module 245 * @psoc: pointer to psoc object 246 * 247 * Return : QDF status of operation 248 */ 249 QDF_STATUS target_if_direct_buf_rx_register_events( 250 struct wlan_objmgr_psoc *psoc); 251 252 /** 253 * target_if_direct_buf_rx_unregister_events() - Unregister WMI events to direct 254 * buffer rx module 255 * @psoc: pointer to psoc object 256 * 257 * Return : QDF status of operation 258 */ 259 QDF_STATUS target_if_direct_buf_rx_unregister_events( 260 struct wlan_objmgr_psoc *psoc); 261 262 /** 263 * target_if_direct_buf_rx_print_ring_stat() - Print ring status for each 264 * module in the pdev 265 * @pdev: pointer to pdev object 266 * 267 * Return : QDF status of operation 268 */ 269 QDF_STATUS target_if_direct_buf_rx_print_ring_stat( 270 struct wlan_objmgr_pdev *pdev); 271 272 /** 273 * target_if_direct_buf_rx_pdev_create_handler() - Handler to be invoked for 274 * direct buffer rx module 275 * during pdev object create 276 * @pdev: pointer to pdev object 277 * @data: pointer to data 278 * 279 * Return : QDF status of operation 280 */ 281 QDF_STATUS target_if_direct_buf_rx_pdev_create_handler( 282 struct wlan_objmgr_pdev *pdev, void *data); 283 284 /** 285 * target_if_direct_buf_rx_pdev_destroy_handler() - Handler to be invoked for 286 * direct buffer rx module 287 * during pdev object destroy 288 * @pdev: pointer to pdev object 289 * @data: pointer to data 290 * 291 * Return : QDF status of operation 292 */ 293 QDF_STATUS target_if_direct_buf_rx_pdev_destroy_handler( 294 struct wlan_objmgr_pdev *pdev, void *data); 295 296 /** 297 * target_if_direct_buf_rx_psoc_create_handler() - Handler invoked for 298 * direct buffer rx module 299 * during attach 300 * @pdev: pointer to psoc object 301 * 302 * Return : QDF status of operation 303 */ 304 QDF_STATUS target_if_direct_buf_rx_psoc_create_handler( 305 struct wlan_objmgr_psoc *psoc, void *data); 306 307 /** 308 * target_if_direct_buf_rx_psoc_destroy_handler() - Handler invoked for 309 * direct buffer rx module 310 * during detach 311 * @pdev: pointer to psoc object 312 * 313 * Return : QDF status of operation 314 */ 315 QDF_STATUS target_if_direct_buf_rx_psoc_destroy_handler( 316 struct wlan_objmgr_psoc *psoc, void *data); 317 318 /** 319 * target_if_deinit_dbr_ring() - Function to deinitialize buffers and ring 320 * allocated for direct buffer rx module 321 * @pdev: pointer to pdev object 322 * @dbr_pdev_obj: pointer to direct buffer rx module pdev obj 323 * @mod_id: module id indicating the module using direct buffer rx framework 324 * @srng_id: srng ID 325 * 326 * Return : QDF status of operation 327 */ 328 QDF_STATUS target_if_deinit_dbr_ring(struct wlan_objmgr_pdev *pdev, 329 struct direct_buf_rx_pdev_obj *dbr_pdev_obj, 330 enum DBR_MODULE mod_id, uint8_t srng_id); 331 /** 332 * target_if_direct_buf_rx_module_register() - Function to register to direct 333 * buffer rx module 334 * @pdev: pointer to pdev object 335 * @mod_id: module id indicating the module using direct buffer rx framework 336 * @dbr_config: dbr module configuration params 337 * @dbr_rsp_handler: function pointer pointing to the response handler to be 338 * invoked for the module registering to direct buffer rx 339 * module 340 * 341 * Return: QDF status of operation 342 */ 343 QDF_STATUS target_if_direct_buf_rx_module_register( 344 struct wlan_objmgr_pdev *pdev, uint8_t mod_id, 345 struct dbr_module_config *dbr_config, 346 bool (*dbr_rsp_handler) 347 (struct wlan_objmgr_pdev *pdev, 348 struct direct_buf_rx_data *dbr_data)); 349 350 /** 351 * target_if_direct_buf_rx_module_unregister() - Function to unregister to 352 * direct buffer rx module 353 * @pdev: pointer to pdev object 354 * @mod_id: module id indicating the module using direct buffer rx framework 355 * 356 * Return: QDF status of operation 357 */ 358 QDF_STATUS target_if_direct_buf_rx_module_unregister( 359 struct wlan_objmgr_pdev *pdev, uint8_t mod_id); 360 361 /** 362 * target_if_direct_buf_rx_get_ring_params() - Function to get ring parameters 363 * for module_id 364 * @pdev: pointer to pdev object 365 * @module_ring_params: pointer to store ring params 366 * @mod_id: module idindicating module using direct buffer rx framework 367 * @srng_id: srng ID 368 */ 369 QDF_STATUS 370 target_if_direct_buf_rx_get_ring_params(struct wlan_objmgr_pdev *pdev, 371 struct module_ring_params *param, 372 uint8_t mod_id, uint8_t srng_id); 373 374 /** 375 * target_if_dbr_start_ring_debug() - Start DBR ring debug 376 * @pdev: pointer to pdev object 377 * @mod_id: module ID indicating the module using direct buffer rx framework 378 * @num_ring_debug_entries: Size of the ring debug entries 379 */ 380 QDF_STATUS target_if_dbr_start_ring_debug(struct wlan_objmgr_pdev *pdev, 381 uint8_t mod_id, 382 uint32_t num_ring_debug_entries); 383 384 /** 385 * target_if_dbr_stop_ring_debug() - Stop DBR ring debug 386 * @pdev: pointer to pdev object 387 * @mod_id: module ID indicating the module using direct buffer rx framework 388 */ 389 QDF_STATUS target_if_dbr_stop_ring_debug(struct wlan_objmgr_pdev *pdev, 390 uint8_t mod_id); 391 392 /** 393 * target_if_dbr_start_buffer_poisoning() - Start DBR buffer poisoning 394 * @pdev: pointer to pdev object 395 * @mod_id: module ID indicating the module using direct buffer rx framework 396 * @value: Value with which buffers should be poisoned 397 * 398 * Only those buffers which are going to be mapped to the device after this 399 * API call are guaranteed to be poisoned. If user wants all the buffers in 400 * the ring to be poisoned from their creation time then this API should be 401 * called before module's registration to the DBR. 402 * 403 */ 404 QDF_STATUS target_if_dbr_start_buffer_poisoning(struct wlan_objmgr_pdev *pdev, 405 uint8_t mod_id, uint32_t value); 406 407 /** 408 * target_if_dbr_stop_buffer_poisoning() - Stop DBR buffer poisoning 409 * @pdev: pointer to pdev object 410 * @mod_id: module ID indicating the module using direct buffer rx framework 411 */ 412 QDF_STATUS target_if_dbr_stop_buffer_poisoning(struct wlan_objmgr_pdev *pdev, 413 uint8_t mod_id); 414 #endif /* _TARGET_IF_DIRECT_BUF_RX_MAIN_H_ */ 415