gsi.h 72 KB

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