Commit a1a6a4d1 authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller

net: dsa: mv88e6xxx: factorize switch setup

Provide a shared mv88e6xxx_setup function to the drivers.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8698fd95
...@@ -51,24 +51,10 @@ static const char *mv88e6123_drv_probe(struct device *dsa_dev, ...@@ -51,24 +51,10 @@ static const char *mv88e6123_drv_probe(struct device *dsa_dev,
ARRAY_SIZE(mv88e6123_table)); ARRAY_SIZE(mv88e6123_table));
} }
static int mv88e6123_setup(struct dsa_switch *ds)
{
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
int ret;
ps->ds = ds;
ret = mv88e6xxx_setup_common(ps);
if (ret < 0)
return ret;
return mv88e6xxx_setup_ports(ds);
}
struct dsa_switch_driver mv88e6123_switch_driver = { struct dsa_switch_driver mv88e6123_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_EDSA, .tag_protocol = DSA_TAG_PROTO_EDSA,
.probe = mv88e6123_drv_probe, .probe = mv88e6123_drv_probe,
.setup = mv88e6123_setup, .setup = mv88e6xxx_setup,
.set_addr = mv88e6xxx_set_addr, .set_addr = mv88e6xxx_set_addr,
.phy_read = mv88e6xxx_phy_read, .phy_read = mv88e6xxx_phy_read,
.phy_write = mv88e6xxx_phy_write, .phy_write = mv88e6xxx_phy_write,
......
...@@ -58,24 +58,10 @@ static const char *mv88e6131_drv_probe(struct device *dsa_dev, ...@@ -58,24 +58,10 @@ static const char *mv88e6131_drv_probe(struct device *dsa_dev,
ARRAY_SIZE(mv88e6131_table)); ARRAY_SIZE(mv88e6131_table));
} }
static int mv88e6131_setup(struct dsa_switch *ds)
{
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
int ret;
ps->ds = ds;
ret = mv88e6xxx_setup_common(ps);
if (ret < 0)
return ret;
return mv88e6xxx_setup_ports(ds);
}
struct dsa_switch_driver mv88e6131_switch_driver = { struct dsa_switch_driver mv88e6131_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_DSA, .tag_protocol = DSA_TAG_PROTO_DSA,
.probe = mv88e6131_drv_probe, .probe = mv88e6131_drv_probe,
.setup = mv88e6131_setup, .setup = mv88e6xxx_setup,
.set_addr = mv88e6xxx_set_addr, .set_addr = mv88e6xxx_set_addr,
.phy_read = mv88e6xxx_phy_read, .phy_read = mv88e6xxx_phy_read,
.phy_write = mv88e6xxx_phy_write, .phy_write = mv88e6xxx_phy_write,
......
...@@ -58,24 +58,10 @@ static const char *mv88e6171_drv_probe(struct device *dsa_dev, ...@@ -58,24 +58,10 @@ static const char *mv88e6171_drv_probe(struct device *dsa_dev,
ARRAY_SIZE(mv88e6171_table)); ARRAY_SIZE(mv88e6171_table));
} }
static int mv88e6171_setup(struct dsa_switch *ds)
{
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
int ret;
ps->ds = ds;
ret = mv88e6xxx_setup_common(ps);
if (ret < 0)
return ret;
return mv88e6xxx_setup_ports(ds);
}
struct dsa_switch_driver mv88e6171_switch_driver = { struct dsa_switch_driver mv88e6171_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_EDSA, .tag_protocol = DSA_TAG_PROTO_EDSA,
.probe = mv88e6171_drv_probe, .probe = mv88e6171_drv_probe,
.setup = mv88e6171_setup, .setup = mv88e6xxx_setup,
.set_addr = mv88e6xxx_set_addr, .set_addr = mv88e6xxx_set_addr,
.phy_read = mv88e6xxx_phy_read, .phy_read = mv88e6xxx_phy_read,
.phy_write = mv88e6xxx_phy_write, .phy_write = mv88e6xxx_phy_write,
......
...@@ -77,24 +77,10 @@ static const char *mv88e6352_drv_probe(struct device *dsa_dev, ...@@ -77,24 +77,10 @@ static const char *mv88e6352_drv_probe(struct device *dsa_dev,
ARRAY_SIZE(mv88e6352_table)); ARRAY_SIZE(mv88e6352_table));
} }
static int mv88e6352_setup(struct dsa_switch *ds)
{
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
int ret;
ps->ds = ds;
ret = mv88e6xxx_setup_common(ps);
if (ret < 0)
return ret;
return mv88e6xxx_setup_ports(ds);
}
struct dsa_switch_driver mv88e6352_switch_driver = { struct dsa_switch_driver mv88e6352_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_EDSA, .tag_protocol = DSA_TAG_PROTO_EDSA,
.probe = mv88e6352_drv_probe, .probe = mv88e6352_drv_probe,
.setup = mv88e6352_setup, .setup = mv88e6xxx_setup,
.set_addr = mv88e6xxx_set_addr, .set_addr = mv88e6xxx_set_addr,
.phy_read = mv88e6xxx_phy_read, .phy_read = mv88e6xxx_phy_read,
.phy_write = mv88e6xxx_phy_write, .phy_write = mv88e6xxx_phy_write,
......
...@@ -2640,14 +2640,12 @@ static int mv88e6xxx_power_on_serdes(struct mv88e6xxx_priv_state *ps) ...@@ -2640,14 +2640,12 @@ static int mv88e6xxx_power_on_serdes(struct mv88e6xxx_priv_state *ps)
return ret; return ret;
} }
static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) static int mv88e6xxx_setup_port(struct mv88e6xxx_priv_state *ps, int port)
{ {
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); struct dsa_switch *ds = ps->ds;
int ret; int ret;
u16 reg; u16 reg;
mutex_lock(&ps->smi_mutex);
if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) ||
mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) ||
mv88e6xxx_6185_family(ps) || mv88e6xxx_6095_family(ps) || mv88e6xxx_6185_family(ps) || mv88e6xxx_6095_family(ps) ||
...@@ -2676,7 +2674,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2676,7 +2674,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_PCS_CTRL, reg); PORT_PCS_CTRL, reg);
if (ret) if (ret)
goto abort; return ret;
} }
/* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock, /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
...@@ -2740,7 +2738,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2740,7 +2738,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_CONTROL, reg); PORT_CONTROL, reg);
if (ret) if (ret)
goto abort; return ret;
} }
/* If this port is connected to a SerDes, make sure the SerDes is not /* If this port is connected to a SerDes, make sure the SerDes is not
...@@ -2749,14 +2747,14 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2749,14 +2747,14 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
if (mv88e6xxx_6352_family(ps)) { if (mv88e6xxx_6352_family(ps)) {
ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_STATUS); ret = _mv88e6xxx_reg_read(ps, REG_PORT(port), PORT_STATUS);
if (ret < 0) if (ret < 0)
goto abort; return ret;
ret &= PORT_STATUS_CMODE_MASK; ret &= PORT_STATUS_CMODE_MASK;
if ((ret == PORT_STATUS_CMODE_100BASE_X) || if ((ret == PORT_STATUS_CMODE_100BASE_X) ||
(ret == PORT_STATUS_CMODE_1000BASE_X) || (ret == PORT_STATUS_CMODE_1000BASE_X) ||
(ret == PORT_STATUS_CMODE_SGMII)) { (ret == PORT_STATUS_CMODE_SGMII)) {
ret = mv88e6xxx_power_on_serdes(ps); ret = mv88e6xxx_power_on_serdes(ps);
if (ret < 0) if (ret < 0)
goto abort; return ret;
} }
} }
...@@ -2793,7 +2791,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2793,7 +2791,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_CONTROL_2, reg); PORT_CONTROL_2, reg);
if (ret) if (ret)
goto abort; return ret;
} }
/* Port Association Vector: when learning source addresses /* Port Association Vector: when learning source addresses
...@@ -2808,13 +2806,13 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2808,13 +2806,13 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_ASSOC_VECTOR, reg); ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_ASSOC_VECTOR, reg);
if (ret) if (ret)
goto abort; return ret;
/* Egress rate control 2: disable egress rate control. */ /* Egress rate control 2: disable egress rate control. */
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_RATE_CONTROL_2, ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_RATE_CONTROL_2,
0x0000); 0x0000);
if (ret) if (ret)
goto abort; return ret;
if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) ||
mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) || mv88e6xxx_6165_family(ps) || mv88e6xxx_6097_family(ps) ||
...@@ -2826,7 +2824,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2826,7 +2824,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_PAUSE_CTRL, 0x0000); PORT_PAUSE_CTRL, 0x0000);
if (ret) if (ret)
goto abort; return ret;
/* Port ATU control: disable limiting the number of /* Port ATU control: disable limiting the number of
* address database entries that this port is allowed * address database entries that this port is allowed
...@@ -2840,7 +2838,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2840,7 +2838,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_PRI_OVERRIDE, 0x0000); PORT_PRI_OVERRIDE, 0x0000);
if (ret) if (ret)
goto abort; return ret;
/* Port Ethertype: use the Ethertype DSA Ethertype /* Port Ethertype: use the Ethertype DSA Ethertype
* value. * value.
...@@ -2848,14 +2846,14 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2848,14 +2846,14 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_ETH_TYPE, ETH_P_EDSA); PORT_ETH_TYPE, ETH_P_EDSA);
if (ret) if (ret)
goto abort; return ret;
/* Tag Remap: use an identity 802.1p prio -> switch /* Tag Remap: use an identity 802.1p prio -> switch
* prio mapping. * prio mapping.
*/ */
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_TAG_REGMAP_0123, 0x3210); PORT_TAG_REGMAP_0123, 0x3210);
if (ret) if (ret)
goto abort; return ret;
/* Tag Remap 2: use an identity 802.1p prio -> switch /* Tag Remap 2: use an identity 802.1p prio -> switch
* prio mapping. * prio mapping.
...@@ -2863,7 +2861,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2863,7 +2861,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_TAG_REGMAP_4567, 0x7654); PORT_TAG_REGMAP_4567, 0x7654);
if (ret) if (ret)
goto abort; return ret;
} }
if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) || if (mv88e6xxx_6352_family(ps) || mv88e6xxx_6351_family(ps) ||
...@@ -2874,7 +2872,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2874,7 +2872,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), ret = _mv88e6xxx_reg_write(ps, REG_PORT(port),
PORT_RATE_CONTROL, 0x0001); PORT_RATE_CONTROL, 0x0001);
if (ret) if (ret)
goto abort; return ret;
} }
/* Port Control 1: disable trunking, disable sending /* Port Control 1: disable trunking, disable sending
...@@ -2882,7 +2880,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2882,7 +2880,7 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
*/ */
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL_1, 0x0000); ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_CONTROL_1, 0x0000);
if (ret) if (ret)
goto abort; return ret;
/* Port based VLAN map: give each port the same default address /* Port based VLAN map: give each port the same default address
* database, and allow bidirectional communication between the * database, and allow bidirectional communication between the
...@@ -2890,33 +2888,20 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port) ...@@ -2890,33 +2888,20 @@ static int mv88e6xxx_setup_port(struct dsa_switch *ds, int port)
*/ */
ret = _mv88e6xxx_port_fid_set(ps, port, 0); ret = _mv88e6xxx_port_fid_set(ps, port, 0);
if (ret) if (ret)
goto abort; return ret;
ret = _mv88e6xxx_port_based_vlan_map(ps, port); ret = _mv88e6xxx_port_based_vlan_map(ps, port);
if (ret) if (ret)
goto abort; return ret;
/* Default VLAN ID and priority: don't set a default VLAN /* Default VLAN ID and priority: don't set a default VLAN
* ID, and set the default packet priority to zero. * ID, and set the default packet priority to zero.
*/ */
ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_DEFAULT_VLAN, ret = _mv88e6xxx_reg_write(ps, REG_PORT(port), PORT_DEFAULT_VLAN,
0x0000); 0x0000);
abort: if (ret)
mutex_unlock(&ps->smi_mutex); return ret;
return ret;
}
int mv88e6xxx_setup_ports(struct dsa_switch *ds)
{
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
int ret;
int i;
for (i = 0; i < ps->info->num_ports; i++) {
ret = mv88e6xxx_setup_port(ds, i);
if (ret < 0)
return ret;
}
return 0; return 0;
} }
...@@ -3123,9 +3108,13 @@ static int mv88e6xxx_setup_global(struct mv88e6xxx_priv_state *ps) ...@@ -3123,9 +3108,13 @@ static int mv88e6xxx_setup_global(struct mv88e6xxx_priv_state *ps)
return err; return err;
} }
int mv88e6xxx_setup_common(struct mv88e6xxx_priv_state *ps) int mv88e6xxx_setup(struct dsa_switch *ds)
{ {
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
int err; int err;
int i;
ps->ds = ds;
mutex_init(&ps->smi_mutex); mutex_init(&ps->smi_mutex);
...@@ -3144,6 +3133,14 @@ int mv88e6xxx_setup_common(struct mv88e6xxx_priv_state *ps) ...@@ -3144,6 +3133,14 @@ int mv88e6xxx_setup_common(struct mv88e6xxx_priv_state *ps)
goto unlock; goto unlock;
err = mv88e6xxx_setup_global(ps); err = mv88e6xxx_setup_global(ps);
if (err)
goto unlock;
for (i = 0; i < ps->info->num_ports; i++) {
err = mv88e6xxx_setup_port(ps, i);
if (err)
goto unlock;
}
unlock: unlock:
mutex_unlock(&ps->smi_mutex); mutex_unlock(&ps->smi_mutex);
......
...@@ -588,8 +588,7 @@ const char *mv88e6xxx_drv_probe(struct device *dsa_dev, struct device *host_dev, ...@@ -588,8 +588,7 @@ const char *mv88e6xxx_drv_probe(struct device *dsa_dev, struct device *host_dev,
const struct mv88e6xxx_info *table, const struct mv88e6xxx_info *table,
unsigned int num); unsigned int num);
int mv88e6xxx_setup_ports(struct dsa_switch *ds); int mv88e6xxx_setup(struct dsa_switch *ds);
int mv88e6xxx_setup_common(struct mv88e6xxx_priv_state *ps);
int mv88e6xxx_reg_read(struct mv88e6xxx_priv_state *ps, int addr, int reg); int mv88e6xxx_reg_read(struct mv88e6xxx_priv_state *ps, int addr, int reg);
int mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr, int mv88e6xxx_reg_write(struct mv88e6xxx_priv_state *ps, int addr,
int reg, u16 val); int reg, u16 val);
......
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