hal_api.h 54 KB

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