aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2015-03-09 23:50:26 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-09 23:50:26 -0400
commitbf0b211256be342e92d3ee5c5a1fb8d42f3928bb (patch)
tree3e57589f3c8b06b02e895e2428a82433f5cb8bda
parent3cef5c5b0b56f3f90b0e9ff8d3f8dc57f464cc14 (diff)
parent769a020289bc8f68b7e48faf8fee970346d71a3b (diff)
Merge branch 'dsa-next'
Florian Fainelli says: ==================== net: dsa: remove restriction on platform_device This patch series removes the restriction in DSA to operate exclusively with platform_device Ethernet MAC drivers when using Device Tree. This basically allows arbitrary Ethernet MAC drivers to be used now in conjunction with Device Tree. The reason was that DSA was using a of_find_device_by_node() which limits the device_node to device pointer search exclusively to platform_device, in our case, we are interested in doing a "class" research and lookup the net_device. Thanks to Chris Packham for testing this on his platform. Changes in v2: - fix build for !CONFIG_OF_NET ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/of_net.h8
-rw-r--r--include/net/dsa.h1
-rw-r--r--net/core/net-sysfs.c25
-rw-r--r--net/dsa/dsa.c16
4 files changed, 45 insertions, 5 deletions
diff --git a/include/linux/of_net.h b/include/linux/of_net.h
index 34597c8c1a4c..9cd72aab76fe 100644
--- a/include/linux/of_net.h
+++ b/include/linux/of_net.h
@@ -9,8 +9,11 @@
9 9
10#ifdef CONFIG_OF_NET 10#ifdef CONFIG_OF_NET
11#include <linux/of.h> 11#include <linux/of.h>
12
13struct net_device;
12extern int of_get_phy_mode(struct device_node *np); 14extern int of_get_phy_mode(struct device_node *np);
13extern const void *of_get_mac_address(struct device_node *np); 15extern const void *of_get_mac_address(struct device_node *np);
16extern struct net_device *of_find_net_device_by_node(struct device_node *np);
14#else 17#else
15static inline int of_get_phy_mode(struct device_node *np) 18static inline int of_get_phy_mode(struct device_node *np)
16{ 19{
@@ -21,6 +24,11 @@ static inline const void *of_get_mac_address(struct device_node *np)
21{ 24{
22 return NULL; 25 return NULL;
23} 26}
27
28static inline struct net_device *of_find_net_device_by_node(struct device_node *np)
29{
30 return NULL;
31}
24#endif 32#endif
25 33
26#endif /* __LINUX_OF_NET_H */ 34#endif /* __LINUX_OF_NET_H */
diff --git a/include/net/dsa.h b/include/net/dsa.h
index b525ac516559..47917e5e1e12 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -72,6 +72,7 @@ struct dsa_platform_data {
72 * to the root switch chip of the tree. 72 * to the root switch chip of the tree.
73 */ 73 */
74 struct device *netdev; 74 struct device *netdev;
75 struct net_device *of_netdev;
75 76
76 /* 77 /*
77 * Info structs describing each of the switch chips 78 * Info structs describing each of the switch chips
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
1379static 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
1389struct 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}
1399EXPORT_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 */
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index b40f11bb419c..899772108ee3 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -20,6 +20,7 @@
20#include <linux/of.h> 20#include <linux/of.h>
21#include <linux/of_mdio.h> 21#include <linux/of_mdio.h>
22#include <linux/of_platform.h> 22#include <linux/of_platform.h>
23#include <linux/of_net.h>
23#include <linux/sysfs.h> 24#include <linux/sysfs.h>
24#include "dsa_priv.h" 25#include "dsa_priv.h"
25 26
@@ -583,7 +584,7 @@ static int dsa_of_probe(struct device *dev)
583 struct device_node *np = dev->of_node; 584 struct device_node *np = dev->of_node;
584 struct device_node *child, *mdio, *ethernet, *port, *link; 585 struct device_node *child, *mdio, *ethernet, *port, *link;
585 struct mii_bus *mdio_bus; 586 struct mii_bus *mdio_bus;
586 struct platform_device *ethernet_dev; 587 struct net_device *ethernet_dev;
587 struct dsa_platform_data *pd; 588 struct dsa_platform_data *pd;
588 struct dsa_chip_data *cd; 589 struct dsa_chip_data *cd;
589 const char *port_name; 590 const char *port_name;
@@ -604,7 +605,7 @@ static int dsa_of_probe(struct device *dev)
604 if (!ethernet) 605 if (!ethernet)
605 return -EINVAL; 606 return -EINVAL;
606 607
607 ethernet_dev = of_find_device_by_node(ethernet); 608 ethernet_dev = of_find_net_device_by_node(ethernet);
608 if (!ethernet_dev) 609 if (!ethernet_dev)
609 return -EPROBE_DEFER; 610 return -EPROBE_DEFER;
610 611
@@ -613,7 +614,7 @@ static int dsa_of_probe(struct device *dev)
613 return -ENOMEM; 614 return -ENOMEM;
614 615
615 dev->platform_data = pd; 616 dev->platform_data = pd;
616 pd->netdev = &ethernet_dev->dev; 617 pd->of_netdev = ethernet_dev;
617 pd->nr_chips = of_get_available_child_count(np); 618 pd->nr_chips = of_get_available_child_count(np);
618 if (pd->nr_chips > DSA_MAX_SWITCHES) 619 if (pd->nr_chips > DSA_MAX_SWITCHES)
619 pd->nr_chips = DSA_MAX_SWITCHES; 620 pd->nr_chips = DSA_MAX_SWITCHES;
@@ -771,10 +772,15 @@ static int dsa_probe(struct platform_device *pdev)
771 pd = pdev->dev.platform_data; 772 pd = pdev->dev.platform_data;
772 } 773 }
773 774
774 if (pd == NULL || pd->netdev == NULL) 775 if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL))
775 return -EINVAL; 776 return -EINVAL;
776 777
777 dev = dev_to_net_device(pd->netdev); 778 if (pd->of_netdev) {
779 dev = pd->of_netdev;
780 dev_hold(dev);
781 } else {
782 dev = dev_to_net_device(pd->netdev);
783 }
778 if (dev == NULL) { 784 if (dev == NULL) {
779 ret = -EPROBE_DEFER; 785 ret = -EPROBE_DEFER;
780 goto out; 786 goto out;