4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
42 #include <rte_ether.h>
43 #include <rte_ethdev.h>
45 #include <rte_memzone.h>
46 #include <rte_malloc.h>
53 #include "i40e_logs.h"
54 #include "base/i40e_type.h"
55 #include "base/i40e_prototype.h"
56 #include "i40e_ethdev.h"
57 #include "i40e_rxtx.h"
59 #define I40E_FDIR_MZ_NAME "FDIR_MEMZONE"
61 #define IPV6_ADDR_LEN 16
64 #define I40E_FDIR_PKT_LEN 512
65 #define I40E_FDIR_IP_DEFAULT_LEN 420
66 #define I40E_FDIR_IP_DEFAULT_TTL 0x40
67 #define I40E_FDIR_IP_DEFAULT_VERSION_IHL 0x45
68 #define I40E_FDIR_TCP_DEFAULT_DATAOFF 0x50
69 #define I40E_FDIR_IPv6_DEFAULT_VTC_FLOW 0x60000000
70 #define I40E_FDIR_IPv6_TC_OFFSET 20
72 #define I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS 0xFF
73 #define I40E_FDIR_IPv6_PAYLOAD_LEN 380
74 #define I40E_FDIR_UDP_DEFAULT_LEN 400
76 /* Wait count and interval for fdir filter programming */
77 #define I40E_FDIR_WAIT_COUNT 10
78 #define I40E_FDIR_WAIT_INTERVAL_US 1000
80 /* Wait count and interval for fdir filter flush */
81 #define I40E_FDIR_FLUSH_RETRY 50
82 #define I40E_FDIR_FLUSH_INTERVAL_MS 5
84 #define I40E_COUNTER_PF 2
85 /* Statistic counter index for one pf */
86 #define I40E_COUNTER_INDEX_FDIR(pf_id) (0 + (pf_id) * I40E_COUNTER_PF)
87 #define I40E_MAX_FLX_SOURCE_OFF 480
88 #define I40E_FLX_OFFSET_IN_FIELD_VECTOR 50
90 #define NONUSE_FLX_PIT_DEST_OFF 63
91 #define NONUSE_FLX_PIT_FSIZE 1
92 #define MK_FLX_PIT(src_offset, fsize, dst_offset) ( \
93 (((src_offset) << I40E_PRTQF_FLX_PIT_SOURCE_OFF_SHIFT) & \
94 I40E_PRTQF_FLX_PIT_SOURCE_OFF_MASK) | \
95 (((fsize) << I40E_PRTQF_FLX_PIT_FSIZE_SHIFT) & \
96 I40E_PRTQF_FLX_PIT_FSIZE_MASK) | \
97 ((((dst_offset) + I40E_FLX_OFFSET_IN_FIELD_VECTOR) << \
98 I40E_PRTQF_FLX_PIT_DEST_OFF_SHIFT) & \
99 I40E_PRTQF_FLX_PIT_DEST_OFF_MASK))
101 #define I40E_FDIR_FLOWS ( \
102 (1 << RTE_ETH_FLOW_FRAG_IPV4) | \
103 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
104 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
105 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
106 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
107 (1 << RTE_ETH_FLOW_FRAG_IPV6) | \
108 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
109 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
110 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
111 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
112 (1 << RTE_ETH_FLOW_L2_PAYLOAD))
114 #define I40E_FLEX_WORD_MASK(off) (0x80 >> (off))
116 static int i40e_fdir_rx_queue_init(struct i40e_rx_queue *rxq);
117 static int i40e_check_fdir_flex_conf(
118 const struct rte_eth_fdir_flex_conf *conf);
119 static void i40e_set_flx_pld_cfg(struct i40e_pf *pf,
120 const struct rte_eth_flex_payload_cfg *cfg);
121 static void i40e_set_flex_mask_on_pctype(struct i40e_pf *pf,
122 enum i40e_filter_pctype pctype,
123 const struct rte_eth_fdir_flex_mask *mask_cfg);
124 static int i40e_fdir_construct_pkt(struct i40e_pf *pf,
125 const struct rte_eth_fdir_input *fdir_input,
126 unsigned char *raw_pkt);
127 static int i40e_add_del_fdir_filter(struct rte_eth_dev *dev,
128 const struct rte_eth_fdir_filter *filter,
130 static int i40e_fdir_filter_programming(struct i40e_pf *pf,
131 enum i40e_filter_pctype pctype,
132 const struct rte_eth_fdir_filter *filter,
134 static int i40e_fdir_flush(struct rte_eth_dev *dev);
135 static void i40e_fdir_info_get(struct rte_eth_dev *dev,
136 struct rte_eth_fdir_info *fdir);
137 static void i40e_fdir_stats_get(struct rte_eth_dev *dev,
138 struct rte_eth_fdir_stats *stat);
141 i40e_fdir_rx_queue_init(struct i40e_rx_queue *rxq)
143 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
144 struct i40e_hmc_obj_rxq rx_ctx;
145 int err = I40E_SUCCESS;
147 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
148 /* Init the RX queue in hardware */
149 rx_ctx.dbuff = I40E_RXBUF_SZ_1024 >> I40E_RXQ_CTX_DBUFF_SHIFT;
151 rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
152 rx_ctx.qlen = rxq->nb_rx_desc;
153 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
156 rx_ctx.dtype = i40e_header_split_none;
157 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
158 rx_ctx.rxmax = ETHER_MAX_LEN;
159 rx_ctx.tphrdesc_ena = 1;
160 rx_ctx.tphwdesc_ena = 1;
161 rx_ctx.tphdata_ena = 1;
162 rx_ctx.tphhead_ena = 1;
163 rx_ctx.lrxqthresh = 2;
169 err = i40e_clear_lan_rx_queue_context(hw, rxq->reg_idx);
170 if (err != I40E_SUCCESS) {
171 PMD_DRV_LOG(ERR, "Failed to clear FDIR RX queue context.");
174 err = i40e_set_lan_rx_queue_context(hw, rxq->reg_idx, &rx_ctx);
175 if (err != I40E_SUCCESS) {
176 PMD_DRV_LOG(ERR, "Failed to set FDIR RX queue context.");
179 rxq->qrx_tail = hw->hw_addr +
180 I40E_QRX_TAIL(rxq->vsi->base_queue);
183 /* Init the RX tail regieter. */
184 I40E_PCI_REG_WRITE(rxq->qrx_tail, 0);
185 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
191 * i40e_fdir_setup - reserve and initialize the Flow Director resources
192 * @pf: board private structure
195 i40e_fdir_setup(struct i40e_pf *pf)
197 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
198 struct i40e_vsi *vsi;
199 int err = I40E_SUCCESS;
200 char z_name[RTE_MEMZONE_NAMESIZE];
201 const struct rte_memzone *mz = NULL;
202 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
204 if ((pf->flags & I40E_FLAG_FDIR) == 0) {
205 PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
206 return I40E_NOT_SUPPORTED;
209 PMD_DRV_LOG(INFO, "FDIR HW Capabilities: num_filters_guaranteed = %u,"
210 " num_filters_best_effort = %u.",
211 hw->func_caps.fd_filters_guaranteed,
212 hw->func_caps.fd_filters_best_effort);
214 vsi = pf->fdir.fdir_vsi;
216 PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
219 /* make new FDIR VSI */
220 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->main_vsi, 0);
222 PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
223 return I40E_ERR_NO_AVAILABLE_VSI;
225 pf->fdir.fdir_vsi = vsi;
227 /*Fdir tx queue setup*/
228 err = i40e_fdir_setup_tx_resources(pf);
230 PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
234 /*Fdir rx queue setup*/
235 err = i40e_fdir_setup_rx_resources(pf);
237 PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
241 err = i40e_tx_queue_init(pf->fdir.txq);
243 PMD_DRV_LOG(ERR, "Failed to do FDIR TX initialization.");
247 /* need switch on before dev start*/
248 err = i40e_switch_tx_queue(hw, vsi->base_queue, TRUE);
250 PMD_DRV_LOG(ERR, "Failed to do fdir TX switch on.");
254 /* Init the rx queue in hardware */
255 err = i40e_fdir_rx_queue_init(pf->fdir.rxq);
257 PMD_DRV_LOG(ERR, "Failed to do FDIR RX initialization.");
261 /* switch on rx queue */
262 err = i40e_switch_rx_queue(hw, vsi->base_queue, TRUE);
264 PMD_DRV_LOG(ERR, "Failed to do FDIR RX switch on.");
268 /* reserve memory for the fdir programming packet */
269 snprintf(z_name, sizeof(z_name), "%s_%s_%d",
270 eth_dev->driver->pci_drv.name,
272 eth_dev->data->port_id);
273 mz = i40e_memzone_reserve(z_name, I40E_FDIR_PKT_LEN, SOCKET_ID_ANY);
275 PMD_DRV_LOG(ERR, "Cannot init memzone for "
276 "flow director program packet.");
277 err = I40E_ERR_NO_MEMORY;
280 pf->fdir.prg_pkt = mz->addr;
281 pf->fdir.dma_addr = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
283 pf->fdir.match_counter_index = I40E_COUNTER_INDEX_FDIR(hw->pf_id);
284 PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
289 i40e_dev_rx_queue_release(pf->fdir.rxq);
292 i40e_dev_tx_queue_release(pf->fdir.txq);
295 i40e_vsi_release(vsi);
296 pf->fdir.fdir_vsi = NULL;
301 * i40e_fdir_teardown - release the Flow Director resources
302 * @pf: board private structure
305 i40e_fdir_teardown(struct i40e_pf *pf)
307 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
308 struct i40e_vsi *vsi;
310 vsi = pf->fdir.fdir_vsi;
313 i40e_switch_tx_queue(hw, vsi->base_queue, FALSE);
314 i40e_switch_rx_queue(hw, vsi->base_queue, FALSE);
315 i40e_dev_rx_queue_release(pf->fdir.rxq);
317 i40e_dev_tx_queue_release(pf->fdir.txq);
319 i40e_vsi_release(vsi);
320 pf->fdir.fdir_vsi = NULL;
323 /* check whether the flow director table in empty */
325 i40e_fdir_empty(struct i40e_hw *hw)
327 uint32_t guarant_cnt, best_cnt;
329 guarant_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
330 I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
331 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
332 best_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
333 I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
334 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
335 if (best_cnt + guarant_cnt > 0)
342 * Initialize the configuration about bytes stream extracted as flexible payload
346 i40e_init_flx_pld(struct i40e_pf *pf)
348 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
353 * Define the bytes stream extracted as flexible payload in
354 * field vector. By default, select 8 words from the beginning
355 * of payload as flexible payload.
357 for (i = I40E_FLXPLD_L2_IDX; i < I40E_MAX_FLXPLD_LAYER; i++) {
358 index = i * I40E_MAX_FLXPLD_FIED;
359 pf->fdir.flex_set[index].src_offset = 0;
360 pf->fdir.flex_set[index].size = I40E_FDIR_MAX_FLEXWORD_NUM;
361 pf->fdir.flex_set[index].dst_offset = 0;
362 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(index), 0x0000C900);
364 I40E_PRTQF_FLX_PIT(index + 1), 0x0000FC29);/*non-used*/
366 I40E_PRTQF_FLX_PIT(index + 2), 0x0000FC2A);/*non-used*/
369 /* initialize the masks */
370 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
371 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
372 if (!I40E_VALID_PCTYPE((enum i40e_filter_pctype)pctype))
374 pf->fdir.flex_mask[pctype].word_mask = 0;
375 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), 0);
376 for (i = 0; i < I40E_FDIR_BITMASK_NUM_WORD; i++) {
377 pf->fdir.flex_mask[pctype].bitmask[i].offset = 0;
378 pf->fdir.flex_mask[pctype].bitmask[i].mask = 0;
379 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), 0);
384 #define I40E_WORD(hi, lo) (uint16_t)((((hi) << 8) & 0xFF00) | ((lo) & 0xFF))
386 #define I40E_VALIDATE_FLEX_PIT(flex_pit1, flex_pit2) do { \
387 if ((flex_pit2).src_offset < \
388 (flex_pit1).src_offset + (flex_pit1).size) { \
389 PMD_DRV_LOG(ERR, "src_offset should be not" \
390 " less than than previous offset" \
391 " + previous FSIZE."); \
397 * i40e_srcoff_to_flx_pit - transform the src_offset into flex_pit structure,
398 * and the flex_pit will be sorted by it's src_offset value
400 static inline uint16_t
401 i40e_srcoff_to_flx_pit(const uint16_t *src_offset,
402 struct i40e_fdir_flex_pit *flex_pit)
404 uint16_t src_tmp, size, num = 0;
405 uint16_t i, k, j = 0;
407 while (j < I40E_FDIR_MAX_FLEX_LEN) {
409 for (; j < I40E_FDIR_MAX_FLEX_LEN - 1; j++) {
410 if (src_offset[j + 1] == src_offset[j] + 1)
415 src_tmp = src_offset[j] + 1 - size;
416 /* the flex_pit need to be sort by src_offset */
417 for (i = 0; i < num; i++) {
418 if (src_tmp < flex_pit[i].src_offset)
421 /* if insert required, move backward */
422 for (k = num; k > i; k--)
423 flex_pit[k] = flex_pit[k - 1];
425 flex_pit[i].dst_offset = j + 1 - size;
426 flex_pit[i].src_offset = src_tmp;
427 flex_pit[i].size = size;
434 /* i40e_check_fdir_flex_payload -check flex payload configuration arguments */
436 i40e_check_fdir_flex_payload(const struct rte_eth_flex_payload_cfg *flex_cfg)
438 struct i40e_fdir_flex_pit flex_pit[I40E_FDIR_MAX_FLEX_LEN];
441 for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i++) {
442 if (flex_cfg->src_offset[i] >= I40E_MAX_FLX_SOURCE_OFF) {
443 PMD_DRV_LOG(ERR, "exceeds maxmial payload limit.");
448 memset(flex_pit, 0, sizeof(flex_pit));
449 num = i40e_srcoff_to_flx_pit(flex_cfg->src_offset, flex_pit);
450 if (num > I40E_MAX_FLXPLD_FIED) {
451 PMD_DRV_LOG(ERR, "exceeds maxmial number of flex fields.");
454 for (i = 0; i < num; i++) {
455 if (flex_pit[i].size & 0x01 || flex_pit[i].dst_offset & 0x01 ||
456 flex_pit[i].src_offset & 0x01) {
457 PMD_DRV_LOG(ERR, "flexpayload should be measured"
462 I40E_VALIDATE_FLEX_PIT(flex_pit[i], flex_pit[i + 1]);
468 * i40e_check_fdir_flex_conf -check if the flex payload and mask configuration
469 * arguments are valid
472 i40e_check_fdir_flex_conf(const struct rte_eth_fdir_flex_conf *conf)
474 const struct rte_eth_flex_payload_cfg *flex_cfg;
475 const struct rte_eth_fdir_flex_mask *flex_mask;
482 PMD_DRV_LOG(INFO, "NULL pointer.");
485 /* check flexible payload setting configuration */
486 if (conf->nb_payloads > RTE_ETH_L4_PAYLOAD) {
487 PMD_DRV_LOG(ERR, "invalid number of payload setting.");
490 for (i = 0; i < conf->nb_payloads; i++) {
491 flex_cfg = &conf->flex_set[i];
492 if (flex_cfg->type > RTE_ETH_L4_PAYLOAD) {
493 PMD_DRV_LOG(ERR, "invalid payload type.");
496 ret = i40e_check_fdir_flex_payload(flex_cfg);
498 PMD_DRV_LOG(ERR, "invalid flex payload arguments.");
503 /* check flex mask setting configuration */
504 if (conf->nb_flexmasks >= RTE_ETH_FLOW_MAX) {
505 PMD_DRV_LOG(ERR, "invalid number of flex masks.");
508 for (i = 0; i < conf->nb_flexmasks; i++) {
509 flex_mask = &conf->flex_mask[i];
510 if (!I40E_VALID_FLOW(flex_mask->flow_type)) {
511 PMD_DRV_LOG(WARNING, "invalid flow type.");
515 for (j = 0; j < I40E_FDIR_MAX_FLEX_LEN; j += sizeof(uint16_t)) {
516 mask_tmp = I40E_WORD(flex_mask->mask[j],
517 flex_mask->mask[j + 1]);
518 if (mask_tmp != 0x0 && mask_tmp != UINT16_MAX) {
520 if (nb_bitmask > I40E_FDIR_BITMASK_NUM_WORD) {
521 PMD_DRV_LOG(ERR, " exceed maximal"
522 " number of bitmasks.");
532 * i40e_set_flx_pld_cfg -configure the rule how bytes stream is extracted as flexible payload
533 * @pf: board private structure
534 * @cfg: the rule how bytes stream is extracted as flexible payload
537 i40e_set_flx_pld_cfg(struct i40e_pf *pf,
538 const struct rte_eth_flex_payload_cfg *cfg)
540 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
541 struct i40e_fdir_flex_pit flex_pit[I40E_MAX_FLXPLD_FIED];
543 uint16_t num, min_next_off; /* in words */
544 uint8_t field_idx = 0;
545 uint8_t layer_idx = 0;
548 if (cfg->type == RTE_ETH_L2_PAYLOAD)
549 layer_idx = I40E_FLXPLD_L2_IDX;
550 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
551 layer_idx = I40E_FLXPLD_L3_IDX;
552 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
553 layer_idx = I40E_FLXPLD_L4_IDX;
555 memset(flex_pit, 0, sizeof(flex_pit));
556 num = i40e_srcoff_to_flx_pit(cfg->src_offset, flex_pit);
558 for (i = 0; i < RTE_MIN(num, RTE_DIM(flex_pit)); i++) {
559 field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
560 /* record the info in fdir structure */
561 pf->fdir.flex_set[field_idx].src_offset =
562 flex_pit[i].src_offset / sizeof(uint16_t);
563 pf->fdir.flex_set[field_idx].size =
564 flex_pit[i].size / sizeof(uint16_t);
565 pf->fdir.flex_set[field_idx].dst_offset =
566 flex_pit[i].dst_offset / sizeof(uint16_t);
567 flx_pit = MK_FLX_PIT(pf->fdir.flex_set[field_idx].src_offset,
568 pf->fdir.flex_set[field_idx].size,
569 pf->fdir.flex_set[field_idx].dst_offset);
571 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
573 min_next_off = pf->fdir.flex_set[field_idx].src_offset +
574 pf->fdir.flex_set[field_idx].size;
576 for (; i < I40E_MAX_FLXPLD_FIED; i++) {
577 /* set the non-used register obeying register's constrain */
578 flx_pit = MK_FLX_PIT(min_next_off, NONUSE_FLX_PIT_FSIZE,
579 NONUSE_FLX_PIT_DEST_OFF);
581 I40E_PRTQF_FLX_PIT(layer_idx * I40E_MAX_FLXPLD_FIED + i),
588 * i40e_set_flex_mask_on_pctype - configure the mask on flexible payload
589 * @pf: board private structure
590 * @pctype: packet classify type
591 * @flex_masks: mask for flexible payload
594 i40e_set_flex_mask_on_pctype(struct i40e_pf *pf,
595 enum i40e_filter_pctype pctype,
596 const struct rte_eth_fdir_flex_mask *mask_cfg)
598 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
599 struct i40e_fdir_flex_mask *flex_mask;
600 uint32_t flxinset, fd_mask;
602 uint8_t i, nb_bitmask = 0;
604 flex_mask = &pf->fdir.flex_mask[pctype];
605 memset(flex_mask, 0, sizeof(struct i40e_fdir_flex_mask));
606 for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i += sizeof(uint16_t)) {
607 mask_tmp = I40E_WORD(mask_cfg->mask[i], mask_cfg->mask[i + 1]);
608 if (mask_tmp != 0x0) {
609 flex_mask->word_mask |=
610 I40E_FLEX_WORD_MASK(i / sizeof(uint16_t));
611 if (mask_tmp != UINT16_MAX) {
613 flex_mask->bitmask[nb_bitmask].mask = ~mask_tmp;
614 flex_mask->bitmask[nb_bitmask].offset =
615 i / sizeof(uint16_t);
620 /* write mask to hw */
621 flxinset = (flex_mask->word_mask <<
622 I40E_PRTQF_FD_FLXINSET_INSET_SHIFT) &
623 I40E_PRTQF_FD_FLXINSET_INSET_MASK;
624 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), flxinset);
626 for (i = 0; i < nb_bitmask; i++) {
627 fd_mask = (flex_mask->bitmask[i].mask <<
628 I40E_PRTQF_FD_MSK_MASK_SHIFT) &
629 I40E_PRTQF_FD_MSK_MASK_MASK;
630 fd_mask |= ((flex_mask->bitmask[i].offset +
631 I40E_FLX_OFFSET_IN_FIELD_VECTOR) <<
632 I40E_PRTQF_FD_MSK_OFFSET_SHIFT) &
633 I40E_PRTQF_FD_MSK_OFFSET_MASK;
634 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), fd_mask);
639 * Configure flow director related setting
642 i40e_fdir_configure(struct rte_eth_dev *dev)
644 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
645 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
646 struct rte_eth_fdir_flex_conf *conf;
647 enum i40e_filter_pctype pctype;
653 * configuration need to be done before
654 * flow director filters are added
655 * If filters exist, flush them.
657 if (i40e_fdir_empty(hw) < 0) {
658 ret = i40e_fdir_flush(dev);
660 PMD_DRV_LOG(ERR, "failed to flush fdir table.");
665 /* enable FDIR filter */
666 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
667 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
668 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
670 i40e_init_flx_pld(pf); /* set flex config to default value */
672 conf = &dev->data->dev_conf.fdir_conf.flex_conf;
673 ret = i40e_check_fdir_flex_conf(conf);
675 PMD_DRV_LOG(ERR, " invalid configuration arguments.");
678 /* configure flex payload */
679 for (i = 0; i < conf->nb_payloads; i++)
680 i40e_set_flx_pld_cfg(pf, &conf->flex_set[i]);
681 /* configure flex mask*/
682 for (i = 0; i < conf->nb_flexmasks; i++) {
683 pctype = i40e_flowtype_to_pctype(conf->flex_mask[i].flow_type);
684 i40e_set_flex_mask_on_pctype(pf, pctype, &conf->flex_mask[i]);
691 i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
692 unsigned char *raw_pkt,
695 static uint8_t vlan_frame[] = {0x81, 0, 0, 0};
696 uint16_t *ether_type;
697 uint8_t len = 2 * sizeof(struct ether_addr);
699 struct ipv6_hdr *ip6;
700 static const uint8_t next_proto[] = {
701 [RTE_ETH_FLOW_FRAG_IPV4] = IPPROTO_IP,
702 [RTE_ETH_FLOW_NONFRAG_IPV4_TCP] = IPPROTO_TCP,
703 [RTE_ETH_FLOW_NONFRAG_IPV4_UDP] = IPPROTO_UDP,
704 [RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] = IPPROTO_SCTP,
705 [RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] = IPPROTO_IP,
706 [RTE_ETH_FLOW_FRAG_IPV6] = IPPROTO_NONE,
707 [RTE_ETH_FLOW_NONFRAG_IPV6_TCP] = IPPROTO_TCP,
708 [RTE_ETH_FLOW_NONFRAG_IPV6_UDP] = IPPROTO_UDP,
709 [RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] = IPPROTO_SCTP,
710 [RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] = IPPROTO_NONE,
713 raw_pkt += 2 * sizeof(struct ether_addr);
714 if (vlan && fdir_input->flow_ext.vlan_tci) {
715 rte_memcpy(raw_pkt, vlan_frame, sizeof(vlan_frame));
716 rte_memcpy(raw_pkt + sizeof(uint16_t),
717 &fdir_input->flow_ext.vlan_tci,
719 raw_pkt += sizeof(vlan_frame);
720 len += sizeof(vlan_frame);
722 ether_type = (uint16_t *)raw_pkt;
723 raw_pkt += sizeof(uint16_t);
724 len += sizeof(uint16_t);
726 switch (fdir_input->flow_type) {
727 case RTE_ETH_FLOW_L2_PAYLOAD:
728 *ether_type = fdir_input->flow.l2_flow.ether_type;
730 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
731 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
732 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
733 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
734 case RTE_ETH_FLOW_FRAG_IPV4:
735 ip = (struct ipv4_hdr *)raw_pkt;
737 *ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
738 ip->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
739 /* set len to by default */
740 ip->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
741 ip->next_proto_id = fdir_input->flow.ip4_flow.proto ?
742 fdir_input->flow.ip4_flow.proto :
743 next_proto[fdir_input->flow_type];
744 ip->time_to_live = fdir_input->flow.ip4_flow.ttl ?
745 fdir_input->flow.ip4_flow.ttl :
746 I40E_FDIR_IP_DEFAULT_TTL;
747 ip->type_of_service = fdir_input->flow.ip4_flow.tos;
749 * The source and destination fields in the transmitted packet
750 * need to be presented in a reversed order with respect
751 * to the expected received packets.
753 ip->src_addr = fdir_input->flow.ip4_flow.dst_ip;
754 ip->dst_addr = fdir_input->flow.ip4_flow.src_ip;
755 len += sizeof(struct ipv4_hdr);
757 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
758 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
759 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
760 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
761 case RTE_ETH_FLOW_FRAG_IPV6:
762 ip6 = (struct ipv6_hdr *)raw_pkt;
764 *ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
766 rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
767 (fdir_input->flow.ipv6_flow.tc <<
768 I40E_FDIR_IPv6_TC_OFFSET));
770 rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
771 ip6->proto = fdir_input->flow.ipv6_flow.proto ?
772 fdir_input->flow.ipv6_flow.proto :
773 next_proto[fdir_input->flow_type];
774 ip6->hop_limits = fdir_input->flow.ipv6_flow.hop_limits ?
775 fdir_input->flow.ipv6_flow.hop_limits :
776 I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
778 * The source and destination fields in the transmitted packet
779 * need to be presented in a reversed order with respect
780 * to the expected received packets.
782 rte_memcpy(&(ip6->src_addr),
783 &(fdir_input->flow.ipv6_flow.dst_ip),
785 rte_memcpy(&(ip6->dst_addr),
786 &(fdir_input->flow.ipv6_flow.src_ip),
788 len += sizeof(struct ipv6_hdr);
791 PMD_DRV_LOG(ERR, "unknown flow type %u.",
792 fdir_input->flow_type);
800 * i40e_fdir_construct_pkt - construct packet based on fields in input
801 * @pf: board private structure
802 * @fdir_input: input set of the flow director entry
803 * @raw_pkt: a packet to be constructed
806 i40e_fdir_construct_pkt(struct i40e_pf *pf,
807 const struct rte_eth_fdir_input *fdir_input,
808 unsigned char *raw_pkt)
810 unsigned char *payload, *ptr;
813 struct sctp_hdr *sctp;
814 uint8_t size, dst = 0;
815 uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
818 /* fill the ethernet and IP head */
819 len = i40e_fdir_fill_eth_ip_head(fdir_input, raw_pkt,
820 !!fdir_input->flow_ext.vlan_tci);
824 /* fill the L4 head */
825 switch (fdir_input->flow_type) {
826 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
827 udp = (struct udp_hdr *)(raw_pkt + len);
828 payload = (unsigned char *)udp + sizeof(struct udp_hdr);
830 * The source and destination fields in the transmitted packet
831 * need to be presented in a reversed order with respect
832 * to the expected received packets.
834 udp->src_port = fdir_input->flow.udp4_flow.dst_port;
835 udp->dst_port = fdir_input->flow.udp4_flow.src_port;
836 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
839 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
840 tcp = (struct tcp_hdr *)(raw_pkt + len);
841 payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
843 * The source and destination fields in the transmitted packet
844 * need to be presented in a reversed order with respect
845 * to the expected received packets.
847 tcp->src_port = fdir_input->flow.tcp4_flow.dst_port;
848 tcp->dst_port = fdir_input->flow.tcp4_flow.src_port;
849 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
852 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
853 sctp = (struct sctp_hdr *)(raw_pkt + len);
854 payload = (unsigned char *)sctp + sizeof(struct sctp_hdr);
856 * The source and destination fields in the transmitted packet
857 * need to be presented in a reversed order with respect
858 * to the expected received packets.
860 sctp->src_port = fdir_input->flow.sctp4_flow.dst_port;
861 sctp->dst_port = fdir_input->flow.sctp4_flow.src_port;
862 sctp->tag = fdir_input->flow.sctp4_flow.verify_tag;
865 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
866 case RTE_ETH_FLOW_FRAG_IPV4:
867 payload = raw_pkt + len;
868 set_idx = I40E_FLXPLD_L3_IDX;
871 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
872 udp = (struct udp_hdr *)(raw_pkt + len);
873 payload = (unsigned char *)udp + sizeof(struct udp_hdr);
875 * The source and destination fields in the transmitted packet
876 * need to be presented in a reversed order with respect
877 * to the expected received packets.
879 udp->src_port = fdir_input->flow.udp6_flow.dst_port;
880 udp->dst_port = fdir_input->flow.udp6_flow.src_port;
881 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
884 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
885 tcp = (struct tcp_hdr *)(raw_pkt + len);
886 payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
888 * The source and destination fields in the transmitted packet
889 * need to be presented in a reversed order with respect
890 * to the expected received packets.
892 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
893 tcp->src_port = fdir_input->flow.udp6_flow.dst_port;
894 tcp->dst_port = fdir_input->flow.udp6_flow.src_port;
897 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
898 sctp = (struct sctp_hdr *)(raw_pkt + len);
899 payload = (unsigned char *)sctp + sizeof(struct sctp_hdr);
901 * The source and destination fields in the transmitted packet
902 * need to be presented in a reversed order with respect
903 * to the expected received packets.
905 sctp->src_port = fdir_input->flow.sctp6_flow.dst_port;
906 sctp->dst_port = fdir_input->flow.sctp6_flow.src_port;
907 sctp->tag = fdir_input->flow.sctp6_flow.verify_tag;
910 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
911 case RTE_ETH_FLOW_FRAG_IPV6:
912 payload = raw_pkt + len;
913 set_idx = I40E_FLXPLD_L3_IDX;
915 case RTE_ETH_FLOW_L2_PAYLOAD:
916 payload = raw_pkt + len;
918 * ARP packet is a special case on which the payload
919 * starts after the whole ARP header
921 if (fdir_input->flow.l2_flow.ether_type ==
922 rte_cpu_to_be_16(ETHER_TYPE_ARP))
923 payload += sizeof(struct arp_hdr);
924 set_idx = I40E_FLXPLD_L2_IDX;
927 PMD_DRV_LOG(ERR, "unknown flow type %u.", fdir_input->flow_type);
931 /* fill the flexbytes to payload */
932 for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
933 pit_idx = set_idx * I40E_MAX_FLXPLD_FIED + i;
934 size = pf->fdir.flex_set[pit_idx].size;
937 dst = pf->fdir.flex_set[pit_idx].dst_offset * sizeof(uint16_t);
939 pf->fdir.flex_set[pit_idx].src_offset * sizeof(uint16_t);
940 (void)rte_memcpy(ptr,
941 &fdir_input->flow_ext.flexbytes[dst],
942 size * sizeof(uint16_t));
948 /* Construct the tx flags */
949 static inline uint64_t
950 i40e_build_ctob(uint32_t td_cmd,
955 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
956 ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
957 ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
958 ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
959 ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
963 * check the programming status descriptor in rx queue.
964 * done after Programming Flow Director is programmed on
968 i40e_check_fdir_programming_status(struct i40e_rx_queue *rxq)
970 volatile union i40e_rx_desc *rxdp;
977 rxdp = &rxq->rx_ring[rxq->rx_tail];
978 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
979 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
980 >> I40E_RXD_QW1_STATUS_SHIFT;
982 if (rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
983 len = qword1 >> I40E_RX_PROG_STATUS_DESC_LENGTH_SHIFT;
984 id = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >>
985 I40E_RX_PROG_STATUS_DESC_QW1_PROGID_SHIFT;
987 if (len == I40E_RX_PROG_STATUS_DESC_LENGTH &&
988 id == I40E_RX_PROG_STATUS_DESC_FD_FILTER_STATUS) {
990 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
991 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
993 I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
994 PMD_DRV_LOG(ERR, "Failed to add FDIR filter"
995 " (FD_ID %u): programming status"
997 rxdp->wb.qword0.hi_dword.fd_id);
999 } else if (error == (0x1 <<
1000 I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
1001 PMD_DRV_LOG(ERR, "Failed to delete FDIR filter"
1002 " (FD_ID %u): programming status"
1004 rxdp->wb.qword0.hi_dword.fd_id);
1007 PMD_DRV_LOG(ERR, "invalid programming status"
1008 " reported, error = %u.", error);
1010 PMD_DRV_LOG(ERR, "unknown programming status"
1011 " reported, len = %d, id = %u.", len, id);
1012 rxdp->wb.qword1.status_error_len = 0;
1014 if (unlikely(rxq->rx_tail == rxq->nb_rx_desc))
1021 * i40e_add_del_fdir_filter - add or remove a flow director filter.
1022 * @pf: board private structure
1023 * @filter: fdir filter entry
1024 * @add: 0 - delete, 1 - add
1027 i40e_add_del_fdir_filter(struct rte_eth_dev *dev,
1028 const struct rte_eth_fdir_filter *filter,
1031 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1032 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1033 enum i40e_filter_pctype pctype;
1036 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1037 PMD_DRV_LOG(ERR, "FDIR is not enabled, please"
1038 " check the mode in fdir_conf.");
1042 if (!I40E_VALID_FLOW(filter->input.flow_type)) {
1043 PMD_DRV_LOG(ERR, "invalid flow_type input.");
1046 if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1047 PMD_DRV_LOG(ERR, "Invalid queue ID");
1050 if (filter->input.flow_ext.is_vf &&
1051 filter->input.flow_ext.dst_id >= pf->vf_num) {
1052 PMD_DRV_LOG(ERR, "Invalid VF ID");
1056 memset(pkt, 0, I40E_FDIR_PKT_LEN);
1058 ret = i40e_fdir_construct_pkt(pf, &filter->input, pkt);
1060 PMD_DRV_LOG(ERR, "construct packet for fdir fails.");
1063 pctype = i40e_flowtype_to_pctype(filter->input.flow_type);
1064 ret = i40e_fdir_filter_programming(pf, pctype, filter, add);
1066 PMD_DRV_LOG(ERR, "fdir programming fails for PCTYPE(%u).",
1074 * i40e_fdir_filter_programming - Program a flow director filter rule.
1075 * Is done by Flow Director Programming Descriptor followed by packet
1076 * structure that contains the filter fields need to match.
1077 * @pf: board private structure
1079 * @filter: fdir filter entry
1080 * @add: 0 - delete, 1 - add
1083 i40e_fdir_filter_programming(struct i40e_pf *pf,
1084 enum i40e_filter_pctype pctype,
1085 const struct rte_eth_fdir_filter *filter,
1088 struct i40e_tx_queue *txq = pf->fdir.txq;
1089 struct i40e_rx_queue *rxq = pf->fdir.rxq;
1090 const struct rte_eth_fdir_action *fdir_action = &filter->action;
1091 volatile struct i40e_tx_desc *txdp;
1092 volatile struct i40e_filter_program_desc *fdirdp;
1097 PMD_DRV_LOG(INFO, "filling filter programming descriptor.");
1098 fdirdp = (volatile struct i40e_filter_program_desc *)
1099 (&(txq->tx_ring[txq->tx_tail]));
1101 fdirdp->qindex_flex_ptype_vsi =
1102 rte_cpu_to_le_32((fdir_action->rx_queue <<
1103 I40E_TXD_FLTR_QW0_QINDEX_SHIFT) &
1104 I40E_TXD_FLTR_QW0_QINDEX_MASK);
1106 fdirdp->qindex_flex_ptype_vsi |=
1107 rte_cpu_to_le_32((fdir_action->flex_off <<
1108 I40E_TXD_FLTR_QW0_FLEXOFF_SHIFT) &
1109 I40E_TXD_FLTR_QW0_FLEXOFF_MASK);
1111 fdirdp->qindex_flex_ptype_vsi |=
1112 rte_cpu_to_le_32((pctype <<
1113 I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) &
1114 I40E_TXD_FLTR_QW0_PCTYPE_MASK);
1116 if (filter->input.flow_ext.is_vf)
1117 vsi_id = pf->vfs[filter->input.flow_ext.dst_id].vsi->vsi_id;
1119 /* Use LAN VSI Id by default */
1120 vsi_id = pf->main_vsi->vsi_id;
1121 fdirdp->qindex_flex_ptype_vsi |=
1122 rte_cpu_to_le_32(((uint32_t)vsi_id <<
1123 I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT) &
1124 I40E_TXD_FLTR_QW0_DEST_VSI_MASK);
1126 fdirdp->dtype_cmd_cntindex =
1127 rte_cpu_to_le_32(I40E_TX_DESC_DTYPE_FILTER_PROG);
1130 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1131 I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE <<
1132 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1134 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1135 I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE <<
1136 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1138 if (fdir_action->behavior == RTE_ETH_FDIR_REJECT)
1139 dest = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1140 else if (fdir_action->behavior == RTE_ETH_FDIR_ACCEPT)
1141 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1142 else if (fdir_action->behavior == RTE_ETH_FDIR_PASSTHRU)
1143 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_OTHER;
1145 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1146 " unsupported fdir behavior.");
1150 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32((dest <<
1151 I40E_TXD_FLTR_QW1_DEST_SHIFT) &
1152 I40E_TXD_FLTR_QW1_DEST_MASK);
1154 fdirdp->dtype_cmd_cntindex |=
1155 rte_cpu_to_le_32((fdir_action->report_status<<
1156 I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT) &
1157 I40E_TXD_FLTR_QW1_FD_STATUS_MASK);
1159 fdirdp->dtype_cmd_cntindex |=
1160 rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
1161 fdirdp->dtype_cmd_cntindex |=
1162 rte_cpu_to_le_32((pf->fdir.match_counter_index <<
1163 I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
1164 I40E_TXD_FLTR_QW1_CNTINDEX_MASK);
1166 fdirdp->fd_id = rte_cpu_to_le_32(filter->soft_id);
1168 PMD_DRV_LOG(INFO, "filling transmit descriptor.");
1169 txdp = &(txq->tx_ring[txq->tx_tail + 1]);
1170 txdp->buffer_addr = rte_cpu_to_le_64(pf->fdir.dma_addr);
1171 td_cmd = I40E_TX_DESC_CMD_EOP |
1172 I40E_TX_DESC_CMD_RS |
1173 I40E_TX_DESC_CMD_DUMMY;
1175 txdp->cmd_type_offset_bsz =
1176 i40e_build_ctob(td_cmd, 0, I40E_FDIR_PKT_LEN, 0);
1178 txq->tx_tail += 2; /* set 2 descriptors above, fdirdp and txdp */
1179 if (txq->tx_tail >= txq->nb_tx_desc)
1181 /* Update the tx tail register */
1183 I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1185 for (i = 0; i < I40E_FDIR_WAIT_COUNT; i++) {
1186 rte_delay_us(I40E_FDIR_WAIT_INTERVAL_US);
1187 if ((txdp->cmd_type_offset_bsz &
1188 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1189 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1192 if (i >= I40E_FDIR_WAIT_COUNT) {
1193 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1194 " time out to get DD on tx queue.");
1197 /* totally delay 10 ms to check programming status*/
1198 rte_delay_us((I40E_FDIR_WAIT_COUNT - i) * I40E_FDIR_WAIT_INTERVAL_US);
1199 if (i40e_check_fdir_programming_status(rxq) < 0) {
1200 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1201 " programming status reported.");
1209 * i40e_fdir_flush - clear all filters of Flow Director table
1210 * @pf: board private structure
1213 i40e_fdir_flush(struct rte_eth_dev *dev)
1215 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1216 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1218 uint16_t guarant_cnt, best_cnt;
1221 I40E_WRITE_REG(hw, I40E_PFQF_CTL_1, I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
1222 I40E_WRITE_FLUSH(hw);
1224 for (i = 0; i < I40E_FDIR_FLUSH_RETRY; i++) {
1225 rte_delay_ms(I40E_FDIR_FLUSH_INTERVAL_MS);
1226 reg = I40E_READ_REG(hw, I40E_PFQF_CTL_1);
1227 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
1230 if (i >= I40E_FDIR_FLUSH_RETRY) {
1231 PMD_DRV_LOG(ERR, "FD table did not flush, may need more time.");
1234 guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1235 I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1236 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1237 best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1238 I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1239 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1240 if (guarant_cnt != 0 || best_cnt != 0) {
1241 PMD_DRV_LOG(ERR, "Failed to flush FD table.");
1244 PMD_DRV_LOG(INFO, "FD table Flush success.");
1249 i40e_fdir_info_get_flex_set(struct i40e_pf *pf,
1250 struct rte_eth_flex_payload_cfg *flex_set,
1253 struct i40e_fdir_flex_pit *flex_pit;
1254 struct rte_eth_flex_payload_cfg *ptr = flex_set;
1255 uint16_t src, dst, size, j, k;
1256 uint8_t i, layer_idx;
1258 for (layer_idx = I40E_FLXPLD_L2_IDX;
1259 layer_idx <= I40E_FLXPLD_L4_IDX;
1261 if (layer_idx == I40E_FLXPLD_L2_IDX)
1262 ptr->type = RTE_ETH_L2_PAYLOAD;
1263 else if (layer_idx == I40E_FLXPLD_L3_IDX)
1264 ptr->type = RTE_ETH_L3_PAYLOAD;
1265 else if (layer_idx == I40E_FLXPLD_L4_IDX)
1266 ptr->type = RTE_ETH_L4_PAYLOAD;
1268 for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
1269 flex_pit = &pf->fdir.flex_set[layer_idx *
1270 I40E_MAX_FLXPLD_FIED + i];
1271 if (flex_pit->size == 0)
1273 src = flex_pit->src_offset * sizeof(uint16_t);
1274 dst = flex_pit->dst_offset * sizeof(uint16_t);
1275 size = flex_pit->size * sizeof(uint16_t);
1276 for (j = src, k = dst; j < src + size; j++, k++)
1277 ptr->src_offset[k] = j;
1285 i40e_fdir_info_get_flex_mask(struct i40e_pf *pf,
1286 struct rte_eth_fdir_flex_mask *flex_mask,
1289 struct i40e_fdir_flex_mask *mask;
1290 struct rte_eth_fdir_flex_mask *ptr = flex_mask;
1293 uint16_t off_bytes, mask_tmp;
1295 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1296 i <= I40E_FILTER_PCTYPE_L2_PAYLOAD;
1298 mask = &pf->fdir.flex_mask[i];
1299 if (!I40E_VALID_PCTYPE((enum i40e_filter_pctype)i))
1301 flow_type = i40e_pctype_to_flowtype((enum i40e_filter_pctype)i);
1302 for (j = 0; j < I40E_FDIR_MAX_FLEXWORD_NUM; j++) {
1303 if (mask->word_mask & I40E_FLEX_WORD_MASK(j)) {
1304 ptr->mask[j * sizeof(uint16_t)] = UINT8_MAX;
1305 ptr->mask[j * sizeof(uint16_t) + 1] = UINT8_MAX;
1307 ptr->mask[j * sizeof(uint16_t)] = 0x0;
1308 ptr->mask[j * sizeof(uint16_t) + 1] = 0x0;
1311 for (j = 0; j < I40E_FDIR_BITMASK_NUM_WORD; j++) {
1312 off_bytes = mask->bitmask[j].offset * sizeof(uint16_t);
1313 mask_tmp = ~mask->bitmask[j].mask;
1314 ptr->mask[off_bytes] &= I40E_HI_BYTE(mask_tmp);
1315 ptr->mask[off_bytes + 1] &= I40E_LO_BYTE(mask_tmp);
1317 ptr->flow_type = flow_type;
1324 * i40e_fdir_info_get - get information of Flow Director
1325 * @pf: ethernet device to get info from
1326 * @fdir: a pointer to a structure of type *rte_eth_fdir_info* to be filled with
1327 * the flow director information.
1330 i40e_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir)
1332 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1333 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1334 uint16_t num_flex_set = 0;
1335 uint16_t num_flex_mask = 0;
1337 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT)
1338 fdir->mode = RTE_FDIR_MODE_PERFECT;
1340 fdir->mode = RTE_FDIR_MODE_NONE;
1343 (uint32_t)hw->func_caps.fd_filters_guaranteed;
1345 (uint32_t)hw->func_caps.fd_filters_best_effort;
1346 fdir->max_flexpayload = I40E_FDIR_MAX_FLEX_LEN;
1347 fdir->flow_types_mask[0] = I40E_FDIR_FLOWS;
1348 fdir->flex_payload_unit = sizeof(uint16_t);
1349 fdir->flex_bitmask_unit = sizeof(uint16_t);
1350 fdir->max_flex_payload_segment_num = I40E_MAX_FLXPLD_FIED;
1351 fdir->flex_payload_limit = I40E_MAX_FLX_SOURCE_OFF;
1352 fdir->max_flex_bitmask_num = I40E_FDIR_BITMASK_NUM_WORD;
1354 i40e_fdir_info_get_flex_set(pf,
1355 fdir->flex_conf.flex_set,
1357 i40e_fdir_info_get_flex_mask(pf,
1358 fdir->flex_conf.flex_mask,
1361 fdir->flex_conf.nb_payloads = num_flex_set;
1362 fdir->flex_conf.nb_flexmasks = num_flex_mask;
1366 * i40e_fdir_stat_get - get statistics of Flow Director
1367 * @pf: ethernet device to get info from
1368 * @stat: a pointer to a structure of type *rte_eth_fdir_stats* to be filled with
1369 * the flow director statistics.
1372 i40e_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *stat)
1374 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1375 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1378 fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1380 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1381 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1383 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1384 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1388 i40e_fdir_filter_set(struct rte_eth_dev *dev,
1389 struct rte_eth_fdir_filter_info *info)
1391 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1395 PMD_DRV_LOG(ERR, "Invalid pointer");
1399 switch (info->info_type) {
1400 case RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT:
1401 ret = i40e_fdir_filter_inset_select(pf,
1402 &(info->info.input_set_conf));
1405 PMD_DRV_LOG(ERR, "FD filter info type (%d) not supported",
1414 * i40e_fdir_ctrl_func - deal with all operations on flow director.
1415 * @pf: board private structure
1416 * @filter_op:operation will be taken.
1417 * @arg: a pointer to specific structure corresponding to the filter_op
1420 i40e_fdir_ctrl_func(struct rte_eth_dev *dev,
1421 enum rte_filter_op filter_op,
1424 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1427 if ((pf->flags & I40E_FLAG_FDIR) == 0)
1430 if (filter_op == RTE_ETH_FILTER_NOP)
1433 if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
1436 switch (filter_op) {
1437 case RTE_ETH_FILTER_ADD:
1438 ret = i40e_add_del_fdir_filter(dev,
1439 (struct rte_eth_fdir_filter *)arg,
1442 case RTE_ETH_FILTER_DELETE:
1443 ret = i40e_add_del_fdir_filter(dev,
1444 (struct rte_eth_fdir_filter *)arg,
1447 case RTE_ETH_FILTER_FLUSH:
1448 ret = i40e_fdir_flush(dev);
1450 case RTE_ETH_FILTER_INFO:
1451 i40e_fdir_info_get(dev, (struct rte_eth_fdir_info *)arg);
1453 case RTE_ETH_FILTER_SET:
1454 ret = i40e_fdir_filter_set(dev,
1455 (struct rte_eth_fdir_filter_info *)arg);
1457 case RTE_ETH_FILTER_STATS:
1458 i40e_fdir_stats_get(dev, (struct rte_eth_fdir_stats *)arg);
1461 PMD_DRV_LOG(ERR, "unknown operation %u.", filter_op);