hal_api.h 53 KB

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