gsi.h 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. *
  5. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  6. */
  7. #ifndef GSI_H
  8. #define GSI_H
  9. #include <linux/device.h>
  10. #include <linux/types.h>
  11. #include <linux/completion.h>
  12. #include <linux/mutex.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/msm_gsi.h>
  15. #include <linux/errno.h>
  16. #include <linux/ipc_logging.h>
  17. #include <linux/iommu.h>
  18. #include <linux/msi.h>
  19. /*
  20. * The following for adding code (ie. for EMULATION) not found on x86.
  21. */
  22. #if defined(CONFIG_IPA_EMULATION)
  23. # include "gsi_emulation_stubs.h"
  24. #endif
  25. #define GSI_ASSERT() \
  26. BUG()
  27. #define GSI_CHAN_MAX 36
  28. #define GSI_EVT_RING_MAX 31
  29. #define GSI_NO_EVT_ERINDEX 255
  30. #define GSI_ISR_CACHE_MAX 20
  31. #define MAX_CHANNELS_SHARING_EVENT_RING 2
  32. #define MINIDUMP_MASK 0x10000
  33. #define GSI_INST_RAM_FW_VER_OFFSET (0)
  34. #define GSI_INST_RAM_FW_VER_GSI_3_0_OFFSET (64)
  35. #define GSI_INST_RAM_FW_VER_GSI_5_5_OFFSET (66)
  36. #define GSI_INST_RAM_FW_VER_HW_MASK (0xFC00)
  37. #define GSI_INST_RAM_FW_VER_HW_SHIFT (10)
  38. #define GSI_INST_RAM_FW_VER_FLAVOR_MASK (0x380)
  39. #define GSI_INST_RAM_FW_VER_FLAVOR_SHIFT (7)
  40. #define GSI_INST_RAM_FW_VER_FW_MASK (0x7f)
  41. #define GSI_INST_RAM_FW_VER_FW_SHIFT (0)
  42. #define GSI_IPC_LOGGING(buf, fmt, args...) \
  43. do { \
  44. if (buf) \
  45. ipc_log_string((buf), fmt, __func__, __LINE__, \
  46. ## args); \
  47. } while (0)
  48. #define GSIDBG(fmt, args...) \
  49. do { \
  50. dev_dbg(gsi_ctx->dev, "%s:%d " fmt, __func__, __LINE__, \
  51. ## args);\
  52. if (gsi_ctx) { \
  53. GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf, \
  54. "%s:%d " fmt, ## args); \
  55. GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf_low, \
  56. "%s:%d " fmt, ## args); \
  57. } \
  58. } while (0)
  59. #define GSIDBG_LOW(fmt, args...) \
  60. do { \
  61. dev_dbg(gsi_ctx->dev, "%s:%d " fmt, __func__, __LINE__, \
  62. ## args);\
  63. if (gsi_ctx) { \
  64. GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf_low, \
  65. "%s:%d " fmt, ## args); \
  66. } \
  67. } while (0)
  68. #define GSIERR(fmt, args...) \
  69. do { \
  70. dev_err(gsi_ctx->dev, "%s:%d " fmt, __func__, __LINE__, \
  71. ## args);\
  72. if (gsi_ctx) { \
  73. GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf, \
  74. "%s:%d " fmt, ## args); \
  75. GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf_low, \
  76. "%s:%d " fmt, ## args); \
  77. } \
  78. } while (0)
  79. #define GSIERR_RL(fmt, args...) \
  80. do { \
  81. dev_err_ratelimited(gsi_ctx->dev, "%s:%d " fmt, __func__, __LINE__, \
  82. ## args);\
  83. if (gsi_ctx) { \
  84. GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf, \
  85. "%s:%d " fmt, ## args); \
  86. GSI_IPC_LOGGING(gsi_ctx->ipc_logbuf_low, \
  87. "%s:%d " fmt, ## args); \
  88. } \
  89. } while (0)
  90. #define GSI_IPC_LOG_PAGES 50
  91. #define GSI_MAX_NUM_MSI 2
  92. enum gsi_ver {
  93. GSI_VER_ERR = 0,
  94. GSI_VER_1_0 = 1,
  95. GSI_VER_1_2 = 2,
  96. GSI_VER_1_3 = 3,
  97. GSI_VER_2_0 = 4,
  98. GSI_VER_2_2 = 5,
  99. GSI_VER_2_5 = 6,
  100. GSI_VER_2_7 = 7,
  101. GSI_VER_2_9 = 8,
  102. GSI_VER_2_11 = 9,
  103. GSI_VER_3_0 = 10,
  104. GSI_VER_5_5 = 11,
  105. GSI_VER_6_0 = 12,
  106. GSI_VER_MAX,
  107. };
  108. enum gsi_status {
  109. GSI_STATUS_SUCCESS = 0,
  110. GSI_STATUS_ERROR = 1,
  111. GSI_STATUS_RING_INSUFFICIENT_SPACE = 2,
  112. GSI_STATUS_RING_EMPTY = 3,
  113. GSI_STATUS_RES_ALLOC_FAILURE = 4,
  114. GSI_STATUS_BAD_STATE = 5,
  115. GSI_STATUS_INVALID_PARAMS = 6,
  116. GSI_STATUS_UNSUPPORTED_OP = 7,
  117. GSI_STATUS_NODEV = 8,
  118. GSI_STATUS_POLL_EMPTY = 9,
  119. GSI_STATUS_EVT_RING_INCOMPATIBLE = 10,
  120. GSI_STATUS_TIMED_OUT = 11,
  121. GSI_STATUS_AGAIN = 12,
  122. GSI_STATUS_PENDING_IRQ = 13,
  123. };
  124. enum gsi_intr_type {
  125. GSI_INTR_MSI = 0x0,
  126. GSI_INTR_IRQ = 0x1
  127. };
  128. enum gsi_evt_err {
  129. GSI_EVT_OUT_OF_BUFFERS_ERR = 0x0,
  130. GSI_EVT_OUT_OF_RESOURCES_ERR = 0x1,
  131. GSI_EVT_UNSUPPORTED_INTER_EE_OP_ERR = 0x2,
  132. GSI_EVT_EVT_RING_EMPTY_ERR = 0x3,
  133. };
  134. /**
  135. * gsi_evt_err_notify - event ring error callback info
  136. *
  137. * @user_data: cookie supplied in gsi_alloc_evt_ring
  138. * @evt_id: type of error
  139. * @err_desc: more info about the error
  140. *
  141. */
  142. struct gsi_evt_err_notify {
  143. void *user_data;
  144. enum gsi_evt_err evt_id;
  145. uint16_t err_desc;
  146. };
  147. enum gsi_evt_chtype {
  148. GSI_EVT_CHTYPE_MHI_EV = 0x0,
  149. GSI_EVT_CHTYPE_XHCI_EV = 0x1,
  150. GSI_EVT_CHTYPE_GPI_EV = 0x2,
  151. GSI_EVT_CHTYPE_XDCI_EV = 0x3,
  152. GSI_EVT_CHTYPE_WDI2_EV = 0x4,
  153. GSI_EVT_CHTYPE_GCI_EV = 0x5,
  154. GSI_EVT_CHTYPE_WDI3_EV = 0x6,
  155. GSI_EVT_CHTYPE_MHIP_EV = 0x7,
  156. GSI_EVT_CHTYPE_AQC_EV = 0x8,
  157. GSI_EVT_CHTYPE_11AD_EV = 0x9,
  158. GSI_EVT_CHTYPE_RTK_EV = 0xC,
  159. GSI_EVT_CHTYPE_NTN_EV = 0xD,
  160. GSI_EVT_CHTYPE_WDI3_V2_EV = 0XF,
  161. };
  162. enum gsi_evt_ring_elem_size {
  163. GSI_EVT_RING_RE_SIZE_4B = 4,
  164. GSI_EVT_RING_RE_SIZE_8B = 8,
  165. GSI_EVT_RING_RE_SIZE_16B = 16,
  166. GSI_EVT_RING_RE_SIZE_32B = 32,
  167. };
  168. /**
  169. * gsi_evt_ring_props - Event ring related properties
  170. *
  171. * @intf: interface type (of the associated channel)
  172. * @intr: interrupt type
  173. * @re_size: size of event ring element
  174. * @ring_len: length of ring in bytes (must be integral multiple of
  175. * re_size)
  176. * @ring_base_addr: physical base address of ring. Address must be aligned to
  177. * ring_len rounded to power of two
  178. * @ring_base_vaddr: virtual base address of ring (set to NULL when not
  179. * applicable)
  180. * @int_modt: cycles base interrupt moderation (32KHz clock)
  181. * @int_modc: interrupt moderation packet counter
  182. * @intvec: write data for MSI write
  183. * @msi_irq: MSI irq number
  184. * @msi_addr: MSI address, APSS_GICA_SETSPI_NSR reg address
  185. * @msi_clear_addr: MSI address, APSS_GICA_CLRSPI_NSR reg address
  186. * @rp_update_addr: physical address to which event read pointer should be
  187. * written on every event generation. must be set to 0 when
  188. * no update is desdired
  189. * @rp_update_vaddr: virtual address of event ring read pointer (set to NULL
  190. * when not applicable)
  191. * @exclusive: if true, only one GSI channel can be associated with this
  192. * event ring. if false, the event ring can be shared among
  193. * multiple GSI channels but in that case no polling
  194. * (GSI_CHAN_MODE_POLL) is supported on any of those channels
  195. * @err_cb: error notification callback
  196. * @user_data: cookie used for error notifications
  197. * @evchid_valid: is evchid valid?
  198. * @evchid: the event ID that is being specifically requested (this is
  199. * relevant for MHI where doorbell routing requires ERs to be
  200. * physically contiguous)
  201. * @gsi_read_event_ring_rp: function reads the value of the event ring RP.
  202. */
  203. struct gsi_evt_ring_props {
  204. enum gsi_evt_chtype intf;
  205. enum gsi_intr_type intr;
  206. enum gsi_evt_ring_elem_size re_size;
  207. uint32_t ring_len;
  208. uint64_t ring_base_addr;
  209. void *ring_base_vaddr;
  210. uint16_t int_modt;
  211. uint8_t int_modc;
  212. uint32_t intvec;
  213. uint32_t msi_irq;
  214. uint64_t msi_addr;
  215. uint64_t msi_addr_iore_mapped;
  216. uint64_t msi_clear_addr;
  217. uint64_t rp_update_addr;
  218. void *rp_update_vaddr;
  219. bool exclusive;
  220. void (*err_cb)(struct gsi_evt_err_notify *notify);
  221. void *user_data;
  222. bool evchid_valid;
  223. uint8_t evchid;
  224. uint64_t (*gsi_read_event_ring_rp)(struct gsi_evt_ring_props *props,
  225. uint8_t id, int ee);
  226. };
  227. enum gsi_chan_mode {
  228. GSI_CHAN_MODE_CALLBACK = 0x0,
  229. GSI_CHAN_MODE_POLL = 0x1,
  230. };
  231. enum gsi_chan_prot {
  232. GSI_CHAN_PROT_MHI = 0x0,
  233. GSI_CHAN_PROT_XHCI = 0x1,
  234. GSI_CHAN_PROT_GPI = 0x2,
  235. GSI_CHAN_PROT_XDCI = 0x3,
  236. GSI_CHAN_PROT_WDI2 = 0x4,
  237. GSI_CHAN_PROT_GCI = 0x5,
  238. GSI_CHAN_PROT_WDI3 = 0x6,
  239. GSI_CHAN_PROT_MHIP = 0x7,
  240. GSI_CHAN_PROT_AQC = 0x8,
  241. GSI_CHAN_PROT_11AD = 0x9,
  242. GSI_CHAN_PROT_MHIC = 0xA,
  243. GSI_CHAN_PROT_QDSS = 0xB,
  244. GSI_CHAN_PROT_RTK = 0xC,
  245. GSI_CHAN_PROT_NTN = 0xD,
  246. GSI_CHAN_PROT_WDI3_V2 = 0XF,
  247. };
  248. enum gsi_max_prefetch {
  249. GSI_ONE_PREFETCH_SEG = 0x0,
  250. GSI_TWO_PREFETCH_SEG = 0x1
  251. };
  252. enum gsi_per_evt {
  253. GSI_PER_EVT_GLOB_ERROR,
  254. GSI_PER_EVT_GLOB_GP1,
  255. GSI_PER_EVT_GLOB_GP2,
  256. GSI_PER_EVT_GLOB_GP3,
  257. GSI_PER_EVT_GENERAL_BREAK_POINT,
  258. GSI_PER_EVT_GENERAL_BUS_ERROR,
  259. GSI_PER_EVT_GENERAL_CMD_FIFO_OVERFLOW,
  260. GSI_PER_EVT_GENERAL_MCS_STACK_OVERFLOW,
  261. };
  262. /**
  263. * gsi_per_notify - Peripheral callback info
  264. *
  265. * @user_data: cookie supplied in gsi_register_device
  266. * @evt_id: type of notification
  267. * @err_desc: error related information
  268. *
  269. */
  270. struct gsi_per_notify {
  271. void *user_data;
  272. enum gsi_per_evt evt_id;
  273. union {
  274. uint16_t err_desc;
  275. } data;
  276. };
  277. /**
  278. * gsi_per_props - Peripheral related properties
  279. *
  280. * @gsi: GSI core version
  281. * @ee: EE where this driver and peripheral driver runs
  282. * @intr: control interrupt type
  283. * @intvec: write data for MSI write
  284. * @msi_addr: MSI address
  285. * @irq: IRQ number
  286. * @phys_addr: physical address of GSI block
  287. * @size: register size of GSI block
  288. * @emulator_intcntrlr_addr: the location of emulator's interrupt control block
  289. * @emulator_intcntrlr_size: the sise of emulator_intcntrlr_addr
  290. * @emulator_intcntrlr_client_isr: client's isr. Called by the emulator's isr
  291. * @mhi_er_id_limits_valid: valid flag for mhi_er_id_limits
  292. * @mhi_er_id_limits: MHI event ring start and end ids
  293. * @notify_cb: general notification callback
  294. * @req_clk_cb: callback to request peripheral clock
  295. * granted should be set to true if request is completed
  296. * synchronously, false otherwise (peripheral needs
  297. * to call gsi_complete_clk_grant later when request is
  298. * completed)
  299. * if this callback is not provided, then GSI will assume
  300. * peripheral is clocked at all times
  301. * @rel_clk_cb: callback to release peripheral clock
  302. * @user_data: cookie used for notifications
  303. * @clk_status_cb: callback to update the current msm bus clock vote
  304. * @enable_clk_bug_on: enable IPA clock for dump saving before assert
  305. * @skip_ieob_mask_wa: flag for skipping ieob_mask_wa
  306. * All the callbacks are in interrupt context
  307. * @tx_poll: propagate to relevant gsi channels that tx polling feature is on
  308. *
  309. */
  310. struct gsi_per_props {
  311. enum gsi_ver ver;
  312. unsigned int ee;
  313. enum gsi_intr_type intr;
  314. uint32_t intvec;
  315. uint64_t msi_addr;
  316. unsigned int irq;
  317. phys_addr_t phys_addr;
  318. unsigned long size;
  319. phys_addr_t emulator_intcntrlr_addr;
  320. unsigned long emulator_intcntrlr_size;
  321. irq_handler_t emulator_intcntrlr_client_isr;
  322. bool mhi_er_id_limits_valid;
  323. uint32_t mhi_er_id_limits[2];
  324. void (*notify_cb)(struct gsi_per_notify *notify);
  325. void (*req_clk_cb)(void *user_data, bool *granted);
  326. int (*rel_clk_cb)(void *user_data);
  327. void *user_data;
  328. int (*clk_status_cb)(void);
  329. void (*enable_clk_bug_on)(void);
  330. void (*vote_clk_cb)(void);
  331. void (*unvote_clk_cb)(void);
  332. bool skip_ieob_mask_wa;
  333. bool tx_poll;
  334. };
  335. enum gsi_chan_evt {
  336. GSI_CHAN_EVT_INVALID = 0x0,
  337. GSI_CHAN_EVT_SUCCESS = 0x1,
  338. GSI_CHAN_EVT_EOT = 0x2,
  339. GSI_CHAN_EVT_OVERFLOW = 0x3,
  340. GSI_CHAN_EVT_EOB = 0x4,
  341. GSI_CHAN_EVT_OOB = 0x5,
  342. GSI_CHAN_EVT_DB_MODE = 0x6,
  343. GSI_CHAN_EVT_UNDEFINED = 0x10,
  344. GSI_CHAN_EVT_RE_ERROR = 0x11,
  345. };
  346. /**
  347. * gsi_chan_xfer_veid - Virtual Channel ID
  348. *
  349. * @GSI_VEID_0: transfer completed for VEID 0
  350. * @GSI_VEID_1: transfer completed for VEID 1
  351. * @GSI_VEID_2: transfer completed for VEID 2
  352. * @GSI_VEID_3: transfer completed for VEID 3
  353. * @GSI_VEID_4: transfer completed for VEID 4
  354. * @GSI_VEID_5: transfer completed for VEID 5
  355. * @GSI_VEID_6: transfer completed for VEID 6
  356. * @GSI_VEID_7: transfer completed for VEID 7
  357. * @GSI_VEID_8: transfer completed for VEID 8
  358. * @GSI_VEID_9: transfer completed for VEID 9
  359. * @GSI_VEID_10: transfer completed for VEID 10
  360. * @GSI_VEID_11: transfer completed for VEID 11
  361. * @GSI_VEID_12: transfer completed for VEID 12
  362. * @GSI_VEID_13: transfer completed for VEID 13
  363. * @GSI_VEID_14: transfer completed for VEID 14
  364. * @GSI_VEID_15: transfer completed for VEID 15
  365. * @GSI_VEID_DEFAULT: used when veid is invalid
  366. */
  367. enum gsi_chan_xfer_veid {
  368. GSI_VEID_0 = 0,
  369. GSI_VEID_1 = 1,
  370. GSI_VEID_2 = 2,
  371. GSI_VEID_3 = 3,
  372. GSI_VEID_4 = 4,
  373. GSI_VEID_5 = 5,
  374. GSI_VEID_6 = 6,
  375. GSI_VEID_7 = 7,
  376. GSI_VEID_8 = 8,
  377. GSI_VEID_9 = 9,
  378. GSI_VEID_10 = 10,
  379. GSI_VEID_11 = 11,
  380. GSI_VEID_12 = 12,
  381. GSI_VEID_13 = 13,
  382. GSI_VEID_14 = 14,
  383. GSI_VEID_15 = 15,
  384. GSI_VEID_DEFAULT,
  385. GSI_VEID_MAX
  386. };
  387. /**
  388. * gsi_chan_xfer_notify - Channel callback info
  389. *
  390. * @chan_user_data: cookie supplied in gsi_alloc_channel
  391. * @xfer_user_data: cookie of the gsi_xfer_elem that caused the
  392. * event to be generated
  393. * @evt_id: type of event triggered by the associated TRE
  394. * (corresponding to xfer_user_data)
  395. * @bytes_xfered: number of bytes transferred by the associated TRE
  396. * (corresponding to xfer_user_data)
  397. * @veid: virtual endpoint id. Valid for GCI completions only
  398. *
  399. */
  400. struct gsi_chan_xfer_notify {
  401. void *chan_user_data;
  402. void *xfer_user_data;
  403. enum gsi_chan_evt evt_id;
  404. uint16_t bytes_xfered;
  405. uint8_t veid;
  406. };
  407. enum gsi_chan_err {
  408. GSI_CHAN_INVALID_TRE_ERR = 0x0,
  409. GSI_CHAN_NON_ALLOCATED_EVT_ACCESS_ERR = 0x1,
  410. GSI_CHAN_OUT_OF_BUFFERS_ERR = 0x2,
  411. GSI_CHAN_OUT_OF_RESOURCES_ERR = 0x3,
  412. GSI_CHAN_UNSUPPORTED_INTER_EE_OP_ERR = 0x4,
  413. GSI_CHAN_HWO_1_ERR = 0x5
  414. };
  415. /**
  416. * gsi_chan_err_notify - Channel general callback info
  417. *
  418. * @chan_user_data: cookie supplied in gsi_alloc_channel
  419. * @evt_id: type of error
  420. * @err_desc: more info about the error
  421. *
  422. */
  423. struct gsi_chan_err_notify {
  424. void *chan_user_data;
  425. enum gsi_chan_err evt_id;
  426. uint16_t err_desc;
  427. };
  428. enum gsi_chan_ring_elem_size {
  429. GSI_CHAN_RE_SIZE_4B = 4,
  430. GSI_CHAN_RE_SIZE_8B = 8,
  431. GSI_CHAN_RE_SIZE_16B = 16,
  432. GSI_CHAN_RE_SIZE_32B = 32,
  433. GSI_CHAN_RE_SIZE_64B = 64,
  434. };
  435. enum gsi_chan_use_db_eng {
  436. GSI_CHAN_DIRECT_MODE = 0x0,
  437. GSI_CHAN_DB_MODE = 0x1,
  438. };
  439. /**
  440. * gsi_chan_props - Channel related properties
  441. *
  442. * @prot: interface type
  443. * @dir: channel direction
  444. * @ch_id: virtual channel ID
  445. * @evt_ring_hdl: handle of associated event ring. set to ~0 if no
  446. * event ring associated
  447. * @re_size: size of channel ring element
  448. * @ring_len: length of ring in bytes (must be integral multiple of
  449. * re_size)
  450. * @max_re_expected: maximal number of ring elements expected to be queued.
  451. * used for data path statistics gathering. if 0 provided
  452. * ring_len / re_size will be used.
  453. * @ring_base_addr: physical base address of ring. Address must be aligned to
  454. * ring_len rounded to power of two
  455. * @ring_base_vaddr: virtual base address of ring (set to NULL when not
  456. * applicable)
  457. * @use_db_eng: 0 => direct mode (doorbells are written directly to RE
  458. * engine)
  459. * 1 => DB mode (doorbells are written to DB engine)
  460. * @max_prefetch: limit number of pre-fetch segments for channel
  461. * @low_weight: low channel weight (priority of channel for RE engine
  462. * round robin algorithm); must be >= 1
  463. * @empty_lvl_threshold:
  464. * The thershold number of free entries available in the
  465. * receiving fifos of GSI-peripheral. If Smart PF mode
  466. * is used, REE will fetch/send new TRE to peripheral only
  467. * if peripheral's empty_level_count is higher than
  468. * EMPTY_LVL_THRSHOLD defined for this channel
  469. * @tx_poll: channel process completions in NAPI context
  470. * @xfer_cb: transfer notification callback, this callback happens
  471. * on event boundaries
  472. *
  473. * e.g. 1
  474. *
  475. * out TD with 3 REs
  476. *
  477. * RE1: EOT=0, EOB=0, CHAIN=1;
  478. * RE2: EOT=0, EOB=0, CHAIN=1;
  479. * RE3: EOT=1, EOB=0, CHAIN=0;
  480. *
  481. * the callback will be triggered for RE3 using the
  482. * xfer_user_data of that RE
  483. *
  484. * e.g. 2
  485. *
  486. * in REs
  487. *
  488. * RE1: EOT=1, EOB=0, CHAIN=0;
  489. * RE2: EOT=1, EOB=0, CHAIN=0;
  490. * RE3: EOT=1, EOB=0, CHAIN=0;
  491. *
  492. * received packet consumes all of RE1, RE2 and part of RE3
  493. * for EOT condition. there will be three callbacks in below
  494. * order
  495. *
  496. * callback for RE1 using GSI_CHAN_EVT_OVERFLOW
  497. * callback for RE2 using GSI_CHAN_EVT_OVERFLOW
  498. * callback for RE3 using GSI_CHAN_EVT_EOT
  499. *
  500. * @err_cb: error notification callback
  501. * @cleanup_cb; cleanup rx-pkt/skb callback
  502. * @chan_user_data: cookie used for notifications
  503. *
  504. * All the callbacks are in interrupt context
  505. *
  506. */
  507. struct gsi_chan_props {
  508. enum gsi_chan_prot prot;
  509. enum gsi_chan_dir dir;
  510. uint8_t ch_id;
  511. unsigned long evt_ring_hdl;
  512. enum gsi_chan_ring_elem_size re_size;
  513. uint32_t ring_len;
  514. uint16_t max_re_expected;
  515. uint64_t ring_base_addr;
  516. uint8_t db_in_bytes;
  517. uint8_t low_latency_en;
  518. void *ring_base_vaddr;
  519. enum gsi_chan_use_db_eng use_db_eng;
  520. enum gsi_max_prefetch max_prefetch;
  521. uint8_t low_weight;
  522. enum gsi_prefetch_mode prefetch_mode;
  523. uint8_t empty_lvl_threshold;
  524. bool tx_poll;
  525. void (*xfer_cb)(struct gsi_chan_xfer_notify *notify);
  526. void (*err_cb)(struct gsi_chan_err_notify *notify);
  527. void (*cleanup_cb)(void *chan_user_data, void *xfer_user_data);
  528. void *chan_user_data;
  529. };
  530. enum gsi_xfer_flag {
  531. GSI_XFER_FLAG_CHAIN = 0x1,
  532. GSI_XFER_FLAG_EOB = 0x100,
  533. GSI_XFER_FLAG_EOT = 0x200,
  534. GSI_XFER_FLAG_BEI = 0x400
  535. };
  536. enum gsi_xfer_elem_type {
  537. GSI_XFER_ELEM_DATA,
  538. GSI_XFER_ELEM_IMME_CMD,
  539. GSI_XFER_ELEM_NOP,
  540. };
  541. /**
  542. * gsi_gpi_channel_scratch - GPI protocol SW config area of
  543. * channel scratch
  544. *
  545. * @dl_nlo_channel: Whether this is DL NLO Channel or not? Relevant for
  546. * GSI 2.5 and above where DL NLO introduced.
  547. * @max_outstanding_tre: Used for the prefetch management sequence by the
  548. * sequencer. Defines the maximum number of allowed
  549. * outstanding TREs in IPA/GSI (in Bytes). RE engine
  550. * prefetch will be limited by this configuration. It
  551. * is suggested to configure this value to IPA_IF
  552. * channel TLV queue size times element size. To disable
  553. * the feature in doorbell mode (DB Mode=1). Maximum
  554. * outstanding TREs should be set to 64KB
  555. * (or any value larger or equal to ring length . RLEN)
  556. * The field is irrelevant starting GSI 2.5 where smart
  557. * prefetch implemented by the H/W.
  558. * @outstanding_threshold: Used for the prefetch management sequence by the
  559. * sequencer. Defines the threshold (in Bytes) as to when
  560. * to update the channel doorbell. Should be smaller than
  561. * Maximum outstanding TREs. value. It is suggested to
  562. * configure this value to 2 * element size.
  563. * The field is irrelevant starting GSI 2.5 where smart
  564. * prefetch implemented by the H/W.
  565. */
  566. struct __packed gsi_gpi_channel_scratch {
  567. uint64_t dl_nlo_channel:1; /* Relevant starting GSI 2.5 */
  568. uint64_t resvd1:63;
  569. uint32_t resvd2:16;
  570. uint32_t max_outstanding_tre:16; /* Not relevant starting GSI 2.5 */
  571. uint32_t resvd3:16;
  572. uint32_t outstanding_threshold:16; /* Not relevant starting GSI 2.5 */
  573. };
  574. /**
  575. * gsi_mhi_channel_scratch - MHI protocol SW config area of
  576. * channel scratch
  577. *
  578. * @mhi_host_wp_addr: Valid only when UL/DL Sync En is asserted. Defines
  579. * address in host from which channel write pointer
  580. * should be read in polling mode
  581. * @assert_bit40: 1: bit #41 in address should be asserted upon
  582. * IPA_IF.ProcessDescriptor routine (for MHI over PCIe
  583. * transfers)
  584. * 0: bit #41 in address should be deasserted upon
  585. * IPA_IF.ProcessDescriptor routine (for non-MHI over
  586. * PCIe transfers)
  587. * @polling_configuration: Uplink channels: Defines timer to poll on MHI
  588. * context. Range: 1 to 31 milliseconds.
  589. * Downlink channel: Defines transfer ring buffer
  590. * availability threshold to poll on MHI context in
  591. * multiple of 8. Range: 0 to 31, meaning 0 to 258 ring
  592. * elements. E.g., value of 2 indicates 16 ring elements.
  593. * Valid only when Burst Mode Enabled is set to 1
  594. * @burst_mode_enabled: 0: Burst mode is disabled for this channel
  595. * 1: Burst mode is enabled for this channel
  596. * @polling_mode: 0: the channel is not in polling mode, meaning the
  597. * host should ring DBs.
  598. * 1: the channel is in polling mode, meaning the host
  599. * @oob_mod_threshold: Defines OOB moderation threshold. Units are in 8
  600. * ring elements.
  601. * should not ring DBs until notified of DB mode/OOB mode
  602. * @max_outstanding_tre: Used for the prefetch management sequence by the
  603. * sequencer. Defines the maximum number of allowed
  604. * outstanding TREs in IPA/GSI (in Bytes). RE engine
  605. * prefetch will be limited by this configuration. It
  606. * is suggested to configure this value to IPA_IF
  607. * channel TLV queue size times element size.
  608. * To disable the feature in doorbell mode (DB Mode=1).
  609. * Maximum outstanding TREs should be set to 64KB
  610. * (or any value larger or equal to ring length . RLEN)
  611. * The field is irrelevant starting GSI 2.5 where smart
  612. * prefetch implemented by the H/W.
  613. * @outstanding_threshold: Used for the prefetch management sequence by the
  614. * sequencer. Defines the threshold (in Bytes) as to when
  615. * to update the channel doorbell. Should be smaller than
  616. * Maximum outstanding TREs. value. It is suggested to
  617. * configure this value to min(TLV_FIFO_SIZE/2,8) *
  618. * element size.
  619. * The field is irrelevant starting GSI 2.5 where smart
  620. * prefetch implemented by the H/W.
  621. */
  622. struct __packed gsi_mhi_channel_scratch {
  623. uint64_t mhi_host_wp_addr;
  624. uint32_t rsvd1:1;
  625. uint32_t assert_bit40:1;
  626. uint32_t polling_configuration:5;
  627. uint32_t burst_mode_enabled:1;
  628. uint32_t polling_mode:1;
  629. uint32_t oob_mod_threshold:5;
  630. uint32_t resvd2:2;
  631. uint32_t max_outstanding_tre:16; /* Not relevant starting GSI 2.5 */
  632. uint32_t resvd3:16;
  633. uint32_t outstanding_threshold:16; /* Not relevant starting GSI 2.5 */
  634. };
  635. /**
  636. * gsi_mhi_channel_scratch_v2 - MHI protocol SW config area of
  637. * channel scratch
  638. *
  639. * @mhi_host_wp_addr_lo: Valid only when UL/DL Sync En is asserted. Defines
  640. * address in host from which channel write pointer
  641. * should be read in polling mode
  642. * @mhi_host_wp_addr_hi: Valid only when UL/DL Sync En is asserted. Defines
  643. * address in host from which channel write pointer
  644. * should be read in polling mode
  645. * @assert_bit40: 1: bit #41 in address should be asserted upon
  646. * IPA_IF.ProcessDescriptor routine (for MHI over PCIe
  647. * transfers)
  648. * 0: bit #41 in address should be deasserted upon
  649. * IPA_IF.ProcessDescriptor routine (for non-MHI over
  650. * PCIe transfers)
  651. * @polling_configuration: Uplink channels: Defines timer to poll on MHI
  652. * context. Range: 1 to 31 milliseconds.
  653. * Downlink channel: Defines transfer ring buffer
  654. * availability threshold to poll on MHI context in
  655. * multiple of 8. Range: 0 to 31, meaning 0 to 258 ring
  656. * elements. E.g., value of 2 indicates 16 ring elements.
  657. * Valid only when Burst Mode Enabled is set to 1
  658. * @burst_mode_enabled: 0: Burst mode is disabled for this channel
  659. * 1: Burst mode is enabled for this channel
  660. * @polling_mode: 0: the channel is not in polling mode, meaning the
  661. * host should ring DBs.
  662. * 1: the channel is in polling mode, meaning the host
  663. * @oob_mod_threshold: Defines OOB moderation threshold. Units are in 8
  664. * ring elements.
  665. * should not ring DBs until notified of DB mode/OOB mode
  666. */
  667. struct __packed gsi_mhi_channel_scratch_v2 {
  668. uint32_t mhi_host_wp_addr_lo;
  669. uint32_t mhi_host_wp_addr_hi : 9;
  670. uint32_t polling_configuration : 5;
  671. uint32_t rsvd1 : 18;
  672. uint32_t rsvd2 : 1;
  673. uint32_t assert_bit40 : 1;
  674. uint32_t resvd3 : 5;
  675. uint32_t burst_mode_enabled : 1;
  676. uint32_t polling_mode : 1;
  677. uint32_t oob_mod_threshold : 5;
  678. uint32_t resvd4 : 18; /* Not configured by AP */
  679. uint32_t resvd5; /* Not configured by AP */
  680. };
  681. /**
  682. * gsi_xdci_channel_scratch - xDCI protocol SW config area of
  683. * channel scratch
  684. *
  685. * @const_buffer_size: TRB buffer size in KB (similar to IPA aggregationi
  686. * configuration). Must be aligned to Max USB Packet Size
  687. * @xferrscidx: Transfer Resource Index (XferRscIdx). The hardware-assigned
  688. * transfer resource index for the transfer, which was
  689. * returned in response to the Start Transfer command.
  690. * This field is used for "Update Transfer" command
  691. * @last_trb_addr: Address (LSB - based on alignment restrictions) of
  692. * last TRB in queue. Used to identify rollover case
  693. * @depcmd_low_addr: Used to generate "Update Transfer" command
  694. * @max_outstanding_tre: Used for the prefetch management sequence by the
  695. * sequencer. Defines the maximum number of allowed
  696. * outstanding TREs in IPA/GSI (in Bytes). RE engine
  697. * prefetch will be limited by this configuration. It
  698. * is suggested to configure this value to IPA_IF
  699. * channel TLV queue size times element size.
  700. * To disable the feature in doorbell mode (DB Mode=1)
  701. * Maximum outstanding TREs should be set to 64KB
  702. * (or any value larger or equal to ring length . RLEN)
  703. * The field is irrelevant starting GSI 2.5 where smart
  704. * prefetch implemented by the H/W.
  705. * @depcmd_hi_addr: Used to generate "Update Transfer" command
  706. * @outstanding_threshold: Used for the prefetch management sequence by the
  707. * sequencer. Defines the threshold (in Bytes) as to when
  708. * to update the channel doorbell. Should be smaller than
  709. * Maximum outstanding TREs. value. It is suggested to
  710. * configure this value to 2 * element size. for MBIM the
  711. * suggested configuration is the element size.
  712. * The field is irrelevant starting GSI 2.5 where smart
  713. * prefetch implemented by the H/W.
  714. */
  715. struct __packed gsi_xdci_channel_scratch {
  716. uint32_t last_trb_addr:16;
  717. uint32_t resvd1:4;
  718. uint32_t xferrscidx:7;
  719. uint32_t const_buffer_size:5;
  720. uint32_t depcmd_low_addr;
  721. uint32_t depcmd_hi_addr:8;
  722. uint32_t resvd2:8;
  723. uint32_t max_outstanding_tre:16; /* Not relevant starting GSI 2.5 */
  724. uint32_t resvd3:16;
  725. uint32_t outstanding_threshold:16; /* Not relevant starting GSI 2.5 */
  726. };
  727. /**
  728. * gsi_wdi_channel_scratch - WDI protocol SW config area of
  729. * channel scratch
  730. *
  731. * @wifi_rx_ri_addr_low: Low 32 bits of Transfer ring Read Index address.
  732. * @wifi_rx_ri_addr_high: High 32 bits of Transfer ring Read Index address.
  733. * @update_ri_moderation_threshold: Threshold N for Transfer ring Read Index
  734. * N is the number of packets that IPA will
  735. * process before Wifi transfer ring Ri will
  736. * be updated.
  737. * @update_ri_moderation_counter: This field is incremented with each TRE
  738. * processed in MCS.
  739. * @wdi_rx_tre_proc_in_progress: It is set if IPA IF returned BECAME FULL
  740. * status after MCS submitted an inline immediate
  741. * command to update the metadata. It allows MCS
  742. * to know that it has to retry sending the TRE
  743. * to IPA.
  744. * @wdi_rx_vdev_id: Rx only. Initialized to 0xFF by SW after allocating channel
  745. * and before starting it. Both FW_DESC and VDEV_ID are part
  746. * of a scratch word that is Read/Write for both MCS and SW.
  747. * To avoid race conditions, SW should not update this field
  748. * after starting the channel.
  749. * @wdi_rx_fw_desc: Rx only. Initialized to 0xFF by SW after allocating channel
  750. * and before starting it. After Start, this is a Read only
  751. * field for SW.
  752. * @endp_metadatareg_offset: Rx only, the offset of IPA_ENDP_INIT_HDR_METADATA
  753. * of the corresponding endpoint in 4B words from IPA
  754. * base address. Read only field for MCS.
  755. * Write for SW.
  756. * @qmap_id: Rx only, used for setting metadata register in IPA. Read only field
  757. * for MCS. Write for SW.
  758. * @wdi_rx_pkt_length: If WDI_RX_TRE_PROC_IN_PROGRESS is set, this field is
  759. * valid and contains the packet length of the TRE that
  760. * needs to be submitted to IPA.
  761. * @resv1: reserved bits.
  762. * @pkt_comp_count: It is incremented on each AOS received. When event ring
  763. * Write index is updated, it is decremented by the same
  764. * amount.
  765. * @stop_in_progress_stm: If a Stop request is in progress, this will indicate
  766. * the current stage of processing of the stop within MCS
  767. * @resv2: reserved bits.
  768. * wdi_rx_qmap_id_internal: Initialized to 0 by MCS when the channel is
  769. * allocated. It is updated to the current value of SW
  770. * QMAP ID that is being written by MCS to the IPA
  771. * metadata register.
  772. */
  773. struct __packed gsi_wdi_channel_scratch {
  774. uint32_t wifi_rx_ri_addr_low;
  775. uint32_t wifi_rx_ri_addr_high;
  776. uint32_t update_ri_moderation_threshold:5;
  777. uint32_t update_ri_moderation_counter:6;
  778. uint32_t wdi_rx_tre_proc_in_progress:1;
  779. uint32_t resv1:4;
  780. uint32_t wdi_rx_vdev_id:8;
  781. uint32_t wdi_rx_fw_desc:8;
  782. uint32_t endp_metadatareg_offset:16;
  783. uint32_t qmap_id:16;
  784. uint32_t wdi_rx_pkt_length:16;
  785. uint32_t resv2:2;
  786. uint32_t pkt_comp_count:11;
  787. uint32_t stop_in_progress_stm:3;
  788. uint32_t resv3:16;
  789. uint32_t wdi_rx_qmap_id_internal:16;
  790. };
  791. /**
  792. * gsi_wdi2_channel_scratch_lito - WDI protocol SW config area of
  793. * channel scratch
  794. *
  795. * @wifi_rx_ri_addr_low: Low 32 bits of Transfer ring Read Index address.
  796. * @wifi_rx_ri_addr_high: High 32 bits of Transfer ring Read Index address.
  797. * @update_ri_moderation_threshold: Threshold N for Transfer ring Read Index
  798. * N is the number of packets that IPA will
  799. * process before Wifi transfer ring Ri will
  800. * be updated.
  801. * @qmap_id: Rx only, used for setting metadata register in IPA. Read only field
  802. * for MCS. Write for SW.
  803. * @endp_metadatareg_offset: Rx only, the offset of IPA_ENDP_INIT_HDR_METADATA
  804. * of the corresponding endpoint in 4B words from IPA
  805. * base address. Read only field for MCS.
  806. * Write for SW.
  807. * @wdi_rx_vdev_id: Rx only. Initialized to 0xFF by SW after allocating channel
  808. * and before starting it. Both FW_DESC and VDEV_ID are part
  809. * of a scratch word that is Read/Write for both MCS and SW.
  810. * To avoid race conditions, SW should not update this field
  811. * after starting the channel.
  812. * @wdi_rx_fw_desc: Rx only. Initialized to 0xFF by SW after allocating channel
  813. * and before starting it. After Start, this is a Read only
  814. * field for SW.
  815. * @update_ri_moderation_counter: This field is incremented with each TRE
  816. * processed in MCS.
  817. * @wdi_rx_tre_proc_in_progress: It is set if IPA IF returned BECAME FULL
  818. * status after MCS submitted an inline immediate
  819. * command to update the metadata. It allows MCS
  820. * to know that it has to retry sending the TRE
  821. * to IPA.
  822. * @outstanding_tlvs_counter: It is the count of outstanding TLVs submitted to
  823. * IPA by MCS and waiting for AOS completion from IPA.
  824. * @wdi_rx_pkt_length: If WDI_RX_TRE_PROC_IN_PROGRESS is set, this field is
  825. * valid and contains the packet length of the TRE that
  826. * needs to be submitted to IPA.
  827. * @resv1: reserved bits.
  828. * @pkt_comp_count: It is incremented on each AOS received. When event ring
  829. * Write index is updated, it is decremented by the same
  830. * amount.
  831. * @stop_in_progress_stm: If a Stop request is in progress, this will indicate
  832. * the current stage of processing of the stop within MCS
  833. * @resv2: reserved bits.
  834. * wdi_rx_qmap_id_internal: Initialized to 0 by MCS when the channel is
  835. * allocated. It is updated to the current value of SW
  836. * QMAP ID that is being written by MCS to the IPA
  837. * metadata register.
  838. */
  839. struct __packed gsi_wdi2_channel_scratch_new {
  840. uint32_t wifi_rx_ri_addr_low;
  841. uint32_t wifi_rx_ri_addr_high;
  842. uint32_t update_ri_moderation_threshold:5;
  843. uint32_t qmap_id:8;
  844. uint32_t resv1:3;
  845. uint32_t endp_metadatareg_offset:16;
  846. uint32_t wdi_rx_vdev_id:8;
  847. uint32_t wdi_rx_fw_desc:8;
  848. uint32_t update_ri_moderation_counter:6;
  849. uint32_t wdi_rx_tre_proc_in_progress:1;
  850. uint32_t resv4:1;
  851. uint32_t outstanding_tlvs_counter:8;
  852. uint32_t wdi_rx_pkt_length:16;
  853. uint32_t resv2:2;
  854. uint32_t pkt_comp_count:11;
  855. uint32_t stop_in_progress_stm:3;
  856. uint32_t resv3:16;
  857. uint32_t wdi_rx_qmap_id_internal:16;
  858. };
  859. /**
  860. * gsi_mhip_channel_scratch - MHI PRIME protocol SW config area of
  861. * channel scratch
  862. * @assert_bit_40: Valid only for non-host channels.
  863. * Set to 1 for MHI’ channels when running over PCIe.
  864. * @host_channel: Set to 1 for MHIP channel running on host.
  865. *
  866. */
  867. struct __packed gsi_mhip_channel_scratch {
  868. uint32_t assert_bit_40:1;
  869. uint32_t host_channel:1;
  870. uint32_t resvd1:30;
  871. };
  872. /**
  873. * gsi_11ad_rx_channel_scratch - 11AD protocol SW config area of
  874. * RX channel scratch
  875. *
  876. * @status_ring_hwtail_address_lsb: Low 32 bits of status ring hwtail address.
  877. * @status_ring_hwtail_address_msb: High 32 bits of status ring hwtail address.
  878. * @data_buffers_base_address_lsb: Low 32 bits of the data buffers address.
  879. * @data_buffers_base_address_msb: High 32 bits of the data buffers address.
  880. * @fixed_data_buffer_size: the fixed buffer size (> MTU).
  881. * @resv1: reserved bits.
  882. */
  883. struct __packed gsi_11ad_rx_channel_scratch {
  884. uint32_t status_ring_hwtail_address_lsb;
  885. uint32_t status_ring_hwtail_address_msb;
  886. uint32_t data_buffers_base_address_lsb;
  887. uint32_t data_buffers_base_address_msb:8;
  888. uint32_t fixed_data_buffer_size_pow_2:16;
  889. uint32_t resv1:8;
  890. };
  891. /**
  892. * gsi_11ad_tx_channel_scratch - 11AD protocol SW config area of
  893. * TX channel scratch
  894. *
  895. * @status_ring_hwtail_address_lsb: Low 32 bits of status ring hwtail address.
  896. * @status_ring_hwhead_address_lsb: Low 32 bits of status ring hwhead address.
  897. * @status_ring_hwhead_hwtail_8_msb: higher 8 msbs of status ring
  898. * hwhead\hwtail addresses (should be identical).
  899. * @update_status_hwtail_mod_threshold: The threshold in (32B) elements for
  900. * updating descriptor ring 11ad HWTAIL pointer moderation.
  901. * @status_ring_num_elem - the number of elements in the status ring.
  902. * @resv1: reserved bits.
  903. * @fixed_data_buffer_size_pow_2: the fixed buffer size power of 2 (> MTU).
  904. * @resv2: reserved bits.
  905. */
  906. struct __packed gsi_11ad_tx_channel_scratch {
  907. uint32_t status_ring_hwtail_address_lsb;
  908. uint32_t status_ring_hwhead_address_lsb;
  909. uint32_t status_ring_hwhead_hwtail_8_msb:8;
  910. uint32_t update_status_hwtail_mod_threshold:8;
  911. uint32_t status_ring_num_elem:16;
  912. uint32_t resv1:8;
  913. uint32_t fixed_data_buffer_size_pow_2:16;
  914. uint32_t resv2:8;
  915. };
  916. /**
  917. * gsi_wdi3_hamilton_channel_scratch - WDI 3 protocol, hamilton chipset
  918. * SW config area of channel scratch
  919. *
  920. * @wifi_rx_ri_addr_low: Low 32 bits of Transfer ring Read Index address.
  921. * @wifi_rx_ri_addr_high: High 32 bits of Transer ring Read Index address.
  922. * @update_ri_moderation_threshold: Threshold N for Transfer ring Read Index
  923. N is the number of packets that IPA will
  924. process before wifi transfer ring Ri will
  925. be updated.
  926. * @endp_metadata_reg_offset: Rx only, the offset of IPA_ENDP_INIT_HDR_METADATA_n
  927. of the corresponding endpoint in 4B words from IPA
  928. base address.
  929. * @qmap_id: Rx only, used for setting metadata register in IPA, Read only field
  930. for MCS, Write for SW
  931. */
  932. struct __packed gsi_wdi3_v2_channel_scratch {
  933. uint32_t wifi_rp_address_low;
  934. uint32_t wifi_rp_address_high;
  935. uint32_t update_rp_moderation_threshold : 5;
  936. uint32_t qmap_id : 8;
  937. uint32_t reserved1 : 3;
  938. uint32_t endp_metadata_reg_offset : 16;
  939. uint32_t rx_pkt_offset : 16;
  940. uint32_t reserved2 : 6;
  941. uint32_t bank_id : 6;
  942. uint32_t reserved3: 4;
  943. };
  944. /**
  945. * gsi_wdi3_channel_scratch - WDI protocol 3 SW config area of
  946. * channel scratch
  947. *
  948. * @wifi_rx_ri_addr_low: Low 32 bits of Transfer ring Read Index address.
  949. * @wifi_rx_ri_addr_high: High 32 bits of Transfer ring Read Index address.
  950. * @update_ri_moderation_threshold: Threshold N for Transfer ring Read Index
  951. * N is the number of packets that IPA will
  952. * process before Wifi transfer ring Ri will
  953. * be updated.
  954. * @qmap_id: Rx only, used for setting metadata register in IPA. Read only field
  955. * for MCS. Write for SW.
  956. * @resv: reserved bits.
  957. * @endp_metadata_reg_offset: Rx only, the offset of
  958. * IPA_ENDP_INIT_HDR_METADATA_n of the
  959. * corresponding endpoint in 4B words from IPA
  960. * base address.
  961. * @rx_pkt_offset: Rx only, Since Rx header length is not fixed,
  962. * WLAN host will pass this information to IPA.
  963. * @resv: reserved bits.
  964. */
  965. struct __packed gsi_wdi3_channel_scratch {
  966. uint32_t wifi_rp_address_low;
  967. uint32_t wifi_rp_address_high;
  968. uint32_t update_rp_moderation_threshold : 5;
  969. uint32_t qmap_id : 8;
  970. uint32_t reserved1 : 3;
  971. uint32_t endp_metadata_reg_offset : 16;
  972. uint32_t rx_pkt_offset : 16;
  973. uint32_t reserved2 : 16;
  974. };
  975. /**
  976. * gsi_qdss_channel_scratch - QDSS SW config area of
  977. * channel scratch
  978. *
  979. * @bam_p_evt_dest_addr: equivalent to event_ring_doorbell_pa
  980. * physical address of the doorbell that IPA uC
  981. * will update the headpointer of the event ring.
  982. * QDSS should send BAM_P_EVNT_REG address in this var
  983. * Configured with the GSI Doorbell Address.
  984. * GSI sends Update RP by doing a write to this address
  985. * @data_fifo_base_addr: Base address of the data FIFO used by BAM
  986. * @data_fifo_size: Size of the data FIFO
  987. * @bam_p_evt_threshold: Threshold level of how many bytes consumed
  988. * @override_eot: if override EOT==1, it doesn't check the EOT bit in
  989. * the descriptor
  990. */
  991. struct __packed gsi_qdss_channel_scratch {
  992. uint32_t bam_p_evt_dest_addr;
  993. uint32_t data_fifo_base_addr;
  994. uint32_t data_fifo_size : 16;
  995. uint32_t bam_p_evt_threshold : 16;
  996. uint32_t reserved1 : 2;
  997. uint32_t override_eot : 1;
  998. uint32_t reserved2 : 29;
  999. };
  1000. /**
  1001. * gsi_wdi3_channel_scratch2 - WDI3 protocol SW config area of
  1002. * channel scratch2
  1003. *
  1004. * @update_ri_moderation_threshold: Threshold N for Transfer ring Read Index
  1005. * N is the number of packets that IPA will
  1006. * process before Wifi transfer ring Ri will
  1007. * be updated.
  1008. * @qmap_id: Rx only, used for setting metadata register in IPA. Read only
  1009. * field for MCS. Write for SW.
  1010. * @resv: reserved bits.
  1011. * @endp_metadata_reg_offset: Rx only, the offset of
  1012. * IPA_ENDP_INIT_HDR_METADATA_n of the
  1013. * corresponding endpoint in 4B words from IPA
  1014. * base address.
  1015. */
  1016. struct __packed gsi_wdi3_channel_scratch2 {
  1017. uint32_t update_rp_moderation_threshold : 5;
  1018. uint32_t qmap_id : 8;
  1019. uint32_t reserved1 : 3;
  1020. uint32_t endp_metadata_reg_offset : 16;
  1021. };
  1022. /**
  1023. * gsi_wdi3_channel_scratch2_reg - channel scratch2 SW config area
  1024. *
  1025. */
  1026. union __packed gsi_wdi3_channel_scratch2_reg {
  1027. struct __packed gsi_wdi3_channel_scratch2 wdi;
  1028. struct __packed {
  1029. uint32_t word1;
  1030. } data;
  1031. };
  1032. /**
  1033. * gsi_rtk_channel_scratch - Realtek SW config area of
  1034. * channel scratch
  1035. *
  1036. * @rtk_bar_low: Realtek bar address LSB
  1037. * @rtk_bar_high: Realtek bar address MSB
  1038. * @queue_number: dma channel number in rtk
  1039. * @fix_buff_size: buff size in KB
  1040. * @rtk_buff_addr_high: buffer addr where TRE points to
  1041. * @rtk_buff_addr_low: buffer addr where TRE points to
  1042. * the descriptor
  1043. */
  1044. struct __packed gsi_rtk_channel_scratch {
  1045. uint32_t rtk_bar_low;
  1046. uint32_t rtk_bar_high : 9;
  1047. uint32_t queue_number : 5;
  1048. uint32_t fix_buff_size : 4;
  1049. uint32_t reserved1 : 6;
  1050. uint32_t rtk_buff_addr_high : 8;
  1051. uint32_t rtk_buff_addr_low;
  1052. uint32_t reserved2;
  1053. };
  1054. /**
  1055. * gsi_aqc_channel_scratch - AQC SW config area of
  1056. * channel scratch
  1057. *
  1058. * @buff_addr_lsb: AQC buffer address LSB (RX)
  1059. * @buff_addr_msb: AQC buffer address MSB (RX)
  1060. * @fix_buff_size: buff size in log2
  1061. * @head_ptr_lsb: head pointer address LSB (RX)
  1062. * @head_ptr_msb: head pointer address MSB (RX)
  1063. */
  1064. struct __packed gsi_aqc_channel_scratch {
  1065. uint32_t buff_addr_lsb;
  1066. uint32_t buff_addr_msb : 8;
  1067. uint32_t reserved1 : 8;
  1068. unsigned fix_buff_size : 16;
  1069. uint32_t head_ptr_lsb;
  1070. uint32_t head_ptr_msb : 9;
  1071. uint32_t reserved2 : 23;
  1072. };
  1073. /**
  1074. * gsi_ntn_channel_scratch - NTN SW config area of
  1075. * channel scratch
  1076. *
  1077. * @buff_addr_lsb: NTN buffer address LSB
  1078. * @buff_addr_msb: NTN buffer address MSB
  1079. * @fix_buff_size: buff size in log2
  1080. * @ioc_mod_threshold: the threshold for IOC moderation (TX)
  1081. */
  1082. struct __packed gsi_ntn_channel_scratch {
  1083. uint32_t buff_addr_lsb;
  1084. uint32_t buff_addr_msb : 8;
  1085. uint32_t fix_buff_size : 4;
  1086. uint32_t reserved1 : 20;
  1087. uint32_t ioc_mod_threshold : 16;
  1088. uint32_t reserved2 : 16;
  1089. uint32_t reserved3;
  1090. uint32_t reserved4;
  1091. };
  1092. /**
  1093. * gsi_channel_scratch - channel scratch SW config area
  1094. *
  1095. */
  1096. union __packed gsi_channel_scratch {
  1097. struct __packed gsi_gpi_channel_scratch gpi;
  1098. struct __packed gsi_mhi_channel_scratch mhi;
  1099. struct __packed gsi_mhi_channel_scratch_v2 mhi_v2;
  1100. struct __packed gsi_xdci_channel_scratch xdci;
  1101. struct __packed gsi_wdi_channel_scratch wdi;
  1102. struct __packed gsi_11ad_rx_channel_scratch rx_11ad;
  1103. struct __packed gsi_11ad_tx_channel_scratch tx_11ad;
  1104. struct __packed gsi_wdi3_channel_scratch wdi3;
  1105. struct __packed gsi_wdi3_v2_channel_scratch wdi3_v2;
  1106. struct __packed gsi_mhip_channel_scratch mhip;
  1107. struct __packed gsi_wdi2_channel_scratch_new wdi2_new;
  1108. struct __packed gsi_aqc_channel_scratch aqc;
  1109. struct __packed gsi_rtk_channel_scratch rtk;
  1110. struct __packed gsi_ntn_channel_scratch ntn;
  1111. struct __packed gsi_qdss_channel_scratch qdss;
  1112. struct __packed {
  1113. uint32_t word1;
  1114. uint32_t word2;
  1115. uint32_t word3;
  1116. uint32_t word4;
  1117. } data;
  1118. };
  1119. /**
  1120. * gsi_wdi_channel_scratch3 - WDI protocol SW config area of
  1121. * channel scratch3
  1122. */
  1123. struct __packed gsi_wdi_channel_scratch3 {
  1124. uint32_t endp_metadatareg_offset:16;
  1125. uint32_t qmap_id:16;
  1126. };
  1127. /**
  1128. * gsi_wdi_channel_scratch3_reg - channel scratch3 SW config area
  1129. *
  1130. */
  1131. union __packed gsi_wdi_channel_scratch3_reg {
  1132. struct __packed gsi_wdi_channel_scratch3 wdi;
  1133. struct __packed {
  1134. uint32_t word1;
  1135. } data;
  1136. };
  1137. /**
  1138. * gsi_wdi2_channel_scratch2 - WDI protocol SW config area of
  1139. * channel scratch2
  1140. */
  1141. struct __packed gsi_wdi2_channel_scratch2 {
  1142. uint32_t update_ri_moderation_threshold:5;
  1143. uint32_t qmap_id:8;
  1144. uint32_t resv1:3;
  1145. uint32_t endp_metadatareg_offset:16;
  1146. };
  1147. /**
  1148. * gsi_wdi_channel_scratch2_reg - channel scratch2 SW config area
  1149. *
  1150. */
  1151. union __packed gsi_wdi2_channel_scratch2_reg {
  1152. struct __packed gsi_wdi2_channel_scratch2 wdi;
  1153. struct __packed {
  1154. uint32_t word1;
  1155. } data;
  1156. };
  1157. /**
  1158. * gsi_mhi_evt_scratch - MHI protocol SW config area of
  1159. * event scratch
  1160. */
  1161. struct __packed gsi_mhi_evt_scratch {
  1162. uint32_t resvd1;
  1163. uint32_t resvd2;
  1164. };
  1165. /**
  1166. * gsi_mhip_evt_scratch - MHI PRIME protocol SW config area of
  1167. * event scratch
  1168. */
  1169. struct __packed gsi_mhip_evt_scratch {
  1170. uint32_t rp_mod_threshold:8;
  1171. uint32_t rp_mod_timer:4;
  1172. uint32_t rp_mod_counter:8;
  1173. uint32_t rp_mod_timer_id:4;
  1174. uint32_t rp_mod_timer_running:1;
  1175. uint32_t resvd1:7;
  1176. uint32_t fixed_buffer_sz:16;
  1177. uint32_t resvd2:16;
  1178. };
  1179. /**
  1180. * gsi_xdci_evt_scratch - xDCI protocol SW config area of
  1181. * event scratch
  1182. *
  1183. */
  1184. struct __packed gsi_xdci_evt_scratch {
  1185. uint32_t gevntcount_low_addr;
  1186. uint32_t gevntcount_hi_addr:8;
  1187. uint32_t resvd1:24;
  1188. };
  1189. /**
  1190. * gsi_wdi_evt_scratch - WDI protocol SW config area of
  1191. * event scratch
  1192. *
  1193. */
  1194. struct __packed gsi_wdi_evt_scratch {
  1195. uint32_t update_ri_moderation_config:8;
  1196. uint32_t resvd1:8;
  1197. uint32_t update_ri_mod_timer_running:1;
  1198. uint32_t evt_comp_count:14;
  1199. uint32_t resvd2:1;
  1200. uint32_t last_update_ri:16;
  1201. uint32_t resvd3:16;
  1202. };
  1203. /**
  1204. * gsi_11ad_evt_scratch - 11AD protocol SW config area of
  1205. * event scratch
  1206. *
  1207. */
  1208. struct __packed gsi_11ad_evt_scratch {
  1209. uint32_t update_status_hwtail_mod_threshold : 8;
  1210. uint32_t resvd1:8;
  1211. uint32_t resvd2:16;
  1212. uint32_t resvd3;
  1213. };
  1214. /**
  1215. * gsi_wdi3_evt_scratch - wdi3 protocol SW config area of
  1216. * event scratch
  1217. * @update_ri_moderation_threshold: Threshold N for Transfer ring Read Index
  1218. * N is the number of packets that IPA will
  1219. * process before Wifi transfer ring Ri will
  1220. * be updated.
  1221. * @reserved1: reserve bit.
  1222. * @reserved2: reserve bit.
  1223. */
  1224. struct __packed gsi_wdi3_evt_scratch {
  1225. uint32_t update_rp_moderation_config : 8;
  1226. uint32_t reserved1 : 24;
  1227. uint32_t reserved2;
  1228. };
  1229. /**
  1230. * gsi_rtk_evt_scratch - realtek protocol SW config area of
  1231. * event scratch
  1232. * @reserved1: reserve bit.
  1233. * @reserved2: reserve bit.
  1234. */
  1235. struct __packed gsi_rtk_evt_scratch {
  1236. uint32_t reserved1;
  1237. uint32_t reserved2;
  1238. };
  1239. /**
  1240. * gsi_aqc_evt_scratch - AQC protocol SW config area of
  1241. * event scratch
  1242. * @head_ptr_wrb_mod_threshold: head pointer write-back moderation threshold
  1243. * @reserved1-3: reserve bit.
  1244. */
  1245. struct __packed gsi_aqc_evt_scratch {
  1246. uint8_t head_ptr_wrb_mod_threshold;
  1247. uint8_t reserved1;
  1248. uint16_t reserved2;
  1249. uint32_t reserved3;
  1250. };
  1251. /**
  1252. * gsi_evt_scratch - event scratch SW config area
  1253. *
  1254. */
  1255. union __packed gsi_evt_scratch {
  1256. struct __packed gsi_mhi_evt_scratch mhi;
  1257. struct __packed gsi_xdci_evt_scratch xdci;
  1258. struct __packed gsi_wdi_evt_scratch wdi;
  1259. struct __packed gsi_11ad_evt_scratch w11ad;
  1260. struct __packed gsi_wdi3_evt_scratch wdi3;
  1261. struct __packed gsi_mhip_evt_scratch mhip;
  1262. struct __packed gsi_aqc_evt_scratch aqc;
  1263. struct __packed gsi_rtk_evt_scratch rtk;
  1264. struct __packed {
  1265. uint32_t word1;
  1266. uint32_t word2;
  1267. } data;
  1268. };
  1269. /**
  1270. * gsi_device_scratch - EE scratch config parameters
  1271. *
  1272. * @mhi_base_chan_idx_valid: is mhi_base_chan_idx valid?
  1273. * @mhi_base_chan_idx: base index of IPA MHI channel indexes.
  1274. * IPA MHI channel index = GSI channel ID +
  1275. * MHI base channel index
  1276. * @max_usb_pkt_size_valid: is max_usb_pkt_size valid?
  1277. * @max_usb_pkt_size: max USB packet size in bytes (valid values are
  1278. * 64, 512 and 1024)
  1279. */
  1280. struct gsi_device_scratch {
  1281. bool mhi_base_chan_idx_valid;
  1282. uint8_t mhi_base_chan_idx;
  1283. bool max_usb_pkt_size_valid;
  1284. uint16_t max_usb_pkt_size;
  1285. };
  1286. /**
  1287. * gsi_chan_info - information about channel occupancy
  1288. *
  1289. * @wp: channel write pointer (physical address)
  1290. * @rp: channel read pointer (physical address)
  1291. * @evt_valid: is evt* info valid?
  1292. * @evt_wp: event ring write pointer (physical address)
  1293. * @evt_rp: event ring read pointer (physical address)
  1294. */
  1295. struct gsi_chan_info {
  1296. uint64_t wp;
  1297. uint64_t rp;
  1298. bool evt_valid;
  1299. uint64_t evt_wp;
  1300. uint64_t evt_rp;
  1301. };
  1302. enum gsi_evt_ring_state {
  1303. GSI_EVT_RING_STATE_NOT_ALLOCATED = 0x0,
  1304. GSI_EVT_RING_STATE_ALLOCATED = 0x1,
  1305. GSI_EVT_RING_STATE_ERROR = 0xf
  1306. };
  1307. enum gsi_chan_state {
  1308. GSI_CHAN_STATE_NOT_ALLOCATED = 0x0,
  1309. GSI_CHAN_STATE_ALLOCATED = 0x1,
  1310. GSI_CHAN_STATE_STARTED = 0x2,
  1311. GSI_CHAN_STATE_STOPPED = 0x3,
  1312. GSI_CHAN_STATE_STOP_IN_PROC = 0x4,
  1313. GSI_CHAN_STATE_FLOW_CONTROL = 0x5,
  1314. GSI_CHAN_STATE_ERROR = 0xf
  1315. };
  1316. struct gsi_ring_ctx {
  1317. spinlock_t slock;
  1318. unsigned long base_va;
  1319. uint64_t base;
  1320. uint64_t wp;
  1321. uint64_t rp;
  1322. uint64_t wp_local;
  1323. uint64_t rp_local;
  1324. uint32_t len;
  1325. uint8_t elem_sz;
  1326. uint16_t max_num_elem;
  1327. uint64_t end;
  1328. };
  1329. struct gsi_chan_dp_stats {
  1330. unsigned long ch_below_lo;
  1331. unsigned long ch_below_hi;
  1332. unsigned long ch_above_hi;
  1333. unsigned long empty_time;
  1334. unsigned long last_timestamp;
  1335. };
  1336. struct gsi_chan_stats {
  1337. unsigned long queued;
  1338. unsigned long completed;
  1339. unsigned long callback_to_poll;
  1340. unsigned long poll_to_callback;
  1341. unsigned long poll_pending_irq;
  1342. unsigned long invalid_tre_error;
  1343. unsigned long poll_ok;
  1344. unsigned long poll_empty;
  1345. unsigned long userdata_in_use;
  1346. struct gsi_chan_dp_stats dp;
  1347. };
  1348. /**
  1349. * struct gsi_user_data - user_data element pointed by the TRE
  1350. * @valid: valid to be cleaned. if its true that means it is being used.
  1351. * false means its free to overwrite
  1352. * @p: pointer to the user data array element
  1353. */
  1354. struct gsi_user_data {
  1355. bool valid;
  1356. void *p;
  1357. };
  1358. struct gsi_chan_ctx {
  1359. struct gsi_chan_props props;
  1360. enum gsi_chan_state state;
  1361. struct gsi_ring_ctx ring;
  1362. struct gsi_user_data *user_data;
  1363. struct gsi_evt_ctx *evtr;
  1364. struct mutex mlock;
  1365. struct completion compl;
  1366. bool allocated;
  1367. atomic_t poll_mode;
  1368. union __packed gsi_channel_scratch scratch;
  1369. struct gsi_chan_stats stats;
  1370. bool enable_dp_stats;
  1371. bool print_dp_stats;
  1372. };
  1373. struct gsi_evt_stats {
  1374. unsigned long completed;
  1375. };
  1376. struct gsi_evt_ctx {
  1377. struct gsi_evt_ring_props props;
  1378. enum gsi_evt_ring_state state;
  1379. uint8_t id;
  1380. struct gsi_ring_ctx ring;
  1381. struct mutex mlock;
  1382. struct completion compl;
  1383. struct gsi_chan_ctx *chan[MAX_CHANNELS_SHARING_EVENT_RING];
  1384. uint8_t num_of_chan_allocated;
  1385. atomic_t chan_ref_cnt;
  1386. union __packed gsi_evt_scratch scratch;
  1387. struct gsi_evt_stats stats;
  1388. };
  1389. struct gsi_ee_scratch {
  1390. union __packed {
  1391. struct {
  1392. uint32_t inter_ee_cmd_return_code:3;
  1393. uint32_t resvd1:2;
  1394. uint32_t generic_ee_cmd_return_code:3;
  1395. uint32_t resvd2:2;
  1396. uint32_t generic_ee_cmd_return_val:3;
  1397. uint32_t resvd4:2;
  1398. uint32_t max_usb_pkt_size:1;
  1399. uint32_t resvd3:8;
  1400. uint32_t mhi_base_chan_idx:8;
  1401. } s;
  1402. uint32_t val;
  1403. } word0;
  1404. uint32_t word1;
  1405. };
  1406. struct ch_debug_stats {
  1407. unsigned long ch_allocate;
  1408. unsigned long ch_start;
  1409. unsigned long ch_stop;
  1410. unsigned long ch_reset;
  1411. unsigned long ch_de_alloc;
  1412. unsigned long ch_db_stop;
  1413. unsigned long cmd_completed;
  1414. };
  1415. struct gsi_generic_ee_cmd_debug_stats {
  1416. unsigned long halt_channel;
  1417. unsigned long flow_ctrl_channel;
  1418. };
  1419. struct gsi_coal_chan_info {
  1420. uint8_t ch_id;
  1421. uint8_t evchid;
  1422. };
  1423. struct gsi_log_ts {
  1424. u64 timestamp;
  1425. u64 qtimer;
  1426. u32 interrupt_type;
  1427. };
  1428. struct gsi_msi {
  1429. u32 num;
  1430. DECLARE_BITMAP(allocated, GSI_MAX_NUM_MSI);
  1431. DECLARE_BITMAP(used, GSI_MAX_NUM_MSI);
  1432. struct msi_msg msg[GSI_MAX_NUM_MSI];
  1433. u32 irq[GSI_MAX_NUM_MSI];
  1434. u32 evt[GSI_MAX_NUM_MSI];
  1435. unsigned long mask;
  1436. };
  1437. struct gsi_ctx {
  1438. void __iomem *base;
  1439. struct device *dev;
  1440. struct gsi_per_props per;
  1441. bool per_registered;
  1442. struct gsi_chan_ctx chan[GSI_CHAN_MAX];
  1443. struct ch_debug_stats ch_dbg[GSI_CHAN_MAX];
  1444. struct gsi_evt_ctx evtr[GSI_EVT_RING_MAX];
  1445. struct gsi_generic_ee_cmd_debug_stats gen_ee_cmd_dbg;
  1446. struct mutex mlock;
  1447. spinlock_t slock;
  1448. unsigned long evt_bmap;
  1449. bool enabled;
  1450. atomic_t num_chan;
  1451. atomic_t num_evt_ring;
  1452. struct gsi_ee_scratch scratch;
  1453. int num_ch_dp_stats;
  1454. struct workqueue_struct *dp_stat_wq;
  1455. u32 max_ch;
  1456. u32 max_ev;
  1457. struct completion gen_ee_cmd_compl;
  1458. void *ipc_logbuf;
  1459. void *ipc_logbuf_low;
  1460. struct gsi_coal_chan_info coal_info;
  1461. bool msi_addr_set;
  1462. uint64_t msi_addr;
  1463. struct gsi_msi msi;
  1464. /*
  1465. * The following used only on emulation systems.
  1466. */
  1467. void __iomem *intcntrlr_base;
  1468. u32 intcntrlr_mem_size;
  1469. irq_handler_t intcntrlr_gsi_isr;
  1470. irq_handler_t intcntrlr_client_isr;
  1471. struct gsi_log_ts gsi_isr_cache[GSI_ISR_CACHE_MAX];
  1472. int gsi_isr_cache_index;
  1473. atomic_t num_unclock_irq;
  1474. };
  1475. enum gsi_re_type {
  1476. GSI_RE_XFER = 0x2,
  1477. GSI_RE_IMMD_CMD = 0x3,
  1478. GSI_RE_NOP = 0x4,
  1479. GSI_RE_COAL = 0x8,
  1480. };
  1481. struct __packed gsi_tre {
  1482. uint64_t buffer_ptr;
  1483. uint16_t buf_len;
  1484. uint16_t resvd1;
  1485. uint16_t chain:1;
  1486. uint16_t resvd4:7;
  1487. uint16_t ieob:1;
  1488. uint16_t ieot:1;
  1489. uint16_t bei:1;
  1490. uint16_t resvd3:5;
  1491. uint8_t re_type;
  1492. uint8_t resvd2;
  1493. };
  1494. struct __packed gsi_gci_tre {
  1495. uint64_t buffer_ptr:41;
  1496. uint64_t resvd1:7;
  1497. uint64_t buf_len:16;
  1498. uint64_t cookie:40;
  1499. uint64_t resvd2:8;
  1500. uint64_t re_type:8;
  1501. uint64_t resvd3:8;
  1502. };
  1503. #define GSI_XFER_COMPL_TYPE_GCI 0x28
  1504. struct __packed gsi_xfer_compl_evt {
  1505. union {
  1506. uint64_t xfer_ptr;
  1507. struct {
  1508. uint64_t cookie:40;
  1509. uint64_t resvd1:24;
  1510. };
  1511. };
  1512. uint16_t len;
  1513. uint8_t veid;
  1514. uint8_t code; /* see gsi_chan_evt */
  1515. uint16_t resvd;
  1516. uint8_t type;
  1517. uint8_t chid;
  1518. };
  1519. enum gsi_err_type {
  1520. GSI_ERR_TYPE_GLOB = 0x1,
  1521. GSI_ERR_TYPE_CHAN = 0x2,
  1522. GSI_ERR_TYPE_EVT = 0x3,
  1523. };
  1524. enum gsi_err_code {
  1525. GSI_INVALID_TRE_ERR = 0x1,
  1526. GSI_OUT_OF_BUFFERS_ERR = 0x2,
  1527. GSI_OUT_OF_RESOURCES_ERR = 0x3,
  1528. GSI_UNSUPPORTED_INTER_EE_OP_ERR = 0x4,
  1529. GSI_EVT_RING_EMPTY_ERR = 0x5,
  1530. GSI_NON_ALLOCATED_EVT_ACCESS_ERR = 0x6,
  1531. GSI_HWO_1_ERR = 0x8
  1532. };
  1533. struct __packed gsi_log_err {
  1534. uint32_t arg3:4;
  1535. uint32_t arg2:4;
  1536. uint32_t arg1:4;
  1537. uint32_t code:4;
  1538. uint32_t resvd:3;
  1539. uint32_t virt_idx:5;
  1540. uint32_t err_type:4;
  1541. uint32_t ee:4;
  1542. };
  1543. enum gsi_ch_cmd_opcode {
  1544. GSI_CH_ALLOCATE = 0x0,
  1545. GSI_CH_START = 0x1,
  1546. GSI_CH_STOP = 0x2,
  1547. GSI_CH_RESET = 0x9,
  1548. GSI_CH_DE_ALLOC = 0xa,
  1549. GSI_CH_DB_STOP = 0xb,
  1550. };
  1551. enum gsi_evt_ch_cmd_opcode {
  1552. GSI_EVT_ALLOCATE = 0x0,
  1553. GSI_EVT_RESET = 0x9,
  1554. GSI_EVT_DE_ALLOC = 0xa,
  1555. };
  1556. enum gsi_generic_ee_cmd_opcode {
  1557. GSI_GEN_EE_CMD_HALT_CHANNEL = 0x1,
  1558. GSI_GEN_EE_CMD_ALLOC_CHANNEL = 0x2,
  1559. GSI_GEN_EE_CMD_ENABLE_FLOW_CHANNEL = 0x3,
  1560. GSI_GEN_EE_CMD_DISABLE_FLOW_CHANNEL = 0x4,
  1561. GSI_GEN_EE_CMD_QUERY_FLOW_CHANNEL = 0x5,
  1562. };
  1563. enum gsi_generic_ee_cmd_return_code {
  1564. GSI_GEN_EE_CMD_RETURN_CODE_SUCCESS = 0x1,
  1565. GSI_GEN_EE_CMD_RETURN_CODE_CHANNEL_NOT_RUNNING = 0x2,
  1566. GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_DIRECTION = 0x3,
  1567. GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_CHANNEL_TYPE = 0x4,
  1568. GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_CHANNEL_INDEX = 0x5,
  1569. GSI_GEN_EE_CMD_RETURN_CODE_RETRY = 0x6,
  1570. GSI_GEN_EE_CMD_RETURN_CODE_OUT_OF_RESOURCES = 0x7,
  1571. };
  1572. /**
  1573. * struct gsi_hw_profiling_data - GSI profiling data
  1574. * @bp_cnt: Back Pressure occurences count
  1575. * @bp_and_pending_cnt: Back Pressure with pending back pressure count
  1576. * @mcs_busy_cnt: Cycle count for MCS busy
  1577. * @mcs_idle_cnt: Cycle count for MCS idle
  1578. */
  1579. struct gsi_hw_profiling_data {
  1580. u64 bp_cnt;
  1581. u64 bp_and_pending_cnt;
  1582. u64 mcs_busy_cnt;
  1583. u64 mcs_idle_cnt;
  1584. };
  1585. /**
  1586. * struct gsi_fw_version - GSI fw version data
  1587. * @hw: HW version
  1588. * @flavor: Flavor identifier
  1589. * @fw: FW version
  1590. */
  1591. struct gsi_fw_version {
  1592. u32 hw;
  1593. u32 flavor;
  1594. u32 fw;
  1595. };
  1596. enum gsi_generic_ee_cmd_query_retun_val {
  1597. GSI_GEN_EE_CMD_RETURN_VAL_FLOW_CONTROL_PRIMARY = 0,
  1598. GSI_GEN_EE_CMD_RETURN_VAL_FLOW_CONTROL_SECONDARY = 1,
  1599. GSI_GEN_EE_CMD_RETURN_VAL_FLOW_CONTROL_PENDING = 2,
  1600. };
  1601. extern struct gsi_ctx *gsi_ctx;
  1602. /**
  1603. * gsi_xfer_elem - Metadata about a single transfer
  1604. *
  1605. * @addr: physical address of buffer
  1606. * @len: size of buffer for GSI_XFER_ELEM_DATA:
  1607. * for outbound transfers this is the number of bytes to
  1608. * transfer.
  1609. * for inbound transfers, this is the maximum number of
  1610. * bytes the host expects from device in this transfer
  1611. *
  1612. * immediate command opcode for GSI_XFER_ELEM_IMME_CMD
  1613. * @flags: transfer flags, OR of all the applicable flags
  1614. *
  1615. * GSI_XFER_FLAG_BEI: Block event interrupt
  1616. * 1: Event generated by this ring element must not assert
  1617. * an interrupt to the host
  1618. * 0: Event generated by this ring element must assert an
  1619. * interrupt to the host
  1620. *
  1621. * GSI_XFER_FLAG_EOT: Interrupt on end of transfer
  1622. * 1: If an EOT condition is encountered when processing
  1623. * this ring element, an event is generated by the device
  1624. * with its completion code set to EOT.
  1625. * 0: If an EOT condition is encountered for this ring
  1626. * element, a completion event is not be generated by the
  1627. * device, unless IEOB is 1
  1628. *
  1629. * GSI_XFER_FLAG_EOB: Interrupt on end of block
  1630. * 1: Device notifies host after processing this ring element
  1631. * by sending a completion event
  1632. * 0: Completion event is not required after processing this
  1633. * ring element
  1634. *
  1635. * GSI_XFER_FLAG_CHAIN: Chain bit that identifies the ring
  1636. * elements in a TD
  1637. *
  1638. * @type: transfer type
  1639. *
  1640. * GSI_XFER_ELEM_DATA: for all data transfers
  1641. * GSI_XFER_ELEM_IMME_CMD: for IPA immediate commands
  1642. * GSI_XFER_ELEM_NOP: for event generation only
  1643. *
  1644. * @xfer_user_data: cookie used in xfer_cb
  1645. *
  1646. */
  1647. struct gsi_xfer_elem {
  1648. uint64_t addr;
  1649. uint16_t len;
  1650. uint16_t flags;
  1651. enum gsi_xfer_elem_type type;
  1652. void *xfer_user_data;
  1653. };
  1654. /**
  1655. * gsi_alloc_evt_ring - Peripheral should call this function to
  1656. * allocate an event ring
  1657. *
  1658. * @props: Event ring properties
  1659. * @dev_hdl: Client handle previously obtained from
  1660. * gsi_register_device
  1661. * @evt_ring_hdl: Handle populated by GSI, opaque to client
  1662. *
  1663. * This function can sleep
  1664. *
  1665. * @Return gsi_status
  1666. */
  1667. int gsi_alloc_evt_ring(struct gsi_evt_ring_props *props, unsigned long dev_hdl,
  1668. unsigned long *evt_ring_hdl);
  1669. /**
  1670. * gsi_dealloc_evt_ring - Peripheral should call this function to
  1671. * de-allocate an event ring. There should not exist any active
  1672. * channels using this event ring
  1673. *
  1674. * @evt_ring_hdl: Client handle previously obtained from
  1675. * gsi_alloc_evt_ring
  1676. *
  1677. * This function can sleep
  1678. *
  1679. * @Return gsi_status
  1680. */
  1681. int gsi_dealloc_evt_ring(unsigned long evt_ring_hdl);
  1682. /**
  1683. * gsi_alloc_channel - Peripheral should call this function to
  1684. * allocate a channel
  1685. *
  1686. * @props: Channel properties
  1687. * @dev_hdl: Client handle previously obtained from
  1688. * gsi_register_device
  1689. * @chan_hdl: Handle populated by GSI, opaque to client
  1690. *
  1691. * This function can sleep
  1692. *
  1693. * @Return gsi_status
  1694. */
  1695. int gsi_alloc_channel(struct gsi_chan_props *props, unsigned long dev_hdl,
  1696. unsigned long *chan_hdl);
  1697. /**
  1698. * gsi_start_channel - Peripheral should call this function to
  1699. * start a channel i.e put into running state
  1700. *
  1701. * @chan_hdl: Client handle previously obtained from
  1702. * gsi_alloc_channel
  1703. *
  1704. * This function can sleep
  1705. *
  1706. * @Return gsi_status
  1707. */
  1708. int gsi_start_channel(unsigned long chan_hdl);
  1709. /**
  1710. * gsi_reset_channel - Peripheral should call this function to
  1711. * reset a channel to recover from error state
  1712. *
  1713. * @chan_hdl: Client handle previously obtained from
  1714. * gsi_alloc_channel
  1715. *
  1716. * This function can sleep
  1717. *
  1718. * @Return gsi_status
  1719. */
  1720. int gsi_reset_channel(unsigned long chan_hdl);
  1721. /**
  1722. * gsi_dealloc_channel - Peripheral should call this function to
  1723. * de-allocate a channel
  1724. *
  1725. * @chan_hdl: Client handle previously obtained from
  1726. * gsi_alloc_channel
  1727. *
  1728. * This function can sleep
  1729. *
  1730. * @Return gsi_status
  1731. */
  1732. int gsi_dealloc_channel(unsigned long chan_hdl);
  1733. /**
  1734. * gsi_poll_channel - Peripheral should call this function to query for
  1735. * completed transfer descriptors.
  1736. *
  1737. * @chan_hdl: Client handle previously obtained from
  1738. * gsi_alloc_channel
  1739. * @notify: Information about the completed transfer if any
  1740. *
  1741. * @Return gsi_status (GSI_STATUS_POLL_EMPTY is returned if no transfers
  1742. * completed)
  1743. */
  1744. int gsi_poll_channel(unsigned long chan_hdl,
  1745. struct gsi_chan_xfer_notify *notify);
  1746. /**
  1747. * gsi_ring_evt_doorbell_napi - doorbell from NAPI context
  1748. * @chan_hdl: Client handle previously obtained from
  1749. * gsi_alloc_channel
  1750. *
  1751. */
  1752. void gsi_ring_evt_doorbell_polling_mode(unsigned long chan_hdl);
  1753. /**
  1754. * gsi_config_channel_mode - Peripheral should call this function
  1755. * to configure the channel mode.
  1756. *
  1757. * @chan_hdl: Client handle previously obtained from
  1758. * gsi_alloc_channel
  1759. * @mode: Mode to move the channel into
  1760. *
  1761. * @Return gsi_status
  1762. */
  1763. int gsi_config_channel_mode(unsigned long chan_hdl, enum gsi_chan_mode mode);
  1764. /**
  1765. * gsi_queue_xfer - Peripheral should call this function
  1766. * to queue transfers on the given channel
  1767. *
  1768. * @chan_hdl: Client handle previously obtained from
  1769. * gsi_alloc_channel
  1770. * @num_xfers: Number of transfer in the array @ xfer
  1771. * @xfer: Array of num_xfers transfer descriptors
  1772. * @ring_db: If true, tell HW about these queued xfers
  1773. * If false, do not notify HW at this time
  1774. *
  1775. * @Return gsi_status
  1776. */
  1777. int gsi_queue_xfer(unsigned long chan_hdl, uint16_t num_xfers,
  1778. struct gsi_xfer_elem *xfer, bool ring_db);
  1779. void gsi_debugfs_init(void);
  1780. uint16_t gsi_find_idx_from_addr(struct gsi_ring_ctx *ctx, uint64_t addr);
  1781. void gsi_update_ch_dp_stats(struct gsi_chan_ctx *ctx, uint16_t used);
  1782. /**
  1783. * gsi_register_device - Peripheral should call this function to
  1784. * register itself with GSI before invoking any other APIs
  1785. *
  1786. * @props: Peripheral properties
  1787. * @dev_hdl: Handle populated by GSI, opaque to client
  1788. *
  1789. * @Return -GSI_STATUS_AGAIN if request should be re-tried later
  1790. * other error codes for failure
  1791. */
  1792. int gsi_register_device(struct gsi_per_props *props, unsigned long *dev_hdl);
  1793. /**
  1794. * gsi_complete_clk_grant - Peripheral should call this function to
  1795. * grant the clock resource requested by GSI previously that could not
  1796. * be granted synchronously. GSI will release the clock resource using
  1797. * the rel_clk_cb when appropriate
  1798. *
  1799. * @dev_hdl: Client handle previously obtained from
  1800. * gsi_register_device
  1801. *
  1802. * @Return gsi_status
  1803. */
  1804. int gsi_complete_clk_grant(unsigned long dev_hdl);
  1805. /**
  1806. * gsi_write_device_scratch - Peripheral should call this function to
  1807. * write to the EE scratch area
  1808. *
  1809. * @dev_hdl: Client handle previously obtained from
  1810. * gsi_register_device
  1811. * @val: Value to write
  1812. *
  1813. * @Return gsi_status
  1814. */
  1815. int gsi_write_device_scratch(unsigned long dev_hdl,
  1816. struct gsi_device_scratch *val);
  1817. /**
  1818. * gsi_deregister_device - Peripheral should call this function to
  1819. * de-register itself with GSI
  1820. *
  1821. * @dev_hdl: Client handle previously obtained from
  1822. * gsi_register_device
  1823. * @force: When set to true, cleanup is performed even if there
  1824. * are in use resources like channels, event rings, etc.
  1825. * this would be used after GSI reset to recover from some
  1826. * fatal error
  1827. * When set to false, there must not exist any allocated
  1828. * channels and event rings.
  1829. *
  1830. * @Return gsi_status
  1831. */
  1832. int gsi_deregister_device(unsigned long dev_hdl, bool force);
  1833. /**
  1834. * gsi_write_evt_ring_scratch - Peripheral should call this function to
  1835. * write to the scratch area of the event ring context
  1836. *
  1837. * @evt_ring_hdl: Client handle previously obtained from
  1838. * gsi_alloc_evt_ring
  1839. * @val: Value to write
  1840. *
  1841. * @Return gsi_status
  1842. */
  1843. int gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
  1844. union __packed gsi_evt_scratch val);
  1845. /**
  1846. * gsi_query_evt_ring_db_addr - Peripheral should call this function to
  1847. * query the physical addresses of the event ring doorbell registers
  1848. *
  1849. * @evt_ring_hdl: Client handle previously obtained from
  1850. * gsi_alloc_evt_ring
  1851. * @db_addr_wp_lsb: Physical address of doorbell register where the 32
  1852. * LSBs of the doorbell value should be written
  1853. * @db_addr_wp_msb: Physical address of doorbell register where the 32
  1854. * MSBs of the doorbell value should be written
  1855. *
  1856. * @Return gsi_status
  1857. */
  1858. int gsi_query_evt_ring_db_addr(unsigned long evt_ring_hdl,
  1859. uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
  1860. /**
  1861. * gsi_ring_evt_ring_db - Peripheral should call this function for
  1862. * ringing the event ring doorbell with given value
  1863. *
  1864. * @evt_ring_hdl: Client handle previously obtained from
  1865. * gsi_alloc_evt_ring
  1866. * @value: The value to be used for ringing the doorbell
  1867. *
  1868. * @Return gsi_status
  1869. */
  1870. int gsi_ring_evt_ring_db(unsigned long evt_ring_hdl, uint64_t value);
  1871. /**
  1872. * gsi_ring_ch_ring_db - Peripheral should call this function for
  1873. * ringing the channel ring doorbell with given value
  1874. *
  1875. * @chan_hdl: Client handle previously obtained from
  1876. * gsi_alloc_channel
  1877. * @value: The value to be used for ringing the doorbell
  1878. *
  1879. * @Return gsi_status
  1880. */
  1881. int gsi_ring_ch_ring_db(unsigned long chan_hdl, uint64_t value);
  1882. /**
  1883. * gsi_reset_evt_ring - Peripheral should call this function to
  1884. * reset an event ring to recover from error state
  1885. *
  1886. * @evt_ring_hdl: Client handle previously obtained from
  1887. * gsi_alloc_evt_ring
  1888. *
  1889. * This function can sleep
  1890. *
  1891. * @Return gsi_status
  1892. */
  1893. int gsi_reset_evt_ring(unsigned long evt_ring_hdl);
  1894. /**
  1895. * gsi_get_evt_ring_cfg - This function returns the current config
  1896. * of the specified event ring
  1897. *
  1898. * @evt_ring_hdl: Client handle previously obtained from
  1899. * gsi_alloc_evt_ring
  1900. * @props: where to copy properties to
  1901. * @scr: where to copy scratch info to
  1902. *
  1903. * @Return gsi_status
  1904. */
  1905. int gsi_get_evt_ring_cfg(unsigned long evt_ring_hdl,
  1906. struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
  1907. /**
  1908. * gsi_set_evt_ring_cfg - This function applies the supplied config
  1909. * to the specified event ring.
  1910. *
  1911. * exclusive property of the event ring cannot be changed after
  1912. * gsi_alloc_evt_ring
  1913. *
  1914. * @evt_ring_hdl: Client handle previously obtained from
  1915. * gsi_alloc_evt_ring
  1916. * @props: the properties to apply
  1917. * @scr: the scratch info to apply
  1918. *
  1919. * @Return gsi_status
  1920. */
  1921. int gsi_set_evt_ring_cfg(unsigned long evt_ring_hdl,
  1922. struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
  1923. /**
  1924. * gsi_write_channel_scratch - Peripheral should call this function to
  1925. * write to the scratch area of the channel context
  1926. *
  1927. * @chan_hdl: Client handle previously obtained from
  1928. * gsi_alloc_channel
  1929. * @val: Value to write
  1930. *
  1931. * @Return gsi_status
  1932. */
  1933. int gsi_write_channel_scratch(unsigned long chan_hdl,
  1934. union __packed gsi_channel_scratch val);
  1935. /**
  1936. * gsi_write_channel_scratch3_reg - Peripheral should call this function to
  1937. * write to the scratch3 reg area of the channel context
  1938. *
  1939. * @chan_hdl: Client handle previously obtained from
  1940. * gsi_alloc_channel
  1941. * @val: Value to write
  1942. *
  1943. * @Return gsi_status
  1944. */
  1945. int gsi_write_channel_scratch3_reg(unsigned long chan_hdl,
  1946. union __packed gsi_wdi_channel_scratch3_reg val);
  1947. /**
  1948. * gsi_write_channel_scratch2_reg - Peripheral should call this function to
  1949. * write to the scratch2 reg area of the channel context
  1950. *
  1951. * @chan_hdl: Client handle previously obtained from
  1952. * gsi_alloc_channel
  1953. * @val: Value to write
  1954. *
  1955. * @Return gsi_status
  1956. */
  1957. int gsi_write_channel_scratch2_reg(unsigned long chan_hdl,
  1958. union __packed gsi_wdi2_channel_scratch2_reg val);
  1959. /**
  1960. * gsi_write_wdi3_channel_scratch2_reg - Peripheral should call this function
  1961. * to write to the WDI3 scratch 3 register area of the channel context
  1962. *
  1963. * @chan_hdl: Client handle previously obtained from
  1964. * gsi_alloc_channel
  1965. * @val: Read value
  1966. *
  1967. * @Return gsi_status
  1968. */
  1969. int gsi_write_wdi3_channel_scratch2_reg(unsigned long chan_hdl,
  1970. union __packed gsi_wdi3_channel_scratch2_reg val);
  1971. /**
  1972. * gsi_read_channel_scratch - Peripheral should call this function to
  1973. * read to the scratch area of the channel context
  1974. *
  1975. * @chan_hdl: Client handle previously obtained from
  1976. * gsi_alloc_channel
  1977. * @val: Read value
  1978. *
  1979. * @Return gsi_status
  1980. */
  1981. int gsi_read_channel_scratch(unsigned long chan_hdl,
  1982. union __packed gsi_channel_scratch *val);
  1983. /**
  1984. * gsi_read_wdi3_channel_scratch2_reg - Peripheral should call this function to
  1985. * read to the WDI3 scratch 2 register area of the channel context
  1986. *
  1987. * @chan_hdl: Client handle previously obtained from
  1988. * gsi_alloc_channel
  1989. * @val: Read value
  1990. *
  1991. * @Return gsi_status
  1992. */
  1993. int gsi_read_wdi3_channel_scratch2_reg(unsigned long chan_hdl,
  1994. union __packed gsi_wdi3_channel_scratch2_reg *val);
  1995. /*
  1996. * gsi_pending_irq_type - Peripheral should call this function to
  1997. * check if there is any pending irq
  1998. *
  1999. * This function can sleep
  2000. *
  2001. * @Return gsi_irq_type
  2002. */
  2003. int gsi_pending_irq_type(void);
  2004. /**
  2005. * gsi_update_mhi_channel_scratch - MHI Peripheral should call this
  2006. * function to update the scratch area of the channel context. Updating
  2007. * will be by read-modify-write method, so non SWI fields will not be
  2008. * affected
  2009. *
  2010. * @chan_hdl: Client handle previously obtained from
  2011. * gsi_alloc_channel
  2012. * @mscr: MHI Channel Scratch value
  2013. *
  2014. * @Return gsi_status
  2015. */
  2016. int gsi_update_mhi_channel_scratch(unsigned long chan_hdl,
  2017. struct __packed gsi_mhi_channel_scratch mscr);
  2018. /**
  2019. * gsi_stop_channel - Peripheral should call this function to
  2020. * stop a channel. Stop will happen on a packet boundary
  2021. *
  2022. * @chan_hdl: Client handle previously obtained from
  2023. * gsi_alloc_channel
  2024. *
  2025. * This function can sleep
  2026. *
  2027. * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
  2028. * other error codes for failure
  2029. */
  2030. int gsi_stop_channel(unsigned long chan_hdl);
  2031. /**
  2032. * gsi_stop_db_channel - Peripheral should call this function to
  2033. * stop a channel when all transfer elements till the doorbell
  2034. * have been processed
  2035. *
  2036. * @chan_hdl: Client handle previously obtained from
  2037. * gsi_alloc_channel
  2038. *
  2039. * This function can sleep
  2040. *
  2041. * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
  2042. * other error codes for failure
  2043. */
  2044. int gsi_stop_db_channel(unsigned long chan_hdl);
  2045. /**
  2046. * gsi_query_channel_db_addr - Peripheral should call this function to
  2047. * query the physical addresses of the channel doorbell registers
  2048. *
  2049. * @chan_hdl: Client handle previously obtained from
  2050. * gsi_alloc_channel
  2051. * @db_addr_wp_lsb: Physical address of doorbell register where the 32
  2052. * LSBs of the doorbell value should be written
  2053. * @db_addr_wp_msb: Physical address of doorbell register where the 32
  2054. * MSBs of the doorbell value should be written
  2055. *
  2056. * @Return gsi_status
  2057. */
  2058. int gsi_query_channel_db_addr(unsigned long chan_hdl,
  2059. uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
  2060. /**
  2061. * gsi_query_channel_info - Peripheral can call this function to query the
  2062. * channel and associated event ring (if any) status.
  2063. *
  2064. * @chan_hdl: Client handle previously obtained from
  2065. * gsi_alloc_channel
  2066. * @info: Where to read the values into
  2067. *
  2068. * @Return gsi_status
  2069. */
  2070. int gsi_query_channel_info(unsigned long chan_hdl,
  2071. struct gsi_chan_info *info);
  2072. /**
  2073. * gsi_is_channel_empty - Peripheral can call this function to query if
  2074. * the channel is empty. This is only applicable to GPI. "Empty" means
  2075. * GSI has consumed all descriptors for a TO_GSI channel and SW has
  2076. * processed all completed descriptors for a FROM_GSI channel.
  2077. *
  2078. * @chan_hdl: Client handle previously obtained from gsi_alloc_channel
  2079. * @is_empty: set by GSI based on channel emptiness
  2080. *
  2081. * @Return gsi_status
  2082. */
  2083. int gsi_is_channel_empty(unsigned long chan_hdl, bool *is_empty);
  2084. /**
  2085. * gsi_is_event_pending - Returns true if there is at least one event in the
  2086. * provided event ring which wasn't processed.
  2087. *
  2088. * @chan_hdl: Client handle previously obtained from gsi_alloc_channel
  2089. *
  2090. * @Return true if an event is pending, else false
  2091. */
  2092. bool gsi_is_event_pending(unsigned long chan_hdl);
  2093. /**
  2094. * gsi_get_channel_cfg - This function returns the current config
  2095. * of the specified channel
  2096. *
  2097. * @chan_hdl: Client handle previously obtained from
  2098. * gsi_alloc_channel
  2099. * @props: where to copy properties to
  2100. * @scr: where to copy scratch info to
  2101. *
  2102. * @Return gsi_status
  2103. */
  2104. int gsi_get_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
  2105. union gsi_channel_scratch *scr);
  2106. /**
  2107. * gsi_set_channel_cfg - This function applies the supplied config
  2108. * to the specified channel
  2109. *
  2110. * ch_id and evt_ring_hdl of the channel cannot be changed after
  2111. * gsi_alloc_channel
  2112. *
  2113. * @chan_hdl: Client handle previously obtained from
  2114. * gsi_alloc_channel
  2115. * @props: the properties to apply
  2116. * @scr: the scratch info to apply
  2117. *
  2118. * @Return gsi_status
  2119. */
  2120. int gsi_set_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
  2121. union gsi_channel_scratch *scr);
  2122. /**
  2123. * gsi_poll_n_channel - Peripheral should call this function to query for
  2124. * completed transfer descriptors.
  2125. *
  2126. * @chan_hdl: Client handle previously obtained from
  2127. * gsi_alloc_channel
  2128. * @notify: Information about the completed transfer if any
  2129. * @expected_num: Number of descriptor we want to poll each time.
  2130. * @actual_num: Actual number of descriptor we polled successfully.
  2131. *
  2132. * @Return gsi_status (GSI_STATUS_POLL_EMPTY is returned if no transfers
  2133. * completed)
  2134. */
  2135. int gsi_poll_n_channel(unsigned long chan_hdl,
  2136. struct gsi_chan_xfer_notify *notify,
  2137. int expected_num, int *actual_num);
  2138. /**
  2139. * gsi_start_xfer - Peripheral should call this function to
  2140. * inform HW about queued xfers
  2141. *
  2142. * @chan_hdl: Client handle previously obtained from
  2143. * gsi_alloc_channel
  2144. *
  2145. * @Return gsi_status
  2146. */
  2147. int gsi_start_xfer(unsigned long chan_hdl);
  2148. /**
  2149. * gsi_configure_regs - Peripheral should call this function
  2150. * to configure the GSI registers before/after the FW is
  2151. * loaded but before it is enabled.
  2152. *
  2153. * @per_base_addr: Base address of the peripheral using GSI
  2154. * @ver: GSI core version
  2155. *
  2156. * @Return gsi_status
  2157. */
  2158. int gsi_configure_regs(phys_addr_t per_base_addr, enum gsi_ver ver);
  2159. /**
  2160. * gsi_enable_fw - Peripheral should call this function
  2161. * to enable the GSI FW after the FW has been loaded to the SRAM.
  2162. *
  2163. * @gsi_base_addr: Base address of GSI register space
  2164. * @gsi_size: Mapping size of the GSI register space
  2165. * @ver: GSI core version
  2166. * @Return gsi_status
  2167. */
  2168. int gsi_enable_fw(phys_addr_t gsi_base_addr, u32 gsi_size, enum gsi_ver ver);
  2169. /**
  2170. * gsi_get_inst_ram_offset_and_size - Peripheral should call this function
  2171. * to get instruction RAM base address offset and size. Peripheral typically
  2172. * uses this info to load GSI FW into the IRAM.
  2173. *
  2174. * @base_offset:[OUT] - IRAM base offset address
  2175. * @size: [OUT] - IRAM size
  2176. * @ver: GSI core version
  2177. * @Return none
  2178. */
  2179. void gsi_get_inst_ram_offset_and_size(unsigned long *base_offset,
  2180. unsigned long *size, enum gsi_ver ver);
  2181. /**
  2182. * gsi_halt_channel_ee - Peripheral should call this function
  2183. * to stop other EE's channel. This is usually used in SSR clean
  2184. *
  2185. * @chan_idx: Virtual channel index
  2186. * @ee: EE
  2187. * @code: [out] response code for operation
  2188. * @Return gsi_status
  2189. */
  2190. int gsi_halt_channel_ee(unsigned int chan_idx, unsigned int ee, int *code);
  2191. /**
  2192. * gsi_wdi3_write_evt_ring_db - write event ring doorbell address
  2193. *
  2194. * @chan_hdl: gsi channel handle
  2195. * @Return gsi_status
  2196. */
  2197. void gsi_wdi3_write_evt_ring_db(unsigned long chan_hdl, uint32_t db_addr_low,
  2198. uint32_t db_addr_high);
  2199. /**
  2200. * gsi_get_refetch_reg - get WP/RP value from re_fetch register
  2201. *
  2202. * @chan_hdl: gsi channel handle
  2203. * @is_rp: rp or wp
  2204. */
  2205. int gsi_get_refetch_reg(unsigned long chan_hdl, bool is_rp);
  2206. /**
  2207. * gsi_ntn3_client_stats_get - get ntn3 stats
  2208. *
  2209. * @ep_id: ep index
  2210. * @scratch_id: scratch register number
  2211. * @chan_hdl: gsi channel handle
  2212. */
  2213. int gsi_ntn3_client_stats_get(unsigned ep_id, int scratch_id, unsigned chan_hdl);
  2214. /**
  2215. * gsi_get_drop_stats - get drop stats by GSI
  2216. *
  2217. * @ep_id: ep index
  2218. * @scratch_id: drop stats on which scratch register
  2219. * @chan_hdl: gsi channel handle
  2220. */
  2221. int gsi_get_drop_stats(unsigned long ep_id, int scratch_id,
  2222. unsigned long chan_hdl);
  2223. /**
  2224. * gsi_get_wp - get channel write pointer for stats
  2225. *
  2226. * @chan_hdl: gsi channel handle
  2227. */
  2228. int gsi_get_wp(unsigned long chan_hdl);
  2229. /**
  2230. * gsi_wdi3_dump_register - dump wdi3 related gsi registers
  2231. *
  2232. * @chan_hdl: gsi channel handle
  2233. */
  2234. void gsi_wdi3_dump_register(unsigned long chan_hdl);
  2235. /**
  2236. * gsi_map_base - Peripheral should call this function to configure
  2237. * access to the GSI registers.
  2238. * @gsi_base_addr: Base address of GSI register space
  2239. * @gsi_size: Mapping size of the GSI register space
  2240. * @ver: The appropriate GSI version enum
  2241. *
  2242. * @Return gsi_status
  2243. */
  2244. int gsi_map_base(phys_addr_t gsi_base_addr, u32 gsi_size, enum gsi_ver ver);
  2245. /**
  2246. * gsi_unmap_base - Peripheral should call this function to undo the
  2247. * effects of gsi_map_base
  2248. *
  2249. * @Return gsi_status
  2250. */
  2251. int gsi_unmap_base(void);
  2252. /**
  2253. * gsi_map_virtual_ch_to_per_ep - Peripheral should call this function
  2254. * to configure each GSI virtual channel with the per endpoint index.
  2255. *
  2256. * @ee: The ee to be used
  2257. * @chan_num: The channel to be used
  2258. * @per_ep_index: value to assign
  2259. *
  2260. * @Return gsi_status
  2261. */
  2262. int gsi_map_virtual_ch_to_per_ep(u32 ee, u32 chan_num, u32 per_ep_index);
  2263. /**
  2264. * gsi_alloc_channel_ee - Peripheral should call this function
  2265. * to alloc other EE's channel. This is usually done in bootup to allocate all
  2266. * chnnels.
  2267. *
  2268. * @chan_idx: Virtual channel index
  2269. * @ee: EE
  2270. * @code: [out] response code for operation
  2271. * @Return gsi_status
  2272. */
  2273. int gsi_alloc_channel_ee(unsigned int chan_idx, unsigned int ee, int *code);
  2274. /**
  2275. * gsi_enable_flow_control_ee - Peripheral should call this function
  2276. * to enable flow control other EE's channel. This is usually done in USB
  2277. * connent and SSR scenarios.
  2278. *
  2279. * @chan_idx: Virtual channel index
  2280. * @ee: EE
  2281. * @code: [out] response code for operation
  2282. * @Return gsi_status
  2283. */
  2284. int gsi_enable_flow_control_ee(unsigned int chan_idx, unsigned int ee,
  2285. int *code);
  2286. /**
  2287. * gsi_query_msi_addr - get gsi channel msi address
  2288. *
  2289. * @chan_id: channel id
  2290. * @addr: [out] channel msi address
  2291. *
  2292. * @Return gsi_status
  2293. */
  2294. int gsi_query_msi_addr(unsigned long chan_hdl, phys_addr_t *addr);
  2295. /**
  2296. * gsi_query_device_msi_addr - get gsi device msi address
  2297. *
  2298. * @addr: [out] msi address
  2299. *
  2300. * @Return gsi_status
  2301. */
  2302. int gsi_query_device_msi_addr(u64 *addr);
  2303. /**
  2304. * gsi_update_almst_empty_thrshold - update almst_empty_thrshold
  2305. *
  2306. * @chan_id: channel id
  2307. * @threshold: Threshold value for channel almost empty indication to MCS.
  2308. *
  2309. */
  2310. void gsi_update_almst_empty_thrshold(unsigned long chan_hdl, unsigned short threshold);
  2311. /**
  2312. * gsi_dump_ch_info - channel information.
  2313. *
  2314. * @chan_id: channel id
  2315. *
  2316. * @Return void
  2317. */
  2318. void gsi_dump_ch_info(unsigned long chan_hdl);
  2319. /**
  2320. * gsi_get_hw_profiling_stats() - Query GSI HW profiling stats
  2321. * @stats: [out] stats blob from client populated by driver
  2322. *
  2323. * Returns: 0 on success, negative on failure
  2324. *
  2325. */
  2326. int gsi_get_hw_profiling_stats(struct gsi_hw_profiling_data *stats);
  2327. /**
  2328. * gsi_get_fw_version() - Query GSI FW version
  2329. * @ver: [out] ver blob from client populated by driver
  2330. *
  2331. * Returns: 0 on success, negative on failure
  2332. *
  2333. */
  2334. int gsi_get_fw_version(struct gsi_fw_version *ver);
  2335. int gsi_flow_control_ee(unsigned int chan_idx, int ep_id, unsigned int ee,
  2336. bool enable, bool prmy_scnd_fc, int *code);
  2337. int gsi_query_flow_control_state_ee(unsigned int chan_idx, unsigned int ee,
  2338. bool prmy_scnd_fc, int *code);
  2339. /*
  2340. * Here is a typical sequence of calls
  2341. *
  2342. * gsi_register_device
  2343. *
  2344. * gsi_write_device_scratch (if the protocol needs this)
  2345. *
  2346. * gsi_alloc_evt_ring (for as many event rings as needed)
  2347. * gsi_write_evt_ring_scratch
  2348. *
  2349. * gsi_alloc_channel (for as many channels as needed; channels can have
  2350. * no event ring, an exclusive event ring or a shared event ring)
  2351. * gsi_write_channel_scratch
  2352. * gsi_read_channel_scratch
  2353. * gsi_start_channel
  2354. * gsi_queue_xfer/gsi_start_xfer
  2355. * gsi_config_channel_mode/gsi_poll_channel (if clients wants to poll on
  2356. * xfer completions)
  2357. * gsi_stop_db_channel/gsi_stop_channel
  2358. *
  2359. * gsi_dealloc_channel
  2360. *
  2361. * gsi_dealloc_evt_ring
  2362. *
  2363. * gsi_deregister_device
  2364. *
  2365. */
  2366. /**
  2367. * These APIs are mostly for the ipa_stats module
  2368. */
  2369. uint64_t gsi_read_event_ring_wp(int evtr_id, int ee);
  2370. uint64_t gsi_read_event_ring_bp(int evt_hdl);
  2371. uint64_t gsi_get_evt_ring_rp(int evt_hdl);
  2372. uint64_t gsi_read_chan_ring_wp(int chan_id, int ee);
  2373. uint64_t gsi_read_chan_ring_rp(int chan_id, int ee);
  2374. uint64_t gsi_read_chan_ring_bp(int chan_hdl);
  2375. uint64_t gsi_read_chan_ring_re_fetch_wp(int chan_id, int ee);
  2376. enum gsi_chan_prot gsi_get_chan_prot_type(int chan_hdl);
  2377. enum gsi_chan_state gsi_get_chan_state(int chan_hdl);
  2378. int gsi_get_chan_poll_mode(int chan_hdl);
  2379. uint32_t gsi_get_ring_len(int chan_hdl);
  2380. uint8_t gsi_get_chan_props_db_in_bytes(int chan_hdl);
  2381. enum gsi_evt_ring_elem_size gsi_get_evt_ring_re_size(int evt_hdl);
  2382. uint32_t gsi_get_evt_ring_len(int evt_hdl);
  2383. int gsi_get_peripheral_ee(void);
  2384. uint32_t gsi_get_chan_stop_stm(int chan_id, int ee);
  2385. #endif