hal_api.h 85 KB

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