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_1_0_VERSION,
43 .name = "qca988x hw1.0",
44 .patch_load_addr = QCA988X_HW_1_0_PATCH_LOAD_ADDR,
46 .dir = QCA988X_HW_1_0_FW_DIR,
47 .fw = QCA988X_HW_1_0_FW_FILE,
48 .otp = QCA988X_HW_1_0_OTP_FILE,
49 .board = QCA988X_HW_1_0_BOARD_DATA_FILE,
53 .id = QCA988X_HW_2_0_VERSION,
54 .name = "qca988x hw2.0",
55 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
57 .dir = QCA988X_HW_2_0_FW_DIR,
58 .fw = QCA988X_HW_2_0_FW_FILE,
59 .otp = QCA988X_HW_2_0_OTP_FILE,
60 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
65 static void ath10k_send_suspend_complete(struct ath10k *ar)
67 ath10k_dbg(ATH10K_DBG_CORE, "%s\n", __func__);
69 ar->is_target_paused = true;
70 wake_up(&ar->event_queue);
73 static int ath10k_check_fw_version(struct ath10k *ar)
77 if (ar->fw_version_major >= SUPPORTED_FW_MAJOR &&
78 ar->fw_version_minor >= SUPPORTED_FW_MINOR &&
79 ar->fw_version_release >= SUPPORTED_FW_RELEASE &&
80 ar->fw_version_build >= SUPPORTED_FW_BUILD)
83 snprintf(version, sizeof(version), "%u.%u.%u.%u",
84 SUPPORTED_FW_MAJOR, SUPPORTED_FW_MINOR,
85 SUPPORTED_FW_RELEASE, SUPPORTED_FW_BUILD);
87 ath10k_warn("WARNING: Firmware version %s is not officially supported.\n",
88 ar->hw->wiphy->fw_version);
89 ath10k_warn("Please upgrade to version %s (or newer)\n", version);
94 static int ath10k_init_connect_htc(struct ath10k *ar)
98 status = ath10k_wmi_connect_htc_service(ar);
103 status = ath10k_htc_start(ar->htc);
107 /* Wait for WMI event to be ready */
108 status = ath10k_wmi_wait_for_service_ready(ar);
110 ath10k_warn("wmi service ready event not received");
115 ath10k_dbg(ATH10K_DBG_CORE, "core wmi ready\n");
119 ath10k_htc_stop(ar->htc);
124 static int ath10k_init_configure_target(struct ath10k *ar)
129 /* tell target which HTC version it is used*/
130 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
131 HTC_PROTOCOL_VERSION);
133 ath10k_err("settings HTC version failed\n");
137 /* set the firmware mode to STA/IBSS/AP */
138 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
140 ath10k_err("setting firmware mode (1/2) failed\n");
144 /* TODO following parameters need to be re-visited. */
146 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
148 /* FIXME: Why FW_MODE_AP ??.*/
149 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
150 /* mac_addr_method */
151 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
152 /* firmware_bridge */
153 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
155 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
157 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
159 ath10k_err("setting firmware mode (2/2) failed\n");
163 /* We do all byte-swapping on the host */
164 ret = ath10k_bmi_write32(ar, hi_be, 0);
166 ath10k_err("setting host CPU BE mode failed\n");
170 /* FW descriptor/Data swap flags */
171 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
174 ath10k_err("setting FW data/desc swap flags failed\n");
181 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
186 const struct firmware *fw;
190 return ERR_PTR(-ENOENT);
195 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
196 ret = request_firmware(&fw, filename, ar->dev);
203 static int ath10k_push_board_ext_data(struct ath10k *ar,
204 const struct firmware *fw)
206 u32 board_data_size = QCA988X_BOARD_DATA_SZ;
207 u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ;
208 u32 board_ext_data_addr;
211 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
213 ath10k_err("could not read board ext data addr (%d)\n", ret);
217 ath10k_dbg(ATH10K_DBG_CORE,
218 "ath10k: Board extended Data download addr: 0x%x\n",
219 board_ext_data_addr);
221 if (board_ext_data_addr == 0)
224 if (fw->size != (board_data_size + board_ext_data_size)) {
225 ath10k_err("invalid board (ext) data sizes %zu != %d+%d\n",
226 fw->size, board_data_size, board_ext_data_size);
230 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
231 fw->data + board_data_size,
232 board_ext_data_size);
234 ath10k_err("could not write board ext data (%d)\n", ret);
238 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
239 (board_ext_data_size << 16) | 1);
241 ath10k_err("could not write board ext data bit (%d)\n", ret);
248 static int ath10k_download_board_data(struct ath10k *ar)
250 u32 board_data_size = QCA988X_BOARD_DATA_SZ;
252 const struct firmware *fw;
255 fw = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
256 ar->hw_params.fw.board);
258 ath10k_err("could not fetch board data fw file (%ld)\n",
263 ret = ath10k_push_board_ext_data(ar, fw);
265 ath10k_err("could not push board ext data (%d)\n", ret);
269 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
271 ath10k_err("could not read board data addr (%d)\n", ret);
275 ret = ath10k_bmi_write_memory(ar, address, fw->data,
276 min_t(u32, board_data_size, fw->size));
278 ath10k_err("could not write board data (%d)\n", ret);
282 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
284 ath10k_err("could not write board data bit (%d)\n", ret);
289 release_firmware(fw);
293 static int ath10k_download_and_run_otp(struct ath10k *ar)
295 const struct firmware *fw;
300 /* OTP is optional */
302 if (ar->hw_params.fw.otp == NULL) {
303 ath10k_info("otp file not defined\n");
307 address = ar->hw_params.patch_load_addr;
309 fw = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
310 ar->hw_params.fw.otp);
312 ath10k_warn("could not fetch otp (%ld)\n", PTR_ERR(fw));
316 ret = ath10k_bmi_fast_download(ar, address, fw->data, fw->size);
318 ath10k_err("could not write otp (%d)\n", ret);
323 ret = ath10k_bmi_execute(ar, address, &exec_param);
325 ath10k_err("could not execute otp (%d)\n", ret);
330 release_firmware(fw);
334 static int ath10k_download_fw(struct ath10k *ar)
336 const struct firmware *fw;
340 if (ar->hw_params.fw.fw == NULL)
343 address = ar->hw_params.patch_load_addr;
345 fw = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
346 ar->hw_params.fw.fw);
348 ath10k_err("could not fetch fw (%ld)\n", PTR_ERR(fw));
352 ret = ath10k_bmi_fast_download(ar, address, fw->data, fw->size);
354 ath10k_err("could not write fw (%d)\n", ret);
359 release_firmware(fw);
363 static int ath10k_init_download_firmware(struct ath10k *ar)
367 ret = ath10k_download_board_data(ar);
371 ret = ath10k_download_and_run_otp(ar);
375 ret = ath10k_download_fw(ar);
382 static int ath10k_init_uart(struct ath10k *ar)
387 * Explicitly setting UART prints to zero as target turns it on
388 * based on scratch registers.
390 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
392 ath10k_warn("could not disable UART prints (%d)\n", ret);
397 ath10k_info("UART prints disabled\n");
401 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, 7);
403 ath10k_warn("could not enable UART prints (%d)\n", ret);
407 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
409 ath10k_warn("could not enable UART prints (%d)\n", ret);
413 ath10k_info("UART prints enabled\n");
417 static int ath10k_init_hw_params(struct ath10k *ar)
419 const struct ath10k_hw_params *uninitialized_var(hw_params);
422 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
423 hw_params = &ath10k_hw_params_list[i];
425 if (hw_params->id == ar->target_version)
429 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
430 ath10k_err("Unsupported hardware version: 0x%x\n",
435 ar->hw_params = *hw_params;
437 ath10k_info("Hardware name %s version 0x%x\n",
438 ar->hw_params.name, ar->target_version);
443 struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
445 const struct ath10k_hif_ops *hif_ops)
449 ar = ath10k_mac_create();
453 ar->ath_common.priv = ar;
454 ar->ath_common.hw = ar->hw;
456 ar->p2p = !!ath10k_p2p;
459 ar->hif.priv = hif_priv;
460 ar->hif.ops = hif_ops;
463 ar->free_vdev_map = 0xFF; /* 8 vdevs */
465 init_completion(&ar->scan.started);
466 init_completion(&ar->scan.completed);
467 init_completion(&ar->scan.on_channel);
469 init_completion(&ar->install_key_done);
470 init_completion(&ar->vdev_setup_done);
472 setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar);
474 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
478 mutex_init(&ar->conf_mutex);
479 spin_lock_init(&ar->data_lock);
481 INIT_LIST_HEAD(&ar->peers);
482 init_waitqueue_head(&ar->peer_mapping_wq);
484 init_completion(&ar->offchan_tx_completed);
485 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
486 skb_queue_head_init(&ar->offchan_tx_queue);
488 init_waitqueue_head(&ar->event_queue);
493 ath10k_mac_destroy(ar);
496 EXPORT_SYMBOL(ath10k_core_create);
498 void ath10k_core_destroy(struct ath10k *ar)
500 flush_workqueue(ar->workqueue);
501 destroy_workqueue(ar->workqueue);
503 ath10k_mac_destroy(ar);
505 EXPORT_SYMBOL(ath10k_core_destroy);
508 int ath10k_core_register(struct ath10k *ar)
510 struct ath10k_htc_ops htc_ops;
511 struct bmi_target_info target_info;
514 memset(&target_info, 0, sizeof(target_info));
515 status = ath10k_bmi_get_target_info(ar, &target_info);
519 ar->target_version = target_info.version;
520 ar->hw->wiphy->hw_version = target_info.version;
522 status = ath10k_init_hw_params(ar);
526 if (ath10k_init_configure_target(ar)) {
531 status = ath10k_init_download_firmware(ar);
535 status = ath10k_init_uart(ar);
539 htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
541 ar->htc = ath10k_htc_create(ar, &htc_ops);
542 if (IS_ERR(ar->htc)) {
543 status = PTR_ERR(ar->htc);
544 ath10k_err("could not create HTC (%d)\n", status);
548 status = ath10k_bmi_done(ar);
550 goto err_htc_destroy;
552 status = ath10k_wmi_attach(ar);
554 ath10k_err("WMI attach failed: %d\n", status);
555 goto err_htc_destroy;
558 status = ath10k_htc_wait_target(ar->htc);
562 ar->htt = ath10k_htt_attach(ar);
568 status = ath10k_init_connect_htc(ar);
572 ath10k_info("firmware %s booted\n", ar->hw->wiphy->fw_version);
574 status = ath10k_check_fw_version(ar);
576 goto err_disconnect_htc;
578 status = ath10k_wmi_cmd_init(ar);
580 ath10k_err("could not send WMI init command (%d)\n", status);
581 goto err_disconnect_htc;
584 status = ath10k_wmi_wait_for_unified_ready(ar);
586 ath10k_err("wmi unified ready event not received\n");
588 goto err_disconnect_htc;
591 status = ath10k_htt_attach_target(ar->htt);
593 goto err_disconnect_htc;
595 status = ath10k_mac_register(ar);
597 goto err_disconnect_htc;
599 status = ath10k_debug_create(ar);
601 ath10k_err("unable to initialize debugfs\n");
602 goto err_unregister_mac;
608 ath10k_mac_unregister(ar);
610 ath10k_htc_stop(ar->htc);
612 ath10k_htt_detach(ar->htt);
614 ath10k_wmi_detach(ar);
616 ath10k_htc_destroy(ar->htc);
620 EXPORT_SYMBOL(ath10k_core_register);
622 void ath10k_core_unregister(struct ath10k *ar)
624 /* We must unregister from mac80211 before we stop HTC and HIF.
625 * Otherwise we will fail to submit commands to FW and mac80211 will be
626 * unhappy about callback failures. */
627 ath10k_mac_unregister(ar);
628 ath10k_htc_stop(ar->htc);
629 ath10k_htt_detach(ar->htt);
630 ath10k_wmi_detach(ar);
631 ath10k_htc_destroy(ar->htc);
633 EXPORT_SYMBOL(ath10k_core_unregister);
635 int ath10k_core_target_suspend(struct ath10k *ar)
639 ath10k_dbg(ATH10K_DBG_CORE, "%s: called", __func__);
641 ret = ath10k_wmi_pdev_suspend_target(ar);
643 ath10k_warn("could not suspend target (%d)\n", ret);
647 EXPORT_SYMBOL(ath10k_core_target_suspend);
649 int ath10k_core_target_resume(struct ath10k *ar)
653 ath10k_dbg(ATH10K_DBG_CORE, "%s: called", __func__);
655 ret = ath10k_wmi_pdev_resume_target(ar);
657 ath10k_warn("could not resume target (%d)\n", ret);
661 EXPORT_SYMBOL(ath10k_core_target_resume);
663 MODULE_AUTHOR("Qualcomm Atheros");
664 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
665 MODULE_LICENSE("Dual BSD/GPL");