net: dsa: remove ds_to_priv
[cascardo/linux.git] / drivers / net / dsa / mv88e6xxx / chip.c
index 8c846bc..d6b0f78 100644 (file)
@@ -325,6 +325,7 @@ static int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg,
                usleep_range(1000, 2000);
        }
 
+       dev_err(chip->dev, "Timeout while waiting for switch\n");
        return -ETIMEDOUT;
 }
 
@@ -485,6 +486,11 @@ static void mv88e6xxx_ppu_state_init(struct mv88e6xxx_chip *chip)
        chip->ppu_timer.function = mv88e6xxx_ppu_reenable_timer;
 }
 
+static void mv88e6xxx_ppu_state_destroy(struct mv88e6xxx_chip *chip)
+{
+       del_timer_sync(&chip->ppu_timer);
+}
+
 static int mv88e6xxx_phy_ppu_read(struct mv88e6xxx_chip *chip, int addr,
                                  int reg, u16 *val)
 {
@@ -580,7 +586,7 @@ static bool mv88e6xxx_has_fid_reg(struct mv88e6xxx_chip *chip)
 static void mv88e6xxx_adjust_link(struct dsa_switch *ds, int port,
                                  struct phy_device *phydev)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        u32 reg;
        int ret;
 
@@ -826,7 +832,7 @@ static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
 static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
                                  uint8_t *data)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        struct mv88e6xxx_hw_stat *stat;
        int i, j;
 
@@ -842,7 +848,7 @@ static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
 
 static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        struct mv88e6xxx_hw_stat *stat;
        int i, j;
 
@@ -857,7 +863,7 @@ static int mv88e6xxx_get_sset_count(struct dsa_switch *ds)
 static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port,
                                        uint64_t *data)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        struct mv88e6xxx_hw_stat *stat;
        int ret;
        int i, j;
@@ -888,7 +894,7 @@ static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port)
 static void mv88e6xxx_get_regs(struct dsa_switch *ds, int port,
                               struct ethtool_regs *regs, void *_p)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        u16 *p = _p;
        int i;
 
@@ -918,7 +924,7 @@ static int _mv88e6xxx_atu_wait(struct mv88e6xxx_chip *chip)
 static int mv88e6xxx_get_eee(struct dsa_switch *ds, int port,
                             struct ethtool_eee *e)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        u16 reg;
        int err;
 
@@ -948,7 +954,7 @@ out:
 static int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
                             struct phy_device *phydev, struct ethtool_eee *e)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        u16 reg;
        int err;
 
@@ -1179,7 +1185,7 @@ static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
 static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
                                         u8 state)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int stp_state;
        int err;
 
@@ -1428,7 +1434,7 @@ static int mv88e6xxx_port_vlan_dump(struct dsa_switch *ds, int port,
                                    struct switchdev_obj_port_vlan *vlan,
                                    int (*cb)(struct switchdev_obj *obj))
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        struct mv88e6xxx_vtu_stu_entry next;
        u16 pvid;
        int err;
@@ -1797,7 +1803,7 @@ static int _mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid,
 static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
                                        u16 vid_begin, u16 vid_end)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        struct mv88e6xxx_vtu_stu_entry vlan;
        int i, err;
 
@@ -1858,7 +1864,7 @@ static const char * const mv88e6xxx_port_8021q_mode_names[] = {
 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
                                         bool vlan_filtering)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        u16 old, new = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
                PORT_CONTROL_2_8021Q_DISABLED;
        int ret;
@@ -1900,7 +1906,7 @@ mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
                            const struct switchdev_obj_port_vlan *vlan,
                            struct switchdev_trans *trans)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int err;
 
        if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
@@ -1941,7 +1947,7 @@ static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
                                    const struct switchdev_obj_port_vlan *vlan,
                                    struct switchdev_trans *trans)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
        bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
        u16 vid;
@@ -2003,7 +2009,7 @@ static int _mv88e6xxx_port_vlan_del(struct mv88e6xxx_chip *chip,
 static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
                                   const struct switchdev_obj_port_vlan *vlan)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        u16 pvid, vid;
        int err = 0;
 
