Skip to contentSkip to conversation

mlx4: update mlx4_read_clock() to provide pre/post timestamps

PATCH In review Mahesh Bandewar 1 participant 1 message Oct 12, 2024

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

PATCH v2 2/3 mlx4: update mlx4_read_clock() to provide pre/post timestamps

Enhance mlx4_read_clock() and mlx4_en_read_clock() to provide both pre- and post-timestamps along with the raw cycle count, which are required to support the gettimex64() operation.

---
 drivers/net/ethernet/mellanox/mlx4/en_clock.c | 15 ++++++++-------
 drivers/net/ethernet/mellanox/mlx4/main.c     | 11 +++++++++--
 include/linux/mlx4/device.h                   |  3 ++-
 3 files changed, 19 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_clock.c +8 -7
index cab9221a0b26..69c5e4c5e036 100644
@@ -47,9 +47,10 @@ static u64 mlx4_en_read_clock_cache(const struct cyclecounter *tc)
 	return READ_ONCE(mdev->clock_cache) & tc->mask;
 }
 
-static void mlx4_en_read_clock(struct mlx4_en_dev *mdev)
+static void mlx4_en_read_clock(struct mlx4_en_dev *mdev,
+			       struct ptp_system_timestamp *sts)
 {
-	u64 cycles = mlx4_read_clock(mdev->dev);
+	u64 cycles = mlx4_read_clock(mdev->dev, sts);
 
 	WRITE_ONCE(mdev->clock_cache, cycles);
 }
@@ -117,7 +118,7 @@ void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev)
 	if (timeout) {
 		write_seqlock_irqsave(&mdev->clock_lock, flags);
 		/* refresh the clock_cache */
-		mlx4_en_read_clock(mdev);
+		mlx4_en_read_clock(mdev, NULL);
 
 		timecounter_read(&mdev->clock);
 		write_sequnlock_irqrestore(&mdev->clock_lock, flags);
@@ -146,7 +147,7 @@ static int mlx4_en_phc_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
 	/* refresh the clock_cache */
-	mlx4_en_read_clock(mdev);
+	mlx4_en_read_clock(mdev, NULL);
 	timecounter_read(&mdev->clock);
 	mdev->cycles.mult = mult;
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
@@ -192,7 +193,7 @@ static int mlx4_en_phc_gettime(struct ptp_clock_info *ptp,
 
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
 	/* refresh the clock_cache */
-	mlx4_en_read_clock(mdev);
+	mlx4_en_read_clock(mdev, NULL);
 	ns = timecounter_read(&mdev->clock);
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
@@ -220,7 +221,7 @@ static int mlx4_en_phc_settime(struct ptp_clock_info *ptp,
 	/* reset the timecounter */
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
 	/* refresh the clock_cache */
-	mlx4_en_read_clock(mdev);
+	mlx4_en_read_clock(mdev, NULL);
 	timecounter_init(&mdev->clock, &mdev->cycles, ns);
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
@@ -298,7 +299,7 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
 
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
 	/* initialize the clock_cache */
-	mlx4_en_read_clock(mdev);
+	mlx4_en_read_clock(mdev, NULL);
 	timecounter_init(&mdev->clock, &mdev->cycles,
 			 ktime_to_ns(ktime_get_real()));
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
drivers/net/ethernet/mellanox/mlx4/main.c +9 -2
index 9408313b0f4d..d9ef6006ada3 100644
@@ -43,6 +43,7 @@
 #include <linux/io-mapping.h>
 #include <linux/delay.h>
 #include <linux/etherdevice.h>
+#include <linux/ptp_clock_kernel.h>
 #include <net/devlink.h>
 
 #include <uapi/rdma/mlx4-abi.h>
@@ -1925,7 +1926,7 @@ static void unmap_bf_area(struct mlx4_dev *dev)
 		io_mapping_free(mlx4_priv(dev)->bf_mapping);
 }
 
-u64 mlx4_read_clock(struct mlx4_dev *dev)
+u64 mlx4_read_clock(struct mlx4_dev *dev, struct ptp_system_timestamp *sts)
 {
 	u32 clockhi, clocklo, clockhi1;
 	u64 cycles;
@@ -1933,7 +1934,13 @@ u64 mlx4_read_clock(struct mlx4_dev *dev)
 	struct mlx4_priv *priv = mlx4_priv(dev);
 
 	for (i = 0; i < 10; i++) {
-		clockhi = swab32(readl(priv->clock_mapping));
+		if (sts) {
+			ptp_read_system_prets(sts);
+			clockhi = swab32(readl(priv->clock_mapping));
+			ptp_read_system_postts(sts);
+		} else {
+			clockhi = swab32(readl(priv->clock_mapping));
+		}
 		clocklo = swab32(readl(priv->clock_mapping + 4));
 		clockhi1 = swab32(readl(priv->clock_mapping));
 		if (clockhi == clockhi1)
include/linux/mlx4/device.h +2 -1
index 27f42f713c89..265accc4e606 100644
@@ -44,6 +44,7 @@
 #include <linux/refcount.h>
 
 #include <linux/timecounter.h>
+#include <linux/ptp_clock_kernel.h>
 
 #define DEFAULT_UAR_PAGE_SHIFT  12
 
@@ -1483,7 +1484,7 @@ int mlx4_get_roce_gid_from_slave(struct mlx4_dev *dev, int port, int slave_id,
 int mlx4_FLOW_STEERING_IB_UC_QP_RANGE(struct mlx4_dev *dev, u32 min_range_qpn,
 				      u32 max_range_qpn);
 
-u64 mlx4_read_clock(struct mlx4_dev *dev);
+u64 mlx4_read_clock(struct mlx4_dev *dev, struct ptp_system_timestamp *sts);
 
 struct mlx4_active_ports {
 	DECLARE_BITMAP(ports, MLX4_MAX_PORTS);
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog