xref: /wlan-dirver/qca-wifi-host-cmn/umac/global_umac_dispatcher/lmac_if/inc/wlan_lmac_if_api.h (revision 3149adf58a329e17232a4c0e58d460d025edd55a)
1 /*
2  * Copyright (c) 2016-2018 The Linux Foundation. All rights reserved.
3  *
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 #ifndef _WLAN_LMAC_IF_API_H_
21 #define _WLAN_LMAC_IF_API_H_
22 
23 #include "wlan_objmgr_cmn.h"
24 #include "wlan_objmgr_psoc_obj.h"
25 #include "wlan_objmgr_pdev_obj.h"
26 
27 /**
28  * wlan_lmac_if_umac_rx_ops_register() - UMAC rx handler register
29  * @rx_ops: Pointer to rx_ops structure to be populated
30  *
31  * Register umac RX callabacks which will be called by DA/OL/WMA/WMI
32  *
33  * Return: QDF_STATUS_SUCCESS - in case of success
34  */
35 QDF_STATUS wlan_lmac_if_umac_rx_ops_register
36 		(struct wlan_lmac_if_rx_ops *rx_ops);
37 
38 /**
39  * wlan_lmac_if_set_umac_txops_registration_cb() - tx registration
40  * callback assignment
41  * @dev_type: Dev type can be either Direct attach or Offload
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 /**
54  * wlan_lmac_if_get_mgmt_txrx_rx_ops() - retrieve the mgmt rx_ops
55  * @psoc: psoc context
56  *
57  * API to retrieve the mgmt rx_ops from the psoc context
58  *
59  * Return: mgmt_rx_ops pointer
60  */
61 static inline struct wlan_lmac_if_mgmt_txrx_rx_ops *
62 wlan_lmac_if_get_mgmt_txrx_rx_ops(struct wlan_objmgr_psoc *psoc)
63 {
64 	if (!psoc)
65 		return NULL;
66 
67 	return &psoc->soc_cb.rx_ops.mgmt_txrx_rx_ops;
68 }
69 
70 /**
71  * wlan_lmac_if_get_dfs_rx_ops() - retrieve the dfs rx_ops
72  * @psoc: psoc context
73  *
74  * API to retrieve the dfs rx_ops from the psoc context
75  *
76  * Return: dfs_rx_ops pointer
77  */
78 static inline struct wlan_lmac_if_dfs_rx_ops *
79 wlan_lmac_if_get_dfs_rx_ops(struct wlan_objmgr_psoc *psoc)
80 {
81 	if (!psoc)
82 		return NULL;
83 
84     return &psoc->soc_cb.rx_ops.dfs_rx_ops;
85 }
86 
87 /**
88  * wlan_lmac_if_get_reg_rx_ops() - retrieve the reg rx_ops
89  * @psoc: psoc context
90  *
91  * API to retrieve the reg rx_ops from the psoc context
92  *
93  * Return: reg_rx_ops pointer
94  */
95 static inline struct wlan_lmac_if_reg_rx_ops *
96 wlan_lmac_if_get_reg_rx_ops(struct wlan_objmgr_psoc *psoc)
97 {
98 	if (!psoc)
99 		return NULL;
100 
101 	return &psoc->soc_cb.rx_ops.reg_rx_ops;
102 }
103 
104 #ifdef WLAN_SUPPORT_GREEN_AP
105 /**
106  * wlan_lmac_if_get_green_ap_rx_ops() - retrieve the green ap rx_ops
107  * @psoc: psoc context
108  *
109  * API to retrieve the dfs rx_ops from the psoc context
110  *
111  * Return: green_ap_rx_ops pointer
112  */
113 static inline struct wlan_lmac_if_green_ap_rx_ops *
114 wlan_lmac_if_get_green_ap_rx_ops(struct wlan_objmgr_psoc *psoc)
115 {
116 	if (!psoc)
117 		return NULL;
118 
119 	return &psoc->soc_cb.rx_ops.green_ap_rx_ops;
120 }
121 #endif
122 
123 /**
124  * mgmt_txrx_get_nbuf() - retrieve nbuf from mgmt desc_id
125  * @pdev: pdev context
126  * @desc_id: mgmt desc_id
127  *
128  * API to retrieve the nbuf from mgmt desc_id
129  *
130  * Return: nbuf
131  */
132 static inline qdf_nbuf_t
133 mgmt_txrx_get_nbuf(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
134 {
135 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
136 	struct wlan_objmgr_psoc *psoc;
137 
138 	psoc = wlan_pdev_get_psoc(pdev);
139 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
140 
141 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_nbuf_from_desc_id)
142 		return mgmt_rx_ops->mgmt_txrx_get_nbuf_from_desc_id(pdev,
143 								     desc_id);
144 
145 	return NULL;
146 }
147 
148 /**
149  * mgmt_txrx_tx_completion_handler() - mgmt tx completion handler
150  * @pdev: pdev context
151  * @desc_id: mgmt desc_id
152  * @status: tx status
153  * @params: tx params
154  *
155  * API to handle the tx completion for mgmt frames
156  *
157  * Return: QDF_STATUS_SUCCESS - in case of success
158  */
159 static inline QDF_STATUS
160 mgmt_txrx_tx_completion_handler(struct wlan_objmgr_pdev *pdev,
161 				uint32_t desc_id, uint32_t status,
162 				void *params)
163 {
164 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
165 	struct wlan_objmgr_psoc *psoc;
166 	qdf_nbuf_t nbuf;
167 
168 	psoc = wlan_pdev_get_psoc(pdev);
169 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
170 
171 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_tx_completion_handler)
172 		return mgmt_rx_ops->mgmt_tx_completion_handler(pdev, desc_id,
173 							status, params);
174 
175 	nbuf = mgmt_txrx_get_nbuf(pdev, desc_id);
176 	if (nbuf)
177 		qdf_nbuf_free(nbuf);
178 
179 	return QDF_STATUS_E_NULL_VALUE;
180 }
181 
182 /**
183  * mgmt_txrx_rx_handler() - mgmt rx frame handler
184  * @psoc: psoc context
185  * @nbuf: nbuf
186  * @params: rx params
187  *
188  * API to receive mgmt frames
189  *
190  * Return: QDF_STATUS_SUCCESS - in case of success
191  */
192 static inline QDF_STATUS
193 mgmt_txrx_rx_handler(struct wlan_objmgr_psoc *psoc, qdf_nbuf_t nbuf,
194 			void *params)
195 {
196 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
197 
198 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
199 
200 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_rx_frame_handler)
201 		return mgmt_rx_ops->mgmt_rx_frame_handler(psoc, nbuf, params);
202 
203 	if (nbuf)
204 		qdf_nbuf_free(nbuf);
205 
206 	return QDF_STATUS_E_NULL_VALUE;
207 }
208 
209 /**
210  * mgmt_txrx_get_peer() - retrieve peer from mgmt desc_id
211  * @pdev: pdev context
212  * @desc_id: mgmt desc_id
213  *
214  * API to retrieve the peer from mgmt desc_id
215  *
216  * Return: objmgr peer pointer
217  */
218 static inline struct wlan_objmgr_peer *
219 mgmt_txrx_get_peer(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
220 {
221 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
222 	struct wlan_objmgr_psoc *psoc;
223 
224 	psoc = wlan_pdev_get_psoc(pdev);
225 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
226 
227 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_peer_from_desc_id)
228 		return mgmt_rx_ops->mgmt_txrx_get_peer_from_desc_id(pdev,
229 								     desc_id);
230 
231 	return NULL;
232 }
233 
234 /**
235  * mgmt_txrx_get_vdev_id() - retrieve vdev_id from mgmt desc_id
236  * @pdev: pdev context
237  * @desc_id: mgmt desc_id
238  *
239  * API to retrieve the vdev_id from mgmt desc_id
240  *
241  * Return: vdev_id
242  */
243 static inline uint8_t
244 mgmt_txrx_get_vdev_id(struct wlan_objmgr_pdev *pdev, uint32_t desc_id)
245 {
246 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
247 	struct wlan_objmgr_psoc *psoc;
248 
249 	psoc = wlan_pdev_get_psoc(pdev);
250 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
251 
252 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_vdev_id_from_desc_id)
253 		return mgmt_rx_ops->mgmt_txrx_get_vdev_id_from_desc_id(pdev,
254 								   desc_id);
255 
256 	return WLAN_UMAC_VDEV_ID_MAX;
257 }
258 /**
259  * mgmt_txrx_get_free_desc_count() - retrieve vdev_id from mgmt desc_id
260  * @pdev: pdev context
261  *
262  * API to get the free desc count mgmt desc pool
263  *
264  * Return: free_desc_count
265  */
266 static inline uint32_t
267 mgmt_txrx_get_free_desc_count(struct wlan_objmgr_pdev *pdev)
268 {
269 	struct wlan_lmac_if_mgmt_txrx_rx_ops *mgmt_rx_ops;
270 	struct wlan_objmgr_psoc *psoc;
271 	uint32_t free_desc_count = WLAN_INVALID_MGMT_DESC_COUNT;
272 
273 	psoc = wlan_pdev_get_psoc(pdev);
274 	mgmt_rx_ops = wlan_lmac_if_get_mgmt_txrx_rx_ops(psoc);
275 
276 	if (mgmt_rx_ops && mgmt_rx_ops->mgmt_txrx_get_free_desc_pool_count)
277 		free_desc_count = mgmt_rx_ops->mgmt_txrx_get_free_desc_pool_count(
278 						pdev);
279 
280 	return free_desc_count;
281 }
282 #endif /* _WLAN_LMAC_IF_API_H */
283