lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20241012114755.2509083-1-maheshb@google.com>
Date: Sat, 12 Oct 2024 04:47:54 -0700
From: Mahesh Bandewar <maheshb@...gle.com>
To: Netdev <netdev@...r.kernel.org>, Tariq Toukan <tariqt@...dia.com>, 
	Yishai Hadas <yishaih@...dia.com>
Cc: Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, 
	David Miller <davem@...emloft.net>, Paolo Abeni <pabeni@...hat.com>, 
	Richard Cochran <richardcochran@...il.com>, Mahesh Bandewar <mahesh@...dewar.net>, 
	Mahesh Bandewar <maheshb@...gle.com>
Subject: [PATCHv2 net-next 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.

Signed-off-by: Mahesh Bandewar <maheshb@...gle.com>
---
 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(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index cab9221a0b26..69c5e4c5e036 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -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);
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 9408313b0f4d..d9ef6006ada3 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -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)
diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
index 27f42f713c89..265accc4e606 100644
--- a/include/linux/mlx4/device.h
+++ b/include/linux/mlx4/device.h
@@ -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);
-- 
2.47.0.rc1.288.g06298d1525-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