diff mbox series

[V2] net: smc911x: Automatically Update ethaddr with MAC

Message ID 20200818131902.18533-1-aford173@gmail.com
State Accepted
Commit 387cbf096e443705fa66776027273ed257ec6ca3
Delegated to: Tom Rini
Headers show
Series [V2] net: smc911x: Automatically Update ethaddr with MAC | expand

Commit Message

Adam Ford Aug. 18, 2020, 1:19 p.m. UTC
The ethernet controller can read the MAC from EEPROM and display it,
but if ethaddr is not set, the ethernet is still unavailable.

This patch checks will automatically set the MAC address if it has
not already been set.

Signed-off-by: Adam Ford <aford173@gmail.com>
---
V2:  Fix typo

Comments

Adam Ford Sept. 26, 2020, 11:06 a.m. UTC | #1
On Tue, Aug 18, 2020 at 8:19 AM Adam Ford <aford173@gmail.com> wrote:

> The ethernet controller can read the MAC from EEPROM and display it,
> but if ethaddr is not set, the ethernet is still unavailable.
>
> This patch checks will automatically set the MAC address if it has
> not already been set.
>
> Signed-off-by: Adam Ford <aford173@gmail.com>
> ---
> V2:  Fix typo
>
>
Ping.  Any chance this can get reviewed?

thank you,

adam

> diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
> index 09372d7f6b..1fa3667b77 100644
> --- a/drivers/net/smc911x.c
> +++ b/drivers/net/smc911x.c
> @@ -6,6 +6,7 @@
>   */
>
>  #include <common.h>
> +#include <env.h>
>  #include <command.h>
>  #include <malloc.h>
>  #include <net.h>
> @@ -185,6 +186,8 @@ static void smc911x_handle_mac_address(struct
> smc911x_priv *priv)
>         smc911x_set_mac_csr(priv, ADDRH, addrh);
>
>         printf(DRIVERNAME ": MAC %pM\n", m);
> +       if (!env_get("ethaddr"))
> +               env_set("ethaddr", (const char *)m);
>  }
>
>  static bool smc911x_read_mac_address(struct smc911x_priv *priv)
> --
> 2.17.1
>
>
Joe Hershberger Sept. 28, 2020, 6:03 p.m. UTC | #2
On Tue, Aug 18, 2020 at 8:19 AM Adam Ford <aford173@gmail.com> wrote:
>
> The ethernet controller can read the MAC from EEPROM and display it,
> but if ethaddr is not set, the ethernet is still unavailable.
>
> This patch checks will automatically set the MAC address if it has
> not already been set.
>
> Signed-off-by: Adam Ford <aford173@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Tom Rini Oct. 1, 2020, 2:09 p.m. UTC | #3
On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:

> The ethernet controller can read the MAC from EEPROM and display it,
> but if ethaddr is not set, the ethernet is still unavailable.
> 
> This patch checks will automatically set the MAC address if it has
> not already been set.
> 
> Signed-off-by: Adam Ford <aford173@gmail.com>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>

Applied to u-boot/next, thanks!
Marek Vasut Oct. 1, 2020, 5:48 p.m. UTC | #4
On 10/1/20 4:09 PM, Tom Rini wrote:
> On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
> 
>> The ethernet controller can read the MAC from EEPROM and display it,
>> but if ethaddr is not set, the ethernet is still unavailable.
>>
>> This patch checks will automatically set the MAC address if it has
>> not already been set.
>>
>> Signed-off-by: Adam Ford <aford173@gmail.com>
>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> 
> Applied to u-boot/next, thanks!

Note that this breaks every single setup where smc911x is not primary
ethernet. On systems where smc911x is secondary ethernet, you need to
set eth1addr and so on, so please do fix that.

Also, this kind of ethXaddr update should happen in the ethernet core
instead, drivers shouldn't really modify environment, no ?
Tom Rini Oct. 1, 2020, 6:17 p.m. UTC | #5
On Thu, Oct 01, 2020 at 07:48:32PM +0200, Marek Vasut wrote:
> On 10/1/20 4:09 PM, Tom Rini wrote:
> > On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
> > 
> >> The ethernet controller can read the MAC from EEPROM and display it,
> >> but if ethaddr is not set, the ethernet is still unavailable.
> >>
> >> This patch checks will automatically set the MAC address if it has
> >> not already been set.
> >>
> >> Signed-off-by: Adam Ford <aford173@gmail.com>
> >> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> > 
> > Applied to u-boot/next, thanks!
> 
> Note that this breaks every single setup where smc911x is not primary
> ethernet. On systems where smc911x is secondary ethernet, you need to
> set eth1addr and so on, so please do fix that.
> 
> Also, this kind of ethXaddr update should happen in the ethernet core
> instead, drivers shouldn't really modify environment, no ?

