Commit b95db668 authored by David S. Miller's avatar David S. Miller

Merge branch 'dsa2-pdata-prepatory-patches'

Florian Fainelli says:

====================
net: dsa: Preparatory patches

This patch series extracts the 4 patches of the larger: net: dsa: Support for
pdata in dsa2 while we wait for feedback from Greg KH on the device references.

Changes in v2:

- rebased properly after the multi-MDIO bus support added to mv88e6xxx
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 80c8eae6 bc1727d2
...@@ -1894,7 +1894,7 @@ int b53_switch_register(struct b53_device *dev) ...@@ -1894,7 +1894,7 @@ int b53_switch_register(struct b53_device *dev)
pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev); 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); EXPORT_SYMBOL(b53_switch_register);
......
...@@ -4356,8 +4356,7 @@ static struct dsa_switch_driver mv88e6xxx_switch_drv = { ...@@ -4356,8 +4356,7 @@ static struct dsa_switch_driver mv88e6xxx_switch_drv = {
.ops = &mv88e6xxx_switch_ops, .ops = &mv88e6xxx_switch_ops,
}; };
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip, static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
struct device_node *np)
{ {
struct device *dev = chip->dev; struct device *dev = chip->dev;
struct dsa_switch *ds; struct dsa_switch *ds;
...@@ -4372,7 +4371,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip, ...@@ -4372,7 +4371,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
dev_set_drvdata(dev, ds); 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) static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
...@@ -4456,7 +4455,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) ...@@ -4456,7 +4455,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
if (err) if (err)
goto out_g2_irq; goto out_g2_irq;
err = mv88e6xxx_register_switch(chip, np); err = mv88e6xxx_register_switch(chip);
if (err) if (err)
goto out_mdio; goto out_mdio;
......
...@@ -964,7 +964,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev) ...@@ -964,7 +964,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
mutex_init(&priv->reg_mutex); mutex_init(&priv->reg_mutex);
dev_set_drvdata(&mdiodev->dev, priv); 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 static void
......
...@@ -387,7 +387,7 @@ static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst) ...@@ -387,7 +387,7 @@ static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
} }
void dsa_unregister_switch(struct dsa_switch *ds); 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 #ifdef CONFIG_PM_SLEEP
int dsa_switch_suspend(struct dsa_switch *ds); int dsa_switch_suspend(struct dsa_switch *ds);
int dsa_switch_resume(struct dsa_switch *ds); int dsa_switch_resume(struct dsa_switch *ds);
......
...@@ -110,8 +110,9 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr, ...@@ -110,8 +110,9 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
/* basic switch operations **************************************************/ /* basic switch operations **************************************************/
int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, 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; struct phy_device *phydev;
int ret, mode; int ret, mode;
...@@ -141,15 +142,15 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, ...@@ -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) 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; int ret, port;
for (port = 0; port < DSA_MAX_PORTS; port++) { for (port = 0; port < DSA_MAX_PORTS; port++) {
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
continue; continue;
port_dn = ds->ports[port].dn; dport = &ds->ports[port];
ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port); ret = dsa_cpu_dsa_setup(ds, dev, dport, port);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -364,8 +365,10 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index, ...@@ -364,8 +365,10 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
return ds; 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)) if (of_phy_is_fixed_link(port_dn))
of_phy_deregister_fixed_link(port_dn); of_phy_deregister_fixed_link(port_dn);
} }
...@@ -389,7 +392,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds) ...@@ -389,7 +392,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
for (port = 0; port < DSA_MAX_PORTS; port++) { for (port = 0; port < DSA_MAX_PORTS; port++) {
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))) if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
continue; 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 */ /* Clearing a bit which is not set does no harm */
ds->cpu_port_mask |= ~(1 << port); ds->cpu_port_mask |= ~(1 << port);
......
...@@ -78,18 +78,23 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst, ...@@ -78,18 +78,23 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
kref_put(&dst->refcount, dsa_free_dst); kref_put(&dst->refcount, dsa_free_dst);
} }
static bool dsa_port_is_dsa(struct device_node *port) static bool dsa_port_is_valid(struct dsa_port *port)
{ {
return !!of_parse_phandle(port, "link", 0); return !!port->dn;
} }
static bool dsa_port_is_cpu(struct device_node *port) static bool dsa_port_is_dsa(struct dsa_port *port)
{ {
return !!of_parse_phandle(port, "ethernet", 0); return !!of_parse_phandle(port->dn, "link", 0);
} }
static bool dsa_ds_find_port(struct dsa_switch *ds, static bool dsa_port_is_cpu(struct dsa_port *port)
struct device_node *port) {
return !!of_parse_phandle(port->dn, "ethernet", 0);
}
static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
struct device_node *port)
{ {
u32 index; u32 index;
...@@ -99,8 +104,8 @@ static bool dsa_ds_find_port(struct dsa_switch *ds, ...@@ -99,8 +104,8 @@ static bool dsa_ds_find_port(struct dsa_switch *ds,
return false; return false;
} }
static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst, static struct dsa_switch *dsa_dst_find_port_dn(struct dsa_switch_tree *dst,
struct device_node *port) struct device_node *port)
{ {
struct dsa_switch *ds; struct dsa_switch *ds;
u32 index; u32 index;
...@@ -110,7 +115,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst, ...@@ -110,7 +115,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
if (!ds) if (!ds)
continue; continue;
if (dsa_ds_find_port(ds, port)) if (dsa_ds_find_port_dn(ds, port))
return ds; return ds;
} }
...@@ -119,7 +124,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst, ...@@ -119,7 +124,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
static int dsa_port_complete(struct dsa_switch_tree *dst, static int dsa_port_complete(struct dsa_switch_tree *dst,
struct dsa_switch *src_ds, struct dsa_switch *src_ds,
struct device_node *port, struct dsa_port *port,
u32 src_port) u32 src_port)
{ {
struct device_node *link; struct device_node *link;
...@@ -127,11 +132,11 @@ static int dsa_port_complete(struct dsa_switch_tree *dst, ...@@ -127,11 +132,11 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
struct dsa_switch *dst_ds; struct dsa_switch *dst_ds;
for (index = 0;; index++) { for (index = 0;; index++) {
link = of_parse_phandle(port, "link", index); link = of_parse_phandle(port->dn, "link", index);
if (!link) if (!link)
break; break;
dst_ds = dsa_dst_find_port(dst, link); dst_ds = dsa_dst_find_port_dn(dst, link);
of_node_put(link); of_node_put(link);
if (!dst_ds) if (!dst_ds)
...@@ -150,13 +155,13 @@ static int dsa_port_complete(struct dsa_switch_tree *dst, ...@@ -150,13 +155,13 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
*/ */
static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds) static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
{ {
struct device_node *port; struct dsa_port *port;
u32 index; u32 index;
int err; int err;
for (index = 0; index < DSA_MAX_PORTS; index++) { for (index = 0; index < DSA_MAX_PORTS; index++) {
port = ds->ports[index].dn; port = &ds->ports[index];
if (!port) if (!dsa_port_is_valid(port))
continue; continue;
if (!dsa_port_is_dsa(port)) if (!dsa_port_is_dsa(port))
...@@ -196,7 +201,7 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst) ...@@ -196,7 +201,7 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst)
return 0; return 0;
} }
static int dsa_dsa_port_apply(struct device_node *port, u32 index, static int dsa_dsa_port_apply(struct dsa_port *port, u32 index,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
int err; int err;
...@@ -211,13 +216,13 @@ static int dsa_dsa_port_apply(struct device_node *port, u32 index, ...@@ -211,13 +216,13 @@ static int dsa_dsa_port_apply(struct device_node *port, u32 index,
return 0; return 0;
} }
static void dsa_dsa_port_unapply(struct device_node *port, u32 index, static void dsa_dsa_port_unapply(struct dsa_port *port, u32 index,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
dsa_cpu_dsa_destroy(port); dsa_cpu_dsa_destroy(port);
} }
static int dsa_cpu_port_apply(struct device_node *port, u32 index, static int dsa_cpu_port_apply(struct dsa_port *port, u32 index,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
int err; int err;
...@@ -234,7 +239,7 @@ static int dsa_cpu_port_apply(struct device_node *port, u32 index, ...@@ -234,7 +239,7 @@ static int dsa_cpu_port_apply(struct device_node *port, u32 index,
return 0; return 0;
} }
static void dsa_cpu_port_unapply(struct device_node *port, u32 index, static void dsa_cpu_port_unapply(struct dsa_port *port, u32 index,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
dsa_cpu_dsa_destroy(port); dsa_cpu_dsa_destroy(port);
...@@ -242,13 +247,13 @@ static void dsa_cpu_port_unapply(struct device_node *port, u32 index, ...@@ -242,13 +247,13 @@ static void dsa_cpu_port_unapply(struct device_node *port, u32 index,
} }
static int dsa_user_port_apply(struct device_node *port, u32 index, static int dsa_user_port_apply(struct dsa_port *port, u32 index,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
const char *name; const char *name;
int err; int err;
name = of_get_property(port, "label", NULL); name = of_get_property(port->dn, "label", NULL);
if (!name) if (!name)
name = "eth%d"; name = "eth%d";
...@@ -262,7 +267,7 @@ static int dsa_user_port_apply(struct device_node *port, u32 index, ...@@ -262,7 +267,7 @@ static int dsa_user_port_apply(struct device_node *port, u32 index,
return 0; return 0;
} }
static void dsa_user_port_unapply(struct device_node *port, u32 index, static void dsa_user_port_unapply(struct dsa_port *port, u32 index,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
if (ds->ports[index].netdev) { if (ds->ports[index].netdev) {
...@@ -274,7 +279,7 @@ static void dsa_user_port_unapply(struct device_node *port, u32 index, ...@@ -274,7 +279,7 @@ static void dsa_user_port_unapply(struct device_node *port, u32 index,
static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
{ {
struct device_node *port; struct dsa_port *port;
u32 index; u32 index;
int err; int err;
...@@ -308,8 +313,8 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -308,8 +313,8 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
} }
for (index = 0; index < DSA_MAX_PORTS; index++) { for (index = 0; index < DSA_MAX_PORTS; index++) {
port = ds->ports[index].dn; port = &ds->ports[index];
if (!port) if (!dsa_port_is_valid(port))
continue; continue;
if (dsa_port_is_dsa(port)) { if (dsa_port_is_dsa(port)) {
...@@ -336,12 +341,12 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -336,12 +341,12 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds) static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
{ {
struct device_node *port; struct dsa_port *port;
u32 index; u32 index;
for (index = 0; index < DSA_MAX_PORTS; index++) { for (index = 0; index < DSA_MAX_PORTS; index++) {
port = ds->ports[index].dn; port = &ds->ports[index];
if (!port) if (!dsa_port_is_valid(port))
continue; continue;
if (dsa_port_is_dsa(port)) { if (dsa_port_is_dsa(port)) {
...@@ -425,7 +430,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst) ...@@ -425,7 +430,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
dst->applied = false; dst->applied = false;
} }
static int dsa_cpu_parse(struct device_node *port, u32 index, static int dsa_cpu_parse(struct dsa_port *port, u32 index,
struct dsa_switch_tree *dst, struct dsa_switch_tree *dst,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
...@@ -433,7 +438,7 @@ static int dsa_cpu_parse(struct device_node *port, u32 index, ...@@ -433,7 +438,7 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
struct net_device *ethernet_dev; struct net_device *ethernet_dev;
struct device_node *ethernet; struct device_node *ethernet;
ethernet = of_parse_phandle(port, "ethernet", 0); ethernet = of_parse_phandle(port->dn, "ethernet", 0);
if (!ethernet) if (!ethernet)
return -EINVAL; return -EINVAL;
...@@ -466,13 +471,13 @@ static int dsa_cpu_parse(struct device_node *port, u32 index, ...@@ -466,13 +471,13 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
{ {
struct device_node *port; struct dsa_port *port;
u32 index; u32 index;
int err; int err;
for (index = 0; index < DSA_MAX_PORTS; index++) { for (index = 0; index < DSA_MAX_PORTS; index++) {
port = ds->ports[index].dn; port = &ds->ports[index];
if (!port) if (!dsa_port_is_valid(port))
continue; continue;
if (dsa_port_is_cpu(port)) { if (dsa_port_is_cpu(port)) {
...@@ -533,14 +538,14 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds) ...@@ -533,14 +538,14 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
* to have access to a correct value, just like what * to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does. * net/dsa/dsa.c::dsa_switch_setup_one does.
*/ */
if (!dsa_port_is_cpu(port)) if (!dsa_port_is_cpu(&ds->ports[reg]))
ds->enabled_port_mask |= 1 << reg; ds->enabled_port_mask |= 1 << reg;
} }
return 0; 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; int err;
...@@ -578,17 +583,19 @@ static struct device_node *dsa_get_ports(struct dsa_switch *ds, ...@@ -578,17 +583,19 @@ static struct device_node *dsa_get_ports(struct dsa_switch *ds,
return ports; 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 *ports = dsa_get_ports(ds, np); struct device_node *np = dev->of_node;
struct dsa_switch_tree *dst; struct dsa_switch_tree *dst;
struct device_node *ports;
u32 tree, index; u32 tree, index;
int i, err; int i, err;
err = dsa_parse_member(np, &tree, &index); err = dsa_parse_member_dn(np, &tree, &index);
if (err) if (err)
return err; return err;
ports = dsa_get_ports(ds, np);
if (IS_ERR(ports)) if (IS_ERR(ports))
return PTR_ERR(ports); return PTR_ERR(ports);
...@@ -659,12 +666,12 @@ static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np) ...@@ -659,12 +666,12 @@ static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
return err; 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; int err;
mutex_lock(&dsa2_mutex); mutex_lock(&dsa2_mutex);
err = _dsa_register_switch(ds, np); err = _dsa_register_switch(ds, dev);
mutex_unlock(&dsa2_mutex); mutex_unlock(&dsa2_mutex);
return err; return err;
......
...@@ -50,8 +50,8 @@ struct dsa_slave_priv { ...@@ -50,8 +50,8 @@ struct dsa_slave_priv {
/* dsa.c */ /* dsa.c */
int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, 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);
void dsa_cpu_dsa_destroy(struct device_node *port_dn); void dsa_cpu_dsa_destroy(struct dsa_port *dport);
const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol); const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds); int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds);
void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds); void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment