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 .dev_id = QCA988X_2_0_DEVICE_ID,
55 .name = "qca988x hw2.0",
56 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
58 .has_shifted_cc_wraparound = true,
60 .channel_counters_freq_hz = 88000,
61 .max_probe_resp_desc_thres = 0,
63 .dir = QCA988X_HW_2_0_FW_DIR,
64 .fw = QCA988X_HW_2_0_FW_FILE,
65 .otp = QCA988X_HW_2_0_OTP_FILE,
66 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
67 .board_size = QCA988X_BOARD_DATA_SZ,
68 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
72 .id = QCA6174_HW_2_1_VERSION,
73 .dev_id = QCA6164_2_1_DEVICE_ID,
74 .name = "qca6164 hw2.1",
75 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
78 .channel_counters_freq_hz = 88000,
79 .max_probe_resp_desc_thres = 0,
81 .dir = QCA6174_HW_2_1_FW_DIR,
82 .fw = QCA6174_HW_2_1_FW_FILE,
83 .otp = QCA6174_HW_2_1_OTP_FILE,
84 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
85 .board_size = QCA6174_BOARD_DATA_SZ,
86 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
90 .id = QCA6174_HW_2_1_VERSION,
91 .dev_id = QCA6174_2_1_DEVICE_ID,
92 .name = "qca6174 hw2.1",
93 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
96 .channel_counters_freq_hz = 88000,
97 .max_probe_resp_desc_thres = 0,
99 .dir = QCA6174_HW_2_1_FW_DIR,
100 .fw = QCA6174_HW_2_1_FW_FILE,
101 .otp = QCA6174_HW_2_1_OTP_FILE,
102 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
103 .board_size = QCA6174_BOARD_DATA_SZ,
104 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
108 .id = QCA6174_HW_3_0_VERSION,
109 .dev_id = QCA6174_2_1_DEVICE_ID,
110 .name = "qca6174 hw3.0",
111 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
114 .channel_counters_freq_hz = 88000,
115 .max_probe_resp_desc_thres = 0,
117 .dir = QCA6174_HW_3_0_FW_DIR,
118 .fw = QCA6174_HW_3_0_FW_FILE,
119 .otp = QCA6174_HW_3_0_OTP_FILE,
120 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
121 .board_size = QCA6174_BOARD_DATA_SZ,
122 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
126 .id = QCA6174_HW_3_2_VERSION,
127 .dev_id = QCA6174_2_1_DEVICE_ID,
128 .name = "qca6174 hw3.2",
129 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
132 .channel_counters_freq_hz = 88000,
133 .max_probe_resp_desc_thres = 0,
135 /* uses same binaries as hw3.0 */
136 .dir = QCA6174_HW_3_0_FW_DIR,
137 .fw = QCA6174_HW_3_0_FW_FILE,
138 .otp = QCA6174_HW_3_0_OTP_FILE,
139 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
140 .board_size = QCA6174_BOARD_DATA_SZ,
141 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
145 .id = QCA99X0_HW_2_0_DEV_VERSION,
146 .dev_id = QCA99X0_2_0_DEVICE_ID,
147 .name = "qca99x0 hw2.0",
148 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
150 .otp_exe_param = 0x00000700,
151 .continuous_frag_desc = true,
152 .channel_counters_freq_hz = 150000,
153 .max_probe_resp_desc_thres = 24,
155 .dir = QCA99X0_HW_2_0_FW_DIR,
156 .fw = QCA99X0_HW_2_0_FW_FILE,
157 .otp = QCA99X0_HW_2_0_OTP_FILE,
158 .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
159 .board_size = QCA99X0_BOARD_DATA_SZ,
160 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
164 .id = QCA9377_HW_1_0_DEV_VERSION,
165 .dev_id = QCA9377_1_0_DEVICE_ID,
166 .name = "qca9377 hw1.0",
167 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
170 .channel_counters_freq_hz = 88000,
171 .max_probe_resp_desc_thres = 0,
173 .dir = QCA9377_HW_1_0_FW_DIR,
174 .fw = QCA9377_HW_1_0_FW_FILE,
175 .otp = QCA9377_HW_1_0_OTP_FILE,
176 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
177 .board_size = QCA9377_BOARD_DATA_SZ,
178 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
182 .id = QCA9377_HW_1_1_DEV_VERSION,
183 .dev_id = QCA9377_1_0_DEVICE_ID,
184 .name = "qca9377 hw1.1",
185 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
188 .channel_counters_freq_hz = 88000,
189 .max_probe_resp_desc_thres = 0,
191 .dir = QCA9377_HW_1_0_FW_DIR,
192 .fw = QCA9377_HW_1_0_FW_FILE,
193 .otp = QCA9377_HW_1_0_OTP_FILE,
194 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
195 .board_size = QCA9377_BOARD_DATA_SZ,
196 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
201 static const char *const ath10k_core_fw_feature_str[] = {
202 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
203 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
204 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
205 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
206 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
207 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
208 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
209 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
210 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
211 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
212 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
213 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA] = "adaptive-cca",
216 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
218 enum ath10k_fw_features feat)
220 /* make sure that ath10k_core_fw_feature_str[] gets updated */
221 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
222 ATH10K_FW_FEATURE_COUNT);
224 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
225 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
226 return scnprintf(buf, buf_len, "bit%d", feat);
229 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
232 void ath10k_core_get_fw_features_str(struct ath10k *ar,
236 unsigned int len = 0;
239 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
240 if (test_bit(i, ar->fw_features)) {
242 len += scnprintf(buf + len, buf_len - len, ",");
244 len += ath10k_core_get_fw_feature_str(buf + len,
251 static void ath10k_send_suspend_complete(struct ath10k *ar)
253 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
255 complete(&ar->target_suspend);
258 static int ath10k_init_configure_target(struct ath10k *ar)
263 /* tell target which HTC version it is used*/
264 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
265 HTC_PROTOCOL_VERSION);
267 ath10k_err(ar, "settings HTC version failed\n");
271 /* set the firmware mode to STA/IBSS/AP */
272 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
274 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
278 /* TODO following parameters need to be re-visited. */
280 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
282 /* FIXME: Why FW_MODE_AP ??.*/
283 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
284 /* mac_addr_method */
285 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
286 /* firmware_bridge */
287 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
289 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
291 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
293 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
297 /* We do all byte-swapping on the host */
298 ret = ath10k_bmi_write32(ar, hi_be, 0);
300 ath10k_err(ar, "setting host CPU BE mode failed\n");
304 /* FW descriptor/Data swap flags */
305 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
308 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
312 /* Some devices have a special sanity check that verifies the PCI
313 * Device ID is written to this host interest var. It is known to be
314 * required to boot QCA6164.
316 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
319 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
326 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
331 const struct firmware *fw;
335 return ERR_PTR(-ENOENT);
340 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
341 ret = request_firmware(&fw, filename, ar->dev);
348 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
351 u32 board_data_size = ar->hw_params.fw.board_size;
352 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
353 u32 board_ext_data_addr;
356 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
358 ath10k_err(ar, "could not read board ext data addr (%d)\n",
363 ath10k_dbg(ar, ATH10K_DBG_BOOT,
364 "boot push board extended data addr 0x%x\n",
365 board_ext_data_addr);
367 if (board_ext_data_addr == 0)
370 if (data_len != (board_data_size + board_ext_data_size)) {
371 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
372 data_len, board_data_size, board_ext_data_size);
376 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
377 data + board_data_size,
378 board_ext_data_size);
380 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
384 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
385 (board_ext_data_size << 16) | 1);
387 ath10k_err(ar, "could not write board ext data bit (%d)\n",
395 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
398 u32 board_data_size = ar->hw_params.fw.board_size;
402 ret = ath10k_push_board_ext_data(ar, data, data_len);
404 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
408 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
410 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
414 ret = ath10k_bmi_write_memory(ar, address, data,
415 min_t(u32, board_data_size,
418 ath10k_err(ar, "could not write board data (%d)\n", ret);
422 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
424 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
432 static int ath10k_download_cal_file(struct ath10k *ar)
439 if (IS_ERR(ar->cal_file))
440 return PTR_ERR(ar->cal_file);
442 ret = ath10k_download_board_data(ar, ar->cal_file->data,
445 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
449 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
454 static int ath10k_download_cal_dt(struct ath10k *ar)
456 struct device_node *node;
461 node = ar->dev->of_node;
463 /* Device Tree is optional, don't print any warnings if
464 * there's no node for ath10k.
468 if (!of_get_property(node, "qcom,ath10k-calibration-data",
470 /* The calibration data node is optional */
474 if (data_len != QCA988X_CAL_DATA_LEN) {
475 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
481 data = kmalloc(data_len, GFP_KERNEL);
487 ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
490 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
495 ret = ath10k_download_board_data(ar, data, data_len);
497 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
511 static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
514 u8 board_id, chip_id;
517 address = ar->hw_params.patch_load_addr;
519 if (!ar->otp_data || !ar->otp_len) {
521 "failed to retrieve board id because of invalid otp\n");
525 ath10k_dbg(ar, ATH10K_DBG_BOOT,
526 "boot upload otp to 0x%x len %zd for board id\n",
527 address, ar->otp_len);
529 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
531 ath10k_err(ar, "could not write otp for board id check: %d\n",
536 ret = ath10k_bmi_execute(ar, address, BMI_PARAM_GET_EEPROM_BOARD_ID,
539 ath10k_err(ar, "could not execute otp for board id check: %d\n",
544 board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP);
545 chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP);
547 ath10k_dbg(ar, ATH10K_DBG_BOOT,
548 "boot get otp board id result 0x%08x board_id %d chip_id %d\n",
549 result, board_id, chip_id);
551 if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0)
554 ar->id.bmi_ids_valid = true;
555 ar->id.bmi_board_id = board_id;
556 ar->id.bmi_chip_id = chip_id;
561 static int ath10k_download_and_run_otp(struct ath10k *ar)
563 u32 result, address = ar->hw_params.patch_load_addr;
564 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
567 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
569 ath10k_err(ar, "failed to download board data: %d\n", ret);
573 /* OTP is optional */
575 if (!ar->otp_data || !ar->otp_len) {
576 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
577 ar->otp_data, ar->otp_len);
581 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
582 address, ar->otp_len);
584 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
586 ath10k_err(ar, "could not write otp (%d)\n", ret);
590 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
592 ath10k_err(ar, "could not execute otp (%d)\n", ret);
596 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
598 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
601 ath10k_err(ar, "otp calibration failed: %d", result);
608 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
610 u32 address, data_len;
611 const char *mode_name;
615 address = ar->hw_params.patch_load_addr;
618 case ATH10K_FIRMWARE_MODE_NORMAL:
619 data = ar->firmware_data;
620 data_len = ar->firmware_len;
621 mode_name = "normal";
622 ret = ath10k_swap_code_seg_configure(ar,
623 ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW);
625 ath10k_err(ar, "failed to configure fw code swap: %d\n",
630 case ATH10K_FIRMWARE_MODE_UTF:
631 data = ar->testmode.utf_firmware_data;
632 data_len = ar->testmode.utf_firmware_len;
636 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
640 ath10k_dbg(ar, ATH10K_DBG_BOOT,
641 "boot uploading firmware image %p len %d mode %s\n",
642 data, data_len, mode_name);
644 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
646 ath10k_err(ar, "failed to download %s firmware: %d\n",
654 static void ath10k_core_free_board_files(struct ath10k *ar)
656 if (!IS_ERR(ar->board))
657 release_firmware(ar->board);
660 ar->board_data = NULL;
664 static void ath10k_core_free_firmware_files(struct ath10k *ar)
666 if (!IS_ERR(ar->otp))
667 release_firmware(ar->otp);
669 if (!IS_ERR(ar->firmware))
670 release_firmware(ar->firmware);
672 if (!IS_ERR(ar->cal_file))
673 release_firmware(ar->cal_file);
675 ath10k_swap_code_seg_release(ar);
682 ar->firmware_data = NULL;
683 ar->firmware_len = 0;
688 static int ath10k_fetch_cal_file(struct ath10k *ar)
692 /* cal-<bus>-<id>.bin */
693 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
694 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
696 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
697 if (IS_ERR(ar->cal_file))
698 /* calibration file is optional, don't print any warnings */
699 return PTR_ERR(ar->cal_file);
701 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
702 ATH10K_FW_DIR, filename);
707 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar)
709 if (!ar->hw_params.fw.board) {
710 ath10k_err(ar, "failed to find board file fw entry\n");
714 ar->board = ath10k_fetch_fw_file(ar,
715 ar->hw_params.fw.dir,
716 ar->hw_params.fw.board);
717 if (IS_ERR(ar->board))
718 return PTR_ERR(ar->board);
720 ar->board_data = ar->board->data;
721 ar->board_len = ar->board->size;
726 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
727 const void *buf, size_t buf_len,
728 const char *boardname)
730 const struct ath10k_fw_ie *hdr;
731 bool name_match_found;
732 int ret, board_ie_id;
734 const void *board_ie_data;
736 name_match_found = false;
738 /* go through ATH10K_BD_IE_BOARD_ elements */
739 while (buf_len > sizeof(struct ath10k_fw_ie)) {
741 board_ie_id = le32_to_cpu(hdr->id);
742 board_ie_len = le32_to_cpu(hdr->len);
743 board_ie_data = hdr->data;
745 buf_len -= sizeof(*hdr);
748 if (buf_len < ALIGN(board_ie_len, 4)) {
749 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
750 buf_len, ALIGN(board_ie_len, 4));
755 switch (board_ie_id) {
756 case ATH10K_BD_IE_BOARD_NAME:
757 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
758 board_ie_data, board_ie_len);
760 if (board_ie_len != strlen(boardname))
763 ret = memcmp(board_ie_data, boardname, strlen(boardname));
767 name_match_found = true;
768 ath10k_dbg(ar, ATH10K_DBG_BOOT,
769 "boot found match for name '%s'",
772 case ATH10K_BD_IE_BOARD_DATA:
773 if (!name_match_found)
777 ath10k_dbg(ar, ATH10K_DBG_BOOT,
778 "boot found board data for '%s'",
781 ar->board_data = board_ie_data;
782 ar->board_len = board_ie_len;
787 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
792 /* jump over the padding */
793 board_ie_len = ALIGN(board_ie_len, 4);
795 buf_len -= board_ie_len;
806 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
807 const char *boardname,
808 const char *filename)
810 size_t len, magic_len, ie_len;
811 struct ath10k_fw_ie *hdr;
815 ar->board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, filename);
816 if (IS_ERR(ar->board))
817 return PTR_ERR(ar->board);
819 data = ar->board->data;
820 len = ar->board->size;
822 /* magic has extra null byte padded */
823 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
824 if (len < magic_len) {
825 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
826 ar->hw_params.fw.dir, filename, len);
831 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
832 ath10k_err(ar, "found invalid board magic\n");
837 /* magic is padded to 4 bytes */
838 magic_len = ALIGN(magic_len, 4);
839 if (len < magic_len) {
840 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
841 ar->hw_params.fw.dir, filename, len);
849 while (len > sizeof(struct ath10k_fw_ie)) {
850 hdr = (struct ath10k_fw_ie *)data;
851 ie_id = le32_to_cpu(hdr->id);
852 ie_len = le32_to_cpu(hdr->len);
857 if (len < ALIGN(ie_len, 4)) {
858 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
865 case ATH10K_BD_IE_BOARD:
866 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
869 /* no match found, continue */
872 /* there was an error, bail out */
875 /* board data found */
879 /* jump over the padding */
880 ie_len = ALIGN(ie_len, 4);
887 if (!ar->board_data || !ar->board_len) {
889 "failed to fetch board data for %s from %s/%s\n",
890 ar->hw_params.fw.dir, boardname, filename);
898 ath10k_core_free_board_files(ar);
902 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
905 if (ar->id.bmi_ids_valid) {
906 scnprintf(name, name_len,
907 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d",
908 ath10k_bus_str(ar->hif.bus),
910 ar->id.bmi_board_id);
914 scnprintf(name, name_len,
915 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
916 ath10k_bus_str(ar->hif.bus),
917 ar->id.vendor, ar->id.device,
918 ar->id.subsystem_vendor, ar->id.subsystem_device);
921 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
926 static int ath10k_core_fetch_board_file(struct ath10k *ar)
931 ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
933 ath10k_err(ar, "failed to create board name: %d", ret);
938 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
939 ATH10K_BOARD_API2_FILE);
944 ret = ath10k_core_fetch_board_data_api_1(ar);
946 ath10k_err(ar, "failed to fetch board data\n");
951 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
955 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
959 if (ar->hw_params.fw.fw == NULL) {
960 ath10k_err(ar, "firmware file not defined\n");
964 ar->firmware = ath10k_fetch_fw_file(ar,
965 ar->hw_params.fw.dir,
966 ar->hw_params.fw.fw);
967 if (IS_ERR(ar->firmware)) {
968 ret = PTR_ERR(ar->firmware);
969 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
973 ar->firmware_data = ar->firmware->data;
974 ar->firmware_len = ar->firmware->size;
976 /* OTP may be undefined. If so, don't fetch it at all */
977 if (ar->hw_params.fw.otp == NULL)
980 ar->otp = ath10k_fetch_fw_file(ar,
981 ar->hw_params.fw.dir,
982 ar->hw_params.fw.otp);
983 if (IS_ERR(ar->otp)) {
984 ret = PTR_ERR(ar->otp);
985 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
989 ar->otp_data = ar->otp->data;
990 ar->otp_len = ar->otp->size;
995 ath10k_core_free_firmware_files(ar);
999 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
1001 size_t magic_len, len, ie_len;
1002 int ie_id, i, index, bit, ret;
1003 struct ath10k_fw_ie *hdr;
1005 __le32 *timestamp, *version;
1007 /* first fetch the firmware file (firmware-*.bin) */
1008 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
1009 if (IS_ERR(ar->firmware)) {
1010 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
1011 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
1012 return PTR_ERR(ar->firmware);
1015 data = ar->firmware->data;
1016 len = ar->firmware->size;
1018 /* magic also includes the null byte, check that as well */
1019 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
1021 if (len < magic_len) {
1022 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
1023 ar->hw_params.fw.dir, name, len);
1028 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
1029 ath10k_err(ar, "invalid firmware magic\n");
1034 /* jump over the padding */
1035 magic_len = ALIGN(magic_len, 4);
1041 while (len > sizeof(struct ath10k_fw_ie)) {
1042 hdr = (struct ath10k_fw_ie *)data;
1044 ie_id = le32_to_cpu(hdr->id);
1045 ie_len = le32_to_cpu(hdr->len);
1047 len -= sizeof(*hdr);
1048 data += sizeof(*hdr);
1051 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
1052 ie_id, len, ie_len);
1058 case ATH10K_FW_IE_FW_VERSION:
1059 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
1062 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
1063 ar->hw->wiphy->fw_version[ie_len] = '\0';
1065 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1066 "found fw version %s\n",
1067 ar->hw->wiphy->fw_version);
1069 case ATH10K_FW_IE_TIMESTAMP:
1070 if (ie_len != sizeof(u32))
1073 timestamp = (__le32 *)data;
1075 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
1076 le32_to_cpup(timestamp));
1078 case ATH10K_FW_IE_FEATURES:
1079 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1080 "found firmware features ie (%zd B)\n",
1083 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
1087 if (index == ie_len)
1090 if (data[index] & (1 << bit)) {
1091 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1092 "Enabling feature bit: %i\n",
1094 __set_bit(i, ar->fw_features);
1098 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
1100 sizeof(ar->fw_features));
1102 case ATH10K_FW_IE_FW_IMAGE:
1103 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1104 "found fw image ie (%zd B)\n",
1107 ar->firmware_data = data;
1108 ar->firmware_len = ie_len;
1111 case ATH10K_FW_IE_OTP_IMAGE:
1112 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1113 "found otp image ie (%zd B)\n",
1116 ar->otp_data = data;
1117 ar->otp_len = ie_len;
1120 case ATH10K_FW_IE_WMI_OP_VERSION:
1121 if (ie_len != sizeof(u32))
1124 version = (__le32 *)data;
1126 ar->wmi.op_version = le32_to_cpup(version);
1128 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1129 ar->wmi.op_version);
1131 case ATH10K_FW_IE_HTT_OP_VERSION:
1132 if (ie_len != sizeof(u32))
1135 version = (__le32 *)data;
1137 ar->htt.op_version = le32_to_cpup(version);
1139 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1140 ar->htt.op_version);
1142 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1143 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1144 "found fw code swap image ie (%zd B)\n",
1146 ar->swap.firmware_codeswap_data = data;
1147 ar->swap.firmware_codeswap_len = ie_len;
1150 ath10k_warn(ar, "Unknown FW IE: %u\n",
1151 le32_to_cpu(hdr->id));
1155 /* jump over the padding */
1156 ie_len = ALIGN(ie_len, 4);
1162 if (!ar->firmware_data || !ar->firmware_len) {
1163 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1164 ar->hw_params.fw.dir, name);
1172 ath10k_core_free_firmware_files(ar);
1176 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1180 /* calibration file is optional, don't check for any errors */
1181 ath10k_fetch_cal_file(ar);
1184 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1186 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE);
1191 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1193 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE);
1198 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1200 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
1205 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1207 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
1212 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1214 ret = ath10k_core_fetch_firmware_api_1(ar);
1219 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1224 static int ath10k_download_cal_data(struct ath10k *ar)
1228 ret = ath10k_download_cal_file(ar);
1230 ar->cal_mode = ATH10K_CAL_MODE_FILE;
1234 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1235 "boot did not find a calibration file, try DT next: %d\n",
1238 ret = ath10k_download_cal_dt(ar);
1240 ar->cal_mode = ATH10K_CAL_MODE_DT;
1244 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1245 "boot did not find DT entry, try OTP next: %d\n",
1248 ret = ath10k_download_and_run_otp(ar);
1250 ath10k_err(ar, "failed to run otp: %d\n", ret);
1254 ar->cal_mode = ATH10K_CAL_MODE_OTP;
1257 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1258 ath10k_cal_mode_str(ar->cal_mode));
1262 static int ath10k_init_uart(struct ath10k *ar)
1267 * Explicitly setting UART prints to zero as target turns it on
1268 * based on scratch registers.
1270 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
1272 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
1279 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
1281 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1285 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
1287 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1291 /* Set the UART baud rate to 19200. */
1292 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1294 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1298 ath10k_info(ar, "UART prints enabled\n");
1302 static int ath10k_init_hw_params(struct ath10k *ar)
1304 const struct ath10k_hw_params *uninitialized_var(hw_params);
1307 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1308 hw_params = &ath10k_hw_params_list[i];
1310 if (hw_params->id == ar->target_version &&
1311 hw_params->dev_id == ar->dev_id)
1315 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1316 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1317 ar->target_version);
1321 ar->hw_params = *hw_params;
1323 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1324 ar->hw_params.name, ar->target_version);
1329 static void ath10k_core_restart(struct work_struct *work)
1331 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1333 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1335 /* Place a barrier to make sure the compiler doesn't reorder
1336 * CRASH_FLUSH and calling other functions.
1340 ieee80211_stop_queues(ar->hw);
1341 ath10k_drain_tx(ar);
1342 complete_all(&ar->scan.started);
1343 complete_all(&ar->scan.completed);
1344 complete_all(&ar->scan.on_channel);
1345 complete_all(&ar->offchan_tx_completed);
1346 complete_all(&ar->install_key_done);
1347 complete_all(&ar->vdev_setup_done);
1348 complete_all(&ar->thermal.wmi_sync);
1349 wake_up(&ar->htt.empty_tx_wq);
1350 wake_up(&ar->wmi.tx_credits_wq);
1351 wake_up(&ar->peer_mapping_wq);
1353 mutex_lock(&ar->conf_mutex);
1355 switch (ar->state) {
1356 case ATH10K_STATE_ON:
1357 ar->state = ATH10K_STATE_RESTARTING;
1358 ath10k_hif_stop(ar);
1359 ath10k_scan_finish(ar);
1360 ieee80211_restart_hw(ar->hw);
1362 case ATH10K_STATE_OFF:
1363 /* this can happen if driver is being unloaded
1364 * or if the crash happens during FW probing */
1365 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1367 case ATH10K_STATE_RESTARTING:
1368 /* hw restart might be requested from multiple places */
1370 case ATH10K_STATE_RESTARTED:
1371 ar->state = ATH10K_STATE_WEDGED;
1373 case ATH10K_STATE_WEDGED:
1374 ath10k_warn(ar, "device is wedged, will not restart\n");
1376 case ATH10K_STATE_UTF:
1377 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1381 mutex_unlock(&ar->conf_mutex);
1384 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1386 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
1387 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1388 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1392 if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1393 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1394 ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version);
1398 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1399 switch (ath10k_cryptmode_param) {
1400 case ATH10K_CRYPT_MODE_HW:
1401 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1402 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1404 case ATH10K_CRYPT_MODE_SW:
1405 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1407 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1411 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1412 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1415 ath10k_info(ar, "invalid cryptmode: %d\n",
1416 ath10k_cryptmode_param);
1420 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1421 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1424 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1426 ath10k_err(ar, "rawmode = 1 requires support from firmware");
1429 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1432 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1433 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1437 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1438 * and causes enormous performance issues (malformed frames,
1441 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1442 * albeit a bit slower compared to regular operation.
1444 ar->htt.max_num_amsdu = 1;
1447 /* Backwards compatibility for firmwares without
1448 * ATH10K_FW_IE_WMI_OP_VERSION.
1450 if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1451 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1452 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1454 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1456 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1458 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1462 switch (ar->wmi.op_version) {
1463 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1464 ar->max_num_peers = TARGET_NUM_PEERS;
1465 ar->max_num_stations = TARGET_NUM_STATIONS;
1466 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1467 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1468 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1470 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
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->max_num_peers = TARGET_10X_NUM_PEERS;
1476 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1477 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1478 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1479 ar->fw_stats_req_mask = WMI_STAT_PEER;
1480 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1482 case ATH10K_FW_WMI_OP_VERSION_TLV:
1483 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1484 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1485 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1486 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1487 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1488 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1489 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1491 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1493 case ATH10K_FW_WMI_OP_VERSION_10_4:
1494 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1495 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1496 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1497 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1498 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1499 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1500 ar->fw_stats_req_mask = WMI_STAT_PEER;
1501 ar->max_spatial_stream = WMI_10_4_MAX_SPATIAL_STREAM;
1503 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1504 case ATH10K_FW_WMI_OP_VERSION_MAX:
1509 /* Backwards compatibility for firmwares without
1510 * ATH10K_FW_IE_HTT_OP_VERSION.
1512 if (ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1513 switch (ar->wmi.op_version) {
1514 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1515 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1517 case ATH10K_FW_WMI_OP_VERSION_10_1:
1518 case ATH10K_FW_WMI_OP_VERSION_10_2:
1519 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1520 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1522 case ATH10K_FW_WMI_OP_VERSION_TLV:
1523 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1525 case ATH10K_FW_WMI_OP_VERSION_10_4:
1526 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1527 case ATH10K_FW_WMI_OP_VERSION_MAX:
1536 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
1540 lockdep_assert_held(&ar->conf_mutex);
1542 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1544 ath10k_bmi_start(ar);
1546 if (ath10k_init_configure_target(ar)) {
1551 status = ath10k_download_cal_data(ar);
1555 /* Some of of qca988x solutions are having global reset issue
1556 * during target initialization. Bypassing PLL setting before
1557 * downloading firmware and letting the SoC run on REF_CLK is
1558 * fixing the problem. Corresponding firmware change is also needed
1559 * to set the clock source once the target is initialized.
1561 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1563 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1565 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
1571 status = ath10k_download_fw(ar, mode);
1575 status = ath10k_init_uart(ar);
1579 ar->htc.htc_ops.target_send_suspend_complete =
1580 ath10k_send_suspend_complete;
1582 status = ath10k_htc_init(ar);
1584 ath10k_err(ar, "could not init HTC (%d)\n", status);
1588 status = ath10k_bmi_done(ar);
1592 status = ath10k_wmi_attach(ar);
1594 ath10k_err(ar, "WMI attach failed: %d\n", status);
1598 status = ath10k_htt_init(ar);
1600 ath10k_err(ar, "failed to init htt: %d\n", status);
1601 goto err_wmi_detach;
1604 status = ath10k_htt_tx_alloc(&ar->htt);
1606 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1607 goto err_wmi_detach;
1610 status = ath10k_htt_rx_alloc(&ar->htt);
1612 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1613 goto err_htt_tx_detach;
1616 status = ath10k_hif_start(ar);
1618 ath10k_err(ar, "could not start HIF: %d\n", status);
1619 goto err_htt_rx_detach;
1622 status = ath10k_htc_wait_target(&ar->htc);
1624 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1628 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1629 status = ath10k_htt_connect(&ar->htt);
1631 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1636 status = ath10k_wmi_connect(ar);
1638 ath10k_err(ar, "could not connect wmi: %d\n", status);
1642 status = ath10k_htc_start(&ar->htc);
1644 ath10k_err(ar, "failed to start htc: %d\n", status);
1648 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1649 status = ath10k_wmi_wait_for_service_ready(ar);
1651 ath10k_warn(ar, "wmi service ready event not received");
1656 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1657 ar->hw->wiphy->fw_version);
1659 status = ath10k_wmi_cmd_init(ar);
1661 ath10k_err(ar, "could not send WMI init command (%d)\n",
1666 status = ath10k_wmi_wait_for_unified_ready(ar);
1668 ath10k_err(ar, "wmi unified ready event not received\n");
1672 /* If firmware indicates Full Rx Reorder support it must be used in a
1673 * slightly different manner. Let HTT code know.
1675 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1678 status = ath10k_htt_rx_ring_refill(ar);
1680 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1684 /* we don't care about HTT in UTF mode */
1685 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1686 status = ath10k_htt_setup(&ar->htt);
1688 ath10k_err(ar, "failed to setup htt: %d\n", status);
1693 status = ath10k_debug_start(ar);
1697 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1699 INIT_LIST_HEAD(&ar->arvifs);
1704 ath10k_hif_stop(ar);
1706 ath10k_htt_rx_free(&ar->htt);
1708 ath10k_htt_tx_free(&ar->htt);
1710 ath10k_wmi_detach(ar);
1714 EXPORT_SYMBOL(ath10k_core_start);
1716 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1719 unsigned long time_left;
1721 reinit_completion(&ar->target_suspend);
1723 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1725 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1729 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1732 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1739 void ath10k_core_stop(struct ath10k *ar)
1741 lockdep_assert_held(&ar->conf_mutex);
1742 ath10k_debug_stop(ar);
1744 /* try to suspend target */
1745 if (ar->state != ATH10K_STATE_RESTARTING &&
1746 ar->state != ATH10K_STATE_UTF)
1747 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1749 ath10k_hif_stop(ar);
1750 ath10k_htt_tx_free(&ar->htt);
1751 ath10k_htt_rx_free(&ar->htt);
1752 ath10k_wmi_detach(ar);
1754 EXPORT_SYMBOL(ath10k_core_stop);
1756 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1757 * order to know what hw capabilities should be advertised to mac80211 it is
1758 * necessary to load the firmware (and tear it down immediately since start
1759 * hook will try to init it again) before registering */
1760 static int ath10k_core_probe_fw(struct ath10k *ar)
1762 struct bmi_target_info target_info;
1765 ret = ath10k_hif_power_up(ar);
1767 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1771 memset(&target_info, 0, sizeof(target_info));
1772 ret = ath10k_bmi_get_target_info(ar, &target_info);
1774 ath10k_err(ar, "could not get target info (%d)\n", ret);
1775 goto err_power_down;
1778 ar->target_version = target_info.version;
1779 ar->hw->wiphy->hw_version = target_info.version;
1781 ret = ath10k_init_hw_params(ar);
1783 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1784 goto err_power_down;
1787 ret = ath10k_core_fetch_firmware_files(ar);
1789 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1790 goto err_power_down;
1793 ret = ath10k_core_get_board_id_from_otp(ar);
1794 if (ret && ret != -EOPNOTSUPP) {
1795 ath10k_err(ar, "failed to get board id from otp for qca99x0: %d\n",
1800 ret = ath10k_core_fetch_board_file(ar);
1802 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
1803 goto err_free_firmware_files;
1806 ret = ath10k_core_init_firmware_features(ar);
1808 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1810 goto err_free_firmware_files;
1813 ret = ath10k_swap_code_seg_init(ar);
1815 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
1817 goto err_free_firmware_files;
1820 mutex_lock(&ar->conf_mutex);
1822 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1824 ath10k_err(ar, "could not init core (%d)\n", ret);
1828 ath10k_print_driver_info(ar);
1829 ath10k_core_stop(ar);
1831 mutex_unlock(&ar->conf_mutex);
1833 ath10k_hif_power_down(ar);
1837 mutex_unlock(&ar->conf_mutex);
1839 err_free_firmware_files:
1840 ath10k_core_free_firmware_files(ar);
1843 ath10k_hif_power_down(ar);
1848 static void ath10k_core_register_work(struct work_struct *work)
1850 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1853 status = ath10k_core_probe_fw(ar);
1855 ath10k_err(ar, "could not probe fw (%d)\n", status);
1859 status = ath10k_mac_register(ar);
1861 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1862 goto err_release_fw;
1865 status = ath10k_debug_register(ar);
1867 ath10k_err(ar, "unable to initialize debugfs\n");
1868 goto err_unregister_mac;
1871 status = ath10k_spectral_create(ar);
1873 ath10k_err(ar, "failed to initialize spectral\n");
1874 goto err_debug_destroy;
1877 status = ath10k_thermal_register(ar);
1879 ath10k_err(ar, "could not register thermal device: %d\n",
1881 goto err_spectral_destroy;
1884 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1887 err_spectral_destroy:
1888 ath10k_spectral_destroy(ar);
1890 ath10k_debug_destroy(ar);
1892 ath10k_mac_unregister(ar);
1894 ath10k_core_free_firmware_files(ar);
1896 /* TODO: It's probably a good idea to release device from the driver
1897 * but calling device_release_driver() here will cause a deadlock.
1902 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1904 ar->chip_id = chip_id;
1905 queue_work(ar->workqueue, &ar->register_work);
1909 EXPORT_SYMBOL(ath10k_core_register);
1911 void ath10k_core_unregister(struct ath10k *ar)
1913 cancel_work_sync(&ar->register_work);
1915 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1918 ath10k_thermal_unregister(ar);
1919 /* Stop spectral before unregistering from mac80211 to remove the
1920 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1921 * would be already be free'd recursively, leading to a double free.
1923 ath10k_spectral_destroy(ar);
1925 /* We must unregister from mac80211 before we stop HTC and HIF.
1926 * Otherwise we will fail to submit commands to FW and mac80211 will be
1927 * unhappy about callback failures. */
1928 ath10k_mac_unregister(ar);
1930 ath10k_testmode_destroy(ar);
1932 ath10k_core_free_firmware_files(ar);
1933 ath10k_core_free_board_files(ar);
1935 ath10k_debug_unregister(ar);
1937 EXPORT_SYMBOL(ath10k_core_unregister);
1939 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1940 enum ath10k_bus bus,
1941 enum ath10k_hw_rev hw_rev,
1942 const struct ath10k_hif_ops *hif_ops)
1947 ar = ath10k_mac_create(priv_size);
1951 ar->ath_common.priv = ar;
1952 ar->ath_common.hw = ar->hw;
1954 ar->hw_rev = hw_rev;
1955 ar->hif.ops = hif_ops;
1959 case ATH10K_HW_QCA988X:
1960 ar->regs = &qca988x_regs;
1961 ar->hw_values = &qca988x_values;
1963 case ATH10K_HW_QCA6174:
1964 case ATH10K_HW_QCA9377:
1965 ar->regs = &qca6174_regs;
1966 ar->hw_values = &qca6174_values;
1968 case ATH10K_HW_QCA99X0:
1969 ar->regs = &qca99x0_regs;
1970 ar->hw_values = &qca99x0_values;
1973 ath10k_err(ar, "unsupported core hardware revision %d\n",
1979 init_completion(&ar->scan.started);
1980 init_completion(&ar->scan.completed);
1981 init_completion(&ar->scan.on_channel);
1982 init_completion(&ar->target_suspend);
1983 init_completion(&ar->wow.wakeup_completed);
1985 init_completion(&ar->install_key_done);
1986 init_completion(&ar->vdev_setup_done);
1987 init_completion(&ar->thermal.wmi_sync);
1989 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1991 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1995 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
1996 if (!ar->workqueue_aux)
1999 mutex_init(&ar->conf_mutex);
2000 spin_lock_init(&ar->data_lock);
2002 INIT_LIST_HEAD(&ar->peers);
2003 init_waitqueue_head(&ar->peer_mapping_wq);
2004 init_waitqueue_head(&ar->htt.empty_tx_wq);
2005 init_waitqueue_head(&ar->wmi.tx_credits_wq);
2007 init_completion(&ar->offchan_tx_completed);
2008 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
2009 skb_queue_head_init(&ar->offchan_tx_queue);
2011 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
2012 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
2014 INIT_WORK(&ar->register_work, ath10k_core_register_work);
2015 INIT_WORK(&ar->restart_work, ath10k_core_restart);
2017 ret = ath10k_debug_create(ar);
2019 goto err_free_aux_wq;
2024 destroy_workqueue(ar->workqueue_aux);
2026 destroy_workqueue(ar->workqueue);
2029 ath10k_mac_destroy(ar);
2033 EXPORT_SYMBOL(ath10k_core_create);
2035 void ath10k_core_destroy(struct ath10k *ar)
2037 flush_workqueue(ar->workqueue);
2038 destroy_workqueue(ar->workqueue);
2040 flush_workqueue(ar->workqueue_aux);
2041 destroy_workqueue(ar->workqueue_aux);
2043 ath10k_debug_destroy(ar);
2044 ath10k_wmi_free_host_mem(ar);
2045 ath10k_mac_destroy(ar);
2047 EXPORT_SYMBOL(ath10k_core_destroy);
2049 MODULE_AUTHOR("Qualcomm Atheros");
2050 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
2051 MODULE_LICENSE("Dual BSD/GPL");