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>
14 #define OCELOT_POLICER_DISCARD 0x17f
20 enum ocelot_vcap_bit
{
26 struct ocelot_vcap_u8
{
31 struct ocelot_vcap_u16
{
36 struct ocelot_vcap_u24
{
41 struct ocelot_vcap_u32
{
46 struct ocelot_vcap_u40
{
51 struct ocelot_vcap_u48
{
56 struct ocelot_vcap_u64
{
61 struct ocelot_vcap_u128
{
66 struct ocelot_vcap_vid
{
71 struct ocelot_vcap_ipv4
{
72 struct ocelot_ipv4 value
;
73 struct ocelot_ipv4 mask
;
76 struct ocelot_vcap_udp_tcp
{
81 struct ocelot_vcap_port
{
86 enum ocelot_vcap_key_type
{
88 OCELOT_VCAP_KEY_ETYPE
,
96 struct ocelot_vcap_key_vlan
{
97 struct ocelot_vcap_vid vid
; /* VLAN ID (12 bit) */
98 struct ocelot_vcap_u8 pcp
; /* PCP (3 bit) */
99 enum ocelot_vcap_bit dei
; /* DEI */
100 enum ocelot_vcap_bit tagged
; /* Tagged/untagged frame */
103 struct ocelot_vcap_key_etype
{
104 struct ocelot_vcap_u48 dmac
;
105 struct ocelot_vcap_u48 smac
;
106 struct ocelot_vcap_u16 etype
;
107 struct ocelot_vcap_u16 data
; /* MAC data */
110 struct ocelot_vcap_key_llc
{
111 struct ocelot_vcap_u48 dmac
;
112 struct ocelot_vcap_u48 smac
;
114 /* LLC header: DSAP at byte 0, SSAP at byte 1, Control at byte 2 */
115 struct ocelot_vcap_u32 llc
;
118 struct ocelot_vcap_key_snap
{
119 struct ocelot_vcap_u48 dmac
;
120 struct ocelot_vcap_u48 smac
;
122 /* SNAP header: Organization Code at byte 0, Type at byte 3 */
123 struct ocelot_vcap_u40 snap
;
126 struct ocelot_vcap_key_arp
{
127 struct ocelot_vcap_u48 smac
;
128 enum ocelot_vcap_bit arp
; /* Opcode ARP/RARP */
129 enum ocelot_vcap_bit req
; /* Opcode request/reply */
130 enum ocelot_vcap_bit unknown
; /* Opcode unknown */
131 enum ocelot_vcap_bit smac_match
; /* Sender MAC matches SMAC */
132 enum ocelot_vcap_bit dmac_match
; /* Target MAC matches DMAC */
134 /**< Protocol addr. length 4, hardware length 6 */
135 enum ocelot_vcap_bit length
;
137 enum ocelot_vcap_bit ip
; /* Protocol address type IP */
138 enum ocelot_vcap_bit ethernet
; /* Hardware address type Ethernet */
139 struct ocelot_vcap_ipv4 sip
; /* Sender IP address */
140 struct ocelot_vcap_ipv4 dip
; /* Target IP address */
143 struct ocelot_vcap_key_ipv4
{
144 enum ocelot_vcap_bit ttl
; /* TTL zero */
145 enum ocelot_vcap_bit fragment
; /* Fragment */
146 enum ocelot_vcap_bit options
; /* Header options */
147 struct ocelot_vcap_u8 ds
;
148 struct ocelot_vcap_u8 proto
; /* Protocol */
149 struct ocelot_vcap_ipv4 sip
; /* Source IP address */
150 struct ocelot_vcap_ipv4 dip
; /* Destination IP address */
151 struct ocelot_vcap_u48 data
; /* Not UDP/TCP: IP data */
152 struct ocelot_vcap_udp_tcp sport
; /* UDP/TCP: Source port */
153 struct ocelot_vcap_udp_tcp dport
; /* UDP/TCP: Destination port */
154 enum ocelot_vcap_bit tcp_fin
;
155 enum ocelot_vcap_bit tcp_syn
;
156 enum ocelot_vcap_bit tcp_rst
;
157 enum ocelot_vcap_bit tcp_psh
;
158 enum ocelot_vcap_bit tcp_ack
;
159 enum ocelot_vcap_bit tcp_urg
;
160 enum ocelot_vcap_bit sip_eq_dip
; /* SIP equals DIP */
161 enum ocelot_vcap_bit sport_eq_dport
; /* SPORT equals DPORT */
162 enum ocelot_vcap_bit seq_zero
; /* TCP sequence number is zero */
165 struct ocelot_vcap_key_ipv6
{
166 struct ocelot_vcap_u8 proto
; /* IPv6 protocol */
167 struct ocelot_vcap_u128 sip
; /* IPv6 source (byte 0-7 ignored) */
168 struct ocelot_vcap_u128 dip
; /* IPv6 destination (byte 0-7 ignored) */
169 enum ocelot_vcap_bit ttl
; /* TTL zero */
170 struct ocelot_vcap_u8 ds
;
171 struct ocelot_vcap_u48 data
; /* Not UDP/TCP: IP data */
172 struct ocelot_vcap_udp_tcp sport
;
173 struct ocelot_vcap_udp_tcp dport
;
174 enum ocelot_vcap_bit tcp_fin
;
175 enum ocelot_vcap_bit tcp_syn
;
176 enum ocelot_vcap_bit tcp_rst
;
177 enum ocelot_vcap_bit tcp_psh
;
178 enum ocelot_vcap_bit tcp_ack
;
179 enum ocelot_vcap_bit tcp_urg
;
180 enum ocelot_vcap_bit sip_eq_dip
; /* SIP equals DIP */
181 enum ocelot_vcap_bit sport_eq_dport
; /* SPORT equals DPORT */
182 enum ocelot_vcap_bit seq_zero
; /* TCP sequence number is zero */
185 enum ocelot_mask_mode
{
186 OCELOT_MASK_MODE_NONE
,
187 OCELOT_MASK_MODE_PERMIT_DENY
,
188 OCELOT_MASK_MODE_POLICY
,
189 OCELOT_MASK_MODE_REDIRECT
,
192 enum ocelot_es0_tag
{
195 OCELOT_FORCE_PORT_TAG
,
199 enum ocelot_tag_tpid_sel
{
200 OCELOT_TAG_TPID_SEL_8021Q
,
201 OCELOT_TAG_TPID_SEL_8021AD
,
204 struct ocelot_vcap_action
{
208 enum ocelot_es0_tag push_outer_tag
;
209 enum ocelot_es0_tag push_inner_tag
;
210 enum ocelot_tag_tpid_sel tag_a_tpid_sel
;
216 enum ocelot_tag_tpid_sel tag_b_tpid_sel
;
226 bool vid_replace_ena
;
228 bool vlan_pop_cnt_ena
;
235 u8 pag_override_mask
;
243 enum ocelot_mask_mode mask_mode
;
244 unsigned long port_mask
;
246 struct ocelot_policer pol
;
252 struct ocelot_vcap_stats
{
258 enum ocelot_vcap_filter_type
{
259 OCELOT_VCAP_FILTER_DUMMY
,
260 OCELOT_VCAP_FILTER_PAG
,
261 OCELOT_VCAP_FILTER_OFFLOAD
,
264 struct ocelot_vcap_filter
{
265 struct list_head list
;
267 enum ocelot_vcap_filter_type type
;
275 struct ocelot_vcap_action action
;
276 struct ocelot_vcap_stats stats
;
277 /* For VCAP IS1 and IS2 */
278 unsigned long ingress_port_mask
;
280 struct ocelot_vcap_port ingress_port
;
281 struct ocelot_vcap_port egress_port
;
283 enum ocelot_vcap_bit dmac_mc
;
284 enum ocelot_vcap_bit dmac_bc
;
285 struct ocelot_vcap_key_vlan vlan
;
287 enum ocelot_vcap_key_type key_type
;
289 /* OCELOT_VCAP_KEY_ANY: No specific fields */
290 struct ocelot_vcap_key_etype etype
;
291 struct ocelot_vcap_key_llc llc
;
292 struct ocelot_vcap_key_snap snap
;
293 struct ocelot_vcap_key_arp arp
;
294 struct ocelot_vcap_key_ipv4 ipv4
;
295 struct ocelot_vcap_key_ipv6 ipv6
;
299 int ocelot_vcap_filter_add(struct ocelot
*ocelot
,
300 struct ocelot_vcap_filter
*rule
,
301 struct netlink_ext_ack
*extack
);
302 int ocelot_vcap_filter_del(struct ocelot
*ocelot
,
303 struct ocelot_vcap_filter
*rule
);
304 int ocelot_vcap_filter_stats_update(struct ocelot
*ocelot
,
305 struct ocelot_vcap_filter
*rule
);
306 struct ocelot_vcap_filter
*
307 ocelot_vcap_block_find_filter_by_id(struct ocelot_vcap_block
*block
, int id
);
309 void ocelot_detect_vcap_constants(struct ocelot
*ocelot
);
310 int ocelot_vcap_init(struct ocelot
*ocelot
);
312 int ocelot_setup_tc_cls_flower(struct ocelot_port_private
*priv
,
313 struct flow_cls_offload
*f
,
316 #endif /* _MSCC_OCELOT_VCAP_H_ */