hal_api.h 103 KB

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