Skip to contentSkip to conversation

Retrieve MAC address from EEPROM

PATCH Superseded Olliver Schinagl 5 participants 32 messages Apr 10, 2017 – May 30, 2017

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Retrieve MAC address from EEPROM

First off:
P.S. Joe, for some reason my previous patches where added with me as:
"oliver at schinagl.nl <[email protected]>" I see that it comes from patchwork as such. Is there some way to fix this to
"Olliver Schinagl <[email protected]>"?

Below the updated summary:

This patch-series introduces methods to retrieve the MAC address from an onboard EEPROM. The series does a few small cleanups at the start, as either I ran into them while doing this series and fixed them along the way or actually depended on them.

A manufacturer wants to produce boards and may even have MAC addresses for boards. Maintaining unique environments on a per-board basis however is horrible. Also this data should be very persistent, and not easily deletable by simply wiping the environment or device tree. Finally there are chips available on the market with a pre-programmed MAC address chips (proms)
that a board manufacturer wants to use. Because of this, the MAC needs to be stored be able to read from such an 'external' source.

The current idea of the eeprom layout, is to skip the first 8 bytes, so that other information can be stored there if needed, for example a header with some magic to identify the EEPROM. Or equivalent purposes.

After those 8 bytes the MAC address follows the first macaddress. The macaddress is appended by a CRC8 byte and then padded to make for nice 8 bytes. Following the first macaddress one can store a second, or a third etc etc macaddress.

The CRC8 is optional (via a define) but is strongly recommended to have. It helps preventing user error and more importantly, checks if the bytes read are actually a user inserted address. E.g. only writing 1 macaddress into the eeprom but trying to consume 2.

These patches where tested on Olimex OLinuXino Lime1 (A10/A20), Lime2 (NAND and eMMC) and A20-OLinuXino-MICRO-4G variants and have been in use internally on our production systems since v2 of this patch set.

TODO in a follow up series:
* Replace the I2C specific read function to a generic function using Maxime Ripard's EEPROM uclass once merged.
* Upgrade to use the EERPOM layout functionality.

=======
Changes since v4:
* Some patches have been merged, so those are no longer included in the set.
* Reworked review comments
* Added the source of a MAC address
* Made sunxi-gmac a subclassed driver
* Switch sunxi-[eg]mac to Kconfig
* Drop the FDT injection code for now, this needs more thought/discussion

Changes since v3:
* Split off board specific stuff and only modify the generic functions
* Make reading of an eeprom available to every board. By default this is unconfigure and thus should just fall through
* Clean some minor bits up (ARP_HLEN) and use it more generically
* Update the gen_ethaddr_crc as suggested by simon
* Let the fixup_ethernet from fdt_common insert mac addresses to the environment
for unconfigured devices. There is a small caveat here however as
described
in the TODO above.
* Print the mac address that u-boot assigned to each device.

Changes since v2:
* Drop the id byte altogether and just mark it as reserved. The 'index' can be
used to indicate the interface instead
* Addopt the read_rom_hwaddr hooks
* Renamed crc8 tool to gen_ethaddr_crc
* Improved the layout EEPROM example
* Made a function out of the hwaddress writing function in sunxi_emac so it can be re-used as the write_hwaddr net_ops hook.
* No longer handle fdt parameters in board.c

Changes since v1:
* Do not CRC the id byte, move it just after the crc byte.
One of the reasons I decided to move it after the crc8 was mostly due to mass
generation of MAC + CRC combo's where the ID is still unknown. Also not crc-ing
the ID means that it is much easier for a user to change it (via the u-boot i2c
cmd line or from within linux) without having to worry about the crc.
* Add a generator to convert a MAC address from the input to a MAC + CRC8 on the output.

Olliver Schinagl (21):
net: cosmetic: Do not use magic values for ARP_HLEN
net: core: Sanitize get/set operations for enetaddr
net: core: Inform the user of the device MAC address
net: core: Add function to check/set MAC locality
net: Add ability to set MAC address via EEPROM
net: core: print the source of the MAC address
net: cosmetic: A MAC address is not limited to SROM
fdt: fixup_eth: Remove code duplication with a function
fdt: fixup_eth: improve error catching/reduce identation
net: sunxi: Enable I2C bus set via NET_ETHADDR_EEPROM_I2C_BUS
net: sunxi_[eg]mac: Convert to Kconfig
arm: sunxi: Expose function to generate sunxi-specific a MAC address
net: sunxi_emac: Write HW address via net_ops hook
net: sunxi: Have sunxi common functions together
net: sunxi_emac: Add read_rom_hwaddr hook
net: sunxi_gmac: Make the sunxi variant of dw driver a subclass
net: dw: Expose designware_eth_start
net: sunxi_gmac: Add read_rom_hwaddr hook
net: sun8i_gmac: Add read_rom_hwaddr hook
net: sun8i: fix whitespace
net: core: Check return value of read_rom_hwaddr

 arch/arm/include/asm/arch-sunxi/sys_proto.h    |   7 +-
 arch/arm/mach-sunxi/board.c                    |   1 -
 board/sunxi/Kconfig                            |   4 +
 board/sunxi/Makefile                           |   1 -
 board/sunxi/board.c                            | 145 ++++++++++++++++---------
 common/fdt_support.c                           |  33 +++---
 configs/A10-OLinuXino-Lime_defconfig           |   4 +-
 configs/A10s-OLinuXino-M_defconfig             |   2 +-
 configs/A20-OLinuXino-Lime2_defconfig          |   5 +-
 configs/A20-OLinuXino-Lime_defconfig           |   5 +-
 configs/A20-OLinuXino_MICRO_defconfig          |   5 +-
 configs/A20-Olimex-SOM-EVB_defconfig           |   4 +-
 configs/Bananapi_defconfig                     |   4 +-
 configs/Bananapro_defconfig                    |   4 +-
 configs/CSQ_CS908_defconfig                    |   3 +-
 configs/Colombus_defconfig                     |   4 +-
 configs/Cubieboard2_defconfig                  |   4 +-
 configs/Cubieboard_defconfig                   |   3 +-
 configs/Cubietruck_defconfig                   |   4 +-
 configs/Hummingbird_A31_defconfig              |   4 +-
 configs/Itead_Ibox_A20_defconfig               |   4 +-
 configs/Lamobo_R1_defconfig                    |   4 +-
 configs/Linksprite_pcDuino3_Nano_defconfig     |   4 +-
 configs/Linksprite_pcDuino3_defconfig          |   4 +-
 configs/Linksprite_pcDuino_defconfig           |   2 +-
 configs/Marsboard_A10_defconfig                |   2 +-
 configs/Mele_A1000G_quad_defconfig             |   3 +-
 configs/Mele_A1000_defconfig                   |   3 +-
 configs/Mele_I7_defconfig                      |   3 +-
 configs/Mele_M3_defconfig                      |   3 +-
 configs/Mele_M5_defconfig                      |   3 +-
 configs/Mele_M9_defconfig                      |   3 +-
 configs/Orangepi_defconfig                     |   4 +-
 configs/Orangepi_mini_defconfig                |   4 +-
 configs/Sinlinx_SinA31s_defconfig              |   3 +-
 configs/Sinovoip_BPI_M2_defconfig              |   4 +-
 configs/Wits_Pro_A20_DKT_defconfig             |   4 +-
 configs/ba10_tv_box_defconfig                  |   2 +-
 configs/i12-tvbox_defconfig                    |   4 +-
 configs/icnova-a20-swac_defconfig              |   4 +-
 configs/jesurun_q5_defconfig                   |   3 +-
 configs/mixtile_loftq_defconfig                |   4 +-
 doc/README.enetaddr                            |  99 +++++++++++++++++
 drivers/net/Kconfig                            |  33 +++++-
 drivers/net/Makefile                           |   5 +-
 drivers/net/designware.c                       |   3 +-
 drivers/net/designware.h                       |   1 +
 drivers/net/sun8i_emac.c                       |  15 ++-
 drivers/net/sunxi_common.c                     |  33 ++++++
 drivers/net/sunxi_common.h                     |  13 +++
 drivers/net/sunxi_emac.c                       |  15 +++
 board/sunxi/gmac.c => drivers/net/sunxi_gmac.c |  54 ++++++++-
 include/configs/sunxi-common.h                 |   5 -
 include/net.h                                  |  53 ++++++++-
 net/Kconfig                                    |  59 ++++++++++
 net/eth-uclass.c                               |  65 ++++++-----
 net/eth_common.c                               |  53 ++++++++-
 net/eth_legacy.c                               |   7 +-
 58 files changed, 626 insertions(+), 207 deletions(-)
 create mode 100644 drivers/net/sunxi_common.c
 create mode 100644 drivers/net/sunxi_common.h
 rename board/sunxi/gmac.c => drivers/net/sunxi_gmac.c (67%)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/21 net: cosmetic: Do not use magic values for ARP_HLEN

Previously overlooked magic value in commit a40db6d51171 ("net: cosmetic: Do not use magic values for ARP_HLEN")

---
 net/eth_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/eth_common.c +1 -1
index 58fa295771..049c1ee6f9 100644
@@ -17,7 +17,7 @@ void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
 	char *end;
 	int i;
 
-	for (i = 0; i < 6; ++i) {
+	for (i = 0; i < ARP_HLEN; ++i) {
 		enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
 		if (addr)
 			addr = (*end) ? end + 1 : end;
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 2/21 net: core: Sanitize get/set operations for enetaddr

In reply to Olliver Schinagl

In the current net stack, we have a few functions to get and set the "ethaddr" and "ethNaddr" environment variables, which use magic values to get and set these environment variables. Remove the magicness of the buffer by defining it proper and also check the input for its length.

Additionally use the define in fdt parser where the ethaddr variables are also used.

---
 common/fdt_support.c |  2 +-
 include/net.h        |  1 +
 net/eth_common.c     | 14 +++++++++-----
 3 files changed, 11 insertions(+), 6 deletions(-)
common/fdt_support.c +1 -1
index c6a76b7ad2..d462bf0642 100644
@@ -471,7 +471,7 @@ void fdt_fixup_ethernet(void *fdt)
 {
 	int i, j, prop;
 	char *tmp, *end;
-	char mac[16];
+	char mac[ETH_ENETADDR_ENV_NAME_LEN];
 	const char *path;
 	unsigned char mac_addr[ARP_HLEN];
 	int offset;
include/net.h +1 -0
index ed5259a807..b4af8eaae4 100644
@@ -243,6 +243,7 @@ void eth_set_current(void);		/* set nterface to ethcur var */
 
 int eth_get_dev_index(void);		/* get the device index */
 void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
+#define ETH_ENETADDR_ENV_NAME_LEN 32
 int eth_getenv_enetaddr(const char *name, uchar *enetaddr);
 int eth_setenv_enetaddr(const char *name, const uchar *enetaddr);
 
net/eth_common.c +9 -5
index 049c1ee6f9..0fe4d260d8 100644
@@ -45,16 +45,20 @@ int eth_setenv_enetaddr(const char *name, const uchar *enetaddr)
 int eth_getenv_enetaddr_by_index(const char *base_name, int index,
 				 uchar *enetaddr)
 {
-	char enetvar[32];
-	sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
+	char enetvar[ETH_ENETADDR_ENV_NAME_LEN];
+
+	snprintf(enetvar, ETH_ENETADDR_ENV_NAME_LEN,
+		 index ? "%s%daddr" : "%saddr", base_name, index);
 	return eth_getenv_enetaddr(enetvar, enetaddr);
 }
 
 int eth_setenv_enetaddr_by_index(const char *base_name, int index,
 				 uchar *enetaddr)
 {
-	char enetvar[32];
-	sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
+	char enetvar[ETH_ENETADDR_ENV_NAME_LEN];
+
+	snprintf(enetvar, ETH_ENETADDR_ENV_NAME_LEN,
+		 index ? "%s%daddr" : "%saddr", base_name, index);
 	return eth_setenv_enetaddr(enetvar, enetaddr);
 }
 
@@ -72,7 +76,7 @@ void eth_common_init(void)
 
 int eth_mac_skip(int index)
 {
-	char enetvar[15];
+	char enetvar[ETH_ENETADDR_ENV_NAME_LEN];
 	char *skip_state;
 
 	sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
Signature · 1 line
2.11.0
#5 lore raw

PATCH v2 2/21 net: core: Sanitize get/set operations for enetaddr

Quoted 9 lines · Olliver Schinagl

In the current net stack, we have a few functions to get and set the "ethaddr" and "ethNaddr" environment variables, which use magic values to get and set these environment variables. Remove the magicness of the buffer by defining it proper and also check the input for its length.

Additionally use the define in fdt parser where the ethaddr variables are also used.

Quoted 6 lines
---
 common/fdt_support.c |  2 +-
 include/net.h        |  1 +
 net/eth_common.c     | 14 +++++++++-----
 3 files changed, 11 insertions(+), 6 deletions(-)
#6 lore raw

PATCH v2 3/21 net: core: Inform the user of the device MAC address

In reply to Olliver Schinagl

In certain conditions we currently print the MAC address. For example a warning when a random mac address is in use or a missmatch between HW and ENV.

If all things went well however (but even if there is a miss-match) we do not inform the user what the final MAC address of the device is.

Lets print the final MAC address of the device with which it has been setup.

---
 net/eth-uclass.c | 9 ++++++---
 net/eth_legacy.c | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)
net/eth-uclass.c +6 -3
index c3cc3152a2..781376955a 100644
@@ -413,11 +413,12 @@ int eth_initialize(void)
 		}
 
 		bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
+		putc('\n');
 		do {
-			if (num_devices)
-				printf(", ");
+			struct eth_pdata *pdata = dev->platdata;
 
-			printf("eth%d: %s", dev->seq, dev->name);
+			printf("eth%d:  %s [%pM]\n", dev->seq, dev->name,
+						     pdata->enetaddr);
 
 			if (ethprime && dev == prime_dev)
 				printf(" [PRIME]");
@@ -525,6 +526,8 @@ static int eth_post_probe(struct udevice *dev)
 #endif
 	}
 
+	printf("%s ", dev->name);
+
 	return 0;
 }
 
net/eth_legacy.c +3 -0
index e4bd0f4c1a..687763682a 100644
@@ -179,6 +179,9 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 			       dev->name);
 	}
 
+	printf("%s (eth%d) has MAC address: %pM\n",
+	       dev->name, eth_number, dev->enetaddr);
+
 	return ret;
 }
 
Signature · 1 line
2.11.0
#7 lore raw

PATCH v2 3/21 net: core: Inform the user of the device MAC address

Hi Oliver,

Quoted 50 lines · Olliver Schinagl

In certain conditions we currently print the MAC address. For example a warning when a random mac address is in use or a missmatch between HW and ENV.

If all things went well however (but even if there is a miss-match) we do not inform the user what the final MAC address of the device is.

Lets print the final MAC address of the device with which it has been setup.

---
 net/eth-uclass.c | 9 ++++++---
 net/eth_legacy.c | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)
net/eth-uclass.c +6 -3
index c3cc3152a2..781376955a 100644
@@ -413,11 +413,12 @@ int eth_initialize(void)
                }
 
                bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
+               putc('\n');
                do {
-                       if (num_devices)
-                               printf(", ");
+                       struct eth_pdata *pdata = dev->platdata;
 
-                       printf("eth%d: %s", dev->seq, dev->name);
+                       printf("eth%d:  %s [%pM]\n", dev->seq, dev->name,
+                                                    pdata->enetaddr);
 
                        if (ethprime && dev == prime_dev)
                                printf(" [PRIME]");
@@ -525,6 +526,8 @@ static int eth_post_probe(struct udevice *dev)
 #endif
        }
 
+       printf("%s ", dev->name);
+
        return 0;
 }
 
net/eth_legacy.c +0 -0
index e4bd0f4c1a..687763682a 100644

net/eth_legacy.c int eth_write_hwaddr(struct eth_device *dev, const char *base_name, · line 183

Quoted 5 lines
net/eth_legacy.c +2 -0
@@ -179,6 +179,9 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
                               dev->name);
        }
 
+       printf("%s (eth%d) has MAC address: %pM\n",
+              dev->name, eth_number, dev->enetaddr);

As a general rule I don't think we should be adding new features to legacy code. If people want the new features they can switch over to driver model.

Regards,
Simon

#8 lore raw

PATCH v2 4/21 net: core: Add function to check/set MAC locality

In reply to Olliver Schinagl

Universally administered and locally administered addresses are distinguished by setting the second-least-significant bit of the first octet of the address. Having a function to check and set this U/L bit from a function makes it nice for boards that want to generate their own mac address to ensure they are locally administered.

---
 include/net.h | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
include/net.h +23 -1
index b4af8eaae4..b1d6f05a76 100644
@@ -779,6 +779,28 @@ static inline int is_multicast_ethaddr(const u8 *addr)
 	return 0x01 & addr[0];
 }
 
+/**
+ * is_local_ethaddr - Determine if the Ethernet address is a locally
+ *		      administered MAC address.
+ * @addr:	Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return true if the address is a locally administered address.
+ */
+static inline int is_local_ethaddr(const u8 *addr)
+{
+	return 0x02 & addr[0];
+}
+
+/**
+ * set_local_ethaddr - Make the supplied Ethernet address a locally
+ * 		       administered one.
+ * @addr:	Pointer to a six-byte array containing the Ethernet address
+ */
+static inline void set_local_ethaddr(u8 *addr)
+{
+	addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */
+}
+
 /*
  * is_broadcast_ethaddr - Determine if the Ethernet address is broadcast
  * @addr: Pointer to a six-byte array containing the Ethernet address
@@ -823,7 +845,7 @@ static inline void net_random_ethaddr(uchar *addr)
 		addr[i] = rand_r(&seed);
 
 	addr[0] &= 0xfe;	/* clear multicast bit */
-	addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */
+	set_local_ethaddr(addr);
 }
 
 /* Convert an IP address to a string */
Signature · 1 line
2.11.0
#9 lore raw

PATCH v2 4/21 net: core: Add function to check/set MAC locality

A first comment I have myself, which will go in a v3 (or as a separate patch after this has been merged):

Quoted 16 lines · Olliver Schinagl

Universally administered and locally administered addresses are distinguished by setting the second-least-significant bit of the first octet of the address. Having a function to check and set this U/L bit from a function makes it nice for boards that want to generate their own mac address to ensure they are locally administered.

---
 include/net.h | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
include/net.h +0 -0
index b4af8eaae4..b1d6f05a76 100644

include/net.h static inline int is_multicast_ethaddr(const u8 *addr) · line 780

Quoted 2 lines
include/net.h +0 -0
@@ -779,6 +779,28 @@ static inline int is_multicast_ethaddr(const u8 *addr)
 	return 0x01 & addr[0];
 }

0x01 can be a defien,

include/net.h static inline int is_multicast_ethaddr(const u8 *addr) · line 791

Quoted 11 lines
include/net.h +10 -0
+/**
+ * is_local_ethaddr - Determine if the Ethernet address is a locally
+ *		      administered MAC address.
+ * @addr:	Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return true if the address is a locally administered address.
+ */
+static inline int is_local_ethaddr(const u8 *addr)
+{
+	return 0x02 & addr[0];

0x02 can be a define as well

Quoted 25 lines
include/net.h +13 -1
+}
+
+/**
+ * set_local_ethaddr - Make the supplied Ethernet address a locally
+ * 		       administered one.
+ * @addr:	Pointer to a six-byte array containing the Ethernet address
+ */
+static inline void set_local_ethaddr(u8 *addr)
+{
+	addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */
+}
+
 /*
  * is_broadcast_ethaddr - Determine if the Ethernet address is broadcast
  * @addr: Pointer to a six-byte array containing the Ethernet address
@@ -823,7 +845,7 @@ static inline void net_random_ethaddr(uchar *addr)
 		addr[i] = rand_r(&seed);
 
 	addr[0] &= 0xfe;	/* clear multicast bit */
-	addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */
+	set_local_ethaddr(addr);
 }
 
 /* Convert an IP address to a string */
#10 lore raw

PATCH v2 5/21 net: Add ability to set MAC address via EEPROM

In reply to Olliver Schinagl

This patch allows Kconfig to enable and set parameters to make it possible to read the MAC address from an EEPROM. The net core layer then uses this information to read MAC addresses from this EEPROM.

