Skip to contentSkip to conversation

net: dsa: Support for pdata in dsa2

PATCH Superseded Florian Fainelli 5 participants 22 messages Jan 12, 2017 – Jan 14, 2017

Subsystems (10)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: dsa: Support for pdata in dsa2

Hi all,

This is not exactly new, and was sent before, although back then, I did not have an user of the pre-declared MDIO board information, but now we do. Note that I have additional changes queued up to have b53 register platform data for MIPS bcm47xx and bcm63xx.

Yes I know that we should have the Orion platforms eventually be converted to Device Tree, but until that happens, I don't want any remaining users of the old "dsa" platform device (hence the previous DTS submissions for ARM/mvebu) and, there will be platforms out there that most likely won't never see DT coming their way (BCM47xx is almost 100% sure, BCM63xx maybe not in a distant future).

We would probably want the whole series to be merged via David Miller's tree to simplify things.

Greg, can you Ack/Nack patch 5 since it touched the core LDD?

Thanks!

Changes in v2:

- Rebased against latest net-next/master

- Moved dev_find_class() to device_find_class() into drivers/base/core.c

- Moved dev_to_net_device into net/core/dev.c

- Utilize dsa_chip_data directly instead of dsa_platform_data

- Augmented dsa_chip_data to be multi-CPU port ready

Changes from last submission (few months back):

- rebased against latest net-next

- do not introduce dsa2_platform_data which was overkill and was meant to allow us to do exaclty the same things with platform data and Device Tree we use the existing dsa_platform_data instead

- properly register MDIO devices when the MDIO bus is registered and associate platform_data with them

- add a change to the Orion platform code to demonstrate how this can be used

Thank you

Florian Fainelli (10):
net: dsa: Pass device pointer to dsa_register_switch
net: dsa: Make most functions take a dsa_port argument
net: dsa: Suffix function manipulating device_node with _dn
net: dsa: Move ports assignment closer to error checking
drivers: base: Add device_find_class()
net: dsa: Migrate to device_find_class()
net: Relocate dev_to_net_device() into core
net: dsa: Add support for platform data
net: phy: Allow pre-declaration of MDIO devices
ARM: orion: Register DSA switch as a MDIO device

 arch/arm/mach-orion5x/common.c               |   2 +-
 arch/arm/mach-orion5x/common.h               |   4 +-
 arch/arm/mach-orion5x/rd88f5181l-fxo-setup.c |   7 +-
 arch/arm/mach-orion5x/rd88f5181l-ge-setup.c  |   7 +-
 arch/arm/mach-orion5x/rd88f6183ap-ge-setup.c |   7 +-
 arch/arm/mach-orion5x/wnr854t-setup.c        |   2 +-
 arch/arm/mach-orion5x/wrt350n-v2-setup.c     |   7 +-
 arch/arm/plat-orion/common.c                 |  25 +++-
 arch/arm/plat-orion/include/plat/common.h    |   4 +-
 drivers/base/core.c                          |  19 +++
 drivers/net/dsa/b53/b53_common.c             |   2 +-
 drivers/net/dsa/mv88e6xxx/chip.c             |  11 +-
 drivers/net/dsa/qca8k.c                      |   2 +-
 drivers/net/phy/Makefile                     |   3 +-
 drivers/net/phy/mdio-boardinfo.c             |  86 ++++++++++++++
 drivers/net/phy/mdio-boardinfo.h             |  19 +++
 drivers/net/phy/mdio_bus.c                   |   5 +
 drivers/net/phy/mdio_device.c                |  11 ++
 include/linux/device.h                       |   1 +
 include/linux/mdio.h                         |   3 +
 include/linux/mod_devicetable.h              |   1 +
 include/linux/netdevice.h                    |   2 +
 include/linux/phy.h                          |  19 +++
 include/net/dsa.h                            |   8 +-
 net/core/dev.c                               |  19 +++
 net/dsa/dsa.c                                |  53 ++-------
 net/dsa/dsa2.c                               | 168 +++++++++++++++++++--------
 net/dsa/dsa_priv.h                           |   4 +-
 28 files changed, 360 insertions(+), 141 deletions(-)
 create mode 100644 drivers/net/phy/mdio-boardinfo.c
 create mode 100644 drivers/net/phy/mdio-boardinfo.h
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 1/10 net: dsa: Pass device pointer to dsa_register_switch

In preparation for allowing dsa_register_switch() to be supplied with device/platform data, pass down a struct device pointer instead of a struct device_node.

---
 drivers/net/dsa/b53/b53_common.c |  2 +-
 drivers/net/dsa/mv88e6xxx/chip.c | 11 ++++++-----
 drivers/net/dsa/qca8k.c          |  2 +-
 include/net/dsa.h                |  2 +-
 net/dsa/dsa2.c                   |  7 ++++---
 5 files changed, 13 insertions(+), 11 deletions(-)
drivers/net/dsa/b53/b53_common.c +1 -1
index 5102a3701a1a..7179eed9ee6d 100644
@@ -1882,7 +1882,7 @@ int b53_switch_register(struct b53_device *dev)
 
 	pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev);
 
-	return dsa_register_switch(dev->ds, dev->ds->dev->of_node);
+	return dsa_register_switch(dev->ds, dev->ds->dev);
 }
 EXPORT_SYMBOL(b53_switch_register);
 
drivers/net/dsa/mv88e6xxx/chip.c +6 -5
index eea8e0176e33..1060597e160a 100644
@@ -4407,8 +4407,7 @@ static struct dsa_switch_driver mv88e6xxx_switch_drv = {
 	.ops			= &mv88e6xxx_switch_ops,
 };
 
-static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
-				     struct device_node *np)
+static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
 {
 	struct device *dev = chip->dev;
 	struct dsa_switch *ds;
@@ -4423,7 +4422,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
 
 	dev_set_drvdata(dev, ds);
 
-	return dsa_register_switch(ds, np);
+	return dsa_register_switch(ds, dev);
 }
 
 static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
@@ -4507,9 +4506,11 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
 	if (err)
 		goto out_g2_irq;
 
-	err = mv88e6xxx_register_switch(chip, np);
-	if (err)
+	err = mv88e6xxx_register_switch(chip);
+	if (err) {
+		mv88e6xxx_mdio_unregister(chip);
 		goto out_mdio;
+	}
 
 	return 0;
 
drivers/net/dsa/qca8k.c +1 -1
index 54d270d59eb0..c084aa484d2b 100644
@@ -964,7 +964,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 	mutex_init(&priv->reg_mutex);
 	dev_set_drvdata(&mdiodev->dev, priv);
 
