gsi.h 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291
  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:7;
  1275. uint32_t max_usb_pkt_size:1;
  1276. uint32_t resvd3:8;
  1277. uint32_t mhi_base_chan_idx:8;
  1278. } s;
  1279. uint32_t val;
  1280. } word0;
  1281. uint32_t word1;
  1282. };
  1283. struct ch_debug_stats {
  1284. unsigned long ch_allocate;
  1285. unsigned long ch_start;
  1286. unsigned long ch_stop;
  1287. unsigned long ch_reset;
  1288. unsigned long ch_de_alloc;
  1289. unsigned long ch_db_stop;
  1290. unsigned long cmd_completed;
  1291. };
  1292. struct gsi_generic_ee_cmd_debug_stats {
  1293. unsigned long halt_channel;
  1294. unsigned long flow_ctrl_channel;
  1295. };
  1296. struct gsi_coal_chan_info {
  1297. uint8_t ch_id;
  1298. uint8_t evchid;
  1299. };
  1300. struct gsi_log_ts {
  1301. u64 timestamp;
  1302. u64 qtimer;
  1303. u32 interrupt_type;
  1304. };
  1305. struct gsi_ctx {
  1306. void __iomem *base;
  1307. struct device *dev;
  1308. struct gsi_per_props per;
  1309. bool per_registered;
  1310. struct gsi_chan_ctx chan[GSI_CHAN_MAX];
  1311. struct ch_debug_stats ch_dbg[GSI_CHAN_MAX];
  1312. struct gsi_evt_ctx evtr[GSI_EVT_RING_MAX];
  1313. struct gsi_generic_ee_cmd_debug_stats gen_ee_cmd_dbg;
  1314. struct mutex mlock;
  1315. spinlock_t slock;
  1316. unsigned long evt_bmap;
  1317. bool enabled;
  1318. atomic_t num_chan;
  1319. atomic_t num_evt_ring;
  1320. struct gsi_ee_scratch scratch;
  1321. int num_ch_dp_stats;
  1322. struct workqueue_struct *dp_stat_wq;
  1323. u32 max_ch;
  1324. u32 max_ev;
  1325. struct completion gen_ee_cmd_compl;
  1326. void *ipc_logbuf;
  1327. void *ipc_logbuf_low;
  1328. struct gsi_coal_chan_info coal_info;
  1329. /*
  1330. * The following used only on emulation systems.
  1331. */
  1332. void __iomem *intcntrlr_base;
  1333. u32 intcntrlr_mem_size;
  1334. irq_handler_t intcntrlr_gsi_isr;
  1335. irq_handler_t intcntrlr_client_isr;
  1336. struct gsi_log_ts gsi_isr_cache[GSI_ISR_CACHE_MAX];
  1337. int gsi_isr_cache_index;
  1338. atomic_t num_unclock_irq;
  1339. };
  1340. enum gsi_re_type {
  1341. GSI_RE_XFER = 0x2,
  1342. GSI_RE_IMMD_CMD = 0x3,
  1343. GSI_RE_NOP = 0x4,
  1344. GSI_RE_COAL = 0x8,
  1345. };
  1346. struct __packed gsi_tre {
  1347. uint64_t buffer_ptr;
  1348. uint16_t buf_len;
  1349. uint16_t resvd1;
  1350. uint16_t chain:1;
  1351. uint16_t resvd4:7;
  1352. uint16_t ieob:1;
  1353. uint16_t ieot:1;
  1354. uint16_t bei:1;
  1355. uint16_t resvd3:5;
  1356. uint8_t re_type;
  1357. uint8_t resvd2;
  1358. };
  1359. struct __packed gsi_gci_tre {
  1360. uint64_t buffer_ptr:41;
  1361. uint64_t resvd1:7;
  1362. uint64_t buf_len:16;
  1363. uint64_t cookie:40;
  1364. uint64_t resvd2:8;
  1365. uint64_t re_type:8;
  1366. uint64_t resvd3:8;
  1367. };
  1368. #define GSI_XFER_COMPL_TYPE_GCI 0x28
  1369. struct __packed gsi_xfer_compl_evt {
  1370. union {
  1371. uint64_t xfer_ptr;
  1372. struct {
  1373. uint64_t cookie:40;
  1374. uint64_t resvd1:24;
  1375. };
  1376. };
  1377. uint16_t len;
  1378. uint8_t veid;
  1379. uint8_t code; /* see gsi_chan_evt */
  1380. uint16_t resvd;
  1381. uint8_t type;
  1382. uint8_t chid;
  1383. };
  1384. enum gsi_err_type {
  1385. GSI_ERR_TYPE_GLOB = 0x1,
  1386. GSI_ERR_TYPE_CHAN = 0x2,
  1387. GSI_ERR_TYPE_EVT = 0x3,
  1388. };
  1389. enum gsi_err_code {
  1390. GSI_INVALID_TRE_ERR = 0x1,
  1391. GSI_OUT_OF_BUFFERS_ERR = 0x2,
  1392. GSI_OUT_OF_RESOURCES_ERR = 0x3,
  1393. GSI_UNSUPPORTED_INTER_EE_OP_ERR = 0x4,
  1394. GSI_EVT_RING_EMPTY_ERR = 0x5,
  1395. GSI_NON_ALLOCATED_EVT_ACCESS_ERR = 0x6,
  1396. GSI_HWO_1_ERR = 0x8
  1397. };
  1398. struct __packed gsi_log_err {
  1399. uint32_t arg3:4;
  1400. uint32_t arg2:4;
  1401. uint32_t arg1:4;
  1402. uint32_t code:4;
  1403. uint32_t resvd:3;
  1404. uint32_t virt_idx:5;
  1405. uint32_t err_type:4;
  1406. uint32_t ee:4;
  1407. };
  1408. enum gsi_ch_cmd_opcode {
  1409. GSI_CH_ALLOCATE = 0x0,
  1410. GSI_CH_START = 0x1,
  1411. GSI_CH_STOP = 0x2,
  1412. GSI_CH_RESET = 0x9,
  1413. GSI_CH_DE_ALLOC = 0xa,
  1414. GSI_CH_DB_STOP = 0xb,
  1415. };
  1416. enum gsi_evt_ch_cmd_opcode {
  1417. GSI_EVT_ALLOCATE = 0x0,
  1418. GSI_EVT_RESET = 0x9,
  1419. GSI_EVT_DE_ALLOC = 0xa,
  1420. };
  1421. enum gsi_generic_ee_cmd_opcode {
  1422. GSI_GEN_EE_CMD_HALT_CHANNEL = 0x1,
  1423. GSI_GEN_EE_CMD_ALLOC_CHANNEL = 0x2,
  1424. GSI_GEN_EE_CMD_ENABLE_FLOW_CHANNEL = 0x3,
  1425. GSI_GEN_EE_CMD_DISABLE_FLOW_CHANNEL = 0x4,
  1426. };
  1427. enum gsi_generic_ee_cmd_return_code {
  1428. GSI_GEN_EE_CMD_RETURN_CODE_SUCCESS = 0x1,
  1429. GSI_GEN_EE_CMD_RETURN_CODE_CHANNEL_NOT_RUNNING = 0x2,
  1430. GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_DIRECTION = 0x3,
  1431. GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_CHANNEL_TYPE = 0x4,
  1432. GSI_GEN_EE_CMD_RETURN_CODE_INCORRECT_CHANNEL_INDEX = 0x5,
  1433. GSI_GEN_EE_CMD_RETURN_CODE_RETRY = 0x6,
  1434. GSI_GEN_EE_CMD_RETURN_CODE_OUT_OF_RESOURCES = 0x7,
  1435. };
  1436. extern struct gsi_ctx *gsi_ctx;
  1437. /**
  1438. * gsi_xfer_elem - Metadata about a single transfer
  1439. *
  1440. * @addr: physical address of buffer
  1441. * @len: size of buffer for GSI_XFER_ELEM_DATA:
  1442. * for outbound transfers this is the number of bytes to
  1443. * transfer.
  1444. * for inbound transfers, this is the maximum number of
  1445. * bytes the host expects from device in this transfer
  1446. *
  1447. * immediate command opcode for GSI_XFER_ELEM_IMME_CMD
  1448. * @flags: transfer flags, OR of all the applicable flags
  1449. *
  1450. * GSI_XFER_FLAG_BEI: Block event interrupt
  1451. * 1: Event generated by this ring element must not assert
  1452. * an interrupt to the host
  1453. * 0: Event generated by this ring element must assert an
  1454. * interrupt to the host
  1455. *
  1456. * GSI_XFER_FLAG_EOT: Interrupt on end of transfer
  1457. * 1: If an EOT condition is encountered when processing
  1458. * this ring element, an event is generated by the device
  1459. * with its completion code set to EOT.
  1460. * 0: If an EOT condition is encountered for this ring
  1461. * element, a completion event is not be generated by the
  1462. * device, unless IEOB is 1
  1463. *
  1464. * GSI_XFER_FLAG_EOB: Interrupt on end of block
  1465. * 1: Device notifies host after processing this ring element
  1466. * by sending a completion event
  1467. * 0: Completion event is not required after processing this
  1468. * ring element
  1469. *
  1470. * GSI_XFER_FLAG_CHAIN: Chain bit that identifies the ring
  1471. * elements in a TD
  1472. *
  1473. * @type: transfer type
  1474. *
  1475. * GSI_XFER_ELEM_DATA: for all data transfers
  1476. * GSI_XFER_ELEM_IMME_CMD: for IPA immediate commands
  1477. * GSI_XFER_ELEM_NOP: for event generation only
  1478. *
  1479. * @xfer_user_data: cookie used in xfer_cb
  1480. *
  1481. */
  1482. struct gsi_xfer_elem {
  1483. uint64_t addr;
  1484. uint16_t len;
  1485. uint16_t flags;
  1486. enum gsi_xfer_elem_type type;
  1487. void *xfer_user_data;
  1488. };
  1489. /**
  1490. * gsi_alloc_evt_ring - Peripheral should call this function to
  1491. * allocate an event ring
  1492. *
  1493. * @props: Event ring properties
  1494. * @dev_hdl: Client handle previously obtained from
  1495. * gsi_register_device
  1496. * @evt_ring_hdl: Handle populated by GSI, opaque to client
  1497. *
  1498. * This function can sleep
  1499. *
  1500. * @Return gsi_status
  1501. */
  1502. int gsi_alloc_evt_ring(struct gsi_evt_ring_props *props, unsigned long dev_hdl,
  1503. unsigned long *evt_ring_hdl);
  1504. /**
  1505. * gsi_dealloc_evt_ring - Peripheral should call this function to
  1506. * de-allocate an event ring. There should not exist any active
  1507. * channels using this event ring
  1508. *
  1509. * @evt_ring_hdl: Client handle previously obtained from
  1510. * gsi_alloc_evt_ring
  1511. *
  1512. * This function can sleep
  1513. *
  1514. * @Return gsi_status
  1515. */
  1516. int gsi_dealloc_evt_ring(unsigned long evt_ring_hdl);
  1517. /**
  1518. * gsi_alloc_channel - Peripheral should call this function to
  1519. * allocate a channel
  1520. *
  1521. * @props: Channel properties
  1522. * @dev_hdl: Client handle previously obtained from
  1523. * gsi_register_device
  1524. * @chan_hdl: Handle populated by GSI, opaque to client
  1525. *
  1526. * This function can sleep
  1527. *
  1528. * @Return gsi_status
  1529. */
  1530. int gsi_alloc_channel(struct gsi_chan_props *props, unsigned long dev_hdl,
  1531. unsigned long *chan_hdl);
  1532. /**
  1533. * gsi_start_channel - Peripheral should call this function to
  1534. * start a channel i.e put into running state
  1535. *
  1536. * @chan_hdl: Client handle previously obtained from
  1537. * gsi_alloc_channel
  1538. *
  1539. * This function can sleep
  1540. *
  1541. * @Return gsi_status
  1542. */
  1543. int gsi_start_channel(unsigned long chan_hdl);
  1544. /**
  1545. * gsi_reset_channel - Peripheral should call this function to
  1546. * reset a channel to recover from error state
  1547. *
  1548. * @chan_hdl: Client handle previously obtained from
  1549. * gsi_alloc_channel
  1550. *
  1551. * This function can sleep
  1552. *
  1553. * @Return gsi_status
  1554. */
  1555. int gsi_reset_channel(unsigned long chan_hdl);
  1556. /**
  1557. * gsi_dealloc_channel - Peripheral should call this function to
  1558. * de-allocate a channel
  1559. *
  1560. * @chan_hdl: Client handle previously obtained from
  1561. * gsi_alloc_channel
  1562. *
  1563. * This function can sleep
  1564. *
  1565. * @Return gsi_status
  1566. */
  1567. int gsi_dealloc_channel(unsigned long chan_hdl);
  1568. /**
  1569. * gsi_poll_channel - Peripheral should call this function to query for
  1570. * completed transfer descriptors.
  1571. *
  1572. * @chan_hdl: Client handle previously obtained from
  1573. * gsi_alloc_channel
  1574. * @notify: Information about the completed transfer if any
  1575. *
  1576. * @Return gsi_status (GSI_STATUS_POLL_EMPTY is returned if no transfers
  1577. * completed)
  1578. */
  1579. int gsi_poll_channel(unsigned long chan_hdl,
  1580. struct gsi_chan_xfer_notify *notify);
  1581. /**
  1582. * gsi_config_channel_mode - Peripheral should call this function
  1583. * to configure the channel mode.
  1584. *
  1585. * @chan_hdl: Client handle previously obtained from
  1586. * gsi_alloc_channel
  1587. * @mode: Mode to move the channel into
  1588. *
  1589. * @Return gsi_status
  1590. */
  1591. int gsi_config_channel_mode(unsigned long chan_hdl, enum gsi_chan_mode mode);
  1592. /**
  1593. * gsi_queue_xfer - Peripheral should call this function
  1594. * to queue transfers on the given channel
  1595. *
  1596. * @chan_hdl: Client handle previously obtained from
  1597. * gsi_alloc_channel
  1598. * @num_xfers: Number of transfer in the array @ xfer
  1599. * @xfer: Array of num_xfers transfer descriptors
  1600. * @ring_db: If true, tell HW about these queued xfers
  1601. * If false, do not notify HW at this time
  1602. *
  1603. * @Return gsi_status
  1604. */
  1605. int gsi_queue_xfer(unsigned long chan_hdl, uint16_t num_xfers,
  1606. struct gsi_xfer_elem *xfer, bool ring_db);
  1607. void gsi_debugfs_init(void);
  1608. uint16_t gsi_find_idx_from_addr(struct gsi_ring_ctx *ctx, uint64_t addr);
  1609. void gsi_update_ch_dp_stats(struct gsi_chan_ctx *ctx, uint16_t used);
  1610. /**
  1611. * gsi_register_device - Peripheral should call this function to
  1612. * register itself with GSI before invoking any other APIs
  1613. *
  1614. * @props: Peripheral properties
  1615. * @dev_hdl: Handle populated by GSI, opaque to client
  1616. *
  1617. * @Return -GSI_STATUS_AGAIN if request should be re-tried later
  1618. * other error codes for failure
  1619. */
  1620. int gsi_register_device(struct gsi_per_props *props, unsigned long *dev_hdl);
  1621. /**
  1622. * gsi_complete_clk_grant - Peripheral should call this function to
  1623. * grant the clock resource requested by GSI previously that could not
  1624. * be granted synchronously. GSI will release the clock resource using
  1625. * the rel_clk_cb when appropriate
  1626. *
  1627. * @dev_hdl: Client handle previously obtained from
  1628. * gsi_register_device
  1629. *
  1630. * @Return gsi_status
  1631. */
  1632. int gsi_complete_clk_grant(unsigned long dev_hdl);
  1633. /**
  1634. * gsi_write_device_scratch - Peripheral should call this function to
  1635. * write to the EE scratch area
  1636. *
  1637. * @dev_hdl: Client handle previously obtained from
  1638. * gsi_register_device
  1639. * @val: Value to write
  1640. *
  1641. * @Return gsi_status
  1642. */
  1643. int gsi_write_device_scratch(unsigned long dev_hdl,
  1644. struct gsi_device_scratch *val);
  1645. /**
  1646. * gsi_deregister_device - Peripheral should call this function to
  1647. * de-register itself with GSI
  1648. *
  1649. * @dev_hdl: Client handle previously obtained from
  1650. * gsi_register_device
  1651. * @force: When set to true, cleanup is performed even if there
  1652. * are in use resources like channels, event rings, etc.
  1653. * this would be used after GSI reset to recover from some
  1654. * fatal error
  1655. * When set to false, there must not exist any allocated
  1656. * channels and event rings.
  1657. *
  1658. * @Return gsi_status
  1659. */
  1660. int gsi_deregister_device(unsigned long dev_hdl, bool force);
  1661. /**
  1662. * gsi_write_evt_ring_scratch - Peripheral should call this function to
  1663. * write to the scratch area of the event ring context
  1664. *
  1665. * @evt_ring_hdl: Client handle previously obtained from
  1666. * gsi_alloc_evt_ring
  1667. * @val: Value to write
  1668. *
  1669. * @Return gsi_status
  1670. */
  1671. int gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
  1672. union __packed gsi_evt_scratch val);
  1673. /**
  1674. * gsi_query_evt_ring_db_addr - Peripheral should call this function to
  1675. * query the physical addresses of the event ring doorbell registers
  1676. *
  1677. * @evt_ring_hdl: Client handle previously obtained from
  1678. * gsi_alloc_evt_ring
  1679. * @db_addr_wp_lsb: Physical address of doorbell register where the 32
  1680. * LSBs of the doorbell value should be written
  1681. * @db_addr_wp_msb: Physical address of doorbell register where the 32
  1682. * MSBs of the doorbell value should be written
  1683. *
  1684. * @Return gsi_status
  1685. */
  1686. int gsi_query_evt_ring_db_addr(unsigned long evt_ring_hdl,
  1687. uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
  1688. /**
  1689. * gsi_ring_evt_ring_db - Peripheral should call this function for
  1690. * ringing the event ring doorbell with given value
  1691. *
  1692. * @evt_ring_hdl: Client handle previously obtained from
  1693. * gsi_alloc_evt_ring
  1694. * @value: The value to be used for ringing the doorbell
  1695. *
  1696. * @Return gsi_status
  1697. */
  1698. int gsi_ring_evt_ring_db(unsigned long evt_ring_hdl, uint64_t value);
  1699. /**
  1700. * gsi_ring_ch_ring_db - Peripheral should call this function for
  1701. * ringing the channel ring doorbell with given value
  1702. *
  1703. * @chan_hdl: Client handle previously obtained from
  1704. * gsi_alloc_channel
  1705. * @value: The value to be used for ringing the doorbell
  1706. *
  1707. * @Return gsi_status
  1708. */
  1709. int gsi_ring_ch_ring_db(unsigned long chan_hdl, uint64_t value);
  1710. /**
  1711. * gsi_reset_evt_ring - Peripheral should call this function to
  1712. * reset an event ring to recover from error state
  1713. *
  1714. * @evt_ring_hdl: Client handle previously obtained from
  1715. * gsi_alloc_evt_ring
  1716. *
  1717. * This function can sleep
  1718. *
  1719. * @Return gsi_status
  1720. */
  1721. int gsi_reset_evt_ring(unsigned long evt_ring_hdl);
  1722. /**
  1723. * gsi_get_evt_ring_cfg - This function returns the current config
  1724. * of the specified event ring
  1725. *
  1726. * @evt_ring_hdl: Client handle previously obtained from
  1727. * gsi_alloc_evt_ring
  1728. * @props: where to copy properties to
  1729. * @scr: where to copy scratch info to
  1730. *
  1731. * @Return gsi_status
  1732. */
  1733. int gsi_get_evt_ring_cfg(unsigned long evt_ring_hdl,
  1734. struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
  1735. /**
  1736. * gsi_set_evt_ring_cfg - This function applies the supplied config
  1737. * to the specified event ring.
  1738. *
  1739. * exclusive property of the event ring cannot be changed after
  1740. * gsi_alloc_evt_ring
  1741. *
  1742. * @evt_ring_hdl: Client handle previously obtained from
  1743. * gsi_alloc_evt_ring
  1744. * @props: the properties to apply
  1745. * @scr: the scratch info to apply
  1746. *
  1747. * @Return gsi_status
  1748. */
  1749. int gsi_set_evt_ring_cfg(unsigned long evt_ring_hdl,
  1750. struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
  1751. /**
  1752. * gsi_write_channel_scratch - Peripheral should call this function to
  1753. * write to the scratch area of the channel context
  1754. *
  1755. * @chan_hdl: Client handle previously obtained from
  1756. * gsi_alloc_channel
  1757. * @val: Value to write
  1758. *
  1759. * @Return gsi_status
  1760. */
  1761. int gsi_write_channel_scratch(unsigned long chan_hdl,
  1762. union __packed gsi_channel_scratch val);
  1763. /**
  1764. * gsi_write_channel_scratch3_reg - Peripheral should call this function to
  1765. * write to the scratch3 reg area of the channel context
  1766. *
  1767. * @chan_hdl: Client handle previously obtained from
  1768. * gsi_alloc_channel
  1769. * @val: Value to write
  1770. *
  1771. * @Return gsi_status
  1772. */
  1773. int gsi_write_channel_scratch3_reg(unsigned long chan_hdl,
  1774. union __packed gsi_wdi_channel_scratch3_reg val);
  1775. /**
  1776. * gsi_write_channel_scratch2_reg - Peripheral should call this function to
  1777. * write to the scratch2 reg area of the channel context
  1778. *
  1779. * @chan_hdl: Client handle previously obtained from
  1780. * gsi_alloc_channel
  1781. * @val: Value to write
  1782. *
  1783. * @Return gsi_status
  1784. */
  1785. int gsi_write_channel_scratch2_reg(unsigned long chan_hdl,
  1786. union __packed gsi_wdi2_channel_scratch2_reg val);
  1787. /**
  1788. * gsi_write_wdi3_channel_scratch2_reg - Peripheral should call this function
  1789. * to write to the WDI3 scratch 3 register area of the channel context
  1790. *
  1791. * @chan_hdl: Client handle previously obtained from
  1792. * gsi_alloc_channel
  1793. * @val: Read value
  1794. *
  1795. * @Return gsi_status
  1796. */
  1797. int gsi_write_wdi3_channel_scratch2_reg(unsigned long chan_hdl,
  1798. union __packed gsi_wdi3_channel_scratch2_reg val);
  1799. /**
  1800. * gsi_read_channel_scratch - Peripheral should call this function to
  1801. * read to the scratch area of the channel context
  1802. *
  1803. * @chan_hdl: Client handle previously obtained from
  1804. * gsi_alloc_channel
  1805. * @val: Read value
  1806. *
  1807. * @Return gsi_status
  1808. */
  1809. int gsi_read_channel_scratch(unsigned long chan_hdl,
  1810. union __packed gsi_channel_scratch *val);
  1811. /**
  1812. * gsi_read_wdi3_channel_scratch2_reg - Peripheral should call this function to
  1813. * read to the WDI3 scratch 2 register area of the channel context
  1814. *
  1815. * @chan_hdl: Client handle previously obtained from
  1816. * gsi_alloc_channel
  1817. * @val: Read value
  1818. *
  1819. * @Return gsi_status
  1820. */
  1821. int gsi_read_wdi3_channel_scratch2_reg(unsigned long chan_hdl,
  1822. union __packed gsi_wdi3_channel_scratch2_reg *val);
  1823. /*
  1824. * gsi_pending_irq_type - Peripheral should call this function to
  1825. * check if there is any pending irq
  1826. *
  1827. * This function can sleep
  1828. *
  1829. * @Return gsi_irq_type
  1830. */
  1831. int gsi_pending_irq_type(void);
  1832. /**
  1833. * gsi_update_mhi_channel_scratch - MHI Peripheral should call this
  1834. * function to update the scratch area of the channel context. Updating
  1835. * will be by read-modify-write method, so non SWI fields will not be
  1836. * affected
  1837. *
  1838. * @chan_hdl: Client handle previously obtained from
  1839. * gsi_alloc_channel
  1840. * @mscr: MHI Channel Scratch value
  1841. *
  1842. * @Return gsi_status
  1843. */
  1844. int gsi_update_mhi_channel_scratch(unsigned long chan_hdl,
  1845. struct __packed gsi_mhi_channel_scratch mscr);
  1846. /**
  1847. * gsi_stop_channel - Peripheral should call this function to
  1848. * stop a channel. Stop will happen on a packet boundary
  1849. *
  1850. * @chan_hdl: Client handle previously obtained from
  1851. * gsi_alloc_channel
  1852. *
  1853. * This function can sleep
  1854. *
  1855. * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
  1856. * other error codes for failure
  1857. */
  1858. int gsi_stop_channel(unsigned long chan_hdl);
  1859. /**
  1860. * gsi_stop_db_channel - Peripheral should call this function to
  1861. * stop a channel when all transfer elements till the doorbell
  1862. * have been processed
  1863. *
  1864. * @chan_hdl: Client handle previously obtained from
  1865. * gsi_alloc_channel
  1866. *
  1867. * This function can sleep
  1868. *
  1869. * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
  1870. * other error codes for failure
  1871. */
  1872. int gsi_stop_db_channel(unsigned long chan_hdl);
  1873. /**
  1874. * gsi_query_channel_db_addr - Peripheral should call this function to
  1875. * query the physical addresses of the channel doorbell registers
  1876. *
  1877. * @chan_hdl: Client handle previously obtained from
  1878. * gsi_alloc_channel
  1879. * @db_addr_wp_lsb: Physical address of doorbell register where the 32
  1880. * LSBs of the doorbell value should be written
  1881. * @db_addr_wp_msb: Physical address of doorbell register where the 32
  1882. * MSBs of the doorbell value should be written
  1883. *
  1884. * @Return gsi_status
  1885. */
  1886. int gsi_query_channel_db_addr(unsigned long chan_hdl,
  1887. uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
  1888. /**
  1889. * gsi_query_channel_info - Peripheral can call this function to query the
  1890. * channel and associated event ring (if any) status.
  1891. *
  1892. * @chan_hdl: Client handle previously obtained from
  1893. * gsi_alloc_channel
  1894. * @info: Where to read the values into
  1895. *
  1896. * @Return gsi_status
  1897. */
  1898. int gsi_query_channel_info(unsigned long chan_hdl,
  1899. struct gsi_chan_info *info);
  1900. /**
  1901. * gsi_is_channel_empty - Peripheral can call this function to query if
  1902. * the channel is empty. This is only applicable to GPI. "Empty" means
  1903. * GSI has consumed all descriptors for a TO_GSI channel and SW has
  1904. * processed all completed descriptors for a FROM_GSI channel.
  1905. *
  1906. * @chan_hdl: Client handle previously obtained from gsi_alloc_channel
  1907. * @is_empty: set by GSI based on channel emptiness
  1908. *
  1909. * @Return gsi_status
  1910. */
  1911. int gsi_is_channel_empty(unsigned long chan_hdl, bool *is_empty);
  1912. /**
  1913. * gsi_get_channel_cfg - This function returns the current config
  1914. * of the specified channel
  1915. *
  1916. * @chan_hdl: Client handle previously obtained from
  1917. * gsi_alloc_channel
  1918. * @props: where to copy properties to
  1919. * @scr: where to copy scratch info to
  1920. *
  1921. * @Return gsi_status
  1922. */
  1923. int gsi_get_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
  1924. union gsi_channel_scratch *scr);
  1925. /**
  1926. * gsi_set_channel_cfg - This function applies the supplied config
  1927. * to the specified channel
  1928. *
  1929. * ch_id and evt_ring_hdl of the channel cannot be changed after
  1930. * gsi_alloc_channel
  1931. *
  1932. * @chan_hdl: Client handle previously obtained from
  1933. * gsi_alloc_channel
  1934. * @props: the properties to apply
  1935. * @scr: the scratch info to apply
  1936. *
  1937. * @Return gsi_status
  1938. */
  1939. int gsi_set_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
  1940. union gsi_channel_scratch *scr);
  1941. /**
  1942. * gsi_poll_n_channel - Peripheral should call this function to query for
  1943. * completed transfer descriptors.
  1944. *
  1945. * @chan_hdl: Client handle previously obtained from
  1946. * gsi_alloc_channel
  1947. * @notify: Information about the completed transfer if any
  1948. * @expected_num: Number of descriptor we want to poll each time.
  1949. * @actual_num: Actual number of descriptor we polled successfully.
  1950. *
  1951. * @Return gsi_status (GSI_STATUS_POLL_EMPTY is returned if no transfers
  1952. * completed)
  1953. */
  1954. int gsi_poll_n_channel(unsigned long chan_hdl,
  1955. struct gsi_chan_xfer_notify *notify,
  1956. int expected_num, int *actual_num);
  1957. /**
  1958. * gsi_start_xfer - Peripheral should call this function to
  1959. * inform HW about queued xfers
  1960. *
  1961. * @chan_hdl: Client handle previously obtained from
  1962. * gsi_alloc_channel
  1963. *
  1964. * @Return gsi_status
  1965. */
  1966. int gsi_start_xfer(unsigned long chan_hdl);
  1967. /**
  1968. * gsi_configure_regs - Peripheral should call this function
  1969. * to configure the GSI registers before/after the FW is
  1970. * loaded but before it is enabled.
  1971. *
  1972. * @per_base_addr: Base address of the peripheral using GSI
  1973. * @ver: GSI core version
  1974. *
  1975. * @Return gsi_status
  1976. */
  1977. int gsi_configure_regs(phys_addr_t per_base_addr, enum gsi_ver ver);
  1978. /**
  1979. * gsi_enable_fw - Peripheral should call this function
  1980. * to enable the GSI FW after the FW has been loaded to the SRAM.
  1981. *
  1982. * @gsi_base_addr: Base address of GSI register space
  1983. * @gsi_size: Mapping size of the GSI register space
  1984. * @ver: GSI core version
  1985. * @Return gsi_status
  1986. */
  1987. int gsi_enable_fw(phys_addr_t gsi_base_addr, u32 gsi_size, enum gsi_ver ver);
  1988. /**
  1989. * gsi_get_inst_ram_offset_and_size - Peripheral should call this function
  1990. * to get instruction RAM base address offset and size. Peripheral typically
  1991. * uses this info to load GSI FW into the IRAM.
  1992. *
  1993. * @base_offset:[OUT] - IRAM base offset address
  1994. * @size: [OUT] - IRAM size
  1995. * @ver: GSI core version
  1996. * @Return none
  1997. */
  1998. void gsi_get_inst_ram_offset_and_size(unsigned long *base_offset,
  1999. unsigned long *size, enum gsi_ver ver);
  2000. /**
  2001. * gsi_halt_channel_ee - Peripheral should call this function
  2002. * to stop other EE's channel. This is usually used in SSR clean
  2003. *
  2004. * @chan_idx: Virtual channel index
  2005. * @ee: EE
  2006. * @code: [out] response code for operation
  2007. * @Return gsi_status
  2008. */
  2009. int gsi_halt_channel_ee(unsigned int chan_idx, unsigned int ee, int *code);
  2010. /**
  2011. * gsi_wdi3_write_evt_ring_db - write event ring doorbell address
  2012. *
  2013. * @chan_hdl: gsi channel handle
  2014. * @Return gsi_status
  2015. */
  2016. void gsi_wdi3_write_evt_ring_db(unsigned long chan_hdl, uint32_t db_addr_low,
  2017. uint32_t db_addr_high);
  2018. /**
  2019. * gsi_get_refetch_reg - get WP/RP value from re_fetch register
  2020. *
  2021. * @chan_hdl: gsi channel handle
  2022. * @is_rp: rp or wp
  2023. */
  2024. int gsi_get_refetch_reg(unsigned long chan_hdl, bool is_rp);
  2025. /**
  2026. * gsi_get_drop_stats - get drop stats by GSI
  2027. *
  2028. * @ep_id: ep index
  2029. * @scratch_id: drop stats on which scratch register
  2030. */
  2031. int gsi_get_drop_stats(unsigned long ep_id, int scratch_id);
  2032. /**
  2033. * gsi_wdi3_dump_register - dump wdi3 related gsi registers
  2034. *
  2035. * @chan_hdl: gsi channel handle
  2036. */
  2037. void gsi_wdi3_dump_register(unsigned long chan_hdl);
  2038. /**
  2039. * gsi_map_base - Peripheral should call this function to configure
  2040. * access to the GSI registers.
  2041. * @gsi_base_addr: Base address of GSI register space
  2042. * @gsi_size: Mapping size of the GSI register space
  2043. * @ver: The appropriate GSI version enum
  2044. *
  2045. * @Return gsi_status
  2046. */
  2047. int gsi_map_base(phys_addr_t gsi_base_addr, u32 gsi_size, enum gsi_ver ver);
  2048. /**
  2049. * gsi_unmap_base - Peripheral should call this function to undo the
  2050. * effects of gsi_map_base
  2051. *
  2052. * @Return gsi_status
  2053. */
  2054. int gsi_unmap_base(void);
  2055. /**
  2056. * gsi_map_virtual_ch_to_per_ep - Peripheral should call this function
  2057. * to configure each GSI virtual channel with the per endpoint index.
  2058. *
  2059. * @ee: The ee to be used
  2060. * @chan_num: The channel to be used
  2061. * @per_ep_index: value to assign
  2062. *
  2063. * @Return gsi_status
  2064. */
  2065. int gsi_map_virtual_ch_to_per_ep(u32 ee, u32 chan_num, u32 per_ep_index);
  2066. /**
  2067. * gsi_alloc_channel_ee - Peripheral should call this function
  2068. * to alloc other EE's channel. This is usually done in bootup to allocate all
  2069. * chnnels.
  2070. *
  2071. * @chan_idx: Virtual channel index
  2072. * @ee: EE
  2073. * @code: [out] response code for operation
  2074. * @Return gsi_status
  2075. */
  2076. int gsi_alloc_channel_ee(unsigned int chan_idx, unsigned int ee, int *code);
  2077. /**
  2078. * gsi_enable_flow_control_ee - Peripheral should call this function
  2079. * to enable flow control other EE's channel. This is usually done in USB
  2080. * connent and SSR scenarios.
  2081. *
  2082. * @chan_idx: Virtual channel index
  2083. * @ee: EE
  2084. * @code: [out] response code for operation
  2085. * @Return gsi_status
  2086. */
  2087. int gsi_enable_flow_control_ee(unsigned int chan_idx, unsigned int ee,
  2088. int *code);
  2089. /**
  2090. * gsi_query_aqc_msi_addr - get aqc channel msi address
  2091. *
  2092. * @chan_id: channel id
  2093. * @addr: [out] aqc channel msi address
  2094. *
  2095. * @Return gsi_status
  2096. */
  2097. int gsi_query_aqc_msi_addr(unsigned long chan_hdl, u32 *addr);
  2098. /*
  2099. * Here is a typical sequence of calls
  2100. *
  2101. * gsi_register_device
  2102. *
  2103. * gsi_write_device_scratch (if the protocol needs this)
  2104. *
  2105. * gsi_alloc_evt_ring (for as many event rings as needed)
  2106. * gsi_write_evt_ring_scratch
  2107. *
  2108. * gsi_alloc_channel (for as many channels as needed; channels can have
  2109. * no event ring, an exclusive event ring or a shared event ring)
  2110. * gsi_write_channel_scratch
  2111. * gsi_read_channel_scratch
  2112. * gsi_start_channel
  2113. * gsi_queue_xfer/gsi_start_xfer
  2114. * gsi_config_channel_mode/gsi_poll_channel (if clients wants to poll on
  2115. * xfer completions)
  2116. * gsi_stop_db_channel/gsi_stop_channel
  2117. *
  2118. * gsi_dealloc_channel
  2119. *
  2120. * gsi_dealloc_evt_ring
  2121. *
  2122. * gsi_deregister_device
  2123. *
  2124. */
  2125. #endif