Skip to contentSkip to conversation

net: dsa: microchip: PTP support for KSZ956x

PATCH Superseded Christian Eggers 2 participants 12 messages Dec 1, 2020 – Dec 3, 2020

Subsystems (6)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover net: dsa: microchip: PTP support for KSZ956x

There is only little documentation for PTP available on the data sheet
[1] (more or less only the register reference). Questions to the Microchip support were seldom answered comprehensively or in reasonable time. So this is more or less the result of reverse engineering.

[1]
http://ww1.microchip.com/downloads/en/DeviceDoc/KSZ9563R-Data-Sheet-DS00002419D.pdf

Changes from v3 --> v4
------------------------
The first 2 patches of v3 have been applied.

[ 5/12]-->[ 3/9] - Reviewed-by: Vladimir Oltean <[email protected]>
[ 6/12]-->[ 4/9] - s/low active/active low/
- Reviewed-by: Vladimir Oltean <[email protected]>
[ 7/12]-->[ 5/9] - Reviewed-by: Vladimir Oltean <[email protected]>
[ 9/12]-->[ 7/9] - Remove useless case statement
- Reviewed-by: Vladimir Oltean <[email protected]>
[10/12]-->[ 8/9] - s/low active/active low/
- 80 chars per line
- Use IEEE 802.1AS mode (to suppress forwarding of PDelay messages)
- Enable/disable hardware timestaping at runtime (port_hwtstamp_set)
- Use mutex in port_hwtstamp_set
- Don't use port specific struct hwtstamp_config
- removed #ifdefs from tag_ksz.c
- Set port's tx_latency and rx_latency to 0
- added include/linux/dsa/ksz_common.h to MAINTAINERS
[11/12] - removed Patch 11/12 (PPS support)
[12/12]-->[ 9/9] - 80 chars per line
- reverse christmas tree
- Set default pulse width for perout pulse to 50% (max. 125ms)
- reject unsupported flags for perout_request

Changes from v2 --> v3
------------------------
Applied all changes requested by Vladimir Oltean. v3 depends on my other netdev patches from 2020-11-18:
- net: ptp: introduce common defines for PTP message types
- net: dsa: avoid potential use-after-free error

[1/11]-->[1/12] - dts: remove " OR BSD-2-Clause" from SPDX-License-Identifier
- dts: add "additionalProperties"
- dts: remove quotes

[2/11]-->[2/12]  - Reviewed-by: Vladimir Oltean <[email protected]>
[3/11]           - [Patch removed] (split ksz_common.h)
[4/11]-->[3/12]  - Reviewed-by: Vladimir Oltean <[email protected]>

- fixed summary
[5/11]-->[4/12] - Use "interrupts-extended" syntax [6/11]-->[5+6/12] - Split up patch
- style fixes
- use GENMASK()
- IRQF_ONESHOT|IRQF_SHARED
[7/11]-->[7/12] - Remove "default n" from Kconfig
- use mutex in adjfine()
- style fixes
[8/11]-->[8/12] - Be more verbose in commit message
- Rename helper
- provide correction instead of t2
- simplify location of UDP header
[9/11]-->[9+10/12] - Split up patch
- Update commmit messages
- don't use OR operator on irqreturn_t
- spin_lock_irqsave() --> spin_lock_bh()
- style fixes
- remove rx_filter cases for DELAY_REQ
- use new PTP_MSGTYPE_* defines
- inline ksz9477_ptp_should_tstamp()
- ksz9477_tstamp_to_clock() --> ksz9477_tstamp_reconstruct()
- use shared data in include/linux/net/dsa/ksz_common.h
- wait for tx time stamp (within sleepable context)
- use boolean for tx time stamp enable
- move t2 from correction to tail tag (again)
- ...

Changes from RFC --> v2
------------------------
I think that all open questions regarding the RFC version could be solved.
dts: referenced to dsa.yaml
dts: changed node name to "switch" in example
dts: changed "ports" subnode to "ethernet-ports"
ksz_common: support "ethernet-ports" subnode
tag_ksz: fix usage of correction field (32 bit ns + 16 bit sub-ns)
tag_ksz: use cached PTP header from device's .port_txtstamp function
tag_ksz: refactored ksz9477_tstamp_to_clock()
tag_ksz: pdelay_req: only subtract 2 bit seconds from the correction field
tag_ksz: pdelay_resp: don't move (negative) correction to the egress tail tag
ptp_classify: add ptp_onestep_p2p_move_t2_to_correction helper
ksz9477_ptp: removed E2E support (as suggested by Vladimir)
ksz9477_ptp: removed master/slave sysfs attributes (nacked by Richard)
ksz9477_ptp: refactored ksz9477_ptp_port_txtstamp
ksz9477_ptp: removed "pulse" attribute
kconfig: depend on PTP_1588_CLOCK (instead of "imply")

#1 lore raw

PATCH v4 1/9 net: dsa: microchip: rename ksz9477.c to ksz9477_main.c

PTP functionality will be built into a separate source file (ksz9477_ptp.c).

---
 drivers/net/dsa/microchip/Makefile                      | 1 +
 drivers/net/dsa/microchip/{ksz9477.c => ksz9477_main.c} | 0
 2 files changed, 1 insertion(+)
 rename drivers/net/dsa/microchip/{ksz9477.c => ksz9477_main.c} (100%)
drivers/net/dsa/microchip/Makefile +1 -0
index 929caa81e782..c5cc1d5dea06 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)	+= ksz_common.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477)		+= ksz9477.o
+ksz9477-objs := ksz9477_main.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C)	+= ksz9477_i2c.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI)	+= ksz9477_spi.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795)		+= ksz8795.o
drivers/net/dsa/microchip/ksz9477_main.c renamed from drivers/net/dsa/microchip/ksz9477.c +0 -0
similarity index 100%
rename from drivers/net/dsa/microchip/ksz9477.c
rename to drivers/net/dsa/microchip/ksz9477_main.c
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#2 lore raw

PATCH v4 2/9 dt-bindings: net: dsa: microchip,ksz: add interrupt property

In reply to Christian Eggers

The devices have an optional interrupt line.

---
 .../devicetree/bindings/net/dsa/microchip,ksz.yaml         | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +7 -0
index 9f7d131bbcef..c3235110156a 100644
@@ -35,6 +35,11 @@ properties:
       Should be a gpio specifier for a reset line.
     maxItems: 1
 
+  interrupts:
+    description:
+      Interrupt specifier for the INTRP_N line from the device.
+    maxItems: 1
+
   microchip,synclko-125:
     $ref: /schemas/types.yaml#/definitions/flag
     description:
