hal_api.h 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  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. #ifdef FEATURE_HAL_DELAYED_REG_WRITE
  482. /**
  483. * hal_dump_reg_write_srng_stats() - dump SRNG reg write stats
  484. * @hal_soc: HAL soc handle
  485. *
  486. * Return: none
  487. */
  488. void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl);
  489. /**
  490. * hal_dump_reg_write_stats() - dump reg write stats
  491. * @hal_soc: HAL soc handle
  492. *
  493. * Return: none
  494. */
  495. void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl);
  496. /**
  497. * hal_get_reg_write_pending_work() - get the number of entries
  498. * pending in the workqueue to be processed.
  499. * @hal_soc: HAL soc handle
  500. *
  501. * Returns: the number of entries pending to be processed
  502. */
  503. int hal_get_reg_write_pending_work(void *hal_soc);
  504. #else
  505. static inline void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl)
  506. {
  507. }
  508. static inline void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl)
  509. {
  510. }
  511. static inline int hal_get_reg_write_pending_work(void *hal_soc)
  512. {
  513. return 0;
  514. }
  515. #endif
  516. /**
  517. * hal_read_address_32_mb() - Read 32-bit value from the register
  518. * @soc: soc handle
  519. * @addr: register address to read
  520. *
  521. * Return: 32-bit value
  522. */
  523. static inline
  524. uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  525. qdf_iomem_t addr)
  526. {
  527. uint32_t offset;
  528. uint32_t ret;
  529. if (!soc->use_register_windowing)
  530. return qdf_ioread32(addr);
  531. offset = addr - soc->dev_base_addr;
  532. ret = hal_read32_mb(soc, offset);
  533. return ret;
  534. }
  535. /**
  536. * hal_attach - Initialize HAL layer
  537. * @hif_handle: Opaque HIF handle
  538. * @qdf_dev: QDF device
  539. *
  540. * Return: Opaque HAL SOC handle
  541. * NULL on failure (if given ring is not available)
  542. *
  543. * This function should be called as part of HIF initialization (for accessing
  544. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  545. */
  546. void *hal_attach(struct hif_opaque_softc *hif_handle, qdf_device_t qdf_dev);
  547. /**
  548. * hal_detach - Detach HAL layer
  549. * @hal_soc: HAL SOC handle
  550. *
  551. * This function should be called as part of HIF detach
  552. *
  553. */
  554. extern void hal_detach(void *hal_soc);
  555. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  556. enum hal_ring_type {
  557. REO_DST = 0,
  558. REO_EXCEPTION = 1,
  559. REO_REINJECT = 2,
  560. REO_CMD = 3,
  561. REO_STATUS = 4,
  562. TCL_DATA = 5,
  563. TCL_CMD_CREDIT = 6,
  564. TCL_STATUS = 7,
  565. CE_SRC = 8,
  566. CE_DST = 9,
  567. CE_DST_STATUS = 10,
  568. WBM_IDLE_LINK = 11,
  569. SW2WBM_RELEASE = 12,
  570. WBM2SW_RELEASE = 13,
  571. RXDMA_BUF = 14,
  572. RXDMA_DST = 15,
  573. RXDMA_MONITOR_BUF = 16,
  574. RXDMA_MONITOR_STATUS = 17,
  575. RXDMA_MONITOR_DST = 18,
  576. RXDMA_MONITOR_DESC = 19,
  577. DIR_BUF_RX_DMA_SRC = 20,
  578. #ifdef WLAN_FEATURE_CIF_CFR
  579. WIFI_POS_SRC,
  580. #endif
  581. MAX_RING_TYPES
  582. };
  583. #define HAL_SRNG_LMAC_RING 0x80000000
  584. /* SRNG flags passed in hal_srng_params.flags */
  585. #define HAL_SRNG_MSI_SWAP 0x00000008
  586. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  587. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  588. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  589. #define HAL_SRNG_MSI_INTR 0x00020000
  590. #define HAL_SRNG_CACHED_DESC 0x00040000
  591. #ifdef QCA_WIFI_QCA6490
  592. #define HAL_SRNG_PREFETCH_TIMER 1
  593. #else
  594. #define HAL_SRNG_PREFETCH_TIMER 0
  595. #endif
  596. #define PN_SIZE_24 0
  597. #define PN_SIZE_48 1
  598. #define PN_SIZE_128 2
  599. #ifdef FORCE_WAKE
  600. /**
  601. * hal_set_init_phase() - Indicate initialization of
  602. * datapath rings
  603. * @soc: hal_soc handle
  604. * @init_phase: flag to indicate datapath rings
  605. * initialization status
  606. *
  607. * Return: None
  608. */
  609. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase);
  610. #else
  611. static inline
  612. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase)
  613. {
  614. }
  615. #endif /* FORCE_WAKE */
  616. /**
  617. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  618. * used by callers for calculating the size of memory to be allocated before
  619. * calling hal_srng_setup to setup the ring
  620. *
  621. * @hal_soc: Opaque HAL SOC handle
  622. * @ring_type: one of the types from hal_ring_type
  623. *
  624. */
  625. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  626. /**
  627. * hal_srng_max_entries - Returns maximum possible number of ring entries
  628. * @hal_soc: Opaque HAL SOC handle
  629. * @ring_type: one of the types from hal_ring_type
  630. *
  631. * Return: Maximum number of entries for the given ring_type
  632. */
  633. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  634. void hal_set_low_threshold(hal_ring_handle_t hal_ring_hdl,
  635. uint32_t low_threshold);
  636. /**
  637. * hal_srng_dump - Dump ring status
  638. * @srng: hal srng pointer
  639. */
  640. void hal_srng_dump(struct hal_srng *srng);
  641. /**
  642. * hal_srng_get_dir - Returns the direction of the ring
  643. * @hal_soc: Opaque HAL SOC handle
  644. * @ring_type: one of the types from hal_ring_type
  645. *
  646. * Return: Ring direction
  647. */
  648. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  649. /* HAL memory information */
  650. struct hal_mem_info {
  651. /* dev base virutal addr */
  652. void *dev_base_addr;
  653. /* dev base physical addr */
  654. void *dev_base_paddr;
  655. /* dev base ce virutal addr - applicable only for qca5018 */
  656. /* In qca5018 CE register are outside wcss block */
  657. /* using a separate address space to access CE registers */
  658. void *dev_base_addr_ce;
  659. /* dev base ce physical addr */
  660. void *dev_base_paddr_ce;
  661. /* Remote virtual pointer memory for HW/FW updates */
  662. void *shadow_rdptr_mem_vaddr;
  663. /* Remote physical pointer memory for HW/FW updates */
  664. void *shadow_rdptr_mem_paddr;
  665. /* Shared memory for ring pointer updates from host to FW */
  666. void *shadow_wrptr_mem_vaddr;
  667. /* Shared physical memory for ring pointer updates from host to FW */
  668. void *shadow_wrptr_mem_paddr;
  669. };
  670. /* SRNG parameters to be passed to hal_srng_setup */
  671. struct hal_srng_params {
  672. /* Physical base address of the ring */
  673. qdf_dma_addr_t ring_base_paddr;
  674. /* Virtual base address of the ring */
  675. void *ring_base_vaddr;
  676. /* Number of entries in ring */
  677. uint32_t num_entries;
  678. /* max transfer length */
  679. uint16_t max_buffer_length;
  680. /* MSI Address */
  681. qdf_dma_addr_t msi_addr;
  682. /* MSI data */
  683. uint32_t msi_data;
  684. /* Interrupt timer threshold – in micro seconds */
  685. uint32_t intr_timer_thres_us;
  686. /* Interrupt batch counter threshold – in number of ring entries */
  687. uint32_t intr_batch_cntr_thres_entries;
  688. /* Low threshold – in number of ring entries
  689. * (valid for src rings only)
  690. */
  691. uint32_t low_threshold;
  692. /* Misc flags */
  693. uint32_t flags;
  694. /* Unique ring id */
  695. uint8_t ring_id;
  696. /* Source or Destination ring */
  697. enum hal_srng_dir ring_dir;
  698. /* Size of ring entry */
  699. uint32_t entry_size;
  700. /* hw register base address */
  701. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  702. /* prefetch timer config - in micro seconds */
  703. uint32_t prefetch_timer;
  704. };
  705. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  706. * @hal_soc: hal handle
  707. *
  708. * Return: QDF_STATUS_OK on success
  709. */
  710. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  711. /* hal_set_one_shadow_config() - add a config for the specified ring
  712. * @hal_soc: hal handle
  713. * @ring_type: ring type
  714. * @ring_num: ring num
  715. *
  716. * The ring type and ring num uniquely specify the ring. After this call,
  717. * the hp/tp will be added as the next entry int the shadow register
  718. * configuration table. The hal code will use the shadow register address
  719. * in place of the hp/tp address.
  720. *
  721. * This function is exposed, so that the CE module can skip configuring shadow
  722. * registers for unused ring and rings assigned to the firmware.
  723. *
  724. * Return: QDF_STATUS_OK on success
  725. */
  726. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  727. int ring_num);
  728. /**
  729. * hal_get_shadow_config() - retrieve the config table
  730. * @hal_soc: hal handle
  731. * @shadow_config: will point to the table after
  732. * @num_shadow_registers_configured: will contain the number of valid entries
  733. */
  734. extern void hal_get_shadow_config(void *hal_soc,
  735. struct pld_shadow_reg_v2_cfg **shadow_config,
  736. int *num_shadow_registers_configured);
  737. /**
  738. * hal_srng_setup - Initialize HW SRNG ring.
  739. *
  740. * @hal_soc: Opaque HAL SOC handle
  741. * @ring_type: one of the types from hal_ring_type
  742. * @ring_num: Ring number if there are multiple rings of
  743. * same type (staring from 0)
  744. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  745. * @ring_params: SRNG ring params in hal_srng_params structure.
  746. * Callers are expected to allocate contiguous ring memory of size
  747. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  748. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  749. * structure. Ring base address should be 8 byte aligned and size of each ring
  750. * entry should be queried using the API hal_srng_get_entrysize
  751. *
  752. * Return: Opaque pointer to ring on success
  753. * NULL on failure (if given ring is not available)
  754. */
  755. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  756. int mac_id, struct hal_srng_params *ring_params);
  757. /* Remapping ids of REO rings */
  758. #define REO_REMAP_TCL 0
  759. #define REO_REMAP_SW1 1
  760. #define REO_REMAP_SW2 2
  761. #define REO_REMAP_SW3 3
  762. #define REO_REMAP_SW4 4
  763. #define REO_REMAP_RELEASE 5
  764. #define REO_REMAP_FW 6
  765. #define REO_REMAP_UNUSED 7
  766. /*
  767. * Macro to access HWIO_REO_R0_ERROR_DESTINATION_RING_CTRL_IX_0
  768. * to map destination to rings
  769. */
  770. #define HAL_REO_ERR_REMAP_IX0(_VALUE, _OFFSET) \
  771. ((_VALUE) << \
  772. (HWIO_REO_R0_ERROR_DESTINATION_MAPPING_IX_0_ERROR_ ## \
  773. DESTINATION_RING_ ## _OFFSET ## _SHFT))
  774. /*
  775. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  776. * to map destination to rings
  777. */
  778. #define HAL_REO_REMAP_IX0(_VALUE, _OFFSET) \
  779. ((_VALUE) << \
  780. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  781. _OFFSET ## _SHFT))
  782. /*
  783. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1
  784. * to map destination to rings
  785. */
  786. #define HAL_REO_REMAP_IX2(_VALUE, _OFFSET) \
  787. ((_VALUE) << \
  788. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_DEST_RING_MAPPING_ ## \
  789. _OFFSET ## _SHFT))
  790. /*
  791. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3
  792. * to map destination to rings
  793. */
  794. #define HAL_REO_REMAP_IX3(_VALUE, _OFFSET) \
  795. ((_VALUE) << \
  796. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_DEST_RING_MAPPING_ ## \
  797. _OFFSET ## _SHFT))
  798. /**
  799. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  800. * @hal_soc_hdl: HAL SOC handle
  801. * @read: boolean value to indicate if read or write
  802. * @ix0: pointer to store IX0 reg value
  803. * @ix1: pointer to store IX1 reg value
  804. * @ix2: pointer to store IX2 reg value
  805. * @ix3: pointer to store IX3 reg value
  806. */
  807. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  808. uint32_t *ix0, uint32_t *ix1,
  809. uint32_t *ix2, uint32_t *ix3);
  810. /**
  811. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  812. * @sring: sring pointer
  813. * @paddr: physical address
  814. */
  815. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  816. /**
  817. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  818. * @srng: sring pointer
  819. * @vaddr: virtual address
  820. */
  821. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  822. /**
  823. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  824. * @hal_soc: Opaque HAL SOC handle
  825. * @hal_srng: Opaque HAL SRNG pointer
  826. */
  827. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl);
  828. static inline bool hal_srng_initialized(hal_ring_handle_t hal_ring_hdl)
  829. {
  830. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  831. return !!srng->initialized;
  832. }
  833. /**
  834. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  835. * @hal_soc: Opaque HAL SOC handle
  836. * @hal_ring_hdl: Destination ring pointer
  837. *
  838. * Caller takes responsibility for any locking needs.
  839. *
  840. * Return: Opaque pointer for next ring entry; NULL on failire
  841. */
  842. static inline
  843. void *hal_srng_dst_peek(hal_soc_handle_t hal_soc_hdl,
  844. hal_ring_handle_t hal_ring_hdl)
  845. {
  846. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  847. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  848. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  849. return NULL;
  850. }
  851. /**
  852. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  853. * hal_srng_access_start if locked access is required
  854. *
  855. * @hal_soc: Opaque HAL SOC handle
  856. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  857. *
  858. * Return: 0 on success; error on failire
  859. */
  860. static inline int
  861. hal_srng_access_start_unlocked(hal_soc_handle_t hal_soc_hdl,
  862. hal_ring_handle_t hal_ring_hdl)
  863. {
  864. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  865. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  866. uint32_t *desc;
  867. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  868. srng->u.src_ring.cached_tp =
  869. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  870. else {
  871. srng->u.dst_ring.cached_hp =
  872. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  873. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  874. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  875. if (qdf_likely(desc)) {
  876. qdf_mem_dma_cache_sync(soc->qdf_dev,
  877. qdf_mem_virt_to_phys
  878. (desc),
  879. QDF_DMA_FROM_DEVICE,
  880. (srng->entry_size *
  881. sizeof(uint32_t)));
  882. qdf_prefetch(desc);
  883. }
  884. }
  885. }
  886. return 0;
  887. }
  888. /**
  889. * hal_srng_try_access_start - Try to start (locked) ring access
  890. *
  891. * @hal_soc: Opaque HAL SOC handle
  892. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  893. *
  894. * Return: 0 on success; error on failure
  895. */
  896. static inline int hal_srng_try_access_start(hal_soc_handle_t hal_soc_hdl,
  897. hal_ring_handle_t hal_ring_hdl)
  898. {
  899. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  900. if (qdf_unlikely(!hal_ring_hdl)) {
  901. qdf_print("Error: Invalid hal_ring\n");
  902. return -EINVAL;
  903. }
  904. if (!SRNG_TRY_LOCK(&(srng->lock)))
  905. return -EINVAL;
  906. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  907. }
  908. /**
  909. * hal_srng_access_start - Start (locked) ring access
  910. *
  911. * @hal_soc: Opaque HAL SOC handle
  912. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  913. *
  914. * Return: 0 on success; error on failire
  915. */
  916. static inline int hal_srng_access_start(hal_soc_handle_t hal_soc_hdl,
  917. hal_ring_handle_t hal_ring_hdl)
  918. {
  919. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  920. if (qdf_unlikely(!hal_ring_hdl)) {
  921. qdf_print("Error: Invalid hal_ring\n");
  922. return -EINVAL;
  923. }
  924. SRNG_LOCK(&(srng->lock));
  925. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  926. }
  927. /**
  928. * hal_srng_dst_get_next - Get next entry from a destination ring
  929. * @hal_soc: Opaque HAL SOC handle
  930. * @hal_ring_hdl: Destination ring pointer
  931. *
  932. * Return: Opaque pointer for next ring entry; NULL on failure
  933. */
  934. static inline
  935. void *hal_srng_dst_get_next(void *hal_soc,
  936. hal_ring_handle_t hal_ring_hdl)
  937. {
  938. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  939. uint32_t *desc;
  940. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  941. return NULL;
  942. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  943. /* TODO: Using % is expensive, but we have to do this since
  944. * size of some SRNG rings is not power of 2 (due to descriptor
  945. * sizes). Need to create separate API for rings used
  946. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  947. * SW2RXDMA and CE rings)
  948. */
  949. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  950. if (srng->u.dst_ring.tp == srng->ring_size)
  951. srng->u.dst_ring.tp = 0;
  952. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  953. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  954. uint32_t *desc_next;
  955. uint32_t tp;
  956. tp = srng->u.dst_ring.tp;
  957. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  958. qdf_mem_dma_cache_sync(soc->qdf_dev,
  959. qdf_mem_virt_to_phys(desc_next),
  960. QDF_DMA_FROM_DEVICE,
  961. (srng->entry_size *
  962. sizeof(uint32_t)));
  963. qdf_prefetch(desc_next);
  964. }
  965. return (void *)desc;
  966. }
  967. /**
  968. * hal_srng_dst_get_next_cached - Get cached next entry
  969. * @hal_soc: Opaque HAL SOC handle
  970. * @hal_ring_hdl: Destination ring pointer
  971. *
  972. * Get next entry from a destination ring and move cached tail pointer
  973. *
  974. * Return: Opaque pointer for next ring entry; NULL on failure
  975. */
  976. static inline
  977. void *hal_srng_dst_get_next_cached(void *hal_soc,
  978. hal_ring_handle_t hal_ring_hdl)
  979. {
  980. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  981. uint32_t *desc;
  982. uint32_t *desc_next;
  983. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  984. return NULL;
  985. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  986. /* TODO: Using % is expensive, but we have to do this since
  987. * size of some SRNG rings is not power of 2 (due to descriptor
  988. * sizes). Need to create separate API for rings used
  989. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  990. * SW2RXDMA and CE rings)
  991. */
  992. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  993. if (srng->u.dst_ring.tp == srng->ring_size)
  994. srng->u.dst_ring.tp = 0;
  995. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  996. qdf_prefetch(desc_next);
  997. return (void *)desc;
  998. }
  999. /**
  1000. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  1001. * cached head pointer
  1002. *
  1003. * @hal_soc: Opaque HAL SOC handle
  1004. * @hal_ring_hdl: Destination ring pointer
  1005. *
  1006. * Return: Opaque pointer for next ring entry; NULL on failire
  1007. */
  1008. static inline void *
  1009. hal_srng_dst_get_next_hp(hal_soc_handle_t hal_soc_hdl,
  1010. hal_ring_handle_t hal_ring_hdl)
  1011. {
  1012. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1013. uint32_t *desc;
  1014. /* TODO: Using % is expensive, but we have to do this since
  1015. * size of some SRNG rings is not power of 2 (due to descriptor
  1016. * sizes). Need to create separate API for rings used
  1017. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1018. * SW2RXDMA and CE rings)
  1019. */
  1020. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  1021. srng->ring_size;
  1022. if (next_hp != srng->u.dst_ring.tp) {
  1023. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  1024. srng->u.dst_ring.cached_hp = next_hp;
  1025. return (void *)desc;
  1026. }
  1027. return NULL;
  1028. }
  1029. /**
  1030. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  1031. * @hal_soc: Opaque HAL SOC handle
  1032. * @hal_ring_hdl: Destination ring pointer
  1033. *
  1034. * Sync cached head pointer with HW.
  1035. * Caller takes responsibility for any locking needs.
  1036. *
  1037. * Return: Opaque pointer for next ring entry; NULL on failire
  1038. */
  1039. static inline
  1040. void *hal_srng_dst_peek_sync(hal_soc_handle_t hal_soc_hdl,
  1041. hal_ring_handle_t hal_ring_hdl)
  1042. {
  1043. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1044. srng->u.dst_ring.cached_hp =
  1045. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1046. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  1047. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  1048. return NULL;
  1049. }
  1050. /**
  1051. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  1052. * @hal_soc: Opaque HAL SOC handle
  1053. * @hal_ring_hdl: Destination ring pointer
  1054. *
  1055. * Sync cached head pointer with HW.
  1056. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  1057. *
  1058. * Return: Opaque pointer for next ring entry; NULL on failire
  1059. */
  1060. static inline
  1061. void *hal_srng_dst_peek_sync_locked(hal_soc_handle_t hal_soc_hdl,
  1062. hal_ring_handle_t hal_ring_hdl)
  1063. {
  1064. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1065. void *ring_desc_ptr = NULL;
  1066. if (qdf_unlikely(!hal_ring_hdl)) {
  1067. qdf_print("Error: Invalid hal_ring\n");
  1068. return NULL;
  1069. }
  1070. SRNG_LOCK(&srng->lock);
  1071. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc_hdl, hal_ring_hdl);
  1072. SRNG_UNLOCK(&srng->lock);
  1073. return ring_desc_ptr;
  1074. }
  1075. /**
  1076. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  1077. * by SW) in destination ring
  1078. *
  1079. * @hal_soc: Opaque HAL SOC handle
  1080. * @hal_ring_hdl: Destination ring pointer
  1081. * @sync_hw_ptr: Sync cached head pointer with HW
  1082. *
  1083. */
  1084. static inline
  1085. uint32_t hal_srng_dst_num_valid(void *hal_soc,
  1086. hal_ring_handle_t hal_ring_hdl,
  1087. int sync_hw_ptr)
  1088. {
  1089. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1090. uint32_t hp;
  1091. uint32_t tp = srng->u.dst_ring.tp;
  1092. if (sync_hw_ptr) {
  1093. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1094. srng->u.dst_ring.cached_hp = hp;
  1095. } else {
  1096. hp = srng->u.dst_ring.cached_hp;
  1097. }
  1098. if (hp >= tp)
  1099. return (hp - tp) / srng->entry_size;
  1100. return (srng->ring_size - tp + hp) / srng->entry_size;
  1101. }
  1102. /**
  1103. * hal_srng_dst_inv_cached_descs - API to invalidate descriptors in batch mode
  1104. * @hal_soc: Opaque HAL SOC handle
  1105. * @hal_ring_hdl: Destination ring pointer
  1106. * @entry_count: Number of descriptors to be invalidated
  1107. *
  1108. * Invalidates a set of cached descriptors starting from tail to
  1109. * provided count worth
  1110. *
  1111. * Return - None
  1112. */
  1113. static inline void hal_srng_dst_inv_cached_descs(void *hal_soc,
  1114. hal_ring_handle_t hal_ring_hdl,
  1115. uint32_t entry_count)
  1116. {
  1117. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1118. uint32_t hp = srng->u.dst_ring.cached_hp;
  1119. uint32_t tp = srng->u.dst_ring.tp;
  1120. uint32_t sync_p = 0;
  1121. /*
  1122. * If SRNG does not have cached descriptors this
  1123. * API call should be a no op
  1124. */
  1125. if (!(srng->flags & HAL_SRNG_CACHED_DESC))
  1126. return;
  1127. if (qdf_unlikely(entry_count == 0))
  1128. return;
  1129. sync_p = (entry_count - 1) * srng->entry_size;
  1130. if (hp > tp) {
  1131. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1132. &srng->ring_base_vaddr[tp + sync_p]
  1133. + (srng->entry_size * sizeof(uint32_t)));
  1134. } else {
  1135. /*
  1136. * We have wrapped around
  1137. */
  1138. uint32_t wrap_cnt = ((srng->ring_size - tp) / srng->entry_size);
  1139. if (entry_count <= wrap_cnt) {
  1140. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1141. &srng->ring_base_vaddr[tp + sync_p] +
  1142. (srng->entry_size * sizeof(uint32_t)));
  1143. return;
  1144. }
  1145. entry_count -= wrap_cnt;
  1146. sync_p = (entry_count - 1) * srng->entry_size;
  1147. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1148. &srng->ring_base_vaddr[srng->ring_size - srng->entry_size] +
  1149. (srng->entry_size * sizeof(uint32_t)));
  1150. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[0],
  1151. &srng->ring_base_vaddr[sync_p]
  1152. + (srng->entry_size * sizeof(uint32_t)));
  1153. }
  1154. }
  1155. /**
  1156. * hal_srng_dst_num_valid_locked - Returns num valid entries to be processed
  1157. *
  1158. * @hal_soc: Opaque HAL SOC handle
  1159. * @hal_ring_hdl: Destination ring pointer
  1160. * @sync_hw_ptr: Sync cached head pointer with HW
  1161. *
  1162. * Returns number of valid entries to be processed by the host driver. The
  1163. * function takes up SRNG lock.
  1164. *
  1165. * Return: Number of valid destination entries
  1166. */
  1167. static inline uint32_t
  1168. hal_srng_dst_num_valid_locked(hal_soc_handle_t hal_soc,
  1169. hal_ring_handle_t hal_ring_hdl,
  1170. int sync_hw_ptr)
  1171. {
  1172. uint32_t num_valid;
  1173. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1174. SRNG_LOCK(&srng->lock);
  1175. num_valid = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr);
  1176. SRNG_UNLOCK(&srng->lock);
  1177. return num_valid;
  1178. }
  1179. /**
  1180. * hal_srng_sync_cachedhp - sync cachehp pointer from hw hp
  1181. *
  1182. * @hal_soc: Opaque HAL SOC handle
  1183. * @hal_ring_hdl: Destination ring pointer
  1184. *
  1185. */
  1186. static inline
  1187. void hal_srng_sync_cachedhp(void *hal_soc,
  1188. hal_ring_handle_t hal_ring_hdl)
  1189. {
  1190. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1191. uint32_t hp;
  1192. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1193. srng->u.dst_ring.cached_hp = hp;
  1194. }
  1195. /**
  1196. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  1197. * pointer. This can be used to release any buffers associated with completed
  1198. * ring entries. Note that this should not be used for posting new descriptor
  1199. * entries. Posting of new entries should be done only using
  1200. * hal_srng_src_get_next_reaped when this function is used for reaping.
  1201. *
  1202. * @hal_soc: Opaque HAL SOC handle
  1203. * @hal_ring_hdl: Source ring pointer
  1204. *
  1205. * Return: Opaque pointer for next ring entry; NULL on failire
  1206. */
  1207. static inline void *
  1208. hal_srng_src_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1209. {
  1210. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1211. uint32_t *desc;
  1212. /* TODO: Using % is expensive, but we have to do this since
  1213. * size of some SRNG rings is not power of 2 (due to descriptor
  1214. * sizes). Need to create separate API for rings used
  1215. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1216. * SW2RXDMA and CE rings)
  1217. */
  1218. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1219. srng->ring_size;
  1220. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  1221. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1222. srng->u.src_ring.reap_hp = next_reap_hp;
  1223. return (void *)desc;
  1224. }
  1225. return NULL;
  1226. }
  1227. /**
  1228. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  1229. * already reaped using hal_srng_src_reap_next, for posting new entries to
  1230. * the ring
  1231. *
  1232. * @hal_soc: Opaque HAL SOC handle
  1233. * @hal_ring_hdl: Source ring pointer
  1234. *
  1235. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  1236. */
  1237. static inline void *
  1238. hal_srng_src_get_next_reaped(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1239. {
  1240. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1241. uint32_t *desc;
  1242. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  1243. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1244. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  1245. srng->ring_size;
  1246. return (void *)desc;
  1247. }
  1248. return NULL;
  1249. }
  1250. /**
  1251. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  1252. * move reap pointer. This API is used in detach path to release any buffers
  1253. * associated with ring entries which are pending reap.
  1254. *
  1255. * @hal_soc: Opaque HAL SOC handle
  1256. * @hal_ring_hdl: Source ring pointer
  1257. *
  1258. * Return: Opaque pointer for next ring entry; NULL on failire
  1259. */
  1260. static inline void *
  1261. hal_srng_src_pending_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1262. {
  1263. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1264. uint32_t *desc;
  1265. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1266. srng->ring_size;
  1267. if (next_reap_hp != srng->u.src_ring.hp) {
  1268. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1269. srng->u.src_ring.reap_hp = next_reap_hp;
  1270. return (void *)desc;
  1271. }
  1272. return NULL;
  1273. }
  1274. /**
  1275. * hal_srng_src_done_val -
  1276. *
  1277. * @hal_soc: Opaque HAL SOC handle
  1278. * @hal_ring_hdl: Source ring pointer
  1279. *
  1280. * Return: Opaque pointer for next ring entry; NULL on failire
  1281. */
  1282. static inline uint32_t
  1283. hal_srng_src_done_val(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1284. {
  1285. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1286. /* TODO: Using % is expensive, but we have to do this since
  1287. * size of some SRNG rings is not power of 2 (due to descriptor
  1288. * sizes). Need to create separate API for rings used
  1289. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1290. * SW2RXDMA and CE rings)
  1291. */
  1292. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1293. srng->ring_size;
  1294. if (next_reap_hp == srng->u.src_ring.cached_tp)
  1295. return 0;
  1296. if (srng->u.src_ring.cached_tp > next_reap_hp)
  1297. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  1298. srng->entry_size;
  1299. else
  1300. return ((srng->ring_size - next_reap_hp) +
  1301. srng->u.src_ring.cached_tp) / srng->entry_size;
  1302. }
  1303. /**
  1304. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  1305. * @hal_ring_hdl: Source ring pointer
  1306. *
  1307. * Return: uint8_t
  1308. */
  1309. static inline
  1310. uint8_t hal_get_entrysize_from_srng(hal_ring_handle_t hal_ring_hdl)
  1311. {
  1312. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1313. return srng->entry_size;
  1314. }
  1315. /**
  1316. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  1317. * @hal_soc: Opaque HAL SOC handle
  1318. * @hal_ring_hdl: Source ring pointer
  1319. * @tailp: Tail Pointer
  1320. * @headp: Head Pointer
  1321. *
  1322. * Return: Update tail pointer and head pointer in arguments.
  1323. */
  1324. static inline
  1325. void hal_get_sw_hptp(void *hal_soc, hal_ring_handle_t hal_ring_hdl,
  1326. uint32_t *tailp, uint32_t *headp)
  1327. {
  1328. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1329. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1330. *headp = srng->u.src_ring.hp;
  1331. *tailp = *srng->u.src_ring.tp_addr;
  1332. } else {
  1333. *tailp = srng->u.dst_ring.tp;
  1334. *headp = *srng->u.dst_ring.hp_addr;
  1335. }
  1336. }
  1337. /**
  1338. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  1339. *
  1340. * @hal_soc: Opaque HAL SOC handle
  1341. * @hal_ring_hdl: Source ring pointer
  1342. *
  1343. * Return: Opaque pointer for next ring entry; NULL on failire
  1344. */
  1345. static inline
  1346. void *hal_srng_src_get_next(void *hal_soc,
  1347. hal_ring_handle_t hal_ring_hdl)
  1348. {
  1349. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1350. uint32_t *desc;
  1351. /* TODO: Using % is expensive, but we have to do this since
  1352. * size of some SRNG rings is not power of 2 (due to descriptor
  1353. * sizes). Need to create separate API for rings used
  1354. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1355. * SW2RXDMA and CE rings)
  1356. */
  1357. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1358. srng->ring_size;
  1359. if (next_hp != srng->u.src_ring.cached_tp) {
  1360. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1361. srng->u.src_ring.hp = next_hp;
  1362. /* TODO: Since reap function is not used by all rings, we can
  1363. * remove the following update of reap_hp in this function
  1364. * if we can ensure that only hal_srng_src_get_next_reaped
  1365. * is used for the rings requiring reap functionality
  1366. */
  1367. srng->u.src_ring.reap_hp = next_hp;
  1368. return (void *)desc;
  1369. }
  1370. return NULL;
  1371. }
  1372. /**
  1373. * hal_srng_src_peek_n_get_next - Get next entry from a ring without
  1374. * moving head pointer.
  1375. * hal_srng_src_get_next should be called subsequently to move the head pointer
  1376. *
  1377. * @hal_soc: Opaque HAL SOC handle
  1378. * @hal_ring_hdl: Source ring pointer
  1379. *
  1380. * Return: Opaque pointer for next ring entry; NULL on failire
  1381. */
  1382. static inline
  1383. void *hal_srng_src_peek_n_get_next(hal_soc_handle_t hal_soc_hdl,
  1384. hal_ring_handle_t hal_ring_hdl)
  1385. {
  1386. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1387. uint32_t *desc;
  1388. /* TODO: Using % is expensive, but we have to do this since
  1389. * size of some SRNG rings is not power of 2 (due to descriptor
  1390. * sizes). Need to create separate API for rings used
  1391. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1392. * SW2RXDMA and CE rings)
  1393. */
  1394. if (((srng->u.src_ring.hp + srng->entry_size) %
  1395. srng->ring_size) != srng->u.src_ring.cached_tp) {
  1396. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1397. srng->entry_size) %
  1398. srng->ring_size]);
  1399. return (void *)desc;
  1400. }
  1401. return NULL;
  1402. }
  1403. /**
  1404. * hal_srng_src_peek_n_get_next_next - Get next to next, i.e HP + 2 entry
  1405. * from a ring without moving head pointer.
  1406. *
  1407. * @hal_soc: Opaque HAL SOC handle
  1408. * @hal_ring_hdl: Source ring pointer
  1409. *
  1410. * Return: Opaque pointer for next to next ring entry; NULL on failire
  1411. */
  1412. static inline
  1413. void *hal_srng_src_peek_n_get_next_next(hal_soc_handle_t hal_soc_hdl,
  1414. hal_ring_handle_t hal_ring_hdl)
  1415. {
  1416. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1417. uint32_t *desc;
  1418. /* TODO: Using % is expensive, but we have to do this since
  1419. * size of some SRNG rings is not power of 2 (due to descriptor
  1420. * sizes). Need to create separate API for rings used
  1421. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1422. * SW2RXDMA and CE rings)
  1423. */
  1424. if ((((srng->u.src_ring.hp + (srng->entry_size)) %
  1425. srng->ring_size) != srng->u.src_ring.cached_tp) &&
  1426. (((srng->u.src_ring.hp + (srng->entry_size * 2)) %
  1427. srng->ring_size) != srng->u.src_ring.cached_tp)) {
  1428. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1429. (srng->entry_size * 2)) %
  1430. srng->ring_size]);
  1431. return (void *)desc;
  1432. }
  1433. return NULL;
  1434. }
  1435. /**
  1436. * hal_srng_src_get_cur_hp_n_move_next () - API returns current hp
  1437. * and move hp to next in src ring
  1438. *
  1439. * Usage: This API should only be used at init time replenish.
  1440. *
  1441. * @hal_soc_hdl: HAL soc handle
  1442. * @hal_ring_hdl: Source ring pointer
  1443. *
  1444. */
  1445. static inline void *
  1446. hal_srng_src_get_cur_hp_n_move_next(hal_soc_handle_t hal_soc_hdl,
  1447. hal_ring_handle_t hal_ring_hdl)
  1448. {
  1449. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1450. uint32_t *cur_desc = NULL;
  1451. uint32_t next_hp;
  1452. cur_desc = &srng->ring_base_vaddr[(srng->u.src_ring.hp)];
  1453. next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1454. srng->ring_size;
  1455. if (next_hp != srng->u.src_ring.cached_tp)
  1456. srng->u.src_ring.hp = next_hp;
  1457. return (void *)cur_desc;
  1458. }
  1459. /**
  1460. * hal_srng_src_num_avail - Returns number of available entries in src ring
  1461. *
  1462. * @hal_soc: Opaque HAL SOC handle
  1463. * @hal_ring_hdl: Source ring pointer
  1464. * @sync_hw_ptr: Sync cached tail pointer with HW
  1465. *
  1466. */
  1467. static inline uint32_t
  1468. hal_srng_src_num_avail(void *hal_soc,
  1469. hal_ring_handle_t hal_ring_hdl, int sync_hw_ptr)
  1470. {
  1471. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1472. uint32_t tp;
  1473. uint32_t hp = srng->u.src_ring.hp;
  1474. if (sync_hw_ptr) {
  1475. tp = *(srng->u.src_ring.tp_addr);
  1476. srng->u.src_ring.cached_tp = tp;
  1477. } else {
  1478. tp = srng->u.src_ring.cached_tp;
  1479. }
  1480. if (tp > hp)
  1481. return ((tp - hp) / srng->entry_size) - 1;
  1482. else
  1483. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  1484. }
  1485. /**
  1486. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  1487. * ring head/tail pointers to HW.
  1488. * This should be used only if hal_srng_access_start_unlocked to start ring
  1489. * access
  1490. *
  1491. * @hal_soc: Opaque HAL SOC handle
  1492. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1493. *
  1494. * Return: 0 on success; error on failire
  1495. */
  1496. static inline void
  1497. hal_srng_access_end_unlocked(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1498. {
  1499. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1500. /* TODO: See if we need a write memory barrier here */
  1501. if (srng->flags & HAL_SRNG_LMAC_RING) {
  1502. /* For LMAC rings, ring pointer updates are done through FW and
  1503. * hence written to a shared memory location that is read by FW
  1504. */
  1505. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1506. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  1507. } else {
  1508. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  1509. }
  1510. } else {
  1511. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1512. hal_srng_write_address_32_mb(hal_soc,
  1513. srng,
  1514. srng->u.src_ring.hp_addr,
  1515. srng->u.src_ring.hp);
  1516. else
  1517. hal_srng_write_address_32_mb(hal_soc,
  1518. srng,
  1519. srng->u.dst_ring.tp_addr,
  1520. srng->u.dst_ring.tp);
  1521. }
  1522. }
  1523. /**
  1524. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  1525. * pointers to HW
  1526. * This should be used only if hal_srng_access_start to start ring access
  1527. *
  1528. * @hal_soc: Opaque HAL SOC handle
  1529. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1530. *
  1531. * Return: 0 on success; error on failire
  1532. */
  1533. static inline void
  1534. hal_srng_access_end(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1535. {
  1536. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1537. if (qdf_unlikely(!hal_ring_hdl)) {
  1538. qdf_print("Error: Invalid hal_ring\n");
  1539. return;
  1540. }
  1541. hal_srng_access_end_unlocked(hal_soc, hal_ring_hdl);
  1542. SRNG_UNLOCK(&(srng->lock));
  1543. }
  1544. /**
  1545. * hal_srng_access_end_reap - Unlock ring access
  1546. * This should be used only if hal_srng_access_start to start ring access
  1547. * and should be used only while reaping SRC ring completions
  1548. *
  1549. * @hal_soc: Opaque HAL SOC handle
  1550. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1551. *
  1552. * Return: 0 on success; error on failire
  1553. */
  1554. static inline void
  1555. hal_srng_access_end_reap(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1556. {
  1557. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1558. SRNG_UNLOCK(&(srng->lock));
  1559. }
  1560. /* TODO: Check if the following definitions is available in HW headers */
  1561. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  1562. #define NUM_MPDUS_PER_LINK_DESC 6
  1563. #define NUM_MSDUS_PER_LINK_DESC 7
  1564. #define REO_QUEUE_DESC_ALIGN 128
  1565. #define LINK_DESC_ALIGN 128
  1566. #define ADDRESS_MATCH_TAG_VAL 0x5
  1567. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  1568. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  1569. */
  1570. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  1571. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  1572. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  1573. * should be specified in 16 word units. But the number of bits defined for
  1574. * this field in HW header files is 5.
  1575. */
  1576. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  1577. /**
  1578. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  1579. * in an idle list
  1580. *
  1581. * @hal_soc: Opaque HAL SOC handle
  1582. *
  1583. */
  1584. static inline
  1585. uint32_t hal_idle_list_scatter_buf_size(hal_soc_handle_t hal_soc_hdl)
  1586. {
  1587. return WBM_IDLE_SCATTER_BUF_SIZE;
  1588. }
  1589. /**
  1590. * hal_get_link_desc_size - Get the size of each link descriptor
  1591. *
  1592. * @hal_soc: Opaque HAL SOC handle
  1593. *
  1594. */
  1595. static inline uint32_t hal_get_link_desc_size(hal_soc_handle_t hal_soc_hdl)
  1596. {
  1597. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1598. if (!hal_soc || !hal_soc->ops) {
  1599. qdf_print("Error: Invalid ops\n");
  1600. QDF_BUG(0);
  1601. return -EINVAL;
  1602. }
  1603. if (!hal_soc->ops->hal_get_link_desc_size) {
  1604. qdf_print("Error: Invalid function pointer\n");
  1605. QDF_BUG(0);
  1606. return -EINVAL;
  1607. }
  1608. return hal_soc->ops->hal_get_link_desc_size();
  1609. }
  1610. /**
  1611. * hal_get_link_desc_align - Get the required start address alignment for
  1612. * link descriptors
  1613. *
  1614. * @hal_soc: Opaque HAL SOC handle
  1615. *
  1616. */
  1617. static inline
  1618. uint32_t hal_get_link_desc_align(hal_soc_handle_t hal_soc_hdl)
  1619. {
  1620. return LINK_DESC_ALIGN;
  1621. }
  1622. /**
  1623. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  1624. *
  1625. * @hal_soc: Opaque HAL SOC handle
  1626. *
  1627. */
  1628. static inline
  1629. uint32_t hal_num_mpdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1630. {
  1631. return NUM_MPDUS_PER_LINK_DESC;
  1632. }
  1633. /**
  1634. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  1635. *
  1636. * @hal_soc: Opaque HAL SOC handle
  1637. *
  1638. */
  1639. static inline
  1640. uint32_t hal_num_msdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1641. {
  1642. return NUM_MSDUS_PER_LINK_DESC;
  1643. }
  1644. /**
  1645. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1646. * descriptor can hold
  1647. *
  1648. * @hal_soc: Opaque HAL SOC handle
  1649. *
  1650. */
  1651. static inline
  1652. uint32_t hal_num_mpdu_links_per_queue_desc(hal_soc_handle_t hal_soc_hdl)
  1653. {
  1654. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1655. }
  1656. /**
  1657. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1658. * that the given buffer size
  1659. *
  1660. * @hal_soc: Opaque HAL SOC handle
  1661. * @scatter_buf_size: Size of scatter buffer
  1662. *
  1663. */
  1664. static inline
  1665. uint32_t hal_idle_scatter_buf_num_entries(hal_soc_handle_t hal_soc_hdl,
  1666. uint32_t scatter_buf_size)
  1667. {
  1668. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1669. hal_srng_get_entrysize(hal_soc_hdl, WBM_IDLE_LINK);
  1670. }
  1671. /**
  1672. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1673. * each given buffer size
  1674. *
  1675. * @hal_soc: Opaque HAL SOC handle
  1676. * @total_mem: size of memory to be scattered
  1677. * @scatter_buf_size: Size of scatter buffer
  1678. *
  1679. */
  1680. static inline
  1681. uint32_t hal_idle_list_num_scatter_bufs(hal_soc_handle_t hal_soc_hdl,
  1682. uint32_t total_mem,
  1683. uint32_t scatter_buf_size)
  1684. {
  1685. uint8_t rem = (total_mem % (scatter_buf_size -
  1686. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1687. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1688. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1689. return num_scatter_bufs;
  1690. }
  1691. enum hal_pn_type {
  1692. HAL_PN_NONE,
  1693. HAL_PN_WPA,
  1694. HAL_PN_WAPI_EVEN,
  1695. HAL_PN_WAPI_UNEVEN,
  1696. };
  1697. #define HAL_RX_MAX_BA_WINDOW 256
  1698. /**
  1699. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1700. * queue descriptors
  1701. *
  1702. * @hal_soc: Opaque HAL SOC handle
  1703. *
  1704. */
  1705. static inline
  1706. uint32_t hal_get_reo_qdesc_align(hal_soc_handle_t hal_soc_hdl)
  1707. {
  1708. return REO_QUEUE_DESC_ALIGN;
  1709. }
  1710. /**
  1711. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1712. *
  1713. * @hal_soc: Opaque HAL SOC handle
  1714. * @ba_window_size: BlockAck window size
  1715. * @start_seq: Starting sequence number
  1716. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1717. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1718. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1719. *
  1720. */
  1721. void hal_reo_qdesc_setup(hal_soc_handle_t hal_soc_hdl,
  1722. int tid, uint32_t ba_window_size,
  1723. uint32_t start_seq, void *hw_qdesc_vaddr,
  1724. qdf_dma_addr_t hw_qdesc_paddr,
  1725. int pn_type);
  1726. /**
  1727. * hal_srng_get_hp_addr - Get head pointer physical address
  1728. *
  1729. * @hal_soc: Opaque HAL SOC handle
  1730. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1731. *
  1732. */
  1733. static inline qdf_dma_addr_t
  1734. hal_srng_get_hp_addr(void *hal_soc,
  1735. hal_ring_handle_t hal_ring_hdl)
  1736. {
  1737. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1738. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1739. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1740. return hal->shadow_wrptr_mem_paddr +
  1741. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1742. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1743. } else {
  1744. return hal->shadow_rdptr_mem_paddr +
  1745. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1746. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1747. }
  1748. }
  1749. /**
  1750. * hal_srng_get_tp_addr - Get tail pointer physical address
  1751. *
  1752. * @hal_soc: Opaque HAL SOC handle
  1753. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1754. *
  1755. */
  1756. static inline qdf_dma_addr_t
  1757. hal_srng_get_tp_addr(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1758. {
  1759. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1760. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1761. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1762. return hal->shadow_rdptr_mem_paddr +
  1763. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1764. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1765. } else {
  1766. return hal->shadow_wrptr_mem_paddr +
  1767. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1768. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1769. }
  1770. }
  1771. /**
  1772. * hal_srng_get_num_entries - Get total entries in the HAL Srng
  1773. *
  1774. * @hal_soc: Opaque HAL SOC handle
  1775. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1776. *
  1777. * Return: total number of entries in hal ring
  1778. */
  1779. static inline
  1780. uint32_t hal_srng_get_num_entries(hal_soc_handle_t hal_soc_hdl,
  1781. hal_ring_handle_t hal_ring_hdl)
  1782. {
  1783. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1784. return srng->num_entries;
  1785. }
  1786. /**
  1787. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1788. *
  1789. * @hal_soc: Opaque HAL SOC handle
  1790. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1791. * @ring_params: SRNG parameters will be returned through this structure
  1792. */
  1793. void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  1794. hal_ring_handle_t hal_ring_hdl,
  1795. struct hal_srng_params *ring_params);
  1796. /**
  1797. * hal_mem_info - Retrieve hal memory base address
  1798. *
  1799. * @hal_soc: Opaque HAL SOC handle
  1800. * @mem: pointer to structure to be updated with hal mem info
  1801. */
  1802. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem);
  1803. /**
  1804. * hal_get_target_type - Return target type
  1805. *
  1806. * @hal_soc: Opaque HAL SOC handle
  1807. */
  1808. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl);
  1809. /**
  1810. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1811. *
  1812. * @hal_soc: Opaque HAL SOC handle
  1813. * @ac: Access category
  1814. * @value: timeout duration in millisec
  1815. */
  1816. void hal_get_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1817. uint32_t *value);
  1818. /**
  1819. * hal_set_aging_timeout - Set BA aging timeout
  1820. *
  1821. * @hal_soc: Opaque HAL SOC handle
  1822. * @ac: Access category in millisec
  1823. * @value: timeout duration value
  1824. */
  1825. void hal_set_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  1826. uint32_t value);
  1827. /**
  1828. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1829. * destination ring HW
  1830. * @hal_soc: HAL SOC handle
  1831. * @srng: SRNG ring pointer
  1832. */
  1833. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1834. struct hal_srng *srng)
  1835. {
  1836. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1837. }
  1838. /**
  1839. * hal_srng_src_hw_init - Private function to initialize SRNG
  1840. * source ring HW
  1841. * @hal_soc: HAL SOC handle
  1842. * @srng: SRNG ring pointer
  1843. */
  1844. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1845. struct hal_srng *srng)
  1846. {
  1847. hal->ops->hal_srng_src_hw_init(hal, srng);
  1848. }
  1849. /**
  1850. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  1851. * @hal_soc: Opaque HAL SOC handle
  1852. * @hal_ring_hdl: Source ring pointer
  1853. * @headp: Head Pointer
  1854. * @tailp: Tail Pointer
  1855. * @ring_type: Ring
  1856. *
  1857. * Return: Update tail pointer and head pointer in arguments.
  1858. */
  1859. static inline
  1860. void hal_get_hw_hptp(hal_soc_handle_t hal_soc_hdl,
  1861. hal_ring_handle_t hal_ring_hdl,
  1862. uint32_t *headp, uint32_t *tailp,
  1863. uint8_t ring_type)
  1864. {
  1865. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1866. hal_soc->ops->hal_get_hw_hptp(hal_soc, hal_ring_hdl,
  1867. headp, tailp, ring_type);
  1868. }
  1869. /**
  1870. * hal_reo_setup - Initialize HW REO block
  1871. *
  1872. * @hal_soc: Opaque HAL SOC handle
  1873. * @reo_params: parameters needed by HAL for REO config
  1874. */
  1875. static inline void hal_reo_setup(hal_soc_handle_t hal_soc_hdl,
  1876. void *reoparams)
  1877. {
  1878. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1879. hal_soc->ops->hal_reo_setup(hal_soc, reoparams);
  1880. }
  1881. static inline
  1882. void hal_compute_reo_remap_ix2_ix3(hal_soc_handle_t hal_soc_hdl,
  1883. uint32_t *ring, uint32_t num_rings,
  1884. uint32_t *remap1, uint32_t *remap2)
  1885. {
  1886. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1887. return hal_soc->ops->hal_compute_reo_remap_ix2_ix3(ring,
  1888. num_rings, remap1, remap2);
  1889. }
  1890. /**
  1891. * hal_setup_link_idle_list - Setup scattered idle list using the
  1892. * buffer list provided
  1893. *
  1894. * @hal_soc: Opaque HAL SOC handle
  1895. * @scatter_bufs_base_paddr: Array of physical base addresses
  1896. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1897. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1898. * @scatter_buf_size: Size of each scatter buffer
  1899. * @last_buf_end_offset: Offset to the last entry
  1900. * @num_entries: Total entries of all scatter bufs
  1901. *
  1902. */
  1903. static inline
  1904. void hal_setup_link_idle_list(hal_soc_handle_t hal_soc_hdl,
  1905. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1906. void *scatter_bufs_base_vaddr[],
  1907. uint32_t num_scatter_bufs,
  1908. uint32_t scatter_buf_size,
  1909. uint32_t last_buf_end_offset,
  1910. uint32_t num_entries)
  1911. {
  1912. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1913. hal_soc->ops->hal_setup_link_idle_list(hal_soc, scatter_bufs_base_paddr,
  1914. scatter_bufs_base_vaddr, num_scatter_bufs,
  1915. scatter_buf_size, last_buf_end_offset,
  1916. num_entries);
  1917. }
  1918. /**
  1919. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  1920. *
  1921. * @hal_soc: Opaque HAL SOC handle
  1922. * @hal_ring_hdl: Source ring pointer
  1923. * @ring_desc: Opaque ring descriptor handle
  1924. */
  1925. static inline void hal_srng_dump_ring_desc(hal_soc_handle_t hal_soc_hdl,
  1926. hal_ring_handle_t hal_ring_hdl,
  1927. hal_ring_desc_t ring_desc)
  1928. {
  1929. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1930. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1931. ring_desc, (srng->entry_size << 2));
  1932. }
  1933. /**
  1934. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  1935. *
  1936. * @hal_soc: Opaque HAL SOC handle
  1937. * @hal_ring_hdl: Source ring pointer
  1938. */
  1939. static inline void hal_srng_dump_ring(hal_soc_handle_t hal_soc_hdl,
  1940. hal_ring_handle_t hal_ring_hdl)
  1941. {
  1942. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1943. uint32_t *desc;
  1944. uint32_t tp, i;
  1945. tp = srng->u.dst_ring.tp;
  1946. for (i = 0; i < 128; i++) {
  1947. if (!tp)
  1948. tp = srng->ring_size;
  1949. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  1950. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  1951. QDF_TRACE_LEVEL_DEBUG,
  1952. desc, (srng->entry_size << 2));
  1953. tp -= srng->entry_size;
  1954. }
  1955. }
  1956. /*
  1957. * hal_rxdma_desc_to_hal_ring_desc - API to convert rxdma ring desc
  1958. * to opaque dp_ring desc type
  1959. * @ring_desc - rxdma ring desc
  1960. *
  1961. * Return: hal_rxdma_desc_t type
  1962. */
  1963. static inline
  1964. hal_ring_desc_t hal_rxdma_desc_to_hal_ring_desc(hal_rxdma_desc_t ring_desc)
  1965. {
  1966. return (hal_ring_desc_t)ring_desc;
  1967. }
  1968. /**
  1969. * hal_srng_set_event() - Set hal_srng event
  1970. * @hal_ring_hdl: Source ring pointer
  1971. * @event: SRNG ring event
  1972. *
  1973. * Return: None
  1974. */
  1975. static inline void hal_srng_set_event(hal_ring_handle_t hal_ring_hdl, int event)
  1976. {
  1977. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1978. qdf_atomic_set_bit(event, &srng->srng_event);
  1979. }
  1980. /**
  1981. * hal_srng_clear_event() - Clear hal_srng event
  1982. * @hal_ring_hdl: Source ring pointer
  1983. * @event: SRNG ring event
  1984. *
  1985. * Return: None
  1986. */
  1987. static inline
  1988. void hal_srng_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  1989. {
  1990. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1991. qdf_atomic_clear_bit(event, &srng->srng_event);
  1992. }
  1993. /**
  1994. * hal_srng_get_clear_event() - Clear srng event and return old value
  1995. * @hal_ring_hdl: Source ring pointer
  1996. * @event: SRNG ring event
  1997. *
  1998. * Return: Return old event value
  1999. */
  2000. static inline
  2001. int hal_srng_get_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  2002. {
  2003. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2004. return qdf_atomic_test_and_clear_bit(event, &srng->srng_event);
  2005. }
  2006. /**
  2007. * hal_srng_set_flush_last_ts() - Record last flush time stamp
  2008. * @hal_ring_hdl: Source ring pointer
  2009. *
  2010. * Return: None
  2011. */
  2012. static inline void hal_srng_set_flush_last_ts(hal_ring_handle_t hal_ring_hdl)
  2013. {
  2014. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2015. srng->last_flush_ts = qdf_get_log_timestamp();
  2016. }
  2017. /**
  2018. * hal_srng_inc_flush_cnt() - Increment flush counter
  2019. * @hal_ring_hdl: Source ring pointer
  2020. *
  2021. * Return: None
  2022. */
  2023. static inline void hal_srng_inc_flush_cnt(hal_ring_handle_t hal_ring_hdl)
  2024. {
  2025. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2026. srng->flush_count++;
  2027. }
  2028. /**
  2029. * hal_rx_sw_mon_desc_info_get () - Get SW monitor desc info
  2030. *
  2031. * @hal: Core HAL soc handle
  2032. * @ring_desc: Mon dest ring descriptor
  2033. * @desc_info: Desc info to be populated
  2034. *
  2035. * Return void
  2036. */
  2037. static inline void
  2038. hal_rx_sw_mon_desc_info_get(struct hal_soc *hal,
  2039. hal_ring_desc_t ring_desc,
  2040. hal_rx_mon_desc_info_t desc_info)
  2041. {
  2042. return hal->ops->hal_rx_sw_mon_desc_info_get(ring_desc, desc_info);
  2043. }
  2044. /**
  2045. * hal_reo_set_err_dst_remap() - Set REO error destination ring remap
  2046. * register value.
  2047. *
  2048. * @hal_soc_hdl: Opaque HAL soc handle
  2049. *
  2050. * Return: None
  2051. */
  2052. static inline void hal_reo_set_err_dst_remap(hal_soc_handle_t hal_soc_hdl)
  2053. {
  2054. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2055. if (hal_soc->ops->hal_reo_set_err_dst_remap)
  2056. hal_soc->ops->hal_reo_set_err_dst_remap(hal_soc);
  2057. }
  2058. #endif /* _HAL_APIH_ */