PTP support for the SJA1105 DSA driver
Vladimir Oltean
maintainerv2 cover PTP support for the SJA1105 DSA driver
This patchset adds the following:
- A timecounter/cyclecounter based PHC for the free-running timestamping clock of this switch.
- A state machine implemented in the DSA tagger for SJA1105, which keeps track of metadata follow-up Ethernet frames (the switch's way of transmitting RX timestamps).
Clock manipulations on the actual hardware PTP clock will have to be implemented anyway, for the TTEthernet block and the time-based ingress policer.
This depends upon the "FDB updates for SJA1105 DSA driver" series at:
https://patchwork.ozlabs.org/project/netdev/list/?series=111354&state=*
v1 patchset can be found at:
https://lkml.org/lkml/2019/5/28/1093
Changes from v1:
- Removed the addition of the DSA .can_timestamp callback.
- Waiting for meta frames is done completely inside the tagger, and all frames emitted on RX are already partially timestamped.
- Added a global data structure for the tagger common to all ports.
- Made PTP work with ports in standalone mode, by limiting use of the DMAC-mangling "incl_srcpt" mode only when ports are bridged, aka when the DSA master is already promiscuous and can receive anything. Also changed meta frames to be sent at the 01-80-C2-00-00-0E DMAC.
- Made some progress w.r.t. observed negative path delay. Apparently it only appears when the delay mechanism is the delay request-response (end-to-end) one. If peer delay is used (-P), the path delay is positive and appears reasonable for an 1000Base-T link (485 ns in steady state).
SJA1105 as PTP slave (OC) with E2E path delay:
ptp4l[55.600]: master offset 8 s2 freq +83677 path delay -2390 ptp4l[56.600]: master offset 17 s2 freq +83688 path delay -2391 ptp4l[57.601]: master offset 6 s2 freq +83682 path delay -2391 ptp4l[58.601]: master offset -1 s2 freq +83677 path delay -2391
SJA1105 as PTP slave (OC) with P2P path delay:
ptp4l[48.343]: master offset 5 s2 freq +83715 path delay 484 ptp4l[48.468]: master offset -3 s2 freq +83705 path delay 485 ptp4l[48.593]: master offset 0 s2 freq +83708 path delay 485 ptp4l[48.718]: master offset 1 s2 freq +83710 path delay 485 ptp4l[48.844]: master offset 1 s2 freq +83710 path delay 485 ptp4l[48.969]: master offset -5 s2 freq +83702 path delay 485 ptp4l[49.094]: master offset 3 s2 freq +83712 path delay 485 ptp4l[49.219]: master offset 4 s2 freq +83714 path delay 485 ptp4l[49.344]: master offset -5 s2 freq +83702 path delay 485 ptp4l[49.469]: master offset 3 s2 freq +83713 path delay 487
Vladimir Oltean (10):
net: dsa: Keep a pointer to the skb clone for TX timestamping
net: dsa: Add teardown callback for drivers
net: dsa: tag_8021q: Create helper function for removing VLAN header
net: dsa: sja1105: Move sja1105_change_tpid into
sja1105_vlan_filtering
net: dsa: sja1105: Limit use of incl_srcpt to bridge+vlan mode
net: dsa: sja1105: Add support for the PTP clock
net: dsa: sja1105: Move sja1105_is_link_local to include/linux
net: dsa: sja1105: Make sja1105_is_link_local not match meta frames
net: dsa: sja1105: Add support for PTP timestamping
net: dsa: sja1105: Increase priority of CPU-trapped frames
drivers/net/dsa/sja1105/Kconfig | 7 + drivers/net/dsa/sja1105/Makefile | 1 + drivers/net/dsa/sja1105/sja1105.h | 29 ++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 2 + drivers/net/dsa/sja1105/sja1105_main.c | 317 ++++++++++++-- drivers/net/dsa/sja1105/sja1105_ptp.c | 392 ++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_ptp.h | 64 +++ drivers/net/dsa/sja1105/sja1105_spi.c | 33 ++ .../net/dsa/sja1105/sja1105_static_config.c | 59 +++ .../net/dsa/sja1105/sja1105_static_config.h | 10 + include/linux/dsa/8021q.h | 7 + include/linux/dsa/sja1105.h | 51 +++ include/net/dsa.h | 1 + net/dsa/dsa2.c | 3 + net/dsa/slave.c | 3 + net/dsa/tag_8021q.c | 15 + net/dsa/tag_sja1105.c | 203 ++++++++- 17 files changed, 1150 insertions(+), 47 deletions(-) create mode 100644 drivers/net/dsa/sja1105/sja1105_ptp.c create mode 100644 drivers/net/dsa/sja1105/sja1105_ptp.h
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 1/10 net: dsa: Keep a pointer to the skb clone for TX timestamping
For drivers that use deferred_xmit for PTP frames (such as sja1105), there is no need to perform matching between PTP frames and their egress timestamps, since the sending process can be serialized.
In that case, it makes sense to have the pointer to the skb clone that DSA made directly in the skb->cb. It will be used for pushing the egress timestamp back in the application socket's error queue.
---
Changes in v2:
Patch is new. Forgot to send in v1.
net/dsa/slave.c | 3 +++ 1 file changed, 3 insertions(+)
net/dsa/slave.c +3 -0
@@ -427,6 +427,8 @@ static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p,if (!clone)return ; +DSA_SKB_CB (skb)->clone = clone; +if (ds->ops->port_txtstamp (ds, p->dp->index, clone, type))return ;
@@ -464,6 +466,7 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)u64_stats_update_end (&s->syncp);DSA_SKB_CB (skb)->deferred_xmit = false; +DSA_SKB_CB (skb)->clone =NULL ;/* Identify PTP protocol packets, clone them, and pass them to the * switch driver
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 2/10 net: dsa: Add teardown callback for drivers
In reply to Vladimir OlteanThis is helpful for e.g. draining per-driver (not per-port) tagger queues.
---
Changes in v2:
Patch is new.
include/net/dsa.h | 1 + net/dsa/dsa2.c | 3 +++ 2 files changed, 4 insertions(+)
include/net/dsa.h +1 -0
@@ -361,6 +361,7 @@ struct dsa_switch_ops { int port);int (*setup)(struct dsa_switch *ds); +void (*teardown)(struct dsa_switch *ds);u32 (*get_phy_flags)(struct dsa_switch *ds,int port);/*
net/dsa/dsa2.c +3 -0
@@ -407,6 +407,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)static void dsa_switch_teardown (struct dsa_switch *ds) { +if (ds->ops->teardown) + ds->ops->teardown (ds); +if (ds->slave_mii_bus && ds->ops->phy_read)mdiobus_unregister (ds->slave_mii_bus);
Signature · 1 line
2.17.1
Andrew Lunn
maintainerRe: [PATCH v2 net-next 02/10] net: dsa: Add teardown callback for drivers
Quoted 30 lines · Vladimir Oltean
This is helpful for e.g. draining per-driver (not per-port) tagger queues.
Signed-off-by Vladimir Oltean <[email protected]>---
Changes in v2:Patch is new.
include/net/dsa.h | 1 + net/dsa/dsa2.c | 3 +++ 2 files changed, 4 insertions(+)include/net/dsa.h +1
-0@@ -361,6 +361,7 @@ struct dsa_switch_ops { int port);int (*setup)(struct dsa_switch *ds); +void (*teardown)(struct dsa_switch *ds);u32 (*get_phy_flags)(struct dsa_switch *ds,int port);/* net/dsa/dsa2.c +0
-0
net/dsa/dsa2.c static int dsa_switch_setup(struct dsa_switch *ds) · line 415
Quoted 9 lines
net/dsa/dsa2.c +3
-0@@ -407,6 +407,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)static void dsa_switch_teardown (struct dsa_switch *ds) { +if (ds->ops->teardown) + ds->ops->teardown (ds); +if (ds->slave_mii_bus && ds->ops->phy_read)mdiobus_unregister (ds->slave_mii_bus);
Hi Vladimir
If we want to keep with symmetric with dsa_switch_setup(), this teardown should be added after dsa_switch_unregister_notifier() and before devlink_unregister().
Andrew
Vladimir Oltean
maintainerRe: [PATCH v2 net-next 02/10] net: dsa: Add teardown callback for drivers
Quoted 44 lines · Andrew Lunn
Quoted 30 lines · Vladimir Oltean
This is helpful for e.g. draining per-driver (not per-port) tagger queues.
Signed-off-by Vladimir Oltean <[email protected]>---
Changes in v2:Patch is new.
include/net/dsa.h | 1 + net/dsa/dsa2.c | 3 +++ 2 files changed, 4 insertions(+)include/net/dsa.h +1
-0@@ -361,6 +361,7 @@ struct dsa_switch_ops { int port);int (*setup)(struct dsa_switch *ds); +void (*teardown)(struct dsa_switch *ds);u32 (*get_phy_flags)(struct dsa_switch *ds,int port);/* net/dsa/dsa2.c +0
-0net/dsa/dsa2.c static int dsa_switch_setup(struct dsa_switch *ds) · line 415
Quoted 9 lines
net/dsa/dsa2.c +3
-0@@ -407,6 +407,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)static void dsa_switch_teardown (struct dsa_switch *ds) { +if (ds->ops->teardown) + ds->ops->teardown (ds); +if (ds->slave_mii_bus && ds->ops->phy_read)mdiobus_unregister (ds->slave_mii_bus);Hi Vladimir
Quoted 5 lines
If we want to keep with symmetric with
dsa_switch_setup(), this teardown should be added afterdsa_switch_unregister_notifier()and beforedevlink_unregister().Andrew
True.
-Vladimir
Vladimir Oltean
maintainerPATCH v2 3/10 net: dsa: tag_8021q: Create helper function for removing VLAN header
In reply to Vladimir OlteanThis removes the existing implementation from tag_sja1105, which was partially incorrect (it was not changing the MAC header offset, thereby leaving it to point 4 bytes earlier than it should have).
This overwrites the VLAN tag by moving the Ethernet source and destination MACs 4 bytes to the right. Then skb->data (assumed to be pointing immediately after the EtherType) is temporarily pushed to the beginning of the new Ethernet header, the new Ethernet header offset and length are recorded, then skb->data is moved back to where it was.
---
Changes in v2:
Patch is new.
include/linux/dsa/8021q.h | 7 +++++++ net/dsa/tag_8021q.c | 15 +++++++++++++++ net/dsa/tag_sja1105.c | 3 +-- 3 files changed, 23 insertions(+), 2 deletions(-)
include/linux/dsa/8021q.h +7 -0
@@ -31,6 +31,8 @@ int dsa_8021q_rx_switch_id(u16 vid);int dsa_8021q_rx_source_port (u16 vid); +struct sk_buff *dsa_8021q_remove_header (struct sk_buff *skb); +#else int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int index,
@@ -71,6 +73,11 @@ int dsa_8021q_rx_source_port(u16 vid)return 0 ; } +struct sk_buff *dsa_8021q_remove_header (struct sk_buff *skb) +{ +return NULL ; +} +#endif /* IS_ENABLED(CONFIG_NET_DSA_TAG_8021Q) */ #endif /* _NET_DSA_8021Q_H */
net/dsa/tag_8021q.c +15 -0
@@ -261,6 +261,21 @@ struct sk_buff *dsa_8021q_rcv(struct sk_buff *skb, struct net_device *netdev, }EXPORT_SYMBOL_GPL (dsa_8021q_rcv); +struct sk_buff *dsa_8021q_remove_header (struct sk_buff *skb) +{ +u8 *from =skb_mac_header (skb); +u8 *dest = from +VLAN_HLEN ; + +memmove (dest, from,ETH_HLEN -VLAN_HLEN ); +skb_push (skb,ETH_HLEN ); +skb_reset_mac_header (skb); +skb_reset_mac_len (skb); +skb_pull (skb,ETH_HLEN ); + +return skb; +} +EXPORT_SYMBOL_GPL (dsa_8021q_remove_header); +static const struct dsa_device_ops dsa_8021q_netdev_ops = { .name ="8021q" , .proto =DSA_TAG_PROTO_8021Q ,
net/dsa/tag_sja1105.c +1 -2
@@ -106,8 +106,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,* it there, see dsa_switch_rcv: skb_push(skb, ETH_HLEN). */ if (is_tagged) -memmove (skb->data -ETH_HLEN , skb->data -ETH_HLEN -VLAN_HLEN , -ETH_HLEN -VLAN_HLEN ); + skb =dsa_8021q_remove_header (skb);return skb; }
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 4/10 net: dsa: sja1105: Move sja1105_change_tpid into sja1105_vlan_filtering
In reply to Vladimir OlteanThis is a cosmetic patch, pre-cursor to making another change to the General Parameters Table (incl_srcpt) which does not logically pertain to the sja1105_change_tpid function name, but not putting it there would otherwise create a need of resetting the switch twice.
So simply move the existing code into the .port_vlan_filtering callback, where the incl_srcpt change will be added as well.
---
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105_main.c | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +21 -21
@@ -1289,23 +1289,6 @@ static int sja1105_static_config_reload(struct sja1105_private *priv)return rc; } -/* The TPID setting belongs to the General Parameters table, -* which can only be partially reconfigured at runtime (and not the TPID). -* So a switch reset is required. -*/ -static int sja1105_change_tpid (struct sja1105_private *priv, -u16 tpid,u16 tpid2) -{ -struct sja1105_general_params_entry *general_params; -struct sja1105_table *table; - - table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS ]; - general_params = table->entries; - general_params->tpid = tpid; - general_params->tpid2 = tpid2; -return sja1105_static_config_reload (priv); -} -static int sja1105_pvid_apply (struct sja1105_private *priv,int port,u16 pvid) {struct sja1105_mac_config_entry *mac;
@@ -1424,17 +1407,34 @@ static int sja1105_vlan_prepare(struct dsa_switch *ds, int port,return 0 ; } +/* The TPID setting belongs to the General Parameters table, +* which can only be partially reconfigured at runtime (and not the TPID). +* So a switch reset is required. +*/ static int sja1105_vlan_filtering (struct dsa_switch *ds,int port,bool enabled) { +struct sja1105_general_params_entry *general_params;struct sja1105_private *priv = ds->priv; +struct sja1105_table *table; +u16 tpid, tpid2;int rc; -if (enabled) +if (enabled) {/* Enable VLAN filtering. */ - rc =sja1105_change_tpid (priv,ETH_P_8021Q ,ETH_P_8021AD ); -else + tpid =ETH_P_8021Q ; + tpid2 =ETH_P_8021AD ; + }else {/* Disable VLAN filtering. */ - rc =sja1105_change_tpid (priv,ETH_P_SJA1105 ,ETH_P_SJA1105 ); + tpid =ETH_P_SJA1105 ; + tpid2 =ETH_P_SJA1105 ; + } + + table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS ]; + general_params = table->entries; + general_params->tpid = tpid; + general_params->tpid2 = tpid2; + + rc =sja1105_static_config_reload (priv);if (rc)dev_err (ds->dev,"Failed to change VLAN Ethertype\n" );
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 5/10 net: dsa: sja1105: Limit use of incl_srcpt to bridge+vlan mode
In reply to Vladimir OlteanThe incl_srcpt setting makes the switch mangle the destination MACs of multicast frames trapped to the CPU - a primitive tagging mechanism that works even when we cannot use the 802.1Q software features.
The downside is that the two multicast MAC addresses that the switch traps for L2 PTP (01-80-C2-00-00-0E and 01-1B-19-00-00-00) quickly turn into a lot more, as the switch encodes the source port and switch id into bytes 3 and 4 of the MAC. The resulting range of MAC addresses would need to be installed manually into the DSA master port's multicast MAC filter, and even then, most devices might not have a large enough MAC filtering table.
As a result, only limit use of incl_srcpt to when it's strictly
necessary: when under a VLAN filtering bridge. This fixes PTP in non-bridged mode (standalone ports). Otherwise, PTP frames, as well as metadata follow-up frames holding RX timestamps won't be received because they will be blocked by the master port's MAC filter. Linuxptp doesn't help, because it only requests the addition of the unmodified PTP MACs to the multicast filter.
This issue is not seen in bridged mode because the master port is put in promiscuous mode when the slave ports are enslaved to a bridge. Therefore, there is no downside to having the incl_srcpt mechanism active there.
---
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105_main.c | 9 +++++++-- net/dsa/tag_sja1105.c | 15 +++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +7 -2
@@ -392,11 +392,11 @@ static int sja1105_init_general_params(struct sja1105_private *priv) .hostprio = 0, .mac_fltres1 = SJA1105_LINKLOCAL_FILTER_A, .mac_flt1 = SJA1105_LINKLOCAL_FILTER_A_MASK, - .incl_srcpt1 = true, + .incl_srcpt1 = false, .send_meta1 = false, .mac_fltres0 = SJA1105_LINKLOCAL_FILTER_B, .mac_flt0 = SJA1105_LINKLOCAL_FILTER_B_MASK, - .incl_srcpt0 = true, + .incl_srcpt0 = false, .send_meta0 = false,/* The destination for traffic matching mac_fltres1 and * mac_fltres0 on all ports except host_port. Such traffic
@@ -1433,6 +1433,11 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) general_params = table->entries; general_params->tpid = tpid; general_params->tpid2 = tpid2; +/* When VLAN filtering is on, we need to at least be able to +* decode management traffic through the "backup plan". +*/ + general_params->incl_srcpt1 = enabled; + general_params->incl_srcpt0 = enabled; rc =sja1105_static_config_reload (priv);if (rc)
net/dsa/tag_sja1105.c +7 -8
@@ -75,12 +75,15 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb, nskb =dsa_8021q_rcv (skb, netdev, pt, &tpid, &tci); is_tagged = (nskb && tpid ==ETH_P_SJA1105 ); - skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; - vid = tci &VLAN_VID_MASK ; - skb->offload_fwd_mark =1 ; -if (sja1105_is_link_local (skb)) { +if (is_tagged) { +/* Normal traffic path. */ + vid = tci &VLAN_VID_MASK ; + source_port =dsa_8021q_rx_source_port (vid); + switch_id =dsa_8021q_rx_switch_id (vid); + skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; + }else if (sja1105_is_link_local (skb)) {/* Management traffic path. Switch embeds the switch ID and * port ID into bytes of the destination MAC, courtesy of * the incl_srcpt options.
@@ -90,10 +93,6 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,/* Clear the DMAC bytes that were mangled by the switch */ hdr->h_dest[3 ] =0 ; hdr->h_dest[4 ] =0 ; - }else { -/* Normal traffic path. */ - source_port =dsa_8021q_rx_source_port (vid); - switch_id =dsa_8021q_rx_switch_id (vid); } skb->dev =dsa_master_find_slave (netdev, switch_id, source_port);
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 6/10 net: dsa: sja1105: Add support for the PTP clock
In reply to Vladimir OlteanThe design of this PHC driver is influenced by the switch's behavior w.r.t. timestamping. It exposes two PTP counters, one free-running (PTPTSCLK) and the other offset- and frequency-corrected in hardware through PTPCLKVAL, PTPCLKADD and PTPCLKRATE. The MACs can sample either of these for frame timestamps.
However, the user manual warns that taking timestamps based on the corrected clock is less than useful, as the switch can deliver corrupted timestamps in a variety of circumstances.
Therefore, this PHC uses the free-running PTPTSCLK together with a timecounter/cyclecounter structure that translates it into a software time domain. Thus, the settime/adjtime and adjfine callbacks are hardware no-ops.
The timestamps (introduced in a further patch) will also be translated to the correct time domain before being handed over to the userspace PTP stack.
The introduction of a second set of PHC operations that operate on the hardware PTPCLKVAL/PTPCLKADD/PTPCLKRATE in the future is somewhat unavoidable, as the TTEthernet core uses the corrected PTP time domain. However, the free-running counter + timecounter structure combination will suffice for now, as the resulting timestamps yield a sub-50 ns synchronization offset in steady state using linuxptp.
For this patch, in absence of frame timestamping, the operations of the switch PHC were tested by syncing it to the system time as a local slave clock with:
phc2sys -s CLOCK_REALTIME -c swp2 -O 0 -m -S 0.01
---
Changes in v2:
Now resetting the PTP clock each time the switch core itself gets reset.
drivers/net/dsa/sja1105/Kconfig | 7 + drivers/net/dsa/sja1105/Makefile | 1 + drivers/net/dsa/sja1105/sja1105.h | 18 ++ drivers/net/dsa/sja1105/sja1105_main.c | 7 + drivers/net/dsa/sja1105/sja1105_ptp.c | 286 +++++++++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_ptp.h | 47 ++++ drivers/net/dsa/sja1105/sja1105_spi.c | 19 ++ 7 files changed, 385 insertions(+) create mode 100644 drivers/net/dsa/sja1105/sja1105_ptp.c create mode 100644 drivers/net/dsa/sja1105/sja1105_ptp.h
drivers/net/dsa/sja1105/Kconfig +7 -0
@@ -16,3 +16,10 @@ tristate "NXP SJA1105 Ethernet switch family support" - SJA1105Q (Gen. 2, No SGMII, TT-Ethernet) - SJA1105R (Gen. 2, SGMII, No TT-Ethernet) - SJA1105S (Gen. 2, SGMII, TT-Ethernet) + +config NET_DSA_SJA1105_PTP +tristate "Support for the PTP clock on the NXP SJA1105 Ethernet switch" + depends on NET_DSA_SJA1105 + help + This enables support for timestamping and PTP clock manipulations in + the SJA1105 DSA driver.
drivers/net/dsa/sja1105/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_NET_DSA_SJA1105) += sja1105.o +obj-$(CONFIG_NET_DSA_SJA1105_PTP) += sja1105_ptp.o sja1105-objs := \ sja1105_spi.o \
drivers/net/dsa/sja1105/sja1105.h +18 -0
@@ -5,6 +5,8 @@#ifndef _SJA1105_H#define _SJA1105_H +#include <linux/ptp_clock_kernel.h> +#include <linux/timecounter.h> #include <linux/dsa/sja1105.h> #include <net/dsa.h> #include <linux/mutex.h>
@@ -27,6 +29,10 @@ struct sja1105_regs {u64 rgu;u64 config;u64 rmii_pll1; +u64 ptp_control; +u64 ptpclk; +u64 ptpclkrate; +u64 ptptsclk;u64 pad_mii_tx[SJA1105_NUM_PORTS ];u64 cgu_idiv[SJA1105_NUM_PORTS ];u64 rgmii_pad_mii_tx[SJA1105_NUM_PORTS ];
@@ -53,6 +59,7 @@ struct sja1105_info {const struct sja1105_dynamic_table_ops *dyn_ops;const struct sja1105_table_ops *static_ops;const struct sja1105_regs *regs; +int (*ptp_cmd)(const void *ctx,const void *data);int (*reset_cmd)(const void *ctx,const void *data);int (*setup_rgmii_delay)(const void *ctx,int port);/* Prototypes from include/net/dsa.h */
@@ -72,6 +79,16 @@ struct sja1105_private {struct spi_device *spidev;struct dsa_switch *ds;struct sja1105_port ports[SJA1105_NUM_PORTS ]; +struct ptp_clock_info ptp_caps; +struct ptp_clock *clock; +/* The cycle counter translates the PTP timestamps (based on +* a free-running counter) into a software time domain. +*/ +struct cyclecounter tstamp_cc; +struct timecounter tstamp_tc; +struct delayed_work refresh_work; +/* Serializes all operations on the cycle counter */ +struct mutex ptp_lock;/* Serializes transmission of management frames so that * the switch doesn't confuse them with one another. */
@@ -79,6 +96,7 @@ struct sja1105_private { };#include "sja1105_dynamic_config.h" +#include "sja1105_ptp.h" struct sja1105_spi_message {u64 access;
drivers/net/dsa/sja1105/sja1105_main.c +7 -0
@@ -1528,6 +1528,11 @@ static int sja1105_setup(struct dsa_switch *ds)return rc; } + rc =sja1105_ptp_clock_register (priv); +if (rc <0 ) { +dev_err (ds->dev,"Failed to register PTP clock: %d\n" , rc); +return rc; + }/* Create and send configuration down to device */ rc =sja1105_static_config_load (priv, ports);if (rc <0 ) {
@@ -1679,6 +1684,7 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .get_strings = sja1105_get_strings, .get_ethtool_stats = sja1105_get_ethtool_stats, .get_sset_count = sja1105_get_sset_count, + .get_ts_info = sja1105_get_ts_info, .port_fdb_dump = sja1105_fdb_dump, .port_fdb_add = sja1105_fdb_add, .port_fdb_del = sja1105_fdb_del,
@@ -1803,6 +1809,7 @@ static int sja1105_remove(struct spi_device *spi) {struct sja1105_private *priv =spi_get_drvdata (spi); +sja1105_ptp_clock_unregister (priv);dsa_unregister_switch (priv->ds);sja1105_static_config_free (&priv->static_config);return 0 ;
drivers/net/dsa/sja1105/sja1105_ptp.c new file +286 -0
286 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_ptp.h new file +47 -0
47 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_spi.c +19 -0
@@ -478,7 +478,12 @@ int sja1105_static_config_upload(struct sja1105_private *priv)dev_info (dev,"Succeeded after %d tried\n" ,RETRIES - retries); } + rc =sja1105_ptp_reset (priv); +if (rc <0 ) +dev_err (dev,"Failed to reset PTP clock: %d\n" , rc); +dev_info (dev,"Reset switch and programmed static config\n" ); + out:kfree (config_buf);return rc;
@@ -507,6 +512,10 @@ static struct sja1105_regs sja1105et_regs = { .rgmii_tx_clk = {0x100016, 0x10001D, 0x100024, 0x10002B, 0x100032}, .rmii_ref_clk = {0x100015, 0x10001C, 0x100023, 0x10002A, 0x100031}, .rmii_ext_tx_clk = {0x100018, 0x10001F, 0x100026, 0x10002D, 0x100034}, + .ptp_control = 0x17, + .ptpclk = 0x18, /* Spans 0x18 to 0x19 */ + .ptpclkrate = 0x1A, + .ptptsclk = 0x1B, /* Spans 0x1B to 0x1C */ }; static struct sja1105_regs sja1105pqrs_regs = {
@@ -533,6 +542,10 @@ static struct sja1105_regs sja1105pqrs_regs = { .rmii_ref_clk = {0x100015, 0x10001B, 0x100021, 0x100027, 0x10002D}, .rmii_ext_tx_clk = {0x100017, 0x10001D, 0x100023, 0x100029, 0x10002F}, .qlevel = {0x604, 0x614, 0x624, 0x634, 0x644}, + .ptp_control = 0x18, + .ptpclk = 0x19, + .ptpclkrate = 0x1B, + .ptptsclk = 0x1C, }; struct sja1105_info sja1105e_info = {
@@ -543,6 +556,7 @@ struct sja1105_info sja1105e_info = { .reset_cmd = sja1105et_reset_cmd, .fdb_add_cmd = sja1105et_fdb_add, .fdb_del_cmd = sja1105et_fdb_del, + .ptp_cmd = sja1105et_ptp_cmd, .regs = &sja1105et_regs, .name = "SJA1105E", };
@@ -554,6 +568,7 @@ struct sja1105_info sja1105t_info = { .reset_cmd = sja1105et_reset_cmd, .fdb_add_cmd = sja1105et_fdb_add, .fdb_del_cmd = sja1105et_fdb_del, + .ptp_cmd = sja1105et_ptp_cmd, .regs = &sja1105et_regs, .name = "SJA1105T", };
@@ -565,6 +580,7 @@ struct sja1105_info sja1105p_info = { .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del, + .ptp_cmd = sja1105pqrs_ptp_cmd, .regs = &sja1105pqrs_regs, .name = "SJA1105P", };
@@ -576,6 +592,7 @@ struct sja1105_info sja1105q_info = { .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del, + .ptp_cmd = sja1105pqrs_ptp_cmd, .regs = &sja1105pqrs_regs, .name = "SJA1105Q", };
@@ -587,6 +604,7 @@ struct sja1105_info sja1105r_info = { .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del, + .ptp_cmd = sja1105pqrs_ptp_cmd, .regs = &sja1105pqrs_regs, .name = "SJA1105R", };
@@ -599,5 +617,6 @@ struct sja1105_info sja1105s_info = { .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del, + .ptp_cmd = sja1105pqrs_ptp_cmd, .name = "SJA1105S", };
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 7/10 net: dsa: sja1105: Move sja1105_is_link_local to include/linux
In reply to Vladimir OlteanThis function will be reused from the .port_rxtstamp callback to see if the received SKB can be timestamped by the switch.
---
Changes in v2:
Patch is new.
include/linux/dsa/sja1105.h | 15 +++++++++++++++ net/dsa/tag_sja1105.c | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-)
include/linux/dsa/sja1105.h +15 -0
@@ -25,4 +25,19 @@ struct sja1105_port { int mgmt_slot; }; +/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ +static inline bool sja1105_is_link_local (const struct sk_buff *skb) +{ +const struct ethhdr *hdr =eth_hdr (skb); +u64 dmac =ether_addr_to_u64 (hdr->h_dest); + +if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == +SJA1105_LINKLOCAL_FILTER_A ) +return true; +if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == +SJA1105_LINKLOCAL_FILTER_B ) +return true; +return false; +} +#endif /* _NET_DSA_SJA1105_H */
net/dsa/tag_sja1105.c +0 -15
@@ -7,21 +7,6 @@#include <linux/packing.h> #include "dsa_priv.h" -/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ -static inline bool sja1105_is_link_local (const struct sk_buff *skb) -{ -const struct ethhdr *hdr =eth_hdr (skb); -u64 dmac =ether_addr_to_u64 (hdr->h_dest); - -if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == -SJA1105_LINKLOCAL_FILTER_A ) -return true; -if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == -SJA1105_LINKLOCAL_FILTER_B ) -return true; -return false; -} -/* This is the first time the tagger sees the frame on RX. * Figure out if we can decode it, and if we can, annotate skb->cb with how we * plan to do that, so we don't need to check again in the rcv function.
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 8/10 net: dsa: sja1105: Make sja1105_is_link_local not match meta frames
In reply to Vladimir OlteanAlthough meta frames are configured to be sent at SJA1105_META_DMAC (01-80-C2-00-00-0E) which is a multicast MAC address that would also be trapped by the switch to the CPU, were it to receive it on a front-panel port, meta frames are conceptually not link-local frames, they only carry their RX timestamps.
The choice of sending meta frames at a multicast DMAC is a pragmatic one, to avoid installing an extra entry to the DSA master port's multicast MAC filter.
---
Changes in v2:
Patch is new.
include/linux/dsa/sja1105.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/dsa/sja1105.h +2 -0
@@ -31,6 +31,8 @@ static inline bool sja1105_is_link_local(const struct sk_buff *skb)const struct ethhdr *hdr =eth_hdr (skb);u64 dmac =ether_addr_to_u64 (hdr->h_dest); +if (ntohs (hdr->h_proto) ==ETH_P_SJA1105_META ) +return false;if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) ==SJA1105_LINKLOCAL_FILTER_A )return true;
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [PATCH v2 net-next 08/10] net: dsa: sja1105: Make sja1105_is_link_local not match meta frames
Quoted 34 lines · Vladimir Oltean
Although meta frames are configured to be sent at
SJA1105_META_DMAC(01-80-C2-00-00-0E) which is a multicast MAC address that would also be trapped by the switch to the CPU, were it to receive it on a front-panel port, meta frames are conceptually not link-local frames, they only carry their RX timestamps.The choice of sending meta frames at a multicast DMAC is a pragmatic one, to avoid installing an extra entry to the DSA master port's multicast MAC filter.
Signed-off-by Vladimir Oltean <[email protected]>---
Changes in v2:Patch is new.
include/linux/dsa/sja1105.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/dsa/sja1105.h +2
-1@@ -31,6 +31,8 @@ static inline bool sja1105_is_link_local(const struct sk_buff *skb)const struct ethhdr *hdr =eth_hdr (skb);u64 dmac =ether_addr_to_u64 (hdr->h_dest); +if (ntohs (hdr->h_proto) ==ETH_P_SJA1105_META ) +return false;if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) ==SJA1105_LINKLOCAL_FILTER_A )return true; --
Quoted 2 lines
2.17.1
Please be aware that this patch is misplaced and should be moved after the current 09/10 (doesn't compile as 08/10).
I'll bundle this change in v3 with the other feedback I'll hopefully get.
Thanks!
-Vladimir
Vladimir Oltean
maintainerPATCH v2 9/10 net: dsa: sja1105: Add support for PTP timestamping
In reply to Vladimir OlteanOn RX, timestamping is done by programming the switch to send "meta" follow-up Ethernet frames (which contain partial RX timestamps) after each link-local frame that was trapped to the CPU port through MAC filtering. This includes PTP frames.
Meta frame reception relies on the hardware keeping its promise that it will send no other traffic towards the CPU port between a link-local frame and a meta frame. Otherwise there is no other way to associate the meta frame with the link-local frame it's holding a timestamp of. The receive function is made stateful, and buffers a timestampable frame until its meta frame arrives, then merges the two, drops the meta and releases the link-local frame up the stack.
On TX, timestamping is performed synchronously from the port_deferred_xmit worker thread. In management routes, the switch is requested to take egress timestamps (again partial), which are reconstructed and appended to a clone of the skb that was just sent. The cloning is done by DSA and we retrieve the pointer from the structure that DSA keeps in skb->cb. Then these clones are enqueued to the socket's error queue for application-level processing.
---
Changes in v2:
- Made cyclecounter_reconstruct driver-specific
(sja1105_tstamp_reconstruct).
- Reimplemented sja1105_rcv_meta_state_machine to buffer a timestampable skb until its meta frame arrives, and then push the cached skb up the stack while dropping the meta (simplification suggested by Richard Cochran).
- Replaced the per-port RX timestamping data structures with a global one.
drivers/net/dsa/sja1105/sja1105.h | 11 + .../net/dsa/sja1105/sja1105_dynamic_config.c | 2 + drivers/net/dsa/sja1105/sja1105_main.c | 257 +++++++++++++++++- drivers/net/dsa/sja1105/sja1105_ptp.c | 110 +++++++- drivers/net/dsa/sja1105/sja1105_ptp.h | 17 ++ drivers/net/dsa/sja1105/sja1105_spi.c | 14 + .../net/dsa/sja1105/sja1105_static_config.c | 59 ++++ .../net/dsa/sja1105/sja1105_static_config.h | 10 + include/linux/dsa/sja1105.h | 34 +++ net/dsa/tag_sja1105.c | 186 ++++++++++++- 10 files changed, 692 insertions(+), 8 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +11 -0
@@ -33,6 +33,7 @@ struct sja1105_regs {u64 ptpclk;u64 ptpclkrate;u64 ptptsclk; +u64 ptpegr_ts[SJA1105_NUM_PORTS ];u64 pad_mii_tx[SJA1105_NUM_PORTS ];u64 cgu_idiv[SJA1105_NUM_PORTS ];u64 rgmii_pad_mii_tx[SJA1105_NUM_PORTS ];
@@ -56,6 +57,15 @@ struct sja1105_info {* switch core and device_id) */ u64 part_no; +/* E/T and P/Q/R/S have partial timestamps of different sizes. +* They must be reconstructed on both families anyway to get the full +* 64-bit values back. +*/ +int ptp_ts_bits; +/* Also SPI commands are of different sizes to retrieve +* the egress timestamps. +*/ +int ptpegr_ts_bytes;const struct sja1105_dynamic_table_ops *dyn_ops;const struct sja1105_table_ops *static_ops;const struct sja1105_regs *regs;
@@ -93,6 +103,7 @@ struct sja1105_private {* the switch doesn't confuse them with one another. */ struct mutex mgmt_lock; +struct sja1105_tagger_data tagger_data; };#include "sja1105_dynamic_config.h"
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +2 -0
@@ -378,6 +378,7 @@ struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = { .addr = 0x38, }, [BLK_IDX_L2_FORWARDING_PARAMS] = {0}, + [BLK_IDX_AVB_PARAMS] = {0}, [BLK_IDX_GENERAL_PARAMS] = { .entry_packing = sja1105et_general_params_entry_packing, .cmd_packing = sja1105et_general_params_cmd_packing,
@@ -441,6 +442,7 @@ struct sja1105_dynamic_table_ops sja1105pqrs_dyn_ops[BLK_IDX_MAX_DYN] = { .addr = 0x38, }, [BLK_IDX_L2_FORWARDING_PARAMS] = {0}, + [BLK_IDX_AVB_PARAMS] = {0}, [BLK_IDX_GENERAL_PARAMS] = { .entry_packing = sja1105et_general_params_entry_packing, .cmd_packing = sja1105et_general_params_cmd_packing,
drivers/net/dsa/sja1105/sja1105_main.c +255 -2
329 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_ptp.c +108 -2
122 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_ptp.h +17 -0
@@ -10,6 +10,8 @@ int sja1105_ptp_clock_register(struct sja1105_private *priv);void sja1105_ptp_clock_unregister (struct sja1105_private *priv); +int sja1105_ptpegr_ts_poll (struct sja1105_private *priv,int port,u64 *ts); +int sja1105et_ptp_cmd (const void *ctx,const void *data);int sja1105pqrs_ptp_cmd (const void *ctx,const void *data);
@@ -17,6 +19,9 @@ int sja1105pqrs_ptp_cmd(const void *ctx, const void *data);int sja1105_get_ts_info (struct dsa_switch *ds,int port,struct ethtool_ts_info *ts); +u64 sja1105_tstamp_reconstruct (struct sja1105_private *priv,u64 now, +u64 ts_partial); +int sja1105_ptp_reset (struct sja1105_private *priv);#else
@@ -31,6 +36,18 @@ static inline void sja1105_ptp_clock_unregister(struct sja1105_private *priv)return ; } +static inline int +sja1105_ptpegr_ts_poll (struct sja1105_private *priv,int port,u64 *ts) +{ +return 0 ; +} + +static inline u64 sja1105_tstamp_reconstruct (struct sja1105_private *priv, +u64 now,u64 ts_partial) +{ +return 0 ; +} +static inline int sja1105_ptp_reset (struct sja1105_private *priv) {return 0 ;
drivers/net/dsa/sja1105/sja1105_spi.c +14 -0
@@ -512,6 +512,7 @@ static struct sja1105_regs sja1105et_regs = { .rgmii_tx_clk = {0x100016, 0x10001D, 0x100024, 0x10002B, 0x100032}, .rmii_ref_clk = {0x100015, 0x10001C, 0x100023, 0x10002A, 0x100031}, .rmii_ext_tx_clk = {0x100018, 0x10001F, 0x100026, 0x10002D, 0x100034}, + .ptpegr_ts = {0xC0, 0xC2, 0xC4, 0xC6, 0xC8}, .ptp_control = 0x17, .ptpclk = 0x18, /* Spans 0x18 to 0x19 */ .ptpclkrate = 0x1A,
@@ -542,6 +543,7 @@ static struct sja1105_regs sja1105pqrs_regs = { .rmii_ref_clk = {0x100015, 0x10001B, 0x100021, 0x100027, 0x10002D}, .rmii_ext_tx_clk = {0x100017, 0x10001D, 0x100023, 0x100029, 0x10002F}, .qlevel = {0x604, 0x614, 0x624, 0x634, 0x644}, + .ptpegr_ts = {0xC0, 0xC4, 0xC8, 0xCC, 0xD0}, .ptp_control = 0x18, .ptpclk = 0x19, .ptpclkrate = 0x1B,
@@ -553,6 +555,8 @@ struct sja1105_info sja1105e_info = { .part_no = SJA1105ET_PART_NO, .static_ops = sja1105e_table_ops, .dyn_ops = sja1105et_dyn_ops, + .ptp_ts_bits = 24, + .ptpegr_ts_bytes = 4, .reset_cmd = sja1105et_reset_cmd, .fdb_add_cmd = sja1105et_fdb_add, .fdb_del_cmd = sja1105et_fdb_del,
@@ -565,6 +569,8 @@ struct sja1105_info sja1105t_info = { .part_no = SJA1105ET_PART_NO, .static_ops = sja1105t_table_ops, .dyn_ops = sja1105et_dyn_ops, + .ptp_ts_bits = 24, + .ptpegr_ts_bytes = 4, .reset_cmd = sja1105et_reset_cmd, .fdb_add_cmd = sja1105et_fdb_add, .fdb_del_cmd = sja1105et_fdb_del,
@@ -577,6 +583,8 @@ struct sja1105_info sja1105p_info = { .part_no = SJA1105P_PART_NO, .static_ops = sja1105p_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, + .ptp_ts_bits = 32, + .ptpegr_ts_bytes = 8, .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del,
@@ -589,6 +597,8 @@ struct sja1105_info sja1105q_info = { .part_no = SJA1105Q_PART_NO, .static_ops = sja1105q_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, + .ptp_ts_bits = 32, + .ptpegr_ts_bytes = 8, .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del,
@@ -601,6 +611,8 @@ struct sja1105_info sja1105r_info = { .part_no = SJA1105R_PART_NO, .static_ops = sja1105r_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, + .ptp_ts_bits = 32, + .ptpegr_ts_bytes = 8, .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del,
@@ -614,6 +626,8 @@ struct sja1105_info sja1105s_info = { .static_ops = sja1105s_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, .regs = &sja1105pqrs_regs, + .ptp_ts_bits = 32, + .ptpegr_ts_bytes = 8, .reset_cmd = sja1105pqrs_reset_cmd, .fdb_add_cmd = sja1105pqrs_fdb_add, .fdb_del_cmd = sja1105pqrs_fdb_del,
drivers/net/dsa/sja1105/sja1105_static_config.c +59 -0
107 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.h +10 -0
@@ -20,10 +20,12 @@#define SJA1105ET_SIZE_MAC_CONFIG_ENTRY 28#define SJA1105ET_SIZE_L2_LOOKUP_PARAMS_ENTRY 4#define SJA1105ET_SIZE_GENERAL_PARAMS_ENTRY 40 +#define SJA1105ET_SIZE_AVB_PARAMS_ENTRY 12#define SJA1105PQRS_SIZE_L2_LOOKUP_ENTRY 20#define SJA1105PQRS_SIZE_MAC_CONFIG_ENTRY 32#define SJA1105PQRS_SIZE_L2_LOOKUP_PARAMS_ENTRY 16#define SJA1105PQRS_SIZE_GENERAL_PARAMS_ENTRY 44 +#define SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY 16/* UM10944.pdf Page 11, Table 2. Configuration Blocks */ enum {
@@ -34,6 +36,7 @@ enum {BLKID_MAC_CONFIG =0x09 ,BLKID_L2_LOOKUP_PARAMS =0x0D ,BLKID_L2_FORWARDING_PARAMS =0x0E , +BLKID_AVB_PARAMS =0x10 ,BLKID_GENERAL_PARAMS =0x11 , BLKID_XMII_PARAMS = 0x4E, };
@@ -46,6 +49,7 @@ enum sja1105_blk_idx {BLK_IDX_MAC_CONFIG ,BLK_IDX_L2_LOOKUP_PARAMS ,BLK_IDX_L2_FORWARDING_PARAMS , +BLK_IDX_AVB_PARAMS ,BLK_IDX_GENERAL_PARAMS ,BLK_IDX_XMII_PARAMS , BLK_IDX_MAX,
@@ -64,6 +68,7 @@ enum sja1105_blk_idx {#define SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT 1#define SJA1105_MAX_GENERAL_PARAMS_COUNT 1#define SJA1105_MAX_XMII_PARAMS_COUNT 1 +#define SJA1105_MAX_AVB_PARAMS_COUNT 1#define SJA1105_MAX_FRAME_MEMORY 929
@@ -179,6 +184,11 @@ struct sja1105_l2_policing_entry {u64 partition; }; +struct sja1105_avb_params_entry { +u64 destmeta; +u64 srcmeta; +}; +struct sja1105_mac_config_entry {u64 top[8 ];u64 base[8 ];
include/linux/dsa/sja1105.h +34 -0
@@ -12,6 +12,7 @@#include <net/dsa.h> #define ETH_P_SJA1105 ETH_P_DSA_8021Q +#define ETH_P_SJA1105_META 0x0008/* IEEE 802.3 Annex 57A: Slow Protocols PDUs (01:80:C2:xx:xx:xx) */ #define SJA1105_LINKLOCAL_FILTER_A 0x0180C2000000ull
@@ -20,8 +21,41 @@#define SJA1105_LINKLOCAL_FILTER_B 0x011B19000000ull#define SJA1105_LINKLOCAL_FILTER_B_MASK 0xFFFFFF000000ull +/* Source and Destination MAC of follow-up meta frames. +* Whereas the choice of SMAC only affects the unique identification of the +* switch as sender of meta frames, the DMAC must be an address that is present +* in the DSA master port's multicast MAC filter. +* 01-80-C2-00-00-0E is a good choice for this, as all profiles of IEEE 1588 +* over L2 use this address for some purpose already. +*/ +#define SJA1105_META_SMAC 0x222222222222ull +#define SJA1105_META_DMAC 0x0180C200000Eull + +/* Global tagger data: each struct sja1105_port has a reference to +* the structure defined in struct sja1105_private. +*/ +struct sja1105_tagger_data { +struct sk_buff_head skb_rxtstamp_queue; +struct work_struct rxtstamp_work; +struct sk_buff *stampable_skb; +/* Protects concurrent access to the meta state machine +* from taggers running on multiple ports on SMP systems +*/ +spinlock_t meta_lock; +bool hwts_rx_en; +}; + +struct sja1105_skb_cb { +u32 meta_tstamp; +}; + +#define SJA1105_SKB_CB (skb) \ + ((struct sja1105_skb_cb *)DSA_SKB_CB_PRIV(skb)) +struct sja1105_port { +struct sja1105_tagger_data *data;struct dsa_port *dp; +bool hwts_tx_en;int mgmt_slot; };
net/dsa/tag_sja1105.c +182 -4
232 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 10/10 net: dsa: sja1105: Increase priority of CPU-trapped frames
In reply to Vladimir OlteanWithout noticing any particular issue, this patch ensures that management traffic is treated with the maximum priority on RX by the switch. This is generally desirable, as the driver keeps a state machine that waits for metadata follow-up frames as soon as a management frame is received. Increasing the priority helps expedite the reception (and further reconstruction) of the RX timestamp to the driver after the MAC has generated it.
---
Changes in v2:
None.
drivers/net/dsa/sja1105/sja1105_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/sja1105/sja1105_main.c +1 -1
@@ -389,7 +389,7 @@ static int sja1105_init_general_params(struct sja1105_private *priv) .mirr_ptacu = 0, .switchid = priv->ds->index,/* Priority queue for link-local frames trapped to CPU */ - .hostprio = 0, + .hostprio = 7, .mac_fltres1 = SJA1105_LINKLOCAL_FILTER_A, .mac_flt1 = SJA1105_LINKLOCAL_FILTER_A_MASK, .incl_srcpt1 = false,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerQuoted 94 lines · Vladimir Oltean
This patchset adds the following:
- A timecounter/cyclecounter based PHC for the free-running timestamping clock of this switch.
- A state machine implemented in the DSA tagger for SJA1105, which keeps track of metadata follow-up Ethernet frames (the switch's way of transmitting RX timestamps).
Clock manipulations on the actual hardware PTP clock will have to be implemented anyway, for the TTEthernet block and the time-based ingress policer.
This depends upon the "FDB updates for SJA1105 DSA driver" series at:
https://patchwork.ozlabs.org/project/netdev/list/?series=111354&state=*v1 patchset can be found at:
https://lkml.org/lkml/2019/5/28/1093Changes from v1:
- Removed the addition of the DSA .can_timestamp callback.
- Waiting for meta frames is done completely inside the tagger, and all frames emitted on RX are already partially timestamped.
- Added a global data structure for the tagger common to all ports.
- Made PTP work with ports in standalone mode, by limiting use of the DMAC-mangling "
incl_srcpt" mode only when ports are bridged, aka when the DSA master is already promiscuous and can receive anything. Also changed meta frames to be sent at the 01-80-C2-00-00-0E DMAC.- Made some progress w.r.t. observed negative path delay. Apparently it only appears when the delay mechanism is the delay request-response (end-to-end) one. If peer delay is used (-P), the path delay is positive and appears reasonable for an 1000Base-T link (485 ns in steady state).
SJA1105 as PTP slave (OC) with E2E path delay:
ptp4l[55.600]: master offset 8 s2 freq +83677 path delay -2390 ptp4l[56.600]: master offset 17 s2 freq +83688 path delay -2391 ptp4l[57.601]: master offset 6 s2 freq +83682 path delay -2391 ptp4l[58.601]: master offset -1 s2 freq +83677 path delay -2391SJA1105 as PTP slave (OC) with P2P path delay:
ptp4l[48.343]: master offset 5 s2 freq +83715 path delay 484 ptp4l[48.468]: master offset -3 s2 freq +83705 path delay 485 ptp4l[48.593]: master offset 0 s2 freq +83708 path delay 485 ptp4l[48.718]: master offset 1 s2 freq +83710 path delay 485 ptp4l[48.844]: master offset 1 s2 freq +83710 path delay 485 ptp4l[48.969]: master offset -5 s2 freq +83702 path delay 485 ptp4l[49.094]: master offset 3 s2 freq +83712 path delay 485 ptp4l[49.219]: master offset 4 s2 freq +83714 path delay 485 ptp4l[49.344]: master offset -5 s2 freq +83702 path delay 485 ptp4l[49.469]: master offset 3 s2 freq +83713 path delay 487Vladimir Oltean (10):
net: dsa: Keep a pointer to the skb clone for TX timestamping
net: dsa: Add teardown callback for drivers
net: dsa:tag_8021q: Create helper function for removing VLAN header
net: dsa: sja1105: Movesja1105_change_tpidintosja1105_vlan_filteringnet: dsa: sja1105: Limit use of
incl_srcptto bridge+vlan mode
net: dsa: sja1105: Add support for the PTP clock
net: dsa: sja1105: Movesja1105_is_link_localtoinclude/linux
net: dsa: sja1105: Makesja1105_is_link_localnot match meta frames
net: dsa: sja1105: Add support for PTP timestamping
net: dsa: sja1105: Increase priority of CPU-trapped framesdrivers/net/dsa/sja1105/Kconfig | 7 + drivers/net/dsa/sja1105/Makefile | 1 + drivers/net/dsa/sja1105/sja1105.h | 29 ++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 2 + drivers/net/dsa/sja1105/sja1105_main.c | 317 ++++++++++++-- drivers/net/dsa/sja1105/sja1105_ptp.c | 392 ++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_ptp.h | 64 +++ drivers/net/dsa/sja1105/sja1105_spi.c | 33 ++ .../net/dsa/sja1105/sja1105_static_config.c | 59 +++ .../net/dsa/sja1105/sja1105_static_config.h | 10 + include/linux/dsa/8021q.h | 7 + include/linux/dsa/sja1105.h | 51 +++ include/net/dsa.h | 1 + net/dsa/dsa2.c | 3 + net/dsa/slave.c | 3 + net/dsa/tag_8021q.c | 15 + net/dsa/tag_sja1105.c | 203 ++++++++- 17 files changed, 1150 insertions(+), 47 deletions(-) create mode 100644 drivers/net/dsa/sja1105/sja1105_ptp.c create mode 100644 drivers/net/dsa/sja1105/sja1105_ptp.h
Quoted 3 lines
--
2.17.1
Hi Dave,
This series appears in patchwork as "superseded":
https://patchwork.ozlabs.org/project/netdev/list/?series=111356&state=*
Perhaps it got mixed up with another one?
Thanks,
-Vladimir
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Tue, 4 Jun 2019 02:13:16 +0300
Quoted 3 lines
This series appears in patchwork as "superseded":
https://patchwork.ozlabs.org/project/netdev/list/?series=111356&state=*
Perhaps it got mixed up with another one?
No, there was a comment in this thread that there would be a respin with some changes. Anticipating that respin, I mark this as superseded.