xref: /wlan-dirver/qca-wifi-host-cmn/target_if/init_deinit/src/init_event_handler.c (revision a175314c51a4ce5cec2835cc8a8c7dc0c1810915)
1 /*
2  * Copyright (c) 2018 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_event_handler.c
21  *
22  * WMI common event handler implementation source file
23  */
24 
25 #include <qdf_status.h>
26 #include <wlan_objmgr_psoc_obj.h>
27 #include <wlan_objmgr_pdev_obj.h>
28 #include <target_if.h>
29 #include <target_if_reg.h>
30 #include <init_event_handler.h>
31 #include <service_ready_util.h>
32 #include <service_ready_param.h>
33 #include <init_cmd_api.h>
34 #include <cdp_txrx_cmn.h>
35 
36 static int init_deinit_service_ready_event_handler(ol_scn_t scn_handle,
37 							uint8_t *event,
38 							uint32_t data_len)
39 {
40 	int err_code;
41 	struct wlan_objmgr_psoc *psoc;
42 	struct target_psoc_info *tgt_hdl;
43 	wmi_legacy_service_ready_callback legacy_callback;
44 	struct common_wmi_handle *wmi_handle;
45 	QDF_STATUS ret_val;
46 
47 	if (!scn_handle) {
48 		target_if_err("scn handle NULL in service ready handler");
49 		return -EINVAL;
50 	}
51 
52 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
53 	if (!psoc) {
54 		target_if_err("psoc is null in service ready handler");
55 		return -EINVAL;
56 	}
57 
58 	tgt_hdl = (struct target_psoc_info *)wlan_psoc_get_tgt_if_handle(
59 						psoc);
60 	if (!tgt_hdl) {
61 		target_if_err("target_psoc_info is null in service ready ev");
62 		return -EINVAL;
63 	}
64 
65 	ret_val = target_if_sw_version_check(psoc, tgt_hdl, event);
66 
67 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
68 
69 	err_code = init_deinit_populate_service_bitmap(wmi_handle, event,
70 			tgt_hdl->info.service_bitmap);
71 	if (err_code)
72 		goto exit;
73 
74 	err_code = init_deinit_populate_fw_version_cmd(wmi_handle, event);
75 	if (err_code)
76 		goto exit;
77 
78 	err_code = init_deinit_populate_target_cap(wmi_handle, event,
79 				   &(tgt_hdl->info.target_caps));
80 	if (err_code)
81 		goto exit;
82 
83 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle, event,
84 				    &(tgt_hdl->info), true);
85 	if (err_code)
86 		goto exit;
87 
88 	if (init_deinit_validate_160_80p80_fw_caps(psoc, tgt_hdl) !=
89 			QDF_STATUS_SUCCESS) {
90 		wlan_psoc_nif_op_flag_set(psoc, WLAN_SOC_OP_VHT_INVALID_CAP);
91 	}
92 
93 	target_if_ext_res_cfg_enable(psoc, tgt_hdl, event);
94 
95 	if (wmi_service_enabled(wmi_handle, wmi_service_tt))
96 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TT_SUPPORT);
97 
98 	if (wmi_service_enabled(wmi_handle, wmi_service_widebw_scan))
99 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN);
100 
101 	if (wmi_service_enabled(wmi_handle, wmi_service_check_cal_version))
102 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_SW_CAL);
103 
104 	target_if_info(" TT support %d, Wide BW Scan %d, SW cal %d",
105 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_TT_SUPPORT),
106 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN),
107 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_SW_CAL));
108 
109 	target_if_mesh_support_enable(psoc, tgt_hdl, event);
110 
111 	target_if_smart_antenna_enable(psoc, tgt_hdl, event);
112 
113 	target_if_peer_cfg_enable(psoc, tgt_hdl, event);
114 
115 	target_if_atf_cfg_enable(psoc, tgt_hdl, event);
116 
117 	target_if_qwrap_cfg_enable(psoc, tgt_hdl, event);
118 
119 	target_if_lteu_cfg_enable(psoc, tgt_hdl, event);
120 
121 	/* override derived value, if it exceeds max peer count */
122 	if ((wlan_psoc_get_max_peer_count(psoc) >
123 		tgt_hdl->info.wlan_res_cfg.num_active_peers) &&
124 		(wlan_psoc_get_max_peer_count(psoc) <
125 			(tgt_hdl->info.wlan_res_cfg.num_peers -
126 				tgt_hdl->info.wlan_res_cfg.num_vdevs))) {
127 		tgt_hdl->info.wlan_res_cfg.num_peers =
128 				wlan_psoc_get_max_peer_count(psoc) +
129 					tgt_hdl->info.wlan_res_cfg.num_vdevs;
130 	}
131 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
132 	if (!legacy_callback) {
133 		err_code = -EINVAL;
134 		goto exit;
135 	}
136 
137 	err_code = legacy_callback(wmi_service_ready_event_id,
138 				  scn_handle, event, data_len);
139 	init_deinit_chainmask_config(psoc, tgt_hdl);
140 
141 	if (wmi_service_enabled(wmi_handle, wmi_service_mgmt_tx_wmi)) {
142 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WMI_MGMT_REF);
143 		target_if_info("WMI mgmt service enabled");
144 	} else {
145 		wlan_psoc_nif_fw_ext_cap_clear(psoc,
146 					       WLAN_SOC_CEXT_WMI_MGMT_REF);
147 		target_if_info("WMI mgmt service disabled");
148 	}
149 
150 	err_code = init_deinit_handle_host_mem_req(psoc, tgt_hdl, event);
151 	if (err_code != QDF_STATUS_SUCCESS)
152 		goto exit;
153 
154 	target_if_reg_set_offloaded_info(psoc);
155 	if (!wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
156 		target_if_info("No EXT message, send init command");
157 		tgt_hdl->info.wmi_service_ready = TRUE;
158 		target_psoc_set_num_radios(tgt_hdl, 1);
159 		/* send init command */
160 		init_deinit_prepare_send_init_cmd(psoc, tgt_hdl);
161 	} else {
162 		target_if_info("Wait for EXT message");
163 	}
164 
165 	target_if_smart_log_enable(psoc, tgt_hdl, event);
166 exit:
167 	return err_code;
168 }
169 
170 static int init_deinit_service_ext_ready_event_handler(ol_scn_t scn_handle,
171 						uint8_t *event,
172 						uint32_t data_len)
173 {
174 	int err_code;
175 	struct wlan_objmgr_psoc *psoc;
176 	struct target_psoc_info *tgt_hdl;
177 	struct common_wmi_handle *wmi_handle;
178 	struct tgt_info *info;
179 	wmi_legacy_service_ready_callback legacy_callback;
180 
181 	if (!scn_handle) {
182 		target_if_err("scn handle NULL in service ready handler");
183 		return -EINVAL;
184 	}
185 
186 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
187 	if (!psoc) {
188 		target_if_err("psoc is null in service ready handler");
189 		return -EINVAL;
190 	}
191 
192 	tgt_hdl = (struct target_psoc_info *)wlan_psoc_get_tgt_if_handle(
193 						psoc);
194 	if (!tgt_hdl) {
195 		target_if_err("target_psoc_info is null in service ready ev");
196 		return -EINVAL;
197 	}
198 
199 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
200 	info = (&tgt_hdl->info);
201 
202 	err_code = init_deinit_populate_service_ready_ext_param(wmi_handle,
203 				event, &(info->service_ext_param));
204 	if (err_code)
205 		goto exit;
206 
207 	target_psoc_set_num_radios(tgt_hdl, 0);
208 	err_code =  init_deinit_populate_hw_mode_capability(wmi_handle,
209 					    event, tgt_hdl);
210 	if (err_code)
211 		goto exit;
212 
213 	if (init_deinit_is_preferred_hw_mode_supported(psoc, tgt_hdl)
214 			== FALSE)
215 		return -EINVAL;
216 
217 	target_if_print_service_ready_ext_param(psoc, tgt_hdl);
218 
219 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle,
220 					   event, info, false);
221 	if (err_code)
222 		goto exit;
223 
224 	target_if_add_11ax_modes(psoc, tgt_hdl);
225 
226 	if (init_deinit_chainmask_table_alloc(
227 				&(info->service_ext_param)) ==
228 							QDF_STATUS_SUCCESS) {
229 		err_code = init_deinit_populate_chainmask_tables(wmi_handle,
230 				event,
231 				&(info->service_ext_param.chainmask_table[0]));
232 		if (err_code)
233 			goto exit;
234 	}
235 
236 	err_code = init_deinit_populate_dbr_ring_cap(psoc, wmi_handle,
237 						event, info);
238 	if (err_code)
239 		goto exit;
240 
241 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
242 	if (legacy_callback)
243 		legacy_callback(wmi_service_ready_ext_event_id,
244 				scn_handle, event, data_len);
245 
246 	info->wlan_res_cfg.num_vdevs = (target_psoc_get_num_radios(tgt_hdl) *
247 					info->wlan_res_cfg.num_vdevs);
248 	info->wlan_res_cfg.beacon_tx_offload_max_vdev =
249 				(target_psoc_get_num_radios(tgt_hdl) *
250 				info->wlan_res_cfg.beacon_tx_offload_max_vdev);
251 
252 	info->wmi_service_ready = TRUE;
253 
254 	init_deinit_prepare_send_init_cmd(psoc, tgt_hdl);
255 
256 exit:
257 	return err_code;
258 }
259 
260 static int init_deinit_service_available_handler(ol_scn_t scn_handle,
261 						uint8_t *event,
262 						uint32_t data_len)
263 {
264 	struct wlan_objmgr_psoc *psoc;
265 	struct target_psoc_info *tgt_hdl;
266 	struct common_wmi_handle *wmi_handle;
267 
268 	if (!scn_handle) {
269 		target_if_err("scn handle NULL");
270 		return -EINVAL;
271 	}
272 
273 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
274 	if (!psoc) {
275 		target_if_err("psoc is null");
276 		return -EINVAL;
277 	}
278 
279 	tgt_hdl = (struct target_psoc_info *)wlan_psoc_get_tgt_if_handle(
280 						psoc);
281 	if (!tgt_hdl) {
282 		target_if_err("target_psoc_info is null");
283 		return -EINVAL;
284 	}
285 
286 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
287 
288 	if (wmi_save_ext_service_bitmap(wmi_handle, event, NULL) !=
289 					QDF_STATUS_SUCCESS) {
290 		target_if_err("Failed to save ext service bitmap");
291 		return -EINVAL;
292 	}
293 
294 	return 0;
295 }
296 
297 /* MAC address fourth byte index */
298 #define MAC_BYTE_4 4
299 
300 static int init_deinit_ready_event_handler(ol_scn_t scn_handle,
301 						uint8_t *event,
302 						uint32_t data_len)
303 {
304 	struct wlan_objmgr_psoc *psoc;
305 	struct wlan_objmgr_pdev *pdev;
306 	struct target_psoc_info *tgt_hdl;
307 	struct common_wmi_handle *wmi_handle;
308 	struct wmi_host_fw_abi_ver fw_ver;
309 	uint8_t myaddr[QDF_MAC_ADDR_SIZE];
310 	struct tgt_info *info;
311 	struct wmi_host_ready_ev_param ready_ev;
312 	wmi_legacy_service_ready_callback legacy_callback;
313 	uint8_t num_radios, i;
314 	uint32_t max_peers;
315 
316 	if (!scn_handle) {
317 		target_if_err("scn handle NULL");
318 		return -EINVAL;
319 	}
320 
321 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
322 	if (!psoc) {
323 		target_if_err("psoc is null");
324 		return -EINVAL;
325 	}
326 
327 	tgt_hdl = (struct target_psoc_info *)wlan_psoc_get_tgt_if_handle(
328 						psoc);
329 	if (!tgt_hdl) {
330 		target_if_err("target_psoc_info is null");
331 		return -EINVAL;
332 	}
333 
334 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
335 	info = (&tgt_hdl->info);
336 
337 	if (wmi_extract_fw_abi_version(wmi_handle, event, &fw_ver) ==
338 				QDF_STATUS_SUCCESS) {
339 		info->version.wlan_ver = fw_ver.sw_version;
340 		info->version.wlan_ver = fw_ver.abi_version;
341 	}
342 
343 	if (wmi_check_and_update_fw_version(wmi_handle, event) < 0) {
344 		target_if_err("Version mismatch with FW");
345 		return -EINVAL;
346 	}
347 
348 	if (wmi_extract_ready_event_params(wmi_handle, event, &ready_ev) !=
349 				QDF_STATUS_SUCCESS) {
350 		target_if_err("Failed to extract ready event");
351 		return -EINVAL;
352 	}
353 
354 	if ((ready_ev.num_total_peer != 0) &&
355 	    (info->wlan_res_cfg.num_peers != ready_ev.num_total_peer)) {
356 		/* FW allocated number of peers is different than host
357 		 * requested. Update host max with FW reported value.
358 		 */
359 		target_if_err("Host Requested %d peers. FW Supports %d peers",
360 			       info->wlan_res_cfg.num_peers,
361 			       ready_ev.num_total_peer);
362 		info->wlan_res_cfg.num_peers = ready_ev.num_total_peer;
363 	}
364 
365 	/* for non legacy  num_total_peer will be non zero
366 	 * allocate peer memory in this case
367 	 */
368 	if (ready_ev.num_total_peer != 0) {
369 		max_peers = info->wlan_res_cfg.num_peers +
370 			ready_ev.num_extra_peer + 1;
371 
372 		cdp_peer_map_attach(wlan_psoc_get_dp_handle(psoc), max_peers);
373 	}
374 
375 	/* Indicate to the waiting thread that the ready
376 	 * event was received
377 	 */
378 	info->wlan_init_status = wmi_ready_extract_init_status(
379 						wmi_handle, event);
380 
381 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
382 	if (legacy_callback)
383 		legacy_callback(wmi_ready_event_id,
384 				scn_handle, event, data_len);
385 
386 	num_radios = target_psoc_get_num_radios(tgt_hdl);
387 	/*
388 	 * For non-legacy HW, MAC addr list is extracted.
389 	 */
390 	if (num_radios > 1) {
391 		uint8_t num_mac_addr;
392 		wmi_host_mac_addr *addr_list;
393 		int i;
394 
395 		addr_list = wmi_ready_extract_mac_addr_list(wmi_handle, event,
396 							    &num_mac_addr);
397 		if ((num_mac_addr >= num_radios) && (addr_list)) {
398 			for (i = 0; i < num_radios; i++) {
399 				WMI_HOST_MAC_ADDR_TO_CHAR_ARRAY(&addr_list[i],
400 								myaddr);
401 				pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
402 								  WLAN_INIT_DEINIT_ID);
403 				if (!pdev) {
404 					target_if_err(" PDEV %d is NULL", i);
405 					return -EINVAL;
406 				}
407 				wlan_pdev_set_hw_macaddr(pdev, myaddr);
408 				wlan_objmgr_pdev_release_ref(pdev,
409 							WLAN_INIT_DEINIT_ID);
410 
411 				/* assign 1st radio addr to psoc */
412 				if (i == 0)
413 					wlan_psoc_set_hw_macaddr(psoc, myaddr);
414 			}
415 			goto out;
416 		} else {
417 			target_if_err("Using default MAC addr for all radios..");
418 		}
419 	}
420 
421 	/*
422 	 * We extract single MAC address in two scenarios:
423 	 * 1. In non-legacy case, if addr list is NULL or num_mac_addr < num_radios
424 	 * 2. In all legacy cases
425 	 */
426 	for (i = 0; i < num_radios; i++) {
427 		wmi_ready_extract_mac_addr(wmi_handle, event, myaddr);
428 		myaddr[MAC_BYTE_4] += i;
429 		pdev = wlan_objmgr_get_pdev_by_id(psoc, i, WLAN_INIT_DEINIT_ID);
430 		if (!pdev) {
431 			target_if_err(" PDEV %d is NULL", i);
432 			return -EINVAL;
433 		}
434 		wlan_pdev_set_hw_macaddr(pdev, myaddr);
435 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
436 		/* assign 1st radio addr to psoc */
437 		if (i == 0)
438 			wlan_psoc_set_hw_macaddr(psoc, myaddr);
439 	}
440 
441 out:
442 	target_if_btcoex_cfg_enable(psoc, tgt_hdl, event);
443 	tgt_hdl->info.wmi_ready = TRUE;
444 	init_deinit_wakeup_host_wait(psoc, tgt_hdl);
445 
446 	return 0;
447 }
448 
449 
450 QDF_STATUS init_deinit_register_tgt_psoc_ev_handlers(
451 				struct wlan_objmgr_psoc *psoc)
452 {
453 	struct target_psoc_info *tgt_hdl;
454 	wmi_unified_t wmi_handle;
455 	QDF_STATUS retval = QDF_STATUS_SUCCESS;
456 
457 	if (!psoc) {
458 		target_if_err("psoc is null in register wmi handler");
459 		return QDF_STATUS_E_FAILURE;
460 	}
461 
462 	tgt_hdl = (struct target_psoc_info *)wlan_psoc_get_tgt_if_handle(
463 						psoc);
464 	if (!tgt_hdl) {
465 		target_if_err("target_psoc_info null in register wmi hadler");
466 		return QDF_STATUS_E_FAILURE;
467 	}
468 
469 	wmi_handle = (wmi_unified_t)target_psoc_get_wmi_hdl(tgt_hdl);
470 
471 	retval = wmi_unified_register_event_handler(wmi_handle,
472 				wmi_service_ready_event_id,
473 				init_deinit_service_ready_event_handler,
474 				WMI_RX_WORK_CTX);
475 	retval = wmi_unified_register_event_handler(wmi_handle,
476 				wmi_service_ready_ext_event_id,
477 				init_deinit_service_ext_ready_event_handler,
478 				WMI_RX_WORK_CTX);
479 	retval = wmi_unified_register_event_handler(wmi_handle,
480 				wmi_service_available_event_id,
481 				init_deinit_service_available_handler,
482 				WMI_RX_UMAC_CTX);
483 	retval = wmi_unified_register_event_handler(wmi_handle,
484 				wmi_ready_event_id,
485 				init_deinit_ready_event_handler,
486 				WMI_RX_WORK_CTX);
487 
488 	return retval;
489 }
490 
491