@@ -2087,9 +2093,9 @@ static int _mv88e6xxx_atu_load(struct mv88e6xxx_chip *chip,
        return _mv88e6xxx_atu_cmd(chip, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
 }
 
-static int _mv88e6xxx_port_fdb_load(struct mv88e6xxx_chip *chip, int port,
-                                   const unsigned char *addr, u16 vid,
-                                   u8 state)
+static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,
+                                       const unsigned char *addr, u16 vid,
+                                       u8 state)
 {
        struct mv88e6xxx_atu_entry entry = { 0 };
        struct mv88e6xxx_vtu_stu_entry vlan;
@@ -2128,30 +2134,27 @@ static void mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
                                   const struct switchdev_obj_port_fdb *fdb,
                                   struct switchdev_trans *trans)
 {
-       int state = is_multicast_ether_addr(fdb->addr) ?
-               GLOBAL_ATU_DATA_STATE_MC_STATIC :
-               GLOBAL_ATU_DATA_STATE_UC_STATIC;
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
 
        mutex_lock(&chip->reg_lock);
-       if (_mv88e6xxx_port_fdb_load(chip, port, fdb->addr, fdb->vid, state))
-               netdev_err(ds->ports[port].netdev,
-                          "failed to load MAC address\n");
+       if (mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
+                                        GLOBAL_ATU_DATA_STATE_UC_STATIC))
+               netdev_err(ds->ports[port].netdev, "failed to load unicast MAC address\n");
        mutex_unlock(&chip->reg_lock);
 }
 
 static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
                                  const struct switchdev_obj_port_fdb *fdb)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
-       int ret;
+       struct mv88e6xxx_chip *chip = ds->priv;
+       int err;
 
        mutex_lock(&chip->reg_lock);
-       ret = _mv88e6xxx_port_fdb_load(chip, port, fdb->addr, fdb->vid,
-                                      GLOBAL_ATU_DATA_STATE_UNUSED);
+       err = mv88e6xxx_port_db_load_purge(chip, port, fdb->addr, fdb->vid,
+                                          GLOBAL_ATU_DATA_STATE_UNUSED);
        mutex_unlock(&chip->reg_lock);
 
-       return ret;
+       return err;
 }
 
 static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
@@ -2199,10 +2202,10 @@ static int _mv88e6xxx_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,
        return 0;
 }
 
