Skip to contentSkip to conversation

net/iavf: add clock read support

PATCH Superseded Anurag Mandal 3 participants 10 messages Jul 27 – Sep 17 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/iavf: add clock read support

Implemented read_clock ethdev operation by adding
iavf_dev_read_clock() feature to get current time
in nanoseconds for scheduling packets based on
transmit time.

---
 drivers/net/intel/iavf/iavf.h        |  3 ++-
 drivers/net/intel/iavf/iavf_ethdev.c | 24 ++++++++++++++++++++++++
 drivers/net/intel/iavf/iavf_vchnl.c  | 13 ++++++++++---
 3 files changed, 36 insertions(+), 4 deletions(-)
drivers/net/intel/iavf/iavf.h +2 -1
index 293adaf6c9..cf2b6596d5 100644
@@ -533,4 +533,5 @@ void iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset);
 void iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change);
 bool is_iavf_supported(struct rte_eth_dev *dev);
 void iavf_hash_uninit(struct iavf_adapter *ad);
-#endif /* _IAVF_ETHDEV_H_ */
+int iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time);
+#endif /* _IAVF_ETHDEV_H_ u*/
drivers/net/intel/iavf/iavf_ethdev.c +24 -0
index e475b64971..1a36885107 100644
@@ -165,6 +165,7 @@ static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
 			struct rte_ether_addr *mc_addrs,
 			uint32_t mc_addrs_num);
 static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
+static int iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t *clock);
 
 static const struct rte_pci_id pci_id_iavf_map[] = {
 	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
@@ -264,6 +265,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {
 	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
 	.get_monitor_addr           = iavf_get_monitor_addr,
 	.tm_ops_get                 = iavf_tm_ops_get,
+	.read_clock                 = iavf_dev_read_clock,
 };
 
 static int
@@ -3662,6 +3664,28 @@ bool is_iavf_supported(struct rte_eth_dev *dev)
 	return !strcmp(dev->device->driver->name, rte_iavf_pmd.driver.name);
 }
 
+static int
+iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
+{
+	struct iavf_adapter *adapter =
+		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	int ret;
+
+	if (adapter->closed)
+		return -EIO;
+
+	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) ||
+	    !(vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_READ_PHC))
+		return -ENOTSUP;
+
+	ret = iavf_phc_get_time(adapter, clock);
+	if (ret != 0)
+		return -EIO;
+
+	return 0;
+}
+
 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
drivers/net/intel/iavf/iavf_vchnl.c +10 -3
index f346837bf1..a63639549c 100644
@@ -2521,9 +2521,8 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)
 }
 
 int
-iavf_get_phc_time(struct ci_rx_queue *rxq)
+iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
 {
-	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_phc_time phc_time;
@@ -2543,9 +2542,17 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 			    "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
 		goto out;
 	}
-	rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
+	*time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
 
 out:
 	rte_spinlock_unlock(&vf->phc_time_aq_lock);
 	return err;
 }
+
+int
+iavf_get_phc_time(struct ci_rx_queue *rxq)
+{
+	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
+
+	return iavf_phc_get_time(adapter, &rxq->phc_time);
+}
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 net/iavf: add clock read support

Implemented read_clock ethdev operation by adding
iavf_dev_read_clock() feature to get current time
in nanoseconds for scheduling packets based on
transmit time.

---
V2: Addressed minor typo

 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 24 ++++++++++++++++++++++++
 drivers/net/intel/iavf/iavf_vchnl.c  | 13 ++++++++++---
 3 files changed, 35 insertions(+), 3 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -0
index 293adaf6c9..416625d9fb 100644
@@ -533,4 +533,5 @@ void iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset);
 void iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change);
 bool is_iavf_supported(struct rte_eth_dev *dev);
 void iavf_hash_uninit(struct iavf_adapter *ad);
