2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <linux/module.h>
20 #include <linux/firmware.h>
22 #include <linux/property.h>
23 #include <linux/dmi.h>
24 #include <linux/ctype.h>
25 #include <asm/byteorder.h>
39 unsigned int ath10k_debug_mask;
40 static unsigned int ath10k_cryptmode_param;
41 static bool uart_print;
45 unsigned long ath10k_coredump_mask = BIT(ATH10K_FW_CRASH_DUMP_REGISTERS) |
46 BIT(ATH10K_FW_CRASH_DUMP_CE_DATA);
48 /* FIXME: most of these should be readonly */
49 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
50 module_param_named(cryptmode, ath10k_cryptmode_param, uint, 0644);
51 module_param(uart_print, bool, 0644);
52 module_param(skip_otp, bool, 0644);
53 module_param(rawmode, bool, 0644);
54 module_param_named(coredump_mask, ath10k_coredump_mask, ulong, 0444);
56 MODULE_PARM_DESC(debug_mask, "Debugging mask");
57 MODULE_PARM_DESC(uart_print, "Uart target debugging");
58 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
59 MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
60 MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath");
61 MODULE_PARM_DESC(coredump_mask, "Bitfield of what to include in firmware crash file");
63 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
65 .id = QCA988X_HW_2_0_VERSION,
66 .dev_id = QCA988X_2_0_DEVICE_ID,
67 .bus = ATH10K_BUS_PCI,
68 .name = "qca988x hw2.0",
69 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
71 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
73 .channel_counters_freq_hz = 88000,
74 .max_probe_resp_desc_thres = 0,
77 .dir = QCA988X_HW_2_0_FW_DIR,
78 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
79 .board_size = QCA988X_BOARD_DATA_SZ,
80 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
82 .hw_ops = &qca988x_ops,
83 .decap_align_bytes = 4,
84 .spectral_bin_discard = 0,
85 .spectral_bin_offset = 0,
86 .vht160_mcs_rx_highest = 0,
87 .vht160_mcs_tx_highest = 0,
89 .ast_skid_limit = 0x10,
90 .num_wds_entries = 0x20,
91 .target_64bit = false,
92 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
93 .shadow_reg_support = false,
95 .hw_filter_reset_required = true,
96 .fw_diag_ce_download = false,
99 .id = QCA988X_HW_2_0_VERSION,
100 .dev_id = QCA988X_2_0_DEVICE_ID_UBNT,
101 .name = "qca988x hw2.0 ubiquiti",
102 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
104 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
106 .channel_counters_freq_hz = 88000,
107 .max_probe_resp_desc_thres = 0,
108 .cal_data_len = 2116,
110 .dir = QCA988X_HW_2_0_FW_DIR,
111 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
112 .board_size = QCA988X_BOARD_DATA_SZ,
113 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
115 .hw_ops = &qca988x_ops,
116 .decap_align_bytes = 4,
117 .spectral_bin_discard = 0,
118 .spectral_bin_offset = 0,
119 .vht160_mcs_rx_highest = 0,
120 .vht160_mcs_tx_highest = 0,
121 .n_cipher_suites = 8,
122 .ast_skid_limit = 0x10,
123 .num_wds_entries = 0x20,
124 .target_64bit = false,
125 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
127 .shadow_reg_support = false,
129 .hw_filter_reset_required = true,
130 .fw_diag_ce_download = false,
133 .id = QCA9887_HW_1_0_VERSION,
134 .dev_id = QCA9887_1_0_DEVICE_ID,
135 .bus = ATH10K_BUS_PCI,
136 .name = "qca9887 hw1.0",
137 .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
139 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
141 .channel_counters_freq_hz = 88000,
142 .max_probe_resp_desc_thres = 0,
143 .cal_data_len = 2116,
145 .dir = QCA9887_HW_1_0_FW_DIR,
146 .board = QCA9887_HW_1_0_BOARD_DATA_FILE,
147 .board_size = QCA9887_BOARD_DATA_SZ,
148 .board_ext_size = QCA9887_BOARD_EXT_DATA_SZ,
150 .hw_ops = &qca988x_ops,
151 .decap_align_bytes = 4,
152 .spectral_bin_discard = 0,
153 .spectral_bin_offset = 0,
154 .vht160_mcs_rx_highest = 0,
155 .vht160_mcs_tx_highest = 0,
156 .n_cipher_suites = 8,
157 .ast_skid_limit = 0x10,
158 .num_wds_entries = 0x20,
159 .target_64bit = false,
160 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
162 .shadow_reg_support = false,
164 .hw_filter_reset_required = true,
165 .fw_diag_ce_download = false,
168 .id = QCA6174_HW_2_1_VERSION,
169 .dev_id = QCA6164_2_1_DEVICE_ID,
170 .bus = ATH10K_BUS_PCI,
171 .name = "qca6164 hw2.1",
172 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
175 .channel_counters_freq_hz = 88000,
176 .max_probe_resp_desc_thres = 0,
177 .cal_data_len = 8124,
179 .dir = QCA6174_HW_2_1_FW_DIR,
180 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
181 .board_size = QCA6174_BOARD_DATA_SZ,
182 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
184 .hw_ops = &qca988x_ops,
185 .decap_align_bytes = 4,
186 .spectral_bin_discard = 0,
187 .spectral_bin_offset = 0,
188 .vht160_mcs_rx_highest = 0,
189 .vht160_mcs_tx_highest = 0,
190 .n_cipher_suites = 8,
191 .ast_skid_limit = 0x10,
192 .num_wds_entries = 0x20,
193 .target_64bit = false,
194 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
196 .shadow_reg_support = false,
198 .hw_filter_reset_required = true,
199 .fw_diag_ce_download = false,
202 .id = QCA6174_HW_2_1_VERSION,
203 .dev_id = QCA6174_2_1_DEVICE_ID,
204 .bus = ATH10K_BUS_PCI,
205 .name = "qca6174 hw2.1",
206 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
209 .channel_counters_freq_hz = 88000,
210 .max_probe_resp_desc_thres = 0,
211 .cal_data_len = 8124,
213 .dir = QCA6174_HW_2_1_FW_DIR,
214 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
215 .board_size = QCA6174_BOARD_DATA_SZ,
216 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
218 .hw_ops = &qca988x_ops,
219 .decap_align_bytes = 4,
220 .spectral_bin_discard = 0,
221 .spectral_bin_offset = 0,
222 .vht160_mcs_rx_highest = 0,
223 .vht160_mcs_tx_highest = 0,
224 .n_cipher_suites = 8,
225 .ast_skid_limit = 0x10,
226 .num_wds_entries = 0x20,
227 .target_64bit = false,
228 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
230 .shadow_reg_support = false,
232 .hw_filter_reset_required = true,
233 .fw_diag_ce_download = false,
236 .id = QCA6174_HW_3_0_VERSION,
237 .dev_id = QCA6174_2_1_DEVICE_ID,
238 .bus = ATH10K_BUS_PCI,
239 .name = "qca6174 hw3.0",
240 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
243 .channel_counters_freq_hz = 88000,
244 .max_probe_resp_desc_thres = 0,
245 .cal_data_len = 8124,
247 .dir = QCA6174_HW_3_0_FW_DIR,
248 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
249 .board_size = QCA6174_BOARD_DATA_SZ,
250 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
252 .hw_ops = &qca988x_ops,
253 .decap_align_bytes = 4,
254 .spectral_bin_discard = 0,
255 .spectral_bin_offset = 0,
256 .vht160_mcs_rx_highest = 0,
257 .vht160_mcs_tx_highest = 0,
258 .n_cipher_suites = 8,
259 .ast_skid_limit = 0x10,
260 .num_wds_entries = 0x20,
261 .target_64bit = false,
262 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
264 .shadow_reg_support = false,
266 .hw_filter_reset_required = true,
267 .fw_diag_ce_download = false,
270 .id = QCA6174_HW_3_2_VERSION,
271 .dev_id = QCA6174_2_1_DEVICE_ID,
272 .bus = ATH10K_BUS_PCI,
273 .name = "qca6174 hw3.2",
274 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
277 .channel_counters_freq_hz = 88000,
278 .max_probe_resp_desc_thres = 0,
279 .cal_data_len = 8124,
281 /* uses same binaries as hw3.0 */
282 .dir = QCA6174_HW_3_0_FW_DIR,
283 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
284 .board_size = QCA6174_BOARD_DATA_SZ,
285 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
287 .hw_ops = &qca6174_ops,
288 .hw_clk = qca6174_clk,
289 .target_cpu_freq = 176000000,
290 .decap_align_bytes = 4,
291 .spectral_bin_discard = 0,
292 .spectral_bin_offset = 0,
293 .vht160_mcs_rx_highest = 0,
294 .vht160_mcs_tx_highest = 0,
295 .n_cipher_suites = 8,
296 .ast_skid_limit = 0x10,
297 .num_wds_entries = 0x20,
298 .target_64bit = false,
299 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
301 .shadow_reg_support = false,
303 .hw_filter_reset_required = true,
304 .fw_diag_ce_download = true,
307 .id = QCA99X0_HW_2_0_DEV_VERSION,
308 .dev_id = QCA99X0_2_0_DEVICE_ID,
309 .bus = ATH10K_BUS_PCI,
310 .name = "qca99x0 hw2.0",
311 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
313 .otp_exe_param = 0x00000700,
314 .continuous_frag_desc = true,
315 .cck_rate_map_rev2 = true,
316 .channel_counters_freq_hz = 150000,
317 .max_probe_resp_desc_thres = 24,
318 .tx_chain_mask = 0xf,
319 .rx_chain_mask = 0xf,
320 .max_spatial_stream = 4,
321 .cal_data_len = 12064,
323 .dir = QCA99X0_HW_2_0_FW_DIR,
324 .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
325 .board_size = QCA99X0_BOARD_DATA_SZ,
326 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
328 .sw_decrypt_mcast_mgmt = true,
329 .hw_ops = &qca99x0_ops,
330 .decap_align_bytes = 1,
331 .spectral_bin_discard = 4,
332 .spectral_bin_offset = 0,
333 .vht160_mcs_rx_highest = 0,
334 .vht160_mcs_tx_highest = 0,
335 .n_cipher_suites = 11,
336 .ast_skid_limit = 0x10,
337 .num_wds_entries = 0x20,
338 .target_64bit = false,
339 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
341 .shadow_reg_support = false,
343 .hw_filter_reset_required = true,
344 .fw_diag_ce_download = false,
347 .id = QCA9984_HW_1_0_DEV_VERSION,
348 .dev_id = QCA9984_1_0_DEVICE_ID,
349 .bus = ATH10K_BUS_PCI,
350 .name = "qca9984/qca9994 hw1.0",
351 .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
353 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
354 .otp_exe_param = 0x00000700,
355 .continuous_frag_desc = true,
356 .cck_rate_map_rev2 = true,
357 .channel_counters_freq_hz = 150000,
358 .max_probe_resp_desc_thres = 24,
359 .tx_chain_mask = 0xf,
360 .rx_chain_mask = 0xf,
361 .max_spatial_stream = 4,
362 .cal_data_len = 12064,
364 .dir = QCA9984_HW_1_0_FW_DIR,
365 .board = QCA9984_HW_1_0_BOARD_DATA_FILE,
366 .eboard = QCA9984_HW_1_0_EBOARD_DATA_FILE,
367 .board_size = QCA99X0_BOARD_DATA_SZ,
368 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
369 .ext_board_size = QCA99X0_EXT_BOARD_DATA_SZ,
371 .sw_decrypt_mcast_mgmt = true,
372 .hw_ops = &qca99x0_ops,
373 .decap_align_bytes = 1,
374 .spectral_bin_discard = 12,
375 .spectral_bin_offset = 8,
377 /* Can do only 2x2 VHT160 or 80+80. 1560Mbps is 4x4 80Mhz
378 * or 2x2 160Mhz, long-guard-interval.
380 .vht160_mcs_rx_highest = 1560,
381 .vht160_mcs_tx_highest = 1560,
382 .n_cipher_suites = 11,
383 .ast_skid_limit = 0x10,
384 .num_wds_entries = 0x20,
385 .target_64bit = false,
386 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
388 .shadow_reg_support = false,
390 .hw_filter_reset_required = true,
391 .fw_diag_ce_download = false,
394 .id = QCA9888_HW_2_0_DEV_VERSION,
395 .dev_id = QCA9888_2_0_DEVICE_ID,
396 .bus = ATH10K_BUS_PCI,
397 .name = "qca9888 hw2.0",
398 .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
400 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
401 .otp_exe_param = 0x00000700,
402 .continuous_frag_desc = true,
403 .channel_counters_freq_hz = 150000,
404 .max_probe_resp_desc_thres = 24,
407 .max_spatial_stream = 2,
408 .cal_data_len = 12064,
410 .dir = QCA9888_HW_2_0_FW_DIR,
411 .board = QCA9888_HW_2_0_BOARD_DATA_FILE,
412 .board_size = QCA99X0_BOARD_DATA_SZ,
413 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
415 .sw_decrypt_mcast_mgmt = true,
416 .hw_ops = &qca99x0_ops,
417 .decap_align_bytes = 1,
418 .spectral_bin_discard = 12,
419 .spectral_bin_offset = 8,
421 /* Can do only 1x1 VHT160 or 80+80. 780Mbps is 2x2 80Mhz or
422 * 1x1 160Mhz, long-guard-interval.
424 .vht160_mcs_rx_highest = 780,
425 .vht160_mcs_tx_highest = 780,
426 .n_cipher_suites = 11,
427 .ast_skid_limit = 0x10,
428 .num_wds_entries = 0x20,
429 .target_64bit = false,
430 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
432 .shadow_reg_support = false,
434 .hw_filter_reset_required = true,
435 .fw_diag_ce_download = false,
438 .id = QCA9377_HW_1_0_DEV_VERSION,
439 .dev_id = QCA9377_1_0_DEVICE_ID,
440 .bus = ATH10K_BUS_PCI,
441 .name = "qca9377 hw1.0",
442 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
445 .channel_counters_freq_hz = 88000,
446 .max_probe_resp_desc_thres = 0,
447 .cal_data_len = 8124,
449 .dir = QCA9377_HW_1_0_FW_DIR,
450 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
451 .board_size = QCA9377_BOARD_DATA_SZ,
452 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
454 .hw_ops = &qca988x_ops,
455 .decap_align_bytes = 4,
456 .spectral_bin_discard = 0,
457 .spectral_bin_offset = 0,
458 .vht160_mcs_rx_highest = 0,
459 .vht160_mcs_tx_highest = 0,
460 .n_cipher_suites = 8,
461 .ast_skid_limit = 0x10,
462 .num_wds_entries = 0x20,
463 .target_64bit = false,
464 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
466 .shadow_reg_support = false,
468 .hw_filter_reset_required = true,
469 .fw_diag_ce_download = false,
472 .id = QCA9377_HW_1_1_DEV_VERSION,
473 .dev_id = QCA9377_1_0_DEVICE_ID,
474 .bus = ATH10K_BUS_PCI,
475 .name = "qca9377 hw1.1",
476 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
479 .channel_counters_freq_hz = 88000,
480 .max_probe_resp_desc_thres = 0,
481 .cal_data_len = 8124,
483 .dir = QCA9377_HW_1_0_FW_DIR,
484 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
485 .board_size = QCA9377_BOARD_DATA_SZ,
486 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
488 .hw_ops = &qca6174_ops,
489 .hw_clk = qca6174_clk,
490 .target_cpu_freq = 176000000,
491 .decap_align_bytes = 4,
492 .spectral_bin_discard = 0,
493 .spectral_bin_offset = 0,
494 .vht160_mcs_rx_highest = 0,
495 .vht160_mcs_tx_highest = 0,
496 .n_cipher_suites = 8,
497 .ast_skid_limit = 0x10,
498 .num_wds_entries = 0x20,
499 .target_64bit = false,
500 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
502 .shadow_reg_support = false,
504 .hw_filter_reset_required = true,
505 .fw_diag_ce_download = true,
508 .id = QCA4019_HW_1_0_DEV_VERSION,
510 .bus = ATH10K_BUS_AHB,
511 .name = "qca4019 hw1.0",
512 .patch_load_addr = QCA4019_HW_1_0_PATCH_LOAD_ADDR,
514 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
515 .otp_exe_param = 0x0010000,
516 .continuous_frag_desc = true,
517 .cck_rate_map_rev2 = true,
518 .channel_counters_freq_hz = 125000,
519 .max_probe_resp_desc_thres = 24,
520 .tx_chain_mask = 0x3,
521 .rx_chain_mask = 0x3,
522 .max_spatial_stream = 2,
523 .cal_data_len = 12064,
525 .dir = QCA4019_HW_1_0_FW_DIR,
526 .board = QCA4019_HW_1_0_BOARD_DATA_FILE,
527 .board_size = QCA4019_BOARD_DATA_SZ,
528 .board_ext_size = QCA4019_BOARD_EXT_DATA_SZ,
530 .sw_decrypt_mcast_mgmt = true,
531 .hw_ops = &qca99x0_ops,
532 .decap_align_bytes = 1,
533 .spectral_bin_discard = 4,
534 .spectral_bin_offset = 0,
535 .vht160_mcs_rx_highest = 0,
536 .vht160_mcs_tx_highest = 0,
537 .n_cipher_suites = 11,
538 .ast_skid_limit = 0x10,
539 .num_wds_entries = 0x20,
540 .target_64bit = false,
541 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
543 .shadow_reg_support = false,
545 .hw_filter_reset_required = true,
546 .fw_diag_ce_download = false,
549 .id = WCN3990_HW_1_0_DEV_VERSION,
551 .bus = ATH10K_BUS_SNOC,
552 .name = "wcn3990 hw1.0",
553 .continuous_frag_desc = true,
554 .tx_chain_mask = 0x7,
555 .rx_chain_mask = 0x7,
556 .max_spatial_stream = 4,
558 .dir = WCN3990_HW_1_0_FW_DIR,
560 .sw_decrypt_mcast_mgmt = true,
561 .hw_ops = &wcn3990_ops,
562 .decap_align_bytes = 1,
563 .num_peers = TARGET_HL_10_TLV_NUM_PEERS,
564 .n_cipher_suites = 11,
565 .ast_skid_limit = TARGET_HL_10_TLV_AST_SKID_LIMIT,
566 .num_wds_entries = TARGET_HL_10_TLV_NUM_WDS_ENTRIES,
567 .target_64bit = true,
568 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL_DUAL_MAC,
570 .shadow_reg_support = true,
572 .hw_filter_reset_required = false,
573 .fw_diag_ce_download = false,
577 static const char *const ath10k_core_fw_feature_str[] = {
578 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
579 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
580 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
581 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
582 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
583 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
584 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
585 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
586 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
587 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
588 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
589 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA] = "adaptive-cca",
590 [ATH10K_FW_FEATURE_MFP_SUPPORT] = "mfp",
591 [ATH10K_FW_FEATURE_PEER_FLOW_CONTROL] = "peer-flow-ctrl",
592 [ATH10K_FW_FEATURE_BTCOEX_PARAM] = "btcoex-param",
593 [ATH10K_FW_FEATURE_SKIP_NULL_FUNC_WAR] = "skip-null-func-war",
594 [ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST] = "allows-mesh-bcast",
595 [ATH10K_FW_FEATURE_NO_PS] = "no-ps",
596 [ATH10K_FW_FEATURE_MGMT_TX_BY_REF] = "mgmt-tx-by-reference",
597 [ATH10K_FW_FEATURE_NON_BMI] = "non-bmi",
598 [ATH10K_FW_FEATURE_SINGLE_CHAN_INFO_PER_CHANNEL] = "single-chan-info-per-channel",
601 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
603 enum ath10k_fw_features feat)
605 /* make sure that ath10k_core_fw_feature_str[] gets updated */
606 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
607 ATH10K_FW_FEATURE_COUNT);
609 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
610 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
611 return scnprintf(buf, buf_len, "bit%d", feat);
614 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
617 void ath10k_core_get_fw_features_str(struct ath10k *ar,
624 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
625 if (test_bit(i, ar->normal_mode_fw.fw_file.fw_features)) {
627 len += scnprintf(buf + len, buf_len - len, ",");
629 len += ath10k_core_get_fw_feature_str(buf + len,
636 static void ath10k_send_suspend_complete(struct ath10k *ar)
638 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
640 complete(&ar->target_suspend);
643 static void ath10k_init_sdio(struct ath10k *ar)
647 ath10k_bmi_write32(ar, hi_mbox_io_block_sz, 256);
648 ath10k_bmi_write32(ar, hi_mbox_isr_yield_limit, 99);
649 ath10k_bmi_read32(ar, hi_acs_flags, ¶m);
651 param |= (HI_ACS_FLAGS_SDIO_SWAP_MAILBOX_SET |
652 HI_ACS_FLAGS_SDIO_REDUCE_TX_COMPL_SET |
653 HI_ACS_FLAGS_ALT_DATA_CREDIT_SIZE);
655 ath10k_bmi_write32(ar, hi_acs_flags, param);
658 static int ath10k_init_configure_target(struct ath10k *ar)
663 /* tell target which HTC version it is used*/
664 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
665 HTC_PROTOCOL_VERSION);
667 ath10k_err(ar, "settings HTC version failed\n");
671 /* set the firmware mode to STA/IBSS/AP */
672 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
674 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
678 /* TODO following parameters need to be re-visited. */
680 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
682 /* FIXME: Why FW_MODE_AP ??.*/
683 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
684 /* mac_addr_method */
685 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
686 /* firmware_bridge */
687 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
689 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
691 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
693 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
697 /* We do all byte-swapping on the host */
698 ret = ath10k_bmi_write32(ar, hi_be, 0);
700 ath10k_err(ar, "setting host CPU BE mode failed\n");
704 /* FW descriptor/Data swap flags */
705 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
708 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
712 /* Some devices have a special sanity check that verifies the PCI
713 * Device ID is written to this host interest var. It is known to be
714 * required to boot QCA6164.
716 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
719 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
726 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
731 const struct firmware *fw;
735 return ERR_PTR(-ENOENT);
740 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
741 ret = firmware_request_nowarn(&fw, filename, ar->dev);
742 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot fw request '%s': %d\n",
751 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
754 u32 board_data_size = ar->hw_params.fw.board_size;
755 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
756 u32 board_ext_data_addr;
759 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
761 ath10k_err(ar, "could not read board ext data addr (%d)\n",
766 ath10k_dbg(ar, ATH10K_DBG_BOOT,
767 "boot push board extended data addr 0x%x\n",
768 board_ext_data_addr);
770 if (board_ext_data_addr == 0)
773 if (data_len != (board_data_size + board_ext_data_size)) {
774 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
775 data_len, board_data_size, board_ext_data_size);
779 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
780 data + board_data_size,
781 board_ext_data_size);
783 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
787 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
788 (board_ext_data_size << 16) | 1);
790 ath10k_err(ar, "could not write board ext data bit (%d)\n",
798 static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
801 u8 board_id, chip_id;
802 bool ext_bid_support;
803 int ret, bmi_board_id_param;
805 address = ar->hw_params.patch_load_addr;
807 if (!ar->normal_mode_fw.fw_file.otp_data ||
808 !ar->normal_mode_fw.fw_file.otp_len) {
810 "failed to retrieve board id because of invalid otp\n");
814 ath10k_dbg(ar, ATH10K_DBG_BOOT,
815 "boot upload otp to 0x%x len %zd for board id\n",
816 address, ar->normal_mode_fw.fw_file.otp_len);
818 ret = ath10k_bmi_fast_download(ar, address,
819 ar->normal_mode_fw.fw_file.otp_data,
820 ar->normal_mode_fw.fw_file.otp_len);
822 ath10k_err(ar, "could not write otp for board id check: %d\n",
827 if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
828 ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
829 bmi_board_id_param = BMI_PARAM_GET_FLASH_BOARD_ID;
831 bmi_board_id_param = BMI_PARAM_GET_EEPROM_BOARD_ID;
833 ret = ath10k_bmi_execute(ar, address, bmi_board_id_param, &result);
835 ath10k_err(ar, "could not execute otp for board id check: %d\n",
840 board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP);
841 chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP);
842 ext_bid_support = (result & ATH10K_BMI_EXT_BOARD_ID_SUPPORT);
844 ath10k_dbg(ar, ATH10K_DBG_BOOT,
845 "boot get otp board id result 0x%08x board_id %d chip_id %d ext_bid_support %d\n",
846 result, board_id, chip_id, ext_bid_support);
848 ar->id.ext_bid_supported = ext_bid_support;
850 if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0 ||
852 ath10k_dbg(ar, ATH10K_DBG_BOOT,
853 "board id does not exist in otp, ignore it\n");
857 ar->id.bmi_ids_valid = true;
858 ar->id.bmi_board_id = board_id;
859 ar->id.bmi_chip_id = chip_id;
864 static void ath10k_core_check_bdfext(const struct dmi_header *hdr, void *data)
866 struct ath10k *ar = data;
868 const char *magic = ATH10K_SMBIOS_BDF_EXT_MAGIC;
872 if (hdr->type != ATH10K_SMBIOS_BDF_EXT_TYPE)
875 if (hdr->length != ATH10K_SMBIOS_BDF_EXT_LENGTH) {
876 ath10k_dbg(ar, ATH10K_DBG_BOOT,
877 "wrong smbios bdf ext type length (%d).\n",
882 bdf_enabled = *((u8 *)hdr + ATH10K_SMBIOS_BDF_EXT_OFFSET);
884 ath10k_dbg(ar, ATH10K_DBG_BOOT, "bdf variant name not found.\n");
888 /* Only one string exists (per spec) */
889 bdf_ext = (char *)hdr + hdr->length;
891 if (memcmp(bdf_ext, magic, strlen(magic)) != 0) {
892 ath10k_dbg(ar, ATH10K_DBG_BOOT,
893 "bdf variant magic does not match.\n");
897 for (i = 0; i < strlen(bdf_ext); i++) {
898 if (!isascii(bdf_ext[i]) || !isprint(bdf_ext[i])) {
899 ath10k_dbg(ar, ATH10K_DBG_BOOT,
900 "bdf variant name contains non ascii chars.\n");
905 /* Copy extension name without magic suffix */
906 if (strscpy(ar->id.bdf_ext, bdf_ext + strlen(magic),
907 sizeof(ar->id.bdf_ext)) < 0) {
908 ath10k_dbg(ar, ATH10K_DBG_BOOT,
909 "bdf variant string is longer than the buffer can accommodate (variant: %s)\n",
914 ath10k_dbg(ar, ATH10K_DBG_BOOT,
915 "found and validated bdf variant smbios_type 0x%x bdf %s\n",
916 ATH10K_SMBIOS_BDF_EXT_TYPE, bdf_ext);
919 static int ath10k_core_check_smbios(struct ath10k *ar)
921 ar->id.bdf_ext[0] = '\0';
922 dmi_walk(ath10k_core_check_bdfext, ar);
924 if (ar->id.bdf_ext[0] == '\0')
930 static int ath10k_core_check_dt(struct ath10k *ar)
932 struct device_node *node;
933 const char *variant = NULL;
935 node = ar->dev->of_node;
939 of_property_read_string(node, "qcom,ath10k-calibration-variant",
944 if (strscpy(ar->id.bdf_ext, variant, sizeof(ar->id.bdf_ext)) < 0)
945 ath10k_dbg(ar, ATH10K_DBG_BOOT,
946 "bdf variant string is longer than the buffer can accommodate (variant: %s)\n",
952 static int ath10k_download_fw(struct ath10k *ar)
954 u32 address, data_len;
958 address = ar->hw_params.patch_load_addr;
960 data = ar->running_fw->fw_file.firmware_data;
961 data_len = ar->running_fw->fw_file.firmware_len;
963 ret = ath10k_swap_code_seg_configure(ar, &ar->running_fw->fw_file);
965 ath10k_err(ar, "failed to configure fw code swap: %d\n",
970 ath10k_dbg(ar, ATH10K_DBG_BOOT,
971 "boot uploading firmware image %pK len %d\n",
974 /* Check if device supports to download firmware via
975 * diag copy engine. Downloading firmware via diag CE
976 * greatly reduces the time to download firmware.
978 if (ar->hw_params.fw_diag_ce_download) {
979 ret = ath10k_hw_diag_fast_download(ar, address,
982 /* firmware upload via diag ce was successful */
986 "failed to upload firmware via diag ce, trying BMI: %d",
990 return ath10k_bmi_fast_download(ar, address,
994 void ath10k_core_free_board_files(struct ath10k *ar)
996 if (!IS_ERR(ar->normal_mode_fw.board))
997 release_firmware(ar->normal_mode_fw.board);
999 if (!IS_ERR(ar->normal_mode_fw.ext_board))
1000 release_firmware(ar->normal_mode_fw.ext_board);
1002 ar->normal_mode_fw.board = NULL;
1003 ar->normal_mode_fw.board_data = NULL;
1004 ar->normal_mode_fw.board_len = 0;
1005 ar->normal_mode_fw.ext_board = NULL;
1006 ar->normal_mode_fw.ext_board_data = NULL;
1007 ar->normal_mode_fw.ext_board_len = 0;
1009 EXPORT_SYMBOL(ath10k_core_free_board_files);
1011 static void ath10k_core_free_firmware_files(struct ath10k *ar)
1013 if (!IS_ERR(ar->normal_mode_fw.fw_file.firmware))
1014 release_firmware(ar->normal_mode_fw.fw_file.firmware);
1016 if (!IS_ERR(ar->cal_file))
1017 release_firmware(ar->cal_file);
1019 if (!IS_ERR(ar->pre_cal_file))
1020 release_firmware(ar->pre_cal_file);
1022 ath10k_swap_code_seg_release(ar, &ar->normal_mode_fw.fw_file);
1024 ar->normal_mode_fw.fw_file.otp_data = NULL;
1025 ar->normal_mode_fw.fw_file.otp_len = 0;
1027 ar->normal_mode_fw.fw_file.firmware = NULL;
1028 ar->normal_mode_fw.fw_file.firmware_data = NULL;
1029 ar->normal_mode_fw.fw_file.firmware_len = 0;
1031 ar->cal_file = NULL;
1032 ar->pre_cal_file = NULL;
1035 static int ath10k_fetch_cal_file(struct ath10k *ar)
1039 /* pre-cal-<bus>-<id>.bin */
1040 scnprintf(filename, sizeof(filename), "pre-cal-%s-%s.bin",
1041 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
1043 ar->pre_cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
1044 if (!IS_ERR(ar->pre_cal_file))
1047 /* cal-<bus>-<id>.bin */
1048 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
1049 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
1051 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
1052 if (IS_ERR(ar->cal_file))
1053 /* calibration file is optional, don't print any warnings */
1054 return PTR_ERR(ar->cal_file);
1056 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
1057 ATH10K_FW_DIR, filename);
1062 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar, int bd_ie_type)
1064 const struct firmware *fw;
1066 if (bd_ie_type == ATH10K_BD_IE_BOARD) {
1067 if (!ar->hw_params.fw.board) {
1068 ath10k_err(ar, "failed to find board file fw entry\n");
1072 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
1073 ar->hw_params.fw.dir,
1074 ar->hw_params.fw.board);
1075 if (IS_ERR(ar->normal_mode_fw.board))
1076 return PTR_ERR(ar->normal_mode_fw.board);
1078 ar->normal_mode_fw.board_data = ar->normal_mode_fw.board->data;
1079 ar->normal_mode_fw.board_len = ar->normal_mode_fw.board->size;
1080 } else if (bd_ie_type == ATH10K_BD_IE_BOARD_EXT) {
1081 if (!ar->hw_params.fw.eboard) {
1082 ath10k_err(ar, "failed to find eboard file fw entry\n");
1086 fw = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
1087 ar->hw_params.fw.eboard);
1088 ar->normal_mode_fw.ext_board = fw;
1089 if (IS_ERR(ar->normal_mode_fw.ext_board))
1090 return PTR_ERR(ar->normal_mode_fw.ext_board);
1092 ar->normal_mode_fw.ext_board_data = ar->normal_mode_fw.ext_board->data;
1093 ar->normal_mode_fw.ext_board_len = ar->normal_mode_fw.ext_board->size;
1099 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
1100 const void *buf, size_t buf_len,
1101 const char *boardname,
1104 const struct ath10k_fw_ie *hdr;
1105 bool name_match_found;
1106 int ret, board_ie_id;
1107 size_t board_ie_len;
1108 const void *board_ie_data;
1110 name_match_found = false;
1112 /* go through ATH10K_BD_IE_BOARD_ elements */
1113 while (buf_len > sizeof(struct ath10k_fw_ie)) {
1115 board_ie_id = le32_to_cpu(hdr->id);
1116 board_ie_len = le32_to_cpu(hdr->len);
1117 board_ie_data = hdr->data;
1119 buf_len -= sizeof(*hdr);
1120 buf += sizeof(*hdr);
1122 if (buf_len < ALIGN(board_ie_len, 4)) {
1123 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
1124 buf_len, ALIGN(board_ie_len, 4));
1129 switch (board_ie_id) {
1130 case ATH10K_BD_IE_BOARD_NAME:
1131 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
1132 board_ie_data, board_ie_len);
1134 if (board_ie_len != strlen(boardname))
1137 ret = memcmp(board_ie_data, boardname, strlen(boardname));
1141 name_match_found = true;
1142 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1143 "boot found match for name '%s'",
1146 case ATH10K_BD_IE_BOARD_DATA:
1147 if (!name_match_found)
1148 /* no match found */
1151 if (bd_ie_type == ATH10K_BD_IE_BOARD) {
1152 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1153 "boot found board data for '%s'",
1156 ar->normal_mode_fw.board_data = board_ie_data;
1157 ar->normal_mode_fw.board_len = board_ie_len;
1158 } else if (bd_ie_type == ATH10K_BD_IE_BOARD_EXT) {
1159 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1160 "boot found eboard data for '%s'",
1163 ar->normal_mode_fw.ext_board_data = board_ie_data;
1164 ar->normal_mode_fw.ext_board_len = board_ie_len;
1170 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
1175 /* jump over the padding */
1176 board_ie_len = ALIGN(board_ie_len, 4);
1178 buf_len -= board_ie_len;
1179 buf += board_ie_len;
1182 /* no match found */
1189 static int ath10k_core_search_bd(struct ath10k *ar,
1190 const char *boardname,
1195 struct ath10k_fw_ie *hdr;
1196 int ret = -ENOENT, ie_id;
1198 while (len > sizeof(struct ath10k_fw_ie)) {
1199 hdr = (struct ath10k_fw_ie *)data;
1200 ie_id = le32_to_cpu(hdr->id);
1201 ie_len = le32_to_cpu(hdr->len);
1203 len -= sizeof(*hdr);
1206 if (len < ALIGN(ie_len, 4)) {
1207 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
1208 ie_id, ie_len, len);
1213 case ATH10K_BD_IE_BOARD:
1214 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
1216 ATH10K_BD_IE_BOARD);
1218 /* no match found, continue */
1221 /* either found or error, so stop searching */
1223 case ATH10K_BD_IE_BOARD_EXT:
1224 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
1226 ATH10K_BD_IE_BOARD_EXT);
1228 /* no match found, continue */
1231 /* either found or error, so stop searching */
1235 /* jump over the padding */
1236 ie_len = ALIGN(ie_len, 4);
1243 /* return result of parse_bd_ie_board() or -ENOENT */
1247 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
1248 const char *boardname,
1249 const char *fallback_boardname,
1250 const char *filename)
1252 size_t len, magic_len;
1256 /* Skip if already fetched during board data download */
1257 if (!ar->normal_mode_fw.board)
1258 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
1259 ar->hw_params.fw.dir,
1261 if (IS_ERR(ar->normal_mode_fw.board))
1262 return PTR_ERR(ar->normal_mode_fw.board);
1264 data = ar->normal_mode_fw.board->data;
1265 len = ar->normal_mode_fw.board->size;
1267 /* magic has extra null byte padded */
1268 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
1269 if (len < magic_len) {
1270 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
1271 ar->hw_params.fw.dir, filename, len);
1276 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
1277 ath10k_err(ar, "found invalid board magic\n");
1282 /* magic is padded to 4 bytes */
1283 magic_len = ALIGN(magic_len, 4);
1284 if (len < magic_len) {
1285 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
1286 ar->hw_params.fw.dir, filename, len);
1294 /* attempt to find boardname in the IE list */
1295 ret = ath10k_core_search_bd(ar, boardname, data, len);
1297 /* if we didn't find it and have a fallback name, try that */
1298 if (ret == -ENOENT && fallback_boardname)
1299 ret = ath10k_core_search_bd(ar, fallback_boardname, data, len);
1301 if (ret == -ENOENT) {
1303 "failed to fetch board data for %s from %s/%s\n",
1304 boardname, ar->hw_params.fw.dir, filename);
1314 ath10k_core_free_board_files(ar);
1318 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
1319 size_t name_len, bool with_variant)
1321 /* strlen(',variant=') + strlen(ar->id.bdf_ext) */
1322 char variant[9 + ATH10K_SMBIOS_BDF_EXT_STR_LENGTH] = { 0 };
1324 if (with_variant && ar->id.bdf_ext[0] != '\0')
1325 scnprintf(variant, sizeof(variant), ",variant=%s",
1328 if (ar->id.bmi_ids_valid) {
1329 scnprintf(name, name_len,
1330 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d%s",
1331 ath10k_bus_str(ar->hif.bus),
1333 ar->id.bmi_board_id, variant);
1337 if (ar->id.qmi_ids_valid) {
1338 scnprintf(name, name_len,
1339 "bus=%s,qmi-board-id=%x",
1340 ath10k_bus_str(ar->hif.bus),
1341 ar->id.qmi_board_id);
1345 scnprintf(name, name_len,
1346 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x%s",
1347 ath10k_bus_str(ar->hif.bus),
1348 ar->id.vendor, ar->id.device,
1349 ar->id.subsystem_vendor, ar->id.subsystem_device, variant);
1351 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
1356 static int ath10k_core_create_eboard_name(struct ath10k *ar, char *name,
1359 if (ar->id.bmi_ids_valid) {
1360 scnprintf(name, name_len,
1361 "bus=%s,bmi-chip-id=%d,bmi-eboard-id=%d",
1362 ath10k_bus_str(ar->hif.bus),
1364 ar->id.bmi_eboard_id);
1366 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using eboard name '%s'\n", name);
1369 /* Fallback if returned board id is zero */
1373 int ath10k_core_fetch_board_file(struct ath10k *ar, int bd_ie_type)
1375 char boardname[100], fallback_boardname[100];
1378 if (bd_ie_type == ATH10K_BD_IE_BOARD) {
1379 ret = ath10k_core_create_board_name(ar, boardname,
1380 sizeof(boardname), true);
1382 ath10k_err(ar, "failed to create board name: %d", ret);
1386 ret = ath10k_core_create_board_name(ar, fallback_boardname,
1387 sizeof(boardname), false);
1389 ath10k_err(ar, "failed to create fallback board name: %d", ret);
1392 } else if (bd_ie_type == ATH10K_BD_IE_BOARD_EXT) {
1393 ret = ath10k_core_create_eboard_name(ar, boardname,
1396 ath10k_err(ar, "fallback to eboard.bin since board id 0");
1402 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
1404 ATH10K_BOARD_API2_FILE);
1410 ret = ath10k_core_fetch_board_data_api_1(ar, bd_ie_type);
1412 ath10k_err(ar, "failed to fetch board-2.bin or board.bin from %s\n",
1413 ar->hw_params.fw.dir);
1418 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
1421 EXPORT_SYMBOL(ath10k_core_fetch_board_file);
1423 static int ath10k_core_get_ext_board_id_from_otp(struct ath10k *ar)
1425 u32 result, address;
1429 address = ar->hw_params.patch_load_addr;
1431 if (!ar->normal_mode_fw.fw_file.otp_data ||
1432 !ar->normal_mode_fw.fw_file.otp_len) {
1434 "failed to retrieve extended board id due to otp binary missing\n");
1438 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1439 "boot upload otp to 0x%x len %zd for ext board id\n",
1440 address, ar->normal_mode_fw.fw_file.otp_len);
1442 ret = ath10k_bmi_fast_download(ar, address,
1443 ar->normal_mode_fw.fw_file.otp_data,
1444 ar->normal_mode_fw.fw_file.otp_len);
1446 ath10k_err(ar, "could not write otp for ext board id check: %d\n",
1451 ret = ath10k_bmi_execute(ar, address, BMI_PARAM_GET_EXT_BOARD_ID, &result);
1453 ath10k_err(ar, "could not execute otp for ext board id check: %d\n",
1459 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1460 "ext board id does not exist in otp, ignore it\n");
1464 ext_board_id = result & ATH10K_BMI_EBOARD_ID_STATUS_MASK;
1466 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1467 "boot get otp ext board id result 0x%08x ext_board_id %d\n",
1468 result, ext_board_id);
1470 ar->id.bmi_eboard_id = ext_board_id;
1475 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
1478 u32 board_data_size = ar->hw_params.fw.board_size;
1479 u32 eboard_data_size = ar->hw_params.fw.ext_board_size;
1481 u32 ext_board_address;
1484 ret = ath10k_push_board_ext_data(ar, data, data_len);
1486 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
1490 ret = ath10k_bmi_read32(ar, hi_board_data, &board_address);
1492 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
1496 ret = ath10k_bmi_write_memory(ar, board_address, data,
1497 min_t(u32, board_data_size,
1500 ath10k_err(ar, "could not write board data (%d)\n", ret);
1504 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
1506 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
1510 if (!ar->id.ext_bid_supported)
1513 /* Extended board data download */
1514 ret = ath10k_core_get_ext_board_id_from_otp(ar);
1515 if (ret == -EOPNOTSUPP) {
1516 /* Not fetching ext_board_data if ext board id is 0 */
1517 ath10k_dbg(ar, ATH10K_DBG_BOOT, "otp returned ext board id 0\n");
1520 ath10k_err(ar, "failed to get extended board id: %d\n", ret);
1524 ret = ath10k_core_fetch_board_file(ar, ATH10K_BD_IE_BOARD_EXT);
1528 if (ar->normal_mode_fw.ext_board_data) {
1529 ext_board_address = board_address + EXT_BOARD_ADDRESS_OFFSET;
1530 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1531 "boot writing ext board data to addr 0x%x",
1533 ret = ath10k_bmi_write_memory(ar, ext_board_address,
1534 ar->normal_mode_fw.ext_board_data,
1535 min_t(u32, eboard_data_size, data_len));
1537 ath10k_err(ar, "failed to write ext board data: %d\n", ret);
1544 static int ath10k_download_and_run_otp(struct ath10k *ar)
1546 u32 result, address = ar->hw_params.patch_load_addr;
1547 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
1550 ret = ath10k_download_board_data(ar,
1551 ar->running_fw->board_data,
1552 ar->running_fw->board_len);
1554 ath10k_err(ar, "failed to download board data: %d\n", ret);
1558 /* OTP is optional */
1560 if (!ar->running_fw->fw_file.otp_data ||
1561 !ar->running_fw->fw_file.otp_len) {
1562 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %pK otp_len %zd)!\n",
1563 ar->running_fw->fw_file.otp_data,
1564 ar->running_fw->fw_file.otp_len);
1568 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
1569 address, ar->running_fw->fw_file.otp_len);
1571 ret = ath10k_bmi_fast_download(ar, address,
1572 ar->running_fw->fw_file.otp_data,
1573 ar->running_fw->fw_file.otp_len);
1575 ath10k_err(ar, "could not write otp (%d)\n", ret);
1579 /* As of now pre-cal is valid for 10_4 variants */
1580 if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
1581 ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
1582 bmi_otp_exe_param = BMI_PARAM_FLASH_SECTION_ALL;
1584 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
1586 ath10k_err(ar, "could not execute otp (%d)\n", ret);
1590 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
1592 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
1593 ar->running_fw->fw_file.fw_features)) &&
1595 ath10k_err(ar, "otp calibration failed: %d", result);
1602 static int ath10k_download_cal_file(struct ath10k *ar,
1603 const struct firmware *file)
1611 return PTR_ERR(file);
1613 ret = ath10k_download_board_data(ar, file->data, file->size);
1615 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
1619 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
1624 static int ath10k_download_cal_dt(struct ath10k *ar, const char *dt_name)
1626 struct device_node *node;
1631 node = ar->dev->of_node;
1633 /* Device Tree is optional, don't print any warnings if
1634 * there's no node for ath10k.
1638 if (!of_get_property(node, dt_name, &data_len)) {
1639 /* The calibration data node is optional */
1643 if (data_len != ar->hw_params.cal_data_len) {
1644 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
1650 data = kmalloc(data_len, GFP_KERNEL);
1656 ret = of_property_read_u8_array(node, dt_name, data, data_len);
1658 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
1663 ret = ath10k_download_board_data(ar, data, data_len);
1665 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
1679 static int ath10k_download_cal_eeprom(struct ath10k *ar)
1685 ret = ath10k_hif_fetch_cal_eeprom(ar, &data, &data_len);
1687 if (ret != -EOPNOTSUPP)
1688 ath10k_warn(ar, "failed to read calibration data from EEPROM: %d\n",
1693 ret = ath10k_download_board_data(ar, data, data_len);
1695 ath10k_warn(ar, "failed to download calibration data from EEPROM: %d\n",
1708 int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name,
1709 struct ath10k_fw_file *fw_file)
1711 size_t magic_len, len, ie_len;
1712 int ie_id, i, index, bit, ret;
1713 struct ath10k_fw_ie *hdr;
1715 __le32 *timestamp, *version;
1717 /* first fetch the firmware file (firmware-*.bin) */
1718 fw_file->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
1720 if (IS_ERR(fw_file->firmware))
1721 return PTR_ERR(fw_file->firmware);
1723 data = fw_file->firmware->data;
1724 len = fw_file->firmware->size;
1726 /* magic also includes the null byte, check that as well */
1727 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
1729 if (len < magic_len) {
1730 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
1731 ar->hw_params.fw.dir, name, len);
1736 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
1737 ath10k_err(ar, "invalid firmware magic\n");
1742 /* jump over the padding */
1743 magic_len = ALIGN(magic_len, 4);
1749 while (len > sizeof(struct ath10k_fw_ie)) {
1750 hdr = (struct ath10k_fw_ie *)data;
1752 ie_id = le32_to_cpu(hdr->id);
1753 ie_len = le32_to_cpu(hdr->len);
1755 len -= sizeof(*hdr);
1756 data += sizeof(*hdr);
1759 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
1760 ie_id, len, ie_len);
1766 case ATH10K_FW_IE_FW_VERSION:
1767 if (ie_len > sizeof(fw_file->fw_version) - 1)
1770 memcpy(fw_file->fw_version, data, ie_len);
1771 fw_file->fw_version[ie_len] = '\0';
1773 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1774 "found fw version %s\n",
1775 fw_file->fw_version);
1777 case ATH10K_FW_IE_TIMESTAMP:
1778 if (ie_len != sizeof(u32))
1781 timestamp = (__le32 *)data;
1783 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
1784 le32_to_cpup(timestamp));
1786 case ATH10K_FW_IE_FEATURES:
1787 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1788 "found firmware features ie (%zd B)\n",
1791 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
1795 if (index == ie_len)
1798 if (data[index] & (1 << bit)) {
1799 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1800 "Enabling feature bit: %i\n",
1802 __set_bit(i, fw_file->fw_features);
1806 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
1807 fw_file->fw_features,
1808 sizeof(fw_file->fw_features));
1810 case ATH10K_FW_IE_FW_IMAGE:
1811 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1812 "found fw image ie (%zd B)\n",
1815 fw_file->firmware_data = data;
1816 fw_file->firmware_len = ie_len;
1819 case ATH10K_FW_IE_OTP_IMAGE:
1820 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1821 "found otp image ie (%zd B)\n",
1824 fw_file->otp_data = data;
1825 fw_file->otp_len = ie_len;
1828 case ATH10K_FW_IE_WMI_OP_VERSION:
1829 if (ie_len != sizeof(u32))
1832 version = (__le32 *)data;
1834 fw_file->wmi_op_version = le32_to_cpup(version);
1836 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1837 fw_file->wmi_op_version);
1839 case ATH10K_FW_IE_HTT_OP_VERSION:
1840 if (ie_len != sizeof(u32))
1843 version = (__le32 *)data;
1845 fw_file->htt_op_version = le32_to_cpup(version);
1847 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1848 fw_file->htt_op_version);
1850 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1851 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1852 "found fw code swap image ie (%zd B)\n",
1854 fw_file->codeswap_data = data;
1855 fw_file->codeswap_len = ie_len;
1858 ath10k_warn(ar, "Unknown FW IE: %u\n",
1859 le32_to_cpu(hdr->id));
1863 /* jump over the padding */
1864 ie_len = ALIGN(ie_len, 4);
1870 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI, fw_file->fw_features) &&
1871 (!fw_file->firmware_data || !fw_file->firmware_len)) {
1872 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1873 ar->hw_params.fw.dir, name);
1881 ath10k_core_free_firmware_files(ar);
1885 static void ath10k_core_get_fw_name(struct ath10k *ar, char *fw_name,
1886 size_t fw_name_len, int fw_api)
1888 switch (ar->hif.bus) {
1889 case ATH10K_BUS_SDIO:
1890 case ATH10K_BUS_USB:
1891 scnprintf(fw_name, fw_name_len, "%s-%s-%d.bin",
1892 ATH10K_FW_FILE_BASE, ath10k_bus_str(ar->hif.bus),
1895 case ATH10K_BUS_PCI:
1896 case ATH10K_BUS_AHB:
1897 case ATH10K_BUS_SNOC:
1898 scnprintf(fw_name, fw_name_len, "%s-%d.bin",
1899 ATH10K_FW_FILE_BASE, fw_api);
1904 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1909 /* calibration file is optional, don't check for any errors */
1910 ath10k_fetch_cal_file(ar);
1912 for (i = ATH10K_FW_API_MAX; i >= ATH10K_FW_API_MIN; i--) {
1914 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n",
1917 ath10k_core_get_fw_name(ar, fw_name, sizeof(fw_name), ar->fw_api);
1918 ret = ath10k_core_fetch_firmware_api_n(ar, fw_name,
1919 &ar->normal_mode_fw.fw_file);
1924 /* we end up here if we couldn't fetch any firmware */
1926 ath10k_err(ar, "Failed to find firmware-N.bin (N between %d and %d) from %s: %d",
1927 ATH10K_FW_API_MIN, ATH10K_FW_API_MAX, ar->hw_params.fw.dir,
1933 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1938 static int ath10k_core_pre_cal_download(struct ath10k *ar)
1942 ret = ath10k_download_cal_file(ar, ar->pre_cal_file);
1944 ar->cal_mode = ATH10K_PRE_CAL_MODE_FILE;
1948 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1949 "boot did not find a pre calibration file, try DT next: %d\n",
1952 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-pre-calibration-data");
1954 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1955 "unable to load pre cal data from DT: %d\n", ret);
1958 ar->cal_mode = ATH10K_PRE_CAL_MODE_DT;
1961 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
1962 ath10k_cal_mode_str(ar->cal_mode));
1967 static int ath10k_core_pre_cal_config(struct ath10k *ar)
1971 ret = ath10k_core_pre_cal_download(ar);
1973 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1974 "failed to load pre cal data: %d\n", ret);
1978 ret = ath10k_core_get_board_id_from_otp(ar);
1980 ath10k_err(ar, "failed to get board id: %d\n", ret);
1984 ret = ath10k_download_and_run_otp(ar);
1986 ath10k_err(ar, "failed to run otp: %d\n", ret);
1990 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1991 "pre cal configuration done successfully\n");
1996 static int ath10k_download_cal_data(struct ath10k *ar)
2000 ret = ath10k_core_pre_cal_config(ar);
2004 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2005 "pre cal download procedure failed, try cal file: %d\n",
2008 ret = ath10k_download_cal_file(ar, ar->cal_file);
2010 ar->cal_mode = ATH10K_CAL_MODE_FILE;
2014 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2015 "boot did not find a calibration file, try DT next: %d\n",
2018 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-calibration-data");
2020 ar->cal_mode = ATH10K_CAL_MODE_DT;
2024 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2025 "boot did not find DT entry, try target EEPROM next: %d\n",
2028 ret = ath10k_download_cal_eeprom(ar);
2030 ar->cal_mode = ATH10K_CAL_MODE_EEPROM;
2034 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2035 "boot did not find target EEPROM entry, try OTP next: %d\n",
2038 ret = ath10k_download_and_run_otp(ar);
2040 ath10k_err(ar, "failed to run otp: %d\n", ret);
2044 ar->cal_mode = ATH10K_CAL_MODE_OTP;
2047 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
2048 ath10k_cal_mode_str(ar->cal_mode));
2052 static int ath10k_init_uart(struct ath10k *ar)
2057 * Explicitly setting UART prints to zero as target turns it on
2058 * based on scratch registers.
2060 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
2062 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
2069 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
2071 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
2075 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
2077 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
2081 /* Set the UART baud rate to 19200. */
2082 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
2084 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
2088 ath10k_info(ar, "UART prints enabled\n");
2092 static int ath10k_init_hw_params(struct ath10k *ar)
2094 const struct ath10k_hw_params *uninitialized_var(hw_params);
2097 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
2098 hw_params = &ath10k_hw_params_list[i];
2100 if (hw_params->bus == ar->hif.bus &&
2101 hw_params->id == ar->target_version &&
2102 hw_params->dev_id == ar->dev_id)
2106 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
2107 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
2108 ar->target_version);
2112 ar->hw_params = *hw_params;
2114 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
2115 ar->hw_params.name, ar->target_version);
2120 static void ath10k_core_restart(struct work_struct *work)
2122 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
2125 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
2127 /* Place a barrier to make sure the compiler doesn't reorder
2128 * CRASH_FLUSH and calling other functions.
2132 ieee80211_stop_queues(ar->hw);
2133 ath10k_drain_tx(ar);
2134 complete(&ar->scan.started);
2135 complete(&ar->scan.completed);
2136 complete(&ar->scan.on_channel);
2137 complete(&ar->offchan_tx_completed);
2138 complete(&ar->install_key_done);
2139 complete(&ar->vdev_setup_done);
2140 complete(&ar->thermal.wmi_sync);
2141 complete(&ar->bss_survey_done);
2142 wake_up(&ar->htt.empty_tx_wq);
2143 wake_up(&ar->wmi.tx_credits_wq);
2144 wake_up(&ar->peer_mapping_wq);
2146 /* TODO: We can have one instance of cancelling coverage_class_work by
2147 * moving it to ath10k_halt(), so that both stop() and restart() would
2148 * call that but it takes conf_mutex() and if we call cancel_work_sync()
2149 * with conf_mutex it will deadlock.
2151 cancel_work_sync(&ar->set_coverage_class_work);
2153 mutex_lock(&ar->conf_mutex);
2155 switch (ar->state) {
2156 case ATH10K_STATE_ON:
2157 ar->state = ATH10K_STATE_RESTARTING;
2159 ath10k_scan_finish(ar);
2160 ieee80211_restart_hw(ar->hw);
2162 case ATH10K_STATE_OFF:
2163 /* this can happen if driver is being unloaded
2164 * or if the crash happens during FW probing
2166 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
2168 case ATH10K_STATE_RESTARTING:
2169 /* hw restart might be requested from multiple places */
2171 case ATH10K_STATE_RESTARTED:
2172 ar->state = ATH10K_STATE_WEDGED;
2174 case ATH10K_STATE_WEDGED:
2175 ath10k_warn(ar, "device is wedged, will not restart\n");
2177 case ATH10K_STATE_UTF:
2178 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
2182 mutex_unlock(&ar->conf_mutex);
2184 ret = ath10k_coredump_submit(ar);
2186 ath10k_warn(ar, "failed to send firmware crash dump via devcoredump: %d",
2189 complete(&ar->driver_recovery);
2192 static void ath10k_core_set_coverage_class_work(struct work_struct *work)
2194 struct ath10k *ar = container_of(work, struct ath10k,
2195 set_coverage_class_work);
2197 if (ar->hw_params.hw_ops->set_coverage_class)
2198 ar->hw_params.hw_ops->set_coverage_class(ar, -1);
2201 static int ath10k_core_init_firmware_features(struct ath10k *ar)
2203 struct ath10k_fw_file *fw_file = &ar->normal_mode_fw.fw_file;
2206 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, fw_file->fw_features) &&
2207 !test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
2208 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
2212 if (fw_file->wmi_op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
2213 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
2214 ATH10K_FW_WMI_OP_VERSION_MAX, fw_file->wmi_op_version);
2218 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
2219 switch (ath10k_cryptmode_param) {
2220 case ATH10K_CRYPT_MODE_HW:
2221 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
2222 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
2224 case ATH10K_CRYPT_MODE_SW:
2225 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
2226 fw_file->fw_features)) {
2227 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
2231 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
2232 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
2235 ath10k_info(ar, "invalid cryptmode: %d\n",
2236 ath10k_cryptmode_param);
2240 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
2241 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
2244 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
2245 fw_file->fw_features)) {
2246 ath10k_err(ar, "rawmode = 1 requires support from firmware");
2249 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
2252 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
2253 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
2257 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
2258 * and causes enormous performance issues (malformed frames,
2261 * Disabling A-MSDU makes RAW mode stable with heavy traffic
2262 * albeit a bit slower compared to regular operation.
2264 ar->htt.max_num_amsdu = 1;
2267 /* Backwards compatibility for firmwares without
2268 * ATH10K_FW_IE_WMI_OP_VERSION.
2270 if (fw_file->wmi_op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
2271 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
2272 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
2273 fw_file->fw_features))
2274 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
2276 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
2278 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
2282 switch (fw_file->wmi_op_version) {
2283 case ATH10K_FW_WMI_OP_VERSION_MAIN:
2284 max_num_peers = TARGET_NUM_PEERS;
2285 ar->max_num_stations = TARGET_NUM_STATIONS;
2286 ar->max_num_vdevs = TARGET_NUM_VDEVS;
2287 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
2288 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
2290 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
2292 case ATH10K_FW_WMI_OP_VERSION_10_1:
2293 case ATH10K_FW_WMI_OP_VERSION_10_2:
2294 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
2295 if (ath10k_peer_stats_enabled(ar)) {
2296 max_num_peers = TARGET_10X_TX_STATS_NUM_PEERS;
2297 ar->max_num_stations = TARGET_10X_TX_STATS_NUM_STATIONS;
2299 max_num_peers = TARGET_10X_NUM_PEERS;
2300 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
2302 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
2303 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
2304 ar->fw_stats_req_mask = WMI_STAT_PEER;
2305 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
2307 case ATH10K_FW_WMI_OP_VERSION_TLV:
2308 max_num_peers = TARGET_TLV_NUM_PEERS;
2309 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
2310 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
2311 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
2312 if (ar->hif.bus == ATH10K_BUS_SDIO)
2313 ar->htt.max_num_pending_tx =
2314 TARGET_TLV_NUM_MSDU_DESC_HL;
2316 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
2317 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
2318 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
2320 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
2321 ar->wmi.mgmt_max_num_pending_tx = TARGET_TLV_MGMT_NUM_MSDU_DESC;
2323 case ATH10K_FW_WMI_OP_VERSION_10_4:
2324 max_num_peers = TARGET_10_4_NUM_PEERS;
2325 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
2326 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
2327 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
2328 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
2329 ar->fw_stats_req_mask = WMI_10_4_STAT_PEER |
2330 WMI_10_4_STAT_PEER_EXTD |
2331 WMI_10_4_STAT_VDEV_EXTD;
2332 ar->max_spatial_stream = ar->hw_params.max_spatial_stream;
2333 ar->max_num_tdls_vdevs = TARGET_10_4_NUM_TDLS_VDEVS;
2335 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
2336 fw_file->fw_features))
2337 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC_PFC;
2339 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
2341 case ATH10K_FW_WMI_OP_VERSION_UNSET:
2342 case ATH10K_FW_WMI_OP_VERSION_MAX:
2348 if (ar->hw_params.num_peers)
2349 ar->max_num_peers = ar->hw_params.num_peers;
2351 ar->max_num_peers = max_num_peers;
2353 /* Backwards compatibility for firmwares without
2354 * ATH10K_FW_IE_HTT_OP_VERSION.
2356 if (fw_file->htt_op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
2357 switch (fw_file->wmi_op_version) {
2358 case ATH10K_FW_WMI_OP_VERSION_MAIN:
2359 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
2361 case ATH10K_FW_WMI_OP_VERSION_10_1:
2362 case ATH10K_FW_WMI_OP_VERSION_10_2:
2363 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
2364 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
2366 case ATH10K_FW_WMI_OP_VERSION_TLV:
2367 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
2369 case ATH10K_FW_WMI_OP_VERSION_10_4:
2370 case ATH10K_FW_WMI_OP_VERSION_UNSET:
2371 case ATH10K_FW_WMI_OP_VERSION_MAX:
2372 ath10k_err(ar, "htt op version not found from fw meta data");
2380 static int ath10k_core_reset_rx_filter(struct ath10k *ar)
2386 const u8 *vdev_addr;
2389 vdev_type = WMI_VDEV_TYPE_STA;
2390 vdev_subtype = ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
2391 vdev_addr = ar->mac_addr;
2393 ret = ath10k_wmi_vdev_create(ar, vdev_id, vdev_type, vdev_subtype,
2396 ath10k_err(ar, "failed to create dummy vdev: %d\n", ret);
2400 ret = ath10k_wmi_vdev_delete(ar, vdev_id);
2402 ath10k_err(ar, "failed to delete dummy vdev: %d\n", ret);
2406 /* WMI and HTT may use separate HIF pipes and are not guaranteed to be
2407 * serialized properly implicitly.
2409 * Moreover (most) WMI commands have no explicit acknowledges. It is
2410 * possible to infer it implicitly by poking firmware with echo
2411 * command - getting a reply means all preceding comments have been
2412 * (mostly) processed.
2414 * In case of vdev create/delete this is sufficient.
2416 * Without this it's possible to end up with a race when HTT Rx ring is
2417 * started before vdev create/delete hack is complete allowing a short
2418 * window of opportunity to receive (and Tx ACK) a bunch of frames.
2420 ret = ath10k_wmi_barrier(ar);
2422 ath10k_err(ar, "failed to ping firmware: %d\n", ret);
2429 static int ath10k_core_compat_services(struct ath10k *ar)
2431 struct ath10k_fw_file *fw_file = &ar->normal_mode_fw.fw_file;
2433 /* all 10.x firmware versions support thermal throttling but don't
2434 * advertise the support via service flags so we have to hardcode
2437 switch (fw_file->wmi_op_version) {
2438 case ATH10K_FW_WMI_OP_VERSION_10_1:
2439 case ATH10K_FW_WMI_OP_VERSION_10_2:
2440 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
2441 case ATH10K_FW_WMI_OP_VERSION_10_4:
2442 set_bit(WMI_SERVICE_THERM_THROT, ar->wmi.svc_map);
2451 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
2452 const struct ath10k_fw_components *fw)
2457 lockdep_assert_held(&ar->conf_mutex);
2459 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
2461 ar->running_fw = fw;
2463 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2464 ar->running_fw->fw_file.fw_features)) {
2465 ath10k_bmi_start(ar);
2467 if (ath10k_init_configure_target(ar)) {
2472 status = ath10k_download_cal_data(ar);
2476 /* Some of of qca988x solutions are having global reset issue
2477 * during target initialization. Bypassing PLL setting before
2478 * downloading firmware and letting the SoC run on REF_CLK is
2479 * fixing the problem. Corresponding firmware change is also
2480 * needed to set the clock source once the target is
2483 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
2484 ar->running_fw->fw_file.fw_features)) {
2485 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
2487 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
2493 status = ath10k_download_fw(ar);
2497 status = ath10k_init_uart(ar);
2501 if (ar->hif.bus == ATH10K_BUS_SDIO)
2502 ath10k_init_sdio(ar);
2505 ar->htc.htc_ops.target_send_suspend_complete =
2506 ath10k_send_suspend_complete;
2508 status = ath10k_htc_init(ar);
2510 ath10k_err(ar, "could not init HTC (%d)\n", status);
2514 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2515 ar->running_fw->fw_file.fw_features)) {
2516 status = ath10k_bmi_done(ar);
2521 status = ath10k_wmi_attach(ar);
2523 ath10k_err(ar, "WMI attach failed: %d\n", status);
2527 status = ath10k_htt_init(ar);
2529 ath10k_err(ar, "failed to init htt: %d\n", status);
2530 goto err_wmi_detach;
2533 status = ath10k_htt_tx_start(&ar->htt);
2535 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
2536 goto err_wmi_detach;
2539 /* If firmware indicates Full Rx Reorder support it must be used in a
2540 * slightly different manner. Let HTT code know.
2542 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
2545 status = ath10k_htt_rx_alloc(&ar->htt);
2547 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
2548 goto err_htt_tx_detach;
2551 status = ath10k_hif_start(ar);
2553 ath10k_err(ar, "could not start HIF: %d\n", status);
2554 goto err_htt_rx_detach;
2557 status = ath10k_htc_wait_target(&ar->htc);
2559 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
2563 status = ath10k_hif_swap_mailbox(ar);
2565 ath10k_err(ar, "failed to swap mailbox: %d\n", status);
2569 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2570 status = ath10k_htt_connect(&ar->htt);
2572 ath10k_err(ar, "failed to connect htt (%d)\n", status);
2577 status = ath10k_wmi_connect(ar);
2579 ath10k_err(ar, "could not connect wmi: %d\n", status);
2583 status = ath10k_htc_start(&ar->htc);
2585 ath10k_err(ar, "failed to start htc: %d\n", status);
2589 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2590 status = ath10k_wmi_wait_for_service_ready(ar);
2592 ath10k_warn(ar, "wmi service ready event not received");
2597 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
2598 ar->hw->wiphy->fw_version);
2600 if (test_bit(WMI_SERVICE_EXT_RES_CFG_SUPPORT, ar->wmi.svc_map) &&
2601 mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2603 if (ath10k_peer_stats_enabled(ar))
2604 val = WMI_10_4_PEER_STATS;
2606 /* Enable vdev stats by default */
2607 val |= WMI_10_4_VDEV_STATS;
2609 if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map))
2610 val |= WMI_10_4_BSS_CHANNEL_INFO_64;
2612 /* 10.4 firmware supports BT-Coex without reloading firmware
2613 * via pdev param. To support Bluetooth coexistence pdev param,
2614 * WMI_COEX_GPIO_SUPPORT of extended resource config should be
2617 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
2618 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
2619 ar->running_fw->fw_file.fw_features))
2620 val |= WMI_10_4_COEX_GPIO_SUPPORT;
2622 if (test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY,
2624 val |= WMI_10_4_TDLS_EXPLICIT_MODE_ONLY;
2626 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA,
2628 val |= WMI_10_4_TDLS_UAPSD_BUFFER_STA;
2630 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI,
2632 val |= WMI_10_4_TX_DATA_ACK_RSSI;
2634 status = ath10k_mac_ext_resource_config(ar, val);
2637 "failed to send ext resource cfg command : %d\n",
2643 status = ath10k_wmi_cmd_init(ar);
2645 ath10k_err(ar, "could not send WMI init command (%d)\n",
2650 status = ath10k_wmi_wait_for_unified_ready(ar);
2652 ath10k_err(ar, "wmi unified ready event not received\n");
2656 status = ath10k_core_compat_services(ar);
2658 ath10k_err(ar, "compat services failed: %d\n", status);
2662 status = ath10k_wmi_pdev_set_base_macaddr(ar, ar->mac_addr);
2663 if (status && status != -EOPNOTSUPP) {
2665 "failed to set base mac address: %d\n", status);
2669 /* Some firmware revisions do not properly set up hardware rx filter
2672 * A known example from QCA9880 and 10.2.4 is that MAC_PCU_ADDR1_MASK
2673 * is filled with 0s instead of 1s allowing HW to respond with ACKs to
2674 * any frames that matches MAC_PCU_RX_FILTER which is also
2675 * misconfigured to accept anything.
2677 * The ADDR1 is programmed using internal firmware structure field and
2678 * can't be (easily/sanely) reached from the driver explicitly. It is
2679 * possible to implicitly make it correct by creating a dummy vdev and
2682 if (ar->hw_params.hw_filter_reset_required &&
2683 mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2684 status = ath10k_core_reset_rx_filter(ar);
2687 "failed to reset rx filter: %d\n", status);
2692 status = ath10k_htt_rx_ring_refill(ar);
2694 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
2698 if (ar->max_num_vdevs >= 64)
2699 ar->free_vdev_map = 0xFFFFFFFFFFFFFFFFLL;
2701 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
2703 INIT_LIST_HEAD(&ar->arvifs);
2705 /* we don't care about HTT in UTF mode */
2706 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2707 status = ath10k_htt_setup(&ar->htt);
2709 ath10k_err(ar, "failed to setup htt: %d\n", status);
2714 status = ath10k_debug_start(ar);
2721 ath10k_hif_stop(ar);
2723 ath10k_htt_rx_free(&ar->htt);
2725 ath10k_htt_tx_free(&ar->htt);
2727 ath10k_wmi_detach(ar);
2731 EXPORT_SYMBOL(ath10k_core_start);
2733 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
2736 unsigned long time_left;
2738 reinit_completion(&ar->target_suspend);
2740 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
2742 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
2746 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
2749 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
2756 void ath10k_core_stop(struct ath10k *ar)
2758 lockdep_assert_held(&ar->conf_mutex);
2759 ath10k_debug_stop(ar);
2761 /* try to suspend target */
2762 if (ar->state != ATH10K_STATE_RESTARTING &&
2763 ar->state != ATH10K_STATE_UTF)
2764 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
2766 ath10k_hif_stop(ar);
2767 ath10k_htt_tx_stop(&ar->htt);
2768 ath10k_htt_rx_free(&ar->htt);
2769 ath10k_wmi_detach(ar);
2771 EXPORT_SYMBOL(ath10k_core_stop);
2773 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
2774 * order to know what hw capabilities should be advertised to mac80211 it is
2775 * necessary to load the firmware (and tear it down immediately since start
2776 * hook will try to init it again) before registering
2778 static int ath10k_core_probe_fw(struct ath10k *ar)
2780 struct bmi_target_info target_info;
2783 ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2785 ath10k_err(ar, "could not power on hif bus (%d)\n", ret);
2789 switch (ar->hif.bus) {
2790 case ATH10K_BUS_SDIO:
2791 memset(&target_info, 0, sizeof(target_info));
2792 ret = ath10k_bmi_get_target_info_sdio(ar, &target_info);
2794 ath10k_err(ar, "could not get target info (%d)\n", ret);
2795 goto err_power_down;
2797 ar->target_version = target_info.version;
2798 ar->hw->wiphy->hw_version = target_info.version;
2800 case ATH10K_BUS_PCI:
2801 case ATH10K_BUS_AHB:
2802 case ATH10K_BUS_USB:
2803 memset(&target_info, 0, sizeof(target_info));
2804 ret = ath10k_bmi_get_target_info(ar, &target_info);
2806 ath10k_err(ar, "could not get target info (%d)\n", ret);
2807 goto err_power_down;
2809 ar->target_version = target_info.version;
2810 ar->hw->wiphy->hw_version = target_info.version;
2812 case ATH10K_BUS_SNOC:
2813 memset(&target_info, 0, sizeof(target_info));
2814 ret = ath10k_hif_get_target_info(ar, &target_info);
2816 ath10k_err(ar, "could not get target info (%d)\n", ret);
2817 goto err_power_down;
2819 ar->target_version = target_info.version;
2820 ar->hw->wiphy->hw_version = target_info.version;
2823 ath10k_err(ar, "incorrect hif bus type: %d\n", ar->hif.bus);
2826 ret = ath10k_init_hw_params(ar);
2828 ath10k_err(ar, "could not get hw params (%d)\n", ret);
2829 goto err_power_down;
2832 ret = ath10k_core_fetch_firmware_files(ar);
2834 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
2835 goto err_power_down;
2838 BUILD_BUG_ON(sizeof(ar->hw->wiphy->fw_version) !=
2839 sizeof(ar->normal_mode_fw.fw_file.fw_version));
2840 memcpy(ar->hw->wiphy->fw_version, ar->normal_mode_fw.fw_file.fw_version,
2841 sizeof(ar->hw->wiphy->fw_version));
2843 ath10k_debug_print_hwfw_info(ar);
2845 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2846 ar->normal_mode_fw.fw_file.fw_features)) {
2847 ret = ath10k_core_pre_cal_download(ar);
2849 /* pre calibration data download is not necessary
2850 * for all the chipsets. Ignore failures and continue.
2852 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2853 "could not load pre cal data: %d\n", ret);
2856 ret = ath10k_core_get_board_id_from_otp(ar);
2857 if (ret && ret != -EOPNOTSUPP) {
2858 ath10k_err(ar, "failed to get board id from otp: %d\n",
2860 goto err_free_firmware_files;
2863 ret = ath10k_core_check_smbios(ar);
2865 ath10k_dbg(ar, ATH10K_DBG_BOOT, "SMBIOS bdf variant name not set.\n");
2867 ret = ath10k_core_check_dt(ar);
2869 ath10k_dbg(ar, ATH10K_DBG_BOOT, "DT bdf variant name not set.\n");
2871 ret = ath10k_core_fetch_board_file(ar, ATH10K_BD_IE_BOARD);
2873 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
2874 goto err_free_firmware_files;
2877 ath10k_debug_print_board_info(ar);
2880 device_get_mac_address(ar->dev, ar->mac_addr, sizeof(ar->mac_addr));
2882 ret = ath10k_core_init_firmware_features(ar);
2884 ath10k_err(ar, "fatal problem with firmware features: %d\n",
2886 goto err_free_firmware_files;
2889 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2890 ar->normal_mode_fw.fw_file.fw_features)) {
2891 ret = ath10k_swap_code_seg_init(ar,
2892 &ar->normal_mode_fw.fw_file);
2894 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
2896 goto err_free_firmware_files;
2900 mutex_lock(&ar->conf_mutex);
2902 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
2903 &ar->normal_mode_fw);
2905 ath10k_err(ar, "could not init core (%d)\n", ret);
2909 ath10k_debug_print_boot_info(ar);
2910 ath10k_core_stop(ar);
2912 mutex_unlock(&ar->conf_mutex);
2914 ath10k_hif_power_down(ar);
2918 mutex_unlock(&ar->conf_mutex);
2920 err_free_firmware_files:
2921 ath10k_core_free_firmware_files(ar);
2924 ath10k_hif_power_down(ar);
2929 static void ath10k_core_register_work(struct work_struct *work)
2931 struct ath10k *ar = container_of(work, struct ath10k, register_work);
2934 /* peer stats are enabled by default */
2935 set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2937 status = ath10k_core_probe_fw(ar);
2939 ath10k_err(ar, "could not probe fw (%d)\n", status);
2943 status = ath10k_mac_register(ar);
2945 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
2946 goto err_release_fw;
2949 status = ath10k_coredump_register(ar);
2951 ath10k_err(ar, "unable to register coredump\n");
2952 goto err_unregister_mac;
2955 status = ath10k_debug_register(ar);
2957 ath10k_err(ar, "unable to initialize debugfs\n");
2958 goto err_unregister_coredump;
2961 status = ath10k_spectral_create(ar);
2963 ath10k_err(ar, "failed to initialize spectral\n");
2964 goto err_debug_destroy;
2967 status = ath10k_thermal_register(ar);
2969 ath10k_err(ar, "could not register thermal device: %d\n",
2971 goto err_spectral_destroy;
2974 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
2977 err_spectral_destroy:
2978 ath10k_spectral_destroy(ar);
2980 ath10k_debug_destroy(ar);
2981 err_unregister_coredump:
2982 ath10k_coredump_unregister(ar);
2984 ath10k_mac_unregister(ar);
2986 ath10k_core_free_firmware_files(ar);
2988 /* TODO: It's probably a good idea to release device from the driver
2989 * but calling device_release_driver() here will cause a deadlock.
2994 int ath10k_core_register(struct ath10k *ar,
2995 const struct ath10k_bus_params *bus_params)
2997 ar->bus_param.chip_id = bus_params->chip_id;
2998 ar->bus_param.dev_type = bus_params->dev_type;
2999 ar->bus_param.link_can_suspend = bus_params->link_can_suspend;
3000 queue_work(ar->workqueue, &ar->register_work);
3004 EXPORT_SYMBOL(ath10k_core_register);
3006 void ath10k_core_unregister(struct ath10k *ar)
3008 cancel_work_sync(&ar->register_work);
3010 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
3013 ath10k_thermal_unregister(ar);
3014 /* Stop spectral before unregistering from mac80211 to remove the
3015 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
3016 * would be already be free'd recursively, leading to a double free.
3018 ath10k_spectral_destroy(ar);
3020 /* We must unregister from mac80211 before we stop HTC and HIF.
3021 * Otherwise we will fail to submit commands to FW and mac80211 will be
3022 * unhappy about callback failures.
3024 ath10k_mac_unregister(ar);
3026 ath10k_testmode_destroy(ar);
3028 ath10k_core_free_firmware_files(ar);
3029 ath10k_core_free_board_files(ar);
3031 ath10k_debug_unregister(ar);
3033 EXPORT_SYMBOL(ath10k_core_unregister);
3035 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
3036 enum ath10k_bus bus,
3037 enum ath10k_hw_rev hw_rev,
3038 const struct ath10k_hif_ops *hif_ops)
3043 ar = ath10k_mac_create(priv_size);
3047 ar->ath_common.priv = ar;
3048 ar->ath_common.hw = ar->hw;
3050 ar->hw_rev = hw_rev;
3051 ar->hif.ops = hif_ops;
3055 case ATH10K_HW_QCA988X:
3056 case ATH10K_HW_QCA9887:
3057 ar->regs = &qca988x_regs;
3058 ar->hw_ce_regs = &qcax_ce_regs;
3059 ar->hw_values = &qca988x_values;
3061 case ATH10K_HW_QCA6174:
3062 case ATH10K_HW_QCA9377:
3063 ar->regs = &qca6174_regs;
3064 ar->hw_ce_regs = &qcax_ce_regs;
3065 ar->hw_values = &qca6174_values;
3067 case ATH10K_HW_QCA99X0:
3068 case ATH10K_HW_QCA9984:
3069 ar->regs = &qca99x0_regs;
3070 ar->hw_ce_regs = &qcax_ce_regs;
3071 ar->hw_values = &qca99x0_values;
3073 case ATH10K_HW_QCA9888:
3074 ar->regs = &qca99x0_regs;
3075 ar->hw_ce_regs = &qcax_ce_regs;
3076 ar->hw_values = &qca9888_values;
3078 case ATH10K_HW_QCA4019:
3079 ar->regs = &qca4019_regs;
3080 ar->hw_ce_regs = &qcax_ce_regs;
3081 ar->hw_values = &qca4019_values;
3083 case ATH10K_HW_WCN3990:
3084 ar->regs = &wcn3990_regs;
3085 ar->hw_ce_regs = &wcn3990_ce_regs;
3086 ar->hw_values = &wcn3990_values;
3089 ath10k_err(ar, "unsupported core hardware revision %d\n",
3095 init_completion(&ar->scan.started);
3096 init_completion(&ar->scan.completed);
3097 init_completion(&ar->scan.on_channel);
3098 init_completion(&ar->target_suspend);
3099 init_completion(&ar->driver_recovery);
3100 init_completion(&ar->wow.wakeup_completed);
3102 init_completion(&ar->install_key_done);
3103 init_completion(&ar->vdev_setup_done);
3104 init_completion(&ar->thermal.wmi_sync);
3105 init_completion(&ar->bss_survey_done);
3107 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
3109 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
3113 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
3114 if (!ar->workqueue_aux)
3117 mutex_init(&ar->conf_mutex);
3118 spin_lock_init(&ar->data_lock);
3120 INIT_LIST_HEAD(&ar->peers);
3121 init_waitqueue_head(&ar->peer_mapping_wq);
3122 init_waitqueue_head(&ar->htt.empty_tx_wq);
3123 init_waitqueue_head(&ar->wmi.tx_credits_wq);
3125 init_completion(&ar->offchan_tx_completed);
3126 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
3127 skb_queue_head_init(&ar->offchan_tx_queue);
3129 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
3130 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
3132 INIT_WORK(&ar->register_work, ath10k_core_register_work);
3133 INIT_WORK(&ar->restart_work, ath10k_core_restart);
3134 INIT_WORK(&ar->set_coverage_class_work,
3135 ath10k_core_set_coverage_class_work);
3137 init_dummy_netdev(&ar->napi_dev);
3139 ret = ath10k_coredump_create(ar);
3141 goto err_free_aux_wq;
3143 ret = ath10k_debug_create(ar);
3145 goto err_free_coredump;
3150 ath10k_coredump_destroy(ar);
3153 destroy_workqueue(ar->workqueue_aux);
3155 destroy_workqueue(ar->workqueue);
3158 ath10k_mac_destroy(ar);
3162 EXPORT_SYMBOL(ath10k_core_create);
3164 void ath10k_core_destroy(struct ath10k *ar)
3166 flush_workqueue(ar->workqueue);
3167 destroy_workqueue(ar->workqueue);
3169 flush_workqueue(ar->workqueue_aux);
3170 destroy_workqueue(ar->workqueue_aux);
3172 ath10k_debug_destroy(ar);
3173 ath10k_coredump_destroy(ar);
3174 ath10k_htt_tx_destroy(&ar->htt);
3175 ath10k_wmi_free_host_mem(ar);
3176 ath10k_mac_destroy(ar);
3178 EXPORT_SYMBOL(ath10k_core_destroy);
3180 MODULE_AUTHOR("Qualcomm Atheros");
3181 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11ac wireless LAN cards.");
3182 MODULE_LICENSE("Dual BSD/GPL");