diff mbox

[U-Boot,RESEND,v3,1/5] net: expose eth_is_active() function to test network device state

Message ID 1442237387-29474-2-git-send-email-bernhard.nortmann@web.de
State Accepted
Delegated to: Joe Hershberger
Headers show

Commit Message

Bernhard Nortmann Sept. 14, 2015, 1:29 p.m. UTC
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 <bernhard.nortmann@web.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- use dev_get_uclass_priv()

Changes in v2: None

 include/net.h |  6 ++++++
 net/eth.c     | 18 +++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

Comments

Joe Hershberger Sept. 14, 2015, 9:26 p.m. UTC | #1
Hi Bernhard,

On Mon, Sep 14, 2015 at 8:29 AM, Bernhard Nortmann
<bernhard.nortmann@web.de> wrote:
> 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 <bernhard.nortmann@web.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger Sept. 30, 2015, 5:22 p.m. UTC | #2
On Mon, Sep 14, 2015 at 8:29 AM, Bernhard Nortmann
<bernhard.nortmann@web.de> wrote:
> 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 <bernhard.nortmann@web.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>

This patch adds warnings to the following boards (all non-DM boards
with NetConsole enabled):

+(tcm-bf537,cm-bf527,bf609-ezkit,bf537-stamp,bf527-ezkit-v2,tcm-bf518,cm-bf537u,cm-bf537e,bf527-ezkit,pr1,bct-brettl2,bf537-minotaur,bf537-srv1,bf518f-ezbrd,bf526-ezbrd,br4)
../drivers/net/netconsole.c: In function ânc_send_packetâ:
+(tcm-bf537,cm-bf527,bf609-ezkit,bf537-stamp,bf527-ezkit-v2,tcm-bf518,cm-bf537u,cm-bf537e,bf527-ezkit,pr1,bct-brettl2,bf537-minotaur,bf537-srv1,bf518f-ezbrd,bf526-ezbrd,br4)
../drivers/net/netconsole.c:190: warning: implicit declaration of
function âeth_is_activeâ
w+(tseries_spi,nitrogen6dl2g,guruplug,digsy_mtc_rev5,netspace_mini_v2,yosemite,taihu,tseries_nand,neo,goflexhome,nitrogen6s,nitrogen6q,acadia,lschlv2,TQM850L,digsy_mtc_RAMBOOT,ebony,devconcenter,a4m2k,iconnect,xfi3,novena,sequoia,io64,arches,nitrogen6dl,ib62x0,km_kirkwood_128m16,netspace_lite_v2,TQM860L,sansa_fuze_plus,digsy_mtc_rev5_RAMBOOT,TQM860M,mgcoge3un,kmnusa,O2MNT,nitrogen6q2g,sheevaplug,t3corp,netspace_max_v2,TQM850M,redwood,microblaze-generic,TQM823L,TQM823M,katmai,gdppc440etx,taishan,yellowstone,nas220,ocotea,walnut,O2MNT_O2M110,sycamore,mx6qsabrelite,kmsuv31,kmsugp1,sequoia_ramboot,haleakala,icon,O2MNT_O2M113,O2MNT_O2M112,rainier_ramboot,canyonlands,kmcoge5un,dlvision,glacier,dockstar,dreamplug,kwb,TQM866M,TQM862L,km_kirkwood,dns325,io,yucca,makalu,lsxhl,wtk,nitrogen6s1g,tseries_mmc,TQM862M,dlvision-10g,TTTech,iocon,netspace_v2,TQM855M,TQM855L,pogo_e02,portl2,glacier_ramboot,edminiv2,bamboo,km_kirkwood_pci,net2big_v2,luan,motionpro,v38b,TQM823L_LCD,a3m071,intip,kilauea,bubinga,digsy_mtc,gwventana,rainier)
../drivers/net/netconsole.c: In function 'nc_send_packet':
w+(tseries_spi,nitrogen6dl2g,guruplug,digsy_mtc_rev5,netspace_mini_v2,yosemite,taihu,tseries_nand,neo,goflexhome,nitrogen6s,nitrogen6q,acadia,lschlv2,TQM850L,digsy_mtc_RAMBOOT,ebony,devconcenter,a4m2k,iconnect,xfi3,novena,sequoia,io64,arches,nitrogen6dl,ib62x0,km_kirkwood_128m16,netspace_lite_v2,TQM860L,sansa_fuze_plus,digsy_mtc_rev5_RAMBOOT,TQM860M,mgcoge3un,kmnusa,O2MNT,nitrogen6q2g,sheevaplug,t3corp,netspace_max_v2,TQM850M,redwood,microblaze-generic,TQM823L,TQM823M,katmai,gdppc440etx,taishan,yellowstone,nas220,ocotea,walnut,O2MNT_O2M110,sycamore,mx6qsabrelite,kmsuv31,kmsugp1,sequoia_ramboot,haleakala,icon,O2MNT_O2M113,O2MNT_O2M112,rainier_ramboot,canyonlands,kmcoge5un,dlvision,glacier,dockstar,dreamplug,kwb,TQM866M,TQM862L,km_kirkwood,dns325,io,yucca,makalu,lsxhl,wtk,nitrogen6s1g,tseries_mmc,TQM862M,dlvision-10g,TTTech,iocon,netspace_v2,TQM855M,TQM855L,pogo_e02,portl2,glacier_ramboot,edminiv2,bamboo,km_kirkwood_pci,net2big_v2,luan,motionpro,v38b,TQM823L_LCD,a3m071,intip,kilauea,bubinga,digsy_mtc,gwventana,rainier)
../drivers/net/netconsole.c:190:3: warning: implicit declaration of
function 'eth_is_active' [-Wimplicit-function-declaration]

After fixing warnings in the above, applied to u-boot-net/master.
-Joe
diff mbox

Patch

diff --git a/include/net.h b/include/net.h
index f1671e3..76ad41d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -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
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)