xref: /wlan-dirver/qca-wifi-host-cmn/umac/mlo_mgr/inc/wlan_mlo_mgr_peer.h (revision 70a19e16789e308182f63b15c75decec7bf0b342)
1 /*
2  * Copyright (c) 2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 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  * @vdev: pointer to vdev
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  * is_mlo_all_peer_links_deleted - Check if all the peer links are deleted
114  *
115  * Return: true if all the peer links are deleted, false otherwise
116  */
117 bool is_mlo_all_peer_links_deleted(void);
118 
119 /**
120  * wlan_mlo_peer_is_disconnect_progress() - MLO peer is in disconnect progress
121  * @ml_peer: MLO peer
122  *
123  * This function checks whether MLO Peer is in disconnect progress
124  *
125  * Return: SUCCESS if MLO Peer is in disconnect progress
126  */
127 QDF_STATUS wlan_mlo_peer_is_disconnect_progress(
128 					struct wlan_mlo_peer_context *ml_peer);
129 
130 /**
131  * wlan_mlo_peer_is_assoc_done() - MLO peer is Assoc complete
132  * @ml_peer: MLO peer
133  *
134  * This function checks whether MLO Peer's Assoc is completed
135  *
136  * Return: SUCCESS if MLO Peer Assoc is completed
137  */
138 QDF_STATUS wlan_mlo_peer_is_assoc_done(struct wlan_mlo_peer_context *ml_peer);
139 
140 /**
141  * wlan_mlo_peer_get_assoc_peer() - get assoc peer
142  * @ml_peer: MLO peer
143  *
144  * This function returns assoc peer of MLO peer
145  *
146  * Return: assoc peer, if it is found, otherwise NULL
147  */
148 struct wlan_objmgr_peer *wlan_mlo_peer_get_assoc_peer(
149 					struct wlan_mlo_peer_context *ml_peer);
150 
151 /**
152  * mlo_peer_is_assoc_peer() - check whether the peer is assoc peer
153  * @ml_peer: MLO peer
154  * @peer: Link peer
155  *
156  * This function checks whether the peer is assoc peer of MLO peer,
157  * This API doesn't have lock protection, caller needs to take the lock
158  *
159  * Return: true, if it is assoc peer
160  */
161 bool mlo_peer_is_assoc_peer(struct wlan_mlo_peer_context *ml_peer,
162 			    struct wlan_objmgr_peer *peer);
163 
164 /**
165  * wlan_mlo_peer_is_assoc_peer() - check whether the peer is assoc peer
166  * @ml_peer: MLO peer
167  * @peer: Link peer
168  *
169  * This function checks whether the peer is assoc peer of MLO peer
170  *
171  * Return: true, if it is assoc peer
172  */
173 bool wlan_mlo_peer_is_assoc_peer(struct wlan_mlo_peer_context *ml_peer,
174 				 struct wlan_objmgr_peer *peer);
175 
176 /**
177  * wlan_mlo_partner_peer_assoc_post() - Notify partner peer assoc
178  * @peer: Link peer
179  *
180  * This function notifies link peers to send peer assoc command to FW
181  *
182  * Return: void
183  */
184 void wlan_mlo_partner_peer_assoc_post(struct wlan_objmgr_peer *assoc_peer);
185 
186 /**
187  * wlan_mlo_peer_deauth_init() - Initiate Deauth of MLO peer
188  * @ml_peer: MLO peer
189  * @src_peer: Source peer, if this pointer is valid, send deauth on other link
190  * @is_disassoc: to indicate, whether Disassoc to be sent instead of deauth
191  *
192  * This function initiates deauth on MLO peer and its links peers
193  *
194  * Return: void
195  */
196 void
197 wlan_mlo_peer_deauth_init(struct wlan_mlo_peer_context *ml_peer,
198 			  struct wlan_objmgr_peer *src_peer,
199 			  uint8_t is_disassoc);
200 
201 /**
202  * wlan_mlo_partner_peer_create_failed_notify() - Notify peer creation fail
203  * @ml_peer: MLO peer
204  *
205  * This function notifies about link peer creation failure
206  *
207  * Return: void
208  */
209 void wlan_mlo_partner_peer_create_failed_notify(
210 					struct wlan_mlo_peer_context *ml_peer);
211 
212 /**
213  * wlan_mlo_partner_peer_disconnect_notify() - Notify peer disconnect
214  * @peer: Link peer
215  *
216  * This function notifies about disconnect is being initilated on link peer
217  *
218  * Return: void
219  */
220 void wlan_mlo_partner_peer_disconnect_notify(struct wlan_objmgr_peer *src_peer);
221 
222 /**
223  * wlan_mlo_peer_create() - MLO peer create
224  * @vdev: Link VDEV
225  * @link_peer: Link peer
226  * @ml_info: ML links info
227  * @frm_buf: Assoc req buffer
228  * @aid: AID, if already allocated
229  *
230  * This function creates MLO peer and notifies other partner VDEVs to create
231  * link peers
232  *
233  * Return: SUCCESS, if MLO peer is successfully created
234  */
235 QDF_STATUS wlan_mlo_peer_create(struct wlan_objmgr_vdev *vdev,
236 				struct wlan_objmgr_peer *link_peer,
237 				struct mlo_partner_info *ml_info,
238 				qdf_nbuf_t frm_buf,
239 				uint16_t aid);
240 
241 /**
242  * mlo_peer_cleanup() - Free MLO peer
243  * @ml_peer: MLO peer
244  *
245  * This function frees MLO peer and resets MLO peer associations
246  * Note, this API is ref count protected, it should be always invoked
247  * from wlan_mlo_peer_release_ref()
248  *
249  * Return: void
250  */
251 void mlo_peer_cleanup(struct wlan_mlo_peer_context *ml_peer);
252 
253 /**
254  * wlan_mlo_peer_get_ref() - Get ref of MLO peer
255  * @ml_peer: MLO peer
256  *
257  * This function gets ref of MLO peer
258  *
259  * Return: void
260  */
261 static inline void wlan_mlo_peer_get_ref(struct wlan_mlo_peer_context *ml_peer)
262 {
263 	qdf_atomic_inc(&ml_peer->ref_cnt);
264 }
265 
266 /**
267  * wlan_mlo_peer_release_ref() - Release ref of MLO peer
268  * @ml_peer: MLO peer
269  *
270  * This function releases ref of MLO peer, if ref is 0, invokes MLO peer free
271  *
272  * Return: void
273  */
274 static inline void wlan_mlo_peer_release_ref(
275 					struct wlan_mlo_peer_context *ml_peer)
276 {
277 	if (qdf_atomic_dec_and_test(&ml_peer->ref_cnt))
278 		mlo_peer_cleanup(ml_peer);
279 }
280 
281 /**
282  * wlan_mlo_link_peer_attach() - MLO link peer attach
283  * @ml_peer: MLO peer
284  * @peer: Link peer
285  * @frm_buf: Assoc resp buffer of non-assoc link
286  *
287  * This function attaches link peer to MLO peer
288  *
289  * Return: SUCCESS, if peer is successfully attached to MLO peer
290  */
291 QDF_STATUS wlan_mlo_link_peer_attach(struct wlan_mlo_peer_context *ml_peer,
292 				     struct wlan_objmgr_peer *peer,
293 				     qdf_nbuf_t frm_buf);
294 
295 /**
296  * wlan_mlo_link_peer_delete() - MLO link peer delete
297  * @peer: Link peer
298  *
299  * This function detaches link peer from MLO peer, if this peer is last link
300  * peer, then MLO peer gets deleted
301  *
302  * Return: SUCCESS, if peer is detached from MLO peer
303  */
304 QDF_STATUS wlan_mlo_link_peer_delete(struct wlan_objmgr_peer *peer);
305 
306 /**
307  * mlo_peer_get_link_peer_assoc_req_buf() - API to get link assoc req buffer
308  * @peer: Object manager peer
309  * @link_ix: link id of vdev
310  *
311  * Return: assoc req buffer
312  */
313 qdf_nbuf_t mlo_peer_get_link_peer_assoc_req_buf(
314 			struct wlan_mlo_peer_context *ml_peer,
315 			uint8_t link_ix);
316 
317 /**
318  * mlo_peer_get_link_peer_assoc_resp_buf() - get MLO link peer assoc resp buf
319  * @ml_peer: MLO peer
320  * @link_ix: Link index of the link peer
321  *
322  * This function retrieves stored assoc resp buffer of link peer
323  *
324  * Return: resp_buf, if link_peer is available
325  *         NULL, if link_peer is not present
326  */
327 qdf_nbuf_t mlo_peer_get_link_peer_assoc_resp_buf(
328 		struct wlan_mlo_peer_context *ml_peer,
329 		uint8_t link_ix);
330 
331 /**
332  * wlan_mlo_peer_free_all_link_assoc_resp_buf() - Free all assoc resp buffers
333  * @peer: Link peer
334  *
335  * This function frees all assoc resp link buffers
336  *
337  * Return: void
338  */
339 void wlan_mlo_peer_free_all_link_assoc_resp_buf(struct wlan_objmgr_peer *peer);
340 
341 /**
342  * wlan_mlo_peer_get_links_info() - get MLO peer partner links info
343  * @peer: Link peer
344  * @ml_links: structure to be filled with partner link info
345  *
346  * This function retrieves partner link info of link peer such as hw link id,
347  * vdev id
348  *
349  * Return: void
350  */
351 void wlan_mlo_peer_get_links_info(struct wlan_objmgr_peer *peer,
352 				  struct mlo_tgt_partner_info *ml_links);
353 
354 /**
355  * wlan_mlo_peer_get_primary_peer_link_id() - get vdev link ID of primary peer
356  * @peer: Link peer
357  *
358  * This function checks for the peers and returns vdev link id of the primary
359  * peer.
360  *
361  * Return: link id of primary vdev
362  */
363 uint8_t wlan_mlo_peer_get_primary_peer_link_id(struct wlan_objmgr_peer *peer);
364 
365 /**
366  * wlan_mlo_peer_get_partner_links_info() - get MLO peer partner links info
367  * @peer: Link peer
368  * @ml_links: structure to be filled with partner link info
369  *
370  * This function retrieves partner link info of link peer such as link id,
371  * mac address
372  *
373  * Return: void
374  */
375 void wlan_mlo_peer_get_partner_links_info(struct wlan_objmgr_peer *peer,
376 					  struct mlo_partner_info *ml_links);
377 
378 /**
379  ** APIs to operations on ML peer object
380  */
381 typedef QDF_STATUS (*wlan_mlo_op_handler)(struct wlan_mlo_dev_context *ml_dev,
382 				    void *ml_peer,
383 				    void *arg);
384 
385 /**
386  * wlan_mlo_iterate_ml_peerlist() - iterate through all ml peer objects
387  * @ml_dev: MLO DEV object
388  * @handler: the handler will be called for each ml peer
389  *            the handler should be implemented to perform required operation
390  * @arg:     arguments passed by caller
391  *
392  * API to be used for performing the operations on all ML PEER objects
393  *
394  * Return: SUCCESS/FAILURE
395  */
396 QDF_STATUS wlan_mlo_iterate_ml_peerlist(struct wlan_mlo_dev_context *ml_dev,
397 					wlan_mlo_op_handler handler,
398 					void *arg);
399 
400 /**
401  * wlan_mlo_get_mlpeer_by_linkmac() - find ML peer by Link MAC address
402  * @ml_dev: MLO DEV object
403  * @link_mac:  Link peer MAC address
404  *
405  * API to get ML peer using link MAC address
406  *
407  * Return: ML peer object, if it is found
408  *         otherwise, returns NULL
409  */
410 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_linkmac(
411 				struct wlan_mlo_dev_context *ml_dev,
412 				struct qdf_mac_addr *link_mac);
413 
414 /**
415  * wlan_mlo_get_mlpeer_by_mld_mac() - find ML peer by MLD MAC address
416  * @ml_dev: MLO DEV object
417  * @mld_mac:  Peer MLD MAC address
418  *
419  * API to get ML peer using link MAC address
420  *
421  * Return: ML peer object, if it is found
422  *         otherwise, returns NULL
423  */
424 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_mld_mac(
425 				struct wlan_mlo_dev_context *ml_dev,
426 				struct qdf_mac_addr *mld_mac);
427 
428 /**
429  * wlan_mlo_get_mlpeer_by_aid() - find ML peer by AID
430  * @ml_dev: MLO DEV object
431  * @aid:  AID
432  *
433  * API to get ML peer using AID
434  *
435  * Return: ML peer object, if it is found
436  *         otherwise, returns NULL
437  */
438 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_aid(
439 				struct wlan_mlo_dev_context *ml_dev,
440 				uint16_t assoc_id);
441 
442 /**
443  * wlan_mlo_get_mlpeer_by_ml_peerid() - find ML peer by ML peer id
444  * @ml_dev: MLO DEV object
445  * @ml_peerid:  ML Peer ID
446  *
447  * API to get ML peer using ML peer id
448  *
449  * Return: ML peer object, if it is found
450  *         otherwise, returns NULL
451  */
452 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_ml_peerid(
453 				struct wlan_mlo_dev_context *ml_dev,
454 				uint16_t ml_peerid);
455 
456 /**
457  * wlan_mlo_get_mlpeer() - find ML peer by MLD MAC address
458  * @ml_dev: MLO DEV object
459  * @ml_addr: MLO MAC address
460  *
461  * API to get ML peer using MLO MAC address
462  *
463  * Return: ML peer object, if it is found
464  *         otherwise, returns NULL
465  */
466 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer(
467 				struct wlan_mlo_dev_context *ml_dev,
468 				struct qdf_mac_addr *ml_addr);
469 
470 /**
471  * mlo_dev_mlpeer_attach() - Add ML PEER to ML peer list
472  * @ml_dev: MLO DEV object
473  * @ml_peer: ML peer
474  *
475  * API to attach ML PEER to MLD PEER table
476  *
477  * Return: SUCCESS, if it attached successfully
478  *         otherwise, returns FAILURE
479  */
480 QDF_STATUS mlo_dev_mlpeer_attach(struct wlan_mlo_dev_context *ml_dev,
481 				 struct wlan_mlo_peer_context *ml_peer);
482 
483 /**
484  * mlo_dev_mlpeer_detach() - Delete ML PEER from ML peer list
485  * @ml_dev: MLO DEV object
486  * @ml_peer: ML peer
487  *
488  * API to detach ML PEER from MLD PEER table
489  *
490  * Return: SUCCESS, if it detached successfully
491  *         otherwise, returns FAILURE
492  */
493 QDF_STATUS mlo_dev_mlpeer_detach(struct wlan_mlo_dev_context *ml_dev,
494 				 struct wlan_mlo_peer_context *ml_peer);
495 
496 /**
497  * mlo_dev_mlpeer_list_init() - Initialize ML peer list
498  * @ml_dev: MLO DEV object
499  *
500  * API to initialize MLO peer list
501  *
502  * Return: SUCCESS, if initialized successfully
503  */
504 QDF_STATUS mlo_dev_mlpeer_list_init(struct wlan_mlo_dev_context *ml_dev);
505 
506 /**
507  * mlo_dev_mlpeer_list_deinit() - destroys ML peer list
508  * @ml_dev: MLO DEV object
509  *
510  * API to destroys MLO peer list
511  *
512  * Return: SUCCESS, if initialized successfully
513  */
514 QDF_STATUS mlo_dev_mlpeer_list_deinit(struct wlan_mlo_dev_context *ml_dev);
515 
516 /**
517  * wlan_peer_is_mlo() - check whether peer is MLO link peer
518  * @peer: link peer object
519  *
520  * API to check link peer is part of MLO peer or not
521  *
522  * Return: true if it MLO peer
523  *         false, if it is not MLO peer
524  */
525 static inline uint8_t wlan_peer_is_mlo(struct wlan_objmgr_peer *peer)
526 {
527 	return wlan_peer_mlme_flag_ext_get(peer, WLAN_PEER_FEXT_MLO);
528 }
529 
530 /**
531  * wlan_peer_set_mlo() - Set peer as MLO link peer
532  * @peer: link peer object
533  *
534  * API to set MLO peer flag in link peer is part of MLO peer
535  *
536  * Return: void
537  */
538 static inline void wlan_peer_set_mlo(struct wlan_objmgr_peer *peer)
539 {
540 	return wlan_peer_mlme_flag_ext_set(peer, WLAN_PEER_FEXT_MLO);
541 }
542 
543 /**
544  * wlan_peer_clear_mlo() - clear peer as MLO link peer
545  * @peer: link peer object
546  *
547  * API to clear MLO peer flag in link peer
548  *
549  * Return: void
550  */
551 static inline void wlan_peer_clear_mlo(struct wlan_objmgr_peer *peer)
552 {
553 	return wlan_peer_mlme_flag_ext_clear(peer, WLAN_PEER_FEXT_MLO);
554 }
555 
556 #if defined(MESH_MODE_SUPPORT) && defined(WLAN_FEATURE_11BE_MLO)
557 /**
558  * wlan_mlo_peer_is_mesh() - Check if ml_peer is configured to operate as MESH
559  * @ml_peer: MLO peer
560  *
561  * Return: TRUE if ml peer is configured as MESH
562  */
563 bool wlan_mlo_peer_is_mesh(struct wlan_mlo_peer_context *ml_peer);
564 #else
565 static inline
566 bool wlan_mlo_peer_is_mesh(struct wlan_mlo_peer_context *ml_peer)
567 {
568 	return false;
569 }
570 #endif
571 
572 #ifdef UMAC_SUPPORT_MLNAWDS
573 /**
574  * wlan_mlo_peer_is_nawds() - Check if ml_peer is configured to operate as NAWDS
575  * @ml_peer: MLO peer
576  *
577  * Return TRUE if ml peer is configured as NAWDS
578  */
579 bool wlan_mlo_peer_is_nawds(struct wlan_mlo_peer_context *ml_peer);
580 #else
581 static inline
582 bool wlan_mlo_peer_is_nawds(struct wlan_mlo_peer_context *ml_peer)
583 {
584 	return false;
585 }
586 #endif
587 #ifdef UMAC_MLO_AUTH_DEFER
588 /**
589  * mlo_peer_link_auth_defer() - Auth request defer for MLO peer
590  * @ml_peer: ML peer
591  * @link_mac:  Link peer MAC address
592  * @auth_params: Defer Auth param
593  *
594  * This function saves Auth request params in MLO peer
595  *
596  * Return: SUCCESS if MAC address matches one of the link peers
597  *         FAILURE, if MAC address doesn't match
598  */
599 QDF_STATUS mlo_peer_link_auth_defer(struct wlan_mlo_peer_context *ml_peer,
600 				    struct qdf_mac_addr *link_mac,
601 				    struct mlpeer_auth_params *auth_params);
602 
603 /**
604  * mlo_peer_free_auth_param() - Free deferred Auth request params
605  * @auth_params: Defer Auth param
606  *
607  * This function frees Auth request params
608  *
609  * Return: void
610  */
611 void mlo_peer_free_auth_param(struct mlpeer_auth_params *auth_params);
612 #else
613 static inline void
614 mlo_peer_free_auth_param(struct mlpeer_auth_params *auth_params)
615 {
616 }
617 #endif
618 
619 /**
620  * wlan_mlo_partner_peer_delete_is_allowed() - Checks MLO peer delete is allowed
621  * @src_peer: Link peer
622  *
623  * This function checks whether MLO peer can be deleted along with link peer
624  * delete in link removal cases
625  *
626  * Return: true, if MLO peer can be deleted
627  */
628 bool wlan_mlo_partner_peer_delete_is_allowed(struct wlan_objmgr_peer *src_peer);
629 #endif
630