Commit 7f4e568d authored by David S. Miller's avatar David S. Miller

Merge branch 'dsa-remove-set_addr'

Vivien Didelot says:

====================
net: dsa: remove .set_addr

An Ethernet switch may support having a MAC address, which can be used
as the switch's source address in transmitted full-duplex Pause frames.

If a DSA switch supports the related .set_addr operation, the DSA core
sets the master's MAC address on the switch.

This won't make sense anymore in a multi-CPU ports system, because there
won't be a unique master device assigned to a switch tree.

Moreover this operation is confusing because it makes the user think
that it could be used to program the switch with the MAC address of the
CPU/management port such that MAC address learning can be disabled on
said port, but in fact, that's not how it is currently used.

To fix this, assign a random MAC address at setup time in the mv88e6060
and mv88e6xxx drivers before removing .set_addr completely from DSA.

Changes in v3:
  - include fix for mv88e6060 switch MAC address setter.

Changes in v2:
  - remove .set_addr implementation from drivers and use a random MAC.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents ec0d0987 841f4f24
...@@ -110,13 +110,6 @@ static void dsa_loop_get_ethtool_stats(struct dsa_switch *ds, int port, ...@@ -110,13 +110,6 @@ static void dsa_loop_get_ethtool_stats(struct dsa_switch *ds, int port,
data[i] = ps->ports[port].mib[i].val; data[i] = ps->ports[port].mib[i].val;
} }
static int dsa_loop_set_addr(struct dsa_switch *ds, u8 *addr)
{
dev_dbg(ds->dev, "%s\n", __func__);
return 0;
}
static int dsa_loop_phy_read(struct dsa_switch *ds, int port, int regnum) static int dsa_loop_phy_read(struct dsa_switch *ds, int port, int regnum)
{ {
struct dsa_loop_priv *ps = ds->priv; struct dsa_loop_priv *ps = ds->priv;
...@@ -263,7 +256,6 @@ static const struct dsa_switch_ops dsa_loop_driver = { ...@@ -263,7 +256,6 @@ static const struct dsa_switch_ops dsa_loop_driver = {
.get_strings = dsa_loop_get_strings, .get_strings = dsa_loop_get_strings,
.get_ethtool_stats = dsa_loop_get_ethtool_stats, .get_ethtool_stats = dsa_loop_get_ethtool_stats,
.get_sset_count = dsa_loop_get_sset_count, .get_sset_count = dsa_loop_get_sset_count,
.set_addr = dsa_loop_set_addr,
.phy_read = dsa_loop_phy_read, .phy_read = dsa_loop_phy_read,
.phy_write = dsa_loop_phy_write, .phy_write = dsa_loop_phy_write,
.port_bridge_join = dsa_loop_port_bridge_join, .port_bridge_join = dsa_loop_port_bridge_join,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
*/ */
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/etherdevice.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -188,6 +189,27 @@ static int mv88e6060_setup_port(struct dsa_switch *ds, int p) ...@@ -188,6 +189,27 @@ static int mv88e6060_setup_port(struct dsa_switch *ds, int p)
return 0; return 0;
} }
static int mv88e6060_setup_addr(struct dsa_switch *ds)
{
u8 addr[ETH_ALEN];
u16 val;
eth_random_addr(addr);
val = addr[0] << 8 | addr[1];
/* The multicast bit is always transmitted as a zero, so the switch uses
* bit 8 for "DiffAddr", where 0 means all ports transmit the same SA.
*/
val &= 0xfeff;
REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, val);
REG_WRITE(REG_GLOBAL, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
REG_WRITE(REG_GLOBAL, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
return 0;
}
static int mv88e6060_setup(struct dsa_switch *ds) static int mv88e6060_setup(struct dsa_switch *ds)
{ {
int ret; int ret;
...@@ -203,6 +225,10 @@ static int mv88e6060_setup(struct dsa_switch *ds) ...@@ -203,6 +225,10 @@ static int mv88e6060_setup(struct dsa_switch *ds)
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = mv88e6060_setup_addr(ds);
if (ret < 0)
return ret;
for (i = 0; i < MV88E6060_PORTS; i++) { for (i = 0; i < MV88E6060_PORTS; i++) {
ret = mv88e6060_setup_port(ds, i); ret = mv88e6060_setup_port(ds, i);
if (ret < 0) if (ret < 0)
...@@ -212,16 +238,6 @@ static int mv88e6060_setup(struct dsa_switch *ds) ...@@ -212,16 +238,6 @@ static int mv88e6060_setup(struct dsa_switch *ds)
return 0; return 0;
} }
static int mv88e6060_set_addr(struct dsa_switch *ds, u8 *addr)
{
/* Use the same MAC Address as FD Pause frames for all ports */
REG_WRITE(REG_GLOBAL, GLOBAL_MAC_01, (addr[0] << 9) | addr[1]);
REG_WRITE(REG_GLOBAL, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
REG_WRITE(REG_GLOBAL, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
return 0;
}
static int mv88e6060_port_to_phy_addr(int port) static int mv88e6060_port_to_phy_addr(int port)
{ {
if (port >= 0 && port < MV88E6060_PORTS) if (port >= 0 && port < MV88E6060_PORTS)
...@@ -256,7 +272,6 @@ static const struct dsa_switch_ops mv88e6060_switch_ops = { ...@@ -256,7 +272,6 @@ static const struct dsa_switch_ops mv88e6060_switch_ops = {
.get_tag_protocol = mv88e6060_get_tag_protocol, .get_tag_protocol = mv88e6060_get_tag_protocol,
.probe = mv88e6060_drv_probe, .probe = mv88e6060_drv_probe,
.setup = mv88e6060_setup, .setup = mv88e6060_setup,
.set_addr = mv88e6060_set_addr,
.phy_read = mv88e6060_phy_read, .phy_read = mv88e6060_phy_read,
.phy_write = mv88e6060_phy_write, .phy_write = mv88e6060_phy_write,
}; };
......
...@@ -932,6 +932,19 @@ static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip) ...@@ -932,6 +932,19 @@ static int mv88e6xxx_irl_setup(struct mv88e6xxx_chip *chip)
return 0; return 0;
} }
static int mv88e6xxx_mac_setup(struct mv88e6xxx_chip *chip)
{
if (chip->info->ops->set_switch_mac) {
u8 addr[ETH_ALEN];
eth_random_addr(addr);
return chip->info->ops->set_switch_mac(chip, addr);
}
return 0;
}
static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port) static int mv88e6xxx_pvt_map(struct mv88e6xxx_chip *chip, int dev, int port)
{ {
u16 pvlan = 0; u16 pvlan = 0;
...@@ -2013,6 +2026,10 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) ...@@ -2013,6 +2026,10 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
if (err) if (err)
goto unlock; goto unlock;
err = mv88e6xxx_mac_setup(chip);
if (err)
goto unlock;
err = mv88e6xxx_phy_setup(chip); err = mv88e6xxx_phy_setup(chip);
if (err) if (err)
goto unlock; goto unlock;
...@@ -2043,21 +2060,6 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) ...@@ -2043,21 +2060,6 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
return err; return err;
} }
static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
{
struct mv88e6xxx_chip *chip = ds->priv;
int err;
if (!chip->info->ops->set_switch_mac)
return -EOPNOTSUPP;
mutex_lock(&chip->reg_lock);
err = chip->info->ops->set_switch_mac(chip, addr);
mutex_unlock(&chip->reg_lock);
return err;
}
static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg) static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
{ {
struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv;
...@@ -3785,7 +3787,6 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { ...@@ -3785,7 +3787,6 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
.probe = mv88e6xxx_drv_probe, .probe = mv88e6xxx_drv_probe,
.get_tag_protocol = mv88e6xxx_get_tag_protocol, .get_tag_protocol = mv88e6xxx_get_tag_protocol,
.setup = mv88e6xxx_setup, .setup = mv88e6xxx_setup,
.set_addr = mv88e6xxx_set_addr,
.adjust_link = mv88e6xxx_adjust_link, .adjust_link = mv88e6xxx_adjust_link,
.get_strings = mv88e6xxx_get_strings, .get_strings = mv88e6xxx_get_strings,
.get_ethtool_stats = mv88e6xxx_get_ethtool_stats, .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
......
...@@ -291,7 +291,6 @@ struct dsa_switch_ops { ...@@ -291,7 +291,6 @@ struct dsa_switch_ops {
enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds); enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds);
int (*setup)(struct dsa_switch *ds); int (*setup)(struct dsa_switch *ds);
int (*set_addr)(struct dsa_switch *ds, u8 *addr);
u32 (*get_phy_flags)(struct dsa_switch *ds, int port); u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
/* /*
......
...@@ -336,12 +336,6 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -336,12 +336,6 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
if (err) if (err)
return err; return err;
if (ds->ops->set_addr) {
err = ds->ops->set_addr(ds, dst->cpu_dp->netdev->dev_addr);
if (err < 0)
return err;
}
if (!ds->slave_mii_bus && ds->ops->phy_read) { if (!ds->slave_mii_bus && ds->ops->phy_read) {
ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev); ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
if (!ds->slave_mii_bus) if (!ds->slave_mii_bus)
......
...@@ -172,12 +172,6 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, ...@@ -172,12 +172,6 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
if (ret) if (ret)
return ret; return ret;
if (ops->set_addr) {
ret = ops->set_addr(ds, master->dev_addr);
if (ret < 0)
return ret;
}
if (!ds->slave_mii_bus && ops->phy_read) { if (!ds->slave_mii_bus && ops->phy_read) {
ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev); ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
if (!ds->slave_mii_bus) if (!ds->slave_mii_bus)
......
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