Commit 38b5beea authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: dsa: sja1105: prepare tagger for handling DSA tags and VLAN simultaneously

In VLAN-unaware mode, sja1105 uses VLAN tags with a custom TPID of
0xdadb. While in the yet-to-be introduced best_effort_vlan_filtering
mode, it needs to work with normal VLAN TPID values.

A complication arises when we must transmit a VLAN-tagged packet to the
switch when it's in VLAN-aware mode. We need to construct a packet with
2 VLAN tags, and the switch will use the outer header for routing and
pop it on egress. But sadly, here the 2 hardware generations don't
behave the same:

- E/T switches won't pop an ETH_P_8021AD tag on egress, it seems
  (packets will remain double-tagged).
- P/Q/R/S switches will drop a packet with 2 ETH_P_8021Q tags (it looks
  like it tries to prevent VLAN hopping).

But looks like the reverse is also true:

- E/T switches have no problem popping the outer tag from packets with
  2 ETH_P_8021Q tags.
- P/Q/R/S will have no problem popping a single tag even if that is
  ETH_P_8021AD.

So it is clear that if we want the hardware to work with dsa_8021q
tagging in VLAN-aware mode, we need to send different TPIDs depending on
revision. Keep that information in priv->info->qinq_tpid.

The per-port tagger structure will hold an xmit_tpid value that depends
not only upon the qinq_tpid, but also upon the VLAN awareness state
itself (in case we must transmit using 0xdadb).
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cfa36b1f
...@@ -87,6 +87,12 @@ struct sja1105_info { ...@@ -87,6 +87,12 @@ struct sja1105_info {
const struct sja1105_dynamic_table_ops *dyn_ops; const struct sja1105_dynamic_table_ops *dyn_ops;
const struct sja1105_table_ops *static_ops; const struct sja1105_table_ops *static_ops;
const struct sja1105_regs *regs; const struct sja1105_regs *regs;
/* Both E/T and P/Q/R/S have quirks when it comes to popping the S-Tag
* from double-tagged frames. E/T will pop it only when it's equal to
* TPID from the General Parameters Table, while P/Q/R/S will only
* pop it when it's equal to TPID2.
*/
u16 qinq_tpid;
int (*reset_cmd)(struct dsa_switch *ds); int (*reset_cmd)(struct dsa_switch *ds);
int (*setup_rgmii_delay)(const void *ctx, int port); int (*setup_rgmii_delay)(const void *ctx, int port);
/* Prototypes from include/net/dsa.h */ /* Prototypes from include/net/dsa.h */
......
...@@ -2153,6 +2153,15 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) ...@@ -2153,6 +2153,15 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)
tpid2 = ETH_P_SJA1105; tpid2 = ETH_P_SJA1105;
} }
for (port = 0; port < ds->num_ports; port++) {
struct sja1105_port *sp = &priv->ports[port];
if (enabled)
sp->xmit_tpid = priv->info->qinq_tpid;
else
sp->xmit_tpid = ETH_P_SJA1105;
}
if (!enabled) if (!enabled)
state = SJA1105_VLAN_UNAWARE; state = SJA1105_VLAN_UNAWARE;
else else
...@@ -2866,6 +2875,7 @@ static int sja1105_probe(struct spi_device *spi) ...@@ -2866,6 +2875,7 @@ static int sja1105_probe(struct spi_device *spi)
goto out; goto out;
} }
skb_queue_head_init(&sp->xmit_queue); skb_queue_head_init(&sp->xmit_queue);
sp->xmit_tpid = ETH_P_SJA1105;
} }
return 0; return 0;
......
...@@ -512,6 +512,7 @@ struct sja1105_info sja1105e_info = { ...@@ -512,6 +512,7 @@ struct sja1105_info sja1105e_info = {
.part_no = SJA1105ET_PART_NO, .part_no = SJA1105ET_PART_NO,
.static_ops = sja1105e_table_ops, .static_ops = sja1105e_table_ops,
.dyn_ops = sja1105et_dyn_ops, .dyn_ops = sja1105et_dyn_ops,
.qinq_tpid = ETH_P_8021Q,
.ptp_ts_bits = 24, .ptp_ts_bits = 24,
.ptpegr_ts_bytes = 4, .ptpegr_ts_bytes = 4,
.reset_cmd = sja1105et_reset_cmd, .reset_cmd = sja1105et_reset_cmd,
...@@ -526,6 +527,7 @@ struct sja1105_info sja1105t_info = { ...@@ -526,6 +527,7 @@ struct sja1105_info sja1105t_info = {
.part_no = SJA1105ET_PART_NO, .part_no = SJA1105ET_PART_NO,
.static_ops = sja1105t_table_ops, .static_ops = sja1105t_table_ops,
.dyn_ops = sja1105et_dyn_ops, .dyn_ops = sja1105et_dyn_ops,
.qinq_tpid = ETH_P_8021Q,
.ptp_ts_bits = 24, .ptp_ts_bits = 24,
.ptpegr_ts_bytes = 4, .ptpegr_ts_bytes = 4,
.reset_cmd = sja1105et_reset_cmd, .reset_cmd = sja1105et_reset_cmd,
...@@ -540,6 +542,7 @@ struct sja1105_info sja1105p_info = { ...@@ -540,6 +542,7 @@ struct sja1105_info sja1105p_info = {
.part_no = SJA1105P_PART_NO, .part_no = SJA1105P_PART_NO,
.static_ops = sja1105p_table_ops, .static_ops = sja1105p_table_ops,
.dyn_ops = sja1105pqrs_dyn_ops, .dyn_ops = sja1105pqrs_dyn_ops,
.qinq_tpid = ETH_P_8021AD,
.ptp_ts_bits = 32, .ptp_ts_bits = 32,
.ptpegr_ts_bytes = 8, .ptpegr_ts_bytes = 8,
.setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay, .setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay,
...@@ -555,6 +558,7 @@ struct sja1105_info sja1105q_info = { ...@@ -555,6 +558,7 @@ struct sja1105_info sja1105q_info = {
.part_no = SJA1105Q_PART_NO, .part_no = SJA1105Q_PART_NO,
.static_ops = sja1105q_table_ops, .static_ops = sja1105q_table_ops,
.dyn_ops = sja1105pqrs_dyn_ops, .dyn_ops = sja1105pqrs_dyn_ops,
.qinq_tpid = ETH_P_8021AD,
.ptp_ts_bits = 32, .ptp_ts_bits = 32,
.ptpegr_ts_bytes = 8, .ptpegr_ts_bytes = 8,
.setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay, .setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay,
...@@ -570,6 +574,7 @@ struct sja1105_info sja1105r_info = { ...@@ -570,6 +574,7 @@ struct sja1105_info sja1105r_info = {
.part_no = SJA1105R_PART_NO, .part_no = SJA1105R_PART_NO,
.static_ops = sja1105r_table_ops, .static_ops = sja1105r_table_ops,
.dyn_ops = sja1105pqrs_dyn_ops, .dyn_ops = sja1105pqrs_dyn_ops,
.qinq_tpid = ETH_P_8021AD,
.ptp_ts_bits = 32, .ptp_ts_bits = 32,
.ptpegr_ts_bytes = 8, .ptpegr_ts_bytes = 8,
.setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay, .setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay,
...@@ -586,6 +591,7 @@ struct sja1105_info sja1105s_info = { ...@@ -586,6 +591,7 @@ struct sja1105_info sja1105s_info = {
.static_ops = sja1105s_table_ops, .static_ops = sja1105s_table_ops,
.dyn_ops = sja1105pqrs_dyn_ops, .dyn_ops = sja1105pqrs_dyn_ops,
.regs = &sja1105pqrs_regs, .regs = &sja1105pqrs_regs,
.qinq_tpid = ETH_P_8021AD,
.ptp_ts_bits = 32, .ptp_ts_bits = 32,
.ptpegr_ts_bytes = 8, .ptpegr_ts_bytes = 8,
.setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay, .setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay,
......
...@@ -59,6 +59,7 @@ struct sja1105_port { ...@@ -59,6 +59,7 @@ struct sja1105_port {
struct sja1105_tagger_data *data; struct sja1105_tagger_data *data;
struct dsa_port *dp; struct dsa_port *dp;
bool hwts_tx_en; bool hwts_tx_en;
u16 xmit_tpid;
}; };
#endif /* _NET_DSA_SJA1105_H */ #endif /* _NET_DSA_SJA1105_H */
...@@ -69,12 +69,25 @@ static inline bool sja1105_is_meta_frame(const struct sk_buff *skb) ...@@ -69,12 +69,25 @@ static inline bool sja1105_is_meta_frame(const struct sk_buff *skb)
return true; return true;
} }
static bool sja1105_can_use_vlan_as_tags(const struct sk_buff *skb)
{
struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
if (hdr->h_vlan_proto == ntohs(ETH_P_SJA1105))
return true;
if (hdr->h_vlan_proto != ntohs(ETH_P_8021Q))
return false;
return vid_is_dsa_8021q(ntohs(hdr->h_vlan_TCI) & VLAN_VID_MASK);
}
/* This is the first time the tagger sees the frame on RX. /* This is the first time the tagger sees the frame on RX.
* Figure out if we can decode it. * Figure out if we can decode it.
*/ */
static bool sja1105_filter(const struct sk_buff *skb, struct net_device *dev) static bool sja1105_filter(const struct sk_buff *skb, struct net_device *dev)
{ {
if (!dsa_port_is_vlan_filtering(dev->dsa_ptr)) if (sja1105_can_use_vlan_as_tags(skb))
return true; return true;
if (sja1105_is_link_local(skb)) if (sja1105_is_link_local(skb))
return true; return true;
...@@ -96,6 +109,11 @@ static struct sk_buff *sja1105_defer_xmit(struct sja1105_port *sp, ...@@ -96,6 +109,11 @@ static struct sk_buff *sja1105_defer_xmit(struct sja1105_port *sp,
return NULL; return NULL;
} }
static u16 sja1105_xmit_tpid(struct sja1105_port *sp)
{
return sp->xmit_tpid;
}
static struct sk_buff *sja1105_xmit(struct sk_buff *skb, static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
struct net_device *netdev) struct net_device *netdev)
{ {
...@@ -111,15 +129,7 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb, ...@@ -111,15 +129,7 @@ static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
if (unlikely(sja1105_is_link_local(skb))) if (unlikely(sja1105_is_link_local(skb)))
return sja1105_defer_xmit(dp->priv, skb); return sja1105_defer_xmit(dp->priv, skb);
/* If we are under a vlan_filtering bridge, IP termination on return dsa_8021q_xmit(skb, netdev, sja1105_xmit_tpid(dp->priv),
* switch ports based on 802.1Q tags is simply too brittle to
* be passable. So just defer to the dsa_slave_notag_xmit
* implementation.
*/
if (dsa_port_is_vlan_filtering(dp))
return skb;
return dsa_8021q_xmit(skb, netdev, ETH_P_SJA1105,
((pcp << VLAN_PRIO_SHIFT) | tx_vid)); ((pcp << VLAN_PRIO_SHIFT) | tx_vid));
} }
...@@ -258,7 +268,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, ...@@ -258,7 +268,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
hdr = eth_hdr(skb); hdr = eth_hdr(skb);
tpid = ntohs(hdr->h_proto); tpid = ntohs(hdr->h_proto);
is_tagged = (tpid == ETH_P_SJA1105); is_tagged = (tpid == ETH_P_SJA1105 || tpid == ETH_P_8021Q);
is_link_local = sja1105_is_link_local(skb); is_link_local = sja1105_is_link_local(skb);
is_meta = sja1105_is_meta_frame(skb); is_meta = sja1105_is_meta_frame(skb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment