Linux Audio

Check our new training course

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