ahb.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. // SPDX-License-Identifier: BSD-3-Clause-Clear
  2. /*
  3. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/of_device.h>
  9. #include <linux/of.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/of_address.h>
  12. #include <linux/iommu.h>
  13. #include "ahb.h"
  14. #include "debug.h"
  15. #include "hif.h"
  16. #include <linux/remoteproc.h>
  17. #include "pcic.h"
  18. #include <linux/soc/qcom/smem.h>
  19. #include <linux/soc/qcom/smem_state.h>
  20. static const struct of_device_id ath11k_ahb_of_match[] = {
  21. /* TODO: Should we change the compatible string to something similar
  22. * to one that ath10k uses?
  23. */
  24. { .compatible = "qcom,ipq8074-wifi",
  25. .data = (void *)ATH11K_HW_IPQ8074,
  26. },
  27. { .compatible = "qcom,ipq6018-wifi",
  28. .data = (void *)ATH11K_HW_IPQ6018_HW10,
  29. },
  30. { .compatible = "qcom,wcn6750-wifi",
  31. .data = (void *)ATH11K_HW_WCN6750_HW10,
  32. },
  33. { }
  34. };
  35. MODULE_DEVICE_TABLE(of, ath11k_ahb_of_match);
  36. #define ATH11K_IRQ_CE0_OFFSET 4
  37. static const char *irq_name[ATH11K_IRQ_NUM_MAX] = {
  38. "misc-pulse1",
  39. "misc-latch",
  40. "sw-exception",
  41. "watchdog",
  42. "ce0",
  43. "ce1",
  44. "ce2",
  45. "ce3",
  46. "ce4",
  47. "ce5",
  48. "ce6",
  49. "ce7",
  50. "ce8",
  51. "ce9",
  52. "ce10",
  53. "ce11",
  54. "host2wbm-desc-feed",
  55. "host2reo-re-injection",
  56. "host2reo-command",
  57. "host2rxdma-monitor-ring3",
  58. "host2rxdma-monitor-ring2",
  59. "host2rxdma-monitor-ring1",
  60. "reo2ost-exception",
  61. "wbm2host-rx-release",
  62. "reo2host-status",
  63. "reo2host-destination-ring4",
  64. "reo2host-destination-ring3",
  65. "reo2host-destination-ring2",
  66. "reo2host-destination-ring1",
  67. "rxdma2host-monitor-destination-mac3",
  68. "rxdma2host-monitor-destination-mac2",
  69. "rxdma2host-monitor-destination-mac1",
  70. "ppdu-end-interrupts-mac3",
  71. "ppdu-end-interrupts-mac2",
  72. "ppdu-end-interrupts-mac1",
  73. "rxdma2host-monitor-status-ring-mac3",
  74. "rxdma2host-monitor-status-ring-mac2",
  75. "rxdma2host-monitor-status-ring-mac1",
  76. "host2rxdma-host-buf-ring-mac3",
  77. "host2rxdma-host-buf-ring-mac2",
  78. "host2rxdma-host-buf-ring-mac1",
  79. "rxdma2host-destination-ring-mac3",
  80. "rxdma2host-destination-ring-mac2",
  81. "rxdma2host-destination-ring-mac1",
  82. "host2tcl-input-ring4",
  83. "host2tcl-input-ring3",
  84. "host2tcl-input-ring2",
  85. "host2tcl-input-ring1",
  86. "wbm2host-tx-completions-ring3",
  87. "wbm2host-tx-completions-ring2",
  88. "wbm2host-tx-completions-ring1",
  89. "tcl2host-status-ring",
  90. };
  91. /* enum ext_irq_num - irq numbers that can be used by external modules
  92. * like datapath
  93. */
  94. enum ext_irq_num {
  95. host2wbm_desc_feed = 16,
  96. host2reo_re_injection,
  97. host2reo_command,
  98. host2rxdma_monitor_ring3,
  99. host2rxdma_monitor_ring2,
  100. host2rxdma_monitor_ring1,
  101. reo2host_exception,
  102. wbm2host_rx_release,
  103. reo2host_status,
  104. reo2host_destination_ring4,
  105. reo2host_destination_ring3,
  106. reo2host_destination_ring2,
  107. reo2host_destination_ring1,
  108. rxdma2host_monitor_destination_mac3,
  109. rxdma2host_monitor_destination_mac2,
  110. rxdma2host_monitor_destination_mac1,
  111. ppdu_end_interrupts_mac3,
  112. ppdu_end_interrupts_mac2,
  113. ppdu_end_interrupts_mac1,
  114. rxdma2host_monitor_status_ring_mac3,
  115. rxdma2host_monitor_status_ring_mac2,
  116. rxdma2host_monitor_status_ring_mac1,
  117. host2rxdma_host_buf_ring_mac3,
  118. host2rxdma_host_buf_ring_mac2,
  119. host2rxdma_host_buf_ring_mac1,
  120. rxdma2host_destination_ring_mac3,
  121. rxdma2host_destination_ring_mac2,
  122. rxdma2host_destination_ring_mac1,
  123. host2tcl_input_ring4,
  124. host2tcl_input_ring3,
  125. host2tcl_input_ring2,
  126. host2tcl_input_ring1,
  127. wbm2host_tx_completions_ring3,
  128. wbm2host_tx_completions_ring2,
  129. wbm2host_tx_completions_ring1,
  130. tcl2host_status_ring,
  131. };
  132. static int
  133. ath11k_ahb_get_msi_irq_wcn6750(struct ath11k_base *ab, unsigned int vector)
  134. {
  135. return ab->pci.msi.irqs[vector];
  136. }
  137. static inline u32
  138. ath11k_ahb_get_window_start_wcn6750(struct ath11k_base *ab, u32 offset)
  139. {
  140. u32 window_start = 0;
  141. /* If offset lies within DP register range, use 1st window */
  142. if ((offset ^ HAL_SEQ_WCSS_UMAC_OFFSET) < ATH11K_PCI_WINDOW_RANGE_MASK)
  143. window_start = ATH11K_PCI_WINDOW_START;
  144. /* If offset lies within CE register range, use 2nd window */
  145. else if ((offset ^ HAL_SEQ_WCSS_UMAC_CE0_SRC_REG(ab)) <
  146. ATH11K_PCI_WINDOW_RANGE_MASK)
  147. window_start = 2 * ATH11K_PCI_WINDOW_START;
  148. return window_start;
  149. }
  150. static void
  151. ath11k_ahb_window_write32_wcn6750(struct ath11k_base *ab, u32 offset, u32 value)
  152. {
  153. u32 window_start;
  154. /* WCN6750 uses static window based register access*/
  155. window_start = ath11k_ahb_get_window_start_wcn6750(ab, offset);
  156. iowrite32(value, ab->mem + window_start +
  157. (offset & ATH11K_PCI_WINDOW_RANGE_MASK));
  158. }
  159. static u32 ath11k_ahb_window_read32_wcn6750(struct ath11k_base *ab, u32 offset)
  160. {
  161. u32 window_start;
  162. u32 val;
  163. /* WCN6750 uses static window based register access */
  164. window_start = ath11k_ahb_get_window_start_wcn6750(ab, offset);
  165. val = ioread32(ab->mem + window_start +
  166. (offset & ATH11K_PCI_WINDOW_RANGE_MASK));
  167. return val;
  168. }
  169. static const struct ath11k_pci_ops ath11k_ahb_pci_ops_wcn6750 = {
  170. .wakeup = NULL,
  171. .release = NULL,
  172. .get_msi_irq = ath11k_ahb_get_msi_irq_wcn6750,
  173. .window_write32 = ath11k_ahb_window_write32_wcn6750,
  174. .window_read32 = ath11k_ahb_window_read32_wcn6750,
  175. };
  176. static inline u32 ath11k_ahb_read32(struct ath11k_base *ab, u32 offset)
  177. {
  178. return ioread32(ab->mem + offset);
  179. }
  180. static inline void ath11k_ahb_write32(struct ath11k_base *ab, u32 offset, u32 value)
  181. {
  182. iowrite32(value, ab->mem + offset);
  183. }
  184. static void ath11k_ahb_kill_tasklets(struct ath11k_base *ab)
  185. {
  186. int i;
  187. for (i = 0; i < ab->hw_params.ce_count; i++) {
  188. struct ath11k_ce_pipe *ce_pipe = &ab->ce.ce_pipe[i];
  189. if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
  190. continue;
  191. tasklet_kill(&ce_pipe->intr_tq);
  192. }
  193. }
  194. static void ath11k_ahb_ext_grp_disable(struct ath11k_ext_irq_grp *irq_grp)
  195. {
  196. int i;
  197. for (i = 0; i < irq_grp->num_irq; i++)
  198. disable_irq_nosync(irq_grp->ab->irq_num[irq_grp->irqs[i]]);
  199. }
  200. static void __ath11k_ahb_ext_irq_disable(struct ath11k_base *ab)
  201. {
  202. int i;
  203. for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
  204. struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
  205. ath11k_ahb_ext_grp_disable(irq_grp);
  206. if (irq_grp->napi_enabled) {
  207. napi_synchronize(&irq_grp->napi);
  208. napi_disable(&irq_grp->napi);
  209. irq_grp->napi_enabled = false;
  210. }
  211. }
  212. }
  213. static void ath11k_ahb_ext_grp_enable(struct ath11k_ext_irq_grp *irq_grp)
  214. {
  215. int i;
  216. for (i = 0; i < irq_grp->num_irq; i++)
  217. enable_irq(irq_grp->ab->irq_num[irq_grp->irqs[i]]);
  218. }
  219. static void ath11k_ahb_setbit32(struct ath11k_base *ab, u8 bit, u32 offset)
  220. {
  221. u32 val;
  222. val = ath11k_ahb_read32(ab, offset);
  223. ath11k_ahb_write32(ab, offset, val | BIT(bit));
  224. }
  225. static void ath11k_ahb_clearbit32(struct ath11k_base *ab, u8 bit, u32 offset)
  226. {
  227. u32 val;
  228. val = ath11k_ahb_read32(ab, offset);
  229. ath11k_ahb_write32(ab, offset, val & ~BIT(bit));
  230. }
  231. static void ath11k_ahb_ce_irq_enable(struct ath11k_base *ab, u16 ce_id)
  232. {
  233. const struct ce_attr *ce_attr;
  234. ce_attr = &ab->hw_params.host_ce_config[ce_id];
  235. if (ce_attr->src_nentries)
  236. ath11k_ahb_setbit32(ab, ce_id, CE_HOST_IE_ADDRESS);
  237. if (ce_attr->dest_nentries) {
  238. ath11k_ahb_setbit32(ab, ce_id, CE_HOST_IE_2_ADDRESS);
  239. ath11k_ahb_setbit32(ab, ce_id + CE_HOST_IE_3_SHIFT,
  240. CE_HOST_IE_3_ADDRESS);
  241. }
  242. }
  243. static void ath11k_ahb_ce_irq_disable(struct ath11k_base *ab, u16 ce_id)
  244. {
  245. const struct ce_attr *ce_attr;
  246. ce_attr = &ab->hw_params.host_ce_config[ce_id];
  247. if (ce_attr->src_nentries)
  248. ath11k_ahb_clearbit32(ab, ce_id, CE_HOST_IE_ADDRESS);
  249. if (ce_attr->dest_nentries) {
  250. ath11k_ahb_clearbit32(ab, ce_id, CE_HOST_IE_2_ADDRESS);
  251. ath11k_ahb_clearbit32(ab, ce_id + CE_HOST_IE_3_SHIFT,
  252. CE_HOST_IE_3_ADDRESS);
  253. }
  254. }
  255. static void ath11k_ahb_sync_ce_irqs(struct ath11k_base *ab)
  256. {
  257. int i;
  258. int irq_idx;
  259. for (i = 0; i < ab->hw_params.ce_count; i++) {
  260. if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
  261. continue;
  262. irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
  263. synchronize_irq(ab->irq_num[irq_idx]);
  264. }
  265. }
  266. static void ath11k_ahb_sync_ext_irqs(struct ath11k_base *ab)
  267. {
  268. int i, j;
  269. int irq_idx;
  270. for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
  271. struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
  272. for (j = 0; j < irq_grp->num_irq; j++) {
  273. irq_idx = irq_grp->irqs[j];
  274. synchronize_irq(ab->irq_num[irq_idx]);
  275. }
  276. }
  277. }
  278. static void ath11k_ahb_ce_irqs_enable(struct ath11k_base *ab)
  279. {
  280. int i;
  281. for (i = 0; i < ab->hw_params.ce_count; i++) {
  282. if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
  283. continue;
  284. ath11k_ahb_ce_irq_enable(ab, i);
  285. }
  286. }
  287. static void ath11k_ahb_ce_irqs_disable(struct ath11k_base *ab)
  288. {
  289. int i;
  290. for (i = 0; i < ab->hw_params.ce_count; i++) {
  291. if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
  292. continue;
  293. ath11k_ahb_ce_irq_disable(ab, i);
  294. }
  295. }
  296. static int ath11k_ahb_start(struct ath11k_base *ab)
  297. {
  298. ath11k_ahb_ce_irqs_enable(ab);
  299. ath11k_ce_rx_post_buf(ab);
  300. return 0;
  301. }
  302. static void ath11k_ahb_ext_irq_enable(struct ath11k_base *ab)
  303. {
  304. int i;
  305. for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
  306. struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
  307. if (!irq_grp->napi_enabled) {
  308. dev_set_threaded(&irq_grp->napi_ndev, true);
  309. napi_enable(&irq_grp->napi);
  310. irq_grp->napi_enabled = true;
  311. }
  312. ath11k_ahb_ext_grp_enable(irq_grp);
  313. }
  314. }
  315. static void ath11k_ahb_ext_irq_disable(struct ath11k_base *ab)
  316. {
  317. __ath11k_ahb_ext_irq_disable(ab);
  318. ath11k_ahb_sync_ext_irqs(ab);
  319. }
  320. static void ath11k_ahb_stop(struct ath11k_base *ab)
  321. {
  322. if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))
  323. ath11k_ahb_ce_irqs_disable(ab);
  324. ath11k_ahb_sync_ce_irqs(ab);
  325. ath11k_ahb_kill_tasklets(ab);
  326. del_timer_sync(&ab->rx_replenish_retry);
  327. ath11k_ce_cleanup_pipes(ab);
  328. }
  329. static int ath11k_ahb_power_up(struct ath11k_base *ab)
  330. {
  331. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  332. int ret;
  333. ret = rproc_boot(ab_ahb->tgt_rproc);
  334. if (ret)
  335. ath11k_err(ab, "failed to boot the remote processor Q6\n");
  336. return ret;
  337. }
  338. static void ath11k_ahb_power_down(struct ath11k_base *ab)
  339. {
  340. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  341. rproc_shutdown(ab_ahb->tgt_rproc);
  342. }
  343. static int ath11k_ahb_fwreset_from_cold_boot(struct ath11k_base *ab)
  344. {
  345. int timeout;
  346. if (ath11k_cold_boot_cal == 0 || ab->qmi.cal_done ||
  347. ab->hw_params.cold_boot_calib == 0 ||
  348. ab->hw_params.cbcal_restart_fw == 0)
  349. return 0;
  350. ath11k_dbg(ab, ATH11K_DBG_AHB, "wait for cold boot done\n");
  351. timeout = wait_event_timeout(ab->qmi.cold_boot_waitq,
  352. (ab->qmi.cal_done == 1),
  353. ATH11K_COLD_BOOT_FW_RESET_DELAY);
  354. if (timeout <= 0) {
  355. ath11k_cold_boot_cal = 0;
  356. ath11k_warn(ab, "Coldboot Calibration failed timed out\n");
  357. }
  358. /* reset the firmware */
  359. ath11k_ahb_power_down(ab);
  360. ath11k_ahb_power_up(ab);
  361. ath11k_dbg(ab, ATH11K_DBG_AHB, "exited from cold boot mode\n");
  362. return 0;
  363. }
  364. static void ath11k_ahb_init_qmi_ce_config(struct ath11k_base *ab)
  365. {
  366. struct ath11k_qmi_ce_cfg *cfg = &ab->qmi.ce_cfg;
  367. cfg->tgt_ce_len = ab->hw_params.target_ce_count;
  368. cfg->tgt_ce = ab->hw_params.target_ce_config;
  369. cfg->svc_to_ce_map_len = ab->hw_params.svc_to_ce_map_len;
  370. cfg->svc_to_ce_map = ab->hw_params.svc_to_ce_map;
  371. ab->qmi.service_ins_id = ab->hw_params.qmi_service_ins_id;
  372. }
  373. static void ath11k_ahb_free_ext_irq(struct ath11k_base *ab)
  374. {
  375. int i, j;
  376. for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
  377. struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
  378. for (j = 0; j < irq_grp->num_irq; j++)
  379. free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp);
  380. netif_napi_del(&irq_grp->napi);
  381. }
  382. }
  383. static void ath11k_ahb_free_irq(struct ath11k_base *ab)
  384. {
  385. int irq_idx;
  386. int i;
  387. if (ab->hw_params.hybrid_bus_type)
  388. return ath11k_pcic_free_irq(ab);
  389. for (i = 0; i < ab->hw_params.ce_count; i++) {
  390. if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
  391. continue;
  392. irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
  393. free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]);
  394. }
  395. ath11k_ahb_free_ext_irq(ab);
  396. }
  397. static void ath11k_ahb_ce_tasklet(struct tasklet_struct *t)
  398. {
  399. struct ath11k_ce_pipe *ce_pipe = from_tasklet(ce_pipe, t, intr_tq);
  400. ath11k_ce_per_engine_service(ce_pipe->ab, ce_pipe->pipe_num);
  401. ath11k_ahb_ce_irq_enable(ce_pipe->ab, ce_pipe->pipe_num);
  402. }
  403. static irqreturn_t ath11k_ahb_ce_interrupt_handler(int irq, void *arg)
  404. {
  405. struct ath11k_ce_pipe *ce_pipe = arg;
  406. /* last interrupt received for this CE */
  407. ce_pipe->timestamp = jiffies;
  408. ath11k_ahb_ce_irq_disable(ce_pipe->ab, ce_pipe->pipe_num);
  409. tasklet_schedule(&ce_pipe->intr_tq);
  410. return IRQ_HANDLED;
  411. }
  412. static int ath11k_ahb_ext_grp_napi_poll(struct napi_struct *napi, int budget)
  413. {
  414. struct ath11k_ext_irq_grp *irq_grp = container_of(napi,
  415. struct ath11k_ext_irq_grp,
  416. napi);
  417. struct ath11k_base *ab = irq_grp->ab;
  418. int work_done;
  419. work_done = ath11k_dp_service_srng(ab, irq_grp, budget);
  420. if (work_done < budget) {
  421. napi_complete_done(napi, work_done);
  422. ath11k_ahb_ext_grp_enable(irq_grp);
  423. }
  424. if (work_done > budget)
  425. work_done = budget;
  426. return work_done;
  427. }
  428. static irqreturn_t ath11k_ahb_ext_interrupt_handler(int irq, void *arg)
  429. {
  430. struct ath11k_ext_irq_grp *irq_grp = arg;
  431. /* last interrupt received for this group */
  432. irq_grp->timestamp = jiffies;
  433. ath11k_ahb_ext_grp_disable(irq_grp);
  434. napi_schedule(&irq_grp->napi);
  435. return IRQ_HANDLED;
  436. }
  437. static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab)
  438. {
  439. struct ath11k_hw_params *hw = &ab->hw_params;
  440. int i, j;
  441. int irq;
  442. int ret;
  443. for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
  444. struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
  445. u32 num_irq = 0;
  446. irq_grp->ab = ab;
  447. irq_grp->grp_id = i;
  448. init_dummy_netdev(&irq_grp->napi_ndev);
  449. netif_napi_add(&irq_grp->napi_ndev, &irq_grp->napi,
  450. ath11k_ahb_ext_grp_napi_poll);
  451. for (j = 0; j < ATH11K_EXT_IRQ_NUM_MAX; j++) {
  452. if (ab->hw_params.ring_mask->tx[i] & BIT(j)) {
  453. irq_grp->irqs[num_irq++] =
  454. wbm2host_tx_completions_ring1 - j;
  455. }
  456. if (ab->hw_params.ring_mask->rx[i] & BIT(j)) {
  457. irq_grp->irqs[num_irq++] =
  458. reo2host_destination_ring1 - j;
  459. }
  460. if (ab->hw_params.ring_mask->rx_err[i] & BIT(j))
  461. irq_grp->irqs[num_irq++] = reo2host_exception;
  462. if (ab->hw_params.ring_mask->rx_wbm_rel[i] & BIT(j))
  463. irq_grp->irqs[num_irq++] = wbm2host_rx_release;
  464. if (ab->hw_params.ring_mask->reo_status[i] & BIT(j))
  465. irq_grp->irqs[num_irq++] = reo2host_status;
  466. if (j < ab->hw_params.max_radios) {
  467. if (ab->hw_params.ring_mask->rxdma2host[i] & BIT(j)) {
  468. irq_grp->irqs[num_irq++] =
  469. rxdma2host_destination_ring_mac1 -
  470. ath11k_hw_get_mac_from_pdev_id(hw, j);
  471. }
  472. if (ab->hw_params.ring_mask->host2rxdma[i] & BIT(j)) {
  473. irq_grp->irqs[num_irq++] =
  474. host2rxdma_host_buf_ring_mac1 -
  475. ath11k_hw_get_mac_from_pdev_id(hw, j);
  476. }
  477. if (ab->hw_params.ring_mask->rx_mon_status[i] & BIT(j)) {
  478. irq_grp->irqs[num_irq++] =
  479. ppdu_end_interrupts_mac1 -
  480. ath11k_hw_get_mac_from_pdev_id(hw, j);
  481. irq_grp->irqs[num_irq++] =
  482. rxdma2host_monitor_status_ring_mac1 -
  483. ath11k_hw_get_mac_from_pdev_id(hw, j);
  484. }
  485. }
  486. }
  487. irq_grp->num_irq = num_irq;
  488. for (j = 0; j < irq_grp->num_irq; j++) {
  489. int irq_idx = irq_grp->irqs[j];
  490. irq = platform_get_irq_byname(ab->pdev,
  491. irq_name[irq_idx]);
  492. ab->irq_num[irq_idx] = irq;
  493. irq_set_status_flags(irq, IRQ_NOAUTOEN | IRQ_DISABLE_UNLAZY);
  494. ret = request_irq(irq, ath11k_ahb_ext_interrupt_handler,
  495. IRQF_TRIGGER_RISING,
  496. irq_name[irq_idx], irq_grp);
  497. if (ret) {
  498. ath11k_err(ab, "failed request_irq for %d\n",
  499. irq);
  500. }
  501. }
  502. }
  503. return 0;
  504. }
  505. static int ath11k_ahb_config_irq(struct ath11k_base *ab)
  506. {
  507. int irq, irq_idx, i;
  508. int ret;
  509. if (ab->hw_params.hybrid_bus_type)
  510. return ath11k_pcic_config_irq(ab);
  511. /* Configure CE irqs */
  512. for (i = 0; i < ab->hw_params.ce_count; i++) {
  513. struct ath11k_ce_pipe *ce_pipe = &ab->ce.ce_pipe[i];
  514. if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
  515. continue;
  516. irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
  517. tasklet_setup(&ce_pipe->intr_tq, ath11k_ahb_ce_tasklet);
  518. irq = platform_get_irq_byname(ab->pdev, irq_name[irq_idx]);
  519. ret = request_irq(irq, ath11k_ahb_ce_interrupt_handler,
  520. IRQF_TRIGGER_RISING, irq_name[irq_idx],
  521. ce_pipe);
  522. if (ret)
  523. return ret;
  524. ab->irq_num[irq_idx] = irq;
  525. }
  526. /* Configure external interrupts */
  527. ret = ath11k_ahb_config_ext_irq(ab);
  528. return ret;
  529. }
  530. static int ath11k_ahb_map_service_to_pipe(struct ath11k_base *ab, u16 service_id,
  531. u8 *ul_pipe, u8 *dl_pipe)
  532. {
  533. const struct service_to_pipe *entry;
  534. bool ul_set = false, dl_set = false;
  535. int i;
  536. for (i = 0; i < ab->hw_params.svc_to_ce_map_len; i++) {
  537. entry = &ab->hw_params.svc_to_ce_map[i];
  538. if (__le32_to_cpu(entry->service_id) != service_id)
  539. continue;
  540. switch (__le32_to_cpu(entry->pipedir)) {
  541. case PIPEDIR_NONE:
  542. break;
  543. case PIPEDIR_IN:
  544. WARN_ON(dl_set);
  545. *dl_pipe = __le32_to_cpu(entry->pipenum);
  546. dl_set = true;
  547. break;
  548. case PIPEDIR_OUT:
  549. WARN_ON(ul_set);
  550. *ul_pipe = __le32_to_cpu(entry->pipenum);
  551. ul_set = true;
  552. break;
  553. case PIPEDIR_INOUT:
  554. WARN_ON(dl_set);
  555. WARN_ON(ul_set);
  556. *dl_pipe = __le32_to_cpu(entry->pipenum);
  557. *ul_pipe = __le32_to_cpu(entry->pipenum);
  558. dl_set = true;
  559. ul_set = true;
  560. break;
  561. }
  562. }
  563. if (WARN_ON(!ul_set || !dl_set))
  564. return -ENOENT;
  565. return 0;
  566. }
  567. static int ath11k_ahb_hif_suspend(struct ath11k_base *ab)
  568. {
  569. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  570. u32 wake_irq;
  571. u32 value = 0;
  572. int ret;
  573. if (!device_may_wakeup(ab->dev))
  574. return -EPERM;
  575. wake_irq = ab->irq_num[ATH11K_PCI_IRQ_CE0_OFFSET + ATH11K_PCI_CE_WAKE_IRQ];
  576. ret = enable_irq_wake(wake_irq);
  577. if (ret) {
  578. ath11k_err(ab, "failed to enable wakeup irq :%d\n", ret);
  579. return ret;
  580. }
  581. value = u32_encode_bits(ab_ahb->smp2p_info.seq_no++,
  582. ATH11K_AHB_SMP2P_SMEM_SEQ_NO);
  583. value |= u32_encode_bits(ATH11K_AHB_POWER_SAVE_ENTER,
  584. ATH11K_AHB_SMP2P_SMEM_MSG);
  585. ret = qcom_smem_state_update_bits(ab_ahb->smp2p_info.smem_state,
  586. ATH11K_AHB_SMP2P_SMEM_VALUE_MASK, value);
  587. if (ret) {
  588. ath11k_err(ab, "failed to send smp2p power save enter cmd :%d\n", ret);
  589. return ret;
  590. }
  591. ath11k_dbg(ab, ATH11K_DBG_AHB, "ahb device suspended\n");
  592. return ret;
  593. }
  594. static int ath11k_ahb_hif_resume(struct ath11k_base *ab)
  595. {
  596. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  597. u32 wake_irq;
  598. u32 value = 0;
  599. int ret;
  600. if (!device_may_wakeup(ab->dev))
  601. return -EPERM;
  602. wake_irq = ab->irq_num[ATH11K_PCI_IRQ_CE0_OFFSET + ATH11K_PCI_CE_WAKE_IRQ];
  603. ret = disable_irq_wake(wake_irq);
  604. if (ret) {
  605. ath11k_err(ab, "failed to disable wakeup irq: %d\n", ret);
  606. return ret;
  607. }
  608. reinit_completion(&ab->wow.wakeup_completed);
  609. value = u32_encode_bits(ab_ahb->smp2p_info.seq_no++,
  610. ATH11K_AHB_SMP2P_SMEM_SEQ_NO);
  611. value |= u32_encode_bits(ATH11K_AHB_POWER_SAVE_EXIT,
  612. ATH11K_AHB_SMP2P_SMEM_MSG);
  613. ret = qcom_smem_state_update_bits(ab_ahb->smp2p_info.smem_state,
  614. ATH11K_AHB_SMP2P_SMEM_VALUE_MASK, value);
  615. if (ret) {
  616. ath11k_err(ab, "failed to send smp2p power save enter cmd :%d\n", ret);
  617. return ret;
  618. }
  619. ret = wait_for_completion_timeout(&ab->wow.wakeup_completed, 3 * HZ);
  620. if (ret == 0) {
  621. ath11k_warn(ab, "timed out while waiting for wow wakeup completion\n");
  622. return -ETIMEDOUT;
  623. }
  624. ath11k_dbg(ab, ATH11K_DBG_AHB, "ahb device resumed\n");
  625. return 0;
  626. }
  627. static const struct ath11k_hif_ops ath11k_ahb_hif_ops_ipq8074 = {
  628. .start = ath11k_ahb_start,
  629. .stop = ath11k_ahb_stop,
  630. .read32 = ath11k_ahb_read32,
  631. .write32 = ath11k_ahb_write32,
  632. .read = NULL,
  633. .irq_enable = ath11k_ahb_ext_irq_enable,
  634. .irq_disable = ath11k_ahb_ext_irq_disable,
  635. .map_service_to_pipe = ath11k_ahb_map_service_to_pipe,
  636. .power_down = ath11k_ahb_power_down,
  637. .power_up = ath11k_ahb_power_up,
  638. };
  639. static const struct ath11k_hif_ops ath11k_ahb_hif_ops_wcn6750 = {
  640. .start = ath11k_pcic_start,
  641. .stop = ath11k_pcic_stop,
  642. .read32 = ath11k_pcic_read32,
  643. .write32 = ath11k_pcic_write32,
  644. .read = NULL,
  645. .irq_enable = ath11k_pcic_ext_irq_enable,
  646. .irq_disable = ath11k_pcic_ext_irq_disable,
  647. .get_msi_address = ath11k_pcic_get_msi_address,
  648. .get_user_msi_vector = ath11k_pcic_get_user_msi_assignment,
  649. .map_service_to_pipe = ath11k_pcic_map_service_to_pipe,
  650. .power_down = ath11k_ahb_power_down,
  651. .power_up = ath11k_ahb_power_up,
  652. .suspend = ath11k_ahb_hif_suspend,
  653. .resume = ath11k_ahb_hif_resume,
  654. .ce_irq_enable = ath11k_pci_enable_ce_irqs_except_wake_irq,
  655. .ce_irq_disable = ath11k_pci_disable_ce_irqs_except_wake_irq,
  656. };
  657. static int ath11k_core_get_rproc(struct ath11k_base *ab)
  658. {
  659. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  660. struct device *dev = ab->dev;
  661. struct rproc *prproc;
  662. phandle rproc_phandle;
  663. if (of_property_read_u32(dev->of_node, "qcom,rproc", &rproc_phandle)) {
  664. ath11k_err(ab, "failed to get q6_rproc handle\n");
  665. return -ENOENT;
  666. }
  667. prproc = rproc_get_by_phandle(rproc_phandle);
  668. if (!prproc) {
  669. ath11k_err(ab, "failed to get rproc\n");
  670. return -EINVAL;
  671. }
  672. ab_ahb->tgt_rproc = prproc;
  673. return 0;
  674. }
  675. static int ath11k_ahb_setup_msi_resources(struct ath11k_base *ab)
  676. {
  677. struct platform_device *pdev = ab->pdev;
  678. phys_addr_t msi_addr_pa;
  679. dma_addr_t msi_addr_iova;
  680. struct resource *res;
  681. int int_prop;
  682. int ret;
  683. int i;
  684. ret = ath11k_pcic_init_msi_config(ab);
  685. if (ret) {
  686. ath11k_err(ab, "failed to init msi config: %d\n", ret);
  687. return ret;
  688. }
  689. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  690. if (!res) {
  691. ath11k_err(ab, "failed to fetch msi_addr\n");
  692. return -ENOENT;
  693. }
  694. msi_addr_pa = res->start;
  695. msi_addr_iova = dma_map_resource(ab->dev, msi_addr_pa, PAGE_SIZE,
  696. DMA_FROM_DEVICE, 0);
  697. if (dma_mapping_error(ab->dev, msi_addr_iova))
  698. return -ENOMEM;
  699. ab->pci.msi.addr_lo = lower_32_bits(msi_addr_iova);
  700. ab->pci.msi.addr_hi = upper_32_bits(msi_addr_iova);
  701. ret = of_property_read_u32_index(ab->dev->of_node, "interrupts", 1, &int_prop);
  702. if (ret)
  703. return ret;
  704. ab->pci.msi.ep_base_data = int_prop + 32;
  705. for (i = 0; i < ab->pci.msi.config->total_vectors; i++) {
  706. ret = platform_get_irq(pdev, i);
  707. if (ret < 0)
  708. return ret;
  709. ab->pci.msi.irqs[i] = ret;
  710. }
  711. set_bit(ATH11K_FLAG_MULTI_MSI_VECTORS, &ab->dev_flags);
  712. return 0;
  713. }
  714. static int ath11k_ahb_setup_smp2p_handle(struct ath11k_base *ab)
  715. {
  716. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  717. if (!ab->hw_params.smp2p_wow_exit)
  718. return 0;
  719. ab_ahb->smp2p_info.smem_state = qcom_smem_state_get(ab->dev, "wlan-smp2p-out",
  720. &ab_ahb->smp2p_info.smem_bit);
  721. if (IS_ERR(ab_ahb->smp2p_info.smem_state)) {
  722. ath11k_err(ab, "failed to fetch smem state: %ld\n",
  723. PTR_ERR(ab_ahb->smp2p_info.smem_state));
  724. return PTR_ERR(ab_ahb->smp2p_info.smem_state);
  725. }
  726. return 0;
  727. }
  728. static void ath11k_ahb_release_smp2p_handle(struct ath11k_base *ab)
  729. {
  730. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  731. if (!ab->hw_params.smp2p_wow_exit)
  732. return;
  733. qcom_smem_state_put(ab_ahb->smp2p_info.smem_state);
  734. }
  735. static int ath11k_ahb_setup_resources(struct ath11k_base *ab)
  736. {
  737. struct platform_device *pdev = ab->pdev;
  738. struct resource *mem_res;
  739. void __iomem *mem;
  740. if (ab->hw_params.hybrid_bus_type)
  741. return ath11k_ahb_setup_msi_resources(ab);
  742. mem = devm_platform_get_and_ioremap_resource(pdev, 0, &mem_res);
  743. if (IS_ERR(mem)) {
  744. dev_err(&pdev->dev, "ioremap error\n");
  745. return PTR_ERR(mem);
  746. }
  747. ab->mem = mem;
  748. ab->mem_len = resource_size(mem_res);
  749. return 0;
  750. }
  751. static int ath11k_ahb_setup_msa_resources(struct ath11k_base *ab)
  752. {
  753. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  754. struct device *dev = ab->dev;
  755. struct device_node *node;
  756. struct resource r;
  757. int ret;
  758. node = of_parse_phandle(dev->of_node, "memory-region", 0);
  759. if (!node)
  760. return -ENOENT;
  761. ret = of_address_to_resource(node, 0, &r);
  762. of_node_put(node);
  763. if (ret) {
  764. dev_err(dev, "failed to resolve msa fixed region\n");
  765. return ret;
  766. }
  767. ab_ahb->fw.msa_paddr = r.start;
  768. ab_ahb->fw.msa_size = resource_size(&r);
  769. node = of_parse_phandle(dev->of_node, "memory-region", 1);
  770. if (!node)
  771. return -ENOENT;
  772. ret = of_address_to_resource(node, 0, &r);
  773. of_node_put(node);
  774. if (ret) {
  775. dev_err(dev, "failed to resolve ce fixed region\n");
  776. return ret;
  777. }
  778. ab_ahb->fw.ce_paddr = r.start;
  779. ab_ahb->fw.ce_size = resource_size(&r);
  780. return 0;
  781. }
  782. static int ath11k_ahb_fw_resources_init(struct ath11k_base *ab)
  783. {
  784. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  785. struct device *host_dev = ab->dev;
  786. struct platform_device_info info = {0};
  787. struct iommu_domain *iommu_dom;
  788. struct platform_device *pdev;
  789. struct device_node *node;
  790. int ret;
  791. /* Chipsets not requiring MSA need not initialize
  792. * MSA resources, return success in such cases.
  793. */
  794. if (!ab->hw_params.fixed_fw_mem)
  795. return 0;
  796. ret = ath11k_ahb_setup_msa_resources(ab);
  797. if (ret) {
  798. ath11k_err(ab, "failed to setup msa resources\n");
  799. return ret;
  800. }
  801. node = of_get_child_by_name(host_dev->of_node, "wifi-firmware");
  802. if (!node) {
  803. ab_ahb->fw.use_tz = true;
  804. return 0;
  805. }
  806. info.fwnode = &node->fwnode;
  807. info.parent = host_dev;
  808. info.name = node->name;
  809. info.dma_mask = DMA_BIT_MASK(32);
  810. pdev = platform_device_register_full(&info);
  811. if (IS_ERR(pdev)) {
  812. of_node_put(node);
  813. return PTR_ERR(pdev);
  814. }
  815. ret = of_dma_configure(&pdev->dev, node, true);
  816. if (ret) {
  817. ath11k_err(ab, "dma configure fail: %d\n", ret);
  818. goto err_unregister;
  819. }
  820. ab_ahb->fw.dev = &pdev->dev;
  821. iommu_dom = iommu_domain_alloc(&platform_bus_type);
  822. if (!iommu_dom) {
  823. ath11k_err(ab, "failed to allocate iommu domain\n");
  824. ret = -ENOMEM;
  825. goto err_unregister;
  826. }
  827. ret = iommu_attach_device(iommu_dom, ab_ahb->fw.dev);
  828. if (ret) {
  829. ath11k_err(ab, "could not attach device: %d\n", ret);
  830. goto err_iommu_free;
  831. }
  832. ret = iommu_map(iommu_dom, ab_ahb->fw.msa_paddr,
  833. ab_ahb->fw.msa_paddr, ab_ahb->fw.msa_size,
  834. IOMMU_READ | IOMMU_WRITE);
  835. if (ret) {
  836. ath11k_err(ab, "failed to map firmware region: %d\n", ret);
  837. goto err_iommu_detach;
  838. }
  839. ret = iommu_map(iommu_dom, ab_ahb->fw.ce_paddr,
  840. ab_ahb->fw.ce_paddr, ab_ahb->fw.ce_size,
  841. IOMMU_READ | IOMMU_WRITE);
  842. if (ret) {
  843. ath11k_err(ab, "failed to map firmware CE region: %d\n", ret);
  844. goto err_iommu_unmap;
  845. }
  846. ab_ahb->fw.use_tz = false;
  847. ab_ahb->fw.iommu_domain = iommu_dom;
  848. of_node_put(node);
  849. return 0;
  850. err_iommu_unmap:
  851. iommu_unmap(iommu_dom, ab_ahb->fw.msa_paddr, ab_ahb->fw.msa_size);
  852. err_iommu_detach:
  853. iommu_detach_device(iommu_dom, ab_ahb->fw.dev);
  854. err_iommu_free:
  855. iommu_domain_free(iommu_dom);
  856. err_unregister:
  857. platform_device_unregister(pdev);
  858. of_node_put(node);
  859. return ret;
  860. }
  861. static int ath11k_ahb_fw_resource_deinit(struct ath11k_base *ab)
  862. {
  863. struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
  864. struct iommu_domain *iommu;
  865. size_t unmapped_size;
  866. /* Chipsets not requiring MSA would have not initialized
  867. * MSA resources, return success in such cases.
  868. */
  869. if (!ab->hw_params.fixed_fw_mem)
  870. return 0;
  871. if (ab_ahb->fw.use_tz)
  872. return 0;
  873. iommu = ab_ahb->fw.iommu_domain;
  874. unmapped_size = iommu_unmap(iommu, ab_ahb->fw.msa_paddr, ab_ahb->fw.msa_size);
  875. if (unmapped_size != ab_ahb->fw.msa_size)
  876. ath11k_err(ab, "failed to unmap firmware: %zu\n",
  877. unmapped_size);
  878. unmapped_size = iommu_unmap(iommu, ab_ahb->fw.ce_paddr, ab_ahb->fw.ce_size);
  879. if (unmapped_size != ab_ahb->fw.ce_size)
  880. ath11k_err(ab, "failed to unmap firmware CE memory: %zu\n",
  881. unmapped_size);
  882. iommu_detach_device(iommu, ab_ahb->fw.dev);
  883. iommu_domain_free(iommu);
  884. platform_device_unregister(to_platform_device(ab_ahb->fw.dev));
  885. return 0;
  886. }
  887. static int ath11k_ahb_probe(struct platform_device *pdev)
  888. {
  889. struct ath11k_base *ab;
  890. const struct of_device_id *of_id;
  891. const struct ath11k_hif_ops *hif_ops;
  892. const struct ath11k_pci_ops *pci_ops;
  893. enum ath11k_hw_rev hw_rev;
  894. int ret;
  895. of_id = of_match_device(ath11k_ahb_of_match, &pdev->dev);
  896. if (!of_id) {
  897. dev_err(&pdev->dev, "failed to find matching device tree id\n");
  898. return -EINVAL;
  899. }
  900. hw_rev = (enum ath11k_hw_rev)of_id->data;
  901. switch (hw_rev) {
  902. case ATH11K_HW_IPQ8074:
  903. case ATH11K_HW_IPQ6018_HW10:
  904. hif_ops = &ath11k_ahb_hif_ops_ipq8074;
  905. pci_ops = NULL;
  906. break;
  907. case ATH11K_HW_WCN6750_HW10:
  908. hif_ops = &ath11k_ahb_hif_ops_wcn6750;
  909. pci_ops = &ath11k_ahb_pci_ops_wcn6750;
  910. break;
  911. default:
  912. dev_err(&pdev->dev, "unsupported device type %d\n", hw_rev);
  913. return -EOPNOTSUPP;
  914. }
  915. ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  916. if (ret) {
  917. dev_err(&pdev->dev, "failed to set 32-bit consistent dma\n");
  918. return ret;
  919. }
  920. ab = ath11k_core_alloc(&pdev->dev, sizeof(struct ath11k_ahb),
  921. ATH11K_BUS_AHB);
  922. if (!ab) {
  923. dev_err(&pdev->dev, "failed to allocate ath11k base\n");
  924. return -ENOMEM;
  925. }
  926. ab->hif.ops = hif_ops;
  927. ab->pdev = pdev;
  928. ab->hw_rev = hw_rev;
  929. platform_set_drvdata(pdev, ab);
  930. ret = ath11k_pcic_register_pci_ops(ab, pci_ops);
  931. if (ret) {
  932. ath11k_err(ab, "failed to register PCI ops: %d\n", ret);
  933. goto err_core_free;
  934. }
  935. ret = ath11k_core_pre_init(ab);
  936. if (ret)
  937. goto err_core_free;
  938. ret = ath11k_ahb_setup_resources(ab);
  939. if (ret)
  940. goto err_core_free;
  941. ret = ath11k_ahb_fw_resources_init(ab);
  942. if (ret)
  943. goto err_core_free;
  944. ret = ath11k_ahb_setup_smp2p_handle(ab);
  945. if (ret)
  946. goto err_fw_deinit;
  947. ret = ath11k_hal_srng_init(ab);
  948. if (ret)
  949. goto err_release_smp2p_handle;
  950. ret = ath11k_ce_alloc_pipes(ab);
  951. if (ret) {
  952. ath11k_err(ab, "failed to allocate ce pipes: %d\n", ret);
  953. goto err_hal_srng_deinit;
  954. }
  955. ath11k_ahb_init_qmi_ce_config(ab);
  956. ret = ath11k_core_get_rproc(ab);
  957. if (ret) {
  958. ath11k_err(ab, "failed to get rproc: %d\n", ret);
  959. goto err_ce_free;
  960. }
  961. ret = ath11k_core_init(ab);
  962. if (ret) {
  963. ath11k_err(ab, "failed to init core: %d\n", ret);
  964. goto err_ce_free;
  965. }
  966. ret = ath11k_ahb_config_irq(ab);
  967. if (ret) {
  968. ath11k_err(ab, "failed to configure irq: %d\n", ret);
  969. goto err_ce_free;
  970. }
  971. ath11k_ahb_fwreset_from_cold_boot(ab);
  972. return 0;
  973. err_ce_free:
  974. ath11k_ce_free_pipes(ab);
  975. err_hal_srng_deinit:
  976. ath11k_hal_srng_deinit(ab);
  977. err_release_smp2p_handle:
  978. ath11k_ahb_release_smp2p_handle(ab);
  979. err_fw_deinit:
  980. ath11k_ahb_fw_resource_deinit(ab);
  981. err_core_free:
  982. ath11k_core_free(ab);
  983. platform_set_drvdata(pdev, NULL);
  984. return ret;
  985. }
  986. static void ath11k_ahb_remove_prepare(struct ath11k_base *ab)
  987. {
  988. unsigned long left;
  989. if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags)) {
  990. left = wait_for_completion_timeout(&ab->driver_recovery,
  991. ATH11K_AHB_RECOVERY_TIMEOUT);
  992. if (!left)
  993. ath11k_warn(ab, "failed to receive recovery response completion\n");
  994. }
  995. set_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags);
  996. cancel_work_sync(&ab->restart_work);
  997. cancel_work_sync(&ab->qmi.event_work);
  998. }
  999. static void ath11k_ahb_free_resources(struct ath11k_base *ab)
  1000. {
  1001. struct platform_device *pdev = ab->pdev;
  1002. ath11k_ahb_free_irq(ab);
  1003. ath11k_hal_srng_deinit(ab);
  1004. ath11k_ahb_release_smp2p_handle(ab);
  1005. ath11k_ahb_fw_resource_deinit(ab);
  1006. ath11k_ce_free_pipes(ab);
  1007. ath11k_core_free(ab);
  1008. platform_set_drvdata(pdev, NULL);
  1009. }
  1010. static int ath11k_ahb_remove(struct platform_device *pdev)
  1011. {
  1012. struct ath11k_base *ab = platform_get_drvdata(pdev);
  1013. if (test_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags)) {
  1014. ath11k_ahb_power_down(ab);
  1015. ath11k_debugfs_soc_destroy(ab);
  1016. ath11k_qmi_deinit_service(ab);
  1017. goto qmi_fail;
  1018. }
  1019. ath11k_ahb_remove_prepare(ab);
  1020. ath11k_core_deinit(ab);
  1021. qmi_fail:
  1022. ath11k_ahb_free_resources(ab);
  1023. return 0;
  1024. }
  1025. static void ath11k_ahb_shutdown(struct platform_device *pdev)
  1026. {
  1027. struct ath11k_base *ab = platform_get_drvdata(pdev);
  1028. /* platform shutdown() & remove() are mutually exclusive.
  1029. * remove() is invoked during rmmod & shutdown() during
  1030. * system reboot/shutdown.
  1031. */
  1032. ath11k_ahb_remove_prepare(ab);
  1033. if (!(test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)))
  1034. goto free_resources;
  1035. ath11k_core_deinit(ab);
  1036. free_resources:
  1037. ath11k_ahb_free_resources(ab);
  1038. }
  1039. static struct platform_driver ath11k_ahb_driver = {
  1040. .driver = {
  1041. .name = "ath11k",
  1042. .of_match_table = ath11k_ahb_of_match,
  1043. },
  1044. .probe = ath11k_ahb_probe,
  1045. .remove = ath11k_ahb_remove,
  1046. .shutdown = ath11k_ahb_shutdown,
  1047. };
  1048. static int ath11k_ahb_init(void)
  1049. {
  1050. return platform_driver_register(&ath11k_ahb_driver);
  1051. }
  1052. module_init(ath11k_ahb_init);
  1053. static void ath11k_ahb_exit(void)
  1054. {
  1055. platform_driver_unregister(&ath11k_ahb_driver);
  1056. }
  1057. module_exit(ath11k_ahb_exit);
  1058. MODULE_DESCRIPTION("Driver support for Qualcomm Technologies 802.11ax WLAN AHB devices");
  1059. MODULE_LICENSE("Dual BSD/GPL");