From 26d3acdab86a4ade8e9407822d8cdbe51b1f7412 Mon Sep 17 00:00:00 2001 From: Mugunthan V N Date: Thu, 3 Sep 2015 15:50:21 +0530 Subject: net: phy: on phy device create do not initialize link to 1 Currently when phy device is created the link variable is initialized to 1 which denoted phy link is already up. On a power reset there is no issue as phy status register link status will not be set, so phy auto negotiate will be started. But when a cpu reset is issued (ex: dra72x-evm) phy's link status bit is already set which leads to assume that link is already setup in genphy_update_link() initial check which results in ehternet not working. So do not assume that link is already up and on phy device create set link to zero. This is verified on dra72x-evm. Reported-by: Franklin S Cooper Jr Signed-off-by: Mugunthan V N Acked-by: Joe Hershberger diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 65c731a..a6023f1 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -571,7 +571,7 @@ static struct phy_device *phy_device_create(struct mii_dev *bus, int addr, memset(dev, 0, sizeof(*dev)); dev->duplex = -1; - dev->link = 1; + dev->link = 0; dev->interface = interface; dev->autoneg = AUTONEG_ENABLE; -- cgit v0.10.2 From eaa8a195cc2372349276bf7d581a9e1e2cc83511 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Mon, 14 Sep 2015 15:29:43 +0200 Subject: net: expose eth_is_active() function to test network device state The previous eth_device struct returned by eth_get_dev() allowed code to directly query the state member field. However, with CONFIG_DM_ETH this data gets encapsulated (i.e. private), and eth_get_dev() returns a udevice struct 'abstraction' instead. This breaks legacy code relying on the former behaviour - e.g. netconsole. (see http://lists.denx.de/pipermail/u-boot/2015-June/216528.html) The patch introduces a method to retrieve the ethernet device state in a 'clean' and uniform way, supporting both legacy code and driver model. The new function eth_is_active() accepts a device struct pointer and tests it for ETH_STATE_ACTIVE. Signed-off-by: Bernhard Nortmann Reviewed-by: Simon Glass Acked-by: Joe Hershberger diff --git a/include/net.h b/include/net.h index f1671e3..3a787cc 100644 --- a/include/net.h +++ b/include/net.h @@ -149,7 +149,9 @@ struct udevice *eth_get_dev(void); /* get the current device */ */ struct udevice *eth_get_dev_by_name(const char *devname); unsigned char *eth_get_ethaddr(void); /* get the current device MAC */ + /* Used only when NetConsole is enabled */ +int eth_is_active(struct udevice *dev); /* Test device for active state */ int eth_init_state_only(void); /* Set active state */ void eth_halt_state_only(void); /* Set passive state */ #endif @@ -195,6 +197,8 @@ static inline unsigned char *eth_get_ethaddr(void) return NULL; } +/* Used only when NetConsole is enabled */ +int eth_is_active(struct eth_device *dev); /* Test device for active state */ /* Set active state */ static inline __attribute__((always_inline)) int eth_init_state_only(void) { diff --git a/net/eth.c b/net/eth.c index 26520d3..2e24b55 100644 --- a/net/eth.c +++ b/net/eth.c @@ -389,6 +389,17 @@ void eth_halt(void) priv->state = ETH_STATE_PASSIVE; } +int eth_is_active(struct udevice *dev) +{ + struct eth_device_priv *priv; + + if (!dev || !device_active(dev)) + return 0; + + priv = dev_get_uclass_priv(dev); + return priv->state == ETH_STATE_ACTIVE; +} + int eth_send(void *packet, int length) { struct udevice *current; @@ -580,7 +591,7 @@ UCLASS_DRIVER(eth) = { .per_device_auto_alloc_size = sizeof(struct eth_device_priv), .flags = DM_UC_FLAG_SEQ_ALIAS, }; -#endif +#endif /* #ifdef CONFIG_DM_ETH */ #ifndef CONFIG_DM_ETH @@ -918,6 +929,11 @@ void eth_halt(void) eth_current->state = ETH_STATE_PASSIVE; } +int eth_is_active(struct eth_device *dev) +{ + return dev && dev->state == ETH_STATE_ACTIVE; +} + int eth_send(void *packet, int length) { if (!eth_current) -- cgit v0.10.2 From c163e4367908ea625ca962ca6312fc88790b5242 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Mon, 14 Sep 2015 15:29:44 +0200 Subject: net: fix netconsole when CONFIG_DM_ETH is set This patch uses the eth_is_active() function to work around issues that prevented compilation with the newer driver model. Signed-off-by: Bernhard Nortmann Acked-by: Joe Hershberger diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 31042a6..bf972dc 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -170,7 +170,11 @@ int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port, static void nc_send_packet(const char *buf, int len) { +#ifdef CONFIG_DM_ETH + struct udevice *eth; +#else struct eth_device *eth; +#endif int inited = 0; uchar *pkt; uchar *ether; @@ -183,7 +187,7 @@ static void nc_send_packet(const char *buf, int len) return; if (!memcmp(nc_ether, net_null_ethaddr, 6)) { - if (eth->state == ETH_STATE_ACTIVE) + if (eth_is_active(eth)) return; /* inside net loop */ output_packet = buf; output_packet_len = len; @@ -194,7 +198,7 @@ static void nc_send_packet(const char *buf, int len) return; } - if (eth->state != ETH_STATE_ACTIVE) { + if (!eth_is_active(eth)) { if (eth_is_on_demand_init()) { if (eth_init() < 0) return; @@ -292,7 +296,11 @@ static int nc_stdio_getc(struct stdio_dev *dev) static int nc_stdio_tstc(struct stdio_dev *dev) { +#ifdef CONFIG_DM_ETH + struct udevice *eth; +#else struct eth_device *eth; +#endif if (input_recursion) return 0; @@ -301,7 +309,7 @@ static int nc_stdio_tstc(struct stdio_dev *dev) return 1; eth = eth_get_dev(); - if (eth && eth->state == ETH_STATE_ACTIVE) + if (eth_is_active(eth)) return 0; /* inside net loop */ input_recursion = 1; -- cgit v0.10.2 From 4917c061a206b1c220307599bbda84b9bc4d44f2 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Mon, 14 Sep 2015 15:29:45 +0200 Subject: net: avoid eth_unregister() call when function is unavailable CONFIG_NETCONSOLE causes common/bootm.c to call eth_unregister() for network device shutdown. However, with CONFIG_DM_ETH this function is no longer defined. This is a workaround to avoid the call in that case, and solely rely on eth_halt(). In case this is insufficient, a proper way to unregister / remove network devices needs to be implemented. Signed-off-by: Bernhard Nortmann Reviewed-by: Simon Glass Acked-by: Joe Hershberger diff --git a/common/bootm.c b/common/bootm.c index 667c934..c0d0d09 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -474,7 +474,9 @@ ulong bootm_disable_interrupts(void) #ifdef CONFIG_NETCONSOLE /* Stop the ethernet stack if NetConsole could have left it up */ eth_halt(); +# ifndef CONFIG_DM_ETH eth_unregister(eth_get_dev()); +# endif #endif #if defined(CONFIG_CMD_USB) -- cgit v0.10.2 From 266607480973a564f545eab1af5057d752480708 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Mon, 14 Sep 2015 15:29:46 +0200 Subject: net: support NETCONSOLE option via Kconfig This patch introduces CONFIG_NETCONSOLE as an option to the Kconfig system. Joe Hershberger pointed out that it may not be entirely free of problems, as many boards predating the driver model define this symbol directly via include files. In case they're not properly migrated, their NetConsole might 'vanish' if they start to use CONFIG_NET or CONFIG_NETDEVICES. Signed-off-by: Bernhard Nortmann Acked-by: Joe Hershberger diff --git a/net/Kconfig b/net/Kconfig index 915371d..77a2f7e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -16,4 +16,10 @@ config NET_RANDOM_ETHADDR A new MAC address will be generated on every boot and it will not be added to the environment. +config NETCONSOLE + bool "NetConsole support" + help + Support the 'nc' input/output device for networked console. + See README.NetConsole for details. + endif # if NET -- cgit v0.10.2 From 8ac46a98618ea21cf9900961fcff9cf803198271 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Mon, 14 Sep 2015 15:29:47 +0200 Subject: sunxi: add NetConsole by default for Banana Pi/Pro Simon Glass and Joe Hershberger suggested adding at least one test case for the CONFIG_DM_ETH plus CONFIG_NETCONSOLE options. This patch enables NetConsole as a default for the "Banana Pi/Pro" sunxi boards. (By the nature of this patch it could probably be extended later to include all sunxi boards using CONFIG_SUNXI_[EG]MAC.) Signed-off-by: Bernhard Nortmann Acked-by: Joe Hershberger diff --git a/configs/Bananapi_defconfig b/configs/Bananapi_defconfig index 794b727..898631d 100644 --- a/configs/Bananapi_defconfig +++ b/configs/Bananapi_defconfig @@ -11,5 +11,6 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER,SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPH(23),AHC # CONFIG_CMD_IMLS is not set # CONFIG_CMD_FLASH is not set # CONFIG_CMD_FPGA is not set +CONFIG_NETCONSOLE=y CONFIG_ETH_DESIGNWARE=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/Bananapro_defconfig b/configs/Bananapro_defconfig index e56ca71..e9909d9 100644 --- a/configs/Bananapro_defconfig +++ b/configs/Bananapro_defconfig @@ -13,5 +13,6 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER,SUNXI_GMAC,RGMII,MACPWR=SUNXI_GPH(23),AHC # CONFIG_CMD_IMLS is not set # CONFIG_CMD_FLASH is not set # CONFIG_CMD_FPGA is not set +CONFIG_NETCONSOLE=y CONFIG_ETH_DESIGNWARE=y CONFIG_USB_EHCI_HCD=y -- cgit v0.10.2