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