Merge branch 'dsa-cleanups-before-multi-CPU-port'

Florian Fainelli says:

====================
net: dsa: Cleanups before multi-CPU port

This patch series does a bunch of cleanups before we start adding support
for multiple CPU ports.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2017-06-04 20:05:15 -04:00
commit 2d9888c5b2
5 changed files with 66 additions and 75 deletions

View File

@ -254,7 +254,7 @@ struct dsa_switch {
static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
{ {
return ds->dst->cpu_dp == &ds->ports[p]; return !!(ds->cpu_port_mask & (1 << p));
} }
static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)

View File

@ -112,8 +112,9 @@ const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol)
return ops; return ops;
} }
int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds) int dsa_cpu_port_ethtool_setup(struct dsa_port *cpu_dp)
{ {
struct dsa_switch *ds = cpu_dp->ds;
struct net_device *master; struct net_device *master;
struct ethtool_ops *cpu_ops; struct ethtool_ops *cpu_ops;
@ -136,8 +137,9 @@ int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds)
return 0; return 0;
} }
void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds) void dsa_cpu_port_ethtool_restore(struct dsa_port *cpu_dp)
{ {
struct dsa_switch *ds = cpu_dp->ds;
struct net_device *master; struct net_device *master;
master = ds->dst->master_netdev; master = ds->dst->master_netdev;

View File

@ -214,66 +214,59 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst)
return 0; return 0;
} }
static int dsa_dsa_port_apply(struct dsa_port *port, u32 index, static int dsa_dsa_port_apply(struct dsa_port *port)
struct dsa_switch *ds)
{ {
struct dsa_switch *ds = port->ds;
int err; int err;
err = dsa_cpu_dsa_setup(ds, ds->dev, port, index); err = dsa_cpu_dsa_setup(ds, ds->dev, port, port->index);
if (err) { if (err) {
dev_warn(ds->dev, "Failed to setup dsa port %d: %d\n", dev_warn(ds->dev, "Failed to setup dsa port %d: %d\n",
index, err); port->index, err);
return err; return err;
} }
memset(&ds->ports[index].devlink_port, 0, memset(&port->devlink_port, 0, sizeof(port->devlink_port));
sizeof(ds->ports[index].devlink_port));
return devlink_port_register(ds->devlink, return devlink_port_register(ds->devlink, &port->devlink_port,
&ds->ports[index].devlink_port, port->index);
index);
} }
static void dsa_dsa_port_unapply(struct dsa_port *port, u32 index, static void dsa_dsa_port_unapply(struct dsa_port *port)
struct dsa_switch *ds)
{ {
devlink_port_unregister(&ds->ports[index].devlink_port); devlink_port_unregister(&port->devlink_port);
dsa_cpu_dsa_destroy(port); dsa_cpu_dsa_destroy(port);
} }
static int dsa_cpu_port_apply(struct dsa_port *port, u32 index, static int dsa_cpu_port_apply(struct dsa_port *port)
struct dsa_switch *ds)
{ {
struct dsa_switch *ds = port->ds;
int err; int err;
err = dsa_cpu_dsa_setup(ds, ds->dev, port, index); err = dsa_cpu_dsa_setup(ds, ds->dev, port, port->index);
if (err) { if (err) {
dev_warn(ds->dev, "Failed to setup cpu port %d: %d\n", dev_warn(ds->dev, "Failed to setup cpu port %d: %d\n",
index, err); port->index, err);
return err; return err;
} }
ds->cpu_port_mask |= BIT(index); memset(&port->devlink_port, 0, sizeof(port->devlink_port));
err = devlink_port_register(ds->devlink, &port->devlink_port,
memset(&ds->ports[index].devlink_port, 0, port->index);
sizeof(ds->ports[index].devlink_port));
err = devlink_port_register(ds->devlink, &ds->ports[index].devlink_port,
index);
return err; return err;
} }
static void dsa_cpu_port_unapply(struct dsa_port *port, u32 index, static void dsa_cpu_port_unapply(struct dsa_port *port)
struct dsa_switch *ds)
{ {
devlink_port_unregister(&ds->ports[index].devlink_port); devlink_port_unregister(&port->devlink_port);
dsa_cpu_dsa_destroy(port); dsa_cpu_dsa_destroy(port);
ds->cpu_port_mask &= ~BIT(index); port->ds->cpu_port_mask &= ~BIT(port->index);
} }
static int dsa_user_port_apply(struct dsa_port *port, u32 index, static int dsa_user_port_apply(struct dsa_port *port)
struct dsa_switch *ds)
{ {
struct dsa_switch *ds = port->ds;
const char *name = port->name; const char *name = port->name;
int err; int err;
@ -282,35 +275,32 @@ static int dsa_user_port_apply(struct dsa_port *port, u32 index,
if (!name) if (!name)
name = "eth%d"; name = "eth%d";
err = dsa_slave_create(ds, ds->dev, index, name); err = dsa_slave_create(ds, ds->dev, port->index, name);
if (err) { if (err) {
dev_warn(ds->dev, "Failed to create slave %d: %d\n", dev_warn(ds->dev, "Failed to create slave %d: %d\n",
index, err); port->index, err);
ds->ports[index].netdev = NULL; port->netdev = NULL;
return err; return err;
} }
memset(&ds->ports[index].devlink_port, 0, memset(&port->devlink_port, 0, sizeof(port->devlink_port));
sizeof(ds->ports[index].devlink_port)); err = devlink_port_register(ds->devlink, &port->devlink_port,
err = devlink_port_register(ds->devlink, &ds->ports[index].devlink_port, port->index);
index);
if (err) if (err)
return err; return err;
devlink_port_type_eth_set(&ds->ports[index].devlink_port, devlink_port_type_eth_set(&port->devlink_port, port->netdev);
ds->ports[index].netdev);
return 0; return 0;
} }
static void dsa_user_port_unapply(struct dsa_port *port, u32 index, static void dsa_user_port_unapply(struct dsa_port *port)
struct dsa_switch *ds)
{ {
devlink_port_unregister(&ds->ports[index].devlink_port); devlink_port_unregister(&port->devlink_port);
if (ds->ports[index].netdev) { if (port->netdev) {
dsa_slave_destroy(ds->ports[index].netdev); dsa_slave_destroy(port->netdev);
ds->ports[index].netdev = NULL; port->netdev = NULL;
ds->enabled_port_mask &= ~(1 << index); port->ds->enabled_port_mask &= ~(1 << port->index);
} }
} }
@ -370,20 +360,20 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
continue; continue;
if (dsa_port_is_dsa(port)) { if (dsa_port_is_dsa(port)) {
err = dsa_dsa_port_apply(port, index, ds); err = dsa_dsa_port_apply(port);
if (err) if (err)
return err; return err;
continue; continue;
} }
if (dsa_port_is_cpu(port)) { if (dsa_port_is_cpu(port)) {
err = dsa_cpu_port_apply(port, index, ds); err = dsa_cpu_port_apply(port);
if (err) if (err)
return err; return err;
continue; continue;
} }
err = dsa_user_port_apply(port, index, ds); err = dsa_user_port_apply(port);
if (err) if (err)
continue; continue;
} }
@ -402,16 +392,16 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
continue; continue;
if (dsa_port_is_dsa(port)) { if (dsa_port_is_dsa(port)) {
dsa_dsa_port_unapply(port, index, ds); dsa_dsa_port_unapply(port);
continue; continue;
} }
if (dsa_port_is_cpu(port)) { if (dsa_port_is_cpu(port)) {
dsa_cpu_port_unapply(port, index, ds); dsa_cpu_port_unapply(port);
continue; continue;
} }
dsa_user_port_unapply(port, index, ds); dsa_user_port_unapply(port);
} }
if (ds->slave_mii_bus && ds->ops->phy_read) if (ds->slave_mii_bus && ds->ops->phy_read)
@ -444,7 +434,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
} }
if (dst->cpu_dp) { if (dst->cpu_dp) {
err = dsa_cpu_port_ethtool_setup(dst->cpu_dp->ds); err = dsa_cpu_port_ethtool_setup(dst->cpu_dp);
if (err) if (err)
return err; return err;
} }
@ -485,7 +475,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
} }
if (dst->cpu_dp) if (dst->cpu_dp)
dsa_cpu_port_ethtool_restore(dst->cpu_dp->ds); dsa_cpu_port_ethtool_restore(dst->cpu_dp);
pr_info("DSA: tree %d unapplied\n", dst->tree); pr_info("DSA: tree %d unapplied\n", dst->tree);
dst->applied = false; dst->applied = false;
@ -530,6 +520,12 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
dst->rcv = dst->tag_ops->rcv; dst->rcv = dst->tag_ops->rcv;
/* Initialize cpu_port_mask now for drv->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
ds->cpu_port_mask |= BIT(index);
return 0; return 0;
} }
@ -541,14 +537,22 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
for (index = 0; index < ds->num_ports; index++) { for (index = 0; index < ds->num_ports; index++) {
port = &ds->ports[index]; port = &ds->ports[index];
if (!dsa_port_is_valid(port)) if (!dsa_port_is_valid(port) ||
dsa_port_is_dsa(port))
continue; continue;
if (dsa_port_is_cpu(port)) { if (dsa_port_is_cpu(port)) {
err = dsa_cpu_parse(port, index, dst, ds); err = dsa_cpu_parse(port, index, dst, ds);
if (err) if (err)
return err; return err;
} else {
/* Initialize enabled_port_mask now for drv->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
ds->enabled_port_mask |= BIT(index);
} }
} }
pr_info("DSA: switch %d %d parsed\n", dst->tree, ds->index); pr_info("DSA: switch %d %d parsed\n", dst->tree, ds->index);
@ -597,13 +601,6 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
return -EINVAL; return -EINVAL;
ds->ports[reg].dn = port; ds->ports[reg].dn = port;
/* Initialize enabled_port_mask now for ops->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
if (!dsa_port_is_cpu(&ds->ports[reg]))
ds->enabled_port_mask |= 1 << reg;
} }
return 0; return 0;
@ -619,14 +616,6 @@ static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
continue; continue;
ds->ports[i].name = cd->port_names[i]; ds->ports[i].name = cd->port_names[i];
/* Initialize enabled_port_mask now for drv->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
if (!dsa_port_is_cpu(&ds->ports[i]))
ds->enabled_port_mask |= 1 << i;
valid_name_found = true; valid_name_found = true;
} }

View File

@ -103,8 +103,8 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
struct dsa_port *dport, int port); struct dsa_port *dport, int port);
void dsa_cpu_dsa_destroy(struct dsa_port *dport); 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_port *cpu_dp);
void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds); void dsa_cpu_port_ethtool_restore(struct dsa_port *cpu_dp);
/* legacy.c */ /* legacy.c */
int dsa_legacy_register(void); int dsa_legacy_register(void);

View File

@ -205,7 +205,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n", netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n",
index); index);
ret = dsa_cpu_port_ethtool_setup(ds); ret = dsa_cpu_port_ethtool_setup(ds->dst->cpu_dp);
if (ret) if (ret)
return ret; return ret;
@ -733,7 +733,7 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
dsa_switch_destroy(ds); dsa_switch_destroy(ds);
} }
dsa_cpu_port_ethtool_restore(dst->cpu_dp->ds); dsa_cpu_port_ethtool_restore(dst->cpu_dp);
dev_put(dst->master_netdev); dev_put(dst->master_netdev);
} }