Skip to content

Commit a2c7023

Browse files
Xiaofei Shendavem330
Xiaofei Shen
authored andcommitted
net: dsa: read mac address from DT for slave device
Before creating a slave netdevice, get the mac address from DTS and apply in case it is valid. Signed-off-by: Xiaofei Shen <[email protected]> Signed-off-by: Vinod Koul <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f5d5476 commit a2c7023

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

include/net/dsa.h

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct dsa_port {
140140
unsigned int index;
141141
const char *name;
142142
const struct dsa_port *cpu_dp;
143+
const char *mac;
143144
struct device_node *dn;
144145
unsigned int ageing_time;
145146
u8 stp_state;

net/dsa/dsa2.c

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ static int dsa_port_setup(struct dsa_port *dp)
266266
return 0;
267267

268268
memset(&dp->devlink_port, 0, sizeof(dp->devlink_port));
269+
dp->mac = of_get_mac_address(dp->dn);
269270

270271
switch (dp->type) {
271272
case DSA_PORT_TYPE_CPU:

net/dsa/slave.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,10 @@ int dsa_slave_create(struct dsa_port *port)
13931393
NETIF_F_HW_VLAN_CTAG_FILTER;
13941394
slave_dev->hw_features |= NETIF_F_HW_TC;
13951395
slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
1396-
eth_hw_addr_inherit(slave_dev, master);
1396+
if (port->mac && is_valid_ether_addr(port->mac))
1397+
ether_addr_copy(slave_dev->dev_addr, port->mac);
1398+
else
1399+
eth_hw_addr_inherit(slave_dev, master);
13971400
slave_dev->priv_flags |= IFF_NO_QUEUE;
13981401
slave_dev->netdev_ops = &dsa_slave_netdev_ops;
13991402
slave_dev->min_mtu = 0;

0 commit comments

Comments
 (0)