ce.c 33 KB

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