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>
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,
310 static const char *const ath10k_core_fw_feature_str[] = {
311 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
312 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
313 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
314 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
315 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
316 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
317 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
318 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
319 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
320 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
321 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
322 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA] = "adaptive-cca",
323 [ATH10K_FW_FEATURE_MFP_SUPPORT] = "mfp",
324 [ATH10K_FW_FEATURE_PEER_FLOW_CONTROL] = "peer-flow-ctrl",
325 [ATH10K_FW_FEATURE_BTCOEX_PARAM] = "btcoex-param",
326 [ATH10K_FW_FEATURE_SKIP_NULL_FUNC_WAR] = "skip-null-func-war",
329 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
331 enum ath10k_fw_features feat)
333 /* make sure that ath10k_core_fw_feature_str[] gets updated */
334 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
335 ATH10K_FW_FEATURE_COUNT);
337 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
338 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
339 return scnprintf(buf, buf_len, "bit%d", feat);
342 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
345 void ath10k_core_get_fw_features_str(struct ath10k *ar,
349 unsigned int len = 0;
352 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
353 if (test_bit(i, ar->normal_mode_fw.fw_file.fw_features)) {
355 len += scnprintf(buf + len, buf_len - len, ",");
357 len += ath10k_core_get_fw_feature_str(buf + len,
364 static void ath10k_send_suspend_complete(struct ath10k *ar)
366 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
368 complete(&ar->target_suspend);
371 static int ath10k_init_configure_target(struct ath10k *ar)
376 /* tell target which HTC version it is used*/
377 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
378 HTC_PROTOCOL_VERSION);
380 ath10k_err(ar, "settings HTC version failed\n");
384 /* set the firmware mode to STA/IBSS/AP */
385 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
387 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
391 /* TODO following parameters need to be re-visited. */
393 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
395 /* FIXME: Why FW_MODE_AP ??.*/
396 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
397 /* mac_addr_method */
398 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
399 /* firmware_bridge */
400 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
402 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
404 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
406 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
410 /* We do all byte-swapping on the host */
411 ret = ath10k_bmi_write32(ar, hi_be, 0);
413 ath10k_err(ar, "setting host CPU BE mode failed\n");
417 /* FW descriptor/Data swap flags */
418 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
421 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
425 /* Some devices have a special sanity check that verifies the PCI
426 * Device ID is written to this host interest var. It is known to be
427 * required to boot QCA6164.
429 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
432 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
439 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
444 const struct firmware *fw;
448 return ERR_PTR(-ENOENT);
453 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
454 ret = reject_firmware(&fw, filename, ar->dev);
461 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
464 u32 board_data_size = ar->hw_params.fw.board_size;
465 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
466 u32 board_ext_data_addr;
469 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
471 ath10k_err(ar, "could not read board ext data addr (%d)\n",
476 ath10k_dbg(ar, ATH10K_DBG_BOOT,
477 "boot push board extended data addr 0x%x\n",
478 board_ext_data_addr);
480 if (board_ext_data_addr == 0)
483 if (data_len != (board_data_size + board_ext_data_size)) {
484 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
485 data_len, board_data_size, board_ext_data_size);
489 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
490 data + board_data_size,
491 board_ext_data_size);
493 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
497 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
498 (board_ext_data_size << 16) | 1);
500 ath10k_err(ar, "could not write board ext data bit (%d)\n",
508 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
511 u32 board_data_size = ar->hw_params.fw.board_size;
515 ret = ath10k_push_board_ext_data(ar, data, data_len);
517 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
521 ret = ath10k_bmi_read32(ar, hi_board_data, &address);
523 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
527 ret = ath10k_bmi_write_memory(ar, address, data,
528 min_t(u32, board_data_size,
531 ath10k_err(ar, "could not write board data (%d)\n", ret);
535 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
537 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
545 static int ath10k_download_cal_file(struct ath10k *ar,
546 const struct firmware *file)
554 return PTR_ERR(file);
556 ret = ath10k_download_board_data(ar, file->data, file->size);
558 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
562 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
567 static int ath10k_download_cal_dt(struct ath10k *ar, const char *dt_name)
569 struct device_node *node;
574 node = ar->dev->of_node;
576 /* Device Tree is optional, don't print any warnings if
577 * there's no node for ath10k.
581 if (!of_get_property(node, dt_name, &data_len)) {
582 /* The calibration data node is optional */
586 if (data_len != ar->hw_params.cal_data_len) {
587 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
593 data = kmalloc(data_len, GFP_KERNEL);
599 ret = of_property_read_u8_array(node, dt_name, data, data_len);
601 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
606 ret = ath10k_download_board_data(ar, data, data_len);
608 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
622 static int ath10k_download_cal_eeprom(struct ath10k *ar)
628 ret = ath10k_hif_fetch_cal_eeprom(ar, &data, &data_len);
630 if (ret != -EOPNOTSUPP)
631 ath10k_warn(ar, "failed to read calibration data from EEPROM: %d\n",
636 ret = ath10k_download_board_data(ar, data, data_len);
638 ath10k_warn(ar, "failed to download calibration data from EEPROM: %d\n",
651 static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
654 u8 board_id, chip_id;
655 int ret, bmi_board_id_param;
657 address = ar->hw_params.patch_load_addr;
659 if (!ar->normal_mode_fw.fw_file.otp_data ||
660 !ar->normal_mode_fw.fw_file.otp_len) {
662 "failed to retrieve board id because of invalid otp\n");
666 ath10k_dbg(ar, ATH10K_DBG_BOOT,
667 "boot upload otp to 0x%x len %zd for board id\n",
668 address, ar->normal_mode_fw.fw_file.otp_len);
670 ret = ath10k_bmi_fast_download(ar, address,
671 ar->normal_mode_fw.fw_file.otp_data,
672 ar->normal_mode_fw.fw_file.otp_len);
674 ath10k_err(ar, "could not write otp for board id check: %d\n",
679 if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
680 ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
681 bmi_board_id_param = BMI_PARAM_GET_FLASH_BOARD_ID;
683 bmi_board_id_param = BMI_PARAM_GET_EEPROM_BOARD_ID;
685 ret = ath10k_bmi_execute(ar, address, bmi_board_id_param, &result);
687 ath10k_err(ar, "could not execute otp for board id check: %d\n",
692 board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP);
693 chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP);
695 ath10k_dbg(ar, ATH10K_DBG_BOOT,
696 "boot get otp board id result 0x%08x board_id %d chip_id %d\n",
697 result, board_id, chip_id);
699 if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0 ||
701 ath10k_dbg(ar, ATH10K_DBG_BOOT,
702 "board id does not exist in otp, ignore it\n");
706 ar->id.bmi_ids_valid = true;
707 ar->id.bmi_board_id = board_id;
708 ar->id.bmi_chip_id = chip_id;
713 static int ath10k_download_and_run_otp(struct ath10k *ar)
715 u32 result, address = ar->hw_params.patch_load_addr;
716 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
719 ret = ath10k_download_board_data(ar,
720 ar->running_fw->board_data,
721 ar->running_fw->board_len);
723 ath10k_err(ar, "failed to download board data: %d\n", ret);
727 /* OTP is optional */
729 if (!ar->running_fw->fw_file.otp_data ||
730 !ar->running_fw->fw_file.otp_len) {
731 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %pK otp_len %zd)!\n",
732 ar->running_fw->fw_file.otp_data,
733 ar->running_fw->fw_file.otp_len);
737 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
738 address, ar->running_fw->fw_file.otp_len);
740 ret = ath10k_bmi_fast_download(ar, address,
741 ar->running_fw->fw_file.otp_data,
742 ar->running_fw->fw_file.otp_len);
744 ath10k_err(ar, "could not write otp (%d)\n", ret);
748 /* As of now pre-cal is valid for 10_4 variants */
749 if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
750 ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
751 bmi_otp_exe_param = BMI_PARAM_FLASH_SECTION_ALL;
753 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
755 ath10k_err(ar, "could not execute otp (%d)\n", ret);
759 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
761 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
762 ar->running_fw->fw_file.fw_features)) &&
764 ath10k_err(ar, "otp calibration failed: %d", result);
771 static int ath10k_download_fw(struct ath10k *ar)
773 u32 address, data_len;
777 address = ar->hw_params.patch_load_addr;
779 data = ar->running_fw->fw_file.firmware_data;
780 data_len = ar->running_fw->fw_file.firmware_len;
782 ret = ath10k_swap_code_seg_configure(ar, &ar->running_fw->fw_file);
784 ath10k_err(ar, "failed to configure fw code swap: %d\n",
789 ath10k_dbg(ar, ATH10K_DBG_BOOT,
790 "boot uploading firmware image %pK len %d\n",
793 ret = ath10k_bmi_fast_download(ar, address, data, data_len);
795 ath10k_err(ar, "failed to download firmware: %d\n",
803 static void ath10k_core_free_board_files(struct ath10k *ar)
805 if (!IS_ERR(ar->normal_mode_fw.board))
806 release_firmware(ar->normal_mode_fw.board);
808 ar->normal_mode_fw.board = NULL;
809 ar->normal_mode_fw.board_data = NULL;
810 ar->normal_mode_fw.board_len = 0;
813 static void ath10k_core_free_firmware_files(struct ath10k *ar)
815 if (!IS_ERR(ar->normal_mode_fw.fw_file.firmware))
816 release_firmware(ar->normal_mode_fw.fw_file.firmware);
818 if (!IS_ERR(ar->cal_file))
819 release_firmware(ar->cal_file);
821 if (!IS_ERR(ar->pre_cal_file))
822 release_firmware(ar->pre_cal_file);
824 ath10k_swap_code_seg_release(ar, &ar->normal_mode_fw.fw_file);
826 ar->normal_mode_fw.fw_file.otp_data = NULL;
827 ar->normal_mode_fw.fw_file.otp_len = 0;
829 ar->normal_mode_fw.fw_file.firmware = NULL;
830 ar->normal_mode_fw.fw_file.firmware_data = NULL;
831 ar->normal_mode_fw.fw_file.firmware_len = 0;
834 ar->pre_cal_file = NULL;
837 static int ath10k_fetch_cal_file(struct ath10k *ar)
841 /* pre-cal-<bus>-<id>.bin */
842 scnprintf(filename, sizeof(filename), "/*(DEBLOBBED)*/",
843 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
845 ar->pre_cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
846 if (!IS_ERR(ar->pre_cal_file))
850 scnprintf(filename, sizeof(filename), "/*(DEBLOBBED)*/",
851 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
853 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
854 if (IS_ERR(ar->cal_file))
855 /* calibration file is optional, don't print any warnings */
856 return PTR_ERR(ar->cal_file);
858 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
859 ATH10K_FW_DIR, filename);
864 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar)
866 if (!ar->hw_params.fw.board) {
867 ath10k_err(ar, "failed to find board file fw entry\n");
871 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
872 ar->hw_params.fw.dir,
873 ar->hw_params.fw.board);
874 if (IS_ERR(ar->normal_mode_fw.board))
875 return PTR_ERR(ar->normal_mode_fw.board);
877 ar->normal_mode_fw.board_data = ar->normal_mode_fw.board->data;
878 ar->normal_mode_fw.board_len = ar->normal_mode_fw.board->size;
883 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
884 const void *buf, size_t buf_len,
885 const char *boardname)
887 const struct ath10k_fw_ie *hdr;
888 bool name_match_found;
889 int ret, board_ie_id;
891 const void *board_ie_data;
893 name_match_found = false;
895 /* go through ATH10K_BD_IE_BOARD_ elements */
896 while (buf_len > sizeof(struct ath10k_fw_ie)) {
898 board_ie_id = le32_to_cpu(hdr->id);
899 board_ie_len = le32_to_cpu(hdr->len);
900 board_ie_data = hdr->data;
902 buf_len -= sizeof(*hdr);
905 if (buf_len < ALIGN(board_ie_len, 4)) {
906 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
907 buf_len, ALIGN(board_ie_len, 4));
912 switch (board_ie_id) {
913 case ATH10K_BD_IE_BOARD_NAME:
914 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
915 board_ie_data, board_ie_len);
917 if (board_ie_len != strlen(boardname))
920 ret = memcmp(board_ie_data, boardname, strlen(boardname));
924 name_match_found = true;
925 ath10k_dbg(ar, ATH10K_DBG_BOOT,
926 "boot found match for name '%s'",
929 case ATH10K_BD_IE_BOARD_DATA:
930 if (!name_match_found)
934 ath10k_dbg(ar, ATH10K_DBG_BOOT,
935 "boot found board data for '%s'",
938 ar->normal_mode_fw.board_data = board_ie_data;
939 ar->normal_mode_fw.board_len = board_ie_len;
944 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
949 /* jump over the padding */
950 board_ie_len = ALIGN(board_ie_len, 4);
952 buf_len -= board_ie_len;
963 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
964 const char *boardname,
965 const char *filename)
967 size_t len, magic_len, ie_len;
968 struct ath10k_fw_ie *hdr;
972 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
973 ar->hw_params.fw.dir,
975 if (IS_ERR(ar->normal_mode_fw.board))
976 return PTR_ERR(ar->normal_mode_fw.board);
978 data = ar->normal_mode_fw.board->data;
979 len = ar->normal_mode_fw.board->size;
981 /* magic has extra null byte padded */
982 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
983 if (len < magic_len) {
984 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
985 ar->hw_params.fw.dir, filename, len);
990 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
991 ath10k_err(ar, "found invalid board magic\n");
996 /* magic is padded to 4 bytes */
997 magic_len = ALIGN(magic_len, 4);
998 if (len < magic_len) {
999 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
1000 ar->hw_params.fw.dir, filename, len);
1008 while (len > sizeof(struct ath10k_fw_ie)) {
1009 hdr = (struct ath10k_fw_ie *)data;
1010 ie_id = le32_to_cpu(hdr->id);
1011 ie_len = le32_to_cpu(hdr->len);
1013 len -= sizeof(*hdr);
1016 if (len < ALIGN(ie_len, 4)) {
1017 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
1018 ie_id, ie_len, len);
1024 case ATH10K_BD_IE_BOARD:
1025 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
1028 /* no match found, continue */
1031 /* there was an error, bail out */
1034 /* board data found */
1038 /* jump over the padding */
1039 ie_len = ALIGN(ie_len, 4);
1046 if (!ar->normal_mode_fw.board_data || !ar->normal_mode_fw.board_len) {
1048 "failed to fetch board data for %s from %s/%s\n",
1049 boardname, ar->hw_params.fw.dir, filename);
1057 ath10k_core_free_board_files(ar);
1061 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
1064 if (ar->id.bmi_ids_valid) {
1065 scnprintf(name, name_len,
1066 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d",
1067 ath10k_bus_str(ar->hif.bus),
1069 ar->id.bmi_board_id);
1073 scnprintf(name, name_len,
1074 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x",
1075 ath10k_bus_str(ar->hif.bus),
1076 ar->id.vendor, ar->id.device,
1077 ar->id.subsystem_vendor, ar->id.subsystem_device);
1080 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
1085 static int ath10k_core_fetch_board_file(struct ath10k *ar)
1087 char boardname[100];
1090 ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname));
1092 ath10k_err(ar, "failed to create board name: %d", ret);
1097 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
1098 ATH10K_BOARD_API2_FILE);
1103 ret = ath10k_core_fetch_board_data_api_1(ar);
1105 ath10k_err(ar, "failed to fetch board data\n");
1110 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
1114 int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name,
1115 struct ath10k_fw_file *fw_file)
1117 size_t magic_len, len, ie_len;
1118 int ie_id, i, index, bit, ret;
1119 struct ath10k_fw_ie *hdr;
1121 __le32 *timestamp, *version;
1123 /* first fetch the firmware file (firmware-*.bin) */
1124 fw_file->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
1126 if (IS_ERR(fw_file->firmware)) {
1127 ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n",
1128 ar->hw_params.fw.dir, name,
1129 PTR_ERR(fw_file->firmware));
1130 return PTR_ERR(fw_file->firmware);
1133 data = fw_file->firmware->data;
1134 len = fw_file->firmware->size;
1136 /* magic also includes the null byte, check that as well */
1137 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
1139 if (len < magic_len) {
1140 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
1141 ar->hw_params.fw.dir, name, len);
1146 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
1147 ath10k_err(ar, "invalid firmware magic\n");
1152 /* jump over the padding */
1153 magic_len = ALIGN(magic_len, 4);
1159 while (len > sizeof(struct ath10k_fw_ie)) {
1160 hdr = (struct ath10k_fw_ie *)data;
1162 ie_id = le32_to_cpu(hdr->id);
1163 ie_len = le32_to_cpu(hdr->len);
1165 len -= sizeof(*hdr);
1166 data += sizeof(*hdr);
1169 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
1170 ie_id, len, ie_len);
1176 case ATH10K_FW_IE_FW_VERSION:
1177 if (ie_len > sizeof(fw_file->fw_version) - 1)
1180 memcpy(fw_file->fw_version, data, ie_len);
1181 fw_file->fw_version[ie_len] = '\0';
1183 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1184 "found fw version %s\n",
1185 fw_file->fw_version);
1187 case ATH10K_FW_IE_TIMESTAMP:
1188 if (ie_len != sizeof(u32))
1191 timestamp = (__le32 *)data;
1193 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
1194 le32_to_cpup(timestamp));
1196 case ATH10K_FW_IE_FEATURES:
1197 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1198 "found firmware features ie (%zd B)\n",
1201 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
1205 if (index == ie_len)
1208 if (data[index] & (1 << bit)) {
1209 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1210 "Enabling feature bit: %i\n",
1212 __set_bit(i, fw_file->fw_features);
1216 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
1217 fw_file->fw_features,
1218 sizeof(fw_file->fw_features));
1220 case ATH10K_FW_IE_FW_IMAGE:
1221 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1222 "found fw image ie (%zd B)\n",
1225 fw_file->firmware_data = data;
1226 fw_file->firmware_len = ie_len;
1229 case ATH10K_FW_IE_OTP_IMAGE:
1230 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1231 "found otp image ie (%zd B)\n",
1234 fw_file->otp_data = data;
1235 fw_file->otp_len = ie_len;
1238 case ATH10K_FW_IE_WMI_OP_VERSION:
1239 if (ie_len != sizeof(u32))
1242 version = (__le32 *)data;
1244 fw_file->wmi_op_version = le32_to_cpup(version);
1246 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1247 fw_file->wmi_op_version);
1249 case ATH10K_FW_IE_HTT_OP_VERSION:
1250 if (ie_len != sizeof(u32))
1253 version = (__le32 *)data;
1255 fw_file->htt_op_version = le32_to_cpup(version);
1257 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1258 fw_file->htt_op_version);
1260 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1261 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1262 "found fw code swap image ie (%zd B)\n",
1264 fw_file->codeswap_data = data;
1265 fw_file->codeswap_len = ie_len;
1268 ath10k_warn(ar, "Unknown FW IE: %u\n",
1269 le32_to_cpu(hdr->id));
1273 /* jump over the padding */
1274 ie_len = ALIGN(ie_len, 4);
1280 if (!fw_file->firmware_data ||
1281 !fw_file->firmware_len) {
1282 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1283 ar->hw_params.fw.dir, name);
1291 ath10k_core_free_firmware_files(ar);
1295 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1299 /* calibration file is optional, don't check for any errors */
1300 ath10k_fetch_cal_file(ar);
1303 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1305 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE,
1306 &ar->normal_mode_fw.fw_file);
1311 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1313 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE,
1314 &ar->normal_mode_fw.fw_file);
1319 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1321 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE,
1322 &ar->normal_mode_fw.fw_file);
1327 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api);
1329 ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE,
1330 &ar->normal_mode_fw.fw_file);
1335 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1340 static int ath10k_core_pre_cal_download(struct ath10k *ar)
1344 ret = ath10k_download_cal_file(ar, ar->pre_cal_file);
1346 ar->cal_mode = ATH10K_PRE_CAL_MODE_FILE;
1350 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1351 "boot did not find a pre calibration file, try DT next: %d\n",
1354 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-pre-calibration-data");
1356 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1357 "unable to load pre cal data from DT: %d\n", ret);
1360 ar->cal_mode = ATH10K_PRE_CAL_MODE_DT;
1363 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1364 ath10k_cal_mode_str(ar->cal_mode));
1369 static int ath10k_core_pre_cal_config(struct ath10k *ar)
1373 ret = ath10k_core_pre_cal_download(ar);
1375 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1376 "failed to load pre cal data: %d\n", ret);
1380 ret = ath10k_core_get_board_id_from_otp(ar);
1382 ath10k_err(ar, "failed to get board id: %d\n", ret);
1386 ret = ath10k_download_and_run_otp(ar);
1388 ath10k_err(ar, "failed to run otp: %d\n", ret);
1392 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1393 "pre cal configuration done successfully\n");
1398 static int ath10k_download_cal_data(struct ath10k *ar)
1402 ret = ath10k_core_pre_cal_config(ar);
1406 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1407 "pre cal download procedure failed, try cal file: %d\n",
1410 ret = ath10k_download_cal_file(ar, ar->cal_file);
1412 ar->cal_mode = ATH10K_CAL_MODE_FILE;
1416 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1417 "boot did not find a calibration file, try DT next: %d\n",
1420 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-calibration-data");
1422 ar->cal_mode = ATH10K_CAL_MODE_DT;
1426 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1427 "boot did not find DT entry, try target EEPROM next: %d\n",
1430 ret = ath10k_download_cal_eeprom(ar);
1432 ar->cal_mode = ATH10K_CAL_MODE_EEPROM;
1436 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1437 "boot did not find target EEPROM entry, try OTP next: %d\n",
1440 ret = ath10k_download_and_run_otp(ar);
1442 ath10k_err(ar, "failed to run otp: %d\n", ret);
1446 ar->cal_mode = ATH10K_CAL_MODE_OTP;
1449 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1450 ath10k_cal_mode_str(ar->cal_mode));
1454 static int ath10k_init_uart(struct ath10k *ar)
1459 * Explicitly setting UART prints to zero as target turns it on
1460 * based on scratch registers.
1462 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
1464 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
1471 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
1473 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1477 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
1479 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
1483 /* Set the UART baud rate to 19200. */
1484 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
1486 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
1490 ath10k_info(ar, "UART prints enabled\n");
1494 static int ath10k_init_hw_params(struct ath10k *ar)
1496 const struct ath10k_hw_params *uninitialized_var(hw_params);
1499 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
1500 hw_params = &ath10k_hw_params_list[i];
1502 if (hw_params->id == ar->target_version &&
1503 hw_params->dev_id == ar->dev_id)
1507 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
1508 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
1509 ar->target_version);
1513 ar->hw_params = *hw_params;
1515 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
1516 ar->hw_params.name, ar->target_version);
1521 static void ath10k_core_restart(struct work_struct *work)
1523 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
1525 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1527 /* Place a barrier to make sure the compiler doesn't reorder
1528 * CRASH_FLUSH and calling other functions.
1532 ieee80211_stop_queues(ar->hw);
1533 ath10k_drain_tx(ar);
1534 complete(&ar->scan.started);
1535 complete(&ar->scan.completed);
1536 complete(&ar->scan.on_channel);
1537 complete(&ar->offchan_tx_completed);
1538 complete(&ar->install_key_done);
1539 complete(&ar->vdev_setup_done);
1540 complete(&ar->thermal.wmi_sync);
1541 complete(&ar->bss_survey_done);
1542 wake_up(&ar->htt.empty_tx_wq);
1543 wake_up(&ar->wmi.tx_credits_wq);
1544 wake_up(&ar->peer_mapping_wq);
1546 mutex_lock(&ar->conf_mutex);
1548 switch (ar->state) {
1549 case ATH10K_STATE_ON:
1550 ar->state = ATH10K_STATE_RESTARTING;
1552 ath10k_scan_finish(ar);
1553 ieee80211_restart_hw(ar->hw);
1555 case ATH10K_STATE_OFF:
1556 /* this can happen if driver is being unloaded
1557 * or if the crash happens during FW probing */
1558 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
1560 case ATH10K_STATE_RESTARTING:
1561 /* hw restart might be requested from multiple places */
1563 case ATH10K_STATE_RESTARTED:
1564 ar->state = ATH10K_STATE_WEDGED;
1566 case ATH10K_STATE_WEDGED:
1567 ath10k_warn(ar, "device is wedged, will not restart\n");
1569 case ATH10K_STATE_UTF:
1570 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
1574 mutex_unlock(&ar->conf_mutex);
1577 static int ath10k_core_init_firmware_features(struct ath10k *ar)
1579 struct ath10k_fw_file *fw_file = &ar->normal_mode_fw.fw_file;
1581 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, fw_file->fw_features) &&
1582 !test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
1583 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
1587 if (fw_file->wmi_op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
1588 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
1589 ATH10K_FW_WMI_OP_VERSION_MAX, fw_file->wmi_op_version);
1593 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
1594 switch (ath10k_cryptmode_param) {
1595 case ATH10K_CRYPT_MODE_HW:
1596 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1597 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1599 case ATH10K_CRYPT_MODE_SW:
1600 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1601 fw_file->fw_features)) {
1602 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
1606 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1607 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
1610 ath10k_info(ar, "invalid cryptmode: %d\n",
1611 ath10k_cryptmode_param);
1615 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
1616 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
1619 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
1620 fw_file->fw_features)) {
1621 ath10k_err(ar, "rawmode = 1 requires support from firmware");
1624 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
1627 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1628 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
1632 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
1633 * and causes enormous performance issues (malformed frames,
1636 * Disabling A-MSDU makes RAW mode stable with heavy traffic
1637 * albeit a bit slower compared to regular operation.
1639 ar->htt.max_num_amsdu = 1;
1642 /* Backwards compatibility for firmwares without
1643 * ATH10K_FW_IE_WMI_OP_VERSION.
1645 if (fw_file->wmi_op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
1646 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
1647 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
1648 fw_file->fw_features))
1649 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
1651 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
1653 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
1657 switch (fw_file->wmi_op_version) {
1658 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1659 ar->max_num_peers = TARGET_NUM_PEERS;
1660 ar->max_num_stations = TARGET_NUM_STATIONS;
1661 ar->max_num_vdevs = TARGET_NUM_VDEVS;
1662 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
1663 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1665 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1667 case ATH10K_FW_WMI_OP_VERSION_10_1:
1668 case ATH10K_FW_WMI_OP_VERSION_10_2:
1669 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1670 if (ath10k_peer_stats_enabled(ar)) {
1671 ar->max_num_peers = TARGET_10X_TX_STATS_NUM_PEERS;
1672 ar->max_num_stations = TARGET_10X_TX_STATS_NUM_STATIONS;
1674 ar->max_num_peers = TARGET_10X_NUM_PEERS;
1675 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
1677 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
1678 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
1679 ar->fw_stats_req_mask = WMI_STAT_PEER;
1680 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1682 case ATH10K_FW_WMI_OP_VERSION_TLV:
1683 ar->max_num_peers = TARGET_TLV_NUM_PEERS;
1684 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
1685 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
1686 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
1687 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
1688 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
1689 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
1691 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
1693 case ATH10K_FW_WMI_OP_VERSION_10_4:
1694 ar->max_num_peers = TARGET_10_4_NUM_PEERS;
1695 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
1696 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
1697 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
1698 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
1699 ar->fw_stats_req_mask = WMI_10_4_STAT_PEER |
1700 WMI_10_4_STAT_PEER_EXTD;
1701 ar->max_spatial_stream = ar->hw_params.max_spatial_stream;
1703 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
1704 fw_file->fw_features))
1705 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC_PFC;
1707 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
1709 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1710 case ATH10K_FW_WMI_OP_VERSION_MAX:
1715 /* Backwards compatibility for firmwares without
1716 * ATH10K_FW_IE_HTT_OP_VERSION.
1718 if (fw_file->htt_op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
1719 switch (fw_file->wmi_op_version) {
1720 case ATH10K_FW_WMI_OP_VERSION_MAIN:
1721 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
1723 case ATH10K_FW_WMI_OP_VERSION_10_1:
1724 case ATH10K_FW_WMI_OP_VERSION_10_2:
1725 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
1726 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
1728 case ATH10K_FW_WMI_OP_VERSION_TLV:
1729 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
1731 case ATH10K_FW_WMI_OP_VERSION_10_4:
1732 case ATH10K_FW_WMI_OP_VERSION_UNSET:
1733 case ATH10K_FW_WMI_OP_VERSION_MAX:
1734 ath10k_err(ar, "htt op version not found from fw meta data");
1742 static int ath10k_core_reset_rx_filter(struct ath10k *ar)
1748 const u8 *vdev_addr;
1751 vdev_type = WMI_VDEV_TYPE_STA;
1752 vdev_subtype = ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
1753 vdev_addr = ar->mac_addr;
1755 ret = ath10k_wmi_vdev_create(ar, vdev_id, vdev_type, vdev_subtype,
1758 ath10k_err(ar, "failed to create dummy vdev: %d\n", ret);
1762 ret = ath10k_wmi_vdev_delete(ar, vdev_id);
1764 ath10k_err(ar, "failed to delete dummy vdev: %d\n", ret);
1768 /* WMI and HTT may use separate HIF pipes and are not guaranteed to be
1769 * serialized properly implicitly.
1771 * Moreover (most) WMI commands have no explicit acknowledges. It is
1772 * possible to infer it implicitly by poking firmware with echo
1773 * command - getting a reply means all preceding comments have been
1774 * (mostly) processed.
1776 * In case of vdev create/delete this is sufficient.
1778 * Without this it's possible to end up with a race when HTT Rx ring is
1779 * started before vdev create/delete hack is complete allowing a short
1780 * window of opportunity to receive (and Tx ACK) a bunch of frames.
1782 ret = ath10k_wmi_barrier(ar);
1784 ath10k_err(ar, "failed to ping firmware: %d\n", ret);
1791 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
1792 const struct ath10k_fw_components *fw)
1797 lockdep_assert_held(&ar->conf_mutex);
1799 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1801 ar->running_fw = fw;
1803 ath10k_bmi_start(ar);
1805 if (ath10k_init_configure_target(ar)) {
1810 status = ath10k_download_cal_data(ar);
1814 /* Some of of qca988x solutions are having global reset issue
1815 * during target initialization. Bypassing PLL setting before
1816 * downloading firmware and letting the SoC run on REF_CLK is
1817 * fixing the problem. Corresponding firmware change is also needed
1818 * to set the clock source once the target is initialized.
1820 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
1821 ar->running_fw->fw_file.fw_features)) {
1822 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
1824 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
1830 status = ath10k_download_fw(ar);
1834 status = ath10k_init_uart(ar);
1838 ar->htc.htc_ops.target_send_suspend_complete =
1839 ath10k_send_suspend_complete;
1841 status = ath10k_htc_init(ar);
1843 ath10k_err(ar, "could not init HTC (%d)\n", status);
1847 status = ath10k_bmi_done(ar);
1851 status = ath10k_wmi_attach(ar);
1853 ath10k_err(ar, "WMI attach failed: %d\n", status);
1857 status = ath10k_htt_init(ar);
1859 ath10k_err(ar, "failed to init htt: %d\n", status);
1860 goto err_wmi_detach;
1863 status = ath10k_htt_tx_alloc(&ar->htt);
1865 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
1866 goto err_wmi_detach;
1869 /* If firmware indicates Full Rx Reorder support it must be used in a
1870 * slightly different manner. Let HTT code know.
1872 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
1875 status = ath10k_htt_rx_alloc(&ar->htt);
1877 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
1878 goto err_htt_tx_detach;
1881 status = ath10k_hif_start(ar);
1883 ath10k_err(ar, "could not start HIF: %d\n", status);
1884 goto err_htt_rx_detach;
1887 status = ath10k_htc_wait_target(&ar->htc);
1889 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
1893 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1894 status = ath10k_htt_connect(&ar->htt);
1896 ath10k_err(ar, "failed to connect htt (%d)\n", status);
1901 status = ath10k_wmi_connect(ar);
1903 ath10k_err(ar, "could not connect wmi: %d\n", status);
1907 status = ath10k_htc_start(&ar->htc);
1909 ath10k_err(ar, "failed to start htc: %d\n", status);
1913 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1914 status = ath10k_wmi_wait_for_service_ready(ar);
1916 ath10k_warn(ar, "wmi service ready event not received");
1921 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
1922 ar->hw->wiphy->fw_version);
1924 if (test_bit(WMI_SERVICE_EXT_RES_CFG_SUPPORT, ar->wmi.svc_map) &&
1925 mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1927 if (ath10k_peer_stats_enabled(ar))
1928 val = WMI_10_4_PEER_STATS;
1930 if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map))
1931 val |= WMI_10_4_BSS_CHANNEL_INFO_64;
1933 /* 10.4 firmware supports BT-Coex without reloading firmware
1934 * via pdev param. To support Bluetooth coexistence pdev param,
1935 * WMI_COEX_GPIO_SUPPORT of extended resource config should be
1938 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
1939 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
1940 ar->running_fw->fw_file.fw_features))
1941 val |= WMI_10_4_COEX_GPIO_SUPPORT;
1943 status = ath10k_mac_ext_resource_config(ar, val);
1946 "failed to send ext resource cfg command : %d\n",
1952 status = ath10k_wmi_cmd_init(ar);
1954 ath10k_err(ar, "could not send WMI init command (%d)\n",
1959 status = ath10k_wmi_wait_for_unified_ready(ar);
1961 ath10k_err(ar, "wmi unified ready event not received\n");
1965 /* Some firmware revisions do not properly set up hardware rx filter
1968 * A known example from QCA9880 and 10.2.4 is that MAC_PCU_ADDR1_MASK
1969 * is filled with 0s instead of 1s allowing HW to respond with ACKs to
1970 * any frames that matches MAC_PCU_RX_FILTER which is also
1971 * misconfigured to accept anything.
1973 * The ADDR1 is programmed using internal firmware structure field and
1974 * can't be (easily/sanely) reached from the driver explicitly. It is
1975 * possible to implicitly make it correct by creating a dummy vdev and
1978 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
1979 status = ath10k_core_reset_rx_filter(ar);
1982 "failed to reset rx filter: %d\n", status);
1987 status = ath10k_htt_rx_ring_refill(ar);
1989 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
1993 if (ar->max_num_vdevs >= 64)
1994 ar->free_vdev_map = 0xFFFFFFFFFFFFFFFFLL;
1996 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
1998 INIT_LIST_HEAD(&ar->arvifs);
2000 /* we don't care about HTT in UTF mode */
2001 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2002 status = ath10k_htt_setup(&ar->htt);
2004 ath10k_err(ar, "failed to setup htt: %d\n", status);
2009 status = ath10k_debug_start(ar);
2016 ath10k_hif_stop(ar);
2018 ath10k_htt_rx_free(&ar->htt);
2020 ath10k_htt_tx_free(&ar->htt);
2022 ath10k_wmi_detach(ar);
2026 EXPORT_SYMBOL(ath10k_core_start);
2028 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
2031 unsigned long time_left;
2033 reinit_completion(&ar->target_suspend);
2035 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
2037 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
2041 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
2044 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
2051 void ath10k_core_stop(struct ath10k *ar)
2053 lockdep_assert_held(&ar->conf_mutex);
2054 ath10k_debug_stop(ar);
2056 /* try to suspend target */
2057 if (ar->state != ATH10K_STATE_RESTARTING &&
2058 ar->state != ATH10K_STATE_UTF)
2059 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
2061 ath10k_hif_stop(ar);
2062 ath10k_htt_tx_free(&ar->htt);
2063 ath10k_htt_rx_free(&ar->htt);
2064 ath10k_wmi_detach(ar);
2066 EXPORT_SYMBOL(ath10k_core_stop);
2068 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
2069 * order to know what hw capabilities should be advertised to mac80211 it is
2070 * necessary to load the firmware (and tear it down immediately since start
2071 * hook will try to init it again) before registering */
2072 static int ath10k_core_probe_fw(struct ath10k *ar)
2074 struct bmi_target_info target_info;
2077 ret = ath10k_hif_power_up(ar);
2079 ath10k_err(ar, "could not start pci hif (%d)\n", ret);
2083 memset(&target_info, 0, sizeof(target_info));
2084 ret = ath10k_bmi_get_target_info(ar, &target_info);
2086 ath10k_err(ar, "could not get target info (%d)\n", ret);
2087 goto err_power_down;
2090 ar->target_version = target_info.version;
2091 ar->hw->wiphy->hw_version = target_info.version;
2093 ret = ath10k_init_hw_params(ar);
2095 ath10k_err(ar, "could not get hw params (%d)\n", ret);
2096 goto err_power_down;
2099 ret = ath10k_core_fetch_firmware_files(ar);
2101 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
2102 goto err_power_down;
2105 BUILD_BUG_ON(sizeof(ar->hw->wiphy->fw_version) !=
2106 sizeof(ar->normal_mode_fw.fw_file.fw_version));
2107 memcpy(ar->hw->wiphy->fw_version, ar->normal_mode_fw.fw_file.fw_version,
2108 sizeof(ar->hw->wiphy->fw_version));
2110 ath10k_debug_print_hwfw_info(ar);
2112 ret = ath10k_core_pre_cal_download(ar);
2114 /* pre calibration data download is not necessary
2115 * for all the chipsets. Ignore failures and continue.
2117 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2118 "could not load pre cal data: %d\n", ret);
2121 ret = ath10k_core_get_board_id_from_otp(ar);
2122 if (ret && ret != -EOPNOTSUPP) {
2123 ath10k_err(ar, "failed to get board id from otp: %d\n",
2125 goto err_free_firmware_files;
2128 ret = ath10k_core_fetch_board_file(ar);
2130 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
2131 goto err_free_firmware_files;
2134 ath10k_debug_print_board_info(ar);
2136 ret = ath10k_core_init_firmware_features(ar);
2138 ath10k_err(ar, "fatal problem with firmware features: %d\n",
2140 goto err_free_firmware_files;
2143 ret = ath10k_swap_code_seg_init(ar, &ar->normal_mode_fw.fw_file);
2145 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
2147 goto err_free_firmware_files;
2150 mutex_lock(&ar->conf_mutex);
2152 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
2153 &ar->normal_mode_fw);
2155 ath10k_err(ar, "could not init core (%d)\n", ret);
2159 ath10k_debug_print_boot_info(ar);
2160 ath10k_core_stop(ar);
2162 mutex_unlock(&ar->conf_mutex);
2164 ath10k_hif_power_down(ar);
2168 mutex_unlock(&ar->conf_mutex);
2170 err_free_firmware_files:
2171 ath10k_core_free_firmware_files(ar);
2174 ath10k_hif_power_down(ar);
2179 static void ath10k_core_register_work(struct work_struct *work)
2181 struct ath10k *ar = container_of(work, struct ath10k, register_work);
2184 /* peer stats are enabled by default */
2185 set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2187 status = ath10k_core_probe_fw(ar);
2189 ath10k_err(ar, "could not probe fw (%d)\n", status);
2193 status = ath10k_mac_register(ar);
2195 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
2196 goto err_release_fw;
2199 status = ath10k_debug_register(ar);
2201 ath10k_err(ar, "unable to initialize debugfs\n");
2202 goto err_unregister_mac;
2205 status = ath10k_spectral_create(ar);
2207 ath10k_err(ar, "failed to initialize spectral\n");
2208 goto err_debug_destroy;
2211 status = ath10k_thermal_register(ar);
2213 ath10k_err(ar, "could not register thermal device: %d\n",
2215 goto err_spectral_destroy;
2218 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
2221 err_spectral_destroy:
2222 ath10k_spectral_destroy(ar);
2224 ath10k_debug_destroy(ar);
2226 ath10k_mac_unregister(ar);
2228 ath10k_core_free_firmware_files(ar);
2230 /* TODO: It's probably a good idea to release device from the driver
2231 * but calling device_release_driver() here will cause a deadlock.
2236 int ath10k_core_register(struct ath10k *ar, u32 chip_id)
2238 ar->chip_id = chip_id;
2239 queue_work(ar->workqueue, &ar->register_work);
2243 EXPORT_SYMBOL(ath10k_core_register);
2245 void ath10k_core_unregister(struct ath10k *ar)
2247 cancel_work_sync(&ar->register_work);
2249 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
2252 ath10k_thermal_unregister(ar);
2253 /* Stop spectral before unregistering from mac80211 to remove the
2254 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
2255 * would be already be free'd recursively, leading to a double free.
2257 ath10k_spectral_destroy(ar);
2259 /* We must unregister from mac80211 before we stop HTC and HIF.
2260 * Otherwise we will fail to submit commands to FW and mac80211 will be
2261 * unhappy about callback failures. */
2262 ath10k_mac_unregister(ar);
2264 ath10k_testmode_destroy(ar);
2266 ath10k_core_free_firmware_files(ar);
2267 ath10k_core_free_board_files(ar);
2269 ath10k_debug_unregister(ar);
2271 EXPORT_SYMBOL(ath10k_core_unregister);
2273 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
2274 enum ath10k_bus bus,
2275 enum ath10k_hw_rev hw_rev,
2276 const struct ath10k_hif_ops *hif_ops)
2281 ar = ath10k_mac_create(priv_size);
2285 ar->ath_common.priv = ar;
2286 ar->ath_common.hw = ar->hw;
2288 ar->hw_rev = hw_rev;
2289 ar->hif.ops = hif_ops;
2293 case ATH10K_HW_QCA988X:
2294 case ATH10K_HW_QCA9887:
2295 ar->regs = &qca988x_regs;
2296 ar->hw_values = &qca988x_values;
2298 case ATH10K_HW_QCA6174:
2299 case ATH10K_HW_QCA9377:
2300 ar->regs = &qca6174_regs;
2301 ar->hw_values = &qca6174_values;
2303 case ATH10K_HW_QCA99X0:
2304 case ATH10K_HW_QCA9984:
2305 ar->regs = &qca99x0_regs;
2306 ar->hw_values = &qca99x0_values;
2308 case ATH10K_HW_QCA9888:
2309 ar->regs = &qca99x0_regs;
2310 ar->hw_values = &qca9888_values;
2312 case ATH10K_HW_QCA4019:
2313 ar->regs = &qca4019_regs;
2314 ar->hw_values = &qca4019_values;
2317 ath10k_err(ar, "unsupported core hardware revision %d\n",
2323 init_completion(&ar->scan.started);
2324 init_completion(&ar->scan.completed);
2325 init_completion(&ar->scan.on_channel);
2326 init_completion(&ar->target_suspend);
2327 init_completion(&ar->wow.wakeup_completed);
2329 init_completion(&ar->install_key_done);
2330 init_completion(&ar->vdev_setup_done);
2331 init_completion(&ar->thermal.wmi_sync);
2332 init_completion(&ar->bss_survey_done);
2334 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
2336 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
2340 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
2341 if (!ar->workqueue_aux)
2344 mutex_init(&ar->conf_mutex);
2345 spin_lock_init(&ar->data_lock);
2346 spin_lock_init(&ar->txqs_lock);
2348 INIT_LIST_HEAD(&ar->txqs);
2349 INIT_LIST_HEAD(&ar->peers);
2350 init_waitqueue_head(&ar->peer_mapping_wq);
2351 init_waitqueue_head(&ar->htt.empty_tx_wq);
2352 init_waitqueue_head(&ar->wmi.tx_credits_wq);
2354 init_completion(&ar->offchan_tx_completed);
2355 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
2356 skb_queue_head_init(&ar->offchan_tx_queue);
2358 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
2359 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
2361 INIT_WORK(&ar->register_work, ath10k_core_register_work);
2362 INIT_WORK(&ar->restart_work, ath10k_core_restart);
2364 init_dummy_netdev(&ar->napi_dev);
2366 ret = ath10k_debug_create(ar);
2368 goto err_free_aux_wq;
2373 destroy_workqueue(ar->workqueue_aux);
2375 destroy_workqueue(ar->workqueue);
2378 ath10k_mac_destroy(ar);
2382 EXPORT_SYMBOL(ath10k_core_create);
2384 void ath10k_core_destroy(struct ath10k *ar)
2386 flush_workqueue(ar->workqueue);
2387 destroy_workqueue(ar->workqueue);
2389 flush_workqueue(ar->workqueue_aux);
2390 destroy_workqueue(ar->workqueue_aux);
2392 ath10k_debug_destroy(ar);
2393 ath10k_wmi_free_host_mem(ar);
2394 ath10k_mac_destroy(ar);
2396 EXPORT_SYMBOL(ath10k_core_destroy);
2398 MODULE_AUTHOR("Qualcomm Atheros");
2399 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11ac wireless LAN cards.");
2400 MODULE_LICENSE("Dual BSD/GPL");