1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
5 #include <rte_malloc.h>
8 #include "base/i40e_prototype.h"
9 #include "base/i40e_dcb.h"
10 #include "i40e_ethdev.h"
12 #include "i40e_rxtx.h"
13 #include "rte_pmd_i40e.h"
16 rte_pmd_i40e_ping_vfs(uint16_t port, uint16_t vf)
18 struct rte_eth_dev *dev;
21 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
23 dev = &rte_eth_devices[port];
25 if (!is_i40e_supported(dev))
28 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
30 if (vf >= pf->vf_num || !pf->vfs) {
31 PMD_DRV_LOG(ERR, "Invalid argument.");
35 i40e_notify_vf_link_status(dev, &pf->vfs[vf]);
41 rte_pmd_i40e_set_vf_mac_anti_spoof(uint16_t port, uint16_t vf_id, uint8_t on)
43 struct rte_eth_dev *dev;
47 struct i40e_vsi_context ctxt;
50 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
52 dev = &rte_eth_devices[port];
54 if (!is_i40e_supported(dev))
57 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
59 if (vf_id >= pf->vf_num || !pf->vfs) {
60 PMD_DRV_LOG(ERR, "Invalid argument.");
64 vsi = pf->vfs[vf_id].vsi;
66 PMD_DRV_LOG(ERR, "Invalid VSI.");
70 /* Check if it has been already on or off */
71 if (vsi->info.valid_sections &
72 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SECURITY_VALID)) {
74 if ((vsi->info.sec_flags &
75 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK) ==
76 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK)
77 return 0; /* already on */
79 if ((vsi->info.sec_flags &
80 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK) == 0)
81 return 0; /* already off */
85 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
87 vsi->info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
89 vsi->info.sec_flags &= ~I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK;
91 memset(&ctxt, 0, sizeof(ctxt));
92 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
93 ctxt.seid = vsi->seid;
95 hw = I40E_VSI_TO_HW(vsi);
96 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
97 if (ret != I40E_SUCCESS) {
99 PMD_DRV_LOG(ERR, "Failed to update VSI params");
106 i40e_add_rm_all_vlan_filter(struct i40e_vsi *vsi, uint8_t add)
110 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
111 struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
114 for (j = 0; j < I40E_VFTA_SIZE; j++) {
118 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
119 if (!(vsi->vfta[j] & (1 << k)))
122 vlan_id = j * I40E_UINT32_BIT_SIZE + k;
126 vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
128 ret = i40e_aq_add_vlan(hw, vsi->seid,
129 &vlan_data, 1, NULL);
131 ret = i40e_aq_remove_vlan(hw, vsi->seid,
132 &vlan_data, 1, NULL);
133 if (ret != I40E_SUCCESS) {
135 "Failed to add/rm vlan filter");
145 rte_pmd_i40e_set_vf_vlan_anti_spoof(uint16_t port, uint16_t vf_id, uint8_t on)
147 struct rte_eth_dev *dev;
149 struct i40e_vsi *vsi;
151 struct i40e_vsi_context ctxt;
154 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
156 dev = &rte_eth_devices[port];
158 if (!is_i40e_supported(dev))
161 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
163 if (vf_id >= pf->vf_num || !pf->vfs) {
164 PMD_DRV_LOG(ERR, "Invalid argument.");
168 vsi = pf->vfs[vf_id].vsi;
170 PMD_DRV_LOG(ERR, "Invalid VSI.");
174 /* Check if it has been already on or off */
175 if (vsi->vlan_anti_spoof_on == on)
176 return 0; /* already on or off */
178 vsi->vlan_anti_spoof_on = on;
179 if (!vsi->vlan_filter_on) {
180 ret = i40e_add_rm_all_vlan_filter(vsi, on);
182 PMD_DRV_LOG(ERR, "Failed to add/remove VLAN filters.");
187 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
189 vsi->info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK;
191 vsi->info.sec_flags &= ~I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK;
193 memset(&ctxt, 0, sizeof(ctxt));
194 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
195 ctxt.seid = vsi->seid;
197 hw = I40E_VSI_TO_HW(vsi);
198 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
199 if (ret != I40E_SUCCESS) {
201 PMD_DRV_LOG(ERR, "Failed to update VSI params");
208 i40e_vsi_rm_mac_filter(struct i40e_vsi *vsi)
210 struct i40e_mac_filter *f;
211 struct i40e_macvlan_filter *mv_f;
213 enum rte_mac_filter_type filter_type;
214 int ret = I40E_SUCCESS;
217 /* remove all the MACs */
218 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
219 vlan_num = vsi->vlan_num;
220 filter_type = f->mac_info.filter_type;
221 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
222 filter_type == RTE_MACVLAN_HASH_MATCH) {
224 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
225 return I40E_ERR_PARAM;
227 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
228 filter_type == RTE_MAC_HASH_MATCH)
231 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
233 PMD_DRV_LOG(ERR, "failed to allocate memory");
234 return I40E_ERR_NO_MEMORY;
237 for (i = 0; i < vlan_num; i++) {
238 mv_f[i].filter_type = filter_type;
239 rte_memcpy(&mv_f[i].macaddr,
240 &f->mac_info.mac_addr,
243 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
244 filter_type == RTE_MACVLAN_HASH_MATCH) {
245 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
246 &f->mac_info.mac_addr);
247 if (ret != I40E_SUCCESS) {
253 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
254 if (ret != I40E_SUCCESS) {
267 i40e_vsi_restore_mac_filter(struct i40e_vsi *vsi)
269 struct i40e_mac_filter *f;
270 struct i40e_macvlan_filter *mv_f;
272 int ret = I40E_SUCCESS;
275 /* restore all the MACs */
276 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
277 if ((f->mac_info.filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
278 (f->mac_info.filter_type == RTE_MACVLAN_HASH_MATCH)) {
280 * If vlan_num is 0, that's the first time to add mac,
281 * set mask for vlan_id 0.
283 if (vsi->vlan_num == 0) {
284 i40e_set_vlan_filter(vsi, 0, 1);
287 vlan_num = vsi->vlan_num;
288 } else if ((f->mac_info.filter_type == RTE_MAC_PERFECT_MATCH) ||
289 (f->mac_info.filter_type == RTE_MAC_HASH_MATCH))
292 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
294 PMD_DRV_LOG(ERR, "failed to allocate memory");
295 return I40E_ERR_NO_MEMORY;
298 for (i = 0; i < vlan_num; i++) {
299 mv_f[i].filter_type = f->mac_info.filter_type;
300 rte_memcpy(&mv_f[i].macaddr,
301 &f->mac_info.mac_addr,
305 if (f->mac_info.filter_type == RTE_MACVLAN_PERFECT_MATCH ||
306 f->mac_info.filter_type == RTE_MACVLAN_HASH_MATCH) {
307 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
308 &f->mac_info.mac_addr);
309 if (ret != I40E_SUCCESS) {
315 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
316 if (ret != I40E_SUCCESS) {
329 i40e_vsi_set_tx_loopback(struct i40e_vsi *vsi, uint8_t on)
331 struct i40e_vsi_context ctxt;
338 hw = I40E_VSI_TO_HW(vsi);
340 /* Use the FW API if FW >= v5.0 */
341 if (hw->aq.fw_maj_ver < 5) {
342 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
346 /* Check if it has been already on or off */
347 if (vsi->info.valid_sections &
348 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID)) {
350 if ((vsi->info.switch_id &
351 I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) ==
352 I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB)
353 return 0; /* already on */
355 if ((vsi->info.switch_id &
356 I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) == 0)
357 return 0; /* already off */
361 /* remove all the MAC and VLAN first */
362 ret = i40e_vsi_rm_mac_filter(vsi);
364 PMD_INIT_LOG(ERR, "Failed to remove MAC filters.");
367 if (vsi->vlan_anti_spoof_on || vsi->vlan_filter_on) {
368 ret = i40e_add_rm_all_vlan_filter(vsi, 0);
370 PMD_INIT_LOG(ERR, "Failed to remove VLAN filters.");
375 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
377 vsi->info.switch_id |= I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
379 vsi->info.switch_id &= ~I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
381 memset(&ctxt, 0, sizeof(ctxt));
382 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
383 ctxt.seid = vsi->seid;
385 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
386 if (ret != I40E_SUCCESS) {
387 PMD_DRV_LOG(ERR, "Failed to update VSI params");
391 /* add all the MAC and VLAN back */
392 ret = i40e_vsi_restore_mac_filter(vsi);
395 if (vsi->vlan_anti_spoof_on || vsi->vlan_filter_on) {
396 ret = i40e_add_rm_all_vlan_filter(vsi, 1);
405 rte_pmd_i40e_set_tx_loopback(uint16_t port, uint8_t on)
407 struct rte_eth_dev *dev;
409 struct i40e_pf_vf *vf;
410 struct i40e_vsi *vsi;
414 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
416 dev = &rte_eth_devices[port];
418 if (!is_i40e_supported(dev))
421 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
423 /* setup PF TX loopback */
425 ret = i40e_vsi_set_tx_loopback(vsi, on);
429 /* setup TX loopback for all the VFs */
431 /* if no VF, do nothing. */
435 for (vf_id = 0; vf_id < pf->vf_num; vf_id++) {
436 vf = &pf->vfs[vf_id];
439 ret = i40e_vsi_set_tx_loopback(vsi, on);
448 rte_pmd_i40e_set_vf_unicast_promisc(uint16_t port, uint16_t vf_id, uint8_t on)
450 struct rte_eth_dev *dev;
452 struct i40e_vsi *vsi;
456 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
458 dev = &rte_eth_devices[port];
460 if (!is_i40e_supported(dev))
463 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
465 if (vf_id >= pf->vf_num || !pf->vfs) {
466 PMD_DRV_LOG(ERR, "Invalid argument.");
470 vsi = pf->vfs[vf_id].vsi;
472 PMD_DRV_LOG(ERR, "Invalid VSI.");
476 hw = I40E_VSI_TO_HW(vsi);
478 ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
480 if (ret != I40E_SUCCESS) {
482 PMD_DRV_LOG(ERR, "Failed to set unicast promiscuous mode");
489 rte_pmd_i40e_set_vf_multicast_promisc(uint16_t port, uint16_t vf_id, uint8_t on)
491 struct rte_eth_dev *dev;
493 struct i40e_vsi *vsi;
497 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
499 dev = &rte_eth_devices[port];
501 if (!is_i40e_supported(dev))
504 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
506 if (vf_id >= pf->vf_num || !pf->vfs) {
507 PMD_DRV_LOG(ERR, "Invalid argument.");
511 vsi = pf->vfs[vf_id].vsi;
513 PMD_DRV_LOG(ERR, "Invalid VSI.");
517 hw = I40E_VSI_TO_HW(vsi);
519 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
521 if (ret != I40E_SUCCESS) {
523 PMD_DRV_LOG(ERR, "Failed to set multicast promiscuous mode");
530 rte_pmd_i40e_set_vf_mac_addr(uint16_t port, uint16_t vf_id,
531 struct ether_addr *mac_addr)
533 struct i40e_mac_filter *f;
534 struct rte_eth_dev *dev;
535 struct i40e_pf_vf *vf;
536 struct i40e_vsi *vsi;
540 if (i40e_validate_mac_addr((u8 *)mac_addr) != I40E_SUCCESS)
543 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
545 dev = &rte_eth_devices[port];
547 if (!is_i40e_supported(dev))
550 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
552 if (vf_id >= pf->vf_num || !pf->vfs)
555 vf = &pf->vfs[vf_id];
558 PMD_DRV_LOG(ERR, "Invalid VSI.");
562 ether_addr_copy(mac_addr, &vf->mac_addr);
564 /* Remove all existing mac */
565 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
566 if (i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr)
568 PMD_DRV_LOG(WARNING, "Delete MAC failed");
573 /* Set vlan strip on/off for specific VF from host */
575 rte_pmd_i40e_set_vf_vlan_stripq(uint16_t port, uint16_t vf_id, uint8_t on)
577 struct rte_eth_dev *dev;
579 struct i40e_vsi *vsi;
582 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
584 dev = &rte_eth_devices[port];
586 if (!is_i40e_supported(dev))
589 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
591 if (vf_id >= pf->vf_num || !pf->vfs) {
592 PMD_DRV_LOG(ERR, "Invalid argument.");
596 vsi = pf->vfs[vf_id].vsi;
601 ret = i40e_vsi_config_vlan_stripping(vsi, !!on);
602 if (ret != I40E_SUCCESS) {
604 PMD_DRV_LOG(ERR, "Failed to set VLAN stripping!");
610 int rte_pmd_i40e_set_vf_vlan_insert(uint16_t port, uint16_t vf_id,
613 struct rte_eth_dev *dev;
616 struct i40e_vsi *vsi;
617 struct i40e_vsi_context ctxt;
620 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
622 if (vlan_id > ETHER_MAX_VLAN_ID) {
623 PMD_DRV_LOG(ERR, "Invalid VLAN ID.");
627 dev = &rte_eth_devices[port];
629 if (!is_i40e_supported(dev))
632 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
633 hw = I40E_PF_TO_HW(pf);
636 * return -ENODEV if SRIOV not enabled, VF number not configured
637 * or no queue assigned.
639 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
643 if (vf_id >= pf->vf_num || !pf->vfs) {
644 PMD_DRV_LOG(ERR, "Invalid VF ID.");
648 vsi = pf->vfs[vf_id].vsi;
650 PMD_DRV_LOG(ERR, "Invalid VSI.");
654 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
655 vsi->info.pvid = vlan_id;
657 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID;
659 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_INSERT_PVID;
661 memset(&ctxt, 0, sizeof(ctxt));
662 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
663 ctxt.seid = vsi->seid;
665 hw = I40E_VSI_TO_HW(vsi);
666 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
667 if (ret != I40E_SUCCESS) {
669 PMD_DRV_LOG(ERR, "Failed to update VSI params");
675 int rte_pmd_i40e_set_vf_broadcast(uint16_t port, uint16_t vf_id,
678 struct rte_eth_dev *dev;
680 struct i40e_vsi *vsi;
682 struct i40e_mac_filter_info filter;
683 struct ether_addr broadcast = {
684 .addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
687 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
690 PMD_DRV_LOG(ERR, "on should be 0 or 1.");
694 dev = &rte_eth_devices[port];
696 if (!is_i40e_supported(dev))
699 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
700 hw = I40E_PF_TO_HW(pf);
702 if (vf_id >= pf->vf_num || !pf->vfs) {
703 PMD_DRV_LOG(ERR, "Invalid VF ID.");
708 * return -ENODEV if SRIOV not enabled, VF number not configured
709 * or no queue assigned.
711 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
712 pf->vf_nb_qps == 0) {
713 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
717 vsi = pf->vfs[vf_id].vsi;
719 PMD_DRV_LOG(ERR, "Invalid VSI.");
724 rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
725 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
726 ret = i40e_vsi_add_mac(vsi, &filter);
728 ret = i40e_vsi_delete_mac(vsi, &broadcast);
731 if (ret != I40E_SUCCESS && ret != I40E_ERR_PARAM) {
733 PMD_DRV_LOG(ERR, "Failed to set VSI broadcast");
741 int rte_pmd_i40e_set_vf_vlan_tag(uint16_t port, uint16_t vf_id, uint8_t on)
743 struct rte_eth_dev *dev;
746 struct i40e_vsi *vsi;
747 struct i40e_vsi_context ctxt;
750 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
753 PMD_DRV_LOG(ERR, "on should be 0 or 1.");
757 dev = &rte_eth_devices[port];
759 if (!is_i40e_supported(dev))
762 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
763 hw = I40E_PF_TO_HW(pf);
766 * return -ENODEV if SRIOV not enabled, VF number not configured
767 * or no queue assigned.
769 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
770 pf->vf_nb_qps == 0) {
771 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
775 if (vf_id >= pf->vf_num || !pf->vfs) {
776 PMD_DRV_LOG(ERR, "Invalid VF ID.");
780 vsi = pf->vfs[vf_id].vsi;
782 PMD_DRV_LOG(ERR, "Invalid VSI.");
786 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
788 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
789 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
791 vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
792 vsi->info.port_vlan_flags &= ~I40E_AQ_VSI_PVLAN_MODE_TAGGED;
795 memset(&ctxt, 0, sizeof(ctxt));
796 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
797 ctxt.seid = vsi->seid;
799 hw = I40E_VSI_TO_HW(vsi);
800 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
801 if (ret != I40E_SUCCESS) {
803 PMD_DRV_LOG(ERR, "Failed to update VSI params");
810 i40e_vlan_filter_count(struct i40e_vsi *vsi)
816 for (j = 0; j < I40E_VFTA_SIZE; j++) {
820 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
821 if (!(vsi->vfta[j] & (1 << k)))
824 vlan_id = j * I40E_UINT32_BIT_SIZE + k;
835 int rte_pmd_i40e_set_vf_vlan_filter(uint16_t port, uint16_t vlan_id,
836 uint64_t vf_mask, uint8_t on)
838 struct rte_eth_dev *dev;
841 struct i40e_vsi *vsi;
843 int ret = I40E_SUCCESS;
845 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
847 dev = &rte_eth_devices[port];
849 if (!is_i40e_supported(dev))
852 if (vlan_id > ETHER_MAX_VLAN_ID || !vlan_id) {
853 PMD_DRV_LOG(ERR, "Invalid VLAN ID.");
858 PMD_DRV_LOG(ERR, "No VF.");
863 PMD_DRV_LOG(ERR, "on is should be 0 or 1.");
867 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
868 hw = I40E_PF_TO_HW(pf);
871 * return -ENODEV if SRIOV not enabled, VF number not configured
872 * or no queue assigned.
874 if (!hw->func_caps.sr_iov_1_1 || pf->vf_num == 0 ||
875 pf->vf_nb_qps == 0) {
876 PMD_DRV_LOG(ERR, "SRIOV is not enabled or no queue.");
880 for (vf_idx = 0; vf_idx < pf->vf_num && ret == I40E_SUCCESS; vf_idx++) {
881 if (vf_mask & ((uint64_t)(1ULL << vf_idx))) {
882 vsi = pf->vfs[vf_idx].vsi;
884 if (!vsi->vlan_filter_on) {
885 vsi->vlan_filter_on = true;
886 i40e_aq_set_vsi_vlan_promisc(hw,
890 if (!vsi->vlan_anti_spoof_on)
891 i40e_add_rm_all_vlan_filter(
894 ret = i40e_vsi_add_vlan(vsi, vlan_id);
896 ret = i40e_vsi_delete_vlan(vsi, vlan_id);
898 if (!i40e_vlan_filter_count(vsi)) {
899 vsi->vlan_filter_on = false;
900 i40e_aq_set_vsi_vlan_promisc(hw,
909 if (ret != I40E_SUCCESS) {
911 PMD_DRV_LOG(ERR, "Failed to set VF VLAN filter, on = %d", on);
918 rte_pmd_i40e_get_vf_stats(uint16_t port,
920 struct rte_eth_stats *stats)
922 struct rte_eth_dev *dev;
924 struct i40e_vsi *vsi;
926 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
928 dev = &rte_eth_devices[port];
930 if (!is_i40e_supported(dev))
933 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
935 if (vf_id >= pf->vf_num || !pf->vfs) {
936 PMD_DRV_LOG(ERR, "Invalid VF ID.");
940 vsi = pf->vfs[vf_id].vsi;
942 PMD_DRV_LOG(ERR, "Invalid VSI.");
946 i40e_update_vsi_stats(vsi);
948 stats->ipackets = vsi->eth_stats.rx_unicast +
949 vsi->eth_stats.rx_multicast +
950 vsi->eth_stats.rx_broadcast;
951 stats->opackets = vsi->eth_stats.tx_unicast +
952 vsi->eth_stats.tx_multicast +
953 vsi->eth_stats.tx_broadcast;
954 stats->ibytes = vsi->eth_stats.rx_bytes;
955 stats->obytes = vsi->eth_stats.tx_bytes;
956 stats->ierrors = vsi->eth_stats.rx_discards;
957 stats->oerrors = vsi->eth_stats.tx_errors + vsi->eth_stats.tx_discards;
963 rte_pmd_i40e_reset_vf_stats(uint16_t port,
966 struct rte_eth_dev *dev;
968 struct i40e_vsi *vsi;
970 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
972 dev = &rte_eth_devices[port];
974 if (!is_i40e_supported(dev))
977 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
979 if (vf_id >= pf->vf_num || !pf->vfs) {
980 PMD_DRV_LOG(ERR, "Invalid VF ID.");
984 vsi = pf->vfs[vf_id].vsi;
986 PMD_DRV_LOG(ERR, "Invalid VSI.");
990 vsi->offset_loaded = false;
991 i40e_update_vsi_stats(vsi);
997 rte_pmd_i40e_set_vf_max_bw(uint16_t port, uint16_t vf_id, uint32_t bw)
999 struct rte_eth_dev *dev;
1001 struct i40e_vsi *vsi;
1006 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1008 dev = &rte_eth_devices[port];
1010 if (!is_i40e_supported(dev))
1013 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1015 if (vf_id >= pf->vf_num || !pf->vfs) {
1016 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1020 vsi = pf->vfs[vf_id].vsi;
1022 PMD_DRV_LOG(ERR, "Invalid VSI.");
1026 if (bw > I40E_QOS_BW_MAX) {
1027 PMD_DRV_LOG(ERR, "Bandwidth should not be larger than %dMbps.",
1032 if (bw % I40E_QOS_BW_GRANULARITY) {
1033 PMD_DRV_LOG(ERR, "Bandwidth should be the multiple of %dMbps.",
1034 I40E_QOS_BW_GRANULARITY);
1038 bw /= I40E_QOS_BW_GRANULARITY;
1040 hw = I40E_VSI_TO_HW(vsi);
1043 if (bw == vsi->bw_info.bw_limit) {
1045 "No change for VF max bandwidth. Nothing to do.");
1050 * VF bandwidth limitation and TC bandwidth limitation cannot be
1051 * enabled in parallel, quit if TC bandwidth limitation is enabled.
1053 * If bw is 0, means disable bandwidth limitation. Then no need to
1054 * check TC bandwidth limitation.
1057 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1058 if ((vsi->enabled_tc & BIT_ULL(i)) &&
1059 vsi->bw_info.bw_ets_credits[i])
1062 if (i != I40E_MAX_TRAFFIC_CLASS) {
1064 "TC max bandwidth has been set on this VF,"
1065 " please disable it first.");
1070 ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid, (uint16_t)bw, 0, NULL);
1073 "Failed to set VF %d bandwidth, err(%d).",
1078 /* Store the configuration. */
1079 vsi->bw_info.bw_limit = (uint16_t)bw;
1080 vsi->bw_info.bw_max = 0;
1086 rte_pmd_i40e_set_vf_tc_bw_alloc(uint16_t port, uint16_t vf_id,
1087 uint8_t tc_num, uint8_t *bw_weight)
1089 struct rte_eth_dev *dev;
1091 struct i40e_vsi *vsi;
1093 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw;
1097 bool b_change = false;
1099 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1101 dev = &rte_eth_devices[port];
1103 if (!is_i40e_supported(dev))
1106 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1108 if (vf_id >= pf->vf_num || !pf->vfs) {
1109 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1113 vsi = pf->vfs[vf_id].vsi;
1115 PMD_DRV_LOG(ERR, "Invalid VSI.");
1119 if (tc_num > I40E_MAX_TRAFFIC_CLASS) {
1120 PMD_DRV_LOG(ERR, "TCs should be no more than %d.",
1121 I40E_MAX_TRAFFIC_CLASS);
1126 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1127 if (vsi->enabled_tc & BIT_ULL(i))
1130 if (sum != tc_num) {
1132 "Weight should be set for all %d enabled TCs.",
1138 for (i = 0; i < tc_num; i++) {
1139 if (!bw_weight[i]) {
1141 "The weight should be 1 at least.");
1144 sum += bw_weight[i];
1148 "The summary of the TC weight should be 100.");
1153 * Create the configuration for all the TCs.
1155 memset(&tc_bw, 0, sizeof(tc_bw));
1156 tc_bw.tc_valid_bits = vsi->enabled_tc;
1158 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1159 if (vsi->enabled_tc & BIT_ULL(i)) {
1161 vsi->bw_info.bw_ets_share_credits[i])
1164 tc_bw.tc_bw_credits[i] = bw_weight[j];
1172 "No change for TC allocated bandwidth."
1177 hw = I40E_VSI_TO_HW(vsi);
1179 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw, NULL);
1182 "Failed to set VF %d TC bandwidth weight, err(%d).",
1187 /* Store the configuration. */
1189 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1190 if (vsi->enabled_tc & BIT_ULL(i)) {
1191 vsi->bw_info.bw_ets_share_credits[i] = bw_weight[j];
1200 rte_pmd_i40e_set_vf_tc_max_bw(uint16_t port, uint16_t vf_id,
1201 uint8_t tc_no, uint32_t bw)
1203 struct rte_eth_dev *dev;
1205 struct i40e_vsi *vsi;
1207 struct i40e_aqc_configure_vsi_ets_sla_bw_data tc_bw;
1211 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1213 dev = &rte_eth_devices[port];
1215 if (!is_i40e_supported(dev))
1218 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1220 if (vf_id >= pf->vf_num || !pf->vfs) {
1221 PMD_DRV_LOG(ERR, "Invalid VF ID.");
1225 vsi = pf->vfs[vf_id].vsi;
1227 PMD_DRV_LOG(ERR, "Invalid VSI.");
1231 if (bw > I40E_QOS_BW_MAX) {
1232 PMD_DRV_LOG(ERR, "Bandwidth should not be larger than %dMbps.",
1237 if (bw % I40E_QOS_BW_GRANULARITY) {
1238 PMD_DRV_LOG(ERR, "Bandwidth should be the multiple of %dMbps.",
1239 I40E_QOS_BW_GRANULARITY);
1243 bw /= I40E_QOS_BW_GRANULARITY;
1245 if (tc_no >= I40E_MAX_TRAFFIC_CLASS) {
1246 PMD_DRV_LOG(ERR, "TC No. should be less than %d.",
1247 I40E_MAX_TRAFFIC_CLASS);
1251 hw = I40E_VSI_TO_HW(vsi);
1253 if (!(vsi->enabled_tc & BIT_ULL(tc_no))) {
1254 PMD_DRV_LOG(ERR, "VF %d TC %d isn't enabled.",
1260 if (bw == vsi->bw_info.bw_ets_credits[tc_no]) {
1262 "No change for TC max bandwidth. Nothing to do.");
1267 * VF bandwidth limitation and TC bandwidth limitation cannot be
1268 * enabled in parallel, disable VF bandwidth limitation if it's
1270 * If bw is 0, means disable bandwidth limitation. Then no need to
1271 * care about VF bandwidth limitation configuration.
1273 if (bw && vsi->bw_info.bw_limit) {
1274 ret = i40e_aq_config_vsi_bw_limit(hw, vsi->seid, 0, 0, NULL);
1277 "Failed to disable VF(%d)"
1278 " bandwidth limitation, err(%d).",
1284 "VF max bandwidth is disabled according"
1285 " to TC max bandwidth setting.");
1289 * Get all the TCs' info to create a whole picture.
1290 * Because the incremental change isn't permitted.
1292 memset(&tc_bw, 0, sizeof(tc_bw));
1293 tc_bw.tc_valid_bits = vsi->enabled_tc;
1294 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1295 if (vsi->enabled_tc & BIT_ULL(i)) {
1296 tc_bw.tc_bw_credits[i] =
1298 vsi->bw_info.bw_ets_credits[i]);
1301 tc_bw.tc_bw_credits[tc_no] = rte_cpu_to_le_16((uint16_t)bw);
1303 ret = i40e_aq_config_vsi_ets_sla_bw_limit(hw, vsi->seid, &tc_bw, NULL);
1306 "Failed to set VF %d TC %d max bandwidth, err(%d).",
1311 /* Store the configuration. */
1312 vsi->bw_info.bw_ets_credits[tc_no] = (uint16_t)bw;
1318 rte_pmd_i40e_set_tc_strict_prio(uint16_t port, uint8_t tc_map)
1320 struct rte_eth_dev *dev;
1322 struct i40e_vsi *vsi;
1323 struct i40e_veb *veb;
1325 struct i40e_aqc_configure_switching_comp_ets_data ets_data;
1329 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1331 dev = &rte_eth_devices[port];
1333 if (!is_i40e_supported(dev))
1336 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1340 PMD_DRV_LOG(ERR, "Invalid VSI.");
1346 PMD_DRV_LOG(ERR, "Invalid VEB.");
1350 if ((tc_map & veb->enabled_tc) != tc_map) {
1352 "TC bitmap isn't the subset of enabled TCs 0x%x.",
1357 if (tc_map == veb->strict_prio_tc) {
1358 PMD_DRV_LOG(INFO, "No change for TC bitmap. Nothing to do.");
1362 hw = I40E_VSI_TO_HW(vsi);
1364 /* Disable DCBx if it's the first time to set strict priority. */
1365 if (!veb->strict_prio_tc) {
1366 ret = i40e_aq_stop_lldp(hw, true, NULL);
1369 "Failed to disable DCBx as it's already"
1373 "DCBx is disabled according to strict"
1374 " priority setting.");
1377 memset(&ets_data, 0, sizeof(ets_data));
1378 ets_data.tc_valid_bits = veb->enabled_tc;
1379 ets_data.seepage = I40E_AQ_ETS_SEEPAGE_EN_MASK;
1380 ets_data.tc_strict_priority_flags = tc_map;
1381 /* Get all TCs' bandwidth. */
1382 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1383 if (veb->enabled_tc & BIT_ULL(i)) {
1384 /* For rubust, if bandwidth is 0, use 1 instead. */
1385 if (veb->bw_info.bw_ets_share_credits[i])
1386 ets_data.tc_bw_share_credits[i] =
1387 veb->bw_info.bw_ets_share_credits[i];
1389 ets_data.tc_bw_share_credits[i] =
1390 I40E_QOS_BW_WEIGHT_MIN;
1394 if (!veb->strict_prio_tc)
1395 ret = i40e_aq_config_switch_comp_ets(
1396 hw, veb->uplink_seid,
1397 &ets_data, i40e_aqc_opc_enable_switching_comp_ets,
1400 ret = i40e_aq_config_switch_comp_ets(
1401 hw, veb->uplink_seid,
1402 &ets_data, i40e_aqc_opc_modify_switching_comp_ets,
1405 ret = i40e_aq_config_switch_comp_ets(
1406 hw, veb->uplink_seid,
1407 &ets_data, i40e_aqc_opc_disable_switching_comp_ets,
1412 "Failed to set TCs' strict priority mode."
1417 veb->strict_prio_tc = tc_map;
1419 /* Enable DCBx again, if all the TCs' strict priority disabled. */
1421 ret = i40e_aq_start_lldp(hw, NULL);
1424 "Failed to enable DCBx, err(%d).", ret);
1429 "DCBx is enabled again according to strict"
1430 " priority setting.");
1436 #define I40E_PROFILE_INFO_SIZE sizeof(struct rte_pmd_i40e_profile_info)
1437 #define I40E_MAX_PROFILE_NUM 16
1440 i40e_generate_profile_info_sec(char *name, struct i40e_ddp_version *version,
1441 uint32_t track_id, uint8_t *profile_info_sec,
1444 struct i40e_profile_section_header *sec = NULL;
1445 struct i40e_profile_info *pinfo;
1447 sec = (struct i40e_profile_section_header *)profile_info_sec;
1449 sec->data_end = sizeof(struct i40e_profile_section_header) +
1450 sizeof(struct i40e_profile_info);
1451 sec->section.type = SECTION_TYPE_INFO;
1452 sec->section.offset = sizeof(struct i40e_profile_section_header);
1453 sec->section.size = sizeof(struct i40e_profile_info);
1454 pinfo = (struct i40e_profile_info *)(profile_info_sec +
1455 sec->section.offset);
1456 pinfo->track_id = track_id;
1457 memcpy(pinfo->name, name, I40E_DDP_NAME_SIZE);
1458 memcpy(&pinfo->version, version, sizeof(struct i40e_ddp_version));
1460 pinfo->op = I40E_DDP_ADD_TRACKID;
1462 pinfo->op = I40E_DDP_REMOVE_TRACKID;
1465 static enum i40e_status_code
1466 i40e_add_rm_profile_info(struct i40e_hw *hw, uint8_t *profile_info_sec)
1468 enum i40e_status_code status = I40E_SUCCESS;
1469 struct i40e_profile_section_header *sec;
1471 uint32_t offset = 0;
1474 sec = (struct i40e_profile_section_header *)profile_info_sec;
1475 track_id = ((struct i40e_profile_info *)(profile_info_sec +
1476 sec->section.offset))->track_id;
1478 status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
1479 track_id, &offset, &info, NULL);
1481 PMD_DRV_LOG(ERR, "Failed to add/remove profile info: "
1482 "offset %d, info %d",
1488 /* Check if the profile info exists */
1490 i40e_check_profile_info(uint16_t port, uint8_t *profile_info_sec)
1492 struct rte_eth_dev *dev = &rte_eth_devices[port];
1493 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1495 struct rte_pmd_i40e_profile_list *p_list;
1496 struct rte_pmd_i40e_profile_info *pinfo, *p;
1499 static const uint32_t group_mask = 0x00ff0000;
1501 pinfo = (struct rte_pmd_i40e_profile_info *)(profile_info_sec +
1502 sizeof(struct i40e_profile_section_header));
1503 if (pinfo->track_id == 0) {
1504 PMD_DRV_LOG(INFO, "Read-only profile.");
1507 buff = rte_zmalloc("pinfo_list",
1508 (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4),
1511 PMD_DRV_LOG(ERR, "failed to allocate memory");
1515 ret = i40e_aq_get_ddp_list(
1517 (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4),
1520 PMD_DRV_LOG(ERR, "Failed to get profile info list.");
1524 p_list = (struct rte_pmd_i40e_profile_list *)buff;
1525 for (i = 0; i < p_list->p_count; i++) {
1526 p = &p_list->p_info[i];
1527 if (pinfo->track_id == p->track_id) {
1528 PMD_DRV_LOG(INFO, "Profile exists.");
1533 for (i = 0; i < p_list->p_count; i++) {
1534 p = &p_list->p_info[i];
1535 if ((p->track_id & group_mask) == 0) {
1536 PMD_DRV_LOG(INFO, "Profile of the group 0 exists.");
1541 for (i = 0; i < p_list->p_count; i++) {
1542 p = &p_list->p_info[i];
1543 if ((pinfo->track_id & group_mask) !=
1544 (p->track_id & group_mask)) {
1545 PMD_DRV_LOG(INFO, "Profile of different group exists.");
1556 rte_pmd_i40e_process_ddp_package(uint16_t port, uint8_t *buff,
1558 enum rte_pmd_i40e_package_op op)
1560 struct rte_eth_dev *dev;
1562 struct i40e_package_header *pkg_hdr;
1563 struct i40e_generic_seg_header *profile_seg_hdr;
1564 struct i40e_generic_seg_header *metadata_seg_hdr;
1566 uint8_t *profile_info_sec;
1568 enum i40e_status_code status = I40E_SUCCESS;
1569 static const uint32_t type_mask = 0xff000000;
1571 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
1572 op != RTE_PMD_I40E_PKG_OP_WR_ONLY &&
1573 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
1574 PMD_DRV_LOG(ERR, "Operation not supported.");
1578 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1580 dev = &rte_eth_devices[port];
1582 if (!is_i40e_supported(dev))
1585 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1587 if (size < (sizeof(struct i40e_package_header) +
1588 sizeof(struct i40e_metadata_segment) +
1589 sizeof(uint32_t) * 2)) {
1590 PMD_DRV_LOG(ERR, "Buff is invalid.");
1594 pkg_hdr = (struct i40e_package_header *)buff;
1597 PMD_DRV_LOG(ERR, "Failed to fill the package structure");
1601 if (pkg_hdr->segment_count < 2) {
1602 PMD_DRV_LOG(ERR, "Segment_count should be 2 at least.");
1606 i40e_update_customized_info(dev, buff, size);
1608 /* Find metadata segment */
1609 metadata_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_METADATA,
1611 if (!metadata_seg_hdr) {
1612 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1615 track_id = ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1616 if (track_id == I40E_DDP_TRACKID_INVALID) {
1617 PMD_DRV_LOG(ERR, "Invalid track_id");
1621 /* force read-only track_id for type 0 */
1622 if ((track_id & type_mask) == 0)
1625 /* Find profile segment */
1626 profile_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_I40E,
1628 if (!profile_seg_hdr) {
1629 PMD_DRV_LOG(ERR, "Failed to find profile segment header");
1633 profile_info_sec = rte_zmalloc(
1634 "i40e_profile_info",
1635 sizeof(struct i40e_profile_section_header) +
1636 sizeof(struct i40e_profile_info),
1638 if (!profile_info_sec) {
1639 PMD_DRV_LOG(ERR, "Failed to allocate memory");
1643 /* Check if the profile already loaded */
1644 i40e_generate_profile_info_sec(
1645 ((struct i40e_profile_segment *)profile_seg_hdr)->name,
1646 &((struct i40e_profile_segment *)profile_seg_hdr)->version,
1647 track_id, profile_info_sec,
1648 op == RTE_PMD_I40E_PKG_OP_WR_ADD);
1649 is_exist = i40e_check_profile_info(port, profile_info_sec);
1651 PMD_DRV_LOG(ERR, "Failed to check profile.");
1652 rte_free(profile_info_sec);
1656 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
1659 PMD_DRV_LOG(ERR, "Profile already exists.");
1660 else if (is_exist == 2)
1661 PMD_DRV_LOG(ERR, "Profile of group 0 already exists.");
1662 else if (is_exist == 3)
1663 PMD_DRV_LOG(ERR, "Profile of different group already exists");
1664 rte_free(profile_info_sec);
1667 } else if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
1668 if (is_exist != 1) {
1669 PMD_DRV_LOG(ERR, "Profile does not exist.");
1670 rte_free(profile_info_sec);
1675 if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
1676 status = i40e_rollback_profile(
1678 (struct i40e_profile_segment *)profile_seg_hdr,
1681 PMD_DRV_LOG(ERR, "Failed to write profile for delete.");
1682 rte_free(profile_info_sec);
1686 status = i40e_write_profile(
1688 (struct i40e_profile_segment *)profile_seg_hdr,
1691 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
1692 PMD_DRV_LOG(ERR, "Failed to write profile for add.");
1694 PMD_DRV_LOG(ERR, "Failed to write profile.");
1695 rte_free(profile_info_sec);
1700 if (track_id && (op != RTE_PMD_I40E_PKG_OP_WR_ONLY)) {
1701 /* Modify loaded profiles info list */
1702 status = i40e_add_rm_profile_info(hw, profile_info_sec);
1704 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
1705 PMD_DRV_LOG(ERR, "Failed to add profile to info list.");
1707 PMD_DRV_LOG(ERR, "Failed to delete profile from info list.");
1711 rte_free(profile_info_sec);
1715 /* Get number of tvl records in the section */
1717 i40e_get_tlv_section_size(struct i40e_profile_section_header *sec)
1719 unsigned int i, nb_rec, nb_tlv = 0;
1720 struct i40e_profile_tlv_section_record *tlv;
1725 /* get number of records in the section */
1726 nb_rec = sec->section.size /
1727 sizeof(struct i40e_profile_tlv_section_record);
1728 for (i = 0; i < nb_rec; ) {
1729 tlv = (struct i40e_profile_tlv_section_record *)&sec[1 + i];
1736 int rte_pmd_i40e_get_ddp_info(uint8_t *pkg_buff, uint32_t pkg_size,
1737 uint8_t *info_buff, uint32_t info_size,
1738 enum rte_pmd_i40e_package_info type)
1741 struct i40e_package_header *pkg_hdr;
1742 struct i40e_generic_seg_header *i40e_seg_hdr;
1743 struct i40e_generic_seg_header *note_seg_hdr;
1744 struct i40e_generic_seg_header *metadata_seg_hdr;
1747 PMD_DRV_LOG(ERR, "Output info buff is invalid.");
1751 if (!pkg_buff || pkg_size < (sizeof(struct i40e_package_header) +
1752 sizeof(struct i40e_metadata_segment) +
1753 sizeof(uint32_t) * 2)) {
1754 PMD_DRV_LOG(ERR, "Package buff is invalid.");
1758 pkg_hdr = (struct i40e_package_header *)pkg_buff;
1759 if (pkg_hdr->segment_count < 2) {
1760 PMD_DRV_LOG(ERR, "Segment_count should be 2 at least.");
1764 /* Find metadata segment */
1765 metadata_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_METADATA,
1768 /* Find global notes segment */
1769 note_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_NOTES,
1772 /* Find i40e profile segment */
1773 i40e_seg_hdr = i40e_find_segment_in_package(SEGMENT_TYPE_I40E, pkg_hdr);
1775 /* get global header info */
1776 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER) {
1777 struct rte_pmd_i40e_profile_info *info =
1778 (struct rte_pmd_i40e_profile_info *)info_buff;
1780 if (info_size < sizeof(struct rte_pmd_i40e_profile_info)) {
1781 PMD_DRV_LOG(ERR, "Output info buff size is invalid.");
1785 if (!metadata_seg_hdr) {
1786 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1790 memset(info, 0, sizeof(struct rte_pmd_i40e_profile_info));
1791 info->owner = RTE_PMD_I40E_DDP_OWNER_UNKNOWN;
1793 ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1796 ((struct i40e_metadata_segment *)metadata_seg_hdr)->name,
1797 I40E_DDP_NAME_SIZE);
1798 memcpy(&info->version,
1799 &((struct i40e_metadata_segment *)metadata_seg_hdr)->version,
1800 sizeof(struct i40e_ddp_version));
1801 return I40E_SUCCESS;
1804 /* get global note size */
1805 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE) {
1806 if (info_size < sizeof(uint32_t)) {
1807 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1810 if (note_seg_hdr == NULL)
1813 ret_size = note_seg_hdr->size;
1814 *(uint32_t *)info_buff = ret_size;
1815 return I40E_SUCCESS;
1818 /* get global note */
1819 if (type == RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES) {
1820 if (note_seg_hdr == NULL)
1822 if (info_size < note_seg_hdr->size) {
1823 PMD_DRV_LOG(ERR, "Information buffer size is too small");
1826 memcpy(info_buff, ¬e_seg_hdr[1], note_seg_hdr->size);
1827 return I40E_SUCCESS;
1830 /* get i40e segment header info */
1831 if (type == RTE_PMD_I40E_PKG_INFO_HEADER) {
1832 struct rte_pmd_i40e_profile_info *info =
1833 (struct rte_pmd_i40e_profile_info *)info_buff;
1835 if (info_size < sizeof(struct rte_pmd_i40e_profile_info)) {
1836 PMD_DRV_LOG(ERR, "Output info buff size is invalid.");
1840 if (!metadata_seg_hdr) {
1841 PMD_DRV_LOG(ERR, "Failed to find metadata segment header");
1845 if (!i40e_seg_hdr) {
1846 PMD_DRV_LOG(ERR, "Failed to find i40e segment header");
1850 memset(info, 0, sizeof(struct rte_pmd_i40e_profile_info));
1851 info->owner = RTE_PMD_I40E_DDP_OWNER_UNKNOWN;
1853 ((struct i40e_metadata_segment *)metadata_seg_hdr)->track_id;
1856 ((struct i40e_profile_segment *)i40e_seg_hdr)->name,
1857 I40E_DDP_NAME_SIZE);
1858 memcpy(&info->version,
1859 &((struct i40e_profile_segment *)i40e_seg_hdr)->version,
1860 sizeof(struct i40e_ddp_version));
1861 return I40E_SUCCESS;
1864 /* get number of devices */
1865 if (type == RTE_PMD_I40E_PKG_INFO_DEVID_NUM) {
1866 if (info_size < sizeof(uint32_t)) {
1867 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1870 *(uint32_t *)info_buff =
1871 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table_count;
1872 return I40E_SUCCESS;
1875 /* get list of devices */
1876 if (type == RTE_PMD_I40E_PKG_INFO_DEVID_LIST) {
1879 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table_count;
1880 if (info_size < sizeof(struct rte_pmd_i40e_ddp_device_id) * dev_num) {
1881 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1885 ((struct i40e_profile_segment *)i40e_seg_hdr)->device_table,
1886 sizeof(struct rte_pmd_i40e_ddp_device_id) * dev_num);
1887 return I40E_SUCCESS;
1890 /* get number of protocols */
1891 if (type == RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM) {
1892 struct i40e_profile_section_header *proto;
1894 if (info_size < sizeof(uint32_t)) {
1895 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1898 proto = i40e_find_section_in_profile(SECTION_TYPE_PROTO,
1899 (struct i40e_profile_segment *)i40e_seg_hdr);
1900 *(uint32_t *)info_buff = i40e_get_tlv_section_size(proto);
1901 return I40E_SUCCESS;
1904 /* get list of protocols */
1905 if (type == RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST) {
1906 uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
1907 struct rte_pmd_i40e_proto_info *pinfo;
1908 struct i40e_profile_section_header *proto;
1909 struct i40e_profile_tlv_section_record *tlv;
1911 pinfo = (struct rte_pmd_i40e_proto_info *)info_buff;
1912 nb_proto_info = info_size /
1913 sizeof(struct rte_pmd_i40e_proto_info);
1914 for (i = 0; i < nb_proto_info; i++) {
1915 pinfo[i].proto_id = RTE_PMD_I40E_PROTO_UNUSED;
1916 memset(pinfo[i].name, 0, RTE_PMD_I40E_DDP_NAME_SIZE);
1918 proto = i40e_find_section_in_profile(SECTION_TYPE_PROTO,
1919 (struct i40e_profile_segment *)i40e_seg_hdr);
1920 nb_tlv = i40e_get_tlv_section_size(proto);
1922 return I40E_SUCCESS;
1923 if (nb_proto_info < nb_tlv) {
1924 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1927 /* get number of records in the section */
1928 nb_rec = proto->section.size /
1929 sizeof(struct i40e_profile_tlv_section_record);
1930 tlv = (struct i40e_profile_tlv_section_record *)&proto[1];
1931 for (i = j = 0; i < nb_rec; j++) {
1932 pinfo[j].proto_id = tlv->data[0];
1933 snprintf(pinfo[j].name, I40E_DDP_NAME_SIZE, "%s",
1934 (const char *)&tlv->data[1]);
1936 tlv = &tlv[tlv->len];
1938 return I40E_SUCCESS;
1941 /* get number of packet classification types */
1942 if (type == RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM) {
1943 struct i40e_profile_section_header *pctype;
1945 if (info_size < sizeof(uint32_t)) {
1946 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1949 pctype = i40e_find_section_in_profile(SECTION_TYPE_PCTYPE,
1950 (struct i40e_profile_segment *)i40e_seg_hdr);
1951 *(uint32_t *)info_buff = i40e_get_tlv_section_size(pctype);
1952 return I40E_SUCCESS;
1955 /* get list of packet classification types */
1956 if (type == RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST) {
1957 uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
1958 struct rte_pmd_i40e_ptype_info *pinfo;
1959 struct i40e_profile_section_header *pctype;
1960 struct i40e_profile_tlv_section_record *tlv;
1962 pinfo = (struct rte_pmd_i40e_ptype_info *)info_buff;
1963 nb_proto_info = info_size /
1964 sizeof(struct rte_pmd_i40e_ptype_info);
1965 for (i = 0; i < nb_proto_info; i++)
1966 memset(&pinfo[i], RTE_PMD_I40E_PROTO_UNUSED,
1967 sizeof(struct rte_pmd_i40e_ptype_info));
1968 pctype = i40e_find_section_in_profile(SECTION_TYPE_PCTYPE,
1969 (struct i40e_profile_segment *)i40e_seg_hdr);
1970 nb_tlv = i40e_get_tlv_section_size(pctype);
1972 return I40E_SUCCESS;
1973 if (nb_proto_info < nb_tlv) {
1974 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1978 /* get number of records in the section */
1979 nb_rec = pctype->section.size /
1980 sizeof(struct i40e_profile_tlv_section_record);
1981 tlv = (struct i40e_profile_tlv_section_record *)&pctype[1];
1982 for (i = j = 0; i < nb_rec; j++) {
1983 memcpy(&pinfo[j], tlv->data,
1984 sizeof(struct rte_pmd_i40e_ptype_info));
1986 tlv = &tlv[tlv->len];
1988 return I40E_SUCCESS;
1991 /* get number of packet types */
1992 if (type == RTE_PMD_I40E_PKG_INFO_PTYPE_NUM) {
1993 struct i40e_profile_section_header *ptype;
1995 if (info_size < sizeof(uint32_t)) {
1996 PMD_DRV_LOG(ERR, "Invalid information buffer size");
1999 ptype = i40e_find_section_in_profile(SECTION_TYPE_PTYPE,
2000 (struct i40e_profile_segment *)i40e_seg_hdr);
2001 *(uint32_t *)info_buff = i40e_get_tlv_section_size(ptype);
2002 return I40E_SUCCESS;
2005 /* get list of packet types */
2006 if (type == RTE_PMD_I40E_PKG_INFO_PTYPE_LIST) {
2007 uint32_t i, j, nb_tlv, nb_rec, nb_proto_info;
2008 struct rte_pmd_i40e_ptype_info *pinfo;
2009 struct i40e_profile_section_header *ptype;
2010 struct i40e_profile_tlv_section_record *tlv;
2012 pinfo = (struct rte_pmd_i40e_ptype_info *)info_buff;
2013 nb_proto_info = info_size /
2014 sizeof(struct rte_pmd_i40e_ptype_info);
2015 for (i = 0; i < nb_proto_info; i++)
2016 memset(&pinfo[i], RTE_PMD_I40E_PROTO_UNUSED,
2017 sizeof(struct rte_pmd_i40e_ptype_info));
2018 ptype = i40e_find_section_in_profile(SECTION_TYPE_PTYPE,
2019 (struct i40e_profile_segment *)i40e_seg_hdr);
2020 nb_tlv = i40e_get_tlv_section_size(ptype);
2022 return I40E_SUCCESS;
2023 if (nb_proto_info < nb_tlv) {
2024 PMD_DRV_LOG(ERR, "Invalid information buffer size");
2027 /* get number of records in the section */
2028 nb_rec = ptype->section.size /
2029 sizeof(struct i40e_profile_tlv_section_record);
2030 for (i = j = 0; i < nb_rec; j++) {
2031 tlv = (struct i40e_profile_tlv_section_record *)
2033 memcpy(&pinfo[j], tlv->data,
2034 sizeof(struct rte_pmd_i40e_ptype_info));
2037 return I40E_SUCCESS;
2040 PMD_DRV_LOG(ERR, "Info type %u is invalid.", type);
2045 rte_pmd_i40e_get_ddp_list(uint16_t port, uint8_t *buff, uint32_t size)
2047 struct rte_eth_dev *dev;
2049 enum i40e_status_code status = I40E_SUCCESS;
2051 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2053 dev = &rte_eth_devices[port];
2055 if (!is_i40e_supported(dev))
2058 if (size < (I40E_PROFILE_INFO_SIZE * I40E_MAX_PROFILE_NUM + 4))
2061 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2063 status = i40e_aq_get_ddp_list(hw, (void *)buff,
2069 static int check_invalid_pkt_type(uint32_t pkt_type)
2071 uint32_t l2, l3, l4, tnl, il2, il3, il4;
2073 l2 = pkt_type & RTE_PTYPE_L2_MASK;
2074 l3 = pkt_type & RTE_PTYPE_L3_MASK;
2075 l4 = pkt_type & RTE_PTYPE_L4_MASK;
2076 tnl = pkt_type & RTE_PTYPE_TUNNEL_MASK;
2077 il2 = pkt_type & RTE_PTYPE_INNER_L2_MASK;
2078 il3 = pkt_type & RTE_PTYPE_INNER_L3_MASK;
2079 il4 = pkt_type & RTE_PTYPE_INNER_L4_MASK;
2082 l2 != RTE_PTYPE_L2_ETHER &&
2083 l2 != RTE_PTYPE_L2_ETHER_TIMESYNC &&
2084 l2 != RTE_PTYPE_L2_ETHER_ARP &&
2085 l2 != RTE_PTYPE_L2_ETHER_LLDP &&
2086 l2 != RTE_PTYPE_L2_ETHER_NSH &&
2087 l2 != RTE_PTYPE_L2_ETHER_VLAN &&
2088 l2 != RTE_PTYPE_L2_ETHER_QINQ &&
2089 l2 != RTE_PTYPE_L2_ETHER_PPPOE)
2093 l3 != RTE_PTYPE_L3_IPV4 &&
2094 l3 != RTE_PTYPE_L3_IPV4_EXT &&
2095 l3 != RTE_PTYPE_L3_IPV6 &&
2096 l3 != RTE_PTYPE_L3_IPV4_EXT_UNKNOWN &&
2097 l3 != RTE_PTYPE_L3_IPV6_EXT &&
2098 l3 != RTE_PTYPE_L3_IPV6_EXT_UNKNOWN)
2102 l4 != RTE_PTYPE_L4_TCP &&
2103 l4 != RTE_PTYPE_L4_UDP &&
2104 l4 != RTE_PTYPE_L4_FRAG &&
2105 l4 != RTE_PTYPE_L4_SCTP &&
2106 l4 != RTE_PTYPE_L4_ICMP &&
2107 l4 != RTE_PTYPE_L4_NONFRAG)
2111 tnl != RTE_PTYPE_TUNNEL_IP &&
2112 tnl != RTE_PTYPE_TUNNEL_GRENAT &&
2113 tnl != RTE_PTYPE_TUNNEL_VXLAN &&
2114 tnl != RTE_PTYPE_TUNNEL_NVGRE &&
2115 tnl != RTE_PTYPE_TUNNEL_GENEVE &&
2116 tnl != RTE_PTYPE_TUNNEL_GRENAT &&
2117 tnl != RTE_PTYPE_TUNNEL_GTPC &&
2118 tnl != RTE_PTYPE_TUNNEL_GTPU &&
2119 tnl != RTE_PTYPE_TUNNEL_L2TP)
2123 il2 != RTE_PTYPE_INNER_L2_ETHER &&
2124 il2 != RTE_PTYPE_INNER_L2_ETHER_VLAN &&
2125 il2 != RTE_PTYPE_INNER_L2_ETHER_QINQ)
2129 il3 != RTE_PTYPE_INNER_L3_IPV4 &&
2130 il3 != RTE_PTYPE_INNER_L3_IPV4_EXT &&
2131 il3 != RTE_PTYPE_INNER_L3_IPV6 &&
2132 il3 != RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN &&
2133 il3 != RTE_PTYPE_INNER_L3_IPV6_EXT &&
2134 il3 != RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN)
2138 il4 != RTE_PTYPE_INNER_L4_TCP &&
2139 il4 != RTE_PTYPE_INNER_L4_UDP &&
2140 il4 != RTE_PTYPE_INNER_L4_FRAG &&
2141 il4 != RTE_PTYPE_INNER_L4_SCTP &&
2142 il4 != RTE_PTYPE_INNER_L4_ICMP &&
2143 il4 != RTE_PTYPE_INNER_L4_NONFRAG)
2149 static int check_invalid_ptype_mapping(
2150 struct rte_pmd_i40e_ptype_mapping *mapping_table,
2155 for (i = 0; i < count; i++) {
2156 uint16_t ptype = mapping_table[i].hw_ptype;
2157 uint32_t pkt_type = mapping_table[i].sw_ptype;
2159 if (ptype >= I40E_MAX_PKT_TYPE)
2162 if (pkt_type == RTE_PTYPE_UNKNOWN)
2165 if (pkt_type & RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK)
2168 if (check_invalid_pkt_type(pkt_type))
2176 rte_pmd_i40e_ptype_mapping_update(
2178 struct rte_pmd_i40e_ptype_mapping *mapping_items,
2182 struct rte_eth_dev *dev;
2183 struct i40e_adapter *ad;
2186 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2188 dev = &rte_eth_devices[port];
2190 if (!is_i40e_supported(dev))
2193 if (count > I40E_MAX_PKT_TYPE)
2196 if (check_invalid_ptype_mapping(mapping_items, count))
2199 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2202 for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
2203 ad->ptype_tbl[i] = RTE_PTYPE_UNKNOWN;
2206 for (i = 0; i < count; i++)
2207 ad->ptype_tbl[mapping_items[i].hw_ptype]
2208 = mapping_items[i].sw_ptype;
2213 int rte_pmd_i40e_ptype_mapping_reset(uint16_t port)
2215 struct rte_eth_dev *dev;
2217 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2219 dev = &rte_eth_devices[port];
2221 if (!is_i40e_supported(dev))
2224 i40e_set_default_ptype_table(dev);
2229 int rte_pmd_i40e_ptype_mapping_get(
2231 struct rte_pmd_i40e_ptype_mapping *mapping_items,
2236 struct rte_eth_dev *dev;
2237 struct i40e_adapter *ad;
2241 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2243 dev = &rte_eth_devices[port];
2245 if (!is_i40e_supported(dev))
2248 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2250 for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
2253 if (valid_only && ad->ptype_tbl[i] == RTE_PTYPE_UNKNOWN)
2255 mapping_items[n].hw_ptype = i;
2256 mapping_items[n].sw_ptype = ad->ptype_tbl[i];
2264 int rte_pmd_i40e_ptype_mapping_replace(uint16_t port,
2269 struct rte_eth_dev *dev;
2270 struct i40e_adapter *ad;
2273 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2275 dev = &rte_eth_devices[port];
2277 if (!is_i40e_supported(dev))
2280 if (!mask && check_invalid_pkt_type(target))
2283 if (check_invalid_pkt_type(pkt_type))
2286 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2288 for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
2290 if ((target | ad->ptype_tbl[i]) == target &&
2291 (target & ad->ptype_tbl[i]))
2292 ad->ptype_tbl[i] = pkt_type;
2294 if (ad->ptype_tbl[i] == target)
2295 ad->ptype_tbl[i] = pkt_type;
2303 rte_pmd_i40e_add_vf_mac_addr(uint16_t port, uint16_t vf_id,
2304 struct ether_addr *mac_addr)
2306 struct rte_eth_dev *dev;
2307 struct i40e_pf_vf *vf;
2308 struct i40e_vsi *vsi;
2310 struct i40e_mac_filter_info mac_filter;
2313 if (i40e_validate_mac_addr((u8 *)mac_addr) != I40E_SUCCESS)
2316 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2318 dev = &rte_eth_devices[port];
2320 if (!is_i40e_supported(dev))
2323 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2325 if (vf_id >= pf->vf_num || !pf->vfs)
2328 vf = &pf->vfs[vf_id];
2331 PMD_DRV_LOG(ERR, "Invalid VSI.");
2335 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
2336 ether_addr_copy(mac_addr, &mac_filter.mac_addr);
2337 ret = i40e_vsi_add_mac(vsi, &mac_filter);
2338 if (ret != I40E_SUCCESS) {
2339 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
2346 int rte_pmd_i40e_flow_type_mapping_reset(uint16_t port)
2348 struct rte_eth_dev *dev;
2350 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2352 dev = &rte_eth_devices[port];
2354 if (!is_i40e_supported(dev))
2357 i40e_set_default_pctype_table(dev);
2362 int rte_pmd_i40e_flow_type_mapping_get(
2364 struct rte_pmd_i40e_flow_type_mapping *mapping_items)
2366 struct rte_eth_dev *dev;
2367 struct i40e_adapter *ad;
2370 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2372 dev = &rte_eth_devices[port];
2374 if (!is_i40e_supported(dev))
2377 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2379 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
2380 mapping_items[i].flow_type = i;
2381 mapping_items[i].pctype = ad->pctypes_tbl[i];
2388 rte_pmd_i40e_flow_type_mapping_update(
2390 struct rte_pmd_i40e_flow_type_mapping *mapping_items,
2394 struct rte_eth_dev *dev;
2395 struct i40e_adapter *ad;
2398 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2400 dev = &rte_eth_devices[port];
2402 if (!is_i40e_supported(dev))
2405 if (count > I40E_FLOW_TYPE_MAX)
2408 for (i = 0; i < count; i++)
2409 if (mapping_items[i].flow_type >= I40E_FLOW_TYPE_MAX ||
2410 mapping_items[i].flow_type == RTE_ETH_FLOW_UNKNOWN ||
2411 (mapping_items[i].pctype &
2412 (1ULL << I40E_FILTER_PCTYPE_INVALID)))
2415 ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2418 for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
2419 ad->pctypes_tbl[i] = 0ULL;
2420 ad->flow_types_mask = 0ULL;
2423 for (i = 0; i < count; i++) {
2424 ad->pctypes_tbl[mapping_items[i].flow_type] =
2425 mapping_items[i].pctype;
2426 if (mapping_items[i].pctype)
2427 ad->flow_types_mask |=
2428 (1ULL << mapping_items[i].flow_type);
2430 ad->flow_types_mask &=
2431 ~(1ULL << mapping_items[i].flow_type);
2434 for (i = 0, ad->pctypes_mask = 0ULL; i < I40E_FLOW_TYPE_MAX; i++)
2435 ad->pctypes_mask |= ad->pctypes_tbl[i];
2441 rte_pmd_i40e_query_vfid_by_mac(uint16_t port, const struct ether_addr *vf_mac)
2443 struct rte_eth_dev *dev;
2444 struct ether_addr *mac;
2447 struct i40e_pf_vf *vf;
2450 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2451 dev = &rte_eth_devices[port];
2453 if (!is_i40e_supported(dev))
2456 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2457 vf_num = pf->vf_num;
2459 for (vf_id = 0; vf_id < vf_num; vf_id++) {
2460 vf = &pf->vfs[vf_id];
2461 mac = &vf->mac_addr;
2463 if (is_same_ether_addr(mac, vf_mac))
2471 i40e_vsi_update_queue_region_mapping(struct i40e_hw *hw,
2475 struct i40e_vsi *vsi = pf->main_vsi;
2476 uint16_t queue_offset, bsf, tc_index;
2477 struct i40e_vsi_context ctxt;
2478 struct i40e_aqc_vsi_properties_data *vsi_info;
2479 struct i40e_queue_regions *region_info =
2481 int32_t ret = -EINVAL;
2483 if (!region_info->queue_region_number) {
2484 PMD_INIT_LOG(ERR, "there is no that region id been set before");
2488 memset(&ctxt, 0, sizeof(struct i40e_vsi_context));
2490 /* Update Queue Pairs Mapping for currently enabled UPs */
2491 ctxt.seid = vsi->seid;
2492 ctxt.pf_num = hw->pf_id;
2494 ctxt.uplink_seid = vsi->uplink_seid;
2495 ctxt.info = vsi->info;
2496 vsi_info = &ctxt.info;
2498 memset(vsi_info->tc_mapping, 0, sizeof(uint16_t) * 8);
2499 memset(vsi_info->queue_mapping, 0, sizeof(uint16_t) * 16);
2501 /* Configure queue region and queue mapping parameters,
2502 * for enabled queue region, allocate queues to this region.
2505 for (i = 0; i < region_info->queue_region_number; i++) {
2506 tc_index = region_info->region[i].region_id;
2507 bsf = rte_bsf32(region_info->region[i].queue_num);
2508 queue_offset = region_info->region[i].queue_start_index;
2509 vsi_info->tc_mapping[tc_index] = rte_cpu_to_le_16(
2510 (queue_offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
2511 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
2514 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
2515 vsi_info->mapping_flags |=
2516 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
2517 vsi_info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
2518 vsi_info->valid_sections |=
2519 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
2521 /* Update the VSI after updating the VSI queue-mapping information */
2522 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
2524 PMD_DRV_LOG(ERR, "Failed to configure queue region mapping = %d ",
2525 hw->aq.asq_last_status);
2528 /* update the local VSI info with updated queue map */
2529 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
2530 sizeof(vsi->info.tc_mapping));
2531 rte_memcpy(&vsi->info.queue_mapping,
2532 &ctxt.info.queue_mapping,
2533 sizeof(vsi->info.queue_mapping));
2534 vsi->info.mapping_flags = ctxt.info.mapping_flags;
2535 vsi->info.valid_sections = 0;
2542 i40e_queue_region_set_region(struct i40e_pf *pf,
2543 struct rte_pmd_i40e_queue_region_conf *conf_ptr)
2546 struct i40e_vsi *main_vsi = pf->main_vsi;
2547 struct i40e_queue_regions *info = &pf->queue_region;
2548 int32_t ret = -EINVAL;
2550 if (!((rte_is_power_of_2(conf_ptr->queue_num)) &&
2551 conf_ptr->queue_num <= 64)) {
2552 PMD_DRV_LOG(ERR, "The region sizes should be any of the following values: 1, 2, 4, 8, 16, 32, 64 as long as the "
2553 "total number of queues do not exceed the VSI allocation");
2557 if (conf_ptr->region_id > I40E_REGION_MAX_INDEX) {
2558 PMD_DRV_LOG(ERR, "the queue region max index is 7");
2562 if ((conf_ptr->queue_start_index + conf_ptr->queue_num)
2563 > main_vsi->nb_used_qps) {
2564 PMD_DRV_LOG(ERR, "the queue index exceeds the VSI range");
2568 for (i = 0; i < info->queue_region_number; i++)
2569 if (conf_ptr->region_id == info->region[i].region_id)
2572 if (i == info->queue_region_number &&
2573 i <= I40E_REGION_MAX_INDEX) {
2574 info->region[i].region_id = conf_ptr->region_id;
2575 info->region[i].queue_num = conf_ptr->queue_num;
2576 info->region[i].queue_start_index =
2577 conf_ptr->queue_start_index;
2578 info->queue_region_number++;
2580 PMD_DRV_LOG(ERR, "queue region number exceeds maxnum 8 or the queue region id has been set before");
2588 i40e_queue_region_set_flowtype(struct i40e_pf *pf,
2589 struct rte_pmd_i40e_queue_region_conf *rss_region_conf)
2591 int32_t ret = -EINVAL;
2592 struct i40e_queue_regions *info = &pf->queue_region;
2594 uint16_t region_index, flowtype_index;
2596 /* For the pctype or hardware flowtype of packet,
2597 * the specific index for each type has been defined
2598 * in file i40e_type.h as enum i40e_filter_pctype.
2601 if (rss_region_conf->region_id > I40E_PFQF_HREGION_MAX_INDEX) {
2602 PMD_DRV_LOG(ERR, "the queue region max index is 7");
2606 if (rss_region_conf->hw_flowtype >= I40E_FILTER_PCTYPE_MAX) {
2607 PMD_DRV_LOG(ERR, "the hw_flowtype or PCTYPE max index is 63");
2612 for (i = 0; i < info->queue_region_number; i++)
2613 if (rss_region_conf->region_id == info->region[i].region_id)
2616 if (i == info->queue_region_number) {
2617 PMD_DRV_LOG(ERR, "that region id has not been set before");
2623 for (i = 0; i < info->queue_region_number; i++) {
2624 for (j = 0; j < info->region[i].flowtype_num; j++) {
2625 if (rss_region_conf->hw_flowtype ==
2626 info->region[i].hw_flowtype[j]) {
2627 PMD_DRV_LOG(ERR, "that hw_flowtype has been set before");
2633 flowtype_index = info->region[region_index].flowtype_num;
2634 info->region[region_index].hw_flowtype[flowtype_index] =
2635 rss_region_conf->hw_flowtype;
2636 info->region[region_index].flowtype_num++;
2642 i40e_queue_region_pf_flowtype_conf(struct i40e_hw *hw,
2645 uint8_t hw_flowtype;
2646 uint32_t pfqf_hregion;
2647 uint16_t i, j, index;
2648 struct i40e_queue_regions *info = &pf->queue_region;
2650 /* For the pctype or hardware flowtype of packet,
2651 * the specific index for each type has been defined
2652 * in file i40e_type.h as enum i40e_filter_pctype.
2655 for (i = 0; i < info->queue_region_number; i++) {
2656 for (j = 0; j < info->region[i].flowtype_num; j++) {
2657 hw_flowtype = info->region[i].hw_flowtype[j];
2658 index = hw_flowtype >> 3;
2660 i40e_read_rx_ctl(hw, I40E_PFQF_HREGION(index));
2662 if ((hw_flowtype & 0x7) == 0) {
2663 pfqf_hregion |= info->region[i].region_id <<
2664 I40E_PFQF_HREGION_REGION_0_SHIFT;
2665 pfqf_hregion |= 1 <<
2666 I40E_PFQF_HREGION_OVERRIDE_ENA_0_SHIFT;
2667 } else if ((hw_flowtype & 0x7) == 1) {
2668 pfqf_hregion |= info->region[i].region_id <<
2669 I40E_PFQF_HREGION_REGION_1_SHIFT;
2670 pfqf_hregion |= 1 <<
2671 I40E_PFQF_HREGION_OVERRIDE_ENA_1_SHIFT;
2672 } else if ((hw_flowtype & 0x7) == 2) {
2673 pfqf_hregion |= info->region[i].region_id <<
2674 I40E_PFQF_HREGION_REGION_2_SHIFT;
2675 pfqf_hregion |= 1 <<
2676 I40E_PFQF_HREGION_OVERRIDE_ENA_2_SHIFT;
2677 } else if ((hw_flowtype & 0x7) == 3) {
2678 pfqf_hregion |= info->region[i].region_id <<
2679 I40E_PFQF_HREGION_REGION_3_SHIFT;
2680 pfqf_hregion |= 1 <<
2681 I40E_PFQF_HREGION_OVERRIDE_ENA_3_SHIFT;
2682 } else if ((hw_flowtype & 0x7) == 4) {
2683 pfqf_hregion |= info->region[i].region_id <<
2684 I40E_PFQF_HREGION_REGION_4_SHIFT;
2685 pfqf_hregion |= 1 <<
2686 I40E_PFQF_HREGION_OVERRIDE_ENA_4_SHIFT;
2687 } else if ((hw_flowtype & 0x7) == 5) {
2688 pfqf_hregion |= info->region[i].region_id <<
2689 I40E_PFQF_HREGION_REGION_5_SHIFT;
2690 pfqf_hregion |= 1 <<
2691 I40E_PFQF_HREGION_OVERRIDE_ENA_5_SHIFT;
2692 } else if ((hw_flowtype & 0x7) == 6) {
2693 pfqf_hregion |= info->region[i].region_id <<
2694 I40E_PFQF_HREGION_REGION_6_SHIFT;
2695 pfqf_hregion |= 1 <<
2696 I40E_PFQF_HREGION_OVERRIDE_ENA_6_SHIFT;
2698 pfqf_hregion |= info->region[i].region_id <<
2699 I40E_PFQF_HREGION_REGION_7_SHIFT;
2700 pfqf_hregion |= 1 <<
2701 I40E_PFQF_HREGION_OVERRIDE_ENA_7_SHIFT;
2704 i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(index),
2711 i40e_queue_region_set_user_priority(struct i40e_pf *pf,
2712 struct rte_pmd_i40e_queue_region_conf *rss_region_conf)
2714 struct i40e_queue_regions *info = &pf->queue_region;
2715 int32_t ret = -EINVAL;
2716 uint16_t i, j, region_index;
2718 if (rss_region_conf->user_priority >= I40E_MAX_USER_PRIORITY) {
2719 PMD_DRV_LOG(ERR, "the queue region max index is 7");
2723 if (rss_region_conf->region_id > I40E_REGION_MAX_INDEX) {
2724 PMD_DRV_LOG(ERR, "the region_id max index is 7");
2728 for (i = 0; i < info->queue_region_number; i++)
2729 if (rss_region_conf->region_id == info->region[i].region_id)
2732 if (i == info->queue_region_number) {
2733 PMD_DRV_LOG(ERR, "that region id has not been set before");
2740 for (i = 0; i < info->queue_region_number; i++) {
2741 for (j = 0; j < info->region[i].user_priority_num; j++) {
2742 if (info->region[i].user_priority[j] ==
2743 rss_region_conf->user_priority) {
2744 PMD_DRV_LOG(ERR, "that user priority has been set before");
2750 j = info->region[region_index].user_priority_num;
2751 info->region[region_index].user_priority[j] =
2752 rss_region_conf->user_priority;
2753 info->region[region_index].user_priority_num++;
2759 i40e_queue_region_dcb_configure(struct i40e_hw *hw,
2762 struct i40e_dcbx_config dcb_cfg_local;
2763 struct i40e_dcbx_config *dcb_cfg;
2764 struct i40e_queue_regions *info = &pf->queue_region;
2765 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
2766 int32_t ret = -EINVAL;
2767 uint16_t i, j, prio_index, region_index;
2768 uint8_t tc_map, tc_bw, bw_lf;
2770 if (!info->queue_region_number) {
2771 PMD_DRV_LOG(ERR, "No queue region been set before");
2775 dcb_cfg = &dcb_cfg_local;
2776 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
2778 /* assume each tc has the same bw */
2779 tc_bw = I40E_MAX_PERCENT / info->queue_region_number;
2780 for (i = 0; i < info->queue_region_number; i++)
2781 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
2782 /* to ensure the sum of tcbw is equal to 100 */
2783 bw_lf = I40E_MAX_PERCENT % info->queue_region_number;
2784 for (i = 0; i < bw_lf; i++)
2785 dcb_cfg->etscfg.tcbwtable[i]++;
2787 /* assume each tc has the same Transmission Selection Algorithm */
2788 for (i = 0; i < info->queue_region_number; i++)
2789 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
2791 for (i = 0; i < info->queue_region_number; i++) {
2792 for (j = 0; j < info->region[i].user_priority_num; j++) {
2793 prio_index = info->region[i].user_priority[j];
2794 region_index = info->region[i].region_id;
2795 dcb_cfg->etscfg.prioritytable[prio_index] =
2800 /* FW needs one App to configure HW */
2801 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
2802 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
2803 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
2804 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
2806 tc_map = RTE_LEN2MASK(info->queue_region_number, uint8_t);
2808 dcb_cfg->pfc.willing = 0;
2809 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
2810 dcb_cfg->pfc.pfcenable = tc_map;
2812 /* Copy the new config to the current config */
2813 *old_cfg = *dcb_cfg;
2814 old_cfg->etsrec = old_cfg->etscfg;
2815 ret = i40e_set_dcb_config(hw);
2818 PMD_DRV_LOG(ERR, "Set queue region DCB Config failed, err %s aq_err %s",
2819 i40e_stat_str(hw, ret),
2820 i40e_aq_str(hw, hw->aq.asq_last_status));
2828 i40e_flush_queue_region_all_conf(struct rte_eth_dev *dev,
2829 struct i40e_hw *hw, struct i40e_pf *pf, uint16_t on)
2831 int32_t ret = -EINVAL;
2832 struct i40e_queue_regions *info = &pf->queue_region;
2833 struct i40e_vsi *main_vsi = pf->main_vsi;
2836 i40e_queue_region_pf_flowtype_conf(hw, pf);
2838 ret = i40e_vsi_update_queue_region_mapping(hw, pf);
2839 if (ret != I40E_SUCCESS) {
2840 PMD_DRV_LOG(INFO, "Failed to flush queue region mapping.");
2844 ret = i40e_queue_region_dcb_configure(hw, pf);
2845 if (ret != I40E_SUCCESS) {
2846 PMD_DRV_LOG(INFO, "Failed to flush dcb.");
2853 if (info->queue_region_number) {
2854 info->queue_region_number = 1;
2855 info->region[0].queue_num = main_vsi->nb_used_qps;
2856 info->region[0].queue_start_index = 0;
2858 ret = i40e_vsi_update_queue_region_mapping(hw, pf);
2859 if (ret != I40E_SUCCESS)
2860 PMD_DRV_LOG(INFO, "Failed to flush queue region mapping.");
2862 ret = i40e_dcb_init_configure(dev, TRUE);
2863 if (ret != I40E_SUCCESS) {
2864 PMD_DRV_LOG(INFO, "Failed to flush dcb.");
2865 pf->flags &= ~I40E_FLAG_DCB;
2868 i40e_init_queue_region_conf(dev);
2874 i40e_queue_region_pf_check_rss(struct i40e_pf *pf)
2876 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2879 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
2880 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
2889 i40e_queue_region_get_all_info(struct i40e_pf *pf,
2890 struct i40e_queue_regions *regions_ptr)
2892 struct i40e_queue_regions *info = &pf->queue_region;
2894 rte_memcpy(regions_ptr, info,
2895 sizeof(struct i40e_queue_regions));
2900 int rte_pmd_i40e_rss_queue_region_conf(uint16_t port_id,
2901 enum rte_pmd_i40e_queue_region_op op_type, void *arg)
2903 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2904 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2905 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2908 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2910 if (!is_i40e_supported(dev))
2913 if (!(!i40e_queue_region_pf_check_rss(pf)))
2916 /* This queue region feature only support pf by now. It should
2917 * be called after dev_start, and will be clear after dev_stop.
2918 * "RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON"
2919 * is just an enable function which server for other configuration,
2920 * it is for all configuration about queue region from up layer,
2921 * at first will only keep in DPDK softwarestored in driver,
2922 * only after "FLUSH_ON", it commit all configuration to HW.
2923 * Because PMD had to set hardware configuration at a time, so
2924 * it will record all up layer command at first.
2925 * "RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF" is
2926 * just clean all configuration about queue region just now,
2927 * and restore all to DPDK i40e driver default
2928 * config when start up.
2932 case RTE_PMD_I40E_RSS_QUEUE_REGION_SET:
2933 ret = i40e_queue_region_set_region(pf,
2934 (struct rte_pmd_i40e_queue_region_conf *)arg);
2936 case RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET:
2937 ret = i40e_queue_region_set_flowtype(pf,
2938 (struct rte_pmd_i40e_queue_region_conf *)arg);
2940 case RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET:
2941 ret = i40e_queue_region_set_user_priority(pf,
2942 (struct rte_pmd_i40e_queue_region_conf *)arg);
2944 case RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON:
2945 ret = i40e_flush_queue_region_all_conf(dev, hw, pf, 1);
2947 case RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF:
2948 ret = i40e_flush_queue_region_all_conf(dev, hw, pf, 0);
2950 case RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET:
2951 ret = i40e_queue_region_get_all_info(pf,
2952 (struct i40e_queue_regions *)arg);
2955 PMD_DRV_LOG(WARNING, "op type (%d) not supported",
2960 I40E_WRITE_FLUSH(hw);
2965 int rte_pmd_i40e_flow_add_del_packet_template(
2967 const struct rte_pmd_i40e_pkt_template_conf *conf,
2970 struct rte_eth_dev *dev = &rte_eth_devices[port];
2971 struct i40e_fdir_filter_conf filter_conf;
2973 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
2975 if (!is_i40e_supported(dev))
2978 memset(&filter_conf, 0, sizeof(filter_conf));
2979 filter_conf.soft_id = conf->soft_id;
2980 filter_conf.input.flow.raw_flow.pctype = conf->input.pctype;
2981 filter_conf.input.flow.raw_flow.packet = conf->input.packet;
2982 filter_conf.input.flow.raw_flow.length = conf->input.length;
2983 filter_conf.input.flow_ext.pkt_template = true;
2985 filter_conf.action.rx_queue = conf->action.rx_queue;
2986 filter_conf.action.behavior =
2987 (enum i40e_fdir_behavior)conf->action.behavior;
2988 filter_conf.action.report_status =
2989 (enum i40e_fdir_status)conf->action.report_status;
2990 filter_conf.action.flex_off = conf->action.flex_off;
2992 return i40e_flow_add_del_fdir_filter(dev, &filter_conf, add);
2996 rte_pmd_i40e_inset_get(uint16_t port, uint8_t pctype,
2997 struct rte_pmd_i40e_inset *inset,
2998 enum rte_pmd_i40e_inset_type inset_type)
3000 struct rte_eth_dev *dev;
3003 uint32_t mask_reg[2];
3006 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
3008 dev = &rte_eth_devices[port];
3010 if (!is_i40e_supported(dev))
3016 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3017 memset(inset, 0, sizeof(struct rte_pmd_i40e_inset));
3019 switch (inset_type) {
3023 i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
3024 inset_reg <<= I40E_32_BIT_WIDTH;
3026 i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
3027 /* Get field mask */
3029 i40e_read_rx_ctl(hw, I40E_GLQF_HASH_MSK(0, pctype));
3031 i40e_read_rx_ctl(hw, I40E_GLQF_HASH_MSK(1, pctype));
3035 i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
3036 inset_reg <<= I40E_32_BIT_WIDTH;
3038 i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
3040 i40e_read_rx_ctl(hw, I40E_GLQF_FD_MSK(0, pctype));
3042 i40e_read_rx_ctl(hw, I40E_GLQF_FD_MSK(1, pctype));
3044 case INSET_FDIR_FLX:
3046 i40e_read_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype));
3048 i40e_read_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, 0));
3050 i40e_read_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, 1));
3053 PMD_DRV_LOG(ERR, "Unsupported input set type.");
3057 inset->inset = inset_reg;
3059 for (i = 0; i < 2; i++) {
3060 inset->mask[i].field_idx = ((mask_reg[i] >> 16) & 0x3F);
3061 inset->mask[i].mask = mask_reg[i] & 0xFFFF;
3068 rte_pmd_i40e_inset_set(uint16_t port, uint8_t pctype,
3069 struct rte_pmd_i40e_inset *inset,
3070 enum rte_pmd_i40e_inset_type inset_type)
3072 struct rte_eth_dev *dev;
3076 uint32_t mask_reg[2];
3079 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
3081 dev = &rte_eth_devices[port];
3083 if (!is_i40e_supported(dev))
3089 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3090 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3092 if (pf->support_multi_driver) {
3093 PMD_DRV_LOG(ERR, "Input set configuration is not supported.");
3097 /* Clear mask first */
3098 for (i = 0; i < 2; i++)
3099 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype), 0);
3101 inset_reg = inset->inset;
3102 for (i = 0; i < 2; i++)
3103 mask_reg[i] = (inset->mask[i].field_idx << 16) |
3104 inset->mask[i].mask;
3106 switch (inset_type) {
3108 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
3109 (uint32_t)(inset_reg & UINT32_MAX));
3110 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
3111 (uint32_t)((inset_reg >>
3112 I40E_32_BIT_WIDTH) & UINT32_MAX));
3113 for (i = 0; i < 2; i++)
3114 i40e_check_write_global_reg(hw,
3115 I40E_GLQF_HASH_MSK(i, pctype),
3117 i40e_global_cfg_warning(I40E_WARNING_HASH_INSET);
3118 i40e_global_cfg_warning(I40E_WARNING_HASH_MSK);
3121 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
3122 (uint32_t)(inset_reg & UINT32_MAX));
3123 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
3124 (uint32_t)((inset_reg >>
3125 I40E_32_BIT_WIDTH) & UINT32_MAX));
3126 for (i = 0; i < 2; i++)
3127 i40e_check_write_global_reg(hw,
3128 I40E_GLQF_FD_MSK(i, pctype),
3130 i40e_global_cfg_warning(I40E_WARNING_FD_MSK);
3132 case INSET_FDIR_FLX:
3133 i40e_check_write_reg(hw, I40E_PRTQF_FD_FLXINSET(pctype),
3134 (uint32_t)(inset_reg & UINT32_MAX));
3135 for (i = 0; i < 2; i++)
3136 i40e_check_write_reg(hw, I40E_PRTQF_FD_MSK(pctype, i),
3140 PMD_DRV_LOG(ERR, "Unsupported input set type.");
3144 I40E_WRITE_FLUSH(hw);