PTP for DSA tag_ocelot_8021q
Subsystems (4)
Vladimir Oltean
maintainerv2 cover PTP for DSA tag_ocelot_8021q
From: Vladimir Oltean <[email protected]>
Changes in v2:
Add stub definition for ocelot_port_inject_frame when switch driver is not compiled in.
This is part two of the errata workaround begun here:
https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
Now that we have basic traffic support when we operate the Ocelot DSA switches without an NPI port, it would be nice to regain some of the features lost due to the lack of the NPI port functionality. An important one is PTP timestamping, which is intimately tied to the DSA frame header added by the NPI port: on TX, we put a "timestamp request ID" in the Injection Frame Header, while on RX, the Extraction Frame Header contains a partial 32-bit PTP timestamp. Get rid of the NPI port and replace it with a VLAN-based tagger, and you lose PTP, right?
Well, not quite, this is what this patch series is about. The NPI port is basically a regular Ethernet port configured to service the packets in and out of the switch's CPU port module (which has other non-DSA I/O mechanisms too, such as register-based MMIO and DMA). If we disable the NPI port, we can in theory still access the packets delivered to the CPU port module by doing exactly what the ocelot switchdev driver does:
extracting Ethernet packets through registers (yes, it is as icky as it sounds).
However, there's a catch. The Felix switch was integrated into NXP LS1028A with the idea in mind that it will operate as DSA, i.e. using the CPU port module connected to the NPI port, not having I/O over register-based MMIO which is painfully slow and CPU intensive. So register-based packet I/O not supposed to work - those registers aren't even documented in the hardware reference manual for Felix. However they kinda do, with the exception of the fact that an RX interrupt was really not wired to the CPU cores - so we don't know when the CPU port module receives a new packet. But we can hack even around that, by replicating every packet that goes to the CPU port module and making it also go to a plain internal Ethernet port. Then drop the Ethernet packet and read the other copy of it from the CPU port module, this time annotated with the much-wanted RX timestamp.
This is all fine and it works, but it does raise some questions about what DSA even is anymore, if we start having switches that inject some of their packets over Ethernet and some through registers, where do we draw the line. In principle I believe these concerns are founded, but at the same time, the way that the Felix driver uses register MMIO based packet I/O is fundamentally the same as any other DSA driver capable of PTP makes use of a side-channel for timestamps like a FIFO (just that this one is a lot more complicated, and comes with the entire actual packet, not just the timestamp).
Nonetheless, I tried to keep the extra pressure added by this ERR workaround upon the DSA subsystem as small as possible, so some of the patches are just a revisit of some of Andrew's complaints w.r.t. the fact that tag_ocelot already violates any driver <-> tagger boundary, and as a consequence, is not able to be used on testbeds such as dsa_loop (which it now can). So now, the tag_ocelot and tag_ocelot_8021q drivers should be dsa_loop-clean, and have the ERR workarounds as self-contained as possible, using all the designated features for PTP timestamping and nothing more.
Comments appreciated.
Vladimir Oltean (12):
net: mscc: ocelot: stop returning IRQ_NONE in ocelot_xtr_irq_handler
net: mscc: ocelot: only drain extraction queue on error
net: mscc: ocelot: better error handling in ocelot_xtr_irq_handler
net: mscc: ocelot: use DIV_ROUND_UP helper in ocelot_port_inject_frame
net: mscc: ocelot: refactor ocelot_port_inject_frame out of
ocelot_port_xmit
net: dsa: tag_ocelot: avoid accessing ds->priv in ocelot_rcv
net: mscc: ocelot: use common tag parsing code with DSA
net: dsa: tag_ocelot: single out PTP-related transmit tag processing
net: dsa: tag_ocelot: create separate tagger for Seville
net: mscc: ocelot: refactor ocelot_xtr_irq_handler into
ocelot_xtr_poll
net: dsa: felix: setup MMIO filtering rules for PTP when using
tag_8021q
net: dsa: tag_ocelot_8021q: add support for PTP timestamping
drivers/net/dsa/ocelot/felix.c | 224 +++++++++++++++++-- drivers/net/dsa/ocelot/felix.h | 14 +- drivers/net/dsa/ocelot/felix_vsc9959.c | 29 +-- drivers/net/dsa/ocelot/seville_vsc9953.c | 30 +-- drivers/net/ethernet/mscc/ocelot.c | 216 ++++++++++++++++++ drivers/net/ethernet/mscc/ocelot.h | 9 - drivers/net/ethernet/mscc/ocelot_net.c | 81 +------ drivers/net/ethernet/mscc/ocelot_vsc7514.c | 178 +-------------- include/linux/dsa/ocelot.h | 218 ++++++++++++++++++ include/net/dsa.h | 2 + include/soc/mscc/ocelot.h | 41 +++- net/dsa/tag_ocelot.c | 244 +++++++-------------- net/dsa/tag_ocelot_8021q.c | 34 +++ 13 files changed, 825 insertions(+), 495 deletions(-) create mode 100644 include/linux/dsa/ocelot.h
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 1/12 net: mscc: ocelot: stop returning IRQ_NONE in ocelot_xtr_irq_handler
From: Vladimir Oltean <[email protected]>
Since the xtr (extraction) IRQ of the ocelot switch is not shared, then if it fired, it means that some data must be present in the queues of the CPU port module. So simplify the code.
---
Changes in v2:
None.
drivers/net/ethernet/mscc/ocelot_vsc7514.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/mscc/ocelot_vsc7514.c +2 -5
@@ -604,10 +604,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg)int i =0 , grp =0 ;int err =0 ; -if (!(ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp))) -return IRQ_NONE ; - - do { +while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp)) {struct skb_shared_hwtstamps *shhwtstamps;struct ocelot_port_private *priv;struct ocelot_port *ocelot_port;
@@ -702,7 +699,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg)netif_rx (skb); dev->stats.rx_bytes += len; dev->stats.rx_packets++; - }while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp)); + }if (err)while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp))
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 2/12 net: mscc: ocelot: only drain extraction queue on error
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
It appears that the intention of this snippet of code is to not exit ocelot_xtr_irq_handler() while in the middle of extracting a frame. The problem in extracting it word by word is that future extraction attempts are really easy to get desynchronized, since the IRQ handler assumes that the first 16 bytes are the IFH, which give further information about the frame, such as frame length.
But during normal operation, "err" will not be 0, but 4, set from here:
for (i = 0; i < OCELOT_TAG_LEN / 4; i++) {
err = ocelot_rx_frame_word(ocelot, grp, true, &ifh[i]);
if (err != 4)
break;
}
if (err != 4)
break;In that case, draining the extraction queue is a no-op. So explicitly make this code execute only on negative err.
---
Changes in v2:
None.
drivers/net/ethernet/mscc/ocelot_vsc7514.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mscc/ocelot_vsc7514.c +1 -1
@@ -701,7 +701,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) dev->stats.rx_packets++; } -if (err) +if (err <0 )while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp))ocelot_read_rix (ocelot,QS_XTR_RD , grp);
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 02/12] net: mscc: ocelot: only drain extraction queue on error
Quoted 20 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
It appears that the intention of this snippet of code is to not exit
ocelot_xtr_irq_handler()while in the middle of extracting a frame. The problem in extracting it word by word is that future extraction attempts are really easy to get desynchronized, since the IRQ handler assumes that the first 16 bytes are the IFH, which give further information about the frame, such as frame length.But during normal operation, "err" will not be 0, but 4, set from here:
for (i = 0; i < OCELOT_TAG_LEN / 4; i++) { err = ocelot_rx_frame_word(ocelot, grp, true, &ifh[i]); if (err != 4) break; } if (err != 4) break;
Quoted 4 lines
In that case, draining the extraction queue is a no-op. So explicitly make this code execute only on negative err.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 3/12 net: mscc: ocelot: better error handling in ocelot_xtr_irq_handler
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The ocelot_rx_frame_word() function can return a negative error code, however this isn't being checked for consistently. Errors being ignored have not been seen in practice though.
Also, some constructs can be simplified by using "goto" instead of repeated "break" statements.
---
Changes in v2:
None.
drivers/net/ethernet/mscc/ocelot_vsc7514.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/net/ethernet/mscc/ocelot_vsc7514.c +12 -10
@@ -619,12 +619,9 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg)for (i =0 ; i <OCELOT_TAG_LEN /4 ; i++) { err =ocelot_rx_frame_word (ocelot, grp, true, &ifh[i]);if (err !=4 ) -break ; + goto out; } -if (err !=4 ) -break ; -/* At this point the IFH was read correctly, so it is safe to * presume that there is no error. The err needs to be reset * otherwise a frame could come in CPU queue between the while
@@ -645,7 +642,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg)if (unlikely (!skb)) {netdev_err (dev,"Unable to allocate sk_buff\n" ); err = -ENOMEM ; -break ; + goto out; } buf_len = info.len -ETH_FCS_LEN ; buf = (u32 *)skb_put (skb, buf_len);
@@ -653,12 +650,21 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) len =0 ;do { sz =ocelot_rx_frame_word (ocelot, grp, false, &val); +if (sz <0 ) { + err = sz; + goto out; + } *buf++ = val; len += sz; }while (len < buf_len);/* Read the FCS */ sz =ocelot_rx_frame_word (ocelot, grp, false, &val); +if (sz <0 ) { + err = sz; + goto out; + } +/* Update the statistics if part of the FCS was read before */ len -=ETH_FCS_LEN - sz;
@@ -667,11 +673,6 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) *buf = val; } -if (sz <0 ) { - err = sz; -break ; - } -if (ocelot->ptp) {ocelot_ptp_gettime64 (&ocelot->ptp_info, &ts);
@@ -701,6 +702,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) dev->stats.rx_packets++; } +out:if (err <0 )while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp))ocelot_read_rix (ocelot,QS_XTR_RD , grp);
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 03/12] net: mscc: ocelot: better error handling in ocelot_xtr_irq_handler
Quoted 10 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
The
ocelot_rx_frame_word()function can return a negative error code, however this isn't being checked for consistently. Errors being ignored have not been seen in practice though.Also, some constructs can be simplified by using "goto" instead of repeated "break" statements.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 4/12 net: mscc: ocelot: use DIV_ROUND_UP helper in ocelot_port_inject_frame
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
This looks a bit nicer than the open-coded "(x + 3) % 4" idiom.
---
Changes in v2:
None.
drivers/net/ethernet/mscc/ocelot_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mscc/ocelot_net.c +1 -1
@@ -563,7 +563,7 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)ocelot_write_rix (ocelot, (__force u32 )cpu_to_be32 (ifh[i]),QS_INJ_WR , grp); - count = (skb->len +3 ) /4 ; + count =DIV_ROUND_UP (skb->len,4 ); last = skb->len %4 ;for (i =0 ; i < count; i++)ocelot_write_rix (ocelot, ((u32 *)skb->data)[i],QS_INJ_WR , grp);
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 04/12] net: mscc: ocelot: use DIV_ROUND_UP helper in ocelot_port_inject_frame
Quoted 5 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
This looks a bit nicer than the open-coded "(x + 3) % 4" idiom.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 5/12 net: mscc: ocelot: refactor ocelot_port_inject_frame out of ocelot_port_xmit
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The felix DSA driver will inject some frames through register MMIO, same as ocelot switchdev currently does. So we need to be able to reuse the common code.
Also create some shim definitions, since the DSA tagger can be compiled without support for the switch driver.
---
Changes in v2:
Create shim definitions.
drivers/net/ethernet/mscc/ocelot.c | 80 +++++++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot_net.c | 81 +++----------------------- include/soc/mscc/ocelot.h | 22 +++++++ 3 files changed, 109 insertions(+), 74 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +80 -0
@@ -628,6 +628,86 @@ void ocelot_get_txtstamp(struct ocelot *ocelot) }EXPORT_SYMBOL (ocelot_get_txtstamp); +/* Generate the IFH for frame injection +* +* The IFH is a 128bit-value +* bit 127: bypass the analyzer processing +* bit 56-67: destination mask +* bit 28-29: pop_cnt: 3 disables all rewriting of the frame +* bit 20-27: cpu extraction queue mask +* bit 16: tag type 0: C-tag, 1: S-tag +* bit 0-11: VID +*/ +static int ocelot_gen_ifh (u32 *ifh,struct frame_info *info) +{ + ifh[0 ] =IFH_INJ_BYPASS | ((0x1ff & info->rew_op) <<21 ); + ifh[1 ] = (0xf00 & info->port) >>8 ; + ifh[2 ] = (0xff & info->port) <<24 ; + ifh[3 ] = (info->tag_type <<16 ) | info->vid; + +return 0 ; +} + +bool ocelot_can_inject (struct ocelot *ocelot,int grp) +{ +u32 val =ocelot_read (ocelot,QS_INJ_STATUS ); + +if (!(val &QS_INJ_STATUS_FIFO_RDY (BIT (grp)))) +return false; +if (val &QS_INJ_STATUS_WMARK_REACHED (BIT (grp))) +return false; + +return true; +} +EXPORT_SYMBOL (ocelot_can_inject); + +void ocelot_port_inject_frame (struct ocelot *ocelot,int port,int grp, +u32 rew_op,struct sk_buff *skb) +{ +struct frame_info info = {}; +u32 ifh[OCELOT_TAG_LEN /4 ]; +unsigned int i, count, last; + +ocelot_write_rix (ocelot,QS_INJ_CTRL_GAP_SIZE (1 ) | +QS_INJ_CTRL_SOF ,QS_INJ_CTRL , grp); + + info.port =BIT (port); + info.tag_type =IFH_TAG_TYPE_C ; + info.vid =skb_vlan_tag_get (skb); + info.rew_op = rew_op; + +ocelot_gen_ifh (ifh, &info); + +for (i =0 ; i <OCELOT_TAG_LEN /4 ; i++) +ocelot_write_rix (ocelot, (__force u32 )cpu_to_be32 (ifh[i]), +QS_INJ_WR , grp); + + count =DIV_ROUND_UP (skb->len,4 ); + last = skb->len %4 ; +for (i =0 ; i < count; i++) +ocelot_write_rix (ocelot, ((u32 *)skb->data)[i],QS_INJ_WR , grp); + +/* Add padding */ +while (i < (OCELOT_BUFFER_CELL_SZ /4 )) { +ocelot_write_rix (ocelot,0 ,QS_INJ_WR , grp); + i++; + } + +/* Indicate EOF and valid bytes in last word */ +ocelot_write_rix (ocelot,QS_INJ_CTRL_GAP_SIZE (1 ) | +QS_INJ_CTRL_VLD_BYTES (skb->len <OCELOT_BUFFER_CELL_SZ ?0 : last) | +QS_INJ_CTRL_EOF , +QS_INJ_CTRL , grp); + +/* Add dummy CRC */ +ocelot_write_rix (ocelot,0 ,QS_INJ_WR , grp); +skb_tx_timestamp (skb); + + skb->dev->stats.tx_packets++; + skb->dev->stats.tx_bytes += skb->len; +} +EXPORT_SYMBOL (ocelot_port_inject_frame); +int ocelot_fdb_add (struct ocelot *ocelot,int port,const unsigned char *addr,u16 vid) {
drivers/net/ethernet/mscc/ocelot_net.c +7 -74
105 lines not on this page · raw message
include/soc/mscc/ocelot.h +22 -0
@@ -742,6 +742,28 @@ u32 __ocelot_target_read_ix(struct ocelot *ocelot, enum ocelot_target target,void __ocelot_target_write_ix (struct ocelot *ocelot,enum ocelot_target target,u32 val,u32 reg,u32 offset); +/* Packet I/O */ +#if IS_ENABLED (CONFIG_MSCC_OCELOT_SWITCH_LIB ) + +bool ocelot_can_inject (struct ocelot *ocelot,int grp); +void ocelot_port_inject_frame (struct ocelot *ocelot,int port,int grp, +u32 rew_op,struct sk_buff *skb); + +#else + +static inline bool ocelot_can_inject (struct ocelot *ocelot,int grp) +{ +return false; +} + +static inline void ocelot_port_inject_frame (struct ocelot *ocelot,int port, +int grp,u32 rew_op, +struct sk_buff *skb) +{ +} + +#endif +/* Hardware initialization */ int ocelot_regfields_init (struct ocelot *ocelot,const struct reg_field *const regfields);
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 05/12] net: mscc: ocelot: refactor ocelot_port_inject_frame out of ocelot_port_xmit
Quoted 10 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
The felix DSA driver will inject some frames through register MMIO, same as ocelot switchdev currently does. So we need to be able to reuse the common code.
Also create some shim definitions, since the DSA tagger can be compiled without support for the switch driver.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 6/12 net: dsa: tag_ocelot: avoid accessing ds->priv in ocelot_rcv
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Taggers should be written to do something valid irrespective of the switch driver that they are attached to. This is even more true now, because since the introduction of the .change_tag_protocol method, a certain tagger is not necessarily strictly associated with a driver any longer, and I would like to be able to test all taggers with dsa_loop in the future.
In the case of ocelot, it needs to move the classified VLAN from the DSA tag into the skb if the port is VLAN-aware. We can allow it to do that by looking at the dp->vlan_filtering property, no need to invoke structures which are specific to ocelot.
---
Changes in v2:
None.
net/dsa/tag_ocelot.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/dsa/tag_ocelot.c +3 -4
@@ -177,12 +177,10 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb,struct net_device *netdev, struct packet_type *pt) { - struct dsa_port *cpu_dp = netdev->dsa_ptr; -struct dsa_switch *ds = cpu_dp->ds; -struct ocelot *ocelot = ds->priv; u64 src_port, qos_class;u64 vlan_tci, tag_type;u8 *start = skb->data; +struct dsa_port *dp;u8 *extraction;u16 vlan_tpid;
@@ -243,9 +241,10 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb,* equal to the pvid of the ingress port and should not be used for * processing. */ + dp =dsa_slave_to_port (skb->dev); vlan_tpid = tag_type ?ETH_P_8021AD :ETH_P_8021Q ; -if (ocelot->ports[src_port]->vlan_aware && +if (dsa_port_is_vlan_filtering (dp) &ð_hdr (skb)->h_proto ==htons (vlan_tpid)) {u16 dummy_vlan_tci;
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 06/12] net: dsa: tag_ocelot: avoid accessing ds->priv in ocelot_rcv
Quoted 9 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Taggers should be written to do something valid irrespective of the switch driver that they are attached to. This is even more true now, because since the introduction of the .change_tag_protocol method, a certain tagger is not necessarily strictly associated with a driver any longer, and I would like to be able to test all taggers with
dsa_loopin the future.
Quoted 6 lines
In the case of ocelot, it needs to move the classified VLAN from the DSA tag into the skb if the port is VLAN-aware. We can allow it to do that by looking at the
dp->vlan_filteringproperty, no need to invoke structures which are specific to ocelot.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 7/12 net: mscc: ocelot: use common tag parsing code with DSA
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The Injection Frame Header and Extraction Frame Header that the switch prepends to frames over the NPI port is also prepended to frames delivered over the CPU port module's queues.
Let's unify the handling of the frame headers by making the ocelot driver call some helpers exported by the DSA tagger. Among other things, this allows us to get rid of the strange cpu_to_be32 when transmitting the Injection Frame Header on ocelot, since the packing API uses network byte order natively (when "quirks" is 0).
The comments above ocelot_gen_ifh talk about setting pop_cnt to 3, and the cpu extraction queue mask to something, but the code doesn't do it, so we don't do it either.
---
Changes in v2:
Added last paragraph of commit description.
drivers/net/dsa/ocelot/felix.c | 6 +- drivers/net/dsa/ocelot/felix_vsc9959.c | 2 +- drivers/net/dsa/ocelot/seville_vsc9953.c | 2 +- drivers/net/ethernet/mscc/ocelot.c | 38 +--- drivers/net/ethernet/mscc/ocelot.h | 9 - drivers/net/ethernet/mscc/ocelot_vsc7514.c | 54 ++---- include/linux/dsa/ocelot.h | 208 +++++++++++++++++++++ include/soc/mscc/ocelot.h | 7 - net/dsa/tag_ocelot.c | 147 +-------------- 9 files changed, 246 insertions(+), 227 deletions(-) create mode 100644 include/linux/dsa/ocelot.h
drivers/net/dsa/ocelot/felix.c +3 -3
@@ -14,8 +14,8 @@#include <soc/mscc/ocelot_ptp.h> #include <soc/mscc/ocelot.h> #include <linux/dsa/8021q.h> +#include <linux/dsa/ocelot.h> #include <linux/platform_device.h> -#include <linux/packing.h> #include <linux/module.h> #include <linux/of_net.h> #include <linux/pci.h>
@@ -1171,9 +1171,9 @@ static int felix_hwtstamp_set(struct dsa_switch *ds, int port,static bool felix_rxtstamp (struct dsa_switch *ds,int port,struct sk_buff *skb,unsigned int type) { +u8 *extraction = skb->data -ETH_HLEN -OCELOT_TAG_LEN ;struct skb_shared_hwtstamps *shhwtstamps;struct ocelot *ocelot = ds->priv; -u8 *extraction = skb->data -ETH_HLEN -OCELOT_TAG_LEN ;u32 tstamp_lo, tstamp_hi;struct timespec64 ts;u64 tstamp, val;
@@ -1181,7 +1181,7 @@ static bool felix_rxtstamp(struct dsa_switch *ds, int port,ocelot_ptp_gettime64 (&ocelot->ptp_info, &ts); tstamp =ktime_set (ts.tv_sec, ts.tv_nsec); -packing (extraction, &val,116 ,85 ,OCELOT_TAG_LEN ,UNPACK ,0 ); +ocelot_xfh_get_rew_val (extraction, &val); tstamp_lo = (u32 )val; tstamp_hi = tstamp >>32 ;
drivers/net/dsa/ocelot/felix_vsc9959.c +1 -1
@@ -8,7 +8,7 @@#include <soc/mscc/ocelot_ptp.h> #include <soc/mscc/ocelot_sys.h> #include <soc/mscc/ocelot.h> -#include <linux/packing.h> +#include <linux/dsa/ocelot.h> #include <linux/pcs-lynx.h> #include <net/pkt_sched.h> #include <linux/iopoll.h>
drivers/net/dsa/ocelot/seville_vsc9953.c +1 -1
@@ -8,7 +8,7 @@#include <soc/mscc/ocelot.h> #include <linux/of_platform.h> #include <linux/pcs-lynx.h> -#include <linux/packing.h> +#include <linux/dsa/ocelot.h> #include <linux/iopoll.h> #include "felix.h"
drivers/net/ethernet/mscc/ocelot.c +8 -30
@@ -4,6 +4,7 @@* * Copyright (c) 2017 Microsemi Corporation */ +#include <linux/dsa/ocelot.h> #include <linux/if_bridge.h> #include <soc/mscc/ocelot_vcap.h> #include "ocelot.h"
@@ -628,26 +629,6 @@ void ocelot_get_txtstamp(struct ocelot *ocelot) }EXPORT_SYMBOL (ocelot_get_txtstamp); -/* Generate the IFH for frame injection -* -* The IFH is a 128bit-value -* bit 127: bypass the analyzer processing -* bit 56-67: destination mask -* bit 28-29: pop_cnt: 3 disables all rewriting of the frame -* bit 20-27: cpu extraction queue mask -* bit 16: tag type 0: C-tag, 1: S-tag -* bit 0-11: VID -*/ -static int ocelot_gen_ifh (u32 *ifh,struct frame_info *info) -{ - ifh[0 ] =IFH_INJ_BYPASS | ((0x1ff & info->rew_op) <<21 ); - ifh[1 ] = (0xf00 & info->port) >>8 ; - ifh[2 ] = (0xff & info->port) <<24 ; - ifh[3 ] = (info->tag_type <<16 ) | info->vid; - -return 0 ; -} -bool ocelot_can_inject (struct ocelot *ocelot,int grp) {u32 val =ocelot_read (ocelot,QS_INJ_STATUS );
@@ -664,23 +645,20 @@ EXPORT_SYMBOL(ocelot_can_inject);void ocelot_port_inject_frame (struct ocelot *ocelot,int port,int grp,u32 rew_op,struct sk_buff *skb) { -struct frame_info info = {}; -u32 ifh[OCELOT_TAG_LEN /4 ]; +u32 ifh[OCELOT_TAG_LEN /4 ] = {0 };unsigned int i, count, last;ocelot_write_rix (ocelot,QS_INJ_CTRL_GAP_SIZE (1 ) |QS_INJ_CTRL_SOF ,QS_INJ_CTRL , grp); - info.port =BIT (port); - info.tag_type =IFH_TAG_TYPE_C ; - info.vid =skb_vlan_tag_get (skb); - info.rew_op = rew_op; - -ocelot_gen_ifh (ifh, &info); +ocelot_ifh_set_bypass (ifh,1 ); +ocelot_ifh_set_dest (ifh,BIT (port)); +ocelot_ifh_set_tag_type (ifh,IFH_TAG_TYPE_C ); +ocelot_ifh_set_vid (ifh,skb_vlan_tag_get (skb)); +ocelot_ifh_set_rew_op (ifh, rew_op);for (i =0 ; i <OCELOT_TAG_LEN /4 ; i++) -ocelot_write_rix (ocelot, (__force u32 )cpu_to_be32 (ifh[i]), -QS_INJ_WR , grp); +ocelot_write_rix (ocelot, ifh[i],QS_INJ_WR , grp); count =DIV_ROUND_UP (skb->len,4 ); last = skb->len %4 ;
drivers/net/ethernet/mscc/ocelot.h +0 -9
@@ -32,15 +32,6 @@#define OCELOT_PTP_QUEUE_SZ 128 -struct frame_info { -u32 len; -u16 port; -u16 vid; -u8 tag_type; -u16 rew_op; -u32 timestamp;/* rew_val */ -}; -struct ocelot_port_tc {bool block_shared;unsigned long offload_cnt;
drivers/net/ethernet/mscc/ocelot_vsc7514.c +16 -38
119 lines not on this page · raw message
include/linux/dsa/ocelot.h new file +208 -0
208 lines not on this page · raw message
include/soc/mscc/ocelot.h +0 -7
@@ -87,9 +87,6 @@/* Source PGIDs, one per physical port */ #define PGID_SRC 80 -#define IFH_INJ_BYPASS BIT(31) -#define IFH_INJ_POP_CNT_DISABLE (3 << 28) -#define IFH_TAG_TYPE_C 0#define IFH_TAG_TYPE_S 1
@@ -100,10 +97,6 @@#define IFH_REW_OP_ORIGIN_PTP 0x5#define OCELOT_NUM_TC 8 -#define OCELOT_TAG_LEN 16 -#define OCELOT_SHORT_PREFIX_LEN 4 -#define OCELOT_LONG_PREFIX_LEN 16 -#define OCELOT_TOTAL_TAG_LEN (OCELOT_SHORT_PREFIX_LEN + OCELOT_TAG_LEN)#define OCELOT_SPEED_2500 0#define OCELOT_SPEED_1000 1
net/dsa/tag_ocelot.c +9 -138
183 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 07/12] net: mscc: ocelot: use common tag parsing code with DSA
Quoted 12 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
The Injection Frame Header and Extraction Frame Header that the switch prepends to frames over the NPI port is also prepended to frames delivered over the CPU port module's queues.
Let's unify the handling of the frame headers by making the ocelot driver call some helpers exported by the DSA tagger. Among other things, this allows us to get rid of the strange
cpu_to_be32when transmitting the Injection Frame Header on ocelot, since the packing API uses network byte order natively (when "quirks" is 0).
Quoted 5 lines
The comments above
ocelot_gen_ifhtalk about settingpop_cntto 3, and the cpu extraction queue mask to something, but the code doesn't do it, so we don't do it either.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 8/12 net: dsa: tag_ocelot: single out PTP-related transmit tag processing
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
There is one place where we cannot avoid accessing driver data, and that is 2-step PTP TX timestamping, since the switch wants us to provide a timestamp request ID through the injection header, which naturally must come from a sequence number kept by the driver (it is generated by the .port_txtstamp method prior to the tagger's xmit).
However, since other drivers like dsa_loop do not claim PTP support anyway, the DSA_SKB_CB(skb)->clone will always be NULL anyway, so if we move all PTP-related dereferences of struct ocelot and struct ocelot_port into a separate function, we can effectively ensure that this is dead code when the ocelot tagger is attached to non-ocelot switches, and the stateful portion of the tagger is more self-contained.
---
Changes in v2:
None.
net/dsa/tag_ocelot.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
net/dsa/tag_ocelot.c +21 -11
@@ -5,6 +5,25 @@#include <soc/mscc/ocelot.h> #include "dsa_priv.h" +static void ocelot_xmit_ptp (struct dsa_port *dp,void *injection, +struct sk_buff *clone) +{ +struct ocelot *ocelot = dp->ds->priv; +struct ocelot_port *ocelot_port; +u64 rew_op; + + ocelot_port = ocelot->ports[dp->index]; + 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_ifh_set_rew_op (injection, rew_op); +} +static struct sk_buff *ocelot_xmit (struct sk_buff *skb,struct net_device *netdev) {
@@ -29,17 +48,8 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb,ocelot_ifh_set_qos_class (injection, skb->priority);/* TX timestamping was requested */ -if (clone) { -u64 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_ifh_set_rew_op (injection, rew_op); - } +if (clone) +ocelot_xmit_ptp (dp, injection, clone);return skb; }
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 08/12] net: dsa: tag_ocelot: single out PTP-related transmit tag processing
Quoted 8 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
There is one place where we cannot avoid accessing driver data, and that is 2-step PTP TX timestamping, since the switch wants us to provide a timestamp request ID through the injection header, which naturally must come from a sequence number kept by the driver (it is generated by the .port_txtstamp method prior to the tagger's xmit).
Quoted 8 lines
However, since other drivers like
dsa_loopdo not claim PTP support anyway, the DSA_SKB_CB(skb)->clone will always be NULL anyway, so if we move all PTP-related dereferences of struct ocelot and structocelot_portinto a separate function, we can effectively ensure that this is dead code when the ocelot tagger is attached to non-ocelot switches, and the stateful portion of the tagger is more self-contained.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 9/12 net: dsa: tag_ocelot: create separate tagger for Seville
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The ocelot tagger is a hot mess currently, it relies on memory initialized by the attached driver for basic frame transmission. This is against all that DSA tagging protocols stand for, which is that the transmission and reception of a DSA-tagged frame, the data path, should be independent from the switch control path, because the tag protocol is in principle hot-pluggable and reusable across switches (even if in practice it wasn't until very recently). But if another driver like dsa_loop wants to make use of tag_ocelot, it couldn't.
This was done to have common code between Felix and Ocelot, which have one bit difference in the frame header format. Quoting from commit 67c2404922c2 ("net: dsa: felix: create a template for the DSA tags on xmit"):
Other alternatives have been analyzed, such as:
- Create a separate tag_seville.c: too much code duplication for just 1 bit field difference.
- Create a separate DSA_TAG_PROTO_SEVILLE under tag_ocelot.c, just like tag_brcm.c, which would have a separate .xmit function. Again, too much code duplication for just 1 bit field difference.
- Allocate the template from the init function of the tag_ocelot.c module, instead of from the driver: couldn't figure out a method of accessing the correct port template corresponding to the correct tagger in the .xmit function.
The really interesting part is that Seville should have had its own tagging protocol defined - it is not compatible on the wire with Ocelot, even for that single bit. In principle, a packet generated by DSA_TAG_PROTO_OCELOT when booted on NXP LS1028A would look in a certain way, but when booted on NXP T1040 it would look differently. The reverse is also true: a packet generated by a Seville switch would be interpreted incorrectly by Wireshark if it was told it was generated by an Ocelot switch.
Actually things are a bit more nuanced. If we concentrate only on the DSA tag, what I said above is true, but Ocelot/Seville also support an optional DSA tag prefix, which can be short or long, and it is possible to distinguish the two taggers based on an integer constant put in that prefix. Nonetheless, creating a separate tagger is still justified, since the tag prefix is optional, and without it, there is again no way to distinguish.
Claiming backwards binary compatibility is a bit more tough, since I've already changed the format of tag_ocelot once, in commit 5124197ce58b ("net: dsa: tag_ocelot: use a short prefix on both ingress and egress"). Therefore I am not very concerned with treating this as a bugfix and backporting it to stable kernels (which would be another mess due to the fact that there would be lots of conflicts with the other DSA_TAG_PROTO* definitions). It's just simpler to say that the string values of the taggers have ABI value starting with kernel 5.12, which will be when the changing of tag protocol via /sys/class/net/<dsa-master>/dsa/tagging goes live.
---
Changes in v2:
None.
drivers/net/dsa/ocelot/felix.c | 18 ++----- drivers/net/dsa/ocelot/felix.h | 1 - drivers/net/dsa/ocelot/felix_vsc9959.c | 26 --------- drivers/net/dsa/ocelot/seville_vsc9953.c | 28 +--------- include/linux/dsa/ocelot.h | 10 ++++ include/net/dsa.h | 2 + net/dsa/tag_ocelot.c | 68 ++++++++++++++++++------ 7 files changed, 70 insertions(+), 83 deletions(-)
drivers/net/dsa/ocelot/felix.c +4 -14
@@ -431,6 +431,7 @@ static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu,int err;switch (proto) { +case DSA_TAG_PROTO_SEVILLE :case DSA_TAG_PROTO_OCELOT : err =felix_setup_tag_npi (ds, cpu);break ;
@@ -448,6 +449,7 @@ static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu, enum dsa_tag_protocol proto) {switch (proto) { +case DSA_TAG_PROTO_SEVILLE :case DSA_TAG_PROTO_OCELOT :felix_teardown_tag_npi (ds, cpu);break ;
@@ -471,7 +473,8 @@ static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu,enum dsa_tag_protocol old_proto = felix->tag_proto;int err; -if (proto !=DSA_TAG_PROTO_OCELOT && +if (proto !=DSA_TAG_PROTO_SEVILLE && + proto !=DSA_TAG_PROTO_OCELOT && proto !=DSA_TAG_PROTO_OCELOT_8021Q )return -EPROTONOSUPPORT ;
@@ -1003,7 +1006,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)for (port =0 ; port < num_phys_ports; port++) {struct ocelot_port *ocelot_port;struct regmap *target; -u8 *template; ocelot_port = devm_kzalloc(ocelot->dev, sizeof(struct ocelot_port),
@@ -1029,22 +1031,10 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)return PTR_ERR (target); } - template =devm_kzalloc (ocelot->dev,OCELOT_TOTAL_TAG_LEN , -GFP_KERNEL ); -if (!template) { -dev_err (ocelot->dev, -"Failed to allocate memory for DSA tag\n" ); -kfree (port_phy_modes); -return -ENOMEM ; - } - ocelot_port->phy_mode = port_phy_modes[port]; ocelot_port->ocelot = ocelot; ocelot_port->target = target; - ocelot_port->xmit_template = template; ocelot->ports[port] = ocelot_port; - - felix->info->xmit_template_populate (ocelot, port); }kfree (port_phy_modes);
drivers/net/dsa/ocelot/felix.h +0 -1
@@ -34,7 +34,6 @@ struct felix_info { enum tc_setup_type type, void *type_data);void (*port_sched_speed_set)(struct ocelot *ocelot,int port,u32 speed); -void (*xmit_template_populate)(struct ocelot *ocelot,int port); };extern const struct dsa_switch_ops felix_switch_ops;
drivers/net/dsa/ocelot/felix_vsc9959.c +0 -26
@@ -1339,31 +1339,6 @@ static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port, } } -static void vsc9959_xmit_template_populate (struct ocelot *ocelot,int port) -{ -struct ocelot_port *ocelot_port = ocelot->ports[port]; -u8 *template = ocelot_port->xmit_template; -u64 bypass, dest, src; -__be32 *prefix; -u8 *injection; - -/* Set the source port as the CPU port module and not the -* NPI port -*/ - src = ocelot->num_phys_ports; - dest =BIT (port); - bypass = true; - - injection = template +OCELOT_SHORT_PREFIX_LEN ; - prefix = (__be32 *)template; - -packing (injection, &bypass,127 ,127 ,OCELOT_TAG_LEN ,PACK ,0 ); -packing (injection, &dest,68 ,56 ,OCELOT_TAG_LEN ,PACK ,0 ); -packing (injection, &src,46 ,43 ,OCELOT_TAG_LEN ,PACK ,0 ); - - *prefix =cpu_to_be32 (0x8880000a ); -} -static const struct felix_info felix_info_vsc9959 = { .target_io_res = vsc9959_target_io_res, .port_io_res = vsc9959_port_io_res,
@@ -1386,7 +1361,6 @@ static const struct felix_info felix_info_vsc9959 = { .prevalidate_phy_mode = vsc9959_prevalidate_phy_mode, .port_setup_tc = vsc9959_port_setup_tc, .port_sched_speed_set = vsc9959_sched_speed_set, - .xmit_template_populate = vsc9959_xmit_template_populate, };static irqreturn_t felix_irq_handler (int irq,void *data)
drivers/net/dsa/ocelot/seville_vsc9953.c +1 -27
@@ -1165,31 +1165,6 @@ static void vsc9953_mdio_bus_free(struct ocelot *ocelot)mdiobus_unregister (felix->imdio); } -static void vsc9953_xmit_template_populate (struct ocelot *ocelot,int port) -{ -struct ocelot_port *ocelot_port = ocelot->ports[port]; -u8 *template = ocelot_port->xmit_template; -u64 bypass, dest, src; -__be32 *prefix; -u8 *injection; - -/* Set the source port as the CPU port module and not the -* NPI port -*/ - src = ocelot->num_phys_ports; - dest =BIT (port); - bypass = true; - - injection = template +OCELOT_SHORT_PREFIX_LEN ; - prefix = (__be32 *)template; - -packing (injection, &bypass,127 ,127 ,OCELOT_TAG_LEN ,PACK ,0 ); -packing (injection, &dest,67 ,57 ,OCELOT_TAG_LEN ,PACK ,0 ); -packing (injection, &src,46 ,43 ,OCELOT_TAG_LEN ,PACK ,0 ); - - *prefix =cpu_to_be32 (0x88800005 ); -} -static const struct felix_info seville_info_vsc9953 = { .target_io_res = vsc9953_target_io_res, .port_io_res = vsc9953_port_io_res,
@@ -1206,7 +1181,6 @@ static const struct felix_info seville_info_vsc9953 = { .mdio_bus_free = vsc9953_mdio_bus_free, .phylink_validate = vsc9953_phylink_validate, .prevalidate_phy_mode = vsc9953_prevalidate_phy_mode, - .xmit_template_populate = vsc9953_xmit_template_populate, };static int seville_probe (struct platform_device *pdev)
@@ -1246,7 +1220,7 @@ static int seville_probe(struct platform_device *pdev) ds->ops = &felix_switch_ops; ds->priv = ocelot; felix->ds = ds; - felix->tag_proto =DSA_TAG_PROTO_OCELOT ; + felix->tag_proto =DSA_TAG_PROTO_SEVILLE ; err =dsa_register_switch (ds);if (err) {
include/linux/dsa/ocelot.h +10 -0
@@ -195,6 +195,16 @@ static inline void ocelot_ifh_set_qos_class(void *injection, u64 qos_class)packing (injection, &qos_class,19 ,17 ,OCELOT_TAG_LEN ,PACK ,0 ); } +static inline void seville_ifh_set_dest (void *injection,u64 dest) +{ +packing (injection, &dest,67 ,57 ,OCELOT_TAG_LEN ,PACK ,0 ); +} + +static inline void ocelot_ifh_set_src (void *injection,u64 src) +{ +packing (injection, &src,46 ,43 ,OCELOT_TAG_LEN ,PACK ,0 ); +} +static inline void ocelot_ifh_set_tag_type (void *injection,u64 tag_type) {packing (injection, &tag_type,16 ,16 ,OCELOT_TAG_LEN ,PACK ,0 );
include/net/dsa.h +2 -0
@@ -48,6 +48,7 @@ struct phylink_link_state;#define DSA_TAG_PROTO_HELLCREEK_VALUE 18#define DSA_TAG_PROTO_XRS700X_VALUE 19#define DSA_TAG_PROTO_OCELOT_8021Q_VALUE 20 +#define DSA_TAG_PROTO_SEVILLE_VALUE 21enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -71,6 +72,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_HELLCREEK =DSA_TAG_PROTO_HELLCREEK_VALUE ,DSA_TAG_PROTO_XRS700X =DSA_TAG_PROTO_XRS700X_VALUE ,DSA_TAG_PROTO_OCELOT_8021Q =DSA_TAG_PROTO_OCELOT_8021Q_VALUE , + DSA_TAG_PROTO_SEVILLE = DSA_TAG_PROTO_SEVILLE_VALUE, };struct packet_type ;
net/dsa/tag_ocelot.c +53 -15
93 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 09/12] net: dsa: tag_ocelot: create separate tagger for Seville
Quoted 55 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
The ocelot tagger is a hot mess currently, it relies on memory initialized by the attached driver for basic frame transmission. This is against all that DSA tagging protocols stand for, which is that the transmission and reception of a DSA-tagged frame, the data path, should be independent from the switch control path, because the tag protocol is in principle hot-pluggable and reusable across switches (even if in practice it wasn't until very recently). But if another driver like
dsa_loopwants to make use oftag_ocelot, it couldn't.This was done to have common code between Felix and Ocelot, which have one bit difference in the frame header format. Quoting from commit
67c2404922c2("net: dsa: felix: create a template for the DSA tags on xmit"):Other alternatives have been analyzed, such as:
- Create a separatetag_seville.c: too much code duplication for just 1 bit field difference.
- Create a separateDSA_TAG_PROTO_SEVILLEundertag_ocelot.c, just liketag_brcm.c, which would have a separate .xmit function. Again, too much code duplication for just 1 bit field difference.
- Allocate the template from the init function of thetag_ocelot.cmodule, instead of from the driver: couldn't figure out a method of accessing the correct port template corresponding to the correct tagger in the .xmit function.The really interesting part is that Seville should have had its own tagging protocol defined - it is not compatible on the wire with Ocelot, even for that single bit. In principle, a packet generated by
DSA_TAG_PROTO_OCELOTwhen booted on NXP LS1028A would look in a certain way, but when booted on NXP T1040 it would look differently. The reverse is also true: a packet generated by a Seville switch would be interpreted incorrectly by Wireshark if it was told it was generated by an Ocelot switch.Actually things are a bit more nuanced. If we concentrate only on the DSA tag, what I said above is true, but Ocelot/Seville also support an optional DSA tag prefix, which can be short or long, and it is possible to distinguish the two taggers based on an integer constant put in that prefix. Nonetheless, creating a separate tagger is still justified, since the tag prefix is optional, and without it, there is again no way to distinguish.
Claiming backwards binary compatibility is a bit more tough, since I've already changed the format of
tag_ocelotonce, in commit5124197ce58b("net: dsa:tag_ocelot: use a short prefix on both ingress and egress"). Therefore I am not very concerned with treating this as a bugfix and backporting it to stable kernels (which would be another mess due to the fact that there would be lots of conflicts with the other DSA_TAG_PROTO* definitions). It's just simpler to say that the string values of the taggers have ABI value starting with kernel 5.12, which will be when the changing of tag protocol via /sys/class/net/<dsa-master>/dsa/tagging goes live.
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 10/12 net: mscc: ocelot: refactor ocelot_xtr_irq_handler into ocelot_xtr_poll
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Since the felix DSA driver will need to poll the CPU port module for extracted frames as well, let's create some common functions that read an Extraction Frame Header, and then an skb, from a CPU extraction group.
We abuse the struct ocelot_ops :: port_to_netdev function a little bit, in order to retrieve the DSA port net_device or the ocelot switchdev net_device based on the source port information from the Extraction Frame Header, but it's all in the benefit of code simplification - netdev_alloc_skb needs it. Originally, the port_to_netdev method was intended for parsing act->dev from tc flower offload code.
---
Changes in v2:
Added shim definitions.
drivers/net/ethernet/mscc/ocelot.c | 151 +++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot_vsc7514.c | 140 +------------------ include/soc/mscc/ocelot.h | 7 + 3 files changed, 163 insertions(+), 135 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +151 -0
@@ -629,6 +629,157 @@ void ocelot_get_txtstamp(struct ocelot *ocelot) }EXPORT_SYMBOL (ocelot_get_txtstamp); +static int ocelot_rx_frame_word (struct ocelot *ocelot,u8 grp,bool ifh, +u32 *rval) +{ +u32 bytes_valid, val; + + val =ocelot_read_rix (ocelot,QS_XTR_RD , grp); +if (val ==XTR_NOT_READY ) { +if (ifh) +return -EIO ; + +do { + val =ocelot_read_rix (ocelot,QS_XTR_RD , grp); + }while (val ==XTR_NOT_READY ); + } + +switch (val) { +case XTR_ABORT : +return -EIO ; +case XTR_EOF_0 : +case XTR_EOF_1 : +case XTR_EOF_2 : +case XTR_EOF_3 : +case XTR_PRUNED : + bytes_valid =XTR_VALID_BYTES (val); + val =ocelot_read_rix (ocelot,QS_XTR_RD , grp); +if (val ==XTR_ESCAPE ) + *rval =ocelot_read_rix (ocelot,QS_XTR_RD , grp); +else + *rval = val; + +return bytes_valid; +case XTR_ESCAPE : + *rval =ocelot_read_rix (ocelot,QS_XTR_RD , grp); + +return 4 ; +default : + *rval = val; + +return 4 ; + } +} + +static int ocelot_xtr_poll_xfh (struct ocelot *ocelot,int grp,u32 *xfh) +{ +int i, err =0 ; + +for (i =0 ; i <OCELOT_TAG_LEN /4 ; i++) { + err =ocelot_rx_frame_word (ocelot, grp, true, &xfh[i]); +if (err !=4 ) +return (err <0 ) ? err : -EIO ; + } + +return 0 ; +} + +int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp,struct sk_buff **nskb) +{ +struct skb_shared_hwtstamps *shhwtstamps; +u64 tod_in_ns, full_ts_in_ns; +u64 timestamp, src_port, len; +u32 xfh[OCELOT_TAG_LEN /4 ]; +struct net_device *dev; +struct timespec64 ts; +struct sk_buff *skb; +int sz, buf_len; +u32 val, *buf; +int err; + + err =ocelot_xtr_poll_xfh (ocelot, grp, xfh); +if (err) +return err; + +ocelot_xfh_get_src_port (xfh, &src_port); +ocelot_xfh_get_len (xfh, &len); +ocelot_xfh_get_rew_val (xfh, ×tamp); + +if (WARN_ON (src_port >= ocelot->num_phys_ports)) +return -EINVAL ; + + dev = ocelot->ops->port_to_netdev (ocelot, src_port); +if (!dev) +return -EINVAL ; + + skb =netdev_alloc_skb (dev, len); +if (unlikely (!skb)) { +netdev_err (dev,"Unable to allocate sk_buff\n" ); +return -ENOMEM ; + } + + buf_len = len -ETH_FCS_LEN ; + buf = (u32 *)skb_put (skb, buf_len); + + len =0 ; +do { + sz =ocelot_rx_frame_word (ocelot, grp, false, &val); +if (sz <0 ) { + err = sz; + goto out_free_skb; + } + *buf++ = val; + len += sz; + }while (len < buf_len); + +/* Read the FCS */ + sz =ocelot_rx_frame_word (ocelot, grp, false, &val); +if (sz <0 ) { + err = sz; + goto out_free_skb; + } + +/* Update the statistics if part of the FCS was read before */ + len -=ETH_FCS_LEN - sz; + +if (unlikely (dev->features &NETIF_F_RXFCS )) { + buf = (u32 *)skb_put (skb,ETH_FCS_LEN ); + *buf = val; + } + +if (ocelot->ptp) { +ocelot_ptp_gettime64 (&ocelot->ptp_info, &ts); + + tod_in_ns =ktime_set (ts.tv_sec, ts.tv_nsec); +if ((tod_in_ns &0xffffffff ) < timestamp) + full_ts_in_ns = (((tod_in_ns >>32 ) -1 ) <<32 ) | + timestamp; +else + full_ts_in_ns = (tod_in_ns &GENMASK_ULL (63 ,32 )) | + timestamp; + + shhwtstamps =skb_hwtstamps (skb); +memset (shhwtstamps,0 ,sizeof (struct skb_shared_hwtstamps )); + shhwtstamps->hwtstamp = full_ts_in_ns; + } + +/* Everything we see on an interface that is in the HW bridge +* has already been forwarded. +*/ +if (ocelot->bridge_mask &BIT (src_port)) + skb->offload_fwd_mark =1 ; + + skb->protocol =eth_type_trans (skb, dev); + *nskb = skb; + +return 0 ; + +out_free_skb: +kfree_skb (skb); +return err; +} +EXPORT_SYMBOL (ocelot_xtr_poll_frame); +bool ocelot_can_inject (struct ocelot *ocelot,int grp) {u32 val =ocelot_read (ocelot,QS_INJ_STATUS );
drivers/net/ethernet/mscc/ocelot_vsc7514.c +5 -135
158 lines not on this page · raw message
include/soc/mscc/ocelot.h +7 -0
@@ -741,6 +741,7 @@ void __ocelot_target_write_ix(struct ocelot *ocelot, enum ocelot_target target,bool ocelot_can_inject (struct ocelot *ocelot,int grp);void ocelot_port_inject_frame (struct ocelot *ocelot,int port,int grp,u32 rew_op,struct sk_buff *skb); +int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp,struct sk_buff **skb);#else
@@ -755,6 +756,12 @@ static inline void ocelot_port_inject_frame(struct ocelot *ocelot, int port, { } +static inline int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp, +struct sk_buff **skb) +{ +return -EIO ; +} +#endif /* Hardware initialization */
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 10/12] net: mscc: ocelot: refactor ocelot_xtr_irq_handler into ocelot_xtr_poll
Quoted 7 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Since the felix DSA driver will need to poll the CPU port module for extracted frames as well, let's create some common functions that read an Extraction Frame Header, and then an skb, from a CPU extraction group.
Quoted 8 lines
We abuse the struct
ocelot_ops::port_to_netdevfunction a little bit, in order to retrieve the DSA portnet_deviceor the ocelot switchdevnet_devicebased on the source port information from the Extraction Frame Header, but it's all in the benefit of code simplification -netdev_alloc_skbneeds it. Originally, theport_to_netdevmethod was intended for parsingact->devfrom tc flower offload code.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 11/12 net: dsa: felix: setup MMIO filtering rules for PTP when using tag_8021q
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Since the tag_8021q tagger is software-defined, it has no means by itself for retrieving hardware timestamps of PTP event messages.
Because we do want to support PTP on ocelot even with tag_8021q, we need to use the CPU port module for that. The RX timestamp is present in the Extraction Frame Header. And because we can't use NPI mode which redirects the CPU queues to an "external CPU" (meaning the ARM CPU running Linux), then we need to poll the CPU port module through the MMIO registers to retrieve TX and RX timestamps.
Sadly, on NXP LS1028A, the Felix switch was integrated into the SoC without wiring the extraction IRQ line to the ARM GIC. So, if we want to be notified of any PTP packets received on the CPU port module, we have a problem.
There is a possible workaround, which is to use the Ethernet CPU port as a notification channel that packets are available on the CPU port module as well. When a PTP packet is received by the DSA tagger (without timestamp, of course), we go to the CPU extraction queues, poll for it there, then we drop the original Ethernet packet and masquerade the packet retrieved over MMIO (plus the timestamp) as the original when we inject it up the stack.
Create a quirk in struct felix is selected by the Felix driver (but not by Seville, since that doesn't support PTP at all). We want to do this such that the workaround is minimally invasive for future switches that don't require this workaround.
The only traffic for which we need timestamps is PTP traffic, so add a redirection rule to the CPU port module for this. Currently we only have the need for PTP over L2, so redirection rules for UDP ports 319 and 320 are TBD for now.
Note that for the workaround of matching of PTP-over-Ethernet-port with PTP-over-MMIO queues to work properly, both channels need to be absolutely lossless. There are two parts to achieving that:
- We keep flow control enabled on the tag_8021q CPU port
- We put the DSA master interface in promiscuous mode, so it will never drop a PTP frame (for the profiles we are interested in, these are sent to the multicast MAC addresses of 01-80-c2-00-00-0e and 01-1b-19-00-00-00).
---
Changes in v2:
None.
drivers/net/dsa/ocelot/felix.c | 131 ++++++++++++++++++++++++- drivers/net/dsa/ocelot/felix.h | 13 +++ drivers/net/dsa/ocelot/felix_vsc9959.c | 1 + net/dsa/tag_ocelot_8021q.c | 1 + 4 files changed, 143 insertions(+), 3 deletions(-)
drivers/net/dsa/ocelot/felix.c +128 -3
@@ -264,6 +264,120 @@ static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port)ocelot_apply_bridge_fwd_mask (ocelot); } +/* Set up a VCAP IS2 rule for delivering PTP frames to the CPU port module. +* If the quirk_no_xtr_irq is in place, then also copy those PTP frames to the +* tag_8021q CPU port. +*/ +static int felix_setup_mmio_filtering (struct felix *felix) +{ +unsigned long user_ports =0 , cpu_ports =0 ; +struct ocelot_vcap_filter *redirect_rule; +struct ocelot_vcap_filter *tagging_rule; +struct ocelot *ocelot = &felix->ocelot; +struct dsa_switch *ds = felix->ds; +int port, ret; + + tagging_rule =kzalloc (sizeof (struct ocelot_vcap_filter ),GFP_KERNEL ); +if (!tagging_rule) +return -ENOMEM ; + + redirect_rule =kzalloc (sizeof (struct ocelot_vcap_filter ),GFP_KERNEL ); +if (!redirect_rule) { +kfree (tagging_rule); +return -ENOMEM ; + } + +for (port =0 ; port < ocelot->num_phys_ports; port++) { +if (dsa_is_user_port (ds, port)) + user_ports |=BIT (port); +if (dsa_is_cpu_port (ds, port)) + cpu_ports |=BIT (port); + } + + tagging_rule->key_type =OCELOT_VCAP_KEY_ETYPE ; + *(__be16 *)tagging_rule->key.etype.etype.value =htons (ETH_P_1588 ); + *(__be16 *)tagging_rule->key.etype.etype.mask =htons (0xffff ); + tagging_rule->ingress_port_mask = user_ports; + tagging_rule->prio =1 ; + tagging_rule->id.cookie = ocelot->num_phys_ports; + tagging_rule->id.tc_offload = false; + tagging_rule->block_id =VCAP_IS1 ; + tagging_rule->type =OCELOT_VCAP_FILTER_OFFLOAD ; + tagging_rule->lookup =0 ; + tagging_rule->action.pag_override_mask =0xff ; + tagging_rule->action.pag_val = ocelot->num_phys_ports; + + ret =ocelot_vcap_filter_add (ocelot, tagging_rule,NULL ); +if (ret) { +kfree (tagging_rule); +kfree (redirect_rule); +return ret; + } + + redirect_rule->key_type =OCELOT_VCAP_KEY_ANY ; + redirect_rule->ingress_port_mask = user_ports; + redirect_rule->pag = ocelot->num_phys_ports; + redirect_rule->prio =1 ; + redirect_rule->id.cookie = ocelot->num_phys_ports; + redirect_rule->id.tc_offload = false; + redirect_rule->block_id =VCAP_IS2 ; + redirect_rule->type =OCELOT_VCAP_FILTER_OFFLOAD ; + redirect_rule->lookup =0 ; + redirect_rule->action.cpu_copy_ena = true; +if (felix->info->quirk_no_xtr_irq) { +/* Redirect to the tag_8021q CPU but also copy PTP packets to +* the CPU port module +*/ + redirect_rule->action.mask_mode =OCELOT_MASK_MODE_REDIRECT ; + redirect_rule->action.port_mask = cpu_ports; + }else { +/* Trap PTP packets only to the CPU port module (which is +* redirected to the NPI port) +*/ + redirect_rule->action.mask_mode =OCELOT_MASK_MODE_PERMIT_DENY ; + redirect_rule->action.port_mask =0 ; + } + + ret =ocelot_vcap_filter_add (ocelot, redirect_rule,NULL ); +if (ret) { +ocelot_vcap_filter_del (ocelot, tagging_rule); +kfree (redirect_rule); +return ret; + } + +return 0 ; +} + +static int felix_teardown_mmio_filtering (struct felix *felix) +{ +struct ocelot_vcap_filter *tagging_rule, *redirect_rule; +struct ocelot_vcap_block *block_vcap_is1; +struct ocelot_vcap_block *block_vcap_is2; +struct ocelot *ocelot = &felix->ocelot; +int err; + + block_vcap_is1 = &ocelot->block[VCAP_IS1 ]; + block_vcap_is2 = &ocelot->block[VCAP_IS2 ]; + + tagging_rule =ocelot_vcap_block_find_filter_by_id (block_vcap_is1, + ocelot->num_phys_ports, + false); +if (!tagging_rule) +return -ENOENT ; + + err =ocelot_vcap_filter_del (ocelot, tagging_rule); +if (err) +return err; + + redirect_rule =ocelot_vcap_block_find_filter_by_id (block_vcap_is2, + ocelot->num_phys_ports, + false); +if (!redirect_rule) +return -ENOENT ; + +return ocelot_vcap_filter_del (ocelot, redirect_rule); +} +static int felix_setup_tag_8021q (struct dsa_switch *ds,int cpu) {struct ocelot *ocelot = ds->priv;
@@ -292,9 +406,9 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) ANA_PORT_CPU_FWD_BPDU_CFG, port); } -/* In tag_8021q mode, the CPU port module is unused. So we -* want to disable flooding of any kind to the CPU port module, -* since packets going there will end in a black hole. +/* In tag_8021q mode, the CPU port module is unused, except for PTP +* frames. So we want to disable flooding of any kind to the CPU port +* module, since packets going there will end in a black hole. */ cpu_flood =ANA_PGID_PGID_PGID (BIT (ocelot->num_phys_ports));ocelot_rmw_rix (ocelot,0 , cpu_flood,ANA_PGID_PGID ,PGID_UC );
@@ -314,8 +428,14 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu)if (err) goto out_free_dsa_8021_ctx; + err =felix_setup_mmio_filtering (felix); +if (err) + goto out_teardown_dsa_8021q; +return 0 ; +out_teardown_dsa_8021q: +dsa_8021q_setup (felix->dsa_8021q_ctx, false); out_free_dsa_8021_ctx:kfree (felix->dsa_8021q_ctx);return err;
@@ -327,6 +447,11 @@ static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu)struct felix *felix =ocelot_to_felix (ocelot);int err, port; + err =felix_teardown_mmio_filtering (felix); +if (err) +dev_err (ds->dev,"felix_teardown_mmio_filtering returned %d" , + err); + err =dsa_8021q_setup (felix->dsa_8021q_ctx, false);if (err)dev_err (ds->dev,"dsa_8021q_setup returned %d" , err);
drivers/net/dsa/ocelot/felix.h +13 -0
@@ -23,6 +23,19 @@ struct felix_info {int switch_pci_bar;int imdio_pci_bar;const struct ptp_clock_info *ptp_caps; + +/* Some Ocelot switches are integrated into the SoC without the +* extraction IRQ line connected to the ARM GIC. By enabling this +* workaround, the few packets that are delivered to the CPU port +* module (currently only PTP) are copied not only to the hardware CPU +* port module, but also to the 802.1Q Ethernet CPU port, and polling +* the extraction registers is triggered once the DSA tagger sees a PTP +* frame. The Ethernet frame is only used as a notification: it is +* dropped, and the original frame is extracted over MMIO and annotated +* with the RX timestamp. +*/ +bool quirk_no_xtr_irq; +int (*mdio_bus_alloc)(struct ocelot *ocelot);void (*mdio_bus_free)(struct ocelot *ocelot); void (*phylink_validate)(struct ocelot *ocelot, int port,
drivers/net/dsa/ocelot/felix_vsc9959.c +1 -0
@@ -1354,6 +1354,7 @@ static const struct felix_info felix_info_vsc9959 = { .num_tx_queues = OCELOT_NUM_TC, .switch_pci_bar = 4, .imdio_pci_bar = 0, + .quirk_no_xtr_irq = true, .ptp_caps = &vsc9959_ptp_caps, .mdio_bus_alloc = vsc9959_mdio_bus_alloc, .mdio_bus_free = vsc9959_mdio_bus_free,
net/dsa/tag_ocelot_8021q.c +1 -0
@@ -60,6 +60,7 @@ static const struct dsa_device_ops ocelot_8021q_netdev_ops = { .xmit = ocelot_xmit, .rcv = ocelot_rcv, .overhead = VLAN_HLEN, + .promisc_on_master = true, };MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 11/12] net: dsa: felix: setup MMIO filtering rules for PTP when using tag_8021q
Quoted 44 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
Since the
tag_8021qtagger is software-defined, it has no means by itself for retrieving hardware timestamps of PTP event messages.Because we do want to support PTP on ocelot even with
tag_8021q, we need to use the CPU port module for that. The RX timestamp is present in the Extraction Frame Header. And because we can't use NPI mode which redirects the CPU queues to an "external CPU" (meaning the ARM CPU running Linux), then we need to poll the CPU port module through the MMIO registers to retrieve TX and RX timestamps.Sadly, on NXP LS1028A, the Felix switch was integrated into the SoC without wiring the extraction IRQ line to the ARM GIC. So, if we want to be notified of any PTP packets received on the CPU port module, we have a problem.
There is a possible workaround, which is to use the Ethernet CPU port as a notification channel that packets are available on the CPU port module as well. When a PTP packet is received by the DSA tagger (without timestamp, of course), we go to the CPU extraction queues, poll for it there, then we drop the original Ethernet packet and masquerade the packet retrieved over MMIO (plus the timestamp) as the original when we inject it up the stack.
Create a quirk in struct felix is selected by the Felix driver (but not by Seville, since that doesn't support PTP at all). We want to do this such that the workaround is minimally invasive for future switches that don't require this workaround.
The only traffic for which we need timestamps is PTP traffic, so add a redirection rule to the CPU port module for this. Currently we only have the need for PTP over L2, so redirection rules for UDP ports 319 and 320 are TBD for now.
Note that for the workaround of matching of PTP-over-Ethernet-port with PTP-over-MMIO queues to work properly, both channels need to be absolutely lossless. There are two parts to achieving that:
- We keep flow control enabled on thetag_8021qCPU port
- We put the DSA master interface in promiscuous mode, so it will never drop a PTP frame (for the profiles we are interested in, these are sent to the multicast MAC addresses of 01-80-c2-00-00-0e and 01-1b-19-00-00-00).
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v2 12/12 net: dsa: tag_ocelot_8021q: add support for PTP timestamping
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
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.
---
Changes in v2:
- added the "ocelot_can_inject" check
- expanded a bit more on the patch implementation aspects
drivers/net/dsa/ocelot/felix.c | 69 ++++++++++++++++++++++ drivers/net/ethernet/mscc/ocelot.c | 7 +++ drivers/net/ethernet/mscc/ocelot_vsc7514.c | 3 +- include/soc/mscc/ocelot.h | 5 ++ net/dsa/tag_ocelot_8021q.c | 33 +++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-)
drivers/net/dsa/ocelot/felix.c +69 -0
@@ -16,6 +16,7 @@#include <linux/dsa/8021q.h> #include <linux/dsa/ocelot.h> #include <linux/platform_device.h> +#include <linux/ptp_classify.h> #include <linux/module.h> #include <linux/of_net.h> #include <linux/pci.h>
@@ -345,6 +346,15 @@ static int felix_setup_mmio_filtering(struct felix *felix)return ret; } +/* The ownership of the CPU port module's queues might have just been +* transferred to the tag_8021q tagger from the NPI-based tagger. +* So there might still be all sorts of crap in the queues. On the +* other hand, the MMIO-based matching of PTP frames is very brittle, +* so we need to be careful that there are no extra frames to be +* dequeued over MMIO, since we would never know to discard them. +*/ +ocelot_drain_cpu_queue (ocelot,0 ); +return 0 ; }
@@ -1283,6 +1293,55 @@ static int felix_hwtstamp_set(struct dsa_switch *ds, int port,return ocelot_hwstamp_set (ocelot, port, ifr); } +static bool felix_check_xtr_pkt (struct ocelot *ocelot,unsigned int ptp_type) +{ +struct felix *felix =ocelot_to_felix (ocelot); +int err, grp =0 ; + +if (felix->tag_proto !=DSA_TAG_PROTO_OCELOT_8021Q ) +return false; + +if (!felix->info->quirk_no_xtr_irq) +return false; + +if (ptp_type ==PTP_CLASS_NONE ) +return false; + +while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp)) { +struct sk_buff *skb; +unsigned int type; + + err =ocelot_xtr_poll_frame (ocelot, grp, &skb); +if (err) + goto out; + +/* We trap to the CPU port module all PTP frames, but +* felix_rxtstamp() only gets called for event frames. +* So we need to avoid sending duplicate general +* message frames by running a second BPF classifier +* here and dropping those. +*/ +__skb_push (skb,ETH_HLEN ); + + type =ptp_classify_raw (skb); + +__skb_pull (skb,ETH_HLEN ); + +if (type ==PTP_CLASS_NONE ) { +kfree_skb (skb); +continue ; + } + +netif_rx (skb); + } + +out: +if (err <0 ) +ocelot_drain_cpu_queue (ocelot,0 ); + +return true; +} +static bool felix_rxtstamp (struct dsa_switch *ds,int port,struct sk_buff *skb,unsigned int type) {
@@ -1293,6 +1352,16 @@ static bool felix_rxtstamp(struct dsa_switch *ds, int port,struct timespec64 ts;u64 tstamp, val; +/* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb +* for RX timestamping. Then free it, and poll for its copy through +* MMIO in the CPU port module, and inject that into the stack from +* ocelot_xtr_poll(). +*/ +if (felix_check_xtr_pkt (ocelot, type)) { +kfree_skb (skb); +return true; + } +ocelot_ptp_gettime64 (&ocelot->ptp_info, &ts); tstamp =ktime_set (ts.tv_sec, ts.tv_nsec);
drivers/net/ethernet/mscc/ocelot.c +7 -0
@@ -837,6 +837,13 @@ void ocelot_port_inject_frame(struct ocelot *ocelot, int port, int grp, }EXPORT_SYMBOL (ocelot_port_inject_frame); +void ocelot_drain_cpu_queue (struct ocelot *ocelot,int grp) +{ +while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp)) +ocelot_read_rix (ocelot,QS_XTR_RD , grp); +} +EXPORT_SYMBOL (ocelot_drain_cpu_queue); +int ocelot_fdb_add (struct ocelot *ocelot,int port,const unsigned char *addr,u16 vid) {
drivers/net/ethernet/mscc/ocelot_vsc7514.c +1 -2
@@ -552,8 +552,7 @@ static irqreturn_t ocelot_xtr_irq_handler(int irq, void *arg) out:if (err <0 ) -while (ocelot_read (ocelot,QS_XTR_DATA_PRESENT ) &BIT (grp)) -ocelot_read_rix (ocelot,QS_XTR_RD , grp); +ocelot_drain_cpu_queue (ocelot,0 );return IRQ_HANDLED ; }
include/soc/mscc/ocelot.h +5 -0
@@ -742,6 +742,7 @@ bool ocelot_can_inject(struct ocelot *ocelot, int grp);void ocelot_port_inject_frame (struct ocelot *ocelot,int port,int grp,u32 rew_op,struct sk_buff *skb);int ocelot_xtr_poll_frame (struct ocelot *ocelot,int grp,struct sk_buff **skb); +void ocelot_drain_cpu_queue (struct ocelot *ocelot,int grp);#else
@@ -762,6 +763,10 @@ static inline int ocelot_xtr_poll_frame(struct ocelot *ocelot, int grp, return -EIO; } +static inline void ocelot_drain_cpu_queue (struct ocelot *ocelot,int grp) +{ +} +#endif /* Hardware initialization */
net/dsa/tag_ocelot_8021q.c +33 -0
@@ -9,8 +9,36 @@* 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) {
@@ -18,6 +46,11 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb,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));
Signature · 1 line
2.25.1
Re: [PATCH v2 net-next 12/12] net: dsa: tag_ocelot_8021q: add support for PTP timestamping
Quoted 65 lines · Vladimir Oltean
From: Vladimir Oltean <[email protected]>
For TX timestamping, we use the
felix_txtstampmethod 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_txtstampis called bydsa_skb_tx_timestamp()just before the tagger's xmit method. In the tagger xmit, we divert the packets classified bydsa_skb_tx_timestamp()as PTP towards the MMIO-based injection registers, and we declare them as dead towardsdsa_slave_xmit. If not PTP, we proceed with normaltag_8021qstuff.Then the timestamp IRQ fires, the clone queued up from
felix_txtstampis 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, thedsa_8021qCPU port the relevant data path processing starts in theptp_classify_rawBPF 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_rxtstampis 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 behindskb->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 infelix_rxtstampfor the regular and 8021q tagger are completely independent. Withtag_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, usingnetif_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 ofETH_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.
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 10 lines · On Sun, 14 Feb 2021 00:37:49 +0200 you wrote:
From: Vladimir Oltean <[email protected]>
Changes in v2:
Add stub definition forocelot_port_inject_framewhen switch driver is not compiled in.This is part two of the errata workaround begun here:
https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/[...]
Here is the summary with links:
- [v2,net-next,01/12] net: mscc: ocelot: stop returning IRQ_NONE in ocelot_xtr_irq_handler
https://git.kernel.org/netdev/net-next/c/f833ca293dd1 - [v2,net-next,02/12] net: mscc: ocelot: only drain extraction queue on error https://git.kernel.org/netdev/net-next/c/d7795f8f26d9 - [v2,net-next,03/12] net: mscc: ocelot: better error handling in ocelot_xtr_irq_handler https://git.kernel.org/netdev/net-next/c/a94306cea56f - [v2,net-next,04/12] net: mscc: ocelot: use DIV_ROUND_UP helper in ocelot_port_inject_frame https://git.kernel.org/netdev/net-next/c/5f016f42d342 - [v2,net-next,05/12] net: mscc: ocelot: refactor ocelot_port_inject_frame out of ocelot_port_xmit https://git.kernel.org/netdev/net-next/c/137ffbc4bb86 - [v2,net-next,06/12] net: dsa: tag_ocelot: avoid accessing ds->priv in ocelot_rcv https://git.kernel.org/netdev/net-next/c/8a678bb29bd2 - [v2,net-next,07/12] net: mscc: ocelot: use common tag parsing code with DSA https://git.kernel.org/netdev/net-next/c/40d3f295b5fe - [v2,net-next,08/12] net: dsa: tag_ocelot: single out PTP-related transmit tag processing https://git.kernel.org/netdev/net-next/c/62bf5fde5e14 - [v2,net-next,09/12] net: dsa: tag_ocelot: create separate tagger for Seville https://git.kernel.org/netdev/net-next/c/7c4bb540e917 - [v2,net-next,10/12] net: mscc: ocelot: refactor ocelot_xtr_irq_handler into ocelot_xtr_poll https://git.kernel.org/netdev/net-next/c/924ee317f724 - [v2,net-next,11/12] net: dsa: felix: setup MMIO filtering rules for PTP when using tag_8021q https://git.kernel.org/netdev/net-next/c/c8c0ba4fe247 - [v2,net-next,12/12] net: dsa: tag_ocelot_8021q: add support for PTP timestamping https://git.kernel.org/netdev/net-next/c/0a6f17c6ae21
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html