Loading...
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries.
3 * Microchip VCAP API
4 */
5
6#ifndef __VCAP_API_CLIENT__
7#define __VCAP_API_CLIENT__
8
9#include <linux/types.h>
10#include <linux/list.h>
11#include <linux/netdevice.h>
12#include <net/flow_offload.h>
13
14#include "vcap_api.h"
15
16/* Client supplied VCAP rule key control part */
17struct vcap_client_keyfield_ctrl {
18 struct list_head list; /* For insertion into a rule */
19 enum vcap_key_field key;
20 enum vcap_field_type type;
21};
22
23struct vcap_u1_key {
24 u8 value;
25 u8 mask;
26};
27
28struct vcap_u32_key {
29 u32 value;
30 u32 mask;
31};
32
33struct vcap_u48_key {
34 u8 value[6];
35 u8 mask[6];
36};
37
38struct vcap_u56_key {
39 u8 value[7];
40 u8 mask[7];
41};
42
43struct vcap_u64_key {
44 u8 value[8];
45 u8 mask[8];
46};
47
48struct vcap_u72_key {
49 u8 value[9];
50 u8 mask[9];
51};
52
53struct vcap_u112_key {
54 u8 value[14];
55 u8 mask[14];
56};
57
58struct vcap_u128_key {
59 u8 value[16];
60 u8 mask[16];
61};
62
63/* Client supplied VCAP rule field data */
64struct vcap_client_keyfield_data {
65 union {
66 struct vcap_u1_key u1;
67 struct vcap_u32_key u32;
68 struct vcap_u48_key u48;
69 struct vcap_u56_key u56;
70 struct vcap_u64_key u64;
71 struct vcap_u72_key u72;
72 struct vcap_u112_key u112;
73 struct vcap_u128_key u128;
74 };
75};
76
77/* Client supplied VCAP rule key (value, mask) */
78struct vcap_client_keyfield {
79 struct vcap_client_keyfield_ctrl ctrl;
80 struct vcap_client_keyfield_data data;
81};
82
83/* Client supplied VCAP rule action control part */
84struct vcap_client_actionfield_ctrl {
85 struct list_head list; /* For insertion into a rule */
86 enum vcap_action_field action;
87 enum vcap_field_type type;
88};
89
90struct vcap_u1_action {
91 u8 value;
92};
93
94struct vcap_u32_action {
95 u32 value;
96};
97
98struct vcap_u48_action {
99 u8 value[6];
100};
101
102struct vcap_u56_action {
103 u8 value[7];
104};
105
106struct vcap_u64_action {
107 u8 value[8];
108};
109
110struct vcap_u72_action {
111 u8 value[9];
112};
113
114struct vcap_u112_action {
115 u8 value[14];
116};
117
118struct vcap_u128_action {
119 u8 value[16];
120};
121
122struct vcap_client_actionfield_data {
123 union {
124 struct vcap_u1_action u1;
125 struct vcap_u32_action u32;
126 struct vcap_u48_action u48;
127 struct vcap_u56_action u56;
128 struct vcap_u64_action u64;
129 struct vcap_u72_action u72;
130 struct vcap_u112_action u112;
131 struct vcap_u128_action u128;
132 };
133};
134
135struct vcap_client_actionfield {
136 struct vcap_client_actionfield_ctrl ctrl;
137 struct vcap_client_actionfield_data data;
138};
139
140enum vcap_bit {
141 VCAP_BIT_ANY,
142 VCAP_BIT_0,
143 VCAP_BIT_1
144};
145
146struct vcap_counter {
147 u32 value;
148 bool sticky;
149};
150
151/* Enable/Disable the VCAP instance lookups */
152int vcap_enable_lookups(struct vcap_control *vctrl, struct net_device *ndev,
153 int from_cid, int to_cid, unsigned long cookie,
154 bool enable);
155
156/* VCAP rule operations */
157/* Allocate a rule and fill in the basic information */
158struct vcap_rule *vcap_alloc_rule(struct vcap_control *vctrl,
159 struct net_device *ndev,
160 int vcap_chain_id,
161 enum vcap_user user,
162 u16 priority,
163 u32 id);
164/* Free mem of a rule owned by client */
165void vcap_free_rule(struct vcap_rule *rule);
166/* Validate a rule before adding it to the VCAP */
167int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto);
168/* Add rule to a VCAP instance */
169int vcap_add_rule(struct vcap_rule *rule);
170/* Delete rule in a VCAP instance */
171int vcap_del_rule(struct vcap_control *vctrl, struct net_device *ndev, u32 id);
172/* Make a full copy of an existing rule with a new rule id */
173struct vcap_rule *vcap_copy_rule(struct vcap_rule *rule);
174/* Get rule from a VCAP instance */
175struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id);
176/* Update existing rule */
177int vcap_mod_rule(struct vcap_rule *rule);
178
179/* Update the keyset for the rule */
180int vcap_set_rule_set_keyset(struct vcap_rule *rule,
181 enum vcap_keyfield_set keyset);
182/* Update the actionset for the rule */
183int vcap_set_rule_set_actionset(struct vcap_rule *rule,
184 enum vcap_actionfield_set actionset);
185/* Set a rule counter id (for certain VCAPs only) */
186void vcap_rule_set_counter_id(struct vcap_rule *rule, u32 counter_id);
187
188/* VCAP rule field operations */
189int vcap_rule_add_key_bit(struct vcap_rule *rule, enum vcap_key_field key,
190 enum vcap_bit val);
191int vcap_rule_add_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
192 u32 value, u32 mask);
193int vcap_rule_add_key_u48(struct vcap_rule *rule, enum vcap_key_field key,
194 struct vcap_u48_key *fieldval);
195int vcap_rule_add_key_u72(struct vcap_rule *rule, enum vcap_key_field key,
196 struct vcap_u72_key *fieldval);
197int vcap_rule_add_key_u128(struct vcap_rule *rule, enum vcap_key_field key,
198 struct vcap_u128_key *fieldval);
199int vcap_rule_add_action_bit(struct vcap_rule *rule,
200 enum vcap_action_field action, enum vcap_bit val);
201int vcap_rule_add_action_u32(struct vcap_rule *rule,
202 enum vcap_action_field action, u32 value);
203
204/* Get number of rules in a vcap instance lookup chain id range */
205int vcap_admin_rule_count(struct vcap_admin *admin, int cid);
206
207/* VCAP rule counter operations */
208int vcap_get_rule_count_by_cookie(struct vcap_control *vctrl,
209 struct vcap_counter *ctr, u64 cookie);
210int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
211int vcap_rule_get_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
212
213/* VCAP lookup operations */
214/* Convert a chain id to a VCAP lookup index */
215int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid);
216/* Lookup a vcap instance using chain id */
217struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid);
218/* Find information on a key field in a rule */
219const struct vcap_field *vcap_lookup_keyfield(struct vcap_rule *rule,
220 enum vcap_key_field key);
221/* Find a rule id with a provided cookie */
222int vcap_lookup_rule_by_cookie(struct vcap_control *vctrl, u64 cookie);
223/* Calculate the value used for chaining VCAP rules */
224int vcap_chain_offset(struct vcap_control *vctrl, int from_cid, int to_cid);
225/* Is the next chain id in the following lookup, possible in another VCAP */
226bool vcap_is_next_lookup(struct vcap_control *vctrl, int cur_cid, int next_cid);
227/* Is this chain id the last lookup of all VCAPs */
228bool vcap_is_last_chain(struct vcap_control *vctrl, int cid, bool ingress);
229/* Match a list of keys against the keysets available in a vcap type */
230bool vcap_rule_find_keysets(struct vcap_rule *rule,
231 struct vcap_keyset_list *matches);
232/* Return the keyset information for the keyset */
233const struct vcap_set *vcap_keyfieldset(struct vcap_control *vctrl,
234 enum vcap_type vt,
235 enum vcap_keyfield_set keyset);
236/* Copy to host byte order */
237void vcap_netbytes_copy(u8 *dst, u8 *src, int count);
238
239/* Convert validation error code into tc extact error message */
240void vcap_set_tc_exterr(struct flow_cls_offload *fco, struct vcap_rule *vrule);
241
242/* Cleanup a VCAP instance */
243int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin);
244
245/* Add a keyset to a keyset list */
246bool vcap_keyset_list_add(struct vcap_keyset_list *keysetlist,
247 enum vcap_keyfield_set keyset);
248/* Drop keys in a keylist and any keys that are not supported by the keyset */
249int vcap_filter_rule_keys(struct vcap_rule *rule,
250 enum vcap_key_field keylist[], int length,
251 bool drop_unsupported);
252
253/* map keyset id to a string with the keyset name */
254const char *vcap_keyset_name(struct vcap_control *vctrl,
255 enum vcap_keyfield_set keyset);
256/* map key field id to a string with the key name */
257const char *vcap_keyfield_name(struct vcap_control *vctrl,
258 enum vcap_key_field key);
259
260/* Modify a 32 bit key field with value and mask in the rule */
261int vcap_rule_mod_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
262 u32 value, u32 mask);
263/* Modify a 32 bit action field with value in the rule */
264int vcap_rule_mod_action_u32(struct vcap_rule *rule,
265 enum vcap_action_field action,
266 u32 value);
267
268/* Get a 32 bit key field value and mask from the rule */
269int vcap_rule_get_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
270 u32 *value, u32 *mask);
271
272/* Remove a key field with value and mask in the rule */
273int vcap_rule_rem_key(struct vcap_rule *rule, enum vcap_key_field key);
274
275/* Select the keyset from the list that results in the smallest rule size */
276enum vcap_keyfield_set
277vcap_select_min_rule_keyset(struct vcap_control *vctrl, enum vcap_type vtype,
278 struct vcap_keyset_list *kslist);
279
280struct vcap_client_actionfield *
281vcap_find_actionfield(struct vcap_rule *rule, enum vcap_action_field act);
282#endif /* __VCAP_API_CLIENT__ */
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries.
3 * Microchip VCAP API
4 */
5
6#ifndef __VCAP_API_CLIENT__
7#define __VCAP_API_CLIENT__
8
9#include <linux/types.h>
10#include <linux/list.h>
11#include <linux/netdevice.h>
12#include <net/flow_offload.h>
13
14#include "vcap_api.h"
15
16/* Client supplied VCAP rule key control part */
17struct vcap_client_keyfield_ctrl {
18 struct list_head list; /* For insertion into a rule */
19 enum vcap_key_field key;
20 enum vcap_field_type type;
21};
22
23struct vcap_u1_key {
24 u8 value;
25 u8 mask;
26};
27
28struct vcap_u32_key {
29 u32 value;
30 u32 mask;
31};
32
33struct vcap_u48_key {
34 u8 value[6];
35 u8 mask[6];
36};
37
38struct vcap_u56_key {
39 u8 value[7];
40 u8 mask[7];
41};
42
43struct vcap_u64_key {
44 u8 value[8];
45 u8 mask[8];
46};
47
48struct vcap_u72_key {
49 u8 value[9];
50 u8 mask[9];
51};
52
53struct vcap_u112_key {
54 u8 value[14];
55 u8 mask[14];
56};
57
58struct vcap_u128_key {
59 u8 value[16];
60 u8 mask[16];
61};
62
63/* Client supplied VCAP rule field data */
64struct vcap_client_keyfield_data {
65 union {
66 struct vcap_u1_key u1;
67 struct vcap_u32_key u32;
68 struct vcap_u48_key u48;
69 struct vcap_u56_key u56;
70 struct vcap_u64_key u64;
71 struct vcap_u72_key u72;
72 struct vcap_u112_key u112;
73 struct vcap_u128_key u128;
74 };
75};
76
77/* Client supplied VCAP rule key (value, mask) */
78struct vcap_client_keyfield {
79 struct vcap_client_keyfield_ctrl ctrl;
80 struct vcap_client_keyfield_data data;
81};
82
83/* Client supplied VCAP rule action control part */
84struct vcap_client_actionfield_ctrl {
85 struct list_head list; /* For insertion into a rule */
86 enum vcap_action_field action;
87 enum vcap_field_type type;
88};
89
90struct vcap_u1_action {
91 u8 value;
92};
93
94struct vcap_u32_action {
95 u32 value;
96};
97
98struct vcap_u48_action {
99 u8 value[6];
100};
101
102struct vcap_u56_action {
103 u8 value[7];
104};
105
106struct vcap_u64_action {
107 u8 value[8];
108};
109
110struct vcap_u72_action {
111 u8 value[9];
112};
113
114struct vcap_u112_action {
115 u8 value[14];
116};
117
118struct vcap_u128_action {
119 u8 value[16];
120};
121
122struct vcap_client_actionfield_data {
123 union {
124 struct vcap_u1_action u1;
125 struct vcap_u32_action u32;
126 struct vcap_u48_action u48;
127 struct vcap_u56_action u56;
128 struct vcap_u64_action u64;
129 struct vcap_u72_action u72;
130 struct vcap_u112_action u112;
131 struct vcap_u128_action u128;
132 };
133};
134
135struct vcap_client_actionfield {
136 struct vcap_client_actionfield_ctrl ctrl;
137 struct vcap_client_actionfield_data data;
138};
139
140enum vcap_bit {
141 VCAP_BIT_ANY,
142 VCAP_BIT_0,
143 VCAP_BIT_1
144};
145
146struct vcap_counter {
147 u32 value;
148 bool sticky;
149};
150
151/* Enable/Disable the VCAP instance lookups. Chain id 0 means disable */
152int vcap_enable_lookups(struct vcap_control *vctrl, struct net_device *ndev,
153 int chain_id, unsigned long cookie, bool enable);
154
155/* VCAP rule operations */
156/* Allocate a rule and fill in the basic information */
157struct vcap_rule *vcap_alloc_rule(struct vcap_control *vctrl,
158 struct net_device *ndev,
159 int vcap_chain_id,
160 enum vcap_user user,
161 u16 priority,
162 u32 id);
163/* Free mem of a rule owned by client */
164void vcap_free_rule(struct vcap_rule *rule);
165/* Validate a rule before adding it to the VCAP */
166int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto);
167/* Add rule to a VCAP instance */
168int vcap_add_rule(struct vcap_rule *rule);
169/* Delete rule in a VCAP instance */
170int vcap_del_rule(struct vcap_control *vctrl, struct net_device *ndev, u32 id);
171/* Make a full copy of an existing rule with a new rule id */
172struct vcap_rule *vcap_copy_rule(struct vcap_rule *rule);
173/* Get rule from a VCAP instance */
174struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id);
175/* Update existing rule */
176int vcap_mod_rule(struct vcap_rule *rule);
177
178/* Update the keyset for the rule */
179int vcap_set_rule_set_keyset(struct vcap_rule *rule,
180 enum vcap_keyfield_set keyset);
181/* Update the actionset for the rule */
182int vcap_set_rule_set_actionset(struct vcap_rule *rule,
183 enum vcap_actionfield_set actionset);
184/* Set a rule counter id (for certain VCAPs only) */
185void vcap_rule_set_counter_id(struct vcap_rule *rule, u32 counter_id);
186
187/* VCAP rule field operations */
188int vcap_rule_add_key_bit(struct vcap_rule *rule, enum vcap_key_field key,
189 enum vcap_bit val);
190int vcap_rule_add_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
191 u32 value, u32 mask);
192int vcap_rule_add_key_u48(struct vcap_rule *rule, enum vcap_key_field key,
193 struct vcap_u48_key *fieldval);
194int vcap_rule_add_key_u72(struct vcap_rule *rule, enum vcap_key_field key,
195 struct vcap_u72_key *fieldval);
196int vcap_rule_add_key_u128(struct vcap_rule *rule, enum vcap_key_field key,
197 struct vcap_u128_key *fieldval);
198int vcap_rule_add_action_bit(struct vcap_rule *rule,
199 enum vcap_action_field action, enum vcap_bit val);
200int vcap_rule_add_action_u32(struct vcap_rule *rule,
201 enum vcap_action_field action, u32 value);
202
203/* VCAP rule counter operations */
204int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
205int vcap_rule_get_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
206
207/* VCAP lookup operations */
208/* Convert a chain id to a VCAP lookup index */
209int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid);
210/* Lookup a vcap instance using chain id */
211struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid);
212/* Find information on a key field in a rule */
213const struct vcap_field *vcap_lookup_keyfield(struct vcap_rule *rule,
214 enum vcap_key_field key);
215/* Find a rule id with a provided cookie */
216int vcap_lookup_rule_by_cookie(struct vcap_control *vctrl, u64 cookie);
217/* Is the next chain id in the following lookup, possible in another VCAP */
218bool vcap_is_next_lookup(struct vcap_control *vctrl, int cur_cid, int next_cid);
219/* Provide all rules via a callback interface */
220int vcap_rule_iter(struct vcap_control *vctrl,
221 int (*callback)(void *, struct vcap_rule *), void *arg);
222/* Match a list of keys against the keysets available in a vcap type */
223bool vcap_rule_find_keysets(struct vcap_rule *rule,
224 struct vcap_keyset_list *matches);
225/* Return the keyset information for the keyset */
226const struct vcap_set *vcap_keyfieldset(struct vcap_control *vctrl,
227 enum vcap_type vt,
228 enum vcap_keyfield_set keyset);
229/* Copy to host byte order */
230void vcap_netbytes_copy(u8 *dst, u8 *src, int count);
231
232/* Convert validation error code into tc extact error message */
233void vcap_set_tc_exterr(struct flow_cls_offload *fco, struct vcap_rule *vrule);
234
235/* Cleanup a VCAP instance */
236int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin);
237
238/* Add a keyset to a keyset list */
239bool vcap_keyset_list_add(struct vcap_keyset_list *keysetlist,
240 enum vcap_keyfield_set keyset);
241/* Drop keys in a keylist and any keys that are not supported by the keyset */
242int vcap_filter_rule_keys(struct vcap_rule *rule,
243 enum vcap_key_field keylist[], int length,
244 bool drop_unsupported);
245
246/* map keyset id to a string with the keyset name */
247const char *vcap_keyset_name(struct vcap_control *vctrl,
248 enum vcap_keyfield_set keyset);
249/* map key field id to a string with the key name */
250const char *vcap_keyfield_name(struct vcap_control *vctrl,
251 enum vcap_key_field key);
252
253/* Modify a 32 bit key field with value and mask in the rule */
254int vcap_rule_mod_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
255 u32 value, u32 mask);
256/* Modify a 32 bit action field with value in the rule */
257int vcap_rule_mod_action_u32(struct vcap_rule *rule,
258 enum vcap_action_field action,
259 u32 value);
260
261/* Get a 32 bit key field value and mask from the rule */
262int vcap_rule_get_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
263 u32 *value, u32 *mask);
264
265#endif /* __VCAP_API_CLIENT__ */