@@ -49,6 +54,7 @@ unevaluatedProperties: false
 examples:
   - |
     #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
 
     // Ethernet switch connected via SPI to the host, CPU port wired to eth0:
     eth0 {
@@ -70,6 +76,7 @@ examples:
             compatible = "microchip,ksz9477";
             reg = <0>;
             reset-gpios = <&gpio5 0 GPIO_ACTIVE_LOW>;
+            interrupts-extended = <&gpio5 1 IRQ_TYPE_LEVEL_LOW>;  /* INTRP_N line */
 
             spi-max-frequency = <44000000>;
 
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#3 lore raw

PATCH v4 3/9 net: dsa: microchip: ksz9477: move chip reset to ksz9477_switch_init()

In reply to Christian Eggers

The next patch will add basic interrupt support. Chip reset must be performed before requesting the IRQ, so move this from ksz9477_setup() to ksz9477_init().

---
 drivers/net/dsa/microchip/ksz9477_main.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/dsa/microchip/ksz9477_main.c +7 -8
index abfd3802bb51..c0b4cf66c904 100644
@@ -1345,19 +1345,12 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 static int ksz9477_setup(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
-	int ret = 0;
 
 	dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
 				       dev->num_vlans, GFP_KERNEL);
 	if (!dev->vlan_cache)
 		return -ENOMEM;
 
-	ret = ksz9477_reset_switch(dev);
-	if (ret) {
-		dev_err(ds->dev, "failed to reset switch\n");
-		return ret;
-	}
-
 	/* Required for port partitioning. */
 	ksz9477_cfg32(dev, REG_SW_QM_CTRL__4, UNICAST_VLAN_BOUNDARY,
 		      true);
@@ -1537,10 +1530,16 @@ static const struct ksz_chip_data ksz9477_switch_chips[] = {
 
 static int ksz9477_switch_init(struct ksz_device *dev)
 {
-	int i;
+	int i, ret;
 
 	dev->ds->ops = &ksz9477_switch_ops;
 
+	ret = ksz9477_reset_switch(dev);
+	if (ret) {
+		dev_err(dev->dev, "failed to reset switch\n");
+		return ret;
+	}
+
 	for (i = 0; i < ARRAY_SIZE(ksz9477_switch_chips); i++) {
 		const struct ksz_chip_data *chip = &ksz9477_switch_chips[i];
 
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#4 lore raw

PATCH v4 4/9 net: dsa: microchip: ksz9477: basic interrupt support

In reply to Christian Eggers

Interrupts are required for TX time stamping. Probably they could also be used for PHY connection status.

This patch only adds the basic infrastructure for interrupts, no interrupts are finally enabled nor handled.

---
Changes in v4:
--------------
- s/low active/active low/
- Reviewed-by: Vladimir Oltean <[email protected]>

 drivers/net/dsa/microchip/ksz9477_i2c.c  |  2 +
 drivers/net/dsa/microchip/ksz9477_main.c | 68 ++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz9477_spi.c  |  2 +
 drivers/net/dsa/microchip/ksz_common.h   |  1 +
 4 files changed, 73 insertions(+)
drivers/net/dsa/microchip/ksz9477_i2c.c +2 -0
index 4e053a25d077..4ed1f503044a 100644
@@ -41,6 +41,8 @@ static int ksz9477_i2c_probe(struct i2c_client *i2c,
 	if (i2c->dev.platform_data)
 		dev->pdata = i2c->dev.platform_data;
 
+	dev->irq = i2c->irq;
+
 	ret = ksz9477_switch_register(dev);
 
 	/* Main DSA driver may not be started yet. */
drivers/net/dsa/microchip/ksz9477_main.c +68 -0

95 lines not on this page · raw message

drivers/net/dsa/microchip/ksz9477_spi.c +2 -0
index 15bc11b3cda4..fc0ac9e2c56d 100644
@@ -48,6 +48,8 @@ static int ksz9477_spi_probe(struct spi_device *spi)
 	if (spi->dev.platform_data)
 		dev->pdata = spi->dev.platform_data;
 
+	dev->irq = spi->irq;
+
 	/* setup spi */
 	spi->mode = SPI_MODE_3;
 	ret = spi_setup(spi);
drivers/net/dsa/microchip/ksz_common.h +1 -0
index cf866e48ff66..5df4a7f9df02 100644
@@ -55,6 +55,7 @@ struct ksz_device {
 
 	struct device *dev;
 	struct regmap *regmap[3];
+	int irq;
 
 	void *priv;
 
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#5 lore raw

PATCH v4 5/9 net: dsa: microchip: ksz9477: add Posix clock support for chip PTP clock

In reply to Christian Eggers

Implement routines (adjfine, adjtime, gettime and settime) for manipulating the chip's PTP clock.

---
 drivers/net/dsa/microchip/Kconfig        |   8 +
 drivers/net/dsa/microchip/Makefile       |   1 +
 drivers/net/dsa/microchip/ksz9477_i2c.c  |   2 +-
 drivers/net/dsa/microchip/ksz9477_main.c |  17 ++
 drivers/net/dsa/microchip/ksz9477_ptp.c  | 308 +++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz9477_ptp.h  |  27 ++
 drivers/net/dsa/microchip/ksz9477_spi.c  |   2 +-
 drivers/net/dsa/microchip/ksz_common.h   |   8 +
 8 files changed, 371 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/dsa/microchip/ksz9477_ptp.c
 create mode 100644 drivers/net/dsa/microchip/ksz9477_ptp.h
drivers/net/dsa/microchip/Kconfig +8 -0
index 4ec6a47b7f72..7a4e06bab238 100644
@@ -24,6 +24,14 @@ config NET_DSA_MICROCHIP_KSZ9477_SPI
 	help
 	  Select to enable support for registering switches configured through SPI.
 
+config NET_DSA_MICROCHIP_KSZ9477_PTP
+	bool "PTP support for Microchip KSZ9477 series"
+	depends on NET_DSA_MICROCHIP_KSZ9477
+	depends on PTP_1588_CLOCK
+	help
+	  Say Y to enable PTP hardware timestamping on Microchip KSZ switch
+	  chips that support it.
+
 menuconfig NET_DSA_MICROCHIP_KSZ8795
 	tristate "Microchip KSZ8795 series switch support"
 	depends on NET_DSA
drivers/net/dsa/microchip/Makefile +1 -0
index c5cc1d5dea06..35c4356bad65 100644
@@ -2,6 +2,7 @@
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)	+= ksz_common.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477)		+= ksz9477.o
 ksz9477-objs := ksz9477_main.o
+ksz9477-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_PTP)	+= ksz9477_ptp.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C)	+= ksz9477_i2c.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI)	+= ksz9477_spi.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795)		+= ksz8795.o
drivers/net/dsa/microchip/ksz9477_i2c.c +1 -1
index 4ed1f503044a..315eb24c444d 100644
@@ -58,7 +58,7 @@ static int ksz9477_i2c_remove(struct i2c_client *i2c)
 {
 	struct ksz_device *dev = i2c_get_clientdata(i2c);
 
-	ksz_switch_remove(dev);
+	ksz9477_switch_remove(dev);
 
 	return 0;
 }
drivers/net/dsa/microchip/ksz9477_main.c +17 -0
index fea5330ae894..b13e6129322b 100644
@@ -19,6 +19,7 @@
 
 #include "ksz9477_reg.h"
 #include "ksz_common.h"
+#include "ksz9477_ptp.h"
 
 /* Used with variable features to indicate capabilities. */
 #define GBIT_SUPPORT			BIT(0)
@@ -1699,10 +1700,26 @@ int ksz9477_switch_register(struct ksz_device *dev)
 			phy_remove_link_mode(phydev,
 					     ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
 	}
+
+	ret = ksz9477_ptp_init(dev);
+	if (ret)
+		goto error_switch_unregister;
+
+	return 0;
+
+error_switch_unregister:
+	ksz_switch_remove(dev);
 	return ret;
 }
 EXPORT_SYMBOL(ksz9477_switch_register);
 
+void ksz9477_switch_remove(struct ksz_device *dev)
+{
+	ksz9477_ptp_deinit(dev);
+	ksz_switch_remove(dev);
+}
+EXPORT_SYMBOL(ksz9477_switch_remove);
+
 MODULE_AUTHOR("Woojung Huh <[email protected]>");
 MODULE_DESCRIPTION("Microchip KSZ9477 Series Switch DSA Driver");
 MODULE_LICENSE("GPL");
drivers/net/dsa/microchip/ksz9477_ptp.c new file +308 -0

308 lines not on this page · raw message

drivers/net/dsa/microchip/ksz9477_ptp.h new file +27 -0
new file mode 100644
index 000000000000..0076538419fa
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Microchip KSZ9477 switch driver PTP routines
+ *
+ * Author: Christian Eggers <[email protected]>
+ *
+ * Copyright (c) 2020 ARRI Lighting
+ */
+
+#ifndef DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_
+#define DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_
+
+#include "ksz_common.h"
+
+#if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ9477_PTP)
+
+int ksz9477_ptp_init(struct ksz_device *dev);
+void ksz9477_ptp_deinit(struct ksz_device *dev);
+
+#else
+
+static inline int ksz9477_ptp_init(struct ksz_device *dev) { return 0; }
+static inline void ksz9477_ptp_deinit(struct ksz_device *dev) {}
+
+#endif
+
+#endif /* DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_ */
drivers/net/dsa/microchip/ksz9477_spi.c +1 -1
index fc0ac9e2c56d..8cd825a02bba 100644
@@ -72,7 +72,7 @@ static int ksz9477_spi_remove(struct spi_device *spi)
 	struct ksz_device *dev = spi_get_drvdata(spi);
 
 	if (dev)
