[U-Boot] [PATCHv6 00/28] Retrieve MAC address from EEPROM

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 as suggested by Igor Grinberg * Add EEPROM/Mac commands suggested by York Sun
The series was initially based ontop of Joe's u-boot_net/next branches, but I rebased it ontop of u-boot/master to get the latest sunxi changes, including: sun7i: Add support for Olimex A20-OLinuXino-LIME2-eMMC ARM: dts: sunxi: Change node name for pwrseq pin on Olinuxino-lime2-emmc
Which are on their way to being merged in master. So once those land into master this all should apply cleanly. Sorry Joe!
======= Changes since v5: * Removed changes to eth_legacy as per Simon's request * Adapted, improved and fixed the emac/gmac Kconfig conversion * Renamed sunxi_[eg]mac to sun[47]_mac to be more clear and allowing preparing to merge common parts into sunxi_common * Added a few more MAC helpers * Added PHY_GIGE as Kconfig symbol
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.
Emmanuel Vadot (1): ARM: dts: sunxi: Change node name for pwrseq pin on Olinuxino-lime2-emmc
Olliver Schinagl (27): sun7i: Add support for Olimex A20-OLinuXino-LIME2-eMMC net: core: Add PHY_GIGE as a Kconfig symbol net: sunxi simplify defconfig net: sunxi: Re-add RTL8211X_PHY_FORCE_MASTER net: sunxi: Restore sunxi_[eg]mac behavior net: sunxi: Move GMAC_TX_DELAY to the driver 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 MAC address helper functions 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 net: core: Check return value of read_rom_hwaddr fdt: fixup_eth: Remove code duplication with a function fdt: fixup_eth: improve error catching/reduce identation arm: sunxi: Expose function to generate sunxi-specific a MAC address net: sunxi_emac: Write HW address via net_ops hook net: sunxi: Rename sunxi_emac to a more specific sun4i_mac net: sunxi: Have sunxi common functions together net: sun4i_mac: Add read_rom_hwaddr hook net: sun7i_mac: Make the sun7i a dw driver subclass net: dw: Expose designware_eth_start net: sun7i_mac: Add read_rom_hwaddr hook net: sun8i_gmac: Add read_rom_hwaddr hook net: sun8i: fix whitespace net: sunxi: Enable eeprom on OLinuXino Lime boards (again)
arch/arm/dts/sun7i-a20-olinuxino-lime2-emmc.dts | 2 +- arch/arm/include/asm/arch-sunxi/sys_proto.h | 4 +- arch/arm/mach-sunxi/Kconfig | 14 +- arch/arm/mach-sunxi/board.c | 1 - board/sunxi/MAINTAINERS | 5 + board/sunxi/Makefile | 1 - board/sunxi/board.c | 146 ++++++++----- common/fdt_support.c | 33 ++- configs/A10-OLinuXino-Lime_defconfig | 4 +- configs/A20-OLinuXino-Lime2-eMMC_defconfig | 36 ++++ configs/A20-OLinuXino-Lime2_defconfig | 8 +- configs/A20-OLinuXino-Lime_defconfig | 8 +- configs/A20-OLinuXino_MICRO_defconfig | 8 +- configs/A20-Olimex-SOM-EVB_defconfig | 4 +- configs/Bananapi_defconfig | 3 +- configs/Bananapro_defconfig | 3 +- configs/CSQ_CS908_defconfig | 4 +- configs/Colombus_defconfig | 3 +- configs/Cubieboard2_defconfig | 4 +- configs/Cubietruck_defconfig | 3 +- configs/Hummingbird_A31_defconfig | 3 +- configs/Itead_Ibox_A20_defconfig | 4 +- configs/Lamobo_R1_defconfig | 3 +- configs/Linksprite_pcDuino3_Nano_defconfig | 3 +- configs/Linksprite_pcDuino3_defconfig | 4 +- configs/Mele_A1000G_quad_defconfig | 4 +- configs/Mele_I7_defconfig | 4 +- configs/Mele_M3_defconfig | 4 +- configs/Mele_M5_defconfig | 4 +- configs/Mele_M9_defconfig | 4 +- configs/Orangepi_defconfig | 3 +- configs/Orangepi_mini_defconfig | 3 +- configs/Sinlinx_SinA31s_defconfig | 4 +- configs/Sinovoip_BPI_M2_defconfig | 3 +- configs/Wits_Pro_A20_DKT_defconfig | 3 +- configs/i12-tvbox_defconfig | 4 +- configs/icnova-a20-swac_defconfig | 4 +- configs/mixtile_loftq_defconfig | 3 +- doc/README.enetaddr | 95 +++++++++ drivers/net/Kconfig | 76 +++++-- drivers/net/Makefile | 5 +- drivers/net/designware.c | 3 +- drivers/net/designware.h | 1 + drivers/net/{sunxi_emac.c => sun4i_mac.c} | 267 +++++++++++++----------- board/sunxi/gmac.c => drivers/net/sun7i_mac.c | 54 ++++- drivers/net/sun8i_emac.c | 15 +- drivers/net/sunxi_common.c | 33 +++ drivers/net/sunxi_common.h | 13 ++ include/configs/sunxi-common.h | 13 +- include/net.h | 76 ++++++- net/Kconfig | 59 ++++++ net/eth-uclass.c | 65 +++--- net/eth_common.c | 53 ++++- net/eth_legacy.c | 4 +- scripts/config_whitelist.txt | 2 - 55 files changed, 842 insertions(+), 350 deletions(-) create mode 100644 configs/A20-OLinuXino-Lime2-eMMC_defconfig rename drivers/net/{sunxi_emac.c => sun4i_mac.c} (59%) rename board/sunxi/gmac.c => drivers/net/sun7i_mac.c (67%) create mode 100644 drivers/net/sunxi_common.c create mode 100644 drivers/net/sunxi_common.h

