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 bool uart_print
;
37 module_param_named(debug_mask
, ath10k_debug_mask
, uint
, 0644);
38 module_param(uart_print
, bool, 0644);
39 module_param(skip_otp
, bool, 0644);
41 MODULE_PARM_DESC(debug_mask
, "Debugging mask");
42 MODULE_PARM_DESC(uart_print
, "Uart target debugging");
43 MODULE_PARM_DESC(skip_otp
, "Skip otp failure for calibration in testmode");
45 static const struct ath10k_hw_params ath10k_hw_params_list
[] = {
47 .id
= QCA988X_HW_2_0_VERSION
,
48 .name
= "qca988x hw2.0",
49 .patch_load_addr
= QCA988X_HW_2_0_PATCH_LOAD_ADDR
,
52 .dir
= QCA988X_HW_2_0_FW_DIR
,
53 .fw
= QCA988X_HW_2_0_FW_FILE
,
54 .otp
= QCA988X_HW_2_0_OTP_FILE
,
55 .board
= QCA988X_HW_2_0_BOARD_DATA_FILE
,
56 .board_size
= QCA988X_BOARD_DATA_SZ
,
57 .board_ext_size
= QCA988X_BOARD_EXT_DATA_SZ
,
61 .id
= QCA6174_HW_2_1_VERSION
,
62 .name
= "qca6174 hw2.1",
63 .patch_load_addr
= QCA6174_HW_2_1_PATCH_LOAD_ADDR
,
66 .dir
= QCA6174_HW_2_1_FW_DIR
,
67 .fw
= QCA6174_HW_2_1_FW_FILE
,
68 .otp
= QCA6174_HW_2_1_OTP_FILE
,
69 .board
= QCA6174_HW_2_1_BOARD_DATA_FILE
,
70 .board_size
= QCA6174_BOARD_DATA_SZ
,
71 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
75 .id
= QCA6174_HW_3_0_VERSION
,
76 .name
= "qca6174 hw3.0",
77 .patch_load_addr
= QCA6174_HW_3_0_PATCH_LOAD_ADDR
,
80 .dir
= QCA6174_HW_3_0_FW_DIR
,
81 .fw
= QCA6174_HW_3_0_FW_FILE
,
82 .otp
= QCA6174_HW_3_0_OTP_FILE
,
83 .board
= QCA6174_HW_3_0_BOARD_DATA_FILE
,
84 .board_size
= QCA6174_BOARD_DATA_SZ
,
85 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
89 .id
= QCA6174_HW_3_2_VERSION
,
90 .name
= "qca6174 hw3.2",
91 .patch_load_addr
= QCA6174_HW_3_0_PATCH_LOAD_ADDR
,
94 /* uses same binaries as hw3.0 */
95 .dir
= QCA6174_HW_3_0_FW_DIR
,
96 .fw
= QCA6174_HW_3_0_FW_FILE
,
97 .otp
= QCA6174_HW_3_0_OTP_FILE
,
98 .board
= QCA6174_HW_3_0_BOARD_DATA_FILE
,
99 .board_size
= QCA6174_BOARD_DATA_SZ
,
100 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
105 static void ath10k_send_suspend_complete(struct ath10k
*ar
)
107 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot suspend complete\n");
109 complete(&ar
->target_suspend
);
112 static int ath10k_init_configure_target(struct ath10k
*ar
)
117 /* tell target which HTC version it is used*/
118 ret
= ath10k_bmi_write32(ar
, hi_app_host_interest
,
119 HTC_PROTOCOL_VERSION
);
121 ath10k_err(ar
, "settings HTC version failed\n");
125 /* set the firmware mode to STA/IBSS/AP */
126 ret
= ath10k_bmi_read32(ar
, hi_option_flag
, ¶m_host
);
128 ath10k_err(ar
, "setting firmware mode (1/2) failed\n");
132 /* TODO following parameters need to be re-visited. */
134 param_host
|= (1 << HI_OPTION_NUM_DEV_SHIFT
);
136 /* FIXME: Why FW_MODE_AP ??.*/
137 param_host
|= (HI_OPTION_FW_MODE_AP
<< HI_OPTION_FW_MODE_SHIFT
);
138 /* mac_addr_method */
139 param_host
|= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT
);
140 /* firmware_bridge */
141 param_host
|= (0 << HI_OPTION_FW_BRIDGE_SHIFT
);
143 param_host
|= (0 << HI_OPTION_FW_SUBMODE_SHIFT
);
145 ret
= ath10k_bmi_write32(ar
, hi_option_flag
, param_host
);
147 ath10k_err(ar
, "setting firmware mode (2/2) failed\n");
151 /* We do all byte-swapping on the host */
152 ret
= ath10k_bmi_write32(ar
, hi_be
, 0);
154 ath10k_err(ar
, "setting host CPU BE mode failed\n");
158 /* FW descriptor/Data swap flags */
159 ret
= ath10k_bmi_write32(ar
, hi_fw_swap
, 0);
162 ath10k_err(ar
, "setting FW data/desc swap flags failed\n");
169 static const struct firmware
*ath10k_fetch_fw_file(struct ath10k
*ar
,
174 const struct firmware
*fw
;
178 return ERR_PTR(-ENOENT
);
183 snprintf(filename
, sizeof(filename
), "%s/%s", dir
, file
);
184 ret
= request_firmware(&fw
, filename
, ar
->dev
);
191 static int ath10k_push_board_ext_data(struct ath10k
*ar
, const void *data
,
194 u32 board_data_size
= ar
->hw_params
.fw
.board_size
;
195 u32 board_ext_data_size
= ar
->hw_params
.fw
.board_ext_size
;
196 u32 board_ext_data_addr
;
199 ret
= ath10k_bmi_read32(ar
, hi_board_ext_data
, &board_ext_data_addr
);
201 ath10k_err(ar
, "could not read board ext data addr (%d)\n",
206 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
207 "boot push board extended data addr 0x%x\n",
208 board_ext_data_addr
);
210 if (board_ext_data_addr
== 0)
213 if (data_len
!= (board_data_size
+ board_ext_data_size
)) {
214 ath10k_err(ar
, "invalid board (ext) data sizes %zu != %d+%d\n",
215 data_len
, board_data_size
, board_ext_data_size
);
219 ret
= ath10k_bmi_write_memory(ar
, board_ext_data_addr
,
220 data
+ board_data_size
,
221 board_ext_data_size
);
223 ath10k_err(ar
, "could not write board ext data (%d)\n", ret
);
227 ret
= ath10k_bmi_write32(ar
, hi_board_ext_data_config
,
228 (board_ext_data_size
<< 16) | 1);
230 ath10k_err(ar
, "could not write board ext data bit (%d)\n",
238 static int ath10k_download_board_data(struct ath10k
*ar
, const void *data
,
241 u32 board_data_size
= ar
->hw_params
.fw
.board_size
;
245 ret
= ath10k_push_board_ext_data(ar
, data
, data_len
);
247 ath10k_err(ar
, "could not push board ext data (%d)\n", ret
);
251 ret
= ath10k_bmi_read32(ar
, hi_board_data
, &address
);
253 ath10k_err(ar
, "could not read board data addr (%d)\n", ret
);
257 ret
= ath10k_bmi_write_memory(ar
, address
, data
,
258 min_t(u32
, board_data_size
,
261 ath10k_err(ar
, "could not write board data (%d)\n", ret
);
265 ret
= ath10k_bmi_write32(ar
, hi_board_data_initialized
, 1);
267 ath10k_err(ar
, "could not write board data bit (%d)\n", ret
);
275 static int ath10k_download_cal_file(struct ath10k
*ar
)
282 if (IS_ERR(ar
->cal_file
))
283 return PTR_ERR(ar
->cal_file
);
285 ret
= ath10k_download_board_data(ar
, ar
->cal_file
->data
,
288 ath10k_err(ar
, "failed to download cal_file data: %d\n", ret
);
292 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot cal file downloaded\n");
297 static int ath10k_download_cal_dt(struct ath10k
*ar
)
299 struct device_node
*node
;
304 node
= ar
->dev
->of_node
;
306 /* Device Tree is optional, don't print any warnings if
307 * there's no node for ath10k.
311 if (!of_get_property(node
, "qcom,ath10k-calibration-data",
313 /* The calibration data node is optional */
317 if (data_len
!= QCA988X_CAL_DATA_LEN
) {
318 ath10k_warn(ar
, "invalid calibration data length in DT: %d\n",
324 data
= kmalloc(data_len
, GFP_KERNEL
);
330 ret
= of_property_read_u8_array(node
, "qcom,ath10k-calibration-data",
333 ath10k_warn(ar
, "failed to read calibration data from DT: %d\n",
338 ret
= ath10k_download_board_data(ar
, data
, data_len
);
340 ath10k_warn(ar
, "failed to download calibration data from Device Tree: %d\n",
354 static int ath10k_download_and_run_otp(struct ath10k
*ar
)
356 u32 result
, address
= ar
->hw_params
.patch_load_addr
;
359 ret
= ath10k_download_board_data(ar
, ar
->board_data
, ar
->board_len
);
361 ath10k_err(ar
, "failed to download board data: %d\n", ret
);
365 /* OTP is optional */
367 if (!ar
->otp_data
|| !ar
->otp_len
) {
368 ath10k_warn(ar
, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
369 ar
->otp_data
, ar
->otp_len
);
373 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot upload otp to 0x%x len %zd\n",
374 address
, ar
->otp_len
);
376 ret
= ath10k_bmi_fast_download(ar
, address
, ar
->otp_data
, ar
->otp_len
);
378 ath10k_err(ar
, "could not write otp (%d)\n", ret
);
382 ret
= ath10k_bmi_execute(ar
, address
, 0, &result
);
384 ath10k_err(ar
, "could not execute otp (%d)\n", ret
);
388 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot otp execute result %d\n", result
);
390 if (!skip_otp
&& result
!= 0) {
391 ath10k_err(ar
, "otp calibration failed: %d", result
);
398 static int ath10k_download_fw(struct ath10k
*ar
, enum ath10k_firmware_mode mode
)
400 u32 address
, data_len
;
401 const char *mode_name
;
405 address
= ar
->hw_params
.patch_load_addr
;
408 case ATH10K_FIRMWARE_MODE_NORMAL
:
409 data
= ar
->firmware_data
;
410 data_len
= ar
->firmware_len
;
411 mode_name
= "normal";
413 case ATH10K_FIRMWARE_MODE_UTF
:
414 data
= ar
->testmode
.utf
->data
;
415 data_len
= ar
->testmode
.utf
->size
;
419 ath10k_err(ar
, "unknown firmware mode: %d\n", mode
);
423 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
424 "boot uploading firmware image %p len %d mode %s\n",
425 data
, data_len
, mode_name
);
427 ret
= ath10k_bmi_fast_download(ar
, address
, data
, data_len
);
429 ath10k_err(ar
, "failed to download %s firmware: %d\n",
437 static void ath10k_core_free_firmware_files(struct ath10k
*ar
)
439 if (ar
->board
&& !IS_ERR(ar
->board
))
440 release_firmware(ar
->board
);
442 if (ar
->otp
&& !IS_ERR(ar
->otp
))
443 release_firmware(ar
->otp
);
445 if (ar
->firmware
&& !IS_ERR(ar
->firmware
))
446 release_firmware(ar
->firmware
);
448 if (ar
->cal_file
&& !IS_ERR(ar
->cal_file
))
449 release_firmware(ar
->cal_file
);
452 ar
->board_data
= NULL
;
460 ar
->firmware_data
= NULL
;
461 ar
->firmware_len
= 0;
466 static int ath10k_fetch_cal_file(struct ath10k
*ar
)
470 /* cal-<bus>-<id>.bin */
471 scnprintf(filename
, sizeof(filename
), "cal-%s-%s.bin",
472 ath10k_bus_str(ar
->hif
.bus
), dev_name(ar
->dev
));
474 ar
->cal_file
= ath10k_fetch_fw_file(ar
, ATH10K_FW_DIR
, filename
);
475 if (IS_ERR(ar
->cal_file
))
476 /* calibration file is optional, don't print any warnings */
477 return PTR_ERR(ar
->cal_file
);
479 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found calibration file %s/%s\n",
480 ATH10K_FW_DIR
, filename
);
485 static int ath10k_core_fetch_firmware_api_1(struct ath10k
*ar
)
489 if (ar
->hw_params
.fw
.fw
== NULL
) {
490 ath10k_err(ar
, "firmware file not defined\n");
494 if (ar
->hw_params
.fw
.board
== NULL
) {
495 ath10k_err(ar
, "board data file not defined");
499 ar
->board
= ath10k_fetch_fw_file(ar
,
500 ar
->hw_params
.fw
.dir
,
501 ar
->hw_params
.fw
.board
);
502 if (IS_ERR(ar
->board
)) {
503 ret
= PTR_ERR(ar
->board
);
504 ath10k_err(ar
, "could not fetch board data (%d)\n", ret
);
508 ar
->board_data
= ar
->board
->data
;
509 ar
->board_len
= ar
->board
->size
;
511 ar
->firmware
= ath10k_fetch_fw_file(ar
,
512 ar
->hw_params
.fw
.dir
,
513 ar
->hw_params
.fw
.fw
);
514 if (IS_ERR(ar
->firmware
)) {
515 ret
= PTR_ERR(ar
->firmware
);
516 ath10k_err(ar
, "could not fetch firmware (%d)\n", ret
);
520 ar
->firmware_data
= ar
->firmware
->data
;
521 ar
->firmware_len
= ar
->firmware
->size
;
523 /* OTP may be undefined. If so, don't fetch it at all */
524 if (ar
->hw_params
.fw
.otp
== NULL
)
527 ar
->otp
= ath10k_fetch_fw_file(ar
,
528 ar
->hw_params
.fw
.dir
,
529 ar
->hw_params
.fw
.otp
);
530 if (IS_ERR(ar
->otp
)) {
531 ret
= PTR_ERR(ar
->otp
);
532 ath10k_err(ar
, "could not fetch otp (%d)\n", ret
);
536 ar
->otp_data
= ar
->otp
->data
;
537 ar
->otp_len
= ar
->otp
->size
;
542 ath10k_core_free_firmware_files(ar
);
546 static int ath10k_core_fetch_firmware_api_n(struct ath10k
*ar
, const char *name
)
548 size_t magic_len
, len
, ie_len
;
549 int ie_id
, i
, index
, bit
, ret
;
550 struct ath10k_fw_ie
*hdr
;
552 __le32
*timestamp
, *version
;
554 /* first fetch the firmware file (firmware-*.bin) */
555 ar
->firmware
= ath10k_fetch_fw_file(ar
, ar
->hw_params
.fw
.dir
, name
);
556 if (IS_ERR(ar
->firmware
)) {
557 ath10k_err(ar
, "could not fetch firmware file '%s/%s': %ld\n",
558 ar
->hw_params
.fw
.dir
, name
, PTR_ERR(ar
->firmware
));
559 return PTR_ERR(ar
->firmware
);
562 data
= ar
->firmware
->data
;
563 len
= ar
->firmware
->size
;
565 /* magic also includes the null byte, check that as well */
566 magic_len
= strlen(ATH10K_FIRMWARE_MAGIC
) + 1;
568 if (len
< magic_len
) {
569 ath10k_err(ar
, "firmware file '%s/%s' too small to contain magic: %zu\n",
570 ar
->hw_params
.fw
.dir
, name
, len
);
575 if (memcmp(data
, ATH10K_FIRMWARE_MAGIC
, magic_len
) != 0) {
576 ath10k_err(ar
, "invalid firmware magic\n");
581 /* jump over the padding */
582 magic_len
= ALIGN(magic_len
, 4);
588 while (len
> sizeof(struct ath10k_fw_ie
)) {
589 hdr
= (struct ath10k_fw_ie
*)data
;
591 ie_id
= le32_to_cpu(hdr
->id
);
592 ie_len
= le32_to_cpu(hdr
->len
);
595 data
+= sizeof(*hdr
);
598 ath10k_err(ar
, "invalid length for FW IE %d (%zu < %zu)\n",
605 case ATH10K_FW_IE_FW_VERSION
:
606 if (ie_len
> sizeof(ar
->hw
->wiphy
->fw_version
) - 1)
609 memcpy(ar
->hw
->wiphy
->fw_version
, data
, ie_len
);
610 ar
->hw
->wiphy
->fw_version
[ie_len
] = '\0';
612 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
613 "found fw version %s\n",
614 ar
->hw
->wiphy
->fw_version
);
616 case ATH10K_FW_IE_TIMESTAMP
:
617 if (ie_len
!= sizeof(u32
))
620 timestamp
= (__le32
*)data
;
622 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw timestamp %d\n",
623 le32_to_cpup(timestamp
));
625 case ATH10K_FW_IE_FEATURES
:
626 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
627 "found firmware features ie (%zd B)\n",
630 for (i
= 0; i
< ATH10K_FW_FEATURE_COUNT
; i
++) {
637 if (data
[index
] & (1 << bit
)) {
638 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
639 "Enabling feature bit: %i\n",
641 __set_bit(i
, ar
->fw_features
);
645 ath10k_dbg_dump(ar
, ATH10K_DBG_BOOT
, "features", "",
647 sizeof(ar
->fw_features
));
649 case ATH10K_FW_IE_FW_IMAGE
:
650 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
651 "found fw image ie (%zd B)\n",
654 ar
->firmware_data
= data
;
655 ar
->firmware_len
= ie_len
;
658 case ATH10K_FW_IE_OTP_IMAGE
:
659 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
660 "found otp image ie (%zd B)\n",
664 ar
->otp_len
= ie_len
;
667 case ATH10K_FW_IE_WMI_OP_VERSION
:
668 if (ie_len
!= sizeof(u32
))
671 version
= (__le32
*)data
;
673 ar
->wmi
.op_version
= le32_to_cpup(version
);
675 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw ie wmi op version %d\n",
679 ath10k_warn(ar
, "Unknown FW IE: %u\n",
680 le32_to_cpu(hdr
->id
));
684 /* jump over the padding */
685 ie_len
= ALIGN(ie_len
, 4);
691 if (!ar
->firmware_data
|| !ar
->firmware_len
) {
692 ath10k_warn(ar
, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
693 ar
->hw_params
.fw
.dir
, name
);
698 /* now fetch the board file */
699 if (ar
->hw_params
.fw
.board
== NULL
) {
700 ath10k_err(ar
, "board data file not defined");
705 ar
->board
= ath10k_fetch_fw_file(ar
,
706 ar
->hw_params
.fw
.dir
,
707 ar
->hw_params
.fw
.board
);
708 if (IS_ERR(ar
->board
)) {
709 ret
= PTR_ERR(ar
->board
);
710 ath10k_err(ar
, "could not fetch board data '%s/%s' (%d)\n",
711 ar
->hw_params
.fw
.dir
, ar
->hw_params
.fw
.board
,
716 ar
->board_data
= ar
->board
->data
;
717 ar
->board_len
= ar
->board
->size
;
722 ath10k_core_free_firmware_files(ar
);
726 static int ath10k_core_fetch_firmware_files(struct ath10k
*ar
)
730 /* calibration file is optional, don't check for any errors */
731 ath10k_fetch_cal_file(ar
);
734 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
736 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API4_FILE
);
741 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
743 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API3_FILE
);
748 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
750 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API2_FILE
);
755 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
757 ret
= ath10k_core_fetch_firmware_api_1(ar
);
762 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "using fw api %d\n", ar
->fw_api
);
767 static int ath10k_download_cal_data(struct ath10k
*ar
)
771 ret
= ath10k_download_cal_file(ar
);
773 ar
->cal_mode
= ATH10K_CAL_MODE_FILE
;
777 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
778 "boot did not find a calibration file, try DT next: %d\n",
781 ret
= ath10k_download_cal_dt(ar
);
783 ar
->cal_mode
= ATH10K_CAL_MODE_DT
;
787 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
788 "boot did not find DT entry, try OTP next: %d\n",
791 ret
= ath10k_download_and_run_otp(ar
);
793 ath10k_err(ar
, "failed to run otp: %d\n", ret
);
797 ar
->cal_mode
= ATH10K_CAL_MODE_OTP
;
800 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot using calibration mode %s\n",
801 ath10k_cal_mode_str(ar
->cal_mode
));
805 static int ath10k_init_uart(struct ath10k
*ar
)
810 * Explicitly setting UART prints to zero as target turns it on
811 * based on scratch registers.
813 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 0);
815 ath10k_warn(ar
, "could not disable UART prints (%d)\n", ret
);
822 ret
= ath10k_bmi_write32(ar
, hi_dbg_uart_txpin
, ar
->hw_params
.uart_pin
);
824 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
828 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 1);
830 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
834 /* Set the UART baud rate to 19200. */
835 ret
= ath10k_bmi_write32(ar
, hi_desired_baud_rate
, 19200);
837 ath10k_warn(ar
, "could not set the baud rate (%d)\n", ret
);
841 ath10k_info(ar
, "UART prints enabled\n");
845 static int ath10k_init_hw_params(struct ath10k
*ar
)
847 const struct ath10k_hw_params
*uninitialized_var(hw_params
);
850 for (i
= 0; i
< ARRAY_SIZE(ath10k_hw_params_list
); i
++) {
851 hw_params
= &ath10k_hw_params_list
[i
];
853 if (hw_params
->id
== ar
->target_version
)
857 if (i
== ARRAY_SIZE(ath10k_hw_params_list
)) {
858 ath10k_err(ar
, "Unsupported hardware version: 0x%x\n",
863 ar
->hw_params
= *hw_params
;
865 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "Hardware name %s version 0x%x\n",
866 ar
->hw_params
.name
, ar
->target_version
);
871 static void ath10k_core_restart(struct work_struct
*work
)
873 struct ath10k
*ar
= container_of(work
, struct ath10k
, restart_work
);
875 set_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
);
877 /* Place a barrier to make sure the compiler doesn't reorder
878 * CRASH_FLUSH and calling other functions.
882 ieee80211_stop_queues(ar
->hw
);
884 complete_all(&ar
->scan
.started
);
885 complete_all(&ar
->scan
.completed
);
886 complete_all(&ar
->scan
.on_channel
);
887 complete_all(&ar
->offchan_tx_completed
);
888 complete_all(&ar
->install_key_done
);
889 complete_all(&ar
->vdev_setup_done
);
890 complete_all(&ar
->thermal
.wmi_sync
);
891 wake_up(&ar
->htt
.empty_tx_wq
);
892 wake_up(&ar
->wmi
.tx_credits_wq
);
893 wake_up(&ar
->peer_mapping_wq
);
895 mutex_lock(&ar
->conf_mutex
);
898 case ATH10K_STATE_ON
:
899 ar
->state
= ATH10K_STATE_RESTARTING
;
901 ath10k_scan_finish(ar
);
902 ieee80211_restart_hw(ar
->hw
);
904 case ATH10K_STATE_OFF
:
905 /* this can happen if driver is being unloaded
906 * or if the crash happens during FW probing */
907 ath10k_warn(ar
, "cannot restart a device that hasn't been started\n");
909 case ATH10K_STATE_RESTARTING
:
910 /* hw restart might be requested from multiple places */
912 case ATH10K_STATE_RESTARTED
:
913 ar
->state
= ATH10K_STATE_WEDGED
;
915 case ATH10K_STATE_WEDGED
:
916 ath10k_warn(ar
, "device is wedged, will not restart\n");
918 case ATH10K_STATE_UTF
:
919 ath10k_warn(ar
, "firmware restart in UTF mode not supported\n");
923 mutex_unlock(&ar
->conf_mutex
);
926 static int ath10k_core_init_firmware_features(struct ath10k
*ar
)
928 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2
, ar
->fw_features
) &&
929 !test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
930 ath10k_err(ar
, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
934 if (ar
->wmi
.op_version
>= ATH10K_FW_WMI_OP_VERSION_MAX
) {
935 ath10k_err(ar
, "unsupported WMI OP version (max %d): %d\n",
936 ATH10K_FW_WMI_OP_VERSION_MAX
, ar
->wmi
.op_version
);
940 /* Backwards compatibility for firmwares without
941 * ATH10K_FW_IE_WMI_OP_VERSION.
943 if (ar
->wmi
.op_version
== ATH10K_FW_WMI_OP_VERSION_UNSET
) {
944 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
945 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2
,
947 ar
->wmi
.op_version
= ATH10K_FW_WMI_OP_VERSION_10_2
;
949 ar
->wmi
.op_version
= ATH10K_FW_WMI_OP_VERSION_10_1
;
951 ar
->wmi
.op_version
= ATH10K_FW_WMI_OP_VERSION_MAIN
;
955 switch (ar
->wmi
.op_version
) {
956 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
957 ar
->max_num_peers
= TARGET_NUM_PEERS
;
958 ar
->max_num_stations
= TARGET_NUM_STATIONS
;
959 ar
->max_num_vdevs
= TARGET_NUM_VDEVS
;
960 ar
->htt
.max_num_pending_tx
= TARGET_NUM_MSDU_DESC
;
962 case ATH10K_FW_WMI_OP_VERSION_10_1
:
963 case ATH10K_FW_WMI_OP_VERSION_10_2
:
964 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
965 ar
->max_num_peers
= TARGET_10X_NUM_PEERS
;
966 ar
->max_num_stations
= TARGET_10X_NUM_STATIONS
;
967 ar
->max_num_vdevs
= TARGET_10X_NUM_VDEVS
;
968 ar
->htt
.max_num_pending_tx
= TARGET_10X_NUM_MSDU_DESC
;
970 case ATH10K_FW_WMI_OP_VERSION_TLV
:
971 ar
->max_num_peers
= TARGET_TLV_NUM_PEERS
;
972 ar
->max_num_stations
= TARGET_TLV_NUM_STATIONS
;
973 ar
->max_num_vdevs
= TARGET_TLV_NUM_VDEVS
;
974 ar
->htt
.max_num_pending_tx
= TARGET_TLV_NUM_MSDU_DESC
;
976 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
977 case ATH10K_FW_WMI_OP_VERSION_MAX
:
985 int ath10k_core_start(struct ath10k
*ar
, enum ath10k_firmware_mode mode
)
989 lockdep_assert_held(&ar
->conf_mutex
);
991 clear_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
);
993 ath10k_bmi_start(ar
);
995 if (ath10k_init_configure_target(ar
)) {
1000 status
= ath10k_download_cal_data(ar
);
1004 status
= ath10k_download_fw(ar
, mode
);
1008 status
= ath10k_init_uart(ar
);
1012 ar
->htc
.htc_ops
.target_send_suspend_complete
=
1013 ath10k_send_suspend_complete
;
1015 status
= ath10k_htc_init(ar
);
1017 ath10k_err(ar
, "could not init HTC (%d)\n", status
);
1021 status
= ath10k_bmi_done(ar
);
1025 status
= ath10k_wmi_attach(ar
);
1027 ath10k_err(ar
, "WMI attach failed: %d\n", status
);
1031 status
= ath10k_htt_init(ar
);
1033 ath10k_err(ar
, "failed to init htt: %d\n", status
);
1034 goto err_wmi_detach
;
1037 status
= ath10k_htt_tx_alloc(&ar
->htt
);
1039 ath10k_err(ar
, "failed to alloc htt tx: %d\n", status
);
1040 goto err_wmi_detach
;
1043 status
= ath10k_htt_rx_alloc(&ar
->htt
);
1045 ath10k_err(ar
, "failed to alloc htt rx: %d\n", status
);
1046 goto err_htt_tx_detach
;
1049 status
= ath10k_hif_start(ar
);
1051 ath10k_err(ar
, "could not start HIF: %d\n", status
);
1052 goto err_htt_rx_detach
;
1055 status
= ath10k_htc_wait_target(&ar
->htc
);
1057 ath10k_err(ar
, "failed to connect to HTC: %d\n", status
);
1061 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1062 status
= ath10k_htt_connect(&ar
->htt
);
1064 ath10k_err(ar
, "failed to connect htt (%d)\n", status
);
1069 status
= ath10k_wmi_connect(ar
);
1071 ath10k_err(ar
, "could not connect wmi: %d\n", status
);
1075 status
= ath10k_htc_start(&ar
->htc
);
1077 ath10k_err(ar
, "failed to start htc: %d\n", status
);
1081 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1082 status
= ath10k_wmi_wait_for_service_ready(ar
);
1084 ath10k_warn(ar
, "wmi service ready event not received");
1085 status
= -ETIMEDOUT
;
1090 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "firmware %s booted\n",
1091 ar
->hw
->wiphy
->fw_version
);
1093 status
= ath10k_wmi_cmd_init(ar
);
1095 ath10k_err(ar
, "could not send WMI init command (%d)\n",
1100 status
= ath10k_wmi_wait_for_unified_ready(ar
);
1102 ath10k_err(ar
, "wmi unified ready event not received\n");
1103 status
= -ETIMEDOUT
;
1107 /* If firmware indicates Full Rx Reorder support it must be used in a
1108 * slightly different manner. Let HTT code know.
1110 ar
->htt
.rx_ring
.in_ord_rx
= !!(test_bit(WMI_SERVICE_RX_FULL_REORDER
,
1113 status
= ath10k_htt_rx_ring_refill(ar
);
1115 ath10k_err(ar
, "failed to refill htt rx ring: %d\n", status
);
1119 /* we don't care about HTT in UTF mode */
1120 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1121 status
= ath10k_htt_setup(&ar
->htt
);
1123 ath10k_err(ar
, "failed to setup htt: %d\n", status
);
1128 status
= ath10k_debug_start(ar
);
1132 ar
->free_vdev_map
= (1LL << ar
->max_num_vdevs
) - 1;
1134 INIT_LIST_HEAD(&ar
->arvifs
);
1139 ath10k_hif_stop(ar
);
1141 ath10k_htt_rx_free(&ar
->htt
);
1143 ath10k_htt_tx_free(&ar
->htt
);
1145 ath10k_wmi_detach(ar
);
1149 EXPORT_SYMBOL(ath10k_core_start
);
1151 int ath10k_wait_for_suspend(struct ath10k
*ar
, u32 suspend_opt
)
1155 reinit_completion(&ar
->target_suspend
);
1157 ret
= ath10k_wmi_pdev_suspend_target(ar
, suspend_opt
);
1159 ath10k_warn(ar
, "could not suspend target (%d)\n", ret
);
1163 ret
= wait_for_completion_timeout(&ar
->target_suspend
, 1 * HZ
);
1166 ath10k_warn(ar
, "suspend timed out - target pause event never came\n");
1173 void ath10k_core_stop(struct ath10k
*ar
)
1175 lockdep_assert_held(&ar
->conf_mutex
);
1177 /* try to suspend target */
1178 if (ar
->state
!= ATH10K_STATE_RESTARTING
&&
1179 ar
->state
!= ATH10K_STATE_UTF
)
1180 ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND_AND_DISABLE_INTR
);
1182 ath10k_debug_stop(ar
);
1183 ath10k_hif_stop(ar
);
1184 ath10k_htt_tx_free(&ar
->htt
);
1185 ath10k_htt_rx_free(&ar
->htt
);
1186 ath10k_wmi_detach(ar
);
1188 EXPORT_SYMBOL(ath10k_core_stop
);
1190 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1191 * order to know what hw capabilities should be advertised to mac80211 it is
1192 * necessary to load the firmware (and tear it down immediately since start
1193 * hook will try to init it again) before registering */
1194 static int ath10k_core_probe_fw(struct ath10k
*ar
)
1196 struct bmi_target_info target_info
;
1199 ret
= ath10k_hif_power_up(ar
);
1201 ath10k_err(ar
, "could not start pci hif (%d)\n", ret
);
1205 memset(&target_info
, 0, sizeof(target_info
));
1206 ret
= ath10k_bmi_get_target_info(ar
, &target_info
);
1208 ath10k_err(ar
, "could not get target info (%d)\n", ret
);
1209 goto err_power_down
;
1212 ar
->target_version
= target_info
.version
;
1213 ar
->hw
->wiphy
->hw_version
= target_info
.version
;
1215 ret
= ath10k_init_hw_params(ar
);
1217 ath10k_err(ar
, "could not get hw params (%d)\n", ret
);
1218 goto err_power_down
;
1221 ret
= ath10k_core_fetch_firmware_files(ar
);
1223 ath10k_err(ar
, "could not fetch firmware files (%d)\n", ret
);
1224 goto err_power_down
;
1227 ret
= ath10k_core_init_firmware_features(ar
);
1229 ath10k_err(ar
, "fatal problem with firmware features: %d\n",
1231 goto err_free_firmware_files
;
1234 mutex_lock(&ar
->conf_mutex
);
1236 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
1238 ath10k_err(ar
, "could not init core (%d)\n", ret
);
1242 ath10k_print_driver_info(ar
);
1243 ath10k_core_stop(ar
);
1245 mutex_unlock(&ar
->conf_mutex
);
1247 ath10k_hif_power_down(ar
);
1251 mutex_unlock(&ar
->conf_mutex
);
1253 err_free_firmware_files
:
1254 ath10k_core_free_firmware_files(ar
);
1257 ath10k_hif_power_down(ar
);
1262 static void ath10k_core_register_work(struct work_struct
*work
)
1264 struct ath10k
*ar
= container_of(work
, struct ath10k
, register_work
);
1267 status
= ath10k_core_probe_fw(ar
);
1269 ath10k_err(ar
, "could not probe fw (%d)\n", status
);
1273 status
= ath10k_mac_register(ar
);
1275 ath10k_err(ar
, "could not register to mac80211 (%d)\n", status
);
1276 goto err_release_fw
;
1279 status
= ath10k_debug_register(ar
);
1281 ath10k_err(ar
, "unable to initialize debugfs\n");
1282 goto err_unregister_mac
;
1285 status
= ath10k_spectral_create(ar
);
1287 ath10k_err(ar
, "failed to initialize spectral\n");
1288 goto err_debug_destroy
;
1291 status
= ath10k_thermal_register(ar
);
1293 ath10k_err(ar
, "could not register thermal device: %d\n",
1295 goto err_spectral_destroy
;
1298 set_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
);
1301 err_spectral_destroy
:
1302 ath10k_spectral_destroy(ar
);
1304 ath10k_debug_destroy(ar
);
1306 ath10k_mac_unregister(ar
);
1308 ath10k_core_free_firmware_files(ar
);
1310 /* TODO: It's probably a good idea to release device from the driver
1311 * but calling device_release_driver() here will cause a deadlock.
1316 int ath10k_core_register(struct ath10k
*ar
, u32 chip_id
)
1318 ar
->chip_id
= chip_id
;
1319 queue_work(ar
->workqueue
, &ar
->register_work
);
1323 EXPORT_SYMBOL(ath10k_core_register
);
1325 void ath10k_core_unregister(struct ath10k
*ar
)
1327 cancel_work_sync(&ar
->register_work
);
1329 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
))
1332 ath10k_thermal_unregister(ar
);
1333 /* Stop spectral before unregistering from mac80211 to remove the
1334 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1335 * would be already be free'd recursively, leading to a double free.
1337 ath10k_spectral_destroy(ar
);
1339 /* We must unregister from mac80211 before we stop HTC and HIF.
1340 * Otherwise we will fail to submit commands to FW and mac80211 will be
1341 * unhappy about callback failures. */
1342 ath10k_mac_unregister(ar
);
1344 ath10k_testmode_destroy(ar
);
1346 ath10k_core_free_firmware_files(ar
);
1348 ath10k_debug_unregister(ar
);
1350 EXPORT_SYMBOL(ath10k_core_unregister
);
1352 struct ath10k
*ath10k_core_create(size_t priv_size
, struct device
*dev
,
1353 enum ath10k_bus bus
,
1354 enum ath10k_hw_rev hw_rev
,
1355 const struct ath10k_hif_ops
*hif_ops
)
1360 ar
= ath10k_mac_create(priv_size
);
1364 ar
->ath_common
.priv
= ar
;
1365 ar
->ath_common
.hw
= ar
->hw
;
1367 ar
->hw_rev
= hw_rev
;
1368 ar
->hif
.ops
= hif_ops
;
1372 case ATH10K_HW_QCA988X
:
1373 ar
->regs
= &qca988x_regs
;
1375 case ATH10K_HW_QCA6174
:
1376 ar
->regs
= &qca6174_regs
;
1379 ath10k_err(ar
, "unsupported core hardware revision %d\n",
1385 init_completion(&ar
->scan
.started
);
1386 init_completion(&ar
->scan
.completed
);
1387 init_completion(&ar
->scan
.on_channel
);
1388 init_completion(&ar
->target_suspend
);
1390 init_completion(&ar
->install_key_done
);
1391 init_completion(&ar
->vdev_setup_done
);
1392 init_completion(&ar
->thermal
.wmi_sync
);
1394 INIT_DELAYED_WORK(&ar
->scan
.timeout
, ath10k_scan_timeout_work
);
1396 ar
->workqueue
= create_singlethread_workqueue("ath10k_wq");
1400 mutex_init(&ar
->conf_mutex
);
1401 spin_lock_init(&ar
->data_lock
);
1403 INIT_LIST_HEAD(&ar
->peers
);
1404 init_waitqueue_head(&ar
->peer_mapping_wq
);
1405 init_waitqueue_head(&ar
->htt
.empty_tx_wq
);
1406 init_waitqueue_head(&ar
->wmi
.tx_credits_wq
);
1408 init_completion(&ar
->offchan_tx_completed
);
1409 INIT_WORK(&ar
->offchan_tx_work
, ath10k_offchan_tx_work
);
1410 skb_queue_head_init(&ar
->offchan_tx_queue
);
1412 INIT_WORK(&ar
->wmi_mgmt_tx_work
, ath10k_mgmt_over_wmi_tx_work
);
1413 skb_queue_head_init(&ar
->wmi_mgmt_tx_queue
);
1415 INIT_WORK(&ar
->register_work
, ath10k_core_register_work
);
1416 INIT_WORK(&ar
->restart_work
, ath10k_core_restart
);
1418 ret
= ath10k_debug_create(ar
);
1425 destroy_workqueue(ar
->workqueue
);
1428 ath10k_mac_destroy(ar
);
1432 EXPORT_SYMBOL(ath10k_core_create
);
1434 void ath10k_core_destroy(struct ath10k
*ar
)
1436 flush_workqueue(ar
->workqueue
);
1437 destroy_workqueue(ar
->workqueue
);
1439 ath10k_debug_destroy(ar
);
1440 ath10k_mac_destroy(ar
);
1442 EXPORT_SYMBOL(ath10k_core_destroy
);
1444 MODULE_AUTHOR("Qualcomm Atheros");
1445 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1446 MODULE_LICENSE("Dual BSD/GPL");