1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
7 #include <linux/module.h>
8 #include <linux/slab.h>
9 #include <linux/remoteproc.h>
10 #include <linux/firmware.h>
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");
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");
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)");
35 static const struct ath11k_hw_params ath11k_hw_params[] = {
37 .hw_rev = ATH11K_HW_IPQ8074,
38 .name = "ipq8074 hw2.0",
40 .dir = "IPQ8074/hw2.0",
41 .board_size = 256 * 1024,
42 .cal_offset = 128 * 1024,
45 .bdf_addr = 0x4B0C0000,
46 .hw_ops = &ipq8074_ops,
47 .ring_mask = &ath11k_hw_ring_mask_ipq8074,
48 .internal_sleep_clock = false,
49 .regs = &ipq8074_regs,
50 .qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ8074,
51 .host_ce_config = ath11k_host_ce_config_ipq8074,
53 .target_ce_config = ath11k_target_ce_config_wlan_ipq8074,
54 .target_ce_count = 11,
55 .svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_ipq8074,
56 .svc_to_ce_map_len = 21,
60 .single_pdev_only = false,
61 .rxdma1_enable = true,
62 .num_rxmda_per_pdev = 1,
63 .rx_mac_buf_ring = false,
64 .vdev_start_delay = false,
65 .htt_peer_map_v2 = true,
69 /* HW bug, expected BIN size is 2 bytes but HW report as 4 bytes.
70 * so added pad size as 2 bytes to compensate the BIN size
78 .interface_modes = BIT(NL80211_IFTYPE_STATION) |
79 BIT(NL80211_IFTYPE_AP) |
80 BIT(NL80211_IFTYPE_MESH_POINT),
81 .supports_monitor = true,
82 .full_monitor_mode = false,
83 .supports_shadow_regs = false,
85 .supports_sta_ps = false,
86 .cold_boot_calib = true,
90 .supports_suspend = false,
91 .hal_desc_sz = sizeof(struct hal_rx_desc_ipq8074),
92 .supports_regdb = false,
95 .max_tx_ring = DP_TCL_NUM_RING_MAX,
96 .hal_params = &ath11k_hw_hal_params_ipq8074,
97 .supports_dynamic_smps_6ghz = false,
98 .alloc_cacheable_memory = true,
99 .supports_rssi_stats = false,
100 .fw_wmi_diag_event = false,
101 .current_cc_support = false,
102 .dbr_debug_support = true,
103 .global_reset = false,
104 .bios_sar_capa = NULL,
105 .m3_fw_support = false,
106 .fixed_bdf_addr = true,
107 .fixed_mem_region = true,
108 .static_window_map = false,
109 .hybrid_bus_type = false,
112 .fixed_fw_mem = false,
113 .support_off_channel_tx = false,
116 .hw_rev = ATH11K_HW_IPQ6018_HW10,
117 .name = "ipq6018 hw1.0",
119 .dir = "IPQ6018/hw1.0",
120 .board_size = 256 * 1024,
121 .cal_offset = 128 * 1024,
124 .bdf_addr = 0x4ABC0000,
125 .hw_ops = &ipq6018_ops,
126 .ring_mask = &ath11k_hw_ring_mask_ipq8074,
127 .internal_sleep_clock = false,
128 .regs = &ipq8074_regs,
129 .qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ8074,
130 .host_ce_config = ath11k_host_ce_config_ipq8074,
132 .target_ce_config = ath11k_target_ce_config_wlan_ipq8074,
133 .target_ce_count = 11,
134 .svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_ipq6018,
135 .svc_to_ce_map_len = 19,
138 .rfkill_on_level = 0,
139 .single_pdev_only = false,
140 .rxdma1_enable = true,
141 .num_rxmda_per_pdev = 1,
142 .rx_mac_buf_ring = false,
143 .vdev_start_delay = false,
144 .htt_peer_map_v2 = true,
154 .interface_modes = BIT(NL80211_IFTYPE_STATION) |
155 BIT(NL80211_IFTYPE_AP) |
156 BIT(NL80211_IFTYPE_MESH_POINT),
157 .supports_monitor = true,
158 .full_monitor_mode = false,
159 .supports_shadow_regs = false,
161 .supports_sta_ps = false,
162 .cold_boot_calib = true,
166 .supports_suspend = false,
167 .hal_desc_sz = sizeof(struct hal_rx_desc_ipq8074),
168 .supports_regdb = false,
170 .credit_flow = false,
171 .max_tx_ring = DP_TCL_NUM_RING_MAX,
172 .hal_params = &ath11k_hw_hal_params_ipq8074,
173 .supports_dynamic_smps_6ghz = false,
174 .alloc_cacheable_memory = true,
175 .supports_rssi_stats = false,
176 .fw_wmi_diag_event = false,
177 .current_cc_support = false,
178 .dbr_debug_support = true,
179 .global_reset = false,
180 .bios_sar_capa = NULL,
181 .m3_fw_support = false,
182 .fixed_bdf_addr = true,
183 .fixed_mem_region = true,
184 .static_window_map = false,
185 .hybrid_bus_type = false,
188 .fixed_fw_mem = false,
189 .support_off_channel_tx = false,
192 .name = "qca6390 hw2.0",
193 .hw_rev = ATH11K_HW_QCA6390_HW20,
195 .dir = "QCA6390/hw2.0",
196 .board_size = 256 * 1024,
197 .cal_offset = 128 * 1024,
200 .bdf_addr = 0x4B0C0000,
201 .hw_ops = &qca6390_ops,
202 .ring_mask = &ath11k_hw_ring_mask_qca6390,
203 .internal_sleep_clock = true,
204 .regs = &qca6390_regs,
205 .qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCA6390,
206 .host_ce_config = ath11k_host_ce_config_qca6390,
208 .target_ce_config = ath11k_target_ce_config_wlan_qca6390,
209 .target_ce_count = 9,
210 .svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
211 .svc_to_ce_map_len = 14,
214 .rfkill_on_level = 1,
215 .single_pdev_only = true,
216 .rxdma1_enable = false,
217 .num_rxmda_per_pdev = 2,
218 .rx_mac_buf_ring = true,
219 .vdev_start_delay = true,
220 .htt_peer_map_v2 = false,
230 .interface_modes = BIT(NL80211_IFTYPE_STATION) |
231 BIT(NL80211_IFTYPE_AP),
232 .supports_monitor = false,
233 .full_monitor_mode = false,
234 .supports_shadow_regs = true,
236 .supports_sta_ps = true,
237 .cold_boot_calib = false,
241 .supports_suspend = true,
242 .hal_desc_sz = sizeof(struct hal_rx_desc_ipq8074),
243 .supports_regdb = false,
246 .max_tx_ring = DP_TCL_NUM_RING_MAX_QCA6390,
247 .hal_params = &ath11k_hw_hal_params_qca6390,
248 .supports_dynamic_smps_6ghz = false,
249 .alloc_cacheable_memory = false,
250 .supports_rssi_stats = true,
251 .fw_wmi_diag_event = true,
252 .current_cc_support = true,
253 .dbr_debug_support = false,
254 .global_reset = true,
255 .bios_sar_capa = NULL,
256 .m3_fw_support = true,
257 .fixed_bdf_addr = false,
258 .fixed_mem_region = false,
259 .static_window_map = false,
260 .hybrid_bus_type = false,
263 .fixed_fw_mem = false,
264 .support_off_channel_tx = true,
267 .name = "qcn9074 hw1.0",
268 .hw_rev = ATH11K_HW_QCN9074_HW10,
270 .dir = "QCN9074/hw1.0",
271 .board_size = 256 * 1024,
272 .cal_offset = 128 * 1024,
275 .single_pdev_only = false,
276 .qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9074,
277 .hw_ops = &qcn9074_ops,
278 .ring_mask = &ath11k_hw_ring_mask_qcn9074,
279 .internal_sleep_clock = false,
280 .regs = &qcn9074_regs,
281 .host_ce_config = ath11k_host_ce_config_qcn9074,
283 .target_ce_config = ath11k_target_ce_config_wlan_qcn9074,
284 .target_ce_count = 9,
285 .svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qcn9074,
286 .svc_to_ce_map_len = 18,
289 .rfkill_on_level = 0,
290 .rxdma1_enable = true,
291 .num_rxmda_per_pdev = 1,
292 .rx_mac_buf_ring = false,
293 .vdev_start_delay = false,
294 .htt_peer_map_v2 = true,
299 .summary_pad_sz = 16,
301 .max_fft_bins = 1024,
304 .interface_modes = BIT(NL80211_IFTYPE_STATION) |
305 BIT(NL80211_IFTYPE_AP) |
306 BIT(NL80211_IFTYPE_MESH_POINT),
307 .supports_monitor = true,
308 .full_monitor_mode = true,
309 .supports_shadow_regs = false,
311 .supports_sta_ps = false,
312 .cold_boot_calib = false,
316 .supports_suspend = false,
317 .hal_desc_sz = sizeof(struct hal_rx_desc_qcn9074),
318 .supports_regdb = false,
320 .credit_flow = false,
321 .max_tx_ring = DP_TCL_NUM_RING_MAX,
322 .hal_params = &ath11k_hw_hal_params_ipq8074,
323 .supports_dynamic_smps_6ghz = true,
324 .alloc_cacheable_memory = true,
325 .supports_rssi_stats = false,
326 .fw_wmi_diag_event = false,
327 .current_cc_support = false,
328 .dbr_debug_support = true,
329 .global_reset = false,
330 .bios_sar_capa = NULL,
331 .m3_fw_support = true,
332 .fixed_bdf_addr = false,
333 .fixed_mem_region = false,
334 .static_window_map = true,
335 .hybrid_bus_type = false,
338 .fixed_fw_mem = false,
339 .support_off_channel_tx = false,
342 .name = "wcn6855 hw2.0",
343 .hw_rev = ATH11K_HW_WCN6855_HW20,
345 .dir = "WCN6855/hw2.0",
346 .board_size = 256 * 1024,
347 .cal_offset = 128 * 1024,
350 .bdf_addr = 0x4B0C0000,
351 .hw_ops = &wcn6855_ops,
352 .ring_mask = &ath11k_hw_ring_mask_qca6390,
353 .internal_sleep_clock = true,
354 .regs = &wcn6855_regs,
355 .qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCA6390,
356 .host_ce_config = ath11k_host_ce_config_qca6390,
358 .target_ce_config = ath11k_target_ce_config_wlan_qca6390,
359 .target_ce_count = 9,
360 .svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
361 .svc_to_ce_map_len = 14,
364 .rfkill_on_level = 0,
365 .single_pdev_only = true,
366 .rxdma1_enable = false,
367 .num_rxmda_per_pdev = 2,
368 .rx_mac_buf_ring = true,
369 .vdev_start_delay = true,
370 .htt_peer_map_v2 = false,
380 .interface_modes = BIT(NL80211_IFTYPE_STATION) |
381 BIT(NL80211_IFTYPE_AP),
382 .supports_monitor = false,
383 .full_monitor_mode = false,
384 .supports_shadow_regs = true,
386 .supports_sta_ps = true,
387 .cold_boot_calib = false,
391 .supports_suspend = true,
392 .hal_desc_sz = sizeof(struct hal_rx_desc_wcn6855),
393 .supports_regdb = true,
396 .max_tx_ring = DP_TCL_NUM_RING_MAX_QCA6390,
397 .hal_params = &ath11k_hw_hal_params_qca6390,
398 .supports_dynamic_smps_6ghz = false,
399 .alloc_cacheable_memory = false,
400 .supports_rssi_stats = true,
401 .fw_wmi_diag_event = true,
402 .current_cc_support = true,
403 .dbr_debug_support = false,
404 .global_reset = true,
405 .bios_sar_capa = &ath11k_hw_sar_capa_wcn6855,
406 .m3_fw_support = true,
407 .fixed_bdf_addr = false,
408 .fixed_mem_region = false,
409 .static_window_map = false,
410 .hybrid_bus_type = false,
413 .fixed_fw_mem = false,
414 .support_off_channel_tx = true,
417 .name = "wcn6855 hw2.1",
418 .hw_rev = ATH11K_HW_WCN6855_HW21,
420 .dir = "WCN6855/hw2.1",
421 .board_size = 256 * 1024,
422 .cal_offset = 128 * 1024,
425 .bdf_addr = 0x4B0C0000,
426 .hw_ops = &wcn6855_ops,
427 .ring_mask = &ath11k_hw_ring_mask_qca6390,
428 .internal_sleep_clock = true,
429 .regs = &wcn6855_regs,
430 .qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_QCA6390,
431 .host_ce_config = ath11k_host_ce_config_qca6390,
433 .target_ce_config = ath11k_target_ce_config_wlan_qca6390,
434 .target_ce_count = 9,
435 .svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
436 .svc_to_ce_map_len = 14,
439 .rfkill_on_level = 0,
440 .single_pdev_only = true,
441 .rxdma1_enable = false,
442 .num_rxmda_per_pdev = 2,
443 .rx_mac_buf_ring = true,
444 .vdev_start_delay = true,
445 .htt_peer_map_v2 = false,
455 .interface_modes = BIT(NL80211_IFTYPE_STATION) |
456 BIT(NL80211_IFTYPE_AP),
457 .supports_monitor = false,
458 .supports_shadow_regs = true,
460 .supports_sta_ps = true,
461 .cold_boot_calib = false,
465 .supports_suspend = true,
466 .hal_desc_sz = sizeof(struct hal_rx_desc_wcn6855),
467 .supports_regdb = true,
470 .max_tx_ring = DP_TCL_NUM_RING_MAX_QCA6390,
471 .hal_params = &ath11k_hw_hal_params_qca6390,
472 .supports_dynamic_smps_6ghz = false,
473 .alloc_cacheable_memory = false,
474 .supports_rssi_stats = true,
475 .fw_wmi_diag_event = true,
476 .current_cc_support = true,
477 .dbr_debug_support = false,
478 .global_reset = true,
479 .bios_sar_capa = &ath11k_hw_sar_capa_wcn6855,
480 .m3_fw_support = true,
481 .fixed_bdf_addr = false,
482 .fixed_mem_region = false,
483 .static_window_map = false,
484 .hybrid_bus_type = false,
487 .fixed_fw_mem = false,
488 .support_off_channel_tx = true,
491 .name = "wcn6750 hw1.0",
492 .hw_rev = ATH11K_HW_WCN6750_HW10,
494 .dir = "WCN6750/hw1.0",
495 .board_size = 256 * 1024,
496 .cal_offset = 128 * 1024,
499 .bdf_addr = 0x4B0C0000,
500 .hw_ops = &wcn6750_ops,
501 .ring_mask = &ath11k_hw_ring_mask_qca6390,
502 .internal_sleep_clock = false,
503 .regs = &wcn6750_regs,
504 .qmi_service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_WCN6750,
505 .host_ce_config = ath11k_host_ce_config_qca6390,
507 .target_ce_config = ath11k_target_ce_config_wlan_qca6390,
508 .target_ce_count = 9,
509 .svc_to_ce_map = ath11k_target_service_to_ce_map_wlan_qca6390,
510 .svc_to_ce_map_len = 14,
513 .rfkill_on_level = 0,
514 .single_pdev_only = true,
515 .rxdma1_enable = false,
516 .num_rxmda_per_pdev = 1,
517 .rx_mac_buf_ring = true,
518 .vdev_start_delay = true,
519 .htt_peer_map_v2 = false,
529 .interface_modes = BIT(NL80211_IFTYPE_STATION) |
530 BIT(NL80211_IFTYPE_AP),
531 .supports_monitor = false,
532 .supports_shadow_regs = true,
534 .supports_sta_ps = true,
535 .cold_boot_calib = false,
539 .supports_suspend = false,
540 .hal_desc_sz = sizeof(struct hal_rx_desc_qcn9074),
541 .supports_regdb = true,
544 .max_tx_ring = DP_TCL_NUM_RING_MAX_QCA6390,
545 .hal_params = &ath11k_hw_hal_params_qca6390,
546 .supports_dynamic_smps_6ghz = false,
547 .alloc_cacheable_memory = false,
548 .supports_rssi_stats = true,
549 .fw_wmi_diag_event = false,
550 .current_cc_support = true,
551 .dbr_debug_support = false,
552 .global_reset = false,
553 .bios_sar_capa = NULL,
554 .m3_fw_support = false,
555 .fixed_bdf_addr = false,
556 .fixed_mem_region = false,
557 .static_window_map = true,
558 .hybrid_bus_type = true,
561 .fixed_fw_mem = true,
562 .support_off_channel_tx = false,
566 static inline struct ath11k_pdev *ath11k_core_get_single_pdev(struct ath11k_base *ab)
568 WARN_ON(!ab->hw_params.single_pdev_only);
570 return &ab->pdevs[0];
573 int ath11k_core_suspend(struct ath11k_base *ab)
576 struct ath11k_pdev *pdev;
579 if (!ab->hw_params.supports_suspend)
582 /* so far single_pdev_only chips have supports_suspend as true
583 * and only the first pdev is valid.
585 pdev = ath11k_core_get_single_pdev(ab);
587 if (!ar || ar->state != ATH11K_STATE_OFF)
590 ret = ath11k_dp_rx_pktlog_stop(ab, true);
592 ath11k_warn(ab, "failed to stop dp rx (and timer) pktlog during suspend: %d\n",
597 ret = ath11k_mac_wait_tx_complete(ar);
599 ath11k_warn(ab, "failed to wait tx complete: %d\n", ret);
603 ret = ath11k_wow_enable(ab);
605 ath11k_warn(ab, "failed to enable wow during suspend: %d\n", ret);
609 ret = ath11k_dp_rx_pktlog_stop(ab, false);
611 ath11k_warn(ab, "failed to stop dp rx pktlog during suspend: %d\n",
616 ath11k_ce_stop_shadow_timers(ab);
617 ath11k_dp_stop_shadow_timers(ab);
619 ath11k_hif_irq_disable(ab);
620 ath11k_hif_ce_irq_disable(ab);
622 ret = ath11k_hif_suspend(ab);
624 ath11k_warn(ab, "failed to suspend hif: %d\n", ret);
630 EXPORT_SYMBOL(ath11k_core_suspend);
632 int ath11k_core_resume(struct ath11k_base *ab)
635 struct ath11k_pdev *pdev;
638 if (!ab->hw_params.supports_suspend)
641 /* so far signle_pdev_only chips have supports_suspend as true
642 * and only the first pdev is valid.
644 pdev = ath11k_core_get_single_pdev(ab);
646 if (!ar || ar->state != ATH11K_STATE_OFF)
649 ret = ath11k_hif_resume(ab);
651 ath11k_warn(ab, "failed to resume hif during resume: %d\n", ret);
655 ath11k_hif_ce_irq_enable(ab);
656 ath11k_hif_irq_enable(ab);
658 ret = ath11k_dp_rx_pktlog_start(ab);
660 ath11k_warn(ab, "failed to start rx pktlog during resume: %d\n",
665 ret = ath11k_wow_wakeup(ab);
667 ath11k_warn(ab, "failed to wakeup wow during resume: %d\n", ret);
673 EXPORT_SYMBOL(ath11k_core_resume);
675 static void ath11k_core_check_cc_code_bdfext(const struct dmi_header *hdr, void *data)
677 struct ath11k_base *ab = data;
678 const char *magic = ATH11K_SMBIOS_BDF_EXT_MAGIC;
679 struct ath11k_smbios_bdf *smbios = (struct ath11k_smbios_bdf *)hdr;
684 if (ab->qmi.target.bdf_ext[0] != '\0')
687 if (hdr->type != ATH11K_SMBIOS_BDF_EXT_TYPE)
690 if (hdr->length != ATH11K_SMBIOS_BDF_EXT_LENGTH) {
691 ath11k_dbg(ab, ATH11K_DBG_BOOT,
692 "wrong smbios bdf ext type length (%d).\n",
697 spin_lock_bh(&ab->base_lock);
699 switch (smbios->country_code_flag) {
700 case ATH11K_SMBIOS_CC_ISO:
701 ab->new_alpha2[0] = (smbios->cc_code >> 8) & 0xff;
702 ab->new_alpha2[1] = smbios->cc_code & 0xff;
703 ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot smbios cc_code %c%c\n",
704 ab->new_alpha2[0], ab->new_alpha2[1]);
706 case ATH11K_SMBIOS_CC_WW:
707 ab->new_alpha2[0] = '0';
708 ab->new_alpha2[1] = '0';
709 ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot smbios worldwide regdomain\n");
712 ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot ignore smbios country code setting %d\n",
713 smbios->country_code_flag);
717 spin_unlock_bh(&ab->base_lock);
719 if (!smbios->bdf_enabled) {
720 ath11k_dbg(ab, ATH11K_DBG_BOOT, "bdf variant name not found.\n");
724 /* Only one string exists (per spec) */
725 if (memcmp(smbios->bdf_ext, magic, strlen(magic)) != 0) {
726 ath11k_dbg(ab, ATH11K_DBG_BOOT,
727 "bdf variant magic does not match.\n");
732 strlen(smbios->bdf_ext), sizeof(ab->qmi.target.bdf_ext));
733 for (i = 0; i < len; i++) {
734 if (!isascii(smbios->bdf_ext[i]) || !isprint(smbios->bdf_ext[i])) {
735 ath11k_dbg(ab, ATH11K_DBG_BOOT,
736 "bdf variant name contains non ascii chars.\n");
741 /* Copy extension name without magic prefix */
742 copied = strscpy(ab->qmi.target.bdf_ext, smbios->bdf_ext + strlen(magic),
743 sizeof(ab->qmi.target.bdf_ext));
745 ath11k_dbg(ab, ATH11K_DBG_BOOT,
746 "bdf variant string is longer than the buffer can accommodate\n");
750 ath11k_dbg(ab, ATH11K_DBG_BOOT,
751 "found and validated bdf variant smbios_type 0x%x bdf %s\n",
752 ATH11K_SMBIOS_BDF_EXT_TYPE, ab->qmi.target.bdf_ext);
755 int ath11k_core_check_smbios(struct ath11k_base *ab)
757 ab->qmi.target.bdf_ext[0] = '\0';
758 dmi_walk(ath11k_core_check_cc_code_bdfext, ab);
760 if (ab->qmi.target.bdf_ext[0] == '\0')
766 int ath11k_core_check_dt(struct ath11k_base *ab)
768 size_t max_len = sizeof(ab->qmi.target.bdf_ext);
769 const char *variant = NULL;
770 struct device_node *node;
772 node = ab->dev->of_node;
776 of_property_read_string(node, "qcom,ath11k-calibration-variant",
781 if (strscpy(ab->qmi.target.bdf_ext, variant, max_len) < 0)
782 ath11k_dbg(ab, ATH11K_DBG_BOOT,
783 "bdf variant string is longer than the buffer can accommodate (variant: %s)\n",
789 static int __ath11k_core_create_board_name(struct ath11k_base *ab, char *name,
790 size_t name_len, bool with_variant)
792 /* strlen(',variant=') + strlen(ab->qmi.target.bdf_ext) */
793 char variant[9 + ATH11K_QMI_BDF_EXT_STR_LENGTH] = { 0 };
795 if (with_variant && ab->qmi.target.bdf_ext[0] != '\0')
796 scnprintf(variant, sizeof(variant), ",variant=%s",
797 ab->qmi.target.bdf_ext);
799 switch (ab->id.bdf_search) {
800 case ATH11K_BDF_SEARCH_BUS_AND_BOARD:
801 scnprintf(name, name_len,
802 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x,qmi-chip-id=%d,qmi-board-id=%d%s",
803 ath11k_bus_str(ab->hif.bus),
804 ab->id.vendor, ab->id.device,
805 ab->id.subsystem_vendor,
806 ab->id.subsystem_device,
807 ab->qmi.target.chip_id,
808 ab->qmi.target.board_id,
812 scnprintf(name, name_len,
813 "bus=%s,qmi-chip-id=%d,qmi-board-id=%d%s",
814 ath11k_bus_str(ab->hif.bus),
815 ab->qmi.target.chip_id,
816 ab->qmi.target.board_id, variant);
820 ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot using board name '%s'\n", name);
825 static int ath11k_core_create_board_name(struct ath11k_base *ab, char *name,
828 return __ath11k_core_create_board_name(ab, name, name_len, true);
831 static int ath11k_core_create_fallback_board_name(struct ath11k_base *ab, char *name,
834 return __ath11k_core_create_board_name(ab, name, name_len, false);
837 const struct firmware *ath11k_core_firmware_request(struct ath11k_base *ab,
840 const struct firmware *fw;
845 return ERR_PTR(-ENOENT);
847 ath11k_core_create_firmware_path(ab, file, path, sizeof(path));
849 ret = firmware_reject_nowarn(&fw, path, ab->dev);
853 ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot firmware request %s size %zu\n",
859 void ath11k_core_free_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd)
862 release_firmware(bd->fw);
864 memset(bd, 0, sizeof(*bd));
867 static int ath11k_core_parse_bd_ie_board(struct ath11k_base *ab,
868 struct ath11k_board_data *bd,
869 const void *buf, size_t buf_len,
870 const char *boardname,
875 const struct ath11k_fw_ie *hdr;
876 bool name_match_found;
877 int ret, board_ie_id;
879 const void *board_ie_data;
881 name_match_found = false;
883 /* go through ATH11K_BD_IE_BOARD_/ATH11K_BD_IE_REGDB_ elements */
884 while (buf_len > sizeof(struct ath11k_fw_ie)) {
886 board_ie_id = le32_to_cpu(hdr->id);
887 board_ie_len = le32_to_cpu(hdr->len);
888 board_ie_data = hdr->data;
890 buf_len -= sizeof(*hdr);
893 if (buf_len < ALIGN(board_ie_len, 4)) {
894 ath11k_err(ab, "invalid %s length: %zu < %zu\n",
895 ath11k_bd_ie_type_str(ie_id),
896 buf_len, ALIGN(board_ie_len, 4));
901 if (board_ie_id == name_id) {
902 ath11k_dbg_dump(ab, ATH11K_DBG_BOOT, "board name", "",
903 board_ie_data, board_ie_len);
905 if (board_ie_len != strlen(boardname))
908 ret = memcmp(board_ie_data, boardname, strlen(boardname));
912 name_match_found = true;
913 ath11k_dbg(ab, ATH11K_DBG_BOOT,
914 "boot found match %s for name '%s'",
915 ath11k_bd_ie_type_str(ie_id),
917 } else if (board_ie_id == data_id) {
918 if (!name_match_found)
922 ath11k_dbg(ab, ATH11K_DBG_BOOT,
923 "boot found %s for '%s'",
924 ath11k_bd_ie_type_str(ie_id),
927 bd->data = board_ie_data;
928 bd->len = board_ie_len;
933 ath11k_warn(ab, "unknown %s id found: %d\n",
934 ath11k_bd_ie_type_str(ie_id),
938 /* jump over the padding */
939 board_ie_len = ALIGN(board_ie_len, 4);
941 buf_len -= board_ie_len;
952 static int ath11k_core_fetch_board_data_api_n(struct ath11k_base *ab,
953 struct ath11k_board_data *bd,
954 const char *boardname,
959 size_t len, magic_len;
961 char *filename, filepath[100];
963 struct ath11k_fw_ie *hdr;
966 filename = ATH11K_BOARD_API2_FILE;
969 bd->fw = ath11k_core_firmware_request(ab, filename);
972 return PTR_ERR(bd->fw);
977 ath11k_core_create_firmware_path(ab, filename,
978 filepath, sizeof(filepath));
980 /* magic has extra null byte padded */
981 magic_len = strlen(ATH11K_BOARD_MAGIC) + 1;
982 if (len < magic_len) {
983 ath11k_err(ab, "failed to find magic value in %s, file too short: %zu\n",
989 if (memcmp(data, ATH11K_BOARD_MAGIC, magic_len)) {
990 ath11k_err(ab, "found invalid board magic\n");
995 /* magic is padded to 4 bytes */
996 magic_len = ALIGN(magic_len, 4);
997 if (len < magic_len) {
998 ath11k_err(ab, "failed: %s too small to contain board data, len: %zu\n",
1007 while (len > sizeof(struct ath11k_fw_ie)) {
1008 hdr = (struct ath11k_fw_ie *)data;
1009 ie_id = le32_to_cpu(hdr->id);
1010 ie_len = le32_to_cpu(hdr->len);
1012 len -= sizeof(*hdr);
1015 if (len < ALIGN(ie_len, 4)) {
1016 ath11k_err(ab, "invalid length for board ie_id %d ie_len %zu len %zu\n",
1017 ie_id, ie_len, len);
1022 if (ie_id == ie_id_match) {
1023 ret = ath11k_core_parse_bd_ie_board(ab, bd, data,
1030 /* no match found, continue */
1033 /* there was an error, bail out */
1035 /* either found or error, so stop searching */
1039 /* jump over the padding */
1040 ie_len = ALIGN(ie_len, 4);
1047 if (!bd->data || !bd->len) {
1048 ath11k_dbg(ab, ATH11K_DBG_BOOT,
1049 "failed to fetch %s for %s from %s\n",
1050 ath11k_bd_ie_type_str(ie_id_match),
1051 boardname, filepath);
1059 ath11k_core_free_bdf(ab, bd);
1063 int ath11k_core_fetch_board_data_api_1(struct ath11k_base *ab,
1064 struct ath11k_board_data *bd,
1067 bd->fw = ath11k_core_firmware_request(ab, name);
1070 return PTR_ERR(bd->fw);
1072 bd->data = bd->fw->data;
1073 bd->len = bd->fw->size;
1078 #define BOARD_NAME_SIZE 200
1079 int ath11k_core_fetch_bdf(struct ath11k_base *ab, struct ath11k_board_data *bd)
1081 char boardname[BOARD_NAME_SIZE], fallback_boardname[BOARD_NAME_SIZE];
1082 char *filename, filepath[100];
1085 filename = ATH11K_BOARD_API2_FILE;
1087 ret = ath11k_core_create_board_name(ab, boardname, sizeof(boardname));
1089 ath11k_err(ab, "failed to create board name: %d", ret);
1094 ret = ath11k_core_fetch_board_data_api_n(ab, bd, boardname,
1096 ATH11K_BD_IE_BOARD_NAME,
1097 ATH11K_BD_IE_BOARD_DATA);
1101 ret = ath11k_core_create_fallback_board_name(ab, fallback_boardname,
1102 sizeof(fallback_boardname));
1104 ath11k_err(ab, "failed to create fallback board name: %d", ret);
1108 ret = ath11k_core_fetch_board_data_api_n(ab, bd, fallback_boardname,
1110 ATH11K_BD_IE_BOARD_NAME,
1111 ATH11K_BD_IE_BOARD_DATA);
1116 ret = ath11k_core_fetch_board_data_api_1(ab, bd, ATH11K_DEFAULT_BOARD_FILE);
1118 ath11k_core_create_firmware_path(ab, filename,
1119 filepath, sizeof(filepath));
1120 ath11k_err(ab, "failed to fetch board data for %s from %s\n",
1121 boardname, filepath);
1122 if (memcmp(boardname, fallback_boardname, strlen(boardname)))
1123 ath11k_err(ab, "failed to fetch board data for %s from %s\n",
1124 fallback_boardname, filepath);
1126 ath11k_err(ab, "failed to fetch /*(DEBLOBBED)*/ from %s\n",
1127 ab->hw_params.fw.dir);
1132 ath11k_dbg(ab, ATH11K_DBG_BOOT, "using board api %d\n", ab->bd_api);
1136 int ath11k_core_fetch_regdb(struct ath11k_base *ab, struct ath11k_board_data *bd)
1138 char boardname[BOARD_NAME_SIZE];
1141 ret = ath11k_core_create_board_name(ab, boardname, BOARD_NAME_SIZE);
1143 ath11k_dbg(ab, ATH11K_DBG_BOOT,
1144 "failed to create board name for regdb: %d", ret);
1148 ret = ath11k_core_fetch_board_data_api_n(ab, bd, boardname,
1150 ATH11K_BD_IE_REGDB_NAME,
1151 ATH11K_BD_IE_REGDB_DATA);
1155 ret = ath11k_core_fetch_board_data_api_1(ab, bd, ATH11K_REGDB_FILE_NAME);
1157 ath11k_dbg(ab, ATH11K_DBG_BOOT, "failed to fetch %s from %s\n",
1158 ATH11K_REGDB_FILE_NAME, ab->hw_params.fw.dir);
1162 ath11k_dbg(ab, ATH11K_DBG_BOOT, "fetched regdb\n");
1167 static void ath11k_core_stop(struct ath11k_base *ab)
1169 if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))
1170 ath11k_qmi_firmware_stop(ab);
1172 ath11k_hif_stop(ab);
1173 ath11k_wmi_detach(ab);
1174 ath11k_dp_pdev_reo_cleanup(ab);
1176 /* De-Init of components as needed */
1179 static int ath11k_core_soc_create(struct ath11k_base *ab)
1183 ret = ath11k_qmi_init_service(ab);
1185 ath11k_err(ab, "failed to initialize qmi :%d\n", ret);
1189 ret = ath11k_debugfs_soc_create(ab);
1191 ath11k_err(ab, "failed to create ath11k debugfs\n");
1192 goto err_qmi_deinit;
1195 ret = ath11k_hif_power_up(ab);
1197 ath11k_err(ab, "failed to power up :%d\n", ret);
1198 goto err_debugfs_reg;
1204 ath11k_debugfs_soc_destroy(ab);
1206 ath11k_qmi_deinit_service(ab);
1210 static void ath11k_core_soc_destroy(struct ath11k_base *ab)
1212 ath11k_debugfs_soc_destroy(ab);
1214 ath11k_reg_free(ab);
1215 ath11k_qmi_deinit_service(ab);
1218 static int ath11k_core_pdev_create(struct ath11k_base *ab)
1222 ret = ath11k_debugfs_pdev_create(ab);
1224 ath11k_err(ab, "failed to create core pdev debugfs: %d\n", ret);
1228 ret = ath11k_mac_register(ab);
1230 ath11k_err(ab, "failed register the radio with mac80211: %d\n", ret);
1231 goto err_pdev_debug;
1234 ret = ath11k_dp_pdev_alloc(ab);
1236 ath11k_err(ab, "failed to attach DP pdev: %d\n", ret);
1237 goto err_mac_unregister;
1240 ret = ath11k_thermal_register(ab);
1242 ath11k_err(ab, "could not register thermal device: %d\n",
1244 goto err_dp_pdev_free;
1247 ret = ath11k_spectral_init(ab);
1249 ath11k_err(ab, "failed to init spectral %d\n", ret);
1250 goto err_thermal_unregister;
1255 err_thermal_unregister:
1256 ath11k_thermal_unregister(ab);
1258 ath11k_dp_pdev_free(ab);
1260 ath11k_mac_unregister(ab);
1262 ath11k_debugfs_pdev_destroy(ab);
1267 static void ath11k_core_pdev_destroy(struct ath11k_base *ab)
1269 ath11k_spectral_deinit(ab);
1270 ath11k_thermal_unregister(ab);
1271 ath11k_mac_unregister(ab);
1272 ath11k_hif_irq_disable(ab);
1273 ath11k_dp_pdev_free(ab);
1274 ath11k_debugfs_pdev_destroy(ab);
1277 static int ath11k_core_start(struct ath11k_base *ab)
1281 ret = ath11k_wmi_attach(ab);
1283 ath11k_err(ab, "failed to attach wmi: %d\n", ret);
1287 ret = ath11k_htc_init(ab);
1289 ath11k_err(ab, "failed to init htc: %d\n", ret);
1290 goto err_wmi_detach;
1293 ret = ath11k_hif_start(ab);
1295 ath11k_err(ab, "failed to start HIF: %d\n", ret);
1296 goto err_wmi_detach;
1299 ret = ath11k_htc_wait_target(&ab->htc);
1301 ath11k_err(ab, "failed to connect to HTC: %d\n", ret);
1305 ret = ath11k_dp_htt_connect(&ab->dp);
1307 ath11k_err(ab, "failed to connect to HTT: %d\n", ret);
1311 ret = ath11k_wmi_connect(ab);
1313 ath11k_err(ab, "failed to connect wmi: %d\n", ret);
1317 ret = ath11k_htc_start(&ab->htc);
1319 ath11k_err(ab, "failed to start HTC: %d\n", ret);
1323 ret = ath11k_wmi_wait_for_service_ready(ab);
1325 ath11k_err(ab, "failed to receive wmi service ready event: %d\n",
1330 ret = ath11k_mac_allocate(ab);
1332 ath11k_err(ab, "failed to create new hw device with mac80211 :%d\n",
1337 ath11k_dp_pdev_pre_alloc(ab);
1339 ret = ath11k_dp_pdev_reo_setup(ab);
1341 ath11k_err(ab, "failed to initialize reo destination rings: %d\n", ret);
1342 goto err_mac_destroy;
1345 ret = ath11k_wmi_cmd_init(ab);
1347 ath11k_err(ab, "failed to send wmi init cmd: %d\n", ret);
1348 goto err_reo_cleanup;
1351 ret = ath11k_wmi_wait_for_unified_ready(ab);
1353 ath11k_err(ab, "failed to receive wmi unified ready event: %d\n",
1355 goto err_reo_cleanup;
1358 /* put hardware to DBS mode */
1359 if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1) {
1360 ret = ath11k_wmi_set_hw_mode(ab, WMI_HOST_HW_MODE_DBS);
1362 ath11k_err(ab, "failed to send dbs mode: %d\n", ret);
1367 ret = ath11k_dp_tx_htt_h2t_ver_req_msg(ab);
1369 ath11k_err(ab, "failed to send htt version request message: %d\n",
1371 goto err_reo_cleanup;
1377 ath11k_dp_pdev_reo_cleanup(ab);
1379 ath11k_mac_destroy(ab);
1381 ath11k_hif_stop(ab);
1383 ath11k_wmi_detach(ab);
1388 static int ath11k_core_start_firmware(struct ath11k_base *ab,
1389 enum ath11k_firmware_mode mode)
1393 ath11k_ce_get_shadow_config(ab, &ab->qmi.ce_cfg.shadow_reg_v2,
1394 &ab->qmi.ce_cfg.shadow_reg_v2_len);
1396 ret = ath11k_qmi_firmware_start(ab, mode);
1398 ath11k_err(ab, "failed to send firmware start: %d\n", ret);
1405 static int ath11k_core_rfkill_config(struct ath11k_base *ab)
1410 if (!(ab->target_caps.sys_cap_info & WMI_SYS_CAP_INFO_RFKILL))
1413 for (i = 0; i < ab->num_radios; i++) {
1414 ar = ab->pdevs[i].ar;
1416 ret = ath11k_mac_rfkill_config(ar);
1417 if (ret && ret != -EOPNOTSUPP) {
1418 ath11k_warn(ab, "failed to configure rfkill: %d", ret);
1426 int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab)
1430 ret = ath11k_core_start_firmware(ab, ATH11K_FIRMWARE_MODE_NORMAL);
1432 ath11k_err(ab, "failed to start firmware: %d\n", ret);
1436 ret = ath11k_ce_init_pipes(ab);
1438 ath11k_err(ab, "failed to initialize CE: %d\n", ret);
1439 goto err_firmware_stop;
1442 ret = ath11k_dp_alloc(ab);
1444 ath11k_err(ab, "failed to init DP: %d\n", ret);
1445 goto err_firmware_stop;
1448 switch (ath11k_crypto_mode) {
1449 case ATH11K_CRYPT_MODE_SW:
1450 set_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags);
1451 set_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags);
1453 case ATH11K_CRYPT_MODE_HW:
1454 clear_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags);
1455 clear_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags);
1458 ath11k_info(ab, "invalid crypto_mode: %d\n", ath11k_crypto_mode);
1462 if (ath11k_frame_mode == ATH11K_HW_TXRX_RAW)
1463 set_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags);
1465 mutex_lock(&ab->core_lock);
1466 ret = ath11k_core_start(ab);
1468 ath11k_err(ab, "failed to start core: %d\n", ret);
1472 ret = ath11k_core_pdev_create(ab);
1474 ath11k_err(ab, "failed to create pdev core: %d\n", ret);
1477 ath11k_hif_irq_enable(ab);
1479 ret = ath11k_core_rfkill_config(ab);
1480 if (ret && ret != -EOPNOTSUPP) {
1481 ath11k_err(ab, "failed to config rfkill: %d\n", ret);
1485 mutex_unlock(&ab->core_lock);
1490 ath11k_core_stop(ab);
1491 ath11k_mac_destroy(ab);
1494 mutex_unlock(&ab->core_lock);
1496 ath11k_qmi_firmware_stop(ab);
1501 static int ath11k_core_reconfigure_on_crash(struct ath11k_base *ab)
1505 mutex_lock(&ab->core_lock);
1506 ath11k_thermal_unregister(ab);
1507 ath11k_hif_irq_disable(ab);
1508 ath11k_dp_pdev_free(ab);
1509 ath11k_spectral_deinit(ab);
1510 ath11k_hif_stop(ab);
1511 ath11k_wmi_detach(ab);
1512 ath11k_dp_pdev_reo_cleanup(ab);
1513 mutex_unlock(&ab->core_lock);
1516 ath11k_hal_srng_deinit(ab);
1518 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS(ab))) - 1;
1520 ret = ath11k_hal_srng_init(ab);
1524 clear_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags);
1526 ret = ath11k_core_qmi_firmware_ready(ab);
1528 goto err_hal_srng_deinit;
1530 clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);
1534 err_hal_srng_deinit:
1535 ath11k_hal_srng_deinit(ab);
1539 void ath11k_core_halt(struct ath11k *ar)
1541 struct ath11k_base *ab = ar->ab;
1543 lockdep_assert_held(&ar->conf_mutex);
1545 ar->num_created_vdevs = 0;
1546 ar->allocated_vdev_map = 0;
1548 ath11k_mac_scan_finish(ar);
1549 ath11k_mac_peer_cleanup_all(ar);
1550 cancel_delayed_work_sync(&ar->scan.timeout);
1551 cancel_work_sync(&ar->regd_update_work);
1552 cancel_work_sync(&ab->update_11d_work);
1553 cancel_work_sync(&ab->rfkill_work);
1555 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], NULL);
1557 INIT_LIST_HEAD(&ar->arvifs);
1558 idr_init(&ar->txmgmt_idr);
1561 static void ath11k_rfkill_work(struct work_struct *work)
1563 struct ath11k_base *ab = container_of(work, struct ath11k_base, rfkill_work);
1565 bool rfkill_radio_on;
1568 spin_lock_bh(&ab->base_lock);
1569 rfkill_radio_on = ab->rfkill_radio_on;
1570 spin_unlock_bh(&ab->base_lock);
1572 for (i = 0; i < ab->num_radios; i++) {
1573 ar = ab->pdevs[i].ar;
1577 /* notify cfg80211 radio state change */
1578 ath11k_mac_rfkill_enable_radio(ar, rfkill_radio_on);
1579 wiphy_rfkill_set_hw_state(ar->hw->wiphy, !rfkill_radio_on);
1583 static void ath11k_update_11d(struct work_struct *work)
1585 struct ath11k_base *ab = container_of(work, struct ath11k_base, update_11d_work);
1587 struct ath11k_pdev *pdev;
1588 struct wmi_set_current_country_params set_current_param = {};
1591 spin_lock_bh(&ab->base_lock);
1592 memcpy(&set_current_param.alpha2, &ab->new_alpha2, 2);
1593 spin_unlock_bh(&ab->base_lock);
1595 ath11k_dbg(ab, ATH11K_DBG_WMI, "update 11d new cc %c%c\n",
1596 set_current_param.alpha2[0],
1597 set_current_param.alpha2[1]);
1599 for (i = 0; i < ab->num_radios; i++) {
1600 pdev = &ab->pdevs[i];
1603 memcpy(&ar->alpha2, &set_current_param.alpha2, 2);
1604 ret = ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param);
1607 "pdev id %d failed set current country code: %d\n",
1612 static void ath11k_core_pre_reconfigure_recovery(struct ath11k_base *ab)
1615 struct ath11k_pdev *pdev;
1618 spin_lock_bh(&ab->base_lock);
1619 ab->stats.fw_crash_counter++;
1620 spin_unlock_bh(&ab->base_lock);
1622 for (i = 0; i < ab->num_radios; i++) {
1623 pdev = &ab->pdevs[i];
1625 if (!ar || ar->state == ATH11K_STATE_OFF)
1628 ieee80211_stop_queues(ar->hw);
1629 ath11k_mac_drain_tx(ar);
1630 ar->state_11d = ATH11K_11D_IDLE;
1631 complete(&ar->completed_11d_scan);
1632 complete(&ar->scan.started);
1633 complete(&ar->scan.completed);
1634 complete(&ar->scan.on_channel);
1635 complete(&ar->peer_assoc_done);
1636 complete(&ar->peer_delete_done);
1637 complete(&ar->install_key_done);
1638 complete(&ar->vdev_setup_done);
1639 complete(&ar->vdev_delete_done);
1640 complete(&ar->bss_survey_done);
1641 complete(&ar->thermal.wmi_sync);
1643 wake_up(&ar->dp.tx_empty_waitq);
1644 idr_for_each(&ar->txmgmt_idr,
1645 ath11k_mac_tx_mgmt_pending_free, ar);
1646 idr_destroy(&ar->txmgmt_idr);
1647 wake_up(&ar->txmgmt_empty_waitq);
1650 wake_up(&ab->wmi_ab.tx_credits_wq);
1651 wake_up(&ab->peer_mapping_wq);
1654 static void ath11k_core_post_reconfigure_recovery(struct ath11k_base *ab)
1657 struct ath11k_pdev *pdev;
1660 for (i = 0; i < ab->num_radios; i++) {
1661 pdev = &ab->pdevs[i];
1663 if (!ar || ar->state == ATH11K_STATE_OFF)
1666 mutex_lock(&ar->conf_mutex);
1668 switch (ar->state) {
1669 case ATH11K_STATE_ON:
1670 ar->state = ATH11K_STATE_RESTARTING;
1671 ath11k_core_halt(ar);
1672 ieee80211_restart_hw(ar->hw);
1674 case ATH11K_STATE_OFF:
1676 "cannot restart radio %d that hasn't been started\n",
1679 case ATH11K_STATE_RESTARTING:
1681 case ATH11K_STATE_RESTARTED:
1682 ar->state = ATH11K_STATE_WEDGED;
1684 case ATH11K_STATE_WEDGED:
1686 "device is wedged, will not restart radio %d\n", i);
1689 mutex_unlock(&ar->conf_mutex);
1691 complete(&ab->driver_recovery);
1694 static void ath11k_core_restart(struct work_struct *work)
1696 struct ath11k_base *ab = container_of(work, struct ath11k_base, restart_work);
1700 ath11k_core_pre_reconfigure_recovery(ab);
1702 ret = ath11k_core_reconfigure_on_crash(ab);
1704 ath11k_err(ab, "failed to reconfigure driver on crash recovery\n");
1709 complete_all(&ab->reconfigure_complete);
1712 ath11k_core_post_reconfigure_recovery(ab);
1715 static void ath11k_core_reset(struct work_struct *work)
1717 struct ath11k_base *ab = container_of(work, struct ath11k_base, reset_work);
1718 int reset_count, fail_cont_count;
1721 if (!(test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))) {
1722 ath11k_warn(ab, "ignore reset dev flags 0x%lx\n", ab->dev_flags);
1726 /* Sometimes the recovery will fail and then the next all recovery fail,
1727 * this is to avoid infinite recovery since it can not recovery success.
1729 fail_cont_count = atomic_read(&ab->fail_cont_count);
1731 if (fail_cont_count >= ATH11K_RESET_MAX_FAIL_COUNT_FINAL)
1734 if (fail_cont_count >= ATH11K_RESET_MAX_FAIL_COUNT_FIRST &&
1735 time_before(jiffies, ab->reset_fail_timeout))
1738 reset_count = atomic_inc_return(&ab->reset_count);
1740 if (reset_count > 1) {
1741 /* Sometimes it happened another reset worker before the previous one
1742 * completed, then the second reset worker will destroy the previous one,
1743 * thus below is to avoid that.
1745 ath11k_warn(ab, "already resetting count %d\n", reset_count);
1747 reinit_completion(&ab->reset_complete);
1748 time_left = wait_for_completion_timeout(&ab->reset_complete,
1749 ATH11K_RESET_TIMEOUT_HZ);
1752 ath11k_dbg(ab, ATH11K_DBG_BOOT, "to skip reset\n");
1753 atomic_dec(&ab->reset_count);
1757 ab->reset_fail_timeout = jiffies + ATH11K_RESET_FAIL_TIMEOUT_HZ;
1758 /* Record the continuous recovery fail count when recovery failed*/
1759 atomic_inc(&ab->fail_cont_count);
1762 ath11k_dbg(ab, ATH11K_DBG_BOOT, "reset starting\n");
1764 ab->is_reset = true;
1765 atomic_set(&ab->recovery_count, 0);
1766 reinit_completion(&ab->recovery_start);
1767 atomic_set(&ab->recovery_start_count, 0);
1769 ath11k_core_pre_reconfigure_recovery(ab);
1771 reinit_completion(&ab->reconfigure_complete);
1772 ath11k_core_post_reconfigure_recovery(ab);
1774 ath11k_dbg(ab, ATH11K_DBG_BOOT, "waiting recovery start...\n");
1776 time_left = wait_for_completion_timeout(&ab->recovery_start,
1777 ATH11K_RECOVER_START_TIMEOUT_HZ);
1779 ath11k_hif_power_down(ab);
1780 ath11k_hif_power_up(ab);
1782 ath11k_dbg(ab, ATH11K_DBG_BOOT, "reset started\n");
1785 static int ath11k_init_hw_params(struct ath11k_base *ab)
1787 const struct ath11k_hw_params *hw_params = NULL;
1790 for (i = 0; i < ARRAY_SIZE(ath11k_hw_params); i++) {
1791 hw_params = &ath11k_hw_params[i];
1793 if (hw_params->hw_rev == ab->hw_rev)
1797 if (i == ARRAY_SIZE(ath11k_hw_params)) {
1798 ath11k_err(ab, "Unsupported hardware version: 0x%x\n", ab->hw_rev);
1802 ab->hw_params = *hw_params;
1804 ath11k_info(ab, "%s\n", ab->hw_params.name);
1809 int ath11k_core_pre_init(struct ath11k_base *ab)
1813 ret = ath11k_init_hw_params(ab);
1815 ath11k_err(ab, "failed to get hw params: %d\n", ret);
1821 EXPORT_SYMBOL(ath11k_core_pre_init);
1823 int ath11k_core_init(struct ath11k_base *ab)
1827 ret = ath11k_core_soc_create(ab);
1829 ath11k_err(ab, "failed to create soc core: %d\n", ret);
1835 EXPORT_SYMBOL(ath11k_core_init);
1837 void ath11k_core_deinit(struct ath11k_base *ab)
1839 mutex_lock(&ab->core_lock);
1841 ath11k_core_pdev_destroy(ab);
1842 ath11k_core_stop(ab);
1844 mutex_unlock(&ab->core_lock);
1846 ath11k_hif_power_down(ab);
1847 ath11k_mac_destroy(ab);
1848 ath11k_core_soc_destroy(ab);
1850 EXPORT_SYMBOL(ath11k_core_deinit);
1852 void ath11k_core_free(struct ath11k_base *ab)
1854 destroy_workqueue(ab->workqueue_aux);
1855 destroy_workqueue(ab->workqueue);
1859 EXPORT_SYMBOL(ath11k_core_free);
1861 struct ath11k_base *ath11k_core_alloc(struct device *dev, size_t priv_size,
1862 enum ath11k_bus bus)
1864 struct ath11k_base *ab;
1866 ab = kzalloc(sizeof(*ab) + priv_size, GFP_KERNEL);
1870 init_completion(&ab->driver_recovery);
1872 ab->workqueue = create_singlethread_workqueue("ath11k_wq");
1876 ab->workqueue_aux = create_singlethread_workqueue("ath11k_aux_wq");
1877 if (!ab->workqueue_aux)
1880 mutex_init(&ab->core_lock);
1881 mutex_init(&ab->tbl_mtx_lock);
1882 spin_lock_init(&ab->base_lock);
1883 mutex_init(&ab->vdev_id_11d_lock);
1884 init_completion(&ab->reset_complete);
1885 init_completion(&ab->reconfigure_complete);
1886 init_completion(&ab->recovery_start);
1888 INIT_LIST_HEAD(&ab->peers);
1889 init_waitqueue_head(&ab->peer_mapping_wq);
1890 init_waitqueue_head(&ab->wmi_ab.tx_credits_wq);
1891 init_waitqueue_head(&ab->qmi.cold_boot_waitq);
1892 INIT_WORK(&ab->restart_work, ath11k_core_restart);
1893 INIT_WORK(&ab->update_11d_work, ath11k_update_11d);
1894 INIT_WORK(&ab->rfkill_work, ath11k_rfkill_work);
1895 INIT_WORK(&ab->reset_work, ath11k_core_reset);
1896 timer_setup(&ab->rx_replenish_retry, ath11k_ce_rx_replenish_retry, 0);
1897 init_completion(&ab->htc_suspend);
1898 init_completion(&ab->wow.wakeup_completed);
1906 destroy_workqueue(ab->workqueue);
1911 EXPORT_SYMBOL(ath11k_core_alloc);
1913 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11ax wireless LAN cards.");
1914 MODULE_LICENSE("Dual BSD/GPL");