gsi.h 65 KB

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