netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] ptp/ptp_vmw: enhancements to ptp_vmw
@ 2025-10-22 10:51 Ajay Kaher
  2025-10-22 10:51 ` [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops 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
  0 siblings, 2 replies; 7+ messages in thread
From: Ajay Kaher @ 2025-10-22 10:51 UTC (permalink / raw)
  To: kuba, davem, richardcochran, nick.shi, alexey.makhalov,
	andrew+netdev, edumazet, pabeni, jiashengjiangcool, andrew,
	viswanathiyyappan, vadim.fedorenko, wei.fang, rmk+kernel,
	vladimir.oltean, cjubran, dtatulea, tariqt
  Cc: netdev, bcm-kernel-feedback-list, linux-kernel, florian.fainelli,
	vamsi-krishna.brahmajosyula, tapas.kundu, shubham-sg.gupta,
	karen.wang, hari-krishna.ginka, ajay.kaher

This series provides:

- implementation of PTP clock adjustments ops for ptp_vmw driver to
adjust its time and frequency, allowing time transfer from a virtual
machine to the underlying hypervisor.

- add a module parameter probe_hv_port that allows ptp_vmw driver to
be loaded even when ACPI is disabled, by directly probing for the
device using VMware hypervisor port commands.

v2:
- [PATCH 2/2]: remove blank line in ptp_vmw_init()

v1 link:
https://lore.kernel.org/lkml/20250821110323.974367-1-ajay.kaher@broadcom.com/

Ajay Kaher (2):
  ptp/ptp_vmw: Implement PTP clock adjustments ops
  ptp/ptp_vmw: load ptp_vmw driver by directly probing the device

 drivers/ptp/ptp_vmw.c | 109 +++++++++++++++++++++++++++++++++---------
 1 file changed, 87 insertions(+), 22 deletions(-)

-- 
2.40.4


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

* [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops
  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
  2025-10-22 11:13   ` Vadim Fedorenko
  2025-10-22 10:51 ` [PATCH v2 2/2] ptp/ptp_vmw: load ptp_vmw driver by directly probing the device Ajay Kaher
  1 sibling, 1 reply; 7+ messages in thread
From: Ajay Kaher @ 2025-10-22 10:51 UTC (permalink / raw)
  To: kuba, davem, richardcochran, nick.shi, alexey.makhalov,
	andrew+netdev, edumazet, pabeni, jiashengjiangcool, andrew,
	viswanathiyyappan, vadim.fedorenko, wei.fang, rmk+kernel,
	vladimir.oltean, cjubran, dtatulea, tariqt
  Cc: netdev, bcm-kernel-feedback-list, linux-kernel, florian.fainelli,
	vamsi-krishna.brahmajosyula, tapas.kundu, shubham-sg.gupta,
	karen.wang, hari-krishna.ginka, ajay.kaher

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


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

* [PATCH v2 2/2] ptp/ptp_vmw: load ptp_vmw driver by directly probing the device
  2025-10-22 10:51 [PATCH v2 0/2] ptp/ptp_vmw: enhancements to ptp_vmw Ajay Kaher
  2025-10-22 10:51 ` [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops Ajay Kaher
@ 2025-10-22 10:51 ` Ajay Kaher
  1 sibling, 0 replies; 7+ messages in thread
From: Ajay Kaher @ 2025-10-22 10:51 UTC (permalink / raw)
  To: kuba, davem, richardcochran, nick.shi, alexey.makhalov,
	andrew+netdev, edumazet, pabeni, jiashengjiangcool, andrew,
	viswanathiyyappan, vadim.fedorenko, wei.fang, rmk+kernel,
	vladimir.oltean, cjubran, dtatulea, tariqt
  Cc: netdev, bcm-kernel-feedback-list, linux-kernel, florian.fainelli,
	vamsi-krishna.brahmajosyula, tapas.kundu, shubham-sg.gupta,
	karen.wang, hari-krishna.ginka, ajay.kaher

For scenerios when ACPI is disabled, allow ptp_vmw driver to be
loaded by directly probing for the device using VMware hypercalls.

VMware precision clock virtual device is exposed as a platform ACPI
device in its virtual chipset hardware. Its driver - ptp_vmw - is
registered with the ACPI bus for discovery and binding. On systems
where ACPI is disabled, such as virtual machines optimized for fast
boot times, this means that the device is not discoverable and cannot
be loaded. Since the device operations are performed via VMware
hypercalls, the ACPI sub-system can be by-passed and manually loaded.

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 | 70 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 12 deletions(-)

diff --git a/drivers/ptp/ptp_vmw.c b/drivers/ptp/ptp_vmw.c
index 7d117eee4..a3978501a 100644
--- a/drivers/ptp/ptp_vmw.c
+++ b/drivers/ptp/ptp_vmw.c
@@ -98,25 +98,41 @@ static struct ptp_clock_info ptp_vmw_clock_info = {
 	.enable		= ptp_vmw_enable,
 };
 
+static int ptp_vmw_clock_register(void)
+{
+	ptp_vmw_clock = ptp_clock_register(&ptp_vmw_clock_info, NULL);
+	if (IS_ERR(ptp_vmw_clock)) {
+		pr_err("ptp_vmw: Failed to register ptp clock\n");
+		return PTR_ERR(ptp_vmw_clock);
+	}
+	pr_debug("ptp_vmw: ptp clock registered\n");
+	return 0;
+}
+
+static void ptp_vmw_clock_unregister(void)
+{
+	ptp_clock_unregister(ptp_vmw_clock);
+	ptp_vmw_clock = NULL;
+	pr_debug("ptp_vmw: ptp clock unregistered\n");
+}
+
 /*
  * ACPI driver ops for VMware "precision clock" virtual device.
  */
 
 static int ptp_vmw_acpi_add(struct acpi_device *device)
 {
-	ptp_vmw_clock = ptp_clock_register(&ptp_vmw_clock_info, NULL);
-	if (IS_ERR(ptp_vmw_clock)) {
-		pr_err("failed to register ptp clock\n");
-		return PTR_ERR(ptp_vmw_clock);
-	}
+	int ret = ptp_vmw_clock_register();
 
-	ptp_vmw_acpi_device = device;
-	return 0;
+	if (ret == 0)
+		ptp_vmw_acpi_device = device;
+	return ret;
 }
 
 static void ptp_vmw_acpi_remove(struct acpi_device *device)
 {
-	ptp_clock_unregister(ptp_vmw_clock);
+	ptp_vmw_clock_unregister();
+	ptp_vmw_acpi_device = NULL;
 }
 
 static const struct acpi_device_id ptp_vmw_acpi_device_ids[] = {
@@ -135,16 +151,46 @@ static struct acpi_driver ptp_vmw_acpi_driver = {
 	},
 };
 
+/*
+ * Probe existence of device by poking at a command. If successful,
+ * register as a PTP clock. This is a fallback option for when ACPI
+ * is not available.
+ */
+static int ptp_vmw_probe(void)
+{
+	u64 ns;
+
+	return ptp_vmw_pclk_read(VMWARE_CMD_PCLK_GETTIME, &ns);
+}
+
 static int __init ptp_vmw_init(void)
 {
-	if (x86_hyper_type != X86_HYPER_VMWARE)
-		return -1;
-	return acpi_bus_register_driver(&ptp_vmw_acpi_driver);
+	int error = -ENODEV;
+
+	if (x86_hyper_type != X86_HYPER_VMWARE) {
+		error = -EINVAL;
+		goto out;
+	}
+
+	if (!acpi_disabled) {
+		error = acpi_bus_register_driver(&ptp_vmw_acpi_driver);
+		if (!error)
+			goto out;
+	}
+
+	if (!ptp_vmw_probe())
+		error = ptp_vmw_clock_register();
+
+out:
+	return error;
 }
 
 static void __exit ptp_vmw_exit(void)
 {
-	acpi_bus_unregister_driver(&ptp_vmw_acpi_driver);
+	if (!acpi_disabled && ptp_vmw_acpi_device)
+		acpi_bus_unregister_driver(&ptp_vmw_acpi_driver);
+	else if (ptp_vmw_clock)
+		ptp_vmw_clock_unregister();
 }
 
 module_init(ptp_vmw_init);
-- 
2.40.4


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

* Re: [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops
  2025-10-22 10:51 ` [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops Ajay Kaher
@ 2025-10-22 11:13   ` Vadim Fedorenko
  2025-10-22 17:27     ` Ajay Kaher
  0 siblings, 1 reply; 7+ messages in thread
From: Vadim Fedorenko @ 2025-10-22 11:13 UTC (permalink / raw)
  To: Ajay Kaher, kuba, davem, richardcochran, nick.shi,
	alexey.makhalov, andrew+netdev, edumazet, pabeni,
	jiashengjiangcool, andrew, viswanathiyyappan, wei.fang,
	rmk+kernel, vladimir.oltean, cjubran, dtatulea, tariqt
  Cc: netdev, bcm-kernel-feedback-list, linux-kernel, florian.fainelli,
	vamsi-krishna.brahmajosyula, tapas.kundu, shubham-sg.gupta,
	karen.wang, hari-krishna.ginka

On 22/10/2025 11:51, Ajay Kaher wrote:
> 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;
> +}

Why do you need to introduce this change? VMWARE_CMD_PCLK_GETTIME is
the only command used in read() in both patches of this patchset.



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

* Re: [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops
  2025-10-22 11:13   ` Vadim Fedorenko
@ 2025-10-22 17:27     ` Ajay Kaher
  2025-10-22 22:17       ` Vadim Fedorenko
  0 siblings, 1 reply; 7+ messages in thread
From: Ajay Kaher @ 2025-10-22 17:27 UTC (permalink / raw)
  To: Vadim Fedorenko
  Cc: kuba, davem, richardcochran, nick.shi, alexey.makhalov,
	andrew+netdev, edumazet, pabeni, jiashengjiangcool, andrew,
	viswanathiyyappan, wei.fang, rmk+kernel, vladimir.oltean, cjubran,
	dtatulea, tariqt, netdev, bcm-kernel-feedback-list, linux-kernel,
	florian.fainelli, vamsi-krishna.brahmajosyula, tapas.kundu,
	shubham-sg.gupta, karen.wang, hari-krishna.ginka

[-- Attachment #1: Type: text/plain, Size: 2950 bytes --]

On Wed, Oct 22, 2025 at 4:43 PM Vadim Fedorenko
<vadim.fedorenko@linux.dev> wrote:
>
> On 22/10/2025 11:51, Ajay Kaher wrote:
> > 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;
> > +}
>
> Why do you need to introduce this change? VMWARE_CMD_PCLK_GETTIME is
> the only command used in read() in both patches of this patchset.
>

Vadim, thanks for looking into patches.

I have added ptp_vmw_pclk_write() where cmd has been passed as argument.
Keeping the same format for ptp_vmw_pclk_read() as well, also may be useful
in future.

Let me know if you think it's better to keep ptp_vmw_pclk_read() as it
is. I will
revert in v3.

-Ajay

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5414 bytes --]

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

* Re: [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops
  2025-10-22 17:27     ` Ajay Kaher
@ 2025-10-22 22:17       ` Vadim Fedorenko
  2025-10-23  5:08         ` Ajay Kaher
  0 siblings, 1 reply; 7+ messages in thread
From: Vadim Fedorenko @ 2025-10-22 22:17 UTC (permalink / raw)
  To: Ajay Kaher
  Cc: kuba, davem, richardcochran, nick.shi, alexey.makhalov,
	andrew+netdev, edumazet, pabeni, jiashengjiangcool, andrew,
	viswanathiyyappan, wei.fang, rmk+kernel, vladimir.oltean, cjubran,
	dtatulea, tariqt, netdev, bcm-kernel-feedback-list, linux-kernel,
	florian.fainelli, vamsi-krishna.brahmajosyula, tapas.kundu,
	shubham-sg.gupta, karen.wang, hari-krishna.ginka

On 22/10/2025 18:27, Ajay Kaher wrote:
> On Wed, Oct 22, 2025 at 4:43 PM Vadim Fedorenko
> <vadim.fedorenko@linux.dev> wrote:
>>
>> On 22/10/2025 11:51, Ajay Kaher wrote:
>>> 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;
>>> +}
>>
>> Why do you need to introduce this change? VMWARE_CMD_PCLK_GETTIME is
>> the only command used in read() in both patches of this patchset.
>>
> 
> Vadim, thanks for looking into patches.
> 
> I have added ptp_vmw_pclk_write() where cmd has been passed as argument.
> Keeping the same format for ptp_vmw_pclk_read() as well, also may be useful
> in future.
> 
> Let me know if you think it's better to keep ptp_vmw_pclk_read() as it
> is. I will
> revert in v3.

I do believe it's better to keep code as is until you have real use of
new feature. And I'm not quite sure which command you can use to do
another read?

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

* Re: [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops
  2025-10-22 22:17       ` Vadim Fedorenko
@ 2025-10-23  5:08         ` Ajay Kaher
  0 siblings, 0 replies; 7+ messages in thread
From: Ajay Kaher @ 2025-10-23  5:08 UTC (permalink / raw)
  To: Vadim Fedorenko
  Cc: kuba, davem, richardcochran, nick.shi, alexey.makhalov,
	andrew+netdev, edumazet, pabeni, jiashengjiangcool, andrew,
	viswanathiyyappan, wei.fang, rmk+kernel, vladimir.oltean, cjubran,
	dtatulea, tariqt, netdev, bcm-kernel-feedback-list, linux-kernel,
	florian.fainelli, vamsi-krishna.brahmajosyula, tapas.kundu,
	shubham-sg.gupta, karen.wang, hari-krishna.ginka

[-- Attachment #1: Type: text/plain, Size: 3508 bytes --]

On Thu, Oct 23, 2025 at 3:47 AM Vadim Fedorenko
<vadim.fedorenko@linux.dev> wrote:
>
> On 22/10/2025 18:27, Ajay Kaher wrote:
> > On Wed, Oct 22, 2025 at 4:43 PM Vadim Fedorenko
> > <vadim.fedorenko@linux.dev> wrote:
> >>
> >> On 22/10/2025 11:51, Ajay Kaher wrote:
> >>> 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;
> >>> +}
> >>
> >> Why do you need to introduce this change? VMWARE_CMD_PCLK_GETTIME is
> >> the only command used in read() in both patches of this patchset.
> >>
> >
> > Vadim, thanks for looking into patches.
> >
> > I have added ptp_vmw_pclk_write() where cmd has been passed as argument.
> > Keeping the same format for ptp_vmw_pclk_read() as well, also may be useful
> > in future.
> >
> > Let me know if you think it's better to keep ptp_vmw_pclk_read() as it
> > is. I will
> > revert in v3.
>
> I do believe it's better to keep code as is until you have real use of
> new feature. And I'm not quite sure which command you can use to do
> another read?

Sure, I will revert the changes of ptp_vmw_pclk_read() in v3.

-Ajay

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5414 bytes --]

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

end of thread, other threads:[~2025-10-23  5:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22 10:51 [PATCH v2 0/2] ptp/ptp_vmw: enhancements to ptp_vmw Ajay Kaher
2025-10-22 10:51 ` [PATCH v2 1/2] ptp/ptp_vmw: Implement PTP clock adjustments ops Ajay Kaher
2025-10-22 11:13   ` 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

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).