1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2020 Marvell International Ltd. All rights reserved. */
3 
4 #ifndef _PRESTERA_ACL_H_
5 #define _PRESTERA_ACL_H_
6 
7 enum prestera_acl_rule_match_entry_type {
8 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ETH_TYPE = 1,
9 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ETH_DMAC,
10 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ETH_SMAC,
11 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_IP_PROTO,
12 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_PORT,
13 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_IP_SRC,
14 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_IP_DST,
15 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_SRC,
16 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_DST,
17 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_RANGE_SRC,
18 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_L4_PORT_RANGE_DST,
19 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_VLAN_ID,
20 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_VLAN_TPID,
21 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ICMP_TYPE,
22 	PRESTERA_ACL_RULE_MATCH_ENTRY_TYPE_ICMP_CODE
23 };
24 
25 enum prestera_acl_rule_action {
26 	PRESTERA_ACL_RULE_ACTION_ACCEPT,
27 	PRESTERA_ACL_RULE_ACTION_DROP,
28 	PRESTERA_ACL_RULE_ACTION_TRAP
29 };
30 
31 struct prestera_switch;
32 struct prestera_port;
33 struct prestera_acl_rule;
34 struct prestera_acl_ruleset;
35 
36 struct prestera_flow_block_binding {
37 	struct list_head list;
38 	struct prestera_port *port;
39 	int span_id;
40 };
41 
42 struct prestera_flow_block {
43 	struct list_head binding_list;
44 	struct prestera_switch *sw;
45 	struct net *net;
46 	struct prestera_acl_ruleset *ruleset;
47 	struct flow_block_cb *block_cb;
48 };
49 
50 struct prestera_acl_rule_action_entry {
51 	struct list_head list;
52 	enum prestera_acl_rule_action id;
53 };
54 
55 struct prestera_acl_rule_match_entry {
56 	struct list_head list;
57 	enum prestera_acl_rule_match_entry_type type;
58 	union {
59 		struct {
60 			u8 key;
61 			u8 mask;
62 		} u8;
63 		struct {
64 			u16 key;
65 			u16 mask;
66 		} u16;
67 		struct {
68 			u32 key;
69 			u32 mask;
70 		} u32;
71 		struct {
72 			u64 key;
73 			u64 mask;
74 		} u64;
75 		struct {
76 			u8 key[ETH_ALEN];
77 			u8 mask[ETH_ALEN];
78 		} mac;
79 	} keymask;
80 };
81 
82 int prestera_acl_init(struct prestera_switch *sw);
83 void prestera_acl_fini(struct prestera_switch *sw);
84 struct prestera_flow_block *
85 prestera_acl_block_create(struct prestera_switch *sw, struct net *net);
86 void prestera_acl_block_destroy(struct prestera_flow_block *block);
87 struct net *prestera_acl_block_net(struct prestera_flow_block *block);
88 struct prestera_switch *prestera_acl_block_sw(struct prestera_flow_block *block);
89 int prestera_acl_block_bind(struct prestera_flow_block *block,
90 			    struct prestera_port *port);
91 int prestera_acl_block_unbind(struct prestera_flow_block *block,
92 			      struct prestera_port *port);
93 struct prestera_acl_ruleset *
94 prestera_acl_block_ruleset_get(struct prestera_flow_block *block);
95 struct prestera_acl_rule *
96 prestera_acl_rule_create(struct prestera_flow_block *block,
97 			 unsigned long cookie);
98 u32 prestera_acl_rule_priority_get(struct prestera_acl_rule *rule);
99 void prestera_acl_rule_priority_set(struct prestera_acl_rule *rule,
100 				    u32 priority);
101 u16 prestera_acl_rule_ruleset_id_get(const struct prestera_acl_rule *rule);
102 struct list_head *
103 prestera_acl_rule_action_list_get(struct prestera_acl_rule *rule);
104 u8 prestera_acl_rule_action_len(struct prestera_acl_rule *rule);
105 u8 prestera_acl_rule_match_len(struct prestera_acl_rule *rule);
106 int prestera_acl_rule_action_add(struct prestera_acl_rule *rule,
107 				 struct prestera_acl_rule_action_entry *entry);
108 struct list_head *
109 prestera_acl_rule_match_list_get(struct prestera_acl_rule *rule);
110 int prestera_acl_rule_match_add(struct prestera_acl_rule *rule,
111 				struct prestera_acl_rule_match_entry *entry);
112 void prestera_acl_rule_destroy(struct prestera_acl_rule *rule);
113 struct prestera_acl_rule *
114 prestera_acl_rule_lookup(struct prestera_acl_ruleset *ruleset,
115 			 unsigned long cookie);
116 int prestera_acl_rule_add(struct prestera_switch *sw,
117 			  struct prestera_acl_rule *rule);
118 void prestera_acl_rule_del(struct prestera_switch *sw,
119 			   struct prestera_acl_rule *rule);
120 int prestera_acl_rule_get_stats(struct prestera_switch *sw,
121 				struct prestera_acl_rule *rule,
122 				u64 *packets, u64 *bytes, u64 *last_use);
123 
124 #endif /* _PRESTERA_ACL_H_ */
125