xref: /linux/drivers/net/wireless/ath/ath11k/core.c (revision 04317b129e4eb5c6f4a58bb899b2019c1545320b)
1 // SPDX-License-Identifier: BSD-3-Clause-Clear
2 /*
3  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
5  */
6 
7 #include <linux/module.h>
8 #include <linux/slab.h>
9 #include <linux/remoteproc.h>
10 #include <linux/firmware.h>
11 #include <linux/of.h>
12 
13 #include "core.h"
14 #include "dp_tx.h"
15 #include "dp_rx.h"
16 #include "debug.h"
17 #include "hif.h"
18 #include "wow.h"
19 
20 unsigned int ath11k_debug_mask;
21 EXPORT_SYMBOL(ath11k_debug_mask);
22 module_param_named(debug_mask, ath11k_debug_mask, uint, 0644);
23 MODULE_PARM_DESC(debug_mask, "Debugging mask");
24 
25 static unsigned int ath11k_crypto_mode;
26 module_param_named(crypto_mode, ath11k_crypto_mode, uint, 0644);
27 MODULE_PARM_DESC(crypto_mode, "crypto mode: 0-hardware, 1-software");
28 
29 /* frame mode values are mapped as per enum ath11k_hw_txrx_mode */
30 unsigned int ath11k_frame_mode = ATH11K_HW_TXRX_NATIVE_WIFI;
31 module_param_named(frame_mode, ath11k_frame_mode, uint, 0644);
32 MODULE_PARM_DESC(frame_mode,
33 		 "Datapath frame mode (0: raw, 1: native wifi (default), 2: ethernet)");
34 
35 bool ath11k_ftm_mode;
36 module_param_named(ftm_mode, ath11k_ftm_mode, bool, 0444);
37 MODULE_PARM_DESC(ftm_mode, "Boots up in factory test mode");
38 
39 static const struct ath11k_hw_params ath11k_hw_params[] = {
40 	{
41 		.hw_rev = ATH11K_HW_IPQ8074,
42 		.name = "ipq8074 hw2.0",
43 		.fw = {
44 			.dir = "IPQ8074/hw2.0",
45 			.board_size = 256 * 1024,
46 			.cal_offset = 128 * 1024,
47 		},
48 		.max_radios = 3,
49 		.bdf_addr = 0x4B0C0000,
50 		.hw_ops = &ipq8074_ops,
51 		.ring_mask = &ath11k_hw_ring_mask_ipq8074,
52 		.internal_sleep_clock = false,
53 		.regs = &ipq8074_regs,
54 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ8074,
55 		.host_ce_config = ath11k_host_ce_config_ipq8074,
56 		.ce_count = 12,
57 		.target_ce_config = ath11k_target_ce_config_wlan_ipq8074,
58 		.target_ce_count = 11,
59 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_ipq8074,
60 		.svc_to_ce_map_len = 21,
61 		.ce_ie_addr = &ath11k_ce_ie_addr_ipq8074,
62 		.single_pdev_only = false,
63 		.rxdma1_enable = true,
64 		.num_rxmda_per_pdev = 1,
65 		.rx_mac_buf_ring = false,
66 		.vdev_start_delay = false,
67 		.htt_peer_map_v2 = true,
68 
69 		.spectral = {
70 			.fft_sz = 2,
71 			/* HW bug, expected BIN size is 2 bytes but HW report as 4 bytes.
72 			 * so added pad size as 2 bytes to compensate the BIN size
73 			 */
74 			.fft_pad_sz = 2,
75 			.summary_pad_sz = 0,
76 			.fft_hdr_len = 16,
77 			.max_fft_bins = 512,
78 			.fragment_160mhz = true,
79 		},
80 
81 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
82 					BIT(NL80211_IFTYPE_AP) |
83 					BIT(NL80211_IFTYPE_MESH_POINT),
84 		.supports_monitor = true,
85 		.full_monitor_mode = false,
86 		.supports_shadow_regs = false,
87 		.idle_ps = false,
88 		.supports_sta_ps = false,
89 		.coldboot_cal_mm = true,
90 		.coldboot_cal_ftm = true,
91 		.cbcal_restart_fw = true,
92 		.fw_mem_mode = 0,
93 		.num_vdevs = 16 + 1,
94 		.num_peers = 512,
95 		.supports_suspend = false,
96 		.hal_desc_sz = sizeof(struct hal_rx_desc_ipq8074),
97 		.supports_regdb = false,
98 		.fix_l1ss = true,
99 		.credit_flow = false,
100 		.max_tx_ring = DP_TCL_NUM_RING_MAX,
101 		.hal_params = &ath11k_hw_hal_params_ipq8074,
102 		.supports_dynamic_smps_6ghz = false,
103 		.alloc_cacheable_memory = true,
104 		.supports_rssi_stats = false,
105 		.fw_wmi_diag_event = false,
106 		.current_cc_support = false,
107 		.dbr_debug_support = true,
108 		.global_reset = false,
109 		.bios_sar_capa = NULL,
110 		.m3_fw_support = false,
111 		.fixed_bdf_addr = true,
112 		.fixed_mem_region = true,
113 		.static_window_map = false,
114 		.hybrid_bus_type = false,
115 		.fixed_fw_mem = false,
116 		.support_off_channel_tx = false,
117 		.supports_multi_bssid = false,
118 
119 		.sram_dump = {},
120 
121 		.tcl_ring_retry = true,
122 		.tx_ring_size = DP_TCL_DATA_RING_SIZE,
123 		.smp2p_wow_exit = false,
124 	},
125 	{
126 		.hw_rev = ATH11K_HW_IPQ6018_HW10,
127 		.name = "ipq6018 hw1.0",
128 		.fw = {
129 			.dir = "IPQ6018/hw1.0",
130 			.board_size = 256 * 1024,
131 			.cal_offset = 128 * 1024,
132 		},
133 		.max_radios = 2,
134 		.bdf_addr = 0x4ABC0000,
135 		.hw_ops = &ipq6018_ops,
136 		.ring_mask = &ath11k_hw_ring_mask_ipq8074,
137 		.internal_sleep_clock = false,
138 		.regs = &ipq8074_regs,
139 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ8074,
140 		.host_ce_config = ath11k_host_ce_config_ipq8074,
141 		.ce_count = 12,
142 		.target_ce_config = ath11k_target_ce_config_wlan_ipq8074,
143 		.target_ce_count = 11,
144 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_ipq6018,
145 		.svc_to_ce_map_len = 19,
146 		.ce_ie_addr = &ath11k_ce_ie_addr_ipq8074,
147 		.single_pdev_only = false,
148 		.rxdma1_enable = true,
149 		.num_rxmda_per_pdev = 1,
150 		.rx_mac_buf_ring = false,
151 		.vdev_start_delay = false,
152 		.htt_peer_map_v2 = true,
153 
154 		.spectral = {
155 			.fft_sz = 4,
156 			.fft_pad_sz = 0,
157 			.summary_pad_sz = 0,
158 			.fft_hdr_len = 16,
159 			.max_fft_bins = 512,
160 			.fragment_160mhz = true,
161 		},
162 
163 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
164 					BIT(NL80211_IFTYPE_AP) |
165 					BIT(NL80211_IFTYPE_MESH_POINT),
166 		.supports_monitor = true,
167 		.full_monitor_mode = false,
168 		.supports_shadow_regs = false,
169 		.idle_ps = false,
170 		.supports_sta_ps = false,
171 		.coldboot_cal_mm = true,
172 		.coldboot_cal_ftm = true,
173 		.cbcal_restart_fw = true,
174 		.fw_mem_mode = 0,
175 		.num_vdevs = 16 + 1,
176 		.num_peers = 512,
177 		.supports_suspend = false,
178 		.hal_desc_sz = sizeof(struct hal_rx_desc_ipq8074),
179 		.supports_regdb = false,
180 		.fix_l1ss = true,
181 		.credit_flow = false,
182 		.max_tx_ring = DP_TCL_NUM_RING_MAX,
183 		.hal_params = &ath11k_hw_hal_params_ipq8074,
184 		.supports_dynamic_smps_6ghz = false,
185 		.alloc_cacheable_memory = true,
186 		.supports_rssi_stats = false,
187 		.fw_wmi_diag_event = false,
188 		.current_cc_support = false,
189 		.dbr_debug_support = true,
190 		.global_reset = false,
191 		.bios_sar_capa = NULL,
192 		.m3_fw_support = false,
193 		.fixed_bdf_addr = true,
194 		.fixed_mem_region = true,
195 		.static_window_map = false,
196 		.hybrid_bus_type = false,
197 		.fixed_fw_mem = false,
198 		.support_off_channel_tx = false,
199 		.supports_multi_bssid = false,
200 
201 		.sram_dump = {},
202 
203 		.tcl_ring_retry = true,
204 		.tx_ring_size = DP_TCL_DATA_RING_SIZE,
205 		.smp2p_wow_exit = false,
206 		.support_fw_mac_sequence = false,
207 	},
208 	{
209 		.name = "qca6390 hw2.0",
210 		.hw_rev = ATH11K_HW_QCA6390_HW20,
211 		.fw = {
212 			.dir = "QCA6390/hw2.0",
213 			.board_size = 256 * 1024,
214 			.cal_offset = 128 * 1024,
215 		},
216 		.max_radios = 3,
217 		.bdf_addr = 0x4B0C0000,
218 		.hw_ops = &qca6390_ops,
219 		.ring_mask = &ath11k_hw_ring_mask_qca6390,
220 		.internal_sleep_clock = true,
221 		.regs = &qca6390_regs,
222 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCA6390,
223 		.host_ce_config = ath11k_host_ce_config_qca6390,
224 		.ce_count = 9,
225 		.target_ce_config = ath11k_target_ce_config_wlan_qca6390,
226 		.target_ce_count = 9,
227 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
228 		.svc_to_ce_map_len = 14,
229 		.ce_ie_addr = &ath11k_ce_ie_addr_ipq8074,
230 		.single_pdev_only = true,
231 		.rxdma1_enable = false,
232 		.num_rxmda_per_pdev = 2,
233 		.rx_mac_buf_ring = true,
234 		.vdev_start_delay = true,
235 		.htt_peer_map_v2 = false,
236 
237 		.spectral = {
238 			.fft_sz = 0,
239 			.fft_pad_sz = 0,
240 			.summary_pad_sz = 0,
241 			.fft_hdr_len = 0,
242 			.max_fft_bins = 0,
243 			.fragment_160mhz = false,
244 		},
245 
246 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
247 					BIT(NL80211_IFTYPE_AP),
248 		.supports_monitor = false,
249 		.full_monitor_mode = false,
250 		.supports_shadow_regs = true,
251 		.idle_ps = true,
252 		.supports_sta_ps = true,
253 		.coldboot_cal_mm = false,
254 		.coldboot_cal_ftm = false,
255 		.cbcal_restart_fw = false,
256 		.fw_mem_mode = 0,
257 		.num_vdevs = 16 + 1,
258 		.num_peers = 512,
259 		.supports_suspend = true,
260 		.hal_desc_sz = sizeof(struct hal_rx_desc_ipq8074),
261 		.supports_regdb = false,
262 		.fix_l1ss = true,
263 		.credit_flow = true,
264 		.max_tx_ring = DP_TCL_NUM_RING_MAX_QCA6390,
265 		.hal_params = &ath11k_hw_hal_params_qca6390,
266 		.supports_dynamic_smps_6ghz = false,
267 		.alloc_cacheable_memory = false,
268 		.supports_rssi_stats = true,
269 		.fw_wmi_diag_event = true,
270 		.current_cc_support = true,
271 		.dbr_debug_support = false,
272 		.global_reset = true,
273 		.bios_sar_capa = NULL,
274 		.m3_fw_support = true,
275 		.fixed_bdf_addr = false,
276 		.fixed_mem_region = false,
277 		.static_window_map = false,
278 		.hybrid_bus_type = false,
279 		.fixed_fw_mem = false,
280 		.support_off_channel_tx = true,
281 		.supports_multi_bssid = true,
282 
283 		.sram_dump = {
284 			.start = 0x01400000,
285 			.end = 0x0171ffff,
286 		},
287 
288 		.tcl_ring_retry = true,
289 		.tx_ring_size = DP_TCL_DATA_RING_SIZE,
290 		.smp2p_wow_exit = false,
291 		.support_fw_mac_sequence = true,
292 	},
293 	{
294 		.name = "qcn9074 hw1.0",
295 		.hw_rev = ATH11K_HW_QCN9074_HW10,
296 		.fw = {
297 			.dir = "QCN9074/hw1.0",
298 			.board_size = 256 * 1024,
299 			.cal_offset = 128 * 1024,
300 		},
301 		.max_radios = 1,
302 		.single_pdev_only = false,
303 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9074,
304 		.hw_ops = &qcn9074_ops,
305 		.ring_mask = &ath11k_hw_ring_mask_qcn9074,
306 		.internal_sleep_clock = false,
307 		.regs = &qcn9074_regs,
308 		.host_ce_config = ath11k_host_ce_config_qcn9074,
309 		.ce_count = 6,
310 		.target_ce_config = ath11k_target_ce_config_wlan_qcn9074,
311 		.target_ce_count = 9,
312 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qcn9074,
313 		.svc_to_ce_map_len = 18,
314 		.ce_ie_addr = &ath11k_ce_ie_addr_ipq8074,
315 		.rxdma1_enable = true,
316 		.num_rxmda_per_pdev = 1,
317 		.rx_mac_buf_ring = false,
318 		.vdev_start_delay = false,
319 		.htt_peer_map_v2 = true,
320 
321 		.spectral = {
322 			.fft_sz = 2,
323 			.fft_pad_sz = 0,
324 			.summary_pad_sz = 16,
325 			.fft_hdr_len = 24,
326 			.max_fft_bins = 1024,
327 			.fragment_160mhz = false,
328 		},
329 
330 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
331 					BIT(NL80211_IFTYPE_AP) |
332 					BIT(NL80211_IFTYPE_MESH_POINT),
333 		.supports_monitor = true,
334 		.full_monitor_mode = true,
335 		.supports_shadow_regs = false,
336 		.idle_ps = false,
337 		.supports_sta_ps = false,
338 		.coldboot_cal_mm = false,
339 		.coldboot_cal_ftm = true,
340 		.cbcal_restart_fw = true,
341 		.fw_mem_mode = 2,
342 		.num_vdevs = 8,
343 		.num_peers = 128,
344 		.supports_suspend = false,
345 		.hal_desc_sz = sizeof(struct hal_rx_desc_qcn9074),
346 		.supports_regdb = false,
347 		.fix_l1ss = true,
348 		.credit_flow = false,
349 		.max_tx_ring = DP_TCL_NUM_RING_MAX,
350 		.hal_params = &ath11k_hw_hal_params_ipq8074,
351 		.supports_dynamic_smps_6ghz = true,
352 		.alloc_cacheable_memory = true,
353 		.supports_rssi_stats = false,
354 		.fw_wmi_diag_event = false,
355 		.current_cc_support = false,
356 		.dbr_debug_support = true,
357 		.global_reset = false,
358 		.bios_sar_capa = NULL,
359 		.m3_fw_support = true,
360 		.fixed_bdf_addr = false,
361 		.fixed_mem_region = false,
362 		.static_window_map = true,
363 		.hybrid_bus_type = false,
364 		.fixed_fw_mem = false,
365 		.support_off_channel_tx = false,
366 		.supports_multi_bssid = false,
367 
368 		.sram_dump = {},
369 
370 		.tcl_ring_retry = true,
371 		.tx_ring_size = DP_TCL_DATA_RING_SIZE,
372 		.smp2p_wow_exit = false,
373 		.support_fw_mac_sequence = false,
374 	},
375 	{
376 		.name = "wcn6855 hw2.0",
377 		.hw_rev = ATH11K_HW_WCN6855_HW20,
378 		.fw = {
379 			.dir = "WCN6855/hw2.0",
380 			.board_size = 256 * 1024,
381 			.cal_offset = 128 * 1024,
382 		},
383 		.max_radios = 3,
384 		.bdf_addr = 0x4B0C0000,
385 		.hw_ops = &wcn6855_ops,
386 		.ring_mask = &ath11k_hw_ring_mask_qca6390,
387 		.internal_sleep_clock = true,
388 		.regs = &wcn6855_regs,
389 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCA6390,
390 		.host_ce_config = ath11k_host_ce_config_qca6390,
391 		.ce_count = 9,
392 		.target_ce_config = ath11k_target_ce_config_wlan_qca6390,
393 		.target_ce_count = 9,
394 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
395 		.svc_to_ce_map_len = 14,
396 		.ce_ie_addr = &ath11k_ce_ie_addr_ipq8074,
397 		.single_pdev_only = true,
398 		.rxdma1_enable = false,
399 		.num_rxmda_per_pdev = 2,
400 		.rx_mac_buf_ring = true,
401 		.vdev_start_delay = true,
402 		.htt_peer_map_v2 = false,
403 
404 		.spectral = {
405 			.fft_sz = 0,
406 			.fft_pad_sz = 0,
407 			.summary_pad_sz = 0,
408 			.fft_hdr_len = 0,
409 			.max_fft_bins = 0,
410 			.fragment_160mhz = false,
411 		},
412 
413 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
414 					BIT(NL80211_IFTYPE_AP),
415 		.supports_monitor = false,
416 		.full_monitor_mode = false,
417 		.supports_shadow_regs = true,
418 		.idle_ps = true,
419 		.supports_sta_ps = true,
420 		.coldboot_cal_mm = false,
421 		.coldboot_cal_ftm = false,
422 		.cbcal_restart_fw = false,
423 		.fw_mem_mode = 0,
424 		.num_vdevs = 16 + 1,
425 		.num_peers = 512,
426 		.supports_suspend = true,
427 		.hal_desc_sz = sizeof(struct hal_rx_desc_wcn6855),
428 		.supports_regdb = true,
429 		.fix_l1ss = false,
430 		.credit_flow = true,
431 		.max_tx_ring = DP_TCL_NUM_RING_MAX_QCA6390,
432 		.hal_params = &ath11k_hw_hal_params_qca6390,
433 		.supports_dynamic_smps_6ghz = false,
434 		.alloc_cacheable_memory = false,
435 		.supports_rssi_stats = true,
436 		.fw_wmi_diag_event = true,
437 		.current_cc_support = true,
438 		.dbr_debug_support = false,
439 		.global_reset = true,
440 		.bios_sar_capa = &ath11k_hw_sar_capa_wcn6855,
441 		.m3_fw_support = true,
442 		.fixed_bdf_addr = false,
443 		.fixed_mem_region = false,
444 		.static_window_map = false,
445 		.hybrid_bus_type = false,
446 		.fixed_fw_mem = false,
447 		.support_off_channel_tx = true,
448 		.supports_multi_bssid = true,
449 
450 		.sram_dump = {
451 			.start = 0x01400000,
452 			.end = 0x0177ffff,
453 		},
454 
455 		.tcl_ring_retry = true,
456 		.tx_ring_size = DP_TCL_DATA_RING_SIZE,
457 		.smp2p_wow_exit = false,
458 		.support_fw_mac_sequence = true,
459 	},
460 	{
461 		.name = "wcn6855 hw2.1",
462 		.hw_rev = ATH11K_HW_WCN6855_HW21,
463 		.fw = {
464 			.dir = "WCN6855/hw2.1",
465 			.board_size = 256 * 1024,
466 			.cal_offset = 128 * 1024,
467 		},
468 		.max_radios = 3,
469 		.bdf_addr = 0x4B0C0000,
470 		.hw_ops = &wcn6855_ops,
471 		.ring_mask = &ath11k_hw_ring_mask_qca6390,
472 		.internal_sleep_clock = true,
473 		.regs = &wcn6855_regs,
474 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCA6390,
475 		.host_ce_config = ath11k_host_ce_config_qca6390,
476 		.ce_count = 9,
477 		.target_ce_config = ath11k_target_ce_config_wlan_qca6390,
478 		.target_ce_count = 9,
479 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
480 		.svc_to_ce_map_len = 14,
481 		.single_pdev_only = true,
482 		.rxdma1_enable = false,
483 		.num_rxmda_per_pdev = 2,
484 		.rx_mac_buf_ring = true,
485 		.vdev_start_delay = true,
486 		.htt_peer_map_v2 = false,
487 
488 		.spectral = {
489 			.fft_sz = 0,
490 			.fft_pad_sz = 0,
491 			.summary_pad_sz = 0,
492 			.fft_hdr_len = 0,
493 			.max_fft_bins = 0,
494 			.fragment_160mhz = false,
495 		},
496 
497 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
498 					BIT(NL80211_IFTYPE_AP),
499 		.supports_monitor = false,
500 		.supports_shadow_regs = true,
501 		.idle_ps = true,
502 		.supports_sta_ps = true,
503 		.coldboot_cal_mm = false,
504 		.coldboot_cal_ftm = false,
505 		.cbcal_restart_fw = false,
506 		.fw_mem_mode = 0,
507 		.num_vdevs = 16 + 1,
508 		.num_peers = 512,
509 		.supports_suspend = true,
510 		.hal_desc_sz = sizeof(struct hal_rx_desc_wcn6855),
511 		.supports_regdb = true,
512 		.fix_l1ss = false,
513 		.credit_flow = true,
514 		.max_tx_ring = DP_TCL_NUM_RING_MAX_QCA6390,
515 		.hal_params = &ath11k_hw_hal_params_qca6390,
516 		.supports_dynamic_smps_6ghz = false,
517 		.alloc_cacheable_memory = false,
518 		.supports_rssi_stats = true,
519 		.fw_wmi_diag_event = true,
520 		.current_cc_support = true,
521 		.dbr_debug_support = false,
522 		.global_reset = true,
523 		.bios_sar_capa = &ath11k_hw_sar_capa_wcn6855,
524 		.m3_fw_support = true,
525 		.fixed_bdf_addr = false,
526 		.fixed_mem_region = false,
527 		.static_window_map = false,
528 		.hybrid_bus_type = false,
529 		.fixed_fw_mem = false,
530 		.support_off_channel_tx = true,
531 		.supports_multi_bssid = true,
532 
533 		.sram_dump = {
534 			.start = 0x01400000,
535 			.end = 0x0177ffff,
536 		},
537 
538 		.tcl_ring_retry = true,
539 		.tx_ring_size = DP_TCL_DATA_RING_SIZE,
540 		.smp2p_wow_exit = false,
541 		.support_fw_mac_sequence = true,
542 	},
543 	{
544 		.name = "wcn6750 hw1.0",
545 		.hw_rev = ATH11K_HW_WCN6750_HW10,
546 		.fw = {
547 			.dir = "WCN6750/hw1.0",
548 			.board_size = 256 * 1024,
549 			.cal_offset = 128 * 1024,
550 		},
551 		.max_radios = 1,
552 		.bdf_addr = 0x4B0C0000,
553 		.hw_ops = &wcn6750_ops,
554 		.ring_mask = &ath11k_hw_ring_mask_wcn6750,
555 		.internal_sleep_clock = false,
556 		.regs = &wcn6750_regs,
557 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_WCN6750,
558 		.host_ce_config = ath11k_host_ce_config_qca6390,
559 		.ce_count = 9,
560 		.target_ce_config = ath11k_target_ce_config_wlan_qca6390,
561 		.target_ce_count = 9,
562 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
563 		.svc_to_ce_map_len = 14,
564 		.ce_ie_addr = &ath11k_ce_ie_addr_ipq8074,
565 		.single_pdev_only = true,
566 		.rxdma1_enable = false,
567 		.num_rxmda_per_pdev = 1,
568 		.rx_mac_buf_ring = true,
569 		.vdev_start_delay = true,
570 		.htt_peer_map_v2 = false,
571 
572 		.spectral = {
573 			.fft_sz = 0,
574 			.fft_pad_sz = 0,
575 			.summary_pad_sz = 0,
576 			.fft_hdr_len = 0,
577 			.max_fft_bins = 0,
578 			.fragment_160mhz = false,
579 		},
580 
581 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
582 					BIT(NL80211_IFTYPE_AP),
583 		.supports_monitor = false,
584 		.supports_shadow_regs = true,
585 		.idle_ps = true,
586 		.supports_sta_ps = true,
587 		.coldboot_cal_mm = true,
588 		.coldboot_cal_ftm = true,
589 		.cbcal_restart_fw = false,
590 		.fw_mem_mode = 0,
591 		.num_vdevs = 16 + 1,
592 		.num_peers = 512,
593 		.supports_suspend = false,
594 		.hal_desc_sz = sizeof(struct hal_rx_desc_qcn9074),
595 		.supports_regdb = true,
596 		.fix_l1ss = false,
597 		.credit_flow = true,
598 		.max_tx_ring = DP_TCL_NUM_RING_MAX,
599 		.hal_params = &ath11k_hw_hal_params_wcn6750,
600 		.supports_dynamic_smps_6ghz = false,
601 		.alloc_cacheable_memory = false,
602 		.supports_rssi_stats = true,
603 		.fw_wmi_diag_event = false,
604 		.current_cc_support = true,
605 		.dbr_debug_support = false,
606 		.global_reset = false,
607 		.bios_sar_capa = &ath11k_hw_sar_capa_wcn6855,
608 		.m3_fw_support = false,
609 		.fixed_bdf_addr = false,
610 		.fixed_mem_region = false,
611 		.static_window_map = true,
612 		.hybrid_bus_type = true,
613 		.fixed_fw_mem = true,
614 		.support_off_channel_tx = true,
615 		.supports_multi_bssid = true,
616 
617 		.sram_dump = {},
618 
619 		.tcl_ring_retry = false,
620 		.tx_ring_size = DP_TCL_DATA_RING_SIZE_WCN6750,
621 		.smp2p_wow_exit = true,
622 		.support_fw_mac_sequence = true,
623 	},
624 	{
625 		.hw_rev = ATH11K_HW_IPQ5018_HW10,
626 		.name = "ipq5018 hw1.0",
627 		.fw = {
628 			.dir = "IPQ5018/hw1.0",
629 			.board_size = 256 * 1024,
630 			.cal_offset = 128 * 1024,
631 		},
632 		.max_radios = MAX_RADIOS_5018,
633 		.bdf_addr = 0x4BA00000,
634 		/* hal_desc_sz and hw ops are similar to qcn9074 */
635 		.hal_desc_sz = sizeof(struct hal_rx_desc_qcn9074),
636 		.qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ8074,
637 		.ring_mask = &ath11k_hw_ring_mask_ipq8074,
638 		.credit_flow = false,
639 		.max_tx_ring = 1,
640 		.spectral = {
641 			.fft_sz = 2,
642 			.fft_pad_sz = 0,
643 			.summary_pad_sz = 16,
644 			.fft_hdr_len = 24,
645 			.max_fft_bins = 1024,
646 		},
647 		.internal_sleep_clock = false,
648 		.regs = &ipq5018_regs,
649 		.hw_ops = &ipq5018_ops,
650 		.host_ce_config = ath11k_host_ce_config_qcn9074,
651 		.ce_count = CE_CNT_5018,
652 		.target_ce_config = ath11k_target_ce_config_wlan_ipq5018,
653 		.target_ce_count = TARGET_CE_CNT_5018,
654 		.svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_ipq5018,
655 		.svc_to_ce_map_len = SVC_CE_MAP_LEN_5018,
656 		.ce_ie_addr = &ath11k_ce_ie_addr_ipq5018,
657 		.ce_remap = &ath11k_ce_remap_ipq5018,
658 		.rxdma1_enable = true,
659 		.num_rxmda_per_pdev = RXDMA_PER_PDEV_5018,
660 		.rx_mac_buf_ring = false,
661 		.vdev_start_delay = false,
662 		.htt_peer_map_v2 = true,
663 		.interface_modes = BIT(NL80211_IFTYPE_STATION) |
664 			BIT(NL80211_IFTYPE_AP) |
665 			BIT(NL80211_IFTYPE_MESH_POINT),
666 		.supports_monitor = false,
667 		.supports_sta_ps = false,
668 		.supports_shadow_regs = false,
669 		.fw_mem_mode = 0,
670 		.num_vdevs = 16 + 1,
671 		.num_peers = 512,
672 		.supports_regdb = false,
673 		.idle_ps = false,
674 		.supports_suspend = false,
675 		.hal_params = &ath11k_hw_hal_params_ipq8074,
676 		.single_pdev_only = false,
677 		.coldboot_cal_mm = true,
678 		.coldboot_cal_ftm = true,
679 		.cbcal_restart_fw = true,
680 		.fix_l1ss = true,
681 		.supports_dynamic_smps_6ghz = false,
682 		.alloc_cacheable_memory = true,
683 		.supports_rssi_stats = false,
684 		.fw_wmi_diag_event = false,
685 		.current_cc_support = false,
686 		.dbr_debug_support = true,
687 		.global_reset = false,
688 		.bios_sar_capa = NULL,
689 		.m3_fw_support = false,
690 		.fixed_bdf_addr = true,
691 		.fixed_mem_region = true,
692 		.static_window_map = false,
693 		.hybrid_bus_type = false,
694 		.fixed_fw_mem = false,
695 		.support_off_channel_tx = false,
696 		.supports_multi_bssid = false,
697 
698 		.sram_dump = {},
699 
700 		.tcl_ring_retry = true,
701 		.tx_ring_size = DP_TCL_DATA_RING_SIZE,
702 		.smp2p_wow_exit = false,
703 		.support_fw_mac_sequence = false,
704 	},
705 };
706 
707 static inline struct ath11k_pdev *ath11k_core_get_single_pdev(struct ath11k_base *ab)
708 {
709 	WARN_ON(!ab->hw_params.single_pdev_only);
710 
711 	return &ab->pdevs[0];
712 }
713 
714 void ath11k_fw_stats_pdevs_free(struct list_head *head)
715 {
716 	struct ath11k_fw_stats_pdev *i, *tmp;
717 
718 	list_for_each_entry_safe(i, tmp, head, list) {
719 		list_del(&i->list);
720 		kfree(i);
721 	}
722 }
723 
724 void ath11k_fw_stats_vdevs_free(struct list_head *head)
725 {
726 	struct ath11k_fw_stats_vdev *i, *tmp;
727 
728 	list_for_each_entry_safe(i, tmp, head, list) {
729 		list_del(&i->list);
730 		kfree(i);
731 	}
732 }
733 
734 void ath11k_fw_stats_bcn_free(struct list_head *head)
735 {
736 	struct ath11k_fw_stats_bcn *i, *tmp;
737 
738 	list_for_each_entry_safe(i, tmp, head, list) {
739 		list_del(&i->list);
740 		kfree(i);
741 	}
742 }
743 
744 void ath11k_fw_stats_init(struct ath11k *ar)
745 {
746 	INIT_LIST_HEAD(&ar->fw_stats.pdevs);
747 	INIT_LIST_HEAD(&ar->fw_stats.vdevs);
748 	INIT_LIST_HEAD(&ar->fw_stats.bcn);
749 
750 	init_completion(&ar->fw_stats_complete);
751 }
752 
753 void ath11k_fw_stats_free(struct ath11k_fw_stats *stats)
754 {
755 	ath11k_fw_stats_pdevs_free(&stats->pdevs);
756 	ath11k_fw_stats_vdevs_free(&stats->vdevs);
757 	ath11k_fw_stats_bcn_free(&stats->bcn);
758 }
759 
760 bool ath11k_core_coldboot_cal_support(struct ath11k_base *ab)
761 {
762 	if (!ath11k_cold_boot_cal)
763 		return false;
764 
765 	if (ath11k_ftm_mode)
766 		return ab->hw_params.coldboot_cal_ftm;
767 
768 	else
769 		return ab->hw_params.coldboot_cal_mm;
770 }
771 
772 int ath11k_core_suspend(struct ath11k_base *ab)
773 {
774 	int ret;
775 	struct ath11k_pdev *pdev;
776 	struct ath11k *ar;
777 
778 	if (!ab->hw_params.supports_suspend)
779 		return -EOPNOTSUPP;
780 
781 	/* so far single_pdev_only chips have supports_suspend as true
782 	 * and only the first pdev is valid.
783 	 */
784 	pdev = ath11k_core_get_single_pdev(ab);
785 	ar = pdev->ar;
786 	if (!ar || ar->state != ATH11K_STATE_OFF)
787 		return 0;
788 
789 	ret = ath11k_dp_rx_pktlog_stop(ab, true);
790 	if (ret) {
791 		ath11k_warn(ab, "failed to stop dp rx (and timer) pktlog during suspend: %d\n",
792 			    ret);
793 		return ret;
794 	}
795 
796 	ret = ath11k_mac_wait_tx_complete(ar);
797 	if (ret) {
798 		ath11k_warn(ab, "failed to wait tx complete: %d\n", ret);
799 		return ret;
800 	}
801 
802 	ret = ath11k_wow_enable(ab);
803 	if (ret) {
804 		ath11k_warn(ab, "failed to enable wow during suspend: %d\n", ret);
805 		return ret;
806 	}
807 
808 	ret = ath11k_dp_rx_pktlog_stop(ab, false);
809 	if (ret) {
810 		ath11k_warn(ab, "failed to stop dp rx pktlog during suspend: %d\n",
811 			    ret);
812 		return ret;
813 	}
814 
815 	ath11k_ce_stop_shadow_timers(ab);
816 	ath11k_dp_stop_shadow_timers(ab);
817 
818 	ath11k_hif_irq_disable(ab);
819 	ath11k_hif_ce_irq_disable(ab);
820 
821 	ret = ath11k_hif_suspend(ab);
822 	if (ret) {
823 		ath11k_warn(ab, "failed to suspend hif: %d\n", ret);
824 		return ret;
825 	}
826 
827 	return 0;
828 }
829 EXPORT_SYMBOL(ath11k_core_suspend);
830 
831 int ath11k_core_resume(struct ath11k_base *ab)
832 {
833 	int ret;
834 	struct ath11k_pdev *pdev;
835 	struct ath11k *ar;
836 
837 	if (!ab->hw_params.supports_suspend)
838 		return -EOPNOTSUPP;
839 
840 	/* so far signle_pdev_only chips have supports_suspend as true
841 	 * and only the first pdev is valid.
842 	 */
843 	pdev = ath11k_core_get_single_pdev(ab);
844 	ar = pdev->ar;
845 	if (!ar || ar->state != ATH11K_STATE_OFF)
846 		return 0;
847 
848 	ret = ath11k_hif_resume(ab);
849 	if (ret) {
850 		ath11k_warn(ab, "failed to resume hif during resume: %d\n", ret);
851 		return ret;
852 	}
853 
854 	ath11k_hif_ce_irq_enable(ab);
855 	ath11k_hif_irq_enable(ab);
856 
857 	ret = ath11k_dp_rx_pktlog_start(ab);
858 	if (ret) {
859 		ath11k_warn(ab, "failed to start rx pktlog during resume: %d\n",
860 			    ret);
861 		return ret;
862 	}
863 
864 	ret = ath11k_wow_wakeup(ab);
865 	if (ret) {
866 		ath11k_warn(ab, "failed to wakeup wow during resume: %d\n", ret);
867 		return ret;
868 	}
869 
870 	return 0;
871 }
872 EXPORT_SYMBOL(ath11k_core_resume);
873 
874 static void ath11k_core_check_cc_code_bdfext(const struct dmi_header *hdr, void *data)
875 {
876 	struct ath11k_base *ab = data;
877 	const char *magic = ATH11K_SMBIOS_BDF_EXT_MAGIC;
878 	struct ath11k_smbios_bdf *smbios = (struct ath11k_smbios_bdf *)hdr;
879 	ssize_t copied;
880 	size_t len;
881 	int i;
882 
883 	if (ab->qmi.target.bdf_ext[0] != '\0')
884 		return;
885 
886 	if (hdr->type != ATH11K_SMBIOS_BDF_EXT_TYPE)
887 		return;
888 
889 	if (hdr->length != ATH11K_SMBIOS_BDF_EXT_LENGTH) {
890 		ath11k_dbg(ab, ATH11K_DBG_BOOT,
891 			   "wrong smbios bdf ext type length (%d).\n",
892 			   hdr->length);
893 		return;
894 	}
895 
896 	spin_lock_bh(&ab->base_lock);
897 
898 	switch (smbios->country_code_flag) {
899 	case ATH11K_SMBIOS_CC_ISO:
900 		ab->new_alpha2[0] = (smbios->cc_code >> 8) & 0xff;
901 		ab->new_alpha2[1] = smbios->cc_code & 0xff;
902 		ath11k_dbg(ab, ATH11K_DBG_BOOT, "smbios cc_code %c%c\n",
903 			   ab->new_alpha2[0], ab->new_alpha2[1]);
904 		break;
905 	case ATH11K_SMBIOS_CC_WW:
906 		ab->new_alpha2[0] = '0';
907 		ab->new_alpha2[1] = '0';
908 		ath11k_dbg(ab, ATH11K_DBG_BOOT, "smbios worldwide regdomain\n");
909 		break;
910 	default:
911 		ath11k_dbg(ab, ATH11K_DBG_BOOT, "ignore smbios country code setting %d\n",
912 			   smbios->country_code_flag);
913 		break;
914 	}
915 
916 	spin_unlock_bh(&ab->base_lock);
917 
918 	if (!smbios->bdf_enabled) {
919 		ath11k_dbg(ab, ATH11K_DBG_BOOT, "bdf variant name not found.\n");
920 		return;
921 	}
922 
923 	/* Only one string exists (per spec) */
924 	if (memcmp(smbios->bdf_ext, magic, strlen(magic)) != 0) {
925 		ath11k_dbg(ab, ATH11K_DBG_BOOT,
926 			   "bdf variant magic does not match.\n");
927 		return;
928 	}
929 
930 	len = min_t(size_t,
931 		    strlen(smbios->bdf_ext), sizeof(ab->qmi.target.bdf_ext));
932 	for (i = 0; i < len; i++) {
933 		if (!isascii(smbios->bdf_ext[i]) || !isprint(smbios->bdf_ext[i])) {
934 			ath11k_dbg(ab, ATH11K_DBG_BOOT,
935 				   "bdf variant name contains non ascii chars.\n");
936 			return;
937 		}
938 	}
939 
940 	/* Copy extension name without magic prefix */
941 	copied = strscpy(ab->qmi.target.bdf_ext, smbios->bdf_ext + strlen(magic),
942 			 sizeof(ab->qmi.target.bdf_ext));
943 	if (copied < 0) {
944 		ath11k_dbg(ab, ATH11K_DBG_BOOT,
945 			   "bdf variant string is longer than the buffer can accommodate\n");
946 		return;
947 	}
948 
949 	ath11k_dbg(ab, ATH11K_DBG_BOOT,
950 		   "found and validated bdf variant smbios_type 0x%x bdf %s\n",
951 		   ATH11K_SMBIOS_BDF_EXT_TYPE, ab->qmi.target.bdf_ext);
952 }
953 
954 int ath11k_core_check_smbios(struct ath11k_base *ab)
955 {
956 	ab->qmi.target.bdf_ext[0] = '\0';
957 	dmi_walk(ath11k_core_check_cc_code_bdfext, ab);
958 
959 	if (ab->qmi.target.bdf_ext[0] == '\0')
960 		return -ENODATA;
961 
962 	return 0;
963 }
964 
965 int ath11k_core_check_dt(struct ath11k_base *ab)
966 {
967 	size_t max_len = sizeof(ab->qmi.target.bdf_ext);
968 	const char *variant = NULL;
969 	struct device_node *node;
970 
971 	node = ab->dev->of_node;
972 	if (!node)
973 		return -ENOENT;
974 
975 	of_property_read_string(node, "qcom,ath11k-calibration-variant",
976 				&variant);
977 	if (!variant)
978 		return -ENODATA;
979 
980 	if (strscpy(ab->qmi.target.bdf_ext, variant, max_len) < 0)
981 		ath11k_dbg(ab, ATH11K_DBG_BOOT,
982 			   "bdf variant string is longer than the buffer can accommodate (variant: %s)\n",
983 			    variant);
984 
985 	return 0;
986 }
987 
988 enum ath11k_bdf_name_type {
989 	ATH11K_BDF_NAME_FULL,
990 	ATH11K_BDF_NAME_BUS_NAME,
991 	ATH11K_BDF_NAME_CHIP_ID,
992 };
993 
994 static int __ath11k_core_create_board_name(struct ath11k_base *ab, char *name,
995 					   size_t name_len, bool with_variant,
996 					   enum ath11k_bdf_name_type name_type)
997 {
998 	/* strlen(',variant=') + strlen(ab->qmi.target.bdf_ext) */
999 	char variant[9 + ATH11K_QMI_BDF_EXT_STR_LENGTH] = { 0 };
1000 
1001 	if (with_variant && ab->qmi.target.bdf_ext[0] != '\0')
1002 		scnprintf(variant, sizeof(variant), ",variant=%s",
1003 			  ab->qmi.target.bdf_ext);
1004 
1005 	switch (ab->id.bdf_search) {
1006 	case ATH11K_BDF_SEARCH_BUS_AND_BOARD:
1007 		switch (name_type) {
1008 		case ATH11K_BDF_NAME_FULL:
1009 			scnprintf(name, name_len,
1010 				  "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x,qmi-chip-id=%d,qmi-board-id=%d%s",
1011 				  ath11k_bus_str(ab->hif.bus),
1012 				  ab->id.vendor, ab->id.device,
1013 				  ab->id.subsystem_vendor,
1014 				  ab->id.subsystem_device,
1015 				  ab->qmi.target.chip_id,
1016 				  ab->qmi.target.board_id,
1017 				  variant);
1018 			break;
1019 		case ATH11K_BDF_NAME_BUS_NAME:
1020 			scnprintf(name, name_len,
1021 				  "bus=%s",
1022 				  ath11k_bus_str(ab->hif.bus));
1023 			break;
1024 		case ATH11K_BDF_NAME_CHIP_ID:
1025 			scnprintf(name, name_len,
1026 				  "bus=%s,qmi-chip-id=%d",
1027 				  ath11k_bus_str(ab->hif.bus),
1028 				  ab->qmi.target.chip_id);
1029 			break;
1030 		}
1031 		break;
1032 	default:
1033 		scnprintf(name, name_len,
1034 			  "bus=%s,qmi-chip-id=%d,qmi-board-id=%d%s",
1035 			  ath11k_bus_str(ab->hif.bus),
1036 			  ab->qmi.target.chip_id,
1037 			  ab->qmi.target.board_id, variant);
1038 		break;
1039 	}
1040 
1041 	ath11k_dbg(ab, ATH11K_DBG_BOOT, "using board name '%s'\n", name);
1042 
1043 	return 0;
1044 }
1045 
1046 static int ath11k_core_create_board_name(struct ath11k_base *ab, char *name,
1047 					 size_t name_len)
1048 {
1049 	return __ath11k_core_create_board_name(ab, name, name_len, true,
1050 					       ATH11K_BDF_NAME_FULL);
1051 }
1052 
1053 static int ath11k_core_create_fallback_board_name(struct ath11k_base *ab, char *name,
1054 						  size_t name_len)
1055 {
1056 	return __ath11k_core_create_board_name(ab, name, name_len, false,
1057 					       ATH11K_BDF_NAME_FULL);
1058 }
1059 
1060 static int ath11k_core_create_bus_type_board_name(struct ath11k_base *ab, char *name,
1061 						  size_t name_len)
1062 {
1063 	return __ath11k_core_create_board_name(ab, name, name_len, false,
1064 					       ATH11K_BDF_NAME_BUS_NAME);
1065 }
1066 
1067 static int ath11k_core_create_chip_id_board_name(struct ath11k_base *ab, char *name,
1068 						 size_t name_len)
1069 {
1070 	return __ath11k_core_create_board_name(ab, name, name_len, false,
1071 					       ATH11K_BDF_NAME_CHIP_ID);
1072 }
1073 
1074 const struct firmware *ath11k_core_firmware_request(struct ath11k_base *ab,
1075 						    const char *file)
1076 {
1077 	const struct firmware *fw;
1078 	char path[100];
1079 	int ret;
1080 
1081 	if (file == NULL)
1082 		return ERR_PTR(-ENOENT);
1083 
1084 	ath11k_core_create_firmware_path(ab, file, path, sizeof(path));
1085 
1086 	ret = firmware_request_nowarn(&fw, path, ab->dev);
1087 	if (ret)
1088 		return ERR_PTR(ret);
1089 
1090 	ath11k_dbg(ab, ATH11K_DBG_BOOT, "firmware request %s size %zu\n",
1091 		   path, fw->size);
1092 
1093 	return fw;
1094 }
1095 
1096 void ath11k_core_free_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd)
1097 {
1098 	if (!IS_ERR(bd->fw))
1099 		release_firmware(bd->fw);
1100 
1101 	memset(bd, 0, sizeof(*bd));
1102 }
1103 
1104 static int ath11k_core_parse_bd_ie_board(struct ath11k_base *ab,
1105 					 struct ath11k_board_data *bd,
1106 					 const void *buf, size_t buf_len,
1107 					 const char *boardname,
1108 					 int ie_id,
1109 					 int name_id,
1110 					 int data_id)
1111 {
1112 	const struct ath11k_fw_ie *hdr;
1113 	bool name_match_found;
1114 	int ret, board_ie_id;
1115 	size_t board_ie_len;
1116 	const void *board_ie_data;
1117 
1118 	name_match_found = false;
1119 
1120 	/* go through ATH11K_BD_IE_BOARD_/ATH11K_BD_IE_REGDB_ elements */
1121 	while (buf_len > sizeof(struct ath11k_fw_ie)) {
1122 		hdr = buf;
1123 		board_ie_id = le32_to_cpu(hdr->id);
1124 		board_ie_len = le32_to_cpu(hdr->len);
1125 		board_ie_data = hdr->data;
1126 
1127 		buf_len -= sizeof(*hdr);
1128 		buf += sizeof(*hdr);
1129 
1130 		if (buf_len < ALIGN(board_ie_len, 4)) {
1131 			ath11k_err(ab, "invalid %s length: %zu < %zu\n",
1132 				   ath11k_bd_ie_type_str(ie_id),
1133 				   buf_len, ALIGN(board_ie_len, 4));
1134 			ret = -EINVAL;
1135 			goto out;
1136 		}
1137 
1138 		if (board_ie_id == name_id) {
1139 			ath11k_dbg_dump(ab, ATH11K_DBG_BOOT, "board name", "",
1140 					board_ie_data, board_ie_len);
1141 
1142 			if (board_ie_len != strlen(boardname))
1143 				goto next;
1144 
1145 			ret = memcmp(board_ie_data, boardname, strlen(boardname));
1146 			if (ret)
1147 				goto next;
1148 
1149 			name_match_found = true;
1150 			ath11k_dbg(ab, ATH11K_DBG_BOOT,
1151 				   "found match %s for name '%s'",
1152 				   ath11k_bd_ie_type_str(ie_id),
1153 				   boardname);
1154 		} else if (board_ie_id == data_id) {
1155 			if (!name_match_found)
1156 				/* no match found */
1157 				goto next;
1158 
1159 			ath11k_dbg(ab, ATH11K_DBG_BOOT,
1160 				   "found %s for '%s'",
1161 				   ath11k_bd_ie_type_str(ie_id),
1162 				   boardname);
1163 
1164 			bd->data = board_ie_data;
1165 			bd->len = board_ie_len;
1166 
1167 			ret = 0;
1168 			goto out;
1169 		} else {
1170 			ath11k_warn(ab, "unknown %s id found: %d\n",
1171 				    ath11k_bd_ie_type_str(ie_id),
1172 				    board_ie_id);
1173 		}
1174 next:
1175 		/* jump over the padding */
1176 		board_ie_len = ALIGN(board_ie_len, 4);
1177 
1178 		buf_len -= board_ie_len;
1179 		buf += board_ie_len;
1180 	}
1181 
1182 	/* no match found */
1183 	ret = -ENOENT;
1184 
1185 out:
1186 	return ret;
1187 }
1188 
1189 static int ath11k_core_fetch_board_data_api_n(struct ath11k_base *ab,
1190 					      struct ath11k_board_data *bd,
1191 					      const char *boardname,
1192 					      int ie_id_match,
1193 					      int name_id,
1194 					      int data_id)
1195 {
1196 	size_t len, magic_len;
1197 	const u8 *data;
1198 	char *filename, filepath[100];
1199 	size_t ie_len;
1200 	struct ath11k_fw_ie *hdr;
1201 	int ret, ie_id;
1202 
1203 	filename = ATH11K_BOARD_API2_FILE;
1204 
1205 	if (!bd->fw)
1206 		bd->fw = ath11k_core_firmware_request(ab, filename);
1207 
1208 	if (IS_ERR(bd->fw))
1209 		return PTR_ERR(bd->fw);
1210 
1211 	data = bd->fw->data;
1212 	len = bd->fw->size;
1213 
1214 	ath11k_core_create_firmware_path(ab, filename,
1215 					 filepath, sizeof(filepath));
1216 
1217 	/* magic has extra null byte padded */
1218 	magic_len = strlen(ATH11K_BOARD_MAGIC) + 1;
1219 	if (len < magic_len) {
1220 		ath11k_err(ab, "failed to find magic value in %s, file too short: %zu\n",
1221 			   filepath, len);
1222 		ret = -EINVAL;
1223 		goto err;
1224 	}
1225 
1226 	if (memcmp(data, ATH11K_BOARD_MAGIC, magic_len)) {
1227 		ath11k_err(ab, "found invalid board magic\n");
1228 		ret = -EINVAL;
1229 		goto err;
1230 	}
1231 
1232 	/* magic is padded to 4 bytes */
1233 	magic_len = ALIGN(magic_len, 4);
1234 	if (len < magic_len) {
1235 		ath11k_err(ab, "failed: %s too small to contain board data, len: %zu\n",
1236 			   filepath, len);
1237 		ret = -EINVAL;
1238 		goto err;
1239 	}
1240 
1241 	data += magic_len;
1242 	len -= magic_len;
1243 
1244 	while (len > sizeof(struct ath11k_fw_ie)) {
1245 		hdr = (struct ath11k_fw_ie *)data;
1246 		ie_id = le32_to_cpu(hdr->id);
1247 		ie_len = le32_to_cpu(hdr->len);
1248 
1249 		len -= sizeof(*hdr);
1250 		data = hdr->data;
1251 
1252 		if (len < ALIGN(ie_len, 4)) {
1253 			ath11k_err(ab, "invalid length for board ie_id %d ie_len %zu len %zu\n",
1254 				   ie_id, ie_len, len);
1255 			ret = -EINVAL;
1256 			goto err;
1257 		}
1258 
1259 		if (ie_id == ie_id_match) {
1260 			ret = ath11k_core_parse_bd_ie_board(ab, bd, data,
1261 							    ie_len,
1262 							    boardname,
1263 							    ie_id_match,
1264 							    name_id,
1265 							    data_id);
1266 			if (ret == -ENOENT)
1267 				/* no match found, continue */
1268 				goto next;
1269 			else if (ret)
1270 				/* there was an error, bail out */
1271 				goto err;
1272 			/* either found or error, so stop searching */
1273 			goto out;
1274 		}
1275 next:
1276 		/* jump over the padding */
1277 		ie_len = ALIGN(ie_len, 4);
1278 
1279 		len -= ie_len;
1280 		data += ie_len;
1281 	}
1282 
1283 out:
1284 	if (!bd->data || !bd->len) {
1285 		ath11k_dbg(ab, ATH11K_DBG_BOOT,
1286 			   "failed to fetch %s for %s from %s\n",
1287 			   ath11k_bd_ie_type_str(ie_id_match),
1288 			   boardname, filepath);
1289 		ret = -ENODATA;
1290 		goto err;
1291 	}
1292 
1293 	return 0;
1294 
1295 err:
1296 	ath11k_core_free_bdf(ab, bd);
1297 	return ret;
1298 }
1299 
1300 int ath11k_core_fetch_board_data_api_1(struct ath11k_base *ab,
1301 				       struct ath11k_board_data *bd,
1302 				       const char *name)
1303 {
1304 	bd->fw = ath11k_core_firmware_request(ab, name);
1305 
1306 	if (IS_ERR(bd->fw))
1307 		return PTR_ERR(bd->fw);
1308 
1309 	bd->data = bd->fw->data;
1310 	bd->len = bd->fw->size;
1311 
1312 	return 0;
1313 }
1314 
1315 #define BOARD_NAME_SIZE 200
1316 int ath11k_core_fetch_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd)
1317 {
1318 	char *boardname = NULL, *fallback_boardname = NULL, *chip_id_boardname = NULL;
1319 	char *filename, filepath[100];
1320 	int ret = 0;
1321 
1322 	filename = ATH11K_BOARD_API2_FILE;
1323 	boardname = kzalloc(BOARD_NAME_SIZE, GFP_KERNEL);
1324 	if (!boardname) {
1325 		ret = -ENOMEM;
1326 		goto exit;
1327 	}
1328 
1329 	ret = ath11k_core_create_board_name(ab, boardname, BOARD_NAME_SIZE);
1330 	if (ret) {
1331 		ath11k_err(ab, "failed to create board name: %d", ret);
1332 		goto exit;
1333 	}
1334 
1335 	ab->bd_api = 2;
1336 	ret = ath11k_core_fetch_board_data_api_n(ab, bd, boardname,
1337 						 ATH11K_BD_IE_BOARD,
1338 						 ATH11K_BD_IE_BOARD_NAME,
1339 						 ATH11K_BD_IE_BOARD_DATA);
1340 	if (!ret)
1341 		goto exit;
1342 
1343 	fallback_boardname = kzalloc(BOARD_NAME_SIZE, GFP_KERNEL);
1344 	if (!fallback_boardname) {
1345 		ret = -ENOMEM;
1346 		goto exit;
1347 	}
1348 
1349 	ret = ath11k_core_create_fallback_board_name(ab, fallback_boardname,
1350 						     BOARD_NAME_SIZE);
1351 	if (ret) {
1352 		ath11k_err(ab, "failed to create fallback board name: %d", ret);
1353 		goto exit;
1354 	}
1355 
1356 	ret = ath11k_core_fetch_board_data_api_n(ab, bd, fallback_boardname,
1357 						 ATH11K_BD_IE_BOARD,
1358 						 ATH11K_BD_IE_BOARD_NAME,
1359 						 ATH11K_BD_IE_BOARD_DATA);
1360 	if (!ret)
1361 		goto exit;
1362 
1363 	chip_id_boardname = kzalloc(BOARD_NAME_SIZE, GFP_KERNEL);
1364 	if (!chip_id_boardname) {
1365 		ret = -ENOMEM;
1366 		goto exit;
1367 	}
1368 
1369 	ret = ath11k_core_create_chip_id_board_name(ab, chip_id_boardname,
1370 						    BOARD_NAME_SIZE);
1371 	if (ret) {
1372 		ath11k_err(ab, "failed to create chip id board name: %d", ret);
1373 		goto exit;
1374 	}
1375 
1376 	ret = ath11k_core_fetch_board_data_api_n(ab, bd, chip_id_boardname,
1377 						 ATH11K_BD_IE_BOARD,
1378 						 ATH11K_BD_IE_BOARD_NAME,
1379 						 ATH11K_BD_IE_BOARD_DATA);
1380 
1381 	if (!ret)
1382 		goto exit;
1383 
1384 	ab->bd_api = 1;
1385 	ret = ath11k_core_fetch_board_data_api_1(ab, bd, ATH11K_DEFAULT_BOARD_FILE);
1386 	if (ret) {
1387 		ath11k_core_create_firmware_path(ab, filename,
1388 						 filepath, sizeof(filepath));
1389 		ath11k_err(ab, "failed to fetch board data for %s from %s\n",
1390 			   boardname, filepath);
1391 		if (memcmp(boardname, fallback_boardname, strlen(boardname)))
1392 			ath11k_err(ab, "failed to fetch board data for %s from %s\n",
1393 				   fallback_boardname, filepath);
1394 
1395 		ath11k_err(ab, "failed to fetch board data for %s from %s\n",
1396 			   chip_id_boardname, filepath);
1397 
1398 		ath11k_err(ab, "failed to fetch board.bin from %s\n",
1399 			   ab->hw_params.fw.dir);
1400 	}
1401 
1402 exit:
1403 	kfree(boardname);
1404 	kfree(fallback_boardname);
1405 	kfree(chip_id_boardname);
1406 
1407 	if (!ret)
1408 		ath11k_dbg(ab, ATH11K_DBG_BOOT, "using board api %d\n", ab->bd_api);
1409 
1410 	return ret;
1411 }
1412 
1413 int ath11k_core_fetch_regdb(struct ath11k_base *ab, struct ath11k_board_data *bd)
1414 {
1415 	char boardname[BOARD_NAME_SIZE], default_boardname[BOARD_NAME_SIZE];
1416 	int ret;
1417 
1418 	ret = ath11k_core_create_board_name(ab, boardname, BOARD_NAME_SIZE);
1419 	if (ret) {
1420 		ath11k_dbg(ab, ATH11K_DBG_BOOT,
1421 			   "failed to create board name for regdb: %d", ret);
1422 		goto exit;
1423 	}
1424 
1425 	ret = ath11k_core_fetch_board_data_api_n(ab, bd, boardname,
1426 						 ATH11K_BD_IE_REGDB,
1427 						 ATH11K_BD_IE_REGDB_NAME,
1428 						 ATH11K_BD_IE_REGDB_DATA);
1429 	if (!ret)
1430 		goto exit;
1431 
1432 	ret = ath11k_core_create_bus_type_board_name(ab, default_boardname,
1433 						     BOARD_NAME_SIZE);
1434 	if (ret) {
1435 		ath11k_dbg(ab, ATH11K_DBG_BOOT,
1436 			   "failed to create default board name for regdb: %d", ret);
1437 		goto exit;
1438 	}
1439 
1440 	ret = ath11k_core_fetch_board_data_api_n(ab, bd, default_boardname,
1441 						 ATH11K_BD_IE_REGDB,
1442 						 ATH11K_BD_IE_REGDB_NAME,
1443 						 ATH11K_BD_IE_REGDB_DATA);
1444 	if (!ret)
1445 		goto exit;
1446 
1447 	ret = ath11k_core_fetch_board_data_api_1(ab, bd, ATH11K_REGDB_FILE_NAME);
1448 	if (ret)
1449 		ath11k_dbg(ab, ATH11K_DBG_BOOT, "failed to fetch %s from %s\n",
1450 			   ATH11K_REGDB_FILE_NAME, ab->hw_params.fw.dir);
1451 
1452 exit:
1453 	if (!ret)
1454 		ath11k_dbg(ab, ATH11K_DBG_BOOT, "fetched regdb\n");
1455 
1456 	return ret;
1457 }
1458 
1459 static void ath11k_core_stop(struct ath11k_base *ab)
1460 {
1461 	if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))
1462 		ath11k_qmi_firmware_stop(ab);
1463 
1464 	ath11k_hif_stop(ab);
1465 	ath11k_wmi_detach(ab);
1466 	ath11k_dp_pdev_reo_cleanup(ab);
1467 
1468 	/* De-Init of components as needed */
1469 }
1470 
1471 static int ath11k_core_soc_create(struct ath11k_base *ab)
1472 {
1473 	int ret;
1474 
1475 	if (ath11k_ftm_mode) {
1476 		ab->fw_mode = ATH11K_FIRMWARE_MODE_FTM;
1477 		ath11k_info(ab, "Booting in factory test mode\n");
1478 	}
1479 
1480 	ret = ath11k_qmi_init_service(ab);
1481 	if (ret) {
1482 		ath11k_err(ab, "failed to initialize qmi :%d\n", ret);
1483 		return ret;
1484 	}
1485 
1486 	ret = ath11k_debugfs_soc_create(ab);
1487 	if (ret) {
1488 		ath11k_err(ab, "failed to create ath11k debugfs\n");
1489 		goto err_qmi_deinit;
1490 	}
1491 
1492 	ret = ath11k_hif_power_up(ab);
1493 	if (ret) {
1494 		ath11k_err(ab, "failed to power up :%d\n", ret);
1495 		goto err_debugfs_reg;
1496 	}
1497 
1498 	return 0;
1499 
1500 err_debugfs_reg:
1501 	ath11k_debugfs_soc_destroy(ab);
1502 err_qmi_deinit:
1503 	ath11k_qmi_deinit_service(ab);
1504 	return ret;
1505 }
1506 
1507 static void ath11k_core_soc_destroy(struct ath11k_base *ab)
1508 {
1509 	ath11k_debugfs_soc_destroy(ab);
1510 	ath11k_dp_free(ab);
1511 	ath11k_reg_free(ab);
1512 	ath11k_qmi_deinit_service(ab);
1513 }
1514 
1515 static int ath11k_core_pdev_create(struct ath11k_base *ab)
1516 {
1517 	int ret;
1518 
1519 	ret = ath11k_debugfs_pdev_create(ab);
1520 	if (ret) {
1521 		ath11k_err(ab, "failed to create core pdev debugfs: %d\n", ret);
1522 		return ret;
1523 	}
1524 
1525 	ret = ath11k_dp_pdev_alloc(ab);
1526 	if (ret) {
1527 		ath11k_err(ab, "failed to attach DP pdev: %d\n", ret);
1528 		goto err_pdev_debug;
1529 	}
1530 
1531 	ret = ath11k_mac_register(ab);
1532 	if (ret) {
1533 		ath11k_err(ab, "failed register the radio with mac80211: %d\n", ret);
1534 		goto err_dp_pdev_free;
1535 	}
1536 
1537 	ret = ath11k_thermal_register(ab);
1538 	if (ret) {
1539 		ath11k_err(ab, "could not register thermal device: %d\n",
1540 			   ret);
1541 		goto err_mac_unregister;
1542 	}
1543 
1544 	ret = ath11k_spectral_init(ab);
1545 	if (ret) {
1546 		ath11k_err(ab, "failed to init spectral %d\n", ret);
1547 		goto err_thermal_unregister;
1548 	}
1549 
1550 	return 0;
1551 
1552 err_thermal_unregister:
1553 	ath11k_thermal_unregister(ab);
1554 err_mac_unregister:
1555 	ath11k_mac_unregister(ab);
1556 err_dp_pdev_free:
1557 	ath11k_dp_pdev_free(ab);
1558 err_pdev_debug:
1559 	ath11k_debugfs_pdev_destroy(ab);
1560 
1561 	return ret;
1562 }
1563 
1564 static void ath11k_core_pdev_destroy(struct ath11k_base *ab)
1565 {
1566 	ath11k_spectral_deinit(ab);
1567 	ath11k_thermal_unregister(ab);
1568 	ath11k_mac_unregister(ab);
1569 	ath11k_hif_irq_disable(ab);
1570 	ath11k_dp_pdev_free(ab);
1571 	ath11k_debugfs_pdev_destroy(ab);
1572 }
1573 
1574 static int ath11k_core_start(struct ath11k_base *ab)
1575 {
1576 	int ret;
1577 
1578 	ret = ath11k_wmi_attach(ab);
1579 	if (ret) {
1580 		ath11k_err(ab, "failed to attach wmi: %d\n", ret);
1581 		return ret;
1582 	}
1583 
1584 	ret = ath11k_htc_init(ab);
1585 	if (ret) {
1586 		ath11k_err(ab, "failed to init htc: %d\n", ret);
1587 		goto err_wmi_detach;
1588 	}
1589 
1590 	ret = ath11k_hif_start(ab);
1591 	if (ret) {
1592 		ath11k_err(ab, "failed to start HIF: %d\n", ret);
1593 		goto err_wmi_detach;
1594 	}
1595 
1596 	ret = ath11k_htc_wait_target(&ab->htc);
1597 	if (ret) {
1598 		ath11k_err(ab, "failed to connect to HTC: %d\n", ret);
1599 		goto err_hif_stop;
1600 	}
1601 
1602 	ret = ath11k_dp_htt_connect(&ab->dp);
1603 	if (ret) {
1604 		ath11k_err(ab, "failed to connect to HTT: %d\n", ret);
1605 		goto err_hif_stop;
1606 	}
1607 
1608 	ret = ath11k_wmi_connect(ab);
1609 	if (ret) {
1610 		ath11k_err(ab, "failed to connect wmi: %d\n", ret);
1611 		goto err_hif_stop;
1612 	}
1613 
1614 	ret = ath11k_htc_start(&ab->htc);
1615 	if (ret) {
1616 		ath11k_err(ab, "failed to start HTC: %d\n", ret);
1617 		goto err_hif_stop;
1618 	}
1619 
1620 	ret = ath11k_wmi_wait_for_service_ready(ab);
1621 	if (ret) {
1622 		ath11k_err(ab, "failed to receive wmi service ready event: %d\n",
1623 			   ret);
1624 		goto err_hif_stop;
1625 	}
1626 
1627 	ret = ath11k_mac_allocate(ab);
1628 	if (ret) {
1629 		ath11k_err(ab, "failed to create new hw device with mac80211 :%d\n",
1630 			   ret);
1631 		goto err_hif_stop;
1632 	}
1633 
1634 	ath11k_dp_pdev_pre_alloc(ab);
1635 
1636 	ret = ath11k_dp_pdev_reo_setup(ab);
1637 	if (ret) {
1638 		ath11k_err(ab, "failed to initialize reo destination rings: %d\n", ret);
1639 		goto err_mac_destroy;
1640 	}
1641 
1642 	ret = ath11k_wmi_cmd_init(ab);
1643 	if (ret) {
1644 		ath11k_err(ab, "failed to send wmi init cmd: %d\n", ret);
1645 		goto err_reo_cleanup;
1646 	}
1647 
1648 	ret = ath11k_wmi_wait_for_unified_ready(ab);
1649 	if (ret) {
1650 		ath11k_err(ab, "failed to receive wmi unified ready event: %d\n",
1651 			   ret);
1652 		goto err_reo_cleanup;
1653 	}
1654 
1655 	/* put hardware to DBS mode */
1656 	if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1) {
1657 		ret = ath11k_wmi_set_hw_mode(ab, WMI_HOST_HW_MODE_DBS);
1658 		if (ret) {
1659 			ath11k_err(ab, "failed to send dbs mode: %d\n", ret);
1660 			goto err_hif_stop;
1661 		}
1662 	}
1663 
1664 	ret = ath11k_dp_tx_htt_h2t_ver_req_msg(ab);
1665 	if (ret) {
1666 		ath11k_err(ab, "failed to send htt version request message: %d\n",
1667 			   ret);
1668 		goto err_reo_cleanup;
1669 	}
1670 
1671 	return 0;
1672 
1673 err_reo_cleanup:
1674 	ath11k_dp_pdev_reo_cleanup(ab);
1675 err_mac_destroy:
1676 	ath11k_mac_destroy(ab);
1677 err_hif_stop:
1678 	ath11k_hif_stop(ab);
1679 err_wmi_detach:
1680 	ath11k_wmi_detach(ab);
1681 
1682 	return ret;
1683 }
1684 
1685 static int ath11k_core_start_firmware(struct ath11k_base *ab,
1686 				      enum ath11k_firmware_mode mode)
1687 {
1688 	int ret;
1689 
1690 	ath11k_ce_get_shadow_config(ab, &ab->qmi.ce_cfg.shadow_reg_v2,
1691 				    &ab->qmi.ce_cfg.shadow_reg_v2_len);
1692 
1693 	ret = ath11k_qmi_firmware_start(ab, mode);
1694 	if (ret) {
1695 		ath11k_err(ab, "failed to send firmware start: %d\n", ret);
1696 		return ret;
1697 	}
1698 
1699 	return ret;
1700 }
1701 
1702 int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab)
1703 {
1704 	int ret;
1705 
1706 	ret = ath11k_core_start_firmware(ab, ab->fw_mode);
1707 	if (ret) {
1708 		ath11k_err(ab, "failed to start firmware: %d\n", ret);
1709 		return ret;
1710 	}
1711 
1712 	ret = ath11k_ce_init_pipes(ab);
1713 	if (ret) {
1714 		ath11k_err(ab, "failed to initialize CE: %d\n", ret);
1715 		goto err_firmware_stop;
1716 	}
1717 
1718 	ret = ath11k_dp_alloc(ab);
1719 	if (ret) {
1720 		ath11k_err(ab, "failed to init DP: %d\n", ret);
1721 		goto err_firmware_stop;
1722 	}
1723 
1724 	switch (ath11k_crypto_mode) {
1725 	case ATH11K_CRYPT_MODE_SW:
1726 		set_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags);
1727 		set_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags);
1728 		break;
1729 	case ATH11K_CRYPT_MODE_HW:
1730 		clear_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags);
1731 		clear_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags);
1732 		break;
1733 	default:
1734 		ath11k_info(ab, "invalid crypto_mode: %d\n", ath11k_crypto_mode);
1735 		return -EINVAL;
1736 	}
1737 
1738 	if (ath11k_frame_mode == ATH11K_HW_TXRX_RAW)
1739 		set_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags);
1740 
1741 	mutex_lock(&ab->core_lock);
1742 	ret = ath11k_core_start(ab);
1743 	if (ret) {
1744 		ath11k_err(ab, "failed to start core: %d\n", ret);
1745 		goto err_dp_free;
1746 	}
1747 
1748 	ret = ath11k_core_pdev_create(ab);
1749 	if (ret) {
1750 		ath11k_err(ab, "failed to create pdev core: %d\n", ret);
1751 		goto err_core_stop;
1752 	}
1753 	ath11k_hif_irq_enable(ab);
1754 	mutex_unlock(&ab->core_lock);
1755 
1756 	return 0;
1757 
1758 err_core_stop:
1759 	ath11k_core_stop(ab);
1760 	ath11k_mac_destroy(ab);
1761 err_dp_free:
1762 	ath11k_dp_free(ab);
1763 	mutex_unlock(&ab->core_lock);
1764 err_firmware_stop:
1765 	ath11k_qmi_firmware_stop(ab);
1766 
1767 	return ret;
1768 }
1769 
1770 static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab)
1771 {
1772 	int ret;
1773 
1774 	mutex_lock(&ab->core_lock);
1775 	ath11k_thermal_unregister(ab);
1776 	ath11k_hif_irq_disable(ab);
1777 	ath11k_dp_pdev_free(ab);
1778 	ath11k_spectral_deinit(ab);
1779 	ath11k_hif_stop(ab);
1780 	ath11k_wmi_detach(ab);
1781 	ath11k_dp_pdev_reo_cleanup(ab);
1782 	mutex_unlock(&ab->core_lock);
1783 
1784 	ath11k_dp_free(ab);
1785 	ath11k_hal_srng_deinit(ab);
1786 
1787 	ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS(ab))) - 1;
1788 
1789 	ret = ath11k_hal_srng_init(ab);
1790 	if (ret)
1791 		return ret;
1792 
1793 	clear_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags);
1794 
1795 	ret = ath11k_core_qmi_firmware_ready(ab);
1796 	if (ret)
1797 		goto err_hal_srng_deinit;
1798 
1799 	clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);
1800 
1801 	return 0;
1802 
1803 err_hal_srng_deinit:
1804 	ath11k_hal_srng_deinit(ab);
1805 	return ret;
1806 }
1807 
1808 void ath11k_core_halt(struct ath11k *ar)
1809 {
1810 	struct ath11k_base *ab = ar->ab;
1811 
1812 	lockdep_assert_held(&ar->conf_mutex);
1813 
1814 	ar->num_created_vdevs = 0;
1815 	ar->allocated_vdev_map = 0;
1816 
1817 	ath11k_mac_scan_finish(ar);
1818 	ath11k_mac_peer_cleanup_all(ar);
1819 	cancel_delayed_work_sync(&ar->scan.timeout);
1820 	cancel_work_sync(&ar->regd_update_work);
1821 	cancel_work_sync(&ab->update_11d_work);
1822 
1823 	rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], NULL);
1824 	synchronize_rcu();
1825 	INIT_LIST_HEAD(&ar->arvifs);
1826 	idr_init(&ar->txmgmt_idr);
1827 }
1828 
1829 static void ath11k_update_11d(struct work_struct *work)
1830 {
1831 	struct ath11k_base *ab = container_of(work, struct ath11k_base, update_11d_work);
1832 	struct ath11k *ar;
1833 	struct ath11k_pdev *pdev;
1834 	struct wmi_set_current_country_params set_current_param = {};
1835 	int ret, i;
1836 
1837 	spin_lock_bh(&ab->base_lock);
1838 	memcpy(&set_current_param.alpha2, &ab->new_alpha2, 2);
1839 	spin_unlock_bh(&ab->base_lock);
1840 
1841 	ath11k_dbg(ab, ATH11K_DBG_WMI, "update 11d new cc %c%c\n",
1842 		   set_current_param.alpha2[0],
1843 		   set_current_param.alpha2[1]);
1844 
1845 	for (i = 0; i < ab->num_radios; i++) {
1846 		pdev = &ab->pdevs[i];
1847 		ar = pdev->ar;
1848 
1849 		memcpy(&ar->alpha2, &set_current_param.alpha2, 2);
1850 		ret = ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param);
1851 		if (ret)
1852 			ath11k_warn(ar->ab,
1853 				    "pdev id %d failed set current country code: %d\n",
1854 				    i, ret);
1855 	}
1856 }
1857 
1858 void ath11k_core_pre_reconfigure_recovery(struct ath11k_base *ab)
1859 {
1860 	struct ath11k *ar;
1861 	struct ath11k_pdev *pdev;
1862 	int i;
1863 
1864 	spin_lock_bh(&ab->base_lock);
1865 	ab->stats.fw_crash_counter++;
1866 	spin_unlock_bh(&ab->base_lock);
1867 
1868 	for (i = 0; i < ab->num_radios; i++) {
1869 		pdev = &ab->pdevs[i];
1870 		ar = pdev->ar;
1871 		if (!ar || ar->state == ATH11K_STATE_OFF ||
1872 		    ar->state == ATH11K_STATE_FTM)
1873 			continue;
1874 
1875 		ieee80211_stop_queues(ar->hw);
1876 		ath11k_mac_drain_tx(ar);
1877 		ar->state_11d = ATH11K_11D_IDLE;
1878 		complete(&ar->completed_11d_scan);
1879 		complete(&ar->scan.started);
1880 		complete_all(&ar->scan.completed);
1881 		complete(&ar->scan.on_channel);
1882 		complete(&ar->peer_assoc_done);
1883 		complete(&ar->peer_delete_done);
1884 		complete(&ar->install_key_done);
1885 		complete(&ar->vdev_setup_done);
1886 		complete(&ar->vdev_delete_done);
1887 		complete(&ar->bss_survey_done);
1888 		complete(&ar->thermal.wmi_sync);
1889 
1890 		wake_up(&ar->dp.tx_empty_waitq);
1891 		idr_for_each(&ar->txmgmt_idr,
1892 			     ath11k_mac_tx_mgmt_pending_free, ar);
1893 		idr_destroy(&ar->txmgmt_idr);
1894 		wake_up(&ar->txmgmt_empty_waitq);
1895 
1896 		ar->monitor_vdev_id = -1;
1897 		clear_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags);
1898 		clear_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
1899 	}
1900 
1901 	wake_up(&ab->wmi_ab.tx_credits_wq);
1902 	wake_up(&ab->peer_mapping_wq);
1903 
1904 	reinit_completion(&ab->driver_recovery);
1905 }
1906 
1907 static void ath11k_core_post_reconfigure_recovery(struct ath11k_base *ab)
1908 {
1909 	struct ath11k *ar;
1910 	struct ath11k_pdev *pdev;
1911 	int i;
1912 
1913 	for (i = 0; i < ab->num_radios; i++) {
1914 		pdev = &ab->pdevs[i];
1915 		ar = pdev->ar;
1916 		if (!ar || ar->state == ATH11K_STATE_OFF)
1917 			continue;
1918 
1919 		mutex_lock(&ar->conf_mutex);
1920 
1921 		switch (ar->state) {
1922 		case ATH11K_STATE_ON:
1923 			ar->state = ATH11K_STATE_RESTARTING;
1924 			ath11k_core_halt(ar);
1925 			ieee80211_restart_hw(ar->hw);
1926 			break;
1927 		case ATH11K_STATE_OFF:
1928 			ath11k_warn(ab,
1929 				    "cannot restart radio %d that hasn't been started\n",
1930 				    i);
1931 			break;
1932 		case ATH11K_STATE_RESTARTING:
1933 			break;
1934 		case ATH11K_STATE_RESTARTED:
1935 			ar->state = ATH11K_STATE_WEDGED;
1936 			fallthrough;
1937 		case ATH11K_STATE_WEDGED:
1938 			ath11k_warn(ab,
1939 				    "device is wedged, will not restart radio %d\n", i);
1940 			break;
1941 		case ATH11K_STATE_FTM:
1942 			ath11k_dbg(ab, ATH11K_DBG_TESTMODE,
1943 				   "fw mode reset done radio %d\n", i);
1944 			break;
1945 		}
1946 
1947 		mutex_unlock(&ar->conf_mutex);
1948 	}
1949 	complete(&ab->driver_recovery);
1950 }
1951 
1952 static void ath11k_core_restart(struct work_struct *work)
1953 {
1954 	struct ath11k_base *ab = container_of(work, struct ath11k_base, restart_work);
1955 	int ret;
1956 
1957 	ret = ath11k_core_reconfigure_on_crash(ab);
1958 	if (ret) {
1959 		ath11k_err(ab, "failed to reconfigure driver on crash recovery\n");
1960 		return;
1961 	}
1962 
1963 	if (ab->is_reset)
1964 		complete_all(&ab->reconfigure_complete);
1965 
1966 	if (!ab->is_reset)
1967 		ath11k_core_post_reconfigure_recovery(ab);
1968 }
1969 
1970 static void ath11k_core_reset(struct work_struct *work)
1971 {
1972 	struct ath11k_base *ab = container_of(work, struct ath11k_base, reset_work);
1973 	int reset_count, fail_cont_count;
1974 	long time_left;
1975 
1976 	if (!(test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))) {
1977 		ath11k_warn(ab, "ignore reset dev flags 0x%lx\n", ab->dev_flags);
1978 		return;
1979 	}
1980 
1981 	/* Sometimes the recovery will fail and then the next all recovery fail,
1982 	 * this is to avoid infinite recovery since it can not recovery success.
1983 	 */
1984 	fail_cont_count = atomic_read(&ab->fail_cont_count);
1985 
1986 	if (fail_cont_count >= ATH11K_RESET_MAX_FAIL_COUNT_FINAL)
1987 		return;
1988 
1989 	if (fail_cont_count >= ATH11K_RESET_MAX_FAIL_COUNT_FIRST &&
1990 	    time_before(jiffies, ab->reset_fail_timeout))
1991 		return;
1992 
1993 	reset_count = atomic_inc_return(&ab->reset_count);
1994 
1995 	if (reset_count > 1) {
1996 		/* Sometimes it happened another reset worker before the previous one
1997 		 * completed, then the second reset worker will destroy the previous one,
1998 		 * thus below is to avoid that.
1999 		 */
2000 		ath11k_warn(ab, "already resetting count %d\n", reset_count);
2001 
2002 		reinit_completion(&ab->reset_complete);
2003 		time_left = wait_for_completion_timeout(&ab->reset_complete,
2004 							ATH11K_RESET_TIMEOUT_HZ);
2005 
2006 		if (time_left) {
2007 			ath11k_dbg(ab, ATH11K_DBG_BOOT, "to skip reset\n");
2008 			atomic_dec(&ab->reset_count);
2009 			return;
2010 		}
2011 
2012 		ab->reset_fail_timeout = jiffies + ATH11K_RESET_FAIL_TIMEOUT_HZ;
2013 		/* Record the continuous recovery fail count when recovery failed*/
2014 		atomic_inc(&ab->fail_cont_count);
2015 	}
2016 
2017 	ath11k_dbg(ab, ATH11K_DBG_BOOT, "reset starting\n");
2018 
2019 	ab->is_reset = true;
2020 	atomic_set(&ab->recovery_count, 0);
2021 	reinit_completion(&ab->recovery_start);
2022 	atomic_set(&ab->recovery_start_count, 0);
2023 
2024 	ath11k_core_pre_reconfigure_recovery(ab);
2025 
2026 	reinit_completion(&ab->reconfigure_complete);
2027 	ath11k_core_post_reconfigure_recovery(ab);
2028 
2029 	ath11k_dbg(ab, ATH11K_DBG_BOOT, "waiting recovery start...\n");
2030 
2031 	time_left = wait_for_completion_timeout(&ab->recovery_start,
2032 						ATH11K_RECOVER_START_TIMEOUT_HZ);
2033 
2034 	ath11k_hif_power_down(ab);
2035 	ath11k_hif_power_up(ab);
2036 
2037 	ath11k_dbg(ab, ATH11K_DBG_BOOT, "reset started\n");
2038 }
2039 
2040 static int ath11k_init_hw_params(struct ath11k_base *ab)
2041 {
2042 	const struct ath11k_hw_params *hw_params = NULL;
2043 	int i;
2044 
2045 	for (i = 0; i < ARRAY_SIZE(ath11k_hw_params); i++) {
2046 		hw_params = &ath11k_hw_params[i];
2047 
2048 		if (hw_params->hw_rev == ab->hw_rev)
2049 			break;
2050 	}
2051 
2052 	if (i == ARRAY_SIZE(ath11k_hw_params)) {
2053 		ath11k_err(ab, "Unsupported hardware version: 0x%x\n", ab->hw_rev);
2054 		return -EINVAL;
2055 	}
2056 
2057 	ab->hw_params = *hw_params;
2058 
2059 	ath11k_info(ab, "%s\n", ab->hw_params.name);
2060 
2061 	return 0;
2062 }
2063 
2064 int ath11k_core_pre_init(struct ath11k_base *ab)
2065 {
2066 	int ret;
2067 
2068 	ret = ath11k_init_hw_params(ab);
2069 	if (ret) {
2070 		ath11k_err(ab, "failed to get hw params: %d\n", ret);
2071 		return ret;
2072 	}
2073 
2074 	return 0;
2075 }
2076 EXPORT_SYMBOL(ath11k_core_pre_init);
2077 
2078 int ath11k_core_init(struct ath11k_base *ab)
2079 {
2080 	int ret;
2081 
2082 	ret = ath11k_core_soc_create(ab);
2083 	if (ret) {
2084 		ath11k_err(ab, "failed to create soc core: %d\n", ret);
2085 		return ret;
2086 	}
2087 
2088 	return 0;
2089 }
2090 EXPORT_SYMBOL(ath11k_core_init);
2091 
2092 void ath11k_core_deinit(struct ath11k_base *ab)
2093 {
2094 	mutex_lock(&ab->core_lock);
2095 
2096 	ath11k_core_pdev_destroy(ab);
2097 	ath11k_core_stop(ab);
2098 
2099 	mutex_unlock(&ab->core_lock);
2100 
2101 	ath11k_hif_power_down(ab);
2102 	ath11k_mac_destroy(ab);
2103 	ath11k_core_soc_destroy(ab);
2104 }
2105 EXPORT_SYMBOL(ath11k_core_deinit);
2106 
2107 void ath11k_core_free(struct ath11k_base *ab)
2108 {
2109 	destroy_workqueue(ab->workqueue_aux);
2110 	destroy_workqueue(ab->workqueue);
2111 
2112 	kfree(ab);
2113 }
2114 EXPORT_SYMBOL(ath11k_core_free);
2115 
2116 struct ath11k_base *ath11k_core_alloc(struct device *dev, size_t priv_size,
2117 				      enum ath11k_bus bus)
2118 {
2119 	struct ath11k_base *ab;
2120 
2121 	ab = kzalloc(sizeof(*ab) + priv_size, GFP_KERNEL);
2122 	if (!ab)
2123 		return NULL;
2124 
2125 	init_completion(&ab->driver_recovery);
2126 
2127 	ab->workqueue = create_singlethread_workqueue("ath11k_wq");
2128 	if (!ab->workqueue)
2129 		goto err_sc_free;
2130 
2131 	ab->workqueue_aux = create_singlethread_workqueue("ath11k_aux_wq");
2132 	if (!ab->workqueue_aux)
2133 		goto err_free_wq;
2134 
2135 	mutex_init(&ab->core_lock);
2136 	mutex_init(&ab->tbl_mtx_lock);
2137 	spin_lock_init(&ab->base_lock);
2138 	mutex_init(&ab->vdev_id_11d_lock);
2139 	init_completion(&ab->reset_complete);
2140 	init_completion(&ab->reconfigure_complete);
2141 	init_completion(&ab->recovery_start);
2142 
2143 	INIT_LIST_HEAD(&ab->peers);
2144 	init_waitqueue_head(&ab->peer_mapping_wq);
2145 	init_waitqueue_head(&ab->wmi_ab.tx_credits_wq);
2146 	init_waitqueue_head(&ab->qmi.cold_boot_waitq);
2147 	INIT_WORK(&ab->restart_work, ath11k_core_restart);
2148 	INIT_WORK(&ab->update_11d_work, ath11k_update_11d);
2149 	INIT_WORK(&ab->reset_work, ath11k_core_reset);
2150 	timer_setup(&ab->rx_replenish_retry, ath11k_ce_rx_replenish_retry, 0);
2151 	init_completion(&ab->htc_suspend);
2152 	init_completion(&ab->wow.wakeup_completed);
2153 
2154 	ab->dev = dev;
2155 	ab->hif.bus = bus;
2156 
2157 	return ab;
2158 
2159 err_free_wq:
2160 	destroy_workqueue(ab->workqueue);
2161 err_sc_free:
2162 	kfree(ab);
2163 	return NULL;
2164 }
2165 EXPORT_SYMBOL(ath11k_core_alloc);
2166 
2167 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11ax wireless LAN cards.");
2168 MODULE_LICENSE("Dual BSD/GPL");
2169