ce.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "hif.h"
  18. #include "pci.h"
  19. #include "ce.h"
  20. #include "debug.h"
  21. /*
  22. * Support for Copy Engine hardware, which is mainly used for
  23. * communication between Host and Target over a PCIe interconnect.
  24. */
  25. /*
  26. * A single CopyEngine (CE) comprises two "rings":
  27. * a source ring
  28. * a destination ring
  29. *
  30. * Each ring consists of a number of descriptors which specify
  31. * an address, length, and meta-data.
  32. *
  33. * Typically, one side of the PCIe interconnect (Host or Target)
  34. * controls one ring and the other side controls the other ring.
  35. * The source side chooses when to initiate a transfer and it
  36. * chooses what to send (buffer address, length). The destination
  37. * side keeps a supply of "anonymous receive buffers" available and
  38. * it handles incoming data as it arrives (when the destination
  39. * recieves an interrupt).
  40. *
  41. * The sender may send a simple buffer (address/length) or it may
  42. * send a small list of buffers. When a small list is sent, hardware
  43. * "gathers" these and they end up in a single destination buffer
  44. * with a single interrupt.
  45. *
  46. * There are several "contexts" managed by this layer -- more, it
  47. * may seem -- than should be needed. These are provided mainly for
  48. * maximum flexibility and especially to facilitate a simpler HIF
  49. * implementation. There are per-CopyEngine recv, send, and watermark
  50. * contexts. These are supplied by the caller when a recv, send,
  51. * or watermark handler is established and they are echoed back to
  52. * the caller when the respective callbacks are invoked. There is
  53. * also a per-transfer context supplied by the caller when a buffer
  54. * (or sendlist) is sent and when a buffer is enqueued for recv.
  55. * These per-transfer contexts are echoed back to the caller when
  56. * the buffer is sent/received.
  57. */
  58. static inline void ath10k_ce_dest_ring_write_index_set(struct ath10k *ar,
  59. u32 ce_ctrl_addr,
  60. unsigned int n)
  61. {
  62. ath10k_pci_write32(ar, ce_ctrl_addr + DST_WR_INDEX_ADDRESS, n);
  63. }
  64. static inline u32 ath10k_ce_dest_ring_write_index_get(struct ath10k *ar,
  65. u32 ce_ctrl_addr)
  66. {
  67. return ath10k_pci_read32(ar, ce_ctrl_addr + DST_WR_INDEX_ADDRESS);
  68. }
  69. static inline void ath10k_ce_src_ring_write_index_set(struct ath10k *ar,
  70. u32 ce_ctrl_addr,
  71. unsigned int n)
  72. {
  73. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  74. void __iomem *indicator_addr;
  75. if (!test_bit(ATH10K_PCI_FEATURE_HW_1_0_WARKAROUND, ar_pci->features)) {
  76. ath10k_pci_write32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS, n);
  77. return;
  78. }
  79. /* workaround for QCA988x_1.0 HW CE */
  80. indicator_addr = ar_pci->mem + ce_ctrl_addr + DST_WATERMARK_ADDRESS;
  81. if (ce_ctrl_addr == ath10k_ce_base_address(CDC_WAR_DATA_CE)) {
  82. iowrite32((CDC_WAR_MAGIC_STR | n), indicator_addr);
  83. } else {
  84. unsigned long irq_flags;
  85. local_irq_save(irq_flags);
  86. iowrite32(1, indicator_addr);
  87. /*
  88. * PCIE write waits for ACK in IPQ8K, there is no
  89. * need to read back value.
  90. */
  91. (void)ioread32(indicator_addr);
  92. (void)ioread32(indicator_addr); /* conservative */
  93. ath10k_pci_write32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS, n);
  94. iowrite32(0, indicator_addr);
  95. local_irq_restore(irq_flags);
  96. }
  97. }
  98. static inline u32 ath10k_ce_src_ring_write_index_get(struct ath10k *ar,
  99. u32 ce_ctrl_addr)
  100. {
  101. return ath10k_pci_read32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS);
  102. }
  103. static inline u32 ath10k_ce_src_ring_read_index_get(struct ath10k *ar,
  104. u32 ce_ctrl_addr)
  105. {
  106. return ath10k_pci_read32(ar, ce_ctrl_addr + CURRENT_SRRI_ADDRESS);
  107. }
  108. static inline void ath10k_ce_src_ring_base_addr_set(struct ath10k *ar,
  109. u32 ce_ctrl_addr,
  110. unsigned int addr)
  111. {
  112. ath10k_pci_write32(ar, ce_ctrl_addr + SR_BA_ADDRESS, addr);
  113. }
  114. static inline void ath10k_ce_src_ring_size_set(struct ath10k *ar,
  115. u32 ce_ctrl_addr,
  116. unsigned int n)
  117. {
  118. ath10k_pci_write32(ar, ce_ctrl_addr + SR_SIZE_ADDRESS, n);
  119. }
  120. static inline void ath10k_ce_src_ring_dmax_set(struct ath10k *ar,
  121. u32 ce_ctrl_addr,
  122. unsigned int n)
  123. {
  124. u32 ctrl1_addr = ath10k_pci_read32((ar),
  125. (ce_ctrl_addr) + CE_CTRL1_ADDRESS);
  126. ath10k_pci_write32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS,
  127. (ctrl1_addr & ~CE_CTRL1_DMAX_LENGTH_MASK) |
  128. CE_CTRL1_DMAX_LENGTH_SET(n));
  129. }
  130. static inline void ath10k_ce_src_ring_byte_swap_set(struct ath10k *ar,
  131. u32 ce_ctrl_addr,
  132. unsigned int n)
  133. {
  134. u32 ctrl1_addr = ath10k_pci_read32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS);
  135. ath10k_pci_write32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS,
  136. (ctrl1_addr & ~CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK) |
  137. CE_CTRL1_SRC_RING_BYTE_SWAP_EN_SET(n));
  138. }
  139. static inline void ath10k_ce_dest_ring_byte_swap_set(struct ath10k *ar,
  140. u32 ce_ctrl_addr,
  141. unsigned int n)
  142. {
  143. u32 ctrl1_addr = ath10k_pci_read32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS);
  144. ath10k_pci_write32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS,
  145. (ctrl1_addr & ~CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK) |
  146. CE_CTRL1_DST_RING_BYTE_SWAP_EN_SET(n));
  147. }
  148. static inline u32 ath10k_ce_dest_ring_read_index_get(struct ath10k *ar,
  149. u32 ce_ctrl_addr)
  150. {
  151. return ath10k_pci_read32(ar, ce_ctrl_addr + CURRENT_DRRI_ADDRESS);
  152. }
  153. static inline void ath10k_ce_dest_ring_base_addr_set(struct ath10k *ar,
  154. u32 ce_ctrl_addr,
  155. u32 addr)
  156. {
  157. ath10k_pci_write32(ar, ce_ctrl_addr + DR_BA_ADDRESS, addr);
  158. }
  159. static inline void ath10k_ce_dest_ring_size_set(struct ath10k *ar,
  160. u32 ce_ctrl_addr,
  161. unsigned int n)
  162. {
  163. ath10k_pci_write32(ar, ce_ctrl_addr + DR_SIZE_ADDRESS, n);
  164. }
  165. static inline void ath10k_ce_src_ring_highmark_set(struct ath10k *ar,
  166. u32 ce_ctrl_addr,
  167. unsigned int n)
  168. {
  169. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS);
  170. ath10k_pci_write32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS,
  171. (addr & ~SRC_WATERMARK_HIGH_MASK) |
  172. SRC_WATERMARK_HIGH_SET(n));
  173. }
  174. static inline void ath10k_ce_src_ring_lowmark_set(struct ath10k *ar,
  175. u32 ce_ctrl_addr,
  176. unsigned int n)
  177. {
  178. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS);
  179. ath10k_pci_write32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS,
  180. (addr & ~SRC_WATERMARK_LOW_MASK) |
  181. SRC_WATERMARK_LOW_SET(n));
  182. }
  183. static inline void ath10k_ce_dest_ring_highmark_set(struct ath10k *ar,
  184. u32 ce_ctrl_addr,
  185. unsigned int n)
  186. {
  187. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS);
  188. ath10k_pci_write32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS,
  189. (addr & ~DST_WATERMARK_HIGH_MASK) |
  190. DST_WATERMARK_HIGH_SET(n));
  191. }
  192. static inline void ath10k_ce_dest_ring_lowmark_set(struct ath10k *ar,
  193. u32 ce_ctrl_addr,
  194. unsigned int n)
  195. {
  196. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS);
  197. ath10k_pci_write32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS,
  198. (addr & ~DST_WATERMARK_LOW_MASK) |
  199. DST_WATERMARK_LOW_SET(n));
  200. }
  201. static inline void ath10k_ce_copy_complete_inter_enable(struct ath10k *ar,
  202. u32 ce_ctrl_addr)
  203. {
  204. u32 host_ie_addr = ath10k_pci_read32(ar,
  205. ce_ctrl_addr + HOST_IE_ADDRESS);
  206. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IE_ADDRESS,
  207. host_ie_addr | HOST_IE_COPY_COMPLETE_MASK);
  208. }
  209. static inline void ath10k_ce_copy_complete_intr_disable(struct ath10k *ar,
  210. u32 ce_ctrl_addr)
  211. {
  212. u32 host_ie_addr = ath10k_pci_read32(ar,
  213. ce_ctrl_addr + HOST_IE_ADDRESS);
  214. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IE_ADDRESS,
  215. host_ie_addr & ~HOST_IE_COPY_COMPLETE_MASK);
  216. }
  217. static inline void ath10k_ce_watermark_intr_disable(struct ath10k *ar,
  218. u32 ce_ctrl_addr)
  219. {
  220. u32 host_ie_addr = ath10k_pci_read32(ar,
  221. ce_ctrl_addr + HOST_IE_ADDRESS);
  222. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IE_ADDRESS,
  223. host_ie_addr & ~CE_WATERMARK_MASK);
  224. }
  225. static inline void ath10k_ce_error_intr_enable(struct ath10k *ar,
  226. u32 ce_ctrl_addr)
  227. {
  228. u32 misc_ie_addr = ath10k_pci_read32(ar,
  229. ce_ctrl_addr + MISC_IE_ADDRESS);
  230. ath10k_pci_write32(ar, ce_ctrl_addr + MISC_IE_ADDRESS,
  231. misc_ie_addr | CE_ERROR_MASK);
  232. }
  233. static inline void ath10k_ce_engine_int_status_clear(struct ath10k *ar,
  234. u32 ce_ctrl_addr,
  235. unsigned int mask)
  236. {
  237. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IS_ADDRESS, mask);
  238. }
  239. /*
  240. * Guts of ath10k_ce_send, used by both ath10k_ce_send and
  241. * ath10k_ce_sendlist_send.
  242. * The caller takes responsibility for any needed locking.
  243. */
  244. static int ath10k_ce_send_nolock(struct ce_state *ce_state,
  245. void *per_transfer_context,
  246. u32 buffer,
  247. unsigned int nbytes,
  248. unsigned int transfer_id,
  249. unsigned int flags)
  250. {
  251. struct ath10k *ar = ce_state->ar;
  252. struct ce_ring_state *src_ring = ce_state->src_ring;
  253. struct ce_desc *desc, *sdesc;
  254. unsigned int nentries_mask = src_ring->nentries_mask;
  255. unsigned int sw_index = src_ring->sw_index;
  256. unsigned int write_index = src_ring->write_index;
  257. u32 ctrl_addr = ce_state->ctrl_addr;
  258. u32 desc_flags = 0;
  259. int ret = 0;
  260. if (nbytes > ce_state->src_sz_max)
  261. ath10k_warn("%s: send more we can (nbytes: %d, max: %d)\n",
  262. __func__, nbytes, ce_state->src_sz_max);
  263. ath10k_pci_wake(ar);
  264. if (unlikely(CE_RING_DELTA(nentries_mask,
  265. write_index, sw_index - 1) <= 0)) {
  266. ret = -EIO;
  267. goto exit;
  268. }
  269. desc = CE_SRC_RING_TO_DESC(src_ring->base_addr_owner_space,
  270. write_index);
  271. sdesc = CE_SRC_RING_TO_DESC(src_ring->shadow_base, write_index);
  272. desc_flags |= SM(transfer_id, CE_DESC_FLAGS_META_DATA);
  273. if (flags & CE_SEND_FLAG_GATHER)
  274. desc_flags |= CE_DESC_FLAGS_GATHER;
  275. if (flags & CE_SEND_FLAG_BYTE_SWAP)
  276. desc_flags |= CE_DESC_FLAGS_BYTE_SWAP;
  277. sdesc->addr = __cpu_to_le32(buffer);
  278. sdesc->nbytes = __cpu_to_le16(nbytes);
  279. sdesc->flags = __cpu_to_le16(desc_flags);
  280. *desc = *sdesc;
  281. src_ring->per_transfer_context[write_index] = per_transfer_context;
  282. /* Update Source Ring Write Index */
  283. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  284. /* WORKAROUND */
  285. if (!(flags & CE_SEND_FLAG_GATHER))
  286. ath10k_ce_src_ring_write_index_set(ar, ctrl_addr, write_index);
  287. src_ring->write_index = write_index;
  288. exit:
  289. ath10k_pci_sleep(ar);
  290. return ret;
  291. }
  292. int ath10k_ce_send(struct ce_state *ce_state,
  293. void *per_transfer_context,
  294. u32 buffer,
  295. unsigned int nbytes,
  296. unsigned int transfer_id,
  297. unsigned int flags)
  298. {
  299. struct ath10k *ar = ce_state->ar;
  300. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  301. int ret;
  302. spin_lock_bh(&ar_pci->ce_lock);
  303. ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
  304. buffer, nbytes, transfer_id, flags);
  305. spin_unlock_bh(&ar_pci->ce_lock);
  306. return ret;
  307. }
  308. void ath10k_ce_sendlist_buf_add(struct ce_sendlist *sendlist, u32 buffer,
  309. unsigned int nbytes, u32 flags)
  310. {
  311. unsigned int num_items = sendlist->num_items;
  312. struct ce_sendlist_item *item;
  313. item = &sendlist->item[num_items];
  314. item->data = buffer;
  315. item->u.nbytes = nbytes;
  316. item->flags = flags;
  317. sendlist->num_items++;
  318. }
  319. int ath10k_ce_sendlist_send(struct ce_state *ce_state,
  320. void *per_transfer_context,
  321. struct ce_sendlist *sendlist,
  322. unsigned int transfer_id)
  323. {
  324. struct ce_ring_state *src_ring = ce_state->src_ring;
  325. struct ce_sendlist_item *item;
  326. struct ath10k *ar = ce_state->ar;
  327. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  328. unsigned int nentries_mask = src_ring->nentries_mask;
  329. unsigned int num_items = sendlist->num_items;
  330. unsigned int sw_index;
  331. unsigned int write_index;
  332. int i, delta, ret = -ENOMEM;
  333. spin_lock_bh(&ar_pci->ce_lock);
  334. sw_index = src_ring->sw_index;
  335. write_index = src_ring->write_index;
  336. delta = CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
  337. if (delta >= num_items) {
  338. /*
  339. * Handle all but the last item uniformly.
  340. */
  341. for (i = 0; i < num_items - 1; i++) {
  342. item = &sendlist->item[i];
  343. ret = ath10k_ce_send_nolock(ce_state,
  344. CE_SENDLIST_ITEM_CTXT,
  345. (u32) item->data,
  346. item->u.nbytes, transfer_id,
  347. item->flags |
  348. CE_SEND_FLAG_GATHER);
  349. if (ret)
  350. ath10k_warn("CE send failed for item: %d\n", i);
  351. }
  352. /*
  353. * Provide valid context pointer for final item.
  354. */
  355. item = &sendlist->item[i];
  356. ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
  357. (u32) item->data, item->u.nbytes,
  358. transfer_id, item->flags);
  359. if (ret)
  360. ath10k_warn("CE send failed for last item: %d\n", i);
  361. }
  362. spin_unlock_bh(&ar_pci->ce_lock);
  363. return ret;
  364. }
  365. int ath10k_ce_recv_buf_enqueue(struct ce_state *ce_state,
  366. void *per_recv_context,
  367. u32 buffer)
  368. {
  369. struct ce_ring_state *dest_ring = ce_state->dest_ring;
  370. u32 ctrl_addr = ce_state->ctrl_addr;
  371. struct ath10k *ar = ce_state->ar;
  372. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  373. unsigned int nentries_mask = dest_ring->nentries_mask;
  374. unsigned int write_index;
  375. unsigned int sw_index;
  376. int ret;
  377. spin_lock_bh(&ar_pci->ce_lock);
  378. write_index = dest_ring->write_index;
  379. sw_index = dest_ring->sw_index;
  380. ath10k_pci_wake(ar);
  381. if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) {
  382. struct ce_desc *base = dest_ring->base_addr_owner_space;
  383. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, write_index);
  384. /* Update destination descriptor */
  385. desc->addr = __cpu_to_le32(buffer);
  386. desc->nbytes = 0;
  387. dest_ring->per_transfer_context[write_index] =
  388. per_recv_context;
  389. /* Update Destination Ring Write Index */
  390. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  391. ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
  392. dest_ring->write_index = write_index;
  393. ret = 0;
  394. } else {
  395. ret = -EIO;
  396. }
  397. ath10k_pci_sleep(ar);
  398. spin_unlock_bh(&ar_pci->ce_lock);
  399. return ret;
  400. }
  401. /*
  402. * Guts of ath10k_ce_completed_recv_next.
  403. * The caller takes responsibility for any necessary locking.
  404. */
  405. static int ath10k_ce_completed_recv_next_nolock(struct ce_state *ce_state,
  406. void **per_transfer_contextp,
  407. u32 *bufferp,
  408. unsigned int *nbytesp,
  409. unsigned int *transfer_idp,
  410. unsigned int *flagsp)
  411. {
  412. struct ce_ring_state *dest_ring = ce_state->dest_ring;
  413. unsigned int nentries_mask = dest_ring->nentries_mask;
  414. unsigned int sw_index = dest_ring->sw_index;
  415. struct ce_desc *base = dest_ring->base_addr_owner_space;
  416. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  417. struct ce_desc sdesc;
  418. u16 nbytes;
  419. /* Copy in one go for performance reasons */
  420. sdesc = *desc;
  421. nbytes = __le16_to_cpu(sdesc.nbytes);
  422. if (nbytes == 0) {
  423. /*
  424. * This closes a relatively unusual race where the Host
  425. * sees the updated DRRI before the update to the
  426. * corresponding descriptor has completed. We treat this
  427. * as a descriptor that is not yet done.
  428. */
  429. return -EIO;
  430. }
  431. desc->nbytes = 0;
  432. /* Return data from completed destination descriptor */
  433. *bufferp = __le32_to_cpu(sdesc.addr);
  434. *nbytesp = nbytes;
  435. *transfer_idp = MS(__le16_to_cpu(sdesc.flags), CE_DESC_FLAGS_META_DATA);
  436. if (__le16_to_cpu(sdesc.flags) & CE_DESC_FLAGS_BYTE_SWAP)
  437. *flagsp = CE_RECV_FLAG_SWAPPED;
  438. else
  439. *flagsp = 0;
  440. if (per_transfer_contextp)
  441. *per_transfer_contextp =
  442. dest_ring->per_transfer_context[sw_index];
  443. /* sanity */
  444. dest_ring->per_transfer_context[sw_index] = NULL;
  445. /* Update sw_index */
  446. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  447. dest_ring->sw_index = sw_index;
  448. return 0;
  449. }
  450. int ath10k_ce_completed_recv_next(struct ce_state *ce_state,
  451. void **per_transfer_contextp,
  452. u32 *bufferp,
  453. unsigned int *nbytesp,
  454. unsigned int *transfer_idp,
  455. unsigned int *flagsp)
  456. {
  457. struct ath10k *ar = ce_state->ar;
  458. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  459. int ret;
  460. spin_lock_bh(&ar_pci->ce_lock);
  461. ret = ath10k_ce_completed_recv_next_nolock(ce_state,
  462. per_transfer_contextp,
  463. bufferp, nbytesp,
  464. transfer_idp, flagsp);
  465. spin_unlock_bh(&ar_pci->ce_lock);
  466. return ret;
  467. }
  468. int ath10k_ce_revoke_recv_next(struct ce_state *ce_state,
  469. void **per_transfer_contextp,
  470. u32 *bufferp)
  471. {
  472. struct ce_ring_state *dest_ring;
  473. unsigned int nentries_mask;
  474. unsigned int sw_index;
  475. unsigned int write_index;
  476. int ret;
  477. struct ath10k *ar;
  478. struct ath10k_pci *ar_pci;
  479. dest_ring = ce_state->dest_ring;
  480. if (!dest_ring)
  481. return -EIO;
  482. ar = ce_state->ar;
  483. ar_pci = ath10k_pci_priv(ar);
  484. spin_lock_bh(&ar_pci->ce_lock);
  485. nentries_mask = dest_ring->nentries_mask;
  486. sw_index = dest_ring->sw_index;
  487. write_index = dest_ring->write_index;
  488. if (write_index != sw_index) {
  489. struct ce_desc *base = dest_ring->base_addr_owner_space;
  490. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  491. /* Return data from completed destination descriptor */
  492. *bufferp = __le32_to_cpu(desc->addr);
  493. if (per_transfer_contextp)
  494. *per_transfer_contextp =
  495. dest_ring->per_transfer_context[sw_index];
  496. /* sanity */
  497. dest_ring->per_transfer_context[sw_index] = NULL;
  498. /* Update sw_index */
  499. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  500. dest_ring->sw_index = sw_index;
  501. ret = 0;
  502. } else {
  503. ret = -EIO;
  504. }
  505. spin_unlock_bh(&ar_pci->ce_lock);
  506. return ret;
  507. }
  508. /*
  509. * Guts of ath10k_ce_completed_send_next.
  510. * The caller takes responsibility for any necessary locking.
  511. */
  512. static int ath10k_ce_completed_send_next_nolock(struct ce_state *ce_state,
  513. void **per_transfer_contextp,
  514. u32 *bufferp,
  515. unsigned int *nbytesp,
  516. unsigned int *transfer_idp)
  517. {
  518. struct ce_ring_state *src_ring = ce_state->src_ring;
  519. u32 ctrl_addr = ce_state->ctrl_addr;
  520. struct ath10k *ar = ce_state->ar;
  521. unsigned int nentries_mask = src_ring->nentries_mask;
  522. unsigned int sw_index = src_ring->sw_index;
  523. unsigned int read_index;
  524. int ret = -EIO;
  525. if (src_ring->hw_index == sw_index) {
  526. /*
  527. * The SW completion index has caught up with the cached
  528. * version of the HW completion index.
  529. * Update the cached HW completion index to see whether
  530. * the SW has really caught up to the HW, or if the cached
  531. * value of the HW index has become stale.
  532. */
  533. ath10k_pci_wake(ar);
  534. src_ring->hw_index =
  535. ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  536. ath10k_pci_sleep(ar);
  537. }
  538. read_index = src_ring->hw_index;
  539. if ((read_index != sw_index) && (read_index != 0xffffffff)) {
  540. struct ce_desc *sbase = src_ring->shadow_base;
  541. struct ce_desc *sdesc = CE_SRC_RING_TO_DESC(sbase, sw_index);
  542. /* Return data from completed source descriptor */
  543. *bufferp = __le32_to_cpu(sdesc->addr);
  544. *nbytesp = __le16_to_cpu(sdesc->nbytes);
  545. *transfer_idp = MS(__le16_to_cpu(sdesc->flags),
  546. CE_DESC_FLAGS_META_DATA);
  547. if (per_transfer_contextp)
  548. *per_transfer_contextp =
  549. src_ring->per_transfer_context[sw_index];
  550. /* sanity */
  551. src_ring->per_transfer_context[sw_index] = NULL;
  552. /* Update sw_index */
  553. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  554. src_ring->sw_index = sw_index;
  555. ret = 0;
  556. }
  557. return ret;
  558. }
  559. /* NB: Modeled after ath10k_ce_completed_send_next */
  560. int ath10k_ce_cancel_send_next(struct ce_state *ce_state,
  561. void **per_transfer_contextp,
  562. u32 *bufferp,
  563. unsigned int *nbytesp,
  564. unsigned int *transfer_idp)
  565. {
  566. struct ce_ring_state *src_ring;
  567. unsigned int nentries_mask;
  568. unsigned int sw_index;
  569. unsigned int write_index;
  570. int ret;
  571. struct ath10k *ar;
  572. struct ath10k_pci *ar_pci;
  573. src_ring = ce_state->src_ring;
  574. if (!src_ring)
  575. return -EIO;
  576. ar = ce_state->ar;
  577. ar_pci = ath10k_pci_priv(ar);
  578. spin_lock_bh(&ar_pci->ce_lock);
  579. nentries_mask = src_ring->nentries_mask;
  580. sw_index = src_ring->sw_index;
  581. write_index = src_ring->write_index;
  582. if (write_index != sw_index) {
  583. struct ce_desc *base = src_ring->base_addr_owner_space;
  584. struct ce_desc *desc = CE_SRC_RING_TO_DESC(base, sw_index);
  585. /* Return data from completed source descriptor */
  586. *bufferp = __le32_to_cpu(desc->addr);
  587. *nbytesp = __le16_to_cpu(desc->nbytes);
  588. *transfer_idp = MS(__le16_to_cpu(desc->flags),
  589. CE_DESC_FLAGS_META_DATA);
  590. if (per_transfer_contextp)
  591. *per_transfer_contextp =
  592. src_ring->per_transfer_context[sw_index];
  593. /* sanity */
  594. src_ring->per_transfer_context[sw_index] = NULL;
  595. /* Update sw_index */
  596. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  597. src_ring->sw_index = sw_index;
  598. ret = 0;
  599. } else {
  600. ret = -EIO;
  601. }
  602. spin_unlock_bh(&ar_pci->ce_lock);
  603. return ret;
  604. }
  605. int ath10k_ce_completed_send_next(struct ce_state *ce_state,
  606. void **per_transfer_contextp,
  607. u32 *bufferp,
  608. unsigned int *nbytesp,
  609. unsigned int *transfer_idp)
  610. {
  611. struct ath10k *ar = ce_state->ar;
  612. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  613. int ret;
  614. spin_lock_bh(&ar_pci->ce_lock);
  615. ret = ath10k_ce_completed_send_next_nolock(ce_state,
  616. per_transfer_contextp,
  617. bufferp, nbytesp,
  618. transfer_idp);
  619. spin_unlock_bh(&ar_pci->ce_lock);
  620. return ret;
  621. }
  622. /*
  623. * Guts of interrupt handler for per-engine interrupts on a particular CE.
  624. *
  625. * Invokes registered callbacks for recv_complete,
  626. * send_complete, and watermarks.
  627. */
  628. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id)
  629. {
  630. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  631. struct ce_state *ce_state = ar_pci->ce_id_to_state[ce_id];
  632. u32 ctrl_addr = ce_state->ctrl_addr;
  633. void *transfer_context;
  634. u32 buf;
  635. unsigned int nbytes;
  636. unsigned int id;
  637. unsigned int flags;
  638. ath10k_pci_wake(ar);
  639. spin_lock_bh(&ar_pci->ce_lock);
  640. /* Clear the copy-complete interrupts that will be handled here. */
  641. ath10k_ce_engine_int_status_clear(ar, ctrl_addr,
  642. HOST_IS_COPY_COMPLETE_MASK);
  643. if (ce_state->recv_cb) {
  644. /*
  645. * Pop completed recv buffers and call the registered
  646. * recv callback for each
  647. */
  648. while (ath10k_ce_completed_recv_next_nolock(ce_state,
  649. &transfer_context,
  650. &buf, &nbytes,
  651. &id, &flags) == 0) {
  652. spin_unlock_bh(&ar_pci->ce_lock);
  653. ce_state->recv_cb(ce_state, transfer_context, buf,
  654. nbytes, id, flags);
  655. spin_lock_bh(&ar_pci->ce_lock);
  656. }
  657. }
  658. if (ce_state->send_cb) {
  659. /*
  660. * Pop completed send buffers and call the registered
  661. * send callback for each
  662. */
  663. while (ath10k_ce_completed_send_next_nolock(ce_state,
  664. &transfer_context,
  665. &buf,
  666. &nbytes,
  667. &id) == 0) {
  668. spin_unlock_bh(&ar_pci->ce_lock);
  669. ce_state->send_cb(ce_state, transfer_context,
  670. buf, nbytes, id);
  671. spin_lock_bh(&ar_pci->ce_lock);
  672. }
  673. }
  674. /*
  675. * Misc CE interrupts are not being handled, but still need
  676. * to be cleared.
  677. */
  678. ath10k_ce_engine_int_status_clear(ar, ctrl_addr, CE_WATERMARK_MASK);
  679. spin_unlock_bh(&ar_pci->ce_lock);
  680. ath10k_pci_sleep(ar);
  681. }
  682. /*
  683. * Handler for per-engine interrupts on ALL active CEs.
  684. * This is used in cases where the system is sharing a
  685. * single interrput for all CEs
  686. */
  687. void ath10k_ce_per_engine_service_any(struct ath10k *ar)
  688. {
  689. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  690. int ce_id;
  691. u32 intr_summary;
  692. ath10k_pci_wake(ar);
  693. intr_summary = CE_INTERRUPT_SUMMARY(ar);
  694. for (ce_id = 0; intr_summary && (ce_id < ar_pci->ce_count); ce_id++) {
  695. if (intr_summary & (1 << ce_id))
  696. intr_summary &= ~(1 << ce_id);
  697. else
  698. /* no intr pending on this CE */
  699. continue;
  700. ath10k_ce_per_engine_service(ar, ce_id);
  701. }
  702. ath10k_pci_sleep(ar);
  703. }
  704. /*
  705. * Adjust interrupts for the copy complete handler.
  706. * If it's needed for either send or recv, then unmask
  707. * this interrupt; otherwise, mask it.
  708. *
  709. * Called with ce_lock held.
  710. */
  711. static void ath10k_ce_per_engine_handler_adjust(struct ce_state *ce_state,
  712. int disable_copy_compl_intr)
  713. {
  714. u32 ctrl_addr = ce_state->ctrl_addr;
  715. struct ath10k *ar = ce_state->ar;
  716. ath10k_pci_wake(ar);
  717. if ((!disable_copy_compl_intr) &&
  718. (ce_state->send_cb || ce_state->recv_cb))
  719. ath10k_ce_copy_complete_inter_enable(ar, ctrl_addr);
  720. else
  721. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  722. ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
  723. ath10k_pci_sleep(ar);
  724. }
  725. void ath10k_ce_disable_interrupts(struct ath10k *ar)
  726. {
  727. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  728. int ce_id;
  729. ath10k_pci_wake(ar);
  730. for (ce_id = 0; ce_id < ar_pci->ce_count; ce_id++) {
  731. struct ce_state *ce_state = ar_pci->ce_id_to_state[ce_id];
  732. u32 ctrl_addr = ce_state->ctrl_addr;
  733. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  734. }
  735. ath10k_pci_sleep(ar);
  736. }
  737. void ath10k_ce_send_cb_register(struct ce_state *ce_state,
  738. void (*send_cb) (struct ce_state *ce_state,
  739. void *transfer_context,
  740. u32 buffer,
  741. unsigned int nbytes,
  742. unsigned int transfer_id),
  743. int disable_interrupts)
  744. {
  745. struct ath10k *ar = ce_state->ar;
  746. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  747. spin_lock_bh(&ar_pci->ce_lock);
  748. ce_state->send_cb = send_cb;
  749. ath10k_ce_per_engine_handler_adjust(ce_state, disable_interrupts);
  750. spin_unlock_bh(&ar_pci->ce_lock);
  751. }
  752. void ath10k_ce_recv_cb_register(struct ce_state *ce_state,
  753. void (*recv_cb) (struct ce_state *ce_state,
  754. void *transfer_context,
  755. u32 buffer,
  756. unsigned int nbytes,
  757. unsigned int transfer_id,
  758. unsigned int flags))
  759. {
  760. struct ath10k *ar = ce_state->ar;
  761. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  762. spin_lock_bh(&ar_pci->ce_lock);
  763. ce_state->recv_cb = recv_cb;
  764. ath10k_ce_per_engine_handler_adjust(ce_state, 0);
  765. spin_unlock_bh(&ar_pci->ce_lock);
  766. }
  767. static int ath10k_ce_init_src_ring(struct ath10k *ar,
  768. unsigned int ce_id,
  769. struct ce_state *ce_state,
  770. const struct ce_attr *attr)
  771. {
  772. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  773. struct ce_ring_state *src_ring;
  774. unsigned int nentries = attr->src_nentries;
  775. unsigned int ce_nbytes;
  776. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  777. dma_addr_t base_addr;
  778. char *ptr;
  779. nentries = roundup_pow_of_two(nentries);
  780. if (ce_state->src_ring) {
  781. WARN_ON(ce_state->src_ring->nentries != nentries);
  782. return 0;
  783. }
  784. ce_nbytes = sizeof(struct ce_ring_state) + (nentries * sizeof(void *));
  785. ptr = kzalloc(ce_nbytes, GFP_KERNEL);
  786. if (ptr == NULL)
  787. return -ENOMEM;
  788. ce_state->src_ring = (struct ce_ring_state *)ptr;
  789. src_ring = ce_state->src_ring;
  790. ptr += sizeof(struct ce_ring_state);
  791. src_ring->nentries = nentries;
  792. src_ring->nentries_mask = nentries - 1;
  793. ath10k_pci_wake(ar);
  794. src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  795. src_ring->hw_index = src_ring->sw_index;
  796. src_ring->write_index =
  797. ath10k_ce_src_ring_write_index_get(ar, ctrl_addr);
  798. ath10k_pci_sleep(ar);
  799. src_ring->per_transfer_context = (void **)ptr;
  800. /*
  801. * Legacy platforms that do not support cache
  802. * coherent DMA are unsupported
  803. */
  804. src_ring->base_addr_owner_space_unaligned =
  805. pci_alloc_consistent(ar_pci->pdev,
  806. (nentries * sizeof(struct ce_desc) +
  807. CE_DESC_RING_ALIGN),
  808. &base_addr);
  809. src_ring->base_addr_ce_space_unaligned = base_addr;
  810. src_ring->base_addr_owner_space = PTR_ALIGN(
  811. src_ring->base_addr_owner_space_unaligned,
  812. CE_DESC_RING_ALIGN);
  813. src_ring->base_addr_ce_space = ALIGN(
  814. src_ring->base_addr_ce_space_unaligned,
  815. CE_DESC_RING_ALIGN);
  816. /*
  817. * Also allocate a shadow src ring in regular
  818. * mem to use for faster access.
  819. */
  820. src_ring->shadow_base_unaligned =
  821. kmalloc((nentries * sizeof(struct ce_desc) +
  822. CE_DESC_RING_ALIGN), GFP_KERNEL);
  823. src_ring->shadow_base = PTR_ALIGN(
  824. src_ring->shadow_base_unaligned,
  825. CE_DESC_RING_ALIGN);
  826. ath10k_pci_wake(ar);
  827. ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr,
  828. src_ring->base_addr_ce_space);
  829. ath10k_ce_src_ring_size_set(ar, ctrl_addr, nentries);
  830. ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, attr->src_sz_max);
  831. ath10k_ce_src_ring_byte_swap_set(ar, ctrl_addr, 0);
  832. ath10k_ce_src_ring_lowmark_set(ar, ctrl_addr, 0);
  833. ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, nentries);
  834. ath10k_pci_sleep(ar);
  835. return 0;
  836. }
  837. static int ath10k_ce_init_dest_ring(struct ath10k *ar,
  838. unsigned int ce_id,
  839. struct ce_state *ce_state,
  840. const struct ce_attr *attr)
  841. {
  842. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  843. struct ce_ring_state *dest_ring;
  844. unsigned int nentries = attr->dest_nentries;
  845. unsigned int ce_nbytes;
  846. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  847. dma_addr_t base_addr;
  848. char *ptr;
  849. nentries = roundup_pow_of_two(nentries);
  850. if (ce_state->dest_ring) {
  851. WARN_ON(ce_state->dest_ring->nentries != nentries);
  852. return 0;
  853. }
  854. ce_nbytes = sizeof(struct ce_ring_state) + (nentries * sizeof(void *));
  855. ptr = kzalloc(ce_nbytes, GFP_KERNEL);
  856. if (ptr == NULL)
  857. return -ENOMEM;
  858. ce_state->dest_ring = (struct ce_ring_state *)ptr;
  859. dest_ring = ce_state->dest_ring;
  860. ptr += sizeof(struct ce_ring_state);
  861. dest_ring->nentries = nentries;
  862. dest_ring->nentries_mask = nentries - 1;
  863. ath10k_pci_wake(ar);
  864. dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr);
  865. dest_ring->write_index =
  866. ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
  867. ath10k_pci_sleep(ar);
  868. dest_ring->per_transfer_context = (void **)ptr;
  869. /*
  870. * Legacy platforms that do not support cache
  871. * coherent DMA are unsupported
  872. */
  873. dest_ring->base_addr_owner_space_unaligned =
  874. pci_alloc_consistent(ar_pci->pdev,
  875. (nentries * sizeof(struct ce_desc) +
  876. CE_DESC_RING_ALIGN),
  877. &base_addr);
  878. dest_ring->base_addr_ce_space_unaligned = base_addr;
  879. /*
  880. * Correctly initialize memory to 0 to prevent garbage
  881. * data crashing system when download firmware
  882. */
  883. memset(dest_ring->base_addr_owner_space_unaligned, 0,
  884. nentries * sizeof(struct ce_desc) + CE_DESC_RING_ALIGN);
  885. dest_ring->base_addr_owner_space = PTR_ALIGN(
  886. dest_ring->base_addr_owner_space_unaligned,
  887. CE_DESC_RING_ALIGN);
  888. dest_ring->base_addr_ce_space = ALIGN(
  889. dest_ring->base_addr_ce_space_unaligned,
  890. CE_DESC_RING_ALIGN);
  891. ath10k_pci_wake(ar);
  892. ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr,
  893. dest_ring->base_addr_ce_space);
  894. ath10k_ce_dest_ring_size_set(ar, ctrl_addr, nentries);
  895. ath10k_ce_dest_ring_byte_swap_set(ar, ctrl_addr, 0);
  896. ath10k_ce_dest_ring_lowmark_set(ar, ctrl_addr, 0);
  897. ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, nentries);
  898. ath10k_pci_sleep(ar);
  899. return 0;
  900. }
  901. static struct ce_state *ath10k_ce_init_state(struct ath10k *ar,
  902. unsigned int ce_id,
  903. const struct ce_attr *attr)
  904. {
  905. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  906. struct ce_state *ce_state = NULL;
  907. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  908. spin_lock_bh(&ar_pci->ce_lock);
  909. if (!ar_pci->ce_id_to_state[ce_id]) {
  910. ce_state = kzalloc(sizeof(*ce_state), GFP_ATOMIC);
  911. if (ce_state == NULL) {
  912. spin_unlock_bh(&ar_pci->ce_lock);
  913. return NULL;
  914. }
  915. ar_pci->ce_id_to_state[ce_id] = ce_state;
  916. ce_state->ar = ar;
  917. ce_state->id = ce_id;
  918. ce_state->ctrl_addr = ctrl_addr;
  919. ce_state->state = CE_RUNNING;
  920. /* Save attribute flags */
  921. ce_state->attr_flags = attr->flags;
  922. ce_state->src_sz_max = attr->src_sz_max;
  923. }
  924. spin_unlock_bh(&ar_pci->ce_lock);
  925. return ce_state;
  926. }
  927. /*
  928. * Initialize a Copy Engine based on caller-supplied attributes.
  929. * This may be called once to initialize both source and destination
  930. * rings or it may be called twice for separate source and destination
  931. * initialization. It may be that only one side or the other is
  932. * initialized by software/firmware.
  933. */
  934. struct ce_state *ath10k_ce_init(struct ath10k *ar,
  935. unsigned int ce_id,
  936. const struct ce_attr *attr)
  937. {
  938. struct ce_state *ce_state;
  939. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  940. ce_state = ath10k_ce_init_state(ar, ce_id, attr);
  941. if (!ce_state) {
  942. ath10k_err("Failed to initialize CE state for ID: %d\n", ce_id);
  943. return NULL;
  944. }
  945. if (attr->src_nentries) {
  946. if (ath10k_ce_init_src_ring(ar, ce_id, ce_state, attr)) {
  947. ath10k_err("Failed to initialize CE src ring for ID: %d\n",
  948. ce_id);
  949. ath10k_ce_deinit(ce_state);
  950. return NULL;
  951. }
  952. }
  953. if (attr->dest_nentries) {
  954. if (ath10k_ce_init_dest_ring(ar, ce_id, ce_state, attr)) {
  955. ath10k_err("Failed to initialize CE dest ring for ID: %d\n",
  956. ce_id);
  957. ath10k_ce_deinit(ce_state);
  958. return NULL;
  959. }
  960. }
  961. /* Enable CE error interrupts */
  962. ath10k_pci_wake(ar);
  963. ath10k_ce_error_intr_enable(ar, ctrl_addr);
  964. ath10k_pci_sleep(ar);
  965. return ce_state;
  966. }
  967. void ath10k_ce_deinit(struct ce_state *ce_state)
  968. {
  969. unsigned int ce_id = ce_state->id;
  970. struct ath10k *ar = ce_state->ar;
  971. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  972. ce_state->state = CE_UNUSED;
  973. ar_pci->ce_id_to_state[ce_id] = NULL;
  974. if (ce_state->src_ring) {
  975. kfree(ce_state->src_ring->shadow_base_unaligned);
  976. pci_free_consistent(ar_pci->pdev,
  977. (ce_state->src_ring->nentries *
  978. sizeof(struct ce_desc) +
  979. CE_DESC_RING_ALIGN),
  980. ce_state->src_ring->base_addr_owner_space,
  981. ce_state->src_ring->base_addr_ce_space);
  982. kfree(ce_state->src_ring);
  983. }
  984. if (ce_state->dest_ring) {
  985. pci_free_consistent(ar_pci->pdev,
  986. (ce_state->dest_ring->nentries *
  987. sizeof(struct ce_desc) +
  988. CE_DESC_RING_ALIGN),
  989. ce_state->dest_ring->base_addr_owner_space,
  990. ce_state->dest_ring->base_addr_ce_space);
  991. kfree(ce_state->dest_ring);
  992. }
  993. kfree(ce_state);
  994. }