Interesting points.  So, if smc911x is not the primary ether device,
something else will have already set "ethaddr", most likely.  We do have
both the common case where "ethaddr" (and "eth1addr" and so forth) are
set.

Adam, when exactly did you run in to the case where ethaddr wasn't set
correctly?  Was it on a non-DM_ETH case?  To Marek's last point, we do
have drivers that set ethaddr/ethXaddr, but that's in the non-DM_ETH
case.

Thanks!
Adam Ford Oct. 1, 2020, 6:22 p.m. UTC | #6
On Thu, Oct 1, 2020 at 1:17 PM Tom Rini <trini@konsulko.com> wrote:

> On Thu, Oct 01, 2020 at 07:48:32PM +0200, Marek Vasut wrote:
> > On 10/1/20 4:09 PM, Tom Rini wrote:
> > > On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
> > >
> > >> The ethernet controller can read the MAC from EEPROM and display it,
> > >> but if ethaddr is not set, the ethernet is still unavailable.
> > >>
> > >> This patch checks will automatically set the MAC address if it has
> > >> not already been set.
> > >>
> > >> Signed-off-by: Adam Ford <aford173@gmail.com>
> > >> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> > >
> > > Applied to u-boot/next, thanks!
> >
> > Note that this breaks every single setup where smc911x is not primary
> > ethernet. On systems where smc911x is secondary ethernet, you need to
> > set eth1addr and so on, so please do fix that.
> >
> > Also, this kind of ethXaddr update should happen in the ethernet core
> > instead, drivers shouldn't really modify environment, no ?
>
> Interesting points.  So, if smc911x is not the primary ether device,
> something else will have already set "ethaddr", most likely.  We do have
> both the common case where "ethaddr" (and "eth1addr" and so forth) are
> set.
>
> Adam, when exactly did you run in to the case where ethaddr wasn't set
> correctly?  Was it on a non-DM_ETH case?  To Marek's last point, we do
> have drivers that set ethaddr/ethXaddr, but that's in the non-DM_ETH
> case.
>

The only situation I tested was with DM_ETH since I thought it was going to
be a requirement by 2020.07.  If ethaddr is already set, it shouldn't
override it, but I can see an issue where using the SMC911x as a secondary
controller may cause an issue because the driver at this level doesn't know.

It seems like there should be a way to determine if the MAC address is
readable so the user doesn't need to enter it manually, but it's probably
not at the driver level based on the feedback.

If you want to revert this patch, I won't object.  I don't really have time
to develop a better one right now.

adam


>
> Thanks!
>
> --
> Tom
>
Tom Rini Oct. 1, 2020, 6:28 p.m. UTC | #7
On Thu, Oct 01, 2020 at 01:22:37PM -0500, Adam Ford wrote:
> On Thu, Oct 1, 2020 at 1:17 PM Tom Rini <trini@konsulko.com> wrote:
> 
> > On Thu, Oct 01, 2020 at 07:48:32PM +0200, Marek Vasut wrote:
> > > On 10/1/20 4:09 PM, Tom Rini wrote:
> > > > On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
> > > >
> > > >> The ethernet controller can read the MAC from EEPROM and display it,
> > > >> but if ethaddr is not set, the ethernet is still unavailable.
> > > >>
> > > >> This patch checks will automatically set the MAC address if it has
> > > >> not already been set.
> > > >>
> > > >> Signed-off-by: Adam Ford <aford173@gmail.com>
> > > >> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> > > >
> > > > Applied to u-boot/next, thanks!
> > >
> > > Note that this breaks every single setup where smc911x is not primary
> > > ethernet. On systems where smc911x is secondary ethernet, you need to
> > > set eth1addr and so on, so please do fix that.
> > >
> > > Also, this kind of ethXaddr update should happen in the ethernet core
> > > instead, drivers shouldn't really modify environment, no ?
> >
> > Interesting points.  So, if smc911x is not the primary ether device,
> > something else will have already set "ethaddr", most likely.  We do have
> > both the common case where "ethaddr" (and "eth1addr" and so forth) are
> > set.
> >
> > Adam, when exactly did you run in to the case where ethaddr wasn't set
> > correctly?  Was it on a non-DM_ETH case?  To Marek's last point, we do
> > have drivers that set ethaddr/ethXaddr, but that's in the non-DM_ETH
> > case.
> >
> 
> The only situation I tested was with DM_ETH since I thought it was going to
> be a requirement by 2020.07.  If ethaddr is already set, it shouldn't
> override it, but I can see an issue where using the SMC911x as a secondary
> controller may cause an issue because the driver at this level doesn't know.
> 
> It seems like there should be a way to determine if the MAC address is
> readable so the user doesn't need to enter it manually, but it's probably
> not at the driver level based on the feedback.
> 
> If you want to revert this patch, I won't object.  I don't really have time
> to develop a better one right now.