+int iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/intel/iavf/iavf_ethdev.c +24 -0
index e475b64971..1a36885107 100644
@@ -165,6 +165,7 @@ static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
 			struct rte_ether_addr *mc_addrs,
 			uint32_t mc_addrs_num);
 static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
+static int iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t *clock);
 
 static const struct rte_pci_id pci_id_iavf_map[] = {
 	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
@@ -264,6 +265,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {
 	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
 	.get_monitor_addr           = iavf_get_monitor_addr,
 	.tm_ops_get                 = iavf_tm_ops_get,
+	.read_clock                 = iavf_dev_read_clock,
 };
 
 static int
@@ -3662,6 +3664,28 @@ bool is_iavf_supported(struct rte_eth_dev *dev)
 	return !strcmp(dev->device->driver->name, rte_iavf_pmd.driver.name);
 }
 
+static int
+iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
+{
+	struct iavf_adapter *adapter =
+		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	int ret;
+
+	if (adapter->closed)
+		return -EIO;
+
+	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) ||
+	    !(vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_READ_PHC))
+		return -ENOTSUP;
+
+	ret = iavf_phc_get_time(adapter, clock);
+	if (ret != 0)
+		return -EIO;
+
+	return 0;
+}
+
 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
drivers/net/intel/iavf/iavf_vchnl.c +10 -3
index f346837bf1..a63639549c 100644
@@ -2521,9 +2521,8 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)
 }
 
 int
-iavf_get_phc_time(struct ci_rx_queue *rxq)
+iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
 {
-	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_phc_time phc_time;
@@ -2543,9 +2542,17 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 			    "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
 		goto out;
 	}
-	rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
+	*time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
 
 out:
 	rte_spinlock_unlock(&vf->phc_time_aq_lock);
 	return err;
 }
+
+int
+iavf_get_phc_time(struct ci_rx_queue *rxq)
+{
+	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
+
+	return iavf_phc_get_time(adapter, &rxq->phc_time);
+}
Signature · 1 line
2.34.1
#2 lore raw

Hi All,

Gentle reminder for review & ack.

Thank you.

Regards,
Anurag M

Quoted 119 lines

-----Original Message-----
From: Mandal, Anurag <[email protected]>
Sent: 27 July 2026 18:40
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Medvedkin, Vladimir <[email protected]>; Mandal, Anurag <[email protected]>
Subject: [PATCH v2] net/iavf: add clock read support

Implemented read_clock ethdev operation by adding iavf_dev_read_clock() feature to get current time in nanoseconds for scheduling packets based on transmit time.

---
V2: Addressed minor typo

 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 24 ++++++++++++++++++++++++
drivers/net/intel/iavf/iavf_vchnl.c  | 13 ++++++++++---
 3 files changed, 35 insertions(+), 3 deletions(-)
drivers/net/intel/iavf/iavf.h index renamed from drivers/net/intel/iavf/iavf.h +0 -0

293adaf6c9..416625d9fb 100644

drivers/net/intel/iavf/iavf.h +0 -0
@@ -533,4 +533,5 @@ void iavf_handle_hw_reset(struct rte_eth_dev *dev,
 bool vf_initiated_reset);  void iavf_set_no_poll(struct iavf_adapter *adapter,

bool link_change); bool is_iavf_supported(struct rte_eth_dev *dev); void iavf_hash_uninit(struct iavf_adapter *ad);

drivers/net/intel/iavf/iavf.h +1 -0
+int iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/intel/iavf/iavf_ethdev.c +2 -0
index e475b64971..1a36885107 100644
@@ -165,6 +165,7 @@ static int iavf_set_mc_addr_list(struct rte_eth_dev
 *dev,
 			struct rte_ether_addr *mc_addrs,
 			uint32_t mc_addrs_num);
 static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void
 *arg);
