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