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,
62 .hw_4addr_pad
= ATH10K_HW_4ADDR_PAD_AFTER
,
65 .dir
= QCA988X_HW_2_0_FW_DIR
,
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
,
72 .id
= QCA6174_HW_2_1_VERSION
,
73 .dev_id
= QCA6164_2_1_DEVICE_ID
,
74 .name
= "qca6164 hw2.1",
75 .patch_load_addr
= QCA6174_HW_2_1_PATCH_LOAD_ADDR
,
78 .channel_counters_freq_hz
= 88000,
79 .max_probe_resp_desc_thres
= 0,
82 .dir
= QCA6174_HW_2_1_FW_DIR
,
83 .board
= QCA6174_HW_2_1_BOARD_DATA_FILE
,
84 .board_size
= QCA6174_BOARD_DATA_SZ
,
85 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
89 .id
= QCA6174_HW_2_1_VERSION
,
90 .dev_id
= QCA6174_2_1_DEVICE_ID
,
91 .name
= "qca6174 hw2.1",
92 .patch_load_addr
= QCA6174_HW_2_1_PATCH_LOAD_ADDR
,
95 .channel_counters_freq_hz
= 88000,
96 .max_probe_resp_desc_thres
= 0,
97 .hw_4addr_pad
= ATH10K_HW_4ADDR_PAD_AFTER
,
100 .dir
= QCA6174_HW_2_1_FW_DIR
,
101 .board
= QCA6174_HW_2_1_BOARD_DATA_FILE
,
102 .board_size
= QCA6174_BOARD_DATA_SZ
,
103 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
107 .id
= QCA6174_HW_3_0_VERSION
,
108 .dev_id
= QCA6174_2_1_DEVICE_ID
,
109 .name
= "qca6174 hw3.0",
110 .patch_load_addr
= QCA6174_HW_3_0_PATCH_LOAD_ADDR
,
113 .channel_counters_freq_hz
= 88000,
114 .max_probe_resp_desc_thres
= 0,
115 .hw_4addr_pad
= ATH10K_HW_4ADDR_PAD_AFTER
,
116 .cal_data_len
= 8124,
118 .dir
= QCA6174_HW_3_0_FW_DIR
,
119 .board
= QCA6174_HW_3_0_BOARD_DATA_FILE
,
120 .board_size
= QCA6174_BOARD_DATA_SZ
,
121 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
125 .id
= QCA6174_HW_3_2_VERSION
,
126 .dev_id
= QCA6174_2_1_DEVICE_ID
,
127 .name
= "qca6174 hw3.2",
128 .patch_load_addr
= QCA6174_HW_3_0_PATCH_LOAD_ADDR
,
131 .channel_counters_freq_hz
= 88000,
132 .max_probe_resp_desc_thres
= 0,
133 .hw_4addr_pad
= ATH10K_HW_4ADDR_PAD_AFTER
,
134 .cal_data_len
= 8124,
136 /* uses same binaries as hw3.0 */
137 .dir
= QCA6174_HW_3_0_FW_DIR
,
138 .board
= QCA6174_HW_3_0_BOARD_DATA_FILE
,
139 .board_size
= QCA6174_BOARD_DATA_SZ
,
140 .board_ext_size
= QCA6174_BOARD_EXT_DATA_SZ
,
144 .id
= QCA99X0_HW_2_0_DEV_VERSION
,
145 .dev_id
= QCA99X0_2_0_DEVICE_ID
,
146 .name
= "qca99x0 hw2.0",
147 .patch_load_addr
= QCA99X0_HW_2_0_PATCH_LOAD_ADDR
,
149 .otp_exe_param
= 0x00000700,
150 .continuous_frag_desc
= true,
151 .channel_counters_freq_hz
= 150000,
152 .max_probe_resp_desc_thres
= 24,
153 .hw_4addr_pad
= ATH10K_HW_4ADDR_PAD_BEFORE
,
154 .tx_chain_mask
= 0xf,
155 .rx_chain_mask
= 0xf,
156 .max_spatial_stream
= 4,
157 .cal_data_len
= 12064,
159 .dir
= QCA99X0_HW_2_0_FW_DIR
,
160 .board
= QCA99X0_HW_2_0_BOARD_DATA_FILE
,
161 .board_size
= QCA99X0_BOARD_DATA_SZ
,
162 .board_ext_size
= QCA99X0_BOARD_EXT_DATA_SZ
,
166 .id
= QCA9377_HW_1_0_DEV_VERSION
,
167 .dev_id
= QCA9377_1_0_DEVICE_ID
,
168 .name
= "qca9377 hw1.0",
169 .patch_load_addr
= QCA9377_HW_1_0_PATCH_LOAD_ADDR
,
172 .channel_counters_freq_hz
= 88000,
173 .max_probe_resp_desc_thres
= 0,
174 .cal_data_len
= 8124,
176 .dir
= QCA9377_HW_1_0_FW_DIR
,
177 .board
= QCA9377_HW_1_0_BOARD_DATA_FILE
,
178 .board_size
= QCA9377_BOARD_DATA_SZ
,
179 .board_ext_size
= QCA9377_BOARD_EXT_DATA_SZ
,
183 .id
= QCA9377_HW_1_1_DEV_VERSION
,
184 .dev_id
= QCA9377_1_0_DEVICE_ID
,
185 .name
= "qca9377 hw1.1",
186 .patch_load_addr
= QCA9377_HW_1_0_PATCH_LOAD_ADDR
,
189 .channel_counters_freq_hz
= 88000,
190 .max_probe_resp_desc_thres
= 0,
191 .cal_data_len
= 8124,
193 .dir
= QCA9377_HW_1_0_FW_DIR
,
194 .board
= QCA9377_HW_1_0_BOARD_DATA_FILE
,
195 .board_size
= QCA9377_BOARD_DATA_SZ
,
196 .board_ext_size
= QCA9377_BOARD_EXT_DATA_SZ
,
200 .id
= QCA4019_HW_1_0_DEV_VERSION
,
202 .name
= "qca4019 hw1.0",
203 .patch_load_addr
= QCA4019_HW_1_0_PATCH_LOAD_ADDR
,
205 .has_shifted_cc_wraparound
= true,
206 .otp_exe_param
= 0x0010000,
207 .continuous_frag_desc
= true,
208 .channel_counters_freq_hz
= 125000,
209 .max_probe_resp_desc_thres
= 24,
210 .hw_4addr_pad
= ATH10K_HW_4ADDR_PAD_BEFORE
,
211 .tx_chain_mask
= 0x3,
212 .rx_chain_mask
= 0x3,
213 .max_spatial_stream
= 2,
214 .cal_data_len
= 12064,
216 .dir
= QCA4019_HW_1_0_FW_DIR
,
217 .board
= QCA4019_HW_1_0_BOARD_DATA_FILE
,
218 .board_size
= QCA4019_BOARD_DATA_SZ
,
219 .board_ext_size
= QCA4019_BOARD_EXT_DATA_SZ
,
224 static const char *const ath10k_core_fw_feature_str
[] = {
225 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX
] = "wmi-mgmt-rx",
226 [ATH10K_FW_FEATURE_WMI_10X
] = "wmi-10.x",
227 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
] = "has-wmi-mgmt-tx",
228 [ATH10K_FW_FEATURE_NO_P2P
] = "no-p2p",
229 [ATH10K_FW_FEATURE_WMI_10_2
] = "wmi-10.2",
230 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT
] = "multi-vif-ps",
231 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT
] = "wowlan",
232 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT
] = "ignore-otp",
233 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING
] = "no-4addr-pad",
234 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT
] = "skip-clock-init",
235 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT
] = "raw-mode",
236 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA
] = "adaptive-cca",
237 [ATH10K_FW_FEATURE_MFP_SUPPORT
] = "mfp",
238 [ATH10K_FW_FEATURE_PEER_FLOW_CONTROL
] = "peer-flow-ctrl",
241 static unsigned int ath10k_core_get_fw_feature_str(char *buf
,
243 enum ath10k_fw_features feat
)
245 /* make sure that ath10k_core_fw_feature_str[] gets updated */
246 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str
) !=
247 ATH10K_FW_FEATURE_COUNT
);
249 if (feat
>= ARRAY_SIZE(ath10k_core_fw_feature_str
) ||
250 WARN_ON(!ath10k_core_fw_feature_str
[feat
])) {
251 return scnprintf(buf
, buf_len
, "bit%d", feat
);
254 return scnprintf(buf
, buf_len
, "%s", ath10k_core_fw_feature_str
[feat
]);
257 void ath10k_core_get_fw_features_str(struct ath10k
*ar
,
261 unsigned int len
= 0;
264 for (i
= 0; i
< ATH10K_FW_FEATURE_COUNT
; i
++) {
265 if (test_bit(i
, ar
->normal_mode_fw
.fw_file
.fw_features
)) {
267 len
+= scnprintf(buf
+ len
, buf_len
- len
, ",");
269 len
+= ath10k_core_get_fw_feature_str(buf
+ len
,
276 static void ath10k_send_suspend_complete(struct ath10k
*ar
)
278 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot suspend complete\n");
280 complete(&ar
->target_suspend
);
283 static int ath10k_init_configure_target(struct ath10k
*ar
)
288 /* tell target which HTC version it is used*/
289 ret
= ath10k_bmi_write32(ar
, hi_app_host_interest
,
290 HTC_PROTOCOL_VERSION
);
292 ath10k_err(ar
, "settings HTC version failed\n");
296 /* set the firmware mode to STA/IBSS/AP */
297 ret
= ath10k_bmi_read32(ar
, hi_option_flag
, ¶m_host
);
299 ath10k_err(ar
, "setting firmware mode (1/2) failed\n");
303 /* TODO following parameters need to be re-visited. */
305 param_host
|= (1 << HI_OPTION_NUM_DEV_SHIFT
);
307 /* FIXME: Why FW_MODE_AP ??.*/
308 param_host
|= (HI_OPTION_FW_MODE_AP
<< HI_OPTION_FW_MODE_SHIFT
);
309 /* mac_addr_method */
310 param_host
|= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT
);
311 /* firmware_bridge */
312 param_host
|= (0 << HI_OPTION_FW_BRIDGE_SHIFT
);
314 param_host
|= (0 << HI_OPTION_FW_SUBMODE_SHIFT
);
316 ret
= ath10k_bmi_write32(ar
, hi_option_flag
, param_host
);
318 ath10k_err(ar
, "setting firmware mode (2/2) failed\n");
322 /* We do all byte-swapping on the host */
323 ret
= ath10k_bmi_write32(ar
, hi_be
, 0);
325 ath10k_err(ar
, "setting host CPU BE mode failed\n");
329 /* FW descriptor/Data swap flags */
330 ret
= ath10k_bmi_write32(ar
, hi_fw_swap
, 0);
333 ath10k_err(ar
, "setting FW data/desc swap flags failed\n");
337 /* Some devices have a special sanity check that verifies the PCI
338 * Device ID is written to this host interest var. It is known to be
339 * required to boot QCA6164.
341 ret
= ath10k_bmi_write32(ar
, hi_hci_uart_pwr_mgmt_params_ext
,
344 ath10k_err(ar
, "failed to set pwr_mgmt_params: %d\n", ret
);
351 static const struct firmware
*ath10k_fetch_fw_file(struct ath10k
*ar
,
356 const struct firmware
*fw
;
360 return ERR_PTR(-ENOENT
);
365 snprintf(filename
, sizeof(filename
), "%s/%s", dir
, file
);
366 ret
= request_firmware(&fw
, filename
, ar
->dev
);
373 static int ath10k_push_board_ext_data(struct ath10k
*ar
, const void *data
,
376 u32 board_data_size
= ar
->hw_params
.fw
.board_size
;
377 u32 board_ext_data_size
= ar
->hw_params
.fw
.board_ext_size
;
378 u32 board_ext_data_addr
;
381 ret
= ath10k_bmi_read32(ar
, hi_board_ext_data
, &board_ext_data_addr
);
383 ath10k_err(ar
, "could not read board ext data addr (%d)\n",
388 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
389 "boot push board extended data addr 0x%x\n",
390 board_ext_data_addr
);
392 if (board_ext_data_addr
== 0)
395 if (data_len
!= (board_data_size
+ board_ext_data_size
)) {
396 ath10k_err(ar
, "invalid board (ext) data sizes %zu != %d+%d\n",
397 data_len
, board_data_size
, board_ext_data_size
);
401 ret
= ath10k_bmi_write_memory(ar
, board_ext_data_addr
,
402 data
+ board_data_size
,
403 board_ext_data_size
);
405 ath10k_err(ar
, "could not write board ext data (%d)\n", ret
);
409 ret
= ath10k_bmi_write32(ar
, hi_board_ext_data_config
,
410 (board_ext_data_size
<< 16) | 1);
412 ath10k_err(ar
, "could not write board ext data bit (%d)\n",
420 static int ath10k_download_board_data(struct ath10k
*ar
, const void *data
,
423 u32 board_data_size
= ar
->hw_params
.fw
.board_size
;
427 ret
= ath10k_push_board_ext_data(ar
, data
, data_len
);
429 ath10k_err(ar
, "could not push board ext data (%d)\n", ret
);
433 ret
= ath10k_bmi_read32(ar
, hi_board_data
, &address
);
435 ath10k_err(ar
, "could not read board data addr (%d)\n", ret
);
439 ret
= ath10k_bmi_write_memory(ar
, address
, data
,
440 min_t(u32
, board_data_size
,
443 ath10k_err(ar
, "could not write board data (%d)\n", ret
);
447 ret
= ath10k_bmi_write32(ar
, hi_board_data_initialized
, 1);
449 ath10k_err(ar
, "could not write board data bit (%d)\n", ret
);
457 static int ath10k_download_cal_file(struct ath10k
*ar
,
458 const struct firmware
*file
)
466 return PTR_ERR(file
);
468 ret
= ath10k_download_board_data(ar
, file
->data
, file
->size
);
470 ath10k_err(ar
, "failed to download cal_file data: %d\n", ret
);
474 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot cal file downloaded\n");
479 static int ath10k_download_cal_dt(struct ath10k
*ar
, const char *dt_name
)
481 struct device_node
*node
;
486 node
= ar
->dev
->of_node
;
488 /* Device Tree is optional, don't print any warnings if
489 * there's no node for ath10k.
493 if (!of_get_property(node
, dt_name
, &data_len
)) {
494 /* The calibration data node is optional */
498 if (data_len
!= ar
->hw_params
.cal_data_len
) {
499 ath10k_warn(ar
, "invalid calibration data length in DT: %d\n",
505 data
= kmalloc(data_len
, GFP_KERNEL
);
511 ret
= of_property_read_u8_array(node
, dt_name
, data
, data_len
);
513 ath10k_warn(ar
, "failed to read calibration data from DT: %d\n",
518 ret
= ath10k_download_board_data(ar
, data
, data_len
);
520 ath10k_warn(ar
, "failed to download calibration data from Device Tree: %d\n",
534 static int ath10k_core_get_board_id_from_otp(struct ath10k
*ar
)
537 u8 board_id
, chip_id
;
540 address
= ar
->hw_params
.patch_load_addr
;
542 if (!ar
->normal_mode_fw
.fw_file
.otp_data
||
543 !ar
->normal_mode_fw
.fw_file
.otp_len
) {
545 "failed to retrieve board id because of invalid otp\n");
549 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
550 "boot upload otp to 0x%x len %zd for board id\n",
551 address
, ar
->normal_mode_fw
.fw_file
.otp_len
);
553 ret
= ath10k_bmi_fast_download(ar
, address
,
554 ar
->normal_mode_fw
.fw_file
.otp_data
,
555 ar
->normal_mode_fw
.fw_file
.otp_len
);
557 ath10k_err(ar
, "could not write otp for board id check: %d\n",
562 ret
= ath10k_bmi_execute(ar
, address
, BMI_PARAM_GET_EEPROM_BOARD_ID
,
565 ath10k_err(ar
, "could not execute otp for board id check: %d\n",
570 board_id
= MS(result
, ATH10K_BMI_BOARD_ID_FROM_OTP
);
571 chip_id
= MS(result
, ATH10K_BMI_CHIP_ID_FROM_OTP
);
573 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
574 "boot get otp board id result 0x%08x board_id %d chip_id %d\n",
575 result
, board_id
, chip_id
);
577 if ((result
& ATH10K_BMI_BOARD_ID_STATUS_MASK
) != 0)
580 ar
->id
.bmi_ids_valid
= true;
581 ar
->id
.bmi_board_id
= board_id
;
582 ar
->id
.bmi_chip_id
= chip_id
;
587 static int ath10k_download_and_run_otp(struct ath10k
*ar
)
589 u32 result
, address
= ar
->hw_params
.patch_load_addr
;
590 u32 bmi_otp_exe_param
= ar
->hw_params
.otp_exe_param
;
593 ret
= ath10k_download_board_data(ar
,
594 ar
->running_fw
->board_data
,
595 ar
->running_fw
->board_len
);
597 ath10k_err(ar
, "failed to download board data: %d\n", ret
);
601 /* OTP is optional */
603 if (!ar
->running_fw
->fw_file
.otp_data
||
604 !ar
->running_fw
->fw_file
.otp_len
) {
605 ath10k_warn(ar
, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n",
606 ar
->running_fw
->fw_file
.otp_data
,
607 ar
->running_fw
->fw_file
.otp_len
);
611 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot upload otp to 0x%x len %zd\n",
612 address
, ar
->running_fw
->fw_file
.otp_len
);
614 ret
= ath10k_bmi_fast_download(ar
, address
,
615 ar
->running_fw
->fw_file
.otp_data
,
616 ar
->running_fw
->fw_file
.otp_len
);
618 ath10k_err(ar
, "could not write otp (%d)\n", ret
);
622 ret
= ath10k_bmi_execute(ar
, address
, bmi_otp_exe_param
, &result
);
624 ath10k_err(ar
, "could not execute otp (%d)\n", ret
);
628 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot otp execute result %d\n", result
);
630 if (!(skip_otp
|| test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT
,
631 ar
->running_fw
->fw_file
.fw_features
)) &&
633 ath10k_err(ar
, "otp calibration failed: %d", result
);
640 static int ath10k_download_fw(struct ath10k
*ar
)
642 u32 address
, data_len
;
646 address
= ar
->hw_params
.patch_load_addr
;
648 data
= ar
->running_fw
->fw_file
.firmware_data
;
649 data_len
= ar
->running_fw
->fw_file
.firmware_len
;
651 ret
= ath10k_swap_code_seg_configure(ar
);
653 ath10k_err(ar
, "failed to configure fw code swap: %d\n",
658 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
659 "boot uploading firmware image %p len %d\n",
662 ret
= ath10k_bmi_fast_download(ar
, address
, data
, data_len
);
664 ath10k_err(ar
, "failed to download firmware: %d\n",
672 static void ath10k_core_free_board_files(struct ath10k
*ar
)
674 if (!IS_ERR(ar
->normal_mode_fw
.board
))
675 release_firmware(ar
->normal_mode_fw
.board
);
677 ar
->normal_mode_fw
.board
= NULL
;
678 ar
->normal_mode_fw
.board_data
= NULL
;
679 ar
->normal_mode_fw
.board_len
= 0;
682 static void ath10k_core_free_firmware_files(struct ath10k
*ar
)
684 if (!IS_ERR(ar
->normal_mode_fw
.fw_file
.firmware
))
685 release_firmware(ar
->normal_mode_fw
.fw_file
.firmware
);
687 if (!IS_ERR(ar
->cal_file
))
688 release_firmware(ar
->cal_file
);
690 if (!IS_ERR(ar
->pre_cal_file
))
691 release_firmware(ar
->pre_cal_file
);
693 ath10k_swap_code_seg_release(ar
);
695 ar
->normal_mode_fw
.fw_file
.otp_data
= NULL
;
696 ar
->normal_mode_fw
.fw_file
.otp_len
= 0;
698 ar
->normal_mode_fw
.fw_file
.firmware
= NULL
;
699 ar
->normal_mode_fw
.fw_file
.firmware_data
= NULL
;
700 ar
->normal_mode_fw
.fw_file
.firmware_len
= 0;
703 ar
->pre_cal_file
= NULL
;
706 static int ath10k_fetch_cal_file(struct ath10k
*ar
)
710 /* pre-cal-<bus>-<id>.bin */
711 scnprintf(filename
, sizeof(filename
), "pre-cal-%s-%s.bin",
712 ath10k_bus_str(ar
->hif
.bus
), dev_name(ar
->dev
));
714 ar
->pre_cal_file
= ath10k_fetch_fw_file(ar
, ATH10K_FW_DIR
, filename
);
715 if (!IS_ERR(ar
->pre_cal_file
))
718 /* cal-<bus>-<id>.bin */
719 scnprintf(filename
, sizeof(filename
), "cal-%s-%s.bin",
720 ath10k_bus_str(ar
->hif
.bus
), dev_name(ar
->dev
));
722 ar
->cal_file
= ath10k_fetch_fw_file(ar
, ATH10K_FW_DIR
, filename
);
723 if (IS_ERR(ar
->cal_file
))
724 /* calibration file is optional, don't print any warnings */
725 return PTR_ERR(ar
->cal_file
);
727 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found calibration file %s/%s\n",
728 ATH10K_FW_DIR
, filename
);
733 static int ath10k_core_fetch_board_data_api_1(struct ath10k
*ar
)
735 if (!ar
->hw_params
.fw
.board
) {
736 ath10k_err(ar
, "failed to find board file fw entry\n");
740 ar
->normal_mode_fw
.board
= ath10k_fetch_fw_file(ar
,
741 ar
->hw_params
.fw
.dir
,
742 ar
->hw_params
.fw
.board
);
743 if (IS_ERR(ar
->normal_mode_fw
.board
))
744 return PTR_ERR(ar
->normal_mode_fw
.board
);
746 ar
->normal_mode_fw
.board_data
= ar
->normal_mode_fw
.board
->data
;
747 ar
->normal_mode_fw
.board_len
= ar
->normal_mode_fw
.board
->size
;
752 static int ath10k_core_parse_bd_ie_board(struct ath10k
*ar
,
753 const void *buf
, size_t buf_len
,
754 const char *boardname
)
756 const struct ath10k_fw_ie
*hdr
;
757 bool name_match_found
;
758 int ret
, board_ie_id
;
760 const void *board_ie_data
;
762 name_match_found
= false;
764 /* go through ATH10K_BD_IE_BOARD_ elements */
765 while (buf_len
> sizeof(struct ath10k_fw_ie
)) {
767 board_ie_id
= le32_to_cpu(hdr
->id
);
768 board_ie_len
= le32_to_cpu(hdr
->len
);
769 board_ie_data
= hdr
->data
;
771 buf_len
-= sizeof(*hdr
);
774 if (buf_len
< ALIGN(board_ie_len
, 4)) {
775 ath10k_err(ar
, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
776 buf_len
, ALIGN(board_ie_len
, 4));
781 switch (board_ie_id
) {
782 case ATH10K_BD_IE_BOARD_NAME
:
783 ath10k_dbg_dump(ar
, ATH10K_DBG_BOOT
, "board name", "",
784 board_ie_data
, board_ie_len
);
786 if (board_ie_len
!= strlen(boardname
))
789 ret
= memcmp(board_ie_data
, boardname
, strlen(boardname
));
793 name_match_found
= true;
794 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
795 "boot found match for name '%s'",
798 case ATH10K_BD_IE_BOARD_DATA
:
799 if (!name_match_found
)
803 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
804 "boot found board data for '%s'",
807 ar
->normal_mode_fw
.board_data
= board_ie_data
;
808 ar
->normal_mode_fw
.board_len
= board_ie_len
;
813 ath10k_warn(ar
, "unknown ATH10K_BD_IE_BOARD found: %d\n",
818 /* jump over the padding */
819 board_ie_len
= ALIGN(board_ie_len
, 4);
821 buf_len
-= board_ie_len
;
832 static int ath10k_core_fetch_board_data_api_n(struct ath10k
*ar
,
833 const char *boardname
,
834 const char *filename
)
836 size_t len
, magic_len
, ie_len
;
837 struct ath10k_fw_ie
*hdr
;
841 ar
->normal_mode_fw
.board
= ath10k_fetch_fw_file(ar
,
842 ar
->hw_params
.fw
.dir
,
844 if (IS_ERR(ar
->normal_mode_fw
.board
))
845 return PTR_ERR(ar
->normal_mode_fw
.board
);
847 data
= ar
->normal_mode_fw
.board
->data
;
848 len
= ar
->normal_mode_fw
.board
->size
;
850 /* magic has extra null byte padded */
851 magic_len
= strlen(ATH10K_BOARD_MAGIC
) + 1;
852 if (len
< magic_len
) {
853 ath10k_err(ar
, "failed to find magic value in %s/%s, file too short: %zu\n",
854 ar
->hw_params
.fw
.dir
, filename
, len
);
859 if (memcmp(data
, ATH10K_BOARD_MAGIC
, magic_len
)) {
860 ath10k_err(ar
, "found invalid board magic\n");
865 /* magic is padded to 4 bytes */
866 magic_len
= ALIGN(magic_len
, 4);
867 if (len
< magic_len
) {
868 ath10k_err(ar
, "failed: %s/%s too small to contain board data, len: %zu\n",
869 ar
->hw_params
.fw
.dir
, filename
, len
);
877 while (len
> sizeof(struct ath10k_fw_ie
)) {
878 hdr
= (struct ath10k_fw_ie
*)data
;
879 ie_id
= le32_to_cpu(hdr
->id
);
880 ie_len
= le32_to_cpu(hdr
->len
);
885 if (len
< ALIGN(ie_len
, 4)) {
886 ath10k_err(ar
, "invalid length for board ie_id %d ie_len %zu len %zu\n",
893 case ATH10K_BD_IE_BOARD
:
894 ret
= ath10k_core_parse_bd_ie_board(ar
, data
, ie_len
,
897 /* no match found, continue */
900 /* there was an error, bail out */
903 /* board data found */
907 /* jump over the padding */
908 ie_len
= ALIGN(ie_len
, 4);
915 if (!ar
->normal_mode_fw
.board_data
|| !ar
->normal_mode_fw
.board_len
) {
917 "failed to fetch board data for %s from %s/%s\n",
918 boardname
, ar
->hw_params
.fw
.dir
, filename
);
926 ath10k_core_free_board_files(ar
);
930 static int ath10k_core_create_board_name(struct ath10k
*ar
, char *name
,
933 if (ar
->id
.bmi_ids_valid
) {
934 scnprintf(name
, name_len
,
935 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d",
936 ath10k_bus_str(ar
->hif
.bus
),
938 ar
->id
.bmi_board_id
);
942 scnprintf(name
, name_len
,
943 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
944 ath10k_bus_str(ar
->hif
.bus
),
945 ar
->id
.vendor
, ar
->id
.device
,
946 ar
->id
.subsystem_vendor
, ar
->id
.subsystem_device
);
949 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot using board name '%s'\n", name
);
954 static int ath10k_core_fetch_board_file(struct ath10k
*ar
)
959 ret
= ath10k_core_create_board_name(ar
, boardname
, sizeof(boardname
));
961 ath10k_err(ar
, "failed to create board name: %d", ret
);
966 ret
= ath10k_core_fetch_board_data_api_n(ar
, boardname
,
967 ATH10K_BOARD_API2_FILE
);
972 ret
= ath10k_core_fetch_board_data_api_1(ar
);
974 ath10k_err(ar
, "failed to fetch board data\n");
979 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "using board api %d\n", ar
->bd_api
);
983 int ath10k_core_fetch_firmware_api_n(struct ath10k
*ar
, const char *name
,
984 struct ath10k_fw_file
*fw_file
)
986 size_t magic_len
, len
, ie_len
;
987 int ie_id
, i
, index
, bit
, ret
;
988 struct ath10k_fw_ie
*hdr
;
990 __le32
*timestamp
, *version
;
992 /* first fetch the firmware file (firmware-*.bin) */
993 fw_file
->firmware
= ath10k_fetch_fw_file(ar
, ar
->hw_params
.fw
.dir
,
995 if (IS_ERR(fw_file
->firmware
)) {
996 ath10k_err(ar
, "could not fetch firmware file '%s/%s': %ld\n",
997 ar
->hw_params
.fw
.dir
, name
,
998 PTR_ERR(fw_file
->firmware
));
999 return PTR_ERR(fw_file
->firmware
);
1002 data
= fw_file
->firmware
->data
;
1003 len
= fw_file
->firmware
->size
;
1005 /* magic also includes the null byte, check that as well */
1006 magic_len
= strlen(ATH10K_FIRMWARE_MAGIC
) + 1;
1008 if (len
< magic_len
) {
1009 ath10k_err(ar
, "firmware file '%s/%s' too small to contain magic: %zu\n",
1010 ar
->hw_params
.fw
.dir
, name
, len
);
1015 if (memcmp(data
, ATH10K_FIRMWARE_MAGIC
, magic_len
) != 0) {
1016 ath10k_err(ar
, "invalid firmware magic\n");
1021 /* jump over the padding */
1022 magic_len
= ALIGN(magic_len
, 4);
1028 while (len
> sizeof(struct ath10k_fw_ie
)) {
1029 hdr
= (struct ath10k_fw_ie
*)data
;
1031 ie_id
= le32_to_cpu(hdr
->id
);
1032 ie_len
= le32_to_cpu(hdr
->len
);
1034 len
-= sizeof(*hdr
);
1035 data
+= sizeof(*hdr
);
1038 ath10k_err(ar
, "invalid length for FW IE %d (%zu < %zu)\n",
1039 ie_id
, len
, ie_len
);
1045 case ATH10K_FW_IE_FW_VERSION
:
1046 if (ie_len
> sizeof(fw_file
->fw_version
) - 1)
1049 memcpy(fw_file
->fw_version
, data
, ie_len
);
1050 fw_file
->fw_version
[ie_len
] = '\0';
1052 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1053 "found fw version %s\n",
1054 fw_file
->fw_version
);
1056 case ATH10K_FW_IE_TIMESTAMP
:
1057 if (ie_len
!= sizeof(u32
))
1060 timestamp
= (__le32
*)data
;
1062 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw timestamp %d\n",
1063 le32_to_cpup(timestamp
));
1065 case ATH10K_FW_IE_FEATURES
:
1066 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1067 "found firmware features ie (%zd B)\n",
1070 for (i
= 0; i
< ATH10K_FW_FEATURE_COUNT
; i
++) {
1074 if (index
== ie_len
)
1077 if (data
[index
] & (1 << bit
)) {
1078 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1079 "Enabling feature bit: %i\n",
1081 __set_bit(i
, fw_file
->fw_features
);
1085 ath10k_dbg_dump(ar
, ATH10K_DBG_BOOT
, "features", "",
1086 ar
->running_fw
->fw_file
.fw_features
,
1087 sizeof(fw_file
->fw_features
));
1089 case ATH10K_FW_IE_FW_IMAGE
:
1090 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1091 "found fw image ie (%zd B)\n",
1094 fw_file
->firmware_data
= data
;
1095 fw_file
->firmware_len
= ie_len
;
1098 case ATH10K_FW_IE_OTP_IMAGE
:
1099 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1100 "found otp image ie (%zd B)\n",
1103 fw_file
->otp_data
= data
;
1104 fw_file
->otp_len
= ie_len
;
1107 case ATH10K_FW_IE_WMI_OP_VERSION
:
1108 if (ie_len
!= sizeof(u32
))
1111 version
= (__le32
*)data
;
1113 fw_file
->wmi_op_version
= le32_to_cpup(version
);
1115 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw ie wmi op version %d\n",
1116 fw_file
->wmi_op_version
);
1118 case ATH10K_FW_IE_HTT_OP_VERSION
:
1119 if (ie_len
!= sizeof(u32
))
1122 version
= (__le32
*)data
;
1124 fw_file
->htt_op_version
= le32_to_cpup(version
);
1126 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "found fw ie htt op version %d\n",
1127 fw_file
->htt_op_version
);
1129 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE
:
1130 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1131 "found fw code swap image ie (%zd B)\n",
1133 fw_file
->codeswap_data
= data
;
1134 fw_file
->codeswap_len
= ie_len
;
1137 ath10k_warn(ar
, "Unknown FW IE: %u\n",
1138 le32_to_cpu(hdr
->id
));
1142 /* jump over the padding */
1143 ie_len
= ALIGN(ie_len
, 4);
1149 if (!fw_file
->firmware_data
||
1150 !fw_file
->firmware_len
) {
1151 ath10k_warn(ar
, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1152 ar
->hw_params
.fw
.dir
, name
);
1160 ath10k_core_free_firmware_files(ar
);
1164 static int ath10k_core_fetch_firmware_files(struct ath10k
*ar
)
1168 /* calibration file is optional, don't check for any errors */
1169 ath10k_fetch_cal_file(ar
);
1172 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1174 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API5_FILE
,
1175 &ar
->normal_mode_fw
.fw_file
);
1180 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1182 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API4_FILE
,
1183 &ar
->normal_mode_fw
.fw_file
);
1188 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1190 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API3_FILE
,
1191 &ar
->normal_mode_fw
.fw_file
);
1196 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "trying fw api %d\n", ar
->fw_api
);
1198 ret
= ath10k_core_fetch_firmware_api_n(ar
, ATH10K_FW_API2_FILE
,
1199 &ar
->normal_mode_fw
.fw_file
);
1204 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "using fw api %d\n", ar
->fw_api
);
1209 static int ath10k_core_pre_cal_download(struct ath10k
*ar
)
1213 ret
= ath10k_download_cal_file(ar
, ar
->pre_cal_file
);
1215 ar
->cal_mode
= ATH10K_PRE_CAL_MODE_FILE
;
1219 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1220 "boot did not find a pre calibration file, try DT next: %d\n",
1223 ret
= ath10k_download_cal_dt(ar
, "qcom,ath10k-pre-calibration-data");
1225 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1226 "unable to load pre cal data from DT: %d\n", ret
);
1229 ar
->cal_mode
= ATH10K_PRE_CAL_MODE_DT
;
1232 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot using calibration mode %s\n",
1233 ath10k_cal_mode_str(ar
->cal_mode
));
1238 static int ath10k_core_pre_cal_config(struct ath10k
*ar
)
1242 ret
= ath10k_core_pre_cal_download(ar
);
1244 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1245 "failed to load pre cal data: %d\n", ret
);
1249 ret
= ath10k_core_get_board_id_from_otp(ar
);
1251 ath10k_err(ar
, "failed to get board id: %d\n", ret
);
1255 ret
= ath10k_download_and_run_otp(ar
);
1257 ath10k_err(ar
, "failed to run otp: %d\n", ret
);
1261 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1262 "pre cal configuration done successfully\n");
1267 static int ath10k_download_cal_data(struct ath10k
*ar
)
1271 ret
= ath10k_core_pre_cal_config(ar
);
1275 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1276 "pre cal download procedure failed, try cal file: %d\n",
1279 ret
= ath10k_download_cal_file(ar
, ar
->cal_file
);
1281 ar
->cal_mode
= ATH10K_CAL_MODE_FILE
;
1285 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1286 "boot did not find a calibration file, try DT next: %d\n",
1289 ret
= ath10k_download_cal_dt(ar
, "qcom,ath10k-calibration-data");
1291 ar
->cal_mode
= ATH10K_CAL_MODE_DT
;
1295 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1296 "boot did not find DT entry, try OTP next: %d\n",
1299 ret
= ath10k_download_and_run_otp(ar
);
1301 ath10k_err(ar
, "failed to run otp: %d\n", ret
);
1305 ar
->cal_mode
= ATH10K_CAL_MODE_OTP
;
1308 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot using calibration mode %s\n",
1309 ath10k_cal_mode_str(ar
->cal_mode
));
1313 static int ath10k_init_uart(struct ath10k
*ar
)
1318 * Explicitly setting UART prints to zero as target turns it on
1319 * based on scratch registers.
1321 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 0);
1323 ath10k_warn(ar
, "could not disable UART prints (%d)\n", ret
);
1330 ret
= ath10k_bmi_write32(ar
, hi_dbg_uart_txpin
, ar
->hw_params
.uart_pin
);
1332 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
1336 ret
= ath10k_bmi_write32(ar
, hi_serial_enable
, 1);
1338 ath10k_warn(ar
, "could not enable UART prints (%d)\n", ret
);
1342 /* Set the UART baud rate to 19200. */
1343 ret
= ath10k_bmi_write32(ar
, hi_desired_baud_rate
, 19200);
1345 ath10k_warn(ar
, "could not set the baud rate (%d)\n", ret
);
1349 ath10k_info(ar
, "UART prints enabled\n");
1353 static int ath10k_init_hw_params(struct ath10k
*ar
)
1355 const struct ath10k_hw_params
*uninitialized_var(hw_params
);
1358 for (i
= 0; i
< ARRAY_SIZE(ath10k_hw_params_list
); i
++) {
1359 hw_params
= &ath10k_hw_params_list
[i
];
1361 if (hw_params
->id
== ar
->target_version
&&
1362 hw_params
->dev_id
== ar
->dev_id
)
1366 if (i
== ARRAY_SIZE(ath10k_hw_params_list
)) {
1367 ath10k_err(ar
, "Unsupported hardware version: 0x%x\n",
1368 ar
->target_version
);
1372 ar
->hw_params
= *hw_params
;
1374 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "Hardware name %s version 0x%x\n",
1375 ar
->hw_params
.name
, ar
->target_version
);
1380 static void ath10k_core_restart(struct work_struct
*work
)
1382 struct ath10k
*ar
= container_of(work
, struct ath10k
, restart_work
);
1384 set_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
);
1386 /* Place a barrier to make sure the compiler doesn't reorder
1387 * CRASH_FLUSH and calling other functions.
1391 ieee80211_stop_queues(ar
->hw
);
1392 ath10k_drain_tx(ar
);
1393 complete_all(&ar
->scan
.started
);
1394 complete_all(&ar
->scan
.completed
);
1395 complete_all(&ar
->scan
.on_channel
);
1396 complete_all(&ar
->offchan_tx_completed
);
1397 complete_all(&ar
->install_key_done
);
1398 complete_all(&ar
->vdev_setup_done
);
1399 complete_all(&ar
->thermal
.wmi_sync
);
1400 complete_all(&ar
->bss_survey_done
);
1401 wake_up(&ar
->htt
.empty_tx_wq
);
1402 wake_up(&ar
->wmi
.tx_credits_wq
);
1403 wake_up(&ar
->peer_mapping_wq
);
1405 mutex_lock(&ar
->conf_mutex
);
1407 switch (ar
->state
) {
1408 case ATH10K_STATE_ON
:
1409 ar
->state
= ATH10K_STATE_RESTARTING
;
1410 ath10k_hif_stop(ar
);
1411 ath10k_scan_finish(ar
);
1412 ieee80211_restart_hw(ar
->hw
);
1414 case ATH10K_STATE_OFF
:
1415 /* this can happen if driver is being unloaded
1416 * or if the crash happens during FW probing */
1417 ath10k_warn(ar
, "cannot restart a device that hasn't been started\n");
1419 case ATH10K_STATE_RESTARTING
:
1420 /* hw restart might be requested from multiple places */
1422 case ATH10K_STATE_RESTARTED
:
1423 ar
->state
= ATH10K_STATE_WEDGED
;
1425 case ATH10K_STATE_WEDGED
:
1426 ath10k_warn(ar
, "device is wedged, will not restart\n");
1428 case ATH10K_STATE_UTF
:
1429 ath10k_warn(ar
, "firmware restart in UTF mode not supported\n");
1433 mutex_unlock(&ar
->conf_mutex
);
1436 static int ath10k_core_init_firmware_features(struct ath10k
*ar
)
1438 struct ath10k_fw_file
*fw_file
= &ar
->normal_mode_fw
.fw_file
;
1440 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2
, fw_file
->fw_features
) &&
1441 !test_bit(ATH10K_FW_FEATURE_WMI_10X
, fw_file
->fw_features
)) {
1442 ath10k_err(ar
, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1446 if (fw_file
->wmi_op_version
>= ATH10K_FW_WMI_OP_VERSION_MAX
) {
1447 ath10k_err(ar
, "unsupported WMI OP version (max %d): %d\n",
1448 ATH10K_FW_WMI_OP_VERSION_MAX
, fw_file
->wmi_op_version
);
1452 ar
->wmi
.rx_decap_mode
= ATH10K_HW_TXRX_NATIVE_WIFI
;
1453 switch (ath10k_cryptmode_param
) {
1454 case ATH10K_CRYPT_MODE_HW
:
1455 clear_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
);
1456 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
);
1458 case ATH10K_CRYPT_MODE_SW
:
1459 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT
,
1460 fw_file
->fw_features
)) {
1461 ath10k_err(ar
, "cryptmode > 0 requires raw mode support from firmware");
1465 set_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
);
1466 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
);
1469 ath10k_info(ar
, "invalid cryptmode: %d\n",
1470 ath10k_cryptmode_param
);
1474 ar
->htt
.max_num_amsdu
= ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT
;
1475 ar
->htt
.max_num_ampdu
= ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT
;
1478 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT
,
1479 fw_file
->fw_features
)) {
1480 ath10k_err(ar
, "rawmode = 1 requires support from firmware");
1483 set_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
);
1486 if (test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
1487 ar
->wmi
.rx_decap_mode
= ATH10K_HW_TXRX_RAW
;
1491 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1492 * and causes enormous performance issues (malformed frames,
1495 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1496 * albeit a bit slower compared to regular operation.
1498 ar
->htt
.max_num_amsdu
= 1;
1501 /* Backwards compatibility for firmwares without
1502 * ATH10K_FW_IE_WMI_OP_VERSION.
1504 if (fw_file
->wmi_op_version
== ATH10K_FW_WMI_OP_VERSION_UNSET
) {
1505 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, fw_file
->fw_features
)) {
1506 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2
,
1507 fw_file
->fw_features
))
1508 fw_file
->wmi_op_version
= ATH10K_FW_WMI_OP_VERSION_10_2
;
1510 fw_file
->wmi_op_version
= ATH10K_FW_WMI_OP_VERSION_10_1
;
1512 fw_file
->wmi_op_version
= ATH10K_FW_WMI_OP_VERSION_MAIN
;
1516 switch (fw_file
->wmi_op_version
) {
1517 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
1518 ar
->max_num_peers
= TARGET_NUM_PEERS
;
1519 ar
->max_num_stations
= TARGET_NUM_STATIONS
;
1520 ar
->max_num_vdevs
= TARGET_NUM_VDEVS
;
1521 ar
->htt
.max_num_pending_tx
= TARGET_NUM_MSDU_DESC
;
1522 ar
->fw_stats_req_mask
= WMI_STAT_PDEV
| WMI_STAT_VDEV
|
1524 ar
->max_spatial_stream
= WMI_MAX_SPATIAL_STREAM
;
1526 case ATH10K_FW_WMI_OP_VERSION_10_1
:
1527 case ATH10K_FW_WMI_OP_VERSION_10_2
:
1528 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
1529 if (ath10k_peer_stats_enabled(ar
)) {
1530 ar
->max_num_peers
= TARGET_10X_TX_STATS_NUM_PEERS
;
1531 ar
->max_num_stations
= TARGET_10X_TX_STATS_NUM_STATIONS
;
1533 ar
->max_num_peers
= TARGET_10X_NUM_PEERS
;
1534 ar
->max_num_stations
= TARGET_10X_NUM_STATIONS
;
1536 ar
->max_num_vdevs
= TARGET_10X_NUM_VDEVS
;
1537 ar
->htt
.max_num_pending_tx
= TARGET_10X_NUM_MSDU_DESC
;
1538 ar
->fw_stats_req_mask
= WMI_STAT_PEER
;
1539 ar
->max_spatial_stream
= WMI_MAX_SPATIAL_STREAM
;
1541 case ATH10K_FW_WMI_OP_VERSION_TLV
:
1542 ar
->max_num_peers
= TARGET_TLV_NUM_PEERS
;
1543 ar
->max_num_stations
= TARGET_TLV_NUM_STATIONS
;
1544 ar
->max_num_vdevs
= TARGET_TLV_NUM_VDEVS
;
1545 ar
->max_num_tdls_vdevs
= TARGET_TLV_NUM_TDLS_VDEVS
;
1546 ar
->htt
.max_num_pending_tx
= TARGET_TLV_NUM_MSDU_DESC
;
1547 ar
->wow
.max_num_patterns
= TARGET_TLV_NUM_WOW_PATTERNS
;
1548 ar
->fw_stats_req_mask
= WMI_STAT_PDEV
| WMI_STAT_VDEV
|
1550 ar
->max_spatial_stream
= WMI_MAX_SPATIAL_STREAM
;
1552 case ATH10K_FW_WMI_OP_VERSION_10_4
:
1553 ar
->max_num_peers
= TARGET_10_4_NUM_PEERS
;
1554 ar
->max_num_stations
= TARGET_10_4_NUM_STATIONS
;
1555 ar
->num_active_peers
= TARGET_10_4_ACTIVE_PEERS
;
1556 ar
->max_num_vdevs
= TARGET_10_4_NUM_VDEVS
;
1557 ar
->num_tids
= TARGET_10_4_TGT_NUM_TIDS
;
1558 ar
->fw_stats_req_mask
= WMI_10_4_STAT_PEER
|
1559 WMI_10_4_STAT_PEER_EXTD
;
1560 ar
->max_spatial_stream
= ar
->hw_params
.max_spatial_stream
;
1562 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL
,
1563 fw_file
->fw_features
))
1564 ar
->htt
.max_num_pending_tx
= TARGET_10_4_NUM_MSDU_DESC_PFC
;
1566 ar
->htt
.max_num_pending_tx
= TARGET_10_4_NUM_MSDU_DESC
;
1568 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
1569 case ATH10K_FW_WMI_OP_VERSION_MAX
:
1574 /* Backwards compatibility for firmwares without
1575 * ATH10K_FW_IE_HTT_OP_VERSION.
1577 if (fw_file
->htt_op_version
== ATH10K_FW_HTT_OP_VERSION_UNSET
) {
1578 switch (fw_file
->wmi_op_version
) {
1579 case ATH10K_FW_WMI_OP_VERSION_MAIN
:
1580 fw_file
->htt_op_version
= ATH10K_FW_HTT_OP_VERSION_MAIN
;
1582 case ATH10K_FW_WMI_OP_VERSION_10_1
:
1583 case ATH10K_FW_WMI_OP_VERSION_10_2
:
1584 case ATH10K_FW_WMI_OP_VERSION_10_2_4
:
1585 fw_file
->htt_op_version
= ATH10K_FW_HTT_OP_VERSION_10_1
;
1587 case ATH10K_FW_WMI_OP_VERSION_TLV
:
1588 fw_file
->htt_op_version
= ATH10K_FW_HTT_OP_VERSION_TLV
;
1590 case ATH10K_FW_WMI_OP_VERSION_10_4
:
1591 case ATH10K_FW_WMI_OP_VERSION_UNSET
:
1592 case ATH10K_FW_WMI_OP_VERSION_MAX
:
1601 int ath10k_core_start(struct ath10k
*ar
, enum ath10k_firmware_mode mode
,
1602 const struct ath10k_fw_components
*fw
)
1607 lockdep_assert_held(&ar
->conf_mutex
);
1609 clear_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
);
1611 ar
->running_fw
= fw
;
1613 ath10k_bmi_start(ar
);
1615 if (ath10k_init_configure_target(ar
)) {
1620 status
= ath10k_download_cal_data(ar
);
1624 /* Some of of qca988x solutions are having global reset issue
1625 * during target initialization. Bypassing PLL setting before
1626 * downloading firmware and letting the SoC run on REF_CLK is
1627 * fixing the problem. Corresponding firmware change is also needed
1628 * to set the clock source once the target is initialized.
1630 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT
,
1631 ar
->running_fw
->fw_file
.fw_features
)) {
1632 status
= ath10k_bmi_write32(ar
, hi_skip_clock_init
, 1);
1634 ath10k_err(ar
, "could not write to skip_clock_init: %d\n",
1640 status
= ath10k_download_fw(ar
);
1644 status
= ath10k_init_uart(ar
);
1648 ar
->htc
.htc_ops
.target_send_suspend_complete
=
1649 ath10k_send_suspend_complete
;
1651 status
= ath10k_htc_init(ar
);
1653 ath10k_err(ar
, "could not init HTC (%d)\n", status
);
1657 status
= ath10k_bmi_done(ar
);
1661 status
= ath10k_wmi_attach(ar
);
1663 ath10k_err(ar
, "WMI attach failed: %d\n", status
);
1667 status
= ath10k_htt_init(ar
);
1669 ath10k_err(ar
, "failed to init htt: %d\n", status
);
1670 goto err_wmi_detach
;
1673 status
= ath10k_htt_tx_alloc(&ar
->htt
);
1675 ath10k_err(ar
, "failed to alloc htt tx: %d\n", status
);
1676 goto err_wmi_detach
;
1679 status
= ath10k_htt_rx_alloc(&ar
->htt
);
1681 ath10k_err(ar
, "failed to alloc htt rx: %d\n", status
);
1682 goto err_htt_tx_detach
;
1685 status
= ath10k_hif_start(ar
);
1687 ath10k_err(ar
, "could not start HIF: %d\n", status
);
1688 goto err_htt_rx_detach
;
1691 status
= ath10k_htc_wait_target(&ar
->htc
);
1693 ath10k_err(ar
, "failed to connect to HTC: %d\n", status
);
1697 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1698 status
= ath10k_htt_connect(&ar
->htt
);
1700 ath10k_err(ar
, "failed to connect htt (%d)\n", status
);
1705 status
= ath10k_wmi_connect(ar
);
1707 ath10k_err(ar
, "could not connect wmi: %d\n", status
);
1711 status
= ath10k_htc_start(&ar
->htc
);
1713 ath10k_err(ar
, "failed to start htc: %d\n", status
);
1717 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1718 status
= ath10k_wmi_wait_for_service_ready(ar
);
1720 ath10k_warn(ar
, "wmi service ready event not received");
1725 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "firmware %s booted\n",
1726 ar
->hw
->wiphy
->fw_version
);
1728 if (test_bit(WMI_SERVICE_EXT_RES_CFG_SUPPORT
, ar
->wmi
.svc_map
)) {
1730 if (ath10k_peer_stats_enabled(ar
))
1731 val
= WMI_10_4_PEER_STATS
;
1733 if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64
, ar
->wmi
.svc_map
))
1734 val
|= WMI_10_4_BSS_CHANNEL_INFO_64
;
1736 status
= ath10k_mac_ext_resource_config(ar
, val
);
1739 "failed to send ext resource cfg command : %d\n",
1745 status
= ath10k_wmi_cmd_init(ar
);
1747 ath10k_err(ar
, "could not send WMI init command (%d)\n",
1752 status
= ath10k_wmi_wait_for_unified_ready(ar
);
1754 ath10k_err(ar
, "wmi unified ready event not received\n");
1758 /* If firmware indicates Full Rx Reorder support it must be used in a
1759 * slightly different manner. Let HTT code know.
1761 ar
->htt
.rx_ring
.in_ord_rx
= !!(test_bit(WMI_SERVICE_RX_FULL_REORDER
,
1764 status
= ath10k_htt_rx_ring_refill(ar
);
1766 ath10k_err(ar
, "failed to refill htt rx ring: %d\n", status
);
1770 ar
->free_vdev_map
= (1LL << ar
->max_num_vdevs
) - 1;
1772 INIT_LIST_HEAD(&ar
->arvifs
);
1774 /* we don't care about HTT in UTF mode */
1775 if (mode
== ATH10K_FIRMWARE_MODE_NORMAL
) {
1776 status
= ath10k_htt_setup(&ar
->htt
);
1778 ath10k_err(ar
, "failed to setup htt: %d\n", status
);
1783 status
= ath10k_debug_start(ar
);
1790 ath10k_hif_stop(ar
);
1792 ath10k_htt_rx_free(&ar
->htt
);
1794 ath10k_htt_tx_free(&ar
->htt
);
1796 ath10k_wmi_detach(ar
);
1800 EXPORT_SYMBOL(ath10k_core_start
);
1802 int ath10k_wait_for_suspend(struct ath10k
*ar
, u32 suspend_opt
)
1805 unsigned long time_left
;
1807 reinit_completion(&ar
->target_suspend
);
1809 ret
= ath10k_wmi_pdev_suspend_target(ar
, suspend_opt
);
1811 ath10k_warn(ar
, "could not suspend target (%d)\n", ret
);
1815 time_left
= wait_for_completion_timeout(&ar
->target_suspend
, 1 * HZ
);
1818 ath10k_warn(ar
, "suspend timed out - target pause event never came\n");
1825 void ath10k_core_stop(struct ath10k
*ar
)
1827 lockdep_assert_held(&ar
->conf_mutex
);
1828 ath10k_debug_stop(ar
);
1830 /* try to suspend target */
1831 if (ar
->state
!= ATH10K_STATE_RESTARTING
&&
1832 ar
->state
!= ATH10K_STATE_UTF
)
1833 ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND_AND_DISABLE_INTR
);
1835 ath10k_hif_stop(ar
);
1836 ath10k_htt_tx_free(&ar
->htt
);
1837 ath10k_htt_rx_free(&ar
->htt
);
1838 ath10k_wmi_detach(ar
);
1840 EXPORT_SYMBOL(ath10k_core_stop
);
1842 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
1843 * order to know what hw capabilities should be advertised to mac80211 it is
1844 * necessary to load the firmware (and tear it down immediately since start
1845 * hook will try to init it again) before registering */
1846 static int ath10k_core_probe_fw(struct ath10k
*ar
)
1848 struct bmi_target_info target_info
;
1851 ret
= ath10k_hif_power_up(ar
);
1853 ath10k_err(ar
, "could not start pci hif (%d)\n", ret
);
1857 memset(&target_info
, 0, sizeof(target_info
));
1858 ret
= ath10k_bmi_get_target_info(ar
, &target_info
);
1860 ath10k_err(ar
, "could not get target info (%d)\n", ret
);
1861 goto err_power_down
;
1864 ar
->target_version
= target_info
.version
;
1865 ar
->hw
->wiphy
->hw_version
= target_info
.version
;
1867 ret
= ath10k_init_hw_params(ar
);
1869 ath10k_err(ar
, "could not get hw params (%d)\n", ret
);
1870 goto err_power_down
;
1873 ret
= ath10k_core_fetch_firmware_files(ar
);
1875 ath10k_err(ar
, "could not fetch firmware files (%d)\n", ret
);
1876 goto err_power_down
;
1879 BUILD_BUG_ON(sizeof(ar
->hw
->wiphy
->fw_version
) !=
1880 sizeof(ar
->normal_mode_fw
.fw_file
.fw_version
));
1881 memcpy(ar
->hw
->wiphy
->fw_version
, ar
->normal_mode_fw
.fw_file
.fw_version
,
1882 sizeof(ar
->hw
->wiphy
->fw_version
));
1884 ath10k_debug_print_hwfw_info(ar
);
1886 ret
= ath10k_core_pre_cal_download(ar
);
1888 /* pre calibration data download is not necessary
1889 * for all the chipsets. Ignore failures and continue.
1891 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1892 "could not load pre cal data: %d\n", ret
);
1895 ret
= ath10k_core_get_board_id_from_otp(ar
);
1896 if (ret
&& ret
!= -EOPNOTSUPP
) {
1897 ath10k_err(ar
, "failed to get board id from otp: %d\n",
1899 goto err_free_firmware_files
;
1902 ret
= ath10k_core_fetch_board_file(ar
);
1904 ath10k_err(ar
, "failed to fetch board file: %d\n", ret
);
1905 goto err_free_firmware_files
;
1908 ath10k_debug_print_board_info(ar
);
1910 ret
= ath10k_core_init_firmware_features(ar
);
1912 ath10k_err(ar
, "fatal problem with firmware features: %d\n",
1914 goto err_free_firmware_files
;
1917 ret
= ath10k_swap_code_seg_init(ar
);
1919 ath10k_err(ar
, "failed to initialize code swap segment: %d\n",
1921 goto err_free_firmware_files
;
1924 mutex_lock(&ar
->conf_mutex
);
1926 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
,
1927 &ar
->normal_mode_fw
);
1929 ath10k_err(ar
, "could not init core (%d)\n", ret
);
1933 ath10k_debug_print_boot_info(ar
);
1934 ath10k_core_stop(ar
);
1936 mutex_unlock(&ar
->conf_mutex
);
1938 ath10k_hif_power_down(ar
);
1942 mutex_unlock(&ar
->conf_mutex
);
1944 err_free_firmware_files
:
1945 ath10k_core_free_firmware_files(ar
);
1948 ath10k_hif_power_down(ar
);
1953 static void ath10k_core_register_work(struct work_struct
*work
)
1955 struct ath10k
*ar
= container_of(work
, struct ath10k
, register_work
);
1958 status
= ath10k_core_probe_fw(ar
);
1960 ath10k_err(ar
, "could not probe fw (%d)\n", status
);
1964 status
= ath10k_mac_register(ar
);
1966 ath10k_err(ar
, "could not register to mac80211 (%d)\n", status
);
1967 goto err_release_fw
;
1970 status
= ath10k_debug_register(ar
);
1972 ath10k_err(ar
, "unable to initialize debugfs\n");
1973 goto err_unregister_mac
;
1976 status
= ath10k_spectral_create(ar
);
1978 ath10k_err(ar
, "failed to initialize spectral\n");
1979 goto err_debug_destroy
;
1982 status
= ath10k_thermal_register(ar
);
1984 ath10k_err(ar
, "could not register thermal device: %d\n",
1986 goto err_spectral_destroy
;
1989 set_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
);
1992 err_spectral_destroy
:
1993 ath10k_spectral_destroy(ar
);
1995 ath10k_debug_destroy(ar
);
1997 ath10k_mac_unregister(ar
);
1999 ath10k_core_free_firmware_files(ar
);
2001 /* TODO: It's probably a good idea to release device from the driver
2002 * but calling device_release_driver() here will cause a deadlock.
2007 int ath10k_core_register(struct ath10k
*ar
, u32 chip_id
)
2009 ar
->chip_id
= chip_id
;
2010 queue_work(ar
->workqueue
, &ar
->register_work
);
2014 EXPORT_SYMBOL(ath10k_core_register
);
2016 void ath10k_core_unregister(struct ath10k
*ar
)
2018 cancel_work_sync(&ar
->register_work
);
2020 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED
, &ar
->dev_flags
))
2023 ath10k_thermal_unregister(ar
);
2024 /* Stop spectral before unregistering from mac80211 to remove the
2025 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
2026 * would be already be free'd recursively, leading to a double free.
2028 ath10k_spectral_destroy(ar
);
2030 /* We must unregister from mac80211 before we stop HTC and HIF.
2031 * Otherwise we will fail to submit commands to FW and mac80211 will be
2032 * unhappy about callback failures. */
2033 ath10k_mac_unregister(ar
);
2035 ath10k_testmode_destroy(ar
);
2037 ath10k_core_free_firmware_files(ar
);
2038 ath10k_core_free_board_files(ar
);
2040 ath10k_debug_unregister(ar
);
2042 EXPORT_SYMBOL(ath10k_core_unregister
);
2044 struct ath10k
*ath10k_core_create(size_t priv_size
, struct device
*dev
,
2045 enum ath10k_bus bus
,
2046 enum ath10k_hw_rev hw_rev
,
2047 const struct ath10k_hif_ops
*hif_ops
)
2052 ar
= ath10k_mac_create(priv_size
);
2056 ar
->ath_common
.priv
= ar
;
2057 ar
->ath_common
.hw
= ar
->hw
;
2059 ar
->hw_rev
= hw_rev
;
2060 ar
->hif
.ops
= hif_ops
;
2064 case ATH10K_HW_QCA988X
:
2065 ar
->regs
= &qca988x_regs
;
2066 ar
->hw_values
= &qca988x_values
;
2068 case ATH10K_HW_QCA6174
:
2069 case ATH10K_HW_QCA9377
:
2070 ar
->regs
= &qca6174_regs
;
2071 ar
->hw_values
= &qca6174_values
;
2073 case ATH10K_HW_QCA99X0
:
2074 ar
->regs
= &qca99x0_regs
;
2075 ar
->hw_values
= &qca99x0_values
;
2077 case ATH10K_HW_QCA4019
:
2078 ar
->regs
= &qca4019_regs
;
2079 ar
->hw_values
= &qca4019_values
;
2082 ath10k_err(ar
, "unsupported core hardware revision %d\n",
2088 init_completion(&ar
->scan
.started
);
2089 init_completion(&ar
->scan
.completed
);
2090 init_completion(&ar
->scan
.on_channel
);
2091 init_completion(&ar
->target_suspend
);
2092 init_completion(&ar
->wow
.wakeup_completed
);
2094 init_completion(&ar
->install_key_done
);
2095 init_completion(&ar
->vdev_setup_done
);
2096 init_completion(&ar
->thermal
.wmi_sync
);
2097 init_completion(&ar
->bss_survey_done
);
2099 INIT_DELAYED_WORK(&ar
->scan
.timeout
, ath10k_scan_timeout_work
);
2101 ar
->workqueue
= create_singlethread_workqueue("ath10k_wq");
2105 ar
->workqueue_aux
= create_singlethread_workqueue("ath10k_aux_wq");
2106 if (!ar
->workqueue_aux
)
2109 mutex_init(&ar
->conf_mutex
);
2110 spin_lock_init(&ar
->data_lock
);
2111 spin_lock_init(&ar
->txqs_lock
);
2113 INIT_LIST_HEAD(&ar
->txqs
);
2114 INIT_LIST_HEAD(&ar
->peers
);
2115 init_waitqueue_head(&ar
->peer_mapping_wq
);
2116 init_waitqueue_head(&ar
->htt
.empty_tx_wq
);
2117 init_waitqueue_head(&ar
->wmi
.tx_credits_wq
);
2119 init_completion(&ar
->offchan_tx_completed
);
2120 INIT_WORK(&ar
->offchan_tx_work
, ath10k_offchan_tx_work
);
2121 skb_queue_head_init(&ar
->offchan_tx_queue
);
2123 INIT_WORK(&ar
->wmi_mgmt_tx_work
, ath10k_mgmt_over_wmi_tx_work
);
2124 skb_queue_head_init(&ar
->wmi_mgmt_tx_queue
);
2126 INIT_WORK(&ar
->register_work
, ath10k_core_register_work
);
2127 INIT_WORK(&ar
->restart_work
, ath10k_core_restart
);
2129 ret
= ath10k_debug_create(ar
);
2131 goto err_free_aux_wq
;
2136 destroy_workqueue(ar
->workqueue_aux
);
2138 destroy_workqueue(ar
->workqueue
);
2141 ath10k_mac_destroy(ar
);
2145 EXPORT_SYMBOL(ath10k_core_create
);
2147 void ath10k_core_destroy(struct ath10k
*ar
)
2149 flush_workqueue(ar
->workqueue
);
2150 destroy_workqueue(ar
->workqueue
);
2152 flush_workqueue(ar
->workqueue_aux
);
2153 destroy_workqueue(ar
->workqueue_aux
);
2155 ath10k_debug_destroy(ar
);
2156 ath10k_wmi_free_host_mem(ar
);
2157 ath10k_mac_destroy(ar
);
2159 EXPORT_SYMBOL(ath10k_core_destroy
);
2161 MODULE_AUTHOR("Qualcomm Atheros");
2162 MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
2163 MODULE_LICENSE("Dual BSD/GPL");