hal_api.h 72 KB

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