net: dsa: mv88e6xxx: add port state setter
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Fri, 4 Nov 2016 02:23:27 +0000 (03:23 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 4 Nov 2016 18:39:58 +0000 (14:39 -0400)
Add the port STP state setter to the port files.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx/chip.c
drivers/net/dsa/mv88e6xxx/port.c
drivers/net/dsa/mv88e6xxx/port.h

index b32b2425606562fb8a201f8973a2dbe783f8e8c6..12c1175ce55d22c670b44ede0c27bae541dd602b 100644 (file)
@@ -1215,41 +1215,6 @@ static int _mv88e6xxx_atu_remove(struct mv88e6xxx_chip *chip, u16 fid,
        return _mv88e6xxx_atu_move(chip, fid, port, 0x0f, static_too);
 }
 
-static const char * const mv88e6xxx_port_state_names[] = {
-       [PORT_CONTROL_STATE_DISABLED] = "Disabled",
-       [PORT_CONTROL_STATE_BLOCKING] = "Blocking/Listening",
-       [PORT_CONTROL_STATE_LEARNING] = "Learning",
-       [PORT_CONTROL_STATE_FORWARDING] = "Forwarding",
-};
-
-static int _mv88e6xxx_port_state(struct mv88e6xxx_chip *chip, int port,
-                                u8 state)
-{
-       struct dsa_switch *ds = chip->ds;
-       u16 reg;
-       int err;
-       u8 oldstate;
-
-       err = mv88e6xxx_port_read(chip, port, PORT_CONTROL, &reg);
-       if (err)
-               return err;
-
-       oldstate = reg & PORT_CONTROL_STATE_MASK;
-
-       reg &= ~PORT_CONTROL_STATE_MASK;
-       reg |= state;
-
-       err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
-       if (err)
-               return err;
-
-       netdev_dbg(ds->ports[port].netdev, "PortState %s (was %s)\n",
-                  mv88e6xxx_port_state_names[state],
-                  mv88e6xxx_port_state_names[oldstate]);
-
-       return 0;
-}
-
 static int _mv88e6xxx_port_based_vlan_map(struct mv88e6xxx_chip *chip, int port)
 {
        struct net_device *bridge = chip->ports[port].bridge_dev;
@@ -1313,13 +1278,11 @@ static void mv88e6xxx_port_stp_state_set(struct dsa_switch *ds, int port,
        }
 
        mutex_lock(&chip->reg_lock);
-       err = _mv88e6xxx_port_state(chip, port, stp_state);
+       err = mv88e6xxx_port_set_state(chip, port, stp_state);
        mutex_unlock(&chip->reg_lock);
 
        if (err)
-               netdev_err(ds->ports[port].netdev,
-                          "failed to update state to %s\n",
-                          mv88e6xxx_port_state_names[stp_state]);
+               netdev_err(ds->ports[port].netdev, "failed to update state\n");
 }
 
 static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)
@@ -2526,12 +2489,8 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
 
        /* Set all ports to the disabled state. */
        for (i = 0; i < mv88e6xxx_num_ports(chip); i++) {
-               err = mv88e6xxx_port_read(chip, i, PORT_CONTROL, &reg);
-               if (err)
-                       return err;
-
-               err = mv88e6xxx_port_write(chip, i, PORT_CONTROL,
-                                          reg & 0xfffc);
+               err = mv88e6xxx_port_set_state(chip, i,
+                                              PORT_CONTROL_STATE_DISABLED);
                if (err)
                        return err;
        }
index 3b36c9290ea84418d18b1ac39bd6462e99e529b1..8d59fe73a8342b962e72194ab4e1a2447726b599 100644 (file)
@@ -29,3 +29,34 @@ int mv88e6xxx_port_write(struct mv88e6xxx_chip *chip, int port, int reg,
 
        return mv88e6xxx_write(chip, addr, reg, val);
 }
+
+/* Offset 0x04: Port Control Register */
+
+static const char * const mv88e6xxx_port_state_names[] = {
+       [PORT_CONTROL_STATE_DISABLED] = "Disabled",
+       [PORT_CONTROL_STATE_BLOCKING] = "Blocking/Listening",
+       [PORT_CONTROL_STATE_LEARNING] = "Learning",
+       [PORT_CONTROL_STATE_FORWARDING] = "Forwarding",
+};
+
+int mv88e6xxx_port_set_state(struct mv88e6xxx_chip *chip, int port, u8 state)
+{
+       u16 reg;
+       int err;
+
+       err = mv88e6xxx_port_read(chip, port, PORT_CONTROL, &reg);
+       if (err)
+               return err;
+
+       reg &= ~PORT_CONTROL_STATE_MASK;
+       reg |= state;
+
+       err = mv88e6xxx_port_write(chip, port, PORT_CONTROL, reg);
+       if (err)
+               return err;
+
+       netdev_dbg(chip->ds->ports[port].netdev, "PortState set to %s\n",
+                  mv88e6xxx_port_state_names[state]);
+
+       return 0;
+}
index ae1ae2b501b614df43d9094b6bdc188270bd8e53..ac13988fc79a0ec14898942eec77c4068306f437 100644 (file)
@@ -21,4 +21,6 @@ int mv88e6xxx_port_read(struct mv88e6xxx_chip *chip, int port, int reg,
 int mv88e6xxx_port_write(struct mv88e6xxx_chip *chip, int port, int reg,
                         u16 val);
 
+int mv88e6xxx_port_set_state(struct mv88e6xxx_chip *chip, int port, u8 state);
+
 #endif /* _MV88E6XXX_PORT_H */