]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
net: dsa: mv88e6xxx: Allow dynamic reconfiguration of tag protocol
authorTobias Waldekranz <tobias@waldekranz.com>
Tue, 20 Apr 2021 18:53:08 +0000 (20:53 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 20 Apr 2021 23:51:19 +0000 (16:51 -0700)
For devices that supports both regular and Ethertyped DSA tags, allow
the user to change the protocol.

Additionally, because there are ethernet controllers that do not
handle regular DSA tags in all cases, also allow the protocol to be
changed on devices with undocumented support for EDSA. But, in those
cases, make sure to log the fact that an undocumented feature has been
enabled.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx/chip.c

index 6fbc1eed05c168d55158fe715e391ed979ae3530..9ff1a10993b1e3ec1e2615957fcab5333b8c1c4a 100644 (file)
@@ -5551,6 +5551,44 @@ static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
        return chip->tag_protocol;
 }
 
+static int mv88e6xxx_change_tag_protocol(struct dsa_switch *ds, int port,
+                                        enum dsa_tag_protocol proto)
+{
+       struct mv88e6xxx_chip *chip = ds->priv;
+       enum dsa_tag_protocol old_protocol;
+       int err;
+
+       switch (proto) {
+       case DSA_TAG_PROTO_EDSA:
+               switch (chip->info->edsa_support) {
+               case MV88E6XXX_EDSA_UNSUPPORTED:
+                       return -EPROTONOSUPPORT;
+               case MV88E6XXX_EDSA_UNDOCUMENTED:
+                       dev_warn(chip->dev, "Relying on undocumented EDSA tagging behavior\n");
+                       fallthrough;
+               case MV88E6XXX_EDSA_SUPPORTED:
+                       break;
+               }
+               break;
+       case DSA_TAG_PROTO_DSA:
+               break;
+       default:
+               return -EPROTONOSUPPORT;
+       }
+
+       old_protocol = chip->tag_protocol;
+       chip->tag_protocol = proto;
+
+       mv88e6xxx_reg_lock(chip);
+       err = mv88e6xxx_setup_port_mode(chip, port);
+       mv88e6xxx_reg_unlock(chip);
+
+       if (err)
+               chip->tag_protocol = old_protocol;
+
+       return err;
+}
+
 static int mv88e6xxx_port_mdb_add(struct dsa_switch *ds, int port,
                                  const struct switchdev_obj_port_mdb *mdb)
 {
@@ -6013,6 +6051,7 @@ static int mv88e6xxx_crosschip_lag_leave(struct dsa_switch *ds, int sw_index,
 
 static const struct dsa_switch_ops mv88e6xxx_switch_ops = {
        .get_tag_protocol       = mv88e6xxx_get_tag_protocol,
+       .change_tag_protocol    = mv88e6xxx_change_tag_protocol,
        .setup                  = mv88e6xxx_setup,
        .teardown               = mv88e6xxx_teardown,
        .phylink_validate       = mv88e6xxx_validate,