* [patch net-next-2.6] dummy: allow report link status and change it via sysfs
@ 2011-07-29 15:27 Jiri Pirko
2011-07-29 16:03 ` Ben Hutchings
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Pirko @ 2011-07-29 15:27 UTC (permalink / raw)
To: netdev; +Cc: davem, eric.dumazet
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
---
drivers/net/dummy.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 39cf9b9..fc39c24 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -37,9 +37,57 @@
#include <linux/rtnetlink.h>
#include <net/rtnetlink.h>
#include <linux/u64_stats_sync.h>
+#include <linux/ethtool.h>
static int numdummies = 1;
+static ssize_t dummy_show_link(struct device *d,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct net_device *dev = to_net_dev(d);
+
+ return sprintf(buf, "%d\n", netif_carrier_ok(dev) ? 1 : 0);
+}
+
+static ssize_t dummy_store_link(struct device *d,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct net_device *dev = to_net_dev(d);
+ int new_value;
+
+ if (sscanf(buf, "%d", &new_value) != 1) {
+ pr_err("%s: no link value specified.\n", dev->name);
+ return -EINVAL;
+ }
+ switch (new_value) {
+ case 0:
+ netif_carrier_off(dev);
+ break;
+ case 1:
+ netif_carrier_on(dev);
+ break;
+ default:
+ pr_info("%s: Ignoring invalid link value %d.\n",
+ dev->name, new_value);
+ }
+ return count;
+}
+
+static DEVICE_ATTR(link, S_IRUGO | S_IWUSR,
+ dummy_show_link, dummy_store_link);
+
+static struct attribute *per_dummy_attrs[] = {
+ &dev_attr_link.attr,
+ NULL,
+};
+
+static struct attribute_group dummy_group = {
+ .name = "dummy",
+ .attrs = per_dummy_attrs,
+};
+
static int dummy_set_address(struct net_device *dev, void *p)
{
struct sockaddr *sa = p;
@@ -103,6 +151,7 @@ static int dummy_dev_init(struct net_device *dev)
if (!dev->dstats)
return -ENOMEM;
+ dev->sysfs_groups[0] = &dummy_group;
return 0;
}
@@ -121,12 +170,17 @@ static const struct net_device_ops dummy_netdev_ops = {
.ndo_get_stats64 = dummy_get_stats64,
};
+static const struct ethtool_ops dummy_ethtool_ops = {
+ .get_link = ethtool_op_get_link,
+};
+
static void dummy_setup(struct net_device *dev)
{
ether_setup(dev);
/* Initialize the device structure. */
dev->netdev_ops = &dummy_netdev_ops;
+ dev->ethtool_ops = &dummy_ethtool_ops;
dev->destructor = dummy_dev_free;
/* Fill in device structure with ethernet-generic values. */
--
1.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch net-next-2.6] dummy: allow report link status and change it via sysfs
2011-07-29 15:27 [patch net-next-2.6] dummy: allow report link status and change it via sysfs Jiri Pirko
@ 2011-07-29 16:03 ` Ben Hutchings
2011-07-29 16:55 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Ben Hutchings @ 2011-07-29 16:03 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, davem, eric.dumazet
On Fri, 2011-07-29 at 17:27 +0200, Jiri Pirko wrote:
> Signed-off-by: Jiri Pirko <jpirko@redhat.com>
> ---
> drivers/net/dummy.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 54 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
> index 39cf9b9..fc39c24 100644
> --- a/drivers/net/dummy.c
> +++ b/drivers/net/dummy.c
> @@ -37,9 +37,57 @@
> #include <linux/rtnetlink.h>
> #include <net/rtnetlink.h>
> #include <linux/u64_stats_sync.h>
> +#include <linux/ethtool.h>
>
> static int numdummies = 1;
>
> +static ssize_t dummy_show_link(struct device *d,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct net_device *dev = to_net_dev(d);
> +
> + return sprintf(buf, "%d\n", netif_carrier_ok(dev) ? 1 : 0);
> +}
[...]
Net devices already have the 'carrier' attribute. You should make that
attribute writable for dummy devices, rather than adding another one.
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch net-next-2.6] dummy: allow report link status and change it via sysfs
2011-07-29 16:03 ` Ben Hutchings
@ 2011-07-29 16:55 ` Stephen Hemminger
0 siblings, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2011-07-29 16:55 UTC (permalink / raw)
To: Ben Hutchings; +Cc: Jiri Pirko, netdev, davem, eric.dumazet
On Fri, 29 Jul 2011 18:03:09 +0200
Ben Hutchings <bhutchings@solarflare.com> wrote:
> On Fri, 2011-07-29 at 17:27 +0200, Jiri Pirko wrote:
> > Signed-off-by: Jiri Pirko <jpirko@redhat.com>
> > ---
> > drivers/net/dummy.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 files changed, 54 insertions(+), 0 deletions(-)
> >
> > diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
> > index 39cf9b9..fc39c24 100644
> > --- a/drivers/net/dummy.c
> > +++ b/drivers/net/dummy.c
> > @@ -37,9 +37,57 @@
> > #include <linux/rtnetlink.h>
> > #include <net/rtnetlink.h>
> > #include <linux/u64_stats_sync.h>
> > +#include <linux/ethtool.h>
> >
> > static int numdummies = 1;
> >
> > +static ssize_t dummy_show_link(struct device *d,
> > + struct device_attribute *attr,
> > + char *buf)
> > +{
> > + struct net_device *dev = to_net_dev(d);
> > +
> > + return sprintf(buf, "%d\n", netif_carrier_ok(dev) ? 1 : 0);
> > +}
> [...]
>
> Net devices already have the 'carrier' attribute. You should make that
> attribute writable for dummy devices, rather than adding another one.
>
And adding ethtool support is unnecessary since carrier is already
reported by tools like 'ip link'
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-07-29 16:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-29 15:27 [patch net-next-2.6] dummy: allow report link status and change it via sysfs Jiri Pirko
2011-07-29 16:03 ` Ben Hutchings
2011-07-29 16:55 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).