hal_api.h 56 KB

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