xref: /wlan-dirver/qca-wifi-host-cmn/umac/global_umac_dispatcher/lmac_if/inc/wlan_lmac_if_api.h (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
1 /*
2  * Copyright (c) 2016-2018, 2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  *
6  * Permission to use, copy, modify, and/or distribute this software for
7  * any purpose with or without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18  * PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #ifndef _WLAN_LMAC_IF_API_H_
22 #define _WLAN_LMAC_IF_API_H_
23 
24 #include "wlan_objmgr_cmn.h"
25 #include "wlan_objmgr_psoc_obj.h"
26 #include "wlan_objmgr_pdev_obj.h"
27 
28 /**
29  * wlan_lmac_if_umac_rx_ops_register() - UMAC rx handler register
30  * @rx_ops: Pointer to rx_ops structure to be populated
31  *
32  * Register umac RX callabacks which will be called by DA/OL/WMA/WMI
33  *
34  * Return: QDF_STATUS_SUCCESS - in case of success
35  */
36 QDF_STATUS wlan_lmac_if_umac_rx_ops_register
37 		(struct wlan_lmac_if_rx_ops *rx_ops);
38 
39 /**
40  * wlan_lmac_if_set_umac_txops_registration_cb() - tx registration
41  * callback assignment
42  * @dev_type: Dev type can be either Direct attach or Offload
43  * @handler: handler to be called for LMAC tx ops registration
44  *
45  * API to assign appropriate tx registration callback handler based on the
46  * device type(Offload or Direct attach)
47  *
48  * Return: QDF_STATUS_SUCCESS - in case of success
49  */
50 QDF_STATUS wlan_lmac_if_set_umac_txops_registration_cb
51 		(QDF_STATUS (*handler)(struct wlan_lmac_if_tx_ops *));
52 
53 /**
54  * wlan_lmac_if_set_umac_crypto_rxpn_ops_registration_cb() - crypto rxpn
55  * registration callback assignment
56  * @dev_type: Dev type can be either Direct attach or Offload
57  * @handler: handler to be called for LMAC crypto rxpn ops registration
58  *
59  * API to assign appropriate crypto rxpn registration callback handler
60  * based on the device type
61  *
62  * Return: QDF_STATUS_SUCCESS - in case of success
63  */
64 QDF_STATUS wlan_lmac_if_set_umac_crypto_rxpn_ops_registration_cb
65 		(QDF_STATUS (*handler)(struct wlan_lmac_if_rx_ops *));
66 
67 /**
68  * wlan_lmac_if_get_mgmt_txrx_rx_ops() - retrieve the mgmt rx_ops
69  * @psoc: psoc context
70  *
71  * API to retrieve the mgmt rx_ops from the psoc context
72  *
73  * Return: mgmt_rx_ops pointer
74  */
75 static inline struct wlan_lmac_if_mgmt_txrx_rx_ops *
76 wlan_lmac_if_get_mgmt_txrx_rx_ops(struct wlan_objmgr_psoc *psoc)
77 {
78 	struct wlan_lmac_if_rx_ops *rx_ops;
79 
80 	if (!psoc)
81 		return NULL;
82 
83 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
84 	if (!rx_ops) {
85 		qdf_err("rx_ops is NULL");
86 		return NULL;
87 	}
88 
89 	return &rx_ops->mgmt_txrx_rx_ops;
90 }
91 
92 /**
93  * wlan_lmac_if_get_dfs_rx_ops() - retrieve the dfs rx_ops
94  * @psoc: psoc context
95  *
96  * API to retrieve the dfs rx_ops from the psoc context
97  *
98  * Return: dfs_rx_ops pointer
99  */
100 static inline struct wlan_lmac_if_dfs_rx_ops *
101 wlan_lmac_if_get_dfs_rx_ops(struct wlan_objmgr_psoc *psoc)
102 {
103 	struct wlan_lmac_if_rx_ops *rx_ops;
104 
105 	if (!psoc)
106 		return NULL;
107 
108 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
109 	if (!rx_ops) {
110 		qdf_err("rx_ops is NULL");
111 		return NULL;
112 	}
113 
114 	return &rx_ops->dfs_rx_ops;
115 }
116 
117 /**
118  * wlan_lmac_if_get_reg_rx_ops() - retrieve the reg rx_ops
119  * @psoc: psoc context
120  *
121  * API to retrieve the reg rx_ops from the psoc context
122  *
123  * Return: reg_rx_ops pointer
124  */
125 static inline struct wlan_lmac_if_reg_rx_ops *
126 wlan_lmac_if_get_reg_rx_ops(struct wlan_objmgr_psoc *psoc)
127 {
128 	struct wlan_lmac_if_rx_ops *rx_ops;
129 
130 	if (!psoc)
131 		return NULL;
132 
133 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
134 	if (!rx_ops) {
135 		qdf_err("rx_ops is NULL");
136 		return NULL;
137 	}
138 
139 	return &rx_ops->reg_rx_ops;
140 }
141 
142 #ifdef WLAN_SUPPORT_GREEN_AP
143 /**
144  * wlan_lmac_if_get_green_ap_rx_ops() - retrieve the green ap rx_ops
145  * @psoc: psoc context
146  *
147  * API to retrieve the dfs rx_ops from the psoc context
148  *
149  * Return: green_ap_rx_ops pointer
150  */
151 static inline struct wlan_lmac_if_green_ap_rx_ops *
152 wlan_lmac_if_get_green_ap_rx_ops(struct wlan_objmgr_psoc *psoc)
153 {
154 	struct wlan_lmac_if_rx_ops *rx_ops;
155 
156 	if (!psoc)
157 		return NULL;
158 
159 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
160 	if (!rx_ops) {
161 		qdf_err("rx_ops is NULL");
162 		return NULL;
163 	}
164 
165 	return &rx_ops->green_ap_rx_ops;
166 }
167 #endif
168 
169 /**
170  * mgmt_txrx_get_nbuf() - retrieve nbuf from mgmt desc_id
171  * @pdev: pdev context
172  * @desc_id: mgmt desc_id
173  *
174  * API to retrieve the nbuf from mgmt desc_id
175  *
176  * Return: nbuf
177  */
178 static inline qdf_nbuf_t
179 mgmt_txrx_get_nbuf(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
180 {
181 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
182 	struct wlan_objmgr_psoc *psoc;
183 
184 	psoc = wlan_pdev_get_psoc(pdev);
185 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
186 
187 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_nbuf_from_desc_id)
188 		return mgmt_rx_ops->mgmt_txrx_get_nbuf_from_desc_id(pdev,
189 								     desc_id);
190 
191 	return NULL;
192 }
193 
194 /**
195  * mgmt_txrx_tx_completion_handler() - mgmt tx completion handler
196  * @pdev: pdev context
197  * @desc_id: mgmt desc_id
198  * @status: tx status
199  * @params: tx params
200  *
201  * API to handle the tx completion for mgmt frames
202  *
203  * Return: QDF_STATUS_SUCCESS - in case of success
204  */
205 static inline QDF_STATUS
206 mgmt_txrx_tx_completion_handler(struct wlan_objmgr_pdev *pdev,
207 				uint32_t desc_id, uint32_t status,
208 				void *params)
209 {
210 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
211 	struct wlan_objmgr_psoc *psoc;
212 	qdf_nbuf_t nbuf;
213 
214 	psoc = wlan_pdev_get_psoc(pdev);
215 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
216 
217 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_tx_completion_handler)
218 		return mgmt_rx_ops->mgmt_tx_completion_handler(pdev, desc_id,
219 							status, params);
220 
221 	nbuf = mgmt_txrx_get_nbuf(pdev, desc_id);
222 	if (nbuf)
223 		qdf_nbuf_free(nbuf);
224 
225 	return QDF_STATUS_E_NULL_VALUE;
226 }
227 
228 /**
229  * mgmt_txrx_rx_handler() - mgmt rx frame handler
230  * @psoc: psoc context
231  * @nbuf: nbuf
232  * @params: rx params
233  *
234  * API to receive mgmt frames
235  *
236  * Return: QDF_STATUS_SUCCESS - in case of success
237  */
238 static inline QDF_STATUS
239 mgmt_txrx_rx_handler(struct wlan_objmgr_psoc *psoc, qdf_nbuf_t nbuf,
240 			void *params)
241 {
242 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
243 
244 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
245 
246 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_rx_frame_handler)
247 		return mgmt_rx_ops->mgmt_rx_frame_handler(psoc, nbuf, params);
248 
249 	if (nbuf)
250 		qdf_nbuf_free(nbuf);
251 
252 	return QDF_STATUS_E_NULL_VALUE;
253 }
254 
255 /**
256  * mgmt_txrx_get_peer() - retrieve peer from mgmt desc_id
257  * @pdev: pdev context
258  * @desc_id: mgmt desc_id
259  *
260  * API to retrieve the peer from mgmt desc_id
261  *
262  * Return: objmgr peer pointer
263  */
264 static inline struct wlan_objmgr_peer *
265 mgmt_txrx_get_peer(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
266 {
267 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
268 	struct wlan_objmgr_psoc *psoc;
269 
270 	psoc = wlan_pdev_get_psoc(pdev);
271 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
272 
273 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_peer_from_desc_id)
274 		return mgmt_rx_ops->mgmt_txrx_get_peer_from_desc_id(pdev,
275 								     desc_id);
276 
277 	return NULL;
278 }
279 
280 /**
281  * mgmt_txrx_get_vdev_id() - retrieve vdev_id from mgmt desc_id
282  * @pdev: pdev context
283  * @desc_id: mgmt desc_id
284  *
285  * API to retrieve the vdev_id from mgmt desc_id
286  *
287  * Return: vdev_id
288  */
289 static inline uint8_t
290 mgmt_txrx_get_vdev_id(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
291 {
292 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
293 	struct wlan_objmgr_psoc *psoc;
294 
295 	psoc = wlan_pdev_get_psoc(pdev);
296 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
297 
298 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_vdev_id_from_desc_id)
299 		return mgmt_rx_ops->mgmt_txrx_get_vdev_id_from_desc_id(pdev,
300 								   desc_id);
301 
302 	return WLAN_UMAC_VDEV_ID_MAX;
303 }
304 /**
305  * mgmt_txrx_get_free_desc_count() - retrieve vdev_id from mgmt desc_id
306  * @pdev: pdev context
307  *
308  * API to get the free desc count mgmt desc pool
309  *
310  * Return: free_desc_count
311  */
312 static inline uint32_t
313 mgmt_txrx_get_free_desc_count(struct wlan_objmgr_pdev *pdev)
314 {
315 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
316 	struct wlan_objmgr_psoc *psoc;
317 	uint32_t free_desc_count = WLAN_INVALID_MGMT_DESC_COUNT;
318 
319 	psoc = wlan_pdev_get_psoc(pdev);
320 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
321 
322 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_free_desc_pool_count)
323 		free_desc_count = mgmt_rx_ops->mgmt_txrx_get_free_desc_pool_count(
324 						pdev);
325 
326 	return free_desc_count;
327 }
328 #endif /* _WLAN_LMAC_IF_API_H */
329