xref: /linux/drivers/net/ipa/ipa_cmd.h (revision 95298d63c67673c654c08952672d016212b26054)
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			= 0,
31 	IPA_CMD_IP_V4_FILTER_INIT	= 3,
32 	IPA_CMD_IP_V6_FILTER_INIT	= 4,
33 	IPA_CMD_IP_V4_ROUTING_INIT	= 7,
34 	IPA_CMD_IP_V6_ROUTING_INIT	= 8,
35 	IPA_CMD_HDR_INIT_LOCAL		= 9,
36 	IPA_CMD_REGISTER_WRITE		= 12,
37 	IPA_CMD_IP_PACKET_INIT		= 16,
38 	IPA_CMD_DMA_SHARED_MEM		= 19,
39 	IPA_CMD_IP_PACKET_TAG_STATUS	= 20,
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 
54 #ifdef IPA_VALIDATE
55 
56 /**
57  * ipa_cmd_table_valid() - Validate a memory region holding a table
58  * @ipa:	- IPA pointer
59  * @mem:	- IPA memory region descriptor
60  * @route:	- Whether the region holds a route or filter table
61  * @ipv6:	- Whether the table is for IPv6 or IPv4
62  * @hashed:	- Whether the table is hashed or non-hashed
63  *
64  * @Return:	true if region is valid, false otherwise
65  */
66 bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
67 			    bool route, bool ipv6, bool hashed);
68 
69 /**
70  * ipa_cmd_data_valid() - Validate command-realted configuration is valid
71  * @ipa:	- IPA pointer
72  *
73  * @Return:	true if assumptions required for command are valid
74  */
75 bool ipa_cmd_data_valid(struct ipa *ipa);
76 
77 #else /* !IPA_VALIDATE */
78 
79 static inline bool ipa_cmd_table_valid(struct ipa *ipa,
80 				       const struct ipa_mem *mem, bool route,
81 				       bool ipv6, bool hashed)
82 {
83 	return true;
84 }
85 
86 static inline bool ipa_cmd_data_valid(struct ipa *ipa)
87 {
88 	return true;
89 }
90 
91 #endif /* !IPA_VALIDATE */
92 
93 /**
94  * ipa_cmd_pool_init() - initialize command channel pools
95  * @channel:	AP->IPA command TX GSI channel pointer
96  * @tre_count:	Number of pool elements to allocate
97  *
98  * @Return:	0 if successful, or a negative error code
99  */
100 int ipa_cmd_pool_init(struct gsi_channel *gsi_channel, u32 tre_count);
101 
102 /**
103  * ipa_cmd_pool_exit() - Inverse of ipa_cmd_pool_init()
104  * @channel:	AP->IPA command TX GSI channel pointer
105  */
106 void ipa_cmd_pool_exit(struct gsi_channel *channel);
107 
108 /**
109  * ipa_cmd_table_init_add() - Add table init command to a transaction
110  * @trans:	GSI transaction
111  * @opcode:	IPA immediate command opcode
112  * @size:	Size of non-hashed routing table memory
113  * @offset:	Offset in IPA shared memory of non-hashed routing table memory
114  * @addr:	DMA address of non-hashed table data to write
115  * @hash_size:	Size of hashed routing table memory
116  * @hash_offset: Offset in IPA shared memory of hashed routing table memory
117  * @hash_addr:	DMA address of hashed table data to write
118  *
119  * If hash_size is 0, hash_offset and hash_addr are ignored.
120  */
121 void ipa_cmd_table_init_add(struct gsi_trans *trans, enum ipa_cmd_opcode opcode,
122 			    u16 size, u32 offset, dma_addr_t addr,
123 			    u16 hash_size, u32 hash_offset,
124 			    dma_addr_t hash_addr);
125 
126 /**
127  * ipa_cmd_hdr_init_local_add() - Add a header init command to a transaction
128  * @ipa:	IPA structure
129  * @offset:	Offset of header memory in IPA local space
130  * @size:	Size of header memory
131  * @addr:	DMA address of buffer to be written from
132  *
133  * Defines and fills the location in IPA memory to use for headers.
134  */
135 void ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size,
136 				dma_addr_t addr);
137 
138 /**
139  * ipa_cmd_register_write_add() - Add a register write command to a transaction
140  * @trans:	GSI transaction
141  * @offset:	Offset of register to be written
142  * @value:	Value to be written
143  * @mask:	Mask of bits in register to update with bits from value
144  * @clear_full: Pipeline clear option; true means full pipeline clear
145  */
146 void ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value,
147 				u32 mask, bool clear_full);
148 
149 /**
150  * ipa_cmd_dma_shared_mem_add() - Add a DMA memory command to a transaction
151  * @trans:	GSI transaction
152  * @offset:	Offset of IPA memory to be read or written
153  * @size:	Number of bytes of memory to be transferred
154  * @addr:	DMA address of buffer to be read into or written from
155  * @toward_ipa:	true means write to IPA memory; false means read
156  */
157 void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset,
158 				u16 size, dma_addr_t addr, bool toward_ipa);
159 
160 /**
161  * ipa_cmd_tag_process_add() - Add IPA tag process commands to a transaction
162  * @trans:	GSI transaction
163  */
164 void ipa_cmd_tag_process_add(struct gsi_trans *trans);
165 
166 /**
167  * ipa_cmd_tag_process_add_count() - Number of commands in a tag process
168  *
169  * @Return:	The number of elements to allocate in a transaction
170  *		to hold tag process commands
171  */
172 u32 ipa_cmd_tag_process_count(void);
173 
174 /**
175  * ipa_cmd_trans_alloc() - Allocate a transaction for the command TX endpoint
176  * @ipa:	IPA pointer
177  * @tre_count:	Number of elements in the transaction
178  *
179  * @Return:	A GSI transaction structure, or a null pointer if all
180  *		available transactions are in use
181  */
182 struct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count);
183 
184 #endif /* _IPA_CMD_H_ */
185