-static int _mv88e6xxx_port_fdb_dump_one(struct mv88e6xxx_chip *chip,
-                                       u16 fid, u16 vid, int port,
-                                       struct switchdev_obj_port_fdb *fdb,
-                                       int (*cb)(struct switchdev_obj *obj))
+static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,
+                                     u16 fid, u16 vid, int port,
+                                     struct switchdev_obj *obj,
+                                     int (*cb)(struct switchdev_obj *obj))
 {
        struct mv88e6xxx_atu_entry addr = {
                .mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
@@ -2216,72 +2219,98 @@ static int _mv88e6xxx_port_fdb_dump_one(struct mv88e6xxx_chip *chip,
        do {
                err = _mv88e6xxx_atu_getnext(chip, fid, &addr);
                if (err)
-                       break;
+                       return err;
 
                if (addr.state == GLOBAL_ATU_DATA_STATE_UNUSED)
                        break;
 
-               if (!addr.trunk && addr.portv_trunkid & BIT(port)) {
-                       bool is_static = addr.state ==
-                               (is_multicast_ether_addr(addr.mac) ?
-                                GLOBAL_ATU_DATA_STATE_MC_STATIC :
-                                GLOBAL_ATU_DATA_STATE_UC_STATIC);
+               if (addr.trunk || (addr.portv_trunkid & BIT(port)) == 0)
+                       continue;
+
+               if (obj->id == SWITCHDEV_OBJ_ID_PORT_FDB) {
+                       struct switchdev_obj_port_fdb *fdb;
 
+                       if (!is_unicast_ether_addr(addr.mac))
+                               continue;
+
+                       fdb = SWITCHDEV_OBJ_PORT_FDB(obj);
                        fdb->vid = vid;
                        ether_addr_copy(fdb->addr, addr.mac);
-                       fdb->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
+                       if (addr.state == GLOBAL_ATU_DATA_STATE_UC_STATIC)
+                               fdb->ndm_state = NUD_NOARP;
+                       else
+                               fdb->ndm_state = NUD_REACHABLE;
+               } else if (obj->id == SWITCHDEV_OBJ_ID_PORT_MDB) {
+                       struct switchdev_obj_port_mdb *mdb;
 
-                       err = cb(&fdb->obj);
-                       if (err)
-                               break;
+                       if (!is_multicast_ether_addr(addr.mac))
+                               continue;
+
+                       mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
+                       mdb->vid = vid;
+                       ether_addr_copy(mdb->addr, addr.mac);
+               } else {
+                       return -EOPNOTSUPP;
                }
+
+               err = cb(obj);
+               if (err)
+                       return err;
        } while (!is_broadcast_ether_addr(addr.mac));
 
        return err;
 }
 
-static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
-                                  struct switchdev_obj_port_fdb *fdb,
-                                  int (*cb)(struct switchdev_obj *obj))
+static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
+                                 struct switchdev_obj *obj,
+                                 int (*cb)(struct switchdev_obj *obj))
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
        struct mv88e6xxx_vtu_stu_entry vlan = {
                .vid = GLOBAL_VTU_VID_MASK, /* all ones */
        };
        u16 fid;
        int err;
 
-       mutex_lock(&chip->reg_lock);
-
        /* Dump port's default Filtering Information Database (VLAN ID 0) */
        err = _mv88e6xxx_port_fid_get(chip, port, &fid);
        if (err)
-               goto unlock;
+               return err;
 
-       err = _mv88e6xxx_port_fdb_dump_one(chip, fid, 0, port, fdb, cb);
+       err = mv88e6xxx_port_db_dump_fid(chip, fid, 0, port, obj, cb);
        if (err)
-               goto unlock;
+               return err;
 
        /* Dump VLANs' Filtering Information Databases */
        err = _mv88e6xxx_vtu_vid_write(chip, vlan.vid);
        if (err)
-               goto unlock;
+               return err;
 
        do {
                err = _mv88e6xxx_vtu_getnext(chip, &vlan);
                if (err)
-                       break;
+                       return err;
 
                if (!vlan.valid)
                        break;
 
-               err = _mv88e6xxx_port_fdb_dump_one(chip, vlan.fid, vlan.vid,
-                                                  port, fdb, cb);
+               err = mv88e6xxx_port_db_dump_fid(chip, vlan.fid, vlan.vid, port,
+                                                obj, cb);
                if (err)
-                       break;
+                       return err;
        } while (vlan.vid < GLOBAL_VTU_VID_MASK);
 
-unlock:
+       return err;
+}
+
+static int mv88e6xxx_port_fdb_dump(struct dsa_switch *ds, int port,
+                                  struct switchdev_obj_port_fdb *fdb,
+                                  int (*cb)(struct switchdev_obj *obj))
+{
+       struct mv88e6xxx_chip *chip = ds->priv;
+       int err;
+
+       mutex_lock(&chip->reg_lock);
+       err = mv88e6xxx_port_db_dump(chip, port, &fdb->obj, cb);
        mutex_unlock(&chip->reg_lock);
 
        return err;
@@ -2290,7 +2319,7 @@ unlock:
 static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
                                      struct net_device *bridge)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int i, err = 0;
 
        mutex_lock(&chip->reg_lock);
