hal_api.h 100 KB

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