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

Merge branch 'dsa-global-cosmetics'

Vivien Didelot says:

====================
net: dsa: mv88e6xxx: Global (1) cosmetics

The Global (1) internal SMI device of Marvell switches is a set of
registers providing support to different units for MAC addresses (ATU),
VLANs (VTU), PHY polling (PPU), etc.

Chips (like 88E6060) may use a different address for it, or have
subtleties in the units (e.g. different number of databases, changing
how registers must be accessed), making it hard to maintain properly.

This patchset is a first step to polish the Global (1) support, with no
functional changes though. Here's basically what it does:

  - add helpers to access Global1 registers (same for Global2)
  - remove a few family checks (VTU/STU FID registers)
  - s/mv88e6xxx_vtu_stu_entry/mv88e6xxx_vtu_entry/
  - add a per-chip mv88e6xxx_ops structure of function pointers:

  struct mv88e6xxx_ops {
        int (*get_eeprom)(struct mv88e6xxx_chip *chip,
                          struct ethtool_eeprom *eeprom, u8 *data);
        int (*set_eeprom)(struct mv88e6xxx_chip *chip,
                          struct ethtool_eeprom *eeprom, u8 *data);

        int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);

        int (*phy_read)(struct mv88e6xxx_chip *chip, int addr, int reg,
                        u16 *val);
        int (*phy_write)(struct mv88e6xxx_chip *chip, int addr, int reg,
                         u16 val);
  };

