blob: 4917525b3a47c73918a8ae09a6bbfaefd06b95e6 [file] [log] [blame]
Alex Elder731c46e2020-03-05 22:28:26 -06001/* 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
12struct sk_buff;
13struct scatterlist;
14
15struct ipa;
16struct ipa_mem;
17struct gsi_trans;
18struct 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 */
29enum 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_TASK_32B_ADDR = 17,
39 IPA_CMD_DMA_SHARED_MEM = 19,
40 IPA_CMD_IP_PACKET_TAG_STATUS = 20,
41};
42
43/**
44 * struct ipa_cmd_info - information needed for an IPA immediate command
45 *
46 * @opcode: The command opcode.
47 * @direction: Direction of data transfer for DMA commands
48 */
49struct ipa_cmd_info {
50 enum ipa_cmd_opcode opcode;
51 enum dma_data_direction direction;
52};
53
54
55#ifdef IPA_VALIDATE
56
57/**
58 * ipa_cmd_table_valid() - Validate a memory region holding a table
59 * @ipa: - IPA pointer
60 * @mem: - IPA memory region descriptor
61 * @route: - Whether the region holds a route or filter table
62 * @ipv6: - Whether the table is for IPv6 or IPv4
63 * @hashed: - Whether the table is hashed or non-hashed
64 *
65 * @Return: true if region is valid, false otherwise
66 */
67bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
68 bool route, bool ipv6, bool hashed);
69
70/**
71 * ipa_cmd_data_valid() - Validate command-realted configuration is valid
72 * @ipa: - IPA pointer
73 *
74 * @Return: true if assumptions required for command are valid
75 */
76bool ipa_cmd_data_valid(struct ipa *ipa);
77
78#else /* !IPA_VALIDATE */
79
80static inline bool ipa_cmd_table_valid(struct ipa *ipa,
81 const struct ipa_mem *mem, bool route,
82 bool ipv6, bool hashed)
83{
84 return true;
85}
86
87static inline bool ipa_cmd_data_valid(struct ipa *ipa)
88{
89 return true;
90}
91
92#endif /* !IPA_VALIDATE */
93
94/**
95 * ipa_cmd_pool_init() - initialize command channel pools
96 * @channel: AP->IPA command TX GSI channel pointer
97 * @tre_count: Number of pool elements to allocate
98 *
99 * @Return: 0 if successful, or a negative error code
100 */
101int ipa_cmd_pool_init(struct gsi_channel *gsi_channel, u32 tre_count);
102
103/**
104 * ipa_cmd_pool_exit() - Inverse of ipa_cmd_pool_init()
105 * @channel: AP->IPA command TX GSI channel pointer
106 */
107void ipa_cmd_pool_exit(struct gsi_channel *channel);
108
109/**
110 * ipa_cmd_table_init_add() - Add table init command to a transaction
111 * @trans: GSI transaction
112 * @opcode: IPA immediate command opcode
113 * @size: Size of non-hashed routing table memory
114 * @offset: Offset in IPA shared memory of non-hashed routing table memory
115 * @addr: DMA address of non-hashed table data to write
116 * @hash_size: Size of hashed routing table memory
117 * @hash_offset: Offset in IPA shared memory of hashed routing table memory
118 * @hash_addr: DMA address of hashed table data to write
119 *
120 * If hash_size is 0, hash_offset and hash_addr are ignored.
121 */
122void ipa_cmd_table_init_add(struct gsi_trans *trans, enum ipa_cmd_opcode opcode,
123 u16 size, u32 offset, dma_addr_t addr,
124 u16 hash_size, u32 hash_offset,
125 dma_addr_t hash_addr);
126
127/**
128 * ipa_cmd_hdr_init_local_add() - Add a header init command to a transaction
129 * @ipa: IPA structure
130 * @offset: Offset of header memory in IPA local space
131 * @size: Size of header memory
132 * @addr: DMA address of buffer to be written from
133 *
134 * Defines and fills the location in IPA memory to use for headers.
135 */
136void ipa_cmd_hdr_init_local_add(struct gsi_trans *trans, u32 offset, u16 size,
137 dma_addr_t addr);
138
139/**
140 * ipa_cmd_register_write_add() - Add a register write command to a transaction
141 * @trans: GSI transaction
142 * @offset: Offset of register to be written
143 * @value: Value to be written
144 * @mask: Mask of bits in register to update with bits from value
145 * @clear_full: Pipeline clear option; true means full pipeline clear
146 */
147void ipa_cmd_register_write_add(struct gsi_trans *trans, u32 offset, u32 value,
148 u32 mask, bool clear_full);
149
150/**
151 * ipa_cmd_dma_task_32b_addr_add() - Add a 32-bit DMA command to a transaction
152 * @trans: GSi transaction
153 * @size: Number of bytes to be 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 */
157void ipa_cmd_dma_task_32b_addr_add(struct gsi_trans *trans, u16 size,
158 dma_addr_t addr, bool toward_ipa);
159
160/**
161 * ipa_cmd_dma_shared_mem_add() - Add a DMA memory command to a transaction
162 * @trans: GSI transaction
163 * @offset: Offset of IPA memory to be read or written
164 * @size: Number of bytes of memory to be transferred
165 * @addr: DMA address of buffer to be read into or written from
166 * @toward_ipa: true means write to IPA memory; false means read
167 */
168void ipa_cmd_dma_shared_mem_add(struct gsi_trans *trans, u32 offset,
169 u16 size, dma_addr_t addr, bool toward_ipa);
170
171/**
172 * ipa_cmd_tag_process_add() - Add IPA tag process commands to a transaction
173 * @trans: GSI transaction
174 */
175void ipa_cmd_tag_process_add(struct gsi_trans *trans);
176
177/**
178 * ipa_cmd_tag_process_add_count() - Number of commands in a tag process
179 *
180 * @Return: The number of elements to allocate in a transaction
181 * to hold tag process commands
182 */
183u32 ipa_cmd_tag_process_count(void);
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 */
193struct gsi_trans *ipa_cmd_trans_alloc(struct ipa *ipa, u32 tre_count);
194
195#endif /* _IPA_CMD_H_ */