-		ksz_switch_remove(dev);
+		ksz9477_switch_remove(dev);
 
 	return 0;
 }
drivers/net/dsa/microchip/ksz_common.h +8 -0
index 5df4a7f9df02..43dd66009482 100644
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/mutex.h>
 #include <linux/phy.h>
+#include <linux/ptp_clock_kernel.h>
 #include <linux/regmap.h>
 #include <net/dsa.h>
 
@@ -92,6 +93,12 @@ struct ksz_device {
 	u32 overrides;			/* chip functions set by user */
 	u16 host_mask;
 	u16 port_mask;
+
+#if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ9477_PTP)
+	struct ptp_clock *ptp_clock;
+	struct ptp_clock_info ptp_caps;
+	struct mutex ptp_mutex;		/* protects PTP related hardware */
+#endif
 };
 
 struct alu_struct {
@@ -147,6 +154,7 @@ void ksz_switch_remove(struct ksz_device *dev);
 
 int ksz8795_switch_register(struct ksz_device *dev);
 int ksz9477_switch_register(struct ksz_device *dev);
+void ksz9477_switch_remove(struct ksz_device *dev);
 
 void ksz_update_port_member(struct ksz_device *dev, int port);
 void ksz_init_mib_timer(struct ksz_device *dev);
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#6 lore raw

PATCH v4 6/9 net: ptp: add helper for one-step P2P clocks

In reply to Christian Eggers

For P2P delay measurement, the ingress time stamp of the PDelay_Req is required for the correction field of the PDelay_Resp. The application echoes back the correction field of the PDelay_Req when sending the PDelay_Resp.

Some hardware (like the ZHAW InES PTP time stamping IP core) subtracts the ingress timestamp autonomously from the correction field, so that the hardware only needs to add the egress timestamp on tx. Other hardware (like the Microchip KSZ9563) reports the ingress time stamp via an interrupt and requires that the software provides this time stamp via tail-tag on tx.

In order to avoid introducing a further application interface for this, the driver can simply emulate the behavior of the InES device and subtract the ingress time stamp in software from the correction field.

On egress, the correction field can either be kept as it is (and the time stamp field in the tail-tag is set to zero) or move the value from the correction field back to the tail-tag.

Changing the correction field requires updating the UDP checksum (if UDP is used as transport).

---
 include/linux/ptp_classify.h | 73 ++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
include/linux/ptp_classify.h +73 -0
index cc0da0b134a4..f19f2f6a9475 100644
@@ -10,8 +10,12 @@
 #ifndef _PTP_CLASSIFY_H_
 #define _PTP_CLASSIFY_H_
 
+#include <asm/unaligned.h>
 #include <linux/ip.h>
+#include <linux/ktime.h>
 #include <linux/skbuff.h>
+#include <linux/udp.h>
+#include <net/checksum.h>
 
 #define PTP_CLASS_NONE  0x00 /* not a PTP event message */
 #define PTP_CLASS_V1    0x01 /* protocol version 1 */
@@ -123,6 +127,67 @@ static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
 	return msgtype;
 }
 
+/**
+ * ptp_check_diff8 - Computes new checksum (when altering a 64-bit field)
+ * @old: old field value
+ * @new: new field value
+ * @oldsum: previous checksum
+ *
+ * This function can be used to calculate a new checksum when only a single
+ * field is changed. Similar as ip_vs_check_diff*() in ip_vs.h.
+ *
+ * Return: Updated checksum
+ */
+static inline __wsum ptp_check_diff8(__be64 old, __be64 new, __wsum oldsum)
+{
+	__be64 diff[2] = { ~old, new };
+
+	return csum_partial(diff, sizeof(diff), oldsum);
+}
+
+/**
+ * ptp_header_update_correction - Update PTP header's correction field
+ * @skb: packet buffer
+ * @type: type of the packet (see ptp_classify_raw())
+ * @hdr: ptp header
+ * @correction: new correction value
+ *
+ * This updates the correction field of a PTP header and updates the UDP
+ * checksum (if UDP is used as transport). It is needed for hardware capable of
+ * one-step P2P that does not already modify the correction field of Pdelay_Req
+ * event messages on ingress.
+ */
+static inline
+void ptp_header_update_correction(struct sk_buff *skb, unsigned int type,
+				  struct ptp_header *hdr, s64 correction)
+{
+	__be64 correction_old;
+	struct udphdr *uhdr;
+
+	/* previous correction value is required for checksum update. */
+	memcpy(&correction_old,  &hdr->correction, sizeof(correction_old));
+
+	/* write new correction value */
+	put_unaligned_be64((u64)correction, &hdr->correction);
+
+	switch (type & PTP_CLASS_PMASK) {
+	case PTP_CLASS_IPV4:
+	case PTP_CLASS_IPV6:
+		/* locate udp header */
+		uhdr = (struct udphdr *)((char *)hdr - sizeof(struct udphdr));
+		break;
+	default:
+		return;
+	}
+
+	/* update checksum */
+	uhdr->check = csum_fold(ptp_check_diff8(correction_old,
+						hdr->correction,
+						~csum_unfold(uhdr->check)));
+	if (!uhdr->check)
+		uhdr->check = CSUM_MANGLED_0;
+}
+
 void __init ptp_classifier_init(void);
 #else
 static inline void ptp_classifier_init(void)
@@ -145,5 +210,13 @@ static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
 	 */
 	return PTP_MSGTYPE_SYNC;
 }
+
+static inline
+void ptp_onestep_p2p_move_t2_to_correction(struct sk_buff *skb,
+					   unsigned int type,
+					   struct ptp_header *hdr,
+					   ktime_t t2)
+{
+}
 #endif
 #endif /* _PTP_CLASSIFY_H_ */
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#7 lore raw

PATCH v4 7/9 net: dsa: microchip: ksz9477: initial hardware time stamping support

In reply to Christian Eggers

Add control routines required for TX hardware time stamping.

The KSZ9563 only supports one step time stamping (HWTSTAMP_TX_ONESTEP_P2P), which requires linuxptp-2.0 or later.

Currently, only P2P delay measurement is supported. See patchwork discussion and comments in ksz9477_ptp_init() for details:
https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/

---
Changes in v4:
--------------
- Remove useless case statement
- Reviewed-by: Vladimir Oltean <[email protected]>

 drivers/net/dsa/microchip/ksz9477_main.c |   6 +
 drivers/net/dsa/microchip/ksz9477_ptp.c  | 186 +++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz9477_ptp.h  |  21 +++
 drivers/net/dsa/microchip/ksz_common.h   |   4 +
 4 files changed, 217 insertions(+)
drivers/net/dsa/microchip/ksz9477_main.c +6 -0
index b13e6129322b..b164605d1563 100644
@@ -1389,6 +1389,7 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.phy_read		= ksz9477_phy_read16,
 	.phy_write		= ksz9477_phy_write16,
 	.phylink_mac_link_down	= ksz_mac_link_down,
+	.get_ts_info		= ksz9477_ptp_get_ts_info,
 	.port_enable		= ksz_enable_port,
 	.get_strings		= ksz9477_get_strings,
 	.get_ethtool_stats	= ksz_get_ethtool_stats,
@@ -1409,6 +1410,11 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.port_mdb_del           = ksz9477_port_mdb_del,
 	.port_mirror_add	= ksz9477_port_mirror_add,
 	.port_mirror_del	= ksz9477_port_mirror_del,
+	.port_hwtstamp_get      = ksz9477_ptp_port_hwtstamp_get,
+	.port_hwtstamp_set      = ksz9477_ptp_port_hwtstamp_set,
+	.port_txtstamp          = NULL,
+	/* never defer rx delivery, tstamping is done via tail tagging */
+	.port_rxtstamp          = NULL,
 };
 
 static u32 ksz9477_get_port_addr(int port, int offset)
drivers/net/dsa/microchip/ksz9477_ptp.c +186 -0

215 lines not on this page · raw message

