xref: /wlan-dirver/qca-wifi-host-cmn/target_if/init_deinit/src/init_event_handler.c (revision 70a8e8a708a5f24e828d089a4c6df03e32b11c42)
1 /*
2  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: init_event_handler.c
22  *
23  * WMI common event handler implementation source file
24  */
25 
26 #include <qdf_status.h>
27 #include <wlan_objmgr_psoc_obj.h>
28 #include <wlan_objmgr_pdev_obj.h>
29 #include <target_if.h>
30 #include <target_if_reg.h>
31 #include <init_event_handler.h>
32 #include <service_ready_util.h>
33 #include <service_ready_param.h>
34 #include <init_cmd_api.h>
35 #include <cdp_txrx_cmn.h>
36 #include <wlan_reg_ucfg_api.h>
37 #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
38 #include <wlan_mlo_mgr_cmn.h>
39 #include <wlan_mlo_mgr_setup.h>
40 #endif
41 #include <target_if_twt.h>
42 
43 static void init_deinit_set_send_init_cmd(struct wlan_objmgr_psoc *psoc,
44 					  struct target_psoc_info *tgt_hdl)
45 {
46 	tgt_hdl->info.wmi_service_ready = TRUE;
47 	/* send init command */
48 	init_deinit_prepare_send_init_cmd(psoc, tgt_hdl);
49 }
50 
51 #ifdef WLAN_FEATURE_P2P_P2P_STA
52 static void
53 init_deinit_update_p2p_p2p_conc_support(struct wmi_unified *wmi_handle,
54 					struct wlan_objmgr_psoc *psoc)
55 {
56 	if (wmi_service_enabled(wmi_handle, wmi_service_p2p_p2p_cc_support))
57 		wlan_psoc_nif_fw_ext_cap_set(psoc,
58 					     WLAN_SOC_EXT_P2P_P2P_CONC_SUPPORT);
59 	else
60 		target_if_debug("P2P + P2P conc disabled");
61 }
62 #else
63 static inline void
64 init_deinit_update_p2p_p2p_conc_support(struct wmi_unified *wmi_handle,
65 					struct wlan_objmgr_psoc *psoc)
66 {}
67 #endif
68 
69 #ifdef QCA_RSSI_DB2DBM
70 static void
71 init_deinit_update_rssi_dbm_conv_support(struct wmi_unified *wmi_handle,
72 					 struct wlan_objmgr_psoc *psoc)
73 {
74 	/* Send RSSI_DBM_CONV to DP layer */
75 	if (wmi_service_enabled(wmi_handle,
76 				wmi_service_pdev_rssi_dbm_conv_event_support))
77 		cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
78 				  DP_SOC_PARAM_RSSI_DBM_CONV_SUPPORT, 1);
79 }
80 #else
81 static inline void
82 init_deinit_update_rssi_dbm_conv_support(struct wmi_unified *wmi_handle,
83 					 struct wlan_objmgr_psoc *psoc)
84 {}
85 #endif
86 
87 #ifdef WIFI_POS_CONVERGED
88 static inline void
89 init_deinit_update_wifi_pos_caps(struct wmi_unified *wmi_handle,
90 				 struct wlan_objmgr_psoc *psoc)
91 {
92 	if (wmi_service_enabled(wmi_handle, wmi_service_rtt_11az_ntb_support))
93 		wlan_psoc_nif_fw_ext_cap_set(psoc,
94 					     WLAN_RTT_11AZ_NTB_SUPPORT);
95 
96 	if (wmi_service_enabled(wmi_handle, wmi_service_rtt_11az_tb_support))
97 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
98 					      WLAN_RTT_11AZ_TB_SUPPORT);
99 
100 	if (wmi_service_enabled(wmi_handle,
101 				wmi_service_rtt_11az_mac_sec_support))
102 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
103 					      WLAN_RTT_11AZ_MAC_SEC_SUPPORT);
104 
105 	if (wmi_service_enabled(wmi_handle,
106 				wmi_service_rtt_11az_mac_phy_sec_support))
107 		wlan_psoc_nif_fw_ext2_cap_set(
108 				psoc, WLAN_RTT_11AZ_MAC_PHY_SEC_SUPPORT);
109 }
110 #else
111 static inline void
112 init_deinit_update_wifi_pos_caps(struct wmi_unified *wmi_handle,
113 				 struct wlan_objmgr_psoc *psoc)
114 {}
115 #endif
116 
117 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
118 static void
119 init_deinit_update_roam_stats_cap(struct wmi_unified *wmi_handle,
120 				  struct wlan_objmgr_psoc *psoc)
121 {
122 	if (wmi_service_enabled(wmi_handle,
123 				wmi_service_roam_stats_per_candidate_frame_info))
124 		wlan_psoc_nif_fw_ext2_cap_set(
125 			psoc, WLAN_ROAM_STATS_FRAME_INFO_PER_CANDIDATE);
126 }
127 #else
128 static inline void
129 init_deinit_update_roam_stats_cap(struct wmi_unified *wmi_handle,
130 				  struct wlan_objmgr_psoc *psoc)
131 {}
132 #endif
133 
134 #ifdef MULTI_CLIENT_LL_SUPPORT
135 /**
136  * init_deinit_update_multi_client_ll_caps() - Update multi client service
137  * capability bit
138  * @wmi_handle: wmi hanle
139  * @psoc: psoc commom object
140  *
141  * Return: none
142  */
143 static void
144 init_deinit_update_multi_client_ll_caps(struct wmi_unified *wmi_handle,
145 					struct wlan_objmgr_psoc *psoc)
146 {
147 	if (wmi_service_enabled(wmi_handle,
148 				wmi_service_configure_multi_client_ll_support))
149 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
150 					WLAN_SOC_WLM_MULTI_CLIENT_LL_SUPPORT);
151 }
152 #else
153 static inline void
154 init_deinit_update_multi_client_ll_caps(struct wmi_unified *wmi_handle,
155 					struct wlan_objmgr_psoc *psoc)
156 {}
157 #endif
158 
159 static int init_deinit_service_ready_event_handler(ol_scn_t scn_handle,
160 							uint8_t *event,
161 							uint32_t data_len)
162 {
163 	int err_code;
164 	struct wlan_objmgr_psoc *psoc;
165 	struct target_psoc_info *tgt_hdl;
166 	wmi_legacy_service_ready_callback legacy_callback;
167 	struct wmi_unified *wmi_handle;
168 	QDF_STATUS ret_val;
169 
170 	if (!scn_handle) {
171 		target_if_err("scn handle NULL in service ready handler");
172 		return -EINVAL;
173 	}
174 
175 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
176 	if (!psoc) {
177 		target_if_err("psoc is null in service ready handler");
178 		return -EINVAL;
179 	}
180 
181 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
182 	if (!tgt_hdl) {
183 		target_if_err("target_psoc_info is null in service ready ev");
184 		return -EINVAL;
185 	}
186 
187 	ret_val = target_if_sw_version_check(psoc, tgt_hdl, event);
188 
189 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
190 
191 	err_code = init_deinit_populate_service_bitmap(wmi_handle, event,
192 			tgt_hdl->info.service_bitmap);
193 	if (err_code)
194 		goto exit;
195 
196 	err_code = init_deinit_populate_fw_version_cmd(wmi_handle, event);
197 	if (err_code)
198 		goto exit;
199 
200 	err_code = init_deinit_populate_target_cap(wmi_handle, event,
201 				   &(tgt_hdl->info.target_caps));
202 	if (err_code)
203 		goto exit;
204 
205 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle, event,
206 				    &(tgt_hdl->info), true);
207 	if (err_code)
208 		goto exit;
209 
210 	if (init_deinit_validate_160_80p80_fw_caps(psoc, tgt_hdl) !=
211 			QDF_STATUS_SUCCESS) {
212 		wlan_psoc_nif_op_flag_set(psoc, WLAN_SOC_OP_VHT_INVALID_CAP);
213 	}
214 
215 	if (wmi_service_enabled(wmi_handle, wmi_service_tt))
216 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TT_SUPPORT);
217 
218 	if (wmi_service_enabled(wmi_handle, wmi_service_widebw_scan))
219 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN);
220 
221 	if (wmi_service_enabled(wmi_handle, wmi_service_check_cal_version))
222 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_SW_CAL);
223 
224 	if (wmi_service_enabled(wmi_handle, wmi_service_twt_requestor))
225 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TWT_REQUESTER);
226 
227 	if (wmi_service_enabled(wmi_handle, wmi_service_twt_responder))
228 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TWT_RESPONDER);
229 
230 	if (wmi_service_enabled(wmi_handle, wmi_service_bss_color_offload))
231 		target_if_debug(" BSS COLOR OFFLOAD supported");
232 
233 	if (wmi_service_enabled(wmi_handle, wmi_service_ul_ru26_allowed))
234 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_OBSS_NBW_RU);
235 
236 	if (wmi_service_enabled(wmi_handle, wmi_service_infra_mbssid))
237 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_MBSS_IE);
238 
239 	if (wmi_service_enabled(wmi_handle,
240 				wmi_service_mbss_param_in_vdev_start_support))
241 		wlan_psoc_nif_fw_ext_cap_set(psoc,
242 					     WLAN_SOC_CEXT_MBSS_PARAM_IN_START);
243 
244 	if (wmi_service_enabled(wmi_handle, wmi_service_dynamic_hw_mode))
245 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_DYNAMIC_HW_MODE);
246 
247 	if (wmi_service_enabled(wmi_handle,
248 				wmi_service_bw_restricted_80p80_support))
249 		wlan_psoc_nif_fw_ext_cap_set(psoc,
250 					     WLAN_SOC_RESTRICTED_80P80_SUPPORT);
251 
252 	if (wmi_service_enabled(wmi_handle,
253 				wmi_service_nss_ratio_to_host_support))
254 		wlan_psoc_nif_fw_ext_cap_set(
255 				psoc, WLAN_SOC_NSS_RATIO_TO_HOST_SUPPORT);
256 
257 	if (wmi_service_enabled(wmi_handle,
258 				wmi_service_rtt_ap_initiator_staggered_mode_supported))
259 		wlan_psoc_nif_fw_ext_cap_set(
260 				psoc, WLAN_SOC_RTT_AP_INITIATOR_STAGGERED_MODE_SUPPORTED);
261 
262 	if (wmi_service_enabled(wmi_handle,
263 				wmi_service_rtt_ap_initiator_bursted_mode_supported))
264 		wlan_psoc_nif_fw_ext_cap_set(
265 				psoc, WLAN_SOC_RTT_AP_INITIATOR_BURSTED_MODE_SUPPORTED);
266 
267 	target_if_debug(" TT support %d, Wide BW Scan %d, SW cal %d",
268 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_TT_SUPPORT),
269 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN),
270 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_SW_CAL));
271 
272 	target_if_mesh_support_enable(psoc, tgt_hdl, event);
273 
274 	target_if_eapol_minrate_enable(psoc, tgt_hdl, event);
275 
276 	target_if_smart_antenna_enable(psoc, tgt_hdl, event);
277 
278 	target_if_cfr_support_enable(psoc, tgt_hdl, event);
279 
280 	target_if_peer_cfg_enable(psoc, tgt_hdl, event);
281 
282 	target_if_atf_cfg_enable(psoc, tgt_hdl, event);
283 
284 	if (wmi_service_enabled(wmi_handle,
285 				wmi_service_mgmt_rx_reo_supported))
286 		wlan_psoc_nif_fw_ext_cap_set(psoc,
287 					     WLAN_SOC_F_MGMT_RX_REO_CAPABLE);
288 
289 	target_if_lteu_cfg_enable(psoc, tgt_hdl, event);
290 
291 	if (wmi_service_enabled(wmi_handle, wmi_service_rx_fse_support))
292 		wlan_psoc_nif_fw_ext_cap_set(psoc,
293 					     WLAN_SOC_CEXT_RX_FSE_SUPPORT);
294 
295 	if (wmi_service_enabled(wmi_handle,
296 				wmi_service_scan_conf_per_ch_support))
297 		wlan_psoc_nif_fw_ext_cap_set(psoc,
298 					     WLAN_SOC_CEXT_SCAN_PER_CH_CONFIG);
299 
300 	if (wmi_service_enabled(wmi_handle,
301 				wmi_service_pno_scan_conf_per_ch_support))
302 		wlan_psoc_nif_fw_ext_cap_set(psoc,
303 					WLAN_SOC_PNO_SCAN_CONFIG_PER_CHANNEL);
304 
305 	if (wmi_service_enabled(wmi_handle, wmi_service_csa_beacon_template))
306 		wlan_psoc_nif_fw_ext_cap_set(psoc,
307 					     WLAN_SOC_CEXT_CSA_TX_OFFLOAD);
308 
309 	init_deinit_update_roam_stats_cap(wmi_handle, psoc);
310 
311 	init_deinit_update_wifi_pos_caps(wmi_handle, psoc);
312 
313 	/* override derived value, if it exceeds max peer count */
314 	if ((wlan_psoc_get_max_peer_count(psoc) >
315 		tgt_hdl->info.wlan_res_cfg.num_active_peers) &&
316 		(wlan_psoc_get_max_peer_count(psoc) <
317 			(tgt_hdl->info.wlan_res_cfg.num_peers -
318 				tgt_hdl->info.wlan_res_cfg.num_vdevs))) {
319 		tgt_hdl->info.wlan_res_cfg.num_peers =
320 				wlan_psoc_get_max_peer_count(psoc) +
321 					tgt_hdl->info.wlan_res_cfg.num_vdevs;
322 	}
323 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
324 	if (!legacy_callback) {
325 		err_code = -EINVAL;
326 		goto exit;
327 	}
328 
329 	err_code = legacy_callback(wmi_service_ready_event_id,
330 				  scn_handle, event, data_len);
331 	init_deinit_chainmask_config(psoc, tgt_hdl);
332 
333 	if (wmi_service_enabled(wmi_handle, wmi_service_mgmt_tx_wmi)) {
334 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WMI_MGMT_REF);
335 		target_if_debug("WMI mgmt service enabled");
336 	} else {
337 		wlan_psoc_nif_fw_ext_cap_clear(psoc,
338 					       WLAN_SOC_CEXT_WMI_MGMT_REF);
339 		target_if_debug("WMI mgmt service disabled");
340 	}
341 	init_deinit_update_p2p_p2p_conc_support(wmi_handle, psoc);
342 
343 	err_code = init_deinit_handle_host_mem_req(psoc, tgt_hdl, event);
344 	if (err_code != QDF_STATUS_SUCCESS)
345 		goto exit;
346 
347 	target_if_reg_set_offloaded_info(psoc);
348 	target_if_reg_set_6ghz_info(psoc);
349 	target_if_reg_set_5dot9_ghz_info(psoc);
350 	target_if_twt_fill_tgt_caps(psoc, wmi_handle);
351 
352 	/* Send num_msdu_desc to DP layer */
353 	cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
354 			  DP_SOC_PARAM_MSDU_EXCEPTION_DESC,
355 			  tgt_hdl->info.target_caps.num_msdu_desc);
356 
357 	/* Send CMEM FSE support to DP layer */
358 	if (wmi_service_enabled(wmi_handle, wmi_service_fse_cmem_alloc_support))
359 		cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
360 				  DP_SOC_PARAM_CMEM_FSE_SUPPORT, 1);
361 
362 	/* Send multi_peer_group support to DP layer */
363 	if (wmi_service_enabled(wmi_handle,
364 				wmi_service_multi_peer_group_cmd_support))
365 		cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
366 				  DP_SOC_PARAM_MULTI_PEER_GRP_CMD_SUPPORT, 1);
367 
368 	init_deinit_update_rssi_dbm_conv_support(wmi_handle, psoc);
369 
370 	init_deinit_update_multi_client_ll_caps(wmi_handle, psoc);
371 
372 	if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
373 		target_if_debug("Wait for EXT message");
374 	} else {
375 		target_if_debug("No EXT message, send init command");
376 		target_psoc_set_num_radios(tgt_hdl, 1);
377 		init_deinit_set_send_init_cmd(psoc, tgt_hdl);
378 	}
379 
380 exit:
381 	return err_code;
382 }
383 
384 static int init_deinit_service_ext2_ready_event_handler(ol_scn_t scn_handle,
385 							uint8_t *event,
386 							uint32_t data_len)
387 {
388 	int err_code = 0;
389 	struct wlan_objmgr_psoc *psoc;
390 	struct target_psoc_info *tgt_hdl;
391 	struct wmi_unified *wmi_handle;
392 	struct tgt_info *info;
393 	wmi_legacy_service_ready_callback legacy_callback;
394 
395 	if (!scn_handle) {
396 		target_if_err("scn handle NULL in service ready ext2 handler");
397 		return -EINVAL;
398 	}
399 
400 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
401 	if (!psoc) {
402 		target_if_err("psoc is null in service ready ext2 handler");
403 		return -EINVAL;
404 	}
405 
406 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
407 	if (!tgt_hdl) {
408 		target_if_err("target_psoc_info is null in service ready ext2 handler");
409 		return -EINVAL;
410 	}
411 
412 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
413 	if (!wmi_handle) {
414 		target_if_err("wmi_handle is null in service ready ext2 handler");
415 		return -EINVAL;
416 	}
417 
418 	info = (&tgt_hdl->info);
419 
420 	err_code = init_deinit_populate_service_ready_ext2_param(wmi_handle,
421 								 event, info);
422 	if (err_code)
423 		goto exit;
424 
425 	if (wmi_service_enabled(wmi_handle,
426 				wmi_service_reg_cc_ext_event_support)) {
427 		target_if_set_reg_cc_ext_supp(tgt_hdl, psoc);
428 		wlan_psoc_nif_fw_ext_cap_set(psoc,
429 					     WLAN_SOC_EXT_EVENT_SUPPORTED);
430 	}
431 
432 	/* dbr_ring_caps could have already come as part of EXT event */
433 	if (info->service_ext2_param.num_dbr_ring_caps) {
434 		err_code = init_deinit_populate_dbr_ring_cap_ext2(psoc,
435 								  wmi_handle,
436 								  event, info);
437 		if (err_code)
438 			goto exit;
439 	}
440 
441 	err_code = init_deinit_populate_hal_reg_cap_ext2(wmi_handle, event,
442 							 info);
443 	if (err_code) {
444 		target_if_err("failed to populate hal reg cap ext2");
445 		goto exit;
446 	}
447 
448 	err_code = init_deinit_populate_mac_phy_cap_ext2(wmi_handle, event,
449 							 info);
450 	if (err_code) {
451 		target_if_err("failed to populate mac phy cap ext2");
452 		goto exit;
453 	}
454 
455 	target_if_add_11ax_modes(psoc, tgt_hdl);
456 
457 	err_code = init_deinit_populate_scan_radio_cap_ext2(wmi_handle, event,
458 							    info);
459 	if (err_code) {
460 		target_if_err("failed to populate scan radio cap ext2");
461 		goto exit;
462 	}
463 
464 	err_code = init_deinit_populate_twt_cap_ext2(psoc, wmi_handle, event,
465 						     info);
466 
467 	if (err_code)
468 		target_if_debug("failed to populate twt cap ext2");
469 
470 	err_code = init_deinit_populate_dbs_or_sbs_cap_ext2(psoc, wmi_handle,
471 							    event, info);
472 	if (err_code)
473 		target_if_debug("failed to populate dbs_or_sbs cap ext2");
474 
475 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
476 	if (legacy_callback)
477 		legacy_callback(wmi_service_ready_ext2_event_id,
478 				scn_handle, event, data_len);
479 
480 	target_if_regulatory_set_ext_tpc(psoc);
481 
482 	target_if_reg_set_lower_6g_edge_ch_info(psoc);
483 
484 	target_if_reg_set_disable_upper_6g_edge_ch_info(psoc);
485 
486 	target_if_reg_set_afc_dev_type(psoc, tgt_hdl);
487 
488 	/* send init command */
489 	init_deinit_set_send_init_cmd(psoc, tgt_hdl);
490 
491 exit:
492 	return err_code;
493 }
494 
495 static int init_deinit_service_ext_ready_event_handler(ol_scn_t scn_handle,
496 						uint8_t *event,
497 						uint32_t data_len)
498 {
499 	int err_code;
500 	uint8_t num_radios;
501 	struct wlan_objmgr_psoc *psoc;
502 	struct target_psoc_info *tgt_hdl;
503 	struct wmi_unified *wmi_handle;
504 	struct tgt_info *info;
505 	wmi_legacy_service_ready_callback legacy_callback;
506 
507 	if (!scn_handle) {
508 		target_if_err("scn handle NULL in service ready handler");
509 		return -EINVAL;
510 	}
511 
512 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
513 	if (!psoc) {
514 		target_if_err("psoc is null in service ready handler");
515 		return -EINVAL;
516 	}
517 
518 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
519 	if (!tgt_hdl) {
520 		target_if_err("target_psoc_info is null in service ready ev");
521 		return -EINVAL;
522 	}
523 
524 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
525 	info = (&tgt_hdl->info);
526 
527 	err_code = init_deinit_populate_service_ready_ext_param(wmi_handle,
528 				event, &(info->service_ext_param));
529 	if (err_code)
530 		goto exit;
531 
532 	target_psoc_set_num_radios(tgt_hdl, 0);
533 	err_code =  init_deinit_populate_hw_mode_capability(wmi_handle,
534 					    event, tgt_hdl);
535 	if (err_code)
536 		goto exit;
537 
538 	if (init_deinit_is_preferred_hw_mode_supported(psoc, tgt_hdl)
539 			== FALSE) {
540 		target_if_err("Preferred mode %d not supported",
541 			      info->preferred_hw_mode);
542 		return -EINVAL;
543 	}
544 
545 	num_radios = target_psoc_get_num_radios_for_mode(tgt_hdl,
546 							 info->preferred_hw_mode);
547 
548 	/* set number of radios based on current mode */
549 	target_psoc_set_num_radios(tgt_hdl, num_radios);
550 
551 	target_if_print_service_ready_ext_param(psoc, tgt_hdl);
552 
553 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle,
554 					   event, info, false);
555 	if (err_code)
556 		goto exit;
557 
558 	/* Host receives 11AX wireless modes from target in service ext2
559 	 * message. Therefore, call target_if_add_11ax_modes() from service ext2
560 	 * event handler as well.
561 	 */
562 	if (!wmi_service_enabled(wmi_handle, wmi_service_ext2_msg))
563 		target_if_add_11ax_modes(psoc, tgt_hdl);
564 
565 	if (init_deinit_chainmask_table_alloc(
566 				&(info->service_ext_param)) ==
567 							QDF_STATUS_SUCCESS) {
568 		err_code = init_deinit_populate_chainmask_tables(wmi_handle,
569 				event,
570 				&(info->service_ext_param.chainmask_table[0]));
571 		if (err_code)
572 			goto exit;
573 	}
574 
575 	/* dbr_ring_caps can be absent if enough space is not available */
576 	if (info->service_ext_param.num_dbr_ring_caps) {
577 		err_code = init_deinit_populate_dbr_ring_cap(psoc, wmi_handle,
578 							     event, info);
579 		if (err_code)
580 			goto exit;
581 	}
582 
583 	err_code = init_deinit_populate_spectral_bin_scale_params(psoc,
584 								  wmi_handle,
585 								  event, info);
586 	if (err_code)
587 		goto exit;
588 
589 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
590 	if (legacy_callback)
591 		legacy_callback(wmi_service_ready_ext_event_id,
592 				scn_handle, event, data_len);
593 
594 	target_if_set_twt_ap_pdev_count(info, tgt_hdl);
595 
596 	info->wlan_res_cfg.max_bssid_indicator =
597 				info->service_ext_param.max_bssid_indicator;
598 
599 	if (wmi_service_enabled(wmi_handle, wmi_service_ext2_msg)) {
600 		target_if_debug("Wait for EXT2 message");
601 	} else {
602 		target_if_debug("No EXT2 message, send init command");
603 		init_deinit_set_send_init_cmd(psoc, tgt_hdl);
604 	}
605 
606 exit:
607 	return err_code;
608 }
609 
610 static int init_deinit_service_available_handler(ol_scn_t scn_handle,
611 						uint8_t *event,
612 						uint32_t data_len)
613 {
614 	struct wlan_objmgr_psoc *psoc;
615 	struct target_psoc_info *tgt_hdl;
616 	struct wmi_unified *wmi_handle;
617 
618 	if (!scn_handle) {
619 		target_if_err("scn handle NULL");
620 		return -EINVAL;
621 	}
622 
623 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
624 	if (!psoc) {
625 		target_if_err("psoc is null");
626 		return -EINVAL;
627 	}
628 
629 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
630 	if (!tgt_hdl) {
631 		target_if_err("target_psoc_info is null");
632 		return -EINVAL;
633 	}
634 
635 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
636 
637 	if (wmi_save_ext_service_bitmap(wmi_handle, event, NULL) !=
638 					QDF_STATUS_SUCCESS) {
639 		target_if_err("Failed to save ext service bitmap");
640 		return -EINVAL;
641 	}
642 
643 	return 0;
644 }
645 
646 #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
647 static bool init_deinit_mlo_capable(struct wlan_objmgr_psoc *psoc)
648 {
649 	struct target_psoc_info *tgt_hdl;
650 
651 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
652 	if (!tgt_hdl) {
653 		target_if_err("target_psoc_info is null");
654 		return false;
655 	}
656 
657 	if ((tgt_hdl->tif_ops) &&
658 	    (tgt_hdl->tif_ops->mlo_capable))
659 		return tgt_hdl->tif_ops->mlo_capable(psoc);
660 
661 	return false;
662 }
663 
664 static void init_deinit_mlo_update_soc_ready(struct wlan_objmgr_psoc *psoc)
665 {
666 	if (init_deinit_mlo_capable(psoc))
667 		mlo_setup_update_soc_ready(psoc);
668 }
669 
670 static void init_deinit_send_ml_link_ready(struct wlan_objmgr_psoc *psoc,
671 					   void *object, void *arg)
672 {
673 	struct wlan_objmgr_pdev *pdev = object;
674 
675 	if (!init_deinit_mlo_capable(psoc))
676 		return;
677 
678 	qdf_assert_always(psoc);
679 	qdf_assert_always(pdev);
680 
681 	mlo_setup_link_ready(pdev);
682 }
683 
684 static void init_deinit_mlo_update_pdev_ready(struct wlan_objmgr_psoc *psoc,
685 					      uint8_t num_radios)
686 {
687 	if (!init_deinit_mlo_capable(psoc))
688 		return;
689 
690 	wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP,
691 				     init_deinit_send_ml_link_ready,
692 				     NULL, 0, WLAN_INIT_DEINIT_ID);
693 }
694 #else
695 static void init_deinit_mlo_update_soc_ready(struct wlan_objmgr_psoc *psoc)
696 {}
697 static void init_deinit_mlo_update_pdev_ready(struct wlan_objmgr_psoc *psoc,
698 					      uint8_t num_radios)
699 {}
700 #endif /*WLAN_FEATURE_11BE_MLO && WLAN_MLO_MULTI_CHIP*/
701 
702 /* MAC address fourth byte index */
703 #define MAC_BYTE_4 4
704 
705 static int init_deinit_ready_event_handler(ol_scn_t scn_handle,
706 						uint8_t *event,
707 						uint32_t data_len)
708 {
709 	struct wlan_objmgr_psoc *psoc;
710 	struct wlan_objmgr_pdev *pdev;
711 	struct target_psoc_info *tgt_hdl;
712 	struct wmi_unified *wmi_handle;
713 	struct wmi_host_fw_abi_ver fw_ver;
714 	uint8_t myaddr[QDF_MAC_ADDR_SIZE];
715 	struct tgt_info *info;
716 	struct wmi_host_ready_ev_param ready_ev;
717 	wmi_legacy_service_ready_callback legacy_callback;
718 	uint8_t num_radios, i;
719 	uint32_t max_peers;
720 	uint32_t max_ast_index;
721 	target_resource_config *tgt_cfg;
722 
723 	if (!scn_handle) {
724 		target_if_err("scn handle NULL");
725 		return -EINVAL;
726 	}
727 
728 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
729 	if (!psoc) {
730 		target_if_err("psoc is null");
731 		return -EINVAL;
732 	}
733 
734 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
735 	if (!tgt_hdl) {
736 		target_if_err("target_psoc_info is null");
737 		return -EINVAL;
738 	}
739 
740 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
741 	info = (&tgt_hdl->info);
742 
743 	if (wmi_extract_fw_abi_version(wmi_handle, event, &fw_ver) ==
744 				QDF_STATUS_SUCCESS) {
745 		info->version.wlan_ver = fw_ver.sw_version;
746 		info->version.wlan_ver = fw_ver.abi_version;
747 	}
748 
749 	if (wmi_check_and_update_fw_version(wmi_handle, event) < 0) {
750 		target_if_err("Version mismatch with FW");
751 		return -EINVAL;
752 	}
753 
754 	if (wmi_extract_ready_event_params(wmi_handle, event, &ready_ev) !=
755 				QDF_STATUS_SUCCESS) {
756 		target_if_err("Failed to extract ready event");
757 		return -EINVAL;
758 	}
759 
760 	if (!ready_ev.agile_capability)
761 		target_if_err("agile capability disabled in HW");
762 	else
763 		info->wlan_res_cfg.agile_capability = ready_ev.agile_capability;
764 
765 	/* Indicate to the waiting thread that the ready
766 	 * event was received
767 	 */
768 	info->wlan_init_status = wmi_ready_extract_init_status(
769 						wmi_handle, event);
770 
771 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
772 	if (legacy_callback)
773 		if (legacy_callback(wmi_ready_event_id,
774 				    scn_handle, event, data_len)) {
775 			target_if_err("Legacy callback returned error!");
776 			tgt_hdl->info.wmi_ready = FALSE;
777 			goto exit;
778 		}
779 
780 	init_deinit_mlo_update_soc_ready(psoc);
781 
782 	num_radios = target_psoc_get_num_radios(tgt_hdl);
783 
784 	if ((ready_ev.num_total_peer != 0) &&
785 	    (info->wlan_res_cfg.num_peers != ready_ev.num_total_peer)) {
786 		uint16_t num_peers = 0;
787 		/* FW allocated number of peers is different than host
788 		 * requested. Update host max with FW reported value.
789 		 */
790 		target_if_err("Host Requested %d peers. FW Supports %d peers",
791 			       info->wlan_res_cfg.num_peers,
792 			       ready_ev.num_total_peer);
793 		info->wlan_res_cfg.num_peers = ready_ev.num_total_peer;
794 		num_peers = info->wlan_res_cfg.num_peers / num_radios;
795 
796 		for (i = 0; i < num_radios; i++) {
797 			pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
798 							  WLAN_INIT_DEINIT_ID);
799 			if (!pdev) {
800 				target_if_err(" PDEV %d is NULL", i);
801 				return -EINVAL;
802 			}
803 
804 			wlan_pdev_set_max_peer_count(pdev, num_peers);
805 			wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
806 		}
807 
808 		wlan_psoc_set_max_peer_count(psoc,
809 					     info->wlan_res_cfg.num_peers);
810 	}
811 
812 	/* for non legacy  num_total_peer will be non zero
813 	 * allocate peer memory in this case
814 	 */
815 	if (ready_ev.num_total_peer != 0) {
816 		tgt_cfg = &info->wlan_res_cfg;
817 		max_peers = tgt_cfg->num_peers + ready_ev.num_extra_peer + 1;
818 		max_ast_index = ready_ev.max_ast_index + 1;
819 
820 		if (cdp_peer_map_attach(wlan_psoc_get_dp_handle(psoc),
821 					max_peers, max_ast_index,
822 					tgt_cfg->peer_map_unmap_version) !=
823 				QDF_STATUS_SUCCESS) {
824 			target_if_err("DP peer map attach failed");
825 			return -EINVAL;
826 		}
827 	}
828 
829 
830 	if (ready_ev.pktlog_defs_checksum) {
831 		for (i = 0; i < num_radios; i++) {
832 			pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
833 							  WLAN_INIT_DEINIT_ID);
834 			if (!pdev) {
835 				target_if_err(" PDEV %d is NULL", i);
836 				return -EINVAL;
837 			}
838 			target_if_set_pktlog_checksum(pdev, tgt_hdl,
839 						      ready_ev.
840 						      pktlog_defs_checksum);
841 			wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
842 		}
843 	}
844 
845 	/*
846 	 * For non-legacy HW, MAC addr list is extracted.
847 	 */
848 	if (num_radios > 1) {
849 		uint8_t num_mac_addr;
850 		wmi_host_mac_addr *addr_list;
851 		int i;
852 
853 		addr_list = wmi_ready_extract_mac_addr_list(wmi_handle, event,
854 							    &num_mac_addr);
855 		if ((num_mac_addr >= num_radios) && (addr_list)) {
856 			for (i = 0; i < num_radios; i++) {
857 				WMI_HOST_MAC_ADDR_TO_CHAR_ARRAY(&addr_list[i],
858 								myaddr);
859 				pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
860 								  WLAN_INIT_DEINIT_ID);
861 				if (!pdev) {
862 					target_if_err(" PDEV %d is NULL", i);
863 					return -EINVAL;
864 				}
865 				wlan_pdev_set_hw_macaddr(pdev, myaddr);
866 				wlan_objmgr_pdev_release_ref(pdev,
867 							WLAN_INIT_DEINIT_ID);
868 
869 				/* assign 1st radio addr to psoc */
870 				if (i == 0)
871 					wlan_psoc_set_hw_macaddr(psoc, myaddr);
872 			}
873 			goto out;
874 		} else {
875 			target_if_err("Using default MAC addr for all radios..");
876 		}
877 	}
878 
879 	/*
880 	 * We extract single MAC address in two scenarios:
881 	 * 1. In non-legacy case, if addr list is NULL or num_mac_addr < num_radios
882 	 * 2. In all legacy cases
883 	 */
884 	for (i = 0; i < num_radios; i++) {
885 		wmi_ready_extract_mac_addr(wmi_handle, event, myaddr);
886 		myaddr[MAC_BYTE_4] += i;
887 		pdev = wlan_objmgr_get_pdev_by_id(psoc, i, WLAN_INIT_DEINIT_ID);
888 		if (!pdev) {
889 			target_if_err(" PDEV %d is NULL", i);
890 			return -EINVAL;
891 		}
892 		wlan_pdev_set_hw_macaddr(pdev, myaddr);
893 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
894 		/* assign 1st radio addr to psoc */
895 		if (i == 0)
896 			wlan_psoc_set_hw_macaddr(psoc, myaddr);
897 	}
898 
899 out:
900 	target_if_btcoex_cfg_enable(psoc, tgt_hdl, event);
901 	tgt_hdl->info.wmi_ready = TRUE;
902 	init_deinit_mlo_update_pdev_ready(psoc, num_radios);
903 exit:
904 	init_deinit_wakeup_host_wait(psoc, tgt_hdl);
905 
906 	return 0;
907 }
908 
909 #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
910 static void init_deinit_mlo_setup_done_event(struct wlan_objmgr_psoc *psoc)
911 {
912 	struct target_psoc_info *tgt_hdl;
913 
914 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
915 	if (!tgt_hdl) {
916 		target_if_err("target_psoc_info is null");
917 		return;
918 	}
919 
920 	if ((tgt_hdl->tif_ops) &&
921 	    (tgt_hdl->tif_ops->mlo_setup_done_event))
922 		tgt_hdl->tif_ops->mlo_setup_done_event(psoc);
923 }
924 
925 static int init_deinit_mlo_setup_comp_event_handler(ol_scn_t scn_handle,
926 						    uint8_t *event,
927 						    uint32_t data_len)
928 {
929 	struct wlan_objmgr_psoc *psoc;
930 	struct wlan_objmgr_pdev *pdev;
931 	struct target_psoc_info *tgt_hdl;
932 	struct wmi_unified *wmi_handle;
933 	struct wmi_mlo_setup_complete_params params;
934 
935 	if (!scn_handle) {
936 		target_if_err("scn handle NULL");
937 		return -EINVAL;
938 	}
939 
940 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
941 	if (!psoc) {
942 		target_if_err("psoc is null");
943 		return -EINVAL;
944 	}
945 
946 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
947 	if (!tgt_hdl) {
948 		target_if_err("target_psoc_info is null");
949 		return -EINVAL;
950 	}
951 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
952 
953 	if (wmi_extract_mlo_setup_cmpl_event(wmi_handle, event, &params) !=
954 			QDF_STATUS_SUCCESS)
955 		return -EINVAL;
956 
957 	pdev = wlan_objmgr_get_pdev_by_id(psoc, params.pdev_id,
958 					  WLAN_INIT_DEINIT_ID);
959 	if (pdev) {
960 		mlo_link_setup_complete(pdev);
961 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
962 	}
963 
964 	init_deinit_mlo_setup_done_event(psoc);
965 
966 	return 0;
967 }
968 
969 static int init_deinit_mlo_teardown_comp_event_handler(ol_scn_t scn_handle,
970 						       uint8_t *event,
971 						       uint32_t data_len)
972 {
973 	struct wlan_objmgr_psoc *psoc;
974 	struct wlan_objmgr_pdev *pdev;
975 	struct target_psoc_info *tgt_hdl;
976 	struct wmi_unified *wmi_handle;
977 	struct wmi_mlo_teardown_cmpl_params params;
978 
979 	if (!scn_handle) {
980 		target_if_err("scn handle NULL");
981 		return -EINVAL;
982 	}
983 
984 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
985 	if (!psoc) {
986 		target_if_err("psoc is null");
987 		return -EINVAL;
988 	}
989 
990 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
991 	if (!tgt_hdl) {
992 		target_if_err("target_psoc_info is null");
993 		return -EINVAL;
994 	}
995 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
996 
997 	if (wmi_extract_mlo_teardown_cmpl_event(wmi_handle, event, &params) !=
998 			QDF_STATUS_SUCCESS)
999 		return -EINVAL;
1000 
1001 	pdev = wlan_objmgr_get_pdev_by_id(psoc, params.pdev_id,
1002 					  WLAN_INIT_DEINIT_ID);
1003 	if (pdev) {
1004 		mlo_link_teardown_complete(pdev);
1005 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
1006 	}
1007 
1008 	return 0;
1009 }
1010 
1011 static QDF_STATUS init_deinit_register_mlo_ev_handlers(wmi_unified_t wmi_handle)
1012 {
1013 	wmi_unified_register_event(wmi_handle,
1014 				   wmi_mlo_setup_complete_event_id,
1015 				   init_deinit_mlo_setup_comp_event_handler);
1016 	wmi_unified_register_event(wmi_handle,
1017 				   wmi_mlo_teardown_complete_event_id,
1018 				   init_deinit_mlo_teardown_comp_event_handler);
1019 
1020 	return QDF_STATUS_SUCCESS;
1021 }
1022 #else
1023 static QDF_STATUS init_deinit_register_mlo_ev_handlers(wmi_unified_t wmi_handle)
1024 {
1025 	return QDF_STATUS_SUCCESS;
1026 }
1027 #endif /*WLAN_FEATURE_11BE_MLO && WLAN_MLO_MULTI_CHIP*/
1028 
1029 QDF_STATUS init_deinit_register_tgt_psoc_ev_handlers(
1030 				struct wlan_objmgr_psoc *psoc)
1031 {
1032 	struct target_psoc_info *tgt_hdl;
1033 	wmi_unified_t wmi_handle;
1034 	QDF_STATUS retval = QDF_STATUS_SUCCESS;
1035 
1036 	if (!psoc) {
1037 		target_if_err("psoc is null in register wmi handler");
1038 		return QDF_STATUS_E_FAILURE;
1039 	}
1040 
1041 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
1042 	if (!tgt_hdl) {
1043 		target_if_err("target_psoc_info null in register wmi hadler");
1044 		return QDF_STATUS_E_FAILURE;
1045 	}
1046 
1047 	wmi_handle = (wmi_unified_t)target_psoc_get_wmi_hdl(tgt_hdl);
1048 
1049 	retval = wmi_unified_register_event_handler(wmi_handle,
1050 				wmi_service_ready_event_id,
1051 				init_deinit_service_ready_event_handler,
1052 				WMI_RX_WORK_CTX);
1053 	retval = wmi_unified_register_event_handler(wmi_handle,
1054 				wmi_service_ready_ext_event_id,
1055 				init_deinit_service_ext_ready_event_handler,
1056 				WMI_RX_WORK_CTX);
1057 	retval = wmi_unified_register_event_handler(wmi_handle,
1058 				wmi_service_available_event_id,
1059 				init_deinit_service_available_handler,
1060 				WMI_RX_UMAC_CTX);
1061 	retval = wmi_unified_register_event_handler(wmi_handle,
1062 				wmi_ready_event_id,
1063 				init_deinit_ready_event_handler,
1064 				WMI_RX_WORK_CTX);
1065 	retval = wmi_unified_register_event_handler(
1066 				wmi_handle,
1067 				wmi_service_ready_ext2_event_id,
1068 				init_deinit_service_ext2_ready_event_handler,
1069 				WMI_RX_WORK_CTX);
1070 	retval = init_deinit_register_mlo_ev_handlers(wmi_handle);
1071 
1072 
1073 	return retval;
1074 }
1075 
1076