hal_api.h 102 KB

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