drivers/net/dsa/microchip/ksz9477_ptp.h +21 -0
index 0076538419fa..b599401812ae 100644
@@ -10,6 +10,8 @@
 #ifndef DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_
 #define DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_
 
+#include <linux/types.h>
+
 #include "ksz_common.h"
 
 #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ9477_PTP)
@@ -17,11 +19,30 @@
 int ksz9477_ptp_init(struct ksz_device *dev);
 void ksz9477_ptp_deinit(struct ksz_device *dev);
 
+int ksz9477_ptp_get_ts_info(struct dsa_switch *ds, int port,
+			    struct ethtool_ts_info *ts);
+int ksz9477_ptp_port_hwtstamp_get(struct dsa_switch *ds, int port,
+				  struct ifreq *ifr);
+int ksz9477_ptp_port_hwtstamp_set(struct dsa_switch *ds, int port,
+				  struct ifreq *ifr);
+
 #else
 
 static inline int ksz9477_ptp_init(struct ksz_device *dev) { return 0; }
 static inline void ksz9477_ptp_deinit(struct ksz_device *dev) {}
 
+static inline int ksz9477_ptp_get_ts_info(struct dsa_switch *ds, int port,
+					  struct ethtool_ts_info *ts)
+{ return -EOPNOTSUPP; }
+
+static inline int ksz9477_ptp_port_hwtstamp_get(struct dsa_switch *ds, int port,
+						struct ifreq *ifr)
+{ return -EOPNOTSUPP; }
+
+static inline int ksz9477_ptp_port_hwtstamp_set(struct dsa_switch *ds, int port,
+						struct ifreq *ifr)
+{ return -EOPNOTSUPP; }
+
 #endif
 
 #endif /* DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_ */
drivers/net/dsa/microchip/ksz_common.h +4 -0
index 43dd66009482..139e9b84290b 100644
@@ -41,6 +41,10 @@ struct ksz_port {
 
 	struct ksz_port_mib mib;
 	phy_interface_t interface;
+#if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ9477_PTP)
+	struct hwtstamp_config tstamp_config;
+	bool hwts_tx_en;
+#endif
 };
 
 struct ksz_device {
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#8 lore raw

PATCH v4 8/9 net: dsa: microchip: ksz9477: remaining hardware time stamping support

In reply to Christian Eggers

Add data path routines required for TX hardware time stamping.

PTP mode is enabled depending on the filter setup (changes tail tag). TX time stamps are reported via an interrupt / device registers whilst RX time stamps are reported via an additional tail tag.

One step TX time stamping of PDelay_Resp requires the RX time stamp from the associated PDelay_Req message. The user space PTP stack assumes that the RX time stamp has already been subtracted from the PDelay_Req correction field (as done by the ZHAW InES PTP time stamping core). It will echo back the value of the correction field in the PDelay_Resp message.

In order to be compatible to this already established interface, the KSZ9563 code emulates this behavior. When processing the PDelay_Resp message, the time stamp is moved back from the correction field to the tail tag, as the hardware generates an invalid UDP checksum if this field is negative.

Of course, the UDP checksums (if any) have to be corrected after this (for both directions).

Everything has been tested on a Microchip KSZ9563 switch.

---
Changes in v4:
--------------
- s/low active/active low/
- 80 chars per line
- Use IEEE 802.1AS mode (to suppress forwarding of PDelay messages)
- Enable/disable hardware timestaping at runtime (port_hwtstamp_set)
- Use mutex in port_hwtstamp_set
- Don't use port specific struct hwtstamp_config
- removed #ifdefs from tag_ksz.c
- Set port's tx_latency and rx_latency to 0
- added include/linux/dsa/ksz_common.h to MAINTAINERS

Quoted 5 lines · Vladimir Oltean

If you don't like the #ifdef's, I am not in love with them either. But maybe Christian is just optimizing too aggressively, and doesn't actually need to put those #ifdef's there and provide stub implementations, but could actually just leave the ksz9477_rcv_timestamp and ksz9477_xmit_timestamp always compiled-in, and "dead at runtime" in the case there is no PTP.

I removed the #ifdefs.

Quoted 12 lines

[...]
The thing is, ptp4l already has ingressLatency and egressLatency settings, and I would not be surprised if those config options would get extended to cover values at multiple link speeds.

In the general case, the ksz9477 MAC could be attached to any external PHY, having its own propagation delay characteristics, or any number of other things that cause clock domain crossings. I'm not sure how feasible it is for the kernel to abstract this away completely, and adjust timestamps automatically based on any and all combinations of MAC and PHY. Maybe this is just wishful thinking.

Quoted 9 lines

Oh, and by the way, Christian, I'm not even sure if you aren't in fact just beating around the bush with these tstamp_rx_latency_ns and tstamp_tx_latency_ns values? I mean, the switch adds the latency value to the timestamps. And you, from the driver, read the value of the register, so you can subtract the value from the timestamp, to compensate for its correction. So, all in all, there is no net latency compensation seen by the outside world?! If that is the case, can't you just set the latency registers to zero, do your compensation from the application stack and call it a day?

At first I thought that I have to move these values to ptp4l.conf. But after setting the hardware registers to zero, it turned out, that I also have to use zero values in ptp4l.conf. So you are right.

Quoted 11 lines · Vladimir Oltean
Quoted 3 lines · Christian Eggers

please let me know, how I shall finally implement this. Enabling the PTP mode on the switch and sending the extra 4 byte tail on tx must be done in sync. Currently, both simply depends on the PTP define.

I, too, would prefer that the reconfiguration is done at ioctl time. Distributions typically enable whatever kernel config options they can. However, for users, the behavior should not change. Therefore the tail tag should remain small even though the PTP kernel config option is enabled, as long as hardware timestamping has not been explicitly enabled.

I moved this to port_hwtstamp_set. But I am not sure whether enabling PTP mode should depend on tx_type or rx_filter.

Quoted 4 lines

[...]
When forwarding what packet? What profile are you testing with? What commands do you run?
A P2P capable switch should not forward Peer delay messages.

With the 802.1AS settings, no SYNC/Announce messages are forwarded anymore. Peer delay messages have never been forwarded.

 MAINTAINERS                              |   1 +
 drivers/net/dsa/microchip/ksz9477_main.c |  12 +-
 drivers/net/dsa/microchip/ksz9477_ptp.c  | 391 ++++++++++++++++++++++-
 drivers/net/dsa/microchip/ksz9477_ptp.h  |  14 +
 drivers/net/dsa/microchip/ksz_common.h   |   9 +-
 include/linux/dsa/ksz_common.h           |  70 ++++
 net/dsa/tag_ksz.c                        | 205 +++++++++++-
 7 files changed, 678 insertions(+), 24 deletions(-)
 create mode 100644 include/linux/dsa/ksz_common.h
MAINTAINERS +1 -0
index 331fa2594f00..7ed88627c8f4 100644
@@ -11491,6 +11491,7 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml
 F:	drivers/net/dsa/microchip/*
+F:	include/linux/dsa/ksz_common.h
 F:	include/linux/platform_data/microchip-ksz.h
 F:	net/dsa/tag_ksz.c
 
drivers/net/dsa/microchip/ksz9477_main.c +8 -4
index b164605d1563..cc7a069877e3 100644
@@ -1412,7 +1412,7 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.port_mirror_del	= ksz9477_port_mirror_del,
 	.port_hwtstamp_get      = ksz9477_ptp_port_hwtstamp_get,
 	.port_hwtstamp_set      = ksz9477_ptp_port_hwtstamp_set,
-	.port_txtstamp          = NULL,
+	.port_txtstamp          = ksz9477_ptp_port_txtstamp,
 	/* never defer rx delivery, tstamping is done via tail tagging */
 	.port_rxtstamp          = NULL,
 };
