Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <rte_flow.h>
7 : : #include <rte_hash.h>
8 : : #include <rte_hash_crc.h>
9 : : #include "base/ice_fdir.h"
10 : : #include "base/ice_flow.h"
11 : : #include "base/ice_type.h"
12 : : #include "ice_ethdev.h"
13 : : #include "ice_rxtx.h"
14 : : #include "ice_generic_flow.h"
15 : :
16 : : #define ICE_FDIR_IPV6_TC_OFFSET 20
17 : : #define ICE_IPV6_TC_MASK (0xFF << ICE_FDIR_IPV6_TC_OFFSET)
18 : :
19 : : #define ICE_FDIR_MAX_QREGION_SIZE 128
20 : :
21 : : #define ICE_FDIR_INSET_ETH (\
22 : : ICE_INSET_DMAC | ICE_INSET_SMAC | ICE_INSET_ETHERTYPE)
23 : :
24 : : #define ICE_FDIR_INSET_ETH_IPV4 (\
25 : : ICE_FDIR_INSET_ETH | \
26 : : ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_IPV4_TOS | \
27 : : ICE_INSET_IPV4_TTL | ICE_INSET_IPV4_PROTO | ICE_INSET_IPV4_PKID)
28 : :
29 : : #define ICE_FDIR_INSET_ETH_IPV4_UDP (\
30 : : ICE_FDIR_INSET_ETH_IPV4 | \
31 : : ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
32 : :
33 : : #define ICE_FDIR_INSET_ETH_IPV4_TCP (\
34 : : ICE_FDIR_INSET_ETH_IPV4 | \
35 : : ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
36 : :
37 : : #define ICE_FDIR_INSET_ETH_IPV4_SCTP (\
38 : : ICE_FDIR_INSET_ETH_IPV4 | \
39 : : ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
40 : :
41 : : #define ICE_FDIR_INSET_ETH_IPV6 (\
42 : : ICE_INSET_DMAC | \
43 : : ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | ICE_INSET_IPV6_TC | \
44 : : ICE_INSET_IPV6_HOP_LIMIT | ICE_INSET_IPV6_NEXT_HDR | \
45 : : ICE_INSET_IPV6_PKID)
46 : :
47 : : #define ICE_FDIR_INSET_ETH_IPV6_UDP (\
48 : : ICE_FDIR_INSET_ETH_IPV6 | \
49 : : ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
50 : :
51 : : #define ICE_FDIR_INSET_ETH_IPV6_TCP (\
52 : : ICE_FDIR_INSET_ETH_IPV6 | \
53 : : ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
54 : :
55 : : #define ICE_FDIR_INSET_ETH_IPV6_SCTP (\
56 : : ICE_FDIR_INSET_ETH_IPV6 | \
57 : : ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
58 : :
59 : : #define ICE_FDIR_INSET_IPV4 (\
60 : : ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
61 : : ICE_INSET_IPV4_PKID)
62 : :
63 : : #define ICE_FDIR_INSET_IPV4_TCP (\
64 : : ICE_FDIR_INSET_IPV4 | \
65 : : ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
66 : :
67 : : #define ICE_FDIR_INSET_IPV4_UDP (\
68 : : ICE_FDIR_INSET_IPV4 | \
69 : : ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
70 : :
71 : : #define ICE_FDIR_INSET_IPV4_SCTP (\
72 : : ICE_FDIR_INSET_IPV4 | \
73 : : ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
74 : :
75 : : #define ICE_FDIR_INSET_ETH_IPV4_VXLAN (\
76 : : ICE_FDIR_INSET_ETH | ICE_FDIR_INSET_ETH_IPV4 | \
77 : : ICE_INSET_VXLAN_VNI)
78 : :
79 : : #define ICE_FDIR_INSET_IPV4_GTPU (\
80 : : ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_GTPU_TEID)
81 : :
82 : : #define ICE_FDIR_INSET_IPV4_GTPU_EH (\
83 : : ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
84 : : ICE_INSET_GTPU_TEID | ICE_INSET_GTPU_QFI)
85 : :
86 : : #define ICE_FDIR_INSET_IPV6_GTPU (\
87 : : ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | ICE_INSET_GTPU_TEID)
88 : :
89 : : #define ICE_FDIR_INSET_IPV6_GTPU_EH (\
90 : : ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | \
91 : : ICE_INSET_GTPU_TEID | ICE_INSET_GTPU_QFI)
92 : :
93 : : #define ICE_FDIR_INSET_IPV4_ESP (\
94 : : ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
95 : : ICE_INSET_ESP_SPI)
96 : :
97 : : #define ICE_FDIR_INSET_IPV6_ESP (\
98 : : ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | \
99 : : ICE_INSET_ESP_SPI)
100 : :
101 : : #define ICE_FDIR_INSET_IPV4_NATT_ESP (\
102 : : ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
103 : : ICE_INSET_NAT_T_ESP_SPI)
104 : :
105 : : #define ICE_FDIR_INSET_IPV6_NATT_ESP (\
106 : : ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | \
107 : : ICE_INSET_NAT_T_ESP_SPI)
108 : :
109 : : static struct ice_pattern_match_item ice_fdir_supported_pattern[] = {
110 : : {pattern_raw, ICE_INSET_NONE, ICE_INSET_NONE, ICE_INSET_NONE},
111 : : {pattern_ethertype, ICE_FDIR_INSET_ETH, ICE_INSET_NONE, ICE_INSET_NONE},
112 : : {pattern_eth_ipv4, ICE_FDIR_INSET_ETH_IPV4, ICE_INSET_NONE, ICE_INSET_NONE},
113 : : {pattern_eth_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_UDP, ICE_INSET_NONE, ICE_INSET_NONE},
114 : : {pattern_eth_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_TCP, ICE_INSET_NONE, ICE_INSET_NONE},
115 : : {pattern_eth_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_SCTP, ICE_INSET_NONE, ICE_INSET_NONE},
116 : : {pattern_eth_ipv6, ICE_FDIR_INSET_ETH_IPV6, ICE_INSET_NONE, ICE_INSET_NONE},
117 : : {pattern_eth_ipv6_frag_ext, ICE_FDIR_INSET_ETH_IPV6, ICE_INSET_NONE, ICE_INSET_NONE},
118 : : {pattern_eth_ipv6_udp, ICE_FDIR_INSET_ETH_IPV6_UDP, ICE_INSET_NONE, ICE_INSET_NONE},
119 : : {pattern_eth_ipv6_tcp, ICE_FDIR_INSET_ETH_IPV6_TCP, ICE_INSET_NONE, ICE_INSET_NONE},
120 : : {pattern_eth_ipv6_sctp, ICE_FDIR_INSET_ETH_IPV6_SCTP, ICE_INSET_NONE, ICE_INSET_NONE},
121 : : {pattern_eth_ipv4_esp, ICE_FDIR_INSET_IPV4_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
122 : : {pattern_eth_ipv4_udp_esp, ICE_FDIR_INSET_IPV4_NATT_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
123 : : {pattern_eth_ipv6_esp, ICE_FDIR_INSET_IPV6_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
124 : : {pattern_eth_ipv6_udp_esp, ICE_FDIR_INSET_IPV6_NATT_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
125 : : {pattern_eth_ipv4_udp_vxlan_ipv4, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4, ICE_INSET_NONE},
126 : : {pattern_eth_ipv4_udp_vxlan_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4_UDP, ICE_INSET_NONE},
127 : : {pattern_eth_ipv4_udp_vxlan_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4_TCP, ICE_INSET_NONE},
128 : : {pattern_eth_ipv4_udp_vxlan_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4_SCTP, ICE_INSET_NONE},
129 : : {pattern_eth_ipv4_udp_vxlan_eth_ipv4, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4, ICE_INSET_NONE},
130 : : {pattern_eth_ipv4_udp_vxlan_eth_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4_UDP, ICE_INSET_NONE},
131 : : {pattern_eth_ipv4_udp_vxlan_eth_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4_TCP, ICE_INSET_NONE},
132 : : {pattern_eth_ipv4_udp_vxlan_eth_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4_SCTP, ICE_INSET_NONE},
133 : : /* duplicated GTPU input set in 3rd column to align with shared code behavior. Ideally, only put GTPU field in 2nd column. */
134 : : {pattern_eth_ipv4_gtpu, ICE_FDIR_INSET_IPV4_GTPU, ICE_FDIR_INSET_IPV4_GTPU, ICE_INSET_NONE},
135 : : {pattern_eth_ipv4_gtpu_eh, ICE_FDIR_INSET_IPV4_GTPU_EH, ICE_FDIR_INSET_IPV4_GTPU_EH, ICE_INSET_NONE},
136 : : {pattern_eth_ipv6_gtpu, ICE_FDIR_INSET_IPV6_GTPU, ICE_FDIR_INSET_IPV6_GTPU, ICE_INSET_NONE},
137 : : {pattern_eth_ipv6_gtpu_eh, ICE_FDIR_INSET_IPV6_GTPU_EH, ICE_FDIR_INSET_IPV6_GTPU_EH, ICE_INSET_NONE},
138 : : };
139 : :
140 : : static int
141 : : ice_fdir_is_tunnel_profile(enum ice_fdir_tunnel_type tunnel_type);
142 : :
143 : : static const struct rte_memzone *
144 : 0 : ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
145 : : {
146 : : const struct rte_memzone *mz;
147 : :
148 : 0 : mz = rte_memzone_lookup(name);
149 [ # # ]: 0 : if (mz)
150 : : return mz;
151 : :
152 : 0 : return rte_memzone_reserve_aligned(name, len, socket_id,
153 : : RTE_MEMZONE_IOVA_CONTIG,
154 : : ICE_RING_BASE_ALIGN);
155 : : }
156 : :
157 : : #define ICE_FDIR_MZ_NAME "FDIR_MEMZONE"
158 : :
159 : : static int
160 : 0 : ice_fdir_prof_alloc(struct ice_hw *hw)
161 : : {
162 : : enum ice_fltr_ptype ptype, fltr_ptype;
163 : :
164 [ # # ]: 0 : if (!hw->fdir_prof) {
165 : 0 : hw->fdir_prof = (struct ice_fd_hw_prof **)
166 : 0 : ice_malloc(hw, ICE_FLTR_PTYPE_MAX *
167 : : sizeof(*hw->fdir_prof));
168 [ # # ]: 0 : if (!hw->fdir_prof)
169 : : return -ENOMEM;
170 : : }
171 : : for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
172 [ # # ]: 0 : ptype < ICE_FLTR_PTYPE_MAX;
173 : 0 : ptype++) {
174 [ # # ]: 0 : if (!hw->fdir_prof[ptype]) {
175 : 0 : hw->fdir_prof[ptype] = (struct ice_fd_hw_prof *)
176 : 0 : ice_malloc(hw, sizeof(**hw->fdir_prof));
177 [ # # ]: 0 : if (!hw->fdir_prof[ptype])
178 : 0 : goto fail_mem;
179 : : }
180 : : }
181 : : return 0;
182 : :
183 : : fail_mem:
184 : 0 : for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
185 [ # # ]: 0 : fltr_ptype < ptype;
186 : 0 : fltr_ptype++) {
187 : 0 : rte_free(hw->fdir_prof[fltr_ptype]);
188 : 0 : hw->fdir_prof[fltr_ptype] = NULL;
189 : : }
190 : :
191 : 0 : rte_free(hw->fdir_prof);
192 : 0 : hw->fdir_prof = NULL;
193 : :
194 : 0 : return -ENOMEM;
195 : : }
196 : :
197 : : static int
198 : 0 : ice_fdir_counter_pool_add(__rte_unused struct ice_pf *pf,
199 : : struct ice_fdir_counter_pool_container *container,
200 : : uint32_t index_start,
201 : : uint32_t len)
202 : : {
203 : : struct ice_fdir_counter_pool *pool;
204 : : uint32_t i;
205 : : int ret = 0;
206 : :
207 : 0 : pool = rte_zmalloc("ice_fdir_counter_pool",
208 : : sizeof(*pool) +
209 : 0 : sizeof(struct ice_fdir_counter) * len,
210 : : 0);
211 [ # # ]: 0 : if (!pool) {
212 : 0 : PMD_INIT_LOG(ERR,
213 : : "Failed to allocate memory for fdir counter pool");
214 : 0 : return -ENOMEM;
215 : : }
216 : :
217 : 0 : TAILQ_INIT(&pool->counter_list);
218 : 0 : TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
219 : :
220 [ # # ]: 0 : for (i = 0; i < len; i++) {
221 : 0 : struct ice_fdir_counter *counter = &pool->counters[i];
222 : :
223 : 0 : counter->hw_index = index_start + i;
224 : 0 : TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
225 : : }
226 : :
227 [ # # ]: 0 : if (container->index_free == ICE_FDIR_COUNTER_MAX_POOL_SIZE) {
228 : 0 : PMD_INIT_LOG(ERR, "FDIR counter pool is full");
229 : : ret = -EINVAL;
230 : 0 : goto free_pool;
231 : : }
232 : :
233 : 0 : container->pools[container->index_free++] = pool;
234 : 0 : return 0;
235 : :
236 : : free_pool:
237 : 0 : rte_free(pool);
238 : 0 : return ret;
239 : : }
240 : :
241 : : static int
242 : 0 : ice_fdir_counter_init(struct ice_pf *pf)
243 : : {
244 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
245 : : struct ice_fdir_info *fdir_info = &pf->fdir;
246 : 0 : struct ice_fdir_counter_pool_container *container =
247 : : &fdir_info->counter;
248 : : uint32_t cnt_index, len;
249 : : int ret;
250 : :
251 : 0 : TAILQ_INIT(&container->pool_list);
252 : :
253 : 0 : cnt_index = ICE_FDIR_COUNTER_INDEX(hw->fd_ctr_base);
254 : : len = ICE_FDIR_COUNTERS_PER_BLOCK;
255 : :
256 : 0 : ret = ice_fdir_counter_pool_add(pf, container, cnt_index, len);
257 [ # # ]: 0 : if (ret) {
258 : 0 : PMD_INIT_LOG(ERR, "Failed to add fdir pool to container");
259 : 0 : return ret;
260 : : }
261 : :
262 : : return 0;
263 : : }
264 : :
265 : : static int
266 : : ice_fdir_counter_release(struct ice_pf *pf)
267 : : {
268 : : struct ice_fdir_info *fdir_info = &pf->fdir;
269 : : struct ice_fdir_counter_pool_container *container =
270 : : &fdir_info->counter;
271 : : uint8_t i;
272 : :
273 [ # # ]: 0 : for (i = 0; i < container->index_free; i++) {
274 : 0 : rte_free(container->pools[i]);
275 : 0 : container->pools[i] = NULL;
276 : : }
277 : :
278 : 0 : TAILQ_INIT(&container->pool_list);
279 : 0 : container->index_free = 0;
280 : :
281 : : return 0;
282 : : }
283 : :
284 : : static struct ice_fdir_counter *
285 : 0 : ice_fdir_counter_shared_search(struct ice_fdir_counter_pool_container
286 : : *container,
287 : : uint32_t id)
288 : : {
289 : : struct ice_fdir_counter_pool *pool;
290 : : struct ice_fdir_counter *counter;
291 : : int i;
292 : :
293 [ # # ]: 0 : TAILQ_FOREACH(pool, &container->pool_list, next) {
294 [ # # ]: 0 : for (i = 0; i < ICE_FDIR_COUNTERS_PER_BLOCK; i++) {
295 : 0 : counter = &pool->counters[i];
296 : :
297 [ # # ]: 0 : if (counter->shared &&
298 [ # # ]: 0 : counter->ref_cnt &&
299 [ # # ]: 0 : counter->id == id)
300 : 0 : return counter;
301 : : }
302 : : }
303 : :
304 : : return NULL;
305 : : }
306 : :
307 : : static struct ice_fdir_counter *
308 : 0 : ice_fdir_counter_alloc(struct ice_pf *pf, uint32_t shared, uint32_t id)
309 : : {
310 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
311 : : struct ice_fdir_info *fdir_info = &pf->fdir;
312 : 0 : struct ice_fdir_counter_pool_container *container =
313 : : &fdir_info->counter;
314 : : struct ice_fdir_counter_pool *pool = NULL;
315 : : struct ice_fdir_counter *counter_free = NULL;
316 : :
317 [ # # ]: 0 : if (shared) {
318 : 0 : counter_free = ice_fdir_counter_shared_search(container, id);
319 [ # # ]: 0 : if (counter_free) {
320 [ # # ]: 0 : if (counter_free->ref_cnt + 1 == 0) {
321 : 0 : rte_errno = E2BIG;
322 : 0 : return NULL;
323 : : }
324 : 0 : counter_free->ref_cnt++;
325 : 0 : return counter_free;
326 : : }
327 : : }
328 : :
329 [ # # ]: 0 : TAILQ_FOREACH(pool, &container->pool_list, next) {
330 : 0 : counter_free = TAILQ_FIRST(&pool->counter_list);
331 [ # # ]: 0 : if (counter_free)
332 : : break;
333 : : counter_free = NULL;
334 : : }
335 : :
336 [ # # ]: 0 : if (!counter_free) {
337 : 0 : PMD_DRV_LOG(ERR, "No free counter found\n");
338 : 0 : return NULL;
339 : : }
340 : :
341 : 0 : counter_free->shared = shared;
342 : 0 : counter_free->id = id;
343 : 0 : counter_free->ref_cnt = 1;
344 : 0 : counter_free->pool = pool;
345 : :
346 : : /* reset statistic counter value */
347 : 0 : ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter_free->hw_index), 0);
348 : 0 : ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter_free->hw_index), 0);
349 : :
350 [ # # ]: 0 : TAILQ_REMOVE(&pool->counter_list, counter_free, next);
351 [ # # ]: 0 : if (TAILQ_EMPTY(&pool->counter_list)) {
352 [ # # ]: 0 : TAILQ_REMOVE(&container->pool_list, pool, next);
353 : 0 : TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
354 : : }
355 : :
356 : : return counter_free;
357 : : }
358 : :
359 : : static void
360 : : ice_fdir_counter_free(__rte_unused struct ice_pf *pf,
361 : : struct ice_fdir_counter *counter)
362 : : {
363 : : if (!counter)
364 : : return;
365 : :
366 [ # # # # ]: 0 : if (--counter->ref_cnt == 0) {
367 : 0 : struct ice_fdir_counter_pool *pool = counter->pool;
368 : :
369 : 0 : TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
370 : : }
371 : : }
372 : :
373 : : static int
374 : 0 : ice_fdir_init_filter_list(struct ice_pf *pf)
375 : : {
376 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
377 : : struct ice_fdir_info *fdir_info = &pf->fdir;
378 : : char fdir_hash_name[RTE_HASH_NAMESIZE];
379 : : int ret;
380 : :
381 : 0 : struct rte_hash_parameters fdir_hash_params = {
382 : : .name = fdir_hash_name,
383 : : .entries = ICE_MAX_FDIR_FILTER_NUM,
384 : : .key_len = sizeof(struct ice_fdir_fltr_pattern),
385 : : .hash_func = rte_hash_crc,
386 : : .hash_func_init_val = 0,
387 : 0 : .socket_id = rte_socket_id(),
388 : : .extra_flag = RTE_HASH_EXTRA_FLAGS_EXT_TABLE,
389 : : };
390 : :
391 : : /* Initialize hash */
392 : 0 : snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
393 : 0 : "fdir_%s", dev->device->name);
394 : 0 : fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
395 [ # # ]: 0 : if (!fdir_info->hash_table) {
396 : 0 : PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
397 : 0 : return -EINVAL;
398 : : }
399 : 0 : fdir_info->hash_map = rte_zmalloc("ice_fdir_hash_map",
400 : : sizeof(*fdir_info->hash_map) *
401 : : ICE_MAX_FDIR_FILTER_NUM,
402 : : 0);
403 [ # # ]: 0 : if (!fdir_info->hash_map) {
404 : 0 : PMD_INIT_LOG(ERR,
405 : : "Failed to allocate memory for fdir hash map!");
406 : : ret = -ENOMEM;
407 : 0 : goto err_fdir_hash_map_alloc;
408 : : }
409 : : return 0;
410 : :
411 : : err_fdir_hash_map_alloc:
412 : 0 : rte_hash_free(fdir_info->hash_table);
413 : :
414 : 0 : return ret;
415 : : }
416 : :
417 : : static void
418 : : ice_fdir_release_filter_list(struct ice_pf *pf)
419 : : {
420 : : struct ice_fdir_info *fdir_info = &pf->fdir;
421 : :
422 : 0 : rte_free(fdir_info->hash_map);
423 : 0 : rte_hash_free(fdir_info->hash_table);
424 : :
425 : 0 : fdir_info->hash_map = NULL;
426 : 0 : fdir_info->hash_table = NULL;
427 : : }
428 : :
429 : : /*
430 : : * ice_fdir_setup - reserve and initialize the Flow Director resources
431 : : * @pf: board private structure
432 : : */
433 : : static int
434 : 0 : ice_fdir_setup(struct ice_pf *pf)
435 : : {
436 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[pf->dev_data->port_id];
437 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
438 : : const struct rte_memzone *mz = NULL;
439 : : char z_name[RTE_MEMZONE_NAMESIZE];
440 : : struct ice_vsi *vsi;
441 : : int err = ICE_SUCCESS;
442 : :
443 [ # # ]: 0 : if ((pf->flags & ICE_FLAG_FDIR) == 0) {
444 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
445 : 0 : return -ENOTSUP;
446 : : }
447 : :
448 : 0 : PMD_DRV_LOG(INFO, "FDIR HW Capabilities: fd_fltr_guar = %u,"
449 : : " fd_fltr_best_effort = %u.",
450 : : hw->func_caps.fd_fltr_guar,
451 : : hw->func_caps.fd_fltr_best_effort);
452 : :
453 [ # # ]: 0 : if (pf->fdir.fdir_vsi) {
454 : 0 : PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
455 : 0 : return ICE_SUCCESS;
456 : : }
457 : :
458 : : /* make new FDIR VSI */
459 : 0 : vsi = ice_setup_vsi(pf, ICE_VSI_CTRL);
460 [ # # ]: 0 : if (!vsi) {
461 : 0 : PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
462 : 0 : return -EINVAL;
463 : : }
464 : 0 : pf->fdir.fdir_vsi = vsi;
465 : :
466 : 0 : err = ice_fdir_init_filter_list(pf);
467 [ # # ]: 0 : if (err) {
468 : 0 : PMD_DRV_LOG(ERR, "Failed to init FDIR filter list.");
469 : 0 : return -EINVAL;
470 : : }
471 : :
472 : 0 : err = ice_fdir_counter_init(pf);
473 [ # # ]: 0 : if (err) {
474 : 0 : PMD_DRV_LOG(ERR, "Failed to init FDIR counter.");
475 : 0 : return -EINVAL;
476 : : }
477 : :
478 : : /*Fdir tx queue setup*/
479 : 0 : err = ice_fdir_setup_tx_resources(pf);
480 [ # # ]: 0 : if (err) {
481 : 0 : PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
482 : 0 : goto fail_setup_tx;
483 : : }
484 : :
485 : : /*Fdir rx queue setup*/
486 : 0 : err = ice_fdir_setup_rx_resources(pf);
487 [ # # ]: 0 : if (err) {
488 : 0 : PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
489 : 0 : goto fail_setup_rx;
490 : : }
491 : :
492 : 0 : err = ice_fdir_tx_queue_start(eth_dev, pf->fdir.txq->queue_id);
493 [ # # ]: 0 : if (err) {
494 : 0 : PMD_DRV_LOG(ERR, "Failed to start FDIR TX queue.");
495 : 0 : goto fail_mem;
496 : : }
497 : :
498 : 0 : err = ice_fdir_rx_queue_start(eth_dev, pf->fdir.rxq->queue_id);
499 [ # # ]: 0 : if (err) {
500 : 0 : PMD_DRV_LOG(ERR, "Failed to start FDIR RX queue.");
501 : 0 : goto fail_mem;
502 : : }
503 : :
504 : : /* Enable FDIR MSIX interrupt */
505 : 0 : vsi->nb_used_qps = 1;
506 : 0 : ice_vsi_queues_bind_intr(vsi);
507 : 0 : ice_vsi_enable_queues_intr(vsi);
508 : :
509 : : /* reserve memory for the fdir programming packet */
510 : 0 : snprintf(z_name, sizeof(z_name), "ICE_%s_%d",
511 : : ICE_FDIR_MZ_NAME,
512 : 0 : eth_dev->data->port_id);
513 : 0 : mz = ice_memzone_reserve(z_name, ICE_FDIR_PKT_LEN, SOCKET_ID_ANY);
514 [ # # ]: 0 : if (!mz) {
515 : 0 : PMD_DRV_LOG(ERR, "Cannot init memzone for "
516 : : "flow director program packet.");
517 : : err = -ENOMEM;
518 : 0 : goto fail_mem;
519 : : }
520 : 0 : pf->fdir.prg_pkt = mz->addr;
521 : 0 : pf->fdir.dma_addr = mz->iova;
522 : 0 : pf->fdir.mz = mz;
523 : :
524 : 0 : err = ice_fdir_prof_alloc(hw);
525 [ # # ]: 0 : if (err) {
526 : 0 : PMD_DRV_LOG(ERR, "Cannot allocate memory for "
527 : : "flow director profile.");
528 : : err = -ENOMEM;
529 : 0 : goto fail_prof;
530 : : }
531 : :
532 : 0 : PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
533 : : vsi->base_queue);
534 : 0 : return ICE_SUCCESS;
535 : :
536 : : fail_prof:
537 : 0 : rte_memzone_free(pf->fdir.mz);
538 : 0 : pf->fdir.mz = NULL;
539 : 0 : fail_mem:
540 : 0 : ice_rx_queue_release(pf->fdir.rxq);
541 : 0 : pf->fdir.rxq = NULL;
542 : 0 : fail_setup_rx:
543 : 0 : ice_tx_queue_release(pf->fdir.txq);
544 : 0 : pf->fdir.txq = NULL;
545 : 0 : fail_setup_tx:
546 : 0 : ice_release_vsi(vsi);
547 : 0 : pf->fdir.fdir_vsi = NULL;
548 : 0 : return err;
549 : : }
550 : :
551 : : static void
552 : 0 : ice_fdir_prof_free(struct ice_hw *hw)
553 : : {
554 : : enum ice_fltr_ptype ptype;
555 : :
556 : 0 : for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
557 [ # # ]: 0 : ptype < ICE_FLTR_PTYPE_MAX;
558 : 0 : ptype++) {
559 : 0 : rte_free(hw->fdir_prof[ptype]);
560 : 0 : hw->fdir_prof[ptype] = NULL;
561 : : }
562 : :
563 : 0 : rte_free(hw->fdir_prof);
564 : 0 : hw->fdir_prof = NULL;
565 : 0 : }
566 : :
567 : : /* Remove a profile for some filter type */
568 : : static void
569 : 0 : ice_fdir_prof_rm(struct ice_pf *pf, enum ice_fltr_ptype ptype, bool is_tunnel)
570 : : {
571 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
572 : : struct ice_fd_hw_prof *hw_prof;
573 : : uint64_t prof_id;
574 : : uint16_t vsi_num;
575 : : int i;
576 : :
577 [ # # # # ]: 0 : if (!hw->fdir_prof || !hw->fdir_prof[ptype])
578 : : return;
579 : :
580 : : hw_prof = hw->fdir_prof[ptype];
581 : :
582 : 0 : prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
583 [ # # ]: 0 : for (i = 0; i < pf->hw_prof_cnt[ptype][is_tunnel]; i++) {
584 [ # # ]: 0 : if (hw_prof->entry_h[i][is_tunnel]) {
585 : 0 : vsi_num = ice_get_hw_vsi_num(hw,
586 : 0 : hw_prof->vsi_h[i]);
587 : 0 : ice_rem_prof_id_flow(hw, ICE_BLK_FD,
588 : : vsi_num, ptype);
589 : 0 : ice_flow_rem_entry(hw, ICE_BLK_FD,
590 : : hw_prof->entry_h[i][is_tunnel]);
591 : 0 : hw_prof->entry_h[i][is_tunnel] = 0;
592 : : }
593 : : }
594 : 0 : ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
595 : 0 : rte_free(hw_prof->fdir_seg[is_tunnel]);
596 : 0 : hw_prof->fdir_seg[is_tunnel] = NULL;
597 : :
598 [ # # ]: 0 : for (i = 0; i < hw_prof->cnt; i++)
599 : 0 : hw_prof->vsi_h[i] = 0;
600 : 0 : pf->hw_prof_cnt[ptype][is_tunnel] = 0;
601 : : }
602 : :
603 : : /* Remove all created profiles */
604 : : static void
605 : 0 : ice_fdir_prof_rm_all(struct ice_pf *pf)
606 : : {
607 : : enum ice_fltr_ptype ptype;
608 : :
609 : 0 : for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
610 [ # # ]: 0 : ptype < ICE_FLTR_PTYPE_MAX;
611 : 0 : ptype++) {
612 : 0 : ice_fdir_prof_rm(pf, ptype, false);
613 : 0 : ice_fdir_prof_rm(pf, ptype, true);
614 : : }
615 : 0 : }
616 : :
617 : : /*
618 : : * ice_fdir_teardown - release the Flow Director resources
619 : : * @pf: board private structure
620 : : */
621 : : static void
622 : 0 : ice_fdir_teardown(struct ice_pf *pf)
623 : : {
624 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[pf->dev_data->port_id];
625 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
626 : : struct ice_vsi *vsi;
627 : : int err;
628 : :
629 : 0 : vsi = pf->fdir.fdir_vsi;
630 [ # # ]: 0 : if (!vsi)
631 : : return;
632 : :
633 : 0 : ice_vsi_disable_queues_intr(vsi);
634 : :
635 : 0 : err = ice_fdir_tx_queue_stop(eth_dev, pf->fdir.txq->queue_id);
636 [ # # ]: 0 : if (err)
637 : 0 : PMD_DRV_LOG(ERR, "Failed to stop TX queue.");
638 : :
639 : 0 : err = ice_fdir_rx_queue_stop(eth_dev, pf->fdir.rxq->queue_id);
640 [ # # ]: 0 : if (err)
641 : 0 : PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
642 : :
643 : : err = ice_fdir_counter_release(pf);
644 : : if (err)
645 : : PMD_DRV_LOG(ERR, "Failed to release FDIR counter resource.");
646 : :
647 : : ice_fdir_release_filter_list(pf);
648 : :
649 : 0 : ice_tx_queue_release(pf->fdir.txq);
650 : 0 : pf->fdir.txq = NULL;
651 : 0 : ice_rx_queue_release(pf->fdir.rxq);
652 : 0 : pf->fdir.rxq = NULL;
653 : 0 : ice_fdir_prof_rm_all(pf);
654 : 0 : ice_fdir_prof_free(hw);
655 : 0 : ice_release_vsi(vsi);
656 : 0 : pf->fdir.fdir_vsi = NULL;
657 : :
658 [ # # ]: 0 : if (pf->fdir.mz) {
659 : 0 : err = rte_memzone_free(pf->fdir.mz);
660 : 0 : pf->fdir.mz = NULL;
661 [ # # ]: 0 : if (err)
662 : 0 : PMD_DRV_LOG(ERR, "Failed to free FDIR memezone.");
663 : : }
664 : : }
665 : :
666 : : static int
667 : 0 : ice_fdir_cur_prof_conflict(struct ice_pf *pf,
668 : : enum ice_fltr_ptype ptype,
669 : : struct ice_flow_seg_info *seg,
670 : : bool is_tunnel)
671 : : {
672 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
673 : : struct ice_flow_seg_info *ori_seg;
674 : : struct ice_fd_hw_prof *hw_prof;
675 : :
676 : 0 : hw_prof = hw->fdir_prof[ptype];
677 : 0 : ori_seg = hw_prof->fdir_seg[is_tunnel];
678 : :
679 : : /* profile does not exist */
680 [ # # ]: 0 : if (!ori_seg)
681 : : return 0;
682 : :
683 : : /* if no input set conflict, return -EEXIST */
684 [ # # # # : 0 : if ((!is_tunnel && !memcmp(ori_seg, seg, sizeof(*seg))) ||
# # ]
685 [ # # ]: 0 : (is_tunnel && !memcmp(&ori_seg[1], &seg[1], sizeof(*seg)))) {
686 : 0 : PMD_DRV_LOG(DEBUG, "Profile already exists for flow type %d.",
687 : : ptype);
688 : 0 : return -EEXIST;
689 : : }
690 : :
691 : : /* a rule with input set conflict already exist, so give up */
692 [ # # ]: 0 : if (pf->fdir_fltr_cnt[ptype][is_tunnel]) {
693 : 0 : PMD_DRV_LOG(DEBUG, "Failed to create profile for flow type %d due to conflict with existing rule.",
694 : : ptype);
695 : 0 : return -EINVAL;
696 : : }
697 : :
698 : : /* it's safe to delete an empty profile */
699 : 0 : ice_fdir_prof_rm(pf, ptype, is_tunnel);
700 : 0 : return 0;
701 : : }
702 : :
703 : : static bool
704 : 0 : ice_fdir_prof_resolve_conflict(struct ice_pf *pf,
705 : : enum ice_fltr_ptype ptype,
706 : : bool is_tunnel)
707 : : {
708 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
709 : : struct ice_fd_hw_prof *hw_prof;
710 : : struct ice_flow_seg_info *seg;
711 : :
712 : 0 : hw_prof = hw->fdir_prof[ptype];
713 : 0 : seg = hw_prof->fdir_seg[is_tunnel];
714 : :
715 : : /* profile does not exist */
716 [ # # ]: 0 : if (!seg)
717 : : return true;
718 : :
719 : : /* profile exists and rule exists, fail to resolve the conflict */
720 [ # # ]: 0 : if (pf->fdir_fltr_cnt[ptype][is_tunnel] != 0)
721 : : return false;
722 : :
723 : : /* it's safe to delete an empty profile */
724 : 0 : ice_fdir_prof_rm(pf, ptype, is_tunnel);
725 : :
726 : 0 : return true;
727 : : }
728 : :
729 : : static int
730 : 0 : ice_fdir_cross_prof_conflict(struct ice_pf *pf,
731 : : enum ice_fltr_ptype ptype,
732 : : bool is_tunnel)
733 : : {
734 : : enum ice_fltr_ptype cflct_ptype;
735 : :
736 [ # # # # : 0 : switch (ptype) {
# # # #
# ]
737 : : /* IPv4 */
738 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
739 : : case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
740 : : case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
741 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
742 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
743 : : (pf, cflct_ptype, is_tunnel))
744 : 0 : goto err;
745 : : break;
746 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
747 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
748 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
749 : : (pf, cflct_ptype, is_tunnel))
750 : 0 : goto err;
751 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
752 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
753 : : (pf, cflct_ptype, is_tunnel))
754 : 0 : goto err;
755 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
756 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
757 : : (pf, cflct_ptype, is_tunnel))
758 : 0 : goto err;
759 : : break;
760 : : /* IPv4 GTPU */
761 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP:
762 : : case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP:
763 : : case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP:
764 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER;
765 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
766 : : (pf, cflct_ptype, is_tunnel))
767 : 0 : goto err;
768 : : break;
769 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER:
770 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP;
771 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
772 : : (pf, cflct_ptype, is_tunnel))
773 : 0 : goto err;
774 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP;
775 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
776 : : (pf, cflct_ptype, is_tunnel))
777 : 0 : goto err;
778 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP;
779 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
780 : : (pf, cflct_ptype, is_tunnel))
781 : 0 : goto err;
782 : : break;
783 : : /* IPv6 */
784 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
785 : : case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
786 : : case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
787 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
788 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
789 : : (pf, cflct_ptype, is_tunnel))
790 : 0 : goto err;
791 : : break;
792 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
793 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
794 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
795 : : (pf, cflct_ptype, is_tunnel))
796 : 0 : goto err;
797 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
798 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
799 : : (pf, cflct_ptype, is_tunnel))
800 : 0 : goto err;
801 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
802 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
803 : : (pf, cflct_ptype, is_tunnel))
804 : 0 : goto err;
805 : : break;
806 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP:
807 : : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP:
808 : : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP:
809 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER;
810 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
811 : : (pf, cflct_ptype, is_tunnel))
812 : 0 : goto err;
813 : : break;
814 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER:
815 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP;
816 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
817 : : (pf, cflct_ptype, is_tunnel))
818 : 0 : goto err;
819 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP;
820 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
821 : : (pf, cflct_ptype, is_tunnel))
822 : 0 : goto err;
823 : : cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP;
824 [ # # ]: 0 : if (!ice_fdir_prof_resolve_conflict
825 : : (pf, cflct_ptype, is_tunnel))
826 : 0 : goto err;
827 : : break;
828 : : default:
829 : : break;
830 : : }
831 : : return 0;
832 : 0 : err:
833 : 0 : PMD_DRV_LOG(DEBUG, "Failed to create profile for flow type %d due to conflict with existing rule of flow type %d.",
834 : : ptype, cflct_ptype);
835 : 0 : return -EINVAL;
836 : : }
837 : :
838 : : static int
839 : 0 : ice_fdir_hw_tbl_conf(struct ice_pf *pf, struct ice_vsi *vsi,
840 : : struct ice_vsi *ctrl_vsi,
841 : : struct ice_flow_seg_info *seg,
842 : : enum ice_fltr_ptype ptype,
843 : : bool is_tunnel)
844 : : {
845 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
846 : : enum ice_flow_dir dir = ICE_FLOW_RX;
847 : : struct ice_fd_hw_prof *hw_prof;
848 : : struct ice_flow_prof *prof;
849 : 0 : uint64_t entry_1 = 0;
850 : 0 : uint64_t entry_2 = 0;
851 : : uint16_t vsi_num;
852 : : int ret;
853 : : uint64_t prof_id;
854 : :
855 : : /* check if have input set conflict on current profile. */
856 : 0 : ret = ice_fdir_cur_prof_conflict(pf, ptype, seg, is_tunnel);
857 [ # # ]: 0 : if (ret)
858 : : return ret;
859 : :
860 : : /* check if the profile is conflict with other profile. */
861 : 0 : ret = ice_fdir_cross_prof_conflict(pf, ptype, is_tunnel);
862 [ # # ]: 0 : if (ret)
863 : : return ret;
864 : :
865 : 0 : prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
866 [ # # ]: 0 : ret = ice_flow_add_prof(hw, ICE_BLK_FD, dir, prof_id, seg,
867 : : (is_tunnel) ? 2 : 1, NULL, 0, &prof);
868 [ # # ]: 0 : if (ret)
869 : : return ret;
870 : 0 : ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
871 : 0 : vsi->idx, ICE_FLOW_PRIO_NORMAL,
872 : : seg, NULL, 0, &entry_1);
873 [ # # ]: 0 : if (ret) {
874 : 0 : PMD_DRV_LOG(ERR, "Failed to add main VSI flow entry for %d.",
875 : : ptype);
876 : 0 : goto err_add_prof;
877 : : }
878 : 0 : ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
879 : 0 : ctrl_vsi->idx, ICE_FLOW_PRIO_NORMAL,
880 : : seg, NULL, 0, &entry_2);
881 [ # # ]: 0 : if (ret) {
882 : 0 : PMD_DRV_LOG(ERR, "Failed to add control VSI flow entry for %d.",
883 : : ptype);
884 : 0 : goto err_add_entry;
885 : : }
886 : :
887 : 0 : hw_prof = hw->fdir_prof[ptype];
888 : : pf->hw_prof_cnt[ptype][is_tunnel] = 0;
889 : : hw_prof->cnt = 0;
890 : 0 : hw_prof->fdir_seg[is_tunnel] = seg;
891 : 0 : hw_prof->vsi_h[hw_prof->cnt] = vsi->idx;
892 : 0 : hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_1;
893 : : pf->hw_prof_cnt[ptype][is_tunnel]++;
894 : 0 : hw_prof->vsi_h[hw_prof->cnt] = ctrl_vsi->idx;
895 : 0 : hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_2;
896 : 0 : pf->hw_prof_cnt[ptype][is_tunnel]++;
897 : :
898 : 0 : return ret;
899 : :
900 : : err_add_entry:
901 : 0 : vsi_num = ice_get_hw_vsi_num(hw, vsi->idx);
902 : 0 : ice_rem_prof_id_flow(hw, ICE_BLK_FD, vsi_num, prof_id);
903 : 0 : ice_flow_rem_entry(hw, ICE_BLK_FD, entry_1);
904 : 0 : err_add_prof:
905 : 0 : ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
906 : :
907 : 0 : return ret;
908 : : }
909 : :
910 : : static void
911 : : ice_fdir_input_set_parse(uint64_t inset, enum ice_flow_field *field)
912 : : {
913 : : uint32_t i, j;
914 : :
915 : : struct ice_inset_map {
916 : : uint64_t inset;
917 : : enum ice_flow_field fld;
918 : : };
919 : : static const struct ice_inset_map ice_inset_map[] = {
920 : : {ICE_INSET_DMAC, ICE_FLOW_FIELD_IDX_ETH_DA},
921 : : {ICE_INSET_ETHERTYPE, ICE_FLOW_FIELD_IDX_ETH_TYPE},
922 : : {ICE_INSET_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
923 : : {ICE_INSET_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
924 : : {ICE_INSET_IPV4_TOS, ICE_FLOW_FIELD_IDX_IPV4_DSCP},
925 : : {ICE_INSET_IPV4_TTL, ICE_FLOW_FIELD_IDX_IPV4_TTL},
926 : : {ICE_INSET_IPV4_PROTO, ICE_FLOW_FIELD_IDX_IPV4_PROT},
927 : : {ICE_INSET_IPV4_PKID, ICE_FLOW_FIELD_IDX_IPV4_ID},
928 : : {ICE_INSET_IPV6_SRC, ICE_FLOW_FIELD_IDX_IPV6_SA},
929 : : {ICE_INSET_IPV6_DST, ICE_FLOW_FIELD_IDX_IPV6_DA},
930 : : {ICE_INSET_IPV6_TC, ICE_FLOW_FIELD_IDX_IPV6_DSCP},
931 : : {ICE_INSET_IPV6_NEXT_HDR, ICE_FLOW_FIELD_IDX_IPV6_PROT},
932 : : {ICE_INSET_IPV6_HOP_LIMIT, ICE_FLOW_FIELD_IDX_IPV6_TTL},
933 : : {ICE_INSET_IPV6_PKID, ICE_FLOW_FIELD_IDX_IPV6_ID},
934 : : {ICE_INSET_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
935 : : {ICE_INSET_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
936 : : {ICE_INSET_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
937 : : {ICE_INSET_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
938 : : {ICE_INSET_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
939 : : {ICE_INSET_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
940 : : {ICE_INSET_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
941 : : {ICE_INSET_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
942 : : {ICE_INSET_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
943 : : {ICE_INSET_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
944 : : {ICE_INSET_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
945 : : {ICE_INSET_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
946 : : {ICE_INSET_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
947 : : {ICE_INSET_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
948 : : {ICE_INSET_GTPU_TEID, ICE_FLOW_FIELD_IDX_GTPU_IP_TEID},
949 : : {ICE_INSET_GTPU_QFI, ICE_FLOW_FIELD_IDX_GTPU_EH_QFI},
950 : : {ICE_INSET_VXLAN_VNI, ICE_FLOW_FIELD_IDX_VXLAN_VNI},
951 : : {ICE_INSET_ESP_SPI, ICE_FLOW_FIELD_IDX_ESP_SPI},
952 : : {ICE_INSET_NAT_T_ESP_SPI, ICE_FLOW_FIELD_IDX_NAT_T_ESP_SPI},
953 : : };
954 : :
955 [ # # ]: 0 : for (i = 0, j = 0; i < RTE_DIM(ice_inset_map); i++) {
956 [ # # ]: 0 : if ((inset & ice_inset_map[i].inset) ==
957 : : ice_inset_map[i].inset)
958 : 0 : field[j++] = ice_inset_map[i].fld;
959 : : }
960 : : }
961 : :
962 : : static void
963 : 0 : ice_fdir_input_set_hdrs(enum ice_fltr_ptype flow, struct ice_flow_seg_info *seg)
964 : : {
965 [ # # # # : 0 : switch (flow) {
# # # # #
# # # # #
# # # # #
# # # ]
966 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
967 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
968 : : ICE_FLOW_SEG_HDR_IPV4 |
969 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
970 : 0 : break;
971 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
972 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
973 : : ICE_FLOW_SEG_HDR_IPV4 |
974 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
975 : 0 : break;
976 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
977 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
978 : : ICE_FLOW_SEG_HDR_IPV4 |
979 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
980 : 0 : break;
981 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
982 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4 |
983 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
984 : 0 : break;
985 : 0 : case ICE_FLTR_PTYPE_FRAG_IPV4:
986 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4 |
987 : : ICE_FLOW_SEG_HDR_IPV_FRAG);
988 : 0 : break;
989 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
990 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
991 : : ICE_FLOW_SEG_HDR_IPV6 |
992 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
993 : 0 : break;
994 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
995 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
996 : : ICE_FLOW_SEG_HDR_IPV6 |
997 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
998 : 0 : break;
999 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
1000 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
1001 : : ICE_FLOW_SEG_HDR_IPV6 |
1002 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1003 : 0 : break;
1004 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
1005 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6 |
1006 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1007 : 0 : break;
1008 : 0 : case ICE_FLTR_PTYPE_FRAG_IPV6:
1009 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6 |
1010 : : ICE_FLOW_SEG_HDR_IPV_FRAG);
1011 : 0 : break;
1012 : : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP:
1013 : : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP:
1014 : : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP:
1015 : : break;
1016 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER:
1017 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV_OTHER);
1018 : 0 : break;
1019 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_GTPU:
1020 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_IP |
1021 : : ICE_FLOW_SEG_HDR_IPV4 |
1022 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1023 : 0 : break;
1024 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH:
1025 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_EH |
1026 : : ICE_FLOW_SEG_HDR_GTPU_IP |
1027 : : ICE_FLOW_SEG_HDR_IPV4 |
1028 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1029 : 0 : break;
1030 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_GTPU:
1031 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_IP |
1032 : : ICE_FLOW_SEG_HDR_IPV6 |
1033 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1034 : 0 : break;
1035 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH:
1036 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_EH |
1037 : : ICE_FLOW_SEG_HDR_GTPU_IP |
1038 : : ICE_FLOW_SEG_HDR_IPV6 |
1039 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1040 : 0 : break;
1041 : 0 : case ICE_FLTR_PTYPE_NON_IP_L2:
1042 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH_NON_IP);
1043 : 0 : break;
1044 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_ESP:
1045 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ESP |
1046 : : ICE_FLOW_SEG_HDR_IPV4 |
1047 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1048 : 0 : break;
1049 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_ESP:
1050 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ESP |
1051 : : ICE_FLOW_SEG_HDR_IPV6 |
1052 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1053 : 0 : break;
1054 : 0 : case ICE_FLTR_PTYPE_NONF_IPV4_NAT_T_ESP:
1055 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_NAT_T_ESP |
1056 : : ICE_FLOW_SEG_HDR_IPV4 |
1057 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1058 : 0 : break;
1059 : 0 : case ICE_FLTR_PTYPE_NONF_IPV6_NAT_T_ESP:
1060 : 0 : ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_NAT_T_ESP |
1061 : : ICE_FLOW_SEG_HDR_IPV6 |
1062 : : ICE_FLOW_SEG_HDR_IPV_OTHER);
1063 : 0 : break;
1064 : 0 : default:
1065 : 0 : PMD_DRV_LOG(ERR, "not supported filter type.");
1066 : 0 : break;
1067 : : }
1068 : 0 : }
1069 : :
1070 : : static int
1071 : 0 : ice_fdir_input_set_conf(struct ice_pf *pf, enum ice_fltr_ptype flow,
1072 : : uint64_t inner_input_set, uint64_t outer_input_set,
1073 : : enum ice_fdir_tunnel_type ttype)
1074 : : {
1075 : : struct ice_flow_seg_info *seg;
1076 : : struct ice_flow_seg_info *seg_tun = NULL;
1077 : : enum ice_flow_field field[ICE_FLOW_FIELD_IDX_MAX];
1078 : : uint64_t input_set;
1079 : : bool is_tunnel;
1080 : : int k, i, ret = 0;
1081 : :
1082 [ # # ]: 0 : if (!(inner_input_set | outer_input_set))
1083 : : return -EINVAL;
1084 : :
1085 : : seg_tun = (struct ice_flow_seg_info *)
1086 : 0 : ice_malloc(hw, sizeof(*seg_tun) * ICE_FD_HW_SEG_MAX);
1087 [ # # ]: 0 : if (!seg_tun) {
1088 : 0 : PMD_DRV_LOG(ERR, "No memory can be allocated");
1089 : 0 : return -ENOMEM;
1090 : : }
1091 : :
1092 : : /* use seg_tun[1] to record tunnel inner part */
1093 [ # # ]: 0 : for (k = 0; k <= ICE_FD_HW_SEG_TUN; k++) {
1094 : 0 : seg = &seg_tun[k];
1095 [ # # ]: 0 : input_set = (k == ICE_FD_HW_SEG_TUN) ? inner_input_set : outer_input_set;
1096 [ # # ]: 0 : if (input_set == 0)
1097 : 0 : continue;
1098 : :
1099 [ # # ]: 0 : for (i = 0; i < ICE_FLOW_FIELD_IDX_MAX; i++)
1100 : 0 : field[i] = ICE_FLOW_FIELD_IDX_MAX;
1101 : :
1102 : : ice_fdir_input_set_parse(input_set, field);
1103 : :
1104 : 0 : ice_fdir_input_set_hdrs(flow, seg);
1105 : :
1106 [ # # ]: 0 : for (i = 0; field[i] != ICE_FLOW_FIELD_IDX_MAX; i++) {
1107 : 0 : ice_flow_set_fld(seg, field[i],
1108 : : ICE_FLOW_FLD_OFF_INVAL,
1109 : : ICE_FLOW_FLD_OFF_INVAL,
1110 : : ICE_FLOW_FLD_OFF_INVAL, false);
1111 : : }
1112 : : }
1113 : :
1114 : : is_tunnel = ice_fdir_is_tunnel_profile(ttype);
1115 : :
1116 : 0 : ret = ice_fdir_hw_tbl_conf(pf, pf->main_vsi, pf->fdir.fdir_vsi,
1117 : : seg_tun, flow, is_tunnel);
1118 : :
1119 [ # # ]: 0 : if (!ret) {
1120 : : return ret;
1121 [ # # ]: 0 : } else if (ret < 0) {
1122 : 0 : rte_free(seg_tun);
1123 [ # # ]: 0 : return (ret == -EEXIST) ? 0 : ret;
1124 : : } else {
1125 : : return ret;
1126 : : }
1127 : : }
1128 : :
1129 : : static void
1130 : 0 : ice_fdir_cnt_update(struct ice_pf *pf, enum ice_fltr_ptype ptype,
1131 : : bool is_tunnel, bool add)
1132 : : {
1133 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1134 : : int cnt;
1135 : :
1136 [ # # ]: 0 : cnt = (add) ? 1 : -1;
1137 : 0 : hw->fdir_active_fltr += cnt;
1138 [ # # ]: 0 : if (ptype == ICE_FLTR_PTYPE_NONF_NONE || ptype >= ICE_FLTR_PTYPE_MAX)
1139 : 0 : PMD_DRV_LOG(ERR, "Unknown filter type %d", ptype);
1140 : : else
1141 : 0 : pf->fdir_fltr_cnt[ptype][is_tunnel] += cnt;
1142 : 0 : }
1143 : :
1144 : : static int
1145 : 0 : ice_fdir_init(struct ice_adapter *ad)
1146 : : {
1147 : 0 : struct ice_pf *pf = &ad->pf;
1148 : :
1149 : 0 : return ice_fdir_setup(pf);
1150 : : }
1151 : :
1152 : : static void
1153 : 0 : ice_fdir_uninit(struct ice_adapter *ad)
1154 : : {
1155 : 0 : struct ice_pf *pf = &ad->pf;
1156 : :
1157 [ # # ]: 0 : if (ad->hw.dcf_enabled)
1158 : : return;
1159 : :
1160 : 0 : ice_fdir_teardown(pf);
1161 : : }
1162 : :
1163 : : static int
1164 : : ice_fdir_is_tunnel_profile(enum ice_fdir_tunnel_type tunnel_type)
1165 : : {
1166 [ # # ]: 0 : if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN)
1167 : : return 1;
1168 : : else
1169 : 0 : return 0;
1170 : : }
1171 : :
1172 : : static int
1173 : 0 : ice_fdir_add_del_raw(struct ice_pf *pf,
1174 : : struct ice_fdir_filter_conf *filter,
1175 : : bool add)
1176 : : {
1177 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1178 : :
1179 : 0 : unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1180 [ # # ]: 0 : rte_memcpy(pkt, filter->pkt_buf, filter->pkt_len);
1181 : :
1182 : : struct ice_fltr_desc desc;
1183 : : memset(&desc, 0, sizeof(desc));
1184 : 0 : filter->input.comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW;
1185 : 0 : ice_fdir_get_prgm_desc(hw, &filter->input, &desc, add);
1186 : :
1187 : 0 : return ice_fdir_programming(pf, &desc);
1188 : : }
1189 : :
1190 : : static int
1191 : 0 : ice_fdir_add_del_filter(struct ice_pf *pf,
1192 : : struct ice_fdir_filter_conf *filter,
1193 : : bool add)
1194 : : {
1195 : : struct ice_fltr_desc desc;
1196 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1197 : 0 : unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1198 : : bool is_tun;
1199 : : int ret;
1200 : :
1201 : 0 : filter->input.dest_vsi = pf->main_vsi->idx;
1202 : :
1203 : : memset(&desc, 0, sizeof(desc));
1204 : 0 : filter->input.comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW;
1205 : 0 : ice_fdir_get_prgm_desc(hw, &filter->input, &desc, add);
1206 : :
1207 [ # # ]: 0 : is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1208 : :
1209 : : memset(pkt, 0, ICE_FDIR_PKT_LEN);
1210 : 0 : ret = ice_fdir_get_gen_prgm_pkt(hw, &filter->input, pkt, false, is_tun);
1211 [ # # ]: 0 : if (ret) {
1212 : 0 : PMD_DRV_LOG(ERR, "Generate dummy packet failed");
1213 : 0 : return -EINVAL;
1214 : : }
1215 : :
1216 : 0 : return ice_fdir_programming(pf, &desc);
1217 : : }
1218 : :
1219 : : static void
1220 [ # # ]: 0 : ice_fdir_extract_fltr_key(struct ice_fdir_fltr_pattern *key,
1221 : : struct ice_fdir_filter_conf *filter)
1222 : : {
1223 : : struct ice_fdir_fltr *input = &filter->input;
1224 : : memset(key, 0, sizeof(*key));
1225 : :
1226 : 0 : key->flow_type = input->flow_type;
1227 [ # # ]: 0 : rte_memcpy(&key->ip, &input->ip, sizeof(key->ip));
1228 [ # # ]: 0 : rte_memcpy(&key->mask, &input->mask, sizeof(key->mask));
1229 [ # # ]: 0 : rte_memcpy(&key->ext_data, &input->ext_data, sizeof(key->ext_data));
1230 [ # # ]: 0 : rte_memcpy(&key->ext_mask, &input->ext_mask, sizeof(key->ext_mask));
1231 : :
1232 [ # # ]: 0 : rte_memcpy(&key->gtpu_data, &input->gtpu_data, sizeof(key->gtpu_data));
1233 [ # # ]: 0 : rte_memcpy(&key->gtpu_mask, &input->gtpu_mask, sizeof(key->gtpu_mask));
1234 : :
1235 : 0 : key->tunnel_type = filter->tunnel_type;
1236 : 0 : }
1237 : :
1238 : : /* Check if there exists the flow director filter */
1239 : : static struct ice_fdir_filter_conf *
1240 : : ice_fdir_entry_lookup(struct ice_fdir_info *fdir_info,
1241 : : const struct ice_fdir_fltr_pattern *key)
1242 : : {
1243 : : int ret;
1244 : :
1245 : 0 : ret = rte_hash_lookup(fdir_info->hash_table, key);
1246 [ # # # # ]: 0 : if (ret < 0)
1247 : : return NULL;
1248 : :
1249 : 0 : return fdir_info->hash_map[ret];
1250 : : }
1251 : :
1252 : : /* Add a flow director entry into the SW list */
1253 : : static int
1254 : 0 : ice_fdir_entry_insert(struct ice_pf *pf,
1255 : : struct ice_fdir_filter_conf *entry,
1256 : : struct ice_fdir_fltr_pattern *key)
1257 : : {
1258 : : struct ice_fdir_info *fdir_info = &pf->fdir;
1259 : : int ret;
1260 : :
1261 : 0 : ret = rte_hash_add_key(fdir_info->hash_table, key);
1262 [ # # ]: 0 : if (ret < 0) {
1263 : 0 : PMD_DRV_LOG(ERR,
1264 : : "Failed to insert fdir entry to hash table %d!",
1265 : : ret);
1266 : 0 : return ret;
1267 : : }
1268 : 0 : fdir_info->hash_map[ret] = entry;
1269 : :
1270 : 0 : return 0;
1271 : : }
1272 : :
1273 : : /* Delete a flow director entry from the SW list */
1274 : : static int
1275 : 0 : ice_fdir_entry_del(struct ice_pf *pf, struct ice_fdir_fltr_pattern *key)
1276 : : {
1277 : : struct ice_fdir_info *fdir_info = &pf->fdir;
1278 : : int ret;
1279 : :
1280 : 0 : ret = rte_hash_del_key(fdir_info->hash_table, key);
1281 [ # # ]: 0 : if (ret < 0) {
1282 : 0 : PMD_DRV_LOG(ERR,
1283 : : "Failed to delete fdir filter to hash table %d!",
1284 : : ret);
1285 : 0 : return ret;
1286 : : }
1287 : 0 : fdir_info->hash_map[ret] = NULL;
1288 : :
1289 : 0 : return 0;
1290 : : }
1291 : :
1292 : : static int
1293 : 0 : ice_fdir_create_filter(struct ice_adapter *ad,
1294 : : struct rte_flow *flow,
1295 : : void *meta,
1296 : : struct rte_flow_error *error)
1297 : : {
1298 : 0 : struct ice_pf *pf = &ad->pf;
1299 : : struct ice_fdir_filter_conf *filter = meta;
1300 : : struct ice_fdir_info *fdir_info = &pf->fdir;
1301 : : struct ice_fdir_filter_conf *entry, *node;
1302 : : struct ice_fdir_fltr_pattern key;
1303 : : bool is_tun;
1304 : : int ret;
1305 : : int i;
1306 : :
1307 [ # # ]: 0 : if (filter->parser_ena) {
1308 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1309 : :
1310 : 0 : int id = ice_find_first_bit(filter->prof->ptypes, UINT16_MAX);
1311 : 0 : int ptg = hw->blk[ICE_BLK_FD].xlt1.t[id];
1312 : 0 : u16 ctrl_vsi = pf->fdir.fdir_vsi->idx;
1313 : 0 : u16 main_vsi = pf->main_vsi->idx;
1314 : : bool fv_found = false;
1315 : :
1316 : : struct ice_fdir_prof_info *pi = &ad->fdir_prof_info[ptg];
1317 [ # # ]: 0 : if (pi->fdir_actived_cnt != 0) {
1318 [ # # ]: 0 : for (i = 0; i < ICE_MAX_FV_WORDS; i++)
1319 : 0 : if (pi->prof.fv[i].proto_id !=
1320 [ # # ]: 0 : filter->prof->fv[i].proto_id ||
1321 : 0 : pi->prof.fv[i].offset !=
1322 [ # # ]: 0 : filter->prof->fv[i].offset ||
1323 : 0 : pi->prof.fv[i].msk !=
1324 [ # # ]: 0 : filter->prof->fv[i].msk)
1325 : : break;
1326 [ # # ]: 0 : if (i == ICE_MAX_FV_WORDS) {
1327 : : fv_found = true;
1328 : 0 : pi->fdir_actived_cnt++;
1329 : : }
1330 : : }
1331 : :
1332 : : if (!fv_found) {
1333 : 0 : ret = ice_flow_set_hw_prof(hw, main_vsi, ctrl_vsi,
1334 : : filter->prof, ICE_BLK_FD);
1335 [ # # ]: 0 : if (ret)
1336 : 0 : goto error;
1337 : : }
1338 : :
1339 : 0 : ret = ice_fdir_add_del_raw(pf, filter, true);
1340 [ # # ]: 0 : if (ret)
1341 : 0 : goto error;
1342 : :
1343 [ # # ]: 0 : if (!fv_found) {
1344 [ # # ]: 0 : for (i = 0; i < filter->prof->fv_num; i++) {
1345 : 0 : pi->prof.fv[i].proto_id =
1346 : 0 : filter->prof->fv[i].proto_id;
1347 : 0 : pi->prof.fv[i].offset =
1348 : 0 : filter->prof->fv[i].offset;
1349 : 0 : pi->prof.fv[i].msk = filter->prof->fv[i].msk;
1350 : : }
1351 : 0 : pi->fdir_actived_cnt = 1;
1352 : : }
1353 : :
1354 [ # # ]: 0 : if (filter->mark_flag == 1)
1355 : 0 : ice_fdir_rx_parsing_enable(ad, 1);
1356 : :
1357 : 0 : entry = rte_zmalloc("fdir_entry", sizeof(*entry), 0);
1358 [ # # ]: 0 : if (!entry)
1359 : 0 : goto error;
1360 : :
1361 : : rte_memcpy(entry, filter, sizeof(*filter));
1362 : :
1363 : 0 : flow->rule = entry;
1364 : :
1365 : 0 : return 0;
1366 : : }
1367 : :
1368 : 0 : ice_fdir_extract_fltr_key(&key, filter);
1369 : : node = ice_fdir_entry_lookup(fdir_info, &key);
1370 [ # # ]: 0 : if (node) {
1371 : 0 : rte_flow_error_set(error, EEXIST,
1372 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1373 : : "Rule already exists!");
1374 : 0 : return -rte_errno;
1375 : : }
1376 : :
1377 : 0 : entry = rte_zmalloc("fdir_entry", sizeof(*entry), 0);
1378 [ # # ]: 0 : if (!entry) {
1379 : 0 : rte_flow_error_set(error, ENOMEM,
1380 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1381 : : "Failed to allocate memory");
1382 : 0 : return -rte_errno;
1383 : : }
1384 : :
1385 [ # # ]: 0 : is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1386 : :
1387 : 0 : ret = ice_fdir_input_set_conf(pf, filter->input.flow_type,
1388 : : filter->input_set_i, filter->input_set_o,
1389 : : filter->tunnel_type);
1390 [ # # ]: 0 : if (ret) {
1391 : 0 : rte_flow_error_set(error, -ret,
1392 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1393 : : "Profile configure failed.");
1394 : 0 : goto free_entry;
1395 : : }
1396 : :
1397 : : /* alloc counter for FDIR */
1398 [ # # ]: 0 : if (filter->input.cnt_ena) {
1399 : : struct rte_flow_action_count *act_count = &filter->act_count;
1400 : :
1401 : 0 : filter->counter = ice_fdir_counter_alloc(pf, 0, act_count->id);
1402 [ # # ]: 0 : if (!filter->counter) {
1403 : 0 : rte_flow_error_set(error, EINVAL,
1404 : : RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1405 : : "Failed to alloc FDIR counter.");
1406 : 0 : goto free_entry;
1407 : : }
1408 : 0 : filter->input.cnt_index = filter->counter->hw_index;
1409 : : }
1410 : :
1411 : 0 : ret = ice_fdir_add_del_filter(pf, filter, true);
1412 [ # # ]: 0 : if (ret) {
1413 : 0 : rte_flow_error_set(error, -ret,
1414 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1415 : : "Add filter rule failed.");
1416 : 0 : goto free_counter;
1417 : : }
1418 : :
1419 [ # # ]: 0 : if (filter->mark_flag == 1)
1420 : 0 : ice_fdir_rx_parsing_enable(ad, 1);
1421 : :
1422 : : rte_memcpy(entry, filter, sizeof(*entry));
1423 : 0 : ret = ice_fdir_entry_insert(pf, entry, &key);
1424 [ # # ]: 0 : if (ret) {
1425 : 0 : rte_flow_error_set(error, -ret,
1426 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1427 : : "Insert entry to table failed.");
1428 : 0 : goto free_entry;
1429 : : }
1430 : :
1431 : 0 : flow->rule = entry;
1432 : 0 : ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, true);
1433 : :
1434 : 0 : return 0;
1435 : :
1436 : : free_counter:
1437 [ # # ]: 0 : if (filter->counter) {
1438 : : ice_fdir_counter_free(pf, filter->counter);
1439 : 0 : filter->counter = NULL;
1440 : : }
1441 : :
1442 : 0 : free_entry:
1443 : 0 : rte_free(entry);
1444 : 0 : return -rte_errno;
1445 : :
1446 : 0 : error:
1447 : 0 : rte_free(filter->prof);
1448 : 0 : rte_free(filter->pkt_buf);
1449 : 0 : return -rte_errno;
1450 : : }
1451 : :
1452 : : static int
1453 : 0 : ice_fdir_destroy_filter(struct ice_adapter *ad,
1454 : : struct rte_flow *flow,
1455 : : struct rte_flow_error *error)
1456 : : {
1457 : 0 : struct ice_pf *pf = &ad->pf;
1458 : : struct ice_fdir_info *fdir_info = &pf->fdir;
1459 : : struct ice_fdir_filter_conf *filter, *entry;
1460 : : struct ice_fdir_fltr_pattern key;
1461 : : bool is_tun;
1462 : : int ret;
1463 : :
1464 : 0 : filter = (struct ice_fdir_filter_conf *)flow->rule;
1465 : :
1466 [ # # ]: 0 : if (filter->parser_ena) {
1467 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1468 : :
1469 : 0 : int id = ice_find_first_bit(filter->prof->ptypes, UINT16_MAX);
1470 : 0 : int ptg = hw->blk[ICE_BLK_FD].xlt1.t[id];
1471 : 0 : u16 ctrl_vsi = pf->fdir.fdir_vsi->idx;
1472 : 0 : u16 main_vsi = pf->main_vsi->idx;
1473 : : enum ice_block blk = ICE_BLK_FD;
1474 : : u16 vsi_num;
1475 : :
1476 : 0 : ret = ice_fdir_add_del_raw(pf, filter, false);
1477 [ # # ]: 0 : if (ret)
1478 : 0 : return -rte_errno;
1479 : :
1480 : : struct ice_fdir_prof_info *pi = &ad->fdir_prof_info[ptg];
1481 [ # # ]: 0 : if (pi->fdir_actived_cnt != 0) {
1482 : 0 : pi->fdir_actived_cnt--;
1483 [ # # ]: 0 : if (!pi->fdir_actived_cnt) {
1484 : 0 : vsi_num = ice_get_hw_vsi_num(hw, ctrl_vsi);
1485 : 0 : ice_rem_prof_id_flow(hw, blk, vsi_num, id);
1486 : :
1487 : 0 : vsi_num = ice_get_hw_vsi_num(hw, main_vsi);
1488 : 0 : ice_rem_prof_id_flow(hw, blk, vsi_num, id);
1489 : : }
1490 : : }
1491 : :
1492 [ # # ]: 0 : if (filter->mark_flag == 1)
1493 : 0 : ice_fdir_rx_parsing_enable(ad, 0);
1494 : :
1495 : 0 : flow->rule = NULL;
1496 : :
1497 : 0 : rte_free(filter->prof);
1498 : 0 : rte_free(filter->pkt_buf);
1499 : 0 : rte_free(filter);
1500 : :
1501 : 0 : return 0;
1502 : : }
1503 : :
1504 [ # # ]: 0 : is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1505 : :
1506 [ # # ]: 0 : if (filter->counter) {
1507 : : ice_fdir_counter_free(pf, filter->counter);
1508 : 0 : filter->counter = NULL;
1509 : : }
1510 : :
1511 : 0 : ice_fdir_extract_fltr_key(&key, filter);
1512 : : entry = ice_fdir_entry_lookup(fdir_info, &key);
1513 [ # # ]: 0 : if (!entry) {
1514 : 0 : rte_flow_error_set(error, ENOENT,
1515 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1516 : : "Can't find entry.");
1517 : 0 : return -rte_errno;
1518 : : }
1519 : :
1520 : 0 : ret = ice_fdir_add_del_filter(pf, filter, false);
1521 [ # # ]: 0 : if (ret) {
1522 : 0 : rte_flow_error_set(error, -ret,
1523 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1524 : : "Del filter rule failed.");
1525 : 0 : return -rte_errno;
1526 : : }
1527 : :
1528 : 0 : ret = ice_fdir_entry_del(pf, &key);
1529 [ # # ]: 0 : if (ret) {
1530 : 0 : rte_flow_error_set(error, -ret,
1531 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1532 : : "Remove entry from table failed.");
1533 : 0 : return -rte_errno;
1534 : : }
1535 : :
1536 : 0 : ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, false);
1537 : :
1538 [ # # ]: 0 : if (filter->mark_flag == 1)
1539 : 0 : ice_fdir_rx_parsing_enable(ad, 0);
1540 : :
1541 : 0 : flow->rule = NULL;
1542 : :
1543 : 0 : rte_free(filter);
1544 : :
1545 : 0 : return 0;
1546 : : }
1547 : :
1548 : : static int
1549 : 0 : ice_fdir_query_count(struct ice_adapter *ad,
1550 : : struct rte_flow *flow,
1551 : : struct rte_flow_query_count *flow_stats,
1552 : : struct rte_flow_error *error)
1553 : : {
1554 : : struct ice_pf *pf = &ad->pf;
1555 : 0 : struct ice_hw *hw = ICE_PF_TO_HW(pf);
1556 : 0 : struct ice_fdir_filter_conf *filter = flow->rule;
1557 : 0 : struct ice_fdir_counter *counter = filter->counter;
1558 : : uint64_t hits_lo, hits_hi;
1559 : :
1560 [ # # ]: 0 : if (!counter) {
1561 : 0 : rte_flow_error_set(error, EINVAL,
1562 : : RTE_FLOW_ERROR_TYPE_ACTION,
1563 : : NULL,
1564 : : "FDIR counters not available");
1565 : 0 : return -rte_errno;
1566 : : }
1567 : :
1568 : : /*
1569 : : * Reading the low 32-bits latches the high 32-bits into a shadow
1570 : : * register. Reading the high 32-bit returns the value in the
1571 : : * shadow register.
1572 : : */
1573 : 0 : hits_lo = ICE_READ_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index));
1574 : 0 : hits_hi = ICE_READ_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index));
1575 : :
1576 : 0 : flow_stats->hits_set = 1;
1577 : 0 : flow_stats->hits = hits_lo | (hits_hi << 32);
1578 : 0 : flow_stats->bytes_set = 0;
1579 : 0 : flow_stats->bytes = 0;
1580 : :
1581 [ # # ]: 0 : if (flow_stats->reset) {
1582 : : /* reset statistic counter value */
1583 : 0 : ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index), 0);
1584 : 0 : ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index), 0);
1585 : : }
1586 : :
1587 : : return 0;
1588 : : }
1589 : :
1590 : : static struct ice_flow_engine ice_fdir_engine = {
1591 : : .init = ice_fdir_init,
1592 : : .uninit = ice_fdir_uninit,
1593 : : .create = ice_fdir_create_filter,
1594 : : .destroy = ice_fdir_destroy_filter,
1595 : : .query_count = ice_fdir_query_count,
1596 : : .type = ICE_FLOW_ENGINE_FDIR,
1597 : : };
1598 : :
1599 : : static int
1600 : 0 : ice_fdir_parse_action_qregion(struct ice_pf *pf,
1601 : : struct rte_flow_error *error,
1602 : : const struct rte_flow_action *act,
1603 : : struct ice_fdir_filter_conf *filter)
1604 : : {
1605 : 0 : const struct rte_flow_action_rss *rss = act->conf;
1606 : : uint32_t i;
1607 : :
1608 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
1609 : 0 : rte_flow_error_set(error, EINVAL,
1610 : : RTE_FLOW_ERROR_TYPE_ACTION, act,
1611 : : "Invalid action.");
1612 : 0 : return -rte_errno;
1613 : : }
1614 : :
1615 [ # # ]: 0 : if (rss->queue_num <= 1) {
1616 : 0 : rte_flow_error_set(error, EINVAL,
1617 : : RTE_FLOW_ERROR_TYPE_ACTION, act,
1618 : : "Queue region size can't be 0 or 1.");
1619 : 0 : return -rte_errno;
1620 : : }
1621 : :
1622 : : /* check if queue index for queue region is continuous */
1623 [ # # ]: 0 : for (i = 0; i < rss->queue_num - 1; i++) {
1624 [ # # ]: 0 : if (rss->queue[i + 1] != rss->queue[i] + 1) {
1625 : 0 : rte_flow_error_set(error, EINVAL,
1626 : : RTE_FLOW_ERROR_TYPE_ACTION, act,
1627 : : "Discontinuous queue region");
1628 : 0 : return -rte_errno;
1629 : : }
1630 : : }
1631 : :
1632 [ # # ]: 0 : if (rss->queue[rss->queue_num - 1] >= pf->dev_data->nb_rx_queues) {
1633 : 0 : rte_flow_error_set(error, EINVAL,
1634 : : RTE_FLOW_ERROR_TYPE_ACTION, act,
1635 : : "Invalid queue region indexes.");
1636 : 0 : return -rte_errno;
1637 : : }
1638 : :
1639 [ # # ]: 0 : if (!(rte_is_power_of_2(rss->queue_num) &&
1640 : : (rss->queue_num <= ICE_FDIR_MAX_QREGION_SIZE))) {
1641 : 0 : rte_flow_error_set(error, EINVAL,
1642 : : RTE_FLOW_ERROR_TYPE_ACTION, act,
1643 : : "The region size should be any of the following values:"
1644 : : "1, 2, 4, 8, 16, 32, 64, 128 as long as the total number "
1645 : : "of queues do not exceed the VSI allocation.");
1646 : 0 : return -rte_errno;
1647 : : }
1648 : :
1649 : 0 : filter->input.q_index = rss->queue[0];
1650 : 0 : filter->input.q_region = rte_fls_u32(rss->queue_num) - 1;
1651 : 0 : filter->input.dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP;
1652 : :
1653 : 0 : return 0;
1654 : : }
1655 : :
1656 : : static int
1657 : 0 : ice_fdir_parse_action(struct ice_adapter *ad,
1658 : : const struct rte_flow_action actions[],
1659 : : struct rte_flow_error *error,
1660 : : struct ice_fdir_filter_conf *filter)
1661 : : {
1662 : 0 : struct ice_pf *pf = &ad->pf;
1663 : : const struct rte_flow_action_queue *act_q;
1664 : : const struct rte_flow_action_mark *mark_spec = NULL;
1665 : : const struct rte_flow_action_count *act_count;
1666 : : uint32_t dest_num = 0;
1667 : : uint32_t mark_num = 0;
1668 : : uint32_t counter_num = 0;
1669 : : int ret;
1670 : :
1671 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1672 [ # # # # : 0 : switch (actions->type) {
# # # # ]
1673 : : case RTE_FLOW_ACTION_TYPE_VOID:
1674 : : break;
1675 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
1676 : 0 : dest_num++;
1677 : :
1678 : 0 : act_q = actions->conf;
1679 : 0 : filter->input.q_index = act_q->index;
1680 : 0 : if (filter->input.q_index >=
1681 [ # # ]: 0 : pf->dev_data->nb_rx_queues) {
1682 : 0 : rte_flow_error_set(error, EINVAL,
1683 : : RTE_FLOW_ERROR_TYPE_ACTION,
1684 : : actions,
1685 : : "Invalid queue for FDIR.");
1686 : 0 : return -rte_errno;
1687 : : }
1688 : 0 : filter->input.dest_ctl =
1689 : : ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
1690 : 0 : break;
1691 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
1692 : 0 : dest_num++;
1693 : :
1694 : 0 : filter->input.dest_ctl =
1695 : : ICE_FLTR_PRGM_DESC_DEST_DROP_PKT;
1696 : 0 : break;
1697 : 0 : case RTE_FLOW_ACTION_TYPE_PASSTHRU:
1698 : 0 : dest_num++;
1699 : :
1700 : 0 : filter->input.dest_ctl =
1701 : : ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER;
1702 : 0 : break;
1703 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
1704 : 0 : dest_num++;
1705 : :
1706 : 0 : ret = ice_fdir_parse_action_qregion(pf,
1707 : : error, actions, filter);
1708 [ # # ]: 0 : if (ret)
1709 : 0 : return ret;
1710 : : break;
1711 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
1712 : 0 : mark_num++;
1713 : 0 : filter->mark_flag = 1;
1714 : 0 : mark_spec = actions->conf;
1715 : 0 : filter->input.fltr_id = mark_spec->id;
1716 : 0 : filter->input.fdid_prio = ICE_FXD_FLTR_QW1_FDID_PRI_ONE;
1717 : 0 : break;
1718 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
1719 : 0 : counter_num++;
1720 : :
1721 : 0 : act_count = actions->conf;
1722 : 0 : filter->input.cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
1723 [ # # ]: 0 : rte_memcpy(&filter->act_count, act_count,
1724 : : sizeof(filter->act_count));
1725 : :
1726 : : break;
1727 : 0 : default:
1728 : 0 : rte_flow_error_set(error, EINVAL,
1729 : : RTE_FLOW_ERROR_TYPE_ACTION, actions,
1730 : : "Invalid action.");
1731 : 0 : return -rte_errno;
1732 : : }
1733 : : }
1734 : :
1735 [ # # ]: 0 : if (dest_num >= 2) {
1736 : 0 : rte_flow_error_set(error, EINVAL,
1737 : : RTE_FLOW_ERROR_TYPE_ACTION, actions,
1738 : : "Unsupported action combination");
1739 : 0 : return -rte_errno;
1740 : : }
1741 : :
1742 [ # # ]: 0 : if (mark_num >= 2) {
1743 : 0 : rte_flow_error_set(error, EINVAL,
1744 : : RTE_FLOW_ERROR_TYPE_ACTION, actions,
1745 : : "Too many mark actions");
1746 : 0 : return -rte_errno;
1747 : : }
1748 : :
1749 [ # # ]: 0 : if (counter_num >= 2) {
1750 : 0 : rte_flow_error_set(error, EINVAL,
1751 : : RTE_FLOW_ERROR_TYPE_ACTION, actions,
1752 : : "Too many count actions");
1753 : 0 : return -rte_errno;
1754 : : }
1755 : :
1756 [ # # ]: 0 : if (dest_num + mark_num + counter_num == 0) {
1757 : 0 : rte_flow_error_set(error, EINVAL,
1758 : : RTE_FLOW_ERROR_TYPE_ACTION, actions,
1759 : : "Empty action");
1760 : 0 : return -rte_errno;
1761 : : }
1762 : :
1763 : : /* set default action to PASSTHRU mode, in "mark/count only" case. */
1764 [ # # ]: 0 : if (dest_num == 0)
1765 : 0 : filter->input.dest_ctl =
1766 : : ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER;
1767 : :
1768 : : return 0;
1769 : : }
1770 : :
1771 : : static int
1772 : 0 : ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
1773 : : const struct rte_flow_item pattern[],
1774 : : struct rte_flow_error *error,
1775 : : struct ice_fdir_filter_conf *filter)
1776 : : {
1777 : : const struct rte_flow_item *item = pattern;
1778 : : enum rte_flow_item_type item_type;
1779 : : enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
1780 : : enum rte_flow_item_type l4 = RTE_FLOW_ITEM_TYPE_END;
1781 : : enum ice_fdir_tunnel_type tunnel_type = ICE_FDIR_TUNNEL_TYPE_NONE;
1782 : : const struct rte_flow_item_raw *raw_spec, *raw_mask;
1783 : : const struct rte_flow_item_eth *eth_spec, *eth_mask;
1784 : : const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_last, *ipv4_mask;
1785 : : const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
1786 : : const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_spec,
1787 : : *ipv6_frag_mask;
1788 : : const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
1789 : : const struct rte_flow_item_udp *udp_spec, *udp_mask;
1790 : : const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
1791 : : const struct rte_flow_item_vxlan *vxlan_spec, *vxlan_mask;
1792 : : const struct rte_flow_item_gtp *gtp_spec, *gtp_mask;
1793 : : const struct rte_flow_item_gtp_psc *gtp_psc_spec, *gtp_psc_mask;
1794 : : const struct rte_flow_item_esp *esp_spec, *esp_mask;
1795 : 0 : uint64_t input_set_i = ICE_INSET_NONE; /* only for tunnel inner */
1796 : 0 : uint64_t input_set_o = ICE_INSET_NONE; /* non-tunnel and tunnel outer */
1797 : : uint64_t *input_set;
1798 : : uint8_t flow_type = ICE_FLTR_PTYPE_NONF_NONE;
1799 : 0 : uint8_t ipv6_addr_mask[16] = {
1800 : : 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1801 : : 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
1802 : : };
1803 : : uint32_t vtc_flow_cpu;
1804 : : uint16_t ether_type;
1805 : : enum rte_flow_item_type next_type;
1806 : : bool is_outer = true;
1807 : : struct ice_fdir_extra *p_ext_data;
1808 : : struct ice_fdir_v4 *p_v4 = NULL;
1809 : : struct ice_fdir_v6 *p_v6 = NULL;
1810 : : struct ice_parser_result rslt;
1811 : : uint8_t item_num = 0;
1812 : :
1813 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1814 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN)
1815 : : tunnel_type = ICE_FDIR_TUNNEL_TYPE_VXLAN;
1816 : : /* To align with shared code behavior, save gtpu outer
1817 : : * fields in inner struct.
1818 : : */
1819 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_GTPU ||
1820 : : item->type == RTE_FLOW_ITEM_TYPE_GTP_PSC) {
1821 : : is_outer = false;
1822 : : }
1823 : 0 : item_num++;
1824 : : }
1825 : :
1826 : : /* This loop parse flow pattern and distinguish Non-tunnel and tunnel
1827 : : * flow. input_set_i is used for inner part.
1828 : : */
1829 [ # # ]: 0 : for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1830 : : item_type = item->type;
1831 : :
1832 [ # # ]: 0 : if (item->last && !(item_type == RTE_FLOW_ITEM_TYPE_IPV4 ||
1833 [ # # ]: 0 : item_type ==
1834 : : RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT)) {
1835 : 0 : rte_flow_error_set(error, EINVAL,
1836 : : RTE_FLOW_ERROR_TYPE_ITEM, item,
1837 : : "Not support range");
1838 : : }
1839 : :
1840 : 0 : input_set = (tunnel_type && !is_outer) ?
1841 [ # # ]: 0 : &input_set_i : &input_set_o;
1842 : :
1843 [ # # # # : 0 : switch (item_type) {
# # # # #
# # # #
# ]
1844 : 0 : case RTE_FLOW_ITEM_TYPE_RAW: {
1845 [ # # ]: 0 : if (ad->psr == NULL)
1846 : 0 : return -rte_errno;
1847 : :
1848 : 0 : raw_spec = item->spec;
1849 : 0 : raw_mask = item->mask;
1850 : :
1851 [ # # ]: 0 : if (item_num != 1)
1852 : : break;
1853 : :
1854 : : /* convert raw spec & mask from byte string to int */
1855 : 0 : unsigned char *spec_pattern =
1856 : : (uint8_t *)(uintptr_t)raw_spec->pattern;
1857 : 0 : unsigned char *mask_pattern =
1858 : : (uint8_t *)(uintptr_t)raw_mask->pattern;
1859 : : uint8_t *tmp_spec, *tmp_mask;
1860 : : uint16_t tmp_val = 0;
1861 : : uint16_t pkt_len = 0;
1862 : : uint8_t tmp = 0;
1863 : : int i, j;
1864 : :
1865 : 0 : pkt_len = strlen((char *)(uintptr_t)raw_spec->pattern);
1866 [ # # ]: 0 : if (strlen((char *)(uintptr_t)raw_mask->pattern) !=
1867 : : pkt_len)
1868 : 0 : return -rte_errno;
1869 : :
1870 : 0 : tmp_spec = rte_zmalloc(NULL, pkt_len / 2, 0);
1871 [ # # ]: 0 : if (!tmp_spec)
1872 : 0 : return -rte_errno;
1873 : :
1874 : 0 : tmp_mask = rte_zmalloc(NULL, pkt_len / 2, 0);
1875 [ # # ]: 0 : if (!tmp_mask) {
1876 : 0 : rte_free(tmp_spec);
1877 : 0 : return -rte_errno;
1878 : : }
1879 : :
1880 [ # # ]: 0 : for (i = 0, j = 0; i < pkt_len; i += 2, j++) {
1881 : 0 : tmp = spec_pattern[i];
1882 [ # # ]: 0 : if (tmp >= 'a' && tmp <= 'f')
1883 : 0 : tmp_val = tmp - 'a' + 10;
1884 [ # # ]: 0 : if (tmp >= 'A' && tmp <= 'F')
1885 : 0 : tmp_val = tmp - 'A' + 10;
1886 [ # # ]: 0 : if (tmp >= '0' && tmp <= '9')
1887 : 0 : tmp_val = tmp - '0';
1888 : :
1889 : 0 : tmp_val *= 16;
1890 : 0 : tmp = spec_pattern[i + 1];
1891 [ # # ]: 0 : if (tmp >= 'a' && tmp <= 'f')
1892 : 0 : tmp_spec[j] = tmp_val + tmp - 'a' + 10;
1893 [ # # ]: 0 : if (tmp >= 'A' && tmp <= 'F')
1894 : 0 : tmp_spec[j] = tmp_val + tmp - 'A' + 10;
1895 [ # # ]: 0 : if (tmp >= '0' && tmp <= '9')
1896 : 0 : tmp_spec[j] = tmp_val + tmp - '0';
1897 : :
1898 : 0 : tmp = mask_pattern[i];
1899 [ # # ]: 0 : if (tmp >= 'a' && tmp <= 'f')
1900 : 0 : tmp_val = tmp - 'a' + 10;
1901 [ # # ]: 0 : if (tmp >= 'A' && tmp <= 'F')
1902 : 0 : tmp_val = tmp - 'A' + 10;
1903 [ # # ]: 0 : if (tmp >= '0' && tmp <= '9')
1904 : 0 : tmp_val = tmp - '0';
1905 : :
1906 : 0 : tmp_val *= 16;
1907 : 0 : tmp = mask_pattern[i + 1];
1908 [ # # ]: 0 : if (tmp >= 'a' && tmp <= 'f')
1909 : 0 : tmp_mask[j] = tmp_val + tmp - 'a' + 10;
1910 [ # # ]: 0 : if (tmp >= 'A' && tmp <= 'F')
1911 : 0 : tmp_mask[j] = tmp_val + tmp - 'A' + 10;
1912 [ # # ]: 0 : if (tmp >= '0' && tmp <= '9')
1913 : 0 : tmp_mask[j] = tmp_val + tmp - '0';
1914 : : }
1915 : :
1916 : : pkt_len /= 2;
1917 : :
1918 [ # # ]: 0 : if (ice_parser_run(ad->psr, tmp_spec, pkt_len, &rslt))
1919 : 0 : return -rte_errno;
1920 : :
1921 : : if (!tmp_mask)
1922 : : return -rte_errno;
1923 : :
1924 : 0 : filter->prof = (struct ice_parser_profile *)
1925 : 0 : ice_malloc(&ad->hw, sizeof(*filter->prof));
1926 [ # # ]: 0 : if (!filter->prof)
1927 : : return -ENOMEM;
1928 : :
1929 [ # # ]: 0 : if (ice_parser_profile_init(&rslt, tmp_spec, tmp_mask,
1930 : : pkt_len, ICE_BLK_FD, true, filter->prof))
1931 : 0 : return -rte_errno;
1932 : :
1933 : 0 : u8 *pkt_buf = (u8 *)ice_malloc(&ad->hw, pkt_len + 1);
1934 [ # # ]: 0 : if (!pkt_buf)
1935 : : return -ENOMEM;
1936 : : rte_memcpy(pkt_buf, tmp_spec, pkt_len);
1937 : 0 : filter->pkt_buf = pkt_buf;
1938 : :
1939 : 0 : filter->pkt_len = pkt_len;
1940 : :
1941 : 0 : filter->parser_ena = true;
1942 : :
1943 : 0 : rte_free(tmp_spec);
1944 : 0 : rte_free(tmp_mask);
1945 : 0 : break;
1946 : : }
1947 : :
1948 : 0 : case RTE_FLOW_ITEM_TYPE_ETH:
1949 : : flow_type = ICE_FLTR_PTYPE_NON_IP_L2;
1950 : 0 : eth_spec = item->spec;
1951 : 0 : eth_mask = item->mask;
1952 : :
1953 [ # # ]: 0 : if (!(eth_spec && eth_mask))
1954 : : break;
1955 : :
1956 [ # # ]: 0 : if (!rte_is_zero_ether_addr(ð_mask->hdr.dst_addr))
1957 : 0 : *input_set |= ICE_INSET_DMAC;
1958 [ # # ]: 0 : if (!rte_is_zero_ether_addr(ð_mask->hdr.src_addr))
1959 : 0 : *input_set |= ICE_INSET_SMAC;
1960 : :
1961 : 0 : next_type = (item + 1)->type;
1962 : : /* Ignore this field except for ICE_FLTR_PTYPE_NON_IP_L2 */
1963 [ # # # # ]: 0 : if (eth_mask->hdr.ether_type == RTE_BE16(0xffff) &&
1964 : : next_type == RTE_FLOW_ITEM_TYPE_END) {
1965 : 0 : *input_set |= ICE_INSET_ETHERTYPE;
1966 [ # # ]: 0 : ether_type = rte_be_to_cpu_16(eth_spec->hdr.ether_type);
1967 : :
1968 : 0 : if (ether_type == RTE_ETHER_TYPE_IPV4 ||
1969 [ # # ]: 0 : ether_type == RTE_ETHER_TYPE_IPV6) {
1970 : 0 : rte_flow_error_set(error, EINVAL,
1971 : : RTE_FLOW_ERROR_TYPE_ITEM,
1972 : : item,
1973 : : "Unsupported ether_type.");
1974 : 0 : return -rte_errno;
1975 : : }
1976 : : }
1977 : :
1978 : 0 : p_ext_data = (tunnel_type && is_outer) ?
1979 [ # # ]: 0 : &filter->input.ext_data_outer :
1980 : : &filter->input.ext_data;
1981 : 0 : rte_memcpy(&p_ext_data->src_mac,
1982 [ # # ]: 0 : ð_spec->hdr.src_addr, RTE_ETHER_ADDR_LEN);
1983 : 0 : rte_memcpy(&p_ext_data->dst_mac,
1984 [ # # ]: 0 : ð_spec->hdr.dst_addr, RTE_ETHER_ADDR_LEN);
1985 : 0 : rte_memcpy(&p_ext_data->ether_type,
1986 [ # # ]: 0 : ð_spec->hdr.ether_type, sizeof(eth_spec->hdr.ether_type));
1987 : : break;
1988 : 0 : case RTE_FLOW_ITEM_TYPE_IPV4:
1989 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
1990 : : l3 = RTE_FLOW_ITEM_TYPE_IPV4;
1991 : 0 : ipv4_spec = item->spec;
1992 : 0 : ipv4_last = item->last;
1993 : 0 : ipv4_mask = item->mask;
1994 : 0 : p_v4 = (tunnel_type && is_outer) ?
1995 [ # # ]: 0 : &filter->input.ip_outer.v4 :
1996 : : &filter->input.ip.v4;
1997 : :
1998 [ # # ]: 0 : if (!(ipv4_spec && ipv4_mask))
1999 : : break;
2000 : :
2001 : : /* Check IPv4 mask and update input set */
2002 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
2003 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
2004 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
2005 : 0 : rte_flow_error_set(error, EINVAL,
2006 : : RTE_FLOW_ERROR_TYPE_ITEM,
2007 : : item,
2008 : : "Invalid IPv4 mask.");
2009 : 0 : return -rte_errno;
2010 : : }
2011 : :
2012 [ # # ]: 0 : if (ipv4_last &&
2013 [ # # ]: 0 : (ipv4_last->hdr.version_ihl ||
2014 [ # # ]: 0 : ipv4_last->hdr.type_of_service ||
2015 [ # # ]: 0 : ipv4_last->hdr.time_to_live ||
2016 : 0 : ipv4_last->hdr.total_length |
2017 [ # # ]: 0 : ipv4_last->hdr.next_proto_id ||
2018 [ # # ]: 0 : ipv4_last->hdr.hdr_checksum ||
2019 [ # # ]: 0 : ipv4_last->hdr.src_addr ||
2020 [ # # ]: 0 : ipv4_last->hdr.dst_addr)) {
2021 : 0 : rte_flow_error_set(error, EINVAL,
2022 : : RTE_FLOW_ERROR_TYPE_ITEM,
2023 : : item, "Invalid IPv4 last.");
2024 : 0 : return -rte_errno;
2025 : : }
2026 : :
2027 : : /* Mask for IPv4 src/dst addrs not supported */
2028 [ # # ]: 0 : if (ipv4_mask->hdr.src_addr &&
2029 : : ipv4_mask->hdr.src_addr != UINT32_MAX)
2030 : 0 : return -rte_errno;
2031 [ # # ]: 0 : if (ipv4_mask->hdr.dst_addr &&
2032 : : ipv4_mask->hdr.dst_addr != UINT32_MAX)
2033 : 0 : return -rte_errno;
2034 : :
2035 [ # # ]: 0 : if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
2036 : 0 : *input_set |= ICE_INSET_IPV4_DST;
2037 [ # # ]: 0 : if (ipv4_mask->hdr.src_addr == UINT32_MAX)
2038 : 0 : *input_set |= ICE_INSET_IPV4_SRC;
2039 [ # # ]: 0 : if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
2040 : 0 : *input_set |= ICE_INSET_IPV4_TTL;
2041 [ # # ]: 0 : if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
2042 : 0 : *input_set |= ICE_INSET_IPV4_PROTO;
2043 [ # # ]: 0 : if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
2044 : 0 : *input_set |= ICE_INSET_IPV4_TOS;
2045 : :
2046 : 0 : p_v4->dst_ip = ipv4_spec->hdr.dst_addr;
2047 : 0 : p_v4->src_ip = ipv4_spec->hdr.src_addr;
2048 : 0 : p_v4->ttl = ipv4_spec->hdr.time_to_live;
2049 : 0 : p_v4->proto = ipv4_spec->hdr.next_proto_id;
2050 : 0 : p_v4->tos = ipv4_spec->hdr.type_of_service;
2051 : :
2052 : : /* fragment Ipv4:
2053 : : * spec is 0x2000, mask is 0x2000
2054 : : */
2055 [ # # ]: 0 : if (ipv4_spec->hdr.fragment_offset ==
2056 : 0 : rte_cpu_to_be_16(RTE_IPV4_HDR_MF_FLAG) &&
2057 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ==
2058 : : rte_cpu_to_be_16(RTE_IPV4_HDR_MF_FLAG)) {
2059 : : /* all IPv4 fragment packet has the same
2060 : : * ethertype, if the spec and mask is valid,
2061 : : * set ethertype into input set.
2062 : : */
2063 : : flow_type = ICE_FLTR_PTYPE_FRAG_IPV4;
2064 : 0 : *input_set |= ICE_INSET_ETHERTYPE;
2065 : 0 : input_set_o |= ICE_INSET_ETHERTYPE;
2066 [ # # ]: 0 : } else if (ipv4_mask->hdr.packet_id == UINT16_MAX) {
2067 : 0 : rte_flow_error_set(error, EINVAL,
2068 : : RTE_FLOW_ERROR_TYPE_ITEM,
2069 : : item, "Invalid IPv4 mask.");
2070 : 0 : return -rte_errno;
2071 : : }
2072 : :
2073 : : break;
2074 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6:
2075 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
2076 : : l3 = RTE_FLOW_ITEM_TYPE_IPV6;
2077 : 0 : ipv6_spec = item->spec;
2078 : 0 : ipv6_mask = item->mask;
2079 : 0 : p_v6 = (tunnel_type && is_outer) ?
2080 [ # # ]: 0 : &filter->input.ip_outer.v6 :
2081 : : &filter->input.ip.v6;
2082 : :
2083 [ # # ]: 0 : if (!(ipv6_spec && ipv6_mask))
2084 : : break;
2085 : :
2086 : : /* Check IPv6 mask and update input set */
2087 [ # # ]: 0 : if (ipv6_mask->hdr.payload_len) {
2088 : 0 : rte_flow_error_set(error, EINVAL,
2089 : : RTE_FLOW_ERROR_TYPE_ITEM,
2090 : : item,
2091 : : "Invalid IPv6 mask");
2092 : 0 : return -rte_errno;
2093 : : }
2094 : :
2095 [ # # ]: 0 : if (!memcmp(ipv6_mask->hdr.src_addr, ipv6_addr_mask,
2096 : : RTE_DIM(ipv6_mask->hdr.src_addr)))
2097 : 0 : *input_set |= ICE_INSET_IPV6_SRC;
2098 [ # # ]: 0 : if (!memcmp(ipv6_mask->hdr.dst_addr, ipv6_addr_mask,
2099 : : RTE_DIM(ipv6_mask->hdr.dst_addr)))
2100 : 0 : *input_set |= ICE_INSET_IPV6_DST;
2101 : :
2102 [ # # ]: 0 : if ((ipv6_mask->hdr.vtc_flow &
2103 : : rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
2104 : : == rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
2105 : 0 : *input_set |= ICE_INSET_IPV6_TC;
2106 [ # # ]: 0 : if (ipv6_mask->hdr.proto == UINT8_MAX)
2107 : 0 : *input_set |= ICE_INSET_IPV6_NEXT_HDR;
2108 [ # # ]: 0 : if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
2109 : 0 : *input_set |= ICE_INSET_IPV6_HOP_LIMIT;
2110 : :
2111 [ # # ]: 0 : rte_memcpy(&p_v6->dst_ip, ipv6_spec->hdr.dst_addr, 16);
2112 [ # # ]: 0 : rte_memcpy(&p_v6->src_ip, ipv6_spec->hdr.src_addr, 16);
2113 [ # # ]: 0 : vtc_flow_cpu = rte_be_to_cpu_32(ipv6_spec->hdr.vtc_flow);
2114 : 0 : p_v6->tc = (uint8_t)(vtc_flow_cpu >> ICE_FDIR_IPV6_TC_OFFSET);
2115 : 0 : p_v6->proto = ipv6_spec->hdr.proto;
2116 : 0 : p_v6->hlim = ipv6_spec->hdr.hop_limits;
2117 : 0 : break;
2118 : 0 : case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
2119 : : l3 = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT;
2120 : : flow_type = ICE_FLTR_PTYPE_FRAG_IPV6;
2121 : 0 : ipv6_frag_spec = item->spec;
2122 : 0 : ipv6_frag_mask = item->mask;
2123 : :
2124 [ # # ]: 0 : if (!(ipv6_frag_spec && ipv6_frag_mask))
2125 : : break;
2126 : :
2127 : : /* fragment Ipv6:
2128 : : * spec is 0x1, mask is 0x1
2129 : : */
2130 [ # # ]: 0 : if (ipv6_frag_spec->hdr.frag_data ==
2131 : 0 : rte_cpu_to_be_16(1) &&
2132 [ # # ]: 0 : ipv6_frag_mask->hdr.frag_data ==
2133 : : rte_cpu_to_be_16(1)) {
2134 : : /* all IPv6 fragment packet has the same
2135 : : * ethertype, if the spec and mask is valid,
2136 : : * set ethertype into input set.
2137 : : */
2138 : 0 : *input_set |= ICE_INSET_ETHERTYPE;
2139 : 0 : input_set_o |= ICE_INSET_ETHERTYPE;
2140 [ # # ]: 0 : } else if (ipv6_frag_mask->hdr.id == UINT32_MAX) {
2141 : 0 : rte_flow_error_set(error, EINVAL,
2142 : : RTE_FLOW_ERROR_TYPE_ITEM,
2143 : : item, "Invalid IPv6 mask.");
2144 : 0 : return -rte_errno;
2145 : : }
2146 : :
2147 : : break;
2148 : :
2149 : 0 : case RTE_FLOW_ITEM_TYPE_TCP:
2150 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2151 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
2152 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2153 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
2154 : :
2155 : 0 : tcp_spec = item->spec;
2156 : 0 : tcp_mask = item->mask;
2157 : :
2158 [ # # ]: 0 : if (!(tcp_spec && tcp_mask))
2159 : : break;
2160 : :
2161 : : /* Check TCP mask and update input set */
2162 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
2163 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
2164 [ # # ]: 0 : tcp_mask->hdr.data_off ||
2165 [ # # ]: 0 : tcp_mask->hdr.tcp_flags ||
2166 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
2167 [ # # ]: 0 : tcp_mask->hdr.cksum ||
2168 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
2169 : 0 : rte_flow_error_set(error, EINVAL,
2170 : : RTE_FLOW_ERROR_TYPE_ITEM,
2171 : : item,
2172 : : "Invalid TCP mask");
2173 : 0 : return -rte_errno;
2174 : : }
2175 : :
2176 : : /* Mask for TCP src/dst ports not supported */
2177 [ # # ]: 0 : if (tcp_mask->hdr.src_port &&
2178 : : tcp_mask->hdr.src_port != UINT16_MAX)
2179 : 0 : return -rte_errno;
2180 [ # # ]: 0 : if (tcp_mask->hdr.dst_port &&
2181 : : tcp_mask->hdr.dst_port != UINT16_MAX)
2182 : 0 : return -rte_errno;
2183 : :
2184 [ # # ]: 0 : if (tcp_mask->hdr.src_port == UINT16_MAX)
2185 : 0 : *input_set |= ICE_INSET_TCP_SRC_PORT;
2186 [ # # ]: 0 : if (tcp_mask->hdr.dst_port == UINT16_MAX)
2187 : 0 : *input_set |= ICE_INSET_TCP_DST_PORT;
2188 : :
2189 : : /* Get filter info */
2190 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2191 [ # # ]: 0 : assert(p_v4);
2192 : 0 : p_v4->dst_port = tcp_spec->hdr.dst_port;
2193 : 0 : p_v4->src_port = tcp_spec->hdr.src_port;
2194 [ # # ]: 0 : } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2195 [ # # ]: 0 : assert(p_v6);
2196 : 0 : p_v6->dst_port = tcp_spec->hdr.dst_port;
2197 : 0 : p_v6->src_port = tcp_spec->hdr.src_port;
2198 : : }
2199 : : break;
2200 : 0 : case RTE_FLOW_ITEM_TYPE_UDP:
2201 : : l4 = RTE_FLOW_ITEM_TYPE_UDP;
2202 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2203 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
2204 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2205 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
2206 : :
2207 : 0 : udp_spec = item->spec;
2208 : 0 : udp_mask = item->mask;
2209 : :
2210 [ # # ]: 0 : if (!(udp_spec && udp_mask))
2211 : : break;
2212 : :
2213 : : /* Check UDP mask and update input set*/
2214 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
2215 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
2216 : 0 : rte_flow_error_set(error, EINVAL,
2217 : : RTE_FLOW_ERROR_TYPE_ITEM,
2218 : : item,
2219 : : "Invalid UDP mask");
2220 : 0 : return -rte_errno;
2221 : : }
2222 : :
2223 : : /* Mask for UDP src/dst ports not supported */
2224 [ # # ]: 0 : if (udp_mask->hdr.src_port &&
2225 : : udp_mask->hdr.src_port != UINT16_MAX)
2226 : 0 : return -rte_errno;
2227 [ # # ]: 0 : if (udp_mask->hdr.dst_port &&
2228 : : udp_mask->hdr.dst_port != UINT16_MAX)
2229 : 0 : return -rte_errno;
2230 : :
2231 [ # # ]: 0 : if (udp_mask->hdr.src_port == UINT16_MAX)
2232 : 0 : *input_set |= ICE_INSET_UDP_SRC_PORT;
2233 [ # # ]: 0 : if (udp_mask->hdr.dst_port == UINT16_MAX)
2234 : 0 : *input_set |= ICE_INSET_UDP_DST_PORT;
2235 : :
2236 : : /* Get filter info */
2237 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2238 [ # # ]: 0 : assert(p_v4);
2239 : 0 : p_v4->dst_port = udp_spec->hdr.dst_port;
2240 : 0 : p_v4->src_port = udp_spec->hdr.src_port;
2241 [ # # ]: 0 : } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2242 [ # # ]: 0 : assert(p_v6);
2243 : 0 : p_v6->src_port = udp_spec->hdr.src_port;
2244 : 0 : p_v6->dst_port = udp_spec->hdr.dst_port;
2245 : : }
2246 : : break;
2247 : 0 : case RTE_FLOW_ITEM_TYPE_SCTP:
2248 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2249 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
2250 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2251 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
2252 : :
2253 : 0 : sctp_spec = item->spec;
2254 : 0 : sctp_mask = item->mask;
2255 : :
2256 [ # # ]: 0 : if (!(sctp_spec && sctp_mask))
2257 : : break;
2258 : :
2259 : : /* Check SCTP mask and update input set */
2260 [ # # ]: 0 : if (sctp_mask->hdr.cksum) {
2261 : 0 : rte_flow_error_set(error, EINVAL,
2262 : : RTE_FLOW_ERROR_TYPE_ITEM,
2263 : : item,
2264 : : "Invalid UDP mask");
2265 : 0 : return -rte_errno;
2266 : : }
2267 : :
2268 : : /* Mask for SCTP src/dst ports not supported */
2269 [ # # ]: 0 : if (sctp_mask->hdr.src_port &&
2270 : : sctp_mask->hdr.src_port != UINT16_MAX)
2271 : 0 : return -rte_errno;
2272 [ # # ]: 0 : if (sctp_mask->hdr.dst_port &&
2273 : : sctp_mask->hdr.dst_port != UINT16_MAX)
2274 : 0 : return -rte_errno;
2275 : :
2276 [ # # ]: 0 : if (sctp_mask->hdr.src_port == UINT16_MAX)
2277 : 0 : *input_set |= ICE_INSET_SCTP_SRC_PORT;
2278 [ # # ]: 0 : if (sctp_mask->hdr.dst_port == UINT16_MAX)
2279 : 0 : *input_set |= ICE_INSET_SCTP_DST_PORT;
2280 : :
2281 : : /* Get filter info */
2282 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2283 [ # # ]: 0 : assert(p_v4);
2284 : 0 : p_v4->dst_port = sctp_spec->hdr.dst_port;
2285 : 0 : p_v4->src_port = sctp_spec->hdr.src_port;
2286 [ # # ]: 0 : } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2287 [ # # ]: 0 : assert(p_v6);
2288 : 0 : p_v6->dst_port = sctp_spec->hdr.dst_port;
2289 : 0 : p_v6->src_port = sctp_spec->hdr.src_port;
2290 : : }
2291 : : break;
2292 : : case RTE_FLOW_ITEM_TYPE_VOID:
2293 : : break;
2294 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
2295 : : l3 = RTE_FLOW_ITEM_TYPE_END;
2296 : 0 : vxlan_spec = item->spec;
2297 : 0 : vxlan_mask = item->mask;
2298 : : is_outer = false;
2299 : :
2300 [ # # ]: 0 : if (!(vxlan_spec && vxlan_mask))
2301 : : break;
2302 : :
2303 [ # # ]: 0 : if (vxlan_mask->hdr.vx_flags) {
2304 : 0 : rte_flow_error_set(error, EINVAL,
2305 : : RTE_FLOW_ERROR_TYPE_ITEM,
2306 : : item,
2307 : : "Invalid vxlan field");
2308 : 0 : return -rte_errno;
2309 : : }
2310 : :
2311 [ # # ]: 0 : if (vxlan_mask->hdr.vx_vni)
2312 : 0 : *input_set |= ICE_INSET_VXLAN_VNI;
2313 : :
2314 : 0 : filter->input.vxlan_data.vni = vxlan_spec->hdr.vx_vni;
2315 : :
2316 : 0 : break;
2317 : 0 : case RTE_FLOW_ITEM_TYPE_GTPU:
2318 : : l3 = RTE_FLOW_ITEM_TYPE_END;
2319 : : tunnel_type = ICE_FDIR_TUNNEL_TYPE_GTPU;
2320 : 0 : gtp_spec = item->spec;
2321 : 0 : gtp_mask = item->mask;
2322 : :
2323 [ # # ]: 0 : if (!(gtp_spec && gtp_mask))
2324 : : break;
2325 : :
2326 : 0 : if (gtp_mask->hdr.gtp_hdr_info ||
2327 [ # # ]: 0 : gtp_mask->hdr.msg_type ||
2328 : : gtp_mask->hdr.plen) {
2329 : 0 : rte_flow_error_set(error, EINVAL,
2330 : : RTE_FLOW_ERROR_TYPE_ITEM,
2331 : : item,
2332 : : "Invalid GTP mask");
2333 : 0 : return -rte_errno;
2334 : : }
2335 : :
2336 [ # # ]: 0 : if (gtp_mask->hdr.teid == UINT32_MAX)
2337 : 0 : input_set_o |= ICE_INSET_GTPU_TEID;
2338 : :
2339 : 0 : filter->input.gtpu_data.teid = gtp_spec->hdr.teid;
2340 : 0 : break;
2341 : 0 : case RTE_FLOW_ITEM_TYPE_GTP_PSC:
2342 : : tunnel_type = ICE_FDIR_TUNNEL_TYPE_GTPU_EH;
2343 : 0 : gtp_psc_spec = item->spec;
2344 : 0 : gtp_psc_mask = item->mask;
2345 : :
2346 [ # # ]: 0 : if (!(gtp_psc_spec && gtp_psc_mask))
2347 : : break;
2348 : :
2349 [ # # ]: 0 : if (gtp_psc_mask->hdr.qfi == 0x3F)
2350 : 0 : input_set_o |= ICE_INSET_GTPU_QFI;
2351 : :
2352 : 0 : filter->input.gtpu_data.qfi =
2353 : 0 : gtp_psc_spec->hdr.qfi;
2354 : 0 : break;
2355 : 0 : case RTE_FLOW_ITEM_TYPE_ESP:
2356 : 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4 &&
2357 [ # # ]: 0 : l4 == RTE_FLOW_ITEM_TYPE_UDP)
2358 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_NAT_T_ESP;
2359 [ # # ]: 0 : else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6 &&
2360 : : l4 == RTE_FLOW_ITEM_TYPE_UDP)
2361 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_NAT_T_ESP;
2362 : 0 : else if (l3 == RTE_FLOW_ITEM_TYPE_IPV4 &&
2363 [ # # ]: 0 : l4 == RTE_FLOW_ITEM_TYPE_END)
2364 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_ESP;
2365 [ # # ]: 0 : else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6 &&
2366 : : l4 == RTE_FLOW_ITEM_TYPE_END)
2367 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_ESP;
2368 : :
2369 : 0 : esp_spec = item->spec;
2370 : 0 : esp_mask = item->mask;
2371 : :
2372 [ # # ]: 0 : if (!(esp_spec && esp_mask))
2373 : : break;
2374 : :
2375 [ # # ]: 0 : if (esp_mask->hdr.spi == UINT32_MAX) {
2376 [ # # ]: 0 : if (l4 == RTE_FLOW_ITEM_TYPE_UDP)
2377 : 0 : *input_set |= ICE_INSET_NAT_T_ESP_SPI;
2378 : : else
2379 : 0 : *input_set |= ICE_INSET_ESP_SPI;
2380 : : }
2381 : :
2382 [ # # ]: 0 : if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2383 : 0 : filter->input.ip.v4.sec_parm_idx =
2384 : 0 : esp_spec->hdr.spi;
2385 [ # # ]: 0 : else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2386 : 0 : filter->input.ip.v6.sec_parm_idx =
2387 : 0 : esp_spec->hdr.spi;
2388 : : break;
2389 : 0 : default:
2390 : 0 : rte_flow_error_set(error, EINVAL,
2391 : : RTE_FLOW_ERROR_TYPE_ITEM,
2392 : : item,
2393 : : "Invalid pattern item.");
2394 : 0 : return -rte_errno;
2395 : : }
2396 : : }
2397 : :
2398 : 0 : if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU &&
2399 [ # # ]: 0 : flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
2400 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_GTPU;
2401 [ # # ]: 0 : else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU_EH &&
2402 : : flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
2403 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH;
2404 : 0 : else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU &&
2405 [ # # ]: 0 : flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
2406 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_GTPU;
2407 [ # # ]: 0 : else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU_EH &&
2408 : : flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
2409 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH;
2410 [ # # ]: 0 : else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2411 : : flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
2412 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP;
2413 : 0 : else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2414 [ # # ]: 0 : flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP)
2415 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP;
2416 : 0 : else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2417 [ # # ]: 0 : flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP)
2418 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP;
2419 : 0 : else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2420 [ # # ]: 0 : flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER)
2421 : : flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER;
2422 : :
2423 : 0 : filter->tunnel_type = tunnel_type;
2424 : 0 : filter->input.flow_type = flow_type;
2425 : 0 : filter->input_set_o = input_set_o;
2426 : 0 : filter->input_set_i = input_set_i;
2427 : :
2428 : 0 : return 0;
2429 : : }
2430 : :
2431 : : static int
2432 : 0 : ice_fdir_parse(struct ice_adapter *ad,
2433 : : struct ice_pattern_match_item *array,
2434 : : uint32_t array_len,
2435 : : const struct rte_flow_item pattern[],
2436 : : const struct rte_flow_action actions[],
2437 : : uint32_t priority,
2438 : : void **meta,
2439 : : struct rte_flow_error *error)
2440 : : {
2441 : : struct ice_pf *pf = &ad->pf;
2442 : 0 : struct ice_fdir_filter_conf *filter = &pf->fdir.conf;
2443 : : struct ice_pattern_match_item *item = NULL;
2444 : : uint64_t input_set;
2445 : : bool raw = false;
2446 : : int ret;
2447 : :
2448 : : memset(filter, 0, sizeof(*filter));
2449 : 0 : item = ice_search_pattern_match_item(ad, pattern, array, array_len,
2450 : : error);
2451 : :
2452 [ # # ]: 0 : if (priority >= 1)
2453 : 0 : return -rte_errno;
2454 : :
2455 [ # # ]: 0 : if (!item)
2456 : 0 : return -rte_errno;
2457 : :
2458 : 0 : ret = ice_fdir_parse_pattern(ad, pattern, error, filter);
2459 [ # # ]: 0 : if (ret)
2460 : 0 : goto error;
2461 : :
2462 [ # # ]: 0 : if (item->pattern_list[0] == RTE_FLOW_ITEM_TYPE_RAW)
2463 : : raw = true;
2464 : :
2465 : 0 : input_set = filter->input_set_o | filter->input_set_i;
2466 [ # # ]: 0 : input_set = raw ? ~input_set : input_set;
2467 : :
2468 [ # # ]: 0 : if (!input_set || filter->input_set_o &
2469 [ # # ]: 0 : ~(item->input_set_mask_o | ICE_INSET_ETHERTYPE) ||
2470 [ # # ]: 0 : filter->input_set_i & ~item->input_set_mask_i) {
2471 : 0 : rte_flow_error_set(error, EINVAL,
2472 : : RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2473 : : pattern,
2474 : : "Invalid input set");
2475 : 0 : ret = -rte_errno;
2476 : 0 : goto error;
2477 : : }
2478 : :
2479 : 0 : ret = ice_fdir_parse_action(ad, actions, error, filter);
2480 [ # # ]: 0 : if (ret)
2481 : 0 : goto error;
2482 : :
2483 [ # # ]: 0 : if (meta)
2484 : 0 : *meta = filter;
2485 : :
2486 : 0 : rte_free(item);
2487 : 0 : return ret;
2488 : 0 : error:
2489 : 0 : rte_free(filter->prof);
2490 : 0 : rte_free(filter->pkt_buf);
2491 : 0 : rte_free(item);
2492 : 0 : return ret;
2493 : : }
2494 : :
2495 : : struct ice_flow_parser ice_fdir_parser = {
2496 : : .engine = &ice_fdir_engine,
2497 : : .array = ice_fdir_supported_pattern,
2498 : : .array_len = RTE_DIM(ice_fdir_supported_pattern),
2499 : : .parse_pattern_action = ice_fdir_parse,
2500 : : .stage = ICE_FLOW_STAGE_DISTRIBUTOR,
2501 : : };
2502 : :
2503 : 235 : RTE_INIT(ice_fdir_engine_register)
2504 : : {
2505 : 235 : ice_register_flow_engine(&ice_fdir_engine);
2506 : 235 : }
|