![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 0003 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. 0004 * Copyright (C) 2019-2020 Linaro Ltd. 0005 */ 0006 #ifndef _GSI_TRANS_H_ 0007 #define _GSI_TRANS_H_ 0008 0009 #include <linux/types.h> 0010 #include <linux/refcount.h> 0011 #include <linux/completion.h> 0012 #include <linux/dma-direction.h> 0013 0014 #include "ipa_cmd.h" 0015 0016 struct page; 0017 struct scatterlist; 0018 struct device; 0019 struct sk_buff; 0020 0021 struct gsi; 0022 struct gsi_trans; 0023 struct gsi_trans_pool; 0024 0025 /* Maximum number of TREs in an IPA immediate command transaction */ 0026 #define IPA_COMMAND_TRANS_TRE_MAX 8 0027 0028 /** 0029 * struct gsi_trans - a GSI transaction 0030 * 0031 * Most fields in this structure for internal use by the transaction core code: 0032 * @links: Links for channel transaction lists by state 0033 * @gsi: GSI pointer 0034 * @channel_id: Channel number transaction is associated with 0035 * @cancelled: If set by the core code, transaction was cancelled 0036 * @rsvd_count: Number of TREs reserved for this transaction 0037 * @used_count: Number of TREs *used* (could be less than rsvd_count) 0038 * @len: Number of bytes sent or received by the transaction 0039 * @data: Preserved but not touched by the core transaction code 0040 * @cmd_opcode: Array of command opcodes (command channel only) 0041 * @sgl: An array of scatter/gather entries managed by core code 0042 * @direction: DMA transfer direction (DMA_NONE for commands) 0043 * @refcount: Reference count used for destruction 0044 * @completion: Completed when the transaction completes 0045 * @byte_count: TX channel byte count recorded when transaction committed 0046 * @trans_count: Channel transaction count when committed (for BQL accounting) 0047 * 0048 * The @len field is set when the transaction is committed. For RX 0049 * transactions it is updated later to reflect the actual number of bytes 0050 * received. 0051 */ 0052 struct gsi_trans { 0053 struct list_head links; /* gsi_channel lists */ 0054 0055 struct gsi *gsi; 0056 u8 channel_id; 0057 0058 bool cancelled; /* true if transaction was cancelled */ 0059 0060 u8 rsvd_count; /* # TREs requested */ 0061 u8 used_count; /* # entries used in sgl[] */ 0062 u32 len; /* total # bytes across sgl[] */ 0063 0064 union { 0065 void *data; 0066 u8 cmd_opcode[IPA_COMMAND_TRANS_TRE_MAX]; 0067 }; 0068 struct scatterlist *sgl; 0069 enum dma_data_direction direction; 0070 0071 refcount_t refcount; 0072 struct completion completion; 0073 0074 u64 byte_count; /* channel byte_count when committed */ 0075 u64 trans_count; /* channel trans_count when committed */ 0076 }; 0077 0078 /** 0079 * gsi_trans_pool_init() - Initialize a pool of structures for transactions 0080 * @pool: GSI transaction poll pointer 0081 * @size: Size of elements in the pool 0082 * @count: Minimum number of elements in the pool 0083 * @max_alloc: Maximum number of elements allocated at a time from pool 0084 * 0085 * Return: 0 if successful, or a negative error code 0086 */ 0087 int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t size, u32 count, 0088 u32 max_alloc); 0089 0090 /** 0091 * gsi_trans_pool_alloc() - Allocate one or more elements from a pool 0092 * @pool: Pool pointer 0093 * @count: Number of elements to allocate from the pool 0094 * 0095 * Return: Virtual address of element(s) allocated from the pool 0096 */ 0097 void *gsi_trans_pool_alloc(struct gsi_trans_pool *pool, u32 count); 0098 0099 /** 0100 * gsi_trans_pool_exit() - Inverse of gsi_trans_pool_init() 0101 * @pool: Pool pointer 0102 */ 0103 void gsi_trans_pool_exit(struct gsi_trans_pool *pool); 0104 0105 /** 0106 * gsi_trans_pool_init_dma() - Initialize a pool of DMA-able structures 0107 * @dev: Device used for DMA 0108 * @pool: Pool pointer 0109 * @size: Size of elements in the pool 0110 * @count: Minimum number of elements in the pool 0111 * @max_alloc: Maximum number of elements allocated at a time from pool 0112 * 0113 * Return: 0 if successful, or a negative error code 0114 * 0115 * Structures in this pool reside in DMA-coherent memory. 0116 */ 0117 int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool, 0118 size_t size, u32 count, u32 max_alloc); 0119 0120 /** 0121 * gsi_trans_pool_alloc_dma() - Allocate an element from a DMA pool 0122 * @pool: DMA pool pointer 0123 * @addr: DMA address "handle" associated with the allocation 0124 * 0125 * Return: Virtual address of element allocated from the pool 0126 * 0127 * Only one element at a time may be allocated from a DMA pool. 0128 */ 0129 void *gsi_trans_pool_alloc_dma(struct gsi_trans_pool *pool, dma_addr_t *addr); 0130 0131 /** 0132 * gsi_trans_pool_exit_dma() - Inverse of gsi_trans_pool_init_dma() 0133 * @dev: Device used for DMA 0134 * @pool: Pool pointer 0135 */ 0136 void gsi_trans_pool_exit_dma(struct device *dev, struct gsi_trans_pool *pool); 0137 0138 /** 0139 * gsi_channel_trans_idle() - Return whether no transactions are allocated 0140 * @gsi: GSI pointer 0141 * @channel_id: Channel the transaction is associated with 0142 * 0143 * Return: True if no transactions are allocated, false otherwise 0144 * 0145 */ 0146 bool gsi_channel_trans_idle(struct gsi *gsi, u32 channel_id); 0147 0148 /** 0149 * gsi_channel_trans_alloc() - Allocate a GSI transaction on a channel 0150 * @gsi: GSI pointer 0151 * @channel_id: Channel the transaction is associated with 0152 * @tre_count: Number of elements in the transaction 0153 * @direction: DMA direction for entire SGL (or DMA_NONE) 0154 * 0155 * Return: A GSI transaction structure, or a null pointer if all 0156 * available transactions are in use 0157 */ 0158 struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, 0159 u32 tre_count, 0160 enum dma_data_direction direction); 0161 0162 /** 0163 * gsi_trans_free() - Free a previously-allocated GSI transaction 0164 * @trans: Transaction to be freed 0165 */ 0166 void gsi_trans_free(struct gsi_trans *trans); 0167 0168 /** 0169 * gsi_trans_cmd_add() - Add an immediate command to a transaction 0170 * @trans: Transaction 0171 * @buf: Buffer pointer for command payload 0172 * @size: Number of bytes in buffer 0173 * @addr: DMA address for payload 0174 * @opcode: IPA immediate command opcode 0175 */ 0176 void gsi_trans_cmd_add(struct gsi_trans *trans, void *buf, u32 size, 0177 dma_addr_t addr, enum ipa_cmd_opcode opcode); 0178 0179 /** 0180 * gsi_trans_page_add() - Add a page transfer to a transaction 0181 * @trans: Transaction 0182 * @page: Page pointer 0183 * @size: Number of bytes (starting at offset) to transfer 0184 * @offset: Offset within page for start of transfer 0185 */ 0186 int gsi_trans_page_add(struct gsi_trans *trans, struct page *page, u32 size, 0187 u32 offset); 0188 0189 /** 0190 * gsi_trans_skb_add() - Add a socket transfer to a transaction 0191 * @trans: Transaction 0192 * @skb: Socket buffer for transfer (outbound) 0193 * 0194 * Return: 0, or -EMSGSIZE if socket data won't fit in transaction. 0195 */ 0196 int gsi_trans_skb_add(struct gsi_trans *trans, struct sk_buff *skb); 0197 0198 /** 0199 * gsi_trans_commit() - Commit a GSI transaction 0200 * @trans: Transaction to commit 0201 * @ring_db: Whether to tell the hardware about these queued transfers 0202 */ 0203 void gsi_trans_commit(struct gsi_trans *trans, bool ring_db); 0204 0205 /** 0206 * gsi_trans_commit_wait() - Commit a GSI transaction and wait for it 0207 * to complete 0208 * @trans: Transaction to commit 0209 */ 0210 void gsi_trans_commit_wait(struct gsi_trans *trans); 0211 0212 /** 0213 * gsi_trans_read_byte() - Issue a single byte read TRE on a channel 0214 * @gsi: GSI pointer 0215 * @channel_id: Channel on which to read a byte 0216 * @addr: DMA address into which to transfer the one byte 0217 * 0218 * This is not a transaction operation at all. It's defined here because 0219 * it needs to be done in coordination with other transaction activity. 0220 */ 0221 int gsi_trans_read_byte(struct gsi *gsi, u32 channel_id, dma_addr_t addr); 0222 0223 /** 0224 * gsi_trans_read_byte_done() - Clean up after a single byte read TRE 0225 * @gsi: GSI pointer 0226 * @channel_id: Channel on which byte was read 0227 * 0228 * This function needs to be called to signal that the work related 0229 * to reading a byte initiated by gsi_trans_read_byte() is complete. 0230 */ 0231 void gsi_trans_read_byte_done(struct gsi *gsi, u32 channel_id); 0232 0233 #endif /* _GSI_TRANS_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |