1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2020-2021 Marvell International Ltd. All rights reserved. */
4 #ifndef _PRESTERA_ACL_H_
5 #define _PRESTERA_ACL_H_
7 #include <linux/types.h>
8 #include "prestera_counter.h"
10 #define PRESTERA_ACL_KEYMASK_PCL_ID 0x3FF
11 #define PRESTERA_ACL_KEYMASK_PCL_ID_USER \
12 (PRESTERA_ACL_KEYMASK_PCL_ID & 0x00FF)
13 #define PRESTERA_ACL_KEYMASK_PCL_ID_CHAIN \
14 (PRESTERA_ACL_KEYMASK_PCL_ID & 0xFF00)
15 #define PRESTERA_ACL_CHAIN_MASK \
16 (PRESTERA_ACL_KEYMASK_PCL_ID >> 8)
18 #define PRESTERA_ACL_PCL_ID_MAKE(uid, chain_id) \
19 (((uid) & PRESTERA_ACL_KEYMASK_PCL_ID_USER) | \
20 (((chain_id) << 8) & PRESTERA_ACL_KEYMASK_PCL_ID_CHAIN))
22 #define rule_match_set_n(match_p, type, val_p, size) \
23 memcpy(&(match_p)[PRESTERA_ACL_RULE_MATCH_TYPE_##type], \
25 #define rule_match_set(match_p, type, val) \
26 memcpy(&(match_p)[PRESTERA_ACL_RULE_MATCH_TYPE_##type], \
29 enum prestera_acl_match_type {
30 PRESTERA_ACL_RULE_MATCH_TYPE_PCL_ID,
31 PRESTERA_ACL_RULE_MATCH_TYPE_ETH_TYPE,
32 PRESTERA_ACL_RULE_MATCH_TYPE_ETH_DMAC_0,
33 PRESTERA_ACL_RULE_MATCH_TYPE_ETH_DMAC_1,
34 PRESTERA_ACL_RULE_MATCH_TYPE_ETH_SMAC_0,
35 PRESTERA_ACL_RULE_MATCH_TYPE_ETH_SMAC_1,
36 PRESTERA_ACL_RULE_MATCH_TYPE_IP_PROTO,
37 PRESTERA_ACL_RULE_MATCH_TYPE_SYS_PORT,
38 PRESTERA_ACL_RULE_MATCH_TYPE_SYS_DEV,
39 PRESTERA_ACL_RULE_MATCH_TYPE_IP_SRC,
40 PRESTERA_ACL_RULE_MATCH_TYPE_IP_DST,
41 PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_SRC,
42 PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_DST,
43 PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_RANGE_SRC,
44 PRESTERA_ACL_RULE_MATCH_TYPE_L4_PORT_RANGE_DST,
45 PRESTERA_ACL_RULE_MATCH_TYPE_VLAN_ID,
46 PRESTERA_ACL_RULE_MATCH_TYPE_VLAN_TPID,
47 PRESTERA_ACL_RULE_MATCH_TYPE_ICMP_TYPE,
48 PRESTERA_ACL_RULE_MATCH_TYPE_ICMP_CODE,
50 __PRESTERA_ACL_RULE_MATCH_TYPE_MAX
53 enum prestera_acl_rule_action {
54 PRESTERA_ACL_RULE_ACTION_ACCEPT = 0,
55 PRESTERA_ACL_RULE_ACTION_DROP = 1,
56 PRESTERA_ACL_RULE_ACTION_TRAP = 2,
57 PRESTERA_ACL_RULE_ACTION_JUMP = 5,
58 PRESTERA_ACL_RULE_ACTION_COUNT = 7,
59 PRESTERA_ACL_RULE_ACTION_POLICE = 8,
61 PRESTERA_ACL_RULE_ACTION_MAX
65 PRESTERA_ACL_IFACE_TYPE_PORT,
66 PRESTERA_ACL_IFACE_TYPE_INDEX
69 struct prestera_acl_match {
70 __be32 key[__PRESTERA_ACL_RULE_MATCH_TYPE_MAX];
71 __be32 mask[__PRESTERA_ACL_RULE_MATCH_TYPE_MAX];
74 struct prestera_acl_action_jump {
78 struct prestera_acl_action_police {
82 struct prestera_acl_action_count {
86 struct prestera_acl_rule_entry_key {
88 struct prestera_acl_match match;
91 struct prestera_acl_hw_action_info {
92 enum prestera_acl_rule_action id;
94 struct prestera_acl_action_police police;
95 struct prestera_acl_action_count count;
96 struct prestera_acl_action_jump jump;
100 /* This struct (arg) used only to be passed as parameter for
101 * acl_rule_entry_create. Must be flat. Can contain object keys, which will be
102 * resolved to object links, before saving to acl_rule_entry struct
104 struct prestera_acl_rule_entry_arg {
109 } accept, drop, trap;
111 struct prestera_acl_action_jump i;
127 struct prestera_acl_rule {
128 struct rhash_head ht_node; /* Member of acl HT */
129 struct list_head list;
130 struct prestera_acl_ruleset *ruleset;
131 struct prestera_acl_ruleset *jump_ruleset;
132 unsigned long cookie;
135 struct prestera_acl_rule_entry_key re_key;
136 struct prestera_acl_rule_entry_arg re_arg;
137 struct prestera_acl_rule_entry *re;
140 struct prestera_acl_iface {
142 struct prestera_port *port;
149 struct prestera_switch;
150 struct prestera_flow_block;
152 int prestera_acl_init(struct prestera_switch *sw);
153 void prestera_acl_fini(struct prestera_switch *sw);
155 struct prestera_acl_rule *
156 prestera_acl_rule_create(struct prestera_acl_ruleset *ruleset,
157 unsigned long cookie, u32 chain_index);
158 void prestera_acl_rule_priority_set(struct prestera_acl_rule *rule,
160 void prestera_acl_rule_destroy(struct prestera_acl_rule *rule);
161 struct prestera_acl_rule *
162 prestera_acl_rule_lookup(struct prestera_acl_ruleset *ruleset,
163 unsigned long cookie);
164 int prestera_acl_rule_add(struct prestera_switch *sw,
165 struct prestera_acl_rule *rule);
166 void prestera_acl_rule_del(struct prestera_switch *sw,
167 struct prestera_acl_rule *rule);
168 int prestera_acl_rule_get_stats(struct prestera_acl *acl,
169 struct prestera_acl_rule *rule,
170 u64 *packets, u64 *bytes, u64 *last_use);
171 struct prestera_acl_rule_entry *
172 prestera_acl_rule_entry_find(struct prestera_acl *acl,
173 struct prestera_acl_rule_entry_key *key);
174 void prestera_acl_rule_entry_destroy(struct prestera_acl *acl,
175 struct prestera_acl_rule_entry *e);
176 struct prestera_acl_rule_entry *
177 prestera_acl_rule_entry_create(struct prestera_acl *acl,
178 struct prestera_acl_rule_entry_key *key,
179 struct prestera_acl_rule_entry_arg *arg);
180 struct prestera_acl_ruleset *
181 prestera_acl_ruleset_get(struct prestera_acl *acl,
182 struct prestera_flow_block *block,
184 struct prestera_acl_ruleset *
185 prestera_acl_ruleset_lookup(struct prestera_acl *acl,
186 struct prestera_flow_block *block,
188 void prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset,
190 bool prestera_acl_ruleset_is_offload(struct prestera_acl_ruleset *ruleset);
191 int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset);
192 void prestera_acl_ruleset_put(struct prestera_acl_ruleset *ruleset);
193 int prestera_acl_ruleset_bind(struct prestera_acl_ruleset *ruleset,
194 struct prestera_port *port);
195 int prestera_acl_ruleset_unbind(struct prestera_acl_ruleset *ruleset,
196 struct prestera_port *port);
197 u32 prestera_acl_ruleset_index_get(const struct prestera_acl_ruleset *ruleset);
199 prestera_acl_rule_keymask_pcl_id_set(struct prestera_acl_rule *rule,
202 int prestera_acl_vtcam_id_get(struct prestera_acl *acl, u8 lookup,
203 void *keymask, u32 *vtcam_id);
204 int prestera_acl_vtcam_id_put(struct prestera_acl *acl, u32 vtcam_id);
205 int prestera_acl_chain_to_client(u32 chain_index, u32 *client);
207 #endif /* _PRESTERA_ACL_H_ */