1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2018-2020, Intel Corporation. */
3 
4 #ifndef _ICE_FDIR_H_
5 #define _ICE_FDIR_H_
6 
7 #define ICE_FDIR_TUN_PKT_OFF		50
8 #define ICE_FDIR_MAX_RAW_PKT_SIZE	(512 + ICE_FDIR_TUN_PKT_OFF)
9 
10 /* macros for offsets into packets for flow director programming */
11 #define ICE_ETH_TYPE_F_OFFSET		12
12 #define ICE_ETH_VLAN_TCI_OFFSET		14
13 #define ICE_ETH_TYPE_VLAN_OFFSET	16
14 #define ICE_IPV4_SRC_ADDR_OFFSET	26
15 #define ICE_IPV4_DST_ADDR_OFFSET	30
16 #define ICE_IPV4_TCP_SRC_PORT_OFFSET	34
17 #define ICE_IPV4_TCP_DST_PORT_OFFSET	36
18 #define ICE_IPV4_UDP_SRC_PORT_OFFSET	34
19 #define ICE_IPV4_UDP_DST_PORT_OFFSET	36
20 #define ICE_IPV4_SCTP_SRC_PORT_OFFSET	34
21 #define ICE_IPV4_SCTP_DST_PORT_OFFSET	36
22 #define ICE_IPV4_PROTO_OFFSET		23
23 #define ICE_IPV6_SRC_ADDR_OFFSET	22
24 #define ICE_IPV6_DST_ADDR_OFFSET	38
25 #define ICE_IPV6_TCP_SRC_PORT_OFFSET	54
26 #define ICE_IPV6_TCP_DST_PORT_OFFSET	56
27 #define ICE_IPV6_UDP_SRC_PORT_OFFSET	54
28 #define ICE_IPV6_UDP_DST_PORT_OFFSET	56
29 #define ICE_IPV6_SCTP_SRC_PORT_OFFSET	54
30 #define ICE_IPV6_SCTP_DST_PORT_OFFSET	56
31 #define ICE_MAC_ETHTYPE_OFFSET		12
32 #define ICE_IPV4_TOS_OFFSET		15
33 #define ICE_IPV4_TTL_OFFSET		22
34 #define ICE_IPV6_TC_OFFSET		14
35 #define ICE_IPV6_HLIM_OFFSET		21
36 #define ICE_IPV6_PROTO_OFFSET		20
37 #define ICE_IPV4_GTPU_TEID_OFFSET	46
38 #define ICE_IPV4_GTPU_QFI_OFFSET	56
39 #define ICE_IPV4_L2TPV3_SESS_ID_OFFSET	34
40 #define ICE_IPV6_L2TPV3_SESS_ID_OFFSET	54
41 #define ICE_IPV4_ESP_SPI_OFFSET		34
42 #define ICE_IPV6_ESP_SPI_OFFSET		54
43 #define ICE_IPV4_AH_SPI_OFFSET		38
44 #define ICE_IPV6_AH_SPI_OFFSET		58
45 #define ICE_IPV4_NAT_T_ESP_SPI_OFFSET	42
46 #define ICE_IPV6_NAT_T_ESP_SPI_OFFSET	62
47 
48 #define ICE_FDIR_MAX_FLTRS		16384
49 
50 /* IP v4 has 2 flag bits that enable fragment processing: DF and MF. DF
51  * requests that the packet not be fragmented. MF indicates that a packet has
52  * been fragmented.
53  */
54 #define ICE_FDIR_IPV4_PKT_FLAG_MF		0x20
55 
56 #define ICE_FDIR_NO_QUEUE_IDX			-1
57 
58 enum ice_fltr_prgm_desc_dest {
59 	ICE_FLTR_PRGM_DESC_DEST_DROP_PKT,
60 	ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX,
61 	ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP,
62 	ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER,
63 };
64 
65 enum ice_fltr_prgm_desc_fd_status {
66 	ICE_FLTR_PRGM_DESC_FD_STATUS_NONE,
67 	ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID,
68 };
69 
70 /* Flow Director (FD) Filter Programming descriptor */
71 struct ice_fd_fltr_desc_ctx {
72 	u32 fdid;
73 	u16 qindex;
74 	u16 cnt_index;
75 	u16 fd_vsi;
76 	u16 flex_val;
77 	u8 comp_q;
78 	u8 comp_report;
79 	u8 fd_space;
80 	u8 cnt_ena;
81 	u8 evict_ena;
82 	u8 toq;
83 	u8 toq_prio;
84 	u8 dpu_recipe;
85 	u8 drop;
86 	u8 flex_prio;
87 	u8 flex_mdid;
88 	u8 dtype;
89 	u8 pcmd;
90 	u8 desc_prof_prio;
91 	u8 desc_prof;
92 	u8 swap;
93 	u8 fdid_prio;
94 	u8 fdid_mdid;
95 };
96 
97 #define ICE_FLTR_PRGM_FLEX_WORD_SIZE	sizeof(__be16)
98 
99 struct ice_rx_flow_userdef {
100 	u16 flex_word;
101 	u16 flex_offset;
102 	u16 flex_fltr;
103 };
104 
105 struct ice_fdir_v4 {
106 	__be32 dst_ip;
107 	__be32 src_ip;
108 	__be16 dst_port;
109 	__be16 src_port;
110 	__be32 l4_header;
111 	__be32 sec_parm_idx;	/* security parameter index */
112 	u8 tos;
113 	u8 ip_ver;
114 	u8 proto;
115 	u8 ttl;
116 };
117 
118 #define ICE_IPV6_ADDR_LEN_AS_U32		4
119 
120 struct ice_fdir_v6 {
121 	__be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32];
122 	__be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32];
123 	__be16 dst_port;
124 	__be16 src_port;
125 	__be32 l4_header; /* next header */
126 	__be32 sec_parm_idx; /* security parameter index */
127 	u8 tc;
128 	u8 proto;
129 	u8 hlim;
130 };
131 
132 struct ice_fdir_udp_gtp {
133 	u8 flags;
134 	u8 msg_type;
135 	__be16 rsrvd_len;
136 	__be32 teid;
137 	__be16 rsrvd_seq_nbr;
138 	u8 rsrvd_n_pdu_nbr;
139 	u8 rsrvd_next_ext_type;
140 	u8 rsvrd_ext_len;
141 	u8	pdu_type:4,
142 		spare:4;
143 	u8	ppp:1,
144 		rqi:1,
145 		qfi:6;
146 	u32 rsvrd;
147 	u8 next_ext;
148 };
149 
150 struct ice_fdir_l2tpv3 {
151 	__be32 session_id;
152 };
153 
154 struct ice_fdir_extra {
155 	u8 dst_mac[ETH_ALEN];	/* dest MAC address */
156 	u8 src_mac[ETH_ALEN];	/* src MAC address */
157 	__be16 ether_type;	/* for NON_IP_L2 */
158 	u32 usr_def[2];		/* user data */
159 	__be16 vlan_type;	/* VLAN ethertype */
160 	__be16 vlan_tag;	/* VLAN tag info */
161 };
162 
163 struct ice_fdir_fltr {
164 	struct list_head fltr_node;
165 	enum ice_fltr_ptype flow_type;
166 
167 	struct ethhdr eth, eth_mask;
168 
169 	union {
170 		struct ice_fdir_v4 v4;
171 		struct ice_fdir_v6 v6;
172 	} ip, mask;
173 
174 	struct ice_fdir_udp_gtp gtpu_data;
175 	struct ice_fdir_udp_gtp gtpu_mask;
176 
177 	struct ice_fdir_l2tpv3 l2tpv3_data;
178 	struct ice_fdir_l2tpv3 l2tpv3_mask;
179 
180 	struct ice_fdir_extra ext_data;
181 	struct ice_fdir_extra ext_mask;
182 
183 	/* flex byte filter data */
184 	__be16 flex_word;
185 	/* queue region size (=2^q_region) */
186 	u8 q_region;
187 	u16 flex_offset;
188 	u16 flex_fltr;
189 
190 	/* filter control */
191 	s16 q_index;
192 	u16 orig_q_index;
193 	u16 dest_vsi;
194 	u8 dest_ctl;
195 	u8 cnt_ena;
196 	u8 fltr_status;
197 	u16 cnt_index;
198 	u32 fltr_id;
199 	u8 fdid_prio;
200 	u8 comp_report;
201 };
202 
203 /* Dummy packet filter definition structure */
204 struct ice_fdir_base_pkt {
205 	enum ice_fltr_ptype flow;
206 	u16 pkt_len;
207 	const u8 *pkt;
208 	u16 tun_pkt_len;
209 	const u8 *tun_pkt;
210 };
211 
212 struct ice_vsi;
213 
214 int ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id);
215 int ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id);
216 int ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
217 int ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
218 void
219 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input,
220 		       struct ice_fltr_desc *fdesc, bool add);
221 int
222 ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
223 			  u8 *pkt, bool frag, bool tun);
224 int ice_get_fdir_cnt_all(struct ice_hw *hw);
225 int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi);
226 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
227 bool ice_fdir_has_frag(enum ice_fltr_ptype flow);
228 struct ice_fdir_fltr *
229 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx);
230 void
231 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add);
232 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
233 #endif /* _ICE_FDIR_H_ */
234