]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
net: expose eth_is_active() function to test network device state
authorBernhard Nortmann <bernhard.nortmann@web.de>
Mon, 14 Sep 2015 13:29:43 +0000 (15:29 +0200)
committerJoe Hershberger <joe.hershberger@ni.com>
Wed, 30 Sep 2015 02:54:45 +0000 (21:54 -0500)
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>
include/net.h
net/eth.c

index f1671e38deaf745224901ec9d252cccf62b179bd..3a787cc4e981da86040f243bee07bef5d6ec9ff0 100644 (file)
@@ -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)
 {
index 26520d303885ea1e77e396b7f175d13f0299417b..2e24b55726be8a63846c835b5d3688c7d74bf670 100644 (file)
--- 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)