diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2015-03-09 17:31:20 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-09 23:50:20 -0400 |
commit | aa836df958886e57ff0d43fb3d79d1af4aec0cc8 (patch) | |
tree | 1b55886cc71a6fd387d42ebc4f08c21a3a6778e9 /net/core | |
parent | 3cef5c5b0b56f3f90b0e9ff8d3f8dc57f464cc14 (diff) |
net: core: add of_find_net_device_by_node()
Add a helper function which allows getting the struct net_device pointer
associated with a given struct device_node pointer. This is useful for
instance for DSA Ethernet devices not backed by a platform_device, but a PCI
device.
Since we need to access net_class which is not accessible outside of
net/core/net-sysfs.c, this helper function is also added here and gated
with CONFIG_OF_NET.
Network devices initialized with SET_NETDEV_DEV() are also taken into
account by checking for dev->parent first and then falling back to
checking the device pointer within struct net_device.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/net-sysfs.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index f2aa73bfb0e4..cf30620a88e1 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/export.h> | 23 | #include <linux/export.h> |
24 | #include <linux/jiffies.h> | 24 | #include <linux/jiffies.h> |
25 | #include <linux/pm_runtime.h> | 25 | #include <linux/pm_runtime.h> |
26 | #include <linux/of.h> | ||
26 | 27 | ||
27 | #include "net-sysfs.h" | 28 | #include "net-sysfs.h" |
28 | 29 | ||
@@ -1374,6 +1375,30 @@ static struct class net_class = { | |||
1374 | .namespace = net_namespace, | 1375 | .namespace = net_namespace, |
1375 | }; | 1376 | }; |
1376 | 1377 | ||
1378 | #ifdef CONFIG_OF_NET | ||
1379 | static int of_dev_node_match(struct device *dev, const void *data) | ||
1380 | { | ||
1381 | int ret = 0; | ||
1382 | |||
1383 | if (dev->parent) | ||
1384 | ret = dev->parent->of_node == data; | ||
1385 | |||
1386 | return ret == 0 ? dev->of_node == data : ret; | ||
1387 | } | ||
1388 | |||
1389 | struct net_device *of_find_net_device_by_node(struct device_node *np) | ||
1390 | { | ||
1391 | struct device *dev; | ||
1392 | |||
1393 | dev = class_find_device(&net_class, NULL, np, of_dev_node_match); | ||
1394 | if (!dev) | ||
1395 | return NULL; | ||
1396 | |||
1397 | return to_net_dev(dev); | ||
1398 | } | ||
1399 | EXPORT_SYMBOL(of_find_net_device_by_node); | ||
1400 | #endif | ||
1401 | |||
1377 | /* Delete sysfs entries but hold kobject reference until after all | 1402 | /* Delete sysfs entries but hold kobject reference until after all |
1378 | * netdev references are gone. | 1403 | * netdev references are gone. |
1379 | */ | 1404 | */ |