net: dsa: sja1105: Reconcile the meaning of TPID and TPID2 for E/T and P/Q/R/S
authorVladimir Oltean <olteanv@gmail.com>
Fri, 27 Dec 2019 01:11:13 +0000 (03:11 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 4 Jan 2020 18:19:06 +0000 (19:19 +0100)
[ Upstream commit 54fa49ee88138756df0fcf867cb1849904710a8c ]

For first-generation switches (SJA1105E and SJA1105T):
- TPID means C-Tag (typically 0x8100)
- TPID2 means S-Tag (typically 0x88A8)

While for the second generation switches (SJA1105P, SJA1105Q, SJA1105R,
SJA1105S) it is the other way around:
- TPID means S-Tag (typically 0x88A8)
- TPID2 means C-Tag (typically 0x8100)

In other words, E/T tags untagged traffic with TPID, and P/Q/R/S with
TPID2.

So the patch mentioned below fixed VLAN filtering for P/Q/R/S, but broke
it for E/T.

We strive for a common code path for all switches in the family, so just
lie in the static config packing functions that TPID and TPID2 are at
swapped bit offsets than they actually are, for P/Q/R/S. This will make
both switches understand TPID to be ETH_P_8021Q and TPID2 to be
ETH_P_8021AD. The meaning from the original E/T was chosen over P/Q/R/S
because E/T is actually the one with public documentation available
(UM10944.pdf).

Fixes: f9a1a7646c0d ("net: dsa: sja1105: Reverse TPID and TPID2")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/dsa/sja1105/sja1105_main.c
drivers/net/dsa/sja1105/sja1105_static_config.c

index 4e5a428ab1a4c97f8a7b218cb5c5faff525cebf4..7763221286d4a12111276eecdb6571f53a5a793f 100644 (file)
@@ -1560,8 +1560,8 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 
        if (enabled) {
                /* Enable VLAN filtering. */
-               tpid  = ETH_P_8021AD;
-               tpid2 = ETH_P_8021Q;
+               tpid  = ETH_P_8021Q;
+               tpid2 = ETH_P_8021AD;
        } else {
                /* Disable VLAN filtering. */
                tpid  = ETH_P_SJA1105;
@@ -1570,9 +1570,9 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
 
        table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS];
        general_params = table->entries;
-       /* EtherType used to identify outer tagged (S-tag) VLAN traffic */
-       general_params->tpid = tpid;
        /* EtherType used to identify inner tagged (C-tag) VLAN traffic */
+       general_params->tpid = tpid;
+       /* EtherType used to identify outer tagged (S-tag) VLAN traffic */
        general_params->tpid2 = tpid2;
        /* When VLAN filtering is on, we need to at least be able to
         * decode management traffic through the "backup plan".
index 0d03e13e99092e36c93adcb946f7f0f26f717b1b..63d2311817c474a460ac26218c93dacfe0678aa7 100644 (file)
@@ -142,6 +142,9 @@ static size_t sja1105et_general_params_entry_packing(void *buf, void *entry_ptr,
        return size;
 }
 
+/* TPID and TPID2 are intentionally reversed so that semantic
+ * compatibility with E/T is kept.
+ */
 static size_t
 sja1105pqrs_general_params_entry_packing(void *buf, void *entry_ptr,
                                         enum packing_op op)
@@ -166,9 +169,9 @@ sja1105pqrs_general_params_entry_packing(void *buf, void *entry_ptr,
        sja1105_packing(buf, &entry->mirr_port,   141, 139, size, op);
        sja1105_packing(buf, &entry->vlmarker,    138, 107, size, op);
        sja1105_packing(buf, &entry->vlmask,      106,  75, size, op);
-       sja1105_packing(buf, &entry->tpid        74,  59, size, op);
+       sja1105_packing(buf, &entry->tpid2,        74,  59, size, op);
        sja1105_packing(buf, &entry->ignore2stf,   58,  58, size, op);
-       sja1105_packing(buf, &entry->tpid2,        57,  42, size, op);
+       sja1105_packing(buf, &entry->tpid        57,  42, size, op);
        sja1105_packing(buf, &entry->queue_ts,     41,  41, size, op);
        sja1105_packing(buf, &entry->egrmirrvid,   40,  29, size, op);
        sja1105_packing(buf, &entry->egrmirrpcp,   28,  26, size, op);