Besides the various tuneables as to how to access the eeprom (bus, address, addressing mode/length, 2 configurable that are EEPROM generic (e.g. SPI or some other form of access) which are:

NET_ETHADDR_EEPROM_OFFSET, indicating where in the EEPROM the start of the MAC address is. The default is 8 allowing for 8 bytes before the MAC for other purposes (header MAGIC for example).

NET_ETHADDR_EEPROM_CRC8, indicating the MAC is appended with a CRC8-CCIT checksum that should be verified.

Currently only I2C eeproms have been tested and thus only those options are available, but shouldn't be a limit. NET_ETHADDR_EEPROM_SPI can be just as created and added.

The code currently first checks if there is a non-zero MAC address in the eeprom. If that fails to be the case, the read_rom_hwaddr can be used by a board to supply the MAC in other ways.

If both these fails, the other code is still in place to query the environent, which then can be used to override the hardware supplied data.

---
 doc/README.enetaddr | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/net.h       | 14 ++++++++
 net/Kconfig         | 59 +++++++++++++++++++++++++++++++
 net/eth-uclass.c    | 42 +++++++++++------------
 net/eth_common.c    | 37 ++++++++++++++++++++
 net/eth_legacy.c    |  2 ++
 6 files changed, 231 insertions(+), 22 deletions(-)
doc/README.enetaddr +99 -0
index 50e4899787..89c1f7d6b4 100644
@@ -47,6 +47,105 @@ Correct flow of setting up the MAC address (summarized):
 Previous behavior had the MAC address always being programmed into hardware
 in the device's init() function.
 
+--------
+ EEPROM
+--------
+
+Boards may come with an EEPROM specifically to store configuration bits, such
+as a MAC address. Using CONFIG_NET_ETHADDR_EEPROM enables this feature.
+Depending on the board, the EEPROM may be connected on various methods, but
+currently, only the I2C bus can be used via CONFIG_NET_ETHADDR_EEPROM_I2C.
+
+The following config options are available,
+CONFIG_NET_ETHADDR_EEPROM_I2C_BUS is the I2C bus on which the eeprom is present.
+CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR sets the address of the EEPROM, which
+defaults to the very common 0x50. Small size EEPROM's generally use single byte
+addressing but larger EEPROM's may use double byte addressing, which can be
+configured using CONFIG_NET_ETHADDR_EEPROM_ADDRLEN.
+
+Within the EEPROM, the MAC address can be stored on any arbitrary offset,
+CONFIG_NET_ETHADDR_EEPROM_OFFSET sets this to 8 as a default however, allowing
+the first 8 bytes to be used for an optional data, for example a configuration
+struct where the mac address is part of.
+
+Appending the 6 (ARP_HLEN) bytes is a CRC8 byte over the previous ARP_HLEN
+bytes. Whether to check this CRC8 or not is dependent on
+CONFIG_NET_ETHADDR_EEPROM_CRC8.
+
+To keep things nicely aligned, a final 'reserved' byte is added to the mac
+address + crc8 combo.
+
+A board may want to store more information in its eeprom, using the following
+example layout, this can be achieved.
+
+struct mac_addr {
+	uint8_t mac[ARP_HLEN];
+	uint8_t crc8;
+	uint8_t reserved;
+};
+
+struct config_eeprom {
+	uint32_t magic;
+	uint8_t version;
+	uint8_t reserved[2];
+	uint8_t mac_cnt;
+	struct mac_addr[mac_cnt];
+};
+
+Filling this in:
+struct config_eeprom eeprom = {
+	.magic = { 'M', 'g', 'i', 'c' },
+	.reserved = { 0x00, 0x00 },
+	.mac_cnt = 2,
+	.mac_addr = {
+		{
+			.mac = {
+				0x01, 0x23, 0x45,
+				0x67, 0x89, 0xab,
+			},
+			.crc8 = 0xbe,
+			.reserved = 0x00,
+		}, {
+			.mac = {
+				0xba, 0x98, 0x76,
+				0x54, 0x32, 0x10,
+			},
+			.crc8 = 0x82,
+			.reserved = 0x00,
+		},
+	},
+};
+
+The eeprom content would look like this.
+
+00000000  4d 67 69 63 01 00 00 02  01 23 45 67 89 ab be 00 |Mgic.....#Eg....|
+00000010  ba 98 76 54 32 10 82 00                          |..vT2...|
+
+This can be done from linux using the i2c-tools:
+
+i2cset I2CBUS 0x50 0x08 0x01
+i2cset I2CBUS 0x50 0x09 0x23
+i2cset I2CBUS 0x50 0x0a 0x45
+i2cset I2CBUS 0x50 0x0b 0x67
+i2cset I2CBUS 0x50 0x0c 0x89
+i2cset I2CBUS 0x50 0x0d 0xab
+i2cset I2CBUS 0x50 0x0e 0xbe
+
+Alternativly this can be done from the u-boot console as:
+
+u-boot> mm.b 0
+00000000: 00 ? 01
+00000001: 23 ? 23
+00000002: 45 ? 45
+00000003: 67 ? 67
+00000004: 89 ? 89
+00000005: ab ? ab
+00000006: be ? be
+00000007: 00 ? q
+i2c dev I2CBUS
+i2c write 0 50 8 7
+i2c md 50 8
+
 -------
  Usage
 -------
include/net.h +14 -0
index b1d6f05a76..7c66f3f06d 100644
@@ -248,6 +248,20 @@ int eth_getenv_enetaddr(const char *name, uchar *enetaddr);
 int eth_setenv_enetaddr(const char *name, const uchar *enetaddr);
 
 /**
+ * eeprom_read_enetaddr() - Read the hardware address from an eeprom
+ *
+ * This function tries to read the MAC address from an eeprom as can be read
+ * in docs/README.enetaddr.
+ *
+ * @index:	index of the interface to get the hwaddr for
+ * @enetaddr:	pointer for the found hwaddr. Needs to be atleast ARP_HLEN
+ * @return:	0 on success, non-zero is error status. Additionally hwaddr
+ *		is set to 00:00:00:00:00. This is also the case if
+ *		CONFIG_NET_ETHADDR_EEPROM is not set.
+ */
+int eeprom_read_enetaddr(const int index, unsigned char *enetaddr);
+
+/**
  * eth_setenv_enetaddr_by_index() - set the MAC address environment variable
  *
  * This sets up an environment variable with the given MAC address (@enetaddr).
net/Kconfig +59 -0

65 lines not on this page · raw message

net/eth-uclass.c +20 -22

65 lines not on this page · raw message

net/eth_common.c +37 -0
index 0fe4d260d8..24488746c9 100644
@@ -8,10 +8,47 @@
 
 #include <common.h>
 #include <dm.h>
+#include <i2c.h>
 #include <miiphy.h>
 #include <net.h>
 #include "eth_internal.h"
 
+int eeprom_read_enetaddr(const int index, unsigned char *enetaddr)
+{
+	uint8_t eeprom[ARP_HLEN + 1] = { 0x00 };
+#if defined(CONFIG_NET_ETHADDR_EEPROM) && defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+	int old_i2c_bus;
+
+	if ((index < 0) && !enetaddr)
+		return -ENOSYS;
+
+	old_i2c_bus = i2c_get_bus_num();
+	if (old_i2c_bus != CONFIG_NET_ETHADDR_EEPROM_I2C_BUS)
+		i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+	/* Skip in blocks of 8 (ARP + CRC8 + pad), but read 7 from the eeprom */
+	if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+		     CONFIG_NET_ETHADDR_EEPROM_OFFSET + (index * (ARP_HLEN + 2)),
+		     CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+		     eeprom, ARP_HLEN + 1)) {
+		i2c_set_bus_num(old_i2c_bus);
+		puts("Could not read I2C EEPROM or EEPROM missing on device: ");
+		return -ENOSYS;
+	}
+	i2c_set_bus_num(old_i2c_bus);
+
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+	if (crc8(0, eeprom, ARP_HLEN) != eeprom[ARP_HLEN]) {
+		puts("CRC error on MAC address from I2C EEPROM on device: ");
+		return -EINVAL;
+	}
+#endif
+#endif
+
+	memcpy(enetaddr, eeprom, ARP_HLEN);
+
+	return 0;
+}
+
 void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
 {
 	char *end;
net/eth_legacy.c +2 -0
index 687763682a..ca63e43c1d 100644
@@ -137,6 +137,8 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 	unsigned char env_enetaddr[ARP_HLEN];
 	int ret = 0;
 
+	eeprom_read_enetaddr(eth_number, dev->enetaddr);
+
 	eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr);
 
 	if (!is_zero_ethaddr(env_enetaddr)) {
Signature · 1 line
2.11.0
#11 lore raw

PATCH v2 6/21 net: core: print the source of the MAC address

In reply to Olliver Schinagl

With many potential places where a MAC address can be read from, the user may not know where the MAC address originated from. Print the MAC source after initializing the Ethernet device.

---
 include/net.h    | 14 ++++++++++++++
 net/eth-uclass.c | 18 +++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)
include/net.h +14 -0
index 7c66f3f06d..3eb5f81ea5 100644
@@ -87,18 +87,32 @@ enum eth_state_t {
 	ETH_STATE_ACTIVE
 };
 
+enum enetaddr_source {
+	ENETADDR_SRC_UNKNOWN = 0,
+	ENETADDR_SRC_ROM,
+	ENETADDR_SRC_EEPROM,
+	ENETADDR_SRC_DRIVER,
+	ENETADDR_SRC_BOARD,
+	ENETADDR_SRC_ENV,
+	ENETADDR_SRC_FDT,
+	ENETADDR_SRC_RANDOM,
+	ENETADDR_SRC_NONE,
+};
+
 #ifdef CONFIG_DM_ETH
 /**
  * struct eth_pdata - Platform data for Ethernet MAC controllers
  *
  * @iobase: The base address of the hardware registers
  * @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env
+ * @enetaddr_source: Indicator where the Ethernet MAC adress came from
  * @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_...
  * @max_speed: Maximum speed of Ethernet connection supported by MAC
  */
 struct eth_pdata {
 	phys_addr_t iobase;
 	unsigned char enetaddr[ARP_HLEN];
+	enum enetaddr_source enetaddr_src;
 	int phy_interface;
 	int max_speed;
 };
