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>
31 unsigned int ath10k_debug_mask
;
32 static bool uart_print
;
33 static unsigned int ath10k_p2p
;
34 module_param_named(debug_mask
, ath10k_debug_mask
, uint
, 0644);
35 module_param(uart_print
, bool, 0644);
36 module_param_named(p2p
, ath10k_p2p
, uint
, 0644);
37 MODULE_PARM_DESC(debug_mask
, "Debugging mask");
38 MODULE_PARM_DESC(uart_print
, "Uart target debugging");
39 MODULE_PARM_DESC(p2p
, "Enable ath10k P2P support");
41 static const struct ath10k_hw_params ath10k_hw_params_list
[] = {
43 .id
= QCA988X_HW_2_0_VERSION
,
44 .name
= "qca988x hw2.0",
45 .patch_load_addr
= QCA988X_HW_2_0_PATCH_LOAD_ADDR
,
47 .dir
= QCA988X_HW_2_0_FW_DIR
,
48 .fw
= QCA988X_HW_2_0_FW_FILE
,
49 .otp
= QCA988X_HW_2_0_OTP_FILE
,
50 .board
= QCA988X_HW_2_0_BOARD_DATA_FILE
,
55 static void ath10k_send_suspend_complete(struct ath10k
*ar
)
57 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot suspend complete\n");
59 complete(&ar
->target_suspend
);
62 static int ath10k_init_configure_target(struct ath10k
*ar
)
67 /* tell target which HTC version it is used*/
68 ret
= ath10k_bmi_write32(ar
, hi_app_host_interest
,
69 HTC_PROTOCOL_VERSION
);
71 ath10k_err(ar
, "settings HTC version failed\n");
75 /* set the firmware mode to STA/IBSS/AP */
76 ret
= ath10k_bmi_read32(ar
, hi_option_flag
, ¶m_host
);
78 ath10k_err(ar
, "setting firmware mode (1/2) failed\n");
82 /* TODO following parameters need to be re-visited. */
84 param_host
|= (1 << HI_OPTION_NUM_DEV_SHIFT
);
86 /* FIXME: Why FW_MODE_AP ??.*/
87 param_host
|= (HI_OPTION_FW_MODE_AP
<< HI_OPTION_FW_MODE_SHIFT
);
89 param_host
|= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT
);
91 param_host
|= (0 << HI_OPTION_FW_BRIDGE_SHIFT
);
93 param_host
|= (0 << HI_OPTION_FW_SUBMODE_SHIFT
);
95 ret
= ath10k_bmi_write32(ar
, hi_option_flag
, param_host
);
97 ath10k_err(ar
, "setting firmware mode (2/2) failed\n");
101 /* We do all byte-swapping on the host */
102 ret
= ath10k_bmi_write32(ar
, hi_be
, 0);
104 ath10k_err(ar
, "setting host CPU BE mode failed\n");
108 /* FW descriptor/Data swap flags */
109 ret
= ath10k_bmi_write32(ar
, hi_fw_swap
, 0);
112 ath10k_err(ar
, "setting FW data/desc swap flags failed\n");
119 static const struct firmware
*ath10k_fetch_fw_file(struct ath10k
*ar
,
124 const struct firmware
*fw
;
128 return ERR_PTR(-ENOENT
);
133 snprintf(filename
, sizeof(filename
), "%s/%s", dir
, file
);
134 ret
= request_firmware(&fw
, filename
, ar
->dev
);
141 static int ath10k_push_board_ext_data(struct ath10k
*ar
)
143 u32 board_data_size
= QCA988X_BOARD_DATA_SZ
;
144 u32 board_ext_data_size
= QCA988X_BOARD_EXT_DATA_SZ
;
145 u32 board_ext_data_addr
;
148 ret
= ath10k_bmi_read32(ar
, hi_board_ext_data
, &board_ext_data_addr
);
150 ath10k_err(ar
, "could not read board ext data addr (%d)\n",
155 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
156 "boot push board extended data addr 0x%x\n",
157 board_ext_data_addr
);
159 if (board_ext_data_addr
== 0)
162 if (ar
->board_len
!= (board_data_size
+ board_ext_data_size
)) {
163 ath10k_err(ar
, "invalid board (ext) data sizes %zu != %d+%d\n",
164 ar
->board_len
, board_data_size
, board_ext_data_size
);
168 ret
= ath10k_bmi_write_memory(ar
, board_ext_data_addr
,
169 ar
->board_data
+ board_data_size
,
170 board_ext_data_size
);
172 ath10k_err(ar
, "could not write board ext data (%d)\n", ret
);
176 ret
= ath10k_bmi_write32(ar
, hi_board_ext_data_config
,
177 (board_ext_data_size
<< 16) | 1);
179 ath10k_err(ar
, "could not write board ext data bit (%d)\n",
187 static int ath10k_download_board_data(struct ath10k
*ar
)
189 u32 board_data_size
= QCA988X_BOARD_DATA_SZ
;
193 ret
= ath10k_push_board_ext_data(ar
);
195 ath10k_err(ar
, "could not push board ext data (%d)\n", ret
);
199 ret
= ath10k_bmi_read32(ar
, hi_board_data
, &address
);
201 ath10k_err(ar
, "could not read board data addr (%d)\n", ret
);
205 ret
= ath10k_bmi_write_memory(ar
, address
, ar
->board_data
,
206 min_t(u32
, board_data_size
,
209 ath10k_err(ar
, "could not write board data (%d)\n", ret
);
213 ret
= ath10k_bmi_write32(ar
, hi_board_data_initialized
, 1);
215 ath10k_err(ar
, "could not write board data bit (%d)\n", ret
);
223 static int ath10k_download_and_run_otp(struct ath10k
*ar
)
225 u32 result
, address
= ar
->hw_params
.patch_load_addr
;
228 /* OTP is optional */
230 if (!ar
->otp_data
|| !ar
->otp_len
) {
231 ath10k_warn(ar
, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
232 ar
->otp_data
, ar
->otp_len
);
236 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot upload otp to 0x%x len %zd\n",
237 address
, ar
->otp_len
);
239 ret
= ath10k_bmi_fast_download(ar
, address
, ar
->otp_data
, ar
->otp_len
);
241 ath10k_err(ar
, "could not write otp (%d)\n", ret
);
245 ret
= ath10k_bmi_execute(ar
, address
, 0, &result
);
247 ath10k_err(ar
, "could not execute otp (%d)\n", ret
);
251 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot otp execute result %d\n", result
);
254 ath10k_err(ar
, "otp calibration failed: %d", result
);
261 static int ath10k_download_fw(struct ath10k
*ar
, enum ath10k_firmware_mode mode
)
263 u32 address
, data_len
;
264 const char *mode_name
;
268 address
= ar
->hw_params
.patch_load_addr
;
271 case ATH10K_FIRMWARE_MODE_NORMAL
:
272 data
= ar
->firmware_data
;
273 data_len
= ar
->firmware_len
;
274 mode_name
= "normal";
276 case ATH10K_FIRMWARE_MODE_UTF
:
277 data
= ar
->testmode
.utf
->data
;
278 data_len
= ar
->testmode
.utf
->size
;
282 ath10k_err(ar
, "unknown firmware mode: %d\n", mode
);
286 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
287 "boot uploading firmware image %p len %d mode %s\n",
288 data
, data_len
, mode_name
);
290 ret
= ath10k_bmi_fast_download(ar
, address
, data
, data_len
);
292 ath10k_err(ar
, "failed to download %s firmware: %d\n",
300 static void ath10k_core_free_firmware_files(struct ath10k
*ar
)
302 if (ar
->board
&& !IS_ERR(ar
->board
))
303 release_firmware(ar
->board
);
305 if (ar
->otp
&& !IS_ERR(ar
->otp
))
306 release_firmware(ar
->otp
);
308 if (ar
->firmware
&& !IS_ERR(ar
->firmware
))
309 release_firmware(ar
->firmware
);
312 ar
->board_data
= NULL
;
320 ar
->firmware_data
= NULL
;
321 ar
->firmware_len
= 0;
324 static int ath10k_core_fetch_firmware_api_1(struct ath10k
*ar
)
328 if (ar
->hw_params
.fw
.fw
== NULL
) {
329 ath10k_err(ar
, "firmware file not defined\n");
333 if (ar
->hw_params
.fw
.board
== NULL
) {
334 ath10k_err(ar
, "board data file not defined");
338 ar
->board
= ath10k_fetch_fw_file(ar
,
339 ar
->hw_params
.fw
.dir
,
340 ar
->hw_params
.fw
.board
);
341 if (IS_ERR(ar
->board
)) {
342 ret
= PTR_ERR(ar
->board
);
343 ath10k_err(ar
, "could not fetch board data (%d)\n", ret
);
347 ar
->board_data
= ar
->board
->data
;
348 ar
->board_len
= ar
->board
->size
;
350 ar
->firmware
= ath10k_fetch_fw_file(ar
,
351 ar
->hw_params
.fw
.dir
,
352 ar
->hw_params
.fw
.fw
);
353 if (IS_ERR(ar
->firmware
)) {
354 ret
= PTR_ERR(ar
->firmware
);
355 ath10k_err(ar
, "could not fetch firmware (%d)\n", ret
);
359 ar
->firmware_data
= ar
->firmware
->data
;
360 ar
->firmware_len
= ar
->firmware
->size
;
362 /* OTP may be undefined. If so, don't fetch it at all */
363 if (ar
->hw_params
.fw
.otp
== NULL
)
366 ar
->otp
= ath10k_fetch_fw_file(ar
,
367 ar
->hw_params
.fw
.dir
,
368 ar
->hw_params
.fw
.otp
);
369 if (IS_ERR(ar
->otp
)) {
370 ret
= PTR_ERR(ar
->otp
);
371 ath10k_err(ar
, "could not fetch otp (%d)\n", ret
);
375 ar
->otp_data
= ar
->otp
->data
;
376 ar
->otp_len
= ar
->otp
->size
;
381 ath10k_core_free_firmware_files(ar
);
385 static int ath10k_core_fetch_firmware_api_n(struct ath10k
*ar
, const char *name
)
387 size_t magic_len
, len
, ie_len
;
388 int ie_id
, i
, index
, bit
, ret
;
389 struct ath10k_fw_ie
*hdr
;
393 /* first fetch the firmware file (firmware-*.bin) */
394 ar
->firmware
= ath10k_fetch_fw_file(ar
, ar
->hw_params
.fw
.dir
, name
);
395 if (IS_ERR(ar
->firmware
)) {
396 ath10k_err(ar
, "could not fetch firmware file '%s/%s': %ld\n",
397 ar
->hw_params
.fw
.dir
, name
, PTR_ERR(ar
->firmware
));
398 return PTR_ERR(ar
->firmware
);
401 data
= ar
->firmware
->data
;
402 len
= ar
->firmware
->size
;
404 /* magic also includes the null byte, check that as well */
405 magic_len
= strlen(ATH10K_FIRMWARE_MAGIC
) + 1;
407 if (len
< magic_len
) {
408 ath10k_err(ar
, "firmware file '%s/%s' too small to contain magic: %zu\n",
409 ar
->hw_params
.fw
.dir
, name
, len
);
414 if (memcmp(data
, ATH10K_FIRMWARE_MAGIC
, magic_len
) != 0) {
415 ath10k_err(ar
, "invalid firmware magic\n");
420 /* jump over the padding */
421 magic_len
= ALIGN(magic_len
, 4);
427 while (len
> sizeof(struct ath10k_fw_ie
)) {
428 hdr
= (struct ath10k_fw_ie
*)data
;
430 ie_id
= le32_to_cpu(hdr
->id
);
431 ie_len
= le32_to_cpu(hdr
->len
);
434 data
+= sizeof(*hdr
);
437 ath10k_err(ar
, "invalid length for FW IE %d (%zu < %zu)\n",
444 case ATH10K_FW_IE_FW_VERSION
:
445 if (ie_len
> sizeof(ar
->hw
->wiphy
->fw_version
) - 1)
448 memcpy(ar
->hw
->wiphy
->fw_version
, data
, ie_len
);
449 ar
->hw
->wiphy
->fw_version
[ie_len
] = '\0';
451 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
452 "found fw version %s\n",
453 ar
->hw
->wiphy
->fw_version
);
455 case ATH10K_FW_IE_TIMESTAMP
:
456 if (ie_len
!= sizeof(u32
))
459 timestamp
= (__le32
*)data
;
461 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw timestamp %d\n",
462 le32_to_cpup(timestamp
));
464 case ATH10K_FW_IE_FEATURES
:
465 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
466 "found firmware features ie (%zd B)\n",
469 for (i
= 0; i
< ATH10K_FW_FEATURE_COUNT
; i
++) {
476 if (data
[index
] & (1 << bit
)) {
477 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
478 "Enabling feature bit: %i\n",
480 __set_bit(i
, ar
->fw_features
);
484 ath10k_dbg_dump(ar
, ATH10K_DBG_BOOT
, "features", "",
486 sizeof(ar
->fw_features
));
488 case ATH10K_FW_IE_FW_IMAGE
:
489 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
490 "found fw image ie (%zd B)\n",
493 ar
->firmware_data
= data
;
494 ar
->firmware_len
= ie_len
;
497 case ATH10K_FW_IE_OTP_IMAGE
:
498 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
499 "found otp image ie (%zd B)\n",
503 ar
->otp_len
= ie_len
;
507 ath10k_warn(ar
, "Unknown FW IE: %u\n",
508 le32_to_cpu(hdr
->id
));
512 /* jump over the padding */
513 ie_len
= ALIGN(ie_len
, 4);
519 if (!ar
->firmware_data
|| !ar
->firmware_len
) {
520 ath10k_warn(ar
, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
521 ar
->hw_params
.fw
.dir
, name
);
526 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2
, ar
->fw_features
) &&
527 !test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
528 ath10k_err(ar
, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
533 /* now fetch the board file */
534 if (ar
->hw_params
.fw
.board
== NULL
) {
535 ath10k_err(ar
, "board data file not defined");
540 ar
->board
= ath10k_fetch_fw_file(ar
,
541 ar
->hw_params
.fw
.dir
,
542 ar
->hw_params
.fw
.board
);
543 if (IS_ERR(ar
->board
)) {
544 ret
= PTR_ERR(ar
->board
);
545 ath10k_err(ar
, "could not fetch board data '%s/%s' (%d)\n",
546 ar
->hw_params
.fw
.dir
, ar
->hw_params
.fw
.board
,
551 ar
->board_data
= ar
->board
->data
;
552 ar
->board_len
= ar
->board
->size
;
557 ath10k_core_free_firmware_files(ar
);
561 static int ath10k_core_fetch_firmware_files(struct ath10k
*ar
)
566 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
568 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API3_FILE
);
573 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
575 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API2_FILE
);
580 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
582 ret
= ath10k_core_fetch_firmware_api_1(ar
);
587 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "using fw api %d\n", ar
->fw_api
);
592 static int ath10k_init_download_firmware(struct ath10k
*ar
,
593 enum ath10k_firmware_mode mode
)
597 ret
= ath10k_download_board_data(ar
);
599 ath10k_err(ar
, "failed to download board data: %d\n", ret
);
603 ret
= ath10k_download_and_run_otp(ar
);
605 ath10k_err(ar
, "failed to run otp: %d\n", ret
);
609 ret
= ath10k_download_fw(ar
, mode
);
611 ath10k_err(ar
, "failed to download firmware: %d\n", ret
);
618 static int ath10k_init_uart(struct ath10k
*ar
)
623 * Explicitly setting UART prints to zero as target turns it on
624 * based on scratch registers.
626 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 0);
628 ath10k_warn(ar
, "could not disable UART prints (%d)\n", ret
);
635 ret
= ath10k_bmi_write32(ar
, hi_dbg_uart_txpin
, 7);
637 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
641 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 1);
643 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
647 /* Set the UART baud rate to 19200. */
648 ret
= ath10k_bmi_write32(ar
, hi_desired_baud_rate
, 19200);
650 ath10k_warn(ar
, "could not set the baud rate (%d)\n", ret
);
654 ath10k_info(ar
, "UART prints enabled\n");
658 static int ath10k_init_hw_params(struct ath10k
*ar
)
660 const struct ath10k_hw_params
*uninitialized_var(hw_params
);
663 for (i
= 0; i
< ARRAY_SIZE(ath10k_hw_params_list
); i
++) {
664 hw_params
= &ath10k_hw_params_list
[i
];
666 if (hw_params
->id
== ar
->target_version
)
670 if (i
== ARRAY_SIZE(ath10k_hw_params_list
)) {
671 ath10k_err(ar
, "Unsupported hardware version: 0x%x\n",
676 ar
->hw_params
= *hw_params
;
678 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "Hardware name %s version 0x%x\n",
679 ar
->hw_params
.name
, ar
->target_version
);
684 static void ath10k_core_restart(struct work_struct
*work
)
686 struct ath10k
*ar
= container_of(work
, struct ath10k
, restart_work
);
688 mutex_lock(&ar
->conf_mutex
);
691 case ATH10K_STATE_ON
:
692 ar
->state
= ATH10K_STATE_RESTARTING
;
694 ath10k_scan_finish(ar
);
695 ieee80211_restart_hw(ar
->hw
);
697 case ATH10K_STATE_OFF
:
698 /* this can happen if driver is being unloaded
699 * or if the crash happens during FW probing */
700 ath10k_warn(ar
, "cannot restart a device that hasn't been started\n");
702 case ATH10K_STATE_RESTARTING
:
703 /* hw restart might be requested from multiple places */
705 case ATH10K_STATE_RESTARTED
:
706 ar
->state
= ATH10K_STATE_WEDGED
;
708 case ATH10K_STATE_WEDGED
:
709 ath10k_warn(ar
, "device is wedged, will not restart\n");
711 case ATH10K_STATE_UTF
:
712 ath10k_warn(ar
, "firmware restart in UTF mode not supported\n");
716 mutex_unlock(&ar
->conf_mutex
);
719 int ath10k_core_start(struct ath10k
*ar
, enum ath10k_firmware_mode mode
)
723 lockdep_assert_held(&ar
->conf_mutex
);
725 ath10k_bmi_start(ar
);
727 if (ath10k_init_configure_target(ar
)) {
732 status
= ath10k_init_download_firmware(ar
, mode
);
736 status
= ath10k_init_uart(ar
);
740 ar
->htc
.htc_ops
.target_send_suspend_complete
=
741 ath10k_send_suspend_complete
;
743 status
= ath10k_htc_init(ar
);
745 ath10k_err(ar
, "could not init HTC (%d)\n", status
);
749 status
= ath10k_bmi_done(ar
);
753 status
= ath10k_wmi_attach(ar
);
755 ath10k_err(ar
, "WMI attach failed: %d\n", status
);
759 status
= ath10k_htt_init(ar
);
761 ath10k_err(ar
, "failed to init htt: %d\n", status
);
765 status
= ath10k_htt_tx_alloc(&ar
->htt
);
767 ath10k_err(ar
, "failed to alloc htt tx: %d\n", status
);
771 status
= ath10k_htt_rx_alloc(&ar
->htt
);
773 ath10k_err(ar
, "failed to alloc htt rx: %d\n", status
);
774 goto err_htt_tx_detach
;
777 status
= ath10k_hif_start(ar
);
779 ath10k_err(ar
, "could not start HIF: %d\n", status
);
780 goto err_htt_rx_detach
;
783 status
= ath10k_htc_wait_target(&ar
->htc
);
785 ath10k_err(ar
, "failed to connect to HTC: %d\n", status
);
789 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
790 status
= ath10k_htt_connect(&ar
->htt
);
792 ath10k_err(ar
, "failed to connect htt (%d)\n", status
);
797 status
= ath10k_wmi_connect(ar
);
799 ath10k_err(ar
, "could not connect wmi: %d\n", status
);
803 status
= ath10k_htc_start(&ar
->htc
);
805 ath10k_err(ar
, "failed to start htc: %d\n", status
);
809 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
810 status
= ath10k_wmi_wait_for_service_ready(ar
);
812 ath10k_warn(ar
, "wmi service ready event not received");
818 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "firmware %s booted\n",
819 ar
->hw
->wiphy
->fw_version
);
821 status
= ath10k_wmi_cmd_init(ar
);
823 ath10k_err(ar
, "could not send WMI init command (%d)\n",
828 status
= ath10k_wmi_wait_for_unified_ready(ar
);
830 ath10k_err(ar
, "wmi unified ready event not received\n");
835 /* we don't care about HTT in UTF mode */
836 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
837 status
= ath10k_htt_setup(&ar
->htt
);
839 ath10k_err(ar
, "failed to setup htt: %d\n", status
);
844 status
= ath10k_debug_start(ar
);
848 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
))
849 ar
->free_vdev_map
= (1 << TARGET_10X_NUM_VDEVS
) - 1;
851 ar
->free_vdev_map
= (1 << TARGET_NUM_VDEVS
) - 1;
853 INIT_LIST_HEAD(&ar
->arvifs
);
860 ath10k_htt_rx_free(&ar
->htt
);
862 ath10k_htt_tx_free(&ar
->htt
);
864 ath10k_wmi_detach(ar
);
868 EXPORT_SYMBOL(ath10k_core_start
);
870 int ath10k_wait_for_suspend(struct ath10k
*ar
, u32 suspend_opt
)
874 reinit_completion(&ar
->target_suspend
);
876 ret
= ath10k_wmi_pdev_suspend_target(ar
, suspend_opt
);
878 ath10k_warn(ar
, "could not suspend target (%d)\n", ret
);
882 ret
= wait_for_completion_timeout(&ar
->target_suspend
, 1 * HZ
);
885 ath10k_warn(ar
, "suspend timed out - target pause event never came\n");
892 void ath10k_core_stop(struct ath10k
*ar
)
894 lockdep_assert_held(&ar
->conf_mutex
);
896 /* try to suspend target */
897 if (ar
->state
!= ATH10K_STATE_RESTARTING
&&
898 ar
->state
!= ATH10K_STATE_UTF
)
899 ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND_AND_DISABLE_INTR
);
901 ath10k_debug_stop(ar
);
903 ath10k_htt_tx_free(&ar
->htt
);
904 ath10k_htt_rx_free(&ar
->htt
);
905 ath10k_wmi_detach(ar
);
907 EXPORT_SYMBOL(ath10k_core_stop
);
909 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
910 * order to know what hw capabilities should be advertised to mac80211 it is
911 * necessary to load the firmware (and tear it down immediately since start
912 * hook will try to init it again) before registering */
913 static int ath10k_core_probe_fw(struct ath10k
*ar
)
915 struct bmi_target_info target_info
;
918 ret
= ath10k_hif_power_up(ar
);
920 ath10k_err(ar
, "could not start pci hif (%d)\n", ret
);
924 memset(&target_info
, 0, sizeof(target_info
));
925 ret
= ath10k_bmi_get_target_info(ar
, &target_info
);
927 ath10k_err(ar
, "could not get target info (%d)\n", ret
);
928 ath10k_hif_power_down(ar
);
932 ar
->target_version
= target_info
.version
;
933 ar
->hw
->wiphy
->hw_version
= target_info
.version
;
935 ret
= ath10k_init_hw_params(ar
);
937 ath10k_err(ar
, "could not get hw params (%d)\n", ret
);
938 ath10k_hif_power_down(ar
);
942 ret
= ath10k_core_fetch_firmware_files(ar
);
944 ath10k_err(ar
, "could not fetch firmware files (%d)\n", ret
);
945 ath10k_hif_power_down(ar
);
949 mutex_lock(&ar
->conf_mutex
);
951 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
953 ath10k_err(ar
, "could not init core (%d)\n", ret
);
954 ath10k_core_free_firmware_files(ar
);
955 ath10k_hif_power_down(ar
);
956 mutex_unlock(&ar
->conf_mutex
);
960 ath10k_print_driver_info(ar
);
961 ath10k_core_stop(ar
);
963 mutex_unlock(&ar
->conf_mutex
);
965 ath10k_hif_power_down(ar
);
969 static int ath10k_core_check_chip_id(struct ath10k
*ar
)
971 u32 hw_revision
= MS(ar
->chip_id
, SOC_CHIP_ID_REV
);
973 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot chip_id 0x%08x hw_revision 0x%x\n",
974 ar
->chip_id
, hw_revision
);
976 /* Check that we are not using hw1.0 (some of them have same pci id
977 * as hw2.0) before doing anything else as ath10k crashes horribly
978 * due to missing hw1.0 workarounds. */
979 switch (hw_revision
) {
980 case QCA988X_HW_1_0_CHIP_ID_REV
:
981 ath10k_err(ar
, "ERROR: qca988x hw1.0 is not supported\n");
984 case QCA988X_HW_2_0_CHIP_ID_REV
:
985 /* known hardware revision, continue normally */
989 ath10k_warn(ar
, "Warning: hardware revision unknown (0x%x), expect problems\n",
997 static void ath10k_core_register_work(struct work_struct
*work
)
999 struct ath10k
*ar
= container_of(work
, struct ath10k
, register_work
);
1002 status
= ath10k_core_probe_fw(ar
);
1004 ath10k_err(ar
, "could not probe fw (%d)\n", status
);
1008 status
= ath10k_mac_register(ar
);
1010 ath10k_err(ar
, "could not register to mac80211 (%d)\n", status
);
1011 goto err_release_fw
;
1014 status
= ath10k_debug_register(ar
);
1016 ath10k_err(ar
, "unable to initialize debugfs\n");
1017 goto err_unregister_mac
;
1020 status
= ath10k_spectral_create(ar
);
1022 ath10k_err(ar
, "failed to initialize spectral\n");
1023 goto err_debug_destroy
;
1026 set_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
);
1030 ath10k_debug_destroy(ar
);
1032 ath10k_mac_unregister(ar
);
1034 ath10k_core_free_firmware_files(ar
);
1036 /* TODO: It's probably a good idea to release device from the driver
1037 * but calling device_release_driver() here will cause a deadlock.
1042 int ath10k_core_register(struct ath10k
*ar
, u32 chip_id
)
1046 ar
->chip_id
= chip_id
;
1048 status
= ath10k_core_check_chip_id(ar
);
1050 ath10k_err(ar
, "Unsupported chip id 0x%08x\n", ar
->chip_id
);
1054 queue_work(ar
->workqueue
, &ar
->register_work
);
1058 EXPORT_SYMBOL(ath10k_core_register
);
1060 void ath10k_core_unregister(struct ath10k
*ar
)
1062 cancel_work_sync(&ar
->register_work
);
1064 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
))
1067 /* Stop spectral before unregistering from mac80211 to remove the
1068 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1069 * would be already be free'd recursively, leading to a double free.
1071 ath10k_spectral_destroy(ar
);
1073 /* We must unregister from mac80211 before we stop HTC and HIF.
1074 * Otherwise we will fail to submit commands to FW and mac80211 will be
1075 * unhappy about callback failures. */
1076 ath10k_mac_unregister(ar
);
1078 ath10k_testmode_destroy(ar
);
1080 ath10k_core_free_firmware_files(ar
);
1082 ath10k_debug_unregister(ar
);
1084 EXPORT_SYMBOL(ath10k_core_unregister
);
1086 struct ath10k
*ath10k_core_create(size_t priv_size
, struct device
*dev
,
1087 const struct ath10k_hif_ops
*hif_ops
)
1092 ar
= ath10k_mac_create(priv_size
);
1096 ar
->ath_common
.priv
= ar
;
1097 ar
->ath_common
.hw
= ar
->hw
;
1099 ar
->p2p
= !!ath10k_p2p
;
1102 ar
->hif
.ops
= hif_ops
;
1104 init_completion(&ar
->scan
.started
);
1105 init_completion(&ar
->scan
.completed
);
1106 init_completion(&ar
->scan
.on_channel
);
1107 init_completion(&ar
->target_suspend
);
1109 init_completion(&ar
->install_key_done
);
1110 init_completion(&ar
->vdev_setup_done
);
1112 INIT_DELAYED_WORK(&ar
->scan
.timeout
, ath10k_scan_timeout_work
);
1114 ar
->workqueue
= create_singlethread_workqueue("ath10k_wq");
1118 mutex_init(&ar
->conf_mutex
);
1119 spin_lock_init(&ar
->data_lock
);
1121 INIT_LIST_HEAD(&ar
->peers
);
1122 init_waitqueue_head(&ar
->peer_mapping_wq
);
1124 init_completion(&ar
->offchan_tx_completed
);
1125 INIT_WORK(&ar
->offchan_tx_work
, ath10k_offchan_tx_work
);
1126 skb_queue_head_init(&ar
->offchan_tx_queue
);
1128 INIT_WORK(&ar
->wmi_mgmt_tx_work
, ath10k_mgmt_over_wmi_tx_work
);
1129 skb_queue_head_init(&ar
->wmi_mgmt_tx_queue
);
1131 INIT_WORK(&ar
->register_work
, ath10k_core_register_work
);
1132 INIT_WORK(&ar
->restart_work
, ath10k_core_restart
);
1134 ret
= ath10k_debug_create(ar
);
1141 destroy_workqueue(ar
->workqueue
);
1144 ath10k_mac_destroy(ar
);
1148 EXPORT_SYMBOL(ath10k_core_create
);
1150 void ath10k_core_destroy(struct ath10k
*ar
)
1152 flush_workqueue(ar
->workqueue
);
1153 destroy_workqueue(ar
->workqueue
);
1155 ath10k_debug_destroy(ar
);
1156 ath10k_mac_destroy(ar
);
1158 EXPORT_SYMBOL(ath10k_core_destroy
);
1160 MODULE_AUTHOR("Qualcomm Atheros");
1161 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1162 MODULE_LICENSE("Dual BSD/GPL");