-	return dsa_register_switch(priv->ds, priv->ds->dev->of_node);
+	return dsa_register_switch(priv->ds, &mdiodev->dev);
 }
 
 static void
include/net/dsa.h +1 -1
index b94d1f2ef912..16a502a6c26a 100644
@@ -403,7 +403,7 @@ static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
 }
 
 void dsa_unregister_switch(struct dsa_switch *ds);
-int dsa_register_switch(struct dsa_switch *ds, struct device_node *np);
+int dsa_register_switch(struct dsa_switch *ds, struct device *dev);
 #ifdef CONFIG_PM_SLEEP
 int dsa_switch_suspend(struct dsa_switch *ds);
 int dsa_switch_resume(struct dsa_switch *ds);
net/dsa/dsa2.c +4 -3
index 42a41d84053c..4170f7ea8e28 100644
@@ -579,8 +579,9 @@ static struct device_node *dsa_get_ports(struct dsa_switch *ds,
 	return ports;
 }
 
-static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
+static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev)
 {
+	struct device_node *np = dev->of_node;
 	struct device_node *ports = dsa_get_ports(ds, np);
 	struct dsa_switch_tree *dst;
 	u32 tree, index;
@@ -660,12 +661,12 @@ static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
 	return err;
 }
 
-int dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
+int dsa_register_switch(struct dsa_switch *ds, struct device *dev)
 {
 	int err;
 
 	mutex_lock(&dsa2_mutex);
-	err = _dsa_register_switch(ds, np);
+	err = _dsa_register_switch(ds, dev);
 	mutex_unlock(&dsa2_mutex);
 
 	return err;
Signature · 1 line
2.9.3
#2 lore raw

PATCH v2 2/10 net: dsa: Make most functions take a dsa_port argument

In reply to Florian Fainelli

In preparation for allowing platform data, and therefore no valid device_node pointer, make most DSA functions takes a pointer to a dsa_port structure whenever possible. While at it, introduce a dsa_port_is_valid() helper function which checks whether port->dn is NULL or not at the moment.

---
 net/dsa/dsa.c      | 15 ++++++++------
 net/dsa/dsa2.c     | 61 +++++++++++++++++++++++++++++-------------------------
 net/dsa/dsa_priv.h |  4 ++--
 3 files changed, 44 insertions(+), 36 deletions(-)
net/dsa/dsa.c +9 -6
index fd532487dfdf..2306d1b87c83 100644
@@ -110,8 +110,9 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
 
 /* basic switch operations **************************************************/
 int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
-		      struct device_node *port_dn, int port)
+		      struct dsa_port *dport, int port)
 {
+	struct device_node *port_dn = dport->dn;
 	struct phy_device *phydev;
 	int ret, mode;
 
@@ -141,15 +142,15 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
 
 static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
 {
-	struct device_node *port_dn;
+	struct dsa_port *dport;
 	int ret, port;
 
 	for (port = 0; port < DSA_MAX_PORTS; port++) {
 		if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
 			continue;
 
-		port_dn = ds->ports[port].dn;
-		ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port);
+		dport = &ds->ports[port];
+		ret = dsa_cpu_dsa_setup(ds, dev, dport, port);
 		if (ret)
 			return ret;
 	}
@@ -366,8 +367,10 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
 	return ds;
 }
 
-void dsa_cpu_dsa_destroy(struct device_node *port_dn)
+void dsa_cpu_dsa_destroy(struct dsa_port *port)
 {
+	struct device_node *port_dn = port->dn;
+
 	if (of_phy_is_fixed_link(port_dn))
 		of_phy_deregister_fixed_link(port_dn);
 }
@@ -393,7 +396,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
 	for (port = 0; port < DSA_MAX_PORTS; port++) {
 		if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
 			continue;
-		dsa_cpu_dsa_destroy(ds->ports[port].dn);
+		dsa_cpu_dsa_destroy(&ds->ports[port]);
 
 		/* Clearing a bit which is not set does no harm */
 		ds->cpu_port_mask |= ~(1 << port);
net/dsa/dsa2.c +33 -28

182 lines not on this page · raw message

net/dsa/dsa_priv.h +2 -2
index 7e3385ec73f4..a015ec97c289 100644
@@ -50,8 +50,8 @@ struct dsa_slave_priv {
 
 /* dsa.c */
 int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
-		      struct device_node *port_dn, int port);
-void dsa_cpu_dsa_destroy(struct device_node *port_dn);
+		      struct dsa_port *dport, int port);
+void dsa_cpu_dsa_destroy(struct dsa_port *dport);
 const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
 int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds);
 void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds);
Signature · 1 line
2.9.3
#3 lore raw

PATCH v2 3/10 net: dsa: Suffix function manipulating device_node with _dn

In reply to Florian Fainelli

Make it clear that these functions take a device_node structure pointer

---
 net/dsa/dsa2.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
net/dsa/dsa2.c +8 -8
index 6e3675220fef..04ab62251fe3 100644
@@ -94,8 +94,8 @@ static bool dsa_port_is_cpu(struct dsa_port *port)
 	return !!of_parse_phandle(port->dn, "ethernet", 0);
 }
 
-static bool dsa_ds_find_port(struct dsa_switch *ds,
-			     struct device_node *port)
+static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
+				struct device_node *port)
 {
 	u32 index;
 
@@ -105,8 +105,8 @@ static bool dsa_ds_find_port(struct dsa_switch *ds,
 	return false;
 }
 
-static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
-					    struct device_node *port)
+static struct dsa_switch *dsa_dst_find_port_dn(struct dsa_switch_tree *dst,
+					       struct device_node *port)
 {
 	struct dsa_switch *ds;
 	u32 index;
@@ -116,7 +116,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
 		if (!ds)
 			continue;
 
-		if (dsa_ds_find_port(ds, port))
+		if (dsa_ds_find_port_dn(ds, port))
 			return ds;
 	}
 
@@ -137,7 +137,7 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
 		if (!link)
 			break;
 
-		dst_ds = dsa_dst_find_port(dst, link);
+		dst_ds = dsa_dst_find_port_dn(dst, link);
 		of_node_put(link);
 
 		if (!dst_ds)
@@ -546,7 +546,7 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
 	return 0;
 }
 
-static int dsa_parse_member(struct device_node *np, u32 *tree, u32 *index)
+static int dsa_parse_member_dn(struct device_node *np, u32 *tree, u32 *index)
 {
 	int err;
 
@@ -592,7 +592,7 @@ static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev)
 	u32 tree, index;
 	int i, err;
 
-	err = dsa_parse_member(np, &tree, &index);
+	err = dsa_parse_member_dn(np, &tree, &index);
 	if (err)
 		return err;
 
