hal_api.h 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef _HAL_API_H_
  20. #define _HAL_API_H_
  21. #include "qdf_types.h"
  22. #include "qdf_util.h"
  23. #include "qdf_atomic.h"
  24. #include "hal_internal.h"
  25. #include "hif.h"
  26. #include "hif_io32.h"
  27. #include "qdf_platform.h"
  28. #ifdef DUMP_REO_QUEUE_INFO_IN_DDR
  29. #include "hal_hw_headers.h"
  30. #endif
  31. /* Ring index for WBM2SW2 release ring */
  32. #define HAL_IPA_TX_COMP_RING_IDX 2
  33. /* calculate the register address offset from bar0 of shadow register x */
  34. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490) || \
  35. defined(QCA_WIFI_KIWI)
  36. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x000008FC
  37. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  38. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  39. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  40. #elif defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCN9000)
  41. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x00003024
  42. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  43. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  44. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  45. #elif defined(QCA_WIFI_QCA6750)
  46. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x00000504
  47. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  48. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  49. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  50. #else
  51. #define SHADOW_REGISTER(x) 0
  52. #endif /* QCA_WIFI_QCA6390 || QCA_WIFI_QCA6490 || QCA_WIFI_QCA6750 */
  53. /*
  54. * BAR + 4K is always accessible, any access outside this
  55. * space requires force wake procedure.
  56. * OFFSET = 4K - 32 bytes = 0xFE0
  57. */
  58. #define MAPPED_REF_OFF 0xFE0
  59. #define HAL_OFFSET(block, field) block ## _ ## field ## _OFFSET
  60. #ifdef ENABLE_VERBOSE_DEBUG
  61. static inline void
  62. hal_set_verbose_debug(bool flag)
  63. {
  64. is_hal_verbose_debug_enabled = flag;
  65. }
  66. #endif
  67. #ifdef ENABLE_HAL_SOC_STATS
  68. #define HAL_STATS_INC(_handle, _field, _delta) \
  69. { \
  70. if (likely(_handle)) \
  71. _handle->stats._field += _delta; \
  72. }
  73. #else
  74. #define HAL_STATS_INC(_handle, _field, _delta)
  75. #endif
  76. #ifdef ENABLE_HAL_REG_WR_HISTORY
  77. #define HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, wr_val, rd_val) \
  78. hal_reg_wr_fail_history_add(hal_soc, offset, wr_val, rd_val)
  79. void hal_reg_wr_fail_history_add(struct hal_soc *hal_soc,
  80. uint32_t offset,
  81. uint32_t wr_val,
  82. uint32_t rd_val);
  83. static inline int hal_history_get_next_index(qdf_atomic_t *table_index,
  84. int array_size)
  85. {
  86. int record_index = qdf_atomic_inc_return(table_index);
  87. return record_index & (array_size - 1);
  88. }
  89. #else
  90. #define HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, wr_val, rd_val) \
  91. hal_err("write failed at reg offset 0x%x, write 0x%x read 0x%x\n", \
  92. offset, \
  93. wr_val, \
  94. rd_val)
  95. #endif
  96. /**
  97. * hal_reg_write_result_check() - check register writing result
  98. * @hal_soc: HAL soc handle
  99. * @offset: register offset to read
  100. * @exp_val: the expected value of register
  101. * @ret_confirm: result confirm flag
  102. *
  103. * Return: none
  104. */
  105. static inline void hal_reg_write_result_check(struct hal_soc *hal_soc,
  106. uint32_t offset,
  107. uint32_t exp_val)
  108. {
  109. uint32_t value;
  110. value = qdf_ioread32(hal_soc->dev_base_addr + offset);
  111. if (exp_val != value) {
  112. HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, exp_val, value);
  113. HAL_STATS_INC(hal_soc, reg_write_fail, 1);
  114. }
  115. }
  116. #ifdef WINDOW_REG_PLD_LOCK_ENABLE
  117. static inline void hal_lock_reg_access(struct hal_soc *soc,
  118. unsigned long *flags)
  119. {
  120. pld_lock_reg_window(soc->qdf_dev->dev, flags);
  121. }
  122. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  123. unsigned long *flags)
  124. {
  125. pld_unlock_reg_window(soc->qdf_dev->dev, flags);
  126. }
  127. #else
  128. static inline void hal_lock_reg_access(struct hal_soc *soc,
  129. unsigned long *flags)
  130. {
  131. qdf_spin_lock_irqsave(&soc->register_access_lock);
  132. }
  133. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  134. unsigned long *flags)
  135. {
  136. qdf_spin_unlock_irqrestore(&soc->register_access_lock);
  137. }
  138. #endif
  139. #ifdef PCIE_REG_WINDOW_LOCAL_NO_CACHE
  140. /**
  141. * hal_select_window_confirm() - write remap window register and
  142. check writing result
  143. *
  144. */
  145. static inline void hal_select_window_confirm(struct hal_soc *hal_soc,
  146. uint32_t offset)
  147. {
  148. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  149. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  150. WINDOW_ENABLE_BIT | window);
  151. hal_soc->register_window = window;
  152. hal_reg_write_result_check(hal_soc, WINDOW_REG_ADDRESS,
  153. WINDOW_ENABLE_BIT | window);
  154. }
  155. #else
  156. static inline void hal_select_window_confirm(struct hal_soc *hal_soc,
  157. uint32_t offset)
  158. {
  159. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  160. if (window != hal_soc->register_window) {
  161. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  162. WINDOW_ENABLE_BIT | window);
  163. hal_soc->register_window = window;
  164. hal_reg_write_result_check(
  165. hal_soc,
  166. WINDOW_REG_ADDRESS,
  167. WINDOW_ENABLE_BIT | window);
  168. }
  169. }
  170. #endif
  171. static inline qdf_iomem_t hal_get_window_address(struct hal_soc *hal_soc,
  172. qdf_iomem_t addr)
  173. {
  174. return hal_soc->ops->hal_get_window_address(hal_soc, addr);
  175. }
  176. static inline void hal_tx_init_cmd_credit_ring(hal_soc_handle_t hal_soc_hdl,
  177. hal_ring_handle_t hal_ring_hdl)
  178. {
  179. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  180. return hal_soc->ops->hal_tx_init_cmd_credit_ring(hal_soc_hdl,
  181. hal_ring_hdl);
  182. }
  183. /**
  184. * hal_write32_mb() - Access registers to update configuration
  185. * @hal_soc: hal soc handle
  186. * @offset: offset address from the BAR
  187. * @value: value to write
  188. *
  189. * Return: None
  190. *
  191. * Description: Register address space is split below:
  192. * SHADOW REGION UNWINDOWED REGION WINDOWED REGION
  193. * |--------------------|-------------------|------------------|
  194. * BAR NO FORCE WAKE BAR+4K FORCE WAKE BAR+512K FORCE WAKE
  195. *
  196. * 1. Any access to the shadow region, doesn't need force wake
  197. * and windowing logic to access.
  198. * 2. Any access beyond BAR + 4K:
  199. * If init_phase enabled, no force wake is needed and access
  200. * should be based on windowed or unwindowed access.
  201. * If init_phase disabled, force wake is needed and access
  202. * should be based on windowed or unwindowed access.
  203. *
  204. * note1: WINDOW_RANGE_MASK = (1 << WINDOW_SHIFT) -1
  205. * note2: 1 << WINDOW_SHIFT = MAX_UNWINDOWED_ADDRESS
  206. * note3: WINDOW_VALUE_MASK = big enough that trying to write past
  207. * that window would be a bug
  208. */
  209. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) && \
  210. !defined(QCA_WIFI_QCA6750) && !defined(QCA_WIFI_KIWI)
  211. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  212. uint32_t value)
  213. {
  214. unsigned long flags;
  215. qdf_iomem_t new_addr;
  216. if (!hal_soc->use_register_windowing ||
  217. offset < MAX_UNWINDOWED_ADDRESS) {
  218. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  219. } else if (hal_soc->static_window_map) {
  220. new_addr = hal_get_window_address(hal_soc,
  221. hal_soc->dev_base_addr + offset);
  222. qdf_iowrite32(new_addr, value);
  223. } else {
  224. hal_lock_reg_access(hal_soc, &flags);
  225. hal_select_window_confirm(hal_soc, offset);
  226. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  227. (offset & WINDOW_RANGE_MASK), value);
  228. hal_unlock_reg_access(hal_soc, &flags);
  229. }
  230. }
  231. #define hal_write32_mb_confirm(_hal_soc, _offset, _value) \
  232. hal_write32_mb(_hal_soc, _offset, _value)
  233. #define hal_write32_mb_cmem(_hal_soc, _offset, _value)
  234. #else
  235. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  236. uint32_t value)
  237. {
  238. int ret;
  239. unsigned long flags;
  240. qdf_iomem_t new_addr;
  241. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  242. hal_soc->hif_handle))) {
  243. hal_err_rl("target access is not allowed");
  244. return;
  245. }
  246. /* Region < BAR + 4K can be directly accessed */
  247. if (offset < MAPPED_REF_OFF) {
  248. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  249. return;
  250. }
  251. /* Region greater than BAR + 4K */
  252. if (!hal_soc->init_phase) {
  253. ret = hif_force_wake_request(hal_soc->hif_handle);
  254. if (ret) {
  255. hal_err_rl("Wake up request failed");
  256. qdf_check_state_before_panic(__func__, __LINE__);
  257. return;
  258. }
  259. }
  260. if (!hal_soc->use_register_windowing ||
  261. offset < MAX_UNWINDOWED_ADDRESS) {
  262. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  263. } else if (hal_soc->static_window_map) {
  264. new_addr = hal_get_window_address(
  265. hal_soc,
  266. hal_soc->dev_base_addr + offset);
  267. qdf_iowrite32(new_addr, value);
  268. } else {
  269. hal_lock_reg_access(hal_soc, &flags);
  270. hal_select_window_confirm(hal_soc, offset);
  271. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  272. (offset & WINDOW_RANGE_MASK), value);
  273. hal_unlock_reg_access(hal_soc, &flags);
  274. }
  275. if (!hal_soc->init_phase) {
  276. ret = hif_force_wake_release(hal_soc->hif_handle);
  277. if (ret) {
  278. hal_err("Wake up release failed");
  279. qdf_check_state_before_panic(__func__, __LINE__);
  280. return;
  281. }
  282. }
  283. }
  284. /**
  285. * hal_write32_mb_confirm() - write register and check wirting result
  286. *
  287. */
  288. static inline void hal_write32_mb_confirm(struct hal_soc *hal_soc,
  289. uint32_t offset,
  290. uint32_t value)
  291. {
  292. int ret;
  293. unsigned long flags;
  294. qdf_iomem_t new_addr;
  295. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  296. hal_soc->hif_handle))) {
  297. hal_err_rl("target access is not allowed");
  298. return;
  299. }
  300. /* Region < BAR + 4K can be directly accessed */
  301. if (offset < MAPPED_REF_OFF) {
  302. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  303. return;
  304. }
  305. /* Region greater than BAR + 4K */
  306. if (!hal_soc->init_phase) {
  307. ret = hif_force_wake_request(hal_soc->hif_handle);
  308. if (ret) {
  309. hal_err("Wake up request failed");
  310. qdf_check_state_before_panic(__func__, __LINE__);
  311. return;
  312. }
  313. }
  314. if (!hal_soc->use_register_windowing ||
  315. offset < MAX_UNWINDOWED_ADDRESS) {
  316. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  317. hal_reg_write_result_check(hal_soc, offset,
  318. value);
  319. } else if (hal_soc->static_window_map) {
  320. new_addr = hal_get_window_address(
  321. hal_soc,
  322. hal_soc->dev_base_addr + offset);
  323. qdf_iowrite32(new_addr, value);
  324. hal_reg_write_result_check(hal_soc,
  325. new_addr - hal_soc->dev_base_addr,
  326. value);
  327. } else {
  328. hal_lock_reg_access(hal_soc, &flags);
  329. hal_select_window_confirm(hal_soc, offset);
  330. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  331. (offset & WINDOW_RANGE_MASK), value);
  332. hal_reg_write_result_check(
  333. hal_soc,
  334. WINDOW_START + (offset & WINDOW_RANGE_MASK),
  335. value);
  336. hal_unlock_reg_access(hal_soc, &flags);
  337. }
  338. if (!hal_soc->init_phase) {
  339. ret = hif_force_wake_release(hal_soc->hif_handle);
  340. if (ret) {
  341. hal_err("Wake up release failed");
  342. qdf_check_state_before_panic(__func__, __LINE__);
  343. return;
  344. }
  345. }
  346. }
  347. static inline void hal_write32_mb_cmem(struct hal_soc *hal_soc, uint32_t offset,
  348. uint32_t value)
  349. {
  350. unsigned long flags;
  351. qdf_iomem_t new_addr;
  352. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  353. hal_soc->hif_handle))) {
  354. hal_err_rl("%s: target access is not allowed", __func__);
  355. return;
  356. }
  357. if (!hal_soc->use_register_windowing ||
  358. offset < MAX_UNWINDOWED_ADDRESS) {
  359. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  360. } else if (hal_soc->static_window_map) {
  361. new_addr = hal_get_window_address(
  362. hal_soc,
  363. hal_soc->dev_base_addr + offset);
  364. qdf_iowrite32(new_addr, value);
  365. } else {
  366. hal_lock_reg_access(hal_soc, &flags);
  367. hal_select_window_confirm(hal_soc, offset);
  368. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  369. (offset & WINDOW_RANGE_MASK), value);
  370. hal_unlock_reg_access(hal_soc, &flags);
  371. }
  372. }
  373. #endif
  374. /**
  375. * hal_write_address_32_mb - write a value to a register
  376. *
  377. */
  378. static inline
  379. void hal_write_address_32_mb(struct hal_soc *hal_soc,
  380. qdf_iomem_t addr, uint32_t value, bool wr_confirm)
  381. {
  382. uint32_t offset;
  383. if (!hal_soc->use_register_windowing)
  384. return qdf_iowrite32(addr, value);
  385. offset = addr - hal_soc->dev_base_addr;
  386. if (qdf_unlikely(wr_confirm))
  387. hal_write32_mb_confirm(hal_soc, offset, value);
  388. else
  389. hal_write32_mb(hal_soc, offset, value);
  390. }
  391. #ifdef DP_HAL_MULTIWINDOW_DIRECT_ACCESS
  392. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  393. struct hal_srng *srng,
  394. void __iomem *addr,
  395. uint32_t value)
  396. {
  397. qdf_iowrite32(addr, value);
  398. }
  399. #elif defined(FEATURE_HAL_DELAYED_REG_WRITE)
  400. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  401. struct hal_srng *srng,
  402. void __iomem *addr,
  403. uint32_t value)
  404. {
  405. hal_delayed_reg_write(hal_soc, srng, addr, value);
  406. }
  407. #else
  408. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  409. struct hal_srng *srng,
  410. void __iomem *addr,
  411. uint32_t value)
  412. {
  413. hal_write_address_32_mb(hal_soc, addr, value, false);
  414. }
  415. #endif
  416. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) && \
  417. !defined(QCA_WIFI_QCA6750) && !defined(QCA_WIFI_KIWI)
  418. /**
  419. * hal_read32_mb() - Access registers to read configuration
  420. * @hal_soc: hal soc handle
  421. * @offset: offset address from the BAR
  422. * @value: value to write
  423. *
  424. * Description: Register address space is split below:
  425. * SHADOW REGION UNWINDOWED REGION WINDOWED REGION
  426. * |--------------------|-------------------|------------------|
  427. * BAR NO FORCE WAKE BAR+4K FORCE WAKE BAR+512K FORCE WAKE
  428. *
  429. * 1. Any access to the shadow region, doesn't need force wake
  430. * and windowing logic to access.
  431. * 2. Any access beyond BAR + 4K:
  432. * If init_phase enabled, no force wake is needed and access
  433. * should be based on windowed or unwindowed access.
  434. * If init_phase disabled, force wake is needed and access
  435. * should be based on windowed or unwindowed access.
  436. *
  437. * Return: < 0 for failure/>= 0 for success
  438. */
  439. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  440. {
  441. uint32_t ret;
  442. unsigned long flags;
  443. qdf_iomem_t new_addr;
  444. if (!hal_soc->use_register_windowing ||
  445. offset < MAX_UNWINDOWED_ADDRESS) {
  446. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  447. } else if (hal_soc->static_window_map) {
  448. new_addr = hal_get_window_address(hal_soc, hal_soc->dev_base_addr + offset);
  449. return qdf_ioread32(new_addr);
  450. }
  451. hal_lock_reg_access(hal_soc, &flags);
  452. hal_select_window_confirm(hal_soc, offset);
  453. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  454. (offset & WINDOW_RANGE_MASK));
  455. hal_unlock_reg_access(hal_soc, &flags);
  456. return ret;
  457. }
  458. #define hal_read32_mb_cmem(_hal_soc, _offset)
  459. #else
  460. static
  461. uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  462. {
  463. uint32_t ret;
  464. unsigned long flags;
  465. qdf_iomem_t new_addr;
  466. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  467. hal_soc->hif_handle))) {
  468. hal_err_rl("target access is not allowed");
  469. return 0;
  470. }
  471. /* Region < BAR + 4K can be directly accessed */
  472. if (offset < MAPPED_REF_OFF)
  473. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  474. if ((!hal_soc->init_phase) &&
  475. hif_force_wake_request(hal_soc->hif_handle)) {
  476. hal_err("Wake up request failed");
  477. qdf_check_state_before_panic(__func__, __LINE__);
  478. return 0;
  479. }
  480. if (!hal_soc->use_register_windowing ||
  481. offset < MAX_UNWINDOWED_ADDRESS) {
  482. ret = qdf_ioread32(hal_soc->dev_base_addr + offset);
  483. } else if (hal_soc->static_window_map) {
  484. new_addr = hal_get_window_address(
  485. hal_soc,
  486. hal_soc->dev_base_addr + offset);
  487. ret = qdf_ioread32(new_addr);
  488. } else {
  489. hal_lock_reg_access(hal_soc, &flags);
  490. hal_select_window_confirm(hal_soc, offset);
  491. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  492. (offset & WINDOW_RANGE_MASK));
  493. hal_unlock_reg_access(hal_soc, &flags);
  494. }
  495. if ((!hal_soc->init_phase) &&
  496. hif_force_wake_release(hal_soc->hif_handle)) {
  497. hal_err("Wake up release failed");
  498. qdf_check_state_before_panic(__func__, __LINE__);
  499. return 0;
  500. }
  501. return ret;
  502. }
  503. static inline
  504. uint32_t hal_read32_mb_cmem(struct hal_soc *hal_soc, uint32_t offset)
  505. {
  506. uint32_t ret;
  507. unsigned long flags;
  508. qdf_iomem_t new_addr;
  509. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  510. hal_soc->hif_handle))) {
  511. hal_err_rl("%s: target access is not allowed", __func__);
  512. return 0;
  513. }
  514. if (!hal_soc->use_register_windowing ||
  515. offset < MAX_UNWINDOWED_ADDRESS) {
  516. ret = qdf_ioread32(hal_soc->dev_base_addr + offset);
  517. } else if (hal_soc->static_window_map) {
  518. new_addr = hal_get_window_address(
  519. hal_soc,
  520. hal_soc->dev_base_addr + offset);
  521. ret = qdf_ioread32(new_addr);
  522. } else {
  523. hal_lock_reg_access(hal_soc, &flags);
  524. hal_select_window_confirm(hal_soc, offset);
  525. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  526. (offset & WINDOW_RANGE_MASK));
  527. hal_unlock_reg_access(hal_soc, &flags);
  528. }
  529. return ret;
  530. }
  531. #endif
  532. /* Max times allowed for register writing retry */
  533. #define HAL_REG_WRITE_RETRY_MAX 5
  534. /* Delay milliseconds for each time retry */
  535. #define HAL_REG_WRITE_RETRY_DELAY 1
  536. #ifdef GENERIC_SHADOW_REGISTER_ACCESS_ENABLE
  537. /* To check shadow config index range between 0..31 */
  538. #define HAL_SHADOW_REG_INDEX_LOW 32
  539. /* To check shadow config index range between 32..39 */
  540. #define HAL_SHADOW_REG_INDEX_HIGH 40
  541. /* Dirty bit reg offsets corresponding to shadow config index */
  542. #define HAL_SHADOW_REG_DIRTY_BIT_DATA_LOW_OFFSET 0x30C8
  543. #define HAL_SHADOW_REG_DIRTY_BIT_DATA_HIGH_OFFSET 0x30C4
  544. /* PCIE_PCIE_TOP base addr offset */
  545. #define HAL_PCIE_PCIE_TOP_WRAPPER 0x01E00000
  546. /* Max retry attempts to read the dirty bit reg */
  547. #ifdef HAL_CONFIG_SLUB_DEBUG_ON
  548. #define HAL_SHADOW_DIRTY_BIT_POLL_MAX 10000
  549. #else
  550. #define HAL_SHADOW_DIRTY_BIT_POLL_MAX 2000
  551. #endif
  552. /* Delay in usecs for polling dirty bit reg */
  553. #define HAL_SHADOW_DIRTY_BIT_POLL_DELAY 5
  554. /**
  555. * hal_poll_dirty_bit_reg() - Poll dirty register bit to confirm
  556. * write was successful
  557. * @hal_soc: hal soc handle
  558. * @shadow_config_index: index of shadow reg used to confirm
  559. * write
  560. *
  561. * Return: QDF_STATUS_SUCCESS on success
  562. */
  563. static inline QDF_STATUS hal_poll_dirty_bit_reg(struct hal_soc *hal,
  564. int shadow_config_index)
  565. {
  566. uint32_t read_value = 0;
  567. int retry_cnt = 0;
  568. uint32_t reg_offset = 0;
  569. if (shadow_config_index > 0 &&
  570. shadow_config_index < HAL_SHADOW_REG_INDEX_LOW) {
  571. reg_offset =
  572. HAL_SHADOW_REG_DIRTY_BIT_DATA_LOW_OFFSET;
  573. } else if (shadow_config_index >= HAL_SHADOW_REG_INDEX_LOW &&
  574. shadow_config_index < HAL_SHADOW_REG_INDEX_HIGH) {
  575. reg_offset =
  576. HAL_SHADOW_REG_DIRTY_BIT_DATA_HIGH_OFFSET;
  577. } else {
  578. hal_err("Invalid shadow_config_index = %d",
  579. shadow_config_index);
  580. return QDF_STATUS_E_INVAL;
  581. }
  582. while (retry_cnt < HAL_SHADOW_DIRTY_BIT_POLL_MAX) {
  583. read_value = hal_read32_mb(
  584. hal, HAL_PCIE_PCIE_TOP_WRAPPER + reg_offset);
  585. /* Check if dirty bit corresponding to shadow_index is set */
  586. if (read_value & BIT(shadow_config_index)) {
  587. /* Dirty reg bit not reset */
  588. qdf_udelay(HAL_SHADOW_DIRTY_BIT_POLL_DELAY);
  589. retry_cnt++;
  590. } else {
  591. hal_debug("Shadow write: offset 0x%x read val 0x%x",
  592. reg_offset, read_value);
  593. return QDF_STATUS_SUCCESS;
  594. }
  595. }
  596. return QDF_STATUS_E_TIMEOUT;
  597. }
  598. /**
  599. * hal_write32_mb_shadow_confirm() - write to shadow reg and
  600. * poll dirty register bit to confirm write
  601. * @hal_soc: hal soc handle
  602. * @reg_offset: target reg offset address from BAR
  603. * @value: value to write
  604. *
  605. * Return: QDF_STATUS_SUCCESS on success
  606. */
  607. static inline QDF_STATUS hal_write32_mb_shadow_confirm(
  608. struct hal_soc *hal,
  609. uint32_t reg_offset,
  610. uint32_t value)
  611. {
  612. int i;
  613. QDF_STATUS ret;
  614. uint32_t shadow_reg_offset;
  615. int shadow_config_index;
  616. bool is_reg_offset_present = false;
  617. for (i = 0; i < MAX_GENERIC_SHADOW_REG; i++) {
  618. /* Found the shadow config for the reg_offset */
  619. struct shadow_reg_config *hal_shadow_reg_list =
  620. &hal->list_shadow_reg_config[i];
  621. if (hal_shadow_reg_list->target_register ==
  622. reg_offset) {
  623. shadow_config_index =
  624. hal_shadow_reg_list->shadow_config_index;
  625. shadow_reg_offset =
  626. SHADOW_REGISTER(shadow_config_index);
  627. hal_write32_mb_confirm(
  628. hal, shadow_reg_offset, value);
  629. is_reg_offset_present = true;
  630. break;
  631. }
  632. ret = QDF_STATUS_E_FAILURE;
  633. }
  634. if (is_reg_offset_present) {
  635. ret = hal_poll_dirty_bit_reg(hal, shadow_config_index);
  636. hal_info("Shadow write:reg 0x%x val 0x%x ret %d",
  637. reg_offset, value, ret);
  638. if (QDF_IS_STATUS_ERROR(ret)) {
  639. HAL_STATS_INC(hal, shadow_reg_write_fail, 1);
  640. return ret;
  641. }
  642. HAL_STATS_INC(hal, shadow_reg_write_succ, 1);
  643. }
  644. return ret;
  645. }
  646. /**
  647. * hal_write32_mb_confirm_retry() - write register with confirming and
  648. do retry/recovery if writing failed
  649. * @hal_soc: hal soc handle
  650. * @offset: offset address from the BAR
  651. * @value: value to write
  652. * @recovery: is recovery needed or not.
  653. *
  654. * Write the register value with confirming and read it back, if
  655. * read back value is not as expected, do retry for writing, if
  656. * retry hit max times allowed but still fail, check if recovery
  657. * needed.
  658. *
  659. * Return: None
  660. */
  661. static inline void hal_write32_mb_confirm_retry(struct hal_soc *hal_soc,
  662. uint32_t offset,
  663. uint32_t value,
  664. bool recovery)
  665. {
  666. QDF_STATUS ret;
  667. ret = hal_write32_mb_shadow_confirm(hal_soc, offset, value);
  668. if (QDF_IS_STATUS_ERROR(ret) && recovery)
  669. qdf_trigger_self_recovery(NULL, QDF_HAL_REG_WRITE_FAILURE);
  670. }
  671. #else /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  672. static inline void hal_write32_mb_confirm_retry(struct hal_soc *hal_soc,
  673. uint32_t offset,
  674. uint32_t value,
  675. bool recovery)
  676. {
  677. uint8_t retry_cnt = 0;
  678. uint32_t read_value;
  679. while (retry_cnt <= HAL_REG_WRITE_RETRY_MAX) {
  680. hal_write32_mb_confirm(hal_soc, offset, value);
  681. read_value = hal_read32_mb(hal_soc, offset);
  682. if (qdf_likely(read_value == value))
  683. break;
  684. /* write failed, do retry */
  685. hal_warn("Retry reg offset 0x%x, value 0x%x, read value 0x%x",
  686. offset, value, read_value);
  687. qdf_mdelay(HAL_REG_WRITE_RETRY_DELAY);
  688. retry_cnt++;
  689. }
  690. if (retry_cnt > HAL_REG_WRITE_RETRY_MAX && recovery)
  691. qdf_trigger_self_recovery(NULL, QDF_HAL_REG_WRITE_FAILURE);
  692. }
  693. #endif /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  694. #if defined(FEATURE_HAL_DELAYED_REG_WRITE)
  695. /**
  696. * hal_dump_reg_write_srng_stats() - dump SRNG reg write stats
  697. * @hal_soc: HAL soc handle
  698. *
  699. * Return: none
  700. */
  701. void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl);
  702. /**
  703. * hal_dump_reg_write_stats() - dump reg write stats
  704. * @hal_soc: HAL soc handle
  705. *
  706. * Return: none
  707. */
  708. void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl);
  709. /**
  710. * hal_get_reg_write_pending_work() - get the number of entries
  711. * pending in the workqueue to be processed.
  712. * @hal_soc: HAL soc handle
  713. *
  714. * Returns: the number of entries pending to be processed
  715. */
  716. int hal_get_reg_write_pending_work(void *hal_soc);
  717. #else
  718. static inline void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl)
  719. {
  720. }
  721. static inline void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl)
  722. {
  723. }
  724. static inline int hal_get_reg_write_pending_work(void *hal_soc)
  725. {
  726. return 0;
  727. }
  728. #endif
  729. /**
  730. * hal_read_address_32_mb() - Read 32-bit value from the register
  731. * @soc: soc handle
  732. * @addr: register address to read
  733. *
  734. * Return: 32-bit value
  735. */
  736. static inline
  737. uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  738. qdf_iomem_t addr)
  739. {
  740. uint32_t offset;
  741. uint32_t ret;
  742. if (!soc->use_register_windowing)
  743. return qdf_ioread32(addr);
  744. offset = addr - soc->dev_base_addr;
  745. ret = hal_read32_mb(soc, offset);
  746. return ret;
  747. }
  748. /**
  749. * hal_attach - Initialize HAL layer
  750. * @hif_handle: Opaque HIF handle
  751. * @qdf_dev: QDF device
  752. *
  753. * Return: Opaque HAL SOC handle
  754. * NULL on failure (if given ring is not available)
  755. *
  756. * This function should be called as part of HIF initialization (for accessing
  757. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  758. */
  759. void *hal_attach(struct hif_opaque_softc *hif_handle, qdf_device_t qdf_dev);
  760. /**
  761. * hal_detach - Detach HAL layer
  762. * @hal_soc: HAL SOC handle
  763. *
  764. * This function should be called as part of HIF detach
  765. *
  766. */
  767. extern void hal_detach(void *hal_soc);
  768. #define HAL_SRNG_LMAC_RING 0x80000000
  769. /* SRNG flags passed in hal_srng_params.flags */
  770. #define HAL_SRNG_MSI_SWAP 0x00000008
  771. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  772. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  773. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  774. #define HAL_SRNG_MSI_INTR 0x00020000
  775. #define HAL_SRNG_CACHED_DESC 0x00040000
  776. #if defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_KIWI)
  777. #define HAL_SRNG_PREFETCH_TIMER 1
  778. #else
  779. #define HAL_SRNG_PREFETCH_TIMER 0
  780. #endif
  781. #define PN_SIZE_24 0
  782. #define PN_SIZE_48 1
  783. #define PN_SIZE_128 2
  784. #ifdef FORCE_WAKE
  785. /**
  786. * hal_set_init_phase() - Indicate initialization of
  787. * datapath rings
  788. * @soc: hal_soc handle
  789. * @init_phase: flag to indicate datapath rings
  790. * initialization status
  791. *
  792. * Return: None
  793. */
  794. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase);
  795. #else
  796. static inline
  797. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase)
  798. {
  799. }
  800. #endif /* FORCE_WAKE */
  801. /**
  802. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  803. * used by callers for calculating the size of memory to be allocated before
  804. * calling hal_srng_setup to setup the ring
  805. *
  806. * @hal_soc: Opaque HAL SOC handle
  807. * @ring_type: one of the types from hal_ring_type
  808. *
  809. */
  810. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  811. /**
  812. * hal_srng_max_entries - Returns maximum possible number of ring entries
  813. * @hal_soc: Opaque HAL SOC handle
  814. * @ring_type: one of the types from hal_ring_type
  815. *
  816. * Return: Maximum number of entries for the given ring_type
  817. */
  818. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  819. void hal_set_low_threshold(hal_ring_handle_t hal_ring_hdl,
  820. uint32_t low_threshold);
  821. /**
  822. * hal_srng_dump - Dump ring status
  823. * @srng: hal srng pointer
  824. */
  825. void hal_srng_dump(struct hal_srng *srng);
  826. /**
  827. * hal_srng_get_dir - Returns the direction of the ring
  828. * @hal_soc: Opaque HAL SOC handle
  829. * @ring_type: one of the types from hal_ring_type
  830. *
  831. * Return: Ring direction
  832. */
  833. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  834. /* HAL memory information */
  835. struct hal_mem_info {
  836. /* dev base virutal addr */
  837. void *dev_base_addr;
  838. /* dev base physical addr */
  839. void *dev_base_paddr;
  840. /* dev base ce virutal addr - applicable only for qca5018 */
  841. /* In qca5018 CE register are outside wcss block */
  842. /* using a separate address space to access CE registers */
  843. void *dev_base_addr_ce;
  844. /* dev base ce physical addr */
  845. void *dev_base_paddr_ce;
  846. /* Remote virtual pointer memory for HW/FW updates */
  847. void *shadow_rdptr_mem_vaddr;
  848. /* Remote physical pointer memory for HW/FW updates */
  849. void *shadow_rdptr_mem_paddr;
  850. /* Shared memory for ring pointer updates from host to FW */
  851. void *shadow_wrptr_mem_vaddr;
  852. /* Shared physical memory for ring pointer updates from host to FW */
  853. void *shadow_wrptr_mem_paddr;
  854. /* lmac srng start id */
  855. uint8_t lmac_srng_start_id;
  856. };
  857. /* SRNG parameters to be passed to hal_srng_setup */
  858. struct hal_srng_params {
  859. /* Physical base address of the ring */
  860. qdf_dma_addr_t ring_base_paddr;
  861. /* Virtual base address of the ring */
  862. void *ring_base_vaddr;
  863. /* Number of entries in ring */
  864. uint32_t num_entries;
  865. /* max transfer length */
  866. uint16_t max_buffer_length;
  867. /* MSI Address */
  868. qdf_dma_addr_t msi_addr;
  869. /* MSI data */
  870. uint32_t msi_data;
  871. /* Interrupt timer threshold – in micro seconds */
  872. uint32_t intr_timer_thres_us;
  873. /* Interrupt batch counter threshold – in number of ring entries */
  874. uint32_t intr_batch_cntr_thres_entries;
  875. /* Low threshold – in number of ring entries
  876. * (valid for src rings only)
  877. */
  878. uint32_t low_threshold;
  879. /* Misc flags */
  880. uint32_t flags;
  881. /* Unique ring id */
  882. uint8_t ring_id;
  883. /* Source or Destination ring */
  884. enum hal_srng_dir ring_dir;
  885. /* Size of ring entry */
  886. uint32_t entry_size;
  887. /* hw register base address */
  888. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  889. /* prefetch timer config - in micro seconds */
  890. uint32_t prefetch_timer;
  891. #ifdef WLAN_FEATURE_NEAR_FULL_IRQ
  892. /* Near full IRQ support flag */
  893. uint32_t nf_irq_support;
  894. /* MSI2 Address */
  895. qdf_dma_addr_t msi2_addr;
  896. /* MSI2 data */
  897. uint32_t msi2_data;
  898. /* Critical threshold */
  899. uint16_t crit_thresh;
  900. /* High threshold */
  901. uint16_t high_thresh;
  902. /* Safe threshold */
  903. uint16_t safe_thresh;
  904. #endif
  905. };
  906. /* hal_construct_srng_shadow_regs() - initialize the shadow
  907. * registers for srngs
  908. * @hal_soc: hal handle
  909. *
  910. * Return: QDF_STATUS_OK on success
  911. */
  912. QDF_STATUS hal_construct_srng_shadow_regs(void *hal_soc);
  913. /* hal_set_one_shadow_config() - add a config for the specified ring
  914. * @hal_soc: hal handle
  915. * @ring_type: ring type
  916. * @ring_num: ring num
  917. *
  918. * The ring type and ring num uniquely specify the ring. After this call,
  919. * the hp/tp will be added as the next entry int the shadow register
  920. * configuration table. The hal code will use the shadow register address
  921. * in place of the hp/tp address.
  922. *
  923. * This function is exposed, so that the CE module can skip configuring shadow
  924. * registers for unused ring and rings assigned to the firmware.
  925. *
  926. * Return: QDF_STATUS_OK on success
  927. */
  928. QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  929. int ring_num);
  930. /**
  931. * hal_get_shadow_config() - retrieve the config table
  932. * @hal_soc: hal handle
  933. * @shadow_config: will point to the table after
  934. * @num_shadow_registers_configured: will contain the number of valid entries
  935. */
  936. extern void hal_get_shadow_config(void *hal_soc,
  937. struct pld_shadow_reg_v2_cfg **shadow_config,
  938. int *num_shadow_registers_configured);
  939. #ifdef WLAN_FEATURE_NEAR_FULL_IRQ
  940. /**
  941. * hal_srng_is_near_full_irq_supported() - Check if srng supports near full irq
  942. * @hal_soc: HAL SoC handle [To be validated by caller]
  943. * @ring_type: srng type
  944. * @ring_num: The index of the srng (of the same type)
  945. *
  946. * Return: true, if srng support near full irq trigger
  947. * false, if the srng does not support near full irq support.
  948. */
  949. bool hal_srng_is_near_full_irq_supported(hal_soc_handle_t hal_soc,
  950. int ring_type, int ring_num);
  951. #else
  952. static inline
  953. bool hal_srng_is_near_full_irq_supported(hal_soc_handle_t hal_soc,
  954. int ring_type, int ring_num)
  955. {
  956. return false;
  957. }
  958. #endif
  959. /**
  960. * hal_srng_setup - Initialize HW SRNG ring.
  961. *
  962. * @hal_soc: Opaque HAL SOC handle
  963. * @ring_type: one of the types from hal_ring_type
  964. * @ring_num: Ring number if there are multiple rings of
  965. * same type (staring from 0)
  966. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  967. * @ring_params: SRNG ring params in hal_srng_params structure.
  968. * Callers are expected to allocate contiguous ring memory of size
  969. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  970. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  971. * structure. Ring base address should be 8 byte aligned and size of each ring
  972. * entry should be queried using the API hal_srng_get_entrysize
  973. *
  974. * Return: Opaque pointer to ring on success
  975. * NULL on failure (if given ring is not available)
  976. */
  977. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  978. int mac_id, struct hal_srng_params *ring_params);
  979. /* Remapping ids of REO rings */
  980. #define REO_REMAP_TCL 0
  981. #define REO_REMAP_SW1 1
  982. #define REO_REMAP_SW2 2
  983. #define REO_REMAP_SW3 3
  984. #define REO_REMAP_SW4 4
  985. #define REO_REMAP_RELEASE 5
  986. #define REO_REMAP_FW 6
  987. /*
  988. * In Beryllium: 4 bits REO destination ring value is defined as: 0: TCL
  989. * 1:SW1 2:SW2 3:SW3 4:SW4 5:Release 6:FW(WIFI) 7:SW5
  990. * 8:SW6 9:SW7 10:SW8 11: NOT_USED.
  991. *
  992. */
  993. #define REO_REMAP_SW5 7
  994. #define REO_REMAP_SW6 8
  995. #define REO_REMAP_SW7 9
  996. #define REO_REMAP_SW8 10
  997. /*
  998. * Macro to access HWIO_REO_R0_ERROR_DESTINATION_RING_CTRL_IX_0
  999. * to map destination to rings
  1000. */
  1001. #define HAL_REO_ERR_REMAP_IX0(_VALUE, _OFFSET) \
  1002. ((_VALUE) << \
  1003. (HWIO_REO_R0_ERROR_DESTINATION_MAPPING_IX_0_ERROR_ ## \
  1004. DESTINATION_RING_ ## _OFFSET ## _SHFT))
  1005. /*
  1006. * Macro to access HWIO_REO_R0_ERROR_DESTINATION_RING_CTRL_IX_1
  1007. * to map destination to rings
  1008. */
  1009. #define HAL_REO_ERR_REMAP_IX1(_VALUE, _OFFSET) \
  1010. ((_VALUE) << \
  1011. (HWIO_REO_R0_ERROR_DESTINATION_MAPPING_IX_1_ERROR_ ## \
  1012. DESTINATION_RING_ ## _OFFSET ## _SHFT))
  1013. /*
  1014. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  1015. * to map destination to rings
  1016. */
  1017. #define HAL_REO_REMAP_IX0(_VALUE, _OFFSET) \
  1018. ((_VALUE) << \
  1019. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  1020. _OFFSET ## _SHFT))
  1021. /*
  1022. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1
  1023. * to map destination to rings
  1024. */
  1025. #define HAL_REO_REMAP_IX2(_VALUE, _OFFSET) \
  1026. ((_VALUE) << \
  1027. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_DEST_RING_MAPPING_ ## \
  1028. _OFFSET ## _SHFT))
  1029. /*
  1030. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3
  1031. * to map destination to rings
  1032. */
  1033. #define HAL_REO_REMAP_IX3(_VALUE, _OFFSET) \
  1034. ((_VALUE) << \
  1035. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_DEST_RING_MAPPING_ ## \
  1036. _OFFSET ## _SHFT))
  1037. /**
  1038. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  1039. * @hal_soc_hdl: HAL SOC handle
  1040. * @read: boolean value to indicate if read or write
  1041. * @ix0: pointer to store IX0 reg value
  1042. * @ix1: pointer to store IX1 reg value
  1043. * @ix2: pointer to store IX2 reg value
  1044. * @ix3: pointer to store IX3 reg value
  1045. */
  1046. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  1047. uint32_t *ix0, uint32_t *ix1,
  1048. uint32_t *ix2, uint32_t *ix3);
  1049. /**
  1050. * hal_srng_set_hp_paddr_confirm() - Set physical address to dest SRNG head
  1051. * pointer and confirm that write went through by reading back the value
  1052. * @sring: sring pointer
  1053. * @paddr: physical address
  1054. *
  1055. * Return: None
  1056. */
  1057. extern void hal_srng_dst_set_hp_paddr_confirm(struct hal_srng *sring,
  1058. uint64_t paddr);
  1059. /**
  1060. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  1061. * @hal_soc: hal_soc handle
  1062. * @srng: sring pointer
  1063. * @vaddr: virtual address
  1064. */
  1065. void hal_srng_dst_init_hp(struct hal_soc_handle *hal_soc,
  1066. struct hal_srng *srng,
  1067. uint32_t *vaddr);
  1068. /**
  1069. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  1070. * @hal_soc: Opaque HAL SOC handle
  1071. * @hal_srng: Opaque HAL SRNG pointer
  1072. */
  1073. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl);
  1074. static inline bool hal_srng_initialized(hal_ring_handle_t hal_ring_hdl)
  1075. {
  1076. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1077. return !!srng->initialized;
  1078. }
  1079. /**
  1080. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  1081. * @hal_soc: Opaque HAL SOC handle
  1082. * @hal_ring_hdl: Destination ring pointer
  1083. *
  1084. * Caller takes responsibility for any locking needs.
  1085. *
  1086. * Return: Opaque pointer for next ring entry; NULL on failire
  1087. */
  1088. static inline
  1089. void *hal_srng_dst_peek(hal_soc_handle_t hal_soc_hdl,
  1090. hal_ring_handle_t hal_ring_hdl)
  1091. {
  1092. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1093. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  1094. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  1095. return NULL;
  1096. }
  1097. /**
  1098. * hal_mem_dma_cache_sync - Cache sync the specified virtual address Range
  1099. * @hal_soc: HAL soc handle
  1100. * @desc: desc start address
  1101. * @entry_size: size of memory to sync
  1102. *
  1103. * Return: void
  1104. */
  1105. #if defined(__LINUX_MIPS32_ARCH__) || defined(__LINUX_MIPS64_ARCH__)
  1106. static inline void hal_mem_dma_cache_sync(struct hal_soc *soc, uint32_t *desc,
  1107. uint32_t entry_size)
  1108. {
  1109. qdf_nbuf_dma_inv_range((void *)desc, (void *)(desc + entry_size));
  1110. }
  1111. #else
  1112. static inline void hal_mem_dma_cache_sync(struct hal_soc *soc, uint32_t *desc,
  1113. uint32_t entry_size)
  1114. {
  1115. qdf_mem_dma_cache_sync(soc->qdf_dev, qdf_mem_virt_to_phys(desc),
  1116. QDF_DMA_FROM_DEVICE,
  1117. (entry_size * sizeof(uint32_t)));
  1118. }
  1119. #endif
  1120. /**
  1121. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  1122. * hal_srng_access_start if locked access is required
  1123. *
  1124. * @hal_soc: Opaque HAL SOC handle
  1125. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1126. *
  1127. * This API doesn't implement any byte-order conversion on reading hp/tp.
  1128. * So, Use API only for those srngs for which the target writes hp/tp values to
  1129. * the DDR in the Host order.
  1130. *
  1131. * Return: 0 on success; error on failire
  1132. */
  1133. static inline int
  1134. hal_srng_access_start_unlocked(hal_soc_handle_t hal_soc_hdl,
  1135. hal_ring_handle_t hal_ring_hdl)
  1136. {
  1137. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1138. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  1139. uint32_t *desc;
  1140. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1141. srng->u.src_ring.cached_tp =
  1142. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  1143. else {
  1144. srng->u.dst_ring.cached_hp =
  1145. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1146. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  1147. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  1148. if (qdf_likely(desc)) {
  1149. hal_mem_dma_cache_sync(soc, desc,
  1150. srng->entry_size);
  1151. qdf_prefetch(desc);
  1152. }
  1153. }
  1154. }
  1155. return 0;
  1156. }
  1157. /**
  1158. * hal_le_srng_access_start_unlocked_in_cpu_order - Start ring access
  1159. * (unlocked) with endianness correction.
  1160. * @hal_soc: Opaque HAL SOC handle
  1161. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1162. *
  1163. * This API provides same functionally as hal_srng_access_start_unlocked()
  1164. * except that it converts the little-endian formatted hp/tp values to
  1165. * Host order on reading them. So, this API should only be used for those srngs
  1166. * for which the target always writes hp/tp values in little-endian order
  1167. * regardless of Host order.
  1168. *
  1169. * Also, this API doesn't take the lock. For locked access, use
  1170. * hal_srng_access_start/hal_le_srng_access_start_in_cpu_order.
  1171. *
  1172. * Return: 0 on success; error on failire
  1173. */
  1174. static inline int
  1175. hal_le_srng_access_start_unlocked_in_cpu_order(
  1176. hal_soc_handle_t hal_soc_hdl,
  1177. hal_ring_handle_t hal_ring_hdl)
  1178. {
  1179. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1180. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  1181. uint32_t *desc;
  1182. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1183. srng->u.src_ring.cached_tp =
  1184. qdf_le32_to_cpu(*(volatile uint32_t *)
  1185. (srng->u.src_ring.tp_addr));
  1186. else {
  1187. srng->u.dst_ring.cached_hp =
  1188. qdf_le32_to_cpu(*(volatile uint32_t *)
  1189. (srng->u.dst_ring.hp_addr));
  1190. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  1191. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  1192. if (qdf_likely(desc)) {
  1193. hal_mem_dma_cache_sync(soc, desc,
  1194. srng->entry_size);
  1195. qdf_prefetch(desc);
  1196. }
  1197. }
  1198. }
  1199. return 0;
  1200. }
  1201. /**
  1202. * hal_srng_try_access_start - Try to start (locked) ring access
  1203. *
  1204. * @hal_soc: Opaque HAL SOC handle
  1205. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1206. *
  1207. * Return: 0 on success; error on failure
  1208. */
  1209. static inline int hal_srng_try_access_start(hal_soc_handle_t hal_soc_hdl,
  1210. hal_ring_handle_t hal_ring_hdl)
  1211. {
  1212. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1213. if (qdf_unlikely(!hal_ring_hdl)) {
  1214. qdf_print("Error: Invalid hal_ring\n");
  1215. return -EINVAL;
  1216. }
  1217. if (!SRNG_TRY_LOCK(&(srng->lock)))
  1218. return -EINVAL;
  1219. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  1220. }
  1221. /**
  1222. * hal_srng_access_start - Start (locked) ring access
  1223. *
  1224. * @hal_soc: Opaque HAL SOC handle
  1225. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1226. *
  1227. * This API doesn't implement any byte-order conversion on reading hp/tp.
  1228. * So, Use API only for those srngs for which the target writes hp/tp values to
  1229. * the DDR in the Host order.
  1230. *
  1231. * Return: 0 on success; error on failire
  1232. */
  1233. static inline int hal_srng_access_start(hal_soc_handle_t hal_soc_hdl,
  1234. hal_ring_handle_t hal_ring_hdl)
  1235. {
  1236. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1237. if (qdf_unlikely(!hal_ring_hdl)) {
  1238. qdf_print("Error: Invalid hal_ring\n");
  1239. return -EINVAL;
  1240. }
  1241. SRNG_LOCK(&(srng->lock));
  1242. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  1243. }
  1244. /**
  1245. * hal_le_srng_access_start_in_cpu_order - Start (locked) ring access with
  1246. * endianness correction
  1247. * @hal_soc: Opaque HAL SOC handle
  1248. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1249. *
  1250. * This API provides same functionally as hal_srng_access_start()
  1251. * except that it converts the little-endian formatted hp/tp values to
  1252. * Host order on reading them. So, this API should only be used for those srngs
  1253. * for which the target always writes hp/tp values in little-endian order
  1254. * regardless of Host order.
  1255. *
  1256. * Return: 0 on success; error on failire
  1257. */
  1258. static inline int
  1259. hal_le_srng_access_start_in_cpu_order(
  1260. hal_soc_handle_t hal_soc_hdl,
  1261. hal_ring_handle_t hal_ring_hdl)
  1262. {
  1263. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1264. if (qdf_unlikely(!hal_ring_hdl)) {
  1265. qdf_print("Error: Invalid hal_ring\n");
  1266. return -EINVAL;
  1267. }
  1268. SRNG_LOCK(&(srng->lock));
  1269. return hal_le_srng_access_start_unlocked_in_cpu_order(
  1270. hal_soc_hdl, hal_ring_hdl);
  1271. }
  1272. /**
  1273. * hal_srng_dst_get_next - Get next entry from a destination ring
  1274. * @hal_soc: Opaque HAL SOC handle
  1275. * @hal_ring_hdl: Destination ring pointer
  1276. *
  1277. * Return: Opaque pointer for next ring entry; NULL on failure
  1278. */
  1279. static inline
  1280. void *hal_srng_dst_get_next(void *hal_soc,
  1281. hal_ring_handle_t hal_ring_hdl)
  1282. {
  1283. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1284. uint32_t *desc;
  1285. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  1286. return NULL;
  1287. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1288. /* TODO: Using % is expensive, but we have to do this since
  1289. * size of some SRNG rings is not power of 2 (due to descriptor
  1290. * sizes). Need to create separate API for rings used
  1291. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1292. * SW2RXDMA and CE rings)
  1293. */
  1294. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  1295. if (srng->u.dst_ring.tp == srng->ring_size)
  1296. srng->u.dst_ring.tp = 0;
  1297. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  1298. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  1299. uint32_t *desc_next;
  1300. uint32_t tp;
  1301. tp = srng->u.dst_ring.tp;
  1302. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1303. hal_mem_dma_cache_sync(soc, desc_next, srng->entry_size);
  1304. qdf_prefetch(desc_next);
  1305. }
  1306. return (void *)desc;
  1307. }
  1308. /**
  1309. * hal_srng_dst_get_next_cached - Get cached next entry
  1310. * @hal_soc: Opaque HAL SOC handle
  1311. * @hal_ring_hdl: Destination ring pointer
  1312. *
  1313. * Get next entry from a destination ring and move cached tail pointer
  1314. *
  1315. * Return: Opaque pointer for next ring entry; NULL on failure
  1316. */
  1317. static inline
  1318. void *hal_srng_dst_get_next_cached(void *hal_soc,
  1319. hal_ring_handle_t hal_ring_hdl)
  1320. {
  1321. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1322. uint32_t *desc;
  1323. uint32_t *desc_next;
  1324. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  1325. return NULL;
  1326. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1327. /* TODO: Using % is expensive, but we have to do this since
  1328. * size of some SRNG rings is not power of 2 (due to descriptor
  1329. * sizes). Need to create separate API for rings used
  1330. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1331. * SW2RXDMA and CE rings)
  1332. */
  1333. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  1334. if (srng->u.dst_ring.tp == srng->ring_size)
  1335. srng->u.dst_ring.tp = 0;
  1336. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1337. qdf_prefetch(desc_next);
  1338. return (void *)desc;
  1339. }
  1340. /**
  1341. * hal_srng_dst_dec_tp - decrement the TP of the Dst ring by one entry
  1342. * @hal_soc: Opaque HAL SOC handle
  1343. * @hal_ring_hdl: Destination ring pointer
  1344. *
  1345. * reset the tail pointer in the destination ring by one entry
  1346. *
  1347. */
  1348. static inline
  1349. void hal_srng_dst_dec_tp(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1350. {
  1351. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1352. if (qdf_unlikely(!srng->u.dst_ring.tp))
  1353. srng->u.dst_ring.tp = (srng->ring_size - srng->entry_size);
  1354. else
  1355. srng->u.dst_ring.tp -= srng->entry_size;
  1356. }
  1357. static inline int hal_srng_lock(hal_ring_handle_t hal_ring_hdl)
  1358. {
  1359. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1360. if (qdf_unlikely(!hal_ring_hdl)) {
  1361. qdf_print("error: invalid hal_ring\n");
  1362. return -EINVAL;
  1363. }
  1364. SRNG_LOCK(&(srng->lock));
  1365. return 0;
  1366. }
  1367. static inline int hal_srng_unlock(hal_ring_handle_t hal_ring_hdl)
  1368. {
  1369. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1370. if (qdf_unlikely(!hal_ring_hdl)) {
  1371. qdf_print("error: invalid hal_ring\n");
  1372. return -EINVAL;
  1373. }
  1374. SRNG_UNLOCK(&(srng->lock));
  1375. return 0;
  1376. }
  1377. /**
  1378. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  1379. * cached head pointer
  1380. *
  1381. * @hal_soc: Opaque HAL SOC handle
  1382. * @hal_ring_hdl: Destination ring pointer
  1383. *
  1384. * Return: Opaque pointer for next ring entry; NULL on failire
  1385. */
  1386. static inline void *
  1387. hal_srng_dst_get_next_hp(hal_soc_handle_t hal_soc_hdl,
  1388. hal_ring_handle_t hal_ring_hdl)
  1389. {
  1390. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1391. uint32_t *desc;
  1392. /* TODO: Using % is expensive, but we have to do this since
  1393. * size of some SRNG rings is not power of 2 (due to descriptor
  1394. * sizes). Need to create separate API for rings used
  1395. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1396. * SW2RXDMA and CE rings)
  1397. */
  1398. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  1399. srng->ring_size;
  1400. if (next_hp != srng->u.dst_ring.tp) {
  1401. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  1402. srng->u.dst_ring.cached_hp = next_hp;
  1403. return (void *)desc;
  1404. }
  1405. return NULL;
  1406. }
  1407. /**
  1408. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  1409. * @hal_soc: Opaque HAL SOC handle
  1410. * @hal_ring_hdl: Destination ring pointer
  1411. *
  1412. * Sync cached head pointer with HW.
  1413. * Caller takes responsibility for any locking needs.
  1414. *
  1415. * Return: Opaque pointer for next ring entry; NULL on failire
  1416. */
  1417. static inline
  1418. void *hal_srng_dst_peek_sync(hal_soc_handle_t hal_soc_hdl,
  1419. hal_ring_handle_t hal_ring_hdl)
  1420. {
  1421. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1422. srng->u.dst_ring.cached_hp =
  1423. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1424. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  1425. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  1426. return NULL;
  1427. }
  1428. /**
  1429. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  1430. * @hal_soc: Opaque HAL SOC handle
  1431. * @hal_ring_hdl: Destination ring pointer
  1432. *
  1433. * Sync cached head pointer with HW.
  1434. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  1435. *
  1436. * Return: Opaque pointer for next ring entry; NULL on failire
  1437. */
  1438. static inline
  1439. void *hal_srng_dst_peek_sync_locked(hal_soc_handle_t hal_soc_hdl,
  1440. hal_ring_handle_t hal_ring_hdl)
  1441. {
  1442. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1443. void *ring_desc_ptr = NULL;
  1444. if (qdf_unlikely(!hal_ring_hdl)) {
  1445. qdf_print("Error: Invalid hal_ring\n");
  1446. return NULL;
  1447. }
  1448. SRNG_LOCK(&srng->lock);
  1449. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc_hdl, hal_ring_hdl);
  1450. SRNG_UNLOCK(&srng->lock);
  1451. return ring_desc_ptr;
  1452. }
  1453. #define hal_srng_dst_num_valid_nolock(hal_soc, hal_ring_hdl, sync_hw_ptr) \
  1454. hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr)
  1455. /**
  1456. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  1457. * by SW) in destination ring
  1458. *
  1459. * @hal_soc: Opaque HAL SOC handle
  1460. * @hal_ring_hdl: Destination ring pointer
  1461. * @sync_hw_ptr: Sync cached head pointer with HW
  1462. *
  1463. */
  1464. static inline
  1465. uint32_t hal_srng_dst_num_valid(void *hal_soc,
  1466. hal_ring_handle_t hal_ring_hdl,
  1467. int sync_hw_ptr)
  1468. {
  1469. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1470. uint32_t hp;
  1471. uint32_t tp = srng->u.dst_ring.tp;
  1472. if (sync_hw_ptr) {
  1473. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1474. srng->u.dst_ring.cached_hp = hp;
  1475. } else {
  1476. hp = srng->u.dst_ring.cached_hp;
  1477. }
  1478. if (hp >= tp)
  1479. return (hp - tp) / srng->entry_size;
  1480. return (srng->ring_size - tp + hp) / srng->entry_size;
  1481. }
  1482. /**
  1483. * hal_srng_dst_inv_cached_descs - API to invalidate descriptors in batch mode
  1484. * @hal_soc: Opaque HAL SOC handle
  1485. * @hal_ring_hdl: Destination ring pointer
  1486. * @entry_count: call invalidate API if valid entries available
  1487. *
  1488. * Invalidates a set of cached descriptors starting from TP to cached_HP
  1489. *
  1490. * Return - None
  1491. */
  1492. static inline void hal_srng_dst_inv_cached_descs(void *hal_soc,
  1493. hal_ring_handle_t hal_ring_hdl,
  1494. uint32_t entry_count)
  1495. {
  1496. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1497. uint32_t *first_desc;
  1498. uint32_t *last_desc;
  1499. /*
  1500. * If SRNG does not have cached descriptors this
  1501. * API call should be a no op
  1502. */
  1503. if (!(srng->flags & HAL_SRNG_CACHED_DESC))
  1504. return;
  1505. if (!entry_count)
  1506. return;
  1507. first_desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1508. last_desc = &srng->ring_base_vaddr[srng->u.dst_ring.cached_hp];
  1509. if (last_desc > (uint32_t *)first_desc)
  1510. /* invalidate from tp to cached_hp */
  1511. qdf_nbuf_dma_inv_range((void *)first_desc, (void *)(last_desc));
  1512. else {
  1513. /* invalidate from tp to end of the ring */
  1514. qdf_nbuf_dma_inv_range((void *)first_desc,
  1515. (void *)srng->ring_vaddr_end);
  1516. /* invalidate from start of ring to cached_hp */
  1517. qdf_nbuf_dma_inv_range((void *)srng->ring_base_vaddr,
  1518. (void *)last_desc);
  1519. }
  1520. }
  1521. /**
  1522. * hal_srng_dst_num_valid_locked - Returns num valid entries to be processed
  1523. *
  1524. * @hal_soc: Opaque HAL SOC handle
  1525. * @hal_ring_hdl: Destination ring pointer
  1526. * @sync_hw_ptr: Sync cached head pointer with HW
  1527. *
  1528. * Returns number of valid entries to be processed by the host driver. The
  1529. * function takes up SRNG lock.
  1530. *
  1531. * Return: Number of valid destination entries
  1532. */
  1533. static inline uint32_t
  1534. hal_srng_dst_num_valid_locked(hal_soc_handle_t hal_soc,
  1535. hal_ring_handle_t hal_ring_hdl,
  1536. int sync_hw_ptr)
  1537. {
  1538. uint32_t num_valid;
  1539. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1540. SRNG_LOCK(&srng->lock);
  1541. num_valid = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr);
  1542. SRNG_UNLOCK(&srng->lock);
  1543. return num_valid;
  1544. }
  1545. /**
  1546. * hal_srng_sync_cachedhp - sync cachehp pointer from hw hp
  1547. *
  1548. * @hal_soc: Opaque HAL SOC handle
  1549. * @hal_ring_hdl: Destination ring pointer
  1550. *
  1551. */
  1552. static inline
  1553. void hal_srng_sync_cachedhp(void *hal_soc,
  1554. hal_ring_handle_t hal_ring_hdl)
  1555. {
  1556. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1557. uint32_t hp;
  1558. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1559. srng->u.dst_ring.cached_hp = hp;
  1560. }
  1561. /**
  1562. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  1563. * pointer. This can be used to release any buffers associated with completed
  1564. * ring entries. Note that this should not be used for posting new descriptor
  1565. * entries. Posting of new entries should be done only using
  1566. * hal_srng_src_get_next_reaped when this function is used for reaping.
  1567. *
  1568. * @hal_soc: Opaque HAL SOC handle
  1569. * @hal_ring_hdl: Source ring pointer
  1570. *
  1571. * Return: Opaque pointer for next ring entry; NULL on failire
  1572. */
  1573. static inline void *
  1574. hal_srng_src_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1575. {
  1576. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1577. uint32_t *desc;
  1578. /* TODO: Using % is expensive, but we have to do this since
  1579. * size of some SRNG rings is not power of 2 (due to descriptor
  1580. * sizes). Need to create separate API for rings used
  1581. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1582. * SW2RXDMA and CE rings)
  1583. */
  1584. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1585. srng->ring_size;
  1586. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  1587. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1588. srng->u.src_ring.reap_hp = next_reap_hp;
  1589. return (void *)desc;
  1590. }
  1591. return NULL;
  1592. }
  1593. /**
  1594. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  1595. * already reaped using hal_srng_src_reap_next, for posting new entries to
  1596. * the ring
  1597. *
  1598. * @hal_soc: Opaque HAL SOC handle
  1599. * @hal_ring_hdl: Source ring pointer
  1600. *
  1601. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  1602. */
  1603. static inline void *
  1604. hal_srng_src_get_next_reaped(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1605. {
  1606. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1607. uint32_t *desc;
  1608. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  1609. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1610. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  1611. srng->ring_size;
  1612. return (void *)desc;
  1613. }
  1614. return NULL;
  1615. }
  1616. /**
  1617. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  1618. * move reap pointer. This API is used in detach path to release any buffers
  1619. * associated with ring entries which are pending reap.
  1620. *
  1621. * @hal_soc: Opaque HAL SOC handle
  1622. * @hal_ring_hdl: Source ring pointer
  1623. *
  1624. * Return: Opaque pointer for next ring entry; NULL on failire
  1625. */
  1626. static inline void *
  1627. hal_srng_src_pending_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1628. {
  1629. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1630. uint32_t *desc;
  1631. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1632. srng->ring_size;
  1633. if (next_reap_hp != srng->u.src_ring.hp) {
  1634. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1635. srng->u.src_ring.reap_hp = next_reap_hp;
  1636. return (void *)desc;
  1637. }
  1638. return NULL;
  1639. }
  1640. /**
  1641. * hal_srng_src_done_val -
  1642. *
  1643. * @hal_soc: Opaque HAL SOC handle
  1644. * @hal_ring_hdl: Source ring pointer
  1645. *
  1646. * Return: Opaque pointer for next ring entry; NULL on failire
  1647. */
  1648. static inline uint32_t
  1649. hal_srng_src_done_val(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1650. {
  1651. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1652. /* TODO: Using % is expensive, but we have to do this since
  1653. * size of some SRNG rings is not power of 2 (due to descriptor
  1654. * sizes). Need to create separate API for rings used
  1655. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1656. * SW2RXDMA and CE rings)
  1657. */
  1658. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1659. srng->ring_size;
  1660. if (next_reap_hp == srng->u.src_ring.cached_tp)
  1661. return 0;
  1662. if (srng->u.src_ring.cached_tp > next_reap_hp)
  1663. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  1664. srng->entry_size;
  1665. else
  1666. return ((srng->ring_size - next_reap_hp) +
  1667. srng->u.src_ring.cached_tp) / srng->entry_size;
  1668. }
  1669. /**
  1670. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  1671. * @hal_ring_hdl: Source ring pointer
  1672. *
  1673. * srng->entry_size value is in 4 byte dwords so left shifting
  1674. * this by 2 to return the value of entry_size in bytes.
  1675. *
  1676. * Return: uint8_t
  1677. */
  1678. static inline
  1679. uint8_t hal_get_entrysize_from_srng(hal_ring_handle_t hal_ring_hdl)
  1680. {
  1681. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1682. return srng->entry_size << 2;
  1683. }
  1684. /**
  1685. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  1686. * @hal_soc: Opaque HAL SOC handle
  1687. * @hal_ring_hdl: Source ring pointer
  1688. * @tailp: Tail Pointer
  1689. * @headp: Head Pointer
  1690. *
  1691. * Return: Update tail pointer and head pointer in arguments.
  1692. */
  1693. static inline
  1694. void hal_get_sw_hptp(void *hal_soc, hal_ring_handle_t hal_ring_hdl,
  1695. uint32_t *tailp, uint32_t *headp)
  1696. {
  1697. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1698. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1699. *headp = srng->u.src_ring.hp;
  1700. *tailp = *srng->u.src_ring.tp_addr;
  1701. } else {
  1702. *tailp = srng->u.dst_ring.tp;
  1703. *headp = *srng->u.dst_ring.hp_addr;
  1704. }
  1705. }
  1706. #if defined(CLEAR_SW2TCL_CONSUMED_DESC)
  1707. /**
  1708. * hal_srng_src_get_next_consumed - Get the next desc if consumed by HW
  1709. *
  1710. * @hal_soc: Opaque HAL SOC handle
  1711. * @hal_ring_hdl: Source ring pointer
  1712. *
  1713. * Return: pointer to descriptor if consumed by HW, else NULL
  1714. */
  1715. static inline
  1716. void *hal_srng_src_get_next_consumed(void *hal_soc,
  1717. hal_ring_handle_t hal_ring_hdl)
  1718. {
  1719. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1720. uint32_t *desc = NULL;
  1721. /* TODO: Using % is expensive, but we have to do this since
  1722. * size of some SRNG rings is not power of 2 (due to descriptor
  1723. * sizes). Need to create separate API for rings used
  1724. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1725. * SW2RXDMA and CE rings)
  1726. */
  1727. uint32_t next_entry = (srng->last_desc_cleared + srng->entry_size) %
  1728. srng->ring_size;
  1729. if (next_entry != srng->u.src_ring.cached_tp) {
  1730. desc = &srng->ring_base_vaddr[next_entry];
  1731. srng->last_desc_cleared = next_entry;
  1732. }
  1733. return desc;
  1734. }
  1735. #else
  1736. static inline
  1737. void *hal_srng_src_get_next_consumed(void *hal_soc,
  1738. hal_ring_handle_t hal_ring_hdl)
  1739. {
  1740. return NULL;
  1741. }
  1742. #endif /* CLEAR_SW2TCL_CONSUMED_DESC */
  1743. /**
  1744. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  1745. *
  1746. * @hal_soc: Opaque HAL SOC handle
  1747. * @hal_ring_hdl: Source ring pointer
  1748. *
  1749. * Return: Opaque pointer for next ring entry; NULL on failire
  1750. */
  1751. static inline
  1752. void *hal_srng_src_get_next(void *hal_soc,
  1753. hal_ring_handle_t hal_ring_hdl)
  1754. {
  1755. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1756. uint32_t *desc;
  1757. /* TODO: Using % is expensive, but we have to do this since
  1758. * size of some SRNG rings is not power of 2 (due to descriptor
  1759. * sizes). Need to create separate API for rings used
  1760. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1761. * SW2RXDMA and CE rings)
  1762. */
  1763. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1764. srng->ring_size;
  1765. if (next_hp != srng->u.src_ring.cached_tp) {
  1766. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1767. srng->u.src_ring.hp = next_hp;
  1768. /* TODO: Since reap function is not used by all rings, we can
  1769. * remove the following update of reap_hp in this function
  1770. * if we can ensure that only hal_srng_src_get_next_reaped
  1771. * is used for the rings requiring reap functionality
  1772. */
  1773. srng->u.src_ring.reap_hp = next_hp;
  1774. return (void *)desc;
  1775. }
  1776. return NULL;
  1777. }
  1778. /**
  1779. * hal_srng_src_peek_n_get_next - Get next entry from a ring without
  1780. * moving head pointer.
  1781. * hal_srng_src_get_next should be called subsequently to move the head pointer
  1782. *
  1783. * @hal_soc: Opaque HAL SOC handle
  1784. * @hal_ring_hdl: Source ring pointer
  1785. *
  1786. * Return: Opaque pointer for next ring entry; NULL on failire
  1787. */
  1788. static inline
  1789. void *hal_srng_src_peek_n_get_next(hal_soc_handle_t hal_soc_hdl,
  1790. hal_ring_handle_t hal_ring_hdl)
  1791. {
  1792. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1793. uint32_t *desc;
  1794. /* TODO: Using % is expensive, but we have to do this since
  1795. * size of some SRNG rings is not power of 2 (due to descriptor
  1796. * sizes). Need to create separate API for rings used
  1797. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1798. * SW2RXDMA and CE rings)
  1799. */
  1800. if (((srng->u.src_ring.hp + srng->entry_size) %
  1801. srng->ring_size) != srng->u.src_ring.cached_tp) {
  1802. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1803. srng->entry_size) %
  1804. srng->ring_size]);
  1805. return (void *)desc;
  1806. }
  1807. return NULL;
  1808. }
  1809. /**
  1810. * hal_srng_src_peek_n_get_next_next - Get next to next, i.e HP + 2 entry
  1811. * from a ring without moving head pointer.
  1812. *
  1813. * @hal_soc: Opaque HAL SOC handle
  1814. * @hal_ring_hdl: Source ring pointer
  1815. *
  1816. * Return: Opaque pointer for next to next ring entry; NULL on failire
  1817. */
  1818. static inline
  1819. void *hal_srng_src_peek_n_get_next_next(hal_soc_handle_t hal_soc_hdl,
  1820. hal_ring_handle_t hal_ring_hdl)
  1821. {
  1822. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1823. uint32_t *desc;
  1824. /* TODO: Using % is expensive, but we have to do this since
  1825. * size of some SRNG rings is not power of 2 (due to descriptor
  1826. * sizes). Need to create separate API for rings used
  1827. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1828. * SW2RXDMA and CE rings)
  1829. */
  1830. if ((((srng->u.src_ring.hp + (srng->entry_size)) %
  1831. srng->ring_size) != srng->u.src_ring.cached_tp) &&
  1832. (((srng->u.src_ring.hp + (srng->entry_size * 2)) %
  1833. srng->ring_size) != srng->u.src_ring.cached_tp)) {
  1834. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1835. (srng->entry_size * 2)) %
  1836. srng->ring_size]);
  1837. return (void *)desc;
  1838. }
  1839. return NULL;
  1840. }
  1841. /**
  1842. * hal_srng_src_get_cur_hp_n_move_next () - API returns current hp
  1843. * and move hp to next in src ring
  1844. *
  1845. * Usage: This API should only be used at init time replenish.
  1846. *
  1847. * @hal_soc_hdl: HAL soc handle
  1848. * @hal_ring_hdl: Source ring pointer
  1849. *
  1850. */
  1851. static inline void *
  1852. hal_srng_src_get_cur_hp_n_move_next(hal_soc_handle_t hal_soc_hdl,
  1853. hal_ring_handle_t hal_ring_hdl)
  1854. {
  1855. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1856. uint32_t *cur_desc = NULL;
  1857. uint32_t next_hp;
  1858. cur_desc = &srng->ring_base_vaddr[(srng->u.src_ring.hp)];
  1859. next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1860. srng->ring_size;
  1861. if (next_hp != srng->u.src_ring.cached_tp)
  1862. srng->u.src_ring.hp = next_hp;
  1863. return (void *)cur_desc;
  1864. }
  1865. /**
  1866. * hal_srng_src_num_avail - Returns number of available entries in src ring
  1867. *
  1868. * @hal_soc: Opaque HAL SOC handle
  1869. * @hal_ring_hdl: Source ring pointer
  1870. * @sync_hw_ptr: Sync cached tail pointer with HW
  1871. *
  1872. */
  1873. static inline uint32_t
  1874. hal_srng_src_num_avail(void *hal_soc,
  1875. hal_ring_handle_t hal_ring_hdl, int sync_hw_ptr)
  1876. {
  1877. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1878. uint32_t tp;
  1879. uint32_t hp = srng->u.src_ring.hp;
  1880. if (sync_hw_ptr) {
  1881. tp = *(srng->u.src_ring.tp_addr);
  1882. srng->u.src_ring.cached_tp = tp;
  1883. } else {
  1884. tp = srng->u.src_ring.cached_tp;
  1885. }
  1886. if (tp > hp)
  1887. return ((tp - hp) / srng->entry_size) - 1;
  1888. else
  1889. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  1890. }
  1891. /**
  1892. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  1893. * ring head/tail pointers to HW.
  1894. *
  1895. * @hal_soc: Opaque HAL SOC handle
  1896. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1897. *
  1898. * The target expects cached head/tail pointer to be updated to the
  1899. * shared location in the little-endian order, This API ensures that.
  1900. * This API should be used only if hal_srng_access_start_unlocked was used to
  1901. * start ring access
  1902. *
  1903. * Return: None
  1904. */
  1905. static inline void
  1906. hal_srng_access_end_unlocked(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1907. {
  1908. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1909. /* TODO: See if we need a write memory barrier here */
  1910. if (srng->flags & HAL_SRNG_LMAC_RING) {
  1911. /* For LMAC rings, ring pointer updates are done through FW and
  1912. * hence written to a shared memory location that is read by FW
  1913. */
  1914. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1915. *srng->u.src_ring.hp_addr =
  1916. qdf_cpu_to_le32(srng->u.src_ring.hp);
  1917. } else {
  1918. *srng->u.dst_ring.tp_addr =
  1919. qdf_cpu_to_le32(srng->u.dst_ring.tp);
  1920. }
  1921. } else {
  1922. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1923. hal_srng_write_address_32_mb(hal_soc,
  1924. srng,
  1925. srng->u.src_ring.hp_addr,
  1926. srng->u.src_ring.hp);
  1927. else
  1928. hal_srng_write_address_32_mb(hal_soc,
  1929. srng,
  1930. srng->u.dst_ring.tp_addr,
  1931. srng->u.dst_ring.tp);
  1932. }
  1933. }
  1934. /* hal_srng_access_end_unlocked already handles endianness conversion,
  1935. * use the same.
  1936. */
  1937. #define hal_le_srng_access_end_unlocked_in_cpu_order \
  1938. hal_srng_access_end_unlocked
  1939. /**
  1940. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  1941. * pointers to HW
  1942. *
  1943. * @hal_soc: Opaque HAL SOC handle
  1944. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1945. *
  1946. * The target expects cached head/tail pointer to be updated to the
  1947. * shared location in the little-endian order, This API ensures that.
  1948. * This API should be used only if hal_srng_access_start was used to
  1949. * start ring access
  1950. *
  1951. * Return: 0 on success; error on failire
  1952. */
  1953. static inline void
  1954. hal_srng_access_end(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1955. {
  1956. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1957. if (qdf_unlikely(!hal_ring_hdl)) {
  1958. qdf_print("Error: Invalid hal_ring\n");
  1959. return;
  1960. }
  1961. hal_srng_access_end_unlocked(hal_soc, hal_ring_hdl);
  1962. SRNG_UNLOCK(&(srng->lock));
  1963. }
  1964. /* hal_srng_access_end already handles endianness conversion, so use the same */
  1965. #define hal_le_srng_access_end_in_cpu_order \
  1966. hal_srng_access_end
  1967. /**
  1968. * hal_srng_access_end_reap - Unlock ring access
  1969. * This should be used only if hal_srng_access_start to start ring access
  1970. * and should be used only while reaping SRC ring completions
  1971. *
  1972. * @hal_soc: Opaque HAL SOC handle
  1973. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1974. *
  1975. * Return: 0 on success; error on failire
  1976. */
  1977. static inline void
  1978. hal_srng_access_end_reap(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1979. {
  1980. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1981. SRNG_UNLOCK(&(srng->lock));
  1982. }
  1983. /* TODO: Check if the following definitions is available in HW headers */
  1984. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  1985. #define NUM_MPDUS_PER_LINK_DESC 6
  1986. #define NUM_MSDUS_PER_LINK_DESC 7
  1987. #define REO_QUEUE_DESC_ALIGN 128
  1988. #define LINK_DESC_ALIGN 128
  1989. #define ADDRESS_MATCH_TAG_VAL 0x5
  1990. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  1991. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  1992. */
  1993. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  1994. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  1995. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  1996. * should be specified in 16 word units. But the number of bits defined for
  1997. * this field in HW header files is 5.
  1998. */
  1999. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  2000. /**
  2001. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  2002. * in an idle list
  2003. *
  2004. * @hal_soc: Opaque HAL SOC handle
  2005. *
  2006. */
  2007. static inline
  2008. uint32_t hal_idle_list_scatter_buf_size(hal_soc_handle_t hal_soc_hdl)
  2009. {
  2010. return WBM_IDLE_SCATTER_BUF_SIZE;
  2011. }
  2012. /**
  2013. * hal_get_link_desc_size - Get the size of each link descriptor
  2014. *
  2015. * @hal_soc: Opaque HAL SOC handle
  2016. *
  2017. */
  2018. static inline uint32_t hal_get_link_desc_size(hal_soc_handle_t hal_soc_hdl)
  2019. {
  2020. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2021. if (!hal_soc || !hal_soc->ops) {
  2022. qdf_print("Error: Invalid ops\n");
  2023. QDF_BUG(0);
  2024. return -EINVAL;
  2025. }
  2026. if (!hal_soc->ops->hal_get_link_desc_size) {
  2027. qdf_print("Error: Invalid function pointer\n");
  2028. QDF_BUG(0);
  2029. return -EINVAL;
  2030. }
  2031. return hal_soc->ops->hal_get_link_desc_size();
  2032. }
  2033. /**
  2034. * hal_get_link_desc_align - Get the required start address alignment for
  2035. * link descriptors
  2036. *
  2037. * @hal_soc: Opaque HAL SOC handle
  2038. *
  2039. */
  2040. static inline
  2041. uint32_t hal_get_link_desc_align(hal_soc_handle_t hal_soc_hdl)
  2042. {
  2043. return LINK_DESC_ALIGN;
  2044. }
  2045. /**
  2046. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  2047. *
  2048. * @hal_soc: Opaque HAL SOC handle
  2049. *
  2050. */
  2051. static inline
  2052. uint32_t hal_num_mpdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  2053. {
  2054. return NUM_MPDUS_PER_LINK_DESC;
  2055. }
  2056. /**
  2057. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  2058. *
  2059. * @hal_soc: Opaque HAL SOC handle
  2060. *
  2061. */
  2062. static inline
  2063. uint32_t hal_num_msdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  2064. {
  2065. return NUM_MSDUS_PER_LINK_DESC;
  2066. }
  2067. /**
  2068. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  2069. * descriptor can hold
  2070. *
  2071. * @hal_soc: Opaque HAL SOC handle
  2072. *
  2073. */
  2074. static inline
  2075. uint32_t hal_num_mpdu_links_per_queue_desc(hal_soc_handle_t hal_soc_hdl)
  2076. {
  2077. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  2078. }
  2079. /**
  2080. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  2081. * that the given buffer size
  2082. *
  2083. * @hal_soc: Opaque HAL SOC handle
  2084. * @scatter_buf_size: Size of scatter buffer
  2085. *
  2086. */
  2087. static inline
  2088. uint32_t hal_idle_scatter_buf_num_entries(hal_soc_handle_t hal_soc_hdl,
  2089. uint32_t scatter_buf_size)
  2090. {
  2091. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  2092. hal_srng_get_entrysize(hal_soc_hdl, WBM_IDLE_LINK);
  2093. }
  2094. /**
  2095. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  2096. * each given buffer size
  2097. *
  2098. * @hal_soc: Opaque HAL SOC handle
  2099. * @total_mem: size of memory to be scattered
  2100. * @scatter_buf_size: Size of scatter buffer
  2101. *
  2102. */
  2103. static inline
  2104. uint32_t hal_idle_list_num_scatter_bufs(hal_soc_handle_t hal_soc_hdl,
  2105. uint32_t total_mem,
  2106. uint32_t scatter_buf_size)
  2107. {
  2108. uint8_t rem = (total_mem % (scatter_buf_size -
  2109. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  2110. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  2111. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  2112. return num_scatter_bufs;
  2113. }
  2114. enum hal_pn_type {
  2115. HAL_PN_NONE,
  2116. HAL_PN_WPA,
  2117. HAL_PN_WAPI_EVEN,
  2118. HAL_PN_WAPI_UNEVEN,
  2119. };
  2120. #define HAL_RX_MAX_BA_WINDOW 256
  2121. /**
  2122. * hal_get_reo_qdesc_align - Get start address alignment for reo
  2123. * queue descriptors
  2124. *
  2125. * @hal_soc: Opaque HAL SOC handle
  2126. *
  2127. */
  2128. static inline
  2129. uint32_t hal_get_reo_qdesc_align(hal_soc_handle_t hal_soc_hdl)
  2130. {
  2131. return REO_QUEUE_DESC_ALIGN;
  2132. }
  2133. /**
  2134. * hal_srng_get_hp_addr - Get head pointer physical address
  2135. *
  2136. * @hal_soc: Opaque HAL SOC handle
  2137. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  2138. *
  2139. */
  2140. static inline qdf_dma_addr_t
  2141. hal_srng_get_hp_addr(void *hal_soc,
  2142. hal_ring_handle_t hal_ring_hdl)
  2143. {
  2144. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2145. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  2146. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  2147. return hal->shadow_wrptr_mem_paddr +
  2148. ((unsigned long)(srng->u.src_ring.hp_addr) -
  2149. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  2150. } else {
  2151. return hal->shadow_rdptr_mem_paddr +
  2152. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  2153. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  2154. }
  2155. }
  2156. /**
  2157. * hal_srng_get_tp_addr - Get tail pointer physical address
  2158. *
  2159. * @hal_soc: Opaque HAL SOC handle
  2160. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  2161. *
  2162. */
  2163. static inline qdf_dma_addr_t
  2164. hal_srng_get_tp_addr(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  2165. {
  2166. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2167. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  2168. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  2169. return hal->shadow_rdptr_mem_paddr +
  2170. ((unsigned long)(srng->u.src_ring.tp_addr) -
  2171. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  2172. } else {
  2173. return hal->shadow_wrptr_mem_paddr +
  2174. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  2175. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  2176. }
  2177. }
  2178. /**
  2179. * hal_srng_get_num_entries - Get total entries in the HAL Srng
  2180. *
  2181. * @hal_soc: Opaque HAL SOC handle
  2182. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  2183. *
  2184. * Return: total number of entries in hal ring
  2185. */
  2186. static inline
  2187. uint32_t hal_srng_get_num_entries(hal_soc_handle_t hal_soc_hdl,
  2188. hal_ring_handle_t hal_ring_hdl)
  2189. {
  2190. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2191. return srng->num_entries;
  2192. }
  2193. /**
  2194. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  2195. *
  2196. * @hal_soc: Opaque HAL SOC handle
  2197. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  2198. * @ring_params: SRNG parameters will be returned through this structure
  2199. */
  2200. void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  2201. hal_ring_handle_t hal_ring_hdl,
  2202. struct hal_srng_params *ring_params);
  2203. /**
  2204. * hal_mem_info - Retrieve hal memory base address
  2205. *
  2206. * @hal_soc: Opaque HAL SOC handle
  2207. * @mem: pointer to structure to be updated with hal mem info
  2208. */
  2209. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem);
  2210. /**
  2211. * hal_get_target_type - Return target type
  2212. *
  2213. * @hal_soc: Opaque HAL SOC handle
  2214. */
  2215. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl);
  2216. /**
  2217. * hal_srng_dst_hw_init - Private function to initialize SRNG
  2218. * destination ring HW
  2219. * @hal_soc: HAL SOC handle
  2220. * @srng: SRNG ring pointer
  2221. */
  2222. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  2223. struct hal_srng *srng)
  2224. {
  2225. hal->ops->hal_srng_dst_hw_init(hal, srng);
  2226. }
  2227. /**
  2228. * hal_srng_src_hw_init - Private function to initialize SRNG
  2229. * source ring HW
  2230. * @hal_soc: HAL SOC handle
  2231. * @srng: SRNG ring pointer
  2232. */
  2233. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  2234. struct hal_srng *srng)
  2235. {
  2236. hal->ops->hal_srng_src_hw_init(hal, srng);
  2237. }
  2238. /**
  2239. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  2240. * @hal_soc: Opaque HAL SOC handle
  2241. * @hal_ring_hdl: Source ring pointer
  2242. * @headp: Head Pointer
  2243. * @tailp: Tail Pointer
  2244. * @ring_type: Ring
  2245. *
  2246. * Return: Update tail pointer and head pointer in arguments.
  2247. */
  2248. static inline
  2249. void hal_get_hw_hptp(hal_soc_handle_t hal_soc_hdl,
  2250. hal_ring_handle_t hal_ring_hdl,
  2251. uint32_t *headp, uint32_t *tailp,
  2252. uint8_t ring_type)
  2253. {
  2254. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2255. hal_soc->ops->hal_get_hw_hptp(hal_soc, hal_ring_hdl,
  2256. headp, tailp, ring_type);
  2257. }
  2258. /**
  2259. * hal_reo_setup - Initialize HW REO block
  2260. *
  2261. * @hal_soc: Opaque HAL SOC handle
  2262. * @reo_params: parameters needed by HAL for REO config
  2263. */
  2264. static inline void hal_reo_setup(hal_soc_handle_t hal_soc_hdl,
  2265. void *reoparams)
  2266. {
  2267. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2268. hal_soc->ops->hal_reo_setup(hal_soc, reoparams);
  2269. }
  2270. static inline
  2271. void hal_compute_reo_remap_ix2_ix3(hal_soc_handle_t hal_soc_hdl,
  2272. uint32_t *ring, uint32_t num_rings,
  2273. uint32_t *remap1, uint32_t *remap2)
  2274. {
  2275. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2276. return hal_soc->ops->hal_compute_reo_remap_ix2_ix3(ring,
  2277. num_rings, remap1, remap2);
  2278. }
  2279. /**
  2280. * hal_setup_link_idle_list - Setup scattered idle list using the
  2281. * buffer list provided
  2282. *
  2283. * @hal_soc: Opaque HAL SOC handle
  2284. * @scatter_bufs_base_paddr: Array of physical base addresses
  2285. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  2286. * @num_scatter_bufs: Number of scatter buffers in the above lists
  2287. * @scatter_buf_size: Size of each scatter buffer
  2288. * @last_buf_end_offset: Offset to the last entry
  2289. * @num_entries: Total entries of all scatter bufs
  2290. *
  2291. */
  2292. static inline
  2293. void hal_setup_link_idle_list(hal_soc_handle_t hal_soc_hdl,
  2294. qdf_dma_addr_t scatter_bufs_base_paddr[],
  2295. void *scatter_bufs_base_vaddr[],
  2296. uint32_t num_scatter_bufs,
  2297. uint32_t scatter_buf_size,
  2298. uint32_t last_buf_end_offset,
  2299. uint32_t num_entries)
  2300. {
  2301. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2302. hal_soc->ops->hal_setup_link_idle_list(hal_soc, scatter_bufs_base_paddr,
  2303. scatter_bufs_base_vaddr, num_scatter_bufs,
  2304. scatter_buf_size, last_buf_end_offset,
  2305. num_entries);
  2306. }
  2307. #ifdef DUMP_REO_QUEUE_INFO_IN_DDR
  2308. /**
  2309. * hal_dump_rx_reo_queue_desc() - Dump reo queue descriptor fields
  2310. * @hw_qdesc_vaddr_aligned: Pointer to hw reo queue desc virtual addr
  2311. *
  2312. * Use the virtual addr pointer to reo h/w queue desc to read
  2313. * the values from ddr and log them.
  2314. *
  2315. * Return: none
  2316. */
  2317. static inline void hal_dump_rx_reo_queue_desc(
  2318. void *hw_qdesc_vaddr_aligned)
  2319. {
  2320. struct rx_reo_queue *hw_qdesc =
  2321. (struct rx_reo_queue *)hw_qdesc_vaddr_aligned;
  2322. if (!hw_qdesc)
  2323. return;
  2324. hal_info("receive_queue_number %u vld %u window_jump_2k %u"
  2325. " hole_count %u ba_window_size %u ignore_ampdu_flag %u"
  2326. " svld %u ssn %u current_index %u"
  2327. " disable_duplicate_detection %u soft_reorder_enable %u"
  2328. " chk_2k_mode %u oor_mode %u mpdu_frames_processed_count %u"
  2329. " msdu_frames_processed_count %u total_processed_byte_count %u"
  2330. " late_receive_mpdu_count %u seq_2k_error_detected_flag %u"
  2331. " pn_error_detected_flag %u current_mpdu_count %u"
  2332. " current_msdu_count %u timeout_count %u"
  2333. " forward_due_to_bar_count %u duplicate_count %u"
  2334. " frames_in_order_count %u bar_received_count %u"
  2335. " pn_check_needed %u pn_shall_be_even %u"
  2336. " pn_shall_be_uneven %u pn_size %u",
  2337. hw_qdesc->receive_queue_number,
  2338. hw_qdesc->vld,
  2339. hw_qdesc->window_jump_2k,
  2340. hw_qdesc->hole_count,
  2341. hw_qdesc->ba_window_size,
  2342. hw_qdesc->ignore_ampdu_flag,
  2343. hw_qdesc->svld,
  2344. hw_qdesc->ssn,
  2345. hw_qdesc->current_index,
  2346. hw_qdesc->disable_duplicate_detection,
  2347. hw_qdesc->soft_reorder_enable,
  2348. hw_qdesc->chk_2k_mode,
  2349. hw_qdesc->oor_mode,
  2350. hw_qdesc->mpdu_frames_processed_count,
  2351. hw_qdesc->msdu_frames_processed_count,
  2352. hw_qdesc->total_processed_byte_count,
  2353. hw_qdesc->late_receive_mpdu_count,
  2354. hw_qdesc->seq_2k_error_detected_flag,
  2355. hw_qdesc->pn_error_detected_flag,
  2356. hw_qdesc->current_mpdu_count,
  2357. hw_qdesc->current_msdu_count,
  2358. hw_qdesc->timeout_count,
  2359. hw_qdesc->forward_due_to_bar_count,
  2360. hw_qdesc->duplicate_count,
  2361. hw_qdesc->frames_in_order_count,
  2362. hw_qdesc->bar_received_count,
  2363. hw_qdesc->pn_check_needed,
  2364. hw_qdesc->pn_shall_be_even,
  2365. hw_qdesc->pn_shall_be_uneven,
  2366. hw_qdesc->pn_size);
  2367. }
  2368. #else /* DUMP_REO_QUEUE_INFO_IN_DDR */
  2369. static inline void hal_dump_rx_reo_queue_desc(
  2370. void *hw_qdesc_vaddr_aligned)
  2371. {
  2372. }
  2373. #endif /* DUMP_REO_QUEUE_INFO_IN_DDR */
  2374. /**
  2375. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  2376. *
  2377. * @hal_soc: Opaque HAL SOC handle
  2378. * @hal_ring_hdl: Source ring pointer
  2379. * @ring_desc: Opaque ring descriptor handle
  2380. */
  2381. static inline void hal_srng_dump_ring_desc(hal_soc_handle_t hal_soc_hdl,
  2382. hal_ring_handle_t hal_ring_hdl,
  2383. hal_ring_desc_t ring_desc)
  2384. {
  2385. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2386. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  2387. ring_desc, (srng->entry_size << 2));
  2388. }
  2389. /**
  2390. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  2391. *
  2392. * @hal_soc: Opaque HAL SOC handle
  2393. * @hal_ring_hdl: Source ring pointer
  2394. */
  2395. static inline void hal_srng_dump_ring(hal_soc_handle_t hal_soc_hdl,
  2396. hal_ring_handle_t hal_ring_hdl)
  2397. {
  2398. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2399. uint32_t *desc;
  2400. uint32_t tp, i;
  2401. tp = srng->u.dst_ring.tp;
  2402. for (i = 0; i < 128; i++) {
  2403. if (!tp)
  2404. tp = srng->ring_size;
  2405. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  2406. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  2407. QDF_TRACE_LEVEL_DEBUG,
  2408. desc, (srng->entry_size << 2));
  2409. tp -= srng->entry_size;
  2410. }
  2411. }
  2412. /*
  2413. * hal_rxdma_desc_to_hal_ring_desc - API to convert rxdma ring desc
  2414. * to opaque dp_ring desc type
  2415. * @ring_desc - rxdma ring desc
  2416. *
  2417. * Return: hal_rxdma_desc_t type
  2418. */
  2419. static inline
  2420. hal_ring_desc_t hal_rxdma_desc_to_hal_ring_desc(hal_rxdma_desc_t ring_desc)
  2421. {
  2422. return (hal_ring_desc_t)ring_desc;
  2423. }
  2424. /**
  2425. * hal_srng_set_event() - Set hal_srng event
  2426. * @hal_ring_hdl: Source ring pointer
  2427. * @event: SRNG ring event
  2428. *
  2429. * Return: None
  2430. */
  2431. static inline void hal_srng_set_event(hal_ring_handle_t hal_ring_hdl, int event)
  2432. {
  2433. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2434. qdf_atomic_set_bit(event, &srng->srng_event);
  2435. }
  2436. /**
  2437. * hal_srng_clear_event() - Clear hal_srng event
  2438. * @hal_ring_hdl: Source ring pointer
  2439. * @event: SRNG ring event
  2440. *
  2441. * Return: None
  2442. */
  2443. static inline
  2444. void hal_srng_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  2445. {
  2446. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2447. qdf_atomic_clear_bit(event, &srng->srng_event);
  2448. }
  2449. /**
  2450. * hal_srng_get_clear_event() - Clear srng event and return old value
  2451. * @hal_ring_hdl: Source ring pointer
  2452. * @event: SRNG ring event
  2453. *
  2454. * Return: Return old event value
  2455. */
  2456. static inline
  2457. int hal_srng_get_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  2458. {
  2459. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2460. return qdf_atomic_test_and_clear_bit(event, &srng->srng_event);
  2461. }
  2462. /**
  2463. * hal_srng_set_flush_last_ts() - Record last flush time stamp
  2464. * @hal_ring_hdl: Source ring pointer
  2465. *
  2466. * Return: None
  2467. */
  2468. static inline void hal_srng_set_flush_last_ts(hal_ring_handle_t hal_ring_hdl)
  2469. {
  2470. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2471. srng->last_flush_ts = qdf_get_log_timestamp();
  2472. }
  2473. /**
  2474. * hal_srng_inc_flush_cnt() - Increment flush counter
  2475. * @hal_ring_hdl: Source ring pointer
  2476. *
  2477. * Return: None
  2478. */
  2479. static inline void hal_srng_inc_flush_cnt(hal_ring_handle_t hal_ring_hdl)
  2480. {
  2481. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2482. srng->flush_count++;
  2483. }
  2484. /**
  2485. * hal_rx_sw_mon_desc_info_get () - Get SW monitor desc info
  2486. *
  2487. * @hal: Core HAL soc handle
  2488. * @ring_desc: Mon dest ring descriptor
  2489. * @desc_info: Desc info to be populated
  2490. *
  2491. * Return void
  2492. */
  2493. static inline void
  2494. hal_rx_sw_mon_desc_info_get(struct hal_soc *hal,
  2495. hal_ring_desc_t ring_desc,
  2496. hal_rx_mon_desc_info_t desc_info)
  2497. {
  2498. return hal->ops->hal_rx_sw_mon_desc_info_get(ring_desc, desc_info);
  2499. }
  2500. /**
  2501. * hal_reo_set_err_dst_remap() - Set REO error destination ring remap
  2502. * register value.
  2503. *
  2504. * @hal_soc_hdl: Opaque HAL soc handle
  2505. *
  2506. * Return: None
  2507. */
  2508. static inline void hal_reo_set_err_dst_remap(hal_soc_handle_t hal_soc_hdl)
  2509. {
  2510. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2511. if (hal_soc->ops->hal_reo_set_err_dst_remap)
  2512. hal_soc->ops->hal_reo_set_err_dst_remap(hal_soc);
  2513. }
  2514. /**
  2515. * hal_reo_enable_pn_in_dest() - Subscribe for previous PN for 2k-jump or
  2516. * OOR error frames
  2517. * @hal_soc_hdl: Opaque HAL soc handle
  2518. *
  2519. * Return: true if feature is enabled,
  2520. * false, otherwise.
  2521. */
  2522. static inline uint8_t
  2523. hal_reo_enable_pn_in_dest(hal_soc_handle_t hal_soc_hdl)
  2524. {
  2525. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2526. if (hal_soc->ops->hal_reo_enable_pn_in_dest)
  2527. return hal_soc->ops->hal_reo_enable_pn_in_dest(hal_soc);
  2528. return 0;
  2529. }
  2530. #ifdef GENERIC_SHADOW_REGISTER_ACCESS_ENABLE
  2531. /**
  2532. * hal_set_one_target_reg_config() - Populate the target reg
  2533. * offset in hal_soc for one non srng related register at the
  2534. * given list index
  2535. * @hal_soc: hal handle
  2536. * @target_reg_offset: target register offset
  2537. * @list_index: index in hal list for shadow regs
  2538. *
  2539. * Return: none
  2540. */
  2541. void hal_set_one_target_reg_config(struct hal_soc *hal,
  2542. uint32_t target_reg_offset,
  2543. int list_index);
  2544. /**
  2545. * hal_set_shadow_regs() - Populate register offset for
  2546. * registers that need to be populated in list_shadow_reg_config
  2547. * in order to be sent to FW. These reg offsets will be mapped
  2548. * to shadow registers.
  2549. * @hal_soc: hal handle
  2550. *
  2551. * Return: QDF_STATUS_OK on success
  2552. */
  2553. QDF_STATUS hal_set_shadow_regs(void *hal_soc);
  2554. /**
  2555. * hal_construct_shadow_regs() - initialize the shadow registers
  2556. * for non-srng related register configs
  2557. * @hal_soc: hal handle
  2558. *
  2559. * Return: QDF_STATUS_OK on success
  2560. */
  2561. QDF_STATUS hal_construct_shadow_regs(void *hal_soc);
  2562. #else /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  2563. static inline void hal_set_one_target_reg_config(
  2564. struct hal_soc *hal,
  2565. uint32_t target_reg_offset,
  2566. int list_index)
  2567. {
  2568. }
  2569. static inline QDF_STATUS hal_set_shadow_regs(void *hal_soc)
  2570. {
  2571. return QDF_STATUS_SUCCESS;
  2572. }
  2573. static inline QDF_STATUS hal_construct_shadow_regs(void *hal_soc)
  2574. {
  2575. return QDF_STATUS_SUCCESS;
  2576. }
  2577. #endif /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  2578. #ifdef FEATURE_HAL_DELAYED_REG_WRITE
  2579. /**
  2580. * hal_flush_reg_write_work() - flush all writes from register write queue
  2581. * @arg: hal_soc pointer
  2582. *
  2583. * Return: None
  2584. */
  2585. void hal_flush_reg_write_work(hal_soc_handle_t hal_handle);
  2586. #else
  2587. static inline void hal_flush_reg_write_work(hal_soc_handle_t hal_handle) { }
  2588. #endif
  2589. /**
  2590. * hal_get_ring_usage - Calculate the ring usage percentage
  2591. * @hal_ring_hdl: Ring pointer
  2592. * @ring_type: Ring type
  2593. * @headp: pointer to head value
  2594. * @tailp: pointer to tail value
  2595. *
  2596. * Calculate the ring usage percentage for src and dest rings
  2597. *
  2598. * Return: Ring usage percentage
  2599. */
  2600. static inline
  2601. uint32_t hal_get_ring_usage(
  2602. hal_ring_handle_t hal_ring_hdl,
  2603. enum hal_ring_type ring_type, uint32_t *headp, uint32_t *tailp)
  2604. {
  2605. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2606. uint32_t num_avail, num_valid = 0;
  2607. uint32_t ring_usage;
  2608. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  2609. if (*tailp > *headp)
  2610. num_avail = ((*tailp - *headp) / srng->entry_size) - 1;
  2611. else
  2612. num_avail = ((srng->ring_size - *headp + *tailp) /
  2613. srng->entry_size) - 1;
  2614. if (ring_type == WBM_IDLE_LINK)
  2615. num_valid = num_avail;
  2616. else
  2617. num_valid = srng->num_entries - num_avail;
  2618. } else {
  2619. if (*headp >= *tailp)
  2620. num_valid = ((*headp - *tailp) / srng->entry_size);
  2621. else
  2622. num_valid = ((srng->ring_size - *tailp + *headp) /
  2623. srng->entry_size);
  2624. }
  2625. ring_usage = (100 * num_valid) / srng->num_entries;
  2626. return ring_usage;
  2627. }
  2628. /**
  2629. * hal_cmem_write() - function for CMEM buffer writing
  2630. * @hal_soc_hdl: HAL SOC handle
  2631. * @offset: CMEM address
  2632. * @value: value to write
  2633. *
  2634. * Return: None.
  2635. */
  2636. static inline void
  2637. hal_cmem_write(hal_soc_handle_t hal_soc_hdl, uint32_t offset,
  2638. uint32_t value)
  2639. {
  2640. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2641. if (hal_soc->ops->hal_cmem_write)
  2642. hal_soc->ops->hal_cmem_write(hal_soc_hdl, offset, value);
  2643. return;
  2644. }
  2645. static inline bool
  2646. hal_dmac_cmn_src_rxbuf_ring_get(hal_soc_handle_t hal_soc_hdl)
  2647. {
  2648. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2649. return hal_soc->dmac_cmn_src_rxbuf_ring;
  2650. }
  2651. /**
  2652. * hal_srng_dst_prefetch() - function to prefetch 4 destination ring descs
  2653. * @hal_soc_hdl: HAL SOC handle
  2654. * @hal_ring_hdl: Destination ring pointer
  2655. * @num_valid: valid entries in the ring
  2656. *
  2657. * return: last prefetched destination ring descriptor
  2658. */
  2659. static inline
  2660. void *hal_srng_dst_prefetch(hal_soc_handle_t hal_soc_hdl,
  2661. hal_ring_handle_t hal_ring_hdl,
  2662. uint16_t num_valid)
  2663. {
  2664. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2665. uint8_t *desc;
  2666. uint32_t cnt;
  2667. /*
  2668. * prefetching 4 HW descriptors will ensure atleast by the time
  2669. * 5th HW descriptor is being processed it is guranteed that the
  2670. * 5th HW descriptor, its SW Desc, its nbuf and its nbuf's data
  2671. * are in cache line. basically ensuring all the 4 (HW, SW, nbuf
  2672. * & nbuf->data) are prefetched.
  2673. */
  2674. uint32_t max_prefetch = 4;
  2675. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  2676. return NULL;
  2677. desc = (uint8_t *)&srng->ring_base_vaddr[srng->u.dst_ring.tp];
  2678. if (num_valid < max_prefetch)
  2679. max_prefetch = num_valid;
  2680. for (cnt = 0; cnt < max_prefetch; cnt++) {
  2681. desc += srng->entry_size * sizeof(uint32_t);
  2682. if (desc == ((uint8_t *)srng->ring_vaddr_end))
  2683. desc = (uint8_t *)&srng->ring_base_vaddr[0];
  2684. qdf_prefetch(desc);
  2685. }
  2686. return (void *)desc;
  2687. }
  2688. /**
  2689. * hal_srng_dst_prefetch_next_cached_desc() - function to prefetch next desc
  2690. * @hal_soc_hdl: HAL SOC handle
  2691. * @hal_ring_hdl: Destination ring pointer
  2692. * @last_prefetched_hw_desc: last prefetched HW descriptor
  2693. *
  2694. * return: next prefetched destination descriptor
  2695. */
  2696. static inline
  2697. void *hal_srng_dst_prefetch_next_cached_desc(hal_soc_handle_t hal_soc_hdl,
  2698. hal_ring_handle_t hal_ring_hdl,
  2699. uint8_t *last_prefetched_hw_desc)
  2700. {
  2701. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2702. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  2703. return NULL;
  2704. last_prefetched_hw_desc += srng->entry_size * sizeof(uint32_t);
  2705. if (last_prefetched_hw_desc == ((uint8_t *)srng->ring_vaddr_end))
  2706. last_prefetched_hw_desc = (uint8_t *)&srng->ring_base_vaddr[0];
  2707. qdf_prefetch(last_prefetched_hw_desc);
  2708. return (void *)last_prefetched_hw_desc;
  2709. }
  2710. #endif /* _HAL_APIH_ */