hal_api.h 54 KB

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