@@ -1541,6 +1541,7 @@ static const struct ksz_chip_data ksz9477_switch_chips[] = {
 static irqreturn_t ksz9477_switch_irq_thread(int irq, void *dev_id)
 {
 	struct ksz_device *dev = dev_id;
+	irqreturn_t result = IRQ_NONE;
 	u32 data;
 	int port;
 	int ret;
@@ -1560,12 +1561,15 @@ static irqreturn_t ksz9477_switch_irq_thread(int irq, void *dev_id)
 		ret = ksz_read8(dev, PORT_CTRL_ADDR(port, REG_PORT_INT_STATUS),
 				&data8);
 		if (ret)
-			return IRQ_NONE;
+			return result;
 
-		/* ToDo: Add specific handling of port interrupts */
+		if (data8 & PORT_PTP_INT) {
+			if (ksz9477_ptp_port_interrupt(dev, port) != IRQ_NONE)
+				result = IRQ_HANDLED;
+		}
 	}
 
-	return IRQ_NONE;
+	return result;
 }
 
 static int ksz9477_enable_port_interrupts(struct ksz_device *dev, bool enable)
drivers/net/dsa/microchip/ksz9477_ptp.c +381 -10

518 lines not on this page · raw message

drivers/net/dsa/microchip/ksz9477_ptp.h +14 -0
index b599401812ae..2f7c4fa0753a 100644
@@ -10,6 +10,7 @@
 #ifndef DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_
 #define DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_
 
+#include <linux/irqreturn.h>
 #include <linux/types.h>
 
 #include "ksz_common.h"
@@ -19,18 +20,26 @@
 int ksz9477_ptp_init(struct ksz_device *dev);
 void ksz9477_ptp_deinit(struct ksz_device *dev);
 
+irqreturn_t ksz9477_ptp_port_interrupt(struct ksz_device *dev, int port);
+
 int ksz9477_ptp_get_ts_info(struct dsa_switch *ds, int port,
 			    struct ethtool_ts_info *ts);
 int ksz9477_ptp_port_hwtstamp_get(struct dsa_switch *ds, int port,
 				  struct ifreq *ifr);
 int ksz9477_ptp_port_hwtstamp_set(struct dsa_switch *ds, int port,
 				  struct ifreq *ifr);
+bool ksz9477_ptp_port_txtstamp(struct dsa_switch *ds, int port,
+			       struct sk_buff *clone, unsigned int type);
 
 #else
 
 static inline int ksz9477_ptp_init(struct ksz_device *dev) { return 0; }
 static inline void ksz9477_ptp_deinit(struct ksz_device *dev) {}
 
+static inline irqreturn_t ksz9477_ptp_port_interrupt(struct ksz_device *dev,
+						     int port)
+{ return IRQ_NONE; }
+
 static inline int ksz9477_ptp_get_ts_info(struct dsa_switch *ds, int port,
 					  struct ethtool_ts_info *ts)
 { return -EOPNOTSUPP; }
@@ -43,6 +52,11 @@ static inline int ksz9477_ptp_port_hwtstamp_set(struct dsa_switch *ds, int port,
 						struct ifreq *ifr)
 { return -EOPNOTSUPP; }
 
+static inline bool ksz9477_ptp_port_txtstamp(struct dsa_switch *ds, int port,
+					     struct sk_buff *clone,
+					     unsigned int type)
+{ return false; }
+
 #endif
 
 #endif /* DRIVERS_NET_DSA_MICROCHIP_KSZ9477_PTP_H_ */
drivers/net/dsa/microchip/ksz_common.h +8 -1
index 139e9b84290b..483a2f0e59d2 100644
@@ -7,8 +7,11 @@
 #ifndef __KSZ_COMMON_H
 #define __KSZ_COMMON_H
 
+#include <linux/completion.h>
+#include <linux/dsa/ksz_common.h>
 #include <linux/etherdevice.h>
 #include <linux/kernel.h>
+#include <linux/ktime.h>
 #include <linux/mutex.h>
 #include <linux/phy.h>
 #include <linux/ptp_clock_kernel.h>
@@ -42,7 +45,9 @@ struct ksz_port {
 	struct ksz_port_mib mib;
 	phy_interface_t interface;
 #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ9477_PTP)
-	struct hwtstamp_config tstamp_config;
+	struct ksz_port_ptp_shared ptp_shared;
+	ktime_t tstamp_xdelay;
+	struct completion tstamp_completion;
 	bool hwts_tx_en;
 #endif
 };
@@ -101,7 +106,9 @@ struct ksz_device {
 #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ9477_PTP)
 	struct ptp_clock *ptp_clock;
 	struct ptp_clock_info ptp_caps;
+	struct hwtstamp_config tstamp_config;
 	struct mutex ptp_mutex;		/* protects PTP related hardware */
+	struct ksz_device_ptp_shared ptp_shared;
 #endif
 };
 
include/linux/dsa/ksz_common.h new file +70 -0

70 lines not on this page · raw message

net/dsa/tag_ksz.c +196 -9

287 lines not on this page · raw message

Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
#9 lore raw

Re: [PATCH net-next v4 8/9] net: dsa: microchip: ksz9477: remaining hardware time stamping support

I love your patch! Yet something to improve:

Hi Christian,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Christian-Eggers/net-dsa-microchip-PTP-support-for-KSZ956x/20201202-002501
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git cb7fb043e69a109057fa94510ff5d5602207d548
config: powerpc64-randconfig-r026-20201201 (attached as .config)
compiler: powerpc-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/473200d809397b5bbb7f7d10a877f4be67cd3224
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christian-Eggers/net-dsa-microchip-PTP-support-for-KSZ956x/20201202-002501 git checkout 473200d809397b5bbb7f7d10a877f4be67cd3224
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

net/dsa/tag_ksz.c: In function 'ksz9477_xmit_timestamp':

>> net/dsa/tag_ksz.c:161:3: error: implicit declaration of function 'ptp_header_update_correction' [-Werror=implicit-function-declaration]
     161 |   ptp_header_update_correction(skb, ptp_type, ptp_hdr, 0);
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/ptp_header_update_correction +161 net/dsa/tag_ksz.c

115
116 /* Time stamp tag is only inserted if PTP is enabled in hardware. */
117 static void ksz9477_xmit_timestamp(struct sk_buff *skb)
118 {
119 struct sk_buff *clone = DSA_SKB_CB(skb)->clone;
120 struct ptp_header *ptp_hdr;
121 unsigned int ptp_type;
122 u32 tstamp_raw = 0;
123 u8 ptp_msg_type;
124 s64 correction;
125
126 if (!clone)
127 goto out_put_tag;
128
129 /* Use cached PTP type from ksz9477_ptp_port_txtstamp(). */
130 ptp_type = KSZ9477_SKB_CB(clone)->ptp_type;
131 if (ptp_type == PTP_CLASS_NONE)
132 goto out_put_tag;
133
134 ptp_hdr = ptp_parse_header(skb, ptp_type);
135 if (!ptp_hdr)
136 goto out_put_tag;
137
138 ptp_msg_type = KSZ9477_SKB_CB(clone)->ptp_msg_type;
139 if (ptp_msg_type != PTP_MSGTYPE_PDELAY_RESP)
140 goto out_put_tag;
141
142 correction = (s64)get_unaligned_be64(&ptp_hdr->correction);
143
144 /* For PDelay_Resp messages we will likely have a negative value in the
145 * correction field (see ksz9477_rcv()). The switch hardware cannot
146 * correctly update such values (produces an off by one error in the UDP
147 * checksum), so it must be moved to the time stamp field in the tail
148 * tag.
149 */
150 if (correction < 0) {
151 struct timespec64 ts;
152
153 /* Move ingress time stamp from PTP header's correction field to
154 * tail tag. Format of the correction filed is 48 bit ns + 16
155 * bit fractional ns.
156 */
157 ts = ns_to_timespec64(-correction >> 16);
158 tstamp_raw = ((ts.tv_sec & 3) << 30) | ts.tv_nsec;
159
160 /* Set correction field to 0 and update UDP checksum. */

 > 161			ptp_header_update_correction(skb, ptp_type, ptp_hdr, 0);

162 }
163
164 /* For PDelay_Resp messages, the clone is not required in
165 * skb_complete_tx_timestamp() and should be freed here.
166 */
167 kfree_skb(clone);
168 DSA_SKB_CB(skb)->clone = NULL;
169
170 out_put_tag:
171 put_unaligned_be32(tstamp_raw, skb_put(skb, KSZ9477_PTP_TAG_LEN));
172 }
173

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#10 lore raw

