netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000
@ 2023-06-16 10:04 alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 1/8] net: stmmac: add IP-specific callbacks for auxiliary snapshot alexis.lothore
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

While trying to use the recently implemented auxiliary snapshot feature
([1]) on Cyclone V platform (embedding DWMAC1000 IP), I realized that some
parts are too tightly coupled to GMAC4 version of the IP. For example,
timestamp_interrupt function in stmmac_hwtstamp.c reads some timestamp
status (GMAC_TIMESTAMP_STATUS), which offset is relevant for GMAC4 (ptpaddr
+ 0x20), but not for GMAC3 (which should be ptpaddr + 0x28).
Another example is that auxiliary snapshot trigger configuration is done in
a dedicated register for GMAC4, while it is in the general Timestamp
control register for DWMAC1000.

This series proposes to split those too specific parts in each IP variant
file. DWMAC1000 mapping is based on Cyclone V HPS register map ([2]) while
GMAC4 mapping has been checked based on some Elkhart Lake range processors
mapping ([3])

One point I am not sure about is for all other variants: sun8i-dwmac,
dwxgmac2 and dwmac100. I have no clue about registers layout for those
platforms. I then had to possible approaches to enable feature on
DWMAC1000:
- ensure that current behaviour is preserved for dwxgmac2, sun8i-dwmac and
  dwmac100; keep auxiliary snapshot feature in stmmac_ptp.c and add
  dwmac1000 behaviour as an "exception"
- assume auxiliary snaspshots controls are different for each, then move the
  controls in each IP version file (XXXX_core.c)
I felt like stmmac_ptp.c should remain independant from the IP version, so
I chose the second option, but since I do not know about other versions
layout (and do not have the hardware), I did not wire "blindly" the
feature on those platform.
Please let me know if I am wrong and/or if I should come with a more
conservative approach (ie first version)

Tested on Cyclone V with testptp

[1] https://lore.kernel.org/netdev/20210414001617.3490-1-vee.khee.wong@linux.intel.com/
[2] https://cdrdv2.intel.com/v1/dl/getContent/666962?fileName=cv_5v4-683126-666962.pdf
[3] https://cdrdv2.intel.com/v1/dl/getContent/636722?fileName=636722_EHL+Datasheet+V2+Book+2_rev003.pdf

Alexis Lothoré (8):
  net: stmmac: add IP-specific callbacks for auxiliary snapshot
  net: stmmac: populate dwmac4 callbacks for auxiliary snapshots
  net: stmmac: move PTP interrupt handling to IP-specific DWMAC file
  net: stmmac: move common defines in stmmac_ptp.h
  net: stmmac: set number of snapshot external triggers for GMAC3
  net: stmmac: introduce setter/getter for timestamp configuration
  net: stmmac: do not overwrite other flags when writing timestamp
    control
  net: stmmac: enable timestamp external trigger for dwmac1000

 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   |  2 +
 .../net/ethernet/stmicro/stmmac/dwmac1000.h   | 12 ++-
 .../ethernet/stmicro/stmmac/dwmac1000_core.c  | 83 ++++++++++++++++++
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h  | 29 +++++--
 .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 85 +++++++++++++++++++
 drivers/net/ethernet/stmicro/stmmac/hwif.h    | 17 +++-
 .../ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 62 ++------------
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 14 +--
 .../net/ethernet/stmicro/stmmac/stmmac_ptp.c  | 29 ++-----
 .../net/ethernet/stmicro/stmmac/stmmac_ptp.h  | 26 +-----
 10 files changed, 246 insertions(+), 113 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH net-next 1/8] net: stmmac: add IP-specific callbacks for auxiliary snapshot
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 2/8] net: stmmac: populate dwmac4 callbacks for auxiliary snapshots alexis.lothore
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

Since auxiliary snapshots configuration registers may be different
depending the DWMAC IP, we need a specific set of callbacks to
- configure timestamp snapshot triggers
- clear the snapshots FIFO

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/hwif.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index 6ee7cf07cfd7..d0b2f13510aa 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -419,6 +419,10 @@ struct stmmac_ops {
 	void (*fpe_send_mpacket)(void __iomem *ioaddr,
 				 enum stmmac_mpacket_type type);
 	int (*fpe_irq_status)(void __iomem *ioaddr, struct net_device *dev);
+	/* Auxiliary snapshots */
+	void (*extts_configure)(void __iomem *ioaddr, int ext_snapshot_num,
+				bool on, struct net_device *dev);
+	int (*clear_snapshot_fifo)(void __iomem *ioaddr);
 };
 
 #define stmmac_core_init(__priv, __args...) \
@@ -523,6 +527,10 @@ struct stmmac_ops {
 	stmmac_do_void_callback(__priv, mac, fpe_send_mpacket, __args)
 #define stmmac_fpe_irq_status(__priv, __args...) \
 	stmmac_do_callback(__priv, mac, fpe_irq_status, __args)
+#define stmmac_extts_configure(__priv, __args...) \
+	stmmac_do_void_callback(__priv, mac, extts_configure, __args)
+#define stmmac_clear_snapshot_fifo(__priv, __args...) \
+	stmmac_do_callback(__priv, mac, clear_snapshot_fifo, __args)
 
 /* PTP and HW Timer helpers */
 struct stmmac_hwtimestamp {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 2/8] net: stmmac: populate dwmac4 callbacks for auxiliary snapshots
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 1/8] net: stmmac: add IP-specific callbacks for auxiliary snapshot alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file alexis.lothore
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

Contrary to generic PTP registers (timestamp control, system time, time
update, addend, etc), auxiliary snapshots registers addresses and layout
differ depending on exact DWMAC IP. Current implementation matches register
layout for DWMAC4, so move current behaviour from stmmac_ptp.c to
dwmac4_core.c. Wire those callbacks for all DWMAC4 versions.

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h  | 22 ++++++++++++
 .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 34 +++++++++++++++++++
 .../net/ethernet/stmicro/stmmac/stmmac_ptp.c  | 24 +++----------
 .../net/ethernet/stmicro/stmmac/stmmac_ptp.h  | 19 -----------
 4 files changed, 60 insertions(+), 39 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index d3c5306f1c41..d249a68f6787 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -51,6 +51,7 @@
 #define GMAC_L3_ADDR0(reg)		(0x910 + (reg) * 0x30)
 #define GMAC_L3_ADDR1(reg)		(0x914 + (reg) * 0x30)
 #define GMAC_TIMESTAMP_STATUS		0x00000b20
+#define GMAC_AUXILIARY_CONTROL		0x00000b40	/* Auxiliary Control Reg */
 
 /* RX Queues Routing */
 #define GMAC_RXQCTRL_AVCPQ_MASK		GENMASK(2, 0)
