1 /* 2 * Copyright (c) 2017-2018 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 * DOC: wlan_serialization_utils_i.h 20 * This file defines the prototypes for the utility helper functions 21 * for the serialization component. 22 */ 23 #ifndef __WLAN_SERIALIZATION_UTILS_I_H 24 #define __WLAN_SERIALIZATION_UTILS_I_H 25 /* Include files */ 26 #include "qdf_status.h" 27 #include "qdf_list.h" 28 #include "qdf_mc_timer.h" 29 #include "wlan_objmgr_cmn.h" 30 #include "wlan_objmgr_global_obj.h" 31 #include "wlan_objmgr_psoc_obj.h" 32 #include "wlan_serialization_rules_i.h" 33 #include "wlan_scan_ucfg_api.h" 34 35 /** 36 * struct wlan_serialization_timer - Timer used for serialization 37 * @cmd: Cmd to which the timer is linked 38 * @timer: Timer associated with the command 39 * 40 * Timers are allocated statically during init, one each for the 41 * maximum active commands permitted in the system. Once a cmd is 42 * moved from pending list to active list, the timer is activated 43 * and once the cmd is completed, the timer is cancelled. Timer is 44 * also cancelled if the command is aborted 45 * 46 * The timers are maintained per psoc. A timer is associated to 47 * unique combination of pdev, cmd_type and cmd_id. 48 */ 49 struct wlan_serialization_timer { 50 struct wlan_serialization_command *cmd; 51 qdf_mc_timer_t timer; 52 }; 53 54 /** 55 * struct wlan_serialization_command_list - List of commands to be serialized 56 * @node: Node identifier in the list 57 * @cmd: Command to be serialized 58 */ 59 struct wlan_serialization_command_list { 60 qdf_list_node_t node; 61 struct wlan_serialization_command cmd; 62 }; 63 64 /** 65 * struct wlan_serialization_pdev_priv_obj - pdev obj data for serialization 66 * @active_list: list to hold the non-scan commands currently being executed 67 * @pending_list list: to hold the non-scan commands currently pending 68 * @active_scan_list: list to hold the scan commands currently active 69 * @pending_scan_list: list to hold the scan commands currently pending 70 * @global_cmd_pool_list: list to hold the global buffers 71 * @cmd_ptr: pointer to globally allocated cmd pool 72 * 73 * Serialization component maintains linked lists to store the commands 74 * sent by other components to get serialized. All the lists are per 75 * pdev. The maximum number of active scans is determined by the firmware. 76 * There is only one non-scan active command per pdev at a time as per the 77 * current software architecture. cmd_ptr holds the memory allocated for 78 * each of the global cmd pool nodes and it is useful in freeing up these 79 * nodes when needed. 80 */ 81 struct wlan_serialization_pdev_priv_obj { 82 qdf_list_t active_list; 83 qdf_list_t pending_list; 84 qdf_list_t active_scan_list; 85 qdf_list_t pending_scan_list; 86 qdf_list_t global_cmd_pool_list; 87 }; 88 89 /** 90 * struct wlan_serialization_psoc_priv_obj - psoc obj data for serialization 91 * @wlan_serialization_module_state_cb - module level callback 92 * @wlan_serialization_apply_rules_cb - pointer to apply rules on the cmd 93 * @timers - Timers associated with the active commands 94 * @max_axtive_cmds - Maximum active commands allowed 95 * 96 * Serialization component takes a command as input and checks whether to 97 * allow/deny the command. It will use the module level callback registered 98 * by each component to fetch the information needed to apply the rules. 99 * Once the information is available, the rules callback registered for each 100 * command internally by serialization will be applied to determine the 101 * checkpoint for the command. If allowed, command will be put into active/ 102 * pending list and each active command is associated with a timer. 103 */ 104 struct wlan_serialization_psoc_priv_obj { 105 wlan_serialization_comp_info_cb comp_info_cb[ 106 WLAN_SER_CMD_MAX][WLAN_UMAC_COMP_ID_MAX]; 107 wlan_serialization_apply_rules_cb apply_rules_cb[WLAN_SER_CMD_MAX]; 108 struct wlan_serialization_timer *timers; 109 uint8_t max_active_cmds; 110 }; 111 112 /** 113 * wlan_serialization_put_back_to_global_list() - put back cmd in global pool 114 * @queue: queue from which cmd needs to be taken out 115 * @ser_pdev_obj: pdev private object 116 * @cmd_list: cmd which needs to be matched 117 * 118 * command will be taken off from the queue and will be put back to global 119 * pool of free command buffers. 120 * 121 * Return: QDF_STATUS 122 */ 123 QDF_STATUS 124 wlan_serialization_put_back_to_global_list(qdf_list_t *queue, 125 struct wlan_serialization_pdev_priv_obj *ser_pdev_obj, 126 struct wlan_serialization_command_list *cmd_list); 127 /** 128 * wlan_serialization_move_pending_to_active() - to move pending command to 129 * active queue 130 * @cmd_type: cmd type to device to which queue the command needs to go 131 * @ser_pdev_obj: pointer to ser_pdev_obj 132 * 133 * Return: none 134 */ 135 void wlan_serialization_move_pending_to_active( 136 enum wlan_serialization_cmd_type cmd_type, 137 struct wlan_serialization_pdev_priv_obj *ser_pdev_obj); 138 /** 139 * wlan_serialization_get_pdev_from_cmd() - get pdev from provided cmd 140 * @cmd: pointer to actual command 141 * 142 * This API will get the pointer to pdev through checking type of cmd 143 * 144 * Return: pointer to pdev 145 */ 146 struct wlan_objmgr_pdev* 147 wlan_serialization_get_pdev_from_cmd(struct wlan_serialization_command *cmd); 148 149 /** 150 * wlan_serialization_get_cmd_from_queue() - to extract command from given queue 151 * @queue: pointer to queue 152 * @nnode: next node to extract 153 * 154 * This API will try to extract node from queue which is next to prev node. If 155 * no previous node is given then take out the front node of the queue. 156 * 157 * Return: QDF_STATUS 158 */ 159 QDF_STATUS wlan_serialization_get_cmd_from_queue(qdf_list_t *queue, 160 qdf_list_node_t **nnode); 161 162 /** 163 * wlan_serialization_is_active_cmd_allowed() - check to see if command 164 * is allowed in active queue 165 * @pdev: pointer to pdev structure 166 * @cmd_type: type of command to check against 167 * 168 * Takes the command type and based on the type, it checks scan command queue 169 * or nonscan command queue to see if active command is allowed or no 170 * 171 * Return: true if allowed else false 172 */ 173 bool wlan_serialization_is_active_cmd_allowed( 174 struct wlan_serialization_command *cmd); 175 176 /** 177 * wlan_serialization_cleanup_all_timers() - to clean-up all timers 178 * 179 * @psoc_ser_ob: pointer to serialization psoc private object 180 * 181 * This API is to cleanup all the timers. it can be used when serialization 182 * module is exiting. it will make sure that if timer is running then it will 183 * stop and destroys the timer 184 * 185 * Return: QDF_STATUS 186 */ 187 QDF_STATUS wlan_serialization_cleanup_all_timers( 188 struct wlan_serialization_psoc_priv_obj *psoc_ser_ob); 189 190 /** 191 * wlan_serialization_find_and_remove_cmd() - to find cmd from queue and remove 192 * @cmd_info: pointer to command related information 193 * 194 * This api will find command from active queue and removes the command 195 * 196 * Return: QDF_STATUS 197 */ 198 QDF_STATUS wlan_serialization_find_and_remove_cmd( 199 struct wlan_serialization_queued_cmd_info *cmd_info); 200 201 /** 202 * wlan_serialization_find_and_cancel_cmd() - to find cmd from queue and cancel 203 * @cmd_info: pointer to command related information 204 * 205 * This api will find command from active queue and pending queue and 206 * removes the command. If it is in active queue then it will notifies the 207 * requester that it is in active queue and from there it expects requester 208 * to send remove command 209 * 210 * Return: wlan_serialization_cmd_status 211 */ 212 enum wlan_serialization_cmd_status 213 wlan_serialization_find_and_cancel_cmd( 214 struct wlan_serialization_queued_cmd_info *cmd_info); 215 /** 216 * wlan_serialization_enqueue_cmd() - Enqueue the cmd to pending/active Queue 217 * @cmd: Command information 218 * @is_cmd_for_active_queue: whether command is for active queue 219 * @cmd_list: command which needs to be inserted in active queue 220 * Return: Status of the serialization request 221 */ 222 enum wlan_serialization_status 223 wlan_serialization_enqueue_cmd( 224 struct wlan_serialization_command *cmd, 225 uint8_t is_cmd_for_active_queue, 226 struct wlan_serialization_command_list **pcmd_list); 227 228 /** 229 * wlan_serialization_dequeue_cmd() - dequeue the cmd to pending/active Queue 230 * @cmd: Command information 231 * @is_cmd_for_active_queue: whether command is for active queue 232 * 233 * Return: Status of the serialization request 234 */ 235 enum wlan_serialization_cmd_status 236 wlan_serialization_dequeue_cmd(struct wlan_serialization_command *cmd, 237 uint8_t is_cmd_for_active_queue); 238 /** 239 * wlan_serialization_find_and_stop_timer() - to find and stop the timer 240 * @psoc: pointer to psoc 241 * @cmd: pointer to actual command 242 * 243 * find the timer associated with command, stop it and destroy it 244 * 245 * Return: QDF_STATUS 246 */ 247 QDF_STATUS 248 wlan_serialization_find_and_stop_timer(struct wlan_objmgr_psoc *psoc, 249 struct wlan_serialization_command *cmd); 250 /** 251 * wlan_serialization_find_and_stop_timer() - to find and start the timer 252 * @psoc: pointer to psoc 253 * @cmd: pointer to actual command 254 * 255 * find the free timer, initialize it, and start it 256 * 257 * Return: QDF_STATUS 258 */ 259 QDF_STATUS 260 wlan_serialization_find_and_start_timer(struct wlan_objmgr_psoc *psoc, 261 struct wlan_serialization_command *cmd); 262 263 /** 264 * wlan_serialization_validate_cmd() - Validate the command 265 * @comp_id: Component ID 266 * @cmd_type: Command Type 267 * 268 * Return: QDF Status 269 */ 270 QDF_STATUS wlan_serialization_validate_cmd( 271 enum wlan_umac_comp_id comp_id, 272 enum wlan_serialization_cmd_type cmd_type); 273 274 /** 275 * wlan_serialization_validate_cmdtype() - Validate the command type 276 * @cmd_type: Command Type 277 * 278 * Return: QDF Status 279 */ 280 QDF_STATUS wlan_serialization_validate_cmdtype( 281 enum wlan_serialization_cmd_type cmd_type); 282 283 /** 284 * wlan_serialization_release_list_cmds() - Release the list cmds to global pool 285 * @ser_pdev_obj: Serialization private pdev object 286 * @list: List for which the commands have to be returned to the global pool 287 * 288 * Return: None 289 */ 290 void wlan_serialization_release_list_cmds( 291 struct wlan_serialization_pdev_priv_obj *ser_pdev_obj, 292 qdf_list_t *list); 293 294 /** 295 * wlan_serialization_destroy_list() - Release the cmds and destroy list 296 * @ser_pdev_obj: Serialization private pdev object 297 * @list: List to be destroyed 298 * 299 * Return: None 300 */ 301 void wlan_serialization_destroy_list( 302 struct wlan_serialization_pdev_priv_obj *ser_pdev_obj, 303 qdf_list_t *list); 304 305 /** 306 * wlan_serialization_get_psoc_priv_obj() - Return the component private obj 307 * @psoc: Pointer to the PSOC object 308 * 309 * Return: Serialization component's PSOC level private data object 310 */ 311 struct wlan_serialization_psoc_priv_obj *wlan_serialization_get_psoc_priv_obj( 312 struct wlan_objmgr_psoc *psoc); 313 314 /** 315 * wlan_serialization_get_pdev_priv_obj() - Return the component private obj 316 * @psoc: Pointer to the PDEV object 317 * 318 * Return: Serialization component's PDEV level private data object 319 */ 320 struct wlan_serialization_pdev_priv_obj *wlan_serialization_get_pdev_priv_obj( 321 struct wlan_objmgr_pdev *pdev); 322 323 /** 324 * wlan_serialization_get_obj() - Return the component private obj 325 * @psoc: Pointer to the SERIALIZATION object 326 * 327 * Return: Serialization component's level private data object 328 */ 329 struct wlan_serialization_psoc_priv_obj * 330 wlan_serialization_get_obj(struct wlan_serialization_command *cmd); 331 332 /** 333 * wlan_serialization_is_cmd_in_vdev_list() - Check Node present in VDEV list 334 * @vdev: Pointer to the VDEV object 335 * @queue: Pointer to the qdf_list_t 336 * 337 * Return: Boolean true or false 338 */ 339 bool 340 wlan_serialization_is_cmd_in_vdev_list( 341 struct wlan_objmgr_vdev *vdev, qdf_list_t *queue); 342 343 /** 344 * wlan_serialization_is_cmd_in_pdev_list() - Check Node present in PDEV list 345 * @pdev: Pointer to the PDEV object 346 * @queue: Pointer to the qdf_list_t 347 * 348 * Return: Boolean true or false 349 */ 350 bool 351 wlan_serialization_is_cmd_in_pdev_list( 352 struct wlan_objmgr_pdev *pdev, qdf_list_t *queue); 353 354 /** 355 * wlan_serialization_is_cmd_in_active_pending() - return cmd status 356 * active/pending queue 357 * @cmd_in_active: CMD in active list 358 * @cmd_in_pending: CMD in pending list 359 * 360 * Return: enum wlan_serialization_cmd_status 361 */ 362 enum wlan_serialization_cmd_status 363 wlan_serialization_is_cmd_in_active_pending(bool cmd_in_active, 364 bool cmd_in_pending); 365 366 /** 367 * wlan_serialization_remove_all_cmd_from_queue() - Remove cmd which matches 368 * @queue: queue from where command needs to be removed 369 * @ser_pdev_obj: pointer to serialization object 370 * @pdev: pointer to pdev 371 * @vdev: pointer to vdev 372 * @cmd: pointer to cmd 373 * @is_active_queue: to check if command matching is for active queue 374 * 375 * This API will remove one or more commands which match the given parameters 376 * interms of argument. For example, if user request all commands to removed 377 * which matches "vdev" then iterate through all commands, find out and remove 378 * command which matches vdev object. 379 * 380 * Return: enum wlan_serialization_cmd_status 381 */ 382 enum wlan_serialization_cmd_status 383 wlan_serialization_remove_all_cmd_from_queue(qdf_list_t *queue, 384 struct wlan_serialization_pdev_priv_obj *ser_pdev_obj, 385 struct wlan_objmgr_pdev *pdev, struct wlan_objmgr_vdev *vdev, 386 struct wlan_serialization_command *cmd, 387 uint8_t is_active_queue); 388 /** 389 * wlan_serialization_is_cmd_present_queue() - Check if same command 390 * is already present active or pending queue 391 * @cmd: pointer to command which we need to find 392 * @is_active_queue: flag to find the command in active or pending queue 393 * 394 * This API will check the given command is already present in active or 395 * pending queue based on flag 396 * If present then return true otherwise false 397 * 398 * Return: true or false 399 */ 400 bool wlan_serialization_is_cmd_present_queue( 401 struct wlan_serialization_command *cmd, 402 uint8_t is_active_queue); 403 404 /** 405 * wlan_serialization_activate_cmd() - activate cmd in active queue 406 * @cmd_list: Command needs to be activated 407 * @ser_pdev_obj: Serialization private pdev object 408 * 409 * Return: None 410 */ 411 void wlan_serialization_activate_cmd( 412 struct wlan_serialization_command_list *cmd_list, 413 struct wlan_serialization_pdev_priv_obj *ser_pdev_obj); 414 #endif 415