1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2019-2021, Intel Corporation. */
7 #include <linux/bits.h>
10 #define ICE_TC_FLWR_FIELD_DST_MAC BIT(0)
11 #define ICE_TC_FLWR_FIELD_SRC_MAC BIT(1)
12 #define ICE_TC_FLWR_FIELD_VLAN BIT(2)
13 #define ICE_TC_FLWR_FIELD_DEST_IPV4 BIT(3)
14 #define ICE_TC_FLWR_FIELD_SRC_IPV4 BIT(4)
15 #define ICE_TC_FLWR_FIELD_DEST_IPV6 BIT(5)
16 #define ICE_TC_FLWR_FIELD_SRC_IPV6 BIT(6)
17 #define ICE_TC_FLWR_FIELD_DEST_L4_PORT BIT(7)
18 #define ICE_TC_FLWR_FIELD_SRC_L4_PORT BIT(8)
19 #define ICE_TC_FLWR_FIELD_TENANT_ID BIT(9)
20 #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV4 BIT(10)
21 #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV4 BIT(11)
22 #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV6 BIT(12)
23 #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV6 BIT(13)
24 #define ICE_TC_FLWR_FIELD_ENC_DEST_L4_PORT BIT(14)
25 #define ICE_TC_FLWR_FIELD_ENC_SRC_L4_PORT BIT(15)
26 #define ICE_TC_FLWR_FIELD_ENC_DST_MAC BIT(16)
27 #define ICE_TC_FLWR_FIELD_ETH_TYPE_ID BIT(17)
28 #define ICE_TC_FLWR_FIELD_GTP_OPTS BIT(18)
29 #define ICE_TC_FLWR_FIELD_CVLAN BIT(19)
30 #define ICE_TC_FLWR_FIELD_PPPOE_SESSID BIT(20)
31 #define ICE_TC_FLWR_FIELD_PPP_PROTO BIT(21)
32 #define ICE_TC_FLWR_FIELD_IP_TOS BIT(22)
33 #define ICE_TC_FLWR_FIELD_IP_TTL BIT(23)
34 #define ICE_TC_FLWR_FIELD_ENC_IP_TOS BIT(24)
35 #define ICE_TC_FLWR_FIELD_ENC_IP_TTL BIT(25)
36 #define ICE_TC_FLWR_FIELD_L2TPV3_SESSID BIT(26)
37 #define ICE_TC_FLWR_FIELD_VLAN_PRIO BIT(27)
38 #define ICE_TC_FLWR_FIELD_CVLAN_PRIO BIT(28)
39 #define ICE_TC_FLWR_FIELD_VLAN_TPID BIT(29)
40 #define ICE_TC_FLWR_FIELD_PFCP_OPTS BIT(30)
42 #define ICE_TC_FLOWER_MASK_32 0xFFFFFFFF
44 #define ICE_IPV6_HDR_TC_MASK 0xFF00000
46 struct ice_indr_block_priv {
47 struct net_device *netdev;
48 struct ice_netdev_priv *np;
49 struct list_head list;
52 struct ice_tc_flower_action {
53 /* forward action specific params */
56 u32 tc_class; /* forward to hw_tc */
60 u16 queue; /* forward to queue */
61 /* To add filter in HW, absolute queue number in global
62 * space of queues (between 0...N) is needed
67 enum ice_sw_fwd_act_type fltr_act;
70 struct ice_tc_vlan_hdr {
71 __be16 vlan_id; /* Only last 12 bits valid */
72 __be16 vlan_prio; /* Only last 3 bits valid (valid values: 0..7) */
76 struct ice_tc_pppoe_hdr {
81 struct ice_tc_l2_hdr {
84 __be16 n_proto; /* Ethernet Protocol */
87 struct ice_tc_l3_hdr {
88 u8 ip_proto; /* IPPROTO value */
91 struct in_addr dst_ip;
92 struct in_addr src_ip;
95 struct in6_addr dst_ip6;
96 struct in6_addr src_ip6;
99 #define dst_ipv6 ip.v6.dst_ip6.s6_addr32
100 #define dst_ipv6_addr ip.v6.dst_ip6.s6_addr
101 #define src_ipv6 ip.v6.src_ip6.s6_addr32
102 #define src_ipv6_addr ip.v6.src_ip6.s6_addr
103 #define dst_ipv4 ip.v4.dst_ip.s_addr
104 #define src_ipv4 ip.v4.src_ip.s_addr
110 struct ice_tc_l2tpv3_hdr {
114 struct ice_tc_l4_hdr {
119 struct ice_tc_flower_lyr_2_4_hdrs {
120 /* L2 layer fields with their mask */
121 struct ice_tc_l2_hdr l2_key;
122 struct ice_tc_l2_hdr l2_mask;
123 struct ice_tc_vlan_hdr vlan_hdr;
124 struct ice_tc_vlan_hdr cvlan_hdr;
125 struct ice_tc_pppoe_hdr pppoe_hdr;
126 struct ice_tc_l2tpv3_hdr l2tpv3_hdr;
127 /* L3 (IPv4[6]) layer fields with their mask */
128 struct ice_tc_l3_hdr l3_key;
129 struct ice_tc_l3_hdr l3_mask;
131 /* L4 layer fields with their mask */
132 struct ice_tc_l4_hdr l4_key;
133 struct ice_tc_l4_hdr l4_mask;
136 enum ice_eswitch_fltr_direction {
137 ICE_ESWITCH_FLTR_INGRESS,
138 ICE_ESWITCH_FLTR_EGRESS,
141 struct ice_tc_flower_fltr {
142 struct hlist_node tc_flower_node;
144 /* cookie becomes filter_rule_id if rule is added successfully */
145 unsigned long cookie;
147 /* add_adv_rule returns information like recipe ID, rule_id. Store
148 * those values since they are needed to remove advanced rule
152 /* VSI handle of the destination VSI (it could be main PF VSI, CHNL_VSI,
156 /* ptr to destination VSI */
157 struct ice_vsi *dest_vsi;
158 /* direction of fltr for eswitch use case */
159 enum ice_eswitch_fltr_direction direction;
161 /* Parsed TC flower configuration params */
162 struct ice_tc_flower_lyr_2_4_hdrs outer_headers;
163 struct ice_tc_flower_lyr_2_4_hdrs inner_headers;
164 struct ice_vsi *src_vsi;
166 struct gtp_pdu_session_info gtp_pdu_info_keys;
167 struct gtp_pdu_session_info gtp_pdu_info_masks;
168 struct pfcp_metadata pfcp_meta_keys;
169 struct pfcp_metadata pfcp_meta_masks;
172 struct ice_tc_flower_action action;
174 /* cache ptr which is used wherever needed to communicate netlink
177 struct netlink_ext_ack *extack;
181 * ice_is_chnl_fltr - is this a valid channel filter
182 * @f: Pointer to tc-flower filter
184 * Criteria to determine of given filter is valid channel filter
185 * or not is based on its destination.
186 * For forward to VSI action, if destination is valid hw_tc (aka tc_class)
187 * and in supported range of TCs for ADQ, then return true.
188 * For forward to queue, as long as dest_vsi is valid and it is of type
189 * VSI_CHNL (PF ADQ VSI is of type VSI_CHNL), return true.
190 * NOTE: For forward to queue, correct dest_vsi is still set in tc_fltr based
191 * on destination queue specified.
193 static inline bool ice_is_chnl_fltr(struct ice_tc_flower_fltr *f)
195 if (f->action.fltr_act == ICE_FWD_TO_VSI)
196 return f->action.fwd.tc.tc_class >= ICE_CHNL_START_TC &&
197 f->action.fwd.tc.tc_class < ICE_CHNL_MAX_TC;
198 else if (f->action.fltr_act == ICE_FWD_TO_Q)
199 return f->dest_vsi && f->dest_vsi->type == ICE_VSI_CHNL;
205 * ice_chnl_dmac_fltr_cnt - DMAC based CHNL filter count
208 static inline int ice_chnl_dmac_fltr_cnt(struct ice_pf *pf)
210 return pf->num_dmac_chnl_fltrs;
213 struct ice_vsi *ice_locate_vsi_using_queue(struct ice_vsi *vsi, int queue);
215 ice_add_cls_flower(struct net_device *netdev, struct ice_vsi *vsi,
216 struct flow_cls_offload *cls_flower);
218 ice_del_cls_flower(struct ice_vsi *vsi, struct flow_cls_offload *cls_flower);
219 void ice_replay_tc_fltrs(struct ice_pf *pf);
220 bool ice_is_tunnel_supported(struct net_device *dev);
222 static inline bool ice_is_forward_action(enum ice_sw_fwd_act_type fltr_act)
232 #endif /* _ICE_TC_LIB_H_ */