net: dsa: sja1105: use 4095 as the private VLAN for untagged traffic
[linux-2.6-microblaze.git] / drivers / net / dsa / sja1105 / sja1105_main.c
index 51ea104..dffa7dd 100644 (file)
@@ -26,6 +26,7 @@
 #include "sja1105_tas.h"
 
 #define SJA1105_UNKNOWN_MULTICAST      0x010000000000ull
+#define SJA1105_DEFAULT_VLAN           (VLAN_N_VID - 1)
 
 static const struct dsa_switch_ops sja1105_switch_ops;
 
@@ -207,6 +208,7 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv,
                default:
                        dev_err(dev, "Unsupported PHY mode %s!\n",
                                phy_modes(ports[i].phy_mode));
+                       return -EINVAL;
                }
 
                /* Even though the SerDes port is able to drive SGMII autoneg
@@ -321,6 +323,13 @@ static int sja1105_init_l2_lookup_params(struct sja1105_private *priv)
        return 0;
 }
 
+/* Set up a default VLAN for untagged traffic injected from the CPU
+ * using management routes (e.g. STP, PTP) as opposed to tag_8021q.
+ * All DT-defined ports are members of this VLAN, and there are no
+ * restrictions on forwarding (since the CPU selects the destination).
+ * Frames from this VLAN will always be transmitted as untagged, and
+ * neither the bridge nor the 8021q module cannot create this VLAN ID.
+ */
 static int sja1105_init_static_vlan(struct sja1105_private *priv)
 {
        struct sja1105_table *table;
@@ -330,17 +339,13 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
                .vmemb_port = 0,
                .vlan_bc = 0,
                .tag_port = 0,
-               .vlanid = 1,
+               .vlanid = SJA1105_DEFAULT_VLAN,
        };
        struct dsa_switch *ds = priv->ds;
        int port;
 
        table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
 
