Skip to content

Commit 93c5d74

Browse files
committed
Merge branch 'sja1105-fixes'
Vladimir Oltean says: ==================== Fixes for SJA1105 DSA driver This series contains some minor fixes in the sja1105 driver: - improved error handling in the probe path - rejecting an invalid phy-mode specified in the device tree - register access fix for SJA1105P/Q/R/S for the virtual links through the dynamic reconfiguration interface - handling 2 bridge VLANs where the second is supposed to overwrite the first - making sure that the lack of a pvid results in the actual dropping of untagged traffic ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 1a6e9a9 + b38e659 commit 93c5d74

File tree

2 files changed

+70
-27
lines changed

2 files changed

+70
-27
lines changed

drivers/net/dsa/sja1105/sja1105_dynamic_config.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ enum sja1105_hostcmd {
167167
SJA1105_HOSTCMD_INVALIDATE = 4,
168168
};
169169

170+
/* Command and entry overlap */
170171
static void
171-
sja1105_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd,
172-
enum packing_op op)
172+
sja1105et_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd,
173+
enum packing_op op)
173174
{
174175
const int size = SJA1105_SIZE_DYN_CMD;
175176

@@ -179,6 +180,20 @@ sja1105_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd,
179180
sja1105_packing(buf, &cmd->index, 9, 0, size, op);
180181
}
181182