From: Emmanuel Vadot manu@bidouilliste.com
The node name for the power seq pin is mmc2@0 like the mmc2_pins_a one. This makes the original node (mmc2_pins_a) scrapped out of the dtb and result in a unusable eMMC if U-Boot didn't configured the pins to the correct functions.
Signed-off-by: Emmanuel Vadot manu@bidouilliste.com Signed-off-by: Maxime Ripard maxime.ripard@free-electrons.com Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- arch/arm/dts/sun7i-a20-olinuxino-lime2-emmc.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2-emmc.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2-emmc.dts index 5ea4915f6d..10d307408f 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2-emmc.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2-emmc.dts @@ -56,7 +56,7 @@ };
&pio { - mmc2_pins_nrst: mmc2@0 { + mmc2_pins_nrst: mmc2-rst-pin { allwinner,pins = "PC16"; allwinner,function = "gpio_out"; allwinner,drive = <SUN4I_PINCTRL_10_MA>;

This patch adds support for the Olimex OLinuXino Lime2 with eMMC flash storage. https://www.olimex.com/Products/OLinuXino/A20/A20-OLinuXino-LIME2-eMMC/
It is a assembly variant of the regular Lime2 but featuring eMMC for storage.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- board/sunxi/MAINTAINERS | 5 +++++ configs/A20-OLinuXino-Lime2-eMMC_defconfig | 36 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 configs/A20-OLinuXino-Lime2-eMMC_defconfig
diff --git a/board/sunxi/MAINTAINERS b/board/sunxi/MAINTAINERS index 1c8817375d..1d3742c744 100644 --- a/board/sunxi/MAINTAINERS +++ b/board/sunxi/MAINTAINERS @@ -89,6 +89,11 @@ M: Iain Paton ipaton0@gmail.com S: Maintained F: configs/A20-OLinuXino-Lime2_defconfig
+A20-OLINUXINO-LIME2-EMMC BOARD +M: Olliver Schinagl oliver@schinagl.nl +S: Maintained +F: configs/A20-OLinuXino-Lime2-eMMC_defconfig + A33-OLINUXINO BOARD M: Stefan Mavrodiev stefan.mavrodiev@gmail.com S: Maintained diff --git a/configs/A20-OLinuXino-Lime2-eMMC_defconfig b/configs/A20-OLinuXino-Lime2-eMMC_defconfig new file mode 100644 index 0000000000..034ae983a5 --- /dev/null +++ b/configs/A20-OLinuXino-Lime2-eMMC_defconfig @@ -0,0 +1,36 @@ +CONFIG_ARM=y +CONFIG_ARCH_SUNXI=y +CONFIG_MACH_SUN7I=y +CONFIG_DRAM_CLK=384 +CONFIG_MMC0_CD_PIN="PH1" +CONFIG_MMC_SUNXI_SLOT_EXTRA=2 +CONFIG_USB0_VBUS_PIN="PC17" +CONFIG_USB0_VBUS_DET="PH5" +CONFIG_I2C1_ENABLE=y +CONFIG_SATAPWR="PC3" +CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-lime2-emmc" +CONFIG_AHCI=y +# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set +CONFIG_SPL=y +CONFIG_SPL_I2C_SUPPORT=y +# CONFIG_CMD_IMLS is not set +# CONFIG_CMD_FLASH is not set +CONFIG_CMD_DFU=y +CONFIG_CMD_USB_MASS_STORAGE=y +# CONFIG_CMD_FPGA is not set +# CONFIG_SPL_DOS_PARTITION is not set +# CONFIG_SPL_ISO_PARTITION is not set +# CONFIG_SPL_PARTITION_UUIDS is not set +CONFIG_DFU_RAM=y +CONFIG_ETH_DESIGNWARE=y +CONFIG_RGMII=y +CONFIG_SUN7I_GMAC=y +CONFIG_AXP_ALDO3_VOLT=2800 +CONFIG_AXP_ALDO4_VOLT=2800 +CONFIG_USB_EHCI_HCD=y +CONFIG_USB_MUSB_GADGET=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_DOWNLOAD=y +CONFIG_G_DNL_MANUFACTURER="Allwinner Technology" +CONFIG_G_DNL_VENDOR_NUM=0x1f3a +CONFIG_G_DNL_PRODUCT_NUM=0x1010

Add the CONFIG_PHY_GIGE option as a hidden Kconfig symbol so that we can select it from the menu as a dependency.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/Kconfig | 4 ++++ include/configs/sunxi-common.h | 1 - 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 9cd0d94cbd..336557f395 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -155,6 +155,9 @@ config RGMII Enable the support of the Reduced Gigabit Media-Independent Interface (RGMII).
+config PHY_GIGE + bool + config RTL8139 bool "Realtek 8139 series Ethernet controller driver" help @@ -169,6 +172,7 @@ config RTL8169
config SUN7I_GMAC bool "Enable Allwinner GMAC Ethernet support" + select PHY_GIGE help Enable the support for Sun7i GMAC Ethernet controller
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h index 997a92c8be..3d8a130f38 100644 --- a/include/configs/sunxi-common.h +++ b/include/configs/sunxi-common.h @@ -294,7 +294,6 @@ extern int soft_i2c_gpio_scl; #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

On Mon, May 15, 2017 at 10:02:19AM +0200, Olliver Schinagl wrote:
Add the CONFIG_PHY_GIGE option as a hidden Kconfig symbol so that we can select it from the menu as a dependency.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Reviewed-by: Tom Rini trini@konsulko.com

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
Add the CONFIG_PHY_GIGE option as a hidden Kconfig symbol so that we can select it from the menu as a dependency.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

We currently have a few dependencies explicitly set in the sunxi defconfigs. Things such as, RGMII, DESIGNWARE_ETH in combination with SUN7I_GMAC. When selecting SUN7I_GMAC we already imply DESIGNWARE_ETH for example.
This patch puts this logic into the Kconfig thus simplifying the defconfigs. For a user it is also no more logical when enabling one of the drivers in Kconfig to have the proper dependencies automatically selected.
One thing to note, the sun7i driver can be connected in two modes, RGMII and MII mode and we use both throughout the boards. To make this easy we split up the CONFIG_SUNXI_GMAC symbol into the SUN7I_GMAC and the SUN7I_EMAC symbol, where the SUN7I_EMAC indicates a MII connected designware IP.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- configs/A20-OLinuXino-Lime2-eMMC_defconfig | 2 -- configs/A20-OLinuXino-Lime2_defconfig | 2 -- configs/A20-OLinuXino-Lime_defconfig | 3 +- configs/A20-OLinuXino_MICRO_defconfig | 3 +- configs/A20-Olimex-SOM-EVB_defconfig | 2 -- configs/Bananapi_defconfig | 2 -- configs/Bananapro_defconfig | 2 -- configs/CSQ_CS908_defconfig | 3 +- configs/Colombus_defconfig | 2 -- configs/Cubieboard2_defconfig | 3 +- configs/Cubietruck_defconfig | 2 -- configs/Hummingbird_A31_defconfig | 2 -- configs/Itead_Ibox_A20_defconfig | 3 +- configs/Lamobo_R1_defconfig | 2 -- configs/Linksprite_pcDuino3_Nano_defconfig | 2 -- configs/Linksprite_pcDuino3_defconfig | 3 +- configs/Mele_A1000G_quad_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 | 2 -- configs/Orangepi_mini_defconfig | 2 -- configs/Sinlinx_SinA31s_defconfig | 3 +- configs/Sinovoip_BPI_M2_defconfig | 2 -- configs/Wits_Pro_A20_DKT_defconfig | 2 -- configs/i12-tvbox_defconfig | 3 +- configs/icnova-a20-swac_defconfig | 3 +- configs/mixtile_loftq_defconfig | 2 -- drivers/net/Kconfig | 54 ++++++++++++++++++++++++------ include/configs/sunxi-common.h | 3 -- 31 files changed, 57 insertions(+), 72 deletions(-)
diff --git a/configs/A20-OLinuXino-Lime2-eMMC_defconfig b/configs/A20-OLinuXino-Lime2-eMMC_defconfig index 034ae983a5..76525f4603 100644 --- a/configs/A20-OLinuXino-Lime2-eMMC_defconfig +++ b/configs/A20-OLinuXino-Lime2-eMMC_defconfig @@ -22,8 +22,6 @@ 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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1f2daa6706..aa8a5d5f2b 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -21,8 +21,6 @@ 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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 diff --git a/configs/A20-OLinuXino-Lime_defconfig b/configs/A20-OLinuXino-Lime_defconfig index 7f63d4af54..b4b2f66ccb 100644 --- a/configs/A20-OLinuXino-Lime_defconfig +++ b/configs/A20-OLinuXino-Lime_defconfig @@ -16,8 +16,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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-OLinuXino_MICRO_defconfig b/configs/A20-OLinuXino_MICRO_defconfig index 89e87e799b..d59a480e8d 100644 --- a/configs/A20-OLinuXino_MICRO_defconfig +++ b/configs/A20-OLinuXino_MICRO_defconfig @@ -19,8 +19,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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-Olimex-SOM-EVB_defconfig b/configs/A20-Olimex-SOM-EVB_defconfig index 6c87648d4f..d52aefc984 100644 --- a/configs/A20-Olimex-SOM-EVB_defconfig +++ b/configs/A20-Olimex-SOM-EVB_defconfig @@ -20,8 +20,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_ETH_DESIGNWARE=y -CONFIG_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 diff --git a/configs/Bananapi_defconfig b/configs/Bananapi_defconfig index fe75eef513..5a45506571 100644 --- a/configs/Bananapi_defconfig +++ b/configs/Bananapi_defconfig @@ -17,7 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Bananapro_defconfig b/configs/Bananapro_defconfig index df65922e83..1503c41d3e 100644 --- a/configs/Bananapro_defconfig +++ b/configs/Bananapro_defconfig @@ -19,8 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO4_VOLT=2500 CONFIG_USB_EHCI_HCD=y diff --git a/configs/CSQ_CS908_defconfig b/configs/CSQ_CS908_defconfig index a6fcbf5ecf..cac210c1e8 100644 --- a/configs/CSQ_CS908_defconfig +++ b/configs/CSQ_CS908_defconfig @@ -13,8 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Colombus_defconfig b/configs/Colombus_defconfig index 1359281ff4..7ce5d5ae2b 100644 --- a/configs/Colombus_defconfig +++ b/configs/Colombus_defconfig @@ -23,8 +23,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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Cubieboard2_defconfig b/configs/Cubieboard2_defconfig index 02c503f672..09b423104e 100644 --- a/configs/Cubieboard2_defconfig +++ b/configs/Cubieboard2_defconfig @@ -15,6 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Cubietruck_defconfig b/configs/Cubietruck_defconfig index f9d56c8f9d..44082ccd30 100644 --- a/configs/Cubietruck_defconfig +++ b/configs/Cubietruck_defconfig @@ -23,8 +23,6 @@ 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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y diff --git a/configs/Hummingbird_A31_defconfig b/configs/Hummingbird_A31_defconfig index 6f9b103207..c25bccc3f5 100644 --- a/configs/Hummingbird_A31_defconfig +++ b/configs/Hummingbird_A31_defconfig @@ -15,8 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Itead_Ibox_A20_defconfig b/configs/Itead_Ibox_A20_defconfig index 4bae19f2fa..2179306666 100644 --- a/configs/Itead_Ibox_A20_defconfig +++ b/configs/Itead_Ibox_A20_defconfig @@ -15,6 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Lamobo_R1_defconfig b/configs/Lamobo_R1_defconfig index cc29d606a9..e7b9ad7920 100644 --- a/configs/Lamobo_R1_defconfig +++ b/configs/Lamobo_R1_defconfig @@ -17,7 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Linksprite_pcDuino3_Nano_defconfig b/configs/Linksprite_pcDuino3_Nano_defconfig index 80416cb7b1..74789ca56e 100644 --- a/configs/Linksprite_pcDuino3_Nano_defconfig +++ b/configs/Linksprite_pcDuino3_Nano_defconfig @@ -17,7 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Linksprite_pcDuino3_defconfig b/configs/Linksprite_pcDuino3_defconfig index b9f89a013e..1aa253abcb 100644 --- a/configs/Linksprite_pcDuino3_defconfig +++ b/configs/Linksprite_pcDuino3_defconfig @@ -15,6 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Mele_A1000G_quad_defconfig b/configs/Mele_A1000G_quad_defconfig index 5b1b5f5d7c..0152b21303 100644 --- a/configs/Mele_A1000G_quad_defconfig +++ b/configs/Mele_A1000G_quad_defconfig @@ -14,8 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_AXP_DCDC1_VOLT=3300 CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 diff --git a/configs/Mele_I7_defconfig b/configs/Mele_I7_defconfig index b60969787c..12f0c1a83c 100644 --- a/configs/Mele_I7_defconfig +++ b/configs/Mele_I7_defconfig @@ -13,8 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_AXP_DCDC1_VOLT=3300 CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 diff --git a/configs/Mele_M3_defconfig b/configs/Mele_M3_defconfig index 08e8c2dbde..382c45b800 100644 --- a/configs/Mele_M3_defconfig +++ b/configs/Mele_M3_defconfig @@ -16,6 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Mele_M5_defconfig b/configs/Mele_M5_defconfig index 4c377e3daf..594b230ff1 100644 --- a/configs/Mele_M5_defconfig +++ b/configs/Mele_M5_defconfig @@ -16,6 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Mele_M9_defconfig b/configs/Mele_M9_defconfig index dc7901f9af..64a111ec6a 100644 --- a/configs/Mele_M9_defconfig +++ b/configs/Mele_M9_defconfig @@ -13,8 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_AXP_DCDC1_VOLT=3300 CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 diff --git a/configs/Orangepi_defconfig b/configs/Orangepi_defconfig index b8c1ea4d7c..34eeb92fa6 100644 --- a/configs/Orangepi_defconfig +++ b/configs/Orangepi_defconfig @@ -19,7 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Orangepi_mini_defconfig b/configs/Orangepi_mini_defconfig index 19c35ef103..2609c54bc2 100644 --- a/configs/Orangepi_mini_defconfig +++ b/configs/Orangepi_mini_defconfig @@ -21,7 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Sinlinx_SinA31s_defconfig b/configs/Sinlinx_SinA31s_defconfig index 7f815a32cb..bdf6ebe9f5 100644 --- a/configs/Sinlinx_SinA31s_defconfig +++ b/configs/Sinlinx_SinA31s_defconfig @@ -17,7 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_AXP_DLDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Sinovoip_BPI_M2_defconfig b/configs/Sinovoip_BPI_M2_defconfig index a2cadbc271..78afc6d668 100644 --- a/configs/Sinovoip_BPI_M2_defconfig +++ b/configs/Sinovoip_BPI_M2_defconfig @@ -13,8 +13,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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_ALDO2_VOLT=1800 diff --git a/configs/Wits_Pro_A20_DKT_defconfig b/configs/Wits_Pro_A20_DKT_defconfig index 8658ef6b4c..979c6a6ae8 100644 --- a/configs/Wits_Pro_A20_DKT_defconfig +++ b/configs/Wits_Pro_A20_DKT_defconfig @@ -19,7 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/i12-tvbox_defconfig b/configs/i12-tvbox_defconfig index 4245491b6a..b609514de8 100644 --- a/configs/i12-tvbox_defconfig +++ b/configs/i12-tvbox_defconfig @@ -14,6 +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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/icnova-a20-swac_defconfig b/configs/icnova-a20-swac_defconfig index 6f79c587ee..63bbd37f97 100644 --- a/configs/icnova-a20-swac_defconfig +++ b/configs/icnova-a20-swac_defconfig @@ -21,6 +21,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_SUN7I_GMAC=y +CONFIG_SUN7I_EMAC=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/mixtile_loftq_defconfig b/configs/mixtile_loftq_defconfig index 6264b3a151..47289c6616 100644 --- a/configs/mixtile_loftq_defconfig +++ b/configs/mixtile_loftq_defconfig @@ -15,8 +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_RGMII=y CONFIG_SUN7I_GMAC=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 336557f395..c0d141754f 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -149,11 +149,11 @@ config PCH_GBE This MAC is present in Intel Platform Controller Hub EG20T. It supports 10/100/1000 Mbps operation.
+config MII + bool + config RGMII - bool "Enable RGMII" - help - Enable the support of the Reduced Gigabit Media-Independent - Interface (RGMII). + bool
config PHY_GIGE bool @@ -170,17 +170,49 @@ config RTL8169 This driver supports Realtek 8169 series gigabit ethernet family of PCI/PCIe chipsets/adapters.
-config SUN7I_GMAC - bool "Enable Allwinner GMAC Ethernet support" - select PHY_GIGE - help - Enable the support for Sun7i GMAC Ethernet controller - config SUN4I_EMAC bool "Allwinner Sun4i Ethernet MAC support" depends on DM_ETH + select MII + select PHYLIB + help + This driver provides the Allwinner based SoCs with 100 Megabit + network support as it is found on the sun4i and sun7i. This driver + is known to have performance issues and should only be used on + sun4i hardware. Newer hardware supports the SUN7I_EMAC driver, + which also works with 100 Megabit PHY's. + +choice + prompt "Allwinner Sun7i GMAC support" help - This driver supports the Allwinner based SUN4I Ethernet MAC. + 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 SUN4I_EMAC driver. + +config SUN7I_NONE + bool "Disable" + +config SUN7I_EMAC + bool "MII" + select ETH_DESIGNWARE + select PHYLIB + select MII + help + If connecting the sun7i MAC to an ethernet (10/100) only PHY, + select this option. + +config SUN7I_GMAC + bool "RGMII" + select ETH_DESIGNWARE + select PHYLIB + select RGMII + select PHY_GIGE + help + If connecting the sun7i MAC to a gigabit ethernet PHY, select + this option. + +endchoice
config SUN8I_EMAC bool "Allwinner Sun8i Ethernet MAC support" diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h index 3d8a130f38..8f97b80619 100644 --- a/include/configs/sunxi-common.h +++ b/include/configs/sunxi-common.h @@ -289,13 +289,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_ADDR 1 -#define CONFIG_MII /* MII PHY management */ #define CONFIG_PHY_REALTEK #endif

On Mon, May 15, 2017 at 10:02:20AM +0200, Olliver Schinagl wrote:
We currently have a few dependencies explicitly set in the sunxi defconfigs. Things such as, RGMII, DESIGNWARE_ETH in combination with SUN7I_GMAC. When selecting SUN7I_GMAC we already imply DESIGNWARE_ETH for example.
This patch puts this logic into the Kconfig thus simplifying the defconfigs. For a user it is also no more logical when enabling one of the drivers in Kconfig to have the proper dependencies automatically selected.
One thing to note, the sun7i driver can be connected in two modes, RGMII and MII mode and we use both throughout the boards. To make this easy we split up the CONFIG_SUNXI_GMAC symbol into the SUN7I_GMAC and the SUN7I_EMAC symbol, where the SUN7I_EMAC indicates a MII connected designware IP.
This doesn't make any sense. You have two *separate* blocks on the A20, the EMAC and the GMAC, and yet, you want SUN7I_EMAC to not represent the EMAC found, but the GMAC with an MII phy?
The current configuration we have is fine as it is, there's no need to change it, especially for something that is so confusing.
Maxime

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
We currently have a few dependencies explicitly set in the sunxi defconfigs. Things such as, RGMII, DESIGNWARE_ETH in combination with SUN7I_GMAC. When selecting SUN7I_GMAC we already imply DESIGNWARE_ETH for example.
This patch puts this logic into the Kconfig thus simplifying the defconfigs. For a user it is also no more logical when enabling one of the drivers in Kconfig to have the proper dependencies automatically selected.
One thing to note, the sun7i driver can be connected in two modes, RGMII and MII mode and we use both throughout the boards. To make this easy we split up the CONFIG_SUNXI_GMAC symbol into the SUN7I_GMAC and the SUN7I_EMAC symbol, where the SUN7I_EMAC indicates a MII connected designware IP.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
configs/A20-OLinuXino-Lime2-eMMC_defconfig | 2 -- configs/A20-OLinuXino-Lime2_defconfig | 2 -- configs/A20-OLinuXino-Lime_defconfig | 3 +- configs/A20-OLinuXino_MICRO_defconfig | 3 +- configs/A20-Olimex-SOM-EVB_defconfig | 2 -- configs/Bananapi_defconfig | 2 -- configs/Bananapro_defconfig | 2 -- configs/CSQ_CS908_defconfig | 3 +- configs/Colombus_defconfig | 2 -- configs/Cubieboard2_defconfig | 3 +- configs/Cubietruck_defconfig | 2 -- configs/Hummingbird_A31_defconfig | 2 -- configs/Itead_Ibox_A20_defconfig | 3 +- configs/Lamobo_R1_defconfig | 2 -- configs/Linksprite_pcDuino3_Nano_defconfig | 2 -- configs/Linksprite_pcDuino3_defconfig | 3 +- configs/Mele_A1000G_quad_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 | 2 -- configs/Orangepi_mini_defconfig | 2 -- configs/Sinlinx_SinA31s_defconfig | 3 +- configs/Sinovoip_BPI_M2_defconfig | 2 -- configs/Wits_Pro_A20_DKT_defconfig | 2 -- configs/i12-tvbox_defconfig | 3 +- configs/icnova-a20-swac_defconfig | 3 +- configs/mixtile_loftq_defconfig | 2 -- drivers/net/Kconfig | 54 ++++++++++++++++++++++++------ include/configs/sunxi-common.h | 3 -- 31 files changed, 57 insertions(+), 72 deletions(-)
[...]
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 336557f395..c0d141754f 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -149,11 +149,11 @@ config PCH_GBE This MAC is present in Intel Platform Controller Hub EG20T. It supports 10/100/1000 Mbps operation.
+config MII
bool
This is a generic config that describes any MII - arguably it could be cleaned up to mean MDIO.
config RGMII
bool "Enable RGMII"
This wasn't a very generically useful config option (meaning there are many devices which use RGMII and don't specify this) so it should probably see expanded use or at least have some depends on in the config that limit it's appearance to drivers that care.
help
Enable the support of the Reduced Gigabit Media-Independent
Interface (RGMII).
bool
It doesn't seem great to hide this, but maybe that's a better approach than making it depend on the correct drivers.
config PHY_GIGE bool @@ -170,17 +170,49 @@ config RTL8169 This driver supports Realtek 8169 series gigabit ethernet family of PCI/PCIe chipsets/adapters.
-config SUN7I_GMAC
bool "Enable Allwinner GMAC Ethernet support"
select PHY_GIGE
help
Enable the support for Sun7i GMAC Ethernet controller
config SUN4I_EMAC bool "Allwinner Sun4i Ethernet MAC support" depends on DM_ETH
select MII
select PHYLIB
help
This driver provides the Allwinner based SoCs with 100 Megabit
network support as it is found on the sun4i and sun7i. This driver
is known to have performance issues and should only be used on
sun4i hardware. Newer hardware supports the SUN7I_EMAC driver,
which also works with 100 Megabit PHY's.
+choice
prompt "Allwinner Sun7i GMAC support" help
This driver supports the Allwinner based SUN4I Ethernet MAC.
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 SUN4I_EMAC driver.
+config SUN7I_NONE
bool "Disable"
+config SUN7I_EMAC
bool "MII"
select ETH_DESIGNWARE
select PHYLIB
select MII
help
If connecting the sun7i MAC to an ethernet (10/100) only PHY,
select this option.
+config SUN7I_GMAC
bool "RGMII"
select ETH_DESIGNWARE
select PHYLIB
select RGMII
select PHY_GIGE
Presumably you would still need to define MII here.
help
If connecting the sun7i MAC to a gigabit ethernet PHY, select
this option.
+endchoice
config SUN8I_EMAC bool "Allwinner Sun8i Ethernet MAC support" diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h index 3d8a130f38..8f97b80619 100644 --- a/include/configs/sunxi-common.h +++ b/include/configs/sunxi-common.h @@ -289,13 +289,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_ADDR 1 -#define CONFIG_MII /* MII PHY management */ #define CONFIG_PHY_REALTEK #endif
-- 2.11.0
U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot

Commit 8728c97eff5bd9 (" configs: Re-sync") potentially broke the lime2 as it removed the RTL8211X_PHY_FORCE_MASTER flag.
Re-add this flag.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- configs/A20-OLinuXino-Lime2_defconfig | 1 + configs/A20-Olimex-SOM-EVB_defconfig | 1 + 2 files changed, 2 insertions(+)
diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index aa8a5d5f2b..14d1159ead 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -22,6 +22,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_SPL_PARTITION_UUIDS is not set CONFIG_DFU_RAM=y CONFIG_SUN7I_GMAC=y +CONFIG_RTL8211X_PHY_FORCE_MASTER=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-Olimex-SOM-EVB_defconfig b/configs/A20-Olimex-SOM-EVB_defconfig index d52aefc984..59388ba7f4 100644 --- a/configs/A20-Olimex-SOM-EVB_defconfig +++ b/configs/A20-Olimex-SOM-EVB_defconfig @@ -21,6 +21,7 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_RTL8211X_PHY_FORCE_MASTER=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
Commit 8728c97eff5bd9 (" configs: Re-sync") potentially broke the lime2 as it removed the RTL8211X_PHY_FORCE_MASTER flag.
Re-add this flag.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

Commit 4d43d065db326 ("sunxi: Move SUNXI_GMAC to Kconfig") renamed SUNXI_[EG]MAC but did not update include/configs/sunxi-common.h where based on these two symbols other config symbols where being set, such as CONFIG_PHY_REALTEK for SUNXI_GMAC boards and the CONFIG_PHY_ADDR being set to a safe default.
This patch restores that behavior by adding the PHY_REALTEK to the defconfigs, where they belong and by setting the address based on the new config symbols.
Additionally, we use the new renamed symbol in the Makefiles to actually compile the drivers.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- arch/arm/include/asm/arch-sunxi/sys_proto.h | 2 +- board/sunxi/Makefile | 2 +- configs/A20-OLinuXino-Lime2_defconfig | 1 + configs/A20-OLinuXino-Lime_defconfig | 1 + configs/A20-OLinuXino_MICRO_defconfig | 1 + configs/A20-Olimex-SOM-EVB_defconfig | 1 + configs/Bananapi_defconfig | 1 + configs/Bananapro_defconfig | 1 + configs/CSQ_CS908_defconfig | 1 + configs/Colombus_defconfig | 1 + configs/Cubieboard2_defconfig | 1 + configs/Cubietruck_defconfig | 1 + configs/Hummingbird_A31_defconfig | 1 + configs/Itead_Ibox_A20_defconfig | 1 + configs/Lamobo_R1_defconfig | 1 + configs/Linksprite_pcDuino3_Nano_defconfig | 1 + configs/Linksprite_pcDuino3_defconfig | 1 + configs/Mele_A1000G_quad_defconfig | 1 + configs/Mele_I7_defconfig | 1 + configs/Mele_M3_defconfig | 1 + configs/Mele_M5_defconfig | 1 + configs/Mele_M9_defconfig | 1 + configs/Orangepi_defconfig | 1 + configs/Orangepi_mini_defconfig | 1 + configs/Sinlinx_SinA31s_defconfig | 1 + configs/Sinovoip_BPI_M2_defconfig | 1 + configs/Wits_Pro_A20_DKT_defconfig | 1 + configs/i12-tvbox_defconfig | 1 + configs/icnova-a20-swac_defconfig | 1 + configs/mixtile_loftq_defconfig | 1 + drivers/net/Kconfig | 5 +++++ drivers/net/Makefile | 2 +- include/configs/sunxi-common.h | 9 +++------ scripts/config_whitelist.txt | 2 -- 34 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/arch/arm/include/asm/arch-sunxi/sys_proto.h b/arch/arm/include/asm/arch-sunxi/sys_proto.h index a373319a2b..850236ed42 100644 --- a/arch/arm/include/asm/arch-sunxi/sys_proto.h +++ b/arch/arm/include/asm/arch-sunxi/sys_proto.h @@ -24,7 +24,7 @@ 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 +#if !defined CONFIG_SPL_BUILD && defined CONFIG_SUN7I_MAC void eth_init_board(void); #else static inline void eth_init_board(void) {} diff --git a/board/sunxi/Makefile b/board/sunxi/Makefile index 43766e0ef4..b4768b9b9b 100644 --- a/board/sunxi/Makefile +++ b/board/sunxi/Makefile @@ -9,7 +9,7 @@ # SPDX-License-Identifier: GPL-2.0+ # obj-y += board.o -obj-$(CONFIG_SUNXI_GMAC) += gmac.o +obj-$(CONFIG_SUN7I_MAC) += gmac.o obj-$(CONFIG_SUNXI_AHCI) += ahci.o obj-$(CONFIG_MACH_SUN4I) += dram_sun4i_auto.o obj-$(CONFIG_MACH_SUN5I) += dram_sun5i_auto.o diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 14d1159ead..14a51ef3f9 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -22,6 +22,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_SPL_PARTITION_UUIDS is not set CONFIG_DFU_RAM=y CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_RTL8211X_PHY_FORCE_MASTER=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 diff --git a/configs/A20-OLinuXino-Lime_defconfig b/configs/A20-OLinuXino-Lime_defconfig index b4b2f66ccb..3fdf7c64aa 100644 --- a/configs/A20-OLinuXino-Lime_defconfig +++ b/configs/A20-OLinuXino-Lime_defconfig @@ -17,6 +17,7 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-OLinuXino_MICRO_defconfig b/configs/A20-OLinuXino_MICRO_defconfig index d59a480e8d..ea7bc73dda 100644 --- a/configs/A20-OLinuXino_MICRO_defconfig +++ b/configs/A20-OLinuXino_MICRO_defconfig @@ -20,6 +20,7 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-Olimex-SOM-EVB_defconfig b/configs/A20-Olimex-SOM-EVB_defconfig index 59388ba7f4..8a2dfad526 100644 --- a/configs/A20-Olimex-SOM-EVB_defconfig +++ b/configs/A20-Olimex-SOM-EVB_defconfig @@ -21,6 +21,7 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_RTL8211X_PHY_FORCE_MASTER=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 diff --git a/configs/Bananapi_defconfig b/configs/Bananapi_defconfig index 5a45506571..eac3175f2d 100644 --- a/configs/Bananapi_defconfig +++ b/configs/Bananapi_defconfig @@ -18,4 +18,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_EFI_PARTITION is not set CONFIG_NETCONSOLE=y CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Bananapro_defconfig b/configs/Bananapro_defconfig index 1503c41d3e..ef1ff21a39 100644 --- a/configs/Bananapro_defconfig +++ b/configs/Bananapro_defconfig @@ -20,5 +20,6 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_EFI_PARTITION is not set CONFIG_NETCONSOLE=y CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO4_VOLT=2500 CONFIG_USB_EHCI_HCD=y diff --git a/configs/CSQ_CS908_defconfig b/configs/CSQ_CS908_defconfig index cac210c1e8..b771ab068d 100644 --- a/configs/CSQ_CS908_defconfig +++ b/configs/CSQ_CS908_defconfig @@ -14,6 +14,7 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Colombus_defconfig b/configs/Colombus_defconfig index 7ce5d5ae2b..dd4eefb98a 100644 --- a/configs/Colombus_defconfig +++ b/configs/Colombus_defconfig @@ -24,5 +24,6 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Cubieboard2_defconfig b/configs/Cubieboard2_defconfig index 09b423104e..072ac047a6 100644 --- a/configs/Cubieboard2_defconfig +++ b/configs/Cubieboard2_defconfig @@ -16,4 +16,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Cubietruck_defconfig b/configs/Cubietruck_defconfig index 44082ccd30..fe15fea717 100644 --- a/configs/Cubietruck_defconfig +++ b/configs/Cubietruck_defconfig @@ -24,6 +24,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_SPL_PARTITION_UUIDS is not set CONFIG_DFU_RAM=y CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_USB_GADGET=y diff --git a/configs/Hummingbird_A31_defconfig b/configs/Hummingbird_A31_defconfig index c25bccc3f5..245b33d6dc 100644 --- a/configs/Hummingbird_A31_defconfig +++ b/configs/Hummingbird_A31_defconfig @@ -16,5 +16,6 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Itead_Ibox_A20_defconfig b/configs/Itead_Ibox_A20_defconfig index 2179306666..496b860954 100644 --- a/configs/Itead_Ibox_A20_defconfig +++ b/configs/Itead_Ibox_A20_defconfig @@ -16,4 +16,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Lamobo_R1_defconfig b/configs/Lamobo_R1_defconfig index e7b9ad7920..7979f4da21 100644 --- a/configs/Lamobo_R1_defconfig +++ b/configs/Lamobo_R1_defconfig @@ -18,4 +18,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Linksprite_pcDuino3_Nano_defconfig b/configs/Linksprite_pcDuino3_Nano_defconfig index 74789ca56e..6586c2168f 100644 --- a/configs/Linksprite_pcDuino3_Nano_defconfig +++ b/configs/Linksprite_pcDuino3_Nano_defconfig @@ -18,4 +18,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Linksprite_pcDuino3_defconfig b/configs/Linksprite_pcDuino3_defconfig index 1aa253abcb..f0290d82dd 100644 --- a/configs/Linksprite_pcDuino3_defconfig +++ b/configs/Linksprite_pcDuino3_defconfig @@ -16,4 +16,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Mele_A1000G_quad_defconfig b/configs/Mele_A1000G_quad_defconfig index 0152b21303..798745d40b 100644 --- a/configs/Mele_A1000G_quad_defconfig +++ b/configs/Mele_A1000G_quad_defconfig @@ -15,6 +15,7 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_DCDC1_VOLT=3300 CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 diff --git a/configs/Mele_I7_defconfig b/configs/Mele_I7_defconfig index 12f0c1a83c..8ccc93bb86 100644 --- a/configs/Mele_I7_defconfig +++ b/configs/Mele_I7_defconfig @@ -14,6 +14,7 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_DCDC1_VOLT=3300 CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 diff --git a/configs/Mele_M3_defconfig b/configs/Mele_M3_defconfig index 382c45b800..e5fcdd34cf 100644 --- a/configs/Mele_M3_defconfig +++ b/configs/Mele_M3_defconfig @@ -17,4 +17,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Mele_M5_defconfig b/configs/Mele_M5_defconfig index 594b230ff1..45c0d26791 100644 --- a/configs/Mele_M5_defconfig +++ b/configs/Mele_M5_defconfig @@ -17,4 +17,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Mele_M9_defconfig b/configs/Mele_M9_defconfig index 64a111ec6a..efa52f92f8 100644 --- a/configs/Mele_M9_defconfig +++ b/configs/Mele_M9_defconfig @@ -14,6 +14,7 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_DCDC1_VOLT=3300 CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_DLDO1_VOLT=3300 diff --git a/configs/Orangepi_defconfig b/configs/Orangepi_defconfig index 34eeb92fa6..2fe3f5978d 100644 --- a/configs/Orangepi_defconfig +++ b/configs/Orangepi_defconfig @@ -20,4 +20,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Orangepi_mini_defconfig b/configs/Orangepi_mini_defconfig index 2609c54bc2..71a93b58a5 100644 --- a/configs/Orangepi_mini_defconfig +++ b/configs/Orangepi_mini_defconfig @@ -22,4 +22,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Sinlinx_SinA31s_defconfig b/configs/Sinlinx_SinA31s_defconfig index bdf6ebe9f5..c6f98e4572 100644 --- a/configs/Sinlinx_SinA31s_defconfig +++ b/configs/Sinlinx_SinA31s_defconfig @@ -18,5 +18,6 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_DLDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/configs/Sinovoip_BPI_M2_defconfig b/configs/Sinovoip_BPI_M2_defconfig index 78afc6d668..fe5845e670 100644 --- a/configs/Sinovoip_BPI_M2_defconfig +++ b/configs/Sinovoip_BPI_M2_defconfig @@ -14,6 +14,7 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_AXP_ALDO2_VOLT=1800 CONFIG_AXP_DLDO1_VOLT=3000 diff --git a/configs/Wits_Pro_A20_DKT_defconfig b/configs/Wits_Pro_A20_DKT_defconfig index 979c6a6ae8..57298f1ea4 100644 --- a/configs/Wits_Pro_A20_DKT_defconfig +++ b/configs/Wits_Pro_A20_DKT_defconfig @@ -20,4 +20,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/i12-tvbox_defconfig b/configs/i12-tvbox_defconfig index b609514de8..f423e57867 100644 --- a/configs/i12-tvbox_defconfig +++ b/configs/i12-tvbox_defconfig @@ -15,4 +15,5 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/icnova-a20-swac_defconfig b/configs/icnova-a20-swac_defconfig index 63bbd37f97..f158220225 100644 --- a/configs/icnova-a20-swac_defconfig +++ b/configs/icnova-a20-swac_defconfig @@ -22,4 +22,5 @@ CONFIG_CMD_UNZIP=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y +CONFIG_PHY_REALTEK=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/mixtile_loftq_defconfig b/configs/mixtile_loftq_defconfig index 47289c6616..4c81b3d7b3 100644 --- a/configs/mixtile_loftq_defconfig +++ b/configs/mixtile_loftq_defconfig @@ -16,5 +16,6 @@ CONFIG_SPL=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y CONFIG_AXP_ALDO1_VOLT=3300 CONFIG_USB_EHCI_HCD=y diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index c0d141754f..04e8cf39c8 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -182,6 +182,9 @@ config SUN4I_EMAC sun4i hardware. Newer hardware supports the SUN7I_EMAC driver, which also works with 100 Megabit PHY's.
+config SUN7I_MAC + bool + choice prompt "Allwinner Sun7i GMAC support" help @@ -196,6 +199,7 @@ config SUN7I_NONE config SUN7I_EMAC bool "MII" select ETH_DESIGNWARE + select SUN7I_MAC select PHYLIB select MII help @@ -205,6 +209,7 @@ config SUN7I_EMAC config SUN7I_GMAC bool "RGMII" select ETH_DESIGNWARE + select SUN7I_MAC select PHYLIB select RGMII select PHY_GIGE diff --git a/drivers/net/Makefile b/drivers/net/Makefile index aedb2cc90d..c5dd52bee2 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -22,7 +22,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_SUN4I_EMAC) += sunxi_emac.o obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_EP93XX) += ep93xx_eth.o diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h index 8f97b80619..5d2c5b9040 100644 --- a/include/configs/sunxi-common.h +++ b/include/configs/sunxi-common.h @@ -287,15 +287,12 @@ extern int soft_i2c_gpio_scl; #endif /* CONFIG_VIDEO */
/* Ethernet support */ -#ifdef CONFIG_SUNXI_EMAC +#if defined(CONFIG_SUN4I_EMAC) || \ + defined(CONFIG_SUN7I_EMAC) || \ + defined(CONFIG_SUN7I_GMAC) #define CONFIG_PHY_ADDR 1 #endif
-#ifdef CONFIG_SUNXI_GMAC -#define CONFIG_PHY_ADDR 1 -#define CONFIG_PHY_REALTEK -#endif - #ifdef CONFIG_USB_EHCI_HCD #define CONFIG_USB_OHCI_NEW #define CONFIG_USB_OHCI_SUNXI diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index cd0165f934..1e2bf24d5a 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -2796,8 +2796,6 @@ CONFIG_STV0991_HZ CONFIG_STV0991_HZ_CLOCK CONFIG_ST_SMI CONFIG_SUNXI_AHCI -CONFIG_SUNXI_EMAC -CONFIG_SUNXI_GMAC CONFIG_SUNXI_GPIO CONFIG_SUNXI_MAX_FB_SIZE CONFIG_SUNXI_USB_PHYS

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
Commit 4d43d065db326 ("sunxi: Move SUNXI_GMAC to Kconfig") renamed SUNXI_[EG]MAC but did not update include/configs/sunxi-common.h where based on these two symbols other config symbols where being set, such as CONFIG_PHY_REALTEK for SUNXI_GMAC boards and the CONFIG_PHY_ADDR being set to a safe default.
This patch restores that behavior by adding the PHY_REALTEK to the defconfigs, where they belong and by setting the address based on the new config symbols.
Additionally, we use the new renamed symbol in the Makefiles to actually compile the drivers.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
arch/arm/include/asm/arch-sunxi/sys_proto.h | 2 +- board/sunxi/Makefile | 2 +- configs/A20-OLinuXino-Lime2_defconfig | 1 + configs/A20-OLinuXino-Lime_defconfig | 1 + configs/A20-OLinuXino_MICRO_defconfig | 1 + configs/A20-Olimex-SOM-EVB_defconfig | 1 + configs/Bananapi_defconfig | 1 + configs/Bananapro_defconfig | 1 + configs/CSQ_CS908_defconfig | 1 + configs/Colombus_defconfig | 1 + configs/Cubieboard2_defconfig | 1 + configs/Cubietruck_defconfig | 1 + configs/Hummingbird_A31_defconfig | 1 + configs/Itead_Ibox_A20_defconfig | 1 + configs/Lamobo_R1_defconfig | 1 + configs/Linksprite_pcDuino3_Nano_defconfig | 1 + configs/Linksprite_pcDuino3_defconfig | 1 + configs/Mele_A1000G_quad_defconfig | 1 + configs/Mele_I7_defconfig | 1 + configs/Mele_M3_defconfig | 1 + configs/Mele_M5_defconfig | 1 + configs/Mele_M9_defconfig | 1 + configs/Orangepi_defconfig | 1 + configs/Orangepi_mini_defconfig | 1 + configs/Sinlinx_SinA31s_defconfig | 1 + configs/Sinovoip_BPI_M2_defconfig | 1 + configs/Wits_Pro_A20_DKT_defconfig | 1 + configs/i12-tvbox_defconfig | 1 + configs/icnova-a20-swac_defconfig | 1 + configs/mixtile_loftq_defconfig | 1 + drivers/net/Kconfig | 5 +++++ drivers/net/Makefile | 2 +- include/configs/sunxi-common.h | 9 +++------ scripts/config_whitelist.txt | 2 -- 34 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/arch/arm/include/asm/arch-sunxi/sys_proto.h b/arch/arm/include/asm/arch-sunxi/sys_proto.h index a373319a2b..850236ed42 100644 --- a/arch/arm/include/asm/arch-sunxi/sys_proto.h +++ b/arch/arm/include/asm/arch-sunxi/sys_proto.h @@ -24,7 +24,7 @@ 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 +#if !defined CONFIG_SPL_BUILD && defined CONFIG_SUN7I_MAC void eth_init_board(void); #else static inline void eth_init_board(void) {} diff --git a/board/sunxi/Makefile b/board/sunxi/Makefile index 43766e0ef4..b4768b9b9b 100644 --- a/board/sunxi/Makefile +++ b/board/sunxi/Makefile @@ -9,7 +9,7 @@ # SPDX-License-Identifier: GPL-2.0+ # obj-y += board.o -obj-$(CONFIG_SUNXI_GMAC) += gmac.o +obj-$(CONFIG_SUN7I_MAC) += gmac.o obj-$(CONFIG_SUNXI_AHCI) += ahci.o obj-$(CONFIG_MACH_SUN4I) += dram_sun4i_auto.o obj-$(CONFIG_MACH_SUN5I) += dram_sun5i_auto.o diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 14d1159ead..14a51ef3f9 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -22,6 +22,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_SPL_PARTITION_UUIDS is not set CONFIG_DFU_RAM=y CONFIG_SUN7I_GMAC=y +CONFIG_PHY_REALTEK=y
Would it make sense to either select this at the platform level or to imply it in the driver Kconfig?
CONFIG_RTL8211X_PHY_FORCE_MASTER=y CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800
[...]
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index c0d141754f..04e8cf39c8 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -182,6 +182,9 @@ config SUN4I_EMAC sun4i hardware. Newer hardware supports the SUN7I_EMAC driver, which also works with 100 Megabit PHY's.
+config SUN7I_MAC
bool
choice prompt "Allwinner Sun7i GMAC support" help @@ -196,6 +199,7 @@ config SUN7I_NONE config SUN7I_EMAC bool "MII" select ETH_DESIGNWARE
select SUN7I_MAC select PHYLIB select MII help
@@ -205,6 +209,7 @@ config SUN7I_EMAC config SUN7I_GMAC bool "RGMII" select ETH_DESIGNWARE
select SUN7I_MAC select PHYLIB select RGMII select PHY_GIGE
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index aedb2cc90d..c5dd52bee2 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -22,7 +22,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_SUN4I_EMAC) += sunxi_emac.o obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_EP93XX) += ep93xx_eth.o diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h index 8f97b80619..5d2c5b9040 100644 --- a/include/configs/sunxi-common.h +++ b/include/configs/sunxi-common.h @@ -287,15 +287,12 @@ extern int soft_i2c_gpio_scl; #endif /* CONFIG_VIDEO */
/* Ethernet support */ -#ifdef CONFIG_SUNXI_EMAC +#if defined(CONFIG_SUN4I_EMAC) || \
- defined(CONFIG_SUN7I_EMAC) || \
- defined(CONFIG_SUN7I_GMAC)
#define CONFIG_PHY_ADDR 1 #endif
-#ifdef CONFIG_SUNXI_GMAC -#define CONFIG_PHY_ADDR 1 -#define CONFIG_PHY_REALTEK -#endif
#ifdef CONFIG_USB_EHCI_HCD #define CONFIG_USB_OHCI_NEW #define CONFIG_USB_OHCI_SUNXI diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index cd0165f934..1e2bf24d5a 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -2796,8 +2796,6 @@ CONFIG_STV0991_HZ CONFIG_STV0991_HZ_CLOCK CONFIG_ST_SMI CONFIG_SUNXI_AHCI -CONFIG_SUNXI_EMAC -CONFIG_SUNXI_GMAC CONFIG_SUNXI_GPIO CONFIG_SUNXI_MAX_FB_SIZE CONFIG_SUNXI_USB_PHYS -- 2.11.0
U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot

