net: dsa: Pass a port to get_tag_protocol()
authorFlorian Fainelli <f.fainelli@gmail.com>
Fri, 10 Nov 2017 23:22:52 +0000 (15:22 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 13 Nov 2017 01:34:54 +0000 (10:34 +0900)
A number of drivers want to check whether the configured CPU port is a
possible configuration for enabling tagging, pass down the CPU port
number so they verify that.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
12 files changed:
drivers/net/dsa/b53/b53_common.c
drivers/net/dsa/bcm_sf2.c
drivers/net/dsa/dsa_loop.c
drivers/net/dsa/lan9303-core.c
drivers/net/dsa/microchip/ksz_common.c
drivers/net/dsa/mt7530.c
drivers/net/dsa/mv88e6060.c
drivers/net/dsa/mv88e6xxx/chip.c
drivers/net/dsa/qca8k.c
include/net/dsa.h
net/dsa/dsa2.c
net/dsa/legacy.c

index 44a9a03bff550ea9fdcaf9ed998daa7eb39f400b..f72aeb9ed12a878f87f19bc116661f2a0cc541ff 100644 (file)
@@ -541,7 +541,8 @@ EXPORT_SYMBOL(b53_disable_port);
 
 void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
 {
-       bool tag_en = !!(ds->ops->get_tag_protocol(ds) == DSA_TAG_PROTO_BRCM);
+       bool tag_en = !!(ds->ops->get_tag_protocol(ds, port) ==
+                        DSA_TAG_PROTO_BRCM);
        struct b53_device *dev = ds->priv;
        u8 hdr_ctl, val;
        u16 reg;
@@ -1478,38 +1479,31 @@ void b53_br_fast_age(struct dsa_switch *ds, int port)
 }
 EXPORT_SYMBOL(b53_br_fast_age);
 
-static bool b53_can_enable_brcm_tags(struct dsa_switch *ds)
+static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port)
 {
-       unsigned int brcm_tag_mask;
-       unsigned int i;
-
        /* Broadcom switches will accept enabling Broadcom tags on the
         * following ports: 5, 7 and 8, any other port is not supported
         */
-       brcm_tag_mask = BIT(B53_CPU_PORT_25) | BIT(7) | BIT(B53_CPU_PORT);
-
-       for (i = 0; i < ds->num_ports; i++) {
-               if (dsa_is_cpu_port(ds, i)) {
-                       if (!(BIT(i) & brcm_tag_mask)) {
-                               dev_warn(ds->dev,
-                                        "Port %d is not Broadcom tag capable\n",
-                                        i);
-                               return false;
-                       }
-               }
+       switch (port) {
+       case B53_CPU_PORT_25:
+       case 7:
+       case B53_CPU_PORT:
+               return true;
        }
 
-       return true;
+       dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", port);
+       return false;
 }
 
-static enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds)
+static enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds,
+                                                 int port)
 {
        struct b53_device *dev = ds->priv;
 
        /* Older models support a different tag format that we do not
         * support in net/dsa/tag_brcm.c yet.
         */
-       if (is5325(dev) || is5365(dev) || !b53_can_enable_brcm_tags(ds))
+       if (is5325(dev) || is5365(dev) || !b53_can_enable_brcm_tags(ds, port))
                return DSA_TAG_PROTO_NONE;
        else
                return DSA_TAG_PROTO_BRCM;
index 2d6867f4008c2df96f04b5400a1643e998792415..93faa1fed6f266017415753fbe383227f22e4a96 100644 (file)
@@ -35,7 +35,8 @@
 #include "b53/b53_priv.h"
 #include "b53/b53_regs.h"
 
-static enum dsa_tag_protocol bcm_sf2_sw_get_tag_protocol(struct dsa_switch *ds)
+static enum dsa_tag_protocol bcm_sf2_sw_get_tag_protocol(struct dsa_switch *ds,
+                                                        int port)
 {
        return DSA_TAG_PROTO_BRCM;
 }
index 3a3f4f7ba36471a33c0926dfbed1d03ee2c2c140..bb71d3d6f65b008dc5195b625ef579af848fea26 100644 (file)
@@ -64,7 +64,8 @@ struct dsa_loop_priv {
 
 static struct phy_device *phydevs[PHY_MAX_ADDR];
 
-static enum dsa_tag_protocol dsa_loop_get_protocol(struct dsa_switch *ds)
+static enum dsa_tag_protocol dsa_loop_get_protocol(struct dsa_switch *ds,
+                                                  int port)
 {
        dev_dbg(ds->dev, "%s\n", __func__);
 
index a2610085e7ba0ef82375df6d69ad394866506c62..fdfdb0edfe624eef313edaf42ec1aebd1caf910b 100644 (file)
@@ -894,7 +894,8 @@ static int lan9303_check_device(struct lan9303 *chip)
 
 /* ---------------------------- DSA -----------------------------------*/
 
-static enum dsa_tag_protocol lan9303_get_tag_protocol(struct dsa_switch *ds)
+static enum dsa_tag_protocol lan9303_get_tag_protocol(struct dsa_switch *ds,
+                                                     int port)
 {
        return DSA_TAG_PROTO_LAN9303;
 }
index 56cd6d365352e2b00d20f80434fed301449ec53d..b5be93a1e0df88a5fcf44dce1d85fdfb4df17ff4 100644 (file)
@@ -394,7 +394,8 @@ static int ksz_setup(struct dsa_switch *ds)
        return 0;
 }
 
-static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds)
+static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
+                                                 int port)
 {
        return DSA_TAG_PROTO_KSZ;
 }
