xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/serialization/inc/wlan_serialization_api.h (revision fa47688f04ef001a6dcafaebdcc3c031f15ee75e)
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 /**
20  * DOC: wlan_serialization_api.h
21  * This file provides prototypes of the routines needed for the
22  * external components to utilize the services provided by the
23  * serialization component.
24  */
25 
26 /* Include files */
27 #ifndef __WLAN_SERIALIZATION_API_H
28 #define __WLAN_SERIALIZATION_API_H
29 
30 #include <qdf_status.h>
31 #include <wlan_objmgr_cmn.h>
32 
33 /* Preprocessor Definitions and Constants */
34 
35 /**
36  * enum ser_queue_reason- reason for changes to serialization queue
37  * @: SER_REQUEST: queue updated for serialization request
38  * @: SER_REMOVE : queue updated for serialization remove request
39  * @: SER_CANCEL : queue updated for serialization cancel request
40  * @: SER_TIMEOUT : queue updated for command timeout
41  * @: SER_ACTIVATION_FAILED : queue updated since command activation failed
42  * @: SER_PENDING_TO_ACTIVE : queue updated for pending to active movement
43  */
44 enum ser_queue_reason {
45 	SER_REQUEST,
46 	SER_REMOVE,
47 	SER_CANCEL,
48 	SER_TIMEOUT,
49 	SER_ACTIVATION_FAILED,
50 	SER_PENDING_TO_ACTIVE,
51 	SER_QUEUE_ACTION_MAX,
52 };
53 
54 /*
55  * struct wlan_serialization_queued_cmd_info member queue_type specifies the
56  * below values to cancel the commands in these queues. Setting both the
57  * bits will cancel the commands in both the queues.
58  */
59 #define WLAN_SERIALIZATION_ACTIVE_QUEUE  0x1
60 #define WLAN_SERIALIZATION_PENDING_QUEUE 0x2
61 
62 /**
63  * enum wlan_serialization_cb_reason - reason for calling the callback
64  * @WLAN_SERIALIZATION_REASON_ACTIVATE_CMD: activate the cmd by sending it to FW
65  * @WLAN_SERIALIZATION_REASON_CANCEL_CMD: Cancel the cmd in the pending list
66  * @WLAN_SERIALIZATION_REASON_RELEASE_MEM_CMD:cmd execution complete. Release
67  *                                           the memory allocated while
68  *                                           building the command
69  * @WLAN_SER_CB_ACTIVE_CMD_TIMEOUT: active cmd has been timeout.
70  */
71 enum wlan_serialization_cb_reason {
72 	WLAN_SER_CB_ACTIVATE_CMD,
73 	WLAN_SER_CB_CANCEL_CMD,
74 	WLAN_SER_CB_RELEASE_MEM_CMD,
75 	WLAN_SER_CB_ACTIVE_CMD_TIMEOUT,
76 };
77 
78 /**
79  * struct wlan_serialization_scan_info - Information needed for scan cmd
80  * @is_cac_in_progress: boolean to check the cac status
81  * @is_tdls_in_progress: boolean to check the tdls status
82  * @is_mlme_op_in_progress: boolean to check the mlme op status
83  *
84  * This information is needed for scan command from other components
85  * to apply the rules and check whether the cmd is allowed or not
86  */
87 struct wlan_serialization_scan_info {
88 	bool is_cac_in_progress;
89 	bool is_tdls_in_progress;
90 	bool is_mlme_op_in_progress;
91 };
92 
93 /**
94  * union wlan_serialization_rules_info - union of all rules info structures
95  * @scan_info: information needed to apply rules on scan command
96  */
97 union wlan_serialization_rules_info {
98 	struct wlan_serialization_scan_info scan_info;
99 };
100 
101 /**
102  * wlan_serialization_cmd_callback() - Callback registered by the component
103  * @wlan_cmd: Command passed by the component for serialization
104  * @reason: Reason code for which the callback is being called
105  *
106  * Reason specifies the reason for which the callback is being called. callback
107  * should return success or failure based up on overall success of callback.
108  * if callback returns failure then serialization will remove the command from
109  * active queue and proceed for next pending command.
110  *
111  * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE
112  */
113 typedef QDF_STATUS (*wlan_serialization_cmd_callback)(void *wlan_cmd,
114 				 enum wlan_serialization_cb_reason reason);
115 
116 /**
117  * wlan_serialization_comp_info_cb() - callback to fill the rules information
118  * @vdev: VDEV object for which the command has been received
119  * @comp_info: Information filled by the component
120  *
121  * This callback is registered dynamically by the component with the
122  * serialization component. Serialization component invokes the callback
123  * while applying the rules for a particular command and the component
124  * fills in the required information to apply the rules
125  *
126  * Return: None
127  */
128 typedef void (*wlan_serialization_comp_info_cb)(struct wlan_objmgr_vdev *vdev,
129 		union wlan_serialization_rules_info *comp_info);
130 
131 /**
132  * wlan_serialization_apply_rules_cb() - callback per command to apply rules
133  * @comp_info: information needed to apply the rules
134  *
135  * The rules are applied using this callback and decided whether to
136  * allow or deny the command
137  *
138  * Return: true, if rules are successful and cmd can be queued
139  *         false, if rules failed and cmd should not be queued
140  */
141 typedef bool (*wlan_serialization_apply_rules_cb)(
142 		union wlan_serialization_rules_info *comp_info,
143 		uint8_t comp_id);
144 
145 /**
146  * enum wlan_umac_cmd_id - Command Type
147  * @WLAN_SER_CMD_SCAN:     Scan command
148  */
149 enum wlan_serialization_cmd_type {
150 	/* all scan command before non-scan */
151 	WLAN_SER_CMD_SCAN,
152 	/* all non-scan command below */
153 	WLAN_SER_CMD_NONSCAN,
154 	WLAN_SER_CMD_HDD_ISSUE_REASSOC_SAME_AP,
155 	WLAN_SER_CMD_SME_ISSUE_REASSOC_SAME_AP,
156 	WLAN_SER_CMD_SME_ISSUE_DISASSOC_FOR_HANDOFF,
157 	WLAN_SER_CMD_SME_ISSUE_ASSOC_TO_SIMILAR_AP,
158 	WLAN_SER_CMD_FORCE_IBSS_LEAVE,
159 	WLAN_SER_CMD_SME_ISSUE_FT_REASSOC,
160 	WLAN_SER_CMD_FORCE_DISASSOC_STA,
161 	WLAN_SER_CMD_FORCE_DEAUTH_STA,
162 	WLAN_SER_CMD_PERFORM_PRE_AUTH,
163 	WLAN_SER_CMD_WM_STATUS_CHANGE,
164 	WLAN_SER_CMD_NDP_INIT_REQ,
165 	WLAN_SER_CMD_NDP_RESP_REQ,
166 	WLAN_SER_CMD_NDP_DATA_END_INIT_REQ,
167 	WLAN_SER_CMD_ADDTS,
168 	WLAN_SER_CMD_DELTS,
169 	WLAN_SER_CMD_TDLS_SEND_MGMT,
170 	WLAN_SER_CMD_TDLS_ADD_PEER,
171 	WLAN_SER_CMD_TDLS_DEL_PEER,
172 	WLAN_SER_CMD_SET_HW_MODE,
173 	WLAN_SER_CMD_NSS_UPDATE,
174 	WLAN_SER_CMD_SET_DUAL_MAC_CONFIG,
175 	WLAN_SER_CMD_SET_ANTENNA_MODE,
176 	WLAN_SER_CMD_DEL_STA_SESSION,
177 	WLAN_SER_CMD_VDEV_START_BSS,
178 	WLAN_SER_CMD_VDEV_STOP_BSS,
179 	WLAN_SER_CMD_VDEV_CONNECT,
180 	WLAN_SER_CMD_VDEV_DISCONNECT,
181 	WLAN_SER_CMD_VDEV_RESTART,
182 	WLAN_SER_CMD_MAX
183 };
184 
185 /**
186  * enum wlan_serialization_cancel_type - Type of commands to be cancelled
187  * @WLAN_SER_CANCEL_SINGLE_SCAN: Cancel a single scan with a given ID
188  * @WLAN_SER_CANCEL_PDEV_SCANS: Cancel all the scans on a given pdev
189  * @WLAN_SER_CANCEL_VDEV_SCANS: Cancel all the scans on given vdev
190  * @WLAN_SER_CANCEL_PDEV_NON_SCAN_CMD: Cancel all non scans on a given pdev
191  * @WLAN_SER_CANCEL_VDEV_NON_SCAN_CMD: Cancel all non scans on a given vdev
192  * @WLAN_SER_CANCEL_VDEV_NON_SCAN_CMD_TYPE: Cancel all non scans on a given vdev
193  * and matching cmd type
194  * @WLAN_SER_CANCEL_NON_SCAN_CMD: Cancel the given non scan command
195  */
196 enum wlan_serialization_cancel_type {
197 	WLAN_SER_CANCEL_SINGLE_SCAN,
198 	WLAN_SER_CANCEL_PDEV_SCANS,
199 	WLAN_SER_CANCEL_VDEV_SCANS,
200 	WLAN_SER_CANCEL_PDEV_NON_SCAN_CMD,
201 	WLAN_SER_CANCEL_VDEV_NON_SCAN_CMD,
202 	WLAN_SER_CANCEL_VDEV_NON_SCAN_CMD_TYPE,
203 	WLAN_SER_CANCEL_NON_SCAN_CMD,
204 	WLAN_SER_CANCEL_MAX,
205 };
206 
207 /**
208  * enum wlan_serialization_status - Return status of cmd serialization request
209  * @WLAN_SER_CMD_PENDING: Command is put into the pending queue
210  * @WLAN_SER_CMD_ACTIVE: Command is activated and put in active queue
211  * @WLAN_SER_CMD_DENIED_RULES_FAILED: Command denied as the rules fail
212  * @WLAN_SER_CMD_DENIED_LIST_FULL: Command denied as the pending list is full
213  * @WLAN_SER_CMD_QUEUE_DISABLED: Command denied as the queue is disabled
214  * @WLAN_SER_CMD_ALREADY_EXISTS: Command already exists in the queue
215  * @WLAN_SER_CMD_DENIED_UNSPECIFIED: Command denied due to unknown reason
216  */
217 enum wlan_serialization_status {
218 	WLAN_SER_CMD_PENDING,
219 	WLAN_SER_CMD_ACTIVE,
220 	WLAN_SER_CMD_DENIED_RULES_FAILED,
221 	WLAN_SER_CMD_DENIED_LIST_FULL,
222 	WLAN_SER_CMD_QUEUE_DISABLED,
223 	WLAN_SER_CMD_ALREADY_EXISTS,
224 	WLAN_SER_CMD_DENIED_UNSPECIFIED,
225 };
226 
227 /**
228  * enum wlan_serialization_cmd_status - Return status for a cancel request
229  * @WLAN_SER_CMD_IN_PENDING_LIST: Command cancelled from pending list
230  * @WLAN_SER_CMD_IN_ACTIVE_LIST: Command cancelled from active list
231  * @WLAN_SER_CMDS_IN_ALL_LISTS: Command cancelled from all lists
232  * @WLAN_SER_CMD_NOT_FOUND: Specified command to be cancelled
233  *                                    not found in the lists
234  */
235 enum wlan_serialization_cmd_status {
236 	WLAN_SER_CMD_IN_PENDING_LIST,
237 	WLAN_SER_CMD_IN_ACTIVE_LIST,
238 	WLAN_SER_CMDS_IN_ALL_LISTS,
239 	WLAN_SER_CMD_MARKED_FOR_ACTIVATION,
240 	WLAN_SER_CMD_NOT_FOUND,
241 };
242 
243 /**
244  * struct wlan_serialization_command - Command to be serialized
245  * @wlan_serialization_cmd_type: Type of command
246  * @cmd_id: Command Identifier
247  * @cmd_cb: Command callback
248  * @source: component ID of the source of the command
249  * @is_high_priority: Normal/High Priority at which the cmd has to be queued
250  * @is_blocking: Is the command blocking
251  * @queue_disable: Should the command disable the queues
252  * @activation_reason: reason the activation cb was called
253  * @cmd_timeout_cb: Command timeout callback
254  * @cmd_timeout_duration: Timeout duration in milliseconds
255  * @vdev: VDEV object associated to the command
256  * @umac_cmd: Actual command that needs to be sent to WMI/firmware
257  *
258  * Note: Unnamed union has been used in this structure, so that in future if
259  * somebody wants to add pdev or psoc structure then that person can add without
260  * modifying existing code.
261  */
262 struct wlan_serialization_command {
263 	enum wlan_serialization_cmd_type cmd_type;
264 	uint32_t cmd_id;
265 	wlan_serialization_cmd_callback cmd_cb;
266 	enum wlan_umac_comp_id source;
267 	uint8_t is_high_priority:1,
268 		is_blocking:1,
269 		queue_disable:1,
270 		activation_reason:3;
271 	uint32_t cmd_timeout_duration;
272 	union {
273 		struct wlan_objmgr_vdev *vdev;
274 	};
275 	void *umac_cmd;
276 };
277 
278 /**
279  * struct wlan_serialization_queued_cmd_info  - cmd that has to be cancelled
280  * @requestor: component ID of the source requesting this action
281  * @cmd_type: Command type
282  * @cmd_id: Command ID
283  * @req_type: Commands that need to be cancelled
284  * @vdev: VDEV object associated to the command
285  * @queue_type: Queues from which the command to be cancelled
286  */
287 struct wlan_serialization_queued_cmd_info {
288 	enum wlan_umac_comp_id requestor;
289 	enum wlan_serialization_cmd_type cmd_type;
290 	uint32_t cmd_id;
291 	enum wlan_serialization_cancel_type req_type;
292 	union {
293 		struct wlan_objmgr_vdev *vdev;
294 	};
295 	uint8_t queue_type;
296 };
297 
298 /**
299  * wlan_serialization_cancel_request() - Request to cancel a command
300  * @req: Request information
301  *
302  * This API is used by external components to cancel a command
303  * that is either in the pending or active queue. Based on the
304  * req_type, it is decided whether to use pdev or vdev
305  * object. For all non-scan commands, it will be pdev.
306  *
307  * Return: Status specifying the removal of a command from a certain queue
308  */
309 enum wlan_serialization_cmd_status
310 wlan_serialization_cancel_request(
311 		struct wlan_serialization_queued_cmd_info *req);
312 
313 /**
314  * wlan_serialization_remove_cmd() - Request to release a command
315  * @cmd: Command information
316  *
317  * This API is used to release a command sitting in the active
318  * queue upon successful completion of the command
319  *
320  * Return: None
321  */
322 void wlan_serialization_remove_cmd(
323 		struct wlan_serialization_queued_cmd_info *cmd);
324 
325 /**
326  * wlan_serialization_flush_cmd() - Request to flush command
327  * @cmd: Command information
328  *
329  * This API is used to flush a cmd sitting in the queue. It
330  * simply flushes the cmd from the queue and does not call
331  * any callbacks in between. If the request is for active
332  * queue, and if the active queue becomes empty upon flush,
333  * then it will pick the next pending cmd and put in the active
334  * queue before returning.
335  *
336  * Return: None
337  */
338 void wlan_serialization_flush_cmd(
339 		struct wlan_serialization_queued_cmd_info *cmd);
340 
341 /**
342  * wlan_serialization_update_timer() -Update timer for an active command
343  * @cmd: Command information
344  *
345  * Return: Status of the timer update
346  */
347 QDF_STATUS
348 wlan_serialization_update_timer(struct wlan_serialization_command *cmd);
349 
350 /**
351  * wlan_serialization_request() - Request to serialize a command
352  * @cmd: Command information
353  *
354  * Return: Status of the serialization request
355  */
356 enum wlan_serialization_status
357 wlan_serialization_request(struct wlan_serialization_command *cmd);
358 
359 /**
360  * wlan_serialization_register_comp_info_cb() - Register component's info cb
361  * @psoc: PSOC object information
362  * @comp_id: Component ID
363  * @cmd_type: Command Type
364  * @cb: Callback
365  *
366  * This is called from component during its initialization.It initializes
367  * callback handler for given comp_id/cmd_id in a 2-D array.
368  *
369  * Return: QDF Status
370  */
371 QDF_STATUS
372 wlan_serialization_register_comp_info_cb(
373 		struct wlan_objmgr_psoc *psoc,
374 		enum wlan_umac_comp_id comp_id,
375 		enum wlan_serialization_cmd_type cmd_type,
376 		wlan_serialization_comp_info_cb cb);
377 
378 /**
379  * wlan_serialization_deregister_comp_info_cb() - Deregister component's info
380  *						callback
381  * @psoc: PSOC object information
382  * @comp_id: Component ID
383  * @cmd_type: Command Type
384  *
385  * This routine is called from other component during its de-initialization.
386  *
387  * Return: QDF Status
388  */
389 QDF_STATUS
390 wlan_serialization_deregister_comp_info_cb(
391 		struct wlan_objmgr_psoc *psoc,
392 		enum wlan_umac_comp_id comp_id,
393 		enum wlan_serialization_cmd_type cmd_type);
394 
395 /**
396  * wlan_serialization_register_apply_rules_cb() - Register component's rules
397  *						callback
398  * @psoc: PSOC object information
399  * @cmd_type: Command Type
400  * @cb: Callback
401  *
402  * This is called from component during its initialization.It initializes
403  * callback handler for given cmd_type in a 1-D array.
404  *
405  * Return: QDF Status
406  */
407 QDF_STATUS
408 wlan_serialization_register_apply_rules_cb(
409 		struct wlan_objmgr_psoc *psoc,
410 		enum wlan_serialization_cmd_type cmd_type,
411 		wlan_serialization_apply_rules_cb apply_rules_cb);
412 
413 /**
414  * wlan_serialization_deregister_apply_rules_cb() - Deregister component's rules
415  *						callback
416  * @psoc: PSOC object information
417  * @cmd_type: Command Type
418  *
419  * This routine is called from other component during its de-initialization.
420  *
421  * Return: QDF Status
422  */
423 QDF_STATUS
424 wlan_serialization_deregister_apply_rules_cb(
425 		struct wlan_objmgr_psoc *psoc,
426 		enum wlan_serialization_cmd_type cmd_type);
427 
428 /**
429  * @wlan_serialization_init() - Serialization component initialization routine
430  *
431  * Return - QDF Status
432  */
433 QDF_STATUS wlan_serialization_init(void);
434 
435 /**
436  * @wlan_serialization_deinit() - Serialization component de-init routine
437  *
438  * Return - QDF Status
439  */
440 QDF_STATUS wlan_serialization_deinit(void);
441 
442 /**
443  * @wlan_serialization_psoc_enable() - Serialization component enable routine
444  *
445  * Return - QDF Status
446  */
447 QDF_STATUS wlan_serialization_psoc_enable(struct wlan_objmgr_psoc *psoc);
448 
449 /**
450  * @wlan_serialization_psoc_disable() - Serialization component disable routine
451  *
452  * Return - QDF Status
453  */
454 QDF_STATUS wlan_serialization_psoc_disable(struct wlan_objmgr_psoc *psoc);
455 
456 /**
457  * wlan_serialization_vdev_scan_status() - Return the status of the vdev scan
458  * @vdev: VDEV Object
459  *
460  * Return: Status of the scans for the corresponding vdev
461  */
462 enum wlan_serialization_cmd_status
463 wlan_serialization_vdev_scan_status(struct wlan_objmgr_vdev *vdev);
464 
465 /**
466  * wlan_serialization_pdev_scan_status() - Return the status of the pdev scan
467  * @pdev: PDEV Object
468  *
469  * Return: Status of the scans for the corresponding pdev
470  */
471 enum wlan_serialization_cmd_status
472 wlan_serialization_pdev_scan_status(struct wlan_objmgr_pdev *pdev);
473 
474 /**
475  * wlan_serialization_non_scan_cmd_status() - Return status of pdev non-scan cmd
476  * @pdev: PDEV Object
477  * @cmd_id: ID of the command for which the status has to be checked
478  *
479  * Return: Status of the command for the corresponding pdev
480  */
481 enum wlan_serialization_cmd_status
482 wlan_serialization_non_scan_cmd_status(struct wlan_objmgr_pdev *pdev,
483 				       enum wlan_serialization_cmd_type cmd_id);
484 
485 /**
486  * wlan_serialization_is_cmd_present_in_pending_queue() - Return if the command
487  *				is already present in pending queue
488  * @cmd: pointer to serialization command to check
489  *
490  * This API will check if command is present in pending queue. If present
491  * then return true, so use know that it is duplicated command
492  *
493  * Return: true or false
494  */
495 bool wlan_serialization_is_cmd_present_in_pending_queue(
496 		struct wlan_objmgr_psoc *psoc,
497 		struct wlan_serialization_command *cmd);
498 /**
499  * wlan_serialization_is_cmd_present_in_active_queue() - Return if the command
500  *			is already present in active queue
501  * @cmd: pointer to serialization command to check
502  *
503  * This API will check if command is present in active queue. If present
504  * then return true, so use know that it is duplicated command
505  *
506  * Return: true or false
507  */
508 bool wlan_serialization_is_cmd_present_in_active_queue(
509 		struct wlan_objmgr_psoc *psoc,
510 		struct wlan_serialization_command *cmd);
511 
512 /**
513  * wlan_serialization_get_scan_cmd_using_scan_id() - Return command which
514  *					matches vdev_id and scan_id
515  * @psoc: pointer to soc
516  * @vdev_id: vdev id to pull vdev object
517  * @scan_id: scan id to match
518  * @is_scan_cmd_from_active_queue: to indicate active or pending queue
519  *
520  * This API fetches vdev/pdev object based on vdev_id, loops through scan
521  * command queue and find the command which matches scan id as well as vdev
522  * object.
523  *
524  * Return: pointer to serialization command
525  */
526 struct wlan_serialization_command*
527 wlan_serialization_get_scan_cmd_using_scan_id(
528 		struct wlan_objmgr_psoc *psoc,
529 		uint8_t vdev_id, uint16_t scan_id,
530 		uint8_t is_scan_cmd_from_active_queue);
531 /**
532  * wlan_serialization_get_active_cmd() - Return active umac command which
533  *  matches vdev and cmd type
534  * @psoc: pointer to soc
535  * @vdev_id: vdev id to pull vdev object
536  * @cmd_type: cmd type to match
537  *
538  * This API fetches vdev/pdev object based on vdev_id, loops through active
539  * command queue and find the active command which matches cmd_type as well
540  * as vdev object.
541  *
542  * Return: Pointer to umac command. NULL is returned if active command of given
543  *  type is not found.
544  */
545 void *wlan_serialization_get_active_cmd(
546 		struct wlan_objmgr_psoc *psoc,
547 		uint8_t vdev_id,
548 		enum wlan_serialization_cmd_type cmd_type);
549 
550 /**
551  * wlan_serialization_get_active_cmd() - Return active umac command which
552  *  matches vdev and cmd type
553  * @vdev: vdev object
554  *
555  * This API fetches command type of the command in the vdev active queue
556  *
557  * Return: command type of the command in the vdev active queue
558  */
559 
560 enum wlan_serialization_cmd_type
561 wlan_serialization_get_vdev_active_cmd_type(struct wlan_objmgr_vdev *vdev);
562 #endif
563