xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/obj_mgr/inc/wlan_objmgr_peer_obj.h (revision 87a8e4458319c60b618522e263ed900e36aab528)
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: Define the peer data structure of UMAC
20   *	Public APIs to perform operations on Global objects
21   */
22 #ifndef _WLAN_OBJMGR_PEER_OBJ_H_
23 #define _WLAN_OBJMGR_PEER_OBJ_H_
24 
25 #include <qdf_types.h>
26 #include <qdf_atomic.h>
27 #include "wlan_objmgr_vdev_obj.h"
28 
29 /* peer flags */
30 /* authorized for data */
31 #define WLAN_PEER_F_AUTH                            0x00000001
32 /* QoS enabled */
33 #define WLAN_PEER_F_QOS                             0x00000002
34 /* ERP enabled */
35 #define WLAN_PEER_F_ERP                             0x00000004
36 /* HT enabled */
37 #define WLAN_PEER_F_HT                              0x00000008
38 /* NB: tWLANhave the same value as IEEE80211_FC1_PWR_MGT */
39 /* power save mode enabled */
40 #define WLAN_PEER_F_PWR_MGT                         0x00000010
41 /* keytsc for node has already been updated */
42 #define WLAN_PEER_F_TSC_SET                         0x00000020
43 /* U-APSD power save enabled */
44 #define WLAN_PEER_F_UAPSD                           0x00000040
45 /* U-APSD triggerable state */
46 #define WLAN_PEER_F_UAPSD_TRIG                      0x00000080
47 /* U-APSD SP in progress */
48 #define WLAN_PEER_F_UAPSD_SP                        0x00000100
49 /* Atheros Owl or follow-on device */
50 #define WLAN_PEER_F_ATH                             0x00000200
51 /* Owl WDS workaround needed*/
52 #define WLAN_PEER_F_OWL_WDSWAR                      0x00000400
53 /* WDS link */
54 #define WLAN_PEER_F_WDS                             0x00000800
55 /* No AMPDU support */
56 #define WLAN_PEER_F_NOAMPDU                         0x00001000
57 /* wep/tkip aggregation support */
58 #define WLAN_PEER_F_WEPTKIPAGGR                     0x00002000
59 #define WLAN_PEER_F_WEPTKIP                         0x00004000
60 /* temp node (not in the node table) */
61 #define WLAN_PEER_F_TEMP                            0x00008000
62 /* 2.4ng VHT interop AMSDU disabled */
63 #define WLAN_PEER_F_11NG_VHT_INTEROP_AMSDU_DISABLE  0x00010000
64 /* 40 MHz Intolerant  */
65 #define WLAN_PEER_F_40MHZ_INTOLERANT                0x00020000
66 /* node is  paused*/
67 #define WLAN_PEER_F_PAUSED                          0x00040000
68 #define WLAN_PEER_F_EXTRADELIMWAR                   0x00080000
69 /* 20 MHz requesting node */
70 #define WLAN_PEER_F_REQ_20MHZ                       0x00100000
71 /* all the tid queues in ath layer are paused*/
72 #define WLAN_PEER_F_ATH_PAUSED                      0x00200000
73 /*Require credit update*/
74 #define WLAN_PEER_F_UAPSD_CREDIT_UPDATE             0x00400000
75 /*Require send deauth when h/w queue no data*/
76 #define WLAN_PEER_F_KICK_OUT_DEAUTH                 0x00800000
77 /* RRM enabled node */
78 #define WLAN_PEER_F_RRM                             0x01000000
79 /* Wakeup node */
80 #define WLAN_PEER_F_WAKEUP                          0x02000000
81 /* VHT enabled node */
82 #define WLAN_PEER_F_VHT                             0x04000000
83 /* deauth/Disassoc wait for node cleanup till frame goes on
84    air and tx feedback received */
85 #define WLAN_PEER_F_DELAYED_CLEANUP                 0x08000000
86 /* Extended stats enabled node */
87 #define WLAN_PEER_F_EXT_STATS                       0x10000000
88 /* Prevent _ieee80211_node_leave() from reentry */
89 #define WLAN_PEER_F_LEAVE_ONGOING                   0x20000000
90 /* band steering is enabled for this node */
91 #define WLAN_PEER_F_BSTEERING_CAPABLE               0x40000000
92 /* node is a local mesh peer */
93 #define WLAN_PEER_F_LOCAL_MESH_PEER                 0x80000000
94 
95 /**
96  * enum wlan_peer_state  - peer state
97  * @WLAN_INIT_STATE:       Default state
98  * @WLAN_JOIN_STATE:       Station mode, STA is waiting for Join
99  * @WLAN_AUTH_STATE:       AUTH in progress
100  * @WLAN_ASSOC_STATE:      ASSOC in progress
101  * @WLAN_WAITKEY_STATE:    4-way KEY handshake is in progress
102  * @WLAN_CONNECTED_STATE:  Connected state
103  * @WLAN_PREAUTH_STATE:    Station mode: Preauth
104  * @WLAN_DISCONNECT_STATE: Disconnect is in progress
105  */
106 enum wlan_peer_state {
107 	WLAN_INIT_STATE       = 1,
108 	WLAN_JOIN_STATE       = 2,
109 	WLAN_AUTH_STATE       = 3,
110 	WLAN_ASSOC_STATE      = 4,
111 	WLAN_WAITKEY_STATE    = 5,
112 	WLAN_CONNECTED_STATE  = 6,
113 	WLAN_PREAUTH_STATE    = 7,
114 	WLAN_DISCONNECT_STATE = 8,
115 };
116 
117 /**
118  * struct wlan_objmgr_peer_mlme - mlme common data of peer
119  * @peer_capinfo:    protocol cap info
120  * @peer_flags:      PEER OP flags
121  * @peer_type:       Type of PEER, (STA/AP/etc.)
122  * @phymode:         phy mode of station
123  * @max_rate:        Max Rate supported
124  * @state:           State of the peer
125  * @seq_num:         Sequence number
126  * @rssi:            Last received RSSI value
127  */
128 struct wlan_objmgr_peer_mlme {
129 	uint32_t peer_capinfo;
130 	uint32_t peer_flags;
131 	enum wlan_peer_type peer_type;
132 	enum wlan_phymode phymode;
133 	uint32_t max_rate;
134 	enum wlan_peer_state state;
135 	uint16_t seq_num;
136 	int8_t rssi;
137 	bool is_authenticated;
138 };
139 
140 /**
141  * struct wlan_objmgr_peer_objmgr - object manager data of peer
142  * @vdev:              VDEV pointer to which it is associated
143  * @ref_cnt:           Ref count
144  * @ref_id_dbg:        Array to track Ref count
145  * @print_cnt:         Count to throttle Logical delete prints
146  */
147 struct wlan_objmgr_peer_objmgr {
148 	struct wlan_objmgr_vdev *vdev;
149 	qdf_atomic_t ref_cnt;
150 #ifdef WLAN_OBJMGR_REF_ID_DEBUG
151 	qdf_atomic_t ref_id_dbg[WLAN_REF_ID_MAX];
152 #endif
153 	uint8_t print_cnt;
154 };
155 
156 /**
157  * struct wlan_peer_activity -- peer inactivity info
158  *
159  */
160 struct wlan_peer_activity {  /*TODO */
161 
162 };
163 
164 /**
165  * struct wlan_objmgr_peer -  PEER common object
166  * @psoc_peer:        peer list node for psoc's qdf list
167  * @vdev_peer:        peer list node for vdev's qdf list
168  * @macaddr[]:        Peer MAC address
169  * @peer_mlme:	      Peer MLME common structure
170  * @peer_activity:    peer activity
171  * @peer_objmgr:      Peer Object manager common structure
172  * @peer_comp_priv_obj[]:  Component's private object pointers
173  * @obj_status[]:     status of each component object
174  * @obj_state:        Status of Peer object
175  * @dp_handle:        DP module handle
176  * @pdev_id:          Pdev ID
177  * @peer_lock:        Lock for access/update peer contents
178  */
179 struct wlan_objmgr_peer {
180 	qdf_list_node_t psoc_peer;
181 	qdf_list_node_t vdev_peer;
182 	uint8_t macaddr[QDF_MAC_ADDR_SIZE];
183 	uint8_t pdev_id;
184 	struct wlan_objmgr_peer_mlme peer_mlme;
185 	struct wlan_peer_activity peer_activity;
186 	struct wlan_objmgr_peer_objmgr peer_objmgr;
187 	void *peer_comp_priv_obj[WLAN_UMAC_MAX_COMPONENTS];
188 	QDF_STATUS obj_status[WLAN_UMAC_MAX_COMPONENTS];
189 	WLAN_OBJ_STATE obj_state;
190 	void *dp_handle;
191 	qdf_spinlock_t peer_lock;
192 };
193 
194 /**
195  ** APIs to Create/Delete Global object APIs
196  */
197 /**
198  * wlan_objmgr_peer_obj_create() - peer object create
199  * @vdev: VDEV object on which this peer gets created
200  * @peer_type: peer type (AP/STA)
201  * @macaddr: MAC address
202  *
203  * Creates Peer object, intializes with default values
204  * Attaches to psoc and vdev objects
205  * Invokes the registered notifiers to create component object
206  *
207  * Return: Handle to struct wlan_objmgr_peer on successful creation,
208  *         NULL on Failure (on Mem alloc failure and Component objects
209  *         Failure)
210  */
211 struct wlan_objmgr_peer *wlan_objmgr_peer_obj_create(
212 			struct wlan_objmgr_vdev *vdev,
213 			enum wlan_peer_type type,
214 			uint8_t macaddr[]);
215 
216 /**
217  * wlan_objmgr_peer_obj_delete() - peer object delete
218  * @peer: PEER object
219  *
220  * Deletes PEER object, removes it from PSOC's, VDEV's peer list
221  * Invokes the registered notifiers to destroy component objects
222  *
223  * Return: SUCCESS/FAILURE
224  */
225 QDF_STATUS wlan_objmgr_peer_obj_delete(struct wlan_objmgr_peer *peer);
226 
227 /**
228  ** APIs to attach/detach component objects
229  */
230 /**
231  * wlan_objmgr_peer_component_obj_attach() - attach comp object to peer
232  * @peer: PEER object
233  * @id: Component id
234  * @comp_priv_obj: component's private object pointer
235  * @status: Component's private object creation status
236  *
237  * API to be used for attaching component object with PEER common object
238  *
239  * Return: SUCCESS on successful storing of component's object in common object
240  *         On FAILURE (appropriate failure codes are returned)
241  */
242 QDF_STATUS wlan_objmgr_peer_component_obj_attach(
243 		struct wlan_objmgr_peer *peer,
244 		enum wlan_umac_comp_id id,
245 		void *comp_priv_obj,
246 		QDF_STATUS status);
247 
248 /**
249  * wlan_objmgr_peer_component_obj_detach() - detach comp object from peer
250  * @peer: PEER object
251  * @id: Component id
252  * @comp_priv_obj: component's private object pointer
253  *
254  * API to be used for detaching component object with PEER common object
255  *
256  * Return: SUCCESS on successful removal of component's object from common
257  *         object
258  *         On FAILURE (appropriate failure codes are returned)
259  */
260 QDF_STATUS wlan_objmgr_peer_component_obj_detach(
261 		struct wlan_objmgr_peer *peer,
262 		enum wlan_umac_comp_id id,
263 		void *comp_priv_obj);
264 
265 /**
266  ** APIs to operations on peer objects
267  */
268 
269 /**
270  * wlan_objmgr_trigger_peer_comp_priv_object_creation() - create
271  * peer comp object
272  * @peer: PEER object
273  * @id: Component id
274  *
275  * API to create component private object in run time, this would
276  * be used for features which gets enabled in run time
277  *
278  * Return: SUCCESS on successful creation
279  *         On FAILURE (appropriate failure codes are returned)
280  */
281 QDF_STATUS wlan_objmgr_trigger_peer_comp_priv_object_creation(
282 		struct wlan_objmgr_peer *peer,
283 		enum wlan_umac_comp_id id);
284 
285 /**
286  * wlan_objmgr_trigger_peer_comp_priv_object_deletion() - destroy
287  * peer comp object
288  * @peer: PEER object
289  * @id: Component id
290  *
291  * API to destroy component private object in run time, this would
292  * be used for features which gets disabled in run time
293  *
294  * Return: SUCCESS on successful deletion
295  *         On FAILURE (appropriate failure codes are returned)
296  */
297 QDF_STATUS wlan_objmgr_trigger_peer_comp_priv_object_deletion(
298 		struct wlan_objmgr_peer *peer,
299 		enum wlan_umac_comp_id id);
300 
301 /**
302  * wlan_objmgr_peer_get_comp_private_obj() - get peer component private object
303  * @peer: PEER object
304  * @id: Component id
305  *
306  * API to get component private object
307  *
308  * Return: void *ptr on SUCCESS
309  *         NULL on Failure
310  */
311 void *wlan_objmgr_peer_get_comp_private_obj(
312 		struct wlan_objmgr_peer *peer,
313 		enum wlan_umac_comp_id id);
314 
315 /**
316  * wlan_peer_obj_lock() - Acquire PEER spinlock
317  * @psoc: PEER object
318  *
319  * API to acquire PEER spin lock
320  * Parent lock should not be taken in child lock context
321  * but child lock can be taken in parent lock context
322  * (for ex: psoc lock can't be invoked in pdev/vdev/peer lock context)
323  *
324  * Return: void
325  */
326 static inline void wlan_peer_obj_lock(struct wlan_objmgr_peer *peer)
327 {
328 	qdf_spin_lock_bh(&peer->peer_lock);
329 }
330 
331 /**
332  * wlan_peer_obj_unlock() - Release PEER spinlock
333  * @peer: PEER object
334  *
335  * API to Release PEER spin lock
336  *
337  * Return: void
338  */
339 static inline void wlan_peer_obj_unlock(struct wlan_objmgr_peer *peer)
340 {
341 	qdf_spin_unlock_bh(&peer->peer_lock);
342 }
343 
344 /**
345  * DOC: Examples to use PEER ref count APIs
346  *
347  * In all the scenarios, the pair of API should be followed
348  * other it lead to memory leak
349  *
350  *  scenario 1:
351  *
352  *     wlan_objmgr_peer_obj_create()
353  *     ----
354  *     wlan_objmgr_peer_obj_delete()
355  *
356  *  scenario 2:
357  *
358  *     wlan_objmgr_peer_get_ref()
359  *     ----
360  *     the operations which are done on
361  *     peer object
362  *     ----
363  *     wlan_objmgr_peer_release_ref()
364  *
365  *  scenario 3:
366  *
367  *     API to retrieve peer (xxx_get_peer_xxx())
368  *     ----
369  *     the operations which are done on
370  *     peer object
371  *     ----
372  *     wlan_objmgr_peer_release_ref()
373  */
374 
375 /**
376  * wlan_objmgr_peer_get_ref() - increment ref count
377  * @peer: PEER object
378  * @id:   Object Manager ref debug id
379  *
380  * API to increment ref count of peer
381  *
382  * Return: void
383  */
384 void wlan_objmgr_peer_get_ref(struct wlan_objmgr_peer *peer,
385 					wlan_objmgr_ref_dbgid id);
386 
387 /**
388  * wlan_objmgr_peer_try_get_ref() - increment ref count, if allowed
389  * @peer: PEER object
390  * @id:   Object Manager ref debug id
391  *
392  * API to increment ref count of peer, if object state is valid
393  *
394  * Return: void
395  */
396 QDF_STATUS wlan_objmgr_peer_try_get_ref(struct wlan_objmgr_peer *peer,
397 						 wlan_objmgr_ref_dbgid id);
398 
399 /**
400  * wlan_objmgr_peer_release_ref() - decrement ref count
401  * @peer: PEER object
402  * @id:   Object Manager ref debug id
403  *
404  * API to decrement ref count of peer, if ref count is 1, it initiates the
405  * peer deletion
406  *
407  * Return: void
408  */
409 void wlan_objmgr_peer_release_ref(struct wlan_objmgr_peer *peer,
410 						 wlan_objmgr_ref_dbgid id);
411 
412 /**
413  * wlan_psoc_peer_list_peek_head() - get head of psoc peer list
414  * @peer_list: qdf_list_t
415  *
416  * API to get the head peer of given peer (of psoc's peer list)
417  *
418  * Caller need to acquire lock with wlan_peer_obj_lock()
419  *
420  * Return:
421  * @peer: head peer
422  */
423 static inline struct wlan_objmgr_peer *wlan_psoc_peer_list_peek_head(
424 					qdf_list_t *peer_list)
425 {
426 	struct wlan_objmgr_peer *peer;
427 	qdf_list_node_t *psoc_node = NULL;
428 
429 	/* This API is invoked with lock acquired, do not add log prints */
430 	if (qdf_list_peek_front(peer_list, &psoc_node) != QDF_STATUS_SUCCESS)
431 		return NULL;
432 
433 	peer = qdf_container_of(psoc_node, struct wlan_objmgr_peer, psoc_peer);
434 	return peer;
435 }
436 
437 /**
438  * wlan_psoc_peer_list_peek_active_head() - get active head of psoc peer list
439  * @peer_list: wlan_peer_list
440  * @hash_index: peer list hash index
441  * @dbg_id: Ref count debug module id
442  *
443  * API to get the head peer of given peer (of psoc's peer list)
444  *
445  * Return:
446  * @peer: head peer
447  */
448 struct wlan_objmgr_peer *wlan_psoc_peer_list_peek_active_head(
449 					struct wlan_peer_list *peer_list,
450 					uint8_t hash_index,
451 					wlan_objmgr_ref_dbgid dbg_id);
452 
453 /**
454  * wlan_psoc_peer_list_peek_head_lock_ref() - get head of psoc peer list
455  *                                            with ref and lock protected
456  * @peer_list: wlan_peer_list
457  * @hash_index: peer list hash index
458  * @dbg_id: Ref count debug module id
459  *
460  * API to get the head peer of given peer (of psoc's peer list)
461  *
462  * Return:
463  * @peer: head peer
464  */
465 struct wlan_objmgr_peer *wlan_psoc_peer_list_peek_head_ref(
466 					struct wlan_peer_list *peer_list,
467 					uint8_t hash_index,
468 					wlan_objmgr_ref_dbgid dbg_id);
469 
470 /**
471  * wlan_vdev_peer_list_peek_head() - get head of vdev peer list
472  * @peer_list: qdf_list_t
473  *
474  * API to get the head peer of given peer (of vdev's peer list)
475  *
476  * Caller need to acquire lock with wlan_peer_obj_lock()
477  *
478  * Return:
479  * @peer: head peer
480  */
481 static inline struct wlan_objmgr_peer *wlan_vdev_peer_list_peek_head(
482 					qdf_list_t *peer_list)
483 {
484 	struct wlan_objmgr_peer *peer;
485 	qdf_list_node_t *vdev_node = NULL;
486 
487 	/* This API is invoked with lock acquired, do not add log prints */
488 	if (qdf_list_peek_front(peer_list, &vdev_node) != QDF_STATUS_SUCCESS)
489 		return NULL;
490 
491 	peer = qdf_container_of(vdev_node, struct wlan_objmgr_peer, vdev_peer);
492 	return peer;
493 }
494 
495 /**
496  * wlan_vdev_peer_list_peek_active_head() - get active head of vdev peer list
497  * @vdev: VDEV object
498  * @peer_list: qdf_list_t
499  * @dbg_id: Ref count debug module id
500  *
501  * API to get the active head peer of given peer (of vdev's peer list)
502  *
503  * Return:
504  * @peer: active head peer
505  */
506 struct wlan_objmgr_peer *wlan_vdev_peer_list_peek_active_head(
507 				struct wlan_objmgr_vdev *vdev,
508 				qdf_list_t *peer_list,
509 				wlan_objmgr_ref_dbgid dbg_id);
510 
511 /**
512  * wlan_peer_get_next_peer_of_vdev() - get next peer of vdev list
513  * @peer: PEER object
514  *
515  * API to get the next peer of given peer (of vdev's peer list)
516  *
517  * Caller need to acquire lock with wlan_peer_obj_lock()
518  *
519  * Return:
520  * @next_peer: PEER object
521  */
522 static inline struct wlan_objmgr_peer *wlan_peer_get_next_peer_of_vdev(
523 			qdf_list_t *peer_list, struct wlan_objmgr_peer *peer)
524 {
525 	struct wlan_objmgr_peer *peer_next;
526 	qdf_list_node_t *node;
527 	qdf_list_node_t *next_node = NULL;
528 
529 	/* This API is invoked with lock acquired, do not add log prints */
530 	if (peer == NULL)
531 		return NULL;
532 
533 	node = &peer->vdev_peer;
534 	if (qdf_list_peek_next(peer_list, node, &next_node) !=
535 						QDF_STATUS_SUCCESS)
536 		return NULL;
537 
538 	peer_next = qdf_container_of(next_node, struct wlan_objmgr_peer,
539 					vdev_peer);
540 	return peer_next;
541 }
542 
543 /**
544  * wlan_peer_get_next_active_peer_of_vdev() - get next active_peer of vdev list
545  * @vdev: VDEV object
546  * @peer_list: Peer object list
547  * @peer: PEER object
548  * @dbg_id: Ref count debug module id
549  *
550  * API to get the next active peer of given peer (of vdev's peer list)
551  *
552  * Return:
553  * @next_peer: PEER object
554  */
555 struct wlan_objmgr_peer *wlan_peer_get_next_active_peer_of_vdev(
556 				struct wlan_objmgr_vdev *vdev,
557 				qdf_list_t *peer_list,
558 				struct wlan_objmgr_peer *peer,
559 				wlan_objmgr_ref_dbgid dbg_id);
560 
561 /**
562  * wlan_peer_set_next_peer_of_vdev() - add peer to vdev peer list
563  * @peer: PEER object
564  * @new_peer: PEER object
565  *
566  * API to set as the next peer to given peer (of vdev's peer list)
567  *
568  * Caller need to acquire lock with wlan_peer_obj_lock()
569  *
570  * Return: void
571  */
572 static inline void wlan_peer_set_next_peer_of_vdev(qdf_list_t *peer_list,
573 				struct wlan_objmgr_peer *new_peer)
574 {
575 	/* This API is invoked with lock acquired, do not add log prints */
576 	/* set next peer with new peer */
577 	qdf_list_insert_back(peer_list, &new_peer->vdev_peer);
578 	return;
579 }
580 
581 /**
582  * wlan_peer_get_next_peer_of_psoc() - get next peer to psoc peer list
583  * @peer_list: Peer list
584  * @peer: PEER object
585  *
586  * API to get the next peer of given peer (of psoc's peer list)
587  *
588  * Caller need to acquire lock with wlan_peer_obj_lock()
589  *
590  * Return:
591  * @next_peer: PEER object
592  */
593 static inline struct wlan_objmgr_peer *wlan_peer_get_next_peer_of_psoc(
594 			qdf_list_t *peer_list, struct wlan_objmgr_peer *peer)
595 {
596 	struct wlan_objmgr_peer *peer_next;
597 	qdf_list_node_t *node = NULL;
598 	qdf_list_node_t *next_node = NULL;
599 
600 	/* This API is invoked with lock acquired, do not add log prints */
601 	if (peer == NULL)
602 		return NULL;
603 
604 	node = &peer->psoc_peer;
605 	if (qdf_list_peek_next(peer_list, node, &next_node) !=
606 						QDF_STATUS_SUCCESS)
607 		return NULL;
608 
609 	peer_next = qdf_container_of(next_node, struct wlan_objmgr_peer,
610 					psoc_peer);
611 	return peer_next;
612 }
613 
614 /**
615  * wlan_peer_get_next_active_peer_of_psoc() - get next active peer to psoc peer
616  *                                            list
617  * @peer_list: Peer list
618  * @hash_index: peer list hash index
619  * @peer: PEER object
620  * @dbg_id: Ref count debug module id
621  *
622  * API to get the next peer of given peer (of psoc's peer list)
623  *
624  * Return:
625  * @next_peer: PEER object
626  */
627 struct wlan_objmgr_peer *wlan_peer_get_next_active_peer_of_psoc(
628 					struct wlan_peer_list *peer_list,
629 					uint8_t hash_index,
630 					struct wlan_objmgr_peer *peer,
631 					wlan_objmgr_ref_dbgid dbg_id);
632 
633 
634 /**
635  * wlan_peer_get_next_peer_of_psoc_ref() - get next peer to psoc peer list
636  *                                         with lock and ref taken
637  * @peer_list: Peer list
638  * @hash_index: peer list hash index
639  * @peer: PEER object
640  * @dbg_id: Ref count debug module id
641  *
642  * API to get the next peer of given peer (of psoc's peer list)
643  *
644  * Return:
645  * @next_peer: PEER object
646  */
647 struct wlan_objmgr_peer *wlan_peer_get_next_peer_of_psoc_ref(
648 				struct wlan_peer_list *peer_list,
649 				uint8_t hash_index,
650 				struct wlan_objmgr_peer *peer,
651 				wlan_objmgr_ref_dbgid dbg_id);
652 
653 /**
654  * wlan_peer_set_next_peer_of_psoc() - add peer to psoc peer list
655  * @peer: PEER object
656  * @new_peer: PEER object
657  *
658  * API to set as the next peer to given peer (of psoc's peer list)
659  *
660  * Caller need to acquire lock with wlan_peer_obj_lock()
661  *
662  * Return: void
663  */
664 static inline void wlan_peer_set_next_peer_of_psoc(qdf_list_t *peer_list,
665 					struct wlan_objmgr_peer *new_peer)
666 {
667 	/* This API is invoked with lock acquired, do not add log prints */
668 	/* set next peer with new peer */
669 	qdf_list_insert_back(peer_list, &new_peer->psoc_peer);
670 	return;
671 }
672 
673 /**
674  * wlan_peer_set_peer_type() - set peer type
675  * @peer: PEER object
676  * @peer_type: type of PEER
677  *
678  * API to set peer type
679  *
680  * Return: void
681  */
682 static inline void wlan_peer_set_peer_type(struct wlan_objmgr_peer *peer,
683 			enum wlan_peer_type type)
684 {
685 	peer->peer_mlme.peer_type = type;
686 }
687 
688 /**
689  * wlan_peer_get_peer_type() - get peer type
690  * @peer: PEER object
691  *
692  * API to get peer type
693  *
694  * Return:
695  * @peer_type: type of PEER
696  */
697 static inline enum wlan_peer_type wlan_peer_get_peer_type(
698 				struct wlan_objmgr_peer *peer)
699 {
700 	return peer->peer_mlme.peer_type;
701 }
702 
703 /**
704  * wlan_peer_set_phymode() - set phymode
705  * @peer: PEER object
706  * @phymode: phymode of peer
707  *
708  * API to set phymode
709  *
710  * Return: void
711  */
712 static inline void wlan_peer_set_phymode(struct wlan_objmgr_peer *peer,
713 					 enum wlan_phymode phymode)
714 {
715 	peer->peer_mlme.phymode = phymode;
716 }
717 
718 /**
719  * wlan_peer_get_phymode() - get phymode
720  * @peer: PEER object
721  *
722  * API to get phymode
723  *
724  * Return:
725  * @phymode: phymode of PEER
726  */
727 static inline enum wlan_phymode wlan_peer_get_phymode(
728 				struct wlan_objmgr_peer *peer)
729 {
730 	return peer->peer_mlme.phymode;
731 }
732 
733 
734 /**
735  * wlan_peer_set_macaddr() - set mac addr
736  * @peer: PEER object
737  * @macaddr: MAC address
738  *
739  * API to set peer mac address
740  *
741  * Caller need to acquire lock with wlan_peer_obj_lock()
742  *
743  * Return: void
744  */
745 static inline void wlan_peer_set_macaddr(struct wlan_objmgr_peer *peer,
746 			uint8_t *macaddr)
747 {
748 	/* This API is invoked with lock acquired, do not add log prints */
749 	WLAN_ADDR_COPY(peer->macaddr, macaddr);
750 }
751 
752 /**
753  * wlan_peer_get_macaddr() - get mac addr
754  * @peer: PEER object
755  *
756  * API to get peer mac address
757  *
758  * Caller need to acquire lock with wlan_peer_obj_lock()
759  *
760  * Return:
761  * @macaddr: MAC address
762  */
763 static inline uint8_t *wlan_peer_get_macaddr(struct wlan_objmgr_peer *peer)
764 {
765 	/* This API is invoked with lock acquired, do not add log prints */
766 	return peer->macaddr;
767 }
768 
769 /**
770  * wlan_peer_get_vdev() - get vdev
771  * @peer: PEER object
772  *
773  * API to get peer's vdev
774  *
775  * Return:
776  * @vdev: VDEV object
777  */
778 static inline struct wlan_objmgr_vdev *wlan_peer_get_vdev(
779 			struct wlan_objmgr_peer *peer)
780 {
781 	return peer->peer_objmgr.vdev;
782 }
783 
784 /**
785  * wlan_peer_set_vdev() - set vdev
786  * @peer: PEER object
787  * @vdev: VDEV object
788  *
789  * API to set peer's vdev
790  *
791  * Return: void
792  */
793 static inline void wlan_peer_set_vdev(struct wlan_objmgr_peer *peer,
794 		struct wlan_objmgr_vdev *vdev)
795 {
796 	peer->peer_objmgr.vdev = vdev;
797 }
798 
799 /**
800  * wlan_peer_mlme_flag_set() - mlme flag set
801  * @peer: PEER object
802  * @flag: flag to be set
803  *
804  * API to set flag in peer
805  *
806  * Return: void
807  */
808 static inline void wlan_peer_mlme_flag_set(struct wlan_objmgr_peer *peer,
809 				uint32_t flag)
810 {
811 	peer->peer_mlme.peer_flags |= flag;
812 }
813 
814 /**
815  * wlan_peer_mlme_flag_clear() - mlme flag clear
816  * @peer: PEER object
817  * @flag: flag to be cleared
818  *
819  * API to clear flag in peer
820  *
821  * Return: void
822  */
823 static inline void wlan_peer_mlme_flag_clear(struct wlan_objmgr_peer *peer,
824 				uint32_t flag)
825 {
826 	peer->peer_mlme.peer_flags &= ~flag;
827 }
828 
829 /**
830  * wlan_peer_mlme_flag_get() - mlme flag get
831  * @peer: PEER object
832  * @flag: flag to be checked
833  *
834  * API to know, whether particular flag is set in peer
835  *
836  * Return: 1 (for set) or 0 (for not set)
837  */
838 static inline uint8_t wlan_peer_mlme_flag_get(struct wlan_objmgr_peer *peer,
839 				uint32_t flag)
840 {
841 	return (peer->peer_mlme.peer_flags & flag) ? 1 : 0;
842 }
843 
844 /**
845  * wlan_peer_mlme_set_state() - peer mlme state
846  * @peer: PEER object
847  * @state: enum wlan_peer_state
848  *
849  * API to update the current peer state
850  *
851  * Return: void
852  */
853 static inline void wlan_peer_mlme_set_state(
854 				struct wlan_objmgr_peer *peer,
855 				enum wlan_peer_state state)
856 {
857 	peer->peer_mlme.state = state;
858 }
859 
860 /**
861  * wlan_peer_mlme_set_auth_state() - peer mlme auth state
862  * @peer: PEER object
863  * @is_authenticated: true or false
864  *
865  * API to update the current peer auth state
866  *
867  * Return: void
868  */
869 static inline void wlan_peer_mlme_set_auth_state(
870 				struct wlan_objmgr_peer *peer,
871 				bool is_authenticated)
872 {
873 	peer->peer_mlme.is_authenticated = is_authenticated;
874 }
875 
876 /**
877  * wlan_peer_mlme_get_state() - peer mlme state
878  * @peer: PEER object
879  *
880  * API to get peer state
881  *
882  * Return: enum wlan_peer_state
883  */
884 static inline enum wlan_peer_state wlan_peer_mlme_get_state(
885 				struct wlan_objmgr_peer *peer)
886 {
887 	return peer->peer_mlme.state;
888 }
889 
890 /**
891  * wlan_peer_mlme_get_auth_state() - peer mlme auth state
892  * @peer: PEER object
893  *
894  * API to get peer auth state
895  *
896  * Return: auth state true/false
897  */
898 static inline bool wlan_peer_mlme_get_auth_state(
899 				struct wlan_objmgr_peer *peer)
900 {
901 	return peer->peer_mlme.is_authenticated;
902 }
903 
904 /**
905  * wlan_peer_mlme_get_next_seq_num() - get peer mlme next sequence number
906  * @peer: PEER object
907  *
908  * API to get mlme peer next sequence number
909  *
910  * Caller need to acquire lock with wlan_peer_obj_lock()
911  *
912  * Return: peer mlme next sequence number
913  */
914 static inline uint32_t wlan_peer_mlme_get_next_seq_num(
915 				struct wlan_objmgr_peer *peer)
916 {
917 	/* This API is invoked with lock acquired, do not add log prints */
918 	if (peer->peer_mlme.seq_num < WLAN_MAX_SEQ_NUM)
919 		peer->peer_mlme.seq_num++;
920 	else
921 		peer->peer_mlme.seq_num = 0;
922 
923 	return peer->peer_mlme.seq_num;
924 }
925 
926 /**
927  * wlan_peer_mlme_get_seq_num() - get peer mlme sequence number
928  * @peer: PEER object
929  *
930  * API to get mlme peer sequence number
931  *
932  * Caller need to acquire lock with wlan_peer_obj_lock()
933  *
934  * Return: peer mlme sequence number
935  */
936 static inline uint32_t wlan_peer_mlme_get_seq_num(
937 				struct wlan_objmgr_peer *peer)
938 {
939 	/* This API is invoked with lock acquired, do not add log prints */
940 	return peer->peer_mlme.seq_num;
941 }
942 
943 /**
944  * wlan_peer_mlme_reset_seq_num() - reset peer mlme sequence number
945  * @peer: PEER object
946  *
947  * API to reset peer sequence number
948  *
949  * Caller need to acquire lock with wlan_peer_obj_lock()
950  *
951  * Return: void
952  */
953 static inline void wlan_peer_mlme_reset_seq_num(
954 				struct wlan_objmgr_peer *peer)
955 {
956 	/* This API is invoked with lock acquired, do not add log prints */
957 	peer->peer_mlme.seq_num = 0;
958 }
959 
960 /**
961  * wlan_peer_set_dp_handle() - set dp handle
962  * @peer: peer object pointer
963  * @dp_handle: Data path module handle
964  *
965  * Return: void
966  */
967 static inline void wlan_peer_set_dp_handle(struct wlan_objmgr_peer *peer,
968 		void *dp_handle)
969 {
970 	if (qdf_unlikely(!peer)) {
971 		QDF_BUG(0);
972 		return;
973 	}
974 
975 	peer->dp_handle = dp_handle;
976 }
977 
978 /**
979  * wlan_peer_get_dp_handle() - get dp handle
980  * @peer: peer object pointer
981  *
982  * Return: dp handle
983  */
984 static inline void *wlan_peer_get_dp_handle(struct wlan_objmgr_peer *peer)
985 {
986 	if (qdf_unlikely(!peer)) {
987 		QDF_BUG(0);
988 		return NULL;
989 	}
990 
991 	return peer->dp_handle;
992 }
993 
994 /**
995  * wlan_peer_get_psoc() - get psoc
996  * @peer: PEER object
997  *
998  * API to get peer's psoc
999  *
1000  * Return: PSOC object or NULL if the psoc can not be found
1001  */
1002 static inline struct wlan_objmgr_psoc *wlan_peer_get_psoc(
1003 			struct wlan_objmgr_peer *peer)
1004 {
1005 	struct wlan_objmgr_vdev *vdev;
1006 	struct wlan_objmgr_psoc *psoc;
1007 
1008 	vdev = wlan_peer_get_vdev(peer);
1009 	if (!vdev)
1010 		return NULL;
1011 
1012 	psoc = wlan_vdev_get_psoc(vdev);
1013 
1014 	return psoc;
1015 }
1016 
1017 /*
1018  * wlan_peer_get_pdev_id() - get pdev id
1019  * @peer: peer object pointer
1020  *
1021  * Return: pdev id
1022  */
1023 static inline uint8_t wlan_peer_get_pdev_id(struct wlan_objmgr_peer *peer)
1024 {
1025 	return peer->pdev_id;
1026 }
1027 
1028 /**
1029  * wlan_peer_set_pdev_id() - set pdev id
1030  * @peer: peer object pointer
1031  * @pdev_id: pdev id
1032  *
1033  * Return: void
1034  */
1035 static inline void wlan_peer_set_pdev_id(struct wlan_objmgr_peer *peer,
1036 					 uint8_t pdev_id)
1037 {
1038 	peer->pdev_id = pdev_id;
1039 }
1040 
1041 /**
1042  * wlan_objmgr_print_peer_ref_ids() - print peer object refs
1043  * @peer: peer object pointer
1044  * @log_level: log level
1045  *
1046  * Return: void
1047  */
1048 void wlan_objmgr_print_peer_ref_ids(struct wlan_objmgr_peer *peer,
1049 				    QDF_TRACE_LEVEL log_level);
1050 
1051 /**
1052  * wlan_objmgr_peer_get_comp_ref_cnt() - get component ref count for a peer
1053  * @peer: peer object pointer
1054  * @id: component id
1055  *
1056  * Return: uint32_t
1057  */
1058 uint32_t
1059 wlan_objmgr_peer_get_comp_ref_cnt(struct wlan_objmgr_peer *peer,
1060 				  enum wlan_umac_comp_id id);
1061 
1062 #endif /* _WLAN_OBJMGR_PEER_OBJ_H_*/
1063