xref: /linux/drivers/net/ethernet/intel/ice/ice_tc_lib.h (revision 24aeeb107f0724fa15e16d5f28b39f3c3ecfc746)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2019-2021, Intel Corporation. */
3 
4 #ifndef _ICE_TC_LIB_H_
5 #define _ICE_TC_LIB_H_
6 
7 #define ICE_TC_FLWR_FIELD_DST_MAC		BIT(0)
8 #define ICE_TC_FLWR_FIELD_SRC_MAC		BIT(1)
9 #define ICE_TC_FLWR_FIELD_VLAN			BIT(2)
10 #define ICE_TC_FLWR_FIELD_DEST_IPV4		BIT(3)
11 #define ICE_TC_FLWR_FIELD_SRC_IPV4		BIT(4)
12 #define ICE_TC_FLWR_FIELD_DEST_IPV6		BIT(5)
13 #define ICE_TC_FLWR_FIELD_SRC_IPV6		BIT(6)
14 #define ICE_TC_FLWR_FIELD_DEST_L4_PORT		BIT(7)
15 #define ICE_TC_FLWR_FIELD_SRC_L4_PORT		BIT(8)
16 #define ICE_TC_FLWR_FIELD_TENANT_ID		BIT(9)
17 #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV4		BIT(10)
18 #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV4		BIT(11)
19 #define ICE_TC_FLWR_FIELD_ENC_DEST_IPV6		BIT(12)
20 #define ICE_TC_FLWR_FIELD_ENC_SRC_IPV6		BIT(13)
21 #define ICE_TC_FLWR_FIELD_ENC_DEST_L4_PORT	BIT(14)
22 #define ICE_TC_FLWR_FIELD_ENC_SRC_L4_PORT	BIT(15)
23 #define ICE_TC_FLWR_FIELD_ENC_DST_MAC		BIT(16)
24 #define ICE_TC_FLWR_FIELD_ETH_TYPE_ID		BIT(17)
25 #define ICE_TC_FLWR_FIELD_ENC_OPTS		BIT(18)
26 #define ICE_TC_FLWR_FIELD_CVLAN			BIT(19)
27 #define ICE_TC_FLWR_FIELD_PPPOE_SESSID		BIT(20)
28 #define ICE_TC_FLWR_FIELD_PPP_PROTO		BIT(21)
29 #define ICE_TC_FLWR_FIELD_IP_TOS		BIT(22)
30 #define ICE_TC_FLWR_FIELD_IP_TTL		BIT(23)
31 #define ICE_TC_FLWR_FIELD_ENC_IP_TOS		BIT(24)
32 #define ICE_TC_FLWR_FIELD_ENC_IP_TTL		BIT(25)
33 #define ICE_TC_FLWR_FIELD_L2TPV3_SESSID		BIT(26)
34 
35 #define ICE_TC_FLOWER_MASK_32   0xFFFFFFFF
36 
37 #define ICE_IPV6_HDR_TC_MASK 0xFF00000
38 
39 struct ice_indr_block_priv {
40 	struct net_device *netdev;
41 	struct ice_netdev_priv *np;
42 	struct list_head list;
43 };
44 
45 struct ice_tc_flower_action {
46 	u32 tc_class;
47 	enum ice_sw_fwd_act_type fltr_act;
48 };
49 
50 struct ice_tc_vlan_hdr {
51 	__be16 vlan_id; /* Only last 12 bits valid */
52 	u16 vlan_prio; /* Only last 3 bits valid (valid values: 0..7) */
53 	__be16 vlan_tpid;
54 };
55 
56 struct ice_tc_pppoe_hdr {
57 	__be16 session_id;
58 	__be16 ppp_proto;
59 };
60 
61 struct ice_tc_l2_hdr {
62 	u8 dst_mac[ETH_ALEN];
63 	u8 src_mac[ETH_ALEN];
64 	__be16 n_proto;    /* Ethernet Protocol */
65 };
66 
67 struct ice_tc_l3_hdr {
68 	u8 ip_proto;    /* IPPROTO value */
69 	union {
70 		struct {
71 			struct in_addr dst_ip;
72 			struct in_addr src_ip;
73 		} v4;
74 		struct {
75 			struct in6_addr dst_ip6;
76 			struct in6_addr src_ip6;
77 		} v6;
78 	} ip;
79 #define dst_ipv6	ip.v6.dst_ip6.s6_addr32
80 #define dst_ipv6_addr	ip.v6.dst_ip6.s6_addr
81 #define src_ipv6	ip.v6.src_ip6.s6_addr32
82 #define src_ipv6_addr	ip.v6.src_ip6.s6_addr
83 #define dst_ipv4	ip.v4.dst_ip.s_addr
84 #define src_ipv4	ip.v4.src_ip.s_addr
85 
86 	u8 tos;
87 	u8 ttl;
88 };
89 
90 struct ice_tc_l2tpv3_hdr {
91 	__be32 session_id;
92 };
93 
94 struct ice_tc_l4_hdr {
95 	__be16 dst_port;
96 	__be16 src_port;
97 };
98 
99 struct ice_tc_flower_lyr_2_4_hdrs {
100 	/* L2 layer fields with their mask */
101 	struct ice_tc_l2_hdr l2_key;
102 	struct ice_tc_l2_hdr l2_mask;
103 	struct ice_tc_vlan_hdr vlan_hdr;
104 	struct ice_tc_vlan_hdr cvlan_hdr;
105 	struct ice_tc_pppoe_hdr pppoe_hdr;
106 	struct ice_tc_l2tpv3_hdr l2tpv3_hdr;
107 	/* L3 (IPv4[6]) layer fields with their mask */
108 	struct ice_tc_l3_hdr l3_key;
109 	struct ice_tc_l3_hdr l3_mask;
110 
111 	/* L4 layer fields with their mask */
112 	struct ice_tc_l4_hdr l4_key;
113 	struct ice_tc_l4_hdr l4_mask;
114 };
115 
116 enum ice_eswitch_fltr_direction {
117 	ICE_ESWITCH_FLTR_INGRESS,
118 	ICE_ESWITCH_FLTR_EGRESS,
119 };
120 
121 struct ice_tc_flower_fltr {
122 	struct hlist_node tc_flower_node;
123 
124 	/* cookie becomes filter_rule_id if rule is added successfully */
125 	unsigned long cookie;
126 
127 	/* add_adv_rule returns information like recipe ID, rule_id. Store
128 	 * those values since they are needed to remove advanced rule
129 	 */
130 	u16 rid;
131 	u16 rule_id;
132 	/* this could be queue/vsi_idx (sw handle)/queue_group, depending upon
133 	 * destination type
134 	 */
135 	u16 dest_id;
136 	/* if dest_id is vsi_idx, then need to store destination VSI ptr */
137 	struct ice_vsi *dest_vsi;
138 	/* direction of fltr for eswitch use case */
139 	enum ice_eswitch_fltr_direction direction;
140 
141 	/* Parsed TC flower configuration params */
142 	struct ice_tc_flower_lyr_2_4_hdrs outer_headers;
143 	struct ice_tc_flower_lyr_2_4_hdrs inner_headers;
144 	struct ice_vsi *src_vsi;
145 	__be32 tenant_id;
146 	struct gtp_pdu_session_info gtp_pdu_info_keys;
147 	struct gtp_pdu_session_info gtp_pdu_info_masks;
148 	u32 flags;
149 	u8 tunnel_type;
150 	struct ice_tc_flower_action	action;
151 
152 	/* cache ptr which is used wherever needed to communicate netlink
153 	 * messages
154 	 */
155 	struct netlink_ext_ack *extack;
156 };
157 
158 /**
159  * ice_is_chnl_fltr - is this a valid channel filter
160  * @f: Pointer to tc-flower filter
161  *
162  * Criteria to determine of given filter is valid channel filter
163  * or not is based on its "destination". If destination is hw_tc (aka tc_class)
164  * and it is non-zero, then it is valid channel (aka ADQ) filter
165  */
166 static inline bool ice_is_chnl_fltr(struct ice_tc_flower_fltr *f)
167 {
168 	return !!f->action.tc_class;
169 }
170 
171 /**
172  * ice_chnl_dmac_fltr_cnt - DMAC based CHNL filter count
173  * @pf: Pointer to PF
174  */
175 static inline int ice_chnl_dmac_fltr_cnt(struct ice_pf *pf)
176 {
177 	return pf->num_dmac_chnl_fltrs;
178 }
179 
180 int
181 ice_add_cls_flower(struct net_device *netdev, struct ice_vsi *vsi,
182 		   struct flow_cls_offload *cls_flower);
183 int
184 ice_del_cls_flower(struct ice_vsi *vsi, struct flow_cls_offload *cls_flower);
185 void ice_replay_tc_fltrs(struct ice_pf *pf);
186 bool ice_is_tunnel_supported(struct net_device *dev);
187 
188 #endif /* _ICE_TC_LIB_H_ */
189