1 /*
2  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 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 #ifdef DP_TX_PACKET_INSPECT_FOR_ILP
37 #include <cdp_txrx_misc.h>
38 #endif
39 #include <wlan_reg_ucfg_api.h>
40 #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
41 #include <wlan_mlo_mgr_cmn.h>
42 #include <wlan_mlo_mgr_ap.h>
43 #include <wlan_mlo_mgr_setup.h>
44 #endif
45 #include <target_if_twt.h>
46 #include <target_if_scan.h>
47 
init_deinit_set_send_init_cmd(struct wlan_objmgr_psoc * psoc,struct target_psoc_info * tgt_hdl)48 static void init_deinit_set_send_init_cmd(struct wlan_objmgr_psoc *psoc,
49 					  struct target_psoc_info *tgt_hdl)
50 {
51 	tgt_hdl->info.wmi_service_ready = TRUE;
52 	/* send init command */
53 	init_deinit_prepare_send_init_cmd(psoc, tgt_hdl);
54 }
55 
56 #ifdef WLAN_FEATURE_P2P_P2P_STA
57 static void
init_deinit_update_p2p_p2p_conc_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)58 init_deinit_update_p2p_p2p_conc_support(struct wmi_unified *wmi_handle,
59 					struct wlan_objmgr_psoc *psoc)
60 {
61 	if (wmi_service_enabled(wmi_handle, wmi_service_p2p_p2p_cc_support))
62 		wlan_psoc_nif_fw_ext_cap_set(psoc,
63 					     WLAN_SOC_EXT_P2P_P2P_CONC_SUPPORT);
64 	else
65 		target_if_debug("P2P + P2P conc disabled");
66 }
67 #else
68 static inline void
init_deinit_update_p2p_p2p_conc_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)69 init_deinit_update_p2p_p2p_conc_support(struct wmi_unified *wmi_handle,
70 					struct wlan_objmgr_psoc *psoc)
71 {}
72 #endif
73 
74 #ifdef QCA_RSSI_DB2DBM
75 static void
init_deinit_update_rssi_dbm_conv_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)76 init_deinit_update_rssi_dbm_conv_support(struct wmi_unified *wmi_handle,
77 					 struct wlan_objmgr_psoc *psoc)
78 {
79 	/* Send RSSI_DBM_CONV to DP layer */
80 	if (wmi_service_enabled(wmi_handle,
81 				wmi_service_pdev_rssi_dbm_conv_event_support))
82 		cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
83 				  DP_SOC_PARAM_RSSI_DBM_CONV_SUPPORT, 1);
84 }
85 #else
86 static inline void
init_deinit_update_rssi_dbm_conv_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)87 init_deinit_update_rssi_dbm_conv_support(struct wmi_unified *wmi_handle,
88 					 struct wlan_objmgr_psoc *psoc)
89 {}
90 #endif
91 
92 #ifdef WIFI_POS_CONVERGED
93 static inline void
init_deinit_update_wifi_pos_caps(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)94 init_deinit_update_wifi_pos_caps(struct wmi_unified *wmi_handle,
95 				 struct wlan_objmgr_psoc *psoc)
96 {
97 	if (wmi_service_enabled(wmi_handle, wmi_service_rtt_11az_ntb_support))
98 		wlan_psoc_nif_fw_ext_cap_set(psoc,
99 					     WLAN_RTT_11AZ_NTB_SUPPORT);
100 
101 	if (wmi_service_enabled(wmi_handle, wmi_service_rtt_11az_tb_support))
102 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
103 					      WLAN_RTT_11AZ_TB_SUPPORT);
104 
105 	if (wmi_service_enabled(wmi_handle,
106 				wmi_service_rtt_11az_tb_rsta_support))
107 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
108 					      WLAN_RTT_11AZ_TB_RSTA_SUPPORT);
109 
110 	if (wmi_service_enabled(wmi_handle,
111 				wmi_service_rtt_11az_mac_sec_support))
112 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
113 					      WLAN_RTT_11AZ_MAC_SEC_SUPPORT);
114 
115 	if (wmi_service_enabled(wmi_handle,
116 				wmi_service_rtt_11az_mac_phy_sec_support))
117 		wlan_psoc_nif_fw_ext2_cap_set(
118 				psoc, WLAN_RTT_11AZ_MAC_PHY_SEC_SUPPORT);
119 }
120 #else
121 static inline void
init_deinit_update_wifi_pos_caps(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)122 init_deinit_update_wifi_pos_caps(struct wmi_unified *wmi_handle,
123 				 struct wlan_objmgr_psoc *psoc)
124 {}
125 #endif
126 
127 #ifdef WLAN_FEATURE_ROAM_OFFLOAD
128 static void
init_deinit_update_roam_stats_cap(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)129 init_deinit_update_roam_stats_cap(struct wmi_unified *wmi_handle,
130 				  struct wlan_objmgr_psoc *psoc)
131 {
132 	if (wmi_service_enabled(wmi_handle,
133 				wmi_service_roam_stats_per_candidate_frame_info))
134 		wlan_psoc_nif_fw_ext2_cap_set(
135 			psoc, WLAN_ROAM_STATS_FRAME_INFO_PER_CANDIDATE);
136 }
137 #else
138 static inline void
init_deinit_update_roam_stats_cap(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)139 init_deinit_update_roam_stats_cap(struct wmi_unified *wmi_handle,
140 				  struct wlan_objmgr_psoc *psoc)
141 {}
142 #endif
143 
144 #ifdef DP_TX_PACKET_INSPECT_FOR_ILP
145 static void
init_deinit_update_tx_ilp_cap(struct wlan_objmgr_psoc * psoc,struct tgt_info * info)146 init_deinit_update_tx_ilp_cap(struct wlan_objmgr_psoc *psoc,
147 			      struct tgt_info *info)
148 {
149 	ol_txrx_soc_handle soc;
150 
151 	soc = wlan_psoc_get_dp_handle(psoc);
152 	info->wlan_res_cfg.tx_ilp_enable =
153 		cdp_evaluate_update_tx_ilp_cfg(
154 			soc, info->service_ext2_param.num_msdu_idx_qtype_map,
155 			info->msdu_idx_qtype_map);
156 }
157 #else
158 static void
init_deinit_update_tx_ilp_cap(struct wlan_objmgr_psoc * psoc,struct tgt_info * info)159 init_deinit_update_tx_ilp_cap(struct wlan_objmgr_psoc *psoc,
160 			      struct tgt_info *info)
161 {
162 }
163 #endif
164 
165 #ifdef MULTI_CLIENT_LL_SUPPORT
166 /**
167  * init_deinit_update_multi_client_ll_caps() - Update multi client service
168  * capability bit
169  * @wmi_handle: wmi handle
170  * @psoc: psoc common object
171  *
172  * Return: none
173  */
174 static void
init_deinit_update_multi_client_ll_caps(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)175 init_deinit_update_multi_client_ll_caps(struct wmi_unified *wmi_handle,
176 					struct wlan_objmgr_psoc *psoc)
177 {
178 	if (wmi_service_enabled(wmi_handle,
179 				wmi_service_configure_multi_client_ll_support))
180 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
181 					WLAN_SOC_WLM_MULTI_CLIENT_LL_SUPPORT);
182 }
183 #else
184 static inline void
init_deinit_update_multi_client_ll_caps(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)185 init_deinit_update_multi_client_ll_caps(struct wmi_unified *wmi_handle,
186 					struct wlan_objmgr_psoc *psoc)
187 {}
188 #endif
189 
190 #ifdef WLAN_VENDOR_HANDOFF_CONTROL
191 /**
192  * init_deinit_update_vendor_handoff_control_caps() - Update vendor handoff
193  * control service capability bit
194  * @wmi_handle: wmi handle
195  * @psoc: psoc common object
196  *
197  * Return: none
198  */
199 static void
init_deinit_update_vendor_handoff_control_caps(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)200 init_deinit_update_vendor_handoff_control_caps(struct wmi_unified *wmi_handle,
201 					       struct wlan_objmgr_psoc *psoc)
202 {
203 	if (wmi_service_enabled(wmi_handle,
204 			wmi_service_configure_vendor_handoff_control_support))
205 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
206 					      WLAN_SOC_VENDOR_HANDOFF_CONTROL);
207 }
208 #else
209 static inline void
init_deinit_update_vendor_handoff_control_caps(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)210 init_deinit_update_vendor_handoff_control_caps(struct wmi_unified *wmi_handle,
211 					       struct wlan_objmgr_psoc *psoc)
212 {}
213 #endif
214 
215 #ifdef FEATURE_WLAN_TDLS
init_deinit_update_tdls_caps(struct wmi_unified * wmi,struct wlan_objmgr_psoc * psoc)216 static void init_deinit_update_tdls_caps(struct wmi_unified *wmi,
217 					 struct wlan_objmgr_psoc *psoc)
218 {
219 	if (wmi_service_enabled(wmi, wmi_service_tdls_concurrency_support))
220 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
221 					      WLAN_TDLS_CONCURRENCIES_SUPPORT);
222 }
223 #else
init_deinit_update_tdls_caps(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)224 static inline void init_deinit_update_tdls_caps(struct wmi_unified *wmi_handle,
225 						struct wlan_objmgr_psoc *psoc)
226 {}
227 #endif
228 static void
229 init_deinit_pdev_wsi_stats_info_support(struct wmi_unified *wmi_handle,
230 					struct wlan_objmgr_psoc *psoc);
231 
232 static void init_deinit_mlo_tsf_sync_support(struct wmi_unified *wmi_handle,
233 					     struct wlan_objmgr_psoc *psoc);
234 
init_deinit_service_ready_event_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)235 static int init_deinit_service_ready_event_handler(ol_scn_t scn_handle,
236 							uint8_t *event,
237 							uint32_t data_len)
238 {
239 	int err_code;
240 	struct wlan_objmgr_psoc *psoc;
241 	struct target_psoc_info *tgt_hdl;
242 	wmi_legacy_service_ready_callback legacy_callback;
243 	struct wmi_unified *wmi_handle;
244 	QDF_STATUS ret_val;
245 
246 	if (!scn_handle) {
247 		target_if_err("scn handle NULL in service ready handler");
248 		return -EINVAL;
249 	}
250 
251 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
252 	if (!psoc) {
253 		target_if_err("psoc is null in service ready handler");
254 		return -EINVAL;
255 	}
256 
257 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
258 	if (!tgt_hdl) {
259 		target_if_err("target_psoc_info is null in service ready ev");
260 		return -EINVAL;
261 	}
262 
263 	ret_val = target_if_sw_version_check(psoc, tgt_hdl, event);
264 
265 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
266 
267 	err_code = init_deinit_populate_service_bitmap(wmi_handle, event,
268 			tgt_hdl->info.service_bitmap);
269 	if (err_code)
270 		goto exit;
271 
272 	err_code = init_deinit_populate_fw_version_cmd(wmi_handle, event);
273 	if (err_code)
274 		goto exit;
275 
276 	err_code = init_deinit_populate_target_cap(wmi_handle, event,
277 				   &(tgt_hdl->info.target_caps));
278 	if (err_code)
279 		goto exit;
280 
281 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle, event,
282 				    &(tgt_hdl->info), true);
283 	if (err_code)
284 		goto exit;
285 
286 	if (init_deinit_validate_160_80p80_fw_caps(psoc, tgt_hdl) !=
287 			QDF_STATUS_SUCCESS) {
288 		wlan_psoc_nif_op_flag_set(psoc, WLAN_SOC_OP_VHT_INVALID_CAP);
289 	}
290 
291 	if (wmi_service_enabled(wmi_handle, wmi_service_tt) ||
292 	    wmi_service_enabled(wmi_handle, wmi_service_thermal_mgmt))
293 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TT_SUPPORT);
294 
295 	if (wmi_service_enabled(wmi_handle, wmi_service_widebw_scan))
296 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN);
297 
298 	if (wmi_service_enabled(wmi_handle, wmi_service_check_cal_version))
299 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_SW_CAL);
300 
301 	if (wmi_service_enabled(wmi_handle, wmi_service_twt_requestor))
302 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TWT_REQUESTER);
303 
304 	if (wmi_service_enabled(wmi_handle, wmi_service_twt_responder))
305 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_TWT_RESPONDER);
306 
307 	if (wmi_service_enabled(wmi_handle, wmi_service_bss_color_offload))
308 		target_if_debug(" BSS COLOR OFFLOAD supported");
309 
310 	if (wmi_service_enabled(wmi_handle, wmi_service_ul_ru26_allowed))
311 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_OBSS_NBW_RU);
312 
313 	if (wmi_service_enabled(wmi_handle, wmi_service_infra_mbssid))
314 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_MBSS_IE);
315 
316 	if (wmi_service_enabled(wmi_handle,
317 				wmi_service_mbss_param_in_vdev_start_support))
318 		wlan_psoc_nif_fw_ext_cap_set(psoc,
319 					     WLAN_SOC_CEXT_MBSS_PARAM_IN_START);
320 
321 	if (wmi_service_enabled(wmi_handle, wmi_service_dynamic_hw_mode))
322 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_DYNAMIC_HW_MODE);
323 
324 	if (wmi_service_enabled(wmi_handle,
325 				wmi_service_bw_restricted_80p80_support))
326 		wlan_psoc_nif_fw_ext_cap_set(psoc,
327 					     WLAN_SOC_RESTRICTED_80P80_SUPPORT);
328 
329 	if (wmi_service_enabled(wmi_handle,
330 				wmi_service_nss_ratio_to_host_support))
331 		wlan_psoc_nif_fw_ext_cap_set(
332 				psoc, WLAN_SOC_NSS_RATIO_TO_HOST_SUPPORT);
333 
334 	if (wmi_service_enabled(wmi_handle,
335 				wmi_service_rtt_ap_initiator_staggered_mode_supported))
336 		wlan_psoc_nif_fw_ext_cap_set(
337 				psoc, WLAN_SOC_RTT_AP_INITIATOR_STAGGERED_MODE_SUPPORTED);
338 
339 	if (wmi_service_enabled(wmi_handle,
340 				wmi_service_rtt_ap_initiator_bursted_mode_supported))
341 		wlan_psoc_nif_fw_ext_cap_set(
342 				psoc, WLAN_SOC_RTT_AP_INITIATOR_BURSTED_MODE_SUPPORTED);
343 
344 	target_if_debug(" TT support %d, Wide BW Scan %d, SW cal %d",
345 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_TT_SUPPORT),
346 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_WIDEBAND_SCAN),
347 		wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_SOC_CEXT_SW_CAL));
348 
349 	target_if_mesh_support_enable(psoc, tgt_hdl, event);
350 
351 	target_if_eapol_minrate_enable(psoc, tgt_hdl, event);
352 
353 	target_if_smart_antenna_enable(psoc, tgt_hdl, event);
354 
355 	target_if_cfr_support_enable(psoc, tgt_hdl, event);
356 
357 	target_if_peer_cfg_enable(psoc, tgt_hdl, event);
358 
359 	target_if_atf_cfg_enable(psoc, tgt_hdl, event);
360 
361 	if (wmi_service_enabled(wmi_handle,
362 				wmi_service_mgmt_rx_reo_supported))
363 		wlan_psoc_nif_feat_cap_set(psoc,
364 					   WLAN_SOC_F_MGMT_RX_REO_CAPABLE);
365 
366 	target_if_lteu_cfg_enable(psoc, tgt_hdl, event);
367 
368 	if (wmi_service_enabled(wmi_handle, wmi_service_rx_fse_support))
369 		wlan_psoc_nif_fw_ext_cap_set(psoc,
370 					     WLAN_SOC_CEXT_RX_FSE_SUPPORT);
371 
372 	if (wmi_service_enabled(wmi_handle,
373 				wmi_service_scan_conf_per_ch_support))
374 		wlan_psoc_nif_fw_ext_cap_set(psoc,
375 					     WLAN_SOC_CEXT_SCAN_PER_CH_CONFIG);
376 
377 	if (wmi_service_enabled(wmi_handle,
378 				wmi_service_pno_scan_conf_per_ch_support))
379 		wlan_psoc_nif_fw_ext_cap_set(psoc,
380 					WLAN_SOC_PNO_SCAN_CONFIG_PER_CHANNEL);
381 
382 	if (wmi_service_enabled(wmi_handle, wmi_service_csa_beacon_template))
383 		wlan_psoc_nif_fw_ext_cap_set(psoc,
384 					     WLAN_SOC_CEXT_CSA_TX_OFFLOAD);
385 
386 	init_deinit_update_roam_stats_cap(wmi_handle, psoc);
387 
388 	init_deinit_update_wifi_pos_caps(wmi_handle, psoc);
389 	init_deinit_update_tdls_caps(wmi_handle, psoc);
390 
391 	init_deinit_pdev_wsi_stats_info_support(wmi_handle, psoc);
392 
393 	init_deinit_mlo_tsf_sync_support(wmi_handle, psoc);
394 
395 	/* override derived value, if it exceeds max peer count */
396 	if ((wlan_psoc_get_max_peer_count(psoc) >
397 		tgt_hdl->info.wlan_res_cfg.num_active_peers) &&
398 		(wlan_psoc_get_max_peer_count(psoc) <
399 			(tgt_hdl->info.wlan_res_cfg.num_peers -
400 				tgt_hdl->info.wlan_res_cfg.num_vdevs))) {
401 		tgt_hdl->info.wlan_res_cfg.num_peers =
402 				wlan_psoc_get_max_peer_count(psoc) +
403 					tgt_hdl->info.wlan_res_cfg.num_vdevs;
404 	}
405 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
406 	if (!legacy_callback) {
407 		err_code = -EINVAL;
408 		goto exit;
409 	}
410 
411 	err_code = legacy_callback(wmi_service_ready_event_id,
412 				  scn_handle, event, data_len);
413 	init_deinit_chainmask_config(psoc, tgt_hdl);
414 
415 	if (wmi_service_enabled(wmi_handle, wmi_service_mgmt_tx_wmi)) {
416 		wlan_psoc_nif_fw_ext_cap_set(psoc, WLAN_SOC_CEXT_WMI_MGMT_REF);
417 		target_if_debug("WMI mgmt service enabled");
418 	} else {
419 		wlan_psoc_nif_fw_ext_cap_clear(psoc,
420 					       WLAN_SOC_CEXT_WMI_MGMT_REF);
421 		target_if_debug("WMI mgmt service disabled");
422 	}
423 	init_deinit_update_p2p_p2p_conc_support(wmi_handle, psoc);
424 
425 	err_code = init_deinit_handle_host_mem_req(psoc, tgt_hdl, event);
426 	if (err_code != QDF_STATUS_SUCCESS)
427 		goto exit;
428 
429 	target_if_reg_set_offloaded_info(psoc);
430 	target_if_reg_set_6ghz_info(psoc);
431 	target_if_reg_set_5dot9_ghz_info(psoc);
432 	target_if_twt_fill_tgt_caps(psoc, wmi_handle);
433 	target_if_update_aux_support(psoc);
434 
435 	/* Send num_msdu_desc to DP layer */
436 	cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
437 			  DP_SOC_PARAM_MSDU_EXCEPTION_DESC,
438 			  tgt_hdl->info.target_caps.num_msdu_desc);
439 
440 	/* Send multi_peer_group support to DP layer */
441 	if (wmi_service_enabled(wmi_handle,
442 				wmi_service_multi_peer_group_cmd_support))
443 		cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
444 				  DP_SOC_PARAM_MULTI_PEER_GRP_CMD_SUPPORT, 1);
445 
446 	/* Send UMAC HW reset support to DP layer */
447 	if (wmi_service_enabled(wmi_handle,
448 				wmi_service_umac_hang_recovery_support))
449 		cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
450 				  DP_SOC_PARAM_UMAC_HW_RESET_SUPPORT, 1);
451 
452 	if (wmi_service_enabled(wmi_handle, wmi_service_vdev_delete_all_peer))
453 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
454 					      WLAN_VDEV_DELETE_ALL_PEER_SUPPORT);
455 
456 	init_deinit_update_rssi_dbm_conv_support(wmi_handle, psoc);
457 
458 	init_deinit_update_multi_client_ll_caps(wmi_handle, psoc);
459 
460 	init_deinit_update_vendor_handoff_control_caps(wmi_handle, psoc);
461 
462 	if (wmi_service_enabled(wmi_handle,
463 				wmi_service_cca_busy_info_for_each_20mhz))
464 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
465 					WLAN_CCA_BUSY_INFO_FOREACH_20MHZ);
466 	if (wmi_service_enabled(wmi_handle,
467 			wmi_service_vdev_param_chwidth_with_notify_support))
468 		wlan_psoc_nif_fw_ext2_cap_set(psoc,
469 				WLAN_VDEV_PARAM_CHWIDTH_WITH_NOTIFY_SUPPORT);
470 
471 	if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
472 		target_if_debug("Wait for EXT message");
473 	} else {
474 		target_if_debug("No EXT message, send init command");
475 		target_psoc_set_num_radios(tgt_hdl, 1);
476 		init_deinit_set_send_init_cmd(psoc, tgt_hdl);
477 	}
478 
479 	if (wmi_service_enabled(wmi_handle,
480 			wmi_service_multiple_reorder_queue_setup_support))
481 		cdp_soc_set_param(wlan_psoc_get_dp_handle(psoc),
482 			DP_SOC_PARAM_MULTI_RX_REORDER_SETUP_SUPPORT, 1);
483 
484 exit:
485 	return err_code;
486 }
487 
init_deinit_service_ext2_ready_event_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)488 static int init_deinit_service_ext2_ready_event_handler(ol_scn_t scn_handle,
489 							uint8_t *event,
490 							uint32_t data_len)
491 {
492 	int err_code = 0;
493 	struct wlan_objmgr_psoc *psoc;
494 	struct target_psoc_info *tgt_hdl;
495 	struct wmi_unified *wmi_handle;
496 	struct tgt_info *info;
497 	wmi_legacy_service_ready_callback legacy_callback;
498 
499 	if (!scn_handle) {
500 		target_if_err("scn handle NULL in service ready ext2 handler");
501 		return -EINVAL;
502 	}
503 
504 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
505 	if (!psoc) {
506 		target_if_err("psoc is null in service ready ext2 handler");
507 		return -EINVAL;
508 	}
509 
510 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
511 	if (!tgt_hdl) {
512 		target_if_err("target_psoc_info is null in service ready ext2 handler");
513 		return -EINVAL;
514 	}
515 
516 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
517 	if (!wmi_handle) {
518 		target_if_err("wmi_handle is null in service ready ext2 handler");
519 		return -EINVAL;
520 	}
521 
522 	info = (&tgt_hdl->info);
523 	if (info->wmi_service_status ==
524 			wmi_init_ext_processing_failed)
525 		return -EINVAL;
526 
527 	err_code = init_deinit_populate_service_ready_ext2_param(wmi_handle,
528 								 event, info);
529 	if (err_code)
530 		goto exit;
531 
532 	if (wmi_service_enabled(wmi_handle,
533 				wmi_service_reg_cc_ext_event_support)) {
534 		target_if_set_reg_cc_ext_supp(tgt_hdl, psoc);
535 		wlan_psoc_nif_fw_ext_cap_set(psoc,
536 					     WLAN_SOC_EXT_EVENT_SUPPORTED);
537 	}
538 
539 	if (wmi_service_enabled(wmi_handle,
540 				wmi_service_bang_radar_320_support)) {
541 		info->wlan_res_cfg.is_host_dfs_320mhz_bangradar_supported =
542 									   true;
543 	}
544 
545 	/* dbr_ring_caps could have already come as part of EXT event */
546 	if (info->service_ext2_param.num_dbr_ring_caps) {
547 		err_code = init_deinit_populate_dbr_ring_cap_ext2(psoc,
548 								  wmi_handle,
549 								  event, info);
550 		if (err_code)
551 			goto exit;
552 	}
553 
554 	err_code = init_deinit_populate_hal_reg_cap_ext2(wmi_handle, event,
555 							 info);
556 	if (err_code) {
557 		target_if_err("failed to populate hal reg cap ext2");
558 		goto exit;
559 	}
560 
561 	err_code = init_deinit_populate_mac_phy_cap_ext2(wmi_handle, event,
562 							 info);
563 	if (err_code) {
564 		target_if_err("failed to populate mac phy cap ext2");
565 		goto exit;
566 	}
567 
568 	target_if_add_11ax_modes(psoc, tgt_hdl);
569 
570 	err_code = init_deinit_populate_scan_radio_cap_ext2(wmi_handle, event,
571 							    info);
572 	if (err_code) {
573 		target_if_err("failed to populate scan radio cap ext2");
574 		goto exit;
575 	}
576 
577 	err_code = init_deinit_populate_msdu_idx_qtype_map_ext2(wmi_handle,
578 								event, info);
579 
580 	if (err_code) {
581 		target_if_err("failed to populate msdu index qtype map ext2");
582 		goto exit;
583 	}
584 
585 	init_deinit_update_tx_ilp_cap(psoc, info);
586 
587 	err_code = init_deinit_populate_twt_cap_ext2(psoc, wmi_handle, event,
588 						     info);
589 
590 	if (err_code)
591 		target_if_debug("failed to populate twt cap ext2");
592 
593 	err_code = init_deinit_populate_dbs_or_sbs_cap_ext2(psoc, wmi_handle,
594 							    event, info);
595 	if (err_code)
596 		target_if_debug("failed to populate dbs_or_sbs cap ext2");
597 
598 	err_code = init_deinit_populate_sap_coex_capability(psoc, wmi_handle,
599 							    event);
600 	if (err_code)
601 		target_if_debug("failed to populate sap_coex_capability ext2");
602 
603 	if (info->service_ext2_param.num_aux_dev_caps) {
604 		err_code = init_deinit_populate_aux_dev_cap_ext2(psoc,
605 								 wmi_handle,
606 								 event, info);
607 		if (err_code)
608 			target_if_debug("failed to populate aux_dev cap ext2");
609 	}
610 
611 	if (wmi_service_enabled(wmi_handle,
612 				wmi_service_aoa_for_rcc_supported)) {
613 		err_code = init_deinit_populate_rcc_aoa_cap_ext2(psoc,
614 								 wmi_handle,
615 								 event, info);
616 		if (err_code)
617 			target_if_debug("failed to populate aoa cap ext2");
618 	}
619 
620 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
621 	if (legacy_callback)
622 		if (legacy_callback(wmi_service_ready_ext2_event_id,
623 				    scn_handle, event, data_len)) {
624 			target_if_err("Legacy callback return error!");
625 			goto exit;
626 		}
627 
628 	if (wmi_service_enabled(wmi_handle, wmi_service_radar_flags_support)) {
629 		target_if_debug("Full bw nol supported");
630 		info->wlan_res_cfg.is_full_bw_nol_supported = true;
631 	}
632 
633 	target_if_regulatory_set_ext_tpc(psoc);
634 
635 	target_if_reg_set_lower_6g_edge_ch_info(psoc);
636 
637 	target_if_reg_set_disable_upper_6g_edge_ch_info(psoc);
638 
639 	target_if_reg_set_afc_dev_type(psoc, tgt_hdl);
640 
641 	target_if_set_regulatory_eirp_preferred_support(psoc);
642 
643 	tgt_if_set_reg_afc_configure(tgt_hdl, psoc);
644 
645 	/* send init command */
646 	init_deinit_set_send_init_cmd(psoc, tgt_hdl);
647 
648 	return 0;
649 exit:
650 	info->wmi_ready = false;
651 	info->wmi_service_status = wmi_init_ext2_processing_failed;
652 	return err_code;
653 }
654 
init_deinit_service_ext_ready_event_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)655 static int init_deinit_service_ext_ready_event_handler(ol_scn_t scn_handle,
656 						uint8_t *event,
657 						uint32_t data_len)
658 {
659 	int err_code;
660 	uint8_t num_radios;
661 	struct wlan_objmgr_psoc *psoc;
662 	struct target_psoc_info *tgt_hdl;
663 	struct wmi_unified *wmi_handle;
664 	struct tgt_info *info;
665 	wmi_legacy_service_ready_callback legacy_callback;
666 
667 	if (!scn_handle) {
668 		target_if_err("scn handle NULL in service ready handler");
669 		return -EINVAL;
670 	}
671 
672 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
673 	if (!psoc) {
674 		target_if_err("psoc is null in service ready handler");
675 		return -EINVAL;
676 	}
677 
678 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
679 	if (!tgt_hdl) {
680 		target_if_err("target_psoc_info is null in service ready ev");
681 		return -EINVAL;
682 	}
683 
684 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
685 	info = (&tgt_hdl->info);
686 
687 	err_code = init_deinit_populate_service_ready_ext_param(wmi_handle,
688 				event, &(info->service_ext_param));
689 	if (err_code)
690 		goto exit;
691 
692 	target_psoc_set_num_radios(tgt_hdl, 0);
693 	err_code =  init_deinit_populate_hw_mode_capability(wmi_handle,
694 					    event, tgt_hdl);
695 	if (err_code)
696 		goto exit;
697 
698 	if (init_deinit_is_preferred_hw_mode_supported(psoc, tgt_hdl)
699 			== FALSE) {
700 		target_if_err("Preferred mode %d not supported",
701 			      info->preferred_hw_mode);
702 		goto exit;
703 	}
704 
705 	num_radios = target_psoc_get_num_radios_for_mode(tgt_hdl,
706 							 info->preferred_hw_mode);
707 
708 	/* set number of radios based on current mode */
709 	target_psoc_set_num_radios(tgt_hdl, num_radios);
710 
711 	target_if_print_service_ready_ext_param(psoc, tgt_hdl);
712 
713 	err_code = init_deinit_populate_phy_reg_cap(psoc, wmi_handle,
714 					   event, info, false);
715 	if (err_code)
716 		goto exit;
717 
718 	/* Host receives 11AX wireless modes from target in service ext2
719 	 * message. Therefore, call target_if_add_11ax_modes() from service ext2
720 	 * event handler as well.
721 	 */
722 	if (!wmi_service_enabled(wmi_handle, wmi_service_ext2_msg))
723 		target_if_add_11ax_modes(psoc, tgt_hdl);
724 
725 	if (init_deinit_chainmask_table_alloc(
726 				&(info->service_ext_param)) ==
727 							QDF_STATUS_SUCCESS) {
728 		err_code = init_deinit_populate_chainmask_tables(wmi_handle,
729 				event,
730 				&(info->service_ext_param.chainmask_table[0]));
731 		if (err_code)
732 			goto exit;
733 	}
734 
735 	/* dbr_ring_caps can be absent if enough space is not available */
736 	if (info->service_ext_param.num_dbr_ring_caps) {
737 		err_code = init_deinit_populate_dbr_ring_cap(psoc, wmi_handle,
738 							     event, info);
739 		if (err_code)
740 			goto exit;
741 	}
742 
743 	err_code = init_deinit_populate_spectral_bin_scale_params(psoc,
744 								  wmi_handle,
745 								  event, info);
746 	if (err_code)
747 		goto exit;
748 
749 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
750 	if (legacy_callback) {
751 		if (legacy_callback(wmi_service_ready_ext_event_id,
752 				    scn_handle, event, data_len)) {
753 			target_if_err("Error Code %d", err_code);
754 			goto exit;
755 		}
756 	}
757 
758 	target_if_set_twt_ap_pdev_count(info, tgt_hdl);
759 
760 	info->wlan_res_cfg.max_bssid_indicator =
761 				info->service_ext_param.max_bssid_indicator;
762 
763 	if (wmi_service_enabled(wmi_handle, wmi_service_ext2_msg)) {
764 		target_if_debug("Wait for EXT2 message");
765 	} else {
766 		target_if_debug("No EXT2 message, send init command");
767 		init_deinit_set_send_init_cmd(psoc, tgt_hdl);
768 	}
769 
770 	return 0;
771 exit:
772 	info->wmi_ready = false;
773 	info->wmi_service_status = wmi_init_ext_processing_failed;
774 	init_deinit_wakeup_host_wait(psoc, tgt_hdl);
775 	return err_code;
776 }
777 
init_deinit_service_available_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)778 static int init_deinit_service_available_handler(ol_scn_t scn_handle,
779 						uint8_t *event,
780 						uint32_t data_len)
781 {
782 	struct wlan_objmgr_psoc *psoc;
783 	struct target_psoc_info *tgt_hdl;
784 	struct wmi_unified *wmi_handle;
785 
786 	if (!scn_handle) {
787 		target_if_err("scn handle NULL");
788 		return -EINVAL;
789 	}
790 
791 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
792 	if (!psoc) {
793 		target_if_err("psoc is null");
794 		return -EINVAL;
795 	}
796 
797 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
798 	if (!tgt_hdl) {
799 		target_if_err("target_psoc_info is null");
800 		return -EINVAL;
801 	}
802 
803 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
804 
805 	if (wmi_save_ext_service_bitmap(wmi_handle, event, NULL) !=
806 					QDF_STATUS_SUCCESS) {
807 		target_if_err("Failed to save ext service bitmap");
808 		return -EINVAL;
809 	}
810 
811 	return 0;
812 }
813 
814 #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
init_deinit_mlo_capable(struct wlan_objmgr_psoc * psoc)815 static bool init_deinit_mlo_capable(struct wlan_objmgr_psoc *psoc)
816 {
817 	struct target_psoc_info *tgt_hdl;
818 
819 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
820 	if (!tgt_hdl) {
821 		target_if_err("target_psoc_info is null");
822 		return false;
823 	}
824 
825 	if ((tgt_hdl->tif_ops) &&
826 	    (tgt_hdl->tif_ops->mlo_capable))
827 		return tgt_hdl->tif_ops->mlo_capable(psoc);
828 
829 	return false;
830 }
831 
init_deinit_mlo_get_group_id(struct wlan_objmgr_psoc * psoc,uint8_t * grp_id)832 static bool init_deinit_mlo_get_group_id(struct wlan_objmgr_psoc *psoc,
833 					 uint8_t *grp_id)
834 {
835 	struct target_psoc_info *tgt_hdl;
836 
837 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
838 	if (!tgt_hdl) {
839 		target_if_err("target_psoc_info is null");
840 		return false;
841 	}
842 
843 	if ((tgt_hdl->tif_ops) &&
844 	    (tgt_hdl->tif_ops->mlo_get_group_id)) {
845 		*grp_id = tgt_hdl->tif_ops->mlo_get_group_id(psoc);
846 		return true;
847 	}
848 
849 	return false;
850 }
851 
init_deinit_mlo_update_soc_ready(struct wlan_objmgr_psoc * psoc)852 static void init_deinit_mlo_update_soc_ready(struct wlan_objmgr_psoc *psoc)
853 {
854 	uint8_t grp_id = 0;
855 
856 	if (init_deinit_mlo_capable(psoc)) {
857 		if (!init_deinit_mlo_get_group_id(psoc, &grp_id)) {
858 			target_if_err("Invalid MLD group id");
859 			return;
860 		}
861 		mlo_setup_update_soc_ready(psoc, grp_id);
862 	}
863 }
864 
init_deinit_send_ml_link_ready(struct wlan_objmgr_psoc * psoc,void * object,void * arg)865 static void init_deinit_send_ml_link_ready(struct wlan_objmgr_psoc *psoc,
866 					   void *object, void *arg)
867 {
868 	struct wlan_objmgr_pdev *pdev = object;
869 	uint8_t grp_id = 0;
870 
871 	if (!init_deinit_mlo_capable(psoc))
872 		return;
873 
874 	qdf_assert_always(psoc);
875 	qdf_assert_always(pdev);
876 
877 	if (!init_deinit_mlo_get_group_id(psoc, &grp_id))
878 		qdf_assert_always(grp_id);
879 
880 	mlo_setup_link_ready(pdev, grp_id);
881 }
882 
init_deinit_mlo_update_pdev_ready(struct wlan_objmgr_psoc * psoc,uint8_t num_radios)883 static void init_deinit_mlo_update_pdev_ready(struct wlan_objmgr_psoc *psoc,
884 					      uint8_t num_radios)
885 {
886 	if (!init_deinit_mlo_capable(psoc))
887 		return;
888 
889 	wlan_objmgr_iterate_obj_list(psoc, WLAN_PDEV_OP,
890 				     init_deinit_send_ml_link_ready,
891 				     NULL, 0, WLAN_INIT_DEINIT_ID);
892 }
893 
894 static void
init_deinit_pdev_wsi_stats_info_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)895 init_deinit_pdev_wsi_stats_info_support(struct wmi_unified *wmi_handle,
896 					struct wlan_objmgr_psoc *psoc)
897 {
898 	bool wsi_stats_info_support = false;
899 
900 	if (!init_deinit_mlo_capable(psoc))
901 		return;
902 
903 	if (wmi_service_enabled(wmi_handle,
904 				wmi_service_pdev_wsi_stats_info_support))
905 		wsi_stats_info_support = true;
906 
907 	mlo_update_wsi_stats_info_support(psoc, wsi_stats_info_support);
908 }
909 
init_deinit_mlo_tsf_sync_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)910 static void init_deinit_mlo_tsf_sync_support(struct wmi_unified *wmi_handle,
911 					     struct wlan_objmgr_psoc *psoc)
912 {
913 	bool mlo_tsf_sync_enab = false;
914 
915 	if (!init_deinit_mlo_capable(psoc))
916 		return;
917 
918 	if (wmi_service_enabled(wmi_handle, wmi_service_mlo_tsf_sync))
919 		mlo_tsf_sync_enab = true;
920 
921 	mlo_update_tsf_sync_support(psoc, mlo_tsf_sync_enab);
922 }
923 
924 #else
init_deinit_mlo_update_soc_ready(struct wlan_objmgr_psoc * psoc)925 static void init_deinit_mlo_update_soc_ready(struct wlan_objmgr_psoc *psoc)
926 {}
init_deinit_mlo_update_pdev_ready(struct wlan_objmgr_psoc * psoc,uint8_t num_radios)927 static void init_deinit_mlo_update_pdev_ready(struct wlan_objmgr_psoc *psoc,
928 					      uint8_t num_radios)
929 {}
930 static void
init_deinit_pdev_wsi_stats_info_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)931 init_deinit_pdev_wsi_stats_info_support(struct wmi_unified *wmi_handle,
932 					struct wlan_objmgr_psoc *psoc)
933 {}
init_deinit_mlo_tsf_sync_support(struct wmi_unified * wmi_handle,struct wlan_objmgr_psoc * psoc)934 static void init_deinit_mlo_tsf_sync_support(struct wmi_unified *wmi_handle,
935 					     struct wlan_objmgr_psoc *psoc)
936 {}
937 #endif /*WLAN_FEATURE_11BE_MLO && WLAN_MLO_MULTI_CHIP*/
938 
939 /* MAC address fourth byte index */
940 #define MAC_BYTE_4 4
941 
init_deinit_ready_event_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)942 static int init_deinit_ready_event_handler(ol_scn_t scn_handle,
943 						uint8_t *event,
944 						uint32_t data_len)
945 {
946 	struct wlan_objmgr_psoc *psoc;
947 	struct wlan_objmgr_pdev *pdev;
948 	struct target_psoc_info *tgt_hdl;
949 	struct wmi_unified *wmi_handle;
950 	struct wmi_host_fw_abi_ver fw_ver;
951 	uint8_t myaddr[QDF_MAC_ADDR_SIZE];
952 	struct tgt_info *info;
953 	struct wmi_host_ready_ev_param ready_ev;
954 	wmi_legacy_service_ready_callback legacy_callback;
955 	uint8_t num_radios, i;
956 	uint32_t max_peers;
957 	uint32_t max_ast_index;
958 	target_resource_config *tgt_cfg;
959 
960 	if (!scn_handle) {
961 		target_if_err("scn handle NULL");
962 		return -EINVAL;
963 	}
964 
965 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
966 	if (!psoc) {
967 		target_if_err("psoc is null");
968 		return -EINVAL;
969 	}
970 
971 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
972 	if (!tgt_hdl) {
973 		target_if_err("target_psoc_info is null");
974 		return -EINVAL;
975 	}
976 
977 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
978 	info = (&tgt_hdl->info);
979 
980 	if (wmi_extract_fw_abi_version(wmi_handle, event, &fw_ver) ==
981 				QDF_STATUS_SUCCESS) {
982 		info->version.wlan_ver = fw_ver.sw_version;
983 		info->version.wlan_ver = fw_ver.abi_version;
984 	}
985 
986 	if (wmi_check_and_update_fw_version(wmi_handle, event) < 0) {
987 		target_if_err("Version mismatch with FW");
988 		return -EINVAL;
989 	}
990 
991 	if (wmi_extract_ready_event_params(wmi_handle, event, &ready_ev) !=
992 				QDF_STATUS_SUCCESS) {
993 		target_if_err("Failed to extract ready event");
994 		return -EINVAL;
995 	}
996 
997 	if (!ready_ev.agile_capability)
998 		target_if_err("agile capability disabled in HW");
999 	else
1000 		info->wlan_res_cfg.agile_capability = ready_ev.agile_capability;
1001 
1002 	if (ready_ev.num_max_active_vdevs) {
1003 		if (ready_ev.num_max_active_vdevs <
1004 		    info->wlan_res_cfg.num_max_active_vdevs) {
1005 			target_if_err("unexpected num_max_active_vdevs fw %d host %d",
1006 				      ready_ev.num_max_active_vdevs,
1007 				      info->wlan_res_cfg.num_max_active_vdevs);
1008 			info->wlan_res_cfg.num_max_active_vdevs =
1009 					ready_ev.num_max_active_vdevs;
1010 		}
1011 	}
1012 
1013 	/* Indicate to the waiting thread that the ready
1014 	 * event was received
1015 	 */
1016 	info->wlan_init_status = wmi_ready_extract_init_status(
1017 						wmi_handle, event);
1018 
1019 	legacy_callback = target_if_get_psoc_legacy_service_ready_cb();
1020 	if (legacy_callback)
1021 		if (legacy_callback(wmi_ready_event_id,
1022 				    scn_handle, event, data_len)) {
1023 			target_if_err("Legacy callback returned error!");
1024 			tgt_hdl->info.wmi_ready = false;
1025 			goto exit;
1026 		}
1027 
1028 	init_deinit_mlo_update_soc_ready(psoc);
1029 
1030 	num_radios = target_psoc_get_num_radios(tgt_hdl);
1031 
1032 	if ((ready_ev.num_total_peer != 0) &&
1033 	    (info->wlan_res_cfg.num_peers != ready_ev.num_total_peer)) {
1034 		uint16_t num_peers = 0;
1035 		/* FW allocated number of peers is different than host
1036 		 * requested. Update host max with FW reported value.
1037 		 */
1038 		target_if_err("Host Requested %d peers. FW Supports %d peers",
1039 			       info->wlan_res_cfg.num_peers,
1040 			       ready_ev.num_total_peer);
1041 		info->wlan_res_cfg.num_peers = ready_ev.num_total_peer;
1042 		num_peers = info->wlan_res_cfg.num_peers / num_radios;
1043 
1044 		for (i = 0; i < num_radios; i++) {
1045 			pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
1046 							  WLAN_INIT_DEINIT_ID);
1047 			if (!pdev) {
1048 				target_if_err(" PDEV %d is NULL", i);
1049 				return -EINVAL;
1050 			}
1051 
1052 			wlan_pdev_set_max_peer_count(pdev, num_peers);
1053 			wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
1054 		}
1055 
1056 		wlan_psoc_set_max_peer_count(psoc,
1057 					     info->wlan_res_cfg.num_peers);
1058 	}
1059 
1060 	/* for non legacy  num_total_peer will be non zero
1061 	 * allocate peer memory in this case
1062 	 */
1063 	if (ready_ev.num_total_peer != 0) {
1064 		tgt_cfg = &info->wlan_res_cfg;
1065 		max_peers = tgt_cfg->num_peers + ready_ev.num_extra_peer + 1;
1066 		max_ast_index = ready_ev.max_ast_index + 1;
1067 
1068 		if (cdp_peer_map_attach(wlan_psoc_get_dp_handle(psoc),
1069 					max_peers, max_ast_index,
1070 					tgt_cfg->peer_map_unmap_version) !=
1071 				QDF_STATUS_SUCCESS) {
1072 			target_if_err("DP peer map attach failed");
1073 			return -EINVAL;
1074 		}
1075 	}
1076 
1077 
1078 	if (ready_ev.pktlog_defs_checksum) {
1079 		for (i = 0; i < num_radios; i++) {
1080 			pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
1081 							  WLAN_INIT_DEINIT_ID);
1082 			if (!pdev) {
1083 				target_if_err(" PDEV %d is NULL", i);
1084 				return -EINVAL;
1085 			}
1086 			target_if_set_pktlog_checksum(pdev, tgt_hdl,
1087 						      ready_ev.
1088 						      pktlog_defs_checksum);
1089 			wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
1090 		}
1091 	}
1092 
1093 	/*
1094 	 * For non-legacy HW, MAC addr list is extracted.
1095 	 */
1096 	if (num_radios > 1) {
1097 		uint8_t num_mac_addr;
1098 		wmi_host_mac_addr *addr_list;
1099 		int i;
1100 
1101 		addr_list = wmi_ready_extract_mac_addr_list(wmi_handle, event,
1102 							    &num_mac_addr);
1103 		if ((num_mac_addr >= num_radios) && (addr_list)) {
1104 			for (i = 0; i < num_radios; i++) {
1105 				WMI_HOST_MAC_ADDR_TO_CHAR_ARRAY(&addr_list[i],
1106 								myaddr);
1107 				pdev = wlan_objmgr_get_pdev_by_id(psoc, i,
1108 								  WLAN_INIT_DEINIT_ID);
1109 				if (!pdev) {
1110 					target_if_err(" PDEV %d is NULL", i);
1111 					return -EINVAL;
1112 				}
1113 				wlan_pdev_set_hw_macaddr(pdev, myaddr);
1114 				wlan_objmgr_pdev_release_ref(pdev,
1115 							WLAN_INIT_DEINIT_ID);
1116 
1117 				/* assign 1st radio addr to psoc */
1118 				if (i == 0)
1119 					wlan_psoc_set_hw_macaddr(psoc, myaddr);
1120 			}
1121 			goto out;
1122 		} else {
1123 			target_if_err("Using default MAC addr for all radios..");
1124 		}
1125 	}
1126 
1127 	/*
1128 	 * We extract single MAC address in two scenarios:
1129 	 * 1. In non-legacy case, if addr list is NULL or num_mac_addr < num_radios
1130 	 * 2. In all legacy cases
1131 	 */
1132 	for (i = 0; i < num_radios; i++) {
1133 		wmi_ready_extract_mac_addr(wmi_handle, event, myaddr);
1134 		myaddr[MAC_BYTE_4] += i;
1135 		pdev = wlan_objmgr_get_pdev_by_id(psoc, i, WLAN_INIT_DEINIT_ID);
1136 		if (!pdev) {
1137 			target_if_err(" PDEV %d is NULL", i);
1138 			return -EINVAL;
1139 		}
1140 		wlan_pdev_set_hw_macaddr(pdev, myaddr);
1141 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
1142 		/* assign 1st radio addr to psoc */
1143 		if (i == 0)
1144 			wlan_psoc_set_hw_macaddr(psoc, myaddr);
1145 	}
1146 
1147 out:
1148 	target_if_btcoex_cfg_enable(psoc, tgt_hdl, event);
1149 	tgt_hdl->info.wmi_ready = true;
1150 	init_deinit_mlo_update_pdev_ready(psoc, num_radios);
1151 exit:
1152 	init_deinit_wakeup_host_wait(psoc, tgt_hdl);
1153 
1154 	return 0;
1155 }
1156 
1157 #ifdef HEALTH_MON_SUPPORT
init_deinit_health_mon_event_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)1158 static int init_deinit_health_mon_event_handler(ol_scn_t scn_handle,
1159 						uint8_t *event,
1160 						uint32_t data_len)
1161 {
1162 	struct wlan_objmgr_psoc *psoc;
1163 	struct target_psoc_info *tgt_hdl;
1164 	struct wmi_unified *wmi_handle;
1165 	struct tgt_info *info;
1166 	struct wmi_health_mon_params *param;
1167 
1168 	if (!scn_handle) {
1169 		target_if_err("scn handle NULL");
1170 		return -EINVAL;
1171 	}
1172 
1173 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
1174 	if (!psoc) {
1175 		target_if_err("psoc is null");
1176 		return -EINVAL;
1177 	}
1178 
1179 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
1180 	if (!tgt_hdl) {
1181 		target_if_err("target_psoc_info is null");
1182 		return -EINVAL;
1183 	}
1184 
1185 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
1186 	info = (&tgt_hdl->info);
1187 
1188 	param = (&info->health_mon_param);
1189 	wmi_extract_health_mon_event(wmi_handle, event, param);
1190 
1191 	return 0;
1192 }
1193 #endif /* HEALTH_MON_SUPPORT */
1194 
1195 #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
init_deinit_mlo_setup_done_event(struct wlan_objmgr_psoc * psoc)1196 static void init_deinit_mlo_setup_done_event(struct wlan_objmgr_psoc *psoc)
1197 {
1198 	struct target_psoc_info *tgt_hdl;
1199 
1200 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
1201 	if (!tgt_hdl) {
1202 		target_if_err("target_psoc_info is null");
1203 		return;
1204 	}
1205 
1206 	if ((tgt_hdl->tif_ops) &&
1207 	    (tgt_hdl->tif_ops->mlo_setup_done_event))
1208 		tgt_hdl->tif_ops->mlo_setup_done_event(psoc);
1209 }
1210 
init_deinit_mlo_setup_comp_event_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)1211 static int init_deinit_mlo_setup_comp_event_handler(ol_scn_t scn_handle,
1212 						    uint8_t *event,
1213 						    uint32_t data_len)
1214 {
1215 	struct wlan_objmgr_psoc *psoc;
1216 	struct wlan_objmgr_pdev *pdev;
1217 	struct target_psoc_info *tgt_hdl;
1218 	struct wmi_unified *wmi_handle;
1219 	struct wmi_mlo_setup_complete_params params;
1220 	uint8_t grp_id = 0;
1221 
1222 	if (!scn_handle) {
1223 		target_if_err("scn handle NULL");
1224 		return -EINVAL;
1225 	}
1226 
1227 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
1228 
1229 	if (!psoc) {
1230 		target_if_err("psoc is null");
1231 		return -EINVAL;
1232 	}
1233 
1234 	if (!init_deinit_mlo_get_group_id(psoc, &grp_id)) {
1235 		target_if_err("Invalid MLD group id");
1236 		return -EINVAL;
1237 	}
1238 
1239 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
1240 
1241 	if (!tgt_hdl) {
1242 		target_if_err("target_psoc_info is null");
1243 		return -EINVAL;
1244 	}
1245 
1246 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
1247 
1248 	if (wmi_extract_mlo_setup_cmpl_event(wmi_handle, event, &params) !=
1249 			QDF_STATUS_SUCCESS)
1250 		return -EINVAL;
1251 
1252 	pdev = wlan_objmgr_get_pdev_by_id(psoc, params.pdev_id,
1253 					  WLAN_INIT_DEINIT_ID);
1254 
1255 	if (mlo_ap_update_max_ml_peer_ids(
1256 				params.pdev_id, params.max_ml_peer_ids)
1257 			!= QDF_STATUS_SUCCESS) {
1258 		target_if_err("max_ml_peer_ids update failed for pdev_id: %d",
1259 			      params.pdev_id);
1260 	}
1261 
1262 	if (pdev) {
1263 		mlo_link_setup_complete(pdev, grp_id);
1264 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
1265 	}
1266 
1267 	init_deinit_mlo_setup_done_event(psoc);
1268 
1269 	return 0;
1270 }
1271 
init_deinit_mlo_teardown_comp_event_handler(ol_scn_t scn_handle,uint8_t * event,uint32_t data_len)1272 static int init_deinit_mlo_teardown_comp_event_handler(ol_scn_t scn_handle,
1273 						       uint8_t *event,
1274 						       uint32_t data_len)
1275 {
1276 	struct wlan_objmgr_psoc *psoc;
1277 	struct wlan_objmgr_pdev *pdev;
1278 	struct target_psoc_info *tgt_hdl;
1279 	struct wmi_unified *wmi_handle;
1280 	struct wmi_mlo_teardown_cmpl_params params;
1281 	uint8_t grp_id = 0;
1282 
1283 	if (!scn_handle) {
1284 		target_if_err("scn handle NULL");
1285 		return -EINVAL;
1286 	}
1287 
1288 	psoc = target_if_get_psoc_from_scn_hdl(scn_handle);
1289 	if (!psoc) {
1290 		target_if_err("psoc is null");
1291 		return -EINVAL;
1292 	}
1293 
1294 	if (!init_deinit_mlo_get_group_id(psoc, &grp_id)) {
1295 		target_if_err("Invalid MLD group id");
1296 		return -EINVAL;
1297 	}
1298 
1299 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
1300 	if (!tgt_hdl) {
1301 		target_if_err("target_psoc_info is null");
1302 		return -EINVAL;
1303 	}
1304 	wmi_handle = target_psoc_get_wmi_hdl(tgt_hdl);
1305 
1306 	if (wmi_extract_mlo_teardown_cmpl_event(wmi_handle, event, &params) !=
1307 			QDF_STATUS_SUCCESS)
1308 		return -EINVAL;
1309 
1310 	pdev = wlan_objmgr_get_pdev_by_id(psoc, params.pdev_id,
1311 					  WLAN_INIT_DEINIT_ID);
1312 	if (pdev) {
1313 		mlo_link_teardown_complete(pdev, grp_id);
1314 		wlan_objmgr_pdev_release_ref(pdev, WLAN_INIT_DEINIT_ID);
1315 	}
1316 
1317 	return 0;
1318 }
1319 
init_deinit_register_mlo_ev_handlers(wmi_unified_t wmi_handle)1320 static QDF_STATUS init_deinit_register_mlo_ev_handlers(wmi_unified_t wmi_handle)
1321 {
1322 	wmi_unified_register_event(wmi_handle,
1323 				   wmi_mlo_setup_complete_event_id,
1324 				   init_deinit_mlo_setup_comp_event_handler);
1325 	wmi_unified_register_event(wmi_handle,
1326 				   wmi_mlo_teardown_complete_event_id,
1327 				   init_deinit_mlo_teardown_comp_event_handler);
1328 
1329 	return QDF_STATUS_SUCCESS;
1330 }
1331 #else
init_deinit_register_mlo_ev_handlers(wmi_unified_t wmi_handle)1332 static QDF_STATUS init_deinit_register_mlo_ev_handlers(wmi_unified_t wmi_handle)
1333 {
1334 	return QDF_STATUS_SUCCESS;
1335 }
1336 #endif /*WLAN_FEATURE_11BE_MLO && WLAN_MLO_MULTI_CHIP*/
1337 
init_deinit_register_tgt_psoc_ev_handlers(struct wlan_objmgr_psoc * psoc)1338 QDF_STATUS init_deinit_register_tgt_psoc_ev_handlers(
1339 				struct wlan_objmgr_psoc *psoc)
1340 {
1341 	struct target_psoc_info *tgt_hdl;
1342 	wmi_unified_t wmi_handle;
1343 	QDF_STATUS retval = QDF_STATUS_SUCCESS;
1344 
1345 	if (!psoc) {
1346 		target_if_err("psoc is null in register wmi handler");
1347 		return QDF_STATUS_E_FAILURE;
1348 	}
1349 
1350 	tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
1351 	if (!tgt_hdl) {
1352 		target_if_err("target_psoc_info null in register wmi hadler");
1353 		return QDF_STATUS_E_FAILURE;
1354 	}
1355 
1356 	wmi_handle = (wmi_unified_t)target_psoc_get_wmi_hdl(tgt_hdl);
1357 
1358 	retval = wmi_unified_register_event_handler(wmi_handle,
1359 				wmi_service_ready_event_id,
1360 				init_deinit_service_ready_event_handler,
1361 				WMI_RX_WORK_CTX);
1362 	retval = wmi_unified_register_event_handler(wmi_handle,
1363 				wmi_service_ready_ext_event_id,
1364 				init_deinit_service_ext_ready_event_handler,
1365 				WMI_RX_WORK_CTX);
1366 	retval = wmi_unified_register_event_handler(wmi_handle,
1367 				wmi_service_available_event_id,
1368 				init_deinit_service_available_handler,
1369 				WMI_RX_UMAC_CTX);
1370 	retval = wmi_unified_register_event_handler(wmi_handle,
1371 				wmi_ready_event_id,
1372 				init_deinit_ready_event_handler,
1373 				WMI_RX_WORK_CTX);
1374 	retval = wmi_unified_register_event_handler(
1375 				wmi_handle,
1376 				wmi_service_ready_ext2_event_id,
1377 				init_deinit_service_ext2_ready_event_handler,
1378 				WMI_RX_WORK_CTX);
1379 	retval = init_deinit_register_mlo_ev_handlers(wmi_handle);
1380 
1381 #ifdef HEALTH_MON_SUPPORT
1382 	retval = wmi_unified_register_event_handler(
1383 				wmi_handle,
1384 				wmi_extract_health_mon_init_done_info_eventid,
1385 				init_deinit_health_mon_event_handler,
1386 				WMI_RX_WORK_CTX);
1387 #endif /* HEALTH_MON_SUPPORT */
1388 
1389 	return retval;
1390 }
1391 
1392