The GMAC_TX_DELAY symbol sets and is dependent on the SUN7I_GMAC driver. Move it from the generic ARCH section to the driver specific section.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- arch/arm/mach-sunxi/Kconfig | 6 ------ drivers/net/Kconfig | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index 8d9900e00b..be060b65dc 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -748,12 +748,6 @@ config SATAPWR format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
-config GMAC_TX_DELAY - int "GMAC Transmit Clock Delay Chain" - default 0 - ---help--- - Set the GMAC Transmit Clock Delay Chain value. - config SPL_STACK_R_ADDR default 0x4fe00000 if MACH_SUN4I default 0x4fe00000 if MACH_SUN5I diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 04e8cf39c8..782348f872 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -219,6 +219,13 @@ config SUN7I_GMAC
endchoice
+config GMAC_TX_DELAY + depends on SUN7I_GMAC + int "- GMAC Transmit Clock Delay Chain" + default 0 + help + Set the GMAC Transmit Clock Delay Chain value. + config SUN8I_EMAC bool "Allwinner Sun8i Ethernet MAC support" depends on DM_ETH

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
The GMAC_TX_DELAY symbol sets and is dependent on the SUN7I_GMAC driver. Move it from the generic ARCH section to the driver specific section.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

Previously overlooked magic value in commit a40db6d51171 ("net: cosmetic: Do not use magic values for ARP_HLEN")
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- include/net.h | 4 ++-- net/eth_common.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/net.h b/include/net.h index ed5259a807..c703c62c99 100644 --- a/include/net.h +++ b/include/net.h @@ -275,7 +275,7 @@ int usb_ether_init(void); * Args: * base_name - base name for device (normally "eth") * index - device index number (0 for first) - * enetaddr - returns 6 byte hardware address + * enetaddr - returns ARP_HLEN byte hardware address * Returns: * Return true if the address is valid. */ @@ -818,7 +818,7 @@ static inline void net_random_ethaddr(uchar *addr) int i; unsigned int seed = get_timer(0);
- for (i = 0; i < 6; i++) + for (i = 0; i < ARP_HLEN; i++) addr[i] = rand_r(&seed);
addr[0] &= 0xfe; /* clear multicast bit */ diff --git a/net/eth_common.c b/net/eth_common.c index 58fa295771..049c1ee6f9 100644 --- a/net/eth_common.c +++ b/net/eth_common.c @@ -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;

