Skip to contentSkip to conversation

fix NetConsole for CONFIG_DM_ETH

PATCH Superseded Bernhard Nortmann 2 participants 12 messages Aug 26, 2015

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover fix NetConsole for CONFIG_DM_ETH

With the introduction of driver model and accompanying changes, outdated code in netconsole.c leads to compilation errors when both CONFIG_NETCONSOLE and CONFIG_DM_ETH are set.

This is a series of patches to fix these issues and get NetConsole working again with DM_ETH. v2 adds some proper subsystem prefixes on the commit messages, and enables a test case (sunxi board configuration for Banana Pi/Pro) that combines CONFIG_DM_ETH and CONFIG_NETCONSOLE.

I have tested the resulting code on my Banana Pi (sun7i / Allwinner A20) and had a functional NetConsole again. I also backported eth_is_active() and the netconsole.c changes to v2015.04, to make sure they properly worked in case CONFIG_DM_ETH is absent (v2015.04 predates the introduction of DM_ETH, and I'm lacking other hardware to test CONFIG_NETCONSOLE with).

Regards, B. Nortmann

Changes in v2:
- add "net:" prefix to commit message
- add "net:" prefix to commit message
- add "net:" prefix to commit message

Bernhard Nortmann (5):
net: expose eth_is_active() function to test network device state
net: fix netconsole when CONFIG_DM_ETH is set
net: avoid eth_unregister() call when function is unavailable
net: support NETCONSOLE option via Kconfig
sunxi: add NetConsole by default for Banana Pi/Pro

 common/bootm.c              |  2 ++
 configs/Bananapi_defconfig  |  3 ++-
 configs/Bananapro_defconfig |  3 ++-
 drivers/net/netconsole.c    | 14 +++++++++++---
 include/net.h               |  6 ++++++
 net/Kconfig                 |  6 ++++++
 net/eth.c                   | 18 +++++++++++++++++-
 7 files changed, 46 insertions(+), 6 deletions(-)
Signature · 1 line
2.4.6
#1 lore raw

PATCH v2 1/5 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.

---

Changes in v2:
- add "net:" prefix to commit message

 include/net.h |  6 ++++++
 net/eth.c     | 18 +++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
include/net.h +6 -0
index d09bec9..c135ec4 100644
@@ -149,7 +149,13 @@ 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 */
+# ifdef CONFIG_DM_ETH
+int eth_is_active(struct udevice *dev); /* Test device for active state */
+# else
+int eth_is_active(struct eth_device *dev); /* Test device for active state */
+# endif
 int eth_init_state_only(void); /* Set active state */
 void eth_halt_state_only(void); /* Set passive state */
 #endif
net/eth.c +17 -1
index d3ec8d6..d3ff7c6 100644
@@ -386,6 +386,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->uclass_priv;
+	return priv->state == ETH_STATE_ACTIVE;
+}
+
 int eth_send(void *packet, int length)
 {
 	struct udevice *current;
@@ -577,7 +588,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
 
@@ -915,6 +926,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)
Signature · 1 line
2.4.6
#2 lore raw

PATCH v2 1/5 net: expose eth_is_active() function to test network device state

Hi Bernhard,

Quoted 49 lines · Bernhard Nortmann

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.

---

Changes in v2:
- add "net:" prefix to commit message

 include/net.h |  6 ++++++
 net/eth.c     | 18 +++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
include/net.h +6 -0
index d09bec9..c135ec4 100644
@@ -149,7 +149,13 @@ 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 */
+# ifdef CONFIG_DM_ETH
+int eth_is_active(struct udevice *dev); /* Test device for active state */
+# else
+int eth_is_active(struct eth_device *dev); /* Test device for active state */
+# endif
 int eth_init_state_only(void); /* Set active state */
 void eth_halt_state_only(void); /* Set passive state */
 #endif
net/eth.c +0 -0
index d3ec8d6..d3ff7c6 100644
@@ -386,6 +386,17 @@ void eth_halt(void)
        priv->state = ETH_STATE_PASSIVE;

net/eth.c void eth_halt(void) · line 396

Quoted 10 lines
net/eth.c +8 -0
 }
 
