diff mbox series

net: dsa: Inherit dev addr from master

Message ID 20190222125654.12478-1-vkoul@kernel.org
State New
Headers show
Series net: dsa: Inherit dev addr from master | expand

Commit Message

Vinod Koul Feb. 22, 2019, 12:56 p.m. UTC
From: Xiaofei Shen <xiaofeis@codeaurora.org>


When we create slave netdevice, the dev addr is inherited from master
but the master dev addr maybe NULL at that time, so inherit it again
while opening the slave.

Signed-off-by: Xiaofei Shen <xiaofeis@codeaurora.org>

Signed-off-by: Vinod Koul <vkoul@kernel.org>

---
 net/dsa/slave.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

-- 
2.20.1

Comments

xiaofeis Feb. 25, 2019, 1:13 p.m. UTC | #1
On 2019-02-22 22:30, Andrew Lunn wrote:
> On Fri, Feb 22, 2019 at 06:26:54PM +0530, Vinod Koul wrote:

>> From: Xiaofei Shen <xiaofeis@codeaurora.org>

>> 

>> When we create slave netdevice, the dev addr is inherited from master

>> but the master dev addr maybe NULL at that time, so inherit it again

>> while opening the slave.

> 

> Hi Xiaofei, Vinod

> 

> Inheriting it twice seems a bit clumsy. Can the first inherit be

> removed? Can you change your MAC driver to set its MAC address in

> probe?

> 

> 	Andrew

Hi Andrew

Some mac driver set its MAC address in probe while some MAC driver do it 
in the open function in the kernel.


This patch is checking whether the address is valid firstly, if it 
already inherits a valid mac address, it will not inherit again.

I think we can remove the first inherit, but if keep it, we can see 
consistent address output by ifconfig -a before open master and slave 
interface.

Xiaofeis
Andrew Lunn Feb. 25, 2019, 1:21 p.m. UTC | #2
> I think we can remove the first inherit, but if keep it, we can see

> consistent address output by ifconfig -a before open master and slave

> interface.


True

But it also means we see inconsistent MAC addresses on the master. The
MAC address changes on open.

Maybe it would be better to change your master so it sets its MAC
address during probe? Everything is then consistent all the time.

	Andrew
xiaofeis March 27, 2019, 4:09 a.m. UTC | #3
On 2019-02-25 21:21, Andrew Lunn wrote:
>> I think we can remove the first inherit, but if keep it, we can see

>> consistent address output by ifconfig -a before open master and slave

>> interface.

> 

> True

> 

> But it also means we see inconsistent MAC addresses on the master. The

> MAC address changes on open.

> 

> Maybe it would be better to change your master so it sets its MAC

> address during probe? Everything is then consistent all the time.

> 

> 	Andrew

I'm trying to suggest our master driver owner to set MAC address during 
probe.

I found in kernel, different driver has different implementation, some 
set it in probe, while
some in open. DSA should be generic to work with all these master 
drivers. I think this change
can help. Thanks.
diff mbox series

Patch

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 8e64c4e947c6..5f95c538b58c 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -77,7 +77,9 @@  static int dsa_slave_open(struct net_device *dev)
 	if (!(master->flags & IFF_UP))
 		return -ENETDOWN;
 
-	if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
+	if (!is_valid_ether_addr(dev->dev_addr)) {
+		eth_hw_addr_inherit(dev, master);
+	} else if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
 		err = dev_uc_add(master, dev->dev_addr);
 		if (err < 0)
 			goto out;