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) == NONUSE_FLX_PIT_DEST_OFF ? \
98 NONUSE_FLX_PIT_DEST_OFF : \
99 ((dst_offset) + I40E_FLX_OFFSET_IN_FIELD_VECTOR)) << \
100 I40E_PRTQF_FLX_PIT_DEST_OFF_SHIFT) & \
101 I40E_PRTQF_FLX_PIT_DEST_OFF_MASK))
103 #define I40E_FDIR_FLOWS ( \
104 (1 << RTE_ETH_FLOW_FRAG_IPV4) | \
105 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
106 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
107 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
108 (1 << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
109 (1 << RTE_ETH_FLOW_FRAG_IPV6) | \
110 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
111 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
112 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
113 (1 << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
114 (1 << RTE_ETH_FLOW_L2_PAYLOAD))
116 #define I40E_FLEX_WORD_MASK(off) (0x80 >> (off))
118 static int i40e_fdir_filter_programming(struct i40e_pf *pf,
119 enum i40e_filter_pctype pctype,
120 const struct rte_eth_fdir_filter *filter,
122 static int i40e_fdir_flush(struct rte_eth_dev *dev);
125 i40e_fdir_rx_queue_init(struct i40e_rx_queue *rxq)
127 struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
128 struct i40e_hmc_obj_rxq rx_ctx;
129 int err = I40E_SUCCESS;
131 memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
132 /* Init the RX queue in hardware */
133 rx_ctx.dbuff = I40E_RXBUF_SZ_1024 >> I40E_RXQ_CTX_DBUFF_SHIFT;
135 rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
136 rx_ctx.qlen = rxq->nb_rx_desc;
137 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
140 rx_ctx.dtype = i40e_header_split_none;
141 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
142 rx_ctx.rxmax = ETHER_MAX_LEN;
143 rx_ctx.tphrdesc_ena = 1;
144 rx_ctx.tphwdesc_ena = 1;
145 rx_ctx.tphdata_ena = 1;
146 rx_ctx.tphhead_ena = 1;
147 rx_ctx.lrxqthresh = 2;
153 err = i40e_clear_lan_rx_queue_context(hw, rxq->reg_idx);
154 if (err != I40E_SUCCESS) {
155 PMD_DRV_LOG(ERR, "Failed to clear FDIR RX queue context.");
158 err = i40e_set_lan_rx_queue_context(hw, rxq->reg_idx, &rx_ctx);
159 if (err != I40E_SUCCESS) {
160 PMD_DRV_LOG(ERR, "Failed to set FDIR RX queue context.");
163 rxq->qrx_tail = hw->hw_addr +
164 I40E_QRX_TAIL(rxq->vsi->base_queue);
167 /* Init the RX tail regieter. */
168 I40E_PCI_REG_WRITE(rxq->qrx_tail, 0);
169 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
175 * i40e_fdir_setup - reserve and initialize the Flow Director resources
176 * @pf: board private structure
179 i40e_fdir_setup(struct i40e_pf *pf)
181 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
182 struct i40e_vsi *vsi;
183 int err = I40E_SUCCESS;
184 char z_name[RTE_MEMZONE_NAMESIZE];
185 const struct rte_memzone *mz = NULL;
186 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
188 if ((pf->flags & I40E_FLAG_FDIR) == 0) {
189 PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
190 return I40E_NOT_SUPPORTED;
193 PMD_DRV_LOG(INFO, "FDIR HW Capabilities: num_filters_guaranteed = %u,"
194 " num_filters_best_effort = %u.",
195 hw->func_caps.fd_filters_guaranteed,
196 hw->func_caps.fd_filters_best_effort);
198 vsi = pf->fdir.fdir_vsi;
200 PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
203 /* make new FDIR VSI */
204 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->main_vsi, 0);
206 PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
207 return I40E_ERR_NO_AVAILABLE_VSI;
209 pf->fdir.fdir_vsi = vsi;
211 /*Fdir tx queue setup*/
212 err = i40e_fdir_setup_tx_resources(pf);
214 PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
218 /*Fdir rx queue setup*/
219 err = i40e_fdir_setup_rx_resources(pf);
221 PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
225 err = i40e_tx_queue_init(pf->fdir.txq);
227 PMD_DRV_LOG(ERR, "Failed to do FDIR TX initialization.");
231 /* need switch on before dev start*/
232 err = i40e_switch_tx_queue(hw, vsi->base_queue, TRUE);
234 PMD_DRV_LOG(ERR, "Failed to do fdir TX switch on.");
238 /* Init the rx queue in hardware */
239 err = i40e_fdir_rx_queue_init(pf->fdir.rxq);
241 PMD_DRV_LOG(ERR, "Failed to do FDIR RX initialization.");
245 /* switch on rx queue */
246 err = i40e_switch_rx_queue(hw, vsi->base_queue, TRUE);
248 PMD_DRV_LOG(ERR, "Failed to do FDIR RX switch on.");
252 /* reserve memory for the fdir programming packet */
253 snprintf(z_name, sizeof(z_name), "%s_%s_%d",
254 eth_dev->driver->pci_drv.driver.name,
256 eth_dev->data->port_id);
257 mz = i40e_memzone_reserve(z_name, I40E_FDIR_PKT_LEN, SOCKET_ID_ANY);
259 PMD_DRV_LOG(ERR, "Cannot init memzone for "
260 "flow director program packet.");
261 err = I40E_ERR_NO_MEMORY;
264 pf->fdir.prg_pkt = mz->addr;
265 pf->fdir.dma_addr = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
267 pf->fdir.match_counter_index = I40E_COUNTER_INDEX_FDIR(hw->pf_id);
268 PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
273 i40e_dev_rx_queue_release(pf->fdir.rxq);
276 i40e_dev_tx_queue_release(pf->fdir.txq);
279 i40e_vsi_release(vsi);
280 pf->fdir.fdir_vsi = NULL;
285 * i40e_fdir_teardown - release the Flow Director resources
286 * @pf: board private structure
289 i40e_fdir_teardown(struct i40e_pf *pf)
291 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
292 struct i40e_vsi *vsi;
294 vsi = pf->fdir.fdir_vsi;
297 i40e_switch_tx_queue(hw, vsi->base_queue, FALSE);
298 i40e_switch_rx_queue(hw, vsi->base_queue, FALSE);
299 i40e_dev_rx_queue_release(pf->fdir.rxq);
301 i40e_dev_tx_queue_release(pf->fdir.txq);
303 i40e_vsi_release(vsi);
304 pf->fdir.fdir_vsi = NULL;
307 /* check whether the flow director table in empty */
309 i40e_fdir_empty(struct i40e_hw *hw)
311 uint32_t guarant_cnt, best_cnt;
313 guarant_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
314 I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
315 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
316 best_cnt = (uint32_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
317 I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
318 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
319 if (best_cnt + guarant_cnt > 0)
326 * Initialize the configuration about bytes stream extracted as flexible payload
330 i40e_init_flx_pld(struct i40e_pf *pf)
332 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
337 * Define the bytes stream extracted as flexible payload in
338 * field vector. By default, select 8 words from the beginning
339 * of payload as flexible payload.
341 for (i = I40E_FLXPLD_L2_IDX; i < I40E_MAX_FLXPLD_LAYER; i++) {
342 index = i * I40E_MAX_FLXPLD_FIED;
343 pf->fdir.flex_set[index].src_offset = 0;
344 pf->fdir.flex_set[index].size = I40E_FDIR_MAX_FLEXWORD_NUM;
345 pf->fdir.flex_set[index].dst_offset = 0;
346 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(index), 0x0000C900);
348 I40E_PRTQF_FLX_PIT(index + 1), 0x0000FC29);/*non-used*/
350 I40E_PRTQF_FLX_PIT(index + 2), 0x0000FC2A);/*non-used*/
353 /* initialize the masks */
354 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
355 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
356 if (!I40E_VALID_PCTYPE((enum i40e_filter_pctype)pctype))
358 pf->fdir.flex_mask[pctype].word_mask = 0;
359 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), 0);
360 for (i = 0; i < I40E_FDIR_BITMASK_NUM_WORD; i++) {
361 pf->fdir.flex_mask[pctype].bitmask[i].offset = 0;
362 pf->fdir.flex_mask[pctype].bitmask[i].mask = 0;
363 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), 0);
368 #define I40E_WORD(hi, lo) (uint16_t)((((hi) << 8) & 0xFF00) | ((lo) & 0xFF))
370 #define I40E_VALIDATE_FLEX_PIT(flex_pit1, flex_pit2) do { \
371 if ((flex_pit2).src_offset < \
372 (flex_pit1).src_offset + (flex_pit1).size) { \
373 PMD_DRV_LOG(ERR, "src_offset should be not" \
374 " less than than previous offset" \
375 " + previous FSIZE."); \
381 * i40e_srcoff_to_flx_pit - transform the src_offset into flex_pit structure,
382 * and the flex_pit will be sorted by it's src_offset value
384 static inline uint16_t
385 i40e_srcoff_to_flx_pit(const uint16_t *src_offset,
386 struct i40e_fdir_flex_pit *flex_pit)
388 uint16_t src_tmp, size, num = 0;
389 uint16_t i, k, j = 0;
391 while (j < I40E_FDIR_MAX_FLEX_LEN) {
393 for (; j < I40E_FDIR_MAX_FLEX_LEN - 1; j++) {
394 if (src_offset[j + 1] == src_offset[j] + 1)
399 src_tmp = src_offset[j] + 1 - size;
400 /* the flex_pit need to be sort by src_offset */
401 for (i = 0; i < num; i++) {
402 if (src_tmp < flex_pit[i].src_offset)
405 /* if insert required, move backward */
406 for (k = num; k > i; k--)
407 flex_pit[k] = flex_pit[k - 1];
409 flex_pit[i].dst_offset = j + 1 - size;
410 flex_pit[i].src_offset = src_tmp;
411 flex_pit[i].size = size;
418 /* i40e_check_fdir_flex_payload -check flex payload configuration arguments */
420 i40e_check_fdir_flex_payload(const struct rte_eth_flex_payload_cfg *flex_cfg)
422 struct i40e_fdir_flex_pit flex_pit[I40E_FDIR_MAX_FLEX_LEN];
425 for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i++) {
426 if (flex_cfg->src_offset[i] >= I40E_MAX_FLX_SOURCE_OFF) {
427 PMD_DRV_LOG(ERR, "exceeds maxmial payload limit.");
432 memset(flex_pit, 0, sizeof(flex_pit));
433 num = i40e_srcoff_to_flx_pit(flex_cfg->src_offset, flex_pit);
434 if (num > I40E_MAX_FLXPLD_FIED) {
435 PMD_DRV_LOG(ERR, "exceeds maxmial number of flex fields.");
438 for (i = 0; i < num; i++) {
439 if (flex_pit[i].size & 0x01 || flex_pit[i].dst_offset & 0x01 ||
440 flex_pit[i].src_offset & 0x01) {
441 PMD_DRV_LOG(ERR, "flexpayload should be measured"
446 I40E_VALIDATE_FLEX_PIT(flex_pit[i], flex_pit[i + 1]);
452 * i40e_check_fdir_flex_conf -check if the flex payload and mask configuration
453 * arguments are valid
456 i40e_check_fdir_flex_conf(const struct rte_eth_fdir_flex_conf *conf)
458 const struct rte_eth_flex_payload_cfg *flex_cfg;
459 const struct rte_eth_fdir_flex_mask *flex_mask;
466 PMD_DRV_LOG(INFO, "NULL pointer.");
469 /* check flexible payload setting configuration */
470 if (conf->nb_payloads > RTE_ETH_L4_PAYLOAD) {
471 PMD_DRV_LOG(ERR, "invalid number of payload setting.");
474 for (i = 0; i < conf->nb_payloads; i++) {
475 flex_cfg = &conf->flex_set[i];
476 if (flex_cfg->type > RTE_ETH_L4_PAYLOAD) {
477 PMD_DRV_LOG(ERR, "invalid payload type.");
480 ret = i40e_check_fdir_flex_payload(flex_cfg);
482 PMD_DRV_LOG(ERR, "invalid flex payload arguments.");
487 /* check flex mask setting configuration */
488 if (conf->nb_flexmasks >= RTE_ETH_FLOW_MAX) {
489 PMD_DRV_LOG(ERR, "invalid number of flex masks.");
492 for (i = 0; i < conf->nb_flexmasks; i++) {
493 flex_mask = &conf->flex_mask[i];
494 if (!I40E_VALID_FLOW(flex_mask->flow_type)) {
495 PMD_DRV_LOG(WARNING, "invalid flow type.");
499 for (j = 0; j < I40E_FDIR_MAX_FLEX_LEN; j += sizeof(uint16_t)) {
500 mask_tmp = I40E_WORD(flex_mask->mask[j],
501 flex_mask->mask[j + 1]);
502 if (mask_tmp != 0x0 && mask_tmp != UINT16_MAX) {
504 if (nb_bitmask > I40E_FDIR_BITMASK_NUM_WORD) {
505 PMD_DRV_LOG(ERR, " exceed maximal"
506 " number of bitmasks.");
516 * i40e_set_flx_pld_cfg -configure the rule how bytes stream is extracted as flexible payload
517 * @pf: board private structure
518 * @cfg: the rule how bytes stream is extracted as flexible payload
521 i40e_set_flx_pld_cfg(struct i40e_pf *pf,
522 const struct rte_eth_flex_payload_cfg *cfg)
524 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
525 struct i40e_fdir_flex_pit flex_pit[I40E_MAX_FLXPLD_FIED];
527 uint16_t num, min_next_off; /* in words */
528 uint8_t field_idx = 0;
529 uint8_t layer_idx = 0;
532 if (cfg->type == RTE_ETH_L2_PAYLOAD)
533 layer_idx = I40E_FLXPLD_L2_IDX;
534 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
535 layer_idx = I40E_FLXPLD_L3_IDX;
536 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
537 layer_idx = I40E_FLXPLD_L4_IDX;
539 memset(flex_pit, 0, sizeof(flex_pit));
540 num = i40e_srcoff_to_flx_pit(cfg->src_offset, flex_pit);
542 for (i = 0; i < RTE_MIN(num, RTE_DIM(flex_pit)); i++) {
543 field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
544 /* record the info in fdir structure */
545 pf->fdir.flex_set[field_idx].src_offset =
546 flex_pit[i].src_offset / sizeof(uint16_t);
547 pf->fdir.flex_set[field_idx].size =
548 flex_pit[i].size / sizeof(uint16_t);
549 pf->fdir.flex_set[field_idx].dst_offset =
550 flex_pit[i].dst_offset / sizeof(uint16_t);
551 flx_pit = MK_FLX_PIT(pf->fdir.flex_set[field_idx].src_offset,
552 pf->fdir.flex_set[field_idx].size,
553 pf->fdir.flex_set[field_idx].dst_offset);
555 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
557 min_next_off = pf->fdir.flex_set[field_idx].src_offset +
558 pf->fdir.flex_set[field_idx].size;
560 for (; i < I40E_MAX_FLXPLD_FIED; i++) {
561 /* set the non-used register obeying register's constrain */
562 flx_pit = MK_FLX_PIT(min_next_off, NONUSE_FLX_PIT_FSIZE,
563 NONUSE_FLX_PIT_DEST_OFF);
565 I40E_PRTQF_FLX_PIT(layer_idx * I40E_MAX_FLXPLD_FIED + i),
572 * i40e_set_flex_mask_on_pctype - configure the mask on flexible payload
573 * @pf: board private structure
574 * @pctype: packet classify type
575 * @flex_masks: mask for flexible payload
578 i40e_set_flex_mask_on_pctype(struct i40e_pf *pf,
579 enum i40e_filter_pctype pctype,
580 const struct rte_eth_fdir_flex_mask *mask_cfg)
582 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
583 struct i40e_fdir_flex_mask *flex_mask;
584 uint32_t flxinset, fd_mask;
586 uint8_t i, nb_bitmask = 0;
588 flex_mask = &pf->fdir.flex_mask[pctype];
589 memset(flex_mask, 0, sizeof(struct i40e_fdir_flex_mask));
590 for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i += sizeof(uint16_t)) {
591 mask_tmp = I40E_WORD(mask_cfg->mask[i], mask_cfg->mask[i + 1]);
592 if (mask_tmp != 0x0) {
593 flex_mask->word_mask |=
594 I40E_FLEX_WORD_MASK(i / sizeof(uint16_t));
595 if (mask_tmp != UINT16_MAX) {
597 flex_mask->bitmask[nb_bitmask].mask = ~mask_tmp;
598 flex_mask->bitmask[nb_bitmask].offset =
599 i / sizeof(uint16_t);
604 /* write mask to hw */
605 flxinset = (flex_mask->word_mask <<
606 I40E_PRTQF_FD_FLXINSET_INSET_SHIFT) &
607 I40E_PRTQF_FD_FLXINSET_INSET_MASK;
608 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), flxinset);
610 for (i = 0; i < nb_bitmask; i++) {
611 fd_mask = (flex_mask->bitmask[i].mask <<
612 I40E_PRTQF_FD_MSK_MASK_SHIFT) &
613 I40E_PRTQF_FD_MSK_MASK_MASK;
614 fd_mask |= ((flex_mask->bitmask[i].offset +
615 I40E_FLX_OFFSET_IN_FIELD_VECTOR) <<
616 I40E_PRTQF_FD_MSK_OFFSET_SHIFT) &
617 I40E_PRTQF_FD_MSK_OFFSET_MASK;
618 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), fd_mask);
623 * Configure flow director related setting
626 i40e_fdir_configure(struct rte_eth_dev *dev)
628 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
629 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
630 struct rte_eth_fdir_flex_conf *conf;
631 enum i40e_filter_pctype pctype;
637 * configuration need to be done before
638 * flow director filters are added
639 * If filters exist, flush them.
641 if (i40e_fdir_empty(hw) < 0) {
642 ret = i40e_fdir_flush(dev);
644 PMD_DRV_LOG(ERR, "failed to flush fdir table.");
649 /* enable FDIR filter */
650 val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
651 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
652 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
654 i40e_init_flx_pld(pf); /* set flex config to default value */
656 conf = &dev->data->dev_conf.fdir_conf.flex_conf;
657 ret = i40e_check_fdir_flex_conf(conf);
659 PMD_DRV_LOG(ERR, " invalid configuration arguments.");
662 /* configure flex payload */
663 for (i = 0; i < conf->nb_payloads; i++)
664 i40e_set_flx_pld_cfg(pf, &conf->flex_set[i]);
665 /* configure flex mask*/
666 for (i = 0; i < conf->nb_flexmasks; i++) {
668 /* get translated pctype value in fd pctype register */
669 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(hw,
670 I40E_GLQF_FD_PCTYPES((int)i40e_flowtype_to_pctype(
671 conf->flex_mask[i].flow_type)));
673 pctype = i40e_flowtype_to_pctype(conf->flex_mask[i].flow_type);
675 i40e_set_flex_mask_on_pctype(pf, pctype, &conf->flex_mask[i]);
682 i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
683 unsigned char *raw_pkt,
686 static uint8_t vlan_frame[] = {0x81, 0, 0, 0};
687 uint16_t *ether_type;
688 uint8_t len = 2 * sizeof(struct ether_addr);
690 struct ipv6_hdr *ip6;
691 static const uint8_t next_proto[] = {
692 [RTE_ETH_FLOW_FRAG_IPV4] = IPPROTO_IP,
693 [RTE_ETH_FLOW_NONFRAG_IPV4_TCP] = IPPROTO_TCP,
694 [RTE_ETH_FLOW_NONFRAG_IPV4_UDP] = IPPROTO_UDP,
695 [RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] = IPPROTO_SCTP,
696 [RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] = IPPROTO_IP,
697 [RTE_ETH_FLOW_FRAG_IPV6] = IPPROTO_NONE,
698 [RTE_ETH_FLOW_NONFRAG_IPV6_TCP] = IPPROTO_TCP,
699 [RTE_ETH_FLOW_NONFRAG_IPV6_UDP] = IPPROTO_UDP,
700 [RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] = IPPROTO_SCTP,
701 [RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] = IPPROTO_NONE,
704 raw_pkt += 2 * sizeof(struct ether_addr);
705 if (vlan && fdir_input->flow_ext.vlan_tci) {
706 rte_memcpy(raw_pkt, vlan_frame, sizeof(vlan_frame));
707 rte_memcpy(raw_pkt + sizeof(uint16_t),
708 &fdir_input->flow_ext.vlan_tci,
710 raw_pkt += sizeof(vlan_frame);
711 len += sizeof(vlan_frame);
713 ether_type = (uint16_t *)raw_pkt;
714 raw_pkt += sizeof(uint16_t);
715 len += sizeof(uint16_t);
717 switch (fdir_input->flow_type) {
718 case RTE_ETH_FLOW_L2_PAYLOAD:
719 *ether_type = fdir_input->flow.l2_flow.ether_type;
721 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
722 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
723 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
724 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
725 case RTE_ETH_FLOW_FRAG_IPV4:
726 ip = (struct ipv4_hdr *)raw_pkt;
728 *ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
729 ip->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
730 /* set len to by default */
731 ip->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
732 ip->next_proto_id = fdir_input->flow.ip4_flow.proto ?
733 fdir_input->flow.ip4_flow.proto :
734 next_proto[fdir_input->flow_type];
735 ip->time_to_live = fdir_input->flow.ip4_flow.ttl ?
736 fdir_input->flow.ip4_flow.ttl :
737 I40E_FDIR_IP_DEFAULT_TTL;
738 ip->type_of_service = fdir_input->flow.ip4_flow.tos;
740 * The source and destination fields in the transmitted packet
741 * need to be presented in a reversed order with respect
742 * to the expected received packets.
744 ip->src_addr = fdir_input->flow.ip4_flow.dst_ip;
745 ip->dst_addr = fdir_input->flow.ip4_flow.src_ip;
746 len += sizeof(struct ipv4_hdr);
748 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
749 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
750 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
751 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
752 case RTE_ETH_FLOW_FRAG_IPV6:
753 ip6 = (struct ipv6_hdr *)raw_pkt;
755 *ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
757 rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
758 (fdir_input->flow.ipv6_flow.tc <<
759 I40E_FDIR_IPv6_TC_OFFSET));
761 rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
762 ip6->proto = fdir_input->flow.ipv6_flow.proto ?
763 fdir_input->flow.ipv6_flow.proto :
764 next_proto[fdir_input->flow_type];
765 ip6->hop_limits = fdir_input->flow.ipv6_flow.hop_limits ?
766 fdir_input->flow.ipv6_flow.hop_limits :
767 I40E_FDIR_IPv6_DEFAULT_HOP_LIMITS;
769 * The source and destination fields in the transmitted packet
770 * need to be presented in a reversed order with respect
771 * to the expected received packets.
773 rte_memcpy(&(ip6->src_addr),
774 &(fdir_input->flow.ipv6_flow.dst_ip),
776 rte_memcpy(&(ip6->dst_addr),
777 &(fdir_input->flow.ipv6_flow.src_ip),
779 len += sizeof(struct ipv6_hdr);
782 PMD_DRV_LOG(ERR, "unknown flow type %u.",
783 fdir_input->flow_type);
791 * i40e_fdir_construct_pkt - construct packet based on fields in input
792 * @pf: board private structure
793 * @fdir_input: input set of the flow director entry
794 * @raw_pkt: a packet to be constructed
797 i40e_fdir_construct_pkt(struct i40e_pf *pf,
798 const struct rte_eth_fdir_input *fdir_input,
799 unsigned char *raw_pkt)
801 unsigned char *payload, *ptr;
804 struct sctp_hdr *sctp;
805 uint8_t size, dst = 0;
806 uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
809 /* fill the ethernet and IP head */
810 len = i40e_fdir_fill_eth_ip_head(fdir_input, raw_pkt,
811 !!fdir_input->flow_ext.vlan_tci);
815 /* fill the L4 head */
816 switch (fdir_input->flow_type) {
817 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
818 udp = (struct udp_hdr *)(raw_pkt + len);
819 payload = (unsigned char *)udp + sizeof(struct udp_hdr);
821 * The source and destination fields in the transmitted packet
822 * need to be presented in a reversed order with respect
823 * to the expected received packets.
825 udp->src_port = fdir_input->flow.udp4_flow.dst_port;
826 udp->dst_port = fdir_input->flow.udp4_flow.src_port;
827 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_UDP_DEFAULT_LEN);
830 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
831 tcp = (struct tcp_hdr *)(raw_pkt + len);
832 payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
834 * The source and destination fields in the transmitted packet
835 * need to be presented in a reversed order with respect
836 * to the expected received packets.
838 tcp->src_port = fdir_input->flow.tcp4_flow.dst_port;
839 tcp->dst_port = fdir_input->flow.tcp4_flow.src_port;
840 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
843 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
844 sctp = (struct sctp_hdr *)(raw_pkt + len);
845 payload = (unsigned char *)sctp + sizeof(struct sctp_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 sctp->src_port = fdir_input->flow.sctp4_flow.dst_port;
852 sctp->dst_port = fdir_input->flow.sctp4_flow.src_port;
853 sctp->tag = fdir_input->flow.sctp4_flow.verify_tag;
856 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
857 case RTE_ETH_FLOW_FRAG_IPV4:
858 payload = raw_pkt + len;
859 set_idx = I40E_FLXPLD_L3_IDX;
862 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
863 udp = (struct udp_hdr *)(raw_pkt + len);
864 payload = (unsigned char *)udp + sizeof(struct udp_hdr);
866 * The source and destination fields in the transmitted packet
867 * need to be presented in a reversed order with respect
868 * to the expected received packets.
870 udp->src_port = fdir_input->flow.udp6_flow.dst_port;
871 udp->dst_port = fdir_input->flow.udp6_flow.src_port;
872 udp->dgram_len = rte_cpu_to_be_16(I40E_FDIR_IPv6_PAYLOAD_LEN);
875 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
876 tcp = (struct tcp_hdr *)(raw_pkt + len);
877 payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
879 * The source and destination fields in the transmitted packet
880 * need to be presented in a reversed order with respect
881 * to the expected received packets.
883 tcp->data_off = I40E_FDIR_TCP_DEFAULT_DATAOFF;
884 tcp->src_port = fdir_input->flow.udp6_flow.dst_port;
885 tcp->dst_port = fdir_input->flow.udp6_flow.src_port;
888 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
889 sctp = (struct sctp_hdr *)(raw_pkt + len);
890 payload = (unsigned char *)sctp + sizeof(struct sctp_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 sctp->src_port = fdir_input->flow.sctp6_flow.dst_port;
897 sctp->dst_port = fdir_input->flow.sctp6_flow.src_port;
898 sctp->tag = fdir_input->flow.sctp6_flow.verify_tag;
901 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
902 case RTE_ETH_FLOW_FRAG_IPV6:
903 payload = raw_pkt + len;
904 set_idx = I40E_FLXPLD_L3_IDX;
906 case RTE_ETH_FLOW_L2_PAYLOAD:
907 payload = raw_pkt + len;
909 * ARP packet is a special case on which the payload
910 * starts after the whole ARP header
912 if (fdir_input->flow.l2_flow.ether_type ==
913 rte_cpu_to_be_16(ETHER_TYPE_ARP))
914 payload += sizeof(struct arp_hdr);
915 set_idx = I40E_FLXPLD_L2_IDX;
918 PMD_DRV_LOG(ERR, "unknown flow type %u.", fdir_input->flow_type);
922 /* fill the flexbytes to payload */
923 for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
924 pit_idx = set_idx * I40E_MAX_FLXPLD_FIED + i;
925 size = pf->fdir.flex_set[pit_idx].size;
928 dst = pf->fdir.flex_set[pit_idx].dst_offset * sizeof(uint16_t);
930 pf->fdir.flex_set[pit_idx].src_offset * sizeof(uint16_t);
931 (void)rte_memcpy(ptr,
932 &fdir_input->flow_ext.flexbytes[dst],
933 size * sizeof(uint16_t));
939 /* Construct the tx flags */
940 static inline uint64_t
941 i40e_build_ctob(uint32_t td_cmd,
946 return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
947 ((uint64_t)td_cmd << I40E_TXD_QW1_CMD_SHIFT) |
948 ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
949 ((uint64_t)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
950 ((uint64_t)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT));
954 * check the programming status descriptor in rx queue.
955 * done after Programming Flow Director is programmed on
959 i40e_check_fdir_programming_status(struct i40e_rx_queue *rxq)
961 volatile union i40e_rx_desc *rxdp;
968 rxdp = &rxq->rx_ring[rxq->rx_tail];
969 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
970 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
971 >> I40E_RXD_QW1_STATUS_SHIFT;
973 if (rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
974 len = qword1 >> I40E_RX_PROG_STATUS_DESC_LENGTH_SHIFT;
975 id = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_PROGID_MASK) >>
976 I40E_RX_PROG_STATUS_DESC_QW1_PROGID_SHIFT;
978 if (len == I40E_RX_PROG_STATUS_DESC_LENGTH &&
979 id == I40E_RX_PROG_STATUS_DESC_FD_FILTER_STATUS) {
981 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
982 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
984 I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
985 PMD_DRV_LOG(ERR, "Failed to add FDIR filter"
986 " (FD_ID %u): programming status"
988 rxdp->wb.qword0.hi_dword.fd_id);
990 } else if (error == (0x1 <<
991 I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
992 PMD_DRV_LOG(ERR, "Failed to delete FDIR filter"
993 " (FD_ID %u): programming status"
995 rxdp->wb.qword0.hi_dword.fd_id);
998 PMD_DRV_LOG(ERR, "invalid programming status"
999 " reported, error = %u.", error);
1001 PMD_DRV_LOG(ERR, "unknown programming status"
1002 " reported, len = %d, id = %u.", len, id);
1003 rxdp->wb.qword1.status_error_len = 0;
1005 if (unlikely(rxq->rx_tail == rxq->nb_rx_desc))
1012 * i40e_add_del_fdir_filter - add or remove a flow director filter.
1013 * @pf: board private structure
1014 * @filter: fdir filter entry
1015 * @add: 0 - delete, 1 - add
1018 i40e_add_del_fdir_filter(struct rte_eth_dev *dev,
1019 const struct rte_eth_fdir_filter *filter,
1022 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1023 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1024 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1025 enum i40e_filter_pctype pctype;
1028 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
1029 PMD_DRV_LOG(ERR, "FDIR is not enabled, please"
1030 " check the mode in fdir_conf.");
1034 if (!I40E_VALID_FLOW(filter->input.flow_type)) {
1035 PMD_DRV_LOG(ERR, "invalid flow_type input.");
1038 if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1039 PMD_DRV_LOG(ERR, "Invalid queue ID");
1042 if (filter->input.flow_ext.is_vf &&
1043 filter->input.flow_ext.dst_id >= pf->vf_num) {
1044 PMD_DRV_LOG(ERR, "Invalid VF ID");
1048 memset(pkt, 0, I40E_FDIR_PKT_LEN);
1050 ret = i40e_fdir_construct_pkt(pf, &filter->input, pkt);
1052 PMD_DRV_LOG(ERR, "construct packet for fdir fails.");
1057 /* get translated pctype value in fd pctype register */
1058 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(hw,
1059 I40E_GLQF_FD_PCTYPES((int)i40e_flowtype_to_pctype(
1060 filter->input.flow_type)));
1062 pctype = i40e_flowtype_to_pctype(filter->input.flow_type);
1065 ret = i40e_fdir_filter_programming(pf, pctype, filter, add);
1067 PMD_DRV_LOG(ERR, "fdir programming fails for PCTYPE(%u).",
1075 * i40e_fdir_filter_programming - Program a flow director filter rule.
1076 * Is done by Flow Director Programming Descriptor followed by packet
1077 * structure that contains the filter fields need to match.
1078 * @pf: board private structure
1080 * @filter: fdir filter entry
1081 * @add: 0 - delete, 1 - add
1084 i40e_fdir_filter_programming(struct i40e_pf *pf,
1085 enum i40e_filter_pctype pctype,
1086 const struct rte_eth_fdir_filter *filter,
1089 struct i40e_tx_queue *txq = pf->fdir.txq;
1090 struct i40e_rx_queue *rxq = pf->fdir.rxq;
1091 const struct rte_eth_fdir_action *fdir_action = &filter->action;
1092 volatile struct i40e_tx_desc *txdp;
1093 volatile struct i40e_filter_program_desc *fdirdp;
1098 PMD_DRV_LOG(INFO, "filling filter programming descriptor.");
1099 fdirdp = (volatile struct i40e_filter_program_desc *)
1100 (&(txq->tx_ring[txq->tx_tail]));
1102 fdirdp->qindex_flex_ptype_vsi =
1103 rte_cpu_to_le_32((fdir_action->rx_queue <<
1104 I40E_TXD_FLTR_QW0_QINDEX_SHIFT) &
1105 I40E_TXD_FLTR_QW0_QINDEX_MASK);
1107 fdirdp->qindex_flex_ptype_vsi |=
1108 rte_cpu_to_le_32((fdir_action->flex_off <<
1109 I40E_TXD_FLTR_QW0_FLEXOFF_SHIFT) &
1110 I40E_TXD_FLTR_QW0_FLEXOFF_MASK);
1112 fdirdp->qindex_flex_ptype_vsi |=
1113 rte_cpu_to_le_32((pctype <<
1114 I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) &
1115 I40E_TXD_FLTR_QW0_PCTYPE_MASK);
1117 if (filter->input.flow_ext.is_vf)
1118 vsi_id = pf->vfs[filter->input.flow_ext.dst_id].vsi->vsi_id;
1120 /* Use LAN VSI Id by default */
1121 vsi_id = pf->main_vsi->vsi_id;
1122 fdirdp->qindex_flex_ptype_vsi |=
1123 rte_cpu_to_le_32(((uint32_t)vsi_id <<
1124 I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT) &
1125 I40E_TXD_FLTR_QW0_DEST_VSI_MASK);
1127 fdirdp->dtype_cmd_cntindex =
1128 rte_cpu_to_le_32(I40E_TX_DESC_DTYPE_FILTER_PROG);
1131 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1132 I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE <<
1133 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1135 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32(
1136 I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE <<
1137 I40E_TXD_FLTR_QW1_PCMD_SHIFT);
1139 if (fdir_action->behavior == RTE_ETH_FDIR_REJECT)
1140 dest = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1141 else if (fdir_action->behavior == RTE_ETH_FDIR_ACCEPT)
1142 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1143 else if (fdir_action->behavior == RTE_ETH_FDIR_PASSTHRU)
1144 dest = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_OTHER;
1146 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1147 " unsupported fdir behavior.");
1151 fdirdp->dtype_cmd_cntindex |= rte_cpu_to_le_32((dest <<
1152 I40E_TXD_FLTR_QW1_DEST_SHIFT) &
1153 I40E_TXD_FLTR_QW1_DEST_MASK);
1155 fdirdp->dtype_cmd_cntindex |=
1156 rte_cpu_to_le_32((fdir_action->report_status<<
1157 I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT) &
1158 I40E_TXD_FLTR_QW1_FD_STATUS_MASK);
1160 fdirdp->dtype_cmd_cntindex |=
1161 rte_cpu_to_le_32(I40E_TXD_FLTR_QW1_CNT_ENA_MASK);
1162 fdirdp->dtype_cmd_cntindex |=
1164 ((uint32_t)pf->fdir.match_counter_index <<
1165 I40E_TXD_FLTR_QW1_CNTINDEX_SHIFT) &
1166 I40E_TXD_FLTR_QW1_CNTINDEX_MASK);
1168 fdirdp->fd_id = rte_cpu_to_le_32(filter->soft_id);
1170 PMD_DRV_LOG(INFO, "filling transmit descriptor.");
1171 txdp = &(txq->tx_ring[txq->tx_tail + 1]);
1172 txdp->buffer_addr = rte_cpu_to_le_64(pf->fdir.dma_addr);
1173 td_cmd = I40E_TX_DESC_CMD_EOP |
1174 I40E_TX_DESC_CMD_RS |
1175 I40E_TX_DESC_CMD_DUMMY;
1177 txdp->cmd_type_offset_bsz =
1178 i40e_build_ctob(td_cmd, 0, I40E_FDIR_PKT_LEN, 0);
1180 txq->tx_tail += 2; /* set 2 descriptors above, fdirdp and txdp */
1181 if (txq->tx_tail >= txq->nb_tx_desc)
1183 /* Update the tx tail register */
1185 I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
1187 for (i = 0; i < I40E_FDIR_WAIT_COUNT; i++) {
1188 rte_delay_us(I40E_FDIR_WAIT_INTERVAL_US);
1189 if ((txdp->cmd_type_offset_bsz &
1190 rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) ==
1191 rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
1194 if (i >= I40E_FDIR_WAIT_COUNT) {
1195 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1196 " time out to get DD on tx queue.");
1199 /* totally delay 10 ms to check programming status*/
1200 rte_delay_us((I40E_FDIR_WAIT_COUNT - i) * I40E_FDIR_WAIT_INTERVAL_US);
1201 if (i40e_check_fdir_programming_status(rxq) < 0) {
1202 PMD_DRV_LOG(ERR, "Failed to program FDIR filter:"
1203 " programming status reported.");
1211 * i40e_fdir_flush - clear all filters of Flow Director table
1212 * @pf: board private structure
1215 i40e_fdir_flush(struct rte_eth_dev *dev)
1217 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1218 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1220 uint16_t guarant_cnt, best_cnt;
1223 I40E_WRITE_REG(hw, I40E_PFQF_CTL_1, I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
1224 I40E_WRITE_FLUSH(hw);
1226 for (i = 0; i < I40E_FDIR_FLUSH_RETRY; i++) {
1227 rte_delay_ms(I40E_FDIR_FLUSH_INTERVAL_MS);
1228 reg = I40E_READ_REG(hw, I40E_PFQF_CTL_1);
1229 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
1232 if (i >= I40E_FDIR_FLUSH_RETRY) {
1233 PMD_DRV_LOG(ERR, "FD table did not flush, may need more time.");
1236 guarant_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1237 I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1238 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1239 best_cnt = (uint16_t)((I40E_READ_REG(hw, I40E_PFQF_FDSTAT) &
1240 I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1241 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1242 if (guarant_cnt != 0 || best_cnt != 0) {
1243 PMD_DRV_LOG(ERR, "Failed to flush FD table.");
1246 PMD_DRV_LOG(INFO, "FD table Flush success.");
1251 i40e_fdir_info_get_flex_set(struct i40e_pf *pf,
1252 struct rte_eth_flex_payload_cfg *flex_set,
1255 struct i40e_fdir_flex_pit *flex_pit;
1256 struct rte_eth_flex_payload_cfg *ptr = flex_set;
1257 uint16_t src, dst, size, j, k;
1258 uint8_t i, layer_idx;
1260 for (layer_idx = I40E_FLXPLD_L2_IDX;
1261 layer_idx <= I40E_FLXPLD_L4_IDX;
1263 if (layer_idx == I40E_FLXPLD_L2_IDX)
1264 ptr->type = RTE_ETH_L2_PAYLOAD;
1265 else if (layer_idx == I40E_FLXPLD_L3_IDX)
1266 ptr->type = RTE_ETH_L3_PAYLOAD;
1267 else if (layer_idx == I40E_FLXPLD_L4_IDX)
1268 ptr->type = RTE_ETH_L4_PAYLOAD;
1270 for (i = 0; i < I40E_MAX_FLXPLD_FIED; i++) {
1271 flex_pit = &pf->fdir.flex_set[layer_idx *
1272 I40E_MAX_FLXPLD_FIED + i];
1273 if (flex_pit->size == 0)
1275 src = flex_pit->src_offset * sizeof(uint16_t);
1276 dst = flex_pit->dst_offset * sizeof(uint16_t);
1277 size = flex_pit->size * sizeof(uint16_t);
1278 for (j = src, k = dst; j < src + size; j++, k++)
1279 ptr->src_offset[k] = j;
1287 i40e_fdir_info_get_flex_mask(struct i40e_pf *pf,
1288 struct rte_eth_fdir_flex_mask *flex_mask,
1291 struct i40e_fdir_flex_mask *mask;
1292 struct rte_eth_fdir_flex_mask *ptr = flex_mask;
1295 uint16_t off_bytes, mask_tmp;
1297 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1298 i <= I40E_FILTER_PCTYPE_L2_PAYLOAD;
1300 mask = &pf->fdir.flex_mask[i];
1301 if (!I40E_VALID_PCTYPE((enum i40e_filter_pctype)i))
1303 flow_type = i40e_pctype_to_flowtype((enum i40e_filter_pctype)i);
1304 for (j = 0; j < I40E_FDIR_MAX_FLEXWORD_NUM; j++) {
1305 if (mask->word_mask & I40E_FLEX_WORD_MASK(j)) {
1306 ptr->mask[j * sizeof(uint16_t)] = UINT8_MAX;
1307 ptr->mask[j * sizeof(uint16_t) + 1] = UINT8_MAX;
1309 ptr->mask[j * sizeof(uint16_t)] = 0x0;
1310 ptr->mask[j * sizeof(uint16_t) + 1] = 0x0;
1313 for (j = 0; j < I40E_FDIR_BITMASK_NUM_WORD; j++) {
1314 off_bytes = mask->bitmask[j].offset * sizeof(uint16_t);
1315 mask_tmp = ~mask->bitmask[j].mask;
1316 ptr->mask[off_bytes] &= I40E_HI_BYTE(mask_tmp);
1317 ptr->mask[off_bytes + 1] &= I40E_LO_BYTE(mask_tmp);
1319 ptr->flow_type = flow_type;
1326 * i40e_fdir_info_get - get information of Flow Director
1327 * @pf: ethernet device to get info from
1328 * @fdir: a pointer to a structure of type *rte_eth_fdir_info* to be filled with
1329 * the flow director information.
1332 i40e_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir)
1334 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1335 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1336 uint16_t num_flex_set = 0;
1337 uint16_t num_flex_mask = 0;
1339 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT)
1340 fdir->mode = RTE_FDIR_MODE_PERFECT;
1342 fdir->mode = RTE_FDIR_MODE_NONE;
1345 (uint32_t)hw->func_caps.fd_filters_guaranteed;
1347 (uint32_t)hw->func_caps.fd_filters_best_effort;
1348 fdir->max_flexpayload = I40E_FDIR_MAX_FLEX_LEN;
1349 fdir->flow_types_mask[0] = I40E_FDIR_FLOWS;
1350 fdir->flex_payload_unit = sizeof(uint16_t);
1351 fdir->flex_bitmask_unit = sizeof(uint16_t);
1352 fdir->max_flex_payload_segment_num = I40E_MAX_FLXPLD_FIED;
1353 fdir->flex_payload_limit = I40E_MAX_FLX_SOURCE_OFF;
1354 fdir->max_flex_bitmask_num = I40E_FDIR_BITMASK_NUM_WORD;
1356 i40e_fdir_info_get_flex_set(pf,
1357 fdir->flex_conf.flex_set,
1359 i40e_fdir_info_get_flex_mask(pf,
1360 fdir->flex_conf.flex_mask,
1363 fdir->flex_conf.nb_payloads = num_flex_set;
1364 fdir->flex_conf.nb_flexmasks = num_flex_mask;
1368 * i40e_fdir_stat_get - get statistics of Flow Director
1369 * @pf: ethernet device to get info from
1370 * @stat: a pointer to a structure of type *rte_eth_fdir_stats* to be filled with
1371 * the flow director statistics.
1374 i40e_fdir_stats_get(struct rte_eth_dev *dev, struct rte_eth_fdir_stats *stat)
1376 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1377 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1380 fdstat = I40E_READ_REG(hw, I40E_PFQF_FDSTAT);
1382 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) >>
1383 I40E_PFQF_FDSTAT_GUARANT_CNT_SHIFT);
1385 (uint32_t)((fdstat & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
1386 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
1390 i40e_fdir_filter_set(struct rte_eth_dev *dev,
1391 struct rte_eth_fdir_filter_info *info)
1393 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1397 PMD_DRV_LOG(ERR, "Invalid pointer");
1401 switch (info->info_type) {
1402 case RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT:
1403 ret = i40e_fdir_filter_inset_select(pf,
1404 &(info->info.input_set_conf));
1407 PMD_DRV_LOG(ERR, "FD filter info type (%d) not supported",
1416 * i40e_fdir_ctrl_func - deal with all operations on flow director.
1417 * @pf: board private structure
1418 * @filter_op:operation will be taken.
1419 * @arg: a pointer to specific structure corresponding to the filter_op
1422 i40e_fdir_ctrl_func(struct rte_eth_dev *dev,
1423 enum rte_filter_op filter_op,
1426 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1429 if ((pf->flags & I40E_FLAG_FDIR) == 0)
1432 if (filter_op == RTE_ETH_FILTER_NOP)
1435 if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
1438 switch (filter_op) {
1439 case RTE_ETH_FILTER_ADD:
1440 ret = i40e_add_del_fdir_filter(dev,
1441 (struct rte_eth_fdir_filter *)arg,
1444 case RTE_ETH_FILTER_DELETE:
1445 ret = i40e_add_del_fdir_filter(dev,
1446 (struct rte_eth_fdir_filter *)arg,
1449 case RTE_ETH_FILTER_FLUSH:
1450 ret = i40e_fdir_flush(dev);
1452 case RTE_ETH_FILTER_INFO:
1453 i40e_fdir_info_get(dev, (struct rte_eth_fdir_info *)arg);
1455 case RTE_ETH_FILTER_SET:
1456 ret = i40e_fdir_filter_set(dev,
1457 (struct rte_eth_fdir_filter_info *)arg);
1459 case RTE_ETH_FILTER_STATS:
1460 i40e_fdir_stats_get(dev, (struct rte_eth_fdir_stats *)arg);
1463 PMD_DRV_LOG(ERR, "unknown operation %u.", filter_op);