hw.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /*
  2. * Copyright (c) 2014-2017 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 <linux/bitops.h>
  18. #include "core.h"
  19. #include "hw.h"
  20. #include "hif.h"
  21. #include "wmi-ops.h"
  22. #include "bmi.h"
  23. const struct ath10k_hw_regs qca988x_regs = {
  24. .rtc_soc_base_address = 0x00004000,
  25. .rtc_wmac_base_address = 0x00005000,
  26. .soc_core_base_address = 0x00009000,
  27. .wlan_mac_base_address = 0x00020000,
  28. .ce_wrapper_base_address = 0x00057000,
  29. .ce0_base_address = 0x00057400,
  30. .ce1_base_address = 0x00057800,
  31. .ce2_base_address = 0x00057c00,
  32. .ce3_base_address = 0x00058000,
  33. .ce4_base_address = 0x00058400,
  34. .ce5_base_address = 0x00058800,
  35. .ce6_base_address = 0x00058c00,
  36. .ce7_base_address = 0x00059000,
  37. .soc_reset_control_si0_rst_mask = 0x00000001,
  38. .soc_reset_control_ce_rst_mask = 0x00040000,
  39. .soc_chip_id_address = 0x000000ec,
  40. .scratch_3_address = 0x00000030,
  41. .fw_indicator_address = 0x00009030,
  42. .pcie_local_base_address = 0x00080000,
  43. .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
  44. .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
  45. .pcie_intr_fw_mask = 0x00000400,
  46. .pcie_intr_ce_mask_all = 0x0007f800,
  47. .pcie_intr_clr_address = 0x00000014,
  48. };
  49. const struct ath10k_hw_regs qca6174_regs = {
  50. .rtc_soc_base_address = 0x00000800,
  51. .rtc_wmac_base_address = 0x00001000,
  52. .soc_core_base_address = 0x0003a000,
  53. .wlan_mac_base_address = 0x00010000,
  54. .ce_wrapper_base_address = 0x00034000,
  55. .ce0_base_address = 0x00034400,
  56. .ce1_base_address = 0x00034800,
  57. .ce2_base_address = 0x00034c00,
  58. .ce3_base_address = 0x00035000,
  59. .ce4_base_address = 0x00035400,
  60. .ce5_base_address = 0x00035800,
  61. .ce6_base_address = 0x00035c00,
  62. .ce7_base_address = 0x00036000,
  63. .soc_reset_control_si0_rst_mask = 0x00000000,
  64. .soc_reset_control_ce_rst_mask = 0x00000001,
  65. .soc_chip_id_address = 0x000000f0,
  66. .scratch_3_address = 0x00000028,
  67. .fw_indicator_address = 0x0003a028,
  68. .pcie_local_base_address = 0x00080000,
  69. .ce_wrap_intr_sum_host_msi_lsb = 0x00000008,
  70. .ce_wrap_intr_sum_host_msi_mask = 0x0000ff00,
  71. .pcie_intr_fw_mask = 0x00000400,
  72. .pcie_intr_ce_mask_all = 0x0007f800,
  73. .pcie_intr_clr_address = 0x00000014,
  74. .cpu_pll_init_address = 0x00404020,
  75. .cpu_speed_address = 0x00404024,
  76. .core_clk_div_address = 0x00404028,
  77. };
  78. const struct ath10k_hw_regs qca99x0_regs = {
  79. .rtc_soc_base_address = 0x00080000,
  80. .rtc_wmac_base_address = 0x00000000,
  81. .soc_core_base_address = 0x00082000,
  82. .wlan_mac_base_address = 0x00030000,
  83. .ce_wrapper_base_address = 0x0004d000,
  84. .ce0_base_address = 0x0004a000,
  85. .ce1_base_address = 0x0004a400,
  86. .ce2_base_address = 0x0004a800,
  87. .ce3_base_address = 0x0004ac00,
  88. .ce4_base_address = 0x0004b000,
  89. .ce5_base_address = 0x0004b400,
  90. .ce6_base_address = 0x0004b800,
  91. .ce7_base_address = 0x0004bc00,
  92. /* Note: qca99x0 supports upto 12 Copy Engines. Other than address of
  93. * CE0 and CE1 no other copy engine is directly referred in the code.
  94. * It is not really necessary to assign address for newly supported
  95. * CEs in this address table.
  96. * Copy Engine Address
  97. * CE8 0x0004c000
  98. * CE9 0x0004c400
  99. * CE10 0x0004c800
  100. * CE11 0x0004cc00
  101. */
  102. .soc_reset_control_si0_rst_mask = 0x00000001,
  103. .soc_reset_control_ce_rst_mask = 0x00000100,
  104. .soc_chip_id_address = 0x000000ec,
  105. .scratch_3_address = 0x00040050,
  106. .fw_indicator_address = 0x00040050,
  107. .pcie_local_base_address = 0x00000000,
  108. .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
  109. .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
  110. .pcie_intr_fw_mask = 0x00100000,
  111. .pcie_intr_ce_mask_all = 0x000fff00,
  112. .pcie_intr_clr_address = 0x00000010,
  113. };
  114. const struct ath10k_hw_regs qca4019_regs = {
  115. .rtc_soc_base_address = 0x00080000,
  116. .soc_core_base_address = 0x00082000,
  117. .wlan_mac_base_address = 0x00030000,
  118. .ce_wrapper_base_address = 0x0004d000,
  119. .ce0_base_address = 0x0004a000,
  120. .ce1_base_address = 0x0004a400,
  121. .ce2_base_address = 0x0004a800,
  122. .ce3_base_address = 0x0004ac00,
  123. .ce4_base_address = 0x0004b000,
  124. .ce5_base_address = 0x0004b400,
  125. .ce6_base_address = 0x0004b800,
  126. .ce7_base_address = 0x0004bc00,
  127. /* qca4019 supports upto 12 copy engines. Since base address
  128. * of ce8 to ce11 are not directly referred in the code,
  129. * no need have them in separate members in this table.
  130. * Copy Engine Address
  131. * CE8 0x0004c000
  132. * CE9 0x0004c400
  133. * CE10 0x0004c800
  134. * CE11 0x0004cc00
  135. */
  136. .soc_reset_control_si0_rst_mask = 0x00000001,
  137. .soc_reset_control_ce_rst_mask = 0x00000100,
  138. .soc_chip_id_address = 0x000000ec,
  139. .fw_indicator_address = 0x0004f00c,
  140. .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
  141. .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
  142. .pcie_intr_fw_mask = 0x00100000,
  143. .pcie_intr_ce_mask_all = 0x000fff00,
  144. .pcie_intr_clr_address = 0x00000010,
  145. };
  146. const struct ath10k_hw_values qca988x_values = {
  147. .rtc_state_val_on = 3,
  148. .ce_count = 8,
  149. .msi_assign_ce_max = 7,
  150. .num_target_ce_config_wlan = 7,
  151. .ce_desc_meta_data_mask = 0xFFFC,
  152. .ce_desc_meta_data_lsb = 2,
  153. };
  154. const struct ath10k_hw_values qca6174_values = {
  155. .rtc_state_val_on = 3,
  156. .ce_count = 8,
  157. .msi_assign_ce_max = 7,
  158. .num_target_ce_config_wlan = 7,
  159. .ce_desc_meta_data_mask = 0xFFFC,
  160. .ce_desc_meta_data_lsb = 2,
  161. };
  162. const struct ath10k_hw_values qca99x0_values = {
  163. .rtc_state_val_on = 5,
  164. .ce_count = 12,
  165. .msi_assign_ce_max = 12,
  166. .num_target_ce_config_wlan = 10,
  167. .ce_desc_meta_data_mask = 0xFFF0,
  168. .ce_desc_meta_data_lsb = 4,
  169. };
  170. const struct ath10k_hw_values qca9888_values = {
  171. .rtc_state_val_on = 3,
  172. .ce_count = 12,
  173. .msi_assign_ce_max = 12,
  174. .num_target_ce_config_wlan = 10,
  175. .ce_desc_meta_data_mask = 0xFFF0,
  176. .ce_desc_meta_data_lsb = 4,
  177. };
  178. const struct ath10k_hw_values qca4019_values = {
  179. .ce_count = 12,
  180. .num_target_ce_config_wlan = 10,
  181. .ce_desc_meta_data_mask = 0xFFF0,
  182. .ce_desc_meta_data_lsb = 4,
  183. };
  184. const struct ath10k_hw_regs wcn3990_regs = {
  185. .rtc_soc_base_address = 0x00000000,
  186. .rtc_wmac_base_address = 0x00000000,
  187. .soc_core_base_address = 0x00000000,
  188. .ce_wrapper_base_address = 0x0024C000,
  189. .ce0_base_address = 0x00240000,
  190. .ce1_base_address = 0x00241000,
  191. .ce2_base_address = 0x00242000,
  192. .ce3_base_address = 0x00243000,
  193. .ce4_base_address = 0x00244000,
  194. .ce5_base_address = 0x00245000,
  195. .ce6_base_address = 0x00246000,
  196. .ce7_base_address = 0x00247000,
  197. .ce8_base_address = 0x00248000,
  198. .ce9_base_address = 0x00249000,
  199. .ce10_base_address = 0x0024A000,
  200. .ce11_base_address = 0x0024B000,
  201. .soc_chip_id_address = 0x000000f0,
  202. .soc_reset_control_si0_rst_mask = 0x00000001,
  203. .soc_reset_control_ce_rst_mask = 0x00000100,
  204. .ce_wrap_intr_sum_host_msi_lsb = 0x0000000c,
  205. .ce_wrap_intr_sum_host_msi_mask = 0x00fff000,
  206. .pcie_intr_fw_mask = 0x00100000,
  207. };
  208. static struct ath10k_hw_ce_regs_addr_map wcn3990_src_ring = {
  209. .msb = 0x00000010,
  210. .lsb = 0x00000010,
  211. .mask = GENMASK(17, 17),
  212. };
  213. static struct ath10k_hw_ce_regs_addr_map wcn3990_dst_ring = {
  214. .msb = 0x00000012,
  215. .lsb = 0x00000012,
  216. .mask = GENMASK(18, 18),
  217. };
  218. static struct ath10k_hw_ce_regs_addr_map wcn3990_dmax = {
  219. .msb = 0x00000000,
  220. .lsb = 0x00000000,
  221. .mask = GENMASK(15, 0),
  222. };
  223. static struct ath10k_hw_ce_ctrl1 wcn3990_ctrl1 = {
  224. .addr = 0x00000018,
  225. .src_ring = &wcn3990_src_ring,
  226. .dst_ring = &wcn3990_dst_ring,
  227. .dmax = &wcn3990_dmax,
  228. };
  229. static struct ath10k_hw_ce_regs_addr_map wcn3990_host_ie_cc = {
  230. .mask = GENMASK(0, 0),
  231. };
  232. static struct ath10k_hw_ce_host_ie wcn3990_host_ie = {
  233. .copy_complete = &wcn3990_host_ie_cc,
  234. };
  235. static struct ath10k_hw_ce_host_wm_regs wcn3990_wm_reg = {
  236. .dstr_lmask = 0x00000010,
  237. .dstr_hmask = 0x00000008,
  238. .srcr_lmask = 0x00000004,
  239. .srcr_hmask = 0x00000002,
  240. .cc_mask = 0x00000001,
  241. .wm_mask = 0x0000001E,
  242. .addr = 0x00000030,
  243. };
  244. static struct ath10k_hw_ce_misc_regs wcn3990_misc_reg = {
  245. .axi_err = 0x00000100,
  246. .dstr_add_err = 0x00000200,
  247. .srcr_len_err = 0x00000100,
  248. .dstr_mlen_vio = 0x00000080,
  249. .dstr_overflow = 0x00000040,
  250. .srcr_overflow = 0x00000020,
  251. .err_mask = 0x000003E0,
  252. .addr = 0x00000038,
  253. };
  254. static struct ath10k_hw_ce_regs_addr_map wcn3990_src_wm_low = {
  255. .msb = 0x00000000,
  256. .lsb = 0x00000010,
  257. .mask = GENMASK(31, 16),
  258. };
  259. static struct ath10k_hw_ce_regs_addr_map wcn3990_src_wm_high = {
  260. .msb = 0x0000000f,
  261. .lsb = 0x00000000,
  262. .mask = GENMASK(15, 0),
  263. };
  264. static struct ath10k_hw_ce_dst_src_wm_regs wcn3990_wm_src_ring = {
  265. .addr = 0x0000004c,
  266. .low_rst = 0x00000000,
  267. .high_rst = 0x00000000,
  268. .wm_low = &wcn3990_src_wm_low,
  269. .wm_high = &wcn3990_src_wm_high,
  270. };
  271. static struct ath10k_hw_ce_regs_addr_map wcn3990_dst_wm_low = {
  272. .lsb = 0x00000010,
  273. .mask = GENMASK(31, 16),
  274. };
  275. static struct ath10k_hw_ce_regs_addr_map wcn3990_dst_wm_high = {
  276. .msb = 0x0000000f,
  277. .lsb = 0x00000000,
  278. .mask = GENMASK(15, 0),
  279. };
  280. static struct ath10k_hw_ce_dst_src_wm_regs wcn3990_wm_dst_ring = {
  281. .addr = 0x00000050,
  282. .low_rst = 0x00000000,
  283. .high_rst = 0x00000000,
  284. .wm_low = &wcn3990_dst_wm_low,
  285. .wm_high = &wcn3990_dst_wm_high,
  286. };
  287. static struct ath10k_hw_ce_ctrl1_upd wcn3990_ctrl1_upd = {
  288. .shift = 19,
  289. .mask = 0x00080000,
  290. .enable = 0x00000000,
  291. };
  292. const struct ath10k_hw_ce_regs wcn3990_ce_regs = {
  293. .sr_base_addr = 0x00000000,
  294. .sr_size_addr = 0x00000008,
  295. .dr_base_addr = 0x0000000c,
  296. .dr_size_addr = 0x00000014,
  297. .misc_ie_addr = 0x00000034,
  298. .sr_wr_index_addr = 0x0000003c,
  299. .dst_wr_index_addr = 0x00000040,
  300. .current_srri_addr = 0x00000044,
  301. .current_drri_addr = 0x00000048,
  302. .ce_rri_low = 0x0024C004,
  303. .ce_rri_high = 0x0024C008,
  304. .host_ie_addr = 0x0000002c,
  305. .ctrl1_regs = &wcn3990_ctrl1,
  306. .host_ie = &wcn3990_host_ie,
  307. .wm_regs = &wcn3990_wm_reg,
  308. .misc_regs = &wcn3990_misc_reg,
  309. .wm_srcr = &wcn3990_wm_src_ring,
  310. .wm_dstr = &wcn3990_wm_dst_ring,
  311. .upd = &wcn3990_ctrl1_upd,
  312. };
  313. const struct ath10k_hw_values wcn3990_values = {
  314. .rtc_state_val_on = 5,
  315. .ce_count = 12,
  316. .msi_assign_ce_max = 12,
  317. .num_target_ce_config_wlan = 12,
  318. .ce_desc_meta_data_mask = 0xFFF0,
  319. .ce_desc_meta_data_lsb = 4,
  320. };
  321. static struct ath10k_hw_ce_regs_addr_map qcax_src_ring = {
  322. .msb = 0x00000010,
  323. .lsb = 0x00000010,
  324. .mask = GENMASK(16, 16),
  325. };
  326. static struct ath10k_hw_ce_regs_addr_map qcax_dst_ring = {
  327. .msb = 0x00000011,
  328. .lsb = 0x00000011,
  329. .mask = GENMASK(17, 17),
  330. };
  331. static struct ath10k_hw_ce_regs_addr_map qcax_dmax = {
  332. .msb = 0x0000000f,
  333. .lsb = 0x00000000,
  334. .mask = GENMASK(15, 0),
  335. };
  336. static struct ath10k_hw_ce_ctrl1 qcax_ctrl1 = {
  337. .addr = 0x00000010,
  338. .hw_mask = 0x0007ffff,
  339. .sw_mask = 0x0007ffff,
  340. .hw_wr_mask = 0x00000000,
  341. .sw_wr_mask = 0x0007ffff,
  342. .reset_mask = 0xffffffff,
  343. .reset = 0x00000080,
  344. .src_ring = &qcax_src_ring,
  345. .dst_ring = &qcax_dst_ring,
  346. .dmax = &qcax_dmax,
  347. };
  348. static struct ath10k_hw_ce_regs_addr_map qcax_cmd_halt_status = {
  349. .msb = 0x00000003,
  350. .lsb = 0x00000003,
  351. .mask = GENMASK(3, 3),
  352. };
  353. static struct ath10k_hw_ce_cmd_halt qcax_cmd_halt = {
  354. .msb = 0x00000000,
  355. .mask = GENMASK(0, 0),
  356. .status_reset = 0x00000000,
  357. .status = &qcax_cmd_halt_status,
  358. };
  359. static struct ath10k_hw_ce_regs_addr_map qcax_host_ie_cc = {
  360. .msb = 0x00000000,
  361. .lsb = 0x00000000,
  362. .mask = GENMASK(0, 0),
  363. };
  364. static struct ath10k_hw_ce_host_ie qcax_host_ie = {
  365. .copy_complete_reset = 0x00000000,
  366. .copy_complete = &qcax_host_ie_cc,
  367. };
  368. static struct ath10k_hw_ce_host_wm_regs qcax_wm_reg = {
  369. .dstr_lmask = 0x00000010,
  370. .dstr_hmask = 0x00000008,
  371. .srcr_lmask = 0x00000004,
  372. .srcr_hmask = 0x00000002,
  373. .cc_mask = 0x00000001,
  374. .wm_mask = 0x0000001E,
  375. .addr = 0x00000030,
  376. };
  377. static struct ath10k_hw_ce_misc_regs qcax_misc_reg = {
  378. .axi_err = 0x00000400,
  379. .dstr_add_err = 0x00000200,
  380. .srcr_len_err = 0x00000100,
  381. .dstr_mlen_vio = 0x00000080,
  382. .dstr_overflow = 0x00000040,
  383. .srcr_overflow = 0x00000020,
  384. .err_mask = 0x000007E0,
  385. .addr = 0x00000038,
  386. };
  387. static struct ath10k_hw_ce_regs_addr_map qcax_src_wm_low = {
  388. .msb = 0x0000001f,
  389. .lsb = 0x00000010,
  390. .mask = GENMASK(31, 16),
  391. };
  392. static struct ath10k_hw_ce_regs_addr_map qcax_src_wm_high = {
  393. .msb = 0x0000000f,
  394. .lsb = 0x00000000,
  395. .mask = GENMASK(15, 0),
  396. };
  397. static struct ath10k_hw_ce_dst_src_wm_regs qcax_wm_src_ring = {
  398. .addr = 0x0000004c,
  399. .low_rst = 0x00000000,
  400. .high_rst = 0x00000000,
  401. .wm_low = &qcax_src_wm_low,
  402. .wm_high = &qcax_src_wm_high,
  403. };
  404. static struct ath10k_hw_ce_regs_addr_map qcax_dst_wm_low = {
  405. .lsb = 0x00000010,
  406. .mask = GENMASK(31, 16),
  407. };
  408. static struct ath10k_hw_ce_regs_addr_map qcax_dst_wm_high = {
  409. .msb = 0x0000000f,
  410. .lsb = 0x00000000,
  411. .mask = GENMASK(15, 0),
  412. };
  413. static struct ath10k_hw_ce_dst_src_wm_regs qcax_wm_dst_ring = {
  414. .addr = 0x00000050,
  415. .low_rst = 0x00000000,
  416. .high_rst = 0x00000000,
  417. .wm_low = &qcax_dst_wm_low,
  418. .wm_high = &qcax_dst_wm_high,
  419. };
  420. const struct ath10k_hw_ce_regs qcax_ce_regs = {
  421. .sr_base_addr = 0x00000000,
  422. .sr_size_addr = 0x00000004,
  423. .dr_base_addr = 0x00000008,
  424. .dr_size_addr = 0x0000000c,
  425. .ce_cmd_addr = 0x00000018,
  426. .misc_ie_addr = 0x00000034,
  427. .sr_wr_index_addr = 0x0000003c,
  428. .dst_wr_index_addr = 0x00000040,
  429. .current_srri_addr = 0x00000044,
  430. .current_drri_addr = 0x00000048,
  431. .host_ie_addr = 0x0000002c,
  432. .ctrl1_regs = &qcax_ctrl1,
  433. .cmd_halt = &qcax_cmd_halt,
  434. .host_ie = &qcax_host_ie,
  435. .wm_regs = &qcax_wm_reg,
  436. .misc_regs = &qcax_misc_reg,
  437. .wm_srcr = &qcax_wm_src_ring,
  438. .wm_dstr = &qcax_wm_dst_ring,
  439. };
  440. const struct ath10k_hw_clk_params qca6174_clk[ATH10K_HW_REFCLK_COUNT] = {
  441. {
  442. .refclk = 48000000,
  443. .div = 0xe,
  444. .rnfrac = 0x2aaa8,
  445. .settle_time = 2400,
  446. .refdiv = 0,
  447. .outdiv = 1,
  448. },
  449. {
  450. .refclk = 19200000,
  451. .div = 0x24,
  452. .rnfrac = 0x2aaa8,
  453. .settle_time = 960,
  454. .refdiv = 0,
  455. .outdiv = 1,
  456. },
  457. {
  458. .refclk = 24000000,
  459. .div = 0x1d,
  460. .rnfrac = 0x15551,
  461. .settle_time = 1200,
  462. .refdiv = 0,
  463. .outdiv = 1,
  464. },
  465. {
  466. .refclk = 26000000,
  467. .div = 0x1b,
  468. .rnfrac = 0x4ec4,
  469. .settle_time = 1300,
  470. .refdiv = 0,
  471. .outdiv = 1,
  472. },
  473. {
  474. .refclk = 37400000,
  475. .div = 0x12,
  476. .rnfrac = 0x34b49,
  477. .settle_time = 1870,
  478. .refdiv = 0,
  479. .outdiv = 1,
  480. },
  481. {
  482. .refclk = 38400000,
  483. .div = 0x12,
  484. .rnfrac = 0x15551,
  485. .settle_time = 1920,
  486. .refdiv = 0,
  487. .outdiv = 1,
  488. },
  489. {
  490. .refclk = 40000000,
  491. .div = 0x12,
  492. .rnfrac = 0x26665,
  493. .settle_time = 2000,
  494. .refdiv = 0,
  495. .outdiv = 1,
  496. },
  497. {
  498. .refclk = 52000000,
  499. .div = 0x1b,
  500. .rnfrac = 0x4ec4,
  501. .settle_time = 2600,
  502. .refdiv = 0,
  503. .outdiv = 1,
  504. },
  505. };
  506. void ath10k_hw_fill_survey_time(struct ath10k *ar, struct survey_info *survey,
  507. u32 cc, u32 rcc, u32 cc_prev, u32 rcc_prev)
  508. {
  509. u32 cc_fix = 0;
  510. u32 rcc_fix = 0;
  511. enum ath10k_hw_cc_wraparound_type wraparound_type;
  512. survey->filled |= SURVEY_INFO_TIME |
  513. SURVEY_INFO_TIME_BUSY;
  514. wraparound_type = ar->hw_params.cc_wraparound_type;
  515. if (cc < cc_prev || rcc < rcc_prev) {
  516. switch (wraparound_type) {
  517. case ATH10K_HW_CC_WRAP_SHIFTED_ALL:
  518. if (cc < cc_prev) {
  519. cc_fix = 0x7fffffff;
  520. survey->filled &= ~SURVEY_INFO_TIME_BUSY;
  521. }
  522. break;
  523. case ATH10K_HW_CC_WRAP_SHIFTED_EACH:
  524. if (cc < cc_prev)
  525. cc_fix = 0x7fffffff;
  526. if (rcc < rcc_prev)
  527. rcc_fix = 0x7fffffff;
  528. break;
  529. case ATH10K_HW_CC_WRAP_DISABLED:
  530. break;
  531. }
  532. }
  533. cc -= cc_prev - cc_fix;
  534. rcc -= rcc_prev - rcc_fix;
  535. survey->time = CCNT_TO_MSEC(ar, cc);
  536. survey->time_busy = CCNT_TO_MSEC(ar, rcc);
  537. }
  538. /* The firmware does not support setting the coverage class. Instead this
  539. * function monitors and modifies the corresponding MAC registers.
  540. */
  541. static void ath10k_hw_qca988x_set_coverage_class(struct ath10k *ar,
  542. s16 value)
  543. {
  544. u32 slottime_reg;
  545. u32 slottime;
  546. u32 timeout_reg;
  547. u32 ack_timeout;
  548. u32 cts_timeout;
  549. u32 phyclk_reg;
  550. u32 phyclk;
  551. u64 fw_dbglog_mask;
  552. u32 fw_dbglog_level;
  553. mutex_lock(&ar->conf_mutex);
  554. /* Only modify registers if the core is started. */
  555. if ((ar->state != ATH10K_STATE_ON) &&
  556. (ar->state != ATH10K_STATE_RESTARTED)) {
  557. spin_lock_bh(&ar->data_lock);
  558. /* Store config value for when radio boots up */
  559. ar->fw_coverage.coverage_class = value;
  560. spin_unlock_bh(&ar->data_lock);
  561. goto unlock;
  562. }
  563. /* Retrieve the current values of the two registers that need to be
  564. * adjusted.
  565. */
  566. slottime_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  567. WAVE1_PCU_GBL_IFS_SLOT);
  568. timeout_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  569. WAVE1_PCU_ACK_CTS_TIMEOUT);
  570. phyclk_reg = ath10k_hif_read32(ar, WLAN_MAC_BASE_ADDRESS +
  571. WAVE1_PHYCLK);
  572. phyclk = MS(phyclk_reg, WAVE1_PHYCLK_USEC) + 1;
  573. if (value < 0)
  574. value = ar->fw_coverage.coverage_class;
  575. /* Break out if the coverage class and registers have the expected
  576. * value.
  577. */
  578. if (value == ar->fw_coverage.coverage_class &&
  579. slottime_reg == ar->fw_coverage.reg_slottime_conf &&
  580. timeout_reg == ar->fw_coverage.reg_ack_cts_timeout_conf &&
  581. phyclk_reg == ar->fw_coverage.reg_phyclk)
  582. goto unlock;
  583. /* Store new initial register values from the firmware. */
  584. if (slottime_reg != ar->fw_coverage.reg_slottime_conf)
  585. ar->fw_coverage.reg_slottime_orig = slottime_reg;
  586. if (timeout_reg != ar->fw_coverage.reg_ack_cts_timeout_conf)
  587. ar->fw_coverage.reg_ack_cts_timeout_orig = timeout_reg;
  588. ar->fw_coverage.reg_phyclk = phyclk_reg;
  589. /* Calculate new value based on the (original) firmware calculation. */
  590. slottime_reg = ar->fw_coverage.reg_slottime_orig;
  591. timeout_reg = ar->fw_coverage.reg_ack_cts_timeout_orig;
  592. /* Do some sanity checks on the slottime register. */
  593. if (slottime_reg % phyclk) {
  594. ath10k_warn(ar,
  595. "failed to set coverage class: expected integer microsecond value in register\n");
  596. goto store_regs;
  597. }
  598. slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
  599. slottime = slottime / phyclk;
  600. if (slottime != 9 && slottime != 20) {
  601. ath10k_warn(ar,
  602. "failed to set coverage class: expected slot time of 9 or 20us in HW register. It is %uus.\n",
  603. slottime);
  604. goto store_regs;
  605. }
  606. /* Recalculate the register values by adding the additional propagation
  607. * delay (3us per coverage class).
  608. */
  609. slottime = MS(slottime_reg, WAVE1_PCU_GBL_IFS_SLOT);
  610. slottime += value * 3 * phyclk;
  611. slottime = min_t(u32, slottime, WAVE1_PCU_GBL_IFS_SLOT_MAX);
  612. slottime = SM(slottime, WAVE1_PCU_GBL_IFS_SLOT);
  613. slottime_reg = (slottime_reg & ~WAVE1_PCU_GBL_IFS_SLOT_MASK) | slottime;
  614. /* Update ack timeout (lower halfword). */
  615. ack_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
  616. ack_timeout += 3 * value * phyclk;
  617. ack_timeout = min_t(u32, ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
  618. ack_timeout = SM(ack_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_ACK);
  619. /* Update cts timeout (upper halfword). */
  620. cts_timeout = MS(timeout_reg, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
  621. cts_timeout += 3 * value * phyclk;
  622. cts_timeout = min_t(u32, cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_MAX);
  623. cts_timeout = SM(cts_timeout, WAVE1_PCU_ACK_CTS_TIMEOUT_CTS);
  624. timeout_reg = ack_timeout | cts_timeout;
  625. ath10k_hif_write32(ar,
  626. WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_GBL_IFS_SLOT,
  627. slottime_reg);
  628. ath10k_hif_write32(ar,
  629. WLAN_MAC_BASE_ADDRESS + WAVE1_PCU_ACK_CTS_TIMEOUT,
  630. timeout_reg);
  631. /* Ensure we have a debug level of WARN set for the case that the
  632. * coverage class is larger than 0. This is important as we need to
  633. * set the registers again if the firmware does an internal reset and
  634. * this way we will be notified of the event.
  635. */
  636. fw_dbglog_mask = ath10k_debug_get_fw_dbglog_mask(ar);
  637. fw_dbglog_level = ath10k_debug_get_fw_dbglog_level(ar);
  638. if (value > 0) {
  639. if (fw_dbglog_level > ATH10K_DBGLOG_LEVEL_WARN)
  640. fw_dbglog_level = ATH10K_DBGLOG_LEVEL_WARN;
  641. fw_dbglog_mask = ~0;
  642. }
  643. ath10k_wmi_dbglog_cfg(ar, fw_dbglog_mask, fw_dbglog_level);
  644. store_regs:
  645. /* After an error we will not retry setting the coverage class. */
  646. spin_lock_bh(&ar->data_lock);
  647. ar->fw_coverage.coverage_class = value;
  648. spin_unlock_bh(&ar->data_lock);
  649. ar->fw_coverage.reg_slottime_conf = slottime_reg;
  650. ar->fw_coverage.reg_ack_cts_timeout_conf = timeout_reg;
  651. unlock:
  652. mutex_unlock(&ar->conf_mutex);
  653. }
  654. /**
  655. * ath10k_hw_qca6174_enable_pll_clock() - enable the qca6174 hw pll clock
  656. * @ar: the ath10k blob
  657. *
  658. * This function is very hardware specific, the clock initialization
  659. * steps is very sensitive and could lead to unknown crash, so they
  660. * should be done in sequence.
  661. *
  662. * *** Be aware if you planned to refactor them. ***
  663. *
  664. * Return: 0 if successfully enable the pll, otherwise EINVAL
  665. */
  666. static int ath10k_hw_qca6174_enable_pll_clock(struct ath10k *ar)
  667. {
  668. int ret, wait_limit;
  669. u32 clk_div_addr, pll_init_addr, speed_addr;
  670. u32 addr, reg_val, mem_val;
  671. struct ath10k_hw_params *hw;
  672. const struct ath10k_hw_clk_params *hw_clk;
  673. hw = &ar->hw_params;
  674. if (ar->regs->core_clk_div_address == 0 ||
  675. ar->regs->cpu_pll_init_address == 0 ||
  676. ar->regs->cpu_speed_address == 0)
  677. return -EINVAL;
  678. clk_div_addr = ar->regs->core_clk_div_address;
  679. pll_init_addr = ar->regs->cpu_pll_init_address;
  680. speed_addr = ar->regs->cpu_speed_address;
  681. /* Read efuse register to find out the right hw clock configuration */
  682. addr = (RTC_SOC_BASE_ADDRESS | EFUSE_OFFSET);
  683. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  684. if (ret)
  685. return -EINVAL;
  686. /* sanitize if the hw refclk index is out of the boundary */
  687. if (MS(reg_val, EFUSE_XTAL_SEL) > ATH10K_HW_REFCLK_COUNT)
  688. return -EINVAL;
  689. hw_clk = &hw->hw_clk[MS(reg_val, EFUSE_XTAL_SEL)];
  690. /* Set the rnfrac and outdiv params to bb_pll register */
  691. addr = (RTC_SOC_BASE_ADDRESS | BB_PLL_CONFIG_OFFSET);
  692. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  693. if (ret)
  694. return -EINVAL;
  695. reg_val &= ~(BB_PLL_CONFIG_FRAC_MASK | BB_PLL_CONFIG_OUTDIV_MASK);
  696. reg_val |= (SM(hw_clk->rnfrac, BB_PLL_CONFIG_FRAC) |
  697. SM(hw_clk->outdiv, BB_PLL_CONFIG_OUTDIV));
  698. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  699. if (ret)
  700. return -EINVAL;
  701. /* Set the correct settle time value to pll_settle register */
  702. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_SETTLE_OFFSET);
  703. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  704. if (ret)
  705. return -EINVAL;
  706. reg_val &= ~WLAN_PLL_SETTLE_TIME_MASK;
  707. reg_val |= SM(hw_clk->settle_time, WLAN_PLL_SETTLE_TIME);
  708. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  709. if (ret)
  710. return -EINVAL;
  711. /* Set the clock_ctrl div to core_clk_ctrl register */
  712. addr = (RTC_SOC_BASE_ADDRESS | SOC_CORE_CLK_CTRL_OFFSET);
  713. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  714. if (ret)
  715. return -EINVAL;
  716. reg_val &= ~SOC_CORE_CLK_CTRL_DIV_MASK;
  717. reg_val |= SM(1, SOC_CORE_CLK_CTRL_DIV);
  718. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  719. if (ret)
  720. return -EINVAL;
  721. /* Set the clock_div register */
  722. mem_val = 1;
  723. ret = ath10k_bmi_write_memory(ar, clk_div_addr, &mem_val,
  724. sizeof(mem_val));
  725. if (ret)
  726. return -EINVAL;
  727. /* Configure the pll_control register */
  728. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
  729. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  730. if (ret)
  731. return -EINVAL;
  732. reg_val |= (SM(hw_clk->refdiv, WLAN_PLL_CONTROL_REFDIV) |
  733. SM(hw_clk->div, WLAN_PLL_CONTROL_DIV) |
  734. SM(1, WLAN_PLL_CONTROL_NOPWD));
  735. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  736. if (ret)
  737. return -EINVAL;
  738. /* busy wait (max 1s) the rtc_sync status register indicate ready */
  739. wait_limit = 100000;
  740. addr = (RTC_WMAC_BASE_ADDRESS | RTC_SYNC_STATUS_OFFSET);
  741. do {
  742. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  743. if (ret)
  744. return -EINVAL;
  745. if (!MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  746. break;
  747. wait_limit--;
  748. udelay(10);
  749. } while (wait_limit > 0);
  750. if (MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  751. return -EINVAL;
  752. /* Unset the pll_bypass in pll_control register */
  753. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
  754. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  755. if (ret)
  756. return -EINVAL;
  757. reg_val &= ~WLAN_PLL_CONTROL_BYPASS_MASK;
  758. reg_val |= SM(0, WLAN_PLL_CONTROL_BYPASS);
  759. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  760. if (ret)
  761. return -EINVAL;
  762. /* busy wait (max 1s) the rtc_sync status register indicate ready */
  763. wait_limit = 100000;
  764. addr = (RTC_WMAC_BASE_ADDRESS | RTC_SYNC_STATUS_OFFSET);
  765. do {
  766. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  767. if (ret)
  768. return -EINVAL;
  769. if (!MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  770. break;
  771. wait_limit--;
  772. udelay(10);
  773. } while (wait_limit > 0);
  774. if (MS(reg_val, RTC_SYNC_STATUS_PLL_CHANGING))
  775. return -EINVAL;
  776. /* Enable the hardware cpu clock register */
  777. addr = (RTC_SOC_BASE_ADDRESS | SOC_CPU_CLOCK_OFFSET);
  778. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  779. if (ret)
  780. return -EINVAL;
  781. reg_val &= ~SOC_CPU_CLOCK_STANDARD_MASK;
  782. reg_val |= SM(1, SOC_CPU_CLOCK_STANDARD);
  783. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  784. if (ret)
  785. return -EINVAL;
  786. /* unset the nopwd from pll_control register */
  787. addr = (RTC_WMAC_BASE_ADDRESS | WLAN_PLL_CONTROL_OFFSET);
  788. ret = ath10k_bmi_read_soc_reg(ar, addr, &reg_val);
  789. if (ret)
  790. return -EINVAL;
  791. reg_val &= ~WLAN_PLL_CONTROL_NOPWD_MASK;
  792. ret = ath10k_bmi_write_soc_reg(ar, addr, reg_val);
  793. if (ret)
  794. return -EINVAL;
  795. /* enable the pll_init register */
  796. mem_val = 1;
  797. ret = ath10k_bmi_write_memory(ar, pll_init_addr, &mem_val,
  798. sizeof(mem_val));
  799. if (ret)
  800. return -EINVAL;
  801. /* set the target clock frequency to speed register */
  802. ret = ath10k_bmi_write_memory(ar, speed_addr, &hw->target_cpu_freq,
  803. sizeof(hw->target_cpu_freq));
  804. if (ret)
  805. return -EINVAL;
  806. return 0;
  807. }
  808. const struct ath10k_hw_ops qca988x_ops = {
  809. .set_coverage_class = ath10k_hw_qca988x_set_coverage_class,
  810. };
  811. static int ath10k_qca99x0_rx_desc_get_l3_pad_bytes(struct htt_rx_desc *rxd)
  812. {
  813. return MS(__le32_to_cpu(rxd->msdu_end.qca99x0.info1),
  814. RX_MSDU_END_INFO1_L3_HDR_PAD);
  815. }
  816. const struct ath10k_hw_ops qca99x0_ops = {
  817. .rx_desc_get_l3_pad_bytes = ath10k_qca99x0_rx_desc_get_l3_pad_bytes,
  818. };
  819. const struct ath10k_hw_ops qca6174_ops = {
  820. .set_coverage_class = ath10k_hw_qca988x_set_coverage_class,
  821. .enable_pll_clk = ath10k_hw_qca6174_enable_pll_clock,
  822. };
  823. const struct ath10k_hw_ops wcn3990_ops = {};