Well, wait.  Did you encounter a case where "ethaddr" was not
automatically correctly set?  A quick skim of the driver and it looks
like it's doing everything needed for the common code to set "ethaddr"
correctly from enetaddr the driver probed.  Thanks!
Adam Ford Oct. 1, 2020, 6:42 p.m. UTC | #8
On Thu, Oct 1, 2020 at 1:28 PM Tom Rini <trini@konsulko.com> wrote:

> On Thu, Oct 01, 2020 at 01:22:37PM -0500, Adam Ford wrote:
> > On Thu, Oct 1, 2020 at 1:17 PM Tom Rini <trini@konsulko.com> wrote:
> >
> > > On Thu, Oct 01, 2020 at 07:48:32PM +0200, Marek Vasut wrote:
> > > > On 10/1/20 4:09 PM, Tom Rini wrote:
> > > > > On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
> > > > >
> > > > >> The ethernet controller can read the MAC from EEPROM and display
> it,
> > > > >> but if ethaddr is not set, the ethernet is still unavailable.
> > > > >>
> > > > >> This patch checks will automatically set the MAC address if it has
> > > > >> not already been set.
> > > > >>
> > > > >> Signed-off-by: Adam Ford <aford173@gmail.com>
> > > > >> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> > > > >
> > > > > Applied to u-boot/next, thanks!
> > > >
> > > > Note that this breaks every single setup where smc911x is not primary
> > > > ethernet. On systems where smc911x is secondary ethernet, you need to
> > > > set eth1addr and so on, so please do fix that.
> > > >
> > > > Also, this kind of ethXaddr update should happen in the ethernet core
> > > > instead, drivers shouldn't really modify environment, no ?
> > >
> > > Interesting points.  So, if smc911x is not the primary ether device,
> > > something else will have already set "ethaddr", most likely.  We do
> have
> > > both the common case where "ethaddr" (and "eth1addr" and so forth) are
> > > set.
> > >
> > > Adam, when exactly did you run in to the case where ethaddr wasn't set
> > > correctly?  Was it on a non-DM_ETH case?  To Marek's last point, we do
> > > have drivers that set ethaddr/ethXaddr, but that's in the non-DM_ETH
> > > case.
> > >
> >
> > The only situation I tested was with DM_ETH since I thought it was going
> to
> > be a requirement by 2020.07.  If ethaddr is already set, it shouldn't
> > override it, but I can see an issue where using the SMC911x as a
> secondary
> > controller may cause an issue because the driver at this level doesn't
> know.
> >
> > It seems like there should be a way to determine if the MAC address is
> > readable so the user doesn't need to enter it manually, but it's probably
> > not at the driver level based on the feedback.
> >
> > If you want to revert this patch, I won't object.  I don't really have
> time
> > to develop a better one right now.
>
> Well, wait.  Did you encounter a case where "ethaddr" was not
> automatically correctly set?  A quick skim of the driver and it looks
> like it's doing everything needed for the common code to set "ethaddr"
> correctly from enetaddr the driver probed.  Thanks!
>

I haven't tried lately, but when booting the Logic PD OMAP3 boards, I was
seeing a message displaying the MAC address while simultaneously showing
the message that it didn't have an address, so DHCP calls would fail.  I
could confirm that ethaddr was not set.  However, if I manually set the
ethaddr to the value dumped by the SMC911x driver, save the environmental
variables then reset the board, the ethernet would work.  It seemed like
the area where the SMC911x displayed the MAC address made sense to update
it since it just finished fetching it. so that's why I set up the patch the
way it was.  I hadn't considered a use case where it wasn't the primary
ethernet controller.

adam