On Mon, May 15, 2017 at 10:02:24AM +0200, Olliver Schinagl wrote:
Previously overlooked magic value in commit a40db6d51171 ("net: cosmetic: Do not use magic values for ARP_HLEN")
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Reviewed-by: Tom Rini trini@konsulko.com

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
Previously overlooked magic value in commit a40db6d51171 ("net: cosmetic: Do not use magic values for ARP_HLEN")
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- common/fdt_support.c | 2 +- include/net.h | 1 + net/eth_common.c | 14 +++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/common/fdt_support.c b/common/fdt_support.c index c6a76b7ad2..d462bf0642 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -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; diff --git a/include/net.h b/include/net.h index c703c62c99..ad2a8a3678 100644 --- a/include/net.h +++ b/include/net.h @@ -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);
diff --git a/net/eth_common.c b/net/eth_common.c index 049c1ee6f9..0fe4d260d8 100644 --- a/net/eth_common.c +++ b/net/eth_common.c @@ -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);

On Mon, May 15, 2017 at 10:02:25AM +0200, Olliver Schinagl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Reviewed-by: Tom Rini trini@konsulko.com

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- net/eth-uclass.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/eth-uclass.c b/net/eth-uclass.c index c3cc3152a2..781376955a 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -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; }

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

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.
Unicast and multicast addresses are distinguised by setting the least-significant bit of the first octet of the address. Having a function to check and set this U/M bit from a function it nice to make a generated mac address a unicast address.
This patch introduces both these helper functions
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- include/net.h | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/include/net.h b/include/net.h index ad2a8a3678..00677a0a89 100644 --- a/include/net.h +++ b/include/net.h @@ -767,6 +767,9 @@ static inline int is_zero_ethaddr(const u8 *addr) return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); }
+/* IEEE802 Unicast/Multicast bit */ +#define IEEE802_UM_BIT 0x1 + /** * is_multicast_ethaddr - Determine if the Ethernet address is a multicast. * @addr: Pointer to a six-byte array containing the Ethernet address @@ -776,7 +779,41 @@ static inline int is_zero_ethaddr(const u8 *addr) */ static inline int is_multicast_ethaddr(const u8 *addr) { - return 0x01 & addr[0]; + return addr[0] & IEEE802_UM_BIT; +} + +/** + * set_unicast_ethaddr - Make the supplied Ethernet address an unicast. + * @addr: Pointer to a six-byte array containing the Ethernet address + */ +static inline void set_unicast_ethaddr(u8 *addr) +{ + addr[0] &= ~IEEE802_UM_BIT; +} + +/* IEEE802 Universal/Local administration bit */ +#define IEEE802_UL_BIT 0x02 + +/** + * 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 addr[0] & IEEE802_UL_BIT; +} + +/** + * 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] |= IEEE802_UL_BIT; }
/* @@ -822,8 +859,8 @@ static inline void net_random_ethaddr(uchar *addr) for (i = 0; i < ARP_HLEN; i++) addr[i] = rand_r(&seed);
- addr[0] &= 0xfe; /* clear multicast bit */ - addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ + addr[0] &= ~IEEE802_UM_BIT; + set_local_ethaddr(addr); }
/* Convert an IP address to a string */

On Mon, May 15, 2017 at 10:02:27AM +0200, Olliver Schinagl wrote:
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.
Unicast and multicast addresses are distinguised by setting the least-significant bit of the first octet of the address. Having a function to check and set this U/M bit from a function it nice to make a generated mac address a unicast address.
This patch introduces both these helper functions
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Reviewed-by: Tom Rini trini@konsulko.com

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Unicast and multicast addresses are distinguised by setting the least-significant bit of the first octet of the address. Having a function to check and set this U/M bit from a function it nice to make a generated mac address a unicast address.
This patch introduces both these helper functions
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- arch/arm/mach-sunxi/Kconfig | 8 +-- configs/A10-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino-Lime2-eMMC_defconfig | 1 - configs/A20-OLinuXino-Lime2_defconfig | 1 - configs/A20-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino_MICRO_defconfig | 1 - doc/README.enetaddr | 95 ++++++++++++++++++++++++++++++ include/net.h | 14 +++++ net/Kconfig | 59 +++++++++++++++++++ net/eth-uclass.c | 42 +++++++------ net/eth_common.c | 37 ++++++++++++ net/eth_legacy.c | 2 + 12 files changed, 231 insertions(+), 31 deletions(-)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index be060b65dc..cf5af4fe18 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -479,14 +479,14 @@ config I2C0_ENABLE
config I2C1_ENABLE bool "Enable I2C/TWI controller 1" - default n + default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1) select CMD_I2C ---help--- See I2C0_ENABLE help text.
config I2C2_ENABLE bool "Enable I2C/TWI controller 2" - default n + default y if (NET_ETHADDR_EEPROM_I2C_BUS = 2) select CMD_I2C ---help--- See I2C0_ENABLE help text. @@ -494,7 +494,7 @@ config I2C2_ENABLE if MACH_SUN6I || MACH_SUN7I config I2C3_ENABLE bool "Enable I2C/TWI controller 3" - default n + default y if (NET_ETHADDR_EEPROM_I2C_BUS = 3) select CMD_I2C ---help--- See I2C0_ENABLE help text. @@ -513,7 +513,7 @@ endif if MACH_SUN7I config I2C4_ENABLE bool "Enable I2C/TWI controller 4" - default n + default y if (NET_ETHADDR_EEPROM_I2C_BUS = 4) select CMD_I2C ---help--- See I2C0_ENABLE help text. diff --git a/configs/A10-OLinuXino-Lime_defconfig b/configs/A10-OLinuXino-Lime_defconfig index ec16a44fbd..d4513144eb 100644 --- a/configs/A10-OLinuXino-Lime_defconfig +++ b/configs/A10-OLinuXino-Lime_defconfig @@ -5,7 +5,6 @@ CONFIG_DRAM_CLK=480 CONFIG_DRAM_EMR1=4 CONFIG_SYS_CLK_FREQ=912000000 CONFIG_MMC0_CD_PIN="PH1" -CONFIG_I2C1_ENABLE=y CONFIG_SATAPWR="PC3" CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-olinuxino-lime" CONFIG_AHCI=y diff --git a/configs/A20-OLinuXino-Lime2-eMMC_defconfig b/configs/A20-OLinuXino-Lime2-eMMC_defconfig index 76525f4603..fd743a5f45 100644 --- a/configs/A20-OLinuXino-Lime2-eMMC_defconfig +++ b/configs/A20-OLinuXino-Lime2-eMMC_defconfig @@ -6,7 +6,6 @@ CONFIG_MMC0_CD_PIN="PH1" CONFIG_MMC_SUNXI_SLOT_EXTRA=2 CONFIG_USB0_VBUS_PIN="PC17" CONFIG_USB0_VBUS_DET="PH5" -CONFIG_I2C1_ENABLE=y CONFIG_SATAPWR="PC3" CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-lime2-emmc" CONFIG_AHCI=y diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 14a51ef3f9..a932ec7b7b 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -5,7 +5,6 @@ CONFIG_DRAM_CLK=384 CONFIG_MMC0_CD_PIN="PH1" CONFIG_USB0_VBUS_PIN="PC17" CONFIG_USB0_VBUS_DET="PH5" -CONFIG_I2C1_ENABLE=y CONFIG_SATAPWR="PC3" CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-lime2" CONFIG_AHCI=y diff --git a/configs/A20-OLinuXino-Lime_defconfig b/configs/A20-OLinuXino-Lime_defconfig index 3fdf7c64aa..41667384f4 100644 --- a/configs/A20-OLinuXino-Lime_defconfig +++ b/configs/A20-OLinuXino-Lime_defconfig @@ -3,7 +3,6 @@ CONFIG_ARCH_SUNXI=y CONFIG_MACH_SUN7I=y CONFIG_DRAM_CLK=384 CONFIG_MMC0_CD_PIN="PH1" -CONFIG_I2C1_ENABLE=y CONFIG_SATAPWR="PC3" CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-lime" CONFIG_AHCI=y diff --git a/configs/A20-OLinuXino_MICRO_defconfig b/configs/A20-OLinuXino_MICRO_defconfig index ea7bc73dda..b1f80835c9 100644 --- a/configs/A20-OLinuXino_MICRO_defconfig +++ b/configs/A20-OLinuXino_MICRO_defconfig @@ -5,7 +5,6 @@ CONFIG_DRAM_CLK=384 CONFIG_MMC0_CD_PIN="PH1" CONFIG_MMC3_CD_PIN="PH11" CONFIG_MMC_SUNXI_SLOT_EXTRA=3 -CONFIG_I2C1_ENABLE=y CONFIG_VIDEO_VGA=y CONFIG_SATAPWR="PB8" CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-olinuxino-micro" diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899787..6f51137710 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,101 @@ 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> i2c dev 1 +u-boot> i2c md 0x50 0x08 0x01 +u-boot> i2c md 0x50 0x09 0x23 +u-boot> i2c md 0x50 0x0a 0x45 +u-boot> i2c md 0x50 0x0b 0x67 +u-boot> i2c md 0x50 0x0c 0x89 +u-boot> i2c md 0x50 0x0d 0xab +u-boot> i2c md 0x50 0x0e 0xbe + ------- Usage ------- diff --git a/include/net.h b/include/net.h index 00677a0a89..392dc95fdc 100644 --- a/include/net.h +++ b/include/net.h @@ -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). diff --git a/net/Kconfig b/net/Kconfig index 414c5497c7..ed7706c428 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,65 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM + bool "Get ethaddr from eeprom" + help + Selecting this will try to get the Ethernet address from an onboard + EEPROM and set into the environment if and only if the environment + does currently not already hold a MAC address. For more information + see doc/README.enetaddr. + +config NET_ETHADDR_EEPROM_I2C + depends on NET_ETHADDR_EEPROM + bool "EEPROM on I2C bus" + help + This switch enables checks for an EEPROM on the I2C bus. Naturally + this will only work if there is an actual EEPROM connected on the + I2C bus and the bus and device are properly configured via the + options below. + +config NET_ETHADDR_EEPROM_I2C_BUS + depends on NET_ETHADDR_EEPROM_I2C + int "I2C bus" + default 0 + help + Select the bus on which the EEPROM is present, defaults to bus 0. + Remember to also make the selected bus available via I2Cn_ENABLE. + +config NET_ETHADDR_EEPROM_I2C_ADDR + depends on NET_ETHADDR_EEPROM_I2C + hex "EEPROM address" + default 0x50 + help + Select the address of the EEPROM, defaults to address 0x50. + +config NET_ETHADDR_EEPROM_I2C_ADDRLEN + depends on NET_ETHADDR_EEPROM_I2C + int "EEPROM address length" + default 1 + help + Number of bytes to be used for the I2C address length. Typically 1, + 2 for large memories, 0 for register type devices with only one + register. + +config NET_ETHADDR_EEPROM_OFFSET + depends on NET_ETHADDR_EEPROM + hex "EEPROM offset" + default 8 + help + Select the byte offset of the MAC address within the page, + defaults to byte 8. + +config NET_ETHADDR_EEPROM_CRC8 + depends on NET_ETHADDR_EEPROM + bool "Check CRC8 of MAC" + default y + help + Optionally, it is possible to run a CRC-8-CCITT check on the MAC + address. To do so, the MAC address is stored with a CRC8 byte append. + This option enables the CRC check of the MAC address against the CRC + byte. + config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 781376955a..02ee926f74 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -459,7 +459,8 @@ static int eth_post_probe(struct udevice *dev) { struct eth_device_priv *priv = dev->uclass_priv; struct eth_pdata *pdata = dev->platdata; - unsigned char env_enetaddr[ARP_HLEN]; + unsigned char env_enetaddr[ARP_HLEN] = { 0x00 }; + int ret;
#if defined(CONFIG_NEEDS_MANUAL_RELOC) struct eth_ops *ops = eth_get_ops(dev); @@ -490,38 +491,35 @@ static int eth_post_probe(struct udevice *dev) #endif
priv->state = ETH_STATE_INIT; + pdata->enetaddr_src = ENETADDR_SRC_UNKNOWN; + + /* Check if the device has a MAC address in EEPROM */ + ret = eeprom_read_enetaddr(dev->seq, pdata->enetaddr); + if (!ret && !is_zero_ethaddr(pdata->enetaddr)) + 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); + pdata->enetaddr_src = ENETADDR_SRC_DRIVER; + }
- /* Check if the device has a MAC address in ROM */ - if (eth_get_ops(dev)->read_rom_hwaddr) - eth_get_ops(dev)->read_rom_hwaddr(dev); - + /* Check the environment for a MAC address */ eth_getenv_enetaddr_by_index("eth", dev->seq, env_enetaddr); if (!is_zero_ethaddr(env_enetaddr)) { - if (!is_zero_ethaddr(pdata->enetaddr) && - memcmp(pdata->enetaddr, env_enetaddr, ARP_HLEN)) { - printf("\nWarning: %s MAC addresses don't match:\n", - dev->name); - printf("Address in ROM is %pM\n", - pdata->enetaddr); - printf("Address in environment is %pM\n", - env_enetaddr); - } - - /* Override the ROM MAC address */ + /* Override the (EEP)ROM MAC address */ memcpy(pdata->enetaddr, env_enetaddr, ARP_HLEN); + pdata->enetaddr_src = ENETADDR_SRC_ENV; } else if (is_valid_ethaddr(pdata->enetaddr)) { eth_setenv_enetaddr_by_index("eth", dev->seq, pdata->enetaddr); - printf("\nWarning: %s using MAC address from ROM\n", - dev->name); } else if (is_zero_ethaddr(pdata->enetaddr) || !is_valid_ethaddr(pdata->enetaddr)) { + /* No valid MAC addresses found, fall back */ #ifdef CONFIG_NET_RANDOM_ETHADDR net_random_ethaddr(pdata->enetaddr); - printf("\nWarning: %s (eth%d) using random MAC address - %pM\n", - dev->name, dev->seq, pdata->enetaddr); + pdata->enetaddr_src = ENETADDR_SRC_RANDOM; #else - printf("\nError: %s address not set.\n", - dev->name); + pdata->enetaddr_src = ENETADDR_SRC_NONE; return -EINVAL; #endif } diff --git a/net/eth_common.c b/net/eth_common.c index 0fe4d260d8..24488746c9 100644 --- a/net/eth_common.c +++ b/net/eth_common.c @@ -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; diff --git a/net/eth_legacy.c b/net/eth_legacy.c index e4bd0f4c1a..4276058800 100644 --- a/net/eth_legacy.c +++ b/net/eth_legacy.c @@ -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)) {

On Mon, May 15, 2017 at 10:02:28AM +0200, Olliver Schinagl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
arch/arm/mach-sunxi/Kconfig | 8 +-- configs/A10-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino-Lime2-eMMC_defconfig | 1 - configs/A20-OLinuXino-Lime2_defconfig | 1 - configs/A20-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino_MICRO_defconfig | 1 - doc/README.enetaddr | 95 ++++++++++++++++++++++++++++++ include/net.h | 14 +++++ net/Kconfig | 59 +++++++++++++++++++ net/eth-uclass.c | 42 +++++++------ net/eth_common.c | 37 ++++++++++++ net/eth_legacy.c | 2 + 12 files changed, 231 insertions(+), 31 deletions(-)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index be060b65dc..cf5af4fe18 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -479,14 +479,14 @@ config I2C0_ENABLE
config I2C1_ENABLE bool "Enable I2C/TWI controller 1"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1) select CMD_I2C ---help--- See I2C0_ENABLE help text.
config I2C2_ENABLE bool "Enable I2C/TWI controller 2"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 2) select CMD_I2C ---help--- See I2C0_ENABLE help text.
@@ -494,7 +494,7 @@ config I2C2_ENABLE if MACH_SUN6I || MACH_SUN7I config I2C3_ENABLE bool "Enable I2C/TWI controller 3"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 3) select CMD_I2C ---help--- See I2C0_ENABLE help text.
@@ -513,7 +513,7 @@ endif if MACH_SUN7I config I2C4_ENABLE bool "Enable I2C/TWI controller 4"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 4) select CMD_I2C ---help--- See I2C0_ENABLE help text.
diff --git a/configs/A10-OLinuXino-Lime_defconfig b/configs/A10-OLinuXino-Lime_defconfig index ec16a44fbd..d4513144eb 100644 --- a/configs/A10-OLinuXino-Lime_defconfig +++ b/configs/A10-OLinuXino-Lime_defconfig @@ -5,7 +5,6 @@ CONFIG_DRAM_CLK=480 CONFIG_DRAM_EMR1=4 CONFIG_SYS_CLK_FREQ=912000000 CONFIG_MMC0_CD_PIN="PH1" -CONFIG_I2C1_ENABLE=y
Didn't that just remove the option if NET_ETHADDR_EEPROM is disabled (which is its default) ?
Maxime