@@ -2313,7 +2342,7 @@ static int mv88e6xxx_port_bridge_join(struct dsa_switch *ds, int port,
 
 static void mv88e6xxx_port_bridge_leave(struct dsa_switch *ds, int port)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        struct net_device *bridge = chip->ports[port].bridge_dev;
        int i;
 
@@ -2482,28 +2511,13 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
                PORT_CONTROL_USE_TAG | PORT_CONTROL_USE_IP |
                PORT_CONTROL_STATE_FORWARDING;
        if (dsa_is_cpu_port(ds, port)) {
-               if (mv88e6xxx_6095_family(chip) || mv88e6xxx_6185_family(chip))
-                       reg |= PORT_CONTROL_DSA_TAG;
-               if (mv88e6xxx_6352_family(chip) ||
-                   mv88e6xxx_6351_family(chip) ||
-                   mv88e6xxx_6165_family(chip) ||
-                   mv88e6xxx_6097_family(chip) ||
-                   mv88e6xxx_6320_family(chip)) {
+               if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
                        reg |= PORT_CONTROL_FRAME_ETHER_TYPE_DSA |
-                               PORT_CONTROL_FORWARD_UNKNOWN |
                                PORT_CONTROL_FORWARD_UNKNOWN_MC;
-               }
-
-               if (mv88e6xxx_6352_family(chip) ||
-                   mv88e6xxx_6351_family(chip) ||
-                   mv88e6xxx_6165_family(chip) ||
-                   mv88e6xxx_6097_family(chip) ||
-                   mv88e6xxx_6095_family(chip) ||
-                   mv88e6xxx_6065_family(chip) ||
-                   mv88e6xxx_6185_family(chip) ||
-                   mv88e6xxx_6320_family(chip)) {
-                       reg |= PORT_CONTROL_EGRESS_ADD_TAG;
-               }
+               else
+                       reg |= PORT_CONTROL_DSA_TAG;
+               reg |= PORT_CONTROL_EGRESS_ADD_TAG |
+                       PORT_CONTROL_FORWARD_UNKNOWN;
        }
        if (dsa_is_dsa_port(ds, port)) {
                if (mv88e6xxx_6095_family(chip) ||
@@ -2631,10 +2645,13 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
                /* Port Ethertype: use the Ethertype DSA Ethertype
                 * value.
                 */
-               ret = _mv88e6xxx_reg_write(chip, REG_PORT(port),
-                                          PORT_ETH_TYPE, ETH_P_EDSA);
-               if (ret)
-                       return ret;
+               if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA)) {
+                       ret = _mv88e6xxx_reg_write(chip, REG_PORT(port),
+                                                  PORT_ETH_TYPE, ETH_P_EDSA);
+                       if (ret)
+                               return ret;
+               }
+
                /* Tag Remap: use an identity 802.1p prio -> switch
                 * prio mapping.
                 */
@@ -2652,15 +2669,19 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
                        return ret;
        }
 