>
> --
> Tom
>
Marek Vasut Oct. 1, 2020, 6:46 p.m. UTC | #9
On 10/1/20 8:42 PM, Adam Ford wrote:
> On Thu, Oct 1, 2020 at 1:28 PM Tom Rini <trini@konsulko.com> wrote:
> 
>> On Thu, Oct 01, 2020 at 01:22:37PM -0500, Adam Ford wrote:
>>> On Thu, Oct 1, 2020 at 1:17 PM Tom Rini <trini@konsulko.com> wrote:
>>>
>>>> On Thu, Oct 01, 2020 at 07:48:32PM +0200, Marek Vasut wrote:
>>>>> On 10/1/20 4:09 PM, Tom Rini wrote:
>>>>>> On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
>>>>>>
>>>>>>> The ethernet controller can read the MAC from EEPROM and display
>> it,
>>>>>>> but if ethaddr is not set, the ethernet is still unavailable.
>>>>>>>
>>>>>>> This patch checks will automatically set the MAC address if it has
>>>>>>> not already been set.
>>>>>>>
>>>>>>> Signed-off-by: Adam Ford <aford173@gmail.com>
>>>>>>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>>>>>>
>>>>>> Applied to u-boot/next, thanks!
>>>>>
>>>>> Note that this breaks every single setup where smc911x is not primary
>>>>> ethernet. On systems where smc911x is secondary ethernet, you need to
>>>>> set eth1addr and so on, so please do fix that.
>>>>>
>>>>> Also, this kind of ethXaddr update should happen in the ethernet core
>>>>> instead, drivers shouldn't really modify environment, no ?
>>>>
>>>> Interesting points.  So, if smc911x is not the primary ether device,
>>>> something else will have already set "ethaddr", most likely.  We do
>> have
>>>> both the common case where "ethaddr" (and "eth1addr" and so forth) are
>>>> set.
>>>>
>>>> Adam, when exactly did you run in to the case where ethaddr wasn't set
>>>> correctly?  Was it on a non-DM_ETH case?  To Marek's last point, we do
>>>> have drivers that set ethaddr/ethXaddr, but that's in the non-DM_ETH
>>>> case.
>>>>
>>>
>>> The only situation I tested was with DM_ETH since I thought it was going
>> to
>>> be a requirement by 2020.07.  If ethaddr is already set, it shouldn't
>>> override it, but I can see an issue where using the SMC911x as a
>> secondary
>>> controller may cause an issue because the driver at this level doesn't
>> know.
>>>
>>> It seems like there should be a way to determine if the MAC address is
>>> readable so the user doesn't need to enter it manually, but it's probably
>>> not at the driver level based on the feedback.
>>>
>>> If you want to revert this patch, I won't object.  I don't really have
>> time
>>> to develop a better one right now.
>>
>> Well, wait.  Did you encounter a case where "ethaddr" was not
>> automatically correctly set?  A quick skim of the driver and it looks
>> like it's doing everything needed for the common code to set "ethaddr"
>> correctly from enetaddr the driver probed.  Thanks!
>>
> 
> I haven't tried lately, but when booting the Logic PD OMAP3 boards, I was
> seeing a message displaying the MAC address while simultaneously showing
> the message that it didn't have an address, so DHCP calls would fail.  I
> could confirm that ethaddr was not set.  However, if I manually set the
> ethaddr to the value dumped by the SMC911x driver, save the environmental
> variables then reset the board, the ethernet would work.  It seemed like
> the area where the SMC911x displayed the MAC address made sense to update
> it since it just finished fetching it. so that's why I set up the patch the
> way it was.  I hadn't considered a use case where it wasn't the primary
> ethernet controller.

