Skip to contentSkip to conversation

net: stmmac: enable timestamp snapshots for DWMAC1000

PATCH In review [email protected] 3 participants 12 messages Jun 16, 2023 – Jun 17, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover net: stmmac: enable timestamp snapshots for DWMAC1000

From: Alexis Lothoré <[email protected]>

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/[email protected]/
[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(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/8 net: stmmac: add IP-specific callbacks for auxiliary snapshot

From: Alexis Lothoré <[email protected]>

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

---
 drivers/net/ethernet/stmicro/stmmac/hwif.h | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/ethernet/stmicro/stmmac/hwif.h +8 -0
index 6ee7cf07cfd7..d0b2f13510aa 100644
@@ -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 {
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/8 net: stmmac: populate dwmac4 callbacks for auxiliary snapshots

In reply to [email protected]

From: Alexis Lothoré <[email protected]>

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.

---
 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(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4.h +22 -0
index d3c5306f1c41..d249a68f6787 100644
@@ -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__ */
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +34 -0
index 03b1c5a97826..01c0822d37e6 100644
@@ -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)
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +4 -20
index b4388ca8d211..167bfbf68911 100644
@@ -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:
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +0 -19
index bf619295d079..9e0ff2cec352 100644
@@ -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__ */
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/8 net: stmmac: move PTP interrupt handling to IP-specific DWMAC file

In reply to [email protected]

From: Alexis Lothoré <[email protected]>

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

---
 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(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4.h +2 -0
index d249a68f6787..9e7ba5f2e53a 100644
@@ -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)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +51 -0

72 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +0 -52

62 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -2
index 5c645b6d5660..4f0ef73d5121 100644
@@ -5804,8 +5804,6 @@ static void stmmac_common_interrupt(struct stmmac_priv *priv)
 			else
 				netif_carrier_off(priv->dev);
 		}
-
-		stmmac_timestamp_interrupt(priv, priv);
 	}
 }
 
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +0 -3
index 9e0ff2cec352..92ed421702b9 100644
@@ -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 */
Signature · 1 line
2.41.0
#4 lore raw

Re: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file

Quoted 7 lines · On Fri, Jun 16, 2023 at 12:04:04PM +0200, [email protected] wrote:

From: Alexis Lothoré <[email protected]>

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

Hi Alexis,

thanks for your patch.

...

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +0 -0
index 01c0822d37e6..b36fbb0fa5da 100644

...

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c static int dwmac4_irq_mtl_status(struct stmmac_priv *priv, · line 818

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +7 -0
+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;

...

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h line 26

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +0 -1
index 9e0ff2cec352..92ed421702b9 100644
@@ -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.

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h line 28

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +0 -2
-#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

#5 lore raw

Re: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file

Hello Simon,

Quoted 33 lines · Simon Horman
Quoted 7 lines · On Fri, Jun 16, 2023 at 12:04:04PM +0200, [email protected] wrote:

From: Alexis Lothoré <[email protected]>

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

Hi Alexis,

thanks for your patch.

...

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +0 -0
index 01c0822d37e6..b36fbb0fa5da 100644

...

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c static int dwmac4_irq_mtl_status(struct stmmac_priv *priv, · line 818

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +7 -0
+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.

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

ACK

Quoted 16 lines

...

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h line 26

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +0 -1
index 9e0ff2cec352..92ed421702b9 100644
@@ -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.

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h line 28

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +0 -2
-#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

Quoted 4 lines

--
pw-bot: changes-requested

Signature · 3 lines
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#6 lore raw

Re: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file

In reply to [email protected]
kernel test robot noticed the following build errors:

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/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230617/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

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  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

PATCH 4/8 net: stmmac: move common defines in stmmac_ptp.h

In reply to [email protected]

From: Alexis Lothoré <[email protected]>

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

---
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h     | 5 -----
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h | 4 +++-
 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4.h +0 -5
index 9e7ba5f2e53a..32a15c020a43 100644
@@ -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)
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +3 -1
index 92ed421702b9..04bbf12dfd4b 100644
@@ -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__ */
Signature · 1 line
2.41.0
#8 lore raw

PATCH 5/8 net: stmmac: set number of snapshot external triggers for GMAC3

In reply to [email protected]

From: Alexis Lothoré <[email protected]>

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

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +4 -1
index 167bfbf68911..090a9d803446 100644
@@ -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);
Signature · 1 line
2.41.0
#9 lore raw

PATCH 6/8 net: stmmac: introduce setter/getter for timestamp configuration

In reply to [email protected]

From: Alexis Lothoré <[email protected]>

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.

---
 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(-)
drivers/net/ethernet/stmicro/stmmac/hwif.h +6 -3
index d0b2f13510aa..927324e3d748 100644
@@ -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...) \
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +8 -2
index 2cd0ec17f4c6..cbb94d3e0fa1 100644
@@ -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,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -2
index 4f0ef73d5121..528d2e010926 100644
@@ -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 */
Signature · 1 line
2.41.0
#10 lore raw

PATCH 7/8 net: stmmac: do not overwrite other flags when writing timestamp control

In reply to [email protected]

From: Alexis Lothoré <[email protected]>

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

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -1
index 528d2e010926..ba483adf4e1a 100644
@@ -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 |
Signature · 1 line
2.41.0
#11 lore raw

PATCH 8/8 net: stmmac: enable timestamp external trigger for dwmac1000

In reply to [email protected]

From: Alexis Lothoré <[email protected]>

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

---
 .../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(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +2 -0
index 6267bcb60206..98f5413cefee 100644
@@ -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)
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +10 -2
index 4296ddda8aaa..d17929ea63e0 100644
@@ -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__ */
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +83 -0

116 lines not on this page · raw message

Signature · 1 line
2.41.0