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 unsigned int ath10k_cryptmode_param
;
35 static bool uart_print
;
39 module_param_named(debug_mask
, ath10k_debug_mask
, uint
, 0644);
40 module_param_named(cryptmode
, ath10k_cryptmode_param
, uint
, 0644);
41 module_param(uart_print
, bool, 0644);
42 module_param(skip_otp
, bool, 0644);
43 module_param(rawmode
, bool, 0644);
45 MODULE_PARM_DESC(debug_mask
, "Debugging mask");
46 MODULE_PARM_DESC(uart_print
, "Uart target debugging");
47 MODULE_PARM_DESC(skip_otp
, "Skip otp failure for calibration in testmode");
48 MODULE_PARM_DESC(cryptmode
, "Crypto mode: 0-hardware, 1-software");
49 MODULE_PARM_DESC(rawmode
, "Use raw 802.11 frame datapath");
51 static const struct ath10k_hw_params ath10k_hw_params_list
[] = {
53 .id
= QCA988X_HW_2_0_VERSION
,
54 .dev_id
= QCA988X_2_0_DEVICE_ID
,
55 .name
= "qca988x hw2.0",
56 .patch_load_addr
= QCA988X_HW_2_0_PATCH_LOAD_ADDR
,
58 .has_shifted_cc_wraparound
= true,
60 .channel_counters_freq_hz
= 88000,
61 .max_probe_resp_desc_thres
= 0,
63 .dir
= QCA988X_HW_2_0_FW_DIR
,
64 .fw
= QCA988X_HW_2_0_FW_FILE
,
65 .otp
= QCA988X_HW_2_0_OTP_FILE
,
66 .board
= QCA988X_HW_2_0_BOARD_DATA_FILE
,
67 .board_size
= QCA988X_BOARD_DATA_SZ
,
68 .board_ext_size
= QCA988X_BOARD_EXT_DATA_SZ
,
70 .decap_align_bytes
= 4,
73 .id
= QCA6174_HW_2_1_VERSION
,
74 .dev_id
= QCA6164_2_1_DEVICE_ID
,
75 .name
= "qca6164 hw2.1",
76 .patch_load_addr
= QCA6174_HW_2_1_PATCH_LOAD_ADDR
,
79 .channel_counters_freq_hz
= 88000,
80 .max_probe_resp_desc_thres
= 0,
82 .dir
= QCA6174_HW_2_1_FW_DIR
,
83 .fw
= QCA6174_HW_2_1_FW_FILE
,
84 .otp
= QCA6174_HW_2_1_OTP_FILE
,
85 .board
= QCA6174_HW_2_1_BOARD_DATA_FILE
,
86 .board_size
= QCA6174_BOARD_DATA_SZ
,
87 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
89 .decap_align_bytes
= 4,
92 .id
= QCA6174_HW_2_1_VERSION
,
93 .dev_id
= QCA6174_2_1_DEVICE_ID
,
94 .name
= "qca6174 hw2.1",
95 .patch_load_addr
= QCA6174_HW_2_1_PATCH_LOAD_ADDR
,
98 .channel_counters_freq_hz
= 88000,
99 .max_probe_resp_desc_thres
= 0,
101 .dir
= QCA6174_HW_2_1_FW_DIR
,
102 .fw
= QCA6174_HW_2_1_FW_FILE
,
103 .otp
= QCA6174_HW_2_1_OTP_FILE
,
104 .board
= QCA6174_HW_2_1_BOARD_DATA_FILE
,
105 .board_size
= QCA6174_BOARD_DATA_SZ
,
106 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
108 .decap_align_bytes
= 4,
111 .id
= QCA6174_HW_3_0_VERSION
,
112 .dev_id
= QCA6174_2_1_DEVICE_ID
,
113 .name
= "qca6174 hw3.0",
114 .patch_load_addr
= QCA6174_HW_3_0_PATCH_LOAD_ADDR
,
117 .channel_counters_freq_hz
= 88000,
118 .max_probe_resp_desc_thres
= 0,
120 .dir
= QCA6174_HW_3_0_FW_DIR
,
121 .fw
= QCA6174_HW_3_0_FW_FILE
,
122 .otp
= QCA6174_HW_3_0_OTP_FILE
,
123 .board
= QCA6174_HW_3_0_BOARD_DATA_FILE
,
124 .board_size
= QCA6174_BOARD_DATA_SZ
,
125 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
127 .decap_align_bytes
= 4,
130 .id
= QCA6174_HW_3_2_VERSION
,
131 .dev_id
= QCA6174_2_1_DEVICE_ID
,
132 .name
= "qca6174 hw3.2",
133 .patch_load_addr
= QCA6174_HW_3_0_PATCH_LOAD_ADDR
,
136 .channel_counters_freq_hz
= 88000,
137 .max_probe_resp_desc_thres
= 0,
139 /* uses same binaries as hw3.0 */
140 .dir
= QCA6174_HW_3_0_FW_DIR
,
141 .fw
= QCA6174_HW_3_0_FW_FILE
,
142 .otp
= QCA6174_HW_3_0_OTP_FILE
,
143 .board
= QCA6174_HW_3_0_BOARD_DATA_FILE
,
144 .board_size
= QCA6174_BOARD_DATA_SZ
,
145 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
147 .decap_align_bytes
= 4,
150 .id
= QCA99X0_HW_2_0_DEV_VERSION
,
151 .dev_id
= QCA99X0_2_0_DEVICE_ID
,
152 .name
= "qca99x0 hw2.0",
153 .patch_load_addr
= QCA99X0_HW_2_0_PATCH_LOAD_ADDR
,
155 .otp_exe_param
= 0x00000700,
156 .continuous_frag_desc
= true,
157 .channel_counters_freq_hz
= 150000,
158 .max_probe_resp_desc_thres
= 24,
160 .dir
= QCA99X0_HW_2_0_FW_DIR
,
161 .fw
= QCA99X0_HW_2_0_FW_FILE
,
162 .otp
= QCA99X0_HW_2_0_OTP_FILE
,
163 .board
= QCA99X0_HW_2_0_BOARD_DATA_FILE
,
164 .board_size
= QCA99X0_BOARD_DATA_SZ
,
165 .board_ext_size
= QCA99X0_BOARD_EXT_DATA_SZ
,
167 .decap_align_bytes
= 1,
170 .id
= QCA9377_HW_1_0_DEV_VERSION
,
171 .dev_id
= QCA9377_1_0_DEVICE_ID
,
172 .name
= "qca9377 hw1.0",
173 .patch_load_addr
= QCA9377_HW_1_0_PATCH_LOAD_ADDR
,
176 .channel_counters_freq_hz
= 88000,
177 .max_probe_resp_desc_thres
= 0,
179 .dir
= QCA9377_HW_1_0_FW_DIR
,
180 .fw
= QCA9377_HW_1_0_FW_FILE
,
181 .otp
= QCA9377_HW_1_0_OTP_FILE
,
182 .board
= QCA9377_HW_1_0_BOARD_DATA_FILE
,
183 .board_size
= QCA9377_BOARD_DATA_SZ
,
184 .board_ext_size
= QCA9377_BOARD_EXT_DATA_SZ
,
186 .decap_align_bytes
= 4,
189 .id
= QCA9377_HW_1_1_DEV_VERSION
,
190 .dev_id
= QCA9377_1_0_DEVICE_ID
,
191 .name
= "qca9377 hw1.1",
192 .patch_load_addr
= QCA9377_HW_1_0_PATCH_LOAD_ADDR
,
195 .channel_counters_freq_hz
= 88000,
196 .max_probe_resp_desc_thres
= 0,
198 .dir
= QCA9377_HW_1_0_FW_DIR
,
199 .fw
= QCA9377_HW_1_0_FW_FILE
,
200 .otp
= QCA9377_HW_1_0_OTP_FILE
,
201 .board
= QCA9377_HW_1_0_BOARD_DATA_FILE
,
202 .board_size
= QCA9377_BOARD_DATA_SZ
,
203 .board_ext_size
= QCA9377_BOARD_EXT_DATA_SZ
,
205 .decap_align_bytes
= 4,
209 static const char *const ath10k_core_fw_feature_str
[] = {
210 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX
] = "wmi-mgmt-rx",
211 [ATH10K_FW_FEATURE_WMI_10X
] = "wmi-10.x",
212 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
] = "has-wmi-mgmt-tx",
213 [ATH10K_FW_FEATURE_NO_P2P
] = "no-p2p",
214 [ATH10K_FW_FEATURE_WMI_10_2
] = "wmi-10.2",
215 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
] = "multi-vif-ps",
216 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT
] = "wowlan",
217 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT
] = "ignore-otp",
218 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING
] = "no-4addr-pad",
219 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT
] = "skip-clock-init",
220 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT
] = "raw-mode",
221 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA
] = "adaptive-cca",
224 static unsigned int ath10k_core_get_fw_feature_str(char *buf
,
226 enum ath10k_fw_features feat
)
228 /* make sure that ath10k_core_fw_feature_str[] gets updated */
229 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str
) !=
230 ATH10K_FW_FEATURE_COUNT
);
232 if (feat
>= ARRAY_SIZE(ath10k_core_fw_feature_str
) ||
233 WARN_ON(!ath10k_core_fw_feature_str
[feat
])) {
234 return scnprintf(buf
, buf_len
, "bit%d", feat
);
237 return scnprintf(buf
, buf_len
, "%s", ath10k_core_fw_feature_str
[feat
]);
240 void ath10k_core_get_fw_features_str(struct ath10k
*ar
,
244 unsigned int len
= 0;
247 for (i
= 0; i
< ATH10K_FW_FEATURE_COUNT
; i
++) {
248 if (test_bit(i
, ar
->fw_features
)) {
250 len
+= scnprintf(buf
+ len
, buf_len
- len
, ",");
252 len
+= ath10k_core_get_fw_feature_str(buf
+ len
,
259 static void ath10k_send_suspend_complete(struct ath10k
*ar
)
261 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot suspend complete\n");
263 complete(&ar
->target_suspend
);
266 static int ath10k_init_configure_target(struct ath10k
*ar
)
271 /* tell target which HTC version it is used*/
272 ret
= ath10k_bmi_write32(ar
, hi_app_host_interest
,
273 HTC_PROTOCOL_VERSION
);
275 ath10k_err(ar
, "settings HTC version failed\n");
279 /* set the firmware mode to STA/IBSS/AP */
280 ret
= ath10k_bmi_read32(ar
, hi_option_flag
, ¶m_host
);
282 ath10k_err(ar
, "setting firmware mode (1/2) failed\n");
286 /* TODO following parameters need to be re-visited. */
288 param_host
|= (1 << HI_OPTION_NUM_DEV_SHIFT
);
290 /* FIXME: Why FW_MODE_AP ??.*/
291 param_host
|= (HI_OPTION_FW_MODE_AP
<< HI_OPTION_FW_MODE_SHIFT
);
292 /* mac_addr_method */
293 param_host
|= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT
);
294 /* firmware_bridge */
295 param_host
|= (0 << HI_OPTION_FW_BRIDGE_SHIFT
);
297 param_host
|= (0 << HI_OPTION_FW_SUBMODE_SHIFT
);
299 ret
= ath10k_bmi_write32(ar
, hi_option_flag
, param_host
);
301 ath10k_err(ar
, "setting firmware mode (2/2) failed\n");
305 /* We do all byte-swapping on the host */
306 ret
= ath10k_bmi_write32(ar
, hi_be
, 0);
308 ath10k_err(ar
, "setting host CPU BE mode failed\n");
312 /* FW descriptor/Data swap flags */
313 ret
= ath10k_bmi_write32(ar
, hi_fw_swap
, 0);
316 ath10k_err(ar
, "setting FW data/desc swap flags failed\n");
320 /* Some devices have a special sanity check that verifies the PCI
321 * Device ID is written to this host interest var. It is known to be
322 * required to boot QCA6164.
324 ret
= ath10k_bmi_write32(ar
, hi_hci_uart_pwr_mgmt_params_ext
,
327 ath10k_err(ar
, "failed to set pwr_mgmt_params: %d\n", ret
);
334 static const struct firmware
*ath10k_fetch_fw_file(struct ath10k
*ar
,
339 const struct firmware
*fw
;
343 return ERR_PTR(-ENOENT
);
348 snprintf(filename
, sizeof(filename
), "%s/%s", dir
, file
);
349 ret
= request_firmware(&fw
, filename
, ar
->dev
);
356 static int ath10k_push_board_ext_data(struct ath10k
*ar
, const void *data
,
359 u32 board_data_size
= ar
->hw_params
.fw
.board_size
;
360 u32 board_ext_data_size
= ar
->hw_params
.fw
.board_ext_size
;
361 u32 board_ext_data_addr
;
364 ret
= ath10k_bmi_read32(ar
, hi_board_ext_data
, &board_ext_data_addr
);
366 ath10k_err(ar
, "could not read board ext data addr (%d)\n",
371 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
372 "boot push board extended data addr 0x%x\n",
373 board_ext_data_addr
);
375 if (board_ext_data_addr
== 0)
378 if (data_len
!= (board_data_size
+ board_ext_data_size
)) {
379 ath10k_err(ar
, "invalid board (ext) data sizes %zu != %d+%d\n",
380 data_len
, board_data_size
, board_ext_data_size
);
384 ret
= ath10k_bmi_write_memory(ar
, board_ext_data_addr
,
385 data
+ board_data_size
,
386 board_ext_data_size
);
388 ath10k_err(ar
, "could not write board ext data (%d)\n", ret
);
392 ret
= ath10k_bmi_write32(ar
, hi_board_ext_data_config
,
393 (board_ext_data_size
<< 16) | 1);
395 ath10k_err(ar
, "could not write board ext data bit (%d)\n",
403 static int ath10k_download_board_data(struct ath10k
*ar
, const void *data
,
406 u32 board_data_size
= ar
->hw_params
.fw
.board_size
;
410 ret
= ath10k_push_board_ext_data(ar
, data
, data_len
);
412 ath10k_err(ar
, "could not push board ext data (%d)\n", ret
);
416 ret
= ath10k_bmi_read32(ar
, hi_board_data
, &address
);
418 ath10k_err(ar
, "could not read board data addr (%d)\n", ret
);
422 ret
= ath10k_bmi_write_memory(ar
, address
, data
,
423 min_t(u32
, board_data_size
,
426 ath10k_err(ar
, "could not write board data (%d)\n", ret
);
430 ret
= ath10k_bmi_write32(ar
, hi_board_data_initialized
, 1);
432 ath10k_err(ar
, "could not write board data bit (%d)\n", ret
);
440 static int ath10k_download_cal_file(struct ath10k
*ar
)
447 if (IS_ERR(ar
->cal_file
))
448 return PTR_ERR(ar
->cal_file
);
450 ret
= ath10k_download_board_data(ar
, ar
->cal_file
->data
,
453 ath10k_err(ar
, "failed to download cal_file data: %d\n", ret
);
457 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot cal file downloaded\n");
462 static int ath10k_download_cal_dt(struct ath10k
*ar
)
464 struct device_node
*node
;
469 node
= ar
->dev
->of_node
;
471 /* Device Tree is optional, don't print any warnings if
472 * there's no node for ath10k.
476 if (!of_get_property(node
, "qcom,ath10k-calibration-data",
478 /* The calibration data node is optional */
482 if (data_len
!= QCA988X_CAL_DATA_LEN
) {
483 ath10k_warn(ar
, "invalid calibration data length in DT: %d\n",
489 data
= kmalloc(data_len
, GFP_KERNEL
);
495 ret
= of_property_read_u8_array(node
, "qcom,ath10k-calibration-data",
498 ath10k_warn(ar
, "failed to read calibration data from DT: %d\n",
503 ret
= ath10k_download_board_data(ar
, data
, data_len
);
505 ath10k_warn(ar
, "failed to download calibration data from Device Tree: %d\n",
519 static int ath10k_core_get_board_id_from_otp(struct ath10k
*ar
)
522 u8 board_id
, chip_id
;
525 address
= ar
->hw_params
.patch_load_addr
;
527 if (!ar
->otp_data
|| !ar
->otp_len
) {
529 "failed to retrieve board id because of invalid otp\n");
533 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
534 "boot upload otp to 0x%x len %zd for board id\n",
535 address
, ar
->otp_len
);
537 ret
= ath10k_bmi_fast_download(ar
, address
, ar
->otp_data
, ar
->otp_len
);
539 ath10k_err(ar
, "could not write otp for board id check: %d\n",
544 ret
= ath10k_bmi_execute(ar
, address
, BMI_PARAM_GET_EEPROM_BOARD_ID
,
547 ath10k_err(ar
, "could not execute otp for board id check: %d\n",
552 board_id
= MS(result
, ATH10K_BMI_BOARD_ID_FROM_OTP
);
553 chip_id
= MS(result
, ATH10K_BMI_CHIP_ID_FROM_OTP
);
555 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
556 "boot get otp board id result 0x%08x board_id %d chip_id %d\n",
557 result
, board_id
, chip_id
);
559 if ((result
& ATH10K_BMI_BOARD_ID_STATUS_MASK
) != 0 ||
561 ath10k_warn(ar
, "board id is not exist in otp, ignore it\n");
565 ar
->id
.bmi_ids_valid
= true;
566 ar
->id
.bmi_board_id
= board_id
;
567 ar
->id
.bmi_chip_id
= chip_id
;
572 static int ath10k_download_and_run_otp(struct ath10k
*ar
)
574 u32 result
, address
= ar
->hw_params
.patch_load_addr
;
575 u32 bmi_otp_exe_param
= ar
->hw_params
.otp_exe_param
;
578 ret
= ath10k_download_board_data(ar
, ar
->board_data
, ar
->board_len
);
580 ath10k_err(ar
, "failed to download board data: %d\n", ret
);
584 /* OTP is optional */
586 if (!ar
->otp_data
|| !ar
->otp_len
) {
587 ath10k_warn(ar
, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
588 ar
->otp_data
, ar
->otp_len
);
592 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot upload otp to 0x%x len %zd\n",
593 address
, ar
->otp_len
);
595 ret
= ath10k_bmi_fast_download(ar
, address
, ar
->otp_data
, ar
->otp_len
);
597 ath10k_err(ar
, "could not write otp (%d)\n", ret
);
601 ret
= ath10k_bmi_execute(ar
, address
, bmi_otp_exe_param
, &result
);
603 ath10k_err(ar
, "could not execute otp (%d)\n", ret
);
607 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot otp execute result %d\n", result
);
609 if (!(skip_otp
|| test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT
,
612 ath10k_err(ar
, "otp calibration failed: %d", result
);
619 static int ath10k_download_fw(struct ath10k
*ar
, enum ath10k_firmware_mode mode
)
621 u32 address
, data_len
;
622 const char *mode_name
;
626 address
= ar
->hw_params
.patch_load_addr
;
629 case ATH10K_FIRMWARE_MODE_NORMAL
:
630 data
= ar
->firmware_data
;
631 data_len
= ar
->firmware_len
;
632 mode_name
= "normal";
633 ret
= ath10k_swap_code_seg_configure(ar
,
634 ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW
);
636 ath10k_err(ar
, "failed to configure fw code swap: %d\n",
641 case ATH10K_FIRMWARE_MODE_UTF
:
642 data
= ar
->testmode
.utf_firmware_data
;
643 data_len
= ar
->testmode
.utf_firmware_len
;
647 ath10k_err(ar
, "unknown firmware mode: %d\n", mode
);
651 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
652 "boot uploading firmware image %p len %d mode %s\n",
653 data
, data_len
, mode_name
);
655 ret
= ath10k_bmi_fast_download(ar
, address
, data
, data_len
);
657 ath10k_err(ar
, "failed to download %s firmware: %d\n",
665 static void ath10k_core_free_board_files(struct ath10k
*ar
)
667 if (!IS_ERR(ar
->board
))
668 release_firmware(ar
->board
);
671 ar
->board_data
= NULL
;
675 static void ath10k_core_free_firmware_files(struct ath10k
*ar
)
677 if (!IS_ERR(ar
->otp
))
678 release_firmware(ar
->otp
);
680 if (!IS_ERR(ar
->firmware
))
681 release_firmware(ar
->firmware
);
683 if (!IS_ERR(ar
->cal_file
))
684 release_firmware(ar
->cal_file
);
686 ath10k_swap_code_seg_release(ar
);
693 ar
->firmware_data
= NULL
;
694 ar
->firmware_len
= 0;
699 static int ath10k_fetch_cal_file(struct ath10k
*ar
)
703 /* cal-<bus>-<id>.bin */
704 scnprintf(filename
, sizeof(filename
), "cal-%s-%s.bin",
705 ath10k_bus_str(ar
->hif
.bus
), dev_name(ar
->dev
));
707 ar
->cal_file
= ath10k_fetch_fw_file(ar
, ATH10K_FW_DIR
, filename
);
708 if (IS_ERR(ar
->cal_file
))
709 /* calibration file is optional, don't print any warnings */
710 return PTR_ERR(ar
->cal_file
);
712 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found calibration file %s/%s\n",
713 ATH10K_FW_DIR
, filename
);
718 static int ath10k_core_fetch_board_data_api_1(struct ath10k
*ar
)
720 if (!ar
->hw_params
.fw
.board
) {
721 ath10k_err(ar
, "failed to find board file fw entry\n");
725 ar
->board
= ath10k_fetch_fw_file(ar
,
726 ar
->hw_params
.fw
.dir
,
727 ar
->hw_params
.fw
.board
);
728 if (IS_ERR(ar
->board
))
729 return PTR_ERR(ar
->board
);
731 ar
->board_data
= ar
->board
->data
;
732 ar
->board_len
= ar
->board
->size
;
737 static int ath10k_core_parse_bd_ie_board(struct ath10k
*ar
,
738 const void *buf
, size_t buf_len
,
739 const char *boardname
)
741 const struct ath10k_fw_ie
*hdr
;
742 bool name_match_found
;
743 int ret
, board_ie_id
;
745 const void *board_ie_data
;
747 name_match_found
= false;
749 /* go through ATH10K_BD_IE_BOARD_ elements */
750 while (buf_len
> sizeof(struct ath10k_fw_ie
)) {
752 board_ie_id
= le32_to_cpu(hdr
->id
);
753 board_ie_len
= le32_to_cpu(hdr
->len
);
754 board_ie_data
= hdr
->data
;
756 buf_len
-= sizeof(*hdr
);
759 if (buf_len
< ALIGN(board_ie_len
, 4)) {
760 ath10k_err(ar
, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
761 buf_len
, ALIGN(board_ie_len
, 4));
766 switch (board_ie_id
) {
767 case ATH10K_BD_IE_BOARD_NAME
:
768 ath10k_dbg_dump(ar
, ATH10K_DBG_BOOT
, "board name", "",
769 board_ie_data
, board_ie_len
);
771 if (board_ie_len
!= strlen(boardname
))
774 ret
= memcmp(board_ie_data
, boardname
, strlen(boardname
));
778 name_match_found
= true;
779 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
780 "boot found match for name '%s'",
783 case ATH10K_BD_IE_BOARD_DATA
:
784 if (!name_match_found
)
788 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
789 "boot found board data for '%s'",
792 ar
->board_data
= board_ie_data
;
793 ar
->board_len
= board_ie_len
;
798 ath10k_warn(ar
, "unknown ATH10K_BD_IE_BOARD found: %d\n",
803 /* jump over the padding */
804 board_ie_len
= ALIGN(board_ie_len
, 4);
806 buf_len
-= board_ie_len
;
817 static int ath10k_core_fetch_board_data_api_n(struct ath10k
*ar
,
818 const char *boardname
,
819 const char *filename
)
821 size_t len
, magic_len
, ie_len
;
822 struct ath10k_fw_ie
*hdr
;
826 ar
->board
= ath10k_fetch_fw_file(ar
, ar
->hw_params
.fw
.dir
, filename
);
827 if (IS_ERR(ar
->board
))
828 return PTR_ERR(ar
->board
);
830 data
= ar
->board
->data
;
831 len
= ar
->board
->size
;
833 /* magic has extra null byte padded */
834 magic_len
= strlen(ATH10K_BOARD_MAGIC
) + 1;
835 if (len
< magic_len
) {
836 ath10k_err(ar
, "failed to find magic value in %s/%s, file too short: %zu\n",
837 ar
->hw_params
.fw
.dir
, filename
, len
);
842 if (memcmp(data
, ATH10K_BOARD_MAGIC
, magic_len
)) {
843 ath10k_err(ar
, "found invalid board magic\n");
848 /* magic is padded to 4 bytes */
849 magic_len
= ALIGN(magic_len
, 4);
850 if (len
< magic_len
) {
851 ath10k_err(ar
, "failed: %s/%s too small to contain board data, len: %zu\n",
852 ar
->hw_params
.fw
.dir
, filename
, len
);
860 while (len
> sizeof(struct ath10k_fw_ie
)) {
861 hdr
= (struct ath10k_fw_ie
*)data
;
862 ie_id
= le32_to_cpu(hdr
->id
);
863 ie_len
= le32_to_cpu(hdr
->len
);
868 if (len
< ALIGN(ie_len
, 4)) {
869 ath10k_err(ar
, "invalid length for board ie_id %d ie_len %zu len %zu\n",
876 case ATH10K_BD_IE_BOARD
:
877 ret
= ath10k_core_parse_bd_ie_board(ar
, data
, ie_len
,
880 /* no match found, continue */
883 /* there was an error, bail out */
886 /* board data found */
890 /* jump over the padding */
891 ie_len
= ALIGN(ie_len
, 4);
898 if (!ar
->board_data
|| !ar
->board_len
) {
900 "failed to fetch board data for %s from %s/%s\n",
901 ar
->hw_params
.fw
.dir
, boardname
, filename
);
909 ath10k_core_free_board_files(ar
);
913 static int ath10k_core_create_board_name(struct ath10k
*ar
, char *name
,
916 if (ar
->id
.bmi_ids_valid
) {
917 scnprintf(name
, name_len
,
918 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d",
919 ath10k_bus_str(ar
->hif
.bus
),
921 ar
->id
.bmi_board_id
);
925 scnprintf(name
, name_len
,
926 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
927 ath10k_bus_str(ar
->hif
.bus
),
928 ar
->id
.vendor
, ar
->id
.device
,
929 ar
->id
.subsystem_vendor
, ar
->id
.subsystem_device
);
932 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot using board name '%s'\n", name
);
937 static int ath10k_core_fetch_board_file(struct ath10k
*ar
)
942 ret
= ath10k_core_create_board_name(ar
, boardname
, sizeof(boardname
));
944 ath10k_err(ar
, "failed to create board name: %d", ret
);
949 ret
= ath10k_core_fetch_board_data_api_n(ar
, boardname
,
950 ATH10K_BOARD_API2_FILE
);
955 ret
= ath10k_core_fetch_board_data_api_1(ar
);
957 ath10k_err(ar
, "failed to fetch board data\n");
962 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "using board api %d\n", ar
->bd_api
);
966 static int ath10k_core_fetch_firmware_api_1(struct ath10k
*ar
)
970 if (ar
->hw_params
.fw
.fw
== NULL
) {
971 ath10k_err(ar
, "firmware file not defined\n");
975 ar
->firmware
= ath10k_fetch_fw_file(ar
,
976 ar
->hw_params
.fw
.dir
,
977 ar
->hw_params
.fw
.fw
);
978 if (IS_ERR(ar
->firmware
)) {
979 ret
= PTR_ERR(ar
->firmware
);
980 ath10k_err(ar
, "could not fetch firmware (%d)\n", ret
);
984 ar
->firmware_data
= ar
->firmware
->data
;
985 ar
->firmware_len
= ar
->firmware
->size
;
987 /* OTP may be undefined. If so, don't fetch it at all */
988 if (ar
->hw_params
.fw
.otp
== NULL
)
991 ar
->otp
= ath10k_fetch_fw_file(ar
,
992 ar
->hw_params
.fw
.dir
,
993 ar
->hw_params
.fw
.otp
);
994 if (IS_ERR(ar
->otp
)) {
995 ret
= PTR_ERR(ar
->otp
);
996 ath10k_err(ar
, "could not fetch otp (%d)\n", ret
);
1000 ar
->otp_data
= ar
->otp
->data
;
1001 ar
->otp_len
= ar
->otp
->size
;
1006 ath10k_core_free_firmware_files(ar
);
1010 static int ath10k_core_fetch_firmware_api_n(struct ath10k
*ar
, const char *name
)
1012 size_t magic_len
, len
, ie_len
;
1013 int ie_id
, i
, index
, bit
, ret
;
1014 struct ath10k_fw_ie
*hdr
;
1016 __le32
*timestamp
, *version
;
1018 /* first fetch the firmware file (firmware-*.bin) */
1019 ar
->firmware
= ath10k_fetch_fw_file(ar
, ar
->hw_params
.fw
.dir
, name
);
1020 if (IS_ERR(ar
->firmware
)) {
1021 ath10k_err(ar
, "could not fetch firmware file '%s/%s': %ld\n",
1022 ar
->hw_params
.fw
.dir
, name
, PTR_ERR(ar
->firmware
));
1023 return PTR_ERR(ar
->firmware
);
1026 data
= ar
->firmware
->data
;
1027 len
= ar
->firmware
->size
;
1029 /* magic also includes the null byte, check that as well */
1030 magic_len
= strlen(ATH10K_FIRMWARE_MAGIC
) + 1;
1032 if (len
< magic_len
) {
1033 ath10k_err(ar
, "firmware file '%s/%s' too small to contain magic: %zu\n",
1034 ar
->hw_params
.fw
.dir
, name
, len
);
1039 if (memcmp(data
, ATH10K_FIRMWARE_MAGIC
, magic_len
) != 0) {
1040 ath10k_err(ar
, "invalid firmware magic\n");
1045 /* jump over the padding */
1046 magic_len
= ALIGN(magic_len
, 4);
1052 while (len
> sizeof(struct ath10k_fw_ie
)) {
1053 hdr
= (struct ath10k_fw_ie
*)data
;
1055 ie_id
= le32_to_cpu(hdr
->id
);
1056 ie_len
= le32_to_cpu(hdr
->len
);
1058 len
-= sizeof(*hdr
);
1059 data
+= sizeof(*hdr
);
1062 ath10k_err(ar
, "invalid length for FW IE %d (%zu < %zu)\n",
1063 ie_id
, len
, ie_len
);
1069 case ATH10K_FW_IE_FW_VERSION
:
1070 if (ie_len
> sizeof(ar
->hw
->wiphy
->fw_version
) - 1)
1073 memcpy(ar
->hw
->wiphy
->fw_version
, data
, ie_len
);
1074 ar
->hw
->wiphy
->fw_version
[ie_len
] = '\0';
1076 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1077 "found fw version %s\n",
1078 ar
->hw
->wiphy
->fw_version
);
1080 case ATH10K_FW_IE_TIMESTAMP
:
1081 if (ie_len
!= sizeof(u32
))
1084 timestamp
= (__le32
*)data
;
1086 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw timestamp %d\n",
1087 le32_to_cpup(timestamp
));
1089 case ATH10K_FW_IE_FEATURES
:
1090 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1091 "found firmware features ie (%zd B)\n",
1094 for (i
= 0; i
< ATH10K_FW_FEATURE_COUNT
; i
++) {
1098 if (index
== ie_len
)
1101 if (data
[index
] & (1 << bit
)) {
1102 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1103 "Enabling feature bit: %i\n",
1105 __set_bit(i
, ar
->fw_features
);
1109 ath10k_dbg_dump(ar
, ATH10K_DBG_BOOT
, "features", "",
1111 sizeof(ar
->fw_features
));
1113 case ATH10K_FW_IE_FW_IMAGE
:
1114 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1115 "found fw image ie (%zd B)\n",
1118 ar
->firmware_data
= data
;
1119 ar
->firmware_len
= ie_len
;
1122 case ATH10K_FW_IE_OTP_IMAGE
:
1123 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1124 "found otp image ie (%zd B)\n",
1127 ar
->otp_data
= data
;
1128 ar
->otp_len
= ie_len
;
1131 case ATH10K_FW_IE_WMI_OP_VERSION
:
1132 if (ie_len
!= sizeof(u32
))
1135 version
= (__le32
*)data
;
1137 ar
->wmi
.op_version
= le32_to_cpup(version
);
1139 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw ie wmi op version %d\n",
1140 ar
->wmi
.op_version
);
1142 case ATH10K_FW_IE_HTT_OP_VERSION
:
1143 if (ie_len
!= sizeof(u32
))
1146 version
= (__le32
*)data
;
1148 ar
->htt
.op_version
= le32_to_cpup(version
);
1150 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw ie htt op version %d\n",
1151 ar
->htt
.op_version
);
1153 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE
:
1154 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1155 "found fw code swap image ie (%zd B)\n",
1157 ar
->swap
.firmware_codeswap_data
= data
;
1158 ar
->swap
.firmware_codeswap_len
= ie_len
;
1161 ath10k_warn(ar
, "Unknown FW IE: %u\n",
1162 le32_to_cpu(hdr
->id
));
1166 /* jump over the padding */
1167 ie_len
= ALIGN(ie_len
, 4);
1173 if (!ar
->firmware_data
|| !ar
->firmware_len
) {
1174 ath10k_warn(ar
, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1175 ar
->hw_params
.fw
.dir
, name
);
1183 ath10k_core_free_firmware_files(ar
);
1187 static int ath10k_core_fetch_firmware_files(struct ath10k
*ar
)
1191 /* calibration file is optional, don't check for any errors */
1192 ath10k_fetch_cal_file(ar
);
1195 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1197 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API5_FILE
);
1202 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1204 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API4_FILE
);
1209 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1211 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API3_FILE
);
1216 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1218 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API2_FILE
);
1223 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1225 ret
= ath10k_core_fetch_firmware_api_1(ar
);
1230 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "using fw api %d\n", ar
->fw_api
);
1235 static int ath10k_download_cal_data(struct ath10k
*ar
)
1239 ret
= ath10k_download_cal_file(ar
);
1241 ar
->cal_mode
= ATH10K_CAL_MODE_FILE
;
1245 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1246 "boot did not find a calibration file, try DT next: %d\n",
1249 ret
= ath10k_download_cal_dt(ar
);
1251 ar
->cal_mode
= ATH10K_CAL_MODE_DT
;
1255 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1256 "boot did not find DT entry, try OTP next: %d\n",
1259 ret
= ath10k_download_and_run_otp(ar
);
1261 ath10k_err(ar
, "failed to run otp: %d\n", ret
);
1265 ar
->cal_mode
= ATH10K_CAL_MODE_OTP
;
1268 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot using calibration mode %s\n",
1269 ath10k_cal_mode_str(ar
->cal_mode
));
1273 static int ath10k_init_uart(struct ath10k
*ar
)
1278 * Explicitly setting UART prints to zero as target turns it on
1279 * based on scratch registers.
1281 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 0);
1283 ath10k_warn(ar
, "could not disable UART prints (%d)\n", ret
);
1290 ret
= ath10k_bmi_write32(ar
, hi_dbg_uart_txpin
, ar
->hw_params
.uart_pin
);
1292 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
1296 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 1);
1298 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
1302 /* Set the UART baud rate to 19200. */
1303 ret
= ath10k_bmi_write32(ar
, hi_desired_baud_rate
, 19200);
1305 ath10k_warn(ar
, "could not set the baud rate (%d)\n", ret
);
1309 ath10k_info(ar
, "UART prints enabled\n");
1313 static int ath10k_init_hw_params(struct ath10k
*ar
)
1315 const struct ath10k_hw_params
*uninitialized_var(hw_params
);
1318 for (i
= 0; i
< ARRAY_SIZE(ath10k_hw_params_list
); i
++) {
1319 hw_params
= &ath10k_hw_params_list
[i
];
1321 if (hw_params
->id
== ar
->target_version
&&
1322 hw_params
->dev_id
== ar
->dev_id
)
1326 if (i
== ARRAY_SIZE(ath10k_hw_params_list
)) {
1327 ath10k_err(ar
, "Unsupported hardware version: 0x%x\n",
1328 ar
->target_version
);
1332 ar
->hw_params
= *hw_params
;
1334 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "Hardware name %s version 0x%x\n",
1335 ar
->hw_params
.name
, ar
->target_version
);
1340 static void ath10k_core_restart(struct work_struct
*work
)
1342 struct ath10k
*ar
= container_of(work
, struct ath10k
, restart_work
);
1344 set_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
);
1346 /* Place a barrier to make sure the compiler doesn't reorder
1347 * CRASH_FLUSH and calling other functions.
1351 ieee80211_stop_queues(ar
->hw
);
1352 ath10k_drain_tx(ar
);
1353 complete_all(&ar
->scan
.started
);
1354 complete_all(&ar
->scan
.completed
);
1355 complete_all(&ar
->scan
.on_channel
);
1356 complete_all(&ar
->offchan_tx_completed
);
1357 complete_all(&ar
->install_key_done
);
1358 complete_all(&ar
->vdev_setup_done
);
1359 complete_all(&ar
->thermal
.wmi_sync
);
1360 wake_up(&ar
->htt
.empty_tx_wq
);
1361 wake_up(&ar
->wmi
.tx_credits_wq
);
1362 wake_up(&ar
->peer_mapping_wq
);
1364 mutex_lock(&ar
->conf_mutex
);
1366 switch (ar
->state
) {
1367 case ATH10K_STATE_ON
:
1368 ar
->state
= ATH10K_STATE_RESTARTING
;
1369 ath10k_hif_stop(ar
);
1370 ath10k_scan_finish(ar
);
1371 ieee80211_restart_hw(ar
->hw
);
1373 case ATH10K_STATE_OFF
:
1374 /* this can happen if driver is being unloaded
1375 * or if the crash happens during FW probing */
1376 ath10k_warn(ar
, "cannot restart a device that hasn't been started\n");
1378 case ATH10K_STATE_RESTARTING
:
1379 /* hw restart might be requested from multiple places */
1381 case ATH10K_STATE_RESTARTED
:
1382 ar
->state
= ATH10K_STATE_WEDGED
;
1384 case ATH10K_STATE_WEDGED
:
1385 ath10k_warn(ar
, "device is wedged, will not restart\n");
1387 case ATH10K_STATE_UTF
:
1388 ath10k_warn(ar
, "firmware restart in UTF mode not supported\n");
1392 mutex_unlock(&ar
->conf_mutex
);
1395 static int ath10k_core_init_firmware_features(struct ath10k
*ar
)
1397 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2
, ar
->fw_features
) &&
1398 !test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
1399 ath10k_err(ar
, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1403 if (ar
->wmi
.op_version
>= ATH10K_FW_WMI_OP_VERSION_MAX
) {
1404 ath10k_err(ar
, "unsupported WMI OP version (max %d): %d\n",
1405 ATH10K_FW_WMI_OP_VERSION_MAX
, ar
->wmi
.op_version
);
1409 ar
->wmi
.rx_decap_mode
= ATH10K_HW_TXRX_NATIVE_WIFI
;
1410 switch (ath10k_cryptmode_param
) {
1411 case ATH10K_CRYPT_MODE_HW
:
1412 clear_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
);
1413 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
);
1415 case ATH10K_CRYPT_MODE_SW
:
1416 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT
,
1418 ath10k_err(ar
, "cryptmode > 0 requires raw mode support from firmware");
1422 set_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
);
1423 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
);
1426 ath10k_info(ar
, "invalid cryptmode: %d\n",
1427 ath10k_cryptmode_param
);
1431 ar
->htt
.max_num_amsdu
= ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT
;
1432 ar
->htt
.max_num_ampdu
= ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT
;
1435 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT
,
1437 ath10k_err(ar
, "rawmode = 1 requires support from firmware");
1440 set_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
);
1443 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
1444 ar
->wmi
.rx_decap_mode
= ATH10K_HW_TXRX_RAW
;
1448 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1449 * and causes enormous performance issues (malformed frames,
1452 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1453 * albeit a bit slower compared to regular operation.
1455 ar
->htt
.max_num_amsdu
= 1;
1458 /* Backwards compatibility for firmwares without
1459 * ATH10K_FW_IE_WMI_OP_VERSION.
1461 if (ar
->wmi
.op_version
== ATH10K_FW_WMI_OP_VERSION_UNSET
) {
1462 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
1463 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2
,
1465 ar
->wmi
.op_version
= ATH10K_FW_WMI_OP_VERSION_10_2
;
1467 ar
->wmi
.op_version
= ATH10K_FW_WMI_OP_VERSION_10_1
;
1469 ar
->wmi
.op_version
= ATH10K_FW_WMI_OP_VERSION_MAIN
;
1473 switch (ar
->wmi
.op_version
) {
1474 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
1475 ar
->max_num_peers
= TARGET_NUM_PEERS
;
1476 ar
->max_num_stations
= TARGET_NUM_STATIONS
;
1477 ar
->max_num_vdevs
= TARGET_NUM_VDEVS
;
1478 ar
->htt
.max_num_pending_tx
= TARGET_NUM_MSDU_DESC
;
1479 ar
->fw_stats_req_mask
= WMI_STAT_PDEV
| WMI_STAT_VDEV
|
1481 ar
->max_spatial_stream
= WMI_MAX_SPATIAL_STREAM
;
1483 case ATH10K_FW_WMI_OP_VERSION_10_1
:
1484 case ATH10K_FW_WMI_OP_VERSION_10_2
:
1485 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
1486 ar
->max_num_peers
= TARGET_10X_NUM_PEERS
;
1487 ar
->max_num_stations
= TARGET_10X_NUM_STATIONS
;
1488 ar
->max_num_vdevs
= TARGET_10X_NUM_VDEVS
;
1489 ar
->htt
.max_num_pending_tx
= TARGET_10X_NUM_MSDU_DESC
;
1490 ar
->fw_stats_req_mask
= WMI_STAT_PEER
;
1491 ar
->max_spatial_stream
= WMI_MAX_SPATIAL_STREAM
;
1493 case ATH10K_FW_WMI_OP_VERSION_TLV
:
1494 ar
->max_num_peers
= TARGET_TLV_NUM_PEERS
;
1495 ar
->max_num_stations
= TARGET_TLV_NUM_STATIONS
;
1496 ar
->max_num_vdevs
= TARGET_TLV_NUM_VDEVS
;
1497 ar
->max_num_tdls_vdevs
= TARGET_TLV_NUM_TDLS_VDEVS
;
1498 ar
->htt
.max_num_pending_tx
= TARGET_TLV_NUM_MSDU_DESC
;
1499 ar
->wow
.max_num_patterns
= TARGET_TLV_NUM_WOW_PATTERNS
;
1500 ar
->fw_stats_req_mask
= WMI_STAT_PDEV
| WMI_STAT_VDEV
|
1502 ar
->max_spatial_stream
= WMI_MAX_SPATIAL_STREAM
;
1504 case ATH10K_FW_WMI_OP_VERSION_10_4
:
1505 ar
->max_num_peers
= TARGET_10_4_NUM_PEERS
;
1506 ar
->max_num_stations
= TARGET_10_4_NUM_STATIONS
;
1507 ar
->num_active_peers
= TARGET_10_4_ACTIVE_PEERS
;
1508 ar
->max_num_vdevs
= TARGET_10_4_NUM_VDEVS
;
1509 ar
->num_tids
= TARGET_10_4_TGT_NUM_TIDS
;
1510 ar
->htt
.max_num_pending_tx
= TARGET_10_4_NUM_MSDU_DESC
;
1511 ar
->fw_stats_req_mask
= WMI_STAT_PEER
;
1512 ar
->max_spatial_stream
= WMI_10_4_MAX_SPATIAL_STREAM
;
1514 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
1515 case ATH10K_FW_WMI_OP_VERSION_MAX
:
1520 /* Backwards compatibility for firmwares without
1521 * ATH10K_FW_IE_HTT_OP_VERSION.
1523 if (ar
->htt
.op_version
== ATH10K_FW_HTT_OP_VERSION_UNSET
) {
1524 switch (ar
->wmi
.op_version
) {
1525 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
1526 ar
->htt
.op_version
= ATH10K_FW_HTT_OP_VERSION_MAIN
;
1528 case ATH10K_FW_WMI_OP_VERSION_10_1
:
1529 case ATH10K_FW_WMI_OP_VERSION_10_2
:
1530 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
1531 ar
->htt
.op_version
= ATH10K_FW_HTT_OP_VERSION_10_1
;
1533 case ATH10K_FW_WMI_OP_VERSION_TLV
:
1534 ar
->htt
.op_version
= ATH10K_FW_HTT_OP_VERSION_TLV
;
1536 case ATH10K_FW_WMI_OP_VERSION_10_4
:
1537 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
1538 case ATH10K_FW_WMI_OP_VERSION_MAX
:
1547 int ath10k_core_start(struct ath10k
*ar
, enum ath10k_firmware_mode mode
)
1551 lockdep_assert_held(&ar
->conf_mutex
);
1553 clear_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
);
1555 ath10k_bmi_start(ar
);
1557 if (ath10k_init_configure_target(ar
)) {
1562 status
= ath10k_download_cal_data(ar
);
1566 /* Some of of qca988x solutions are having global reset issue
1567 * during target initialization. Bypassing PLL setting before
1568 * downloading firmware and letting the SoC run on REF_CLK is
1569 * fixing the problem. Corresponding firmware change is also needed
1570 * to set the clock source once the target is initialized.
1572 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT
,
1574 status
= ath10k_bmi_write32(ar
, hi_skip_clock_init
, 1);
1576 ath10k_err(ar
, "could not write to skip_clock_init: %d\n",
1582 status
= ath10k_download_fw(ar
, mode
);
1586 status
= ath10k_init_uart(ar
);
1590 ar
->htc
.htc_ops
.target_send_suspend_complete
=
1591 ath10k_send_suspend_complete
;
1593 status
= ath10k_htc_init(ar
);
1595 ath10k_err(ar
, "could not init HTC (%d)\n", status
);
1599 status
= ath10k_bmi_done(ar
);
1603 status
= ath10k_wmi_attach(ar
);
1605 ath10k_err(ar
, "WMI attach failed: %d\n", status
);
1609 status
= ath10k_htt_init(ar
);
1611 ath10k_err(ar
, "failed to init htt: %d\n", status
);
1612 goto err_wmi_detach
;
1615 status
= ath10k_htt_tx_alloc(&ar
->htt
);
1617 ath10k_err(ar
, "failed to alloc htt tx: %d\n", status
);
1618 goto err_wmi_detach
;
1621 /* If firmware indicates Full Rx Reorder support it must be used in a
1622 * slightly different manner. Let HTT code know.
1624 ar
->htt
.rx_ring
.in_ord_rx
= !!(test_bit(WMI_SERVICE_RX_FULL_REORDER
,
1627 status
= ath10k_htt_rx_alloc(&ar
->htt
);
1629 ath10k_err(ar
, "failed to alloc htt rx: %d\n", status
);
1630 goto err_htt_tx_detach
;
1633 status
= ath10k_hif_start(ar
);
1635 ath10k_err(ar
, "could not start HIF: %d\n", status
);
1636 goto err_htt_rx_detach
;
1639 status
= ath10k_htc_wait_target(&ar
->htc
);
1641 ath10k_err(ar
, "failed to connect to HTC: %d\n", status
);
1645 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1646 status
= ath10k_htt_connect(&ar
->htt
);
1648 ath10k_err(ar
, "failed to connect htt (%d)\n", status
);
1653 status
= ath10k_wmi_connect(ar
);
1655 ath10k_err(ar
, "could not connect wmi: %d\n", status
);
1659 status
= ath10k_htc_start(&ar
->htc
);
1661 ath10k_err(ar
, "failed to start htc: %d\n", status
);
1665 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1666 status
= ath10k_wmi_wait_for_service_ready(ar
);
1668 ath10k_warn(ar
, "wmi service ready event not received");
1673 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "firmware %s booted\n",
1674 ar
->hw
->wiphy
->fw_version
);
1676 status
= ath10k_wmi_cmd_init(ar
);
1678 ath10k_err(ar
, "could not send WMI init command (%d)\n",
1683 status
= ath10k_wmi_wait_for_unified_ready(ar
);
1685 ath10k_err(ar
, "wmi unified ready event not received\n");
1689 status
= ath10k_htt_rx_ring_refill(ar
);
1691 ath10k_err(ar
, "failed to refill htt rx ring: %d\n", status
);
1695 ar
->free_vdev_map
= (1LL << ar
->max_num_vdevs
) - 1;
1697 INIT_LIST_HEAD(&ar
->arvifs
);
1699 /* we don't care about HTT in UTF mode */
1700 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1701 status
= ath10k_htt_setup(&ar
->htt
);
1703 ath10k_err(ar
, "failed to setup htt: %d\n", status
);
1708 status
= ath10k_debug_start(ar
);
1715 ath10k_hif_stop(ar
);
1717 ath10k_htt_rx_free(&ar
->htt
);
1719 ath10k_htt_tx_free(&ar
->htt
);
1721 ath10k_wmi_detach(ar
);
1725 EXPORT_SYMBOL(ath10k_core_start
);
1727 int ath10k_wait_for_suspend(struct ath10k
*ar
, u32 suspend_opt
)
1730 unsigned long time_left
;
1732 reinit_completion(&ar
->target_suspend
);
1734 ret
= ath10k_wmi_pdev_suspend_target(ar
, suspend_opt
);
1736 ath10k_warn(ar
, "could not suspend target (%d)\n", ret
);
1740 time_left
= wait_for_completion_timeout(&ar
->target_suspend
, 1 * HZ
);
1743 ath10k_warn(ar
, "suspend timed out - target pause event never came\n");
1750 void ath10k_core_stop(struct ath10k
*ar
)
1752 lockdep_assert_held(&ar
->conf_mutex
);
1753 ath10k_debug_stop(ar
);
1755 /* try to suspend target */
1756 if (ar
->state
!= ATH10K_STATE_RESTARTING
&&
1757 ar
->state
!= ATH10K_STATE_UTF
)
1758 ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND_AND_DISABLE_INTR
);
1760 ath10k_hif_stop(ar
);
1761 ath10k_htt_tx_free(&ar
->htt
);
1762 ath10k_htt_rx_free(&ar
->htt
);
1763 ath10k_wmi_detach(ar
);
1765 EXPORT_SYMBOL(ath10k_core_stop
);
1767 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1768 * order to know what hw capabilities should be advertised to mac80211 it is
1769 * necessary to load the firmware (and tear it down immediately since start
1770 * hook will try to init it again) before registering */
1771 static int ath10k_core_probe_fw(struct ath10k
*ar
)
1773 struct bmi_target_info target_info
;
1776 ret
= ath10k_hif_power_up(ar
);
1778 ath10k_err(ar
, "could not start pci hif (%d)\n", ret
);
1782 memset(&target_info
, 0, sizeof(target_info
));
1783 ret
= ath10k_bmi_get_target_info(ar
, &target_info
);
1785 ath10k_err(ar
, "could not get target info (%d)\n", ret
);
1786 goto err_power_down
;
1789 ar
->target_version
= target_info
.version
;
1790 ar
->hw
->wiphy
->hw_version
= target_info
.version
;
1792 ret
= ath10k_init_hw_params(ar
);
1794 ath10k_err(ar
, "could not get hw params (%d)\n", ret
);
1795 goto err_power_down
;
1798 ret
= ath10k_core_fetch_firmware_files(ar
);
1800 ath10k_err(ar
, "could not fetch firmware files (%d)\n", ret
);
1801 goto err_power_down
;
1804 ret
= ath10k_core_get_board_id_from_otp(ar
);
1805 if (ret
&& ret
!= -EOPNOTSUPP
) {
1806 ath10k_err(ar
, "failed to get board id from otp for qca99x0: %d\n",
1811 ret
= ath10k_core_fetch_board_file(ar
);
1813 ath10k_err(ar
, "failed to fetch board file: %d\n", ret
);
1814 goto err_free_firmware_files
;
1817 ret
= ath10k_core_init_firmware_features(ar
);
1819 ath10k_err(ar
, "fatal problem with firmware features: %d\n",
1821 goto err_free_firmware_files
;
1824 ret
= ath10k_swap_code_seg_init(ar
);
1826 ath10k_err(ar
, "failed to initialize code swap segment: %d\n",
1828 goto err_free_firmware_files
;
1831 mutex_lock(&ar
->conf_mutex
);
1833 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
1835 ath10k_err(ar
, "could not init core (%d)\n", ret
);
1839 ath10k_print_driver_info(ar
);
1840 ath10k_core_stop(ar
);
1842 mutex_unlock(&ar
->conf_mutex
);
1844 ath10k_hif_power_down(ar
);
1848 mutex_unlock(&ar
->conf_mutex
);
1850 err_free_firmware_files
:
1851 ath10k_core_free_firmware_files(ar
);
1854 ath10k_hif_power_down(ar
);
1859 static void ath10k_core_register_work(struct work_struct
*work
)
1861 struct ath10k
*ar
= container_of(work
, struct ath10k
, register_work
);
1864 status
= ath10k_core_probe_fw(ar
);
1866 ath10k_err(ar
, "could not probe fw (%d)\n", status
);
1870 status
= ath10k_mac_register(ar
);
1872 ath10k_err(ar
, "could not register to mac80211 (%d)\n", status
);
1873 goto err_release_fw
;
1876 status
= ath10k_debug_register(ar
);
1878 ath10k_err(ar
, "unable to initialize debugfs\n");
1879 goto err_unregister_mac
;
1882 status
= ath10k_spectral_create(ar
);
1884 ath10k_err(ar
, "failed to initialize spectral\n");
1885 goto err_debug_destroy
;
1888 status
= ath10k_thermal_register(ar
);
1890 ath10k_err(ar
, "could not register thermal device: %d\n",
1892 goto err_spectral_destroy
;
1895 set_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
);
1898 err_spectral_destroy
:
1899 ath10k_spectral_destroy(ar
);
1901 ath10k_debug_destroy(ar
);
1903 ath10k_mac_unregister(ar
);
1905 ath10k_core_free_firmware_files(ar
);
1907 /* TODO: It's probably a good idea to release device from the driver
1908 * but calling device_release_driver() here will cause a deadlock.
1913 int ath10k_core_register(struct ath10k
*ar
, u32 chip_id
)
1915 ar
->chip_id
= chip_id
;
1916 queue_work(ar
->workqueue
, &ar
->register_work
);
1920 EXPORT_SYMBOL(ath10k_core_register
);
1922 void ath10k_core_unregister(struct ath10k
*ar
)
1924 cancel_work_sync(&ar
->register_work
);
1926 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
))
1929 ath10k_thermal_unregister(ar
);
1930 /* Stop spectral before unregistering from mac80211 to remove the
1931 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
1932 * would be already be free'd recursively, leading to a double free.
1934 ath10k_spectral_destroy(ar
);
1936 /* We must unregister from mac80211 before we stop HTC and HIF.
1937 * Otherwise we will fail to submit commands to FW and mac80211 will be
1938 * unhappy about callback failures. */
1939 ath10k_mac_unregister(ar
);
1941 ath10k_testmode_destroy(ar
);
1943 ath10k_core_free_firmware_files(ar
);
1944 ath10k_core_free_board_files(ar
);
1946 ath10k_debug_unregister(ar
);
1948 EXPORT_SYMBOL(ath10k_core_unregister
);
1950 struct ath10k
*ath10k_core_create(size_t priv_size
, struct device
*dev
,
1951 enum ath10k_bus bus
,
1952 enum ath10k_hw_rev hw_rev
,
1953 const struct ath10k_hif_ops
*hif_ops
)
1958 ar
= ath10k_mac_create(priv_size
);
1962 ar
->ath_common
.priv
= ar
;
1963 ar
->ath_common
.hw
= ar
->hw
;
1965 ar
->hw_rev
= hw_rev
;
1966 ar
->hif
.ops
= hif_ops
;
1970 case ATH10K_HW_QCA988X
:
1971 ar
->regs
= &qca988x_regs
;
1972 ar
->hw_values
= &qca988x_values
;
1974 case ATH10K_HW_QCA6174
:
1975 case ATH10K_HW_QCA9377
:
1976 ar
->regs
= &qca6174_regs
;
1977 ar
->hw_values
= &qca6174_values
;
1979 case ATH10K_HW_QCA99X0
:
1980 ar
->regs
= &qca99x0_regs
;
1981 ar
->hw_values
= &qca99x0_values
;
1984 ath10k_err(ar
, "unsupported core hardware revision %d\n",
1990 init_completion(&ar
->scan
.started
);
1991 init_completion(&ar
->scan
.completed
);
1992 init_completion(&ar
->scan
.on_channel
);
1993 init_completion(&ar
->target_suspend
);
1994 init_completion(&ar
->wow
.wakeup_completed
);
1996 init_completion(&ar
->install_key_done
);
1997 init_completion(&ar
->vdev_setup_done
);
1998 init_completion(&ar
->thermal
.wmi_sync
);
2000 INIT_DELAYED_WORK(&ar
->scan
.timeout
, ath10k_scan_timeout_work
);
2002 ar
->workqueue
= create_singlethread_workqueue("ath10k_wq");
2006 ar
->workqueue_aux
= create_singlethread_workqueue("ath10k_aux_wq");
2007 if (!ar
->workqueue_aux
)
2010 mutex_init(&ar
->conf_mutex
);
2011 spin_lock_init(&ar
->data_lock
);
2013 INIT_LIST_HEAD(&ar
->peers
);
2014 init_waitqueue_head(&ar
->peer_mapping_wq
);
2015 init_waitqueue_head(&ar
->htt
.empty_tx_wq
);
2016 init_waitqueue_head(&ar
->wmi
.tx_credits_wq
);
2018 init_completion(&ar
->offchan_tx_completed
);
2019 INIT_WORK(&ar
->offchan_tx_work
, ath10k_offchan_tx_work
);
2020 skb_queue_head_init(&ar
->offchan_tx_queue
);
2022 INIT_WORK(&ar
->wmi_mgmt_tx_work
, ath10k_mgmt_over_wmi_tx_work
);
2023 skb_queue_head_init(&ar
->wmi_mgmt_tx_queue
);
2025 INIT_WORK(&ar
->register_work
, ath10k_core_register_work
);
2026 INIT_WORK(&ar
->restart_work
, ath10k_core_restart
);
2028 ret
= ath10k_debug_create(ar
);
2030 goto err_free_aux_wq
;
2035 destroy_workqueue(ar
->workqueue_aux
);
2037 destroy_workqueue(ar
->workqueue
);
2040 ath10k_mac_destroy(ar
);
2044 EXPORT_SYMBOL(ath10k_core_create
);
2046 void ath10k_core_destroy(struct ath10k
*ar
)
2048 flush_workqueue(ar
->workqueue
);
2049 destroy_workqueue(ar
->workqueue
);
2051 flush_workqueue(ar
->workqueue_aux
);
2052 destroy_workqueue(ar
->workqueue_aux
);
2054 ath10k_debug_destroy(ar
);
2055 ath10k_wmi_free_host_mem(ar
);
2056 ath10k_mac_destroy(ar
);
2058 EXPORT_SYMBOL(ath10k_core_destroy
);
2060 MODULE_AUTHOR("Qualcomm Atheros");
2061 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
2062 MODULE_LICENSE("Dual BSD/GPL");