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