Commit e41c1b50 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: dsa: Consistently use dsa_port for dsa_*_port_{apply, unapply}

We have all the information we need in dsa_port, so use it instead of
repeating the same arguments over and over again.
Suggested-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 937c7df8
...@@ -214,66 +214,61 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst) ...@@ -214,66 +214,61 @@ 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); ds->cpu_port_mask |= BIT(port->index);
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);
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 +277,32 @@ static int dsa_user_port_apply(struct dsa_port *port, u32 index, ...@@ -282,35 +277,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 +362,20 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -370,20 +362,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 +394,16 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -402,16 +394,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)
......
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