Re: [PATCH net-next v4 8/9] net: dsa: microchip: ksz9477: remaining hardware time stamping support

Quoted 23 lines · kernel test robot

Hi Christian,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Christian-Eggers/net-dsa-microchip-PTP-support-for-KSZ956x/20201202-002501
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git cb7fb043e69a109057fa94510ff5d5602207d548
config: powerpc64-randconfig-r026-20201201 (attached as .config)
compiler: powerpc-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/473200d809397b5bbb7f7d10a877f4be67cd3224
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christian-Eggers/net-dsa-microchip-PTP-support-for-KSZ956x/20201202-002501 git checkout 473200d809397b5bbb7f7d10a877f4be67cd3224
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc64

If you fix the issue, kindly add following tag as appropriate

Quoted 7 lines

All errors (new ones prefixed by >>):

net/dsa/tag_ksz.c: In function 'ksz9477_xmit_timestamp':

Quoted 1 line
Quoted 1 line

net/dsa/tag_ksz.c:161:3: error: implicit declaration of function 'ptp_header_update_correction' [-Werror=implicit-function-declaration]

     161 |   ptp_header_update_correction(skb, ptp_type, ptp_hdr, 0);
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

_
CONFIG_NET_DSA_TAG_KSZ must select CONFIG_NET_PTP_CLASSIFY. This is fixed in v5 (just being sent).

regards
Christian

Quoted 63 lines

vim +/ptp_header_update_correction +161 net/dsa/tag_ksz.c

   115
   116        /* Time stamp tag is only inserted if PTP is enabled in hardware. */
   117        static void ksz9477_xmit_timestamp(struct sk_buff *skb)
   118        {
   119                struct sk_buff *clone = DSA_SKB_CB(skb)->clone;
   120                struct ptp_header *ptp_hdr;
   121                unsigned int ptp_type;
   122                u32 tstamp_raw = 0;
   123                u8 ptp_msg_type;
   124                s64 correction;
   125
   126                if (!clone)
   127                        goto out_put_tag;
   128
   129                /* Use cached PTP type from ksz9477_ptp_port_txtstamp().  */
   130                ptp_type = KSZ9477_SKB_CB(clone)->ptp_type;
   131                if (ptp_type == PTP_CLASS_NONE)
   132                        goto out_put_tag;
   133
   134                ptp_hdr = ptp_parse_header(skb, ptp_type);
   135                if (!ptp_hdr)
   136                        goto out_put_tag;
   137
   138                ptp_msg_type = KSZ9477_SKB_CB(clone)->ptp_msg_type;
   139                if (ptp_msg_type != PTP_MSGTYPE_PDELAY_RESP)
   140                        goto out_put_tag;
   141
   142                correction = (s64)get_unaligned_be64(&ptp_hdr->correction);
   143
   144                /* For PDelay_Resp messages we will likely have a negative value in the
   145                 * correction field (see ksz9477_rcv()). The switch hardware cannot
   146                 * correctly update such values (produces an off by one error in the UDP
   147                 * checksum), so it must be moved to the time stamp field in the tail
   148                 * tag.
   149                 */
   150                if (correction < 0) {
   151                        struct timespec64 ts;
   152
   153                        /* Move ingress time stamp from PTP header's correction field to
   154                         * tail tag. Format of the correction filed is 48 bit ns + 16
   155                         * bit fractional ns.
   156                         */
   157                        ts = ns_to_timespec64(-correction >> 16);
   158                        tstamp_raw = ((ts.tv_sec & 3) << 30) | ts.tv_nsec;
   159
   160                        /* Set correction field to 0 and update UDP checksum.  */
Quoted 1 line

161 ptp_header_update_correction(skb, ptp_type, ptp_hdr, 0);

162 }
163
164 /* For PDelay_Resp messages, the clone is not required in
165 * skb_complete_tx_timestamp() and should be freed here.
166 */

   167                kfree_skb(clone);
   168                DSA_SKB_CB(skb)->clone = NULL;
   169
   170        out_put_tag:
   171                put_unaligned_be32(tstamp_raw, skb_put(skb, KSZ9477_PTP_TAG_LEN));
   172        }
   173
Quoted 4 lines

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

________________________________
[http://assets.arri.com/media/sign/2020-04-03-E-mail-signature-Stellar2_V1.jpg] <https://microsites.arri.com/stellar/>

Get all the latest information from www.arri.com<https://www.arri.com/>, Facebook<https://www.facebook.com/TeamARRI>, Twitter<https://twitter.com/ARRIChannel>, Instagram<https://instagram.com/arri> and YouTube<https://www.youtube.com/user/ARRIChannel>.

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRA 57918 Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRB 54477 Geschäftsführer: Dr. Michael Neuhäuser; Stephan Schenk; Walter Trauninger; Markus Zeiler

#11 lore raw

PATCH v4 9/9 net: dsa: microchip: ksz9477: add periodic output support

In reply to Christian Eggers

The KSZ9563 has a Trigger Output Unit (TOU) which can be used to generate periodic signals.

The pulse length can be altered via a device attribute.

Tested on a Microchip KSZ9563 switch.

---
Changes in v4:
--------------
- 80 chars per line
- reverse christmas tree
- Set default pulse width for perout pulse to 50% (max. 125ms)
- reject unsupported flags for perout_request

Quoted 7 lines · Vladimir Oltean
Quoted 5 lines · Christian Eggers

static int ksz9477_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)

(quoted diff) +0 -0
@@ -241,6 +256,15 @@ static int ksz9477_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
 	case KSZ_PTP_TOU_IDLE:
 		break;
 
Quoted 5 lines

Review static int ksz9477_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) · line 260

Quoted 2 lines
(quoted diff) +2 -0
+	case KSZ_PTP_TOU_PEROUT:
+		dev_info(dev->dev, "Restarting periodic output signal\n");

Isn't this a bit too verbose, or is there something for the user to be concerned about?

In my setup this message appears only once after ptp4l has been started. Shall I remove it?

Quoted 1 line

Watch out for 80 characters, please!

A few long line are left (for instance ksz9477_ptp_enable_perout). Please let me know how I shall wrap them.

Quoted 6 lines
Quoted 6 lines
(quoted diff) +6 -0
+	if (perout_request->flags & PTP_PEROUT_DUTY_CYCLE) {
+		u64 value = perout_request->on.sec * NSEC_PER_SEC +
+			    perout_request->on.nsec;
+
+		ret = ksz9477_ptp_tou_pulse_verify(value);
+		if (ret)
Quoted 8 lines

Review static int ksz9477_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) · line 270

Quoted 4 lines
(quoted diff) +4 -0
+			return ret;
+
+		dev->ptp_perout_pulse_width_ns = value;
+	}

It is not guaranteed that user space will set this flag. Shouldn't you assign a default value for the pulse width? I don't know, half the period should be a good default.

Yes I should. The hardware support a maximum "duty cycle" of a little bit more than 125 ms. As PPS signals often have a 125 ms high period, I use this duration as the maximum.

Quoted 11 lines

Review static int ksz9477_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)

