Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2015 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : :
13 : : #include <rte_ether.h>
14 : : #include <ethdev_driver.h>
15 : : #include <rte_log.h>
16 : : #include <rte_memzone.h>
17 : : #include <rte_malloc.h>
18 : : #include <rte_arp.h>
19 : : #include <rte_ip.h>
20 : : #include <rte_udp.h>
21 : : #include <rte_tcp.h>
22 : : #include <rte_sctp.h>
23 : : #include <rte_hash_crc.h>
24 : : #include <rte_bitmap.h>
25 : : #include <rte_os_shim.h>
26 : :
27 : : #include "i40e_logs.h"
28 : : #include "base/i40e_type.h"
29 : : #include "base/i40e_prototype.h"
30 : : #include "i40e_ethdev.h"
31 : : #include "i40e_rxtx.h"
32 : :
33 : : #define I40E_FDIR_MZ_NAME "FDIR_MEMZONE"
34 : : #ifndef IPV6_ADDR_LEN
35 : : #define IPV6_ADDR_LEN 16
36 : : #endif
37 : :
38 : : #ifndef IPPROTO_L2TP
39 : : #define IPPROTO_L2TP 115
40 : : #endif
41 : :
42 : : #define I40E_FDIR_PKT_LEN 512
43 : : #define I40E_FDIR_IP_DEFAULT_LEN 420
44 : : #define I40E_FDIR_IP_DEFAULT_TTL 0x40
45 : : #define I40E_FDIR_IP_DEFAULT_VERSION_IHL 0x45
46 : : #define I40E_FDIR_TCP_DEFAULT_DATAOFF 0x50
47 : : #define I40E_FDIR_IPv6_DEFAULT_VTC_FLOW 0x60000000
48 : :
49 : : #define I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS 0xFF
50 : : #define I40E_FDIR_IPv6_PAYLOAD_LEN 380
51 : : #define I40E_FDIR_UDP_DEFAULT_LEN 400
52 : : #define I40E_FDIR_GTP_DEFAULT_LEN 384
53 : : #define I40E_FDIR_INNER_IP_DEFAULT_LEN 384
54 : : #define I40E_FDIR_INNER_IPV6_DEFAULT_LEN 344
55 : :
56 : : #define I40E_FDIR_GTPC_DST_PORT 2123
57 : : #define I40E_FDIR_GTPU_DST_PORT 2152
58 : : #define I40E_FDIR_GTP_VER_FLAG_0X30 0x30
59 : : #define I40E_FDIR_GTP_VER_FLAG_0X32 0x32
60 : : #define I40E_FDIR_GTP_MSG_TYPE_0X01 0x01
61 : : #define I40E_FDIR_GTP_MSG_TYPE_0XFF 0xFF
62 : :
63 : : #define I40E_FDIR_ESP_DST_PORT 4500
64 : :
65 : : /* Wait time for fdir filter programming */
66 : : #define I40E_FDIR_MAX_WAIT_US 10000
67 : :
68 : : /* Wait count and interval for fdir filter flush */
69 : : #define I40E_FDIR_FLUSH_RETRY 50
70 : : #define I40E_FDIR_FLUSH_INTERVAL_MS 5
71 : :
72 : : #define I40E_COUNTER_PF 2
73 : : /* Statistic counter index for one pf */
74 : : #define I40E_COUNTER_INDEX_FDIR(pf_id) (0 + (pf_id) * I40E_COUNTER_PF)
75 : :
76 : : #define I40E_FDIR_FLOWS ( \
77 : : (1ULL << RTE_ETH_FLOW_FRAG_IPV4) | \
78 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
79 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
80 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
81 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
82 : : (1ULL << RTE_ETH_FLOW_FRAG_IPV6) | \
83 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
84 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
85 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
86 : : (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
87 : : (1ULL << RTE_ETH_FLOW_L2_PAYLOAD))
88 : :
89 : : static int i40e_fdir_filter_convert(const struct i40e_fdir_filter_conf *input,
90 : : struct i40e_fdir_filter *filter);
91 : : static struct i40e_fdir_filter *
92 : : i40e_sw_fdir_filter_lookup(struct i40e_fdir_info *fdir_info,
93 : : const struct i40e_fdir_input *input);
94 : : static int i40e_sw_fdir_filter_insert(struct i40e_pf *pf,
95 : : struct i40e_fdir_filter *filter);
96 : : static int
97 : : i40e_flow_fdir_filter_programming(struct i40e_pf *pf,
98 : : enum i40e_filter_pctype pctype,
99 : : const struct i40e_fdir_filter_conf *filter,
100 : : bool add, bool wait_status);
101 : :
102 : : static int
103 : 0 : i40e_fdir_rx_queue_init(struct i40e_rx_queue *rxq)
104 : : {
105 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
106 : : struct i40e_hmc_obj_rxq rx_ctx;
107 : : int err = I40E_SUCCESS;
108 : :
109 : : memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
110 : : /* Init the RX queue in hardware */
111 : 0 : rx_ctx.dbuff = I40E_RXBUF_SZ_1024 >> I40E_RXQ_CTX_DBUFF_SHIFT;
112 : : rx_ctx.hbuff = 0;
113 : 0 : rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
114 : 0 : rx_ctx.qlen = rxq->nb_rx_desc;
115 : : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
116 : 0 : rx_ctx.dsize = 1;
117 : : #endif
118 : : rx_ctx.dtype = i40e_header_split_none;
119 : : rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
120 : 0 : rx_ctx.rxmax = I40E_ETH_MAX_LEN;
121 : 0 : rx_ctx.tphrdesc_ena = 1;
122 : 0 : rx_ctx.tphwdesc_ena = 1;
123 : 0 : rx_ctx.tphdata_ena = 1;
124 : 0 : rx_ctx.tphhead_ena = 1;
125 : 0 : rx_ctx.lrxqthresh = 2;
126 : : rx_ctx.crcstrip = 0;
127 : 0 : rx_ctx.l2tsel = 1;
128 : : rx_ctx.showiv = 0;
129 : 0 : rx_ctx.prefena = 1;
130 : :
131 : 0 : err = i40e_clear_lan_rx_queue_context(hw, rxq->reg_idx);
132 [ # # ]: 0 : if (err != I40E_SUCCESS) {
133 : 0 : PMD_DRV_LOG(ERR, "Failed to clear FDIR RX queue context.");
134 : 0 : return err;
135 : : }
136 : 0 : err = i40e_set_lan_rx_queue_context(hw, rxq->reg_idx, &rx_ctx);
137 [ # # ]: 0 : if (err != I40E_SUCCESS) {
138 : 0 : PMD_DRV_LOG(ERR, "Failed to set FDIR RX queue context.");
139 : 0 : return err;
140 : : }
141 : 0 : rxq->qrx_tail = hw->hw_addr +
142 : 0 : I40E_QRX_TAIL(rxq->vsi->base_queue);
143 : :
144 : : rte_wmb();
145 : : /* Init the RX tail register. */
146 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
147 : :
148 : 0 : return err;
149 : : }
150 : :
151 : : /*
152 : : * i40e_fdir_setup - reserve and initialize the Flow Director resources
153 : : * @pf: board private structure
154 : : */
155 : : int
156 : 0 : i40e_fdir_setup(struct i40e_pf *pf)
157 : : {
158 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
159 : : struct i40e_vsi *vsi;
160 : : int err = I40E_SUCCESS;
161 : : char z_name[RTE_MEMZONE_NAMESIZE];
162 : : const struct rte_memzone *mz = NULL;
163 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[pf->dev_data->port_id];
164 : : uint16_t i;
165 : :
166 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_FDIR) == 0) {
167 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
168 : 0 : return I40E_NOT_SUPPORTED;
169 : : }
170 : :
171 : 0 : PMD_DRV_LOG(INFO, "FDIR HW Capabilities: num_filters_guaranteed = %u,"
172 : : " num_filters_best_effort = %u.",
173 : : hw->func_caps.fd_filters_guaranteed,
174 : : hw->func_caps.fd_filters_best_effort);
175 : :
176 : 0 : vsi = pf->fdir.fdir_vsi;
177 [ # # ]: 0 : if (vsi) {
178 : 0 : PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
179 : 0 : return I40E_SUCCESS;
180 : : }
181 : :
182 : : /* make new FDIR VSI */
183 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->main_vsi, 0);
184 [ # # ]: 0 : if (!vsi) {
185 : 0 : PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
186 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
187 : : }
188 : 0 : pf->fdir.fdir_vsi = vsi;
189 : :
190 : : /*Fdir tx queue setup*/
191 : 0 : err = i40e_fdir_setup_tx_resources(pf);
192 [ # # ]: 0 : if (err) {
193 : 0 : PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
194 : 0 : goto fail_setup_tx;
195 : : }
196 : :
197 : : /*Fdir rx queue setup*/
198 : 0 : err = i40e_fdir_setup_rx_resources(pf);
199 [ # # ]: 0 : if (err) {
200 : 0 : PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
201 : 0 : goto fail_setup_rx;
202 : : }
203 : :
204 : 0 : err = i40e_tx_queue_init(pf->fdir.txq);
205 [ # # ]: 0 : if (err) {
206 : 0 : PMD_DRV_LOG(ERR, "Failed to do FDIR TX initialization.");
207 : 0 : goto fail_mem;
208 : : }
209 : :
210 : : /* need switch on before dev start*/
211 : 0 : err = i40e_switch_tx_queue(hw, vsi->base_queue, TRUE);
212 [ # # ]: 0 : if (err) {
213 : 0 : PMD_DRV_LOG(ERR, "Failed to do fdir TX switch on.");
214 : 0 : goto fail_mem;
215 : : }
216 : :
217 : : /* Init the rx queue in hardware */
218 : 0 : err = i40e_fdir_rx_queue_init(pf->fdir.rxq);
219 [ # # ]: 0 : if (err) {
220 : 0 : PMD_DRV_LOG(ERR, "Failed to do FDIR RX initialization.");
221 : 0 : goto fail_mem;
222 : : }
223 : :
224 : : /* switch on rx queue */
225 : 0 : err = i40e_switch_rx_queue(hw, vsi->base_queue, TRUE);
226 [ # # ]: 0 : if (err) {
227 : 0 : PMD_DRV_LOG(ERR, "Failed to do FDIR RX switch on.");
228 : 0 : goto fail_mem;
229 : : }
230 : :
231 : : /* enable FDIR MSIX interrupt */
232 : 0 : vsi->nb_used_qps = 1;
233 : 0 : i40e_vsi_queues_bind_intr(vsi, I40E_ITR_INDEX_NONE);
234 : 0 : i40e_vsi_enable_queues_intr(vsi);
235 : :
236 : : /* reserve memory for the fdir programming packet */
237 : 0 : snprintf(z_name, sizeof(z_name), "%s_%s_%d",
238 : 0 : eth_dev->device->driver->name,
239 : : I40E_FDIR_MZ_NAME,
240 : 0 : eth_dev->data->port_id);
241 : 0 : mz = i40e_memzone_reserve(z_name, I40E_FDIR_PKT_LEN *
242 : : I40E_FDIR_PRG_PKT_CNT, SOCKET_ID_ANY);
243 [ # # ]: 0 : if (!mz) {
244 : 0 : PMD_DRV_LOG(ERR, "Cannot init memzone for "
245 : : "flow director program packet.");
246 : : err = I40E_ERR_NO_MEMORY;
247 : 0 : goto fail_mem;
248 : : }
249 : :
250 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_PRG_PKT_CNT; i++) {
251 : 0 : pf->fdir.prg_pkt[i] = (uint8_t *)mz->addr +
252 : 0 : I40E_FDIR_PKT_LEN * i;
253 : 0 : pf->fdir.dma_addr[i] = mz->iova +
254 : : I40E_FDIR_PKT_LEN * i;
255 : : }
256 : :
257 : 0 : pf->fdir.match_counter_index = I40E_COUNTER_INDEX_FDIR(hw->pf_id);
258 : 0 : pf->fdir.fdir_actual_cnt = 0;
259 : 0 : pf->fdir.fdir_guarantee_free_space =
260 : 0 : pf->fdir.fdir_guarantee_total_space;
261 : :
262 : 0 : PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
263 : : vsi->base_queue);
264 : 0 : return I40E_SUCCESS;
265 : :
266 : 0 : fail_mem:
267 : 0 : i40e_rx_queue_release(pf->fdir.rxq);
268 : 0 : pf->fdir.rxq = NULL;
269 : 0 : fail_setup_rx:
270 : 0 : i40e_tx_queue_release(pf->fdir.txq);
271 : 0 : pf->fdir.txq = NULL;
272 : 0 : fail_setup_tx:
273 : 0 : i40e_vsi_release(vsi);
274 : 0 : pf->fdir.fdir_vsi = NULL;
275 : 0 : return err;
276 : : }
277 : :
278 : : /*
279 : : * i40e_fdir_teardown - release the Flow Director resources
280 : : * @pf: board private structure
281 : : */
282 : : void
283 : 0 : i40e_fdir_teardown(struct i40e_pf *pf)
284 : : {
285 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
286 : : struct i40e_vsi *vsi;
287 : :
288 : 0 : vsi = pf->fdir.fdir_vsi;
289 [ # # ]: 0 : if (!vsi)
290 : : return;
291 : :
292 : : /* disable FDIR MSIX interrupt */
293 : 0 : i40e_vsi_queues_unbind_intr(vsi);
294 : 0 : i40e_vsi_disable_queues_intr(vsi);
295 : :
296 : 0 : int err = i40e_switch_tx_queue(hw, vsi->base_queue, FALSE);
297 [ # # ]: 0 : if (err)
298 : 0 : PMD_DRV_LOG(DEBUG, "Failed to do FDIR TX switch off");
299 : 0 : err = i40e_switch_rx_queue(hw, vsi->base_queue, FALSE);
300 [ # # ]: 0 : if (err)
301 : 0 : PMD_DRV_LOG(DEBUG, "Failed to do FDIR RX switch off");
302 : :
303 : 0 : i40e_rx_queue_release(pf->fdir.rxq);
304 : 0 : pf->fdir.rxq = NULL;
305 : 0 : i40e_tx_queue_release(pf->fdir.txq);
306 : 0 : pf->fdir.txq = NULL;
307 : 0 : i40e_vsi_release(vsi);
308 : 0 : pf->fdir.fdir_vsi = NULL;
309 : : }
310 : :
311 : : /* check whether the flow director table in empty */
312 : : static inline int
313 : : i40e_fdir_empty(struct i40e_hw *hw)
314 : : {
315 : : uint32_t guarant_cnt, best_cnt;
316 : :
317 : 0 : guarant_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
318 : : I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
319 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
320 : 0 : best_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
321 : 0 : I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
322 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
323 [ # # ]: 0 : if (best_cnt + guarant_cnt > 0)
324 : : return -1;
325 : :
326 : : return 0;
327 : : }
328 : :
329 : : /*
330 : : * Initialize the configuration about bytes stream extracted as flexible payload
331 : : * and mask setting
332 : : */
333 : : static inline void
334 : 0 : i40e_init_flx_pld(struct i40e_pf *pf)
335 : : {
336 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
337 : : uint8_t pctype;
338 : : int i, index;
339 : : uint16_t flow_type;
340 : :
341 : : /*
342 : : * Define the bytes stream extracted as flexible payload in
343 : : * field vector. By default, select 8 words from the beginning
344 : : * of payload as flexible payload.
345 : : */
346 [ # # ]: 0 : for (i = I40E_FLXPLD_L2_IDX; i < I40E_MAX_FLXPLD_LAYER; i++) {
347 : 0 : index = i * I40E_MAX_FLXPLD_FIED;
348 : 0 : pf->fdir.flex_set[index].src_offset = 0;
349 : 0 : pf->fdir.flex_set[index].size = I40E_FDIR_MAX_FLEXWORD_NUM;
350 : 0 : pf->fdir.flex_set[index].dst_offset = 0;
351 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(index), 0x0000C900);
352 : 0 : I40E_WRITE_REG(hw,
353 : : I40E_PRTQF_FLX_PIT(index + 1), 0x0000FC29);/*non-used*/
354 : 0 : I40E_WRITE_REG(hw,
355 : : I40E_PRTQF_FLX_PIT(index + 2), 0x0000FC2A);/*non-used*/
356 : 0 : pf->fdir.flex_pit_flag[i] = 0;
357 : : }
358 : :
359 : : /* initialize the masks */
360 : : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
361 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
362 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
363 : :
364 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
365 : 0 : continue;
366 : 0 : pf->fdir.flex_mask[pctype].word_mask = 0;
367 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), 0);
368 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_BITMASK_NUM_WORD; i++) {
369 : 0 : pf->fdir.flex_mask[pctype].bitmask[i].offset = 0;
370 : 0 : pf->fdir.flex_mask[pctype].bitmask[i].mask = 0;
371 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), 0);
372 : : }
373 : : }
374 : 0 : }
375 : :
376 : : /*
377 : : * Enable/disable flow director RX processing in vector routines.
378 : : */
379 : : void
380 : 0 : i40e_fdir_rx_proc_enable(struct rte_eth_dev *dev, bool on)
381 : : {
382 : : int32_t i;
383 : :
384 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
385 : 0 : struct i40e_rx_queue *rxq = dev->data->rx_queues[i];
386 [ # # ]: 0 : if (!rxq)
387 : 0 : continue;
388 : 0 : rxq->fdir_enabled = on;
389 : : }
390 : 0 : PMD_DRV_LOG(DEBUG, "Flow Director processing on RX set to %d", on);
391 : 0 : }
392 : :
393 : : /*
394 : : * Configure flow director related setting
395 : : */
396 : : int
397 : 0 : i40e_fdir_configure(struct rte_eth_dev *dev)
398 : : {
399 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
400 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
401 : : uint32_t val;
402 : : int ret = 0;
403 : :
404 : : /*
405 : : * configuration need to be done before
406 : : * flow director filters are added
407 : : * If filters exist, flush them.
408 : : */
409 : : if (i40e_fdir_empty(hw) < 0) {
410 : 0 : ret = i40e_fdir_flush(dev);
411 [ # # ]: 0 : if (ret) {
412 : 0 : PMD_DRV_LOG(ERR, "failed to flush fdir table.");
413 : 0 : return ret;
414 : : }
415 : : }
416 : :
417 : : /* enable FDIR filter */
418 : 0 : val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
419 : 0 : val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
420 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
421 : :
422 : 0 : i40e_init_flx_pld(pf); /* set flex config to default value */
423 : :
424 : : /* Enable FDIR processing in RX routines */
425 : 0 : i40e_fdir_rx_proc_enable(dev, 1);
426 : :
427 : 0 : return ret;
428 : : }
429 : :
430 : :
431 : : static struct i40e_customized_pctype *
432 : : i40e_flow_fdir_find_customized_pctype(struct i40e_pf *pf, uint8_t pctype)
433 : : {
434 : : struct i40e_customized_pctype *cus_pctype;
435 : : enum i40e_new_pctype i = I40E_CUSTOMIZED_GTPC;
436 : :
437 [ # # # # ]: 0 : for (; i < I40E_CUSTOMIZED_MAX; i++) {
438 : 0 : cus_pctype = &pf->customized_pctype[i];
439 [ # # # # ]: 0 : if (pctype == cus_pctype->pctype)
440 : : return cus_pctype;
441 : : }
442 : : return NULL;
443 : : }
444 : :
445 : : static inline int
446 : 0 : fill_ip6_head(const struct i40e_fdir_input *fdir_input, unsigned char *raw_pkt,
447 : : uint8_t next_proto, uint8_t len, uint16_t *ether_type)
448 : : {
449 : : struct rte_ipv6_hdr *ip6;
450 : :
451 : : ip6 = (struct rte_ipv6_hdr *)raw_pkt;
452 : :
453 : 0 : *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
454 [ # # ]: 0 : ip6->vtc_flow = rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
455 : : (fdir_input->flow.ipv6_flow.tc << I40E_FDIR_IPv6_TC_OFFSET));
456 : 0 : ip6->payload_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
457 [ # # ]: 0 : ip6->proto = fdir_input->flow.ipv6_flow.proto ?
458 : : fdir_input->flow.ipv6_flow.proto : next_proto;
459 [ # # ]: 0 : ip6->hop_limits = fdir_input->flow.ipv6_flow.hop_limits ?
460 : : fdir_input->flow.ipv6_flow.hop_limits :
461 : : I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
462 : : /**
463 : : * The source and destination fields in the transmitted packet
464 : : * need to be presented in a reversed order with respect
465 : : * to the expected received packets.
466 : : */
467 [ # # ]: 0 : rte_memcpy(&ip6->src_addr, &fdir_input->flow.ipv6_flow.dst_ip,
468 : : IPV6_ADDR_LEN);
469 [ # # ]: 0 : rte_memcpy(&ip6->dst_addr, &fdir_input->flow.ipv6_flow.src_ip,
470 : : IPV6_ADDR_LEN);
471 : 0 : len += sizeof(struct rte_ipv6_hdr);
472 : :
473 : 0 : return len;
474 : : }
475 : :
476 : : static inline int
477 : : fill_ip4_head(const struct i40e_fdir_input *fdir_input, unsigned char *raw_pkt,
478 : : uint8_t next_proto, uint8_t len, uint16_t *ether_type)
479 : : {
480 : : struct rte_ipv4_hdr *ip4;
481 : :
482 : : ip4 = (struct rte_ipv4_hdr *)raw_pkt;
483 : :
484 : 0 : *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
485 : 0 : ip4->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
486 : : /* set len to by default */
487 : 0 : ip4->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
488 [ # # # # : 0 : ip4->time_to_live = fdir_input->flow.ip4_flow.ttl ?
# # # # ]
489 : : fdir_input->flow.ip4_flow.ttl :
490 : : I40E_FDIR_IP_DEFAULT_TTL;
491 : 0 : ip4->type_of_service = fdir_input->flow.ip4_flow.tos;
492 [ # # # # : 0 : ip4->next_proto_id = fdir_input->flow.ip4_flow.proto ?
# # # # #
# ]
493 : : fdir_input->flow.ip4_flow.proto : next_proto;
494 : : /**
495 : : * The source and destination fields in the transmitted packet
496 : : * need to be presented in a reversed order with respect
497 : : * to the expected received packets.
498 : : */
499 : 0 : ip4->src_addr = fdir_input->flow.ip4_flow.dst_ip;
500 : 0 : ip4->dst_addr = fdir_input->flow.ip4_flow.src_ip;
501 : 0 : len += sizeof(struct rte_ipv4_hdr);
502 : :
503 : : return len;
504 : : }
505 : :
506 : : static inline int
507 : 0 : i40e_flow_fdir_fill_eth_ip_head(struct i40e_pf *pf,
508 : : const struct i40e_fdir_input *fdir_input,
509 : : unsigned char *raw_pkt,
510 : : bool vlan)
511 : : {
512 : : struct i40e_customized_pctype *cus_pctype = NULL;
513 : : static uint8_t vlan_frame[] = {0x81, 0, 0, 0};
514 : : uint16_t *ether_type;
515 : : uint8_t len = 2 * sizeof(struct rte_ether_addr);
516 : 0 : uint8_t pctype = fdir_input->pctype;
517 : 0 : bool is_customized_pctype = fdir_input->flow_ext.customized_pctype;
518 : : static const uint8_t next_proto[] = {
519 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] = IPPROTO_IP,
520 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] = IPPROTO_TCP,
521 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] = IPPROTO_UDP,
522 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] = IPPROTO_SCTP,
523 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] = IPPROTO_IP,
524 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] = IPPROTO_NONE,
525 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] = IPPROTO_TCP,
526 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] = IPPROTO_UDP,
527 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] = IPPROTO_SCTP,
528 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] = IPPROTO_NONE,
529 : : };
530 : :
531 [ # # ]: 0 : rte_memcpy(raw_pkt, &fdir_input->flow.l2_flow.dst,
532 : : sizeof(struct rte_ether_addr));
533 : 0 : rte_memcpy(raw_pkt + sizeof(struct rte_ether_addr),
534 [ # # ]: 0 : &fdir_input->flow.l2_flow.src,
535 : : sizeof(struct rte_ether_addr));
536 : 0 : raw_pkt += 2 * sizeof(struct rte_ether_addr);
537 : :
538 [ # # # # ]: 0 : if (vlan && fdir_input->flow_ext.vlan_tci) {
539 : : rte_memcpy(raw_pkt, vlan_frame, sizeof(vlan_frame));
540 : 0 : rte_memcpy(raw_pkt + sizeof(uint16_t),
541 [ # # ]: 0 : &fdir_input->flow_ext.vlan_tci,
542 : : sizeof(uint16_t));
543 : 0 : raw_pkt += sizeof(vlan_frame);
544 : : len += sizeof(vlan_frame);
545 : : }
546 : : ether_type = (uint16_t *)raw_pkt;
547 : 0 : raw_pkt += sizeof(uint16_t);
548 : 0 : len += sizeof(uint16_t);
549 : :
550 [ # # ]: 0 : if (is_customized_pctype) {
551 : : cus_pctype = i40e_flow_fdir_find_customized_pctype(pf, pctype);
552 [ # # ]: 0 : if (!cus_pctype) {
553 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.",
554 : : fdir_input->pctype);
555 : 0 : return -1;
556 : : }
557 : : }
558 : :
559 [ # # ]: 0 : if (pctype == I40E_FILTER_PCTYPE_L2_PAYLOAD)
560 : 0 : *ether_type = fdir_input->flow.l2_flow.ether_type;
561 : 0 : else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP ||
562 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP ||
563 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP ||
564 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
565 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV4 ||
566 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP ||
567 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP ||
568 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP ||
569 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
570 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_FRAG_IPV6 ||
571 : : is_customized_pctype) {
572 [ # # ]: 0 : if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP ||
573 : : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP ||
574 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP ||
575 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
576 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV4) {
577 : 0 : len = fill_ip4_head(fdir_input, raw_pkt,
578 [ # # ]: 0 : next_proto[pctype], len, ether_type);
579 : 0 : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP ||
580 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP ||
581 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP ||
582 [ # # ]: 0 : pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
583 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV6) {
584 : 0 : len = fill_ip6_head(fdir_input, raw_pkt,
585 : 0 : next_proto[pctype], len,
586 : : ether_type);
587 [ # # ]: 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_GTPC ||
588 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4 ||
589 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6 ||
590 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU) {
591 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_UDP,
592 : : len, ether_type);
593 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3) {
594 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_L2TP,
595 : : len, ether_type);
596 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4) {
597 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_ESP,
598 : : len, ether_type);
599 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4_UDP) {
600 : : len = fill_ip4_head(fdir_input, raw_pkt, IPPROTO_UDP,
601 : : len, ether_type);
602 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6) {
603 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_ESP,
604 : : len, ether_type);
605 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP) {
606 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_UDP,
607 : : len, ether_type);
608 : : } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3) {
609 : 0 : len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_L2TP,
610 : : len, ether_type);
611 : : }
612 : : } else {
613 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
614 : 0 : return -1;
615 : : }
616 : :
617 : 0 : return len;
618 : : }
619 : :
620 : : /**
621 : : * i40e_flow_fdir_construct_pkt - construct packet based on fields in input
622 : : * @pf: board private structure
623 : : * @fdir_input: input set of the flow director entry
624 : : * @raw_pkt: a packet to be constructed
625 : : */
626 : : static int
627 : 0 : i40e_flow_fdir_construct_pkt(struct i40e_pf *pf,
628 : : const struct i40e_fdir_input *fdir_input,
629 : : unsigned char *raw_pkt)
630 : : {
631 : : unsigned char *payload = NULL;
632 : : unsigned char *ptr;
633 : : struct rte_udp_hdr *udp;
634 : : struct rte_tcp_hdr *tcp;
635 : : struct rte_sctp_hdr *sctp;
636 : : struct rte_flow_item_gtp *gtp;
637 : : struct rte_ipv4_hdr *gtp_ipv4;
638 : : struct rte_ipv6_hdr *gtp_ipv6;
639 : : struct rte_flow_item_l2tpv3oip *l2tpv3oip;
640 : : struct rte_flow_item_esp *esp;
641 : : struct rte_ipv4_hdr *esp_ipv4;
642 : : struct rte_ipv6_hdr *esp_ipv6;
643 : :
644 : : uint8_t size, dst = 0;
645 : : uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
646 : : int len;
647 : 0 : uint8_t pctype = fdir_input->pctype;
648 : : struct i40e_customized_pctype *cus_pctype;
649 : :
650 : : /* raw packet template - just copy contents of the raw packet */
651 [ # # ]: 0 : if (fdir_input->flow_ext.pkt_template) {
652 : 0 : memcpy(raw_pkt, fdir_input->flow.raw_flow.packet,
653 : 0 : fdir_input->flow.raw_flow.length);
654 : 0 : return 0;
655 : : }
656 : :
657 : : /* fill the ethernet and IP head */
658 : 0 : len = i40e_flow_fdir_fill_eth_ip_head(pf, fdir_input, raw_pkt,
659 : 0 : !!fdir_input->flow_ext.vlan_tci);
660 [ # # ]: 0 : if (len < 0)
661 : : return -EINVAL;
662 : :
663 : : /* fill the L4 head */
664 : : if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP) {
665 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
666 : 0 : payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
667 : : /**
668 : : * The source and destination fields in the transmitted packet
669 : : * need to be presented in a reversed order with respect
670 : : * to the expected received packets.
671 : : */
672 : 0 : udp->src_port = fdir_input->flow.udp4_flow.dst_port;
673 : 0 : udp->dst_port = fdir_input->flow.udp4_flow.src_port;
674 : 0 : udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
675 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP) {
676 : 0 : tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
677 : 0 : payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
678 : : /**
679 : : * The source and destination fields in the transmitted packet
680 : : * need to be presented in a reversed order with respect
681 : : * to the expected received packets.
682 : : */
683 : 0 : tcp->src_port = fdir_input->flow.tcp4_flow.dst_port;
684 : 0 : tcp->dst_port = fdir_input->flow.tcp4_flow.src_port;
685 : 0 : tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
686 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) {
687 : 0 : sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
688 : 0 : payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
689 : : /**
690 : : * The source and destination fields in the transmitted packet
691 : : * need to be presented in a reversed order with respect
692 : : * to the expected received packets.
693 : : */
694 : 0 : sctp->src_port = fdir_input->flow.sctp4_flow.dst_port;
695 : 0 : sctp->dst_port = fdir_input->flow.sctp4_flow.src_port;
696 : 0 : sctp->tag = fdir_input->flow.sctp4_flow.verify_tag;
697 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
698 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV4) {
699 : 0 : payload = raw_pkt + len;
700 : : set_idx = I40E_FLXPLD_L3_IDX;
701 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP) {
702 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
703 : 0 : payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
704 : : /**
705 : : * The source and destination fields in the transmitted packet
706 : : * need to be presented in a reversed order with respect
707 : : * to the expected received packets.
708 : : */
709 : 0 : udp->src_port = fdir_input->flow.udp6_flow.dst_port;
710 : 0 : udp->dst_port = fdir_input->flow.udp6_flow.src_port;
711 : 0 : udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
712 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP) {
713 : 0 : tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
714 : 0 : payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
715 : : /**
716 : : * The source and destination fields in the transmitted packet
717 : : * need to be presented in a reversed order with respect
718 : : * to the expected received packets.
719 : : */
720 : 0 : tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
721 : 0 : tcp->src_port = fdir_input->flow.udp6_flow.dst_port;
722 : 0 : tcp->dst_port = fdir_input->flow.udp6_flow.src_port;
723 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) {
724 : 0 : sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
725 : 0 : payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
726 : : /**
727 : : * The source and destination fields in the transmitted packet
728 : : * need to be presented in a reversed order with respect
729 : : * to the expected received packets.
730 : : */
731 : 0 : sctp->src_port = fdir_input->flow.sctp6_flow.dst_port;
732 : 0 : sctp->dst_port = fdir_input->flow.sctp6_flow.src_port;
733 : 0 : sctp->tag = fdir_input->flow.sctp6_flow.verify_tag;
734 : : } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
735 : : pctype == I40E_FILTER_PCTYPE_FRAG_IPV6) {
736 : 0 : payload = raw_pkt + len;
737 : : set_idx = I40E_FLXPLD_L3_IDX;
738 : : } else if (pctype == I40E_FILTER_PCTYPE_L2_PAYLOAD) {
739 : 0 : payload = raw_pkt + len;
740 : : /**
741 : : * ARP packet is a special case on which the payload
742 : : * starts after the whole ARP header
743 : : */
744 [ # # ]: 0 : if (fdir_input->flow.l2_flow.ether_type ==
745 : : rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP))
746 : 0 : payload += sizeof(struct rte_arp_hdr);
747 : : set_idx = I40E_FLXPLD_L2_IDX;
748 [ # # ]: 0 : } else if (fdir_input->flow_ext.customized_pctype) {
749 : : /* If customized pctype is used */
750 : : cus_pctype = i40e_flow_fdir_find_customized_pctype(pf, pctype);
751 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPC ||
752 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4 ||
753 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6 ||
754 : : cus_pctype->index == I40E_CUSTOMIZED_GTPU) {
755 : 0 : udp = (struct rte_udp_hdr *)(raw_pkt + len);
756 : 0 : udp->dgram_len =
757 : : rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
758 : :
759 : : gtp = (struct rte_flow_item_gtp *)
760 : : ((unsigned char *)udp +
761 : : sizeof(struct rte_udp_hdr));
762 : 0 : gtp->hdr.plen =
763 : : rte_cpu_to_be_16(I40E_FDIR_GTP_DEFAULT_LEN);
764 : 0 : gtp->hdr.teid = fdir_input->flow.gtp_flow.teid;
765 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0X01;
766 : :
767 : : /* GTP-C message type is not supported. */
768 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPC) {
769 : 0 : udp->dst_port =
770 : : rte_cpu_to_be_16(I40E_FDIR_GTPC_DST_PORT);
771 : 0 : gtp->hdr.gtp_hdr_info =
772 : : I40E_FDIR_GTP_VER_FLAG_0X32;
773 : : } else {
774 : 0 : udp->dst_port =
775 : : rte_cpu_to_be_16(I40E_FDIR_GTPU_DST_PORT);
776 : 0 : gtp->hdr.gtp_hdr_info =
777 : : I40E_FDIR_GTP_VER_FLAG_0X30;
778 : : }
779 : :
780 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4) {
781 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
782 : : gtp_ipv4 = (struct rte_ipv4_hdr *)
783 : : ((unsigned char *)gtp +
784 : : sizeof(struct rte_flow_item_gtp));
785 : 0 : gtp_ipv4->version_ihl =
786 : : I40E_FDIR_IP_DEFAULT_VERSION_IHL;
787 : 0 : gtp_ipv4->next_proto_id = IPPROTO_IP;
788 : 0 : gtp_ipv4->total_length =
789 : : rte_cpu_to_be_16(
790 : : I40E_FDIR_INNER_IP_DEFAULT_LEN);
791 : 0 : payload = (unsigned char *)gtp_ipv4 +
792 : : sizeof(struct rte_ipv4_hdr);
793 [ # # ]: 0 : } else if (cus_pctype->index ==
794 : : I40E_CUSTOMIZED_GTPU_IPV6) {
795 : 0 : gtp->hdr.msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
796 : : gtp_ipv6 = (struct rte_ipv6_hdr *)
797 : : ((unsigned char *)gtp +
798 : : sizeof(struct rte_flow_item_gtp));
799 : 0 : gtp_ipv6->vtc_flow =
800 : : rte_cpu_to_be_32(
801 : : I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
802 : : (0 << I40E_FDIR_IPv6_TC_OFFSET));
803 : 0 : gtp_ipv6->proto = IPPROTO_NONE;
804 : 0 : gtp_ipv6->payload_len =
805 : : rte_cpu_to_be_16(
806 : : I40E_FDIR_INNER_IPV6_DEFAULT_LEN);
807 : 0 : gtp_ipv6->hop_limits =
808 : : I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
809 : 0 : payload = (unsigned char *)gtp_ipv6 +
810 : : sizeof(struct rte_ipv6_hdr);
811 : : } else
812 : 0 : payload = (unsigned char *)gtp +
813 : : sizeof(struct rte_flow_item_gtp);
814 [ # # ]: 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3 ||
815 : : cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3) {
816 : 0 : l2tpv3oip = (struct rte_flow_item_l2tpv3oip *)(raw_pkt
817 : 0 : + len);
818 : :
819 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3)
820 : 0 : l2tpv3oip->session_id =
821 : 0 : fdir_input->flow.ip4_l2tpv3oip_flow.session_id;
822 : : else
823 : 0 : l2tpv3oip->session_id =
824 : 0 : fdir_input->flow.ip6_l2tpv3oip_flow.session_id;
825 : 0 : payload = (unsigned char *)l2tpv3oip +
826 : : sizeof(struct rte_flow_item_l2tpv3oip);
827 : 0 : } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4 ||
828 : : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6 ||
829 [ # # ]: 0 : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4_UDP ||
830 : : cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP) {
831 [ # # ]: 0 : if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4) {
832 : 0 : esp_ipv4 = (struct rte_ipv4_hdr *)
833 : 0 : (raw_pkt + len);
834 : : esp = (struct rte_flow_item_esp *)esp_ipv4;
835 : 0 : esp->hdr.spi =
836 : 0 : fdir_input->flow.esp_ipv4_flow.spi;
837 : 0 : payload = (unsigned char *)esp +
838 : : sizeof(struct rte_esp_hdr);
839 : : len += sizeof(struct rte_esp_hdr);
840 [ # # ]: 0 : } else if (cus_pctype->index ==
841 : : I40E_CUSTOMIZED_ESP_IPV4_UDP) {
842 : 0 : esp_ipv4 = (struct rte_ipv4_hdr *)
843 : 0 : (raw_pkt + len);
844 : : udp = (struct rte_udp_hdr *)esp_ipv4;
845 : 0 : udp->dst_port = rte_cpu_to_be_16
846 : : (I40E_FDIR_ESP_DST_PORT);
847 : :
848 : 0 : udp->dgram_len = rte_cpu_to_be_16
849 : : (I40E_FDIR_UDP_DEFAULT_LEN);
850 : : esp = (struct rte_flow_item_esp *)
851 : : ((unsigned char *)esp_ipv4 +
852 : : sizeof(struct rte_udp_hdr));
853 : 0 : esp->hdr.spi =
854 : 0 : fdir_input->flow.esp_ipv4_udp_flow.spi;
855 : 0 : payload = (unsigned char *)esp +
856 : : sizeof(struct rte_esp_hdr);
857 : : len += sizeof(struct rte_udp_hdr) +
858 : : sizeof(struct rte_esp_hdr);
859 [ # # ]: 0 : } else if (cus_pctype->index ==
860 : : I40E_CUSTOMIZED_ESP_IPV6) {
861 : 0 : esp_ipv6 = (struct rte_ipv6_hdr *)
862 : 0 : (raw_pkt + len);
863 : : esp = (struct rte_flow_item_esp *)esp_ipv6;
864 : 0 : esp->hdr.spi =
865 : 0 : fdir_input->flow.esp_ipv6_flow.spi;
866 : 0 : payload = (unsigned char *)esp +
867 : : sizeof(struct rte_esp_hdr);
868 : : len += sizeof(struct rte_esp_hdr);
869 : : } else if (cus_pctype->index ==
870 : : I40E_CUSTOMIZED_ESP_IPV6_UDP) {
871 : 0 : esp_ipv6 = (struct rte_ipv6_hdr *)
872 : 0 : (raw_pkt + len);
873 : : udp = (struct rte_udp_hdr *)esp_ipv6;
874 : 0 : udp->dst_port = rte_cpu_to_be_16
875 : : (I40E_FDIR_ESP_DST_PORT);
876 : :
877 : 0 : udp->dgram_len = rte_cpu_to_be_16
878 : : (I40E_FDIR_UDP_DEFAULT_LEN);
879 : : esp = (struct rte_flow_item_esp *)
880 : : ((unsigned char *)esp_ipv6 +
881 : : sizeof(struct rte_udp_hdr));
882 : 0 : esp->hdr.spi =
883 : 0 : fdir_input->flow.esp_ipv6_udp_flow.spi;
884 : 0 : payload = (unsigned char *)esp +
885 : : sizeof(struct rte_esp_hdr);
886 : : len += sizeof(struct rte_udp_hdr) +
887 : : sizeof(struct rte_esp_hdr);
888 : : }
889 : : }
890 : : } else {
891 : 0 : PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
892 : 0 : return -1;
893 : : }
894 : :
895 : : /* fill the flexbytes to payload */
896 [ # # ]: 0 : for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
897 : 0 : pit_idx = set_idx * I40E_MAX_FLXPLD_FIED + i;
898 : 0 : size = pf->fdir.flex_set[pit_idx].size;
899 [ # # ]: 0 : if (size == 0)
900 : 0 : continue;
901 : 0 : dst = pf->fdir.flex_set[pit_idx].dst_offset * sizeof(uint16_t);
902 : 0 : ptr = payload +
903 : 0 : pf->fdir.flex_set[pit_idx].src_offset * sizeof(uint16_t);
904 : 0 : (void)rte_memcpy(ptr,
905 [ # # ]: 0 : &fdir_input->flow_ext.flexbytes[dst],
906 : : size * sizeof(uint16_t));
907 : : }
908 : :
909 : : return 0;
910 : : }
911 : :
912 : : /* Construct the tx flags */
913 : : static inline uint64_t
914 : : i40e_build_ctob(uint32_t td_cmd,
915 : : uint32_t td_offset,
916 : : unsigned int size,
917 : : uint32_t td_tag)
918 : : {
919 : : return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
920 : : ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
921 : : ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
922 : : ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
923 : : ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
924 : : }
925 : :
926 : : /*
927 : : * check the programming status descriptor in rx queue.
928 : : * done after Programming Flow Director is programmed on
929 : : * tx queue
930 : : */
931 : : static inline int
932 : 0 : i40e_check_fdir_programming_status(struct i40e_rx_queue *rxq)
933 : : {
934 : : volatile union i40e_rx_desc *rxdp;
935 : : uint64_t qword1;
936 : : uint32_t rx_status;
937 : : uint32_t len, id;
938 : : uint32_t error;
939 : : int ret = 0;
940 : :
941 : 0 : rxdp = &rxq->rx_ring[rxq->rx_tail];
942 : 0 : qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
943 : : rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
944 : 0 : >> I40E_RXD_QW1_STATUS_SHIFT;
945 : :
946 [ # # ]: 0 : if (rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
947 : 0 : len = qword1 >> I40E_RX_PROG_STATUS_DESC_LENGTH_SHIFT;
948 : 0 : id = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >>
949 : : I40E_RX_PROG_STATUS_DESC_QW1_PROGID_SHIFT;
950 : :
951 : 0 : if (len == I40E_RX_PROG_STATUS_DESC_LENGTH &&
952 [ # # ]: 0 : id == I40E_RX_PROG_STATUS_DESC_FD_FILTER_STATUS) {
953 : 0 : error = (qword1 &
954 : 0 : I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
955 : : I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
956 [ # # ]: 0 : if (error == (0x1 <<
957 : : I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
958 : 0 : PMD_DRV_LOG(ERR, "Failed to add FDIR filter"
959 : : " (FD_ID %u): programming status"
960 : : " reported.",
961 : : rxdp->wb.qword0.hi_dword.fd_id);
962 : : ret = -1;
963 [ # # ]: 0 : } else if (error == (0x1 <<
964 : : I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
965 : 0 : PMD_DRV_LOG(ERR, "Failed to delete FDIR filter"
966 : : " (FD_ID %u): programming status"
967 : : " reported.",
968 : : rxdp->wb.qword0.hi_dword.fd_id);
969 : : ret = -1;
970 : : } else
971 : 0 : PMD_DRV_LOG(ERR, "invalid programming status"
972 : : " reported, error = %u.", error);
973 : : } else
974 : 0 : PMD_DRV_LOG(INFO, "unknown programming status"
975 : : " reported, len = %d, id = %u.", len, id);
976 : 0 : rxdp->wb.qword1.status_error_len = 0;
977 : 0 : rxq->rx_tail++;
978 [ # # ]: 0 : if (unlikely(rxq->rx_tail == rxq->nb_rx_desc))
979 : 0 : rxq->rx_tail = 0;
980 [ # # ]: 0 : if (rxq->rx_tail == 0)
981 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
982 : : else
983 : 0 : I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_tail - 1);
984 : : }
985 : :
986 : 0 : return ret;
987 : : }
988 : :
989 : : static inline void
990 : 0 : i40e_fdir_programming_status_cleanup(struct i40e_rx_queue *rxq)
991 : : {
992 : : uint16_t retry_count = 0;
993 : :
994 : : /* capture the previous error report(if any) from rx ring */
995 [ # # # # ]: 0 : while ((i40e_check_fdir_programming_status(rxq) < 0) &&
996 : : (++retry_count < I40E_FDIR_NUM_RX_DESC))
997 : 0 : PMD_DRV_LOG(INFO, "error report captured.");
998 : 0 : }
999 : :
1000 : : static int
1001 : 0 : i40e_fdir_filter_convert(const struct i40e_fdir_filter_conf *input,
1002 : : struct i40e_fdir_filter *filter)
1003 : : {
1004 [ # # ]: 0 : rte_memcpy(&filter->fdir, input, sizeof(struct i40e_fdir_filter_conf));
1005 [ # # ]: 0 : if (input->input.flow_ext.pkt_template) {
1006 : 0 : filter->fdir.input.flow.raw_flow.packet = NULL;
1007 : 0 : filter->fdir.input.flow.raw_flow.length =
1008 : 0 : rte_hash_crc(input->input.flow.raw_flow.packet,
1009 : 0 : input->input.flow.raw_flow.length,
1010 : 0 : input->input.flow.raw_flow.pctype);
1011 : : }
1012 : 0 : return 0;
1013 : : }
1014 : :
1015 : : /* Check if there exists the flow director filter */
1016 : : static struct i40e_fdir_filter *
1017 : 0 : i40e_sw_fdir_filter_lookup(struct i40e_fdir_info *fdir_info,
1018 : : const struct i40e_fdir_input *input)
1019 : : {
1020 : : int ret;
1021 : :
1022 [ # # ]: 0 : if (input->flow_ext.pkt_template)
1023 : 0 : ret = rte_hash_lookup_with_hash(fdir_info->hash_table,
1024 : : (const void *)input,
1025 : 0 : input->flow.raw_flow.length);
1026 : : else
1027 : 0 : ret = rte_hash_lookup(fdir_info->hash_table,
1028 : : (const void *)input);
1029 [ # # ]: 0 : if (ret < 0)
1030 : : return NULL;
1031 : :
1032 : 0 : return fdir_info->hash_map[ret];
1033 : : }
1034 : :
1035 : : /* Add a flow director filter into the SW list */
1036 : : static int
1037 : 0 : i40e_sw_fdir_filter_insert(struct i40e_pf *pf, struct i40e_fdir_filter *filter)
1038 : : {
1039 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1040 : : struct i40e_fdir_filter *hash_filter;
1041 : : int ret;
1042 : :
1043 [ # # ]: 0 : if (filter->fdir.input.flow_ext.pkt_template)
1044 : 0 : ret = rte_hash_add_key_with_hash(fdir_info->hash_table,
1045 : 0 : &filter->fdir.input,
1046 : : filter->fdir.input.flow.raw_flow.length);
1047 : : else
1048 : 0 : ret = rte_hash_add_key(fdir_info->hash_table,
1049 : 0 : &filter->fdir.input);
1050 [ # # ]: 0 : if (ret < 0) {
1051 : 0 : PMD_DRV_LOG(ERR,
1052 : : "Failed to insert fdir filter to hash table %d!",
1053 : : ret);
1054 : 0 : return ret;
1055 : : }
1056 : :
1057 [ # # ]: 0 : if (fdir_info->hash_map[ret])
1058 : : return -1;
1059 : :
1060 [ # # ]: 0 : hash_filter = &fdir_info->fdir_filter_array[ret];
1061 : : rte_memcpy(hash_filter, filter, sizeof(*filter));
1062 : 0 : fdir_info->hash_map[ret] = hash_filter;
1063 : 0 : TAILQ_INSERT_TAIL(&fdir_info->fdir_list, hash_filter, rules);
1064 : :
1065 : 0 : return 0;
1066 : : }
1067 : :
1068 : : /* Delete a flow director filter from the SW list */
1069 : : int
1070 : 0 : i40e_sw_fdir_filter_del(struct i40e_pf *pf, struct i40e_fdir_input *input)
1071 : : {
1072 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1073 : : struct i40e_fdir_filter *filter;
1074 : : int ret;
1075 : :
1076 [ # # ]: 0 : if (input->flow_ext.pkt_template)
1077 : 0 : ret = rte_hash_del_key_with_hash(fdir_info->hash_table,
1078 : : input,
1079 : : input->flow.raw_flow.length);
1080 : : else
1081 : 0 : ret = rte_hash_del_key(fdir_info->hash_table, input);
1082 [ # # ]: 0 : if (ret < 0) {
1083 : 0 : PMD_DRV_LOG(ERR,
1084 : : "Failed to delete fdir filter to hash table %d!",
1085 : : ret);
1086 : 0 : return ret;
1087 : : }
1088 : 0 : filter = fdir_info->hash_map[ret];
1089 : 0 : fdir_info->hash_map[ret] = NULL;
1090 : :
1091 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, filter, rules);
1092 : :
1093 : 0 : return 0;
1094 : : }
1095 : :
1096 : : struct rte_flow *
1097 : 0 : i40e_fdir_entry_pool_get(struct i40e_fdir_info *fdir_info)
1098 : : {
1099 : : struct rte_flow *flow = NULL;
1100 : 0 : uint64_t slab = 0;
1101 : 0 : uint32_t pos = 0;
1102 : : uint32_t i = 0;
1103 : : int ret;
1104 : :
1105 : 0 : if (fdir_info->fdir_actual_cnt >=
1106 [ # # ]: 0 : fdir_info->fdir_space_size) {
1107 : 0 : PMD_DRV_LOG(ERR, "Fdir space full");
1108 : 0 : return NULL;
1109 : : }
1110 : :
1111 : 0 : ret = rte_bitmap_scan(fdir_info->fdir_flow_pool.bitmap, &pos,
1112 : : &slab);
1113 : :
1114 : : /* normally this won't happen as the fdir_actual_cnt should be
1115 : : * same with the number of the set bits in fdir_flow_pool,
1116 : : * but anyway handle this error condition here for safe
1117 : : */
1118 [ # # ]: 0 : if (ret == 0) {
1119 : 0 : PMD_DRV_LOG(ERR, "fdir_actual_cnt out of sync");
1120 : 0 : return NULL;
1121 : : }
1122 : :
1123 : 0 : i = rte_bsf64(slab);
1124 : 0 : pos += i;
1125 : 0 : rte_bitmap_clear(fdir_info->fdir_flow_pool.bitmap, pos);
1126 : 0 : flow = &fdir_info->fdir_flow_pool.pool[pos].flow;
1127 : :
1128 : : memset(flow, 0, sizeof(struct rte_flow));
1129 : :
1130 : 0 : return flow;
1131 : : }
1132 : :
1133 : : void
1134 : 0 : i40e_fdir_entry_pool_put(struct i40e_fdir_info *fdir_info,
1135 : : struct rte_flow *flow)
1136 : : {
1137 : : struct i40e_fdir_entry *f;
1138 : :
1139 : : f = FLOW_TO_FLOW_BITMAP(flow);
1140 : 0 : rte_bitmap_set(fdir_info->fdir_flow_pool.bitmap, f->idx);
1141 : 0 : }
1142 : :
1143 : : static int
1144 : 0 : i40e_flow_store_flex_pit(struct i40e_pf *pf,
1145 : : struct i40e_fdir_flex_pit *flex_pit,
1146 : : enum i40e_flxpld_layer_idx layer_idx,
1147 : : uint8_t raw_id)
1148 : : {
1149 : : uint8_t field_idx;
1150 : :
1151 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + raw_id;
1152 : : /* Check if the configuration is conflicted */
1153 [ # # ]: 0 : if (pf->fdir.flex_pit_flag[layer_idx] &&
1154 [ # # ]: 0 : (pf->fdir.flex_set[field_idx].src_offset != flex_pit->src_offset ||
1155 [ # # ]: 0 : pf->fdir.flex_set[field_idx].size != flex_pit->size ||
1156 [ # # ]: 0 : pf->fdir.flex_set[field_idx].dst_offset != flex_pit->dst_offset))
1157 : : return -1;
1158 : :
1159 : : /* Check if the configuration exists. */
1160 [ # # ]: 0 : if (pf->fdir.flex_pit_flag[layer_idx] &&
1161 [ # # ]: 0 : (pf->fdir.flex_set[field_idx].src_offset == flex_pit->src_offset &&
1162 [ # # ]: 0 : pf->fdir.flex_set[field_idx].size == flex_pit->size &&
1163 [ # # ]: 0 : pf->fdir.flex_set[field_idx].dst_offset == flex_pit->dst_offset))
1164 : : return 1;
1165 : :
1166 : 0 : pf->fdir.flex_set[field_idx].src_offset =
1167 : 0 : flex_pit->src_offset;
1168 : 0 : pf->fdir.flex_set[field_idx].size =
1169 : 0 : flex_pit->size;
1170 : 0 : pf->fdir.flex_set[field_idx].dst_offset =
1171 : 0 : flex_pit->dst_offset;
1172 : :
1173 : 0 : return 0;
1174 : : }
1175 : :
1176 : : static void
1177 : 0 : i40e_flow_set_fdir_flex_pit(struct i40e_pf *pf,
1178 : : enum i40e_flxpld_layer_idx layer_idx,
1179 : : uint8_t raw_id)
1180 : : {
1181 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1182 : : uint32_t flx_pit, flx_ort;
1183 : : uint16_t min_next_off = 0;
1184 : : uint8_t field_idx;
1185 : : uint8_t i;
1186 : :
1187 [ # # ]: 0 : if (raw_id) {
1188 : 0 : flx_ort = (1 << I40E_GLQF_ORT_FLX_PAYLOAD_SHIFT) |
1189 : 0 : (raw_id << I40E_GLQF_ORT_FIELD_CNT_SHIFT) |
1190 : 0 : (layer_idx * I40E_MAX_FLXPLD_FIED);
1191 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33 + layer_idx), flx_ort);
1192 : : }
1193 : :
1194 : : /* Set flex pit */
1195 [ # # ]: 0 : for (i = 0; i < raw_id; i++) {
1196 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1197 [ # # ]: 0 : flx_pit = MK_FLX_PIT(pf->fdir.flex_set[field_idx].src_offset,
1198 : : pf->fdir.flex_set[field_idx].size,
1199 : : pf->fdir.flex_set[field_idx].dst_offset);
1200 : :
1201 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
1202 : 0 : min_next_off = pf->fdir.flex_set[field_idx].src_offset +
1203 : 0 : pf->fdir.flex_set[field_idx].size;
1204 : : }
1205 : :
1206 [ # # ]: 0 : for (; i < I40E_MAX_FLXPLD_FIED; i++) {
1207 : : /* set the non-used register obeying register's constrain */
1208 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1209 : 0 : flx_pit = MK_FLX_PIT(min_next_off, NONUSE_FLX_PIT_FSIZE,
1210 : : NONUSE_FLX_PIT_DEST_OFF);
1211 : 0 : I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
1212 : 0 : min_next_off++;
1213 : : }
1214 : 0 : }
1215 : :
1216 : : static int
1217 : 0 : i40e_flow_store_flex_mask(struct i40e_pf *pf,
1218 : : enum i40e_filter_pctype pctype,
1219 : : uint8_t *mask)
1220 : : {
1221 : : struct i40e_fdir_flex_mask flex_mask;
1222 : : uint8_t nb_bitmask = 0;
1223 : : uint16_t mask_tmp;
1224 : : uint8_t i;
1225 : :
1226 : : memset(&flex_mask, 0, sizeof(struct i40e_fdir_flex_mask));
1227 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i += sizeof(uint16_t)) {
1228 : 0 : mask_tmp = I40E_WORD(mask[i], mask[i + 1]);
1229 [ # # ]: 0 : if (mask_tmp) {
1230 : 0 : flex_mask.word_mask |=
1231 : 0 : I40E_FLEX_WORD_MASK(i / sizeof(uint16_t));
1232 [ # # ]: 0 : if (mask_tmp != UINT16_MAX) {
1233 : 0 : flex_mask.bitmask[nb_bitmask].mask = ~mask_tmp;
1234 : 0 : flex_mask.bitmask[nb_bitmask].offset =
1235 : : i / sizeof(uint16_t);
1236 : 0 : nb_bitmask++;
1237 [ # # ]: 0 : if (nb_bitmask > I40E_FDIR_BITMASK_NUM_WORD)
1238 : : return -1;
1239 : : }
1240 : : }
1241 : : }
1242 : 0 : flex_mask.nb_bitmask = nb_bitmask;
1243 : :
1244 [ # # ]: 0 : if (pf->fdir.flex_mask_flag[pctype] &&
1245 [ # # ]: 0 : (memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
1246 : : sizeof(struct i40e_fdir_flex_mask))))
1247 : : return -2;
1248 [ # # ]: 0 : else if (pf->fdir.flex_mask_flag[pctype] &&
1249 [ # # ]: 0 : !(memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
1250 : : sizeof(struct i40e_fdir_flex_mask))))
1251 : : return 1;
1252 : :
1253 : 0 : memcpy(&pf->fdir.flex_mask[pctype], &flex_mask,
1254 : : sizeof(struct i40e_fdir_flex_mask));
1255 : 0 : return 0;
1256 : : }
1257 : :
1258 : : static void
1259 : 0 : i40e_flow_set_fdir_flex_msk(struct i40e_pf *pf,
1260 : : enum i40e_filter_pctype pctype)
1261 : : {
1262 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1263 : : struct i40e_fdir_flex_mask *flex_mask;
1264 : : uint32_t flxinset, fd_mask;
1265 : : uint8_t i;
1266 : :
1267 : : /* Set flex mask */
1268 : : flex_mask = &pf->fdir.flex_mask[pctype];
1269 : 0 : flxinset = (flex_mask->word_mask <<
1270 : : I40E_PRTQF_FD_FLXINSET_INSET_SHIFT) &
1271 : : I40E_PRTQF_FD_FLXINSET_INSET_MASK;
1272 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), flxinset);
1273 : :
1274 [ # # ]: 0 : for (i = 0; i < flex_mask->nb_bitmask; i++) {
1275 : 0 : fd_mask = (flex_mask->bitmask[i].mask <<
1276 : : I40E_PRTQF_FD_MSK_MASK_SHIFT) &
1277 : : I40E_PRTQF_FD_MSK_MASK_MASK;
1278 : 0 : fd_mask |= ((flex_mask->bitmask[i].offset +
1279 : 0 : I40E_FLX_OFFSET_IN_FIELD_VECTOR) <<
1280 : 0 : I40E_PRTQF_FD_MSK_OFFSET_SHIFT) &
1281 : : I40E_PRTQF_FD_MSK_OFFSET_MASK;
1282 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), fd_mask);
1283 : : }
1284 : :
1285 : 0 : pf->fdir.flex_mask_flag[pctype] = 1;
1286 : 0 : }
1287 : :
1288 : : static int
1289 : 0 : i40e_flow_set_fdir_inset(struct i40e_pf *pf,
1290 : : enum i40e_filter_pctype pctype,
1291 : : uint64_t input_set)
1292 : : {
1293 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
1294 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1295 : : uint64_t inset_reg = 0;
1296 : : int i, num;
1297 : :
1298 : : /* Check if the input set is valid */
1299 [ # # ]: 0 : if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_FDIR,
1300 : : input_set) != 0) {
1301 : 0 : PMD_DRV_LOG(ERR, "Invalid input set");
1302 : 0 : return -EINVAL;
1303 : : }
1304 : :
1305 : : /* Check if the configuration is conflicted */
1306 [ # # ]: 0 : if (pf->fdir.flow_count[pctype] &&
1307 [ # # ]: 0 : memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t))) {
1308 : 0 : PMD_DRV_LOG(ERR, "Conflict with the first rule's input set.");
1309 : 0 : return -EINVAL;
1310 : : }
1311 : :
1312 [ # # ]: 0 : if (pf->fdir.flow_count[pctype] &&
1313 [ # # ]: 0 : !memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t)))
1314 : : return 0;
1315 : :
1316 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
1317 : : I40E_INSET_MASK_NUM_REG);
1318 [ # # ]: 0 : if (num < 0) {
1319 : 0 : PMD_DRV_LOG(ERR, "Invalid pattern mask.");
1320 : 0 : return -EINVAL;
1321 : : }
1322 : :
1323 [ # # ]: 0 : if (pf->support_multi_driver) {
1324 [ # # ]: 0 : for (i = 0; i < num; i++)
1325 : 0 : if (i40e_read_rx_ctl(hw,
1326 : 0 : I40E_GLQF_FD_MSK(i, pctype)) !=
1327 [ # # ]: 0 : mask_reg[i]) {
1328 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not"
1329 : : " supported with"
1330 : : " `support-multi-driver`"
1331 : : " enabled!");
1332 : 0 : return -EPERM;
1333 : : }
1334 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
1335 [ # # ]: 0 : if (i40e_read_rx_ctl(hw,
1336 : 0 : I40E_GLQF_FD_MSK(i, pctype)) != 0) {
1337 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not"
1338 : : " supported with"
1339 : : " `support-multi-driver`"
1340 : : " enabled!");
1341 : 0 : return -EPERM;
1342 : : }
1343 : :
1344 : : } else {
1345 [ # # ]: 0 : for (i = 0; i < num; i++)
1346 : 0 : i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
1347 : : mask_reg[i]);
1348 : : /*clear unused mask registers of the pctype */
1349 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
1350 : 0 : i40e_check_write_reg(hw,
1351 : 0 : I40E_GLQF_FD_MSK(i, pctype), 0);
1352 : : }
1353 : :
1354 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
1355 : :
1356 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
1357 : : (uint32_t)(inset_reg & UINT32_MAX));
1358 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
1359 : 0 : (uint32_t)((inset_reg >>
1360 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
1361 : :
1362 : 0 : I40E_WRITE_FLUSH(hw);
1363 : :
1364 : 0 : pf->fdir.input_set[pctype] = input_set;
1365 : 0 : return 0;
1366 : : }
1367 : :
1368 : : static inline unsigned char *
1369 : 0 : i40e_find_available_buffer(struct rte_eth_dev *dev)
1370 : : {
1371 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1372 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1373 : 0 : struct ci_tx_queue *txq = pf->fdir.txq;
1374 : :
1375 : : /* no available buffer
1376 : : * search for more available buffers from the current
1377 : : * descriptor, until an unavailable one
1378 : : */
1379 [ # # ]: 0 : if (fdir_info->txq_available_buf_count <= 0) {
1380 : : uint16_t tmp_tail;
1381 : : volatile struct i40e_tx_desc *tmp_txdp;
1382 : :
1383 : 0 : tmp_tail = txq->tx_tail;
1384 : 0 : tmp_txdp = &txq->i40e_tx_ring[tmp_tail + 1];
1385 : :
1386 : : do {
1387 [ # # ]: 0 : if ((tmp_txdp->cmd_type_offset_bsz &
1388 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1389 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1390 : 0 : fdir_info->txq_available_buf_count++;
1391 : : else
1392 : : break;
1393 : :
1394 : 0 : tmp_tail += 2;
1395 [ # # ]: 0 : if (tmp_tail >= txq->nb_tx_desc)
1396 : : tmp_tail = 0;
1397 [ # # ]: 0 : } while (tmp_tail != txq->tx_tail);
1398 : : }
1399 : :
1400 [ # # ]: 0 : if (fdir_info->txq_available_buf_count > 0)
1401 : 0 : fdir_info->txq_available_buf_count--;
1402 : : else
1403 : : return NULL;
1404 : 0 : return (unsigned char *)fdir_info->prg_pkt[txq->tx_tail >> 1];
1405 : : }
1406 : :
1407 : : /**
1408 : : * i40e_flow_add_del_fdir_filter - add or remove a flow director filter.
1409 : : * @pf: board private structure
1410 : : * @filter: fdir filter entry
1411 : : * @add: 0 - delete, 1 - add
1412 : : */
1413 : : int
1414 : 0 : i40e_flow_add_del_fdir_filter(struct rte_eth_dev *dev,
1415 : : const struct i40e_fdir_filter_conf *filter,
1416 : : bool add)
1417 : : {
1418 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1419 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1420 : : enum i40e_flxpld_layer_idx layer_idx = I40E_FLXPLD_L2_IDX;
1421 : 0 : struct i40e_fdir_info *fdir_info = &pf->fdir;
1422 : : uint8_t flex_mask[I40E_FDIR_MAX_FLEX_LEN];
1423 : : struct i40e_fdir_filter check_filter; /* Check if the filter exists */
1424 : : struct i40e_fdir_flex_pit flex_pit;
1425 : : enum i40e_filter_pctype pctype;
1426 : : struct i40e_fdir_filter *node;
1427 : : unsigned char *pkt = NULL;
1428 : : bool cfg_flex_pit = true;
1429 : : bool wait_status = true;
1430 : : uint8_t field_idx;
1431 : : int ret = 0;
1432 : : int i;
1433 : :
1434 [ # # ]: 0 : if (pf->fdir.fdir_vsi == NULL) {
1435 : 0 : PMD_DRV_LOG(ERR, "FDIR is not enabled");
1436 : 0 : return -ENOTSUP;
1437 : : }
1438 : :
1439 [ # # ]: 0 : if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1440 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
1441 : 0 : return -EINVAL;
1442 : : }
1443 [ # # ]: 0 : if (filter->input.flow_ext.is_vf &&
1444 [ # # ]: 0 : filter->input.flow_ext.dst_id >= pf->vf_num) {
1445 : 0 : PMD_DRV_LOG(ERR, "Invalid VF ID");
1446 : 0 : return -EINVAL;
1447 : : }
1448 [ # # ]: 0 : if (filter->input.flow_ext.pkt_template) {
1449 [ # # ]: 0 : if (filter->input.flow.raw_flow.length > I40E_FDIR_PKT_LEN ||
1450 [ # # ]: 0 : !filter->input.flow.raw_flow.packet) {
1451 : 0 : PMD_DRV_LOG(ERR, "Invalid raw packet template"
1452 : : " flow filter parameters!");
1453 : 0 : return -EINVAL;
1454 : : }
1455 : 0 : pctype = filter->input.flow.raw_flow.pctype;
1456 : : } else {
1457 : 0 : pctype = filter->input.pctype;
1458 : : }
1459 : :
1460 : : /* Check if there is the filter in SW list */
1461 : : memset(&check_filter, 0, sizeof(check_filter));
1462 : 0 : i40e_fdir_filter_convert(filter, &check_filter);
1463 : :
1464 [ # # ]: 0 : if (add) {
1465 : : /* configure the input set for common PCTYPEs*/
1466 [ # # ]: 0 : if (!filter->input.flow_ext.customized_pctype &&
1467 [ # # ]: 0 : !filter->input.flow_ext.pkt_template) {
1468 : 0 : ret = i40e_flow_set_fdir_inset(pf, pctype,
1469 : 0 : filter->input.flow_ext.input_set);
1470 [ # # ]: 0 : if (ret < 0)
1471 : : return ret;
1472 : : }
1473 : :
1474 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow) {
1475 [ # # ]: 0 : for (i = 0; i < filter->input.flow_ext.raw_id; i++) {
1476 : 0 : layer_idx = filter->input.flow_ext.layer_idx;
1477 : 0 : field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
1478 : 0 : flex_pit = filter->input.flow_ext.flex_pit[field_idx];
1479 : :
1480 : : /* Store flex pit to SW */
1481 : 0 : ret = i40e_flow_store_flex_pit(pf, &flex_pit,
1482 : : layer_idx, i);
1483 [ # # ]: 0 : if (ret < 0) {
1484 : 0 : PMD_DRV_LOG(ERR, "Conflict with the"
1485 : : " first flexible rule.");
1486 : 0 : return -EINVAL;
1487 [ # # ]: 0 : } else if (ret > 0) {
1488 : : cfg_flex_pit = false;
1489 : : }
1490 : : }
1491 : :
1492 [ # # ]: 0 : if (cfg_flex_pit)
1493 : 0 : i40e_flow_set_fdir_flex_pit(pf, layer_idx,
1494 : : filter->input.flow_ext.raw_id);
1495 : :
1496 : : /* Store flex mask to SW */
1497 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i++)
1498 : 0 : flex_mask[i] =
1499 : 0 : filter->input.flow_ext.flex_mask[i];
1500 : :
1501 : 0 : ret = i40e_flow_store_flex_mask(pf, pctype, flex_mask);
1502 [ # # ]: 0 : if (ret == -1) {
1503 : 0 : PMD_DRV_LOG(ERR, "Exceed maximal"
1504 : : " number of bitmasks");
1505 : 0 : return -EINVAL;
1506 [ # # ]: 0 : } else if (ret == -2) {
1507 : 0 : PMD_DRV_LOG(ERR, "Conflict with the"
1508 : : " first flexible rule");
1509 : 0 : return -EINVAL;
1510 [ # # ]: 0 : } else if (ret == 0) {
1511 : 0 : i40e_flow_set_fdir_flex_msk(pf, pctype);
1512 : : }
1513 : : }
1514 : :
1515 : 0 : ret = i40e_sw_fdir_filter_insert(pf, &check_filter);
1516 [ # # ]: 0 : if (ret < 0) {
1517 : 0 : PMD_DRV_LOG(ERR,
1518 : : "Conflict with existing flow director rules!");
1519 : 0 : return -EINVAL;
1520 : : }
1521 : :
1522 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1523 [ # # ]: 0 : fdir_info->fdir_guarantee_free_space > 0)
1524 : : wait_status = false;
1525 : : } else {
1526 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow)
1527 : 0 : layer_idx = filter->input.flow_ext.layer_idx;
1528 : :
1529 : 0 : node = i40e_sw_fdir_filter_lookup(fdir_info,
1530 : : &check_filter.fdir.input);
1531 [ # # ]: 0 : if (!node) {
1532 : 0 : PMD_DRV_LOG(ERR,
1533 : : "There's no corresponding flow director filter!");
1534 : 0 : return -EINVAL;
1535 : : }
1536 : :
1537 : 0 : ret = i40e_sw_fdir_filter_del(pf, &node->fdir.input);
1538 [ # # ]: 0 : if (ret < 0) {
1539 : 0 : PMD_DRV_LOG(ERR,
1540 : : "Error deleting fdir rule from hash table!");
1541 : 0 : return -EINVAL;
1542 : : }
1543 : :
1544 : 0 : pf->fdir.flex_mask_flag[pctype] = 0;
1545 : :
1546 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1)
1547 : : wait_status = false;
1548 : : }
1549 : :
1550 : : /* find a buffer to store the pkt */
1551 : 0 : pkt = i40e_find_available_buffer(dev);
1552 [ # # ]: 0 : if (pkt == NULL)
1553 : 0 : goto error_op;
1554 : :
1555 : : memset(pkt, 0, I40E_FDIR_PKT_LEN);
1556 : 0 : ret = i40e_flow_fdir_construct_pkt(pf, &filter->input, pkt);
1557 [ # # ]: 0 : if (ret < 0) {
1558 : 0 : PMD_DRV_LOG(ERR, "construct packet for fdir fails.");
1559 : 0 : goto error_op;
1560 : : }
1561 : :
1562 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
1563 : : /* get translated pctype value in fd pctype register */
1564 : 0 : pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(
1565 : 0 : hw, I40E_GLQF_FD_PCTYPES((int)pctype));
1566 : : }
1567 : :
1568 : 0 : ret = i40e_flow_fdir_filter_programming(pf, pctype, filter, add,
1569 : : wait_status);
1570 [ # # ]: 0 : if (ret < 0) {
1571 : 0 : PMD_DRV_LOG(ERR, "fdir programming fails for PCTYPE(%u).",
1572 : : pctype);
1573 : 0 : goto error_op;
1574 : : }
1575 : :
1576 [ # # ]: 0 : if (filter->input.flow_ext.is_flex_flow) {
1577 [ # # ]: 0 : if (add) {
1578 : 0 : fdir_info->flex_flow_count[layer_idx]++;
1579 : 0 : pf->fdir.flex_pit_flag[layer_idx] = 1;
1580 : : } else {
1581 : 0 : fdir_info->flex_flow_count[layer_idx]--;
1582 [ # # ]: 0 : if (!fdir_info->flex_flow_count[layer_idx])
1583 : 0 : pf->fdir.flex_pit_flag[layer_idx] = 0;
1584 : : }
1585 : : }
1586 : :
1587 [ # # ]: 0 : if (add) {
1588 : 0 : fdir_info->flow_count[pctype]++;
1589 : 0 : fdir_info->fdir_actual_cnt++;
1590 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1591 [ # # ]: 0 : fdir_info->fdir_guarantee_free_space > 0)
1592 : 0 : fdir_info->fdir_guarantee_free_space--;
1593 : : } else {
1594 : 0 : fdir_info->flow_count[pctype]--;
1595 : 0 : fdir_info->fdir_actual_cnt--;
1596 [ # # ]: 0 : if (fdir_info->fdir_invalprio == 1 &&
1597 : 0 : fdir_info->fdir_guarantee_free_space <
1598 [ # # ]: 0 : fdir_info->fdir_guarantee_total_space)
1599 : 0 : fdir_info->fdir_guarantee_free_space++;
1600 : : }
1601 : :
1602 : : return ret;
1603 : :
1604 : 0 : error_op:
1605 : : /* roll back */
1606 [ # # ]: 0 : if (add)
1607 : 0 : i40e_sw_fdir_filter_del(pf, &check_filter.fdir.input);
1608 : : else
1609 : 0 : i40e_sw_fdir_filter_insert(pf, &check_filter);
1610 : :
1611 : : return ret;
1612 : : }
1613 : :
1614 : : /*
1615 : : * i40e_flow_fdir_filter_programming - Program a flow director filter rule.
1616 : : * Is done by Flow Director Programming Descriptor followed by packet
1617 : : * structure that contains the filter fields need to match.
1618 : : * @pf: board private structure
1619 : : * @pctype: pctype
1620 : : * @filter: fdir filter entry
1621 : : * @add: 0 - delete, 1 - add
1622 : : */
1623 : : static int
1624 : 0 : i40e_flow_fdir_filter_programming(struct i40e_pf *pf,
1625 : : enum i40e_filter_pctype pctype,
1626 : : const struct i40e_fdir_filter_conf *filter,
1627 : : bool add, bool wait_status)
1628 : : {
1629 : 0 : struct ci_tx_queue *txq = pf->fdir.txq;
1630 : 0 : struct i40e_rx_queue *rxq = pf->fdir.rxq;
1631 : : const struct i40e_fdir_action *fdir_action = &filter->action;
1632 : : volatile struct i40e_tx_desc *txdp;
1633 : : volatile struct i40e_filter_program_desc *fdirdp;
1634 : : uint32_t td_cmd;
1635 : : uint16_t vsi_id;
1636 : : uint8_t dest;
1637 : : uint32_t i;
1638 : :
1639 : 0 : PMD_DRV_LOG(INFO, "filling filter programming descriptor.");
1640 : 0 : fdirdp = (volatile struct i40e_filter_program_desc *)
1641 : 0 : (&txq->i40e_tx_ring[txq->tx_tail]);
1642 : :
1643 : 0 : fdirdp->qindex_flex_ptype_vsi =
1644 : 0 : rte_cpu_to_le_32((fdir_action->rx_queue <<
1645 : : I40E_TXD_FLTR_QW0_QINDEX_SHIFT) &
1646 : : I40E_TXD_FLTR_QW0_QINDEX_MASK);
1647 : :
1648 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1649 : 0 : rte_cpu_to_le_32((fdir_action->flex_off <<
1650 : : I40E_TXD_FLTR_QW0_FLEXOFF_SHIFT) &
1651 : : I40E_TXD_FLTR_QW0_FLEXOFF_MASK);
1652 : :
1653 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1654 : 0 : rte_cpu_to_le_32((pctype <<
1655 : : I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) &
1656 : : I40E_TXD_FLTR_QW0_PCTYPE_MASK);
1657 : :
1658 [ # # ]: 0 : if (filter->input.flow_ext.is_vf)
1659 : 0 : vsi_id = pf->vfs[filter->input.flow_ext.dst_id].vsi->vsi_id;
1660 : : else
1661 : : /* Use LAN VSI Id by default */
1662 : 0 : vsi_id = pf->main_vsi->vsi_id;
1663 : 0 : fdirdp->qindex_flex_ptype_vsi |=
1664 : 0 : rte_cpu_to_le_32(((uint32_t)vsi_id <<
1665 : : I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT) &
1666 : : I40E_TXD_FLTR_QW0_DEST_VSI_MASK);
1667 : :
1668 : 0 : fdirdp->dtype_cmd_cntindex =
1669 : : rte_cpu_to_le_32(I40E_TX_DESC_DTYPE_FILTER_PROG);
1670 : :
1671 [ # # ]: 0 : if (add)
1672 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1673 : : I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE <<
1674 : : I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1675 : : else
1676 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1677 : : I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE <<
1678 : : I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1679 : :
1680 [ # # ]: 0 : if (fdir_action->behavior == I40E_FDIR_REJECT)
1681 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1682 [ # # ]: 0 : else if (fdir_action->behavior == I40E_FDIR_ACCEPT)
1683 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1684 [ # # ]: 0 : else if (fdir_action->behavior == I40E_FDIR_PASSTHRU)
1685 : : dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_OTHER;
1686 : : else {
1687 : 0 : PMD_DRV_LOG(ERR, "Failed to program FDIR filter: unsupported fdir behavior.");
1688 : 0 : return -EINVAL;
1689 : : }
1690 : :
1691 : 0 : fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32((dest <<
1692 : : I40E_TXD_FLTR_QW1_DEST_SHIFT) &
1693 : : I40E_TXD_FLTR_QW1_DEST_MASK);
1694 : :
1695 : 0 : fdirdp->dtype_cmd_cntindex |=
1696 : 0 : rte_cpu_to_le_32((fdir_action->report_status <<
1697 : : I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT) &
1698 : : I40E_TXD_FLTR_QW1_FD_STATUS_MASK);
1699 : :
1700 : 0 : fdirdp->dtype_cmd_cntindex |=
1701 : : rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
1702 : 0 : fdirdp->dtype_cmd_cntindex |=
1703 : 0 : rte_cpu_to_le_32(
1704 : : ((uint32_t)pf->fdir.match_counter_index <<
1705 : : I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
1706 : : I40E_TXD_FLTR_QW1_CNTINDEX_MASK);
1707 : :
1708 : 0 : fdirdp->fd_id = rte_cpu_to_le_32(filter->soft_id);
1709 : :
1710 : 0 : PMD_DRV_LOG(INFO, "filling transmit descriptor.");
1711 : 0 : txdp = &txq->i40e_tx_ring[txq->tx_tail + 1];
1712 : 0 : txdp->buffer_addr = rte_cpu_to_le_64(pf->fdir.dma_addr[txq->tx_tail >> 1]);
1713 : :
1714 : : td_cmd = I40E_TX_DESC_CMD_EOP |
1715 : : I40E_TX_DESC_CMD_RS |
1716 : : I40E_TX_DESC_CMD_DUMMY;
1717 : :
1718 : 0 : txdp->cmd_type_offset_bsz =
1719 : : i40e_build_ctob(td_cmd, 0, I40E_FDIR_PKT_LEN, 0);
1720 : :
1721 : 0 : txq->tx_tail += 2; /* set 2 descriptors above, fdirdp and txdp */
1722 [ # # ]: 0 : if (txq->tx_tail >= txq->nb_tx_desc)
1723 : 0 : txq->tx_tail = 0;
1724 : : /* Update the tx tail register */
1725 : : rte_wmb();
1726 : :
1727 : : /* fdir program rx queue cleanup */
1728 : 0 : i40e_fdir_programming_status_cleanup(rxq);
1729 : :
1730 : 0 : I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1731 : :
1732 [ # # ]: 0 : if (wait_status) {
1733 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_MAX_WAIT_US; i++) {
1734 [ # # ]: 0 : if ((txdp->cmd_type_offset_bsz &
1735 : : rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1736 : : rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1737 : : break;
1738 : 0 : rte_delay_us(1);
1739 : : }
1740 [ # # ]: 0 : if (i >= I40E_FDIR_MAX_WAIT_US) {
1741 : 0 : PMD_DRV_LOG(ERR,
1742 : : "Failed to program FDIR filter: time out to get DD on tx queue.");
1743 : 0 : return -ETIMEDOUT;
1744 : : }
1745 : : /* totally delay 10 ms to check programming status*/
1746 : 0 : rte_delay_us(I40E_FDIR_MAX_WAIT_US);
1747 [ # # ]: 0 : if (i40e_check_fdir_programming_status(rxq) < 0) {
1748 : 0 : PMD_DRV_LOG(ERR,
1749 : : "Failed to program FDIR filter: programming status reported.");
1750 : 0 : return -ETIMEDOUT;
1751 : : }
1752 : : }
1753 : :
1754 : : return 0;
1755 : : }
1756 : :
1757 : : /*
1758 : : * i40e_fdir_flush - clear all filters of Flow Director table
1759 : : * @pf: board private structure
1760 : : */
1761 : : int
1762 : 0 : i40e_fdir_flush(struct rte_eth_dev *dev)
1763 : : {
1764 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1765 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1766 : : uint32_t reg;
1767 : : uint16_t guarant_cnt, best_cnt;
1768 : : uint16_t i;
1769 : :
1770 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_CTL_1, I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
1771 : 0 : I40E_WRITE_FLUSH(hw);
1772 : :
1773 [ # # ]: 0 : for (i = 0; i < I40E_FDIR_FLUSH_RETRY; i++) {
1774 : : rte_delay_ms(I40E_FDIR_FLUSH_INTERVAL_MS);
1775 : 0 : reg = I40E_READ_REG(hw, I40E_PFQF_CTL_1);
1776 [ # # ]: 0 : if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
1777 : : break;
1778 : : }
1779 [ # # ]: 0 : if (i >= I40E_FDIR_FLUSH_RETRY) {
1780 : 0 : PMD_DRV_LOG(ERR, "FD table did not flush, may need more time.");
1781 : 0 : return -ETIMEDOUT;
1782 : : }
1783 : 0 : guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1784 : : I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1785 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1786 : 0 : best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1787 : 0 : I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1788 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1789 [ # # ]: 0 : if (guarant_cnt != 0 || best_cnt != 0) {
1790 : 0 : PMD_DRV_LOG(ERR, "Failed to flush FD table.");
1791 : 0 : return -ENOSYS;
1792 : : } else
1793 : 0 : PMD_DRV_LOG(INFO, "FD table Flush success.");
1794 : 0 : return 0;
1795 : : }
1796 : :
1797 : : static inline void
1798 : 0 : i40e_fdir_info_get_flex_set(struct i40e_pf *pf,
1799 : : struct rte_eth_flex_payload_cfg *flex_set,
1800 : : uint16_t *num)
1801 : : {
1802 : : struct i40e_fdir_flex_pit *flex_pit;
1803 : : struct rte_eth_flex_payload_cfg *ptr = flex_set;
1804 : : uint16_t src, dst, size, j, k;
1805 : : uint8_t i, layer_idx;
1806 : :
1807 : 0 : for (layer_idx = I40E_FLXPLD_L2_IDX;
1808 [ # # ]: 0 : layer_idx <= I40E_FLXPLD_L4_IDX;
1809 : 0 : layer_idx++) {
1810 [ # # ]: 0 : if (layer_idx == I40E_FLXPLD_L2_IDX)
1811 : 0 : ptr->type = RTE_ETH_L2_PAYLOAD;
1812 [ # # ]: 0 : else if (layer_idx == I40E_FLXPLD_L3_IDX)
1813 : 0 : ptr->type = RTE_ETH_L3_PAYLOAD;
1814 : : else if (layer_idx == I40E_FLXPLD_L4_IDX)
1815 : 0 : ptr->type = RTE_ETH_L4_PAYLOAD;
1816 : :
1817 [ # # ]: 0 : for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
1818 : 0 : flex_pit = &pf->fdir.flex_set[layer_idx *
1819 : 0 : I40E_MAX_FLXPLD_FIED + i];
1820 [ # # ]: 0 : if (flex_pit->size == 0)
1821 : 0 : continue;
1822 : 0 : src = flex_pit->src_offset * sizeof(uint16_t);
1823 : 0 : dst = flex_pit->dst_offset * sizeof(uint16_t);
1824 : 0 : size = flex_pit->size * sizeof(uint16_t);
1825 [ # # ]: 0 : for (j = src, k = dst; j < src + size; j++, k++)
1826 : 0 : ptr->src_offset[k] = j;
1827 : : }
1828 : 0 : (*num)++;
1829 : 0 : ptr++;
1830 : : }
1831 : 0 : }
1832 : :
1833 : : static inline void
1834 : 0 : i40e_fdir_info_get_flex_mask(struct i40e_pf *pf,
1835 : : struct rte_eth_fdir_flex_mask *flex_mask,
1836 : : uint16_t *num)
1837 : : {
1838 : : struct i40e_fdir_flex_mask *mask;
1839 : : struct rte_eth_fdir_flex_mask *ptr = flex_mask;
1840 : : uint16_t flow_type;
1841 : : uint8_t i, j;
1842 : : uint16_t off_bytes, mask_tmp;
1843 : :
1844 : 0 : for (i = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1845 [ # # ]: 0 : i <= I40E_FILTER_PCTYPE_L2_PAYLOAD;
1846 : 0 : i++) {
1847 : 0 : mask = &pf->fdir.flex_mask[i];
1848 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter,
1849 : : (enum i40e_filter_pctype)i);
1850 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
1851 : 0 : continue;
1852 : :
1853 [ # # ]: 0 : for (j = 0; j < I40E_FDIR_MAX_FLEXWORD_NUM; j++) {
1854 [ # # ]: 0 : if (mask->word_mask & I40E_FLEX_WORD_MASK(j)) {
1855 : 0 : ptr->mask[j * sizeof(uint16_t)] = UINT8_MAX;
1856 : 0 : ptr->mask[j * sizeof(uint16_t) + 1] = UINT8_MAX;
1857 : : } else {
1858 : 0 : ptr->mask[j * sizeof(uint16_t)] = 0x0;
1859 : 0 : ptr->mask[j * sizeof(uint16_t) + 1] = 0x0;
1860 : : }
1861 : : }
1862 [ # # ]: 0 : for (j = 0; j < I40E_FDIR_BITMASK_NUM_WORD; j++) {
1863 : 0 : off_bytes = mask->bitmask[j].offset * sizeof(uint16_t);
1864 : 0 : mask_tmp = ~mask->bitmask[j].mask;
1865 : 0 : ptr->mask[off_bytes] &= I40E_HI_BYTE(mask_tmp);
1866 : 0 : ptr->mask[off_bytes + 1] &= I40E_LO_BYTE(mask_tmp);
1867 : : }
1868 : 0 : ptr->flow_type = flow_type;
1869 : 0 : ptr++;
1870 : 0 : (*num)++;
1871 : : }
1872 : 0 : }
1873 : :
1874 : : /*
1875 : : * i40e_fdir_info_get - get information of Flow Director
1876 : : * @pf: ethernet device to get info from
1877 : : * @fdir: a pointer to a structure of type *rte_eth_fdir_info* to be filled with
1878 : : * the flow director information.
1879 : : */
1880 : : void
1881 : 0 : i40e_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir)
1882 : : {
1883 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1884 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1885 : 0 : uint16_t num_flex_set = 0;
1886 : 0 : uint16_t num_flex_mask = 0;
1887 : : uint16_t i;
1888 : :
1889 : 0 : fdir->mode = RTE_FDIR_MODE_NONE;
1890 : :
1891 : 0 : fdir->guarant_spc =
1892 : 0 : (uint32_t)hw->func_caps.fd_filters_guaranteed;
1893 : 0 : fdir->best_spc =
1894 : 0 : (uint32_t)hw->func_caps.fd_filters_best_effort;
1895 : 0 : fdir->max_flexpayload = I40E_FDIR_MAX_FLEX_LEN;
1896 : 0 : fdir->flow_types_mask[0] = I40E_FDIR_FLOWS;
1897 : : for (i = 1; i < RTE_FLOW_MASK_ARRAY_SIZE; i++)
1898 : : fdir->flow_types_mask[i] = 0ULL;
1899 : 0 : fdir->flex_payload_unit = sizeof(uint16_t);
1900 : 0 : fdir->flex_bitmask_unit = sizeof(uint16_t);
1901 : 0 : fdir->max_flex_payload_segment_num = I40E_MAX_FLXPLD_FIED;
1902 : 0 : fdir->flex_payload_limit = I40E_MAX_FLX_SOURCE_OFF;
1903 : 0 : fdir->max_flex_bitmask_num = I40E_FDIR_BITMASK_NUM_WORD;
1904 : :
1905 : 0 : i40e_fdir_info_get_flex_set(pf,
1906 : 0 : fdir->flex_conf.flex_set,
1907 : : &num_flex_set);
1908 : 0 : i40e_fdir_info_get_flex_mask(pf,
1909 : 0 : fdir->flex_conf.flex_mask,
1910 : : &num_flex_mask);
1911 : :
1912 : 0 : fdir->flex_conf.nb_payloads = num_flex_set;
1913 : 0 : fdir->flex_conf.nb_flexmasks = num_flex_mask;
1914 : 0 : }
1915 : :
1916 : : /*
1917 : : * i40e_fdir_stat_get - get statistics of Flow Director
1918 : : * @pf: ethernet device to get info from
1919 : : * @stat: a pointer to a structure of type *rte_eth_fdir_stats* to be filled with
1920 : : * the flow director statistics.
1921 : : */
1922 : : void
1923 : 0 : i40e_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *stat)
1924 : : {
1925 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1926 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1927 : : uint32_t fdstat;
1928 : :
1929 : 0 : fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1930 : 0 : stat->guarant_cnt =
1931 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1932 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1933 : 0 : stat->best_cnt =
1934 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1935 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1936 : 0 : }
1937 : :
1938 : : /* Restore flow director filter */
1939 : : void
1940 : 0 : i40e_fdir_filter_restore(struct i40e_pf *pf)
1941 : : {
1942 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(pf->main_vsi);
1943 : : struct i40e_fdir_filter_list *fdir_list = &pf->fdir.fdir_list;
1944 : : struct i40e_fdir_filter *f;
1945 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1946 : : uint32_t fdstat;
1947 : : uint32_t guarant_cnt; /**< Number of filters in guaranteed spaces. */
1948 : : uint32_t best_cnt; /**< Number of filters in best effort spaces. */
1949 : :
1950 [ # # ]: 0 : TAILQ_FOREACH(f, fdir_list, rules)
1951 : 0 : i40e_flow_add_del_fdir_filter(dev, &f->fdir, TRUE);
1952 : :
1953 : 0 : fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1954 : 0 : guarant_cnt =
1955 : : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1956 : : I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1957 : 0 : best_cnt =
1958 : 0 : (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1959 : : I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1960 : :
1961 : 0 : PMD_DRV_LOG(INFO, "FDIR: Guarant count: %d, Best count: %d",
1962 : : guarant_cnt, best_cnt);
1963 : 0 : }
|