Future patchsets will add ATU/VTU ops, software reset, etc.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 31fbe81f ee4dc2e7
obj-$(CONFIG_NET_DSA_MV88E6XXX) += mv88e6xxx.o obj-$(CONFIG_NET_DSA_MV88E6XXX) += mv88e6xxx.o
mv88e6xxx-objs := chip.o mv88e6xxx-objs := chip.o
mv88e6xxx-objs += global1.o
mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_GLOBAL2) += global2.o mv88e6xxx-$(CONFIG_NET_DSA_MV88E6XXX_GLOBAL2) += global2.o
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <net/switchdev.h> #include <net/switchdev.h>
#include "mv88e6xxx.h" #include "mv88e6xxx.h"
#include "global1.h"
#include "global2.h" #include "global2.h"
static void assert_reg_lock(struct mv88e6xxx_chip *chip) static void assert_reg_lock(struct mv88e6xxx_chip *chip)
...@@ -97,7 +98,7 @@ static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip, ...@@ -97,7 +98,7 @@ static int mv88e6xxx_smi_single_chip_write(struct mv88e6xxx_chip *chip,
return 0; return 0;
} }
static const struct mv88e6xxx_ops mv88e6xxx_smi_single_chip_ops = { static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_single_chip_ops = {
.read = mv88e6xxx_smi_single_chip_read, .read = mv88e6xxx_smi_single_chip_read,
.write = mv88e6xxx_smi_single_chip_write, .write = mv88e6xxx_smi_single_chip_write,
}; };
...@@ -179,7 +180,7 @@ static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip, ...@@ -179,7 +180,7 @@ static int mv88e6xxx_smi_multi_chip_write(struct mv88e6xxx_chip *chip,
return 0; return 0;
} }
static const struct mv88e6xxx_ops mv88e6xxx_smi_multi_chip_ops = { static const struct mv88e6xxx_bus_ops mv88e6xxx_smi_multi_chip_ops = {
.read = mv88e6xxx_smi_multi_chip_read, .read = mv88e6xxx_smi_multi_chip_read,
.write = mv88e6xxx_smi_multi_chip_write, .write = mv88e6xxx_smi_multi_chip_write,
}; };
...@@ -237,10 +238,10 @@ static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy, ...@@ -237,10 +238,10 @@ static int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int phy,
{ {
int addr = phy; /* PHY devices addresses start at 0x0 */ int addr = phy; /* PHY devices addresses start at 0x0 */
if (!chip->phy_ops) if (!chip->info->ops->phy_read)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return chip->phy_ops->read(chip, addr, reg, val); return chip->info->ops->phy_read(chip, addr, reg, val);
} }
static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy, static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
...@@ -248,10 +249,10 @@ static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy, ...@@ -248,10 +249,10 @@ static int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy,
{ {
int addr = phy; /* PHY devices addresses start at 0x0 */ int addr = phy; /* PHY devices addresses start at 0x0 */
if (!chip->phy_ops) if (!chip->info->ops->phy_write)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return chip->phy_ops->write(chip, addr, reg, val); return chip->info->ops->phy_write(chip, addr, reg, val);
} }
static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page) static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8 page)
...@@ -361,46 +362,27 @@ int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update) ...@@ -361,46 +362,27 @@ int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, u16 update)
return mv88e6xxx_write(chip, addr, reg, val); return mv88e6xxx_write(chip, addr, reg, val);
} }
static int _mv88e6xxx_reg_read(struct mv88e6xxx_chip *chip, int addr, int reg) static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
{ {
u16 val; u16 val;
int err; int i, err;
err = mv88e6xxx_read(chip, addr, reg, &val); err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
if (err) if (err)
return err; return err;
return val; err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
} val & ~GLOBAL_CONTROL_PPU_ENABLE);
if (err)
static int _mv88e6xxx_reg_write(struct mv88e6xxx_chip *chip, int addr, return err;
int reg, u16 val)
{
return mv88e6xxx_write(chip, addr, reg, val);
}
static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
{
int ret;
int i;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_CONTROL);
if (ret < 0)
return ret;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_CONTROL,
ret & ~GLOBAL_CONTROL_PPU_ENABLE);
if (ret)
return ret;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_STATUS); err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
if (ret < 0) if (err)
return ret; return err;
usleep_range(1000, 2000); usleep_range(1000, 2000);
if ((ret & GLOBAL_STATUS_PPU_MASK) != if ((val & GLOBAL_STATUS_PPU_MASK) != GLOBAL_STATUS_PPU_POLLING)
GLOBAL_STATUS_PPU_POLLING)
return 0; return 0;
} }
...@@ -409,25 +391,25 @@ static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip) ...@@ -409,25 +391,25 @@ static int mv88e6xxx_ppu_disable(struct mv88e6xxx_chip *chip)
static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip) static int mv88e6xxx_ppu_enable(struct mv88e6xxx_chip *chip)
{ {
int ret, err, i; u16 val;
int i, err;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_CONTROL); err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL, &val);
if (ret < 0) if (err)
return ret; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_CONTROL, err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL,
ret | GLOBAL_CONTROL_PPU_ENABLE); val | GLOBAL_CONTROL_PPU_ENABLE);
if (err) if (err)
return err; return err;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_STATUS); err = mv88e6xxx_g1_read(chip, GLOBAL_STATUS, &val);
if (ret < 0) if (err)
return ret; return err;
usleep_range(1000, 2000); usleep_range(1000, 2000);
if ((ret & GLOBAL_STATUS_PPU_MASK) == if ((val & GLOBAL_STATUS_PPU_MASK) == GLOBAL_STATUS_PPU_POLLING)
GLOBAL_STATUS_PPU_POLLING)
return 0; return 0;
} }
...@@ -533,11 +515,6 @@ static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr, ...@@ -533,11 +515,6 @@ static int mv88e6xxx_phy_ppu_write(struct mv88e6xxx_chip *chip, int addr,
return err; return err;
} }
static const struct mv88e6xxx_ops mv88e6xxx_phy_ppu_ops = {
.read = mv88e6xxx_phy_ppu_read,
.write = mv88e6xxx_phy_ppu_write,
};
static bool mv88e6xxx_6065_family(struct mv88e6xxx_chip *chip) static bool mv88e6xxx_6065_family(struct mv88e6xxx_chip *chip)
{ {
return chip->info->family == MV88E6XXX_FAMILY_6065; return chip->info->family == MV88E6XXX_FAMILY_6065;
...@@ -578,21 +555,6 @@ static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip) ...@@ -578,21 +555,6 @@ static bool mv88e6xxx_6352_family(struct mv88e6xxx_chip *chip)
return chip->info->family == MV88E6XXX_FAMILY_6352; return chip->info->family == MV88E6XXX_FAMILY_6352;
} }
static unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
{
return chip->info->num_databases;
}
static bool mv88e6xxx_has_fid_reg(struct mv88e6xxx_chip *chip)
{
/* Does the device have dedicated FID registers for ATU and VTU ops? */
if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip))
return true;
return false;
}
/* We expect the switch to perform auto negotiation if there is a real /* We expect the switch to perform auto negotiation if there is a real
* phy. However, in the case of a fixed link phy, we force the port * phy. However, in the case of a fixed link phy, we force the port
* settings from the fixed link settings. * settings from the fixed link settings.
...@@ -646,7 +608,7 @@ static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port, ...@@ -646,7 +608,7 @@ static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
reg |= PORT_PCS_CTRL_DUPLEX_FULL; reg |= PORT_PCS_CTRL_DUPLEX_FULL;
if ((mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip)) && if ((mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip)) &&
(port >= chip->info->num_ports - 2)) { (port >= mv88e6xxx_num_ports(chip) - 2)) {
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
reg |= PORT_PCS_CTRL_RGMII_DELAY_RXCLK; reg |= PORT_PCS_CTRL_RGMII_DELAY_RXCLK;
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
...@@ -663,12 +625,12 @@ static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port, ...@@ -663,12 +625,12 @@ static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
static int _mv88e6xxx_stats_wait(struct mv88e6xxx_chip *chip) static int _mv88e6xxx_stats_wait(struct mv88e6xxx_chip *chip)
{ {
int ret; u16 val;
int i; int i, err;
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_STATS_OP); err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_OP, &val);
if ((ret & GLOBAL_STATS_OP_BUSY) == 0) if ((val & GLOBAL_STATS_OP_BUSY) == 0)
return 0; return 0;
} }
...@@ -677,55 +639,52 @@ static int _mv88e6xxx_stats_wait(struct mv88e6xxx_chip *chip) ...@@ -677,55 +639,52 @@ static int _mv88e6xxx_stats_wait(struct mv88e6xxx_chip *chip)
static int _mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port) static int _mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port)
{ {
int ret; int err;
if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip)) if (mv88e6xxx_6320_family(chip) || mv88e6xxx_6352_family(chip))
port = (port + 1) << 5; port = (port + 1) << 5;
/* Snapshot the hardware statistics counters for this port. */ /* Snapshot the hardware statistics counters for this port. */
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_STATS_OP, err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
GLOBAL_STATS_OP_CAPTURE_PORT | GLOBAL_STATS_OP_CAPTURE_PORT |
GLOBAL_STATS_OP_HIST_RX_TX | port); GLOBAL_STATS_OP_HIST_RX_TX | port);
if (ret < 0) if (err)
return ret; return err;
/* Wait for the snapshotting to complete. */ /* Wait for the snapshotting to complete. */
ret = _mv88e6xxx_stats_wait(chip); return _mv88e6xxx_stats_wait(chip);
if (ret < 0)
return ret;
return 0;
} }
static void _mv88e6xxx_stats_read(struct mv88e6xxx_chip *chip, static void _mv88e6xxx_stats_read(struct mv88e6xxx_chip *chip,
int stat, u32 *val) int stat, u32 *val)
{ {
u32 _val; u32 value;
int ret; u16 reg;
int err;
*val = 0; *val = 0;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_STATS_OP, err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
GLOBAL_STATS_OP_READ_CAPTURED | GLOBAL_STATS_OP_READ_CAPTURED |
GLOBAL_STATS_OP_HIST_RX_TX | stat); GLOBAL_STATS_OP_HIST_RX_TX | stat);
if (ret < 0) if (err)
return; return;
ret = _mv88e6xxx_stats_wait(chip); err = _mv88e6xxx_stats_wait(chip);
if (ret < 0) if (err)
return; return;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_STATS_COUNTER_32); err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_32, &reg);
if (ret < 0) if (err)
return; return;
_val = ret << 16; value = reg << 16;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_STATS_COUNTER_01); err = mv88e6xxx_g1_read(chip, GLOBAL_STATS_COUNTER_01, &reg);
if (ret < 0) if (err)
return; return;
*val = _val | ret; *val = value | reg;
} }
static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = { static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = {
...@@ -932,8 +891,7 @@ static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port, ...@@ -932,8 +891,7 @@ static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip) static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
{ {
return mv88e6xxx_wait(chip, REG_GLOBAL, GLOBAL_ATU_OP, return mv88e6xxx_g1_wait(chip, GLOBAL_ATU_OP, GLOBAL_ATU_OP_BUSY);
GLOBAL_ATU_OP_BUSY);
} }
static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
...@@ -997,32 +955,31 @@ static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port, ...@@ -997,32 +955,31 @@ static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd) static int _mv88e6xxx_atu_cmd(struct mv88e6xxx_chip *chip, u16 fid, u16 cmd)
{ {
int ret; u16 val;
int err;
if (mv88e6xxx_has_fid_reg(chip)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_ATU_FID)) {
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_ATU_FID, err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_FID, fid);
fid); if (err)
if (ret < 0) return err;
return ret;
} else if (mv88e6xxx_num_databases(chip) == 256) { } else if (mv88e6xxx_num_databases(chip) == 256) {
/* ATU DBNum[7:4] are located in ATU Control 15:12 */ /* ATU DBNum[7:4] are located in ATU Control 15:12 */
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_ATU_CONTROL); err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_ATU_CONTROL, err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
(ret & 0xfff) | (val & 0xfff) | ((fid << 8) & 0xf000));
((fid << 8) & 0xf000)); if (err)
if (ret < 0) return err;
return ret;
/* ATU DBNum[3:0] are located in ATU Operation 3:0 */ /* ATU DBNum[3:0] are located in ATU Operation 3:0 */
cmd |= fid & 0xf; cmd |= fid & 0xf;
} }
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_ATU_OP, cmd); err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_OP, cmd);
if (ret < 0) if (err)
return ret; return err;
return _mv88e6xxx_atu_wait(chip); return _mv88e6xxx_atu_wait(chip);
} }
...@@ -1047,7 +1004,7 @@ static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip, ...@@ -1047,7 +1004,7 @@ static int _mv88e6xxx_atu_data_write(struct mv88e6xxx_chip *chip,
data |= (entry->portv_trunkid << shift) & mask; data |= (entry->portv_trunkid << shift) & mask;
} }
return _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_ATU_DATA, data); return mv88e6xxx_g1_write(chip, GLOBAL_ATU_DATA, data);
} }
static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_atu_flush_move(struct mv88e6xxx_chip *chip,
...@@ -1150,7 +1107,7 @@ static int _mv88e6xxx_port_state(struct mv88e6xxx_chip *chip, int port, ...@@ -1150,7 +1107,7 @@ static int _mv88e6xxx_port_state(struct mv88e6xxx_chip *chip, int port,
static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port) static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
{ {
struct net_device *bridge = chip->ports[port].bridge_dev; struct net_device *bridge = chip->ports[port].bridge_dev;
const u16 mask = (1 << chip->info->num_ports) - 1; const u16 mask = (1 << mv88e6xxx_num_ports(chip)) - 1;
struct dsa_switch *ds = chip->ds; struct dsa_switch *ds = chip->ds;
u16 output_ports = 0; u16 output_ports = 0;
u16 reg; u16 reg;
...@@ -1161,7 +1118,7 @@ static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port) ...@@ -1161,7 +1118,7 @@ static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int 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)) {
output_ports = mask; output_ports = mask;
} else { } else {
for (i = 0; i < chip->info->num_ports; ++i) { for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
/* allow sending frames to every group member */ /* allow sending frames to every group member */
if (bridge && chip->ports[i].bridge_dev == bridge) if (bridge && chip->ports[i].bridge_dev == bridge)
output_ports |= BIT(i); output_ports |= BIT(i);
...@@ -1277,17 +1234,16 @@ static int _mv88e6xxx_port_pvid_set(struct mv88e6xxx_chip *chip, ...@@ -1277,17 +1234,16 @@ static int _mv88e6xxx_port_pvid_set(struct mv88e6xxx_chip *chip,
static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip) static int _mv88e6xxx_vtu_wait(struct mv88e6xxx_chip *chip)
{ {
return mv88e6xxx_wait(chip, REG_GLOBAL, GLOBAL_VTU_OP, return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY);
GLOBAL_VTU_OP_BUSY);
} }
static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op) static int _mv88e6xxx_vtu_cmd(struct mv88e6xxx_chip *chip, u16 op)
{ {
int ret; int err;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_OP, op); err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op);
if (ret < 0) if (err)
return ret; return err;
return _mv88e6xxx_vtu_wait(chip); return _mv88e6xxx_vtu_wait(chip);
} }
...@@ -1304,23 +1260,21 @@ static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip) ...@@ -1304,23 +1260,21 @@ static int _mv88e6xxx_vtu_stu_flush(struct mv88e6xxx_chip *chip)
} }
static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry, struct mv88e6xxx_vtu_entry *entry,
unsigned int nibble_offset) unsigned int nibble_offset)
{ {
u16 regs[3]; u16 regs[3];
int i; int i, err;
int ret;
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, u16 *reg = &regs[i];
GLOBAL_VTU_DATA_0_3 + i);
if (ret < 0)
return ret;
regs[i] = ret; err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
if (err)
return err;
} }
for (i = 0; i < chip->info->num_ports; ++i) { for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
unsigned int shift = (i % 4) * 4 + nibble_offset; unsigned int shift = (i % 4) * 4 + nibble_offset;
u16 reg = regs[i / 4]; u16 reg = regs[i / 4];
...@@ -1331,26 +1285,25 @@ static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip, ...@@ -1331,26 +1285,25 @@ static int _mv88e6xxx_vtu_stu_data_read(struct mv88e6xxx_chip *chip,
} }
static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip, static int mv88e6xxx_vtu_data_read(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0); return _mv88e6xxx_vtu_stu_data_read(chip, entry, 0);
} }
static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip, static int mv88e6xxx_stu_data_read(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2); return _mv88e6xxx_vtu_stu_data_read(chip, entry, 2);
} }
static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry, struct mv88e6xxx_vtu_entry *entry,
unsigned int nibble_offset) unsigned int nibble_offset)
{ {
u16 regs[3] = { 0 }; u16 regs[3] = { 0 };
int i; int i, err;
int ret;
for (i = 0; i < chip->info->num_ports; ++i) { for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
unsigned int shift = (i % 4) * 4 + nibble_offset; unsigned int shift = (i % 4) * 4 + nibble_offset;
u8 data = entry->data[i]; u8 data = entry->data[i];
...@@ -1358,86 +1311,85 @@ static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip, ...@@ -1358,86 +1311,85 @@ static int _mv88e6xxx_vtu_stu_data_write(struct mv88e6xxx_chip *chip,
} }
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, u16 reg = regs[i];
GLOBAL_VTU_DATA_0_3 + i, regs[i]);
if (ret < 0) err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_DATA_0_3 + i, reg);
return ret; if (err)
return err;
} }
return 0; return 0;
} }
static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip, static int mv88e6xxx_vtu_data_write(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0); return _mv88e6xxx_vtu_stu_data_write(chip, entry, 0);
} }
static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip, static int mv88e6xxx_stu_data_write(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2); return _mv88e6xxx_vtu_stu_data_write(chip, entry, 2);
} }
static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid) static int _mv88e6xxx_vtu_vid_write(struct mv88e6xxx_chip *chip, u16 vid)
{ {
return _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_VID, return mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID,
vid & GLOBAL_VTU_VID_MASK); vid & GLOBAL_VTU_VID_MASK);
} }
static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_vtu_getnext(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
struct mv88e6xxx_vtu_stu_entry next = { 0 }; struct mv88e6xxx_vtu_entry next = { 0 };
int ret; u16 val;
int err;
ret = _mv88e6xxx_vtu_wait(chip); err = _mv88e6xxx_vtu_wait(chip);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT); err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_VTU_GET_NEXT);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_VTU_VID); err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
if (ret < 0) if (err)
return ret; return err;
next.vid = ret & GLOBAL_VTU_VID_MASK; next.vid = val & GLOBAL_VTU_VID_MASK;
next.valid = !!(ret & GLOBAL_VTU_VID_VALID); next.valid = !!(val & GLOBAL_VTU_VID_VALID);
if (next.valid) { if (next.valid) {
ret = mv88e6xxx_vtu_data_read(chip, &next); err = mv88e6xxx_vtu_data_read(chip, &next);
if (ret < 0) if (err)
return ret; return err;
if (mv88e6xxx_has_fid_reg(chip)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val);
GLOBAL_VTU_FID); if (err)
if (ret < 0) return err;
return ret;
next.fid = ret & GLOBAL_VTU_FID_MASK; next.fid = val & GLOBAL_VTU_FID_MASK;
} else if (mv88e6xxx_num_databases(chip) == 256) { } else if (mv88e6xxx_num_databases(chip) == 256) {
/* VTU DBNum[7:4] are located in VTU Operation 11:8, and /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
* VTU DBNum[3:0] are located in VTU Operation 3:0 * VTU DBNum[3:0] are located in VTU Operation 3:0
*/ */
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_OP, &val);
GLOBAL_VTU_OP); if (err)
if (ret < 0) return err;
return ret;
next.fid = (ret & 0xf00) >> 4; next.fid = (val & 0xf00) >> 4;
next.fid |= ret & 0xf; next.fid |= val & 0xf;
} }
if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
GLOBAL_VTU_SID); if (err)
if (ret < 0) return err;
return ret;
next.sid = ret & GLOBAL_VTU_SID_MASK; next.sid = val & GLOBAL_VTU_SID_MASK;
} }
} }
...@@ -1450,7 +1402,7 @@ static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port, ...@@ -1450,7 +1402,7 @@ static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
int (*cb)(struct switchdev_obj *obj)) int (*cb)(struct switchdev_obj *obj))
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
struct mv88e6xxx_vtu_stu_entry next; struct mv88e6xxx_vtu_entry next;
u16 pvid; u16 pvid;
int err; int err;
...@@ -1501,38 +1453,36 @@ static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port, ...@@ -1501,38 +1453,36 @@ static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
} }
static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE; u16 op = GLOBAL_VTU_OP_VTU_LOAD_PURGE;
u16 reg = 0; u16 reg = 0;
int ret; int err;
ret = _mv88e6xxx_vtu_wait(chip); err = _mv88e6xxx_vtu_wait(chip);
if (ret < 0) if (err)
return ret; return err;
if (!entry->valid) if (!entry->valid)
goto loadpurge; goto loadpurge;
/* Write port member tags */ /* Write port member tags */
ret = mv88e6xxx_vtu_data_write(chip, entry); err = mv88e6xxx_vtu_data_write(chip, entry);
if (ret < 0) if (err)
return ret; return err;
if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_STU)) {
reg = entry->sid & GLOBAL_VTU_SID_MASK; reg = entry->sid & GLOBAL_VTU_SID_MASK;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_SID, err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
reg); if (err)
if (ret < 0) return err;
return ret;
} }
if (mv88e6xxx_has_fid_reg(chip)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G1_VTU_FID)) {
reg = entry->fid & GLOBAL_VTU_FID_MASK; reg = entry->fid & GLOBAL_VTU_FID_MASK;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_FID, err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, reg);
reg); if (err)
if (ret < 0) return err;
return ret;
} else if (mv88e6xxx_num_databases(chip) == 256) { } else if (mv88e6xxx_num_databases(chip) == 256) {
/* VTU DBNum[7:4] are located in VTU Operation 11:8, and /* VTU DBNum[7:4] are located in VTU Operation 11:8, and
* VTU DBNum[3:0] are located in VTU Operation 3:0 * VTU DBNum[3:0] are located in VTU Operation 3:0
...@@ -1544,48 +1494,49 @@ static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip, ...@@ -1544,48 +1494,49 @@ static int _mv88e6xxx_vtu_loadpurge(struct mv88e6xxx_chip *chip,
reg = GLOBAL_VTU_VID_VALID; reg = GLOBAL_VTU_VID_VALID;
loadpurge: loadpurge:
reg |= entry->vid & GLOBAL_VTU_VID_MASK; reg |= entry->vid & GLOBAL_VTU_VID_MASK;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_VID, reg); err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
if (ret < 0) if (err)
return ret; return err;
return _mv88e6xxx_vtu_cmd(chip, op); return _mv88e6xxx_vtu_cmd(chip, op);
} }
static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid, static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
struct mv88e6xxx_vtu_stu_entry next = { 0 }; struct mv88e6xxx_vtu_entry next = { 0 };
int ret; u16 val;
int err;
ret = _mv88e6xxx_vtu_wait(chip); err = _mv88e6xxx_vtu_wait(chip);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_SID, err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID,
sid & GLOBAL_VTU_SID_MASK); sid & GLOBAL_VTU_SID_MASK);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT); err = _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_GET_NEXT);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_VTU_SID); err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val);
if (ret < 0) if (err)
return ret; return err;
next.sid = ret & GLOBAL_VTU_SID_MASK; next.sid = val & GLOBAL_VTU_SID_MASK;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_VTU_VID); err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_VID, &val);
if (ret < 0) if (err)
return ret; return err;
next.valid = !!(ret & GLOBAL_VTU_VID_VALID); next.valid = !!(val & GLOBAL_VTU_VID_VALID);
if (next.valid) { if (next.valid) {
ret = mv88e6xxx_stu_data_read(chip, &next); err = mv88e6xxx_stu_data_read(chip, &next);
if (ret < 0) if (err)
return ret; return err;
} }
*entry = next; *entry = next;
...@@ -1593,33 +1544,33 @@ static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid, ...@@ -1593,33 +1544,33 @@ static int _mv88e6xxx_stu_getnext(struct mv88e6xxx_chip *chip, u8 sid,
} }
static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_stu_loadpurge(struct mv88e6xxx_chip *chip,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
u16 reg = 0; u16 reg = 0;
int ret; int err;
ret = _mv88e6xxx_vtu_wait(chip); err = _mv88e6xxx_vtu_wait(chip);
if (ret < 0) if (err)
return ret; return err;
if (!entry->valid) if (!entry->valid)
goto loadpurge; goto loadpurge;
/* Write port states */ /* Write port states */
ret = mv88e6xxx_stu_data_write(chip, entry); err = mv88e6xxx_stu_data_write(chip, entry);
if (ret < 0) if (err)
return ret; return err;
reg = GLOBAL_VTU_VID_VALID; reg = GLOBAL_VTU_VID_VALID;
loadpurge: loadpurge:
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_VID, reg); err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_VID, reg);
if (ret < 0) if (err)
return ret; return err;
reg = entry->sid & GLOBAL_VTU_SID_MASK; reg = entry->sid & GLOBAL_VTU_SID_MASK;
ret = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_VTU_SID, reg); err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, reg);
if (ret < 0) if (err)
return ret; return err;
return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE); return _mv88e6xxx_vtu_cmd(chip, GLOBAL_VTU_OP_STU_LOAD_PURGE);
} }
...@@ -1696,13 +1647,13 @@ static int _mv88e6xxx_port_fid_set(struct mv88e6xxx_chip *chip, ...@@ -1696,13 +1647,13 @@ static int _mv88e6xxx_port_fid_set(struct mv88e6xxx_chip *chip,
static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid) static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
{ {
DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID); DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID);
struct mv88e6xxx_vtu_stu_entry vlan; struct mv88e6xxx_vtu_entry vlan;
int i, err; int i, err;
bitmap_zero(fid_bitmap, MV88E6XXX_N_FID); bitmap_zero(fid_bitmap, MV88E6XXX_N_FID);
/* Set every FID bit used by the (un)bridged ports */ /* Set every FID bit used by the (un)bridged ports */
for (i = 0; i < chip->info->num_ports; ++i) { for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
err = _mv88e6xxx_port_fid_get(chip, i, fid); err = _mv88e6xxx_port_fid_get(chip, i, fid);
if (err) if (err)
return err; return err;
...@@ -1738,10 +1689,10 @@ static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid) ...@@ -1738,10 +1689,10 @@ static int _mv88e6xxx_fid_new(struct mv88e6xxx_chip *chip, u16 *fid)
} }
static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid, static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
struct mv88e6xxx_vtu_stu_entry *entry) struct mv88e6xxx_vtu_entry *entry)
{ {
struct dsa_switch *ds = chip->ds; struct dsa_switch *ds = chip->ds;
struct mv88e6xxx_vtu_stu_entry vlan = { struct mv88e6xxx_vtu_entry vlan = {
.valid = true, .valid = true,
.vid = vid, .vid = vid,
}; };
...@@ -1752,14 +1703,14 @@ static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid, ...@@ -1752,14 +1703,14 @@ static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
return err; return err;
/* exclude all ports except the CPU and DSA ports */ /* exclude all ports except the CPU and DSA ports */
for (i = 0; i < chip->info->num_ports; ++i) for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i) vlan.data[i] = dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)
? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED ? GLOBAL_VTU_DATA_MEMBER_TAG_UNMODIFIED
: GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER; : GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER;
if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) || if (mv88e6xxx_6097_family(chip) || mv88e6xxx_6165_family(chip) ||
mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) { mv88e6xxx_6351_family(chip) || mv88e6xxx_6352_family(chip)) {
struct mv88e6xxx_vtu_stu_entry vstp; struct mv88e6xxx_vtu_entry vstp;
/* Adding a VTU entry requires a valid STU entry. As VSTP is not /* Adding a VTU entry requires a valid STU entry. As VSTP is not
* implemented, only one STU entry is needed to cover all VTU * implemented, only one STU entry is needed to cover all VTU
...@@ -1786,7 +1737,7 @@ static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid, ...@@ -1786,7 +1737,7 @@ static int _mv88e6xxx_vtu_new(struct mv88e6xxx_chip *chip, u16 vid,
} }
static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid, static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
struct mv88e6xxx_vtu_stu_entry *entry, bool creat) struct mv88e6xxx_vtu_entry *entry, bool creat)
{ {
int err; int err;
...@@ -1818,7 +1769,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, ...@@ -1818,7 +1769,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
u16 vid_begin, u16 vid_end) u16 vid_begin, u16 vid_end)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
struct mv88e6xxx_vtu_stu_entry vlan; struct mv88e6xxx_vtu_entry vlan;
int i, err; int i, err;
if (!vid_begin) if (!vid_begin)
...@@ -1841,7 +1792,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, ...@@ -1841,7 +1792,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
if (vlan.vid > vid_end) if (vlan.vid > vid_end)
break; break;
for (i = 0; i < chip->info->num_ports; ++i) { for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i)) if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
continue; continue;
...@@ -1943,7 +1894,7 @@ mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port, ...@@ -1943,7 +1894,7 @@ mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port, static int _mv88e6xxx_port_vlan_add(struct mv88e6xxx_chip *chip, int port,
u16 vid, bool untagged) u16 vid, bool untagged)
{ {
struct mv88e6xxx_vtu_stu_entry vlan; struct mv88e6xxx_vtu_entry vlan;
int err; int err;
err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true); err = _mv88e6xxx_vtu_get(chip, vid, &vlan, true);
...@@ -1988,7 +1939,7 @@ static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip, ...@@ -1988,7 +1939,7 @@ static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
int port, u16 vid) int port, u16 vid)
{ {
struct dsa_switch *ds = chip->ds; struct dsa_switch *ds = chip->ds;
struct mv88e6xxx_vtu_stu_entry vlan; struct mv88e6xxx_vtu_entry vlan;
int i, err; int i, err;
err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false); err = _mv88e6xxx_vtu_get(chip, vid, &vlan, false);
...@@ -2003,7 +1954,7 @@ static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip, ...@@ -2003,7 +1954,7 @@ static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
/* keep the VLAN unless all ports are excluded */ /* keep the VLAN unless all ports are excluded */
vlan.valid = false; vlan.valid = false;
for (i = 0; i < chip->info->num_ports; ++i) { for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i)) if (dsa_is_cpu_port(ds, i) || dsa_is_dsa_port(ds, i))
continue; continue;
...@@ -2057,14 +2008,13 @@ static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, ...@@ -2057,14 +2008,13 @@ static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
const unsigned char *addr) const unsigned char *addr)
{ {
int i, ret; int i, err;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
ret = _mv88e6xxx_reg_write( err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_MAC_01 + i,
chip, REG_GLOBAL, GLOBAL_ATU_MAC_01 + i, (addr[i * 2] << 8) | addr[i * 2 + 1]);
(addr[i * 2] << 8) | addr[i * 2 + 1]); if (err)
if (ret < 0) return err;
return ret;
} }
return 0; return 0;
...@@ -2073,15 +2023,16 @@ static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip, ...@@ -2073,15 +2023,16 @@ static int _mv88e6xxx_atu_mac_write(struct mv88e6xxx_chip *chip,
static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip, static int _mv88e6xxx_atu_mac_read(struct mv88e6xxx_chip *chip,
unsigned char *addr) unsigned char *addr)
{ {
int i, ret; u16 val;
int i, err;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_MAC_01 + i, &val);
GLOBAL_ATU_MAC_01 + i); if (err)
if (ret < 0) return err;
return ret;
addr[i * 2] = ret >> 8; addr[i * 2] = val >> 8;
addr[i * 2 + 1] = ret & 0xff; addr[i * 2 + 1] = val & 0xff;
} }
return 0; return 0;
...@@ -2147,7 +2098,7 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, ...@@ -2147,7 +2098,7 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
const unsigned char *addr, u16 vid, const unsigned char *addr, u16 vid,
u8 state) u8 state)
{ {
struct mv88e6xxx_vtu_stu_entry vlan; struct mv88e6xxx_vtu_entry vlan;
struct mv88e6xxx_atu_entry entry; struct mv88e6xxx_atu_entry entry;
int err; int err;
...@@ -2217,31 +2168,32 @@ static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid, ...@@ -2217,31 +2168,32 @@ static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
struct mv88e6xxx_atu_entry *entry) struct mv88e6xxx_atu_entry *entry)
{ {
struct mv88e6xxx_atu_entry next = { 0 }; struct mv88e6xxx_atu_entry next = { 0 };
int ret; u16 val;
int err;
next.fid = fid; next.fid = fid;
ret = _mv88e6xxx_atu_wait(chip); err = _mv88e6xxx_atu_wait(chip);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB); err = _mv88e6xxx_atu_cmd(chip, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_atu_mac_read(chip, next.mac); err = _mv88e6xxx_atu_mac_read(chip, next.mac);
if (ret < 0) if (err)
return ret; return err;
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, GLOBAL_ATU_DATA); err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_DATA, &val);
if (ret < 0) if (err)
return ret; return err;
next.state = ret & GLOBAL_ATU_DATA_STATE_MASK; next.state = val & GLOBAL_ATU_DATA_STATE_MASK;
if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) { if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
unsigned int mask, shift; unsigned int mask, shift;
if (ret & GLOBAL_ATU_DATA_TRUNK) { if (val & GLOBAL_ATU_DATA_TRUNK) {
next.trunk = true; next.trunk = true;
mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK; mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT; shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
...@@ -2251,7 +2203,7 @@ static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid, ...@@ -2251,7 +2203,7 @@ static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT; shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
} }
next.portv_trunkid = (ret & mask) >> shift; next.portv_trunkid = (val & mask) >> shift;
} }
*entry = next; *entry = next;
...@@ -2321,7 +2273,7 @@ static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port, ...@@ -2321,7 +2273,7 @@ static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
struct switchdev_obj *obj, struct switchdev_obj *obj,
int (*cb)(struct switchdev_obj *obj)) int (*cb)(struct switchdev_obj *obj))
{ {
struct mv88e6xxx_vtu_stu_entry vlan = { struct mv88e6xxx_vtu_entry vlan = {
.vid = GLOBAL_VTU_VID_MASK, /* all ones */ .vid = GLOBAL_VTU_VID_MASK, /* all ones */
}; };
u16 fid; u16 fid;
...@@ -2383,7 +2335,7 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -2383,7 +2335,7 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
/* Assign the bridge and remap each port's VLANTable */ /* Assign the bridge and remap each port's VLANTable */
chip->ports[port].bridge_dev = bridge; chip->ports[port].bridge_dev = bridge;
for (i = 0; i < chip->info->num_ports; ++i) { for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
if (chip->ports[i].bridge_dev == bridge) { if (chip->ports[i].bridge_dev == bridge) {
err = _mv88e6xxx_port_based_vlan_map(chip, i); err = _mv88e6xxx_port_based_vlan_map(chip, i);
if (err) if (err)
...@@ -2407,7 +2359,7 @@ static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port) ...@@ -2407,7 +2359,7 @@ static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
/* Unassign the bridge and remap each port's VLANTable */ /* Unassign the bridge and remap each port's VLANTable */
chip->ports[port].bridge_dev = NULL; chip->ports[port].bridge_dev = NULL;
for (i = 0; i < chip->info->num_ports; ++i) for (i = 0; i < mv88e6xxx_num_ports(chip); ++i)
if (i == port || chip->ports[i].bridge_dev == bridge) if (i == port || chip->ports[i].bridge_dev == bridge)
if (_mv88e6xxx_port_based_vlan_map(chip, i)) if (_mv88e6xxx_port_based_vlan_map(chip, i))
netdev_warn(ds->ports[i].netdev, netdev_warn(ds->ports[i].netdev,
...@@ -2422,12 +2374,12 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip) ...@@ -2422,12 +2374,12 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
u16 is_reset = (ppu_active ? 0x8800 : 0xc800); u16 is_reset = (ppu_active ? 0x8800 : 0xc800);
struct gpio_desc *gpiod = chip->reset; struct gpio_desc *gpiod = chip->reset;
unsigned long timeout; unsigned long timeout;
int err, ret;
u16 reg; u16 reg;
int err;
int i; int i;
/* Set all ports to the disabled state. */ /* Set all ports to the disabled state. */
for (i = 0; i < chip->info->num_ports; i++) { for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
err = mv88e6xxx_port_read(chip, i, PORT_CONTROL, &reg); err = mv88e6xxx_port_read(chip, i, PORT_CONTROL, &reg);
if (err) if (err)
return err; return err;
...@@ -2454,20 +2406,20 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip) ...@@ -2454,20 +2406,20 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
* through global registers 0x18 and 0x19. * through global registers 0x18 and 0x19.
*/ */
if (ppu_active) if (ppu_active)
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, 0x04, 0xc000); err = mv88e6xxx_g1_write(chip, 0x04, 0xc000);
else else
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, 0x04, 0xc400); err = mv88e6xxx_g1_write(chip, 0x04, 0xc400);
if (err) if (err)
return err; return err;
/* Wait up to one second for reset to complete. */ /* Wait up to one second for reset to complete. */
timeout = jiffies + 1 * HZ; timeout = jiffies + 1 * HZ;
while (time_before(jiffies, timeout)) { while (time_before(jiffies, timeout)) {
ret = _mv88e6xxx_reg_read(chip, REG_GLOBAL, 0x00); err = mv88e6xxx_g1_read(chip, 0x00, &reg);
if (ret < 0) if (err)
return ret; return err;
if ((ret & is_reset) == is_reset) if ((reg & is_reset) == is_reset)
break; break;
usleep_range(1000, 2000); usleep_range(1000, 2000);
} }
...@@ -2749,22 +2701,23 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) ...@@ -2749,22 +2701,23 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000); return mv88e6xxx_port_write(chip, port, PORT_DEFAULT_VLAN, 0x0000);
} }
static int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr) int mv88e6xxx_g1_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
{ {
int err; int err;
err = mv88e6xxx_write(chip, REG_GLOBAL, GLOBAL_MAC_01, err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_01, (addr[0] << 8) | addr[1]);
(addr[0] << 8) | addr[1]); if (err)
return err;
err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_23, (addr[2] << 8) | addr[3]);
if (err) if (err)
return err; return err;
err = mv88e6xxx_write(chip, REG_GLOBAL, GLOBAL_MAC_23, err = mv88e6xxx_g1_write(chip, GLOBAL_MAC_45, (addr[4] << 8) | addr[5]);
(addr[2] << 8) | addr[3]);
if (err) if (err)
return err; return err;
return mv88e6xxx_write(chip, REG_GLOBAL, GLOBAL_MAC_45, return 0;
(addr[4] << 8) | addr[5]);
} }
static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip, static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
...@@ -2783,7 +2736,7 @@ static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip, ...@@ -2783,7 +2736,7 @@ static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
/* Round to nearest multiple of coeff */ /* Round to nearest multiple of coeff */
age_time = (msecs + coeff / 2) / coeff; age_time = (msecs + coeff / 2) / coeff;
err = mv88e6xxx_read(chip, REG_GLOBAL, GLOBAL_ATU_CONTROL, &val); err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
if (err) if (err)
return err; return err;
...@@ -2791,7 +2744,7 @@ static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip, ...@@ -2791,7 +2744,7 @@ static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
val &= ~0xff0; val &= ~0xff0;
val |= age_time << 4; val |= age_time << 4;
return mv88e6xxx_write(chip, REG_GLOBAL, GLOBAL_ATU_CONTROL, val); return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
} }
static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds, static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
...@@ -2822,7 +2775,7 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip) ...@@ -2822,7 +2775,7 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE)) mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU_ACTIVE))
reg |= GLOBAL_CONTROL_PPU_ENABLE; reg |= GLOBAL_CONTROL_PPU_ENABLE;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_CONTROL, reg); err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL, reg);
if (err) if (err)
return err; return err;
...@@ -2832,15 +2785,14 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip) ...@@ -2832,15 +2785,14 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT | reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT | upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT; upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, err = mv88e6xxx_g1_write(chip, GLOBAL_MONITOR_CONTROL, reg);
reg);
if (err) if (err)
return err; return err;
/* Disable remote management, and set the switch's DSA device number. */ /* Disable remote management, and set the switch's DSA device number. */
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_CONTROL_2, err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2,
GLOBAL_CONTROL_2_MULTIPLE_CASCADE | GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
(ds->index & 0x1f)); (ds->index & 0x1f));
if (err) if (err)
return err; return err;
...@@ -2853,8 +2805,8 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip) ...@@ -2853,8 +2805,8 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
* enable address learn messages to be sent to all message * enable address learn messages to be sent to all message
* ports. * ports.
*/ */
err = mv88e6xxx_write(chip, REG_GLOBAL, GLOBAL_ATU_CONTROL, err = mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL,
GLOBAL_ATU_CONTROL_LEARN2ALL); GLOBAL_ATU_CONTROL_LEARN2ALL);
if (err) if (err)
return err; return err;
...@@ -2868,39 +2820,39 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip) ...@@ -2868,39 +2820,39 @@ static int mv88e6xxx_g1_setup(struct mv88e6xxx_chip *chip)
return err; return err;
/* Configure the IP ToS mapping registers. */ /* Configure the IP ToS mapping registers. */
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_0, 0x0000); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_0, 0x0000);
if (err) if (err)
return err; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_1, 0x0000); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_1, 0x0000);
if (err) if (err)
return err; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_2, 0x5555); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_2, 0x5555);
if (err) if (err)
return err; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_3, 0x5555); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_3, 0x5555);
if (err) if (err)
return err; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_4, 0xaaaa); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_4, 0xaaaa);
if (err) if (err)
return err; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_5, 0xaaaa); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_5, 0xaaaa);
if (err) if (err)
return err; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_6, 0xffff); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_6, 0xffff);
if (err) if (err)
return err; return err;
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IP_PRI_7, 0xffff); err = mv88e6xxx_g1_write(chip, GLOBAL_IP_PRI_7, 0xffff);
if (err) if (err)
return err; return err;
/* Configure the IEEE 802.1p priority mapping register. */ /* Configure the IEEE 802.1p priority mapping register. */
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_IEEE_PRI, 0xfa41); err = mv88e6xxx_g1_write(chip, GLOBAL_IEEE_PRI, 0xfa41);
if (err) if (err)
return err; return err;
/* Clear the statistics counters for all ports */ /* Clear the statistics counters for all ports */
err = _mv88e6xxx_reg_write(chip, REG_GLOBAL, GLOBAL_STATS_OP, err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP,
GLOBAL_STATS_OP_FLUSH_ALL); GLOBAL_STATS_OP_FLUSH_ALL);
if (err) if (err)
return err; return err;
...@@ -2928,7 +2880,7 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) ...@@ -2928,7 +2880,7 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
goto unlock; goto unlock;
/* Setup Switch Port Registers */ /* Setup Switch Port Registers */
for (i = 0; i < chip->info->num_ports; i++) { for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
err = mv88e6xxx_setup_port(chip, i); err = mv88e6xxx_setup_port(chip, i);
if (err) if (err)
goto unlock; goto unlock;
...@@ -2957,14 +2909,11 @@ static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr) ...@@ -2957,14 +2909,11 @@ static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
mutex_lock(&chip->reg_lock); if (!chip->info->ops->set_switch_mac)
return -EOPNOTSUPP;
/* Has an indirect Switch MAC/WoL/WoF register in Global 2? */
if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_SWITCH_MAC))
err = mv88e6xxx_g2_set_switch_mac(chip, addr);
else
err = mv88e6xxx_g1_set_switch_mac(chip, addr);
mutex_lock(&chip->reg_lock);
err = chip->info->ops->set_switch_mac(chip, addr);
mutex_unlock(&chip->reg_lock); mutex_unlock(&chip->reg_lock);
return err; return err;
...@@ -2976,7 +2925,7 @@ static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg) ...@@ -2976,7 +2925,7 @@ static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
u16 val; u16 val;
int err; int err;
if (phy >= chip->info->num_ports) if (phy >= mv88e6xxx_num_ports(chip))
return 0xffff; return 0xffff;
mutex_lock(&chip->reg_lock); mutex_lock(&chip->reg_lock);
...@@ -2991,7 +2940,7 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) ...@@ -2991,7 +2940,7 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
struct mv88e6xxx_chip *chip = bus->priv; struct mv88e6xxx_chip *chip = bus->priv;
int err; int err;
if (phy >= chip->info->num_ports) if (phy >= mv88e6xxx_num_ports(chip))
return 0xffff; return 0xffff;
mutex_lock(&chip->reg_lock); mutex_lock(&chip->reg_lock);
...@@ -3219,13 +3168,11 @@ static int mv88e6xxx_get_eeprom(struct dsa_switch *ds, ...@@ -3219,13 +3168,11 @@ static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
mutex_lock(&chip->reg_lock); if (!chip->info->ops->get_eeprom)
return -EOPNOTSUPP;
if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_EEPROM16))
err = mv88e6xxx_g2_get_eeprom16(chip, eeprom, data);
else
err = -EOPNOTSUPP;
mutex_lock(&chip->reg_lock);
err = chip->info->ops->get_eeprom(chip, eeprom, data);
mutex_unlock(&chip->reg_lock); mutex_unlock(&chip->reg_lock);
if (err) if (err)
...@@ -3242,21 +3189,133 @@ static int mv88e6xxx_set_eeprom(struct dsa_switch *ds, ...@@ -3242,21 +3189,133 @@ static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int err; int err;
if (!chip->info->ops->set_eeprom)
return -EOPNOTSUPP;
if (eeprom->magic != 0xc3ec4951) if (eeprom->magic != 0xc3ec4951)
return -EINVAL; return -EINVAL;
mutex_lock(&chip->reg_lock); mutex_lock(&chip->reg_lock);
err = chip->info->ops->set_eeprom(chip, eeprom, data);
if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_EEPROM16))
err = mv88e6xxx_g2_set_eeprom16(chip, eeprom, data);
else
err = -EOPNOTSUPP;
mutex_unlock(&chip->reg_lock); mutex_unlock(&chip->reg_lock);
return err; return err;
} }
static const struct mv88e6xxx_ops mv88e6085_ops = {
.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
.phy_read = mv88e6xxx_phy_ppu_read,
.phy_write = mv88e6xxx_phy_ppu_write,
};
static const struct mv88e6xxx_ops mv88e6095_ops = {
.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
.phy_read = mv88e6xxx_phy_ppu_read,
.phy_write = mv88e6xxx_phy_ppu_write,
};
static const struct mv88e6xxx_ops mv88e6123_ops = {
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_read,
.phy_write = mv88e6xxx_write,
};
static const struct mv88e6xxx_ops mv88e6131_ops = {
.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
.phy_read = mv88e6xxx_phy_ppu_read,
.phy_write = mv88e6xxx_phy_ppu_write,
};
static const struct mv88e6xxx_ops mv88e6161_ops = {
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_read,
.phy_write = mv88e6xxx_write,
};
static const struct mv88e6xxx_ops mv88e6165_ops = {
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_read,
.phy_write = mv88e6xxx_write,
};
static const struct mv88e6xxx_ops mv88e6171_ops = {
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6172_ops = {
.get_eeprom = mv88e6xxx_g2_get_eeprom16,
.set_eeprom = mv88e6xxx_g2_set_eeprom16,
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6175_ops = {
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6176_ops = {
.get_eeprom = mv88e6xxx_g2_get_eeprom16,
.set_eeprom = mv88e6xxx_g2_set_eeprom16,
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6185_ops = {
.set_switch_mac = mv88e6xxx_g1_set_switch_mac,
.phy_read = mv88e6xxx_phy_ppu_read,
.phy_write = mv88e6xxx_phy_ppu_write,
};
static const struct mv88e6xxx_ops mv88e6240_ops = {
.get_eeprom = mv88e6xxx_g2_get_eeprom16,
.set_eeprom = mv88e6xxx_g2_set_eeprom16,
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6320_ops = {
.get_eeprom = mv88e6xxx_g2_get_eeprom16,
.set_eeprom = mv88e6xxx_g2_set_eeprom16,
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6321_ops = {
.get_eeprom = mv88e6xxx_g2_get_eeprom16,
.set_eeprom = mv88e6xxx_g2_set_eeprom16,
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6350_ops = {
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6351_ops = {
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6352_ops = {
.get_eeprom = mv88e6xxx_g2_get_eeprom16,
.set_eeprom = mv88e6xxx_g2_set_eeprom16,
.set_switch_mac = mv88e6xxx_g2_set_switch_mac,
.phy_read = mv88e6xxx_g2_smi_phy_read,
.phy_write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_info mv88e6xxx_table[] = { static const struct mv88e6xxx_info mv88e6xxx_table[] = {
[MV88E6085] = { [MV88E6085] = {
.prod_num = PORT_SWITCH_ID_PROD_NUM_6085, .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
...@@ -3265,8 +3324,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3265,8 +3324,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 10, .num_ports = 10,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6097, .flags = MV88E6XXX_FLAGS_FAMILY_6097,
.ops = &mv88e6085_ops,
}, },
[MV88E6095] = { [MV88E6095] = {
...@@ -3276,8 +3337,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3276,8 +3337,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 256, .num_databases = 256,
.num_ports = 11, .num_ports = 11,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6095, .flags = MV88E6XXX_FLAGS_FAMILY_6095,
.ops = &mv88e6095_ops,
}, },
[MV88E6123] = { [MV88E6123] = {
...@@ -3287,8 +3350,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3287,8 +3350,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 3, .num_ports = 3,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6165, .flags = MV88E6XXX_FLAGS_FAMILY_6165,
.ops = &mv88e6123_ops,
}, },
[MV88E6131] = { [MV88E6131] = {
...@@ -3298,8 +3363,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3298,8 +3363,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 256, .num_databases = 256,
.num_ports = 8, .num_ports = 8,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6185, .flags = MV88E6XXX_FLAGS_FAMILY_6185,
.ops = &mv88e6131_ops,
}, },
[MV88E6161] = { [MV88E6161] = {
...@@ -3309,8 +3376,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3309,8 +3376,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 6, .num_ports = 6,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6165, .flags = MV88E6XXX_FLAGS_FAMILY_6165,
.ops = &mv88e6161_ops,
}, },
[MV88E6165] = { [MV88E6165] = {
...@@ -3320,8 +3389,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3320,8 +3389,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 6, .num_ports = 6,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6165, .flags = MV88E6XXX_FLAGS_FAMILY_6165,
.ops = &mv88e6165_ops,
}, },
[MV88E6171] = { [MV88E6171] = {
...@@ -3331,8 +3402,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3331,8 +3402,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6351, .flags = MV88E6XXX_FLAGS_FAMILY_6351,
.ops = &mv88e6171_ops,
}, },
[MV88E6172] = { [MV88E6172] = {
...@@ -3342,8 +3415,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3342,8 +3415,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6352, .flags = MV88E6XXX_FLAGS_FAMILY_6352,
.ops = &mv88e6172_ops,
}, },
[MV88E6175] = { [MV88E6175] = {
...@@ -3353,8 +3428,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3353,8 +3428,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6351, .flags = MV88E6XXX_FLAGS_FAMILY_6351,
.ops = &mv88e6175_ops,
}, },
[MV88E6176] = { [MV88E6176] = {
...@@ -3364,8 +3441,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3364,8 +3441,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6352, .flags = MV88E6XXX_FLAGS_FAMILY_6352,
.ops = &mv88e6176_ops,
}, },
[MV88E6185] = { [MV88E6185] = {
...@@ -3375,8 +3454,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3375,8 +3454,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 256, .num_databases = 256,
.num_ports = 10, .num_ports = 10,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6185, .flags = MV88E6XXX_FLAGS_FAMILY_6185,
.ops = &mv88e6185_ops,
}, },
[MV88E6240] = { [MV88E6240] = {
...@@ -3386,8 +3467,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3386,8 +3467,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6352, .flags = MV88E6XXX_FLAGS_FAMILY_6352,
.ops = &mv88e6240_ops,
}, },
[MV88E6320] = { [MV88E6320] = {
...@@ -3397,8 +3480,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3397,8 +3480,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6320, .flags = MV88E6XXX_FLAGS_FAMILY_6320,
.ops = &mv88e6320_ops,
}, },
[MV88E6321] = { [MV88E6321] = {
...@@ -3408,8 +3493,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3408,8 +3493,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6320, .flags = MV88E6XXX_FLAGS_FAMILY_6320,
.ops = &mv88e6321_ops,
}, },
[MV88E6350] = { [MV88E6350] = {
...@@ -3419,8 +3506,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3419,8 +3506,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6351, .flags = MV88E6XXX_FLAGS_FAMILY_6351,
.ops = &mv88e6350_ops,
}, },
[MV88E6351] = { [MV88E6351] = {
...@@ -3430,8 +3519,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3430,8 +3519,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6351, .flags = MV88E6XXX_FLAGS_FAMILY_6351,
.ops = &mv88e6351_ops,
}, },
[MV88E6352] = { [MV88E6352] = {
...@@ -3441,8 +3532,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { ...@@ -3441,8 +3532,10 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = {
.num_databases = 4096, .num_databases = 4096,
.num_ports = 7, .num_ports = 7,
.port_base_addr = 0x10, .port_base_addr = 0x10,
.global1_addr = 0x1b,
.age_time_coeff = 15000, .age_time_coeff = 15000,
.flags = MV88E6XXX_FLAGS_FAMILY_6352, .flags = MV88E6XXX_FLAGS_FAMILY_6352,
.ops = &mv88e6352_ops,
}, },
}; };
...@@ -3505,33 +3598,16 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev) ...@@ -3505,33 +3598,16 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
return chip; return chip;
} }
static const struct mv88e6xxx_ops mv88e6xxx_g2_smi_phy_ops = {
.read = mv88e6xxx_g2_smi_phy_read,
.write = mv88e6xxx_g2_smi_phy_write,
};
static const struct mv88e6xxx_ops mv88e6xxx_phy_ops = {
.read = mv88e6xxx_read,
.write = mv88e6xxx_write,
};
static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip) static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
{ {
if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_SMI_PHY)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
chip->phy_ops = &mv88e6xxx_g2_smi_phy_ops;
} else if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU)) {
chip->phy_ops = &mv88e6xxx_phy_ppu_ops;
mv88e6xxx_ppu_state_init(chip); mv88e6xxx_ppu_state_init(chip);
} else {
chip->phy_ops = &mv88e6xxx_phy_ops;
}
} }
static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip) static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
{ {
if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU))
mv88e6xxx_ppu_state_destroy(chip); mv88e6xxx_ppu_state_destroy(chip);
}
} }
static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip, static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
...@@ -3757,7 +3833,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) ...@@ -3757,7 +3833,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
if (IS_ERR(chip->reset)) if (IS_ERR(chip->reset))
return PTR_ERR(chip->reset); return PTR_ERR(chip->reset);
if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_EEPROM16) && if (chip->info->ops->get_eeprom &&
!of_property_read_u32(np, "eeprom-length", &eeprom_len)) !of_property_read_u32(np, "eeprom-length", &eeprom_len))
chip->eeprom_len = eeprom_len; chip->eeprom_len = eeprom_len;
......
/*
* Marvell 88E6xxx Switch Global (1) Registers support
*
* Copyright (c) 2008 Marvell Semiconductor
*
* Copyright (c) 2016 Vivien Didelot <vivien.didelot@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include "mv88e6xxx.h"
#include "global1.h"
int mv88e6xxx_g1_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
{
int addr = chip->info->global1_addr;
return mv88e6xxx_read(chip, addr, reg, val);
}
int mv88e6xxx_g1_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
{
int addr = chip->info->global1_addr;
return mv88e6xxx_write(chip, addr, reg, val);
}
int mv88e6xxx_g1_wait(struct mv88e6xxx_chip *chip, int reg, u16 mask)
{
return mv88e6xxx_wait(chip, chip->info->global1_addr, reg, mask);
}
/*
* Marvell 88E6xxx Switch Global (1) Registers support
*
* Copyright (c) 2008 Marvell Semiconductor
*
* Copyright (c) 2016 Vivien Didelot <vivien.didelot@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef _MV88E6XXX_GLOBAL1_H
#define _MV88E6XXX_GLOBAL1_H
#include "mv88e6xxx.h"
int mv88e6xxx_g1_read(struct mv88e6xxx_chip *chip, int reg, u16 *val);
int mv88e6xxx_g1_write(struct mv88e6xxx_chip *chip, int reg, u16 val);
int mv88e6xxx_g1_wait(struct mv88e6xxx_chip *chip, int reg, u16 mask);
#endif /* _MV88E6XXX_GLOBAL1_H */
...@@ -14,6 +14,28 @@ ...@@ -14,6 +14,28 @@
#include "mv88e6xxx.h" #include "mv88e6xxx.h"
#include "global2.h" #include "global2.h"
#define ADDR_GLOBAL2 0x1c
static int mv88e6xxx_g2_read(struct mv88e6xxx_chip *chip, int reg, u16 *val)
{
return mv88e6xxx_read(chip, ADDR_GLOBAL2, reg, val);
}
static int mv88e6xxx_g2_write(struct mv88e6xxx_chip *chip, int reg, u16 val)
{
return mv88e6xxx_write(chip, ADDR_GLOBAL2, reg, val);
}
static int mv88e6xxx_g2_update(struct mv88e6xxx_chip *chip, int reg, u16 update)
{
return mv88e6xxx_update(chip, ADDR_GLOBAL2, reg, update);
}
static int mv88e6xxx_g2_wait(struct mv88e6xxx_chip *chip, int reg, u16 mask)
{
return mv88e6xxx_wait(chip, ADDR_GLOBAL2, reg, mask);
}
/* Offset 0x06: Device Mapping Table register */ /* Offset 0x06: Device Mapping Table register */
static int mv88e6xxx_g2_device_mapping_write(struct mv88e6xxx_chip *chip, static int mv88e6xxx_g2_device_mapping_write(struct mv88e6xxx_chip *chip,
...@@ -21,7 +43,7 @@ static int mv88e6xxx_g2_device_mapping_write(struct mv88e6xxx_chip *chip, ...@@ -21,7 +43,7 @@ static int mv88e6xxx_g2_device_mapping_write(struct mv88e6xxx_chip *chip,
{ {
u16 val = (target << 8) | (port & 0xf); u16 val = (target << 8) | (port & 0xf);
return mv88e6xxx_update(chip, REG_GLOBAL2, GLOBAL2_DEVICE_MAPPING, val); return mv88e6xxx_g2_update(chip, GLOBAL2_DEVICE_MAPPING, val);
} }
static int mv88e6xxx_g2_set_device_mapping(struct mv88e6xxx_chip *chip) static int mv88e6xxx_g2_set_device_mapping(struct mv88e6xxx_chip *chip)
...@@ -52,13 +74,13 @@ static int mv88e6xxx_g2_set_device_mapping(struct mv88e6xxx_chip *chip) ...@@ -52,13 +74,13 @@ static int mv88e6xxx_g2_set_device_mapping(struct mv88e6xxx_chip *chip)
static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num, static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num,
bool hask, u16 mask) bool hask, u16 mask)
{ {
const u16 port_mask = BIT(chip->info->num_ports) - 1; const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1;
u16 val = (num << 12) | (mask & port_mask); u16 val = (num << 12) | (mask & port_mask);
if (hask) if (hask)
val |= GLOBAL2_TRUNK_MASK_HASK; val |= GLOBAL2_TRUNK_MASK_HASK;
return mv88e6xxx_update(chip, REG_GLOBAL2, GLOBAL2_TRUNK_MASK, val); return mv88e6xxx_g2_update(chip, GLOBAL2_TRUNK_MASK, val);
} }
/* Offset 0x08: Trunk Mapping Table register */ /* Offset 0x08: Trunk Mapping Table register */
...@@ -66,15 +88,15 @@ static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num, ...@@ -66,15 +88,15 @@ static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num,
static int mv88e6xxx_g2_trunk_mapping_write(struct mv88e6xxx_chip *chip, int id, static int mv88e6xxx_g2_trunk_mapping_write(struct mv88e6xxx_chip *chip, int id,
u16 map) u16 map)
{ {
const u16 port_mask = BIT(chip->info->num_ports) - 1; const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1;
u16 val = (id << 11) | (map & port_mask); u16 val = (id << 11) | (map & port_mask);
return mv88e6xxx_update(chip, REG_GLOBAL2, GLOBAL2_TRUNK_MAPPING, val); return mv88e6xxx_g2_update(chip, GLOBAL2_TRUNK_MAPPING, val);
} }
static int mv88e6xxx_g2_clear_trunk(struct mv88e6xxx_chip *chip) static int mv88e6xxx_g2_clear_trunk(struct mv88e6xxx_chip *chip)
{ {
const u16 port_mask = BIT(chip->info->num_ports) - 1; const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1;
int i, err; int i, err;
/* Clear all eight possible Trunk Mask vectors */ /* Clear all eight possible Trunk Mask vectors */
...@@ -103,17 +125,17 @@ static int mv88e6xxx_g2_clear_irl(struct mv88e6xxx_chip *chip) ...@@ -103,17 +125,17 @@ static int mv88e6xxx_g2_clear_irl(struct mv88e6xxx_chip *chip)
int port, err; int port, err;
/* Init all Ingress Rate Limit resources of all ports */ /* Init all Ingress Rate Limit resources of all ports */
for (port = 0; port < chip->info->num_ports; ++port) { for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
/* XXX newer chips (like 88E6390) have different 2-bit ops */ /* XXX newer chips (like 88E6390) have different 2-bit ops */
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_IRL_CMD, err = mv88e6xxx_g2_write(chip, GLOBAL2_IRL_CMD,
GLOBAL2_IRL_CMD_OP_INIT_ALL | GLOBAL2_IRL_CMD_OP_INIT_ALL |
(port << 8)); (port << 8));
if (err) if (err)
break; break;
/* Wait for the operation to complete */ /* Wait for the operation to complete */
err = mv88e6xxx_wait(chip, REG_GLOBAL2, GLOBAL2_IRL_CMD, err = mv88e6xxx_g2_wait(chip, GLOBAL2_IRL_CMD,
GLOBAL2_IRL_CMD_BUSY); GLOBAL2_IRL_CMD_BUSY);
if (err) if (err)
break; break;
} }
...@@ -128,7 +150,7 @@ static int mv88e6xxx_g2_switch_mac_write(struct mv88e6xxx_chip *chip, ...@@ -128,7 +150,7 @@ static int mv88e6xxx_g2_switch_mac_write(struct mv88e6xxx_chip *chip,
{ {
u16 val = (pointer << 8) | data; u16 val = (pointer << 8) | data;
return mv88e6xxx_update(chip, REG_GLOBAL2, GLOBAL2_SWITCH_MAC, val); return mv88e6xxx_g2_update(chip, GLOBAL2_SWITCH_MAC, val);
} }
int mv88e6xxx_g2_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr) int mv88e6xxx_g2_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr)
...@@ -151,7 +173,7 @@ static int mv88e6xxx_g2_pot_write(struct mv88e6xxx_chip *chip, int pointer, ...@@ -151,7 +173,7 @@ static int mv88e6xxx_g2_pot_write(struct mv88e6xxx_chip *chip, int pointer,
{ {
u16 val = (pointer << 8) | (data & 0x7); u16 val = (pointer << 8) | (data & 0x7);
return mv88e6xxx_update(chip, REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE, val); return mv88e6xxx_g2_update(chip, GLOBAL2_PRIO_OVERRIDE, val);
} }
static int mv88e6xxx_g2_clear_pot(struct mv88e6xxx_chip *chip) static int mv88e6xxx_g2_clear_pot(struct mv88e6xxx_chip *chip)
...@@ -174,16 +196,16 @@ static int mv88e6xxx_g2_clear_pot(struct mv88e6xxx_chip *chip) ...@@ -174,16 +196,16 @@ static int mv88e6xxx_g2_clear_pot(struct mv88e6xxx_chip *chip)
static int mv88e6xxx_g2_eeprom_wait(struct mv88e6xxx_chip *chip) static int mv88e6xxx_g2_eeprom_wait(struct mv88e6xxx_chip *chip)
{ {
return mv88e6xxx_wait(chip, REG_GLOBAL2, GLOBAL2_EEPROM_CMD, return mv88e6xxx_g2_wait(chip, GLOBAL2_EEPROM_CMD,
GLOBAL2_EEPROM_CMD_BUSY | GLOBAL2_EEPROM_CMD_BUSY |
GLOBAL2_EEPROM_CMD_RUNNING); GLOBAL2_EEPROM_CMD_RUNNING);
} }
static int mv88e6xxx_g2_eeprom_cmd(struct mv88e6xxx_chip *chip, u16 cmd) static int mv88e6xxx_g2_eeprom_cmd(struct mv88e6xxx_chip *chip, u16 cmd)
{ {
int err; int err;
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_EEPROM_CMD, cmd); err = mv88e6xxx_g2_write(chip, GLOBAL2_EEPROM_CMD, cmd);
if (err) if (err)
return err; return err;
...@@ -204,7 +226,7 @@ static int mv88e6xxx_g2_eeprom_read16(struct mv88e6xxx_chip *chip, ...@@ -204,7 +226,7 @@ static int mv88e6xxx_g2_eeprom_read16(struct mv88e6xxx_chip *chip,
if (err) if (err)
return err; return err;
return mv88e6xxx_read(chip, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data); return mv88e6xxx_g2_read(chip, GLOBAL2_EEPROM_DATA, data);
} }
static int mv88e6xxx_g2_eeprom_write16(struct mv88e6xxx_chip *chip, static int mv88e6xxx_g2_eeprom_write16(struct mv88e6xxx_chip *chip,
...@@ -217,7 +239,7 @@ static int mv88e6xxx_g2_eeprom_write16(struct mv88e6xxx_chip *chip, ...@@ -217,7 +239,7 @@ static int mv88e6xxx_g2_eeprom_write16(struct mv88e6xxx_chip *chip,
if (err) if (err)
return err; return err;
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data); err = mv88e6xxx_g2_write(chip, GLOBAL2_EEPROM_DATA, data);
if (err) if (err)
return err; return err;
...@@ -283,7 +305,7 @@ int mv88e6xxx_g2_set_eeprom16(struct mv88e6xxx_chip *chip, ...@@ -283,7 +305,7 @@ int mv88e6xxx_g2_set_eeprom16(struct mv88e6xxx_chip *chip,
int err; int err;
/* Ensure the RO WriteEn bit is set */ /* Ensure the RO WriteEn bit is set */
err = mv88e6xxx_read(chip, REG_GLOBAL2, GLOBAL2_EEPROM_CMD, &val); err = mv88e6xxx_g2_read(chip, GLOBAL2_EEPROM_CMD, &val);
if (err) if (err)
return err; return err;
...@@ -346,15 +368,15 @@ int mv88e6xxx_g2_set_eeprom16(struct mv88e6xxx_chip *chip, ...@@ -346,15 +368,15 @@ int mv88e6xxx_g2_set_eeprom16(struct mv88e6xxx_chip *chip,
static int mv88e6xxx_g2_smi_phy_wait(struct mv88e6xxx_chip *chip) static int mv88e6xxx_g2_smi_phy_wait(struct mv88e6xxx_chip *chip)
{ {
return mv88e6xxx_wait(chip, REG_GLOBAL2, GLOBAL2_SMI_PHY_CMD, return mv88e6xxx_g2_wait(chip, GLOBAL2_SMI_PHY_CMD,
GLOBAL2_SMI_PHY_CMD_BUSY); GLOBAL2_SMI_PHY_CMD_BUSY);
} }
static int mv88e6xxx_g2_smi_phy_cmd(struct mv88e6xxx_chip *chip, u16 cmd) static int mv88e6xxx_g2_smi_phy_cmd(struct mv88e6xxx_chip *chip, u16 cmd)
{ {
int err; int err;
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_SMI_PHY_CMD, cmd); err = mv88e6xxx_g2_write(chip, GLOBAL2_SMI_PHY_CMD, cmd);
if (err) if (err)
return err; return err;
...@@ -375,7 +397,7 @@ int mv88e6xxx_g2_smi_phy_read(struct mv88e6xxx_chip *chip, int addr, int reg, ...@@ -375,7 +397,7 @@ int mv88e6xxx_g2_smi_phy_read(struct mv88e6xxx_chip *chip, int addr, int reg,
if (err) if (err)
return err; return err;
return mv88e6xxx_read(chip, REG_GLOBAL2, GLOBAL2_SMI_PHY_DATA, val); return mv88e6xxx_g2_read(chip, GLOBAL2_SMI_PHY_DATA, val);
} }
int mv88e6xxx_g2_smi_phy_write(struct mv88e6xxx_chip *chip, int addr, int reg, int mv88e6xxx_g2_smi_phy_write(struct mv88e6xxx_chip *chip, int addr, int reg,
...@@ -388,7 +410,7 @@ int mv88e6xxx_g2_smi_phy_write(struct mv88e6xxx_chip *chip, int addr, int reg, ...@@ -388,7 +410,7 @@ int mv88e6xxx_g2_smi_phy_write(struct mv88e6xxx_chip *chip, int addr, int reg,
if (err) if (err)
return err; return err;
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_SMI_PHY_DATA, val); err = mv88e6xxx_g2_write(chip, GLOBAL2_SMI_PHY_DATA, val);
if (err) if (err)
return err; return err;
...@@ -404,8 +426,7 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip) ...@@ -404,8 +426,7 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip)
/* Consider the frames with reserved multicast destination /* Consider the frames with reserved multicast destination
* addresses matching 01:80:c2:00:00:2x as MGMT. * addresses matching 01:80:c2:00:00:2x as MGMT.
*/ */
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_MGMT_EN_2X, err = mv88e6xxx_g2_write(chip, GLOBAL2_MGMT_EN_2X, 0xffff);
0xffff);
if (err) if (err)
return err; return err;
} }
...@@ -414,8 +435,7 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip) ...@@ -414,8 +435,7 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip)
/* Consider the frames with reserved multicast destination /* Consider the frames with reserved multicast destination
* addresses matching 01:80:c2:00:00:0x as MGMT. * addresses matching 01:80:c2:00:00:0x as MGMT.
*/ */
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_MGMT_EN_0X, err = mv88e6xxx_g2_write(chip, GLOBAL2_MGMT_EN_0X, 0xffff);
0xffff);
if (err) if (err)
return err; return err;
} }
...@@ -429,7 +449,7 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip) ...@@ -429,7 +449,7 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip)
if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_0X) || if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_0X) ||
mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_2X)) mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_2X))
reg |= GLOBAL2_SWITCH_MGMT_RSVD2CPU | 0x7; reg |= GLOBAL2_SWITCH_MGMT_RSVD2CPU | 0x7;
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_SWITCH_MGMT, reg); err = mv88e6xxx_g2_write(chip, GLOBAL2_SWITCH_MGMT, reg);
if (err) if (err)
return err; return err;
...@@ -454,8 +474,8 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip) ...@@ -454,8 +474,8 @@ int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip)
if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_PVT)) { if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_PVT)) {
/* Initialize Cross-chip Port VLAN Table to reset defaults */ /* Initialize Cross-chip Port VLAN Table to reset defaults */
err = mv88e6xxx_write(chip, REG_GLOBAL2, GLOBAL2_PVT_ADDR, err = mv88e6xxx_g2_write(chip, GLOBAL2_PVT_ADDR,
GLOBAL2_PVT_ADDR_OP_INIT_ONES); GLOBAL2_PVT_ADDR_OP_INIT_ONES);
if (err) if (err)
return err; return err;
} }
......
...@@ -159,7 +159,6 @@ ...@@ -159,7 +159,6 @@
#define PORT_TAG_REGMAP_0123 0x18 #define PORT_TAG_REGMAP_0123 0x18
#define PORT_TAG_REGMAP_4567 0x19 #define PORT_TAG_REGMAP_4567 0x19
#define REG_GLOBAL 0x1b
#define GLOBAL_STATUS 0x00 #define GLOBAL_STATUS 0x00
#define GLOBAL_STATUS_PPU_STATE BIT(15) /* 6351 and 6171 */ #define GLOBAL_STATUS_PPU_STATE BIT(15) /* 6351 and 6171 */
/* Two bits for 6165, 6185 etc */ /* Two bits for 6165, 6185 etc */
...@@ -171,8 +170,8 @@ ...@@ -171,8 +170,8 @@
#define GLOBAL_MAC_01 0x01 #define GLOBAL_MAC_01 0x01
#define GLOBAL_MAC_23 0x02 #define GLOBAL_MAC_23 0x02
#define GLOBAL_MAC_45 0x03 #define GLOBAL_MAC_45 0x03
#define GLOBAL_ATU_FID 0x01 /* 6097 6165 6351 6352 */ #define GLOBAL_ATU_FID 0x01
#define GLOBAL_VTU_FID 0x02 /* 6097 6165 6351 6352 */ #define GLOBAL_VTU_FID 0x02
#define GLOBAL_VTU_FID_MASK 0xfff #define GLOBAL_VTU_FID_MASK 0xfff
#define GLOBAL_VTU_SID 0x03 /* 6097 6165 6351 6352 */ #define GLOBAL_VTU_SID 0x03 /* 6097 6165 6351 6352 */
#define GLOBAL_VTU_SID_MASK 0x3f #define GLOBAL_VTU_SID_MASK 0x3f
...@@ -277,7 +276,6 @@ ...@@ -277,7 +276,6 @@
#define GLOBAL_STATS_COUNTER_32 0x1e #define GLOBAL_STATS_COUNTER_32 0x1e
#define GLOBAL_STATS_COUNTER_01 0x1f #define GLOBAL_STATS_COUNTER_01 0x1f
#define REG_GLOBAL2 0x1c
#define GLOBAL2_INT_SOURCE 0x00 #define GLOBAL2_INT_SOURCE 0x00
#define GLOBAL2_INT_MASK 0x01 #define GLOBAL2_INT_MASK 0x01
#define GLOBAL2_MGMT_EN_2X 0x02 #define GLOBAL2_MGMT_EN_2X 0x02
...@@ -410,6 +408,11 @@ enum mv88e6xxx_cap { ...@@ -410,6 +408,11 @@ enum mv88e6xxx_cap {
*/ */
MV88E6XXX_CAP_SERDES, MV88E6XXX_CAP_SERDES,
/* Switch Global (1) Registers.
*/
MV88E6XXX_CAP_G1_ATU_FID, /* (0x01) ATU FID Register */
MV88E6XXX_CAP_G1_VTU_FID, /* (0x02) VTU FID Register */
/* Switch Global 2 Registers. /* Switch Global 2 Registers.
* The device contains a second set of global 16-bit registers. * The device contains a second set of global 16-bit registers.
*/ */
...@@ -420,12 +423,7 @@ enum mv88e6xxx_cap { ...@@ -420,12 +423,7 @@ enum mv88e6xxx_cap {
MV88E6XXX_CAP_G2_IRL_DATA, /* (0x0a) Ingress Rate Data */ MV88E6XXX_CAP_G2_IRL_DATA, /* (0x0a) Ingress Rate Data */
MV88E6XXX_CAP_G2_PVT_ADDR, /* (0x0b) Cross Chip Port VLAN Addr */ MV88E6XXX_CAP_G2_PVT_ADDR, /* (0x0b) Cross Chip Port VLAN Addr */
MV88E6XXX_CAP_G2_PVT_DATA, /* (0x0c) Cross Chip Port VLAN Data */ MV88E6XXX_CAP_G2_PVT_DATA, /* (0x0c) Cross Chip Port VLAN Data */
MV88E6XXX_CAP_G2_SWITCH_MAC, /* (0x0d) Switch MAC/WoL/WoF */
MV88E6XXX_CAP_G2_POT, /* (0x0f) Priority Override Table */ MV88E6XXX_CAP_G2_POT, /* (0x0f) Priority Override Table */
MV88E6XXX_CAP_G2_EEPROM_CMD, /* (0x14) EEPROM Command */
MV88E6XXX_CAP_G2_EEPROM_DATA, /* (0x15) EEPROM Data */
MV88E6XXX_CAP_G2_SMI_PHY_CMD, /* (0x18) SMI PHY Command */
MV88E6XXX_CAP_G2_SMI_PHY_DATA, /* (0x19) SMI PHY Data */
/* PHY Polling Unit. /* PHY Polling Unit.
* See GLOBAL_CONTROL_PPU_ENABLE and GLOBAL_STATUS_PPU_POLLING. * See GLOBAL_CONTROL_PPU_ENABLE and GLOBAL_STATUS_PPU_POLLING.
...@@ -462,6 +460,9 @@ enum mv88e6xxx_cap { ...@@ -462,6 +460,9 @@ enum mv88e6xxx_cap {
#define MV88E6XXX_FLAG_SERDES BIT_ULL(MV88E6XXX_CAP_SERDES) #define MV88E6XXX_FLAG_SERDES BIT_ULL(MV88E6XXX_CAP_SERDES)
#define MV88E6XXX_FLAG_G1_ATU_FID BIT_ULL(MV88E6XXX_CAP_G1_ATU_FID)
#define MV88E6XXX_FLAG_G1_VTU_FID BIT_ULL(MV88E6XXX_CAP_G1_VTU_FID)
#define MV88E6XXX_FLAG_GLOBAL2 BIT_ULL(MV88E6XXX_CAP_GLOBAL2) #define MV88E6XXX_FLAG_GLOBAL2 BIT_ULL(MV88E6XXX_CAP_GLOBAL2)
#define MV88E6XXX_FLAG_G2_MGMT_EN_2X BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_2X) #define MV88E6XXX_FLAG_G2_MGMT_EN_2X BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_2X)
#define MV88E6XXX_FLAG_G2_MGMT_EN_0X BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_0X) #define MV88E6XXX_FLAG_G2_MGMT_EN_0X BIT_ULL(MV88E6XXX_CAP_G2_MGMT_EN_0X)
...@@ -469,12 +470,7 @@ enum mv88e6xxx_cap { ...@@ -469,12 +470,7 @@ enum mv88e6xxx_cap {
#define MV88E6XXX_FLAG_G2_IRL_DATA BIT_ULL(MV88E6XXX_CAP_G2_IRL_DATA) #define MV88E6XXX_FLAG_G2_IRL_DATA BIT_ULL(MV88E6XXX_CAP_G2_IRL_DATA)
#define MV88E6XXX_FLAG_G2_PVT_ADDR BIT_ULL(MV88E6XXX_CAP_G2_PVT_ADDR) #define MV88E6XXX_FLAG_G2_PVT_ADDR BIT_ULL(MV88E6XXX_CAP_G2_PVT_ADDR)
#define MV88E6XXX_FLAG_G2_PVT_DATA BIT_ULL(MV88E6XXX_CAP_G2_PVT_DATA) #define MV88E6XXX_FLAG_G2_PVT_DATA BIT_ULL(MV88E6XXX_CAP_G2_PVT_DATA)
#define MV88E6XXX_FLAG_G2_SWITCH_MAC BIT_ULL(MV88E6XXX_CAP_G2_SWITCH_MAC)
#define MV88E6XXX_FLAG_G2_POT BIT_ULL(MV88E6XXX_CAP_G2_POT) #define MV88E6XXX_FLAG_G2_POT BIT_ULL(MV88E6XXX_CAP_G2_POT)
#define MV88E6XXX_FLAG_G2_EEPROM_CMD BIT_ULL(MV88E6XXX_CAP_G2_EEPROM_CMD)
#define MV88E6XXX_FLAG_G2_EEPROM_DATA BIT_ULL(MV88E6XXX_CAP_G2_EEPROM_DATA)
#define MV88E6XXX_FLAG_G2_SMI_PHY_CMD BIT_ULL(MV88E6XXX_CAP_G2_SMI_PHY_CMD)
#define MV88E6XXX_FLAG_G2_SMI_PHY_DATA BIT_ULL(MV88E6XXX_CAP_G2_SMI_PHY_DATA)
#define MV88E6XXX_FLAG_PPU BIT_ULL(MV88E6XXX_CAP_PPU) #define MV88E6XXX_FLAG_PPU BIT_ULL(MV88E6XXX_CAP_PPU)
#define MV88E6XXX_FLAG_PPU_ACTIVE BIT_ULL(MV88E6XXX_CAP_PPU_ACTIVE) #define MV88E6XXX_FLAG_PPU_ACTIVE BIT_ULL(MV88E6XXX_CAP_PPU_ACTIVE)
...@@ -483,11 +479,6 @@ enum mv88e6xxx_cap { ...@@ -483,11 +479,6 @@ enum mv88e6xxx_cap {
#define MV88E6XXX_FLAG_TEMP_LIMIT BIT_ULL(MV88E6XXX_CAP_TEMP_LIMIT) #define MV88E6XXX_FLAG_TEMP_LIMIT BIT_ULL(MV88E6XXX_CAP_TEMP_LIMIT)
#define MV88E6XXX_FLAG_VTU BIT_ULL(MV88E6XXX_CAP_VTU) #define MV88E6XXX_FLAG_VTU BIT_ULL(MV88E6XXX_CAP_VTU)
/* EEPROM Programming via Global2 with 16-bit data */
#define MV88E6XXX_FLAGS_EEPROM16 \
(MV88E6XXX_FLAG_G2_EEPROM_CMD | \
MV88E6XXX_FLAG_G2_EEPROM_DATA)
/* Ingress Rate Limit unit */ /* Ingress Rate Limit unit */
#define MV88E6XXX_FLAGS_IRL \ #define MV88E6XXX_FLAGS_IRL \
(MV88E6XXX_FLAG_G2_IRL_CMD | \ (MV88E6XXX_FLAG_G2_IRL_CMD | \
...@@ -508,11 +499,6 @@ enum mv88e6xxx_cap { ...@@ -508,11 +499,6 @@ enum mv88e6xxx_cap {
(MV88E6XXX_FLAG_PHY_PAGE | \ (MV88E6XXX_FLAG_PHY_PAGE | \
MV88E6XXX_FLAG_SERDES) MV88E6XXX_FLAG_SERDES)
/* Indirect PHY access via Global2 SMI PHY registers */
#define MV88E6XXX_FLAGS_SMI_PHY \
(MV88E6XXX_FLAG_G2_SMI_PHY_CMD |\
MV88E6XXX_FLAG_G2_SMI_PHY_DATA)
#define MV88E6XXX_FLAGS_FAMILY_6095 \ #define MV88E6XXX_FLAGS_FAMILY_6095 \
(MV88E6XXX_FLAG_GLOBAL2 | \ (MV88E6XXX_FLAG_GLOBAL2 | \
MV88E6XXX_FLAG_G2_MGMT_EN_0X | \ MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
...@@ -521,7 +507,9 @@ enum mv88e6xxx_cap { ...@@ -521,7 +507,9 @@ enum mv88e6xxx_cap {
MV88E6XXX_FLAGS_MULTI_CHIP) MV88E6XXX_FLAGS_MULTI_CHIP)
#define MV88E6XXX_FLAGS_FAMILY_6097 \ #define MV88E6XXX_FLAGS_FAMILY_6097 \
(MV88E6XXX_FLAG_GLOBAL2 | \ (MV88E6XXX_FLAG_G1_ATU_FID | \
MV88E6XXX_FLAG_G1_VTU_FID | \
MV88E6XXX_FLAG_GLOBAL2 | \
MV88E6XXX_FLAG_G2_MGMT_EN_2X | \ MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
MV88E6XXX_FLAG_G2_MGMT_EN_0X | \ MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
MV88E6XXX_FLAG_G2_POT | \ MV88E6XXX_FLAG_G2_POT | \
...@@ -533,10 +521,11 @@ enum mv88e6xxx_cap { ...@@ -533,10 +521,11 @@ enum mv88e6xxx_cap {
MV88E6XXX_FLAGS_PVT) MV88E6XXX_FLAGS_PVT)
#define MV88E6XXX_FLAGS_FAMILY_6165 \ #define MV88E6XXX_FLAGS_FAMILY_6165 \
(MV88E6XXX_FLAG_GLOBAL2 | \ (MV88E6XXX_FLAG_G1_ATU_FID | \
MV88E6XXX_FLAG_G1_VTU_FID | \
MV88E6XXX_FLAG_GLOBAL2 | \
MV88E6XXX_FLAG_G2_MGMT_EN_2X | \ MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
MV88E6XXX_FLAG_G2_MGMT_EN_0X | \ MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
MV88E6XXX_FLAG_G2_SWITCH_MAC | \
MV88E6XXX_FLAG_G2_POT | \ MV88E6XXX_FLAG_G2_POT | \
MV88E6XXX_FLAG_STU | \ MV88E6XXX_FLAG_STU | \
MV88E6XXX_FLAG_TEMP | \ MV88E6XXX_FLAG_TEMP | \
...@@ -558,24 +547,22 @@ enum mv88e6xxx_cap { ...@@ -558,24 +547,22 @@ enum mv88e6xxx_cap {
MV88E6XXX_FLAG_GLOBAL2 | \ MV88E6XXX_FLAG_GLOBAL2 | \
MV88E6XXX_FLAG_G2_MGMT_EN_2X | \ MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
MV88E6XXX_FLAG_G2_MGMT_EN_0X | \ MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
MV88E6XXX_FLAG_G2_SWITCH_MAC | \
MV88E6XXX_FLAG_G2_POT | \ MV88E6XXX_FLAG_G2_POT | \
MV88E6XXX_FLAG_PPU_ACTIVE | \ MV88E6XXX_FLAG_PPU_ACTIVE | \
MV88E6XXX_FLAG_TEMP | \ MV88E6XXX_FLAG_TEMP | \
MV88E6XXX_FLAG_TEMP_LIMIT | \ MV88E6XXX_FLAG_TEMP_LIMIT | \
MV88E6XXX_FLAG_VTU | \ MV88E6XXX_FLAG_VTU | \
MV88E6XXX_FLAGS_EEPROM16 | \
MV88E6XXX_FLAGS_IRL | \ MV88E6XXX_FLAGS_IRL | \
MV88E6XXX_FLAGS_MULTI_CHIP | \ MV88E6XXX_FLAGS_MULTI_CHIP | \
MV88E6XXX_FLAGS_PVT | \ MV88E6XXX_FLAGS_PVT)
MV88E6XXX_FLAGS_SMI_PHY)
#define MV88E6XXX_FLAGS_FAMILY_6351 \ #define MV88E6XXX_FLAGS_FAMILY_6351 \
(MV88E6XXX_FLAG_EDSA | \ (MV88E6XXX_FLAG_EDSA | \
MV88E6XXX_FLAG_G1_ATU_FID | \
MV88E6XXX_FLAG_G1_VTU_FID | \
MV88E6XXX_FLAG_GLOBAL2 | \ MV88E6XXX_FLAG_GLOBAL2 | \
MV88E6XXX_FLAG_G2_MGMT_EN_2X | \ MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
MV88E6XXX_FLAG_G2_MGMT_EN_0X | \ MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
MV88E6XXX_FLAG_G2_SWITCH_MAC | \
MV88E6XXX_FLAG_G2_POT | \ MV88E6XXX_FLAG_G2_POT | \
MV88E6XXX_FLAG_PPU_ACTIVE | \ MV88E6XXX_FLAG_PPU_ACTIVE | \
MV88E6XXX_FLAG_STU | \ MV88E6XXX_FLAG_STU | \
...@@ -583,28 +570,28 @@ enum mv88e6xxx_cap { ...@@ -583,28 +570,28 @@ enum mv88e6xxx_cap {
MV88E6XXX_FLAG_VTU | \ MV88E6XXX_FLAG_VTU | \
MV88E6XXX_FLAGS_IRL | \ MV88E6XXX_FLAGS_IRL | \
MV88E6XXX_FLAGS_MULTI_CHIP | \ MV88E6XXX_FLAGS_MULTI_CHIP | \
MV88E6XXX_FLAGS_PVT | \ MV88E6XXX_FLAGS_PVT)
MV88E6XXX_FLAGS_SMI_PHY)
#define MV88E6XXX_FLAGS_FAMILY_6352 \ #define MV88E6XXX_FLAGS_FAMILY_6352 \
(MV88E6XXX_FLAG_EDSA | \ (MV88E6XXX_FLAG_EDSA | \
MV88E6XXX_FLAG_EEE | \ MV88E6XXX_FLAG_EEE | \
MV88E6XXX_FLAG_G1_ATU_FID | \
MV88E6XXX_FLAG_G1_VTU_FID | \
MV88E6XXX_FLAG_GLOBAL2 | \ MV88E6XXX_FLAG_GLOBAL2 | \
MV88E6XXX_FLAG_G2_MGMT_EN_2X | \ MV88E6XXX_FLAG_G2_MGMT_EN_2X | \
MV88E6XXX_FLAG_G2_MGMT_EN_0X | \ MV88E6XXX_FLAG_G2_MGMT_EN_0X | \
MV88E6XXX_FLAG_G2_SWITCH_MAC | \
MV88E6XXX_FLAG_G2_POT | \ MV88E6XXX_FLAG_G2_POT | \
MV88E6XXX_FLAG_PPU_ACTIVE | \ MV88E6XXX_FLAG_PPU_ACTIVE | \
MV88E6XXX_FLAG_STU | \ MV88E6XXX_FLAG_STU | \
MV88E6XXX_FLAG_TEMP | \ MV88E6XXX_FLAG_TEMP | \
MV88E6XXX_FLAG_TEMP_LIMIT | \ MV88E6XXX_FLAG_TEMP_LIMIT | \
MV88E6XXX_FLAG_VTU | \ MV88E6XXX_FLAG_VTU | \
MV88E6XXX_FLAGS_EEPROM16 | \
MV88E6XXX_FLAGS_IRL | \ MV88E6XXX_FLAGS_IRL | \
MV88E6XXX_FLAGS_MULTI_CHIP | \ MV88E6XXX_FLAGS_MULTI_CHIP | \
MV88E6XXX_FLAGS_PVT | \ MV88E6XXX_FLAGS_PVT | \
MV88E6XXX_FLAGS_SERDES | \ MV88E6XXX_FLAGS_SERDES)
MV88E6XXX_FLAGS_SMI_PHY)
struct mv88e6xxx_ops;
struct mv88e6xxx_info { struct mv88e6xxx_info {
enum mv88e6xxx_family family; enum mv88e6xxx_family family;
...@@ -613,8 +600,10 @@ struct mv88e6xxx_info { ...@@ -613,8 +600,10 @@ struct mv88e6xxx_info {
unsigned int num_databases; unsigned int num_databases;
unsigned int num_ports; unsigned int num_ports;
unsigned int port_base_addr; unsigned int port_base_addr;
unsigned int global1_addr;
unsigned int age_time_coeff; unsigned int age_time_coeff;
unsigned long long flags; unsigned long long flags;
const struct mv88e6xxx_ops *ops;
}; };
struct mv88e6xxx_atu_entry { struct mv88e6xxx_atu_entry {
...@@ -625,18 +614,15 @@ struct mv88e6xxx_atu_entry { ...@@ -625,18 +614,15 @@ struct mv88e6xxx_atu_entry {
u8 mac[ETH_ALEN]; u8 mac[ETH_ALEN];
}; };
struct mv88e6xxx_vtu_stu_entry { struct mv88e6xxx_vtu_entry {
/* VTU only */
u16 vid; u16 vid;
u16 fid; u16 fid;
/* VTU and STU */
u8 sid; u8 sid;
bool valid; bool valid;
u8 data[DSA_MAX_PORTS]; u8 data[DSA_MAX_PORTS];
}; };
struct mv88e6xxx_ops; struct mv88e6xxx_bus_ops;
struct mv88e6xxx_priv_port { struct mv88e6xxx_priv_port {
struct net_device *bridge_dev; struct net_device *bridge_dev;
...@@ -657,14 +643,14 @@ struct mv88e6xxx_chip { ...@@ -657,14 +643,14 @@ struct mv88e6xxx_chip {
/* The MII bus and the address on the bus that is used to /* The MII bus and the address on the bus that is used to
* communication with the switch * communication with the switch
*/ */
const struct mv88e6xxx_ops *smi_ops; const struct mv88e6xxx_bus_ops *smi_ops;
struct mii_bus *bus; struct mii_bus *bus;
int sw_addr; int sw_addr;
/* Handles automatic disabling and re-enabling of the PHY /* Handles automatic disabling and re-enabling of the PHY
* polling unit. * polling unit.
*/ */
const struct mv88e6xxx_ops *phy_ops; const struct mv88e6xxx_bus_ops *phy_ops;
struct mutex ppu_mutex; struct mutex ppu_mutex;
int ppu_disabled; int ppu_disabled;
struct work_struct ppu_work; struct work_struct ppu_work;
...@@ -693,11 +679,25 @@ struct mv88e6xxx_chip { ...@@ -693,11 +679,25 @@ struct mv88e6xxx_chip {
struct mii_bus *mdio_bus; struct mii_bus *mdio_bus;
}; };
struct mv88e6xxx_ops { struct mv88e6xxx_bus_ops {
int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val); int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val); int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
}; };
struct mv88e6xxx_ops {
int (*get_eeprom)(struct mv88e6xxx_chip *chip,
struct ethtool_eeprom *eeprom, u8 *data);
int (*set_eeprom)(struct mv88e6xxx_chip *chip,
struct ethtool_eeprom *eeprom, u8 *data);
int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);
int (*phy_read)(struct mv88e6xxx_chip *chip, int addr, int reg,
u16 *val);
int (*phy_write)(struct mv88e6xxx_chip *chip, int addr, int reg,
u16 val);
};
enum stat_type { enum stat_type {
BANK0, BANK0,
BANK1, BANK1,
...@@ -717,6 +717,16 @@ static inline bool mv88e6xxx_has(struct mv88e6xxx_chip *chip, ...@@ -717,6 +717,16 @@ static inline bool mv88e6xxx_has(struct mv88e6xxx_chip *chip,
return (chip->info->flags & flags) == flags; return (chip->info->flags & flags) == flags;
} }
static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
{
return chip->info->num_databases;
}
static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
{
return chip->info->num_ports;
}
int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val); int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val); int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg, int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
......
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