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