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,
141 .id = QCA9377_HW_1_0_DEV_VERSION,
142 .name = "qca9377 hw1.0",
143 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
147 .dir = QCA9377_HW_1_0_FW_DIR,
148 .fw = QCA9377_HW_1_0_FW_FILE,
149 .otp = QCA9377_HW_1_0_OTP_FILE,
150 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
151 .board_size = QCA9377_BOARD_DATA_SZ,
152 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
157 static const char *const ath10k_core_fw_feature_str[] = {
158 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
159 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
160 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
161 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
162 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
163 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
164 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
165 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
166 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
167 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
168 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
169 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA] = "adaptive-cca",
172 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
174 enum ath10k_fw_features feat)
176 /* make sure that ath10k_core_fw_feature_str[] gets updated */
177 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
178 ATH10K_FW_FEATURE_COUNT);
180 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
181 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
182 return scnprintf(buf, buf_len, "bit%d", feat);
185 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
188 void ath10k_core_get_fw_features_str(struct ath10k *ar,
192 unsigned int len = 0;
195 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
196 if (test_bit(i, ar->fw_features)) {
198 len += scnprintf(buf + len, buf_len - len, ",");
200 len += ath10k_core_get_fw_feature_str(buf + len,
207 static void ath10k_send_suspend_complete(struct ath10k *ar)
209 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
211 complete(&ar->target_suspend);
214 static int ath10k_init_configure_target(struct ath10k *ar)
219 /* tell target which HTC version it is used*/
220 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
221 HTC_PROTOCOL_VERSION);
223 ath10k_err(ar, "settings HTC version failed\n");
227 /* set the firmware mode to STA/IBSS/AP */
228 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
230 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
234 /* TODO following parameters need to be re-visited. */
236 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
238 /* FIXME: Why FW_MODE_AP ??.*/
239 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
240 /* mac_addr_method */
241 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
242 /* firmware_bridge */
243 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
245 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
247 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
249 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
253 /* We do all byte-swapping on the host */
254 ret = ath10k_bmi_write32(ar, hi_be, 0);
256 ath10k_err(ar, "setting host CPU BE mode failed\n");
260 /* FW descriptor/Data swap flags */
261 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
264 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
268 /* Some devices have a special sanity check that verifies the PCI
269 * Device ID is written to this host interest var. It is known to be
270 * required to boot QCA6164.
272 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
275 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
282 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
287 const struct firmware *fw;
291 return ERR_PTR(-ENOENT);
296 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
297 ret = request_firmware(&fw, filename, ar->dev);
304 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
307 u32 board_data_size = ar->hw_params.fw.board_size;
308 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
309 u32 board_ext_data_addr;
312 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
314 ath10k_err(ar, "could not read board ext data addr (%d)\n",
319 ath10k_dbg(ar, ATH10K_DBG_BOOT,
320 "boot push board extended data addr 0x%x\n",
321 board_ext_data_addr);
323 if (board_ext_data_addr == 0)
326 if (data_len != (board_data_size + board_ext_data_size)) {
327 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
328 data_len, board_data_size, board_ext_data_size);
332 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
333 data + board_data_size,
334 board_ext_data_size);
336 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
340 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
341 (board_ext_data_size << 16) | 1);
343 ath10k_err(ar, "could not write board ext data bit (%d)\n",
351 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
354 u32 board_data_size = ar->hw_params.fw.board_size;
358 ret = ath10k_push_board_ext_data(ar, data, data_len);
360 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
364 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
366 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
370 ret = ath10k_bmi_write_memory(ar, address, data,
371 min_t(u32, board_data_size,
374 ath10k_err(ar, "could not write board data (%d)\n", ret);
378 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
380 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
388 static int ath10k_download_cal_file(struct ath10k *ar)
395 if (IS_ERR(ar->cal_file))
396 return PTR_ERR(ar->cal_file);
398 ret = ath10k_download_board_data(ar, ar->cal_file->data,
401 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
405 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
410 static int ath10k_download_cal_dt(struct ath10k *ar)
412 struct device_node *node;
417 node = ar->dev->of_node;
419 /* Device Tree is optional, don't print any warnings if
420 * there's no node for ath10k.
424 if (!of_get_property(node, "qcom,ath10k-calibration-data",
426 /* The calibration data node is optional */
430 if (data_len != QCA988X_CAL_DATA_LEN) {
431 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
437 data = kmalloc(data_len, GFP_KERNEL);
443 ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
446 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
451 ret = ath10k_download_board_data(ar, data, data_len);
453 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
467 static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
470 u8 board_id, chip_id;
473 address = ar->hw_params.patch_load_addr;
475 if (!ar->otp_data || !ar->otp_len) {
477 "failed to retrieve board id because of invalid otp\n");
481 ath10k_dbg(ar, ATH10K_DBG_BOOT,
482 "boot upload otp to 0x%x len %zd for board id\n",
483 address, ar->otp_len);
485 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
487 ath10k_err(ar, "could not write otp for board id check: %d\n",
492 ret = ath10k_bmi_execute(ar, address, BMI_PARAM_GET_EEPROM_BOARD_ID,
495 ath10k_err(ar, "could not execute otp for board id check: %d\n",
500 board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP);
501 chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP);
503 ath10k_dbg(ar, ATH10K_DBG_BOOT,
504 "boot get otp board id result 0x%08x board_id %d chip_id %d\n",
505 result, board_id, chip_id);
507 if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0)
510 ar->id.bmi_ids_valid = true;
511 ar->id.bmi_board_id = board_id;
512 ar->id.bmi_chip_id = chip_id;
517 static int ath10k_download_and_run_otp(struct ath10k *ar)
519 u32 result, address = ar->hw_params.patch_load_addr;
520 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
523 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
525 ath10k_err(ar, "failed to download board data: %d\n", ret);
529 /* OTP is optional */
531 if (!ar->otp_data || !ar->otp_len) {
532 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
533 ar->otp_data, ar->otp_len);
537 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
538 address, ar->otp_len);
540 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
542 ath10k_err(ar, "could not write otp (%d)\n", ret);
546 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
548 ath10k_err(ar, "could not execute otp (%d)\n", ret);
552 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
554 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
557 ath10k_err(ar, "otp calibration failed: %d", result);
564 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
566 u32 address, data_len;
567 const char *mode_name;
571 address = ar->hw_params.patch_load_addr;
574 case ATH10K_FIRMWARE_MODE_NORMAL:
575 data = ar->firmware_data;
576 data_len = ar->firmware_len;
577 mode_name = "normal";
578 ret = ath10k_swap_code_seg_configure(ar,
579 ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW);
581 ath10k_err(ar, "failed to configure fw code swap: %d\n",
586 case ATH10K_FIRMWARE_MODE_UTF:
587 data = ar->testmode.utf_firmware_data;
588 data_len = ar->testmode.utf_firmware_len;
592 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
596 ath10k_dbg(ar, ATH10K_DBG_BOOT,
597 "boot uploading firmware image %p len %d mode %s\n",
598 data, data_len, mode_name);
600 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
602 ath10k_err(ar, "failed to download %s firmware: %d\n",
610 static void ath10k_core_free_board_files(struct ath10k *ar)
612 if (!IS_ERR(ar->board))
613 release_firmware(ar->board);
616 ar->board_data = NULL;
620 static void ath10k_core_free_firmware_files(struct ath10k *ar)
622 if (!IS_ERR(ar->otp))
623 release_firmware(ar->otp);
625 if (!IS_ERR(ar->firmware))
626 release_firmware(ar->firmware);
628 if (!IS_ERR(ar->cal_file))
629 release_firmware(ar->cal_file);
631 ath10k_swap_code_seg_release(ar);
638 ar->firmware_data = NULL;
639 ar->firmware_len = 0;
644 static int ath10k_fetch_cal_file(struct ath10k *ar)
648 /* cal-<bus>-<id>.bin */
649 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
650 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
652 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
653 if (IS_ERR(ar->cal_file))
654 /* calibration file is optional, don't print any warnings */
655 return PTR_ERR(ar->cal_file);
657 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
658 ATH10K_FW_DIR, filename);
663 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar)
665 if (!ar->hw_params.fw.board) {
666 ath10k_err(ar, "failed to find board file fw entry\n");
670 ar->board = ath10k_fetch_fw_file(ar,
671 ar->hw_params.fw.dir,
672 ar->hw_params.fw.board);
673 if (IS_ERR(ar->board))
674 return PTR_ERR(ar->board);
676 ar->board_data = ar->board->data;
677 ar->board_len = ar->board->size;
682 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
683 const void *buf, size_t buf_len,
684 const char *boardname)
686 const struct ath10k_fw_ie *hdr;
687 bool name_match_found;
688 int ret, board_ie_id;
690 const void *board_ie_data;
692 name_match_found = false;
694 /* go through ATH10K_BD_IE_BOARD_ elements */
695 while (buf_len > sizeof(struct ath10k_fw_ie)) {
697 board_ie_id = le32_to_cpu(hdr->id);
698 board_ie_len = le32_to_cpu(hdr->len);
699 board_ie_data = hdr->data;
701 buf_len -= sizeof(*hdr);
704 if (buf_len < ALIGN(board_ie_len, 4)) {
705 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
706 buf_len, ALIGN(board_ie_len, 4));
711 switch (board_ie_id) {
712 case ATH10K_BD_IE_BOARD_NAME:
713 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
714 board_ie_data, board_ie_len);
716 if (board_ie_len != strlen(boardname))
719 ret = memcmp(board_ie_data, boardname, strlen(boardname));
723 name_match_found = true;
724 ath10k_dbg(ar, ATH10K_DBG_BOOT,
725 "boot found match for name '%s'",
728 case ATH10K_BD_IE_BOARD_DATA:
729 if (!name_match_found)
733 ath10k_dbg(ar, ATH10K_DBG_BOOT,
734 "boot found board data for '%s'",
737 ar->board_data = board_ie_data;
738 ar->board_len = board_ie_len;
743 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
748 /* jump over the padding */
749 board_ie_len = ALIGN(board_ie_len, 4);
751 buf_len -= board_ie_len;
762 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
763 const char *boardname,
764 const char *filename)
766 size_t len, magic_len, ie_len;
767 struct ath10k_fw_ie *hdr;
771 ar->board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, filename);
772 if (IS_ERR(ar->board))
773 return PTR_ERR(ar->board);
775 data = ar->board->data;
776 len = ar->board->size;
778 /* magic has extra null byte padded */
779 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
780 if (len < magic_len) {
781 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
782 ar->hw_params.fw.dir, filename, len);
787 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
788 ath10k_err(ar, "found invalid board magic\n");
793 /* magic is padded to 4 bytes */
794 magic_len = ALIGN(magic_len, 4);
795 if (len < magic_len) {
796 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
797 ar->hw_params.fw.dir, filename, len);
805 while (len > sizeof(struct ath10k_fw_ie)) {
806 hdr = (struct ath10k_fw_ie *)data;
807 ie_id = le32_to_cpu(hdr->id);
808 ie_len = le32_to_cpu(hdr->len);
813 if (len < ALIGN(ie_len, 4)) {
814 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
821 case ATH10K_BD_IE_BOARD:
822 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
825 /* no match found, continue */
828 /* there was an error, bail out */
831 /* board data found */
835 /* jump over the padding */
836 ie_len = ALIGN(ie_len, 4);
843 if (!ar->board_data || !ar->board_len) {
845 "failed to fetch board data for %s from %s/%s\n",
846 ar->hw_params.fw.dir, boardname, filename);
854 ath10k_core_free_board_files(ar);
858 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
861 if (ar->id.bmi_ids_valid) {
862 scnprintf(name, name_len,
863 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d",
864 ath10k_bus_str(ar->hif.bus),
866 ar->id.bmi_board_id);
870 scnprintf(name, name_len,
871 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
872 ath10k_bus_str(ar->hif.bus),
873 ar->id.vendor, ar->id.device,
874 ar->id.subsystem_vendor, ar->id.subsystem_device);
877 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
882 static int ath10k_core_fetch_board_file(struct ath10k *ar)
887 ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
889 ath10k_err(ar, "failed to create board name: %d", ret);
894 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
895 ATH10K_BOARD_API2_FILE);
900 ret = ath10k_core_fetch_board_data_api_1(ar);
902 ath10k_err(ar, "failed to fetch board data\n");
907 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
911 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
915 if (ar->hw_params.fw.fw == NULL) {
916 ath10k_err(ar, "firmware file not defined\n");
920 ar->firmware = ath10k_fetch_fw_file(ar,
921 ar->hw_params.fw.dir,
922 ar->hw_params.fw.fw);
923 if (IS_ERR(ar->firmware)) {
924 ret = PTR_ERR(ar->firmware);
925 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
929 ar->firmware_data = ar->firmware->data;
930 ar->firmware_len = ar->firmware->size;
932 /* OTP may be undefined. If so, don't fetch it at all */
933 if (ar->hw_params.fw.otp == NULL)
936 ar->otp = ath10k_fetch_fw_file(ar,
937 ar->hw_params.fw.dir,
938 ar->hw_params.fw.otp);
939 if (IS_ERR(ar->otp)) {
940 ret = PTR_ERR(ar->otp);
941 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
945 ar->otp_data = ar->otp->data;
946 ar->otp_len = ar->otp->size;
951 ath10k_core_free_firmware_files(ar);
955 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
957 size_t magic_len, len, ie_len;
958 int ie_id, i, index, bit, ret;
959 struct ath10k_fw_ie *hdr;
961 __le32 *timestamp, *version;
963 /* first fetch the firmware file (firmware-*.bin) */
964 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
965 if (IS_ERR(ar->firmware)) {
966 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
967 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
968 return PTR_ERR(ar->firmware);
971 data = ar->firmware->data;
972 len = ar->firmware->size;
974 /* magic also includes the null byte, check that as well */
975 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
977 if (len < magic_len) {
978 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
979 ar->hw_params.fw.dir, name, len);
984 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
985 ath10k_err(ar, "invalid firmware magic\n");
990 /* jump over the padding */
991 magic_len = ALIGN(magic_len, 4);
997 while (len > sizeof(struct ath10k_fw_ie)) {
998 hdr = (struct ath10k_fw_ie *)data;
1000 ie_id = le32_to_cpu(hdr->id);
1001 ie_len = le32_to_cpu(hdr->len);
1003 len -= sizeof(*hdr);
1004 data += sizeof(*hdr);
1007 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
1008 ie_id, len, ie_len);
1014 case ATH10K_FW_IE_FW_VERSION:
1015 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
1018 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
1019 ar->hw->wiphy->fw_version[ie_len] = '\0';
1021 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1022 "found fw version %s\n",
1023 ar->hw->wiphy->fw_version);
1025 case ATH10K_FW_IE_TIMESTAMP:
1026 if (ie_len != sizeof(u32))
1029 timestamp = (__le32 *)data;
1031 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
1032 le32_to_cpup(timestamp));
1034 case ATH10K_FW_IE_FEATURES:
1035 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1036 "found firmware features ie (%zd B)\n",
1039 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
1043 if (index == ie_len)
1046 if (data[index] & (1 << bit)) {
1047 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1048 "Enabling feature bit: %i\n",
1050 __set_bit(i, ar->fw_features);
1054 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
1056 sizeof(ar->fw_features));
1058 case ATH10K_FW_IE_FW_IMAGE:
1059 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1060 "found fw image ie (%zd B)\n",
1063 ar->firmware_data = data;
1064 ar->firmware_len = ie_len;
1067 case ATH10K_FW_IE_OTP_IMAGE:
1068 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1069 "found otp image ie (%zd B)\n",
1072 ar->otp_data = data;
1073 ar->otp_len = ie_len;
1076 case ATH10K_FW_IE_WMI_OP_VERSION:
1077 if (ie_len != sizeof(u32))
1080 version = (__le32 *)data;
1082 ar->wmi.op_version = le32_to_cpup(version);
1084 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1085 ar->wmi.op_version);
1087 case ATH10K_FW_IE_HTT_OP_VERSION:
1088 if (ie_len != sizeof(u32))
1091 version = (__le32 *)data;
1093 ar->htt.op_version = le32_to_cpup(version);
1095 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1096 ar->htt.op_version);
1098 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1099 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1100 "found fw code swap image ie (%zd B)\n",
1102 ar->swap.firmware_codeswap_data = data;
1103 ar->swap.firmware_codeswap_len = ie_len;
1106 ath10k_warn(ar, "Unknown FW IE: %u\n",
1107 le32_to_cpu(hdr->id));
1111 /* jump over the padding */
1112 ie_len = ALIGN(ie_len, 4);
1118 if (!ar->firmware_data || !ar->firmware_len) {
1119 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1120 ar->hw_params.fw.dir, name);
1128 ath10k_core_free_firmware_files(ar);
1132 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1136 /* calibration file is optional, don't check for any errors */
1137 ath10k_fetch_cal_file(ar);
1140 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1142 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE);
1147 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1149 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE);
1154 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1156 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
1161 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1163 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
1168 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1170 ret = ath10k_core_fetch_firmware_api_1(ar);
1175 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1180 static int ath10k_download_cal_data(struct ath10k *ar)
1184 ret = ath10k_download_cal_file(ar);
1186 ar->cal_mode = ATH10K_CAL_MODE_FILE;
1190 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1191 "boot did not find a calibration file, try DT next: %d\n",
1194 ret = ath10k_download_cal_dt(ar);
1196 ar->cal_mode = ATH10K_CAL_MODE_DT;
1200 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1201 "boot did not find DT entry, try OTP next: %d\n",
1204 ret = ath10k_download_and_run_otp(ar);
1206 ath10k_err(ar, "failed to run otp: %d\n", ret);
1210 ar->cal_mode = ATH10K_CAL_MODE_OTP;
1213 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1214 ath10k_cal_mode_str(ar->cal_mode));
1218 static int ath10k_init_uart(struct ath10k *ar)
1223 * Explicitly setting UART prints to zero as target turns it on
1224 * based on scratch registers.
1226 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
1228 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
1235 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
1237 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1241 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
1243 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1247 /* Set the UART baud rate to 19200. */
1248 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1250 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1254 ath10k_info(ar, "UART prints enabled\n");
1258 static int ath10k_init_hw_params(struct ath10k *ar)
1260 const struct ath10k_hw_params *uninitialized_var(hw_params);
1263 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1264 hw_params = &ath10k_hw_params_list[i];
1266 if (hw_params->id == ar->target_version)
1270 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1271 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1272 ar->target_version);
1276 ar->hw_params = *hw_params;
1278 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1279 ar->hw_params.name, ar->target_version);
1284 static void ath10k_core_restart(struct work_struct *work)
1286 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1288 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1290 /* Place a barrier to make sure the compiler doesn't reorder
1291 * CRASH_FLUSH and calling other functions.
1295 ieee80211_stop_queues(ar->hw);
1296 ath10k_drain_tx(ar);
1297 complete_all(&ar->scan.started);
1298 complete_all(&ar->scan.completed);
1299 complete_all(&ar->scan.on_channel);
1300 complete_all(&ar->offchan_tx_completed);
1301 complete_all(&ar->install_key_done);
1302 complete_all(&ar->vdev_setup_done);
1303 complete_all(&ar->thermal.wmi_sync);
1304 wake_up(&ar->htt.empty_tx_wq);
1305 wake_up(&ar->wmi.tx_credits_wq);
1306 wake_up(&ar->peer_mapping_wq);
1308 mutex_lock(&ar->conf_mutex);
1310 switch (ar->state) {
1311 case ATH10K_STATE_ON:
1312 ar->state = ATH10K_STATE_RESTARTING;
1313 ath10k_hif_stop(ar);
1314 ath10k_scan_finish(ar);
1315 ieee80211_restart_hw(ar->hw);
1317 case ATH10K_STATE_OFF:
1318 /* this can happen if driver is being unloaded
1319 * or if the crash happens during FW probing */
1320 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1322 case ATH10K_STATE_RESTARTING:
1323 /* hw restart might be requested from multiple places */
1325 case ATH10K_STATE_RESTARTED:
1326 ar->state = ATH10K_STATE_WEDGED;
1328 case ATH10K_STATE_WEDGED:
1329 ath10k_warn(ar, "device is wedged, will not restart\n");
1331 case ATH10K_STATE_UTF:
1332 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1336 mutex_unlock(&ar->conf_mutex);
1339 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1341 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
1342 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1343 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1347 if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1348 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1349 ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version);
1353 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1354 switch (ath10k_cryptmode_param) {
1355 case ATH10K_CRYPT_MODE_HW:
1356 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1357 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1359 case ATH10K_CRYPT_MODE_SW:
1360 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1362 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1366 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1367 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1370 ath10k_info(ar, "invalid cryptmode: %d\n",
1371 ath10k_cryptmode_param);
1375 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1376 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1379 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1381 ath10k_err(ar, "rawmode = 1 requires support from firmware");
1384 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1387 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1388 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1392 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1393 * and causes enormous performance issues (malformed frames,
1396 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1397 * albeit a bit slower compared to regular operation.
1399 ar->htt.max_num_amsdu = 1;
1402 /* Backwards compatibility for firmwares without
1403 * ATH10K_FW_IE_WMI_OP_VERSION.
1405 if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1406 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1407 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1409 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1411 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1413 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1417 switch (ar->wmi.op_version) {
1418 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1419 ar->max_num_peers = TARGET_NUM_PEERS;
1420 ar->max_num_stations = TARGET_NUM_STATIONS;
1421 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1422 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1423 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1425 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1427 case ATH10K_FW_WMI_OP_VERSION_10_1:
1428 case ATH10K_FW_WMI_OP_VERSION_10_2:
1429 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1430 ar->max_num_peers = TARGET_10X_NUM_PEERS;
1431 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1432 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1433 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1434 ar->fw_stats_req_mask = WMI_STAT_PEER;
1435 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1437 case ATH10K_FW_WMI_OP_VERSION_TLV:
1438 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1439 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1440 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1441 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1442 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1443 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1444 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1446 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1448 case ATH10K_FW_WMI_OP_VERSION_10_4:
1449 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1450 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1451 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1452 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1453 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1454 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1455 ar->fw_stats_req_mask = WMI_STAT_PEER;
1456 ar->max_spatial_stream = WMI_10_4_MAX_SPATIAL_STREAM;
1458 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1459 case ATH10K_FW_WMI_OP_VERSION_MAX:
1464 /* Backwards compatibility for firmwares without
1465 * ATH10K_FW_IE_HTT_OP_VERSION.
1467 if (ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1468 switch (ar->wmi.op_version) {
1469 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1470 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1472 case ATH10K_FW_WMI_OP_VERSION_10_1:
1473 case ATH10K_FW_WMI_OP_VERSION_10_2:
1474 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1475 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1477 case ATH10K_FW_WMI_OP_VERSION_TLV:
1478 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1480 case ATH10K_FW_WMI_OP_VERSION_10_4:
1481 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1482 case ATH10K_FW_WMI_OP_VERSION_MAX:
1491 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
1495 lockdep_assert_held(&ar->conf_mutex);
1497 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1499 ath10k_bmi_start(ar);
1501 if (ath10k_init_configure_target(ar)) {
1506 status = ath10k_download_cal_data(ar);
1510 /* Some of of qca988x solutions are having global reset issue
1511 * during target initialization. Bypassing PLL setting before
1512 * downloading firmware and letting the SoC run on REF_CLK is
1513 * fixing the problem. Corresponding firmware change is also needed
1514 * to set the clock source once the target is initialized.
1516 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1518 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1520 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
1526 status = ath10k_download_fw(ar, mode);
1530 status = ath10k_init_uart(ar);
1534 ar->htc.htc_ops.target_send_suspend_complete =
1535 ath10k_send_suspend_complete;
1537 status = ath10k_htc_init(ar);
1539 ath10k_err(ar, "could not init HTC (%d)\n", status);
1543 status = ath10k_bmi_done(ar);
1547 status = ath10k_wmi_attach(ar);
1549 ath10k_err(ar, "WMI attach failed: %d\n", status);
1553 status = ath10k_htt_init(ar);
1555 ath10k_err(ar, "failed to init htt: %d\n", status);
1556 goto err_wmi_detach;
1559 status = ath10k_htt_tx_alloc(&ar->htt);
1561 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1562 goto err_wmi_detach;
1565 status = ath10k_htt_rx_alloc(&ar->htt);
1567 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1568 goto err_htt_tx_detach;
1571 status = ath10k_hif_start(ar);
1573 ath10k_err(ar, "could not start HIF: %d\n", status);
1574 goto err_htt_rx_detach;
1577 status = ath10k_htc_wait_target(&ar->htc);
1579 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1583 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1584 status = ath10k_htt_connect(&ar->htt);
1586 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1591 status = ath10k_wmi_connect(ar);
1593 ath10k_err(ar, "could not connect wmi: %d\n", status);
1597 status = ath10k_htc_start(&ar->htc);
1599 ath10k_err(ar, "failed to start htc: %d\n", status);
1603 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1604 status = ath10k_wmi_wait_for_service_ready(ar);
1606 ath10k_warn(ar, "wmi service ready event not received");
1611 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1612 ar->hw->wiphy->fw_version);
1614 status = ath10k_wmi_cmd_init(ar);
1616 ath10k_err(ar, "could not send WMI init command (%d)\n",
1621 status = ath10k_wmi_wait_for_unified_ready(ar);
1623 ath10k_err(ar, "wmi unified ready event not received\n");
1627 /* If firmware indicates Full Rx Reorder support it must be used in a
1628 * slightly different manner. Let HTT code know.
1630 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1633 status = ath10k_htt_rx_ring_refill(ar);
1635 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1639 /* we don't care about HTT in UTF mode */
1640 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1641 status = ath10k_htt_setup(&ar->htt);
1643 ath10k_err(ar, "failed to setup htt: %d\n", status);
1648 status = ath10k_debug_start(ar);
1652 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1654 INIT_LIST_HEAD(&ar->arvifs);
1659 ath10k_hif_stop(ar);
1661 ath10k_htt_rx_free(&ar->htt);
1663 ath10k_htt_tx_free(&ar->htt);
1665 ath10k_wmi_detach(ar);
1669 EXPORT_SYMBOL(ath10k_core_start);
1671 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1674 unsigned long time_left;
1676 reinit_completion(&ar->target_suspend);
1678 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1680 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1684 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1687 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1694 void ath10k_core_stop(struct ath10k *ar)
1696 lockdep_assert_held(&ar->conf_mutex);
1697 ath10k_debug_stop(ar);
1699 /* try to suspend target */
1700 if (ar->state != ATH10K_STATE_RESTARTING &&
1701 ar->state != ATH10K_STATE_UTF)
1702 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1704 ath10k_hif_stop(ar);
1705 ath10k_htt_tx_free(&ar->htt);
1706 ath10k_htt_rx_free(&ar->htt);
1707 ath10k_wmi_detach(ar);
1709 EXPORT_SYMBOL(ath10k_core_stop);
1711 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1712 * order to know what hw capabilities should be advertised to mac80211 it is
1713 * necessary to load the firmware (and tear it down immediately since start
1714 * hook will try to init it again) before registering */
1715 static int ath10k_core_probe_fw(struct ath10k *ar)
1717 struct bmi_target_info target_info;
1720 ret = ath10k_hif_power_up(ar);
1722 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1726 memset(&target_info, 0, sizeof(target_info));
1727 ret = ath10k_bmi_get_target_info(ar, &target_info);
1729 ath10k_err(ar, "could not get target info (%d)\n", ret);
1730 goto err_power_down;
1733 ar->target_version = target_info.version;
1734 ar->hw->wiphy->hw_version = target_info.version;
1736 ret = ath10k_init_hw_params(ar);
1738 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1739 goto err_power_down;
1742 ret = ath10k_core_fetch_firmware_files(ar);
1744 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1745 goto err_power_down;
1748 ret = ath10k_core_get_board_id_from_otp(ar);
1749 if (ret && ret != -EOPNOTSUPP) {
1750 ath10k_err(ar, "failed to get board id from otp for qca99x0: %d\n",
1755 ret = ath10k_core_fetch_board_file(ar);
1757 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
1758 goto err_free_firmware_files;
1761 ret = ath10k_core_init_firmware_features(ar);
1763 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1765 goto err_free_firmware_files;
1768 ret = ath10k_swap_code_seg_init(ar);
1770 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
1772 goto err_free_firmware_files;
1775 mutex_lock(&ar->conf_mutex);
1777 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1779 ath10k_err(ar, "could not init core (%d)\n", ret);
1783 ath10k_print_driver_info(ar);
1784 ath10k_core_stop(ar);
1786 mutex_unlock(&ar->conf_mutex);
1788 ath10k_hif_power_down(ar);
1792 mutex_unlock(&ar->conf_mutex);
1794 err_free_firmware_files:
1795 ath10k_core_free_firmware_files(ar);
1798 ath10k_hif_power_down(ar);
1803 static void ath10k_core_register_work(struct work_struct *work)
1805 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1808 status = ath10k_core_probe_fw(ar);
1810 ath10k_err(ar, "could not probe fw (%d)\n", status);
1814 status = ath10k_mac_register(ar);
1816 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1817 goto err_release_fw;
1820 status = ath10k_debug_register(ar);
1822 ath10k_err(ar, "unable to initialize debugfs\n");
1823 goto err_unregister_mac;
1826 status = ath10k_spectral_create(ar);
1828 ath10k_err(ar, "failed to initialize spectral\n");
1829 goto err_debug_destroy;
1832 status = ath10k_thermal_register(ar);
1834 ath10k_err(ar, "could not register thermal device: %d\n",
1836 goto err_spectral_destroy;
1839 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1842 err_spectral_destroy:
1843 ath10k_spectral_destroy(ar);
1845 ath10k_debug_destroy(ar);
1847 ath10k_mac_unregister(ar);
1849 ath10k_core_free_firmware_files(ar);
1851 /* TODO: It's probably a good idea to release device from the driver
1852 * but calling device_release_driver() here will cause a deadlock.
1857 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1859 ar->chip_id = chip_id;
1860 queue_work(ar->workqueue, &ar->register_work);
1864 EXPORT_SYMBOL(ath10k_core_register);
1866 void ath10k_core_unregister(struct ath10k *ar)
1868 cancel_work_sync(&ar->register_work);
1870 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1873 ath10k_thermal_unregister(ar);
1874 /* Stop spectral before unregistering from mac80211 to remove the
1875 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1876 * would be already be free'd recursively, leading to a double free.
1878 ath10k_spectral_destroy(ar);
1880 /* We must unregister from mac80211 before we stop HTC and HIF.
1881 * Otherwise we will fail to submit commands to FW and mac80211 will be
1882 * unhappy about callback failures. */
1883 ath10k_mac_unregister(ar);
1885 ath10k_testmode_destroy(ar);
1887 ath10k_core_free_firmware_files(ar);
1888 ath10k_core_free_board_files(ar);
1890 ath10k_debug_unregister(ar);
1892 EXPORT_SYMBOL(ath10k_core_unregister);
1894 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1895 enum ath10k_bus bus,
1896 enum ath10k_hw_rev hw_rev,
1897 const struct ath10k_hif_ops *hif_ops)
1902 ar = ath10k_mac_create(priv_size);
1906 ar->ath_common.priv = ar;
1907 ar->ath_common.hw = ar->hw;
1909 ar->hw_rev = hw_rev;
1910 ar->hif.ops = hif_ops;
1914 case ATH10K_HW_QCA988X:
1915 ar->regs = &qca988x_regs;
1916 ar->hw_values = &qca988x_values;
1918 case ATH10K_HW_QCA6174:
1919 case ATH10K_HW_QCA9377:
1920 ar->regs = &qca6174_regs;
1921 ar->hw_values = &qca6174_values;
1923 case ATH10K_HW_QCA99X0:
1924 ar->regs = &qca99x0_regs;
1925 ar->hw_values = &qca99x0_values;
1928 ath10k_err(ar, "unsupported core hardware revision %d\n",
1934 init_completion(&ar->scan.started);
1935 init_completion(&ar->scan.completed);
1936 init_completion(&ar->scan.on_channel);
1937 init_completion(&ar->target_suspend);
1938 init_completion(&ar->wow.wakeup_completed);
1940 init_completion(&ar->install_key_done);
1941 init_completion(&ar->vdev_setup_done);
1942 init_completion(&ar->thermal.wmi_sync);
1944 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1946 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1950 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
1951 if (!ar->workqueue_aux)
1954 mutex_init(&ar->conf_mutex);
1955 spin_lock_init(&ar->data_lock);
1957 INIT_LIST_HEAD(&ar->peers);
1958 init_waitqueue_head(&ar->peer_mapping_wq);
1959 init_waitqueue_head(&ar->htt.empty_tx_wq);
1960 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1962 init_completion(&ar->offchan_tx_completed);
1963 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1964 skb_queue_head_init(&ar->offchan_tx_queue);
1966 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1967 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1969 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1970 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1972 ret = ath10k_debug_create(ar);
1974 goto err_free_aux_wq;
1979 destroy_workqueue(ar->workqueue_aux);
1981 destroy_workqueue(ar->workqueue);
1984 ath10k_mac_destroy(ar);
1988 EXPORT_SYMBOL(ath10k_core_create);
1990 void ath10k_core_destroy(struct ath10k *ar)
1992 flush_workqueue(ar->workqueue);
1993 destroy_workqueue(ar->workqueue);
1995 flush_workqueue(ar->workqueue_aux);
1996 destroy_workqueue(ar->workqueue_aux);
1998 ath10k_debug_destroy(ar);
1999 ath10k_wmi_free_host_mem(ar);
2000 ath10k_mac_destroy(ar);
2002 EXPORT_SYMBOL(ath10k_core_destroy);
2004 MODULE_AUTHOR("Qualcomm Atheros");
2005 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
2006 MODULE_LICENSE("Dual BSD/GPL");