Hey Maxime,
On 15-05-17 10:18, Maxime Ripard wrote:
On Mon, May 15, 2017 at 10:02:28AM +0200, Olliver Schinagl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
arch/arm/mach-sunxi/Kconfig | 8 +-- configs/A10-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino-Lime2-eMMC_defconfig | 1 - configs/A20-OLinuXino-Lime2_defconfig | 1 - configs/A20-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino_MICRO_defconfig | 1 - doc/README.enetaddr | 95 ++++++++++++++++++++++++++++++ include/net.h | 14 +++++ net/Kconfig | 59 +++++++++++++++++++ net/eth-uclass.c | 42 +++++++------ net/eth_common.c | 37 ++++++++++++ net/eth_legacy.c | 2 + 12 files changed, 231 insertions(+), 31 deletions(-)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index be060b65dc..cf5af4fe18 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -479,14 +479,14 @@ config I2C0_ENABLE
config I2C1_ENABLE bool "Enable I2C/TWI controller 1"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1) select CMD_I2C ---help--- See I2C0_ENABLE help text.
config I2C2_ENABLE bool "Enable I2C/TWI controller 2"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 2) select CMD_I2C ---help--- See I2C0_ENABLE help text.
@@ -494,7 +494,7 @@ config I2C2_ENABLE if MACH_SUN6I || MACH_SUN7I config I2C3_ENABLE bool "Enable I2C/TWI controller 3"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 3) select CMD_I2C ---help--- See I2C0_ENABLE help text.
@@ -513,7 +513,7 @@ endif if MACH_SUN7I config I2C4_ENABLE bool "Enable I2C/TWI controller 4"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 4) select CMD_I2C ---help--- See I2C0_ENABLE help text.
diff --git a/configs/A10-OLinuXino-Lime_defconfig b/configs/A10-OLinuXino-Lime_defconfig index ec16a44fbd..d4513144eb 100644 --- a/configs/A10-OLinuXino-Lime_defconfig +++ b/configs/A10-OLinuXino-Lime_defconfig @@ -5,7 +5,6 @@ CONFIG_DRAM_CLK=480 CONFIG_DRAM_EMR1=4 CONFIG_SYS_CLK_FREQ=912000000 CONFIG_MMC0_CD_PIN="PH1" -CONFIG_I2C1_ENABLE=y
Didn't that just remove the option if NET_ETHADDR_EEPROM is disabled (which is its default) ?
I initially forced I2C1_ENABLE on all the Olimex boards before finding that I could do:
default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
So by defining NET_ETHADDR_EEPROM_I2C_BUS = x in the defconfig, the correct I2C1_ENABLE is being set, so we do not need to hardcode this in the defconfig anymore.
Or am I miss-understanding you?
Olliver
Maxime

On Mon, May 15, 2017 at 02:18:06PM +0200, Olliver Schinagl wrote:
Hey Maxime,
On 15-05-17 10:18, Maxime Ripard wrote:
On Mon, May 15, 2017 at 10:02:28AM +0200, Olliver Schinagl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
arch/arm/mach-sunxi/Kconfig | 8 +-- configs/A10-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino-Lime2-eMMC_defconfig | 1 - configs/A20-OLinuXino-Lime2_defconfig | 1 - configs/A20-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino_MICRO_defconfig | 1 - doc/README.enetaddr | 95 ++++++++++++++++++++++++++++++ include/net.h | 14 +++++ net/Kconfig | 59 +++++++++++++++++++ net/eth-uclass.c | 42 +++++++------ net/eth_common.c | 37 ++++++++++++ net/eth_legacy.c | 2 + 12 files changed, 231 insertions(+), 31 deletions(-)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index be060b65dc..cf5af4fe18 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -479,14 +479,14 @@ config I2C0_ENABLE
config I2C1_ENABLE bool "Enable I2C/TWI controller 1"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1) select CMD_I2C ---help--- See I2C0_ENABLE help text.
config I2C2_ENABLE bool "Enable I2C/TWI controller 2"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 2) select CMD_I2C ---help--- See I2C0_ENABLE help text.
@@ -494,7 +494,7 @@ config I2C2_ENABLE if MACH_SUN6I || MACH_SUN7I config I2C3_ENABLE bool "Enable I2C/TWI controller 3"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 3) select CMD_I2C ---help--- See I2C0_ENABLE help text.
@@ -513,7 +513,7 @@ endif if MACH_SUN7I config I2C4_ENABLE bool "Enable I2C/TWI controller 4"
- default n
- default y if (NET_ETHADDR_EEPROM_I2C_BUS = 4) select CMD_I2C ---help--- See I2C0_ENABLE help text.
diff --git a/configs/A10-OLinuXino-Lime_defconfig b/configs/A10-OLinuXino-Lime_defconfig index ec16a44fbd..d4513144eb 100644 --- a/configs/A10-OLinuXino-Lime_defconfig +++ b/configs/A10-OLinuXino-Lime_defconfig @@ -5,7 +5,6 @@ CONFIG_DRAM_CLK=480 CONFIG_DRAM_EMR1=4 CONFIG_SYS_CLK_FREQ=912000000 CONFIG_MMC0_CD_PIN="PH1" -CONFIG_I2C1_ENABLE=y
Didn't that just remove the option if NET_ETHADDR_EEPROM is disabled (which is its default) ?
I initially forced I2C1_ENABLE on all the Olimex boards before finding that I could do:
default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
So by defining NET_ETHADDR_EEPROM_I2C_BUS = x in the defconfig, the correct I2C1_ENABLE is being set, so we do not need to hardcode this in the defconfig anymore.
Or am I miss-understanding you?
My point is: before, you had the I2C enabled using the defconfig (and the defconfig alone), and you don't have that anymore.
Maxime

Hi Oliver,
On 15 May 2017 at 02:02, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
arch/arm/mach-sunxi/Kconfig | 8 +-- configs/A10-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino-Lime2-eMMC_defconfig | 1 - configs/A20-OLinuXino-Lime2_defconfig | 1 - configs/A20-OLinuXino-Lime_defconfig | 1 - configs/A20-OLinuXino_MICRO_defconfig | 1 - doc/README.enetaddr | 95 ++++++++++++++++++++++++++++++ include/net.h | 14 +++++ net/Kconfig | 59 +++++++++++++++++++ net/eth-uclass.c | 42 +++++++------ net/eth_common.c | 37 ++++++++++++ net/eth_legacy.c | 2 + 12 files changed, 231 insertions(+), 31 deletions(-)
Please don't implement this feature in legacy code / legacy I2C. New features should only use DM - otherwise it just makes it harder and harder to ever finish the port.
Regards, Simon

Hi Olliver,
On 15 May 2017 at 18:02, Olliver Schinagl oliver@schinagl.nl wrote:
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).
Note that Olimex has started to write their own data to the EEPROM for their A20 boards: https://github.com/OLIMEX/OLINUXINO/blob/master/SOFTWARE/A20/A20-eeprom-cont...
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Regards, Jonathan

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- include/net.h | 14 ++++++++++++++ net/eth-uclass.c | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/include/net.h b/include/net.h index 392dc95fdc..762ff2b319 100644 --- a/include/net.h +++ b/include/net.h @@ -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; }; diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 02ee926f74..c88b032868 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -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]");

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

Currently, we print that the MAC from the SROM does not match. It can be many forms of ROM, so lets drop the S.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- net/eth_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/eth_legacy.c b/net/eth_legacy.c index 4276058800..800b91c327 100644 --- a/net/eth_legacy.c +++ b/net/eth_legacy.c @@ -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);

On Mon, May 15, 2017 at 10:02:30AM +0200, Olliver Schinagl wrote:
Currently, we print that the MAC from the SROM does not match. It can be many forms of ROM, so lets drop the S.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
net/eth_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/eth_legacy.c b/net/eth_legacy.c index 4276058800..800b91c327 100644 --- a/net/eth_legacy.c +++ b/net/eth_legacy.c @@ -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);
We need to add a space in the print then as the output is manually aligned.

Hey Tom,
On 15-05-17 14:53, Tom Rini wrote:
On Mon, May 15, 2017 at 10:02:30AM +0200, Olliver Schinagl wrote:
Currently, we print that the MAC from the SROM does not match. It can be many forms of ROM, so lets drop the S.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
net/eth_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/eth_legacy.c b/net/eth_legacy.c index 4276058800..800b91c327 100644 --- a/net/eth_legacy.c +++ b/net/eth_legacy.c @@ -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);
We need to add a space in the print then as the output is manually aligned.
I did not realize, I'll add a space to this one, and a space to the already merged one as well.
Olliver

On Mon, May 15, 2017 at 7:53 AM, Tom Rini trini@konsulko.com wrote:
On Mon, May 15, 2017 at 10:02:30AM +0200, Olliver Schinagl wrote:
Currently, we print that the MAC from the SROM does not match. It can be many forms of ROM, so lets drop the S.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
net/eth_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/eth_legacy.c b/net/eth_legacy.c index 4276058800..800b91c327 100644 --- a/net/eth_legacy.c +++ b/net/eth_legacy.c @@ -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);
We need to add a space in the print then as the output is manually aligned.
Agreed.

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- net/eth-uclass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/eth-uclass.c b/net/eth-uclass.c index c88b032868..024136a7cb 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -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; }

On Mon, May 15, 2017 at 10:02:31AM +0200, Olliver Schinagl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Reviewed-by: Tom Rini trini@konsulko.com

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- common/fdt_support.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/common/fdt_support.c b/common/fdt_support.c index d462bf0642..4d05465232 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -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);

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- common/fdt_support.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/common/fdt_support.c b/common/fdt_support.c index 4d05465232..71cbee43e0 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -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",

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- arch/arm/include/asm/arch-sunxi/sys_proto.h | 2 + board/sunxi/board.c | 146 ++++++++++++++++++---------- 2 files changed, 95 insertions(+), 53 deletions(-)
diff --git a/arch/arm/include/asm/arch-sunxi/sys_proto.h b/arch/arm/include/asm/arch-sunxi/sys_proto.h index 850236ed42..f264c84b56 100644 --- a/arch/arm/include/asm/arch-sunxi/sys_proto.h +++ b/arch/arm/include/asm/arch-sunxi/sys_proto.h @@ -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 diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 01de42d031..db56fba233 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -21,6 +21,7 @@ #include <asm/arch/gpio.h> #include <asm/arch/mmc.h> #include <asm/arch/spl.h> +#include <asm/arch/sys_proto.h> #include <asm/arch/usb_phy.h> #ifndef CONFIG_ARM64 #include <asm/armv7.h> @@ -596,6 +597,73 @@ int g_dnl_board_usb_cable_connected(void) } #endif
+static int sunxi_get_board_serial(unsigned int *serial) +{ + int ret; + + ret = sunxi_get_sid(serial); + if (!ret || serial[0]) + return -ENOSYS; + + /* + * The single words 1 - 3 of the SID have quite a few bits + * which are the same on many models, so we take a crc32 + * of all 3 words, to get a more unique value. + * + * Note we only do this on newer SoCs as we cannot change + * the algorithm on older SoCs since those have been using + * fixed mac-addresses/serial based on only using word 3 for a + * long time and changing a fixed mac-address/serial with an + * u-boot update is not good. + */ +#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \ + !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \ + !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33) + serial[3] = crc32(0, (unsigned char *)&serial[1], 12); +#endif + + return 0; +} + + /* + * Generate a MAC address based on device index and the serial number. + * The first half of the of the first octet holds the eth index. + * + * In the second octet we forcefully mark the MAC address to a locally + * administered MAC address. + * + */ +int sunxi_gen_hwaddr(const int seq, unsigned char *enetaddr) +{ + uint8_t mac_addr[ARP_HLEN] = { 0x00 }; + unsigned int serial[4]; + int ret; + + if (!enetaddr || (seq < 0)) + return -ENOSYS; + + ret = sunxi_get_board_serial(serial); + if (!ret) + return ret; + + /* Ensure the NIC specific bytes of the mac are not all 0 */ + if ((serial[3] & 0xffffff) == 0) + serial[3] |= 0x800000; + + mac_addr[0] = (seq << 4); + mac_addr[1] = (serial[0] >> 0) & 0xff; + mac_addr[2] = (serial[3] >> 24) & 0xff; + mac_addr[3] = (serial[3] >> 16) & 0xff; + mac_addr[4] = (serial[3] >> 8) & 0xff; + mac_addr[5] = (serial[3] >> 0) & 0xff; + + set_local_ethaddr(mac_addr); + set_unicast_ethaddr(mac_addr); + memcpy(enetaddr, mac_addr, ARP_HLEN); + + return 0; +} + #ifdef CONFIG_SERIAL_TAG void get_board_serial(struct tag_serialnr *serialnr) { @@ -655,71 +723,35 @@ static void parse_spl_header(const uint32_t spl_addr) */ static void setup_environment(const void *fdt) { - char serial_string[17] = { 0 }; - unsigned int sid[4]; - uint8_t mac_addr[6]; - char ethaddr[16]; + uint8_t enetaddr[ARP_HLEN]; + char ethaddr[ETH_ENETADDR_ENV_NAME_LEN]; int i, ret;
- ret = sunxi_get_sid(sid); - if (ret == 0 && sid[0] != 0) { - /* - * The single words 1 - 3 of the SID have quite a few bits - * which are the same on many models, so we take a crc32 - * of all 3 words, to get a more unique value. - * - * Note we only do this on newer SoCs as we cannot change - * the algorithm on older SoCs since those have been using - * fixed mac-addresses based on only using word 3 for a - * long time and changing a fixed mac-address with an - * u-boot update is not good. - */ -#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \ - !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \ - !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33) - sid[3] = crc32(0, (unsigned char *)&sid[1], 12); -#endif - - /* Ensure the NIC specific bytes of the mac are not all 0 */ - if ((sid[3] & 0xffffff) == 0) - sid[3] |= 0x800000; - - for (i = 0; i < 4; i++) { - sprintf(ethaddr, "ethernet%d", i); - if (!fdt_get_alias(fdt, ethaddr)) - continue; - - if (i == 0) - strcpy(ethaddr, "ethaddr"); - else - sprintf(ethaddr, "eth%daddr", i); - - if (getenv(ethaddr)) - continue; + for (i = 0; i < 4; i++) { + sprintf(ethaddr, "ethernet%d", i); + if (!fdt_get_alias(fdt, ethaddr)) + continue;
- /* Non OUI / registered MAC address */ - mac_addr[0] = (i << 4) | 0x02; - mac_addr[1] = (sid[0] >> 0) & 0xff; - mac_addr[2] = (sid[3] >> 24) & 0xff; - mac_addr[3] = (sid[3] >> 16) & 0xff; - mac_addr[4] = (sid[3] >> 8) & 0xff; - mac_addr[5] = (sid[3] >> 0) & 0xff; + if (i == 0) + strcpy(ethaddr, "ethaddr"); + else + sprintf(ethaddr, "eth%daddr", i);
- eth_setenv_enetaddr(ethaddr, mac_addr); - } + if (getenv(ethaddr)) + continue;
- if (!getenv("serial#")) { - snprintf(serial_string, sizeof(serial_string), - "%08x%08x", sid[0], sid[3]); + ret = sunxi_gen_hwaddr(i, enetaddr); + if (!ret) + return;
- setenv("serial#", serial_string); - } + eth_setenv_enetaddr(ethaddr, enetaddr); } }
int misc_init_r(void) { __maybe_unused int ret; + unsigned int serial[4];
setenv("fel_booted", NULL); setenv("fel_scriptaddr", NULL); @@ -730,6 +762,14 @@ int misc_init_r(void) }
setup_environment(gd->fdt_blob); + if (!getenv("serial#") && sunxi_get_board_serial(serial)) { + char serial_string[17] = { 0 }; + + snprintf(serial_string, sizeof(serial_string), + "%08x%08x", serial[0], serial[3]); + + setenv("serial#", serial_string); + }
#ifndef CONFIG_MACH_SUN9I ret = sunxi_usb_phy_probe();

