net: use a more deterministic approach to get the active ethernet device
PATCH 1/1 net: use a more deterministic approach to get the active ethernet device
If the environment variable "ethact" is not set, the first device in the uclass is returned. This depends on the probing order of the ethernet devices. Moreover it is not not configurable at all.
Try to return the ethernet device with sequence id 0 first which then can be configured by the aliases in a device tree. Fall back to the old mechanism in case of an error.
--- net/eth-uclass.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
net/eth-uclass.c +12 -5
@@ -69,8 +69,11 @@ void eth_set_current_to_next(void)/* * Typically this will simply return the active device. * In the case where the most recent active device was unset, this will attempt -* to return the first device. If that device doesn't exist or fails to probe, -* this function will return NULL. +* to return the device with sequence id 0 (which can be configured by the +* device tree). If this fails, fall back to just getting the first device. +* The latter is non-deterministic and depends on the order of the probing. +* If that device doesn't exist or fails to probe, this function will return +* NULL. */ struct udevice *eth_get_dev (void ) {
@@ -80,9 +83,13 @@ struct udevice *eth_get_dev(void)if (!uc_priv)return NULL ; -if (!uc_priv->current) - eth_errno =uclass_first_device (UCLASS_ETH , - &uc_priv->current); +if (!uc_priv->current) { + eth_errno =uclass_get_device_by_seq (UCLASS_ETH ,0 , + &uc_priv->current); +if (eth_errno) + eth_errno =uclass_first_device (UCLASS_ETH , + &uc_priv->current); + }return uc_priv->current; }
Signature · 1 line
2.20.1
PATCH 1/1 net: use a more deterministic approach to get the active ethernet device
Am 2021-02-24 17:30, schrieb Michael Walle:
Quoted 8 lines
If the environment variable "ethact" is not set, the first device in the
uclass is returned. This depends on the probing order of the ethernet devices. Moreover it is not not configurable at all.Try to return the ethernet device with sequence id 0 first which then can be configured by the aliases in a device tree. Fall back to the old mechanism in case of an error.
any news?
-michael
PATCH 1/1 net: use a more deterministic approach to get the active ethernet device
In reply to Michael WalleQuoted 50 lines · Michael Walle
If the environment variable "ethact" is not set, the first device in the uclass is returned. This depends on the probing order of the ethernet devices. Moreover it is not not configurable at all.
Try to return the ethernet device with sequence id 0 first which then can be configured by the aliases in a device tree. Fall back to the old mechanism in case of an error.
Signed-off-by Michael Walle <[email protected]>--- net/eth-uclass.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)net/eth-uclass.c +12
-6@@ -69,8 +69,11 @@ void eth_set_current_to_next(void)/* * Typically this will simply return the active device. * In the case where the most recent active device was unset, this will attempt -* to return the first device. If that device doesn't exist or fails to probe, -* this function will return NULL. +* to return the device with sequence id 0 (which can be configured by the +* device tree). If this fails, fall back to just getting the first device. +* The latter is non-deterministic and depends on the order of the probing. +* If that device doesn't exist or fails to probe, this function will return +* NULL. */ struct udevice *eth_get_dev (void ) {@@ -80,9 +83,13 @@ struct udevice *eth_get_dev(void)if (!uc_priv)return NULL ; -if (!uc_priv->current) - eth_errno =uclass_first_device (UCLASS_ETH , - &uc_priv->current); +if (!uc_priv->current) { + eth_errno =uclass_get_device_by_seq (UCLASS_ETH ,0 , + &uc_priv->current); +if (eth_errno) + eth_errno =uclass_first_device (UCLASS_ETH , + &uc_priv->current); + }return uc_priv->current; } --
Quoted 2 lines
2.20.1
Quoted 51 lines · Ramon Fried
Quoted 49 lines · Michael Walle
If the environment variable "ethact" is not set, the first device in the uclass is returned. This depends on the probing order of the ethernet devices. Moreover it is not not configurable at all.
Try to return the ethernet device with sequence id 0 first which then can be configured by the aliases in a device tree. Fall back to the old mechanism in case of an error.
Signed-off-by Michael Walle <[email protected]>--- net/eth-uclass.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)net/eth-uclass.c +12
-5@@ -69,8 +69,11 @@ void eth_set_current_to_next(void)/* * Typically this will simply return the active device. * In the case where the most recent active device was unset, this will attempt -* to return the first device. If that device doesn't exist or fails to probe, -* this function will return NULL. +* to return the device with sequence id 0 (which can be configured by the +* device tree). If this fails, fall back to just getting the first device. +* The latter is non-deterministic and depends on the order of the probing. +* If that device doesn't exist or fails to probe, this function will return +* NULL. */ struct udevice *eth_get_dev (void ) {@@ -80,9 +83,13 @@ struct udevice *eth_get_dev(void)if (!uc_priv)return NULL ; -if (!uc_priv->current) - eth_errno =uclass_first_device (UCLASS_ETH , - &uc_priv->current); +if (!uc_priv->current) { + eth_errno =uclass_get_device_by_seq (UCLASS_ETH ,0 , + &uc_priv->current); +if (eth_errno) + eth_errno =uclass_first_device (UCLASS_ETH , + &uc_priv->current); + }return uc_priv->current; }
Quoted 4 lines
Quoted 3 lines
--
2.20.1Reviewed-by Ramon Fried <[email protected]>
Applied to u-boot-net/master, thanks!
Best regards,
Ramon Fried