hal_api.h 80 KB

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