Typo in the subject line...
"arm: sunxi: Expose function to generate _a_ sunxi-specific MAC address"
On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Looks fine other than the subject.
Acked-by: Joe Hershberger joe.hershberger@ni.com

Expose the write_hwaddr net_ops hook to write the Ethernet address.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/sunxi_emac.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sunxi_emac.c index 99339db4bf..0dc37de242 100644 --- a/drivers/net/sunxi_emac.c +++ b/drivers/net/sunxi_emac.c @@ -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)

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
Expose the write_hwaddr net_ops hook to write the Ethernet address.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

The sunxi_emac driver is very specific to the IP used in the sun4i. Thus rename it to what it actually is, the MAC driver for the sun4i MAC.
The rename also changes the variable and function names inside the driver. There are no code changes in this patch however.
While here, use the BIT() macro for bitfields as well.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/Makefile | 2 +- drivers/net/{sunxi_emac.c => sun4i_mac.c} | 260 +++++++++++++++--------------- 2 files changed, 133 insertions(+), 129 deletions(-) rename drivers/net/{sunxi_emac.c => sun4i_mac.c} (60%)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index c5dd52bee2..9834d67146 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -22,7 +22,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_SUN4I_EMAC) += sunxi_emac.o +obj-$(CONFIG_SUN4I_EMAC) += sun4i_mac.o obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_EP93XX) += ep93xx_eth.o diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sun4i_mac.c similarity index 60% rename from drivers/net/sunxi_emac.c rename to drivers/net/sun4i_mac.c index 0dc37de242..ea52bd8a17 100644 --- a/drivers/net/sunxi_emac.c +++ b/drivers/net/sun4i_mac.c @@ -1,5 +1,5 @@ /* - * sunxi_emac.c -- Allwinner A10 ethernet driver + * sun4i_mac.c -- Allwinner A10 ethernet driver * * (C) Copyright 2012, Stefan Roese sr@denx.de * @@ -9,6 +9,7 @@ #include <common.h> #include <dm.h> #include <linux/err.h> +#include <linux/bitops.h> #include <malloc.h> #include <miiphy.h> #include <net.h> @@ -17,7 +18,7 @@ #include <asm/arch/gpio.h>
/* EMAC register */ -struct emac_regs { +struct sun4i_mac_regs { u32 ctl; /* 0x00 */ u32 tx_mode; /* 0x04 */ u32 tx_flow; /* 0x08 */ @@ -67,111 +68,114 @@ struct sunxi_sramc_regs { };
/* 0: Disable 1: Aborted frame enable(default) */ -#define EMAC_TX_AB_M (0x1 << 0) +#define SUN4I_MAC_TX_AB_M BIT(0) /* 0: CPU 1: DMA(default) */ -#define EMAC_TX_TM (0x1 << 1) +#define SUN4I_MAC_TX_TM BIT(1)
-#define EMAC_TX_SETUP (0) +#define SUN4I_MAC_TX_SETUP (0)
/* 0: DRQ asserted 1: DRQ automatically(default) */ -#define EMAC_RX_DRQ_MODE (0x1 << 1) +#define SUN4I_MAC_RX_DRQ_MODE BIT(1) /* 0: CPU 1: DMA(default) */ -#define EMAC_RX_TM (0x1 << 2) +#define SUN4I_MAC_RX_TM BIT(2) /* 0: Normal(default) 1: Pass all Frames */ -#define EMAC_RX_PA (0x1 << 4) +#define SUN4I_MAC_RX_PA BIT(4) /* 0: Normal(default) 1: Pass Control Frames */ -#define EMAC_RX_PCF (0x1 << 5) +#define SUN4I_MAC_RX_PCF BIT(5) /* 0: Normal(default) 1: Pass Frames with CRC Error */ -#define EMAC_RX_PCRCE (0x1 << 6) +#define SUN4I_MAC_RX_PCRCE BIT(6) /* 0: Normal(default) 1: Pass Frames with Length Error */ -#define EMAC_RX_PLE (0x1 << 7) +#define SUN4I_MAC_RX_PLE BIT(7) /* 0: Normal 1: Pass Frames length out of range(default) */ -#define EMAC_RX_POR (0x1 << 8) +#define SUN4I_MAC_RX_POR BIT(8) /* 0: Not accept 1: Accept unicast Packets(default) */ -#define EMAC_RX_UCAD (0x1 << 16) +#define SUN4I_MAC_RX_UCAD BIT(16) /* 0: Normal(default) 1: DA Filtering */ -#define EMAC_RX_DAF (0x1 << 17) +#define SUN4I_MAC_RX_DAF BIT(17) /* 0: Not accept 1: Accept multicast Packets(default) */ -#define EMAC_RX_MCO (0x1 << 20) +#define SUN4I_MAC_RX_MCO BIT(20) /* 0: Disable(default) 1: Enable Hash filter */ -#define EMAC_RX_MHF (0x1 << 21) +#define SUN4I_MAC_RX_MHF BIT(21) /* 0: Not accept 1: Accept Broadcast Packets(default) */ -#define EMAC_RX_BCO (0x1 << 22) +#define SUN4I_MAC_RX_BCO BIT(22) /* 0: Disable(default) 1: Enable SA Filtering */ -#define EMAC_RX_SAF (0x1 << 24) +#define SUN4I_MAC_RX_SAF BIT(24) /* 0: Normal(default) 1: Inverse Filtering */ -#define EMAC_RX_SAIF (0x1 << 25) +#define SUN4I_MAC_RX_SAIF BIT(25)
-#define EMAC_RX_SETUP (EMAC_RX_POR | EMAC_RX_UCAD | EMAC_RX_DAF | \ - EMAC_RX_MCO | EMAC_RX_BCO) +#define SUN4I_MAC_RX_SETUP (SUN4I_MAC_RX_POR | SUN4I_MAC_RX_UCAD | \ + SUN4I_MAC_RX_DAF | SUN4I_MAC_RX_MCO | \ + SUN4I_MAC_RX_BCO)
/* 0: Disable 1: Enable Receive Flow Control(default) */ -#define EMAC_MAC_CTL0_RFC (0x1 << 2) +#define SUN4I_MAC_MAC_CTL0_RFC BIT(2) /* 0: Disable 1: Enable Transmit Flow Control(default) */ -#define EMAC_MAC_CTL0_TFC (0x1 << 3) +#define SUN4I_MAC_MAC_CTL0_TFC BIT(3)
-#define EMAC_MAC_CTL0_SETUP (EMAC_MAC_CTL0_RFC | EMAC_MAC_CTL0_TFC) +#define SUN4I_MAC_MAC_CTL0_SETUP (SUN4I_MAC_MAC_CTL0_RFC | \ + SUN4I_MAC_MAC_CTL0_TFC)
/* 0: Disable 1: Enable MAC Frame Length Checking(default) */ -#define EMAC_MAC_CTL1_FLC (0x1 << 1) +#define SUN4I_MAC_MAC_CTL1_FLC BIT(1) /* 0: Disable(default) 1: Enable Huge Frame */ -#define EMAC_MAC_CTL1_HF (0x1 << 2) +#define SUN4I_MAC_MAC_CTL1_HF BIT(2) /* 0: Disable(default) 1: Enable MAC Delayed CRC */ -#define EMAC_MAC_CTL1_DCRC (0x1 << 3) +#define SUN4I_MAC_MAC_CTL1_DCRC BIT(3) /* 0: Disable 1: Enable MAC CRC(default) */ -#define EMAC_MAC_CTL1_CRC (0x1 << 4) +#define SUN4I_MAC_MAC_CTL1_CRC BIT(4) /* 0: Disable 1: Enable MAC PAD Short frames(default) */ -#define EMAC_MAC_CTL1_PC (0x1 << 5) +#define SUN4I_MAC_MAC_CTL1_PC BIT(5) /* 0: Disable(default) 1: Enable MAC PAD Short frames and append CRC */ -#define EMAC_MAC_CTL1_VC (0x1 << 6) +#define SUN4I_MAC_MAC_CTL1_VC BIT(6) /* 0: Disable(default) 1: Enable MAC auto detect Short frames */ -#define EMAC_MAC_CTL1_ADP (0x1 << 7) +#define SUN4I_MAC_MAC_CTL1_ADP BIT(7) /* 0: Disable(default) 1: Enable */ -#define EMAC_MAC_CTL1_PRE (0x1 << 8) +#define SUN4I_MAC_MAC_CTL1_PRE BIT(8) /* 0: Disable(default) 1: Enable */ -#define EMAC_MAC_CTL1_LPE (0x1 << 9) +#define SUN4I_MAC_MAC_CTL1_LPE BIT(9) /* 0: Disable(default) 1: Enable no back off */ -#define EMAC_MAC_CTL1_NB (0x1 << 12) +#define SUN4I_MAC_MAC_CTL1_NB BIT(12) /* 0: Disable(default) 1: Enable */ -#define EMAC_MAC_CTL1_BNB (0x1 << 13) +#define SUN4I_MAC_MAC_CTL1_BNB BIT(13) /* 0: Disable(default) 1: Enable */ -#define EMAC_MAC_CTL1_ED (0x1 << 14) +#define SUN4I_MAC_MAC_CTL1_ED BIT(14)
-#define EMAC_MAC_CTL1_SETUP (EMAC_MAC_CTL1_FLC | EMAC_MAC_CTL1_CRC | \ - EMAC_MAC_CTL1_PC) +#define SUN4I_MAC_MAC_CTL1_SETUP (SUN4I_MAC_MAC_CTL1_FLC | \ + SUN4I_MAC_MAC_CTL1_CRC | \ + SUN4I_MAC_MAC_CTL1_PC)
-#define EMAC_MAC_IPGT 0x15 +#define SUN4I_MAC_MAC_IPGT 0x15
-#define EMAC_MAC_NBTB_IPG1 0xc -#define EMAC_MAC_NBTB_IPG2 0x12 +#define SUN4I_MAC_MAC_NBTB_IPG1 0xc +#define SUN4I_MAC_MAC_NBTB_IPG2 0x12
-#define EMAC_MAC_CW 0x37 -#define EMAC_MAC_RM 0xf +#define SUN4I_MAC_MAC_CW 0x37 +#define SUN4I_MAC_MAC_RM 0xf
-#define EMAC_MAC_MFL 0x0600 +#define SUN4I_MAC_MAC_MFL 0x0600
/* Receive status */ -#define EMAC_CRCERR (0x1 << 4) -#define EMAC_LENERR (0x3 << 5) +#define SUN4I_MAC_CRCERR BIT(4) +#define SUN4I_MAC_LENERR (0x3 << 5)
-#define EMAC_RX_BUFSIZE 2000 +#define SUN4I_MAC_RX_BUFSIZE 2000
-struct emac_eth_dev { - struct emac_regs *regs; +struct sun4i_mac_eth_dev { + struct sun4i_mac_regs *regs; struct mii_dev *bus; struct phy_device *phydev; int link_printed; #ifdef CONFIG_DM_ETH - uchar rx_buf[EMAC_RX_BUFSIZE]; + uchar rx_buf[SUN4I_MAC_RX_BUFSIZE]; #endif };
-struct emac_rxhdr { +struct sun4i_mac_rxhdr { s16 rx_len; u16 rx_status; };
-static void emac_inblk_32bit(void *reg, void *data, int count) +static void sun4i_mac_inblk_32bit(void *reg, void *data, int count) { int cnt = (count + 3) >> 2;
@@ -185,7 +189,7 @@ static void emac_inblk_32bit(void *reg, void *data, int count) } }
-static void emac_outblk_32bit(void *reg, void *data, int count) +static void sun4i_mac_outblk_32bit(void *reg, void *data, int count) { int cnt = (count + 3) >> 2;
@@ -199,10 +203,10 @@ static void emac_outblk_32bit(void *reg, void *data, int count) }
/* Read a word from phyxcer */ -static int emac_mdio_read(struct mii_dev *bus, int addr, int devad, int reg) +static int sun4i_mac_mdio_read(struct mii_dev *bus, int addr, int devad, int reg) { - struct emac_eth_dev *priv = bus->priv; - struct emac_regs *regs = priv->regs; + struct sun4i_mac_eth_dev *priv = bus->priv; + struct sun4i_mac_regs *regs = priv->regs;
/* issue the phy address and reg */ writel(addr << 8 | reg, ®s->mac_madr); @@ -221,11 +225,11 @@ static int emac_mdio_read(struct mii_dev *bus, int addr, int devad, int reg) }
/* Write a word to phyxcer */ -static int emac_mdio_write(struct mii_dev *bus, int addr, int devad, int reg, +static int sun4i_mac_mdio_write(struct mii_dev *bus, int addr, int devad, int reg, u16 value) { - struct emac_eth_dev *priv = bus->priv; - struct emac_regs *regs = priv->regs; + struct sun4i_mac_eth_dev *priv = bus->priv; + struct sun4i_mac_regs *regs = priv->regs;
/* issue the phy address and reg */ writel(addr << 8 | reg, ®s->mac_madr); @@ -245,7 +249,7 @@ static int emac_mdio_write(struct mii_dev *bus, int addr, int devad, int reg, return 0; }
-static int sunxi_emac_init_phy(struct emac_eth_dev *priv, void *dev) +static int sun4i_mac_init_phy(struct sun4i_mac_eth_dev *priv, void *dev) { int ret, mask = 0xffffffff;
@@ -259,10 +263,10 @@ static int sunxi_emac_init_phy(struct emac_eth_dev *priv, void *dev) return -ENOMEM; }
- priv->bus->read = emac_mdio_read; - priv->bus->write = emac_mdio_write; + priv->bus->read = sun4i_mac_mdio_read; + priv->bus->write = sun4i_mac_mdio_write; priv->bus->priv = priv; - strcpy(priv->bus->name, "emac"); + strcpy(priv->bus->name, "sun4i-mac");
ret = mdio_register(priv->bus); if (ret) @@ -279,43 +283,43 @@ static int sunxi_emac_init_phy(struct emac_eth_dev *priv, void *dev) return 0; }
-static void emac_setup(struct emac_eth_dev *priv) +static void sun4i_mac_setup(struct sun4i_mac_eth_dev *priv) { - struct emac_regs *regs = priv->regs; + struct sun4i_mac_regs *regs = priv->regs; u32 reg_val;
/* Set up TX */ - writel(EMAC_TX_SETUP, ®s->tx_mode); + writel(SUN4I_MAC_TX_SETUP, ®s->tx_mode);
/* Set up RX */ - writel(EMAC_RX_SETUP, ®s->rx_ctl); + writel(SUN4I_MAC_RX_SETUP, ®s->rx_ctl);
/* Set MAC */ /* Set MAC CTL0 */ - writel(EMAC_MAC_CTL0_SETUP, ®s->mac_ctl0); + writel(SUN4I_MAC_MAC_CTL0_SETUP, ®s->mac_ctl0);
/* Set MAC CTL1 */ reg_val = 0; if (priv->phydev->duplex == DUPLEX_FULL) reg_val = (0x1 << 0); - writel(EMAC_MAC_CTL1_SETUP | reg_val, ®s->mac_ctl1); + writel(SUN4I_MAC_MAC_CTL1_SETUP | reg_val, ®s->mac_ctl1);
/* Set up IPGT */ - writel(EMAC_MAC_IPGT, ®s->mac_ipgt); + writel(SUN4I_MAC_MAC_IPGT, ®s->mac_ipgt);
/* Set up IPGR */ - writel(EMAC_MAC_NBTB_IPG2 | (EMAC_MAC_NBTB_IPG1 << 8), ®s->mac_ipgr); + writel(SUN4I_MAC_MAC_NBTB_IPG2 | (SUN4I_MAC_MAC_NBTB_IPG1 << 8), ®s->mac_ipgr);
/* Set up Collison window */ - writel(EMAC_MAC_RM | (EMAC_MAC_CW << 8), ®s->mac_clrt); + writel(SUN4I_MAC_MAC_RM | (SUN4I_MAC_MAC_CW << 8), ®s->mac_clrt);
/* Set up Max Frame Length */ - writel(EMAC_MAC_MFL, ®s->mac_maxf); + writel(SUN4I_MAC_MAC_MFL, ®s->mac_maxf); }
-static void emac_reset(struct emac_eth_dev *priv) +static void sun4i_mac_reset(struct sun4i_mac_eth_dev *priv) { - struct emac_regs *regs = priv->regs; + struct sun4i_mac_regs *regs = priv->regs;
debug("resetting device\n");
@@ -327,9 +331,9 @@ static void emac_reset(struct emac_eth_dev *priv) udelay(200); }
-static int _sunxi_write_hwaddr(struct emac_eth_dev *priv, u8 *enetaddr) +static int _sun4i_write_hwaddr(struct sun4i_mac_eth_dev *priv, u8 *enetaddr) { - struct emac_regs *regs = priv->regs; + struct sun4i_mac_regs *regs = priv->regs; u32 enetaddr_lo, enetaddr_hi;
enetaddr_lo = enetaddr[2] | (enetaddr[1] << 8) | (enetaddr[0] << 16); @@ -341,9 +345,9 @@ static int _sunxi_write_hwaddr(struct emac_eth_dev *priv, u8 *enetaddr) return 0; }
-static int _sunxi_emac_eth_init(struct emac_eth_dev *priv, u8 *enetaddr) +static int _sun4i_mac_eth_init(struct sun4i_mac_eth_dev *priv, u8 *enetaddr) { - struct emac_regs *regs = priv->regs; + struct sun4i_mac_regs *regs = priv->regs; int ret;
/* Init EMAC */ @@ -362,13 +366,13 @@ static int _sunxi_emac_eth_init(struct emac_eth_dev *priv, u8 *enetaddr) udelay(1);
/* Set up EMAC */ - emac_setup(priv); + sun4i_mac_setup(priv);
- _sunxi_write_hwaddr(priv, enetaddr); + _sun4i_write_hwaddr(priv, enetaddr);
mdelay(1);
- emac_reset(priv); + sun4i_mac_reset(priv);
/* PHY POWER UP */ ret = phy_startup(priv->phydev); @@ -404,10 +408,10 @@ static int _sunxi_emac_eth_init(struct emac_eth_dev *priv, u8 *enetaddr) return 0; }
-static int _sunxi_emac_eth_recv(struct emac_eth_dev *priv, void *packet) +static int _sun4i_mac_eth_recv(struct sun4i_mac_eth_dev *priv, void *packet) { - struct emac_regs *regs = priv->regs; - struct emac_rxhdr rxhdr; + struct sun4i_mac_regs *regs = priv->regs; + struct sun4i_mac_rxhdr rxhdr; u32 rxcount; u32 reg_val; int rx_len; @@ -448,7 +452,7 @@ static int _sunxi_emac_eth_recv(struct emac_eth_dev *priv, void *packet) */ good_packet = 1;
- emac_inblk_32bit(®s->rx_io_data, &rxhdr, sizeof(rxhdr)); + sun4i_mac_inblk_32bit(®s->rx_io_data, &rxhdr, sizeof(rxhdr));
rx_len = rxhdr.rx_len; rx_status = rxhdr.rx_status; @@ -460,37 +464,37 @@ static int _sunxi_emac_eth_recv(struct emac_eth_dev *priv, void *packet) }
/* rx_status is identical to RSR register. */ - if (0 & rx_status & (EMAC_CRCERR | EMAC_LENERR)) { + if (0 & rx_status & (SUN4I_MAC_CRCERR | SUN4I_MAC_LENERR)) { good_packet = 0; - if (rx_status & EMAC_CRCERR) + if (rx_status & SUN4I_MAC_CRCERR) printf("crc error\n"); - if (rx_status & EMAC_LENERR) + if (rx_status & SUN4I_MAC_LENERR) printf("length error\n"); }
/* Move data from EMAC */ if (good_packet) { - if (rx_len > EMAC_RX_BUFSIZE) { + if (rx_len > SUN4I_MAC_RX_BUFSIZE) { printf("Received packet is too big (len=%d)\n", rx_len); return -EMSGSIZE; } - emac_inblk_32bit((void *)®s->rx_io_data, packet, rx_len); + sun4i_mac_inblk_32bit((void *)®s->rx_io_data, packet, rx_len); return rx_len; }
return -EIO; /* Bad packet */ }
-static int _sunxi_emac_eth_send(struct emac_eth_dev *priv, void *packet, +static int _sun4i_mac_eth_send(struct sun4i_mac_eth_dev *priv, void *packet, int len) { - struct emac_regs *regs = priv->regs; + struct sun4i_mac_regs *regs = priv->regs;
/* Select channel 0 */ writel(0, ®s->tx_ins);
/* Write packet */ - emac_outblk_32bit((void *)®s->tx_io_data, packet, len); + sun4i_mac_outblk_32bit((void *)®s->tx_io_data, packet, len);
/* Set TX len */ writel(len, ®s->tx_pl0); @@ -501,13 +505,13 @@ static int _sunxi_emac_eth_send(struct emac_eth_dev *priv, void *packet, return 0; }
-static void sunxi_emac_board_setup(struct emac_eth_dev *priv) +static void sun4i_mac_board_setup(struct sun4i_mac_eth_dev *priv) { struct sunxi_ccm_reg *const ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; struct sunxi_sramc_regs *sram = (struct sunxi_sramc_regs *)SUNXI_SRAMC_BASE; - struct emac_regs *regs = priv->regs; + struct sun4i_mac_regs *regs = priv->regs; int pin;
/* Map SRAM to EMAC */ @@ -524,67 +528,67 @@ static void sunxi_emac_board_setup(struct emac_eth_dev *priv) clrsetbits_le32(®s->mac_mcfg, 0xf << 2, 0xd << 2); }
-static int sunxi_emac_eth_start(struct udevice *dev) +static int sun4i_mac_eth_start(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev);
- return _sunxi_emac_eth_init(dev->priv, pdata->enetaddr); + return _sun4i_mac_eth_init(dev->priv, pdata->enetaddr); }
-static int sunxi_emac_eth_send(struct udevice *dev, void *packet, int length) +static int sun4i_mac_eth_send(struct udevice *dev, void *packet, int length) { - struct emac_eth_dev *priv = dev_get_priv(dev); + struct sun4i_mac_eth_dev *priv = dev_get_priv(dev);
- return _sunxi_emac_eth_send(priv, packet, length); + return _sun4i_mac_eth_send(priv, packet, length); }
-static int sunxi_emac_eth_recv(struct udevice *dev, int flags, uchar **packetp) +static int sun4i_mac_eth_recv(struct udevice *dev, int flags, uchar **packetp) { - struct emac_eth_dev *priv = dev_get_priv(dev); + struct sun4i_mac_eth_dev *priv = dev_get_priv(dev); int rx_len;
- rx_len = _sunxi_emac_eth_recv(priv, priv->rx_buf); + rx_len = _sun4i_mac_eth_recv(priv, priv->rx_buf); *packetp = priv->rx_buf;
return rx_len; }
-static void sunxi_emac_eth_stop(struct udevice *dev) +static void sun4i_mac_eth_stop(struct udevice *dev) { /* Nothing to do here */ }
-static int sunxi_emac_eth_probe(struct udevice *dev) +static int sun4i_mac_eth_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev); - struct emac_eth_dev *priv = dev_get_priv(dev); + struct sun4i_mac_eth_dev *priv = dev_get_priv(dev);
- priv->regs = (struct emac_regs *)pdata->iobase; - sunxi_emac_board_setup(priv); + priv->regs = (struct sun4i_mac_regs *)pdata->iobase; + sun4i_mac_board_setup(priv);
- return sunxi_emac_init_phy(priv, dev); + return sun4i_mac_init_phy(priv, dev); }
-static int sunxi_emac_eth_write_hwaddr(struct udevice *dev) +static int sun4i_mac_eth_write_hwaddr(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev); - struct emac_eth_dev *priv = dev_get_priv(dev); + struct sun4i_mac_eth_dev *priv = dev_get_priv(dev);
if (!pdata) return -ENOSYS;
- return _sunxi_write_hwaddr(priv, pdata->enetaddr); + return _sun4i_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 const struct eth_ops sun4i_mac_eth_ops = { + .start = sun4i_mac_eth_start, + .send = sun4i_mac_eth_send, + .recv = sun4i_mac_eth_recv, + .stop = sun4i_mac_eth_stop, + .write_hwaddr = sun4i_mac_eth_write_hwaddr, };
-static int sunxi_emac_eth_ofdata_to_platdata(struct udevice *dev) +static int sun4i_mac_eth_ofdata_to_platdata(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev);
@@ -593,18 +597,18 @@ static int sunxi_emac_eth_ofdata_to_platdata(struct udevice *dev) return 0; }
-static const struct udevice_id sunxi_emac_eth_ids[] = { +static const struct udevice_id sun4i_mac_eth_ids[] = { { .compatible = "allwinner,sun4i-a10-emac" }, { } };
-U_BOOT_DRIVER(eth_sunxi_emac) = { - .name = "eth_sunxi_emac", +U_BOOT_DRIVER(eth_sun4i_mac) = { + .name = "eth_sun4i_mac", .id = UCLASS_ETH, - .of_match = sunxi_emac_eth_ids, - .ofdata_to_platdata = sunxi_emac_eth_ofdata_to_platdata, - .probe = sunxi_emac_eth_probe, - .ops = &sunxi_emac_eth_ops, - .priv_auto_alloc_size = sizeof(struct emac_eth_dev), + .of_match = sun4i_mac_eth_ids, + .ofdata_to_platdata = sun4i_mac_eth_ofdata_to_platdata, + .probe = sun4i_mac_eth_probe, + .ops = &sun4i_mac_eth_ops, + .priv_auto_alloc_size = sizeof(struct sun4i_mac_eth_dev), .platdata_auto_alloc_size = sizeof(struct eth_pdata), };

On Mon, May 15, 2017 at 10:02:36AM +0200, Olliver Schinagl wrote:
The sunxi_emac driver is very specific to the IP used in the sun4i. Thus rename it to what it actually is, the MAC driver for the sun4i MAC.
The rename also changes the variable and function names inside the driver. There are no code changes in this patch however.
While here, use the BIT() macro for bitfields as well.
This should be in a separate patch.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
drivers/net/Makefile | 2 +- drivers/net/{sunxi_emac.c => sun4i_mac.c} | 260 +++++++++++++++---------------
The IP is called EMAC everywhere, please keep that name.
Maxime

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- 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
diff --git a/drivers/net/sunxi_common.c b/drivers/net/sunxi_common.c new file mode 100644 index 0000000000..a22fd2bfe7 --- /dev/null +++ b/drivers/net/sunxi_common.c @@ -0,0 +1,33 @@ +/* + * (c) Copyright 2017 + * Author: Olliver Schinagl oliver@schinagl.nl + * + * SPX-License-Identifier: GPL-3.0+ + * + * Common code for the sunxi series of the ethernet sunxi mac driver + * + */ + +#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_mac_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); +} diff --git a/drivers/net/sunxi_common.h b/drivers/net/sunxi_common.h new file mode 100644 index 0000000000..99ef5e6f25 --- /dev/null +++ b/drivers/net/sunxi_common.h @@ -0,0 +1,13 @@ +/* + * (c) Copyright 2017 + * Author: Olliver Schinagl oliver@schinagl.nl + * + * SPX-License-Identifier: GPL-3.0+ + * + * Common code for the sunxi series of the ethernet sunxi mac drivers + * + */ + +#include <dm/device.h> + +int sunxi_mac_read_rom_hwaddr(struct udevice *dev);

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
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
I actually would like you to add this file to the Makefile in this change.
create mode 100644 drivers/net/sunxi_common.h
Nacked-by: Joe Hershberger joe.hershberger@ni.com
Thanks, -Joe

With this patch sun4i_mac can now get the MAC address from the board in a predetermined board specific manner.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/Makefile | 2 +- drivers/net/sun4i_mac.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 9834d67146..594f54f714 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -22,7 +22,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_SUN4I_EMAC) += sun4i_mac.o +obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_EP93XX) += ep93xx_eth.o diff --git a/drivers/net/sun4i_mac.c b/drivers/net/sun4i_mac.c index ea52bd8a17..06d7e63efc 100644 --- a/drivers/net/sun4i_mac.c +++ b/drivers/net/sun4i_mac.c @@ -17,6 +17,8 @@ #include <asm/arch/clock.h> #include <asm/arch/gpio.h>
+#include "sunxi_common.h" + /* EMAC register */ struct sun4i_mac_regs { u32 ctl; /* 0x00 */ @@ -586,6 +588,7 @@ static const struct eth_ops sun4i_mac_eth_ops = { .recv = sun4i_mac_eth_recv, .stop = sun4i_mac_eth_stop, .write_hwaddr = sun4i_mac_eth_write_hwaddr, + .read_rom_hwaddr = sunxi_mac_read_rom_hwaddr, };
static int sun4i_mac_eth_ofdata_to_platdata(struct udevice *dev)

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
With this patch sun4i_mac can now get the MAC address from the board in a predetermined board specific manner.
I think this patch should be squashed into to one before it.
Thanks, -Joe

This patch removes the old sunxi_gmac glue layer and turns it into a proper sub-class driver.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- 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/sun7i_mac.c | 52 +++++++++++++++++++++++---- 5 files changed, 47 insertions(+), 9 deletions(-) rename board/sunxi/gmac.c => drivers/net/sun7i_mac.c (69%)
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c index 65b1ebd837..728da01a49 100644 --- a/arch/arm/mach-sunxi/board.c +++ b/arch/arm/mach-sunxi/board.c @@ -207,7 +207,6 @@ void s_init(void) #ifndef CONFIG_DM_I2C i2c_init_board(); #endif - eth_init_board(); }
#ifdef CONFIG_SPL_BUILD diff --git a/board/sunxi/Makefile b/board/sunxi/Makefile index b4768b9b9b..f2dba9532a 100644 --- a/board/sunxi/Makefile +++ b/board/sunxi/Makefile @@ -9,7 +9,6 @@ # SPDX-License-Identifier: GPL-2.0+ # obj-y += board.o -obj-$(CONFIG_SUN7I_MAC) += gmac.o obj-$(CONFIG_SUNXI_AHCI) += ahci.o obj-$(CONFIG_MACH_SUN4I) += dram_sun4i_auto.o obj-$(CONFIG_MACH_SUN5I) += dram_sun5i_auto.o diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 594f54f714..86dee7d746 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -23,6 +23,7 @@ obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o +obj-$(CONFIG_SUN7I_MAC) += sun7i_mac.o obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_EP93XX) += ep93xx_eth.o diff --git a/drivers/net/designware.c b/drivers/net/designware.c index f9fb8e0886..3e18f28232 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -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" }, diff --git a/board/sunxi/gmac.c b/drivers/net/sun7i_mac.c similarity index 69% rename from board/sunxi/gmac.c rename to drivers/net/sun7i_mac.c index 69eb8ff2d9..f8c6a58c08 100644 --- a/board/sunxi/gmac.c +++ b/drivers/net/sun7i_mac.c @@ -1,12 +1,24 @@ -#include <common.h> -#include <netdev.h> -#include <miiphy.h> -#include <asm/gpio.h> -#include <asm/io.h> +/* + * (C) Copyright 2016 Olliver Schinagl oliver@schinagl.nl + * + * SPDX-License-Identifier: GPL-2.0+ + * + * Allwinner GMAC ethernet IP driver for U-Boot + */ + +#include <asm/arch/cpu.h> #include <asm/arch/clock.h> #include <asm/arch/gpio.h> +#include <asm/io.h> +#include <common.h> +#include <dm.h> +#include <net.h> + +#include "designware.h"
-void eth_init_board(void) +DECLARE_GLOBAL_DATA_PTR; + +static int sun7i_mac_eth_probe(struct udevice *dev) { int pin; struct sunxi_ccm_reg *const ccm = @@ -79,4 +91,32 @@ void eth_init_board(void) for (pin = SUNXI_GPA(26); pin <= SUNXI_GPA(27); pin++) sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC); #endif + + return designware_eth_probe(dev); } + +const struct eth_ops sun7i_mac_eth_ops = { + .start = designware_eth_start, + .send = designware_eth_send, + .recv = designware_eth_recv, + .free_pkt = designware_eth_free_pkt, + .stop = designware_eth_stop, + .write_hwaddr = designware_eth_write_hwaddr, +}; + +static const struct udevice_id sun7i_mac_eth_ids[] = { + { .compatible = "allwinner,sun7i-a20-gmac" }, + { /* sentinel */ }, +}; + +U_BOOT_DRIVER(eth_sun7i_mac) = { + .name = "sun7i-mac", + .id = UCLASS_ETH, + .of_match = sun7i_mac_eth_ids, + .ofdata_to_platdata = designware_eth_ofdata_to_platdata, + .probe = sun7i_mac_eth_probe, + .ops = &sun7i_mac_eth_ops, + .priv_auto_alloc_size = sizeof(struct dw_eth_dev), + .platdata_auto_alloc_size = sizeof(struct dw_eth_pdata), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +};

On Mon, May 15, 2017 at 10:02:39AM +0200, Olliver Schinagl wrote:
This patch removes the old sunxi_gmac glue layer and turns it into a proper sub-class driver.
And renames it. Please split that into two patches.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
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/sun7i_mac.c | 52 +++++++++++++++++++++++---- 5 files changed, 47 insertions(+), 9 deletions(-) rename board/sunxi/gmac.c => drivers/net/sun7i_mac.c (69%)
And that block is used GMAC everywhere, please keep that name.
Maxime

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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/designware.c | 2 +- drivers/net/designware.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 3e18f28232..ac8258c8bd 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -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); diff --git a/drivers/net/designware.h b/drivers/net/designware.h index 7992d0ebee..24b64d975c 100644 --- a/drivers/net/designware.h +++ b/drivers/net/designware.h @@ -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

On 15 May 2017 at 02:02, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
drivers/net/designware.c | 2 +- drivers/net/designware.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
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.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

With this patch sun7i_mac can now get the MAC address from the board in a predetermined board specific manner.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/Makefile | 2 +- drivers/net/sun7i_mac.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 86dee7d746..5df5567536 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -23,7 +23,7 @@ obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o -obj-$(CONFIG_SUN7I_MAC) += sun7i_mac.o +obj-$(CONFIG_SUN7I_MAC) += sunxi_common.o sun7i_mac.o obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o obj-$(CONFIG_ENC28J60) += enc28j60.o obj-$(CONFIG_EP93XX) += ep93xx_eth.o diff --git a/drivers/net/sun7i_mac.c b/drivers/net/sun7i_mac.c index f8c6a58c08..b10a6ec03a 100644 --- a/drivers/net/sun7i_mac.c +++ b/drivers/net/sun7i_mac.c @@ -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 sun7i_mac_eth_ops = { .free_pkt = designware_eth_free_pkt, .stop = designware_eth_stop, .write_hwaddr = designware_eth_write_hwaddr, + .read_rom_hwaddr = sunxi_mac_read_rom_hwaddr, };
static const struct udevice_id sun7i_mac_eth_ids[] = {

On Mon, May 15, 2017 at 10:02:41AM +0200, Olliver Schinagl wrote:
With this patch sun7i_mac can now get the MAC address from the board in a predetermined board specific manner.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
drivers/net/Makefile | 2 +- drivers/net/sun7i_mac.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 86dee7d746..5df5567536 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -23,7 +23,7 @@ obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o -obj-$(CONFIG_SUN7I_MAC) += sun7i_mac.o +obj-$(CONFIG_SUN7I_MAC) += sunxi_common.o sun7i_mac.o
Shouldn't that be turned in a Kconfig option selected by both drivers?
Maxime

Hey Maxime,
On 15-05-17 10:22, Maxime Ripard wrote:
On Mon, May 15, 2017 at 10:02:41AM +0200, Olliver Schinagl wrote:
With this patch sun7i_mac can now get the MAC address from the board in a predetermined board specific manner.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
drivers/net/Makefile | 2 +- drivers/net/sun7i_mac.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 86dee7d746..5df5567536 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -23,7 +23,7 @@ obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o -obj-$(CONFIG_SUN7I_MAC) += sun7i_mac.o +obj-$(CONFIG_SUN7I_MAC) += sunxi_common.o sun7i_mac.o
Shouldn't that be turned in a Kconfig option selected by both drivers?
What do you mean? There are some common functions that all of them share, such as reading the MAC address.
Or do you mean we should make the net_op rom_read_hwaddr() a configurable Kconfig?
Olliver
Maxime

On Mon, May 15, 2017 at 02:20:25PM +0200, Olliver Schinagl wrote:
Hey Maxime,
On 15-05-17 10:22, Maxime Ripard wrote:
On Mon, May 15, 2017 at 10:02:41AM +0200, Olliver Schinagl wrote:
With this patch sun7i_mac can now get the MAC address from the board in a predetermined board specific manner.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
drivers/net/Makefile | 2 +- drivers/net/sun7i_mac.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 86dee7d746..5df5567536 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -23,7 +23,7 @@ obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o -obj-$(CONFIG_SUN7I_MAC) += sun7i_mac.o +obj-$(CONFIG_SUN7I_MAC) += sunxi_common.o sun7i_mac.o
Shouldn't that be turned in a Kconfig option selected by both drivers?
What do you mean? There are some common functions that all of them share, such as reading the MAC address.
Or do you mean we should make the net_op rom_read_hwaddr() a configurable Kconfig?
I meant having a KConfig symbol to compile sunxi_common, and then have that symbol selected by the three EMAC/GMAC Kconfig symbol.
Maxime

With this patch sun8i_emac can now get the MAC address from the board in a predetermined board specific manner.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/Makefile | 2 +- drivers/net/sun8i_emac.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 5df5567536..8464062d83 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -24,7 +24,7 @@ obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o obj-$(CONFIG_SUN7I_MAC) += sunxi_common.o sun7i_mac.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 diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c index a3dbe2823b..5093f9c83d 100644 --- a/drivers/net/sun8i_emac.c +++ b/drivers/net/sun8i_emac.c @@ -25,6 +25,8 @@ #include <asm-generic/gpio.h> #endif
+#include "sunxi_common.h" + #define MDIO_CMD_MII_BUSY BIT(0) #define MDIO_CMD_MII_WRITE BIT(1)
@@ -757,6 +759,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_mac_read_rom_hwaddr, .send = sun8i_emac_eth_send, .recv = sun8i_emac_eth_recv, .free_pkt = sun8i_eth_free_pkt,

Fix a few whitespaces errors in the sun8i driver.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- drivers/net/Kconfig | 8 ++++---- drivers/net/sun8i_emac.c | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 782348f872..d9d700ac15 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -227,10 +227,10 @@ config GMAC_TX_DELAY Set the GMAC Transmit Clock Delay Chain value.
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. diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c index 5093f9c83d..84e1d7d208 100644 --- a/drivers/net/sun8i_emac.c +++ b/drivers/net/sun8i_emac.c @@ -757,13 +757,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_mac_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)

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
Fix a few whitespaces errors in the sun8i driver.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

With commit 2681e78a5ee ("configs: Re-sync") we lost the EEPROM settings from the defconfig files. Let us re-add them.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl --- configs/A10-OLinuXino-Lime_defconfig | 3 +++ configs/A20-OLinuXino-Lime2-eMMC_defconfig | 3 +++ configs/A20-OLinuXino-Lime2_defconfig | 3 +++ configs/A20-OLinuXino-Lime_defconfig | 3 +++ configs/A20-OLinuXino_MICRO_defconfig | 3 +++ 5 files changed, 15 insertions(+)
diff --git a/configs/A10-OLinuXino-Lime_defconfig b/configs/A10-OLinuXino-Lime_defconfig index d4513144eb..993f7b81d4 100644 --- a/configs/A10-OLinuXino-Lime_defconfig +++ b/configs/A10-OLinuXino-Lime_defconfig @@ -18,6 +18,9 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_ISO_PARTITION is not set # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN4I_EMAC=y +CONFIG_NET_ETHADDR_EEPROM=y +CONFIG_NET_ETHADDR_EEPROM_I2C=y +CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1 CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-OLinuXino-Lime2-eMMC_defconfig b/configs/A20-OLinuXino-Lime2-eMMC_defconfig index fd743a5f45..ccb7a664d4 100644 --- a/configs/A20-OLinuXino-Lime2-eMMC_defconfig +++ b/configs/A20-OLinuXino-Lime2-eMMC_defconfig @@ -22,6 +22,9 @@ CONFIG_CMD_USB_MASS_STORAGE=y # CONFIG_SPL_PARTITION_UUIDS is not set CONFIG_DFU_RAM=y CONFIG_SUN7I_GMAC=y +CONFIG_NET_ETHADDR_EEPROM=y +CONFIG_NET_ETHADDR_EEPROM_I2C=y +CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1 CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index a932ec7b7b..43337cfc24 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -23,6 +23,9 @@ CONFIG_DFU_RAM=y CONFIG_SUN7I_GMAC=y CONFIG_PHY_REALTEK=y CONFIG_RTL8211X_PHY_FORCE_MASTER=y +CONFIG_NET_ETHADDR_EEPROM=y +CONFIG_NET_ETHADDR_EEPROM_I2C=y +CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1 CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-OLinuXino-Lime_defconfig b/configs/A20-OLinuXino-Lime_defconfig index 41667384f4..802989518b 100644 --- a/configs/A20-OLinuXino-Lime_defconfig +++ b/configs/A20-OLinuXino-Lime_defconfig @@ -17,6 +17,9 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y CONFIG_PHY_REALTEK=y +CONFIG_NET_ETHADDR_EEPROM=y +CONFIG_NET_ETHADDR_EEPROM_I2C=y +CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1 CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y diff --git a/configs/A20-OLinuXino_MICRO_defconfig b/configs/A20-OLinuXino_MICRO_defconfig index b1f80835c9..68e9984ac1 100644 --- a/configs/A20-OLinuXino_MICRO_defconfig +++ b/configs/A20-OLinuXino_MICRO_defconfig @@ -20,6 +20,9 @@ CONFIG_SPL_I2C_SUPPORT=y # CONFIG_SPL_EFI_PARTITION is not set CONFIG_SUN7I_EMAC=y CONFIG_PHY_REALTEK=y +CONFIG_NET_ETHADDR_EEPROM=y +CONFIG_NET_ETHADDR_EEPROM_I2C=y +CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1 CONFIG_AXP_ALDO3_VOLT=2800 CONFIG_AXP_ALDO4_VOLT=2800 CONFIG_USB_EHCI_HCD=y

On Mon, May 15, 2017 at 3:02 AM, Olliver Schinagl oliver@schinagl.nl wrote:
With commit 2681e78a5ee ("configs: Re-sync") we lost the EEPROM settings from the defconfig files. Let us re-add them.
Signed-off-by: Olliver Schinagl oliver@schinagl.nl
Acked-by: Joe Hershberger joe.hershberger@ni.com

Hey all,
On 15-05-17 10:02, Olliver Schinagl wrote:
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 as suggested by Igor Grinberg
- Add EEPROM/Mac commands suggested by York Sun
The series was initially based ontop of Joe's u-boot_net/next branches, but I rebased it ontop of u-boot/master to get the latest sunxi changes, including: sun7i: Add support for Olimex A20-OLinuXino-LIME2-eMMC ARM: dts: sunxi: Change node name for pwrseq pin on Olinuxino-lime2-emmc
Which are on their way to being merged in master. So once those land into master this all should apply cleanly. Sorry Joe!
So I accidentally added those too to this patch series as well (first two patches). Which are technically not part of this series and are on their way as it is. Does patchwork figure out this automatically, or do you prefer a resend with the 2 patches removed?
Olliver
======= Changes since v5:
- Removed changes to eth_legacy as per Simon's request
- Adapted, improved and fixed the emac/gmac Kconfig conversion
- Renamed sunxi_[eg]mac to sun[47]_mac to be more clear and allowing preparing to merge common parts into sunxi_common
- Added a few more MAC helpers
- Added PHY_GIGE as Kconfig symbol
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.
Emmanuel Vadot (1): ARM: dts: sunxi: Change node name for pwrseq pin on Olinuxino-lime2-emmc
Olliver Schinagl (27): sun7i: Add support for Olimex A20-OLinuXino-LIME2-eMMC net: core: Add PHY_GIGE as a Kconfig symbol net: sunxi simplify defconfig net: sunxi: Re-add RTL8211X_PHY_FORCE_MASTER net: sunxi: Restore sunxi_[eg]mac behavior net: sunxi: Move GMAC_TX_DELAY to the driver 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 MAC address helper functions 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 net: core: Check return value of read_rom_hwaddr fdt: fixup_eth: Remove code duplication with a function fdt: fixup_eth: improve error catching/reduce identation arm: sunxi: Expose function to generate sunxi-specific a MAC address net: sunxi_emac: Write HW address via net_ops hook net: sunxi: Rename sunxi_emac to a more specific sun4i_mac net: sunxi: Have sunxi common functions together net: sun4i_mac: Add read_rom_hwaddr hook net: sun7i_mac: Make the sun7i a dw driver subclass net: dw: Expose designware_eth_start net: sun7i_mac: Add read_rom_hwaddr hook net: sun8i_gmac: Add read_rom_hwaddr hook net: sun8i: fix whitespace net: sunxi: Enable eeprom on OLinuXino Lime boards (again)
arch/arm/dts/sun7i-a20-olinuxino-lime2-emmc.dts | 2 +- arch/arm/include/asm/arch-sunxi/sys_proto.h | 4 +- arch/arm/mach-sunxi/Kconfig | 14 +- arch/arm/mach-sunxi/board.c | 1 - board/sunxi/MAINTAINERS | 5 + board/sunxi/Makefile | 1 - board/sunxi/board.c | 146 ++++++++----- common/fdt_support.c | 33 ++- configs/A10-OLinuXino-Lime_defconfig | 4 +- configs/A20-OLinuXino-Lime2-eMMC_defconfig | 36 ++++ configs/A20-OLinuXino-Lime2_defconfig | 8 +- configs/A20-OLinuXino-Lime_defconfig | 8 +- configs/A20-OLinuXino_MICRO_defconfig | 8 +- configs/A20-Olimex-SOM-EVB_defconfig | 4 +- configs/Bananapi_defconfig | 3 +- configs/Bananapro_defconfig | 3 +- configs/CSQ_CS908_defconfig | 4 +- configs/Colombus_defconfig | 3 +- configs/Cubieboard2_defconfig | 4 +- configs/Cubietruck_defconfig | 3 +- configs/Hummingbird_A31_defconfig | 3 +- configs/Itead_Ibox_A20_defconfig | 4 +- configs/Lamobo_R1_defconfig | 3 +- configs/Linksprite_pcDuino3_Nano_defconfig | 3 +- configs/Linksprite_pcDuino3_defconfig | 4 +- configs/Mele_A1000G_quad_defconfig | 4 +- configs/Mele_I7_defconfig | 4 +- configs/Mele_M3_defconfig | 4 +- configs/Mele_M5_defconfig | 4 +- configs/Mele_M9_defconfig | 4 +- configs/Orangepi_defconfig | 3 +- configs/Orangepi_mini_defconfig | 3 +- configs/Sinlinx_SinA31s_defconfig | 4 +- configs/Sinovoip_BPI_M2_defconfig | 3 +- configs/Wits_Pro_A20_DKT_defconfig | 3 +- configs/i12-tvbox_defconfig | 4 +- configs/icnova-a20-swac_defconfig | 4 +- configs/mixtile_loftq_defconfig | 3 +- doc/README.enetaddr | 95 +++++++++ drivers/net/Kconfig | 76 +++++-- drivers/net/Makefile | 5 +- drivers/net/designware.c | 3 +- drivers/net/designware.h | 1 + drivers/net/{sunxi_emac.c => sun4i_mac.c} | 267 +++++++++++++----------- board/sunxi/gmac.c => drivers/net/sun7i_mac.c | 54 ++++- drivers/net/sun8i_emac.c | 15 +- drivers/net/sunxi_common.c | 33 +++ drivers/net/sunxi_common.h | 13 ++ include/configs/sunxi-common.h | 13 +- include/net.h | 76 ++++++- net/Kconfig | 59 ++++++ net/eth-uclass.c | 65 +++--- net/eth_common.c | 53 ++++- net/eth_legacy.c | 4 +- scripts/config_whitelist.txt | 2 - 55 files changed, 842 insertions(+), 350 deletions(-) create mode 100644 configs/A20-OLinuXino-Lime2-eMMC_defconfig rename drivers/net/{sunxi_emac.c => sun4i_mac.c} (59%) rename board/sunxi/gmac.c => drivers/net/sun7i_mac.c (67%) create mode 100644 drivers/net/sunxi_common.c create mode 100644 drivers/net/sunxi_common.h

On Mon, May 15, 2017 at 10:09:02AM +0200, Olliver Schinagl wrote:
Hey all,
On 15-05-17 10:02, Olliver Schinagl wrote:
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 as suggested by Igor Grinberg
- Add EEPROM/Mac commands suggested by York Sun
The series was initially based ontop of Joe's u-boot_net/next branches, but I rebased it ontop of u-boot/master to get the latest sunxi changes, including: sun7i: Add support for Olimex A20-OLinuXino-LIME2-eMMC ARM: dts: sunxi: Change node name for pwrseq pin on Olinuxino-lime2-emmc
Which are on their way to being merged in master. So once those land into master this all should apply cleanly. Sorry Joe!
So I accidentally added those too to this patch series as well (first two patches). Which are technically not part of this series and are on their way as it is. Does patchwork figure out this automatically, or do you prefer a resend with the 2 patches removed?
I've made patchwork reflect things correctly.

On Mon, May 15, 2017 at 6:17 PM, Tom Rini trini@konsulko.com wrote:
On Mon, May 15, 2017 at 10:09:02AM +0200, Olliver Schinagl wrote:
Hey all,
On 15-05-17 10:02, Olliver Schinagl wrote:
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 as suggested by Igor Grinberg
- Add EEPROM/Mac commands suggested by York Sun
The series was initially based ontop of Joe's u-boot_net/next branches, but I rebased it ontop of u-boot/master to get the latest sunxi changes, including: sun7i: Add support for Olimex A20-OLinuXino-LIME2-eMMC ARM: dts: sunxi: Change node name for pwrseq pin on Olinuxino-lime2-emmc
Which are on their way to being merged in master. So once those land into master this all should apply cleanly. Sorry Joe!
So I accidentally added those too to this patch series as well (first two patches). Which are technically not part of this series and are on their way as it is. Does patchwork figure out this automatically, or do you prefer a resend with the 2 patches removed?
I've made patchwork reflect things correctly.
Few of the patches need re-work, so updated patchwork status as "Changes Requested" for the series.
thanks!

Hello,
- Renamed sunxi_[eg]mac to sun[47]_mac to be more clear and allowing preparing to merge common parts into sunxi_common
Wouldn't those better renamed to sun[47]i_mac instead, for consistency ?
participants (8)
-
Jagan Teki
-
Joe Hershberger
-
Jonathan Liu
-
Maxime Ripard
-
Olliver Schinagl
-
Simon Glass
-
Tom Rini
-
Vincent Legoll