hal_api.h 103 KB

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