2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/module.h>
19 #include <linux/firmware.h>
33 unsigned int ath10k_debug_mask;
34 static unsigned int ath10k_cryptmode_param;
35 static bool uart_print;
39 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
40 module_param_named(cryptmode, ath10k_cryptmode_param, uint, 0644);
41 module_param(uart_print, bool, 0644);
42 module_param(skip_otp, bool, 0644);
43 module_param(rawmode, bool, 0644);
45 MODULE_PARM_DESC(debug_mask, "Debugging mask");
46 MODULE_PARM_DESC(uart_print, "Uart target debugging");
47 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
48 MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
49 MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath");
51 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
53 .id = QCA988X_HW_2_0_VERSION,
54 .name = "qca988x hw2.0",
55 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
57 .has_shifted_cc_wraparound = true,
59 .channel_counters_freq_hz = 88000,
60 .max_probe_resp_desc_thres = 0,
62 .dir = QCA988X_HW_2_0_FW_DIR,
63 .fw = QCA988X_HW_2_0_FW_FILE,
64 .otp = QCA988X_HW_2_0_OTP_FILE,
65 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
66 .board_size = QCA988X_BOARD_DATA_SZ,
67 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
71 .id = QCA6174_HW_2_1_VERSION,
72 .name = "qca6174 hw2.1",
73 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
76 .channel_counters_freq_hz = 88000,
77 .max_probe_resp_desc_thres = 0,
79 .dir = QCA6174_HW_2_1_FW_DIR,
80 .fw = QCA6174_HW_2_1_FW_FILE,
81 .otp = QCA6174_HW_2_1_OTP_FILE,
82 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
83 .board_size = QCA6174_BOARD_DATA_SZ,
84 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
88 .id = QCA6174_HW_3_0_VERSION,
89 .name = "qca6174 hw3.0",
90 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
93 .channel_counters_freq_hz = 88000,
94 .max_probe_resp_desc_thres = 0,
96 .dir = QCA6174_HW_3_0_FW_DIR,
97 .fw = QCA6174_HW_3_0_FW_FILE,
98 .otp = QCA6174_HW_3_0_OTP_FILE,
99 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
100 .board_size = QCA6174_BOARD_DATA_SZ,
101 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
105 .id = QCA6174_HW_3_2_VERSION,
106 .name = "qca6174 hw3.2",
107 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
110 .channel_counters_freq_hz = 88000,
111 .max_probe_resp_desc_thres = 0,
113 /* uses same binaries as hw3.0 */
114 .dir = QCA6174_HW_3_0_FW_DIR,
115 .fw = QCA6174_HW_3_0_FW_FILE,
116 .otp = QCA6174_HW_3_0_OTP_FILE,
117 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
118 .board_size = QCA6174_BOARD_DATA_SZ,
119 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
123 .id = QCA99X0_HW_2_0_DEV_VERSION,
124 .name = "qca99x0 hw2.0",
125 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
127 .otp_exe_param = 0x00000700,
128 .continuous_frag_desc = true,
129 .channel_counters_freq_hz = 150000,
130 .max_probe_resp_desc_thres = 24,
132 .dir = QCA99X0_HW_2_0_FW_DIR,
133 .fw = QCA99X0_HW_2_0_FW_FILE,
134 .otp = QCA99X0_HW_2_0_OTP_FILE,
135 .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
136 .board_size = QCA99X0_BOARD_DATA_SZ,
137 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
142 static const char *const ath10k_core_fw_feature_str[] = {
143 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
144 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
145 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
146 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
147 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
148 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
149 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
150 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
151 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
152 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
153 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
156 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
158 enum ath10k_fw_features feat)
160 /* make sure that ath10k_core_fw_feature_str[] gets updated */
161 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
162 ATH10K_FW_FEATURE_COUNT);
164 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
165 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
166 return scnprintf(buf, buf_len, "bit%d", feat);
169 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
172 void ath10k_core_get_fw_features_str(struct ath10k *ar,
176 unsigned int len = 0;
179 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
180 if (test_bit(i, ar->fw_features)) {
182 len += scnprintf(buf + len, buf_len - len, ",");
184 len += ath10k_core_get_fw_feature_str(buf + len,
191 static void ath10k_send_suspend_complete(struct ath10k *ar)
193 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
195 complete(&ar->target_suspend);
198 static int ath10k_init_configure_target(struct ath10k *ar)
203 /* tell target which HTC version it is used*/
204 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
205 HTC_PROTOCOL_VERSION);
207 ath10k_err(ar, "settings HTC version failed\n");
211 /* set the firmware mode to STA/IBSS/AP */
212 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
214 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
218 /* TODO following parameters need to be re-visited. */
220 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
222 /* FIXME: Why FW_MODE_AP ??.*/
223 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
224 /* mac_addr_method */
225 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
226 /* firmware_bridge */
227 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
229 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
231 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
233 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
237 /* We do all byte-swapping on the host */
238 ret = ath10k_bmi_write32(ar, hi_be, 0);
240 ath10k_err(ar, "setting host CPU BE mode failed\n");
244 /* FW descriptor/Data swap flags */
245 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
248 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
252 /* Some devices have a special sanity check that verifies the PCI
253 * Device ID is written to this host interest var. It is known to be
254 * required to boot QCA6164.
256 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
259 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
266 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
271 const struct firmware *fw;
275 return ERR_PTR(-ENOENT);
280 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
281 ret = request_firmware(&fw, filename, ar->dev);
288 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
291 u32 board_data_size = ar->hw_params.fw.board_size;
292 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
293 u32 board_ext_data_addr;
296 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
298 ath10k_err(ar, "could not read board ext data addr (%d)\n",
303 ath10k_dbg(ar, ATH10K_DBG_BOOT,
304 "boot push board extended data addr 0x%x\n",
305 board_ext_data_addr);
307 if (board_ext_data_addr == 0)
310 if (data_len != (board_data_size + board_ext_data_size)) {
311 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
312 data_len, board_data_size, board_ext_data_size);
316 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
317 data + board_data_size,
318 board_ext_data_size);
320 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
324 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
325 (board_ext_data_size << 16) | 1);
327 ath10k_err(ar, "could not write board ext data bit (%d)\n",
335 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
338 u32 board_data_size = ar->hw_params.fw.board_size;
342 ret = ath10k_push_board_ext_data(ar, data, data_len);
344 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
348 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
350 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
354 ret = ath10k_bmi_write_memory(ar, address, data,
355 min_t(u32, board_data_size,
358 ath10k_err(ar, "could not write board data (%d)\n", ret);
362 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
364 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
372 static int ath10k_download_cal_file(struct ath10k *ar)
379 if (IS_ERR(ar->cal_file))
380 return PTR_ERR(ar->cal_file);
382 ret = ath10k_download_board_data(ar, ar->cal_file->data,
385 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
389 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
394 static int ath10k_download_cal_dt(struct ath10k *ar)
396 struct device_node *node;
401 node = ar->dev->of_node;
403 /* Device Tree is optional, don't print any warnings if
404 * there's no node for ath10k.
408 if (!of_get_property(node, "qcom,ath10k-calibration-data",
410 /* The calibration data node is optional */
414 if (data_len != QCA988X_CAL_DATA_LEN) {
415 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
421 data = kmalloc(data_len, GFP_KERNEL);
427 ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
430 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
435 ret = ath10k_download_board_data(ar, data, data_len);
437 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
451 static int ath10k_download_and_run_otp(struct ath10k *ar)
453 u32 result, address = ar->hw_params.patch_load_addr;
454 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
457 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
459 ath10k_err(ar, "failed to download board data: %d\n", ret);
463 /* OTP is optional */
465 if (!ar->otp_data || !ar->otp_len) {
466 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
467 ar->otp_data, ar->otp_len);
471 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
472 address, ar->otp_len);
474 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
476 ath10k_err(ar, "could not write otp (%d)\n", ret);
480 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
482 ath10k_err(ar, "could not execute otp (%d)\n", ret);
486 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
488 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
491 ath10k_err(ar, "otp calibration failed: %d", result);
498 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
500 u32 address, data_len;
501 const char *mode_name;
505 address = ar->hw_params.patch_load_addr;
508 case ATH10K_FIRMWARE_MODE_NORMAL:
509 data = ar->firmware_data;
510 data_len = ar->firmware_len;
511 mode_name = "normal";
512 ret = ath10k_swap_code_seg_configure(ar,
513 ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW);
515 ath10k_err(ar, "failed to configure fw code swap: %d\n",
520 case ATH10K_FIRMWARE_MODE_UTF:
521 data = ar->testmode.utf->data;
522 data_len = ar->testmode.utf->size;
526 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
530 ath10k_dbg(ar, ATH10K_DBG_BOOT,
531 "boot uploading firmware image %p len %d mode %s\n",
532 data, data_len, mode_name);
534 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
536 ath10k_err(ar, "failed to download %s firmware: %d\n",
544 static void ath10k_core_free_firmware_files(struct ath10k *ar)
546 if (!IS_ERR(ar->board))
547 release_firmware(ar->board);
549 if (!IS_ERR(ar->otp))
550 release_firmware(ar->otp);
552 if (!IS_ERR(ar->firmware))
553 release_firmware(ar->firmware);
555 if (!IS_ERR(ar->cal_file))
556 release_firmware(ar->cal_file);
558 ath10k_swap_code_seg_release(ar);
561 ar->board_data = NULL;
569 ar->firmware_data = NULL;
570 ar->firmware_len = 0;
575 static int ath10k_fetch_cal_file(struct ath10k *ar)
579 /* cal-<bus>-<id>.bin */
580 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
581 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
583 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
584 if (IS_ERR(ar->cal_file))
585 /* calibration file is optional, don't print any warnings */
586 return PTR_ERR(ar->cal_file);
588 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
589 ATH10K_FW_DIR, filename);
594 static int ath10k_core_fetch_spec_board_file(struct ath10k *ar)
598 scnprintf(filename, sizeof(filename), "board-%s-%s.bin",
599 ath10k_bus_str(ar->hif.bus), ar->spec_board_id);
601 ar->board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, filename);
602 if (IS_ERR(ar->board))
603 return PTR_ERR(ar->board);
605 ar->board_data = ar->board->data;
606 ar->board_len = ar->board->size;
607 ar->spec_board_loaded = true;
612 static int ath10k_core_fetch_generic_board_file(struct ath10k *ar)
614 if (!ar->hw_params.fw.board) {
615 ath10k_err(ar, "failed to find board file fw entry\n");
619 ar->board = ath10k_fetch_fw_file(ar,
620 ar->hw_params.fw.dir,
621 ar->hw_params.fw.board);
622 if (IS_ERR(ar->board))
623 return PTR_ERR(ar->board);
625 ar->board_data = ar->board->data;
626 ar->board_len = ar->board->size;
627 ar->spec_board_loaded = false;
632 static int ath10k_core_fetch_board_file(struct ath10k *ar)
636 if (strlen(ar->spec_board_id) > 0) {
637 ret = ath10k_core_fetch_spec_board_file(ar);
639 ath10k_info(ar, "failed to load spec board file, falling back to generic: %d\n",
644 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found specific board file for %s\n",
650 ret = ath10k_core_fetch_generic_board_file(ar);
652 ath10k_err(ar, "failed to fetch generic board data: %d\n", ret);
659 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
663 if (ar->hw_params.fw.fw == NULL) {
664 ath10k_err(ar, "firmware file not defined\n");
668 ar->firmware = ath10k_fetch_fw_file(ar,
669 ar->hw_params.fw.dir,
670 ar->hw_params.fw.fw);
671 if (IS_ERR(ar->firmware)) {
672 ret = PTR_ERR(ar->firmware);
673 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
677 ar->firmware_data = ar->firmware->data;
678 ar->firmware_len = ar->firmware->size;
680 /* OTP may be undefined. If so, don't fetch it at all */
681 if (ar->hw_params.fw.otp == NULL)
684 ar->otp = ath10k_fetch_fw_file(ar,
685 ar->hw_params.fw.dir,
686 ar->hw_params.fw.otp);
687 if (IS_ERR(ar->otp)) {
688 ret = PTR_ERR(ar->otp);
689 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
693 ar->otp_data = ar->otp->data;
694 ar->otp_len = ar->otp->size;
699 ath10k_core_free_firmware_files(ar);
703 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
705 size_t magic_len, len, ie_len;
706 int ie_id, i, index, bit, ret;
707 struct ath10k_fw_ie *hdr;
709 __le32 *timestamp, *version;
711 /* first fetch the firmware file (firmware-*.bin) */
712 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
713 if (IS_ERR(ar->firmware)) {
714 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
715 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
716 return PTR_ERR(ar->firmware);
719 data = ar->firmware->data;
720 len = ar->firmware->size;
722 /* magic also includes the null byte, check that as well */
723 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
725 if (len < magic_len) {
726 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
727 ar->hw_params.fw.dir, name, len);
732 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
733 ath10k_err(ar, "invalid firmware magic\n");
738 /* jump over the padding */
739 magic_len = ALIGN(magic_len, 4);
745 while (len > sizeof(struct ath10k_fw_ie)) {
746 hdr = (struct ath10k_fw_ie *)data;
748 ie_id = le32_to_cpu(hdr->id);
749 ie_len = le32_to_cpu(hdr->len);
752 data += sizeof(*hdr);
755 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
762 case ATH10K_FW_IE_FW_VERSION:
763 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
766 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
767 ar->hw->wiphy->fw_version[ie_len] = '\0';
769 ath10k_dbg(ar, ATH10K_DBG_BOOT,
770 "found fw version %s\n",
771 ar->hw->wiphy->fw_version);
773 case ATH10K_FW_IE_TIMESTAMP:
774 if (ie_len != sizeof(u32))
777 timestamp = (__le32 *)data;
779 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
780 le32_to_cpup(timestamp));
782 case ATH10K_FW_IE_FEATURES:
783 ath10k_dbg(ar, ATH10K_DBG_BOOT,
784 "found firmware features ie (%zd B)\n",
787 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
794 if (data[index] & (1 << bit)) {
795 ath10k_dbg(ar, ATH10K_DBG_BOOT,
796 "Enabling feature bit: %i\n",
798 __set_bit(i, ar->fw_features);
802 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
804 sizeof(ar->fw_features));
806 case ATH10K_FW_IE_FW_IMAGE:
807 ath10k_dbg(ar, ATH10K_DBG_BOOT,
808 "found fw image ie (%zd B)\n",
811 ar->firmware_data = data;
812 ar->firmware_len = ie_len;
815 case ATH10K_FW_IE_OTP_IMAGE:
816 ath10k_dbg(ar, ATH10K_DBG_BOOT,
817 "found otp image ie (%zd B)\n",
821 ar->otp_len = ie_len;
824 case ATH10K_FW_IE_WMI_OP_VERSION:
825 if (ie_len != sizeof(u32))
828 version = (__le32 *)data;
830 ar->wmi.op_version = le32_to_cpup(version);
832 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
835 case ATH10K_FW_IE_HTT_OP_VERSION:
836 if (ie_len != sizeof(u32))
839 version = (__le32 *)data;
841 ar->htt.op_version = le32_to_cpup(version);
843 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
846 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
847 ath10k_dbg(ar, ATH10K_DBG_BOOT,
848 "found fw code swap image ie (%zd B)\n",
850 ar->swap.firmware_codeswap_data = data;
851 ar->swap.firmware_codeswap_len = ie_len;
854 ath10k_warn(ar, "Unknown FW IE: %u\n",
855 le32_to_cpu(hdr->id));
859 /* jump over the padding */
860 ie_len = ALIGN(ie_len, 4);
866 if (!ar->firmware_data || !ar->firmware_len) {
867 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
868 ar->hw_params.fw.dir, name);
876 ath10k_core_free_firmware_files(ar);
880 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
884 /* calibration file is optional, don't check for any errors */
885 ath10k_fetch_cal_file(ar);
887 ret = ath10k_core_fetch_board_file(ar);
889 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
894 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
896 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE);
901 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
903 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE);
908 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
910 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
915 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
917 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
922 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
924 ret = ath10k_core_fetch_firmware_api_1(ar);
929 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
934 static int ath10k_download_cal_data(struct ath10k *ar)
938 ret = ath10k_download_cal_file(ar);
940 ar->cal_mode = ATH10K_CAL_MODE_FILE;
944 ath10k_dbg(ar, ATH10K_DBG_BOOT,
945 "boot did not find a calibration file, try DT next: %d\n",
948 ret = ath10k_download_cal_dt(ar);
950 ar->cal_mode = ATH10K_CAL_MODE_DT;
954 ath10k_dbg(ar, ATH10K_DBG_BOOT,
955 "boot did not find DT entry, try OTP next: %d\n",
958 ret = ath10k_download_and_run_otp(ar);
960 ath10k_err(ar, "failed to run otp: %d\n", ret);
964 ar->cal_mode = ATH10K_CAL_MODE_OTP;
967 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
968 ath10k_cal_mode_str(ar->cal_mode));
972 static int ath10k_init_uart(struct ath10k *ar)
977 * Explicitly setting UART prints to zero as target turns it on
978 * based on scratch registers.
980 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
982 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
989 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
991 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
995 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
997 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1001 /* Set the UART baud rate to 19200. */
1002 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1004 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1008 ath10k_info(ar, "UART prints enabled\n");
1012 static int ath10k_init_hw_params(struct ath10k *ar)
1014 const struct ath10k_hw_params *uninitialized_var(hw_params);
1017 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1018 hw_params = &ath10k_hw_params_list[i];
1020 if (hw_params->id == ar->target_version)
1024 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1025 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1026 ar->target_version);
1030 ar->hw_params = *hw_params;
1032 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1033 ar->hw_params.name, ar->target_version);
1038 static void ath10k_core_restart(struct work_struct *work)
1040 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1042 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1044 /* Place a barrier to make sure the compiler doesn't reorder
1045 * CRASH_FLUSH and calling other functions.
1049 ieee80211_stop_queues(ar->hw);
1050 ath10k_drain_tx(ar);
1051 complete_all(&ar->scan.started);
1052 complete_all(&ar->scan.completed);
1053 complete_all(&ar->scan.on_channel);
1054 complete_all(&ar->offchan_tx_completed);
1055 complete_all(&ar->install_key_done);
1056 complete_all(&ar->vdev_setup_done);
1057 complete_all(&ar->thermal.wmi_sync);
1058 wake_up(&ar->htt.empty_tx_wq);
1059 wake_up(&ar->wmi.tx_credits_wq);
1060 wake_up(&ar->peer_mapping_wq);
1062 mutex_lock(&ar->conf_mutex);
1064 switch (ar->state) {
1065 case ATH10K_STATE_ON:
1066 ar->state = ATH10K_STATE_RESTARTING;
1067 ath10k_hif_stop(ar);
1068 ath10k_scan_finish(ar);
1069 ieee80211_restart_hw(ar->hw);
1071 case ATH10K_STATE_OFF:
1072 /* this can happen if driver is being unloaded
1073 * or if the crash happens during FW probing */
1074 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1076 case ATH10K_STATE_RESTARTING:
1077 /* hw restart might be requested from multiple places */
1079 case ATH10K_STATE_RESTARTED:
1080 ar->state = ATH10K_STATE_WEDGED;
1082 case ATH10K_STATE_WEDGED:
1083 ath10k_warn(ar, "device is wedged, will not restart\n");
1085 case ATH10K_STATE_UTF:
1086 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1090 mutex_unlock(&ar->conf_mutex);
1093 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1095 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
1096 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1097 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1101 if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1102 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1103 ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version);
1107 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1108 switch (ath10k_cryptmode_param) {
1109 case ATH10K_CRYPT_MODE_HW:
1110 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1111 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1113 case ATH10K_CRYPT_MODE_SW:
1114 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1116 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1120 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1121 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1124 ath10k_info(ar, "invalid cryptmode: %d\n",
1125 ath10k_cryptmode_param);
1129 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1130 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1133 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1135 ath10k_err(ar, "rawmode = 1 requires support from firmware");
1138 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1141 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1142 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1146 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1147 * and causes enormous performance issues (malformed frames,
1150 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1151 * albeit a bit slower compared to regular operation.
1153 ar->htt.max_num_amsdu = 1;
1156 /* Backwards compatibility for firmwares without
1157 * ATH10K_FW_IE_WMI_OP_VERSION.
1159 if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1160 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1161 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1163 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1165 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1167 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1171 switch (ar->wmi.op_version) {
1172 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1173 ar->max_num_peers = TARGET_NUM_PEERS;
1174 ar->max_num_stations = TARGET_NUM_STATIONS;
1175 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1176 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1177 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1179 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1181 case ATH10K_FW_WMI_OP_VERSION_10_1:
1182 case ATH10K_FW_WMI_OP_VERSION_10_2:
1183 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1184 ar->max_num_peers = TARGET_10X_NUM_PEERS;
1185 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1186 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1187 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1188 ar->fw_stats_req_mask = WMI_STAT_PEER;
1189 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1191 case ATH10K_FW_WMI_OP_VERSION_TLV:
1192 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1193 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1194 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1195 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1196 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1197 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1198 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1200 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1202 case ATH10K_FW_WMI_OP_VERSION_10_4:
1203 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1204 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1205 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1206 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1207 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1208 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1209 ar->fw_stats_req_mask = WMI_STAT_PEER;
1210 ar->max_spatial_stream = WMI_10_4_MAX_SPATIAL_STREAM;
1212 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1213 case ATH10K_FW_WMI_OP_VERSION_MAX:
1218 /* Backwards compatibility for firmwares without
1219 * ATH10K_FW_IE_HTT_OP_VERSION.
1221 if (ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1222 switch (ar->wmi.op_version) {
1223 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1224 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1226 case ATH10K_FW_WMI_OP_VERSION_10_1:
1227 case ATH10K_FW_WMI_OP_VERSION_10_2:
1228 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1229 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1231 case ATH10K_FW_WMI_OP_VERSION_TLV:
1232 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1234 case ATH10K_FW_WMI_OP_VERSION_10_4:
1235 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1236 case ATH10K_FW_WMI_OP_VERSION_MAX:
1245 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
1249 lockdep_assert_held(&ar->conf_mutex);
1251 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1253 ath10k_bmi_start(ar);
1255 if (ath10k_init_configure_target(ar)) {
1260 status = ath10k_download_cal_data(ar);
1264 /* Some of of qca988x solutions are having global reset issue
1265 * during target initialization. Bypassing PLL setting before
1266 * downloading firmware and letting the SoC run on REF_CLK is
1267 * fixing the problem. Corresponding firmware change is also needed
1268 * to set the clock source once the target is initialized.
1270 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1272 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1274 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
1280 status = ath10k_download_fw(ar, mode);
1284 status = ath10k_init_uart(ar);
1288 ar->htc.htc_ops.target_send_suspend_complete =
1289 ath10k_send_suspend_complete;
1291 status = ath10k_htc_init(ar);
1293 ath10k_err(ar, "could not init HTC (%d)\n", status);
1297 status = ath10k_bmi_done(ar);
1301 status = ath10k_wmi_attach(ar);
1303 ath10k_err(ar, "WMI attach failed: %d\n", status);
1307 status = ath10k_htt_init(ar);
1309 ath10k_err(ar, "failed to init htt: %d\n", status);
1310 goto err_wmi_detach;
1313 status = ath10k_htt_tx_alloc(&ar->htt);
1315 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1316 goto err_wmi_detach;
1319 status = ath10k_htt_rx_alloc(&ar->htt);
1321 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1322 goto err_htt_tx_detach;
1325 status = ath10k_hif_start(ar);
1327 ath10k_err(ar, "could not start HIF: %d\n", status);
1328 goto err_htt_rx_detach;
1331 status = ath10k_htc_wait_target(&ar->htc);
1333 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1337 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1338 status = ath10k_htt_connect(&ar->htt);
1340 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1345 status = ath10k_wmi_connect(ar);
1347 ath10k_err(ar, "could not connect wmi: %d\n", status);
1351 status = ath10k_htc_start(&ar->htc);
1353 ath10k_err(ar, "failed to start htc: %d\n", status);
1357 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1358 status = ath10k_wmi_wait_for_service_ready(ar);
1360 ath10k_warn(ar, "wmi service ready event not received");
1365 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1366 ar->hw->wiphy->fw_version);
1368 status = ath10k_wmi_cmd_init(ar);
1370 ath10k_err(ar, "could not send WMI init command (%d)\n",
1375 status = ath10k_wmi_wait_for_unified_ready(ar);
1377 ath10k_err(ar, "wmi unified ready event not received\n");
1381 /* If firmware indicates Full Rx Reorder support it must be used in a
1382 * slightly different manner. Let HTT code know.
1384 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1387 status = ath10k_htt_rx_ring_refill(ar);
1389 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1393 /* we don't care about HTT in UTF mode */
1394 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1395 status = ath10k_htt_setup(&ar->htt);
1397 ath10k_err(ar, "failed to setup htt: %d\n", status);
1402 status = ath10k_debug_start(ar);
1406 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1408 INIT_LIST_HEAD(&ar->arvifs);
1413 ath10k_hif_stop(ar);
1415 ath10k_htt_rx_free(&ar->htt);
1417 ath10k_htt_tx_free(&ar->htt);
1419 ath10k_wmi_detach(ar);
1423 EXPORT_SYMBOL(ath10k_core_start);
1425 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1428 unsigned long time_left;
1430 reinit_completion(&ar->target_suspend);
1432 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1434 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1438 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1441 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1448 void ath10k_core_stop(struct ath10k *ar)
1450 lockdep_assert_held(&ar->conf_mutex);
1451 ath10k_debug_stop(ar);
1453 /* try to suspend target */
1454 if (ar->state != ATH10K_STATE_RESTARTING &&
1455 ar->state != ATH10K_STATE_UTF)
1456 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1458 ath10k_hif_stop(ar);
1459 ath10k_htt_tx_free(&ar->htt);
1460 ath10k_htt_rx_free(&ar->htt);
1461 ath10k_wmi_detach(ar);
1463 EXPORT_SYMBOL(ath10k_core_stop);
1465 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1466 * order to know what hw capabilities should be advertised to mac80211 it is
1467 * necessary to load the firmware (and tear it down immediately since start
1468 * hook will try to init it again) before registering */
1469 static int ath10k_core_probe_fw(struct ath10k *ar)
1471 struct bmi_target_info target_info;
1474 ret = ath10k_hif_power_up(ar);
1476 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1480 memset(&target_info, 0, sizeof(target_info));
1481 ret = ath10k_bmi_get_target_info(ar, &target_info);
1483 ath10k_err(ar, "could not get target info (%d)\n", ret);
1484 goto err_power_down;
1487 ar->target_version = target_info.version;
1488 ar->hw->wiphy->hw_version = target_info.version;
1490 ret = ath10k_init_hw_params(ar);
1492 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1493 goto err_power_down;
1496 ret = ath10k_core_fetch_firmware_files(ar);
1498 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1499 goto err_power_down;
1502 ret = ath10k_core_init_firmware_features(ar);
1504 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1506 goto err_free_firmware_files;
1509 ret = ath10k_swap_code_seg_init(ar);
1511 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
1513 goto err_free_firmware_files;
1516 mutex_lock(&ar->conf_mutex);
1518 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1520 ath10k_err(ar, "could not init core (%d)\n", ret);
1524 ath10k_print_driver_info(ar);
1525 ath10k_core_stop(ar);
1527 mutex_unlock(&ar->conf_mutex);
1529 ath10k_hif_power_down(ar);
1533 mutex_unlock(&ar->conf_mutex);
1535 err_free_firmware_files:
1536 ath10k_core_free_firmware_files(ar);
1539 ath10k_hif_power_down(ar);
1544 static void ath10k_core_register_work(struct work_struct *work)
1546 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1549 status = ath10k_core_probe_fw(ar);
1551 ath10k_err(ar, "could not probe fw (%d)\n", status);
1555 status = ath10k_mac_register(ar);
1557 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1558 goto err_release_fw;
1561 status = ath10k_debug_register(ar);
1563 ath10k_err(ar, "unable to initialize debugfs\n");
1564 goto err_unregister_mac;
1567 status = ath10k_spectral_create(ar);
1569 ath10k_err(ar, "failed to initialize spectral\n");
1570 goto err_debug_destroy;
1573 status = ath10k_thermal_register(ar);
1575 ath10k_err(ar, "could not register thermal device: %d\n",
1577 goto err_spectral_destroy;
1580 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1583 err_spectral_destroy:
1584 ath10k_spectral_destroy(ar);
1586 ath10k_debug_destroy(ar);
1588 ath10k_mac_unregister(ar);
1590 ath10k_core_free_firmware_files(ar);
1592 /* TODO: It's probably a good idea to release device from the driver
1593 * but calling device_release_driver() here will cause a deadlock.
1598 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1600 ar->chip_id = chip_id;
1601 queue_work(ar->workqueue, &ar->register_work);
1605 EXPORT_SYMBOL(ath10k_core_register);
1607 void ath10k_core_unregister(struct ath10k *ar)
1609 cancel_work_sync(&ar->register_work);
1611 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1614 ath10k_thermal_unregister(ar);
1615 /* Stop spectral before unregistering from mac80211 to remove the
1616 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1617 * would be already be free'd recursively, leading to a double free.
1619 ath10k_spectral_destroy(ar);
1621 /* We must unregister from mac80211 before we stop HTC and HIF.
1622 * Otherwise we will fail to submit commands to FW and mac80211 will be
1623 * unhappy about callback failures. */
1624 ath10k_mac_unregister(ar);
1626 ath10k_testmode_destroy(ar);
1628 ath10k_core_free_firmware_files(ar);
1630 ath10k_debug_unregister(ar);
1632 EXPORT_SYMBOL(ath10k_core_unregister);
1634 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1635 enum ath10k_bus bus,
1636 enum ath10k_hw_rev hw_rev,
1637 const struct ath10k_hif_ops *hif_ops)
1642 ar = ath10k_mac_create(priv_size);
1646 ar->ath_common.priv = ar;
1647 ar->ath_common.hw = ar->hw;
1649 ar->hw_rev = hw_rev;
1650 ar->hif.ops = hif_ops;
1654 case ATH10K_HW_QCA988X:
1655 ar->regs = &qca988x_regs;
1656 ar->hw_values = &qca988x_values;
1658 case ATH10K_HW_QCA6174:
1659 ar->regs = &qca6174_regs;
1660 ar->hw_values = &qca6174_values;
1662 case ATH10K_HW_QCA99X0:
1663 ar->regs = &qca99x0_regs;
1664 ar->hw_values = &qca99x0_values;
1667 ath10k_err(ar, "unsupported core hardware revision %d\n",
1673 init_completion(&ar->scan.started);
1674 init_completion(&ar->scan.completed);
1675 init_completion(&ar->scan.on_channel);
1676 init_completion(&ar->target_suspend);
1677 init_completion(&ar->wow.wakeup_completed);
1679 init_completion(&ar->install_key_done);
1680 init_completion(&ar->vdev_setup_done);
1681 init_completion(&ar->thermal.wmi_sync);
1683 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1685 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1689 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
1690 if (!ar->workqueue_aux)
1693 mutex_init(&ar->conf_mutex);
1694 spin_lock_init(&ar->data_lock);
1696 INIT_LIST_HEAD(&ar->peers);
1697 init_waitqueue_head(&ar->peer_mapping_wq);
1698 init_waitqueue_head(&ar->htt.empty_tx_wq);
1699 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1701 init_completion(&ar->offchan_tx_completed);
1702 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1703 skb_queue_head_init(&ar->offchan_tx_queue);
1705 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1706 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1708 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1709 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1711 ret = ath10k_debug_create(ar);
1713 goto err_free_aux_wq;
1718 destroy_workqueue(ar->workqueue_aux);
1720 destroy_workqueue(ar->workqueue);
1723 ath10k_mac_destroy(ar);
1727 EXPORT_SYMBOL(ath10k_core_create);
1729 void ath10k_core_destroy(struct ath10k *ar)
1731 flush_workqueue(ar->workqueue);
1732 destroy_workqueue(ar->workqueue);
1734 flush_workqueue(ar->workqueue_aux);
1735 destroy_workqueue(ar->workqueue_aux);
1737 ath10k_debug_destroy(ar);
1738 ath10k_wmi_free_host_mem(ar);
1739 ath10k_mac_destroy(ar);
1741 EXPORT_SYMBOL(ath10k_core_destroy);
1743 MODULE_AUTHOR("Qualcomm Atheros");
1744 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1745 MODULE_LICENSE("Dual BSD/GPL");