1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
2 /* Microsemi Ocelot Switch driver
3 * Copyright (c) 2019 Microsemi Corporation
6 #ifndef _MSCC_OCELOT_VCAP_H_
7 #define _MSCC_OCELOT_VCAP_H_
10 #include "ocelot_police.h"
11 #include <net/sch_generic.h>
12 #include <net/pkt_cls.h>
18 enum ocelot_vcap_bit {
24 struct ocelot_vcap_u8 {
29 struct ocelot_vcap_u16 {
34 struct ocelot_vcap_u24 {
39 struct ocelot_vcap_u32 {
44 struct ocelot_vcap_u40 {
49 struct ocelot_vcap_u48 {
54 struct ocelot_vcap_u64 {
59 struct ocelot_vcap_u128 {
64 struct ocelot_vcap_vid {
69 struct ocelot_vcap_ipv4 {
70 struct ocelot_ipv4 value;
71 struct ocelot_ipv4 mask;
74 struct ocelot_vcap_udp_tcp {
79 enum ocelot_vcap_key_type {
81 OCELOT_VCAP_KEY_ETYPE,
89 struct 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 */
96 struct 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 */
103 struct ocelot_vcap_key_llc {
104 struct ocelot_vcap_u48 dmac;
105 struct ocelot_vcap_u48 smac;
107 /* LLC header: DSAP at byte 0, SSAP at byte 1, Control at byte 2 */
108 struct ocelot_vcap_u32 llc;
111 struct ocelot_vcap_key_snap {
112 struct ocelot_vcap_u48 dmac;
113 struct ocelot_vcap_u48 smac;
115 /* SNAP header: Organization Code at byte 0, Type at byte 3 */
116 struct ocelot_vcap_u40 snap;
119 struct 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 */
127 /**< Protocol addr. length 4, hardware length 6 */
128 enum ocelot_vcap_bit length;
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 */
136 struct 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 */
158 struct 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 */
177 enum ocelot_vcap_action {
178 OCELOT_VCAP_ACTION_DROP,
179 OCELOT_VCAP_ACTION_TRAP,
180 OCELOT_VCAP_ACTION_POLICE,
183 struct ocelot_vcap_stats {
189 struct ocelot_vcap_filter {
190 struct list_head list;
195 enum ocelot_vcap_action action;
196 struct ocelot_vcap_stats stats;
197 unsigned long ingress_port_mask;
199 enum ocelot_vcap_bit dmac_mc;
200 enum ocelot_vcap_bit dmac_bc;
201 struct ocelot_vcap_key_vlan vlan;
203 enum ocelot_vcap_key_type key_type;
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;
213 struct ocelot_policer pol;
217 int ocelot_vcap_filter_add(struct ocelot *ocelot,
218 struct ocelot_vcap_filter *rule,
219 struct netlink_ext_ack *extack);
220 int ocelot_vcap_filter_del(struct ocelot *ocelot,
221 struct ocelot_vcap_filter *rule);
222 int ocelot_vcap_filter_stats_update(struct ocelot *ocelot,
223 struct ocelot_vcap_filter *rule);
225 int ocelot_vcap_init(struct ocelot *ocelot);
227 int ocelot_setup_tc_cls_flower(struct ocelot_port_private *priv,
228 struct flow_cls_offload *f,
231 #endif /* _MSCC_OCELOT_VCAP_H_ */