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,
61 .hw_4addr_pad = ATH10K_HW_4ADDR_PAD_AFTER,
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 .name = "qca6174 hw2.1",
74 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
77 .channel_counters_freq_hz = 88000,
78 .max_probe_resp_desc_thres = 0,
79 .hw_4addr_pad = ATH10K_HW_4ADDR_PAD_AFTER,
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_3_0_VERSION,
91 .name = "qca6174 hw3.0",
92 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
95 .channel_counters_freq_hz = 88000,
96 .max_probe_resp_desc_thres = 0,
97 .hw_4addr_pad = ATH10K_HW_4ADDR_PAD_AFTER,
99 .dir = QCA6174_HW_3_0_FW_DIR,
100 .fw = QCA6174_HW_3_0_FW_FILE,
101 .otp = QCA6174_HW_3_0_OTP_FILE,
102 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
103 .board_size = QCA6174_BOARD_DATA_SZ,
104 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
108 .id = QCA6174_HW_3_2_VERSION,
109 .name = "qca6174 hw3.2",
110 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
113 .channel_counters_freq_hz = 88000,
114 .max_probe_resp_desc_thres = 0,
115 .hw_4addr_pad = ATH10K_HW_4ADDR_PAD_AFTER,
117 /* uses same binaries as hw3.0 */
118 .dir = QCA6174_HW_3_0_FW_DIR,
119 .fw = QCA6174_HW_3_0_FW_FILE,
120 .otp = QCA6174_HW_3_0_OTP_FILE,
121 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
122 .board_size = QCA6174_BOARD_DATA_SZ,
123 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
127 .id = QCA99X0_HW_2_0_DEV_VERSION,
128 .name = "qca99x0 hw2.0",
129 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
131 .otp_exe_param = 0x00000700,
132 .continuous_frag_desc = true,
133 .channel_counters_freq_hz = 150000,
134 .max_probe_resp_desc_thres = 24,
135 .hw_4addr_pad = ATH10K_HW_4ADDR_PAD_BEFORE,
137 .dir = QCA99X0_HW_2_0_FW_DIR,
138 .fw = QCA99X0_HW_2_0_FW_FILE,
139 .otp = QCA99X0_HW_2_0_OTP_FILE,
140 .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
141 .board_size = QCA99X0_BOARD_DATA_SZ,
142 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
146 .id = QCA9377_HW_1_0_DEV_VERSION,
147 .name = "qca9377 hw1.0",
148 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
152 .dir = QCA9377_HW_1_0_FW_DIR,
153 .fw = QCA9377_HW_1_0_FW_FILE,
154 .otp = QCA9377_HW_1_0_OTP_FILE,
155 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
156 .board_size = QCA9377_BOARD_DATA_SZ,
157 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
162 static const char *const ath10k_core_fw_feature_str[] = {
163 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
164 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
165 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
166 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
167 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
168 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
169 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
170 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
171 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
172 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
173 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
174 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA] = "adaptive-cca",
175 [ATH10K_FW_FEATURE_MFP_SUPPORT] = "mfp",
178 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
180 enum ath10k_fw_features feat)
182 /* make sure that ath10k_core_fw_feature_str[] gets updated */
183 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
184 ATH10K_FW_FEATURE_COUNT);
186 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
187 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
188 return scnprintf(buf, buf_len, "bit%d", feat);
191 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
194 void ath10k_core_get_fw_features_str(struct ath10k *ar,
198 unsigned int len = 0;
201 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
202 if (test_bit(i, ar->fw_features)) {
204 len += scnprintf(buf + len, buf_len - len, ",");
206 len += ath10k_core_get_fw_feature_str(buf + len,
213 static void ath10k_send_suspend_complete(struct ath10k *ar)
215 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
217 complete(&ar->target_suspend);
220 static int ath10k_init_configure_target(struct ath10k *ar)
225 /* tell target which HTC version it is used*/
226 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
227 HTC_PROTOCOL_VERSION);
229 ath10k_err(ar, "settings HTC version failed\n");
233 /* set the firmware mode to STA/IBSS/AP */
234 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
236 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
240 /* TODO following parameters need to be re-visited. */
242 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
244 /* FIXME: Why FW_MODE_AP ??.*/
245 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
246 /* mac_addr_method */
247 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
248 /* firmware_bridge */
249 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
251 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
253 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
255 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
259 /* We do all byte-swapping on the host */
260 ret = ath10k_bmi_write32(ar, hi_be, 0);
262 ath10k_err(ar, "setting host CPU BE mode failed\n");
266 /* FW descriptor/Data swap flags */
267 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
270 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
274 /* Some devices have a special sanity check that verifies the PCI
275 * Device ID is written to this host interest var. It is known to be
276 * required to boot QCA6164.
278 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
281 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
288 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
293 const struct firmware *fw;
297 return ERR_PTR(-ENOENT);
302 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
303 ret = request_firmware(&fw, filename, ar->dev);
310 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
313 u32 board_data_size = ar->hw_params.fw.board_size;
314 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
315 u32 board_ext_data_addr;
318 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
320 ath10k_err(ar, "could not read board ext data addr (%d)\n",
325 ath10k_dbg(ar, ATH10K_DBG_BOOT,
326 "boot push board extended data addr 0x%x\n",
327 board_ext_data_addr);
329 if (board_ext_data_addr == 0)
332 if (data_len != (board_data_size + board_ext_data_size)) {
333 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
334 data_len, board_data_size, board_ext_data_size);
338 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
339 data + board_data_size,
340 board_ext_data_size);
342 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
346 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
347 (board_ext_data_size << 16) | 1);
349 ath10k_err(ar, "could not write board ext data bit (%d)\n",
357 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
360 u32 board_data_size = ar->hw_params.fw.board_size;
364 ret = ath10k_push_board_ext_data(ar, data, data_len);
366 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
370 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
372 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
376 ret = ath10k_bmi_write_memory(ar, address, data,
377 min_t(u32, board_data_size,
380 ath10k_err(ar, "could not write board data (%d)\n", ret);
384 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
386 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
394 static int ath10k_download_cal_file(struct ath10k *ar)
401 if (IS_ERR(ar->cal_file))
402 return PTR_ERR(ar->cal_file);
404 ret = ath10k_download_board_data(ar, ar->cal_file->data,
407 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
411 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
416 static int ath10k_download_cal_dt(struct ath10k *ar)
418 struct device_node *node;
423 node = ar->dev->of_node;
425 /* Device Tree is optional, don't print any warnings if
426 * there's no node for ath10k.
430 if (!of_get_property(node, "qcom,ath10k-calibration-data",
432 /* The calibration data node is optional */
436 if (data_len != QCA988X_CAL_DATA_LEN) {
437 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
443 data = kmalloc(data_len, GFP_KERNEL);
449 ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
452 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
457 ret = ath10k_download_board_data(ar, data, data_len);
459 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
473 static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
476 u8 board_id, chip_id;
479 address = ar->hw_params.patch_load_addr;
481 if (!ar->otp_data || !ar->otp_len) {
483 "failed to retrieve board id because of invalid otp\n");
487 ath10k_dbg(ar, ATH10K_DBG_BOOT,
488 "boot upload otp to 0x%x len %zd for board id\n",
489 address, ar->otp_len);
491 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
493 ath10k_err(ar, "could not write otp for board id check: %d\n",
498 ret = ath10k_bmi_execute(ar, address, BMI_PARAM_GET_EEPROM_BOARD_ID,
501 ath10k_err(ar, "could not execute otp for board id check: %d\n",
506 board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP);
507 chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP);
509 ath10k_dbg(ar, ATH10K_DBG_BOOT,
510 "boot get otp board id result 0x%08x board_id %d chip_id %d\n",
511 result, board_id, chip_id);
513 if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0)
516 ar->id.bmi_ids_valid = true;
517 ar->id.bmi_board_id = board_id;
518 ar->id.bmi_chip_id = chip_id;
523 static int ath10k_download_and_run_otp(struct ath10k *ar)
525 u32 result, address = ar->hw_params.patch_load_addr;
526 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
529 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
531 ath10k_err(ar, "failed to download board data: %d\n", ret);
535 /* OTP is optional */
537 if (!ar->otp_data || !ar->otp_len) {
538 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
539 ar->otp_data, ar->otp_len);
543 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
544 address, ar->otp_len);
546 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
548 ath10k_err(ar, "could not write otp (%d)\n", ret);
552 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
554 ath10k_err(ar, "could not execute otp (%d)\n", ret);
558 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
560 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
563 ath10k_err(ar, "otp calibration failed: %d", result);
570 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
572 u32 address, data_len;
573 const char *mode_name;
577 address = ar->hw_params.patch_load_addr;
580 case ATH10K_FIRMWARE_MODE_NORMAL:
581 data = ar->firmware_data;
582 data_len = ar->firmware_len;
583 mode_name = "normal";
584 ret = ath10k_swap_code_seg_configure(ar,
585 ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW);
587 ath10k_err(ar, "failed to configure fw code swap: %d\n",
592 case ATH10K_FIRMWARE_MODE_UTF:
593 data = ar->testmode.utf_firmware_data;
594 data_len = ar->testmode.utf_firmware_len;
598 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
602 ath10k_dbg(ar, ATH10K_DBG_BOOT,
603 "boot uploading firmware image %p len %d mode %s\n",
604 data, data_len, mode_name);
606 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
608 ath10k_err(ar, "failed to download %s firmware: %d\n",
616 static void ath10k_core_free_board_files(struct ath10k *ar)
618 if (!IS_ERR(ar->board))
619 release_firmware(ar->board);
622 ar->board_data = NULL;
626 static void ath10k_core_free_firmware_files(struct ath10k *ar)
628 if (!IS_ERR(ar->otp))
629 release_firmware(ar->otp);
631 if (!IS_ERR(ar->firmware))
632 release_firmware(ar->firmware);
634 if (!IS_ERR(ar->cal_file))
635 release_firmware(ar->cal_file);
637 ath10k_swap_code_seg_release(ar);
644 ar->firmware_data = NULL;
645 ar->firmware_len = 0;
650 static int ath10k_fetch_cal_file(struct ath10k *ar)
654 /* cal-<bus>-<id>.bin */
655 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
656 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
658 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
659 if (IS_ERR(ar->cal_file))
660 /* calibration file is optional, don't print any warnings */
661 return PTR_ERR(ar->cal_file);
663 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
664 ATH10K_FW_DIR, filename);
669 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar)
671 if (!ar->hw_params.fw.board) {
672 ath10k_err(ar, "failed to find board file fw entry\n");
676 ar->board = ath10k_fetch_fw_file(ar,
677 ar->hw_params.fw.dir,
678 ar->hw_params.fw.board);
679 if (IS_ERR(ar->board))
680 return PTR_ERR(ar->board);
682 ar->board_data = ar->board->data;
683 ar->board_len = ar->board->size;
688 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
689 const void *buf, size_t buf_len,
690 const char *boardname)
692 const struct ath10k_fw_ie *hdr;
693 bool name_match_found;
694 int ret, board_ie_id;
696 const void *board_ie_data;
698 name_match_found = false;
700 /* go through ATH10K_BD_IE_BOARD_ elements */
701 while (buf_len > sizeof(struct ath10k_fw_ie)) {
703 board_ie_id = le32_to_cpu(hdr->id);
704 board_ie_len = le32_to_cpu(hdr->len);
705 board_ie_data = hdr->data;
707 buf_len -= sizeof(*hdr);
710 if (buf_len < ALIGN(board_ie_len, 4)) {
711 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
712 buf_len, ALIGN(board_ie_len, 4));
717 switch (board_ie_id) {
718 case ATH10K_BD_IE_BOARD_NAME:
719 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
720 board_ie_data, board_ie_len);
722 if (board_ie_len != strlen(boardname))
725 ret = memcmp(board_ie_data, boardname, strlen(boardname));
729 name_match_found = true;
730 ath10k_dbg(ar, ATH10K_DBG_BOOT,
731 "boot found match for name '%s'",
734 case ATH10K_BD_IE_BOARD_DATA:
735 if (!name_match_found)
739 ath10k_dbg(ar, ATH10K_DBG_BOOT,
740 "boot found board data for '%s'",
743 ar->board_data = board_ie_data;
744 ar->board_len = board_ie_len;
749 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
754 /* jump over the padding */
755 board_ie_len = ALIGN(board_ie_len, 4);
757 buf_len -= board_ie_len;
768 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
769 const char *boardname,
770 const char *filename)
772 size_t len, magic_len, ie_len;
773 struct ath10k_fw_ie *hdr;
777 ar->board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, filename);
778 if (IS_ERR(ar->board))
779 return PTR_ERR(ar->board);
781 data = ar->board->data;
782 len = ar->board->size;
784 /* magic has extra null byte padded */
785 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
786 if (len < magic_len) {
787 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
788 ar->hw_params.fw.dir, filename, len);
793 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
794 ath10k_err(ar, "found invalid board magic\n");
799 /* magic is padded to 4 bytes */
800 magic_len = ALIGN(magic_len, 4);
801 if (len < magic_len) {
802 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
803 ar->hw_params.fw.dir, filename, len);
811 while (len > sizeof(struct ath10k_fw_ie)) {
812 hdr = (struct ath10k_fw_ie *)data;
813 ie_id = le32_to_cpu(hdr->id);
814 ie_len = le32_to_cpu(hdr->len);
819 if (len < ALIGN(ie_len, 4)) {
820 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
827 case ATH10K_BD_IE_BOARD:
828 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
831 /* no match found, continue */
834 /* there was an error, bail out */
837 /* board data found */
841 /* jump over the padding */
842 ie_len = ALIGN(ie_len, 4);
849 if (!ar->board_data || !ar->board_len) {
851 "failed to fetch board data for %s from %s/%s\n",
852 boardname, ar->hw_params.fw.dir, filename);
860 ath10k_core_free_board_files(ar);
864 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
867 if (ar->id.bmi_ids_valid) {
868 scnprintf(name, name_len,
869 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d",
870 ath10k_bus_str(ar->hif.bus),
872 ar->id.bmi_board_id);
876 scnprintf(name, name_len,
877 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
878 ath10k_bus_str(ar->hif.bus),
879 ar->id.vendor, ar->id.device,
880 ar->id.subsystem_vendor, ar->id.subsystem_device);
883 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
888 static int ath10k_core_fetch_board_file(struct ath10k *ar)
893 ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
895 ath10k_err(ar, "failed to create board name: %d", ret);
900 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
901 ATH10K_BOARD_API2_FILE);
906 ret = ath10k_core_fetch_board_data_api_1(ar);
908 ath10k_err(ar, "failed to fetch board data\n");
913 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
917 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
921 if (ar->hw_params.fw.fw == NULL) {
922 ath10k_err(ar, "firmware file not defined\n");
926 ar->firmware = ath10k_fetch_fw_file(ar,
927 ar->hw_params.fw.dir,
928 ar->hw_params.fw.fw);
929 if (IS_ERR(ar->firmware)) {
930 ret = PTR_ERR(ar->firmware);
931 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
935 ar->firmware_data = ar->firmware->data;
936 ar->firmware_len = ar->firmware->size;
938 /* OTP may be undefined. If so, don't fetch it at all */
939 if (ar->hw_params.fw.otp == NULL)
942 ar->otp = ath10k_fetch_fw_file(ar,
943 ar->hw_params.fw.dir,
944 ar->hw_params.fw.otp);
945 if (IS_ERR(ar->otp)) {
946 ret = PTR_ERR(ar->otp);
947 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
951 ar->otp_data = ar->otp->data;
952 ar->otp_len = ar->otp->size;
957 ath10k_core_free_firmware_files(ar);
961 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
963 size_t magic_len, len, ie_len;
964 int ie_id, i, index, bit, ret;
965 struct ath10k_fw_ie *hdr;
967 __le32 *timestamp, *version;
969 /* first fetch the firmware file (firmware-*.bin) */
970 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
971 if (IS_ERR(ar->firmware)) {
972 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
973 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
974 return PTR_ERR(ar->firmware);
977 data = ar->firmware->data;
978 len = ar->firmware->size;
980 /* magic also includes the null byte, check that as well */
981 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
983 if (len < magic_len) {
984 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
985 ar->hw_params.fw.dir, name, len);
990 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
991 ath10k_err(ar, "invalid firmware magic\n");
996 /* jump over the padding */
997 magic_len = ALIGN(magic_len, 4);
1003 while (len > sizeof(struct ath10k_fw_ie)) {
1004 hdr = (struct ath10k_fw_ie *)data;
1006 ie_id = le32_to_cpu(hdr->id);
1007 ie_len = le32_to_cpu(hdr->len);
1009 len -= sizeof(*hdr);
1010 data += sizeof(*hdr);
1013 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
1014 ie_id, len, ie_len);
1020 case ATH10K_FW_IE_FW_VERSION:
1021 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
1024 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
1025 ar->hw->wiphy->fw_version[ie_len] = '\0';
1027 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1028 "found fw version %s\n",
1029 ar->hw->wiphy->fw_version);
1031 case ATH10K_FW_IE_TIMESTAMP:
1032 if (ie_len != sizeof(u32))
1035 timestamp = (__le32 *)data;
1037 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
1038 le32_to_cpup(timestamp));
1040 case ATH10K_FW_IE_FEATURES:
1041 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1042 "found firmware features ie (%zd B)\n",
1045 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
1049 if (index == ie_len)
1052 if (data[index] & (1 << bit)) {
1053 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1054 "Enabling feature bit: %i\n",
1056 __set_bit(i, ar->fw_features);
1060 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
1062 sizeof(ar->fw_features));
1064 case ATH10K_FW_IE_FW_IMAGE:
1065 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1066 "found fw image ie (%zd B)\n",
1069 ar->firmware_data = data;
1070 ar->firmware_len = ie_len;
1073 case ATH10K_FW_IE_OTP_IMAGE:
1074 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1075 "found otp image ie (%zd B)\n",
1078 ar->otp_data = data;
1079 ar->otp_len = ie_len;
1082 case ATH10K_FW_IE_WMI_OP_VERSION:
1083 if (ie_len != sizeof(u32))
1086 version = (__le32 *)data;
1088 ar->wmi.op_version = le32_to_cpup(version);
1090 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1091 ar->wmi.op_version);
1093 case ATH10K_FW_IE_HTT_OP_VERSION:
1094 if (ie_len != sizeof(u32))
1097 version = (__le32 *)data;
1099 ar->htt.op_version = le32_to_cpup(version);
1101 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1102 ar->htt.op_version);
1104 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1105 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1106 "found fw code swap image ie (%zd B)\n",
1108 ar->swap.firmware_codeswap_data = data;
1109 ar->swap.firmware_codeswap_len = ie_len;
1112 ath10k_warn(ar, "Unknown FW IE: %u\n",
1113 le32_to_cpu(hdr->id));
1117 /* jump over the padding */
1118 ie_len = ALIGN(ie_len, 4);
1124 if (!ar->firmware_data || !ar->firmware_len) {
1125 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1126 ar->hw_params.fw.dir, name);
1134 ath10k_core_free_firmware_files(ar);
1138 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1142 /* calibration file is optional, don't check for any errors */
1143 ath10k_fetch_cal_file(ar);
1146 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1148 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE);
1153 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1155 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE);
1160 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1162 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
1167 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1169 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
1174 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1176 ret = ath10k_core_fetch_firmware_api_1(ar);
1181 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1186 static int ath10k_download_cal_data(struct ath10k *ar)
1190 ret = ath10k_download_cal_file(ar);
1192 ar->cal_mode = ATH10K_CAL_MODE_FILE;
1196 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1197 "boot did not find a calibration file, try DT next: %d\n",
1200 ret = ath10k_download_cal_dt(ar);
1202 ar->cal_mode = ATH10K_CAL_MODE_DT;
1206 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1207 "boot did not find DT entry, try OTP next: %d\n",
1210 ret = ath10k_download_and_run_otp(ar);
1212 ath10k_err(ar, "failed to run otp: %d\n", ret);
1216 ar->cal_mode = ATH10K_CAL_MODE_OTP;
1219 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1220 ath10k_cal_mode_str(ar->cal_mode));
1224 static int ath10k_init_uart(struct ath10k *ar)
1229 * Explicitly setting UART prints to zero as target turns it on
1230 * based on scratch registers.
1232 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
1234 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
1241 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
1243 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1247 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
1249 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1253 /* Set the UART baud rate to 19200. */
1254 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1256 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1260 ath10k_info(ar, "UART prints enabled\n");
1264 static int ath10k_init_hw_params(struct ath10k *ar)
1266 const struct ath10k_hw_params *uninitialized_var(hw_params);
1269 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1270 hw_params = &ath10k_hw_params_list[i];
1272 if (hw_params->id == ar->target_version)
1276 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1277 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1278 ar->target_version);
1282 ar->hw_params = *hw_params;
1284 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1285 ar->hw_params.name, ar->target_version);
1290 static void ath10k_core_restart(struct work_struct *work)
1292 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1294 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1296 /* Place a barrier to make sure the compiler doesn't reorder
1297 * CRASH_FLUSH and calling other functions.
1301 ieee80211_stop_queues(ar->hw);
1302 ath10k_drain_tx(ar);
1303 complete_all(&ar->scan.started);
1304 complete_all(&ar->scan.completed);
1305 complete_all(&ar->scan.on_channel);
1306 complete_all(&ar->offchan_tx_completed);
1307 complete_all(&ar->install_key_done);
1308 complete_all(&ar->vdev_setup_done);
1309 complete_all(&ar->thermal.wmi_sync);
1310 wake_up(&ar->htt.empty_tx_wq);
1311 wake_up(&ar->wmi.tx_credits_wq);
1312 wake_up(&ar->peer_mapping_wq);
1314 mutex_lock(&ar->conf_mutex);
1316 switch (ar->state) {
1317 case ATH10K_STATE_ON:
1318 ar->state = ATH10K_STATE_RESTARTING;
1319 ath10k_hif_stop(ar);
1320 ath10k_scan_finish(ar);
1321 ieee80211_restart_hw(ar->hw);
1323 case ATH10K_STATE_OFF:
1324 /* this can happen if driver is being unloaded
1325 * or if the crash happens during FW probing */
1326 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1328 case ATH10K_STATE_RESTARTING:
1329 /* hw restart might be requested from multiple places */
1331 case ATH10K_STATE_RESTARTED:
1332 ar->state = ATH10K_STATE_WEDGED;
1334 case ATH10K_STATE_WEDGED:
1335 ath10k_warn(ar, "device is wedged, will not restart\n");
1337 case ATH10K_STATE_UTF:
1338 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1342 mutex_unlock(&ar->conf_mutex);
1345 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1347 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
1348 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1349 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1353 if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1354 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1355 ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version);
1359 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1360 switch (ath10k_cryptmode_param) {
1361 case ATH10K_CRYPT_MODE_HW:
1362 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1363 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1365 case ATH10K_CRYPT_MODE_SW:
1366 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1368 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1372 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1373 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1376 ath10k_info(ar, "invalid cryptmode: %d\n",
1377 ath10k_cryptmode_param);
1381 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1382 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1385 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1387 ath10k_err(ar, "rawmode = 1 requires support from firmware");
1390 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1393 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1394 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1398 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1399 * and causes enormous performance issues (malformed frames,
1402 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1403 * albeit a bit slower compared to regular operation.
1405 ar->htt.max_num_amsdu = 1;
1408 /* Backwards compatibility for firmwares without
1409 * ATH10K_FW_IE_WMI_OP_VERSION.
1411 if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1412 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1413 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1415 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1417 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1419 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1423 switch (ar->wmi.op_version) {
1424 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1425 ar->max_num_peers = TARGET_NUM_PEERS;
1426 ar->max_num_stations = TARGET_NUM_STATIONS;
1427 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1428 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1429 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1431 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1433 case ATH10K_FW_WMI_OP_VERSION_10_1:
1434 case ATH10K_FW_WMI_OP_VERSION_10_2:
1435 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1436 ar->max_num_peers = TARGET_10X_NUM_PEERS;
1437 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1438 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1439 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1440 ar->fw_stats_req_mask = WMI_STAT_PEER;
1441 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1443 case ATH10K_FW_WMI_OP_VERSION_TLV:
1444 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1445 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1446 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1447 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1448 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1449 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1450 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1452 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1454 case ATH10K_FW_WMI_OP_VERSION_10_4:
1455 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1456 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1457 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1458 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1459 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1460 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1461 ar->fw_stats_req_mask = WMI_STAT_PEER;
1462 ar->max_spatial_stream = WMI_10_4_MAX_SPATIAL_STREAM;
1464 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1465 case ATH10K_FW_WMI_OP_VERSION_MAX:
1470 /* Backwards compatibility for firmwares without
1471 * ATH10K_FW_IE_HTT_OP_VERSION.
1473 if (ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1474 switch (ar->wmi.op_version) {
1475 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1476 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1478 case ATH10K_FW_WMI_OP_VERSION_10_1:
1479 case ATH10K_FW_WMI_OP_VERSION_10_2:
1480 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1481 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1483 case ATH10K_FW_WMI_OP_VERSION_TLV:
1484 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1486 case ATH10K_FW_WMI_OP_VERSION_10_4:
1487 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1488 case ATH10K_FW_WMI_OP_VERSION_MAX:
1497 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
1501 lockdep_assert_held(&ar->conf_mutex);
1503 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1505 ath10k_bmi_start(ar);
1507 if (ath10k_init_configure_target(ar)) {
1512 status = ath10k_download_cal_data(ar);
1516 /* Some of of qca988x solutions are having global reset issue
1517 * during target initialization. Bypassing PLL setting before
1518 * downloading firmware and letting the SoC run on REF_CLK is
1519 * fixing the problem. Corresponding firmware change is also needed
1520 * to set the clock source once the target is initialized.
1522 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1524 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1526 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
1532 status = ath10k_download_fw(ar, mode);
1536 status = ath10k_init_uart(ar);
1540 ar->htc.htc_ops.target_send_suspend_complete =
1541 ath10k_send_suspend_complete;
1543 status = ath10k_htc_init(ar);
1545 ath10k_err(ar, "could not init HTC (%d)\n", status);
1549 status = ath10k_bmi_done(ar);
1553 status = ath10k_wmi_attach(ar);
1555 ath10k_err(ar, "WMI attach failed: %d\n", status);
1559 status = ath10k_htt_init(ar);
1561 ath10k_err(ar, "failed to init htt: %d\n", status);
1562 goto err_wmi_detach;
1565 status = ath10k_htt_tx_alloc(&ar->htt);
1567 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1568 goto err_wmi_detach;
1571 status = ath10k_htt_rx_alloc(&ar->htt);
1573 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1574 goto err_htt_tx_detach;
1577 status = ath10k_hif_start(ar);
1579 ath10k_err(ar, "could not start HIF: %d\n", status);
1580 goto err_htt_rx_detach;
1583 status = ath10k_htc_wait_target(&ar->htc);
1585 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1589 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1590 status = ath10k_htt_connect(&ar->htt);
1592 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1597 status = ath10k_wmi_connect(ar);
1599 ath10k_err(ar, "could not connect wmi: %d\n", status);
1603 status = ath10k_htc_start(&ar->htc);
1605 ath10k_err(ar, "failed to start htc: %d\n", status);
1609 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1610 status = ath10k_wmi_wait_for_service_ready(ar);
1612 ath10k_warn(ar, "wmi service ready event not received");
1617 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1618 ar->hw->wiphy->fw_version);
1620 status = ath10k_wmi_cmd_init(ar);
1622 ath10k_err(ar, "could not send WMI init command (%d)\n",
1627 status = ath10k_wmi_wait_for_unified_ready(ar);
1629 ath10k_err(ar, "wmi unified ready event not received\n");
1633 /* If firmware indicates Full Rx Reorder support it must be used in a
1634 * slightly different manner. Let HTT code know.
1636 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1639 status = ath10k_htt_rx_ring_refill(ar);
1641 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1645 /* we don't care about HTT in UTF mode */
1646 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1647 status = ath10k_htt_setup(&ar->htt);
1649 ath10k_err(ar, "failed to setup htt: %d\n", status);
1654 status = ath10k_debug_start(ar);
1658 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1660 INIT_LIST_HEAD(&ar->arvifs);
1665 ath10k_hif_stop(ar);
1667 ath10k_htt_rx_free(&ar->htt);
1669 ath10k_htt_tx_free(&ar->htt);
1671 ath10k_wmi_detach(ar);
1675 EXPORT_SYMBOL(ath10k_core_start);
1677 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1680 unsigned long time_left;
1682 reinit_completion(&ar->target_suspend);
1684 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1686 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1690 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1693 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1700 void ath10k_core_stop(struct ath10k *ar)
1702 lockdep_assert_held(&ar->conf_mutex);
1703 ath10k_debug_stop(ar);
1705 /* try to suspend target */
1706 if (ar->state != ATH10K_STATE_RESTARTING &&
1707 ar->state != ATH10K_STATE_UTF)
1708 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1710 ath10k_hif_stop(ar);
1711 ath10k_htt_tx_free(&ar->htt);
1712 ath10k_htt_rx_free(&ar->htt);
1713 ath10k_wmi_detach(ar);
1715 EXPORT_SYMBOL(ath10k_core_stop);
1717 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1718 * order to know what hw capabilities should be advertised to mac80211 it is
1719 * necessary to load the firmware (and tear it down immediately since start
1720 * hook will try to init it again) before registering */
1721 static int ath10k_core_probe_fw(struct ath10k *ar)
1723 struct bmi_target_info target_info;
1726 ret = ath10k_hif_power_up(ar);
1728 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1732 memset(&target_info, 0, sizeof(target_info));
1733 ret = ath10k_bmi_get_target_info(ar, &target_info);
1735 ath10k_err(ar, "could not get target info (%d)\n", ret);
1736 goto err_power_down;
1739 ar->target_version = target_info.version;
1740 ar->hw->wiphy->hw_version = target_info.version;
1742 ret = ath10k_init_hw_params(ar);
1744 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1745 goto err_power_down;
1748 ret = ath10k_core_fetch_firmware_files(ar);
1750 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1751 goto err_power_down;
1754 ret = ath10k_core_get_board_id_from_otp(ar);
1755 if (ret && ret != -EOPNOTSUPP) {
1756 ath10k_err(ar, "failed to get board id from otp: %d\n",
1761 ret = ath10k_core_fetch_board_file(ar);
1763 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
1764 goto err_free_firmware_files;
1767 ret = ath10k_core_init_firmware_features(ar);
1769 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1771 goto err_free_firmware_files;
1774 ret = ath10k_swap_code_seg_init(ar);
1776 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
1778 goto err_free_firmware_files;
1781 mutex_lock(&ar->conf_mutex);
1783 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1785 ath10k_err(ar, "could not init core (%d)\n", ret);
1789 ath10k_print_driver_info(ar);
1790 ath10k_core_stop(ar);
1792 mutex_unlock(&ar->conf_mutex);
1794 ath10k_hif_power_down(ar);
1798 mutex_unlock(&ar->conf_mutex);
1800 err_free_firmware_files:
1801 ath10k_core_free_firmware_files(ar);
1804 ath10k_hif_power_down(ar);
1809 static void ath10k_core_register_work(struct work_struct *work)
1811 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1814 status = ath10k_core_probe_fw(ar);
1816 ath10k_err(ar, "could not probe fw (%d)\n", status);
1820 status = ath10k_mac_register(ar);
1822 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1823 goto err_release_fw;
1826 status = ath10k_debug_register(ar);
1828 ath10k_err(ar, "unable to initialize debugfs\n");
1829 goto err_unregister_mac;
1832 status = ath10k_spectral_create(ar);
1834 ath10k_err(ar, "failed to initialize spectral\n");
1835 goto err_debug_destroy;
1838 status = ath10k_thermal_register(ar);
1840 ath10k_err(ar, "could not register thermal device: %d\n",
1842 goto err_spectral_destroy;
1845 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1848 err_spectral_destroy:
1849 ath10k_spectral_destroy(ar);
1851 ath10k_debug_destroy(ar);
1853 ath10k_mac_unregister(ar);
1855 ath10k_core_free_firmware_files(ar);
1857 /* TODO: It's probably a good idea to release device from the driver
1858 * but calling device_release_driver() here will cause a deadlock.
1863 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1865 ar->chip_id = chip_id;
1866 queue_work(ar->workqueue, &ar->register_work);
1870 EXPORT_SYMBOL(ath10k_core_register);
1872 void ath10k_core_unregister(struct ath10k *ar)
1874 cancel_work_sync(&ar->register_work);
1876 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1879 ath10k_thermal_unregister(ar);
1880 /* Stop spectral before unregistering from mac80211 to remove the
1881 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1882 * would be already be free'd recursively, leading to a double free.
1884 ath10k_spectral_destroy(ar);
1886 /* We must unregister from mac80211 before we stop HTC and HIF.
1887 * Otherwise we will fail to submit commands to FW and mac80211 will be
1888 * unhappy about callback failures. */
1889 ath10k_mac_unregister(ar);
1891 ath10k_testmode_destroy(ar);
1893 ath10k_core_free_firmware_files(ar);
1894 ath10k_core_free_board_files(ar);
1896 ath10k_debug_unregister(ar);
1898 EXPORT_SYMBOL(ath10k_core_unregister);
1900 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1901 enum ath10k_bus bus,
1902 enum ath10k_hw_rev hw_rev,
1903 const struct ath10k_hif_ops *hif_ops)
1908 ar = ath10k_mac_create(priv_size);
1912 ar->ath_common.priv = ar;
1913 ar->ath_common.hw = ar->hw;
1915 ar->hw_rev = hw_rev;
1916 ar->hif.ops = hif_ops;
1920 case ATH10K_HW_QCA988X:
1921 ar->regs = &qca988x_regs;
1922 ar->hw_values = &qca988x_values;
1924 case ATH10K_HW_QCA6174:
1925 case ATH10K_HW_QCA9377:
1926 ar->regs = &qca6174_regs;
1927 ar->hw_values = &qca6174_values;
1929 case ATH10K_HW_QCA99X0:
1930 ar->regs = &qca99x0_regs;
1931 ar->hw_values = &qca99x0_values;
1934 ath10k_err(ar, "unsupported core hardware revision %d\n",
1940 init_completion(&ar->scan.started);
1941 init_completion(&ar->scan.completed);
1942 init_completion(&ar->scan.on_channel);
1943 init_completion(&ar->target_suspend);
1944 init_completion(&ar->wow.wakeup_completed);
1946 init_completion(&ar->install_key_done);
1947 init_completion(&ar->vdev_setup_done);
1948 init_completion(&ar->thermal.wmi_sync);
1950 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1952 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1956 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
1957 if (!ar->workqueue_aux)
1960 mutex_init(&ar->conf_mutex);
1961 spin_lock_init(&ar->data_lock);
1963 INIT_LIST_HEAD(&ar->peers);
1964 init_waitqueue_head(&ar->peer_mapping_wq);
1965 init_waitqueue_head(&ar->htt.empty_tx_wq);
1966 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1968 init_completion(&ar->offchan_tx_completed);
1969 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1970 skb_queue_head_init(&ar->offchan_tx_queue);
1972 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1973 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1975 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1976 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1978 ret = ath10k_debug_create(ar);
1980 goto err_free_aux_wq;
1985 destroy_workqueue(ar->workqueue_aux);
1987 destroy_workqueue(ar->workqueue);
1990 ath10k_mac_destroy(ar);
1994 EXPORT_SYMBOL(ath10k_core_create);
1996 void ath10k_core_destroy(struct ath10k *ar)
1998 flush_workqueue(ar->workqueue);
1999 destroy_workqueue(ar->workqueue);
2001 flush_workqueue(ar->workqueue_aux);
2002 destroy_workqueue(ar->workqueue_aux);
2004 ath10k_debug_destroy(ar);
2005 ath10k_wmi_free_host_mem(ar);
2006 ath10k_mac_destroy(ar);
2008 EXPORT_SYMBOL(ath10k_core_destroy);
2010 MODULE_AUTHOR("Qualcomm Atheros");
2011 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
2012 MODULE_LICENSE("Dual BSD/GPL");