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