Skip to content

Commit ca48b27

Browse files
Alex Elderdavem330
authored andcommitted
soc: qcom: ipa: GSI headers
The Generic Software Interface is a layer of the IPA driver that abstracts the underlying hardware. The next patch includes the main code for GSI (including some additional documentation). This patch just includes three GSI header files. - "gsi.h" is the top-level GSI header file. This structure is is embedded within the IPA structure. The main abstraction implemented by the GSI code is the channel, and this header exposes several operations that can be performed on a GSI channel. - "gsi_private.h" exposes some definitions that are intended to be private, used only by the main GSI code and the GSI transaction code (defined in an upcoming patch). - Like "ipa_reg.h", "gsi_reg.h" defines the offsets of the 32-bit registers used by the GSI layer, along with masks that define the position and width of fields less than 32 bits located within these registers. Signed-off-by: Alex Elder <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ba764c4 commit ca48b27

File tree

3 files changed

+792
-0
lines changed

3 files changed

+792
-0
lines changed

drivers/net/ipa/gsi.h

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
4+
* Copyright (C) 2018-2020 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+
/* Maximum number of channels and event rings supported by the driver */
17+
#define GSI_CHANNEL_COUNT_MAX 17
18+
#define GSI_EVT_RING_COUNT_MAX 13
19+
20+
/* Maximum TLV FIFO size for a channel; 64 here is arbitrary (and high) */
21+
#define GSI_TLV_MAX 64
22+
23+
struct device;
24+
struct scatterlist;
25+
struct platform_device;
26+
27+
struct gsi;
28+
struct gsi_trans;
29+
struct gsi_channel_data;
30+
struct ipa_gsi_endpoint_data;
31+
32+
/* Execution environment IDs */
33+
enum gsi_ee_id {
34+
GSI_EE_AP = 0,
35+
GSI_EE_MODEM = 1,
36+
GSI_EE_UC = 2,
37+
GSI_EE_TZ = 3,
38+
};
39+
40+
struct gsi_ring {
41+
void *virt; /* ring array base address */
42+
dma_addr_t addr; /* primarily low 32 bits used */
43+
u32 count; /* number of elements in ring */
44+
45+
/* The ring index value indicates the next "open" entry in the ring.
46+
*
47+
* A channel ring consists of TRE entries filled by the AP and passed
48+
* to the hardware for processing. For a channel ring, the ring index
49+
* identifies the next unused entry to be filled by the AP.
50+
*
51+
* An event ring consists of event structures filled by the hardware
52+
* and passed to the AP. For event rings, the ring index identifies
53+
* the next ring entry that is not known to have been filled by the
54+
* hardware.
55+
*/
56+
u32 index;
57+
};
58+
59+
/* Transactions use several resources that can be allocated dynamically
60+
* but taken from a fixed-size pool. The number of elements required for
61+
* the pool is limited by the total number of TREs that can be outstanding.
62+
*
63+
* If sufficient TREs are available to reserve for a transaction,
64+
* allocation from these pools is guaranteed to succeed. Furthermore,
65+
* these resources are implicitly freed whenever the TREs in the
66+
* transaction they're associated with are released.
67+
*
68+
* The result of a pool allocation of multiple elements is always
69+
* contiguous.
70+
*/
71+
struct gsi_trans_pool {
72+
void *base; /* base address of element pool */
73+
u32 count; /* # elements in the pool */
74+
u32 free; /* next free element in pool (modulo) */
75+
u32 size; /* size (bytes) of an element */
76+
u32 max_alloc; /* max allocation request */
77+
dma_addr_t addr; /* DMA address if DMA pool (or 0) */
78+
};
79+
80+
struct gsi_trans_info {
81+
atomic_t tre_avail; /* TREs available for allocation */
82+
struct gsi_trans_pool pool; /* transaction pool */
83+
struct gsi_trans_pool sg_pool; /* scatterlist pool */
84+
struct gsi_trans_pool cmd_pool; /* command payload DMA pool */
85+
struct gsi_trans_pool info_pool;/* command information pool */
86+
struct gsi_trans **map; /* TRE -> transaction map */
87+
88+
spinlock_t spinlock; /* protects updates to the lists */
89+
struct list_head alloc; /* allocated, not committed */
90+
struct list_head pending; /* committed, awaiting completion */
91+
struct list_head complete; /* completed, awaiting poll */
92+
struct list_head polled; /* returned by gsi_channel_poll_one() */
93+
};
94+
95+
/* Hardware values signifying the state of a channel */
96+
enum gsi_channel_state {
97+
GSI_CHANNEL_STATE_NOT_ALLOCATED = 0x0,
98+
GSI_CHANNEL_STATE_ALLOCATED = 0x1,
99+
GSI_CHANNEL_STATE_STARTED = 0x2,
100+
GSI_CHANNEL_STATE_STOPPED = 0x3,
101+
GSI_CHANNEL_STATE_STOP_IN_PROC = 0x4,
102+
GSI_CHANNEL_STATE_ERROR = 0xf,
103+
};
104+
105+
/* We only care about channels between IPA and AP */
106+
struct gsi_channel {
107+
struct gsi *gsi;
108+
bool toward_ipa;
109+
bool command; /* AP command TX channel or not */
110+
bool use_prefetch; /* use prefetch (else escape buf) */
111+
112+
u8 tlv_count; /* # entries in TLV FIFO */
113+
u16 tre_count;
114+
u16 event_count;
115+
116+
struct completion completion; /* signals channel state changes */
117+
enum gsi_channel_state state;
118+
119+
struct gsi_ring tre_ring;
120+
u32 evt_ring_id;
121+
122+
u64 byte_count; /* total # bytes transferred */
123+
u64 trans_count; /* total # transactions */
124+
/* The following counts are used only for TX endpoints */
125+
u64 queued_byte_count; /* last reported queued byte count */
126+
u64 queued_trans_count; /* ...and queued trans count */
127+
u64 compl_byte_count; /* last reported completed byte count */
128+
u64 compl_trans_count; /* ...and completed trans count */
129+
130+
struct gsi_trans_info trans_info;
131+
132+
struct napi_struct napi;
133+
};
134+
135+
/* Hardware values signifying the state of an event ring */
136+
enum gsi_evt_ring_state {
137+
GSI_EVT_RING_STATE_NOT_ALLOCATED = 0x0,
138+
GSI_EVT_RING_STATE_ALLOCATED = 0x1,
139+
GSI_EVT_RING_STATE_ERROR = 0xf,
140+
};
141+
142+
struct gsi_evt_ring {
143+
struct gsi_channel *channel;
144+
struct completion completion; /* signals event ring state changes */
145+
enum gsi_evt_ring_state state;
146+
struct gsi_ring ring;
147+
};
148+
149+
struct gsi {
150+
struct device *dev; /* Same as IPA device */
151+
struct net_device dummy_dev; /* needed for NAPI */
152+
void __iomem *virt;
153+
u32 irq;
154+
bool irq_wake_enabled;
155+
u32 channel_count;
156+
u32 evt_ring_count;
157+
struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX];
158+
struct gsi_evt_ring evt_ring[GSI_EVT_RING_COUNT_MAX];
159+
u32 event_bitmap;
160+
u32 event_enable_bitmap;
161+
u32 modem_channel_bitmap;
162+
struct completion completion; /* for global EE commands */
163+
struct mutex mutex; /* protects commands, programming */
164+
};
165+
166+
/**
167+
* gsi_setup() - Set up the GSI subsystem
168+
* @gsi: Address of GSI structure embedded in an IPA structure
169+
* @db_enable: Whether to use the GSI doorbell engine
170+
*
171+
* @Return: 0 if successful, or a negative error code
172+
*
173+
* Performs initialization that must wait until the GSI hardware is
174+
* ready (including firmware loaded).
175+
*/
176+
int gsi_setup(struct gsi *gsi, bool db_enable);
177+
178+
/**
179+
* gsi_teardown() - Tear down GSI subsystem
180+
* @gsi: GSI address previously passed to a successful gsi_setup() call
181+
*/
182+
void gsi_teardown(struct gsi *gsi);
183+
184+
/**
185+
* gsi_channel_tre_max() - Channel maximum number of in-flight TREs
186+
* @gsi: GSI pointer
187+
* @channel_id: Channel whose limit is to be returned
188+
*
189+
* @Return: The maximum number of TREs oustanding on the channel
190+
*/
191+
u32 gsi_channel_tre_max(struct gsi *gsi, u32 channel_id);
192+
193+
/**
194+
* gsi_channel_trans_tre_max() - Maximum TREs in a single transaction
195+
* @gsi: GSI pointer
196+
* @channel_id: Channel whose limit is to be returned
197+
*
198+
* @Return: The maximum TRE count per transaction on the channel
199+
*/
200+
u32 gsi_channel_trans_tre_max(struct gsi *gsi, u32 channel_id);
201+
202+
/**
203+
* gsi_channel_start() - Start an allocated GSI channel
204+
* @gsi: GSI pointer
205+
* @channel_id: Channel to start
206+
*
207+
* @Return: 0 if successful, or a negative error code
208+
*/
209+
int gsi_channel_start(struct gsi *gsi, u32 channel_id);
210+
211+
/**
212+
* gsi_channel_stop() - Stop a started GSI channel
213+
* @gsi: GSI pointer returned by gsi_setup()
214+
* @channel_id: Channel to stop
215+
*
216+
* @Return: 0 if successful, or a negative error code
217+
*/
218+
int gsi_channel_stop(struct gsi *gsi, u32 channel_id);
219+
220+
/**
221+
* gsi_channel_reset() - Reset an allocated GSI channel
222+
* @gsi: GSI pointer
223+
* @channel_id: Channel to be reset
224+
* @db_enable: Whether doorbell engine should be enabled
225+
*
226+
* Reset a channel and reconfigure it. The @db_enable flag indicates
227+
* whether the doorbell engine will be enabled following reconfiguration.
228+
*
229+
* GSI hardware relinquishes ownership of all pending receive buffer
230+
* transactions and they will complete with their cancelled flag set.
231+
*/
232+
void gsi_channel_reset(struct gsi *gsi, u32 channel_id, bool db_enable);
233+
234+
int gsi_channel_suspend(struct gsi *gsi, u32 channel_id, bool stop);
235+
int gsi_channel_resume(struct gsi *gsi, u32 channel_id, bool start);
236+
237+
/**
238+
* gsi_init() - Initialize the GSI subsystem
239+
* @gsi: Address of GSI structure embedded in an IPA structure
240+
* @pdev: IPA platform device
241+
*
242+
* @Return: 0 if successful, or a negative error code
243+
*
244+
* Early stage initialization of the GSI subsystem, performing tasks
245+
* that can be done before the GSI hardware is ready to use.
246+
*/
247+
int gsi_init(struct gsi *gsi, struct platform_device *pdev, bool prefetch,
248+
u32 count, const struct ipa_gsi_endpoint_data *data,
249+
bool modem_alloc);
250+
251+
/**
252+
* gsi_exit() - Exit the GSI subsystem
253+
* @gsi: GSI address previously passed to a successful gsi_init() call
254+
*/
255+
void gsi_exit(struct gsi *gsi);
256+
257+
#endif /* _GSI_H_ */

