blob: ee2704d62b501583ad5b020beb5b12c4bbc439b5 [file] [log] [blame]
Amir Levy9659e592016-10-27 18:08:27 +03001/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _IPAHAL_FLTRT_H_
14#define _IPAHAL_FLTRT_H_
15
16/*
17 * struct ipahal_fltrt_alloc_imgs_params - Params for tbls imgs allocations
18 * The allocation logic will allocate DMA memory representing the header.
19 * If the bodies are local (SRAM) the allocation will allocate
20 * a DMA buffers that would contain the content of these local tables in raw
21 * @ipt: IP version type
22 * @tbls_num: Number of tables to represent by the header
23 * @num_lcl_hash_tbls: Number of local (sram) hashable tables
24 * @num_lcl_nhash_tbls: Number of local (sram) non-hashable tables
25 * @total_sz_lcl_hash_tbls: Total size of local hashable tables
26 * @total_sz_lcl_nhash_tbls: Total size of local non-hashable tables
27 * @hash_hdr/nhash_hdr: OUT params for the header structures
28 * @hash_bdy/nhash_bdy: OUT params for the local body structures
29 */
30struct ipahal_fltrt_alloc_imgs_params {
31 enum ipa_ip_type ipt;
32 u32 tbls_num;
33 u32 num_lcl_hash_tbls;
34 u32 num_lcl_nhash_tbls;
35 u32 total_sz_lcl_hash_tbls;
36 u32 total_sz_lcl_nhash_tbls;
37
38 /* OUT PARAMS */
39 struct ipa_mem_buffer hash_hdr;
40 struct ipa_mem_buffer nhash_hdr;
41 struct ipa_mem_buffer hash_bdy;
42 struct ipa_mem_buffer nhash_bdy;
43};
44
45/*
46 * enum ipahal_rt_rule_hdr_type - Header type used in rt rules
47 * @IPAHAL_RT_RULE_HDR_NONE: No header is used
48 * @IPAHAL_RT_RULE_HDR_RAW: Raw header is used
49 * @IPAHAL_RT_RULE_HDR_PROC_CTX: Header Processing context is used
50 */
51enum ipahal_rt_rule_hdr_type {
52 IPAHAL_RT_RULE_HDR_NONE,
53 IPAHAL_RT_RULE_HDR_RAW,
54 IPAHAL_RT_RULE_HDR_PROC_CTX,
55};
56
57/*
58 * struct ipahal_rt_rule_gen_params - Params for generating rt rule
59 * @ipt: IP family version
60 * @dst_pipe_idx: Destination pipe index
61 * @hdr_type: Header type to be used
62 * @hdr_lcl: Does header on local or system table?
63 * @hdr_ofst: Offset of the header in the header table
64 * @priority: Rule priority
65 * @id: Rule ID
66 * @rule: Rule info
67 */
68struct ipahal_rt_rule_gen_params {
69 enum ipa_ip_type ipt;
70 int dst_pipe_idx;
71 enum ipahal_rt_rule_hdr_type hdr_type;
72 bool hdr_lcl;
73 u32 hdr_ofst;
74 u32 priority;
75 u32 id;
76 const struct ipa_rt_rule *rule;
77};
78
79/*
80 * struct ipahal_rt_rule_entry - Rt rule info parsed from H/W
81 * @dst_pipe_idx: Destination pipe index
82 * @hdr_lcl: Does the references header located in sram or system mem?
83 * @hdr_ofst: Offset of the header in the header table
84 * @hdr_type: Header type to be used
85 * @priority: Rule priority
86 * @retain_hdr: to retain the removed header in header removal
87 * @id: Rule ID
88 * @eq_attrib: Equations and their params in the rule
89 * @rule_size: Rule size in memory
90 */
91struct ipahal_rt_rule_entry {
92 int dst_pipe_idx;
93 bool hdr_lcl;
94 u32 hdr_ofst;
95 enum ipahal_rt_rule_hdr_type hdr_type;
96 u32 priority;
97 bool retain_hdr;
98 u32 id;
99 struct ipa_ipfltri_rule_eq eq_attrib;
100 u32 rule_size;
101};
102
103/*
104 * struct ipahal_flt_rule_gen_params - Params for generating flt rule
105 * @ipt: IP family version
106 * @rt_tbl_idx: Routing table the rule pointing to
107 * @priority: Rule priority
108 * @id: Rule ID
109 * @rule: Rule info
110 */
111struct ipahal_flt_rule_gen_params {
112 enum ipa_ip_type ipt;
113 u32 rt_tbl_idx;
114 u32 priority;
115 u32 id;
116 const struct ipa_flt_rule *rule;
117};
118
119/*
120 * struct ipahal_flt_rule_entry - Flt rule info parsed from H/W
121 * @rule: Rule info
122 * @priority: Rule priority
123 * @id: Rule ID
124 * @rule_size: Rule size in memory
125 */
126struct ipahal_flt_rule_entry {
127 struct ipa_flt_rule rule;
128 u32 priority;
129 u32 id;
130 u32 rule_size;
131};
132
133/* Get the H/W table (flt/rt) header width */
134u32 ipahal_get_hw_tbl_hdr_width(void);
135
136/* Get the H/W local table (SRAM) address alignment
137 * Tables headers references to local tables via offsets in SRAM
138 * This function return the alignment of the offset that IPA expects
139 */
140u32 ipahal_get_lcl_tbl_addr_alignment(void);
141
142/*
143 * Rule priority is used to distinguish rules order
144 * at the integrated table consisting from hashable and
145 * non-hashable tables. Max priority are rules that once are
146 * scanned by IPA, IPA will not look for further rules and use it.
147 */
148int ipahal_get_rule_max_priority(void);
149
150/* Given a priority, calc and return the next lower one if it is in
151 * legal range.
152 */
153int ipahal_rule_decrease_priority(int *prio);
154
155/* Does the given ID represents rule miss? */
156bool ipahal_is_rule_miss_id(u32 id);
157
158/* Get rule ID with high bit only asserted
159 * Used e.g. to create groups of IDs according to this bit
160 */
161u32 ipahal_get_rule_id_hi_bit(void);
162
163/* Get the low value possible to be used for rule-id */
164u32 ipahal_get_low_rule_id(void);
165
166/*
167 * ipahal_rt_generate_empty_img() - Generate empty route image
168 * Creates routing header buffer for the given tables number.
169 * For each table, make it point to the empty table on DDR.
170 * @tbls_num: Number of tables. For each will have an entry in the header
171 * @hash_hdr_size: SRAM buf size of the hash tbls hdr. Used for space check
172 * @nhash_hdr_size: SRAM buf size of the nhash tbls hdr. Used for space check
173 * @mem: mem object that points to DMA mem representing the hdr structure
174 */
175int ipahal_rt_generate_empty_img(u32 tbls_num, u32 hash_hdr_size,
176 u32 nhash_hdr_size, struct ipa_mem_buffer *mem);
177
178/*
179 * ipahal_flt_generate_empty_img() - Generate empty filter image
180 * Creates filter header buffer for the given tables number.
181 * For each table, make it point to the empty table on DDR.
182 * @tbls_num: Number of tables. For each will have an entry in the header
183 * @hash_hdr_size: SRAM buf size of the hash tbls hdr. Used for space check
184 * @nhash_hdr_size: SRAM buf size of the nhash tbls hdr. Used for space check
185 * @ep_bitmap: Bitmap representing the EP that has flt tables. The format
186 * should be: bit0->EP0, bit1->EP1
187 * @mem: mem object that points to DMA mem representing the hdr structure
188 */
189int ipahal_flt_generate_empty_img(u32 tbls_num, u32 hash_hdr_size,
190 u32 nhash_hdr_size, u64 ep_bitmap, struct ipa_mem_buffer *mem);
191
192/*
193 * ipahal_fltrt_allocate_hw_tbl_imgs() - Allocate tbl images DMA structures
194 * Used usually during commit.
195 * Allocates header structures and init them to point to empty DDR table
196 * Allocate body strucutres for local bodies tables
197 * @params: Parameters for IN and OUT regard the allocation.
198 */
199int ipahal_fltrt_allocate_hw_tbl_imgs(
200 struct ipahal_fltrt_alloc_imgs_params *params);
201
202/*
203 * ipahal_fltrt_allocate_hw_sys_tbl() - Allocate DMA mem for H/W flt/rt sys tbl
204 * @tbl_mem: IN/OUT param. size for effective table size. Pointer, for the
205 * allocated memory.
206 *
207 * The size is adapted for needed alignments/borders.
208 */
209int ipahal_fltrt_allocate_hw_sys_tbl(struct ipa_mem_buffer *tbl_mem);
210
211/*
212 * ipahal_fltrt_write_addr_to_hdr() - Fill table header with table address
213 * Given table addr/offset, adapt it to IPA H/W format and write it
214 * to given header index.
215 * @addr: Address or offset to be used
216 * @hdr_base: base address of header structure to write the address
217 * @hdr_idx: index of the address in the header structure
218 * @is_sys: Is it system address or local offset
219 */
220int ipahal_fltrt_write_addr_to_hdr(u64 addr, void *hdr_base, u32 hdr_idx,
221 bool is_sys);
222
223/*
224 * ipahal_fltrt_read_addr_from_hdr() - Given sram address, read it's
225 * content (physical address or offset) and parse it.
226 * @hdr_base: base sram address of the header structure.
227 * @hdr_idx: index of the header entry line in the header structure.
228 * @addr: The parsed address - Out parameter
229 * @is_sys: Is this system or local address - Out parameter
230 */
231int ipahal_fltrt_read_addr_from_hdr(void *hdr_base, u32 hdr_idx, u64 *addr,
232 bool *is_sys);
233
234/*
235 * ipahal_rt_generate_hw_rule() - generates the routing hardware rule.
236 * @params: Params for the rule creation.
237 * @hw_len: Size of the H/W rule to be returned
238 * @buf: Buffer to build the rule in. If buf is NULL, then the rule will
239 * be built in internal temp buf. This is used e.g. to get the rule size
240 * only.
241 */
242int ipahal_rt_generate_hw_rule(struct ipahal_rt_rule_gen_params *params,
243 u32 *hw_len, u8 *buf);
244
245/*
246 * ipahal_flt_generate_hw_rule() - generates the filtering hardware rule.
247 * @params: Params for the rule creation.
248 * @hw_len: Size of the H/W rule to be returned
249 * @buf: Buffer to build the rule in. If buf is NULL, then the rule will
250 * be built in internal temp buf. This is used e.g. to get the rule size
251 * only.
252 */
253int ipahal_flt_generate_hw_rule(struct ipahal_flt_rule_gen_params *params,
254 u32 *hw_len, u8 *buf);
255
256/*
257 * ipahal_flt_generate_equation() - generate flt rule in equation form
258 * Will build equation form flt rule from given info.
259 * @ipt: IP family
260 * @attrib: Rule attribute to be generated
261 * @eq_atrb: Equation form generated rule
262 * Note: Usage example: Pass the generated form to other sub-systems
263 * for inter-subsystems rules exchange.
264 */
265int ipahal_flt_generate_equation(enum ipa_ip_type ipt,
266 const struct ipa_rule_attrib *attrib,
267 struct ipa_ipfltri_rule_eq *eq_atrb);
268
269/*
270 * ipahal_rt_parse_hw_rule() - Parse H/W formated rt rule
271 * Given the rule address, read the rule info from H/W and parse it.
272 * @rule_addr: Rule address (virtual memory)
273 * @rule: Out parameter for parsed rule info
274 */
275int ipahal_rt_parse_hw_rule(u8 *rule_addr,
276 struct ipahal_rt_rule_entry *rule);
277
278/*
279 * ipahal_flt_parse_hw_rule() - Parse H/W formated flt rule
280 * Given the rule address, read the rule info from H/W and parse it.
281 * @rule_addr: Rule address (virtual memory)
282 * @rule: Out parameter for parsed rule info
283 */
284int ipahal_flt_parse_hw_rule(u8 *rule_addr,
285 struct ipahal_flt_rule_entry *rule);
286
287
288#endif /* _IPAHAL_FLTRT_H_ */