hal_api.h 97 KB

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