xref: /wlan-dirver/qca-wifi-host-cmn/target_if/init_deinit/src/init_deinit_lmac.c (revision bea437e2293c3d4fb1b5704fcf633aedac996962)
1 /*
2  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: init_deinit_lmac.c
21  *
22  * APIs to get/set target_if params
23  */
24 #include <qdf_status.h>
25 #include <wlan_objmgr_psoc_obj.h>
26 #include <wlan_objmgr_pdev_obj.h>
27 #include <target_if.h>
28 #include <target_type.h>
29 #include <init_deinit_lmac.h>
30 #include <qdf_module.h>
31 
32 struct wlan_psoc_target_capability_info *lmac_get_target_cap(
33 				struct wlan_objmgr_psoc *psoc)
34 {
35 	struct target_psoc_info *tgt_hdl;
36 
37 	if (!psoc) {
38 		target_if_err("psoc is null");
39 		return NULL;
40 	}
41 
42 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
43 	if (!tgt_hdl) {
44 		target_if_err("target_psoc_info is null");
45 		return NULL;
46 	}
47 
48 	return target_psoc_get_target_caps(tgt_hdl);
49 }
50 
51 target_resource_config *lmac_get_tgt_res_cfg(struct wlan_objmgr_psoc *psoc)
52 {
53 	struct target_psoc_info *tgt_hdl;
54 
55 	if (!psoc) {
56 		target_if_err("psoc is null");
57 		return NULL;
58 	}
59 
60 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
61 	if (!tgt_hdl) {
62 		target_if_err("target_psoc_info is null");
63 		return NULL;
64 	}
65 
66 	return target_psoc_get_wlan_res_cfg(tgt_hdl);
67 }
68 
69 int32_t lmac_get_pdev_idx(struct wlan_objmgr_pdev *pdev)
70 {
71 	if (!pdev) {
72 		target_if_err("pdev is null");
73 		return 0xffffffff;
74 	}
75 
76 	return wlan_objmgr_pdev_get_pdev_id(pdev);
77 }
78 
79 uint32_t lmac_get_tgt_type(struct wlan_objmgr_psoc *psoc)
80 {
81 	struct target_psoc_info *tgt_hdl;
82 
83 	if (!psoc) {
84 		target_if_err("psoc is null");
85 		return 0;
86 	}
87 
88 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
89 	if (!tgt_hdl) {
90 		target_if_err("target_psoc_info is null");
91 		return 0;
92 	}
93 
94 	return target_psoc_get_target_type(tgt_hdl);
95 }
96 qdf_export_symbol(lmac_get_tgt_type);
97 
98 QDF_STATUS lmac_get_pdev_target_type(struct wlan_objmgr_pdev *pdev,
99 					uint32_t *target_type)
100 {
101 	struct wlan_objmgr_psoc *psoc;
102 
103 	psoc = wlan_pdev_get_psoc(pdev);
104 	if (!psoc) {
105 		target_if_err("psoc is NULL");
106 		return QDF_STATUS_E_FAILURE;
107 	}
108 
109 	*target_type = lmac_get_tgt_type(psoc);
110 	return QDF_STATUS_SUCCESS;
111 }
112 qdf_export_symbol(lmac_get_pdev_target_type);
113 
114 uint32_t lmac_get_tgt_version(struct wlan_objmgr_psoc *psoc)
115 {
116 	struct target_psoc_info *tgt_hdl;
117 
118 	if (!psoc) {
119 		target_if_err("psoc is null");
120 		return -EINVAL;
121 	}
122 
123 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
124 	if (!tgt_hdl) {
125 		target_if_err("target_psoc_info is null");
126 		return -EINVAL;
127 	}
128 
129 	return target_psoc_get_target_ver(tgt_hdl);
130 }
131 qdf_export_symbol(lmac_get_tgt_version);
132 
133 uint32_t lmac_get_tgt_revision(struct wlan_objmgr_psoc *psoc)
134 {
135 	struct target_psoc_info *tgt_hdl;
136 
137 	if (!psoc) {
138 		target_if_err("psoc is null");
139 		return -EINVAL;
140 	}
141 
142 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
143 	if (!tgt_hdl) {
144 		target_if_err("target_psoc_info is null");
145 		return -EINVAL;
146 	}
147 
148 	return target_psoc_get_target_rev(tgt_hdl);
149 }
150 qdf_export_symbol(lmac_get_tgt_revision);
151 
152 bool lmac_is_target_ar900b(struct wlan_objmgr_psoc *psoc)
153 {
154 	struct target_psoc_info *tgt_hdl;
155 	uint32_t target_type;
156 
157 	if (!psoc) {
158 		target_if_err("psoc is null\n");
159 		return false;
160 	}
161 
162 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
163 	if (!tgt_hdl) {
164 		target_if_err("target_psoc_info is null");
165 		return false;
166 	}
167 	target_type = tgt_hdl->info.target_type;
168 
169 	switch (target_type) {
170 	case TARGET_TYPE_AR900B:
171 	case TARGET_TYPE_QCA9984:
172 	case TARGET_TYPE_IPQ4019:
173 	case TARGET_TYPE_QCA9888:
174 		return true;
175 	default:
176 		return false;
177 	}
178 	return false;
179 }
180 qdf_export_symbol(lmac_is_target_ar900b);
181 
182 struct wmi_unified *lmac_get_wmi_hdl(struct wlan_objmgr_psoc *psoc)
183 {
184 	struct target_psoc_info *tgt_hdl;
185 
186 	if (!psoc) {
187 		target_if_err("psoc is null");
188 		return NULL;
189 	}
190 
191 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
192 	if (!tgt_hdl) {
193 		target_if_err("target_psoc_info is null");
194 		return NULL;
195 	}
196 
197 	return target_psoc_get_wmi_hdl(tgt_hdl);
198 }
199 qdf_export_symbol(lmac_get_wmi_hdl);
200 
201 wmi_unified_t lmac_get_wmi_unified_hdl(struct wlan_objmgr_psoc *psoc)
202 {
203 	return (wmi_unified_t)lmac_get_wmi_hdl(psoc);
204 }
205 qdf_export_symbol(lmac_get_wmi_unified_hdl);
206 
207 HTC_HANDLE lmac_get_htc_hdl(struct wlan_objmgr_psoc *psoc)
208 {
209 	struct target_psoc_info *tgt_hdl;
210 
211 	if (!psoc) {
212 		target_if_err("psoc is null");
213 		return NULL;
214 	}
215 
216 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
217 	if (!tgt_hdl) {
218 		target_if_err("target_psoc_info is null");
219 		return NULL;
220 	}
221 
222 	return target_psoc_get_htc_hdl(tgt_hdl);
223 }
224 qdf_export_symbol(lmac_get_htc_hdl);
225 
226 void lmac_set_htc_hdl(struct wlan_objmgr_psoc *psoc,
227 		      HTC_HANDLE htc_hdl)
228 {
229 	struct target_psoc_info *tgt_hdl;
230 
231 	if (!psoc) {
232 		target_if_err("psoc is null");
233 		return;
234 	}
235 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
236 	if (!tgt_hdl) {
237 		target_if_err("target_psoc_info is null");
238 		return;
239 	}
240 
241 	target_psoc_set_htc_hdl(tgt_hdl, htc_hdl);
242 }
243 
244 struct hif_opaque_softc *lmac_get_hif_hdl(struct wlan_objmgr_psoc *psoc)
245 {
246 	struct target_psoc_info *tgt_hdl;
247 
248 	if (!psoc) {
249 		target_if_err("psoc is null");
250 		return NULL;
251 	}
252 
253 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
254 	if (!tgt_hdl) {
255 		target_if_err("target_psoc_info is null");
256 		return NULL;
257 	}
258 
259 	return target_psoc_get_hif_hdl(tgt_hdl);
260 }
261 qdf_export_symbol(lmac_get_hif_hdl);
262 
263 struct hif_opaque_softc *lmac_get_ol_hif_hdl(struct wlan_objmgr_psoc *psoc)
264 {
265 	return (struct hif_opaque_softc *)lmac_get_hif_hdl(psoc);
266 }
267 qdf_export_symbol(lmac_get_ol_hif_hdl);
268 
269 struct wmi_unified *lmac_get_pdev_wmi_handle(
270 		struct wlan_objmgr_pdev *pdev)
271 {
272 	struct target_pdev_info *tgt_hdl;
273 
274 	if (!pdev) {
275 		target_if_err("pdev is null");
276 		return NULL;
277 	}
278 
279 	tgt_hdl = wlan_pdev_get_tgt_if_handle(pdev);
280 	if (!tgt_hdl) {
281 		target_if_err("target_pdev_info is null");
282 		return NULL;
283 	}
284 
285 	return target_pdev_get_wmi_handle(tgt_hdl);
286 }
287 qdf_export_symbol(lmac_get_pdev_wmi_handle);
288 
289 wmi_unified_t
290 lmac_get_pdev_wmi_unified_handle(struct wlan_objmgr_pdev *pdev)
291 {
292 	return (wmi_unified_t)lmac_get_pdev_wmi_handle(pdev);
293 }
294 
295 uint32_t lmac_get_num_radios(struct wlan_objmgr_psoc *psoc)
296 {
297 	struct target_psoc_info *tgt_hdl;
298 
299 	if (!psoc) {
300 		target_if_err("psoc is null");
301 		return 0;
302 	}
303 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
304 	if (!tgt_hdl) {
305 		target_if_err("target_psoc_info is null");
306 		return 0;
307 	}
308 
309 	return target_psoc_get_num_radios(tgt_hdl);
310 }
311 qdf_export_symbol(lmac_get_num_radios);
312 
313 void *lmac_get_psoc_feature_ptr(struct wlan_objmgr_psoc *psoc)
314 {
315 	struct target_psoc_info *tgt_hdl;
316 
317 	if (!psoc) {
318 		target_if_err("psoc is null");
319 		return NULL;
320 	}
321 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
322 	if (!tgt_hdl) {
323 		target_if_err("target_psoc_info is null");
324 		return NULL;
325 	}
326 
327 	return target_psoc_get_feature_ptr(tgt_hdl);
328 }
329 qdf_export_symbol(lmac_get_psoc_feature_ptr);
330 
331 void *lmac_get_pdev_feature_ptr(struct wlan_objmgr_pdev *pdev)
332 {
333 	struct target_pdev_info *tgt_hdl;
334 
335 	if (!pdev) {
336 		target_if_err("pdev is null");
337 		return NULL;
338 	}
339 	tgt_hdl = wlan_pdev_get_tgt_if_handle(pdev);
340 	if (!tgt_hdl) {
341 		target_if_err("target_pdev_info is null");
342 		return NULL;
343 	}
344 
345 	return target_pdev_get_feature_ptr(tgt_hdl);
346 }
347 qdf_export_symbol(lmac_get_pdev_feature_ptr);
348 
349 enum wmi_host_hw_mode_config_type lmac_get_preferred_hw_mode(
350 				struct wlan_objmgr_psoc *psoc)
351 {
352 	struct target_psoc_info *tgt_hdl;
353 
354 	if (!psoc) {
355 		target_if_err("psoc is null");
356 		return WMI_HOST_HW_MODE_MAX;
357 	}
358 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
359 	if (!tgt_hdl) {
360 		target_if_err("target_psoc_info is null");
361 		return WMI_HOST_HW_MODE_MAX;
362 	}
363 
364 	return target_psoc_get_preferred_hw_mode(tgt_hdl);
365 }
366 
367 qdf_export_symbol(lmac_get_preferred_hw_mode);
368