net: dsa: mv88e6xxx: flush VTU and STU entries
[firefly-linux-kernel-4.4.55.git] / drivers / net / dsa / mv88e6xxx.c
index 9c6781de533b96df4fb834e1aa0ed7c6b5f8bb4f..175353a659d4ff904e8972ae27af3f385c3d9401 100644 (file)
@@ -1182,8 +1182,36 @@ int mv88e6xxx_port_stp_update(struct dsa_switch *ds, int port, u8 state)
        return 0;
 }
 
+static int _mv88e6xxx_vtu_wait(struct dsa_switch *ds)
+{
+       return _mv88e6xxx_wait(ds, REG_GLOBAL, GLOBAL_VTU_OP,
+                              GLOBAL_VTU_OP_BUSY);
+}
+
+static int _mv88e6xxx_vtu_cmd(struct dsa_switch *ds, u16 op)
+{
+       int ret;
+
+       ret = _mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_VTU_OP, op);
+       if (ret < 0)
+               return ret;
+
+       return _mv88e6xxx_vtu_wait(ds);
+}
+
+static int _mv88e6xxx_vtu_stu_flush(struct dsa_switch *ds)
+{
+       int ret;
+
+       ret = _mv88e6xxx_vtu_wait(ds);
+       if (ret < 0)
+               return ret;
+
+       return _mv88e6xxx_vtu_cmd(ds, GLOBAL_VTU_OP_FLUSH_ALL);
+}
+
 static int _mv88e6xxx_atu_mac_write(struct dsa_switch *ds,
-                                   const u8 addr[ETH_ALEN])
+                                   const unsigned char *addr)
 {
        int i, ret;
 
@@ -1198,7 +1226,7 @@ static int _mv88e6xxx_atu_mac_write(struct dsa_switch *ds,
        return 0;
 }
 
-static int _mv88e6xxx_atu_mac_read(struct dsa_switch *ds, u8 addr[ETH_ALEN])
+static int _mv88e6xxx_atu_mac_read(struct dsa_switch *ds, unsigned char *addr)
 {
        int i, ret;
 
@@ -1252,56 +1280,6 @@ static int _mv88e6xxx_atu_load(struct dsa_switch *ds,
        return _mv88e6xxx_atu_cmd(ds, entry->fid, GLOBAL_ATU_OP_LOAD_DB);
 }
 
-static int _mv88e6xxx_atu_getnext(struct dsa_switch *ds, u16 fid,
-                                 const u8 addr[ETH_ALEN],
-                                 struct mv88e6xxx_atu_entry *entry)
-{
-       struct mv88e6xxx_atu_entry next = { 0 };
-       int ret;
-
-       next.fid = fid;
-
-       ret = _mv88e6xxx_atu_wait(ds);
-       if (ret < 0)
-               return ret;
-
-       ret = _mv88e6xxx_atu_mac_write(ds, addr);
-       if (ret < 0)
-               return ret;
-
-       ret = _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
-       if (ret < 0)
-               return ret;
-
-       ret = _mv88e6xxx_atu_mac_read(ds, next.mac);
-       if (ret < 0)
-               return ret;
-
-       ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA);
-       if (ret < 0)
-               return ret;
-
-       next.state = ret & GLOBAL_ATU_DATA_STATE_MASK;
-       if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
-               unsigned int mask, shift;
-
-               if (ret & GLOBAL_ATU_DATA_TRUNK) {
-                       next.trunk = true;
-                       mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
-                       shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
-               } else {
-                       next.trunk = false;
-                       mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
-                       shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
-               }
-
-               next.portv_trunkid = (ret & mask) >> shift;
-       }
-
-       *entry = next;
-       return 0;
-}
-
 static int _mv88e6xxx_port_vid_to_fid(struct dsa_switch *ds, int port, u16 vid)
 {
        struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
@@ -1312,8 +1290,9 @@ static int _mv88e6xxx_port_vid_to_fid(struct dsa_switch *ds, int port, u16 vid)
        return -ENOENT;
 }
 
