1 /* SPDX-License-Identifier: GPL-2.0 */
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2019-2020 Linaro Ltd.
9 #include <linux/types.h>
10 #include <linux/refcount.h>
11 #include <linux/completion.h>
12 #include <linux/dma-direction.h>
22 struct gsi_trans_pool;
25 * struct gsi_trans - a GSI transaction
27 * Most fields in this structure for internal use by the transaction core code:
28 * @links: Links for channel transaction lists by state
30 * @channel_id: Channel number transaction is associated with
31 * @cancelled: If set by the core code, transaction was cancelled
32 * @tre_count: Number of TREs reserved for this transaction
33 * @used: Number of TREs *used* (could be less than tre_count)
34 * @len: Total # of transfer bytes represented in sgl[] (set by core)
35 * @data: Preserved but not touched by the core transaction code
36 * @sgl: An array of scatter/gather entries managed by core code
37 * @info: Array of command information structures (command channel)
38 * @direction: DMA transfer direction (DMA_NONE for commands)
39 * @refcount: Reference count used for destruction
40 * @completion: Completed when the transaction completes
41 * @byte_count: TX channel byte count recorded when transaction committed
42 * @trans_count: Channel transaction count when committed (for BQL accounting)
44 * The size used for some fields in this structure were chosen to ensure
45 * the full structure size is no larger than 128 bytes.
48 struct list_head links; /* gsi_channel lists */
53 bool cancelled; /* true if transaction was cancelled */
55 u8 tre_count; /* # TREs requested */
56 u8 used; /* # entries used in sgl[] */
57 u32 len; /* total # bytes across sgl[] */
60 struct scatterlist *sgl;
61 struct ipa_cmd_info *info; /* array of entries, or null */
62 enum dma_data_direction direction;
65 struct completion completion;
67 u64 byte_count; /* channel byte_count when committed */
68 u64 trans_count; /* channel trans_count when committed */
72 * gsi_trans_pool_init() - Initialize a pool of structures for transactions
74 * @size: Size of elements in the pool
75 * @count: Minimum number of elements in the pool
76 * @max_alloc: Maximum number of elements allocated at a time from pool
78 * Return: 0 if successful, or a negative error code
80 int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t size, u32 count,
84 * gsi_trans_pool_alloc() - Allocate one or more elements from a pool
86 * @count: Number of elements to allocate from the pool
88 * Return: Virtual address of element(s) allocated from the pool
90 void *gsi_trans_pool_alloc(struct gsi_trans_pool *pool, u32 count);
93 * gsi_trans_pool_exit() - Inverse of gsi_trans_pool_init()
96 void gsi_trans_pool_exit(struct gsi_trans_pool *pool);
99 * gsi_trans_pool_init_dma() - Initialize a pool of DMA-able structures
100 * @dev: Device used for DMA
101 * @pool: Pool pointer
102 * @size: Size of elements in the pool
103 * @count: Minimum number of elements in the pool
104 * @max_alloc: Maximum number of elements allocated at a time from pool
106 * Return: 0 if successful, or a negative error code
108 * Structures in this pool reside in DMA-coherent memory.
110 int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,
111 size_t size, u32 count, u32 max_alloc);
114 * gsi_trans_pool_alloc_dma() - Allocate an element from a DMA pool
115 * @pool: DMA pool pointer
116 * @addr: DMA address "handle" associated with the allocation
118 * Return: Virtual address of element allocated from the pool
120 * Only one element at a time may be allocated from a DMA pool.
122 void *gsi_trans_pool_alloc_dma(struct gsi_trans_pool *pool, dma_addr_t *addr);
125 * gsi_trans_pool_exit() - Inverse of gsi_trans_pool_init()
126 * @pool: Pool pointer
128 void gsi_trans_pool_exit_dma(struct device *dev, struct gsi_trans_pool *pool);
131 * gsi_channel_trans_alloc() - Allocate a GSI transaction on a channel
133 * @channel_id: Channel the transaction is associated with
134 * @tre_count: Number of elements in the transaction
135 * @direction: DMA direction for entire SGL (or DMA_NONE)
137 * Return: A GSI transaction structure, or a null pointer if all
138 * available transactions are in use
140 struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id,
142 enum dma_data_direction direction);
145 * gsi_trans_free() - Free a previously-allocated GSI transaction
146 * @trans: Transaction to be freed
148 void gsi_trans_free(struct gsi_trans *trans);
151 * gsi_trans_cmd_add() - Add an immediate command to a transaction
152 * @trans: Transaction
153 * @buf: Buffer pointer for command payload
154 * @size: Number of bytes in buffer
155 * @addr: DMA address for payload
156 * @direction: Direction of DMA transfer (or DMA_NONE if none required)
157 * @opcode: IPA immediate command opcode
159 void gsi_trans_cmd_add(struct gsi_trans *trans, void *buf, u32 size,
160 dma_addr_t addr, enum dma_data_direction direction,
161 enum ipa_cmd_opcode opcode);
164 * gsi_trans_page_add() - Add a page transfer to a transaction
165 * @trans: Transaction
166 * @page: Page pointer
167 * @size: Number of bytes (starting at offset) to transfer
168 * @offset: Offset within page for start of transfer
170 int gsi_trans_page_add(struct gsi_trans *trans, struct page *page, u32 size,
174 * gsi_trans_skb_add() - Add a socket transfer to a transaction
175 * @trans: Transaction
176 * @skb: Socket buffer for transfer (outbound)
178 * Return: 0, or -EMSGSIZE if socket data won't fit in transaction.
180 int gsi_trans_skb_add(struct gsi_trans *trans, struct sk_buff *skb);
183 * gsi_trans_commit() - Commit a GSI transaction
184 * @trans: Transaction to commit
185 * @ring_db: Whether to tell the hardware about these queued transfers
187 void gsi_trans_commit(struct gsi_trans *trans, bool ring_db);
190 * gsi_trans_commit_wait() - Commit a GSI transaction and wait for it
192 * @trans: Transaction to commit
194 void gsi_trans_commit_wait(struct gsi_trans *trans);
197 * gsi_trans_commit_wait_timeout() - Commit a GSI transaction and wait for
198 * it to complete, with timeout
199 * @trans: Transaction to commit
200 * @timeout: Timeout period (in milliseconds)
202 int gsi_trans_commit_wait_timeout(struct gsi_trans *trans,
203 unsigned long timeout);
206 * gsi_trans_read_byte() - Issue a single byte read TRE on a channel
208 * @channel_id: Channel on which to read a byte
209 * @addr: DMA address into which to transfer the one byte
211 * This is not a transaction operation at all. It's defined here because
212 * it needs to be done in coordination with other transaction activity.
214 int gsi_trans_read_byte(struct gsi *gsi, u32 channel_id, dma_addr_t addr);
217 * gsi_trans_read_byte_done() - Clean up after a single byte read TRE
219 * @channel_id: Channel on which byte was read
221 * This function needs to be called to signal that the work related
222 * to reading a byte initiated by gsi_trans_read_byte() is complete.
224 void gsi_trans_read_byte_done(struct gsi *gsi, u32 channel_id);
226 #endif /* _GSI_TRANS_H_ */