index 627c039f12ca71de7ce7b79662ad6b14a340ab35..2820d69810b307322978729e376002984e308ed6 100644 (file)
@@ -907,11 +907,11 @@ err:
 }
 
 static enum dsa_tag_protocol
-mtk_get_tag_protocol(struct dsa_switch *ds)
+mtk_get_tag_protocol(struct dsa_switch *ds, int port)
 {
        struct mt7530_priv *priv = ds->priv;
 
-       if (!dsa_is_cpu_port(ds, MT7530_CPU_PORT)) {
+       if (port != MT7530_CPU_PORT) {
                dev_warn(priv->dev,
                         "port not matched with tagging CPU port\n");
                return DSA_TAG_PROTO_NONE;
index 45768e3c5bc587a1ce6b755e01ad2c2d5b5169ce..65f10fec25b397345b03e503526a3b40de514a3a 100644 (file)
@@ -70,7 +70,8 @@ static const char *mv88e6060_get_name(struct mii_bus *bus, int sw_addr)
        return NULL;
 }
 
-static enum dsa_tag_protocol mv88e6060_get_tag_protocol(struct dsa_switch *ds)
+static enum dsa_tag_protocol mv88e6060_get_tag_protocol(struct dsa_switch *ds,
+                                                       int port)
 {
        return DSA_TAG_PROTO_TRAILER;
 }
index d6c3a22c8789cf1060cf5e92c05d17bf4e22de2b..8171055fde7a0238fb2fbc691a482c211d4d8d5b 100644 (file)
@@ -3731,7 +3731,8 @@ static int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip,
        return 0;
 }
 
-static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds)
+static enum dsa_tag_protocol mv88e6xxx_get_tag_protocol(struct dsa_switch *ds,
+                                                       int port)
 {
        struct mv88e6xxx_chip *chip = ds->priv;
 
index cf72e274275fe926f45ee77aa2ab853851964ef5..9df22ebee8223822d8bbfebe299b3f6ccfefc84e 100644 (file)
@@ -823,7 +823,7 @@ qca8k_port_fdb_dump(struct dsa_switch *ds, int port,
 }
 
 static enum dsa_tag_protocol
-qca8k_get_tag_protocol(struct dsa_switch *ds)
+qca8k_get_tag_protocol(struct dsa_switch *ds, int port)
 {
        return DSA_TAG_PROTO_QCA;
 }
index 6c239257309b9dfc61af130c29adcd93ee8f8531..68e232fd4b0f0476e3cd4f658e05bdaf94932454 100644 (file)
@@ -321,7 +321,8 @@ struct dsa_switch_ops {
                                  struct device *host_dev, int sw_addr,
                                  void **priv);
 
-       enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds);
+       enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
+                                                 int port);
 
        int     (*setup)(struct dsa_switch *ds);
        u32     (*get_phy_flags)(struct dsa_switch *ds, int port);
index fd54a8e17986d01d005c50f344d87c9ea5930a87..44e3fb7dec8cfa1b8d3da54590238e2cacc37782 100644 (file)
@@ -539,7 +539,7 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master)
        const struct dsa_device_ops *tag_ops;
        enum dsa_tag_protocol tag_protocol;
 
-       tag_protocol = ds->ops->get_tag_protocol(ds);
+       tag_protocol = ds->ops->get_tag_protocol(ds, dp->index);
        tag_ops = dsa_resolve_tag_protocol(tag_protocol);
        if (IS_ERR(tag_ops)) {
                dev_warn(ds->dev, "No tagger for this switch\n");
index 4863e3e398b616714f668dc0edcc06f446867fb9..84611d7fcfa2c973c02b08b55e048d69ca4837c1 100644 (file)
@@ -151,7 +151,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
                const struct dsa_device_ops *tag_ops;
                enum dsa_tag_protocol tag_protocol;
 
-               tag_protocol = ops->get_tag_protocol(ds);
+               tag_protocol = ops->get_tag_protocol(ds, dst->cpu_dp->index);
                tag_ops = dsa_resolve_tag_protocol(tag_protocol);
                if (IS_ERR(tag_ops))
                        return PTR_ERR(tag_ops);