From: Ajay Kaher <ajay.kaher@broadcom.com>
To: kuba@kernel.org, davem@davemloft.net, richardcochran@gmail.com,
nick.shi@broadcom.com, alexey.makhalov@broadcom.com,
andrew+netdev@lunn.ch, edumazet@google.com, pabeni@redhat.com,
jiashengjiangcool@gmail.com, andrew@lunn.ch,
viswanathiyyappan@gmail.com, vadim.fedorenko@linux.dev,
wei.fang@nxp.com, rmk+kernel@armlinux.org.uk,
vladimir.oltean@nxp.com, cjubran@nvidia.com, dtatulea@nvidia.com,
tariqt@nvidia.com
Cc: netdev@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com,
linux-kernel@vger.kernel.org, florian.fainelli@broadcom.com,
vamsi-krishna.brahmajosyula@broadcom.com,
tapas.kundu@broadcom.com, shubham-sg.gupta@broadcom.com,
karen.wang@broadcom.com, hari-krishna.ginka@broadcom.com,
ajay.kaher@broadcom.com
Subject: [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops
Date: Wed, 22 Oct 2025 10:51:27 +0000 [thread overview]
Message-ID: <20251022105128.3679902-2-ajay.kaher@broadcom.com> (raw)
In-Reply-To: <20251022105128.3679902-1-ajay.kaher@broadcom.com>
Implement PTP clock ops that set time and frequency of the underlying
clock. On supported versions of VMware precision clock virtual device,
new commands can adjust its time and frequency, allowing time transfer
from a virtual machine to the underlying hypervisor.
In case of error, vmware_hypercall doesn't return Linux defined errno,
converting it to -EIO.
Cc: Shubham Gupta <shubham-sg.gupta@broadcom.com>
Cc: Nick Shi <nick.shi@broadcom.com>
Tested-by: Karen Wang <karen.wang@broadcom.com>
Tested-by: Hari Krishna Ginka <hari-krishna.ginka@broadcom.com>
Signed-off-by: Ajay Kaher <ajay.kaher@broadcom.com>
---
drivers/ptp/ptp_vmw.c | 39 +++++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/drivers/ptp/ptp_vmw.c b/drivers/ptp/ptp_vmw.c
index 20ab05c4d..7d117eee4 100644
--- a/drivers/ptp/ptp_vmw.c
+++ b/drivers/ptp/ptp_vmw.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
/*
- * Copyright (C) 2020 VMware, Inc., Palo Alto, CA., USA
+ * Copyright (C) 2020-2023 VMware, Inc., Palo Alto, CA., USA
+ * Copyright (C) 2024-2025 Broadcom Ltd.
*
* PTP clock driver for VMware precision clock virtual device.
*/
@@ -16,20 +17,36 @@
#define VMWARE_CMD_PCLK(nr) ((nr << 16) | 97)
#define VMWARE_CMD_PCLK_GETTIME VMWARE_CMD_PCLK(0)
+#define VMWARE_CMD_PCLK_SETTIME VMWARE_CMD_PCLK(1)
+#define VMWARE_CMD_PCLK_ADJTIME VMWARE_CMD_PCLK(2)
+#define VMWARE_CMD_PCLK_ADJFREQ VMWARE_CMD_PCLK(3)
static struct acpi_device *ptp_vmw_acpi_device;
static struct ptp_clock *ptp_vmw_clock;
+/*
+ * Helpers for reading and writing to precision clock device.
+ */
-static int ptp_vmw_pclk_read(u64 *ns)
+static int ptp_vmw_pclk_read(int cmd, u64 *ns)
{
u32 ret, nsec_hi, nsec_lo;
- ret = vmware_hypercall3(VMWARE_CMD_PCLK_GETTIME, 0,
- &nsec_hi, &nsec_lo);
+ ret = vmware_hypercall3(cmd, 0, &nsec_hi, &nsec_lo);
if (ret == 0)
*ns = ((u64)nsec_hi << 32) | nsec_lo;
- return ret;
+
+ return ret != 0 ? -EIO : 0;
+}
+
+static int ptp_vmw_pclk_write(int cmd, u64 in)
+{
+ u32 ret, unused;
+
+ ret = vmware_hypercall5(cmd, 0, 0, in >> 32, in & 0xffffffff,
+ &unused);
+
+ return ret != 0 ? -EIO : 0;
}
/*
@@ -38,19 +55,19 @@ static int ptp_vmw_pclk_read(u64 *ns)
static int ptp_vmw_adjtime(struct ptp_clock_info *info, s64 delta)
{
- return -EOPNOTSUPP;
+ return ptp_vmw_pclk_write(VMWARE_CMD_PCLK_ADJTIME, (u64)delta);
}
static int ptp_vmw_adjfine(struct ptp_clock_info *info, long delta)
{
- return -EOPNOTSUPP;
+ return ptp_vmw_pclk_write(VMWARE_CMD_PCLK_ADJFREQ, (u64)delta);
}
static int ptp_vmw_gettime(struct ptp_clock_info *info, struct timespec64 *ts)
{
u64 ns;
- if (ptp_vmw_pclk_read(&ns) != 0)
+ if (ptp_vmw_pclk_read(VMWARE_CMD_PCLK_GETTIME, &ns) != 0)
return -EIO;
*ts = ns_to_timespec64(ns);
return 0;
@@ -59,7 +76,9 @@ static int ptp_vmw_gettime(struct ptp_clock_info *info, struct timespec64 *ts)
static int ptp_vmw_settime(struct ptp_clock_info *info,
const struct timespec64 *ts)
{
- return -EOPNOTSUPP;
+ u64 ns = timespec64_to_ns(ts);
+
+ return ptp_vmw_pclk_write(VMWARE_CMD_PCLK_SETTIME, ns);
}
static int ptp_vmw_enable(struct ptp_clock_info *info,
@@ -71,7 +90,7 @@ static int ptp_vmw_enable(struct ptp_clock_info *info,
static struct ptp_clock_info ptp_vmw_clock_info = {
.owner = THIS_MODULE,
.name = "ptp_vmw",
- .max_adj = 0,
+ .max_adj = 999999999,
.adjtime = ptp_vmw_adjtime,
.adjfine = ptp_vmw_adjfine,
.gettime64 = ptp_vmw_gettime,
--
2.40.4
next prev parent reply other threads:[~2025-10-22 11:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 10:51 [PATCH v2 0/2] ptp/ptp_vmw: enhancements to ptp_vmw Ajay Kaher
2025-10-22 10:51 ` Ajay Kaher [this message]
2025-10-22 11:13 ` [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops Vadim Fedorenko
2025-10-22 17:27 ` Ajay Kaher
2025-10-22 22:17 ` Vadim Fedorenko
2025-10-23 5:08 ` Ajay Kaher
2025-10-22 10:51 ` [PATCH v2 2/2] ptp/ptp_vmw: load ptp_vmw driver by directly probing the device Ajay Kaher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251022105128.3679902-2-ajay.kaher@broadcom.com \
--to=ajay.kaher@broadcom.com \
--cc=alexey.makhalov@broadcom.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=hari-krishna.ginka@broadcom.com \
--cc=jiashengjiangcool@gmail.com \
--cc=karen.wang@broadcom.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nick.shi@broadcom.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=shubham-sg.gupta@broadcom.com \
--cc=tapas.kundu@broadcom.com \
--cc=tariqt@nvidia.com \
--cc=vadim.fedorenko@linux.dev \
--cc=vamsi-krishna.brahmajosyula@broadcom.com \
--cc=viswanathiyyappan@gmail.com \
--cc=vladimir.oltean@nxp.com \
--cc=wei.fang@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).