hal_api.h 56 KB

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