hal_api.h 55 KB

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