4 * Copyright(c) 2010-2017 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 <rte_malloc.h>
35 #include <rte_tailq.h>
37 #include "base/i40e_prototype.h"
38 #include "i40e_ethdev.h"
40 #include "i40e_rxtx.h"
41 #include "rte_pmd_i40e.h"
44 rte_pmd_i40e_ping_vfs(uint16_t port, uint16_t vf)
46 struct rte_eth_dev *dev;
49 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
51 dev = &rte_eth_devices[port];
53 if (!is_i40e_supported(dev))
56 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
58 if (vf >= pf->vf_num || !pf->vfs) {
59 PMD_DRV_LOG(ERR, "Invalid argument.");
63 i40e_notify_vf_link_status(dev, &pf->vfs[vf]);
69 rte_pmd_i40e_set_vf_mac_anti_spoof(uint16_t port, uint16_t vf_id, uint8_t on)
71 struct rte_eth_dev *dev;
75 struct i40e_vsi_context ctxt;
78 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
80 dev = &rte_eth_devices[port];
82 if (!is_i40e_supported(dev))
85 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
87 if (vf_id >= pf->vf_num || !pf->vfs) {
88 PMD_DRV_LOG(ERR, "Invalid argument.");
92 vsi = pf->vfs[vf_id].vsi;
94 PMD_DRV_LOG(ERR, "Invalid VSI.");
98 /* Check if it has been already on or off */
99 if (vsi->info.valid_sections &
100 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SECURITY_VALID)) {
102 if ((vsi->info.sec_flags &
103 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK) ==
104 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK)
105 return 0; /* already on */
107 if ((vsi->info.sec_flags &
108 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK) == 0)
109 return 0; /* already off */
113 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
115 vsi->info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
117 vsi->info.sec_flags &= ~I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
119 memset(&ctxt, 0, sizeof(ctxt));
120 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
121 ctxt.seid = vsi->seid;
123 hw = I40E_VSI_TO_HW(vsi);
124 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
125 if (ret != I40E_SUCCESS) {
127 PMD_DRV_LOG(ERR, "Failed to update VSI params");
134 i40e_add_rm_all_vlan_filter(struct i40e_vsi *vsi, uint8_t add)
138 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
139 struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
142 for (j = 0; j < I40E_VFTA_SIZE; j++) {
146 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
147 if (!(vsi->vfta[j] & (1 << k)))
150 vlan_id = j * I40E_UINT32_BIT_SIZE + k;
154 vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
156 ret = i40e_aq_add_vlan(hw, vsi->seid,
157 &vlan_data, 1, NULL);
159 ret = i40e_aq_remove_vlan(hw, vsi->seid,
160 &vlan_data, 1, NULL);
161 if (ret != I40E_SUCCESS) {
163 "Failed to add/rm vlan filter");
173 rte_pmd_i40e_set_vf_vlan_anti_spoof(uint16_t port, uint16_t vf_id, uint8_t on)
175 struct rte_eth_dev *dev;
177 struct i40e_vsi *vsi;
179 struct i40e_vsi_context ctxt;
182 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
184 dev = &rte_eth_devices[port];
186 if (!is_i40e_supported(dev))
189 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
191 if (vf_id >= pf->vf_num || !pf->vfs) {
192 PMD_DRV_LOG(ERR, "Invalid argument.");
196 vsi = pf->vfs[vf_id].vsi;
198 PMD_DRV_LOG(ERR, "Invalid VSI.");
202 /* Check if it has been already on or off */
203 if (vsi->vlan_anti_spoof_on == on)
204 return 0; /* already on or off */
206 vsi->vlan_anti_spoof_on = on;
207 if (!vsi->vlan_filter_on) {
208 ret = i40e_add_rm_all_vlan_filter(vsi, on);
210 PMD_DRV_LOG(ERR, "Failed to add/remove VLAN filters.");
215 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
217 vsi->info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK;
219 vsi->info.sec_flags &= ~I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK;
221 memset(&ctxt, 0, sizeof(ctxt));
222 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
223 ctxt.seid = vsi->seid;
225 hw = I40E_VSI_TO_HW(vsi);
226 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
227 if (ret != I40E_SUCCESS) {
229 PMD_DRV_LOG(ERR, "Failed to update VSI params");
236 i40e_vsi_rm_mac_filter(struct i40e_vsi *vsi)
238 struct i40e_mac_filter *f;
239 struct i40e_macvlan_filter *mv_f;
241 enum rte_mac_filter_type filter_type;
242 int ret = I40E_SUCCESS;
245 /* remove all the MACs */
246 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
247 vlan_num = vsi->vlan_num;
248 filter_type = f->mac_info.filter_type;
249 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
250 filter_type == RTE_MACVLAN_HASH_MATCH) {
252 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
253 return I40E_ERR_PARAM;
255 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
256 filter_type == RTE_MAC_HASH_MATCH)
259 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
261 PMD_DRV_LOG(ERR, "failed to allocate memory");
262 return I40E_ERR_NO_MEMORY;
265 for (i = 0; i < vlan_num; i++) {
266 mv_f[i].filter_type = filter_type;
267 rte_memcpy(&mv_f[i].macaddr,
268 &f->mac_info.mac_addr,
271 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
272 filter_type == RTE_MACVLAN_HASH_MATCH) {
273 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
274 &f->mac_info.mac_addr);
275 if (ret != I40E_SUCCESS) {
281 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
282 if (ret != I40E_SUCCESS) {
295 i40e_vsi_restore_mac_filter(struct i40e_vsi *vsi)
297 struct i40e_mac_filter *f;
298 struct i40e_macvlan_filter *mv_f;
300 int ret = I40E_SUCCESS;
303 /* restore all the MACs */
304 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
305 if ((f->mac_info.filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
306 (f->mac_info.filter_type == RTE_MACVLAN_HASH_MATCH)) {
308 * If vlan_num is 0, that's the first time to add mac,
309 * set mask for vlan_id 0.
311 if (vsi->vlan_num == 0) {
312 i40e_set_vlan_filter(vsi, 0, 1);
315 vlan_num = vsi->vlan_num;
316 } else if ((f->mac_info.filter_type == RTE_MAC_PERFECT_MATCH) ||
317 (f->mac_info.filter_type == RTE_MAC_HASH_MATCH))
320 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
322 PMD_DRV_LOG(ERR, "failed to allocate memory");
323 return I40E_ERR_NO_MEMORY;
326 for (i = 0; i < vlan_num; i++) {
327 mv_f[i].filter_type = f->mac_info.filter_type;
328 rte_memcpy(&mv_f[i].macaddr,
329 &f->mac_info.mac_addr,
333 if (f->mac_info.filter_type == RTE_MACVLAN_PERFECT_MATCH ||
334 f->mac_info.filter_type == RTE_MACVLAN_HASH_MATCH) {
335 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
336 &f->mac_info.mac_addr);
337 if (ret != I40E_SUCCESS) {
343 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
344 if (ret != I40E_SUCCESS) {
357 i40e_vsi_set_tx_loopback(struct i40e_vsi *vsi, uint8_t on)
359 struct i40e_vsi_context ctxt;
366 hw = I40E_VSI_TO_HW(vsi);
368 /* Use the FW API if FW >= v5.0 */
369 if (hw->aq.fw_maj_ver < 5) {
370 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
374 /* Check if it has been already on or off */
375 if (vsi->info.valid_sections &
376 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID)) {
378 if ((vsi->info.switch_id &
379 I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) ==
380 I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB)
381 return 0; /* already on */
383 if ((vsi->info.switch_id &
384 I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) == 0)
385 return 0; /* already off */
389 /* remove all the MAC and VLAN first */
390 ret = i40e_vsi_rm_mac_filter(vsi);
392 PMD_INIT_LOG(ERR, "Failed to remove MAC filters.");
395 if (vsi->vlan_anti_spoof_on || vsi->vlan_filter_on) {
396 ret = i40e_add_rm_all_vlan_filter(vsi, 0);
398 PMD_INIT_LOG(ERR, "Failed to remove VLAN filters.");
403 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
405 vsi->info.switch_id |= I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
407 vsi->info.switch_id &= ~I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
409 memset(&ctxt, 0, sizeof(ctxt));
410 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
411 ctxt.seid = vsi->seid;
413 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
414 if (ret != I40E_SUCCESS) {
415 PMD_DRV_LOG(ERR, "Failed to update VSI params");
419 /* add all the MAC and VLAN back */
420 ret = i40e_vsi_restore_mac_filter(vsi);
423 if (vsi->vlan_anti_spoof_on || vsi->vlan_filter_on) {
424 ret = i40e_add_rm_all_vlan_filter(vsi, 1);
433 rte_pmd_i40e_set_tx_loopback(uint16_t port, uint8_t on)
435 struct rte_eth_dev *dev;
437 struct i40e_pf_vf *vf;
438 struct i40e_vsi *vsi;
442 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
444 dev = &rte_eth_devices[port];
446 if (!is_i40e_supported(dev))
449 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
451 /* setup PF TX loopback */
453 ret = i40e_vsi_set_tx_loopback(vsi, on);
457 /* setup TX loopback for all the VFs */
459 /* if no VF, do nothing. */
463 for (vf_id = 0; vf_id < pf->vf_num; vf_id++) {
464 vf = &pf->vfs[vf_id];
467 ret = i40e_vsi_set_tx_loopback(vsi, on);
476 rte_pmd_i40e_set_vf_unicast_promisc(uint16_t port, uint16_t vf_id, uint8_t on)
478 struct rte_eth_dev *dev;
480 struct i40e_vsi *vsi;
484 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
486 dev = &rte_eth_devices[port];
488 if (!is_i40e_supported(dev))
491 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
493 if (vf_id >= pf->vf_num || !pf->vfs) {
494 PMD_DRV_LOG(ERR, "Invalid argument.");
498 vsi = pf->vfs[vf_id].vsi;
500 PMD_DRV_LOG(ERR, "Invalid VSI.");
504 hw = I40E_VSI_TO_HW(vsi);
506 ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
508 if (ret != I40E_SUCCESS) {
510 PMD_DRV_LOG(ERR, "Failed to set unicast promiscuous mode");
517 rte_pmd_i40e_set_vf_multicast_promisc(uint16_t port, uint16_t vf_id, uint8_t on)
519 struct rte_eth_dev *dev;
521 struct i40e_vsi *vsi;
525 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
527 dev = &rte_eth_devices[port];
529 if (!is_i40e_supported(dev))
532 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
534 if (vf_id >= pf->vf_num || !pf->vfs) {
535 PMD_DRV_LOG(ERR, "Invalid argument.");
539 vsi = pf->vfs[vf_id].vsi;
541 PMD_DRV_LOG(ERR, "Invalid VSI.");
545 hw = I40E_VSI_TO_HW(vsi);
547 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
549 if (ret != I40E_SUCCESS) {
551 PMD_DRV_LOG(ERR, "Failed to set multicast promiscuous mode");
558 rte_pmd_i40e_set_vf_mac_addr(uint16_t port, uint16_t vf_id,
559 struct ether_addr *mac_addr)
561 struct i40e_mac_filter *f;
562 struct rte_eth_dev *dev;
563 struct i40e_pf_vf *vf;
564 struct i40e_vsi *vsi;
568 if (i40e_validate_mac_addr((u8 *)mac_addr) != I40E_SUCCESS)
571 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
573 dev = &rte_eth_devices[port];
575 if (!is_i40e_supported(dev))
578 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
580 if (vf_id >= pf->vf_num || !pf->vfs)
583 vf = &pf->vfs[vf_id];
586 PMD_DRV_LOG(ERR, "Invalid VSI.");
590 ether_addr_copy(mac_addr, &vf->mac_addr);
592 /* Remove all existing mac */
593 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
594 if (i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr)
596 PMD_DRV_LOG(WARNING, "Delete MAC failed");
601 /* Set vlan strip on/off for specific VF from host */
603 rte_pmd_i40e_set_vf_vlan_stripq(uint16_t port, uint16_t vf_id, uint8_t on)
605 struct rte_eth_dev *dev;
607 struct i40e_vsi *vsi;
610 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
612 dev = &rte_eth_devices[port];
614 if (!is_i40e_supported(dev))
617 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
619 if (vf_id >= pf->vf_num || !pf->vfs) {
620 PMD_DRV_LOG(ERR, "Invalid argument.");
624 vsi = pf->vfs[vf_id].vsi;
629 ret = i40e_vsi_config_vlan_stripping(vsi, !!on);
630 if (ret != I40E_SUCCESS) {
632 PMD_DRV_LOG(ERR, "Failed to set VLAN stripping!");
638 int rte_pmd_i40e_set_vf_vlan_insert(uint16_t port, uint16_t vf_id,
641 struct rte_eth_dev *dev;
644 struct i40e_vsi *vsi;
645 struct i40e_vsi_context ctxt;
648 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
650 if (vlan_id > ETHER_MAX_VLAN_ID) {
651 PMD_DRV_LOG(ERR, "Invalid VLAN ID.");
655 dev = &rte_eth_devices[port];
657 if (!is_i40e_supported(dev))
660 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
661 hw = I40E_PF_TO_HW(pf);
664 * return -ENODEV if SRIOV not enabled, VF number not configured
665 * or no queue assigned.
667 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
671 if (vf_id >= pf->vf_num || !pf->vfs) {
672 PMD_DRV_LOG(ERR, "Invalid VF ID.");
676 vsi = pf->vfs[vf_id].vsi;
678 PMD_DRV_LOG(ERR, "Invalid VSI.");
682 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
683 vsi->info.pvid = vlan_id;
685 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID;
687 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_INSERT_PVID;
689 memset(&ctxt, 0, sizeof(ctxt));
690 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
691 ctxt.seid = vsi->seid;
693 hw = I40E_VSI_TO_HW(vsi);
694 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
695 if (ret != I40E_SUCCESS) {
697 PMD_DRV_LOG(ERR, "Failed to update VSI params");
703 int rte_pmd_i40e_set_vf_broadcast(uint16_t port, uint16_t vf_id,
706 struct rte_eth_dev *dev;
708 struct i40e_vsi *vsi;
710 struct i40e_mac_filter_info filter;
711 struct ether_addr broadcast = {
712 .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
715 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
718 PMD_DRV_LOG(ERR, "on should be 0 or 1.");
722 dev = &rte_eth_devices[port];
724 if (!is_i40e_supported(dev))
727 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
728 hw = I40E_PF_TO_HW(pf);
730 if (vf_id >= pf->vf_num || !pf->vfs) {
731 PMD_DRV_LOG(ERR, "Invalid VF ID.");
736 * return -ENODEV if SRIOV not enabled, VF number not configured
737 * or no queue assigned.
739 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
740 pf->vf_nb_qps == 0) {
741 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
745 vsi = pf->vfs[vf_id].vsi;
747 PMD_DRV_LOG(ERR, "Invalid VSI.");
752 rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
753 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
754 ret = i40e_vsi_add_mac(vsi, &filter);
756 ret = i40e_vsi_delete_mac(vsi, &broadcast);
759 if (ret != I40E_SUCCESS && ret != I40E_ERR_PARAM) {
761 PMD_DRV_LOG(ERR, "Failed to set VSI broadcast");
769 int rte_pmd_i40e_set_vf_vlan_tag(uint16_t port, uint16_t vf_id, uint8_t on)
771 struct rte_eth_dev *dev;
774 struct i40e_vsi *vsi;
775 struct i40e_vsi_context ctxt;
778 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
781 PMD_DRV_LOG(ERR, "on should be 0 or 1.");
785 dev = &rte_eth_devices[port];
787 if (!is_i40e_supported(dev))
790 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
791 hw = I40E_PF_TO_HW(pf);
794 * return -ENODEV if SRIOV not enabled, VF number not configured
795 * or no queue assigned.
797 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
798 pf->vf_nb_qps == 0) {
799 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
803 if (vf_id >= pf->vf_num || !pf->vfs) {
804 PMD_DRV_LOG(ERR, "Invalid VF ID.");
808 vsi = pf->vfs[vf_id].vsi;
810 PMD_DRV_LOG(ERR, "Invalid VSI.");
814 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
816 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
817 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
819 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
820 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_MODE_TAGGED;
823 memset(&ctxt, 0, sizeof(ctxt));
824 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
825 ctxt.seid = vsi->seid;
827 hw = I40E_VSI_TO_HW(vsi);
828 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
829 if (ret != I40E_SUCCESS) {
831 PMD_DRV_LOG(ERR, "Failed to update VSI params");
838 i40e_vlan_filter_count(struct i40e_vsi *vsi)
844 for (j = 0; j < I40E_VFTA_SIZE; j++) {
848 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
849 if (!(vsi->vfta[j] & (1 << k)))
852 vlan_id = j * I40E_UINT32_BIT_SIZE + k;
863 int rte_pmd_i40e_set_vf_vlan_filter(uint16_t port, uint16_t vlan_id,
864 uint64_t vf_mask, uint8_t on)
866 struct rte_eth_dev *dev;
869 struct i40e_vsi *vsi;
871 int ret = I40E_SUCCESS;
873 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
875 dev = &rte_eth_devices[port];
877 if (!is_i40e_supported(dev))
880 if (vlan_id > ETHER_MAX_VLAN_ID || !vlan_id) {
881 PMD_DRV_LOG(ERR, "Invalid VLAN ID.");
886 PMD_DRV_LOG(ERR, "No VF.");
891 PMD_DRV_LOG(ERR, "on is should be 0 or 1.");
895 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
896 hw = I40E_PF_TO_HW(pf);
899 * return -ENODEV if SRIOV not enabled, VF number not configured
900 * or no queue assigned.
902 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
903 pf->vf_nb_qps == 0) {
904 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
908 for (vf_idx = 0; vf_idx < pf->vf_num && ret == I40E_SUCCESS; vf_idx++) {
909 if (vf_mask & ((uint64_t)(1ULL << vf_idx))) {
910 vsi = pf->vfs[vf_idx].vsi;
912 if (!vsi->vlan_filter_on) {
913 vsi->vlan_filter_on = true;
914 i40e_aq_set_vsi_vlan_promisc(hw,
918 if (!vsi->vlan_anti_spoof_on)
919 i40e_add_rm_all_vlan_filter(
922 ret = i40e_vsi_add_vlan(vsi, vlan_id);
924 ret = i40e_vsi_delete_vlan(vsi, vlan_id);
926 if (!i40e_vlan_filter_count(vsi)) {
927 vsi->vlan_filter_on = false;
928 i40e_aq_set_vsi_vlan_promisc(hw,
937 if (ret != I40E_SUCCESS) {
939 PMD_DRV_LOG(ERR, "Failed to set VF VLAN filter, on = %d", on);
946 rte_pmd_i40e_get_vf_stats(uint16_t port,
948 struct rte_eth_stats *stats)
950 struct rte_eth_dev *dev;
952 struct i40e_vsi *vsi;
954 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
956 dev = &rte_eth_devices[port];
958 if (!is_i40e_supported(dev))
961 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
963 if (vf_id >= pf->vf_num || !pf->vfs) {
964 PMD_DRV_LOG(ERR, "Invalid VF ID.");
968 vsi = pf->vfs[vf_id].vsi;
970 PMD_DRV_LOG(ERR, "Invalid VSI.");
974 i40e_update_vsi_stats(vsi);
976 stats->ipackets = vsi->eth_stats.rx_unicast +
977 vsi->eth_stats.rx_multicast +
978 vsi->eth_stats.rx_broadcast;
979 stats->opackets = vsi->eth_stats.tx_unicast +
980 vsi->eth_stats.tx_multicast +
981 vsi->eth_stats.tx_broadcast;
982 stats->ibytes = vsi->eth_stats.rx_bytes;
983 stats->obytes = vsi->eth_stats.tx_bytes;
984 stats->ierrors = vsi->eth_stats.rx_discards;
985 stats->oerrors = vsi->eth_stats.tx_errors + vsi->eth_stats.tx_discards;
991 rte_pmd_i40e_reset_vf_stats(uint16_t port,
994 struct rte_eth_dev *dev;
996 struct i40e_vsi *vsi;
998 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1000 dev = &rte_eth_devices[port];
1002 if (!is_i40e_supported(dev))
1005 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1007 if (vf_id >= pf->vf_num || !pf->vfs) {
1008 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1012 vsi = pf->vfs[vf_id].vsi;
1014 PMD_DRV_LOG(ERR, "Invalid VSI.");
1018 vsi->offset_loaded = false;
1019 i40e_update_vsi_stats(vsi);
1025 rte_pmd_i40e_set_vf_max_bw(uint16_t port, uint16_t vf_id, uint32_t bw)
1027 struct rte_eth_dev *dev;
1029 struct i40e_vsi *vsi;
1034 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1036 dev = &rte_eth_devices[port];
1038 if (!is_i40e_supported(dev))
1041 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1043 if (vf_id >= pf->vf_num || !pf->vfs) {
1044 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1048 vsi = pf->vfs[vf_id].vsi;
1050 PMD_DRV_LOG(ERR, "Invalid VSI.");
1054 if (bw > I40E_QOS_BW_MAX) {
1055 PMD_DRV_LOG(ERR, "Bandwidth should not be larger than %dMbps.",
1060 if (bw % I40E_QOS_BW_GRANULARITY) {
1061 PMD_DRV_LOG(ERR, "Bandwidth should be the multiple of %dMbps.",
1062 I40E_QOS_BW_GRANULARITY);
1066 bw /= I40E_QOS_BW_GRANULARITY;
1068 hw = I40E_VSI_TO_HW(vsi);
1071 if (bw == vsi->bw_info.bw_limit) {
1073 "No change for VF max bandwidth. Nothing to do.");
1078 * VF bandwidth limitation and TC bandwidth limitation cannot be
1079 * enabled in parallel, quit if TC bandwidth limitation is enabled.
1081 * If bw is 0, means disable bandwidth limitation. Then no need to
1082 * check TC bandwidth limitation.
1085 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1086 if ((vsi->enabled_tc & BIT_ULL(i)) &&
1087 vsi->bw_info.bw_ets_credits[i])
1090 if (i != I40E_MAX_TRAFFIC_CLASS) {
1092 "TC max bandwidth has been set on this VF,"
1093 " please disable it first.");
1098 ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid, (uint16_t)bw, 0, NULL);
1101 "Failed to set VF %d bandwidth, err(%d).",
1106 /* Store the configuration. */
1107 vsi->bw_info.bw_limit = (uint16_t)bw;
1108 vsi->bw_info.bw_max = 0;
1114 rte_pmd_i40e_set_vf_tc_bw_alloc(uint16_t port, uint16_t vf_id,
1115 uint8_t tc_num, uint8_t *bw_weight)
1117 struct rte_eth_dev *dev;
1119 struct i40e_vsi *vsi;
1121 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw;
1125 bool b_change = false;
1127 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1129 dev = &rte_eth_devices[port];
1131 if (!is_i40e_supported(dev))
1134 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1136 if (vf_id >= pf->vf_num || !pf->vfs) {
1137 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1141 vsi = pf->vfs[vf_id].vsi;
1143 PMD_DRV_LOG(ERR, "Invalid VSI.");
1147 if (tc_num > I40E_MAX_TRAFFIC_CLASS) {
1148 PMD_DRV_LOG(ERR, "TCs should be no more than %d.",
1149 I40E_MAX_TRAFFIC_CLASS);
1154 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1155 if (vsi->enabled_tc & BIT_ULL(i))
1158 if (sum != tc_num) {
1160 "Weight should be set for all %d enabled TCs.",
1166 for (i = 0; i < tc_num; i++) {
1167 if (!bw_weight[i]) {
1169 "The weight should be 1 at least.");
1172 sum += bw_weight[i];
1176 "The summary of the TC weight should be 100.");
1181 * Create the configuration for all the TCs.
1183 memset(&tc_bw, 0, sizeof(tc_bw));
1184 tc_bw.tc_valid_bits = vsi->enabled_tc;
1186 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1187 if (vsi->enabled_tc & BIT_ULL(i)) {
1189 vsi->bw_info.bw_ets_share_credits[i])
1192 tc_bw.tc_bw_credits[i] = bw_weight[j];
1200 "No change for TC allocated bandwidth."
1205 hw = I40E_VSI_TO_HW(vsi);
1207 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw, NULL);
1210 "Failed to set VF %d TC bandwidth weight, err(%d).",
1215 /* Store the configuration. */
1217 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1218 if (vsi->enabled_tc & BIT_ULL(i)) {
1219 vsi->bw_info.bw_ets_share_credits[i] = bw_weight[j];
1228 rte_pmd_i40e_set_vf_tc_max_bw(uint16_t port, uint16_t vf_id,
1229 uint8_t tc_no, uint32_t bw)
1231 struct rte_eth_dev *dev;
1233 struct i40e_vsi *vsi;
1235 struct i40e_aqc_configure_vsi_ets_sla_bw_data tc_bw;
1239 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1241 dev = &rte_eth_devices[port];
1243 if (!is_i40e_supported(dev))
1246 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1248 if (vf_id >= pf->vf_num || !pf->vfs) {
1249 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1253 vsi = pf->vfs[vf_id].vsi;
1255 PMD_DRV_LOG(ERR, "Invalid VSI.");
1259 if (bw > I40E_QOS_BW_MAX) {
1260 PMD_DRV_LOG(ERR, "Bandwidth should not be larger than %dMbps.",
1265 if (bw % I40E_QOS_BW_GRANULARITY) {
1266 PMD_DRV_LOG(ERR, "Bandwidth should be the multiple of %dMbps.",
1267 I40E_QOS_BW_GRANULARITY);
1271 bw /= I40E_QOS_BW_GRANULARITY;
1273 if (tc_no >= I40E_MAX_TRAFFIC_CLASS) {
1274 PMD_DRV_LOG(ERR, "TC No. should be less than %d.",
1275 I40E_MAX_TRAFFIC_CLASS);
1279 hw = I40E_VSI_TO_HW(vsi);
1281 if (!(vsi->enabled_tc & BIT_ULL(tc_no))) {
1282 PMD_DRV_LOG(ERR, "VF %d TC %d isn't enabled.",
1288 if (bw == vsi->bw_info.bw_ets_credits[tc_no]) {
1290 "No change for TC max bandwidth. Nothing to do.");
1295 * VF bandwidth limitation and TC bandwidth limitation cannot be
1296 * enabled in parallel, disable VF bandwidth limitation if it's
1298 * If bw is 0, means disable bandwidth limitation. Then no need to
1299 * care about VF bandwidth limitation configuration.
1301 if (bw && vsi->bw_info.bw_limit) {
1302 ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid, 0, 0, NULL);
1305 "Failed to disable VF(%d)"
1306 " bandwidth limitation, err(%d).",
1312 "VF max bandwidth is disabled according"
1313 " to TC max bandwidth setting.");
1317 * Get all the TCs' info to create a whole picture.
1318 * Because the incremental change isn't permitted.
1320 memset(&tc_bw, 0, sizeof(tc_bw));
1321 tc_bw.tc_valid_bits = vsi->enabled_tc;
1322 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1323 if (vsi->enabled_tc & BIT_ULL(i)) {
1324 tc_bw.tc_bw_credits[i] =
1326 vsi->bw_info.bw_ets_credits[i]);
1329 tc_bw.tc_bw_credits[tc_no] = rte_cpu_to_le_16((uint16_t)bw);
1331 ret = i40e_aq_config_vsi_ets_sla_bw_limit(hw, vsi->seid, &tc_bw, NULL);
1334 "Failed to set VF %d TC %d max bandwidth, err(%d).",
1339 /* Store the configuration. */
1340 vsi->bw_info.bw_ets_credits[tc_no] = (uint16_t)bw;
1346 rte_pmd_i40e_set_tc_strict_prio(uint16_t port, uint8_t tc_map)
1348 struct rte_eth_dev *dev;
1350 struct i40e_vsi *vsi;
1351 struct i40e_veb *veb;
1353 struct i40e_aqc_configure_switching_comp_ets_data ets_data;
1357 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1359 dev = &rte_eth_devices[port];
1361 if (!is_i40e_supported(dev))
1364 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1368 PMD_DRV_LOG(ERR, "Invalid VSI.");
1374 PMD_DRV_LOG(ERR, "Invalid VEB.");
1378 if ((tc_map & veb->enabled_tc) != tc_map) {
1380 "TC bitmap isn't the subset of enabled TCs 0x%x.",
1385 if (tc_map == veb->strict_prio_tc) {
1386 PMD_DRV_LOG(INFO, "No change for TC bitmap. Nothing to do.");
1390 hw = I40E_VSI_TO_HW(vsi);
1392 /* Disable DCBx if it's the first time to set strict priority. */
1393 if (!veb->strict_prio_tc) {
1394 ret = i40e_aq_stop_lldp(hw, true, NULL);
1397 "Failed to disable DCBx as it's already"
1401 "DCBx is disabled according to strict"
1402 " priority setting.");
1405 memset(&ets_data, 0, sizeof(ets_data));
1406 ets_data.tc_valid_bits = veb->enabled_tc;
1407 ets_data.seepage = I40E_AQ_ETS_SEEPAGE_EN_MASK;
1408 ets_data.tc_strict_priority_flags = tc_map;
1409 /* Get all TCs' bandwidth. */
1410 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1411 if (veb->enabled_tc & BIT_ULL(i)) {
1412 /* For rubust, if bandwidth is 0, use 1 instead. */
1413 if (veb->bw_info.bw_ets_share_credits[i])
1414 ets_data.tc_bw_share_credits[i] =
1415 veb->bw_info.bw_ets_share_credits[i];
1417 ets_data.tc_bw_share_credits[i] =
1418 I40E_QOS_BW_WEIGHT_MIN;
1422 if (!veb->strict_prio_tc)
1423 ret = i40e_aq_config_switch_comp_ets(
1424 hw, veb->uplink_seid,
1425 &ets_data, i40e_aqc_opc_enable_switching_comp_ets,
1428 ret = i40e_aq_config_switch_comp_ets(
1429 hw, veb->uplink_seid,
1430 &ets_data, i40e_aqc_opc_modify_switching_comp_ets,
1433 ret = i40e_aq_config_switch_comp_ets(
1434 hw, veb->uplink_seid,
1435 &ets_data, i40e_aqc_opc_disable_switching_comp_ets,
1440 "Failed to set TCs' strict priority mode."
1445 veb->strict_prio_tc = tc_map;
1447 /* Enable DCBx again, if all the TCs' strict priority disabled. */
1449 ret = i40e_aq_start_lldp(hw, NULL);
1452 "Failed to enable DCBx, err(%d).", ret);
1457 "DCBx is enabled again according to strict"
1458 " priority setting.");
1464 #define I40E_PROFILE_INFO_SIZE sizeof(struct rte_pmd_i40e_profile_info)
1465 #define I40E_MAX_PROFILE_NUM 16
1468 i40e_generate_profile_info_sec(char *name, struct i40e_ddp_version *version,
1469 uint32_t track_id, uint8_t *profile_info_sec,
1472 struct i40e_profile_section_header *sec = NULL;
1473 struct i40e_profile_info *pinfo;
1475 sec = (struct i40e_profile_section_header *)profile_info_sec;
1477 sec->data_end = sizeof(struct i40e_profile_section_header) +
1478 sizeof(struct i40e_profile_info);
1479 sec->section.type = SECTION_TYPE_INFO;
1480 sec->section.offset = sizeof(struct i40e_profile_section_header);
1481 sec->section.size = sizeof(struct i40e_profile_info);
1482 pinfo = (struct i40e_profile_info *)(profile_info_sec +
1483 sec->section.offset);
1484 pinfo->track_id = track_id;
1485 memcpy(pinfo->name, name, I40E_DDP_NAME_SIZE);
1486 memcpy(&pinfo->version, version, sizeof(struct i40e_ddp_version));
1488 pinfo->op = I40E_DDP_ADD_TRACKID;
1490 pinfo->op = I40E_DDP_REMOVE_TRACKID;
1493 static enum i40e_status_code
1494 i40e_add_rm_profile_info(struct i40e_hw *hw, uint8_t *profile_info_sec)
1496 enum i40e_status_code status = I40E_SUCCESS;
1497 struct i40e_profile_section_header *sec;
1499 uint32_t offset = 0;
1502 sec = (struct i40e_profile_section_header *)profile_info_sec;
1503 track_id = ((struct i40e_profile_info *)(profile_info_sec +
1504 sec->section.offset))->track_id;
1506 status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
1507 track_id, &offset, &info, NULL);
1509 PMD_DRV_LOG(ERR, "Failed to add/remove profile info: "
1510 "offset %d, info %d",
1516 /* Check if the profile info exists */
1518 i40e_check_profile_info(uint16_t port, uint8_t *profile_info_sec)
1520 struct rte_eth_dev *dev = &rte_eth_devices[port];
1521 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1523 struct rte_pmd_i40e_profile_list *p_list;
1524 struct rte_pmd_i40e_profile_info *pinfo, *p;
1528 buff = rte_zmalloc("pinfo_list",
1529 (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4),
1532 PMD_DRV_LOG(ERR, "failed to allocate memory");
1536 ret = i40e_aq_get_ddp_list(
1538 (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4),
1541 PMD_DRV_LOG(ERR, "Failed to get profile info list.");
1545 p_list = (struct rte_pmd_i40e_profile_list *)buff;
1546 pinfo = (struct rte_pmd_i40e_profile_info *)(profile_info_sec +
1547 sizeof(struct i40e_profile_section_header));
1548 for (i = 0; i < p_list->p_count; i++) {
1549 p = &p_list->p_info[i];
1550 if (pinfo->track_id == p->track_id) {
1551 PMD_DRV_LOG(INFO, "Profile exists.");
1562 rte_pmd_i40e_process_ddp_package(uint16_t port, uint8_t *buff,
1564 enum rte_pmd_i40e_package_op op)
1566 struct rte_eth_dev *dev;
1568 struct i40e_package_header *pkg_hdr;
1569 struct i40e_generic_seg_header *profile_seg_hdr;
1570 struct i40e_generic_seg_header *metadata_seg_hdr;
1572 uint8_t *profile_info_sec;
1574 enum i40e_status_code status = I40E_SUCCESS;
1576 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
1577 op != RTE_PMD_I40E_PKG_OP_WR_ONLY &&
1578 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
1579 PMD_DRV_LOG(ERR, "Operation not supported.");
1583 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1585 dev = &rte_eth_devices[port];
1587 if (!is_i40e_supported(dev))
1590 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1592 if (size < (sizeof(struct i40e_package_header) +
1593 sizeof(struct i40e_metadata_segment) +
1594 sizeof(uint32_t) * 2)) {
1595 PMD_DRV_LOG(ERR, "Buff is invalid.");
1599 pkg_hdr = (struct i40e_package_header *)buff;
1602 PMD_DRV_LOG(ERR, "Failed to fill the package structure");
1606 if (pkg_hdr->segment_count < 2) {
1607 PMD_DRV_LOG(ERR, "Segment_count should be 2 at least.");
1611 i40e_update_customized_info(dev, buff, size);
1613 /* Find metadata segment */
1614 metadata_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_METADATA,
1616 if (!metadata_seg_hdr) {
1617 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1620 track_id = ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1621 if (track_id == I40E_DDP_TRACKID_INVALID) {
1622 PMD_DRV_LOG(ERR, "Invalid track_id");
1626 /* Find profile segment */
1627 profile_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_I40E,
1629 if (!profile_seg_hdr) {
1630 PMD_DRV_LOG(ERR, "Failed to find profile segment header");
1634 profile_info_sec = rte_zmalloc(
1635 "i40e_profile_info",
1636 sizeof(struct i40e_profile_section_header) +
1637 sizeof(struct i40e_profile_info),
1639 if (!profile_info_sec) {
1640 PMD_DRV_LOG(ERR, "Failed to allocate memory");
1644 /* Check if the profile already loaded */
1645 i40e_generate_profile_info_sec(
1646 ((struct i40e_profile_segment *)profile_seg_hdr)->name,
1647 &((struct i40e_profile_segment *)profile_seg_hdr)->version,
1648 track_id, profile_info_sec,
1649 op == RTE_PMD_I40E_PKG_OP_WR_ADD);
1650 is_exist = i40e_check_profile_info(port, profile_info_sec);
1652 PMD_DRV_LOG(ERR, "Failed to check profile.");
1653 rte_free(profile_info_sec);
1657 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
1659 PMD_DRV_LOG(ERR, "Profile already exists.");
1660 rte_free(profile_info_sec);
1663 } else if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
1665 PMD_DRV_LOG(ERR, "Profile does not exist.");
1666 rte_free(profile_info_sec);
1671 if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
1672 status = i40e_rollback_profile(
1674 (struct i40e_profile_segment *)profile_seg_hdr,
1677 PMD_DRV_LOG(ERR, "Failed to write profile for delete.");
1678 rte_free(profile_info_sec);
1682 status = i40e_write_profile(
1684 (struct i40e_profile_segment *)profile_seg_hdr,
1687 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
1688 PMD_DRV_LOG(ERR, "Failed to write profile for add.");
1690 PMD_DRV_LOG(ERR, "Failed to write profile.");
1691 rte_free(profile_info_sec);
1696 if (track_id && (op != RTE_PMD_I40E_PKG_OP_WR_ONLY)) {
1697 /* Modify loaded profiles info list */
1698 status = i40e_add_rm_profile_info(hw, profile_info_sec);
1700 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
1701 PMD_DRV_LOG(ERR, "Failed to add profile to info list.");
1703 PMD_DRV_LOG(ERR, "Failed to delete profile from info list.");
1707 rte_free(profile_info_sec);
1711 /* Get number of tvl records in the section */
1713 i40e_get_tlv_section_size(struct i40e_profile_section_header *sec)
1715 unsigned int i, nb_rec, nb_tlv = 0;
1716 struct i40e_profile_tlv_section_record *tlv;
1721 /* get number of records in the section */
1722 nb_rec = sec->section.size /
1723 sizeof(struct i40e_profile_tlv_section_record);
1724 for (i = 0; i < nb_rec; ) {
1725 tlv = (struct i40e_profile_tlv_section_record *)&sec[1 + i];
1732 int rte_pmd_i40e_get_ddp_info(uint8_t *pkg_buff, uint32_t pkg_size,
1733 uint8_t *info_buff, uint32_t info_size,
1734 enum rte_pmd_i40e_package_info type)
1737 struct i40e_package_header *pkg_hdr;
1738 struct i40e_generic_seg_header *i40e_seg_hdr;
1739 struct i40e_generic_seg_header *note_seg_hdr;
1740 struct i40e_generic_seg_header *metadata_seg_hdr;
1743 PMD_DRV_LOG(ERR, "Output info buff is invalid.");
1747 if (!pkg_buff || pkg_size < (sizeof(struct i40e_package_header) +
1748 sizeof(struct i40e_metadata_segment) +
1749 sizeof(uint32_t) * 2)) {
1750 PMD_DRV_LOG(ERR, "Package buff is invalid.");
1754 pkg_hdr = (struct i40e_package_header *)pkg_buff;
1755 if (pkg_hdr->segment_count < 2) {
1756 PMD_DRV_LOG(ERR, "Segment_count should be 2 at least.");
1760 /* Find metadata segment */
1761 metadata_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_METADATA,
1764 /* Find global notes segment */
1765 note_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_NOTES,
1768 /* Find i40e profile segment */
1769 i40e_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_I40E, pkg_hdr);
1771 /* get global header info */
1772 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER) {
1773 struct rte_pmd_i40e_profile_info *info =
1774 (struct rte_pmd_i40e_profile_info *)info_buff;
1776 if (info_size < sizeof(struct rte_pmd_i40e_profile_info)) {
1777 PMD_DRV_LOG(ERR, "Output info buff size is invalid.");
1781 if (!metadata_seg_hdr) {
1782 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1786 memset(info, 0, sizeof(struct rte_pmd_i40e_profile_info));
1787 info->owner = RTE_PMD_I40E_DDP_OWNER_UNKNOWN;
1789 ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1792 ((struct i40e_metadata_segment *)metadata_seg_hdr)->name,
1793 I40E_DDP_NAME_SIZE);
1794 memcpy(&info->version,
1795 &((struct i40e_metadata_segment *)metadata_seg_hdr)->version,
1796 sizeof(struct i40e_ddp_version));
1797 return I40E_SUCCESS;
1800 /* get global note size */
1801 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE) {
1802 if (info_size < sizeof(uint32_t)) {
1803 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1806 if (note_seg_hdr == NULL)
1809 ret_size = note_seg_hdr->size;
1810 *(uint32_t *)info_buff = ret_size;
1811 return I40E_SUCCESS;
1814 /* get global note */
1815 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES) {
1816 if (note_seg_hdr == NULL)
1818 if (info_size < note_seg_hdr->size) {
1819 PMD_DRV_LOG(ERR, "Information buffer size is too small");
1822 memcpy(info_buff, ¬e_seg_hdr[1], note_seg_hdr->size);
1823 return I40E_SUCCESS;
1826 /* get i40e segment header info */
1827 if (type == RTE_PMD_I40E_PKG_INFO_HEADER) {
1828 struct rte_pmd_i40e_profile_info *info =
1829 (struct rte_pmd_i40e_profile_info *)info_buff;
1831 if (info_size < sizeof(struct rte_pmd_i40e_profile_info)) {
1832 PMD_DRV_LOG(ERR, "Output info buff size is invalid.");
1836 if (!metadata_seg_hdr) {
1837 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1841 if (!i40e_seg_hdr) {
1842 PMD_DRV_LOG(ERR, "Failed to find i40e segment header");
1846 memset(info, 0, sizeof(struct rte_pmd_i40e_profile_info));
1847 info->owner = RTE_PMD_I40E_DDP_OWNER_UNKNOWN;
1849 ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1852 ((struct i40e_profile_segment *)i40e_seg_hdr)->name,
1853 I40E_DDP_NAME_SIZE);
1854 memcpy(&info->version,
1855 &((struct i40e_profile_segment *)i40e_seg_hdr)->version,
1856 sizeof(struct i40e_ddp_version));
1857 return I40E_SUCCESS;
1860 /* get number of devices */
1861 if (type == RTE_PMD_I40E_PKG_INFO_DEVID_NUM) {
1862 if (info_size < sizeof(uint32_t)) {
1863 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1866 *(uint32_t *)info_buff =
1867 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table_count;
1868 return I40E_SUCCESS;
1871 /* get list of devices */
1872 if (type == RTE_PMD_I40E_PKG_INFO_DEVID_LIST) {
1875 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table_count;
1876 if (info_size < sizeof(struct rte_pmd_i40e_ddp_device_id) * dev_num) {
1877 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1881 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table,
1882 sizeof(struct rte_pmd_i40e_ddp_device_id) * dev_num);
1883 return I40E_SUCCESS;
1886 /* get number of protocols */
1887 if (type == RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM) {
1888 struct i40e_profile_section_header *proto;
1890 if (info_size < sizeof(uint32_t)) {
1891 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1894 proto = i40e_find_section_in_profile(SECTION_TYPE_PROTO,
1895 (struct i40e_profile_segment *)i40e_seg_hdr);
1896 *(uint32_t *)info_buff = i40e_get_tlv_section_size(proto);
1897 return I40E_SUCCESS;
1900 /* get list of protocols */
1901 if (type == RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST) {
1902 uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
1903 struct rte_pmd_i40e_proto_info *pinfo;
1904 struct i40e_profile_section_header *proto;
1905 struct i40e_profile_tlv_section_record *tlv;
1907 pinfo = (struct rte_pmd_i40e_proto_info *)info_buff;
1908 nb_proto_info = info_size /
1909 sizeof(struct rte_pmd_i40e_proto_info);
1910 for (i = 0; i < nb_proto_info; i++) {
1911 pinfo[i].proto_id = RTE_PMD_I40E_PROTO_UNUSED;
1912 memset(pinfo[i].name, 0, RTE_PMD_I40E_DDP_NAME_SIZE);
1914 proto = i40e_find_section_in_profile(SECTION_TYPE_PROTO,
1915 (struct i40e_profile_segment *)i40e_seg_hdr);
1916 nb_tlv = i40e_get_tlv_section_size(proto);
1918 return I40E_SUCCESS;
1919 if (nb_proto_info < nb_tlv) {
1920 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1923 /* get number of records in the section */
1924 nb_rec = proto->section.size /
1925 sizeof(struct i40e_profile_tlv_section_record);
1926 tlv = (struct i40e_profile_tlv_section_record *)&proto[1];
1927 for (i = j = 0; i < nb_rec; j++) {
1928 pinfo[j].proto_id = tlv->data[0];
1929 strncpy(pinfo[j].name, (const char *)&tlv->data[1],
1930 I40E_DDP_NAME_SIZE);
1932 tlv = &tlv[tlv->len];
1934 return I40E_SUCCESS;
1937 /* get number of packet classification types */
1938 if (type == RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM) {
1939 struct i40e_profile_section_header *pctype;
1941 if (info_size < sizeof(uint32_t)) {
1942 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1945 pctype = i40e_find_section_in_profile(SECTION_TYPE_PCTYPE,
1946 (struct i40e_profile_segment *)i40e_seg_hdr);
1947 *(uint32_t *)info_buff = i40e_get_tlv_section_size(pctype);
1948 return I40E_SUCCESS;
1951 /* get list of packet classification types */
1952 if (type == RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST) {
1953 uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
1954 struct rte_pmd_i40e_ptype_info *pinfo;
1955 struct i40e_profile_section_header *pctype;
1956 struct i40e_profile_tlv_section_record *tlv;
1958 pinfo = (struct rte_pmd_i40e_ptype_info *)info_buff;
1959 nb_proto_info = info_size /
1960 sizeof(struct rte_pmd_i40e_ptype_info);
1961 for (i = 0; i < nb_proto_info; i++)
1962 memset(&pinfo[i], RTE_PMD_I40E_PROTO_UNUSED,
1963 sizeof(struct rte_pmd_i40e_ptype_info));
1964 pctype = i40e_find_section_in_profile(SECTION_TYPE_PCTYPE,
1965 (struct i40e_profile_segment *)i40e_seg_hdr);
1966 nb_tlv = i40e_get_tlv_section_size(pctype);
1968 return I40E_SUCCESS;
1969 if (nb_proto_info < nb_tlv) {
1970 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1974 /* get number of records in the section */
1975 nb_rec = pctype->section.size /
1976 sizeof(struct i40e_profile_tlv_section_record);
1977 tlv = (struct i40e_profile_tlv_section_record *)&pctype[1];
1978 for (i = j = 0; i < nb_rec; j++) {
1979 memcpy(&pinfo[j], tlv->data,
1980 sizeof(struct rte_pmd_i40e_ptype_info));
1982 tlv = &tlv[tlv->len];
1984 return I40E_SUCCESS;
1987 /* get number of packet types */
1988 if (type == RTE_PMD_I40E_PKG_INFO_PTYPE_NUM) {
1989 struct i40e_profile_section_header *ptype;
1991 if (info_size < sizeof(uint32_t)) {
1992 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1995 ptype = i40e_find_section_in_profile(SECTION_TYPE_PTYPE,
1996 (struct i40e_profile_segment *)i40e_seg_hdr);
1997 *(uint32_t *)info_buff = i40e_get_tlv_section_size(ptype);
1998 return I40E_SUCCESS;
2001 /* get list of packet types */
2002 if (type == RTE_PMD_I40E_PKG_INFO_PTYPE_LIST) {
2003 uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
2004 struct rte_pmd_i40e_ptype_info *pinfo;
2005 struct i40e_profile_section_header *ptype;
2006 struct i40e_profile_tlv_section_record *tlv;
2008 pinfo = (struct rte_pmd_i40e_ptype_info *)info_buff;
2009 nb_proto_info = info_size /
2010 sizeof(struct rte_pmd_i40e_ptype_info);
2011 for (i = 0; i < nb_proto_info; i++)
2012 memset(&pinfo[i], RTE_PMD_I40E_PROTO_UNUSED,
2013 sizeof(struct rte_pmd_i40e_ptype_info));
2014 ptype = i40e_find_section_in_profile(SECTION_TYPE_PTYPE,
2015 (struct i40e_profile_segment *)i40e_seg_hdr);
2016 nb_tlv = i40e_get_tlv_section_size(ptype);
2018 return I40E_SUCCESS;
2019 if (nb_proto_info < nb_tlv) {
2020 PMD_DRV_LOG(ERR, "Invalid information buffer size");
2023 /* get number of records in the section */
2024 nb_rec = ptype->section.size /
2025 sizeof(struct i40e_profile_tlv_section_record);
2026 for (i = j = 0; i < nb_rec; j++) {
2027 tlv = (struct i40e_profile_tlv_section_record *)
2029 memcpy(&pinfo[j], tlv->data,
2030 sizeof(struct rte_pmd_i40e_ptype_info));
2033 return I40E_SUCCESS;
2036 PMD_DRV_LOG(ERR, "Info type %u is invalid.", type);
2041 rte_pmd_i40e_get_ddp_list(uint16_t port, uint8_t *buff, uint32_t size)
2043 struct rte_eth_dev *dev;
2045 enum i40e_status_code status = I40E_SUCCESS;
2047 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2049 dev = &rte_eth_devices[port];
2051 if (!is_i40e_supported(dev))
2054 if (size < (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4))
2057 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2059 status = i40e_aq_get_ddp_list(hw, (void *)buff,
2065 static int check_invalid_pkt_type(uint32_t pkt_type)
2067 uint32_t l2, l3, l4, tnl, il2, il3, il4;
2069 l2 = pkt_type & RTE_PTYPE_L2_MASK;
2070 l3 = pkt_type & RTE_PTYPE_L3_MASK;
2071 l4 = pkt_type & RTE_PTYPE_L4_MASK;
2072 tnl = pkt_type & RTE_PTYPE_TUNNEL_MASK;
2073 il2 = pkt_type & RTE_PTYPE_INNER_L2_MASK;
2074 il3 = pkt_type & RTE_PTYPE_INNER_L3_MASK;
2075 il4 = pkt_type & RTE_PTYPE_INNER_L4_MASK;
2078 l2 != RTE_PTYPE_L2_ETHER &&
2079 l2 != RTE_PTYPE_L2_ETHER_TIMESYNC &&
2080 l2 != RTE_PTYPE_L2_ETHER_ARP &&
2081 l2 != RTE_PTYPE_L2_ETHER_LLDP &&
2082 l2 != RTE_PTYPE_L2_ETHER_NSH &&
2083 l2 != RTE_PTYPE_L2_ETHER_VLAN &&
2084 l2 != RTE_PTYPE_L2_ETHER_QINQ)
2088 l3 != RTE_PTYPE_L3_IPV4 &&
2089 l3 != RTE_PTYPE_L3_IPV4_EXT &&
2090 l3 != RTE_PTYPE_L3_IPV6 &&
2091 l3 != RTE_PTYPE_L3_IPV4_EXT_UNKNOWN &&
2092 l3 != RTE_PTYPE_L3_IPV6_EXT &&
2093 l3 != RTE_PTYPE_L3_IPV6_EXT_UNKNOWN)
2097 l4 != RTE_PTYPE_L4_TCP &&
2098 l4 != RTE_PTYPE_L4_UDP &&
2099 l4 != RTE_PTYPE_L4_FRAG &&
2100 l4 != RTE_PTYPE_L4_SCTP &&
2101 l4 != RTE_PTYPE_L4_ICMP &&
2102 l4 != RTE_PTYPE_L4_NONFRAG)
2106 tnl != RTE_PTYPE_TUNNEL_IP &&
2107 tnl != RTE_PTYPE_TUNNEL_GRENAT &&
2108 tnl != RTE_PTYPE_TUNNEL_VXLAN &&
2109 tnl != RTE_PTYPE_TUNNEL_NVGRE &&
2110 tnl != RTE_PTYPE_TUNNEL_GENEVE &&
2111 tnl != RTE_PTYPE_TUNNEL_GRENAT &&
2112 tnl != RTE_PTYPE_TUNNEL_GTPC &&
2113 tnl != RTE_PTYPE_TUNNEL_GTPU)
2117 il2 != RTE_PTYPE_INNER_L2_ETHER &&
2118 il2 != RTE_PTYPE_INNER_L2_ETHER_VLAN &&
2119 il2 != RTE_PTYPE_INNER_L2_ETHER_QINQ)
2123 il3 != RTE_PTYPE_INNER_L3_IPV4 &&
2124 il3 != RTE_PTYPE_INNER_L3_IPV4_EXT &&
2125 il3 != RTE_PTYPE_INNER_L3_IPV6 &&
2126 il3 != RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN &&
2127 il3 != RTE_PTYPE_INNER_L3_IPV6_EXT &&
2128 il3 != RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN)
2132 il4 != RTE_PTYPE_INNER_L4_TCP &&
2133 il4 != RTE_PTYPE_INNER_L4_UDP &&
2134 il4 != RTE_PTYPE_INNER_L4_FRAG &&
2135 il4 != RTE_PTYPE_INNER_L4_SCTP &&
2136 il4 != RTE_PTYPE_INNER_L4_ICMP &&
2137 il4 != RTE_PTYPE_INNER_L4_NONFRAG)
2143 static int check_invalid_ptype_mapping(
2144 struct rte_pmd_i40e_ptype_mapping *mapping_table,
2149 for (i = 0; i < count; i++) {
2150 uint16_t ptype = mapping_table[i].hw_ptype;
2151 uint32_t pkt_type = mapping_table[i].sw_ptype;
2153 if (ptype >= I40E_MAX_PKT_TYPE)
2156 if (pkt_type == RTE_PTYPE_UNKNOWN)
2159 if (pkt_type & RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK)
2162 if (check_invalid_pkt_type(pkt_type))
2170 rte_pmd_i40e_ptype_mapping_update(
2172 struct rte_pmd_i40e_ptype_mapping *mapping_items,
2176 struct rte_eth_dev *dev;
2177 struct i40e_adapter *ad;
2180 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2182 dev = &rte_eth_devices[port];
2184 if (!is_i40e_supported(dev))
2187 if (count > I40E_MAX_PKT_TYPE)
2190 if (check_invalid_ptype_mapping(mapping_items, count))
2193 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2196 for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
2197 ad->ptype_tbl[i] = RTE_PTYPE_UNKNOWN;
2200 for (i = 0; i < count; i++)
2201 ad->ptype_tbl[mapping_items[i].hw_ptype]
2202 = mapping_items[i].sw_ptype;
2207 int rte_pmd_i40e_ptype_mapping_reset(uint16_t port)
2209 struct rte_eth_dev *dev;
2211 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2213 dev = &rte_eth_devices[port];
2215 if (!is_i40e_supported(dev))
2218 i40e_set_default_ptype_table(dev);
2223 int rte_pmd_i40e_ptype_mapping_get(
2225 struct rte_pmd_i40e_ptype_mapping *mapping_items,
2230 struct rte_eth_dev *dev;
2231 struct i40e_adapter *ad;
2235 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2237 dev = &rte_eth_devices[port];
2239 if (!is_i40e_supported(dev))
2242 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2244 for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
2247 if (valid_only && ad->ptype_tbl[i] == RTE_PTYPE_UNKNOWN)
2249 mapping_items[n].hw_ptype = i;
2250 mapping_items[n].sw_ptype = ad->ptype_tbl[i];
2258 int rte_pmd_i40e_ptype_mapping_replace(uint16_t port,
2263 struct rte_eth_dev *dev;
2264 struct i40e_adapter *ad;
2267 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2269 dev = &rte_eth_devices[port];
2271 if (!is_i40e_supported(dev))
2274 if (!mask && check_invalid_pkt_type(target))
2277 if (check_invalid_pkt_type(pkt_type))
2280 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2282 for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
2284 if ((target | ad->ptype_tbl[i]) == target &&
2285 (target & ad->ptype_tbl[i]))
2286 ad->ptype_tbl[i] = pkt_type;
2288 if (ad->ptype_tbl[i] == target)
2289 ad->ptype_tbl[i] = pkt_type;
2297 rte_pmd_i40e_add_vf_mac_addr(uint8_t port, uint16_t vf_id,
2298 struct ether_addr *mac_addr)
2300 struct rte_eth_dev *dev;
2301 struct i40e_pf_vf *vf;
2302 struct i40e_vsi *vsi;
2304 struct i40e_mac_filter_info mac_filter;
2307 if (i40e_validate_mac_addr((u8 *)mac_addr) != I40E_SUCCESS)
2310 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2312 dev = &rte_eth_devices[port];
2314 if (!is_i40e_supported(dev))
2317 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2319 if (vf_id >= pf->vf_num || !pf->vfs)
2322 vf = &pf->vfs[vf_id];
2325 PMD_DRV_LOG(ERR, "Invalid VSI.");
2329 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
2330 ether_addr_copy(mac_addr, &mac_filter.mac_addr);
2331 ret = i40e_vsi_add_mac(vsi, &mac_filter);
2332 if (ret != I40E_SUCCESS) {
2333 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
2340 int rte_pmd_i40e_flow_type_mapping_reset(uint8_t port)
2342 struct rte_eth_dev *dev;
2344 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2346 dev = &rte_eth_devices[port];
2348 if (!is_i40e_supported(dev))
2351 i40e_set_default_pctype_table(dev);
2356 int rte_pmd_i40e_flow_type_mapping_get(
2358 struct rte_pmd_i40e_flow_type_mapping *mapping_items)
2360 struct rte_eth_dev *dev;
2361 struct i40e_adapter *ad;
2364 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2366 dev = &rte_eth_devices[port];
2368 if (!is_i40e_supported(dev))
2371 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2373 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
2374 mapping_items[i].flow_type = i;
2375 mapping_items[i].pctype = ad->pctypes_tbl[i];
2382 rte_pmd_i40e_flow_type_mapping_update(
2384 struct rte_pmd_i40e_flow_type_mapping *mapping_items,
2388 struct rte_eth_dev *dev;
2389 struct i40e_adapter *ad;
2392 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2394 dev = &rte_eth_devices[port];
2396 if (!is_i40e_supported(dev))
2399 if (count > I40E_FLOW_TYPE_MAX)
2402 for (i = 0; i < count; i++)
2403 if (mapping_items[i].flow_type >= I40E_FLOW_TYPE_MAX ||
2404 mapping_items[i].flow_type == RTE_ETH_FLOW_UNKNOWN ||
2405 (mapping_items[i].pctype &
2406 (1ULL << I40E_FILTER_PCTYPE_INVALID)))
2409 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2412 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
2413 ad->pctypes_tbl[i] = 0ULL;
2414 ad->flow_types_mask = 0ULL;
2417 for (i = 0; i < count; i++) {
2418 ad->pctypes_tbl[mapping_items[i].flow_type] =
2419 mapping_items[i].pctype;
2420 if (mapping_items[i].pctype)
2421 ad->flow_types_mask |=
2422 (1ULL << mapping_items[i].flow_type);
2424 ad->flow_types_mask &=
2425 ~(1ULL << mapping_items[i].flow_type);
2428 for (i = 0, ad->pctypes_mask = 0ULL; i < I40E_FLOW_TYPE_MAX; i++)
2429 ad->pctypes_mask |= ad->pctypes_tbl[i];
2435 rte_pmd_i40e_query_vfid_by_mac(uint16_t port, const struct ether_addr *vf_mac)
2437 struct rte_eth_dev *dev;
2438 struct ether_addr *mac;
2441 struct i40e_pf_vf *vf;
2444 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2445 dev = &rte_eth_devices[port];
2447 if (!is_i40e_supported(dev))
2450 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2451 vf_num = pf->vf_num;
2453 for (vf_id = 0; vf_id < vf_num; vf_id++) {
2454 vf = &pf->vfs[vf_id];
2455 mac = &vf->mac_addr;
2457 if (is_same_ether_addr(mac, vf_mac))