Unless there is something else broken, the driver does provide a
callback to pull ethernet address from the EEPROM already, and that
should permit the driver core to set ethXaddr. So can you please debug
that, why it is not happening on your board, instead of adding the
current workaround ?
Tom Rini Oct. 1, 2020, 6:51 p.m. UTC | #10
On Thu, Oct 01, 2020 at 08:46:56PM +0200, Marek Vasut wrote:
> On 10/1/20 8:42 PM, Adam Ford wrote:
> > On Thu, Oct 1, 2020 at 1:28 PM Tom Rini <trini@konsulko.com> wrote:
> > 
> >> On Thu, Oct 01, 2020 at 01:22:37PM -0500, Adam Ford wrote:
> >>> On Thu, Oct 1, 2020 at 1:17 PM Tom Rini <trini@konsulko.com> wrote:
> >>>
> >>>> On Thu, Oct 01, 2020 at 07:48:32PM +0200, Marek Vasut wrote:
> >>>>> On 10/1/20 4:09 PM, Tom Rini wrote:
> >>>>>> On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
> >>>>>>
> >>>>>>> The ethernet controller can read the MAC from EEPROM and display
> >> it,
> >>>>>>> but if ethaddr is not set, the ethernet is still unavailable.
> >>>>>>>
> >>>>>>> This patch checks will automatically set the MAC address if it has
> >>>>>>> not already been set.
> >>>>>>>
> >>>>>>> Signed-off-by: Adam Ford <aford173@gmail.com>
> >>>>>>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> >>>>>>
> >>>>>> Applied to u-boot/next, thanks!
> >>>>>
> >>>>> Note that this breaks every single setup where smc911x is not primary
> >>>>> ethernet. On systems where smc911x is secondary ethernet, you need to
> >>>>> set eth1addr and so on, so please do fix that.
> >>>>>
> >>>>> Also, this kind of ethXaddr update should happen in the ethernet core
> >>>>> instead, drivers shouldn't really modify environment, no ?
> >>>>
> >>>> Interesting points.  So, if smc911x is not the primary ether device,
> >>>> something else will have already set "ethaddr", most likely.  We do
> >> have
> >>>> both the common case where "ethaddr" (and "eth1addr" and so forth) are
> >>>> set.
> >>>>
> >>>> Adam, when exactly did you run in to the case where ethaddr wasn't set
> >>>> correctly?  Was it on a non-DM_ETH case?  To Marek's last point, we do
> >>>> have drivers that set ethaddr/ethXaddr, but that's in the non-DM_ETH
> >>>> case.
> >>>>
> >>>
> >>> The only situation I tested was with DM_ETH since I thought it was going
> >> to
> >>> be a requirement by 2020.07.  If ethaddr is already set, it shouldn't
> >>> override it, but I can see an issue where using the SMC911x as a
> >> secondary
> >>> controller may cause an issue because the driver at this level doesn't
> >> know.
> >>>
> >>> It seems like there should be a way to determine if the MAC address is
> >>> readable so the user doesn't need to enter it manually, but it's probably
> >>> not at the driver level based on the feedback.
> >>>
> >>> If you want to revert this patch, I won't object.  I don't really have
> >> time
> >>> to develop a better one right now.
> >>
> >> Well, wait.  Did you encounter a case where "ethaddr" was not
> >> automatically correctly set?  A quick skim of the driver and it looks
> >> like it's doing everything needed for the common code to set "ethaddr"
> >> correctly from enetaddr the driver probed.  Thanks!
> >>
> > 
> > I haven't tried lately, but when booting the Logic PD OMAP3 boards, I was
> > seeing a message displaying the MAC address while simultaneously showing
> > the message that it didn't have an address, so DHCP calls would fail.  I
> > could confirm that ethaddr was not set.  However, if I manually set the
> > ethaddr to the value dumped by the SMC911x driver, save the environmental
> > variables then reset the board, the ethernet would work.  It seemed like
> > the area where the SMC911x displayed the MAC address made sense to update
> > it since it just finished fetching it. so that's why I set up the patch the
> > way it was.  I hadn't considered a use case where it wasn't the primary
> > ethernet controller.
> 
> Unless there is something else broken, the driver does provide a
> callback to pull ethernet address from the EEPROM already, and that
> should permit the driver core to set ethXaddr. So can you please debug
> that, why it is not happening on your board, instead of adding the
> current workaround ?

