hal_api.h 72 KB

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