1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2024 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>
21 unsigned int ath12k_debug_mask
;
22 module_param_named(debug_mask
, ath12k_debug_mask
, uint
, 0644);
23 MODULE_PARM_DESC(debug_mask
, "Debugging mask");
25 static int ath12k_core_rfkill_config(struct ath12k_base
*ab
)
30 if (!(ab
->target_caps
.sys_cap_info
& WMI_SYS_CAP_INFO_RFKILL
))
33 for (i
= 0; i
< ab
->num_radios
; i
++) {
36 ret
= ath12k_mac_rfkill_config(ar
);
37 if (ret
&& ret
!= -EOPNOTSUPP
) {
38 ath12k_warn(ab
, "failed to configure rfkill: %d", ret
);
46 /* Check if we need to continue with suspend/resume operation.
48 * a negative value: error happens and don't continue.
49 * 0: no error but don't continue.
50 * positive value: no error and do continue.
52 static int ath12k_core_continue_suspend_resume(struct ath12k_base
*ab
)
56 if (!ab
->hw_params
->supports_suspend
)
59 /* so far single_pdev_only chips have supports_suspend as true
60 * so pass 0 as a dummy pdev_id here.
63 if (!ar
|| !ar
->ah
|| ar
->ah
->state
!= ATH12K_HW_STATE_OFF
)
69 int ath12k_core_suspend(struct ath12k_base
*ab
)
74 ret
= ath12k_core_continue_suspend_resume(ab
);
78 for (i
= 0; i
< ab
->num_radios
; i
++) {
82 ret
= ath12k_mac_wait_tx_complete(ar
);
84 ath12k_warn(ab
, "failed to wait tx complete: %d\n", ret
);
89 /* PM framework skips suspend_late/resume_early callbacks
90 * if other devices report errors in their suspend callbacks.
91 * However ath12k_core_resume() would still be called because
92 * here we return success thus kernel put us on dpm_suspended_list.
93 * Since we won't go through a power down/up cycle, there is
94 * no chance to call complete(&ab->restart_completed) in
95 * ath12k_core_restart(), making ath12k_core_resume() timeout.
96 * So call it here to avoid this issue. This also works in case
97 * no error happens thus suspend_late/resume_early get called,
98 * because it will be reinitialized in ath12k_core_resume_early().
100 complete(&ab
->restart_completed
);
104 EXPORT_SYMBOL(ath12k_core_suspend
);
106 int ath12k_core_suspend_late(struct ath12k_base
*ab
)
110 ret
= ath12k_core_continue_suspend_resume(ab
);
114 ath12k_acpi_stop(ab
);
116 ath12k_hif_irq_disable(ab
);
117 ath12k_hif_ce_irq_disable(ab
);
119 ath12k_hif_power_down(ab
, true);
123 EXPORT_SYMBOL(ath12k_core_suspend_late
);
125 int ath12k_core_resume_early(struct ath12k_base
*ab
)
129 ret
= ath12k_core_continue_suspend_resume(ab
);
133 reinit_completion(&ab
->restart_completed
);
134 ret
= ath12k_hif_power_up(ab
);
136 ath12k_warn(ab
, "failed to power up hif during resume: %d\n", ret
);
140 EXPORT_SYMBOL(ath12k_core_resume_early
);
142 int ath12k_core_resume(struct ath12k_base
*ab
)
147 ret
= ath12k_core_continue_suspend_resume(ab
);
151 time_left
= wait_for_completion_timeout(&ab
->restart_completed
,
152 ATH12K_RESET_TIMEOUT_HZ
);
153 if (time_left
== 0) {
154 ath12k_warn(ab
, "timeout while waiting for restart complete");
160 EXPORT_SYMBOL(ath12k_core_resume
);
162 static int __ath12k_core_create_board_name(struct ath12k_base
*ab
, char *name
,
163 size_t name_len
, bool with_variant
,
166 /* strlen(',variant=') + strlen(ab->qmi.target.bdf_ext) */
167 char variant
[9 + ATH12K_QMI_BDF_EXT_STR_LENGTH
] = { 0 };
169 if (with_variant
&& ab
->qmi
.target
.bdf_ext
[0] != '\0')
170 scnprintf(variant
, sizeof(variant
), ",variant=%s",
171 ab
->qmi
.target
.bdf_ext
);
173 switch (ab
->id
.bdf_search
) {
174 case ATH12K_BDF_SEARCH_BUS_AND_BOARD
:
176 scnprintf(name
, name_len
,
178 ath12k_bus_str(ab
->hif
.bus
));
180 scnprintf(name
, name_len
,
181 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x,qmi-chip-id=%d,qmi-board-id=%d%s",
182 ath12k_bus_str(ab
->hif
.bus
),
183 ab
->id
.vendor
, ab
->id
.device
,
184 ab
->id
.subsystem_vendor
,
185 ab
->id
.subsystem_device
,
186 ab
->qmi
.target
.chip_id
,
187 ab
->qmi
.target
.board_id
,
191 scnprintf(name
, name_len
,
192 "bus=%s,qmi-chip-id=%d,qmi-board-id=%d%s",
193 ath12k_bus_str(ab
->hif
.bus
),
194 ab
->qmi
.target
.chip_id
,
195 ab
->qmi
.target
.board_id
, variant
);
199 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "boot using board name '%s'\n", name
);
204 static int ath12k_core_create_board_name(struct ath12k_base
*ab
, char *name
,
207 return __ath12k_core_create_board_name(ab
, name
, name_len
, true, false);
210 static int ath12k_core_create_fallback_board_name(struct ath12k_base
*ab
, char *name
,
213 return __ath12k_core_create_board_name(ab
, name
, name_len
, false, false);
216 static int ath12k_core_create_bus_type_board_name(struct ath12k_base
*ab
, char *name
,
219 return __ath12k_core_create_board_name(ab
, name
, name_len
, false, true);
222 const struct firmware
*ath12k_core_firmware_request(struct ath12k_base
*ab
,
225 const struct firmware
*fw
;
230 return ERR_PTR(-ENOENT
);
232 ath12k_core_create_firmware_path(ab
, file
, path
, sizeof(path
));
234 ret
= firmware_request_nowarn(&fw
, path
, ab
->dev
);
238 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "boot firmware request %s size %zu\n",
244 void ath12k_core_free_bdf(struct ath12k_base
*ab
, struct ath12k_board_data
*bd
)
247 release_firmware(bd
->fw
);
249 memset(bd
, 0, sizeof(*bd
));
252 static int ath12k_core_parse_bd_ie_board(struct ath12k_base
*ab
,
253 struct ath12k_board_data
*bd
,
254 const void *buf
, size_t buf_len
,
255 const char *boardname
,
260 const struct ath12k_fw_ie
*hdr
;
261 bool name_match_found
;
262 int ret
, board_ie_id
;
264 const void *board_ie_data
;
266 name_match_found
= false;
268 /* go through ATH12K_BD_IE_BOARD_/ATH12K_BD_IE_REGDB_ elements */
269 while (buf_len
> sizeof(struct ath12k_fw_ie
)) {
271 board_ie_id
= le32_to_cpu(hdr
->id
);
272 board_ie_len
= le32_to_cpu(hdr
->len
);
273 board_ie_data
= hdr
->data
;
275 buf_len
-= sizeof(*hdr
);
278 if (buf_len
< ALIGN(board_ie_len
, 4)) {
279 ath12k_err(ab
, "invalid %s length: %zu < %zu\n",
280 ath12k_bd_ie_type_str(ie_id
),
281 buf_len
, ALIGN(board_ie_len
, 4));
286 if (board_ie_id
== name_id
) {
287 ath12k_dbg_dump(ab
, ATH12K_DBG_BOOT
, "board name", "",
288 board_ie_data
, board_ie_len
);
290 if (board_ie_len
!= strlen(boardname
))
293 ret
= memcmp(board_ie_data
, boardname
, strlen(boardname
));
297 name_match_found
= true;
298 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
299 "boot found match %s for name '%s'",
300 ath12k_bd_ie_type_str(ie_id
),
302 } else if (board_ie_id
== data_id
) {
303 if (!name_match_found
)
307 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
308 "boot found %s for '%s'",
309 ath12k_bd_ie_type_str(ie_id
),
312 bd
->data
= board_ie_data
;
313 bd
->len
= board_ie_len
;
318 ath12k_warn(ab
, "unknown %s id found: %d\n",
319 ath12k_bd_ie_type_str(ie_id
),
323 /* jump over the padding */
324 board_ie_len
= ALIGN(board_ie_len
, 4);
326 buf_len
-= board_ie_len
;
337 static int ath12k_core_fetch_board_data_api_n(struct ath12k_base
*ab
,
338 struct ath12k_board_data
*bd
,
339 const char *boardname
,
344 size_t len
, magic_len
;
346 char *filename
, filepath
[100];
348 struct ath12k_fw_ie
*hdr
;
351 filename
= ATH12K_BOARD_API2_FILE
;
354 bd
->fw
= ath12k_core_firmware_request(ab
, filename
);
357 return PTR_ERR(bd
->fw
);
362 ath12k_core_create_firmware_path(ab
, filename
,
363 filepath
, sizeof(filepath
));
365 /* magic has extra null byte padded */
366 magic_len
= strlen(ATH12K_BOARD_MAGIC
) + 1;
367 if (len
< magic_len
) {
368 ath12k_err(ab
, "failed to find magic value in %s, file too short: %zu\n",
374 if (memcmp(data
, ATH12K_BOARD_MAGIC
, magic_len
)) {
375 ath12k_err(ab
, "found invalid board magic\n");
380 /* magic is padded to 4 bytes */
381 magic_len
= ALIGN(magic_len
, 4);
382 if (len
< magic_len
) {
383 ath12k_err(ab
, "failed: %s too small to contain board data, len: %zu\n",
392 while (len
> sizeof(struct ath12k_fw_ie
)) {
393 hdr
= (struct ath12k_fw_ie
*)data
;
394 ie_id
= le32_to_cpu(hdr
->id
);
395 ie_len
= le32_to_cpu(hdr
->len
);
400 if (len
< ALIGN(ie_len
, 4)) {
401 ath12k_err(ab
, "invalid length for board ie_id %d ie_len %zu len %zu\n",
407 if (ie_id
== ie_id_match
) {
408 ret
= ath12k_core_parse_bd_ie_board(ab
, bd
, data
,
415 /* no match found, continue */
418 /* there was an error, bail out */
420 /* either found or error, so stop searching */
424 /* jump over the padding */
425 ie_len
= ALIGN(ie_len
, 4);
432 if (!bd
->data
|| !bd
->len
) {
433 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
434 "failed to fetch %s for %s from %s\n",
435 ath12k_bd_ie_type_str(ie_id_match
),
436 boardname
, filepath
);
444 ath12k_core_free_bdf(ab
, bd
);
448 int ath12k_core_fetch_board_data_api_1(struct ath12k_base
*ab
,
449 struct ath12k_board_data
*bd
,
452 bd
->fw
= ath12k_core_firmware_request(ab
, filename
);
454 return PTR_ERR(bd
->fw
);
456 bd
->data
= bd
->fw
->data
;
457 bd
->len
= bd
->fw
->size
;
462 #define BOARD_NAME_SIZE 200
463 int ath12k_core_fetch_bdf(struct ath12k_base
*ab
, struct ath12k_board_data
*bd
)
465 char boardname
[BOARD_NAME_SIZE
], fallback_boardname
[BOARD_NAME_SIZE
];
466 char *filename
, filepath
[100];
470 filename
= ATH12K_BOARD_API2_FILE
;
472 ret
= ath12k_core_create_board_name(ab
, boardname
, sizeof(boardname
));
474 ath12k_err(ab
, "failed to create board name: %d", ret
);
479 ret
= ath12k_core_fetch_board_data_api_n(ab
, bd
, boardname
,
481 ATH12K_BD_IE_BOARD_NAME
,
482 ATH12K_BD_IE_BOARD_DATA
);
486 ret
= ath12k_core_create_fallback_board_name(ab
, fallback_boardname
,
487 sizeof(fallback_boardname
));
489 ath12k_err(ab
, "failed to create fallback board name: %d", ret
);
493 ret
= ath12k_core_fetch_board_data_api_n(ab
, bd
, fallback_boardname
,
495 ATH12K_BD_IE_BOARD_NAME
,
496 ATH12K_BD_IE_BOARD_DATA
);
501 ret
= ath12k_core_fetch_board_data_api_1(ab
, bd
, ATH12K_DEFAULT_BOARD_FILE
);
503 ath12k_core_create_firmware_path(ab
, filename
,
504 filepath
, sizeof(filepath
));
505 ath12k_err(ab
, "failed to fetch board data for %s from %s\n",
506 boardname
, filepath
);
507 if (memcmp(boardname
, fallback_boardname
, strlen(boardname
)))
508 ath12k_err(ab
, "failed to fetch board data for %s from %s\n",
509 fallback_boardname
, filepath
);
511 ath12k_err(ab
, "failed to fetch board.bin from %s\n",
512 ab
->hw_params
->fw
.dir
);
517 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "using board api %d\n", bd_api
);
521 int ath12k_core_fetch_regdb(struct ath12k_base
*ab
, struct ath12k_board_data
*bd
)
523 char boardname
[BOARD_NAME_SIZE
], default_boardname
[BOARD_NAME_SIZE
];
526 ret
= ath12k_core_create_board_name(ab
, boardname
, BOARD_NAME_SIZE
);
528 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
529 "failed to create board name for regdb: %d", ret
);
533 ret
= ath12k_core_fetch_board_data_api_n(ab
, bd
, boardname
,
535 ATH12K_BD_IE_REGDB_NAME
,
536 ATH12K_BD_IE_REGDB_DATA
);
540 ret
= ath12k_core_create_bus_type_board_name(ab
, default_boardname
,
543 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
544 "failed to create default board name for regdb: %d", ret
);
548 ret
= ath12k_core_fetch_board_data_api_n(ab
, bd
, default_boardname
,
550 ATH12K_BD_IE_REGDB_NAME
,
551 ATH12K_BD_IE_REGDB_DATA
);
555 ret
= ath12k_core_fetch_board_data_api_1(ab
, bd
, ATH12K_REGDB_FILE_NAME
);
557 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "failed to fetch %s from %s\n",
558 ATH12K_REGDB_FILE_NAME
, ab
->hw_params
->fw
.dir
);
562 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "fetched regdb\n");
567 u32
ath12k_core_get_max_station_per_radio(struct ath12k_base
*ab
)
569 if (ab
->num_radios
== 2)
570 return TARGET_NUM_STATIONS_DBS
;
571 else if (ab
->num_radios
== 3)
572 return TARGET_NUM_PEERS_PDEV_DBS_SBS
;
573 return TARGET_NUM_STATIONS_SINGLE
;
576 u32
ath12k_core_get_max_peers_per_radio(struct ath12k_base
*ab
)
578 if (ab
->num_radios
== 2)
579 return TARGET_NUM_PEERS_PDEV_DBS
;
580 else if (ab
->num_radios
== 3)
581 return TARGET_NUM_PEERS_PDEV_DBS_SBS
;
582 return TARGET_NUM_PEERS_PDEV_SINGLE
;
585 u32
ath12k_core_get_max_num_tids(struct ath12k_base
*ab
)
587 if (ab
->num_radios
== 2)
588 return TARGET_NUM_TIDS(DBS
);
589 else if (ab
->num_radios
== 3)
590 return TARGET_NUM_TIDS(DBS_SBS
);
591 return TARGET_NUM_TIDS(SINGLE
);
594 static void ath12k_core_stop(struct ath12k_base
*ab
)
596 if (!test_bit(ATH12K_FLAG_CRASH_FLUSH
, &ab
->dev_flags
))
597 ath12k_qmi_firmware_stop(ab
);
599 ath12k_acpi_stop(ab
);
602 ath12k_wmi_detach(ab
);
603 ath12k_dp_rx_pdev_reo_cleanup(ab
);
605 /* De-Init of components as needed */
608 static void ath12k_core_check_bdfext(const struct dmi_header
*hdr
, void *data
)
610 struct ath12k_base
*ab
= data
;
611 const char *magic
= ATH12K_SMBIOS_BDF_EXT_MAGIC
;
612 struct ath12k_smbios_bdf
*smbios
= (struct ath12k_smbios_bdf
*)hdr
;
617 if (ab
->qmi
.target
.bdf_ext
[0] != '\0')
620 if (hdr
->type
!= ATH12K_SMBIOS_BDF_EXT_TYPE
)
623 if (hdr
->length
!= ATH12K_SMBIOS_BDF_EXT_LENGTH
) {
624 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
625 "wrong smbios bdf ext type length (%d).\n",
630 if (!smbios
->bdf_enabled
) {
631 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "bdf variant name not found.\n");
635 /* Only one string exists (per spec) */
636 if (memcmp(smbios
->bdf_ext
, magic
, strlen(magic
)) != 0) {
637 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
638 "bdf variant magic does not match.\n");
643 strlen(smbios
->bdf_ext
), sizeof(ab
->qmi
.target
.bdf_ext
));
644 for (i
= 0; i
< len
; i
++) {
645 if (!isascii(smbios
->bdf_ext
[i
]) || !isprint(smbios
->bdf_ext
[i
])) {
646 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
647 "bdf variant name contains non ascii chars.\n");
652 /* Copy extension name without magic prefix */
653 copied
= strscpy(ab
->qmi
.target
.bdf_ext
, smbios
->bdf_ext
+ strlen(magic
),
654 sizeof(ab
->qmi
.target
.bdf_ext
));
656 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
657 "bdf variant string is longer than the buffer can accommodate\n");
661 ath12k_dbg(ab
, ATH12K_DBG_BOOT
,
662 "found and validated bdf variant smbios_type 0x%x bdf %s\n",
663 ATH12K_SMBIOS_BDF_EXT_TYPE
, ab
->qmi
.target
.bdf_ext
);
666 int ath12k_core_check_smbios(struct ath12k_base
*ab
)
668 ab
->qmi
.target
.bdf_ext
[0] = '\0';
669 dmi_walk(ath12k_core_check_bdfext
, ab
);
671 if (ab
->qmi
.target
.bdf_ext
[0] == '\0')
677 static int ath12k_core_soc_create(struct ath12k_base
*ab
)
681 ret
= ath12k_qmi_init_service(ab
);
683 ath12k_err(ab
, "failed to initialize qmi :%d\n", ret
);
687 ath12k_debugfs_soc_create(ab
);
689 ret
= ath12k_hif_power_up(ab
);
691 ath12k_err(ab
, "failed to power up :%d\n", ret
);
698 ath12k_debugfs_soc_destroy(ab
);
699 ath12k_qmi_deinit_service(ab
);
703 static void ath12k_core_soc_destroy(struct ath12k_base
*ab
)
707 ath12k_debugfs_soc_destroy(ab
);
708 ath12k_qmi_deinit_service(ab
);
711 static int ath12k_core_pdev_create(struct ath12k_base
*ab
)
715 ret
= ath12k_mac_register(ab
);
717 ath12k_err(ab
, "failed register the radio with mac80211: %d\n", ret
);
721 ret
= ath12k_dp_pdev_alloc(ab
);
723 ath12k_err(ab
, "failed to attach DP pdev: %d\n", ret
);
724 goto err_mac_unregister
;
730 ath12k_mac_unregister(ab
);
735 static void ath12k_core_pdev_destroy(struct ath12k_base
*ab
)
737 ath12k_mac_unregister(ab
);
738 ath12k_hif_irq_disable(ab
);
739 ath12k_dp_pdev_free(ab
);
742 static int ath12k_core_start(struct ath12k_base
*ab
,
743 enum ath12k_firmware_mode mode
)
747 ret
= ath12k_wmi_attach(ab
);
749 ath12k_err(ab
, "failed to attach wmi: %d\n", ret
);
753 ret
= ath12k_htc_init(ab
);
755 ath12k_err(ab
, "failed to init htc: %d\n", ret
);
759 ret
= ath12k_hif_start(ab
);
761 ath12k_err(ab
, "failed to start HIF: %d\n", ret
);
765 ret
= ath12k_htc_wait_target(&ab
->htc
);
767 ath12k_err(ab
, "failed to connect to HTC: %d\n", ret
);
771 ret
= ath12k_dp_htt_connect(&ab
->dp
);
773 ath12k_err(ab
, "failed to connect to HTT: %d\n", ret
);
777 ret
= ath12k_wmi_connect(ab
);
779 ath12k_err(ab
, "failed to connect wmi: %d\n", ret
);
783 ret
= ath12k_htc_start(&ab
->htc
);
785 ath12k_err(ab
, "failed to start HTC: %d\n", ret
);
789 ret
= ath12k_wmi_wait_for_service_ready(ab
);
791 ath12k_err(ab
, "failed to receive wmi service ready event: %d\n",
796 ret
= ath12k_mac_allocate(ab
);
798 ath12k_err(ab
, "failed to create new hw device with mac80211 :%d\n",
803 ath12k_dp_cc_config(ab
);
805 ret
= ath12k_dp_rx_pdev_reo_setup(ab
);
807 ath12k_err(ab
, "failed to initialize reo destination rings: %d\n", ret
);
808 goto err_mac_destroy
;
811 ath12k_dp_hal_rx_desc_init(ab
);
813 ret
= ath12k_wmi_cmd_init(ab
);
815 ath12k_err(ab
, "failed to send wmi init cmd: %d\n", ret
);
816 goto err_reo_cleanup
;
819 ret
= ath12k_wmi_wait_for_unified_ready(ab
);
821 ath12k_err(ab
, "failed to receive wmi unified ready event: %d\n",
823 goto err_reo_cleanup
;
826 /* put hardware to DBS mode */
827 if (ab
->hw_params
->single_pdev_only
) {
828 ret
= ath12k_wmi_set_hw_mode(ab
, WMI_HOST_HW_MODE_DBS
);
830 ath12k_err(ab
, "failed to send dbs mode: %d\n", ret
);
831 goto err_reo_cleanup
;
835 ret
= ath12k_dp_tx_htt_h2t_ver_req_msg(ab
);
837 ath12k_err(ab
, "failed to send htt version request message: %d\n",
839 goto err_reo_cleanup
;
842 ret
= ath12k_acpi_start(ab
);
844 /* ACPI is optional so continue in case of an error */
845 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "acpi failed: %d\n", ret
);
850 ath12k_dp_rx_pdev_reo_cleanup(ab
);
852 ath12k_mac_destroy(ab
);
856 ath12k_wmi_detach(ab
);
860 static int ath12k_core_start_firmware(struct ath12k_base
*ab
,
861 enum ath12k_firmware_mode mode
)
865 ath12k_ce_get_shadow_config(ab
, &ab
->qmi
.ce_cfg
.shadow_reg_v3
,
866 &ab
->qmi
.ce_cfg
.shadow_reg_v3_len
);
868 ret
= ath12k_qmi_firmware_start(ab
, mode
);
870 ath12k_err(ab
, "failed to send firmware start: %d\n", ret
);
877 int ath12k_core_qmi_firmware_ready(struct ath12k_base
*ab
)
881 ret
= ath12k_core_start_firmware(ab
, ATH12K_FIRMWARE_MODE_NORMAL
);
883 ath12k_err(ab
, "failed to start firmware: %d\n", ret
);
887 ret
= ath12k_ce_init_pipes(ab
);
889 ath12k_err(ab
, "failed to initialize CE: %d\n", ret
);
890 goto err_firmware_stop
;
893 ret
= ath12k_dp_alloc(ab
);
895 ath12k_err(ab
, "failed to init DP: %d\n", ret
);
896 goto err_firmware_stop
;
899 mutex_lock(&ab
->core_lock
);
900 ret
= ath12k_core_start(ab
, ATH12K_FIRMWARE_MODE_NORMAL
);
902 ath12k_err(ab
, "failed to start core: %d\n", ret
);
906 ret
= ath12k_core_pdev_create(ab
);
908 ath12k_err(ab
, "failed to create pdev core: %d\n", ret
);
911 ath12k_hif_irq_enable(ab
);
913 ret
= ath12k_core_rfkill_config(ab
);
914 if (ret
&& ret
!= -EOPNOTSUPP
) {
915 ath12k_err(ab
, "failed to config rfkill: %d\n", ret
);
916 goto err_core_pdev_destroy
;
919 mutex_unlock(&ab
->core_lock
);
923 err_core_pdev_destroy
:
924 ath12k_core_pdev_destroy(ab
);
926 ath12k_core_stop(ab
);
927 ath12k_mac_destroy(ab
);
930 mutex_unlock(&ab
->core_lock
);
932 ath12k_qmi_firmware_stop(ab
);
937 static int ath12k_core_reconfigure_on_crash(struct ath12k_base
*ab
)
941 mutex_lock(&ab
->core_lock
);
942 ath12k_dp_pdev_free(ab
);
943 ath12k_ce_cleanup_pipes(ab
);
944 ath12k_wmi_detach(ab
);
945 ath12k_dp_rx_pdev_reo_cleanup(ab
);
946 mutex_unlock(&ab
->core_lock
);
949 ath12k_hal_srng_deinit(ab
);
951 ab
->free_vdev_map
= (1LL << (ab
->num_radios
* TARGET_NUM_VDEVS
)) - 1;
953 ret
= ath12k_hal_srng_init(ab
);
957 clear_bit(ATH12K_FLAG_CRASH_FLUSH
, &ab
->dev_flags
);
959 ret
= ath12k_core_qmi_firmware_ready(ab
);
961 goto err_hal_srng_deinit
;
963 clear_bit(ATH12K_FLAG_RECOVERY
, &ab
->dev_flags
);
968 ath12k_hal_srng_deinit(ab
);
972 static void ath12k_rfkill_work(struct work_struct
*work
)
974 struct ath12k_base
*ab
= container_of(work
, struct ath12k_base
, rfkill_work
);
976 struct ath12k_hw
*ah
;
977 struct ieee80211_hw
*hw
;
978 bool rfkill_radio_on
;
981 spin_lock_bh(&ab
->base_lock
);
982 rfkill_radio_on
= ab
->rfkill_radio_on
;
983 spin_unlock_bh(&ab
->base_lock
);
985 for (i
= 0; i
< ab
->num_hw
; i
++) {
990 for (j
= 0; j
< ah
->num_radio
; j
++) {
995 ath12k_mac_rfkill_enable_radio(ar
, rfkill_radio_on
);
999 wiphy_rfkill_set_hw_state(hw
->wiphy
, !rfkill_radio_on
);
1003 void ath12k_core_halt(struct ath12k
*ar
)
1005 struct ath12k_base
*ab
= ar
->ab
;
1007 lockdep_assert_wiphy(ath12k_ar_to_hw(ar
)->wiphy
);
1009 ar
->num_created_vdevs
= 0;
1010 ar
->allocated_vdev_map
= 0;
1012 ath12k_mac_scan_finish(ar
);
1013 ath12k_mac_peer_cleanup_all(ar
);
1014 cancel_delayed_work_sync(&ar
->scan
.timeout
);
1015 cancel_work_sync(&ar
->regd_update_work
);
1016 cancel_work_sync(&ab
->rfkill_work
);
1018 rcu_assign_pointer(ab
->pdevs_active
[ar
->pdev_idx
], NULL
);
1020 INIT_LIST_HEAD(&ar
->arvifs
);
1021 idr_init(&ar
->txmgmt_idr
);
1024 static void ath12k_core_pre_reconfigure_recovery(struct ath12k_base
*ab
)
1027 struct ath12k_hw
*ah
;
1030 spin_lock_bh(&ab
->base_lock
);
1031 ab
->stats
.fw_crash_counter
++;
1032 spin_unlock_bh(&ab
->base_lock
);
1035 set_bit(ATH12K_FLAG_CRASH_FLUSH
, &ab
->dev_flags
);
1037 for (i
= 0; i
< ab
->num_hw
; i
++) {
1039 if (!ah
|| ah
->state
== ATH12K_HW_STATE_OFF
)
1042 ieee80211_stop_queues(ah
->hw
);
1044 for (j
= 0; j
< ah
->num_radio
; j
++) {
1047 ath12k_mac_drain_tx(ar
);
1048 complete(&ar
->scan
.started
);
1049 complete(&ar
->scan
.completed
);
1050 complete(&ar
->scan
.on_channel
);
1051 complete(&ar
->peer_assoc_done
);
1052 complete(&ar
->peer_delete_done
);
1053 complete(&ar
->install_key_done
);
1054 complete(&ar
->vdev_setup_done
);
1055 complete(&ar
->vdev_delete_done
);
1056 complete(&ar
->bss_survey_done
);
1058 wake_up(&ar
->dp
.tx_empty_waitq
);
1059 idr_for_each(&ar
->txmgmt_idr
,
1060 ath12k_mac_tx_mgmt_pending_free
, ar
);
1061 idr_destroy(&ar
->txmgmt_idr
);
1062 wake_up(&ar
->txmgmt_empty_waitq
);
1066 wake_up(&ab
->wmi_ab
.tx_credits_wq
);
1067 wake_up(&ab
->peer_mapping_wq
);
1070 static void ath12k_core_post_reconfigure_recovery(struct ath12k_base
*ab
)
1072 struct ath12k_hw
*ah
;
1076 for (i
= 0; i
< ab
->num_hw
; i
++) {
1078 if (!ah
|| ah
->state
== ATH12K_HW_STATE_OFF
)
1081 wiphy_lock(ah
->hw
->wiphy
);
1082 mutex_lock(&ah
->hw_mutex
);
1084 switch (ah
->state
) {
1085 case ATH12K_HW_STATE_ON
:
1086 ah
->state
= ATH12K_HW_STATE_RESTARTING
;
1088 for (j
= 0; j
< ah
->num_radio
; j
++) {
1090 ath12k_core_halt(ar
);
1094 case ATH12K_HW_STATE_OFF
:
1096 "cannot restart hw %d that hasn't been started\n",
1099 case ATH12K_HW_STATE_RESTARTING
:
1101 case ATH12K_HW_STATE_RESTARTED
:
1102 ah
->state
= ATH12K_HW_STATE_WEDGED
;
1104 case ATH12K_HW_STATE_WEDGED
:
1106 "device is wedged, will not restart hw %d\n", i
);
1110 mutex_unlock(&ah
->hw_mutex
);
1111 wiphy_unlock(ah
->hw
->wiphy
);
1114 complete(&ab
->driver_recovery
);
1117 static void ath12k_core_restart(struct work_struct
*work
)
1119 struct ath12k_base
*ab
= container_of(work
, struct ath12k_base
, restart_work
);
1120 struct ath12k_hw
*ah
;
1123 ret
= ath12k_core_reconfigure_on_crash(ab
);
1125 ath12k_err(ab
, "failed to reconfigure driver on crash recovery\n");
1130 for (i
= 0; i
< ab
->num_hw
; i
++) {
1132 ieee80211_restart_hw(ah
->hw
);
1136 complete(&ab
->restart_completed
);
1139 static void ath12k_core_reset(struct work_struct
*work
)
1141 struct ath12k_base
*ab
= container_of(work
, struct ath12k_base
, reset_work
);
1142 int reset_count
, fail_cont_count
;
1145 if (!(test_bit(ATH12K_FLAG_REGISTERED
, &ab
->dev_flags
))) {
1146 ath12k_warn(ab
, "ignore reset dev flags 0x%lx\n", ab
->dev_flags
);
1150 /* Sometimes the recovery will fail and then the next all recovery fail,
1151 * this is to avoid infinite recovery since it can not recovery success
1153 fail_cont_count
= atomic_read(&ab
->fail_cont_count
);
1155 if (fail_cont_count
>= ATH12K_RESET_MAX_FAIL_COUNT_FINAL
)
1158 if (fail_cont_count
>= ATH12K_RESET_MAX_FAIL_COUNT_FIRST
&&
1159 time_before(jiffies
, ab
->reset_fail_timeout
))
1162 reset_count
= atomic_inc_return(&ab
->reset_count
);
1164 if (reset_count
> 1) {
1165 /* Sometimes it happened another reset worker before the previous one
1166 * completed, then the second reset worker will destroy the previous one,
1167 * thus below is to avoid that.
1169 ath12k_warn(ab
, "already resetting count %d\n", reset_count
);
1171 reinit_completion(&ab
->reset_complete
);
1172 time_left
= wait_for_completion_timeout(&ab
->reset_complete
,
1173 ATH12K_RESET_TIMEOUT_HZ
);
1175 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "to skip reset\n");
1176 atomic_dec(&ab
->reset_count
);
1180 ab
->reset_fail_timeout
= jiffies
+ ATH12K_RESET_FAIL_TIMEOUT_HZ
;
1181 /* Record the continuous recovery fail count when recovery failed*/
1182 fail_cont_count
= atomic_inc_return(&ab
->fail_cont_count
);
1185 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "reset starting\n");
1187 ab
->is_reset
= true;
1188 atomic_set(&ab
->recovery_count
, 0);
1190 ath12k_coredump_collect(ab
);
1191 ath12k_core_pre_reconfigure_recovery(ab
);
1193 ath12k_core_post_reconfigure_recovery(ab
);
1195 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "waiting recovery start...\n");
1197 ath12k_hif_irq_disable(ab
);
1198 ath12k_hif_ce_irq_disable(ab
);
1200 ath12k_hif_power_down(ab
, false);
1201 ath12k_hif_power_up(ab
);
1203 ath12k_dbg(ab
, ATH12K_DBG_BOOT
, "reset started\n");
1206 int ath12k_core_pre_init(struct ath12k_base
*ab
)
1210 ret
= ath12k_hw_init(ab
);
1212 ath12k_err(ab
, "failed to init hw params: %d\n", ret
);
1221 static int ath12k_core_panic_handler(struct notifier_block
*nb
,
1222 unsigned long action
, void *data
)
1224 struct ath12k_base
*ab
= container_of(nb
, struct ath12k_base
,
1227 return ath12k_hif_panic_handler(ab
);
1230 static int ath12k_core_panic_notifier_register(struct ath12k_base
*ab
)
1232 ab
->panic_nb
.notifier_call
= ath12k_core_panic_handler
;
1234 return atomic_notifier_chain_register(&panic_notifier_list
,
1238 static void ath12k_core_panic_notifier_unregister(struct ath12k_base
*ab
)
1240 atomic_notifier_chain_unregister(&panic_notifier_list
,
1244 int ath12k_core_init(struct ath12k_base
*ab
)
1248 ret
= ath12k_core_soc_create(ab
);
1250 ath12k_err(ab
, "failed to create soc core: %d\n", ret
);
1254 ret
= ath12k_core_panic_notifier_register(ab
);
1256 ath12k_warn(ab
, "failed to register panic handler: %d\n", ret
);
1261 void ath12k_core_deinit(struct ath12k_base
*ab
)
1263 ath12k_core_panic_notifier_unregister(ab
);
1265 mutex_lock(&ab
->core_lock
);
1267 ath12k_core_pdev_destroy(ab
);
1268 ath12k_core_stop(ab
);
1270 mutex_unlock(&ab
->core_lock
);
1272 ath12k_hif_power_down(ab
, false);
1273 ath12k_mac_destroy(ab
);
1274 ath12k_core_soc_destroy(ab
);
1275 ath12k_fw_unmap(ab
);
1278 void ath12k_core_free(struct ath12k_base
*ab
)
1280 timer_delete_sync(&ab
->rx_replenish_retry
);
1281 destroy_workqueue(ab
->workqueue_aux
);
1282 destroy_workqueue(ab
->workqueue
);
1286 struct ath12k_base
*ath12k_core_alloc(struct device
*dev
, size_t priv_size
,
1287 enum ath12k_bus bus
)
1289 struct ath12k_base
*ab
;
1291 ab
= kzalloc(sizeof(*ab
) + priv_size
, GFP_KERNEL
);
1295 init_completion(&ab
->driver_recovery
);
1297 ab
->workqueue
= create_singlethread_workqueue("ath12k_wq");
1301 ab
->workqueue_aux
= create_singlethread_workqueue("ath12k_aux_wq");
1302 if (!ab
->workqueue_aux
)
1305 mutex_init(&ab
->core_lock
);
1306 spin_lock_init(&ab
->base_lock
);
1307 init_completion(&ab
->reset_complete
);
1309 INIT_LIST_HEAD(&ab
->peers
);
1310 init_waitqueue_head(&ab
->peer_mapping_wq
);
1311 init_waitqueue_head(&ab
->wmi_ab
.tx_credits_wq
);
1312 INIT_WORK(&ab
->restart_work
, ath12k_core_restart
);
1313 INIT_WORK(&ab
->reset_work
, ath12k_core_reset
);
1314 INIT_WORK(&ab
->rfkill_work
, ath12k_rfkill_work
);
1315 INIT_WORK(&ab
->dump_work
, ath12k_coredump_upload
);
1317 timer_setup(&ab
->rx_replenish_retry
, ath12k_ce_rx_replenish_retry
, 0);
1318 init_completion(&ab
->htc_suspend
);
1319 init_completion(&ab
->restart_completed
);
1320 init_completion(&ab
->wow
.wakeup_completed
);
1324 ab
->qmi
.num_radios
= U8_MAX
;
1325 ab
->mlo_capable_flags
= ATH12K_INTRA_DEVICE_MLO_SUPPORT
;
1327 /* Device index used to identify the devices in a group.
1329 * In Intra-device MLO, only one device present in a group,
1330 * so it is always zero.
1332 * In Inter-device MLO, Multiple device present in a group,
1333 * expect non-zero value.
1340 destroy_workqueue(ab
->workqueue
);
1346 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11be wireless LAN cards.");
1347 MODULE_LICENSE("Dual BSD/GPL");