xref: /wlan-dirver/qca-wifi-host-cmn/umac/mlo_mgr/inc/wlan_mlo_mgr_peer.h (revision 8cfe6b10058a04cafb17eed051f2ddf11bee8931)
1 /*
2  * Copyright (c) 2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /*
19  * DOC: contains MLO manager public file containing peer functionality
20  */
21 #ifndef _WLAN_MLO_MGR_PEER_H_
22 #define _WLAN_MLO_MGR_PEER_H_
23 
24 #include "wlan_objmgr_peer_obj.h"
25 
26 #define WLAN_LINK_ID_INVALID    0xff
27 
28 /**
29  * mlo_peer_create - Initiatiate peer create on secondary link(s)
30  * by posting a message
31  *
32  * @vdev: pointer to vdev
33  * @peer: pointer to peer context
34  * @mlo_ie: MLO information element
35  * @aid: association ID
36  *
37  * Initiate the peer on the second link
38  *
39  * Return: none
40  */
41 void mlo_peer_create(struct wlan_objmgr_vdev *vdev,
42 			       struct wlan_objmgr_peer *peer, uint8_t *mlo_ie,
43 			       uint8_t aid);
44 
45 /**
46  * mlo_get_mlpeer - Get ML peer corresponds to the MLD address
47  * @ml_dev: MLO DEV object
48  * @ml_addr: MLD MAC address
49  *
50  * This API will be used to get the ML peer associated with MLD address.
51  * It will return Null if the peer does not exist for the given MLD address.
52  *
53  * Return: Pointer to the ML peer context structure
54  */
55 struct wlan_mlo_peer_context *mlo_get_mlpeer(
56 				struct wlan_mlo_dev_context *ml_dev,
57 				const struct qdf_mac_addr *ml_addr);
58 
59 /**
60  * mlo_peer_attach - Attaches the peer by updating the MLO peer context with
61  * the new link information
62  *
63  * @vdev: pointer to vdev
64  * @peer: pointer to peer context
65  *
66  * Return: none
67  */
68 void mlo_peer_attach(struct wlan_objmgr_vdev *vdev,
69 		     struct wlan_objmgr_peer *peer);
70 
71 /**
72  * mlo_peer_setup_failed_notify - Notify MLO manager that peer setup has failed
73  * and to cleanup by deleting the partner peers
74  *
75  * @vdev: pointer to vdev
76  *
77  * This API is called in scenarios where peer create or peer assoc fails
78  *
79  * Return: none
80  */
81 void mlo_peer_setup_failed_notify(struct wlan_objmgr_vdev *vdev);
82 
83 /**
84  * mlo_peer_disconnect_notify - Notify MLO manager that peer has disconnected
85  * and to clean up by deleting partner peers
86  *
87  * @peer: pointer to peer context
88  *
89  * Return: none
90  */
91 void mlo_peer_disconnect_notify(struct wlan_objmgr_peer *peer);
92 
93 /**
94  * wlan_peer_delete_complete - Notify MLO manager that peer delete is completed
95  * and to clean up by unlinking the peer object
96  *
97  * @peer: pointer to peer context
98  *
99  * Return: none
100  */
101 void wlan_peer_delete_complete(struct wlan_objmgr_peer *peer);
102 
103 /**
104  * mlo_peer_delete - Delete the peer object
105  *
106  * @peer: pointer to peer context
107  *
108  * Return: none
109  */
110 void mlo_peer_delete(struct wlan_objmgr_peer *peer);
111 
112 /**
113  * wlan_mlo_peer_delete - Initiate deletion of MLO peer
114  *
115  * @ml_peer: pointer to ML peer context
116  *
117  * Return: none
118  */
119 void wlan_mlo_peer_delete(struct wlan_mlo_peer_context *ml_peer);
120 
121 /**
122  * is_mlo_all_peer_links_deleted - Check if all the peer links are deleted
123  *
124  * Return: true if all the peer links are deleted, false otherwise
125  */
126 bool is_mlo_all_peer_links_deleted(void);
127 
128 /**
129  * wlan_mlo_peer_is_disconnect_progress() - MLO peer is in disconnect progress
130  * @ml_peer: MLO peer
131  *
132  * This function checks whether MLO Peer is in disconnect progress
133  *
134  * Return: SUCCESS if MLO Peer is in disconnect progress
135  */
136 QDF_STATUS wlan_mlo_peer_is_disconnect_progress(
137 					struct wlan_mlo_peer_context *ml_peer);
138 
139 /**
140  * wlan_mlo_peer_is_assoc_done() - MLO peer is Assoc complete
141  * @ml_peer: MLO peer
142  *
143  * This function checks whether MLO Peer's Assoc is completed
144  *
145  * Return: SUCCESS if MLO Peer Assoc is completed
146  */
147 QDF_STATUS wlan_mlo_peer_is_assoc_done(struct wlan_mlo_peer_context *ml_peer);
148 
149 /**
150  * wlan_mlo_peer_get_assoc_peer() - get assoc peer
151  * @ml_peer: MLO peer
152  *
153  * This function returns assoc peer of MLO peer
154  *
155  * Return: assoc peer, if it is found, otherwise NULL
156  */
157 struct wlan_objmgr_peer *wlan_mlo_peer_get_assoc_peer(
158 					struct wlan_mlo_peer_context *ml_peer);
159 
160 /**
161  * mlo_peer_is_assoc_peer() - check whether the peer is assoc peer
162  * @ml_peer: MLO peer
163  * @peer: Link peer
164  *
165  * This function checks whether the peer is assoc peer of MLO peer,
166  * This API doesn't have lock protection, caller needs to take the lock
167  *
168  * Return: true, if it is assoc peer
169  */
170 bool mlo_peer_is_assoc_peer(struct wlan_mlo_peer_context *ml_peer,
171 			    struct wlan_objmgr_peer *peer);
172 
173 /**
174  * wlan_mlo_peer_is_assoc_peer() - check whether the peer is assoc peer
175  * @ml_peer: MLO peer
176  * @peer: Link peer
177  *
178  * This function checks whether the peer is assoc peer of MLO peer
179  *
180  * Return: true, if it is assoc peer
181  */
182 bool wlan_mlo_peer_is_assoc_peer(struct wlan_mlo_peer_context *ml_peer,
183 				 struct wlan_objmgr_peer *peer);
184 
185 /**
186  * wlan_mlo_partner_peer_assoc_post() - Notify partner peer assoc
187  * @assoc_peer: Link peer
188  *
189  * This function notifies link peers to send peer assoc command to FW
190  *
191  * Return: void
192  */
193 void wlan_mlo_partner_peer_assoc_post(struct wlan_objmgr_peer *assoc_peer);
194 
195 /**
196  * wlan_mlo_peer_deauth_init() - Initiate Deauth of MLO peer
197  * @ml_peer: MLO peer
198  * @src_peer: Source peer, if this pointer is valid, send deauth on other link
199  * @is_disassoc: to indicate, whether Disassoc to be sent instead of deauth
200  *
201  * This function initiates deauth on MLO peer and its links peers
202  *
203  * Return: void
204  */
205 void
206 wlan_mlo_peer_deauth_init(struct wlan_mlo_peer_context *ml_peer,
207 			  struct wlan_objmgr_peer *src_peer,
208 			  uint8_t is_disassoc);
209 
210 /**
211  * wlan_mlo_partner_peer_create_failed_notify() - Notify peer creation fail
212  * @ml_peer: MLO peer
213  *
214  * This function notifies about link peer creation failure
215  *
216  * Return: void
217  */
218 void wlan_mlo_partner_peer_create_failed_notify(
219 					struct wlan_mlo_peer_context *ml_peer);
220 
221 /**
222  * wlan_mlo_partner_peer_disconnect_notify() - Notify peer disconnect
223  * @src_peer: Link peer
224  *
225  * This function notifies about disconnect is being initilated on link peer
226  *
227  * Return: void
228  */
229 void wlan_mlo_partner_peer_disconnect_notify(struct wlan_objmgr_peer *src_peer);
230 
231 /**
232  * wlan_mlo_peer_create() - MLO peer create
233  * @vdev: Link VDEV
234  * @link_peer: Link peer
235  * @ml_info: ML links info
236  * @frm_buf: Assoc req buffer
237  * @aid: AID, if already allocated
238  *
239  * This function creates MLO peer and notifies other partner VDEVs to create
240  * link peers
241  *
242  * Return: SUCCESS, if MLO peer is successfully created
243  */
244 QDF_STATUS wlan_mlo_peer_create(struct wlan_objmgr_vdev *vdev,
245 				struct wlan_objmgr_peer *link_peer,
246 				struct mlo_partner_info *ml_info,
247 				qdf_nbuf_t frm_buf,
248 				uint16_t aid);
249 
250 /**
251  * mlo_peer_cleanup() - Free MLO peer
252  * @ml_peer: MLO peer
253  *
254  * This function frees MLO peer and resets MLO peer associations
255  * Note, this API is ref count protected, it should be always invoked
256  * from wlan_mlo_peer_release_ref()
257  *
258  * Return: void
259  */
260 void mlo_peer_cleanup(struct wlan_mlo_peer_context *ml_peer);
261 
262 /**
263  * wlan_mlo_peer_get_ref() - Get ref of MLO peer
264  * @ml_peer: MLO peer
265  *
266  * This function gets ref of MLO peer
267  *
268  * Return: void
269  */
270 static inline void wlan_mlo_peer_get_ref(struct wlan_mlo_peer_context *ml_peer)
271 {
272 	qdf_atomic_inc(&ml_peer->ref_cnt);
273 }
274 
275 /**
276  * wlan_mlo_peer_release_ref() - Release ref of MLO peer
277  * @ml_peer: MLO peer
278  *
279  * This function releases ref of MLO peer, if ref is 0, invokes MLO peer free
280  *
281  * Return: void
282  */
283 static inline void wlan_mlo_peer_release_ref(
284 					struct wlan_mlo_peer_context *ml_peer)
285 {
286 	if (qdf_atomic_dec_and_test(&ml_peer->ref_cnt))
287 		mlo_peer_cleanup(ml_peer);
288 }
289 
290 /**
291  * wlan_mlo_link_peer_attach() - MLO link peer attach
292  * @ml_peer: MLO peer
293  * @peer: Link peer
294  * @frm_buf: Assoc resp buffer of non-assoc link
295  *
296  * This function attaches link peer to MLO peer
297  *
298  * Return: SUCCESS, if peer is successfully attached to MLO peer
299  */
300 QDF_STATUS wlan_mlo_link_peer_attach(struct wlan_mlo_peer_context *ml_peer,
301 				     struct wlan_objmgr_peer *peer,
302 				     qdf_nbuf_t frm_buf);
303 
304 /**
305  * wlan_mlo_link_peer_delete() - MLO link peer delete
306  * @peer: Link peer
307  *
308  * This function detaches link peer from MLO peer, if this peer is last link
309  * peer, then MLO peer gets deleted
310  *
311  * Return: SUCCESS, if peer is detached from MLO peer
312  */
313 QDF_STATUS wlan_mlo_link_peer_delete(struct wlan_objmgr_peer *peer);
314 
315 /**
316  * mlo_peer_get_link_peer_assoc_req_buf() - API to get link assoc req buffer
317  * @ml_peer: Object manager peer
318  * @link_ix: link id of vdev
319  *
320  * Return: assoc req buffer
321  */
322 qdf_nbuf_t mlo_peer_get_link_peer_assoc_req_buf(
323 			struct wlan_mlo_peer_context *ml_peer,
324 			uint8_t link_ix);
325 
326 /**
327  * mlo_peer_get_link_peer_assoc_resp_buf() - get MLO link peer assoc resp buf
328  * @ml_peer: MLO peer
329  * @link_ix: Link index of the link peer
330  *
331  * This function retrieves stored assoc resp buffer of link peer
332  *
333  * Return: resp_buf, if link_peer is available
334  *         NULL, if link_peer is not present
335  */
336 qdf_nbuf_t mlo_peer_get_link_peer_assoc_resp_buf(
337 		struct wlan_mlo_peer_context *ml_peer,
338 		uint8_t link_ix);
339 
340 /**
341  * wlan_mlo_peer_free_all_link_assoc_resp_buf() - Free all assoc resp buffers
342  * @peer: Link peer
343  *
344  * This function frees all assoc resp link buffers
345  *
346  * Return: void
347  */
348 void wlan_mlo_peer_free_all_link_assoc_resp_buf(struct wlan_objmgr_peer *peer);
349 
350 /**
351  * wlan_mlo_peer_get_links_info() - get MLO peer partner links info
352  * @peer: Link peer
353  * @ml_links: structure to be filled with partner link info
354  *
355  * This function retrieves partner link info of link peer such as hw link id,
356  * vdev id
357  *
358  * Return: void
359  */
360 void wlan_mlo_peer_get_links_info(struct wlan_objmgr_peer *peer,
361 				  struct mlo_tgt_partner_info *ml_links);
362 
363 /**
364  * wlan_mlo_peer_get_primary_peer_link_id() - get vdev link ID of primary peer
365  * @peer: Link peer
366  *
367  * This function checks for the peers and returns vdev link id of the primary
368  * peer.
369  *
370  * Return: link id of primary vdev
371  */
372 uint8_t wlan_mlo_peer_get_primary_peer_link_id(struct wlan_objmgr_peer *peer);
373 
374 /**
375  * wlan_mlo_peer_get_partner_links_info() - get MLO peer partner links info
376  * @peer: Link peer
377  * @ml_links: structure to be filled with partner link info
378  *
379  * This function retrieves partner link info of link peer such as link id,
380  * mac address
381  *
382  * Return: void
383  */
384 void wlan_mlo_peer_get_partner_links_info(struct wlan_objmgr_peer *peer,
385 					  struct mlo_partner_info *ml_links);
386 
387 /*
388  * APIs to operations on ML peer object
389  */
390 typedef QDF_STATUS (*wlan_mlo_op_handler)(struct wlan_mlo_dev_context *ml_dev,
391 				    void *ml_peer,
392 				    void *arg);
393 
394 /**
395  * wlan_mlo_iterate_ml_peerlist() - iterate through all ml peer objects
396  * @ml_dev: MLO DEV object
397  * @handler: the handler will be called for each ml peer
398  *            the handler should be implemented to perform required operation
399  * @arg:     arguments passed by caller
400  *
401  * API to be used for performing the operations on all ML PEER objects
402  *
403  * Return: SUCCESS/FAILURE
404  */
405 QDF_STATUS wlan_mlo_iterate_ml_peerlist(struct wlan_mlo_dev_context *ml_dev,
406 					wlan_mlo_op_handler handler,
407 					void *arg);
408 
409 /**
410  * wlan_mlo_get_mlpeer_by_linkmac() - find ML peer by Link MAC address
411  * @ml_dev: MLO DEV object
412  * @link_mac:  Link peer MAC address
413  *
414  * API to get ML peer using link MAC address
415  *
416  * Return: ML peer object, if it is found
417  *         otherwise, returns NULL
418  */
419 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_linkmac(
420 				struct wlan_mlo_dev_context *ml_dev,
421 				struct qdf_mac_addr *link_mac);
422 
423 /**
424  * wlan_mlo_get_mlpeer_by_mld_mac() - find ML peer by MLD MAC address
425  * @ml_dev: MLO DEV object
426  * @mld_mac:  Peer MLD MAC address
427  *
428  * API to get ML peer using link MAC address
429  *
430  * Return: ML peer object, if it is found
431  *         otherwise, returns NULL
432  */
433 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_mld_mac(
434 				struct wlan_mlo_dev_context *ml_dev,
435 				struct qdf_mac_addr *mld_mac);
436 
437 /**
438  * wlan_mlo_get_mlpeer_by_aid() - find ML peer by AID
439  * @ml_dev: MLO DEV object
440  * @assoc_id:  AID
441  *
442  * API to get ML peer using AID
443  *
444  * Return: ML peer object, if it is found
445  *         otherwise, returns NULL
446  */
447 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_aid(
448 				struct wlan_mlo_dev_context *ml_dev,
449 				uint16_t assoc_id);
450 
451 /**
452  * wlan_mlo_get_mlpeer_by_ml_peerid() - find ML peer by ML peer id
453  * @ml_dev: MLO DEV object
454  * @ml_peerid:  ML Peer ID
455  *
456  * API to get ML peer using ML peer id
457  *
458  * Return: ML peer object, if it is found
459  *         otherwise, returns NULL
460  */
461 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_ml_peerid(
462 				struct wlan_mlo_dev_context *ml_dev,
463 				uint16_t ml_peerid);
464 
465 /**
466  * wlan_mlo_get_mlpeer() - find ML peer by MLD MAC address
467  * @ml_dev: MLO DEV object
468  * @ml_addr: MLO MAC address
469  *
470  * API to get ML peer using MLO MAC address
471  *
472  * Return: ML peer object, if it is found
473  *         otherwise, returns NULL
474  */
475 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer(
476 				struct wlan_mlo_dev_context *ml_dev,
477 				struct qdf_mac_addr *ml_addr);
478 
479 /**
480  * mlo_dev_mlpeer_attach() - Add ML PEER to ML peer list
481  * @ml_dev: MLO DEV object
482  * @ml_peer: ML peer
483  *
484  * API to attach ML PEER to MLD PEER table
485  *
486  * Return: SUCCESS, if it attached successfully
487  *         otherwise, returns FAILURE
488  */
489 QDF_STATUS mlo_dev_mlpeer_attach(struct wlan_mlo_dev_context *ml_dev,
490 				 struct wlan_mlo_peer_context *ml_peer);
491 
492 /**
493  * mlo_dev_mlpeer_detach() - Delete ML PEER from ML peer list
494  * @ml_dev: MLO DEV object
495  * @ml_peer: ML peer
496  *
497  * API to detach ML PEER from MLD PEER table
498  *
499  * Return: SUCCESS, if it detached successfully
500  *         otherwise, returns FAILURE
501  */
502 QDF_STATUS mlo_dev_mlpeer_detach(struct wlan_mlo_dev_context *ml_dev,
503 				 struct wlan_mlo_peer_context *ml_peer);
504 
505 /**
506  * mlo_dev_mlpeer_list_init() - Initialize ML peer list
507  * @ml_dev: MLO DEV object
508  *
509  * API to initialize MLO peer list
510  *
511  * Return: SUCCESS, if initialized successfully
512  */
513 QDF_STATUS mlo_dev_mlpeer_list_init(struct wlan_mlo_dev_context *ml_dev);
514 
515 /**
516  * mlo_dev_mlpeer_list_deinit() - destroys ML peer list
517  * @ml_dev: MLO DEV object
518  *
519  * API to destroys MLO peer list
520  *
521  * Return: SUCCESS, if initialized successfully
522  */
523 QDF_STATUS mlo_dev_mlpeer_list_deinit(struct wlan_mlo_dev_context *ml_dev);
524 
525 /**
526  * wlan_peer_is_mlo() - check whether peer is MLO link peer
527  * @peer: link peer object
528  *
529  * API to check link peer is part of MLO peer or not
530  *
531  * Return: true if it MLO peer
532  *         false, if it is not MLO peer
533  */
534 static inline uint8_t wlan_peer_is_mlo(struct wlan_objmgr_peer *peer)
535 {
536 	return wlan_peer_mlme_flag_ext_get(peer, WLAN_PEER_FEXT_MLO);
537 }
538 
539 /**
540  * wlan_peer_set_mlo() - Set peer as MLO link peer
541  * @peer: link peer object
542  *
543  * API to set MLO peer flag in link peer is part of MLO peer
544  *
545  * Return: void
546  */
547 static inline void wlan_peer_set_mlo(struct wlan_objmgr_peer *peer)
548 {
549 	return wlan_peer_mlme_flag_ext_set(peer, WLAN_PEER_FEXT_MLO);
550 }
551 
552 /**
553  * wlan_peer_clear_mlo() - clear peer as MLO link peer
554  * @peer: link peer object
555  *
556  * API to clear MLO peer flag in link peer
557  *
558  * Return: void
559  */
560 static inline void wlan_peer_clear_mlo(struct wlan_objmgr_peer *peer)
561 {
562 	return wlan_peer_mlme_flag_ext_clear(peer, WLAN_PEER_FEXT_MLO);
563 }
564 
565 #if defined(MESH_MODE_SUPPORT) && defined(WLAN_FEATURE_11BE_MLO)
566 /**
567  * wlan_mlo_peer_is_mesh() - Check if ml_peer is configured to operate as MESH
568  * @ml_peer: MLO peer
569  *
570  * Return: TRUE if ml peer is configured as MESH
571  */
572 bool wlan_mlo_peer_is_mesh(struct wlan_mlo_peer_context *ml_peer);
573 #else
574 static inline
575 bool wlan_mlo_peer_is_mesh(struct wlan_mlo_peer_context *ml_peer)
576 {
577 	return false;
578 }
579 #endif
580 
581 #ifdef UMAC_SUPPORT_MLNAWDS
582 /**
583  * wlan_mlo_peer_is_nawds() - Check if ml_peer is configured to operate as NAWDS
584  * @ml_peer: MLO peer
585  *
586  * Return TRUE if ml peer is configured as NAWDS
587  */
588 bool wlan_mlo_peer_is_nawds(struct wlan_mlo_peer_context *ml_peer);
589 #else
590 static inline
591 bool wlan_mlo_peer_is_nawds(struct wlan_mlo_peer_context *ml_peer)
592 {
593 	return false;
594 }
595 #endif
596 #ifdef UMAC_MLO_AUTH_DEFER
597 /**
598  * mlo_peer_link_auth_defer() - Auth request defer for MLO peer
599  * @ml_peer: ML peer
600  * @link_mac:  Link peer MAC address
601  * @auth_params: Defer Auth param
602  *
603  * This function saves Auth request params in MLO peer
604  *
605  * Return: SUCCESS if MAC address matches one of the link peers
606  *         FAILURE, if MAC address doesn't match
607  */
608 QDF_STATUS mlo_peer_link_auth_defer(struct wlan_mlo_peer_context *ml_peer,
609 				    struct qdf_mac_addr *link_mac,
610 				    struct mlpeer_auth_params *auth_params);
611 
612 /**
613  * mlo_peer_free_auth_param() - Free deferred Auth request params
614  * @auth_params: Defer Auth param
615  *
616  * This function frees Auth request params
617  *
618  * Return: void
619  */
620 void mlo_peer_free_auth_param(struct mlpeer_auth_params *auth_params);
621 #else
622 static inline void
623 mlo_peer_free_auth_param(struct mlpeer_auth_params *auth_params)
624 {
625 }
626 #endif
627 
628 /**
629  * wlan_mlo_partner_peer_delete_is_allowed() - Checks MLO peer delete is allowed
630  * @src_peer: Link peer
631  *
632  * This function checks whether MLO peer can be deleted along with link peer
633  * delete in link removal cases
634  *
635  * Return: true, if MLO peer can be deleted
636  */
637 bool wlan_mlo_partner_peer_delete_is_allowed(struct wlan_objmgr_peer *src_peer);
638 #endif
639