xref: /openbmc/linux/drivers/net/ipa/ipa_cmd.h (revision 31e67366)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2019-2020 Linaro Ltd.
5  */
6 #ifndef _IPA_CMD_H_
7 #define _IPA_CMD_H_
8 
9 #include <linux/types.h>
10 #include <linux/dma-direction.h>
11 
12 struct sk_buff;
13 struct scatterlist;
14 
15 struct ipa;
16 struct ipa_mem;
17 struct gsi_trans;
18 struct gsi_channel;
19 
20 /**
21  * enum ipa_cmd_opcode:	IPA immediate commands
22  *
23  * All immediate commands are issued using the AP command TX endpoint.
24  * The numeric values here are the opcodes for IPA v3.5.1 hardware.
25  *
26  * IPA_CMD_NONE is a special (invalid) value that's used to indicate
27  * a request is *not* an immediate command.
28  */
29 enum ipa_cmd_opcode {
30 	IPA_CMD_NONE			= 0x0,
31 	IPA_CMD_IP_V4_FILTER_INIT	= 0x3,
32 	IPA_CMD_IP_V6_FILTER_INIT	= 0x4,
33 	IPA_CMD_IP_V4_ROUTING_INIT	= 0x7,
34 	IPA_CMD_IP_V6_ROUTING_INIT	= 0x8,
35 	IPA_CMD_HDR_INIT_LOCAL		= 0x9,
36 	IPA_CMD_REGISTER_WRITE		= 0xc,
37 	IPA_CMD_IP_PACKET_INIT		= 0x10,
38 	IPA_CMD_DMA_SHARED_MEM		= 0x13,
39 	IPA_CMD_IP_PACKET_TAG_STATUS	= 0x14,
40 };
41 
42 /**
43  * struct ipa_cmd_info - information needed for an IPA immediate command
44  *
45  * @opcode:	The command opcode.
46  * @direction:	Direction of data transfer for DMA commands
47  */
48 struct ipa_cmd_info {
49 	enum ipa_cmd_opcode opcode;
50 	enum dma_data_direction direction;
51 };
52 
53 #ifdef IPA_VALIDATE
54 
55 /**
56  * ipa_cmd_table_valid() - Validate a memory region holding a table
57  * @ipa:	- IPA pointer
58  * @mem:	- IPA memory region descriptor
59  * @route:	- Whether the region holds a route or filter table
60  * @ipv6:	- Whether the table is for IPv6 or IPv4
61  * @hashed:	- Whether the table is hashed or non-hashed
62  *
63  * Return:	true if region is valid, false otherwise
64  */
65 bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
66 			    bool route, bool ipv6, bool hashed);
67 
68 /**
69  * ipa_cmd_data_valid() - Validate command-realted configuration is valid
70  * @ipa:	- IPA pointer
71  *
72  * Return:	true if assumptions required for command are valid
73  */
74 bool ipa_cmd_data_valid(struct ipa *ipa);
75 
76 #else /* !IPA_VALIDATE */
77 
78 static inline bool ipa_cmd_table_valid(struct ipa *ipa,
79 				       const struct ipa_mem *mem, bool route,
80 				       bool ipv6, bool hashed)
81 {
82 	return true;
83 }
84 
85 static inline bool ipa_cmd_data_valid(struct ipa *ipa)
86 {
87 	return true;
88 }
89 
90 #endif /* !IPA_VALIDATE */
91 
92 /**
93  * ipa_cmd_pool_init() - initialize command channel pools
94  * @channel:	AP->IPA command TX GSI channel pointer
95  * @tre_count:	Number of pool elements to allocate
96  *
97  * Return:	0 if successful, or a negative error code
98  */
99 int ipa_cmd_pool_init(struct gsi_channel *gsi_channel, u32 tre_count);
100 
101 /**
102  * ipa_cmd_pool_exit() - Inverse of ipa_cmd_pool_init()
103  * @channel:	AP->IPA command TX GSI channel pointer
104  */
105 void ipa_cmd_pool_exit(struct gsi_channel *channel);
106 
107 /**
108  * ipa_cmd_table_init_add() - Add table init command to a transaction
109  * @trans:	GSI transaction
110  * @opcode:	IPA immediate command opcode
111  * @size:	Size of non-hashed routing table memory
112  * @offset:	Offset in IPA shared memory of non-hashed routing table memory
113  * @addr:	DMA address of non-hashed table data to write
114  * @hash_size:	Size of hashed routing table memory
115  * @hash_offset: Offset in IPA shared memory of hashed routing table memory
116  * @hash_addr:	DMA address of hashed table data to write
117  *
118  * If hash_size is 0, hash_offset and hash_addr are ignored.
119  */
120 void ipa_cmd_table_init_add(struct gsi_trans *trans, enum ipa_cmd_opcode opcode,
121 			    u16 size, u32 offset, dma_addr_t addr,
122 			    u16 hash_size, u32 hash_offset,
123 			    dma_addr_t hash_addr);
124 
125 /**
126  * ipa_cmd_hdr_init_local_add() - Add a header init command to a transaction
127  * @ipa:	IPA structure
128  * @offset:	Offset of header memory in IPA local space
129  * @size:	Size of header memory
130  * @addr:	DMA address of buffer to be written from
131  *
132  * Defines and fills the location in IPA memory to use for headers.
133  */
134 void ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size,
135 				dma_addr_t addr);
136 
137 /**
138  * ipa_cmd_register_write_add() - Add a register write command to a transaction
139  * @trans:	GSI transaction
140  * @offset:	Offset of register to be written
141  * @value:	Value to be written
142  * @mask:	Mask of bits in register to update with bits from value
143  * @clear_full: Pipeline clear option; true means full pipeline clear
144  */
145 void ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value,
146 				u32 mask, bool clear_full);
147 
148 /**
149  * ipa_cmd_dma_shared_mem_add() - Add a DMA memory command to a transaction
150  * @trans:	GSI transaction
151  * @offset:	Offset of IPA memory to be read or written
152  * @size:	Number of bytes of memory to be transferred
153  * @addr:	DMA address of buffer to be read into or written from
154  * @toward_ipa:	true means write to IPA memory; false means read
155  */
156 void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset,
157 				u16 size, dma_addr_t addr, bool toward_ipa);
158 
159 /**
160  * ipa_cmd_pipeline_clear_add() - Add pipeline clear commands to a transaction
161  * @trans:	GSI transaction
162  */
163 void ipa_cmd_pipeline_clear_add(struct gsi_trans *trans);
164 
165 /**
166  * ipa_cmd_pipeline_clear_count() - # commands required to clear pipeline
167  *
168  * Return:	The number of elements to allocate in a transaction
169  *		to hold commands to clear the pipeline
170  */
171 u32 ipa_cmd_pipeline_clear_count(void);
172 
173 /**
174  * ipa_cmd_pipeline_clear_wait() - Wait pipeline clear to complete
175  * @ipa:	- IPA pointer
176  */
177 void ipa_cmd_pipeline_clear_wait(struct ipa *ipa);
178 
179 /**
180  * ipa_cmd_pipeline_clear() - Clear the hardware pipeline
181  * @ipa:	- IPA pointer
182  */
183 void ipa_cmd_pipeline_clear(struct ipa *ipa);
184 
185 /**
186  * ipa_cmd_trans_alloc() - Allocate a transaction for the command TX endpoint
187  * @ipa:	IPA pointer
188  * @tre_count:	Number of elements in the transaction
189  *
190  * Return:	A GSI transaction structure, or a null pointer if all
191  *		available transactions are in use
192  */
193 struct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count);
194 
195 #endif /* _IPA_CMD_H_ */
196