hal_api.h 66 KB

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