1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
6 #include <linux/module.h>
7 #include <linux/slab.h>
8 #include <linux/remoteproc.h>
9 #include <linux/firmware.h>
18 unsigned int ath11k_debug_mask
;
19 EXPORT_SYMBOL(ath11k_debug_mask
);
20 module_param_named(debug_mask
, ath11k_debug_mask
, uint
, 0644);
21 MODULE_PARM_DESC(debug_mask
, "Debugging mask");
23 static unsigned int ath11k_crypto_mode
;
24 module_param_named(crypto_mode
, ath11k_crypto_mode
, uint
, 0644);
25 MODULE_PARM_DESC(crypto_mode
, "crypto mode: 0-hardware, 1-software");
27 /* frame mode values are mapped as per enum ath11k_hw_txrx_mode */
28 unsigned int ath11k_frame_mode
= ATH11K_HW_TXRX_NATIVE_WIFI
;
29 module_param_named(frame_mode
, ath11k_frame_mode
, uint
, 0644);
30 MODULE_PARM_DESC(frame_mode
,
31 "Datapath frame mode (0: raw, 1: native wifi (default), 2: ethernet)");
33 static const struct ath11k_hw_params ath11k_hw_params
[] = {
35 .hw_rev
= ATH11K_HW_IPQ8074
,
36 .name
= "ipq8074 hw2.0",
38 .dir
= "IPQ8074/hw2.0",
39 .board_size
= 256 * 1024,
40 .cal_size
= 256 * 1024,
43 .bdf_addr
= 0x4B0C0000,
44 .hw_ops
= &ipq8074_ops
,
45 .ring_mask
= &ath11k_hw_ring_mask_ipq8074
,
46 .internal_sleep_clock
= false,
47 .regs
= &ipq8074_regs
,
48 .host_ce_config
= ath11k_host_ce_config_ipq8074
,
50 .target_ce_config
= ath11k_target_ce_config_wlan_ipq8074
,
51 .target_ce_count
= 11,
52 .svc_to_ce_map
= ath11k_target_service_to_ce_map_wlan_ipq8074
,
53 .svc_to_ce_map_len
= 21,
54 .single_pdev_only
= false,
55 .rxdma1_enable
= true,
56 .num_rxmda_per_pdev
= 1,
57 .rx_mac_buf_ring
= false,
58 .vdev_start_delay
= false,
59 .htt_peer_map_v2
= true,
63 .interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
64 BIT(NL80211_IFTYPE_AP
) |
65 BIT(NL80211_IFTYPE_MESH_POINT
),
66 .supports_monitor
= true,
67 .supports_shadow_regs
= false,
69 .cold_boot_calib
= true,
70 .supports_suspend
= false,
73 .hw_rev
= ATH11K_HW_IPQ6018_HW10
,
74 .name
= "ipq6018 hw1.0",
76 .dir
= "IPQ6018/hw1.0",
77 .board_size
= 256 * 1024,
78 .cal_size
= 256 * 1024,
81 .bdf_addr
= 0x4ABC0000,
82 .hw_ops
= &ipq6018_ops
,
83 .ring_mask
= &ath11k_hw_ring_mask_ipq8074
,
84 .internal_sleep_clock
= false,
85 .regs
= &ipq8074_regs
,
86 .host_ce_config
= ath11k_host_ce_config_ipq8074
,
88 .target_ce_config
= ath11k_target_ce_config_wlan_ipq8074
,
89 .target_ce_count
= 11,
90 .svc_to_ce_map
= ath11k_target_service_to_ce_map_wlan_ipq6018
,
91 .svc_to_ce_map_len
= 19,
92 .single_pdev_only
= false,
93 .rxdma1_enable
= true,
94 .num_rxmda_per_pdev
= 1,
95 .rx_mac_buf_ring
= false,
96 .vdev_start_delay
= false,
97 .htt_peer_map_v2
= true,
101 .interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
102 BIT(NL80211_IFTYPE_AP
) |
103 BIT(NL80211_IFTYPE_MESH_POINT
),
104 .supports_monitor
= true,
105 .supports_shadow_regs
= false,
107 .cold_boot_calib
= true,
108 .supports_suspend
= false,
111 .name
= "qca6390 hw2.0",
112 .hw_rev
= ATH11K_HW_QCA6390_HW20
,
114 .dir
= "QCA6390/hw2.0",
115 .board_size
= 256 * 1024,
116 .cal_size
= 256 * 1024,
119 .bdf_addr
= 0x4B0C0000,
120 .hw_ops
= &qca6390_ops
,
121 .ring_mask
= &ath11k_hw_ring_mask_qca6390
,
122 .internal_sleep_clock
= true,
123 .regs
= &qca6390_regs
,
124 .host_ce_config
= ath11k_host_ce_config_qca6390
,
126 .target_ce_config
= ath11k_target_ce_config_wlan_qca6390
,
127 .target_ce_count
= 9,
128 .svc_to_ce_map
= ath11k_target_service_to_ce_map_wlan_qca6390
,
129 .svc_to_ce_map_len
= 14,
130 .single_pdev_only
= true,
131 .rxdma1_enable
= false,
132 .num_rxmda_per_pdev
= 2,
133 .rx_mac_buf_ring
= true,
134 .vdev_start_delay
= true,
135 .htt_peer_map_v2
= false,
137 .spectral_fft_sz
= 0,
139 .interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
140 BIT(NL80211_IFTYPE_AP
),
141 .supports_monitor
= false,
142 .supports_shadow_regs
= true,
144 .cold_boot_calib
= false,
145 .supports_suspend
= true,
149 int ath11k_core_suspend(struct ath11k_base
*ab
)
153 if (!ab
->hw_params
.supports_suspend
)
156 /* TODO: there can frames in queues so for now add delay as a hack.
157 * Need to implement to handle and remove this delay.
161 ret
= ath11k_dp_rx_pktlog_stop(ab
, true);
163 ath11k_warn(ab
, "failed to stop dp rx (and timer) pktlog during suspend: %d\n",
168 ret
= ath11k_wow_enable(ab
);
170 ath11k_warn(ab
, "failed to enable wow during suspend: %d\n", ret
);
174 ret
= ath11k_dp_rx_pktlog_stop(ab
, false);
176 ath11k_warn(ab
, "failed to stop dp rx pktlog during suspend: %d\n",
181 ath11k_ce_stop_shadow_timers(ab
);
182 ath11k_dp_stop_shadow_timers(ab
);
184 ath11k_hif_irq_disable(ab
);
185 ath11k_hif_ce_irq_disable(ab
);
187 ret
= ath11k_hif_suspend(ab
);
189 ath11k_warn(ab
, "failed to suspend hif: %d\n", ret
);
195 EXPORT_SYMBOL(ath11k_core_suspend
);
197 int ath11k_core_resume(struct ath11k_base
*ab
)
201 if (!ab
->hw_params
.supports_suspend
)
204 ret
= ath11k_hif_resume(ab
);
206 ath11k_warn(ab
, "failed to resume hif during resume: %d\n", ret
);
210 ath11k_hif_ce_irq_enable(ab
);
211 ath11k_hif_irq_enable(ab
);
213 ret
= ath11k_dp_rx_pktlog_start(ab
);
215 ath11k_warn(ab
, "failed to start rx pktlog during resume: %d\n",
220 ret
= ath11k_wow_wakeup(ab
);
222 ath11k_warn(ab
, "failed to wakeup wow during resume: %d\n", ret
);
228 EXPORT_SYMBOL(ath11k_core_resume
);
230 int ath11k_core_check_dt(struct ath11k_base
*ab
)
232 size_t max_len
= sizeof(ab
->qmi
.target
.bdf_ext
);
233 const char *variant
= NULL
;
234 struct device_node
*node
;
236 node
= ab
->dev
->of_node
;
240 of_property_read_string(node
, "qcom,ath11k-calibration-variant",
245 if (strscpy(ab
->qmi
.target
.bdf_ext
, variant
, max_len
) < 0)
246 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
247 "bdf variant string is longer than the buffer can accommodate (variant: %s)\n",
253 static int ath11k_core_create_board_name(struct ath11k_base
*ab
, char *name
,
256 /* strlen(',variant=') + strlen(ab->qmi.target.bdf_ext) */
257 char variant
[9 + ATH11K_QMI_BDF_EXT_STR_LENGTH
] = { 0 };
259 if (ab
->qmi
.target
.bdf_ext
[0] != '\0')
260 scnprintf(variant
, sizeof(variant
), ",variant=%s",
261 ab
->qmi
.target
.bdf_ext
);
263 scnprintf(name
, name_len
,
264 "bus=%s,qmi-chip-id=%d,qmi-board-id=%d%s",
265 ath11k_bus_str(ab
->hif
.bus
),
266 ab
->qmi
.target
.chip_id
,
267 ab
->qmi
.target
.board_id
, variant
);
269 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "boot using board name '%s'\n", name
);
274 const struct firmware
*ath11k_core_firmware_request(struct ath11k_base
*ab
,
277 const struct firmware
*fw
;
282 return ERR_PTR(-ENOENT
);
284 ath11k_core_create_firmware_path(ab
, file
, path
, sizeof(path
));
286 ret
= firmware_request_nowarn(&fw
, path
, ab
->dev
);
290 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "boot firmware request %s size %zu\n",
296 void ath11k_core_free_bdf(struct ath11k_base
*ab
, struct ath11k_board_data
*bd
)
299 release_firmware(bd
->fw
);
301 memset(bd
, 0, sizeof(*bd
));
304 static int ath11k_core_parse_bd_ie_board(struct ath11k_base
*ab
,
305 struct ath11k_board_data
*bd
,
306 const void *buf
, size_t buf_len
,
307 const char *boardname
,
310 const struct ath11k_fw_ie
*hdr
;
311 bool name_match_found
;
312 int ret
, board_ie_id
;
314 const void *board_ie_data
;
316 name_match_found
= false;
318 /* go through ATH11K_BD_IE_BOARD_ elements */
319 while (buf_len
> sizeof(struct ath11k_fw_ie
)) {
321 board_ie_id
= le32_to_cpu(hdr
->id
);
322 board_ie_len
= le32_to_cpu(hdr
->len
);
323 board_ie_data
= hdr
->data
;
325 buf_len
-= sizeof(*hdr
);
328 if (buf_len
< ALIGN(board_ie_len
, 4)) {
329 ath11k_err(ab
, "invalid ATH11K_BD_IE_BOARD length: %zu < %zu\n",
330 buf_len
, ALIGN(board_ie_len
, 4));
335 switch (board_ie_id
) {
336 case ATH11K_BD_IE_BOARD_NAME
:
337 ath11k_dbg_dump(ab
, ATH11K_DBG_BOOT
, "board name", "",
338 board_ie_data
, board_ie_len
);
340 if (board_ie_len
!= strlen(boardname
))
343 ret
= memcmp(board_ie_data
, boardname
, strlen(boardname
));
347 name_match_found
= true;
348 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
349 "boot found match for name '%s'",
352 case ATH11K_BD_IE_BOARD_DATA
:
353 if (!name_match_found
)
357 ath11k_dbg(ab
, ATH11K_DBG_BOOT
,
358 "boot found board data for '%s'", boardname
);
360 bd
->data
= board_ie_data
;
361 bd
->len
= board_ie_len
;
366 ath11k_warn(ab
, "unknown ATH11K_BD_IE_BOARD found: %d\n",
371 /* jump over the padding */
372 board_ie_len
= ALIGN(board_ie_len
, 4);
374 buf_len
-= board_ie_len
;
385 static int ath11k_core_fetch_board_data_api_n(struct ath11k_base
*ab
,
386 struct ath11k_board_data
*bd
,
387 const char *boardname
)
389 size_t len
, magic_len
;
391 char *filename
, filepath
[100];
393 struct ath11k_fw_ie
*hdr
;
396 filename
= ATH11K_BOARD_API2_FILE
;
399 bd
->fw
= ath11k_core_firmware_request(ab
, filename
);
402 return PTR_ERR(bd
->fw
);
407 ath11k_core_create_firmware_path(ab
, filename
,
408 filepath
, sizeof(filepath
));
410 /* magic has extra null byte padded */
411 magic_len
= strlen(ATH11K_BOARD_MAGIC
) + 1;
412 if (len
< magic_len
) {
413 ath11k_err(ab
, "failed to find magic value in %s, file too short: %zu\n",
419 if (memcmp(data
, ATH11K_BOARD_MAGIC
, magic_len
)) {
420 ath11k_err(ab
, "found invalid board magic\n");
425 /* magic is padded to 4 bytes */
426 magic_len
= ALIGN(magic_len
, 4);
427 if (len
< magic_len
) {
428 ath11k_err(ab
, "failed: %s too small to contain board data, len: %zu\n",
437 while (len
> sizeof(struct ath11k_fw_ie
)) {
438 hdr
= (struct ath11k_fw_ie
*)data
;
439 ie_id
= le32_to_cpu(hdr
->id
);
440 ie_len
= le32_to_cpu(hdr
->len
);
445 if (len
< ALIGN(ie_len
, 4)) {
446 ath11k_err(ab
, "invalid length for board ie_id %d ie_len %zu len %zu\n",
452 case ATH11K_BD_IE_BOARD
:
453 ret
= ath11k_core_parse_bd_ie_board(ab
, bd
, data
,
458 /* no match found, continue */
461 /* there was an error, bail out */
463 /* either found or error, so stop searching */
467 /* jump over the padding */
468 ie_len
= ALIGN(ie_len
, 4);
475 if (!bd
->data
|| !bd
->len
) {
477 "failed to fetch board data for %s from %s\n",
478 boardname
, filepath
);
486 ath11k_core_free_bdf(ab
, bd
);
490 static int ath11k_core_fetch_board_data_api_1(struct ath11k_base
*ab
,
491 struct ath11k_board_data
*bd
)
493 bd
->fw
= ath11k_core_firmware_request(ab
, ATH11K_DEFAULT_BOARD_FILE
);
495 return PTR_ERR(bd
->fw
);
497 bd
->data
= bd
->fw
->data
;
498 bd
->len
= bd
->fw
->size
;
503 #define BOARD_NAME_SIZE 100
504 int ath11k_core_fetch_bdf(struct ath11k_base
*ab
, struct ath11k_board_data
*bd
)
506 char boardname
[BOARD_NAME_SIZE
];
509 ret
= ath11k_core_create_board_name(ab
, boardname
, BOARD_NAME_SIZE
);
511 ath11k_err(ab
, "failed to create board name: %d", ret
);
516 ret
= ath11k_core_fetch_board_data_api_n(ab
, bd
, boardname
);
521 ret
= ath11k_core_fetch_board_data_api_1(ab
, bd
);
523 ath11k_err(ab
, "failed to fetch board-2.bin or board.bin from %s\n",
524 ab
->hw_params
.fw
.dir
);
529 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "using board api %d\n", ab
->bd_api
);
533 static void ath11k_core_stop(struct ath11k_base
*ab
)
535 if (!test_bit(ATH11K_FLAG_CRASH_FLUSH
, &ab
->dev_flags
))
536 ath11k_qmi_firmware_stop(ab
);
539 ath11k_wmi_detach(ab
);
540 ath11k_dp_pdev_reo_cleanup(ab
);
542 /* De-Init of components as needed */
545 static int ath11k_core_soc_create(struct ath11k_base
*ab
)
549 ret
= ath11k_qmi_init_service(ab
);
551 ath11k_err(ab
, "failed to initialize qmi :%d\n", ret
);
555 ret
= ath11k_debugfs_soc_create(ab
);
557 ath11k_err(ab
, "failed to create ath11k debugfs\n");
561 ret
= ath11k_hif_power_up(ab
);
563 ath11k_err(ab
, "failed to power up :%d\n", ret
);
564 goto err_debugfs_reg
;
570 ath11k_debugfs_soc_destroy(ab
);
572 ath11k_qmi_deinit_service(ab
);
576 static void ath11k_core_soc_destroy(struct ath11k_base
*ab
)
578 ath11k_debugfs_soc_destroy(ab
);
581 ath11k_qmi_deinit_service(ab
);
584 static int ath11k_core_pdev_create(struct ath11k_base
*ab
)
588 ret
= ath11k_debugfs_pdev_create(ab
);
590 ath11k_err(ab
, "failed to create core pdev debugfs: %d\n", ret
);
594 ret
= ath11k_mac_register(ab
);
596 ath11k_err(ab
, "failed register the radio with mac80211: %d\n", ret
);
600 ret
= ath11k_dp_pdev_alloc(ab
);
602 ath11k_err(ab
, "failed to attach DP pdev: %d\n", ret
);
603 goto err_mac_unregister
;
606 ret
= ath11k_thermal_register(ab
);
608 ath11k_err(ab
, "could not register thermal device: %d\n",
610 goto err_dp_pdev_free
;
613 ret
= ath11k_spectral_init(ab
);
615 ath11k_err(ab
, "failed to init spectral %d\n", ret
);
616 goto err_thermal_unregister
;
621 err_thermal_unregister
:
622 ath11k_thermal_unregister(ab
);
624 ath11k_dp_pdev_free(ab
);
626 ath11k_mac_unregister(ab
);
628 ath11k_debugfs_pdev_destroy(ab
);
633 static void ath11k_core_pdev_destroy(struct ath11k_base
*ab
)
635 ath11k_spectral_deinit(ab
);
636 ath11k_thermal_unregister(ab
);
637 ath11k_mac_unregister(ab
);
638 ath11k_hif_irq_disable(ab
);
639 ath11k_dp_pdev_free(ab
);
640 ath11k_debugfs_pdev_destroy(ab
);
643 static int ath11k_core_start(struct ath11k_base
*ab
,
644 enum ath11k_firmware_mode mode
)
648 ret
= ath11k_qmi_firmware_start(ab
, mode
);
650 ath11k_err(ab
, "failed to attach wmi: %d\n", ret
);
654 ret
= ath11k_wmi_attach(ab
);
656 ath11k_err(ab
, "failed to attach wmi: %d\n", ret
);
657 goto err_firmware_stop
;
660 ret
= ath11k_htc_init(ab
);
662 ath11k_err(ab
, "failed to init htc: %d\n", ret
);
666 ret
= ath11k_hif_start(ab
);
668 ath11k_err(ab
, "failed to start HIF: %d\n", ret
);
672 ret
= ath11k_htc_wait_target(&ab
->htc
);
674 ath11k_err(ab
, "failed to connect to HTC: %d\n", ret
);
678 ret
= ath11k_dp_htt_connect(&ab
->dp
);
680 ath11k_err(ab
, "failed to connect to HTT: %d\n", ret
);
684 ret
= ath11k_wmi_connect(ab
);
686 ath11k_err(ab
, "failed to connect wmi: %d\n", ret
);
690 ret
= ath11k_htc_start(&ab
->htc
);
692 ath11k_err(ab
, "failed to start HTC: %d\n", ret
);
696 ret
= ath11k_wmi_wait_for_service_ready(ab
);
698 ath11k_err(ab
, "failed to receive wmi service ready event: %d\n",
703 ret
= ath11k_mac_allocate(ab
);
705 ath11k_err(ab
, "failed to create new hw device with mac80211 :%d\n",
710 ath11k_dp_pdev_pre_alloc(ab
);
712 ret
= ath11k_dp_pdev_reo_setup(ab
);
714 ath11k_err(ab
, "failed to initialize reo destination rings: %d\n", ret
);
715 goto err_mac_destroy
;
718 ret
= ath11k_wmi_cmd_init(ab
);
720 ath11k_err(ab
, "failed to send wmi init cmd: %d\n", ret
);
721 goto err_reo_cleanup
;
724 ret
= ath11k_wmi_wait_for_unified_ready(ab
);
726 ath11k_err(ab
, "failed to receive wmi unified ready event: %d\n",
728 goto err_reo_cleanup
;
731 /* put hardware to DBS mode */
732 if (ab
->hw_params
.single_pdev_only
) {
733 ret
= ath11k_wmi_set_hw_mode(ab
, WMI_HOST_HW_MODE_DBS
);
735 ath11k_err(ab
, "failed to send dbs mode: %d\n", ret
);
740 ret
= ath11k_dp_tx_htt_h2t_ver_req_msg(ab
);
742 ath11k_err(ab
, "failed to send htt version request message: %d\n",
744 goto err_reo_cleanup
;
750 ath11k_dp_pdev_reo_cleanup(ab
);
752 ath11k_mac_destroy(ab
);
756 ath11k_wmi_detach(ab
);
758 ath11k_qmi_firmware_stop(ab
);
763 int ath11k_core_qmi_firmware_ready(struct ath11k_base
*ab
)
767 ret
= ath11k_ce_init_pipes(ab
);
769 ath11k_err(ab
, "failed to initialize CE: %d\n", ret
);
773 ret
= ath11k_dp_alloc(ab
);
775 ath11k_err(ab
, "failed to init DP: %d\n", ret
);
779 switch (ath11k_crypto_mode
) {
780 case ATH11K_CRYPT_MODE_SW
:
781 set_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED
, &ab
->dev_flags
);
782 set_bit(ATH11K_FLAG_RAW_MODE
, &ab
->dev_flags
);
784 case ATH11K_CRYPT_MODE_HW
:
785 clear_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED
, &ab
->dev_flags
);
786 clear_bit(ATH11K_FLAG_RAW_MODE
, &ab
->dev_flags
);
789 ath11k_info(ab
, "invalid crypto_mode: %d\n", ath11k_crypto_mode
);
793 if (ath11k_frame_mode
== ATH11K_HW_TXRX_RAW
)
794 set_bit(ATH11K_FLAG_RAW_MODE
, &ab
->dev_flags
);
796 mutex_lock(&ab
->core_lock
);
797 ret
= ath11k_core_start(ab
, ATH11K_FIRMWARE_MODE_NORMAL
);
799 ath11k_err(ab
, "failed to start core: %d\n", ret
);
803 ret
= ath11k_core_pdev_create(ab
);
805 ath11k_err(ab
, "failed to create pdev core: %d\n", ret
);
808 ath11k_hif_irq_enable(ab
);
809 mutex_unlock(&ab
->core_lock
);
814 ath11k_core_stop(ab
);
815 ath11k_mac_destroy(ab
);
818 mutex_unlock(&ab
->core_lock
);
822 static int ath11k_core_reconfigure_on_crash(struct ath11k_base
*ab
)
826 mutex_lock(&ab
->core_lock
);
827 ath11k_thermal_unregister(ab
);
828 ath11k_hif_irq_disable(ab
);
829 ath11k_dp_pdev_free(ab
);
830 ath11k_spectral_deinit(ab
);
832 ath11k_wmi_detach(ab
);
833 ath11k_dp_pdev_reo_cleanup(ab
);
834 mutex_unlock(&ab
->core_lock
);
837 ath11k_hal_srng_deinit(ab
);
839 ab
->free_vdev_map
= (1LL << (ab
->num_radios
* TARGET_NUM_VDEVS
)) - 1;
841 ret
= ath11k_hal_srng_init(ab
);
845 clear_bit(ATH11K_FLAG_CRASH_FLUSH
, &ab
->dev_flags
);
847 ret
= ath11k_core_qmi_firmware_ready(ab
);
849 goto err_hal_srng_deinit
;
851 clear_bit(ATH11K_FLAG_RECOVERY
, &ab
->dev_flags
);
856 ath11k_hal_srng_deinit(ab
);
860 void ath11k_core_halt(struct ath11k
*ar
)
862 struct ath11k_base
*ab
= ar
->ab
;
864 lockdep_assert_held(&ar
->conf_mutex
);
866 ar
->num_created_vdevs
= 0;
867 ar
->allocated_vdev_map
= 0;
869 ath11k_mac_scan_finish(ar
);
870 ath11k_mac_peer_cleanup_all(ar
);
871 cancel_delayed_work_sync(&ar
->scan
.timeout
);
872 cancel_work_sync(&ar
->regd_update_work
);
874 rcu_assign_pointer(ab
->pdevs_active
[ar
->pdev_idx
], NULL
);
876 INIT_LIST_HEAD(&ar
->arvifs
);
877 idr_init(&ar
->txmgmt_idr
);
880 static void ath11k_core_restart(struct work_struct
*work
)
882 struct ath11k_base
*ab
= container_of(work
, struct ath11k_base
, restart_work
);
884 struct ath11k_pdev
*pdev
;
887 spin_lock_bh(&ab
->base_lock
);
888 ab
->stats
.fw_crash_counter
++;
889 spin_unlock_bh(&ab
->base_lock
);
891 for (i
= 0; i
< ab
->num_radios
; i
++) {
892 pdev
= &ab
->pdevs
[i
];
894 if (!ar
|| ar
->state
== ATH11K_STATE_OFF
)
897 ieee80211_stop_queues(ar
->hw
);
898 ath11k_mac_drain_tx(ar
);
899 complete(&ar
->scan
.started
);
900 complete(&ar
->scan
.completed
);
901 complete(&ar
->peer_assoc_done
);
902 complete(&ar
->peer_delete_done
);
903 complete(&ar
->install_key_done
);
904 complete(&ar
->vdev_setup_done
);
905 complete(&ar
->vdev_delete_done
);
906 complete(&ar
->bss_survey_done
);
907 complete(&ar
->thermal
.wmi_sync
);
909 wake_up(&ar
->dp
.tx_empty_waitq
);
910 idr_for_each(&ar
->txmgmt_idr
,
911 ath11k_mac_tx_mgmt_pending_free
, ar
);
912 idr_destroy(&ar
->txmgmt_idr
);
915 wake_up(&ab
->wmi_ab
.tx_credits_wq
);
916 wake_up(&ab
->peer_mapping_wq
);
918 ret
= ath11k_core_reconfigure_on_crash(ab
);
920 ath11k_err(ab
, "failed to reconfigure driver on crash recovery\n");
924 for (i
= 0; i
< ab
->num_radios
; i
++) {
925 pdev
= &ab
->pdevs
[i
];
927 if (!ar
|| ar
->state
== ATH11K_STATE_OFF
)
930 mutex_lock(&ar
->conf_mutex
);
933 case ATH11K_STATE_ON
:
934 ar
->state
= ATH11K_STATE_RESTARTING
;
935 ath11k_core_halt(ar
);
936 ieee80211_restart_hw(ar
->hw
);
938 case ATH11K_STATE_OFF
:
940 "cannot restart radio %d that hasn't been started\n",
943 case ATH11K_STATE_RESTARTING
:
945 case ATH11K_STATE_RESTARTED
:
946 ar
->state
= ATH11K_STATE_WEDGED
;
948 case ATH11K_STATE_WEDGED
:
950 "device is wedged, will not restart radio %d\n", i
);
953 mutex_unlock(&ar
->conf_mutex
);
955 complete(&ab
->driver_recovery
);
958 static int ath11k_init_hw_params(struct ath11k_base
*ab
)
960 const struct ath11k_hw_params
*hw_params
= NULL
;
963 for (i
= 0; i
< ARRAY_SIZE(ath11k_hw_params
); i
++) {
964 hw_params
= &ath11k_hw_params
[i
];
966 if (hw_params
->hw_rev
== ab
->hw_rev
)
970 if (i
== ARRAY_SIZE(ath11k_hw_params
)) {
971 ath11k_err(ab
, "Unsupported hardware version: 0x%x\n", ab
->hw_rev
);
975 ab
->hw_params
= *hw_params
;
977 ath11k_dbg(ab
, ATH11K_DBG_BOOT
, "Hardware name %s\n", ab
->hw_params
.name
);
982 int ath11k_core_pre_init(struct ath11k_base
*ab
)
986 ret
= ath11k_init_hw_params(ab
);
988 ath11k_err(ab
, "failed to get hw params: %d\n", ret
);
994 EXPORT_SYMBOL(ath11k_core_pre_init
);
996 int ath11k_core_init(struct ath11k_base
*ab
)
1000 ret
= ath11k_core_soc_create(ab
);
1002 ath11k_err(ab
, "failed to create soc core: %d\n", ret
);
1008 EXPORT_SYMBOL(ath11k_core_init
);
1010 void ath11k_core_deinit(struct ath11k_base
*ab
)
1012 mutex_lock(&ab
->core_lock
);
1014 ath11k_core_pdev_destroy(ab
);
1015 ath11k_core_stop(ab
);
1017 mutex_unlock(&ab
->core_lock
);
1019 ath11k_hif_power_down(ab
);
1020 ath11k_mac_destroy(ab
);
1021 ath11k_core_soc_destroy(ab
);
1023 EXPORT_SYMBOL(ath11k_core_deinit
);
1025 void ath11k_core_free(struct ath11k_base
*ab
)
1029 EXPORT_SYMBOL(ath11k_core_free
);
1031 struct ath11k_base
*ath11k_core_alloc(struct device
*dev
, size_t priv_size
,
1032 enum ath11k_bus bus
,
1033 const struct ath11k_bus_params
*bus_params
)
1035 struct ath11k_base
*ab
;
1037 ab
= kzalloc(sizeof(*ab
) + priv_size
, GFP_KERNEL
);
1041 init_completion(&ab
->driver_recovery
);
1043 ab
->workqueue
= create_singlethread_workqueue("ath11k_wq");
1047 mutex_init(&ab
->core_lock
);
1048 spin_lock_init(&ab
->base_lock
);
1050 INIT_LIST_HEAD(&ab
->peers
);
1051 init_waitqueue_head(&ab
->peer_mapping_wq
);
1052 init_waitqueue_head(&ab
->wmi_ab
.tx_credits_wq
);
1053 init_waitqueue_head(&ab
->qmi
.cold_boot_waitq
);
1054 INIT_WORK(&ab
->restart_work
, ath11k_core_restart
);
1055 timer_setup(&ab
->rx_replenish_retry
, ath11k_ce_rx_replenish_retry
, 0);
1056 init_completion(&ab
->htc_suspend
);
1057 init_completion(&ab
->wow
.wakeup_completed
);
1060 ab
->bus_params
= *bus_params
;
1069 EXPORT_SYMBOL(ath11k_core_alloc
);
1071 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11ax wireless LAN cards.");
1072 MODULE_LICENSE("Dual BSD/GPL");