mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 19:29:37 +00:00
![Vladimir Oltean](/assets/img/avatar_default.png)
For TX timestamping, we use the felix_txtstamp method which is common with the regular (non-8021q) ocelot tagger. This method says that skb deferral is needed, prepares a timestamp request ID, and puts a clone of the skb in a queue waiting for the timestamp IRQ. felix_txtstamp is called by dsa_skb_tx_timestamp() just before the tagger's xmit method. In the tagger xmit, we divert the packets classified by dsa_skb_tx_timestamp() as PTP towards the MMIO-based injection registers, and we declare them as dead towards dsa_slave_xmit. If not PTP, we proceed with normal tag_8021q stuff. Then the timestamp IRQ fires, the clone queued up from felix_txtstamp is matched to the TX timestamp retrieved from the switch's FIFO based on the timestamp request ID, and the clone is delivered to the stack. On RX, thanks to the VCAP IS2 rule that redirects the frames with an EtherType for 1588 towards two destinations: - the CPU port module (for MMIO based extraction) and - if the "no XTR IRQ" workaround is in place, the dsa_8021q CPU port the relevant data path processing starts in the ptp_classify_raw BPF classifier installed by DSA in the RX data path (post tagger, which is completely unaware that it saw a PTP packet). This time we can't reuse the same implementation of .port_rxtstamp that also works with the default ocelot tagger. That is because felix_rxtstamp is given an skb with a freshly stripped DSA header, and it says "I don't need deferral for its RX timestamp, it's right in it, let me show you"; and it just points to the header right behind skb->data, from where it unpacks the timestamp and annotates the skb with it. The same thing cannot happen with tag_ocelot_8021q, because for one thing, the skb did not have an extraction frame header in the first place, but a VLAN tag with no timestamp information. So the code paths in felix_rxtstamp for the regular and 8021q tagger are completely independent. With tag_8021q, the timestamp must come from the packet's duplicate delivered to the CPU port module, but there is potentially complex logic to be handled [ and prone to reordering ] if we were to just start reading packets from the CPU port module, and try to match them to the one we received over Ethernet and which needs an RX timestamp. So we do something simple: we tell DSA "give me some time to think" (we request skb deferral by returning false from .port_rxtstamp) and we just drop the frame we got over Ethernet with no attempt to match it to anything - we just treat it as a notification that there's data to be processed from the CPU port module's queues. Then we proceed to read the packets from those, one by one, which we deliver up the stack, timestamped, using netif_rx - the same function that any driver would use anyway if it needed RX timestamp deferral. So the assumption is that we'll come across the PTP packet that triggered the CPU extraction notification eventually, but we don't know when exactly. Thanks to the VCAP IS2 trap/redirect rule and the exclusion of the CPU port module from the flooding replicators, only PTP frames should be present in the CPU port module's RX queues anyway. There is just one conflict between the VCAP IS2 trapping rule and the semantics of the BPF classifier. Namely, ptp_classify_raw() deems general messages as non-timestampable, but still, those are trapped to the CPU port module since they have an EtherType of ETH_P_1588. So, if the "no XTR IRQ" workaround is in place, we need to run another BPF classifier on the frames extracted over MMIO, to avoid duplicates being sent to the stack (once over Ethernet, once over MMIO). It doesn't look like it's possible to install VCAP IS2 rules based on keys extracted from the 1588 frame headers. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
102 lines
2.8 KiB
C
102 lines
2.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright 2020-2021 NXP Semiconductors
|
|
*
|
|
* An implementation of the software-defined tag_8021q.c tagger format, which
|
|
* also preserves full functionality under a vlan_filtering bridge. It does
|
|
* this by using the TCAM engines for:
|
|
* - pushing the RX VLAN as a second, outer tag, on egress towards the CPU port
|
|
* - redirecting towards the correct front port based on TX VLAN and popping
|
|
* that on egress
|
|
*/
|
|
#include <linux/dsa/8021q.h>
|
|
#include <soc/mscc/ocelot.h>
|
|
#include <soc/mscc/ocelot_ptp.h>
|
|
#include "dsa_priv.h"
|
|
|
|
static struct sk_buff *ocelot_xmit_ptp(struct dsa_port *dp,
|
|
struct sk_buff *skb,
|
|
struct sk_buff *clone)
|
|
{
|
|
struct ocelot *ocelot = dp->ds->priv;
|
|
struct ocelot_port *ocelot_port;
|
|
int port = dp->index;
|
|
u32 rew_op;
|
|
|
|
if (!ocelot_can_inject(ocelot, 0))
|
|
return NULL;
|
|
|
|
ocelot_port = ocelot->ports[port];
|
|
rew_op = ocelot_port->ptp_cmd;
|
|
|
|
/* Retrieve timestamp ID populated inside skb->cb[0] of the
|
|
* clone by ocelot_port_add_txtstamp_skb
|
|
*/
|
|
if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP)
|
|
rew_op |= clone->cb[0] << 3;
|
|
|
|
ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static struct sk_buff *ocelot_xmit(struct sk_buff *skb,
|
|
struct net_device *netdev)
|
|
{
|
|
struct dsa_port *dp = dsa_slave_to_port(netdev);
|
|
u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index);
|
|
u16 queue_mapping = skb_get_queue_mapping(skb);
|
|
u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
|
|
struct sk_buff *clone = DSA_SKB_CB(skb)->clone;
|
|
|
|
/* TX timestamping was requested, so inject through MMIO */
|
|
if (clone)
|
|
return ocelot_xmit_ptp(dp, skb, clone);
|
|
|
|
return dsa_8021q_xmit(skb, netdev, ETH_P_8021Q,
|
|
((pcp << VLAN_PRIO_SHIFT) | tx_vid));
|
|
}
|
|
|
|
static struct sk_buff *ocelot_rcv(struct sk_buff *skb,
|
|
struct net_device *netdev,
|
|
struct packet_type *pt)
|
|
{
|
|
int src_port, switch_id, qos_class;
|
|
u16 vid, tci;
|
|
|
|
skb_push_rcsum(skb, ETH_HLEN);
|
|
if (skb_vlan_tag_present(skb)) {
|
|
tci = skb_vlan_tag_get(skb);
|
|
__vlan_hwaccel_clear_tag(skb);
|
|
} else {
|
|
__skb_vlan_pop(skb, &tci);
|
|
}
|
|
skb_pull_rcsum(skb, ETH_HLEN);
|
|
|
|
vid = tci & VLAN_VID_MASK;
|
|
src_port = dsa_8021q_rx_source_port(vid);
|
|
switch_id = dsa_8021q_rx_switch_id(vid);
|
|
qos_class = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
|
|
|
|
skb->dev = dsa_master_find_slave(netdev, switch_id, src_port);
|
|
if (!skb->dev)
|
|
return NULL;
|
|
|
|
skb->offload_fwd_mark = 1;
|
|
skb->priority = qos_class;
|
|
|
|
return skb;
|
|
}
|
|
|
|
static const struct dsa_device_ops ocelot_8021q_netdev_ops = {
|
|
.name = "ocelot-8021q",
|
|
.proto = DSA_TAG_PROTO_OCELOT_8021Q,
|
|
.xmit = ocelot_xmit,
|
|
.rcv = ocelot_rcv,
|
|
.overhead = VLAN_HLEN,
|
|
.promisc_on_master = true,
|
|
};
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_OCELOT_8021Q);
|
|
|
|
module_dsa_tag_driver(ocelot_8021q_netdev_ops);
|