hal_api.h 84 KB

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