-static int _mv88e6xxx_port_fdb_load(struct dsa_switch *ds, int port, u16 vid,
-                                   const u8 addr[ETH_ALEN], u8 state)
+static int _mv88e6xxx_port_fdb_load(struct dsa_switch *ds, int port,
+                                   const unsigned char *addr, u16 vid,
+                                   u8 state)
 {
        struct mv88e6xxx_atu_entry entry = { 0 };
        int ret;
@@ -1333,38 +1312,89 @@ static int _mv88e6xxx_port_fdb_load(struct dsa_switch *ds, int port, u16 vid,
        return _mv88e6xxx_atu_load(ds, &entry);
 }
 
-int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port, u16 vid,
-                          const u8 addr[ETH_ALEN])
+int mv88e6xxx_port_fdb_add(struct dsa_switch *ds, int port,
+                          const unsigned char *addr, u16 vid)
 {
-       struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
-       u8 state = is_multicast_ether_addr(addr) ?
+       int state = is_multicast_ether_addr(addr) ?
                GLOBAL_ATU_DATA_STATE_MC_STATIC :
                GLOBAL_ATU_DATA_STATE_UC_STATIC;
+       struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
        int ret;
 
        mutex_lock(&ps->smi_mutex);
-       ret = _mv88e6xxx_port_fdb_load(ds, port, vid, addr, state);
+       ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid, state);
        mutex_unlock(&ps->smi_mutex);
 
        return ret;
 }
 
-int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port, u16 vid,
-                          const u8 addr[ETH_ALEN])
+int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,
+                          const unsigned char *addr, u16 vid)
 {
        struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
-       u8 state = GLOBAL_ATU_DATA_STATE_UNUSED;
        int ret;
 
        mutex_lock(&ps->smi_mutex);
-       ret = _mv88e6xxx_port_fdb_load(ds, port, vid, addr, state);
+       ret = _mv88e6xxx_port_fdb_load(ds, port, addr, vid,
+                                      GLOBAL_ATU_DATA_STATE_UNUSED);
        mutex_unlock(&ps->smi_mutex);
 
        return ret;
 }
 
-int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port, u16 *vid,
-                              u8 addr[ETH_ALEN], bool *is_static)
+static int _mv88e6xxx_atu_getnext(struct dsa_switch *ds, u16 fid,
+                                 const unsigned char *addr,
+                                 struct mv88e6xxx_atu_entry *entry)
+{
+       struct mv88e6xxx_atu_entry next = { 0 };
+       int ret;
+
+       next.fid = fid;
+
+       ret = _mv88e6xxx_atu_wait(ds);
+       if (ret < 0)
+               return ret;
+
+       ret = _mv88e6xxx_atu_mac_write(ds, addr);
+       if (ret < 0)
+               return ret;
+
+       ret = _mv88e6xxx_atu_cmd(ds, fid, GLOBAL_ATU_OP_GET_NEXT_DB);
+       if (ret < 0)
+               return ret;
+
+       ret = _mv88e6xxx_atu_mac_read(ds, next.mac);
+       if (ret < 0)
+               return ret;
+
+       ret = _mv88e6xxx_reg_read(ds, REG_GLOBAL, GLOBAL_ATU_DATA);
+       if (ret < 0)
+               return ret;
+
+       next.state = ret & GLOBAL_ATU_DATA_STATE_MASK;
+       if (next.state != GLOBAL_ATU_DATA_STATE_UNUSED) {
+               unsigned int mask, shift;
+
+               if (ret & GLOBAL_ATU_DATA_TRUNK) {
+                       next.trunk = true;
+                       mask = GLOBAL_ATU_DATA_TRUNK_ID_MASK;
+                       shift = GLOBAL_ATU_DATA_TRUNK_ID_SHIFT;
+               } else {
+                       next.trunk = false;
+                       mask = GLOBAL_ATU_DATA_PORT_VECTOR_MASK;
+                       shift = GLOBAL_ATU_DATA_PORT_VECTOR_SHIFT;
+               }
+
+               next.portv_trunkid = (ret & mask) >> shift;
+       }
+
+       *entry = next;
+       return 0;
+}
+
+/* get next entry for port */
+int mv88e6xxx_port_fdb_getnext(struct dsa_switch *ds, int port,
+                              unsigned char *addr, u16 *vid, bool *is_static)
 {
        struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
        struct mv88e6xxx_atu_entry next;
@@ -2069,6 +2099,12 @@ int mv88e6xxx_setup_global(struct dsa_switch *ds)
        /* Wait for the flush to complete. */
        mutex_lock(&ps->smi_mutex);
        ret = _mv88e6xxx_stats_wait(ds);
+       if (ret < 0)
+               goto unlock;
+
+       /* Clear all the VTU and STU entries */
+       ret = _mv88e6xxx_vtu_stu_flush(ds);
+unlock:
        mutex_unlock(&ps->smi_mutex);
 
        return ret;