hal_api.h 102 KB

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