gsi.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2018-2024 Linaro Ltd.
  4. */
  5. #ifndef _GSI_H_
  6. #define _GSI_H_
  7. #include <linux/completion.h>
  8. #include <linux/mutex.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/types.h>
  11. #include "ipa_version.h"
  12. /* Maximum number of channels and event rings supported by the driver */
  13. #define GSI_CHANNEL_COUNT_MAX 28
  14. #define GSI_EVT_RING_COUNT_MAX 28
  15. /* Maximum TLV FIFO size for a channel; 64 here is arbitrary (and high) */
  16. #define GSI_TLV_MAX 64
  17. struct device;
  18. struct platform_device;
  19. struct gsi;
  20. struct gsi_trans;
  21. struct ipa_gsi_endpoint_data;
  22. struct gsi_ring {
  23. void *virt; /* ring array base address */
  24. dma_addr_t addr; /* primarily low 32 bits used */
  25. u32 count; /* number of elements in ring */
  26. /* The ring index value indicates the next "open" entry in the ring.
  27. *
  28. * A channel ring consists of TRE entries filled by the AP and passed
  29. * to the hardware for processing. For a channel ring, the ring index
  30. * identifies the next unused entry to be filled by the AP. In this
  31. * case the initial value is assumed by hardware to be 0.
  32. *
  33. * An event ring consists of event structures filled by the hardware
  34. * and passed to the AP. For event rings, the ring index identifies
  35. * the next ring entry that is not known to have been filled by the
  36. * hardware. The initial value used is arbitrary (so we use 0).
  37. */
  38. u32 index;
  39. };
  40. /* Transactions use several resources that can be allocated dynamically
  41. * but taken from a fixed-size pool. The number of elements required for
  42. * the pool is limited by the total number of TREs that can be outstanding.
  43. *
  44. * If sufficient TREs are available to reserve for a transaction,
  45. * allocation from these pools is guaranteed to succeed. Furthermore,
  46. * these resources are implicitly freed whenever the TREs in the
  47. * transaction they're associated with are released.
  48. *
  49. * The result of a pool allocation of multiple elements is always
  50. * contiguous.
  51. */
  52. struct gsi_trans_pool {
  53. void *base; /* base address of element pool */
  54. u32 count; /* # elements in the pool */
  55. u32 free; /* next free element in pool (modulo) */
  56. u32 size; /* size (bytes) of an element */
  57. u32 max_alloc; /* max allocation request */
  58. dma_addr_t addr; /* DMA address if DMA pool (or 0) */
  59. };
  60. struct gsi_trans_info {
  61. atomic_t tre_avail; /* TREs available for allocation */
  62. u16 free_id; /* first free trans in array */
  63. u16 allocated_id; /* first allocated transaction */
  64. u16 committed_id; /* first committed transaction */
  65. u16 pending_id; /* first pending transaction */
  66. u16 completed_id; /* first completed transaction */
  67. u16 polled_id; /* first polled transaction */
  68. struct gsi_trans *trans; /* transaction array */
  69. struct gsi_trans **map; /* TRE -> transaction map */
  70. struct gsi_trans_pool sg_pool; /* scatterlist pool */
  71. struct gsi_trans_pool cmd_pool; /* command payload DMA pool */
  72. };
  73. /* Hardware values signifying the state of a channel */
  74. enum gsi_channel_state {
  75. GSI_CHANNEL_STATE_NOT_ALLOCATED = 0x0,
  76. GSI_CHANNEL_STATE_ALLOCATED = 0x1,
  77. GSI_CHANNEL_STATE_STARTED = 0x2,
  78. GSI_CHANNEL_STATE_STOPPED = 0x3,
  79. GSI_CHANNEL_STATE_STOP_IN_PROC = 0x4,
  80. GSI_CHANNEL_STATE_FLOW_CONTROLLED = 0x5, /* IPA v4.2-v4.9 */
  81. GSI_CHANNEL_STATE_ERROR = 0xf,
  82. };
  83. /* We only care about channels between IPA and AP */
  84. struct gsi_channel {
  85. struct gsi *gsi;
  86. bool toward_ipa;
  87. bool command; /* AP command TX channel or not */
  88. u8 trans_tre_max; /* max TREs in a transaction */
  89. u16 tre_count;
  90. u16 event_count;
  91. struct gsi_ring tre_ring;
  92. u32 evt_ring_id;
  93. /* The following counts are used only for TX endpoints */
  94. u64 byte_count; /* total # bytes transferred */
  95. u64 trans_count; /* total # transactions */
  96. u64 queued_byte_count; /* last reported queued byte count */
  97. u64 queued_trans_count; /* ...and queued trans count */
  98. u64 compl_byte_count; /* last reported completed byte count */
  99. u64 compl_trans_count; /* ...and completed trans count */
  100. struct gsi_trans_info trans_info;
  101. struct napi_struct napi;
  102. };
  103. /* Hardware values signifying the state of an event ring */
  104. enum gsi_evt_ring_state {
  105. GSI_EVT_RING_STATE_NOT_ALLOCATED = 0x0,
  106. GSI_EVT_RING_STATE_ALLOCATED = 0x1,
  107. GSI_EVT_RING_STATE_ERROR = 0xf,
  108. };
  109. struct gsi_evt_ring {
  110. struct gsi_channel *channel;
  111. struct gsi_ring ring;
  112. };
  113. struct gsi {
  114. struct device *dev; /* Same as IPA device */
  115. enum ipa_version version;
  116. void __iomem *virt; /* I/O mapped registers */
  117. const struct regs *regs;
  118. u32 irq;
  119. u32 channel_count;
  120. u32 evt_ring_count;
  121. u32 event_bitmap; /* allocated event rings */
  122. u32 modem_channel_bitmap; /* modem channels to allocate */
  123. u32 type_enabled_bitmap; /* GSI IRQ types enabled */
  124. u32 ieob_enabled_bitmap; /* IEOB IRQ enabled (event rings) */
  125. int result; /* Negative errno (generic commands) */
  126. struct completion completion; /* Signals GSI command completion */
  127. struct mutex mutex; /* protects commands, programming */
  128. struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX];
  129. struct gsi_evt_ring evt_ring[GSI_EVT_RING_COUNT_MAX];
  130. struct net_device *dummy_dev; /* needed for NAPI */
  131. };
  132. /**
  133. * gsi_setup() - Set up the GSI subsystem
  134. * @gsi: Address of GSI structure embedded in an IPA structure
  135. *
  136. * Return: 0 if successful, or a negative error code
  137. *
  138. * Performs initialization that must wait until the GSI hardware is
  139. * ready (including firmware loaded).
  140. */
  141. int gsi_setup(struct gsi *gsi);
  142. /**
  143. * gsi_teardown() - Tear down GSI subsystem
  144. * @gsi: GSI address previously passed to a successful gsi_setup() call
  145. */
  146. void gsi_teardown(struct gsi *gsi);
  147. /**
  148. * gsi_channel_tre_max() - Channel maximum number of in-flight TREs
  149. * @gsi: GSI pointer
  150. * @channel_id: Channel whose limit is to be returned
  151. *
  152. * Return: The maximum number of TREs outstanding on the channel
  153. */
  154. u32 gsi_channel_tre_max(struct gsi *gsi, u32 channel_id);
  155. /**
  156. * gsi_channel_start() - Start an allocated GSI channel
  157. * @gsi: GSI pointer
  158. * @channel_id: Channel to start
  159. *
  160. * Return: 0 if successful, or a negative error code
  161. */
  162. int gsi_channel_start(struct gsi *gsi, u32 channel_id);
  163. /**
  164. * gsi_channel_stop() - Stop a started GSI channel
  165. * @gsi: GSI pointer returned by gsi_setup()
  166. * @channel_id: Channel to stop
  167. *
  168. * Return: 0 if successful, or a negative error code
  169. */
  170. int gsi_channel_stop(struct gsi *gsi, u32 channel_id);
  171. /**
  172. * gsi_modem_channel_flow_control() - Set channel flow control state (IPA v4.2+)
  173. * @gsi: GSI pointer returned by gsi_setup()
  174. * @channel_id: Modem TX channel to control
  175. * @enable: Whether to enable flow control (i.e., prevent flow)
  176. */
  177. void gsi_modem_channel_flow_control(struct gsi *gsi, u32 channel_id,
  178. bool enable);
  179. /**
  180. * gsi_channel_reset() - Reset an allocated GSI channel
  181. * @gsi: GSI pointer
  182. * @channel_id: Channel to be reset
  183. * @doorbell: Whether to (possibly) enable the doorbell engine
  184. *
  185. * Reset a channel and reconfigure it. The @doorbell flag indicates
  186. * that the doorbell engine should be enabled if needed.
  187. *
  188. * GSI hardware relinquishes ownership of all pending receive buffer
  189. * transactions and they will complete with their cancelled flag set.
  190. */
  191. void gsi_channel_reset(struct gsi *gsi, u32 channel_id, bool doorbell);
  192. /**
  193. * gsi_suspend() - Prepare the GSI subsystem for suspend
  194. * @gsi: GSI pointer
  195. */
  196. void gsi_suspend(struct gsi *gsi);
  197. /**
  198. * gsi_resume() - Resume the GSI subsystem following suspend
  199. * @gsi: GSI pointer
  200. */
  201. void gsi_resume(struct gsi *gsi);
  202. /**
  203. * gsi_channel_suspend() - Suspend a GSI channel
  204. * @gsi: GSI pointer
  205. * @channel_id: Channel to suspend
  206. *
  207. * For IPA v4.0+, suspend is implemented by stopping the channel.
  208. */
  209. int gsi_channel_suspend(struct gsi *gsi, u32 channel_id);
  210. /**
  211. * gsi_channel_resume() - Resume a suspended GSI channel
  212. * @gsi: GSI pointer
  213. * @channel_id: Channel to resume
  214. *
  215. * For IPA v4.0+, the stopped channel is started again.
  216. */
  217. int gsi_channel_resume(struct gsi *gsi, u32 channel_id);
  218. /**
  219. * gsi_init() - Initialize the GSI subsystem
  220. * @gsi: Address of GSI structure embedded in an IPA structure
  221. * @pdev: IPA platform device
  222. * @version: IPA hardware version (implies GSI version)
  223. * @count: Number of entries in the configuration data array
  224. * @data: Endpoint and channel configuration data
  225. *
  226. * Return: 0 if successful, or a negative error code
  227. *
  228. * Early stage initialization of the GSI subsystem, performing tasks
  229. * that can be done before the GSI hardware is ready to use.
  230. */
  231. int gsi_init(struct gsi *gsi, struct platform_device *pdev,
  232. enum ipa_version version, u32 count,
  233. const struct ipa_gsi_endpoint_data *data);
  234. /**
  235. * gsi_exit() - Exit the GSI subsystem
  236. * @gsi: GSI address previously passed to a successful gsi_init() call
  237. */
  238. void gsi_exit(struct gsi *gsi);
  239. #endif /* _GSI_H_ */