hal_api.h 53 KB

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