It does sound like something more fundamental is broken in that
particular setup if the generic code path in net/net-uclass.c to set
"ethaddr"/etc as appropriate is not called.  I will revert this for now,
as you said.  Thanks!
Marek Vasut Oct. 1, 2020, 7:49 p.m. UTC | #11
On 10/1/20 8:51 PM, Tom Rini wrote:
> On Thu, Oct 01, 2020 at 08:46:56PM +0200, Marek Vasut wrote:
>> On 10/1/20 8:42 PM, Adam Ford wrote:
>>> On Thu, Oct 1, 2020 at 1:28 PM Tom Rini <trini@konsulko.com> wrote:
>>>
>>>> On Thu, Oct 01, 2020 at 01:22:37PM -0500, Adam Ford wrote:
>>>>> On Thu, Oct 1, 2020 at 1:17 PM Tom Rini <trini@konsulko.com> wrote:
>>>>>
>>>>>> On Thu, Oct 01, 2020 at 07:48:32PM +0200, Marek Vasut wrote:
>>>>>>> On 10/1/20 4:09 PM, Tom Rini wrote:
>>>>>>>> On Tue, Aug 18, 2020 at 08:19:02AM -0500, Adam Ford wrote:
>>>>>>>>
>>>>>>>>> The ethernet controller can read the MAC from EEPROM and display
>>>> it,
>>>>>>>>> but if ethaddr is not set, the ethernet is still unavailable.
>>>>>>>>>
>>>>>>>>> This patch checks will automatically set the MAC address if it has
>>>>>>>>> not already been set.
>>>>>>>>>
>>>>>>>>> Signed-off-by: Adam Ford <aford173@gmail.com>
>>>>>>>>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>>>>>>>>
>>>>>>>> Applied to u-boot/next, thanks!
>>>>>>>
>>>>>>> Note that this breaks every single setup where smc911x is not primary
>>>>>>> ethernet. On systems where smc911x is secondary ethernet, you need to
>>>>>>> set eth1addr and so on, so please do fix that.
>>>>>>>
>>>>>>> Also, this kind of ethXaddr update should happen in the ethernet core
>>>>>>> instead, drivers shouldn't really modify environment, no ?
>>>>>>
>>>>>> Interesting points.  So, if smc911x is not the primary ether device,
>>>>>> something else will have already set "ethaddr", most likely.  We do
>>>> have
>>>>>> both the common case where "ethaddr" (and "eth1addr" and so forth) are
>>>>>> set.
>>>>>>
>>>>>> Adam, when exactly did you run in to the case where ethaddr wasn't set
>>>>>> correctly?  Was it on a non-DM_ETH case?  To Marek's last point, we do
>>>>>> have drivers that set ethaddr/ethXaddr, but that's in the non-DM_ETH
>>>>>> case.
>>>>>>
>>>>>
>>>>> The only situation I tested was with DM_ETH since I thought it was going
>>>> to
>>>>> be a requirement by 2020.07.  If ethaddr is already set, it shouldn't
>>>>> override it, but I can see an issue where using the SMC911x as a
>>>> secondary
>>>>> controller may cause an issue because the driver at this level doesn't
>>>> know.
>>>>>
>>>>> It seems like there should be a way to determine if the MAC address is
>>>>> readable so the user doesn't need to enter it manually, but it's probably
>>>>> not at the driver level based on the feedback.
>>>>>
>>>>> If you want to revert this patch, I won't object.  I don't really have
>>>> time
>>>>> to develop a better one right now.
>>>>
>>>> Well, wait.  Did you encounter a case where "ethaddr" was not
>>>> automatically correctly set?  A quick skim of the driver and it looks
>>>> like it's doing everything needed for the common code to set "ethaddr"
>>>> correctly from enetaddr the driver probed.  Thanks!
>>>>
>>>
>>> I haven't tried lately, but when booting the Logic PD OMAP3 boards, I was
>>> seeing a message displaying the MAC address while simultaneously showing
>>> the message that it didn't have an address, so DHCP calls would fail.  I
>>> could confirm that ethaddr was not set.  However, if I manually set the
>>> ethaddr to the value dumped by the SMC911x driver, save the environmental
>>> variables then reset the board, the ethernet would work.  It seemed like
>>> the area where the SMC911x displayed the MAC address made sense to update
>>> it since it just finished fetching it. so that's why I set up the patch the
>>> way it was.  I hadn't considered a use case where it wasn't the primary
>>> ethernet controller.
>>
>> Unless there is something else broken, the driver does provide a
>> callback to pull ethernet address from the EEPROM already, and that
>> should permit the driver core to set ethXaddr. So can you please debug
>> that, why it is not happening on your board, instead of adding the
>> current workaround ?
> 
> It does sound like something more fundamental is broken in that
> particular setup if the generic code path in net/net-uclass.c to set
> "ethaddr"/etc as appropriate is not called.  I will revert this for now,
> as you said.  Thanks!

That's fine, but it would be good to figure out what was broken in that
other setup too.
diff mbox series

Patch

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 09372d7f6b..1fa3667b77 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -6,6 +6,7 @@ 
  */
 
 #include <common.h>
+#include <env.h>
 #include <command.h>
 #include <malloc.h>
 #include <net.h>
@@ -185,6 +186,8 @@  static void smc911x_handle_mac_address(struct smc911x_priv *priv)
 	smc911x_set_mac_csr(priv, ADDRH, addrh);
 
 	printf(DRIVERNAME ": MAC %pM\n", m);
+	if (!env_get("ethaddr"))
+		env_set("ethaddr", (const char *)m);
 }
 
 static bool smc911x_read_mac_address(struct smc911x_priv *priv)