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