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