From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, stephen@networkplumber.org,
Narendra_K@Dell.com, bhutchings@solarflare.com,
john.r.fastabend@intel.com
Subject: [patch net-next v2 3/3] net: export physical port id via sysfs
Date: Sat, 20 Jul 2013 19:53:54 +0200 [thread overview]
Message-ID: <1374342834-10814-4-git-send-email-jiri@resnulli.us> (raw)
In-Reply-To: <1374342834-10814-1-git-send-email-jiri@resnulli.us>
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
net/core/net-sysfs.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 981fed3..56b4635 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -334,6 +334,47 @@ static ssize_t store_group(struct device *dev, struct device_attribute *attr,
return netdev_store(dev, attr, buf, len, change_group);
}
+static size_t _format_port_id(char *buf, int buflen,
+ const unsigned char *id, int len)
+{
+ int i;
+ char *cp = buf;
+
+ for (i = 0; i < len; i++)
+ cp += scnprintf(cp, buflen - (cp - buf), "%02x", id[i]);
+ return cp - buf;
+}
+
+ssize_t sysfs_format_port_id(char *buf, const unsigned char *id, int len)
+{
+ size_t l;
+
+ l = _format_port_id(buf, PAGE_SIZE, id, len);
+ l += scnprintf(buf + l, PAGE_SIZE - l, "\n");
+ return (ssize_t)l;
+}
+
+static ssize_t show_phys_port_id(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct net_device *netdev = to_net_dev(dev);
+ ssize_t ret = -EINVAL;
+
+ if (!rtnl_trylock())
+ return restart_syscall();
+
+ if (dev_isalive(netdev)) {
+ struct netdev_phys_port_id ppid;
+
+ ret = dev_get_phys_port_id(netdev, &ppid);
+ if (!ret)
+ ret = sysfs_format_port_id(buf, ppid.id, ppid.id_len);
+ }
+ rtnl_unlock();
+
+ return ret;
+}
+
static struct device_attribute net_class_attributes[] = {
__ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL),
__ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
@@ -355,6 +396,7 @@ static struct device_attribute net_class_attributes[] = {
__ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
store_tx_queue_len),
__ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group),
+ __ATTR(phys_port_id, S_IRUGO, show_phys_port_id, NULL),
{}
};
--
1.8.1.4
next prev parent reply other threads:[~2013-07-20 17:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-20 17:53 [patch net-next v2 0/3] export device physical port id to userspace Jiri Pirko
2013-07-20 17:53 ` [patch net-next v2 1/3] net: add ndo to get id of physical port of the device Jiri Pirko
2013-07-21 11:10 ` Or Gerlitz
2013-07-21 15:00 ` Ben Hutchings
2013-07-21 15:01 ` Ben Hutchings
2013-07-21 20:26 ` Or Gerlitz
2013-07-21 21:02 ` Jiri Pirko
2013-07-22 11:29 ` Narendra_K
2013-07-22 11:53 ` Jiri Pirko
2013-07-22 15:52 ` Or Gerlitz
2013-07-20 17:53 ` [patch net-next v2 2/3] rtnl: export physical port id via RT netlink Jiri Pirko
2013-07-21 15:03 ` Ben Hutchings
2013-07-22 11:50 ` Narendra_K
2013-07-20 17:53 ` Jiri Pirko [this message]
2013-07-21 15:05 ` [patch net-next v2 3/3] net: export physical port id via sysfs Ben Hutchings
2013-07-22 11:54 ` Narendra_K
2013-07-21 5:59 ` [patch net-next v2 0/3] export device physical port id to userspace Or Gerlitz
2013-07-21 7:26 ` Jiri Pirko
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=1374342834-10814-4-git-send-email-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=Narendra_K@Dell.com \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=john.r.fastabend@intel.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/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).