hal_api.h 55 KB

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