net: eth-uclass: ignore unavailable devices
PATCH 1/1 net: eth-uclass: ignore unavailable devices
device_probe() may fail in which case the seq_id will be -1. Don't display these devices during startup. While this is only a cosmetic change, the return value of eth_initialize() will also change to the actual number of available devices. The return value is only used in spl_net to decide whether there are any devices to boot from. So returning only available devices is also more correct in that case.
--- net/eth-uclass.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
net/eth-uclass.c +11 -6
@@ -420,20 +420,25 @@ int eth_initialize(void)bootstage_mark (BOOTSTAGE_ID_NET_ETH_INIT );do { -if (num_devices) -printf (", " ); +if (dev->seq !=-1 ) { +if (num_devices) +printf (", " ); -printf ("eth%d: %s" , dev->seq, dev->name); +printf ("eth%d: %s" , dev->seq, dev->name); -if (ethprime && dev == prime_dev) -printf (" [PRIME]" ); +if (ethprime && dev == prime_dev) +printf (" [PRIME]" ); + }eth_write_hwaddr (dev); +if (dev->seq !=-1 ) + num_devices++;uclass_next_device_check (&dev); - num_devices++; }while (dev); +if (!num_devices) +printf ("No ethernet found.\n" );putc ('\n' ); }
Signature · 1 line
2.20.1
PATCH 1/1 net: eth-uclass: ignore unavailable devices
Quoted 9 lines · Michael Walle
device_probe()may fail in which case theseq_idwill be -1. Don't display these devices during startup. While this is only a cosmetic change, the return value ofeth_initialize()will also change to the actual number of available devices. The return value is only used inspl_netto decide whether there are any devices to boot from. So returning only available devices is also more correct in that case.Signed-off-by Michael Walle <[email protected]>
PATCH 1/1 net: eth-uclass: ignore unavailable devices
In reply to Michael WalleHi Michael,
Quoted 39 lines · Michael Walle
device_probe()may fail in which case theseq_idwill be -1. Don't display these devices during startup. While this is only a cosmetic change, the return value ofeth_initialize()will also change to the actual number of available devices. The return value is only used inspl_netto decide whether there are any devices to boot from. So returning only available devices is also more correct in that case.Signed-off-by Michael Walle <[email protected]>--- net/eth-uclass.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)net/eth-uclass.c +8
-5@@ -420,20 +420,25 @@ int eth_initialize(void)bootstage_mark (BOOTSTAGE_ID_NET_ETH_INIT ); do { - if (num_devices) - printf(", "); + if (dev->seq != -1) { + if (num_devices) + printf(", "); - printf("eth%d: %s", dev->seq, dev->name); + printf("eth%d: %s", dev->seq, dev->name); - if (ethprime && dev == prime_dev) - printf(" [PRIME]"); + if (ethprime && dev == prime_dev) + printf(" [PRIME]"); + } eth_write_hwaddr(dev); + if (dev->seq != -1)
net/eth-uclass.c int eth_initialize(void) · line 444
Quoted 10 lines
net/eth-uclass.c +3
-1+ num_devices++;uclass_next_device_check (&dev); - num_devices++; }while (dev); +if (!num_devices) +printf ("No ethernet found.\n" );putc ('\n' ); }
What would you say about something like this instead? It's a bit more compact and should be functionally equivalent:
net/eth-uclass.c | 54 ++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 29 deletions(-)
net/eth-uclass.c +25 -29
@@ -390,10 +390,16 @@ int eth_rx(void)int eth_initialize (void ) { +struct udevice *dev, *prime_dev =NULL ; +char *ethprime =env_get ("ethprime" );int num_devices =0 ; -struct udevice *dev; +struct uclass *uc;eth_common_init (); +eth_set_dev (NULL ); + +if (ethprime) + prime_dev =eth_get_dev_by_name (ethprime);/* * Devices need to write the hwaddr even if not started so that Linux
@@ -401,40 +407,30 @@ int eth_initialize(void)* This is accomplished by attempting to probe each device and calling * their write_hwaddr() operation. */ -uclass_first_device_check (UCLASS_ETH , &dev); -if (!dev) { -printf ("No ethernet found.\n" ); -bootstage_error (BOOTSTAGE_ID_NET_ETH_START ); - }else { -char *ethprime =env_get ("ethprime" ); -struct udevice *prime_dev =NULL ; +uclass_get (UCLASS_ETH , &uc); + uclass_foreach_dev(dev, uc) { +if (device_probe (dev)) +continue ; + +eth_write_hwaddr (dev); + +if (num_devices) +printf (", " ); +printf ("eth%d: %s" , dev->seq, dev->name); -if (ethprime) - prime_dev =eth_get_dev_by_name (ethprime); -if (prime_dev) { +if (dev == prime_dev) {eth_set_dev (prime_dev);eth_current_changed (); - }else { -eth_set_dev (NULL ); +printf (" [PRIME]" ); } + num_devices++; + } +if (!num_devices) { +bootstage_error (BOOTSTAGE_ID_NET_ETH_START ); +printf ("No ethernet found.\n" ); + }else {bootstage_mark (BOOTSTAGE_ID_NET_ETH_INIT ); -do { -if (device_active (dev)) { -if (num_devices) -printf (", " ); - -printf ("eth%d: %s" , dev->seq, dev->name); - -if (ethprime && dev == prime_dev) -printf (" [PRIME]" ); -eth_write_hwaddr (dev); - } - -uclass_next_device_check (&dev); - num_devices++; - }while (dev); -putc ('\n' ); }
Alex
PATCH 1/1 net: eth-uclass: ignore unavailable devices
Am 2019-12-01 01:55, schrieb Alexandru Marginean:
Quoted 40 lines
Hi Michael,
Quoted 37 lines · Michael Walle
device_probe()may fail in which case theseq_idwill be -1. Don't display these devices during startup. While this is only a cosmetic change, the return value ofeth_initialize()will also change to the actual number of available devices. The return value is only used inspl_netto decide whether there are any devices to boot from. So returning only available devices is also more correct in that case.Signed-off-by Michael Walle <[email protected]>--- net/eth-uclass.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)net/eth-uclass.c +8
-4@@ -420,20 +420,25 @@ int eth_initialize(void)bootstage_mark (BOOTSTAGE_ID_NET_ETH_INIT );do { -if (num_devices) -printf (", " ); +if (dev->seq !=-1 ) { +if (num_devices) +printf (", " ); -printf ("eth%d: %s" , dev->seq, dev->name); +printf ("eth%d: %s" , dev->seq, dev->name); - if (ethprime && dev == prime_dev) -printf (" [PRIME]" ); +if (ethprime && dev == prime_dev) +printf (" [PRIME]" ); + }eth_write_hwaddr (dev); + if (dev->seq != -1) + num_devices++;uclass_next_device_check (&dev); - num_devices++; }while (dev);
Quoted 8 lines
net/eth-uclass.c int eth_initialize(void) · line 436
Quoted 5 lines
net/eth-uclass.c +1
-0+ if (!num_devices) +printf ("No ethernet found.\n" );putc ('\n' ); }What would you say about something like this instead? It's a bit more compact and should be functionally equivalent:
sure, but I've noticed that this is only part of the fix (or isn't even necessary). At least, it doesn't work if the first device is unavailable,
because eth_get_dev() will then fail. You should be able to reproduce the issue if you disable the first enetc of the LS1028A. Then network should only work if ethact is set.
I've traced that back to the pci enumeration which doesn't respect the 'status = "disabled"' property. But instead someone added that check to the enetc driver, but that doesn't really work, because the device is already included in the uclass list. See separate patch, I'll send in a minute.
-michael
Quoted 87 lines
net/eth-uclass.c | 54 ++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 29 deletions(-)net/eth-uclass.c +7
-1@@ -390,10 +390,16 @@ int eth_rx(void)int eth_initialize (void ) { +struct udevice *dev, *prime_dev =NULL ; +char *ethprime =env_get ("ethprime" );int num_devices =0 ; -struct udevice *dev; +struct uclass *uc;eth_common_init (); +eth_set_dev (NULL ); + +if (ethprime) + prime_dev =eth_get_dev_by_name (ethprime);/* * Devices need to write the hwaddr even if not started so that Linux @@ -401,40 +407,30 @@ int eth_initialize(void)* This is accomplished by attempting to probe each device and calling
net/eth-uclass.c +18
-28* their write_hwaddr() operation. */ -uclass_first_device_check (UCLASS_ETH , &dev); -if (!dev) { -printf ("No ethernet found.\n" ); -bootstage_error (BOOTSTAGE_ID_NET_ETH_START ); - }else { -char *ethprime =env_get ("ethprime" ); -struct udevice *prime_dev =NULL ; +uclass_get (UCLASS_ETH , &uc); + uclass_foreach_dev(dev, uc) { +if (device_probe (dev)) +continue ; + +eth_write_hwaddr (dev); + +if (num_devices) +printf (", " ); +printf ("eth%d: %s" , dev->seq, dev->name); -if (ethprime) - prime_dev =eth_get_dev_by_name (ethprime); -if (prime_dev) { +if (dev == prime_dev) {eth_set_dev (prime_dev);eth_current_changed (); - }else { -eth_set_dev (NULL ); +printf (" [PRIME]" ); } + num_devices++; + } +if (!num_devices) { +bootstage_error (BOOTSTAGE_ID_NET_ETH_START ); +printf ("No ethernet found.\n" ); + }else {bootstage_mark (BOOTSTAGE_ID_NET_ETH_INIT ); -do { -if (device_active (dev)) { -if (num_devices) -printf (", " ); - -printf ("eth%d: %s" , dev->seq, dev->name); - -if (ethprime && dev == prime_dev) -printf (" [PRIME]" ); -eth_write_hwaddr (dev); - } - -uclass_next_device_check (&dev); - num_devices++; - }while (dev); -putc ('\n' ); }Alex
PATCH 1/1 net: eth-uclass: ignore unavailable devices
Quoted 56 lines · Michael Walle
Am 2019-12-01 01:55, schrieb Alexandru Marginean:
Quoted 40 lines
Hi Michael,
Quoted 37 lines · Michael Walle
device_probe()may fail in which case theseq_idwill be -1. Don't display these devices during startup. While this is only a cosmetic change, the return value ofeth_initialize()will also change to the actual number of available devices. The return value is only used inspl_netto decide whether there are any devices to boot from. So returning only available devices is also more correct in that case.Signed-off-by Michael Walle <[email protected]>---
net/eth-uclass.c| 17 +++++++++++------1 file changed, 11 insertions(+), 6 deletions(-)net/eth-uclass.c +8
-4@@ -420,20 +420,25 @@ int eth_initialize(void) bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT); do { - if (num_devices) - printf(", "); + if (dev->seq != -1) { + if (num_devices) + printf(", "); - printf("eth%d: %s", dev->seq, dev->name); + printf("eth%d: %s", dev->seq, dev->name); - if (ethprime && dev == prime_dev) - printf(" [PRIME]"); + if (ethprime && dev == prime_dev) + printf(" [PRIME]"); + } eth_write_hwaddr(dev); + if (dev->seq != -1) + num_devices++; uclass_next_device_check(&dev); - num_devices++; } while (dev);Quoted 8 lines
net/eth-uclass.c int eth_initialize(void) · line 440
Quoted 5 lines
net/eth-uclass.c +1
-0+ if (!num_devices) + printf("No ethernet found.\n"); putc('\n'); }What would you say about something like this instead? It's a bit more compact and should be functionally equivalent:
sure, but I've noticed that this is only part of the fix (or isn't even necessary). At least, it doesn't work if the first device is unavailable, because
eth_get_dev()will then fail. You should be able to reproduce the issue if you disable the first enetc of the LS1028A. Then network should only work if ethact is set.
Quoted 7 lines
I've traced that back to the pci enumeration which doesn't respect the 'status = "disabled"' property. But instead someone added that check to the enetc driver, but that doesn't really work, because the device is already included in the uclass list. See separate patch, I'll send in a minute.
-michael
For disabled nodes the pci_find_and_bind_driver patch is sufficient. We should probably deal with drivers failing to probe for other reasons too, there could be other legitimate reasons for that to happen.
how about the eth_initialize patch plus:
net/eth-uclass.c +2 -2
@@ -69,8 +69,8 @@ struct udevice *eth_get_dev(void) uc_priv =eth_get_uclass_priv ();if (!uc_priv->current) - eth_errno =uclass_first_device (UCLASS_ETH , - &uc_priv->current); +uclass_get_device_by_seq (UCLASS_ETH ,0 , &uc_priv->current); +return uc_priv->current; }
Since seq == -1 on devices that fail to probe this code will ignore them.
Or add uclass helpers that only deal with devices that probe
successfully: uclass_get_first_device_active, uclass_get_next_device_active and uclass_foreach_dev_active.
Alex
Quoted 89 lines
Quoted 89 lines
net/eth-uclass.c | 54 ++++++++++++++++++++++--------------------------
1 file changed, 25 insertions(+), 29 deletions(-)net/eth-uclass.c +7
-1@@ -390,10 +390,16 @@ int eth_rx(void) int eth_initialize(void) { + struct udevice *dev, *prime_dev = NULL; + char *ethprime = env_get("ethprime"); int num_devices = 0; - struct udevice *dev; + struct uclass *uc; eth_common_init(); + eth_set_dev(NULL); + + if (ethprime) + prime_dev = eth_get_dev_by_name(ethprime); /** Devices need to write the hwaddr even if not started so that Linux
net/eth-uclass.c +0
-0@@ -401,40 +407,30 @@ int eth_initialize(void) * This is accomplished by attempting to probe each device andcalling
* theirwrite_hwaddr()operation.
*/
-uclass_first_device_check(UCLASS_ETH, &dev); - if (!dev) {
-printf("No ethernet found.\n");
-bootstage_error(BOOTSTAGE_ID_NET_ETH_START); - } else {
- char *ethprime =env_get("ethprime"); - struct udevice*prime_dev= NULL;
+uclass_get(UCLASS_ETH, &uc);
+uclass_foreach_dev(dev, uc){
+ if (device_probe(dev))
+ continue;net/eth-uclass.c +7
-3+ + eth_write_hwaddr(dev); + + if (num_devices) + printf(", "); + printf("eth%d: %s", dev->seq, dev->name); - if (ethprime) - prime_dev = eth_get_dev_by_name(ethprime); - if (prime_dev) { + if (dev == prime_dev) {
eth_set_dev(prime_dev);
eth_current_changed();
- } else {
-eth_set_dev(NULL);
+printf(" [PRIME]");
}
+ num_devices++;
+ }+ if (!num_devices) {
+bootstage_error(BOOTSTAGE_ID_NET_ETH_START); +printf("No ethernet found.\n");
+ } else {bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT); - do {
- if (device_active(dev)) {
- if (num_devices)
-printf(", ");net/eth-uclass.c +0
-12- - printf("eth%d: %s", dev->seq, dev->name); - - if (ethprime && dev == prime_dev) - printf(" [PRIME]"); - eth_write_hwaddr(dev); - } - - uclass_next_device_check(&dev); - num_devices++; - } while (dev); -putc('\n');
}Alex