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