xref: /wlan-dirver/qca-wifi-host-cmn/dp/inc/cdp_txrx_peer_ops.h (revision cd39549564686e1d60a410c477b7c6e9e19791fd)
1 /*
2  * Copyright (c) 2016 The Linux Foundation. All rights reserved.
3  *
4  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5  *
6  *
7  * Permission to use, copy, modify, and/or distribute this software for
8  * any purpose with or without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19  * PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27  /**
28  * @file cdp_txrx_peer.h
29  * @brief Define the host data path peer API functions
30  * called by the host control SW and the OS interface module
31  */
32 #ifndef _CDP_TXRX_PEER_H_
33 #define _CDP_TXRX_PEER_H_
34 #include <cdp_txrx_ops.h>
35 
36 /**
37  * cdp_peer_register() - Register peer into physical device
38  * @soc - data path soc handle
39  * @pdev - data path device instance
40  * @sta_desc - peer description
41  *
42  * Register peer into physical device
43  *
44  * Return: QDF_STATUS_SUCCESS registration success
45  *         QDF_STATUS_E_NOSUPPORT not support this feature
46  */
47 static inline QDF_STATUS
48 cdp_peer_register(ol_txrx_soc_handle soc, void *pdev,
49 		struct ol_txrx_desc_type *sta_desc)
50 {
51 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
52 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
53 			"%s invalid instance", __func__);
54 		return QDF_STATUS_E_INVAL;
55 	}
56 
57 	if (soc->ops->peer_ops->register_peer)
58 		return soc->ops->peer_ops->register_peer(pdev, sta_desc);
59 
60 	return QDF_STATUS_E_NOSUPPORT;
61 }
62 
63 /**
64  * cdp_peer_clear() - remove peer from physical device
65  * @soc - data path soc handle
66  * @pdev - data path device instance
67  * @sta_id - local peer id
68  *
69  * remove peer from physical device
70  *
71  * Return: QDF_STATUS_SUCCESS registration success
72  *         QDF_STATUS_E_NOSUPPORT not support this feature
73  */
74 static inline QDF_STATUS
75 cdp_peer_clear(ol_txrx_soc_handle soc, void *pdev, uint8_t sta_id)
76 {
77 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
78 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
79 			"%s invalid instance", __func__);
80 		return QDF_STATUS_E_INVAL;
81 	}
82 
83 	return QDF_STATUS_E_NOSUPPORT;
84 }
85 
86 /**
87  * cdp_peer_register_ocb_peer() - register ocb peer from physical device
88  * @soc - data path soc handle
89  * @cds_ctx - cds void context
90  * @mac_addr - mac address for ocb self peer
91  * @peer_id - local peer id
92  *
93  * register ocb peer from physical device
94  *
95  * Return: QDF_STATUS_SUCCESS registration success
96  *         QDF_STATUS_E_NOSUPPORT not support this feature
97  */
98 static inline QDF_STATUS
99 cdp_peer_register_ocb_peer(ol_txrx_soc_handle soc, void *cds_ctx,
100 		uint8_t *mac_addr, uint8_t *peer_id)
101 {
102 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
103 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
104 			"%s invalid instance", __func__);
105 		return QDF_STATUS_E_INVAL;
106 	}
107 
108 	if (soc->ops->peer_ops->register_ocb_peer)
109 		return soc->ops->peer_ops->register_ocb_peer(cds_ctx,
110 			mac_addr, peer_id);
111 
112 	return QDF_STATUS_E_NOSUPPORT;
113 }
114 
115 /**
116  * cdp_peer_remove_for_vdev() - remove peer instance from virtual interface
117  * @soc - data path soc handle
118  * @vdev - virtual interface instance
119  * @callback - remove done notification callback function pointer
120  * @callback_context - callback caller context
121  * @remove_last_peer - removed peer is last peer or not
122  *
123  * remove peer instance from virtual interface
124  *
125  * Return: NONE
126  */
127 static inline void
128 cdp_peer_remove_for_vdev(ol_txrx_soc_handle soc,
129 		void *vdev, ol_txrx_vdev_peer_remove_cb callback,
130 		void *callback_context, bool remove_last_peer)
131 {
132 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
133 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
134 			"%s invalid instance", __func__);
135 		return;
136 	}
137 
138 	if (soc->ops->peer_ops->remove_peers_for_vdev)
139 		return soc->ops->peer_ops->remove_peers_for_vdev(
140 			vdev, callback, callback_context, remove_last_peer);
141 
142 	return;
143 }
144 
145 /**
146  * cdp_peer_find_by_addr() - Find peer by peer mac address
147  * @soc - data path soc handle
148  * @pdev - data path device instance
149  * @peer_addr - peer mac address
150  * @peer_id - local peer id with target mac address
151  *
152  * Find peer and local peer id by peer mac address
153  *
154  * Return: peer instance void pointer
155  *         NULL cannot find target peer
156  */
157 static inline void
158 *cdp_peer_find_by_addr(ol_txrx_soc_handle soc, void *pdev,
159 		uint8_t *peer_addr, uint8_t *peer_id)
160 {
161 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
162 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
163 			"%s invalid instance", __func__);
164 		return NULL;
165 	}
166 
167 	if (soc->ops->peer_ops->find_peer_by_addr)
168 		return soc->ops->peer_ops->find_peer_by_addr(
169 			pdev, peer_addr, peer_id);
170 
171 	return NULL;
172 }
173 
174 /**
175  * cdp_peer_find_by_addr_and_vdev() - Find peer by peer mac address within vdev
176  * @soc - data path soc handle
177  * @pdev - data path device instance
178  * @vdev - virtual interface instance
179  * @peer_addr - peer mac address
180  * @peer_id - local peer id with target mac address
181  *
182  * Find peer by peer mac address within vdev
183  *
184  * Return: peer instance void pointer
185  *         NULL cannot find target peer
186  */
187 static inline void
188 *cdp_peer_find_by_addr_and_vdev(ol_txrx_soc_handle soc, void *pdev,
189 		void *vdev, uint8_t *peer_addr, uint8_t *peer_id)
190 {
191 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
192 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
193 			"%s invalid instance", __func__);
194 		return NULL;
195 	}
196 
197 	if (soc->ops->peer_ops->find_peer_by_addr_and_vdev)
198 		return soc->ops->peer_ops->find_peer_by_addr_and_vdev(
199 			pdev, vdev, peer_addr, peer_id);
200 
201 	return NULL;
202 }
203 
204 /**
205  * cdp_peer_find_by_local_id() - Find peer by local peer id
206  * @soc - data path soc handle
207  * @pdev - data path device instance
208  * @local_peer_id - local peer id want to find
209  *
210  * Find peer by local peer id within physical device
211  *
212  * Return: peer instance void pointer
213  *         NULL cannot find target peer
214  */
215 static inline void
216 *cdp_peer_find_by_local_id(ol_txrx_soc_handle soc, void *pdev,
217 		uint8_t local_peer_id)
218 {
219 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
220 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
221 			"%s invalid instance", __func__);
222 		return NULL;
223 	}
224 
225 	if (soc->ops->peer_ops->peer_find_by_local_id)
226 		return soc->ops->peer_ops->peer_find_by_local_id(
227 			pdev, local_peer_id);
228 
229 	return NULL;
230 }
231 
232 /**
233  * cdp_peer_state_update() - update peer local state
234  * @soc - data path soc handle
235  * @pdev - data path device instance
236  * @peer_addr - peer mac address
237  * @state - new peer local state
238  *
239  * update peer local state
240  *
241  * Return: QDF_STATUS_SUCCESS registration success
242  *         QDF_STATUS_E_NOSUPPORT not support this feature
243  */
244 static inline QDF_STATUS
245 cdp_peer_state_update(ol_txrx_soc_handle soc, void *pdev,
246 		uint8_t *peer_addr, enum ol_txrx_peer_state state)
247 {
248 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
249 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
250 			"%s invalid instance", __func__);
251 		return QDF_STATUS_E_INVAL;
252 	}
253 
254 	if (soc->ops->peer_ops->peer_state_update)
255 		return soc->ops->peer_ops->peer_state_update(
256 			pdev, peer_addr, state);
257 
258 	return QDF_STATUS_E_NOSUPPORT;
259 }
260 
261 /**
262  * cdp_peer_state_get() - Get local peer state
263  * @soc - data path soc handle
264  * @peer - peer instance
265  *
266  * Get local peer state
267  *
268  * Return: peer status
269  */
270 static inline int
271 cdp_peer_state_get(ol_txrx_soc_handle soc, void *peer)
272 {
273 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
274 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
275 			"%s invalid instance", __func__);
276 		return 0;
277 	}
278 
279 	if (soc->ops->peer_ops->get_peer_state)
280 		return soc->ops->peer_ops->get_peer_state(peer);
281 
282 	return 0;
283 }
284 
285 /**
286  * cdp_peer_get_local_peer_id() - Find local peer id within peer instance
287  * @soc - data path soc handle
288  * @peer - peer instance
289  *
290  * Find local peer id within peer instance
291  *
292  * Return: local peer id
293  *         HTT_INVALID_PEER Invalid peer
294  */
295 static inline uint16_t
296 cdp_peer_get_local_peer_id(ol_txrx_soc_handle soc, void *peer)
297 {
298 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
299 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
300 			"%s invalid instance", __func__);
301 		return HTT_INVALID_PEER;
302 	}
303 
304 	if (soc->ops->peer_ops->local_peer_id)
305 		return soc->ops->peer_ops->local_peer_id(peer);
306 
307 	return HTT_INVALID_PEER;
308 }
309 
310 /**
311  * cdp_peer_get_vdevid() - Get virtaul interface id which peer registered
312  * @soc - data path soc handle
313  * @peer - peer instance
314  * @vdev_id - virtaul interface id which peer registered
315  *
316  * Get virtaul interface id which peer registered
317  *
318  * Return: QDF_STATUS_SUCCESS registration success
319  *         QDF_STATUS_E_NOSUPPORT not support this feature
320  */
321 static inline QDF_STATUS
322 cdp_peer_get_vdevid(ol_txrx_soc_handle soc, void *peer, uint8_t *vdev_id)
323 {
324 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
325 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
326 			"%s invalid instance", __func__);
327 		return QDF_STATUS_E_INVAL;
328 	}
329 
330 	if (soc->ops->peer_ops->get_vdevid)
331 		return soc->ops->peer_ops->get_vdevid(peer, vdev_id);
332 
333 	return QDF_STATUS_E_NOSUPPORT;
334 }
335 
336 /**
337  * cdp_peer_get_vdev_by_sta_id() - Get vdev instance by local peer id
338  * @soc - data path soc handle
339  * @sta_id - local peer id
340  *
341  * Get virtaul interface id by local peer id
342  *
343  * Return: Virtual interface instance
344  *         NULL in case cannot find
345  */
346 static inline void
347 *cdp_peer_get_vdev_by_sta_id(ol_txrx_soc_handle soc, uint8_t sta_id)
348 {
349 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
350 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
351 			"%s invalid instance", __func__);
352 		return NULL;
353 	}
354 
355 	if (soc->ops->peer_ops->get_vdev_by_sta_id)
356 		return soc->ops->peer_ops->get_vdev_by_sta_id(sta_id);
357 
358 	return NULL;
359 }
360 
361 /**
362  * cdp_peer_get_peer_mac_addr() - Get peer mac address
363  * @soc - data path soc handle
364  * @peer - peer instance
365  *
366  * Get peer mac address
367  *
368  * Return: peer mac address pointer
369  *         NULL in case cannot find
370  */
371 static inline uint8_t
372 *cdp_peer_get_peer_mac_addr(ol_txrx_soc_handle soc, void *peer)
373 {
374 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
375 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
376 			"%s invalid instance", __func__);
377 		return NULL;
378 	}
379 
380 	if (soc->ops->peer_ops->peer_get_peer_mac_addr)
381 		return soc->ops->peer_ops->peer_get_peer_mac_addr(peer);
382 
383 	return NULL;
384 }
385 
386 /**
387  * cdp_peer_get_vdev() - Get virtual interface instance which peer belongs
388  * @soc - data path soc handle
389  * @peer - peer instance
390  *
391  * Get virtual interface instance which peer belongs
392  *
393  * Return: virtual interface instance pointer
394  *         NULL in case cannot find
395  */
396 static inline void
397 *cdp_peer_get_vdev(ol_txrx_soc_handle soc, void *peer)
398 {
399 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
400 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
401 			"%s invalid instance", __func__);
402 		return NULL;
403 	}
404 
405 	if (soc->ops->peer_ops->get_vdev_for_peer)
406 		return soc->ops->peer_ops->get_vdev_for_peer(peer);
407 
408 	return NULL;
409 }
410 
411 /**
412  * cdp_peer_update_ibss_add_peer_num_of_vdev() - update number of peer
413  * @soc - data path soc handle
414  * @vdev - virtual interface instance
415  * @peer_num_delta - number of peer should be updated
416  *
417  * update number of peer
418  *
419  * Return: updated number of peer
420  *         0 fail
421  */
422 static inline int16_t
423 cdp_peer_update_ibss_add_peer_num_of_vdev(ol_txrx_soc_handle soc,
424 		void *vdev, int16_t peer_num_delta)
425 {
426 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
427 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
428 			"%s invalid instance", __func__);
429 		return 0;
430 	}
431 
432 	if (soc->ops->peer_ops->update_ibss_add_peer_num_of_vdev)
433 		return soc->ops->peer_ops->update_ibss_add_peer_num_of_vdev(
434 			vdev, peer_num_delta);
435 
436 	return 0;
437 }
438 
439 /**
440  * cdp_peer_copy_mac_addr_raw() - copy peer mac address
441  * @soc - data path soc handle
442  * @vdev - virtual interface instance
443  * @bss_addr - mac address should be copied
444  *
445  * copy peer mac address
446  *
447  * Return: none
448  */
449 static inline void
450 cdp_peer_copy_mac_addr_raw(ol_txrx_soc_handle soc,
451 		void *vdev, uint8_t *bss_addr)
452 {
453 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
454 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
455 			"%s invalid instance", __func__);
456 		return;
457 	}
458 
459 	if (soc->ops->peer_ops->copy_mac_addr_raw)
460 		return soc->ops->peer_ops->copy_mac_addr_raw(vdev, bss_addr);
461 
462 	return;
463 }
464 
465 /**
466  * cdp_peer_add_last_real_peer() - Add peer with last peer marking
467  * @soc - data path soc handle
468  * @pdev - data path device instance
469  * @vdev - virtual interface instance
470  * @peer_id - local peer id
471  *
472  * copy peer mac address
473  *
474  * Return: none
475  */
476 static inline void
477 cdp_peer_add_last_real_peer(ol_txrx_soc_handle soc,
478 		void *pdev, void *vdev, uint8_t *peer_id)
479 {
480 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
481 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
482 			"%s invalid instance", __func__);
483 		return;
484 	}
485 
486 	if (soc->ops->peer_ops->add_last_real_peer)
487 		return soc->ops->peer_ops->add_last_real_peer(
488 			pdev, vdev, peer_id);
489 	return;
490 }
491 
492 /**
493  * cdp_peer_last_assoc_received() - last assoc received peer
494  * @soc - data path soc handle
495  * @peer - peer instance pointer
496  *
497  * !!! This should be implemented on legacy also
498  * last assoc received peer
499  *
500  * Return: pointer
501  */
502 static inline qdf_time_t *
503 cdp_peer_last_assoc_received(ol_txrx_soc_handle soc, void *peer)
504 {
505 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
506 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
507 			"%s invalid instance", __func__);
508 		return NULL;
509 	}
510 
511 	if (soc->ops->peer_ops->last_assoc_received)
512 		return soc->ops->peer_ops->last_assoc_received(peer);
513 
514 	return NULL;
515 }
516 
517 /**
518  * cdp_peer_last_disassoc_received() - last disassoc received peer
519  * @soc - data path soc handle
520  * @peer - peer instance pointer
521  *
522  * !!! This should be implemented on legacy also
523  * last disassoc received peer
524  *
525  * Return: pointer
526  */
527 static inline qdf_time_t *
528 cdp_peer_last_disassoc_received(ol_txrx_soc_handle soc, void *peer)
529 {
530 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
531 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
532 			"%s invalid instance", __func__);
533 		return NULL;
534 	}
535 
536 	if (soc->ops->peer_ops->last_disassoc_received)
537 		return soc->ops->peer_ops->last_disassoc_received(peer);
538 
539 	return NULL;
540 }
541 
542 /**
543  * cdp_peer_last_deauth_received() - last deauth received peer
544  * @soc - data path soc handle
545  * @peer - peer instance pointer
546  *
547  * !!! This should be implemented on legacy also
548  * last deauth received peer
549  *
550  * Return: pointer
551  */
552 static inline qdf_time_t *
553 cdp_peer_last_deauth_received(ol_txrx_soc_handle soc, void *peer)
554 {
555 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
556 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
557 			"%s invalid instance", __func__);
558 		return NULL;
559 	}
560 
561 	if (soc->ops->peer_ops->last_deauth_received)
562 		return soc->ops->peer_ops->last_deauth_received(peer);
563 
564 	return NULL;
565 }
566 
567 /**
568  * cdp_peer_is_vdev_restore_last_peer() - restore last peer
569  * @soc - data path soc handle
570  * @peer - peer instance pointer
571  *
572  * restore last peer
573  *
574  * Return: true, restore success
575  *         fasle, restore fail
576  */
577 static inline bool
578 cdp_peer_is_vdev_restore_last_peer(ol_txrx_soc_handle soc, void *peer)
579 {
580 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
581 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
582 			"%s invalid instance", __func__);
583 		return false;
584 	}
585 
586 	if (soc->ops->peer_ops->is_vdev_restore_last_peer)
587 		return soc->ops->peer_ops->is_vdev_restore_last_peer(peer);
588 
589 	return false;
590 }
591 
592 /**
593  * cdp_peer_update_last_real_peer() - update last real peer
594  * @soc - data path soc handle
595  * @pdev - data path device instance
596  * @peer - peer instance pointer
597  * @peer_id - local peer id
598  * @restore_last_peer - restore last peer or not
599  *
600  * update last real peer
601  *
602  * Return: none
603  */
604 static inline void
605 cdp_peer_update_last_real_peer(ol_txrx_soc_handle soc, void *pdev,
606 		void *peer, uint8_t *peer_id, bool restore_last_peer)
607 {
608 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
609 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
610 			"%s invalid instance", __func__);
611 		return;
612 	}
613 
614 	if (soc->ops->peer_ops->update_last_real_peer)
615 		return soc->ops->peer_ops->update_last_real_peer(pdev, peer,
616 			peer_id, restore_last_peer);
617 
618 	return;
619 }
620 
621 /**
622  * ol_txrx_peer_detach_force_delete() - Detach and delete a peer's data object
623  * @peer - the object to detach
624  *
625  * Detach a peer and force the peer object to be removed. It is called during
626  * roaming scenario when the firmware has already deleted a peer.
627  * Peer object is freed immediately to avoid duplicate peers during roam sync
628  * indication processing.
629  *
630  * Return: None
631  */
632 static inline void cdp_peer_detach_force_delete(ol_txrx_soc_handle soc,
633 		void *peer)
634 {
635 	if (!soc || !soc->ops || !soc->ops->peer_ops) {
636 		QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
637 			"%s invalid instance", __func__);
638 		return;
639 	}
640 
641 	if (soc->ops->peer_ops->peer_detach_force_delete)
642 		return soc->ops->peer_ops->peer_detach_force_delete(peer);
643 
644 	return;
645 }
646 #endif /* _CDP_TXRX_PEER_H_ */
647