diff mbox series

[iwl-next,v4,1/2] iavf: add check for current MAC address in set_mac callback

Message ID 20230519150029.370332-2-piotrx.gardocki@intel.com
State Changes Requested
Delegated to: Anthony Nguyen
Headers show
Series iavf: clean up procedure for changing interface's MAC address | expand

Commit Message

Piotr Gardocki May 19, 2023, 3 p.m. UTC
In some cases it is possible for kernel to come with request
to change primary MAC address to the address that is actually
already set on the given interface.

If the old and new MAC addresses are equal there is no need
for going through entire routine, including AdminQ and
waitqueue.

This patch adds proper check to return fast from the function
in these cases. The same check can also be found in i40e and
ice drivers.

An example of such case is adding an interface to bonding
channel in balance-alb mode:
modprobe bonding mode=balance-alb miimon=100 max_bonds=1
ip link set bond0 up
ifenslave bond0 <eth>

Signed-off-by: Piotr Gardocki <piotrx.gardocki@intel.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Romanowski, Rafal May 26, 2023, 8:25 a.m. UTC | #1
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of Piotr
> Gardocki
> Sent: piÄ…tek, 19 maja 2023 17:00
> To: intel-wired-lan@lists.osuosl.org
> Cc: Kitszel, Przemyslaw <przemyslaw.kitszel@intel.com>;
> pmenzel@molgen.mpg.de
> Subject: [Intel-wired-lan] [PATCH iwl-next v4 1/2] iavf: add check for current
> MAC address in set_mac callback
> 
> In some cases it is possible for kernel to come with request to change primary
> MAC address to the address that is actually already set on the given interface.
> 
> If the old and new MAC addresses are equal there is no need for going through
> entire routine, including AdminQ and waitqueue.
> 
> This patch adds proper check to return fast from the function in these cases.
> The same check can also be found in i40e and ice drivers.
> 
> An example of such case is adding an interface to bonding channel in balance-
> alb mode:
> modprobe bonding mode=balance-alb miimon=100 max_bonds=1 ip link set
> bond0 up ifenslave bond0 <eth>
> 
> Signed-off-by: Piotr Gardocki <piotrx.gardocki@intel.com>
> Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> ---
>  drivers/net/ethernet/intel/iavf/iavf_main.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c
> b/drivers/net/ethernet/intel/iavf/iavf_main.c
> index e18d7cacf99c..888d063478a1 100644
> --- a/drivers/net/ethernet/intel/iavf/iavf_main.c
> +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
> @@ -1085,6 +1085,12 @@ static int iavf_set_mac(struct net_device *netdev,
> void *p)
>  	if (!is_valid_ether_addr(addr->sa_data))
>  		return -EADDRNOTAVAIL;
> 
> +	if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
> +		netdev_dbg(netdev, "already using mac address %pM\n",
> +			   addr->sa_data);
> +		return 0;
> +	}
> +
>  	ret = iavf_replace_primary_mac(adapter, addr->sa_data);
> 
>  	if (ret)
> --
> 2.34.1
> 
> _______________________________________________
> Intel-wired-lan mailing list
> Intel-wired-lan@osuosl.org
> https://lists.osuosl.org/mailman/listinfo/intel-wired-lan


Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index e18d7cacf99c..888d063478a1 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -1085,6 +1085,12 @@  static int iavf_set_mac(struct net_device *netdev, void *p)
 	if (!is_valid_ether_addr(addr->sa_data))
 		return -EADDRNOTAVAIL;
 
+	if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
+		netdev_dbg(netdev, "already using mac address %pM\n",
+			   addr->sa_data);
+		return 0;
+	}
+
 	ret = iavf_replace_primary_mac(adapter, addr->sa_data);
 
 	if (ret)