net: dsa: various fixes
cover net: dsa: various fixes
Before a DSA port is probed, the master port needs to be probed first. For now this worked, because the probing order was correct. But it already falls short if you use the enetc6 port on the LS1028A SoC:
Device tree snippet:
&enetc6 {
status = "okay";
};&mscc_felix_port5 {
ethernet = <&enetc6>;
status = "okay";
};NB. keep enetc2 enabled, otherwise you will trigger an access violation.
Michael Walle (2):
net: dsa: return early if there is no master
net: dsa: probe master device
net/dsa-uclass.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
RFC PATCH 1/2 net: dsa: return early if there is no master
It doesn't make sense to have DSA without a master port. Error out early if there is no master port.
--- net/dsa-uclass.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/dsa-uclass.c +4 -4
@@ -280,6 +280,10 @@ static int dsa_port_probe(struct udevice *pdev)if (!port_pdata->phy)return -ENODEV ; + master =dsa_get_master (dev); +if (!master) +return -ENODEV ; +/* * Inherit port's hwaddr from the DSA master, unless the port already * has a unique MAC address specified in the environment.
@@ -288,10 +292,6 @@ static int dsa_port_probe(struct udevice *pdev)if (!is_zero_ethaddr (env_enetaddr))return 0 ; - master =dsa_get_master (dev); -if (!master) -return 0 ; - master_pdata =dev_get_plat (master); eth_pdata =dev_get_plat (pdev);memcpy (eth_pdata->enetaddr, master_pdata->enetaddr,ARP_HLEN );
Signature · 1 line
2.20.1
RFC PATCH 1/2 net: dsa: return early if there is no master
Quoted 6 lines · Michael Walle
It doesn't make sense to have DSA without a master port. Error out early if there is no master port.
Fixes fc054d563bfb ("net: Introduce DSA class for Ethernet switches")Signed-off-by Michael Walle <[email protected]>---
I think you can also be more aggressive and remove the checks:
if (!master) return -EINVAL;
from dsa_port_send and dsa_port_recv. At least it sounds broken to me that this could ever happen.
RFC PATCH 1/2 net: dsa: return early if there is no master
Am 2021-02-23 17:32, schrieb Vladimir Oltean:
Quoted 11 lines · Michael Walle
Quoted 7 lines
It doesn't make sense to have DSA without a master port. Error out early
if there is no master port.Fixes fc054d563bfb ("net: Introduce DSA class for Ethernet switches")Signed-off-by Michael Walle <[email protected]>---
Reviewed-by Vladimir Oltean <[email protected]>
Quoted 7 lines
I think you can also be more aggressive and remove the checks:
if (!master) return -EINVAL;from
dsa_port_sendanddsa_port_recv. At least it sounds broken to me that this could ever happen.
Yep, I've seen these, too. I'll send a non-RFC version and remove these.
-michael
RFC PATCH 1/2 net: dsa: return early if there is no master
In reply to Vladimir OlteanQuoted 8 lines
I think you can also be more aggressive and remove the checks:
if (!master) return -EINVAL;from
dsa_port_sendanddsa_port_recv. At least it sounds broken to me that this could ever happen.
The following comment got me curious:
/* * stop master only if it's active, don't probe it otherwise. * Under normal usage it would be active because we're using it, but * during tear-down it may have been removed ahead of us. */ if (master && device_active(master)) eth_get_ops(master)->stop(master);
Do we actually care about device removal? I don't think it will work right now.
If you do "unbind eth 0" and then using a DSA port you'll get a panic. The check for master doesn't really help here because it will return "priv->master_dev" which is just set in .pre_probe(). Thus in the error case, it will contain a dangling pointer.
-michael
RFC PATCH 2/2 net: dsa: probe master device
In reply to Michael WalleDSA needs to have the master device probed first for MAC inheritance. Until now, it only works by chance because the only user (LS1028A SoC) will probe the master device first. The probe order is given by the PCI device ordering, thus it works because the master device has a "smaller" BDF then the switch device.
Explicitly probe the master device in dsa_port_probe().
--- net/dsa-uclass.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/dsa-uclass.c +8 -0
@@ -284,6 +284,14 @@ static int dsa_port_probe(struct udevice *pdev)if (!master)return -ENODEV ; +/* +* Probe the master device. We depend on the master device for proper +* operation and we also need it for MAC inheritance below. +*/ + ret =device_probe (master); +if (ret) +return ret; +/* * Inherit port's hwaddr from the DSA master, unless the port already * has a unique MAC address specified in the environment.
Signature · 1 line
2.20.1
RFC PATCH 2/2 net: dsa: probe master device
Quoted 11 lines · Michael Walle
DSA needs to have the master device probed first for MAC inheritance. Until now, it only works by chance because the only user (LS1028A SoC) will probe the master device first. The probe order is given by the PCI device ordering, thus it works because the master device has a "smaller" BDF then the switch device.
Explicitly probe the master device in
dsa_port_probe().Fixes fc054d563bfb ("net: Introduce DSA class for Ethernet switches")Signed-off-by Michael Walle <[email protected]>---
By the way we had this in the old driver that marinated too much and never got merged, I am not sure why we removed it during the second submission process:
https://github.com/openil/u-boot/commit/2544ed8051d3dce55b12e13b6c2b476733d19c05
RFC PATCH 2/2 net: dsa: probe master device
In reply to Michael WalleAm 2021-02-23 17:19, schrieb Michael Walle:
Quoted 20 lines
DSA needs to have the master device probed first for MAC inheritance. Until now, it only works by chance because the only user (LS1028A SoC) will probe the master device first. The probe order is given by the PCI device ordering, thus it works because the master device has a "smaller"
BDF then the switch device.Explicitly probe the master device in
dsa_port_probe().Fixes fc054d563bfb ("net: Introduce DSA class for Ethernet switches")Signed-off-by Michael Walle <[email protected]>--- net/dsa-uclass.c | 8 ++++++++ 1 file changed, 8 insertions(+)net/dsa-uclass.c +0
-0
net/dsa-uclass.c static int dsa_port_probe(struct udevice *pdev) · line 291
Quoted 8 lines
net/dsa-uclass.c +5
-0@@ -284,6 +284,14 @@ static int dsa_port_probe(struct udevice *pdev)if (!master)return -ENODEV ; +/* +* Probe the master device. We depend on the master device for proper +* operation and we also need it for MAC inheritance below. +*/ + ret =device_probe (master);
btw, there is a "int ret" missing above. Will be fixed in the non-RFC version.
Quoted 6 lines
net/dsa-uclass.c +3
-0+if (ret) +return ret; +/* * Inherit port's hwaddr from the DSA master, unless the port already * has a unique MAC address specified in the environment.
Signature · 1 line
-michael