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