1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries.
9 #include <linux/types.h>
10 #include <linux/list.h>
11 #include <linux/netdevice.h>
13 /* Use the generated API model */
14 #include "vcap_ag_api.h"
16 #define VCAP_CID_LOOKUP_SIZE 100000 /* Chains in a lookup */
17 #define VCAP_CID_INGRESS_L0 1000000 /* Ingress Stage 1 Lookup 0 */
18 #define VCAP_CID_INGRESS_L1 1100000 /* Ingress Stage 1 Lookup 1 */
19 #define VCAP_CID_INGRESS_L2 1200000 /* Ingress Stage 1 Lookup 2 */
20 #define VCAP_CID_INGRESS_L3 1300000 /* Ingress Stage 1 Lookup 3 */
21 #define VCAP_CID_INGRESS_L4 1400000 /* Ingress Stage 1 Lookup 4 */
22 #define VCAP_CID_INGRESS_L5 1500000 /* Ingress Stage 1 Lookup 5 */
24 #define VCAP_CID_PREROUTING_IPV6 3000000 /* Prerouting Stage */
25 #define VCAP_CID_PREROUTING 6000000 /* Prerouting Stage */
27 #define VCAP_CID_INGRESS_STAGE2_L0 8000000 /* Ingress Stage 2 Lookup 0 */
28 #define VCAP_CID_INGRESS_STAGE2_L1 8100000 /* Ingress Stage 2 Lookup 1 */
29 #define VCAP_CID_INGRESS_STAGE2_L2 8200000 /* Ingress Stage 2 Lookup 2 */
30 #define VCAP_CID_INGRESS_STAGE2_L3 8300000 /* Ingress Stage 2 Lookup 3 */
32 #define VCAP_CID_EGRESS_L0 10000000 /* Egress Lookup 0 */
33 #define VCAP_CID_EGRESS_L1 10100000 /* Egress Lookup 1 */
35 #define VCAP_CID_EGRESS_STAGE2_L0 20000000 /* Egress Stage 2 Lookup 0 */
36 #define VCAP_CID_EGRESS_STAGE2_L1 20100000 /* Egress Stage 2 Lookup 1 */
38 /* Known users of the VCAP API */
49 /* add new users above here */
51 /* used to define VCAP_USER_MAX below */
52 __VCAP_USER_AFTER_LAST,
53 VCAP_USER_MAX = __VCAP_USER_AFTER_LAST - 1,
56 /* VCAP information used for displaying data */
57 struct vcap_statistics {
60 const char * const *keyfield_set_names;
61 const char * const *actionfield_set_names;
62 const char * const *keyfield_names;
63 const char * const *actionfield_names;
66 /* VCAP key/action field type, position and width */
73 /* VCAP keyset or actionset type and width */
80 /* VCAP typegroup position and bitvalue */
81 struct vcap_typegroup {
89 char *name; /* user-friendly name */
90 u16 rows; /* number of row in instance */
91 u16 sw_count; /* maximum subwords used per rule */
92 u16 sw_width; /* bits per subword in a keyset */
93 u16 sticky_width; /* sticky bits per rule */
94 u16 act_width; /* bits per subword in an actionset */
95 u16 default_cnt; /* number of default rules */
96 u16 require_cnt_dis; /* not used */
97 u16 version; /* vcap rtl version */
98 const struct vcap_set *keyfield_set; /* keysets */
99 int keyfield_set_size; /* number of keysets */
100 const struct vcap_set *actionfield_set; /* actionsets */
101 int actionfield_set_size; /* number of actionsets */
102 /* map of keys per keyset */
103 const struct vcap_field **keyfield_set_map;
104 /* number of entries in the above map */
105 int *keyfield_set_map_size;
106 /* map of actions per actionset */
107 const struct vcap_field **actionfield_set_map;
108 /* number of entries in the above map */
109 int *actionfield_set_map_size;
110 /* map of keyset typegroups per subword size */
111 const struct vcap_typegroup **keyfield_set_typegroups;
112 /* map of actionset typegroups per subword size */
113 const struct vcap_typegroup **actionfield_set_typegroups;
116 enum vcap_field_type {
127 /* VCAP rule data towards the VCAP cache */
128 struct vcap_cache_data {
136 /* Selects which part of the rule must be updated */
137 enum vcap_selection {
138 VCAP_SEL_ENTRY = 0x01,
139 VCAP_SEL_ACTION = 0x02,
140 VCAP_SEL_COUNTER = 0x04,
144 /* Commands towards the VCAP cache */
148 VCAP_CMD_MOVE_DOWN = 2,
149 VCAP_CMD_MOVE_UP = 3,
150 VCAP_CMD_INITIALIZE = 4,
153 enum vcap_rule_error {
154 VCAP_ERR_NONE = 0, /* No known error */
155 VCAP_ERR_NO_ADMIN, /* No admin instance */
156 VCAP_ERR_NO_NETDEV, /* No netdev instance */
157 VCAP_ERR_NO_KEYSET_MATCH, /* No keyset matched the rule keys */
158 VCAP_ERR_NO_ACTIONSET_MATCH, /* No actionset matched the rule actions */
159 VCAP_ERR_NO_PORT_KEYSET_MATCH, /* No port keyset matched the rule keys */
162 /* Administration of each VCAP instance */
164 struct list_head list; /* for insertion in vcap_control */
165 struct list_head rules; /* list of rules */
166 struct list_head enabled; /* list of enabled ports */
167 struct mutex lock; /* control access to rules */
168 enum vcap_type vtype; /* type of vcap */
169 int vinst; /* instance number within the same type */
170 int first_cid; /* first chain id in this vcap */
171 int last_cid; /* last chain id in this vcap */
172 int tgt_inst; /* hardware instance number */
173 int lookups; /* number of lookups in this vcap type */
174 int lookups_per_instance; /* number of lookups in this instance */
175 int last_valid_addr; /* top of address range to be used */
176 int first_valid_addr; /* bottom of address range to be used */
177 int last_used_addr; /* address of lowest added rule */
178 bool w32be; /* vcap uses "32bit-word big-endian" encoding */
179 bool ingress; /* chain traffic direction */
180 struct vcap_cache_data cache; /* encoded rule data */
183 /* Client supplied VCAP rule data */
185 int vcap_chain_id; /* chain used for this rule */
186 enum vcap_user user; /* rule owner */
188 u32 id; /* vcap rule id, must be unique, 0 will auto-generate a value */
189 u64 cookie; /* used by the client to identify the rule */
190 struct list_head keyfields; /* list of vcap_client_keyfield */
191 struct list_head actionfields; /* list of vcap_client_actionfield */
192 enum vcap_keyfield_set keyset; /* keyset used: may be derived from fields */
193 enum vcap_actionfield_set actionset; /* actionset used: may be derived from fields */
194 enum vcap_rule_error exterr; /* extended error - used by TC */
195 u64 client; /* space for client defined data */
198 /* List of keysets */
199 struct vcap_keyset_list {
200 int max; /* size of the keyset list */
201 int cnt; /* count of keysets actually in the list */
202 enum vcap_keyfield_set *keysets; /* the list of keysets */
205 /* List of actionsets */
206 struct vcap_actionset_list {
207 int max; /* size of the actionset list */
208 int cnt; /* count of actionsets actually in the list */
209 enum vcap_actionfield_set *actionsets; /* the list of actionsets */
212 /* Client output printf-like function with destination */
213 struct vcap_output_print {
215 void (*prf)(void *out, const char *fmt, ...);
219 /* Client supplied VCAP callback operations */
220 struct vcap_operations {
221 /* validate port keyset operation */
222 enum vcap_keyfield_set (*validate_keyset)
223 (struct net_device *ndev,
224 struct vcap_admin *admin,
225 struct vcap_rule *rule,
226 struct vcap_keyset_list *kslist,
228 /* add default rule fields for the selected keyset operations */
229 void (*add_default_fields)
230 (struct net_device *ndev,
231 struct vcap_admin *admin,
232 struct vcap_rule *rule);
233 /* cache operations */
235 (struct vcap_admin *admin);
237 (struct net_device *ndev,
238 struct vcap_admin *admin,
239 enum vcap_selection sel,
242 (struct net_device *ndev,
243 struct vcap_admin *admin,
244 enum vcap_selection sel,
247 /* block operations */
249 (struct net_device *ndev,
250 struct vcap_admin *admin,
254 (struct net_device *ndev,
255 struct vcap_admin *admin,
256 enum vcap_command cmd,
257 enum vcap_selection sel,
260 (struct net_device *ndev,
261 struct vcap_admin *admin,
267 (struct net_device *ndev,
268 struct vcap_admin *admin,
269 struct vcap_output_print *out);
272 /* VCAP API Client control interface */
273 struct vcap_control {
274 struct vcap_operations *ops; /* client supplied operations */
275 const struct vcap_info *vcaps; /* client supplied vcap models */
276 const struct vcap_statistics *stats; /* client supplied vcap stats */
277 struct list_head list; /* list of vcap instances */
280 #endif /* __VCAP_API__ */