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 enum ice_fltr_prgm_desc_dest {
54 	ICE_FLTR_PRGM_DESC_DEST_DROP_PKT,
55 	ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX,
56 	ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP,
57 	ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER,
58 };
59 
60 enum ice_fltr_prgm_desc_fd_status {
61 	ICE_FLTR_PRGM_DESC_FD_STATUS_NONE,
62 	ICE_FLTR_PRGM_DESC_FD_STATUS_FD_ID,
63 };
64 
65 /* Flow Director (FD) Filter Programming descriptor */
66 struct ice_fd_fltr_desc_ctx {
67 	u32 fdid;
68 	u16 qindex;
69 	u16 cnt_index;
70 	u16 fd_vsi;
71 	u16 flex_val;
72 	u8 comp_q;
73 	u8 comp_report;
74 	u8 fd_space;
75 	u8 cnt_ena;
76 	u8 evict_ena;
77 	u8 toq;
78 	u8 toq_prio;
79 	u8 dpu_recipe;
80 	u8 drop;
81 	u8 flex_prio;
82 	u8 flex_mdid;
83 	u8 dtype;
84 	u8 pcmd;
85 	u8 desc_prof_prio;
86 	u8 desc_prof;
87 	u8 swap;
88 	u8 fdid_prio;
89 	u8 fdid_mdid;
90 };
91 
92 #define ICE_FLTR_PRGM_FLEX_WORD_SIZE	sizeof(__be16)
93 
94 struct ice_rx_flow_userdef {
95 	u16 flex_word;
96 	u16 flex_offset;
97 	u16 flex_fltr;
98 };
99 
100 struct ice_fdir_v4 {
101 	__be32 dst_ip;
102 	__be32 src_ip;
103 	__be16 dst_port;
104 	__be16 src_port;
105 	__be32 l4_header;
106 	__be32 sec_parm_idx;	/* security parameter index */
107 	u8 tos;
108 	u8 ip_ver;
109 	u8 proto;
110 	u8 ttl;
111 };
112 
113 #define ICE_IPV6_ADDR_LEN_AS_U32		4
114 
115 struct ice_fdir_v6 {
116 	__be32 dst_ip[ICE_IPV6_ADDR_LEN_AS_U32];
117 	__be32 src_ip[ICE_IPV6_ADDR_LEN_AS_U32];
118 	__be16 dst_port;
119 	__be16 src_port;
120 	__be32 l4_header; /* next header */
121 	__be32 sec_parm_idx; /* security parameter index */
122 	u8 tc;
123 	u8 proto;
124 	u8 hlim;
125 };
126 
127 struct ice_fdir_udp_gtp {
128 	u8 flags;
129 	u8 msg_type;
130 	__be16 rsrvd_len;
131 	__be32 teid;
132 	__be16 rsrvd_seq_nbr;
133 	u8 rsrvd_n_pdu_nbr;
134 	u8 rsrvd_next_ext_type;
135 	u8 rsvrd_ext_len;
136 	u8	pdu_type:4,
137 		spare:4;
138 	u8	ppp:1,
139 		rqi:1,
140 		qfi:6;
141 	u32 rsvrd;
142 	u8 next_ext;
143 };
144 
145 struct ice_fdir_l2tpv3 {
146 	__be32 session_id;
147 };
148 
149 struct ice_fdir_extra {
150 	u8 dst_mac[ETH_ALEN];	/* dest MAC address */
151 	u8 src_mac[ETH_ALEN];	/* src MAC address */
152 	__be16 ether_type;	/* for NON_IP_L2 */
153 	u32 usr_def[2];		/* user data */
154 	__be16 vlan_type;	/* VLAN ethertype */
155 	__be16 vlan_tag;	/* VLAN tag info */
156 };
157 
158 struct ice_fdir_fltr {
159 	struct list_head fltr_node;
160 	enum ice_fltr_ptype flow_type;
161 
162 	union {
163 		struct ice_fdir_v4 v4;
164 		struct ice_fdir_v6 v6;
165 	} ip, mask;
166 
167 	struct ice_fdir_udp_gtp gtpu_data;
168 	struct ice_fdir_udp_gtp gtpu_mask;
169 
170 	struct ice_fdir_l2tpv3 l2tpv3_data;
171 	struct ice_fdir_l2tpv3 l2tpv3_mask;
172 
173 	struct ice_fdir_extra ext_data;
174 	struct ice_fdir_extra ext_mask;
175 
176 	/* flex byte filter data */
177 	__be16 flex_word;
178 	/* queue region size (=2^q_region) */
179 	u8 q_region;
180 	u16 flex_offset;
181 	u16 flex_fltr;
182 
183 	/* filter control */
184 	u16 q_index;
185 	u16 orig_q_index;
186 	u16 dest_vsi;
187 	u8 dest_ctl;
188 	u8 cnt_ena;
189 	u8 fltr_status;
190 	u16 cnt_index;
191 	u32 fltr_id;
192 	u8 fdid_prio;
193 	u8 comp_report;
194 };
195 
196 /* Dummy packet filter definition structure */
197 struct ice_fdir_base_pkt {
198 	enum ice_fltr_ptype flow;
199 	u16 pkt_len;
200 	const u8 *pkt;
201 	u16 tun_pkt_len;
202 	const u8 *tun_pkt;
203 };
204 
205 struct ice_vsi;
206 
207 int ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id);
208 int ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id);
209 int ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
210 int ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr);
211 void
212 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input,
213 		       struct ice_fltr_desc *fdesc, bool add);
214 int
215 ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
216 			  u8 *pkt, bool frag, bool tun);
217 int ice_get_fdir_cnt_all(struct ice_hw *hw);
218 int ice_fdir_num_avail_fltr(struct ice_hw *hw, struct ice_vsi *vsi);
219 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
220 bool ice_fdir_has_frag(enum ice_fltr_ptype flow);
221 struct ice_fdir_fltr *
222 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx);
223 void
224 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow, bool add);
225 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input);
226 #endif /* _ICE_FDIR_H_ */
227