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