xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/serialization/inc/wlan_serialization_api.h (revision 1b9674e21e24478fba4530f5ae7396b9555e9c6a)
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 successful 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 	/* all non-scan command below */
132 	WLAN_SER_CMD_NONSCAN,
133 	WLAN_SER_CMD_FORCE_DISASSOC,
134 	WLAN_SER_CMD_HDD_ISSUED,
135 	WLAN_SER_CMD_LOST_LINK1,
136 	WLAN_SER_CMD_LOST_LINK2,
137 	WLAN_SER_CMD_LOST_LINK3,
138 	WLAN_SER_CMD_FORCE_DISASSOC_MIC_FAIL,
139 	WLAN_SER_CMD_HDD_ISSUE_REASSOC_SAME_AP,
140 	WLAN_SER_CMD_SME_ISSUE_REASSOC_SAME_AP,
141 	WLAN_SER_CMD_FORCE_DEAUTH,
142 	WLAN_SER_CMD_SME_ISSUE_DISASSOC_FOR_HANDOFF,
143 	WLAN_SER_CMD_SME_ISSUE_ASSOC_TO_SIMILAR_AP,
144 	WLAN_SER_CMD_SME_ISSUE_IBSS_JOIN_FAIL,
145 	WLAN_SER_CMD_FORCE_IBSS_LEAVE,
146 	WLAN_SER_CMD_STOP_BSS,
147 	WLAN_SER_CMD_SME_ISSUE_FT_REASSOC,
148 	WLAN_SER_CMD_FORCE_DISASSOC_STA,
149 	WLAN_SER_CMD_FORCE_DEAUTH_STA,
150 	WLAN_SER_CMD_PERFORM_PRE_AUTH,
151 	WLAN_SER_CMD_WM_STATUS_CHANGE,
152 	WLAN_SER_CMD_SET_KEY,
153 	WLAN_SER_CMD_NDP_INIT_REQ,
154 	WLAN_SER_CMD_NDP_RESP_REQ,
155 	WLAN_SER_CMD_NDP_DATA_END_INIT_REQ,
156 	WLAN_SER_CMD_ADDTS,
157 	WLAN_SER_CMD_DELTS,
158 	WLAN_SER_CMD_TDLS_SEND_MGMT,
159 	WLAN_SER_CMD_TDLS_ADD_PEER,
160 	WLAN_SER_CMD_TDLS_DEL_PEER,
161 	WLAN_SER_CMD_TDLS_LINK_EST,
162 	WLAN_SER_CMD_SET_HW_MODE,
163 	WLAN_SER_CMD_NSS_UPDATE,
164 	WLAN_SER_CMD_SET_DUAL_MAC_CONFIG,
165 	WLAN_SER_CMD_SET_ANTENNA_MODE,
166 	WLAN_SER_CMD_ENTER_BMPS,
167 	WLAN_SER_CMD_EXIT_BMPS,
168 	WLAN_SER_CMD_ENTER_UAPSD,
169 	WLAN_SER_CMD_EXIT_UAPSD,
170 	WLAN_SER_CMD_EXIT_WOWL,
171 	WLAN_SER_CMD_DEL_STA_SESSION,
172 	WLAN_SER_CMD_MAX
173 };
174 
175 /**
176  * enum wlan_serialization_cancel_type - Type of commands to be cancelled
177  * @WLAN_SER_CANCEL_SINGLE_SCAN: Cancel a single scan with a given ID
178  * @WLAN_SER_CANCEL_PDEV_SCANS: Cancel all the scans on a given pdev
179  * @WLAN_SER_CANCEL_VDEV_SCANS: Cancel all the scans on given vdev
180  * @WLAN_SER_CANCEL_NON_SCAN_CMD: Cancel the given non scan command
181  */
182 enum wlan_serialization_cancel_type {
183 	WLAN_SER_CANCEL_SINGLE_SCAN,
184 	WLAN_SER_CANCEL_PDEV_SCANS,
185 	WLAN_SER_CANCEL_VDEV_SCANS,
186 	WLAN_SER_CANCEL_NON_SCAN_CMD,
187 	WLAN_SER_CANCEL_MAX,
188 };
189 
190 /**
191  * enum wlan_serialization_status - Return status of cmd serialization request
192  * @WLAN_SER_CMD_PENDING: Command is put into the pending queue
193  * @WLAN_SER_CMD_ACTIVE: Command is activated and put in active queue
194  * @WLAN_SER_CMD_DENIED_RULES_FAILED: Command denied as the rules fail
195  * @WLAN_SER_CMD_DENIED_LIST_FULL: Command denied as the pending list is full
196  * @WLAN_SER_CMD_DENIED_UNSPECIFIED: Command denied due to unknown reason
197  */
198 enum wlan_serialization_status {
199 	WLAN_SER_CMD_PENDING,
200 	WLAN_SER_CMD_ACTIVE,
201 	WLAN_SER_CMD_DENIED_RULES_FAILED,
202 	WLAN_SER_CMD_DENIED_LIST_FULL,
203 	WLAN_SER_CMD_DENIED_UNSPECIFIED,
204 };
205 
206 /**
207  * enum wlan_serialization_cmd_status - Return status for a cancel request
208  * @WLAN_SER_CMD_IN_PENDING_LIST: Command cancelled from pending list
209  * @WLAN_SER_CMD_IN_ACTIVE_LIST: Command cancelled from active list
210  * @WLAN_SER_CMDS_IN_ALL_LISTS: Command cancelled from all lists
211  * @WLAN_SER_CMD_NOT_FOUND: Specified command to be cancelled
212  *                                    not found in the lists
213  */
214 enum wlan_serialization_cmd_status {
215 	WLAN_SER_CMD_IN_PENDING_LIST,
216 	WLAN_SER_CMD_IN_ACTIVE_LIST,
217 	WLAN_SER_CMDS_IN_ALL_LISTS,
218 	WLAN_SER_CMD_NOT_FOUND,
219 };
220 
221 /**
222  * struct wlan_serialization_command - Command to be serialized
223  * @wlan_serialization_cmd_type: Type of command
224  * @cmd_id: Command Identifier
225  * @cmd_cb: Command callback
226  * @source: component ID of the source of the command
227  * @is_high_priority: Normal/High Priority at which the cmd has to be queued
228  * @cmd_timeout_cb: Command timeout callback
229  * @cmd_timeout_duration: Timeout duration in milliseconds
230  * @vdev: VDEV object associated to the command
231  * @umac_cmd: Actual command that needs to be sent to WMI/firmware
232  *
233  * Note: Unnamed union has been used in this structure, so that in future if
234  * somebody wants to add pdev or psoc structure then that person can add without
235  * modifying existing code.
236  */
237 struct wlan_serialization_command {
238 	enum wlan_serialization_cmd_type cmd_type;
239 	uint32_t cmd_id;
240 	wlan_serialization_cmd_callback cmd_cb;
241 	enum wlan_umac_comp_id source;
242 	bool is_high_priority;
243 	uint16_t cmd_timeout_duration;
244 	union {
245 		struct wlan_objmgr_vdev *vdev;
246 	};
247 	void *umac_cmd;
248 };
249 
250 /**
251  * struct wlan_serialization_queued_cmd_info  - cmd that has to be cancelled
252  * @requestor: component ID of the source requesting this action
253  * @cmd_type: Command type
254  * @cmd_id: Command ID
255  * @req_type: Commands that need to be cancelled
256  * @vdev: VDEV object associated to the command
257  * @queue_type: Queues from which the command to be cancelled
258  */
259 struct wlan_serialization_queued_cmd_info {
260 	enum wlan_umac_comp_id requestor;
261 	enum wlan_serialization_cmd_type cmd_type;
262 	uint32_t cmd_id;
263 	enum wlan_serialization_cancel_type req_type;
264 	union {
265 		struct wlan_objmgr_vdev *vdev;
266 	};
267 	uint8_t queue_type;
268 };
269 
270 /**
271  * wlan_serialization_cancel_request() - Request to cancel a command
272  * @req: Request information
273  *
274  * This API is used by external components to cancel a command
275  * that is either in the pending or active queue. Based on the
276  * req_type, it is decided whether to use pdev or vdev
277  * object. For all non-scan commands, it will be pdev.
278  *
279  * Return: Status specifying the removal of a command from a certain queue
280  */
281 enum wlan_serialization_cmd_status
282 wlan_serialization_cancel_request(
283 		struct wlan_serialization_queued_cmd_info *req);
284 
285 /**
286  * wlan_serialization_remove_cmd() - Request to release a command
287  * @cmd: Command information
288  *
289  * This API is used to release a command sitting in the active
290  * queue upon successful completion of the command
291  *
292  * Return: None
293  */
294 void wlan_serialization_remove_cmd(
295 		struct wlan_serialization_queued_cmd_info *cmd);
296 
297 /**
298  * wlan_serialization_flush_cmd() - Request to flush command
299  * @cmd: Command information
300  *
301  * This API is used to flush a cmd sitting in the queue. It
302  * simply flushes the cmd from the queue and does not call
303  * any callbacks in between. If the request is for active
304  * queue, and if the active queue becomes empty upon flush,
305  * then it will pick the next pending cmd and put in the active
306  * queue before returning.
307  *
308  * Return: None
309  */
310 void wlan_serialization_flush_cmd(
311 		struct wlan_serialization_queued_cmd_info *cmd);
312 /**
313  * wlan_serialization_request() - Request to serialize a command
314  * @cmd: Command information
315  *
316  * Return: Status of the serialization request
317  */
318 enum wlan_serialization_status
319 wlan_serialization_request(struct wlan_serialization_command *cmd);
320 
321 /**
322  * wlan_serialization_register_comp_info_cb() - Register component's info
323  * 						callback
324  * @psoc: PSOC object information
325  * @comp_id: Component ID
326  * @cmd_type: Command Type
327  * @cb: Callback
328  *
329  * This is called from component during its initialization.It initializes
330  * callback handler for given comp_id/cmd_id in a 2-D array.
331  *
332  * Return: QDF Status
333  */
334 QDF_STATUS
335 wlan_serialization_register_comp_info_cb(struct wlan_objmgr_psoc *psoc,
336 		enum wlan_umac_comp_id comp_id,
337 		enum wlan_serialization_cmd_type cmd_type,
338 		wlan_serialization_comp_info_cb cb);
339 
340 /**
341  * wlan_serialization_deregister_comp_info_cb() - Deregister component's info
342  *						callback
343  * @psoc: PSOC object information
344  * @comp_id: Component ID
345  * @cmd_type: Command Type
346  *
347  * This routine is called from other component during its de-initialization.
348  *
349  * Return: QDF Status
350  */
351 QDF_STATUS
352 wlan_serialization_deregister_comp_info_cb(struct wlan_objmgr_psoc *psoc,
353 		enum wlan_umac_comp_id comp_id,
354 		enum wlan_serialization_cmd_type cmd_type);
355 
356 /**
357  * wlan_serialization_register_apply_rules_cb() - Register component's rules
358  *						callback
359  * @psoc: PSOC object information
360  * @cmd_type: Command Type
361  * @cb: Callback
362  *
363  * This is called from component during its initialization.It initializes
364  * callback handler for given cmd_type in a 1-D array.
365  *
366  * Return: QDF Status
367  */
368 QDF_STATUS
369 wlan_serialization_register_apply_rules_cb(struct wlan_objmgr_psoc *psoc,
370 		enum wlan_serialization_cmd_type cmd_type,
371 		wlan_serialization_apply_rules_cb apply_rules_cb);
372 
373 /**
374  * wlan_serialization_deregister_apply_rules_cb() - Deregister component's rules
375  *						callback
376  * @psoc: PSOC object information
377  * @cmd_type: Command Type
378  *
379  * This routine is called from other component during its de-initialization.
380  *
381  * Return: QDF Status
382  */
383 QDF_STATUS
384 wlan_serialization_deregister_apply_rules_cb(struct wlan_objmgr_psoc *psoc,
385 		enum wlan_serialization_cmd_type cmd_type);
386 
387 /**
388  * @wlan_serialization_init() - Serialization component initialization routine
389  *
390  * Return - QDF Status
391  */
392 QDF_STATUS wlan_serialization_init(void);
393 
394 /**
395  * @wlan_serialization_deinit() - Serialization component de-init routine
396  *
397  * Return - QDF Status
398  */
399 QDF_STATUS wlan_serialization_deinit(void);
400 
401 /**
402  * @wlan_serialization_psoc_open() - Serialization component open routine
403  *
404  * Return - QDF Status
405  */
406 QDF_STATUS wlan_serialization_psoc_open(struct wlan_objmgr_psoc *psoc);
407 
408 /**
409  * @wlan_serialization_psoc_close() - Serialization component close routine
410  *
411  * Return - QDF Status
412  */
413 QDF_STATUS wlan_serialization_psoc_close(struct wlan_objmgr_psoc *psoc);
414 
415 /**
416  * wlan_serialization_vdev_scan_status() - Return the status of the vdev scan
417  * @vdev: VDEV Object
418  *
419  * Return: Status of the scans for the corresponding vdev
420  */
421 enum wlan_serialization_cmd_status
422 wlan_serialization_vdev_scan_status(struct wlan_objmgr_vdev *vdev);
423 
424 /**
425  * wlan_serialization_pdev_scan_status() - Return the status of the pdev scan
426  * @pdev: PDEV Object
427  *
428  * Return: Status of the scans for the corresponding pdev
429  */
430 enum wlan_serialization_cmd_status
431 wlan_serialization_pdev_scan_status(struct wlan_objmgr_pdev *pdev);
432 
433 /**
434  * wlan_serialization_non_scan_cmd_status() - Return status of pdev non-scan cmd
435  * @pdev: PDEV Object
436  * @cmd_id: ID of the command for which the status has to be checked
437  *
438  * Return: Status of the command for the corresponding pdev
439  */
440 enum wlan_serialization_cmd_status
441 wlan_serialization_non_scan_cmd_status(struct wlan_objmgr_pdev *pdev,
442 		enum wlan_serialization_cmd_type cmd_id);
443 
444 /**
445  * wlan_serialization_is_cmd_present_in_pending_queue() - Return if the command
446  *				is already present in pending queue
447  * @cmd: pointer to serialization command to check
448  *
449  * This API will check if command is present in pending queue. If present
450  * then return true, so use know that it is duplicated command
451  *
452  * Return: true or false
453  */
454 bool wlan_serialization_is_cmd_present_in_pending_queue(
455 		struct wlan_objmgr_psoc *psoc,
456 		struct wlan_serialization_command *cmd);
457 /**
458  * wlan_serialization_is_cmd_present_in_active_queue() - Return if the command
459  *			is already present in active queue
460  * @cmd: pointer to serialization command to check
461  *
462  * This API will check if command is present in active queue. If present
463  * then return true, so use know that it is duplicated command
464  *
465  * Return: true or false
466  */
467 bool wlan_serialization_is_cmd_present_in_active_queue(
468 		struct wlan_objmgr_psoc *psoc,
469 		struct wlan_serialization_command *cmd);
470 
471 /**
472  * wlan_serialization_get_scan_cmd_using_scan_id() - Return command which
473  *					matches vdev_id and scan_id
474  * @psoc: pointer to soc
475  * @vdev_id: vdev id to pull vdev object
476  * @scan_id: scan id to match
477  * @is_scan_cmd_from_active_queue: to indicate active or pending queue
478  *
479  * This API fetches vdev/pdev object based on vdev_id, loops through scan
480  * command queue and find the command which matches scan id as well as vdev
481  * object.
482  *
483  * Return: pointer to serialization command
484  */
485 struct wlan_serialization_command*
486 wlan_serialization_get_scan_cmd_using_scan_id(
487 		struct wlan_objmgr_psoc *psoc,
488 		uint8_t vdev_id, uint16_t scan_id,
489 		uint8_t is_scan_cmd_from_active_queue);
490 /**
491  * wlan_serialization_get_active_cmd() - Return active umac command which
492  *  matches vdev and cmd type
493  * @psoc: pointer to soc
494  * @vdev_id: vdev id to pull vdev object
495  * @cmd_type: cmd type to match
496  *
497  * This API fetches vdev/pdev object based on vdev_id, loops through active
498  * command queue and find the active command which matches cmd_type as well
499  * as vdev object.
500  *
501  * Return: Pointer to umac command. NULL is returned if active command of given
502  *  type is not found.
503  */
504 void *wlan_serialization_get_active_cmd(struct wlan_objmgr_psoc *psoc,
505 				     uint8_t vdev_id,
506 				     enum wlan_serialization_cmd_type cmd_type);
507 #endif
508