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>
30 unsigned int ath10k_debug_mask;
31 static bool uart_print;
32 static unsigned int ath10k_p2p;
33 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
34 module_param(uart_print, bool, 0644);
35 module_param_named(p2p, ath10k_p2p, uint, 0644);
36 MODULE_PARM_DESC(debug_mask, "Debugging mask");
37 MODULE_PARM_DESC(uart_print, "Uart target debugging");
38 MODULE_PARM_DESC(p2p, "Enable ath10k P2P support");
40 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
42 .id = QCA988X_HW_2_0_VERSION,
43 .name = "qca988x hw2.0",
44 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
46 .dir = QCA988X_HW_2_0_FW_DIR,
47 .fw = QCA988X_HW_2_0_FW_FILE,
48 .otp = QCA988X_HW_2_0_OTP_FILE,
49 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
54 static void ath10k_send_suspend_complete(struct ath10k *ar)
56 ath10k_dbg(ATH10K_DBG_BOOT, "boot suspend complete\n");
58 complete(&ar->target_suspend);
61 static int ath10k_init_configure_target(struct ath10k *ar)
66 /* tell target which HTC version it is used*/
67 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
68 HTC_PROTOCOL_VERSION);
70 ath10k_err("settings HTC version failed\n");
74 /* set the firmware mode to STA/IBSS/AP */
75 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
77 ath10k_err("setting firmware mode (1/2) failed\n");
81 /* TODO following parameters need to be re-visited. */
83 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
85 /* FIXME: Why FW_MODE_AP ??.*/
86 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
88 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
90 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
92 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
94 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
96 ath10k_err("setting firmware mode (2/2) failed\n");
100 /* We do all byte-swapping on the host */
101 ret = ath10k_bmi_write32(ar, hi_be, 0);
103 ath10k_err("setting host CPU BE mode failed\n");
107 /* FW descriptor/Data swap flags */
108 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
111 ath10k_err("setting FW data/desc swap flags failed\n");
118 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
123 const struct firmware *fw;
127 return ERR_PTR(-ENOENT);
132 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
133 ret = request_firmware(&fw, filename, ar->dev);
140 static int ath10k_push_board_ext_data(struct ath10k *ar)
142 u32 board_data_size = QCA988X_BOARD_DATA_SZ;
143 u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ;
144 u32 board_ext_data_addr;
147 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
149 ath10k_err("could not read board ext data addr (%d)\n", ret);
153 ath10k_dbg(ATH10K_DBG_BOOT,
154 "boot push board extended data addr 0x%x\n",
155 board_ext_data_addr);
157 if (board_ext_data_addr == 0)
160 if (ar->board_len != (board_data_size + board_ext_data_size)) {
161 ath10k_err("invalid board (ext) data sizes %zu != %d+%d\n",
162 ar->board_len, board_data_size, board_ext_data_size);
166 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
167 ar->board_data + board_data_size,
168 board_ext_data_size);
170 ath10k_err("could not write board ext data (%d)\n", ret);
174 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
175 (board_ext_data_size << 16) | 1);
177 ath10k_err("could not write board ext data bit (%d)\n", ret);
184 static int ath10k_download_board_data(struct ath10k *ar)
186 u32 board_data_size = QCA988X_BOARD_DATA_SZ;
190 ret = ath10k_push_board_ext_data(ar);
192 ath10k_err("could not push board ext data (%d)\n", ret);
196 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
198 ath10k_err("could not read board data addr (%d)\n", ret);
202 ret = ath10k_bmi_write_memory(ar, address, ar->board_data,
203 min_t(u32, board_data_size,
206 ath10k_err("could not write board data (%d)\n", ret);
210 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
212 ath10k_err("could not write board data bit (%d)\n", ret);
220 static int ath10k_download_and_run_otp(struct ath10k *ar)
222 u32 result, address = ar->hw_params.patch_load_addr;
225 /* OTP is optional */
227 if (!ar->otp_data || !ar->otp_len) {
228 ath10k_warn("Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
229 ar->otp_data, ar->otp_len);
233 ath10k_dbg(ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
234 address, ar->otp_len);
236 ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len);
238 ath10k_err("could not write otp (%d)\n", ret);
242 ret = ath10k_bmi_execute(ar, address, 0, &result);
244 ath10k_err("could not execute otp (%d)\n", ret);
248 ath10k_dbg(ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
251 ath10k_err("otp calibration failed: %d", result);
258 static int ath10k_download_fw(struct ath10k *ar)
263 address = ar->hw_params.patch_load_addr;
265 ret = ath10k_bmi_fast_download(ar, address, ar->firmware_data,
268 ath10k_err("could not write fw (%d)\n", ret);
276 static void ath10k_core_free_firmware_files(struct ath10k *ar)
278 if (ar->board && !IS_ERR(ar->board))
279 release_firmware(ar->board);
281 if (ar->otp && !IS_ERR(ar->otp))
282 release_firmware(ar->otp);
284 if (ar->firmware && !IS_ERR(ar->firmware))
285 release_firmware(ar->firmware);
288 ar->board_data = NULL;
296 ar->firmware_data = NULL;
297 ar->firmware_len = 0;
300 static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar)
304 if (ar->hw_params.fw.fw == NULL) {
305 ath10k_err("firmware file not defined\n");
309 if (ar->hw_params.fw.board == NULL) {
310 ath10k_err("board data file not defined");
314 ar->board = ath10k_fetch_fw_file(ar,
315 ar->hw_params.fw.dir,
316 ar->hw_params.fw.board);
317 if (IS_ERR(ar->board)) {
318 ret = PTR_ERR(ar->board);
319 ath10k_err("could not fetch board data (%d)\n", ret);
323 ar->board_data = ar->board->data;
324 ar->board_len = ar->board->size;
326 ar->firmware = ath10k_fetch_fw_file(ar,
327 ar->hw_params.fw.dir,
328 ar->hw_params.fw.fw);
329 if (IS_ERR(ar->firmware)) {
330 ret = PTR_ERR(ar->firmware);
331 ath10k_err("could not fetch firmware (%d)\n", ret);
335 ar->firmware_data = ar->firmware->data;
336 ar->firmware_len = ar->firmware->size;
338 /* OTP may be undefined. If so, don't fetch it at all */
339 if (ar->hw_params.fw.otp == NULL)
342 ar->otp = ath10k_fetch_fw_file(ar,
343 ar->hw_params.fw.dir,
344 ar->hw_params.fw.otp);
345 if (IS_ERR(ar->otp)) {
346 ret = PTR_ERR(ar->otp);
347 ath10k_err("could not fetch otp (%d)\n", ret);
351 ar->otp_data = ar->otp->data;
352 ar->otp_len = ar->otp->size;
357 ath10k_core_free_firmware_files(ar);
361 static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name)
363 size_t magic_len, len, ie_len;
364 int ie_id, i, index, bit, ret;
365 struct ath10k_fw_ie *hdr;
369 /* first fetch the firmware file (firmware-*.bin) */
370 ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name);
371 if (IS_ERR(ar->firmware)) {
372 ath10k_err("could not fetch firmware file '%s/%s': %ld\n",
373 ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware));
374 return PTR_ERR(ar->firmware);
377 data = ar->firmware->data;
378 len = ar->firmware->size;
380 /* magic also includes the null byte, check that as well */
381 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
383 if (len < magic_len) {
384 ath10k_err("firmware file '%s/%s' too small to contain magic: %zu\n",
385 ar->hw_params.fw.dir, name, len);
390 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
391 ath10k_err("invalid firmware magic\n");
396 /* jump over the padding */
397 magic_len = ALIGN(magic_len, 4);
403 while (len > sizeof(struct ath10k_fw_ie)) {
404 hdr = (struct ath10k_fw_ie *)data;
406 ie_id = le32_to_cpu(hdr->id);
407 ie_len = le32_to_cpu(hdr->len);
410 data += sizeof(*hdr);
413 ath10k_err("invalid length for FW IE %d (%zu < %zu)\n",
420 case ATH10K_FW_IE_FW_VERSION:
421 if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1)
424 memcpy(ar->hw->wiphy->fw_version, data, ie_len);
425 ar->hw->wiphy->fw_version[ie_len] = '\0';
427 ath10k_dbg(ATH10K_DBG_BOOT,
428 "found fw version %s\n",
429 ar->hw->wiphy->fw_version);
431 case ATH10K_FW_IE_TIMESTAMP:
432 if (ie_len != sizeof(u32))
435 timestamp = (__le32 *)data;
437 ath10k_dbg(ATH10K_DBG_BOOT, "found fw timestamp %d\n",
438 le32_to_cpup(timestamp));
440 case ATH10K_FW_IE_FEATURES:
441 ath10k_dbg(ATH10K_DBG_BOOT,
442 "found firmware features ie (%zd B)\n",
445 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
452 if (data[index] & (1 << bit)) {
453 ath10k_dbg(ATH10K_DBG_BOOT,
454 "Enabling feature bit: %i\n",
456 __set_bit(i, ar->fw_features);
460 ath10k_dbg_dump(ATH10K_DBG_BOOT, "features", "",
462 sizeof(ar->fw_features));
464 case ATH10K_FW_IE_FW_IMAGE:
465 ath10k_dbg(ATH10K_DBG_BOOT,
466 "found fw image ie (%zd B)\n",
469 ar->firmware_data = data;
470 ar->firmware_len = ie_len;
473 case ATH10K_FW_IE_OTP_IMAGE:
474 ath10k_dbg(ATH10K_DBG_BOOT,
475 "found otp image ie (%zd B)\n",
479 ar->otp_len = ie_len;
483 ath10k_warn("Unknown FW IE: %u\n",
484 le32_to_cpu(hdr->id));
488 /* jump over the padding */
489 ie_len = ALIGN(ie_len, 4);
495 if (!ar->firmware_data || !ar->firmware_len) {
496 ath10k_warn("No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
497 ar->hw_params.fw.dir, name);
502 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) &&
503 !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
504 ath10k_err("feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
509 /* now fetch the board file */
510 if (ar->hw_params.fw.board == NULL) {
511 ath10k_err("board data file not defined");
516 ar->board = ath10k_fetch_fw_file(ar,
517 ar->hw_params.fw.dir,
518 ar->hw_params.fw.board);
519 if (IS_ERR(ar->board)) {
520 ret = PTR_ERR(ar->board);
521 ath10k_err("could not fetch board data '%s/%s' (%d)\n",
522 ar->hw_params.fw.dir, ar->hw_params.fw.board,
527 ar->board_data = ar->board->data;
528 ar->board_len = ar->board->size;
533 ath10k_core_free_firmware_files(ar);
537 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
542 ath10k_dbg(ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
544 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE);
549 ath10k_dbg(ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
551 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE);
556 ath10k_dbg(ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
558 ret = ath10k_core_fetch_firmware_api_1(ar);
563 ath10k_dbg(ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
568 static int ath10k_init_download_firmware(struct ath10k *ar)
572 ret = ath10k_download_board_data(ar);
574 ath10k_err("failed to download board data: %d\n", ret);
578 ret = ath10k_download_and_run_otp(ar);
580 ath10k_err("failed to run otp: %d\n", ret);
584 ret = ath10k_download_fw(ar);
586 ath10k_err("failed to download firmware: %d\n", ret);
593 static int ath10k_init_uart(struct ath10k *ar)
598 * Explicitly setting UART prints to zero as target turns it on
599 * based on scratch registers.
601 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
603 ath10k_warn("could not disable UART prints (%d)\n", ret);
610 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, 7);
612 ath10k_warn("could not enable UART prints (%d)\n", ret);
616 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
618 ath10k_warn("could not enable UART prints (%d)\n", ret);
622 /* Set the UART baud rate to 19200. */
623 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
625 ath10k_warn("could not set the baud rate (%d)\n", ret);
629 ath10k_info("UART prints enabled\n");
633 static int ath10k_init_hw_params(struct ath10k *ar)
635 const struct ath10k_hw_params *uninitialized_var(hw_params);
638 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
639 hw_params = &ath10k_hw_params_list[i];
641 if (hw_params->id == ar->target_version)
645 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
646 ath10k_err("Unsupported hardware version: 0x%x\n",
651 ar->hw_params = *hw_params;
653 ath10k_dbg(ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
654 ar->hw_params.name, ar->target_version);
659 static void ath10k_core_restart(struct work_struct *work)
661 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
663 mutex_lock(&ar->conf_mutex);
666 case ATH10K_STATE_ON:
667 ar->state = ATH10K_STATE_RESTARTING;
668 ath10k_scan_finish(ar);
669 ieee80211_restart_hw(ar->hw);
671 case ATH10K_STATE_OFF:
672 /* this can happen if driver is being unloaded
673 * or if the crash happens during FW probing */
674 ath10k_warn("cannot restart a device that hasn't been started\n");
676 case ATH10K_STATE_RESTARTING:
677 /* hw restart might be requested from multiple places */
679 case ATH10K_STATE_RESTARTED:
680 ar->state = ATH10K_STATE_WEDGED;
682 case ATH10K_STATE_WEDGED:
683 ath10k_warn("device is wedged, will not restart\n");
687 mutex_unlock(&ar->conf_mutex);
690 int ath10k_core_start(struct ath10k *ar)
694 lockdep_assert_held(&ar->conf_mutex);
696 ath10k_bmi_start(ar);
698 if (ath10k_init_configure_target(ar)) {
703 status = ath10k_init_download_firmware(ar);
707 status = ath10k_init_uart(ar);
711 ar->htc.htc_ops.target_send_suspend_complete =
712 ath10k_send_suspend_complete;
714 status = ath10k_htc_init(ar);
716 ath10k_err("could not init HTC (%d)\n", status);
720 status = ath10k_bmi_done(ar);
724 status = ath10k_wmi_attach(ar);
726 ath10k_err("WMI attach failed: %d\n", status);
730 status = ath10k_htt_init(ar);
732 ath10k_err("failed to init htt: %d\n", status);
736 status = ath10k_htt_tx_alloc(&ar->htt);
738 ath10k_err("failed to alloc htt tx: %d\n", status);
742 status = ath10k_htt_rx_alloc(&ar->htt);
744 ath10k_err("failed to alloc htt rx: %d\n", status);
745 goto err_htt_tx_detach;
748 status = ath10k_hif_start(ar);
750 ath10k_err("could not start HIF: %d\n", status);
751 goto err_htt_rx_detach;
754 status = ath10k_htc_wait_target(&ar->htc);
756 ath10k_err("failed to connect to HTC: %d\n", status);
760 status = ath10k_htt_connect(&ar->htt);
762 ath10k_err("failed to connect htt (%d)\n", status);
766 status = ath10k_wmi_connect(ar);
768 ath10k_err("could not connect wmi: %d\n", status);
772 status = ath10k_htc_start(&ar->htc);
774 ath10k_err("failed to start htc: %d\n", status);
778 status = ath10k_wmi_wait_for_service_ready(ar);
780 ath10k_warn("wmi service ready event not received");
785 ath10k_dbg(ATH10K_DBG_BOOT, "firmware %s booted\n",
786 ar->hw->wiphy->fw_version);
788 status = ath10k_wmi_cmd_init(ar);
790 ath10k_err("could not send WMI init command (%d)\n", status);
794 status = ath10k_wmi_wait_for_unified_ready(ar);
796 ath10k_err("wmi unified ready event not received\n");
801 status = ath10k_htt_setup(&ar->htt);
803 ath10k_err("failed to setup htt: %d\n", status);
807 status = ath10k_debug_start(ar);
811 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
812 ar->free_vdev_map = (1 << TARGET_10X_NUM_VDEVS) - 1;
814 ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1;
816 INIT_LIST_HEAD(&ar->arvifs);
818 if (!test_bit(ATH10K_FLAG_FIRST_BOOT_DONE, &ar->dev_flags)) {
819 ath10k_info("%s (0x%08x, 0x%08x) fw %s api %d htt %d.%d\n",
823 ar->hw->wiphy->fw_version,
825 ar->htt.target_version_major,
826 ar->htt.target_version_minor);
827 ath10k_info("debug %d debugfs %d tracing %d dfs %d\n",
828 config_enabled(CONFIG_ATH10K_DEBUG),
829 config_enabled(CONFIG_ATH10K_DEBUGFS),
830 config_enabled(CONFIG_ATH10K_TRACING),
831 config_enabled(CONFIG_ATH10K_DFS_CERTIFIED));
834 __set_bit(ATH10K_FLAG_FIRST_BOOT_DONE, &ar->dev_flags);
839 ath10k_htc_stop(&ar->htc);
843 ath10k_htt_rx_free(&ar->htt);
845 ath10k_htt_tx_free(&ar->htt);
847 ath10k_wmi_detach(ar);
851 EXPORT_SYMBOL(ath10k_core_start);
853 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
857 reinit_completion(&ar->target_suspend);
859 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
861 ath10k_warn("could not suspend target (%d)\n", ret);
865 ret = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
868 ath10k_warn("suspend timed out - target pause event never came\n");
875 void ath10k_core_stop(struct ath10k *ar)
877 lockdep_assert_held(&ar->conf_mutex);
879 /* try to suspend target */
880 if (ar->state != ATH10K_STATE_RESTARTING)
881 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
883 ath10k_debug_stop(ar);
884 ath10k_htc_stop(&ar->htc);
886 ath10k_htt_tx_free(&ar->htt);
887 ath10k_htt_rx_free(&ar->htt);
888 ath10k_wmi_detach(ar);
890 EXPORT_SYMBOL(ath10k_core_stop);
892 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
893 * order to know what hw capabilities should be advertised to mac80211 it is
894 * necessary to load the firmware (and tear it down immediately since start
895 * hook will try to init it again) before registering */
896 static int ath10k_core_probe_fw(struct ath10k *ar)
898 struct bmi_target_info target_info;
901 ret = ath10k_hif_power_up(ar);
903 ath10k_err("could not start pci hif (%d)\n", ret);
907 memset(&target_info, 0, sizeof(target_info));
908 ret = ath10k_bmi_get_target_info(ar, &target_info);
910 ath10k_err("could not get target info (%d)\n", ret);
911 ath10k_hif_power_down(ar);
915 ar->target_version = target_info.version;
916 ar->hw->wiphy->hw_version = target_info.version;
918 ret = ath10k_init_hw_params(ar);
920 ath10k_err("could not get hw params (%d)\n", ret);
921 ath10k_hif_power_down(ar);
925 ret = ath10k_core_fetch_firmware_files(ar);
927 ath10k_err("could not fetch firmware files (%d)\n", ret);
928 ath10k_hif_power_down(ar);
932 mutex_lock(&ar->conf_mutex);
934 ret = ath10k_core_start(ar);
936 ath10k_err("could not init core (%d)\n", ret);
937 ath10k_core_free_firmware_files(ar);
938 ath10k_hif_power_down(ar);
939 mutex_unlock(&ar->conf_mutex);
943 ath10k_core_stop(ar);
945 mutex_unlock(&ar->conf_mutex);
947 ath10k_hif_power_down(ar);
951 static int ath10k_core_check_chip_id(struct ath10k *ar)
953 u32 hw_revision = MS(ar->chip_id, SOC_CHIP_ID_REV);
955 ath10k_dbg(ATH10K_DBG_BOOT, "boot chip_id 0x%08x hw_revision 0x%x\n",
956 ar->chip_id, hw_revision);
958 /* Check that we are not using hw1.0 (some of them have same pci id
959 * as hw2.0) before doing anything else as ath10k crashes horribly
960 * due to missing hw1.0 workarounds. */
961 switch (hw_revision) {
962 case QCA988X_HW_1_0_CHIP_ID_REV:
963 ath10k_err("ERROR: qca988x hw1.0 is not supported\n");
966 case QCA988X_HW_2_0_CHIP_ID_REV:
967 /* known hardware revision, continue normally */
971 ath10k_warn("Warning: hardware revision unknown (0x%x), expect problems\n",
979 static void ath10k_core_register_work(struct work_struct *work)
981 struct ath10k *ar = container_of(work, struct ath10k, register_work);
984 status = ath10k_core_probe_fw(ar);
986 ath10k_err("could not probe fw (%d)\n", status);
990 status = ath10k_mac_register(ar);
992 ath10k_err("could not register to mac80211 (%d)\n", status);
996 status = ath10k_debug_create(ar);
998 ath10k_err("unable to initialize debugfs\n");
999 goto err_unregister_mac;
1002 status = ath10k_spectral_create(ar);
1004 ath10k_err("failed to initialize spectral\n");
1005 goto err_debug_destroy;
1008 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
1012 ath10k_debug_destroy(ar);
1014 ath10k_mac_unregister(ar);
1016 ath10k_core_free_firmware_files(ar);
1018 /* TODO: It's probably a good idea to release device from the driver
1019 * but calling device_release_driver() here will cause a deadlock.
1024 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1028 ar->chip_id = chip_id;
1030 status = ath10k_core_check_chip_id(ar);
1032 ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id);
1036 queue_work(ar->workqueue, &ar->register_work);
1040 EXPORT_SYMBOL(ath10k_core_register);
1042 void ath10k_core_unregister(struct ath10k *ar)
1044 cancel_work_sync(&ar->register_work);
1046 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1049 /* We must unregister from mac80211 before we stop HTC and HIF.
1050 * Otherwise we will fail to submit commands to FW and mac80211 will be
1051 * unhappy about callback failures. */
1052 ath10k_mac_unregister(ar);
1054 ath10k_core_free_firmware_files(ar);
1056 ath10k_spectral_destroy(ar);
1058 ath10k_debug_destroy(ar);
1060 EXPORT_SYMBOL(ath10k_core_unregister);
1062 struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
1063 const struct ath10k_hif_ops *hif_ops)
1067 ar = ath10k_mac_create();
1071 ar->ath_common.priv = ar;
1072 ar->ath_common.hw = ar->hw;
1074 ar->p2p = !!ath10k_p2p;
1077 ar->hif.priv = hif_priv;
1078 ar->hif.ops = hif_ops;
1080 init_completion(&ar->scan.started);
1081 init_completion(&ar->scan.completed);
1082 init_completion(&ar->scan.on_channel);
1083 init_completion(&ar->target_suspend);
1085 init_completion(&ar->install_key_done);
1086 init_completion(&ar->vdev_setup_done);
1088 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
1090 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1094 mutex_init(&ar->conf_mutex);
1095 spin_lock_init(&ar->data_lock);
1097 INIT_LIST_HEAD(&ar->peers);
1098 init_waitqueue_head(&ar->peer_mapping_wq);
1100 init_completion(&ar->offchan_tx_completed);
1101 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1102 skb_queue_head_init(&ar->offchan_tx_queue);
1104 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1105 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1107 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1108 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1113 ath10k_mac_destroy(ar);
1116 EXPORT_SYMBOL(ath10k_core_create);
1118 void ath10k_core_destroy(struct ath10k *ar)
1120 flush_workqueue(ar->workqueue);
1121 destroy_workqueue(ar->workqueue);
1123 ath10k_mac_destroy(ar);
1125 EXPORT_SYMBOL(ath10k_core_destroy);
1127 MODULE_AUTHOR("Qualcomm Atheros");
1128 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1129 MODULE_LICENSE("Dual BSD/GPL");