hal_api.h 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354
  1. /*
  2. * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _HAL_API_H_
  19. #define _HAL_API_H_
  20. #include "qdf_types.h"
  21. #include "qdf_util.h"
  22. #include "qdf_atomic.h"
  23. #include "hal_internal.h"
  24. #include "hif.h"
  25. #include "hif_io32.h"
  26. #include "qdf_platform.h"
  27. /* calculate the register address offset from bar0 of shadow register x */
  28. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490)
  29. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x000008FC
  30. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  31. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  32. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  33. #elif defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCN9000)
  34. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x00003024
  35. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  36. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  37. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  38. #elif defined(QCA_WIFI_QCA6750)
  39. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x00000504
  40. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  41. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  42. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  43. #else
  44. #define SHADOW_REGISTER(x) 0
  45. #endif /* QCA_WIFI_QCA6390 || QCA_WIFI_QCA6490 || QCA_WIFI_QCA6750 */
  46. #define MAX_UNWINDOWED_ADDRESS 0x80000
  47. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490) || \
  48. defined(QCA_WIFI_QCN9000) || defined(QCA_WIFI_QCA6750)
  49. #define WINDOW_ENABLE_BIT 0x40000000
  50. #else
  51. #define WINDOW_ENABLE_BIT 0x80000000
  52. #endif
  53. #define WINDOW_REG_ADDRESS 0x310C
  54. #define WINDOW_SHIFT 19
  55. #define WINDOW_VALUE_MASK 0x3F
  56. #define WINDOW_START MAX_UNWINDOWED_ADDRESS
  57. #define WINDOW_RANGE_MASK 0x7FFFF
  58. /*
  59. * BAR + 4K is always accessible, any access outside this
  60. * space requires force wake procedure.
  61. * OFFSET = 4K - 32 bytes = 0xFE0
  62. */
  63. #define MAPPED_REF_OFF 0xFE0
  64. #ifdef ENABLE_VERBOSE_DEBUG
  65. static inline void
  66. hal_set_verbose_debug(bool flag)
  67. {
  68. is_hal_verbose_debug_enabled = flag;
  69. }
  70. #endif
  71. #ifdef ENABLE_HAL_SOC_STATS
  72. #define HAL_STATS_INC(_handle, _field, _delta) \
  73. { \
  74. if (likely(_handle)) \
  75. _handle->stats._field += _delta; \
  76. }
  77. #else
  78. #define HAL_STATS_INC(_handle, _field, _delta)
  79. #endif
  80. #ifdef ENABLE_HAL_REG_WR_HISTORY
  81. #define HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, wr_val, rd_val) \
  82. hal_reg_wr_fail_history_add(hal_soc, offset, wr_val, rd_val)
  83. void hal_reg_wr_fail_history_add(struct hal_soc *hal_soc,
  84. uint32_t offset,
  85. uint32_t wr_val,
  86. uint32_t rd_val);
  87. static inline int hal_history_get_next_index(qdf_atomic_t *table_index,
  88. int array_size)
  89. {
  90. int record_index = qdf_atomic_inc_return(table_index);
  91. return record_index & (array_size - 1);
  92. }
  93. #else
  94. #define HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, wr_val, rd_val) \
  95. hal_err("write failed at reg offset 0x%x, write 0x%x read 0x%x\n", \
  96. offset, \
  97. wr_val, \
  98. rd_val)
  99. #endif
  100. /**
  101. * hal_reg_write_result_check() - check register writing result
  102. * @hal_soc: HAL soc handle
  103. * @offset: register offset to read
  104. * @exp_val: the expected value of register
  105. * @ret_confirm: result confirm flag
  106. *
  107. * Return: none
  108. */
  109. static inline void hal_reg_write_result_check(struct hal_soc *hal_soc,
  110. uint32_t offset,
  111. uint32_t exp_val)
  112. {
  113. uint32_t value;
  114. value = qdf_ioread32(hal_soc->dev_base_addr + offset);
  115. if (exp_val != value) {
  116. HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, exp_val, value);
  117. HAL_STATS_INC(hal_soc, reg_write_fail, 1);
  118. }
  119. }
  120. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) || \
  121. !defined(QCA_WIFI_QCA6750)
  122. static inline void hal_lock_reg_access(struct hal_soc *soc,
  123. unsigned long *flags)
  124. {
  125. qdf_spin_lock_irqsave(&soc->register_access_lock);
  126. }
  127. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  128. unsigned long *flags)
  129. {
  130. qdf_spin_unlock_irqrestore(&soc->register_access_lock);
  131. }
  132. #else
  133. static inline void hal_lock_reg_access(struct hal_soc *soc,
  134. unsigned long *flags)
  135. {
  136. pld_lock_reg_window(soc->qdf_dev->dev, flags);
  137. }
  138. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  139. unsigned long *flags)
  140. {
  141. pld_unlock_reg_window(soc->qdf_dev->dev, flags);
  142. }
  143. #endif
  144. #ifdef PCIE_REG_WINDOW_LOCAL_NO_CACHE
  145. /**
  146. * hal_select_window_confirm() - write remap window register and
  147. check writing result
  148. *
  149. */
  150. static inline void hal_select_window_confirm(struct hal_soc *hal_soc,
  151. uint32_t offset)
  152. {
  153. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  154. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  155. WINDOW_ENABLE_BIT | window);
  156. hal_soc->register_window = window;
  157. hal_reg_write_result_check(hal_soc, WINDOW_REG_ADDRESS,
  158. WINDOW_ENABLE_BIT | window);
  159. }
  160. #else
  161. static inline void hal_select_window_confirm(struct hal_soc *hal_soc,
  162. uint32_t offset)
  163. {
  164. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  165. if (window != hal_soc->register_window) {
  166. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  167. WINDOW_ENABLE_BIT | window);
  168. hal_soc->register_window = window;
  169. hal_reg_write_result_check(
  170. hal_soc,
  171. WINDOW_REG_ADDRESS,
  172. WINDOW_ENABLE_BIT | window);
  173. }
  174. }
  175. #endif
  176. static inline qdf_iomem_t hal_get_window_address(struct hal_soc *hal_soc,
  177. qdf_iomem_t addr)
  178. {
  179. return hal_soc->ops->hal_get_window_address(hal_soc, addr);
  180. }
  181. static inline void hal_tx_init_cmd_credit_ring(hal_soc_handle_t hal_soc_hdl,
  182. hal_ring_handle_t hal_ring_hdl)
  183. {
  184. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  185. return hal_soc->ops->hal_tx_init_cmd_credit_ring(hal_soc_hdl,
  186. hal_ring_hdl);
  187. }
  188. /**
  189. * hal_write32_mb() - Access registers to update configuration
  190. * @hal_soc: hal soc handle
  191. * @offset: offset address from the BAR
  192. * @value: value to write
  193. *
  194. * Return: None
  195. *
  196. * Description: Register address space is split below:
  197. * SHADOW REGION UNWINDOWED REGION WINDOWED REGION
  198. * |--------------------|-------------------|------------------|
  199. * BAR NO FORCE WAKE BAR+4K FORCE WAKE BAR+512K FORCE WAKE
  200. *
  201. * 1. Any access to the shadow region, doesn't need force wake
  202. * and windowing logic to access.
  203. * 2. Any access beyond BAR + 4K:
  204. * If init_phase enabled, no force wake is needed and access
  205. * should be based on windowed or unwindowed access.
  206. * If init_phase disabled, force wake is needed and access
  207. * should be based on windowed or unwindowed access.
  208. *
  209. * note1: WINDOW_RANGE_MASK = (1 << WINDOW_SHIFT) -1
  210. * note2: 1 << WINDOW_SHIFT = MAX_UNWINDOWED_ADDRESS
  211. * note3: WINDOW_VALUE_MASK = big enough that trying to write past
  212. * that window would be a bug
  213. */
  214. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) && \
  215. !defined(QCA_WIFI_QCA6750)
  216. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  217. uint32_t value)
  218. {
  219. unsigned long flags;
  220. qdf_iomem_t new_addr;
  221. if (!hal_soc->use_register_windowing ||
  222. offset < MAX_UNWINDOWED_ADDRESS) {
  223. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  224. } else if (hal_soc->static_window_map) {
  225. new_addr = hal_get_window_address(hal_soc,
  226. hal_soc->dev_base_addr + offset);
  227. qdf_iowrite32(new_addr, value);
  228. } else {
  229. hal_lock_reg_access(hal_soc, &flags);
  230. hal_select_window_confirm(hal_soc, offset);
  231. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  232. (offset & WINDOW_RANGE_MASK), value);
  233. hal_unlock_reg_access(hal_soc, &flags);
  234. }
  235. }
  236. #define hal_write32_mb_confirm(_hal_soc, _offset, _value) \
  237. hal_write32_mb(_hal_soc, _offset, _value)
  238. #else
  239. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  240. uint32_t value)
  241. {
  242. int ret;
  243. unsigned long flags;
  244. qdf_iomem_t new_addr;
  245. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  246. hal_soc->hif_handle))) {
  247. hal_err_rl("target access is not allowed");
  248. return;
  249. }
  250. /* Region < BAR + 4K can be directly accessed */
  251. if (offset < MAPPED_REF_OFF) {
  252. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  253. return;
  254. }
  255. /* Region greater than BAR + 4K */
  256. if (!hal_soc->init_phase) {
  257. ret = hif_force_wake_request(hal_soc->hif_handle);
  258. if (ret) {
  259. hal_err("Wake up request failed");
  260. qdf_check_state_before_panic();
  261. return;
  262. }
  263. }
  264. if (!hal_soc->use_register_windowing ||
  265. offset < MAX_UNWINDOWED_ADDRESS) {
  266. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  267. } else if (hal_soc->static_window_map) {
  268. new_addr = hal_get_window_address(
  269. hal_soc,
  270. hal_soc->dev_base_addr + offset);
  271. qdf_iowrite32(new_addr, value);
  272. } else {
  273. hal_lock_reg_access(hal_soc, &flags);
  274. hal_select_window_confirm(hal_soc, offset);
  275. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  276. (offset & WINDOW_RANGE_MASK), value);
  277. hal_unlock_reg_access(hal_soc, &flags);
  278. }
  279. if (!hal_soc->init_phase) {
  280. ret = hif_force_wake_release(hal_soc->hif_handle);
  281. if (ret) {
  282. hal_err("Wake up release failed");
  283. qdf_check_state_before_panic();
  284. return;
  285. }
  286. }
  287. }
  288. /**
  289. * hal_write32_mb_confirm() - write register and check wirting result
  290. *
  291. */
  292. static inline void hal_write32_mb_confirm(struct hal_soc *hal_soc,
  293. uint32_t offset,
  294. uint32_t value)
  295. {
  296. int ret;
  297. unsigned long flags;
  298. qdf_iomem_t new_addr;
  299. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  300. hal_soc->hif_handle))) {
  301. hal_err_rl("target access is not allowed");
  302. return;
  303. }
  304. /* Region < BAR + 4K can be directly accessed */
  305. if (offset < MAPPED_REF_OFF) {
  306. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  307. return;
  308. }
  309. /* Region greater than BAR + 4K */
  310. if (!hal_soc->init_phase) {
  311. ret = hif_force_wake_request(hal_soc->hif_handle);
  312. if (ret) {
  313. hal_err("Wake up request failed");
  314. qdf_check_state_before_panic();
  315. return;
  316. }
  317. }
  318. if (!hal_soc->use_register_windowing ||
  319. offset < MAX_UNWINDOWED_ADDRESS) {
  320. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  321. hal_reg_write_result_check(hal_soc, offset,
  322. value);
  323. } else if (hal_soc->static_window_map) {
  324. new_addr = hal_get_window_address(
  325. hal_soc,
  326. hal_soc->dev_base_addr + offset);
  327. qdf_iowrite32(new_addr, value);
  328. hal_reg_write_result_check(hal_soc,
  329. new_addr - hal_soc->dev_base_addr,
  330. value);
  331. } else {
  332. hal_lock_reg_access(hal_soc, &flags);
  333. hal_select_window_confirm(hal_soc, offset);
  334. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  335. (offset & WINDOW_RANGE_MASK), value);
  336. hal_reg_write_result_check(
  337. hal_soc,
  338. WINDOW_START + (offset & WINDOW_RANGE_MASK),
  339. value);
  340. hal_unlock_reg_access(hal_soc, &flags);
  341. }
  342. if (!hal_soc->init_phase) {
  343. ret = hif_force_wake_release(hal_soc->hif_handle);
  344. if (ret) {
  345. hal_err("Wake up release failed");
  346. qdf_check_state_before_panic();
  347. return;
  348. }
  349. }
  350. }
  351. #endif
  352. /**
  353. * hal_write_address_32_mb - write a value to a register
  354. *
  355. */
  356. static inline
  357. void hal_write_address_32_mb(struct hal_soc *hal_soc,
  358. qdf_iomem_t addr, uint32_t value, bool wr_confirm)
  359. {
  360. uint32_t offset;
  361. if (!hal_soc->use_register_windowing)
  362. return qdf_iowrite32(addr, value);
  363. offset = addr - hal_soc->dev_base_addr;
  364. if (qdf_unlikely(wr_confirm))
  365. hal_write32_mb_confirm(hal_soc, offset, value);
  366. else
  367. hal_write32_mb(hal_soc, offset, value);
  368. }
  369. #ifdef DP_HAL_MULTIWINDOW_DIRECT_ACCESS
  370. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  371. struct hal_srng *srng,
  372. void __iomem *addr,
  373. uint32_t value)
  374. {
  375. qdf_iowrite32(addr, value);
  376. }
  377. #elif defined(FEATURE_HAL_DELAYED_REG_WRITE)
  378. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  379. struct hal_srng *srng,
  380. void __iomem *addr,
  381. uint32_t value)
  382. {
  383. hal_delayed_reg_write(hal_soc, srng, addr, value);
  384. }
  385. #else
  386. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  387. struct hal_srng *srng,
  388. void __iomem *addr,
  389. uint32_t value)
  390. {
  391. hal_write_address_32_mb(hal_soc, addr, value, false);
  392. }
  393. #endif
  394. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) && \
  395. !defined(QCA_WIFI_QCA6750)
  396. /**
  397. * hal_read32_mb() - Access registers to read configuration
  398. * @hal_soc: hal soc handle
  399. * @offset: offset address from the BAR
  400. * @value: value to write
  401. *
  402. * Description: Register address space is split below:
  403. * SHADOW REGION UNWINDOWED REGION WINDOWED REGION
  404. * |--------------------|-------------------|------------------|
  405. * BAR NO FORCE WAKE BAR+4K FORCE WAKE BAR+512K FORCE WAKE
  406. *
  407. * 1. Any access to the shadow region, doesn't need force wake
  408. * and windowing logic to access.
  409. * 2. Any access beyond BAR + 4K:
  410. * If init_phase enabled, no force wake is needed and access
  411. * should be based on windowed or unwindowed access.
  412. * If init_phase disabled, force wake is needed and access
  413. * should be based on windowed or unwindowed access.
  414. *
  415. * Return: < 0 for failure/>= 0 for success
  416. */
  417. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  418. {
  419. uint32_t ret;
  420. unsigned long flags;
  421. qdf_iomem_t new_addr;
  422. if (!hal_soc->use_register_windowing ||
  423. offset < MAX_UNWINDOWED_ADDRESS) {
  424. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  425. } else if (hal_soc->static_window_map) {
  426. new_addr = hal_get_window_address(hal_soc, hal_soc->dev_base_addr + offset);
  427. return qdf_ioread32(new_addr);
  428. }
  429. hal_lock_reg_access(hal_soc, &flags);
  430. hal_select_window_confirm(hal_soc, offset);
  431. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  432. (offset & WINDOW_RANGE_MASK));
  433. hal_unlock_reg_access(hal_soc, &flags);
  434. return ret;
  435. }
  436. #else
  437. static
  438. uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  439. {
  440. uint32_t ret;
  441. unsigned long flags;
  442. qdf_iomem_t new_addr;
  443. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  444. hal_soc->hif_handle))) {
  445. hal_err_rl("target access is not allowed");
  446. return 0;
  447. }
  448. /* Region < BAR + 4K can be directly accessed */
  449. if (offset < MAPPED_REF_OFF)
  450. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  451. if ((!hal_soc->init_phase) &&
  452. hif_force_wake_request(hal_soc->hif_handle)) {
  453. hal_err("Wake up request failed");
  454. qdf_check_state_before_panic();
  455. return 0;
  456. }
  457. if (!hal_soc->use_register_windowing ||
  458. offset < MAX_UNWINDOWED_ADDRESS) {
  459. ret = qdf_ioread32(hal_soc->dev_base_addr + offset);
  460. } else if (hal_soc->static_window_map) {
  461. new_addr = hal_get_window_address(
  462. hal_soc,
  463. hal_soc->dev_base_addr + offset);
  464. ret = qdf_ioread32(new_addr);
  465. } else {
  466. hal_lock_reg_access(hal_soc, &flags);
  467. hal_select_window_confirm(hal_soc, offset);
  468. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  469. (offset & WINDOW_RANGE_MASK));
  470. hal_unlock_reg_access(hal_soc, &flags);
  471. }
  472. if ((!hal_soc->init_phase) &&
  473. hif_force_wake_release(hal_soc->hif_handle)) {
  474. hal_err("Wake up release failed");
  475. qdf_check_state_before_panic();
  476. return 0;
  477. }
  478. return ret;
  479. }
  480. #endif
  481. /* Max times allowed for register writing retry */
  482. #define HAL_REG_WRITE_RETRY_MAX 5
  483. /* Delay milliseconds for each time retry */
  484. #define HAL_REG_WRITE_RETRY_DELAY 1
  485. /**
  486. * hal_write32_mb_confirm_retry() - write register with confirming and
  487. do retry/recovery if writing failed
  488. * @hal_soc: hal soc handle
  489. * @offset: offset address from the BAR
  490. * @value: value to write
  491. * @recovery: is recovery needed or not.
  492. *
  493. * Write the register value with confirming and read it back, if
  494. * read back value is not as expected, do retry for writing, if
  495. * retry hit max times allowed but still fail, check if recovery
  496. * needed.
  497. *
  498. * Return: None
  499. */
  500. static inline void hal_write32_mb_confirm_retry(struct hal_soc *hal_soc,
  501. uint32_t offset,
  502. uint32_t value,
  503. bool recovery)
  504. {
  505. uint8_t retry_cnt = 0;
  506. uint32_t read_value;
  507. while (retry_cnt <= HAL_REG_WRITE_RETRY_MAX) {
  508. hal_write32_mb_confirm(hal_soc, offset, value);
  509. read_value = hal_read32_mb(hal_soc, offset);
  510. if (qdf_likely(read_value == value))
  511. break;
  512. /* write failed, do retry */
  513. hal_warn("Retry reg offset 0x%x, value 0x%x, read value 0x%x",
  514. offset, value, read_value);
  515. qdf_mdelay(HAL_REG_WRITE_RETRY_DELAY);
  516. retry_cnt++;
  517. }
  518. if (retry_cnt > HAL_REG_WRITE_RETRY_MAX && recovery)
  519. qdf_trigger_self_recovery(NULL, QDF_HAL_REG_WRITE_FAILURE);
  520. }
  521. #ifdef FEATURE_HAL_DELAYED_REG_WRITE
  522. /**
  523. * hal_dump_reg_write_srng_stats() - dump SRNG reg write stats
  524. * @hal_soc: HAL soc handle
  525. *
  526. * Return: none
  527. */
  528. void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl);
  529. /**
  530. * hal_dump_reg_write_stats() - dump reg write stats
  531. * @hal_soc: HAL soc handle
  532. *
  533. * Return: none
  534. */
  535. void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl);
  536. /**
  537. * hal_get_reg_write_pending_work() - get the number of entries
  538. * pending in the workqueue to be processed.
  539. * @hal_soc: HAL soc handle
  540. *
  541. * Returns: the number of entries pending to be processed
  542. */
  543. int hal_get_reg_write_pending_work(void *hal_soc);
  544. #else
  545. static inline void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl)
  546. {
  547. }
  548. static inline void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl)
  549. {
  550. }
  551. static inline int hal_get_reg_write_pending_work(void *hal_soc)
  552. {
  553. return 0;
  554. }
  555. #endif
  556. /**
  557. * hal_read_address_32_mb() - Read 32-bit value from the register
  558. * @soc: soc handle
  559. * @addr: register address to read
  560. *
  561. * Return: 32-bit value
  562. */
  563. static inline
  564. uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  565. qdf_iomem_t addr)
  566. {
  567. uint32_t offset;
  568. uint32_t ret;
  569. if (!soc->use_register_windowing)
  570. return qdf_ioread32(addr);
  571. offset = addr - soc->dev_base_addr;
  572. ret = hal_read32_mb(soc, offset);
  573. return ret;
  574. }
  575. /**
  576. * hal_attach - Initialize HAL layer
  577. * @hif_handle: Opaque HIF handle
  578. * @qdf_dev: QDF device
  579. *
  580. * Return: Opaque HAL SOC handle
  581. * NULL on failure (if given ring is not available)
  582. *
  583. * This function should be called as part of HIF initialization (for accessing
  584. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  585. */
  586. void *hal_attach(struct hif_opaque_softc *hif_handle, qdf_device_t qdf_dev);
  587. /**
  588. * hal_detach - Detach HAL layer
  589. * @hal_soc: HAL SOC handle
  590. *
  591. * This function should be called as part of HIF detach
  592. *
  593. */
  594. extern void hal_detach(void *hal_soc);
  595. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  596. enum hal_ring_type {
  597. REO_DST = 0,
  598. REO_EXCEPTION = 1,
  599. REO_REINJECT = 2,
  600. REO_CMD = 3,
  601. REO_STATUS = 4,
  602. TCL_DATA = 5,
  603. TCL_CMD_CREDIT = 6,
  604. TCL_STATUS = 7,
  605. CE_SRC = 8,
  606. CE_DST = 9,
  607. CE_DST_STATUS = 10,
  608. WBM_IDLE_LINK = 11,
  609. SW2WBM_RELEASE = 12,
  610. WBM2SW_RELEASE = 13,
  611. RXDMA_BUF = 14,
  612. RXDMA_DST = 15,
  613. RXDMA_MONITOR_BUF = 16,
  614. RXDMA_MONITOR_STATUS = 17,
  615. RXDMA_MONITOR_DST = 18,
  616. RXDMA_MONITOR_DESC = 19,
  617. DIR_BUF_RX_DMA_SRC = 20,
  618. #ifdef WLAN_FEATURE_CIF_CFR
  619. WIFI_POS_SRC,
  620. #endif
  621. MAX_RING_TYPES
  622. };
  623. #define HAL_SRNG_LMAC_RING 0x80000000
  624. /* SRNG flags passed in hal_srng_params.flags */
  625. #define HAL_SRNG_MSI_SWAP 0x00000008
  626. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  627. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  628. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  629. #define HAL_SRNG_MSI_INTR 0x00020000
  630. #define HAL_SRNG_CACHED_DESC 0x00040000
  631. #ifdef QCA_WIFI_QCA6490
  632. #define HAL_SRNG_PREFETCH_TIMER 1
  633. #else
  634. #define HAL_SRNG_PREFETCH_TIMER 0
  635. #endif
  636. #define PN_SIZE_24 0
  637. #define PN_SIZE_48 1
  638. #define PN_SIZE_128 2
  639. #ifdef FORCE_WAKE
  640. /**
  641. * hal_set_init_phase() - Indicate initialization of
  642. * datapath rings
  643. * @soc: hal_soc handle
  644. * @init_phase: flag to indicate datapath rings
  645. * initialization status
  646. *
  647. * Return: None
  648. */
  649. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase);
  650. #else
  651. static inline
  652. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase)
  653. {
  654. }
  655. #endif /* FORCE_WAKE */
  656. /**
  657. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  658. * used by callers for calculating the size of memory to be allocated before
  659. * calling hal_srng_setup to setup the ring
  660. *
  661. * @hal_soc: Opaque HAL SOC handle
  662. * @ring_type: one of the types from hal_ring_type
  663. *
  664. */
  665. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  666. /**
  667. * hal_srng_max_entries - Returns maximum possible number of ring entries
  668. * @hal_soc: Opaque HAL SOC handle
  669. * @ring_type: one of the types from hal_ring_type
  670. *
  671. * Return: Maximum number of entries for the given ring_type
  672. */
  673. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  674. void hal_set_low_threshold(hal_ring_handle_t hal_ring_hdl,
  675. uint32_t low_threshold);
  676. /**
  677. * hal_srng_dump - Dump ring status
  678. * @srng: hal srng pointer
  679. */
  680. void hal_srng_dump(struct hal_srng *srng);
  681. /**
  682. * hal_srng_get_dir - Returns the direction of the ring
  683. * @hal_soc: Opaque HAL SOC handle
  684. * @ring_type: one of the types from hal_ring_type
  685. *
  686. * Return: Ring direction
  687. */
  688. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  689. /* HAL memory information */
  690. struct hal_mem_info {
  691. /* dev base virutal addr */
  692. void *dev_base_addr;
  693. /* dev base physical addr */
  694. void *dev_base_paddr;
  695. /* dev base ce virutal addr - applicable only for qca5018 */
  696. /* In qca5018 CE register are outside wcss block */
  697. /* using a separate address space to access CE registers */
  698. void *dev_base_addr_ce;
  699. /* dev base ce physical addr */
  700. void *dev_base_paddr_ce;
  701. /* Remote virtual pointer memory for HW/FW updates */
  702. void *shadow_rdptr_mem_vaddr;
  703. /* Remote physical pointer memory for HW/FW updates */
  704. void *shadow_rdptr_mem_paddr;
  705. /* Shared memory for ring pointer updates from host to FW */
  706. void *shadow_wrptr_mem_vaddr;
  707. /* Shared physical memory for ring pointer updates from host to FW */
  708. void *shadow_wrptr_mem_paddr;
  709. };
  710. /* SRNG parameters to be passed to hal_srng_setup */
  711. struct hal_srng_params {
  712. /* Physical base address of the ring */
  713. qdf_dma_addr_t ring_base_paddr;
  714. /* Virtual base address of the ring */
  715. void *ring_base_vaddr;
  716. /* Number of entries in ring */
  717. uint32_t num_entries;
  718. /* max transfer length */
  719. uint16_t max_buffer_length;
  720. /* MSI Address */
  721. qdf_dma_addr_t msi_addr;
  722. /* MSI data */
  723. uint32_t msi_data;
  724. /* Interrupt timer threshold – in micro seconds */
  725. uint32_t intr_timer_thres_us;
  726. /* Interrupt batch counter threshold – in number of ring entries */
  727. uint32_t intr_batch_cntr_thres_entries;
  728. /* Low threshold – in number of ring entries
  729. * (valid for src rings only)
  730. */
  731. uint32_t low_threshold;
  732. /* Misc flags */
  733. uint32_t flags;
  734. /* Unique ring id */
  735. uint8_t ring_id;
  736. /* Source or Destination ring */
  737. enum hal_srng_dir ring_dir;
  738. /* Size of ring entry */
  739. uint32_t entry_size;
  740. /* hw register base address */
  741. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  742. /* prefetch timer config - in micro seconds */
  743. uint32_t prefetch_timer;
  744. };
  745. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  746. * @hal_soc: hal handle
  747. *
  748. * Return: QDF_STATUS_OK on success
  749. */
  750. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  751. /* hal_set_one_shadow_config() - add a config for the specified ring
  752. * @hal_soc: hal handle
  753. * @ring_type: ring type
  754. * @ring_num: ring num
  755. *
  756. * The ring type and ring num uniquely specify the ring. After this call,
  757. * the hp/tp will be added as the next entry int the shadow register
  758. * configuration table. The hal code will use the shadow register address
  759. * in place of the hp/tp address.
  760. *
  761. * This function is exposed, so that the CE module can skip configuring shadow
  762. * registers for unused ring and rings assigned to the firmware.
  763. *
  764. * Return: QDF_STATUS_OK on success
  765. */
  766. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  767. int ring_num);
  768. /**
  769. * hal_get_shadow_config() - retrieve the config table
  770. * @hal_soc: hal handle
  771. * @shadow_config: will point to the table after
  772. * @num_shadow_registers_configured: will contain the number of valid entries
  773. */
  774. extern void hal_get_shadow_config(void *hal_soc,
  775. struct pld_shadow_reg_v2_cfg **shadow_config,
  776. int *num_shadow_registers_configured);
  777. /**
  778. * hal_srng_setup - Initialize HW SRNG ring.
  779. *
  780. * @hal_soc: Opaque HAL SOC handle
  781. * @ring_type: one of the types from hal_ring_type
  782. * @ring_num: Ring number if there are multiple rings of
  783. * same type (staring from 0)
  784. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  785. * @ring_params: SRNG ring params in hal_srng_params structure.
  786. * Callers are expected to allocate contiguous ring memory of size
  787. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  788. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  789. * structure. Ring base address should be 8 byte aligned and size of each ring
  790. * entry should be queried using the API hal_srng_get_entrysize
  791. *
  792. * Return: Opaque pointer to ring on success
  793. * NULL on failure (if given ring is not available)
  794. */
  795. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  796. int mac_id, struct hal_srng_params *ring_params);
  797. /* Remapping ids of REO rings */
  798. #define REO_REMAP_TCL 0
  799. #define REO_REMAP_SW1 1
  800. #define REO_REMAP_SW2 2
  801. #define REO_REMAP_SW3 3
  802. #define REO_REMAP_SW4 4
  803. #define REO_REMAP_RELEASE 5
  804. #define REO_REMAP_FW 6
  805. #define REO_REMAP_UNUSED 7
  806. /*
  807. * Macro to access HWIO_REO_R0_ERROR_DESTINATION_RING_CTRL_IX_0
  808. * to map destination to rings
  809. */
  810. #define HAL_REO_ERR_REMAP_IX0(_VALUE, _OFFSET) \
  811. ((_VALUE) << \
  812. (HWIO_REO_R0_ERROR_DESTINATION_MAPPING_IX_0_ERROR_ ## \
  813. DESTINATION_RING_ ## _OFFSET ## _SHFT))
  814. /*
  815. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  816. * to map destination to rings
  817. */
  818. #define HAL_REO_REMAP_IX0(_VALUE, _OFFSET) \
  819. ((_VALUE) << \
  820. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  821. _OFFSET ## _SHFT))
  822. /*
  823. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1
  824. * to map destination to rings
  825. */
  826. #define HAL_REO_REMAP_IX2(_VALUE, _OFFSET) \
  827. ((_VALUE) << \
  828. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_DEST_RING_MAPPING_ ## \
  829. _OFFSET ## _SHFT))
  830. /*
  831. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3
  832. * to map destination to rings
  833. */
  834. #define HAL_REO_REMAP_IX3(_VALUE, _OFFSET) \
  835. ((_VALUE) << \
  836. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_DEST_RING_MAPPING_ ## \
  837. _OFFSET ## _SHFT))
  838. /**
  839. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  840. * @hal_soc_hdl: HAL SOC handle
  841. * @read: boolean value to indicate if read or write
  842. * @ix0: pointer to store IX0 reg value
  843. * @ix1: pointer to store IX1 reg value
  844. * @ix2: pointer to store IX2 reg value
  845. * @ix3: pointer to store IX3 reg value
  846. */
  847. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  848. uint32_t *ix0, uint32_t *ix1,
  849. uint32_t *ix2, uint32_t *ix3);
  850. /**
  851. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  852. * @sring: sring pointer
  853. * @paddr: physical address
  854. */
  855. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  856. /**
  857. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  858. * @srng: sring pointer
  859. * @vaddr: virtual address
  860. */
  861. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  862. /**
  863. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  864. * @hal_soc: Opaque HAL SOC handle
  865. * @hal_srng: Opaque HAL SRNG pointer
  866. */
  867. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl);
  868. static inline bool hal_srng_initialized(hal_ring_handle_t hal_ring_hdl)
  869. {
  870. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  871. return !!srng->initialized;
  872. }
  873. /**
  874. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  875. * @hal_soc: Opaque HAL SOC handle
  876. * @hal_ring_hdl: Destination ring pointer
  877. *
  878. * Caller takes responsibility for any locking needs.
  879. *
  880. * Return: Opaque pointer for next ring entry; NULL on failire
  881. */
  882. static inline
  883. void *hal_srng_dst_peek(hal_soc_handle_t hal_soc_hdl,
  884. hal_ring_handle_t hal_ring_hdl)
  885. {
  886. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  887. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  888. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  889. return NULL;
  890. }
  891. /**
  892. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  893. * hal_srng_access_start if locked access is required
  894. *
  895. * @hal_soc: Opaque HAL SOC handle
  896. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  897. *
  898. * Return: 0 on success; error on failire
  899. */
  900. static inline int
  901. hal_srng_access_start_unlocked(hal_soc_handle_t hal_soc_hdl,
  902. hal_ring_handle_t hal_ring_hdl)
  903. {
  904. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  905. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  906. uint32_t *desc;
  907. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  908. srng->u.src_ring.cached_tp =
  909. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  910. else {
  911. srng->u.dst_ring.cached_hp =
  912. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  913. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  914. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  915. if (qdf_likely(desc)) {
  916. qdf_mem_dma_cache_sync(soc->qdf_dev,
  917. qdf_mem_virt_to_phys
  918. (desc),
  919. QDF_DMA_FROM_DEVICE,
  920. (srng->entry_size *
  921. sizeof(uint32_t)));
  922. qdf_prefetch(desc);
  923. }
  924. }
  925. }
  926. return 0;
  927. }
  928. /**
  929. * hal_srng_try_access_start - Try to start (locked) ring access
  930. *
  931. * @hal_soc: Opaque HAL SOC handle
  932. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  933. *
  934. * Return: 0 on success; error on failure
  935. */
  936. static inline int hal_srng_try_access_start(hal_soc_handle_t hal_soc_hdl,
  937. hal_ring_handle_t hal_ring_hdl)
  938. {
  939. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  940. if (qdf_unlikely(!hal_ring_hdl)) {
  941. qdf_print("Error: Invalid hal_ring\n");
  942. return -EINVAL;
  943. }
  944. if (!SRNG_TRY_LOCK(&(srng->lock)))
  945. return -EINVAL;
  946. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  947. }
  948. /**
  949. * hal_srng_access_start - Start (locked) ring access
  950. *
  951. * @hal_soc: Opaque HAL SOC handle
  952. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  953. *
  954. * Return: 0 on success; error on failire
  955. */
  956. static inline int hal_srng_access_start(hal_soc_handle_t hal_soc_hdl,
  957. hal_ring_handle_t hal_ring_hdl)
  958. {
  959. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  960. if (qdf_unlikely(!hal_ring_hdl)) {
  961. qdf_print("Error: Invalid hal_ring\n");
  962. return -EINVAL;
  963. }
  964. SRNG_LOCK(&(srng->lock));
  965. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  966. }
  967. /**
  968. * hal_srng_dst_get_next - Get next entry from a destination ring
  969. * @hal_soc: Opaque HAL SOC handle
  970. * @hal_ring_hdl: Destination ring pointer
  971. *
  972. * Return: Opaque pointer for next ring entry; NULL on failure
  973. */
  974. static inline
  975. void *hal_srng_dst_get_next(void *hal_soc,
  976. hal_ring_handle_t hal_ring_hdl)
  977. {
  978. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  979. uint32_t *desc;
  980. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  981. return NULL;
  982. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  983. /* TODO: Using % is expensive, but we have to do this since
  984. * size of some SRNG rings is not power of 2 (due to descriptor
  985. * sizes). Need to create separate API for rings used
  986. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  987. * SW2RXDMA and CE rings)
  988. */
  989. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  990. if (srng->u.dst_ring.tp == srng->ring_size)
  991. srng->u.dst_ring.tp = 0;
  992. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  993. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  994. uint32_t *desc_next;
  995. uint32_t tp;
  996. tp = srng->u.dst_ring.tp;
  997. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  998. qdf_mem_dma_cache_sync(soc->qdf_dev,
  999. qdf_mem_virt_to_phys(desc_next),
  1000. QDF_DMA_FROM_DEVICE,
  1001. (srng->entry_size *
  1002. sizeof(uint32_t)));
  1003. qdf_prefetch(desc_next);
  1004. }
  1005. return (void *)desc;
  1006. }
  1007. /**
  1008. * hal_srng_dst_get_next_cached - Get cached next entry
  1009. * @hal_soc: Opaque HAL SOC handle
  1010. * @hal_ring_hdl: Destination ring pointer
  1011. *
  1012. * Get next entry from a destination ring and move cached tail pointer
  1013. *
  1014. * Return: Opaque pointer for next ring entry; NULL on failure
  1015. */
  1016. static inline
  1017. void *hal_srng_dst_get_next_cached(void *hal_soc,
  1018. hal_ring_handle_t hal_ring_hdl)
  1019. {
  1020. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1021. uint32_t *desc;
  1022. uint32_t *desc_next;
  1023. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  1024. return NULL;
  1025. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1026. /* TODO: Using % is expensive, but we have to do this since
  1027. * size of some SRNG rings is not power of 2 (due to descriptor
  1028. * sizes). Need to create separate API for rings used
  1029. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1030. * SW2RXDMA and CE rings)
  1031. */
  1032. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  1033. if (srng->u.dst_ring.tp == srng->ring_size)
  1034. srng->u.dst_ring.tp = 0;
  1035. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1036. qdf_prefetch(desc_next);
  1037. return (void *)desc;
  1038. }
  1039. /**
  1040. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  1041. * cached head pointer
  1042. *
  1043. * @hal_soc: Opaque HAL SOC handle
  1044. * @hal_ring_hdl: Destination ring pointer
  1045. *
  1046. * Return: Opaque pointer for next ring entry; NULL on failire
  1047. */
  1048. static inline void *
  1049. hal_srng_dst_get_next_hp(hal_soc_handle_t hal_soc_hdl,
  1050. hal_ring_handle_t hal_ring_hdl)
  1051. {
  1052. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1053. uint32_t *desc;
  1054. /* TODO: Using % is expensive, but we have to do this since
  1055. * size of some SRNG rings is not power of 2 (due to descriptor
  1056. * sizes). Need to create separate API for rings used
  1057. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1058. * SW2RXDMA and CE rings)
  1059. */
  1060. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  1061. srng->ring_size;
  1062. if (next_hp != srng->u.dst_ring.tp) {
  1063. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  1064. srng->u.dst_ring.cached_hp = next_hp;
  1065. return (void *)desc;
  1066. }
  1067. return NULL;
  1068. }
  1069. /**
  1070. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  1071. * @hal_soc: Opaque HAL SOC handle
  1072. * @hal_ring_hdl: Destination ring pointer
  1073. *
  1074. * Sync cached head pointer with HW.
  1075. * Caller takes responsibility for any locking needs.
  1076. *
  1077. * Return: Opaque pointer for next ring entry; NULL on failire
  1078. */
  1079. static inline
  1080. void *hal_srng_dst_peek_sync(hal_soc_handle_t hal_soc_hdl,
  1081. hal_ring_handle_t hal_ring_hdl)
  1082. {
  1083. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1084. srng->u.dst_ring.cached_hp =
  1085. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1086. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  1087. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  1088. return NULL;
  1089. }
  1090. /**
  1091. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  1092. * @hal_soc: Opaque HAL SOC handle
  1093. * @hal_ring_hdl: Destination ring pointer
  1094. *
  1095. * Sync cached head pointer with HW.
  1096. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  1097. *
  1098. * Return: Opaque pointer for next ring entry; NULL on failire
  1099. */
  1100. static inline
  1101. void *hal_srng_dst_peek_sync_locked(hal_soc_handle_t hal_soc_hdl,
  1102. hal_ring_handle_t hal_ring_hdl)
  1103. {
  1104. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1105. void *ring_desc_ptr = NULL;
  1106. if (qdf_unlikely(!hal_ring_hdl)) {
  1107. qdf_print("Error: Invalid hal_ring\n");
  1108. return NULL;
  1109. }
  1110. SRNG_LOCK(&srng->lock);
  1111. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc_hdl, hal_ring_hdl);
  1112. SRNG_UNLOCK(&srng->lock);
  1113. return ring_desc_ptr;
  1114. }
  1115. /**
  1116. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  1117. * by SW) in destination ring
  1118. *
  1119. * @hal_soc: Opaque HAL SOC handle
  1120. * @hal_ring_hdl: Destination ring pointer
  1121. * @sync_hw_ptr: Sync cached head pointer with HW
  1122. *
  1123. */
  1124. static inline
  1125. uint32_t hal_srng_dst_num_valid(void *hal_soc,
  1126. hal_ring_handle_t hal_ring_hdl,
  1127. int sync_hw_ptr)
  1128. {
  1129. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1130. uint32_t hp;
  1131. uint32_t tp = srng->u.dst_ring.tp;
  1132. if (sync_hw_ptr) {
  1133. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1134. srng->u.dst_ring.cached_hp = hp;
  1135. } else {
  1136. hp = srng->u.dst_ring.cached_hp;
  1137. }
  1138. if (hp >= tp)
  1139. return (hp - tp) / srng->entry_size;
  1140. return (srng->ring_size - tp + hp) / srng->entry_size;
  1141. }
  1142. /**
  1143. * hal_srng_dst_inv_cached_descs - API to invalidate descriptors in batch mode
  1144. * @hal_soc: Opaque HAL SOC handle
  1145. * @hal_ring_hdl: Destination ring pointer
  1146. * @entry_count: Number of descriptors to be invalidated
  1147. *
  1148. * Invalidates a set of cached descriptors starting from tail to
  1149. * provided count worth
  1150. *
  1151. * Return - None
  1152. */
  1153. static inline void hal_srng_dst_inv_cached_descs(void *hal_soc,
  1154. hal_ring_handle_t hal_ring_hdl,
  1155. uint32_t entry_count)
  1156. {
  1157. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1158. uint32_t hp = srng->u.dst_ring.cached_hp;
  1159. uint32_t tp = srng->u.dst_ring.tp;
  1160. uint32_t sync_p = 0;
  1161. /*
  1162. * If SRNG does not have cached descriptors this
  1163. * API call should be a no op
  1164. */
  1165. if (!(srng->flags & HAL_SRNG_CACHED_DESC))
  1166. return;
  1167. if (qdf_unlikely(entry_count == 0))
  1168. return;
  1169. sync_p = (entry_count - 1) * srng->entry_size;
  1170. if (hp > tp) {
  1171. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1172. &srng->ring_base_vaddr[tp + sync_p]
  1173. + (srng->entry_size * sizeof(uint32_t)));
  1174. } else {
  1175. /*
  1176. * We have wrapped around
  1177. */
  1178. uint32_t wrap_cnt = ((srng->ring_size - tp) / srng->entry_size);
  1179. if (entry_count <= wrap_cnt) {
  1180. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1181. &srng->ring_base_vaddr[tp + sync_p] +
  1182. (srng->entry_size * sizeof(uint32_t)));
  1183. return;
  1184. }
  1185. entry_count -= wrap_cnt;
  1186. sync_p = (entry_count - 1) * srng->entry_size;
  1187. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1188. &srng->ring_base_vaddr[srng->ring_size - srng->entry_size] +
  1189. (srng->entry_size * sizeof(uint32_t)));
  1190. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[0],
  1191. &srng->ring_base_vaddr[sync_p]
  1192. + (srng->entry_size * sizeof(uint32_t)));
  1193. }
  1194. }
  1195. /**
  1196. * hal_srng_dst_num_valid_locked - Returns num valid entries to be processed
  1197. *
  1198. * @hal_soc: Opaque HAL SOC handle
  1199. * @hal_ring_hdl: Destination ring pointer
  1200. * @sync_hw_ptr: Sync cached head pointer with HW
  1201. *
  1202. * Returns number of valid entries to be processed by the host driver. The
  1203. * function takes up SRNG lock.
  1204. *
  1205. * Return: Number of valid destination entries
  1206. */
  1207. static inline uint32_t
  1208. hal_srng_dst_num_valid_locked(hal_soc_handle_t hal_soc,
  1209. hal_ring_handle_t hal_ring_hdl,
  1210. int sync_hw_ptr)
  1211. {
  1212. uint32_t num_valid;
  1213. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1214. SRNG_LOCK(&srng->lock);
  1215. num_valid = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr);
  1216. SRNG_UNLOCK(&srng->lock);
  1217. return num_valid;
  1218. }
  1219. /**
  1220. * hal_srng_sync_cachedhp - sync cachehp pointer from hw hp
  1221. *
  1222. * @hal_soc: Opaque HAL SOC handle
  1223. * @hal_ring_hdl: Destination ring pointer
  1224. *
  1225. */
  1226. static inline
  1227. void hal_srng_sync_cachedhp(void *hal_soc,
  1228. hal_ring_handle_t hal_ring_hdl)
  1229. {
  1230. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1231. uint32_t hp;
  1232. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1233. srng->u.dst_ring.cached_hp = hp;
  1234. }
  1235. /**
  1236. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  1237. * pointer. This can be used to release any buffers associated with completed
  1238. * ring entries. Note that this should not be used for posting new descriptor
  1239. * entries. Posting of new entries should be done only using
  1240. * hal_srng_src_get_next_reaped when this function is used for reaping.
  1241. *
  1242. * @hal_soc: Opaque HAL SOC handle
  1243. * @hal_ring_hdl: Source ring pointer
  1244. *
  1245. * Return: Opaque pointer for next ring entry; NULL on failire
  1246. */
  1247. static inline void *
  1248. hal_srng_src_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1249. {
  1250. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1251. uint32_t *desc;
  1252. /* TODO: Using % is expensive, but we have to do this since
  1253. * size of some SRNG rings is not power of 2 (due to descriptor
  1254. * sizes). Need to create separate API for rings used
  1255. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1256. * SW2RXDMA and CE rings)
  1257. */
  1258. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1259. srng->ring_size;
  1260. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  1261. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1262. srng->u.src_ring.reap_hp = next_reap_hp;
  1263. return (void *)desc;
  1264. }
  1265. return NULL;
  1266. }
  1267. /**
  1268. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  1269. * already reaped using hal_srng_src_reap_next, for posting new entries to
  1270. * the ring
  1271. *
  1272. * @hal_soc: Opaque HAL SOC handle
  1273. * @hal_ring_hdl: Source ring pointer
  1274. *
  1275. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  1276. */
  1277. static inline void *
  1278. hal_srng_src_get_next_reaped(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1279. {
  1280. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1281. uint32_t *desc;
  1282. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  1283. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1284. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  1285. srng->ring_size;
  1286. return (void *)desc;
  1287. }
  1288. return NULL;
  1289. }
  1290. /**
  1291. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  1292. * move reap pointer. This API is used in detach path to release any buffers
  1293. * associated with ring entries which are pending reap.
  1294. *
  1295. * @hal_soc: Opaque HAL SOC handle
  1296. * @hal_ring_hdl: Source ring pointer
  1297. *
  1298. * Return: Opaque pointer for next ring entry; NULL on failire
  1299. */
  1300. static inline void *
  1301. hal_srng_src_pending_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1302. {
  1303. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1304. uint32_t *desc;
  1305. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1306. srng->ring_size;
  1307. if (next_reap_hp != srng->u.src_ring.hp) {
  1308. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1309. srng->u.src_ring.reap_hp = next_reap_hp;
  1310. return (void *)desc;
  1311. }
  1312. return NULL;
  1313. }
  1314. /**
  1315. * hal_srng_src_done_val -
  1316. *
  1317. * @hal_soc: Opaque HAL SOC handle
  1318. * @hal_ring_hdl: Source ring pointer
  1319. *
  1320. * Return: Opaque pointer for next ring entry; NULL on failire
  1321. */
  1322. static inline uint32_t
  1323. hal_srng_src_done_val(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1324. {
  1325. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1326. /* TODO: Using % is expensive, but we have to do this since
  1327. * size of some SRNG rings is not power of 2 (due to descriptor
  1328. * sizes). Need to create separate API for rings used
  1329. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1330. * SW2RXDMA and CE rings)
  1331. */
  1332. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1333. srng->ring_size;
  1334. if (next_reap_hp == srng->u.src_ring.cached_tp)
  1335. return 0;
  1336. if (srng->u.src_ring.cached_tp > next_reap_hp)
  1337. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  1338. srng->entry_size;
  1339. else
  1340. return ((srng->ring_size - next_reap_hp) +
  1341. srng->u.src_ring.cached_tp) / srng->entry_size;
  1342. }
  1343. /**
  1344. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  1345. * @hal_ring_hdl: Source ring pointer
  1346. *
  1347. * Return: uint8_t
  1348. */
  1349. static inline
  1350. uint8_t hal_get_entrysize_from_srng(hal_ring_handle_t hal_ring_hdl)
  1351. {
  1352. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1353. return srng->entry_size;
  1354. }
  1355. /**
  1356. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  1357. * @hal_soc: Opaque HAL SOC handle
  1358. * @hal_ring_hdl: Source ring pointer
  1359. * @tailp: Tail Pointer
  1360. * @headp: Head Pointer
  1361. *
  1362. * Return: Update tail pointer and head pointer in arguments.
  1363. */
  1364. static inline
  1365. void hal_get_sw_hptp(void *hal_soc, hal_ring_handle_t hal_ring_hdl,
  1366. uint32_t *tailp, uint32_t *headp)
  1367. {
  1368. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1369. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1370. *headp = srng->u.src_ring.hp;
  1371. *tailp = *srng->u.src_ring.tp_addr;
  1372. } else {
  1373. *tailp = srng->u.dst_ring.tp;
  1374. *headp = *srng->u.dst_ring.hp_addr;
  1375. }
  1376. }
  1377. /**
  1378. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  1379. *
  1380. * @hal_soc: Opaque HAL SOC handle
  1381. * @hal_ring_hdl: Source ring pointer
  1382. *
  1383. * Return: Opaque pointer for next ring entry; NULL on failire
  1384. */
  1385. static inline
  1386. void *hal_srng_src_get_next(void *hal_soc,
  1387. hal_ring_handle_t hal_ring_hdl)
  1388. {
  1389. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1390. uint32_t *desc;
  1391. /* TODO: Using % is expensive, but we have to do this since
  1392. * size of some SRNG rings is not power of 2 (due to descriptor
  1393. * sizes). Need to create separate API for rings used
  1394. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1395. * SW2RXDMA and CE rings)
  1396. */
  1397. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1398. srng->ring_size;
  1399. if (next_hp != srng->u.src_ring.cached_tp) {
  1400. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1401. srng->u.src_ring.hp = next_hp;
  1402. /* TODO: Since reap function is not used by all rings, we can
  1403. * remove the following update of reap_hp in this function
  1404. * if we can ensure that only hal_srng_src_get_next_reaped
  1405. * is used for the rings requiring reap functionality
  1406. */
  1407. srng->u.src_ring.reap_hp = next_hp;
  1408. return (void *)desc;
  1409. }
  1410. return NULL;
  1411. }
  1412. /**
  1413. * hal_srng_src_peek_n_get_next - Get next entry from a ring without
  1414. * moving head pointer.
  1415. * hal_srng_src_get_next should be called subsequently to move the head pointer
  1416. *
  1417. * @hal_soc: Opaque HAL SOC handle
  1418. * @hal_ring_hdl: Source ring pointer
  1419. *
  1420. * Return: Opaque pointer for next ring entry; NULL on failire
  1421. */
  1422. static inline
  1423. void *hal_srng_src_peek_n_get_next(hal_soc_handle_t hal_soc_hdl,
  1424. hal_ring_handle_t hal_ring_hdl)
  1425. {
  1426. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1427. uint32_t *desc;
  1428. /* TODO: Using % is expensive, but we have to do this since
  1429. * size of some SRNG rings is not power of 2 (due to descriptor
  1430. * sizes). Need to create separate API for rings used
  1431. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1432. * SW2RXDMA and CE rings)
  1433. */
  1434. if (((srng->u.src_ring.hp + srng->entry_size) %
  1435. srng->ring_size) != srng->u.src_ring.cached_tp) {
  1436. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1437. srng->entry_size) %
  1438. srng->ring_size]);
  1439. return (void *)desc;
  1440. }
  1441. return NULL;
  1442. }
  1443. /**
  1444. * hal_srng_src_peek_n_get_next_next - Get next to next, i.e HP + 2 entry
  1445. * from a ring without moving head pointer.
  1446. *
  1447. * @hal_soc: Opaque HAL SOC handle
  1448. * @hal_ring_hdl: Source ring pointer
  1449. *
  1450. * Return: Opaque pointer for next to next ring entry; NULL on failire
  1451. */
  1452. static inline
  1453. void *hal_srng_src_peek_n_get_next_next(hal_soc_handle_t hal_soc_hdl,
  1454. hal_ring_handle_t hal_ring_hdl)
  1455. {
  1456. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1457. uint32_t *desc;
  1458. /* TODO: Using % is expensive, but we have to do this since
  1459. * size of some SRNG rings is not power of 2 (due to descriptor
  1460. * sizes). Need to create separate API for rings used
  1461. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1462. * SW2RXDMA and CE rings)
  1463. */
  1464. if ((((srng->u.src_ring.hp + (srng->entry_size)) %
  1465. srng->ring_size) != srng->u.src_ring.cached_tp) &&
  1466. (((srng->u.src_ring.hp + (srng->entry_size * 2)) %
  1467. srng->ring_size) != srng->u.src_ring.cached_tp)) {
  1468. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1469. (srng->entry_size * 2)) %
  1470. srng->ring_size]);
  1471. return (void *)desc;
  1472. }
  1473. return NULL;
  1474. }
  1475. /**
  1476. * hal_srng_src_get_cur_hp_n_move_next () - API returns current hp
  1477. * and move hp to next in src ring
  1478. *
  1479. * Usage: This API should only be used at init time replenish.
  1480. *
  1481. * @hal_soc_hdl: HAL soc handle
  1482. * @hal_ring_hdl: Source ring pointer
  1483. *
  1484. */
  1485. static inline void *
  1486. hal_srng_src_get_cur_hp_n_move_next(hal_soc_handle_t hal_soc_hdl,
  1487. hal_ring_handle_t hal_ring_hdl)
  1488. {
  1489. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1490. uint32_t *cur_desc = NULL;
  1491. uint32_t next_hp;
  1492. cur_desc = &srng->ring_base_vaddr[(srng->u.src_ring.hp)];
  1493. next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1494. srng->ring_size;
  1495. if (next_hp != srng->u.src_ring.cached_tp)
  1496. srng->u.src_ring.hp = next_hp;
  1497. return (void *)cur_desc;
  1498. }
  1499. /**
  1500. * hal_srng_src_num_avail - Returns number of available entries in src ring
  1501. *
  1502. * @hal_soc: Opaque HAL SOC handle
  1503. * @hal_ring_hdl: Source ring pointer
  1504. * @sync_hw_ptr: Sync cached tail pointer with HW
  1505. *
  1506. */
  1507. static inline uint32_t
  1508. hal_srng_src_num_avail(void *hal_soc,
  1509. hal_ring_handle_t hal_ring_hdl, int sync_hw_ptr)
  1510. {
  1511. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1512. uint32_t tp;
  1513. uint32_t hp = srng->u.src_ring.hp;
  1514. if (sync_hw_ptr) {
  1515. tp = *(srng->u.src_ring.tp_addr);
  1516. srng->u.src_ring.cached_tp = tp;
  1517. } else {
  1518. tp = srng->u.src_ring.cached_tp;
  1519. }
  1520. if (tp > hp)
  1521. return ((tp - hp) / srng->entry_size) - 1;
  1522. else
  1523. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  1524. }
  1525. /**
  1526. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  1527. * ring head/tail pointers to HW.
  1528. * This should be used only if hal_srng_access_start_unlocked to start ring
  1529. * access
  1530. *
  1531. * @hal_soc: Opaque HAL SOC handle
  1532. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1533. *
  1534. * Return: 0 on success; error on failire
  1535. */
  1536. static inline void
  1537. hal_srng_access_end_unlocked(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1538. {
  1539. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1540. /* TODO: See if we need a write memory barrier here */
  1541. if (srng->flags & HAL_SRNG_LMAC_RING) {
  1542. /* For LMAC rings, ring pointer updates are done through FW and
  1543. * hence written to a shared memory location that is read by FW
  1544. */
  1545. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1546. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  1547. } else {
  1548. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  1549. }
  1550. } else {
  1551. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1552. hal_srng_write_address_32_mb(hal_soc,
  1553. srng,
  1554. srng->u.src_ring.hp_addr,
  1555. srng->u.src_ring.hp);
  1556. else
  1557. hal_srng_write_address_32_mb(hal_soc,
  1558. srng,
  1559. srng->u.dst_ring.tp_addr,
  1560. srng->u.dst_ring.tp);
  1561. }
  1562. }
  1563. /**
  1564. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  1565. * pointers to HW
  1566. * This should be used only if hal_srng_access_start to start ring access
  1567. *
  1568. * @hal_soc: Opaque HAL SOC handle
  1569. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1570. *
  1571. * Return: 0 on success; error on failire
  1572. */
  1573. static inline void
  1574. hal_srng_access_end(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1575. {
  1576. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1577. if (qdf_unlikely(!hal_ring_hdl)) {
  1578. qdf_print("Error: Invalid hal_ring\n");
  1579. return;
  1580. }
  1581. hal_srng_access_end_unlocked(hal_soc, hal_ring_hdl);
  1582. SRNG_UNLOCK(&(srng->lock));
  1583. }
  1584. /**
  1585. * hal_srng_access_end_reap - Unlock ring access
  1586. * This should be used only if hal_srng_access_start to start ring access
  1587. * and should be used only while reaping SRC ring completions
  1588. *
  1589. * @hal_soc: Opaque HAL SOC handle
  1590. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1591. *
  1592. * Return: 0 on success; error on failire
  1593. */
  1594. static inline void
  1595. hal_srng_access_end_reap(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1596. {
  1597. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1598. SRNG_UNLOCK(&(srng->lock));
  1599. }
  1600. /* TODO: Check if the following definitions is available in HW headers */
  1601. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  1602. #define NUM_MPDUS_PER_LINK_DESC 6
  1603. #define NUM_MSDUS_PER_LINK_DESC 7
  1604. #define REO_QUEUE_DESC_ALIGN 128
  1605. #define LINK_DESC_ALIGN 128
  1606. #define ADDRESS_MATCH_TAG_VAL 0x5
  1607. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  1608. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  1609. */
  1610. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  1611. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  1612. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  1613. * should be specified in 16 word units. But the number of bits defined for
  1614. * this field in HW header files is 5.
  1615. */
  1616. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  1617. /**
  1618. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  1619. * in an idle list
  1620. *
  1621. * @hal_soc: Opaque HAL SOC handle
  1622. *
  1623. */
  1624. static inline
  1625. uint32_t hal_idle_list_scatter_buf_size(hal_soc_handle_t hal_soc_hdl)
  1626. {
  1627. return WBM_IDLE_SCATTER_BUF_SIZE;
  1628. }
  1629. /**
  1630. * hal_get_link_desc_size - Get the size of each link descriptor
  1631. *
  1632. * @hal_soc: Opaque HAL SOC handle
  1633. *
  1634. */
  1635. static inline uint32_t hal_get_link_desc_size(hal_soc_handle_t hal_soc_hdl)
  1636. {
  1637. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1638. if (!hal_soc || !hal_soc->ops) {
  1639. qdf_print("Error: Invalid ops\n");
  1640. QDF_BUG(0);
  1641. return -EINVAL;
  1642. }
  1643. if (!hal_soc->ops->hal_get_link_desc_size) {
  1644. qdf_print("Error: Invalid function pointer\n");
  1645. QDF_BUG(0);
  1646. return -EINVAL;
  1647. }
  1648. return hal_soc->ops->hal_get_link_desc_size();
  1649. }
  1650. /**
  1651. * hal_get_link_desc_align - Get the required start address alignment for
  1652. * link descriptors
  1653. *
  1654. * @hal_soc: Opaque HAL SOC handle
  1655. *
  1656. */
  1657. static inline
  1658. uint32_t hal_get_link_desc_align(hal_soc_handle_t hal_soc_hdl)
  1659. {
  1660. return LINK_DESC_ALIGN;
  1661. }
  1662. /**
  1663. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  1664. *
  1665. * @hal_soc: Opaque HAL SOC handle
  1666. *
  1667. */
  1668. static inline
  1669. uint32_t hal_num_mpdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1670. {
  1671. return NUM_MPDUS_PER_LINK_DESC;
  1672. }
  1673. /**
  1674. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  1675. *
  1676. * @hal_soc: Opaque HAL SOC handle
  1677. *
  1678. */
  1679. static inline
  1680. uint32_t hal_num_msdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1681. {
  1682. return NUM_MSDUS_PER_LINK_DESC;
  1683. }
  1684. /**
  1685. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1686. * descriptor can hold
  1687. *
  1688. * @hal_soc: Opaque HAL SOC handle
  1689. *
  1690. */
  1691. static inline
  1692. uint32_t hal_num_mpdu_links_per_queue_desc(hal_soc_handle_t hal_soc_hdl)
  1693. {
  1694. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1695. }
  1696. /**
  1697. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1698. * that the given buffer size
  1699. *
  1700. * @hal_soc: Opaque HAL SOC handle
  1701. * @scatter_buf_size: Size of scatter buffer
  1702. *
  1703. */
  1704. static inline
  1705. uint32_t hal_idle_scatter_buf_num_entries(hal_soc_handle_t hal_soc_hdl,
  1706. uint32_t scatter_buf_size)
  1707. {
  1708. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1709. hal_srng_get_entrysize(hal_soc_hdl, WBM_IDLE_LINK);
  1710. }
  1711. /**
  1712. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1713. * each given buffer size
  1714. *
  1715. * @hal_soc: Opaque HAL SOC handle
  1716. * @total_mem: size of memory to be scattered
  1717. * @scatter_buf_size: Size of scatter buffer
  1718. *
  1719. */
  1720. static inline
  1721. uint32_t hal_idle_list_num_scatter_bufs(hal_soc_handle_t hal_soc_hdl,
  1722. uint32_t total_mem,
  1723. uint32_t scatter_buf_size)
  1724. {
  1725. uint8_t rem = (total_mem % (scatter_buf_size -
  1726. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1727. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1728. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1729. return num_scatter_bufs;
  1730. }
  1731. enum hal_pn_type {
  1732. HAL_PN_NONE,
  1733. HAL_PN_WPA,
  1734. HAL_PN_WAPI_EVEN,
  1735. HAL_PN_WAPI_UNEVEN,
  1736. };
  1737. #define HAL_RX_MAX_BA_WINDOW 256
  1738. /**
  1739. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1740. * queue descriptors
  1741. *
  1742. * @hal_soc: Opaque HAL SOC handle
  1743. *
  1744. */
  1745. static inline
  1746. uint32_t hal_get_reo_qdesc_align(hal_soc_handle_t hal_soc_hdl)
  1747. {
  1748. return REO_QUEUE_DESC_ALIGN;
  1749. }
  1750. /**
  1751. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1752. *
  1753. * @hal_soc: Opaque HAL SOC handle
  1754. * @ba_window_size: BlockAck window size
  1755. * @start_seq: Starting sequence number
  1756. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1757. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1758. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1759. *
  1760. */
  1761. void hal_reo_qdesc_setup(hal_soc_handle_t hal_soc_hdl,
  1762. int tid, uint32_t ba_window_size,
  1763. uint32_t start_seq, void *hw_qdesc_vaddr,
  1764. qdf_dma_addr_t hw_qdesc_paddr,
  1765. int pn_type);
  1766. /**
  1767. * hal_srng_get_hp_addr - Get head pointer physical address
  1768. *
  1769. * @hal_soc: Opaque HAL SOC handle
  1770. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1771. *
  1772. */
  1773. static inline qdf_dma_addr_t
  1774. hal_srng_get_hp_addr(void *hal_soc,
  1775. hal_ring_handle_t hal_ring_hdl)
  1776. {
  1777. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1778. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1779. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1780. return hal->shadow_wrptr_mem_paddr +
  1781. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1782. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1783. } else {
  1784. return hal->shadow_rdptr_mem_paddr +
  1785. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1786. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1787. }
  1788. }
  1789. /**
  1790. * hal_srng_get_tp_addr - Get tail pointer physical address
  1791. *
  1792. * @hal_soc: Opaque HAL SOC handle
  1793. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1794. *
  1795. */
  1796. static inline qdf_dma_addr_t
  1797. hal_srng_get_tp_addr(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1798. {
  1799. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1800. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1801. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1802. return hal->shadow_rdptr_mem_paddr +
  1803. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1804. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1805. } else {
  1806. return hal->shadow_wrptr_mem_paddr +
  1807. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1808. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1809. }
  1810. }
  1811. /**
  1812. * hal_srng_get_num_entries - Get total entries in the HAL Srng
  1813. *
  1814. * @hal_soc: Opaque HAL SOC handle
  1815. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1816. *
  1817. * Return: total number of entries in hal ring
  1818. */
  1819. static inline
  1820. uint32_t hal_srng_get_num_entries(hal_soc_handle_t hal_soc_hdl,
  1821. hal_ring_handle_t hal_ring_hdl)
  1822. {
  1823. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1824. return srng->num_entries;
  1825. }
  1826. /**
  1827. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1828. *
  1829. * @hal_soc: Opaque HAL SOC handle
  1830. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1831. * @ring_params: SRNG parameters will be returned through this structure
  1832. */
  1833. void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  1834. hal_ring_handle_t hal_ring_hdl,
  1835. struct hal_srng_params *ring_params);
  1836. /**
  1837. * hal_mem_info - Retrieve hal memory base address
  1838. *
  1839. * @hal_soc: Opaque HAL SOC handle
  1840. * @mem: pointer to structure to be updated with hal mem info
  1841. */
  1842. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem);
  1843. /**
  1844. * hal_get_target_type - Return target type
  1845. *
  1846. * @hal_soc: Opaque HAL SOC handle
  1847. */
  1848. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl);
  1849. /**
  1850. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1851. *
  1852. * @hal_soc: Opaque HAL SOC handle
  1853. * @ac: Access category
  1854. * @value: timeout duration in millisec
  1855. */
  1856. void hal_get_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1857. uint32_t *value);
  1858. /**
  1859. * hal_set_aging_timeout - Set BA aging timeout
  1860. *
  1861. * @hal_soc: Opaque HAL SOC handle
  1862. * @ac: Access category in millisec
  1863. * @value: timeout duration value
  1864. */
  1865. void hal_set_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1866. uint32_t value);
  1867. /**
  1868. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1869. * destination ring HW
  1870. * @hal_soc: HAL SOC handle
  1871. * @srng: SRNG ring pointer
  1872. */
  1873. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1874. struct hal_srng *srng)
  1875. {
  1876. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1877. }
  1878. /**
  1879. * hal_srng_src_hw_init - Private function to initialize SRNG
  1880. * source ring HW
  1881. * @hal_soc: HAL SOC handle
  1882. * @srng: SRNG ring pointer
  1883. */
  1884. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1885. struct hal_srng *srng)
  1886. {
  1887. hal->ops->hal_srng_src_hw_init(hal, srng);
  1888. }
  1889. /**
  1890. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  1891. * @hal_soc: Opaque HAL SOC handle
  1892. * @hal_ring_hdl: Source ring pointer
  1893. * @headp: Head Pointer
  1894. * @tailp: Tail Pointer
  1895. * @ring_type: Ring
  1896. *
  1897. * Return: Update tail pointer and head pointer in arguments.
  1898. */
  1899. static inline
  1900. void hal_get_hw_hptp(hal_soc_handle_t hal_soc_hdl,
  1901. hal_ring_handle_t hal_ring_hdl,
  1902. uint32_t *headp, uint32_t *tailp,
  1903. uint8_t ring_type)
  1904. {
  1905. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1906. hal_soc->ops->hal_get_hw_hptp(hal_soc, hal_ring_hdl,
  1907. headp, tailp, ring_type);
  1908. }
  1909. /**
  1910. * hal_reo_setup - Initialize HW REO block
  1911. *
  1912. * @hal_soc: Opaque HAL SOC handle
  1913. * @reo_params: parameters needed by HAL for REO config
  1914. */
  1915. static inline void hal_reo_setup(hal_soc_handle_t hal_soc_hdl,
  1916. void *reoparams)
  1917. {
  1918. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1919. hal_soc->ops->hal_reo_setup(hal_soc, reoparams);
  1920. }
  1921. static inline
  1922. void hal_compute_reo_remap_ix2_ix3(hal_soc_handle_t hal_soc_hdl,
  1923. uint32_t *ring, uint32_t num_rings,
  1924. uint32_t *remap1, uint32_t *remap2)
  1925. {
  1926. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1927. return hal_soc->ops->hal_compute_reo_remap_ix2_ix3(ring,
  1928. num_rings, remap1, remap2);
  1929. }
  1930. /**
  1931. * hal_setup_link_idle_list - Setup scattered idle list using the
  1932. * buffer list provided
  1933. *
  1934. * @hal_soc: Opaque HAL SOC handle
  1935. * @scatter_bufs_base_paddr: Array of physical base addresses
  1936. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1937. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1938. * @scatter_buf_size: Size of each scatter buffer
  1939. * @last_buf_end_offset: Offset to the last entry
  1940. * @num_entries: Total entries of all scatter bufs
  1941. *
  1942. */
  1943. static inline
  1944. void hal_setup_link_idle_list(hal_soc_handle_t hal_soc_hdl,
  1945. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1946. void *scatter_bufs_base_vaddr[],
  1947. uint32_t num_scatter_bufs,
  1948. uint32_t scatter_buf_size,
  1949. uint32_t last_buf_end_offset,
  1950. uint32_t num_entries)
  1951. {
  1952. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1953. hal_soc->ops->hal_setup_link_idle_list(hal_soc, scatter_bufs_base_paddr,
  1954. scatter_bufs_base_vaddr, num_scatter_bufs,
  1955. scatter_buf_size, last_buf_end_offset,
  1956. num_entries);
  1957. }
  1958. /**
  1959. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  1960. *
  1961. * @hal_soc: Opaque HAL SOC handle
  1962. * @hal_ring_hdl: Source ring pointer
  1963. * @ring_desc: Opaque ring descriptor handle
  1964. */
  1965. static inline void hal_srng_dump_ring_desc(hal_soc_handle_t hal_soc_hdl,
  1966. hal_ring_handle_t hal_ring_hdl,
  1967. hal_ring_desc_t ring_desc)
  1968. {
  1969. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1970. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1971. ring_desc, (srng->entry_size << 2));
  1972. }
  1973. /**
  1974. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  1975. *
  1976. * @hal_soc: Opaque HAL SOC handle
  1977. * @hal_ring_hdl: Source ring pointer
  1978. */
  1979. static inline void hal_srng_dump_ring(hal_soc_handle_t hal_soc_hdl,
  1980. hal_ring_handle_t hal_ring_hdl)
  1981. {
  1982. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1983. uint32_t *desc;
  1984. uint32_t tp, i;
  1985. tp = srng->u.dst_ring.tp;
  1986. for (i = 0; i < 128; i++) {
  1987. if (!tp)
  1988. tp = srng->ring_size;
  1989. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  1990. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  1991. QDF_TRACE_LEVEL_DEBUG,
  1992. desc, (srng->entry_size << 2));
  1993. tp -= srng->entry_size;
  1994. }
  1995. }
  1996. /*
  1997. * hal_rxdma_desc_to_hal_ring_desc - API to convert rxdma ring desc
  1998. * to opaque dp_ring desc type
  1999. * @ring_desc - rxdma ring desc
  2000. *
  2001. * Return: hal_rxdma_desc_t type
  2002. */
  2003. static inline
  2004. hal_ring_desc_t hal_rxdma_desc_to_hal_ring_desc(hal_rxdma_desc_t ring_desc)
  2005. {
  2006. return (hal_ring_desc_t)ring_desc;
  2007. }
  2008. /**
  2009. * hal_srng_set_event() - Set hal_srng event
  2010. * @hal_ring_hdl: Source ring pointer
  2011. * @event: SRNG ring event
  2012. *
  2013. * Return: None
  2014. */
  2015. static inline void hal_srng_set_event(hal_ring_handle_t hal_ring_hdl, int event)
  2016. {
  2017. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2018. qdf_atomic_set_bit(event, &srng->srng_event);
  2019. }
  2020. /**
  2021. * hal_srng_clear_event() - Clear hal_srng event
  2022. * @hal_ring_hdl: Source ring pointer
  2023. * @event: SRNG ring event
  2024. *
  2025. * Return: None
  2026. */
  2027. static inline
  2028. void hal_srng_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  2029. {
  2030. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2031. qdf_atomic_clear_bit(event, &srng->srng_event);
  2032. }
  2033. /**
  2034. * hal_srng_get_clear_event() - Clear srng event and return old value
  2035. * @hal_ring_hdl: Source ring pointer
  2036. * @event: SRNG ring event
  2037. *
  2038. * Return: Return old event value
  2039. */
  2040. static inline
  2041. int hal_srng_get_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  2042. {
  2043. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2044. return qdf_atomic_test_and_clear_bit(event, &srng->srng_event);
  2045. }
  2046. /**
  2047. * hal_srng_set_flush_last_ts() - Record last flush time stamp
  2048. * @hal_ring_hdl: Source ring pointer
  2049. *
  2050. * Return: None
  2051. */
  2052. static inline void hal_srng_set_flush_last_ts(hal_ring_handle_t hal_ring_hdl)
  2053. {
  2054. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2055. srng->last_flush_ts = qdf_get_log_timestamp();
  2056. }
  2057. /**
  2058. * hal_srng_inc_flush_cnt() - Increment flush counter
  2059. * @hal_ring_hdl: Source ring pointer
  2060. *
  2061. * Return: None
  2062. */
  2063. static inline void hal_srng_inc_flush_cnt(hal_ring_handle_t hal_ring_hdl)
  2064. {
  2065. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2066. srng->flush_count++;
  2067. }
  2068. /**
  2069. * hal_rx_sw_mon_desc_info_get () - Get SW monitor desc info
  2070. *
  2071. * @hal: Core HAL soc handle
  2072. * @ring_desc: Mon dest ring descriptor
  2073. * @desc_info: Desc info to be populated
  2074. *
  2075. * Return void
  2076. */
  2077. static inline void
  2078. hal_rx_sw_mon_desc_info_get(struct hal_soc *hal,
  2079. hal_ring_desc_t ring_desc,
  2080. hal_rx_mon_desc_info_t desc_info)
  2081. {
  2082. return hal->ops->hal_rx_sw_mon_desc_info_get(ring_desc, desc_info);
  2083. }
  2084. /**
  2085. * hal_reo_set_err_dst_remap() - Set REO error destination ring remap
  2086. * register value.
  2087. *
  2088. * @hal_soc_hdl: Opaque HAL soc handle
  2089. *
  2090. * Return: None
  2091. */
  2092. static inline void hal_reo_set_err_dst_remap(hal_soc_handle_t hal_soc_hdl)
  2093. {
  2094. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2095. if (hal_soc->ops->hal_reo_set_err_dst_remap)
  2096. hal_soc->ops->hal_reo_set_err_dst_remap(hal_soc);
  2097. }
  2098. #endif /* _HAL_APIH_ */