xref: /wlan-driver/qca-wifi-host-cmn/umac/dfs/dispatcher/src/wlan_dfs_lmac_api.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2016-2020 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 /**
21  * DOC: Functions to call lmac/offload functions from DFS component.
22  */
23 
24 #include "wlan_dfs_lmac_api.h"
25 #include "../../core/src/dfs_internal.h"
26 #include <wlan_reg_services_api.h>
27 #include <wlan_lmac_if_def.h>
28 
lmac_get_caps(struct wlan_objmgr_pdev * pdev,struct wlan_dfs_caps * dfs_caps)29 void lmac_get_caps(struct wlan_objmgr_pdev *pdev,
30 		struct wlan_dfs_caps *dfs_caps)
31 {
32 	struct wlan_objmgr_psoc *psoc;
33 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
34 	struct wlan_lmac_if_tx_ops *tx_ops;
35 
36 	psoc = wlan_pdev_get_psoc(pdev);
37 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
38 	if (!tx_ops) {
39 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
40 		return;
41 	}
42 
43 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
44 
45 	if (dfs_tx_ops->dfs_get_caps)
46 		dfs_tx_ops->dfs_get_caps(pdev, dfs_caps);
47 }
48 
lmac_get_tsf64(struct wlan_objmgr_pdev * pdev)49 uint64_t lmac_get_tsf64(struct wlan_objmgr_pdev *pdev)
50 {
51 	struct wlan_objmgr_psoc *psoc;
52 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
53 	uint64_t tsf64 = 0;
54 	struct wlan_lmac_if_tx_ops *tx_ops;
55 
56 	psoc = wlan_pdev_get_psoc(pdev);
57 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
58 	if (!tx_ops) {
59 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
60 		return tsf64;
61 	}
62 
63 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
64 
65 	if (dfs_tx_ops->dfs_gettsf64)
66 		dfs_tx_ops->dfs_gettsf64(pdev, &tsf64);
67 
68 	return tsf64;
69 }
70 
lmac_dfs_disable(struct wlan_objmgr_pdev * pdev,int no_cac)71 void lmac_dfs_disable(struct wlan_objmgr_pdev *pdev, int no_cac)
72 {
73 	struct wlan_objmgr_psoc *psoc;
74 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
75 	struct wlan_lmac_if_tx_ops *tx_ops;
76 
77 	psoc = wlan_pdev_get_psoc(pdev);
78 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
79 	if (!tx_ops) {
80 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
81 		return;
82 	}
83 
84 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
85 
86 	if (dfs_tx_ops->dfs_disable)
87 		dfs_tx_ops->dfs_disable(pdev, no_cac);
88 }
89 
lmac_dfs_enable(struct wlan_objmgr_pdev * pdev,int * is_fastclk,struct wlan_dfs_phyerr_param * param,int dfsdomain)90 void lmac_dfs_enable(struct wlan_objmgr_pdev *pdev,
91 		int *is_fastclk,
92 		struct wlan_dfs_phyerr_param *param,
93 		int dfsdomain)
94 {
95 	struct wlan_objmgr_psoc *psoc;
96 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
97 	struct wlan_lmac_if_tx_ops *tx_ops;
98 
99 	psoc = wlan_pdev_get_psoc(pdev);
100 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
101 	if (!tx_ops) {
102 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
103 		return;
104 	}
105 
106 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
107 
108 	if (dfs_tx_ops->dfs_enable)
109 		dfs_tx_ops->dfs_enable(pdev,
110 				is_fastclk,
111 				param,
112 				dfsdomain);
113 }
114 
lmac_dfs_get_thresholds(struct wlan_objmgr_pdev * pdev,struct wlan_dfs_phyerr_param * param)115 void lmac_dfs_get_thresholds(struct wlan_objmgr_pdev *pdev,
116 		struct wlan_dfs_phyerr_param *param)
117 {
118 	struct wlan_objmgr_psoc *psoc;
119 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
120 	struct wlan_lmac_if_tx_ops *tx_ops;
121 
122 	psoc = wlan_pdev_get_psoc(pdev);
123 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
124 	if (!tx_ops) {
125 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
126 		return;
127 	}
128 
129 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
130 
131 	if (dfs_tx_ops->dfs_get_thresholds)
132 		dfs_tx_ops->dfs_get_thresholds(pdev, param);
133 }
134 
lmac_get_ah_devid(struct wlan_objmgr_pdev * pdev)135 uint16_t lmac_get_ah_devid(struct wlan_objmgr_pdev *pdev)
136 {
137 	struct wlan_objmgr_psoc *psoc;
138 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
139 	uint16_t devid = 0;
140 	struct wlan_lmac_if_tx_ops *tx_ops;
141 
142 	psoc = wlan_pdev_get_psoc(pdev);
143 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
144 	if (!tx_ops) {
145 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
146 		return devid;
147 	}
148 
149 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
150 
151 	if (dfs_tx_ops->dfs_get_ah_devid)
152 		dfs_tx_ops->dfs_get_ah_devid(pdev, &devid);
153 
154 	return devid;
155 }
156 
lmac_get_ext_busy(struct wlan_objmgr_pdev * pdev)157 uint32_t lmac_get_ext_busy(struct wlan_objmgr_pdev *pdev)
158 {
159 	struct wlan_objmgr_psoc *psoc;
160 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
161 	uint32_t ext_chan_busy = 0;
162 	struct wlan_lmac_if_tx_ops *tx_ops;
163 
164 	psoc = wlan_pdev_get_psoc(pdev);
165 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
166 	if (!tx_ops) {
167 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
168 		return ext_chan_busy;
169 	}
170 
171 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
172 
173 	if (dfs_tx_ops->dfs_get_ext_busy)
174 		dfs_tx_ops->dfs_get_ext_busy(pdev, &ext_chan_busy);
175 
176 	return ext_chan_busy;
177 }
178 
lmac_set_use_cac_prssi(struct wlan_objmgr_pdev * pdev)179 void lmac_set_use_cac_prssi(struct wlan_objmgr_pdev *pdev)
180 {
181 	struct wlan_objmgr_psoc *psoc;
182 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
183 	struct wlan_lmac_if_tx_ops *tx_ops;
184 
185 	psoc = wlan_pdev_get_psoc(pdev);
186 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
187 	if (!tx_ops) {
188 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
189 		return;
190 	}
191 
192 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
193 
194 	if (dfs_tx_ops->dfs_set_use_cac_prssi)
195 		dfs_tx_ops->dfs_set_use_cac_prssi(pdev);
196 }
197 
lmac_get_target_type(struct wlan_objmgr_pdev * pdev)198 uint32_t lmac_get_target_type(struct wlan_objmgr_pdev *pdev)
199 {
200 	struct wlan_objmgr_psoc *psoc;
201 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
202 	uint32_t target_type = 0;
203 	struct wlan_lmac_if_tx_ops *tx_ops;
204 
205 	psoc = wlan_pdev_get_psoc(pdev);
206 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
207 	if (!tx_ops) {
208 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
209 		return target_type;
210 	}
211 
212 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
213 
214 	if (dfs_tx_ops->dfs_get_target_type)
215 		dfs_tx_ops->dfs_get_target_type(pdev, &target_type);
216 
217 	return target_type;
218 }
219 
lmac_get_phymode_info(struct wlan_objmgr_pdev * pdev,uint32_t chan_mode)220 uint32_t lmac_get_phymode_info(struct wlan_objmgr_pdev *pdev,
221 		uint32_t chan_mode)
222 {
223 	struct wlan_objmgr_psoc *psoc;
224 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
225 	uint32_t mode_info = 0;
226 	struct wlan_lmac_if_tx_ops *tx_ops;
227 
228 	psoc = wlan_pdev_get_psoc(pdev);
229 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
230 	if (!tx_ops) {
231 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
232 		return mode_info;
233 	}
234 
235 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
236 
237 	/* since dfs never comes into 2G, hardcode is_2gvht_en flag to false */
238 	if (dfs_tx_ops->dfs_get_phymode_info)
239 		dfs_tx_ops->dfs_get_phymode_info(pdev, chan_mode, &mode_info,
240 						 false);
241 
242 	return mode_info;
243 }
244 
245 #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
lmac_is_host_dfs_check_support_enabled(struct wlan_objmgr_pdev * pdev)246 bool lmac_is_host_dfs_check_support_enabled(struct wlan_objmgr_pdev *pdev)
247 {
248 	struct wlan_objmgr_psoc *psoc;
249 	struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
250 	bool enabled = false;
251 	struct wlan_lmac_if_tx_ops *tx_ops;
252 
253 	psoc = wlan_pdev_get_psoc(pdev);
254 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
255 	if (!tx_ops) {
256 		dfs_err(NULL, WLAN_DEBUG_DFS_ALWAYS,  "tx_ops is null");
257 		return enabled;
258 	}
259 
260 	dfs_tx_ops = &tx_ops->dfs_tx_ops;
261 
262 	if (dfs_tx_ops->dfs_host_dfs_check_support)
263 		dfs_tx_ops->dfs_host_dfs_check_support(pdev, &enabled);
264 
265 	return enabled;
266 }
267 #endif
268