Signature · 1 line
2.9.3
#4 lore raw

PATCH v2 4/10 net: dsa: Move ports assignment closer to error checking

In reply to Florian Fainelli

Move the assignment of ports in _dsa_register_switch() closer to where it is checked, no functional change. Re-order declarations to be preserve the inverted christmas tree style.

---
 net/dsa/dsa2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/dsa/dsa2.c +2 -1
index 04ab62251fe3..cd91070b5467 100644
@@ -587,8 +587,8 @@ static struct device_node *dsa_get_ports(struct dsa_switch *ds,
 static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev)
 {
 	struct device_node *np = dev->of_node;
-	struct device_node *ports = dsa_get_ports(ds, np);
 	struct dsa_switch_tree *dst;
+	struct device_node *ports;
 	u32 tree, index;
 	int i, err;
 
@@ -596,6 +596,7 @@ static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev)
 	if (err)
 		return err;
 
+	ports = dsa_get_ports(ds, np);
 	if (IS_ERR(ports))
 		return PTR_ERR(ports);
 
Signature · 1 line
2.9.3
#5 lore raw

PATCH v2 5/10 drivers: base: Add device_find_class()

In reply to Florian Fainelli

Add a helper function to lookup a device reference given a class name. This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and make it more generic.

---
 drivers/base/core.c    | 19 +++++++++++++++++++
 include/linux/device.h |  1 +
 2 files changed, 20 insertions(+)
drivers/base/core.c +19 -0
index 020ea7f05520..3dd6047c10d8 100644
@@ -2065,6 +2065,25 @@ struct device *device_find_child(struct device *parent, void *data,
 }
 EXPORT_SYMBOL_GPL(device_find_child);
 
