ce.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2017 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 "ce.h"
  19. #include "debug.h"
  20. /*
  21. * Support for Copy Engine hardware, which is mainly used for
  22. * communication between Host and Target over a PCIe interconnect.
  23. */
  24. /*
  25. * A single CopyEngine (CE) comprises two "rings":
  26. * a source ring
  27. * a destination ring
  28. *
  29. * Each ring consists of a number of descriptors which specify
  30. * an address, length, and meta-data.
  31. *
  32. * Typically, one side of the PCIe/AHB/SNOC interconnect (Host or Target)
  33. * controls one ring and the other side controls the other ring.
  34. * The source side chooses when to initiate a transfer and it
  35. * chooses what to send (buffer address, length). The destination
  36. * side keeps a supply of "anonymous receive buffers" available and
  37. * it handles incoming data as it arrives (when the destination
  38. * receives an interrupt).
  39. *
  40. * The sender may send a simple buffer (address/length) or it may
  41. * send a small list of buffers. When a small list is sent, hardware
  42. * "gathers" these and they end up in a single destination buffer
  43. * with a single interrupt.
  44. *
  45. * There are several "contexts" managed by this layer -- more, it
  46. * may seem -- than should be needed. These are provided mainly for
  47. * maximum flexibility and especially to facilitate a simpler HIF
  48. * implementation. There are per-CopyEngine recv, send, and watermark
  49. * contexts. These are supplied by the caller when a recv, send,
  50. * or watermark handler is established and they are echoed back to
  51. * the caller when the respective callbacks are invoked. There is
  52. * also a per-transfer context supplied by the caller when a buffer
  53. * (or sendlist) is sent and when a buffer is enqueued for recv.
  54. * These per-transfer contexts are echoed back to the caller when
  55. * the buffer is sent/received.
  56. */
  57. static inline unsigned int
  58. ath10k_set_ring_byte(unsigned int offset,
  59. struct ath10k_hw_ce_regs_addr_map *addr_map)
  60. {
  61. return ((offset << addr_map->lsb) & addr_map->mask);
  62. }
  63. static inline unsigned int
  64. ath10k_get_ring_byte(unsigned int offset,
  65. struct ath10k_hw_ce_regs_addr_map *addr_map)
  66. {
  67. return ((offset & addr_map->mask) >> (addr_map->lsb));
  68. }
  69. static inline u32 ath10k_ce_read32(struct ath10k *ar, u32 offset)
  70. {
  71. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  72. return ce->bus_ops->read32(ar, offset);
  73. }
  74. static inline void ath10k_ce_write32(struct ath10k *ar, u32 offset, u32 value)
  75. {
  76. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  77. ce->bus_ops->write32(ar, offset, value);
  78. }
  79. static inline void ath10k_ce_dest_ring_write_index_set(struct ath10k *ar,
  80. u32 ce_ctrl_addr,
  81. unsigned int n)
  82. {
  83. ath10k_ce_write32(ar, ce_ctrl_addr +
  84. ar->hw_ce_regs->dst_wr_index_addr, n);
  85. }
  86. static inline u32 ath10k_ce_dest_ring_write_index_get(struct ath10k *ar,
  87. u32 ce_ctrl_addr)
  88. {
  89. return ath10k_ce_read32(ar, ce_ctrl_addr +
  90. ar->hw_ce_regs->dst_wr_index_addr);
  91. }
  92. static inline void ath10k_ce_src_ring_write_index_set(struct ath10k *ar,
  93. u32 ce_ctrl_addr,
  94. unsigned int n)
  95. {
  96. ath10k_ce_write32(ar, ce_ctrl_addr +
  97. ar->hw_ce_regs->sr_wr_index_addr, n);
  98. }
  99. static inline u32 ath10k_ce_src_ring_write_index_get(struct ath10k *ar,
  100. u32 ce_ctrl_addr)
  101. {
  102. return ath10k_ce_read32(ar, ce_ctrl_addr +
  103. ar->hw_ce_regs->sr_wr_index_addr);
  104. }
  105. static inline u32 ath10k_ce_src_ring_read_index_get(struct ath10k *ar,
  106. u32 ce_ctrl_addr)
  107. {
  108. return ath10k_ce_read32(ar, ce_ctrl_addr +
  109. ar->hw_ce_regs->current_srri_addr);
  110. }
  111. static inline void ath10k_ce_src_ring_base_addr_set(struct ath10k *ar,
  112. u32 ce_ctrl_addr,
  113. unsigned int addr)
  114. {
  115. ath10k_ce_write32(ar, ce_ctrl_addr +
  116. ar->hw_ce_regs->sr_base_addr, addr);
  117. }
  118. static inline void ath10k_ce_src_ring_size_set(struct ath10k *ar,
  119. u32 ce_ctrl_addr,
  120. unsigned int n)
  121. {
  122. ath10k_ce_write32(ar, ce_ctrl_addr +
  123. ar->hw_ce_regs->sr_size_addr, n);
  124. }
  125. static inline void ath10k_ce_src_ring_dmax_set(struct ath10k *ar,
  126. u32 ce_ctrl_addr,
  127. unsigned int n)
  128. {
  129. struct ath10k_hw_ce_ctrl1 *ctrl_regs = ar->hw_ce_regs->ctrl1_regs;
  130. u32 ctrl1_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
  131. ctrl_regs->addr);
  132. ath10k_ce_write32(ar, ce_ctrl_addr + ctrl_regs->addr,
  133. (ctrl1_addr & ~(ctrl_regs->dmax->mask)) |
  134. ath10k_set_ring_byte(n, ctrl_regs->dmax));
  135. }
  136. static inline void ath10k_ce_src_ring_byte_swap_set(struct ath10k *ar,
  137. u32 ce_ctrl_addr,
  138. unsigned int n)
  139. {
  140. struct ath10k_hw_ce_ctrl1 *ctrl_regs = ar->hw_ce_regs->ctrl1_regs;
  141. u32 ctrl1_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
  142. ctrl_regs->addr);
  143. ath10k_ce_write32(ar, ce_ctrl_addr + ctrl_regs->addr,
  144. (ctrl1_addr & ~(ctrl_regs->src_ring->mask)) |
  145. ath10k_set_ring_byte(n, ctrl_regs->src_ring));
  146. }
  147. static inline void ath10k_ce_dest_ring_byte_swap_set(struct ath10k *ar,
  148. u32 ce_ctrl_addr,
  149. unsigned int n)
  150. {
  151. struct ath10k_hw_ce_ctrl1 *ctrl_regs = ar->hw_ce_regs->ctrl1_regs;
  152. u32 ctrl1_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
  153. ctrl_regs->addr);
  154. ath10k_ce_write32(ar, ce_ctrl_addr + ctrl_regs->addr,
  155. (ctrl1_addr & ~(ctrl_regs->dst_ring->mask)) |
  156. ath10k_set_ring_byte(n, ctrl_regs->dst_ring));
  157. }
  158. static inline u32 ath10k_ce_dest_ring_read_index_get(struct ath10k *ar,
  159. u32 ce_ctrl_addr)
  160. {
  161. return ath10k_ce_read32(ar, ce_ctrl_addr +
  162. ar->hw_ce_regs->current_drri_addr);
  163. }
  164. static inline void ath10k_ce_dest_ring_base_addr_set(struct ath10k *ar,
  165. u32 ce_ctrl_addr,
  166. u32 addr)
  167. {
  168. ath10k_ce_write32(ar, ce_ctrl_addr +
  169. ar->hw_ce_regs->dr_base_addr, addr);
  170. }
  171. static inline void ath10k_ce_dest_ring_size_set(struct ath10k *ar,
  172. u32 ce_ctrl_addr,
  173. unsigned int n)
  174. {
  175. ath10k_ce_write32(ar, ce_ctrl_addr +
  176. ar->hw_ce_regs->dr_size_addr, n);
  177. }
  178. static inline void ath10k_ce_src_ring_highmark_set(struct ath10k *ar,
  179. u32 ce_ctrl_addr,
  180. unsigned int n)
  181. {
  182. struct ath10k_hw_ce_dst_src_wm_regs *srcr_wm = ar->hw_ce_regs->wm_srcr;
  183. u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + srcr_wm->addr);
  184. ath10k_ce_write32(ar, ce_ctrl_addr + srcr_wm->addr,
  185. (addr & ~(srcr_wm->wm_high->mask)) |
  186. (ath10k_set_ring_byte(n, srcr_wm->wm_high)));
  187. }
  188. static inline void ath10k_ce_src_ring_lowmark_set(struct ath10k *ar,
  189. u32 ce_ctrl_addr,
  190. unsigned int n)
  191. {
  192. struct ath10k_hw_ce_dst_src_wm_regs *srcr_wm = ar->hw_ce_regs->wm_srcr;
  193. u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + srcr_wm->addr);
  194. ath10k_ce_write32(ar, ce_ctrl_addr + srcr_wm->addr,
  195. (addr & ~(srcr_wm->wm_low->mask)) |
  196. (ath10k_set_ring_byte(n, srcr_wm->wm_low)));
  197. }
  198. static inline void ath10k_ce_dest_ring_highmark_set(struct ath10k *ar,
  199. u32 ce_ctrl_addr,
  200. unsigned int n)
  201. {
  202. struct ath10k_hw_ce_dst_src_wm_regs *dstr_wm = ar->hw_ce_regs->wm_dstr;
  203. u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + dstr_wm->addr);
  204. ath10k_ce_write32(ar, ce_ctrl_addr + dstr_wm->addr,
  205. (addr & ~(dstr_wm->wm_high->mask)) |
  206. (ath10k_set_ring_byte(n, dstr_wm->wm_high)));
  207. }
  208. static inline void ath10k_ce_dest_ring_lowmark_set(struct ath10k *ar,
  209. u32 ce_ctrl_addr,
  210. unsigned int n)
  211. {
  212. struct ath10k_hw_ce_dst_src_wm_regs *dstr_wm = ar->hw_ce_regs->wm_dstr;
  213. u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + dstr_wm->addr);
  214. ath10k_ce_write32(ar, ce_ctrl_addr + dstr_wm->addr,
  215. (addr & ~(dstr_wm->wm_low->mask)) |
  216. (ath10k_set_ring_byte(n, dstr_wm->wm_low)));
  217. }
  218. static inline void ath10k_ce_copy_complete_inter_enable(struct ath10k *ar,
  219. u32 ce_ctrl_addr)
  220. {
  221. struct ath10k_hw_ce_host_ie *host_ie = ar->hw_ce_regs->host_ie;
  222. u32 host_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
  223. ar->hw_ce_regs->host_ie_addr);
  224. ath10k_ce_write32(ar, ce_ctrl_addr + ar->hw_ce_regs->host_ie_addr,
  225. host_ie_addr | host_ie->copy_complete->mask);
  226. }
  227. static inline void ath10k_ce_copy_complete_intr_disable(struct ath10k *ar,
  228. u32 ce_ctrl_addr)
  229. {
  230. struct ath10k_hw_ce_host_ie *host_ie = ar->hw_ce_regs->host_ie;
  231. u32 host_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
  232. ar->hw_ce_regs->host_ie_addr);
  233. ath10k_ce_write32(ar, ce_ctrl_addr + ar->hw_ce_regs->host_ie_addr,
  234. host_ie_addr & ~(host_ie->copy_complete->mask));
  235. }
  236. static inline void ath10k_ce_watermark_intr_disable(struct ath10k *ar,
  237. u32 ce_ctrl_addr)
  238. {
  239. struct ath10k_hw_ce_host_wm_regs *wm_regs = ar->hw_ce_regs->wm_regs;
  240. u32 host_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
  241. ar->hw_ce_regs->host_ie_addr);
  242. ath10k_ce_write32(ar, ce_ctrl_addr + ar->hw_ce_regs->host_ie_addr,
  243. host_ie_addr & ~(wm_regs->wm_mask));
  244. }
  245. static inline void ath10k_ce_error_intr_enable(struct ath10k *ar,
  246. u32 ce_ctrl_addr)
  247. {
  248. struct ath10k_hw_ce_misc_regs *misc_regs = ar->hw_ce_regs->misc_regs;
  249. u32 misc_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
  250. ar->hw_ce_regs->misc_ie_addr);
  251. ath10k_ce_write32(ar,
  252. ce_ctrl_addr + ar->hw_ce_regs->misc_ie_addr,
  253. misc_ie_addr | misc_regs->err_mask);
  254. }
  255. static inline void ath10k_ce_error_intr_disable(struct ath10k *ar,
  256. u32 ce_ctrl_addr)
  257. {
  258. struct ath10k_hw_ce_misc_regs *misc_regs = ar->hw_ce_regs->misc_regs;
  259. u32 misc_ie_addr = ath10k_ce_read32(ar,
  260. ce_ctrl_addr + ar->hw_ce_regs->misc_ie_addr);
  261. ath10k_ce_write32(ar,
  262. ce_ctrl_addr + ar->hw_ce_regs->misc_ie_addr,
  263. misc_ie_addr & ~(misc_regs->err_mask));
  264. }
  265. static inline void ath10k_ce_engine_int_status_clear(struct ath10k *ar,
  266. u32 ce_ctrl_addr,
  267. unsigned int mask)
  268. {
  269. struct ath10k_hw_ce_host_wm_regs *wm_regs = ar->hw_ce_regs->wm_regs;
  270. ath10k_ce_write32(ar, ce_ctrl_addr + wm_regs->addr, mask);
  271. }
  272. /*
  273. * Guts of ath10k_ce_send.
  274. * The caller takes responsibility for any needed locking.
  275. */
  276. static int _ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
  277. void *per_transfer_context,
  278. dma_addr_t buffer,
  279. unsigned int nbytes,
  280. unsigned int transfer_id,
  281. unsigned int flags)
  282. {
  283. struct ath10k *ar = ce_state->ar;
  284. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  285. struct ce_desc *desc, sdesc;
  286. unsigned int nentries_mask = src_ring->nentries_mask;
  287. unsigned int sw_index = src_ring->sw_index;
  288. unsigned int write_index = src_ring->write_index;
  289. u32 ctrl_addr = ce_state->ctrl_addr;
  290. u32 desc_flags = 0;
  291. int ret = 0;
  292. if (nbytes > ce_state->src_sz_max)
  293. ath10k_warn(ar, "%s: send more we can (nbytes: %d, max: %d)\n",
  294. __func__, nbytes, ce_state->src_sz_max);
  295. if (unlikely(CE_RING_DELTA(nentries_mask,
  296. write_index, sw_index - 1) <= 0)) {
  297. ret = -ENOSR;
  298. goto exit;
  299. }
  300. desc = CE_SRC_RING_TO_DESC(src_ring->base_addr_owner_space,
  301. write_index);
  302. desc_flags |= SM(transfer_id, CE_DESC_FLAGS_META_DATA);
  303. if (flags & CE_SEND_FLAG_GATHER)
  304. desc_flags |= CE_DESC_FLAGS_GATHER;
  305. if (flags & CE_SEND_FLAG_BYTE_SWAP)
  306. desc_flags |= CE_DESC_FLAGS_BYTE_SWAP;
  307. sdesc.addr = __cpu_to_le32(buffer);
  308. sdesc.nbytes = __cpu_to_le16(nbytes);
  309. sdesc.flags = __cpu_to_le16(desc_flags);
  310. *desc = sdesc;
  311. src_ring->per_transfer_context[write_index] = per_transfer_context;
  312. /* Update Source Ring Write Index */
  313. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  314. /* WORKAROUND */
  315. if (!(flags & CE_SEND_FLAG_GATHER))
  316. ath10k_ce_src_ring_write_index_set(ar, ctrl_addr, write_index);
  317. src_ring->write_index = write_index;
  318. exit:
  319. return ret;
  320. }
  321. static int _ath10k_ce_send_nolock_64(struct ath10k_ce_pipe *ce_state,
  322. void *per_transfer_context,
  323. dma_addr_t buffer,
  324. unsigned int nbytes,
  325. unsigned int transfer_id,
  326. unsigned int flags)
  327. {
  328. struct ath10k *ar = ce_state->ar;
  329. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  330. struct ce_desc_64 *desc, sdesc;
  331. unsigned int nentries_mask = src_ring->nentries_mask;
  332. unsigned int sw_index = src_ring->sw_index;
  333. unsigned int write_index = src_ring->write_index;
  334. u32 ctrl_addr = ce_state->ctrl_addr;
  335. __le32 *addr;
  336. u32 desc_flags = 0;
  337. int ret = 0;
  338. if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
  339. return -ESHUTDOWN;
  340. if (nbytes > ce_state->src_sz_max)
  341. ath10k_warn(ar, "%s: send more we can (nbytes: %d, max: %d)\n",
  342. __func__, nbytes, ce_state->src_sz_max);
  343. if (unlikely(CE_RING_DELTA(nentries_mask,
  344. write_index, sw_index - 1) <= 0)) {
  345. ret = -ENOSR;
  346. goto exit;
  347. }
  348. desc = CE_SRC_RING_TO_DESC_64(src_ring->base_addr_owner_space,
  349. write_index);
  350. desc_flags |= SM(transfer_id, CE_DESC_FLAGS_META_DATA);
  351. if (flags & CE_SEND_FLAG_GATHER)
  352. desc_flags |= CE_DESC_FLAGS_GATHER;
  353. if (flags & CE_SEND_FLAG_BYTE_SWAP)
  354. desc_flags |= CE_DESC_FLAGS_BYTE_SWAP;
  355. addr = (__le32 *)&sdesc.addr;
  356. flags |= upper_32_bits(buffer) & CE_DESC_FLAGS_GET_MASK;
  357. addr[0] = __cpu_to_le32(buffer);
  358. addr[1] = __cpu_to_le32(flags);
  359. if (flags & CE_SEND_FLAG_GATHER)
  360. addr[1] |= __cpu_to_le32(CE_WCN3990_DESC_FLAGS_GATHER);
  361. else
  362. addr[1] &= ~(__cpu_to_le32(CE_WCN3990_DESC_FLAGS_GATHER));
  363. sdesc.nbytes = __cpu_to_le16(nbytes);
  364. sdesc.flags = __cpu_to_le16(desc_flags);
  365. *desc = sdesc;
  366. src_ring->per_transfer_context[write_index] = per_transfer_context;
  367. /* Update Source Ring Write Index */
  368. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  369. if (!(flags & CE_SEND_FLAG_GATHER))
  370. ath10k_ce_src_ring_write_index_set(ar, ctrl_addr, write_index);
  371. src_ring->write_index = write_index;
  372. exit:
  373. return ret;
  374. }
  375. int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
  376. void *per_transfer_context,
  377. dma_addr_t buffer,
  378. unsigned int nbytes,
  379. unsigned int transfer_id,
  380. unsigned int flags)
  381. {
  382. return ce_state->ops->ce_send_nolock(ce_state, per_transfer_context,
  383. buffer, nbytes, transfer_id, flags);
  384. }
  385. void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe)
  386. {
  387. struct ath10k *ar = pipe->ar;
  388. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  389. struct ath10k_ce_ring *src_ring = pipe->src_ring;
  390. u32 ctrl_addr = pipe->ctrl_addr;
  391. lockdep_assert_held(&ce->ce_lock);
  392. /*
  393. * This function must be called only if there is an incomplete
  394. * scatter-gather transfer (before index register is updated)
  395. * that needs to be cleaned up.
  396. */
  397. if (WARN_ON_ONCE(src_ring->write_index == src_ring->sw_index))
  398. return;
  399. if (WARN_ON_ONCE(src_ring->write_index ==
  400. ath10k_ce_src_ring_write_index_get(ar, ctrl_addr)))
  401. return;
  402. src_ring->write_index--;
  403. src_ring->write_index &= src_ring->nentries_mask;
  404. src_ring->per_transfer_context[src_ring->write_index] = NULL;
  405. }
  406. int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
  407. void *per_transfer_context,
  408. dma_addr_t buffer,
  409. unsigned int nbytes,
  410. unsigned int transfer_id,
  411. unsigned int flags)
  412. {
  413. struct ath10k *ar = ce_state->ar;
  414. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  415. int ret;
  416. spin_lock_bh(&ce->ce_lock);
  417. ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
  418. buffer, nbytes, transfer_id, flags);
  419. spin_unlock_bh(&ce->ce_lock);
  420. return ret;
  421. }
  422. int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe)
  423. {
  424. struct ath10k *ar = pipe->ar;
  425. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  426. int delta;
  427. spin_lock_bh(&ce->ce_lock);
  428. delta = CE_RING_DELTA(pipe->src_ring->nentries_mask,
  429. pipe->src_ring->write_index,
  430. pipe->src_ring->sw_index - 1);
  431. spin_unlock_bh(&ce->ce_lock);
  432. return delta;
  433. }
  434. int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe)
  435. {
  436. struct ath10k *ar = pipe->ar;
  437. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  438. struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
  439. unsigned int nentries_mask = dest_ring->nentries_mask;
  440. unsigned int write_index = dest_ring->write_index;
  441. unsigned int sw_index = dest_ring->sw_index;
  442. lockdep_assert_held(&ce->ce_lock);
  443. return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
  444. }
  445. static int __ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
  446. dma_addr_t paddr)
  447. {
  448. struct ath10k *ar = pipe->ar;
  449. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  450. struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
  451. unsigned int nentries_mask = dest_ring->nentries_mask;
  452. unsigned int write_index = dest_ring->write_index;
  453. unsigned int sw_index = dest_ring->sw_index;
  454. struct ce_desc *base = dest_ring->base_addr_owner_space;
  455. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, write_index);
  456. u32 ctrl_addr = pipe->ctrl_addr;
  457. lockdep_assert_held(&ce->ce_lock);
  458. if ((pipe->id != 5) &&
  459. CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) == 0)
  460. return -ENOSPC;
  461. desc->addr = __cpu_to_le32(paddr);
  462. desc->nbytes = 0;
  463. dest_ring->per_transfer_context[write_index] = ctx;
  464. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  465. ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
  466. dest_ring->write_index = write_index;
  467. return 0;
  468. }
  469. static int __ath10k_ce_rx_post_buf_64(struct ath10k_ce_pipe *pipe,
  470. void *ctx,
  471. dma_addr_t paddr)
  472. {
  473. struct ath10k *ar = pipe->ar;
  474. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  475. struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
  476. unsigned int nentries_mask = dest_ring->nentries_mask;
  477. unsigned int write_index = dest_ring->write_index;
  478. unsigned int sw_index = dest_ring->sw_index;
  479. struct ce_desc_64 *base = dest_ring->base_addr_owner_space;
  480. struct ce_desc_64 *desc =
  481. CE_DEST_RING_TO_DESC_64(base, write_index);
  482. u32 ctrl_addr = pipe->ctrl_addr;
  483. lockdep_assert_held(&ce->ce_lock);
  484. if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) == 0)
  485. return -ENOSPC;
  486. desc->addr = __cpu_to_le64(paddr);
  487. desc->addr &= __cpu_to_le64(CE_DESC_37BIT_ADDR_MASK);
  488. desc->nbytes = 0;
  489. dest_ring->per_transfer_context[write_index] = ctx;
  490. write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
  491. ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
  492. dest_ring->write_index = write_index;
  493. return 0;
  494. }
  495. void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries)
  496. {
  497. struct ath10k *ar = pipe->ar;
  498. struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
  499. unsigned int nentries_mask = dest_ring->nentries_mask;
  500. unsigned int write_index = dest_ring->write_index;
  501. u32 ctrl_addr = pipe->ctrl_addr;
  502. u32 cur_write_idx = ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
  503. /* Prevent CE ring stuck issue that will occur when ring is full.
  504. * Make sure that write index is 1 less than read index.
  505. */
  506. if ((cur_write_idx + nentries) == dest_ring->sw_index)
  507. nentries -= 1;
  508. write_index = CE_RING_IDX_ADD(nentries_mask, write_index, nentries);
  509. ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
  510. dest_ring->write_index = write_index;
  511. }
  512. int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
  513. dma_addr_t paddr)
  514. {
  515. struct ath10k *ar = pipe->ar;
  516. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  517. int ret;
  518. spin_lock_bh(&ce->ce_lock);
  519. ret = pipe->ops->ce_rx_post_buf(pipe, ctx, paddr);
  520. spin_unlock_bh(&ce->ce_lock);
  521. return ret;
  522. }
  523. /*
  524. * Guts of ath10k_ce_completed_recv_next.
  525. * The caller takes responsibility for any necessary locking.
  526. */
  527. static int
  528. _ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
  529. void **per_transfer_contextp,
  530. unsigned int *nbytesp)
  531. {
  532. struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
  533. unsigned int nentries_mask = dest_ring->nentries_mask;
  534. unsigned int sw_index = dest_ring->sw_index;
  535. struct ce_desc *base = dest_ring->base_addr_owner_space;
  536. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  537. struct ce_desc sdesc;
  538. u16 nbytes;
  539. /* Copy in one go for performance reasons */
  540. sdesc = *desc;
  541. nbytes = __le16_to_cpu(sdesc.nbytes);
  542. if (nbytes == 0) {
  543. /*
  544. * This closes a relatively unusual race where the Host
  545. * sees the updated DRRI before the update to the
  546. * corresponding descriptor has completed. We treat this
  547. * as a descriptor that is not yet done.
  548. */
  549. return -EIO;
  550. }
  551. desc->nbytes = 0;
  552. /* Return data from completed destination descriptor */
  553. *nbytesp = nbytes;
  554. if (per_transfer_contextp)
  555. *per_transfer_contextp =
  556. dest_ring->per_transfer_context[sw_index];
  557. /* Copy engine 5 (HTT Rx) will reuse the same transfer context.
  558. * So update transfer context all CEs except CE5.
  559. */
  560. if (ce_state->id != 5)
  561. dest_ring->per_transfer_context[sw_index] = NULL;
  562. /* Update sw_index */
  563. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  564. dest_ring->sw_index = sw_index;
  565. return 0;
  566. }
  567. static int
  568. _ath10k_ce_completed_recv_next_nolock_64(struct ath10k_ce_pipe *ce_state,
  569. void **per_transfer_contextp,
  570. unsigned int *nbytesp)
  571. {
  572. struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
  573. unsigned int nentries_mask = dest_ring->nentries_mask;
  574. unsigned int sw_index = dest_ring->sw_index;
  575. struct ce_desc_64 *base = dest_ring->base_addr_owner_space;
  576. struct ce_desc_64 *desc =
  577. CE_DEST_RING_TO_DESC_64(base, sw_index);
  578. struct ce_desc_64 sdesc;
  579. u16 nbytes;
  580. /* Copy in one go for performance reasons */
  581. sdesc = *desc;
  582. nbytes = __le16_to_cpu(sdesc.nbytes);
  583. if (nbytes == 0) {
  584. /* This closes a relatively unusual race where the Host
  585. * sees the updated DRRI before the update to the
  586. * corresponding descriptor has completed. We treat this
  587. * as a descriptor that is not yet done.
  588. */
  589. return -EIO;
  590. }
  591. desc->nbytes = 0;
  592. /* Return data from completed destination descriptor */
  593. *nbytesp = nbytes;
  594. if (per_transfer_contextp)
  595. *per_transfer_contextp =
  596. dest_ring->per_transfer_context[sw_index];
  597. /* Copy engine 5 (HTT Rx) will reuse the same transfer context.
  598. * So update transfer context all CEs except CE5.
  599. */
  600. if (ce_state->id != 5)
  601. dest_ring->per_transfer_context[sw_index] = NULL;
  602. /* Update sw_index */
  603. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  604. dest_ring->sw_index = sw_index;
  605. return 0;
  606. }
  607. int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
  608. void **per_transfer_ctx,
  609. unsigned int *nbytesp)
  610. {
  611. return ce_state->ops->ce_completed_recv_next_nolock(ce_state,
  612. per_transfer_ctx,
  613. nbytesp);
  614. }
  615. int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
  616. void **per_transfer_contextp,
  617. unsigned int *nbytesp)
  618. {
  619. struct ath10k *ar = ce_state->ar;
  620. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  621. int ret;
  622. spin_lock_bh(&ce->ce_lock);
  623. ret = ce_state->ops->ce_completed_recv_next_nolock(ce_state,
  624. per_transfer_contextp,
  625. nbytesp);
  626. spin_unlock_bh(&ce->ce_lock);
  627. return ret;
  628. }
  629. static int _ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  630. void **per_transfer_contextp,
  631. dma_addr_t *bufferp)
  632. {
  633. struct ath10k_ce_ring *dest_ring;
  634. unsigned int nentries_mask;
  635. unsigned int sw_index;
  636. unsigned int write_index;
  637. int ret;
  638. struct ath10k *ar;
  639. struct ath10k_ce *ce;
  640. dest_ring = ce_state->dest_ring;
  641. if (!dest_ring)
  642. return -EIO;
  643. ar = ce_state->ar;
  644. ce = ath10k_ce_priv(ar);
  645. spin_lock_bh(&ce->ce_lock);
  646. nentries_mask = dest_ring->nentries_mask;
  647. sw_index = dest_ring->sw_index;
  648. write_index = dest_ring->write_index;
  649. if (write_index != sw_index) {
  650. struct ce_desc *base = dest_ring->base_addr_owner_space;
  651. struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
  652. /* Return data from completed destination descriptor */
  653. *bufferp = __le32_to_cpu(desc->addr);
  654. if (per_transfer_contextp)
  655. *per_transfer_contextp =
  656. dest_ring->per_transfer_context[sw_index];
  657. /* sanity */
  658. dest_ring->per_transfer_context[sw_index] = NULL;
  659. desc->nbytes = 0;
  660. /* Update sw_index */
  661. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  662. dest_ring->sw_index = sw_index;
  663. ret = 0;
  664. } else {
  665. ret = -EIO;
  666. }
  667. spin_unlock_bh(&ce->ce_lock);
  668. return ret;
  669. }
  670. static int _ath10k_ce_revoke_recv_next_64(struct ath10k_ce_pipe *ce_state,
  671. void **per_transfer_contextp,
  672. dma_addr_t *bufferp)
  673. {
  674. struct ath10k_ce_ring *dest_ring;
  675. unsigned int nentries_mask;
  676. unsigned int sw_index;
  677. unsigned int write_index;
  678. int ret;
  679. struct ath10k *ar;
  680. struct ath10k_ce *ce;
  681. dest_ring = ce_state->dest_ring;
  682. if (!dest_ring)
  683. return -EIO;
  684. ar = ce_state->ar;
  685. ce = ath10k_ce_priv(ar);
  686. spin_lock_bh(&ce->ce_lock);
  687. nentries_mask = dest_ring->nentries_mask;
  688. sw_index = dest_ring->sw_index;
  689. write_index = dest_ring->write_index;
  690. if (write_index != sw_index) {
  691. struct ce_desc_64 *base = dest_ring->base_addr_owner_space;
  692. struct ce_desc_64 *desc =
  693. CE_DEST_RING_TO_DESC_64(base, sw_index);
  694. /* Return data from completed destination descriptor */
  695. *bufferp = __le64_to_cpu(desc->addr);
  696. if (per_transfer_contextp)
  697. *per_transfer_contextp =
  698. dest_ring->per_transfer_context[sw_index];
  699. /* sanity */
  700. dest_ring->per_transfer_context[sw_index] = NULL;
  701. desc->nbytes = 0;
  702. /* Update sw_index */
  703. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  704. dest_ring->sw_index = sw_index;
  705. ret = 0;
  706. } else {
  707. ret = -EIO;
  708. }
  709. spin_unlock_bh(&ce->ce_lock);
  710. return ret;
  711. }
  712. int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
  713. void **per_transfer_contextp,
  714. dma_addr_t *bufferp)
  715. {
  716. return ce_state->ops->ce_revoke_recv_next(ce_state,
  717. per_transfer_contextp,
  718. bufferp);
  719. }
  720. /*
  721. * Guts of ath10k_ce_completed_send_next.
  722. * The caller takes responsibility for any necessary locking.
  723. */
  724. int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
  725. void **per_transfer_contextp)
  726. {
  727. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  728. u32 ctrl_addr = ce_state->ctrl_addr;
  729. struct ath10k *ar = ce_state->ar;
  730. unsigned int nentries_mask = src_ring->nentries_mask;
  731. unsigned int sw_index = src_ring->sw_index;
  732. unsigned int read_index;
  733. struct ce_desc *desc;
  734. if (src_ring->hw_index == sw_index) {
  735. /*
  736. * The SW completion index has caught up with the cached
  737. * version of the HW completion index.
  738. * Update the cached HW completion index to see whether
  739. * the SW has really caught up to the HW, or if the cached
  740. * value of the HW index has become stale.
  741. */
  742. read_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  743. if (read_index == 0xffffffff)
  744. return -ENODEV;
  745. read_index &= nentries_mask;
  746. src_ring->hw_index = read_index;
  747. }
  748. read_index = src_ring->hw_index;
  749. if (read_index == sw_index)
  750. return -EIO;
  751. if (per_transfer_contextp)
  752. *per_transfer_contextp =
  753. src_ring->per_transfer_context[sw_index];
  754. /* sanity */
  755. src_ring->per_transfer_context[sw_index] = NULL;
  756. desc = CE_SRC_RING_TO_DESC(src_ring->base_addr_owner_space,
  757. sw_index);
  758. desc->nbytes = 0;
  759. /* Update sw_index */
  760. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  761. src_ring->sw_index = sw_index;
  762. return 0;
  763. }
  764. static void ath10k_ce_extract_desc_data(struct ath10k *ar,
  765. struct ath10k_ce_ring *src_ring,
  766. u32 sw_index,
  767. dma_addr_t *bufferp,
  768. u32 *nbytesp,
  769. u32 *transfer_idp)
  770. {
  771. struct ce_desc *base = src_ring->base_addr_owner_space;
  772. struct ce_desc *desc = CE_SRC_RING_TO_DESC(base, sw_index);
  773. /* Return data from completed source descriptor */
  774. *bufferp = __le32_to_cpu(desc->addr);
  775. *nbytesp = __le16_to_cpu(desc->nbytes);
  776. *transfer_idp = MS(__le16_to_cpu(desc->flags),
  777. CE_DESC_FLAGS_META_DATA);
  778. }
  779. static void ath10k_ce_extract_desc_data_64(struct ath10k *ar,
  780. struct ath10k_ce_ring *src_ring,
  781. u32 sw_index,
  782. dma_addr_t *bufferp,
  783. u32 *nbytesp,
  784. u32 *transfer_idp)
  785. {
  786. struct ce_desc_64 *base = src_ring->base_addr_owner_space;
  787. struct ce_desc_64 *desc =
  788. CE_SRC_RING_TO_DESC_64(base, sw_index);
  789. /* Return data from completed source descriptor */
  790. *bufferp = __le64_to_cpu(desc->addr);
  791. *nbytesp = __le16_to_cpu(desc->nbytes);
  792. *transfer_idp = MS(__le16_to_cpu(desc->flags),
  793. CE_DESC_FLAGS_META_DATA);
  794. }
  795. /* NB: Modeled after ath10k_ce_completed_send_next */
  796. int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
  797. void **per_transfer_contextp,
  798. dma_addr_t *bufferp,
  799. unsigned int *nbytesp,
  800. unsigned int *transfer_idp)
  801. {
  802. struct ath10k_ce_ring *src_ring;
  803. unsigned int nentries_mask;
  804. unsigned int sw_index;
  805. unsigned int write_index;
  806. int ret;
  807. struct ath10k *ar;
  808. struct ath10k_ce *ce;
  809. src_ring = ce_state->src_ring;
  810. if (!src_ring)
  811. return -EIO;
  812. ar = ce_state->ar;
  813. ce = ath10k_ce_priv(ar);
  814. spin_lock_bh(&ce->ce_lock);
  815. nentries_mask = src_ring->nentries_mask;
  816. sw_index = src_ring->sw_index;
  817. write_index = src_ring->write_index;
  818. if (write_index != sw_index) {
  819. ce_state->ops->ce_extract_desc_data(ar, src_ring, sw_index,
  820. bufferp, nbytesp,
  821. transfer_idp);
  822. if (per_transfer_contextp)
  823. *per_transfer_contextp =
  824. src_ring->per_transfer_context[sw_index];
  825. /* sanity */
  826. src_ring->per_transfer_context[sw_index] = NULL;
  827. /* Update sw_index */
  828. sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
  829. src_ring->sw_index = sw_index;
  830. ret = 0;
  831. } else {
  832. ret = -EIO;
  833. }
  834. spin_unlock_bh(&ce->ce_lock);
  835. return ret;
  836. }
  837. int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
  838. void **per_transfer_contextp)
  839. {
  840. struct ath10k *ar = ce_state->ar;
  841. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  842. int ret;
  843. spin_lock_bh(&ce->ce_lock);
  844. ret = ath10k_ce_completed_send_next_nolock(ce_state,
  845. per_transfer_contextp);
  846. spin_unlock_bh(&ce->ce_lock);
  847. return ret;
  848. }
  849. /*
  850. * Guts of interrupt handler for per-engine interrupts on a particular CE.
  851. *
  852. * Invokes registered callbacks for recv_complete,
  853. * send_complete, and watermarks.
  854. */
  855. void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id)
  856. {
  857. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  858. struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
  859. struct ath10k_hw_ce_host_wm_regs *wm_regs = ar->hw_ce_regs->wm_regs;
  860. u32 ctrl_addr = ce_state->ctrl_addr;
  861. spin_lock_bh(&ce->ce_lock);
  862. /* Clear the copy-complete interrupts that will be handled here. */
  863. ath10k_ce_engine_int_status_clear(ar, ctrl_addr,
  864. wm_regs->cc_mask);
  865. spin_unlock_bh(&ce->ce_lock);
  866. if (ce_state->recv_cb)
  867. ce_state->recv_cb(ce_state);
  868. if (ce_state->send_cb)
  869. ce_state->send_cb(ce_state);
  870. spin_lock_bh(&ce->ce_lock);
  871. /*
  872. * Misc CE interrupts are not being handled, but still need
  873. * to be cleared.
  874. */
  875. ath10k_ce_engine_int_status_clear(ar, ctrl_addr, wm_regs->wm_mask);
  876. spin_unlock_bh(&ce->ce_lock);
  877. }
  878. /*
  879. * Handler for per-engine interrupts on ALL active CEs.
  880. * This is used in cases where the system is sharing a
  881. * single interrput for all CEs
  882. */
  883. void ath10k_ce_per_engine_service_any(struct ath10k *ar)
  884. {
  885. int ce_id;
  886. u32 intr_summary;
  887. intr_summary = ath10k_ce_interrupt_summary(ar);
  888. for (ce_id = 0; intr_summary && (ce_id < CE_COUNT); ce_id++) {
  889. if (intr_summary & (1 << ce_id))
  890. intr_summary &= ~(1 << ce_id);
  891. else
  892. /* no intr pending on this CE */
  893. continue;
  894. ath10k_ce_per_engine_service(ar, ce_id);
  895. }
  896. }
  897. /*
  898. * Adjust interrupts for the copy complete handler.
  899. * If it's needed for either send or recv, then unmask
  900. * this interrupt; otherwise, mask it.
  901. *
  902. * Called with ce_lock held.
  903. */
  904. static void ath10k_ce_per_engine_handler_adjust(struct ath10k_ce_pipe *ce_state)
  905. {
  906. u32 ctrl_addr = ce_state->ctrl_addr;
  907. struct ath10k *ar = ce_state->ar;
  908. bool disable_copy_compl_intr = ce_state->attr_flags & CE_ATTR_DIS_INTR;
  909. if ((!disable_copy_compl_intr) &&
  910. (ce_state->send_cb || ce_state->recv_cb))
  911. ath10k_ce_copy_complete_inter_enable(ar, ctrl_addr);
  912. else
  913. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  914. ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
  915. }
  916. int ath10k_ce_disable_interrupts(struct ath10k *ar)
  917. {
  918. int ce_id;
  919. for (ce_id = 0; ce_id < CE_COUNT; ce_id++) {
  920. u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  921. ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
  922. ath10k_ce_error_intr_disable(ar, ctrl_addr);
  923. ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
  924. }
  925. return 0;
  926. }
  927. void ath10k_ce_enable_interrupts(struct ath10k *ar)
  928. {
  929. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  930. int ce_id;
  931. struct ath10k_ce_pipe *ce_state;
  932. /* Skip the last copy engine, CE7 the diagnostic window, as that
  933. * uses polling and isn't initialized for interrupts.
  934. */
  935. for (ce_id = 0; ce_id < CE_COUNT - 1; ce_id++) {
  936. ce_state = &ce->ce_states[ce_id];
  937. ath10k_ce_per_engine_handler_adjust(ce_state);
  938. }
  939. }
  940. static int ath10k_ce_init_src_ring(struct ath10k *ar,
  941. unsigned int ce_id,
  942. const struct ce_attr *attr)
  943. {
  944. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  945. struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
  946. struct ath10k_ce_ring *src_ring = ce_state->src_ring;
  947. u32 nentries, ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  948. nentries = roundup_pow_of_two(attr->src_nentries);
  949. if (ar->hw_params.target_64bit)
  950. memset(src_ring->base_addr_owner_space, 0,
  951. nentries * sizeof(struct ce_desc_64));
  952. else
  953. memset(src_ring->base_addr_owner_space, 0,
  954. nentries * sizeof(struct ce_desc));
  955. src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
  956. src_ring->sw_index &= src_ring->nentries_mask;
  957. src_ring->hw_index = src_ring->sw_index;
  958. src_ring->write_index =
  959. ath10k_ce_src_ring_write_index_get(ar, ctrl_addr);
  960. src_ring->write_index &= src_ring->nentries_mask;
  961. ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr,
  962. src_ring->base_addr_ce_space);
  963. ath10k_ce_src_ring_size_set(ar, ctrl_addr, nentries);
  964. ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, attr->src_sz_max);
  965. ath10k_ce_src_ring_byte_swap_set(ar, ctrl_addr, 0);
  966. ath10k_ce_src_ring_lowmark_set(ar, ctrl_addr, 0);
  967. ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, nentries);
  968. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  969. "boot init ce src ring id %d entries %d base_addr %pK\n",
  970. ce_id, nentries, src_ring->base_addr_owner_space);
  971. return 0;
  972. }
  973. static int ath10k_ce_init_dest_ring(struct ath10k *ar,
  974. unsigned int ce_id,
  975. const struct ce_attr *attr)
  976. {
  977. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  978. struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
  979. struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
  980. u32 nentries, ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  981. nentries = roundup_pow_of_two(attr->dest_nentries);
  982. if (ar->hw_params.target_64bit)
  983. memset(dest_ring->base_addr_owner_space, 0,
  984. nentries * sizeof(struct ce_desc_64));
  985. else
  986. memset(dest_ring->base_addr_owner_space, 0,
  987. nentries * sizeof(struct ce_desc));
  988. dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr);
  989. dest_ring->sw_index &= dest_ring->nentries_mask;
  990. dest_ring->write_index =
  991. ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
  992. dest_ring->write_index &= dest_ring->nentries_mask;
  993. ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr,
  994. dest_ring->base_addr_ce_space);
  995. ath10k_ce_dest_ring_size_set(ar, ctrl_addr, nentries);
  996. ath10k_ce_dest_ring_byte_swap_set(ar, ctrl_addr, 0);
  997. ath10k_ce_dest_ring_lowmark_set(ar, ctrl_addr, 0);
  998. ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, nentries);
  999. ath10k_dbg(ar, ATH10K_DBG_BOOT,
  1000. "boot ce dest ring id %d entries %d base_addr %pK\n",
  1001. ce_id, nentries, dest_ring->base_addr_owner_space);
  1002. return 0;
  1003. }
  1004. static struct ath10k_ce_ring *
  1005. ath10k_ce_alloc_src_ring(struct ath10k *ar, unsigned int ce_id,
  1006. const struct ce_attr *attr)
  1007. {
  1008. struct ath10k_ce_ring *src_ring;
  1009. u32 nentries = attr->src_nentries;
  1010. dma_addr_t base_addr;
  1011. nentries = roundup_pow_of_two(nentries);
  1012. src_ring = kzalloc(sizeof(*src_ring) +
  1013. (nentries *
  1014. sizeof(*src_ring->per_transfer_context)),
  1015. GFP_KERNEL);
  1016. if (src_ring == NULL)
  1017. return ERR_PTR(-ENOMEM);
  1018. src_ring->nentries = nentries;
  1019. src_ring->nentries_mask = nentries - 1;
  1020. /*
  1021. * Legacy platforms that do not support cache
  1022. * coherent DMA are unsupported
  1023. */
  1024. src_ring->base_addr_owner_space_unaligned =
  1025. dma_alloc_coherent(ar->dev,
  1026. (nentries * sizeof(struct ce_desc) +
  1027. CE_DESC_RING_ALIGN),
  1028. &base_addr, GFP_KERNEL);
  1029. if (!src_ring->base_addr_owner_space_unaligned) {
  1030. kfree(src_ring);
  1031. return ERR_PTR(-ENOMEM);
  1032. }
  1033. src_ring->base_addr_ce_space_unaligned = base_addr;
  1034. src_ring->base_addr_owner_space =
  1035. PTR_ALIGN(src_ring->base_addr_owner_space_unaligned,
  1036. CE_DESC_RING_ALIGN);
  1037. src_ring->base_addr_ce_space =
  1038. ALIGN(src_ring->base_addr_ce_space_unaligned,
  1039. CE_DESC_RING_ALIGN);
  1040. return src_ring;
  1041. }
  1042. static struct ath10k_ce_ring *
  1043. ath10k_ce_alloc_src_ring_64(struct ath10k *ar, unsigned int ce_id,
  1044. const struct ce_attr *attr)
  1045. {
  1046. struct ath10k_ce_ring *src_ring;
  1047. u32 nentries = attr->src_nentries;
  1048. dma_addr_t base_addr;
  1049. nentries = roundup_pow_of_two(nentries);
  1050. src_ring = kzalloc(sizeof(*src_ring) +
  1051. (nentries *
  1052. sizeof(*src_ring->per_transfer_context)),
  1053. GFP_KERNEL);
  1054. if (!src_ring)
  1055. return ERR_PTR(-ENOMEM);
  1056. src_ring->nentries = nentries;
  1057. src_ring->nentries_mask = nentries - 1;
  1058. /* Legacy platforms that do not support cache
  1059. * coherent DMA are unsupported
  1060. */
  1061. src_ring->base_addr_owner_space_unaligned =
  1062. dma_alloc_coherent(ar->dev,
  1063. (nentries * sizeof(struct ce_desc_64) +
  1064. CE_DESC_RING_ALIGN),
  1065. &base_addr, GFP_KERNEL);
  1066. if (!src_ring->base_addr_owner_space_unaligned) {
  1067. kfree(src_ring);
  1068. return ERR_PTR(-ENOMEM);
  1069. }
  1070. src_ring->base_addr_ce_space_unaligned = base_addr;
  1071. src_ring->base_addr_owner_space =
  1072. PTR_ALIGN(src_ring->base_addr_owner_space_unaligned,
  1073. CE_DESC_RING_ALIGN);
  1074. src_ring->base_addr_ce_space =
  1075. ALIGN(src_ring->base_addr_ce_space_unaligned,
  1076. CE_DESC_RING_ALIGN);
  1077. return src_ring;
  1078. }
  1079. static struct ath10k_ce_ring *
  1080. ath10k_ce_alloc_dest_ring(struct ath10k *ar, unsigned int ce_id,
  1081. const struct ce_attr *attr)
  1082. {
  1083. struct ath10k_ce_ring *dest_ring;
  1084. u32 nentries;
  1085. dma_addr_t base_addr;
  1086. nentries = roundup_pow_of_two(attr->dest_nentries);
  1087. dest_ring = kzalloc(sizeof(*dest_ring) +
  1088. (nentries *
  1089. sizeof(*dest_ring->per_transfer_context)),
  1090. GFP_KERNEL);
  1091. if (dest_ring == NULL)
  1092. return ERR_PTR(-ENOMEM);
  1093. dest_ring->nentries = nentries;
  1094. dest_ring->nentries_mask = nentries - 1;
  1095. /*
  1096. * Legacy platforms that do not support cache
  1097. * coherent DMA are unsupported
  1098. */
  1099. dest_ring->base_addr_owner_space_unaligned =
  1100. dma_zalloc_coherent(ar->dev,
  1101. (nentries * sizeof(struct ce_desc) +
  1102. CE_DESC_RING_ALIGN),
  1103. &base_addr, GFP_KERNEL);
  1104. if (!dest_ring->base_addr_owner_space_unaligned) {
  1105. kfree(dest_ring);
  1106. return ERR_PTR(-ENOMEM);
  1107. }
  1108. dest_ring->base_addr_ce_space_unaligned = base_addr;
  1109. dest_ring->base_addr_owner_space =
  1110. PTR_ALIGN(dest_ring->base_addr_owner_space_unaligned,
  1111. CE_DESC_RING_ALIGN);
  1112. dest_ring->base_addr_ce_space =
  1113. ALIGN(dest_ring->base_addr_ce_space_unaligned,
  1114. CE_DESC_RING_ALIGN);
  1115. return dest_ring;
  1116. }
  1117. static struct ath10k_ce_ring *
  1118. ath10k_ce_alloc_dest_ring_64(struct ath10k *ar, unsigned int ce_id,
  1119. const struct ce_attr *attr)
  1120. {
  1121. struct ath10k_ce_ring *dest_ring;
  1122. u32 nentries;
  1123. dma_addr_t base_addr;
  1124. nentries = roundup_pow_of_two(attr->dest_nentries);
  1125. dest_ring = kzalloc(sizeof(*dest_ring) +
  1126. (nentries *
  1127. sizeof(*dest_ring->per_transfer_context)),
  1128. GFP_KERNEL);
  1129. if (!dest_ring)
  1130. return ERR_PTR(-ENOMEM);
  1131. dest_ring->nentries = nentries;
  1132. dest_ring->nentries_mask = nentries - 1;
  1133. /* Legacy platforms that do not support cache
  1134. * coherent DMA are unsupported
  1135. */
  1136. dest_ring->base_addr_owner_space_unaligned =
  1137. dma_alloc_coherent(ar->dev,
  1138. (nentries * sizeof(struct ce_desc_64) +
  1139. CE_DESC_RING_ALIGN),
  1140. &base_addr, GFP_KERNEL);
  1141. if (!dest_ring->base_addr_owner_space_unaligned) {
  1142. kfree(dest_ring);
  1143. return ERR_PTR(-ENOMEM);
  1144. }
  1145. dest_ring->base_addr_ce_space_unaligned = base_addr;
  1146. /* Correctly initialize memory to 0 to prevent garbage
  1147. * data crashing system when download firmware
  1148. */
  1149. memset(dest_ring->base_addr_owner_space_unaligned, 0,
  1150. nentries * sizeof(struct ce_desc_64) + CE_DESC_RING_ALIGN);
  1151. dest_ring->base_addr_owner_space =
  1152. PTR_ALIGN(dest_ring->base_addr_owner_space_unaligned,
  1153. CE_DESC_RING_ALIGN);
  1154. dest_ring->base_addr_ce_space =
  1155. ALIGN(dest_ring->base_addr_ce_space_unaligned,
  1156. CE_DESC_RING_ALIGN);
  1157. return dest_ring;
  1158. }
  1159. /*
  1160. * Initialize a Copy Engine based on caller-supplied attributes.
  1161. * This may be called once to initialize both source and destination
  1162. * rings or it may be called twice for separate source and destination
  1163. * initialization. It may be that only one side or the other is
  1164. * initialized by software/firmware.
  1165. */
  1166. int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
  1167. const struct ce_attr *attr)
  1168. {
  1169. int ret;
  1170. if (attr->src_nentries) {
  1171. ret = ath10k_ce_init_src_ring(ar, ce_id, attr);
  1172. if (ret) {
  1173. ath10k_err(ar, "Failed to initialize CE src ring for ID: %d (%d)\n",
  1174. ce_id, ret);
  1175. return ret;
  1176. }
  1177. }
  1178. if (attr->dest_nentries) {
  1179. ret = ath10k_ce_init_dest_ring(ar, ce_id, attr);
  1180. if (ret) {
  1181. ath10k_err(ar, "Failed to initialize CE dest ring for ID: %d (%d)\n",
  1182. ce_id, ret);
  1183. return ret;
  1184. }
  1185. }
  1186. return 0;
  1187. }
  1188. static void ath10k_ce_deinit_src_ring(struct ath10k *ar, unsigned int ce_id)
  1189. {
  1190. u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  1191. ath10k_ce_src_ring_base_addr_set(ar, ctrl_addr, 0);
  1192. ath10k_ce_src_ring_size_set(ar, ctrl_addr, 0);
  1193. ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, 0);
  1194. ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, 0);
  1195. }
  1196. static void ath10k_ce_deinit_dest_ring(struct ath10k *ar, unsigned int ce_id)
  1197. {
  1198. u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  1199. ath10k_ce_dest_ring_base_addr_set(ar, ctrl_addr, 0);
  1200. ath10k_ce_dest_ring_size_set(ar, ctrl_addr, 0);
  1201. ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, 0);
  1202. }
  1203. void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id)
  1204. {
  1205. ath10k_ce_deinit_src_ring(ar, ce_id);
  1206. ath10k_ce_deinit_dest_ring(ar, ce_id);
  1207. }
  1208. static void _ath10k_ce_free_pipe(struct ath10k *ar, int ce_id)
  1209. {
  1210. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  1211. struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
  1212. if (ce_state->src_ring) {
  1213. dma_free_coherent(ar->dev,
  1214. (ce_state->src_ring->nentries *
  1215. sizeof(struct ce_desc) +
  1216. CE_DESC_RING_ALIGN),
  1217. ce_state->src_ring->base_addr_owner_space,
  1218. ce_state->src_ring->base_addr_ce_space);
  1219. kfree(ce_state->src_ring);
  1220. }
  1221. if (ce_state->dest_ring) {
  1222. dma_free_coherent(ar->dev,
  1223. (ce_state->dest_ring->nentries *
  1224. sizeof(struct ce_desc) +
  1225. CE_DESC_RING_ALIGN),
  1226. ce_state->dest_ring->base_addr_owner_space,
  1227. ce_state->dest_ring->base_addr_ce_space);
  1228. kfree(ce_state->dest_ring);
  1229. }
  1230. ce_state->src_ring = NULL;
  1231. ce_state->dest_ring = NULL;
  1232. }
  1233. static void _ath10k_ce_free_pipe_64(struct ath10k *ar, int ce_id)
  1234. {
  1235. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  1236. struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
  1237. if (ce_state->src_ring) {
  1238. dma_free_coherent(ar->dev,
  1239. (ce_state->src_ring->nentries *
  1240. sizeof(struct ce_desc_64) +
  1241. CE_DESC_RING_ALIGN),
  1242. ce_state->src_ring->base_addr_owner_space,
  1243. ce_state->src_ring->base_addr_ce_space);
  1244. kfree(ce_state->src_ring);
  1245. }
  1246. if (ce_state->dest_ring) {
  1247. dma_free_coherent(ar->dev,
  1248. (ce_state->dest_ring->nentries *
  1249. sizeof(struct ce_desc_64) +
  1250. CE_DESC_RING_ALIGN),
  1251. ce_state->dest_ring->base_addr_owner_space,
  1252. ce_state->dest_ring->base_addr_ce_space);
  1253. kfree(ce_state->dest_ring);
  1254. }
  1255. ce_state->src_ring = NULL;
  1256. ce_state->dest_ring = NULL;
  1257. }
  1258. void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id)
  1259. {
  1260. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  1261. struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
  1262. ce_state->ops->ce_free_pipe(ar, ce_id);
  1263. }
  1264. void ath10k_ce_dump_registers(struct ath10k *ar,
  1265. struct ath10k_fw_crash_data *crash_data)
  1266. {
  1267. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  1268. struct ath10k_ce_crash_data ce_data;
  1269. u32 addr, id;
  1270. lockdep_assert_held(&ar->data_lock);
  1271. ath10k_err(ar, "Copy Engine register dump:\n");
  1272. spin_lock_bh(&ce->ce_lock);
  1273. for (id = 0; id < CE_COUNT; id++) {
  1274. addr = ath10k_ce_base_address(ar, id);
  1275. ce_data.base_addr = cpu_to_le32(addr);
  1276. ce_data.src_wr_idx =
  1277. cpu_to_le32(ath10k_ce_src_ring_write_index_get(ar, addr));
  1278. ce_data.src_r_idx =
  1279. cpu_to_le32(ath10k_ce_src_ring_read_index_get(ar, addr));
  1280. ce_data.dst_wr_idx =
  1281. cpu_to_le32(ath10k_ce_dest_ring_write_index_get(ar, addr));
  1282. ce_data.dst_r_idx =
  1283. cpu_to_le32(ath10k_ce_dest_ring_read_index_get(ar, addr));
  1284. if (crash_data)
  1285. crash_data->ce_crash_data[id] = ce_data;
  1286. ath10k_err(ar, "[%02d]: 0x%08x %3u %3u %3u %3u", id,
  1287. le32_to_cpu(ce_data.base_addr),
  1288. le32_to_cpu(ce_data.src_wr_idx),
  1289. le32_to_cpu(ce_data.src_r_idx),
  1290. le32_to_cpu(ce_data.dst_wr_idx),
  1291. le32_to_cpu(ce_data.dst_r_idx));
  1292. }
  1293. spin_unlock_bh(&ce->ce_lock);
  1294. }
  1295. static const struct ath10k_ce_ops ce_ops = {
  1296. .ce_alloc_src_ring = ath10k_ce_alloc_src_ring,
  1297. .ce_alloc_dst_ring = ath10k_ce_alloc_dest_ring,
  1298. .ce_rx_post_buf = __ath10k_ce_rx_post_buf,
  1299. .ce_completed_recv_next_nolock = _ath10k_ce_completed_recv_next_nolock,
  1300. .ce_revoke_recv_next = _ath10k_ce_revoke_recv_next,
  1301. .ce_extract_desc_data = ath10k_ce_extract_desc_data,
  1302. .ce_free_pipe = _ath10k_ce_free_pipe,
  1303. .ce_send_nolock = _ath10k_ce_send_nolock,
  1304. };
  1305. static const struct ath10k_ce_ops ce_64_ops = {
  1306. .ce_alloc_src_ring = ath10k_ce_alloc_src_ring_64,
  1307. .ce_alloc_dst_ring = ath10k_ce_alloc_dest_ring_64,
  1308. .ce_rx_post_buf = __ath10k_ce_rx_post_buf_64,
  1309. .ce_completed_recv_next_nolock =
  1310. _ath10k_ce_completed_recv_next_nolock_64,
  1311. .ce_revoke_recv_next = _ath10k_ce_revoke_recv_next_64,
  1312. .ce_extract_desc_data = ath10k_ce_extract_desc_data_64,
  1313. .ce_free_pipe = _ath10k_ce_free_pipe_64,
  1314. .ce_send_nolock = _ath10k_ce_send_nolock_64,
  1315. };
  1316. static void ath10k_ce_set_ops(struct ath10k *ar,
  1317. struct ath10k_ce_pipe *ce_state)
  1318. {
  1319. switch (ar->hw_rev) {
  1320. case ATH10K_HW_WCN3990:
  1321. ce_state->ops = &ce_64_ops;
  1322. break;
  1323. default:
  1324. ce_state->ops = &ce_ops;
  1325. break;
  1326. }
  1327. }
  1328. int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
  1329. const struct ce_attr *attr)
  1330. {
  1331. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  1332. struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
  1333. int ret;
  1334. ath10k_ce_set_ops(ar, ce_state);
  1335. /* Make sure there's enough CE ringbuffer entries for HTT TX to avoid
  1336. * additional TX locking checks.
  1337. *
  1338. * For the lack of a better place do the check here.
  1339. */
  1340. BUILD_BUG_ON(2 * TARGET_NUM_MSDU_DESC >
  1341. (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
  1342. BUILD_BUG_ON(2 * TARGET_10_4_NUM_MSDU_DESC_PFC >
  1343. (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
  1344. BUILD_BUG_ON(2 * TARGET_TLV_NUM_MSDU_DESC >
  1345. (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
  1346. ce_state->ar = ar;
  1347. ce_state->id = ce_id;
  1348. ce_state->ctrl_addr = ath10k_ce_base_address(ar, ce_id);
  1349. ce_state->attr_flags = attr->flags;
  1350. ce_state->src_sz_max = attr->src_sz_max;
  1351. if (attr->src_nentries)
  1352. ce_state->send_cb = attr->send_cb;
  1353. if (attr->dest_nentries)
  1354. ce_state->recv_cb = attr->recv_cb;
  1355. if (attr->src_nentries) {
  1356. ce_state->src_ring =
  1357. ce_state->ops->ce_alloc_src_ring(ar, ce_id, attr);
  1358. if (IS_ERR(ce_state->src_ring)) {
  1359. ret = PTR_ERR(ce_state->src_ring);
  1360. ath10k_err(ar, "failed to alloc CE src ring %d: %d\n",
  1361. ce_id, ret);
  1362. ce_state->src_ring = NULL;
  1363. return ret;
  1364. }
  1365. }
  1366. if (attr->dest_nentries) {
  1367. ce_state->dest_ring = ce_state->ops->ce_alloc_dst_ring(ar,
  1368. ce_id,
  1369. attr);
  1370. if (IS_ERR(ce_state->dest_ring)) {
  1371. ret = PTR_ERR(ce_state->dest_ring);
  1372. ath10k_err(ar, "failed to alloc CE dest ring %d: %d\n",
  1373. ce_id, ret);
  1374. ce_state->dest_ring = NULL;
  1375. return ret;
  1376. }
  1377. }
  1378. return 0;
  1379. }