snoc.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. /*
  2. * Copyright (c) 2018 The Linux Foundation. All rights reserved.
  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/module.h>
  17. #include <linux/kernel.h>
  18. #include "debug.h"
  19. #include "hif.h"
  20. #include "htc.h"
  21. #include "ce.h"
  22. #include "snoc.h"
  23. #include <linux/of.h>
  24. #include <linux/of_device.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/regulator/consumer.h>
  27. #include <linux/clk.h>
  28. #define WCN3990_CE_ATTR_FLAGS 0
  29. #define ATH10K_SNOC_RX_POST_RETRY_MS 50
  30. #define CE_POLL_PIPE 4
  31. static char *const ce_name[] = {
  32. "WLAN_CE_0",
  33. "WLAN_CE_1",
  34. "WLAN_CE_2",
  35. "WLAN_CE_3",
  36. "WLAN_CE_4",
  37. "WLAN_CE_5",
  38. "WLAN_CE_6",
  39. "WLAN_CE_7",
  40. "WLAN_CE_8",
  41. "WLAN_CE_9",
  42. "WLAN_CE_10",
  43. "WLAN_CE_11",
  44. };
  45. static struct ath10k_wcn3990_vreg_info vreg_cfg[] = {
  46. {NULL, "vdd-0.8-cx-mx", 800000, 800000, 0, 0, false},
  47. {NULL, "vdd-1.8-xo", 1800000, 1800000, 0, 0, false},
  48. {NULL, "vdd-1.3-rfa", 1304000, 1304000, 0, 0, false},
  49. {NULL, "vdd-3.3-ch0", 3312000, 3312000, 0, 0, false},
  50. };
  51. static struct ath10k_wcn3990_clk_info clk_cfg[] = {
  52. {NULL, "cxo_ref_clk_pin", 0, false},
  53. };
  54. static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
  55. static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
  56. static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
  57. static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
  58. static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
  59. static const struct ath10k_snoc_drv_priv drv_priv = {
  60. .hw_rev = ATH10K_HW_WCN3990,
  61. .dma_mask = DMA_BIT_MASK(37),
  62. };
  63. static struct ce_attr host_ce_config_wlan[] = {
  64. /* CE0: host->target HTC control streams */
  65. {
  66. .flags = CE_ATTR_FLAGS,
  67. .src_nentries = 16,
  68. .src_sz_max = 2048,
  69. .dest_nentries = 0,
  70. .send_cb = ath10k_snoc_htc_tx_cb,
  71. },
  72. /* CE1: target->host HTT + HTC control */
  73. {
  74. .flags = CE_ATTR_FLAGS,
  75. .src_nentries = 0,
  76. .src_sz_max = 2048,
  77. .dest_nentries = 512,
  78. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  79. },
  80. /* CE2: target->host WMI */
  81. {
  82. .flags = CE_ATTR_FLAGS,
  83. .src_nentries = 0,
  84. .src_sz_max = 2048,
  85. .dest_nentries = 64,
  86. .recv_cb = ath10k_snoc_htc_rx_cb,
  87. },
  88. /* CE3: host->target WMI */
  89. {
  90. .flags = CE_ATTR_FLAGS,
  91. .src_nentries = 32,
  92. .src_sz_max = 2048,
  93. .dest_nentries = 0,
  94. .send_cb = ath10k_snoc_htc_tx_cb,
  95. },
  96. /* CE4: host->target HTT */
  97. {
  98. .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
  99. .src_nentries = 256,
  100. .src_sz_max = 256,
  101. .dest_nentries = 0,
  102. .send_cb = ath10k_snoc_htt_tx_cb,
  103. },
  104. /* CE5: target->host HTT (ipa_uc->target ) */
  105. {
  106. .flags = CE_ATTR_FLAGS,
  107. .src_nentries = 0,
  108. .src_sz_max = 512,
  109. .dest_nentries = 512,
  110. .recv_cb = ath10k_snoc_htt_rx_cb,
  111. },
  112. /* CE6: target autonomous hif_memcpy */
  113. {
  114. .flags = CE_ATTR_FLAGS,
  115. .src_nentries = 0,
  116. .src_sz_max = 0,
  117. .dest_nentries = 0,
  118. },
  119. /* CE7: ce_diag, the Diagnostic Window */
  120. {
  121. .flags = CE_ATTR_FLAGS,
  122. .src_nentries = 2,
  123. .src_sz_max = 2048,
  124. .dest_nentries = 2,
  125. },
  126. /* CE8: Target to uMC */
  127. {
  128. .flags = CE_ATTR_FLAGS,
  129. .src_nentries = 0,
  130. .src_sz_max = 2048,
  131. .dest_nentries = 128,
  132. },
  133. /* CE9 target->host HTT */
  134. {
  135. .flags = CE_ATTR_FLAGS,
  136. .src_nentries = 0,
  137. .src_sz_max = 2048,
  138. .dest_nentries = 512,
  139. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  140. },
  141. /* CE10: target->host HTT */
  142. {
  143. .flags = CE_ATTR_FLAGS,
  144. .src_nentries = 0,
  145. .src_sz_max = 2048,
  146. .dest_nentries = 512,
  147. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  148. },
  149. /* CE11: target -> host PKTLOG */
  150. {
  151. .flags = CE_ATTR_FLAGS,
  152. .src_nentries = 0,
  153. .src_sz_max = 2048,
  154. .dest_nentries = 512,
  155. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  156. },
  157. };
  158. static struct service_to_pipe target_service_to_ce_map_wlan[] = {
  159. {
  160. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
  161. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  162. __cpu_to_le32(3),
  163. },
  164. {
  165. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
  166. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  167. __cpu_to_le32(2),
  168. },
  169. {
  170. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
  171. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  172. __cpu_to_le32(3),
  173. },
  174. {
  175. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
  176. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  177. __cpu_to_le32(2),
  178. },
  179. {
  180. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
  181. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  182. __cpu_to_le32(3),
  183. },
  184. {
  185. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
  186. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  187. __cpu_to_le32(2),
  188. },
  189. {
  190. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
  191. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  192. __cpu_to_le32(3),
  193. },
  194. {
  195. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
  196. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  197. __cpu_to_le32(2),
  198. },
  199. {
  200. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
  201. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  202. __cpu_to_le32(3),
  203. },
  204. {
  205. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
  206. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  207. __cpu_to_le32(2),
  208. },
  209. {
  210. __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
  211. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  212. __cpu_to_le32(0),
  213. },
  214. {
  215. __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
  216. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  217. __cpu_to_le32(2),
  218. },
  219. { /* not used */
  220. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  221. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  222. __cpu_to_le32(0),
  223. },
  224. { /* not used */
  225. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  226. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  227. __cpu_to_le32(2),
  228. },
  229. {
  230. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
  231. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  232. __cpu_to_le32(4),
  233. },
  234. {
  235. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
  236. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  237. __cpu_to_le32(1),
  238. },
  239. { /* not used */
  240. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  241. __cpu_to_le32(PIPEDIR_OUT),
  242. __cpu_to_le32(5),
  243. },
  244. { /* in = DL = target -> host */
  245. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA2_MSG),
  246. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  247. __cpu_to_le32(9),
  248. },
  249. { /* in = DL = target -> host */
  250. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA3_MSG),
  251. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  252. __cpu_to_le32(10),
  253. },
  254. { /* in = DL = target -> host pktlog */
  255. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_LOG_MSG),
  256. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  257. __cpu_to_le32(11),
  258. },
  259. /* (Additions here) */
  260. { /* must be last */
  261. __cpu_to_le32(0),
  262. __cpu_to_le32(0),
  263. __cpu_to_le32(0),
  264. },
  265. };
  266. void ath10k_snoc_write32(struct ath10k *ar, u32 offset, u32 value)
  267. {
  268. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  269. iowrite32(value, ar_snoc->mem + offset);
  270. }
  271. u32 ath10k_snoc_read32(struct ath10k *ar, u32 offset)
  272. {
  273. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  274. u32 val;
  275. val = ioread32(ar_snoc->mem + offset);
  276. return val;
  277. }
  278. static int __ath10k_snoc_rx_post_buf(struct ath10k_snoc_pipe *pipe)
  279. {
  280. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  281. struct ath10k *ar = pipe->hif_ce_state;
  282. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  283. struct sk_buff *skb;
  284. dma_addr_t paddr;
  285. int ret;
  286. skb = dev_alloc_skb(pipe->buf_sz);
  287. if (!skb)
  288. return -ENOMEM;
  289. WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
  290. paddr = dma_map_single(ar->dev, skb->data,
  291. skb->len + skb_tailroom(skb),
  292. DMA_FROM_DEVICE);
  293. if (unlikely(dma_mapping_error(ar->dev, paddr))) {
  294. ath10k_warn(ar, "failed to dma map snoc rx buf\n");
  295. dev_kfree_skb_any(skb);
  296. return -EIO;
  297. }
  298. ATH10K_SKB_RXCB(skb)->paddr = paddr;
  299. spin_lock_bh(&ce->ce_lock);
  300. ret = ce_pipe->ops->ce_rx_post_buf(ce_pipe, skb, paddr);
  301. spin_unlock_bh(&ce->ce_lock);
  302. if (ret) {
  303. dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
  304. DMA_FROM_DEVICE);
  305. dev_kfree_skb_any(skb);
  306. return ret;
  307. }
  308. return 0;
  309. }
  310. static void ath10k_snoc_rx_post_pipe(struct ath10k_snoc_pipe *pipe)
  311. {
  312. struct ath10k *ar = pipe->hif_ce_state;
  313. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  314. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  315. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  316. int ret, num;
  317. if (pipe->buf_sz == 0)
  318. return;
  319. if (!ce_pipe->dest_ring)
  320. return;
  321. spin_lock_bh(&ce->ce_lock);
  322. num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
  323. spin_unlock_bh(&ce->ce_lock);
  324. while (num--) {
  325. ret = __ath10k_snoc_rx_post_buf(pipe);
  326. if (ret) {
  327. if (ret == -ENOSPC)
  328. break;
  329. ath10k_warn(ar, "failed to post rx buf: %d\n", ret);
  330. mod_timer(&ar_snoc->rx_post_retry, jiffies +
  331. ATH10K_SNOC_RX_POST_RETRY_MS);
  332. break;
  333. }
  334. }
  335. }
  336. static void ath10k_snoc_rx_post(struct ath10k *ar)
  337. {
  338. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  339. int i;
  340. for (i = 0; i < CE_COUNT; i++)
  341. ath10k_snoc_rx_post_pipe(&ar_snoc->pipe_info[i]);
  342. }
  343. static void ath10k_snoc_process_rx_cb(struct ath10k_ce_pipe *ce_state,
  344. void (*callback)(struct ath10k *ar,
  345. struct sk_buff *skb))
  346. {
  347. struct ath10k *ar = ce_state->ar;
  348. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  349. struct ath10k_snoc_pipe *pipe_info = &ar_snoc->pipe_info[ce_state->id];
  350. struct sk_buff *skb;
  351. struct sk_buff_head list;
  352. void *transfer_context;
  353. unsigned int nbytes, max_nbytes;
  354. __skb_queue_head_init(&list);
  355. while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
  356. &nbytes) == 0) {
  357. skb = transfer_context;
  358. max_nbytes = skb->len + skb_tailroom(skb);
  359. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  360. max_nbytes, DMA_FROM_DEVICE);
  361. if (unlikely(max_nbytes < nbytes)) {
  362. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  363. nbytes, max_nbytes);
  364. dev_kfree_skb_any(skb);
  365. continue;
  366. }
  367. skb_put(skb, nbytes);
  368. __skb_queue_tail(&list, skb);
  369. }
  370. while ((skb = __skb_dequeue(&list))) {
  371. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc rx ce pipe %d len %d\n",
  372. ce_state->id, skb->len);
  373. callback(ar, skb);
  374. }
  375. ath10k_snoc_rx_post_pipe(pipe_info);
  376. }
  377. static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  378. {
  379. ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  380. }
  381. static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  382. {
  383. /* CE4 polling needs to be done whenever CE pipe which transports
  384. * HTT Rx (target->host) is processed.
  385. */
  386. ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE);
  387. ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  388. }
  389. static void ath10k_snoc_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
  390. {
  391. skb_pull(skb, sizeof(struct ath10k_htc_hdr));
  392. ath10k_htt_t2h_msg_handler(ar, skb);
  393. }
  394. static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
  395. {
  396. ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE);
  397. ath10k_snoc_process_rx_cb(ce_state, ath10k_snoc_htt_rx_deliver);
  398. }
  399. static void ath10k_snoc_rx_replenish_retry(struct timer_list *t)
  400. {
  401. struct ath10k_pci *ar_snoc = from_timer(ar_snoc, t, rx_post_retry);
  402. struct ath10k *ar = ar_snoc->ar;
  403. ath10k_snoc_rx_post(ar);
  404. }
  405. static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
  406. {
  407. struct ath10k *ar = ce_state->ar;
  408. struct sk_buff_head list;
  409. struct sk_buff *skb;
  410. __skb_queue_head_init(&list);
  411. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  412. if (!skb)
  413. continue;
  414. __skb_queue_tail(&list, skb);
  415. }
  416. while ((skb = __skb_dequeue(&list)))
  417. ath10k_htc_tx_completion_handler(ar, skb);
  418. }
  419. static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
  420. {
  421. struct ath10k *ar = ce_state->ar;
  422. struct sk_buff *skb;
  423. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  424. if (!skb)
  425. continue;
  426. dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
  427. skb->len, DMA_TO_DEVICE);
  428. ath10k_htt_hif_tx_complete(ar, skb);
  429. }
  430. }
  431. static int ath10k_snoc_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  432. struct ath10k_hif_sg_item *items, int n_items)
  433. {
  434. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  435. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  436. struct ath10k_snoc_pipe *snoc_pipe;
  437. struct ath10k_ce_pipe *ce_pipe;
  438. int err, i = 0;
  439. snoc_pipe = &ar_snoc->pipe_info[pipe_id];
  440. ce_pipe = snoc_pipe->ce_hdl;
  441. spin_lock_bh(&ce->ce_lock);
  442. for (i = 0; i < n_items - 1; i++) {
  443. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  444. "snoc tx item %d paddr %pad len %d n_items %d\n",
  445. i, &items[i].paddr, items[i].len, n_items);
  446. err = ath10k_ce_send_nolock(ce_pipe,
  447. items[i].transfer_context,
  448. items[i].paddr,
  449. items[i].len,
  450. items[i].transfer_id,
  451. CE_SEND_FLAG_GATHER);
  452. if (err)
  453. goto err;
  454. }
  455. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  456. "snoc tx item %d paddr %pad len %d n_items %d\n",
  457. i, &items[i].paddr, items[i].len, n_items);
  458. err = ath10k_ce_send_nolock(ce_pipe,
  459. items[i].transfer_context,
  460. items[i].paddr,
  461. items[i].len,
  462. items[i].transfer_id,
  463. 0);
  464. if (err)
  465. goto err;
  466. spin_unlock_bh(&ce->ce_lock);
  467. return 0;
  468. err:
  469. for (; i > 0; i--)
  470. __ath10k_ce_send_revert(ce_pipe);
  471. spin_unlock_bh(&ce->ce_lock);
  472. return err;
  473. }
  474. static int ath10k_snoc_hif_get_target_info(struct ath10k *ar,
  475. struct bmi_target_info *target_info)
  476. {
  477. target_info->version = ATH10K_HW_WCN3990;
  478. target_info->type = ATH10K_HW_WCN3990;
  479. return 0;
  480. }
  481. static u16 ath10k_snoc_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
  482. {
  483. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  484. ath10k_dbg(ar, ATH10K_DBG_SNOC, "hif get free queue number\n");
  485. return ath10k_ce_num_free_src_entries(ar_snoc->pipe_info[pipe].ce_hdl);
  486. }
  487. static void ath10k_snoc_hif_send_complete_check(struct ath10k *ar, u8 pipe,
  488. int force)
  489. {
  490. int resources;
  491. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif send complete check\n");
  492. if (!force) {
  493. resources = ath10k_snoc_hif_get_free_queue_number(ar, pipe);
  494. if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
  495. return;
  496. }
  497. ath10k_ce_per_engine_service(ar, pipe);
  498. }
  499. static int ath10k_snoc_hif_map_service_to_pipe(struct ath10k *ar,
  500. u16 service_id,
  501. u8 *ul_pipe, u8 *dl_pipe)
  502. {
  503. const struct service_to_pipe *entry;
  504. bool ul_set = false, dl_set = false;
  505. int i;
  506. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif map service\n");
  507. for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
  508. entry = &target_service_to_ce_map_wlan[i];
  509. if (__le32_to_cpu(entry->service_id) != service_id)
  510. continue;
  511. switch (__le32_to_cpu(entry->pipedir)) {
  512. case PIPEDIR_NONE:
  513. break;
  514. case PIPEDIR_IN:
  515. WARN_ON(dl_set);
  516. *dl_pipe = __le32_to_cpu(entry->pipenum);
  517. dl_set = true;
  518. break;
  519. case PIPEDIR_OUT:
  520. WARN_ON(ul_set);
  521. *ul_pipe = __le32_to_cpu(entry->pipenum);
  522. ul_set = true;
  523. break;
  524. case PIPEDIR_INOUT:
  525. WARN_ON(dl_set);
  526. WARN_ON(ul_set);
  527. *dl_pipe = __le32_to_cpu(entry->pipenum);
  528. *ul_pipe = __le32_to_cpu(entry->pipenum);
  529. dl_set = true;
  530. ul_set = true;
  531. break;
  532. }
  533. }
  534. if (WARN_ON(!ul_set || !dl_set))
  535. return -ENOENT;
  536. return 0;
  537. }
  538. static void ath10k_snoc_hif_get_default_pipe(struct ath10k *ar,
  539. u8 *ul_pipe, u8 *dl_pipe)
  540. {
  541. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif get default pipe\n");
  542. (void)ath10k_snoc_hif_map_service_to_pipe(ar,
  543. ATH10K_HTC_SVC_ID_RSVD_CTRL,
  544. ul_pipe, dl_pipe);
  545. }
  546. static inline void ath10k_snoc_irq_disable(struct ath10k *ar)
  547. {
  548. ath10k_ce_disable_interrupts(ar);
  549. }
  550. static inline void ath10k_snoc_irq_enable(struct ath10k *ar)
  551. {
  552. ath10k_ce_enable_interrupts(ar);
  553. }
  554. static void ath10k_snoc_rx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe)
  555. {
  556. struct ath10k_ce_pipe *ce_pipe;
  557. struct ath10k_ce_ring *ce_ring;
  558. struct sk_buff *skb;
  559. struct ath10k *ar;
  560. int i;
  561. ar = snoc_pipe->hif_ce_state;
  562. ce_pipe = snoc_pipe->ce_hdl;
  563. ce_ring = ce_pipe->dest_ring;
  564. if (!ce_ring)
  565. return;
  566. if (!snoc_pipe->buf_sz)
  567. return;
  568. for (i = 0; i < ce_ring->nentries; i++) {
  569. skb = ce_ring->per_transfer_context[i];
  570. if (!skb)
  571. continue;
  572. ce_ring->per_transfer_context[i] = NULL;
  573. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  574. skb->len + skb_tailroom(skb),
  575. DMA_FROM_DEVICE);
  576. dev_kfree_skb_any(skb);
  577. }
  578. }
  579. static void ath10k_snoc_tx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe)
  580. {
  581. struct ath10k_ce_pipe *ce_pipe;
  582. struct ath10k_ce_ring *ce_ring;
  583. struct ath10k_snoc *ar_snoc;
  584. struct sk_buff *skb;
  585. struct ath10k *ar;
  586. int i;
  587. ar = snoc_pipe->hif_ce_state;
  588. ar_snoc = ath10k_snoc_priv(ar);
  589. ce_pipe = snoc_pipe->ce_hdl;
  590. ce_ring = ce_pipe->src_ring;
  591. if (!ce_ring)
  592. return;
  593. if (!snoc_pipe->buf_sz)
  594. return;
  595. for (i = 0; i < ce_ring->nentries; i++) {
  596. skb = ce_ring->per_transfer_context[i];
  597. if (!skb)
  598. continue;
  599. ce_ring->per_transfer_context[i] = NULL;
  600. ath10k_htc_tx_completion_handler(ar, skb);
  601. }
  602. }
  603. static void ath10k_snoc_buffer_cleanup(struct ath10k *ar)
  604. {
  605. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  606. struct ath10k_snoc_pipe *pipe_info;
  607. int pipe_num;
  608. del_timer_sync(&ar_snoc->rx_post_retry);
  609. for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
  610. pipe_info = &ar_snoc->pipe_info[pipe_num];
  611. ath10k_snoc_rx_pipe_cleanup(pipe_info);
  612. ath10k_snoc_tx_pipe_cleanup(pipe_info);
  613. }
  614. }
  615. static void ath10k_snoc_hif_stop(struct ath10k *ar)
  616. {
  617. ath10k_snoc_irq_disable(ar);
  618. ath10k_snoc_buffer_cleanup(ar);
  619. napi_synchronize(&ar->napi);
  620. napi_disable(&ar->napi);
  621. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
  622. }
  623. static int ath10k_snoc_hif_start(struct ath10k *ar)
  624. {
  625. ath10k_snoc_irq_enable(ar);
  626. ath10k_snoc_rx_post(ar);
  627. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
  628. return 0;
  629. }
  630. static int ath10k_snoc_init_pipes(struct ath10k *ar)
  631. {
  632. int i, ret;
  633. for (i = 0; i < CE_COUNT; i++) {
  634. ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
  635. if (ret) {
  636. ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
  637. i, ret);
  638. return ret;
  639. }
  640. }
  641. return 0;
  642. }
  643. static int ath10k_snoc_wlan_enable(struct ath10k *ar)
  644. {
  645. return 0;
  646. }
  647. static void ath10k_snoc_wlan_disable(struct ath10k *ar)
  648. {
  649. }
  650. static void ath10k_snoc_hif_power_down(struct ath10k *ar)
  651. {
  652. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
  653. ath10k_snoc_wlan_disable(ar);
  654. ath10k_ce_free_rri(ar);
  655. }
  656. static int ath10k_snoc_hif_power_up(struct ath10k *ar)
  657. {
  658. int ret;
  659. ath10k_dbg(ar, ATH10K_DBG_SNOC, "%s:WCN3990 driver state = %d\n",
  660. __func__, ar->state);
  661. ret = ath10k_snoc_wlan_enable(ar);
  662. if (ret) {
  663. ath10k_err(ar, "failed to enable wcn3990: %d\n", ret);
  664. return ret;
  665. }
  666. ath10k_ce_alloc_rri(ar);
  667. ret = ath10k_snoc_init_pipes(ar);
  668. if (ret) {
  669. ath10k_err(ar, "failed to initialize CE: %d\n", ret);
  670. goto err_wlan_enable;
  671. }
  672. napi_enable(&ar->napi);
  673. return 0;
  674. err_wlan_enable:
  675. ath10k_snoc_wlan_disable(ar);
  676. return ret;
  677. }
  678. static const struct ath10k_hif_ops ath10k_snoc_hif_ops = {
  679. .read32 = ath10k_snoc_read32,
  680. .write32 = ath10k_snoc_write32,
  681. .start = ath10k_snoc_hif_start,
  682. .stop = ath10k_snoc_hif_stop,
  683. .map_service_to_pipe = ath10k_snoc_hif_map_service_to_pipe,
  684. .get_default_pipe = ath10k_snoc_hif_get_default_pipe,
  685. .power_up = ath10k_snoc_hif_power_up,
  686. .power_down = ath10k_snoc_hif_power_down,
  687. .tx_sg = ath10k_snoc_hif_tx_sg,
  688. .send_complete_check = ath10k_snoc_hif_send_complete_check,
  689. .get_free_queue_number = ath10k_snoc_hif_get_free_queue_number,
  690. .get_target_info = ath10k_snoc_hif_get_target_info,
  691. };
  692. static const struct ath10k_bus_ops ath10k_snoc_bus_ops = {
  693. .read32 = ath10k_snoc_read32,
  694. .write32 = ath10k_snoc_write32,
  695. };
  696. int ath10k_snoc_get_ce_id_from_irq(struct ath10k *ar, int irq)
  697. {
  698. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  699. int i;
  700. for (i = 0; i < CE_COUNT_MAX; i++) {
  701. if (ar_snoc->ce_irqs[i].irq_line == irq)
  702. return i;
  703. }
  704. ath10k_err(ar, "No matching CE id for irq %d\n", irq);
  705. return -EINVAL;
  706. }
  707. static irqreturn_t ath10k_snoc_per_engine_handler(int irq, void *arg)
  708. {
  709. struct ath10k *ar = arg;
  710. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  711. int ce_id = ath10k_snoc_get_ce_id_from_irq(ar, irq);
  712. if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_snoc->pipe_info)) {
  713. ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
  714. ce_id);
  715. return IRQ_HANDLED;
  716. }
  717. ath10k_snoc_irq_disable(ar);
  718. napi_schedule(&ar->napi);
  719. return IRQ_HANDLED;
  720. }
  721. static int ath10k_snoc_napi_poll(struct napi_struct *ctx, int budget)
  722. {
  723. struct ath10k *ar = container_of(ctx, struct ath10k, napi);
  724. int done = 0;
  725. ath10k_ce_per_engine_service_any(ar);
  726. done = ath10k_htt_txrx_compl_task(ar, budget);
  727. if (done < budget) {
  728. napi_complete(ctx);
  729. ath10k_snoc_irq_enable(ar);
  730. }
  731. return done;
  732. }
  733. void ath10k_snoc_init_napi(struct ath10k *ar)
  734. {
  735. netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_snoc_napi_poll,
  736. ATH10K_NAPI_BUDGET);
  737. }
  738. static int ath10k_snoc_request_irq(struct ath10k *ar)
  739. {
  740. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  741. int irqflags = IRQF_TRIGGER_RISING;
  742. int ret, id;
  743. for (id = 0; id < CE_COUNT_MAX; id++) {
  744. ret = request_irq(ar_snoc->ce_irqs[id].irq_line,
  745. ath10k_snoc_per_engine_handler,
  746. irqflags, ce_name[id], ar);
  747. if (ret) {
  748. ath10k_err(ar,
  749. "failed to register IRQ handler for CE %d: %d",
  750. id, ret);
  751. goto err_irq;
  752. }
  753. }
  754. return 0;
  755. err_irq:
  756. for (id -= 1; id >= 0; id--)
  757. free_irq(ar_snoc->ce_irqs[id].irq_line, ar);
  758. return ret;
  759. }
  760. static void ath10k_snoc_free_irq(struct ath10k *ar)
  761. {
  762. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  763. int id;
  764. for (id = 0; id < CE_COUNT_MAX; id++)
  765. free_irq(ar_snoc->ce_irqs[id].irq_line, ar);
  766. }
  767. static int ath10k_snoc_resource_init(struct ath10k *ar)
  768. {
  769. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  770. struct platform_device *pdev;
  771. struct resource *res;
  772. int i, ret = 0;
  773. pdev = ar_snoc->dev;
  774. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "membase");
  775. if (!res) {
  776. ath10k_err(ar, "Memory base not found in DT\n");
  777. return -EINVAL;
  778. }
  779. ar_snoc->mem_pa = res->start;
  780. ar_snoc->mem = devm_ioremap(&pdev->dev, ar_snoc->mem_pa,
  781. resource_size(res));
  782. if (!ar_snoc->mem) {
  783. ath10k_err(ar, "Memory base ioremap failed with physical address %pa\n",
  784. &ar_snoc->mem_pa);
  785. return -EINVAL;
  786. }
  787. for (i = 0; i < CE_COUNT; i++) {
  788. res = platform_get_resource(ar_snoc->dev, IORESOURCE_IRQ, i);
  789. if (!res) {
  790. ath10k_err(ar, "failed to get IRQ%d\n", i);
  791. ret = -ENODEV;
  792. goto out;
  793. }
  794. ar_snoc->ce_irqs[i].irq_line = res->start;
  795. }
  796. out:
  797. return ret;
  798. }
  799. static int ath10k_snoc_setup_resource(struct ath10k *ar)
  800. {
  801. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  802. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  803. struct ath10k_snoc_pipe *pipe;
  804. int i, ret;
  805. timer_setup(&ar_snoc->rx_post_retry, ath10k_snoc_rx_replenish_retry, 0);
  806. spin_lock_init(&ce->ce_lock);
  807. for (i = 0; i < CE_COUNT; i++) {
  808. pipe = &ar_snoc->pipe_info[i];
  809. pipe->ce_hdl = &ce->ce_states[i];
  810. pipe->pipe_num = i;
  811. pipe->hif_ce_state = ar;
  812. ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
  813. if (ret) {
  814. ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
  815. i, ret);
  816. return ret;
  817. }
  818. pipe->buf_sz = host_ce_config_wlan[i].src_sz_max;
  819. }
  820. ath10k_snoc_init_napi(ar);
  821. return 0;
  822. }
  823. static void ath10k_snoc_release_resource(struct ath10k *ar)
  824. {
  825. int i;
  826. netif_napi_del(&ar->napi);
  827. for (i = 0; i < CE_COUNT; i++)
  828. ath10k_ce_free_pipe(ar, i);
  829. }
  830. static int ath10k_get_vreg_info(struct ath10k *ar, struct device *dev,
  831. struct ath10k_wcn3990_vreg_info *vreg_info)
  832. {
  833. struct regulator *reg;
  834. int ret = 0;
  835. reg = devm_regulator_get_optional(dev, vreg_info->name);
  836. if (IS_ERR(reg)) {
  837. ret = PTR_ERR(reg);
  838. if (ret == -EPROBE_DEFER) {
  839. ath10k_err(ar, "EPROBE_DEFER for regulator: %s\n",
  840. vreg_info->name);
  841. return ret;
  842. }
  843. if (vreg_info->required) {
  844. ath10k_err(ar, "Regulator %s doesn't exist: %d\n",
  845. vreg_info->name, ret);
  846. return ret;
  847. }
  848. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  849. "Optional regulator %s doesn't exist: %d\n",
  850. vreg_info->name, ret);
  851. goto done;
  852. }
  853. vreg_info->reg = reg;
  854. done:
  855. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  856. "snog vreg %s min_v %u max_v %u load_ua %u settle_delay %lu\n",
  857. vreg_info->name, vreg_info->min_v, vreg_info->max_v,
  858. vreg_info->load_ua, vreg_info->settle_delay);
  859. return 0;
  860. }
  861. static int ath10k_get_clk_info(struct ath10k *ar, struct device *dev,
  862. struct ath10k_wcn3990_clk_info *clk_info)
  863. {
  864. struct clk *handle;
  865. int ret = 0;
  866. handle = devm_clk_get(dev, clk_info->name);
  867. if (IS_ERR(handle)) {
  868. ret = PTR_ERR(handle);
  869. if (clk_info->required) {
  870. ath10k_err(ar, "snoc clock %s isn't available: %d\n",
  871. clk_info->name, ret);
  872. return ret;
  873. }
  874. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc ignoring clock %s: %d\n",
  875. clk_info->name,
  876. ret);
  877. return 0;
  878. }
  879. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s freq %u\n",
  880. clk_info->name, clk_info->freq);
  881. clk_info->handle = handle;
  882. return ret;
  883. }
  884. static int ath10k_wcn3990_vreg_on(struct ath10k *ar)
  885. {
  886. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  887. struct ath10k_wcn3990_vreg_info *vreg_info;
  888. int ret = 0;
  889. int i;
  890. for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) {
  891. vreg_info = &ar_snoc->vreg[i];
  892. if (!vreg_info->reg)
  893. continue;
  894. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being enabled\n",
  895. vreg_info->name);
  896. ret = regulator_set_voltage(vreg_info->reg, vreg_info->min_v,
  897. vreg_info->max_v);
  898. if (ret) {
  899. ath10k_err(ar,
  900. "failed to set regulator %s voltage-min: %d voltage-max: %d\n",
  901. vreg_info->name, vreg_info->min_v, vreg_info->max_v);
  902. goto err_reg_config;
  903. }
  904. if (vreg_info->load_ua) {
  905. ret = regulator_set_load(vreg_info->reg,
  906. vreg_info->load_ua);
  907. if (ret < 0) {
  908. ath10k_err(ar,
  909. "failed to set regulator %s load: %d\n",
  910. vreg_info->name,
  911. vreg_info->load_ua);
  912. goto err_reg_config;
  913. }
  914. }
  915. ret = regulator_enable(vreg_info->reg);
  916. if (ret) {
  917. ath10k_err(ar, "failed to enable regulator %s\n",
  918. vreg_info->name);
  919. goto err_reg_config;
  920. }
  921. if (vreg_info->settle_delay)
  922. udelay(vreg_info->settle_delay);
  923. }
  924. return 0;
  925. err_reg_config:
  926. for (; i >= 0; i--) {
  927. vreg_info = &ar_snoc->vreg[i];
  928. if (!vreg_info->reg)
  929. continue;
  930. regulator_disable(vreg_info->reg);
  931. regulator_set_load(vreg_info->reg, 0);
  932. regulator_set_voltage(vreg_info->reg, 0, vreg_info->max_v);
  933. }
  934. return ret;
  935. }
  936. static int ath10k_wcn3990_vreg_off(struct ath10k *ar)
  937. {
  938. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  939. struct ath10k_wcn3990_vreg_info *vreg_info;
  940. int ret = 0;
  941. int i;
  942. for (i = ARRAY_SIZE(vreg_cfg) - 1; i >= 0; i--) {
  943. vreg_info = &ar_snoc->vreg[i];
  944. if (!vreg_info->reg)
  945. continue;
  946. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being disabled\n",
  947. vreg_info->name);
  948. ret = regulator_disable(vreg_info->reg);
  949. if (ret)
  950. ath10k_err(ar, "failed to disable regulator %s\n",
  951. vreg_info->name);
  952. ret = regulator_set_load(vreg_info->reg, 0);
  953. if (ret < 0)
  954. ath10k_err(ar, "failed to set load %s\n",
  955. vreg_info->name);
  956. ret = regulator_set_voltage(vreg_info->reg, 0,
  957. vreg_info->max_v);
  958. if (ret)
  959. ath10k_err(ar, "failed to set voltage %s\n",
  960. vreg_info->name);
  961. }
  962. return ret;
  963. }
  964. static int ath10k_wcn3990_clk_init(struct ath10k *ar)
  965. {
  966. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  967. struct ath10k_wcn3990_clk_info *clk_info;
  968. int ret = 0;
  969. int i;
  970. for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
  971. clk_info = &ar_snoc->clk[i];
  972. if (!clk_info->handle)
  973. continue;
  974. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being enabled\n",
  975. clk_info->name);
  976. if (clk_info->freq) {
  977. ret = clk_set_rate(clk_info->handle, clk_info->freq);
  978. if (ret) {
  979. ath10k_err(ar, "failed to set clock %s freq %u\n",
  980. clk_info->name, clk_info->freq);
  981. goto err_clock_config;
  982. }
  983. }
  984. ret = clk_prepare_enable(clk_info->handle);
  985. if (ret) {
  986. ath10k_err(ar, "failed to enable clock %s\n",
  987. clk_info->name);
  988. goto err_clock_config;
  989. }
  990. }
  991. return 0;
  992. err_clock_config:
  993. for (; i >= 0; i--) {
  994. clk_info = &ar_snoc->clk[i];
  995. if (!clk_info->handle)
  996. continue;
  997. clk_disable_unprepare(clk_info->handle);
  998. }
  999. return ret;
  1000. }
  1001. static int ath10k_wcn3990_clk_deinit(struct ath10k *ar)
  1002. {
  1003. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  1004. struct ath10k_wcn3990_clk_info *clk_info;
  1005. int i;
  1006. for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
  1007. clk_info = &ar_snoc->clk[i];
  1008. if (!clk_info->handle)
  1009. continue;
  1010. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being disabled\n",
  1011. clk_info->name);
  1012. clk_disable_unprepare(clk_info->handle);
  1013. }
  1014. return 0;
  1015. }
  1016. static int ath10k_hw_power_on(struct ath10k *ar)
  1017. {
  1018. int ret;
  1019. ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power on\n");
  1020. ret = ath10k_wcn3990_vreg_on(ar);
  1021. if (ret)
  1022. return ret;
  1023. ret = ath10k_wcn3990_clk_init(ar);
  1024. if (ret)
  1025. goto vreg_off;
  1026. return ret;
  1027. vreg_off:
  1028. ath10k_wcn3990_vreg_off(ar);
  1029. return ret;
  1030. }
  1031. static int ath10k_hw_power_off(struct ath10k *ar)
  1032. {
  1033. int ret;
  1034. ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power off\n");
  1035. ath10k_wcn3990_clk_deinit(ar);
  1036. ret = ath10k_wcn3990_vreg_off(ar);
  1037. return ret;
  1038. }
  1039. static const struct of_device_id ath10k_snoc_dt_match[] = {
  1040. { .compatible = "qcom,wcn3990-wifi",
  1041. .data = &drv_priv,
  1042. },
  1043. { }
  1044. };
  1045. MODULE_DEVICE_TABLE(of, ath10k_snoc_dt_match);
  1046. static int ath10k_snoc_probe(struct platform_device *pdev)
  1047. {
  1048. const struct ath10k_snoc_drv_priv *drv_data;
  1049. const struct of_device_id *of_id;
  1050. struct ath10k_snoc *ar_snoc;
  1051. struct device *dev;
  1052. struct ath10k *ar;
  1053. int ret;
  1054. u32 i;
  1055. of_id = of_match_device(ath10k_snoc_dt_match, &pdev->dev);
  1056. if (!of_id) {
  1057. dev_err(&pdev->dev, "failed to find matching device tree id\n");
  1058. return -EINVAL;
  1059. }
  1060. drv_data = of_id->data;
  1061. dev = &pdev->dev;
  1062. ret = dma_set_mask_and_coherent(dev, drv_data->dma_mask);
  1063. if (ret) {
  1064. dev_err(dev, "failed to set dma mask: %d", ret);
  1065. return ret;
  1066. }
  1067. ar = ath10k_core_create(sizeof(*ar_snoc), dev, ATH10K_BUS_SNOC,
  1068. drv_data->hw_rev, &ath10k_snoc_hif_ops);
  1069. if (!ar) {
  1070. dev_err(dev, "failed to allocate core\n");
  1071. return -ENOMEM;
  1072. }
  1073. ar_snoc = ath10k_snoc_priv(ar);
  1074. ar_snoc->dev = pdev;
  1075. platform_set_drvdata(pdev, ar);
  1076. ar_snoc->ar = ar;
  1077. ar_snoc->ce.bus_ops = &ath10k_snoc_bus_ops;
  1078. ar->ce_priv = &ar_snoc->ce;
  1079. ath10k_snoc_resource_init(ar);
  1080. if (ret) {
  1081. ath10k_warn(ar, "failed to initialize resource: %d\n", ret);
  1082. goto err_core_destroy;
  1083. }
  1084. ath10k_snoc_setup_resource(ar);
  1085. if (ret) {
  1086. ath10k_warn(ar, "failed to setup resource: %d\n", ret);
  1087. goto err_core_destroy;
  1088. }
  1089. ret = ath10k_snoc_request_irq(ar);
  1090. if (ret) {
  1091. ath10k_warn(ar, "failed to request irqs: %d\n", ret);
  1092. goto err_release_resource;
  1093. }
  1094. ar_snoc->vreg = vreg_cfg;
  1095. for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) {
  1096. ret = ath10k_get_vreg_info(ar, dev, &ar_snoc->vreg[i]);
  1097. if (ret)
  1098. goto err_free_irq;
  1099. }
  1100. ar_snoc->clk = clk_cfg;
  1101. for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
  1102. ret = ath10k_get_clk_info(ar, dev, &ar_snoc->clk[i]);
  1103. if (ret)
  1104. goto err_free_irq;
  1105. }
  1106. ret = ath10k_hw_power_on(ar);
  1107. if (ret) {
  1108. ath10k_err(ar, "failed to power on device: %d\n", ret);
  1109. goto err_free_irq;
  1110. }
  1111. ret = ath10k_core_register(ar, drv_data->hw_rev);
  1112. if (ret) {
  1113. ath10k_err(ar, "failed to register driver core: %d\n", ret);
  1114. goto err_hw_power_off;
  1115. }
  1116. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc probe\n");
  1117. ath10k_warn(ar, "Warning: SNOC support is still work-in-progress, it will not work properly!");
  1118. return 0;
  1119. err_hw_power_off:
  1120. ath10k_hw_power_off(ar);
  1121. err_free_irq:
  1122. ath10k_snoc_free_irq(ar);
  1123. err_release_resource:
  1124. ath10k_snoc_release_resource(ar);
  1125. err_core_destroy:
  1126. ath10k_core_destroy(ar);
  1127. return ret;
  1128. }
  1129. static int ath10k_snoc_remove(struct platform_device *pdev)
  1130. {
  1131. struct ath10k *ar = platform_get_drvdata(pdev);
  1132. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc remove\n");
  1133. ath10k_core_unregister(ar);
  1134. ath10k_hw_power_off(ar);
  1135. ath10k_snoc_free_irq(ar);
  1136. ath10k_snoc_release_resource(ar);
  1137. ath10k_core_destroy(ar);
  1138. return 0;
  1139. }
  1140. static struct platform_driver ath10k_snoc_driver = {
  1141. .probe = ath10k_snoc_probe,
  1142. .remove = ath10k_snoc_remove,
  1143. .driver = {
  1144. .name = "ath10k_snoc",
  1145. .of_match_table = ath10k_snoc_dt_match,
  1146. },
  1147. };
  1148. static int __init ath10k_snoc_init(void)
  1149. {
  1150. int ret;
  1151. ret = platform_driver_register(&ath10k_snoc_driver);
  1152. if (ret)
  1153. pr_err("failed to register ath10k snoc driver: %d\n",
  1154. ret);
  1155. return ret;
  1156. }
  1157. module_init(ath10k_snoc_init);
  1158. static void __exit ath10k_snoc_exit(void)
  1159. {
  1160. platform_driver_unregister(&ath10k_snoc_driver);
  1161. }
  1162. module_exit(ath10k_snoc_exit);
  1163. MODULE_AUTHOR("Qualcomm");
  1164. MODULE_LICENSE("Dual BSD/GPL");
  1165. MODULE_DESCRIPTION("Driver support for Atheros WCN3990 SNOC devices");