gsi.h 8.8 KB

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