+static int iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t
+*clock);
 
 static const struct rte_pci_id pci_id_iavf_map[] = {
 	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID,

IAVF_DEV_ID_ADAPTIVE_VF) }, @@ -264,6 +265,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {

drivers/net/intel/iavf/iavf_ethdev.c +22 -0
 	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
 	.get_monitor_addr           = iavf_get_monitor_addr,
 	.tm_ops_get                 = iavf_tm_ops_get,
+	.read_clock                 = iavf_dev_read_clock,
 };
 
 static int
@@ -3662,6 +3664,28 @@ bool is_iavf_supported(struct rte_eth_dev *dev)
 	return !strcmp(dev->device->driver->name,
 rte_iavf_pmd.driver.name);  }
 
+static int
+iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t *clock) {
+	struct iavf_adapter *adapter =
+		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	int ret;
+
+	if (adapter->closed)
+		return -EIO;
+
+	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) ||
+	    !(vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_READ_PHC))
+		return -ENOTSUP;
+
+	ret = iavf_phc_get_time(adapter, clock);
+	if (ret != 0)
+		return -EIO;
+
+	return 0;
+}
+
 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);

RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci"); diff --git a/drivers/net/intel/iavf/iavf_vchnl.c b/drivers/net/intel/iavf/iavf_vchnl.c index f346837bf1..a63639549c 100644

drivers/net/intel/iavf/iavf_vchnl.c +8 -4
@@ -2521,9 +2521,8 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)  }
 
 int
-iavf_get_phc_time(struct ci_rx_queue *rxq)
+iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
 {
-	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_phc_time phc_time;
@@ -2543,9 +2542,17 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 			    "Failed to execute command of
 VIRTCHNL_OP_1588_PTP_GET_TIME");
 		goto out;
 	}
-	rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
+	*time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
 
 out:
 	rte_spinlock_unlock(&vf->phc_time_aq_lock);
 	return err;
 }
+
+int
+iavf_get_phc_time(struct ci_rx_queue *rxq) {
+	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
+
+	return iavf_phc_get_time(adapter, &rxq->phc_time); }
--

2.34.1

#3 lore raw
In reply to Anurag Mandal

Recheck-request: rebase=next-net-intel, iol-unit-arm64-testing intel-Functional

Thank you.

Regards,
Anurag M

Quoted 116 lines

-----Original Message-----
From: Mandal, Anurag <[email protected]>
Sent: 27 July 2026 15:55
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Medvedkin, Vladimir <[email protected]>; Mandal, Anurag <[email protected]>
Subject: [PATCH] net/iavf: add clock read support

Implemented read_clock ethdev operation by adding iavf_dev_read_clock() feature to get current time in nanoseconds for scheduling packets based on transmit time.

---
 drivers/net/intel/iavf/iavf.h        |  3 ++-
 drivers/net/intel/iavf/iavf_ethdev.c | 24 ++++++++++++++++++++++++
drivers/net/intel/iavf/iavf_vchnl.c  | 13 ++++++++++---
 3 files changed, 36 insertions(+), 4 deletions(-)
drivers/net/intel/iavf/iavf.h index renamed from drivers/net/intel/iavf/iavf.h +0 -0

293adaf6c9..cf2b6596d5 100644

drivers/net/intel/iavf/iavf.h +0 -0
@@ -533,4 +533,5 @@ void iavf_handle_hw_reset(struct rte_eth_dev *dev,
 bool vf_initiated_reset);  void iavf_set_no_poll(struct iavf_adapter *adapter,

bool link_change); bool is_iavf_supported(struct rte_eth_dev *dev); void iavf_hash_uninit(struct iavf_adapter *ad); -#endif /* _IAVF_ETHDEV_H_ */

drivers/net/intel/iavf/iavf.h +2 -0
+int iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time);
+#endif /* _IAVF_ETHDEV_H_ u*/
drivers/net/intel/iavf/iavf_ethdev.c +2 -0
index e475b64971..1a36885107 100644
@@ -165,6 +165,7 @@ static int iavf_set_mc_addr_list(struct rte_eth_dev
 *dev,
 			struct rte_ether_addr *mc_addrs,
 			uint32_t mc_addrs_num);
 static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
