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