@@ -580,6 +581,27 @@ static inline u32 mtl_low_credx_base_addr(const struct dwmac4_addrs *addrs,
 #define GMAC_PHYIF_CTRLSTATUS_SPEED_25		0x1
 #define GMAC_PHYIF_CTRLSTATUS_SPEED_2_5		0x0
 
+/* Auxiliary Control defines */
+#define	PTP_ACR_ATSFC		BIT(0)	/* Auxiliary Snapshot FIFO Clear */
+#define	PTP_ACR_ATSEN0		BIT(4)	/* Auxiliary Snapshot 0 Enable */
+#define	PTP_ACR_ATSEN1		BIT(5)	/* Auxiliary Snapshot 1 Enable */
+#define	PTP_ACR_ATSEN2		BIT(6)	/* Auxiliary Snapshot 2 Enable */
+#define	PTP_ACR_ATSEN3		BIT(7)	/* Auxiliary Snapshot 3 Enable */
+#define	PTP_ACR_ATSEN_SHIFT	5	/* Auxiliary Snapshot shift */
+#define	PTP_ACR_MASK		GENMASK(7, 4)	/* Aux Snapshot Mask */
+#define	PMC_ART_VALUE0		0x01	/* PMC_ART[15:0] timer value */
+#define	PMC_ART_VALUE1		0x02	/* PMC_ART[31:16] timer value */
+#define	PMC_ART_VALUE2		0x03	/* PMC_ART[47:32] timer value */
+#define	PMC_ART_VALUE3		0x04	/* PMC_ART[63:48] timer value */
+#define	GMAC4_ART_TIME_SHIFT	16	/* ART TIME 16-bits shift */
+
+enum aux_snapshot {
+	AUX_SNAPSHOT0 = 0x10,
+	AUX_SNAPSHOT1 = 0x20,
+	AUX_SNAPSHOT2 = 0x40,
+	AUX_SNAPSHOT3 = 0x80,
+};
+
 extern const struct stmmac_dma_ops dwmac4_dma_ops;
 extern const struct stmmac_dma_ops dwmac410_dma_ops;
 #endif /* __DWMAC4_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 03b1c5a97826..01c0822d37e6 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -1129,6 +1129,34 @@ static int dwmac4_config_l4_filter(struct mac_device_info *hw, u32 filter_no,
 	return 0;
 }
 
