1 /*
2 * Copyright (c) 2016-2018, 2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 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 * @handler: handler to be called for LMAC tx ops registration
43 *
44 * API to assign appropriate tx registration callback handler based on the
45 * device type(Offload or Direct attach)
46 *
47 * Return: QDF_STATUS_SUCCESS - in case of success
48 */
49 QDF_STATUS wlan_lmac_if_set_umac_txops_registration_cb
50 (QDF_STATUS (*handler)(struct wlan_lmac_if_tx_ops *));
51
52 /**
53 * wlan_lmac_if_set_umac_crypto_rxpn_ops_registration_cb() - crypto rxpn
54 * registration callback assignment
55 * @handler: handler to be called for LMAC crypto rxpn ops registration
56 *
57 * API to assign appropriate crypto rxpn registration callback handler
58 * based on the device type
59 *
60 * Return: QDF_STATUS_SUCCESS - in case of success
61 */
62 QDF_STATUS wlan_lmac_if_set_umac_crypto_rxpn_ops_registration_cb
63 (QDF_STATUS (*handler)(struct wlan_lmac_if_rx_ops *));
64
65 /**
66 * wlan_lmac_if_get_mgmt_txrx_rx_ops() - retrieve the mgmt rx_ops
67 * @psoc: psoc context
68 *
69 * API to retrieve the mgmt rx_ops from the psoc context
70 *
71 * Return: mgmt_rx_ops pointer
72 */
73 static inline struct wlan_lmac_if_mgmt_txrx_rx_ops *
wlan_lmac_if_get_mgmt_txrx_rx_ops(struct wlan_objmgr_psoc * psoc)74 wlan_lmac_if_get_mgmt_txrx_rx_ops(struct wlan_objmgr_psoc *psoc)
75 {
76 struct wlan_lmac_if_rx_ops *rx_ops;
77
78 if (!psoc)
79 return NULL;
80
81 rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
82 if (!rx_ops) {
83 qdf_err("rx_ops is NULL");
84 return NULL;
85 }
86
87 return &rx_ops->mgmt_txrx_rx_ops;
88 }
89
90 /**
91 * wlan_lmac_if_get_dfs_rx_ops() - retrieve the dfs rx_ops
92 * @psoc: psoc context
93 *
94 * API to retrieve the dfs rx_ops from the psoc context
95 *
96 * Return: dfs_rx_ops pointer
97 */
98 static inline struct wlan_lmac_if_dfs_rx_ops *
wlan_lmac_if_get_dfs_rx_ops(struct wlan_objmgr_psoc * psoc)99 wlan_lmac_if_get_dfs_rx_ops(struct wlan_objmgr_psoc *psoc)
100 {
101 struct wlan_lmac_if_rx_ops *rx_ops;
102
103 if (!psoc)
104 return NULL;
105
106 rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
107 if (!rx_ops) {
108 qdf_err("rx_ops is NULL");
109 return NULL;
110 }
111
112 return &rx_ops->dfs_rx_ops;
113 }
114
115 /**
116 * wlan_lmac_if_get_reg_rx_ops() - retrieve the reg rx_ops
117 * @psoc: psoc context
118 *
119 * API to retrieve the reg rx_ops from the psoc context
120 *
121 * Return: reg_rx_ops pointer
122 */
123 static inline struct wlan_lmac_if_reg_rx_ops *
wlan_lmac_if_get_reg_rx_ops(struct wlan_objmgr_psoc * psoc)124 wlan_lmac_if_get_reg_rx_ops(struct wlan_objmgr_psoc *psoc)
125 {
126 struct wlan_lmac_if_rx_ops *rx_ops;
127
128 if (!psoc)
129 return NULL;
130
131 rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
132 if (!rx_ops) {
133 qdf_err("rx_ops is NULL");
134 return NULL;
135 }
136
137 return &rx_ops->reg_rx_ops;
138 }
139
140 #ifdef WLAN_SUPPORT_GREEN_AP
141 /**
142 * wlan_lmac_if_get_green_ap_rx_ops() - retrieve the green ap rx_ops
143 * @psoc: psoc context
144 *
145 * API to retrieve the dfs rx_ops from the psoc context
146 *
147 * Return: green_ap_rx_ops pointer
148 */
149 static inline struct wlan_lmac_if_green_ap_rx_ops *
wlan_lmac_if_get_green_ap_rx_ops(struct wlan_objmgr_psoc * psoc)150 wlan_lmac_if_get_green_ap_rx_ops(struct wlan_objmgr_psoc *psoc)
151 {
152 struct wlan_lmac_if_rx_ops *rx_ops;
153
154 if (!psoc)
155 return NULL;
156
157 rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
158 if (!rx_ops) {
159 qdf_err("rx_ops is NULL");
160 return NULL;
161 }
162
163 return &rx_ops->green_ap_rx_ops;
164 }
165 #endif
166
167 /**
168 * mgmt_txrx_get_nbuf() - retrieve nbuf from mgmt desc_id
169 * @pdev: pdev context
170 * @desc_id: mgmt desc_id
171 *
172 * API to retrieve the nbuf from mgmt desc_id
173 *
174 * Return: nbuf
175 */
176 static inline qdf_nbuf_t
mgmt_txrx_get_nbuf(struct wlan_objmgr_pdev * pdev,uint32_t desc_id)177 mgmt_txrx_get_nbuf(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
178 {
179 struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
180 struct wlan_objmgr_psoc *psoc;
181
182 psoc = wlan_pdev_get_psoc(pdev);
183 mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
184
185 if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_nbuf_from_desc_id)
186 return mgmt_rx_ops->mgmt_txrx_get_nbuf_from_desc_id(pdev,
187 desc_id);
188
189 return NULL;
190 }
191
192 /**
193 * mgmt_txrx_tx_completion_handler() - mgmt tx completion handler
194 * @pdev: pdev context
195 * @desc_id: mgmt desc_id
196 * @status: tx status
197 * @params: tx params
198 *
199 * API to handle the tx completion for mgmt frames
200 *
201 * Return: QDF_STATUS_SUCCESS - in case of success
202 */
203 static inline QDF_STATUS
mgmt_txrx_tx_completion_handler(struct wlan_objmgr_pdev * pdev,uint32_t desc_id,uint32_t status,void * params)204 mgmt_txrx_tx_completion_handler(struct wlan_objmgr_pdev *pdev,
205 uint32_t desc_id, uint32_t status,
206 void *params)
207 {
208 struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
209 struct wlan_objmgr_psoc *psoc;
210 qdf_nbuf_t nbuf;
211
212 psoc = wlan_pdev_get_psoc(pdev);
213 mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
214
215 if (mgmt_rx_ops && mgmt_rx_ops->mgmt_tx_completion_handler)
216 return mgmt_rx_ops->mgmt_tx_completion_handler(pdev, desc_id,
217 status, params);
218
219 nbuf = mgmt_txrx_get_nbuf(pdev, desc_id);
220 if (nbuf)
221 qdf_nbuf_free(nbuf);
222
223 return QDF_STATUS_E_NULL_VALUE;
224 }
225
226 /**
227 * mgmt_txrx_rx_handler() - mgmt rx frame handler
228 * @psoc: psoc context
229 * @nbuf: nbuf
230 * @params: rx params
231 *
232 * API to receive mgmt frames
233 *
234 * Return: QDF_STATUS_SUCCESS - in case of success
235 */
236 static inline QDF_STATUS
mgmt_txrx_rx_handler(struct wlan_objmgr_psoc * psoc,qdf_nbuf_t nbuf,void * params)237 mgmt_txrx_rx_handler(struct wlan_objmgr_psoc *psoc, qdf_nbuf_t nbuf,
238 void *params)
239 {
240 struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
241
242 mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
243
244 if (mgmt_rx_ops && mgmt_rx_ops->mgmt_rx_frame_handler)
245 return mgmt_rx_ops->mgmt_rx_frame_handler(psoc, nbuf, params);
246
247 if (nbuf)
248 qdf_nbuf_free(nbuf);
249
250 return QDF_STATUS_E_NULL_VALUE;
251 }
252
253 /**
254 * mgmt_txrx_get_peer() - retrieve peer from mgmt desc_id
255 * @pdev: pdev context
256 * @desc_id: mgmt desc_id
257 *
258 * API to retrieve the peer from mgmt desc_id
259 *
260 * Return: objmgr peer pointer
261 */
262 static inline struct wlan_objmgr_peer *
mgmt_txrx_get_peer(struct wlan_objmgr_pdev * pdev,uint32_t desc_id)263 mgmt_txrx_get_peer(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
264 {
265 struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
266 struct wlan_objmgr_psoc *psoc;
267
268 psoc = wlan_pdev_get_psoc(pdev);
269 mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
270
271 if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_peer_from_desc_id)
272 return mgmt_rx_ops->mgmt_txrx_get_peer_from_desc_id(pdev,
273 desc_id);
274
275 return NULL;
276 }
277
278 /**
279 * mgmt_txrx_get_vdev_id() - retrieve vdev_id from mgmt desc_id
280 * @pdev: pdev context
281 * @desc_id: mgmt desc_id
282 *
283 * API to retrieve the vdev_id from mgmt desc_id
284 *
285 * Return: vdev_id
286 */
287 static inline uint8_t
mgmt_txrx_get_vdev_id(struct wlan_objmgr_pdev * pdev,uint32_t desc_id)288 mgmt_txrx_get_vdev_id(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
289 {
290 struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
291 struct wlan_objmgr_psoc *psoc;
292
293 psoc = wlan_pdev_get_psoc(pdev);
294 mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
295
296 if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_vdev_id_from_desc_id)
297 return mgmt_rx_ops->mgmt_txrx_get_vdev_id_from_desc_id(pdev,
298 desc_id);
299
300 return WLAN_UMAC_VDEV_ID_MAX;
301 }
302 /**
303 * mgmt_txrx_get_free_desc_count() - retrieve vdev_id from mgmt desc_id
304 * @pdev: pdev context
305 *
306 * API to get the free desc count mgmt desc pool
307 *
308 * Return: free_desc_count
309 */
310 static inline uint32_t
mgmt_txrx_get_free_desc_count(struct wlan_objmgr_pdev * pdev)311 mgmt_txrx_get_free_desc_count(struct wlan_objmgr_pdev *pdev)
312 {
313 struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
314 struct wlan_objmgr_psoc *psoc;
315 uint32_t free_desc_count = WLAN_INVALID_MGMT_DESC_COUNT;
316
317 psoc = wlan_pdev_get_psoc(pdev);
318 mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
319
320 if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_free_desc_pool_count)
321 free_desc_count = mgmt_rx_ops->mgmt_txrx_get_free_desc_pool_count(
322 pdev);
323
324 return free_desc_count;
325 }
326 #endif /* _WLAN_LMAC_IF_API_H */
327