+static int dev_is_class(struct device *dev, void *class)
+{
+	if (dev->class != NULL && !strcmp(dev->class->name, class))
+		return 1;
+
+	return 0;
+}
+
+struct device *device_find_class(struct device *parent, char *class)
+{
+	if (dev_is_class(parent, class)) {
+		get_device(parent);
+		return parent;
+	}
+
+	return device_find_child(parent, class, dev_is_class);
+}
+EXPORT_SYMBOL_GPL(device_find_class);
+
 int __init devices_init(void)
 {
 	devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
include/linux/device.h +1 -0
index 491b4c0ca633..8d37f5ecb972 100644
@@ -1120,6 +1120,7 @@ extern int device_for_each_child_reverse(struct device *dev, void *data,
 		     int (*fn)(struct device *dev, void *data));
 extern struct device *device_find_child(struct device *dev, void *data,
 				int (*match)(struct device *dev, void *data));
+extern struct device *device_find_class(struct device *parent, char *class);
 extern int device_rename(struct device *dev, const char *new_name);
 extern int device_move(struct device *dev, struct device *new_parent,
 		       enum dpm_order dpm_order);
Signature · 1 line
2.9.3
maintainer
#6 lore raw

Re: [PATCH net-next v2 05/10] drivers: base: Add device_find_class()

From: Florian Fainelli <[email protected]>
Date: Wed, 11 Jan 2017 19:41:16 -0800

Quoted 15 lines

Add a helper function to lookup a device reference given a class name. This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and make it more generic.

---
 drivers/base/core.c    | 19 +++++++++++++++++++
 include/linux/device.h |  1 +
 2 files changed, 20 insertions(+)
drivers/base/core.c +0 -0
index 020ea7f05520..3dd6047c10d8 100644

drivers/base/core.c struct device *device_find_child(struct device *parent, void *data, · line 2068

Quoted 4 lines
drivers/base/core.c +1 -0
@@ -2065,6 +2065,25 @@ struct device *device_find_child(struct device *parent, void *data,
 }
 EXPORT_SYMBOL_GPL(device_find_child);
 
+static int dev_is_class(struct device *dev, void *class)

I know you are just moving code, but this class argumnet is a string and thus should be "char *" or even "const char *".

#7 lore raw

Re: [PATCH net-next v2 05/10] drivers: base: Add device_find_class()

Quoted 21 lines · David Miller

From: Florian Fainelli <[email protected]>
Date: Wed, 11 Jan 2017 19:41:16 -0800

Quoted 18 lines

Add a helper function to lookup a device reference given a class name. This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and make it more generic.

---
 drivers/base/core.c    | 19 +++++++++++++++++++
 include/linux/device.h |  1 +
 2 files changed, 20 insertions(+)
drivers/base/core.c +0 -0
index 020ea7f05520..3dd6047c10d8 100644
@@ -2065,6 +2065,25 @@ struct device *device_find_child(struct device *parent, void *data,
 }
 EXPORT_SYMBOL_GPL(device_find_child);
 
Quoted 4 lines

drivers/base/core.c struct device *device_find_child(struct device *parent, void *data, · line 2068

Quoted 1 line
drivers/base/core.c +1 -0
+static int dev_is_class(struct device *dev, void *class)

I know you are just moving code, but this class argumnet is a string and thus should be "char *" or even "const char *".

Well, this is really so that we don't need to cast the arguments passed to device_find_child(), which takes a void *data as well. If we made that a const char *class, we'd get warnings that look like these:

drivers/base/core.c: In function 'device_find_class':
drivers/base/core.c:2083:2: warning: passing argument 2 of 'device_find_child' discards 'const' qualifier from pointer target type [enabled by default]
return device_find_child(parent, class, dev_is_class);
^
drivers/base/core.c:2050:16: note: expected 'void *' but argument is of type 'const char *'
struct device *device_find_child(struct device *parent, void *data,

                ^

drivers/base/core.c:2083:2: warning: passing argument 3 of 'device_find_child' from incompatible pointer type [enabled by default]
return device_find_child(parent, class, dev_is_class);
^
drivers/base/core.c:2050:16: note: expected 'int (*)(struct device *, void *)' but argument is of type 'int (*)(struct device *, const char *)'
struct device *device_find_child(struct device *parent, void *data,

                ^
Signature · 1 line
Florian
maintainer
#8 lore raw

Re: [PATCH net-next v2 05/10] drivers: base: Add device_find_class()

From: Florian Fainelli <[email protected]>
Date: Thu, 12 Jan 2017 14:50:39 -0800

Quoted 2 lines

Well, this is really so that we don't need to cast the arguments passed to device_find_child(), which takes a void *data as well.

Aha, I didn't catch that, my bad.

#9 lore raw

RE: [PATCH net-next v2 05/10] drivers: base: Add device_find_class()

In reply to Florian Fainelli

From: Florian Fainelli

Quoted 8 lines

Sent: 12 January 2017 22:51

Quoted 6 lines · David Miller

From: Florian Fainelli <[email protected]>
Date: Wed, 11 Jan 2017 19:41:16 -0800

Quoted 3 lines

Add a helper function to lookup a device reference given a class name. This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and make it more generic.

...

Quoted 18 lines
Quoted 4 lines
Quoted 1 line

+static int dev_is_class(struct device *dev, void *class)

I know you are just moving code, but this class argumnet is a string and thus should be "char *" or even "const char *".

Well, this is really so that we don't need to cast the arguments passed to device_find_child(), which takes a void *data as well. If we made that a const char *class, we'd get warnings that look like these:

drivers/base/core.c: In function 'device_find_class':
drivers/base/core.c:2083:2: warning: passing argument 2 of 'device_find_child' discards 'const' qualifier from pointer target type [enabled by default]
return device_find_child(parent, class, dev_is_class);
^
drivers/base/core.c:2050:16: note: expected 'void *' but argument is of type 'const char *'
struct device *device_find_child(struct device *parent, void *data,

Quoted 1 line
                ^

...

Maybe device_find_child() needs changing to take 'const void *' ?

David

#10 lore raw

Re: [PATCH net-next v2 05/10] drivers: base: Add device_find_class()

Quoted 29 lines · David Laight

From: Florian Fainelli

Quoted 8 lines

Sent: 12 January 2017 22:51

Quoted 6 lines · David Miller

From: Florian Fainelli <[email protected]>
Date: Wed, 11 Jan 2017 19:41:16 -0800

Quoted 3 lines

Add a helper function to lookup a device reference given a class name. This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and make it more generic.

...

Quoted 18 lines
Quoted 4 lines
Quoted 1 line

+static int dev_is_class(struct device *dev, void *class)

I know you are just moving code, but this class argumnet is a string and thus should be "char *" or even "const char *".

Well, this is really so that we don't need to cast the arguments passed to device_find_child(), which takes a void *data as well. If we made that a const char *class, we'd get warnings that look like these:

drivers/base/core.c: In function 'device_find_class':
drivers/base/core.c:2083:2: warning: passing argument 2 of 'device_find_child' discards 'const' qualifier from pointer target type [enabled by default]
return device_find_child(parent, class, dev_is_class);
^
drivers/base/core.c:2050:16: note: expected 'void *' but argument is of type 'const char *'
struct device *device_find_child(struct device *parent, void *data,

Quoted 1 line
                ^
Quoted 3 lines

...

Maybe device_find_child() needs changing to take 'const void *' ?

As a separate patch set, sure, I will add that to my TODO. Thanks!

Signature · 1 line
Florian
#11 lore raw

PATCH v2 6/10 net: dsa: Migrate to device_find_class()

In reply to Florian Fainelli

Now that the base device driver code provides an identical implementation of dev_find_class() utilize device_find_class() instead of our own version of it.

---
 net/dsa/dsa.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
net/dsa/dsa.c +2 -20
index 2306d1b87c83..77fa4c4f5828 100644
@@ -455,29 +455,11 @@ EXPORT_SYMBOL_GPL(dsa_switch_resume);
 #endif
 
 /* platform driver init and cleanup *****************************************/
-static int dev_is_class(struct device *dev, void *class)
-{
-	if (dev->class != NULL && !strcmp(dev->class->name, class))
-		return 1;
-
-	return 0;
-}
-
-static struct device *dev_find_class(struct device *parent, char *class)
-{
-	if (dev_is_class(parent, class)) {
-		get_device(parent);
-		return parent;
-	}
-
-	return device_find_child(parent, class, dev_is_class);
-}
-
 struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev)
 {
 	struct device *d;
 
-	d = dev_find_class(dev, "mdio_bus");
+	d = device_find_class(dev, "mdio_bus");
 	if (d != NULL) {
 		struct mii_bus *bus;
 
@@ -495,7 +477,7 @@ static struct net_device *dev_to_net_device(struct device *dev)
 {
 	struct device *d;
 
-	d = dev_find_class(dev, "net");
+	d = device_find_class(dev, "net");
 	if (d != NULL) {
 		struct net_device *nd;
 
Signature · 1 line
2.9.3
#12 lore raw

PATCH v2 7/10 net: Relocate dev_to_net_device() into core

In reply to Florian Fainelli

dev_to_net_device() is moved from net/dsa/dsa.c to net/core/dev.c since it going to be used by net/dsa/dsa2.c and the namespace of the function justifies making it available to other users potentially.

---
 include/linux/netdevice.h |  2 ++
 net/core/dev.c            | 19 +++++++++++++++++++
 net/dsa/dsa.c             | 18 ------------------
 3 files changed, 21 insertions(+), 18 deletions(-)
include/linux/netdevice.h +2 -0
index ebd9e2c12f44..d532c070163f 100644
@@ -4378,4 +4378,6 @@ do {								\
 #define PTYPE_HASH_SIZE	(16)
 #define PTYPE_HASH_MASK	(PTYPE_HASH_SIZE - 1)
 
+struct net_device *dev_to_net_device(struct device *dev);
+
 #endif	/* _LINUX_NETDEVICE_H */
net/core/dev.c +19 -0
index e98cc06d2577..643e4a4491c6 100644
@@ -8150,6 +8150,25 @@ const char *netdev_drivername(const struct net_device *dev)
 	return empty;
 }
 
+struct net_device *dev_to_net_device(struct device *dev)
+{
+	struct device *d;
+
+	d = device_find_class(dev, "net");
+	if (d) {
+		struct net_device *nd;
+
+		nd = to_net_dev(d);
+		dev_hold(nd);
+		put_device(d);
+
+		return nd;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(dev_to_net_device);
+
 static void __netdev_printk(const char *level, const struct net_device *dev,
 			    struct va_format *vaf)
 {
net/dsa/dsa.c +0 -18
index 77fa4c4f5828..6c264f92fec5 100644
@@ -473,24 +473,6 @@ struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(dsa_host_dev_to_mii_bus);
 
-static struct net_device *dev_to_net_device(struct device *dev)
-{
-	struct device *d;
-
-	d = device_find_class(dev, "net");
-	if (d != NULL) {
-		struct net_device *nd;
-
-		nd = to_net_dev(d);
-		dev_hold(nd);
-		put_device(d);
-
-		return nd;
-	}
-
-	return NULL;
-}
-
 #ifdef CONFIG_OF
 static int dsa_of_setup_routing_table(struct dsa_platform_data *pd,
 					struct dsa_chip_data *cd,
Signature · 1 line
2.9.3
#13 lore raw

PATCH v2 8/10 net: dsa: Add support for platform data

In reply to Florian Fainelli

Allow drivers to use the new DSA API with platform data. Most of the code in net/dsa/dsa2.c does not rely so much on device_nodes and can get the same information from platform_data instead.

We purposely do not support distributed configurations with platform data, so drivers should be providing a pointer to a 'struct dsa_chip_data' structure if they wish to communicate per-port layout.

Multiple CPUs port could potentially be supported and dsa_chip_data is extended to receive up to one reference to an upstream network device per port described by a dsa_chip_data structure.

---
 include/net/dsa.h |  6 ++++
 net/dsa/dsa2.c    | 95 ++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 83 insertions(+), 18 deletions(-)
include/net/dsa.h +6 -0
index 16a502a6c26a..491008792e4d 100644
@@ -42,6 +42,11 @@ struct dsa_chip_data {
 	struct device	*host_dev;
 	int		sw_addr;
 
+	/*
+	 * Reference to network devices
+	 */
+	struct device	*netdev[DSA_MAX_PORTS];
+
 	/* set to size of eeprom if supported by the switch */
 	int		eeprom_len;
 
@@ -140,6 +145,7 @@ struct dsa_switch_tree {
 };
 
 struct dsa_port {
+	const char		*name;
 	struct net_device	*netdev;
 	struct device_node	*dn;
 	unsigned int		ageing_time;
net/dsa/dsa2.c +77 -18

156 lines not on this page · raw message

Signature · 1 line
2.9.3
maintainer
#14 lore raw

Re: [PATCH net-next v2 08/10] net: dsa: Add support for platform data

net/dsa/dsa2.c static void dsa_dst_del_ds(struct dsa_switch_tree *dst, · line 85

Quoted 10 lines

index cd91070b5467..d326fc4afad7 100644

net/dsa/dsa2.c +1 -1
@@ -81,17 +81,23 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
 
 static bool dsa_port_is_valid(struct dsa_port *port)
 {
-	return !!port->dn;
+	return !!(port->dn || port->name);
 }

Does this clash with Viviens recent change to make names optional and have the kernel assign it?

I suppose you could use an name of "eth%d"? Is it worth adding a comment to the platform data structure?

Andrew

#15 lore raw

Re: [PATCH net-next v2 08/10] net: dsa: Add support for platform data

Quoted 5 lines · Andrew Lunn
Quoted 5 lines

index cd91070b5467..d326fc4afad7 100644

net/dsa/dsa2.c +0 -0
@@ -81,17 +81,23 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
 
Quoted 8 lines

net/dsa/dsa2.c static void dsa_dst_del_ds(struct dsa_switch_tree *dst, · line 85

Quoted 5 lines
net/dsa/dsa2.c +1 -1
 static bool dsa_port_is_valid(struct dsa_port *port)
 {
-	return !!port->dn;
+	return !!(port->dn || port->name);
 }

Does this clash with Viviens recent change to make names optional and have the kernel assign it?

So there were two ways to look at this, one was that could check here that ds->pd is assigned and port->name is assigned, which means that platform data has to provide valid port name. We can also eliminate this check entirely because we now support NULL names just fines.

Quoted 3 lines

I suppose you could use an name of "eth%d"? Is it worth adding a comment to the platform data structure?

Humm, that could be done, maybe for simplicity we can just let net/dsa/dsa2.c assign names either based on what platform data provided, or by falling back to eth%d.

Thanks!

Signature · 1 line
Florian
#16 lore raw

Re: [PATCH net-next v2 08/10] net: dsa: Add support for platform data

Quoted 15 lines · Florian Fainelli
Quoted 5 lines · Andrew Lunn
Quoted 5 lines

index cd91070b5467..d326fc4afad7 100644

net/dsa/dsa2.c +0 -0
@@ -81,17 +81,23 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
 
Quoted 8 lines

net/dsa/dsa2.c static void dsa_dst_del_ds(struct dsa_switch_tree *dst, · line 85

Quoted 5 lines
net/dsa/dsa2.c +1 -1
 static bool dsa_port_is_valid(struct dsa_port *port)
 {
-	return !!port->dn;
+	return !!(port->dn || port->name);
 }

Does this clash with Viviens recent change to make names optional and have the kernel assign it?

Quoted 4 lines

So there were two ways to look at this, one was that could check here that ds->pd is assigned and port->name is assigned, which means that platform data has to provide valid port name. We can also eliminate this check entirely because we now support NULL names just fines.

Considering that the comment above struct dsa_chip_data::port_names in net/dsa/dsa.h is pretty clear about the port_names usage, I am tempted to keep the code as-is since without a name, for platform data, we would not have a way to tell if a port is disabled or not.

Does that work for you?

Signature · 1 line
Florian
maintainer
#17 lore raw

Re: [PATCH net-next v2 08/10] net: dsa: Add support for platform data

In reply to Florian Fainelli
Quoted 22 lines

static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev) {

net/dsa/dsa2.c +7 -6
+	struct dsa_chip_data *pdata = dev->platform_data;
 	struct device_node *np = dev->of_node;
 	struct dsa_switch_tree *dst;
 	struct device_node *ports;
 	u32 tree, index;
 	int i, err;
 
-	err = dsa_parse_member_dn(np, &tree, &index);
-	if (err)
-		return err;
+	if (np) {
+		err = dsa_parse_member_dn(np, &tree, &index);
+		if (err)
+			return err;
 
-	ports = dsa_get_ports(ds, np);
-	if (IS_ERR(ports))
-		return PTR_ERR(ports);
+		ports = dsa_get_ports(ds, np);
+		if (IS_ERR(ports))

net/dsa/dsa2.c static struct device_node *dsa_get_ports(struct dsa_switch *ds, · line 656

Quoted 10 lines
net/dsa/dsa2.c +6 -3
+			return PTR_ERR(ports);
 
-	err = dsa_parse_ports_dn(ports, ds);
-	if (err)
-		return err;
+		err = dsa_parse_ports_dn(ports, ds);
+		if (err)
+			return err;
+	} else {
+		err = dsa_parse_member(pdata, &tree, &index);

Hi Florian

Maybe it is hiding, but i don't see anywhere you check that pdata != NULL.

At least for x86 platforms, i don't expect we are booting using platform data like ARM systems used to do. I think it is more likely a glue module will be loaded. It looks up the MDIO bus and appends a platform data to an MDIO device. The switch driver then needs to load and use the platform data. But if things happen in a different order, it could be the switch driver probes before the glue driver, meaning pdata is NULL.

Do we even want to return -EPROBE_DEFERED?

Andrew

#18 lore raw

Re: [PATCH net-next v2 08/10] net: dsa: Add support for platform data

Quoted 24 lines · Andrew Lunn
Quoted 24 lines

static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev) {

net/dsa/dsa2.c +8 -6
+	struct dsa_chip_data *pdata = dev->platform_data;
 	struct device_node *np = dev->of_node;
 	struct dsa_switch_tree *dst;
 	struct device_node *ports;
 	u32 tree, index;
 	int i, err;
 
-	err = dsa_parse_member_dn(np, &tree, &index);
-	if (err)
-		return err;
+	if (np) {
+		err = dsa_parse_member_dn(np, &tree, &index);
+		if (err)
+			return err;
 
-	ports = dsa_get_ports(ds, np);
-	if (IS_ERR(ports))
-		return PTR_ERR(ports);
+		ports = dsa_get_ports(ds, np);
+		if (IS_ERR(ports))
+			return PTR_ERR(ports);
Quoted 9 lines

net/dsa/dsa2.c static struct device_node *dsa_get_ports(struct dsa_switch *ds, · line 656

Quoted 8 lines
net/dsa/dsa2.c +5 -3
-	err = dsa_parse_ports_dn(ports, ds);
-	if (err)
-		return err;
+		err = dsa_parse_ports_dn(ports, ds);
+		if (err)
+			return err;
+	} else {
+		err = dsa_parse_member(pdata, &tree, &index);

Hello Andrew,

Quoted 4 lines

Hi Florian

Maybe it is hiding, but i don't see anywhere you check that pdata != NULL.

You are right, there is not such a check, it should probably be added early on.

Quoted 8 lines

At least for x86 platforms, i don't expect we are booting using platform data like ARM systems used to do. I think it is more likely a glue module will be loaded. It looks up the MDIO bus and appends a platform data to an MDIO device. The switch driver then needs to load and use the platform data. But if things happen in a different order, it could be the switch driver probes before the glue driver, meaning pdata is NULL.

That's very valid, I will fix this, thanks!

Quoted 2 lines

Do we even want to return -EPROBE_DEFERED?

I was trying to exercise that code path a little bit, but could not quite make sense of what I was seeing, let me try again with more tracing.

Signature · 1 line
Florian
#19 lore raw

PATCH v2 9/10 net: phy: Allow pre-declaration of MDIO devices

In reply to Florian Fainelli

Allow board support code to collect pre-declarations for MDIO devices by registering them with mdiobus_register_board_info(). SPI and I2C buses have a similar feature, we were missing this for MDIO devices, but this is particularly useful for e.g: MDIO-connected switches which need to provide their port layout (often board-specific) to a MDIO Ethernet switch driver.

---
 drivers/net/phy/Makefile         |  3 +-
 drivers/net/phy/mdio-boardinfo.c | 86 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/mdio-boardinfo.h | 19 +++++++++
 drivers/net/phy/mdio_bus.c       |  5 +++
 drivers/net/phy/mdio_device.c    | 11 +++++
 include/linux/mdio.h             |  3 ++
 include/linux/mod_devicetable.h  |  1 +
 include/linux/phy.h              | 19 +++++++++
 8 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/phy/mdio-boardinfo.c
 create mode 100644 drivers/net/phy/mdio-boardinfo.h
drivers/net/phy/Makefile +2 -1
index 356859ac7c18..407b0b601ea8 100644
@@ -1,6 +1,7 @@
 # Makefile for Linux PHY drivers and MDIO bus drivers
 
-libphy-y			:= phy.o phy_device.o mdio_bus.o mdio_device.o
+libphy-y			:= phy.o phy_device.o mdio_bus.o mdio_device.o \
+				   mdio-boardinfo.o
 libphy-$(CONFIG_SWPHY)		+= swphy.o
 libphy-$(CONFIG_LED_TRIGGER_PHY)	+= phy_led_triggers.o
 
drivers/net/phy/mdio-boardinfo.c new file +86 -0

86 lines not on this page · raw message

drivers/net/phy/mdio-boardinfo.h new file +19 -0
new file mode 100644
index 000000000000..00f98163e90e
@@ -0,0 +1,19 @@
+/*
+ * mdio-boardinfo.h - board info interface internal to the mdio_bus
+ * component
+ */
+
+#ifndef __MDIO_BOARD_INFO_H
+#define __MDIO_BOARD_INFO_H
+
+#include <linux/phy.h>
+#include <linux/mutex.h>
+
+struct mdio_board_entry {
+	struct list_head	list;
+	struct mdio_board_info	board_info;
+};
+
+void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus);
+
+#endif /* __MDIO_BOARD_INFO_H */
drivers/net/phy/mdio_bus.c +5 -0
index 653d076eafe5..976cb9c4ab01 100644
@@ -41,6 +41,8 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/mdio.h>
 
+#include "mdio-boardinfo.h"
+
 int mdiobus_register_device(struct mdio_device *mdiodev)
 {
 	if (mdiodev->bus->mdio_map[mdiodev->addr])
@@ -343,7 +345,10 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
 		}
 	}
 
+	mdiobus_setup_mdiodev_from_board_info(bus);
+
 	bus->state = MDIOBUS_REGISTERED;
+
 	pr_info("%s: probed\n", bus->name);
 	return 0;
 
drivers/net/phy/mdio_device.c +11 -0
index fc3aaaa36b1d..e24f28924af8 100644
@@ -34,6 +34,17 @@ static void mdio_device_release(struct device *dev)
 	kfree(to_mdio_device(dev));
 }
 
+int mdio_device_bus_match(struct device *dev, struct device_driver *drv)
+{
+	struct mdio_device *mdiodev = to_mdio_device(dev);
+	struct mdio_driver *mdiodrv = to_mdio_driver(drv);
+
+	if (mdiodrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY)
+		return 0;
+
+	return strcmp(mdiodev->modalias, drv->name) == 0;
+}
+
 struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr)
 {
 	struct mdio_device *mdiodev;
include/linux/mdio.h +3 -0
index b6587a4b32e7..00a7f43c1482 100644
@@ -10,6 +10,7 @@
 #define __LINUX_MDIO_H__
 
 #include <uapi/linux/mdio.h>
+#include <linux/mod_devicetable.h>
 
 struct mii_bus;
 
@@ -29,6 +30,7 @@ struct mdio_device {
 
 	const struct dev_pm_ops *pm_ops;
 	struct mii_bus *bus;
+	char modalias[MDIO_NAME_SIZE];
 
 	int (*bus_match)(struct device *dev, struct device_driver *drv);
 	void (*device_free)(struct mdio_device *mdiodev);
@@ -71,6 +73,7 @@ int mdio_device_register(struct mdio_device *mdiodev);
 void mdio_device_remove(struct mdio_device *mdiodev);
 int mdio_driver_register(struct mdio_driver *drv);
 void mdio_driver_unregister(struct mdio_driver *drv);
+int mdio_device_bus_match(struct device *dev, struct device_driver *drv);
 
 static inline bool mdio_phy_id_is_c45(int phy_id)
 {
include/linux/mod_devicetable.h +1 -0
index 8a57f0b1242d..8850fcaf50db 100644
@@ -501,6 +501,7 @@ struct platform_device_id {
 	kernel_ulong_t driver_data;
 };
 
+#define MDIO_NAME_SIZE		32
 #define MDIO_MODULE_PREFIX	"mdio:"
 
 #define MDIO_ID_FMT "%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d"
include/linux/phy.h +19 -0
index f7d95f644eed..7745f7391d3e 100644
@@ -882,6 +882,25 @@ void mdio_bus_exit(void);
 
 extern struct bus_type mdio_bus_type;
 
+struct mdio_board_info {
+	const char	*bus_id;
+	char		modalias[MDIO_NAME_SIZE];
+	int		mdio_addr;
+	const void	*platform_data;
+};
+
+#if IS_ENABLED(CONFIG_PHYLIB)
+int mdiobus_register_board_info(const struct mdio_board_info *info,
+				unsigned int n);
+#else
+static inline int mdiobus_register_board_info(const struct mdio_board_info *i,
+					      unsigned int n)
+{
+	return 0;
+}
+#endif
+
+
 /**
  * module_phy_driver() - Helper macro for registering PHY drivers
  * @__phy_drivers: array of PHY drivers to register
Signature · 1 line
2.9.3
#20 lore raw

PATCH v2 10/10 ARM: orion: Register DSA switch as a MDIO device

In reply to Florian Fainelli

Utilize the ability to pass board specific MDIO bus information towards a particular MDIO device thus allowing us to provide the per-port switch layout to the Marvell 88E6XXX switch driver.

Since we would end-up with conflicting registration paths, do not register the "dsa" platform device anymore.

Note that the MDIO devices registered by code in net/dsa/dsa2.c does not parse a dsa_platform_data, but directly take a dsa_chip_data (specific to a single switch chip), so we update the different call sites to pass this structure down to orion_ge00_switch_init().

---
 arch/arm/mach-orion5x/common.c               |  2 +-
 arch/arm/mach-orion5x/common.h               |  4 ++--
 arch/arm/mach-orion5x/rd88f5181l-fxo-setup.c |  7 +------
 arch/arm/mach-orion5x/rd88f5181l-ge-setup.c  |  7 +------
 arch/arm/mach-orion5x/rd88f6183ap-ge-setup.c |  7 +------
 arch/arm/mach-orion5x/wnr854t-setup.c        |  2 +-
 arch/arm/mach-orion5x/wrt350n-v2-setup.c     |  7 +------
 arch/arm/plat-orion/common.c                 | 25 +++++++++++++++++++------
 arch/arm/plat-orion/include/plat/common.h    |  4 ++--
 9 files changed, 29 insertions(+), 36 deletions(-)
arch/arm/mach-orion5x/common.c +1 -1
index 04910764c385..83a7ec4c16d0 100644
@@ -105,7 +105,7 @@ void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data)
 /*****************************************************************************
  * Ethernet switch
  ****************************************************************************/
-void __init orion5x_eth_switch_init(struct dsa_platform_data *d)
+void __init orion5x_eth_switch_init(struct dsa_chip_data *d)
 {
 	orion_ge00_switch_init(d);
 }
arch/arm/mach-orion5x/common.h +2 -2
index 8a4115bd441d..efeffc6b4ebb 100644
@@ -3,7 +3,7 @@
 
 #include <linux/reboot.h>
 
-struct dsa_platform_data;
+struct dsa_chip_data;
 struct mv643xx_eth_platform_data;
 struct mv_sata_platform_data;
 
@@ -41,7 +41,7 @@ void orion5x_setup_wins(void);
 void orion5x_ehci0_init(void);
 void orion5x_ehci1_init(void);
 void orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data);
-void orion5x_eth_switch_init(struct dsa_platform_data *d);
+void orion5x_eth_switch_init(struct dsa_chip_data *d);
 void orion5x_i2c_init(void);
 void orion5x_sata_init(struct mv_sata_platform_data *sata_data);
 void orion5x_spi_init(void);
arch/arm/mach-orion5x/rd88f5181l-fxo-setup.c +1 -6
index dccadf68ea2b..a3c1336d30c9 100644
@@ -101,11 +101,6 @@ static struct dsa_chip_data rd88f5181l_fxo_switch_chip_data = {
 	.port_names[7]	= "lan3",
 };
 
-static struct dsa_platform_data __initdata rd88f5181l_fxo_switch_plat_data = {
-	.nr_chips	= 1,
-	.chip		= &rd88f5181l_fxo_switch_chip_data,
-};
-
 static void __init rd88f5181l_fxo_init(void)
 {
 	/*
@@ -120,7 +115,7 @@ static void __init rd88f5181l_fxo_init(void)
 	 */
 	orion5x_ehci0_init();
 	orion5x_eth_init(&rd88f5181l_fxo_eth_data);
-	orion5x_eth_switch_init(&rd88f5181l_fxo_switch_plat_data);
+	orion5x_eth_switch_init(&rd88f5181l_fxo_switch_chip_data);
 	orion5x_uart0_init();
 
 	mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
arch/arm/mach-orion5x/rd88f5181l-ge-setup.c +1 -6
index affe5ec825de..252efe29bd1a 100644
@@ -102,11 +102,6 @@ static struct dsa_chip_data rd88f5181l_ge_switch_chip_data = {
 	.port_names[7]	= "lan3",
 };
 
-static struct dsa_platform_data __initdata rd88f5181l_ge_switch_plat_data = {
-	.nr_chips	= 1,
-	.chip		= &rd88f5181l_ge_switch_chip_data,
-};
-
 static struct i2c_board_info __initdata rd88f5181l_ge_i2c_rtc = {
 	I2C_BOARD_INFO("ds1338", 0x68),
 };
@@ -125,7 +120,7 @@ static void __init rd88f5181l_ge_init(void)
 	 */
 	orion5x_ehci0_init();
 	orion5x_eth_init(&rd88f5181l_ge_eth_data);
-	orion5x_eth_switch_init(&rd88f5181l_ge_switch_plat_data);
+	orion5x_eth_switch_init(&rd88f5181l_ge_switch_chip_data);
 	orion5x_i2c_init();
 	orion5x_uart0_init();
 
arch/arm/mach-orion5x/rd88f6183ap-ge-setup.c +1 -6
index 67ee8571b03c..f4f1dbe1d91d 100644
@@ -40,11 +40,6 @@ static struct dsa_chip_data rd88f6183ap_ge_switch_chip_data = {
 	.port_names[5]	= "cpu",
 };
 
-static struct dsa_platform_data __initdata rd88f6183ap_ge_switch_plat_data = {
-	.nr_chips	= 1,
-	.chip		= &rd88f6183ap_ge_switch_chip_data,
-};
-
 static struct mtd_partition rd88f6183ap_ge_partitions[] = {
 	{
 		.name	= "kernel",
@@ -89,7 +84,7 @@ static void __init rd88f6183ap_ge_init(void)
 	 */
 	orion5x_ehci0_init();
 	orion5x_eth_init(&rd88f6183ap_ge_eth_data);
-	orion5x_eth_switch_init(&rd88f6183ap_ge_switch_plat_data);
+	orion5x_eth_switch_init(&rd88f6183ap_ge_switch_chip_data);
 	spi_register_board_info(rd88f6183ap_ge_spi_slave_info,
 				ARRAY_SIZE(rd88f6183ap_ge_spi_slave_info));
 	orion5x_spi_init();
arch/arm/mach-orion5x/wnr854t-setup.c +1 -1
index 4dbcdbe1de7c..ac3376fc269f 100644
@@ -124,7 +124,7 @@ static void __init wnr854t_init(void)
 	 * Configure peripherals.
 	 */
 	orion5x_eth_init(&wnr854t_eth_data);
-	orion5x_eth_switch_init(&wnr854t_switch_plat_data);
+	orion5x_eth_switch_init(&wnr854t_switch_chip_data);
 	orion5x_uart0_init();
 
 	mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
arch/arm/mach-orion5x/wrt350n-v2-setup.c +1 -6
index a6a8c4648d74..9250bb2e429c 100644
@@ -191,11 +191,6 @@ static struct dsa_chip_data wrt350n_v2_switch_chip_data = {
 	.port_names[7]	= "lan4",
 };
 
-static struct dsa_platform_data __initdata wrt350n_v2_switch_plat_data = {
-	.nr_chips	= 1,
-	.chip		= &wrt350n_v2_switch_chip_data,
-};
-
 static void __init wrt350n_v2_init(void)
 {
 	/*
@@ -210,7 +205,7 @@ static void __init wrt350n_v2_init(void)
 	 */
 	orion5x_ehci0_init();
 	orion5x_eth_init(&wrt350n_v2_eth_data);
-	orion5x_eth_switch_init(&wrt350n_v2_switch_plat_data);
+	orion5x_eth_switch_init(&wrt350n_v2_switch_chip_data);
 	orion5x_uart0_init();
 
 	mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
arch/arm/plat-orion/common.c +19 -6
index 272f49b2c68f..989f3ccfcdc7 100644
@@ -22,6 +22,7 @@
 #include <linux/platform_data/dma-mv_xor.h>
 #include <linux/platform_data/usb-ehci-orion.h>
 #include <plat/common.h>
+#include <linux/phy.h>
 
 /* Create a clkdev entry for a given device/clk */
 void __init orion_clkdev_add(const char *con_id, const char *dev_id,
@@ -470,15 +471,27 @@ void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
 /*****************************************************************************
  * Ethernet switch
  ****************************************************************************/
-void __init orion_ge00_switch_init(struct dsa_platform_data *d)
+static __initdata const char *orion_ge00_mvmdio_bus_name = "orion-mii";
+static __initdata struct mdio_board_info
+		  orion_ge00_switch_board_info;
+
+void __init orion_ge00_switch_init(struct dsa_chip_data *d)
 {
-	int i;
+	struct mdio_board_info *bd;
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(d->port_names); i++)
+		if (!strcmp(d->port_names[i], "cpu"))
+			break;
 
-	d->netdev = &orion_ge00.dev;
-	for (i = 0; i < d->nr_chips; i++)
-		d->chip[i].host_dev = &orion_ge_mvmdio.dev;
+	bd = &orion_ge00_switch_board_info;
+	bd->bus_id = orion_ge00_mvmdio_bus_name;
+	bd->mdio_addr = d->sw_addr;
+	d->netdev[i] = &orion_ge00.dev;
+	strcpy(bd->modalias, "mv88e6085");
+	bd->platform_data = d;
 
-	platform_device_register_data(NULL, "dsa", 0, d, sizeof(d));
+	mdiobus_register_board_info(&orion_ge00_switch_board_info, 1);
 }
 
 /*****************************************************************************
arch/arm/plat-orion/include/plat/common.h +2 -2
index 9347f3c58a6d..3647d3b33c20 100644
@@ -12,7 +12,7 @@
 #include <linux/mv643xx_eth.h>
 #include <linux/platform_data/usb-ehci-orion.h>
 
-struct dsa_platform_data;
+struct dsa_chip_data;
 struct mv_sata_platform_data;
 
 void __init orion_uart0_init(void __iomem *membase,
@@ -57,7 +57,7 @@ void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
 			    unsigned long mapbase,
 			    unsigned long irq);
 
-void __init orion_ge00_switch_init(struct dsa_platform_data *d);
+void __init orion_ge00_switch_init(struct dsa_chip_data *d);
 
 void __init orion_i2c_init(unsigned long mapbase,
 			   unsigned long irq,
Signature · 1 line
2.9.3
Tested-by on the v2 series
#21 lore raw
In reply to Florian Fainelli

Hi Florian,

Quoted 14 lines · Florian Fainelli

Hi all,

This is not exactly new, and was sent before, although back then, I did not have an user of the pre-declared MDIO board information, but now we do. Note that I have additional changes queued up to have b53 register platform data for MIPS bcm47xx and bcm63xx.

Yes I know that we should have the Orion platforms eventually be converted to Device Tree, but until that happens, I don't want any remaining users of the old "dsa" platform device (hence the previous DTS submissions for ARM/mvebu) and, there will be platforms out there that most likely won't never see DT coming their way (BCM47xx is almost 100% sure, BCM63xx maybe not in a distant future).

Quoted 6 lines

We would probably want the whole series to be merged via David Miller's tree to simplify things.

Greg, can you Ack/Nack patch 5 since it touched the core LDD?

Thanks!

I've tested this patchset on my mv88e6xxx (DTS) boards to make sure nothing was broken, since it touches the driver. Looks good!

Thanks,

Vivien