netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sfeldma@gmail.com
To: netdev@vger.kernel.org
Cc: jiri@resnulli.us, davem@davemloft.net, f.fainelli@gmail.com,
	roopa@cumulusnetworks.com
Subject: [RFC PATCH net-next 1/2] switchdev: create new switchdev device class
Date: Thu, 27 Aug 2015 00:16:45 -0700	[thread overview]
Message-ID: <1440659806-56582-2-git-send-email-sfeldma@gmail.com> (raw)
In-Reply-To: <1440659806-56582-1-git-send-email-sfeldma@gmail.com>

From: Scott Feldman <sfeldma@gmail.com>

Signed-off-by: Scott Feldman <sfeldma@gmail.com>
---
 include/net/switchdev.h   |   16 ++++++++++
 net/switchdev/switchdev.c |   76 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/include/net/switchdev.h b/include/net/switchdev.h
index 319baab..d61e73c 100644
--- a/include/net/switchdev.h
+++ b/include/net/switchdev.h
@@ -16,6 +16,11 @@
 
 #define SWITCHDEV_F_NO_RECURSE		BIT(0)
 
+struct switchdev {
+	struct device dev;
+	atomic_t foo;
+};
+
 enum switchdev_trans {
 	SWITCHDEV_TRANS_NONE,
 	SWITCHDEV_TRANS_PREPARE,
@@ -126,6 +131,8 @@ switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
 
 #ifdef CONFIG_NET_SWITCHDEV
 
+int register_switchdev(struct switchdev *sdev, const char *name);
+void unregister_switchdev(struct switchdev *sdev);
 int switchdev_port_attr_get(struct net_device *dev,
 			    struct switchdev_attr *attr);
 int switchdev_port_attr_set(struct net_device *dev,
@@ -164,6 +171,15 @@ void switchdev_port_fwd_mark_set(struct net_device *dev,
 
 #else
 
+static inline int register_switchdev(struct switchdev *sdev, const char *name)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void unregister_switchdev(struct switchdev *sdev)
+{
+}
+
 static inline int switchdev_port_attr_get(struct net_device *dev,
 					  struct switchdev_attr *attr)
 {
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 16c1c43..f705202 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -10,6 +10,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/mutex.h>
@@ -19,6 +20,63 @@
 #include <net/ip_fib.h>
 #include <net/switchdev.h>
 
+#define to_switchdev(d) container_of(d, struct switchdev, dev)
+
+static void switchdev_release(struct device *dev)
+{
+}
+
+static ssize_t foo_show(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct switchdev *switchdev = to_switchdev(dev);
+
+	return sprintf(buf, "%d\n", atomic_read(&switchdev->foo));
+}
+
+static DEVICE_ATTR_RO(foo);
+
+static struct attribute *switchdev_attrs[] = {
+	&dev_attr_foo.attr
+};
+
+ATTRIBUTE_GROUPS(switchdev);
+
+static int switchdev_uevent(struct device *d, struct kobj_uevent_env *env)
+{
+	return 0;
+}
+
+static struct class switchdev_class = {
+	.name = "switchdev",
+	.dev_release = switchdev_release,
+	.dev_groups = switchdev_groups,
+	.dev_uevent = switchdev_uevent,
+};
+
+int register_switchdev(struct switchdev *sdev, const char *name)
+{
+	struct device *dev = &sdev->dev;
+	int err;
+
+	device_initialize(dev);
+
+	dev->class = &switchdev_class;
+
+	err = dev_set_name(dev, "%s", name);
+	if (err)
+		return err;
+
+	return device_add(dev);
+}
+EXPORT_SYMBOL_GPL(register_switchdev);
+
+void unregister_switchdev(struct switchdev *sdev)
+{
+	put_device(&sdev->dev);
+}
+EXPORT_SYMBOL_GPL(unregister_switchdev);
+
 /**
  *	switchdev_port_attr_get - Get port attribute
  *
@@ -1142,3 +1200,21 @@ void switchdev_port_fwd_mark_set(struct net_device *dev,
 	dev->offload_fwd_mark = mark;
 }
 EXPORT_SYMBOL_GPL(switchdev_port_fwd_mark_set);
+
+static int __init switchdev_module_init(void)
+{
+	return class_register(&switchdev_class);
+}
+
+static void __exit switchdev_module_exit(void)
+{
+	class_unregister(&switchdev_class);
+}
+
+module_init(switchdev_module_init);
+module_exit(switchdev_module_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
+MODULE_AUTHOR("Scott Feldman <sfeldma@gmail.com>");
+MODULE_DESCRIPTION("Ethernet switch device model");
-- 
1.7.10.4

  reply	other threads:[~2015-08-27  7:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27  7:16 [RFC PATCH net-next 0/2] Add new switchdev device class sfeldma
2015-08-27  7:16 ` sfeldma [this message]
2015-08-27  7:16 ` [RFC PATCH net-next 2/2] rocker: register each switch as a switchdev sfeldma
2015-08-27  7:27 ` [RFC PATCH net-next 0/2] Add new switchdev device class Jiri Pirko
2015-08-27  7:43   ` John Fastabend
2015-08-27  7:51     ` Jiri Pirko
2015-08-27  8:14       ` John Fastabend
2015-08-27  8:17   ` Scott Feldman
2015-08-27  8:41     ` Jiri Pirko
2015-08-27  7:36 ` John Fastabend
2015-08-27  7:44   ` Jiri Pirko
2015-08-27  8:09     ` John Fastabend
2015-08-27  8:23   ` Scott Feldman
2015-08-27  7:45 ` Andrew Lunn
2015-08-27  8:42   ` Scott Feldman
2015-08-27  9:06     ` Andrew Lunn
2015-08-27 16:41       ` Scott Feldman
2015-08-28 11:52         ` Andrew Lunn
2015-08-27 13:54 ` John W. Linville
2015-08-27 23:25 ` David Miller
2015-08-28  2:13 ` Arad, Ronen
2015-08-28 16:55   ` Florian Fainelli

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=1440659806-56582-2-git-send-email-sfeldma@gmail.com \
    --to=sfeldma@gmail.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    /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;
as well as URLs for NNTP newsgroup(s).