+static int iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t
+*clock);
 
 static const struct rte_pci_id pci_id_iavf_map[] = {
 	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID,

IAVF_DEV_ID_ADAPTIVE_VF) }, @@ -264,6 +265,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {

drivers/net/intel/iavf/iavf_ethdev.c +22 -0
 	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
 	.get_monitor_addr           = iavf_get_monitor_addr,
 	.tm_ops_get                 = iavf_tm_ops_get,
+	.read_clock                 = iavf_dev_read_clock,
 };
 
 static int
@@ -3662,6 +3664,28 @@ bool is_iavf_supported(struct rte_eth_dev *dev)
 	return !strcmp(dev->device->driver->name,
 rte_iavf_pmd.driver.name);  }
 
+static int
+iavf_dev_read_clock(struct rte_eth_dev *dev, uint64_t *clock) {
+	struct iavf_adapter *adapter =
+		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	int ret;
+
+	if (adapter->closed)
+		return -EIO;
+
+	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) ||
+	    !(vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_READ_PHC))
+		return -ENOTSUP;
+
+	ret = iavf_phc_get_time(adapter, clock);
+	if (ret != 0)
+		return -EIO;
+
+	return 0;
+}
+
 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);

RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci"); diff --git a/drivers/net/intel/iavf/iavf_vchnl.c b/drivers/net/intel/iavf/iavf_vchnl.c index f346837bf1..a63639549c 100644

drivers/net/intel/iavf/iavf_vchnl.c +8 -4
@@ -2521,9 +2521,8 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)  }
 
 int
-iavf_get_phc_time(struct ci_rx_queue *rxq)
+iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
 {
-	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_phc_time phc_time;
@@ -2543,9 +2542,17 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 			    "Failed to execute command of
 VIRTCHNL_OP_1588_PTP_GET_TIME");
 		goto out;
 	}
-	rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
+	*time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
 
 out:
 	rte_spinlock_unlock(&vf->phc_time_aq_lock);
 	return err;
 }
+
+int
+iavf_get_phc_time(struct ci_rx_queue *rxq) {
+	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
+
+	return iavf_phc_get_time(adapter, &rxq->phc_time); }
--

2.34.1

#4 lore raw

PATCH v3 1/1 net/iavf: add PTP clock read support

In reply to Anurag Mandal

Added iavf support for the timesync_read_time ethdev API to read the device PTP Hardware Clock (PHC). A VF has no direct access to the PHC, so the time is fetched from the PF over virtchnl, and the API is only advertised when the PF grants the
PTP read capability.

---
V3: Changed read_clock to timesync_read_time
V2: Addressed minor typo

 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 28 ++++++++++++++++++++++++++++
 drivers/net/intel/iavf/iavf_vchnl.c  | 13 ++++++++++---
 3 files changed, 39 insertions(+), 3 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -0
index 293adaf6c9..416625d9fb 100644
@@ -533,4 +533,5 @@ void iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset);
 void iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change);
 bool is_iavf_supported(struct rte_eth_dev *dev);
 void iavf_hash_uninit(struct iavf_adapter *ad);
+int iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/intel/iavf/iavf_ethdev.c +28 -0
index e475b64971..b855be5cfc 100644
@@ -24,6 +24,7 @@
 #include <rte_cycles.h>
 #include <rte_eal.h>
 #include <rte_ether.h>
+#include <rte_time.h>
 #include <ethdev_driver.h>
 #include <ethdev_pci.h>
 #include <rte_malloc.h>
@@ -165,6 +166,7 @@ static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
 			struct rte_ether_addr *mc_addrs,
 			uint32_t mc_addrs_num);
 static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
