Skip to contentSkip to conversation

net: smc911x: Automatically Update ethaddr with MAC

PATCH Superseded Adam Ford 4 participants 12 messages Aug 18, 2020 – Oct 1, 2020 Network drivers

lore
Share & tools
lore

Adam Ford

author
#0 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

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.

---
V2: Fix typo

drivers/net/smc911x.c +3 -0
index 09372d7f6b..1fa3667b77 100644
@@ -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)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 11 lines · Adam Ford

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.

---
V2: Fix typo

Ping. Any chance this can get reviewed?

thank you,

adam

Quoted 26 lines
drivers/net/smc911x.c +3 -0
index 09372d7f6b..1fa3667b77 100644
@@ -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

#3 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

In reply to Adam Ford
Quoted 8 lines · Adam Ford

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.

Applied to u-boot/next, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201001/9781a987/attachment.sig>
#4 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 5 lines · Tom Rini
Quoted 3 lines · Adam Ford

The ethernet controller can read the MAC from EEPROM and display it, but if ethaddr is not set, the ethernet is still unavailable.

Quoted 7 lines
Quoted 5 lines

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

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 ?

#5 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 12 lines · Marek Vasut
Quoted 11 lines · Tom Rini
Quoted 8 lines · Adam Ford

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.

Quoted 8 lines
Quoted 1 line

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!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201001/f94a6b7d/attachment.sig>
author
#6 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 27 lines · Tom Rini
Quoted 12 lines · Marek Vasut
Quoted 11 lines · Tom Rini
Quoted 8 lines · Adam Ford

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.

Quoted 8 lines
Quoted 1 line

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.

Quoted 5 lines

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

Quoted 6 lines

Thanks!

--
Tom

#7 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 40 lines · Adam Ford
Quoted 27 lines · Tom Rini
Quoted 12 lines · Marek Vasut
Quoted 11 lines · Tom Rini
Quoted 8 lines · Adam Ford

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.

Quoted 8 lines
Quoted 1 line

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.

Quoted 5 lines

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.

Quoted 6 lines

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!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201001/52c6e60d/attachment.sig>
author
#8 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 50 lines · Tom Rini
Quoted 7 lines · Adam Ford
Quoted 5 lines · Tom Rini
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Tom Rini
Quoted 1 line · Adam Ford

The ethernet controller can read the MAC from EEPROM and display

it,

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines

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.

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.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

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

Quoted 10 lines
Quoted 8 lines

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

Quoted 2 lines

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

Quoted 1 line

controller may cause an issue because the driver at this level doesn't

know.

Quoted 5 lines

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.

Quoted 9 lines
Quoted 1 line

If you want to revert this patch, I won't object. I don't really have

time

Quoted 1 line

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

Quoted 4 lines

--
Tom

#9 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 62 lines · Adam Ford
Quoted 50 lines · Tom Rini
Quoted 7 lines · Adam Ford
Quoted 5 lines · Tom Rini
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Tom Rini
Quoted 1 line · Adam Ford

The ethernet controller can read the MAC from EEPROM and display

it,

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines

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.

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.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

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

Quoted 10 lines
Quoted 8 lines

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

Quoted 2 lines

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

Quoted 1 line

controller may cause an issue because the driver at this level doesn't

know.

Quoted 5 lines

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.

Quoted 9 lines
Quoted 1 line

If you want to revert this patch, I won't object. I don't really have

time

Quoted 1 line

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!

Quoted 10 lines

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 ?

#10 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 74 lines · Marek Vasut
Quoted 62 lines · Adam Ford
Quoted 50 lines · Tom Rini
Quoted 7 lines · Adam Ford
Quoted 5 lines · Tom Rini
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Tom Rini
Quoted 1 line · Adam Ford

The ethernet controller can read the MAC from EEPROM and display

it,

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines

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.

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.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

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

Quoted 10 lines
Quoted 8 lines

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

Quoted 2 lines

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

Quoted 1 line

controller may cause an issue because the driver at this level doesn't

know.

Quoted 5 lines

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.

Quoted 9 lines
Quoted 1 line

If you want to revert this patch, I won't object. I don't really have

time

Quoted 1 line

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!

Quoted 10 lines

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.

Quoted 5 lines

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!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201001/dcd42f59/attachment.sig>
#11 lore raw

PATCH v2 1/1 net: smc911x: Automatically Update ethaddr with MAC

Quoted 81 lines · Tom Rini
Quoted 74 lines · Marek Vasut
Quoted 62 lines · Adam Ford
Quoted 50 lines · Tom Rini
Quoted 7 lines · Adam Ford
Quoted 5 lines · Tom Rini
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Tom Rini
Quoted 1 line · Adam Ford

The ethernet controller can read the MAC from EEPROM and display

it,

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
Quoted 7 lines

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.

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.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

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

Quoted 10 lines
Quoted 8 lines

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

Quoted 2 lines

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

Quoted 1 line

controller may cause an issue because the driver at this level doesn't

know.

Quoted 5 lines

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.

Quoted 9 lines
Quoted 1 line

If you want to revert this patch, I won't object. I don't really have

time

Quoted 1 line

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!

Quoted 10 lines

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.

Quoted 5 lines

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 ?

Quoted 4 lines

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.