hal_api.h 98 KB

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