From: Vinod Koul <vkoul@kernel.org>
To: "David S. Miller" <davem@davemloft.net>
Cc: linux-arm-msm@vger.kernel.org,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Xiaofei Shen <xiaofeis@codeaurora.org>,
Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Niklas Cassel <niklas.cassel@linaro.org>,
netdev@vger.kernel.org, Vinod Koul <vkoul@kernel.org>
Subject: [PATCH] net: dsa: read mac address from DT for slave device
Date: Fri, 22 Feb 2019 18:28:15 +0530 [thread overview]
Message-ID: <20190222125815.12866-1-vkoul@kernel.org> (raw)
From: Xiaofei Shen <xiaofeis@codeaurora.org>
Before creating a slave netdevice, get the mac address from DTS and
apply in case it is valid.
Signed-off-by: Xiaofei Shen <xiaofeis@codeaurora.org>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
---
include/net/dsa.h | 1 +
net/dsa/dsa2.c | 1 +
net/dsa/slave.c | 5 ++++-
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index b3eefe8e18fd..aa24ce756679 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -198,6 +198,7 @@ struct dsa_port {
unsigned int index;
const char *name;
const struct dsa_port *cpu_dp;
+ const char *mac;
struct device_node *dn;
unsigned int ageing_time;
u8 stp_state;
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index a1917025e155..afb7d9fa42f6 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -261,6 +261,7 @@ static int dsa_port_setup(struct dsa_port *dp)
int err = 0;
memset(&dp->devlink_port, 0, sizeof(dp->devlink_port));
+ dp->mac = of_get_mac_address(dp->dn);
if (dp->type != DSA_PORT_TYPE_UNUSED)
err = devlink_port_register(ds->devlink, &dp->devlink_port,
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index a3fcc1d01615..8e64c4e947c6 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1308,7 +1308,10 @@ int dsa_slave_create(struct dsa_port *port)
slave_dev->features = master->vlan_features | NETIF_F_HW_TC;
slave_dev->hw_features |= NETIF_F_HW_TC;
slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
- eth_hw_addr_inherit(slave_dev, master);
+ if (port->mac && is_valid_ether_addr(port->mac))
+ ether_addr_copy(slave_dev->dev_addr, port->mac);
+ else
+ eth_hw_addr_inherit(slave_dev, master);
slave_dev->priv_flags |= IFF_NO_QUEUE;
slave_dev->netdev_ops = &dsa_slave_netdev_ops;
slave_dev->switchdev_ops = &dsa_slave_switchdev_ops;
--
2.20.1
next reply other threads:[~2019-02-22 12:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 12:58 Vinod Koul [this message]
2019-02-22 14:26 ` [PATCH] net: dsa: read mac address from DT for slave device Andrew Lunn
2019-03-04 3:46 ` xiaofeis
2019-03-04 7:31 ` Vinod Koul
2019-03-04 13:18 ` Andrew Lunn
2019-02-22 15:43 ` Florian Fainelli
2019-02-25 13:28 ` xiaofeis
2019-02-25 17:27 ` Florian Fainelli
2019-02-26 7:45 ` xiaofeis
2019-02-27 2:04 ` xiaofeis
2019-02-27 3:13 ` Florian Fainelli
2019-02-28 2:23 ` xiaofeis
2019-02-28 3:54 ` Florian Fainelli
2019-03-04 3:48 ` xiaofeis
2019-03-27 3:56 ` xiaofeis
2019-02-27 6:57 ` xiaofeis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190222125815.12866-1-vkoul@kernel.org \
--to=vkoul@kernel.org \
--cc=andrew@lunn.ch \
--cc=bjorn.andersson@linaro.org \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=niklas.cassel@linaro.org \
--cc=vivien.didelot@gmail.com \
--cc=xiaofeis@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).