2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/module.h>
19 #include <linux/firmware.h>
33 unsigned int ath10k_debug_mask;
34 static unsigned int ath10k_cryptmode_param;
35 static bool uart_print;
39 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
40 module_param_named(cryptmode, ath10k_cryptmode_param, uint, 0644);
41 module_param(uart_print, bool, 0644);
42 module_param(skip_otp, bool, 0644);
43 module_param(rawmode, bool, 0644);
45 MODULE_PARM_DESC(debug_mask, "Debugging mask");
46 MODULE_PARM_DESC(uart_print, "Uart target debugging");
47 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
48 MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
49 MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath");
51 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
53 .id = QCA988X_HW_2_0_VERSION,
54 .name = "qca988x hw2.0",
55 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
57 .has_shifted_cc_wraparound = true,
59 .channel_counters_freq_hz = 88000,
60 .max_probe_resp_desc_thres = 0,
62 .dir = QCA988X_HW_2_0_FW_DIR,
63 .fw = QCA988X_HW_2_0_FW_FILE,
64 .otp = QCA988X_HW_2_0_OTP_FILE,
65 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
66 .board_size = QCA988X_BOARD_DATA_SZ,
67 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
71 .id = QCA6174_HW_2_1_VERSION,
72 .name = "qca6174 hw2.1",
73 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
76 .channel_counters_freq_hz = 88000,
77 .max_probe_resp_desc_thres = 0,
79 .dir = QCA6174_HW_2_1_FW_DIR,
80 .fw = QCA6174_HW_2_1_FW_FILE,
81 .otp = QCA6174_HW_2_1_OTP_FILE,
82 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
83 .board_size = QCA6174_BOARD_DATA_SZ,
84 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
88 .id = QCA6174_HW_3_0_VERSION,
89 .name = "qca6174 hw3.0",
90 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
93 .channel_counters_freq_hz = 88000,
94 .max_probe_resp_desc_thres = 0,
96 .dir = QCA6174_HW_3_0_FW_DIR,
97 .fw = QCA6174_HW_3_0_FW_FILE,
98 .otp = QCA6174_HW_3_0_OTP_FILE,
99 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
100 .board_size = QCA6174_BOARD_DATA_SZ,
101 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
105 .id = QCA6174_HW_3_2_VERSION,
106 .name = "qca6174 hw3.2",
107 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
110 .channel_counters_freq_hz = 88000,
111 .max_probe_resp_desc_thres = 0,
113 /* uses same binaries as hw3.0 */
114 .dir = QCA6174_HW_3_0_FW_DIR,
115 .fw = QCA6174_HW_3_0_FW_FILE,
116 .otp = QCA6174_HW_3_0_OTP_FILE,
117 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
118 .board_size = QCA6174_BOARD_DATA_SZ,
119 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
123 .id = QCA99X0_HW_2_0_DEV_VERSION,
124 .name = "qca99x0 hw2.0",
125 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
127 .otp_exe_param = 0x00000700,
128 .continuous_frag_desc = true,
129 .channel_counters_freq_hz = 150000,
130 .max_probe_resp_desc_thres = 24,
132 .dir = QCA99X0_HW_2_0_FW_DIR,
133 .fw = QCA99X0_HW_2_0_FW_FILE,
134 .otp = QCA99X0_HW_2_0_OTP_FILE,
135 .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
136 .board_size = QCA99X0_BOARD_DATA_SZ,
137 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
142 static const char *const ath10k_core_fw_feature_str[] = {
143 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
144 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
145 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
146 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
147 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
148 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
149 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
150 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
151 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
152 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
153 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
156 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
158 enum ath10k_fw_features feat)
160 /* make sure that ath10k_core_fw_feature_str[] gets updated */
161 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
162 ATH10K_FW_FEATURE_COUNT);
164 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
165 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
166 return scnprintf(buf, buf_len, "bit%d", feat);
169 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
172 void ath10k_core_get_fw_features_str(struct ath10k *ar,
176 unsigned int len = 0;
179 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
180 if (test_bit(i, ar->fw_features)) {
182 len += scnprintf(buf + len, buf_len - len, ",");
184 len += ath10k_core_get_fw_feature_str(buf + len,
191 static void ath10k_send_suspend_complete(struct ath10k *ar)
193 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
195 complete(&ar->target_suspend);
198 static int ath10k_init_configure_target(struct ath10k *ar)
203 /* tell target which HTC version it is used*/
204 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
205 HTC_PROTOCOL_VERSION);
207 ath10k_err(ar, "settings HTC version failed\n");
211 /* set the firmware mode to STA/IBSS/AP */
212 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
214 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
218 /* TODO following parameters need to be re-visited. */
220 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
222 /* FIXME: Why FW_MODE_AP ??.*/
223 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
224 /* mac_addr_method */
225 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
226 /* firmware_bridge */
227 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
229 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
231 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
233 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
237 /* We do all byte-swapping on the host */
238 ret = ath10k_bmi_write32(ar, hi_be, 0);
240 ath10k_err(ar, "setting host CPU BE mode failed\n");
244 /* FW descriptor/Data swap flags */
245 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
248 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
252 /* Some devices have a special sanity check that verifies the PCI
253 * Device ID is written to this host interest var. It is known to be
254 * required to boot QCA6164.
256 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
259 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
266 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
271 const struct firmware *fw;
275 return ERR_PTR(-ENOENT);
280 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
281 ret = request_firmware(&fw, filename, ar->dev);
288 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
291 u32 board_data_size = ar->hw_params.fw.board_size;
292 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
293 u32 board_ext_data_addr;
296 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
298 ath10k_err(ar, "could not read board ext data addr (%d)\n",
303 ath10k_dbg(ar, ATH10K_DBG_BOOT,
304 "boot push board extended data addr 0x%x\n",
305 board_ext_data_addr);
307 if (board_ext_data_addr == 0)
310 if (data_len != (board_data_size + board_ext_data_size)) {
311 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
312 data_len, board_data_size, board_ext_data_size);
316 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
317 data + board_data_size,
318 board_ext_data_size);
320 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
324 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
325 (board_ext_data_size << 16) | 1);
327 ath10k_err(ar, "could not write board ext data bit (%d)\n",
335 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
338 u32 board_data_size = ar->hw_params.fw.board_size;
342 ret = ath10k_push_board_ext_data(ar, data, data_len);
344 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
348 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
350 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
354 ret = ath10k_bmi_write_memory(ar, address, data,
355 min_t(u32, board_data_size,
358 ath10k_err(ar, "could not write board data (%d)\n", ret);
362 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
364 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
372 static int ath10k_download_cal_file(struct ath10k *ar)
379 if (IS_ERR(ar->cal_file))
380 return PTR_ERR(ar->cal_file);
382 ret = ath10k_download_board_data(ar, ar->cal_file->data,
385 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
389 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
394 static int ath10k_download_cal_dt(struct ath10k *ar)
396 struct device_node *node;
401 node = ar->dev->of_node;
403 /* Device Tree is optional, don't print any warnings if
404 * there's no node for ath10k.
408 if (!of_get_property(node, "qcom,ath10k-calibration-data",
410 /* The calibration data node is optional */
414 if (data_len != QCA988X_CAL_DATA_LEN) {
415 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
421 data = kmalloc(data_len, GFP_KERNEL);
427 ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
430 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
435 ret = ath10k_download_board_data(ar, data, data_len);
437 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
451 static int ath10k_download_and_run_otp(struct ath10k *ar)
453 u32 result, address = ar->hw_params.patch_load_addr;
454 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
457 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
459 ath10k_err(ar, "failed to download board data: %d\n", ret);
463 /* OTP is optional */
465 if (!ar->otp_data || !ar->otp_len) {
466 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
467 ar->otp_data, ar->otp_len);
471 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
472 address, ar->otp_len);
474 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
476 ath10k_err(ar, "could not write otp (%d)\n", ret);
480 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
482 ath10k_err(ar, "could not execute otp (%d)\n", ret);
486 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
488 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
491 ath10k_err(ar, "otp calibration failed: %d", result);
498 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
500 u32 address, data_len;
501 const char *mode_name;
505 address = ar->hw_params.patch_load_addr;
508 case ATH10K_FIRMWARE_MODE_NORMAL:
509 data = ar->firmware_data;
510 data_len = ar->firmware_len;
511 mode_name = "normal";
512 ret = ath10k_swap_code_seg_configure(ar,
513 ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW);
515 ath10k_err(ar, "failed to configure fw code swap: %d\n",
520 case ATH10K_FIRMWARE_MODE_UTF:
521 data = ar->testmode.utf->data;
522 data_len = ar->testmode.utf->size;
526 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
530 ath10k_dbg(ar, ATH10K_DBG_BOOT,
531 "boot uploading firmware image %p len %d mode %s\n",
532 data, data_len, mode_name);
534 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
536 ath10k_err(ar, "failed to download %s firmware: %d\n",
544 static void ath10k_core_free_board_files(struct ath10k *ar)
546 if (!IS_ERR(ar->board))
547 release_firmware(ar->board);
550 ar->board_data = NULL;
554 static void ath10k_core_free_firmware_files(struct ath10k *ar)
556 if (!IS_ERR(ar->otp))
557 release_firmware(ar->otp);
559 if (!IS_ERR(ar->firmware))
560 release_firmware(ar->firmware);
562 if (!IS_ERR(ar->cal_file))
563 release_firmware(ar->cal_file);
565 ath10k_swap_code_seg_release(ar);
572 ar->firmware_data = NULL;
573 ar->firmware_len = 0;
578 static int ath10k_fetch_cal_file(struct ath10k *ar)
582 /* cal-<bus>-<id>.bin */
583 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
584 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
586 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
587 if (IS_ERR(ar->cal_file))
588 /* calibration file is optional, don't print any warnings */
589 return PTR_ERR(ar->cal_file);
591 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
592 ATH10K_FW_DIR, filename);
597 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar)
599 if (!ar->hw_params.fw.board) {
600 ath10k_err(ar, "failed to find board file fw entry\n");
604 ar->board = ath10k_fetch_fw_file(ar,
605 ar->hw_params.fw.dir,
606 ar->hw_params.fw.board);
607 if (IS_ERR(ar->board))
608 return PTR_ERR(ar->board);
610 ar->board_data = ar->board->data;
611 ar->board_len = ar->board->size;
616 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
617 const void *buf, size_t buf_len,
618 const char *boardname)
620 const struct ath10k_fw_ie *hdr;
621 bool name_match_found;
622 int ret, board_ie_id;
624 const void *board_ie_data;
626 name_match_found = false;
628 /* go through ATH10K_BD_IE_BOARD_ elements */
629 while (buf_len > sizeof(struct ath10k_fw_ie)) {
631 board_ie_id = le32_to_cpu(hdr->id);
632 board_ie_len = le32_to_cpu(hdr->len);
633 board_ie_data = hdr->data;
635 buf_len -= sizeof(*hdr);
638 if (buf_len < ALIGN(board_ie_len, 4)) {
639 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
640 buf_len, ALIGN(board_ie_len, 4));
645 switch (board_ie_id) {
646 case ATH10K_BD_IE_BOARD_NAME:
647 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
648 board_ie_data, board_ie_len);
650 if (board_ie_len != strlen(boardname))
653 ret = memcmp(board_ie_data, boardname, strlen(boardname));
657 name_match_found = true;
658 ath10k_dbg(ar, ATH10K_DBG_BOOT,
659 "boot found match for name '%s'",
662 case ATH10K_BD_IE_BOARD_DATA:
663 if (!name_match_found)
667 ath10k_dbg(ar, ATH10K_DBG_BOOT,
668 "boot found board data for '%s'",
671 ar->board_data = board_ie_data;
672 ar->board_len = board_ie_len;
677 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
682 /* jump over the padding */
683 board_ie_len = ALIGN(board_ie_len, 4);
685 buf_len -= board_ie_len;
696 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
697 const char *boardname,
698 const char *filename)
700 size_t len, magic_len, ie_len;
701 struct ath10k_fw_ie *hdr;
705 ar->board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, filename);
706 if (IS_ERR(ar->board))
707 return PTR_ERR(ar->board);
709 data = ar->board->data;
710 len = ar->board->size;
712 /* magic has extra null byte padded */
713 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
714 if (len < magic_len) {
715 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
716 ar->hw_params.fw.dir, filename, len);
721 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
722 ath10k_err(ar, "found invalid board magic\n");
727 /* magic is padded to 4 bytes */
728 magic_len = ALIGN(magic_len, 4);
729 if (len < magic_len) {
730 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
731 ar->hw_params.fw.dir, filename, len);
739 while (len > sizeof(struct ath10k_fw_ie)) {
740 hdr = (struct ath10k_fw_ie *)data;
741 ie_id = le32_to_cpu(hdr->id);
742 ie_len = le32_to_cpu(hdr->len);
747 if (len < ALIGN(ie_len, 4)) {
748 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
755 case ATH10K_BD_IE_BOARD:
756 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
759 /* no match found, continue */
762 /* there was an error, bail out */
765 /* board data found */
769 /* jump over the padding */
770 ie_len = ALIGN(ie_len, 4);
777 if (!ar->board_data || !ar->board_len) {
779 "failed to fetch board data for %s from %s/%s\n",
780 ar->hw_params.fw.dir, boardname, filename);
788 ath10k_core_free_board_files(ar);
792 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
795 scnprintf(name, name_len,
796 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
797 ath10k_bus_str(ar->hif.bus),
798 ar->id.vendor, ar->id.device,
799 ar->id.subsystem_vendor, ar->id.subsystem_device);
801 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
806 static int ath10k_core_fetch_board_file(struct ath10k *ar)
811 ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
813 ath10k_err(ar, "failed to create board name: %d", ret);
818 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
819 ATH10K_BOARD_API2_FILE);
824 ret = ath10k_core_fetch_board_data_api_1(ar);
826 ath10k_err(ar, "failed to fetch board data\n");
831 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
835 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
839 if (ar->hw_params.fw.fw == NULL) {
840 ath10k_err(ar, "firmware file not defined\n");
844 ar->firmware = ath10k_fetch_fw_file(ar,
845 ar->hw_params.fw.dir,
846 ar->hw_params.fw.fw);
847 if (IS_ERR(ar->firmware)) {
848 ret = PTR_ERR(ar->firmware);
849 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
853 ar->firmware_data = ar->firmware->data;
854 ar->firmware_len = ar->firmware->size;
856 /* OTP may be undefined. If so, don't fetch it at all */
857 if (ar->hw_params.fw.otp == NULL)
860 ar->otp = ath10k_fetch_fw_file(ar,
861 ar->hw_params.fw.dir,
862 ar->hw_params.fw.otp);
863 if (IS_ERR(ar->otp)) {
864 ret = PTR_ERR(ar->otp);
865 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
869 ar->otp_data = ar->otp->data;
870 ar->otp_len = ar->otp->size;
875 ath10k_core_free_firmware_files(ar);
879 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
881 size_t magic_len, len, ie_len;
882 int ie_id, i, index, bit, ret;
883 struct ath10k_fw_ie *hdr;
885 __le32 *timestamp, *version;
887 /* first fetch the firmware file (firmware-*.bin) */
888 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
889 if (IS_ERR(ar->firmware)) {
890 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
891 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
892 return PTR_ERR(ar->firmware);
895 data = ar->firmware->data;
896 len = ar->firmware->size;
898 /* magic also includes the null byte, check that as well */
899 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
901 if (len < magic_len) {
902 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
903 ar->hw_params.fw.dir, name, len);
908 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
909 ath10k_err(ar, "invalid firmware magic\n");
914 /* jump over the padding */
915 magic_len = ALIGN(magic_len, 4);
921 while (len > sizeof(struct ath10k_fw_ie)) {
922 hdr = (struct ath10k_fw_ie *)data;
924 ie_id = le32_to_cpu(hdr->id);
925 ie_len = le32_to_cpu(hdr->len);
928 data += sizeof(*hdr);
931 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
938 case ATH10K_FW_IE_FW_VERSION:
939 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
942 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
943 ar->hw->wiphy->fw_version[ie_len] = '\0';
945 ath10k_dbg(ar, ATH10K_DBG_BOOT,
946 "found fw version %s\n",
947 ar->hw->wiphy->fw_version);
949 case ATH10K_FW_IE_TIMESTAMP:
950 if (ie_len != sizeof(u32))
953 timestamp = (__le32 *)data;
955 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
956 le32_to_cpup(timestamp));
958 case ATH10K_FW_IE_FEATURES:
959 ath10k_dbg(ar, ATH10K_DBG_BOOT,
960 "found firmware features ie (%zd B)\n",
963 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
970 if (data[index] & (1 << bit)) {
971 ath10k_dbg(ar, ATH10K_DBG_BOOT,
972 "Enabling feature bit: %i\n",
974 __set_bit(i, ar->fw_features);
978 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
980 sizeof(ar->fw_features));
982 case ATH10K_FW_IE_FW_IMAGE:
983 ath10k_dbg(ar, ATH10K_DBG_BOOT,
984 "found fw image ie (%zd B)\n",
987 ar->firmware_data = data;
988 ar->firmware_len = ie_len;
991 case ATH10K_FW_IE_OTP_IMAGE:
992 ath10k_dbg(ar, ATH10K_DBG_BOOT,
993 "found otp image ie (%zd B)\n",
997 ar->otp_len = ie_len;
1000 case ATH10K_FW_IE_WMI_OP_VERSION:
1001 if (ie_len != sizeof(u32))
1004 version = (__le32 *)data;
1006 ar->wmi.op_version = le32_to_cpup(version);
1008 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1009 ar->wmi.op_version);
1011 case ATH10K_FW_IE_HTT_OP_VERSION:
1012 if (ie_len != sizeof(u32))
1015 version = (__le32 *)data;
1017 ar->htt.op_version = le32_to_cpup(version);
1019 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1020 ar->htt.op_version);
1022 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1023 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1024 "found fw code swap image ie (%zd B)\n",
1026 ar->swap.firmware_codeswap_data = data;
1027 ar->swap.firmware_codeswap_len = ie_len;
1030 ath10k_warn(ar, "Unknown FW IE: %u\n",
1031 le32_to_cpu(hdr->id));
1035 /* jump over the padding */
1036 ie_len = ALIGN(ie_len, 4);
1042 if (!ar->firmware_data || !ar->firmware_len) {
1043 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1044 ar->hw_params.fw.dir, name);
1052 ath10k_core_free_firmware_files(ar);
1056 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1060 /* calibration file is optional, don't check for any errors */
1061 ath10k_fetch_cal_file(ar);
1063 ret = ath10k_core_fetch_board_file(ar);
1065 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
1070 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1072 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE);
1077 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1079 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE);
1084 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1086 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
1091 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1093 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
1098 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1100 ret = ath10k_core_fetch_firmware_api_1(ar);
1105 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1110 static int ath10k_download_cal_data(struct ath10k *ar)
1114 ret = ath10k_download_cal_file(ar);
1116 ar->cal_mode = ATH10K_CAL_MODE_FILE;
1120 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1121 "boot did not find a calibration file, try DT next: %d\n",
1124 ret = ath10k_download_cal_dt(ar);
1126 ar->cal_mode = ATH10K_CAL_MODE_DT;
1130 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1131 "boot did not find DT entry, try OTP next: %d\n",
1134 ret = ath10k_download_and_run_otp(ar);
1136 ath10k_err(ar, "failed to run otp: %d\n", ret);
1140 ar->cal_mode = ATH10K_CAL_MODE_OTP;
1143 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1144 ath10k_cal_mode_str(ar->cal_mode));
1148 static int ath10k_init_uart(struct ath10k *ar)
1153 * Explicitly setting UART prints to zero as target turns it on
1154 * based on scratch registers.
1156 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
1158 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
1165 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
1167 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1171 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
1173 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1177 /* Set the UART baud rate to 19200. */
1178 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1180 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1184 ath10k_info(ar, "UART prints enabled\n");
1188 static int ath10k_init_hw_params(struct ath10k *ar)
1190 const struct ath10k_hw_params *uninitialized_var(hw_params);
1193 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1194 hw_params = &ath10k_hw_params_list[i];
1196 if (hw_params->id == ar->target_version)
1200 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1201 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1202 ar->target_version);
1206 ar->hw_params = *hw_params;
1208 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1209 ar->hw_params.name, ar->target_version);
1214 static void ath10k_core_restart(struct work_struct *work)
1216 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1218 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1220 /* Place a barrier to make sure the compiler doesn't reorder
1221 * CRASH_FLUSH and calling other functions.
1225 ieee80211_stop_queues(ar->hw);
1226 ath10k_drain_tx(ar);
1227 complete_all(&ar->scan.started);
1228 complete_all(&ar->scan.completed);
1229 complete_all(&ar->scan.on_channel);
1230 complete_all(&ar->offchan_tx_completed);
1231 complete_all(&ar->install_key_done);
1232 complete_all(&ar->vdev_setup_done);
1233 complete_all(&ar->thermal.wmi_sync);
1234 wake_up(&ar->htt.empty_tx_wq);
1235 wake_up(&ar->wmi.tx_credits_wq);
1236 wake_up(&ar->peer_mapping_wq);
1238 mutex_lock(&ar->conf_mutex);
1240 switch (ar->state) {
1241 case ATH10K_STATE_ON:
1242 ar->state = ATH10K_STATE_RESTARTING;
1243 ath10k_hif_stop(ar);
1244 ath10k_scan_finish(ar);
1245 ieee80211_restart_hw(ar->hw);
1247 case ATH10K_STATE_OFF:
1248 /* this can happen if driver is being unloaded
1249 * or if the crash happens during FW probing */
1250 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1252 case ATH10K_STATE_RESTARTING:
1253 /* hw restart might be requested from multiple places */
1255 case ATH10K_STATE_RESTARTED:
1256 ar->state = ATH10K_STATE_WEDGED;
1258 case ATH10K_STATE_WEDGED:
1259 ath10k_warn(ar, "device is wedged, will not restart\n");
1261 case ATH10K_STATE_UTF:
1262 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1266 mutex_unlock(&ar->conf_mutex);
1269 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1271 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
1272 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1273 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1277 if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1278 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1279 ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version);
1283 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1284 switch (ath10k_cryptmode_param) {
1285 case ATH10K_CRYPT_MODE_HW:
1286 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1287 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1289 case ATH10K_CRYPT_MODE_SW:
1290 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1292 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1296 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1297 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1300 ath10k_info(ar, "invalid cryptmode: %d\n",
1301 ath10k_cryptmode_param);
1305 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1306 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1309 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1311 ath10k_err(ar, "rawmode = 1 requires support from firmware");
1314 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1317 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1318 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1322 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1323 * and causes enormous performance issues (malformed frames,
1326 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1327 * albeit a bit slower compared to regular operation.
1329 ar->htt.max_num_amsdu = 1;
1332 /* Backwards compatibility for firmwares without
1333 * ATH10K_FW_IE_WMI_OP_VERSION.
1335 if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1336 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
1337 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1339 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1341 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1343 ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1347 switch (ar->wmi.op_version) {
1348 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1349 ar->max_num_peers = TARGET_NUM_PEERS;
1350 ar->max_num_stations = TARGET_NUM_STATIONS;
1351 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1352 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1353 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1355 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1357 case ATH10K_FW_WMI_OP_VERSION_10_1:
1358 case ATH10K_FW_WMI_OP_VERSION_10_2:
1359 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1360 ar->max_num_peers = TARGET_10X_NUM_PEERS;
1361 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1362 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1363 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1364 ar->fw_stats_req_mask = WMI_STAT_PEER;
1365 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1367 case ATH10K_FW_WMI_OP_VERSION_TLV:
1368 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1369 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1370 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1371 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1372 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1373 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1374 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1376 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1378 case ATH10K_FW_WMI_OP_VERSION_10_4:
1379 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1380 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1381 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1382 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1383 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1384 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1385 ar->fw_stats_req_mask = WMI_STAT_PEER;
1386 ar->max_spatial_stream = WMI_10_4_MAX_SPATIAL_STREAM;
1388 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1389 case ATH10K_FW_WMI_OP_VERSION_MAX:
1394 /* Backwards compatibility for firmwares without
1395 * ATH10K_FW_IE_HTT_OP_VERSION.
1397 if (ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1398 switch (ar->wmi.op_version) {
1399 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1400 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1402 case ATH10K_FW_WMI_OP_VERSION_10_1:
1403 case ATH10K_FW_WMI_OP_VERSION_10_2:
1404 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1405 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1407 case ATH10K_FW_WMI_OP_VERSION_TLV:
1408 ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1410 case ATH10K_FW_WMI_OP_VERSION_10_4:
1411 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1412 case ATH10K_FW_WMI_OP_VERSION_MAX:
1421 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
1425 lockdep_assert_held(&ar->conf_mutex);
1427 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1429 ath10k_bmi_start(ar);
1431 if (ath10k_init_configure_target(ar)) {
1436 status = ath10k_download_cal_data(ar);
1440 /* Some of of qca988x solutions are having global reset issue
1441 * during target initialization. Bypassing PLL setting before
1442 * downloading firmware and letting the SoC run on REF_CLK is
1443 * fixing the problem. Corresponding firmware change is also needed
1444 * to set the clock source once the target is initialized.
1446 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1448 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1450 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
1456 status = ath10k_download_fw(ar, mode);
1460 status = ath10k_init_uart(ar);
1464 ar->htc.htc_ops.target_send_suspend_complete =
1465 ath10k_send_suspend_complete;
1467 status = ath10k_htc_init(ar);
1469 ath10k_err(ar, "could not init HTC (%d)\n", status);
1473 status = ath10k_bmi_done(ar);
1477 status = ath10k_wmi_attach(ar);
1479 ath10k_err(ar, "WMI attach failed: %d\n", status);
1483 status = ath10k_htt_init(ar);
1485 ath10k_err(ar, "failed to init htt: %d\n", status);
1486 goto err_wmi_detach;
1489 status = ath10k_htt_tx_alloc(&ar->htt);
1491 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1492 goto err_wmi_detach;
1495 status = ath10k_htt_rx_alloc(&ar->htt);
1497 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1498 goto err_htt_tx_detach;
1501 status = ath10k_hif_start(ar);
1503 ath10k_err(ar, "could not start HIF: %d\n", status);
1504 goto err_htt_rx_detach;
1507 status = ath10k_htc_wait_target(&ar->htc);
1509 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1513 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1514 status = ath10k_htt_connect(&ar->htt);
1516 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1521 status = ath10k_wmi_connect(ar);
1523 ath10k_err(ar, "could not connect wmi: %d\n", status);
1527 status = ath10k_htc_start(&ar->htc);
1529 ath10k_err(ar, "failed to start htc: %d\n", status);
1533 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1534 status = ath10k_wmi_wait_for_service_ready(ar);
1536 ath10k_warn(ar, "wmi service ready event not received");
1541 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1542 ar->hw->wiphy->fw_version);
1544 status = ath10k_wmi_cmd_init(ar);
1546 ath10k_err(ar, "could not send WMI init command (%d)\n",
1551 status = ath10k_wmi_wait_for_unified_ready(ar);
1553 ath10k_err(ar, "wmi unified ready event not received\n");
1557 /* If firmware indicates Full Rx Reorder support it must be used in a
1558 * slightly different manner. Let HTT code know.
1560 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1563 status = ath10k_htt_rx_ring_refill(ar);
1565 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1569 /* we don't care about HTT in UTF mode */
1570 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1571 status = ath10k_htt_setup(&ar->htt);
1573 ath10k_err(ar, "failed to setup htt: %d\n", status);
1578 status = ath10k_debug_start(ar);
1582 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1584 INIT_LIST_HEAD(&ar->arvifs);
1589 ath10k_hif_stop(ar);
1591 ath10k_htt_rx_free(&ar->htt);
1593 ath10k_htt_tx_free(&ar->htt);
1595 ath10k_wmi_detach(ar);
1599 EXPORT_SYMBOL(ath10k_core_start);
1601 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1604 unsigned long time_left;
1606 reinit_completion(&ar->target_suspend);
1608 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1610 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1614 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1617 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1624 void ath10k_core_stop(struct ath10k *ar)
1626 lockdep_assert_held(&ar->conf_mutex);
1627 ath10k_debug_stop(ar);
1629 /* try to suspend target */
1630 if (ar->state != ATH10K_STATE_RESTARTING &&
1631 ar->state != ATH10K_STATE_UTF)
1632 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1634 ath10k_hif_stop(ar);
1635 ath10k_htt_tx_free(&ar->htt);
1636 ath10k_htt_rx_free(&ar->htt);
1637 ath10k_wmi_detach(ar);
1639 EXPORT_SYMBOL(ath10k_core_stop);
1641 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1642 * order to know what hw capabilities should be advertised to mac80211 it is
1643 * necessary to load the firmware (and tear it down immediately since start
1644 * hook will try to init it again) before registering */
1645 static int ath10k_core_probe_fw(struct ath10k *ar)
1647 struct bmi_target_info target_info;
1650 ret = ath10k_hif_power_up(ar);
1652 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1656 memset(&target_info, 0, sizeof(target_info));
1657 ret = ath10k_bmi_get_target_info(ar, &target_info);
1659 ath10k_err(ar, "could not get target info (%d)\n", ret);
1660 goto err_power_down;
1663 ar->target_version = target_info.version;
1664 ar->hw->wiphy->hw_version = target_info.version;
1666 ret = ath10k_init_hw_params(ar);
1668 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1669 goto err_power_down;
1672 ret = ath10k_core_fetch_firmware_files(ar);
1674 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1675 goto err_power_down;
1678 ret = ath10k_core_init_firmware_features(ar);
1680 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1682 goto err_free_firmware_files;
1685 ret = ath10k_swap_code_seg_init(ar);
1687 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
1689 goto err_free_firmware_files;
1692 mutex_lock(&ar->conf_mutex);
1694 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1696 ath10k_err(ar, "could not init core (%d)\n", ret);
1700 ath10k_print_driver_info(ar);
1701 ath10k_core_stop(ar);
1703 mutex_unlock(&ar->conf_mutex);
1705 ath10k_hif_power_down(ar);
1709 mutex_unlock(&ar->conf_mutex);
1711 err_free_firmware_files:
1712 ath10k_core_free_firmware_files(ar);
1715 ath10k_hif_power_down(ar);
1720 static void ath10k_core_register_work(struct work_struct *work)
1722 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1725 status = ath10k_core_probe_fw(ar);
1727 ath10k_err(ar, "could not probe fw (%d)\n", status);
1731 status = ath10k_mac_register(ar);
1733 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1734 goto err_release_fw;
1737 status = ath10k_debug_register(ar);
1739 ath10k_err(ar, "unable to initialize debugfs\n");
1740 goto err_unregister_mac;
1743 status = ath10k_spectral_create(ar);
1745 ath10k_err(ar, "failed to initialize spectral\n");
1746 goto err_debug_destroy;
1749 status = ath10k_thermal_register(ar);
1751 ath10k_err(ar, "could not register thermal device: %d\n",
1753 goto err_spectral_destroy;
1756 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1759 err_spectral_destroy:
1760 ath10k_spectral_destroy(ar);
1762 ath10k_debug_destroy(ar);
1764 ath10k_mac_unregister(ar);
1766 ath10k_core_free_firmware_files(ar);
1768 /* TODO: It's probably a good idea to release device from the driver
1769 * but calling device_release_driver() here will cause a deadlock.
1774 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1776 ar->chip_id = chip_id;
1777 queue_work(ar->workqueue, &ar->register_work);
1781 EXPORT_SYMBOL(ath10k_core_register);
1783 void ath10k_core_unregister(struct ath10k *ar)
1785 cancel_work_sync(&ar->register_work);
1787 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1790 ath10k_thermal_unregister(ar);
1791 /* Stop spectral before unregistering from mac80211 to remove the
1792 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1793 * would be already be free'd recursively, leading to a double free.
1795 ath10k_spectral_destroy(ar);
1797 /* We must unregister from mac80211 before we stop HTC and HIF.
1798 * Otherwise we will fail to submit commands to FW and mac80211 will be
1799 * unhappy about callback failures. */
1800 ath10k_mac_unregister(ar);
1802 ath10k_testmode_destroy(ar);
1804 ath10k_core_free_firmware_files(ar);
1805 ath10k_core_free_board_files(ar);
1807 ath10k_debug_unregister(ar);
1809 EXPORT_SYMBOL(ath10k_core_unregister);
1811 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1812 enum ath10k_bus bus,
1813 enum ath10k_hw_rev hw_rev,
1814 const struct ath10k_hif_ops *hif_ops)
1819 ar = ath10k_mac_create(priv_size);
1823 ar->ath_common.priv = ar;
1824 ar->ath_common.hw = ar->hw;
1826 ar->hw_rev = hw_rev;
1827 ar->hif.ops = hif_ops;
1831 case ATH10K_HW_QCA988X:
1832 ar->regs = &qca988x_regs;
1833 ar->hw_values = &qca988x_values;
1835 case ATH10K_HW_QCA6174:
1836 ar->regs = &qca6174_regs;
1837 ar->hw_values = &qca6174_values;
1839 case ATH10K_HW_QCA99X0:
1840 ar->regs = &qca99x0_regs;
1841 ar->hw_values = &qca99x0_values;
1844 ath10k_err(ar, "unsupported core hardware revision %d\n",
1850 init_completion(&ar->scan.started);
1851 init_completion(&ar->scan.completed);
1852 init_completion(&ar->scan.on_channel);
1853 init_completion(&ar->target_suspend);
1854 init_completion(&ar->wow.wakeup_completed);
1856 init_completion(&ar->install_key_done);
1857 init_completion(&ar->vdev_setup_done);
1858 init_completion(&ar->thermal.wmi_sync);
1860 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1862 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1866 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
1867 if (!ar->workqueue_aux)
1870 mutex_init(&ar->conf_mutex);
1871 spin_lock_init(&ar->data_lock);
1873 INIT_LIST_HEAD(&ar->peers);
1874 init_waitqueue_head(&ar->peer_mapping_wq);
1875 init_waitqueue_head(&ar->htt.empty_tx_wq);
1876 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1878 init_completion(&ar->offchan_tx_completed);
1879 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1880 skb_queue_head_init(&ar->offchan_tx_queue);
1882 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1883 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1885 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1886 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1888 ret = ath10k_debug_create(ar);
1890 goto err_free_aux_wq;
1895 destroy_workqueue(ar->workqueue_aux);
1897 destroy_workqueue(ar->workqueue);
1900 ath10k_mac_destroy(ar);
1904 EXPORT_SYMBOL(ath10k_core_create);
1906 void ath10k_core_destroy(struct ath10k *ar)
1908 flush_workqueue(ar->workqueue);
1909 destroy_workqueue(ar->workqueue);
1911 flush_workqueue(ar->workqueue_aux);
1912 destroy_workqueue(ar->workqueue_aux);
1914 ath10k_debug_destroy(ar);
1915 ath10k_wmi_free_host_mem(ar);
1916 ath10k_mac_destroy(ar);
1918 EXPORT_SYMBOL(ath10k_core_destroy);
1920 MODULE_AUTHOR("Qualcomm Atheros");
1921 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1922 MODULE_LICENSE("Dual BSD/GPL");