blob: f5d2f72277c5c860b788057ff5d732d7a7c18af7 [file] [log] [blame]
Ghanim Fodi37b64952017-01-24 15:42:30 +02001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Amir Levycdccd632016-10-30 09:36:41 +02002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#ifndef MSM_GSI_H
13#define MSM_GSI_H
14#include <linux/types.h>
15
Amir Levy41644242016-11-03 15:38:09 +020016enum gsi_ver {
17 GSI_VER_ERR = 0,
18 GSI_VER_1_0 = 1,
19 GSI_VER_1_2 = 2,
20 GSI_VER_1_3 = 3,
21 GSI_VER_MAX,
22};
23
Amir Levycdccd632016-10-30 09:36:41 +020024enum gsi_status {
25 GSI_STATUS_SUCCESS = 0,
26 GSI_STATUS_ERROR = 1,
27 GSI_STATUS_RING_INSUFFICIENT_SPACE = 2,
28 GSI_STATUS_RING_EMPTY = 3,
29 GSI_STATUS_RES_ALLOC_FAILURE = 4,
30 GSI_STATUS_BAD_STATE = 5,
31 GSI_STATUS_INVALID_PARAMS = 6,
32 GSI_STATUS_UNSUPPORTED_OP = 7,
33 GSI_STATUS_NODEV = 8,
34 GSI_STATUS_POLL_EMPTY = 9,
35 GSI_STATUS_EVT_RING_INCOMPATIBLE = 10,
36 GSI_STATUS_TIMED_OUT = 11,
37 GSI_STATUS_AGAIN = 12,
38};
39
40enum gsi_per_evt {
41 GSI_PER_EVT_GLOB_ERROR,
42 GSI_PER_EVT_GLOB_GP1,
43 GSI_PER_EVT_GLOB_GP2,
44 GSI_PER_EVT_GLOB_GP3,
45 GSI_PER_EVT_GENERAL_BREAK_POINT,
46 GSI_PER_EVT_GENERAL_BUS_ERROR,
47 GSI_PER_EVT_GENERAL_CMD_FIFO_OVERFLOW,
48 GSI_PER_EVT_GENERAL_MCS_STACK_OVERFLOW,
49};
50
51/**
52 * gsi_per_notify - Peripheral callback info
53 *
54 * @user_data: cookie supplied in gsi_register_device
55 * @evt_id: type of notification
56 * @err_desc: error related information
57 *
58 */
59struct gsi_per_notify {
60 void *user_data;
61 enum gsi_per_evt evt_id;
62 union {
63 uint16_t err_desc;
64 } data;
65};
66
67enum gsi_intr_type {
68 GSI_INTR_MSI = 0x0,
69 GSI_INTR_IRQ = 0x1
70};
71
72
73/**
74 * gsi_per_props - Peripheral related properties
75 *
Amir Levy41644242016-11-03 15:38:09 +020076 * @gsi: GSI core version
Amir Levycdccd632016-10-30 09:36:41 +020077 * @ee: EE where this driver and peripheral driver runs
78 * @intr: control interrupt type
79 * @intvec: write data for MSI write
80 * @msi_addr: MSI address
81 * @irq: IRQ number
82 * @phys_addr: physical address of GSI block
83 * @size: register size of GSI block
84 * @notify_cb: general notification callback
85 * @req_clk_cb: callback to request peripheral clock
86 * granted should be set to true if request is completed
87 * synchronously, false otherwise (peripheral needs
88 * to call gsi_complete_clk_grant later when request is
89 * completed)
90 * if this callback is not provided, then GSI will assume
91 * peripheral is clocked at all times
92 * @rel_clk_cb: callback to release peripheral clock
93 * @user_data: cookie used for notifications
94 *
95 * All the callbacks are in interrupt context
96 *
97 */
98struct gsi_per_props {
Amir Levy41644242016-11-03 15:38:09 +020099 enum gsi_ver ver;
Amir Levycdccd632016-10-30 09:36:41 +0200100 unsigned int ee;
101 enum gsi_intr_type intr;
102 uint32_t intvec;
103 uint64_t msi_addr;
104 unsigned int irq;
105 phys_addr_t phys_addr;
106 unsigned long size;
107 void (*notify_cb)(struct gsi_per_notify *notify);
108 void (*req_clk_cb)(void *user_data, bool *granted);
109 int (*rel_clk_cb)(void *user_data);
110 void *user_data;
111};
112
113enum gsi_evt_err {
114 GSI_EVT_OUT_OF_BUFFERS_ERR = 0x0,
115 GSI_EVT_OUT_OF_RESOURCES_ERR = 0x1,
116 GSI_EVT_UNSUPPORTED_INTER_EE_OP_ERR = 0x2,
117 GSI_EVT_EVT_RING_EMPTY_ERR = 0x3,
118};
119
120/**
121 * gsi_evt_err_notify - event ring error callback info
122 *
123 * @user_data: cookie supplied in gsi_alloc_evt_ring
124 * @evt_id: type of error
125 * @err_desc: more info about the error
126 *
127 */
128struct gsi_evt_err_notify {
129 void *user_data;
130 enum gsi_evt_err evt_id;
131 uint16_t err_desc;
132};
133
134enum gsi_evt_chtype {
135 GSI_EVT_CHTYPE_MHI_EV = 0x0,
136 GSI_EVT_CHTYPE_XHCI_EV = 0x1,
137 GSI_EVT_CHTYPE_GPI_EV = 0x2,
138 GSI_EVT_CHTYPE_XDCI_EV = 0x3
139};
140
141enum gsi_evt_ring_elem_size {
142 GSI_EVT_RING_RE_SIZE_4B = 4,
143 GSI_EVT_RING_RE_SIZE_16B = 16,
144};
145
146/**
147 * gsi_evt_ring_props - Event ring related properties
148 *
149 * @intf: interface type (of the associated channel)
150 * @intr: interrupt type
151 * @re_size: size of event ring element
152 * @ring_len: length of ring in bytes (must be integral multiple of
153 * re_size)
154 * @ring_base_addr: physical base address of ring. Address must be aligned to
155 * ring_len rounded to power of two
156 * @ring_base_vaddr: virtual base address of ring (set to NULL when not
157 * applicable)
158 * @int_modt: cycles base interrupt moderation (32KHz clock)
159 * @int_modc: interrupt moderation packet counter
160 * @intvec: write data for MSI write
161 * @msi_addr: MSI address
162 * @rp_update_addr: physical address to which event read pointer should be
163 * written on every event generation. must be set to 0 when
164 * no update is desdired
165 * @exclusive: if true, only one GSI channel can be associated with this
166 * event ring. if false, the event ring can be shared among
167 * multiple GSI channels but in that case no polling
168 * (GSI_CHAN_MODE_POLL) is supported on any of those channels
169 * @err_cb: error notification callback
170 * @user_data: cookie used for error notifications
171 * @evchid_valid: is evchid valid?
172 * @evchid: the event ID that is being specifically requested (this is
173 * relevant for MHI where doorbell routing requires ERs to be
174 * physically contiguous)
175 */
176struct gsi_evt_ring_props {
177 enum gsi_evt_chtype intf;
178 enum gsi_intr_type intr;
179 enum gsi_evt_ring_elem_size re_size;
180 uint16_t ring_len;
181 uint64_t ring_base_addr;
182 void *ring_base_vaddr;
183 uint16_t int_modt;
184 uint8_t int_modc;
185 uint32_t intvec;
186 uint64_t msi_addr;
187 uint64_t rp_update_addr;
188 bool exclusive;
189 void (*err_cb)(struct gsi_evt_err_notify *notify);
190 void *user_data;
191 bool evchid_valid;
192 uint8_t evchid;
193};
194
195enum gsi_chan_mode {
196 GSI_CHAN_MODE_CALLBACK = 0x0,
197 GSI_CHAN_MODE_POLL = 0x1,
198};
199
200enum gsi_chan_prot {
201 GSI_CHAN_PROT_MHI = 0x0,
202 GSI_CHAN_PROT_XHCI = 0x1,
203 GSI_CHAN_PROT_GPI = 0x2,
204 GSI_CHAN_PROT_XDCI = 0x3
205};
206
207enum gsi_chan_dir {
208 GSI_CHAN_DIR_FROM_GSI = 0x0,
209 GSI_CHAN_DIR_TO_GSI = 0x1
210};
211
212enum gsi_max_prefetch {
213 GSI_ONE_PREFETCH_SEG = 0x0,
214 GSI_TWO_PREFETCH_SEG = 0x1
215};
216
217enum gsi_chan_evt {
218 GSI_CHAN_EVT_INVALID = 0x0,
219 GSI_CHAN_EVT_SUCCESS = 0x1,
220 GSI_CHAN_EVT_EOT = 0x2,
221 GSI_CHAN_EVT_OVERFLOW = 0x3,
222 GSI_CHAN_EVT_EOB = 0x4,
223 GSI_CHAN_EVT_OOB = 0x5,
224 GSI_CHAN_EVT_DB_MODE = 0x6,
225 GSI_CHAN_EVT_UNDEFINED = 0x10,
226 GSI_CHAN_EVT_RE_ERROR = 0x11,
227};
228
229/**
230 * gsi_chan_xfer_notify - Channel callback info
231 *
232 * @chan_user_data: cookie supplied in gsi_alloc_channel
233 * @xfer_user_data: cookie of the gsi_xfer_elem that caused the
234 * event to be generated
235 * @evt_id: type of event triggered by the associated TRE
236 * (corresponding to xfer_user_data)
237 * @bytes_xfered: number of bytes transferred by the associated TRE
238 * (corresponding to xfer_user_data)
239 *
240 */
241struct gsi_chan_xfer_notify {
242 void *chan_user_data;
243 void *xfer_user_data;
244 enum gsi_chan_evt evt_id;
245 uint16_t bytes_xfered;
246};
247
248enum gsi_chan_err {
249 GSI_CHAN_INVALID_TRE_ERR = 0x0,
250 GSI_CHAN_NON_ALLOCATED_EVT_ACCESS_ERR = 0x1,
251 GSI_CHAN_OUT_OF_BUFFERS_ERR = 0x2,
252 GSI_CHAN_OUT_OF_RESOURCES_ERR = 0x3,
253 GSI_CHAN_UNSUPPORTED_INTER_EE_OP_ERR = 0x4,
254 GSI_CHAN_HWO_1_ERR = 0x5
255};
256
257/**
258 * gsi_chan_err_notify - Channel general callback info
259 *
260 * @chan_user_data: cookie supplied in gsi_alloc_channel
261 * @evt_id: type of error
262 * @err_desc: more info about the error
263 *
264 */
265struct gsi_chan_err_notify {
266 void *chan_user_data;
267 enum gsi_chan_err evt_id;
268 uint16_t err_desc;
269};
270
271enum gsi_chan_ring_elem_size {
272 GSI_CHAN_RE_SIZE_4B = 4,
273 GSI_CHAN_RE_SIZE_16B = 16,
274 GSI_CHAN_RE_SIZE_32B = 32,
275};
276
277enum gsi_chan_use_db_eng {
278 GSI_CHAN_DIRECT_MODE = 0x0,
279 GSI_CHAN_DB_MODE = 0x1,
280};
281
282/**
283 * gsi_chan_props - Channel related properties
284 *
285 * @prot: interface type
286 * @dir: channel direction
287 * @ch_id: virtual channel ID
288 * @evt_ring_hdl: handle of associated event ring. set to ~0 if no
289 * event ring associated
290 * @re_size: size of channel ring element
291 * @ring_len: length of ring in bytes (must be integral multiple of
292 * re_size)
293 * @max_re_expected: maximal number of ring elements expected to be queued.
294 * used for data path statistics gathering. if 0 provided
295 * ring_len / re_size will be used.
296 * @ring_base_addr: physical base address of ring. Address must be aligned to
297 * ring_len rounded to power of two
298 * @ring_base_vaddr: virtual base address of ring (set to NULL when not
299 * applicable)
300 * @use_db_eng: 0 => direct mode (doorbells are written directly to RE
301 * engine)
302 * 1 => DB mode (doorbells are written to DB engine)
303 * @max_prefetch: limit number of pre-fetch segments for channel
304 * @low_weight: low channel weight (priority of channel for RE engine
305 * round robin algorithm); must be >= 1
306 * @xfer_cb: transfer notification callback, this callback happens
307 * on event boundaries
308 *
309 * e.g. 1
310 *
311 * out TD with 3 REs
312 *
313 * RE1: EOT=0, EOB=0, CHAIN=1;
314 * RE2: EOT=0, EOB=0, CHAIN=1;
315 * RE3: EOT=1, EOB=0, CHAIN=0;
316 *
317 * the callback will be triggered for RE3 using the
318 * xfer_user_data of that RE
319 *
320 * e.g. 2
321 *
322 * in REs
323 *
324 * RE1: EOT=1, EOB=0, CHAIN=0;
325 * RE2: EOT=1, EOB=0, CHAIN=0;
326 * RE3: EOT=1, EOB=0, CHAIN=0;
327 *
328 * received packet consumes all of RE1, RE2 and part of RE3
329 * for EOT condition. there will be three callbacks in below
330 * order
331 *
332 * callback for RE1 using GSI_CHAN_EVT_OVERFLOW
333 * callback for RE2 using GSI_CHAN_EVT_OVERFLOW
334 * callback for RE3 using GSI_CHAN_EVT_EOT
335 *
336 * @err_cb: error notification callback
337 * @chan_user_data: cookie used for notifications
338 *
339 * All the callbacks are in interrupt context
340 *
341 */
342struct gsi_chan_props {
343 enum gsi_chan_prot prot;
344 enum gsi_chan_dir dir;
345 uint8_t ch_id;
346 unsigned long evt_ring_hdl;
347 enum gsi_chan_ring_elem_size re_size;
348 uint16_t ring_len;
349 uint16_t max_re_expected;
350 uint64_t ring_base_addr;
351 void *ring_base_vaddr;
352 enum gsi_chan_use_db_eng use_db_eng;
353 enum gsi_max_prefetch max_prefetch;
354 uint8_t low_weight;
355 void (*xfer_cb)(struct gsi_chan_xfer_notify *notify);
356 void (*err_cb)(struct gsi_chan_err_notify *notify);
357 void *chan_user_data;
358};
359
360enum gsi_xfer_flag {
361 GSI_XFER_FLAG_CHAIN = 0x1,
362 GSI_XFER_FLAG_EOB = 0x100,
363 GSI_XFER_FLAG_EOT = 0x200,
364 GSI_XFER_FLAG_BEI = 0x400
365};
366
367enum gsi_xfer_elem_type {
368 GSI_XFER_ELEM_DATA,
369 GSI_XFER_ELEM_IMME_CMD,
Skylar Changa7975cf2017-03-21 17:20:20 -0700370 GSI_XFER_ELEM_NOP,
Amir Levycdccd632016-10-30 09:36:41 +0200371};
372
373/**
374 * gsi_xfer_elem - Metadata about a single transfer
375 *
376 * @addr: physical address of buffer
377 * @len: size of buffer for GSI_XFER_ELEM_DATA:
378 * for outbound transfers this is the number of bytes to
379 * transfer.
380 * for inbound transfers, this is the maximum number of
381 * bytes the host expects from device in this transfer
382 *
383 * immediate command opcode for GSI_XFER_ELEM_IMME_CMD
384 * @flags: transfer flags, OR of all the applicable flags
385 *
386 * GSI_XFER_FLAG_BEI: Block event interrupt
387 * 1: Event generated by this ring element must not assert
388 * an interrupt to the host
389 * 0: Event generated by this ring element must assert an
390 * interrupt to the host
391 *
392 * GSI_XFER_FLAG_EOT: Interrupt on end of transfer
393 * 1: If an EOT condition is encountered when processing
394 * this ring element, an event is generated by the device
395 * with its completion code set to EOT.
396 * 0: If an EOT condition is encountered for this ring
397 * element, a completion event is not be generated by the
398 * device, unless IEOB is 1
399 *
400 * GSI_XFER_FLAG_EOB: Interrupt on end of block
401 * 1: Device notifies host after processing this ring element
402 * by sending a completion event
403 * 0: Completion event is not required after processing this
404 * ring element
405 *
406 * GSI_XFER_FLAG_CHAIN: Chain bit that identifies the ring
407 * elements in a TD
408 *
409 * @type: transfer type
410 *
411 * GSI_XFER_ELEM_DATA: for all data transfers
412 * GSI_XFER_ELEM_IMME_CMD: for IPA immediate commands
Skylar Changa7975cf2017-03-21 17:20:20 -0700413 * GSI_XFER_ELEM_NOP: for event generation only
Amir Levycdccd632016-10-30 09:36:41 +0200414 *
415 * @xfer_user_data: cookie used in xfer_cb
416 *
417 */
418struct gsi_xfer_elem {
419 uint64_t addr;
420 uint16_t len;
421 uint16_t flags;
422 enum gsi_xfer_elem_type type;
423 void *xfer_user_data;
424};
425
426/**
427 * gsi_gpi_channel_scratch - GPI protocol SW config area of
428 * channel scratch
429 *
430 * @max_outstanding_tre: Used for the prefetch management sequence by the
431 * sequencer. Defines the maximum number of allowed
432 * outstanding TREs in IPA/GSI (in Bytes). RE engine
433 * prefetch will be limited by this configuration. It
434 * is suggested to configure this value to IPA_IF
435 * channel TLV queue size times element size. To disable
436 * the feature in doorbell mode (DB Mode=1). Maximum
437 * outstanding TREs should be set to 64KB
438 * (or any value larger or equal to ring length . RLEN)
439 * @outstanding_threshold: Used for the prefetch management sequence by the
440 * sequencer. Defines the threshold (in Bytes) as to when
441 * to update the channel doorbell. Should be smaller than
442 * Maximum outstanding TREs. value. It is suggested to
443 * configure this value to 2 * element size.
444 */
445struct __packed gsi_gpi_channel_scratch {
446 uint64_t resvd1;
447 uint32_t resvd2:16;
448 uint32_t max_outstanding_tre:16;
449 uint32_t resvd3:16;
450 uint32_t outstanding_threshold:16;
451};
452
453/**
454 * gsi_mhi_channel_scratch - MHI protocol SW config area of
455 * channel scratch
456 *
457 * @mhi_host_wp_addr: Valid only when UL/DL Sync En is asserted. Defines
458 * address in host from which channel write pointer
459 * should be read in polling mode
460 * @assert_bit40: 1: bit #41 in address should be asserted upon
461 * IPA_IF.ProcessDescriptor routine (for MHI over PCIe
462 * transfers)
463 * 0: bit #41 in address should be deasserted upon
464 * IPA_IF.ProcessDescriptor routine (for non-MHI over
465 * PCIe transfers)
466 * @polling_configuration: Uplink channels: Defines timer to poll on MHI
467 * context. Range: 1 to 31 milliseconds.
468 * Downlink channel: Defines transfer ring buffer
469 * availability threshold to poll on MHI context in
470 * multiple of 8. Range: 0 to 31, meaning 0 to 258 ring
471 * elements. E.g., value of 2 indicates 16 ring elements.
472 * Valid only when Burst Mode Enabled is set to 1
473 * @burst_mode_enabled: 0: Burst mode is disabled for this channel
474 * 1: Burst mode is enabled for this channel
475 * @polling_mode: 0: the channel is not in polling mode, meaning the
476 * host should ring DBs.
477 * 1: the channel is in polling mode, meaning the host
478 * @oob_mod_threshold: Defines OOB moderation threshold. Units are in 8
479 * ring elements.
480 * should not ring DBs until notified of DB mode/OOB mode
481 * @max_outstanding_tre: Used for the prefetch management sequence by the
482 * sequencer. Defines the maximum number of allowed
483 * outstanding TREs in IPA/GSI (in Bytes). RE engine
484 * prefetch will be limited by this configuration. It
485 * is suggested to configure this value to IPA_IF
486 * channel TLV queue size times element size.
487 * To disable the feature in doorbell mode (DB Mode=1).
488 * Maximum outstanding TREs should be set to 64KB
489 * (or any value larger or equal to ring length . RLEN)
490 * @outstanding_threshold: Used for the prefetch management sequence by the
491 * sequencer. Defines the threshold (in Bytes) as to when
492 * to update the channel doorbell. Should be smaller than
493 * Maximum outstanding TREs. value. It is suggested to
494 * configure this value to min(TLV_FIFO_SIZE/2,8) *
495 * element size.
496 */
497struct __packed gsi_mhi_channel_scratch {
498 uint64_t mhi_host_wp_addr;
499 uint32_t rsvd1:1;
500 uint32_t assert_bit40:1;
501 uint32_t polling_configuration:5;
502 uint32_t burst_mode_enabled:1;
503 uint32_t polling_mode:1;
504 uint32_t oob_mod_threshold:5;
505 uint32_t resvd2:2;
506 uint32_t max_outstanding_tre:16;
507 uint32_t resvd3:16;
508 uint32_t outstanding_threshold:16;
509};
510
511/**
512 * gsi_xdci_channel_scratch - xDCI protocol SW config area of
513 * channel scratch
514 *
515 * @const_buffer_size: TRB buffer size in KB (similar to IPA aggregationi
516 * configuration). Must be aligned to Max USB Packet Size
517 * @xferrscidx: Transfer Resource Index (XferRscIdx). The hardware-assigned
518 * transfer resource index for the transfer, which was
519 * returned in response to the Start Transfer command.
520 * This field is used for "Update Transfer" command
521 * @last_trb_addr: Address (LSB - based on alignment restrictions) of
522 * last TRB in queue. Used to identify rollover case
523 * @depcmd_low_addr: Used to generate "Update Transfer" command
524 * @max_outstanding_tre: Used for the prefetch management sequence by the
525 * sequencer. Defines the maximum number of allowed
526 * outstanding TREs in IPA/GSI (in Bytes). RE engine
527 * prefetch will be limited by this configuration. It
528 * is suggested to configure this value to IPA_IF
529 * channel TLV queue size times element size.
530 * To disable the feature in doorbell mode (DB Mode=1)
531 * Maximum outstanding TREs should be set to 64KB
532 * (or any value larger or equal to ring length . RLEN)
533 * @depcmd_hi_addr: Used to generate "Update Transfer" command
534 * @outstanding_threshold: Used for the prefetch management sequence by the
535 * sequencer. Defines the threshold (in Bytes) as to when
536 * to update the channel doorbell. Should be smaller than
537 * Maximum outstanding TREs. value. It is suggested to
538 * configure this value to 2 * element size. for MBIM the
539 * suggested configuration is the element size.
540 */
541struct __packed gsi_xdci_channel_scratch {
542 uint32_t last_trb_addr:16;
543 uint32_t resvd1:4;
544 uint32_t xferrscidx:7;
545 uint32_t const_buffer_size:5;
546 uint32_t depcmd_low_addr;
547 uint32_t depcmd_hi_addr:8;
548 uint32_t resvd2:8;
549 uint32_t max_outstanding_tre:16;
550 uint32_t resvd3:16;
551 uint32_t outstanding_threshold:16;
552};
553
554/**
555 * gsi_channel_scratch - channel scratch SW config area
556 *
557 */
558union __packed gsi_channel_scratch {
559 struct __packed gsi_gpi_channel_scratch gpi;
560 struct __packed gsi_mhi_channel_scratch mhi;
561 struct __packed gsi_xdci_channel_scratch xdci;
562 struct __packed {
563 uint32_t word1;
564 uint32_t word2;
565 uint32_t word3;
566 uint32_t word4;
567 } data;
568};
569
570/**
571 * gsi_mhi_evt_scratch - MHI protocol SW config area of
572 * event scratch
573 */
574struct __packed gsi_mhi_evt_scratch {
575 uint32_t resvd1;
576 uint32_t resvd2;
577};
578
579/**
580 * gsi_xdci_evt_scratch - xDCI protocol SW config area of
581 * event scratch
582 *
583 */
584struct __packed gsi_xdci_evt_scratch {
585 uint32_t gevntcount_low_addr;
586 uint32_t gevntcount_hi_addr:8;
587 uint32_t resvd1:24;
588};
589
590/**
591 * gsi_evt_scratch - event scratch SW config area
592 *
593 */
594union __packed gsi_evt_scratch {
595 struct __packed gsi_mhi_evt_scratch mhi;
596 struct __packed gsi_xdci_evt_scratch xdci;
597 struct __packed {
598 uint32_t word1;
599 uint32_t word2;
600 } data;
601};
602
603/**
604 * gsi_device_scratch - EE scratch config parameters
605 *
606 * @mhi_base_chan_idx_valid: is mhi_base_chan_idx valid?
607 * @mhi_base_chan_idx: base index of IPA MHI channel indexes.
608 * IPA MHI channel index = GSI channel ID +
609 * MHI base channel index
610 * @max_usb_pkt_size_valid: is max_usb_pkt_size valid?
611 * @max_usb_pkt_size: max USB packet size in bytes (valid values are
612 * 512 and 1024)
613 */
614struct gsi_device_scratch {
615 bool mhi_base_chan_idx_valid;
616 uint8_t mhi_base_chan_idx;
617 bool max_usb_pkt_size_valid;
618 uint16_t max_usb_pkt_size;
619};
620
621/**
622 * gsi_chan_info - information about channel occupancy
623 *
624 * @wp: channel write pointer (physical address)
625 * @rp: channel read pointer (physical address)
626 * @evt_valid: is evt* info valid?
627 * @evt_wp: event ring write pointer (physical address)
628 * @evt_rp: event ring read pointer (physical address)
629 */
630struct gsi_chan_info {
631 uint64_t wp;
632 uint64_t rp;
633 bool evt_valid;
634 uint64_t evt_wp;
635 uint64_t evt_rp;
636};
637
638#ifdef CONFIG_GSI
639/**
640 * gsi_register_device - Peripheral should call this function to
641 * register itself with GSI before invoking any other APIs
642 *
643 * @props: Peripheral properties
644 * @dev_hdl: Handle populated by GSI, opaque to client
645 *
646 * @Return -GSI_STATUS_AGAIN if request should be re-tried later
647 * other error codes for failure
648 */
649int gsi_register_device(struct gsi_per_props *props, unsigned long *dev_hdl);
650
651/**
652 * gsi_complete_clk_grant - Peripheral should call this function to
653 * grant the clock resource requested by GSI previously that could not
654 * be granted synchronously. GSI will release the clock resource using
655 * the rel_clk_cb when appropriate
656 *
657 * @dev_hdl: Client handle previously obtained from
658 * gsi_register_device
659 *
660 * @Return gsi_status
661 */
662int gsi_complete_clk_grant(unsigned long dev_hdl);
663
664/**
665 * gsi_write_device_scratch - Peripheral should call this function to
666 * write to the EE scratch area
667 *
668 * @dev_hdl: Client handle previously obtained from
669 * gsi_register_device
670 * @val: Value to write
671 *
672 * @Return gsi_status
673 */
674int gsi_write_device_scratch(unsigned long dev_hdl,
675 struct gsi_device_scratch *val);
676
677/**
678 * gsi_deregister_device - Peripheral should call this function to
679 * de-register itself with GSI
680 *
681 * @dev_hdl: Client handle previously obtained from
682 * gsi_register_device
683 * @force: When set to true, cleanup is performed even if there
684 * are in use resources like channels, event rings, etc.
685 * this would be used after GSI reset to recover from some
686 * fatal error
687 * When set to false, there must not exist any allocated
688 * channels and event rings.
689 *
690 * @Return gsi_status
691 */
692int gsi_deregister_device(unsigned long dev_hdl, bool force);
693
694/**
695 * gsi_alloc_evt_ring - Peripheral should call this function to
696 * allocate an event ring
697 *
698 * @props: Event ring properties
699 * @dev_hdl: Client handle previously obtained from
700 * gsi_register_device
701 * @evt_ring_hdl: Handle populated by GSI, opaque to client
702 *
703 * This function can sleep
704 *
705 * @Return gsi_status
706 */
707int gsi_alloc_evt_ring(struct gsi_evt_ring_props *props, unsigned long dev_hdl,
708 unsigned long *evt_ring_hdl);
709
710/**
711 * gsi_write_evt_ring_scratch - Peripheral should call this function to
712 * write to the scratch area of the event ring context
713 *
714 * @evt_ring_hdl: Client handle previously obtained from
715 * gsi_alloc_evt_ring
716 * @val: Value to write
717 *
718 * @Return gsi_status
719 */
720int gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
721 union __packed gsi_evt_scratch val);
722
723/**
724 * gsi_dealloc_evt_ring - Peripheral should call this function to
725 * de-allocate an event ring. There should not exist any active
726 * channels using this event ring
727 *
728 * @evt_ring_hdl: Client handle previously obtained from
729 * gsi_alloc_evt_ring
730 *
731 * This function can sleep
732 *
733 * @Return gsi_status
734 */
735int gsi_dealloc_evt_ring(unsigned long evt_ring_hdl);
736
737/**
738 * gsi_query_evt_ring_db_addr - Peripheral should call this function to
739 * query the physical addresses of the event ring doorbell registers
740 *
741 * @evt_ring_hdl: Client handle previously obtained from
742 * gsi_alloc_evt_ring
743 * @db_addr_wp_lsb: Physical address of doorbell register where the 32
744 * LSBs of the doorbell value should be written
745 * @db_addr_wp_msb: Physical address of doorbell register where the 32
746 * MSBs of the doorbell value should be written
747 *
748 * @Return gsi_status
749 */
750int gsi_query_evt_ring_db_addr(unsigned long evt_ring_hdl,
751 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
752
753/**
754 * gsi_reset_evt_ring - Peripheral should call this function to
755 * reset an event ring to recover from error state
756 *
757 * @evt_ring_hdl: Client handle previously obtained from
758 * gsi_alloc_evt_ring
759 *
760 * This function can sleep
761 *
762 * @Return gsi_status
763 */
764int gsi_reset_evt_ring(unsigned long evt_ring_hdl);
765
766/**
767 * gsi_get_evt_ring_cfg - This function returns the current config
768 * of the specified event ring
769 *
770 * @evt_ring_hdl: Client handle previously obtained from
771 * gsi_alloc_evt_ring
772 * @props: where to copy properties to
773 * @scr: where to copy scratch info to
774 *
775 * @Return gsi_status
776 */
777int gsi_get_evt_ring_cfg(unsigned long evt_ring_hdl,
778 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
779
780/**
781 * gsi_set_evt_ring_cfg - This function applies the supplied config
782 * to the specified event ring.
783 *
784 * exclusive property of the event ring cannot be changed after
785 * gsi_alloc_evt_ring
786 *
787 * @evt_ring_hdl: Client handle previously obtained from
788 * gsi_alloc_evt_ring
789 * @props: the properties to apply
790 * @scr: the scratch info to apply
791 *
792 * @Return gsi_status
793 */
794int gsi_set_evt_ring_cfg(unsigned long evt_ring_hdl,
795 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr);
796
797/**
798 * gsi_alloc_channel - Peripheral should call this function to
799 * allocate a channel
800 *
801 * @props: Channel properties
802 * @dev_hdl: Client handle previously obtained from
803 * gsi_register_device
804 * @chan_hdl: Handle populated by GSI, opaque to client
805 *
806 * This function can sleep
807 *
808 * @Return gsi_status
809 */
810int gsi_alloc_channel(struct gsi_chan_props *props, unsigned long dev_hdl,
811 unsigned long *chan_hdl);
812
813/**
814 * gsi_write_channel_scratch - Peripheral should call this function to
815 * write to the scratch area of the channel context
816 *
817 * @chan_hdl: Client handle previously obtained from
818 * gsi_alloc_channel
819 * @val: Value to write
820 *
821 * @Return gsi_status
822 */
823int gsi_write_channel_scratch(unsigned long chan_hdl,
824 union __packed gsi_channel_scratch val);
825
826/**
827 * gsi_start_channel - Peripheral should call this function to
828 * start a channel i.e put into running state
829 *
830 * @chan_hdl: Client handle previously obtained from
831 * gsi_alloc_channel
832 *
833 * This function can sleep
834 *
835 * @Return gsi_status
836 */
837int gsi_start_channel(unsigned long chan_hdl);
838
839/**
840 * gsi_stop_channel - Peripheral should call this function to
841 * stop a channel. Stop will happen on a packet boundary
842 *
843 * @chan_hdl: Client handle previously obtained from
844 * gsi_alloc_channel
845 *
846 * This function can sleep
847 *
848 * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
849 * other error codes for failure
850 */
851int gsi_stop_channel(unsigned long chan_hdl);
852
853/**
854 * gsi_reset_channel - Peripheral should call this function to
855 * reset a channel to recover from error state
856 *
857 * @chan_hdl: Client handle previously obtained from
858 * gsi_alloc_channel
859 *
860 * This function can sleep
861 *
862 * @Return gsi_status
863 */
864int gsi_reset_channel(unsigned long chan_hdl);
865
866/**
867 * gsi_dealloc_channel - Peripheral should call this function to
868 * de-allocate a channel
869 *
870 * @chan_hdl: Client handle previously obtained from
871 * gsi_alloc_channel
872 *
873 * This function can sleep
874 *
875 * @Return gsi_status
876 */
877int gsi_dealloc_channel(unsigned long chan_hdl);
878
879/**
880 * gsi_stop_db_channel - Peripheral should call this function to
881 * stop a channel when all transfer elements till the doorbell
882 * have been processed
883 *
884 * @chan_hdl: Client handle previously obtained from
885 * gsi_alloc_channel
886 *
887 * This function can sleep
888 *
889 * @Return -GSI_STATUS_AGAIN if client should call stop/stop_db again
890 * other error codes for failure
891 */
892int gsi_stop_db_channel(unsigned long chan_hdl);
893
894/**
895 * gsi_query_channel_db_addr - Peripheral should call this function to
896 * query the physical addresses of the channel doorbell registers
897 *
898 * @chan_hdl: Client handle previously obtained from
899 * gsi_alloc_channel
900 * @db_addr_wp_lsb: Physical address of doorbell register where the 32
901 * LSBs of the doorbell value should be written
902 * @db_addr_wp_msb: Physical address of doorbell register where the 32
903 * MSBs of the doorbell value should be written
904 *
905 * @Return gsi_status
906 */
907int gsi_query_channel_db_addr(unsigned long chan_hdl,
908 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb);
909
910/**
911 * gsi_query_channel_info - Peripheral can call this function to query the
912 * channel and associated event ring (if any) status.
913 *
914 * @chan_hdl: Client handle previously obtained from
915 * gsi_alloc_channel
916 * @info: Where to read the values into
917 *
918 * @Return gsi_status
919 */
920int gsi_query_channel_info(unsigned long chan_hdl,
921 struct gsi_chan_info *info);
922
923/**
924 * gsi_is_channel_empty - Peripheral can call this function to query if
925 * the channel is empty. This is only applicable to GPI. "Empty" means
926 * GSI has consumed all descriptors for a TO_GSI channel and SW has
927 * processed all completed descriptors for a FROM_GSI channel.
928 *
929 * @chan_hdl: Client handle previously obtained from gsi_alloc_channel
930 * @is_empty: set by GSI based on channel emptiness
931 *
932 * @Return gsi_status
933 */
934int gsi_is_channel_empty(unsigned long chan_hdl, bool *is_empty);
935
936/**
937 * gsi_get_channel_cfg - This function returns the current config
938 * of the specified channel
939 *
940 * @chan_hdl: Client handle previously obtained from
941 * gsi_alloc_channel
942 * @props: where to copy properties to
943 * @scr: where to copy scratch info to
944 *
945 * @Return gsi_status
946 */
947int gsi_get_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
948 union gsi_channel_scratch *scr);
949
950/**
951 * gsi_set_channel_cfg - This function applies the supplied config
952 * to the specified channel
953 *
954 * ch_id and evt_ring_hdl of the channel cannot be changed after
955 * gsi_alloc_channel
956 *
957 * @chan_hdl: Client handle previously obtained from
958 * gsi_alloc_channel
959 * @props: the properties to apply
960 * @scr: the scratch info to apply
961 *
962 * @Return gsi_status
963 */
964int gsi_set_channel_cfg(unsigned long chan_hdl, struct gsi_chan_props *props,
965 union gsi_channel_scratch *scr);
966
967/**
968 * gsi_poll_channel - Peripheral should call this function to query for
969 * completed transfer descriptors.
970 *
971 * @chan_hdl: Client handle previously obtained from
972 * gsi_alloc_channel
973 * @notify: Information about the completed transfer if any
974 *
975 * @Return gsi_status (GSI_STATUS_POLL_EMPTY is returned if no transfers
976 * completed)
977 */
978int gsi_poll_channel(unsigned long chan_hdl,
979 struct gsi_chan_xfer_notify *notify);
980
981/**
982 * gsi_config_channel_mode - Peripheral should call this function
983 * to configure the channel mode.
984 *
985 * @chan_hdl: Client handle previously obtained from
986 * gsi_alloc_channel
987 * @mode: Mode to move the channel into
988 *
989 * @Return gsi_status
990 */
991int gsi_config_channel_mode(unsigned long chan_hdl, enum gsi_chan_mode mode);
992
993/**
994 * gsi_queue_xfer - Peripheral should call this function
995 * to queue transfers on the given channel
996 *
997 * @chan_hdl: Client handle previously obtained from
998 * gsi_alloc_channel
999 * @num_xfers: Number of transfer in the array @ xfer
1000 * @xfer: Array of num_xfers transfer descriptors
1001 * @ring_db: If true, tell HW about these queued xfers
1002 * If false, do not notify HW at this time
1003 *
1004 * @Return gsi_status
1005 */
1006int gsi_queue_xfer(unsigned long chan_hdl, uint16_t num_xfers,
1007 struct gsi_xfer_elem *xfer, bool ring_db);
1008
1009/**
1010 * gsi_start_xfer - Peripheral should call this function to
1011 * inform HW about queued xfers
1012 *
1013 * @chan_hdl: Client handle previously obtained from
1014 * gsi_alloc_channel
1015 *
1016 * @Return gsi_status
1017 */
1018int gsi_start_xfer(unsigned long chan_hdl);
1019
1020/**
1021 * gsi_configure_regs - Peripheral should call this function
1022 * to configure the GSI registers before/after the FW is
1023 * loaded but before it is enabled.
1024 *
1025 * @gsi_base_addr: Base address of GSI register space
1026 * @gsi_size: Mapping size of the GSI register space
1027 * @per_base_addr: Base address of the peripheral using GSI
1028 *
1029 * @Return gsi_status
1030 */
1031int gsi_configure_regs(phys_addr_t gsi_base_addr, u32 gsi_size,
1032 phys_addr_t per_base_addr);
1033
1034/**
1035 * gsi_enable_fw - Peripheral should call this function
1036 * to enable the GSI FW after the FW has been loaded to the SRAM.
1037 *
1038 * @gsi_base_addr: Base address of GSI register space
1039 * @gsi_size: Mapping size of the GSI register space
Amir Levy85dcd172016-12-06 17:47:39 +02001040 * @ver: GSI core version
Amir Levycdccd632016-10-30 09:36:41 +02001041
1042 * @Return gsi_status
1043 */
Amir Levy85dcd172016-12-06 17:47:39 +02001044int gsi_enable_fw(phys_addr_t gsi_base_addr, u32 gsi_size, enum gsi_ver ver);
Amir Levycdccd632016-10-30 09:36:41 +02001045
Ghanim Fodi37b64952017-01-24 15:42:30 +02001046/**
1047 * gsi_get_inst_ram_offset_and_size - Peripheral should call this function
1048 * to get instruction RAM base address offset and size. Peripheral typically
1049 * uses this info to load GSI FW into the IRAM.
1050 *
1051 * @base_offset:[OUT] - IRAM base offset address
1052 * @size: [OUT] - IRAM size
1053
1054 * @Return none
1055 */
1056void gsi_get_inst_ram_offset_and_size(unsigned long *base_offset,
1057 unsigned long *size);
1058
Skylar Changc9939cf2017-02-21 09:46:46 -08001059/**
1060 * gsi_halt_channel_ee - Peripheral should call this function
1061 * to stop other EE's channel. This is usually used in SSR clean
1062 *
1063 * @chan_idx: Virtual channel index
1064 * @ee: EE
1065 * @code: [out] response code for operation
1066
1067 * @Return gsi_status
1068 */
1069int gsi_halt_channel_ee(unsigned int chan_idx, unsigned int ee, int *code);
1070
Amir Levycdccd632016-10-30 09:36:41 +02001071/*
1072 * Here is a typical sequence of calls
1073 *
1074 * gsi_register_device
1075 *
1076 * gsi_write_device_scratch (if the protocol needs this)
1077 *
1078 * gsi_alloc_evt_ring (for as many event rings as needed)
1079 * gsi_write_evt_ring_scratch
1080 *
1081 * gsi_alloc_channel (for as many channels as needed; channels can have
1082 * no event ring, an exclusive event ring or a shared event ring)
1083 * gsi_write_channel_scratch
1084 * gsi_start_channel
1085 * gsi_queue_xfer/gsi_start_xfer
1086 * gsi_config_channel_mode/gsi_poll_channel (if clients wants to poll on
1087 * xfer completions)
1088 * gsi_stop_db_channel/gsi_stop_channel
1089 *
1090 * gsi_dealloc_channel
1091 *
1092 * gsi_dealloc_evt_ring
1093 *
1094 * gsi_deregister_device
1095 *
1096 */
1097#else
1098static inline int gsi_register_device(struct gsi_per_props *props,
1099 unsigned long *dev_hdl)
1100{
1101 return -GSI_STATUS_UNSUPPORTED_OP;
1102}
1103
1104static inline int gsi_complete_clk_grant(unsigned long dev_hdl)
1105{
1106 return -GSI_STATUS_UNSUPPORTED_OP;
1107}
1108
1109static inline int gsi_write_device_scratch(unsigned long dev_hdl,
1110 struct gsi_device_scratch *val)
1111{
1112 return -GSI_STATUS_UNSUPPORTED_OP;
1113}
1114
1115static inline int gsi_deregister_device(unsigned long dev_hdl, bool force)
1116{
1117 return -GSI_STATUS_UNSUPPORTED_OP;
1118}
1119
1120static inline int gsi_alloc_evt_ring(struct gsi_evt_ring_props *props,
1121 unsigned long dev_hdl,
1122 unsigned long *evt_ring_hdl)
1123{
1124 return -GSI_STATUS_UNSUPPORTED_OP;
1125}
1126
1127static inline int gsi_write_evt_ring_scratch(unsigned long evt_ring_hdl,
1128 union __packed gsi_evt_scratch val)
1129{
1130 return -GSI_STATUS_UNSUPPORTED_OP;
1131}
1132
1133static inline int gsi_dealloc_evt_ring(unsigned long evt_ring_hdl)
1134{
1135 return -GSI_STATUS_UNSUPPORTED_OP;
1136}
1137
1138static inline int gsi_query_evt_ring_db_addr(unsigned long evt_ring_hdl,
1139 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb)
1140{
1141 return -GSI_STATUS_UNSUPPORTED_OP;
1142}
1143
1144static inline int gsi_reset_evt_ring(unsigned long evt_ring_hdl)
1145{
1146 return -GSI_STATUS_UNSUPPORTED_OP;
1147}
1148
1149static inline int gsi_alloc_channel(struct gsi_chan_props *props,
1150 unsigned long dev_hdl,
1151 unsigned long *chan_hdl)
1152{
1153 return -GSI_STATUS_UNSUPPORTED_OP;
1154}
1155
1156static inline int gsi_write_channel_scratch(unsigned long chan_hdl,
1157 union __packed gsi_channel_scratch val)
1158{
1159 return -GSI_STATUS_UNSUPPORTED_OP;
1160}
1161
1162static inline int gsi_start_channel(unsigned long chan_hdl)
1163{
1164 return -GSI_STATUS_UNSUPPORTED_OP;
1165}
1166
1167static inline int gsi_stop_channel(unsigned long chan_hdl)
1168{
1169 return -GSI_STATUS_UNSUPPORTED_OP;
1170}
1171
1172static inline int gsi_reset_channel(unsigned long chan_hdl)
1173{
1174 return -GSI_STATUS_UNSUPPORTED_OP;
1175}
1176
1177static inline int gsi_dealloc_channel(unsigned long chan_hdl)
1178{
1179 return -GSI_STATUS_UNSUPPORTED_OP;
1180}
1181
1182static inline int gsi_stop_db_channel(unsigned long chan_hdl)
1183{
1184 return -GSI_STATUS_UNSUPPORTED_OP;
1185}
1186
1187static inline int gsi_query_channel_db_addr(unsigned long chan_hdl,
1188 uint32_t *db_addr_wp_lsb, uint32_t *db_addr_wp_msb)
1189{
1190 return -GSI_STATUS_UNSUPPORTED_OP;
1191}
1192
1193static inline int gsi_query_channel_info(unsigned long chan_hdl,
1194 struct gsi_chan_info *info)
1195{
1196 return -GSI_STATUS_UNSUPPORTED_OP;
1197}
1198
1199static inline int gsi_is_channel_empty(unsigned long chan_hdl, bool *is_empty)
1200{
1201 return -GSI_STATUS_UNSUPPORTED_OP;
1202}
1203
1204static inline int gsi_poll_channel(unsigned long chan_hdl,
1205 struct gsi_chan_xfer_notify *notify)
1206{
1207 return -GSI_STATUS_UNSUPPORTED_OP;
1208}
1209
1210static inline int gsi_config_channel_mode(unsigned long chan_hdl,
1211 enum gsi_chan_mode mode)
1212{
1213 return -GSI_STATUS_UNSUPPORTED_OP;
1214}
1215
1216static inline int gsi_queue_xfer(unsigned long chan_hdl, uint16_t num_xfers,
1217 struct gsi_xfer_elem *xfer, bool ring_db)
1218{
1219 return -GSI_STATUS_UNSUPPORTED_OP;
1220}
1221
1222static inline int gsi_start_xfer(unsigned long chan_hdl)
1223{
1224 return -GSI_STATUS_UNSUPPORTED_OP;
1225}
1226
1227static inline int gsi_get_channel_cfg(unsigned long chan_hdl,
1228 struct gsi_chan_props *props,
1229 union gsi_channel_scratch *scr)
1230{
1231 return -GSI_STATUS_UNSUPPORTED_OP;
1232}
1233
1234static inline int gsi_set_channel_cfg(unsigned long chan_hdl,
1235 struct gsi_chan_props *props,
1236 union gsi_channel_scratch *scr)
1237{
1238 return -GSI_STATUS_UNSUPPORTED_OP;
1239}
1240
1241static inline int gsi_get_evt_ring_cfg(unsigned long evt_ring_hdl,
1242 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr)
1243{
1244 return -GSI_STATUS_UNSUPPORTED_OP;
1245}
1246
1247static inline int gsi_set_evt_ring_cfg(unsigned long evt_ring_hdl,
1248 struct gsi_evt_ring_props *props, union gsi_evt_scratch *scr)
1249{
1250 return -GSI_STATUS_UNSUPPORTED_OP;
1251}
1252
1253static inline int gsi_configure_regs(phys_addr_t gsi_base_addr, u32 gsi_size,
1254 phys_addr_t per_base_addr)
1255{
1256 return -GSI_STATUS_UNSUPPORTED_OP;
1257}
Ghanim Fodi37b64952017-01-24 15:42:30 +02001258
Amir Levycdccd632016-10-30 09:36:41 +02001259static inline int gsi_enable_fw(phys_addr_t gsi_base_addr, u32 gsi_size)
1260{
1261 return -GSI_STATUS_UNSUPPORTED_OP;
1262}
Ghanim Fodi37b64952017-01-24 15:42:30 +02001263
1264static inline void gsi_get_inst_ram_offset_and_size(unsigned long *base_offset,
1265 unsigned long *size)
1266{
1267}
Skylar Changc9939cf2017-02-21 09:46:46 -08001268
1269static inline int gsi_halt_channel_ee(unsigned int chan_idx, unsigned int ee,
1270 int *code)
1271{
1272 return -GSI_STATUS_UNSUPPORTED_OP;
1273}
Amir Levycdccd632016-10-30 09:36:41 +02001274#endif
1275#endif