-       /* The static VLAN table will only contain the initial pvid of 1.
-        * All other VLANs are to be configured through dynamic entries,
-        * and kept in the static configuration table as backing memory.
-        */
        if (table->entry_count) {
                kfree(table->entries);
                table->entry_count = 0;
@@ -353,9 +358,6 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
 
        table->entry_count = 1;
 
-       /* VLAN 1: all DT-defined ports are members; no restrictions on
-        * forwarding; always transmit as untagged.
-        */
        for (port = 0; port < ds->num_ports; port++) {
                struct sja1105_bridge_vlan *v;
 
@@ -366,15 +368,12 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
                pvid.vlan_bc |= BIT(port);
                pvid.tag_port &= ~BIT(port);
 
-               /* Let traffic that don't need dsa_8021q (e.g. STP, PTP) be
-                * transmitted as untagged.
-                */
                v = kzalloc(sizeof(*v), GFP_KERNEL);
                if (!v)
                        return -ENOMEM;
 
                v->port = port;
-               v->vid = 1;
+               v->vid = SJA1105_DEFAULT_VLAN;
                v->untagged = true;
                if (dsa_is_cpu_port(ds, port))
                        v->pvid = true;
@@ -2976,13 +2975,13 @@ static int sja1105_setup(struct dsa_switch *ds)
        rc = sja1105_static_config_load(priv, ports);
        if (rc < 0) {
                dev_err(ds->dev, "Failed to load static config: %d\n", rc);
-               return rc;
+               goto out_ptp_clock_unregister;
        }
        /* Configure the CGU (PHY link modes and speeds) */
        rc = sja1105_clocking_setup(priv);
        if (rc < 0) {
                dev_err(ds->dev, "Failed to configure MII clocking: %d\n", rc);
-               return rc;
+               goto out_static_config_free;
        }
        /* On SJA1105, VLAN filtering per se is always enabled in hardware.
         * The only thing we can do to disable it is lie about what the 802.1Q
@@ -3003,7 +3002,7 @@ static int sja1105_setup(struct dsa_switch *ds)
 
        rc = sja1105_devlink_setup(ds);
        if (rc < 0)
-               return rc;
+               goto out_static_config_free;
 
        /* The DSA/switchdev model brings up switch ports in standalone mode by
         * default, and that means vlan_filtering is 0 since they're not under
@@ -3012,6 +3011,17 @@ static int sja1105_setup(struct dsa_switch *ds)
        rtnl_lock();
        rc = sja1105_setup_8021q_tagging(ds, true);
        rtnl_unlock();
+       if (rc)
+               goto out_devlink_teardown;
+
+       return 0;
+
+out_devlink_teardown:
+       sja1105_devlink_teardown(ds);
+out_ptp_clock_unregister:
+       sja1105_ptp_clock_unregister(ds);
+out_static_config_free:
+       sja1105_static_config_free(&priv->static_config);
 
        return rc;
 }
@@ -3049,21 +3059,6 @@ static void sja1105_teardown(struct dsa_switch *ds)
        }
 }
 
-static int sja1105_port_enable(struct dsa_switch *ds, int port,
-                              struct phy_device *phy)
-{
-       struct net_device *slave;
-
-       if (!dsa_is_user_port(ds, port))
-               return 0;
-
-       slave = dsa_to_port(ds, port)->slave;
-
-       slave->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
-
-       return 0;
-}
-
 static void sja1105_port_disable(struct dsa_switch *ds, int port)
 {
        struct sja1105_private *priv = ds->priv;
@@ -3152,7 +3147,7 @@ static void sja1105_port_deferred_xmit(struct kthread_work *work)
        struct sk_buff *skb;
 
        while ((skb = skb_dequeue(&sp->xmit_queue)) != NULL) {
-               struct sk_buff *clone = DSA_SKB_CB(skb)->clone;
+               struct sk_buff *clone = SJA1105_SKB_CB(skb)->clone;
 
                mutex_lock(&priv->mgmt_lock);
 
@@ -3491,7 +3486,6 @@ static const struct dsa_switch_ops sja1105_switch_ops = {
        .get_ethtool_stats      = sja1105_get_ethtool_stats,
        .get_sset_count         = sja1105_get_sset_count,
        .get_ts_info            = sja1105_get_ts_info,
-       .port_enable            = sja1105_port_enable,
        .port_disable           = sja1105_port_disable,
        .port_fdb_dump          = sja1105_fdb_dump,
        .port_fdb_add           = sja1105_fdb_add,
@@ -3662,8 +3656,10 @@ static int sja1105_probe(struct spi_device *spi)
                priv->cbs = devm_kcalloc(dev, priv->info->num_cbs_shapers,
                                         sizeof(struct sja1105_cbs_entry),
                                         GFP_KERNEL);
-               if (!priv->cbs)
-                       return -ENOMEM;
+               if (!priv->cbs) {
+                       rc = -ENOMEM;
+                       goto out_unregister_switch;
+               }
        }
 
        /* Connections between dsa_port and sja1105_port */
@@ -3688,7 +3684,7 @@ static int sja1105_probe(struct spi_device *spi)
                        dev_err(ds->dev,
                                "failed to create deferred xmit thread: %d\n",
                                rc);
-                       goto out;
+                       goto out_destroy_workers;
                }
                skb_queue_head_init(&sp->xmit_queue);
                sp->xmit_tpid = ETH_P_SJA1105;
@@ -3698,7 +3694,8 @@ static int sja1105_probe(struct spi_device *spi)
        }
 
        return 0;
-out:
+
+out_destroy_workers:
        while (port-- > 0) {
                struct sja1105_port *sp = &priv->ports[port];
 
@@ -3707,6 +3704,10 @@ out:
 
                kthread_destroy_worker(sp->xmit_worker);
        }
+
+out_unregister_switch:
+       dsa_unregister_switch(ds);
+
        return rc;
 }