All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: use a more deterministic approach to get the active ethernet device
@ 2021-02-24 16:30 Michael Walle
  2021-04-24 11:01 ` Michael Walle
  2021-04-29 20:03 ` Ramon Fried
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Walle @ 2021-02-24 16:30 UTC (permalink / raw)
  To: u-boot

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 <michael@walle.cc>
---
 net/eth-uclass.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 34ca731d1e..0b4260dc5b 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -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;
 }
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] net: use a more deterministic approach to get the active ethernet device
  2021-02-24 16:30 [PATCH] net: use a more deterministic approach to get the active ethernet device Michael Walle
@ 2021-04-24 11:01 ` Michael Walle
  2021-04-29 20:03 ` Ramon Fried
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Walle @ 2021-04-24 11:01 UTC (permalink / raw)
  To: u-boot

Am 2021-02-24 17:30, schrieb 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.

any news?

-michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] net: use a more deterministic approach to get the active ethernet device
  2021-02-24 16:30 [PATCH] net: use a more deterministic approach to get the active ethernet device Michael Walle
  2021-04-24 11:01 ` Michael Walle
@ 2021-04-29 20:03 ` Ramon Fried
  2021-06-14 20:55   ` Ramon Fried
  1 sibling, 1 reply; 4+ messages in thread
From: Ramon Fried @ 2021-04-29 20:03 UTC (permalink / raw)
  To: u-boot

On Wed, Feb 24, 2021 at 6:30 PM Michael Walle <michael@walle.cc> wrote:
>
> 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 <michael@walle.cc>
> ---
>  net/eth-uclass.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/net/eth-uclass.c b/net/eth-uclass.c
> index 34ca731d1e..0b4260dc5b 100644
> --- a/net/eth-uclass.c
> +++ b/net/eth-uclass.c
> @@ -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;
>  }
>
> --
> 2.20.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: use a more deterministic approach to get the active ethernet device
  2021-04-29 20:03 ` Ramon Fried
@ 2021-06-14 20:55   ` Ramon Fried
  0 siblings, 0 replies; 4+ messages in thread
From: Ramon Fried @ 2021-06-14 20:55 UTC (permalink / raw)
  To: Michael Walle; +Cc: U-Boot Mailing List, Joe Hershberger

On Thu, Apr 29, 2021 at 11:03 PM Ramon Fried <rfried.dev@gmail.com> wrote:
>
> On Wed, Feb 24, 2021 at 6:30 PM Michael Walle <michael@walle.cc> wrote:
> >
> > 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 <michael@walle.cc>
> > ---
> >  net/eth-uclass.c | 17 ++++++++++++-----
> >  1 file changed, 12 insertions(+), 5 deletions(-)
> >
> > diff --git a/net/eth-uclass.c b/net/eth-uclass.c
> > index 34ca731d1e..0b4260dc5b 100644
> > --- a/net/eth-uclass.c
> > +++ b/net/eth-uclass.c
> > @@ -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;
> >  }
> >
> > --
> > 2.20.1
> >
> Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Applied to u-boot-net/master, thanks!

Best regards,
Ramon Fried

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-14 20:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 16:30 [PATCH] net: use a more deterministic approach to get the active ethernet device Michael Walle
2021-04-24 11:01 ` Michael Walle
2021-04-29 20:03 ` Ramon Fried
2021-06-14 20:55   ` Ramon Fried

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.