26
26
#include "sja1105_tas.h"
27
27
28
28
#define SJA1105_UNKNOWN_MULTICAST 0x010000000000ull
29
+ #define SJA1105_DEFAULT_VLAN (VLAN_N_VID - 1)
29
30
30
31
static const struct dsa_switch_ops sja1105_switch_ops ;
31
32
@@ -207,6 +208,7 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv,
207
208
default :
208
209
dev_err (dev , "Unsupported PHY mode %s!\n" ,
209
210
phy_modes (ports [i ].phy_mode ));
211
+ return - EINVAL ;
210
212
}
211
213
212
214
/* 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)
321
323
return 0 ;
322
324
}
323
325
326
+ /* Set up a default VLAN for untagged traffic injected from the CPU
327
+ * using management routes (e.g. STP, PTP) as opposed to tag_8021q.
328
+ * All DT-defined ports are members of this VLAN, and there are no
329
+ * restrictions on forwarding (since the CPU selects the destination).
330
+ * Frames from this VLAN will always be transmitted as untagged, and
331
+ * neither the bridge nor the 8021q module cannot create this VLAN ID.
332
+ */
324
333
static int sja1105_init_static_vlan (struct sja1105_private * priv )
325
334
{
326
335
struct sja1105_table * table ;
@@ -330,17 +339,13 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
330
339
.vmemb_port = 0 ,
331
340
.vlan_bc = 0 ,
332
341
.tag_port = 0 ,
333
- .vlanid = 1 ,
342
+ .vlanid = SJA1105_DEFAULT_VLAN ,
334
343
};
335
344
struct dsa_switch * ds = priv -> ds ;
336
345
int port ;
337
346
338
347
table = & priv -> static_config .tables [BLK_IDX_VLAN_LOOKUP ];
339
348
340
- /* The static VLAN table will only contain the initial pvid of 1.
341
- * All other VLANs are to be configured through dynamic entries,
342
- * and kept in the static configuration table as backing memory.
343
- */
344
349
if (table -> entry_count ) {
345
350
kfree (table -> entries );
346
351
table -> entry_count = 0 ;
@@ -353,9 +358,6 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
353
358
354
359
table -> entry_count = 1 ;
355
360
356
- /* VLAN 1: all DT-defined ports are members; no restrictions on
357
- * forwarding; always transmit as untagged.
358
- */
359
361
for (port = 0 ; port < ds -> num_ports ; port ++ ) {
360
362
struct sja1105_bridge_vlan * v ;
361
363
@@ -366,15 +368,12 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
366
368
pvid .vlan_bc |= BIT (port );
367
369
pvid .tag_port &= ~BIT (port );
368
370
369
- /* Let traffic that don't need dsa_8021q (e.g. STP, PTP) be
370
- * transmitted as untagged.
371
- */
372
371
v = kzalloc (sizeof (* v ), GFP_KERNEL );
373
372
if (!v )
374
373
return - ENOMEM ;
375
374
376
375
v -> port = port ;
377
- v -> vid = 1 ;
376
+ v -> vid = SJA1105_DEFAULT_VLAN ;
378
377
v -> untagged = true;
379
378
if (dsa_is_cpu_port (ds , port ))
380
379
v -> pvid = true;
@@ -2817,11 +2816,22 @@ static int sja1105_vlan_add_one(struct dsa_switch *ds, int port, u16 vid,
2817
2816
bool pvid = flags & BRIDGE_VLAN_INFO_PVID ;
2818
2817
struct sja1105_bridge_vlan * v ;
2819
2818
2820
- list_for_each_entry (v , vlan_list , list )
2821
- if (v -> port == port && v -> vid == vid &&
2822
- v -> untagged == untagged && v -> pvid == pvid )
2819
+ list_for_each_entry (v , vlan_list , list ) {
2820
+ if (v -> port == port && v -> vid == vid ) {
2823
2821
/* Already added */
2824
- return 0 ;
2822
+ if (v -> untagged == untagged && v -> pvid == pvid )
2823
+ /* Nothing changed */
2824
+ return 0 ;
2825
+
2826
+ /* It's the same VLAN, but some of the flags changed
2827
+ * and the user did not bother to delete it first.
2828
+ * Update it and trigger sja1105_build_vlan_table.
2829
+ */
2830
+ v -> untagged = untagged ;
2831
+ v -> pvid = pvid ;
2832
+ return 1 ;
2833
+ }
2834
+ }
2825
2835
2826
2836
v = kzalloc (sizeof (* v ), GFP_KERNEL );
2827
2837
if (!v ) {
@@ -2976,13 +2986,13 @@ static int sja1105_setup(struct dsa_switch *ds)
2976
2986
rc = sja1105_static_config_load (priv , ports );
2977
2987
if (rc < 0 ) {
2978
2988
dev_err (ds -> dev , "Failed to load static config: %d\n" , rc );
2979
- return rc ;
2989
+ goto out_ptp_clock_unregister ;
2980
2990
}
2981
2991
/* Configure the CGU (PHY link modes and speeds) */
2982
2992
rc = sja1105_clocking_setup (priv );
2983
2993
if (rc < 0 ) {
2984
2994
dev_err (ds -> dev , "Failed to configure MII clocking: %d\n" , rc );
2985
- return rc ;
2995
+ goto out_static_config_free ;
2986
2996
}
2987
2997
/* On SJA1105, VLAN filtering per se is always enabled in hardware.
2988
2998
* The only thing we can do to disable it is lie about what the 802.1Q
@@ -3003,7 +3013,7 @@ static int sja1105_setup(struct dsa_switch *ds)
3003
3013
3004
3014
rc = sja1105_devlink_setup (ds );
3005
3015
if (rc < 0 )
3006
- return rc ;
3016
+ goto out_static_config_free ;
3007
3017
3008
3018
/* The DSA/switchdev model brings up switch ports in standalone mode by
3009
3019
* default, and that means vlan_filtering is 0 since they're not under
@@ -3012,6 +3022,17 @@ static int sja1105_setup(struct dsa_switch *ds)
3012
3022
rtnl_lock ();
3013
3023
rc = sja1105_setup_8021q_tagging (ds , true);
3014
3024
rtnl_unlock ();
3025
+ if (rc )
3026
+ goto out_devlink_teardown ;
3027
+
3028
+ return 0 ;
3029
+
3030
+ out_devlink_teardown :
3031
+ sja1105_devlink_teardown (ds );
3032
+ out_ptp_clock_unregister :
3033
+ sja1105_ptp_clock_unregister (ds );
3034
+ out_static_config_free :
3035
+ sja1105_static_config_free (& priv -> static_config );
3015
3036
3016
3037
return rc ;
3017
3038
}
@@ -3646,8 +3667,10 @@ static int sja1105_probe(struct spi_device *spi)
3646
3667
priv -> cbs = devm_kcalloc (dev , priv -> info -> num_cbs_shapers ,
3647
3668
sizeof (struct sja1105_cbs_entry ),
3648
3669
GFP_KERNEL );
3649
- if (!priv -> cbs )
3650
- return - ENOMEM ;
3670
+ if (!priv -> cbs ) {
3671
+ rc = - ENOMEM ;
3672
+ goto out_unregister_switch ;
3673
+ }
3651
3674
}
3652
3675
3653
3676
/* Connections between dsa_port and sja1105_port */
@@ -3672,7 +3695,7 @@ static int sja1105_probe(struct spi_device *spi)
3672
3695
dev_err (ds -> dev ,
3673
3696
"failed to create deferred xmit thread: %d\n" ,
3674
3697
rc );
3675
- goto out ;
3698
+ goto out_destroy_workers ;
3676
3699
}
3677
3700
skb_queue_head_init (& sp -> xmit_queue );
3678
3701
sp -> xmit_tpid = ETH_P_SJA1105 ;
@@ -3682,7 +3705,8 @@ static int sja1105_probe(struct spi_device *spi)
3682
3705
}
3683
3706
3684
3707
return 0 ;
3685
- out :
3708
+
3709
+ out_destroy_workers :
3686
3710
while (port -- > 0 ) {
3687
3711
struct sja1105_port * sp = & priv -> ports [port ];
3688
3712
@@ -3691,6 +3715,10 @@ static int sja1105_probe(struct spi_device *spi)
3691
3715
3692
3716
kthread_destroy_worker (sp -> xmit_worker );
3693
3717
}
3718
+
3719
+ out_unregister_switch :
3720
+ dsa_unregister_switch (ds );
3721
+
3694
3722
return rc ;
3695
3723
}
3696
3724
0 commit comments