1 /*
2 * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
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 #include "wmi_unified_api.h"
21 #include "wmi.h"
22 #include "wmi_version.h"
23 #include "wmi_unified_priv.h"
24 #include <wlan_defs.h>
25 #include "target_if.h"
26 #include "wma.h"
27 #include "wlan_ocb_ucfg_api.h"
28 #include "wlan_ocb_main.h"
29
30 void wmi_ocb_ut_attach(struct wmi_unified *wmi_handle);
31
32 static inline struct wlan_ocb_rx_ops *
target_if_ocb_get_rx_ops(struct wlan_objmgr_psoc * psoc)33 target_if_ocb_get_rx_ops(struct wlan_objmgr_psoc *psoc)
34 {
35 struct wlan_objmgr_pdev *pdev;
36 struct ocb_pdev_obj *pdev_obj;
37
38 pdev = wlan_objmgr_get_pdev_by_id(psoc, 0,
39 WLAN_OCB_SB_ID);
40 pdev_obj = (struct ocb_pdev_obj *)
41 wlan_objmgr_pdev_get_comp_private_obj(pdev,
42 WLAN_UMAC_COMP_OCB);
43 return &pdev_obj->ocb_rxops;
44 }
45
46 /**
47 * fake_vdev_create_cmd_tlv() - send VDEV create command to fw
48 * @wmi_handle: wmi handle
49 * @param: pointer to hold vdev create parameter
50 * @macaddr: vdev mac address
51 *
52 * Return: QDF_STATUS_SUCCESS for success or error code
53 */
fake_vdev_create_cmd_tlv(wmi_unified_t wmi_handle,uint8_t macaddr[QDF_MAC_ADDR_SIZE],struct vdev_create_params * param)54 static QDF_STATUS fake_vdev_create_cmd_tlv(wmi_unified_t wmi_handle,
55 uint8_t macaddr[QDF_MAC_ADDR_SIZE],
56 struct vdev_create_params *param)
57 {
58 wmi_debug("called");
59 return QDF_STATUS_SUCCESS;
60 }
61
62 /**
63 * fake_vdev_delete_cmd_tlv() - send VDEV delete command to fw
64 * @wmi_handle: wmi handle
65 * @if_id: vdev id
66 *
67 * Return: QDF_STATUS_SUCCESS for success or error code
68 */
fake_vdev_delete_cmd_tlv(wmi_unified_t wmi_handle,uint8_t if_id)69 static QDF_STATUS fake_vdev_delete_cmd_tlv(wmi_unified_t wmi_handle,
70 uint8_t if_id)
71 {
72 wmi_debug("called");
73 return QDF_STATUS_SUCCESS;
74 }
75
76 /**
77 * fake_ocb_set_utc_time_cmd_tlv() - send the UTC time to the firmware
78 * @wmi_handle: pointer to the wmi handle
79 * @utc: pointer to the UTC time struct
80 *
81 * Return: 0 on success
82 */
fake_ocb_set_utc_time_cmd_tlv(wmi_unified_t wmi_handle,struct ocb_utc_param * utc)83 static QDF_STATUS fake_ocb_set_utc_time_cmd_tlv(wmi_unified_t wmi_handle,
84 struct ocb_utc_param *utc)
85 {
86 wmi_debug("called");
87 return QDF_STATUS_SUCCESS;
88 }
89
90 /**
91 * fake_ocb_get_tsf_timer_cmd_tlv() - get ocb tsf timer val
92 * @wmi_handle: pointer to the wmi handle
93 * @vdev_id: vdev of interest
94 *
95 * Return: 0 on success
96 */
fake_ocb_get_tsf_timer_cmd_tlv(wmi_unified_t wmi_handle,uint8_t vdev_id)97 static QDF_STATUS fake_ocb_get_tsf_timer_cmd_tlv(wmi_unified_t wmi_handle,
98 uint8_t vdev_id)
99 {
100 QDF_STATUS status;
101 struct wlan_objmgr_psoc *psoc;
102 struct wlan_ocb_rx_ops *ocb_rx_ops;
103 struct ocb_get_tsf_timer_response response;
104 ol_scn_t scn = (ol_scn_t) wmi_handle->scn_handle;
105
106 wmi_debug("called");
107 psoc = target_if_get_psoc_from_scn_hdl(scn);
108 if (!psoc) {
109 wmi_err("null psoc");
110 return -EINVAL;
111 }
112 response.vdev_id = vdev_id;
113 response.timer_high = 0x1234;
114 response.timer_low = 0x5678;
115
116 ocb_rx_ops = target_if_ocb_get_rx_ops(psoc);
117 if (ocb_rx_ops->ocb_tsf_timer) {
118 status = ocb_rx_ops->ocb_tsf_timer(psoc, &response);
119 if (status != QDF_STATUS_SUCCESS) {
120 wmi_err("ocb_tsf_timer failed");
121 return -EINVAL;
122 }
123 } else {
124 wmi_err("No ocb_tsf_timer callback");
125 return -EINVAL;
126 }
127 return QDF_STATUS_SUCCESS;
128 }
129
130 /**
131 * fake_dcc_clear_stats_cmd_tlv() - command to clear the DCC stats
132 * @wmi_handle: pointer to the wmi handle
133 * @vdev_id: vdev id
134 * @dcc_stats_bitmap: dcc status bitmap
135 *
136 * Return: 0 on success
137 */
fake_dcc_clear_stats_cmd_tlv(wmi_unified_t wmi_handle,uint32_t vdev_id,uint32_t dcc_stats_bitmap)138 static QDF_STATUS fake_dcc_clear_stats_cmd_tlv(wmi_unified_t wmi_handle,
139 uint32_t vdev_id, uint32_t dcc_stats_bitmap)
140 {
141 wmi_debug("called");
142 return QDF_STATUS_SUCCESS;
143 }
144
145 wmi_dcc_ndl_stats_per_channel chan1_info[2] = {
146 [0] = {.chan_info = 5860,
147 .tx_power_datarate = 23 | (10 << 8),
148 .carrier_sense_est_comm_range = 107 | (198 << 13),
149 .dcc_stats = 78 | (56 << 8) | (345 << 16),
150 .packet_stats = 1278 | (789 << 14),
151 .channel_busy_time = 1389,
152 },
153 [1] = {.chan_info = 5880,
154 .tx_power_datarate = 53 | (17 << 8),
155 .carrier_sense_est_comm_range = 137 | (198 << 13),
156 .dcc_stats = 78 | (66 << 8) | (245 << 16),
157 .packet_stats = 1278 | (889 << 14),
158 .channel_busy_time = 2389,
159 },
160 };
161
162 /**
163 * fake_dcc_get_stats_cmd_tlv() - get the DCC channel stats
164 * @wmi_handle: pointer to the wmi handle
165 * @get_stats_param: pointer to the dcc stats
166 *
167 * Return: 0 on success
168 */
fake_dcc_get_stats_cmd_tlv(wmi_unified_t wmi_handle,struct ocb_dcc_get_stats_param * get_stats_param)169 static QDF_STATUS fake_dcc_get_stats_cmd_tlv(wmi_unified_t wmi_handle,
170 struct ocb_dcc_get_stats_param *get_stats_param)
171 {
172 QDF_STATUS status;
173 struct wlan_objmgr_psoc *psoc;
174 struct wlan_ocb_rx_ops *ocb_rx_ops;
175 ol_scn_t scn = (ol_scn_t) wmi_handle->scn_handle;
176 struct ocb_dcc_get_stats_response *response;
177
178 wmi_debug("called");
179 psoc = target_if_get_psoc_from_scn_hdl(scn);
180 if (!psoc) {
181 wmi_err("null psoc");
182 return -EINVAL;
183 }
184 response = qdf_mem_malloc(sizeof(*response) + 2 *
185 sizeof(wmi_dcc_ndl_stats_per_channel));
186 response->num_channels = 2;
187 response->channel_stats_array_len = 2 *
188 sizeof(wmi_dcc_ndl_stats_per_channel);
189 response->vdev_id = get_stats_param->vdev_id;
190 response->channel_stats_array = (uint8_t *)response + sizeof(*response);
191 qdf_mem_copy(response->channel_stats_array,
192 &chan1_info,
193 2 * sizeof(wmi_dcc_ndl_stats_per_channel));
194 wmi_debug("channel1 freq %d, channel2 freq %d", chan1_info[0].chan_info,
195 chan1_info[1].chan_info);
196 ocb_rx_ops = target_if_ocb_get_rx_ops(psoc);
197 if (ocb_rx_ops->ocb_dcc_stats_indicate) {
198 status = ocb_rx_ops->ocb_dcc_stats_indicate(psoc,
199 response, true);
200 if (status != QDF_STATUS_SUCCESS) {
201 wmi_err("dcc_stats_indicate failed");
202 status = -EINVAL;
203 } else {
204 status = 0;
205 }
206 } else {
207 wmi_err("No dcc_stats_indicate callback");
208 status = -EINVAL;
209 }
210
211 qdf_mem_free(response);
212 return QDF_STATUS_SUCCESS;
213 }
214
215 /**
216 * fake_dcc_update_ndl_cmd_tlv() - command to update the NDL data
217 * @wmi_handle: pointer to the wmi handle
218 * @update_ndl_param: pointer to the request parameters
219 *
220 * Return: 0 on success
221 */
fake_dcc_update_ndl_cmd_tlv(wmi_unified_t wmi_handle,struct ocb_dcc_update_ndl_param * update_ndl_param)222 static QDF_STATUS fake_dcc_update_ndl_cmd_tlv(wmi_unified_t wmi_handle,
223 struct ocb_dcc_update_ndl_param *update_ndl_param)
224 {
225 QDF_STATUS status;
226 struct wlan_objmgr_psoc *psoc;
227 struct wlan_ocb_rx_ops *ocb_rx_ops;
228 ol_scn_t scn = (ol_scn_t) wmi_handle->scn_handle;
229 struct ocb_dcc_update_ndl_response *resp;
230
231 wmi_debug("called");
232 /* Allocate and populate the response */
233 resp = qdf_mem_malloc(sizeof(*resp));
234 if (!resp)
235 return -ENOMEM;
236
237 resp->vdev_id = update_ndl_param->vdev_id;
238 resp->status = 0;
239
240 psoc = target_if_get_psoc_from_scn_hdl(scn);
241 if (!psoc) {
242 wmi_err("null psoc");
243 return -EINVAL;
244 }
245
246 ocb_rx_ops = target_if_ocb_get_rx_ops(psoc);
247 if (ocb_rx_ops->ocb_dcc_ndl_update) {
248 status = ocb_rx_ops->ocb_dcc_ndl_update(psoc, resp);
249 if (status != QDF_STATUS_SUCCESS) {
250 wmi_err("dcc_ndl_update failed");
251 status = -EINVAL;
252 } else {
253 status = 0;
254 }
255 } else {
256 wmi_err("No dcc_ndl_update callback");
257 status = -EINVAL;
258 }
259
260 qdf_mem_free(resp);
261 return QDF_STATUS_SUCCESS;
262 }
263
264 /**
265 * fake_ocb_set_config_cmd_tlv() - send the OCB config to the FW
266 * @wmi_handle: pointer to the wmi handle
267 * @config: the OCB configuration
268 *
269 * Return: 0 on success
270 */
fake_ocb_set_config_cmd_tlv(wmi_unified_t wmi_handle,struct ocb_config * config)271 static QDF_STATUS fake_ocb_set_config_cmd_tlv(wmi_unified_t wmi_handle,
272 struct ocb_config *config)
273 {
274 u32 i;
275 QDF_STATUS status;
276 struct wlan_objmgr_psoc *psoc;
277 struct wlan_ocb_rx_ops *ocb_rx_ops;
278 ol_scn_t scn = (ol_scn_t) wmi_handle->scn_handle;
279
280 wmi_debug("vdev_id=%d, channel_count=%d, schedule_size=%d, flag=%x",
281 config->vdev_id, config->channel_count,
282 config->schedule_size, config->flags);
283
284 for (i = 0; i < config->channel_count; i++) {
285 wmi_debug("channel info for channel %d"
286 " chan_freq=%d, bandwidth=%d, " QDF_MAC_ADDR_FMT
287 " max_pwr=%d, min_pwr=%d, reg_pwr=%d, antenna_max=%d, "
288 "flags=%d", i, config->channels[i].chan_freq,
289 config->channels[i].bandwidth,
290 QDF_MAC_ADDR_REF(
291 config->channels[i].mac_address.bytes),
292 config->channels[i].max_pwr,
293 config->channels[i].min_pwr,
294 config->channels[i].reg_pwr,
295 config->channels[i].antenna_max,
296 config->channels[i].flags);
297 }
298
299 for (i = 0; i < config->schedule_size; i++) {
300 wmi_debug("schedule info for channel %d: "
301 "chan_fre=%d, total_duration=%d, guard_intreval=%d",
302 i, config->schedule[i].chan_freq,
303 config->schedule[i].total_duration,
304 config->schedule[i].guard_interval);
305 }
306 psoc = target_if_get_psoc_from_scn_hdl(scn);
307 if (!psoc) {
308 wmi_err("null psoc");
309 return -EINVAL;
310 }
311
312 ocb_rx_ops = target_if_ocb_get_rx_ops(psoc);
313 if (ocb_rx_ops->ocb_set_config_status) {
314 status = ocb_rx_ops->ocb_set_config_status(psoc, 0);
315 if (status != QDF_STATUS_SUCCESS) {
316 wmi_err("ocb_set_config_status failed");
317 return -EINVAL;
318 }
319 } else {
320 wmi_err("No ocb_set_config_status callback");
321 return -EINVAL;
322 }
323 return QDF_STATUS_SUCCESS;
324 }
325
326 /**
327 * fake_ocb_stop_timing_advert_cmd_tlv() - stop sending the
328 * timing advertisement frames on a channel
329 * @wmi_handle: pointer to the wmi handle
330 * @timing_advert: pointer to the timing advertisement struct
331 *
332 * Return: 0 on success
333 */
fake_ocb_stop_timing_advert_cmd_tlv(wmi_unified_t wmi_handle,struct ocb_timing_advert_param * timing_advert)334 static QDF_STATUS fake_ocb_stop_timing_advert_cmd_tlv(wmi_unified_t wmi_handle,
335 struct ocb_timing_advert_param *timing_advert)
336 {
337 wmi_debug("called");
338 return QDF_STATUS_SUCCESS;
339 }
340
341 /**
342 * fake_ocb_start_timing_advert_cmd_tlv() - start sending the
343 * timing advertisement frames on a channel
344 * @wmi_handle: pointer to the wmi handle
345 * @timing_advert: pointer to the timing advertisement struct
346 *
347 * Return: 0 on success
348 */
349 static QDF_STATUS
fake_ocb_start_timing_advert_cmd_tlv(wmi_unified_t wmi_handle,struct ocb_timing_advert_param * timing_advert)350 fake_ocb_start_timing_advert_cmd_tlv(wmi_unified_t wmi_handle,
351 struct ocb_timing_advert_param *timing_advert)
352 {
353 wmi_debug("called");
354 return QDF_STATUS_SUCCESS;
355 }
356
357 /**
358 * fake_peer_create_cmd_tlv() - send peer create command to fw
359 * @wmi: wmi handle
360 * @param: peer create parameters
361 *
362 * Return: QDF_STATUS_SUCCESS for success or error code
363 */
fake_peer_create_cmd_tlv(wmi_unified_t wmi,struct peer_create_params * param)364 static QDF_STATUS fake_peer_create_cmd_tlv(wmi_unified_t wmi,
365 struct peer_create_params *param)
366 {
367 wmi_debug("called");
368 return QDF_STATUS_SUCCESS;
369 }
370
371 /**
372 * fake_peer_delete_cmd_tlv() - send PEER delete command to fw
373 * @wmi: wmi handle
374 * @peer_addr: peer mac addr
375 * @param: peer delete parameters
376 *
377 * Return: QDF_STATUS_SUCCESS for success or error code
378 */
fake_peer_delete_cmd_tlv(wmi_unified_t wmi,uint8_t peer_addr[QDF_MAC_ADDR_SIZE],struct peer_delete_cmd_params * param)379 static QDF_STATUS fake_peer_delete_cmd_tlv(wmi_unified_t wmi,
380 uint8_t peer_addr[QDF_MAC_ADDR_SIZE],
381 struct peer_delete_cmd_params *param)
382 {
383 wmi_debug("called");
384 return QDF_STATUS_SUCCESS;
385 }
386
387 /**
388 * fake_vdev_start_cmd_tlv() - send vdev start request to fw
389 * @wmi_handle: wmi handle
390 * @req: vdev start params
391 *
392 * Return: QDF status
393 */
fake_vdev_start_cmd_tlv(wmi_unified_t wmi_handle,struct vdev_start_params * req)394 static QDF_STATUS fake_vdev_start_cmd_tlv(wmi_unified_t wmi_handle,
395 struct vdev_start_params *req)
396 {
397 tp_wma_handle wma = (tp_wma_handle) wmi_handle->scn_handle;
398
399 wmi_debug("vdev_id %d freq %d chanmode %d ch_info is_dfs %d "
400 "beacon interval %d dtim %d center_chan %d center_freq2 %d "
401 "max_txpow: 0x%x "
402 "Tx SS %d, Rx SS %d, ldpc_rx: %d, cac %d, regd %d, HE ops: %d",
403 (int)req->vdev_id, req->channel.mhz,
404 req->channel.phy_mode,
405 (int)req->channel.dfs_set, req->beacon_intval, req->dtim_period,
406 req->channel.cfreq1, req->channel.cfreq2,
407 req->channel.maxregpower,
408 req->preferred_tx_streams, req->preferred_rx_streams,
409 (int)req->ldpc_rx_enabled, req->cac_duration_ms,
410 req->regdomain, req->he_ops);
411 ucfg_ocb_config_channel(wma->pdev);
412 return QDF_STATUS_SUCCESS;
413 }
414
415 /**
416 * fake_vdev_down_cmd_tlv() - send vdev down command to fw
417 * @wmi: wmi handle
418 * @vdev_id: vdev id
419 *
420 * Return: QDF_STATUS_SUCCESS for success or error code
421 */
fake_vdev_down_cmd_tlv(wmi_unified_t wmi,uint8_t vdev_id)422 static QDF_STATUS fake_vdev_down_cmd_tlv(wmi_unified_t wmi, uint8_t vdev_id)
423 {
424 wmi_debug("called");
425 return QDF_STATUS_SUCCESS;
426 }
427
428 /**
429 * fake_vdev_set_param_cmd_tlv() - WMI vdev set parameter function
430 * @wmi_handle: handle to WMI.
431 * @param: pointer to hold vdev set parameter
432 *
433 * Return: 0 on success and -ve on failure.
434 */
fake_vdev_set_param_cmd_tlv(wmi_unified_t wmi_handle,struct vdev_set_params * param)435 static QDF_STATUS fake_vdev_set_param_cmd_tlv(wmi_unified_t wmi_handle,
436 struct vdev_set_params *param)
437 {
438 wmi_debug("called");
439 return QDF_STATUS_SUCCESS;
440 }
441
442 /**
443 * fake_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv() -
444 * faked API to enable/disable mcc scheduler
445 * @wmi_handle: wmi handle
446 * @mcc_adaptive_scheduler: enable/disable
447 * @pdev_id: pdev ID
448 *
449 * This function enable/disable mcc adaptive scheduler in fw.
450 *
451 * Return: QDF_STATUS_SUCCESS for success or error code
452 */
fake_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv(wmi_unified_t wmi_handle,uint32_t mcc_adaptive_scheduler,uint32_t pdev_id)453 static QDF_STATUS fake_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv(
454 wmi_unified_t wmi_handle, uint32_t mcc_adaptive_scheduler,
455 uint32_t pdev_id)
456 {
457 wmi_debug("called");
458 return QDF_STATUS_SUCCESS;
459 }
460
461 /**
462 * fake_process_set_ie_info_cmd_tlv() - Function to send IE info to firmware
463 * @wmi_handle: Pointer to WMi handle
464 * @ie_info: Pointer for ie info
465 *
466 * This function sends IE information to firmware
467 *
468 * Return: QDF_STATUS_SUCCESS for success otherwise failure
469 *
470 */
fake_process_set_ie_info_cmd_tlv(wmi_unified_t wmi_handle,struct vdev_ie_info_param * ie_info)471 static QDF_STATUS fake_process_set_ie_info_cmd_tlv(wmi_unified_t wmi_handle,
472 struct vdev_ie_info_param *ie_info)
473 {
474 wmi_debug("called");
475 return QDF_STATUS_SUCCESS;
476 }
477
wmi_ocb_ut_attach(struct wmi_unified * wmi_handle)478 void wmi_ocb_ut_attach(struct wmi_unified *wmi_handle)
479 {
480 struct wmi_ops *wmi_ops;
481
482 if (!wmi_handle) {
483 wmi_err("null wmi handle");
484 return;
485 }
486
487 wmi_ops = wmi_handle->ops;
488 wmi_ops->send_vdev_create_cmd = fake_vdev_create_cmd_tlv;
489 wmi_ops->send_vdev_delete_cmd = fake_vdev_delete_cmd_tlv;
490 wmi_ops->send_vdev_down_cmd = fake_vdev_down_cmd_tlv;
491 wmi_ops->send_vdev_start_cmd = fake_vdev_start_cmd_tlv;
492 wmi_ops->send_peer_create_cmd = fake_peer_create_cmd_tlv;
493 wmi_ops->send_peer_delete_cmd = fake_peer_delete_cmd_tlv;
494 wmi_ops->send_vdev_set_param_cmd = fake_vdev_set_param_cmd_tlv;
495 wmi_ops->send_ocb_set_utc_time_cmd = fake_ocb_set_utc_time_cmd_tlv;
496 wmi_ops->send_ocb_get_tsf_timer_cmd = fake_ocb_get_tsf_timer_cmd_tlv;
497 wmi_ops->send_dcc_clear_stats_cmd = fake_dcc_clear_stats_cmd_tlv;
498 wmi_ops->send_dcc_get_stats_cmd = fake_dcc_get_stats_cmd_tlv;
499 wmi_ops->send_dcc_update_ndl_cmd = fake_dcc_update_ndl_cmd_tlv;
500 wmi_ops->send_ocb_set_config_cmd = fake_ocb_set_config_cmd_tlv;
501 wmi_ops->send_ocb_stop_timing_advert_cmd =
502 fake_ocb_stop_timing_advert_cmd_tlv;
503 wmi_ops->send_ocb_start_timing_advert_cmd =
504 fake_ocb_start_timing_advert_cmd_tlv;
505 wmi_ops->send_set_enable_disable_mcc_adaptive_scheduler_cmd =
506 fake_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv;
507 wmi_ops->send_process_set_ie_info_cmd =
508 fake_process_set_ie_info_cmd_tlv;
509 }
510