+int eth_is_active(struct udevice *dev)
+{
+       struct eth_device_priv *priv;
+
+       if (!dev || !device_active(dev))
+               return 0;
+
+       priv = dev->uclass_priv;

You should use dev_get_uclass_priv();

Quoted 34 lines
net/eth.c +9 -2
+       return priv->state == ETH_STATE_ACTIVE;
+}
+
 int eth_send(void *packet, int length)
 {
        struct udevice *current;
@@ -577,7 +588,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
 
@@ -915,6 +926,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)
--

2.4.6

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

#3 lore raw

PATCH v3 1/5 net: expose eth_is_active() function to test network device state

In reply to Bernhard Nortmann

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.

Series-changes: 3
- use dev_get_uclass_priv()

---
 include/net.h |  6 ++++++
 net/eth.c     | 18 +++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
include/net.h +6 -0
index d09bec9..c135ec4 100644
@@ -149,7 +149,13 @@ 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 */
+# ifdef CONFIG_DM_ETH
+int eth_is_active(struct udevice *dev); /* Test device for active state */
+# else
+int eth_is_active(struct eth_device *dev); /* Test device for active state */
+# endif
 int eth_init_state_only(void); /* Set active state */
 void eth_halt_state_only(void); /* Set passive state */
 #endif
net/eth.c +17 -1
index d3ec8d6..39b9918 100644
@@ -386,6 +386,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;
@@ -577,7 +588,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
 
@@ -915,6 +926,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)
Signature · 1 line
2.4.6
#4 lore raw

PATCH v2 2/5 net: fix netconsole when CONFIG_DM_ETH is set

In reply to Bernhard Nortmann

This patches uses the eth_is_active() function to work around issues that prevented compilation with the newer driver model.

---

Changes in v2:
- add "net:" prefix to commit message

 drivers/net/netconsole.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/net/netconsole.c +11 -3
index 31042a6..bf972dc 100644
@@ -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;
Signature · 1 line
2.4.6
#6 lore raw

PATCH v2 3/5 net: avoid eth_unregister() call when function is unavailable

In reply to Bernhard Nortmann

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.

---

Changes in v2:
- add "net:" prefix to commit message

 common/bootm.c | 2 ++
 1 file changed, 2 insertions(+)
common/bootm.c +2 -0
index 667c934..c0d0d09 100644
@@ -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)
Signature · 1 line
2.4.6
#7 lore raw

PATCH v2 3/5 net: avoid eth_unregister() call when function is unavailable

Quoted 10 lines · Bernhard Nortmann

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.

#8 lore raw

PATCH v2 4/5 net: support NETCONSOLE option via Kconfig

In reply to Bernhard Nortmann

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.

---

Changes in v2: None

 net/Kconfig | 6 ++++++
 1 file changed, 6 insertions(+)
net/Kconfig +6 -0
index 915371d..77a2f7e 100644
@@ -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
Signature · 1 line
2.4.6
#9 lore raw

PATCH v2 4/5 net: support NETCONSOLE option via Kconfig

Quoted 10 lines · Bernhard Nortmann

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.

Do you plan to use moveconfig.pl to update other boards?

I guess that can wait until next release.

-Joe

#10 lore raw

PATCH v2 5/5 sunxi: add NetConsole by default for Banana Pi/Pro

In reply to Bernhard Nortmann

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.)

---

Changes in v2: None

 configs/Bananapi_defconfig  | 3 ++-
 configs/Bananapro_defconfig | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
configs/Bananapi_defconfig +2 -1
index 560295f..898631d 100644
@@ -2,8 +2,8 @@ CONFIG_ARM=y
 CONFIG_ARCH_SUNXI=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_GMAC_TX_DELAY=3
 CONFIG_VIDEO_COMPOSITE=y
+CONFIG_GMAC_TX_DELAY=3
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL=y
@@ -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
configs/Bananapro_defconfig +2 -1
index 346db34..e9909d9 100644
@@ -4,8 +4,8 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
 CONFIG_USB1_VBUS_PIN="PH0"
 CONFIG_USB2_VBUS_PIN="PH1"
-CONFIG_GMAC_TX_DELAY=3
 CONFIG_VIDEO_COMPOSITE=y
+CONFIG_GMAC_TX_DELAY=3
 CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapro"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL=y
@@ -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
Signature · 1 line
2.4.6
#11 lore raw

PATCH v2 5/5 sunxi: add NetConsole by default for Banana Pi/Pro

Quoted 10 lines · Bernhard Nortmann

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.)