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