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(uint8_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(uint8_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 (void)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(uint8_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 (void)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 (void)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 (void)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 (void)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(uint8_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(uint8_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(uint8_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(uint8_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 i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
599 /* Set vlan strip on/off for specific VF from host */
601 rte_pmd_i40e_set_vf_vlan_stripq(uint8_t port, uint16_t vf_id, uint8_t on)
603 struct rte_eth_dev *dev;
605 struct i40e_vsi *vsi;
608 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
610 dev = &rte_eth_devices[port];
612 if (!is_i40e_supported(dev))
615 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
617 if (vf_id >= pf->vf_num || !pf->vfs) {
618 PMD_DRV_LOG(ERR, "Invalid argument.");
622 vsi = pf->vfs[vf_id].vsi;
627 ret = i40e_vsi_config_vlan_stripping(vsi, !!on);
628 if (ret != I40E_SUCCESS) {
630 PMD_DRV_LOG(ERR, "Failed to set VLAN stripping!");
636 int rte_pmd_i40e_set_vf_vlan_insert(uint8_t port, uint16_t vf_id,
639 struct rte_eth_dev *dev;
642 struct i40e_vsi *vsi;
643 struct i40e_vsi_context ctxt;
646 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
648 if (vlan_id > ETHER_MAX_VLAN_ID) {
649 PMD_DRV_LOG(ERR, "Invalid VLAN ID.");
653 dev = &rte_eth_devices[port];
655 if (!is_i40e_supported(dev))
658 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
659 hw = I40E_PF_TO_HW(pf);
662 * return -ENODEV if SRIOV not enabled, VF number not configured
663 * or no queue assigned.
665 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
669 if (vf_id >= pf->vf_num || !pf->vfs) {
670 PMD_DRV_LOG(ERR, "Invalid VF ID.");
674 vsi = pf->vfs[vf_id].vsi;
676 PMD_DRV_LOG(ERR, "Invalid VSI.");
680 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
681 vsi->info.pvid = vlan_id;
683 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID;
685 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_INSERT_PVID;
687 memset(&ctxt, 0, sizeof(ctxt));
688 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
689 ctxt.seid = vsi->seid;
691 hw = I40E_VSI_TO_HW(vsi);
692 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
693 if (ret != I40E_SUCCESS) {
695 PMD_DRV_LOG(ERR, "Failed to update VSI params");
701 int rte_pmd_i40e_set_vf_broadcast(uint8_t port, uint16_t vf_id,
704 struct rte_eth_dev *dev;
706 struct i40e_vsi *vsi;
708 struct i40e_mac_filter_info filter;
709 struct ether_addr broadcast = {
710 .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
713 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
716 PMD_DRV_LOG(ERR, "on should be 0 or 1.");
720 dev = &rte_eth_devices[port];
722 if (!is_i40e_supported(dev))
725 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
726 hw = I40E_PF_TO_HW(pf);
728 if (vf_id >= pf->vf_num || !pf->vfs) {
729 PMD_DRV_LOG(ERR, "Invalid VF ID.");
734 * return -ENODEV if SRIOV not enabled, VF number not configured
735 * or no queue assigned.
737 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
738 pf->vf_nb_qps == 0) {
739 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
743 vsi = pf->vfs[vf_id].vsi;
745 PMD_DRV_LOG(ERR, "Invalid VSI.");
750 (void)rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
751 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
752 ret = i40e_vsi_add_mac(vsi, &filter);
754 ret = i40e_vsi_delete_mac(vsi, &broadcast);
757 if (ret != I40E_SUCCESS && ret != I40E_ERR_PARAM) {
759 PMD_DRV_LOG(ERR, "Failed to set VSI broadcast");
767 int rte_pmd_i40e_set_vf_vlan_tag(uint8_t port, uint16_t vf_id, uint8_t on)
769 struct rte_eth_dev *dev;
772 struct i40e_vsi *vsi;
773 struct i40e_vsi_context ctxt;
776 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
779 PMD_DRV_LOG(ERR, "on should be 0 or 1.");
783 dev = &rte_eth_devices[port];
785 if (!is_i40e_supported(dev))
788 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
789 hw = I40E_PF_TO_HW(pf);
792 * return -ENODEV if SRIOV not enabled, VF number not configured
793 * or no queue assigned.
795 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
796 pf->vf_nb_qps == 0) {
797 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
801 if (vf_id >= pf->vf_num || !pf->vfs) {
802 PMD_DRV_LOG(ERR, "Invalid VF ID.");
806 vsi = pf->vfs[vf_id].vsi;
808 PMD_DRV_LOG(ERR, "Invalid VSI.");
812 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
814 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
815 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
817 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
818 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_MODE_TAGGED;
821 memset(&ctxt, 0, sizeof(ctxt));
822 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
823 ctxt.seid = vsi->seid;
825 hw = I40E_VSI_TO_HW(vsi);
826 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
827 if (ret != I40E_SUCCESS) {
829 PMD_DRV_LOG(ERR, "Failed to update VSI params");
836 i40e_vlan_filter_count(struct i40e_vsi *vsi)
842 for (j = 0; j < I40E_VFTA_SIZE; j++) {
846 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
847 if (!(vsi->vfta[j] & (1 << k)))
850 vlan_id = j * I40E_UINT32_BIT_SIZE + k;
861 int rte_pmd_i40e_set_vf_vlan_filter(uint8_t port, uint16_t vlan_id,
862 uint64_t vf_mask, uint8_t on)
864 struct rte_eth_dev *dev;
867 struct i40e_vsi *vsi;
869 int ret = I40E_SUCCESS;
871 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
873 dev = &rte_eth_devices[port];
875 if (!is_i40e_supported(dev))
878 if (vlan_id > ETHER_MAX_VLAN_ID || !vlan_id) {
879 PMD_DRV_LOG(ERR, "Invalid VLAN ID.");
884 PMD_DRV_LOG(ERR, "No VF.");
889 PMD_DRV_LOG(ERR, "on is should be 0 or 1.");
893 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
894 hw = I40E_PF_TO_HW(pf);
897 * return -ENODEV if SRIOV not enabled, VF number not configured
898 * or no queue assigned.
900 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
901 pf->vf_nb_qps == 0) {
902 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
906 for (vf_idx = 0; vf_idx < pf->vf_num && ret == I40E_SUCCESS; vf_idx++) {
907 if (vf_mask & ((uint64_t)(1ULL << vf_idx))) {
908 vsi = pf->vfs[vf_idx].vsi;
910 if (!vsi->vlan_filter_on) {
911 vsi->vlan_filter_on = true;
912 i40e_aq_set_vsi_vlan_promisc(hw,
916 if (!vsi->vlan_anti_spoof_on)
917 i40e_add_rm_all_vlan_filter(
920 ret = i40e_vsi_add_vlan(vsi, vlan_id);
922 ret = i40e_vsi_delete_vlan(vsi, vlan_id);
924 if (!i40e_vlan_filter_count(vsi)) {
925 vsi->vlan_filter_on = false;
926 i40e_aq_set_vsi_vlan_promisc(hw,
935 if (ret != I40E_SUCCESS) {
937 PMD_DRV_LOG(ERR, "Failed to set VF VLAN filter, on = %d", on);
944 rte_pmd_i40e_get_vf_stats(uint8_t port,
946 struct rte_eth_stats *stats)
948 struct rte_eth_dev *dev;
950 struct i40e_vsi *vsi;
952 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
954 dev = &rte_eth_devices[port];
956 if (!is_i40e_supported(dev))
959 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
961 if (vf_id >= pf->vf_num || !pf->vfs) {
962 PMD_DRV_LOG(ERR, "Invalid VF ID.");
966 vsi = pf->vfs[vf_id].vsi;
968 PMD_DRV_LOG(ERR, "Invalid VSI.");
972 i40e_update_vsi_stats(vsi);
974 stats->ipackets = vsi->eth_stats.rx_unicast +
975 vsi->eth_stats.rx_multicast +
976 vsi->eth_stats.rx_broadcast;
977 stats->opackets = vsi->eth_stats.tx_unicast +
978 vsi->eth_stats.tx_multicast +
979 vsi->eth_stats.tx_broadcast;
980 stats->ibytes = vsi->eth_stats.rx_bytes;
981 stats->obytes = vsi->eth_stats.tx_bytes;
982 stats->ierrors = vsi->eth_stats.rx_discards;
983 stats->oerrors = vsi->eth_stats.tx_errors + vsi->eth_stats.tx_discards;
989 rte_pmd_i40e_reset_vf_stats(uint8_t port,
992 struct rte_eth_dev *dev;
994 struct i40e_vsi *vsi;
996 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
998 dev = &rte_eth_devices[port];
1000 if (!is_i40e_supported(dev))
1003 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1005 if (vf_id >= pf->vf_num || !pf->vfs) {
1006 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1010 vsi = pf->vfs[vf_id].vsi;
1012 PMD_DRV_LOG(ERR, "Invalid VSI.");
1016 vsi->offset_loaded = false;
1017 i40e_update_vsi_stats(vsi);
1023 rte_pmd_i40e_set_vf_max_bw(uint8_t port, uint16_t vf_id, uint32_t bw)
1025 struct rte_eth_dev *dev;
1027 struct i40e_vsi *vsi;
1032 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1034 dev = &rte_eth_devices[port];
1036 if (!is_i40e_supported(dev))
1039 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1041 if (vf_id >= pf->vf_num || !pf->vfs) {
1042 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1046 vsi = pf->vfs[vf_id].vsi;
1048 PMD_DRV_LOG(ERR, "Invalid VSI.");
1052 if (bw > I40E_QOS_BW_MAX) {
1053 PMD_DRV_LOG(ERR, "Bandwidth should not be larger than %dMbps.",
1058 if (bw % I40E_QOS_BW_GRANULARITY) {
1059 PMD_DRV_LOG(ERR, "Bandwidth should be the multiple of %dMbps.",
1060 I40E_QOS_BW_GRANULARITY);
1064 bw /= I40E_QOS_BW_GRANULARITY;
1066 hw = I40E_VSI_TO_HW(vsi);
1069 if (bw == vsi->bw_info.bw_limit) {
1071 "No change for VF max bandwidth. Nothing to do.");
1076 * VF bandwidth limitation and TC bandwidth limitation cannot be
1077 * enabled in parallel, quit if TC bandwidth limitation is enabled.
1079 * If bw is 0, means disable bandwidth limitation. Then no need to
1080 * check TC bandwidth limitation.
1083 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1084 if ((vsi->enabled_tc & BIT_ULL(i)) &&
1085 vsi->bw_info.bw_ets_credits[i])
1088 if (i != I40E_MAX_TRAFFIC_CLASS) {
1090 "TC max bandwidth has been set on this VF,"
1091 " please disable it first.");
1096 ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid, (uint16_t)bw, 0, NULL);
1099 "Failed to set VF %d bandwidth, err(%d).",
1104 /* Store the configuration. */
1105 vsi->bw_info.bw_limit = (uint16_t)bw;
1106 vsi->bw_info.bw_max = 0;
1112 rte_pmd_i40e_set_vf_tc_bw_alloc(uint8_t port, uint16_t vf_id,
1113 uint8_t tc_num, uint8_t *bw_weight)
1115 struct rte_eth_dev *dev;
1117 struct i40e_vsi *vsi;
1119 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw;
1123 bool b_change = false;
1125 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1127 dev = &rte_eth_devices[port];
1129 if (!is_i40e_supported(dev))
1132 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1134 if (vf_id >= pf->vf_num || !pf->vfs) {
1135 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1139 vsi = pf->vfs[vf_id].vsi;
1141 PMD_DRV_LOG(ERR, "Invalid VSI.");
1145 if (tc_num > I40E_MAX_TRAFFIC_CLASS) {
1146 PMD_DRV_LOG(ERR, "TCs should be no more than %d.",
1147 I40E_MAX_TRAFFIC_CLASS);
1152 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1153 if (vsi->enabled_tc & BIT_ULL(i))
1156 if (sum != tc_num) {
1158 "Weight should be set for all %d enabled TCs.",
1164 for (i = 0; i < tc_num; i++) {
1165 if (!bw_weight[i]) {
1167 "The weight should be 1 at least.");
1170 sum += bw_weight[i];
1174 "The summary of the TC weight should be 100.");
1179 * Create the configuration for all the TCs.
1181 memset(&tc_bw, 0, sizeof(tc_bw));
1182 tc_bw.tc_valid_bits = vsi->enabled_tc;
1184 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1185 if (vsi->enabled_tc & BIT_ULL(i)) {
1187 vsi->bw_info.bw_ets_share_credits[i])
1190 tc_bw.tc_bw_credits[i] = bw_weight[j];
1198 "No change for TC allocated bandwidth."
1203 hw = I40E_VSI_TO_HW(vsi);
1205 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw, NULL);
1208 "Failed to set VF %d TC bandwidth weight, err(%d).",
1213 /* Store the configuration. */
1215 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1216 if (vsi->enabled_tc & BIT_ULL(i)) {
1217 vsi->bw_info.bw_ets_share_credits[i] = bw_weight[j];
1226 rte_pmd_i40e_set_vf_tc_max_bw(uint8_t port, uint16_t vf_id,
1227 uint8_t tc_no, uint32_t bw)
1229 struct rte_eth_dev *dev;
1231 struct i40e_vsi *vsi;
1233 struct i40e_aqc_configure_vsi_ets_sla_bw_data tc_bw;
1237 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1239 dev = &rte_eth_devices[port];
1241 if (!is_i40e_supported(dev))
1244 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1246 if (vf_id >= pf->vf_num || !pf->vfs) {
1247 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1251 vsi = pf->vfs[vf_id].vsi;
1253 PMD_DRV_LOG(ERR, "Invalid VSI.");
1257 if (bw > I40E_QOS_BW_MAX) {
1258 PMD_DRV_LOG(ERR, "Bandwidth should not be larger than %dMbps.",
1263 if (bw % I40E_QOS_BW_GRANULARITY) {
1264 PMD_DRV_LOG(ERR, "Bandwidth should be the multiple of %dMbps.",
1265 I40E_QOS_BW_GRANULARITY);
1269 bw /= I40E_QOS_BW_GRANULARITY;
1271 if (tc_no >= I40E_MAX_TRAFFIC_CLASS) {
1272 PMD_DRV_LOG(ERR, "TC No. should be less than %d.",
1273 I40E_MAX_TRAFFIC_CLASS);
1277 hw = I40E_VSI_TO_HW(vsi);
1279 if (!(vsi->enabled_tc & BIT_ULL(tc_no))) {
1280 PMD_DRV_LOG(ERR, "VF %d TC %d isn't enabled.",
1286 if (bw == vsi->bw_info.bw_ets_credits[tc_no]) {
1288 "No change for TC max bandwidth. Nothing to do.");
1293 * VF bandwidth limitation and TC bandwidth limitation cannot be
1294 * enabled in parallel, disable VF bandwidth limitation if it's
1296 * If bw is 0, means disable bandwidth limitation. Then no need to
1297 * care about VF bandwidth limitation configuration.
1299 if (bw && vsi->bw_info.bw_limit) {
1300 ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid, 0, 0, NULL);
1303 "Failed to disable VF(%d)"
1304 " bandwidth limitation, err(%d).",
1310 "VF max bandwidth is disabled according"
1311 " to TC max bandwidth setting.");
1315 * Get all the TCs' info to create a whole picture.
1316 * Because the incremental change isn't permitted.
1318 memset(&tc_bw, 0, sizeof(tc_bw));
1319 tc_bw.tc_valid_bits = vsi->enabled_tc;
1320 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1321 if (vsi->enabled_tc & BIT_ULL(i)) {
1322 tc_bw.tc_bw_credits[i] =
1324 vsi->bw_info.bw_ets_credits[i]);
1327 tc_bw.tc_bw_credits[tc_no] = rte_cpu_to_le_16((uint16_t)bw);
1329 ret = i40e_aq_config_vsi_ets_sla_bw_limit(hw, vsi->seid, &tc_bw, NULL);
1332 "Failed to set VF %d TC %d max bandwidth, err(%d).",
1337 /* Store the configuration. */
1338 vsi->bw_info.bw_ets_credits[tc_no] = (uint16_t)bw;
1344 rte_pmd_i40e_set_tc_strict_prio(uint8_t port, uint8_t tc_map)
1346 struct rte_eth_dev *dev;
1348 struct i40e_vsi *vsi;
1349 struct i40e_veb *veb;
1351 struct i40e_aqc_configure_switching_comp_ets_data ets_data;
1355 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1357 dev = &rte_eth_devices[port];
1359 if (!is_i40e_supported(dev))
1362 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1366 PMD_DRV_LOG(ERR, "Invalid VSI.");
1372 PMD_DRV_LOG(ERR, "Invalid VEB.");
1376 if ((tc_map & veb->enabled_tc) != tc_map) {
1378 "TC bitmap isn't the subset of enabled TCs 0x%x.",
1383 if (tc_map == veb->strict_prio_tc) {
1384 PMD_DRV_LOG(INFO, "No change for TC bitmap. Nothing to do.");
1388 hw = I40E_VSI_TO_HW(vsi);
1390 /* Disable DCBx if it's the first time to set strict priority. */
1391 if (!veb->strict_prio_tc) {
1392 ret = i40e_aq_stop_lldp(hw, true, NULL);
1395 "Failed to disable DCBx as it's already"
1399 "DCBx is disabled according to strict"
1400 " priority setting.");
1403 memset(&ets_data, 0, sizeof(ets_data));
1404 ets_data.tc_valid_bits = veb->enabled_tc;
1405 ets_data.seepage = I40E_AQ_ETS_SEEPAGE_EN_MASK;
1406 ets_data.tc_strict_priority_flags = tc_map;
1407 /* Get all TCs' bandwidth. */
1408 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1409 if (veb->enabled_tc & BIT_ULL(i)) {
1410 /* For rubust, if bandwidth is 0, use 1 instead. */
1411 if (veb->bw_info.bw_ets_share_credits[i])
1412 ets_data.tc_bw_share_credits[i] =
1413 veb->bw_info.bw_ets_share_credits[i];
1415 ets_data.tc_bw_share_credits[i] =
1416 I40E_QOS_BW_WEIGHT_MIN;
1420 if (!veb->strict_prio_tc)
1421 ret = i40e_aq_config_switch_comp_ets(
1422 hw, veb->uplink_seid,
1423 &ets_data, i40e_aqc_opc_enable_switching_comp_ets,
1426 ret = i40e_aq_config_switch_comp_ets(
1427 hw, veb->uplink_seid,
1428 &ets_data, i40e_aqc_opc_modify_switching_comp_ets,
1431 ret = i40e_aq_config_switch_comp_ets(
1432 hw, veb->uplink_seid,
1433 &ets_data, i40e_aqc_opc_disable_switching_comp_ets,
1438 "Failed to set TCs' strict priority mode."
1443 veb->strict_prio_tc = tc_map;
1445 /* Enable DCBx again, if all the TCs' strict priority disabled. */
1447 ret = i40e_aq_start_lldp(hw, NULL);
1450 "Failed to enable DCBx, err(%d).", ret);
1455 "DCBx is enabled again according to strict"
1456 " priority setting.");
1462 #define I40E_PROFILE_INFO_SIZE sizeof(struct rte_pmd_i40e_profile_info)
1463 #define I40E_MAX_PROFILE_NUM 16
1466 i40e_generate_profile_info_sec(char *name, struct i40e_ddp_version *version,
1467 uint32_t track_id, uint8_t *profile_info_sec,
1470 struct i40e_profile_section_header *sec = NULL;
1471 struct i40e_profile_info *pinfo;
1473 sec = (struct i40e_profile_section_header *)profile_info_sec;
1475 sec->data_end = sizeof(struct i40e_profile_section_header) +
1476 sizeof(struct i40e_profile_info);
1477 sec->section.type = SECTION_TYPE_INFO;
1478 sec->section.offset = sizeof(struct i40e_profile_section_header);
1479 sec->section.size = sizeof(struct i40e_profile_info);
1480 pinfo = (struct i40e_profile_info *)(profile_info_sec +
1481 sec->section.offset);
1482 pinfo->track_id = track_id;
1483 memcpy(pinfo->name, name, I40E_DDP_NAME_SIZE);
1484 memcpy(&pinfo->version, version, sizeof(struct i40e_ddp_version));
1486 pinfo->op = I40E_DDP_ADD_TRACKID;
1488 pinfo->op = I40E_DDP_REMOVE_TRACKID;
1491 static enum i40e_status_code
1492 i40e_add_rm_profile_info(struct i40e_hw *hw, uint8_t *profile_info_sec)
1494 enum i40e_status_code status = I40E_SUCCESS;
1495 struct i40e_profile_section_header *sec;
1497 uint32_t offset = 0;
1500 sec = (struct i40e_profile_section_header *)profile_info_sec;
1501 track_id = ((struct i40e_profile_info *)(profile_info_sec +
1502 sec->section.offset))->track_id;
1504 status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
1505 track_id, &offset, &info, NULL);
1507 PMD_DRV_LOG(ERR, "Failed to add/remove profile info: "
1508 "offset %d, info %d",
1514 /* Check if the profile info exists */
1516 i40e_check_profile_info(uint8_t port, uint8_t *profile_info_sec)
1518 struct rte_eth_dev *dev = &rte_eth_devices[port];
1519 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1521 struct rte_pmd_i40e_profile_list *p_list;
1522 struct rte_pmd_i40e_profile_info *pinfo, *p;
1526 buff = rte_zmalloc("pinfo_list",
1527 (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4),
1530 PMD_DRV_LOG(ERR, "failed to allocate memory");
1534 ret = i40e_aq_get_ddp_list(
1536 (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4),
1539 PMD_DRV_LOG(ERR, "Failed to get profile info list.");
1543 p_list = (struct rte_pmd_i40e_profile_list *)buff;
1544 pinfo = (struct rte_pmd_i40e_profile_info *)(profile_info_sec +
1545 sizeof(struct i40e_profile_section_header));
1546 for (i = 0; i < p_list->p_count; i++) {
1547 p = &p_list->p_info[i];
1548 if (pinfo->track_id == p->track_id) {
1549 PMD_DRV_LOG(INFO, "Profile exists.");
1560 rte_pmd_i40e_process_ddp_package(uint8_t port, uint8_t *buff,
1562 enum rte_pmd_i40e_package_op op)
1564 struct rte_eth_dev *dev;
1566 struct i40e_package_header *pkg_hdr;
1567 struct i40e_generic_seg_header *profile_seg_hdr;
1568 struct i40e_generic_seg_header *metadata_seg_hdr;
1570 uint8_t *profile_info_sec;
1572 enum i40e_status_code status = I40E_SUCCESS;
1574 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
1575 op != RTE_PMD_I40E_PKG_OP_WR_ONLY &&
1576 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
1577 PMD_DRV_LOG(ERR, "Operation not supported.");
1581 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1583 dev = &rte_eth_devices[port];
1585 if (!is_i40e_supported(dev))
1588 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1590 if (size < (sizeof(struct i40e_package_header) +
1591 sizeof(struct i40e_metadata_segment) +
1592 sizeof(uint32_t) * 2)) {
1593 PMD_DRV_LOG(ERR, "Buff is invalid.");
1597 pkg_hdr = (struct i40e_package_header *)buff;
1600 PMD_DRV_LOG(ERR, "Failed to fill the package structure");
1604 if (pkg_hdr->segment_count < 2) {
1605 PMD_DRV_LOG(ERR, "Segment_count should be 2 at least.");
1609 /* Find metadata segment */
1610 metadata_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_METADATA,
1612 if (!metadata_seg_hdr) {
1613 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1616 track_id = ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1617 if (track_id == I40E_DDP_TRACKID_INVALID) {
1618 PMD_DRV_LOG(ERR, "Invalid track_id");
1622 /* Find profile segment */
1623 profile_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_I40E,
1625 if (!profile_seg_hdr) {
1626 PMD_DRV_LOG(ERR, "Failed to find profile segment header");
1630 profile_info_sec = rte_zmalloc(
1631 "i40e_profile_info",
1632 sizeof(struct i40e_profile_section_header) +
1633 sizeof(struct i40e_profile_info),
1635 if (!profile_info_sec) {
1636 PMD_DRV_LOG(ERR, "Failed to allocate memory");
1640 /* Check if the profile already loaded */
1641 i40e_generate_profile_info_sec(
1642 ((struct i40e_profile_segment *)profile_seg_hdr)->name,
1643 &((struct i40e_profile_segment *)profile_seg_hdr)->version,
1644 track_id, profile_info_sec,
1645 op == RTE_PMD_I40E_PKG_OP_WR_ADD);
1646 is_exist = i40e_check_profile_info(port, profile_info_sec);
1648 PMD_DRV_LOG(ERR, "Failed to check profile.");
1649 rte_free(profile_info_sec);
1653 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
1655 PMD_DRV_LOG(ERR, "Profile already exists.");
1656 rte_free(profile_info_sec);
1659 } else if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
1661 PMD_DRV_LOG(ERR, "Profile does not exist.");
1662 rte_free(profile_info_sec);
1667 if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
1668 status = i40e_rollback_profile(
1670 (struct i40e_profile_segment *)profile_seg_hdr,
1673 PMD_DRV_LOG(ERR, "Failed to write profile for delete.");
1674 rte_free(profile_info_sec);
1678 status = i40e_write_profile(
1680 (struct i40e_profile_segment *)profile_seg_hdr,
1683 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
1684 PMD_DRV_LOG(ERR, "Failed to write profile for add.");
1686 PMD_DRV_LOG(ERR, "Failed to write profile.");
1687 rte_free(profile_info_sec);
1692 if (track_id && (op != RTE_PMD_I40E_PKG_OP_WR_ONLY)) {
1693 /* Modify loaded profiles info list */
1694 status = i40e_add_rm_profile_info(hw, profile_info_sec);
1696 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
1697 PMD_DRV_LOG(ERR, "Failed to add profile to info list.");
1699 PMD_DRV_LOG(ERR, "Failed to delete profile from info list.");
1703 rte_free(profile_info_sec);
1707 int rte_pmd_i40e_get_ddp_info(uint8_t *pkg_buff, uint32_t pkg_size,
1708 uint8_t *info_buff, uint32_t info_size,
1709 enum rte_pmd_i40e_package_info type)
1712 struct i40e_package_header *pkg_hdr;
1713 struct i40e_generic_seg_header *i40e_seg_hdr;
1714 struct i40e_generic_seg_header *note_seg_hdr;
1715 struct i40e_generic_seg_header *metadata_seg_hdr;
1718 PMD_DRV_LOG(ERR, "Output info buff is invalid.");
1722 if (!pkg_buff || pkg_size < (sizeof(struct i40e_package_header) +
1723 sizeof(struct i40e_metadata_segment) +
1724 sizeof(uint32_t) * 2)) {
1725 PMD_DRV_LOG(ERR, "Package buff is invalid.");
1729 pkg_hdr = (struct i40e_package_header *)pkg_buff;
1730 if (pkg_hdr->segment_count < 2) {
1731 PMD_DRV_LOG(ERR, "Segment_count should be 2 at least.");
1735 /* Find metadata segment */
1736 metadata_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_METADATA,
1739 /* Find global notes segment */
1740 note_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_NOTES,
1743 /* Find i40e profile segment */
1744 i40e_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_I40E, pkg_hdr);
1746 /* get global header info */
1747 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER) {
1748 struct rte_pmd_i40e_profile_info *info =
1749 (struct rte_pmd_i40e_profile_info *)info_buff;
1751 if (info_size < sizeof(struct rte_pmd_i40e_profile_info)) {
1752 PMD_DRV_LOG(ERR, "Output info buff size is invalid.");
1756 if (!metadata_seg_hdr) {
1757 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1761 memset(info, 0, sizeof(struct rte_pmd_i40e_profile_info));
1762 info->owner = RTE_PMD_I40E_DDP_OWNER_UNKNOWN;
1764 ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1767 ((struct i40e_metadata_segment *)metadata_seg_hdr)->name,
1768 I40E_DDP_NAME_SIZE);
1769 memcpy(&info->version,
1770 &((struct i40e_metadata_segment *)metadata_seg_hdr)->version,
1771 sizeof(struct i40e_ddp_version));
1772 return I40E_SUCCESS;
1775 /* get global note size */
1776 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE) {
1777 if (info_size < sizeof(uint32_t)) {
1778 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1781 if (note_seg_hdr == NULL)
1784 ret_size = note_seg_hdr->size;
1785 *(uint32_t *)info_buff = ret_size;
1786 return I40E_SUCCESS;
1789 /* get global note */
1790 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES) {
1791 if (note_seg_hdr == NULL)
1793 if (info_size < note_seg_hdr->size) {
1794 PMD_DRV_LOG(ERR, "Information buffer size is too small");
1797 memcpy(info_buff, ¬e_seg_hdr[1], note_seg_hdr->size);
1798 return I40E_SUCCESS;
1801 /* get i40e segment header info */
1802 if (type == RTE_PMD_I40E_PKG_INFO_HEADER) {
1803 struct rte_pmd_i40e_profile_info *info =
1804 (struct rte_pmd_i40e_profile_info *)info_buff;
1806 if (info_size < sizeof(struct rte_pmd_i40e_profile_info)) {
1807 PMD_DRV_LOG(ERR, "Output info buff size is invalid.");
1811 if (!metadata_seg_hdr) {
1812 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1816 if (!i40e_seg_hdr) {
1817 PMD_DRV_LOG(ERR, "Failed to find i40e segment header");
1821 memset(info, 0, sizeof(struct rte_pmd_i40e_profile_info));
1822 info->owner = RTE_PMD_I40E_DDP_OWNER_UNKNOWN;
1824 ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1827 ((struct i40e_profile_segment *)i40e_seg_hdr)->name,
1828 I40E_DDP_NAME_SIZE);
1829 memcpy(&info->version,
1830 &((struct i40e_profile_segment *)i40e_seg_hdr)->version,
1831 sizeof(struct i40e_ddp_version));
1832 return I40E_SUCCESS;
1835 /* get number of devices */
1836 if (type == RTE_PMD_I40E_PKG_INFO_DEVID_NUM) {
1837 if (info_size < sizeof(uint32_t)) {
1838 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1841 *(uint32_t *)info_buff =
1842 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table_count;
1843 return I40E_SUCCESS;
1846 /* get list of devices */
1847 if (type == RTE_PMD_I40E_PKG_INFO_DEVID_LIST) {
1850 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table_count;
1851 if (info_size < sizeof(struct rte_pmd_i40e_ddp_device_id) * dev_num) {
1852 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1856 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table,
1857 sizeof(struct rte_pmd_i40e_ddp_device_id) * dev_num);
1858 return I40E_SUCCESS;
1861 PMD_DRV_LOG(ERR, "Info type %u is invalid.", type);
1866 rte_pmd_i40e_get_ddp_list(uint8_t port, uint8_t *buff, uint32_t size)
1868 struct rte_eth_dev *dev;
1870 enum i40e_status_code status = I40E_SUCCESS;
1872 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1874 dev = &rte_eth_devices[port];
1876 if (!is_i40e_supported(dev))
1879 if (size < (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4))
1882 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1884 status = i40e_aq_get_ddp_list(hw, (void *)buff,
1890 static int check_invalid_pkt_type(uint32_t pkt_type)
1892 uint32_t l2, l3, l4, tnl, il2, il3, il4;
1894 l2 = pkt_type & RTE_PTYPE_L2_MASK;
1895 l3 = pkt_type & RTE_PTYPE_L3_MASK;
1896 l4 = pkt_type & RTE_PTYPE_L4_MASK;
1897 tnl = pkt_type & RTE_PTYPE_TUNNEL_MASK;
1898 il2 = pkt_type & RTE_PTYPE_INNER_L2_MASK;
1899 il3 = pkt_type & RTE_PTYPE_INNER_L3_MASK;
1900 il4 = pkt_type & RTE_PTYPE_INNER_L4_MASK;
1903 l2 != RTE_PTYPE_L2_ETHER &&
1904 l2 != RTE_PTYPE_L2_ETHER_TIMESYNC &&
1905 l2 != RTE_PTYPE_L2_ETHER_ARP &&
1906 l2 != RTE_PTYPE_L2_ETHER_LLDP &&
1907 l2 != RTE_PTYPE_L2_ETHER_NSH &&
1908 l2 != RTE_PTYPE_L2_ETHER_VLAN &&
1909 l2 != RTE_PTYPE_L2_ETHER_QINQ)
1913 l3 != RTE_PTYPE_L3_IPV4 &&
1914 l3 != RTE_PTYPE_L3_IPV4_EXT &&
1915 l3 != RTE_PTYPE_L3_IPV6 &&
1916 l3 != RTE_PTYPE_L3_IPV4_EXT_UNKNOWN &&
1917 l3 != RTE_PTYPE_L3_IPV6_EXT &&
1918 l3 != RTE_PTYPE_L3_IPV6_EXT_UNKNOWN)
1922 l4 != RTE_PTYPE_L4_TCP &&
1923 l4 != RTE_PTYPE_L4_UDP &&
1924 l4 != RTE_PTYPE_L4_FRAG &&
1925 l4 != RTE_PTYPE_L4_SCTP &&
1926 l4 != RTE_PTYPE_L4_ICMP &&
1927 l4 != RTE_PTYPE_L4_NONFRAG)
1931 tnl != RTE_PTYPE_TUNNEL_IP &&
1932 tnl != RTE_PTYPE_TUNNEL_GRENAT &&
1933 tnl != RTE_PTYPE_TUNNEL_VXLAN &&
1934 tnl != RTE_PTYPE_TUNNEL_NVGRE &&
1935 tnl != RTE_PTYPE_TUNNEL_GENEVE &&
1936 tnl != RTE_PTYPE_TUNNEL_GRENAT)
1940 il2 != RTE_PTYPE_INNER_L2_ETHER &&
1941 il2 != RTE_PTYPE_INNER_L2_ETHER_VLAN &&
1942 il2 != RTE_PTYPE_INNER_L2_ETHER_QINQ)
1946 il3 != RTE_PTYPE_INNER_L3_IPV4 &&
1947 il3 != RTE_PTYPE_INNER_L3_IPV4_EXT &&
1948 il3 != RTE_PTYPE_INNER_L3_IPV6 &&
1949 il3 != RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN &&
1950 il3 != RTE_PTYPE_INNER_L3_IPV6_EXT &&
1951 il3 != RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN)
1955 il4 != RTE_PTYPE_INNER_L4_TCP &&
1956 il4 != RTE_PTYPE_INNER_L4_UDP &&
1957 il4 != RTE_PTYPE_INNER_L4_FRAG &&
1958 il4 != RTE_PTYPE_INNER_L4_SCTP &&
1959 il4 != RTE_PTYPE_INNER_L4_ICMP &&
1960 il4 != RTE_PTYPE_INNER_L4_NONFRAG)
1966 static int check_invalid_ptype_mapping(
1967 struct rte_pmd_i40e_ptype_mapping *mapping_table,
1972 for (i = 0; i < count; i++) {
1973 uint16_t ptype = mapping_table[i].hw_ptype;
1974 uint32_t pkt_type = mapping_table[i].sw_ptype;
1976 if (ptype >= I40E_MAX_PKT_TYPE)
1979 if (pkt_type == RTE_PTYPE_UNKNOWN)
1982 if (pkt_type & RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK)
1985 if (check_invalid_pkt_type(pkt_type))
1993 rte_pmd_i40e_ptype_mapping_update(
1995 struct rte_pmd_i40e_ptype_mapping *mapping_items,
1999 struct rte_eth_dev *dev;
2000 struct i40e_adapter *ad;
2003 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2005 dev = &rte_eth_devices[port];
2007 if (!is_i40e_supported(dev))
2010 if (count > I40E_MAX_PKT_TYPE)
2013 if (check_invalid_ptype_mapping(mapping_items, count))
2016 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2019 for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
2020 ad->ptype_tbl[i] = RTE_PTYPE_UNKNOWN;
2023 for (i = 0; i < count; i++)
2024 ad->ptype_tbl[mapping_items[i].hw_ptype]
2025 = mapping_items[i].sw_ptype;
2030 int rte_pmd_i40e_ptype_mapping_reset(uint8_t port)
2032 struct rte_eth_dev *dev;
2034 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2036 dev = &rte_eth_devices[port];
2038 if (!is_i40e_supported(dev))
2041 i40e_set_default_ptype_table(dev);
2046 int rte_pmd_i40e_ptype_mapping_get(
2048 struct rte_pmd_i40e_ptype_mapping *mapping_items,
2053 struct rte_eth_dev *dev;
2054 struct i40e_adapter *ad;
2058 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2060 dev = &rte_eth_devices[port];
2062 if (!is_i40e_supported(dev))
2065 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2067 for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
2070 if (valid_only && ad->ptype_tbl[i] == RTE_PTYPE_UNKNOWN)
2072 mapping_items[n].hw_ptype = i;
2073 mapping_items[n].sw_ptype = ad->ptype_tbl[i];
2081 int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
2086 struct rte_eth_dev *dev;
2087 struct i40e_adapter *ad;
2090 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2092 dev = &rte_eth_devices[port];
2094 if (!is_i40e_supported(dev))
2097 if (!mask && check_invalid_pkt_type(target))
2100 if (check_invalid_pkt_type(pkt_type))
2103 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2105 for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
2107 if ((target | ad->ptype_tbl[i]) == target &&
2108 (target & ad->ptype_tbl[i]))
2109 ad->ptype_tbl[i] = pkt_type;
2111 if (ad->ptype_tbl[i] == target)
2112 ad->ptype_tbl[i] = pkt_type;