ce.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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_engine_int_status_clear(struct ath10k *ar,
  211. u32 ce_ctrl_addr,
  212. unsigned int mask)
  213. {
  214. ath10k_pci_write32(ar, ce_ctrl_addr + HOST_IS_ADDRESS, mask);
  215. }
  216. /*
  217. * Guts of ath10k_ce_send, used by both ath10k_ce_send and
  218. * ath10k_ce_sendlist_send.
  219. * The caller takes responsibility for any needed locking.
  220. */
  221. static int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
  222. void *per_transfer_context,
  223. u32 buffer,
  224. unsigned int nbytes,
  225. unsigned int transfer_id,
  226. unsigned int flags)
  227. {
  228. struct ath10k *ar = ce_state->ar;
  229. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  230. struct ce_desc *desc, *sdesc;
  231. unsigned int nentries_mask = src_ring->nentries_mask;
  232. unsigned int sw_index = src_ring->sw_index;
  233. unsigned int write_index = src_ring->write_index;
  234. u32 ctrl_addr = ce_state->ctrl_addr;
  235. u32 desc_flags = 0;
  236. int ret = 0;
  237. if (nbytes > ce_state->src_sz_max)
  238. ath10k_warn("%s: send more we can (nbytes: %d, max: %d)\n",
  239. __func__, nbytes, ce_state->src_sz_max);
  240. ret = ath10k_pci_wake(ar);
  241. if (ret)
  242. return ret;
  243. if (unlikely(CE_RING_DELTA(nentries_mask,
  244. write_index, sw_index - 1) <= 0)) {
  245. ret = -EIO;
  246. goto exit;
  247. }
  248. desc = CE_SRC_RING_TO_DESC(src_ring->base_addr_owner_space,
  249. write_index);
  250. sdesc = CE_SRC_RING_TO_DESC(src_ring->shadow_base, write_index);
  251. desc_flags |= SM(transfer_id, CE_DESC_FLAGS_META_DATA);
  252. if (flags & CE_SEND_FLAG_GATHER)
  253. desc_flags |= CE_DESC_FLAGS_GATHER;
  254. if (flags & CE_SEND_FLAG_BYTE_SWAP)
  255. desc_flags |= CE_DESC_FLAGS_BYTE_SWAP;
  256. sdesc->addr = __cpu_to_le32(buffer);
  257. sdesc->nbytes = __cpu_to_le16(nbytes);
  258. sdesc->flags = __cpu_to_le16(desc_flags);
  259. *desc = *sdesc;
  260. src_ring->per_transfer_context[write_index] = per_transfer_context;
  261. /* Update Source Ring Write Index */
  262. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  263. /* WORKAROUND */
  264. if (!(flags & CE_SEND_FLAG_GATHER))
  265. ath10k_ce_src_ring_write_index_set(ar, ctrl_addr, write_index);
  266. src_ring->write_index = write_index;
  267. exit:
  268. ath10k_pci_sleep(ar);
  269. return ret;
  270. }
  271. int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
  272. void *per_transfer_context,
  273. u32 buffer,
  274. unsigned int nbytes,
  275. unsigned int transfer_id,
  276. unsigned int flags)
  277. {
  278. struct ath10k *ar = ce_state->ar;
  279. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  280. int ret;
  281. spin_lock_bh(&ar_pci->ce_lock);
  282. ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
  283. buffer, nbytes, transfer_id, flags);
  284. spin_unlock_bh(&ar_pci->ce_lock);
  285. return ret;
  286. }
  287. void ath10k_ce_sendlist_buf_add(struct ce_sendlist *sendlist, u32 buffer,
  288. unsigned int nbytes, u32 flags)
  289. {
  290. unsigned int num_items = sendlist->num_items;
  291. struct ce_sendlist_item *item;
  292. item = &sendlist->item[num_items];
  293. item->data = buffer;
  294. item->u.nbytes = nbytes;
  295. item->flags = flags;
  296. sendlist->num_items++;
  297. }
  298. int ath10k_ce_sendlist_send(struct ath10k_ce_pipe *ce_state,
  299. void *per_transfer_context,
  300. struct ce_sendlist *sendlist,
  301. unsigned int transfer_id)
  302. {
  303. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  304. struct ce_sendlist_item *item;
  305. struct ath10k *ar = ce_state->ar;
  306. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  307. unsigned int nentries_mask = src_ring->nentries_mask;
  308. unsigned int num_items = sendlist->num_items;
  309. unsigned int sw_index;
  310. unsigned int write_index;
  311. int i, delta, ret = -ENOMEM;
  312. spin_lock_bh(&ar_pci->ce_lock);
  313. sw_index = src_ring->sw_index;
  314. write_index = src_ring->write_index;
  315. delta = CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
  316. if (delta >= num_items) {
  317. /*
  318. * Handle all but the last item uniformly.
  319. */
  320. for (i = 0; i < num_items - 1; i++) {
  321. item = &sendlist->item[i];
  322. ret = ath10k_ce_send_nolock(ce_state,
  323. CE_SENDLIST_ITEM_CTXT,
  324. (u32) item->data,
  325. item->u.nbytes, transfer_id,
  326. item->flags |
  327. CE_SEND_FLAG_GATHER);
  328. if (ret)
  329. ath10k_warn("CE send failed for item: %d\n", i);
  330. }
  331. /*
  332. * Provide valid context pointer for final item.
  333. */
  334. item = &sendlist->item[i];
  335. ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
  336. (u32) item->data, item->u.nbytes,
  337. transfer_id, item->flags);
  338. if (ret)
  339. ath10k_warn("CE send failed for last item: %d\n", i);
  340. }
  341. spin_unlock_bh(&ar_pci->ce_lock);
  342. return ret;
  343. }
  344. int ath10k_ce_recv_buf_enqueue(struct ath10k_ce_pipe *ce_state,
  345. void *per_recv_context,
  346. u32 buffer)
  347. {
  348. struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
  349. u32 ctrl_addr = ce_state->ctrl_addr;
  350. struct ath10k *ar = ce_state->ar;
  351. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  352. unsigned int nentries_mask = dest_ring->nentries_mask;
  353. unsigned int write_index;
  354. unsigned int sw_index;
  355. int ret;
  356. spin_lock_bh(&ar_pci->ce_lock);
  357. write_index = dest_ring->write_index;
  358. sw_index = dest_ring->sw_index;
  359. ret = ath10k_pci_wake(ar);
  360. if (ret)
  361. goto out;
  362. if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) > 0) {
  363. struct ce_desc *base = dest_ring->base_addr_owner_space;
  364. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, write_index);
  365. /* Update destination descriptor */
  366. desc->addr = __cpu_to_le32(buffer);
  367. desc->nbytes = 0;
  368. dest_ring->per_transfer_context[write_index] =
  369. per_recv_context;
  370. /* Update Destination Ring Write Index */
  371. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  372. ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
  373. dest_ring->write_index = write_index;
  374. ret = 0;
  375. } else {
  376. ret = -EIO;
  377. }
  378. ath10k_pci_sleep(ar);
  379. out:
  380. spin_unlock_bh(&ar_pci->ce_lock);
  381. return ret;
  382. }
  383. /*
  384. * Guts of ath10k_ce_completed_recv_next.
  385. * The caller takes responsibility for any necessary locking.
  386. */
  387. static int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
  388. void **per_transfer_contextp,
  389. u32 *bufferp,
  390. unsigned int *nbytesp,
  391. unsigned int *transfer_idp,
  392. unsigned int *flagsp)
  393. {
  394. struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
  395. unsigned int nentries_mask = dest_ring->nentries_mask;
  396. unsigned int sw_index = dest_ring->sw_index;
  397. struct ce_desc *base = dest_ring->base_addr_owner_space;
  398. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  399. struct ce_desc sdesc;
  400. u16 nbytes;
  401. /* Copy in one go for performance reasons */
  402. sdesc = *desc;
  403. nbytes = __le16_to_cpu(sdesc.nbytes);
  404. if (nbytes == 0) {
  405. /*
  406. * This closes a relatively unusual race where the Host
  407. * sees the updated DRRI before the update to the
  408. * corresponding descriptor has completed. We treat this
  409. * as a descriptor that is not yet done.
  410. */
  411. return -EIO;
  412. }
  413. desc->nbytes = 0;
  414. /* Return data from completed destination descriptor */
  415. *bufferp = __le32_to_cpu(sdesc.addr);
  416. *nbytesp = nbytes;
  417. *transfer_idp = MS(__le16_to_cpu(sdesc.flags), CE_DESC_FLAGS_META_DATA);
  418. if (__le16_to_cpu(sdesc.flags) & CE_DESC_FLAGS_BYTE_SWAP)
  419. *flagsp = CE_RECV_FLAG_SWAPPED;
  420. else
  421. *flagsp = 0;
  422. if (per_transfer_contextp)
  423. *per_transfer_contextp =
  424. dest_ring->per_transfer_context[sw_index];
  425. /* sanity */
  426. dest_ring->per_transfer_context[sw_index] = NULL;
  427. /* Update sw_index */
  428. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  429. dest_ring->sw_index = sw_index;
  430. return 0;
  431. }
  432. int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
  433. void **per_transfer_contextp,
  434. u32 *bufferp,
  435. unsigned int *nbytesp,
  436. unsigned int *transfer_idp,
  437. unsigned int *flagsp)
  438. {
  439. struct ath10k *ar = ce_state->ar;
  440. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  441. int ret;
  442. spin_lock_bh(&ar_pci->ce_lock);
  443. ret = ath10k_ce_completed_recv_next_nolock(ce_state,
  444. per_transfer_contextp,
  445. bufferp, nbytesp,
  446. transfer_idp, flagsp);
  447. spin_unlock_bh(&ar_pci->ce_lock);
  448. return ret;
  449. }
  450. int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  451. void **per_transfer_contextp,
  452. u32 *bufferp)
  453. {
  454. struct ath10k_ce_ring *dest_ring;
  455. unsigned int nentries_mask;
  456. unsigned int sw_index;
  457. unsigned int write_index;
  458. int ret;
  459. struct ath10k *ar;
  460. struct ath10k_pci *ar_pci;
  461. dest_ring = ce_state->dest_ring;
  462. if (!dest_ring)
  463. return -EIO;
  464. ar = ce_state->ar;
  465. ar_pci = ath10k_pci_priv(ar);
  466. spin_lock_bh(&ar_pci->ce_lock);
  467. nentries_mask = dest_ring->nentries_mask;
  468. sw_index = dest_ring->sw_index;
  469. write_index = dest_ring->write_index;
  470. if (write_index != sw_index) {
  471. struct ce_desc *base = dest_ring->base_addr_owner_space;
  472. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  473. /* Return data from completed destination descriptor */
  474. *bufferp = __le32_to_cpu(desc->addr);
  475. if (per_transfer_contextp)
  476. *per_transfer_contextp =
  477. dest_ring->per_transfer_context[sw_index];
  478. /* sanity */
  479. dest_ring->per_transfer_context[sw_index] = NULL;
  480. /* Update sw_index */
  481. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  482. dest_ring->sw_index = sw_index;
  483. ret = 0;
  484. } else {
  485. ret = -EIO;
  486. }
  487. spin_unlock_bh(&ar_pci->ce_lock);
  488. return ret;
  489. }
  490. /*
  491. * Guts of ath10k_ce_completed_send_next.
  492. * The caller takes responsibility for any necessary locking.
  493. */
  494. static int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
  495. void **per_transfer_contextp,
  496. u32 *bufferp,
  497. unsigned int *nbytesp,
  498. unsigned int *transfer_idp)
  499. {
  500. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  501. u32 ctrl_addr = ce_state->ctrl_addr;
  502. struct ath10k *ar = ce_state->ar;
  503. unsigned int nentries_mask = src_ring->nentries_mask;
  504. unsigned int sw_index = src_ring->sw_index;
  505. struct ce_desc *sdesc, *sbase;
  506. unsigned int read_index;
  507. int ret;
  508. if (src_ring->hw_index == sw_index) {
  509. /*
  510. * The SW completion index has caught up with the cached
  511. * version of the HW completion index.
  512. * Update the cached HW completion index to see whether
  513. * the SW has really caught up to the HW, or if the cached
  514. * value of the HW index has become stale.
  515. */
  516. ret = ath10k_pci_wake(ar);
  517. if (ret)
  518. return ret;
  519. src_ring->hw_index =
  520. ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  521. src_ring->hw_index &= nentries_mask;
  522. ath10k_pci_sleep(ar);
  523. }
  524. read_index = src_ring->hw_index;
  525. if ((read_index == sw_index) || (read_index == 0xffffffff))
  526. return -EIO;
  527. sbase = src_ring->shadow_base;
  528. sdesc = CE_SRC_RING_TO_DESC(sbase, sw_index);
  529. /* Return data from completed source descriptor */
  530. *bufferp = __le32_to_cpu(sdesc->addr);
  531. *nbytesp = __le16_to_cpu(sdesc->nbytes);
  532. *transfer_idp = MS(__le16_to_cpu(sdesc->flags),
  533. CE_DESC_FLAGS_META_DATA);
  534. if (per_transfer_contextp)
  535. *per_transfer_contextp =
  536. src_ring->per_transfer_context[sw_index];
  537. /* sanity */
  538. src_ring->per_transfer_context[sw_index] = NULL;
  539. /* Update sw_index */
  540. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  541. src_ring->sw_index = sw_index;
  542. return 0;
  543. }
  544. /* NB: Modeled after ath10k_ce_completed_send_next */
  545. int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
  546. void **per_transfer_contextp,
  547. u32 *bufferp,
  548. unsigned int *nbytesp,
  549. unsigned int *transfer_idp)
  550. {
  551. struct ath10k_ce_ring *src_ring;
  552. unsigned int nentries_mask;
  553. unsigned int sw_index;
  554. unsigned int write_index;
  555. int ret;
  556. struct ath10k *ar;
  557. struct ath10k_pci *ar_pci;
  558. src_ring = ce_state->src_ring;
  559. if (!src_ring)
  560. return -EIO;
  561. ar = ce_state->ar;
  562. ar_pci = ath10k_pci_priv(ar);
  563. spin_lock_bh(&ar_pci->ce_lock);
  564. nentries_mask = src_ring->nentries_mask;
  565. sw_index = src_ring->sw_index;
  566. write_index = src_ring->write_index;
  567. if (write_index != sw_index) {
  568. struct ce_desc *base = src_ring->base_addr_owner_space;
  569. struct ce_desc *desc = CE_SRC_RING_TO_DESC(base, sw_index);
  570. /* Return data from completed source descriptor */
  571. *bufferp = __le32_to_cpu(desc->addr);
  572. *nbytesp = __le16_to_cpu(desc->nbytes);
  573. *transfer_idp = MS(__le16_to_cpu(desc->flags),
  574. CE_DESC_FLAGS_META_DATA);
  575. if (per_transfer_contextp)
  576. *per_transfer_contextp =
  577. src_ring->per_transfer_context[sw_index];
  578. /* sanity */
  579. src_ring->per_transfer_context[sw_index] = NULL;
  580. /* Update sw_index */
  581. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  582. src_ring->sw_index = sw_index;
  583. ret = 0;
  584. } else {
  585. ret = -EIO;
  586. }
  587. spin_unlock_bh(&ar_pci->ce_lock);
  588. return ret;
  589. }
  590. int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
  591. void **per_transfer_contextp,
  592. u32 *bufferp,
  593. unsigned int *nbytesp,
  594. unsigned int *transfer_idp)
  595. {
  596. struct ath10k *ar = ce_state->ar;
  597. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  598. int ret;
  599. spin_lock_bh(&ar_pci->ce_lock);
  600. ret = ath10k_ce_completed_send_next_nolock(ce_state,
  601. per_transfer_contextp,
  602. bufferp, nbytesp,
  603. transfer_idp);
  604. spin_unlock_bh(&ar_pci->ce_lock);
  605. return ret;
  606. }
  607. /*
  608. * Guts of interrupt handler for per-engine interrupts on a particular CE.
  609. *
  610. * Invokes registered callbacks for recv_complete,
  611. * send_complete, and watermarks.
  612. */
  613. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id)
  614. {
  615. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  616. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  617. u32 ctrl_addr = ce_state->ctrl_addr;
  618. int ret;
  619. ret = ath10k_pci_wake(ar);
  620. if (ret)
  621. return;
  622. spin_lock_bh(&ar_pci->ce_lock);
  623. /* Clear the copy-complete interrupts that will be handled here. */
  624. ath10k_ce_engine_int_status_clear(ar, ctrl_addr,
  625. HOST_IS_COPY_COMPLETE_MASK);
  626. spin_unlock_bh(&ar_pci->ce_lock);
  627. if (ce_state->recv_cb)
  628. ce_state->recv_cb(ce_state);
  629. if (ce_state->send_cb)
  630. ce_state->send_cb(ce_state);
  631. spin_lock_bh(&ar_pci->ce_lock);
  632. /*
  633. * Misc CE interrupts are not being handled, but still need
  634. * to be cleared.
  635. */
  636. ath10k_ce_engine_int_status_clear(ar, ctrl_addr, CE_WATERMARK_MASK);
  637. spin_unlock_bh(&ar_pci->ce_lock);
  638. ath10k_pci_sleep(ar);
  639. }
  640. /*
  641. * Handler for per-engine interrupts on ALL active CEs.
  642. * This is used in cases where the system is sharing a
  643. * single interrput for all CEs
  644. */
  645. void ath10k_ce_per_engine_service_any(struct ath10k *ar)
  646. {
  647. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  648. int ce_id, ret;
  649. u32 intr_summary;
  650. ret = ath10k_pci_wake(ar);
  651. if (ret)
  652. return;
  653. intr_summary = CE_INTERRUPT_SUMMARY(ar);
  654. for (ce_id = 0; intr_summary && (ce_id < ar_pci->ce_count); ce_id++) {
  655. if (intr_summary & (1 << ce_id))
  656. intr_summary &= ~(1 << ce_id);
  657. else
  658. /* no intr pending on this CE */
  659. continue;
  660. ath10k_ce_per_engine_service(ar, ce_id);
  661. }
  662. ath10k_pci_sleep(ar);
  663. }
  664. /*
  665. * Adjust interrupts for the copy complete handler.
  666. * If it's needed for either send or recv, then unmask
  667. * this interrupt; otherwise, mask it.
  668. *
  669. * Called with ce_lock held.
  670. */
  671. static void ath10k_ce_per_engine_handler_adjust(struct ath10k_ce_pipe *ce_state,
  672. int disable_copy_compl_intr)
  673. {
  674. u32 ctrl_addr = ce_state->ctrl_addr;
  675. struct ath10k *ar = ce_state->ar;
  676. int ret;
  677. ret = ath10k_pci_wake(ar);
  678. if (ret)
  679. return;
  680. if ((!disable_copy_compl_intr) &&
  681. (ce_state->send_cb || ce_state->recv_cb))
  682. ath10k_ce_copy_complete_inter_enable(ar, ctrl_addr);
  683. else
  684. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  685. ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
  686. ath10k_pci_sleep(ar);
  687. }
  688. void ath10k_ce_disable_interrupts(struct ath10k *ar)
  689. {
  690. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  691. int ce_id, ret;
  692. ret = ath10k_pci_wake(ar);
  693. if (ret)
  694. return;
  695. for (ce_id = 0; ce_id < ar_pci->ce_count; ce_id++) {
  696. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  697. u32 ctrl_addr = ce_state->ctrl_addr;
  698. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  699. }
  700. ath10k_pci_sleep(ar);
  701. }
  702. void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
  703. void (*send_cb)(struct ath10k_ce_pipe *),
  704. int disable_interrupts)
  705. {
  706. struct ath10k *ar = ce_state->ar;
  707. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  708. spin_lock_bh(&ar_pci->ce_lock);
  709. ce_state->send_cb = send_cb;
  710. ath10k_ce_per_engine_handler_adjust(ce_state, disable_interrupts);
  711. spin_unlock_bh(&ar_pci->ce_lock);
  712. }
  713. void ath10k_ce_recv_cb_register(struct ath10k_ce_pipe *ce_state,
  714. void (*recv_cb)(struct ath10k_ce_pipe *))
  715. {
  716. struct ath10k *ar = ce_state->ar;
  717. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  718. spin_lock_bh(&ar_pci->ce_lock);
  719. ce_state->recv_cb = recv_cb;
  720. ath10k_ce_per_engine_handler_adjust(ce_state, 0);
  721. spin_unlock_bh(&ar_pci->ce_lock);
  722. }
  723. static int ath10k_ce_init_src_ring(struct ath10k *ar,
  724. unsigned int ce_id,
  725. struct ath10k_ce_pipe *ce_state,
  726. const struct ce_attr *attr)
  727. {
  728. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  729. struct ath10k_ce_ring *src_ring;
  730. unsigned int nentries = attr->src_nentries;
  731. unsigned int ce_nbytes;
  732. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  733. dma_addr_t base_addr;
  734. char *ptr;
  735. nentries = roundup_pow_of_two(nentries);
  736. if (ce_state->src_ring) {
  737. WARN_ON(ce_state->src_ring->nentries != nentries);
  738. return 0;
  739. }
  740. ce_nbytes = sizeof(struct ath10k_ce_ring) + (nentries * sizeof(void *));
  741. ptr = kzalloc(ce_nbytes, GFP_KERNEL);
  742. if (ptr == NULL)
  743. return -ENOMEM;
  744. ce_state->src_ring = (struct ath10k_ce_ring *)ptr;
  745. src_ring = ce_state->src_ring;
  746. ptr += sizeof(struct ath10k_ce_ring);
  747. src_ring->nentries = nentries;
  748. src_ring->nentries_mask = nentries - 1;
  749. src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  750. src_ring->sw_index &= src_ring->nentries_mask;
  751. src_ring->hw_index = src_ring->sw_index;
  752. src_ring->write_index =
  753. ath10k_ce_src_ring_write_index_get(ar, ctrl_addr);
  754. src_ring->write_index &= src_ring->nentries_mask;
  755. src_ring->per_transfer_context = (void **)ptr;
  756. /*
  757. * Legacy platforms that do not support cache
  758. * coherent DMA are unsupported
  759. */
  760. src_ring->base_addr_owner_space_unaligned =
  761. pci_alloc_consistent(ar_pci->pdev,
  762. (nentries * sizeof(struct ce_desc) +
  763. CE_DESC_RING_ALIGN),
  764. &base_addr);
  765. if (!src_ring->base_addr_owner_space_unaligned) {
  766. kfree(ce_state->src_ring);
  767. ce_state->src_ring = NULL;
  768. return -ENOMEM;
  769. }
  770. src_ring->base_addr_ce_space_unaligned = base_addr;
  771. src_ring->base_addr_owner_space = PTR_ALIGN(
  772. src_ring->base_addr_owner_space_unaligned,
  773. CE_DESC_RING_ALIGN);
  774. src_ring->base_addr_ce_space = ALIGN(
  775. src_ring->base_addr_ce_space_unaligned,
  776. CE_DESC_RING_ALIGN);
  777. /*
  778. * Also allocate a shadow src ring in regular
  779. * mem to use for faster access.
  780. */
  781. src_ring->shadow_base_unaligned =
  782. kmalloc((nentries * sizeof(struct ce_desc) +
  783. CE_DESC_RING_ALIGN), GFP_KERNEL);
  784. if (!src_ring->shadow_base_unaligned) {
  785. pci_free_consistent(ar_pci->pdev,
  786. (nentries * sizeof(struct ce_desc) +
  787. CE_DESC_RING_ALIGN),
  788. src_ring->base_addr_owner_space,
  789. src_ring->base_addr_ce_space);
  790. kfree(ce_state->src_ring);
  791. ce_state->src_ring = NULL;
  792. return -ENOMEM;
  793. }
  794. src_ring->shadow_base = PTR_ALIGN(
  795. src_ring->shadow_base_unaligned,
  796. CE_DESC_RING_ALIGN);
  797. ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr,
  798. src_ring->base_addr_ce_space);
  799. ath10k_ce_src_ring_size_set(ar, ctrl_addr, nentries);
  800. ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, attr->src_sz_max);
  801. ath10k_ce_src_ring_byte_swap_set(ar, ctrl_addr, 0);
  802. ath10k_ce_src_ring_lowmark_set(ar, ctrl_addr, 0);
  803. ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, nentries);
  804. return 0;
  805. }
  806. static int ath10k_ce_init_dest_ring(struct ath10k *ar,
  807. unsigned int ce_id,
  808. struct ath10k_ce_pipe *ce_state,
  809. const struct ce_attr *attr)
  810. {
  811. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  812. struct ath10k_ce_ring *dest_ring;
  813. unsigned int nentries = attr->dest_nentries;
  814. unsigned int ce_nbytes;
  815. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  816. dma_addr_t base_addr;
  817. char *ptr;
  818. nentries = roundup_pow_of_two(nentries);
  819. if (ce_state->dest_ring) {
  820. WARN_ON(ce_state->dest_ring->nentries != nentries);
  821. return 0;
  822. }
  823. ce_nbytes = sizeof(struct ath10k_ce_ring) + (nentries * sizeof(void *));
  824. ptr = kzalloc(ce_nbytes, GFP_KERNEL);
  825. if (ptr == NULL)
  826. return -ENOMEM;
  827. ce_state->dest_ring = (struct ath10k_ce_ring *)ptr;
  828. dest_ring = ce_state->dest_ring;
  829. ptr += sizeof(struct ath10k_ce_ring);
  830. dest_ring->nentries = nentries;
  831. dest_ring->nentries_mask = nentries - 1;
  832. dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr);
  833. dest_ring->sw_index &= dest_ring->nentries_mask;
  834. dest_ring->write_index =
  835. ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
  836. dest_ring->write_index &= dest_ring->nentries_mask;
  837. dest_ring->per_transfer_context = (void **)ptr;
  838. /*
  839. * Legacy platforms that do not support cache
  840. * coherent DMA are unsupported
  841. */
  842. dest_ring->base_addr_owner_space_unaligned =
  843. pci_alloc_consistent(ar_pci->pdev,
  844. (nentries * sizeof(struct ce_desc) +
  845. CE_DESC_RING_ALIGN),
  846. &base_addr);
  847. if (!dest_ring->base_addr_owner_space_unaligned) {
  848. kfree(ce_state->dest_ring);
  849. ce_state->dest_ring = NULL;
  850. return -ENOMEM;
  851. }
  852. dest_ring->base_addr_ce_space_unaligned = base_addr;
  853. /*
  854. * Correctly initialize memory to 0 to prevent garbage
  855. * data crashing system when download firmware
  856. */
  857. memset(dest_ring->base_addr_owner_space_unaligned, 0,
  858. nentries * sizeof(struct ce_desc) + CE_DESC_RING_ALIGN);
  859. dest_ring->base_addr_owner_space = PTR_ALIGN(
  860. dest_ring->base_addr_owner_space_unaligned,
  861. CE_DESC_RING_ALIGN);
  862. dest_ring->base_addr_ce_space = ALIGN(
  863. dest_ring->base_addr_ce_space_unaligned,
  864. CE_DESC_RING_ALIGN);
  865. ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr,
  866. dest_ring->base_addr_ce_space);
  867. ath10k_ce_dest_ring_size_set(ar, ctrl_addr, nentries);
  868. ath10k_ce_dest_ring_byte_swap_set(ar, ctrl_addr, 0);
  869. ath10k_ce_dest_ring_lowmark_set(ar, ctrl_addr, 0);
  870. ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, nentries);
  871. return 0;
  872. }
  873. static struct ath10k_ce_pipe *ath10k_ce_init_state(struct ath10k *ar,
  874. unsigned int ce_id,
  875. const struct ce_attr *attr)
  876. {
  877. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  878. struct ath10k_ce_pipe *ce_state = &ar_pci->ce_states[ce_id];
  879. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  880. spin_lock_bh(&ar_pci->ce_lock);
  881. ce_state->ar = ar;
  882. ce_state->id = ce_id;
  883. ce_state->ctrl_addr = ctrl_addr;
  884. ce_state->attr_flags = attr->flags;
  885. ce_state->src_sz_max = attr->src_sz_max;
  886. spin_unlock_bh(&ar_pci->ce_lock);
  887. return ce_state;
  888. }
  889. /*
  890. * Initialize a Copy Engine based on caller-supplied attributes.
  891. * This may be called once to initialize both source and destination
  892. * rings or it may be called twice for separate source and destination
  893. * initialization. It may be that only one side or the other is
  894. * initialized by software/firmware.
  895. */
  896. struct ath10k_ce_pipe *ath10k_ce_init(struct ath10k *ar,
  897. unsigned int ce_id,
  898. const struct ce_attr *attr)
  899. {
  900. struct ath10k_ce_pipe *ce_state;
  901. u32 ctrl_addr = ath10k_ce_base_address(ce_id);
  902. int ret;
  903. ret = ath10k_pci_wake(ar);
  904. if (ret)
  905. return NULL;
  906. ce_state = ath10k_ce_init_state(ar, ce_id, attr);
  907. if (!ce_state) {
  908. ath10k_err("Failed to initialize CE state for ID: %d\n", ce_id);
  909. return NULL;
  910. }
  911. if (attr->src_nentries) {
  912. ret = ath10k_ce_init_src_ring(ar, ce_id, ce_state, attr);
  913. if (ret) {
  914. ath10k_err("Failed to initialize CE src ring for ID: %d (%d)\n",
  915. ce_id, ret);
  916. ath10k_ce_deinit(ce_state);
  917. return NULL;
  918. }
  919. }
  920. if (attr->dest_nentries) {
  921. ret = ath10k_ce_init_dest_ring(ar, ce_id, ce_state, attr);
  922. if (ret) {
  923. ath10k_err("Failed to initialize CE dest ring for ID: %d (%d)\n",
  924. ce_id, ret);
  925. ath10k_ce_deinit(ce_state);
  926. return NULL;
  927. }
  928. }
  929. /* Enable CE error interrupts */
  930. ath10k_ce_error_intr_enable(ar, ctrl_addr);
  931. ath10k_pci_sleep(ar);
  932. return ce_state;
  933. }
  934. void ath10k_ce_deinit(struct ath10k_ce_pipe *ce_state)
  935. {
  936. struct ath10k *ar = ce_state->ar;
  937. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  938. if (ce_state->src_ring) {
  939. kfree(ce_state->src_ring->shadow_base_unaligned);
  940. pci_free_consistent(ar_pci->pdev,
  941. (ce_state->src_ring->nentries *
  942. sizeof(struct ce_desc) +
  943. CE_DESC_RING_ALIGN),
  944. ce_state->src_ring->base_addr_owner_space,
  945. ce_state->src_ring->base_addr_ce_space);
  946. kfree(ce_state->src_ring);
  947. }
  948. if (ce_state->dest_ring) {
  949. pci_free_consistent(ar_pci->pdev,
  950. (ce_state->dest_ring->nentries *
  951. sizeof(struct ce_desc) +
  952. CE_DESC_RING_ALIGN),
  953. ce_state->dest_ring->base_addr_owner_space,
  954. ce_state->dest_ring->base_addr_ce_space);
  955. kfree(ce_state->dest_ring);
  956. }
  957. ce_state->src_ring = NULL;
  958. ce_state->dest_ring = NULL;
  959. }