hw.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Copyright (c) 2014-2015 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/types.h>
  17. #include "core.h"
  18. #include "hw.h"
  19. #include "hif.h"
  20. #include "wmi-ops.h"
  21. const struct ath10k_hw_regs qca988x_regs = {
  22. .rtc_soc_base_address = 0x00004000,
  23. .rtc_wmac_base_address = 0x00005000,
  24. .soc_core_base_address = 0x00009000,
  25. .wlan_mac_base_address = 0x00020000,
  26. .ce_wrapper_base_address = 0x00057000,
  27. .ce0_base_address = 0x00057400,
  28. .ce1_base_address = 0x00057800,
  29. .ce2_base_address = 0x00057c00,
  30. .ce3_base_address = 0x00058000,
  31. .ce4_base_address = 0x00058400,
  32. .ce5_base_address = 0x00058800,
  33. .ce6_base_address = 0x00058c00,
  34. .ce7_base_address = 0x00059000,
  35. .soc_reset_control_si0_rst_mask = 0x00000001,
  36. .soc_reset_control_ce_rst_mask = 0x00040000,
  37. .soc_chip_id_address = 0x000000ec,
  38. .scratch_3_address = 0x00000030,
  39. .fw_indicator_address = 0x00009030,
  40. .pcie_local_base_address = 0x00080000,
  41. .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
  42. .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
  43. .pcie_intr_fw_mask = 0x00000400,
  44. .pcie_intr_ce_mask_all = 0x0007f800,
  45. .pcie_intr_clr_address = 0x00000014,
  46. };
  47. const struct ath10k_hw_regs qca6174_regs = {
  48. .rtc_soc_base_address = 0x00000800,
  49. .rtc_wmac_base_address = 0x00001000,
  50. .soc_core_base_address = 0x0003a000,
  51. .wlan_mac_base_address = 0x00020000,
  52. .ce_wrapper_base_address = 0x00034000,
  53. .ce0_base_address = 0x00034400,
  54. .ce1_base_address = 0x00034800,
  55. .ce2_base_address = 0x00034c00,
  56. .ce3_base_address = 0x00035000,
  57. .ce4_base_address = 0x00035400,
  58. .ce5_base_address = 0x00035800,
  59. .ce6_base_address = 0x00035c00,
  60. .ce7_base_address = 0x00036000,
  61. .soc_reset_control_si0_rst_mask = 0x00000000,
  62. .soc_reset_control_ce_rst_mask = 0x00000001,
  63. .soc_chip_id_address = 0x000000f0,
  64. .scratch_3_address = 0x00000028,
  65. .fw_indicator_address = 0x0003a028,
  66. .pcie_local_base_address = 0x00080000,
  67. .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
  68. .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
  69. .pcie_intr_fw_mask = 0x00000400,
  70. .pcie_intr_ce_mask_all = 0x0007f800,
  71. .pcie_intr_clr_address = 0x00000014,
  72. };
  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.
  91. * Copy Engine Address
  92. * CE8 0x0004c000
  93. * CE9 0x0004c400
  94. * CE10 0x0004c800
  95. * CE11 0x0004cc00
  96. */
  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,
  108. };
  109. const struct ath10k_hw_regs qca4019_regs = {
  110. .rtc_soc_base_address = 0x00080000,
  111. .soc_core_base_address = 0x00082000,
  112. .wlan_mac_base_address = 0x00030000,
  113. .ce_wrapper_base_address = 0x0004d000,
  114. .ce0_base_address = 0x0004a000,
  115. .ce1_base_address = 0x0004a400,
  116. .ce2_base_address = 0x0004a800,
  117. .ce3_base_address = 0x0004ac00,
  118. .ce4_base_address = 0x0004b000,
  119. .ce5_base_address = 0x0004b400,
  120. .ce6_base_address = 0x0004b800,
  121. .ce7_base_address = 0x0004bc00,
  122. /* qca4019 supports upto 12 copy engines. Since base address
  123. * of ce8 to ce11 are not directly referred in the code,
  124. * no need have them in separate members in this table.
  125. * Copy Engine Address
  126. * CE8 0x0004c000
  127. * CE9 0x0004c400
  128. * CE10 0x0004c800
  129. * CE11 0x0004cc00
  130. */
  131. .soc_reset_control_si0_rst_mask = 0x00000001,
  132. .soc_reset_control_ce_rst_mask = 0x00000100,
  133. .soc_chip_id_address = 0x000000ec,
  134. .fw_indicator_address = 0x0004f00c,
  135. .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
  136. .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
  137. .pcie_intr_fw_mask = 0x00100000,
  138. .pcie_intr_ce_mask_all = 0x000fff00,
  139. .pcie_intr_clr_address = 0x00000010,
  140. };
  141. const struct ath10k_hw_values qca988x_values = {
  142. .rtc_state_val_on = 3,
  143. .ce_count = 8,
  144. .msi_assign_ce_max = 7,
  145. .num_target_ce_config_wlan = 7,
  146. .ce_desc_meta_data_mask = 0xFFFC,
  147. .ce_desc_meta_data_lsb = 2,
  148. };
  149. const struct ath10k_hw_values qca6174_values = {
  150. .rtc_state_val_on = 3,
  151. .ce_count = 8,
  152. .msi_assign_ce_max = 7,
  153. .num_target_ce_config_wlan = 7,
  154. .ce_desc_meta_data_mask = 0xFFFC,
  155. .ce_desc_meta_data_lsb = 2,
  156. };
  157. const struct ath10k_hw_values qca99x0_values = {
  158. .rtc_state_val_on = 5,
  159. .ce_count = 12,
  160. .msi_assign_ce_max = 12,
  161. .num_target_ce_config_wlan = 10,
  162. .ce_desc_meta_data_mask = 0xFFF0,
  163. .ce_desc_meta_data_lsb = 4,
  164. };
  165. const struct ath10k_hw_values qca9888_values = {
  166. .rtc_state_val_on = 3,
  167. .ce_count = 12,
  168. .msi_assign_ce_max = 12,
  169. .num_target_ce_config_wlan = 10,
  170. .ce_desc_meta_data_mask = 0xFFF0,
  171. .ce_desc_meta_data_lsb = 4,
  172. };
  173. const struct ath10k_hw_values qca4019_values = {
  174. .ce_count = 12,
  175. .num_target_ce_config_wlan = 10,
  176. .ce_desc_meta_data_mask = 0xFFF0,
  177. .ce_desc_meta_data_lsb = 4,
  178. };
  179. void ath10k_hw_fill_survey_time(struct ath10k *ar, struct survey_info *survey,
  180. u32 cc, u32 rcc, u32 cc_prev, u32 rcc_prev)
  181. {
  182. u32 cc_fix = 0;
  183. u32 rcc_fix = 0;
  184. enum ath10k_hw_cc_wraparound_type wraparound_type;
  185. survey->filled |= SURVEY_INFO_TIME |
  186. SURVEY_INFO_TIME_BUSY;
  187. wraparound_type = ar->hw_params.cc_wraparound_type;
  188. if (cc < cc_prev || rcc < rcc_prev) {
  189. switch (wraparound_type) {
  190. case ATH10K_HW_CC_WRAP_SHIFTED_ALL:
  191. if (cc < cc_prev) {
  192. cc_fix = 0x7fffffff;
  193. survey->filled &= ~SURVEY_INFO_TIME_BUSY;
  194. }
  195. break;
  196. case ATH10K_HW_CC_WRAP_SHIFTED_EACH:
  197. if (cc < cc_prev)
  198. cc_fix = 0x7fffffff;
  199. if (rcc < rcc_prev)
  200. rcc_fix = 0x7fffffff;
  201. break;
  202. case ATH10K_HW_CC_WRAP_DISABLED:
  203. break;
  204. }
  205. }
  206. cc -= cc_prev - cc_fix;
  207. rcc -= rcc_prev - rcc_fix;
  208. survey->time = CCNT_TO_MSEC(ar, cc);
  209. survey->time_busy = CCNT_TO_MSEC(ar, rcc);
  210. }
  211. /* The firmware does not support setting the coverage class. Instead this
  212. * function monitors and modifies the corresponding MAC registers.
  213. */
  214. static void ath10k_hw_qca988x_set_coverage_class(struct ath10k *ar,
  215. s16 value)
  216. {
  217. u32 slottime_reg;
  218. u32 slottime;
  219. u32 timeout_reg;
  220. u32 ack_timeout;
  221. u32 cts_timeout;
  222. u32 phyclk_reg;
  223. u32 phyclk;
  224. u64 fw_dbglog_mask;
  225. u32 fw_dbglog_level;
  226. mutex_lock(&ar->conf_mutex);
  227. /* Only modify registers if the core is started. */
  228. if ((ar->state != ATH10K_STATE_ON) &&
  229. (ar->state != ATH10K_STATE_RESTARTED))
  230. goto unlock;
  231. /* Retrieve the current values of the two registers that need to be
  232. * adjusted.
  233. */
  234. slottime_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  235. WAVE1_PCU_GBL_IFS_SLOT);
  236. timeout_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  237. WAVE1_PCU_ACK_CTS_TIMEOUT);
  238. phyclk_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  239. WAVE1_PHYCLK);
  240. phyclk = MS(phyclk_reg, WAVE1_PHYCLK_USEC) + 1;
  241. if (value < 0)
  242. value = ar->fw_coverage.coverage_class;
  243. /* Break out if the coverage class and registers have the expected
  244. * value.
  245. */
  246. if (value == ar->fw_coverage.coverage_class &&
  247. slottime_reg == ar->fw_coverage.reg_slottime_conf &&
  248. timeout_reg == ar->fw_coverage.reg_ack_cts_timeout_conf &&
  249. phyclk_reg == ar->fw_coverage.reg_phyclk)
  250. goto unlock;
  251. /* Store new initial register values from the firmware. */
  252. if (slottime_reg != ar->fw_coverage.reg_slottime_conf)
  253. ar->fw_coverage.reg_slottime_orig = slottime_reg;
  254. if (timeout_reg != ar->fw_coverage.reg_ack_cts_timeout_conf)
  255. ar->fw_coverage.reg_ack_cts_timeout_orig = timeout_reg;
  256. ar->fw_coverage.reg_phyclk = phyclk_reg;
  257. /* Calculat new value based on the (original) firmware calculation. */
  258. slottime_reg = ar->fw_coverage.reg_slottime_orig;
  259. timeout_reg = ar->fw_coverage.reg_ack_cts_timeout_orig;
  260. /* Do some sanity checks on the slottime register. */
  261. if (slottime_reg % phyclk) {
  262. ath10k_warn(ar,
  263. "failed to set coverage class: expected integer microsecond value in register\n");
  264. goto store_regs;
  265. }
  266. slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
  267. slottime = slottime / phyclk;
  268. if (slottime != 9 && slottime != 20) {
  269. ath10k_warn(ar,
  270. "failed to set coverage class: expected slot time of 9 or 20us in HW register. It is %uus.\n",
  271. slottime);
  272. goto store_regs;
  273. }
  274. /* Recalculate the register values by adding the additional propagation
  275. * delay (3us per coverage class).
  276. */
  277. slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
  278. slottime += value * 3 * phyclk;
  279. slottime = min_t(u32, slottime, WAVE1_PCU_GBL_IFS_SLOT_MAX);
  280. slottime = SM(slottime, WAVE1_PCU_GBL_IFS_SLOT);
  281. slottime_reg = (slottime_reg & ~WAVE1_PCU_GBL_IFS_SLOT_MASK) | slottime;
  282. /* Update ack timeout (lower halfword). */
  283. ack_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
  284. ack_timeout += 3 * value * phyclk;
  285. ack_timeout = min_t(u32, ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
  286. ack_timeout = SM(ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
  287. /* Update cts timeout (upper halfword). */
  288. cts_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
  289. cts_timeout += 3 * value * phyclk;
  290. cts_timeout = min_t(u32, cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
  291. cts_timeout = SM(cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
  292. timeout_reg = ack_timeout | cts_timeout;
  293. ath10k_hif_write32(ar,
  294. WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_GBL_IFS_SLOT,
  295. slottime_reg);
  296. ath10k_hif_write32(ar,
  297. WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_ACK_CTS_TIMEOUT,
  298. timeout_reg);
  299. /* Ensure we have a debug level of WARN set for the case that the
  300. * coverage class is larger than 0. This is important as we need to
  301. * set the registers again if the firmware does an internal reset and
  302. * this way we will be notified of the event.
  303. */
  304. fw_dbglog_mask = ath10k_debug_get_fw_dbglog_mask(ar);
  305. fw_dbglog_level = ath10k_debug_get_fw_dbglog_level(ar);
  306. if (value > 0) {
  307. if (fw_dbglog_level > ATH10K_DBGLOG_LEVEL_WARN)
  308. fw_dbglog_level = ATH10K_DBGLOG_LEVEL_WARN;
  309. fw_dbglog_mask = ~0;
  310. }
  311. ath10k_wmi_dbglog_cfg(ar, fw_dbglog_mask, fw_dbglog_level);
  312. store_regs:
  313. /* After an error we will not retry setting the coverage class. */
  314. spin_lock_bh(&ar->data_lock);
  315. ar->fw_coverage.coverage_class = value;
  316. spin_unlock_bh(&ar->data_lock);
  317. ar->fw_coverage.reg_slottime_conf = slottime_reg;
  318. ar->fw_coverage.reg_ack_cts_timeout_conf = timeout_reg;
  319. unlock:
  320. mutex_unlock(&ar->conf_mutex);
  321. }
  322. const struct ath10k_hw_ops qca988x_ops = {
  323. .set_coverage_class = ath10k_hw_qca988x_set_coverage_class,
  324. };
  325. static int ath10k_qca99x0_rx_desc_get_l3_pad_bytes(struct htt_rx_desc *rxd)
  326. {
  327. return MS(__le32_to_cpu(rxd->msdu_end.qca99x0.info1),
  328. RX_MSDU_END_INFO1_L3_HDR_PAD);
  329. }
  330. const struct ath10k_hw_ops qca99x0_ops = {
  331. .rx_desc_get_l3_pad_bytes = ath10k_qca99x0_rx_desc_get_l3_pad_bytes,
  332. };