hal_api.h 79 KB

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