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