183+
/* Command and entry are separate */
184+
static void
185+
sja1105pqrs_vl_lookup_cmd_packing(void *buf, struct sja1105_dyn_cmd *cmd,
186+
enum packing_op op)
187+
{
188+
u8 *p = buf + SJA1105_SIZE_VL_LOOKUP_ENTRY;
189+
const int size = SJA1105_SIZE_DYN_CMD;
190+
191+
sja1105_packing(p, &cmd->valid, 31, 31, size, op);
192+
sja1105_packing(p, &cmd->errors, 30, 30, size, op);
193+
sja1105_packing(p, &cmd->rdwrset, 29, 29, size, op);
194+
sja1105_packing(p, &cmd->index, 9, 0, size, op);
195+
}
196+
182197
static size_t sja1105et_vl_lookup_entry_packing(void *buf, void *entry_ptr,
183198
enum packing_op op)
184199
{
@@ -641,7 +656,7 @@ static size_t sja1105pqrs_cbs_entry_packing(void *buf, void *entry_ptr,
641656
const struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = {
642657
[BLK_IDX_VL_LOOKUP] = {
643658
.entry_packing = sja1105et_vl_lookup_entry_packing,
644-
.cmd_packing = sja1105_vl_lookup_cmd_packing,
659+
.cmd_packing = sja1105et_vl_lookup_cmd_packing,
645660
.access = OP_WRITE,
646661
.max_entry_count = SJA1105_MAX_VL_LOOKUP_COUNT,
647662
.packed_size = SJA1105ET_SIZE_VL_LOOKUP_DYN_CMD,
@@ -725,7 +740,7 @@ const struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = {
725740
const struct sja1105_dynamic_table_ops sja1105pqrs_dyn_ops[BLK_IDX_MAX_DYN] = {
726741
[BLK_IDX_VL_LOOKUP] = {
727742
.entry_packing = sja1105_vl_lookup_entry_packing,
728-
.cmd_packing = sja1105_vl_lookup_cmd_packing,
743+
.cmd_packing = sja1105pqrs_vl_lookup_cmd_packing,
729744
.access = (OP_READ | OP_WRITE),
730745
.max_entry_count = SJA1105_MAX_VL_LOOKUP_COUNT,
731746
.packed_size = SJA1105PQRS_SIZE_VL_LOOKUP_DYN_CMD,

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "sja1105_tas.h"
2727

2828
#define SJA1105_UNKNOWN_MULTICAST 0x010000000000ull
29+
#define SJA1105_DEFAULT_VLAN (VLAN_N_VID - 1)
2930

3031
static const struct dsa_switch_ops sja1105_switch_ops;
3132

@@ -207,6 +208,7 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv,
207208
default:
208209
dev_err(dev, "Unsupported PHY mode %s!\n",
209210
phy_modes(ports[i].phy_mode));
211+
return -EINVAL;
210212
}
211213

212214
/* 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)
321323
return 0;
322324
}
323325

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+
*/
324333
static int sja1105_init_static_vlan(struct sja1105_private *priv)
325334
{
326335
struct sja1105_table *table;
@@ -330,17 +339,13 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
330339
.vmemb_port = 0,
331340
.vlan_bc = 0,
332341
.tag_port = 0,
333-
.vlanid = 1,
342+
.vlanid = SJA1105_DEFAULT_VLAN,
334343
};
335344
struct dsa_switch *ds = priv->ds;
336345
int port;
337346

338347
table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
339348

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-
*/
344349
if (table->entry_count) {
345350
kfree(table->entries);
346351
table->entry_count = 0;
@@ -353,9 +358,6 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
353358

354359
table->entry_count = 1;
355360

356-
/* VLAN 1: all DT-defined ports are members; no restrictions on
357-
* forwarding; always transmit as untagged.
358-
*/
359361
for (port = 0; port < ds->num_ports; port++) {
360362
struct sja1105_bridge_vlan *v;
361363

@@ -366,15 +368,12 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
366368
pvid.vlan_bc |= BIT(port);
367369
pvid.tag_port &= ~BIT(port);
368370

369-
/* Let traffic that don't need dsa_8021q (e.g. STP, PTP) be
370-
* transmitted as untagged.
371-
*/
372371
v = kzalloc(sizeof(*v), GFP_KERNEL);
373372
if (!v)
374373
return -ENOMEM;
375374

376375
v->port = port;
377-
v->vid = 1;
376+
v->vid = SJA1105_DEFAULT_VLAN;
378377
v->untagged = true;
379378
if (dsa_is_cpu_port(ds, port))
380379
v->pvid = true;
@@ -2817,11 +2816,22 @@ static int sja1105_vlan_add_one(struct dsa_switch *ds, int port, u16 vid,
28172816
bool pvid = flags & BRIDGE_VLAN_INFO_PVID;
28182817
struct sja1105_bridge_vlan *v;
28192818

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) {
28232821
/* 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+
}
28252835

28262836
v = kzalloc(sizeof(*v), GFP_KERNEL);
28272837
if (!v) {
@@ -2976,13 +2986,13 @@ static int sja1105_setup(struct dsa_switch *ds)
29762986
rc = sja1105_static_config_load(priv, ports);
29772987
if (rc < 0) {
29782988
dev_err(ds->dev, "Failed to load static config: %d\n", rc);
2979-
return rc;
2989+
goto out_ptp_clock_unregister;
29802990
}
29812991
/* Configure the CGU (PHY link modes and speeds) */
29822992
rc = sja1105_clocking_setup(priv);
29832993
if (rc < 0) {
29842994
dev_err(ds->dev, "Failed to configure MII clocking: %d\n", rc);
2985-
return rc;
2995+
goto out_static_config_free;
29862996
}
29872997
/* On SJA1105, VLAN filtering per se is always enabled in hardware.
29882998
* 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)
30033013

30043014
rc = sja1105_devlink_setup(ds);
30053015
if (rc < 0)
3006-
return rc;
3016+
goto out_static_config_free;
30073017

30083018
/* The DSA/switchdev model brings up switch ports in standalone mode by
30093019
* 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)
30123022
rtnl_lock();
30133023
rc = sja1105_setup_8021q_tagging(ds, true);
30143024
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);
30153036

30163037
return rc;
30173038
}
@@ -3646,8 +3667,10 @@ static int sja1105_probe(struct spi_device *spi)
36463667
priv->cbs = devm_kcalloc(dev, priv->info->num_cbs_shapers,
36473668
sizeof(struct sja1105_cbs_entry),
36483669
GFP_KERNEL);
3649-
if (!priv->cbs)
3650-
return -ENOMEM;
3670+
if (!priv->cbs) {
3671+
rc = -ENOMEM;
3672+
goto out_unregister_switch;
3673+
}
36513674
}
36523675

36533676
/* Connections between dsa_port and sja1105_port */
@@ -3672,7 +3695,7 @@ static int sja1105_probe(struct spi_device *spi)
36723695
dev_err(ds->dev,
36733696
"failed to create deferred xmit thread: %d\n",
36743697
rc);
3675-
goto out;
3698+
goto out_destroy_workers;
36763699
}
36773700
skb_queue_head_init(&sp->xmit_queue);
36783701
sp->xmit_tpid = ETH_P_SJA1105;
@@ -3682,7 +3705,8 @@ static int sja1105_probe(struct spi_device *spi)
36823705
}
36833706

36843707
return 0;
3685-
out:
3708+
3709+
out_destroy_workers:
36863710
while (port-- > 0) {
36873711
struct sja1105_port *sp = &priv->ports[port];
36883712

@@ -3691,6 +3715,10 @@ static int sja1105_probe(struct spi_device *spi)
36913715

36923716
kthread_destroy_worker(sp->xmit_worker);
36933717
}
3718+
3719+
out_unregister_switch:
3720+
dsa_unregister_switch(ds);
3721+
36943722
return rc;
36953723
}
36963724

0 commit comments

Comments
 (0)