hal_api.h 82 KB

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