xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/obj_mgr/inc/wlan_objmgr_cmn.h (revision a175314c51a4ce5cec2835cc8a8c7dc0c1810915)
1 /*
2  * Copyright (c) 2016-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: This file provides the common definitions for object manager
20   */
21 
22 #ifndef _WLAN_OBJMGR_CMN_H_
23 #define _WLAN_OBJMGR_CMN_H_
24 
25 #include "qdf_lock.h"
26 #include "qdf_list.h"
27 #include "qdf_status.h"
28 #include "wlan_cmn.h"
29 #include "qdf_atomic.h"
30 
31 /* No. of PSOCs can be supported */
32 #define WLAN_OBJMGR_MAX_DEVICES 3
33 
34 /* size of Hash */
35 #define WLAN_PEER_HASHSIZE 64
36 
37 /* simple hash is enough for variation of macaddr */
38 #define WLAN_PEER_HASH(addr)   \
39 (((const uint8_t *)(addr))[QDF_MAC_ADDR_SIZE - 1] % WLAN_PEER_HASHSIZE)
40 
41 #define obj_mgr_log(level, args...) \
42 		QDF_TRACE(QDF_MODULE_ID_OBJ_MGR, level, ## args)
43 #define obj_mgr_logfl(level, format, args...) \
44 		obj_mgr_log(level, FL(format), ## args)
45 #define obj_mgr_log_level(level, format, args...)\
46 		obj_mgr_logfl(level, format, ## args)
47 
48 #define obj_mgr_alert(params...) \
49 	QDF_TRACE_FATAL(QDF_MODULE_ID_OBJ_MGR, params)
50 #define obj_mgr_err(params...) \
51 	QDF_TRACE_ERROR(QDF_MODULE_ID_OBJ_MGR, params)
52 #define obj_mgr_warn(params...) \
53 	QDF_TRACE_WARN(QDF_MODULE_ID_OBJ_MGR, params)
54 #define obj_mgr_info(params...) \
55 	QDF_TRACE_INFO(QDF_MODULE_ID_OBJ_MGR, params)
56 #define obj_mgr_debug(params...) \
57 	QDF_TRACE_DEBUG(QDF_MODULE_ID_OBJ_MGR, params)
58 
59 /**
60  * enum WLAN_OBJ_STATE - State of Object
61  * @WLAN_OBJ_STATE_ALLOCATED:           Common object is allocated, but not
62  *                                      fully initialized
63  * @WLAN_OBJ_STATE_CREATED:             All component objects are created
64  * @WLAN_OBJ_STATE_DELETED:             All component objects are destroyed
65  * @WLAN_OBJ_STATE_PARTIALLY_CREATED:   Few/All component objects creation is
66  *                                      in progress
67  * @WLAN_OBJ_STATE_PARTIALLY_DELETED:   Component objects deletion is triggered,
68  *                                      they are yet to be destroyed
69  * @WLAN_OBJ_STATE_COMP_DEL_PROGRESS:   If a component is disabled run time,
70  *                                      and this state is used to represent the
71  *                                      deletion in progress after that
72  *                                      component object is destroyed, object
73  *                                      state would be moved to CREATED state
74  * @WLAN_OBJ_STATE_LOGICALLY_DELETED:   Object deletion has been initiated,
75  *                                      object destroy invoked once references
76  *                                      are released
77  * @WLAN_OBJ_STATE_CREATION_FAILED:     any component object is failed to be
78  *                                      created
79  * @WLAN_OBJ_STATE_DELETION_FAILED:     any component object is failed to be
80  *                                      destroyed
81  */
82 typedef enum {
83 	WLAN_OBJ_STATE_ALLOCATED          = 0,
84 	WLAN_OBJ_STATE_CREATED            = 1,
85 	WLAN_OBJ_STATE_DELETED            = 2,
86 	WLAN_OBJ_STATE_PARTIALLY_CREATED  = 3,
87 	WLAN_OBJ_STATE_PARTIALLY_DELETED  = 4,
88 	WLAN_OBJ_STATE_COMP_DEL_PROGRESS  = 5,
89 	WLAN_OBJ_STATE_LOGICALLY_DELETED  = 6,
90 	WLAN_OBJ_STATE_CREATION_FAILED    = 7,
91 	WLAN_OBJ_STATE_DELETION_FAILED    = 8,
92 } WLAN_OBJ_STATE;
93 
94 /* Object type is assigned with value */
95 enum wlan_objmgr_obj_type {
96 	WLAN_PSOC_OP      = 0,
97 	WLAN_PDEV_OP      = 1,
98 	WLAN_VDEV_OP      = 2,
99 	WLAN_PEER_OP      = 3,
100 	WLAN_OBJ_TYPE_MAX = 4,
101 };
102 
103 /**
104  * struct wlan_peer_list {
105  * @peer_hash[]:    peer sub lists
106  * @peer_list_lock: List lock, this has to be acquired on
107  *		    accessing/updating the list
108  *
109  *  Peer list, it maintains sublists based on the MAC address as hash
110  *  Note: For DA WDS similar peer list has to be maintained
111  *  This peer list will not have WDS nodes
112  */
113 struct wlan_peer_list {
114 	qdf_list_t peer_hash[WLAN_PEER_HASHSIZE];
115 	qdf_spinlock_t peer_list_lock;
116 };
117 
118 struct wlan_objmgr_psoc;
119 struct wlan_objmgr_pdev;
120 struct wlan_objmgr_vdev;
121 struct wlan_objmgr_peer;
122 
123 /* Create handler would return the following status
124 	QDF_STATUS_SUCCESS--
125 		For synchronous handler:- this is returned on successful
126 	component object creation
127 
128 	QDF_STATUS_COMP_DISABLED--
129 		For synchronous handler:- this is returned on if component
130 	doesn't want to allocate
131 
132 	QDF_STATUS_COMP_ASYNC--
133 		For asynchronous handler:- this is returned on if component
134 	needs a context break
135 
136 	QDF_STATUS_E_NOMEM--
137 		For synchronous handler:- this is returned on if component
138 	can't allocate
139 	QDF_STATUS_E_FAILURE--
140 		For synchronous handler:- If it is failed,
141 		For asynchronous handler:- If it is failed to post message
142 	(means, not required)/feature is not supported
143 */
144 typedef QDF_STATUS (*wlan_objmgr_psoc_create_handler)(
145 				struct wlan_objmgr_psoc *psoc, void *arg);
146 typedef QDF_STATUS (*wlan_objmgr_psoc_destroy_handler)(
147 				struct wlan_objmgr_psoc *psoc, void *arg);
148 typedef void (*wlan_objmgr_psoc_status_handler)(struct wlan_objmgr_psoc *psoc,
149 					 void *arg, QDF_STATUS status);
150 
151 typedef QDF_STATUS (*wlan_objmgr_pdev_create_handler)(
152 				struct wlan_objmgr_pdev *pdev, void *arg);
153 typedef QDF_STATUS (*wlan_objmgr_pdev_destroy_handler)(
154 				struct wlan_objmgr_pdev *pdev, void *arg);
155 typedef void (*wlan_objmgr_pdev_status_handler)(
156 				struct wlan_objmgr_pdev *pdev, void *arg,
157 						QDF_STATUS status);
158 
159 typedef QDF_STATUS (*wlan_objmgr_vdev_create_handler)(
160 				struct wlan_objmgr_vdev *vdev, void *arg);
161 typedef QDF_STATUS (*wlan_objmgr_vdev_destroy_handler)(
162 				struct wlan_objmgr_vdev *vdev, void *arg);
163 typedef void (*wlan_objmgr_vdev_status_handler)(
164 				struct wlan_objmgr_vdev *vdev, void *arg,
165 						QDF_STATUS status);
166 
167 typedef QDF_STATUS (*wlan_objmgr_peer_create_handler)(
168 				struct wlan_objmgr_peer *peer, void *arg);
169 typedef QDF_STATUS (*wlan_objmgr_peer_destroy_handler)(
170 				struct wlan_objmgr_peer *peer, void *arg);
171 typedef void (*wlan_objmgr_peer_status_handler)(
172 				struct wlan_objmgr_peer *peer, void *arg,
173 						QDF_STATUS status);
174 
175 /**
176  * enum wlan_objmgr_ref_dbgid - ref count debug id
177  * @WLAN_OBJMGR_ID:             Object manager internal operations
178  * @WLAN_MLME_SB_ID:            MLME Southbound operations
179  * @WLAN_MLME_NB_ID:            MLME Northbound operations
180  * @WLAN_MGMT_SB_ID:            MGMT Northbound operations
181  * @WLAN_MGMT_NB_ID:            MGMT Southbound operations
182  * @WLAN_HDD_ID_OBJ_MGR:        HDD Object Manager operations
183  * @WLAN_OSIF_ID:               New component's OS IF ID
184  * @WLAN_LEGACY_MAC_ID:         Legacy MAC operations
185  * @WLAN_LEGACY_WMA_ID:         Legacy WMA operations
186  * @WLAN_SERIALIZATION_ID:      Serialization operations
187  * @WLAN_PMO_ID:                power manager offload (PMO) ID
188  * @WLAN_LEGACY_SME_ID:         Legacy SME operations
189  * @WLAN_SCAN_ID:               scan operations
190  * @WLAN_WIFI_POS_CORE_ID:      wifi positioning (CORE)
191  * @WLAN_DFS_ID:                DFS operations
192  * @WLAN_P2P_ID:                P2P operations
193  * @WLAN_TDLS_SB_ID:            TDLS Southbound operations
194  * @WLAN_TDLS_NB_ID:            TDLS Northbound operations
195  * @WLAN_ATF_ID:                Airtime Fairness operations
196  * @WLAN_CRYPTO_ID:             Crypto service operation
197  * @WLAN_NAN_ID:                nan operations
198  * @WLAN_REGULATORY_SB_ID:      SB regulatory operations
199  * @WLAN_REGULATORY_NB_ID:      NB regulatory operations
200  * @WLAN_POLICY_MGR_ID:         Policy Manager operations
201  * @WLAN_SON_ID:                SON
202  * @WLAN_SA_API_ID:             SA PAI
203  * @WLAN_SPECTRAL_ID:           Spectral operations
204  * @WLAN_SPLITMAC_ID:           SplitMac
205  * @WLAN_DEBUG_ID:              Debug operations
206  * @WLAN_DIRECT_BUF_RX_ID:      Direct Buffer Receive operations
207  * @WLAN_DISA_ID:               DISA (encryption test) operations
208  * @WLAN_FTM_ID:                FTM module
209  * @WLAN_FD_ID:                 FILS Discovery
210  * @WLAN_OCB_NB_ID:             OCB Northbound operations
211  * @WLAN_OCB_SB_ID:             OCB Southbound operations
212  * @WLAN_INIT_DEINIT_ID:        Init deinit module
213  * @WLAN_IPA_ID:                IPA operations
214  * @WLAN_CP_STATS_ID:           Control Plane Statistics Module
215  * @WLAN_GREEN_AP_ID:           Green AP operations
216  * @WLAN_WIFI_POS_OSIF_ID:      wifi positioning (OSID)
217  * @WLAN_WIFI_POS_TGT_IF_ID:    wifi positioning (Target IF)
218  * @WLAN_REF_ID_MAX:            Max id used to generate ref count tracking array
219  */
220  /* New value added to the enum must also be reflected in function
221   * string_from_dbgid()
222   */
223 typedef enum {
224 	WLAN_OBJMGR_ID        = 0,
225 	WLAN_MLME_SB_ID       = 1,
226 	WLAN_MLME_NB_ID       = 2,
227 	WLAN_MGMT_SB_ID       = 3,
228 	WLAN_MGMT_NB_ID       = 4,
229 	WLAN_HDD_ID_OBJ_MGR   = 5,
230 	WLAN_OSIF_ID          = 6,
231 	WLAN_LEGACY_MAC_ID    = 7,
232 	WLAN_LEGACY_WMA_ID    = 8,
233 	WLAN_SERIALIZATION_ID = 9,
234 	WLAN_PMO_ID           = 10,
235 	WLAN_LEGACY_SME_ID    = 11,
236 	WLAN_SCAN_ID          = 12,
237 	WLAN_WIFI_POS_CORE_ID = 13,
238 	WLAN_DFS_ID           = 14,
239 	WLAN_P2P_ID           = 15,
240 	WLAN_TDLS_SB_ID       = 16,
241 	WLAN_TDLS_NB_ID       = 17,
242 	WLAN_ATF_ID           = 18,
243 	WLAN_CRYPTO_ID        = 19,
244 	WLAN_NAN_ID           = 20,
245 	WLAN_REGULATORY_SB_ID = 21,
246 	WLAN_REGULATORY_NB_ID = 22,
247 	WLAN_OFFCHAN_TXRX_ID  = 23,
248 	WLAN_POLICY_MGR_ID    = 24,
249 	WLAN_SON_ID           = 25,
250 	WLAN_SA_API_ID        = 26,
251 	WLAN_SPECTRAL_ID      = 27,
252 	WLAN_SPLITMAC_ID      = 28,
253 	WLAN_DEBUG_ID         = 29,
254 	WLAN_DIRECT_BUF_RX_ID = 30,
255 	WLAN_DISA_ID          = 31,
256 	WLAN_FTM_ID           = 32,
257 	WLAN_FD_ID            = 33,
258 	WLAN_OCB_NB_ID        = 34,
259 	WLAN_OCB_SB_ID        = 35,
260 	WLAN_INIT_DEINIT_ID   = 36,
261 	WLAN_IPA_ID           = 37,
262 	WLAN_CP_STATS_ID      = 38,
263 	WLAN_GREEN_AP_ID      = 39,
264 	WLAN_WIFI_POS_OSIF_ID = 40,
265 	WLAN_WIFI_POS_TGT_IF_ID = 41,
266 	WLAN_REF_ID_MAX,
267 } wlan_objmgr_ref_dbgid;
268 
269 /**
270  * string_from_dbgid() - Convert Refcnt dbgid to respective string
271  * @id - Reference count debug id
272  *
273  * Debug support function to convert refcnt dbgid to string.
274  * Please note to add new string in the array at index equal to
275  * its enum value in wlan_objmgr_ref_dbgid.
276  */
277 static inline char *string_from_dbgid(wlan_objmgr_ref_dbgid id)
278 {
279 	static const char *strings[] = { "WLAN_OBJMGR_ID",
280 					"WLAN_MLME_SB_ID",
281 					"WLAN_MLME_NB_ID",
282 					"WLAN_MGMT_SB_ID",
283 					"WLAN_MGMT_NB_ID",
284 					"WLAN_HDD_ID_OBJ_MGR",
285 					"WLAN_OSIF_ID",
286 					"WLAN_LEGACY_MAC_ID",
287 					"WLAN_LEGACY_WMA_ID",
288 					"WLAN_SERIALIZATION_ID",
289 					"WLAN_PMO_ID",
290 					"WLAN_LEGACY_SME_ID",
291 					"WLAN_SCAN_ID",
292 					"WLAN_WIFI_POS_CORE_ID",
293 					"WLAN_DFS_ID",
294 					"WLAN_P2P_ID",
295 					"WLAN_TDLS_SB_ID",
296 					"WLAN_TDLS_NB_ID",
297 					"WLAN_ATF_ID",
298 					"WLAN_CRYPTO_ID",
299 					"WLAN_NAN_ID",
300 					"WLAN_REGULATORY_SB_ID",
301 					"WLAN_REGULATORY_NB_ID",
302 					"WLAN_OFFCHAN_TXRX_ID",
303 					"WLAN_POLICY_MGR_ID",
304 					"WLAN_SON_ID",
305 					"WLAN_SA_API_ID",
306 					"WLAN_SPECTRAL_ID",
307 					"WLAN_SPLITMAC_ID",
308 					"WLAN_DEBUG_ID",
309 					"WLAN_DIRECT_BUF_RX_ID",
310 					"WLAN_DISA_ID",
311 					"WLAN_FTM_ID",
312 					"WLAN_FD_ID",
313 					"WLAN_OCB_NB_ID",
314 					"WLAN_OCB_SB_ID",
315 					"WLAN_INIT_DEINIT_ID",
316 					"WLAN_IPA_ID",
317 					"WLAN_CP_STATS_ID",
318 					"WLAN_GREEN_AP_ID",
319 					"WLAN_WIFI_POS_OSIF_ID",
320 					"WLAN_WIFI_POS_TGT_IF_ID",
321 					"WLAN_REF_ID_MAX"};
322 
323 	return (char *)strings[id];
324 }
325 
326 #ifdef WLAN_OBJMGR_DEBUG
327 #define WLAN_OBJMGR_BUG(val) QDF_BUG(val)
328 #else
329 #define WLAN_OBJMGR_BUG(val)
330 #endif
331 #define WLAN_OBJMGR_RATELIMIT_THRESH 2
332 #endif /* _WLAN_OBJMGR_CMN_H_*/
333