1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2015 Intel Corporation
13 #include <rte_ether.h>
14 #include <rte_ethdev_driver.h>
16 #include <rte_memzone.h>
17 #include <rte_malloc.h>
23 #include <rte_hash_crc.h>
25 #include "i40e_logs.h"
26 #include "base/i40e_type.h"
27 #include "base/i40e_prototype.h"
28 #include "i40e_ethdev.h"
29 #include "i40e_rxtx.h"
31 #define I40E_FDIR_MZ_NAME "FDIR_MEMZONE"
33 #define IPV6_ADDR_LEN 16
37 #define IPPROTO_L2TP 115
40 #define I40E_FDIR_PKT_LEN 512
41 #define I40E_FDIR_IP_DEFAULT_LEN 420
42 #define I40E_FDIR_IP_DEFAULT_TTL 0x40
43 #define I40E_FDIR_IP_DEFAULT_VERSION_IHL 0x45
44 #define I40E_FDIR_TCP_DEFAULT_DATAOFF 0x50
45 #define I40E_FDIR_IPv6_DEFAULT_VTC_FLOW 0x60000000
47 #define I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS 0xFF
48 #define I40E_FDIR_IPv6_PAYLOAD_LEN 380
49 #define I40E_FDIR_UDP_DEFAULT_LEN 400
50 #define I40E_FDIR_GTP_DEFAULT_LEN 384
51 #define I40E_FDIR_INNER_IP_DEFAULT_LEN 384
52 #define I40E_FDIR_INNER_IPV6_DEFAULT_LEN 344
54 #define I40E_FDIR_GTPC_DST_PORT 2123
55 #define I40E_FDIR_GTPU_DST_PORT 2152
56 #define I40E_FDIR_GTP_VER_FLAG_0X30 0x30
57 #define I40E_FDIR_GTP_VER_FLAG_0X32 0x32
58 #define I40E_FDIR_GTP_MSG_TYPE_0X01 0x01
59 #define I40E_FDIR_GTP_MSG_TYPE_0XFF 0xFF
61 #define I40E_FDIR_ESP_DST_PORT 4500
63 /* Wait time for fdir filter programming */
64 #define I40E_FDIR_MAX_WAIT_US 10000
66 /* Wait count and interval for fdir filter flush */
67 #define I40E_FDIR_FLUSH_RETRY 50
68 #define I40E_FDIR_FLUSH_INTERVAL_MS 5
70 #define I40E_COUNTER_PF 2
71 /* Statistic counter index for one pf */
72 #define I40E_COUNTER_INDEX_FDIR(pf_id) (0 + (pf_id) * I40E_COUNTER_PF)
74 #define I40E_FDIR_FLOWS ( \
75 (1ULL << RTE_ETH_FLOW_FRAG_IPV4) | \
76 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
77 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
78 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
79 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
80 (1ULL << RTE_ETH_FLOW_FRAG_IPV6) | \
81 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
82 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
83 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
84 (1ULL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
85 (1ULL << RTE_ETH_FLOW_L2_PAYLOAD))
87 static int i40e_fdir_filter_programming(struct i40e_pf *pf,
88 enum i40e_filter_pctype pctype,
89 const struct rte_eth_fdir_filter *filter,
91 static int i40e_fdir_filter_convert(const struct i40e_fdir_filter_conf *input,
92 struct i40e_fdir_filter *filter);
93 static struct i40e_fdir_filter *
94 i40e_sw_fdir_filter_lookup(struct i40e_fdir_info *fdir_info,
95 const struct i40e_fdir_input *input);
96 static int i40e_sw_fdir_filter_insert(struct i40e_pf *pf,
97 struct i40e_fdir_filter *filter);
99 i40e_flow_fdir_filter_programming(struct i40e_pf *pf,
100 enum i40e_filter_pctype pctype,
101 const struct i40e_fdir_filter_conf *filter,
105 i40e_fdir_rx_queue_init(struct i40e_rx_queue *rxq)
107 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
108 struct i40e_hmc_obj_rxq rx_ctx;
109 int err = I40E_SUCCESS;
111 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
112 /* Init the RX queue in hardware */
113 rx_ctx.dbuff = I40E_RXBUF_SZ_1024 >> I40E_RXQ_CTX_DBUFF_SHIFT;
115 rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
116 rx_ctx.qlen = rxq->nb_rx_desc;
117 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
120 rx_ctx.dtype = i40e_header_split_none;
121 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
122 rx_ctx.rxmax = RTE_ETHER_MAX_LEN;
123 rx_ctx.tphrdesc_ena = 1;
124 rx_ctx.tphwdesc_ena = 1;
125 rx_ctx.tphdata_ena = 1;
126 rx_ctx.tphhead_ena = 1;
127 rx_ctx.lrxqthresh = 2;
133 err = i40e_clear_lan_rx_queue_context(hw, rxq->reg_idx);
134 if (err != I40E_SUCCESS) {
135 PMD_DRV_LOG(ERR, "Failed to clear FDIR RX queue context.");
138 err = i40e_set_lan_rx_queue_context(hw, rxq->reg_idx, &rx_ctx);
139 if (err != I40E_SUCCESS) {
140 PMD_DRV_LOG(ERR, "Failed to set FDIR RX queue context.");
143 rxq->qrx_tail = hw->hw_addr +
144 I40E_QRX_TAIL(rxq->vsi->base_queue);
147 /* Init the RX tail regieter. */
148 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
154 * i40e_fdir_setup - reserve and initialize the Flow Director resources
155 * @pf: board private structure
158 i40e_fdir_setup(struct i40e_pf *pf)
160 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
161 struct i40e_vsi *vsi;
162 int err = I40E_SUCCESS;
163 char z_name[RTE_MEMZONE_NAMESIZE];
164 const struct rte_memzone *mz = NULL;
165 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
167 if ((pf->flags & I40E_FLAG_FDIR) == 0) {
168 PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
169 return I40E_NOT_SUPPORTED;
172 PMD_DRV_LOG(INFO, "FDIR HW Capabilities: num_filters_guaranteed = %u,"
173 " num_filters_best_effort = %u.",
174 hw->func_caps.fd_filters_guaranteed,
175 hw->func_caps.fd_filters_best_effort);
177 vsi = pf->fdir.fdir_vsi;
179 PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
182 /* make new FDIR VSI */
183 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->main_vsi, 0);
185 PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
186 return I40E_ERR_NO_AVAILABLE_VSI;
188 pf->fdir.fdir_vsi = vsi;
190 /*Fdir tx queue setup*/
191 err = i40e_fdir_setup_tx_resources(pf);
193 PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
197 /*Fdir rx queue setup*/
198 err = i40e_fdir_setup_rx_resources(pf);
200 PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
204 err = i40e_tx_queue_init(pf->fdir.txq);
206 PMD_DRV_LOG(ERR, "Failed to do FDIR TX initialization.");
210 /* need switch on before dev start*/
211 err = i40e_switch_tx_queue(hw, vsi->base_queue, TRUE);
213 PMD_DRV_LOG(ERR, "Failed to do fdir TX switch on.");
217 /* Init the rx queue in hardware */
218 err = i40e_fdir_rx_queue_init(pf->fdir.rxq);
220 PMD_DRV_LOG(ERR, "Failed to do FDIR RX initialization.");
224 /* switch on rx queue */
225 err = i40e_switch_rx_queue(hw, vsi->base_queue, TRUE);
227 PMD_DRV_LOG(ERR, "Failed to do FDIR RX switch on.");
231 /* reserve memory for the fdir programming packet */
232 snprintf(z_name, sizeof(z_name), "%s_%s_%d",
233 eth_dev->device->driver->name,
235 eth_dev->data->port_id);
236 mz = i40e_memzone_reserve(z_name, I40E_FDIR_PKT_LEN, SOCKET_ID_ANY);
238 PMD_DRV_LOG(ERR, "Cannot init memzone for "
239 "flow director program packet.");
240 err = I40E_ERR_NO_MEMORY;
243 pf->fdir.prg_pkt = mz->addr;
244 pf->fdir.dma_addr = mz->iova;
246 pf->fdir.match_counter_index = I40E_COUNTER_INDEX_FDIR(hw->pf_id);
247 PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
252 i40e_dev_rx_queue_release(pf->fdir.rxq);
255 i40e_dev_tx_queue_release(pf->fdir.txq);
258 i40e_vsi_release(vsi);
259 pf->fdir.fdir_vsi = NULL;
264 * i40e_fdir_teardown - release the Flow Director resources
265 * @pf: board private structure
268 i40e_fdir_teardown(struct i40e_pf *pf)
270 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
271 struct i40e_vsi *vsi;
273 vsi = pf->fdir.fdir_vsi;
276 int err = i40e_switch_tx_queue(hw, vsi->base_queue, FALSE);
278 PMD_DRV_LOG(DEBUG, "Failed to do FDIR TX switch off");
279 err = i40e_switch_rx_queue(hw, vsi->base_queue, FALSE);
281 PMD_DRV_LOG(DEBUG, "Failed to do FDIR RX switch off");
282 i40e_dev_rx_queue_release(pf->fdir.rxq);
284 i40e_dev_tx_queue_release(pf->fdir.txq);
286 i40e_vsi_release(vsi);
287 pf->fdir.fdir_vsi = NULL;
290 /* check whether the flow director table in empty */
292 i40e_fdir_empty(struct i40e_hw *hw)
294 uint32_t guarant_cnt, best_cnt;
296 guarant_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
297 I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
298 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
299 best_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
300 I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
301 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
302 if (best_cnt + guarant_cnt > 0)
309 * Initialize the configuration about bytes stream extracted as flexible payload
313 i40e_init_flx_pld(struct i40e_pf *pf)
315 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
321 * Define the bytes stream extracted as flexible payload in
322 * field vector. By default, select 8 words from the beginning
323 * of payload as flexible payload.
325 for (i = I40E_FLXPLD_L2_IDX; i < I40E_MAX_FLXPLD_LAYER; i++) {
326 index = i * I40E_MAX_FLXPLD_FIED;
327 pf->fdir.flex_set[index].src_offset = 0;
328 pf->fdir.flex_set[index].size = I40E_FDIR_MAX_FLEXWORD_NUM;
329 pf->fdir.flex_set[index].dst_offset = 0;
330 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(index), 0x0000C900);
332 I40E_PRTQF_FLX_PIT(index + 1), 0x0000FC29);/*non-used*/
334 I40E_PRTQF_FLX_PIT(index + 2), 0x0000FC2A);/*non-used*/
337 /* initialize the masks */
338 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
339 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
340 flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
342 if (flow_type == RTE_ETH_FLOW_UNKNOWN)
344 pf->fdir.flex_mask[pctype].word_mask = 0;
345 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), 0);
346 for (i = 0; i < I40E_FDIR_BITMASK_NUM_WORD; i++) {
347 pf->fdir.flex_mask[pctype].bitmask[i].offset = 0;
348 pf->fdir.flex_mask[pctype].bitmask[i].mask = 0;
349 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), 0);
354 #define I40E_VALIDATE_FLEX_PIT(flex_pit1, flex_pit2) do { \
355 if ((flex_pit2).src_offset < \
356 (flex_pit1).src_offset + (flex_pit1).size) { \
357 PMD_DRV_LOG(ERR, "src_offset should be not" \
358 " less than than previous offset" \
359 " + previous FSIZE."); \
365 * i40e_srcoff_to_flx_pit - transform the src_offset into flex_pit structure,
366 * and the flex_pit will be sorted by it's src_offset value
368 static inline uint16_t
369 i40e_srcoff_to_flx_pit(const uint16_t *src_offset,
370 struct i40e_fdir_flex_pit *flex_pit)
372 uint16_t src_tmp, size, num = 0;
373 uint16_t i, k, j = 0;
375 while (j < I40E_FDIR_MAX_FLEX_LEN) {
377 for (; j < I40E_FDIR_MAX_FLEX_LEN - 1; j++) {
378 if (src_offset[j + 1] == src_offset[j] + 1)
383 src_tmp = src_offset[j] + 1 - size;
384 /* the flex_pit need to be sort by src_offset */
385 for (i = 0; i < num; i++) {
386 if (src_tmp < flex_pit[i].src_offset)
389 /* if insert required, move backward */
390 for (k = num; k > i; k--)
391 flex_pit[k] = flex_pit[k - 1];
393 flex_pit[i].dst_offset = j + 1 - size;
394 flex_pit[i].src_offset = src_tmp;
395 flex_pit[i].size = size;
402 /* i40e_check_fdir_flex_payload -check flex payload configuration arguments */
404 i40e_check_fdir_flex_payload(const struct rte_eth_flex_payload_cfg *flex_cfg)
406 struct i40e_fdir_flex_pit flex_pit[I40E_FDIR_MAX_FLEX_LEN];
409 for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i++) {
410 if (flex_cfg->src_offset[i] >= I40E_MAX_FLX_SOURCE_OFF) {
411 PMD_DRV_LOG(ERR, "exceeds maxmial payload limit.");
416 memset(flex_pit, 0, sizeof(flex_pit));
417 num = i40e_srcoff_to_flx_pit(flex_cfg->src_offset, flex_pit);
418 if (num > I40E_MAX_FLXPLD_FIED) {
419 PMD_DRV_LOG(ERR, "exceeds maxmial number of flex fields.");
422 for (i = 0; i < num; i++) {
423 if (flex_pit[i].size & 0x01 || flex_pit[i].dst_offset & 0x01 ||
424 flex_pit[i].src_offset & 0x01) {
425 PMD_DRV_LOG(ERR, "flexpayload should be measured"
430 I40E_VALIDATE_FLEX_PIT(flex_pit[i], flex_pit[i + 1]);
436 * i40e_check_fdir_flex_conf -check if the flex payload and mask configuration
437 * arguments are valid
440 i40e_check_fdir_flex_conf(const struct i40e_adapter *adapter,
441 const struct rte_eth_fdir_flex_conf *conf)
443 const struct rte_eth_flex_payload_cfg *flex_cfg;
444 const struct rte_eth_fdir_flex_mask *flex_mask;
449 enum i40e_filter_pctype pctype;
452 PMD_DRV_LOG(INFO, "NULL pointer.");
455 /* check flexible payload setting configuration */
456 if (conf->nb_payloads > RTE_ETH_L4_PAYLOAD) {
457 PMD_DRV_LOG(ERR, "invalid number of payload setting.");
460 for (i = 0; i < conf->nb_payloads; i++) {
461 flex_cfg = &conf->flex_set[i];
462 if (flex_cfg->type > RTE_ETH_L4_PAYLOAD) {
463 PMD_DRV_LOG(ERR, "invalid payload type.");
466 ret = i40e_check_fdir_flex_payload(flex_cfg);
468 PMD_DRV_LOG(ERR, "invalid flex payload arguments.");
473 /* check flex mask setting configuration */
474 if (conf->nb_flexmasks >= RTE_ETH_FLOW_MAX) {
475 PMD_DRV_LOG(ERR, "invalid number of flex masks.");
478 for (i = 0; i < conf->nb_flexmasks; i++) {
479 flex_mask = &conf->flex_mask[i];
480 pctype = i40e_flowtype_to_pctype(adapter, flex_mask->flow_type);
481 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
482 PMD_DRV_LOG(WARNING, "invalid flow type.");
486 for (j = 0; j < I40E_FDIR_MAX_FLEX_LEN; j += sizeof(uint16_t)) {
487 mask_tmp = I40E_WORD(flex_mask->mask[j],
488 flex_mask->mask[j + 1]);
489 if (mask_tmp != 0x0 && mask_tmp != UINT16_MAX) {
491 if (nb_bitmask > I40E_FDIR_BITMASK_NUM_WORD) {
492 PMD_DRV_LOG(ERR, " exceed maximal"
493 " number of bitmasks.");
503 * i40e_set_flx_pld_cfg -configure the rule how bytes stream is extracted as flexible payload
504 * @pf: board private structure
505 * @cfg: the rule how bytes stream is extracted as flexible payload
508 i40e_set_flx_pld_cfg(struct i40e_pf *pf,
509 const struct rte_eth_flex_payload_cfg *cfg)
511 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
512 struct i40e_fdir_flex_pit flex_pit[I40E_MAX_FLXPLD_FIED];
513 uint32_t flx_pit, flx_ort;
514 uint16_t num, min_next_off; /* in words */
515 uint8_t field_idx = 0;
516 uint8_t layer_idx = 0;
519 if (cfg->type == RTE_ETH_L2_PAYLOAD)
520 layer_idx = I40E_FLXPLD_L2_IDX;
521 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
522 layer_idx = I40E_FLXPLD_L3_IDX;
523 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
524 layer_idx = I40E_FLXPLD_L4_IDX;
526 memset(flex_pit, 0, sizeof(flex_pit));
527 num = RTE_MIN(i40e_srcoff_to_flx_pit(cfg->src_offset, flex_pit),
531 flx_ort = (1 << I40E_GLQF_ORT_FLX_PAYLOAD_SHIFT) |
532 (num << I40E_GLQF_ORT_FIELD_CNT_SHIFT) |
533 (layer_idx * I40E_MAX_FLXPLD_FIED);
534 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33 + layer_idx), flx_ort);
537 for (i = 0; i < num; i++) {
538 field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
539 /* record the info in fdir structure */
540 pf->fdir.flex_set[field_idx].src_offset =
541 flex_pit[i].src_offset / sizeof(uint16_t);
542 pf->fdir.flex_set[field_idx].size =
543 flex_pit[i].size / sizeof(uint16_t);
544 pf->fdir.flex_set[field_idx].dst_offset =
545 flex_pit[i].dst_offset / sizeof(uint16_t);
546 flx_pit = MK_FLX_PIT(pf->fdir.flex_set[field_idx].src_offset,
547 pf->fdir.flex_set[field_idx].size,
548 pf->fdir.flex_set[field_idx].dst_offset);
550 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
552 min_next_off = pf->fdir.flex_set[field_idx].src_offset +
553 pf->fdir.flex_set[field_idx].size;
555 for (; i < I40E_MAX_FLXPLD_FIED; i++) {
556 /* set the non-used register obeying register's constrain */
557 flx_pit = MK_FLX_PIT(min_next_off, NONUSE_FLX_PIT_FSIZE,
558 NONUSE_FLX_PIT_DEST_OFF);
560 I40E_PRTQF_FLX_PIT(layer_idx * I40E_MAX_FLXPLD_FIED + i),
567 * i40e_set_flex_mask_on_pctype - configure the mask on flexible payload
568 * @pf: board private structure
569 * @pctype: packet classify type
570 * @flex_masks: mask for flexible payload
573 i40e_set_flex_mask_on_pctype(struct i40e_pf *pf,
574 enum i40e_filter_pctype pctype,
575 const struct rte_eth_fdir_flex_mask *mask_cfg)
577 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
578 struct i40e_fdir_flex_mask *flex_mask;
579 uint32_t flxinset, fd_mask;
581 uint8_t i, nb_bitmask = 0;
583 flex_mask = &pf->fdir.flex_mask[pctype];
584 memset(flex_mask, 0, sizeof(struct i40e_fdir_flex_mask));
585 for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i += sizeof(uint16_t)) {
586 mask_tmp = I40E_WORD(mask_cfg->mask[i], mask_cfg->mask[i + 1]);
587 if (mask_tmp != 0x0) {
588 flex_mask->word_mask |=
589 I40E_FLEX_WORD_MASK(i / sizeof(uint16_t));
590 if (mask_tmp != UINT16_MAX) {
592 flex_mask->bitmask[nb_bitmask].mask = ~mask_tmp;
593 flex_mask->bitmask[nb_bitmask].offset =
594 i / sizeof(uint16_t);
599 /* write mask to hw */
600 flxinset = (flex_mask->word_mask <<
601 I40E_PRTQF_FD_FLXINSET_INSET_SHIFT) &
602 I40E_PRTQF_FD_FLXINSET_INSET_MASK;
603 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), flxinset);
605 for (i = 0; i < nb_bitmask; i++) {
606 fd_mask = (flex_mask->bitmask[i].mask <<
607 I40E_PRTQF_FD_MSK_MASK_SHIFT) &
608 I40E_PRTQF_FD_MSK_MASK_MASK;
609 fd_mask |= ((flex_mask->bitmask[i].offset +
610 I40E_FLX_OFFSET_IN_FIELD_VECTOR) <<
611 I40E_PRTQF_FD_MSK_OFFSET_SHIFT) &
612 I40E_PRTQF_FD_MSK_OFFSET_MASK;
613 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), fd_mask);
618 * Enable/disable flow director RX processing in vector routines.
621 i40e_fdir_rx_proc_enable(struct rte_eth_dev *dev, bool on)
625 for (i = 0; i < dev->data->nb_rx_queues; i++) {
626 struct i40e_rx_queue *rxq = dev->data->rx_queues[i];
629 rxq->fdir_enabled = on;
631 PMD_DRV_LOG(DEBUG, "Flow Director processing on RX set to %d", on);
635 * Configure flow director related setting
638 i40e_fdir_configure(struct rte_eth_dev *dev)
640 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
641 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
642 struct rte_eth_fdir_flex_conf *conf;
643 enum i40e_filter_pctype pctype;
649 * configuration need to be done before
650 * flow director filters are added
651 * If filters exist, flush them.
653 if (i40e_fdir_empty(hw) < 0) {
654 ret = i40e_fdir_flush(dev);
656 PMD_DRV_LOG(ERR, "failed to flush fdir table.");
661 /* enable FDIR filter */
662 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
663 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
664 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
666 i40e_init_flx_pld(pf); /* set flex config to default value */
668 conf = &dev->data->dev_conf.fdir_conf.flex_conf;
669 ret = i40e_check_fdir_flex_conf(pf->adapter, conf);
671 PMD_DRV_LOG(ERR, " invalid configuration arguments.");
675 if (!pf->support_multi_driver) {
676 /* configure flex payload */
677 for (i = 0; i < conf->nb_payloads; i++)
678 i40e_set_flx_pld_cfg(pf, &conf->flex_set[i]);
679 /* configure flex mask*/
680 for (i = 0; i < conf->nb_flexmasks; i++) {
681 if (hw->mac.type == I40E_MAC_X722) {
682 /* get pctype value in fd pctype register */
683 pctype = (enum i40e_filter_pctype)
685 I40E_GLQF_FD_PCTYPES(
686 (int)i40e_flowtype_to_pctype(
688 conf->flex_mask[i].flow_type)));
690 pctype = i40e_flowtype_to_pctype(pf->adapter,
691 conf->flex_mask[i].flow_type);
694 i40e_set_flex_mask_on_pctype(pf, pctype,
695 &conf->flex_mask[i]);
698 PMD_DRV_LOG(ERR, "Not support flexible payload.");
701 /* Enable FDIR processing in RX routines */
702 i40e_fdir_rx_proc_enable(dev, 1);
708 i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
709 unsigned char *raw_pkt,
712 static uint8_t vlan_frame[] = {0x81, 0, 0, 0};
713 uint16_t *ether_type;
714 uint8_t len = 2 * sizeof(struct rte_ether_addr);
715 struct rte_ipv4_hdr *ip;
716 struct rte_ipv6_hdr *ip6;
717 static const uint8_t next_proto[] = {
718 [RTE_ETH_FLOW_FRAG_IPV4] = IPPROTO_IP,
719 [RTE_ETH_FLOW_NONFRAG_IPV4_TCP] = IPPROTO_TCP,
720 [RTE_ETH_FLOW_NONFRAG_IPV4_UDP] = IPPROTO_UDP,
721 [RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] = IPPROTO_SCTP,
722 [RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] = IPPROTO_IP,
723 [RTE_ETH_FLOW_FRAG_IPV6] = IPPROTO_NONE,
724 [RTE_ETH_FLOW_NONFRAG_IPV6_TCP] = IPPROTO_TCP,
725 [RTE_ETH_FLOW_NONFRAG_IPV6_UDP] = IPPROTO_UDP,
726 [RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] = IPPROTO_SCTP,
727 [RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] = IPPROTO_NONE,
730 raw_pkt += 2 * sizeof(struct rte_ether_addr);
731 if (vlan && fdir_input->flow_ext.vlan_tci) {
732 rte_memcpy(raw_pkt, vlan_frame, sizeof(vlan_frame));
733 rte_memcpy(raw_pkt + sizeof(uint16_t),
734 &fdir_input->flow_ext.vlan_tci,
736 raw_pkt += sizeof(vlan_frame);
737 len += sizeof(vlan_frame);
739 ether_type = (uint16_t *)raw_pkt;
740 raw_pkt += sizeof(uint16_t);
741 len += sizeof(uint16_t);
743 switch (fdir_input->flow_type) {
744 case RTE_ETH_FLOW_L2_PAYLOAD:
745 *ether_type = fdir_input->flow.l2_flow.ether_type;
747 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
748 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
749 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
750 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
751 case RTE_ETH_FLOW_FRAG_IPV4:
752 ip = (struct rte_ipv4_hdr *)raw_pkt;
754 *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
755 ip->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
756 /* set len to by default */
757 ip->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
758 ip->next_proto_id = fdir_input->flow.ip4_flow.proto ?
759 fdir_input->flow.ip4_flow.proto :
760 next_proto[fdir_input->flow_type];
761 ip->time_to_live = fdir_input->flow.ip4_flow.ttl ?
762 fdir_input->flow.ip4_flow.ttl :
763 I40E_FDIR_IP_DEFAULT_TTL;
764 ip->type_of_service = fdir_input->flow.ip4_flow.tos;
766 * The source and destination fields in the transmitted packet
767 * need to be presented in a reversed order with respect
768 * to the expected received packets.
770 ip->src_addr = fdir_input->flow.ip4_flow.dst_ip;
771 ip->dst_addr = fdir_input->flow.ip4_flow.src_ip;
772 len += sizeof(struct rte_ipv4_hdr);
774 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
775 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
776 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
777 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
778 case RTE_ETH_FLOW_FRAG_IPV6:
779 ip6 = (struct rte_ipv6_hdr *)raw_pkt;
781 *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
783 rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
784 (fdir_input->flow.ipv6_flow.tc <<
785 I40E_FDIR_IPv6_TC_OFFSET));
787 rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
788 ip6->proto = fdir_input->flow.ipv6_flow.proto ?
789 fdir_input->flow.ipv6_flow.proto :
790 next_proto[fdir_input->flow_type];
791 ip6->hop_limits = fdir_input->flow.ipv6_flow.hop_limits ?
792 fdir_input->flow.ipv6_flow.hop_limits :
793 I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
795 * The source and destination fields in the transmitted packet
796 * need to be presented in a reversed order with respect
797 * to the expected received packets.
799 rte_memcpy(&(ip6->src_addr),
800 &(fdir_input->flow.ipv6_flow.dst_ip),
802 rte_memcpy(&(ip6->dst_addr),
803 &(fdir_input->flow.ipv6_flow.src_ip),
805 len += sizeof(struct rte_ipv6_hdr);
808 PMD_DRV_LOG(ERR, "unknown flow type %u.",
809 fdir_input->flow_type);
817 * i40e_fdir_construct_pkt - construct packet based on fields in input
818 * @pf: board private structure
819 * @fdir_input: input set of the flow director entry
820 * @raw_pkt: a packet to be constructed
823 i40e_fdir_construct_pkt(struct i40e_pf *pf,
824 const struct rte_eth_fdir_input *fdir_input,
825 unsigned char *raw_pkt)
827 unsigned char *payload, *ptr;
828 struct rte_udp_hdr *udp;
829 struct rte_tcp_hdr *tcp;
830 struct rte_sctp_hdr *sctp;
831 uint8_t size, dst = 0;
832 uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
835 /* fill the ethernet and IP head */
836 len = i40e_fdir_fill_eth_ip_head(fdir_input, raw_pkt,
837 !!fdir_input->flow_ext.vlan_tci);
841 /* fill the L4 head */
842 switch (fdir_input->flow_type) {
843 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
844 udp = (struct rte_udp_hdr *)(raw_pkt + len);
845 payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
847 * The source and destination fields in the transmitted packet
848 * need to be presented in a reversed order with respect
849 * to the expected received packets.
851 udp->src_port = fdir_input->flow.udp4_flow.dst_port;
852 udp->dst_port = fdir_input->flow.udp4_flow.src_port;
853 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
856 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
857 tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
858 payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
860 * The source and destination fields in the transmitted packet
861 * need to be presented in a reversed order with respect
862 * to the expected received packets.
864 tcp->src_port = fdir_input->flow.tcp4_flow.dst_port;
865 tcp->dst_port = fdir_input->flow.tcp4_flow.src_port;
866 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
869 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
870 sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
871 payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
873 * The source and destination fields in the transmitted packet
874 * need to be presented in a reversed order with respect
875 * to the expected received packets.
877 sctp->src_port = fdir_input->flow.sctp4_flow.dst_port;
878 sctp->dst_port = fdir_input->flow.sctp4_flow.src_port;
879 sctp->tag = fdir_input->flow.sctp4_flow.verify_tag;
882 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
883 case RTE_ETH_FLOW_FRAG_IPV4:
884 payload = raw_pkt + len;
885 set_idx = I40E_FLXPLD_L3_IDX;
888 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
889 udp = (struct rte_udp_hdr *)(raw_pkt + len);
890 payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
892 * The source and destination fields in the transmitted packet
893 * need to be presented in a reversed order with respect
894 * to the expected received packets.
896 udp->src_port = fdir_input->flow.udp6_flow.dst_port;
897 udp->dst_port = fdir_input->flow.udp6_flow.src_port;
898 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
901 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
902 tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
903 payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
905 * The source and destination fields in the transmitted packet
906 * need to be presented in a reversed order with respect
907 * to the expected received packets.
909 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
910 tcp->src_port = fdir_input->flow.udp6_flow.dst_port;
911 tcp->dst_port = fdir_input->flow.udp6_flow.src_port;
914 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
915 sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
916 payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
918 * The source and destination fields in the transmitted packet
919 * need to be presented in a reversed order with respect
920 * to the expected received packets.
922 sctp->src_port = fdir_input->flow.sctp6_flow.dst_port;
923 sctp->dst_port = fdir_input->flow.sctp6_flow.src_port;
924 sctp->tag = fdir_input->flow.sctp6_flow.verify_tag;
927 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
928 case RTE_ETH_FLOW_FRAG_IPV6:
929 payload = raw_pkt + len;
930 set_idx = I40E_FLXPLD_L3_IDX;
932 case RTE_ETH_FLOW_L2_PAYLOAD:
933 payload = raw_pkt + len;
935 * ARP packet is a special case on which the payload
936 * starts after the whole ARP header
938 if (fdir_input->flow.l2_flow.ether_type ==
939 rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP))
940 payload += sizeof(struct rte_arp_hdr);
941 set_idx = I40E_FLXPLD_L2_IDX;
944 PMD_DRV_LOG(ERR, "unknown flow type %u.", fdir_input->flow_type);
948 /* fill the flexbytes to payload */
949 for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
950 pit_idx = set_idx * I40E_MAX_FLXPLD_FIED + i;
951 size = pf->fdir.flex_set[pit_idx].size;
954 dst = pf->fdir.flex_set[pit_idx].dst_offset * sizeof(uint16_t);
956 pf->fdir.flex_set[pit_idx].src_offset * sizeof(uint16_t);
958 &fdir_input->flow_ext.flexbytes[dst],
959 size * sizeof(uint16_t));
965 static struct i40e_customized_pctype *
966 i40e_flow_fdir_find_customized_pctype(struct i40e_pf *pf, uint8_t pctype)
968 struct i40e_customized_pctype *cus_pctype;
969 enum i40e_new_pctype i = I40E_CUSTOMIZED_GTPC;
971 for (; i < I40E_CUSTOMIZED_MAX; i++) {
972 cus_pctype = &pf->customized_pctype[i];
973 if (pctype == cus_pctype->pctype)
980 fill_ip6_head(const struct i40e_fdir_input *fdir_input, unsigned char *raw_pkt,
981 uint8_t next_proto, uint8_t len, uint16_t *ether_type)
983 struct rte_ipv6_hdr *ip6;
985 ip6 = (struct rte_ipv6_hdr *)raw_pkt;
987 *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
988 ip6->vtc_flow = rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
989 (fdir_input->flow.ipv6_flow.tc << I40E_FDIR_IPv6_TC_OFFSET));
990 ip6->payload_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
991 ip6->proto = fdir_input->flow.ipv6_flow.proto ?
992 fdir_input->flow.ipv6_flow.proto : next_proto;
993 ip6->hop_limits = fdir_input->flow.ipv6_flow.hop_limits ?
994 fdir_input->flow.ipv6_flow.hop_limits :
995 I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
997 * The source and destination fields in the transmitted packet
998 * need to be presented in a reversed order with respect
999 * to the expected received packets.
1001 rte_memcpy(&ip6->src_addr, &fdir_input->flow.ipv6_flow.dst_ip,
1003 rte_memcpy(&ip6->dst_addr, &fdir_input->flow.ipv6_flow.src_ip,
1005 len += sizeof(struct rte_ipv6_hdr);
1011 i40e_flow_fdir_fill_eth_ip_head(struct i40e_pf *pf,
1012 const struct i40e_fdir_input *fdir_input,
1013 unsigned char *raw_pkt,
1016 struct i40e_customized_pctype *cus_pctype = NULL;
1017 static uint8_t vlan_frame[] = {0x81, 0, 0, 0};
1018 uint16_t *ether_type;
1019 uint8_t len = 2 * sizeof(struct rte_ether_addr);
1020 struct rte_ipv4_hdr *ip;
1021 struct rte_ipv6_hdr *ip6;
1022 uint8_t pctype = fdir_input->pctype;
1023 bool is_customized_pctype = fdir_input->flow_ext.customized_pctype;
1024 static const uint8_t next_proto[] = {
1025 [I40E_FILTER_PCTYPE_FRAG_IPV4] = IPPROTO_IP,
1026 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] = IPPROTO_TCP,
1027 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] = IPPROTO_UDP,
1028 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] = IPPROTO_SCTP,
1029 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] = IPPROTO_IP,
1030 [I40E_FILTER_PCTYPE_FRAG_IPV6] = IPPROTO_NONE,
1031 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] = IPPROTO_TCP,
1032 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] = IPPROTO_UDP,
1033 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] = IPPROTO_SCTP,
1034 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] = IPPROTO_NONE,
1037 raw_pkt += 2 * sizeof(struct rte_ether_addr);
1038 if (vlan && fdir_input->flow_ext.vlan_tci) {
1039 rte_memcpy(raw_pkt, vlan_frame, sizeof(vlan_frame));
1040 rte_memcpy(raw_pkt + sizeof(uint16_t),
1041 &fdir_input->flow_ext.vlan_tci,
1043 raw_pkt += sizeof(vlan_frame);
1044 len += sizeof(vlan_frame);
1046 ether_type = (uint16_t *)raw_pkt;
1047 raw_pkt += sizeof(uint16_t);
1048 len += sizeof(uint16_t);
1050 if (is_customized_pctype) {
1051 cus_pctype = i40e_flow_fdir_find_customized_pctype(pf, pctype);
1053 PMD_DRV_LOG(ERR, "unknown pctype %u.",
1054 fdir_input->pctype);
1059 if (pctype == I40E_FILTER_PCTYPE_L2_PAYLOAD)
1060 *ether_type = fdir_input->flow.l2_flow.ether_type;
1061 else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP ||
1062 pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP ||
1063 pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP ||
1064 pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
1065 pctype == I40E_FILTER_PCTYPE_FRAG_IPV4 ||
1066 ((is_customized_pctype) &&
1067 ((cus_pctype->index == I40E_CUSTOMIZED_GTPC) ||
1068 (cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4) ||
1069 (cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6) ||
1070 (cus_pctype->index == I40E_CUSTOMIZED_GTPU) ||
1071 (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3)))) {
1072 ip = (struct rte_ipv4_hdr *)raw_pkt;
1074 *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
1075 ip->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
1076 /* set len to by default */
1077 ip->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
1078 ip->time_to_live = fdir_input->flow.ip4_flow.ttl ?
1079 fdir_input->flow.ip4_flow.ttl :
1080 I40E_FDIR_IP_DEFAULT_TTL;
1081 ip->type_of_service = fdir_input->flow.ip4_flow.tos;
1083 * The source and destination fields in the transmitted packet
1084 * need to be presented in a reversed order with respect
1085 * to the expected received packets.
1087 ip->src_addr = fdir_input->flow.ip4_flow.dst_ip;
1088 ip->dst_addr = fdir_input->flow.ip4_flow.src_ip;
1090 if (!is_customized_pctype) {
1091 ip->next_proto_id = fdir_input->flow.ip4_flow.proto ?
1092 fdir_input->flow.ip4_flow.proto :
1093 next_proto[fdir_input->pctype];
1094 len += sizeof(struct rte_ipv4_hdr);
1095 } else if (cus_pctype->index == I40E_CUSTOMIZED_GTPC ||
1096 cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4 ||
1097 cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6 ||
1098 cus_pctype->index == I40E_CUSTOMIZED_GTPU) {
1099 ip->next_proto_id = IPPROTO_UDP;
1100 len += sizeof(struct rte_ipv4_hdr);
1101 } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3) {
1102 ip->next_proto_id = IPPROTO_L2TP;
1103 len += sizeof(struct rte_ipv4_hdr);
1104 } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4) {
1105 ip->next_proto_id = IPPROTO_ESP;
1106 len += sizeof(struct rte_ipv4_hdr);
1107 } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4_UDP) {
1108 ip->next_proto_id = IPPROTO_UDP;
1109 len += sizeof(struct rte_ipv4_hdr);
1110 } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6)
1111 len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_ESP,
1113 else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP)
1114 len = fill_ip6_head(fdir_input, raw_pkt, IPPROTO_UDP,
1116 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP ||
1117 pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP ||
1118 pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP ||
1119 pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
1120 pctype == I40E_FILTER_PCTYPE_FRAG_IPV6 ||
1121 ((is_customized_pctype) &&
1122 (cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3))) {
1123 ip6 = (struct rte_ipv6_hdr *)raw_pkt;
1125 *ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
1127 rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
1128 (fdir_input->flow.ipv6_flow.tc <<
1129 I40E_FDIR_IPv6_TC_OFFSET));
1131 rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
1132 if (!is_customized_pctype)
1133 ip6->proto = fdir_input->flow.ipv6_flow.proto ?
1134 fdir_input->flow.ipv6_flow.proto :
1135 next_proto[fdir_input->pctype];
1136 else if (cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3)
1137 ip6->proto = IPPROTO_L2TP;
1138 ip6->hop_limits = fdir_input->flow.ipv6_flow.hop_limits ?
1139 fdir_input->flow.ipv6_flow.hop_limits :
1140 I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
1142 * The source and destination fields in the transmitted packet
1143 * need to be presented in a reversed order with respect
1144 * to the expected received packets.
1146 rte_memcpy(&ip6->src_addr,
1147 &fdir_input->flow.ipv6_flow.dst_ip,
1149 rte_memcpy(&ip6->dst_addr,
1150 &fdir_input->flow.ipv6_flow.src_ip,
1152 len += sizeof(struct rte_ipv6_hdr);
1154 PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
1162 * i40e_flow_fdir_construct_pkt - construct packet based on fields in input
1163 * @pf: board private structure
1164 * @fdir_input: input set of the flow director entry
1165 * @raw_pkt: a packet to be constructed
1168 i40e_flow_fdir_construct_pkt(struct i40e_pf *pf,
1169 const struct i40e_fdir_input *fdir_input,
1170 unsigned char *raw_pkt)
1172 unsigned char *payload = NULL;
1174 struct rte_udp_hdr *udp;
1175 struct rte_tcp_hdr *tcp;
1176 struct rte_sctp_hdr *sctp;
1177 struct rte_flow_item_gtp *gtp;
1178 struct rte_ipv4_hdr *gtp_ipv4;
1179 struct rte_ipv6_hdr *gtp_ipv6;
1180 struct rte_flow_item_l2tpv3oip *l2tpv3oip;
1181 struct rte_flow_item_esp *esp;
1182 struct rte_ipv4_hdr *esp_ipv4;
1183 struct rte_ipv6_hdr *esp_ipv6;
1185 uint8_t size, dst = 0;
1186 uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
1188 uint8_t pctype = fdir_input->pctype;
1189 struct i40e_customized_pctype *cus_pctype;
1191 /* raw pcket template - just copy contents of the raw packet */
1192 if (fdir_input->flow_ext.pkt_template) {
1193 memcpy(raw_pkt, fdir_input->flow.raw_flow.packet,
1194 fdir_input->flow.raw_flow.length);
1198 /* fill the ethernet and IP head */
1199 len = i40e_flow_fdir_fill_eth_ip_head(pf, fdir_input, raw_pkt,
1200 !!fdir_input->flow_ext.vlan_tci);
1204 /* fill the L4 head */
1205 if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_UDP) {
1206 udp = (struct rte_udp_hdr *)(raw_pkt + len);
1207 payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
1209 * The source and destination fields in the transmitted packet
1210 * need to be presented in a reversed order with respect
1211 * to the expected received packets.
1213 udp->src_port = fdir_input->flow.udp4_flow.dst_port;
1214 udp->dst_port = fdir_input->flow.udp4_flow.src_port;
1215 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
1216 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_TCP) {
1217 tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
1218 payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
1220 * The source and destination fields in the transmitted packet
1221 * need to be presented in a reversed order with respect
1222 * to the expected received packets.
1224 tcp->src_port = fdir_input->flow.tcp4_flow.dst_port;
1225 tcp->dst_port = fdir_input->flow.tcp4_flow.src_port;
1226 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
1227 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) {
1228 sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
1229 payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
1231 * The source and destination fields in the transmitted packet
1232 * need to be presented in a reversed order with respect
1233 * to the expected received packets.
1235 sctp->src_port = fdir_input->flow.sctp4_flow.dst_port;
1236 sctp->dst_port = fdir_input->flow.sctp4_flow.src_port;
1237 sctp->tag = fdir_input->flow.sctp4_flow.verify_tag;
1238 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER ||
1239 pctype == I40E_FILTER_PCTYPE_FRAG_IPV4) {
1240 payload = raw_pkt + len;
1241 set_idx = I40E_FLXPLD_L3_IDX;
1242 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_UDP) {
1243 udp = (struct rte_udp_hdr *)(raw_pkt + len);
1244 payload = (unsigned char *)udp + sizeof(struct rte_udp_hdr);
1246 * The source and destination fields in the transmitted packet
1247 * need to be presented in a reversed order with respect
1248 * to the expected received packets.
1250 udp->src_port = fdir_input->flow.udp6_flow.dst_port;
1251 udp->dst_port = fdir_input->flow.udp6_flow.src_port;
1252 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
1253 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_TCP) {
1254 tcp = (struct rte_tcp_hdr *)(raw_pkt + len);
1255 payload = (unsigned char *)tcp + sizeof(struct rte_tcp_hdr);
1257 * The source and destination fields in the transmitted packet
1258 * need to be presented in a reversed order with respect
1259 * to the expected received packets.
1261 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
1262 tcp->src_port = fdir_input->flow.udp6_flow.dst_port;
1263 tcp->dst_port = fdir_input->flow.udp6_flow.src_port;
1264 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) {
1265 sctp = (struct rte_sctp_hdr *)(raw_pkt + len);
1266 payload = (unsigned char *)sctp + sizeof(struct rte_sctp_hdr);
1268 * The source and destination fields in the transmitted packet
1269 * need to be presented in a reversed order with respect
1270 * to the expected received packets.
1272 sctp->src_port = fdir_input->flow.sctp6_flow.dst_port;
1273 sctp->dst_port = fdir_input->flow.sctp6_flow.src_port;
1274 sctp->tag = fdir_input->flow.sctp6_flow.verify_tag;
1275 } else if (pctype == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER ||
1276 pctype == I40E_FILTER_PCTYPE_FRAG_IPV6) {
1277 payload = raw_pkt + len;
1278 set_idx = I40E_FLXPLD_L3_IDX;
1279 } else if (pctype == I40E_FILTER_PCTYPE_L2_PAYLOAD) {
1280 payload = raw_pkt + len;
1282 * ARP packet is a special case on which the payload
1283 * starts after the whole ARP header
1285 if (fdir_input->flow.l2_flow.ether_type ==
1286 rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP))
1287 payload += sizeof(struct rte_arp_hdr);
1288 set_idx = I40E_FLXPLD_L2_IDX;
1289 } else if (fdir_input->flow_ext.customized_pctype) {
1290 /* If customized pctype is used */
1291 cus_pctype = i40e_flow_fdir_find_customized_pctype(pf, pctype);
1292 if (cus_pctype->index == I40E_CUSTOMIZED_GTPC ||
1293 cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4 ||
1294 cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV6 ||
1295 cus_pctype->index == I40E_CUSTOMIZED_GTPU) {
1296 udp = (struct rte_udp_hdr *)(raw_pkt + len);
1298 rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
1300 gtp = (struct rte_flow_item_gtp *)
1301 ((unsigned char *)udp +
1302 sizeof(struct rte_udp_hdr));
1304 rte_cpu_to_be_16(I40E_FDIR_GTP_DEFAULT_LEN);
1305 gtp->teid = fdir_input->flow.gtp_flow.teid;
1306 gtp->msg_type = I40E_FDIR_GTP_MSG_TYPE_0X01;
1308 /* GTP-C message type is not supported. */
1309 if (cus_pctype->index == I40E_CUSTOMIZED_GTPC) {
1311 rte_cpu_to_be_16(I40E_FDIR_GTPC_DST_PORT);
1312 gtp->v_pt_rsv_flags =
1313 I40E_FDIR_GTP_VER_FLAG_0X32;
1316 rte_cpu_to_be_16(I40E_FDIR_GTPU_DST_PORT);
1317 gtp->v_pt_rsv_flags =
1318 I40E_FDIR_GTP_VER_FLAG_0X30;
1321 if (cus_pctype->index == I40E_CUSTOMIZED_GTPU_IPV4) {
1322 gtp->msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
1323 gtp_ipv4 = (struct rte_ipv4_hdr *)
1324 ((unsigned char *)gtp +
1325 sizeof(struct rte_flow_item_gtp));
1326 gtp_ipv4->version_ihl =
1327 I40E_FDIR_IP_DEFAULT_VERSION_IHL;
1328 gtp_ipv4->next_proto_id = IPPROTO_IP;
1329 gtp_ipv4->total_length =
1331 I40E_FDIR_INNER_IP_DEFAULT_LEN);
1332 payload = (unsigned char *)gtp_ipv4 +
1333 sizeof(struct rte_ipv4_hdr);
1334 } else if (cus_pctype->index ==
1335 I40E_CUSTOMIZED_GTPU_IPV6) {
1336 gtp->msg_type = I40E_FDIR_GTP_MSG_TYPE_0XFF;
1337 gtp_ipv6 = (struct rte_ipv6_hdr *)
1338 ((unsigned char *)gtp +
1339 sizeof(struct rte_flow_item_gtp));
1340 gtp_ipv6->vtc_flow =
1342 I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
1343 (0 << I40E_FDIR_IPv6_TC_OFFSET));
1344 gtp_ipv6->proto = IPPROTO_NONE;
1345 gtp_ipv6->payload_len =
1347 I40E_FDIR_INNER_IPV6_DEFAULT_LEN);
1348 gtp_ipv6->hop_limits =
1349 I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
1350 payload = (unsigned char *)gtp_ipv6 +
1351 sizeof(struct rte_ipv6_hdr);
1353 payload = (unsigned char *)gtp +
1354 sizeof(struct rte_flow_item_gtp);
1355 } else if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3 ||
1356 cus_pctype->index == I40E_CUSTOMIZED_IPV6_L2TPV3) {
1357 l2tpv3oip = (struct rte_flow_item_l2tpv3oip *)(raw_pkt
1360 if (cus_pctype->index == I40E_CUSTOMIZED_IPV4_L2TPV3)
1361 l2tpv3oip->session_id =
1362 fdir_input->flow.ip4_l2tpv3oip_flow.session_id;
1364 l2tpv3oip->session_id =
1365 fdir_input->flow.ip6_l2tpv3oip_flow.session_id;
1366 payload = (unsigned char *)l2tpv3oip +
1367 sizeof(struct rte_flow_item_l2tpv3oip);
1368 } else if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4 ||
1369 cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6 ||
1370 cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4_UDP ||
1371 cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV6_UDP) {
1372 if (cus_pctype->index == I40E_CUSTOMIZED_ESP_IPV4) {
1373 esp_ipv4 = (struct rte_ipv4_hdr *)
1375 esp = (struct rte_flow_item_esp *)esp_ipv4;
1377 fdir_input->flow.esp_ipv4_flow.spi;
1378 payload = (unsigned char *)esp +
1379 sizeof(struct rte_esp_hdr);
1380 len += sizeof(struct rte_esp_hdr);
1381 } else if (cus_pctype->index ==
1382 I40E_CUSTOMIZED_ESP_IPV4_UDP) {
1383 esp_ipv4 = (struct rte_ipv4_hdr *)
1385 udp = (struct rte_udp_hdr *)esp_ipv4;
1386 udp->dst_port = rte_cpu_to_be_16
1387 (I40E_FDIR_ESP_DST_PORT);
1389 udp->dgram_len = rte_cpu_to_be_16
1390 (I40E_FDIR_UDP_DEFAULT_LEN);
1391 esp = (struct rte_flow_item_esp *)
1392 ((unsigned char *)esp_ipv4 +
1393 sizeof(struct rte_udp_hdr));
1395 fdir_input->flow.esp_ipv4_udp_flow.spi;
1396 payload = (unsigned char *)esp +
1397 sizeof(struct rte_esp_hdr);
1398 len += sizeof(struct rte_udp_hdr) +
1399 sizeof(struct rte_esp_hdr);
1400 } else if (cus_pctype->index ==
1401 I40E_CUSTOMIZED_ESP_IPV6) {
1402 esp_ipv6 = (struct rte_ipv6_hdr *)
1404 esp = (struct rte_flow_item_esp *)esp_ipv6;
1406 fdir_input->flow.esp_ipv6_flow.spi;
1407 payload = (unsigned char *)esp +
1408 sizeof(struct rte_esp_hdr);
1409 len += sizeof(struct rte_esp_hdr);
1410 } else if (cus_pctype->index ==
1411 I40E_CUSTOMIZED_ESP_IPV6_UDP) {
1412 esp_ipv6 = (struct rte_ipv6_hdr *)
1414 udp = (struct rte_udp_hdr *)esp_ipv6;
1415 udp->dst_port = rte_cpu_to_be_16
1416 (I40E_FDIR_ESP_DST_PORT);
1418 udp->dgram_len = rte_cpu_to_be_16
1419 (I40E_FDIR_UDP_DEFAULT_LEN);
1420 esp = (struct rte_flow_item_esp *)
1421 ((unsigned char *)esp_ipv6 +
1422 sizeof(struct rte_udp_hdr));
1424 fdir_input->flow.esp_ipv6_udp_flow.spi;
1425 payload = (unsigned char *)esp +
1426 sizeof(struct rte_esp_hdr);
1427 len += sizeof(struct rte_udp_hdr) +
1428 sizeof(struct rte_esp_hdr);
1432 PMD_DRV_LOG(ERR, "unknown pctype %u.", fdir_input->pctype);
1436 /* fill the flexbytes to payload */
1437 for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
1438 pit_idx = set_idx * I40E_MAX_FLXPLD_FIED + i;
1439 size = pf->fdir.flex_set[pit_idx].size;
1442 dst = pf->fdir.flex_set[pit_idx].dst_offset * sizeof(uint16_t);
1444 pf->fdir.flex_set[pit_idx].src_offset * sizeof(uint16_t);
1445 (void)rte_memcpy(ptr,
1446 &fdir_input->flow_ext.flexbytes[dst],
1447 size * sizeof(uint16_t));
1453 /* Construct the tx flags */
1454 static inline uint64_t
1455 i40e_build_ctob(uint32_t td_cmd,
1460 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
1461 ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
1462 ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
1463 ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
1464 ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
1468 * check the programming status descriptor in rx queue.
1469 * done after Programming Flow Director is programmed on
1473 i40e_check_fdir_programming_status(struct i40e_rx_queue *rxq)
1475 volatile union i40e_rx_desc *rxdp;
1482 rxdp = &rxq->rx_ring[rxq->rx_tail];
1483 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
1484 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
1485 >> I40E_RXD_QW1_STATUS_SHIFT;
1487 if (rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
1488 len = qword1 >> I40E_RX_PROG_STATUS_DESC_LENGTH_SHIFT;
1489 id = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >>
1490 I40E_RX_PROG_STATUS_DESC_QW1_PROGID_SHIFT;
1492 if (len == I40E_RX_PROG_STATUS_DESC_LENGTH &&
1493 id == I40E_RX_PROG_STATUS_DESC_FD_FILTER_STATUS) {
1495 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
1496 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
1497 if (error == (0x1 <<
1498 I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
1499 PMD_DRV_LOG(ERR, "Failed to add FDIR filter"
1500 " (FD_ID %u): programming status"
1502 rxdp->wb.qword0.hi_dword.fd_id);
1504 } else if (error == (0x1 <<
1505 I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
1506 PMD_DRV_LOG(ERR, "Failed to delete FDIR filter"
1507 " (FD_ID %u): programming status"
1509 rxdp->wb.qword0.hi_dword.fd_id);
1512 PMD_DRV_LOG(ERR, "invalid programming status"
1513 " reported, error = %u.", error);
1515 PMD_DRV_LOG(INFO, "unknown programming status"
1516 " reported, len = %d, id = %u.", len, id);
1517 rxdp->wb.qword1.status_error_len = 0;
1519 if (unlikely(rxq->rx_tail == rxq->nb_rx_desc))
1521 if (rxq->rx_tail == 0)
1522 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1524 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_tail - 1);
1531 i40e_fdir_filter_convert(const struct i40e_fdir_filter_conf *input,
1532 struct i40e_fdir_filter *filter)
1534 rte_memcpy(&filter->fdir, input, sizeof(struct i40e_fdir_filter_conf));
1535 if (input->input.flow_ext.pkt_template) {
1536 filter->fdir.input.flow.raw_flow.packet = NULL;
1537 filter->fdir.input.flow.raw_flow.length =
1538 rte_hash_crc(input->input.flow.raw_flow.packet,
1539 input->input.flow.raw_flow.length,
1540 input->input.flow.raw_flow.pctype);
1545 /* Check if there exists the flow director filter */
1546 static struct i40e_fdir_filter *
1547 i40e_sw_fdir_filter_lookup(struct i40e_fdir_info *fdir_info,
1548 const struct i40e_fdir_input *input)
1552 if (input->flow_ext.pkt_template)
1553 ret = rte_hash_lookup_with_hash(fdir_info->hash_table,
1554 (const void *)input,
1555 input->flow.raw_flow.length);
1557 ret = rte_hash_lookup(fdir_info->hash_table,
1558 (const void *)input);
1562 return fdir_info->hash_map[ret];
1565 /* Add a flow director filter into the SW list */
1567 i40e_sw_fdir_filter_insert(struct i40e_pf *pf, struct i40e_fdir_filter *filter)
1569 struct i40e_fdir_info *fdir_info = &pf->fdir;
1572 if (filter->fdir.input.flow_ext.pkt_template)
1573 ret = rte_hash_add_key_with_hash(fdir_info->hash_table,
1574 &filter->fdir.input,
1575 filter->fdir.input.flow.raw_flow.length);
1577 ret = rte_hash_add_key(fdir_info->hash_table,
1578 &filter->fdir.input);
1581 "Failed to insert fdir filter to hash table %d!",
1585 fdir_info->hash_map[ret] = filter;
1587 TAILQ_INSERT_TAIL(&fdir_info->fdir_list, filter, rules);
1592 /* Delete a flow director filter from the SW list */
1594 i40e_sw_fdir_filter_del(struct i40e_pf *pf, struct i40e_fdir_input *input)
1596 struct i40e_fdir_info *fdir_info = &pf->fdir;
1597 struct i40e_fdir_filter *filter;
1600 if (input->flow_ext.pkt_template)
1601 ret = rte_hash_del_key_with_hash(fdir_info->hash_table,
1603 input->flow.raw_flow.length);
1605 ret = rte_hash_del_key(fdir_info->hash_table, input);
1608 "Failed to delete fdir filter to hash table %d!",
1612 filter = fdir_info->hash_map[ret];
1613 fdir_info->hash_map[ret] = NULL;
1615 TAILQ_REMOVE(&fdir_info->fdir_list, filter, rules);
1622 * i40e_add_del_fdir_filter - add or remove a flow director filter.
1623 * @pf: board private structure
1624 * @filter: fdir filter entry
1625 * @add: 0 - delete, 1 - add
1628 i40e_add_del_fdir_filter(struct rte_eth_dev *dev,
1629 const struct rte_eth_fdir_filter *filter,
1632 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1633 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1634 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1635 enum i40e_filter_pctype pctype;
1638 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1639 PMD_DRV_LOG(ERR, "FDIR is not enabled, please"
1640 " check the mode in fdir_conf.");
1644 pctype = i40e_flowtype_to_pctype(pf->adapter, filter->input.flow_type);
1645 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
1646 PMD_DRV_LOG(ERR, "invalid flow_type input.");
1649 if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1650 PMD_DRV_LOG(ERR, "Invalid queue ID");
1653 if (filter->input.flow_ext.is_vf &&
1654 filter->input.flow_ext.dst_id >= pf->vf_num) {
1655 PMD_DRV_LOG(ERR, "Invalid VF ID");
1659 memset(pkt, 0, I40E_FDIR_PKT_LEN);
1661 ret = i40e_fdir_construct_pkt(pf, &filter->input, pkt);
1663 PMD_DRV_LOG(ERR, "construct packet for fdir fails.");
1667 if (hw->mac.type == I40E_MAC_X722) {
1668 /* get translated pctype value in fd pctype register */
1669 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(
1670 hw, I40E_GLQF_FD_PCTYPES((int)pctype));
1673 ret = i40e_fdir_filter_programming(pf, pctype, filter, add);
1675 PMD_DRV_LOG(ERR, "fdir programming fails for PCTYPE(%u).",
1684 * i40e_flow_add_del_fdir_filter - add or remove a flow director filter.
1685 * @pf: board private structure
1686 * @filter: fdir filter entry
1687 * @add: 0 - delete, 1 - add
1690 i40e_flow_add_del_fdir_filter(struct rte_eth_dev *dev,
1691 const struct i40e_fdir_filter_conf *filter,
1694 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1695 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1696 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1697 enum i40e_filter_pctype pctype;
1698 struct i40e_fdir_info *fdir_info = &pf->fdir;
1699 struct i40e_fdir_filter *fdir_filter, *node;
1700 struct i40e_fdir_filter check_filter; /* Check if the filter exists */
1703 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1704 PMD_DRV_LOG(ERR, "FDIR is not enabled, please check the mode in fdir_conf.");
1708 if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1709 PMD_DRV_LOG(ERR, "Invalid queue ID");
1712 if (filter->input.flow_ext.is_vf &&
1713 filter->input.flow_ext.dst_id >= pf->vf_num) {
1714 PMD_DRV_LOG(ERR, "Invalid VF ID");
1717 if (filter->input.flow_ext.pkt_template) {
1718 if (filter->input.flow.raw_flow.length > I40E_FDIR_PKT_LEN ||
1719 !filter->input.flow.raw_flow.packet) {
1720 PMD_DRV_LOG(ERR, "Invalid raw packet template"
1721 " flow filter parameters!");
1724 pctype = filter->input.flow.raw_flow.pctype;
1726 pctype = filter->input.pctype;
1729 /* Check if there is the filter in SW list */
1730 memset(&check_filter, 0, sizeof(check_filter));
1731 i40e_fdir_filter_convert(filter, &check_filter);
1732 node = i40e_sw_fdir_filter_lookup(fdir_info, &check_filter.fdir.input);
1735 "Conflict with existing flow director rules!");
1739 if (!add && !node) {
1741 "There's no corresponding flow firector filter!");
1745 memset(pkt, 0, I40E_FDIR_PKT_LEN);
1747 ret = i40e_flow_fdir_construct_pkt(pf, &filter->input, pkt);
1749 PMD_DRV_LOG(ERR, "construct packet for fdir fails.");
1753 if (hw->mac.type == I40E_MAC_X722) {
1754 /* get translated pctype value in fd pctype register */
1755 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(
1756 hw, I40E_GLQF_FD_PCTYPES((int)pctype));
1759 ret = i40e_flow_fdir_filter_programming(pf, pctype, filter, add);
1761 PMD_DRV_LOG(ERR, "fdir programming fails for PCTYPE(%u).",
1767 fdir_filter = rte_zmalloc("fdir_filter",
1768 sizeof(*fdir_filter), 0);
1769 if (fdir_filter == NULL) {
1770 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
1774 rte_memcpy(fdir_filter, &check_filter, sizeof(check_filter));
1775 ret = i40e_sw_fdir_filter_insert(pf, fdir_filter);
1777 rte_free(fdir_filter);
1779 ret = i40e_sw_fdir_filter_del(pf, &node->fdir.input);
1786 * i40e_fdir_filter_programming - Program a flow director filter rule.
1787 * Is done by Flow Director Programming Descriptor followed by packet
1788 * structure that contains the filter fields need to match.
1789 * @pf: board private structure
1791 * @filter: fdir filter entry
1792 * @add: 0 - delete, 1 - add
1795 i40e_fdir_filter_programming(struct i40e_pf *pf,
1796 enum i40e_filter_pctype pctype,
1797 const struct rte_eth_fdir_filter *filter,
1800 struct i40e_tx_queue *txq = pf->fdir.txq;
1801 struct i40e_rx_queue *rxq = pf->fdir.rxq;
1802 const struct rte_eth_fdir_action *fdir_action = &filter->action;
1803 volatile struct i40e_tx_desc *txdp;
1804 volatile struct i40e_filter_program_desc *fdirdp;
1809 PMD_DRV_LOG(INFO, "filling filter programming descriptor.");
1810 fdirdp = (volatile struct i40e_filter_program_desc *)
1811 (&(txq->tx_ring[txq->tx_tail]));
1813 fdirdp->qindex_flex_ptype_vsi =
1814 rte_cpu_to_le_32((fdir_action->rx_queue <<
1815 I40E_TXD_FLTR_QW0_QINDEX_SHIFT) &
1816 I40E_TXD_FLTR_QW0_QINDEX_MASK);
1818 fdirdp->qindex_flex_ptype_vsi |=
1819 rte_cpu_to_le_32((fdir_action->flex_off <<
1820 I40E_TXD_FLTR_QW0_FLEXOFF_SHIFT) &
1821 I40E_TXD_FLTR_QW0_FLEXOFF_MASK);
1823 fdirdp->qindex_flex_ptype_vsi |=
1824 rte_cpu_to_le_32((pctype <<
1825 I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) &
1826 I40E_TXD_FLTR_QW0_PCTYPE_MASK);
1828 if (filter->input.flow_ext.is_vf)
1829 vsi_id = pf->vfs[filter->input.flow_ext.dst_id].vsi->vsi_id;
1831 /* Use LAN VSI Id by default */
1832 vsi_id = pf->main_vsi->vsi_id;
1833 fdirdp->qindex_flex_ptype_vsi |=
1834 rte_cpu_to_le_32(((uint32_t)vsi_id <<
1835 I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT) &
1836 I40E_TXD_FLTR_QW0_DEST_VSI_MASK);
1838 fdirdp->dtype_cmd_cntindex =
1839 rte_cpu_to_le_32(I40E_TX_DESC_DTYPE_FILTER_PROG);
1842 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1843 I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE <<
1844 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1846 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1847 I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE <<
1848 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1850 if (fdir_action->behavior == RTE_ETH_FDIR_REJECT)
1851 dest = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1852 else if (fdir_action->behavior == RTE_ETH_FDIR_ACCEPT)
1853 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1854 else if (fdir_action->behavior == RTE_ETH_FDIR_PASSTHRU)
1855 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_OTHER;
1857 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1858 " unsupported fdir behavior.");
1862 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32((dest <<
1863 I40E_TXD_FLTR_QW1_DEST_SHIFT) &
1864 I40E_TXD_FLTR_QW1_DEST_MASK);
1866 fdirdp->dtype_cmd_cntindex |=
1867 rte_cpu_to_le_32((fdir_action->report_status<<
1868 I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT) &
1869 I40E_TXD_FLTR_QW1_FD_STATUS_MASK);
1871 fdirdp->dtype_cmd_cntindex |=
1872 rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
1873 fdirdp->dtype_cmd_cntindex |=
1875 ((uint32_t)pf->fdir.match_counter_index <<
1876 I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
1877 I40E_TXD_FLTR_QW1_CNTINDEX_MASK);
1879 fdirdp->fd_id = rte_cpu_to_le_32(filter->soft_id);
1881 PMD_DRV_LOG(INFO, "filling transmit descriptor.");
1882 txdp = &(txq->tx_ring[txq->tx_tail + 1]);
1883 txdp->buffer_addr = rte_cpu_to_le_64(pf->fdir.dma_addr);
1884 td_cmd = I40E_TX_DESC_CMD_EOP |
1885 I40E_TX_DESC_CMD_RS |
1886 I40E_TX_DESC_CMD_DUMMY;
1888 txdp->cmd_type_offset_bsz =
1889 i40e_build_ctob(td_cmd, 0, I40E_FDIR_PKT_LEN, 0);
1891 txq->tx_tail += 2; /* set 2 descriptors above, fdirdp and txdp */
1892 if (txq->tx_tail >= txq->nb_tx_desc)
1894 /* Update the tx tail register */
1896 I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1897 for (i = 0; i < I40E_FDIR_MAX_WAIT_US; i++) {
1898 if ((txdp->cmd_type_offset_bsz &
1899 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1900 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1904 if (i >= I40E_FDIR_MAX_WAIT_US) {
1905 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1906 " time out to get DD on tx queue.");
1909 /* totally delay 10 ms to check programming status*/
1910 for (; i < I40E_FDIR_MAX_WAIT_US; i++) {
1911 if (i40e_check_fdir_programming_status(rxq) >= 0)
1916 "Failed to program FDIR filter: programming status reported.");
1921 * i40e_flow_fdir_filter_programming - Program a flow director filter rule.
1922 * Is done by Flow Director Programming Descriptor followed by packet
1923 * structure that contains the filter fields need to match.
1924 * @pf: board private structure
1926 * @filter: fdir filter entry
1927 * @add: 0 - delete, 1 - add
1930 i40e_flow_fdir_filter_programming(struct i40e_pf *pf,
1931 enum i40e_filter_pctype pctype,
1932 const struct i40e_fdir_filter_conf *filter,
1935 struct i40e_tx_queue *txq = pf->fdir.txq;
1936 struct i40e_rx_queue *rxq = pf->fdir.rxq;
1937 const struct i40e_fdir_action *fdir_action = &filter->action;
1938 volatile struct i40e_tx_desc *txdp;
1939 volatile struct i40e_filter_program_desc *fdirdp;
1944 PMD_DRV_LOG(INFO, "filling filter programming descriptor.");
1945 fdirdp = (volatile struct i40e_filter_program_desc *)
1946 (&txq->tx_ring[txq->tx_tail]);
1948 fdirdp->qindex_flex_ptype_vsi =
1949 rte_cpu_to_le_32((fdir_action->rx_queue <<
1950 I40E_TXD_FLTR_QW0_QINDEX_SHIFT) &
1951 I40E_TXD_FLTR_QW0_QINDEX_MASK);
1953 fdirdp->qindex_flex_ptype_vsi |=
1954 rte_cpu_to_le_32((fdir_action->flex_off <<
1955 I40E_TXD_FLTR_QW0_FLEXOFF_SHIFT) &
1956 I40E_TXD_FLTR_QW0_FLEXOFF_MASK);
1958 fdirdp->qindex_flex_ptype_vsi |=
1959 rte_cpu_to_le_32((pctype <<
1960 I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) &
1961 I40E_TXD_FLTR_QW0_PCTYPE_MASK);
1963 if (filter->input.flow_ext.is_vf)
1964 vsi_id = pf->vfs[filter->input.flow_ext.dst_id].vsi->vsi_id;
1966 /* Use LAN VSI Id by default */
1967 vsi_id = pf->main_vsi->vsi_id;
1968 fdirdp->qindex_flex_ptype_vsi |=
1969 rte_cpu_to_le_32(((uint32_t)vsi_id <<
1970 I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT) &
1971 I40E_TXD_FLTR_QW0_DEST_VSI_MASK);
1973 fdirdp->dtype_cmd_cntindex =
1974 rte_cpu_to_le_32(I40E_TX_DESC_DTYPE_FILTER_PROG);
1977 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1978 I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE <<
1979 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1981 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1982 I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE <<
1983 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1985 if (fdir_action->behavior == I40E_FDIR_REJECT)
1986 dest = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1987 else if (fdir_action->behavior == I40E_FDIR_ACCEPT)
1988 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1989 else if (fdir_action->behavior == I40E_FDIR_PASSTHRU)
1990 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_OTHER;
1992 PMD_DRV_LOG(ERR, "Failed to program FDIR filter: unsupported fdir behavior.");
1996 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32((dest <<
1997 I40E_TXD_FLTR_QW1_DEST_SHIFT) &
1998 I40E_TXD_FLTR_QW1_DEST_MASK);
2000 fdirdp->dtype_cmd_cntindex |=
2001 rte_cpu_to_le_32((fdir_action->report_status <<
2002 I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT) &
2003 I40E_TXD_FLTR_QW1_FD_STATUS_MASK);
2005 fdirdp->dtype_cmd_cntindex |=
2006 rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
2007 fdirdp->dtype_cmd_cntindex |=
2009 ((uint32_t)pf->fdir.match_counter_index <<
2010 I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
2011 I40E_TXD_FLTR_QW1_CNTINDEX_MASK);
2013 fdirdp->fd_id = rte_cpu_to_le_32(filter->soft_id);
2015 PMD_DRV_LOG(INFO, "filling transmit descriptor.");
2016 txdp = &txq->tx_ring[txq->tx_tail + 1];
2017 txdp->buffer_addr = rte_cpu_to_le_64(pf->fdir.dma_addr);
2018 td_cmd = I40E_TX_DESC_CMD_EOP |
2019 I40E_TX_DESC_CMD_RS |
2020 I40E_TX_DESC_CMD_DUMMY;
2022 txdp->cmd_type_offset_bsz =
2023 i40e_build_ctob(td_cmd, 0, I40E_FDIR_PKT_LEN, 0);
2025 txq->tx_tail += 2; /* set 2 descriptors above, fdirdp and txdp */
2026 if (txq->tx_tail >= txq->nb_tx_desc)
2028 /* Update the tx tail register */
2030 I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
2031 for (i = 0; i < I40E_FDIR_MAX_WAIT_US; i++) {
2032 if ((txdp->cmd_type_offset_bsz &
2033 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
2034 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
2038 if (i >= I40E_FDIR_MAX_WAIT_US) {
2040 "Failed to program FDIR filter: time out to get DD on tx queue.");
2043 /* totally delay 10 ms to check programming status*/
2044 rte_delay_us(I40E_FDIR_MAX_WAIT_US);
2045 if (i40e_check_fdir_programming_status(rxq) < 0) {
2047 "Failed to program FDIR filter: programming status reported.");
2055 * i40e_fdir_flush - clear all filters of Flow Director table
2056 * @pf: board private structure
2059 i40e_fdir_flush(struct rte_eth_dev *dev)
2061 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2062 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2064 uint16_t guarant_cnt, best_cnt;
2067 I40E_WRITE_REG(hw, I40E_PFQF_CTL_1, I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
2068 I40E_WRITE_FLUSH(hw);
2070 for (i = 0; i < I40E_FDIR_FLUSH_RETRY; i++) {
2071 rte_delay_ms(I40E_FDIR_FLUSH_INTERVAL_MS);
2072 reg = I40E_READ_REG(hw, I40E_PFQF_CTL_1);
2073 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
2076 if (i >= I40E_FDIR_FLUSH_RETRY) {
2077 PMD_DRV_LOG(ERR, "FD table did not flush, may need more time.");
2080 guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
2081 I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
2082 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
2083 best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
2084 I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
2085 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
2086 if (guarant_cnt != 0 || best_cnt != 0) {
2087 PMD_DRV_LOG(ERR, "Failed to flush FD table.");
2090 PMD_DRV_LOG(INFO, "FD table Flush success.");
2095 i40e_fdir_info_get_flex_set(struct i40e_pf *pf,
2096 struct rte_eth_flex_payload_cfg *flex_set,
2099 struct i40e_fdir_flex_pit *flex_pit;
2100 struct rte_eth_flex_payload_cfg *ptr = flex_set;
2101 uint16_t src, dst, size, j, k;
2102 uint8_t i, layer_idx;
2104 for (layer_idx = I40E_FLXPLD_L2_IDX;
2105 layer_idx <= I40E_FLXPLD_L4_IDX;
2107 if (layer_idx == I40E_FLXPLD_L2_IDX)
2108 ptr->type = RTE_ETH_L2_PAYLOAD;
2109 else if (layer_idx == I40E_FLXPLD_L3_IDX)
2110 ptr->type = RTE_ETH_L3_PAYLOAD;
2111 else if (layer_idx == I40E_FLXPLD_L4_IDX)
2112 ptr->type = RTE_ETH_L4_PAYLOAD;
2114 for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
2115 flex_pit = &pf->fdir.flex_set[layer_idx *
2116 I40E_MAX_FLXPLD_FIED + i];
2117 if (flex_pit->size == 0)
2119 src = flex_pit->src_offset * sizeof(uint16_t);
2120 dst = flex_pit->dst_offset * sizeof(uint16_t);
2121 size = flex_pit->size * sizeof(uint16_t);
2122 for (j = src, k = dst; j < src + size; j++, k++)
2123 ptr->src_offset[k] = j;
2131 i40e_fdir_info_get_flex_mask(struct i40e_pf *pf,
2132 struct rte_eth_fdir_flex_mask *flex_mask,
2135 struct i40e_fdir_flex_mask *mask;
2136 struct rte_eth_fdir_flex_mask *ptr = flex_mask;
2139 uint16_t off_bytes, mask_tmp;
2141 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2142 i <= I40E_FILTER_PCTYPE_L2_PAYLOAD;
2144 mask = &pf->fdir.flex_mask[i];
2145 flow_type = i40e_pctype_to_flowtype(pf->adapter,
2146 (enum i40e_filter_pctype)i);
2147 if (flow_type == RTE_ETH_FLOW_UNKNOWN)
2150 for (j = 0; j < I40E_FDIR_MAX_FLEXWORD_NUM; j++) {
2151 if (mask->word_mask & I40E_FLEX_WORD_MASK(j)) {
2152 ptr->mask[j * sizeof(uint16_t)] = UINT8_MAX;
2153 ptr->mask[j * sizeof(uint16_t) + 1] = UINT8_MAX;
2155 ptr->mask[j * sizeof(uint16_t)] = 0x0;
2156 ptr->mask[j * sizeof(uint16_t) + 1] = 0x0;
2159 for (j = 0; j < I40E_FDIR_BITMASK_NUM_WORD; j++) {
2160 off_bytes = mask->bitmask[j].offset * sizeof(uint16_t);
2161 mask_tmp = ~mask->bitmask[j].mask;
2162 ptr->mask[off_bytes] &= I40E_HI_BYTE(mask_tmp);
2163 ptr->mask[off_bytes + 1] &= I40E_LO_BYTE(mask_tmp);
2165 ptr->flow_type = flow_type;
2172 * i40e_fdir_info_get - get information of Flow Director
2173 * @pf: ethernet device to get info from
2174 * @fdir: a pointer to a structure of type *rte_eth_fdir_info* to be filled with
2175 * the flow director information.
2178 i40e_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir)
2180 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2181 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2182 uint16_t num_flex_set = 0;
2183 uint16_t num_flex_mask = 0;
2186 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT)
2187 fdir->mode = RTE_FDIR_MODE_PERFECT;
2189 fdir->mode = RTE_FDIR_MODE_NONE;
2192 (uint32_t)hw->func_caps.fd_filters_guaranteed;
2194 (uint32_t)hw->func_caps.fd_filters_best_effort;
2195 fdir->max_flexpayload = I40E_FDIR_MAX_FLEX_LEN;
2196 fdir->flow_types_mask[0] = I40E_FDIR_FLOWS;
2197 for (i = 1; i < RTE_FLOW_MASK_ARRAY_SIZE; i++)
2198 fdir->flow_types_mask[i] = 0ULL;
2199 fdir->flex_payload_unit = sizeof(uint16_t);
2200 fdir->flex_bitmask_unit = sizeof(uint16_t);
2201 fdir->max_flex_payload_segment_num = I40E_MAX_FLXPLD_FIED;
2202 fdir->flex_payload_limit = I40E_MAX_FLX_SOURCE_OFF;
2203 fdir->max_flex_bitmask_num = I40E_FDIR_BITMASK_NUM_WORD;
2205 i40e_fdir_info_get_flex_set(pf,
2206 fdir->flex_conf.flex_set,
2208 i40e_fdir_info_get_flex_mask(pf,
2209 fdir->flex_conf.flex_mask,
2212 fdir->flex_conf.nb_payloads = num_flex_set;
2213 fdir->flex_conf.nb_flexmasks = num_flex_mask;
2217 * i40e_fdir_stat_get - get statistics of Flow Director
2218 * @pf: ethernet device to get info from
2219 * @stat: a pointer to a structure of type *rte_eth_fdir_stats* to be filled with
2220 * the flow director statistics.
2223 i40e_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *stat)
2225 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2226 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2229 fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
2231 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
2232 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
2234 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
2235 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
2239 i40e_fdir_filter_set(struct rte_eth_dev *dev,
2240 struct rte_eth_fdir_filter_info *info)
2242 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2246 PMD_DRV_LOG(ERR, "Invalid pointer");
2250 switch (info->info_type) {
2251 case RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT:
2252 ret = i40e_fdir_filter_inset_select(pf,
2253 &(info->info.input_set_conf));
2256 PMD_DRV_LOG(ERR, "FD filter info type (%d) not supported",
2265 * i40e_fdir_ctrl_func - deal with all operations on flow director.
2266 * @pf: board private structure
2267 * @filter_op:operation will be taken.
2268 * @arg: a pointer to specific structure corresponding to the filter_op
2271 i40e_fdir_ctrl_func(struct rte_eth_dev *dev,
2272 enum rte_filter_op filter_op,
2275 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2278 if ((pf->flags & I40E_FLAG_FDIR) == 0)
2281 if (filter_op == RTE_ETH_FILTER_NOP)
2284 if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
2287 switch (filter_op) {
2288 case RTE_ETH_FILTER_ADD:
2289 ret = i40e_add_del_fdir_filter(dev,
2290 (struct rte_eth_fdir_filter *)arg,
2293 case RTE_ETH_FILTER_DELETE:
2294 ret = i40e_add_del_fdir_filter(dev,
2295 (struct rte_eth_fdir_filter *)arg,
2298 case RTE_ETH_FILTER_FLUSH:
2299 ret = i40e_fdir_flush(dev);
2301 case RTE_ETH_FILTER_INFO:
2302 i40e_fdir_info_get(dev, (struct rte_eth_fdir_info *)arg);
2304 case RTE_ETH_FILTER_SET:
2305 ret = i40e_fdir_filter_set(dev,
2306 (struct rte_eth_fdir_filter_info *)arg);
2308 case RTE_ETH_FILTER_STATS:
2309 i40e_fdir_stats_get(dev, (struct rte_eth_fdir_stats *)arg);
2312 PMD_DRV_LOG(ERR, "unknown operation %u.", filter_op);
2319 /* Restore flow director filter */
2321 i40e_fdir_filter_restore(struct i40e_pf *pf)
2323 struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(pf->main_vsi);
2324 struct i40e_fdir_filter_list *fdir_list = &pf->fdir.fdir_list;
2325 struct i40e_fdir_filter *f;
2326 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2328 uint32_t guarant_cnt; /**< Number of filters in guaranteed spaces. */
2329 uint32_t best_cnt; /**< Number of filters in best effort spaces. */
2331 TAILQ_FOREACH(f, fdir_list, rules)
2332 i40e_flow_add_del_fdir_filter(dev, &f->fdir, TRUE);
2334 fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
2336 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
2337 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
2339 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
2340 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
2342 PMD_DRV_LOG(INFO, "FDIR: Guarant count: %d, Best count: %d",
2343 guarant_cnt, best_cnt);