Quoted 8 lines
(quoted diff) +8 -0
+	/* Check error flag:
+	 * - the ACTIVE flag is NOT cleared an error!
+	 */
+	ret = ksz_read32(dev, REG_PTP_TRIG_STATUS__4, &gpio_stat0);
+	if (ret)
+		return ret;
+
+	if (gpio_stat0 & (1 << (0 + TRIG_ERROR_S))) {

What is the role of this "0 +" term here?

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+		dev_err(dev->dev, "%s: Trigger unit0 error!\n", __func__);

This is the index of the used trigger unit.

 drivers/net/dsa/microchip/ksz9477_ptp.c | 357 +++++++++++++++++++++++-
 drivers/net/dsa/microchip/ksz9477_ptp.h |   4 +
 drivers/net/dsa/microchip/ksz_common.h  |  10 +
 3 files changed, 369 insertions(+), 2 deletions(-)
drivers/net/dsa/microchip/ksz9477_ptp.c +355 -2
index e68c9fc8e679..c3a0275e444a 100644
@@ -19,6 +19,140 @@
 #define KSZ_PTP_INC_NS 40  /* HW clock is incremented every 40 ns (by 40) */
 #define KSZ_PTP_SUBNS_BITS 32  /* Number of bits in sub-nanoseconds counter */
 
+/* Shared register access routines (Trigger Output Unit) */
+
+static int ksz9477_ptp_tou_reset(struct ksz_device *dev, unsigned int unit)
+{
+	u32 ctrl_stat, data;
+	int ret;
+
+	/* Reset trigger unit (clears TRIGGER_EN, but not GPIOSTATx) */
+	ret = ksz_read32(dev, REG_PTP_CTRL_STAT__4, &ctrl_stat);
+	if (ret)
+		return ret;
+
+	ctrl_stat |= TRIG_RESET;
+
+	ret = ksz_write32(dev, REG_PTP_CTRL_STAT__4, ctrl_stat);
+	if (ret)
+		return ret;
+
+	/* Clear DONE */
+	data = 1 << (unit + TRIG_DONE_S);
+	ret = ksz_write32(dev, REG_PTP_TRIG_STATUS__4, data);
+	if (ret)
+		return ret;
+
+	/* Clear IRQ */
+	data = 1 << (unit + TRIG_INT_S);
+	ret = ksz_write32(dev, REG_PTP_INT_STATUS__4, data);
+	if (ret)
+		return ret;
+
+	/* Clear reset and set GPIO direction */
+	ctrl_stat &= ~TRIG_ENABLE;  /* clear cached bit :-) */
+	ctrl_stat &= ~TRIG_RESET;
+
+	ret = ksz_write32(dev, REG_PTP_CTRL_STAT__4, ctrl_stat);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int ksz9477_ptp_tou_cycle_width_set(struct ksz_device *dev, u32 width_ns)
+{
+	int ret;
+
+	ret = ksz_write32(dev, REG_TRIG_CYCLE_WIDTH, width_ns);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int ksz9477_ptp_tou_cycle_count_set(struct ksz_device *dev, u16 count)
+{
+	u32 data;
+	int ret;
+
+	ret = ksz_read32(dev, REG_TRIG_CYCLE_CNT, &data);
+	if (ret)
+		return ret;
+
+	data &= ~(TRIG_CYCLE_CNT_M << TRIG_CYCLE_CNT_S);
+	data |= (count & TRIG_CYCLE_CNT_M) << TRIG_CYCLE_CNT_S;
+
+	ret = ksz_write32(dev, REG_TRIG_CYCLE_CNT, data);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int ksz9477_ptp_tou_pulse_verify(u64 pulse_ns)
+{
+	u32 data;
+
+	if (pulse_ns & 0x3)
+		return -EINVAL;
+
+	data = (pulse_ns / 8);
+	if (data != (data & TRIG_PULSE_WIDTH_M))
+		return -ERANGE;
+
+	return 0;
+}
+
+static int ksz9477_ptp_tou_pulse_set(struct ksz_device *dev, u32 pulse_ns)
+{
+	u32 data;
+
+	data = (pulse_ns / 8);
+
+	return ksz_write32(dev, REG_TRIG_PULSE_WIDTH__4, data);
+}
+
+static int ksz9477_ptp_tou_target_time_set(struct ksz_device *dev, struct timespec64 const *ts)
+{
+	int ret;
+
+	/* Hardware has only 32 bit */
+	if ((ts->tv_sec & 0xffffffff) != ts->tv_sec)
+		return -EINVAL;
+
+	ret = ksz_write32(dev, REG_TRIG_TARGET_NANOSEC, ts->tv_nsec);
+	if (ret)
+		return ret;
+
+	ret = ksz_write32(dev, REG_TRIG_TARGET_SEC, ts->tv_sec);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int ksz9477_ptp_tou_start(struct ksz_device *dev, u32 *ctrl_stat_)
+{
+	u32 ctrl_stat;
+	int ret;
+
+	ret = ksz_read32(dev, REG_PTP_CTRL_STAT__4, &ctrl_stat);
+	if (ret)
+		return ret;
+
+	ctrl_stat |= TRIG_ENABLE;
+
+	ret = ksz_write32(dev, REG_PTP_CTRL_STAT__4, ctrl_stat);
+	if (ret)
+		return ret;
+
+	if (ctrl_stat_)
+		*ctrl_stat_ = ctrl_stat;
+
+	return 0;
+}
+
 /* Posix clock support */
 
 static int ksz9477_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
@@ -76,6 +210,8 @@ static int ksz9477_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 	return ret;
 }
 
+static int ksz9477_ptp_restart_perout(struct ksz_device *dev);
+
 static int ksz9477_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
 {
 	struct ksz_device *dev = container_of(ptp, struct ksz_device, ptp_caps);
@@ -115,6 +251,20 @@ static int ksz9477_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
 	if (ret)
 		goto error_return;
 
+	switch (dev->ptp_tou_mode) {
+	case KSZ_PTP_TOU_IDLE:
+		break;
+
+	case KSZ_PTP_TOU_PEROUT:
+		dev_info(dev->dev, "Restarting periodic output signal\n");
+
+		ret = ksz9477_ptp_restart_perout(dev);
+		if (ret)
+			goto error_return;
+
+		break;
+	}
+
 	spin_lock_bh(&ptp_shared->ptp_clock_lock);
 	ptp_shared->ptp_clock_time = timespec64_add(ptp_shared->ptp_clock_time,
 						    delta64);
@@ -218,6 +368,20 @@ static int ksz9477_ptp_settime(struct ptp_clock_info *ptp,
 	if (ret)
 		goto error_return;
 
+	switch (dev->ptp_tou_mode) {
+	case KSZ_PTP_TOU_IDLE:
+		break;
+
+	case KSZ_PTP_TOU_PEROUT:
+		dev_info(dev->dev, "Restarting periodic output signal\n");
+
+		ret = ksz9477_ptp_restart_perout(dev);
+		if (ret)
+			goto error_return;
+
+		break;
+	}
+
 	spin_lock_bh(&ptp_shared->ptp_clock_lock);
 	ptp_shared->ptp_clock_time = *ts;
 	spin_unlock_bh(&ptp_shared->ptp_clock_lock);
@@ -227,10 +391,199 @@ static int ksz9477_ptp_settime(struct ptp_clock_info *ptp,
 	return ret;
 }
 
+static int ksz9477_ptp_configure_perout(struct ksz_device *dev,
+					u32 cycle_width_ns, u16 cycle_count,
+					u32 pulse_width_ns,
+					struct timespec64 const *target_time)
+{
+	u32 trig_ctrl;
+	int ret;
+
+	/* Enable notify, set rising edge, set periodic pattern */
+	trig_ctrl = TRIG_NOTIFY | (TRIG_POS_PERIOD << TRIG_PATTERN_S);
+	ret = ksz_write32(dev, REG_TRIG_CTRL__4, trig_ctrl);
+	if (ret)
+		return ret;
+
+	ret = ksz9477_ptp_tou_cycle_width_set(dev, cycle_width_ns);
+	if (ret)
+		return ret;
+
+	ksz9477_ptp_tou_cycle_count_set(dev,  cycle_count);
+	if (ret)
+		return ret;
+
+	ret = ksz9477_ptp_tou_pulse_set(dev, pulse_width_ns);
+	if (ret)
+		return ret;
+
+	ret = ksz9477_ptp_tou_target_time_set(dev, target_time);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+#define KSZ9477_PEROUT_VALID_FLAGS ( \
+	PTP_PEROUT_DUTY_CYCLE \
+)
+
+static int ksz9477_ptp_enable_perout(struct ksz_device *dev,
+				     struct ptp_perout_request const *perout_request,
+				     int on)
+{
+	u64 cycle_width_ns;
+	u64 pulse_width_ns;
+	u32 gpio_stat0;
+	int ret;
+
+	if (perout_request->flags & ~KSZ9477_PEROUT_VALID_FLAGS)
+		return -EINVAL;
+
+	if (dev->ptp_tou_mode != KSZ_PTP_TOU_PEROUT &&
+	    dev->ptp_tou_mode != KSZ_PTP_TOU_IDLE)
+		return -EBUSY;
+
+	ret = ksz9477_ptp_tou_reset(dev, 0);
+	if (ret)
+		return ret;
+
+	if (!on) {
+		dev->ptp_tou_mode = KSZ_PTP_TOU_IDLE;
+		return 0;  /* success */
+	}
+
+	dev->ptp_perout_target_time_first.tv_sec  = perout_request->start.sec;
+	dev->ptp_perout_target_time_first.tv_nsec = perout_request->start.nsec;
+
+	dev->ptp_perout_period.tv_sec = perout_request->period.sec;
+	dev->ptp_perout_period.tv_nsec = perout_request->period.nsec;
+
+	cycle_width_ns = timespec64_to_ns(&dev->ptp_perout_period);
+	if ((cycle_width_ns & GENMASK(31, 0)) != cycle_width_ns)
+		return -EINVAL;
+
+	if (perout_request->flags & PTP_PEROUT_DUTY_CYCLE)
+		pulse_width_ns = perout_request->on.sec * NSEC_PER_SEC +
+				 perout_request->on.nsec;
+
+	else
+		/* Use a duty cycle of 50%. Maximum pulse width supported by the
+		 * hardware is a little bit more than 125 ms.
+		 */
+		pulse_width_ns = min_t(u64,
+				       (perout_request->period.sec * NSEC_PER_SEC
+					+ perout_request->period.nsec) / 2
+				       / 8 * 8,
+				       125000000LL);
+
+	ret = ksz9477_ptp_tou_pulse_verify(pulse_width_ns);
+	if (ret)
+		return ret;
+
+	dev->ptp_perout_pulse_width_ns = pulse_width_ns;
+
+	ret = ksz9477_ptp_configure_perout(dev, cycle_width_ns,
+					   dev->ptp_perout_cycle_count,
+					   dev->ptp_perout_pulse_width_ns,
+					   &dev->ptp_perout_target_time_first);
+	if (ret)
+		return ret;
+
+	/* Activate trigger unit */
+	ret = ksz9477_ptp_tou_start(dev, NULL);
+	if (ret)
+		return ret;
+
+	/* Check error flag:
+	 * - the ACTIVE flag is NOT cleared an error!
+	 */
+	ret = ksz_read32(dev, REG_PTP_TRIG_STATUS__4, &gpio_stat0);
+	if (ret)
+		return ret;
+
+	if (gpio_stat0 & (1 << (0 + TRIG_ERROR_S))) {
+		dev_err(dev->dev, "%s: Trigger unit0 error!\n", __func__);
+		ret = -EIO;
+		/* Unit will be reset on next access */
+		return ret;
+	}
+
+	dev->ptp_tou_mode = KSZ_PTP_TOU_PEROUT;
+	return 0;
+}
+
+static int ksz9477_ptp_restart_perout(struct ksz_device *dev)
+{
+	s64 now_ns, first_ns, period_ns, next_ns;
+	struct timespec64 now;
+	unsigned int count;
+	int ret;
+
+	ret = _ksz9477_ptp_gettime(dev, &now);
+	if (ret)
+		return ret;
+
+	now_ns = timespec64_to_ns(&now);
+	first_ns = timespec64_to_ns(&dev->ptp_perout_target_time_first);
+
+	/* Calculate next perout event based on start time and period */
+	period_ns = timespec64_to_ns(&dev->ptp_perout_period);
+
+	if (first_ns < now_ns) {
+		count = div_u64(now_ns - first_ns, period_ns);
+		next_ns = first_ns + count * period_ns;
+	} else {
+		next_ns = first_ns;
+	}
+
+	/* Ensure 100 ms guard time prior next event */
+	while (next_ns < now_ns + 100000000)
+		next_ns += period_ns;
+
+	/* Restart periodic output signal */
+	{
+		struct timespec64 next = ns_to_timespec64(next_ns);
+		struct ptp_perout_request perout_request = {
+			.start = {
+				.sec  = next.tv_sec,
+				.nsec = next.tv_nsec
+			},
+			.period = {
+				.sec  = dev->ptp_perout_period.tv_sec,
+				.nsec = dev->ptp_perout_period.tv_nsec
+			},
+			.index = 0,
+			.flags = 0,  /* keep current values */
+		};
+		ret = ksz9477_ptp_enable_perout(dev, &perout_request, 1);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int ksz9477_ptp_enable(struct ptp_clock_info *ptp,
 			      struct ptp_clock_request *req, int on)
 {
-	return -EOPNOTSUPP;
+	struct ksz_device *dev = container_of(ptp, struct ksz_device, ptp_caps);
+	int ret;
+
+	switch (req->type) {
+	case PTP_CLK_REQ_PEROUT: {
+		struct ptp_perout_request const *perout_request = &req->perout;
+
+		mutex_lock(&dev->ptp_mutex);
+		ret = ksz9477_ptp_enable_perout(dev, perout_request, on);
+		mutex_unlock(&dev->ptp_mutex);
+		return ret;
+	}
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 static long ksz9477_ptp_do_aux_work(struct ptp_clock_info *ptp)
@@ -592,7 +945,7 @@ int ksz9477_ptp_init(struct ksz_device *dev)
 	dev->ptp_caps.max_adj     = 6249999;
 	dev->ptp_caps.n_alarm     = 0;
 	dev->ptp_caps.n_ext_ts    = 0;  /* currently not implemented */
-	dev->ptp_caps.n_per_out   = 0;
+	dev->ptp_caps.n_per_out   = 1;
 	dev->ptp_caps.pps         = 0;
 	dev->ptp_caps.adjfine     = ksz9477_ptp_adjfine;
 	dev->ptp_caps.adjtime     = ksz9477_ptp_adjtime;
drivers/net/dsa/microchip/ksz9477_ptp.h +4 -0
index 2f7c4fa0753a..4d20decf0ad7 100644
@@ -20,6 +20,7 @@
 int ksz9477_ptp_init(struct ksz_device *dev);
 void ksz9477_ptp_deinit(struct ksz_device *dev);
 
+irqreturn_t ksz9477_ptp_interrupt(struct ksz_device *dev);
 irqreturn_t ksz9477_ptp_port_interrupt(struct ksz_device *dev, int port);
 
 int ksz9477_ptp_get_ts_info(struct dsa_switch *ds, int port,
@@ -36,6 +37,9 @@ bool ksz9477_ptp_port_txtstamp(struct dsa_switch *ds, int port,
 static inline int ksz9477_ptp_init(struct ksz_device *dev) { return 0; }
 static inline void ksz9477_ptp_deinit(struct ksz_device *dev) {}
 
+static inline irqreturn_t ksz9477_ptp_interrupt(struct ksz_device *dev)
+{ return IRQ_NONE; }
+
 static inline irqreturn_t ksz9477_ptp_port_interrupt(struct ksz_device *dev,
 						     int port)
 { return IRQ_NONE; }
drivers/net/dsa/microchip/ksz_common.h +10 -0
index 483a2f0e59d2..c9495c92a32d 100644
@@ -52,6 +52,11 @@ struct ksz_port {
 #endif
 };
 
+enum ksz_ptp_tou_mode {
+	KSZ_PTP_TOU_IDLE,
+	KSZ_PTP_TOU_PEROUT,
+};
+
 struct ksz_device {
 	struct dsa_switch *ds;
 	struct ksz_platform_data *pdata;
@@ -109,6 +114,11 @@ struct ksz_device {
 	struct hwtstamp_config tstamp_config;
 	struct mutex ptp_mutex;		/* protects PTP related hardware */
 	struct ksz_device_ptp_shared ptp_shared;
+	enum ksz_ptp_tou_mode ptp_tou_mode;
+	struct timespec64 ptp_perout_target_time_first;  /* start of first perout pulse */
+	struct timespec64 ptp_perout_period;
+	u32 ptp_perout_pulse_width_ns;
+	u16 ptp_perout_cycle_count;
 #endif
 };
 
Signature · 8 lines
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler