hal_api.h 96 KB

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