drivers/net/ipa/gsi_private.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
4+
* Copyright (C) 2018-2020 Linaro Ltd.
5+
*/
6+
#ifndef _GSI_PRIVATE_H_
7+
#define _GSI_PRIVATE_H_
8+
9+
/* === Only "gsi.c" and "gsi_trans.c" should include this file === */
10+
11+
#include <linux/types.h>
12+
13+
struct gsi_trans;
14+
struct gsi_ring;
15+
struct gsi_channel;
16+
17+
#define GSI_RING_ELEMENT_SIZE 16 /* bytes */
18+
19+
/* Return the entry that follows one provided in a transaction pool */
20+
void *gsi_trans_pool_next(struct gsi_trans_pool *pool, void *element);
21+
22+
/**
23+
* gsi_trans_move_complete() - Mark a GSI transaction completed
24+
* @trans: Transaction to commit
25+
*/
26+
void gsi_trans_move_complete(struct gsi_trans *trans);
27+
28+
/**
29+
* gsi_trans_move_polled() - Mark a transaction polled
30+
* @trans: Transaction to update
31+
*/
32+
void gsi_trans_move_polled(struct gsi_trans *trans);
33+
34+
/**
35+
* gsi_trans_complete() - Complete a GSI transaction
36+
* @trans: Transaction to complete
37+
*
38+
* Marks a transaction complete (including freeing it).
39+
*/
40+
void gsi_trans_complete(struct gsi_trans *trans);
41+
42+
/**
43+
* gsi_channel_trans_mapped() - Return a transaction mapped to a TRE index
44+
* @channel: Channel associated with the transaction
45+
* @index: Index of the TRE having a transaction
46+
*
47+
* @Return: The GSI transaction pointer associated with the TRE index
48+
*/
49+
struct gsi_trans *gsi_channel_trans_mapped(struct gsi_channel *channel,
50+
u32 index);
51+
52+
/**
53+
* gsi_channel_trans_complete() - Return a channel's next completed transaction
54+
* @channel: Channel whose next transaction is to be returned
55+
*
56+
* @Return: The next completed transaction, or NULL if nothing new
57+
*/
58+
struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel);
59+
60+
/**
61+
* gsi_channel_trans_cancel_pending() - Cancel pending transactions
62+
* @channel: Channel whose pending transactions should be cancelled
63+
*
64+
* Cancel all pending transactions on a channel. These are transactions
65+
* that have been committed but not yet completed. This is required when
66+
* the channel gets reset. At that time all pending transactions will be
67+
* marked as cancelled.
68+
*
69+
* NOTE: Transactions already complete at the time of this call are
70+
* unaffected.
71+
*/
72+
void gsi_channel_trans_cancel_pending(struct gsi_channel *channel);
73+
74+
/**
75+
* gsi_channel_trans_init() - Initialize a channel's GSI transaction info
76+
* @gsi: GSI pointer
77+
* @channel_id: Channel number
78+
*
79+
* @Return: 0 if successful, or -ENOMEM on allocation failure
80+
*
81+
* Creates and sets up information for managing transactions on a channel
82+
*/
83+
int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id);
84+
85+
/**
86+
* gsi_channel_trans_exit() - Inverse of gsi_channel_trans_init()
87+
* @channel: Channel whose transaction information is to be cleaned up
88+
*/
89+
void gsi_channel_trans_exit(struct gsi_channel *channel);
90+
91+
/**
92+
* gsi_channel_doorbell() - Ring a channel's doorbell
93+
* @channel: Channel whose doorbell should be rung
94+
*
95+
* Rings a channel's doorbell to inform the GSI hardware that new
96+
* transactions (TREs, really) are available for it to process.
97+
*/
98+
void gsi_channel_doorbell(struct gsi_channel *channel);
99+
100+
/**
101+
* gsi_ring_virt() - Return virtual address for a ring entry
102+
* @ring: Ring whose address is to be translated
103+
* @addr: Index (slot number) of entry
104+
*/
105+
void *gsi_ring_virt(struct gsi_ring *ring, u32 index);
106+
107+
/**
108+
* gsi_channel_tx_queued() - Report the number of bytes queued to hardware
109+
* @channel: Channel whose bytes have been queued
110+
*
111+
* This arranges for the the number of transactions and bytes for
112+
* transfer that have been queued to hardware to be reported. It
113+
* passes this information up the network stack so it can be used to
114+
* throttle transmissions.
115+
*/
116+
void gsi_channel_tx_queued(struct gsi_channel *channel);
117+
118+
#endif /* _GSI_PRIVATE_H_ */

0 commit comments

Comments
 (0)