+       /* Rate Control: disable ingress rate limiting. */
        if (mv88e6xxx_6352_family(chip) || mv88e6xxx_6351_family(chip) ||
            mv88e6xxx_6165_family(chip) || mv88e6xxx_6097_family(chip) ||
-           mv88e6xxx_6185_family(chip) || mv88e6xxx_6095_family(chip) ||
            mv88e6xxx_6320_family(chip)) {
-               /* Rate Control: disable ingress rate limiting. */
                ret = _mv88e6xxx_reg_write(chip, REG_PORT(port),
                                           PORT_RATE_CONTROL, 0x0001);
                if (ret)
                        return ret;
+       } else if (mv88e6xxx_6185_family(chip) || mv88e6xxx_6095_family(chip)) {
+               ret = _mv88e6xxx_reg_write(chip, REG_PORT(port),
+                                          PORT_RATE_CONTROL, 0x0000);
+               if (ret)
+                       return ret;
        }
 
        /* Port Control 1: disable trunking, disable sending
@@ -2742,7 +2763,7 @@ static int mv88e6xxx_g1_set_age_time(struct mv88e6xxx_chip *chip,
 static int mv88e6xxx_set_ageing_time(struct dsa_switch *ds,
                                     unsigned int ageing_time)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int err;
 
        mutex_lock(&chip->reg_lock);
@@ -3183,7 +3204,7 @@ static int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip)
 
 static int mv88e6xxx_setup(struct dsa_switch *ds)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int err;
        int i;
 
@@ -3223,7 +3244,7 @@ unlock:
 
 static int mv88e6xxx_set_addr(struct dsa_switch *ds, u8 *addr)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int err;
 
        mutex_lock(&chip->reg_lock);
@@ -3331,7 +3352,7 @@ static void mv88e6xxx_mdio_unregister(struct mv88e6xxx_chip *chip)
 
 static int mv88e61xx_get_temp(struct dsa_switch *ds, int *temp)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        u16 val;
        int ret;
 
@@ -3374,7 +3395,7 @@ error:
 
 static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
        u16 val;
        int ret;
@@ -3394,7 +3415,7 @@ static int mv88e63xx_get_temp(struct dsa_switch *ds, int *temp)
 
 static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
 
        if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_TEMP))
                return -EOPNOTSUPP;
@@ -3407,7 +3428,7 @@ static int mv88e6xxx_get_temp(struct dsa_switch *ds, int *temp)
 
 static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
        u16 val;
        int ret;
@@ -3430,7 +3451,7 @@ static int mv88e6xxx_get_temp_limit(struct dsa_switch *ds, int *temp)
 
 static int mv88e6xxx_set_temp_limit(struct dsa_switch *ds, int temp)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
        u16 val;
        int err;
@@ -3453,7 +3474,7 @@ unlock:
 
 static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int phy = mv88e6xxx_6320_family(chip) ? 3 : 0;
        u16 val;
        int ret;
@@ -3477,7 +3498,7 @@ static int mv88e6xxx_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
 
 static int mv88e6xxx_get_eeprom_len(struct dsa_switch *ds)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
 
        return chip->eeprom_len;
 }
@@ -3535,7 +3556,7 @@ static int mv88e6xxx_get_eeprom16(struct mv88e6xxx_chip *chip,
 static int mv88e6xxx_get_eeprom(struct dsa_switch *ds,
                                struct ethtool_eeprom *eeprom, u8 *data)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int err;
 
        mutex_lock(&chip->reg_lock);
@@ -3624,7 +3645,7 @@ static int mv88e6xxx_set_eeprom16(struct mv88e6xxx_chip *chip,
 static int mv88e6xxx_set_eeprom(struct dsa_switch *ds,
                                struct ethtool_eeprom *eeprom, u8 *data)
 {
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
        int err;
 
        if (eeprom->magic != 0xc3ec4951)
@@ -3903,6 +3924,13 @@ static void mv88e6xxx_phy_init(struct mv88e6xxx_chip *chip)
        }
 }
 
+static void mv88e6xxx_phy_destroy(struct mv88e6xxx_chip *chip)
+{
+       if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_PPU)) {
+               mv88e6xxx_ppu_state_destroy(chip);
+       }
+}
+
 static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
                              struct mii_bus *bus, int sw_addr)
 {
@@ -3923,6 +3951,16 @@ static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
        return 0;
 }
 
+static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
+{
+       struct mv88e6xxx_chip *chip = ds->priv;
+
+       if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_EDSA))
+               return DSA_TAG_PROTO_EDSA;
+
+       return DSA_TAG_PROTO_DSA;
+}
+
 static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
                                       struct device *host_dev, int sw_addr,
                                       void **priv)
@@ -3965,9 +4003,61 @@ free:
        return NULL;
 }
 
-static struct dsa_switch_driver mv88e6xxx_switch_driver = {
-       .tag_protocol           = DSA_TAG_PROTO_EDSA,
+static int mv88e6xxx_port_mdb_prepare(struct dsa_switch *ds, int port,
+                                     const struct switchdev_obj_port_mdb *mdb,
+                                     struct switchdev_trans *trans)
+{
+       /* We don't need any dynamic resource from the kernel (yet),
+        * so skip the prepare phase.
+        */
+
+       return 0;
+}
+
+static void mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
+                                  const struct switchdev_obj_port_mdb *mdb,
+                                  struct switchdev_trans *trans)
+{
+       struct mv88e6xxx_chip *chip = ds->priv;
+
+       mutex_lock(&chip->reg_lock);
+       if (mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
+                                        GLOBAL_ATU_DATA_STATE_MC_STATIC))
+               netdev_err(ds->ports[port].netdev, "failed to load multicast MAC address\n");
+       mutex_unlock(&chip->reg_lock);
+}
+
+static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,
+                                 const struct switchdev_obj_port_mdb *mdb)
+{
+       struct mv88e6xxx_chip *chip = ds->priv;
+       int err;
+
+       mutex_lock(&chip->reg_lock);
+       err = mv88e6xxx_port_db_load_purge(chip, port, mdb->addr, mdb->vid,
+                                          GLOBAL_ATU_DATA_STATE_UNUSED);
+       mutex_unlock(&chip->reg_lock);
+
+       return err;
+}
+
+static int mv88e6xxx_port_mdb_dump(struct dsa_switch *ds, int port,
+                                  struct switchdev_obj_port_mdb *mdb,
+                                  int (*cb)(struct switchdev_obj *obj))
+{
+       struct mv88e6xxx_chip *chip = ds->priv;
+       int err;
+
+       mutex_lock(&chip->reg_lock);
+       err = mv88e6xxx_port_db_dump(chip, port, &mdb->obj, cb);
+       mutex_unlock(&chip->reg_lock);
+
+       return err;
+}
+
+static struct dsa_switch_ops mv88e6xxx_switch_ops = {
        .probe                  = mv88e6xxx_drv_probe,
+       .get_tag_protocol       = mv88e6xxx_get_tag_protocol,
        .setup                  = mv88e6xxx_setup,
        .set_addr               = mv88e6xxx_set_addr,
        .adjust_link            = mv88e6xxx_adjust_link,
@@ -4000,6 +4090,10 @@ static struct dsa_switch_driver mv88e6xxx_switch_driver = {
        .port_fdb_add           = mv88e6xxx_port_fdb_add,
        .port_fdb_del           = mv88e6xxx_port_fdb_del,
        .port_fdb_dump          = mv88e6xxx_port_fdb_dump,
+       .port_mdb_prepare       = mv88e6xxx_port_mdb_prepare,
+       .port_mdb_add           = mv88e6xxx_port_mdb_add,
+       .port_mdb_del           = mv88e6xxx_port_mdb_del,
+       .port_mdb_dump          = mv88e6xxx_port_mdb_dump,
 };
 
 static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
@@ -4014,7 +4108,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
 
        ds->dev = dev;
        ds->priv = chip;
-       ds->drv = &mv88e6xxx_switch_driver;
+       ds->ops = &mv88e6xxx_switch_ops;
 
        dev_set_drvdata(dev, ds);
 
@@ -4079,8 +4173,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
 static void mv88e6xxx_remove(struct mdio_device *mdiodev)
 {
        struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
-       struct mv88e6xxx_chip *chip = ds_to_priv(ds);
+       struct mv88e6xxx_chip *chip = ds->priv;
 
+       mv88e6xxx_phy_destroy(chip);
        mv88e6xxx_unregister_switch(chip);
        mv88e6xxx_mdio_unregister(chip);
 }
@@ -4106,7 +4201,7 @@ static struct mdio_driver mv88e6xxx_driver = {
 
 static int __init mv88e6xxx_init(void)
 {
-       register_switch_driver(&mv88e6xxx_switch_driver);
+       register_switch_driver(&mv88e6xxx_switch_ops);
        return mdio_driver_register(&mv88e6xxx_driver);
 }
 module_init(mv88e6xxx_init);
@@ -4114,7 +4209,7 @@ module_init(mv88e6xxx_init);
 static void __exit mv88e6xxx_cleanup(void)
 {
        mdio_driver_unregister(&mv88e6xxx_driver);
-       unregister_switch_driver(&mv88e6xxx_switch_driver);
+       unregister_switch_driver(&mv88e6xxx_switch_ops);
 }
 module_exit(mv88e6xxx_cleanup);