From: Bernhard Nortmann <bernhard.nortmann@web.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 1/3] expose eth_is_active() function to test network device state
Date: Sat, 22 Aug 2015 00:30:45 +0200 [thread overview]
Message-ID: <1440196247-6885-2-git-send-email-bernhard.nortmann@web.de> (raw)
In-Reply-To: <1440196247-6885-1-git-send-email-bernhard.nortmann@web.de>
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>
---
include/net.h | 6 ++++++
net/eth.c | 18 +++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/include/net.h b/include/net.h
index d09bec9..c135ec4 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 d3ec8d6..d3ff7c6 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -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)
--
2.4.6
next prev parent reply other threads:[~2015-08-21 22:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-21 22:30 [U-Boot] [RFC PATCH 0/3] fix netconsole for CONFIG_DM_ETH Bernhard Nortmann
2015-08-21 22:30 ` Bernhard Nortmann [this message]
2015-08-23 21:21 ` [U-Boot] [RFC PATCH 1/3] expose eth_is_active() function to test network device state Simon Glass
2015-08-24 10:20 ` Bernhard Nortmann
2015-08-24 16:59 ` Simon Glass
2015-08-24 17:02 ` Joe Hershberger
2015-08-25 9:53 ` Bernhard Nortmann
2015-08-25 15:55 ` Joe Hershberger
2015-08-25 18:01 ` Bernhard Nortmann
2015-08-25 18:13 ` Joe Hershberger
2015-08-21 22:30 ` [U-Boot] [RFC PATCH 2/3] fix netconsole when CONFIG_DM_ETH is set Bernhard Nortmann
2015-08-21 22:30 ` [U-Boot] [RFC PATCH 3/3] avoid eth_unregister() call when function is unavailable Bernhard Nortmann
2015-08-23 21:21 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440196247-6885-2-git-send-email-bernhard.nortmann@web.de \
--to=bernhard.nortmann@web.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox