xref: /wlan-dirver/qca-wifi-host-cmn/target_if/init_deinit/src/init_event_handler.c (revision 45a38684b07295822dc8eba39e293408f203eec8)
1 /*
2  * Copyright (c) 2018-2020 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 #include <wlan_reg_ucfg_api.h>
36 
37 static void init_deinit_set_send_init_cmd(struct wlan_objmgr_psoc *psoc,
38 					  struct target_psoc_info *tgt_hdl)
39 {
40 	tgt_hdl->info.wmi_service_ready = TRUE;
41 	/* send init command */
42 	init_deinit_prepare_send_init_cmd(psoc, tgt_hdl);
43 }
44 
45 static int init_deinit_service_ready_event_handler(ol_scn_t scn_handle,
46 							uint8_t *event,
47 							uint32_t data_len)
48 {
49 	int err_code;
50 	struct wlan_objmgr_psoc *psoc;
51 	struct target_psoc_info *tgt_hdl;
52 	wmi_legacy_service_ready_callback legacy_callback;
53 	struct wmi_unified *wmi_handle;
54 	QDF_STATUS ret_val;
55 
56 	if (!scn_handle) {
57 		target_if_err("scn handle NULL in service ready handler");
58 		return -EINVAL;
59 	}
60 
61 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
62 	if (!psoc) {
63 		target_if_err("psoc is null in service ready handler");
64 		return -EINVAL;
65 	}
66 
67 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
68 	if (!tgt_hdl) {
69 		target_if_err("target_psoc_info is null in service ready ev");
70 		return -EINVAL;
71 	}
72 
73 	ret_val = target_if_sw_version_check(psoc, tgt_hdl, event);
74 
75 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
76 
77 	err_code = init_deinit_populate_service_bitmap(wmi_handle, event,
78 			tgt_hdl->info.service_bitmap);
79 	if (err_code)
80 		goto exit;
81 
82 	err_code = init_deinit_populate_fw_version_cmd(wmi_handle, event);
83 	if (err_code)
84 		goto exit;
85 
86 	err_code = init_deinit_populate_target_cap(wmi_handle, event,
87 				   &(tgt_hdl->info.target_caps));
88 	if (err_code)
89 		goto exit;
90 
91 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle, event,
92 				    &(tgt_hdl->info), true);
93 	if (err_code)
94 		goto exit;
95 
96 	if (init_deinit_validate_160_80p80_fw_caps(psoc, tgt_hdl) !=
97 			QDF_STATUS_SUCCESS) {
98 		wlan_psoc_nif_op_flag_set(psoc, WLAN_SOC_OP_VHT_INVALID_CAP);
99 	}
100 
101 	target_if_ext_res_cfg_enable(psoc, tgt_hdl, event);
102 
103 	if (wmi_service_enabled(wmi_handle, wmi_service_tt))
104 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TT_SUPPORT);
105 
106 	if (wmi_service_enabled(wmi_handle, wmi_service_widebw_scan))
107 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN);
108 
109 	if (wmi_service_enabled(wmi_handle, wmi_service_check_cal_version))
110 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_SW_CAL);
111 
112 	if (wmi_service_enabled(wmi_handle, wmi_service_twt_requestor))
113 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TWT_REQUESTER);
114 
115 	if (wmi_service_enabled(wmi_handle, wmi_service_twt_responder))
116 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TWT_RESPONDER);
117 
118 	if (wmi_service_enabled(wmi_handle, wmi_service_bss_color_offload))
119 		target_if_debug(" BSS COLOR OFFLOAD supported");
120 
121 	if (wmi_service_enabled(wmi_handle, wmi_service_ul_ru26_allowed))
122 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_OBSS_NBW_RU);
123 
124 	if (wmi_service_enabled(wmi_handle, wmi_service_infra_mbssid))
125 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_MBSS_IE);
126 
127 	if (wmi_service_enabled(wmi_handle, wmi_service_dynamic_hw_mode))
128 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_DYNAMIC_HW_MODE);
129 
130 	if (wmi_service_enabled(wmi_handle,
131 				wmi_service_bw_restricted_80p80_support))
132 		wlan_psoc_nif_fw_ext_cap_set(psoc,
133 					     WLAN_SOC_RESTRICTED_80P80_SUPPORT);
134 
135 	if (wmi_service_enabled(wmi_handle,
136 				wmi_service_nss_ratio_to_host_support))
137 		wlan_psoc_nif_fw_ext_cap_set(
138 				psoc, WLAN_SOC_NSS_RATIO_TO_HOST_SUPPORT);
139 
140 	target_if_debug(" TT support %d, Wide BW Scan %d, SW cal %d",
141 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_TT_SUPPORT),
142 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN),
143 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_SW_CAL));
144 
145 	target_if_mesh_support_enable(psoc, tgt_hdl, event);
146 
147 	target_if_eapol_minrate_enable(psoc, tgt_hdl, event);
148 
149 	target_if_smart_antenna_enable(psoc, tgt_hdl, event);
150 
151 	target_if_cfr_support_enable(psoc, tgt_hdl, event);
152 
153 	target_if_peer_cfg_enable(psoc, tgt_hdl, event);
154 
155 	target_if_atf_cfg_enable(psoc, tgt_hdl, event);
156 
157 	if (!wmi_service_enabled(wmi_handle, wmi_service_ext_msg))
158 		target_if_qwrap_cfg_enable(psoc, tgt_hdl, event);
159 
160 	target_if_lteu_cfg_enable(psoc, tgt_hdl, event);
161 
162 	if (wmi_service_enabled(wmi_handle, wmi_service_rx_fse_support))
163 		wlan_psoc_nif_fw_ext_cap_set(psoc,
164 					     WLAN_SOC_CEXT_RX_FSE_SUPPORT);
165 
166 	/* override derived value, if it exceeds max peer count */
167 	if ((wlan_psoc_get_max_peer_count(psoc) >
168 		tgt_hdl->info.wlan_res_cfg.num_active_peers) &&
169 		(wlan_psoc_get_max_peer_count(psoc) <
170 			(tgt_hdl->info.wlan_res_cfg.num_peers -
171 				tgt_hdl->info.wlan_res_cfg.num_vdevs))) {
172 		tgt_hdl->info.wlan_res_cfg.num_peers =
173 				wlan_psoc_get_max_peer_count(psoc) +
174 					tgt_hdl->info.wlan_res_cfg.num_vdevs;
175 	}
176 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
177 	if (!legacy_callback) {
178 		err_code = -EINVAL;
179 		goto exit;
180 	}
181 
182 	err_code = legacy_callback(wmi_service_ready_event_id,
183 				  scn_handle, event, data_len);
184 	init_deinit_chainmask_config(psoc, tgt_hdl);
185 
186 	if (wmi_service_enabled(wmi_handle, wmi_service_mgmt_tx_wmi)) {
187 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WMI_MGMT_REF);
188 		target_if_debug("WMI mgmt service enabled");
189 	} else {
190 		wlan_psoc_nif_fw_ext_cap_clear(psoc,
191 					       WLAN_SOC_CEXT_WMI_MGMT_REF);
192 		target_if_debug("WMI mgmt service disabled");
193 	}
194 
195 	err_code = init_deinit_handle_host_mem_req(psoc, tgt_hdl, event);
196 	if (err_code != QDF_STATUS_SUCCESS)
197 		goto exit;
198 
199 	target_if_reg_set_offloaded_info(psoc);
200 	target_if_reg_set_6ghz_info(psoc);
201 	target_if_reg_set_5dot9_ghz_info(psoc);
202 
203 	/* Send num_msdu_desc to DP layer */
204 	cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
205 			  DP_SOC_PARAM_MSDU_EXCEPTION_DESC,
206 			  tgt_hdl->info.target_caps.num_msdu_desc);
207 
208 	if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
209 		target_if_debug("Wait for EXT message");
210 	} else {
211 		target_if_debug("No EXT message, send init command");
212 		target_psoc_set_num_radios(tgt_hdl, 1);
213 		init_deinit_set_send_init_cmd(psoc, tgt_hdl);
214 	}
215 
216 exit:
217 	return err_code;
218 }
219 
220 static int init_deinit_service_ext2_ready_event_handler(ol_scn_t scn_handle,
221 							uint8_t *event,
222 							uint32_t data_len)
223 {
224 	int err_code = 0;
225 	struct wlan_objmgr_psoc *psoc;
226 	struct target_psoc_info *tgt_hdl;
227 	struct wmi_unified *wmi_handle;
228 	struct tgt_info *info;
229 
230 	if (!scn_handle) {
231 		target_if_err("scn handle NULL in service ready ext2 handler");
232 		return -EINVAL;
233 	}
234 
235 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
236 	if (!psoc) {
237 		target_if_err("psoc is null in service ready ext2 handler");
238 		return -EINVAL;
239 	}
240 
241 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
242 	if (!tgt_hdl) {
243 		target_if_err("target_psoc_info is null in service ready ext2 handler");
244 		return -EINVAL;
245 	}
246 
247 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
248 	if (!wmi_handle) {
249 		target_if_err("wmi_handle is null in service ready ext2 handler");
250 		return -EINVAL;
251 	}
252 
253 	info = (&tgt_hdl->info);
254 
255 	err_code = init_deinit_populate_service_ready_ext2_param(wmi_handle,
256 								 event, info);
257 	if (err_code)
258 		goto exit;
259 
260 	/* dbr_ring_caps could have already come as part of EXT event */
261 	if (info->service_ext2_param.num_dbr_ring_caps) {
262 		err_code = init_deinit_populate_dbr_ring_cap_ext2(psoc,
263 								  wmi_handle,
264 								  event, info);
265 		if (err_code)
266 			goto exit;
267 	}
268 
269 	err_code = init_deinit_populate_hal_reg_cap_ext2(wmi_handle, event,
270 							 info);
271 	if (err_code) {
272 		target_if_err("failed to populate hal reg cap ext2");
273 		goto exit;
274 	}
275 
276 	err_code = init_deinit_populate_mac_phy_cap_ext2(wmi_handle, event,
277 							 info);
278 	if (err_code) {
279 		target_if_err("failed to populate mac phy cap ext2");
280 		goto exit;
281 	}
282 
283 	target_if_add_11ax_modes(psoc, tgt_hdl);
284 
285 	err_code = init_deinit_populate_scan_radio_cap_ext2(wmi_handle, event,
286 							    info);
287 	if (err_code) {
288 		target_if_err("failed to populate scan radio cap ext2");
289 		goto exit;
290 	}
291 
292 	/* send init command */
293 	init_deinit_set_send_init_cmd(psoc, tgt_hdl);
294 
295 exit:
296 	return err_code;
297 }
298 
299 static int init_deinit_service_ext_ready_event_handler(ol_scn_t scn_handle,
300 						uint8_t *event,
301 						uint32_t data_len)
302 {
303 	int err_code;
304 	uint8_t num_radios;
305 	struct wlan_objmgr_psoc *psoc;
306 	struct target_psoc_info *tgt_hdl;
307 	struct wmi_unified *wmi_handle;
308 	struct tgt_info *info;
309 	wmi_legacy_service_ready_callback legacy_callback;
310 
311 	if (!scn_handle) {
312 		target_if_err("scn handle NULL in service ready handler");
313 		return -EINVAL;
314 	}
315 
316 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
317 	if (!psoc) {
318 		target_if_err("psoc is null in service ready handler");
319 		return -EINVAL;
320 	}
321 
322 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
323 	if (!tgt_hdl) {
324 		target_if_err("target_psoc_info is null in service ready ev");
325 		return -EINVAL;
326 	}
327 
328 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
329 	info = (&tgt_hdl->info);
330 
331 	err_code = init_deinit_populate_service_ready_ext_param(wmi_handle,
332 				event, &(info->service_ext_param));
333 	if (err_code)
334 		goto exit;
335 
336 	target_psoc_set_num_radios(tgt_hdl, 0);
337 	err_code =  init_deinit_populate_hw_mode_capability(wmi_handle,
338 					    event, tgt_hdl);
339 	if (err_code)
340 		goto exit;
341 
342 	if (init_deinit_is_preferred_hw_mode_supported(psoc, tgt_hdl)
343 			== FALSE) {
344 		target_if_err("Preferred mode %d not supported",
345 			      info->preferred_hw_mode);
346 		return -EINVAL;
347 	}
348 
349 	num_radios = target_psoc_get_num_radios_for_mode(tgt_hdl,
350 							 info->preferred_hw_mode);
351 
352 	/* set number of radios based on current mode */
353 	target_psoc_set_num_radios(tgt_hdl, num_radios);
354 
355 	target_if_print_service_ready_ext_param(psoc, tgt_hdl);
356 
357 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle,
358 					   event, info, false);
359 	if (err_code)
360 		goto exit;
361 
362 	/* Host receives 11AX wireless modes from target in service ext2
363 	 * message. Therefore, call target_if_add_11ax_modes() from service ext2
364 	 * event handler as well.
365 	 */
366 	if (!wmi_service_enabled(wmi_handle, wmi_service_ext2_msg))
367 		target_if_add_11ax_modes(psoc, tgt_hdl);
368 
369 	if (init_deinit_chainmask_table_alloc(
370 				&(info->service_ext_param)) ==
371 							QDF_STATUS_SUCCESS) {
372 		err_code = init_deinit_populate_chainmask_tables(wmi_handle,
373 				event,
374 				&(info->service_ext_param.chainmask_table[0]));
375 		if (err_code)
376 			goto exit;
377 	}
378 
379 	/* dbr_ring_caps can be absent if enough space is not available */
380 	if (info->service_ext_param.num_dbr_ring_caps) {
381 		err_code = init_deinit_populate_dbr_ring_cap(psoc, wmi_handle,
382 							     event, info);
383 		if (err_code)
384 			goto exit;
385 	}
386 
387 	err_code = init_deinit_populate_spectral_bin_scale_params(psoc,
388 								  wmi_handle,
389 								  event, info);
390 	if (err_code)
391 		goto exit;
392 
393 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
394 	if (legacy_callback)
395 		legacy_callback(wmi_service_ready_ext_event_id,
396 				scn_handle, event, data_len);
397 
398 	target_if_qwrap_cfg_enable(psoc, tgt_hdl, event);
399 
400 	target_if_set_twt_ap_pdev_count(info, tgt_hdl);
401 
402 	info->wlan_res_cfg.max_bssid_indicator =
403 				info->service_ext_param.max_bssid_indicator;
404 
405 	if (wmi_service_enabled(wmi_handle, wmi_service_ext2_msg)) {
406 		target_if_debug("Wait for EXT2 message");
407 	} else {
408 		target_if_debug("No EXT2 message, send init command");
409 		init_deinit_set_send_init_cmd(psoc, tgt_hdl);
410 	}
411 
412 exit:
413 	return err_code;
414 }
415 
416 static int init_deinit_service_available_handler(ol_scn_t scn_handle,
417 						uint8_t *event,
418 						uint32_t data_len)
419 {
420 	struct wlan_objmgr_psoc *psoc;
421 	struct target_psoc_info *tgt_hdl;
422 	struct wmi_unified *wmi_handle;
423 
424 	if (!scn_handle) {
425 		target_if_err("scn handle NULL");
426 		return -EINVAL;
427 	}
428 
429 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
430 	if (!psoc) {
431 		target_if_err("psoc is null");
432 		return -EINVAL;
433 	}
434 
435 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
436 	if (!tgt_hdl) {
437 		target_if_err("target_psoc_info is null");
438 		return -EINVAL;
439 	}
440 
441 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
442 
443 	if (wmi_save_ext_service_bitmap(wmi_handle, event, NULL) !=
444 					QDF_STATUS_SUCCESS) {
445 		target_if_err("Failed to save ext service bitmap");
446 		return -EINVAL;
447 	}
448 
449 	return 0;
450 }
451 
452 /* MAC address fourth byte index */
453 #define MAC_BYTE_4 4
454 
455 static int init_deinit_ready_event_handler(ol_scn_t scn_handle,
456 						uint8_t *event,
457 						uint32_t data_len)
458 {
459 	struct wlan_objmgr_psoc *psoc;
460 	struct wlan_objmgr_pdev *pdev;
461 	struct target_psoc_info *tgt_hdl;
462 	struct wmi_unified *wmi_handle;
463 	struct wmi_host_fw_abi_ver fw_ver;
464 	uint8_t myaddr[QDF_MAC_ADDR_SIZE];
465 	struct tgt_info *info;
466 	struct wmi_host_ready_ev_param ready_ev;
467 	wmi_legacy_service_ready_callback legacy_callback;
468 	uint8_t num_radios, i;
469 	uint32_t max_peers;
470 	uint32_t max_ast_index;
471 	target_resource_config *tgt_cfg;
472 
473 	if (!scn_handle) {
474 		target_if_err("scn handle NULL");
475 		return -EINVAL;
476 	}
477 
478 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
479 	if (!psoc) {
480 		target_if_err("psoc is null");
481 		return -EINVAL;
482 	}
483 
484 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
485 	if (!tgt_hdl) {
486 		target_if_err("target_psoc_info is null");
487 		return -EINVAL;
488 	}
489 
490 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
491 	info = (&tgt_hdl->info);
492 
493 	if (wmi_extract_fw_abi_version(wmi_handle, event, &fw_ver) ==
494 				QDF_STATUS_SUCCESS) {
495 		info->version.wlan_ver = fw_ver.sw_version;
496 		info->version.wlan_ver = fw_ver.abi_version;
497 	}
498 
499 	if (wmi_check_and_update_fw_version(wmi_handle, event) < 0) {
500 		target_if_err("Version mismatch with FW");
501 		return -EINVAL;
502 	}
503 
504 	if (wmi_extract_ready_event_params(wmi_handle, event, &ready_ev) !=
505 				QDF_STATUS_SUCCESS) {
506 		target_if_err("Failed to extract ready event");
507 		return -EINVAL;
508 	}
509 
510 	if (!ready_ev.agile_capability)
511 		target_if_err("agile capability disabled in HW");
512 	else
513 		info->wlan_res_cfg.agile_capability = ready_ev.agile_capability;
514 
515 	/* Indicate to the waiting thread that the ready
516 	 * event was received
517 	 */
518 	info->wlan_init_status = wmi_ready_extract_init_status(
519 						wmi_handle, event);
520 
521 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
522 	if (legacy_callback)
523 		if (legacy_callback(wmi_ready_event_id,
524 				    scn_handle, event, data_len)) {
525 			target_if_err("Legacy callback returned error!");
526 			tgt_hdl->info.wmi_ready = FALSE;
527 			goto exit;
528 		}
529 
530 	num_radios = target_psoc_get_num_radios(tgt_hdl);
531 
532 	if ((ready_ev.num_total_peer != 0) &&
533 	    (info->wlan_res_cfg.num_peers != ready_ev.num_total_peer)) {
534 		uint16_t num_peers = 0;
535 		/* FW allocated number of peers is different than host
536 		 * requested. Update host max with FW reported value.
537 		 */
538 		target_if_err("Host Requested %d peers. FW Supports %d peers",
539 			       info->wlan_res_cfg.num_peers,
540 			       ready_ev.num_total_peer);
541 		info->wlan_res_cfg.num_peers = ready_ev.num_total_peer;
542 		num_peers = info->wlan_res_cfg.num_peers / num_radios;
543 
544 		for (i = 0; i < num_radios; i++) {
545 			pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
546 							  WLAN_INIT_DEINIT_ID);
547 			if (!pdev) {
548 				target_if_err(" PDEV %d is NULL", i);
549 				return -EINVAL;
550 			}
551 
552 			wlan_pdev_set_max_peer_count(pdev, num_peers);
553 			wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
554 		}
555 
556 		wlan_psoc_set_max_peer_count(psoc,
557 					     info->wlan_res_cfg.num_peers);
558 	}
559 
560 	/* for non legacy  num_total_peer will be non zero
561 	 * allocate peer memory in this case
562 	 */
563 	if (ready_ev.num_total_peer != 0) {
564 		tgt_cfg = &info->wlan_res_cfg;
565 		max_peers = tgt_cfg->num_peers + ready_ev.num_extra_peer + 1;
566 		max_ast_index = ready_ev.max_ast_index + 1;
567 
568 		if (cdp_peer_map_attach(wlan_psoc_get_dp_handle(psoc),
569 					max_peers, max_ast_index,
570 					tgt_cfg->peer_map_unmap_v2) !=
571 				QDF_STATUS_SUCCESS) {
572 			target_if_err("DP peer map attach failed");
573 			return -EINVAL;
574 		}
575 	}
576 
577 
578 	if (ready_ev.pktlog_defs_checksum) {
579 		for (i = 0; i < num_radios; i++) {
580 			pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
581 							  WLAN_INIT_DEINIT_ID);
582 			if (!pdev) {
583 				target_if_err(" PDEV %d is NULL", i);
584 				return -EINVAL;
585 			}
586 			target_if_set_pktlog_checksum(pdev, tgt_hdl,
587 						      ready_ev.
588 						      pktlog_defs_checksum);
589 			wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
590 		}
591 	}
592 
593 	/*
594 	 * For non-legacy HW, MAC addr list is extracted.
595 	 */
596 	if (num_radios > 1) {
597 		uint8_t num_mac_addr;
598 		wmi_host_mac_addr *addr_list;
599 		int i;
600 
601 		addr_list = wmi_ready_extract_mac_addr_list(wmi_handle, event,
602 							    &num_mac_addr);
603 		if ((num_mac_addr >= num_radios) && (addr_list)) {
604 			for (i = 0; i < num_radios; i++) {
605 				WMI_HOST_MAC_ADDR_TO_CHAR_ARRAY(&addr_list[i],
606 								myaddr);
607 				pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
608 								  WLAN_INIT_DEINIT_ID);
609 				if (!pdev) {
610 					target_if_err(" PDEV %d is NULL", i);
611 					return -EINVAL;
612 				}
613 				wlan_pdev_set_hw_macaddr(pdev, myaddr);
614 				wlan_objmgr_pdev_release_ref(pdev,
615 							WLAN_INIT_DEINIT_ID);
616 
617 				/* assign 1st radio addr to psoc */
618 				if (i == 0)
619 					wlan_psoc_set_hw_macaddr(psoc, myaddr);
620 			}
621 			goto out;
622 		} else {
623 			target_if_err("Using default MAC addr for all radios..");
624 		}
625 	}
626 
627 	/*
628 	 * We extract single MAC address in two scenarios:
629 	 * 1. In non-legacy case, if addr list is NULL or num_mac_addr < num_radios
630 	 * 2. In all legacy cases
631 	 */
632 	for (i = 0; i < num_radios; i++) {
633 		wmi_ready_extract_mac_addr(wmi_handle, event, myaddr);
634 		myaddr[MAC_BYTE_4] += i;
635 		pdev = wlan_objmgr_get_pdev_by_id(psoc, i, WLAN_INIT_DEINIT_ID);
636 		if (!pdev) {
637 			target_if_err(" PDEV %d is NULL", i);
638 			return -EINVAL;
639 		}
640 		wlan_pdev_set_hw_macaddr(pdev, myaddr);
641 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
642 		/* assign 1st radio addr to psoc */
643 		if (i == 0)
644 			wlan_psoc_set_hw_macaddr(psoc, myaddr);
645 	}
646 
647 out:
648 	target_if_btcoex_cfg_enable(psoc, tgt_hdl, event);
649 	tgt_hdl->info.wmi_ready = TRUE;
650 exit:
651 	init_deinit_wakeup_host_wait(psoc, tgt_hdl);
652 
653 	return 0;
654 }
655 
656 
657 QDF_STATUS init_deinit_register_tgt_psoc_ev_handlers(
658 				struct wlan_objmgr_psoc *psoc)
659 {
660 	struct target_psoc_info *tgt_hdl;
661 	wmi_unified_t wmi_handle;
662 	QDF_STATUS retval = QDF_STATUS_SUCCESS;
663 
664 	if (!psoc) {
665 		target_if_err("psoc is null in register wmi handler");
666 		return QDF_STATUS_E_FAILURE;
667 	}
668 
669 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
670 	if (!tgt_hdl) {
671 		target_if_err("target_psoc_info null in register wmi hadler");
672 		return QDF_STATUS_E_FAILURE;
673 	}
674 
675 	wmi_handle = (wmi_unified_t)target_psoc_get_wmi_hdl(tgt_hdl);
676 
677 	retval = wmi_unified_register_event_handler(wmi_handle,
678 				wmi_service_ready_event_id,
679 				init_deinit_service_ready_event_handler,
680 				WMI_RX_WORK_CTX);
681 	retval = wmi_unified_register_event_handler(wmi_handle,
682 				wmi_service_ready_ext_event_id,
683 				init_deinit_service_ext_ready_event_handler,
684 				WMI_RX_WORK_CTX);
685 	retval = wmi_unified_register_event_handler(wmi_handle,
686 				wmi_service_available_event_id,
687 				init_deinit_service_available_handler,
688 				WMI_RX_UMAC_CTX);
689 	retval = wmi_unified_register_event_handler(wmi_handle,
690 				wmi_ready_event_id,
691 				init_deinit_ready_event_handler,
692 				WMI_RX_WORK_CTX);
693 	retval = wmi_unified_register_event_handler(
694 				wmi_handle,
695 				wmi_service_ready_ext2_event_id,
696 				init_deinit_service_ext2_ready_event_handler,
697 				WMI_RX_WORK_CTX);
698 
699 
700 	return retval;
701 }
702 
703