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>
32 unsigned int ath10k_debug_mask;
33 static bool uart_print;
34 static unsigned int ath10k_p2p;
37 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
38 module_param(uart_print, bool, 0644);
39 module_param_named(p2p, ath10k_p2p, uint, 0644);
40 module_param(skip_otp, bool, 0644);
42 MODULE_PARM_DESC(debug_mask, "Debugging mask");
43 MODULE_PARM_DESC(uart_print, "Uart target debugging");
44 MODULE_PARM_DESC(p2p, "Enable ath10k P2P support");
45 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
47 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
49 .id = QCA988X_HW_2_0_VERSION,
50 .name = "qca988x hw2.0",
51 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
54 .dir = QCA988X_HW_2_0_FW_DIR,
55 .fw = QCA988X_HW_2_0_FW_FILE,
56 .otp = QCA988X_HW_2_0_OTP_FILE,
57 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
58 .board_size = QCA988X_BOARD_DATA_SZ,
59 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
64 static void ath10k_send_suspend_complete(struct ath10k *ar)
66 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
68 complete(&ar->target_suspend);
71 static int ath10k_init_configure_target(struct ath10k *ar)
76 /* tell target which HTC version it is used*/
77 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
78 HTC_PROTOCOL_VERSION);
80 ath10k_err(ar, "settings HTC version failed\n");
84 /* set the firmware mode to STA/IBSS/AP */
85 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
87 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
91 /* TODO following parameters need to be re-visited. */
93 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
95 /* FIXME: Why FW_MODE_AP ??.*/
96 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
98 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
100 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
102 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
104 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
106 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
110 /* We do all byte-swapping on the host */
111 ret = ath10k_bmi_write32(ar, hi_be, 0);
113 ath10k_err(ar, "setting host CPU BE mode failed\n");
117 /* FW descriptor/Data swap flags */
118 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
121 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
128 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
133 const struct firmware *fw;
137 return ERR_PTR(-ENOENT);
142 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
143 ret = request_firmware(&fw, filename, ar->dev);
150 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
153 u32 board_data_size = ar->hw_params.fw.board_size;
154 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
155 u32 board_ext_data_addr;
158 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
160 ath10k_err(ar, "could not read board ext data addr (%d)\n",
165 ath10k_dbg(ar, ATH10K_DBG_BOOT,
166 "boot push board extended data addr 0x%x\n",
167 board_ext_data_addr);
169 if (board_ext_data_addr == 0)
172 if (data_len != (board_data_size + board_ext_data_size)) {
173 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
174 data_len, board_data_size, board_ext_data_size);
178 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
179 data + board_data_size,
180 board_ext_data_size);
182 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
186 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
187 (board_ext_data_size << 16) | 1);
189 ath10k_err(ar, "could not write board ext data bit (%d)\n",
197 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
200 u32 board_data_size = ar->hw_params.fw.board_size;
204 ret = ath10k_push_board_ext_data(ar, data, data_len);
206 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
210 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
212 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
216 ret = ath10k_bmi_write_memory(ar, address, data,
217 min_t(u32, board_data_size,
220 ath10k_err(ar, "could not write board data (%d)\n", ret);
224 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
226 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
234 static int ath10k_download_cal_file(struct ath10k *ar)
241 if (IS_ERR(ar->cal_file))
242 return PTR_ERR(ar->cal_file);
244 ret = ath10k_download_board_data(ar, ar->cal_file->data,
247 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
251 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
256 static int ath10k_download_cal_dt(struct ath10k *ar)
258 struct device_node *node;
263 node = ar->dev->of_node;
265 /* Device Tree is optional, don't print any warnings if
266 * there's no node for ath10k.
270 if (!of_get_property(node, "qcom,ath10k-calibration-data",
272 /* The calibration data node is optional */
276 if (data_len != QCA988X_CAL_DATA_LEN) {
277 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
283 data = kmalloc(data_len, GFP_KERNEL);
289 ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data",
292 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
297 ret = ath10k_download_board_data(ar, data, data_len);
299 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
313 static int ath10k_download_and_run_otp(struct ath10k *ar)
315 u32 result, address = ar->hw_params.patch_load_addr;
318 ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len);
320 ath10k_err(ar, "failed to download board data: %d\n", ret);
324 /* OTP is optional */
326 if (!ar->otp_data || !ar->otp_len) {
327 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
328 ar->otp_data, ar->otp_len);
332 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
333 address, ar->otp_len);
335 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
337 ath10k_err(ar, "could not write otp (%d)\n", ret);
341 ret = ath10k_bmi_execute(ar, address, 0, &result);
343 ath10k_err(ar, "could not execute otp (%d)\n", ret);
347 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
349 if (!skip_otp && result != 0) {
350 ath10k_err(ar, "otp calibration failed: %d", result);
357 static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
359 u32 address, data_len;
360 const char *mode_name;
364 address = ar->hw_params.patch_load_addr;
367 case ATH10K_FIRMWARE_MODE_NORMAL:
368 data = ar->firmware_data;
369 data_len = ar->firmware_len;
370 mode_name = "normal";
372 case ATH10K_FIRMWARE_MODE_UTF:
373 data = ar->testmode.utf->data;
374 data_len = ar->testmode.utf->size;
378 ath10k_err(ar, "unknown firmware mode: %d\n", mode);
382 ath10k_dbg(ar, ATH10K_DBG_BOOT,
383 "boot uploading firmware image %p len %d mode %s\n",
384 data, data_len, mode_name);
386 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
388 ath10k_err(ar, "failed to download %s firmware: %d\n",
396 static void ath10k_core_free_firmware_files(struct ath10k *ar)
398 if (ar->board && !IS_ERR(ar->board))
399 release_firmware(ar->board);
401 if (ar->otp && !IS_ERR(ar->otp))
402 release_firmware(ar->otp);
404 if (ar->firmware && !IS_ERR(ar->firmware))
405 release_firmware(ar->firmware);
407 if (ar->cal_file && !IS_ERR(ar->cal_file))
408 release_firmware(ar->cal_file);
411 ar->board_data = NULL;
419 ar->firmware_data = NULL;
420 ar->firmware_len = 0;
425 static int ath10k_fetch_cal_file(struct ath10k *ar)
429 /* cal-<bus>-<id>.bin */
430 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
431 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
433 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
434 if (IS_ERR(ar->cal_file))
435 /* calibration file is optional, don't print any warnings */
436 return PTR_ERR(ar->cal_file);
438 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
439 ATH10K_FW_DIR, filename);
444 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
448 if (ar->hw_params.fw.fw == NULL) {
449 ath10k_err(ar, "firmware file not defined\n");
453 if (ar->hw_params.fw.board == NULL) {
454 ath10k_err(ar, "board data file not defined");
458 ar->board = ath10k_fetch_fw_file(ar,
459 ar->hw_params.fw.dir,
460 ar->hw_params.fw.board);
461 if (IS_ERR(ar->board)) {
462 ret = PTR_ERR(ar->board);
463 ath10k_err(ar, "could not fetch board data (%d)\n", ret);
467 ar->board_data = ar->board->data;
468 ar->board_len = ar->board->size;
470 ar->firmware = ath10k_fetch_fw_file(ar,
471 ar->hw_params.fw.dir,
472 ar->hw_params.fw.fw);
473 if (IS_ERR(ar->firmware)) {
474 ret = PTR_ERR(ar->firmware);
475 ath10k_err(ar, "could not fetch firmware (%d)\n", ret);
479 ar->firmware_data = ar->firmware->data;
480 ar->firmware_len = ar->firmware->size;
482 /* OTP may be undefined. If so, don't fetch it at all */
483 if (ar->hw_params.fw.otp == NULL)
486 ar->otp = ath10k_fetch_fw_file(ar,
487 ar->hw_params.fw.dir,
488 ar->hw_params.fw.otp);
489 if (IS_ERR(ar->otp)) {
490 ret = PTR_ERR(ar->otp);
491 ath10k_err(ar, "could not fetch otp (%d)\n", ret);
495 ar->otp_data = ar->otp->data;
496 ar->otp_len = ar->otp->size;
501 ath10k_core_free_firmware_files(ar);
505 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
507 size_t magic_len, len, ie_len;
508 int ie_id, i, index, bit, ret;
509 struct ath10k_fw_ie *hdr;
513 /* first fetch the firmware file (firmware-*.bin) */
514 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
515 if (IS_ERR(ar->firmware)) {
516 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
517 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
518 return PTR_ERR(ar->firmware);
521 data = ar->firmware->data;
522 len = ar->firmware->size;
524 /* magic also includes the null byte, check that as well */
525 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
527 if (len < magic_len) {
528 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
529 ar->hw_params.fw.dir, name, len);
534 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
535 ath10k_err(ar, "invalid firmware magic\n");
540 /* jump over the padding */
541 magic_len = ALIGN(magic_len, 4);
547 while (len > sizeof(struct ath10k_fw_ie)) {
548 hdr = (struct ath10k_fw_ie *)data;
550 ie_id = le32_to_cpu(hdr->id);
551 ie_len = le32_to_cpu(hdr->len);
554 data += sizeof(*hdr);
557 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
564 case ATH10K_FW_IE_FW_VERSION:
565 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
568 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
569 ar->hw->wiphy->fw_version[ie_len] = '\0';
571 ath10k_dbg(ar, ATH10K_DBG_BOOT,
572 "found fw version %s\n",
573 ar->hw->wiphy->fw_version);
575 case ATH10K_FW_IE_TIMESTAMP:
576 if (ie_len != sizeof(u32))
579 timestamp = (__le32 *)data;
581 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
582 le32_to_cpup(timestamp));
584 case ATH10K_FW_IE_FEATURES:
585 ath10k_dbg(ar, ATH10K_DBG_BOOT,
586 "found firmware features ie (%zd B)\n",
589 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
596 if (data[index] & (1 << bit)) {
597 ath10k_dbg(ar, ATH10K_DBG_BOOT,
598 "Enabling feature bit: %i\n",
600 __set_bit(i, ar->fw_features);
604 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
606 sizeof(ar->fw_features));
608 case ATH10K_FW_IE_FW_IMAGE:
609 ath10k_dbg(ar, ATH10K_DBG_BOOT,
610 "found fw image ie (%zd B)\n",
613 ar->firmware_data = data;
614 ar->firmware_len = ie_len;
617 case ATH10K_FW_IE_OTP_IMAGE:
618 ath10k_dbg(ar, ATH10K_DBG_BOOT,
619 "found otp image ie (%zd B)\n",
623 ar->otp_len = ie_len;
627 ath10k_warn(ar, "Unknown FW IE: %u\n",
628 le32_to_cpu(hdr->id));
632 /* jump over the padding */
633 ie_len = ALIGN(ie_len, 4);
639 if (!ar->firmware_data || !ar->firmware_len) {
640 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
641 ar->hw_params.fw.dir, name);
646 /* now fetch the board file */
647 if (ar->hw_params.fw.board == NULL) {
648 ath10k_err(ar, "board data file not defined");
653 ar->board = ath10k_fetch_fw_file(ar,
654 ar->hw_params.fw.dir,
655 ar->hw_params.fw.board);
656 if (IS_ERR(ar->board)) {
657 ret = PTR_ERR(ar->board);
658 ath10k_err(ar, "could not fetch board data '%s/%s' (%d)\n",
659 ar->hw_params.fw.dir, ar->hw_params.fw.board,
664 ar->board_data = ar->board->data;
665 ar->board_len = ar->board->size;
670 ath10k_core_free_firmware_files(ar);
674 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
678 /* calibration file is optional, don't check for any errors */
679 ath10k_fetch_cal_file(ar);
682 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
684 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
689 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
691 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
696 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
698 ret = ath10k_core_fetch_firmware_api_1(ar);
703 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
708 static int ath10k_download_cal_data(struct ath10k *ar)
712 ret = ath10k_download_cal_file(ar);
714 ar->cal_mode = ATH10K_CAL_MODE_FILE;
718 ath10k_dbg(ar, ATH10K_DBG_BOOT,
719 "boot did not find a calibration file, try DT next: %d\n",
722 ret = ath10k_download_cal_dt(ar);
724 ar->cal_mode = ATH10K_CAL_MODE_DT;
728 ath10k_dbg(ar, ATH10K_DBG_BOOT,
729 "boot did not find DT entry, try OTP next: %d\n",
732 ret = ath10k_download_and_run_otp(ar);
734 ath10k_err(ar, "failed to run otp: %d\n", ret);
738 ar->cal_mode = ATH10K_CAL_MODE_OTP;
741 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
742 ath10k_cal_mode_str(ar->cal_mode));
746 static int ath10k_init_uart(struct ath10k *ar)
751 * Explicitly setting UART prints to zero as target turns it on
752 * based on scratch registers.
754 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
756 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
763 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
765 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
769 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
771 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
775 /* Set the UART baud rate to 19200. */
776 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
778 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
782 ath10k_info(ar, "UART prints enabled\n");
786 static int ath10k_init_hw_params(struct ath10k *ar)
788 const struct ath10k_hw_params *uninitialized_var(hw_params);
791 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
792 hw_params = &ath10k_hw_params_list[i];
794 if (hw_params->id == ar->target_version)
798 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
799 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
804 ar->hw_params = *hw_params;
806 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
807 ar->hw_params.name, ar->target_version);
812 static void ath10k_core_restart(struct work_struct *work)
814 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
816 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
818 /* Place a barrier to make sure the compiler doesn't reorder
819 * CRASH_FLUSH and calling other functions.
823 ieee80211_stop_queues(ar->hw);
825 complete_all(&ar->scan.started);
826 complete_all(&ar->scan.completed);
827 complete_all(&ar->scan.on_channel);
828 complete_all(&ar->offchan_tx_completed);
829 complete_all(&ar->install_key_done);
830 complete_all(&ar->vdev_setup_done);
831 wake_up(&ar->htt.empty_tx_wq);
832 wake_up(&ar->wmi.tx_credits_wq);
833 wake_up(&ar->peer_mapping_wq);
835 mutex_lock(&ar->conf_mutex);
838 case ATH10K_STATE_ON:
839 ar->state = ATH10K_STATE_RESTARTING;
841 ath10k_scan_finish(ar);
842 ieee80211_restart_hw(ar->hw);
844 case ATH10K_STATE_OFF:
845 /* this can happen if driver is being unloaded
846 * or if the crash happens during FW probing */
847 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
849 case ATH10K_STATE_RESTARTING:
850 /* hw restart might be requested from multiple places */
852 case ATH10K_STATE_RESTARTED:
853 ar->state = ATH10K_STATE_WEDGED;
855 case ATH10K_STATE_WEDGED:
856 ath10k_warn(ar, "device is wedged, will not restart\n");
858 case ATH10K_STATE_UTF:
859 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
863 mutex_unlock(&ar->conf_mutex);
866 static int ath10k_core_init_firmware_features(struct ath10k *ar)
868 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
869 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
870 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
874 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
875 ar->max_num_peers = TARGET_10X_NUM_PEERS;
876 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
878 ar->max_num_peers = TARGET_NUM_PEERS;
879 ar->max_num_stations = TARGET_NUM_STATIONS;
885 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode)
889 lockdep_assert_held(&ar->conf_mutex);
891 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
893 ath10k_bmi_start(ar);
895 if (ath10k_init_configure_target(ar)) {
900 status = ath10k_download_cal_data(ar);
904 status = ath10k_download_fw(ar, mode);
908 status = ath10k_init_uart(ar);
912 ar->htc.htc_ops.target_send_suspend_complete =
913 ath10k_send_suspend_complete;
915 status = ath10k_htc_init(ar);
917 ath10k_err(ar, "could not init HTC (%d)\n", status);
921 status = ath10k_bmi_done(ar);
925 status = ath10k_wmi_attach(ar);
927 ath10k_err(ar, "WMI attach failed: %d\n", status);
931 status = ath10k_htt_init(ar);
933 ath10k_err(ar, "failed to init htt: %d\n", status);
937 status = ath10k_htt_tx_alloc(&ar->htt);
939 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
943 status = ath10k_htt_rx_alloc(&ar->htt);
945 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
946 goto err_htt_tx_detach;
949 status = ath10k_hif_start(ar);
951 ath10k_err(ar, "could not start HIF: %d\n", status);
952 goto err_htt_rx_detach;
955 status = ath10k_htc_wait_target(&ar->htc);
957 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
961 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
962 status = ath10k_htt_connect(&ar->htt);
964 ath10k_err(ar, "failed to connect htt (%d)\n", status);
969 status = ath10k_wmi_connect(ar);
971 ath10k_err(ar, "could not connect wmi: %d\n", status);
975 status = ath10k_htc_start(&ar->htc);
977 ath10k_err(ar, "failed to start htc: %d\n", status);
981 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
982 status = ath10k_wmi_wait_for_service_ready(ar);
984 ath10k_warn(ar, "wmi service ready event not received");
990 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
991 ar->hw->wiphy->fw_version);
993 status = ath10k_wmi_cmd_init(ar);
995 ath10k_err(ar, "could not send WMI init command (%d)\n",
1000 status = ath10k_wmi_wait_for_unified_ready(ar);
1002 ath10k_err(ar, "wmi unified ready event not received\n");
1003 status = -ETIMEDOUT;
1007 /* we don't care about HTT in UTF mode */
1008 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1009 status = ath10k_htt_setup(&ar->htt);
1011 ath10k_err(ar, "failed to setup htt: %d\n", status);
1016 status = ath10k_debug_start(ar);
1020 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
1021 ar->free_vdev_map = (1LL << TARGET_10X_NUM_VDEVS) - 1;
1023 ar->free_vdev_map = (1LL << TARGET_NUM_VDEVS) - 1;
1025 INIT_LIST_HEAD(&ar->arvifs);
1030 ath10k_hif_stop(ar);
1032 ath10k_htt_rx_free(&ar->htt);
1034 ath10k_htt_tx_free(&ar->htt);
1036 ath10k_wmi_detach(ar);
1040 EXPORT_SYMBOL(ath10k_core_start);
1042 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
1046 reinit_completion(&ar->target_suspend);
1048 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
1050 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
1054 ret = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
1057 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
1064 void ath10k_core_stop(struct ath10k *ar)
1066 lockdep_assert_held(&ar->conf_mutex);
1068 /* try to suspend target */
1069 if (ar->state != ATH10K_STATE_RESTARTING &&
1070 ar->state != ATH10K_STATE_UTF)
1071 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
1073 ath10k_debug_stop(ar);
1074 ath10k_hif_stop(ar);
1075 ath10k_htt_tx_free(&ar->htt);
1076 ath10k_htt_rx_free(&ar->htt);
1077 ath10k_wmi_detach(ar);
1079 EXPORT_SYMBOL(ath10k_core_stop);
1081 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1082 * order to know what hw capabilities should be advertised to mac80211 it is
1083 * necessary to load the firmware (and tear it down immediately since start
1084 * hook will try to init it again) before registering */
1085 static int ath10k_core_probe_fw(struct ath10k *ar)
1087 struct bmi_target_info target_info;
1090 ret = ath10k_hif_power_up(ar);
1092 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
1096 memset(&target_info, 0, sizeof(target_info));
1097 ret = ath10k_bmi_get_target_info(ar, &target_info);
1099 ath10k_err(ar, "could not get target info (%d)\n", ret);
1100 goto err_power_down;
1103 ar->target_version = target_info.version;
1104 ar->hw->wiphy->hw_version = target_info.version;
1106 ret = ath10k_init_hw_params(ar);
1108 ath10k_err(ar, "could not get hw params (%d)\n", ret);
1109 goto err_power_down;
1112 ret = ath10k_core_fetch_firmware_files(ar);
1114 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
1115 goto err_power_down;
1118 ret = ath10k_core_init_firmware_features(ar);
1120 ath10k_err(ar, "fatal problem with firmware features: %d\n",
1122 goto err_free_firmware_files;
1125 mutex_lock(&ar->conf_mutex);
1127 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
1129 ath10k_err(ar, "could not init core (%d)\n", ret);
1133 ath10k_print_driver_info(ar);
1134 ath10k_core_stop(ar);
1136 mutex_unlock(&ar->conf_mutex);
1138 ath10k_hif_power_down(ar);
1142 mutex_unlock(&ar->conf_mutex);
1144 err_free_firmware_files:
1145 ath10k_core_free_firmware_files(ar);
1148 ath10k_hif_power_down(ar);
1153 static void ath10k_core_register_work(struct work_struct *work)
1155 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1158 status = ath10k_core_probe_fw(ar);
1160 ath10k_err(ar, "could not probe fw (%d)\n", status);
1164 status = ath10k_mac_register(ar);
1166 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
1167 goto err_release_fw;
1170 status = ath10k_debug_register(ar);
1172 ath10k_err(ar, "unable to initialize debugfs\n");
1173 goto err_unregister_mac;
1176 status = ath10k_spectral_create(ar);
1178 ath10k_err(ar, "failed to initialize spectral\n");
1179 goto err_debug_destroy;
1182 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1186 ath10k_debug_destroy(ar);
1188 ath10k_mac_unregister(ar);
1190 ath10k_core_free_firmware_files(ar);
1192 /* TODO: It's probably a good idea to release device from the driver
1193 * but calling device_release_driver() here will cause a deadlock.
1198 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1200 ar->chip_id = chip_id;
1201 queue_work(ar->workqueue, &ar->register_work);
1205 EXPORT_SYMBOL(ath10k_core_register);
1207 void ath10k_core_unregister(struct ath10k *ar)
1209 cancel_work_sync(&ar->register_work);
1211 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1214 /* Stop spectral before unregistering from mac80211 to remove the
1215 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1216 * would be already be free'd recursively, leading to a double free.
1218 ath10k_spectral_destroy(ar);
1220 /* We must unregister from mac80211 before we stop HTC and HIF.
1221 * Otherwise we will fail to submit commands to FW and mac80211 will be
1222 * unhappy about callback failures. */
1223 ath10k_mac_unregister(ar);
1225 ath10k_testmode_destroy(ar);
1227 ath10k_core_free_firmware_files(ar);
1229 ath10k_debug_unregister(ar);
1231 EXPORT_SYMBOL(ath10k_core_unregister);
1233 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
1234 enum ath10k_bus bus,
1235 const struct ath10k_hif_ops *hif_ops)
1240 ar = ath10k_mac_create(priv_size);
1244 ar->ath_common.priv = ar;
1245 ar->ath_common.hw = ar->hw;
1247 ar->p2p = !!ath10k_p2p;
1250 ar->hif.ops = hif_ops;
1253 init_completion(&ar->scan.started);
1254 init_completion(&ar->scan.completed);
1255 init_completion(&ar->scan.on_channel);
1256 init_completion(&ar->target_suspend);
1258 init_completion(&ar->install_key_done);
1259 init_completion(&ar->vdev_setup_done);
1261 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1263 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1267 mutex_init(&ar->conf_mutex);
1268 spin_lock_init(&ar->data_lock);
1270 INIT_LIST_HEAD(&ar->peers);
1271 init_waitqueue_head(&ar->peer_mapping_wq);
1272 init_waitqueue_head(&ar->htt.empty_tx_wq);
1273 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1275 init_completion(&ar->offchan_tx_completed);
1276 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1277 skb_queue_head_init(&ar->offchan_tx_queue);
1279 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1280 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1282 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1283 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1285 ret = ath10k_debug_create(ar);
1292 destroy_workqueue(ar->workqueue);
1295 ath10k_mac_destroy(ar);
1299 EXPORT_SYMBOL(ath10k_core_create);
1301 void ath10k_core_destroy(struct ath10k *ar)
1303 flush_workqueue(ar->workqueue);
1304 destroy_workqueue(ar->workqueue);
1306 ath10k_debug_destroy(ar);
1307 ath10k_mac_destroy(ar);
1309 EXPORT_SYMBOL(ath10k_core_destroy);
1311 MODULE_AUTHOR("Qualcomm Atheros");
1312 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1313 MODULE_LICENSE("Dual BSD/GPL");