ce.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  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. ath10k_pci_write32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS, n);
  74. }
  75. static inline u32 ath10k_ce_src_ring_write_index_get(struct ath10k *ar,
  76. u32 ce_ctrl_addr)
  77. {
  78. return ath10k_pci_read32(ar, ce_ctrl_addr + SR_WR_INDEX_ADDRESS);
  79. }
  80. static inline u32 ath10k_ce_src_ring_read_index_get(struct ath10k *ar,
  81. u32 ce_ctrl_addr)
  82. {
  83. return ath10k_pci_read32(ar, ce_ctrl_addr + CURRENT_SRRI_ADDRESS);
  84. }
  85. static inline void ath10k_ce_src_ring_base_addr_set(struct ath10k *ar,
  86. u32 ce_ctrl_addr,
  87. unsigned int addr)
  88. {
  89. ath10k_pci_write32(ar, ce_ctrl_addr + SR_BA_ADDRESS, addr);
  90. }
  91. static inline void ath10k_ce_src_ring_size_set(struct ath10k *ar,
  92. u32 ce_ctrl_addr,
  93. unsigned int n)
  94. {
  95. ath10k_pci_write32(ar, ce_ctrl_addr + SR_SIZE_ADDRESS, n);
  96. }
  97. static inline void ath10k_ce_src_ring_dmax_set(struct ath10k *ar,
  98. u32 ce_ctrl_addr,
  99. unsigned int n)
  100. {
  101. u32 ctrl1_addr = ath10k_pci_read32((ar),
  102. (ce_ctrl_addr) + CE_CTRL1_ADDRESS);
  103. ath10k_pci_write32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS,
  104. (ctrl1_addr & ~CE_CTRL1_DMAX_LENGTH_MASK) |
  105. CE_CTRL1_DMAX_LENGTH_SET(n));
  106. }
  107. static inline void ath10k_ce_src_ring_byte_swap_set(struct ath10k *ar,
  108. u32 ce_ctrl_addr,
  109. unsigned int n)
  110. {
  111. u32 ctrl1_addr = ath10k_pci_read32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS);
  112. ath10k_pci_write32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS,
  113. (ctrl1_addr & ~CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK) |
  114. CE_CTRL1_SRC_RING_BYTE_SWAP_EN_SET(n));
  115. }
  116. static inline void ath10k_ce_dest_ring_byte_swap_set(struct ath10k *ar,
  117. u32 ce_ctrl_addr,
  118. unsigned int n)
  119. {
  120. u32 ctrl1_addr = ath10k_pci_read32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS);
  121. ath10k_pci_write32(ar, ce_ctrl_addr + CE_CTRL1_ADDRESS,
  122. (ctrl1_addr & ~CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK) |
  123. CE_CTRL1_DST_RING_BYTE_SWAP_EN_SET(n));
  124. }
  125. static inline u32 ath10k_ce_dest_ring_read_index_get(struct ath10k *ar,
  126. u32 ce_ctrl_addr)
  127. {
  128. return ath10k_pci_read32(ar, ce_ctrl_addr + CURRENT_DRRI_ADDRESS);
  129. }
  130. static inline void ath10k_ce_dest_ring_base_addr_set(struct ath10k *ar,
  131. u32 ce_ctrl_addr,
  132. u32 addr)
  133. {
  134. ath10k_pci_write32(ar, ce_ctrl_addr + DR_BA_ADDRESS, addr);
  135. }
  136. static inline void ath10k_ce_dest_ring_size_set(struct ath10k *ar,
  137. u32 ce_ctrl_addr,
  138. unsigned int n)
  139. {
  140. ath10k_pci_write32(ar, ce_ctrl_addr + DR_SIZE_ADDRESS, n);
  141. }
  142. static inline void ath10k_ce_src_ring_highmark_set(struct ath10k *ar,
  143. u32 ce_ctrl_addr,
  144. unsigned int n)
  145. {
  146. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS);
  147. ath10k_pci_write32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS,
  148. (addr & ~SRC_WATERMARK_HIGH_MASK) |
  149. SRC_WATERMARK_HIGH_SET(n));
  150. }
  151. static inline void ath10k_ce_src_ring_lowmark_set(struct ath10k *ar,
  152. u32 ce_ctrl_addr,
  153. unsigned int n)
  154. {
  155. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS);
  156. ath10k_pci_write32(ar, ce_ctrl_addr + SRC_WATERMARK_ADDRESS,
  157. (addr & ~SRC_WATERMARK_LOW_MASK) |
  158. SRC_WATERMARK_LOW_SET(n));
  159. }
  160. static inline void ath10k_ce_dest_ring_highmark_set(struct ath10k *ar,
  161. u32 ce_ctrl_addr,
  162. unsigned int n)
  163. {
  164. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS);
  165. ath10k_pci_write32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS,
  166. (addr & ~DST_WATERMARK_HIGH_MASK) |
  167. DST_WATERMARK_HIGH_SET(n));
  168. }
  169. static inline void ath10k_ce_dest_ring_lowmark_set(struct ath10k *ar,
  170. u32 ce_ctrl_addr,
  171. unsigned int n)
  172. {
  173. u32 addr = ath10k_pci_read32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS);
  174. ath10k_pci_write32(ar, ce_ctrl_addr + DST_WATERMARK_ADDRESS,
  175. (addr & ~DST_WATERMARK_LOW_MASK) |
  176. DST_WATERMARK_LOW_SET(n));
  177. }
  178. static inline void ath10k_ce_copy_complete_inter_enable(struct ath10k *ar,
  179. u32 ce_ctrl_addr)
  180. {
  181. u32 host_ie_addr = ath10k_pci_read32(ar,
  182. ce_ctrl_addr + HOST_IE_ADDRESS);
  183. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IE_ADDRESS,
  184. host_ie_addr | HOST_IE_COPY_COMPLETE_MASK);
  185. }
  186. static inline void ath10k_ce_copy_complete_intr_disable(struct ath10k *ar,
  187. u32 ce_ctrl_addr)
  188. {
  189. u32 host_ie_addr = ath10k_pci_read32(ar,
  190. ce_ctrl_addr + HOST_IE_ADDRESS);
  191. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IE_ADDRESS,
  192. host_ie_addr & ~HOST_IE_COPY_COMPLETE_MASK);
  193. }
  194. static inline void ath10k_ce_watermark_intr_disable(struct ath10k *ar,
  195. u32 ce_ctrl_addr)
  196. {
  197. u32 host_ie_addr = ath10k_pci_read32(ar,
  198. ce_ctrl_addr + HOST_IE_ADDRESS);
  199. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IE_ADDRESS,
  200. host_ie_addr & ~CE_WATERMARK_MASK);
  201. }
  202. static inline void ath10k_ce_error_intr_enable(struct ath10k *ar,
  203. u32 ce_ctrl_addr)
  204. {
  205. u32 misc_ie_addr = ath10k_pci_read32(ar,
  206. ce_ctrl_addr + MISC_IE_ADDRESS);
  207. ath10k_pci_write32(ar, ce_ctrl_addr + MISC_IE_ADDRESS,
  208. misc_ie_addr | CE_ERROR_MASK);
  209. }
  210. static inline void ath10k_ce_error_intr_disable(struct ath10k *ar,
  211. u32 ce_ctrl_addr)
  212. {
  213. u32 misc_ie_addr = ath10k_pci_read32(ar,
  214. ce_ctrl_addr + MISC_IE_ADDRESS);
  215. ath10k_pci_write32(ar, ce_ctrl_addr + MISC_IE_ADDRESS,
  216. misc_ie_addr & ~CE_ERROR_MASK);
  217. }
  218. static inline void ath10k_ce_engine_int_status_clear(struct ath10k *ar,
  219. u32 ce_ctrl_addr,
  220. unsigned int mask)
  221. {
  222. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IS_ADDRESS, mask);
  223. }
  224. /*
  225. * Guts of ath10k_ce_send, used by both ath10k_ce_send and
  226. * ath10k_ce_sendlist_send.
  227. * The caller takes responsibility for any needed locking.
  228. */
  229. int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
  230. void *per_transfer_context,
  231. u32 buffer,
  232. unsigned int nbytes,
  233. unsigned int transfer_id,
  234. unsigned int flags)
  235. {
  236. struct ath10k *ar = ce_state->ar;
  237. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  238. struct ce_desc *desc, sdesc;
  239. unsigned int nentries_mask = src_ring->nentries_mask;
  240. unsigned int sw_index = src_ring->sw_index;
  241. unsigned int write_index = src_ring->write_index;
  242. u32 ctrl_addr = ce_state->ctrl_addr;
  243. u32 desc_flags = 0;
  244. int ret = 0;
  245. if (nbytes > ce_state->src_sz_max)
  246. ath10k_warn(ar, "%s: send more we can (nbytes: %d, max: %d)\n",
  247. __func__, nbytes, ce_state->src_sz_max);
  248. if (unlikely(CE_RING_DELTA(nentries_mask,
  249. write_index, sw_index - 1) <= 0)) {
  250. ret = -ENOSR;
  251. goto exit;
  252. }
  253. desc = CE_SRC_RING_TO_DESC(src_ring->base_addr_owner_space,
  254. write_index);
  255. desc_flags |= SM(transfer_id, CE_DESC_FLAGS_META_DATA);
  256. if (flags & CE_SEND_FLAG_GATHER)
  257. desc_flags |= CE_DESC_FLAGS_GATHER;
  258. if (flags & CE_SEND_FLAG_BYTE_SWAP)
  259. desc_flags |= CE_DESC_FLAGS_BYTE_SWAP;
  260. sdesc.addr = __cpu_to_le32(buffer);
  261. sdesc.nbytes = __cpu_to_le16(nbytes);
  262. sdesc.flags = __cpu_to_le16(desc_flags);
  263. *desc = sdesc;
  264. src_ring->per_transfer_context[write_index] = per_transfer_context;
  265. /* Update Source Ring Write Index */
  266. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  267. /* WORKAROUND */
  268. if (!(flags & CE_SEND_FLAG_GATHER))
  269. ath10k_ce_src_ring_write_index_set(ar, ctrl_addr, write_index);
  270. src_ring->write_index = write_index;
  271. exit:
  272. return ret;
  273. }
  274. void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe)
  275. {
  276. struct ath10k *ar = pipe->ar;
  277. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  278. struct ath10k_ce_ring *src_ring = pipe->src_ring;
  279. u32 ctrl_addr = pipe->ctrl_addr;
  280. lockdep_assert_held(&ar_pci->ce_lock);
  281. /*
  282. * This function must be called only if there is an incomplete
  283. * scatter-gather transfer (before index register is updated)
  284. * that needs to be cleaned up.
  285. */
  286. if (WARN_ON_ONCE(src_ring->write_index == src_ring->sw_index))
  287. return;
  288. if (WARN_ON_ONCE(src_ring->write_index ==
  289. ath10k_ce_src_ring_write_index_get(ar, ctrl_addr)))
  290. return;
  291. src_ring->write_index--;
  292. src_ring->write_index &= src_ring->nentries_mask;
  293. src_ring->per_transfer_context[src_ring->write_index] = NULL;
  294. }
  295. int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
  296. void *per_transfer_context,
  297. u32 buffer,
  298. unsigned int nbytes,
  299. unsigned int transfer_id,
  300. unsigned int flags)
  301. {
  302. struct ath10k *ar = ce_state->ar;
  303. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  304. int ret;
  305. spin_lock_bh(&ar_pci->ce_lock);
  306. ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
  307. buffer, nbytes, transfer_id, flags);
  308. spin_unlock_bh(&ar_pci->ce_lock);
  309. return ret;
  310. }
  311. int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe)
  312. {
  313. struct ath10k *ar = pipe->ar;
  314. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  315. int delta;
  316. spin_lock_bh(&ar_pci->ce_lock);
  317. delta = CE_RING_DELTA(pipe->src_ring->nentries_mask,
  318. pipe->src_ring->write_index,
  319. pipe->src_ring->sw_index - 1);
  320. spin_unlock_bh(&ar_pci->ce_lock);
  321. return delta;
  322. }
  323. int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe)
  324. {
  325. struct ath10k *ar = pipe->ar;
  326. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  327. struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
  328. unsigned int nentries_mask = dest_ring->nentries_mask;
  329. unsigned int write_index = dest_ring->write_index;
  330. unsigned int sw_index = dest_ring->sw_index;
  331. lockdep_assert_held(&ar_pci->ce_lock);
  332. return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
  333. }
  334. int __ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx, u32 paddr)
  335. {
  336. struct ath10k *ar = pipe->ar;
  337. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  338. struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
  339. unsigned int nentries_mask = dest_ring->nentries_mask;
  340. unsigned int write_index = dest_ring->write_index;
  341. unsigned int sw_index = dest_ring->sw_index;
  342. struct ce_desc *base = dest_ring->base_addr_owner_space;
  343. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, write_index);
  344. u32 ctrl_addr = pipe->ctrl_addr;
  345. lockdep_assert_held(&ar_pci->ce_lock);
  346. if ((pipe->id != 5) &&
  347. CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) == 0)
  348. return -ENOSPC;
  349. desc->addr = __cpu_to_le32(paddr);
  350. desc->nbytes = 0;
  351. dest_ring->per_transfer_context[write_index] = ctx;
  352. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  353. ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
  354. dest_ring->write_index = write_index;
  355. return 0;
  356. }
  357. void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries)
  358. {
  359. struct ath10k *ar = pipe->ar;
  360. struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
  361. unsigned int nentries_mask = dest_ring->nentries_mask;
  362. unsigned int write_index = dest_ring->write_index;
  363. u32 ctrl_addr = pipe->ctrl_addr;
  364. write_index = CE_RING_IDX_ADD(nentries_mask, write_index, nentries);
  365. ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
  366. dest_ring->write_index = write_index;
  367. }
  368. int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx, u32 paddr)
  369. {
  370. struct ath10k *ar = pipe->ar;
  371. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  372. int ret;
  373. spin_lock_bh(&ar_pci->ce_lock);
  374. ret = __ath10k_ce_rx_post_buf(pipe, ctx, paddr);
  375. spin_unlock_bh(&ar_pci->ce_lock);
  376. return ret;
  377. }
  378. /*
  379. * Guts of ath10k_ce_completed_recv_next.
  380. * The caller takes responsibility for any necessary locking.
  381. */
  382. int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
  383. void **per_transfer_contextp,
  384. unsigned int *nbytesp)
  385. {
  386. struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
  387. unsigned int nentries_mask = dest_ring->nentries_mask;
  388. unsigned int sw_index = dest_ring->sw_index;
  389. struct ce_desc *base = dest_ring->base_addr_owner_space;
  390. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  391. struct ce_desc sdesc;
  392. u16 nbytes;
  393. /* Copy in one go for performance reasons */
  394. sdesc = *desc;
  395. nbytes = __le16_to_cpu(sdesc.nbytes);
  396. if (nbytes == 0) {
  397. /*
  398. * This closes a relatively unusual race where the Host
  399. * sees the updated DRRI before the update to the
  400. * corresponding descriptor has completed. We treat this
  401. * as a descriptor that is not yet done.
  402. */
  403. return -EIO;
  404. }
  405. desc->nbytes = 0;
  406. /* Return data from completed destination descriptor */
  407. *nbytesp = nbytes;
  408. if (per_transfer_contextp)
  409. *per_transfer_contextp =
  410. dest_ring->per_transfer_context[sw_index];
  411. /* Copy engine 5 (HTT Rx) will reuse the same transfer context.
  412. * So update transfer context all CEs except CE5.
  413. */
  414. if (ce_state->id != 5)
  415. dest_ring->per_transfer_context[sw_index] = NULL;
  416. /* Update sw_index */
  417. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  418. dest_ring->sw_index = sw_index;
  419. return 0;
  420. }
  421. int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
  422. void **per_transfer_contextp,
  423. unsigned int *nbytesp)
  424. {
  425. struct ath10k *ar = ce_state->ar;
  426. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  427. int ret;
  428. spin_lock_bh(&ar_pci->ce_lock);
  429. ret = ath10k_ce_completed_recv_next_nolock(ce_state,
  430. per_transfer_contextp,
  431. nbytesp);
  432. spin_unlock_bh(&ar_pci->ce_lock);
  433. return ret;
  434. }
  435. int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  436. void **per_transfer_contextp,
  437. u32 *bufferp)
  438. {
  439. struct ath10k_ce_ring *dest_ring;
  440. unsigned int nentries_mask;
  441. unsigned int sw_index;
  442. unsigned int write_index;
  443. int ret;
  444. struct ath10k *ar;
  445. struct ath10k_pci *ar_pci;
  446. dest_ring = ce_state->dest_ring;
  447. if (!dest_ring)
  448. return -EIO;
  449. ar = ce_state->ar;
  450. ar_pci = ath10k_pci_priv(ar);
  451. spin_lock_bh(&ar_pci->ce_lock);
  452. nentries_mask = dest_ring->nentries_mask;
  453. sw_index = dest_ring->sw_index;
  454. write_index = dest_ring->write_index;
  455. if (write_index != sw_index) {
  456. struct ce_desc *base = dest_ring->base_addr_owner_space;
  457. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  458. /* Return data from completed destination descriptor */
  459. *bufferp = __le32_to_cpu(desc->addr);
  460. if (per_transfer_contextp)
  461. *per_transfer_contextp =
  462. dest_ring->per_transfer_context[sw_index];
  463. /* sanity */
  464. dest_ring->per_transfer_context[sw_index] = NULL;
  465. desc->nbytes = 0;
  466. /* Update sw_index */
  467. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  468. dest_ring->sw_index = sw_index;
  469. ret = 0;
  470. } else {
  471. ret = -EIO;
  472. }
  473. spin_unlock_bh(&ar_pci->ce_lock);
  474. return ret;
  475. }
  476. /*
  477. * Guts of ath10k_ce_completed_send_next.
  478. * The caller takes responsibility for any necessary locking.
  479. */
  480. int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
  481. void **per_transfer_contextp)
  482. {
  483. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  484. u32 ctrl_addr = ce_state->ctrl_addr;
  485. struct ath10k *ar = ce_state->ar;
  486. unsigned int nentries_mask = src_ring->nentries_mask;
  487. unsigned int sw_index = src_ring->sw_index;
  488. unsigned int read_index;
  489. if (src_ring->hw_index == sw_index) {
  490. /*
  491. * The SW completion index has caught up with the cached
  492. * version of the HW completion index.
  493. * Update the cached HW completion index to see whether
  494. * the SW has really caught up to the HW, or if the cached
  495. * value of the HW index has become stale.
  496. */
  497. read_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  498. if (read_index == 0xffffffff)
  499. return -ENODEV;
  500. read_index &= nentries_mask;
  501. src_ring->hw_index = read_index;
  502. }
  503. read_index = src_ring->hw_index;
  504. if (read_index == sw_index)
  505. return -EIO;
  506. if (per_transfer_contextp)
  507. *per_transfer_contextp =
  508. src_ring->per_transfer_context[sw_index];
  509. /* sanity */
  510. src_ring->per_transfer_context[sw_index] = NULL;
  511. /* Update sw_index */
  512. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  513. src_ring->sw_index = sw_index;
  514. return 0;
  515. }
  516. /* NB: Modeled after ath10k_ce_completed_send_next */
  517. int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
  518. void **per_transfer_contextp,
  519. u32 *bufferp,
  520. unsigned int *nbytesp,
  521. unsigned int *transfer_idp)
  522. {
  523. struct ath10k_ce_ring *src_ring;
  524. unsigned int nentries_mask;
  525. unsigned int sw_index;
  526. unsigned int write_index;
  527. int ret;
  528. struct ath10k *ar;
  529. struct ath10k_pci *ar_pci;
  530. src_ring = ce_state->src_ring;
  531. if (!src_ring)
  532. return -EIO;
  533. ar = ce_state->ar;
  534. ar_pci = ath10k_pci_priv(ar);
  535. spin_lock_bh(&ar_pci->ce_lock);
  536. nentries_mask = src_ring->nentries_mask;
  537. sw_index = src_ring->sw_index;
  538. write_index = src_ring->write_index;
  539. if (write_index != sw_index) {
  540. struct ce_desc *base = src_ring->base_addr_owner_space;
  541. struct ce_desc *desc = CE_SRC_RING_TO_DESC(base, sw_index);
  542. /* Return data from completed source descriptor */
  543. *bufferp = __le32_to_cpu(desc->addr);
  544. *nbytesp = __le16_to_cpu(desc->nbytes);
  545. *transfer_idp = MS(__le16_to_cpu(desc->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. } else {
  557. ret = -EIO;
  558. }
  559. spin_unlock_bh(&ar_pci->ce_lock);
  560. return ret;
  561. }
  562. int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
  563. void **per_transfer_contextp)
  564. {
  565. struct ath10k *ar = ce_state->ar;
  566. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  567. int ret;
  568. spin_lock_bh(&ar_pci->ce_lock);
  569. ret = ath10k_ce_completed_send_next_nolock(ce_state,
  570. per_transfer_contextp);
  571. spin_unlock_bh(&ar_pci->ce_lock);
  572. return ret;
  573. }
  574. /*
  575. * Guts of interrupt handler for per-engine interrupts on a particular CE.
  576. *
  577. * Invokes registered callbacks for recv_complete,
  578. * send_complete, and watermarks.
  579. */
  580. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id)
  581. {
  582. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  583. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  584. u32 ctrl_addr = ce_state->ctrl_addr;
  585. spin_lock_bh(&ar_pci->ce_lock);
  586. /* Clear the copy-complete interrupts that will be handled here. */
  587. ath10k_ce_engine_int_status_clear(ar, ctrl_addr,
  588. HOST_IS_COPY_COMPLETE_MASK);
  589. spin_unlock_bh(&ar_pci->ce_lock);
  590. if (ce_state->recv_cb)
  591. ce_state->recv_cb(ce_state);
  592. if (ce_state->send_cb)
  593. ce_state->send_cb(ce_state);
  594. spin_lock_bh(&ar_pci->ce_lock);
  595. /*
  596. * Misc CE interrupts are not being handled, but still need
  597. * to be cleared.
  598. */
  599. ath10k_ce_engine_int_status_clear(ar, ctrl_addr, CE_WATERMARK_MASK);
  600. spin_unlock_bh(&ar_pci->ce_lock);
  601. }
  602. /*
  603. * Handler for per-engine interrupts on ALL active CEs.
  604. * This is used in cases where the system is sharing a
  605. * single interrput for all CEs
  606. */
  607. void ath10k_ce_per_engine_service_any(struct ath10k *ar)
  608. {
  609. int ce_id;
  610. u32 intr_summary;
  611. intr_summary = CE_INTERRUPT_SUMMARY(ar);
  612. for (ce_id = 0; intr_summary && (ce_id < CE_COUNT); ce_id++) {
  613. if (intr_summary & (1 << ce_id))
  614. intr_summary &= ~(1 << ce_id);
  615. else
  616. /* no intr pending on this CE */
  617. continue;
  618. ath10k_ce_per_engine_service(ar, ce_id);
  619. }
  620. }
  621. /*
  622. * Adjust interrupts for the copy complete handler.
  623. * If it's needed for either send or recv, then unmask
  624. * this interrupt; otherwise, mask it.
  625. *
  626. * Called with ce_lock held.
  627. */
  628. static void ath10k_ce_per_engine_handler_adjust(struct ath10k_ce_pipe *ce_state)
  629. {
  630. u32 ctrl_addr = ce_state->ctrl_addr;
  631. struct ath10k *ar = ce_state->ar;
  632. bool disable_copy_compl_intr = ce_state->attr_flags & CE_ATTR_DIS_INTR;
  633. if ((!disable_copy_compl_intr) &&
  634. (ce_state->send_cb || ce_state->recv_cb))
  635. ath10k_ce_copy_complete_inter_enable(ar, ctrl_addr);
  636. else
  637. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  638. ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
  639. }
  640. int ath10k_ce_disable_interrupts(struct ath10k *ar)
  641. {
  642. int ce_id;
  643. for (ce_id = 0; ce_id < CE_COUNT; ce_id++) {
  644. u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  645. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  646. ath10k_ce_error_intr_disable(ar, ctrl_addr);
  647. ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
  648. }
  649. return 0;
  650. }
  651. void ath10k_ce_enable_interrupts(struct ath10k *ar)
  652. {
  653. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  654. int ce_id;
  655. /* Skip the last copy engine, CE7 the diagnostic window, as that
  656. * uses polling and isn't initialized for interrupts.
  657. */
  658. for (ce_id = 0; ce_id < CE_COUNT - 1; ce_id++)
  659. ath10k_ce_per_engine_handler_adjust(&ar_pci->ce_states[ce_id]);
  660. }
  661. static int ath10k_ce_init_src_ring(struct ath10k *ar,
  662. unsigned int ce_id,
  663. const struct ce_attr *attr)
  664. {
  665. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  666. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  667. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  668. u32 nentries, ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  669. nentries = roundup_pow_of_two(attr->src_nentries);
  670. memset(src_ring->base_addr_owner_space, 0,
  671. nentries * sizeof(struct ce_desc));
  672. src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  673. src_ring->sw_index &= src_ring->nentries_mask;
  674. src_ring->hw_index = src_ring->sw_index;
  675. src_ring->write_index =
  676. ath10k_ce_src_ring_write_index_get(ar, ctrl_addr);
  677. src_ring->write_index &= src_ring->nentries_mask;
  678. ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr,
  679. src_ring->base_addr_ce_space);
  680. ath10k_ce_src_ring_size_set(ar, ctrl_addr, nentries);
  681. ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, attr->src_sz_max);
  682. ath10k_ce_src_ring_byte_swap_set(ar, ctrl_addr, 0);
  683. ath10k_ce_src_ring_lowmark_set(ar, ctrl_addr, 0);
  684. ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, nentries);
  685. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  686. "boot init ce src ring id %d entries %d base_addr %p\n",
  687. ce_id, nentries, src_ring->base_addr_owner_space);
  688. return 0;
  689. }
  690. static int ath10k_ce_init_dest_ring(struct ath10k *ar,
  691. unsigned int ce_id,
  692. const struct ce_attr *attr)
  693. {
  694. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  695. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  696. struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
  697. u32 nentries, ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  698. nentries = roundup_pow_of_two(attr->dest_nentries);
  699. memset(dest_ring->base_addr_owner_space, 0,
  700. nentries * sizeof(struct ce_desc));
  701. dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr);
  702. dest_ring->sw_index &= dest_ring->nentries_mask;
  703. dest_ring->write_index =
  704. ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
  705. dest_ring->write_index &= dest_ring->nentries_mask;
  706. ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr,
  707. dest_ring->base_addr_ce_space);
  708. ath10k_ce_dest_ring_size_set(ar, ctrl_addr, nentries);
  709. ath10k_ce_dest_ring_byte_swap_set(ar, ctrl_addr, 0);
  710. ath10k_ce_dest_ring_lowmark_set(ar, ctrl_addr, 0);
  711. ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, nentries);
  712. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  713. "boot ce dest ring id %d entries %d base_addr %p\n",
  714. ce_id, nentries, dest_ring->base_addr_owner_space);
  715. return 0;
  716. }
  717. static struct ath10k_ce_ring *
  718. ath10k_ce_alloc_src_ring(struct ath10k *ar, unsigned int ce_id,
  719. const struct ce_attr *attr)
  720. {
  721. struct ath10k_ce_ring *src_ring;
  722. u32 nentries = attr->src_nentries;
  723. dma_addr_t base_addr;
  724. nentries = roundup_pow_of_two(nentries);
  725. src_ring = kzalloc(sizeof(*src_ring) +
  726. (nentries *
  727. sizeof(*src_ring->per_transfer_context)),
  728. GFP_KERNEL);
  729. if (src_ring == NULL)
  730. return ERR_PTR(-ENOMEM);
  731. src_ring->nentries = nentries;
  732. src_ring->nentries_mask = nentries - 1;
  733. /*
  734. * Legacy platforms that do not support cache
  735. * coherent DMA are unsupported
  736. */
  737. src_ring->base_addr_owner_space_unaligned =
  738. dma_alloc_coherent(ar->dev,
  739. (nentries * sizeof(struct ce_desc) +
  740. CE_DESC_RING_ALIGN),
  741. &base_addr, GFP_KERNEL);
  742. if (!src_ring->base_addr_owner_space_unaligned) {
  743. kfree(src_ring);
  744. return ERR_PTR(-ENOMEM);
  745. }
  746. src_ring->base_addr_ce_space_unaligned = base_addr;
  747. src_ring->base_addr_owner_space = PTR_ALIGN(
  748. src_ring->base_addr_owner_space_unaligned,
  749. CE_DESC_RING_ALIGN);
  750. src_ring->base_addr_ce_space = ALIGN(
  751. src_ring->base_addr_ce_space_unaligned,
  752. CE_DESC_RING_ALIGN);
  753. return src_ring;
  754. }
  755. static struct ath10k_ce_ring *
  756. ath10k_ce_alloc_dest_ring(struct ath10k *ar, unsigned int ce_id,
  757. const struct ce_attr *attr)
  758. {
  759. struct ath10k_ce_ring *dest_ring;
  760. u32 nentries;
  761. dma_addr_t base_addr;
  762. nentries = roundup_pow_of_two(attr->dest_nentries);
  763. dest_ring = kzalloc(sizeof(*dest_ring) +
  764. (nentries *
  765. sizeof(*dest_ring->per_transfer_context)),
  766. GFP_KERNEL);
  767. if (dest_ring == NULL)
  768. return ERR_PTR(-ENOMEM);
  769. dest_ring->nentries = nentries;
  770. dest_ring->nentries_mask = nentries - 1;
  771. /*
  772. * Legacy platforms that do not support cache
  773. * coherent DMA are unsupported
  774. */
  775. dest_ring->base_addr_owner_space_unaligned =
  776. dma_alloc_coherent(ar->dev,
  777. (nentries * sizeof(struct ce_desc) +
  778. CE_DESC_RING_ALIGN),
  779. &base_addr, GFP_KERNEL);
  780. if (!dest_ring->base_addr_owner_space_unaligned) {
  781. kfree(dest_ring);
  782. return ERR_PTR(-ENOMEM);
  783. }
  784. dest_ring->base_addr_ce_space_unaligned = base_addr;
  785. /*
  786. * Correctly initialize memory to 0 to prevent garbage
  787. * data crashing system when download firmware
  788. */
  789. memset(dest_ring->base_addr_owner_space_unaligned, 0,
  790. nentries * sizeof(struct ce_desc) + CE_DESC_RING_ALIGN);
  791. dest_ring->base_addr_owner_space = PTR_ALIGN(
  792. dest_ring->base_addr_owner_space_unaligned,
  793. CE_DESC_RING_ALIGN);
  794. dest_ring->base_addr_ce_space = ALIGN(
  795. dest_ring->base_addr_ce_space_unaligned,
  796. CE_DESC_RING_ALIGN);
  797. return dest_ring;
  798. }
  799. /*
  800. * Initialize a Copy Engine based on caller-supplied attributes.
  801. * This may be called once to initialize both source and destination
  802. * rings or it may be called twice for separate source and destination
  803. * initialization. It may be that only one side or the other is
  804. * initialized by software/firmware.
  805. */
  806. int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
  807. const struct ce_attr *attr)
  808. {
  809. int ret;
  810. if (attr->src_nentries) {
  811. ret = ath10k_ce_init_src_ring(ar, ce_id, attr);
  812. if (ret) {
  813. ath10k_err(ar, "Failed to initialize CE src ring for ID: %d (%d)\n",
  814. ce_id, ret);
  815. return ret;
  816. }
  817. }
  818. if (attr->dest_nentries) {
  819. ret = ath10k_ce_init_dest_ring(ar, ce_id, attr);
  820. if (ret) {
  821. ath10k_err(ar, "Failed to initialize CE dest ring for ID: %d (%d)\n",
  822. ce_id, ret);
  823. return ret;
  824. }
  825. }
  826. return 0;
  827. }
  828. static void ath10k_ce_deinit_src_ring(struct ath10k *ar, unsigned int ce_id)
  829. {
  830. u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  831. ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr, 0);
  832. ath10k_ce_src_ring_size_set(ar, ctrl_addr, 0);
  833. ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, 0);
  834. ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, 0);
  835. }
  836. static void ath10k_ce_deinit_dest_ring(struct ath10k *ar, unsigned int ce_id)
  837. {
  838. u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  839. ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr, 0);
  840. ath10k_ce_dest_ring_size_set(ar, ctrl_addr, 0);
  841. ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, 0);
  842. }
  843. void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id)
  844. {
  845. ath10k_ce_deinit_src_ring(ar, ce_id);
  846. ath10k_ce_deinit_dest_ring(ar, ce_id);
  847. }
  848. int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
  849. const struct ce_attr *attr)
  850. {
  851. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  852. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  853. int ret;
  854. /*
  855. * Make sure there's enough CE ringbuffer entries for HTT TX to avoid
  856. * additional TX locking checks.
  857. *
  858. * For the lack of a better place do the check here.
  859. */
  860. BUILD_BUG_ON(2 * TARGET_NUM_MSDU_DESC >
  861. (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
  862. BUILD_BUG_ON(2 * TARGET_10X_NUM_MSDU_DESC >
  863. (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
  864. BUILD_BUG_ON(2 * TARGET_TLV_NUM_MSDU_DESC >
  865. (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
  866. ce_state->ar = ar;
  867. ce_state->id = ce_id;
  868. ce_state->ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  869. ce_state->attr_flags = attr->flags;
  870. ce_state->src_sz_max = attr->src_sz_max;
  871. if (attr->src_nentries)
  872. ce_state->send_cb = attr->send_cb;
  873. if (attr->dest_nentries)
  874. ce_state->recv_cb = attr->recv_cb;
  875. if (attr->src_nentries) {
  876. ce_state->src_ring = ath10k_ce_alloc_src_ring(ar, ce_id, attr);
  877. if (IS_ERR(ce_state->src_ring)) {
  878. ret = PTR_ERR(ce_state->src_ring);
  879. ath10k_err(ar, "failed to allocate copy engine source ring %d: %d\n",
  880. ce_id, ret);
  881. ce_state->src_ring = NULL;
  882. return ret;
  883. }
  884. }
  885. if (attr->dest_nentries) {
  886. ce_state->dest_ring = ath10k_ce_alloc_dest_ring(ar, ce_id,
  887. attr);
  888. if (IS_ERR(ce_state->dest_ring)) {
  889. ret = PTR_ERR(ce_state->dest_ring);
  890. ath10k_err(ar, "failed to allocate copy engine destination ring %d: %d\n",
  891. ce_id, ret);
  892. ce_state->dest_ring = NULL;
  893. return ret;
  894. }
  895. }
  896. return 0;
  897. }
  898. void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id)
  899. {
  900. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  901. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  902. if (ce_state->src_ring) {
  903. dma_free_coherent(ar->dev,
  904. (ce_state->src_ring->nentries *
  905. sizeof(struct ce_desc) +
  906. CE_DESC_RING_ALIGN),
  907. ce_state->src_ring->base_addr_owner_space,
  908. ce_state->src_ring->base_addr_ce_space);
  909. kfree(ce_state->src_ring);
  910. }
  911. if (ce_state->dest_ring) {
  912. dma_free_coherent(ar->dev,
  913. (ce_state->dest_ring->nentries *
  914. sizeof(struct ce_desc) +
  915. CE_DESC_RING_ALIGN),
  916. ce_state->dest_ring->base_addr_owner_space,
  917. ce_state->dest_ring->base_addr_ce_space);
  918. kfree(ce_state->dest_ring);
  919. }
  920. ce_state->src_ring = NULL;
  921. ce_state->dest_ring = NULL;
  922. }