Loading...
Note: File does not exist in v3.1.
1/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
2/* Microsemi Ocelot Switch driver
3 * Copyright (c) 2019 Microsemi Corporation
4 */
5
6#ifndef _MSCC_OCELOT_VCAP_H_
7#define _MSCC_OCELOT_VCAP_H_
8
9#include "ocelot.h"
10#include "ocelot_police.h"
11#include <net/sch_generic.h>
12#include <net/pkt_cls.h>
13
14struct ocelot_ipv4 {
15 u8 addr[4];
16};
17
18enum ocelot_vcap_bit {
19 OCELOT_VCAP_BIT_ANY,
20 OCELOT_VCAP_BIT_0,
21 OCELOT_VCAP_BIT_1
22};
23
24struct ocelot_vcap_u8 {
25 u8 value[1];
26 u8 mask[1];
27};
28
29struct ocelot_vcap_u16 {
30 u8 value[2];
31 u8 mask[2];
32};
33
34struct ocelot_vcap_u24 {
35 u8 value[3];
36 u8 mask[3];
37};
38
39struct ocelot_vcap_u32 {
40 u8 value[4];
41 u8 mask[4];
42};
43
44struct ocelot_vcap_u40 {
45 u8 value[5];
46 u8 mask[5];
47};
48
49struct ocelot_vcap_u48 {
50 u8 value[6];
51 u8 mask[6];
52};
53
54struct ocelot_vcap_u64 {
55 u8 value[8];
56 u8 mask[8];
57};
58
59struct ocelot_vcap_u128 {
60 u8 value[16];
61 u8 mask[16];
62};
63
64struct ocelot_vcap_vid {
65 u16 value;
66 u16 mask;
67};
68
69struct ocelot_vcap_ipv4 {
70 struct ocelot_ipv4 value;
71 struct ocelot_ipv4 mask;
72};
73
74struct ocelot_vcap_udp_tcp {
75 u16 value;
76 u16 mask;
77};
78
79enum ocelot_vcap_key_type {
80 OCELOT_VCAP_KEY_ANY,
81 OCELOT_VCAP_KEY_ETYPE,
82 OCELOT_VCAP_KEY_LLC,
83 OCELOT_VCAP_KEY_SNAP,
84 OCELOT_VCAP_KEY_ARP,
85 OCELOT_VCAP_KEY_IPV4,
86 OCELOT_VCAP_KEY_IPV6
87};
88
89struct ocelot_vcap_key_vlan {
90 struct ocelot_vcap_vid vid; /* VLAN ID (12 bit) */
91 struct ocelot_vcap_u8 pcp; /* PCP (3 bit) */
92 enum ocelot_vcap_bit dei; /* DEI */
93 enum ocelot_vcap_bit tagged; /* Tagged/untagged frame */
94};
95
96struct ocelot_vcap_key_etype {
97 struct ocelot_vcap_u48 dmac;
98 struct ocelot_vcap_u48 smac;
99 struct ocelot_vcap_u16 etype;
100 struct ocelot_vcap_u16 data; /* MAC data */
101};
102
103struct ocelot_vcap_key_llc {
104 struct ocelot_vcap_u48 dmac;
105 struct ocelot_vcap_u48 smac;
106
107 /* LLC header: DSAP at byte 0, SSAP at byte 1, Control at byte 2 */
108 struct ocelot_vcap_u32 llc;
109};
110
111struct ocelot_vcap_key_snap {
112 struct ocelot_vcap_u48 dmac;
113 struct ocelot_vcap_u48 smac;
114
115 /* SNAP header: Organization Code at byte 0, Type at byte 3 */
116 struct ocelot_vcap_u40 snap;
117};
118
119struct ocelot_vcap_key_arp {
120 struct ocelot_vcap_u48 smac;
121 enum ocelot_vcap_bit arp; /* Opcode ARP/RARP */
122 enum ocelot_vcap_bit req; /* Opcode request/reply */
123 enum ocelot_vcap_bit unknown; /* Opcode unknown */
124 enum ocelot_vcap_bit smac_match; /* Sender MAC matches SMAC */
125 enum ocelot_vcap_bit dmac_match; /* Target MAC matches DMAC */
126
127 /**< Protocol addr. length 4, hardware length 6 */
128 enum ocelot_vcap_bit length;
129
130 enum ocelot_vcap_bit ip; /* Protocol address type IP */
131 enum ocelot_vcap_bit ethernet; /* Hardware address type Ethernet */
132 struct ocelot_vcap_ipv4 sip; /* Sender IP address */
133 struct ocelot_vcap_ipv4 dip; /* Target IP address */
134};
135
136struct ocelot_vcap_key_ipv4 {
137 enum ocelot_vcap_bit ttl; /* TTL zero */
138 enum ocelot_vcap_bit fragment; /* Fragment */
139 enum ocelot_vcap_bit options; /* Header options */
140 struct ocelot_vcap_u8 ds;
141 struct ocelot_vcap_u8 proto; /* Protocol */
142 struct ocelot_vcap_ipv4 sip; /* Source IP address */
143 struct ocelot_vcap_ipv4 dip; /* Destination IP address */
144 struct ocelot_vcap_u48 data; /* Not UDP/TCP: IP data */
145 struct ocelot_vcap_udp_tcp sport; /* UDP/TCP: Source port */
146 struct ocelot_vcap_udp_tcp dport; /* UDP/TCP: Destination port */
147 enum ocelot_vcap_bit tcp_fin;
148 enum ocelot_vcap_bit tcp_syn;
149 enum ocelot_vcap_bit tcp_rst;
150 enum ocelot_vcap_bit tcp_psh;
151 enum ocelot_vcap_bit tcp_ack;
152 enum ocelot_vcap_bit tcp_urg;
153 enum ocelot_vcap_bit sip_eq_dip; /* SIP equals DIP */
154 enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT */
155 enum ocelot_vcap_bit seq_zero; /* TCP sequence number is zero */
156};
157
158struct ocelot_vcap_key_ipv6 {
159 struct ocelot_vcap_u8 proto; /* IPv6 protocol */
160 struct ocelot_vcap_u128 sip; /* IPv6 source (byte 0-7 ignored) */
161 enum ocelot_vcap_bit ttl; /* TTL zero */
162 struct ocelot_vcap_u8 ds;
163 struct ocelot_vcap_u48 data; /* Not UDP/TCP: IP data */
164 struct ocelot_vcap_udp_tcp sport;
165 struct ocelot_vcap_udp_tcp dport;
166 enum ocelot_vcap_bit tcp_fin;
167 enum ocelot_vcap_bit tcp_syn;
168 enum ocelot_vcap_bit tcp_rst;
169 enum ocelot_vcap_bit tcp_psh;
170 enum ocelot_vcap_bit tcp_ack;
171 enum ocelot_vcap_bit tcp_urg;
172 enum ocelot_vcap_bit sip_eq_dip; /* SIP equals DIP */
173 enum ocelot_vcap_bit sport_eq_dport; /* SPORT equals DPORT */
174 enum ocelot_vcap_bit seq_zero; /* TCP sequence number is zero */
175};
176
177enum ocelot_vcap_action {
178 OCELOT_VCAP_ACTION_DROP,
179 OCELOT_VCAP_ACTION_TRAP,
180 OCELOT_VCAP_ACTION_POLICE,
181};
182
183struct ocelot_vcap_stats {
184 u64 bytes;
185 u64 pkts;
186 u64 used;
187};
188
189struct ocelot_vcap_filter {
190 struct list_head list;
191
192 u16 prio;
193 u32 id;
194
195 enum ocelot_vcap_action action;
196 struct ocelot_vcap_stats stats;
197 unsigned long ingress_port_mask;
198
199 enum ocelot_vcap_bit dmac_mc;
200 enum ocelot_vcap_bit dmac_bc;
201 struct ocelot_vcap_key_vlan vlan;
202
203 enum ocelot_vcap_key_type key_type;
204 union {
205 /* OCELOT_VCAP_KEY_ANY: No specific fields */
206 struct ocelot_vcap_key_etype etype;
207 struct ocelot_vcap_key_llc llc;
208 struct ocelot_vcap_key_snap snap;
209 struct ocelot_vcap_key_arp arp;
210 struct ocelot_vcap_key_ipv4 ipv4;
211 struct ocelot_vcap_key_ipv6 ipv6;
212 } key;
213 struct ocelot_policer pol;
214 u32 pol_ix;
215};
216
217int ocelot_vcap_filter_add(struct ocelot *ocelot,
218 struct ocelot_vcap_filter *rule,
219 struct netlink_ext_ack *extack);
220int ocelot_vcap_filter_del(struct ocelot *ocelot,
221 struct ocelot_vcap_filter *rule);
222int ocelot_vcap_filter_stats_update(struct ocelot *ocelot,
223 struct ocelot_vcap_filter *rule);
224
225int ocelot_vcap_init(struct ocelot *ocelot);
226
227int ocelot_setup_tc_cls_flower(struct ocelot_port_private *priv,
228 struct flow_cls_offload *f,
229 bool ingress);
230
231#endif /* _MSCC_OCELOT_VCAP_H_ */