blob: 3ee883b6fb2007cdd9e4120055c2bf0a1c539d33 [file] [log] [blame]
Amir Levy4dc79be2017-02-01 19:18:35 +02001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Amir Levy9659e592016-10-27 18:08:27 +03002 *
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
Amir Levy4dc79be2017-02-01 19:18:35 +0200174 * @atomic: should DMA allocation be executed with atomic flag
Amir Levy9659e592016-10-27 18:08:27 +0300175 */
176int ipahal_rt_generate_empty_img(u32 tbls_num, u32 hash_hdr_size,
Amir Levy4dc79be2017-02-01 19:18:35 +0200177 u32 nhash_hdr_size, struct ipa_mem_buffer *mem, bool atomic);
Amir Levy9659e592016-10-27 18:08:27 +0300178
179/*
180 * ipahal_flt_generate_empty_img() - Generate empty filter image
181 * Creates filter header buffer for the given tables number.
182 * For each table, make it point to the empty table on DDR.
183 * @tbls_num: Number of tables. For each will have an entry in the header
184 * @hash_hdr_size: SRAM buf size of the hash tbls hdr. Used for space check
185 * @nhash_hdr_size: SRAM buf size of the nhash tbls hdr. Used for space check
186 * @ep_bitmap: Bitmap representing the EP that has flt tables. The format
187 * should be: bit0->EP0, bit1->EP1
188 * @mem: mem object that points to DMA mem representing the hdr structure
Amir Levy4dc79be2017-02-01 19:18:35 +0200189 * @atomic: should DMA allocation be executed with atomic flag
Amir Levy9659e592016-10-27 18:08:27 +0300190 */
191int ipahal_flt_generate_empty_img(u32 tbls_num, u32 hash_hdr_size,
Amir Levy4dc79be2017-02-01 19:18:35 +0200192 u32 nhash_hdr_size, u64 ep_bitmap, struct ipa_mem_buffer *mem,
193 bool atomic);
Amir Levy9659e592016-10-27 18:08:27 +0300194
195/*
196 * ipahal_fltrt_allocate_hw_tbl_imgs() - Allocate tbl images DMA structures
197 * Used usually during commit.
198 * Allocates header structures and init them to point to empty DDR table
199 * Allocate body strucutres for local bodies tables
200 * @params: Parameters for IN and OUT regard the allocation.
201 */
202int ipahal_fltrt_allocate_hw_tbl_imgs(
203 struct ipahal_fltrt_alloc_imgs_params *params);
204
205/*
206 * ipahal_fltrt_allocate_hw_sys_tbl() - Allocate DMA mem for H/W flt/rt sys tbl
207 * @tbl_mem: IN/OUT param. size for effective table size. Pointer, for the
208 * allocated memory.
209 *
210 * The size is adapted for needed alignments/borders.
211 */
212int ipahal_fltrt_allocate_hw_sys_tbl(struct ipa_mem_buffer *tbl_mem);
213
214/*
215 * ipahal_fltrt_write_addr_to_hdr() - Fill table header with table address
216 * Given table addr/offset, adapt it to IPA H/W format and write it
217 * to given header index.
218 * @addr: Address or offset to be used
219 * @hdr_base: base address of header structure to write the address
220 * @hdr_idx: index of the address in the header structure
221 * @is_sys: Is it system address or local offset
222 */
223int ipahal_fltrt_write_addr_to_hdr(u64 addr, void *hdr_base, u32 hdr_idx,
224 bool is_sys);
225
226/*
227 * ipahal_fltrt_read_addr_from_hdr() - Given sram address, read it's
228 * content (physical address or offset) and parse it.
229 * @hdr_base: base sram address of the header structure.
230 * @hdr_idx: index of the header entry line in the header structure.
231 * @addr: The parsed address - Out parameter
232 * @is_sys: Is this system or local address - Out parameter
233 */
234int ipahal_fltrt_read_addr_from_hdr(void *hdr_base, u32 hdr_idx, u64 *addr,
235 bool *is_sys);
236
237/*
238 * ipahal_rt_generate_hw_rule() - generates the routing hardware rule.
239 * @params: Params for the rule creation.
240 * @hw_len: Size of the H/W rule to be returned
241 * @buf: Buffer to build the rule in. If buf is NULL, then the rule will
242 * be built in internal temp buf. This is used e.g. to get the rule size
243 * only.
244 */
245int ipahal_rt_generate_hw_rule(struct ipahal_rt_rule_gen_params *params,
246 u32 *hw_len, u8 *buf);
247
248/*
249 * ipahal_flt_generate_hw_rule() - generates the filtering hardware rule.
250 * @params: Params for the rule creation.
251 * @hw_len: Size of the H/W rule to be returned
252 * @buf: Buffer to build the rule in. If buf is NULL, then the rule will
253 * be built in internal temp buf. This is used e.g. to get the rule size
254 * only.
255 */
256int ipahal_flt_generate_hw_rule(struct ipahal_flt_rule_gen_params *params,
257 u32 *hw_len, u8 *buf);
258
259/*
260 * ipahal_flt_generate_equation() - generate flt rule in equation form
261 * Will build equation form flt rule from given info.
262 * @ipt: IP family
263 * @attrib: Rule attribute to be generated
264 * @eq_atrb: Equation form generated rule
265 * Note: Usage example: Pass the generated form to other sub-systems
266 * for inter-subsystems rules exchange.
267 */
268int ipahal_flt_generate_equation(enum ipa_ip_type ipt,
269 const struct ipa_rule_attrib *attrib,
270 struct ipa_ipfltri_rule_eq *eq_atrb);
271
272/*
273 * ipahal_rt_parse_hw_rule() - Parse H/W formated rt rule
274 * Given the rule address, read the rule info from H/W and parse it.
275 * @rule_addr: Rule address (virtual memory)
276 * @rule: Out parameter for parsed rule info
277 */
278int ipahal_rt_parse_hw_rule(u8 *rule_addr,
279 struct ipahal_rt_rule_entry *rule);
280
281/*
282 * ipahal_flt_parse_hw_rule() - Parse H/W formated flt rule
283 * Given the rule address, read the rule info from H/W and parse it.
284 * @rule_addr: Rule address (virtual memory)
285 * @rule: Out parameter for parsed rule info
286 */
287int ipahal_flt_parse_hw_rule(u8 *rule_addr,
288 struct ipahal_flt_rule_entry *rule);
289
290
291#endif /* _IPAHAL_FLTRT_H_ */