+static int iavf_timesync_read_time(struct rte_eth_dev *dev, struct timespec *timestamp);
 
 static const struct rte_pci_id pci_id_iavf_map[] = {
 	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
@@ -264,6 +266,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {
 	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
 	.get_monitor_addr           = iavf_get_monitor_addr,
 	.tm_ops_get                 = iavf_tm_ops_get,
+	.timesync_read_time         = iavf_timesync_read_time,
 };
 
 static int
@@ -3662,6 +3665,31 @@ bool is_iavf_supported(struct rte_eth_dev *dev)
 	return !strcmp(dev->device->driver->name, rte_iavf_pmd.driver.name);
 }
 
+static int
+iavf_timesync_read_time(struct rte_eth_dev *dev, struct timespec *timestamp)
+{
+	struct iavf_adapter *adapter =
+		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint64_t time;
+	int ret;
+
+	if (adapter->closed)
+		return -EIO;
+
+	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) ||
+	    !(vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_READ_PHC))
+		return -ENOTSUP;
+
+	ret = iavf_phc_get_time(adapter, &time);
+	if (ret != 0)
+		return -EIO;
+
+	*timestamp = rte_ns_to_timespec(time);
+
+	return 0;
+}
+
 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
drivers/net/intel/iavf/iavf_vchnl.c +10 -3
index f346837bf1..a63639549c 100644
@@ -2521,9 +2521,8 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)
 }
 
 int
-iavf_get_phc_time(struct ci_rx_queue *rxq)
+iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
 {
-	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_phc_time phc_time;
@@ -2543,9 +2542,17 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 			    "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
 		goto out;
 	}
-	rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
+	*time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
 
 out:
 	rte_spinlock_unlock(&vf->phc_time_aq_lock);
 	return err;
 }
+
+int
+iavf_get_phc_time(struct ci_rx_queue *rxq)
+{
+	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
+
+	return iavf_phc_get_time(adapter, &rxq->phc_time);
+}
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v3] net/iavf: support reading PHC time

The new iavf_timesync_read_time() callback converts every error returned by iavf_phc_get_time() to -EIO. The underlying AdminQ path can return more specific errors, including -ENOTSUP and -EINVAL, so this prevents callers from distinguishing an unsupported operation from an actual I/O failure.

Could the original error be propagated instead?

    ret = iavf_phc_get_time(adapter, &time);
    if (ret != 0)
        return ret;
#6 lore raw

RE: [PATCH v3] net/iavf: support reading PHC time

Quoted 12 lines

-----Original Message-----
From: Kumar, Rajesh3 <[email protected]>
Sent: 15 September 2026 18:32
To: Mandal, Anurag <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v3] net/iavf: support reading PHC time

The new iavf_timesync_read_time() callback converts every error returned by iavf_phc_get_time() to -EIO. The underlying AdminQ path can return more specific errors, including -ENOTSUP and -EINVAL, so this prevents callers from distinguishing an unsupported operation from an actual I/O failure.

Quoted 5 lines

Could the original error be propagated instead?

    ret = iavf_phc_get_time(adapter, &time);
    if (ret != 0)
        return ret;

Sure. Let me try the same.

Thank you.

Regards,
Anurag M

#7 lore raw

PATCH v4 1/1 net/iavf: add reading PHC time support

In reply to Anurag Mandal

Added iavf support for the timesync_read_time ethdev API to read the device PTP Hardware Clock (PHC). A VF has no direct access to the PHC, so the time is fetched from the PF over virtchnl, and the API is only advertised when the PF grants the
PTP read capability.

---
V4: Addressed Rajesh Kumar's feedback
- return the error unchanged
V3: Changed read_clock to timesync_read_time
V2: Addressed minor typo

 drivers/net/intel/iavf/iavf.h        |  1 +
 drivers/net/intel/iavf/iavf_ethdev.c | 28 ++++++++++++++++++++++++++++
 drivers/net/intel/iavf/iavf_vchnl.c  | 13 ++++++++++---
 3 files changed, 39 insertions(+), 3 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -0
