1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2005-2011 Atheros Communications Inc.
4 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
8 #include <linux/module.h>
9 #include <linux/firmware.h>
11 #include <linux/property.h>
12 #include <linux/dmi.h>
13 #include <linux/ctype.h>
14 #include <asm/byteorder.h>
28 unsigned int ath10k_debug_mask;
29 EXPORT_SYMBOL(ath10k_debug_mask);
31 static unsigned int ath10k_cryptmode_param;
32 static bool uart_print;
35 static bool fw_diag_log;
37 unsigned long ath10k_coredump_mask = BIT(ATH10K_FW_CRASH_DUMP_REGISTERS) |
38 BIT(ATH10K_FW_CRASH_DUMP_CE_DATA);
40 /* FIXME: most of these should be readonly */
41 module_param_named(debug_mask, ath10k_debug_mask, uint, 0644);
42 module_param_named(cryptmode, ath10k_cryptmode_param, uint, 0644);
43 module_param(uart_print, bool, 0644);
44 module_param(skip_otp, bool, 0644);
45 module_param(rawmode, bool, 0644);
46 module_param(fw_diag_log, bool, 0644);
47 module_param_named(coredump_mask, ath10k_coredump_mask, ulong, 0444);
49 MODULE_PARM_DESC(debug_mask, "Debugging mask");
50 MODULE_PARM_DESC(uart_print, "Uart target debugging");
51 MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode");
52 MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software");
53 MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath");
54 MODULE_PARM_DESC(coredump_mask, "Bitfield of what to include in firmware crash file");
55 MODULE_PARM_DESC(fw_diag_log, "Diag based fw log debugging");
57 static const struct ath10k_hw_params ath10k_hw_params_list[] = {
59 .id = QCA988X_HW_2_0_VERSION,
60 .dev_id = QCA988X_2_0_DEVICE_ID,
61 .bus = ATH10K_BUS_PCI,
62 .name = "qca988x hw2.0",
63 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
65 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
67 .channel_counters_freq_hz = 88000,
68 .max_probe_resp_desc_thres = 0,
71 .dir = QCA988X_HW_2_0_FW_DIR,
72 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
73 .board_size = QCA988X_BOARD_DATA_SZ,
74 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
76 .hw_ops = &qca988x_ops,
77 .decap_align_bytes = 4,
78 .spectral_bin_discard = 0,
79 .spectral_bin_offset = 0,
80 .vht160_mcs_rx_highest = 0,
81 .vht160_mcs_tx_highest = 0,
83 .ast_skid_limit = 0x10,
84 .num_wds_entries = 0x20,
85 .target_64bit = false,
86 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
87 .shadow_reg_support = false,
89 .hw_filter_reset_required = true,
90 .fw_diag_ce_download = false,
91 .tx_stats_over_pktlog = true,
94 .id = QCA988X_HW_2_0_VERSION,
95 .dev_id = QCA988X_2_0_DEVICE_ID_UBNT,
96 .name = "qca988x hw2.0 ubiquiti",
97 .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR,
99 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
101 .channel_counters_freq_hz = 88000,
102 .max_probe_resp_desc_thres = 0,
103 .cal_data_len = 2116,
105 .dir = QCA988X_HW_2_0_FW_DIR,
106 .board = QCA988X_HW_2_0_BOARD_DATA_FILE,
107 .board_size = QCA988X_BOARD_DATA_SZ,
108 .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ,
110 .hw_ops = &qca988x_ops,
111 .decap_align_bytes = 4,
112 .spectral_bin_discard = 0,
113 .spectral_bin_offset = 0,
114 .vht160_mcs_rx_highest = 0,
115 .vht160_mcs_tx_highest = 0,
116 .n_cipher_suites = 8,
117 .ast_skid_limit = 0x10,
118 .num_wds_entries = 0x20,
119 .target_64bit = false,
120 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
122 .shadow_reg_support = false,
124 .hw_filter_reset_required = true,
125 .fw_diag_ce_download = false,
126 .tx_stats_over_pktlog = true,
129 .id = QCA9887_HW_1_0_VERSION,
130 .dev_id = QCA9887_1_0_DEVICE_ID,
131 .bus = ATH10K_BUS_PCI,
132 .name = "qca9887 hw1.0",
133 .patch_load_addr = QCA9887_HW_1_0_PATCH_LOAD_ADDR,
135 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_ALL,
137 .channel_counters_freq_hz = 88000,
138 .max_probe_resp_desc_thres = 0,
139 .cal_data_len = 2116,
141 .dir = QCA9887_HW_1_0_FW_DIR,
142 .board = QCA9887_HW_1_0_BOARD_DATA_FILE,
143 .board_size = QCA9887_BOARD_DATA_SZ,
144 .board_ext_size = QCA9887_BOARD_EXT_DATA_SZ,
146 .hw_ops = &qca988x_ops,
147 .decap_align_bytes = 4,
148 .spectral_bin_discard = 0,
149 .spectral_bin_offset = 0,
150 .vht160_mcs_rx_highest = 0,
151 .vht160_mcs_tx_highest = 0,
152 .n_cipher_suites = 8,
153 .ast_skid_limit = 0x10,
154 .num_wds_entries = 0x20,
155 .target_64bit = false,
156 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
158 .shadow_reg_support = false,
160 .hw_filter_reset_required = true,
161 .fw_diag_ce_download = false,
162 .tx_stats_over_pktlog = false,
165 .id = QCA6174_HW_3_2_VERSION,
166 .dev_id = QCA6174_3_2_DEVICE_ID,
167 .bus = ATH10K_BUS_SDIO,
168 .name = "qca6174 hw3.2 sdio",
169 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
172 .channel_counters_freq_hz = 88000,
173 .max_probe_resp_desc_thres = 0,
176 .dir = QCA6174_HW_3_0_FW_DIR,
177 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
178 .board_size = QCA6174_BOARD_DATA_SZ,
179 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
181 .hw_ops = &qca6174_sdio_ops,
182 .hw_clk = qca6174_clk,
183 .target_cpu_freq = 176000000,
184 .decap_align_bytes = 4,
185 .n_cipher_suites = 8,
187 .ast_skid_limit = 0x10,
188 .num_wds_entries = 0x20,
189 .uart_pin_workaround = true,
190 .tx_stats_over_pktlog = false,
193 .id = QCA6174_HW_2_1_VERSION,
194 .dev_id = QCA6164_2_1_DEVICE_ID,
195 .bus = ATH10K_BUS_PCI,
196 .name = "qca6164 hw2.1",
197 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
200 .channel_counters_freq_hz = 88000,
201 .max_probe_resp_desc_thres = 0,
202 .cal_data_len = 8124,
204 .dir = QCA6174_HW_2_1_FW_DIR,
205 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
206 .board_size = QCA6174_BOARD_DATA_SZ,
207 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
209 .hw_ops = &qca988x_ops,
210 .decap_align_bytes = 4,
211 .spectral_bin_discard = 0,
212 .spectral_bin_offset = 0,
213 .vht160_mcs_rx_highest = 0,
214 .vht160_mcs_tx_highest = 0,
215 .n_cipher_suites = 8,
216 .ast_skid_limit = 0x10,
217 .num_wds_entries = 0x20,
218 .target_64bit = false,
219 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
221 .shadow_reg_support = false,
223 .hw_filter_reset_required = true,
224 .fw_diag_ce_download = false,
225 .tx_stats_over_pktlog = false,
228 .id = QCA6174_HW_2_1_VERSION,
229 .dev_id = QCA6174_2_1_DEVICE_ID,
230 .bus = ATH10K_BUS_PCI,
231 .name = "qca6174 hw2.1",
232 .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR,
235 .channel_counters_freq_hz = 88000,
236 .max_probe_resp_desc_thres = 0,
237 .cal_data_len = 8124,
239 .dir = QCA6174_HW_2_1_FW_DIR,
240 .board = QCA6174_HW_2_1_BOARD_DATA_FILE,
241 .board_size = QCA6174_BOARD_DATA_SZ,
242 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
244 .hw_ops = &qca988x_ops,
245 .decap_align_bytes = 4,
246 .spectral_bin_discard = 0,
247 .spectral_bin_offset = 0,
248 .vht160_mcs_rx_highest = 0,
249 .vht160_mcs_tx_highest = 0,
250 .n_cipher_suites = 8,
251 .ast_skid_limit = 0x10,
252 .num_wds_entries = 0x20,
253 .target_64bit = false,
254 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
256 .shadow_reg_support = false,
258 .hw_filter_reset_required = true,
259 .fw_diag_ce_download = false,
260 .tx_stats_over_pktlog = false,
263 .id = QCA6174_HW_3_0_VERSION,
264 .dev_id = QCA6174_2_1_DEVICE_ID,
265 .bus = ATH10K_BUS_PCI,
266 .name = "qca6174 hw3.0",
267 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
270 .channel_counters_freq_hz = 88000,
271 .max_probe_resp_desc_thres = 0,
272 .cal_data_len = 8124,
274 .dir = QCA6174_HW_3_0_FW_DIR,
275 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
276 .board_size = QCA6174_BOARD_DATA_SZ,
277 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
279 .hw_ops = &qca988x_ops,
280 .decap_align_bytes = 4,
281 .spectral_bin_discard = 0,
282 .spectral_bin_offset = 0,
283 .vht160_mcs_rx_highest = 0,
284 .vht160_mcs_tx_highest = 0,
285 .n_cipher_suites = 8,
286 .ast_skid_limit = 0x10,
287 .num_wds_entries = 0x20,
288 .target_64bit = false,
289 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
291 .shadow_reg_support = false,
293 .hw_filter_reset_required = true,
294 .fw_diag_ce_download = false,
295 .tx_stats_over_pktlog = false,
298 .id = QCA6174_HW_3_2_VERSION,
299 .dev_id = QCA6174_2_1_DEVICE_ID,
300 .bus = ATH10K_BUS_PCI,
301 .name = "qca6174 hw3.2",
302 .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR,
305 .channel_counters_freq_hz = 88000,
306 .max_probe_resp_desc_thres = 0,
307 .cal_data_len = 8124,
309 /* uses same binaries as hw3.0 */
310 .dir = QCA6174_HW_3_0_FW_DIR,
311 .board = QCA6174_HW_3_0_BOARD_DATA_FILE,
312 .board_size = QCA6174_BOARD_DATA_SZ,
313 .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ,
315 .hw_ops = &qca6174_ops,
316 .hw_clk = qca6174_clk,
317 .target_cpu_freq = 176000000,
318 .decap_align_bytes = 4,
319 .spectral_bin_discard = 0,
320 .spectral_bin_offset = 0,
321 .vht160_mcs_rx_highest = 0,
322 .vht160_mcs_tx_highest = 0,
323 .n_cipher_suites = 8,
324 .ast_skid_limit = 0x10,
325 .num_wds_entries = 0x20,
326 .target_64bit = false,
327 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
329 .shadow_reg_support = false,
331 .hw_filter_reset_required = true,
332 .fw_diag_ce_download = true,
333 .tx_stats_over_pktlog = false,
336 .id = QCA99X0_HW_2_0_DEV_VERSION,
337 .dev_id = QCA99X0_2_0_DEVICE_ID,
338 .bus = ATH10K_BUS_PCI,
339 .name = "qca99x0 hw2.0",
340 .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR,
342 .otp_exe_param = 0x00000700,
343 .continuous_frag_desc = true,
344 .cck_rate_map_rev2 = true,
345 .channel_counters_freq_hz = 150000,
346 .max_probe_resp_desc_thres = 24,
347 .tx_chain_mask = 0xf,
348 .rx_chain_mask = 0xf,
349 .max_spatial_stream = 4,
350 .cal_data_len = 12064,
352 .dir = QCA99X0_HW_2_0_FW_DIR,
353 .board = QCA99X0_HW_2_0_BOARD_DATA_FILE,
354 .board_size = QCA99X0_BOARD_DATA_SZ,
355 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
357 .sw_decrypt_mcast_mgmt = true,
358 .hw_ops = &qca99x0_ops,
359 .decap_align_bytes = 1,
360 .spectral_bin_discard = 4,
361 .spectral_bin_offset = 0,
362 .vht160_mcs_rx_highest = 0,
363 .vht160_mcs_tx_highest = 0,
364 .n_cipher_suites = 11,
365 .ast_skid_limit = 0x10,
366 .num_wds_entries = 0x20,
367 .target_64bit = false,
368 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
370 .shadow_reg_support = false,
372 .hw_filter_reset_required = true,
373 .fw_diag_ce_download = false,
374 .tx_stats_over_pktlog = false,
377 .id = QCA9984_HW_1_0_DEV_VERSION,
378 .dev_id = QCA9984_1_0_DEVICE_ID,
379 .bus = ATH10K_BUS_PCI,
380 .name = "qca9984/qca9994 hw1.0",
381 .patch_load_addr = QCA9984_HW_1_0_PATCH_LOAD_ADDR,
383 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
384 .otp_exe_param = 0x00000700,
385 .continuous_frag_desc = true,
386 .cck_rate_map_rev2 = true,
387 .channel_counters_freq_hz = 150000,
388 .max_probe_resp_desc_thres = 24,
389 .tx_chain_mask = 0xf,
390 .rx_chain_mask = 0xf,
391 .max_spatial_stream = 4,
392 .cal_data_len = 12064,
394 .dir = QCA9984_HW_1_0_FW_DIR,
395 .board = QCA9984_HW_1_0_BOARD_DATA_FILE,
396 .eboard = QCA9984_HW_1_0_EBOARD_DATA_FILE,
397 .board_size = QCA99X0_BOARD_DATA_SZ,
398 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
399 .ext_board_size = QCA99X0_EXT_BOARD_DATA_SZ,
401 .sw_decrypt_mcast_mgmt = true,
402 .hw_ops = &qca99x0_ops,
403 .decap_align_bytes = 1,
404 .spectral_bin_discard = 12,
405 .spectral_bin_offset = 8,
407 /* Can do only 2x2 VHT160 or 80+80. 1560Mbps is 4x4 80Mhz
408 * or 2x2 160Mhz, long-guard-interval.
410 .vht160_mcs_rx_highest = 1560,
411 .vht160_mcs_tx_highest = 1560,
412 .n_cipher_suites = 11,
413 .ast_skid_limit = 0x10,
414 .num_wds_entries = 0x20,
415 .target_64bit = false,
416 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
418 .shadow_reg_support = false,
420 .hw_filter_reset_required = true,
421 .fw_diag_ce_download = false,
422 .tx_stats_over_pktlog = false,
425 .id = QCA9888_HW_2_0_DEV_VERSION,
426 .dev_id = QCA9888_2_0_DEVICE_ID,
427 .bus = ATH10K_BUS_PCI,
428 .name = "qca9888 hw2.0",
429 .patch_load_addr = QCA9888_HW_2_0_PATCH_LOAD_ADDR,
431 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
432 .otp_exe_param = 0x00000700,
433 .continuous_frag_desc = true,
434 .channel_counters_freq_hz = 150000,
435 .max_probe_resp_desc_thres = 24,
438 .max_spatial_stream = 2,
439 .cal_data_len = 12064,
441 .dir = QCA9888_HW_2_0_FW_DIR,
442 .board = QCA9888_HW_2_0_BOARD_DATA_FILE,
443 .board_size = QCA99X0_BOARD_DATA_SZ,
444 .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ,
446 .sw_decrypt_mcast_mgmt = true,
447 .hw_ops = &qca99x0_ops,
448 .decap_align_bytes = 1,
449 .spectral_bin_discard = 12,
450 .spectral_bin_offset = 8,
452 /* Can do only 1x1 VHT160 or 80+80. 780Mbps is 2x2 80Mhz or
453 * 1x1 160Mhz, long-guard-interval.
455 .vht160_mcs_rx_highest = 780,
456 .vht160_mcs_tx_highest = 780,
457 .n_cipher_suites = 11,
458 .ast_skid_limit = 0x10,
459 .num_wds_entries = 0x20,
460 .target_64bit = false,
461 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
463 .shadow_reg_support = false,
465 .hw_filter_reset_required = true,
466 .fw_diag_ce_download = false,
467 .tx_stats_over_pktlog = false,
470 .id = QCA9377_HW_1_0_DEV_VERSION,
471 .dev_id = QCA9377_1_0_DEVICE_ID,
472 .bus = ATH10K_BUS_PCI,
473 .name = "qca9377 hw1.0",
474 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
477 .channel_counters_freq_hz = 88000,
478 .max_probe_resp_desc_thres = 0,
479 .cal_data_len = 8124,
481 .dir = QCA9377_HW_1_0_FW_DIR,
482 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
483 .board_size = QCA9377_BOARD_DATA_SZ,
484 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
486 .hw_ops = &qca988x_ops,
487 .decap_align_bytes = 4,
488 .spectral_bin_discard = 0,
489 .spectral_bin_offset = 0,
490 .vht160_mcs_rx_highest = 0,
491 .vht160_mcs_tx_highest = 0,
492 .n_cipher_suites = 8,
493 .ast_skid_limit = 0x10,
494 .num_wds_entries = 0x20,
495 .target_64bit = false,
496 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
498 .shadow_reg_support = false,
500 .hw_filter_reset_required = true,
501 .fw_diag_ce_download = false,
502 .tx_stats_over_pktlog = false,
505 .id = QCA9377_HW_1_1_DEV_VERSION,
506 .dev_id = QCA9377_1_0_DEVICE_ID,
507 .bus = ATH10K_BUS_PCI,
508 .name = "qca9377 hw1.1",
509 .patch_load_addr = QCA9377_HW_1_0_PATCH_LOAD_ADDR,
512 .channel_counters_freq_hz = 88000,
513 .max_probe_resp_desc_thres = 0,
514 .cal_data_len = 8124,
516 .dir = QCA9377_HW_1_0_FW_DIR,
517 .board = QCA9377_HW_1_0_BOARD_DATA_FILE,
518 .board_size = QCA9377_BOARD_DATA_SZ,
519 .board_ext_size = QCA9377_BOARD_EXT_DATA_SZ,
521 .hw_ops = &qca6174_ops,
522 .hw_clk = qca6174_clk,
523 .target_cpu_freq = 176000000,
524 .decap_align_bytes = 4,
525 .spectral_bin_discard = 0,
526 .spectral_bin_offset = 0,
527 .vht160_mcs_rx_highest = 0,
528 .vht160_mcs_tx_highest = 0,
529 .n_cipher_suites = 8,
530 .ast_skid_limit = 0x10,
531 .num_wds_entries = 0x20,
532 .target_64bit = false,
533 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
535 .shadow_reg_support = false,
537 .hw_filter_reset_required = true,
538 .fw_diag_ce_download = true,
539 .tx_stats_over_pktlog = false,
542 .id = QCA4019_HW_1_0_DEV_VERSION,
544 .bus = ATH10K_BUS_AHB,
545 .name = "qca4019 hw1.0",
546 .patch_load_addr = QCA4019_HW_1_0_PATCH_LOAD_ADDR,
548 .cc_wraparound_type = ATH10K_HW_CC_WRAP_SHIFTED_EACH,
549 .otp_exe_param = 0x0010000,
550 .continuous_frag_desc = true,
551 .cck_rate_map_rev2 = true,
552 .channel_counters_freq_hz = 125000,
553 .max_probe_resp_desc_thres = 24,
554 .tx_chain_mask = 0x3,
555 .rx_chain_mask = 0x3,
556 .max_spatial_stream = 2,
557 .cal_data_len = 12064,
559 .dir = QCA4019_HW_1_0_FW_DIR,
560 .board = QCA4019_HW_1_0_BOARD_DATA_FILE,
561 .board_size = QCA4019_BOARD_DATA_SZ,
562 .board_ext_size = QCA4019_BOARD_EXT_DATA_SZ,
564 .sw_decrypt_mcast_mgmt = true,
565 .hw_ops = &qca99x0_ops,
566 .decap_align_bytes = 1,
567 .spectral_bin_discard = 4,
568 .spectral_bin_offset = 0,
569 .vht160_mcs_rx_highest = 0,
570 .vht160_mcs_tx_highest = 0,
571 .n_cipher_suites = 11,
572 .ast_skid_limit = 0x10,
573 .num_wds_entries = 0x20,
574 .target_64bit = false,
575 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL,
577 .shadow_reg_support = false,
579 .hw_filter_reset_required = true,
580 .fw_diag_ce_download = false,
581 .tx_stats_over_pktlog = false,
584 .id = WCN3990_HW_1_0_DEV_VERSION,
586 .bus = ATH10K_BUS_SNOC,
587 .name = "wcn3990 hw1.0",
588 .continuous_frag_desc = true,
589 .tx_chain_mask = 0x7,
590 .rx_chain_mask = 0x7,
591 .max_spatial_stream = 4,
593 .dir = WCN3990_HW_1_0_FW_DIR,
595 .sw_decrypt_mcast_mgmt = true,
596 .hw_ops = &wcn3990_ops,
597 .decap_align_bytes = 1,
598 .num_peers = TARGET_HL_TLV_NUM_PEERS,
599 .n_cipher_suites = 11,
600 .ast_skid_limit = TARGET_HL_TLV_AST_SKID_LIMIT,
601 .num_wds_entries = TARGET_HL_TLV_NUM_WDS_ENTRIES,
602 .target_64bit = true,
603 .rx_ring_fill_level = HTT_RX_RING_FILL_LEVEL_DUAL_MAC,
605 .shadow_reg_support = true,
607 .hw_filter_reset_required = false,
608 .fw_diag_ce_download = false,
609 .tx_stats_over_pktlog = false,
613 static const char *const ath10k_core_fw_feature_str[] = {
614 [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx",
615 [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x",
616 [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx",
617 [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p",
618 [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2",
619 [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps",
620 [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan",
621 [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp",
622 [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad",
623 [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init",
624 [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode",
625 [ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA] = "adaptive-cca",
626 [ATH10K_FW_FEATURE_MFP_SUPPORT] = "mfp",
627 [ATH10K_FW_FEATURE_PEER_FLOW_CONTROL] = "peer-flow-ctrl",
628 [ATH10K_FW_FEATURE_BTCOEX_PARAM] = "btcoex-param",
629 [ATH10K_FW_FEATURE_SKIP_NULL_FUNC_WAR] = "skip-null-func-war",
630 [ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST] = "allows-mesh-bcast",
631 [ATH10K_FW_FEATURE_NO_PS] = "no-ps",
632 [ATH10K_FW_FEATURE_MGMT_TX_BY_REF] = "mgmt-tx-by-reference",
633 [ATH10K_FW_FEATURE_NON_BMI] = "non-bmi",
634 [ATH10K_FW_FEATURE_SINGLE_CHAN_INFO_PER_CHANNEL] = "single-chan-info-per-channel",
635 [ATH10K_FW_FEATURE_PEER_FIXED_RATE] = "peer-fixed-rate",
638 static unsigned int ath10k_core_get_fw_feature_str(char *buf,
640 enum ath10k_fw_features feat)
642 /* make sure that ath10k_core_fw_feature_str[] gets updated */
643 BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) !=
644 ATH10K_FW_FEATURE_COUNT);
646 if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) ||
647 WARN_ON(!ath10k_core_fw_feature_str[feat])) {
648 return scnprintf(buf, buf_len, "bit%d", feat);
651 return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
654 void ath10k_core_get_fw_features_str(struct ath10k *ar,
661 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
662 if (test_bit(i, ar->normal_mode_fw.fw_file.fw_features)) {
664 len += scnprintf(buf + len, buf_len - len, ",");
666 len += ath10k_core_get_fw_feature_str(buf + len,
673 static void ath10k_send_suspend_complete(struct ath10k *ar)
675 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n");
677 complete(&ar->target_suspend);
680 static void ath10k_init_sdio(struct ath10k *ar, enum ath10k_firmware_mode mode)
684 ath10k_bmi_write32(ar, hi_mbox_io_block_sz, 256);
685 ath10k_bmi_write32(ar, hi_mbox_isr_yield_limit, 99);
686 ath10k_bmi_read32(ar, hi_acs_flags, ¶m);
688 /* Data transfer is not initiated, when reduced Tx completion
689 * is used for SDIO. disable it until fixed
691 param &= ~HI_ACS_FLAGS_SDIO_REDUCE_TX_COMPL_SET;
693 /* Alternate credit size of 1544 as used by SDIO firmware is
694 * not big enough for mac80211 / native wifi frames. disable it
696 param &= ~HI_ACS_FLAGS_ALT_DATA_CREDIT_SIZE;
698 if (mode == ATH10K_FIRMWARE_MODE_UTF)
699 param &= ~HI_ACS_FLAGS_SDIO_SWAP_MAILBOX_SET;
701 param |= HI_ACS_FLAGS_SDIO_SWAP_MAILBOX_SET;
703 ath10k_bmi_write32(ar, hi_acs_flags, param);
705 /* Explicitly set fwlog prints to zero as target may turn it on
706 * based on scratch registers.
708 ath10k_bmi_read32(ar, hi_option_flag, ¶m);
709 param |= HI_OPTION_DISABLE_DBGLOG;
710 ath10k_bmi_write32(ar, hi_option_flag, param);
713 static int ath10k_init_configure_target(struct ath10k *ar)
718 /* tell target which HTC version it is used*/
719 ret = ath10k_bmi_write32(ar, hi_app_host_interest,
720 HTC_PROTOCOL_VERSION);
722 ath10k_err(ar, "settings HTC version failed\n");
726 /* set the firmware mode to STA/IBSS/AP */
727 ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host);
729 ath10k_err(ar, "setting firmware mode (1/2) failed\n");
733 /* TODO following parameters need to be re-visited. */
735 param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT);
737 /* FIXME: Why FW_MODE_AP ??.*/
738 param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT);
739 /* mac_addr_method */
740 param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
741 /* firmware_bridge */
742 param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
744 param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT);
746 ret = ath10k_bmi_write32(ar, hi_option_flag, param_host);
748 ath10k_err(ar, "setting firmware mode (2/2) failed\n");
752 /* We do all byte-swapping on the host */
753 ret = ath10k_bmi_write32(ar, hi_be, 0);
755 ath10k_err(ar, "setting host CPU BE mode failed\n");
759 /* FW descriptor/Data swap flags */
760 ret = ath10k_bmi_write32(ar, hi_fw_swap, 0);
763 ath10k_err(ar, "setting FW data/desc swap flags failed\n");
767 /* Some devices have a special sanity check that verifies the PCI
768 * Device ID is written to this host interest var. It is known to be
769 * required to boot QCA6164.
771 ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext,
774 ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret);
781 static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar,
786 const struct firmware *fw;
790 return ERR_PTR(-ENOENT);
795 snprintf(filename, sizeof(filename), "%s/%s", dir, file);
796 ret = firmware_request_nowarn(&fw, filename, ar->dev);
797 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot fw request '%s': %d\n",
806 static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data,
809 u32 board_data_size = ar->hw_params.fw.board_size;
810 u32 board_ext_data_size = ar->hw_params.fw.board_ext_size;
811 u32 board_ext_data_addr;
814 ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr);
816 ath10k_err(ar, "could not read board ext data addr (%d)\n",
821 ath10k_dbg(ar, ATH10K_DBG_BOOT,
822 "boot push board extended data addr 0x%x\n",
823 board_ext_data_addr);
825 if (board_ext_data_addr == 0)
828 if (data_len != (board_data_size + board_ext_data_size)) {
829 ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n",
830 data_len, board_data_size, board_ext_data_size);
834 ret = ath10k_bmi_write_memory(ar, board_ext_data_addr,
835 data + board_data_size,
836 board_ext_data_size);
838 ath10k_err(ar, "could not write board ext data (%d)\n", ret);
842 ret = ath10k_bmi_write32(ar, hi_board_ext_data_config,
843 (board_ext_data_size << 16) | 1);
845 ath10k_err(ar, "could not write board ext data bit (%d)\n",
853 static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
856 u8 board_id, chip_id;
857 bool ext_bid_support;
858 int ret, bmi_board_id_param;
860 address = ar->hw_params.patch_load_addr;
862 if (!ar->normal_mode_fw.fw_file.otp_data ||
863 !ar->normal_mode_fw.fw_file.otp_len) {
865 "failed to retrieve board id because of invalid otp\n");
869 ath10k_dbg(ar, ATH10K_DBG_BOOT,
870 "boot upload otp to 0x%x len %zd for board id\n",
871 address, ar->normal_mode_fw.fw_file.otp_len);
873 ret = ath10k_bmi_fast_download(ar, address,
874 ar->normal_mode_fw.fw_file.otp_data,
875 ar->normal_mode_fw.fw_file.otp_len);
877 ath10k_err(ar, "could not write otp for board id check: %d\n",
882 if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
883 ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
884 bmi_board_id_param = BMI_PARAM_GET_FLASH_BOARD_ID;
886 bmi_board_id_param = BMI_PARAM_GET_EEPROM_BOARD_ID;
888 ret = ath10k_bmi_execute(ar, address, bmi_board_id_param, &result);
890 ath10k_err(ar, "could not execute otp for board id check: %d\n",
895 board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP);
896 chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP);
897 ext_bid_support = (result & ATH10K_BMI_EXT_BOARD_ID_SUPPORT);
899 ath10k_dbg(ar, ATH10K_DBG_BOOT,
900 "boot get otp board id result 0x%08x board_id %d chip_id %d ext_bid_support %d\n",
901 result, board_id, chip_id, ext_bid_support);
903 ar->id.ext_bid_supported = ext_bid_support;
905 if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0 ||
907 ath10k_dbg(ar, ATH10K_DBG_BOOT,
908 "board id does not exist in otp, ignore it\n");
912 ar->id.bmi_ids_valid = true;
913 ar->id.bmi_board_id = board_id;
914 ar->id.bmi_chip_id = chip_id;
919 static void ath10k_core_check_bdfext(const struct dmi_header *hdr, void *data)
921 struct ath10k *ar = data;
923 const char *magic = ATH10K_SMBIOS_BDF_EXT_MAGIC;
927 if (hdr->type != ATH10K_SMBIOS_BDF_EXT_TYPE)
930 if (hdr->length != ATH10K_SMBIOS_BDF_EXT_LENGTH) {
931 ath10k_dbg(ar, ATH10K_DBG_BOOT,
932 "wrong smbios bdf ext type length (%d).\n",
937 bdf_enabled = *((u8 *)hdr + ATH10K_SMBIOS_BDF_EXT_OFFSET);
939 ath10k_dbg(ar, ATH10K_DBG_BOOT, "bdf variant name not found.\n");
943 /* Only one string exists (per spec) */
944 bdf_ext = (char *)hdr + hdr->length;
946 if (memcmp(bdf_ext, magic, strlen(magic)) != 0) {
947 ath10k_dbg(ar, ATH10K_DBG_BOOT,
948 "bdf variant magic does not match.\n");
952 for (i = 0; i < strlen(bdf_ext); i++) {
953 if (!isascii(bdf_ext[i]) || !isprint(bdf_ext[i])) {
954 ath10k_dbg(ar, ATH10K_DBG_BOOT,
955 "bdf variant name contains non ascii chars.\n");
960 /* Copy extension name without magic suffix */
961 if (strscpy(ar->id.bdf_ext, bdf_ext + strlen(magic),
962 sizeof(ar->id.bdf_ext)) < 0) {
963 ath10k_dbg(ar, ATH10K_DBG_BOOT,
964 "bdf variant string is longer than the buffer can accommodate (variant: %s)\n",
969 ath10k_dbg(ar, ATH10K_DBG_BOOT,
970 "found and validated bdf variant smbios_type 0x%x bdf %s\n",
971 ATH10K_SMBIOS_BDF_EXT_TYPE, bdf_ext);
974 static int ath10k_core_check_smbios(struct ath10k *ar)
976 ar->id.bdf_ext[0] = '\0';
977 dmi_walk(ath10k_core_check_bdfext, ar);
979 if (ar->id.bdf_ext[0] == '\0')
985 static int ath10k_core_check_dt(struct ath10k *ar)
987 struct device_node *node;
988 const char *variant = NULL;
990 node = ar->dev->of_node;
994 of_property_read_string(node, "qcom,ath10k-calibration-variant",
999 if (strscpy(ar->id.bdf_ext, variant, sizeof(ar->id.bdf_ext)) < 0)
1000 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1001 "bdf variant string is longer than the buffer can accommodate (variant: %s)\n",
1007 static int ath10k_download_fw(struct ath10k *ar)
1009 u32 address, data_len;
1013 address = ar->hw_params.patch_load_addr;
1015 data = ar->running_fw->fw_file.firmware_data;
1016 data_len = ar->running_fw->fw_file.firmware_len;
1018 ret = ath10k_swap_code_seg_configure(ar, &ar->running_fw->fw_file);
1020 ath10k_err(ar, "failed to configure fw code swap: %d\n",
1025 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1026 "boot uploading firmware image %pK len %d\n",
1029 /* Check if device supports to download firmware via
1030 * diag copy engine. Downloading firmware via diag CE
1031 * greatly reduces the time to download firmware.
1033 if (ar->hw_params.fw_diag_ce_download) {
1034 ret = ath10k_hw_diag_fast_download(ar, address,
1037 /* firmware upload via diag ce was successful */
1041 "failed to upload firmware via diag ce, trying BMI: %d",
1045 return ath10k_bmi_fast_download(ar, address,
1049 void ath10k_core_free_board_files(struct ath10k *ar)
1051 if (!IS_ERR(ar->normal_mode_fw.board))
1052 release_firmware(ar->normal_mode_fw.board);
1054 if (!IS_ERR(ar->normal_mode_fw.ext_board))
1055 release_firmware(ar->normal_mode_fw.ext_board);
1057 ar->normal_mode_fw.board = NULL;
1058 ar->normal_mode_fw.board_data = NULL;
1059 ar->normal_mode_fw.board_len = 0;
1060 ar->normal_mode_fw.ext_board = NULL;
1061 ar->normal_mode_fw.ext_board_data = NULL;
1062 ar->normal_mode_fw.ext_board_len = 0;
1064 EXPORT_SYMBOL(ath10k_core_free_board_files);
1066 static void ath10k_core_free_firmware_files(struct ath10k *ar)
1068 if (!IS_ERR(ar->normal_mode_fw.fw_file.firmware))
1069 release_firmware(ar->normal_mode_fw.fw_file.firmware);
1071 if (!IS_ERR(ar->cal_file))
1072 release_firmware(ar->cal_file);
1074 if (!IS_ERR(ar->pre_cal_file))
1075 release_firmware(ar->pre_cal_file);
1077 ath10k_swap_code_seg_release(ar, &ar->normal_mode_fw.fw_file);
1079 ar->normal_mode_fw.fw_file.otp_data = NULL;
1080 ar->normal_mode_fw.fw_file.otp_len = 0;
1082 ar->normal_mode_fw.fw_file.firmware = NULL;
1083 ar->normal_mode_fw.fw_file.firmware_data = NULL;
1084 ar->normal_mode_fw.fw_file.firmware_len = 0;
1086 ar->cal_file = NULL;
1087 ar->pre_cal_file = NULL;
1090 static int ath10k_fetch_cal_file(struct ath10k *ar)
1094 /* pre-cal-<bus>-<id>.bin */
1095 scnprintf(filename, sizeof(filename), "pre-cal-%s-%s.bin",
1096 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
1098 ar->pre_cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
1099 if (!IS_ERR(ar->pre_cal_file))
1102 /* cal-<bus>-<id>.bin */
1103 scnprintf(filename, sizeof(filename), "cal-%s-%s.bin",
1104 ath10k_bus_str(ar->hif.bus), dev_name(ar->dev));
1106 ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename);
1107 if (IS_ERR(ar->cal_file))
1108 /* calibration file is optional, don't print any warnings */
1109 return PTR_ERR(ar->cal_file);
1111 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n",
1112 ATH10K_FW_DIR, filename);
1117 static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar, int bd_ie_type)
1119 const struct firmware *fw;
1121 if (bd_ie_type == ATH10K_BD_IE_BOARD) {
1122 if (!ar->hw_params.fw.board) {
1123 ath10k_err(ar, "failed to find board file fw entry\n");
1127 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
1128 ar->hw_params.fw.dir,
1129 ar->hw_params.fw.board);
1130 if (IS_ERR(ar->normal_mode_fw.board))
1131 return PTR_ERR(ar->normal_mode_fw.board);
1133 ar->normal_mode_fw.board_data = ar->normal_mode_fw.board->data;
1134 ar->normal_mode_fw.board_len = ar->normal_mode_fw.board->size;
1135 } else if (bd_ie_type == ATH10K_BD_IE_BOARD_EXT) {
1136 if (!ar->hw_params.fw.eboard) {
1137 ath10k_err(ar, "failed to find eboard file fw entry\n");
1141 fw = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
1142 ar->hw_params.fw.eboard);
1143 ar->normal_mode_fw.ext_board = fw;
1144 if (IS_ERR(ar->normal_mode_fw.ext_board))
1145 return PTR_ERR(ar->normal_mode_fw.ext_board);
1147 ar->normal_mode_fw.ext_board_data = ar->normal_mode_fw.ext_board->data;
1148 ar->normal_mode_fw.ext_board_len = ar->normal_mode_fw.ext_board->size;
1154 static int ath10k_core_parse_bd_ie_board(struct ath10k *ar,
1155 const void *buf, size_t buf_len,
1156 const char *boardname,
1159 const struct ath10k_fw_ie *hdr;
1160 bool name_match_found;
1161 int ret, board_ie_id;
1162 size_t board_ie_len;
1163 const void *board_ie_data;
1165 name_match_found = false;
1167 /* go through ATH10K_BD_IE_BOARD_ elements */
1168 while (buf_len > sizeof(struct ath10k_fw_ie)) {
1170 board_ie_id = le32_to_cpu(hdr->id);
1171 board_ie_len = le32_to_cpu(hdr->len);
1172 board_ie_data = hdr->data;
1174 buf_len -= sizeof(*hdr);
1175 buf += sizeof(*hdr);
1177 if (buf_len < ALIGN(board_ie_len, 4)) {
1178 ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n",
1179 buf_len, ALIGN(board_ie_len, 4));
1184 switch (board_ie_id) {
1185 case ATH10K_BD_IE_BOARD_NAME:
1186 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "",
1187 board_ie_data, board_ie_len);
1189 if (board_ie_len != strlen(boardname))
1192 ret = memcmp(board_ie_data, boardname, strlen(boardname));
1196 name_match_found = true;
1197 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1198 "boot found match for name '%s'",
1201 case ATH10K_BD_IE_BOARD_DATA:
1202 if (!name_match_found)
1203 /* no match found */
1206 if (bd_ie_type == ATH10K_BD_IE_BOARD) {
1207 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1208 "boot found board data for '%s'",
1211 ar->normal_mode_fw.board_data = board_ie_data;
1212 ar->normal_mode_fw.board_len = board_ie_len;
1213 } else if (bd_ie_type == ATH10K_BD_IE_BOARD_EXT) {
1214 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1215 "boot found eboard data for '%s'",
1218 ar->normal_mode_fw.ext_board_data = board_ie_data;
1219 ar->normal_mode_fw.ext_board_len = board_ie_len;
1225 ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n",
1230 /* jump over the padding */
1231 board_ie_len = ALIGN(board_ie_len, 4);
1233 buf_len -= board_ie_len;
1234 buf += board_ie_len;
1237 /* no match found */
1244 static int ath10k_core_search_bd(struct ath10k *ar,
1245 const char *boardname,
1250 struct ath10k_fw_ie *hdr;
1251 int ret = -ENOENT, ie_id;
1253 while (len > sizeof(struct ath10k_fw_ie)) {
1254 hdr = (struct ath10k_fw_ie *)data;
1255 ie_id = le32_to_cpu(hdr->id);
1256 ie_len = le32_to_cpu(hdr->len);
1258 len -= sizeof(*hdr);
1261 if (len < ALIGN(ie_len, 4)) {
1262 ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n",
1263 ie_id, ie_len, len);
1268 case ATH10K_BD_IE_BOARD:
1269 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
1271 ATH10K_BD_IE_BOARD);
1273 /* no match found, continue */
1276 /* either found or error, so stop searching */
1278 case ATH10K_BD_IE_BOARD_EXT:
1279 ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len,
1281 ATH10K_BD_IE_BOARD_EXT);
1283 /* no match found, continue */
1286 /* either found or error, so stop searching */
1290 /* jump over the padding */
1291 ie_len = ALIGN(ie_len, 4);
1298 /* return result of parse_bd_ie_board() or -ENOENT */
1302 static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar,
1303 const char *boardname,
1304 const char *fallback_boardname,
1305 const char *filename)
1307 size_t len, magic_len;
1311 /* Skip if already fetched during board data download */
1312 if (!ar->normal_mode_fw.board)
1313 ar->normal_mode_fw.board = ath10k_fetch_fw_file(ar,
1314 ar->hw_params.fw.dir,
1316 if (IS_ERR(ar->normal_mode_fw.board))
1317 return PTR_ERR(ar->normal_mode_fw.board);
1319 data = ar->normal_mode_fw.board->data;
1320 len = ar->normal_mode_fw.board->size;
1322 /* magic has extra null byte padded */
1323 magic_len = strlen(ATH10K_BOARD_MAGIC) + 1;
1324 if (len < magic_len) {
1325 ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n",
1326 ar->hw_params.fw.dir, filename, len);
1331 if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) {
1332 ath10k_err(ar, "found invalid board magic\n");
1337 /* magic is padded to 4 bytes */
1338 magic_len = ALIGN(magic_len, 4);
1339 if (len < magic_len) {
1340 ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n",
1341 ar->hw_params.fw.dir, filename, len);
1349 /* attempt to find boardname in the IE list */
1350 ret = ath10k_core_search_bd(ar, boardname, data, len);
1352 /* if we didn't find it and have a fallback name, try that */
1353 if (ret == -ENOENT && fallback_boardname)
1354 ret = ath10k_core_search_bd(ar, fallback_boardname, data, len);
1356 if (ret == -ENOENT) {
1358 "failed to fetch board data for %s from %s/%s\n",
1359 boardname, ar->hw_params.fw.dir, filename);
1369 ath10k_core_free_board_files(ar);
1373 static int ath10k_core_create_board_name(struct ath10k *ar, char *name,
1374 size_t name_len, bool with_variant)
1376 /* strlen(',variant=') + strlen(ar->id.bdf_ext) */
1377 char variant[9 + ATH10K_SMBIOS_BDF_EXT_STR_LENGTH] = { 0 };
1379 if (with_variant && ar->id.bdf_ext[0] != '\0')
1380 scnprintf(variant, sizeof(variant), ",variant=%s",
1383 if (ar->id.bmi_ids_valid) {
1384 scnprintf(name, name_len,
1385 "bus=%s,bmi-chip-id=%d,bmi-board-id=%d%s",
1386 ath10k_bus_str(ar->hif.bus),
1388 ar->id.bmi_board_id, variant);
1392 if (ar->id.qmi_ids_valid) {
1393 scnprintf(name, name_len,
1394 "bus=%s,qmi-board-id=%x",
1395 ath10k_bus_str(ar->hif.bus),
1396 ar->id.qmi_board_id);
1400 scnprintf(name, name_len,
1401 "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x%s",
1402 ath10k_bus_str(ar->hif.bus),
1403 ar->id.vendor, ar->id.device,
1404 ar->id.subsystem_vendor, ar->id.subsystem_device, variant);
1406 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name);
1411 static int ath10k_core_create_eboard_name(struct ath10k *ar, char *name,
1414 if (ar->id.bmi_ids_valid) {
1415 scnprintf(name, name_len,
1416 "bus=%s,bmi-chip-id=%d,bmi-eboard-id=%d",
1417 ath10k_bus_str(ar->hif.bus),
1419 ar->id.bmi_eboard_id);
1421 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using eboard name '%s'\n", name);
1424 /* Fallback if returned board id is zero */
1428 int ath10k_core_fetch_board_file(struct ath10k *ar, int bd_ie_type)
1430 char boardname[100], fallback_boardname[100];
1433 if (bd_ie_type == ATH10K_BD_IE_BOARD) {
1434 ret = ath10k_core_create_board_name(ar, boardname,
1435 sizeof(boardname), true);
1437 ath10k_err(ar, "failed to create board name: %d", ret);
1441 ret = ath10k_core_create_board_name(ar, fallback_boardname,
1442 sizeof(boardname), false);
1444 ath10k_err(ar, "failed to create fallback board name: %d", ret);
1447 } else if (bd_ie_type == ATH10K_BD_IE_BOARD_EXT) {
1448 ret = ath10k_core_create_eboard_name(ar, boardname,
1451 ath10k_err(ar, "fallback to eboard.bin since board id 0");
1457 ret = ath10k_core_fetch_board_data_api_n(ar, boardname,
1459 ATH10K_BOARD_API2_FILE);
1465 ret = ath10k_core_fetch_board_data_api_1(ar, bd_ie_type);
1467 ath10k_err(ar, "failed to fetch board-2.bin or board.bin from %s\n",
1468 ar->hw_params.fw.dir);
1473 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api);
1476 EXPORT_SYMBOL(ath10k_core_fetch_board_file);
1478 static int ath10k_core_get_ext_board_id_from_otp(struct ath10k *ar)
1480 u32 result, address;
1484 address = ar->hw_params.patch_load_addr;
1486 if (!ar->normal_mode_fw.fw_file.otp_data ||
1487 !ar->normal_mode_fw.fw_file.otp_len) {
1489 "failed to retrieve extended board id due to otp binary missing\n");
1493 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1494 "boot upload otp to 0x%x len %zd for ext board id\n",
1495 address, ar->normal_mode_fw.fw_file.otp_len);
1497 ret = ath10k_bmi_fast_download(ar, address,
1498 ar->normal_mode_fw.fw_file.otp_data,
1499 ar->normal_mode_fw.fw_file.otp_len);
1501 ath10k_err(ar, "could not write otp for ext board id check: %d\n",
1506 ret = ath10k_bmi_execute(ar, address, BMI_PARAM_GET_EXT_BOARD_ID, &result);
1508 ath10k_err(ar, "could not execute otp for ext board id check: %d\n",
1514 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1515 "ext board id does not exist in otp, ignore it\n");
1519 ext_board_id = result & ATH10K_BMI_EBOARD_ID_STATUS_MASK;
1521 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1522 "boot get otp ext board id result 0x%08x ext_board_id %d\n",
1523 result, ext_board_id);
1525 ar->id.bmi_eboard_id = ext_board_id;
1530 static int ath10k_download_board_data(struct ath10k *ar, const void *data,
1533 u32 board_data_size = ar->hw_params.fw.board_size;
1534 u32 eboard_data_size = ar->hw_params.fw.ext_board_size;
1536 u32 ext_board_address;
1539 ret = ath10k_push_board_ext_data(ar, data, data_len);
1541 ath10k_err(ar, "could not push board ext data (%d)\n", ret);
1545 ret = ath10k_bmi_read32(ar, hi_board_data, &board_address);
1547 ath10k_err(ar, "could not read board data addr (%d)\n", ret);
1551 ret = ath10k_bmi_write_memory(ar, board_address, data,
1552 min_t(u32, board_data_size,
1555 ath10k_err(ar, "could not write board data (%d)\n", ret);
1559 ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1);
1561 ath10k_err(ar, "could not write board data bit (%d)\n", ret);
1565 if (!ar->id.ext_bid_supported)
1568 /* Extended board data download */
1569 ret = ath10k_core_get_ext_board_id_from_otp(ar);
1570 if (ret == -EOPNOTSUPP) {
1571 /* Not fetching ext_board_data if ext board id is 0 */
1572 ath10k_dbg(ar, ATH10K_DBG_BOOT, "otp returned ext board id 0\n");
1575 ath10k_err(ar, "failed to get extended board id: %d\n", ret);
1579 ret = ath10k_core_fetch_board_file(ar, ATH10K_BD_IE_BOARD_EXT);
1583 if (ar->normal_mode_fw.ext_board_data) {
1584 ext_board_address = board_address + EXT_BOARD_ADDRESS_OFFSET;
1585 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1586 "boot writing ext board data to addr 0x%x",
1588 ret = ath10k_bmi_write_memory(ar, ext_board_address,
1589 ar->normal_mode_fw.ext_board_data,
1590 min_t(u32, eboard_data_size, data_len));
1592 ath10k_err(ar, "failed to write ext board data: %d\n", ret);
1599 static int ath10k_download_and_run_otp(struct ath10k *ar)
1601 u32 result, address = ar->hw_params.patch_load_addr;
1602 u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param;
1605 ret = ath10k_download_board_data(ar,
1606 ar->running_fw->board_data,
1607 ar->running_fw->board_len);
1609 ath10k_err(ar, "failed to download board data: %d\n", ret);
1613 /* OTP is optional */
1615 if (!ar->running_fw->fw_file.otp_data ||
1616 !ar->running_fw->fw_file.otp_len) {
1617 ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %pK otp_len %zd)!\n",
1618 ar->running_fw->fw_file.otp_data,
1619 ar->running_fw->fw_file.otp_len);
1623 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n",
1624 address, ar->running_fw->fw_file.otp_len);
1626 ret = ath10k_bmi_fast_download(ar, address,
1627 ar->running_fw->fw_file.otp_data,
1628 ar->running_fw->fw_file.otp_len);
1630 ath10k_err(ar, "could not write otp (%d)\n", ret);
1634 /* As of now pre-cal is valid for 10_4 variants */
1635 if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
1636 ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
1637 bmi_otp_exe_param = BMI_PARAM_FLASH_SECTION_ALL;
1639 ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
1641 ath10k_err(ar, "could not execute otp (%d)\n", ret);
1645 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result);
1647 if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT,
1648 ar->running_fw->fw_file.fw_features)) &&
1650 ath10k_err(ar, "otp calibration failed: %d", result);
1657 static int ath10k_download_cal_file(struct ath10k *ar,
1658 const struct firmware *file)
1666 return PTR_ERR(file);
1668 ret = ath10k_download_board_data(ar, file->data, file->size);
1670 ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
1674 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
1679 static int ath10k_download_cal_dt(struct ath10k *ar, const char *dt_name)
1681 struct device_node *node;
1686 node = ar->dev->of_node;
1688 /* Device Tree is optional, don't print any warnings if
1689 * there's no node for ath10k.
1693 if (!of_get_property(node, dt_name, &data_len)) {
1694 /* The calibration data node is optional */
1698 if (data_len != ar->hw_params.cal_data_len) {
1699 ath10k_warn(ar, "invalid calibration data length in DT: %d\n",
1705 data = kmalloc(data_len, GFP_KERNEL);
1711 ret = of_property_read_u8_array(node, dt_name, data, data_len);
1713 ath10k_warn(ar, "failed to read calibration data from DT: %d\n",
1718 ret = ath10k_download_board_data(ar, data, data_len);
1720 ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n",
1734 static int ath10k_download_cal_eeprom(struct ath10k *ar)
1740 ret = ath10k_hif_fetch_cal_eeprom(ar, &data, &data_len);
1742 if (ret != -EOPNOTSUPP)
1743 ath10k_warn(ar, "failed to read calibration data from EEPROM: %d\n",
1748 ret = ath10k_download_board_data(ar, data, data_len);
1750 ath10k_warn(ar, "failed to download calibration data from EEPROM: %d\n",
1763 int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name,
1764 struct ath10k_fw_file *fw_file)
1766 size_t magic_len, len, ie_len;
1767 int ie_id, i, index, bit, ret;
1768 struct ath10k_fw_ie *hdr;
1770 __le32 *timestamp, *version;
1772 /* first fetch the firmware file (firmware-*.bin) */
1773 fw_file->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir,
1775 if (IS_ERR(fw_file->firmware))
1776 return PTR_ERR(fw_file->firmware);
1778 data = fw_file->firmware->data;
1779 len = fw_file->firmware->size;
1781 /* magic also includes the null byte, check that as well */
1782 magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1;
1784 if (len < magic_len) {
1785 ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n",
1786 ar->hw_params.fw.dir, name, len);
1791 if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) {
1792 ath10k_err(ar, "invalid firmware magic\n");
1797 /* jump over the padding */
1798 magic_len = ALIGN(magic_len, 4);
1804 while (len > sizeof(struct ath10k_fw_ie)) {
1805 hdr = (struct ath10k_fw_ie *)data;
1807 ie_id = le32_to_cpu(hdr->id);
1808 ie_len = le32_to_cpu(hdr->len);
1810 len -= sizeof(*hdr);
1811 data += sizeof(*hdr);
1814 ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n",
1815 ie_id, len, ie_len);
1821 case ATH10K_FW_IE_FW_VERSION:
1822 if (ie_len > sizeof(fw_file->fw_version) - 1)
1825 memcpy(fw_file->fw_version, data, ie_len);
1826 fw_file->fw_version[ie_len] = '\0';
1828 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1829 "found fw version %s\n",
1830 fw_file->fw_version);
1832 case ATH10K_FW_IE_TIMESTAMP:
1833 if (ie_len != sizeof(u32))
1836 timestamp = (__le32 *)data;
1838 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n",
1839 le32_to_cpup(timestamp));
1841 case ATH10K_FW_IE_FEATURES:
1842 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1843 "found firmware features ie (%zd B)\n",
1846 for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) {
1850 if (index == ie_len)
1853 if (data[index] & (1 << bit)) {
1854 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1855 "Enabling feature bit: %i\n",
1857 __set_bit(i, fw_file->fw_features);
1861 ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "",
1862 fw_file->fw_features,
1863 sizeof(fw_file->fw_features));
1865 case ATH10K_FW_IE_FW_IMAGE:
1866 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1867 "found fw image ie (%zd B)\n",
1870 fw_file->firmware_data = data;
1871 fw_file->firmware_len = ie_len;
1874 case ATH10K_FW_IE_OTP_IMAGE:
1875 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1876 "found otp image ie (%zd B)\n",
1879 fw_file->otp_data = data;
1880 fw_file->otp_len = ie_len;
1883 case ATH10K_FW_IE_WMI_OP_VERSION:
1884 if (ie_len != sizeof(u32))
1887 version = (__le32 *)data;
1889 fw_file->wmi_op_version = le32_to_cpup(version);
1891 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n",
1892 fw_file->wmi_op_version);
1894 case ATH10K_FW_IE_HTT_OP_VERSION:
1895 if (ie_len != sizeof(u32))
1898 version = (__le32 *)data;
1900 fw_file->htt_op_version = le32_to_cpup(version);
1902 ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n",
1903 fw_file->htt_op_version);
1905 case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
1906 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1907 "found fw code swap image ie (%zd B)\n",
1909 fw_file->codeswap_data = data;
1910 fw_file->codeswap_len = ie_len;
1913 ath10k_warn(ar, "Unknown FW IE: %u\n",
1914 le32_to_cpu(hdr->id));
1918 /* jump over the padding */
1919 ie_len = ALIGN(ie_len, 4);
1925 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI, fw_file->fw_features) &&
1926 (!fw_file->firmware_data || !fw_file->firmware_len)) {
1927 ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n",
1928 ar->hw_params.fw.dir, name);
1936 ath10k_core_free_firmware_files(ar);
1940 static void ath10k_core_get_fw_name(struct ath10k *ar, char *fw_name,
1941 size_t fw_name_len, int fw_api)
1943 switch (ar->hif.bus) {
1944 case ATH10K_BUS_SDIO:
1945 case ATH10K_BUS_USB:
1946 scnprintf(fw_name, fw_name_len, "%s-%s-%d.bin",
1947 ATH10K_FW_FILE_BASE, ath10k_bus_str(ar->hif.bus),
1950 case ATH10K_BUS_PCI:
1951 case ATH10K_BUS_AHB:
1952 case ATH10K_BUS_SNOC:
1953 scnprintf(fw_name, fw_name_len, "%s-%d.bin",
1954 ATH10K_FW_FILE_BASE, fw_api);
1959 static int ath10k_core_fetch_firmware_files(struct ath10k *ar)
1964 /* calibration file is optional, don't check for any errors */
1965 ath10k_fetch_cal_file(ar);
1967 for (i = ATH10K_FW_API_MAX; i >= ATH10K_FW_API_MIN; i--) {
1969 ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n",
1972 ath10k_core_get_fw_name(ar, fw_name, sizeof(fw_name), ar->fw_api);
1973 ret = ath10k_core_fetch_firmware_api_n(ar, fw_name,
1974 &ar->normal_mode_fw.fw_file);
1979 /* we end up here if we couldn't fetch any firmware */
1981 ath10k_err(ar, "Failed to find firmware-N.bin (N between %d and %d) from %s: %d",
1982 ATH10K_FW_API_MIN, ATH10K_FW_API_MAX, ar->hw_params.fw.dir,
1988 ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1993 static int ath10k_core_pre_cal_download(struct ath10k *ar)
1997 ret = ath10k_download_cal_file(ar, ar->pre_cal_file);
1999 ar->cal_mode = ATH10K_PRE_CAL_MODE_FILE;
2003 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2004 "boot did not find a pre calibration file, try DT next: %d\n",
2007 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-pre-calibration-data");
2009 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2010 "unable to load pre cal data from DT: %d\n", ret);
2013 ar->cal_mode = ATH10K_PRE_CAL_MODE_DT;
2016 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
2017 ath10k_cal_mode_str(ar->cal_mode));
2022 static int ath10k_core_pre_cal_config(struct ath10k *ar)
2026 ret = ath10k_core_pre_cal_download(ar);
2028 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2029 "failed to load pre cal data: %d\n", ret);
2033 ret = ath10k_core_get_board_id_from_otp(ar);
2035 ath10k_err(ar, "failed to get board id: %d\n", ret);
2039 ret = ath10k_download_and_run_otp(ar);
2041 ath10k_err(ar, "failed to run otp: %d\n", ret);
2045 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2046 "pre cal configuration done successfully\n");
2051 static int ath10k_download_cal_data(struct ath10k *ar)
2055 ret = ath10k_core_pre_cal_config(ar);
2059 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2060 "pre cal download procedure failed, try cal file: %d\n",
2063 ret = ath10k_download_cal_file(ar, ar->cal_file);
2065 ar->cal_mode = ATH10K_CAL_MODE_FILE;
2069 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2070 "boot did not find a calibration file, try DT next: %d\n",
2073 ret = ath10k_download_cal_dt(ar, "qcom,ath10k-calibration-data");
2075 ar->cal_mode = ATH10K_CAL_MODE_DT;
2079 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2080 "boot did not find DT entry, try target EEPROM next: %d\n",
2083 ret = ath10k_download_cal_eeprom(ar);
2085 ar->cal_mode = ATH10K_CAL_MODE_EEPROM;
2089 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2090 "boot did not find target EEPROM entry, try OTP next: %d\n",
2093 ret = ath10k_download_and_run_otp(ar);
2095 ath10k_err(ar, "failed to run otp: %d\n", ret);
2099 ar->cal_mode = ATH10K_CAL_MODE_OTP;
2102 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n",
2103 ath10k_cal_mode_str(ar->cal_mode));
2107 static int ath10k_init_uart(struct ath10k *ar)
2112 * Explicitly setting UART prints to zero as target turns it on
2113 * based on scratch registers.
2115 ret = ath10k_bmi_write32(ar, hi_serial_enable, 0);
2117 ath10k_warn(ar, "could not disable UART prints (%d)\n", ret);
2121 if (!uart_print && ar->hw_params.uart_pin_workaround) {
2122 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin,
2123 ar->hw_params.uart_pin);
2125 ath10k_warn(ar, "failed to set UART TX pin: %d", ret);
2132 ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin);
2134 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
2138 ret = ath10k_bmi_write32(ar, hi_serial_enable, 1);
2140 ath10k_warn(ar, "could not enable UART prints (%d)\n", ret);
2144 /* Set the UART baud rate to 19200. */
2145 ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200);
2147 ath10k_warn(ar, "could not set the baud rate (%d)\n", ret);
2151 ath10k_info(ar, "UART prints enabled\n");
2155 static int ath10k_init_hw_params(struct ath10k *ar)
2157 const struct ath10k_hw_params *uninitialized_var(hw_params);
2160 for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) {
2161 hw_params = &ath10k_hw_params_list[i];
2163 if (hw_params->bus == ar->hif.bus &&
2164 hw_params->id == ar->target_version &&
2165 hw_params->dev_id == ar->dev_id)
2169 if (i == ARRAY_SIZE(ath10k_hw_params_list)) {
2170 ath10k_err(ar, "Unsupported hardware version: 0x%x\n",
2171 ar->target_version);
2175 ar->hw_params = *hw_params;
2177 ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n",
2178 ar->hw_params.name, ar->target_version);
2183 static void ath10k_core_restart(struct work_struct *work)
2185 struct ath10k *ar = container_of(work, struct ath10k, restart_work);
2188 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
2190 /* Place a barrier to make sure the compiler doesn't reorder
2191 * CRASH_FLUSH and calling other functions.
2195 ieee80211_stop_queues(ar->hw);
2196 ath10k_drain_tx(ar);
2197 complete(&ar->scan.started);
2198 complete(&ar->scan.completed);
2199 complete(&ar->scan.on_channel);
2200 complete(&ar->offchan_tx_completed);
2201 complete(&ar->install_key_done);
2202 complete(&ar->vdev_setup_done);
2203 complete(&ar->vdev_delete_done);
2204 complete(&ar->thermal.wmi_sync);
2205 complete(&ar->bss_survey_done);
2206 wake_up(&ar->htt.empty_tx_wq);
2207 wake_up(&ar->wmi.tx_credits_wq);
2208 wake_up(&ar->peer_mapping_wq);
2210 /* TODO: We can have one instance of cancelling coverage_class_work by
2211 * moving it to ath10k_halt(), so that both stop() and restart() would
2212 * call that but it takes conf_mutex() and if we call cancel_work_sync()
2213 * with conf_mutex it will deadlock.
2215 cancel_work_sync(&ar->set_coverage_class_work);
2217 mutex_lock(&ar->conf_mutex);
2219 switch (ar->state) {
2220 case ATH10K_STATE_ON:
2221 ar->state = ATH10K_STATE_RESTARTING;
2223 ath10k_scan_finish(ar);
2224 ieee80211_restart_hw(ar->hw);
2226 case ATH10K_STATE_OFF:
2227 /* this can happen if driver is being unloaded
2228 * or if the crash happens during FW probing
2230 ath10k_warn(ar, "cannot restart a device that hasn't been started\n");
2232 case ATH10K_STATE_RESTARTING:
2233 /* hw restart might be requested from multiple places */
2235 case ATH10K_STATE_RESTARTED:
2236 ar->state = ATH10K_STATE_WEDGED;
2238 case ATH10K_STATE_WEDGED:
2239 ath10k_warn(ar, "device is wedged, will not restart\n");
2241 case ATH10K_STATE_UTF:
2242 ath10k_warn(ar, "firmware restart in UTF mode not supported\n");
2246 mutex_unlock(&ar->conf_mutex);
2248 ret = ath10k_coredump_submit(ar);
2250 ath10k_warn(ar, "failed to send firmware crash dump via devcoredump: %d",
2253 complete(&ar->driver_recovery);
2256 static void ath10k_core_set_coverage_class_work(struct work_struct *work)
2258 struct ath10k *ar = container_of(work, struct ath10k,
2259 set_coverage_class_work);
2261 if (ar->hw_params.hw_ops->set_coverage_class)
2262 ar->hw_params.hw_ops->set_coverage_class(ar, -1);
2265 static int ath10k_core_init_firmware_features(struct ath10k *ar)
2267 struct ath10k_fw_file *fw_file = &ar->normal_mode_fw.fw_file;
2270 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, fw_file->fw_features) &&
2271 !test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
2272 ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well");
2276 if (fw_file->wmi_op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) {
2277 ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n",
2278 ATH10K_FW_WMI_OP_VERSION_MAX, fw_file->wmi_op_version);
2282 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI;
2283 switch (ath10k_cryptmode_param) {
2284 case ATH10K_CRYPT_MODE_HW:
2285 clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
2286 clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
2288 case ATH10K_CRYPT_MODE_SW:
2289 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
2290 fw_file->fw_features)) {
2291 ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware");
2295 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
2296 set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags);
2299 ath10k_info(ar, "invalid cryptmode: %d\n",
2300 ath10k_cryptmode_param);
2304 ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT;
2305 ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT;
2308 if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT,
2309 fw_file->fw_features)) {
2310 ath10k_err(ar, "rawmode = 1 requires support from firmware");
2313 set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags);
2316 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
2317 ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW;
2321 * Firmware A-MSDU aggregation breaks with RAW Tx encap mode
2322 * and causes enormous performance issues (malformed frames,
2325 * Disabling A-MSDU makes RAW mode stable with heavy traffic
2326 * albeit a bit slower compared to regular operation.
2328 ar->htt.max_num_amsdu = 1;
2331 /* Backwards compatibility for firmwares without
2332 * ATH10K_FW_IE_WMI_OP_VERSION.
2334 if (fw_file->wmi_op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) {
2335 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, fw_file->fw_features)) {
2336 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2,
2337 fw_file->fw_features))
2338 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_2;
2340 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_10_1;
2342 fw_file->wmi_op_version = ATH10K_FW_WMI_OP_VERSION_MAIN;
2346 switch (fw_file->wmi_op_version) {
2347 case ATH10K_FW_WMI_OP_VERSION_MAIN:
2348 max_num_peers = TARGET_NUM_PEERS;
2349 ar->max_num_stations = TARGET_NUM_STATIONS;
2350 ar->max_num_vdevs = TARGET_NUM_VDEVS;
2351 ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC;
2352 ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV |
2354 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
2356 case ATH10K_FW_WMI_OP_VERSION_10_1:
2357 case ATH10K_FW_WMI_OP_VERSION_10_2:
2358 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
2359 if (ath10k_peer_stats_enabled(ar)) {
2360 max_num_peers = TARGET_10X_TX_STATS_NUM_PEERS;
2361 ar->max_num_stations = TARGET_10X_TX_STATS_NUM_STATIONS;
2363 max_num_peers = TARGET_10X_NUM_PEERS;
2364 ar->max_num_stations = TARGET_10X_NUM_STATIONS;
2366 ar->max_num_vdevs = TARGET_10X_NUM_VDEVS;
2367 ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC;
2368 ar->fw_stats_req_mask = WMI_STAT_PEER;
2369 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
2371 case ATH10K_FW_WMI_OP_VERSION_TLV:
2372 max_num_peers = TARGET_TLV_NUM_PEERS;
2373 ar->max_num_stations = TARGET_TLV_NUM_STATIONS;
2374 ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS;
2375 ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS;
2376 if (ar->hif.bus == ATH10K_BUS_SDIO)
2377 ar->htt.max_num_pending_tx =
2378 TARGET_TLV_NUM_MSDU_DESC_HL;
2380 ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC;
2381 ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS;
2382 ar->fw_stats_req_mask = WMI_TLV_STAT_PDEV | WMI_TLV_STAT_VDEV |
2383 WMI_TLV_STAT_PEER | WMI_TLV_STAT_PEER_EXTD;
2384 ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM;
2385 ar->wmi.mgmt_max_num_pending_tx = TARGET_TLV_MGMT_NUM_MSDU_DESC;
2387 case ATH10K_FW_WMI_OP_VERSION_10_4:
2388 max_num_peers = TARGET_10_4_NUM_PEERS;
2389 ar->max_num_stations = TARGET_10_4_NUM_STATIONS;
2390 ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS;
2391 ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS;
2392 ar->num_tids = TARGET_10_4_TGT_NUM_TIDS;
2393 ar->fw_stats_req_mask = WMI_10_4_STAT_PEER |
2394 WMI_10_4_STAT_PEER_EXTD |
2395 WMI_10_4_STAT_VDEV_EXTD;
2396 ar->max_spatial_stream = ar->hw_params.max_spatial_stream;
2397 ar->max_num_tdls_vdevs = TARGET_10_4_NUM_TDLS_VDEVS;
2399 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
2400 fw_file->fw_features))
2401 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC_PFC;
2403 ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC;
2405 case ATH10K_FW_WMI_OP_VERSION_UNSET:
2406 case ATH10K_FW_WMI_OP_VERSION_MAX:
2412 if (ar->hw_params.num_peers)
2413 ar->max_num_peers = ar->hw_params.num_peers;
2415 ar->max_num_peers = max_num_peers;
2417 /* Backwards compatibility for firmwares without
2418 * ATH10K_FW_IE_HTT_OP_VERSION.
2420 if (fw_file->htt_op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) {
2421 switch (fw_file->wmi_op_version) {
2422 case ATH10K_FW_WMI_OP_VERSION_MAIN:
2423 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_MAIN;
2425 case ATH10K_FW_WMI_OP_VERSION_10_1:
2426 case ATH10K_FW_WMI_OP_VERSION_10_2:
2427 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
2428 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_10_1;
2430 case ATH10K_FW_WMI_OP_VERSION_TLV:
2431 fw_file->htt_op_version = ATH10K_FW_HTT_OP_VERSION_TLV;
2433 case ATH10K_FW_WMI_OP_VERSION_10_4:
2434 case ATH10K_FW_WMI_OP_VERSION_UNSET:
2435 case ATH10K_FW_WMI_OP_VERSION_MAX:
2436 ath10k_err(ar, "htt op version not found from fw meta data");
2444 static int ath10k_core_reset_rx_filter(struct ath10k *ar)
2450 const u8 *vdev_addr;
2453 vdev_type = WMI_VDEV_TYPE_STA;
2454 vdev_subtype = ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
2455 vdev_addr = ar->mac_addr;
2457 ret = ath10k_wmi_vdev_create(ar, vdev_id, vdev_type, vdev_subtype,
2460 ath10k_err(ar, "failed to create dummy vdev: %d\n", ret);
2464 ret = ath10k_wmi_vdev_delete(ar, vdev_id);
2466 ath10k_err(ar, "failed to delete dummy vdev: %d\n", ret);
2470 /* WMI and HTT may use separate HIF pipes and are not guaranteed to be
2471 * serialized properly implicitly.
2473 * Moreover (most) WMI commands have no explicit acknowledges. It is
2474 * possible to infer it implicitly by poking firmware with echo
2475 * command - getting a reply means all preceding comments have been
2476 * (mostly) processed.
2478 * In case of vdev create/delete this is sufficient.
2480 * Without this it's possible to end up with a race when HTT Rx ring is
2481 * started before vdev create/delete hack is complete allowing a short
2482 * window of opportunity to receive (and Tx ACK) a bunch of frames.
2484 ret = ath10k_wmi_barrier(ar);
2486 ath10k_err(ar, "failed to ping firmware: %d\n", ret);
2493 static int ath10k_core_compat_services(struct ath10k *ar)
2495 struct ath10k_fw_file *fw_file = &ar->normal_mode_fw.fw_file;
2497 /* all 10.x firmware versions support thermal throttling but don't
2498 * advertise the support via service flags so we have to hardcode
2501 switch (fw_file->wmi_op_version) {
2502 case ATH10K_FW_WMI_OP_VERSION_10_1:
2503 case ATH10K_FW_WMI_OP_VERSION_10_2:
2504 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
2505 case ATH10K_FW_WMI_OP_VERSION_10_4:
2506 set_bit(WMI_SERVICE_THERM_THROT, ar->wmi.svc_map);
2515 int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode,
2516 const struct ath10k_fw_components *fw)
2521 lockdep_assert_held(&ar->conf_mutex);
2523 clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
2525 ar->running_fw = fw;
2527 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2528 ar->running_fw->fw_file.fw_features)) {
2529 ath10k_bmi_start(ar);
2531 if (ath10k_init_configure_target(ar)) {
2536 status = ath10k_download_cal_data(ar);
2540 /* Some of of qca988x solutions are having global reset issue
2541 * during target initialization. Bypassing PLL setting before
2542 * downloading firmware and letting the SoC run on REF_CLK is
2543 * fixing the problem. Corresponding firmware change is also
2544 * needed to set the clock source once the target is
2547 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT,
2548 ar->running_fw->fw_file.fw_features)) {
2549 status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1);
2551 ath10k_err(ar, "could not write to skip_clock_init: %d\n",
2557 status = ath10k_download_fw(ar);
2561 status = ath10k_init_uart(ar);
2565 if (ar->hif.bus == ATH10K_BUS_SDIO)
2566 ath10k_init_sdio(ar, mode);
2569 ar->htc.htc_ops.target_send_suspend_complete =
2570 ath10k_send_suspend_complete;
2572 status = ath10k_htc_init(ar);
2574 ath10k_err(ar, "could not init HTC (%d)\n", status);
2578 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2579 ar->running_fw->fw_file.fw_features)) {
2580 status = ath10k_bmi_done(ar);
2585 status = ath10k_wmi_attach(ar);
2587 ath10k_err(ar, "WMI attach failed: %d\n", status);
2591 status = ath10k_htt_init(ar);
2593 ath10k_err(ar, "failed to init htt: %d\n", status);
2594 goto err_wmi_detach;
2597 status = ath10k_htt_tx_start(&ar->htt);
2599 ath10k_err(ar, "failed to alloc htt tx: %d\n", status);
2600 goto err_wmi_detach;
2603 /* If firmware indicates Full Rx Reorder support it must be used in a
2604 * slightly different manner. Let HTT code know.
2606 ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER,
2609 status = ath10k_htt_rx_alloc(&ar->htt);
2611 ath10k_err(ar, "failed to alloc htt rx: %d\n", status);
2612 goto err_htt_tx_detach;
2615 status = ath10k_hif_start(ar);
2617 ath10k_err(ar, "could not start HIF: %d\n", status);
2618 goto err_htt_rx_detach;
2621 status = ath10k_htc_wait_target(&ar->htc);
2623 ath10k_err(ar, "failed to connect to HTC: %d\n", status);
2627 status = ath10k_hif_swap_mailbox(ar);
2629 ath10k_err(ar, "failed to swap mailbox: %d\n", status);
2633 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2634 status = ath10k_htt_connect(&ar->htt);
2636 ath10k_err(ar, "failed to connect htt (%d)\n", status);
2641 status = ath10k_wmi_connect(ar);
2643 ath10k_err(ar, "could not connect wmi: %d\n", status);
2647 status = ath10k_htc_start(&ar->htc);
2649 ath10k_err(ar, "failed to start htc: %d\n", status);
2653 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2654 status = ath10k_wmi_wait_for_service_ready(ar);
2656 ath10k_warn(ar, "wmi service ready event not received");
2661 ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n",
2662 ar->hw->wiphy->fw_version);
2664 if (test_bit(WMI_SERVICE_EXT_RES_CFG_SUPPORT, ar->wmi.svc_map) &&
2665 mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2667 if (ath10k_peer_stats_enabled(ar))
2668 val = WMI_10_4_PEER_STATS;
2670 /* Enable vdev stats by default */
2671 val |= WMI_10_4_VDEV_STATS;
2673 if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map))
2674 val |= WMI_10_4_BSS_CHANNEL_INFO_64;
2676 /* 10.4 firmware supports BT-Coex without reloading firmware
2677 * via pdev param. To support Bluetooth coexistence pdev param,
2678 * WMI_COEX_GPIO_SUPPORT of extended resource config should be
2681 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
2682 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
2683 ar->running_fw->fw_file.fw_features))
2684 val |= WMI_10_4_COEX_GPIO_SUPPORT;
2686 if (test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY,
2688 val |= WMI_10_4_TDLS_EXPLICIT_MODE_ONLY;
2690 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA,
2692 val |= WMI_10_4_TDLS_UAPSD_BUFFER_STA;
2694 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI,
2696 val |= WMI_10_4_TX_DATA_ACK_RSSI;
2698 if (test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
2699 val |= WMI_10_4_REPORT_AIRTIME;
2701 status = ath10k_mac_ext_resource_config(ar, val);
2704 "failed to send ext resource cfg command : %d\n",
2710 status = ath10k_wmi_cmd_init(ar);
2712 ath10k_err(ar, "could not send WMI init command (%d)\n",
2717 status = ath10k_wmi_wait_for_unified_ready(ar);
2719 ath10k_err(ar, "wmi unified ready event not received\n");
2723 status = ath10k_core_compat_services(ar);
2725 ath10k_err(ar, "compat services failed: %d\n", status);
2729 status = ath10k_wmi_pdev_set_base_macaddr(ar, ar->mac_addr);
2730 if (status && status != -EOPNOTSUPP) {
2732 "failed to set base mac address: %d\n", status);
2736 /* Some firmware revisions do not properly set up hardware rx filter
2739 * A known example from QCA9880 and 10.2.4 is that MAC_PCU_ADDR1_MASK
2740 * is filled with 0s instead of 1s allowing HW to respond with ACKs to
2741 * any frames that matches MAC_PCU_RX_FILTER which is also
2742 * misconfigured to accept anything.
2744 * The ADDR1 is programmed using internal firmware structure field and
2745 * can't be (easily/sanely) reached from the driver explicitly. It is
2746 * possible to implicitly make it correct by creating a dummy vdev and
2749 if (ar->hw_params.hw_filter_reset_required &&
2750 mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2751 status = ath10k_core_reset_rx_filter(ar);
2754 "failed to reset rx filter: %d\n", status);
2759 status = ath10k_htt_rx_ring_refill(ar);
2761 ath10k_err(ar, "failed to refill htt rx ring: %d\n", status);
2765 if (ar->max_num_vdevs >= 64)
2766 ar->free_vdev_map = 0xFFFFFFFFFFFFFFFFLL;
2768 ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1;
2770 INIT_LIST_HEAD(&ar->arvifs);
2772 /* we don't care about HTT in UTF mode */
2773 if (mode == ATH10K_FIRMWARE_MODE_NORMAL) {
2774 status = ath10k_htt_setup(&ar->htt);
2776 ath10k_err(ar, "failed to setup htt: %d\n", status);
2781 status = ath10k_debug_start(ar);
2785 status = ath10k_hif_set_target_log_mode(ar, fw_diag_log);
2786 if (status && status != -EOPNOTSUPP) {
2787 ath10k_warn(ar, "set traget log mode faileds: %d\n", status);
2794 ath10k_hif_stop(ar);
2796 ath10k_htt_rx_free(&ar->htt);
2798 ath10k_htt_tx_free(&ar->htt);
2800 ath10k_wmi_detach(ar);
2804 EXPORT_SYMBOL(ath10k_core_start);
2806 int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt)
2809 unsigned long time_left;
2811 reinit_completion(&ar->target_suspend);
2813 ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt);
2815 ath10k_warn(ar, "could not suspend target (%d)\n", ret);
2819 time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ);
2822 ath10k_warn(ar, "suspend timed out - target pause event never came\n");
2829 void ath10k_core_stop(struct ath10k *ar)
2831 lockdep_assert_held(&ar->conf_mutex);
2832 ath10k_debug_stop(ar);
2834 /* try to suspend target */
2835 if (ar->state != ATH10K_STATE_RESTARTING &&
2836 ar->state != ATH10K_STATE_UTF)
2837 ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR);
2839 ath10k_hif_stop(ar);
2840 ath10k_htt_tx_stop(&ar->htt);
2841 ath10k_htt_rx_free(&ar->htt);
2842 ath10k_wmi_detach(ar);
2844 EXPORT_SYMBOL(ath10k_core_stop);
2846 /* mac80211 manages fw/hw initialization through start/stop hooks. However in
2847 * order to know what hw capabilities should be advertised to mac80211 it is
2848 * necessary to load the firmware (and tear it down immediately since start
2849 * hook will try to init it again) before registering
2851 static int ath10k_core_probe_fw(struct ath10k *ar)
2853 struct bmi_target_info target_info;
2856 ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2858 ath10k_err(ar, "could not power on hif bus (%d)\n", ret);
2862 switch (ar->hif.bus) {
2863 case ATH10K_BUS_SDIO:
2864 memset(&target_info, 0, sizeof(target_info));
2865 ret = ath10k_bmi_get_target_info_sdio(ar, &target_info);
2867 ath10k_err(ar, "could not get target info (%d)\n", ret);
2868 goto err_power_down;
2870 ar->target_version = target_info.version;
2871 ar->hw->wiphy->hw_version = target_info.version;
2873 case ATH10K_BUS_PCI:
2874 case ATH10K_BUS_AHB:
2875 case ATH10K_BUS_USB:
2876 memset(&target_info, 0, sizeof(target_info));
2877 ret = ath10k_bmi_get_target_info(ar, &target_info);
2879 ath10k_err(ar, "could not get target info (%d)\n", ret);
2880 goto err_power_down;
2882 ar->target_version = target_info.version;
2883 ar->hw->wiphy->hw_version = target_info.version;
2885 case ATH10K_BUS_SNOC:
2886 memset(&target_info, 0, sizeof(target_info));
2887 ret = ath10k_hif_get_target_info(ar, &target_info);
2889 ath10k_err(ar, "could not get target info (%d)\n", ret);
2890 goto err_power_down;
2892 ar->target_version = target_info.version;
2893 ar->hw->wiphy->hw_version = target_info.version;
2896 ath10k_err(ar, "incorrect hif bus type: %d\n", ar->hif.bus);
2899 ret = ath10k_init_hw_params(ar);
2901 ath10k_err(ar, "could not get hw params (%d)\n", ret);
2902 goto err_power_down;
2905 ret = ath10k_core_fetch_firmware_files(ar);
2907 ath10k_err(ar, "could not fetch firmware files (%d)\n", ret);
2908 goto err_power_down;
2911 BUILD_BUG_ON(sizeof(ar->hw->wiphy->fw_version) !=
2912 sizeof(ar->normal_mode_fw.fw_file.fw_version));
2913 memcpy(ar->hw->wiphy->fw_version, ar->normal_mode_fw.fw_file.fw_version,
2914 sizeof(ar->hw->wiphy->fw_version));
2916 ath10k_debug_print_hwfw_info(ar);
2918 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2919 ar->normal_mode_fw.fw_file.fw_features)) {
2920 ret = ath10k_core_pre_cal_download(ar);
2922 /* pre calibration data download is not necessary
2923 * for all the chipsets. Ignore failures and continue.
2925 ath10k_dbg(ar, ATH10K_DBG_BOOT,
2926 "could not load pre cal data: %d\n", ret);
2929 ret = ath10k_core_get_board_id_from_otp(ar);
2930 if (ret && ret != -EOPNOTSUPP) {
2931 ath10k_err(ar, "failed to get board id from otp: %d\n",
2933 goto err_free_firmware_files;
2936 ret = ath10k_core_check_smbios(ar);
2938 ath10k_dbg(ar, ATH10K_DBG_BOOT, "SMBIOS bdf variant name not set.\n");
2940 ret = ath10k_core_check_dt(ar);
2942 ath10k_dbg(ar, ATH10K_DBG_BOOT, "DT bdf variant name not set.\n");
2944 ret = ath10k_core_fetch_board_file(ar, ATH10K_BD_IE_BOARD);
2946 ath10k_err(ar, "failed to fetch board file: %d\n", ret);
2947 goto err_free_firmware_files;
2950 ath10k_debug_print_board_info(ar);
2953 device_get_mac_address(ar->dev, ar->mac_addr, sizeof(ar->mac_addr));
2955 ret = ath10k_core_init_firmware_features(ar);
2957 ath10k_err(ar, "fatal problem with firmware features: %d\n",
2959 goto err_free_firmware_files;
2962 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI,
2963 ar->normal_mode_fw.fw_file.fw_features)) {
2964 ret = ath10k_swap_code_seg_init(ar,
2965 &ar->normal_mode_fw.fw_file);
2967 ath10k_err(ar, "failed to initialize code swap segment: %d\n",
2969 goto err_free_firmware_files;
2973 mutex_lock(&ar->conf_mutex);
2975 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
2976 &ar->normal_mode_fw);
2978 ath10k_err(ar, "could not init core (%d)\n", ret);
2982 ath10k_debug_print_boot_info(ar);
2983 ath10k_core_stop(ar);
2985 mutex_unlock(&ar->conf_mutex);
2987 ath10k_hif_power_down(ar);
2991 mutex_unlock(&ar->conf_mutex);
2993 err_free_firmware_files:
2994 ath10k_core_free_firmware_files(ar);
2997 ath10k_hif_power_down(ar);
3002 static void ath10k_core_register_work(struct work_struct *work)
3004 struct ath10k *ar = container_of(work, struct ath10k, register_work);
3007 /* peer stats are enabled by default */
3008 set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
3010 status = ath10k_core_probe_fw(ar);
3012 ath10k_err(ar, "could not probe fw (%d)\n", status);
3016 status = ath10k_mac_register(ar);
3018 ath10k_err(ar, "could not register to mac80211 (%d)\n", status);
3019 goto err_release_fw;
3022 status = ath10k_coredump_register(ar);
3024 ath10k_err(ar, "unable to register coredump\n");
3025 goto err_unregister_mac;
3028 status = ath10k_debug_register(ar);
3030 ath10k_err(ar, "unable to initialize debugfs\n");
3031 goto err_unregister_coredump;
3034 status = ath10k_spectral_create(ar);
3036 ath10k_err(ar, "failed to initialize spectral\n");
3037 goto err_debug_destroy;
3040 status = ath10k_thermal_register(ar);
3042 ath10k_err(ar, "could not register thermal device: %d\n",
3044 goto err_spectral_destroy;
3047 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
3050 err_spectral_destroy:
3051 ath10k_spectral_destroy(ar);
3053 ath10k_debug_destroy(ar);
3054 err_unregister_coredump:
3055 ath10k_coredump_unregister(ar);
3057 ath10k_mac_unregister(ar);
3059 ath10k_core_free_firmware_files(ar);
3061 /* TODO: It's probably a good idea to release device from the driver
3062 * but calling device_release_driver() here will cause a deadlock.
3067 int ath10k_core_register(struct ath10k *ar,
3068 const struct ath10k_bus_params *bus_params)
3070 ar->bus_param = *bus_params;
3072 queue_work(ar->workqueue, &ar->register_work);
3076 EXPORT_SYMBOL(ath10k_core_register);
3078 void ath10k_core_unregister(struct ath10k *ar)
3080 cancel_work_sync(&ar->register_work);
3082 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
3085 ath10k_thermal_unregister(ar);
3086 /* Stop spectral before unregistering from mac80211 to remove the
3087 * relayfs debugfs file cleanly. Otherwise the parent debugfs tree
3088 * would be already be free'd recursively, leading to a double free.
3090 ath10k_spectral_destroy(ar);
3092 /* We must unregister from mac80211 before we stop HTC and HIF.
3093 * Otherwise we will fail to submit commands to FW and mac80211 will be
3094 * unhappy about callback failures.
3096 ath10k_mac_unregister(ar);
3098 ath10k_testmode_destroy(ar);
3100 ath10k_core_free_firmware_files(ar);
3101 ath10k_core_free_board_files(ar);
3103 ath10k_debug_unregister(ar);
3105 EXPORT_SYMBOL(ath10k_core_unregister);
3107 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
3108 enum ath10k_bus bus,
3109 enum ath10k_hw_rev hw_rev,
3110 const struct ath10k_hif_ops *hif_ops)
3115 ar = ath10k_mac_create(priv_size);
3119 ar->ath_common.priv = ar;
3120 ar->ath_common.hw = ar->hw;
3122 ar->hw_rev = hw_rev;
3123 ar->hif.ops = hif_ops;
3127 case ATH10K_HW_QCA988X:
3128 case ATH10K_HW_QCA9887:
3129 ar->regs = &qca988x_regs;
3130 ar->hw_ce_regs = &qcax_ce_regs;
3131 ar->hw_values = &qca988x_values;
3133 case ATH10K_HW_QCA6174:
3134 case ATH10K_HW_QCA9377:
3135 ar->regs = &qca6174_regs;
3136 ar->hw_ce_regs = &qcax_ce_regs;
3137 ar->hw_values = &qca6174_values;
3139 case ATH10K_HW_QCA99X0:
3140 case ATH10K_HW_QCA9984:
3141 ar->regs = &qca99x0_regs;
3142 ar->hw_ce_regs = &qcax_ce_regs;
3143 ar->hw_values = &qca99x0_values;
3145 case ATH10K_HW_QCA9888:
3146 ar->regs = &qca99x0_regs;
3147 ar->hw_ce_regs = &qcax_ce_regs;
3148 ar->hw_values = &qca9888_values;
3150 case ATH10K_HW_QCA4019:
3151 ar->regs = &qca4019_regs;
3152 ar->hw_ce_regs = &qcax_ce_regs;
3153 ar->hw_values = &qca4019_values;
3155 case ATH10K_HW_WCN3990:
3156 ar->regs = &wcn3990_regs;
3157 ar->hw_ce_regs = &wcn3990_ce_regs;
3158 ar->hw_values = &wcn3990_values;
3161 ath10k_err(ar, "unsupported core hardware revision %d\n",
3167 init_completion(&ar->scan.started);
3168 init_completion(&ar->scan.completed);
3169 init_completion(&ar->scan.on_channel);
3170 init_completion(&ar->target_suspend);
3171 init_completion(&ar->driver_recovery);
3172 init_completion(&ar->wow.wakeup_completed);
3174 init_completion(&ar->install_key_done);
3175 init_completion(&ar->vdev_setup_done);
3176 init_completion(&ar->vdev_delete_done);
3177 init_completion(&ar->thermal.wmi_sync);
3178 init_completion(&ar->bss_survey_done);
3179 init_completion(&ar->peer_delete_done);
3181 INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work);
3183 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
3187 ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq");
3188 if (!ar->workqueue_aux)
3191 mutex_init(&ar->conf_mutex);
3192 mutex_init(&ar->dump_mutex);
3193 spin_lock_init(&ar->data_lock);
3195 INIT_LIST_HEAD(&ar->peers);
3196 init_waitqueue_head(&ar->peer_mapping_wq);
3197 init_waitqueue_head(&ar->htt.empty_tx_wq);
3198 init_waitqueue_head(&ar->wmi.tx_credits_wq);
3200 init_completion(&ar->offchan_tx_completed);
3201 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
3202 skb_queue_head_init(&ar->offchan_tx_queue);
3204 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
3205 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
3207 INIT_WORK(&ar->register_work, ath10k_core_register_work);
3208 INIT_WORK(&ar->restart_work, ath10k_core_restart);
3209 INIT_WORK(&ar->set_coverage_class_work,
3210 ath10k_core_set_coverage_class_work);
3212 init_dummy_netdev(&ar->napi_dev);
3214 ret = ath10k_coredump_create(ar);
3216 goto err_free_aux_wq;
3218 ret = ath10k_debug_create(ar);
3220 goto err_free_coredump;
3225 ath10k_coredump_destroy(ar);
3228 destroy_workqueue(ar->workqueue_aux);
3230 destroy_workqueue(ar->workqueue);
3233 ath10k_mac_destroy(ar);
3237 EXPORT_SYMBOL(ath10k_core_create);
3239 void ath10k_core_destroy(struct ath10k *ar)
3241 flush_workqueue(ar->workqueue);
3242 destroy_workqueue(ar->workqueue);
3244 flush_workqueue(ar->workqueue_aux);
3245 destroy_workqueue(ar->workqueue_aux);
3247 ath10k_debug_destroy(ar);
3248 ath10k_coredump_destroy(ar);
3249 ath10k_htt_tx_destroy(&ar->htt);
3250 ath10k_wmi_free_host_mem(ar);
3251 ath10k_mac_destroy(ar);
3253 EXPORT_SYMBOL(ath10k_core_destroy);
3255 MODULE_AUTHOR("Qualcomm Atheros");
3256 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11ac wireless LAN cards.");
3257 MODULE_LICENSE("Dual BSD/GPL");