gsi.h 80 KB

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