index 293adaf6c9..416625d9fb 100644
@@ -533,4 +533,5 @@ void iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset);
 void iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change);
 bool is_iavf_supported(struct rte_eth_dev *dev);
 void iavf_hash_uninit(struct iavf_adapter *ad);
+int iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/intel/iavf/iavf_ethdev.c +28 -0
index e475b64971..cb0e8989e1 100644
@@ -24,6 +24,7 @@
 #include <rte_cycles.h>
 #include <rte_eal.h>
 #include <rte_ether.h>
+#include <rte_time.h>
 #include <ethdev_driver.h>
 #include <ethdev_pci.h>
 #include <rte_malloc.h>
@@ -165,6 +166,7 @@ static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
 			struct rte_ether_addr *mc_addrs,
 			uint32_t mc_addrs_num);
 static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
+static int iavf_timesync_read_time(struct rte_eth_dev *dev, struct timespec *timestamp);
 
 static const struct rte_pci_id pci_id_iavf_map[] = {
 	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
@@ -264,6 +266,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {
 	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
 	.get_monitor_addr           = iavf_get_monitor_addr,
 	.tm_ops_get                 = iavf_tm_ops_get,
+	.timesync_read_time         = iavf_timesync_read_time,
 };
 
 static int
@@ -3662,6 +3665,31 @@ bool is_iavf_supported(struct rte_eth_dev *dev)
 	return !strcmp(dev->device->driver->name, rte_iavf_pmd.driver.name);
 }
 
+static int
+iavf_timesync_read_time(struct rte_eth_dev *dev, struct timespec *timestamp)
+{
+	struct iavf_adapter *adapter =
+		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint64_t time;
+	int ret;
+
+	if (adapter->closed)
+		return -EIO;
+
+	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) ||
+	    !(vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_READ_PHC))
+		return -ENOTSUP;
+
+	ret = iavf_phc_get_time(adapter, &time);
+	if (ret != 0)
+		return ret;
+
+	*timestamp = rte_ns_to_timespec(time);
+
+	return 0;
+}
+
 RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
drivers/net/intel/iavf/iavf_vchnl.c +10 -3
index f346837bf1..a63639549c 100644
@@ -2521,9 +2521,8 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)
 }
 
 int
-iavf_get_phc_time(struct ci_rx_queue *rxq)
+iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
 {
-	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
 	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
 	struct virtchnl_phc_time phc_time;
@@ -2543,9 +2542,17 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
 			    "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
 		goto out;
 	}
-	rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
+	*time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
 
 out:
 	rte_spinlock_unlock(&vf->phc_time_aq_lock);
 	return err;
 }
+
+int
+iavf_get_phc_time(struct ci_rx_queue *rxq)
+{
+	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
+
+	return iavf_phc_get_time(adapter, &rxq->phc_time);
+}
Signature · 1 line
2.34.1
Reviewed-by on v4 1/1
#8 lore raw

Re: [PATCH v4] net/iavf: add reading PHC time support

LGTM.

Quoted 125 lines · Anurag Mandal

Added iavf support for the timesync_read_time ethdev API to read the device PTP Hardware Clock (PHC). A VF has no direct access to the PHC, so the time is fetched from the PF over virtchnl, and the API is only advertised when the PF grants the
PTP read capability.

---
V4: Addressed Rajesh Kumar's feedback
- return the error unchanged
V3: Changed read_clock to timesync_read_time
V2: Addressed minor typo

  drivers/net/intel/iavf/iavf.h        |  1 +
  drivers/net/intel/iavf/iavf_ethdev.c | 28 ++++++++++++++++++++++++++++
  drivers/net/intel/iavf/iavf_vchnl.c  | 13 ++++++++++---
  3 files changed, 39 insertions(+), 3 deletions(-)
drivers/net/intel/iavf/iavf.h +1 -0
index 293adaf6c9..416625d9fb 100644
@@ -533,4 +533,5 @@ void iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset);
  void iavf_set_no_poll(struct iavf_adapter *adapter, bool link_change);
  bool is_iavf_supported(struct rte_eth_dev *dev);
  void iavf_hash_uninit(struct iavf_adapter *ad);
+int iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time);
  #endif /* _IAVF_ETHDEV_H_ */
drivers/net/intel/iavf/iavf_ethdev.c +28 -0
index e475b64971..cb0e8989e1 100644
@@ -24,6 +24,7 @@
  #include <rte_cycles.h>
  #include <rte_eal.h>
  #include <rte_ether.h>
+#include <rte_time.h>
  #include <ethdev_driver.h>
  #include <ethdev_pci.h>
  #include <rte_malloc.h>
@@ -165,6 +166,7 @@ static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
  			struct rte_ether_addr *mc_addrs,
  			uint32_t mc_addrs_num);
  static int iavf_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
+static int iavf_timesync_read_time(struct rte_eth_dev *dev, struct timespec *timestamp);
 
  static const struct rte_pci_id pci_id_iavf_map[] = {
  	{ RTE_PCI_DEVICE(IAVF_INTEL_VENDOR_ID, IAVF_DEV_ID_ADAPTIVE_VF) },
@@ -264,6 +266,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {
  	.tx_done_cleanup	    = iavf_dev_tx_done_cleanup,
  	.get_monitor_addr           = iavf_get_monitor_addr,
  	.tm_ops_get                 = iavf_tm_ops_get,
+	.timesync_read_time         = iavf_timesync_read_time,
  };
 
  static int
@@ -3662,6 +3665,31 @@ bool is_iavf_supported(struct rte_eth_dev *dev)
  	return !strcmp(dev->device->driver->name, rte_iavf_pmd.driver.name);
  }
 
+static int
+iavf_timesync_read_time(struct rte_eth_dev *dev, struct timespec *timestamp)
+{
+	struct iavf_adapter *adapter =
+		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
+	uint64_t time;
+	int ret;
+
+	if (adapter->closed)
+		return -EIO;
+
+	if (!(vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) ||
+	    !(vf->ptp_caps & VIRTCHNL_1588_PTP_CAP_READ_PHC))
+		return -ENOTSUP;
+
+	ret = iavf_phc_get_time(adapter, &time);
+	if (ret != 0)
+		return ret;
+
+	*timestamp = rte_ns_to_timespec(time);
+
+	return 0;
+}
+
  RTE_PMD_REGISTER_PCI(net_iavf, rte_iavf_pmd);
  RTE_PMD_REGISTER_PCI_TABLE(net_iavf, pci_id_iavf_map);
  RTE_PMD_REGISTER_KMOD_DEP(net_iavf, "* igb_uio | vfio-pci");
drivers/net/intel/iavf/iavf_vchnl.c +10 -3
index f346837bf1..a63639549c 100644
@@ -2521,9 +2521,8 @@ iavf_get_ptp_cap(struct iavf_adapter *adapter)
  }
 
  int
-iavf_get_phc_time(struct ci_rx_queue *rxq)
+iavf_phc_get_time(struct iavf_adapter *adapter, uint64_t *time)
  {
-	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
  	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
  	uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
  	struct virtchnl_phc_time phc_time;
@@ -2543,9 +2542,17 @@ iavf_get_phc_time(struct ci_rx_queue *rxq)
  			    "Failed to execute command of VIRTCHNL_OP_1588_PTP_GET_TIME");
  		goto out;
  	}
-	rxq->phc_time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
+	*time = ((struct virtchnl_phc_time *)args.out_buffer)->time;
 
  out:
  	rte_spinlock_unlock(&vf->phc_time_aq_lock);
  	return err;
  }
+
+int
+iavf_get_phc_time(struct ci_rx_queue *rxq)
+{
+	struct iavf_adapter *adapter = rxq->iavf_vsi->adapter;
+
+	return iavf_phc_get_time(adapter, &rxq->phc_time);
+}