Tested-by: Aliaksei Belovus <[email protected]>

Comments from submitter in Bugzilla-1897

"This fix works at startup. The only thing that bothers me is the 
iavf_add_del_all_mac_addr method, which has no error handling and doesn't take 
its result into account when setting the mac_primary_set flag.
But for me this fix is totally good. And my problem was fixed."


> -----Original Message-----
> From: Mandal, Anurag <[email protected]>
> Sent: 04 March 2026 16:46
> To: [email protected]
> Cc: Richardson, Bruce <[email protected]>; Medvedkin, Vladimir
> <[email protected]>; [email protected]; Mandal,
> Anurag <[email protected]>; [email protected]
> Subject: [PATCH] net/iavf: fix old primary MAC deletion
> 
> Old Primary MAC removal operation fails while trying to set the default MAC
> address on a VF via rte_eth_dev_default_mac_addr_set()
> when VF is yet to be started post initialization.
> This happens due to non-assignment of the old MAC as
> VIRTCHNL_ETHER_ADDR_PRIMARY MAC on the VF as it did not invoke
> iavf_dev_start() yet to do the same post initialization.
> Logs indicate old primary MAC removal failure even though
> rte_eth_dev_default_mac_addr_set() returns success causing ambiguity.
> 
> This patch fixes the issue by introducing the flag "mac_primary_set"
> in the iavf_adapter & is set to 'false' upon VF initialization.
> It is set to 'true' when any MAC address gets assigned as
> VIRTCHNL_ETHER_ADDR_PRIMARY MAC on the VF. This flags gets enabled
> only once for a VF.
> 
> Bugzilla ID: 1897
> Fixes: b335e7203475 ("net/iavf: fix lack of MAC type when set MAC address")
> Cc: [email protected]
> 
> Signed-off-by: Anurag Mandal <[email protected]>
> ---
>  drivers/net/intel/iavf/iavf.h        |  1 +
>  drivers/net/intel/iavf/iavf_ethdev.c | 19 ++++++++++++++-----
>  2 files changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/intel/iavf/iavf.h b/drivers/net/intel/iavf/iavf.h 
> index
> 33ba3115d0..f7f3522d6b 100644
> --- a/drivers/net/intel/iavf/iavf.h
> +++ b/drivers/net/intel/iavf/iavf.h
> @@ -383,6 +383,7 @@ struct iavf_adapter {
>       enum iavf_tx_func_type tx_func_type;
>       uint16_t fdir_ref_cnt;
>       struct iavf_devargs devargs;
> +     bool mac_primary_set;
>  };
> 
>  /* IAVF_DEV_PRIVATE_TO */
> diff --git a/drivers/net/intel/iavf/iavf_ethdev.c
> b/drivers/net/intel/iavf/iavf_ethdev.c
> index c1160c8967..7da92bd31e 100644
> --- a/drivers/net/intel/iavf/iavf_ethdev.c
> +++ b/drivers/net/intel/iavf/iavf_ethdev.c
> @@ -1042,6 +1042,9 @@ iavf_dev_start(struct rte_eth_dev *dev)
>       /* Set all mac addrs */
>       iavf_add_del_all_mac_addr(adapter, true);
> 
> +     if (!adapter->mac_primary_set)
> +             adapter->mac_primary_set = true;
> +
>       /* Set all multicast addresses */
>       iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf-
> >mc_addrs_num,
>                                 true);
> @@ -1718,11 +1721,13 @@ iavf_dev_set_default_mac_addr(struct
> rte_eth_dev *dev,
>       if (rte_is_same_ether_addr(old_addr, mac_addr))
>               return 0;
> 
> -     ret = iavf_add_del_eth_addr(adapter, old_addr, false,
> VIRTCHNL_ETHER_ADDR_PRIMARY);
> -     if (ret)
> -             PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
> -                         RTE_ETHER_ADDR_PRT_FMT,
> -                             RTE_ETHER_ADDR_BYTES(old_addr));
> +     if (adapter->mac_primary_set) {  /* delete old PRIMARY MAC only if
> set */
> +             ret = iavf_add_del_eth_addr(adapter, old_addr, false,
> VIRTCHNL_ETHER_ADDR_PRIMARY);
> +             if (ret)
> +                     PMD_DRV_LOG(ERR, "Fail to delete old MAC:"
> +                                 RTE_ETHER_ADDR_PRT_FMT,
> +                                     RTE_ETHER_ADDR_BYTES(old_addr));
> +     }
> 
>       ret = iavf_add_del_eth_addr(adapter, mac_addr, true,
> VIRTCHNL_ETHER_ADDR_PRIMARY);
>       if (ret)
> @@ -1733,6 +1738,9 @@ iavf_dev_set_default_mac_addr(struct rte_eth_dev
> *dev,
>       if (ret)
>               return -EIO;
> 
> +     if (!adapter->mac_primary_set)
> +             adapter->mac_primary_set = true;
> +
>       rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)hw-
> >mac.addr);
>       return 0;
>  }
> @@ -2789,6 +2797,7 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
>       hw->back = IAVF_DEV_PRIVATE_TO_ADAPTER(eth_dev->data-
> >dev_private);
>       adapter->dev_data = eth_dev->data;
>       adapter->stopped = 1;
> +     adapter->mac_primary_set = false;
> 
>       if (iavf_dev_event_handler_init())
>               goto init_vf_err;
> --
> 2.34.1

Reply via email to