hal_api.h 99 KB

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