+static void dwmac4_extts_configure(void __iomem *ioaddr, int ext_snapshot_num, bool on,
+				   struct net_device *dev)
+{
+	u32 acr_value;
+
+	acr_value = readl(ioaddr + GMAC_AUXILIARY_CONTROL);
+	acr_value &= ~PTP_ACR_MASK;
+	if (on) {
+		/* Enable External snapshot trigger */
+		acr_value |= ext_snapshot_num;
+		acr_value |= PTP_ACR_ATSFC;
+		netdev_dbg(dev, "Auxiliary Snapshot %d enabled.\n",
+			   ext_snapshot_num >> PTP_ACR_ATSEN_SHIFT);
+	} else {
+		netdev_dbg(dev, "Auxiliary Snapshot %d disabled.\n",
+			   ext_snapshot_num >> PTP_ACR_ATSEN_SHIFT);
+	}
+	writel(acr_value, ioaddr + GMAC_AUXILIARY_CONTROL);
+}
+
+static int dwmac4_clear_snapshot_fifo(void __iomem *ioaddr)
+{
+	u32 acr_value;
+
+	return readl_poll_timeout(ioaddr + GMAC_AUXILIARY_CONTROL, acr_value,
+				  !(acr_value & PTP_ACR_ATSFC), 10, 10000);
+}
+
 const struct stmmac_ops dwmac4_ops = {
 	.core_init = dwmac4_core_init,
 	.set_mac = stmmac_set_mac,
@@ -1169,6 +1197,8 @@ const struct stmmac_ops dwmac4_ops = {
 	.add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
 	.del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
 	.restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
+	.extts_configure = dwmac4_extts_configure,
+	.clear_snapshot_fifo = dwmac4_clear_snapshot_fifo
 };
 
 const struct stmmac_ops dwmac410_ops = {
@@ -1217,6 +1247,8 @@ const struct stmmac_ops dwmac410_ops = {
 	.add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
 	.del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
 	.restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
+	.extts_configure = dwmac4_extts_configure,
+	.clear_snapshot_fifo = dwmac4_clear_snapshot_fifo
 };
 
 const struct stmmac_ops dwmac510_ops = {
@@ -1269,6 +1301,8 @@ const struct stmmac_ops dwmac510_ops = {
 	.add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr,
 	.del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr,
 	.restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr,
+	.extts_configure = dwmac4_extts_configure,
+	.clear_snapshot_fifo = dwmac4_clear_snapshot_fifo
 };
 
 static u32 dwmac4_get_num_vlan(void __iomem *ioaddr)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
index b4388ca8d211..167bfbf68911 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -165,11 +165,9 @@ static int stmmac_enable(struct ptp_clock_info *ptp,
 {
 	struct stmmac_priv *priv =
 	    container_of(ptp, struct stmmac_priv, ptp_clock_ops);
-	void __iomem *ptpaddr = priv->ptpaddr;
 	struct stmmac_pps_cfg *cfg;
 	int ret = -EOPNOTSUPP;
 	unsigned long flags;
-	u32 acr_value;
 
 	switch (rq->type) {
 	case PTP_CLK_REQ_PEROUT:
@@ -194,26 +192,12 @@ static int stmmac_enable(struct ptp_clock_info *ptp,
 	case PTP_CLK_REQ_EXTTS:
 		priv->plat->ext_snapshot_en = on;
 		mutex_lock(&priv->aux_ts_lock);
-		acr_value = readl(ptpaddr + PTP_ACR);
-		acr_value &= ~PTP_ACR_MASK;
-		if (on) {
-			/* Enable External snapshot trigger */
-			acr_value |= priv->plat->ext_snapshot_num;
-			acr_value |= PTP_ACR_ATSFC;
-			netdev_dbg(priv->dev, "Auxiliary Snapshot %d enabled.\n",
-				   priv->plat->ext_snapshot_num >>
-				   PTP_ACR_ATSEN_SHIFT);
-		} else {
-			netdev_dbg(priv->dev, "Auxiliary Snapshot %d disabled.\n",
-				   priv->plat->ext_snapshot_num >>
-				   PTP_ACR_ATSEN_SHIFT);
-		}
-		writel(acr_value, ptpaddr + PTP_ACR);
+		stmmac_extts_configure(priv, priv->ioaddr,
+				       priv->plat->ext_snapshot_num, on,
+				       priv->dev);
 		mutex_unlock(&priv->aux_ts_lock);
 		/* wait for auxts fifo clear to finish */
-		ret = readl_poll_timeout(ptpaddr + PTP_ACR, acr_value,
-					 !(acr_value & PTP_ACR_ATSFC),
-					 10, 10000);
+		ret = stmmac_clear_snapshot_fifo(priv, priv->ioaddr);
 		break;
 
 	default:
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
index bf619295d079..9e0ff2cec352 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
@@ -67,25 +67,6 @@
 #define	PTP_SSIR_SSINC_MAX		0xff
 #define	GMAC4_PTP_SSIR_SSINC_SHIFT	16
 
-/* Auxiliary Control defines */
-#define	PTP_ACR_ATSFC		BIT(0)	/* Auxiliary Snapshot FIFO Clear */
-#define	PTP_ACR_ATSEN0		BIT(4)	/* Auxiliary Snapshot 0 Enable */
-#define	PTP_ACR_ATSEN1		BIT(5)	/* Auxiliary Snapshot 1 Enable */
-#define	PTP_ACR_ATSEN2		BIT(6)	/* Auxiliary Snapshot 2 Enable */
-#define	PTP_ACR_ATSEN3		BIT(7)	/* Auxiliary Snapshot 3 Enable */
-#define	PTP_ACR_ATSEN_SHIFT	5	/* Auxiliary Snapshot shift */
-#define	PTP_ACR_MASK		GENMASK(7, 4)	/* Aux Snapshot Mask */
-#define	PMC_ART_VALUE0		0x01	/* PMC_ART[15:0] timer value */
-#define	PMC_ART_VALUE1		0x02	/* PMC_ART[31:16] timer value */
-#define	PMC_ART_VALUE2		0x03	/* PMC_ART[47:32] timer value */
-#define	PMC_ART_VALUE3		0x04	/* PMC_ART[63:48] timer value */
-#define	GMAC4_ART_TIME_SHIFT	16	/* ART TIME 16-bits shift */
 
-enum aux_snapshot {
-	AUX_SNAPSHOT0 = 0x10,
-	AUX_SNAPSHOT1 = 0x20,
-	AUX_SNAPSHOT2 = 0x40,
-	AUX_SNAPSHOT3 = 0x80,
-};
 
 #endif	/* __STMMAC_PTP_H__ */
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 1/8] net: stmmac: add IP-specific callbacks for auxiliary snapshot alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 2/8] net: stmmac: populate dwmac4 callbacks for auxiliary snapshots alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  2023-06-16 13:34   ` Simon Horman
  2023-06-17  3:09   ` kernel test robot
  2023-06-16 10:04 ` [PATCH net-next 4/8] net: stmmac: move common defines in stmmac_ptp.h alexis.lothore
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

As for auxiliary snapshot triggers configuration, reading snapshots depends
on specific registers addresses and layout. As a consequence, move
PTP-specific part of stmmac interrupt handling to specific DWMAC IP file

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h  |  2 +
 .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 51 ++++++++++++++++++
 .../ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 52 -------------------
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  2 -
 .../net/ethernet/stmicro/stmmac/stmmac_ptp.h  |  3 --
 5 files changed, 53 insertions(+), 57 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index d249a68f6787..9e7ba5f2e53a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -52,6 +52,8 @@
 #define GMAC_L3_ADDR1(reg)		(0x914 + (reg) * 0x30)
 #define GMAC_TIMESTAMP_STATUS		0x00000b20
 #define GMAC_AUXILIARY_CONTROL		0x00000b40	/* Auxiliary Control Reg */
+#define GMAC_AT_NS			0x00000b48	/* Auxiliary Timestamp - Nanoseconds Reg */
+#define GMAC_AT_S			0x00000b4c	/* Auxiliary Timestamp - Seconds Reg */
 
 /* RX Queues Routing */
 #define GMAC_RXQCTRL_AVCPQ_MASK		GENMASK(2, 0)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index 01c0822d37e6..b36fbb0fa5da 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -16,6 +16,7 @@
 #include <linux/io.h>
 #include "stmmac.h"
 #include "stmmac_pcs.h"
+#include "stmmac_ptp.h"
 #include "dwmac4.h"
 #include "dwmac5.h"
 
@@ -798,9 +799,56 @@ static int dwmac4_irq_mtl_status(struct stmmac_priv *priv,
 	return ret;
 }
 
+static void get_ptptime(void __iomem *ioaddr, u64 *ptp_time)
+{
+	u64 ns;
+
+	ns = readl(ioaddr + GMAC_AT_NS);
+	ns += readl(ioaddr + GMAC_AT_S) * NSEC_PER_SEC;
+
+	*ptp_time = ns;
+}
+
+static void dwmac4_ptp_isr(struct stmmac_priv *priv)
+{
+	u32 num_snapshot, ts_status;
+	struct ptp_clock_event event;
+	unsigned long flags;
+	u64 ptp_time;
+	int i;
+
+	if (priv->plat->int_snapshot_en) {
+		wake_up(&priv->tstamp_busy_wait);
+		return;
+	}
+
+	/* Read timestamp status to clear interrupt from either external
+	 * timestamp or start/end of PPS.
+	 */
+	ts_status = readl(priv->ioaddr + GMAC_TIMESTAMP_STATUS);
+
+	if (!priv->plat->ext_snapshot_en)
+		return;
+
+	num_snapshot = (ts_status & GMAC_TIMESTAMP_ATSNS_MASK) >>
+		       GMAC_TIMESTAMP_ATSNS_SHIFT;
+
+	for (i = 0; i < num_snapshot; i++) {
+		read_lock_irqsave(&priv->ptp_lock, flags);
+		get_ptptime(priv->ioaddr, &ptp_time);
+		read_unlock_irqrestore(&priv->ptp_lock, flags);
+		event.type = PTP_CLOCK_EXTTS;
+		event.index = 0;
+		event.timestamp = ptp_time;
+		ptp_clock_event(priv->ptp_clock, &event);
+	}
+}
+
 static int dwmac4_irq_status(struct mac_device_info *hw,
 			     struct stmmac_extra_stats *x)
 {
+	struct stmmac_priv *priv =
+		container_of(x, struct stmmac_priv, xstats);
 	void __iomem *ioaddr = hw->pcsr;
 	u32 intr_status = readl(ioaddr + GMAC_INT_STATUS);
 	u32 intr_enable = readl(ioaddr + GMAC_INT_EN);
@@ -841,6 +889,9 @@ static int dwmac4_irq_status(struct mac_device_info *hw,
 			x->irq_rx_path_exit_lpi_mode_n++;
 	}
 
+	if (intr_status & time_stamp_irq)
+		dwmac4_ptp_isr(priv);
+
 	dwmac_pcs_isr(ioaddr, GMAC_PCS_BASE, intr_status, x);
 	if (intr_status & PCS_RGSMIIIS_IRQ)
 		dwmac4_phystatus(ioaddr, x);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
index 8b50f03056b7..2cd0ec17f4c6 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
@@ -162,56 +162,6 @@ static void get_systime(void __iomem *ioaddr, u64 *systime)
 		*systime = ns + (sec1 * 1000000000ULL);
 }
 
-static void get_ptptime(void __iomem *ptpaddr, u64 *ptp_time)
-{
-	u64 ns;
-
-	ns = readl(ptpaddr + PTP_ATNR);
-	ns += readl(ptpaddr + PTP_ATSR) * NSEC_PER_SEC;
-
-	*ptp_time = ns;
-}
-
-static void timestamp_interrupt(struct stmmac_priv *priv)
-{
-	u32 num_snapshot, ts_status, tsync_int;
-	struct ptp_clock_event event;
-	unsigned long flags;
-	u64 ptp_time;
-	int i;
-
-	if (priv->plat->int_snapshot_en) {
-		wake_up(&priv->tstamp_busy_wait);
-		return;
-	}
-
-	tsync_int = readl(priv->ioaddr + GMAC_INT_STATUS) & GMAC_INT_TSIE;
-
-	if (!tsync_int)
-		return;
-
-	/* Read timestamp status to clear interrupt from either external
-	 * timestamp or start/end of PPS.
-	 */
-	ts_status = readl(priv->ioaddr + GMAC_TIMESTAMP_STATUS);
-
-	if (!priv->plat->ext_snapshot_en)
-		return;
-
-	num_snapshot = (ts_status & GMAC_TIMESTAMP_ATSNS_MASK) >>
-		       GMAC_TIMESTAMP_ATSNS_SHIFT;
-
-	for (i = 0; i < num_snapshot; i++) {
-		read_lock_irqsave(&priv->ptp_lock, flags);
-		get_ptptime(priv->ptpaddr, &ptp_time);
-		read_unlock_irqrestore(&priv->ptp_lock, flags);
-		event.type = PTP_CLOCK_EXTTS;
-		event.index = 0;
-		event.timestamp = ptp_time;
-		ptp_clock_event(priv->ptp_clock, &event);
-	}
-}
-
 const struct stmmac_hwtimestamp stmmac_ptp = {
 	.config_hw_tstamping = config_hw_tstamping,
 	.init_systime = init_systime,
@@ -219,6 +169,4 @@ const struct stmmac_hwtimestamp stmmac_ptp = {
 	.config_addend = config_addend,
 	.adjust_systime = adjust_systime,
 	.get_systime = get_systime,
-	.get_ptptime = get_ptptime,
-	.timestamp_interrupt = timestamp_interrupt,
 };
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 5c645b6d5660..4f0ef73d5121 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -5804,8 +5804,6 @@ static void stmmac_common_interrupt(struct stmmac_priv *priv)
 			else
 				netif_carrier_off(priv->dev);
 		}
-
-		stmmac_timestamp_interrupt(priv, priv);
 	}
 }
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
index 9e0ff2cec352..92ed421702b9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
@@ -23,9 +23,6 @@
 #define	PTP_STSUR	0x10	/* System Time – Seconds Update Reg */
 #define	PTP_STNSUR	0x14	/* System Time – Nanoseconds Update Reg */
 #define	PTP_TAR		0x18	/* Timestamp Addend Reg */
-#define	PTP_ACR		0x40	/* Auxiliary Control Reg */
-#define	PTP_ATNR	0x48	/* Auxiliary Timestamp - Nanoseconds Reg */
-#define	PTP_ATSR	0x4c	/* Auxiliary Timestamp - Seconds Reg */
 
 #define	PTP_STNSUR_ADDSUB_SHIFT	31
 #define	PTP_DIGITAL_ROLLOVER_MODE	0x3B9ACA00	/* 10e9-1 ns */
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 4/8] net: stmmac: move common defines in stmmac_ptp.h
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
                   ` (2 preceding siblings ...)
  2023-06-16 10:04 ` [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 5/8] net: stmmac: set number of snapshot external triggers for GMAC3 alexis.lothore
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

Even if the address of registers containing statuses is not the same
between dwamc4 and dwmac 1000, the offsets of interest inside those
register are the same regarding auxiliary snapshots. As a consequence, move
those offset definitions in stmmac_ptp.h

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h     | 5 -----
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h | 4 +++-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
index 9e7ba5f2e53a..32a15c020a43 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h
@@ -313,11 +313,6 @@ enum power_event {
 #define GMAC_L4DP0_SHIFT		16
 #define GMAC_L4SP0			GENMASK(15, 0)
 
-/* MAC Timestamp Status */
-#define GMAC_TIMESTAMP_AUXTSTRIG	BIT(2)
-#define GMAC_TIMESTAMP_ATSNS_MASK	GENMASK(29, 25)
-#define GMAC_TIMESTAMP_ATSNS_SHIFT	25
-
 /*  MTL registers */
 #define MTL_OPERATION_MODE		0x00000c00
 #define MTL_FRPE			BIT(15)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
index 92ed421702b9..04bbf12dfd4b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
@@ -64,6 +64,8 @@
 #define	PTP_SSIR_SSINC_MAX		0xff
 #define	GMAC4_PTP_SSIR_SSINC_SHIFT	16
 
-
+/* MAC Timestamp Status */
+#define GMAC_TIMESTAMP_ATSNS_MASK	GENMASK(29, 25)
+#define GMAC_TIMESTAMP_ATSNS_SHIFT	25
 
 #endif	/* __STMMAC_PTP_H__ */
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 5/8] net: stmmac: set number of snapshot external triggers for GMAC3
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
                   ` (3 preceding siblings ...)
  2023-06-16 10:04 ` [PATCH net-next 4/8] net: stmmac: move common defines in stmmac_ptp.h alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 6/8] net: stmmac: introduce setter/getter for timestamp configuration alexis.lothore
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

While GMAC4 exposes number of available auxiliary snapshots inputs in
MAC_HW_FEATURE2 register, GMAC3 (DWMAC1000) does not expose this
information in its only hardware feature register.
When running on GMAC3, hardcode the value to 1 to allow external trigger
usage

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
index 167bfbf68911..090a9d803446 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -280,7 +280,10 @@ void stmmac_ptp_register(struct stmmac_priv *priv)
 		priv->plat->cdc_error_adj = (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate;
 
 	stmmac_ptp_clock_ops.n_per_out = priv->dma_cap.pps_out_num;
-	stmmac_ptp_clock_ops.n_ext_ts = priv->dma_cap.aux_snapshot_n;
+	/* Number of available external triggers is not provided through a
+	 * hardware capabilities register for GMAC3
+	 */
+	stmmac_ptp_clock_ops.n_ext_ts = priv->plat->has_gmac ? 1 : priv->dma_cap.aux_snapshot_n;
 
 	rwlock_init(&priv->ptp_lock);
 	mutex_init(&priv->aux_ts_lock);
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 6/8] net: stmmac: introduce setter/getter for timestamp configuration
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
                   ` (4 preceding siblings ...)
  2023-06-16 10:04 ` [PATCH net-next 5/8] net: stmmac: set number of snapshot external triggers for GMAC3 alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 7/8] net: stmmac: do not overwrite other flags when writing timestamp control alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 8/8] net: stmmac: enable timestamp external trigger for dwmac1000 alexis.lothore
  7 siblings, 0 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

stmmac_hwtstamp_set currently writes the whole Timestamp Control register
when configuring hardware timestamping. It is done for all GMAC variants,
and leads to issues with DWMAC1000: this version also bears the Auxiliary
Snapshot Trigger bit in the same register. This field, which is set
independently with during PTP_CLK_REQ_EXTTS ioctl, is then overwritten when
stmmac_hwtstamp_set is called.
Introduce setter and getter to allow modifying only relevant parts of the
timestamp control register instead of overwriting it all.

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/hwif.h            |  9 ++++++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 10 ++++++++--
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c     |  4 ++--
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index d0b2f13510aa..927324e3d748 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -534,7 +534,8 @@ struct stmmac_ops {
 
 /* PTP and HW Timer helpers */
 struct stmmac_hwtimestamp {
-	void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
+	void (*config_hw_tstamping_set)(void __iomem *ioaddr, u32 data);
+	u32 (*config_hw_tstamping_get)(void __iomem *ioaddr);
 	void (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
 					   int gmac4, u32 *ssinc);
 	int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
@@ -546,8 +547,10 @@ struct stmmac_hwtimestamp {
 	void (*timestamp_interrupt)(struct stmmac_priv *priv);
 };
 
-#define stmmac_config_hw_tstamping(__priv, __args...) \
-	stmmac_do_void_callback(__priv, ptp, config_hw_tstamping, __args)
+#define stmmac_config_hw_tstamping_set(__priv, __args...) \
+	stmmac_do_void_callback(__priv, ptp, config_hw_tstamping_set, __args)
+#define stmmac_config_hw_tstamping_get(__priv, __args...) \
+	stmmac_do_callback(__priv, ptp, config_hw_tstamping_get, __args)
 #define stmmac_config_sub_second_increment(__priv, __args...) \
 	stmmac_do_void_callback(__priv, ptp, config_sub_second_increment, __args)
 #define stmmac_init_systime(__priv, __args...) \
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
index 2cd0ec17f4c6..cbb94d3e0fa1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
@@ -18,11 +18,16 @@
 #include "dwmac4.h"
 #include "stmmac.h"
 
-static void config_hw_tstamping(void __iomem *ioaddr, u32 data)
+static void config_hw_tstamping_set(void __iomem *ioaddr, u32 data)
 {
 	writel(data, ioaddr + PTP_TCR);
 }
 
+static u32 config_hw_tstamping_get(void __iomem *ioaddr)
+{
+	return readl(ioaddr + PTP_TCR);
+}
+
 static void config_sub_second_increment(void __iomem *ioaddr,
 		u32 ptp_clock, int gmac4, u32 *ssinc)
 {
@@ -163,7 +168,8 @@ static void get_systime(void __iomem *ioaddr, u64 *systime)
 }
 
 const struct stmmac_hwtimestamp stmmac_ptp = {
-	.config_hw_tstamping = config_hw_tstamping,
+	.config_hw_tstamping_set = config_hw_tstamping_set,
+	.config_hw_tstamping_get = config_hw_tstamping_get,
 	.init_systime = init_systime,
 	.config_sub_second_increment = config_sub_second_increment,
 	.config_addend = config_addend,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 4f0ef73d5121..528d2e010926 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -792,7 +792,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 				       ts_master_en | snap_type_sel;
 	}
 
-	stmmac_config_hw_tstamping(priv, priv->ptpaddr, priv->systime_flags);
+	stmmac_config_hw_tstamping_set(priv, priv->ptpaddr, priv->systime_flags);
 
 	memcpy(&priv->tstamp_config, &config, sizeof(config));
 
@@ -841,7 +841,7 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
 	if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
 		return -EOPNOTSUPP;
 
-	stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags);
+	stmmac_config_hw_tstamping_set(priv, priv->ptpaddr, systime_flags);
 	priv->systime_flags = systime_flags;
 
 	/* program Sub Second Increment reg */
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 7/8] net: stmmac: do not overwrite other flags when writing timestamp control
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
                   ` (5 preceding siblings ...)
  2023-06-16 10:04 ` [PATCH net-next 6/8] net: stmmac: introduce setter/getter for timestamp configuration alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  2023-06-16 10:04 ` [PATCH net-next 8/8] net: stmmac: enable timestamp external trigger for dwmac1000 alexis.lothore
  7 siblings, 0 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

On some versions of GMAC IP, for example, DWMAC1000, we may overwrite some
other flags like ATSEN0 when writing Timestamp Control register.
Avoid overwriting those additional flags by setting a read-write-modify
process only on flags of interest

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 528d2e010926..ba483adf4e1a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -616,6 +616,10 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
  */
 static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 {
+	u32 reset_mask = PTP_TCR_SNAPTYPSEL_1 | PTP_TCR_TSIPV4ENA |
+			 PTP_TCR_TSIPV6ENA | PTP_TCR_TSEVNTENA |
+			 PTP_TCR_TSMSTRENA | PTP_TCR_TSVER2ENA |
+			 PTP_TCR_TSIPENA | PTP_TCR_TSENALL;
 	struct stmmac_priv *priv = netdev_priv(dev);
 	struct hwtstamp_config config;
 	u32 ptp_v2 = 0;
@@ -783,7 +787,9 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 	priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
 	priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
 
-	priv->systime_flags = STMMAC_HWTS_ACTIVE;
+	priv->systime_flags = stmmac_config_hw_tstamping_get(priv, priv->ptpaddr);
+	priv->systime_flags &= ~reset_mask;
+	priv->systime_flags |= STMMAC_HWTS_ACTIVE;
 
 	if (priv->hwts_tx_en || priv->hwts_rx_en) {
 		priv->systime_flags |= tstamp_all | ptp_v2 |
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net-next 8/8] net: stmmac: enable timestamp external trigger for dwmac1000
  2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
                   ` (6 preceding siblings ...)
  2023-06-16 10:04 ` [PATCH net-next 7/8] net: stmmac: do not overwrite other flags when writing timestamp control alexis.lothore
@ 2023-06-16 10:04 ` alexis.lothore
  7 siblings, 0 replies; 12+ messages in thread
From: alexis.lothore @ 2023-06-16 10:04 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: linux-kernel, netdev, linux-arm-kernel, linux-stm32,
	Thomas Petazzoni, Nicolas Carrier

From: Alexis Lothoré <alexis.lothore@bootlin.com>

The code is pretty similar to dwmac4 snapshot external trigger code. The
difference is mostly about used registers addresses and/or bits offset in
registers

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   |  2 +
 .../net/ethernet/stmicro/stmmac/dwmac1000.h   | 12 ++-
 .../ethernet/stmicro/stmmac/dwmac1000_core.c  | 83 +++++++++++++++++++
 3 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index 6267bcb60206..98f5413cefee 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -17,6 +17,7 @@
 
 #include "stmmac.h"
 #include "stmmac_platform.h"
+#include "dwmac1000.h"
 
 #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0
 #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1
@@ -428,6 +429,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
 	dwmac->ops = ops;
 	plat_dat->bsp_priv = dwmac;
 	plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
+	plat_dat->ext_snapshot_num = GMAC_TC_ATSEN0;
 
 	ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
 	if (ret)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
index 4296ddda8aaa..d17929ea63e0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
@@ -41,8 +41,7 @@
 #define	GMAC_INT_DISABLE_PCS	(GMAC_INT_DISABLE_RGMII | \
 				 GMAC_INT_DISABLE_PCSLINK | \
 				 GMAC_INT_DISABLE_PCSAN)
-#define	GMAC_INT_DEFAULT_MASK	(GMAC_INT_DISABLE_TIMESTAMP | \
-				 GMAC_INT_DISABLE_PCS)
+#define	GMAC_INT_DEFAULT_MASK	GMAC_INT_DISABLE_PCS
 
 /* PMT Control and Status */
 #define GMAC_PMT		0x0000002c
@@ -329,5 +328,14 @@ enum rtc_control {
 #define GMAC_MMC_RX_CSUM_OFFLOAD   0x208
 #define GMAC_EXTHASH_BASE  0x500
 
+/* Timestamping registers */
+#define GMAC_TIMESTAMP_C0NTROL	0x00000700
+#define GMAC_TC_ATSFC	BIT(24)
+#define GMAC_TC_ATSEN0	BIT(25)
+#define GMAC_TIMESTAMP_STATUS	0x00000728
+#define GMAC_AT_NS	0x00000730
+#define GMAC_AT_NS_MASK	0x7FFFFFFF
+#define GMAC_AT_S	0x00000734
+
 extern const struct stmmac_dma_ops dwmac1000_dma_ops;
 #endif /* __DWMAC1000_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index 3927609abc44..97d94b009014 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -19,6 +19,7 @@
 #include "stmmac.h"
 #include "stmmac_pcs.h"
 #include "dwmac1000.h"
+#include "stmmac_ptp.h"
 
 static void dwmac1000_core_init(struct mac_device_info *hw,
 				struct net_device *dev)
@@ -294,9 +295,58 @@ static void dwmac1000_rgsmii(void __iomem *ioaddr, struct stmmac_extra_stats *x)
 	}
 }
 
+static void get_ptptime(void __iomem *ioaddr, u64 *ptp_time)
+{
+	u64 ns;
+
+	ns = (readl(ioaddr + GMAC_AT_NS) & GMAC_AT_NS_MASK);
+	*ptp_time = ns;
+	ns = readl(ioaddr + GMAC_AT_S);
+	*ptp_time += ns * NSEC_PER_SEC;
+}
+
+static void dwmac1000_ptp_isr(struct stmmac_priv *priv)
+{
+	struct ptp_clock_event event;
+	u32 status_reg, num_snapshot;
+	unsigned long flags;
+	u64 ptp_time;
+	int i = 0;
+
+	if (priv->plat->int_snapshot_en) {
+		wake_up(&priv->tstamp_busy_wait);
+		return;
+	}
+
+	/* Read timestamp status to clear interrupt from either external
+	 * timestamp or start/end of PPS.
+	 */
+	status_reg = readl(priv->ioaddr + GMAC_TIMESTAMP_STATUS);
+
+	if (!priv->plat->ext_snapshot_en)
+		return;
+
+	num_snapshot = (status_reg & GMAC_TIMESTAMP_ATSNS_MASK) >>
+		       GMAC_TIMESTAMP_ATSNS_SHIFT;
+	if (!num_snapshot)
+		return;
+
+	for (i = 0; i < num_snapshot; i++) {
+		read_lock_irqsave(&priv->ptp_lock, flags);
+		get_ptptime(priv->ioaddr, &ptp_time);
+		read_unlock_irqrestore(&priv->ptp_lock, flags);
+		event.type = PTP_CLOCK_EXTTS;
+		event.index = 0;
+		event.timestamp = ptp_time;
+		ptp_clock_event(priv->ptp_clock, &event);
+	}
+}
+
 static int dwmac1000_irq_status(struct mac_device_info *hw,
 				struct stmmac_extra_stats *x)
 {
+	struct stmmac_priv *priv =
+		container_of(x, struct stmmac_priv, xstats);
 	void __iomem *ioaddr = hw->pcsr;
 	u32 intr_status = readl(ioaddr + GMAC_INT_STATUS);
 	u32 intr_mask = readl(ioaddr + GMAC_INT_MASK);
@@ -318,6 +368,9 @@ static int dwmac1000_irq_status(struct mac_device_info *hw,
 		x->irq_receive_pmt_irq_n++;
 	}
 
+	if (intr_status & GMAC_INT_STATUS_TSTAMP)
+		dwmac1000_ptp_isr(priv);
+
 	/* MAC tx/rx EEE LPI entry/exit interrupts */
 	if (intr_status & GMAC_INT_STATUS_LPIIS) {
 		/* Clean LPI interrupt by reading the Reg 12 */
@@ -502,6 +555,34 @@ static void dwmac1000_set_mac_loopback(void __iomem *ioaddr, bool enable)
 	writel(value, ioaddr + GMAC_CONTROL);
 }
 
+static void dwmac1000_extts_configure(void __iomem *ioaddr, int ext_snapshot_num,
+				      bool on, struct net_device *dev)
+{
+	u32 acr_value;
+
+	/* Since DWMAC1000 has only one external trigger input,
+	 * ext_snapshot_num is not used
+	 */
+	acr_value = readl(ioaddr + GMAC_TIMESTAMP_C0NTROL);
+	acr_value &= ~GMAC_TC_ATSEN0;
+	if (on) {
+		acr_value |= GMAC_TC_ATSEN0;
+		acr_value |= GMAC_TC_ATSFC;
+		netdev_dbg(dev, "Auxiliary Snapshot 0 enabled.\n");
+	} else {
+		netdev_dbg(dev, "Auxiliary Snapshot 0 disabled.\n");
+	}
+	writel(acr_value, ioaddr + GMAC_TIMESTAMP_C0NTROL);
+}
+
+static int dwmac1000_clear_snapshot_fifo(void __iomem *ioaddr)
+{
+	u32 acr_value;
+
+	return readl_poll_timeout(ioaddr + GMAC_TIMESTAMP_C0NTROL, acr_value,
+				  !(acr_value & GMAC_TC_ATSFC), 10, 10000);
+}
+
 const struct stmmac_ops dwmac1000_ops = {
 	.core_init = dwmac1000_core_init,
 	.set_mac = stmmac_set_mac,
@@ -522,6 +603,8 @@ const struct stmmac_ops dwmac1000_ops = {
 	.pcs_rane = dwmac1000_rane,
 	.pcs_get_adv_lp = dwmac1000_get_adv_lp,
 	.set_mac_loopback = dwmac1000_set_mac_loopback,
+	.extts_configure = dwmac1000_extts_configure,
+	.clear_snapshot_fifo = dwmac1000_clear_snapshot_fifo
 };
 
 int dwmac1000_setup(struct stmmac_priv *priv)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file
  2023-06-16 10:04 ` [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file alexis.lothore
@ 2023-06-16 13:34   ` Simon Horman
  2023-06-16 13:48     ` Alexis Lothoré
  2023-06-17  3:09   ` kernel test robot
  1 sibling, 1 reply; 12+ messages in thread
From: Simon Horman @ 2023-06-16 13:34 UTC (permalink / raw)
  To: alexis.lothore
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran, linux-kernel, netdev,
	linux-arm-kernel, linux-stm32, Thomas Petazzoni, Nicolas Carrier

On Fri, Jun 16, 2023 at 12:04:04PM +0200, alexis.lothore@bootlin.com wrote:
> From: Alexis Lothoré <alexis.lothore@bootlin.com>
> 
> As for auxiliary snapshot triggers configuration, reading snapshots depends
> on specific registers addresses and layout. As a consequence, move
> PTP-specific part of stmmac interrupt handling to specific DWMAC IP file
> 
> Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>

Hi Alexis,

thanks for your patch.

...

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> index 01c0822d37e6..b36fbb0fa5da 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c

...

> +static void dwmac4_ptp_isr(struct stmmac_priv *priv)
> +{
> +	u32 num_snapshot, ts_status;
> +	struct ptp_clock_event event;
> +	unsigned long flags;
> +	u64 ptp_time;
> +	int i;

Please use reverse xmas tree - longest line to shortest - for new
Networking code.

	struct ptp_clock_event event;
	u32 num_snapshot, ts_status;
	unsigned long flags;
	u64 ptp_time;
	int i;

...

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
> index 9e0ff2cec352..92ed421702b9 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
> @@ -23,9 +23,6 @@
>  #define	PTP_STSUR	0x10	/* System Time – Seconds Update Reg */
>  #define	PTP_STNSUR	0x14	/* System Time – Nanoseconds Update Reg */
>  #define	PTP_TAR		0x18	/* Timestamp Addend Reg */
> -#define	PTP_ACR		0x40	/* Auxiliary Control Reg */

Unfortunately this seems to break the build of
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
on an x86_64 alllodconfig, as PTP_ACR is used in that file.

> -#define	PTP_ATNR	0x48	/* Auxiliary Timestamp - Nanoseconds Reg */
> -#define	PTP_ATSR	0x4c	/* Auxiliary Timestamp - Seconds Reg */
>  
>  #define	PTP_STNSUR_ADDSUB_SHIFT	31
>  #define	PTP_DIGITAL_ROLLOVER_MODE	0x3B9ACA00	/* 10e9-1 ns */

--
pw-bot: changes-requested


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file
  2023-06-16 13:34   ` Simon Horman
@ 2023-06-16 13:48     ` Alexis Lothoré
  0 siblings, 0 replies; 12+ messages in thread
From: Alexis Lothoré @ 2023-06-16 13:48 UTC (permalink / raw)
  To: Simon Horman
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran, linux-kernel, netdev,
	linux-arm-kernel, linux-stm32, Thomas Petazzoni, Nicolas Carrier

Hello Simon,

On 6/16/23 15:34, Simon Horman wrote:
> On Fri, Jun 16, 2023 at 12:04:04PM +0200, alexis.lothore@bootlin.com wrote:
>> From: Alexis Lothoré <alexis.lothore@bootlin.com>
>>
>> As for auxiliary snapshot triggers configuration, reading snapshots depends
>> on specific registers addresses and layout. As a consequence, move
>> PTP-specific part of stmmac interrupt handling to specific DWMAC IP file
>>
>> Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
> 
> Hi Alexis,
> 
> thanks for your patch.
> 
> ...
> 
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
>> index 01c0822d37e6..b36fbb0fa5da 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> 
> ...
> 
>> +static void dwmac4_ptp_isr(struct stmmac_priv *priv)
>> +{
>> +	u32 num_snapshot, ts_status;
>> +	struct ptp_clock_event event;
>> +	unsigned long flags;
>> +	u64 ptp_time;
>> +	int i;
> 
> Please use reverse xmas tree - longest line to shortest - for new
> Networking code.
> 
> 	struct ptp_clock_event event;
> 	u32 num_snapshot, ts_status;
> 	unsigned long flags;
> 	u64 ptp_time;
> 	int i;
> 
ACK
> ...
> 
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
>> index 9e0ff2cec352..92ed421702b9 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
>> @@ -23,9 +23,6 @@
>>  #define	PTP_STSUR	0x10	/* System Time – Seconds Update Reg */
>>  #define	PTP_STNSUR	0x14	/* System Time – Nanoseconds Update Reg */
>>  #define	PTP_TAR		0x18	/* Timestamp Addend Reg */
>> -#define	PTP_ACR		0x40	/* Auxiliary Control Reg */
> 
> Unfortunately this seems to break the build of
> drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
> on an x86_64 alllodconfig, as PTP_ACR is used in that file.
> 
>> -#define	PTP_ATNR	0x48	/* Auxiliary Timestamp - Nanoseconds Reg */
>> -#define	PTP_ATSR	0x4c	/* Auxiliary Timestamp - Seconds Reg */
>>  
>>  #define	PTP_STNSUR_ADDSUB_SHIFT	31
>>  #define	PTP_DIGITAL_ROLLOVER_MODE	0x3B9ACA00	/* 10e9-1 ns */

Ouch. thanks for spotting the issue and the providing build details, I'll fix
this and wait a bit for more comments before sending v2
> 
> --
> pw-bot: changes-requested
> 

-- 
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file
  2023-06-16 10:04 ` [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file alexis.lothore
  2023-06-16 13:34   ` Simon Horman
@ 2023-06-17  3:09   ` kernel test robot
  1 sibling, 0 replies; 12+ messages in thread
From: kernel test robot @ 2023-06-17  3:09 UTC (permalink / raw)
  To: alexis.lothore, Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Richard Cochran
  Cc: oe-kbuild-all, netdev, linux-kernel, linux-arm-kernel,
	linux-stm32, Thomas Petazzoni, Nicolas Carrier

Hi,

kernel test robot noticed the following build errors:

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

url:    https://github.com/intel-lab-lkp/linux/commits/alexis-lothore-bootlin-com/net-stmmac-add-IP-specific-callbacks-for-auxiliary-snapshot/20230616-180912
base:   net-next/main
patch link:    https://lore.kernel.org/r/20230616100409.164583-4-alexis.lothore%40bootlin.com
patch subject: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230617/202306171135.YYkItsr2-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230617/202306171135.YYkItsr2-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306171135.YYkItsr2-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c: In function 'intel_crosststamp':
>> drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c:336:37: error: 'PTP_ACR' undeclared (first use in this function); did you mean 'PTP_TCR'?
     336 |         acr_value = readl(ptpaddr + PTP_ACR);
         |                                     ^~~~~~~
         |                                     PTP_TCR
   drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c:336:37: note: each undeclared identifier is reported only once for each function it appears in


vim +336 drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c

76c16d3e19446d Wong Vee Khee  2022-07-14  303  
341f67e424e572 Tan Tee Min    2021-03-23  304  static int intel_crosststamp(ktime_t *device,
341f67e424e572 Tan Tee Min    2021-03-23  305  			     struct system_counterval_t *system,
341f67e424e572 Tan Tee Min    2021-03-23  306  			     void *ctx)
341f67e424e572 Tan Tee Min    2021-03-23  307  {
341f67e424e572 Tan Tee Min    2021-03-23  308  	struct intel_priv_data *intel_priv;
341f67e424e572 Tan Tee Min    2021-03-23  309  
341f67e424e572 Tan Tee Min    2021-03-23  310  	struct stmmac_priv *priv = (struct stmmac_priv *)ctx;
341f67e424e572 Tan Tee Min    2021-03-23  311  	void __iomem *ptpaddr = priv->ptpaddr;
341f67e424e572 Tan Tee Min    2021-03-23  312  	void __iomem *ioaddr = priv->hw->pcsr;
341f67e424e572 Tan Tee Min    2021-03-23  313  	unsigned long flags;
341f67e424e572 Tan Tee Min    2021-03-23  314  	u64 art_time = 0;
341f67e424e572 Tan Tee Min    2021-03-23  315  	u64 ptp_time = 0;
341f67e424e572 Tan Tee Min    2021-03-23  316  	u32 num_snapshot;
341f67e424e572 Tan Tee Min    2021-03-23  317  	u32 gpio_value;
341f67e424e572 Tan Tee Min    2021-03-23  318  	u32 acr_value;
341f67e424e572 Tan Tee Min    2021-03-23  319  	int i;
341f67e424e572 Tan Tee Min    2021-03-23  320  
341f67e424e572 Tan Tee Min    2021-03-23  321  	if (!boot_cpu_has(X86_FEATURE_ART))
341f67e424e572 Tan Tee Min    2021-03-23  322  		return -EOPNOTSUPP;
341f67e424e572 Tan Tee Min    2021-03-23  323  
341f67e424e572 Tan Tee Min    2021-03-23  324  	intel_priv = priv->plat->bsp_priv;
341f67e424e572 Tan Tee Min    2021-03-23  325  
f4da56529da602 Tan Tee Min    2021-04-14  326  	/* Both internal crosstimestamping and external triggered event
f4da56529da602 Tan Tee Min    2021-04-14  327  	 * timestamping cannot be run concurrently.
f4da56529da602 Tan Tee Min    2021-04-14  328  	 */
f4da56529da602 Tan Tee Min    2021-04-14  329  	if (priv->plat->ext_snapshot_en)
f4da56529da602 Tan Tee Min    2021-04-14  330  		return -EBUSY;
f4da56529da602 Tan Tee Min    2021-04-14  331  
76c16d3e19446d Wong Vee Khee  2022-07-14  332  	priv->plat->int_snapshot_en = 1;
76c16d3e19446d Wong Vee Khee  2022-07-14  333  
f4da56529da602 Tan Tee Min    2021-04-14  334  	mutex_lock(&priv->aux_ts_lock);
341f67e424e572 Tan Tee Min    2021-03-23  335  	/* Enable Internal snapshot trigger */
341f67e424e572 Tan Tee Min    2021-03-23 @336  	acr_value = readl(ptpaddr + PTP_ACR);
341f67e424e572 Tan Tee Min    2021-03-23  337  	acr_value &= ~PTP_ACR_MASK;
341f67e424e572 Tan Tee Min    2021-03-23  338  	switch (priv->plat->int_snapshot_num) {
341f67e424e572 Tan Tee Min    2021-03-23  339  	case AUX_SNAPSHOT0:
341f67e424e572 Tan Tee Min    2021-03-23  340  		acr_value |= PTP_ACR_ATSEN0;
341f67e424e572 Tan Tee Min    2021-03-23  341  		break;
341f67e424e572 Tan Tee Min    2021-03-23  342  	case AUX_SNAPSHOT1:
341f67e424e572 Tan Tee Min    2021-03-23  343  		acr_value |= PTP_ACR_ATSEN1;
341f67e424e572 Tan Tee Min    2021-03-23  344  		break;
341f67e424e572 Tan Tee Min    2021-03-23  345  	case AUX_SNAPSHOT2:
341f67e424e572 Tan Tee Min    2021-03-23  346  		acr_value |= PTP_ACR_ATSEN2;
341f67e424e572 Tan Tee Min    2021-03-23  347  		break;
341f67e424e572 Tan Tee Min    2021-03-23  348  	case AUX_SNAPSHOT3:
341f67e424e572 Tan Tee Min    2021-03-23  349  		acr_value |= PTP_ACR_ATSEN3;
341f67e424e572 Tan Tee Min    2021-03-23  350  		break;
341f67e424e572 Tan Tee Min    2021-03-23  351  	default:
53e35ebb9a17fd Dan Carpenter  2021-04-21  352  		mutex_unlock(&priv->aux_ts_lock);
76c16d3e19446d Wong Vee Khee  2022-07-14  353  		priv->plat->int_snapshot_en = 0;
341f67e424e572 Tan Tee Min    2021-03-23  354  		return -EINVAL;
341f67e424e572 Tan Tee Min    2021-03-23  355  	}
341f67e424e572 Tan Tee Min    2021-03-23  356  	writel(acr_value, ptpaddr + PTP_ACR);
341f67e424e572 Tan Tee Min    2021-03-23  357  
341f67e424e572 Tan Tee Min    2021-03-23  358  	/* Clear FIFO */
341f67e424e572 Tan Tee Min    2021-03-23  359  	acr_value = readl(ptpaddr + PTP_ACR);
341f67e424e572 Tan Tee Min    2021-03-23  360  	acr_value |= PTP_ACR_ATSFC;
341f67e424e572 Tan Tee Min    2021-03-23  361  	writel(acr_value, ptpaddr + PTP_ACR);
f4da56529da602 Tan Tee Min    2021-04-14  362  	/* Release the mutex */
f4da56529da602 Tan Tee Min    2021-04-14  363  	mutex_unlock(&priv->aux_ts_lock);
341f67e424e572 Tan Tee Min    2021-03-23  364  
341f67e424e572 Tan Tee Min    2021-03-23  365  	/* Trigger Internal snapshot signal
341f67e424e572 Tan Tee Min    2021-03-23  366  	 * Create a rising edge by just toggle the GPO1 to low
341f67e424e572 Tan Tee Min    2021-03-23  367  	 * and back to high.
341f67e424e572 Tan Tee Min    2021-03-23  368  	 */
341f67e424e572 Tan Tee Min    2021-03-23  369  	gpio_value = readl(ioaddr + GMAC_GPIO_STATUS);
341f67e424e572 Tan Tee Min    2021-03-23  370  	gpio_value &= ~GMAC_GPO1;
341f67e424e572 Tan Tee Min    2021-03-23  371  	writel(gpio_value, ioaddr + GMAC_GPIO_STATUS);
341f67e424e572 Tan Tee Min    2021-03-23  372  	gpio_value |= GMAC_GPO1;
341f67e424e572 Tan Tee Min    2021-03-23  373  	writel(gpio_value, ioaddr + GMAC_GPIO_STATUS);
341f67e424e572 Tan Tee Min    2021-03-23  374  
76c16d3e19446d Wong Vee Khee  2022-07-14  375  	/* Time sync done Indication - Interrupt method */
76c16d3e19446d Wong Vee Khee  2022-07-14  376  	if (!wait_event_interruptible_timeout(priv->tstamp_busy_wait,
76c16d3e19446d Wong Vee Khee  2022-07-14  377  					      stmmac_cross_ts_isr(priv),
76c16d3e19446d Wong Vee Khee  2022-07-14  378  					      HZ / 100)) {
76c16d3e19446d Wong Vee Khee  2022-07-14  379  		priv->plat->int_snapshot_en = 0;
76c16d3e19446d Wong Vee Khee  2022-07-14  380  		return -ETIMEDOUT;
341f67e424e572 Tan Tee Min    2021-03-23  381  	}
341f67e424e572 Tan Tee Min    2021-03-23  382  
341f67e424e572 Tan Tee Min    2021-03-23  383  	num_snapshot = (readl(ioaddr + GMAC_TIMESTAMP_STATUS) &
341f67e424e572 Tan Tee Min    2021-03-23  384  			GMAC_TIMESTAMP_ATSNS_MASK) >>
341f67e424e572 Tan Tee Min    2021-03-23  385  			GMAC_TIMESTAMP_ATSNS_SHIFT;
341f67e424e572 Tan Tee Min    2021-03-23  386  
341f67e424e572 Tan Tee Min    2021-03-23  387  	/* Repeat until the timestamps are from the FIFO last segment */
341f67e424e572 Tan Tee Min    2021-03-23  388  	for (i = 0; i < num_snapshot; i++) {
642436a1ad34a2 Yannick Vignon 2022-02-04  389  		read_lock_irqsave(&priv->ptp_lock, flags);
341f67e424e572 Tan Tee Min    2021-03-23  390  		stmmac_get_ptptime(priv, ptpaddr, &ptp_time);
341f67e424e572 Tan Tee Min    2021-03-23  391  		*device = ns_to_ktime(ptp_time);
642436a1ad34a2 Yannick Vignon 2022-02-04  392  		read_unlock_irqrestore(&priv->ptp_lock, flags);
341f67e424e572 Tan Tee Min    2021-03-23  393  		get_arttime(priv->mii, intel_priv->mdio_adhoc_addr, &art_time);
341f67e424e572 Tan Tee Min    2021-03-23  394  		*system = convert_art_to_tsc(art_time);
341f67e424e572 Tan Tee Min    2021-03-23  395  	}
341f67e424e572 Tan Tee Min    2021-03-23  396  
1c137d4777b5b6 Wong Vee Khee  2021-03-30  397  	system->cycles *= intel_priv->crossts_adj;
76c16d3e19446d Wong Vee Khee  2022-07-14  398  	priv->plat->int_snapshot_en = 0;
1c137d4777b5b6 Wong Vee Khee  2021-03-30  399  
341f67e424e572 Tan Tee Min    2021-03-23  400  	return 0;
341f67e424e572 Tan Tee Min    2021-03-23  401  }
341f67e424e572 Tan Tee Min    2021-03-23  402  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-06-17  3:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 10:04 [PATCH net-next 0/8] net: stmmac: enable timestamp snapshots for DWMAC1000 alexis.lothore
2023-06-16 10:04 ` [PATCH net-next 1/8] net: stmmac: add IP-specific callbacks for auxiliary snapshot alexis.lothore
2023-06-16 10:04 ` [PATCH net-next 2/8] net: stmmac: populate dwmac4 callbacks for auxiliary snapshots alexis.lothore
2023-06-16 10:04 ` [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file alexis.lothore
2023-06-16 13:34   ` Simon Horman
2023-06-16 13:48     ` Alexis Lothoré
2023-06-17  3:09   ` kernel test robot
2023-06-16 10:04 ` [PATCH net-next 4/8] net: stmmac: move common defines in stmmac_ptp.h alexis.lothore
2023-06-16 10:04 ` [PATCH net-next 5/8] net: stmmac: set number of snapshot external triggers for GMAC3 alexis.lothore
2023-06-16 10:04 ` [PATCH net-next 6/8] net: stmmac: introduce setter/getter for timestamp configuration alexis.lothore
2023-06-16 10:04 ` [PATCH net-next 7/8] net: stmmac: do not overwrite other flags when writing timestamp control alexis.lothore
2023-06-16 10:04 ` [PATCH net-next 8/8] net: stmmac: enable timestamp external trigger for dwmac1000 alexis.lothore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).