net/eth-uclass.c +15 -3
index 02ee926f74..c88b032868 100644
@@ -416,9 +416,21 @@ int eth_initialize(void)
 		putc('\n');
 		do {
 			struct eth_pdata *pdata = dev->platdata;
-
-			printf("eth%d:  %s [%pM]\n", dev->seq, dev->name,
-						     pdata->enetaddr);
+			const char *enetaddr_src[] = {
+				"unknown",
+				"ROM",
+				"EEPROM",
+				"driver",
+				"board",
+				"environment",
+				"flattened device tree",
+				"randomly generated",
+				"not set",
+			};
+
+			printf("eth%d:  %s [%pM] (%s)\n", dev->seq, dev->name,
+							  pdata->enetaddr,
+							  enetaddr_src[pdata->enetaddr_src]);
 
 			if (ethprime && dev == prime_dev)
 				printf(" [PRIME]");
Signature · 1 line
2.11.0
#12 lore raw

PATCH v2 7/21 net: cosmetic: A MAC address is not limited to SROM

In reply to Olliver Schinagl

Currently, we print that the MAC from the SROM does not match. It can be many forms of ROM, so lets drop the S.

---
 net/eth_legacy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/eth_legacy.c +1 -1
index ca63e43c1d..8c3a1750ea 100644
@@ -146,7 +146,7 @@ int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
 		    memcmp(dev->enetaddr, env_enetaddr, ARP_HLEN)) {
 			printf("\nWarning: %s MAC addresses don't match:\n",
 			       dev->name);
-			printf("Address in SROM is         %pM\n",
+			printf("Address in ROM is         %pM\n",
 			       dev->enetaddr);
 			printf("Address in environment is  %pM\n",
 			       env_enetaddr);
Signature · 1 line
2.11.0
#13 lore raw

PATCH v2 8/21 fdt: fixup_eth: Remove code duplication with a function

In reply to Olliver Schinagl

In fdt_support.c we use a loop to parse the mac address string from the fdt blob, net.h has a function for this however, so lets use it.

Also, rename the variable from tmp to something more descriptive.

---
 common/fdt_support.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
common/fdt_support.c +5 -10
index d462bf0642..4d05465232 100644
@@ -469,8 +469,8 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size)
 
 void fdt_fixup_ethernet(void *fdt)
 {
-	int i, j, prop;
-	char *tmp, *end;
+	int i, prop;
+	char *fdt_eth_addr;
 	char mac[ETH_ENETADDR_ENV_NAME_LEN];
 	const char *path;
 	unsigned char mac_addr[ARP_HLEN];
@@ -509,16 +509,11 @@ void fdt_fixup_ethernet(void *fdt)
 			} else {
 				continue;
 			}
-			tmp = getenv(mac);
-			if (!tmp)
+			fdt_eth_addr = getenv(mac);
+			if (!fdt_eth_addr)
 				continue;
 
-			for (j = 0; j < 6; j++) {
-				mac_addr[j] = tmp ?
-					      simple_strtoul(tmp, &end, 16) : 0;
-				if (tmp)
-					tmp = (*end) ? end + 1 : end;
-			}
+			eth_parse_enetaddr(fdt_eth_addr, mac_addr);
 
 			do_fixup_by_path(fdt, path, "mac-address",
 					 &mac_addr, 6, 0);
Signature · 1 line
2.11.0
#14 lore raw

PATCH v2 9/21 fdt: fixup_eth: improve error catching/reduce identation

In reply to Olliver Schinagl

Currently when checking for an error in ethernet aliases in the fdt, we only check for the error case -1. It is safer to ignore anything < 0.

By rearranging logic a bit we can now also reduce identation.

---
 common/fdt_support.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
common/fdt_support.c +10 -10
index 4d05465232..71cbee43e0 100644
@@ -501,20 +501,20 @@ void fdt_fixup_ethernet(void *fdt)
 			else
 				i = trailing_strtol(name);
 
-			if (i != -1) {
-				if (i == 0)
-					strcpy(mac, "ethaddr");
-				else
-					sprintf(mac, "eth%daddr", i);
-			} else {
+			if (i < 0)
 				continue;
-			}
+
+			if (i == 0)
+				strcpy(mac, "ethaddr");
+			else
+				sprintf(mac, "eth%daddr", i);
+
 			fdt_eth_addr = getenv(mac);
-			if (!fdt_eth_addr)
+			if (fdt_eth_addr)
+				eth_parse_enetaddr(fdt_eth_addr, mac_addr);
+			else
 				continue;
 
-			eth_parse_enetaddr(fdt_eth_addr, mac_addr);
-
 			do_fixup_by_path(fdt, path, "mac-address",
 					 &mac_addr, 6, 0);
 			do_fixup_by_path(fdt, path, "local-mac-address",
Signature · 1 line
2.11.0
#15 lore raw

PATCH v2 10/21 net: sunxi: Enable I2C bus set via NET_ETHADDR_EEPROM_I2C_BUS

In reply to Olliver Schinagl

A user may select the connected eeprom address via NET_ETHADDR_EEPROM_I2C_BUS, but not enable it (I2Cn_ENABLE). To prevent this mistake, enable the I2C controller selected via NET_ETHADDR_EEPROM_I2C_BUS.

This in turn simplifies the defconfig.

---
 board/sunxi/Kconfig                   | 4 ++++
 configs/A10-OLinuXino-Lime_defconfig  | 1 -
 configs/A20-OLinuXino-Lime2_defconfig | 1 -
 configs/A20-OLinuXino-Lime_defconfig  | 1 -
 configs/A20-OLinuXino_MICRO_defconfig | 1 -
 5 files changed, 4 insertions(+), 4 deletions(-)
board/sunxi/Kconfig +4 -0
index 962da09136..e515175117 100644
@@ -441,6 +441,7 @@ config I2C0_ENABLE
 
 config I2C1_ENABLE
 	bool "Enable I2C/TWI controller 1"
+	default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
 	default n
 	select CMD_I2C
 	---help---
@@ -448,6 +449,7 @@ config I2C1_ENABLE
 
 config I2C2_ENABLE
 	bool "Enable I2C/TWI controller 2"
+	default y if (NET_ETHADDR_EEPROM_I2C_BUS = 2)
 	default n
 	select CMD_I2C
 	---help---
@@ -455,6 +457,7 @@ config I2C2_ENABLE
 
 if MACH_SUN6I || MACH_SUN7I
 config I2C3_ENABLE
+	default y if (NET_ETHADDR_EEPROM_I2C_BUS = 3)
 	bool "Enable I2C/TWI controller 3"
 	default n
 	select CMD_I2C
@@ -475,6 +478,7 @@ endif
 if MACH_SUN7I
 config I2C4_ENABLE
 	bool "Enable I2C/TWI controller 4"
+	default y if (NET_ETHADDR_EEPROM_I2C_BUS = 4)
 	default n
 	select CMD_I2C
 	---help---
configs/A10-OLinuXino-Lime_defconfig +0 -1
index 6634139ab8..7a8756620a 100644
@@ -17,7 +17,6 @@ CONFIG_SPL_I2C_SUPPORT=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
-CONFIG_I2C1_ENABLE=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
configs/A20-OLinuXino-Lime2_defconfig +0 -1
index 4c720b3109..0d7d5f042f 100644
@@ -24,7 +24,6 @@ CONFIG_ETH_DESIGNWARE=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
-CONFIG_I2C1_ENABLE=y
 CONFIG_AXP_ALDO3_VOLT=2800
 CONFIG_AXP_ALDO4_VOLT=2800
 CONFIG_USB_EHCI_HCD=y
configs/A20-OLinuXino-Lime_defconfig +0 -1
index 564ae256a3..a90d681064 100644
@@ -19,7 +19,6 @@ CONFIG_ETH_DESIGNWARE=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
-CONFIG_I2C1_ENABLE=y
 CONFIG_AXP_ALDO3_VOLT=2800
 CONFIG_AXP_ALDO4_VOLT=2800
 CONFIG_USB_EHCI_HCD=y
configs/A20-OLinuXino_MICRO_defconfig +0 -1
index 93be13b407..d0bfa9c3c0 100644
@@ -22,7 +22,6 @@ CONFIG_ETH_DESIGNWARE=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
-CONFIG_I2C1_ENABLE=y
 CONFIG_AXP_ALDO3_VOLT=2800
 CONFIG_AXP_ALDO4_VOLT=2800
 CONFIG_USB_EHCI_HCD=y
Signature · 1 line
2.11.0
#16 lore raw

PATCH v2 11/21 net: sunxi_[eg]mac: Convert to Kconfig

In reply to Olliver Schinagl

Convert both the sunxi_emac and sunxi_gmac drivers to use KConfig.

---
 configs/A10-OLinuXino-Lime_defconfig       |  3 ++-
 configs/A10s-OLinuXino-M_defconfig         |  2 +-
 configs/A20-OLinuXino-Lime2_defconfig      |  4 ++--
 configs/A20-OLinuXino-Lime_defconfig       |  4 ++--
 configs/A20-OLinuXino_MICRO_defconfig      |  4 ++--
 configs/A20-Olimex-SOM-EVB_defconfig       |  4 ++--
 configs/Bananapi_defconfig                 |  4 ++--
 configs/Bananapro_defconfig                |  4 ++--
 configs/CSQ_CS908_defconfig                |  3 +--
 configs/Colombus_defconfig                 |  4 ++--
 configs/Cubieboard2_defconfig              |  4 ++--
 configs/Cubieboard_defconfig               |  3 ++-
 configs/Cubietruck_defconfig               |  4 ++--
 configs/Hummingbird_A31_defconfig          |  4 ++--
 configs/Itead_Ibox_A20_defconfig           |  4 ++--
 configs/Lamobo_R1_defconfig                |  4 ++--
 configs/Linksprite_pcDuino3_Nano_defconfig |  4 ++--
 configs/Linksprite_pcDuino3_defconfig      |  4 ++--
 configs/Linksprite_pcDuino_defconfig       |  2 +-
 configs/Marsboard_A10_defconfig            |  2 +-
 configs/Mele_A1000G_quad_defconfig         |  3 +--
 configs/Mele_A1000_defconfig               |  3 ++-
 configs/Mele_I7_defconfig                  |  3 +--
 configs/Mele_M3_defconfig                  |  3 +--
 configs/Mele_M5_defconfig                  |  3 +--
 configs/Mele_M9_defconfig                  |  3 +--
 configs/Orangepi_defconfig                 |  4 ++--
 configs/Orangepi_mini_defconfig            |  4 ++--
 configs/Sinlinx_SinA31s_defconfig          |  3 +--
 configs/Sinovoip_BPI_M2_defconfig          |  4 ++--
 configs/Wits_Pro_A20_DKT_defconfig         |  4 ++--
 configs/ba10_tv_box_defconfig              |  2 +-
 configs/i12-tvbox_defconfig                |  4 ++--
 configs/icnova-a20-swac_defconfig          |  4 ++--
 configs/jesurun_q5_defconfig               |  3 ++-
 configs/mixtile_loftq_defconfig            |  4 ++--
 drivers/net/Kconfig                        | 25 +++++++++++++++++++++++++
 include/configs/sunxi-common.h             |  5 -----
 38 files changed, 86 insertions(+), 69 deletions(-)
configs/A10-OLinuXino-Lime_defconfig +2 -1
index 7a8756620a..c275461d51 100644
@@ -8,12 +8,13 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-olinuxino-lime"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC,SATAPWR=SUNXI_GPC(3)"
+CONFIG_SYS_EXTRA_OPTIONS="SATAPWR=SUNXI_GPC(3)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_FPGA is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
configs/A10s-OLinuXino-M_defconfig +1 -1
index 9c2a354ff4..9a319f6c9c 100644
@@ -8,7 +8,6 @@ CONFIG_MMC_SUNXI_SLOT_EXTRA=1
 CONFIG_USB1_VBUS_PIN="PB10"
 CONFIG_DEFAULT_DEVICE_TREE="sun5i-a10s-olinuxino-micro"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -17,5 +16,6 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_AXP152_POWER=y
 CONFIG_USB_EHCI_HCD=y
configs/A20-OLinuXino-Lime2_defconfig +2 -2
index 0d7d5f042f..126ead3ca2 100644
@@ -8,7 +8,7 @@ CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-lime2"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,SATAPWR=SUNXI_GPC(3)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,SATAPWR=SUNXI_GPC(3)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -20,7 +20,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_DFU_RAM=y
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
configs/A20-OLinuXino-Lime_defconfig +2 -2
index a90d681064..e134de2839 100644
@@ -6,7 +6,7 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-lime"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,SATAPWR=SUNXI_GPC(3)"
+CONFIG_SYS_EXTRA_OPTIONS="SATAPWR=SUNXI_GPC(3)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -15,7 +15,7 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
configs/A20-OLinuXino_MICRO_defconfig +2 -2
index d0bfa9c3c0..4f32f2f680 100644
@@ -9,7 +9,7 @@ CONFIG_VIDEO_VGA=y
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-micro"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,SATAPWR=SUNXI_GPB(8)"
+CONFIG_SYS_EXTRA_OPTIONS="SATAPWR=SUNXI_GPB(8)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -18,7 +18,7 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_NET_ETHADDR_EEPROM=y
 CONFIG_NET_ETHADDR_EEPROM_I2C=y
 CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
configs/A20-Olimex-SOM-EVB_defconfig +2 -2
index b835dc59b9..ae2e853b39 100644
@@ -11,7 +11,7 @@ CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olimex-som-evb"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,SATAPWR=SUNXI_GPC(3)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,SATAPWR=SUNXI_GPC(3)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -20,7 +20,7 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_ALDO3_VOLT=2800
 CONFIG_AXP_ALDO4_VOLT=2800
 CONFIG_USB_EHCI_HCD=y
configs/Bananapi_defconfig +2 -2
index 059559d393..9f47a13a4e 100644
@@ -7,7 +7,7 @@ CONFIG_GMAC_TX_DELAY=3
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPH(23)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,MACPWR=SUNXI_GPH(23)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -17,5 +17,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_NETCONSOLE=y
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Bananapro_defconfig +2 -2
index 27b9e63e00..dd4c03dd44 100644
@@ -9,7 +9,7 @@ CONFIG_GMAC_TX_DELAY=3
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapro"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPH(23)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,MACPWR=SUNXI_GPH(23)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -19,6 +19,6 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_NETCONSOLE=y
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_ALDO4_VOLT=2500
 CONFIG_USB_EHCI_HCD=y
configs/CSQ_CS908_defconfig +1 -2
index 953ec253c0..cbfee3def4 100644
@@ -6,7 +6,6 @@ CONFIG_USB1_VBUS_PIN=""
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31s-cs908"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -14,7 +13,7 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_AXP_DLDO1_VOLT=3300
 CONFIG_USB_EHCI_HCD=y
configs/Colombus_defconfig +2 -2
index ac283a2070..86c55500ac 100644
@@ -16,7 +16,7 @@ CONFIG_VIDEO_LCD_PANEL_I2C_SCL="PA24"
 CONFIG_VIDEO_LCD_PANEL_EDP_4_LANE_1620M_VIA_ANX9804=y
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-colombus"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -24,6 +24,6 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_USB_EHCI_HCD=y
configs/Cubieboard2_defconfig +2 -2
index 690ba49cfc..3e9510b253 100644
@@ -6,7 +6,7 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-cubieboard2"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,SATAPWR=SUNXI_GPB(8)"
+CONFIG_SYS_EXTRA_OPTIONS="SATAPWR=SUNXI_GPB(8)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -15,5 +15,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Cubieboard_defconfig +2 -1
index e1d1f1f8bb..fe56d1cc0b 100644
@@ -6,7 +6,7 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-cubieboard"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC,SATAPWR=SUNXI_GPB(8)"
+CONFIG_SYS_EXTRA_OPTIONS="SATAPWR=SUNXI_GPB(8)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -15,4 +15,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Cubietruck_defconfig +2 -2
index ca549bc298..e33804fc47 100644
@@ -11,7 +11,7 @@ CONFIG_GMAC_TX_DELAY=1
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-cubietruck"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,SATAPWR=SUNXI_GPH(12)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,SATAPWR=SUNXI_GPH(12)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -23,7 +23,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_DFU_RAM=y
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_MUSB_GADGET=y
 CONFIG_USB_GADGET=y
configs/Hummingbird_A31_defconfig +2 -2
index c1cbbc829a..e988b7d5bb 100644
@@ -8,7 +8,7 @@ CONFIG_VIDEO_VGA_VIA_LCD=y
 CONFIG_VIDEO_VGA_EXTERNAL_DAC_EN="PH25"
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-hummingbird"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -16,6 +16,6 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_USB_EHCI_HCD=y
configs/Itead_Ibox_A20_defconfig +2 -2
index c38d71f25a..80087723e9 100644
@@ -6,7 +6,7 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-itead-ibox"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,SATAPWR=SUNXI_GPB(8)"
+CONFIG_SYS_EXTRA_OPTIONS="SATAPWR=SUNXI_GPB(8)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -15,5 +15,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Lamobo_R1_defconfig +2 -2
index 92ae4e231d..6f83a4634f 100644
@@ -7,7 +7,7 @@ CONFIG_GMAC_TX_DELAY=4
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-lamobo-r1"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPH(23),SATAPWR=SUNXI_GPB(3)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,MACPWR=SUNXI_GPH(23),SATAPWR=SUNXI_GPB(3)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -16,5 +16,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Linksprite_pcDuino3_Nano_defconfig +2 -2
index 9c2cf8129f..9b1537e48d 100644
@@ -8,7 +8,7 @@ CONFIG_GMAC_TX_DELAY=3
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-pcduino3-nano"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,SATAPWR=SUNXI_GPH(2)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,SATAPWR=SUNXI_GPH(2)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -17,5 +17,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Linksprite_pcDuino3_defconfig +2 -2
index b245e7e0d7..21fb81ddc5 100644
@@ -6,7 +6,7 @@ CONFIG_DRAM_ZQ=122
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-pcduino3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,SATAPWR=SUNXI_GPH(2)"
+CONFIG_SYS_EXTRA_OPTIONS="SATAPWR=SUNXI_GPH(2)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -15,5 +15,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Linksprite_pcDuino_defconfig +1 -1
index 1d2ab19a0b..452f3bd212 100644
@@ -5,7 +5,6 @@ CONFIG_USB1_VBUS_PIN=""
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-pcduino"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -14,4 +13,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Marsboard_A10_defconfig +1 -1
index 34e78f1e8c..4deff8610a 100644
@@ -4,7 +4,6 @@ CONFIG_MACH_SUN4I=y
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-marsboard"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -12,5 +11,6 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_SUNXI_NO_PMIC=y
 CONFIG_USB_EHCI_HCD=y
configs/Mele_A1000G_quad_defconfig +1 -2
index 8f03835375..bbe60f13cc 100644
@@ -7,7 +7,6 @@ CONFIG_USB1_VBUS_PIN="PC27"
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-mele-a1000g-quad"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -15,7 +14,7 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_DCDC1_VOLT=3300
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_AXP_DLDO1_VOLT=3300
configs/Mele_A1000_defconfig +2 -1
index 4496688d3f..0df008e89a 100644
@@ -6,7 +6,7 @@ CONFIG_VIDEO_COMPOSITE=y
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-a1000"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC,MACPWR=SUNXI_GPH(15)"
+CONFIG_SYS_EXTRA_OPTIONS="MACPWR=SUNXI_GPH(15)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -15,4 +15,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Mele_I7_defconfig +1 -2
index 572b5219cc..55b756cdee 100644
@@ -6,7 +6,6 @@ CONFIG_USB1_VBUS_PIN="PC27"
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-i7"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -14,7 +13,7 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_DCDC1_VOLT=3300
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_AXP_DLDO1_VOLT=3300
configs/Mele_M3_defconfig +1 -2
index dd1526954b..1e0b2780a1 100644
@@ -8,7 +8,6 @@ CONFIG_VIDEO_VGA=y
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-m3"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -17,5 +16,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Mele_M5_defconfig +1 -2
index 12e1d0cae4..17fbf74cf1 100644
@@ -8,7 +8,6 @@ CONFIG_VIDEO_COMPOSITE=y
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-m5"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -17,5 +16,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Mele_M9_defconfig +1 -2
index a9dc159063..caf9aa3e09 100644
@@ -6,7 +6,6 @@ CONFIG_USB1_VBUS_PIN="PC27"
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-m9"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -14,7 +13,7 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_DCDC1_VOLT=3300
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_AXP_DLDO1_VOLT=3300
configs/Orangepi_defconfig +2 -2
index 3c9f74f3b4..31ba76fc95 100644
@@ -10,7 +10,7 @@ CONFIG_GMAC_TX_DELAY=3
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPH(23)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,MACPWR=SUNXI_GPH(23)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -19,5 +19,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Orangepi_mini_defconfig +2 -2
index f1d413b445..a6e8822442 100644
@@ -12,7 +12,7 @@ CONFIG_GMAC_TX_DELAY=3
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi-mini"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPH(23)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,MACPWR=SUNXI_GPH(23)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -21,5 +21,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/Sinlinx_SinA31s_defconfig +1 -2
index 54c975a2b2..86aa769930 100644
@@ -10,7 +10,6 @@ CONFIG_USB1_VBUS_PIN=""
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31s-sina31s"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -18,6 +17,6 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_DLDO1_VOLT=3300
 CONFIG_USB_EHCI_HCD=y
configs/Sinovoip_BPI_M2_defconfig +2 -2
index dbff2344bb..ad93c80b7b 100644
@@ -6,7 +6,7 @@ CONFIG_USB1_VBUS_PIN=""
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31s-sinovoip-bpi-m2"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -14,7 +14,7 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_AXP_ALDO2_VOLT=1800
 CONFIG_AXP_DLDO1_VOLT=3000
configs/Wits_Pro_A20_DKT_defconfig +2 -2
index cd6e821958..1ff3ce00cf 100644
@@ -11,7 +11,7 @@ CONFIG_VIDEO_LCD_PANEL_LVDS=y
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-wits-pro-a20-dkt"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -20,5 +20,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/ba10_tv_box_defconfig +1 -1
index ec71159151..1fa0c2bc74 100644
@@ -8,7 +8,6 @@ CONFIG_USB2_VBUS_PIN="PH12"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-ba10-tvbox"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -17,5 +16,6 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_MUSB_HOST=y
configs/i12-tvbox_defconfig +2 -2
index 9715bb9228..c03f32e577 100644
@@ -5,7 +5,7 @@ CONFIG_DRAM_CLK=384
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-i12-tvbox"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,MACPWR=SUNXI_GPH(21)"
+CONFIG_SYS_EXTRA_OPTIONS="MACPWR=SUNXI_GPH(21)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -14,5 +14,5 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/icnova-a20-swac_defconfig +2 -2
index 30e75e3c71..0c0dfb14f8 100644
@@ -12,7 +12,7 @@ CONFIG_VIDEO_LCD_POWER="PH22"
 CONFIG_VIDEO_LCD_PANEL_LVDS=y
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-icnova-swac"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER,SUNXI_GMAC,CMD_BMP"
+CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER,CMD_BMP"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -22,5 +22,5 @@ CONFIG_CMD_UNZIP=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_USB_EHCI_HCD=y
configs/jesurun_q5_defconfig +2 -1
index a6bec12fd2..d5a7d96bab 100644
@@ -6,7 +6,7 @@ CONFIG_USB0_VBUS_PIN="PB9"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-jesurun-q5"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_EMAC,MACPWR=SUNXI_GPH(19)"
+CONFIG_SYS_EXTRA_OPTIONS="MACPWR=SUNXI_GPH(19)"
 CONFIG_SPL=y
 CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_CMD_IMLS is not set
@@ -15,5 +15,6 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_SUNXI_EMAC=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_MUSB_HOST=y
configs/mixtile_loftq_defconfig +2 -2
index ec6a4381ac..3bba9583bc 100644
@@ -7,7 +7,7 @@ CONFIG_USB1_VBUS_PIN="PH24"
 CONFIG_USB2_VBUS_PIN=""
 CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-mixtile-loftq"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
-CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPA(21)"
+CONFIG_SYS_EXTRA_OPTIONS="RGMII,MACPWR=SUNXI_GPA(21)"
 CONFIG_SPL=y
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_FLASH is not set
@@ -15,6 +15,6 @@ CONFIG_SPL=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
-CONFIG_ETH_DESIGNWARE=y
+CONFIG_SUNXI_GMAC=y
 CONFIG_AXP_ALDO1_VOLT=3300
 CONFIG_USB_EHCI_HCD=y
drivers/net/Kconfig +25 -0
index 70e36611ea..9f088e1e7b 100644
@@ -161,6 +161,17 @@ config RTL8169
 	  This driver supports Realtek 8169 series gigabit ethernet family of
 	  PCI/PCIe chipsets/adapters.
 
+config SUNXI_EMAC
+	bool "Allwinner sunxi Ethernet MAC support"
+	depends on DM_ETH
+	select MII
+	select PHYLIB
+	help
+	  This driver provides the Allwinner based SoCs with 100 Megabit network
+	  support. This driver is known to have performance issues and should
+	  only be used on sun4i hardware. Newer hardware supports the
+	  SUNXI_GMAC driver, which also works with 100 Megabit PHY's.
+
 config SUN8I_EMAC
         bool "Allwinner Sun8i Ethernet MAC support"
         depends on DM_ETH
@@ -170,6 +181,20 @@ config SUN8I_EMAC
 	  It can be found in H3/A64/A83T based SoCs and compatible with both
 	  External and Internal PHYs.
 
+config SUNXI_GMAC
+	bool "Allwinner sunxi Ethernet GMAC support"
+	depends on DM_ETH
+	select ETH_DESIGNWARE
+	select MII
+	select PHYLIB
+	select PHY_GIGE
+	help
+	  This driver provides the Allwinner based SoCs network support based
+	  on the Synopsys Designware gigabit driver. The driver supports both
+	  RGMII and MII communications and can thus be used as a drop in
+	  replacement of the SUNXI_EMAC driver. CONFIG_RGMII needs to be set for
+	  gigabit PHY's that speak RGMII.
+
 config XILINX_AXIEMAC
 	depends on DM_ETH && (MICROBLAZE || ARCH_ZYNQ || ARCH_ZYNQMP)
 	select PHYLIB
include/configs/sunxi-common.h +0 -5
index 05ea172fe3..b3fed6fea1 100644
@@ -290,15 +290,10 @@ extern int soft_i2c_gpio_scl;
 /* Ethernet support */
 #ifdef CONFIG_SUNXI_EMAC
 #define CONFIG_PHY_ADDR		1
-#define CONFIG_MII			/* MII PHY management		*/
-#define CONFIG_PHYLIB
 #endif
 
 #ifdef CONFIG_SUNXI_GMAC
-#define CONFIG_PHY_GIGE			/* GMAC can use gigabit PHY	*/
 #define CONFIG_PHY_ADDR		1
-#define CONFIG_MII			/* MII PHY management		*/
-#define CONFIG_PHY_REALTEK
 #endif
 
 #ifdef CONFIG_USB_EHCI_HCD
Signature · 1 line
2.11.0
#17 lore raw

PATCH v2 12/21 arm: sunxi: Expose function to generate sunxi-specific a MAC address

In reply to Olliver Schinagl

Expose the function to generate a MAC adddress based on the serial number. This can then later be moved completly out of the sunxi board specific stuff.

The setup_environment quirky function still exists as it is still used to fixup the FDT for drivers that need the MAC address available in the FDT. Once that is changed, we can clean up some more.

---
 arch/arm/include/asm/arch-sunxi/sys_proto.h |   2 +
 board/sunxi/board.c                         | 145 ++++++++++++++++++----------
 2 files changed, 94 insertions(+), 53 deletions(-)
arch/arm/include/asm/arch-sunxi/sys_proto.h +2 -0
index a373319a2b..98effbf5c6 100644
@@ -30,4 +30,6 @@ void eth_init_board(void);
 static inline void eth_init_board(void) {}
 #endif
 
+int sunxi_gen_hwaddr(const int seq, unsigned char *enetaddr);
+
 #endif
board/sunxi/board.c +92 -53

181 lines not on this page · raw message

Signature · 1 line
2.11.0
#18 lore raw

PATCH v2 13/21 net: sunxi_emac: Write HW address via net_ops hook

In reply to Olliver Schinagl

Expose the write_hwaddr net_ops hook to write the Ethernet address.

---
 drivers/net/sunxi_emac.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/net/sunxi_emac.c +12 -0
index 99339db4bf..0dc37de242 100644
@@ -565,11 +565,23 @@ static int sunxi_emac_eth_probe(struct udevice *dev)
 	return sunxi_emac_init_phy(priv, dev);
 }
 
+static int sunxi_emac_eth_write_hwaddr(struct udevice *dev)
+{
+	struct eth_pdata *pdata = dev_get_platdata(dev);
+	struct emac_eth_dev *priv = dev_get_priv(dev);
+
+	if (!pdata)
+		return -ENOSYS;
+
+	return _sunxi_write_hwaddr(priv, pdata->enetaddr);
+}
+
 static const struct eth_ops sunxi_emac_eth_ops = {
 	.start			= sunxi_emac_eth_start,
 	.send			= sunxi_emac_eth_send,
 	.recv			= sunxi_emac_eth_recv,
 	.stop			= sunxi_emac_eth_stop,
+	.write_hwaddr		= sunxi_emac_eth_write_hwaddr,
 };
 
 static int sunxi_emac_eth_ofdata_to_platdata(struct udevice *dev)
Signature · 1 line
2.11.0
#19 lore raw

PATCH v2 14/21 net: sunxi: Have sunxi common functions together

In reply to Olliver Schinagl

The sun[8x]i network drivers have some common functions. Let's introduce a common file with the reading of the MAC address as a start.

In the future, we can move more sunxi shared/common code into this file.

---
 drivers/net/sunxi_common.c | 33 +++++++++++++++++++++++++++++++++
 drivers/net/sunxi_common.h | 13 +++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 drivers/net/sunxi_common.c
 create mode 100644 drivers/net/sunxi_common.h
drivers/net/sunxi_common.c new file +33 -0
new file mode 100644
index 0000000000..a0c0548059
@@ -0,0 +1,33 @@
+/*
+ * (c) Copyright 2017
+ * Author: Olliver Schinagl <[email protected]>
+ *
+ * SPX-License-Identifier:	GPL-3.0+
+ *
+ * Common code for the sunxi series of the ethernet sunxi glue code
+ *
+ */
+
+#include <asm/arch/sys_proto.h>
+#include <common.h>
+#include <dm/device.h>
+#include <net.h>
+#include <linux/types.h>
+
+/*
+ * Set ethernet MAC address based on serial number.
+ * FIXME: For now we call sunxi_gen_hwaddr to generate the MAC address there.
+ * This is done because we have some devices, which expect their MAC address to
+ * to be passed via the environment and obtained from the FDT. Once that code
+ * has been refactored (it is quircky to say the least), the mac generating code
+ * should live here.
+ */
+int sunxi_eth_read_rom_hwaddr(struct udevice *dev)
+{
+	struct eth_pdata *pdata = dev_get_platdata(dev);
+
+	if (!pdata || (dev->seq < 0))
+		return -ENOSYS;
+
+	return sunxi_gen_hwaddr(dev->seq, pdata->enetaddr);
+}
drivers/net/sunxi_common.h new file +13 -0
new file mode 100644
index 0000000000..79d33e40bb
@@ -0,0 +1,13 @@
+/*
+ * (c) Copyright 2017
+ * Author: Olliver Schinagl <[email protected]>
+ *
+ * SPX-License-Identifier:	GPL-3.0+
+ *
+ * Common code for the sunxi series of the ethernet sunxi glue code
+ *
+ */
+
+#include <dm/device.h>
+
+int sunxi_eth_read_rom_hwaddr(struct udevice *dev);
Signature · 1 line
2.11.0
#20 lore raw

PATCH v2 15/21 net: sunxi_emac: Add read_rom_hwaddr hook

In reply to Olliver Schinagl

With this patch sunxi_emac can now get the MAC address from the board in a predetermined board specific manner.

---
 drivers/net/Makefile     | 2 +-
 drivers/net/sunxi_emac.c | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/Makefile +1 -1
index 2493a48b88..c840770bd8 100644
@@ -23,7 +23,7 @@ obj-$(CONFIG_DNET) += dnet.o
 obj-$(CONFIG_E1000) += e1000.o
 obj-$(CONFIG_E1000_SPI) += e1000_spi.o
 obj-$(CONFIG_EEPRO100) += eepro100.o
-obj-$(CONFIG_SUNXI_EMAC) += sunxi_emac.o
+obj-$(CONFIG_SUNXI_EMAC) += sunxi_common.o sunxi_emac.o
 obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o
 obj-$(CONFIG_ENC28J60) += enc28j60.o
 obj-$(CONFIG_EP93XX) += ep93xx_eth.o
drivers/net/sunxi_emac.c +3 -0
index 0dc37de242..b50f0eec09 100644
@@ -16,6 +16,8 @@
 #include <asm/arch/clock.h>
 #include <asm/arch/gpio.h>
 
+#include "sunxi_common.h"
+
 /* EMAC register  */
 struct emac_regs {
 	u32 ctl;	/* 0x00 */
@@ -582,6 +584,7 @@ static const struct eth_ops sunxi_emac_eth_ops = {
 	.recv			= sunxi_emac_eth_recv,
 	.stop			= sunxi_emac_eth_stop,
 	.write_hwaddr		= sunxi_emac_eth_write_hwaddr,
+	.read_rom_hwaddr	= sunxi_eth_read_rom_hwaddr,
 };
 
 static int sunxi_emac_eth_ofdata_to_platdata(struct udevice *dev)
Signature · 1 line
2.11.0
#21 lore raw

PATCH v2 16/21 net: sunxi_gmac: Make the sunxi variant of dw driver a subclass

In reply to Olliver Schinagl

This patch removes the old sunxi_gmac glue layer and turns it into a proper sub-class driver.

---
 arch/arm/include/asm/arch-sunxi/sys_proto.h    |  7 ----
 arch/arm/mach-sunxi/board.c                    |  1 -
 board/sunxi/Makefile                           |  1 -
 drivers/net/Makefile                           |  1 +
 drivers/net/designware.c                       |  1 -
 board/sunxi/gmac.c => drivers/net/sunxi_gmac.c | 52 +++++++++++++++++++++++---
 6 files changed, 47 insertions(+), 16 deletions(-)
 rename board/sunxi/gmac.c => drivers/net/sunxi_gmac.c (69%)
arch/arm/include/asm/arch-sunxi/sys_proto.h +0 -7
index 98effbf5c6..42bdfc711a 100644
@@ -23,13 +23,6 @@ void sdelay(unsigned long);
  */
 void return_to_fel(uint32_t lr, uint32_t sp);
 
-/* Board / SoC level designware gmac init */
-#if !defined CONFIG_SPL_BUILD && defined CONFIG_SUNXI_GMAC
-void eth_init_board(void);
-#else
-static inline void eth_init_board(void) {}
-#endif
-
 int sunxi_gen_hwaddr(const int seq, unsigned char *enetaddr);
 
 #endif
arch/arm/mach-sunxi/board.c +0 -1
index 3a5840b9c0..64aed3180c 100644
@@ -200,7 +200,6 @@ void s_init(void)
 	timer_init();
 	gpio_init();
 	i2c_init_board();
-	eth_init_board();
 }
 
 #ifdef CONFIG_SPL_BUILD
board/sunxi/Makefile +0 -1
index 43766e0ef4..f2dba9532a 100644
@@ -9,7 +9,6 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 obj-y	+= board.o
-obj-$(CONFIG_SUNXI_GMAC)	+= gmac.o
 obj-$(CONFIG_SUNXI_AHCI)	+= ahci.o
 obj-$(CONFIG_MACH_SUN4I)	+= dram_sun4i_auto.o
 obj-$(CONFIG_MACH_SUN5I)	+= dram_sun5i_auto.o
drivers/net/Makefile +1 -0
index c840770bd8..3a0ab139c3 100644
@@ -24,6 +24,7 @@ obj-$(CONFIG_E1000) += e1000.o
 obj-$(CONFIG_E1000_SPI) += e1000_spi.o
 obj-$(CONFIG_EEPRO100) += eepro100.o
 obj-$(CONFIG_SUNXI_EMAC) += sunxi_common.o sunxi_emac.o
+obj-$(CONFIG_SUNXI_GMAC) += sunxi_gmac.o
 obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o
 obj-$(CONFIG_ENC28J60) += enc28j60.o
 obj-$(CONFIG_EP93XX) += ep93xx_eth.o
drivers/net/designware.c +0 -1
index f9fb8e0886..3e18f28232 100644
@@ -761,7 +761,6 @@ int designware_eth_ofdata_to_platdata(struct udevice *dev)
 }
 
 static const struct udevice_id designware_eth_ids[] = {
-	{ .compatible = "allwinner,sun7i-a20-gmac" },
 	{ .compatible = "altr,socfpga-stmmac" },
 	{ .compatible = "amlogic,meson6-dwmac" },
 	{ .compatible = "amlogic,meson-gx-dwmac" },
drivers/net/sunxi_gmac.c renamed from board/sunxi/gmac.c +46 -6

62 lines not on this page · raw message

Signature · 1 line
2.11.0
#22 lore raw

PATCH v2 17/21 net: dw: Expose designware_eth_start

In reply to Olliver Schinagl

Commit e72ced234045f ("net: designware: Export the operation functions") started to expose some of the net_ops. The sunxi_gmac glue driver also needs the start function, so let us expose that as well.

---
 drivers/net/designware.c | 2 +-
 drivers/net/designware.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/designware.c +1 -1
index 3e18f28232..ac8258c8bd 100644
@@ -585,7 +585,7 @@ int designware_initialize(ulong base_addr, u32 interface)
 #endif
 
 #ifdef CONFIG_DM_ETH
-static int designware_eth_start(struct udevice *dev)
+int designware_eth_start(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct dw_eth_dev *priv = dev_get_priv(dev);
drivers/net/designware.h +1 -0
index 7992d0ebee..24b64d975c 100644
@@ -260,6 +260,7 @@ int designware_eth_send(struct udevice *dev, void *packet, int length);
 int designware_eth_recv(struct udevice *dev, int flags, uchar **packetp);
 int designware_eth_free_pkt(struct udevice *dev, uchar *packet,
 				   int length);
+int designware_eth_start(struct udevice *dev);
 void designware_eth_stop(struct udevice *dev);
 int designware_eth_write_hwaddr(struct udevice *dev);
 #endif
Signature · 1 line
2.11.0
#23 lore raw

PATCH v2 18/21 net: sunxi_gmac: Add read_rom_hwaddr hook

In reply to Olliver Schinagl

With this patch sunxi_gmac can now get the MAC address from the board in a predetermined board specific manner.

---
 drivers/net/Makefile     | 2 +-
 drivers/net/sunxi_gmac.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/Makefile +1 -1
index 3a0ab139c3..1c0bca229b 100644
@@ -24,7 +24,7 @@ obj-$(CONFIG_E1000) += e1000.o
 obj-$(CONFIG_E1000_SPI) += e1000_spi.o
 obj-$(CONFIG_EEPRO100) += eepro100.o
 obj-$(CONFIG_SUNXI_EMAC) += sunxi_common.o sunxi_emac.o
-obj-$(CONFIG_SUNXI_GMAC) += sunxi_gmac.o
+obj-$(CONFIG_SUNXI_GMAC) += sunxi_common.o sunxi_gmac.o
 obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o
 obj-$(CONFIG_ENC28J60) += enc28j60.o
 obj-$(CONFIG_EP93XX) += ep93xx_eth.o
drivers/net/sunxi_gmac.c +2 -0
index 15f8164c34..0f6d124d2b 100644
@@ -15,6 +15,7 @@
 #include <net.h>
 
 #include "designware.h"
+#include "sunxi_common.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -102,6 +103,7 @@ const struct eth_ops sunxi_gmac_eth_ops = {
 	.free_pkt		= designware_eth_free_pkt,
 	.stop			= designware_eth_stop,
 	.write_hwaddr		= designware_eth_write_hwaddr,
+	.read_rom_hwaddr	= sunxi_eth_read_rom_hwaddr,
 };
 
 static const struct udevice_id sunxi_gmac_eth_ids[] = {
Signature · 1 line
2.11.0
#24 lore raw

PATCH v2 19/21 net: sun8i_gmac: Add read_rom_hwaddr hook

In reply to Olliver Schinagl

With this patch sun8i_emac can now get the MAC address from the board in a predetermined board specific manner.

---
 drivers/net/Makefile     | 2 +-
 drivers/net/sun8i_emac.c | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/net/Makefile +1 -1
index 1c0bca229b..b6e5640576 100644
@@ -25,7 +25,7 @@ obj-$(CONFIG_E1000_SPI) += e1000_spi.o
 obj-$(CONFIG_EEPRO100) += eepro100.o
 obj-$(CONFIG_SUNXI_EMAC) += sunxi_common.o sunxi_emac.o
 obj-$(CONFIG_SUNXI_GMAC) += sunxi_common.o sunxi_gmac.o
-obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o
+obj-$(CONFIG_SUN8I_EMAC) += sunxi_common.o sun8i_emac.o
 obj-$(CONFIG_ENC28J60) += enc28j60.o
 obj-$(CONFIG_EP93XX) += ep93xx_eth.o
 obj-$(CONFIG_ETHOC) += ethoc.o
drivers/net/sun8i_emac.c +3 -0
index b87210bad7..f2838f9f8f 100644
@@ -22,6 +22,8 @@
 #include <miiphy.h>
 #include <net.h>
 
+#include "sunxi_common.h"
+
 #define MDIO_CMD_MII_BUSY		BIT(0)
 #define MDIO_CMD_MII_WRITE		BIT(1)
 
@@ -705,6 +707,7 @@ static int sun8i_emac_eth_probe(struct udevice *dev)
 static const struct eth_ops sun8i_emac_eth_ops = {
 	.start                  = sun8i_emac_eth_start,
 	.write_hwaddr           = sun8i_eth_write_hwaddr,
+	.read_rom_hwaddr	= sunxi_eth_read_rom_hwaddr,
 	.send                   = sun8i_emac_eth_send,
 	.recv                   = sun8i_emac_eth_recv,
 	.free_pkt               = sun8i_eth_free_pkt,
Signature · 1 line
2.11.0
#25 lore raw

PATCH v2 20/21 net: sun8i: fix whitespace

In reply to Olliver Schinagl

Fix a few whitespaces errors in the sun8i driver.

---
 drivers/net/Kconfig      |  8 ++++----
 drivers/net/sun8i_emac.c | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/net/Kconfig +4 -4
index 9f088e1e7b..82685800aa 100644
@@ -173,10 +173,10 @@ config SUNXI_EMAC
 	  SUNXI_GMAC driver, which also works with 100 Megabit PHY's.
 
 config SUN8I_EMAC
-        bool "Allwinner Sun8i Ethernet MAC support"
-        depends on DM_ETH
-        select PHYLIB
-        help
+	bool "Allwinner Sun8i Ethernet MAC support"
+	depends on DM_ETH
+	select PHYLIB
+	help
           This driver supports the  Allwinner based SUN8I/SUN50I Ethernet MAC.
 	  It can be found in H3/A64/A83T based SoCs and compatible with both
 	  External and Internal PHYs.
drivers/net/sun8i_emac.c +6 -6
index f2838f9f8f..6a4dc40b84 100644
@@ -705,13 +705,13 @@ static int sun8i_emac_eth_probe(struct udevice *dev)
 }
 
 static const struct eth_ops sun8i_emac_eth_ops = {
-	.start                  = sun8i_emac_eth_start,
-	.write_hwaddr           = sun8i_eth_write_hwaddr,
+	.start			= sun8i_emac_eth_start,
+	.write_hwaddr		= sun8i_eth_write_hwaddr,
 	.read_rom_hwaddr	= sunxi_eth_read_rom_hwaddr,
-	.send                   = sun8i_emac_eth_send,
-	.recv                   = sun8i_emac_eth_recv,
-	.free_pkt               = sun8i_eth_free_pkt,
-	.stop                   = sun8i_emac_eth_stop,
+	.send			= sun8i_emac_eth_send,
+	.recv			= sun8i_emac_eth_recv,
+	.free_pkt		= sun8i_eth_free_pkt,
+	.stop			= sun8i_emac_eth_stop,
 };
 
 static int sun8i_emac_eth_ofdata_to_platdata(struct udevice *dev)
Signature · 1 line
2.11.0
#26 lore raw

PATCH v2 21/21 net: core: Check return value of read_rom_hwaddr

In reply to Olliver Schinagl

Currently, we silently ignore the return value of netops->read_rom_hwaddr(). This naturally is bad and we should check if the code ran successfully.

---
 net/eth-uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/eth-uclass.c +2 -2
index c88b032868..024136a7cb 100644
@@ -511,8 +511,8 @@ static int eth_post_probe(struct udevice *dev)
 		pdata->enetaddr_src = ENETADDR_SRC_EEPROM;
 	else
 		/* Check if the device driver has a MAC address */
-		if (eth_get_ops(dev)->read_rom_hwaddr) {
-			eth_get_ops(dev)->read_rom_hwaddr(dev);
+		if (eth_get_ops(dev)->read_rom_hwaddr &&
+		    !eth_get_ops(dev)->read_rom_hwaddr(dev)) {
 			pdata->enetaddr_src = ENETADDR_SRC_DRIVER;
 		}
 
Signature · 1 line
2.11.0
#27 lore raw

v5 cover Retrieve MAC address from EEPROM

In reply to Olliver Schinagl
Quoted 31 lines · Olliver Schinagl

First off:
P.S. Joe, for some reason my previous patches where added with me as:
"oliver at schinagl.nl <[email protected]>" I see that it comes from patchwork as such. Is there some way to fix this to
"Olliver Schinagl <[email protected]>"?

Below the updated summary:

This patch-series introduces methods to retrieve the MAC address from an onboard EEPROM. The series does a few small cleanups at the start, as either I ran into them while doing this series and fixed them along the way or actually depended on them.

A manufacturer wants to produce boards and may even have MAC addresses for boards. Maintaining unique environments on a per-board basis however is horrible. Also this data should be very persistent, and not easily deletable by simply wiping the environment or device tree. Finally there are chips available on the market with a pre-programmed MAC address chips (proms)
that a board manufacturer wants to use. Because of this, the MAC needs to be stored be able to read from such an 'external' source.

The current idea of the eeprom layout, is to skip the first 8 bytes, so that other information can be stored there if needed, for example a header with some magic to identify the EEPROM. Or equivalent purposes.

After those 8 bytes the MAC address follows the first macaddress. The macaddress is appended by a CRC8 byte and then padded to make for nice 8 bytes. Following the first macaddress one can store a second, or a third etc etc macaddress.

Quoted 4 lines

The CRC8 is optional (via a define) but is strongly recommended to have. It helps preventing user error and more importantly, checks if the bytes read are actually a user inserted address. E.g. only writing 1 macaddress into the eeprom but trying to consume 2.

Interesting solution. We have used EEPROM to store board ID, version number, MAC addresses on many of our boards. We have a command "mac" to read/write these addresses. Would you take a look to see if it is possible to integrate?

York

#28 lore raw

v5 cover Retrieve MAC address from EEPROM

Hey York,

Quoted 46 lines · York Sun
Quoted 38 lines · Olliver Schinagl

First off:
P.S. Joe, for some reason my previous patches where added with me as:
"oliver at schinagl.nl <[email protected]>" I see that it comes from patchwork
as such. Is there some way to fix this to
"Olliver Schinagl <[email protected]>"?

Below the updated summary:

This patch-series introduces methods to retrieve the MAC address from an onboard EEPROM. The series does a few small cleanups at the start, as either
I ran into them while doing this series and fixed them along the way or actually depended on them.

A manufacturer wants to produce boards and may even have MAC addresses for
boards. Maintaining unique environments on a per-board basis however is horrible. Also this data should be very persistent, and not easily deletable
by simply wiping the environment or device tree. Finally there are chips available on the market with a pre-programmed MAC address chips (proms)
that a board manufacturer wants to use. Because of this, the MAC needs to be
stored be able to read from such an 'external' source.

The current idea of the eeprom layout, is to skip the first 8 bytes, so that
other information can be stored there if needed, for example a header with some magic to identify the EEPROM. Or equivalent purposes.

After those 8 bytes the MAC address follows the first macaddress. The macaddress is appended by a CRC8 byte and then padded to make for nice 8 bytes.
Following the first macaddress one can store a second, or a third etc etc macaddress.

Quoted 6 lines

The CRC8 is optional (via a define) but is strongly recommended to have. It
helps preventing user error and more importantly, checks if the bytes read are actually a user inserted address. E.g. only writing 1 macaddress into
the eeprom but trying to consume 2.

Quoted 4 lines

Interesting solution. We have used EEPROM to store board ID, version number, MAC addresses on many of our boards. We have a command "mac" to read/write these addresses. Would you take a look to see if it is possible to integrate?

I feel bad for not noticing the mac command! I think that this indeed could get integrated, providing generic helpers.

Just wished you would have sent your suggestion during patch v1 or v2 :p

Olliver

Quoted 2 lines

York

#29 lore raw

v5 cover Retrieve MAC address from EEPROM

Quoted 54 lines · Olliver Schinagl

Hey York,

Quoted 46 lines · York Sun
Quoted 38 lines · Olliver Schinagl

First off:
P.S. Joe, for some reason my previous patches where added with me as:
"oliver at schinagl.nl <[email protected]>" I see that it comes from patchwork
as such. Is there some way to fix this to
"Olliver Schinagl <[email protected]>"?

Below the updated summary:

This patch-series introduces methods to retrieve the MAC address from an onboard EEPROM. The series does a few small cleanups at the start, as either
I ran into them while doing this series and fixed them along the way or actually depended on them.

A manufacturer wants to produce boards and may even have MAC addresses for
boards. Maintaining unique environments on a per-board basis however is horrible. Also this data should be very persistent, and not easily deletable
by simply wiping the environment or device tree. Finally there are chips available on the market with a pre-programmed MAC address chips (proms)
that a board manufacturer wants to use. Because of this, the MAC needs to be
stored be able to read from such an 'external' source.

The current idea of the eeprom layout, is to skip the first 8 bytes, so that
other information can be stored there if needed, for example a header with some magic to identify the EEPROM. Or equivalent purposes.

After those 8 bytes the MAC address follows the first macaddress. The macaddress is appended by a CRC8 byte and then padded to make for nice 8 bytes.
Following the first macaddress one can store a second, or a third etc etc macaddress.

Quoted 6 lines

The CRC8 is optional (via a define) but is strongly recommended to have. It
helps preventing user error and more importantly, checks if the bytes read are actually a user inserted address. E.g. only writing 1 macaddress into
the eeprom but trying to consume 2.

Quoted 4 lines

Interesting solution. We have used EEPROM to store board ID, version number, MAC addresses on many of our boards. We have a command "mac" to read/write these addresses. Would you take a look to see if it is possible to integrate?

Quoted 5 lines

I feel bad for not noticing the mac command! I think that this indeed could get integrated, providing generic helpers.

Just wished you would have sent your suggestion during patch v1 or v2 :p

Sorry, for some reason I wasn't CC'ed for your earlier version. They were buried in thousands of emails.

York

#30 lore raw

v5 cover Retrieve MAC address from EEPROM

Hey York,

Quoted 79 lines · York Sun
Quoted 78 lines · Olliver Schinagl

Hey York,

Quoted 64 lines · York Sun
Quoted 54 lines · Olliver Schinagl

First off:
P.S. Joe, for some reason my previous patches where added with me as:
"oliver at schinagl.nl <[email protected]>" I see that it comes from
patchwork
as such. Is there some way to fix this to
"Olliver Schinagl <[email protected]>"?

Below the updated summary:

This patch-series introduces methods to retrieve the MAC address from an
onboard EEPROM. The series does a few small cleanups at the start, as
either
I ran into them while doing this series and fixed them along the way or
actually depended on them.

A manufacturer wants to produce boards and may even have MAC addresses
for
boards. Maintaining unique environments on a per-board basis however is
horrible. Also this data should be very persistent, and not easily
deletable
by simply wiping the environment or device tree. Finally there are
chips available on the market with a pre-programmed MAC address chips
(proms)
that a board manufacturer wants to use. Because of this, the MAC needs
to be
stored be able to read from such an 'external' source.

The current idea of the eeprom layout, is to skip the first 8 bytes,
so that
other information can be stored there if needed, for example a header
with some magic to identify the EEPROM. Or equivalent purposes.

After those 8 bytes the MAC address follows the first macaddress. The
macaddress is appended by a CRC8 byte and then padded to make for nice
8 bytes.
Following the first macaddress one can store a second, or a third etc etc
macaddress.

Quoted 8 lines

The CRC8 is optional (via a define) but is strongly recommended to
have. It
helps preventing user error and more importantly, checks if the bytes
read are actually a user inserted address. E.g. only writing 1 macaddress into
the eeprom but trying to consume 2.

Quoted 6 lines

Interesting solution. We have used EEPROM to store board ID, version
number, MAC addresses on many of our boards. We have a command "mac" to
read/write these addresses. Would you take a look to see if it is possible to integrate?

I feel bad for not noticing the mac command! I think that this indeed
could get integrated, providing generic helpers.

Quoted 6 lines
Quoted 3 lines

Just wished you would have sent your suggestion during patch v1 or v2 :p

Sorry, for some reason I wasn't CC'ed for your earlier version. They were buried in thousands of emails.

Yeah, I saw, sorry.

As for the do_mac cmd, It looks something useful to add, I'll do that once Maxime's EEPROM patches have landed as I will add support for that then. Also I want to use the generic eeprom layout stuff for the layout then and at that point, it would be good to integrate the do_mac stuff.

The only thing I don't quite understand from looking at the code, is the name implies that you read/write/modify the MAC address in the rom with this, but I see that the two implementers have lots of other functions here, such as dumping the entire eeprom etc.

So what is the intend of do_mac? only MAC address related things, or full rom related tasks?

Olliver

Quoted 7 lines

York

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#31 lore raw

v5 cover Retrieve MAC address from EEPROM

Quoted 96 lines · o.schinagl at ultimaker.com

Hey York,

Quoted 79 lines · York Sun
Quoted 78 lines · Olliver Schinagl

Hey York,

Quoted 64 lines · York Sun
Quoted 54 lines · Olliver Schinagl

First off:
P.S. Joe, for some reason my previous patches where added with me as:
"oliver at schinagl.nl <[email protected]>" I see that it comes from
patchwork
as such. Is there some way to fix this to
"Olliver Schinagl <[email protected]>"?

Below the updated summary:

This patch-series introduces methods to retrieve the MAC address from an
onboard EEPROM. The series does a few small cleanups at the start, as
either
I ran into them while doing this series and fixed them along the way or
actually depended on them.

A manufacturer wants to produce boards and may even have MAC addresses
for
boards. Maintaining unique environments on a per-board basis however is
horrible. Also this data should be very persistent, and not easily
deletable
by simply wiping the environment or device tree. Finally there are
chips available on the market with a pre-programmed MAC address chips
(proms)
that a board manufacturer wants to use. Because of this, the MAC needs
to be
stored be able to read from such an 'external' source.

The current idea of the eeprom layout, is to skip the first 8 bytes,
so that
other information can be stored there if needed, for example a header
with some magic to identify the EEPROM. Or equivalent purposes.

After those 8 bytes the MAC address follows the first macaddress. The
macaddress is appended by a CRC8 byte and then padded to make for nice
8 bytes.
Following the first macaddress one can store a second, or a third etc etc
macaddress.

Quoted 8 lines

The CRC8 is optional (via a define) but is strongly recommended to
have. It
helps preventing user error and more importantly, checks if the bytes
read are actually a user inserted address. E.g. only writing 1 macaddress into
the eeprom but trying to consume 2.

Quoted 6 lines

Interesting solution. We have used EEPROM to store board ID, version
number, MAC addresses on many of our boards. We have a command "mac" to
read/write these addresses. Would you take a look to see if it is possible to integrate?

I feel bad for not noticing the mac command! I think that this indeed
could get integrated, providing generic helpers.

Quoted 6 lines
Quoted 3 lines

Just wished you would have sent your suggestion during patch v1 or v2 :p

Sorry, for some reason I wasn't CC'ed for your earlier version. They were buried in thousands of emails.

Yeah, I saw, sorry.

As for the do_mac cmd, It looks something useful to add, I'll do that once Maxime's EEPROM patches have landed as I will add support for that then. Also I want to use the generic eeprom layout stuff for the layout then and at that point, it would be good to integrate the do_mac stuff.

Quoted 8 lines

The only thing I don't quite understand from looking at the code, is the name implies that you read/write/modify the MAC address in the rom with this, but I see that the two implementers have lots of other functions here, such as dumping the entire eeprom etc.

So what is the intend of do_mac? only MAC address related things, or full rom related tasks?

The EEPROM we have holds more than just MAC addresses. It also has system ID, errata, number of ports, and CRC32 checksum. You can see them in cmd/mac.c, or board/freescale/common/sys_eeprom.c.

The command "mac" can read data out, and it can write. This is EEPROM on I2C bus. We were requested to provide a tool to update the errata number and etc.

York