xref: /wlan-driver/qcacld-3.0/core/dp/txrx/ol_txrx_peer_find.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2011, 2015-2019,2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * @file ol_txrx_peer_find.h
22  * @brief Define the API for the rx peer lookup datapath module.
23  */
24 #ifndef _OL_TXRX_PEER_FIND__H_
25 #define _OL_TXRX_PEER_FIND__H_
26 
27 #include <htt.h>                /* HTT_INVALID_PEER */
28 #include <cdp_txrx_cmn.h>       /* ol_txrx_pdev_t, etc. */
29 #include <ol_txrx_internal.h>   /* TXRX_ASSERT */
30 
31 /**
32  * ol_txrx_peer_get_ref() - get peer reference
33  * @peer: peer for removing obj map entries
34  * @dbg_id: debug id to keep track of peer references
35  *
36  * The function increments the peer ref count. The ref count can be reduced by
37  * calling ol_txrx_peer_release_ref function. Callers are responsible for
38  * acquiring the peer_ref_mutex lock when needed.
39  *
40  * Return: peer debug id ref count or error
41  */
42 int
43 ol_txrx_peer_get_ref(struct ol_txrx_peer_t *peer,
44 		     enum peer_debug_id_type dbg_id);
45 
46 int ol_txrx_peer_find_attach(struct ol_txrx_pdev_t *pdev);
47 
48 void ol_txrx_peer_find_detach(struct ol_txrx_pdev_t *pdev);
49 
50 static inline
51 int
ol_txrx_peer_find_mac_addr_cmp(union ol_txrx_align_mac_addr_t * mac_addr1,union ol_txrx_align_mac_addr_t * mac_addr2)52 ol_txrx_peer_find_mac_addr_cmp(union ol_txrx_align_mac_addr_t *mac_addr1,
53 			       union ol_txrx_align_mac_addr_t *mac_addr2)
54 {
55 	return !((mac_addr1->align4.bytes_abcd == mac_addr2->align4.bytes_abcd)
56 		 /*
57 		  * Intentionally use & rather than &&.
58 		  * because the operands are binary rather than generic bool,
59 		  * the functionality is equivalent.
60 		  * Using && has the advantage of short-circuited evaluation,
61 		  * but using & has the advantage of no conditional branching,
62 		  * which is a more significant benefit.
63 		  */
64 		 & (mac_addr1->align4.bytes_ef == mac_addr2->align4.bytes_ef));
65 }
66 
67 static inline
ol_txrx_peer_find_by_id(struct ol_txrx_pdev_t * pdev,uint16_t peer_id)68 struct ol_txrx_peer_t *ol_txrx_peer_find_by_id(struct ol_txrx_pdev_t *pdev,
69 					       uint16_t peer_id)
70 {
71 	struct ol_txrx_peer_t *peer;
72 
73 	peer = (peer_id > ol_cfg_max_peer_id(pdev->ctrl_pdev)) ? NULL :
74 	       pdev->peer_id_to_obj_map[peer_id].peer;
75 	/*
76 	 * Currently, peer IDs are assigned to vdevs as well as peers.
77 	 * If the peer ID is for a vdev, the peer_id_to_obj_map entry
78 	 * will hold NULL rather than a valid peer pointer.
79 	 */
80 	/* TXRX_ASSERT2(peer); */
81 	/*
82 	 * Only return the peer object if it is valid,
83 	 * i.e. it has not already been detached.
84 	 * If it has already been detached, then returning the
85 	 * peer object could result in unpausing the peer's tx queues
86 	 * in HL systems, which is an invalid operation following peer_detach.
87 	 */
88 	if (peer && peer->valid)
89 		return peer;
90 
91 	return NULL;
92 }
93 
94 void
95 ol_txrx_peer_find_hash_add(struct ol_txrx_pdev_t *pdev,
96 			   struct ol_txrx_peer_t *peer);
97 
98 struct ol_txrx_peer_t *
99 	ol_txrx_peer_find_hash_find_get_ref
100 				(struct ol_txrx_pdev_t *pdev,
101 				uint8_t *peer_mac_addr,
102 				int mac_addr_is_aligned,
103 				u8 check_valid,
104 				enum peer_debug_id_type dbg_id);
105 
106 struct
107 ol_txrx_peer_t *ol_txrx_peer_vdev_find_hash(struct ol_txrx_pdev_t *pdev,
108 					    struct ol_txrx_vdev_t *vdev,
109 					    uint8_t *peer_mac_addr,
110 					    int mac_addr_is_aligned,
111 					    uint8_t check_valid);
112 
113 void
114 ol_txrx_peer_find_hash_remove(struct ol_txrx_pdev_t *pdev,
115 			      struct ol_txrx_peer_t *peer);
116 
117 void ol_txrx_peer_find_hash_erase(struct ol_txrx_pdev_t *pdev);
118 
119 void ol_txrx_peer_free_inactive_list(struct ol_txrx_pdev_t *pdev);
120 
121 struct ol_txrx_peer_t *ol_txrx_assoc_peer_find(struct ol_txrx_vdev_t *vdev);
122 void ol_txrx_peer_remove_obj_map_entries(ol_txrx_pdev_handle pdev,
123 					struct ol_txrx_peer_t *peer);
124 void ol_txrx_peer_clear_map_peer(ol_txrx_pdev_handle pdev,
125 				 struct ol_txrx_peer_t *peer);
126 #if defined(TXRX_DEBUG_LEVEL) && TXRX_DEBUG_LEVEL > 5
127 void ol_txrx_peer_find_display(ol_txrx_pdev_handle pdev, int indent);
128 #else
129 #define ol_txrx_peer_find_display(pdev, indent)
130 #endif /* TXRX_DEBUG_LEVEL */
131 
132 #endif /* _OL_TXRX_PEER_FIND__H_ */
133