hal_api.h 55 KB

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