2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013, 2017 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>
21 #include <asm/byteorder.h>
34 unsigned int ath10k_debug_mask;
35 static unsigned int ath10k_cryptmode_param;
36 static bool uart_print;
40 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
41 module_param_named(cryptmode, ath10k_cryptmode_param, uint, 0644);
42 module_param(uart_print, bool, 0644);
43 module_param(skip_otp, bool, 0644);
44 module_param(rawmode, bool, 0644);
46 MODULE_PARM_DESC(debug_mask, "Debugging mask");
47 MODULE_PARM_DESC(uart_print, "Uart target debugging");
48 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
49 MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
50 MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath");
52 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
54 .id = QCA988X_HW_2_0_VERSION,
55 .dev_id = QCA988X_2_0_DEVICE_ID,
56 .name = "qca988x hw2.0",
57 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
59 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
61 .channel_counters_freq_hz = 88000,
62 .max_probe_resp_desc_thres = 0,
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,
70 .hw_ops = &qca988x_ops,
71 .decap_align_bytes = 4,
74 .id = QCA9887_HW_1_0_VERSION,
75 .dev_id = QCA9887_1_0_DEVICE_ID,
76 .name = "qca9887 hw1.0",
77 .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
79 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
81 .channel_counters_freq_hz = 88000,
82 .max_probe_resp_desc_thres = 0,
85 .dir = QCA9887_HW_1_0_FW_DIR,
86 .board = QCA9887_HW_1_0_BOARD_DATA_FILE,
87 .board_size = QCA9887_BOARD_DATA_SZ,
88 .board_ext_size = QCA9887_BOARD_EXT_DATA_SZ,
90 .hw_ops = &qca988x_ops,
91 .decap_align_bytes = 4,
94 .id = QCA6174_HW_2_1_VERSION,
95 .dev_id = QCA6164_2_1_DEVICE_ID,
96 .name = "qca6164 hw2.1",
97 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
100 .channel_counters_freq_hz = 88000,
101 .max_probe_resp_desc_thres = 0,
102 .cal_data_len = 8124,
104 .dir = QCA6174_HW_2_1_FW_DIR,
105 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
106 .board_size = QCA6174_BOARD_DATA_SZ,
107 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
109 .hw_ops = &qca988x_ops,
110 .decap_align_bytes = 4,
113 .id = QCA6174_HW_2_1_VERSION,
114 .dev_id = QCA6174_2_1_DEVICE_ID,
115 .name = "qca6174 hw2.1",
116 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
119 .channel_counters_freq_hz = 88000,
120 .max_probe_resp_desc_thres = 0,
121 .cal_data_len = 8124,
123 .dir = QCA6174_HW_2_1_FW_DIR,
124 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
125 .board_size = QCA6174_BOARD_DATA_SZ,
126 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
128 .hw_ops = &qca988x_ops,
129 .decap_align_bytes = 4,
132 .id = QCA6174_HW_3_0_VERSION,
133 .dev_id = QCA6174_2_1_DEVICE_ID,
134 .name = "qca6174 hw3.0",
135 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
138 .channel_counters_freq_hz = 88000,
139 .max_probe_resp_desc_thres = 0,
140 .cal_data_len = 8124,
142 .dir = QCA6174_HW_3_0_FW_DIR,
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 .hw_ops = &qca988x_ops,
148 .decap_align_bytes = 4,
151 .id = QCA6174_HW_3_2_VERSION,
152 .dev_id = QCA6174_2_1_DEVICE_ID,
153 .name = "qca6174 hw3.2",
154 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
157 .channel_counters_freq_hz = 88000,
158 .max_probe_resp_desc_thres = 0,
159 .cal_data_len = 8124,
161 /* uses same binaries as hw3.0 */
162 .dir = QCA6174_HW_3_0_FW_DIR,
163 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
164 .board_size = QCA6174_BOARD_DATA_SZ,
165 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
167 .hw_ops = &qca988x_ops,
168 .decap_align_bytes = 4,
171 .id = QCA99X0_HW_2_0_DEV_VERSION,
172 .dev_id = QCA99X0_2_0_DEVICE_ID,
173 .name = "qca99x0 hw2.0",
174 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
176 .otp_exe_param = 0x00000700,
177 .continuous_frag_desc = true,
178 .cck_rate_map_rev2 = true,
179 .channel_counters_freq_hz = 150000,
180 .max_probe_resp_desc_thres = 24,
181 .tx_chain_mask = 0xf,
182 .rx_chain_mask = 0xf,
183 .max_spatial_stream = 4,
184 .cal_data_len = 12064,
186 .dir = QCA99X0_HW_2_0_FW_DIR,
187 .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
188 .board_size = QCA99X0_BOARD_DATA_SZ,
189 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
191 .sw_decrypt_mcast_mgmt = true,
192 .hw_ops = &qca99x0_ops,
193 .decap_align_bytes = 1,
196 .id = QCA9984_HW_1_0_DEV_VERSION,
197 .dev_id = QCA9984_1_0_DEVICE_ID,
198 .name = "qca9984/qca9994 hw1.0",
199 .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
201 .otp_exe_param = 0x00000700,
202 .continuous_frag_desc = true,
203 .cck_rate_map_rev2 = true,
204 .channel_counters_freq_hz = 150000,
205 .max_probe_resp_desc_thres = 24,
206 .tx_chain_mask = 0xf,
207 .rx_chain_mask = 0xf,
208 .max_spatial_stream = 4,
209 .cal_data_len = 12064,
211 .dir = QCA9984_HW_1_0_FW_DIR,
212 .board = QCA9984_HW_1_0_BOARD_DATA_FILE,
213 .board_size = QCA99X0_BOARD_DATA_SZ,
214 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
216 .sw_decrypt_mcast_mgmt = true,
217 .hw_ops = &qca99x0_ops,
218 .decap_align_bytes = 1,
221 .id = QCA9888_HW_2_0_DEV_VERSION,
222 .dev_id = QCA9888_2_0_DEVICE_ID,
223 .name = "qca9888 hw2.0",
224 .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
226 .otp_exe_param = 0x00000700,
227 .continuous_frag_desc = true,
228 .channel_counters_freq_hz = 150000,
229 .max_probe_resp_desc_thres = 24,
232 .max_spatial_stream = 2,
233 .cal_data_len = 12064,
235 .dir = QCA9888_HW_2_0_FW_DIR,
236 .board = QCA9888_HW_2_0_BOARD_DATA_FILE,
237 .board_size = QCA99X0_BOARD_DATA_SZ,
238 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
240 .sw_decrypt_mcast_mgmt = true,
241 .hw_ops = &qca99x0_ops,
242 .decap_align_bytes = 1,
245 .id = QCA9377_HW_1_0_DEV_VERSION,
246 .dev_id = QCA9377_1_0_DEVICE_ID,
247 .name = "qca9377 hw1.0",
248 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
251 .channel_counters_freq_hz = 88000,
252 .max_probe_resp_desc_thres = 0,
253 .cal_data_len = 8124,
255 .dir = QCA9377_HW_1_0_FW_DIR,
256 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
257 .board_size = QCA9377_BOARD_DATA_SZ,
258 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
260 .hw_ops = &qca988x_ops,
261 .decap_align_bytes = 4,
264 .id = QCA9377_HW_1_1_DEV_VERSION,
265 .dev_id = QCA9377_1_0_DEVICE_ID,
266 .name = "qca9377 hw1.1",
267 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
270 .channel_counters_freq_hz = 88000,
271 .max_probe_resp_desc_thres = 0,
272 .cal_data_len = 8124,
274 .dir = QCA9377_HW_1_0_FW_DIR,
275 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
276 .board_size = QCA9377_BOARD_DATA_SZ,
277 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
279 .hw_ops = &qca988x_ops,
280 .decap_align_bytes = 4,
283 .id = QCA4019_HW_1_0_DEV_VERSION,
285 .name = "qca4019 hw1.0",
286 .patch_load_addr = QCA4019_HW_1_0_PATCH_LOAD_ADDR,
288 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
289 .otp_exe_param = 0x0010000,
290 .continuous_frag_desc = true,
291 .cck_rate_map_rev2 = true,
292 .channel_counters_freq_hz = 125000,
293 .max_probe_resp_desc_thres = 24,
294 .tx_chain_mask = 0x3,
295 .rx_chain_mask = 0x3,
296 .max_spatial_stream = 2,
297 .cal_data_len = 12064,
299 .dir = QCA4019_HW_1_0_FW_DIR,
300 .board = QCA4019_HW_1_0_BOARD_DATA_FILE,
301 .board_size = QCA4019_BOARD_DATA_SZ,
302 .board_ext_size = QCA4019_BOARD_EXT_DATA_SZ,
304 .sw_decrypt_mcast_mgmt = true,
305 .hw_ops = &qca99x0_ops,
306 .decap_align_bytes = 1,
309 .id = ATH10K_HW_WCN3990,
311 .name = "wcn3990 hw1.0",
312 .continuous_frag_desc = true,
313 .tx_chain_mask = 0x7,
314 .rx_chain_mask = 0x7,
315 .max_spatial_stream = 4,
317 .dir = WCN3990_HW_1_0_FW_DIR,
319 .sw_decrypt_mcast_mgmt = true,
320 .hw_ops = &wcn3990_ops,
321 .decap_align_bytes = 1,
325 static const char *const ath10k_core_fw_feature_str[] = {
326 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
327 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
328 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
329 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
330 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
331 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
332 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
333 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
334 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
335 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
336 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
337 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA] = "adaptive-cca",
338 [ATH10K_FW_FEATURE_MFP_SUPPORT] = "mfp",
339 [ATH10K_FW_FEATURE_PEER_FLOW_CONTROL] = "peer-flow-ctrl",
340 [ATH10K_FW_FEATURE_BTCOEX_PARAM] = "btcoex-param",
341 [ATH10K_FW_FEATURE_SKIP_NULL_FUNC_WAR] = "skip-null-func-war",
344 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
346 enum ath10k_fw_features feat)
348 /* make sure that ath10k_core_fw_feature_str[] gets updated */
349 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
350 ATH10K_FW_FEATURE_COUNT);
352 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
353 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
354 return scnprintf(buf, buf_len, "bit%d", feat);
357 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
360 void ath10k_core_get_fw_features_str(struct ath10k *ar,
364 unsigned int len = 0;
367 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
368 if (test_bit(i, ar->normal_mode_fw.fw_file.fw_features)) {
370 len += scnprintf(buf + len, buf_len - len, ",");
372 len += ath10k_core_get_fw_feature_str(buf + len,
379 static void ath10k_send_suspend_complete(struct ath10k *ar)
381 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
383 complete(&ar->target_suspend);
386 static int ath10k_init_configure_target(struct ath10k *ar)
391 /* tell target which HTC version it is used*/
392 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
393 HTC_PROTOCOL_VERSION);
395 ath10k_err(ar, "settings HTC version failed\n");
399 /* set the firmware mode to STA/IBSS/AP */
400 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
402 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
406 /* TODO following parameters need to be re-visited. */
408 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
410 /* FIXME: Why FW_MODE_AP ??.*/
411 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
412 /* mac_addr_method */
413 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
414 /* firmware_bridge */
415 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
417 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
419 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
421 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
425 /* We do all byte-swapping on the host */
426 ret = ath10k_bmi_write32(ar, hi_be, 0);
428 ath10k_err(ar, "setting host CPU BE mode failed\n");
432 /* FW descriptor/Data swap flags */
433 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
436 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
440 /* Some devices have a special sanity check that verifies the PCI
441 * Device ID is written to this host interest var. It is known to be
442 * required to boot QCA6164.
444 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
447 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
454 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
459 const struct firmware *fw;
463 return ERR_PTR(-ENOENT);
468 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
469 ret = request_firmware(&fw, filename, ar->dev);
476 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
479 u32 board_data_size = ar->hw_params.fw.board_size;
480 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
481 u32 board_ext_data_addr;
484 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
486 ath10k_err(ar, "could not read board ext data addr (%d)\n",
491 ath10k_dbg(ar, ATH10K_DBG_BOOT,
492 "boot push board extended data addr 0x%x\n",
493 board_ext_data_addr);
495 if (board_ext_data_addr == 0)
498 if (data_len != (board_data_size + board_ext_data_size)) {
499 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
500 data_len, board_data_size, board_ext_data_size);
504 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
505 data + board_data_size,
506 board_ext_data_size);
508 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
512 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
513 (board_ext_data_size << 16) | 1);
515 ath10k_err(ar, "could not write board ext data bit (%d)\n",
523 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
526 u32 board_data_size = ar->hw_params.fw.board_size;
530 ret = ath10k_push_board_ext_data(ar, data, data_len);
532 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
536 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
538 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
542 ret = ath10k_bmi_write_memory(ar, address, data,
543 min_t(u32, board_data_size,
546 ath10k_err(ar, "could not write board data (%d)\n", ret);
550 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
552 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
560 static int ath10k_download_cal_file(struct ath10k *ar,
561 const struct firmware *file)
569 return PTR_ERR(file);
571 ret = ath10k_download_board_data(ar, file->data, file->size);
573 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
577 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
582 static int ath10k_download_cal_dt(struct ath10k *ar, const char *dt_name)
584 struct device_node *node;
589 node = ar->dev->of_node;
591 /* Device Tree is optional, don't print any warnings if
592 * there's no node for ath10k.
596 if (!of_get_property(node, dt_name, &data_len)) {
597 /* The calibration data node is optional */
601 if (data_len != ar->hw_params.cal_data_len) {
602 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
608 data = kmalloc(data_len, GFP_KERNEL);
614 ret = of_property_read_u8_array(node, dt_name, data, data_len);
616 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
621 ret = ath10k_download_board_data(ar, data, data_len);
623 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
637 static int ath10k_download_cal_eeprom(struct ath10k *ar)
643 ret = ath10k_hif_fetch_cal_eeprom(ar, &data, &data_len);
645 if (ret != -EOPNOTSUPP)
646 ath10k_warn(ar, "failed to read calibration data from EEPROM: %d\n",
651 ret = ath10k_download_board_data(ar, data, data_len);
653 ath10k_warn(ar, "failed to download calibration data from EEPROM: %d\n",
666 static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
669 u8 board_id, chip_id;
672 address = ar->hw_params.patch_load_addr;
674 if (!ar->normal_mode_fw.fw_file.otp_data ||
675 !ar->normal_mode_fw.fw_file.otp_len) {
677 "failed to retrieve board id because of invalid otp\n");
681 ath10k_dbg(ar, ATH10K_DBG_BOOT,
682 "boot upload otp to 0x%x len %zd for board id\n",
683 address, ar->normal_mode_fw.fw_file.otp_len);
685 ret = ath10k_bmi_fast_download(ar, address,
686 ar->normal_mode_fw.fw_file.otp_data,
687 ar->normal_mode_fw.fw_file.otp_len);
689 ath10k_err(ar, "could not write otp for board id check: %d\n",
694 ret = ath10k_bmi_execute(ar, address, BMI_PARAM_GET_EEPROM_BOARD_ID,
697 ath10k_err(ar, "could not execute otp for board id check: %d\n",
702 board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP);
703 chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP);
705 ath10k_dbg(ar, ATH10K_DBG_BOOT,
706 "boot get otp board id result 0x%08x board_id %d chip_id %d\n",
707 result, board_id, chip_id);
709 if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0 ||
711 ath10k_warn(ar, "board id is not exist in otp, ignore it\n");
715 ar->id.bmi_ids_valid = true;
716 ar->id.bmi_board_id = board_id;
717 ar->id.bmi_chip_id = chip_id;
722 static int ath10k_download_and_run_otp(struct ath10k *ar)
724 u32 result, address = ar->hw_params.patch_load_addr;
725 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
728 ret = ath10k_download_board_data(ar,
729 ar->running_fw->board_data,
730 ar->running_fw->board_len);
732 ath10k_err(ar, "failed to download board data: %d\n", ret);
736 /* OTP is optional */
738 if (!ar->running_fw->fw_file.otp_data ||
739 !ar->running_fw->fw_file.otp_len) {
740 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %pK otp_len %zd)!\n",
741 ar->running_fw->fw_file.otp_data,
742 ar->running_fw->fw_file.otp_len);
746 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
747 address, ar->running_fw->fw_file.otp_len);
749 ret = ath10k_bmi_fast_download(ar, address,
750 ar->running_fw->fw_file.otp_data,
751 ar->running_fw->fw_file.otp_len);
753 ath10k_err(ar, "could not write otp (%d)\n", ret);
757 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
759 ath10k_err(ar, "could not execute otp (%d)\n", ret);
763 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
765 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
766 ar->running_fw->fw_file.fw_features)) &&
768 ath10k_err(ar, "otp calibration failed: %d", result);
775 static int ath10k_download_fw(struct ath10k *ar)
777 u32 address, data_len;
781 address = ar->hw_params.patch_load_addr;
783 data = ar->running_fw->fw_file.firmware_data;
784 data_len = ar->running_fw->fw_file.firmware_len;
786 ret = ath10k_swap_code_seg_configure(ar, &ar->running_fw->fw_file);
788 ath10k_err(ar, "failed to configure fw code swap: %d\n",
793 ath10k_dbg(ar, ATH10K_DBG_BOOT,
794 "boot uploading firmware image %pK len %d\n",
797 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
799 ath10k_err(ar, "failed to download firmware: %d\n",
807 static void ath10k_core_free_board_files(struct ath10k *ar)
809 if (!IS_ERR(ar->normal_mode_fw.board))
810 release_firmware(ar->normal_mode_fw.board);
812 ar->normal_mode_fw.board = NULL;
813 ar->normal_mode_fw.board_data = NULL;
814 ar->normal_mode_fw.board_len = 0;
817 static void ath10k_core_free_firmware_files(struct ath10k *ar)
819 if (!IS_ERR(ar->normal_mode_fw.fw_file.firmware))
820 release_firmware(ar->normal_mode_fw.fw_file.firmware);
822 if (!IS_ERR(ar->cal_file))
823 release_firmware(ar->cal_file);
825 if (!IS_ERR(ar->pre_cal_file))
826 release_firmware(ar->pre_cal_file);
828 ath10k_swap_code_seg_release(ar, &ar->normal_mode_fw.fw_file);
830 ar->normal_mode_fw.fw_file.otp_data = NULL;
831 ar->normal_mode_fw.fw_file.otp_len = 0;
833 ar->normal_mode_fw.fw_file.firmware = NULL;
834 ar->normal_mode_fw.fw_file.firmware_data = NULL;
835 ar->normal_mode_fw.fw_file.firmware_len = 0;
838 ar->pre_cal_file = NULL;
841 static int ath10k_fetch_cal_file(struct ath10k *ar)
845 /* pre-cal-<bus>-<id>.bin */
846 scnprintf(filename, sizeof(filename), "pre-cal-%s-%s.bin",
847 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
849 ar->pre_cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
850 if (!IS_ERR(ar->pre_cal_file))
853 /* cal-<bus>-<id>.bin */
854 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
855 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
857 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
858 if (IS_ERR(ar->cal_file))
859 /* calibration file is optional, don't print any warnings */
860 return PTR_ERR(ar->cal_file);
862 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
863 ATH10K_FW_DIR, filename);
868 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar)
870 if (!ar->hw_params.fw.board) {
871 ath10k_err(ar, "failed to find board file fw entry\n");
875 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
876 ar->hw_params.fw.dir,
877 ar->hw_params.fw.board);
878 if (IS_ERR(ar->normal_mode_fw.board))
879 return PTR_ERR(ar->normal_mode_fw.board);
881 ar->normal_mode_fw.board_data = ar->normal_mode_fw.board->data;
882 ar->normal_mode_fw.board_len = ar->normal_mode_fw.board->size;
887 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
888 const void *buf, size_t buf_len,
889 const char *boardname)
891 const struct ath10k_fw_ie *hdr;
892 bool name_match_found;
893 int ret, board_ie_id;
895 const void *board_ie_data;
897 name_match_found = false;
899 /* go through ATH10K_BD_IE_BOARD_ elements */
900 while (buf_len > sizeof(struct ath10k_fw_ie)) {
902 board_ie_id = le32_to_cpu(hdr->id);
903 board_ie_len = le32_to_cpu(hdr->len);
904 board_ie_data = hdr->data;
906 buf_len -= sizeof(*hdr);
909 if (buf_len < ALIGN(board_ie_len, 4)) {
910 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
911 buf_len, ALIGN(board_ie_len, 4));
916 switch (board_ie_id) {
917 case ATH10K_BD_IE_BOARD_NAME:
918 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
919 board_ie_data, board_ie_len);
921 if (board_ie_len != strlen(boardname))
924 ret = memcmp(board_ie_data, boardname, strlen(boardname));
928 name_match_found = true;
929 ath10k_dbg(ar, ATH10K_DBG_BOOT,
930 "boot found match for name '%s'",
933 case ATH10K_BD_IE_BOARD_DATA:
934 if (!name_match_found)
938 ath10k_dbg(ar, ATH10K_DBG_BOOT,
939 "boot found board data for '%s'",
942 ar->normal_mode_fw.board_data = board_ie_data;
943 ar->normal_mode_fw.board_len = board_ie_len;
948 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
953 /* jump over the padding */
954 board_ie_len = ALIGN(board_ie_len, 4);
956 buf_len -= board_ie_len;
967 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
968 const char *boardname,
969 const char *filename)
971 size_t len, magic_len, ie_len;
972 struct ath10k_fw_ie *hdr;
976 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
977 ar->hw_params.fw.dir,
979 if (IS_ERR(ar->normal_mode_fw.board))
980 return PTR_ERR(ar->normal_mode_fw.board);
982 data = ar->normal_mode_fw.board->data;
983 len = ar->normal_mode_fw.board->size;
985 /* magic has extra null byte padded */
986 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
987 if (len < magic_len) {
988 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
989 ar->hw_params.fw.dir, filename, len);
994 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
995 ath10k_err(ar, "found invalid board magic\n");
1000 /* magic is padded to 4 bytes */
1001 magic_len = ALIGN(magic_len, 4);
1002 if (len < magic_len) {
1003 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
1004 ar->hw_params.fw.dir, filename, len);
1012 while (len > sizeof(struct ath10k_fw_ie)) {
1013 hdr = (struct ath10k_fw_ie *)data;
1014 ie_id = le32_to_cpu(hdr->id);
1015 ie_len = le32_to_cpu(hdr->len);
1017 len -= sizeof(*hdr);
1020 if (len < ALIGN(ie_len, 4)) {
1021 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
1022 ie_id, ie_len, len);
1028 case ATH10K_BD_IE_BOARD:
1029 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
1032 /* no match found, continue */
1035 /* there was an error, bail out */
1038 /* board data found */
1042 /* jump over the padding */
1043 ie_len = ALIGN(ie_len, 4);
1050 if (!ar->normal_mode_fw.board_data || !ar->normal_mode_fw.board_len) {
1052 "failed to fetch board data for %s from %s/%s\n",
1053 boardname, ar->hw_params.fw.dir, filename);
1061 ath10k_core_free_board_files(ar);
1065 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
1068 if (ar->id.bmi_ids_valid) {
1069 scnprintf(name, name_len,
1070 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d",
1071 ath10k_bus_str(ar->hif.bus),
1073 ar->id.bmi_board_id);
1077 scnprintf(name, name_len,
1078 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
1079 ath10k_bus_str(ar->hif.bus),
1080 ar->id.vendor, ar->id.device,
1081 ar->id.subsystem_vendor, ar->id.subsystem_device);
1084 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
1089 static int ath10k_core_fetch_board_file(struct ath10k *ar)
1091 char boardname[100];
1094 ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
1096 ath10k_err(ar, "failed to create board name: %d", ret);
1101 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
1102 ATH10K_BOARD_API2_FILE);
1107 ret = ath10k_core_fetch_board_data_api_1(ar);
1109 ath10k_err(ar, "failed to fetch board data\n");
1114 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
1118 int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name,
1119 struct ath10k_fw_file *fw_file)
1121 size_t magic_len, len, ie_len;
1122 int ie_id, i, index, bit, ret;
1123 struct ath10k_fw_ie *hdr;
1125 __le32 *timestamp, *version;
1127 /* first fetch the firmware file (firmware-*.bin) */
1128 fw_file->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
1130 if (IS_ERR(fw_file->firmware)) {
1131 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
1132 ar->hw_params.fw.dir, name,
1133 PTR_ERR(fw_file->firmware));
1134 return PTR_ERR(fw_file->firmware);
1137 data = fw_file->firmware->data;
1138 len = fw_file->firmware->size;
1140 /* magic also includes the null byte, check that as well */
1141 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
1143 if (len < magic_len) {
1144 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
1145 ar->hw_params.fw.dir, name, len);
1150 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
1151 ath10k_err(ar, "invalid firmware magic\n");
1156 /* jump over the padding */
1157 magic_len = ALIGN(magic_len, 4);
1163 while (len > sizeof(struct ath10k_fw_ie)) {
1164 hdr = (struct ath10k_fw_ie *)data;
1166 ie_id = le32_to_cpu(hdr->id);
1167 ie_len = le32_to_cpu(hdr->len);
1169 len -= sizeof(*hdr);
1170 data += sizeof(*hdr);
1173 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
1174 ie_id, len, ie_len);
1180 case ATH10K_FW_IE_FW_VERSION:
1181 if (ie_len > sizeof(fw_file->fw_version) - 1)
1184 memcpy(fw_file->fw_version, data, ie_len);
1185 fw_file->fw_version[ie_len] = '\0';
1187 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1188 "found fw version %s\n",
1189 fw_file->fw_version);
1191 case ATH10K_FW_IE_TIMESTAMP:
1192 if (ie_len != sizeof(u32))
1195 timestamp = (__le32 *)data;
1197 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
1198 le32_to_cpup(timestamp));
1200 case ATH10K_FW_IE_FEATURES:
1201 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1202 "found firmware features ie (%zd B)\n",
1205 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
1209 if (index == ie_len)
1212 if (data[index] & (1 << bit)) {
1213 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1214 "Enabling feature bit: %i\n",
1216 __set_bit(i, fw_file->fw_features);
1220 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
1221 fw_file->fw_features,
1222 sizeof(fw_file->fw_features));
1224 case ATH10K_FW_IE_FW_IMAGE:
1225 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1226 "found fw image ie (%zd B)\n",
1229 fw_file->firmware_data = data;
1230 fw_file->firmware_len = ie_len;
1233 case ATH10K_FW_IE_OTP_IMAGE:
1234 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1235 "found otp image ie (%zd B)\n",
1238 fw_file->otp_data = data;
1239 fw_file->otp_len = ie_len;
1242 case ATH10K_FW_IE_WMI_OP_VERSION:
1243 if (ie_len != sizeof(u32))
1246 version = (__le32 *)data;
1248 fw_file->wmi_op_version = le32_to_cpup(version);
1250 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1251 fw_file->wmi_op_version);
1253 case ATH10K_FW_IE_HTT_OP_VERSION:
1254 if (ie_len != sizeof(u32))
1257 version = (__le32 *)data;
1259 fw_file->htt_op_version = le32_to_cpup(version);
1261 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1262 fw_file->htt_op_version);
1264 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1265 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1266 "found fw code swap image ie (%zd B)\n",
1268 fw_file->codeswap_data = data;
1269 fw_file->codeswap_len = ie_len;
1272 ath10k_warn(ar, "Unknown FW IE: %u\n",
1273 le32_to_cpu(hdr->id));
1277 /* jump over the padding */
1278 ie_len = ALIGN(ie_len, 4);
1285 if (!fw_file->firmware_data ||
1286 !fw_file->firmware_len) {
1287 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1288 ar->hw_params.fw.dir, name);
1297 ath10k_core_free_firmware_files(ar);
1301 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1304 struct ath10k_fw_file *fw_file;
1306 if (!ar->is_bmi && QCA_REV_WCN3990(ar)) {
1307 fw_file = &ar->normal_mode_fw.fw_file;
1308 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_TLV;
1309 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1310 __set_bit(ATH10K_FW_FEATURE_WOWLAN_SUPPORT,
1311 fw_file->fw_features);
1312 __set_bit(WMI_SERVICE_WOW, ar->wmi.svc_map);
1313 __set_bit(ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING,
1314 fw_file->fw_features);
1319 /* calibration file is optional, don't check for any errors */
1320 ath10k_fetch_cal_file(ar);
1324 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1326 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE,
1327 &ar->normal_mode_fw.fw_file);
1332 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1334 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE,
1335 &ar->normal_mode_fw.fw_file);
1340 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1342 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE,
1343 &ar->normal_mode_fw.fw_file);
1348 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1350 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE,
1351 &ar->normal_mode_fw.fw_file);
1356 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1361 static int ath10k_core_pre_cal_download(struct ath10k *ar)
1365 ret = ath10k_download_cal_file(ar, ar->pre_cal_file);
1367 ar->cal_mode = ATH10K_PRE_CAL_MODE_FILE;
1371 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1372 "boot did not find a pre calibration file, try DT next: %d\n",
1375 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-pre-calibration-data");
1377 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1378 "unable to load pre cal data from DT: %d\n", ret);
1381 ar->cal_mode = ATH10K_PRE_CAL_MODE_DT;
1384 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1385 ath10k_cal_mode_str(ar->cal_mode));
1390 static int ath10k_core_pre_cal_config(struct ath10k *ar)
1394 ret = ath10k_core_pre_cal_download(ar);
1396 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1397 "failed to load pre cal data: %d\n", ret);
1401 ret = ath10k_core_get_board_id_from_otp(ar);
1403 ath10k_err(ar, "failed to get board id: %d\n", ret);
1407 ret = ath10k_download_and_run_otp(ar);
1409 ath10k_err(ar, "failed to run otp: %d\n", ret);
1413 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1414 "pre cal configuration done successfully\n");
1419 static int ath10k_download_cal_data(struct ath10k *ar)
1423 ret = ath10k_core_pre_cal_config(ar);
1427 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1428 "pre cal download procedure failed, try cal file: %d\n",
1431 ret = ath10k_download_cal_file(ar, ar->cal_file);
1433 ar->cal_mode = ATH10K_CAL_MODE_FILE;
1437 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1438 "boot did not find a calibration file, try DT next: %d\n",
1441 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-calibration-data");
1443 ar->cal_mode = ATH10K_CAL_MODE_DT;
1447 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1448 "boot did not find DT entry, try target EEPROM next: %d\n",
1451 ret = ath10k_download_cal_eeprom(ar);
1453 ar->cal_mode = ATH10K_CAL_MODE_EEPROM;
1457 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1458 "boot did not find target EEPROM entry, try OTP next: %d\n",
1461 ret = ath10k_download_and_run_otp(ar);
1463 ath10k_err(ar, "failed to run otp: %d\n", ret);
1467 ar->cal_mode = ATH10K_CAL_MODE_OTP;
1470 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1471 ath10k_cal_mode_str(ar->cal_mode));
1475 static int ath10k_init_uart(struct ath10k *ar)
1480 * Explicitly setting UART prints to zero as target turns it on
1481 * based on scratch registers.
1483 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
1485 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
1492 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
1494 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1498 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
1500 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1504 /* Set the UART baud rate to 19200. */
1505 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1507 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1511 ath10k_info(ar, "UART prints enabled\n");
1515 static int ath10k_init_hw_params(struct ath10k *ar)
1517 const struct ath10k_hw_params *uninitialized_var(hw_params);
1520 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1521 hw_params = &ath10k_hw_params_list[i];
1523 if (hw_params->id == ar->target_version &&
1524 hw_params->dev_id == ar->dev_id)
1528 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1529 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1530 ar->target_version);
1534 ar->hw_params = *hw_params;
1536 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1537 ar->hw_params.name, ar->target_version);
1542 static void ath10k_core_restart(struct work_struct *work)
1544 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1546 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1548 /* Place a barrier to make sure the compiler doesn't reorder
1549 * CRASH_FLUSH and calling other functions.
1553 ieee80211_stop_queues(ar->hw);
1554 ath10k_drain_tx(ar);
1555 complete(&ar->scan.started);
1556 complete(&ar->scan.completed);
1557 complete(&ar->scan.on_channel);
1558 complete(&ar->offchan_tx_completed);
1559 complete(&ar->install_key_done);
1560 complete(&ar->vdev_setup_done);
1561 complete(&ar->vdev_delete_done);
1562 complete(&ar->thermal.wmi_sync);
1563 complete(&ar->bss_survey_done);
1564 wake_up(&ar->htt.empty_tx_wq);
1565 wake_up(&ar->wmi.tx_credits_wq);
1566 wake_up(&ar->peer_mapping_wq);
1568 mutex_lock(&ar->conf_mutex);
1570 switch (ar->state) {
1571 case ATH10K_STATE_ON:
1572 ar->state = ATH10K_STATE_RESTARTING;
1573 ath10k_hif_stop(ar);
1574 ath10k_scan_finish(ar);
1575 ieee80211_restart_hw(ar->hw);
1577 case ATH10K_STATE_OFF:
1578 /* this can happen if driver is being unloaded
1579 * or if the crash happens during FW probing */
1580 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1582 case ATH10K_STATE_RESTARTING:
1583 /* hw restart might be requested from multiple places */
1585 case ATH10K_STATE_RESTARTED:
1586 ar->state = ATH10K_STATE_WEDGED;
1588 case ATH10K_STATE_WEDGED:
1589 ath10k_warn(ar, "device is wedged, will not restart\n");
1591 case ATH10K_STATE_UTF:
1592 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1596 mutex_unlock(&ar->conf_mutex);
1599 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1601 struct ath10k_fw_file *fw_file = &ar->normal_mode_fw.fw_file;
1603 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, fw_file->fw_features) &&
1604 !test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
1605 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1609 if (fw_file->wmi_op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1610 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1611 ATH10K_FW_WMI_OP_VERSION_MAX, fw_file->wmi_op_version);
1615 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1616 switch (ath10k_cryptmode_param) {
1617 case ATH10K_CRYPT_MODE_HW:
1618 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1619 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1621 case ATH10K_CRYPT_MODE_SW:
1622 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1623 fw_file->fw_features)) {
1624 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1628 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1629 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1632 ath10k_info(ar, "invalid cryptmode: %d\n",
1633 ath10k_cryptmode_param);
1637 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1638 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1641 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1642 fw_file->fw_features)) {
1643 ath10k_err(ar, "rawmode = 1 requires support from firmware");
1646 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1649 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1650 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1654 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1655 * and causes enormous performance issues (malformed frames,
1658 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1659 * albeit a bit slower compared to regular operation.
1661 ar->htt.max_num_amsdu = 1;
1664 /* Backwards compatibility for firmwares without
1665 * ATH10K_FW_IE_WMI_OP_VERSION.
1667 if (fw_file->wmi_op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1668 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
1669 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1670 fw_file->fw_features))
1671 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1673 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1675 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1679 switch (fw_file->wmi_op_version) {
1680 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1681 ar->max_num_peers = TARGET_NUM_PEERS;
1682 ar->max_num_stations = TARGET_NUM_STATIONS;
1683 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1684 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1685 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1687 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1689 case ATH10K_FW_WMI_OP_VERSION_10_1:
1690 case ATH10K_FW_WMI_OP_VERSION_10_2:
1691 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1692 if (ath10k_peer_stats_enabled(ar)) {
1693 ar->max_num_peers = TARGET_10X_TX_STATS_NUM_PEERS;
1694 ar->max_num_stations = TARGET_10X_TX_STATS_NUM_STATIONS;
1696 ar->max_num_peers = TARGET_10X_NUM_PEERS;
1697 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1699 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1700 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1701 ar->fw_stats_req_mask = WMI_STAT_PEER;
1702 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1704 case ATH10K_FW_WMI_OP_VERSION_TLV:
1705 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1706 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1707 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1708 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1709 if (QCA_REV_WCN3990(ar))
1710 ar->htt.max_num_pending_tx =
1711 TARGET_HL_1_0_NUM_MSDU_DESC;
1713 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1714 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1715 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1717 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1718 ar->wmi.mgmt_max_num_pending_tx = TARGET_TLV_MGMT_NUM_MSDU_DESC;
1720 case ATH10K_FW_WMI_OP_VERSION_10_4:
1721 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1722 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1723 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1724 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1725 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1726 ar->fw_stats_req_mask = WMI_10_4_STAT_PEER |
1727 WMI_10_4_STAT_PEER_EXTD;
1728 ar->max_spatial_stream = ar->hw_params.max_spatial_stream;
1730 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
1731 fw_file->fw_features))
1732 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC_PFC;
1734 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1736 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1737 case ATH10K_FW_WMI_OP_VERSION_MAX:
1742 /* Backwards compatibility for firmwares without
1743 * ATH10K_FW_IE_HTT_OP_VERSION.
1745 if (fw_file->htt_op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1746 switch (fw_file->wmi_op_version) {
1747 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1748 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1750 case ATH10K_FW_WMI_OP_VERSION_10_1:
1751 case ATH10K_FW_WMI_OP_VERSION_10_2:
1752 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1753 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1755 case ATH10K_FW_WMI_OP_VERSION_TLV:
1756 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1758 case ATH10K_FW_WMI_OP_VERSION_10_4:
1759 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1760 case ATH10K_FW_WMI_OP_VERSION_MAX:
1761 ath10k_err(ar, "htt op version not found from fw meta data");
1769 static int ath10k_core_reset_rx_filter(struct ath10k *ar)
1775 const u8 *vdev_addr;
1778 vdev_type = WMI_VDEV_TYPE_STA;
1779 vdev_subtype = ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
1780 vdev_addr = ar->mac_addr;
1782 ret = ath10k_wmi_vdev_create(ar, vdev_id, vdev_type, vdev_subtype,
1785 ath10k_err(ar, "failed to create dummy vdev: %d\n", ret);
1789 ret = ath10k_wmi_vdev_delete(ar, vdev_id);
1791 ath10k_err(ar, "failed to delete dummy vdev: %d\n", ret);
1795 /* WMI and HTT may use separate HIF pipes and are not guaranteed to be
1796 * serialized properly implicitly.
1798 * Moreover (most) WMI commands have no explicit acknowledges. It is
1799 * possible to infer it implicitly by poking firmware with echo
1800 * command - getting a reply means all preceding comments have been
1801 * (mostly) processed.
1803 * In case of vdev create/delete this is sufficient.
1805 * Without this it's possible to end up with a race when HTT Rx ring is
1806 * started before vdev create/delete hack is complete allowing a short
1807 * window of opportunity to receive (and Tx ACK) a bunch of frames.
1809 ret = ath10k_wmi_barrier(ar);
1811 ath10k_err(ar, "failed to ping firmware: %d\n", ret);
1818 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
1819 const struct ath10k_fw_components *fw)
1824 lockdep_assert_held(&ar->conf_mutex);
1826 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1828 ar->running_fw = fw;
1832 ath10k_bmi_start(ar);
1834 if (ath10k_init_configure_target(ar)) {
1839 status = ath10k_download_cal_data(ar);
1843 /* Some of of qca988x solutions are having global reset issue
1844 * during target initialization. Bypassing PLL setting before
1845 * downloading firmware and letting the SoC run on REF_CLK is
1846 * fixing the problem. Corresponding firmware change is also
1847 * needed to set the clock source once the target is
1850 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1851 ar->running_fw->fw_file.fw_features)) {
1852 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1854 ath10k_err(ar, "skip_clock_init failed: %d\n",
1860 status = ath10k_download_fw(ar);
1864 status = ath10k_init_uart(ar);
1869 ar->htc.htc_ops.target_send_suspend_complete =
1870 ath10k_send_suspend_complete;
1872 status = ath10k_htc_init(ar);
1874 ath10k_err(ar, "could not init HTC (%d)\n", status);
1879 status = ath10k_bmi_done(ar);
1884 status = ath10k_wmi_attach(ar);
1886 ath10k_err(ar, "WMI attach failed: %d\n", status);
1890 status = ath10k_htt_init(ar);
1892 ath10k_err(ar, "failed to init htt: %d\n", status);
1893 goto err_wmi_detach;
1896 status = ath10k_htt_tx_alloc(&ar->htt);
1898 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1899 goto err_wmi_detach;
1902 /* If firmware indicates Full Rx Reorder support it must be used in a
1903 * slightly different manner. Let HTT code know.
1905 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1908 status = ath10k_htt_rx_alloc(&ar->htt);
1910 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1911 goto err_htt_tx_detach;
1914 status = ath10k_hif_start(ar);
1916 ath10k_err(ar, "could not start HIF: %d\n", status);
1917 goto err_htt_rx_detach;
1920 status = ath10k_htc_wait_target(&ar->htc);
1922 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1926 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1927 status = ath10k_htt_connect(&ar->htt);
1929 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1934 status = ath10k_wmi_connect(ar);
1936 ath10k_err(ar, "could not connect wmi: %d\n", status);
1940 status = ath10k_pktlog_connect(ar);
1942 ath10k_err(ar, "could not connect pktlog: %d\n", status);
1946 status = ath10k_htc_start(&ar->htc);
1948 ath10k_err(ar, "failed to start htc: %d\n", status);
1952 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1953 status = ath10k_wmi_wait_for_service_ready(ar);
1955 ath10k_warn(ar, "wmi service ready event not received");
1960 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1961 ar->hw->wiphy->fw_version);
1963 if (test_bit(WMI_SERVICE_EXT_RES_CFG_SUPPORT, ar->wmi.svc_map)) {
1965 if (ath10k_peer_stats_enabled(ar))
1966 val = WMI_10_4_PEER_STATS;
1968 if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map))
1969 val |= WMI_10_4_BSS_CHANNEL_INFO_64;
1971 /* 10.4 firmware supports BT-Coex without reloading firmware
1972 * via pdev param. To support Bluetooth coexistence pdev param,
1973 * WMI_COEX_GPIO_SUPPORT of extended resource config should be
1976 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
1977 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
1978 ar->running_fw->fw_file.fw_features))
1979 val |= WMI_10_4_COEX_GPIO_SUPPORT;
1981 status = ath10k_mac_ext_resource_config(ar, val);
1984 "failed to send ext resource cfg command : %d\n",
1990 status = ath10k_wmi_cmd_init(ar);
1992 ath10k_err(ar, "could not send WMI init command (%d)\n",
1997 status = ath10k_wmi_wait_for_unified_ready(ar);
1999 ath10k_err(ar, "wmi unified ready event not received\n");
2003 /* Some firmware revisions do not properly set up hardware rx filter
2006 * A known example from QCA9880 and 10.2.4 is that MAC_PCU_ADDR1_MASK
2007 * is filled with 0s instead of 1s allowing HW to respond with ACKs to
2008 * any frames that matches MAC_PCU_RX_FILTER which is also
2009 * misconfigured to accept anything.
2011 * The ADDR1 is programmed using internal firmware structure field and
2012 * can't be (easily/sanely) reached from the driver explicitly. It is
2013 * possible to implicitly make it correct by creating a dummy vdev and
2016 if (!QCA_REV_WCN3990(ar)) {
2017 status = ath10k_core_reset_rx_filter(ar);
2019 ath10k_err(ar, "failed to reset rx filter: %d\n",
2025 status = ath10k_htt_rx_ring_refill(ar);
2027 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
2031 if (ar->max_num_vdevs >= 64)
2032 ar->free_vdev_map = 0xFFFFFFFFFFFFFFFFLL;
2034 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
2036 INIT_LIST_HEAD(&ar->arvifs);
2038 /* we don't care about HTT in UTF mode */
2039 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2040 status = ath10k_htt_setup(&ar->htt);
2042 ath10k_err(ar, "failed to setup htt: %d\n", status);
2047 status = ath10k_debug_start(ar);
2054 ath10k_hif_stop(ar);
2056 ath10k_htt_rx_free(&ar->htt);
2058 ath10k_htt_tx_free(&ar->htt);
2060 ath10k_wmi_detach(ar);
2064 EXPORT_SYMBOL(ath10k_core_start);
2066 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
2069 unsigned long time_left;
2071 reinit_completion(&ar->target_suspend);
2073 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
2075 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
2079 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
2082 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
2089 void ath10k_core_stop(struct ath10k *ar)
2091 lockdep_assert_held(&ar->conf_mutex);
2092 ath10k_debug_stop(ar);
2094 /* try to suspend target */
2095 if (ar->state != ATH10K_STATE_RESTARTING &&
2096 ar->state != ATH10K_STATE_UTF)
2097 ath10k_wait_for_suspend(ar, ar->hw_values->pdev_suspend_option);
2099 ath10k_hif_stop(ar);
2100 ath10k_htt_tx_free(&ar->htt);
2101 ath10k_htt_rx_free(&ar->htt);
2102 ath10k_wmi_detach(ar);
2104 EXPORT_SYMBOL(ath10k_core_stop);
2106 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
2107 * order to know what hw capabilities should be advertised to mac80211 it is
2108 * necessary to load the firmware (and tear it down immediately since start
2109 * hook will try to init it again) before registering */
2110 static int ath10k_core_probe_fw(struct ath10k *ar)
2112 struct bmi_target_info target_info;
2115 ret = ath10k_hif_power_up(ar);
2117 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
2122 memset(&target_info, 0, sizeof(target_info));
2123 ret = ath10k_bmi_get_target_info(ar, &target_info);
2125 ath10k_err(ar, "could not get target info (%d)\n", ret);
2126 goto err_power_down;
2128 ar->target_version = target_info.version;
2129 ar->hw->wiphy->hw_version = target_info.version;
2132 ret = ath10k_init_hw_params(ar);
2134 ath10k_err(ar, "could not get hw params (%d)\n", ret);
2135 goto err_power_down;
2138 ret = ath10k_core_fetch_firmware_files(ar);
2140 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
2141 goto err_power_down;
2144 BUILD_BUG_ON(sizeof(ar->hw->wiphy->fw_version) !=
2145 sizeof(ar->normal_mode_fw.fw_file.fw_version));
2146 memcpy(ar->hw->wiphy->fw_version,
2147 ar->normal_mode_fw.fw_file.fw_version,
2148 sizeof(ar->hw->wiphy->fw_version));
2149 ath10k_debug_print_hwfw_info(ar);
2152 ret = ath10k_core_pre_cal_download(ar);
2154 /* pre calibration data download is not necessary
2155 * for all the chipsets. Ignore failures and continue.
2157 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2158 "could not load pre cal data: %d\n", ret);
2161 ret = ath10k_core_get_board_id_from_otp(ar);
2162 if (ret && ret != -EOPNOTSUPP) {
2163 ath10k_err(ar, "failed to get board id from otp: %d\n",
2165 goto err_free_firmware_files;
2168 ret = ath10k_core_fetch_board_file(ar);
2170 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
2171 goto err_free_firmware_files;
2174 ath10k_debug_print_board_info(ar);
2177 ret = ath10k_core_init_firmware_features(ar);
2179 ath10k_err(ar, "fatal problem with firmware features: %d\n",
2181 goto err_free_firmware_files;
2185 ret = ath10k_swap_code_seg_init(ar,
2186 &ar->normal_mode_fw.fw_file);
2188 ath10k_err(ar, "failed to init code swap segment: %d\n",
2190 goto err_free_firmware_files;
2194 mutex_lock(&ar->conf_mutex);
2196 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
2197 &ar->normal_mode_fw);
2199 ath10k_err(ar, "could not init core (%d)\n", ret);
2203 ath10k_debug_print_boot_info(ar);
2204 ath10k_core_stop(ar);
2206 mutex_unlock(&ar->conf_mutex);
2208 ath10k_hif_power_down(ar);
2212 mutex_unlock(&ar->conf_mutex);
2214 err_free_firmware_files:
2215 ath10k_core_free_firmware_files(ar);
2218 ath10k_hif_power_down(ar);
2223 static void ath10k_core_register_work(struct work_struct *work)
2225 struct ath10k *ar = container_of(work, struct ath10k, register_work);
2228 /* peer stats are enabled by default */
2229 set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2231 status = ath10k_core_probe_fw(ar);
2233 ath10k_err(ar, "could not probe fw (%d)\n", status);
2237 status = ath10k_mac_register(ar);
2239 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
2240 goto err_release_fw;
2243 status = ath10k_debug_register(ar);
2245 ath10k_err(ar, "unable to initialize debugfs\n");
2246 goto err_unregister_mac;
2249 status = ath10k_spectral_create(ar);
2251 ath10k_err(ar, "failed to initialize spectral\n");
2252 goto err_debug_destroy;
2255 status = ath10k_thermal_register(ar);
2257 ath10k_err(ar, "could not register thermal device: %d\n",
2259 goto err_spectral_destroy;
2262 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
2265 err_spectral_destroy:
2266 ath10k_spectral_destroy(ar);
2268 ath10k_debug_destroy(ar);
2270 ath10k_mac_unregister(ar);
2272 ath10k_core_free_firmware_files(ar);
2274 /* TODO: It's probably a good idea to release device from the driver
2275 * but calling device_release_driver() here will cause a deadlock.
2280 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
2282 ar->chip_id = chip_id;
2283 queue_work(ar->workqueue, &ar->register_work);
2287 EXPORT_SYMBOL(ath10k_core_register);
2289 void ath10k_core_unregister(struct ath10k *ar)
2291 cancel_work_sync(&ar->register_work);
2293 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
2296 ath10k_thermal_unregister(ar);
2297 /* Stop spectral before unregistering from mac80211 to remove the
2298 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
2299 * would be already be free'd recursively, leading to a double free.
2301 ath10k_spectral_destroy(ar);
2303 /* We must unregister from mac80211 before we stop HTC and HIF.
2304 * Otherwise we will fail to submit commands to FW and mac80211 will be
2305 * unhappy about callback failures. */
2306 ath10k_mac_unregister(ar);
2308 ath10k_testmode_destroy(ar);
2310 ath10k_core_free_firmware_files(ar);
2311 ath10k_core_free_board_files(ar);
2313 ath10k_debug_unregister(ar);
2315 EXPORT_SYMBOL(ath10k_core_unregister);
2317 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
2318 enum ath10k_bus bus,
2319 enum ath10k_hw_rev hw_rev,
2320 const struct ath10k_hif_ops *hif_ops)
2325 ar = ath10k_mac_create(priv_size);
2329 ar->ath_common.priv = ar;
2330 ar->ath_common.hw = ar->hw;
2332 ar->hw_rev = hw_rev;
2333 ar->hif.ops = hif_ops;
2336 /* By default, assume bmi is set, as most of the existing
2337 * chip sets are based on this, set to false explicitly
2338 * when current chip set does not support.
2343 case ATH10K_HW_QCA988X:
2344 case ATH10K_HW_QCA9887:
2345 ar->regs = &qca988x_regs;
2346 ar->hw_ce_regs = &qcax_ce_regs;
2347 ar->hw_values = &qca988x_values;
2349 case ATH10K_HW_QCA6174:
2350 case ATH10K_HW_QCA9377:
2351 ar->regs = &qca6174_regs;
2352 ar->hw_ce_regs = &qcax_ce_regs;
2353 ar->hw_values = &qca6174_values;
2355 case ATH10K_HW_QCA99X0:
2356 case ATH10K_HW_QCA9984:
2357 ar->regs = &qca99x0_regs;
2358 ar->hw_ce_regs = &qcax_ce_regs;
2359 ar->hw_values = &qca99x0_values;
2361 case ATH10K_HW_QCA9888:
2362 ar->regs = &qca99x0_regs;
2363 ar->hw_ce_regs = &qcax_ce_regs;
2364 ar->hw_values = &qca9888_values;
2366 case ATH10K_HW_QCA4019:
2367 ar->regs = &qca4019_regs;
2368 ar->hw_ce_regs = &qcax_ce_regs;
2369 ar->hw_values = &qca4019_values;
2371 case ATH10K_HW_WCN3990:
2372 ar->regs = &wcn3990_regs;
2373 ar->hw_ce_regs = &wcn3990_ce_regs;
2374 ar->hw_values = &wcn3990_values;
2375 /* WCN3990 chip set is non bmi based */
2377 ar->fw_flags = &wcn3990_fw_flags;
2378 ar->shadow_reg_value = &wcn3990_shadow_reg_value;
2379 ar->shadow_reg_address = &wcn3990_shadow_reg_address;
2380 ar->rri_on_ddr = true;
2383 ath10k_err(ar, "unsupported core hardware revision %d\n",
2389 init_completion(&ar->scan.started);
2390 init_completion(&ar->scan.completed);
2391 init_completion(&ar->scan.on_channel);
2392 init_completion(&ar->target_suspend);
2393 init_completion(&ar->wow.wakeup_completed);
2395 init_completion(&ar->install_key_done);
2396 init_completion(&ar->vdev_setup_done);
2397 init_completion(&ar->vdev_delete_done);
2398 init_completion(&ar->thermal.wmi_sync);
2399 init_completion(&ar->bss_survey_done);
2400 init_completion(&ar->peer_delete_done);
2402 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
2404 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
2408 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
2409 if (!ar->workqueue_aux)
2412 mutex_init(&ar->conf_mutex);
2413 spin_lock_init(&ar->data_lock);
2414 spin_lock_init(&ar->txqs_lock);
2415 spin_lock_init(&ar->datapath_rx_stat_lock);
2417 INIT_LIST_HEAD(&ar->txqs);
2418 INIT_LIST_HEAD(&ar->peers);
2419 init_waitqueue_head(&ar->peer_mapping_wq);
2420 init_waitqueue_head(&ar->htt.empty_tx_wq);
2421 init_waitqueue_head(&ar->wmi.tx_credits_wq);
2423 init_completion(&ar->offchan_tx_completed);
2424 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
2425 skb_queue_head_init(&ar->offchan_tx_queue);
2427 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
2428 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
2430 INIT_WORK(&ar->register_work, ath10k_core_register_work);
2431 INIT_WORK(&ar->restart_work, ath10k_core_restart);
2433 init_dummy_netdev(&ar->napi_dev);
2435 ret = ath10k_debug_create(ar);
2437 goto err_free_aux_wq;
2442 destroy_workqueue(ar->workqueue_aux);
2444 destroy_workqueue(ar->workqueue);
2447 ath10k_mac_destroy(ar);
2451 EXPORT_SYMBOL(ath10k_core_create);
2453 void ath10k_core_destroy(struct ath10k *ar)
2455 flush_workqueue(ar->workqueue);
2456 destroy_workqueue(ar->workqueue);
2458 flush_workqueue(ar->workqueue_aux);
2459 destroy_workqueue(ar->workqueue_aux);
2461 ath10k_debug_destroy(ar);
2462 ath10k_wmi_free_host_mem(ar);
2463 ath10k_mac_destroy(ar);
2465 EXPORT_SYMBOL(ath10k_core_destroy);
2467 MODULE_AUTHOR("Qualcomm Atheros");
2468 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11ac wireless LAN cards.");
2469 MODULE_LICENSE("Dual BSD/GPL");