xref: /wlan-dirver/qca-wifi-host-cmn/umac/mlo_mgr/inc/wlan_mlo_mgr_peer.h (revision 2f4b444fb7e689b83a4ab0e7b3b38f0bf4def8e0)
1 /*
2  * Copyright (c) 2021, The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /*
18  * DOC: contains MLO manager public file containing peer functionality
19  */
20 #ifndef _WLAN_MLO_MGR_PEER_H_
21 #define _WLAN_MLO_MGR_PEER_H_
22 
23 #include "wlan_objmgr_peer_obj.h"
24 /**
25  * mlo_peer_create - Initiatiate peer create on secondary link(s)
26  * by posting a message
27  *
28  * @vdev: pointer to vdev
29  * @peer: pointer to peer context
30  * @mlo_ie: MLO information element
31  * @aid: association ID
32  *
33  * Initiate the peer on the second link
34  *
35  * Return: none
36  */
37 void mlo_peer_create(struct wlan_objmgr_vdev *vdev,
38 			       struct wlan_objmgr_peer *peer, uint8_t *mlo_ie,
39 			       uint8_t aid);
40 
41 /**
42  * mlo_peer_attach - Attaches the peer by updating the MLO peer context with
43  * the new link information
44  *
45  * @vdev: pointer to vdev
46  * @peer: pointer to peer context
47  *
48  * Return: none
49  */
50 void mlo_peer_attach(struct wlan_objmgr_vdev *vdev,
51 		     struct wlan_objmgr_peer *peer);
52 
53 /**
54  * mlo_peer_setup_failed_notify - Notify MLO manager that peer setup has failed
55  * and to cleanup by deleting the partner peers
56  *
57  * @vdev: pointer to vdev
58  *
59  * This API is called in scenarios where peer create or peer assoc fails
60  *
61  * Return: none
62  */
63 void mlo_peer_setup_failed_notify(struct wlan_objmgr_vdev *vdev);
64 
65 /**
66  * mlo_peer_disconnect_notify - Notify MLO manager that peer has disconnected
67  * and to clean up by deleting partner peers
68  *
69  * @vdev: pointer to vdev
70  *
71  * Return: none
72  */
73 void mlo_peer_disconnect_notify(struct wlan_objmgr_peer *peer);
74 
75 /**
76  * wlan_peer_delete_complete - Notify MLO manager that peer delete is completed
77  * and to clean up by unlinking the peer object
78  *
79  * @peer: pointer to peer context
80  *
81  * Return: none
82  */
83 void wlan_peer_delete_complete(struct wlan_objmgr_peer *peer);
84 
85 /**
86  * mlo_peer_delete - Delete the peer object
87  *
88  * @peer: pointer to peer context
89  *
90  * Return: none
91  */
92 void mlo_peer_delete(struct wlan_objmgr_peer *peer);
93 
94 /**
95  * is_mlo_all_peer_links_deleted - Check if all the peer links are deleted
96  *
97  * Return: true if all the peer links are deleted, false otherwise
98  */
99 bool is_mlo_all_peer_links_deleted(void);
100 
101 /**
102  * wlan_mlo_peer_is_disconnect_progress() - MLO peer is in disconnect progress
103  * @ml_peer: MLO peer
104  *
105  * This function checks whether MLO Peer is in disconnect progress
106  *
107  * Return: SUCCESS if MLO Peer is in disconnect progress
108  */
109 QDF_STATUS wlan_mlo_peer_is_disconnect_progress(
110 					struct wlan_mlo_peer_context *ml_peer);
111 
112 /**
113  * wlan_mlo_peer_is_assoc_done() - MLO peer is Assoc complete
114  * @ml_peer: MLO peer
115  *
116  * This function checks whether MLO Peer's Assoc is completed
117  *
118  * Return: SUCCESS if MLO Peer Assoc is completed
119  */
120 QDF_STATUS wlan_mlo_peer_is_assoc_done(struct wlan_mlo_peer_context *ml_peer);
121 
122 /**
123  * wlan_mlo_peer_get_assoc_peer() - get assoc peer
124  * @ml_peer: MLO peer
125  *
126  * This function returns assoc peer of MLO peer
127  *
128  * Return: assoc peer, if it is found, otherwise NULL
129  */
130 struct wlan_objmgr_peer *wlan_mlo_peer_get_assoc_peer(
131 					struct wlan_mlo_peer_context *ml_peer);
132 
133 /**
134  * wlan_mlo_partner_peer_assoc_post() - Notify partner peer assoc
135  * @peer: Link peer
136  *
137  * This function notifies link peers to send peer assoc command to FW
138  *
139  * Return: void
140  */
141 void wlan_mlo_partner_peer_assoc_post(struct wlan_objmgr_peer *assoc_peer);
142 
143 /**
144  * wlan_mlo_partner_peer_create_failed_notify() - Notify peer creation fail
145  * @ml_peer: MLO peer
146  *
147  * This function notifies about link peer creation failure
148  *
149  * Return: void
150  */
151 void wlan_mlo_partner_peer_create_failed_notify(
152 					struct wlan_mlo_peer_context *ml_peer);
153 
154 /**
155  * wlan_mlo_partner_peer_disconnect_notify() - Notify peer disconnect
156  * @peer: Link peer
157  *
158  * This function notifies about disconnect is being initilated on link peer
159  *
160  * Return: void
161  */
162 void wlan_mlo_partner_peer_disconnect_notify(struct wlan_objmgr_peer *src_peer);
163 
164 /**
165  * wlan_mlo_peer_create() - MLO peer create
166  * @vdev: Link VDEV
167  * @link_peer: Link peer
168  * @ml_info: ML links info
169  * @frm_buf: Assoc req buffer
170  * @aid: AID, if already allocated
171  *
172  * This function creates MLO peer and notifies other partner VDEVs to create
173  * link peers
174  *
175  * Return: SUCCESS, if MLO peer is successfully created
176  */
177 QDF_STATUS wlan_mlo_peer_create(struct wlan_objmgr_vdev *vdev,
178 				struct wlan_objmgr_peer *link_peer,
179 				struct mlo_partner_info *ml_info,
180 				qdf_nbuf_t frm_buf,
181 				uint16_t aid);
182 
183 /**
184  * mlo_peer_free() - Free MLO peer
185  * @ml_peer: MLO peer
186  *
187  * This function frees MLO peer and resets MLO peer associations
188  * Note, this API is ref count protected, it should be always invoked
189  * from wlan_mlo_peer_release_ref()
190  *
191  * Return: void
192  */
193 void mlo_peer_free(struct wlan_mlo_peer_context *ml_peer);
194 
195 /**
196  * wlan_mlo_peer_get_ref() - Get ref of MLO peer
197  * @ml_peer: MLO peer
198  *
199  * This function gets ref of MLO peer
200  *
201  * Return: void
202  */
203 static inline void wlan_mlo_peer_get_ref(struct wlan_mlo_peer_context *ml_peer)
204 {
205 	qdf_atomic_inc(&ml_peer->ref_cnt);
206 }
207 
208 /**
209  * wlan_mlo_peer_release_ref() - Release ref of MLO peer
210  * @ml_peer: MLO peer
211  *
212  * This function releases ref of MLO peer, if ref is 0, invokes MLO peer free
213  *
214  * Return: void
215  */
216 static inline void wlan_mlo_peer_release_ref(
217 					struct wlan_mlo_peer_context *ml_peer)
218 {
219 	if (qdf_atomic_dec_and_test(&ml_peer->ref_cnt))
220 		mlo_peer_free(ml_peer);
221 }
222 
223 /**
224  * wlan_mlo_link_peer_attach() - MLO link peer attach
225  * @ml_peer: MLO peer
226  * @peer: Link peer
227  *
228  * This function attaches link peer to MLO peer
229  *
230  * Return: SUCCESS, if peer is successfully attached to MLO peer
231  */
232 QDF_STATUS wlan_mlo_link_peer_attach(struct wlan_mlo_peer_context *ml_peer,
233 				     struct wlan_objmgr_peer *peer);
234 
235 /**
236  * wlan_mlo_link_peer_delete() - MLO link peer delete
237  * @peer: Link peer
238  *
239  * This function detaches link peer from MLO peer, if this peer is last link
240  * peer, then MLO peer gets deleted
241  *
242  * Return: SUCCESS, if peer is detached from MLO peer
243  */
244 QDF_STATUS wlan_mlo_link_peer_delete(struct wlan_objmgr_peer *peer);
245 
246 /**
247  ** APIs to operations on ML peer object
248  */
249 typedef QDF_STATUS (*wlan_mlo_op_handler)(struct wlan_mlo_dev_context *ml_dev,
250 				    void *ml_peer,
251 				    void *arg);
252 
253 /**
254  * wlan_mlo_iterate_ml_peerlist() - iterate through all ml peer objects
255  * @ml_dev: MLO DEV object
256  * @handler: the handler will be called for each ml peer
257  *            the handler should be implemented to perform required operation
258  * @arg:     agruments passed by caller
259  *
260  * API to be used for performing the operations on all ML PEER objects
261  *
262  * Return: SUCCESS/FAILURE
263  */
264 QDF_STATUS wlan_mlo_iterate_ml_peerlist(struct wlan_mlo_dev_context *ml_dev,
265 					wlan_mlo_op_handler handler,
266 					void *arg);
267 
268 /**
269  * wlan_mlo_get_mlpeer_by_linkmac() - find ML peer by Link MAC address
270  * @ml_dev: MLO DEV object
271  * @link_mac:  Link peer MAC address
272  *
273  * API to get ML peer using link MAC address
274  *
275  * Return: ML peer object, if it is found
276  *         otherwise, returns NULL
277  */
278 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_linkmac(
279 				struct wlan_mlo_dev_context *ml_dev,
280 				struct qdf_mac_addr *link_mac);
281 
282 /**
283  * wlan_mlo_get_mlpeer_by_aid() - find ML peer by AID
284  * @ml_dev: MLO DEV object
285  * @aid:  AID
286  *
287  * API to get ML peer using AID
288  *
289  * Return: ML peer object, if it is found
290  *         otherwise, returns NULL
291  */
292 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_aid(
293 				struct wlan_mlo_dev_context *ml_dev,
294 				uint16_t assoc_id);
295 
296 /**
297  * wlan_mlo_get_mlpeer_by_ml_peerid() - find ML peer by ML peer id
298  * @ml_dev: MLO DEV object
299  * @ml_peerid:  ML Peer ID
300  *
301  * API to get ML peer using ML peer id
302  *
303  * Return: ML peer object, if it is found
304  *         otherwise, returns NULL
305  */
306 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer_by_ml_peerid(
307 				struct wlan_mlo_dev_context *ml_dev,
308 				uint16_t ml_peerid);
309 
310 /**
311  * wlan_mlo_get_mlpeer() - find ML peer by MLD MAC address
312  * @ml_dev: MLO DEV object
313  * @ml_addr: MLO MAC address
314  *
315  * API to get ML peer using MLO MAC address
316  *
317  * Return: ML peer object, if it is found
318  *         otherwise, returns NULL
319  */
320 struct wlan_mlo_peer_context *wlan_mlo_get_mlpeer(
321 				struct wlan_mlo_dev_context *ml_dev,
322 				struct qdf_mac_addr *ml_addr);
323 
324 /**
325  * mlo_dev_mlpeer_attach() - Add ML PEER to ML peer list
326  * @ml_dev: MLO DEV object
327  * @ml_peer: ML peer
328  *
329  * API to attach ML PEER to MLD PEER table
330  *
331  * Return: SUCCESS, if it attached successfully
332  *         otherwise, returns FAILURE
333  */
334 QDF_STATUS mlo_dev_mlpeer_attach(struct wlan_mlo_dev_context *ml_dev,
335 				 struct wlan_mlo_peer_context *ml_peer);
336 
337 /**
338  * mlo_dev_mlpeer_detach() - Delete ML PEER from ML peer list
339  * @ml_dev: MLO DEV object
340  * @ml_peer: ML peer
341  *
342  * API to detach ML PEER from MLD PEER table
343  *
344  * Return: SUCCESS, if it detached successfully
345  *         otherwise, returns FAILURE
346  */
347 QDF_STATUS mlo_dev_mlpeer_detach(struct wlan_mlo_dev_context *ml_dev,
348 				 struct wlan_mlo_peer_context *ml_peer);
349 
350 /**
351  * mlo_dev_mlpeer_list_init() - Initialize ML peer list
352  * @ml_dev: MLO DEV object
353  *
354  * API to initialize MLO peer list
355  *
356  * Return: SUCCESS, if initialized successfully
357  */
358 QDF_STATUS mlo_dev_mlpeer_list_init(struct wlan_mlo_dev_context *ml_dev);
359 
360 /**
361  * mlo_dev_mlpeer_list_deinit() - destroys ML peer list
362  * @ml_dev: MLO DEV object
363  *
364  * API to destroys MLO peer list
365  *
366  * Return: SUCCESS, if initialized successfully
367  */
368 QDF_STATUS mlo_dev_mlpeer_list_deinit(struct wlan_mlo_dev_context *ml_dev);
369 
370 /**
371  * wlan_peer_is_mlo() - check whether peer is MLO link peer
372  * @peer: link peer object
373  *
374  * API to check link peer is part of MLO peer or not
375  *
376  * Return: true if it MLO peer
377  *         false, if it is not MLO peer
378  */
379 static inline uint8_t wlan_peer_is_mlo(struct wlan_objmgr_peer *peer)
380 {
381 	return wlan_peer_mlme_flag_ext_get(peer, WLAN_PEER_FEXT_MLO);
382 }
383 
384 /**
385  * wlan_peer_set_mlo() - Set peer as MLO link peer
386  * @peer: link peer object
387  *
388  * API to set MLO peer flag in link peer is part of MLO peer
389  *
390  * Return: void
391  */
392 static inline void wlan_peer_set_mlo(struct wlan_objmgr_peer *peer)
393 {
394 	return wlan_peer_mlme_flag_ext_set(peer, WLAN_PEER_FEXT_MLO);
395 }
396 
397 /**
398  * wlan_peer_clear_mlo() - clear peer as MLO link peer
399  * @peer: link peer object
400  *
401  * API to clear MLO peer flag in link peer
402  *
403  * Return: void
404  */
405 static inline void wlan_peer_clear_mlo(struct wlan_objmgr_peer *peer)
406 {
407 	return wlan_peer_mlme_flag_ext_clear(peer, WLAN_PEER_FEXT_MLO);
408 }
409 #endif
410