]> git.karo-electronics.de Git - linux-beck.git/commitdiff
net: dsa: mv88e6xxx: add port 802.1Q mode setter
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Fri, 4 Nov 2016 02:23:31 +0000 (03:23 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 4 Nov 2016 18:39:59 +0000 (14:39 -0400)
Add port functions to set the port 802.1Q mode.

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 9c0a0283f9618dd69eb4d1cd8beca7ffd8752bb7..181d3b9aad066f2cea7513822e5ab7cdceb9aaaf 100644 (file)
@@ -1806,48 +1806,19 @@ unlock:
        return err;
 }
 
-static const char * const mv88e6xxx_port_8021q_mode_names[] = {
-       [PORT_CONTROL_2_8021Q_DISABLED] = "Disabled",
-       [PORT_CONTROL_2_8021Q_FALLBACK] = "Fallback",
-       [PORT_CONTROL_2_8021Q_CHECK] = "Check",
-       [PORT_CONTROL_2_8021Q_SECURE] = "Secure",
-};
-
 static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
                                         bool vlan_filtering)
 {
        struct mv88e6xxx_chip *chip = ds->priv;
-       u16 old, new = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
+       u16 mode = vlan_filtering ? PORT_CONTROL_2_8021Q_SECURE :
                PORT_CONTROL_2_8021Q_DISABLED;
-       u16 reg;
        int err;
 
        if (!mv88e6xxx_has(chip, MV88E6XXX_FLAG_VTU))
                return -EOPNOTSUPP;
 
        mutex_lock(&chip->reg_lock);
-
-       err = mv88e6xxx_port_read(chip, port, PORT_CONTROL_2, &reg);
-       if (err)
-               goto unlock;
-
-       old = reg & PORT_CONTROL_2_8021Q_MASK;
-
-       if (new != old) {
-               reg &= ~PORT_CONTROL_2_8021Q_MASK;
-               reg |= new & PORT_CONTROL_2_8021Q_MASK;
-
-               err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
-               if (err)
-                       goto unlock;
-
-               netdev_dbg(ds->ports[port].netdev, "802.1Q Mode %s (was %s)\n",
-                          mv88e6xxx_port_8021q_mode_names[new],
-                          mv88e6xxx_port_8021q_mode_names[old]);
-       }
-
-       err = 0;
-unlock:
+       err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
        mutex_unlock(&chip->reg_lock);
 
        return err;
index 104fe2d9d4e15cb9f4438dca07956651cedda441..53d17e63b04aa26cdfd829ba751aa86a07a025eb 100644 (file)
@@ -190,3 +190,35 @@ int mv88e6xxx_port_set_pvid(struct mv88e6xxx_chip *chip, int port, u16 pvid)
 
        return 0;
 }
+
+/* Offset 0x08: Port Control 2 Register */
+
+static const char * const mv88e6xxx_port_8021q_mode_names[] = {
+       [PORT_CONTROL_2_8021Q_DISABLED] = "Disabled",
+       [PORT_CONTROL_2_8021Q_FALLBACK] = "Fallback",
+       [PORT_CONTROL_2_8021Q_CHECK] = "Check",
+       [PORT_CONTROL_2_8021Q_SECURE] = "Secure",
+};
+
+int mv88e6xxx_port_set_8021q_mode(struct mv88e6xxx_chip *chip, int port,
+                                 u16 mode)
+{
+       u16 reg;
+       int err;
+
+       err = mv88e6xxx_port_read(chip, port, PORT_CONTROL_2, &reg);
+       if (err)
+               return err;
+
+       reg &= ~PORT_CONTROL_2_8021Q_MASK;
+       reg |= mode & PORT_CONTROL_2_8021Q_MASK;
+
+       err = mv88e6xxx_port_write(chip, port, PORT_CONTROL_2, reg);
+       if (err)
+               return err;
+
+       netdev_dbg(chip->ds->ports[port].netdev, "802.1QMode set to %s\n",
+                  mv88e6xxx_port_8021q_mode_names[mode]);
+
+       return 0;
+}
index 4489d9e88689795d6ead80b237e9e8e9be6786b6..921eecf8acb8546bd8c229203c65bae382f0dd64 100644 (file)
@@ -31,4 +31,7 @@ int mv88e6xxx_port_set_fid(struct mv88e6xxx_chip *chip, int port, u16 fid);
 int mv88e6xxx_port_get_pvid(struct mv88e6xxx_chip *chip, int port, u16 *pvid);
 int mv88e6xxx_port_set_pvid(struct mv88e6xxx_chip *chip, int port, u16 pvid);
 
+int mv88e6xxx_port_set_8021q_mode(struct mv88e6xxx_chip *chip, int port,
+                                 u16 mode);
+
 #endif /* _MV88E6XXX_PORT_H */