1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2014-2017 Qualcomm Atheros, Inc.
6 #include <linux/types.h>
7 #include <linux/bitops.h>
8 #include <linux/bitfield.h>
16 const struct ath10k_hw_regs qca988x_regs = {
17 .rtc_soc_base_address = 0x00004000,
18 .rtc_wmac_base_address = 0x00005000,
19 .soc_core_base_address = 0x00009000,
20 .wlan_mac_base_address = 0x00020000,
21 .ce_wrapper_base_address = 0x00057000,
22 .ce0_base_address = 0x00057400,
23 .ce1_base_address = 0x00057800,
24 .ce2_base_address = 0x00057c00,
25 .ce3_base_address = 0x00058000,
26 .ce4_base_address = 0x00058400,
27 .ce5_base_address = 0x00058800,
28 .ce6_base_address = 0x00058c00,
29 .ce7_base_address = 0x00059000,
30 .soc_reset_control_si0_rst_mask = 0x00000001,
31 .soc_reset_control_ce_rst_mask = 0x00040000,
32 .soc_chip_id_address = 0x000000ec,
33 .scratch_3_address = 0x00000030,
34 .fw_indicator_address = 0x00009030,
35 .pcie_local_base_address = 0x00080000,
36 .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
37 .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
38 .pcie_intr_fw_mask = 0x00000400,
39 .pcie_intr_ce_mask_all = 0x0007f800,
40 .pcie_intr_clr_address = 0x00000014,
43 const struct ath10k_hw_regs qca6174_regs = {
44 .rtc_soc_base_address = 0x00000800,
45 .rtc_wmac_base_address = 0x00001000,
46 .soc_core_base_address = 0x0003a000,
47 .wlan_mac_base_address = 0x00010000,
48 .ce_wrapper_base_address = 0x00034000,
49 .ce0_base_address = 0x00034400,
50 .ce1_base_address = 0x00034800,
51 .ce2_base_address = 0x00034c00,
52 .ce3_base_address = 0x00035000,
53 .ce4_base_address = 0x00035400,
54 .ce5_base_address = 0x00035800,
55 .ce6_base_address = 0x00035c00,
56 .ce7_base_address = 0x00036000,
57 .soc_reset_control_si0_rst_mask = 0x00000000,
58 .soc_reset_control_ce_rst_mask = 0x00000001,
59 .soc_chip_id_address = 0x000000f0,
60 .scratch_3_address = 0x00000028,
61 .fw_indicator_address = 0x0003a028,
62 .pcie_local_base_address = 0x00080000,
63 .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
64 .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
65 .pcie_intr_fw_mask = 0x00000400,
66 .pcie_intr_ce_mask_all = 0x0007f800,
67 .pcie_intr_clr_address = 0x00000014,
68 .cpu_pll_init_address = 0x00404020,
69 .cpu_speed_address = 0x00404024,
70 .core_clk_div_address = 0x00404028,
73 const struct ath10k_hw_regs qca99x0_regs = {
74 .rtc_soc_base_address = 0x00080000,
75 .rtc_wmac_base_address = 0x00000000,
76 .soc_core_base_address = 0x00082000,
77 .wlan_mac_base_address = 0x00030000,
78 .ce_wrapper_base_address = 0x0004d000,
79 .ce0_base_address = 0x0004a000,
80 .ce1_base_address = 0x0004a400,
81 .ce2_base_address = 0x0004a800,
82 .ce3_base_address = 0x0004ac00,
83 .ce4_base_address = 0x0004b000,
84 .ce5_base_address = 0x0004b400,
85 .ce6_base_address = 0x0004b800,
86 .ce7_base_address = 0x0004bc00,
87 /* Note: qca99x0 supports upto 12 Copy Engines. Other than address of
88 * CE0 and CE1 no other copy engine is directly referred in the code.
89 * It is not really necessary to assign address for newly supported
90 * CEs in this address table.
97 .soc_reset_control_si0_rst_mask = 0x00000001,
98 .soc_reset_control_ce_rst_mask = 0x00000100,
99 .soc_chip_id_address = 0x000000ec,
100 .scratch_3_address = 0x00040050,
101 .fw_indicator_address = 0x00040050,
102 .pcie_local_base_address = 0x00000000,
103 .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
104 .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
105 .pcie_intr_fw_mask = 0x00100000,
106 .pcie_intr_ce_mask_all = 0x000fff00,
107 .pcie_intr_clr_address = 0x00000010,
110 const struct ath10k_hw_regs qca4019_regs = {
111 .rtc_soc_base_address = 0x00080000,
112 .soc_core_base_address = 0x00082000,
113 .wlan_mac_base_address = 0x00030000,
114 .ce_wrapper_base_address = 0x0004d000,
115 .ce0_base_address = 0x0004a000,
116 .ce1_base_address = 0x0004a400,
117 .ce2_base_address = 0x0004a800,
118 .ce3_base_address = 0x0004ac00,
119 .ce4_base_address = 0x0004b000,
120 .ce5_base_address = 0x0004b400,
121 .ce6_base_address = 0x0004b800,
122 .ce7_base_address = 0x0004bc00,
123 /* qca4019 supports upto 12 copy engines. Since base address
124 * of ce8 to ce11 are not directly referred in the code,
125 * no need have them in separate members in this table.
126 * Copy Engine Address
132 .soc_reset_control_si0_rst_mask = 0x00000001,
133 .soc_reset_control_ce_rst_mask = 0x00000100,
134 .soc_chip_id_address = 0x000000ec,
135 .fw_indicator_address = 0x0004f00c,
136 .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
137 .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
138 .pcie_intr_fw_mask = 0x00100000,
139 .pcie_intr_ce_mask_all = 0x000fff00,
140 .pcie_intr_clr_address = 0x00000010,
143 const struct ath10k_hw_values qca988x_values = {
144 .rtc_state_val_on = 3,
146 .msi_assign_ce_max = 7,
147 .num_target_ce_config_wlan = 7,
148 .ce_desc_meta_data_mask = 0xFFFC,
149 .ce_desc_meta_data_lsb = 2,
152 const struct ath10k_hw_values qca6174_values = {
153 .rtc_state_val_on = 3,
155 .msi_assign_ce_max = 7,
156 .num_target_ce_config_wlan = 7,
157 .ce_desc_meta_data_mask = 0xFFFC,
158 .ce_desc_meta_data_lsb = 2,
161 .rfkill_on_level = 1,
164 const struct ath10k_hw_values qca99x0_values = {
165 .rtc_state_val_on = 7,
167 .msi_assign_ce_max = 12,
168 .num_target_ce_config_wlan = 10,
169 .ce_desc_meta_data_mask = 0xFFF0,
170 .ce_desc_meta_data_lsb = 4,
173 const struct ath10k_hw_values qca9888_values = {
174 .rtc_state_val_on = 3,
176 .msi_assign_ce_max = 12,
177 .num_target_ce_config_wlan = 10,
178 .ce_desc_meta_data_mask = 0xFFF0,
179 .ce_desc_meta_data_lsb = 4,
182 const struct ath10k_hw_values qca4019_values = {
184 .num_target_ce_config_wlan = 10,
185 .ce_desc_meta_data_mask = 0xFFF0,
186 .ce_desc_meta_data_lsb = 4,
189 const struct ath10k_hw_regs wcn3990_regs = {
190 .rtc_soc_base_address = 0x00000000,
191 .rtc_wmac_base_address = 0x00000000,
192 .soc_core_base_address = 0x00000000,
193 .ce_wrapper_base_address = 0x0024C000,
194 .ce0_base_address = 0x00240000,
195 .ce1_base_address = 0x00241000,
196 .ce2_base_address = 0x00242000,
197 .ce3_base_address = 0x00243000,
198 .ce4_base_address = 0x00244000,
199 .ce5_base_address = 0x00245000,
200 .ce6_base_address = 0x00246000,
201 .ce7_base_address = 0x00247000,
202 .ce8_base_address = 0x00248000,
203 .ce9_base_address = 0x00249000,
204 .ce10_base_address = 0x0024A000,
205 .ce11_base_address = 0x0024B000,
206 .soc_chip_id_address = 0x000000f0,
207 .soc_reset_control_si0_rst_mask = 0x00000001,
208 .soc_reset_control_ce_rst_mask = 0x00000100,
209 .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
210 .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
211 .pcie_intr_fw_mask = 0x00100000,
214 static struct ath10k_hw_ce_regs_addr_map wcn3990_src_ring = {
217 .mask = GENMASK(17, 17),
220 static struct ath10k_hw_ce_regs_addr_map wcn3990_dst_ring = {
223 .mask = GENMASK(18, 18),
226 static struct ath10k_hw_ce_regs_addr_map wcn3990_dmax = {
229 .mask = GENMASK(15, 0),
232 static struct ath10k_hw_ce_ctrl1 wcn3990_ctrl1 = {
234 .src_ring = &wcn3990_src_ring,
235 .dst_ring = &wcn3990_dst_ring,
236 .dmax = &wcn3990_dmax,
239 static struct ath10k_hw_ce_regs_addr_map wcn3990_host_ie_cc = {
240 .mask = GENMASK(0, 0),
243 static struct ath10k_hw_ce_host_ie wcn3990_host_ie = {
244 .copy_complete = &wcn3990_host_ie_cc,
247 static struct ath10k_hw_ce_host_wm_regs wcn3990_wm_reg = {
248 .dstr_lmask = 0x00000010,
249 .dstr_hmask = 0x00000008,
250 .srcr_lmask = 0x00000004,
251 .srcr_hmask = 0x00000002,
252 .cc_mask = 0x00000001,
253 .wm_mask = 0x0000001E,
257 static struct ath10k_hw_ce_misc_regs wcn3990_misc_reg = {
258 .axi_err = 0x00000100,
259 .dstr_add_err = 0x00000200,
260 .srcr_len_err = 0x00000100,
261 .dstr_mlen_vio = 0x00000080,
262 .dstr_overflow = 0x00000040,
263 .srcr_overflow = 0x00000020,
264 .err_mask = 0x000003E0,
268 static struct ath10k_hw_ce_regs_addr_map wcn3990_src_wm_low = {
271 .mask = GENMASK(31, 16),
274 static struct ath10k_hw_ce_regs_addr_map wcn3990_src_wm_high = {
277 .mask = GENMASK(15, 0),
280 static struct ath10k_hw_ce_dst_src_wm_regs wcn3990_wm_src_ring = {
282 .low_rst = 0x00000000,
283 .high_rst = 0x00000000,
284 .wm_low = &wcn3990_src_wm_low,
285 .wm_high = &wcn3990_src_wm_high,
288 static struct ath10k_hw_ce_regs_addr_map wcn3990_dst_wm_low = {
290 .mask = GENMASK(31, 16),
293 static struct ath10k_hw_ce_regs_addr_map wcn3990_dst_wm_high = {
296 .mask = GENMASK(15, 0),
299 static struct ath10k_hw_ce_dst_src_wm_regs wcn3990_wm_dst_ring = {
301 .low_rst = 0x00000000,
302 .high_rst = 0x00000000,
303 .wm_low = &wcn3990_dst_wm_low,
304 .wm_high = &wcn3990_dst_wm_high,
307 static struct ath10k_hw_ce_ctrl1_upd wcn3990_ctrl1_upd = {
310 .enable = 0x00000000,
313 const struct ath10k_hw_ce_regs wcn3990_ce_regs = {
314 .sr_base_addr_lo = 0x00000000,
315 .sr_base_addr_hi = 0x00000004,
316 .sr_size_addr = 0x00000008,
317 .dr_base_addr_lo = 0x0000000c,
318 .dr_base_addr_hi = 0x00000010,
319 .dr_size_addr = 0x00000014,
320 .misc_ie_addr = 0x00000034,
321 .sr_wr_index_addr = 0x0000003c,
322 .dst_wr_index_addr = 0x00000040,
323 .current_srri_addr = 0x00000044,
324 .current_drri_addr = 0x00000048,
325 .ce_rri_low = 0x0024C004,
326 .ce_rri_high = 0x0024C008,
327 .host_ie_addr = 0x0000002c,
328 .ctrl1_regs = &wcn3990_ctrl1,
329 .host_ie = &wcn3990_host_ie,
330 .wm_regs = &wcn3990_wm_reg,
331 .misc_regs = &wcn3990_misc_reg,
332 .wm_srcr = &wcn3990_wm_src_ring,
333 .wm_dstr = &wcn3990_wm_dst_ring,
334 .upd = &wcn3990_ctrl1_upd,
337 const struct ath10k_hw_values wcn3990_values = {
338 .rtc_state_val_on = 5,
340 .msi_assign_ce_max = 12,
341 .num_target_ce_config_wlan = 12,
342 .ce_desc_meta_data_mask = 0xFFF0,
343 .ce_desc_meta_data_lsb = 4,
346 static struct ath10k_hw_ce_regs_addr_map qcax_src_ring = {
349 .mask = GENMASK(16, 16),
352 static struct ath10k_hw_ce_regs_addr_map qcax_dst_ring = {
355 .mask = GENMASK(17, 17),
358 static struct ath10k_hw_ce_regs_addr_map qcax_dmax = {
361 .mask = GENMASK(15, 0),
364 static struct ath10k_hw_ce_ctrl1 qcax_ctrl1 = {
366 .hw_mask = 0x0007ffff,
367 .sw_mask = 0x0007ffff,
368 .hw_wr_mask = 0x00000000,
369 .sw_wr_mask = 0x0007ffff,
370 .reset_mask = 0xffffffff,
372 .src_ring = &qcax_src_ring,
373 .dst_ring = &qcax_dst_ring,
377 static struct ath10k_hw_ce_regs_addr_map qcax_cmd_halt_status = {
380 .mask = GENMASK(3, 3),
383 static struct ath10k_hw_ce_cmd_halt qcax_cmd_halt = {
385 .mask = GENMASK(0, 0),
386 .status_reset = 0x00000000,
387 .status = &qcax_cmd_halt_status,
390 static struct ath10k_hw_ce_regs_addr_map qcax_host_ie_cc = {
393 .mask = GENMASK(0, 0),
396 static struct ath10k_hw_ce_host_ie qcax_host_ie = {
397 .copy_complete_reset = 0x00000000,
398 .copy_complete = &qcax_host_ie_cc,
401 static struct ath10k_hw_ce_host_wm_regs qcax_wm_reg = {
402 .dstr_lmask = 0x00000010,
403 .dstr_hmask = 0x00000008,
404 .srcr_lmask = 0x00000004,
405 .srcr_hmask = 0x00000002,
406 .cc_mask = 0x00000001,
407 .wm_mask = 0x0000001E,
411 static struct ath10k_hw_ce_misc_regs qcax_misc_reg = {
412 .axi_err = 0x00000400,
413 .dstr_add_err = 0x00000200,
414 .srcr_len_err = 0x00000100,
415 .dstr_mlen_vio = 0x00000080,
416 .dstr_overflow = 0x00000040,
417 .srcr_overflow = 0x00000020,
418 .err_mask = 0x000007E0,
422 static struct ath10k_hw_ce_regs_addr_map qcax_src_wm_low = {
425 .mask = GENMASK(31, 16),
428 static struct ath10k_hw_ce_regs_addr_map qcax_src_wm_high = {
431 .mask = GENMASK(15, 0),
434 static struct ath10k_hw_ce_dst_src_wm_regs qcax_wm_src_ring = {
436 .low_rst = 0x00000000,
437 .high_rst = 0x00000000,
438 .wm_low = &qcax_src_wm_low,
439 .wm_high = &qcax_src_wm_high,
442 static struct ath10k_hw_ce_regs_addr_map qcax_dst_wm_low = {
444 .mask = GENMASK(31, 16),
447 static struct ath10k_hw_ce_regs_addr_map qcax_dst_wm_high = {
450 .mask = GENMASK(15, 0),
453 static struct ath10k_hw_ce_dst_src_wm_regs qcax_wm_dst_ring = {
455 .low_rst = 0x00000000,
456 .high_rst = 0x00000000,
457 .wm_low = &qcax_dst_wm_low,
458 .wm_high = &qcax_dst_wm_high,
461 const struct ath10k_hw_ce_regs qcax_ce_regs = {
462 .sr_base_addr_lo = 0x00000000,
463 .sr_size_addr = 0x00000004,
464 .dr_base_addr_lo = 0x00000008,
465 .dr_size_addr = 0x0000000c,
466 .ce_cmd_addr = 0x00000018,
467 .misc_ie_addr = 0x00000034,
468 .sr_wr_index_addr = 0x0000003c,
469 .dst_wr_index_addr = 0x00000040,
470 .current_srri_addr = 0x00000044,
471 .current_drri_addr = 0x00000048,
472 .host_ie_addr = 0x0000002c,
473 .ctrl1_regs = &qcax_ctrl1,
474 .cmd_halt = &qcax_cmd_halt,
475 .host_ie = &qcax_host_ie,
476 .wm_regs = &qcax_wm_reg,
477 .misc_regs = &qcax_misc_reg,
478 .wm_srcr = &qcax_wm_src_ring,
479 .wm_dstr = &qcax_wm_dst_ring,
482 const struct ath10k_hw_clk_params qca6174_clk[ATH10K_HW_REFCLK_COUNT] = {
549 void ath10k_hw_fill_survey_time(struct ath10k *ar, struct survey_info *survey,
550 u32 cc, u32 rcc, u32 cc_prev, u32 rcc_prev)
554 enum ath10k_hw_cc_wraparound_type wraparound_type;
556 survey->filled |= SURVEY_INFO_TIME |
557 SURVEY_INFO_TIME_BUSY;
559 wraparound_type = ar->hw_params.cc_wraparound_type;
561 if (cc < cc_prev || rcc < rcc_prev) {
562 switch (wraparound_type) {
563 case ATH10K_HW_CC_WRAP_SHIFTED_ALL:
566 survey->filled &= ~SURVEY_INFO_TIME_BUSY;
569 case ATH10K_HW_CC_WRAP_SHIFTED_EACH:
574 rcc_fix = 0x7fffffff;
576 case ATH10K_HW_CC_WRAP_DISABLED:
581 cc -= cc_prev - cc_fix;
582 rcc -= rcc_prev - rcc_fix;
584 survey->time = CCNT_TO_MSEC(ar, cc);
585 survey->time_busy = CCNT_TO_MSEC(ar, rcc);
588 /* The firmware does not support setting the coverage class. Instead this
589 * function monitors and modifies the corresponding MAC registers.
591 static void ath10k_hw_qca988x_set_coverage_class(struct ath10k *ar,
604 mutex_lock(&ar->conf_mutex);
606 /* Only modify registers if the core is started. */
607 if ((ar->state != ATH10K_STATE_ON) &&
608 (ar->state != ATH10K_STATE_RESTARTED)) {
609 spin_lock_bh(&ar->data_lock);
610 /* Store config value for when radio boots up */
611 ar->fw_coverage.coverage_class = value;
612 spin_unlock_bh(&ar->data_lock);
616 /* Retrieve the current values of the two registers that need to be
619 slottime_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
620 WAVE1_PCU_GBL_IFS_SLOT);
621 timeout_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
622 WAVE1_PCU_ACK_CTS_TIMEOUT);
623 phyclk_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
625 phyclk = MS(phyclk_reg, WAVE1_PHYCLK_USEC) + 1;
628 value = ar->fw_coverage.coverage_class;
630 /* Break out if the coverage class and registers have the expected
633 if (value == ar->fw_coverage.coverage_class &&
634 slottime_reg == ar->fw_coverage.reg_slottime_conf &&
635 timeout_reg == ar->fw_coverage.reg_ack_cts_timeout_conf &&
636 phyclk_reg == ar->fw_coverage.reg_phyclk)
639 /* Store new initial register values from the firmware. */
640 if (slottime_reg != ar->fw_coverage.reg_slottime_conf)
641 ar->fw_coverage.reg_slottime_orig = slottime_reg;
642 if (timeout_reg != ar->fw_coverage.reg_ack_cts_timeout_conf)
643 ar->fw_coverage.reg_ack_cts_timeout_orig = timeout_reg;
644 ar->fw_coverage.reg_phyclk = phyclk_reg;
646 /* Calculate new value based on the (original) firmware calculation. */
647 slottime_reg = ar->fw_coverage.reg_slottime_orig;
648 timeout_reg = ar->fw_coverage.reg_ack_cts_timeout_orig;
650 /* Do some sanity checks on the slottime register. */
651 if (slottime_reg % phyclk) {
653 "failed to set coverage class: expected integer microsecond value in register\n");
658 slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
659 slottime = slottime / phyclk;
660 if (slottime != 9 && slottime != 20) {
662 "failed to set coverage class: expected slot time of 9 or 20us in HW register. It is %uus.\n",
668 /* Recalculate the register values by adding the additional propagation
669 * delay (3us per coverage class).
672 slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
673 slottime += value * 3 * phyclk;
674 slottime = min_t(u32, slottime, WAVE1_PCU_GBL_IFS_SLOT_MAX);
675 slottime = SM(slottime, WAVE1_PCU_GBL_IFS_SLOT);
676 slottime_reg = (slottime_reg & ~WAVE1_PCU_GBL_IFS_SLOT_MASK) | slottime;
678 /* Update ack timeout (lower halfword). */
679 ack_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
680 ack_timeout += 3 * value * phyclk;
681 ack_timeout = min_t(u32, ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
682 ack_timeout = SM(ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
684 /* Update cts timeout (upper halfword). */
685 cts_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
686 cts_timeout += 3 * value * phyclk;
687 cts_timeout = min_t(u32, cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
688 cts_timeout = SM(cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
690 timeout_reg = ack_timeout | cts_timeout;
692 ath10k_hif_write32(ar,
693 WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_GBL_IFS_SLOT,
695 ath10k_hif_write32(ar,
696 WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_ACK_CTS_TIMEOUT,
699 /* Ensure we have a debug level of WARN set for the case that the
700 * coverage class is larger than 0. This is important as we need to
701 * set the registers again if the firmware does an internal reset and
702 * this way we will be notified of the event.
704 fw_dbglog_mask = ath10k_debug_get_fw_dbglog_mask(ar);
705 fw_dbglog_level = ath10k_debug_get_fw_dbglog_level(ar);
708 if (fw_dbglog_level > ATH10K_DBGLOG_LEVEL_WARN)
709 fw_dbglog_level = ATH10K_DBGLOG_LEVEL_WARN;
713 ath10k_wmi_dbglog_cfg(ar, fw_dbglog_mask, fw_dbglog_level);
716 /* After an error we will not retry setting the coverage class. */
717 spin_lock_bh(&ar->data_lock);
718 ar->fw_coverage.coverage_class = value;
719 spin_unlock_bh(&ar->data_lock);
721 ar->fw_coverage.reg_slottime_conf = slottime_reg;
722 ar->fw_coverage.reg_ack_cts_timeout_conf = timeout_reg;
725 mutex_unlock(&ar->conf_mutex);
729 * ath10k_hw_qca6174_enable_pll_clock() - enable the qca6174 hw pll clock
730 * @ar: the ath10k blob
732 * This function is very hardware specific, the clock initialization
733 * steps is very sensitive and could lead to unknown crash, so they
734 * should be done in sequence.
736 * *** Be aware if you planned to refactor them. ***
738 * Return: 0 if successfully enable the pll, otherwise EINVAL
740 static int ath10k_hw_qca6174_enable_pll_clock(struct ath10k *ar)
743 u32 clk_div_addr, pll_init_addr, speed_addr;
744 u32 addr, reg_val, mem_val;
745 struct ath10k_hw_params *hw;
746 const struct ath10k_hw_clk_params *hw_clk;
750 if (ar->regs->core_clk_div_address == 0 ||
751 ar->regs->cpu_pll_init_address == 0 ||
752 ar->regs->cpu_speed_address == 0)
755 clk_div_addr = ar->regs->core_clk_div_address;
756 pll_init_addr = ar->regs->cpu_pll_init_address;
757 speed_addr = ar->regs->cpu_speed_address;
759 /* Read efuse register to find out the right hw clock configuration */
760 addr = (RTC_SOC_BASE_ADDRESS | EFUSE_OFFSET);
761 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
765 /* sanitize if the hw refclk index is out of the boundary */
766 if (MS(reg_val, EFUSE_XTAL_SEL) > ATH10K_HW_REFCLK_COUNT)
769 hw_clk = &hw->hw_clk[MS(reg_val, EFUSE_XTAL_SEL)];
771 /* Set the rnfrac and outdiv params to bb_pll register */
772 addr = (RTC_SOC_BASE_ADDRESS | BB_PLL_CONFIG_OFFSET);
773 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
777 reg_val &= ~(BB_PLL_CONFIG_FRAC_MASK | BB_PLL_CONFIG_OUTDIV_MASK);
778 reg_val |= (SM(hw_clk->rnfrac, BB_PLL_CONFIG_FRAC) |
779 SM(hw_clk->outdiv, BB_PLL_CONFIG_OUTDIV));
780 ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
784 /* Set the correct settle time value to pll_settle register */
785 addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_SETTLE_OFFSET);
786 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
790 reg_val &= ~WLAN_PLL_SETTLE_TIME_MASK;
791 reg_val |= SM(hw_clk->settle_time, WLAN_PLL_SETTLE_TIME);
792 ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
796 /* Set the clock_ctrl div to core_clk_ctrl register */
797 addr = (RTC_SOC_BASE_ADDRESS | SOC_CORE_CLK_CTRL_OFFSET);
798 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
802 reg_val &= ~SOC_CORE_CLK_CTRL_DIV_MASK;
803 reg_val |= SM(1, SOC_CORE_CLK_CTRL_DIV);
804 ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
808 /* Set the clock_div register */
810 ret = ath10k_bmi_write_memory(ar, clk_div_addr, &mem_val,
815 /* Configure the pll_control register */
816 addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
817 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
821 reg_val |= (SM(hw_clk->refdiv, WLAN_PLL_CONTROL_REFDIV) |
822 SM(hw_clk->div, WLAN_PLL_CONTROL_DIV) |
823 SM(1, WLAN_PLL_CONTROL_NOPWD));
824 ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
828 /* busy wait (max 1s) the rtc_sync status register indicate ready */
830 addr = (RTC_WMAC_BASE_ADDRESS | RTC_SYNC_STATUS_OFFSET);
832 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
836 if (!MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
842 } while (wait_limit > 0);
844 if (MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
847 /* Unset the pll_bypass in pll_control register */
848 addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
849 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
853 reg_val &= ~WLAN_PLL_CONTROL_BYPASS_MASK;
854 reg_val |= SM(0, WLAN_PLL_CONTROL_BYPASS);
855 ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
859 /* busy wait (max 1s) the rtc_sync status register indicate ready */
861 addr = (RTC_WMAC_BASE_ADDRESS | RTC_SYNC_STATUS_OFFSET);
863 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
867 if (!MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
873 } while (wait_limit > 0);
875 if (MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
878 /* Enable the hardware cpu clock register */
879 addr = (RTC_SOC_BASE_ADDRESS | SOC_CPU_CLOCK_OFFSET);
880 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
884 reg_val &= ~SOC_CPU_CLOCK_STANDARD_MASK;
885 reg_val |= SM(1, SOC_CPU_CLOCK_STANDARD);
886 ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
890 /* unset the nopwd from pll_control register */
891 addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
892 ret = ath10k_bmi_read_soc_reg(ar, addr, ®_val);
896 reg_val &= ~WLAN_PLL_CONTROL_NOPWD_MASK;
897 ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
901 /* enable the pll_init register */
903 ret = ath10k_bmi_write_memory(ar, pll_init_addr, &mem_val,
908 /* set the target clock frequency to speed register */
909 ret = ath10k_bmi_write_memory(ar, speed_addr, &hw->target_cpu_freq,
910 sizeof(hw->target_cpu_freq));
917 /* Program CPU_ADDR_MSB to allow different memory
920 static void ath10k_hw_map_target_mem(struct ath10k *ar, u32 msb)
922 u32 address = SOC_CORE_BASE_ADDRESS + FW_RAM_CONFIG_ADDRESS;
924 ath10k_hif_write32(ar, address, msb);
927 /* 1. Write to memory region of target, such as IRAM adn DRAM.
928 * 2. Target address( 0 ~ 00100000 & 0x00400000~0x00500000)
929 * can be written directly. See ath10k_pci_targ_cpu_to_ce_addr() too.
930 * 3. In order to access the region other than the above,
931 * we need to set the value of register CPU_ADDR_MSB.
932 * 4. Target memory access space is limited to 1M size. If the size is larger
933 * than 1M, need to split it and program CPU_ADDR_MSB accordingly.
935 static int ath10k_hw_diag_segment_msb_download(struct ath10k *ar,
940 u32 addr = address & REGION_ACCESS_SIZE_MASK;
941 int ret, remain_size, size;
944 ath10k_hw_map_target_mem(ar, CPU_ADDR_MSB_REGION_VAL(address));
946 if (addr + length > REGION_ACCESS_SIZE_LIMIT) {
947 size = REGION_ACCESS_SIZE_LIMIT - addr;
948 remain_size = length - size;
950 ret = ath10k_hif_diag_write(ar, address, buffer, size);
953 "failed to download the first %d bytes segment to address:0x%x: %d\n",
958 /* Change msb to the next memory region*/
959 ath10k_hw_map_target_mem(ar,
960 CPU_ADDR_MSB_REGION_VAL(address) + 1);
962 ret = ath10k_hif_diag_write(ar,
963 address & ~REGION_ACCESS_SIZE_MASK,
967 "failed to download the second %d bytes segment to address:0x%x: %d\n",
969 address & ~REGION_ACCESS_SIZE_MASK,
974 ret = ath10k_hif_diag_write(ar, address, buffer, length);
977 "failed to download the only %d bytes segment to address:0x%x: %d\n",
978 length, address, ret);
984 /* Change msb to DRAM */
985 ath10k_hw_map_target_mem(ar,
986 CPU_ADDR_MSB_REGION_VAL(DRAM_BASE_ADDRESS));
990 static int ath10k_hw_diag_segment_download(struct ath10k *ar,
995 if (address >= DRAM_BASE_ADDRESS + REGION_ACCESS_SIZE_LIMIT)
996 /* Needs to change MSB for memory write */
997 return ath10k_hw_diag_segment_msb_download(ar, buffer,
1000 return ath10k_hif_diag_write(ar, address, buffer, length);
1003 int ath10k_hw_diag_fast_download(struct ath10k *ar,
1008 const u8 *buf = buffer;
1009 bool sgmt_end = false;
1013 struct bmi_segmented_file_header *hdr;
1014 struct bmi_segmented_metadata *metadata;
1017 if (length < sizeof(*hdr))
1020 /* check firmware header. If it has no correct magic number
1021 * or it's compressed, returns error.
1023 hdr = (struct bmi_segmented_file_header *)buf;
1024 if (__le32_to_cpu(hdr->magic_num) != BMI_SGMTFILE_MAGIC_NUM) {
1025 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1026 "Not a supported firmware, magic_num:0x%x\n",
1031 if (hdr->file_flags != 0) {
1032 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1033 "Not a supported firmware, file_flags:0x%x\n",
1038 metadata = (struct bmi_segmented_metadata *)hdr->data;
1039 left = length - sizeof(*hdr);
1042 if (left < sizeof(*metadata)) {
1043 ath10k_warn(ar, "firmware segment is truncated: %d\n",
1048 base_addr = __le32_to_cpu(metadata->addr);
1049 base_len = __le32_to_cpu(metadata->length);
1050 buf = metadata->data;
1051 left -= sizeof(*metadata);
1054 case BMI_SGMTFILE_BEGINADDR:
1055 /* base_addr is the start address to run */
1056 ret = ath10k_bmi_set_start(ar, base_addr);
1059 case BMI_SGMTFILE_DONE:
1060 /* no more segment */
1065 case BMI_SGMTFILE_BDDATA:
1066 case BMI_SGMTFILE_EXEC:
1068 "firmware has unsupported segment:%d\n",
1073 if (base_len > left) {
1076 "firmware has invalid segment length, %d > %d\n",
1082 ret = ath10k_hw_diag_segment_download(ar,
1089 "failed to download firmware via diag interface:%d\n",
1094 if (ret || sgmt_end)
1097 metadata = (struct bmi_segmented_metadata *)(buf + base_len);
1102 ath10k_dbg(ar, ATH10K_DBG_BOOT,
1103 "boot firmware fast diag download successfully.\n");
1107 static int ath10k_htt_tx_rssi_enable(struct htt_resp *resp)
1109 return (resp->data_tx_completion.flags2 & HTT_TX_CMPL_FLAG_DATA_RSSI);
1112 static int ath10k_htt_tx_rssi_enable_wcn3990(struct htt_resp *resp)
1114 return (resp->data_tx_completion.flags2 &
1115 HTT_TX_DATA_RSSI_ENABLE_WCN3990);
1118 static int ath10k_get_htt_tx_data_rssi_pad(struct htt_resp *resp)
1120 struct htt_data_tx_completion_ext extd;
1123 if (resp->data_tx_completion.flags2 & HTT_TX_DATA_APPEND_RETRIES)
1124 pad_bytes += sizeof(extd.a_retries) /
1125 sizeof(extd.msdus_rssi[0]);
1127 if (resp->data_tx_completion.flags2 & HTT_TX_DATA_APPEND_TIMESTAMP)
1128 pad_bytes += sizeof(extd.t_stamp) / sizeof(extd.msdus_rssi[0]);
1133 const struct ath10k_hw_ops qca988x_ops = {
1134 .set_coverage_class = ath10k_hw_qca988x_set_coverage_class,
1135 .is_rssi_enable = ath10k_htt_tx_rssi_enable,
1138 const struct ath10k_hw_ops qca99x0_ops = {
1139 .is_rssi_enable = ath10k_htt_tx_rssi_enable,
1142 const struct ath10k_hw_ops qca6174_ops = {
1143 .set_coverage_class = ath10k_hw_qca988x_set_coverage_class,
1144 .enable_pll_clk = ath10k_hw_qca6174_enable_pll_clock,
1145 .is_rssi_enable = ath10k_htt_tx_rssi_enable,
1148 const struct ath10k_hw_ops qca6174_sdio_ops = {
1149 .enable_pll_clk = ath10k_hw_qca6174_enable_pll_clock,
1152 const struct ath10k_hw_ops wcn3990_ops = {
1153 .tx_data_rssi_pad_bytes = ath10k_get_htt_tx_data_rssi_pad,
1154 .is_rssi_enable = ath10k_htt_tx_rssi_enable_wcn3990,