hal_api.h 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626
  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. /* Ring index for WBM2SW2 release ring */
  28. #define HAL_IPA_TX_COMP_RING_IDX 2
  29. /* calculate the register address offset from bar0 of shadow register x */
  30. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490)
  31. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x000008FC
  32. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  33. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  34. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  35. #elif defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCN9000)
  36. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x00003024
  37. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  38. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  39. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  40. #elif defined(QCA_WIFI_QCA6750)
  41. #define SHADOW_REGISTER_START_ADDRESS_OFFSET 0x00000504
  42. #define SHADOW_REGISTER_END_ADDRESS_OFFSET \
  43. ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (MAX_SHADOW_REGISTERS)))
  44. #define SHADOW_REGISTER(x) ((SHADOW_REGISTER_START_ADDRESS_OFFSET) + (4 * (x)))
  45. #else
  46. #define SHADOW_REGISTER(x) 0
  47. #endif /* QCA_WIFI_QCA6390 || QCA_WIFI_QCA6490 || QCA_WIFI_QCA6750 */
  48. #define MAX_UNWINDOWED_ADDRESS 0x80000
  49. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490) || \
  50. defined(QCA_WIFI_QCN9000) || defined(QCA_WIFI_QCA6750)
  51. #define WINDOW_ENABLE_BIT 0x40000000
  52. #else
  53. #define WINDOW_ENABLE_BIT 0x80000000
  54. #endif
  55. #define WINDOW_REG_ADDRESS 0x310C
  56. #define WINDOW_SHIFT 19
  57. #define WINDOW_VALUE_MASK 0x3F
  58. #define WINDOW_START MAX_UNWINDOWED_ADDRESS
  59. #define WINDOW_RANGE_MASK 0x7FFFF
  60. /*
  61. * BAR + 4K is always accessible, any access outside this
  62. * space requires force wake procedure.
  63. * OFFSET = 4K - 32 bytes = 0xFE0
  64. */
  65. #define MAPPED_REF_OFF 0xFE0
  66. #ifdef ENABLE_VERBOSE_DEBUG
  67. static inline void
  68. hal_set_verbose_debug(bool flag)
  69. {
  70. is_hal_verbose_debug_enabled = flag;
  71. }
  72. #endif
  73. #ifdef ENABLE_HAL_SOC_STATS
  74. #define HAL_STATS_INC(_handle, _field, _delta) \
  75. { \
  76. if (likely(_handle)) \
  77. _handle->stats._field += _delta; \
  78. }
  79. #else
  80. #define HAL_STATS_INC(_handle, _field, _delta)
  81. #endif
  82. #ifdef ENABLE_HAL_REG_WR_HISTORY
  83. #define HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, wr_val, rd_val) \
  84. hal_reg_wr_fail_history_add(hal_soc, offset, wr_val, rd_val)
  85. void hal_reg_wr_fail_history_add(struct hal_soc *hal_soc,
  86. uint32_t offset,
  87. uint32_t wr_val,
  88. uint32_t rd_val);
  89. static inline int hal_history_get_next_index(qdf_atomic_t *table_index,
  90. int array_size)
  91. {
  92. int record_index = qdf_atomic_inc_return(table_index);
  93. return record_index & (array_size - 1);
  94. }
  95. #else
  96. #define HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, wr_val, rd_val) \
  97. hal_err("write failed at reg offset 0x%x, write 0x%x read 0x%x\n", \
  98. offset, \
  99. wr_val, \
  100. rd_val)
  101. #endif
  102. /**
  103. * hal_reg_write_result_check() - check register writing result
  104. * @hal_soc: HAL soc handle
  105. * @offset: register offset to read
  106. * @exp_val: the expected value of register
  107. * @ret_confirm: result confirm flag
  108. *
  109. * Return: none
  110. */
  111. static inline void hal_reg_write_result_check(struct hal_soc *hal_soc,
  112. uint32_t offset,
  113. uint32_t exp_val)
  114. {
  115. uint32_t value;
  116. value = qdf_ioread32(hal_soc->dev_base_addr + offset);
  117. if (exp_val != value) {
  118. HAL_REG_WRITE_FAIL_HIST_ADD(hal_soc, offset, exp_val, value);
  119. HAL_STATS_INC(hal_soc, reg_write_fail, 1);
  120. }
  121. }
  122. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) || \
  123. !defined(QCA_WIFI_QCA6750)
  124. static inline void hal_lock_reg_access(struct hal_soc *soc,
  125. unsigned long *flags)
  126. {
  127. qdf_spin_lock_irqsave(&soc->register_access_lock);
  128. }
  129. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  130. unsigned long *flags)
  131. {
  132. qdf_spin_unlock_irqrestore(&soc->register_access_lock);
  133. }
  134. #else
  135. static inline void hal_lock_reg_access(struct hal_soc *soc,
  136. unsigned long *flags)
  137. {
  138. pld_lock_reg_window(soc->qdf_dev->dev, flags);
  139. }
  140. static inline void hal_unlock_reg_access(struct hal_soc *soc,
  141. unsigned long *flags)
  142. {
  143. pld_unlock_reg_window(soc->qdf_dev->dev, flags);
  144. }
  145. #endif
  146. #ifdef PCIE_REG_WINDOW_LOCAL_NO_CACHE
  147. /**
  148. * hal_select_window_confirm() - write remap window register and
  149. check writing result
  150. *
  151. */
  152. static inline void hal_select_window_confirm(struct hal_soc *hal_soc,
  153. uint32_t offset)
  154. {
  155. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  156. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  157. WINDOW_ENABLE_BIT | window);
  158. hal_soc->register_window = window;
  159. hal_reg_write_result_check(hal_soc, WINDOW_REG_ADDRESS,
  160. WINDOW_ENABLE_BIT | window);
  161. }
  162. #else
  163. static inline void hal_select_window_confirm(struct hal_soc *hal_soc,
  164. uint32_t offset)
  165. {
  166. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  167. if (window != hal_soc->register_window) {
  168. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  169. WINDOW_ENABLE_BIT | window);
  170. hal_soc->register_window = window;
  171. hal_reg_write_result_check(
  172. hal_soc,
  173. WINDOW_REG_ADDRESS,
  174. WINDOW_ENABLE_BIT | window);
  175. }
  176. }
  177. #endif
  178. static inline qdf_iomem_t hal_get_window_address(struct hal_soc *hal_soc,
  179. qdf_iomem_t addr)
  180. {
  181. return hal_soc->ops->hal_get_window_address(hal_soc, addr);
  182. }
  183. static inline void hal_tx_init_cmd_credit_ring(hal_soc_handle_t hal_soc_hdl,
  184. hal_ring_handle_t hal_ring_hdl)
  185. {
  186. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  187. return hal_soc->ops->hal_tx_init_cmd_credit_ring(hal_soc_hdl,
  188. hal_ring_hdl);
  189. }
  190. /**
  191. * hal_write32_mb() - Access registers to update configuration
  192. * @hal_soc: hal soc handle
  193. * @offset: offset address from the BAR
  194. * @value: value to write
  195. *
  196. * Return: None
  197. *
  198. * Description: Register address space is split below:
  199. * SHADOW REGION UNWINDOWED REGION WINDOWED REGION
  200. * |--------------------|-------------------|------------------|
  201. * BAR NO FORCE WAKE BAR+4K FORCE WAKE BAR+512K FORCE WAKE
  202. *
  203. * 1. Any access to the shadow region, doesn't need force wake
  204. * and windowing logic to access.
  205. * 2. Any access beyond BAR + 4K:
  206. * If init_phase enabled, no force wake is needed and access
  207. * should be based on windowed or unwindowed access.
  208. * If init_phase disabled, force wake is needed and access
  209. * should be based on windowed or unwindowed access.
  210. *
  211. * note1: WINDOW_RANGE_MASK = (1 << WINDOW_SHIFT) -1
  212. * note2: 1 << WINDOW_SHIFT = MAX_UNWINDOWED_ADDRESS
  213. * note3: WINDOW_VALUE_MASK = big enough that trying to write past
  214. * that window would be a bug
  215. */
  216. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) && \
  217. !defined(QCA_WIFI_QCA6750)
  218. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  219. uint32_t value)
  220. {
  221. unsigned long flags;
  222. qdf_iomem_t new_addr;
  223. if (!hal_soc->use_register_windowing ||
  224. offset < MAX_UNWINDOWED_ADDRESS) {
  225. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  226. } else if (hal_soc->static_window_map) {
  227. new_addr = hal_get_window_address(hal_soc,
  228. hal_soc->dev_base_addr + offset);
  229. qdf_iowrite32(new_addr, value);
  230. } else {
  231. hal_lock_reg_access(hal_soc, &flags);
  232. hal_select_window_confirm(hal_soc, offset);
  233. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  234. (offset & WINDOW_RANGE_MASK), value);
  235. hal_unlock_reg_access(hal_soc, &flags);
  236. }
  237. }
  238. #define hal_write32_mb_confirm(_hal_soc, _offset, _value) \
  239. hal_write32_mb(_hal_soc, _offset, _value)
  240. #define hal_write32_mb_cmem(_hal_soc, _offset, _value)
  241. #else
  242. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  243. uint32_t value)
  244. {
  245. int ret;
  246. unsigned long flags;
  247. qdf_iomem_t new_addr;
  248. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  249. hal_soc->hif_handle))) {
  250. hal_err_rl("target access is not allowed");
  251. return;
  252. }
  253. /* Region < BAR + 4K can be directly accessed */
  254. if (offset < MAPPED_REF_OFF) {
  255. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  256. return;
  257. }
  258. /* Region greater than BAR + 4K */
  259. if (!hal_soc->init_phase) {
  260. ret = hif_force_wake_request(hal_soc->hif_handle);
  261. if (ret) {
  262. hal_err("Wake up request failed");
  263. qdf_check_state_before_panic();
  264. return;
  265. }
  266. }
  267. if (!hal_soc->use_register_windowing ||
  268. offset < MAX_UNWINDOWED_ADDRESS) {
  269. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  270. } else if (hal_soc->static_window_map) {
  271. new_addr = hal_get_window_address(
  272. hal_soc,
  273. hal_soc->dev_base_addr + offset);
  274. qdf_iowrite32(new_addr, value);
  275. } else {
  276. hal_lock_reg_access(hal_soc, &flags);
  277. hal_select_window_confirm(hal_soc, offset);
  278. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  279. (offset & WINDOW_RANGE_MASK), value);
  280. hal_unlock_reg_access(hal_soc, &flags);
  281. }
  282. if (!hal_soc->init_phase) {
  283. ret = hif_force_wake_release(hal_soc->hif_handle);
  284. if (ret) {
  285. hal_err("Wake up release failed");
  286. qdf_check_state_before_panic();
  287. return;
  288. }
  289. }
  290. }
  291. /**
  292. * hal_write32_mb_confirm() - write register and check wirting result
  293. *
  294. */
  295. static inline void hal_write32_mb_confirm(struct hal_soc *hal_soc,
  296. uint32_t offset,
  297. uint32_t value)
  298. {
  299. int ret;
  300. unsigned long flags;
  301. qdf_iomem_t new_addr;
  302. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  303. hal_soc->hif_handle))) {
  304. hal_err_rl("target access is not allowed");
  305. return;
  306. }
  307. /* Region < BAR + 4K can be directly accessed */
  308. if (offset < MAPPED_REF_OFF) {
  309. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  310. return;
  311. }
  312. /* Region greater than BAR + 4K */
  313. if (!hal_soc->init_phase) {
  314. ret = hif_force_wake_request(hal_soc->hif_handle);
  315. if (ret) {
  316. hal_err("Wake up request failed");
  317. qdf_check_state_before_panic();
  318. return;
  319. }
  320. }
  321. if (!hal_soc->use_register_windowing ||
  322. offset < MAX_UNWINDOWED_ADDRESS) {
  323. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  324. hal_reg_write_result_check(hal_soc, offset,
  325. value);
  326. } else if (hal_soc->static_window_map) {
  327. new_addr = hal_get_window_address(
  328. hal_soc,
  329. hal_soc->dev_base_addr + offset);
  330. qdf_iowrite32(new_addr, value);
  331. hal_reg_write_result_check(hal_soc,
  332. new_addr - hal_soc->dev_base_addr,
  333. value);
  334. } else {
  335. hal_lock_reg_access(hal_soc, &flags);
  336. hal_select_window_confirm(hal_soc, offset);
  337. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  338. (offset & WINDOW_RANGE_MASK), value);
  339. hal_reg_write_result_check(
  340. hal_soc,
  341. WINDOW_START + (offset & WINDOW_RANGE_MASK),
  342. value);
  343. hal_unlock_reg_access(hal_soc, &flags);
  344. }
  345. if (!hal_soc->init_phase) {
  346. ret = hif_force_wake_release(hal_soc->hif_handle);
  347. if (ret) {
  348. hal_err("Wake up release failed");
  349. qdf_check_state_before_panic();
  350. return;
  351. }
  352. }
  353. }
  354. static inline void hal_write32_mb_cmem(struct hal_soc *hal_soc, uint32_t offset,
  355. uint32_t value)
  356. {
  357. unsigned long flags;
  358. qdf_iomem_t new_addr;
  359. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  360. hal_soc->hif_handle))) {
  361. hal_err_rl("%s: target access is not allowed", __func__);
  362. return;
  363. }
  364. if (!hal_soc->use_register_windowing ||
  365. offset < MAX_UNWINDOWED_ADDRESS) {
  366. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  367. } else if (hal_soc->static_window_map) {
  368. new_addr = hal_get_window_address(
  369. hal_soc,
  370. hal_soc->dev_base_addr + offset);
  371. qdf_iowrite32(new_addr, value);
  372. } else {
  373. hal_lock_reg_access(hal_soc, &flags);
  374. hal_select_window_confirm(hal_soc, offset);
  375. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  376. (offset & WINDOW_RANGE_MASK), value);
  377. hal_unlock_reg_access(hal_soc, &flags);
  378. }
  379. }
  380. #endif
  381. /**
  382. * hal_write_address_32_mb - write a value to a register
  383. *
  384. */
  385. static inline
  386. void hal_write_address_32_mb(struct hal_soc *hal_soc,
  387. qdf_iomem_t addr, uint32_t value, bool wr_confirm)
  388. {
  389. uint32_t offset;
  390. if (!hal_soc->use_register_windowing)
  391. return qdf_iowrite32(addr, value);
  392. offset = addr - hal_soc->dev_base_addr;
  393. if (qdf_unlikely(wr_confirm))
  394. hal_write32_mb_confirm(hal_soc, offset, value);
  395. else
  396. hal_write32_mb(hal_soc, offset, value);
  397. }
  398. #ifdef DP_HAL_MULTIWINDOW_DIRECT_ACCESS
  399. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  400. struct hal_srng *srng,
  401. void __iomem *addr,
  402. uint32_t value)
  403. {
  404. qdf_iowrite32(addr, value);
  405. }
  406. #elif defined(FEATURE_HAL_DELAYED_REG_WRITE)
  407. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  408. struct hal_srng *srng,
  409. void __iomem *addr,
  410. uint32_t value)
  411. {
  412. hal_delayed_reg_write(hal_soc, srng, addr, value);
  413. }
  414. #else
  415. static inline void hal_srng_write_address_32_mb(struct hal_soc *hal_soc,
  416. struct hal_srng *srng,
  417. void __iomem *addr,
  418. uint32_t value)
  419. {
  420. hal_write_address_32_mb(hal_soc, addr, value, false);
  421. }
  422. #endif
  423. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490) && \
  424. !defined(QCA_WIFI_QCA6750)
  425. /**
  426. * hal_read32_mb() - Access registers to read configuration
  427. * @hal_soc: hal soc handle
  428. * @offset: offset address from the BAR
  429. * @value: value to write
  430. *
  431. * Description: Register address space is split below:
  432. * SHADOW REGION UNWINDOWED REGION WINDOWED REGION
  433. * |--------------------|-------------------|------------------|
  434. * BAR NO FORCE WAKE BAR+4K FORCE WAKE BAR+512K FORCE WAKE
  435. *
  436. * 1. Any access to the shadow region, doesn't need force wake
  437. * and windowing logic to access.
  438. * 2. Any access beyond BAR + 4K:
  439. * If init_phase enabled, no force wake is needed and access
  440. * should be based on windowed or unwindowed access.
  441. * If init_phase disabled, force wake is needed and access
  442. * should be based on windowed or unwindowed access.
  443. *
  444. * Return: < 0 for failure/>= 0 for success
  445. */
  446. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  447. {
  448. uint32_t ret;
  449. unsigned long flags;
  450. qdf_iomem_t new_addr;
  451. if (!hal_soc->use_register_windowing ||
  452. offset < MAX_UNWINDOWED_ADDRESS) {
  453. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  454. } else if (hal_soc->static_window_map) {
  455. new_addr = hal_get_window_address(hal_soc, hal_soc->dev_base_addr + offset);
  456. return qdf_ioread32(new_addr);
  457. }
  458. hal_lock_reg_access(hal_soc, &flags);
  459. hal_select_window_confirm(hal_soc, offset);
  460. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  461. (offset & WINDOW_RANGE_MASK));
  462. hal_unlock_reg_access(hal_soc, &flags);
  463. return ret;
  464. }
  465. #define hal_read32_mb_cmem(_hal_soc, _offset)
  466. #else
  467. static
  468. uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  469. {
  470. uint32_t ret;
  471. unsigned long flags;
  472. qdf_iomem_t new_addr;
  473. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  474. hal_soc->hif_handle))) {
  475. hal_err_rl("target access is not allowed");
  476. return 0;
  477. }
  478. /* Region < BAR + 4K can be directly accessed */
  479. if (offset < MAPPED_REF_OFF)
  480. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  481. if ((!hal_soc->init_phase) &&
  482. hif_force_wake_request(hal_soc->hif_handle)) {
  483. hal_err("Wake up request failed");
  484. qdf_check_state_before_panic();
  485. return 0;
  486. }
  487. if (!hal_soc->use_register_windowing ||
  488. offset < MAX_UNWINDOWED_ADDRESS) {
  489. ret = qdf_ioread32(hal_soc->dev_base_addr + offset);
  490. } else if (hal_soc->static_window_map) {
  491. new_addr = hal_get_window_address(
  492. hal_soc,
  493. hal_soc->dev_base_addr + offset);
  494. ret = qdf_ioread32(new_addr);
  495. } else {
  496. hal_lock_reg_access(hal_soc, &flags);
  497. hal_select_window_confirm(hal_soc, offset);
  498. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  499. (offset & WINDOW_RANGE_MASK));
  500. hal_unlock_reg_access(hal_soc, &flags);
  501. }
  502. if ((!hal_soc->init_phase) &&
  503. hif_force_wake_release(hal_soc->hif_handle)) {
  504. hal_err("Wake up release failed");
  505. qdf_check_state_before_panic();
  506. return 0;
  507. }
  508. return ret;
  509. }
  510. static inline
  511. uint32_t hal_read32_mb_cmem(struct hal_soc *hal_soc, uint32_t offset)
  512. {
  513. uint32_t ret;
  514. unsigned long flags;
  515. qdf_iomem_t new_addr;
  516. if (!TARGET_ACCESS_ALLOWED(HIF_GET_SOFTC(
  517. hal_soc->hif_handle))) {
  518. hal_err_rl("%s: target access is not allowed", __func__);
  519. return 0;
  520. }
  521. if (!hal_soc->use_register_windowing ||
  522. offset < MAX_UNWINDOWED_ADDRESS) {
  523. ret = qdf_ioread32(hal_soc->dev_base_addr + offset);
  524. } else if (hal_soc->static_window_map) {
  525. new_addr = hal_get_window_address(
  526. hal_soc,
  527. hal_soc->dev_base_addr + offset);
  528. ret = qdf_ioread32(new_addr);
  529. } else {
  530. hal_lock_reg_access(hal_soc, &flags);
  531. hal_select_window_confirm(hal_soc, offset);
  532. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  533. (offset & WINDOW_RANGE_MASK));
  534. hal_unlock_reg_access(hal_soc, &flags);
  535. }
  536. return ret;
  537. }
  538. #endif
  539. #ifdef GENERIC_SHADOW_REGISTER_ACCESS_ENABLE
  540. /* To check shadow config index range between 0..31 */
  541. #define HAL_SHADOW_REG_INDEX_LOW 32
  542. /* To check shadow config index range between 32..39 */
  543. #define HAL_SHADOW_REG_INDEX_HIGH 40
  544. /* Dirty bit reg offsets corresponding to shadow config index */
  545. #define HAL_SHADOW_REG_DIRTY_BIT_DATA_LOW_OFFSET 0x30C8
  546. #define HAL_SHADOW_REG_DIRTY_BIT_DATA_HIGH_OFFSET 0x30C4
  547. /* PCIE_PCIE_TOP base addr offset */
  548. #define HAL_PCIE_PCIE_TOP_WRAPPER 0x01E00000
  549. /* Max retry attempts to read the dirty bit reg */
  550. #ifdef HAL_CONFIG_SLUB_DEBUG_ON
  551. #define HAL_SHADOW_DIRTY_BIT_POLL_MAX 10000
  552. #else
  553. #define HAL_SHADOW_DIRTY_BIT_POLL_MAX 2000
  554. #endif
  555. /* Delay in usecs for polling dirty bit reg */
  556. #define HAL_SHADOW_DIRTY_BIT_POLL_DELAY 5
  557. /**
  558. * hal_poll_dirty_bit_reg() - Poll dirty register bit to confirm
  559. * write was successful
  560. * @hal_soc: hal soc handle
  561. * @shadow_config_index: index of shadow reg used to confirm
  562. * write
  563. *
  564. * Return: QDF_STATUS_SUCCESS on success
  565. */
  566. static inline QDF_STATUS hal_poll_dirty_bit_reg(struct hal_soc *hal,
  567. int shadow_config_index)
  568. {
  569. uint32_t read_value = 0;
  570. int retry_cnt = 0;
  571. uint32_t reg_offset = 0;
  572. if (shadow_config_index > 0 &&
  573. shadow_config_index < HAL_SHADOW_REG_INDEX_LOW) {
  574. reg_offset =
  575. HAL_SHADOW_REG_DIRTY_BIT_DATA_LOW_OFFSET;
  576. } else if (shadow_config_index >= HAL_SHADOW_REG_INDEX_LOW &&
  577. shadow_config_index < HAL_SHADOW_REG_INDEX_HIGH) {
  578. reg_offset =
  579. HAL_SHADOW_REG_DIRTY_BIT_DATA_HIGH_OFFSET;
  580. } else {
  581. hal_err("Invalid shadow_config_index = %d",
  582. shadow_config_index);
  583. return QDF_STATUS_E_INVAL;
  584. }
  585. while (retry_cnt < HAL_SHADOW_DIRTY_BIT_POLL_MAX) {
  586. read_value = hal_read32_mb(
  587. hal, HAL_PCIE_PCIE_TOP_WRAPPER + reg_offset);
  588. /* Check if dirty bit corresponding to shadow_index is set */
  589. if (read_value & BIT(shadow_config_index)) {
  590. /* Dirty reg bit not reset */
  591. qdf_udelay(HAL_SHADOW_DIRTY_BIT_POLL_DELAY);
  592. retry_cnt++;
  593. } else {
  594. hal_debug("Shadow write: offset 0x%x read val 0x%x",
  595. reg_offset, read_value);
  596. return QDF_STATUS_SUCCESS;
  597. }
  598. }
  599. return QDF_STATUS_E_TIMEOUT;
  600. }
  601. /**
  602. * hal_write32_mb_shadow_confirm() - write to shadow reg and
  603. * poll dirty register bit to confirm write
  604. * @hal_soc: hal soc handle
  605. * @reg_offset: target reg offset address from BAR
  606. * @value: value to write
  607. *
  608. * Return: QDF_STATUS_SUCCESS on success
  609. */
  610. static inline QDF_STATUS hal_write32_mb_shadow_confirm(
  611. struct hal_soc *hal,
  612. uint32_t reg_offset,
  613. uint32_t value)
  614. {
  615. int i;
  616. QDF_STATUS ret;
  617. uint32_t shadow_reg_offset;
  618. uint32_t read_value;
  619. int shadow_config_index;
  620. bool is_reg_offset_present = false;
  621. for (i = 0; i < MAX_GENERIC_SHADOW_REG; i++) {
  622. /* Found the shadow config for the reg_offset */
  623. struct shadow_reg_config *hal_shadow_reg_list =
  624. &hal->list_shadow_reg_config[i];
  625. if (hal_shadow_reg_list->target_register ==
  626. reg_offset) {
  627. shadow_config_index =
  628. hal_shadow_reg_list->shadow_config_index;
  629. shadow_reg_offset =
  630. SHADOW_REGISTER(shadow_config_index);
  631. hal_write32_mb_confirm(
  632. hal, shadow_reg_offset, value);
  633. is_reg_offset_present = true;
  634. break;
  635. }
  636. ret = QDF_STATUS_E_FAILURE;
  637. }
  638. if (is_reg_offset_present) {
  639. ret = hal_poll_dirty_bit_reg(hal, shadow_config_index);
  640. read_value = hal_read32_mb(hal, reg_offset);
  641. hal_info("Shadow retry:reg 0x%x val 0x%x readval 0x%x ret %d",
  642. reg_offset, value, read_value, ret);
  643. if (QDF_IS_STATUS_ERROR(ret)) {
  644. HAL_STATS_INC(hal, shadow_reg_write_fail, 1);
  645. return ret;
  646. }
  647. HAL_STATS_INC(hal, shadow_reg_write_succ, 1);
  648. }
  649. return ret;
  650. }
  651. #else /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  652. static inline QDF_STATUS hal_write32_mb_shadow_confirm(
  653. struct hal_soc *hal_soc,
  654. uint32_t offset,
  655. uint32_t value)
  656. {
  657. return QDF_STATUS_SUCCESS;
  658. }
  659. #endif /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  660. /* Max times allowed for register writing retry */
  661. #define HAL_REG_WRITE_RETRY_MAX 5
  662. /* Delay milliseconds for each time retry */
  663. #define HAL_REG_WRITE_RETRY_DELAY 1
  664. /**
  665. * hal_write32_mb_confirm_retry() - write register with confirming and
  666. do retry/recovery if writing failed
  667. * @hal_soc: hal soc handle
  668. * @offset: offset address from the BAR
  669. * @value: value to write
  670. * @recovery: is recovery needed or not.
  671. *
  672. * Write the register value with confirming and read it back, if
  673. * read back value is not as expected, do retry for writing, if
  674. * retry hit max times allowed but still fail, check if recovery
  675. * needed.
  676. *
  677. * Return: None
  678. */
  679. static inline void hal_write32_mb_confirm_retry(struct hal_soc *hal_soc,
  680. uint32_t offset,
  681. uint32_t value,
  682. bool recovery)
  683. {
  684. uint8_t retry_cnt = 0;
  685. uint32_t read_value;
  686. QDF_STATUS ret;
  687. while (retry_cnt <= HAL_REG_WRITE_RETRY_MAX) {
  688. hal_write32_mb_confirm(hal_soc, offset, value);
  689. read_value = hal_read32_mb(hal_soc, offset);
  690. if (qdf_likely(read_value == value))
  691. break;
  692. /* write failed, do retry */
  693. hal_warn("Retry reg offset 0x%x, value 0x%x, read value 0x%x",
  694. offset, value, read_value);
  695. qdf_mdelay(HAL_REG_WRITE_RETRY_DELAY);
  696. retry_cnt++;
  697. }
  698. if (retry_cnt > HAL_REG_WRITE_RETRY_MAX) {
  699. ret = hal_write32_mb_shadow_confirm(hal_soc, offset, value);
  700. if (QDF_IS_STATUS_ERROR(ret) && recovery)
  701. qdf_trigger_self_recovery(
  702. NULL, QDF_HAL_REG_WRITE_FAILURE);
  703. }
  704. }
  705. #ifdef FEATURE_HAL_DELAYED_REG_WRITE
  706. /**
  707. * hal_dump_reg_write_srng_stats() - dump SRNG reg write stats
  708. * @hal_soc: HAL soc handle
  709. *
  710. * Return: none
  711. */
  712. void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl);
  713. /**
  714. * hal_dump_reg_write_stats() - dump reg write stats
  715. * @hal_soc: HAL soc handle
  716. *
  717. * Return: none
  718. */
  719. void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl);
  720. /**
  721. * hal_get_reg_write_pending_work() - get the number of entries
  722. * pending in the workqueue to be processed.
  723. * @hal_soc: HAL soc handle
  724. *
  725. * Returns: the number of entries pending to be processed
  726. */
  727. int hal_get_reg_write_pending_work(void *hal_soc);
  728. #else
  729. static inline void hal_dump_reg_write_srng_stats(hal_soc_handle_t hal_soc_hdl)
  730. {
  731. }
  732. static inline void hal_dump_reg_write_stats(hal_soc_handle_t hal_soc_hdl)
  733. {
  734. }
  735. static inline int hal_get_reg_write_pending_work(void *hal_soc)
  736. {
  737. return 0;
  738. }
  739. #endif
  740. /**
  741. * hal_read_address_32_mb() - Read 32-bit value from the register
  742. * @soc: soc handle
  743. * @addr: register address to read
  744. *
  745. * Return: 32-bit value
  746. */
  747. static inline
  748. uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  749. qdf_iomem_t addr)
  750. {
  751. uint32_t offset;
  752. uint32_t ret;
  753. if (!soc->use_register_windowing)
  754. return qdf_ioread32(addr);
  755. offset = addr - soc->dev_base_addr;
  756. ret = hal_read32_mb(soc, offset);
  757. return ret;
  758. }
  759. /**
  760. * hal_attach - Initialize HAL layer
  761. * @hif_handle: Opaque HIF handle
  762. * @qdf_dev: QDF device
  763. *
  764. * Return: Opaque HAL SOC handle
  765. * NULL on failure (if given ring is not available)
  766. *
  767. * This function should be called as part of HIF initialization (for accessing
  768. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  769. */
  770. void *hal_attach(struct hif_opaque_softc *hif_handle, qdf_device_t qdf_dev);
  771. /**
  772. * hal_detach - Detach HAL layer
  773. * @hal_soc: HAL SOC handle
  774. *
  775. * This function should be called as part of HIF detach
  776. *
  777. */
  778. extern void hal_detach(void *hal_soc);
  779. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  780. enum hal_ring_type {
  781. REO_DST = 0,
  782. REO_EXCEPTION = 1,
  783. REO_REINJECT = 2,
  784. REO_CMD = 3,
  785. REO_STATUS = 4,
  786. TCL_DATA = 5,
  787. TCL_CMD_CREDIT = 6,
  788. TCL_STATUS = 7,
  789. CE_SRC = 8,
  790. CE_DST = 9,
  791. CE_DST_STATUS = 10,
  792. WBM_IDLE_LINK = 11,
  793. SW2WBM_RELEASE = 12,
  794. WBM2SW_RELEASE = 13,
  795. RXDMA_BUF = 14,
  796. RXDMA_DST = 15,
  797. RXDMA_MONITOR_BUF = 16,
  798. RXDMA_MONITOR_STATUS = 17,
  799. RXDMA_MONITOR_DST = 18,
  800. RXDMA_MONITOR_DESC = 19,
  801. DIR_BUF_RX_DMA_SRC = 20,
  802. #ifdef WLAN_FEATURE_CIF_CFR
  803. WIFI_POS_SRC,
  804. #endif
  805. MAX_RING_TYPES
  806. };
  807. #define HAL_SRNG_LMAC_RING 0x80000000
  808. /* SRNG flags passed in hal_srng_params.flags */
  809. #define HAL_SRNG_MSI_SWAP 0x00000008
  810. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  811. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  812. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  813. #define HAL_SRNG_MSI_INTR 0x00020000
  814. #define HAL_SRNG_CACHED_DESC 0x00040000
  815. #ifdef QCA_WIFI_QCA6490
  816. #define HAL_SRNG_PREFETCH_TIMER 1
  817. #else
  818. #define HAL_SRNG_PREFETCH_TIMER 0
  819. #endif
  820. #define PN_SIZE_24 0
  821. #define PN_SIZE_48 1
  822. #define PN_SIZE_128 2
  823. #ifdef FORCE_WAKE
  824. /**
  825. * hal_set_init_phase() - Indicate initialization of
  826. * datapath rings
  827. * @soc: hal_soc handle
  828. * @init_phase: flag to indicate datapath rings
  829. * initialization status
  830. *
  831. * Return: None
  832. */
  833. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase);
  834. #else
  835. static inline
  836. void hal_set_init_phase(hal_soc_handle_t soc, bool init_phase)
  837. {
  838. }
  839. #endif /* FORCE_WAKE */
  840. /**
  841. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  842. * used by callers for calculating the size of memory to be allocated before
  843. * calling hal_srng_setup to setup the ring
  844. *
  845. * @hal_soc: Opaque HAL SOC handle
  846. * @ring_type: one of the types from hal_ring_type
  847. *
  848. */
  849. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  850. /**
  851. * hal_srng_max_entries - Returns maximum possible number of ring entries
  852. * @hal_soc: Opaque HAL SOC handle
  853. * @ring_type: one of the types from hal_ring_type
  854. *
  855. * Return: Maximum number of entries for the given ring_type
  856. */
  857. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  858. void hal_set_low_threshold(hal_ring_handle_t hal_ring_hdl,
  859. uint32_t low_threshold);
  860. /**
  861. * hal_srng_dump - Dump ring status
  862. * @srng: hal srng pointer
  863. */
  864. void hal_srng_dump(struct hal_srng *srng);
  865. /**
  866. * hal_srng_get_dir - Returns the direction of the ring
  867. * @hal_soc: Opaque HAL SOC handle
  868. * @ring_type: one of the types from hal_ring_type
  869. *
  870. * Return: Ring direction
  871. */
  872. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  873. /* HAL memory information */
  874. struct hal_mem_info {
  875. /* dev base virutal addr */
  876. void *dev_base_addr;
  877. /* dev base physical addr */
  878. void *dev_base_paddr;
  879. /* dev base ce virutal addr - applicable only for qca5018 */
  880. /* In qca5018 CE register are outside wcss block */
  881. /* using a separate address space to access CE registers */
  882. void *dev_base_addr_ce;
  883. /* dev base ce physical addr */
  884. void *dev_base_paddr_ce;
  885. /* Remote virtual pointer memory for HW/FW updates */
  886. void *shadow_rdptr_mem_vaddr;
  887. /* Remote physical pointer memory for HW/FW updates */
  888. void *shadow_rdptr_mem_paddr;
  889. /* Shared memory for ring pointer updates from host to FW */
  890. void *shadow_wrptr_mem_vaddr;
  891. /* Shared physical memory for ring pointer updates from host to FW */
  892. void *shadow_wrptr_mem_paddr;
  893. };
  894. /* SRNG parameters to be passed to hal_srng_setup */
  895. struct hal_srng_params {
  896. /* Physical base address of the ring */
  897. qdf_dma_addr_t ring_base_paddr;
  898. /* Virtual base address of the ring */
  899. void *ring_base_vaddr;
  900. /* Number of entries in ring */
  901. uint32_t num_entries;
  902. /* max transfer length */
  903. uint16_t max_buffer_length;
  904. /* MSI Address */
  905. qdf_dma_addr_t msi_addr;
  906. /* MSI data */
  907. uint32_t msi_data;
  908. /* Interrupt timer threshold – in micro seconds */
  909. uint32_t intr_timer_thres_us;
  910. /* Interrupt batch counter threshold – in number of ring entries */
  911. uint32_t intr_batch_cntr_thres_entries;
  912. /* Low threshold – in number of ring entries
  913. * (valid for src rings only)
  914. */
  915. uint32_t low_threshold;
  916. /* Misc flags */
  917. uint32_t flags;
  918. /* Unique ring id */
  919. uint8_t ring_id;
  920. /* Source or Destination ring */
  921. enum hal_srng_dir ring_dir;
  922. /* Size of ring entry */
  923. uint32_t entry_size;
  924. /* hw register base address */
  925. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  926. /* prefetch timer config - in micro seconds */
  927. uint32_t prefetch_timer;
  928. };
  929. /* hal_construct_srng_shadow_regs() - initialize the shadow
  930. * registers for srngs
  931. * @hal_soc: hal handle
  932. *
  933. * Return: QDF_STATUS_OK on success
  934. */
  935. QDF_STATUS hal_construct_srng_shadow_regs(void *hal_soc);
  936. /* hal_set_one_shadow_config() - add a config for the specified ring
  937. * @hal_soc: hal handle
  938. * @ring_type: ring type
  939. * @ring_num: ring num
  940. *
  941. * The ring type and ring num uniquely specify the ring. After this call,
  942. * the hp/tp will be added as the next entry int the shadow register
  943. * configuration table. The hal code will use the shadow register address
  944. * in place of the hp/tp address.
  945. *
  946. * This function is exposed, so that the CE module can skip configuring shadow
  947. * registers for unused ring and rings assigned to the firmware.
  948. *
  949. * Return: QDF_STATUS_OK on success
  950. */
  951. QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  952. int ring_num);
  953. /**
  954. * hal_get_shadow_config() - retrieve the config table
  955. * @hal_soc: hal handle
  956. * @shadow_config: will point to the table after
  957. * @num_shadow_registers_configured: will contain the number of valid entries
  958. */
  959. extern void hal_get_shadow_config(void *hal_soc,
  960. struct pld_shadow_reg_v2_cfg **shadow_config,
  961. int *num_shadow_registers_configured);
  962. /**
  963. * hal_srng_setup - Initialize HW SRNG ring.
  964. *
  965. * @hal_soc: Opaque HAL SOC handle
  966. * @ring_type: one of the types from hal_ring_type
  967. * @ring_num: Ring number if there are multiple rings of
  968. * same type (staring from 0)
  969. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  970. * @ring_params: SRNG ring params in hal_srng_params structure.
  971. * Callers are expected to allocate contiguous ring memory of size
  972. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  973. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  974. * structure. Ring base address should be 8 byte aligned and size of each ring
  975. * entry should be queried using the API hal_srng_get_entrysize
  976. *
  977. * Return: Opaque pointer to ring on success
  978. * NULL on failure (if given ring is not available)
  979. */
  980. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  981. int mac_id, struct hal_srng_params *ring_params);
  982. /* Remapping ids of REO rings */
  983. #define REO_REMAP_TCL 0
  984. #define REO_REMAP_SW1 1
  985. #define REO_REMAP_SW2 2
  986. #define REO_REMAP_SW3 3
  987. #define REO_REMAP_SW4 4
  988. #define REO_REMAP_RELEASE 5
  989. #define REO_REMAP_FW 6
  990. #define REO_REMAP_UNUSED 7
  991. /*
  992. * Macro to access HWIO_REO_R0_ERROR_DESTINATION_RING_CTRL_IX_0
  993. * to map destination to rings
  994. */
  995. #define HAL_REO_ERR_REMAP_IX0(_VALUE, _OFFSET) \
  996. ((_VALUE) << \
  997. (HWIO_REO_R0_ERROR_DESTINATION_MAPPING_IX_0_ERROR_ ## \
  998. DESTINATION_RING_ ## _OFFSET ## _SHFT))
  999. /*
  1000. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  1001. * to map destination to rings
  1002. */
  1003. #define HAL_REO_REMAP_IX0(_VALUE, _OFFSET) \
  1004. ((_VALUE) << \
  1005. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  1006. _OFFSET ## _SHFT))
  1007. /*
  1008. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_1
  1009. * to map destination to rings
  1010. */
  1011. #define HAL_REO_REMAP_IX2(_VALUE, _OFFSET) \
  1012. ((_VALUE) << \
  1013. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_2_DEST_RING_MAPPING_ ## \
  1014. _OFFSET ## _SHFT))
  1015. /*
  1016. * Macro to access HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3
  1017. * to map destination to rings
  1018. */
  1019. #define HAL_REO_REMAP_IX3(_VALUE, _OFFSET) \
  1020. ((_VALUE) << \
  1021. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_3_DEST_RING_MAPPING_ ## \
  1022. _OFFSET ## _SHFT))
  1023. /**
  1024. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  1025. * @hal_soc_hdl: HAL SOC handle
  1026. * @read: boolean value to indicate if read or write
  1027. * @ix0: pointer to store IX0 reg value
  1028. * @ix1: pointer to store IX1 reg value
  1029. * @ix2: pointer to store IX2 reg value
  1030. * @ix3: pointer to store IX3 reg value
  1031. */
  1032. void hal_reo_read_write_ctrl_ix(hal_soc_handle_t hal_soc_hdl, bool read,
  1033. uint32_t *ix0, uint32_t *ix1,
  1034. uint32_t *ix2, uint32_t *ix3);
  1035. /**
  1036. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  1037. * @sring: sring pointer
  1038. * @paddr: physical address
  1039. */
  1040. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  1041. /**
  1042. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  1043. * @hal_soc: hal_soc handle
  1044. * @srng: sring pointer
  1045. * @vaddr: virtual address
  1046. */
  1047. void hal_srng_dst_init_hp(struct hal_soc_handle *hal_soc,
  1048. struct hal_srng *srng,
  1049. uint32_t *vaddr);
  1050. /**
  1051. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  1052. * @hal_soc: Opaque HAL SOC handle
  1053. * @hal_srng: Opaque HAL SRNG pointer
  1054. */
  1055. void hal_srng_cleanup(void *hal_soc, hal_ring_handle_t hal_ring_hdl);
  1056. static inline bool hal_srng_initialized(hal_ring_handle_t hal_ring_hdl)
  1057. {
  1058. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1059. return !!srng->initialized;
  1060. }
  1061. /**
  1062. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  1063. * @hal_soc: Opaque HAL SOC handle
  1064. * @hal_ring_hdl: Destination ring pointer
  1065. *
  1066. * Caller takes responsibility for any locking needs.
  1067. *
  1068. * Return: Opaque pointer for next ring entry; NULL on failire
  1069. */
  1070. static inline
  1071. void *hal_srng_dst_peek(hal_soc_handle_t hal_soc_hdl,
  1072. hal_ring_handle_t hal_ring_hdl)
  1073. {
  1074. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1075. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  1076. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  1077. return NULL;
  1078. }
  1079. /**
  1080. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  1081. * hal_srng_access_start if locked access is required
  1082. *
  1083. * @hal_soc: Opaque HAL SOC handle
  1084. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1085. *
  1086. * Return: 0 on success; error on failire
  1087. */
  1088. static inline int
  1089. hal_srng_access_start_unlocked(hal_soc_handle_t hal_soc_hdl,
  1090. hal_ring_handle_t hal_ring_hdl)
  1091. {
  1092. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1093. struct hal_soc *soc = (struct hal_soc *)hal_soc_hdl;
  1094. uint32_t *desc;
  1095. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1096. srng->u.src_ring.cached_tp =
  1097. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  1098. else {
  1099. srng->u.dst_ring.cached_hp =
  1100. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1101. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  1102. desc = hal_srng_dst_peek(hal_soc_hdl, hal_ring_hdl);
  1103. if (qdf_likely(desc)) {
  1104. qdf_mem_dma_cache_sync(soc->qdf_dev,
  1105. qdf_mem_virt_to_phys
  1106. (desc),
  1107. QDF_DMA_FROM_DEVICE,
  1108. (srng->entry_size *
  1109. sizeof(uint32_t)));
  1110. qdf_prefetch(desc);
  1111. }
  1112. }
  1113. }
  1114. return 0;
  1115. }
  1116. /**
  1117. * hal_srng_try_access_start - Try to start (locked) ring access
  1118. *
  1119. * @hal_soc: Opaque HAL SOC handle
  1120. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1121. *
  1122. * Return: 0 on success; error on failure
  1123. */
  1124. static inline int hal_srng_try_access_start(hal_soc_handle_t hal_soc_hdl,
  1125. hal_ring_handle_t hal_ring_hdl)
  1126. {
  1127. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1128. if (qdf_unlikely(!hal_ring_hdl)) {
  1129. qdf_print("Error: Invalid hal_ring\n");
  1130. return -EINVAL;
  1131. }
  1132. if (!SRNG_TRY_LOCK(&(srng->lock)))
  1133. return -EINVAL;
  1134. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  1135. }
  1136. /**
  1137. * hal_srng_access_start - Start (locked) ring access
  1138. *
  1139. * @hal_soc: Opaque HAL SOC handle
  1140. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1141. *
  1142. * Return: 0 on success; error on failire
  1143. */
  1144. static inline int hal_srng_access_start(hal_soc_handle_t hal_soc_hdl,
  1145. hal_ring_handle_t hal_ring_hdl)
  1146. {
  1147. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1148. if (qdf_unlikely(!hal_ring_hdl)) {
  1149. qdf_print("Error: Invalid hal_ring\n");
  1150. return -EINVAL;
  1151. }
  1152. SRNG_LOCK(&(srng->lock));
  1153. return hal_srng_access_start_unlocked(hal_soc_hdl, hal_ring_hdl);
  1154. }
  1155. /**
  1156. * hal_srng_dst_get_next - Get next entry from a destination ring
  1157. * @hal_soc: Opaque HAL SOC handle
  1158. * @hal_ring_hdl: Destination ring pointer
  1159. *
  1160. * Return: Opaque pointer for next ring entry; NULL on failure
  1161. */
  1162. static inline
  1163. void *hal_srng_dst_get_next(void *hal_soc,
  1164. hal_ring_handle_t hal_ring_hdl)
  1165. {
  1166. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1167. uint32_t *desc;
  1168. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  1169. return NULL;
  1170. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1171. /* TODO: Using % is expensive, but we have to do this since
  1172. * size of some SRNG rings is not power of 2 (due to descriptor
  1173. * sizes). Need to create separate API for rings used
  1174. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1175. * SW2RXDMA and CE rings)
  1176. */
  1177. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  1178. if (srng->u.dst_ring.tp == srng->ring_size)
  1179. srng->u.dst_ring.tp = 0;
  1180. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  1181. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  1182. uint32_t *desc_next;
  1183. uint32_t tp;
  1184. tp = srng->u.dst_ring.tp;
  1185. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1186. qdf_mem_dma_cache_sync(soc->qdf_dev,
  1187. qdf_mem_virt_to_phys(desc_next),
  1188. QDF_DMA_FROM_DEVICE,
  1189. (srng->entry_size *
  1190. sizeof(uint32_t)));
  1191. qdf_prefetch(desc_next);
  1192. }
  1193. return (void *)desc;
  1194. }
  1195. /**
  1196. * hal_srng_dst_get_next_cached - Get cached next entry
  1197. * @hal_soc: Opaque HAL SOC handle
  1198. * @hal_ring_hdl: Destination ring pointer
  1199. *
  1200. * Get next entry from a destination ring and move cached tail pointer
  1201. *
  1202. * Return: Opaque pointer for next ring entry; NULL on failure
  1203. */
  1204. static inline
  1205. void *hal_srng_dst_get_next_cached(void *hal_soc,
  1206. hal_ring_handle_t hal_ring_hdl)
  1207. {
  1208. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1209. uint32_t *desc;
  1210. uint32_t *desc_next;
  1211. if (srng->u.dst_ring.tp == srng->u.dst_ring.cached_hp)
  1212. return NULL;
  1213. desc = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1214. /* TODO: Using % is expensive, but we have to do this since
  1215. * size of some SRNG rings is not power of 2 (due to descriptor
  1216. * sizes). Need to create separate API for rings used
  1217. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1218. * SW2RXDMA and CE rings)
  1219. */
  1220. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size);
  1221. if (srng->u.dst_ring.tp == srng->ring_size)
  1222. srng->u.dst_ring.tp = 0;
  1223. desc_next = &srng->ring_base_vaddr[srng->u.dst_ring.tp];
  1224. qdf_prefetch(desc_next);
  1225. return (void *)desc;
  1226. }
  1227. /**
  1228. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  1229. * cached head pointer
  1230. *
  1231. * @hal_soc: Opaque HAL SOC handle
  1232. * @hal_ring_hdl: Destination ring pointer
  1233. *
  1234. * Return: Opaque pointer for next ring entry; NULL on failire
  1235. */
  1236. static inline void *
  1237. hal_srng_dst_get_next_hp(hal_soc_handle_t hal_soc_hdl,
  1238. hal_ring_handle_t hal_ring_hdl)
  1239. {
  1240. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1241. uint32_t *desc;
  1242. /* TODO: Using % is expensive, but we have to do this since
  1243. * size of some SRNG rings is not power of 2 (due to descriptor
  1244. * sizes). Need to create separate API for rings used
  1245. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1246. * SW2RXDMA and CE rings)
  1247. */
  1248. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  1249. srng->ring_size;
  1250. if (next_hp != srng->u.dst_ring.tp) {
  1251. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  1252. srng->u.dst_ring.cached_hp = next_hp;
  1253. return (void *)desc;
  1254. }
  1255. return NULL;
  1256. }
  1257. /**
  1258. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  1259. * @hal_soc: Opaque HAL SOC handle
  1260. * @hal_ring_hdl: Destination ring pointer
  1261. *
  1262. * Sync cached head pointer with HW.
  1263. * Caller takes responsibility for any locking needs.
  1264. *
  1265. * Return: Opaque pointer for next ring entry; NULL on failire
  1266. */
  1267. static inline
  1268. void *hal_srng_dst_peek_sync(hal_soc_handle_t hal_soc_hdl,
  1269. hal_ring_handle_t hal_ring_hdl)
  1270. {
  1271. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1272. srng->u.dst_ring.cached_hp =
  1273. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1274. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  1275. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  1276. return NULL;
  1277. }
  1278. /**
  1279. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  1280. * @hal_soc: Opaque HAL SOC handle
  1281. * @hal_ring_hdl: Destination ring pointer
  1282. *
  1283. * Sync cached head pointer with HW.
  1284. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  1285. *
  1286. * Return: Opaque pointer for next ring entry; NULL on failire
  1287. */
  1288. static inline
  1289. void *hal_srng_dst_peek_sync_locked(hal_soc_handle_t hal_soc_hdl,
  1290. hal_ring_handle_t hal_ring_hdl)
  1291. {
  1292. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1293. void *ring_desc_ptr = NULL;
  1294. if (qdf_unlikely(!hal_ring_hdl)) {
  1295. qdf_print("Error: Invalid hal_ring\n");
  1296. return NULL;
  1297. }
  1298. SRNG_LOCK(&srng->lock);
  1299. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc_hdl, hal_ring_hdl);
  1300. SRNG_UNLOCK(&srng->lock);
  1301. return ring_desc_ptr;
  1302. }
  1303. /**
  1304. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  1305. * by SW) in destination ring
  1306. *
  1307. * @hal_soc: Opaque HAL SOC handle
  1308. * @hal_ring_hdl: Destination ring pointer
  1309. * @sync_hw_ptr: Sync cached head pointer with HW
  1310. *
  1311. */
  1312. static inline
  1313. uint32_t hal_srng_dst_num_valid(void *hal_soc,
  1314. hal_ring_handle_t hal_ring_hdl,
  1315. int sync_hw_ptr)
  1316. {
  1317. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1318. uint32_t hp;
  1319. uint32_t tp = srng->u.dst_ring.tp;
  1320. if (sync_hw_ptr) {
  1321. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1322. srng->u.dst_ring.cached_hp = hp;
  1323. } else {
  1324. hp = srng->u.dst_ring.cached_hp;
  1325. }
  1326. if (hp >= tp)
  1327. return (hp - tp) / srng->entry_size;
  1328. return (srng->ring_size - tp + hp) / srng->entry_size;
  1329. }
  1330. /**
  1331. * hal_srng_dst_inv_cached_descs - API to invalidate descriptors in batch mode
  1332. * @hal_soc: Opaque HAL SOC handle
  1333. * @hal_ring_hdl: Destination ring pointer
  1334. * @entry_count: Number of descriptors to be invalidated
  1335. *
  1336. * Invalidates a set of cached descriptors starting from tail to
  1337. * provided count worth
  1338. *
  1339. * Return - None
  1340. */
  1341. static inline void hal_srng_dst_inv_cached_descs(void *hal_soc,
  1342. hal_ring_handle_t hal_ring_hdl,
  1343. uint32_t entry_count)
  1344. {
  1345. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1346. uint32_t hp = srng->u.dst_ring.cached_hp;
  1347. uint32_t tp = srng->u.dst_ring.tp;
  1348. uint32_t sync_p = 0;
  1349. /*
  1350. * If SRNG does not have cached descriptors this
  1351. * API call should be a no op
  1352. */
  1353. if (!(srng->flags & HAL_SRNG_CACHED_DESC))
  1354. return;
  1355. if (qdf_unlikely(entry_count == 0))
  1356. return;
  1357. sync_p = (entry_count - 1) * srng->entry_size;
  1358. if (hp > tp) {
  1359. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1360. &srng->ring_base_vaddr[tp + sync_p]
  1361. + (srng->entry_size * sizeof(uint32_t)));
  1362. } else {
  1363. /*
  1364. * We have wrapped around
  1365. */
  1366. uint32_t wrap_cnt = ((srng->ring_size - tp) / srng->entry_size);
  1367. if (entry_count <= wrap_cnt) {
  1368. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1369. &srng->ring_base_vaddr[tp + sync_p] +
  1370. (srng->entry_size * sizeof(uint32_t)));
  1371. return;
  1372. }
  1373. entry_count -= wrap_cnt;
  1374. sync_p = (entry_count - 1) * srng->entry_size;
  1375. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[tp],
  1376. &srng->ring_base_vaddr[srng->ring_size - srng->entry_size] +
  1377. (srng->entry_size * sizeof(uint32_t)));
  1378. qdf_nbuf_dma_inv_range(&srng->ring_base_vaddr[0],
  1379. &srng->ring_base_vaddr[sync_p]
  1380. + (srng->entry_size * sizeof(uint32_t)));
  1381. }
  1382. }
  1383. /**
  1384. * hal_srng_dst_num_valid_locked - Returns num valid entries to be processed
  1385. *
  1386. * @hal_soc: Opaque HAL SOC handle
  1387. * @hal_ring_hdl: Destination ring pointer
  1388. * @sync_hw_ptr: Sync cached head pointer with HW
  1389. *
  1390. * Returns number of valid entries to be processed by the host driver. The
  1391. * function takes up SRNG lock.
  1392. *
  1393. * Return: Number of valid destination entries
  1394. */
  1395. static inline uint32_t
  1396. hal_srng_dst_num_valid_locked(hal_soc_handle_t hal_soc,
  1397. hal_ring_handle_t hal_ring_hdl,
  1398. int sync_hw_ptr)
  1399. {
  1400. uint32_t num_valid;
  1401. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1402. SRNG_LOCK(&srng->lock);
  1403. num_valid = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, sync_hw_ptr);
  1404. SRNG_UNLOCK(&srng->lock);
  1405. return num_valid;
  1406. }
  1407. /**
  1408. * hal_srng_sync_cachedhp - sync cachehp pointer from hw hp
  1409. *
  1410. * @hal_soc: Opaque HAL SOC handle
  1411. * @hal_ring_hdl: Destination ring pointer
  1412. *
  1413. */
  1414. static inline
  1415. void hal_srng_sync_cachedhp(void *hal_soc,
  1416. hal_ring_handle_t hal_ring_hdl)
  1417. {
  1418. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1419. uint32_t hp;
  1420. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  1421. srng->u.dst_ring.cached_hp = hp;
  1422. }
  1423. /**
  1424. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  1425. * pointer. This can be used to release any buffers associated with completed
  1426. * ring entries. Note that this should not be used for posting new descriptor
  1427. * entries. Posting of new entries should be done only using
  1428. * hal_srng_src_get_next_reaped when this function is used for reaping.
  1429. *
  1430. * @hal_soc: Opaque HAL SOC handle
  1431. * @hal_ring_hdl: Source ring pointer
  1432. *
  1433. * Return: Opaque pointer for next ring entry; NULL on failire
  1434. */
  1435. static inline void *
  1436. hal_srng_src_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1437. {
  1438. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1439. uint32_t *desc;
  1440. /* TODO: Using % is expensive, but we have to do this since
  1441. * size of some SRNG rings is not power of 2 (due to descriptor
  1442. * sizes). Need to create separate API for rings used
  1443. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1444. * SW2RXDMA and CE rings)
  1445. */
  1446. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1447. srng->ring_size;
  1448. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  1449. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1450. srng->u.src_ring.reap_hp = next_reap_hp;
  1451. return (void *)desc;
  1452. }
  1453. return NULL;
  1454. }
  1455. /**
  1456. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  1457. * already reaped using hal_srng_src_reap_next, for posting new entries to
  1458. * the ring
  1459. *
  1460. * @hal_soc: Opaque HAL SOC handle
  1461. * @hal_ring_hdl: Source ring pointer
  1462. *
  1463. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  1464. */
  1465. static inline void *
  1466. hal_srng_src_get_next_reaped(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1467. {
  1468. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1469. uint32_t *desc;
  1470. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  1471. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1472. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  1473. srng->ring_size;
  1474. return (void *)desc;
  1475. }
  1476. return NULL;
  1477. }
  1478. /**
  1479. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  1480. * move reap pointer. This API is used in detach path to release any buffers
  1481. * associated with ring entries which are pending reap.
  1482. *
  1483. * @hal_soc: Opaque HAL SOC handle
  1484. * @hal_ring_hdl: Source ring pointer
  1485. *
  1486. * Return: Opaque pointer for next ring entry; NULL on failire
  1487. */
  1488. static inline void *
  1489. hal_srng_src_pending_reap_next(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1490. {
  1491. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1492. uint32_t *desc;
  1493. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1494. srng->ring_size;
  1495. if (next_reap_hp != srng->u.src_ring.hp) {
  1496. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  1497. srng->u.src_ring.reap_hp = next_reap_hp;
  1498. return (void *)desc;
  1499. }
  1500. return NULL;
  1501. }
  1502. /**
  1503. * hal_srng_src_done_val -
  1504. *
  1505. * @hal_soc: Opaque HAL SOC handle
  1506. * @hal_ring_hdl: Source ring pointer
  1507. *
  1508. * Return: Opaque pointer for next ring entry; NULL on failire
  1509. */
  1510. static inline uint32_t
  1511. hal_srng_src_done_val(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1512. {
  1513. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1514. /* TODO: Using % is expensive, but we have to do this since
  1515. * size of some SRNG rings is not power of 2 (due to descriptor
  1516. * sizes). Need to create separate API for rings used
  1517. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1518. * SW2RXDMA and CE rings)
  1519. */
  1520. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  1521. srng->ring_size;
  1522. if (next_reap_hp == srng->u.src_ring.cached_tp)
  1523. return 0;
  1524. if (srng->u.src_ring.cached_tp > next_reap_hp)
  1525. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  1526. srng->entry_size;
  1527. else
  1528. return ((srng->ring_size - next_reap_hp) +
  1529. srng->u.src_ring.cached_tp) / srng->entry_size;
  1530. }
  1531. /**
  1532. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  1533. * @hal_ring_hdl: Source ring pointer
  1534. *
  1535. * Return: uint8_t
  1536. */
  1537. static inline
  1538. uint8_t hal_get_entrysize_from_srng(hal_ring_handle_t hal_ring_hdl)
  1539. {
  1540. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1541. return srng->entry_size;
  1542. }
  1543. /**
  1544. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  1545. * @hal_soc: Opaque HAL SOC handle
  1546. * @hal_ring_hdl: Source ring pointer
  1547. * @tailp: Tail Pointer
  1548. * @headp: Head Pointer
  1549. *
  1550. * Return: Update tail pointer and head pointer in arguments.
  1551. */
  1552. static inline
  1553. void hal_get_sw_hptp(void *hal_soc, hal_ring_handle_t hal_ring_hdl,
  1554. uint32_t *tailp, uint32_t *headp)
  1555. {
  1556. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1557. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1558. *headp = srng->u.src_ring.hp;
  1559. *tailp = *srng->u.src_ring.tp_addr;
  1560. } else {
  1561. *tailp = srng->u.dst_ring.tp;
  1562. *headp = *srng->u.dst_ring.hp_addr;
  1563. }
  1564. }
  1565. /**
  1566. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  1567. *
  1568. * @hal_soc: Opaque HAL SOC handle
  1569. * @hal_ring_hdl: Source ring pointer
  1570. *
  1571. * Return: Opaque pointer for next ring entry; NULL on failire
  1572. */
  1573. static inline
  1574. void *hal_srng_src_get_next(void *hal_soc,
  1575. hal_ring_handle_t hal_ring_hdl)
  1576. {
  1577. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1578. uint32_t *desc;
  1579. /* TODO: Using % is expensive, but we have to do this since
  1580. * size of some SRNG rings is not power of 2 (due to descriptor
  1581. * sizes). Need to create separate API for rings used
  1582. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1583. * SW2RXDMA and CE rings)
  1584. */
  1585. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1586. srng->ring_size;
  1587. if (next_hp != srng->u.src_ring.cached_tp) {
  1588. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  1589. srng->u.src_ring.hp = next_hp;
  1590. /* TODO: Since reap function is not used by all rings, we can
  1591. * remove the following update of reap_hp in this function
  1592. * if we can ensure that only hal_srng_src_get_next_reaped
  1593. * is used for the rings requiring reap functionality
  1594. */
  1595. srng->u.src_ring.reap_hp = next_hp;
  1596. return (void *)desc;
  1597. }
  1598. return NULL;
  1599. }
  1600. /**
  1601. * hal_srng_src_peek_n_get_next - Get next entry from a ring without
  1602. * moving head pointer.
  1603. * hal_srng_src_get_next should be called subsequently to move the head pointer
  1604. *
  1605. * @hal_soc: Opaque HAL SOC handle
  1606. * @hal_ring_hdl: Source ring pointer
  1607. *
  1608. * Return: Opaque pointer for next ring entry; NULL on failire
  1609. */
  1610. static inline
  1611. void *hal_srng_src_peek_n_get_next(hal_soc_handle_t hal_soc_hdl,
  1612. hal_ring_handle_t hal_ring_hdl)
  1613. {
  1614. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1615. uint32_t *desc;
  1616. /* TODO: Using % is expensive, but we have to do this since
  1617. * size of some SRNG rings is not power of 2 (due to descriptor
  1618. * sizes). Need to create separate API for rings used
  1619. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1620. * SW2RXDMA and CE rings)
  1621. */
  1622. if (((srng->u.src_ring.hp + srng->entry_size) %
  1623. srng->ring_size) != srng->u.src_ring.cached_tp) {
  1624. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1625. srng->entry_size) %
  1626. srng->ring_size]);
  1627. return (void *)desc;
  1628. }
  1629. return NULL;
  1630. }
  1631. /**
  1632. * hal_srng_src_peek_n_get_next_next - Get next to next, i.e HP + 2 entry
  1633. * from a ring without moving head pointer.
  1634. *
  1635. * @hal_soc: Opaque HAL SOC handle
  1636. * @hal_ring_hdl: Source ring pointer
  1637. *
  1638. * Return: Opaque pointer for next to next ring entry; NULL on failire
  1639. */
  1640. static inline
  1641. void *hal_srng_src_peek_n_get_next_next(hal_soc_handle_t hal_soc_hdl,
  1642. hal_ring_handle_t hal_ring_hdl)
  1643. {
  1644. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1645. uint32_t *desc;
  1646. /* TODO: Using % is expensive, but we have to do this since
  1647. * size of some SRNG rings is not power of 2 (due to descriptor
  1648. * sizes). Need to create separate API for rings used
  1649. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  1650. * SW2RXDMA and CE rings)
  1651. */
  1652. if ((((srng->u.src_ring.hp + (srng->entry_size)) %
  1653. srng->ring_size) != srng->u.src_ring.cached_tp) &&
  1654. (((srng->u.src_ring.hp + (srng->entry_size * 2)) %
  1655. srng->ring_size) != srng->u.src_ring.cached_tp)) {
  1656. desc = &(srng->ring_base_vaddr[(srng->u.src_ring.hp +
  1657. (srng->entry_size * 2)) %
  1658. srng->ring_size]);
  1659. return (void *)desc;
  1660. }
  1661. return NULL;
  1662. }
  1663. /**
  1664. * hal_srng_src_get_cur_hp_n_move_next () - API returns current hp
  1665. * and move hp to next in src ring
  1666. *
  1667. * Usage: This API should only be used at init time replenish.
  1668. *
  1669. * @hal_soc_hdl: HAL soc handle
  1670. * @hal_ring_hdl: Source ring pointer
  1671. *
  1672. */
  1673. static inline void *
  1674. hal_srng_src_get_cur_hp_n_move_next(hal_soc_handle_t hal_soc_hdl,
  1675. hal_ring_handle_t hal_ring_hdl)
  1676. {
  1677. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1678. uint32_t *cur_desc = NULL;
  1679. uint32_t next_hp;
  1680. cur_desc = &srng->ring_base_vaddr[(srng->u.src_ring.hp)];
  1681. next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  1682. srng->ring_size;
  1683. if (next_hp != srng->u.src_ring.cached_tp)
  1684. srng->u.src_ring.hp = next_hp;
  1685. return (void *)cur_desc;
  1686. }
  1687. /**
  1688. * hal_srng_src_num_avail - Returns number of available entries in src ring
  1689. *
  1690. * @hal_soc: Opaque HAL SOC handle
  1691. * @hal_ring_hdl: Source ring pointer
  1692. * @sync_hw_ptr: Sync cached tail pointer with HW
  1693. *
  1694. */
  1695. static inline uint32_t
  1696. hal_srng_src_num_avail(void *hal_soc,
  1697. hal_ring_handle_t hal_ring_hdl, int sync_hw_ptr)
  1698. {
  1699. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1700. uint32_t tp;
  1701. uint32_t hp = srng->u.src_ring.hp;
  1702. if (sync_hw_ptr) {
  1703. tp = *(srng->u.src_ring.tp_addr);
  1704. srng->u.src_ring.cached_tp = tp;
  1705. } else {
  1706. tp = srng->u.src_ring.cached_tp;
  1707. }
  1708. if (tp > hp)
  1709. return ((tp - hp) / srng->entry_size) - 1;
  1710. else
  1711. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  1712. }
  1713. /**
  1714. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  1715. * ring head/tail pointers to HW.
  1716. * This should be used only if hal_srng_access_start_unlocked to start ring
  1717. * access
  1718. *
  1719. * @hal_soc: Opaque HAL SOC handle
  1720. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1721. *
  1722. * Return: 0 on success; error on failire
  1723. */
  1724. static inline void
  1725. hal_srng_access_end_unlocked(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1726. {
  1727. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1728. /* TODO: See if we need a write memory barrier here */
  1729. if (srng->flags & HAL_SRNG_LMAC_RING) {
  1730. /* For LMAC rings, ring pointer updates are done through FW and
  1731. * hence written to a shared memory location that is read by FW
  1732. */
  1733. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1734. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  1735. } else {
  1736. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  1737. }
  1738. } else {
  1739. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  1740. hal_srng_write_address_32_mb(hal_soc,
  1741. srng,
  1742. srng->u.src_ring.hp_addr,
  1743. srng->u.src_ring.hp);
  1744. else
  1745. hal_srng_write_address_32_mb(hal_soc,
  1746. srng,
  1747. srng->u.dst_ring.tp_addr,
  1748. srng->u.dst_ring.tp);
  1749. }
  1750. }
  1751. /**
  1752. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  1753. * pointers to HW
  1754. * This should be used only if hal_srng_access_start to start ring access
  1755. *
  1756. * @hal_soc: Opaque HAL SOC handle
  1757. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1758. *
  1759. * Return: 0 on success; error on failire
  1760. */
  1761. static inline void
  1762. hal_srng_access_end(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1763. {
  1764. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1765. if (qdf_unlikely(!hal_ring_hdl)) {
  1766. qdf_print("Error: Invalid hal_ring\n");
  1767. return;
  1768. }
  1769. hal_srng_access_end_unlocked(hal_soc, hal_ring_hdl);
  1770. SRNG_UNLOCK(&(srng->lock));
  1771. }
  1772. /**
  1773. * hal_srng_access_end_reap - Unlock ring access
  1774. * This should be used only if hal_srng_access_start to start ring access
  1775. * and should be used only while reaping SRC ring completions
  1776. *
  1777. * @hal_soc: Opaque HAL SOC handle
  1778. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1779. *
  1780. * Return: 0 on success; error on failire
  1781. */
  1782. static inline void
  1783. hal_srng_access_end_reap(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1784. {
  1785. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1786. SRNG_UNLOCK(&(srng->lock));
  1787. }
  1788. /* TODO: Check if the following definitions is available in HW headers */
  1789. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  1790. #define NUM_MPDUS_PER_LINK_DESC 6
  1791. #define NUM_MSDUS_PER_LINK_DESC 7
  1792. #define REO_QUEUE_DESC_ALIGN 128
  1793. #define LINK_DESC_ALIGN 128
  1794. #define ADDRESS_MATCH_TAG_VAL 0x5
  1795. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  1796. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  1797. */
  1798. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  1799. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  1800. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  1801. * should be specified in 16 word units. But the number of bits defined for
  1802. * this field in HW header files is 5.
  1803. */
  1804. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  1805. /**
  1806. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  1807. * in an idle list
  1808. *
  1809. * @hal_soc: Opaque HAL SOC handle
  1810. *
  1811. */
  1812. static inline
  1813. uint32_t hal_idle_list_scatter_buf_size(hal_soc_handle_t hal_soc_hdl)
  1814. {
  1815. return WBM_IDLE_SCATTER_BUF_SIZE;
  1816. }
  1817. /**
  1818. * hal_get_link_desc_size - Get the size of each link descriptor
  1819. *
  1820. * @hal_soc: Opaque HAL SOC handle
  1821. *
  1822. */
  1823. static inline uint32_t hal_get_link_desc_size(hal_soc_handle_t hal_soc_hdl)
  1824. {
  1825. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  1826. if (!hal_soc || !hal_soc->ops) {
  1827. qdf_print("Error: Invalid ops\n");
  1828. QDF_BUG(0);
  1829. return -EINVAL;
  1830. }
  1831. if (!hal_soc->ops->hal_get_link_desc_size) {
  1832. qdf_print("Error: Invalid function pointer\n");
  1833. QDF_BUG(0);
  1834. return -EINVAL;
  1835. }
  1836. return hal_soc->ops->hal_get_link_desc_size();
  1837. }
  1838. /**
  1839. * hal_get_link_desc_align - Get the required start address alignment for
  1840. * link descriptors
  1841. *
  1842. * @hal_soc: Opaque HAL SOC handle
  1843. *
  1844. */
  1845. static inline
  1846. uint32_t hal_get_link_desc_align(hal_soc_handle_t hal_soc_hdl)
  1847. {
  1848. return LINK_DESC_ALIGN;
  1849. }
  1850. /**
  1851. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  1852. *
  1853. * @hal_soc: Opaque HAL SOC handle
  1854. *
  1855. */
  1856. static inline
  1857. uint32_t hal_num_mpdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1858. {
  1859. return NUM_MPDUS_PER_LINK_DESC;
  1860. }
  1861. /**
  1862. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  1863. *
  1864. * @hal_soc: Opaque HAL SOC handle
  1865. *
  1866. */
  1867. static inline
  1868. uint32_t hal_num_msdus_per_link_desc(hal_soc_handle_t hal_soc_hdl)
  1869. {
  1870. return NUM_MSDUS_PER_LINK_DESC;
  1871. }
  1872. /**
  1873. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1874. * descriptor can hold
  1875. *
  1876. * @hal_soc: Opaque HAL SOC handle
  1877. *
  1878. */
  1879. static inline
  1880. uint32_t hal_num_mpdu_links_per_queue_desc(hal_soc_handle_t hal_soc_hdl)
  1881. {
  1882. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1883. }
  1884. /**
  1885. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1886. * that the given buffer size
  1887. *
  1888. * @hal_soc: Opaque HAL SOC handle
  1889. * @scatter_buf_size: Size of scatter buffer
  1890. *
  1891. */
  1892. static inline
  1893. uint32_t hal_idle_scatter_buf_num_entries(hal_soc_handle_t hal_soc_hdl,
  1894. uint32_t scatter_buf_size)
  1895. {
  1896. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1897. hal_srng_get_entrysize(hal_soc_hdl, WBM_IDLE_LINK);
  1898. }
  1899. /**
  1900. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1901. * each given buffer size
  1902. *
  1903. * @hal_soc: Opaque HAL SOC handle
  1904. * @total_mem: size of memory to be scattered
  1905. * @scatter_buf_size: Size of scatter buffer
  1906. *
  1907. */
  1908. static inline
  1909. uint32_t hal_idle_list_num_scatter_bufs(hal_soc_handle_t hal_soc_hdl,
  1910. uint32_t total_mem,
  1911. uint32_t scatter_buf_size)
  1912. {
  1913. uint8_t rem = (total_mem % (scatter_buf_size -
  1914. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1915. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1916. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1917. return num_scatter_bufs;
  1918. }
  1919. enum hal_pn_type {
  1920. HAL_PN_NONE,
  1921. HAL_PN_WPA,
  1922. HAL_PN_WAPI_EVEN,
  1923. HAL_PN_WAPI_UNEVEN,
  1924. };
  1925. #define HAL_RX_MAX_BA_WINDOW 256
  1926. /**
  1927. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1928. * queue descriptors
  1929. *
  1930. * @hal_soc: Opaque HAL SOC handle
  1931. *
  1932. */
  1933. static inline
  1934. uint32_t hal_get_reo_qdesc_align(hal_soc_handle_t hal_soc_hdl)
  1935. {
  1936. return REO_QUEUE_DESC_ALIGN;
  1937. }
  1938. /**
  1939. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1940. *
  1941. * @hal_soc: Opaque HAL SOC handle
  1942. * @ba_window_size: BlockAck window size
  1943. * @start_seq: Starting sequence number
  1944. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1945. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1946. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1947. *
  1948. */
  1949. void hal_reo_qdesc_setup(hal_soc_handle_t hal_soc_hdl,
  1950. int tid, uint32_t ba_window_size,
  1951. uint32_t start_seq, void *hw_qdesc_vaddr,
  1952. qdf_dma_addr_t hw_qdesc_paddr,
  1953. int pn_type);
  1954. /**
  1955. * hal_srng_get_hp_addr - Get head pointer physical address
  1956. *
  1957. * @hal_soc: Opaque HAL SOC handle
  1958. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1959. *
  1960. */
  1961. static inline qdf_dma_addr_t
  1962. hal_srng_get_hp_addr(void *hal_soc,
  1963. hal_ring_handle_t hal_ring_hdl)
  1964. {
  1965. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1966. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1967. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1968. return hal->shadow_wrptr_mem_paddr +
  1969. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1970. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1971. } else {
  1972. return hal->shadow_rdptr_mem_paddr +
  1973. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1974. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1975. }
  1976. }
  1977. /**
  1978. * hal_srng_get_tp_addr - Get tail pointer physical address
  1979. *
  1980. * @hal_soc: Opaque HAL SOC handle
  1981. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  1982. *
  1983. */
  1984. static inline qdf_dma_addr_t
  1985. hal_srng_get_tp_addr(void *hal_soc, hal_ring_handle_t hal_ring_hdl)
  1986. {
  1987. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  1988. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1989. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1990. return hal->shadow_rdptr_mem_paddr +
  1991. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1992. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1993. } else {
  1994. return hal->shadow_wrptr_mem_paddr +
  1995. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1996. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1997. }
  1998. }
  1999. /**
  2000. * hal_srng_get_num_entries - Get total entries in the HAL Srng
  2001. *
  2002. * @hal_soc: Opaque HAL SOC handle
  2003. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  2004. *
  2005. * Return: total number of entries in hal ring
  2006. */
  2007. static inline
  2008. uint32_t hal_srng_get_num_entries(hal_soc_handle_t hal_soc_hdl,
  2009. hal_ring_handle_t hal_ring_hdl)
  2010. {
  2011. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2012. return srng->num_entries;
  2013. }
  2014. /**
  2015. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  2016. *
  2017. * @hal_soc: Opaque HAL SOC handle
  2018. * @hal_ring_hdl: Ring pointer (Source or Destination ring)
  2019. * @ring_params: SRNG parameters will be returned through this structure
  2020. */
  2021. void hal_get_srng_params(hal_soc_handle_t hal_soc_hdl,
  2022. hal_ring_handle_t hal_ring_hdl,
  2023. struct hal_srng_params *ring_params);
  2024. /**
  2025. * hal_mem_info - Retrieve hal memory base address
  2026. *
  2027. * @hal_soc: Opaque HAL SOC handle
  2028. * @mem: pointer to structure to be updated with hal mem info
  2029. */
  2030. void hal_get_meminfo(hal_soc_handle_t hal_soc_hdl, struct hal_mem_info *mem);
  2031. /**
  2032. * hal_get_target_type - Return target type
  2033. *
  2034. * @hal_soc: Opaque HAL SOC handle
  2035. */
  2036. uint32_t hal_get_target_type(hal_soc_handle_t hal_soc_hdl);
  2037. /**
  2038. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  2039. *
  2040. * @hal_soc: Opaque HAL SOC handle
  2041. * @ac: Access category
  2042. * @value: timeout duration in millisec
  2043. */
  2044. void hal_get_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  2045. uint32_t *value);
  2046. /**
  2047. * hal_set_aging_timeout - Set BA aging timeout
  2048. *
  2049. * @hal_soc: Opaque HAL SOC handle
  2050. * @ac: Access category in millisec
  2051. * @value: timeout duration value
  2052. */
  2053. void hal_set_ba_aging_timeout(hal_soc_handle_t hal_soc_hdl, uint8_t ac,
  2054. uint32_t value);
  2055. /**
  2056. * hal_srng_dst_hw_init - Private function to initialize SRNG
  2057. * destination ring HW
  2058. * @hal_soc: HAL SOC handle
  2059. * @srng: SRNG ring pointer
  2060. */
  2061. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  2062. struct hal_srng *srng)
  2063. {
  2064. hal->ops->hal_srng_dst_hw_init(hal, srng);
  2065. }
  2066. /**
  2067. * hal_srng_src_hw_init - Private function to initialize SRNG
  2068. * source ring HW
  2069. * @hal_soc: HAL SOC handle
  2070. * @srng: SRNG ring pointer
  2071. */
  2072. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  2073. struct hal_srng *srng)
  2074. {
  2075. hal->ops->hal_srng_src_hw_init(hal, srng);
  2076. }
  2077. /**
  2078. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  2079. * @hal_soc: Opaque HAL SOC handle
  2080. * @hal_ring_hdl: Source ring pointer
  2081. * @headp: Head Pointer
  2082. * @tailp: Tail Pointer
  2083. * @ring_type: Ring
  2084. *
  2085. * Return: Update tail pointer and head pointer in arguments.
  2086. */
  2087. static inline
  2088. void hal_get_hw_hptp(hal_soc_handle_t hal_soc_hdl,
  2089. hal_ring_handle_t hal_ring_hdl,
  2090. uint32_t *headp, uint32_t *tailp,
  2091. uint8_t ring_type)
  2092. {
  2093. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2094. hal_soc->ops->hal_get_hw_hptp(hal_soc, hal_ring_hdl,
  2095. headp, tailp, ring_type);
  2096. }
  2097. /**
  2098. * hal_reo_setup - Initialize HW REO block
  2099. *
  2100. * @hal_soc: Opaque HAL SOC handle
  2101. * @reo_params: parameters needed by HAL for REO config
  2102. */
  2103. static inline void hal_reo_setup(hal_soc_handle_t hal_soc_hdl,
  2104. void *reoparams)
  2105. {
  2106. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2107. hal_soc->ops->hal_reo_setup(hal_soc, reoparams);
  2108. }
  2109. static inline
  2110. void hal_compute_reo_remap_ix2_ix3(hal_soc_handle_t hal_soc_hdl,
  2111. uint32_t *ring, uint32_t num_rings,
  2112. uint32_t *remap1, uint32_t *remap2)
  2113. {
  2114. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2115. return hal_soc->ops->hal_compute_reo_remap_ix2_ix3(ring,
  2116. num_rings, remap1, remap2);
  2117. }
  2118. /**
  2119. * hal_setup_link_idle_list - Setup scattered idle list using the
  2120. * buffer list provided
  2121. *
  2122. * @hal_soc: Opaque HAL SOC handle
  2123. * @scatter_bufs_base_paddr: Array of physical base addresses
  2124. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  2125. * @num_scatter_bufs: Number of scatter buffers in the above lists
  2126. * @scatter_buf_size: Size of each scatter buffer
  2127. * @last_buf_end_offset: Offset to the last entry
  2128. * @num_entries: Total entries of all scatter bufs
  2129. *
  2130. */
  2131. static inline
  2132. void hal_setup_link_idle_list(hal_soc_handle_t hal_soc_hdl,
  2133. qdf_dma_addr_t scatter_bufs_base_paddr[],
  2134. void *scatter_bufs_base_vaddr[],
  2135. uint32_t num_scatter_bufs,
  2136. uint32_t scatter_buf_size,
  2137. uint32_t last_buf_end_offset,
  2138. uint32_t num_entries)
  2139. {
  2140. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2141. hal_soc->ops->hal_setup_link_idle_list(hal_soc, scatter_bufs_base_paddr,
  2142. scatter_bufs_base_vaddr, num_scatter_bufs,
  2143. scatter_buf_size, last_buf_end_offset,
  2144. num_entries);
  2145. }
  2146. /**
  2147. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  2148. *
  2149. * @hal_soc: Opaque HAL SOC handle
  2150. * @hal_ring_hdl: Source ring pointer
  2151. * @ring_desc: Opaque ring descriptor handle
  2152. */
  2153. static inline void hal_srng_dump_ring_desc(hal_soc_handle_t hal_soc_hdl,
  2154. hal_ring_handle_t hal_ring_hdl,
  2155. hal_ring_desc_t ring_desc)
  2156. {
  2157. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2158. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  2159. ring_desc, (srng->entry_size << 2));
  2160. }
  2161. /**
  2162. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  2163. *
  2164. * @hal_soc: Opaque HAL SOC handle
  2165. * @hal_ring_hdl: Source ring pointer
  2166. */
  2167. static inline void hal_srng_dump_ring(hal_soc_handle_t hal_soc_hdl,
  2168. hal_ring_handle_t hal_ring_hdl)
  2169. {
  2170. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2171. uint32_t *desc;
  2172. uint32_t tp, i;
  2173. tp = srng->u.dst_ring.tp;
  2174. for (i = 0; i < 128; i++) {
  2175. if (!tp)
  2176. tp = srng->ring_size;
  2177. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  2178. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  2179. QDF_TRACE_LEVEL_DEBUG,
  2180. desc, (srng->entry_size << 2));
  2181. tp -= srng->entry_size;
  2182. }
  2183. }
  2184. /*
  2185. * hal_rxdma_desc_to_hal_ring_desc - API to convert rxdma ring desc
  2186. * to opaque dp_ring desc type
  2187. * @ring_desc - rxdma ring desc
  2188. *
  2189. * Return: hal_rxdma_desc_t type
  2190. */
  2191. static inline
  2192. hal_ring_desc_t hal_rxdma_desc_to_hal_ring_desc(hal_rxdma_desc_t ring_desc)
  2193. {
  2194. return (hal_ring_desc_t)ring_desc;
  2195. }
  2196. /**
  2197. * hal_srng_set_event() - Set hal_srng event
  2198. * @hal_ring_hdl: Source ring pointer
  2199. * @event: SRNG ring event
  2200. *
  2201. * Return: None
  2202. */
  2203. static inline void hal_srng_set_event(hal_ring_handle_t hal_ring_hdl, int event)
  2204. {
  2205. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2206. qdf_atomic_set_bit(event, &srng->srng_event);
  2207. }
  2208. /**
  2209. * hal_srng_clear_event() - Clear hal_srng event
  2210. * @hal_ring_hdl: Source ring pointer
  2211. * @event: SRNG ring event
  2212. *
  2213. * Return: None
  2214. */
  2215. static inline
  2216. void hal_srng_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  2217. {
  2218. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2219. qdf_atomic_clear_bit(event, &srng->srng_event);
  2220. }
  2221. /**
  2222. * hal_srng_get_clear_event() - Clear srng event and return old value
  2223. * @hal_ring_hdl: Source ring pointer
  2224. * @event: SRNG ring event
  2225. *
  2226. * Return: Return old event value
  2227. */
  2228. static inline
  2229. int hal_srng_get_clear_event(hal_ring_handle_t hal_ring_hdl, int event)
  2230. {
  2231. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2232. return qdf_atomic_test_and_clear_bit(event, &srng->srng_event);
  2233. }
  2234. /**
  2235. * hal_srng_set_flush_last_ts() - Record last flush time stamp
  2236. * @hal_ring_hdl: Source ring pointer
  2237. *
  2238. * Return: None
  2239. */
  2240. static inline void hal_srng_set_flush_last_ts(hal_ring_handle_t hal_ring_hdl)
  2241. {
  2242. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2243. srng->last_flush_ts = qdf_get_log_timestamp();
  2244. }
  2245. /**
  2246. * hal_srng_inc_flush_cnt() - Increment flush counter
  2247. * @hal_ring_hdl: Source ring pointer
  2248. *
  2249. * Return: None
  2250. */
  2251. static inline void hal_srng_inc_flush_cnt(hal_ring_handle_t hal_ring_hdl)
  2252. {
  2253. struct hal_srng *srng = (struct hal_srng *)hal_ring_hdl;
  2254. srng->flush_count++;
  2255. }
  2256. /**
  2257. * hal_rx_sw_mon_desc_info_get () - Get SW monitor desc info
  2258. *
  2259. * @hal: Core HAL soc handle
  2260. * @ring_desc: Mon dest ring descriptor
  2261. * @desc_info: Desc info to be populated
  2262. *
  2263. * Return void
  2264. */
  2265. static inline void
  2266. hal_rx_sw_mon_desc_info_get(struct hal_soc *hal,
  2267. hal_ring_desc_t ring_desc,
  2268. hal_rx_mon_desc_info_t desc_info)
  2269. {
  2270. return hal->ops->hal_rx_sw_mon_desc_info_get(ring_desc, desc_info);
  2271. }
  2272. /**
  2273. * hal_reo_set_err_dst_remap() - Set REO error destination ring remap
  2274. * register value.
  2275. *
  2276. * @hal_soc_hdl: Opaque HAL soc handle
  2277. *
  2278. * Return: None
  2279. */
  2280. static inline void hal_reo_set_err_dst_remap(hal_soc_handle_t hal_soc_hdl)
  2281. {
  2282. struct hal_soc *hal_soc = (struct hal_soc *)hal_soc_hdl;
  2283. if (hal_soc->ops->hal_reo_set_err_dst_remap)
  2284. hal_soc->ops->hal_reo_set_err_dst_remap(hal_soc);
  2285. }
  2286. #ifdef GENERIC_SHADOW_REGISTER_ACCESS_ENABLE
  2287. /**
  2288. * hal_set_one_target_reg_config() - Populate the target reg
  2289. * offset in hal_soc for one non srng related register at the
  2290. * given list index
  2291. * @hal_soc: hal handle
  2292. * @target_reg_offset: target register offset
  2293. * @list_index: index in hal list for shadow regs
  2294. *
  2295. * Return: none
  2296. */
  2297. void hal_set_one_target_reg_config(struct hal_soc *hal,
  2298. uint32_t target_reg_offset,
  2299. int list_index);
  2300. /**
  2301. * hal_set_shadow_regs() - Populate register offset for
  2302. * registers that need to be populated in list_shadow_reg_config
  2303. * in order to be sent to FW. These reg offsets will be mapped
  2304. * to shadow registers.
  2305. * @hal_soc: hal handle
  2306. *
  2307. * Return: QDF_STATUS_OK on success
  2308. */
  2309. QDF_STATUS hal_set_shadow_regs(void *hal_soc);
  2310. /**
  2311. * hal_construct_shadow_regs() - initialize the shadow registers
  2312. * for non-srng related register configs
  2313. * @hal_soc: hal handle
  2314. *
  2315. * Return: QDF_STATUS_OK on success
  2316. */
  2317. QDF_STATUS hal_construct_shadow_regs(void *hal_soc);
  2318. #else /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  2319. static inline void hal_set_one_target_reg_config(
  2320. struct hal_soc *hal,
  2321. uint32_t target_reg_offset,
  2322. int list_index)
  2323. {
  2324. }
  2325. static inline QDF_STATUS hal_set_shadow_regs(void *hal_soc)
  2326. {
  2327. return QDF_STATUS_SUCCESS;
  2328. }
  2329. static inline QDF_STATUS hal_construct_shadow_regs(void *hal_soc)
  2330. {
  2331. return QDF_STATUS_SUCCESS;
  2332. }
  2333. #endif /* GENERIC_SHADOW_REGISTER_ACCESS_ENABLE */
  2334. #ifdef FEATURE_HAL_DELAYED_REG_WRITE
  2335. /**
  2336. * hal_flush_reg_write_work() - flush all writes from register write queue
  2337. * @arg: hal_soc pointer
  2338. *
  2339. * Return: None
  2340. */
  2341. void hal_flush_reg_write_work(hal_soc_handle_t hal_handle);
  2342. #else
  2343. static inline void hal_flush_reg_write_work(hal_soc_handle_t hal_handle) { }
  2344. #endif
  2345. #endif /* _HAL_APIH_ */