summaryrefslogtreecommitdiff
path: root/net/dsa-uclass.c
diff options
context:
space:
mode:
authorVladimir Oltean <vladimir.oltean@nxp.com>2021-08-24 15:00:40 +0300
committerRamon Fried <rfried.dev@gmail.com>2021-09-28 18:50:55 +0300
commit5eee5ab91638c4482dd59ff511feefd3b15a2472 (patch)
tree50d3b6425db68c3a5c923407238391b612f6c5f2 /net/dsa-uclass.c
parentf4b712b840dd5fe0b984aadfe466c1886a31e906 (diff)
downloadu-boot-5eee5ab91638c4482dd59ff511feefd3b15a2472.tar.gz
u-boot-5eee5ab91638c4482dd59ff511feefd3b15a2472.tar.bz2
u-boot-5eee5ab91638c4482dd59ff511feefd3b15a2472.zip
net: dsa: refactor the code to set the port MAC address into a dedicated function
This snippet of code has a bothering "if (...) return 0" in it which assumes it is the last piece of code running in dsa_port_probe(). This makes it difficult to add further code at the end of dsa_port_probe() which does not depend on MAC address stuff. So move the code to a dedicated function which returns void and let the code flow through. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Ramon Fried <rfried.dev@gmail.com> Tested-by: Michael Walle <michael@walle.cc>
Diffstat (limited to 'net/dsa-uclass.c')
-rw-r--r--net/dsa-uclass.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index f279ca7d2d..dbd8558b64 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -240,11 +240,36 @@ static const struct eth_ops dsa_port_ops = {
.free_pkt = dsa_port_free_pkt,
};
-static int dsa_port_probe(struct udevice *pdev)
+/*
+ * Inherit port's hwaddr from the DSA master, unless the port already has a
+ * unique MAC address specified in the environment.
+ */
+static void dsa_port_set_hwaddr(struct udevice *pdev, struct udevice *master)
{
- struct udevice *dev = dev_get_parent(pdev);
struct eth_pdata *eth_pdata, *master_pdata;
unsigned char env_enetaddr[ARP_HLEN];
+
+ eth_env_get_enetaddr_by_index("eth", dev_seq(pdev), env_enetaddr);
+ if (!is_zero_ethaddr(env_enetaddr)) {
+ /* individual port mac addrs require master to be promisc */
+ struct eth_ops *eth_ops = eth_get_ops(master);
+
+ if (eth_ops->set_promisc)
+ eth_ops->set_promisc(master, 1);
+
+ return;
+ }
+
+ master_pdata = dev_get_plat(master);
+ eth_pdata = dev_get_plat(pdev);
+ memcpy(eth_pdata->enetaddr, master_pdata->enetaddr, ARP_HLEN);
+ eth_env_set_enetaddr_by_index("eth", dev_seq(pdev),
+ master_pdata->enetaddr);
+}
+
+static int dsa_port_probe(struct udevice *pdev)
+{
+ struct udevice *dev = dev_get_parent(pdev);
struct dsa_port_pdata *port_pdata;
struct dsa_priv *dsa_priv;
struct udevice *master;
@@ -272,26 +297,7 @@ static int dsa_port_probe(struct udevice *pdev)
if (err)
return err;
- /*
- * Inherit port's hwaddr from the DSA master, unless the port already
- * has a unique MAC address specified in the environment.
- */
- eth_env_get_enetaddr_by_index("eth", dev_seq(pdev), env_enetaddr);
- if (!is_zero_ethaddr(env_enetaddr)) {
- /* individual port mac addrs require master to be promisc */
- struct eth_ops *eth_ops = eth_get_ops(master);
-
- if (eth_ops->set_promisc)
- eth_ops->set_promisc(master, 1);
-
- return 0;
- }
-
- master_pdata = dev_get_plat(master);
- eth_pdata = dev_get_plat(pdev);
- memcpy(eth_pdata->enetaddr, master_pdata->enetaddr, ARP_HLEN);
- eth_env_set_enetaddr_by_index("eth", dev_seq(pdev),
- master_pdata->enetaddr);
+ dsa_port_set_hwaddr(pdev, master);
return 0;
}