hal_api.h 103 KB

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