Add additional functions to support the existing IEEE1588
functionality.

* rte_eth_timesync_settime(), function to set the device clock time.
* rte_eth_timesync_gettime, function to get the device clock time.
* rte_eth_timesync_adjust, function to adjust the device clock time.

Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod at intel.com>
---
 doc/guides/rel_notes/release_2_2.rst   |  3 ++
 lib/librte_ether/rte_ethdev.c          | 36 +++++++++++++++++++
 lib/librte_ether/rte_ethdev.h          | 65 +++++++++++++++++++++++++++++++++-
 lib/librte_ether/rte_ether_version.map |  3 ++
 4 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/doc/guides/rel_notes/release_2_2.rst 
b/doc/guides/rel_notes/release_2_2.rst
index 59dda59..17b281c 100644
--- a/doc/guides/rel_notes/release_2_2.rst
+++ b/doc/guides/rel_notes/release_2_2.rst
@@ -222,6 +222,9 @@ API Changes

 * The devargs union field virtual is renamed to virt for C++ compatibility.

+* Add new functions in ethdev to support IEEE1588: 
rte_eth_timesync_time_adjust()
+  rte_eth_timesync_time_get(), rte_eth_timesync_time_set()
+

 ABI Changes
 -----------
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index e0e1dca..20cf013 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3193,6 +3193,42 @@ rte_eth_timesync_read_tx_timestamp(uint8_t port_id, 
struct timespec *timestamp)
 }

 int
+rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta)
+{
+       struct rte_eth_dev *dev;
+
+       VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+       dev = &rte_eth_devices[port_id];
+
+       FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_adjust, -ENOTSUP);
+       return (*dev->dev_ops->timesync_time_adjust)(dev, delta);
+}
+
+int
+rte_eth_timesync_time_get(uint8_t port_id, struct timespec *timestamp)
+{
+       struct rte_eth_dev *dev;
+
+       VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+       dev = &rte_eth_devices[port_id];
+
+       FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_get, -ENOTSUP);
+       return (*dev->dev_ops->timesync_time_get)(dev, timestamp);
+}
+
+int
+rte_eth_timesync_time_set(uint8_t port_id, struct timespec *timestamp)
+{
+       struct rte_eth_dev *dev;
+
+       VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+       dev = &rte_eth_devices[port_id];
+
+       FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_time_set, -ENOTSUP);
+       return (*dev->dev_ops->timesync_time_set)(dev, timestamp);
+}
+
+int
 rte_eth_dev_get_reg_length(uint8_t port_id)
 {
        struct rte_eth_dev *dev;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 48a540d..585d980 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1206,6 +1206,17 @@ typedef int (*eth_timesync_read_tx_timestamp_t)(struct 
rte_eth_dev *dev,
                                                struct timespec *timestamp);
 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */

+typedef int (*eth_timesync_time_adjust)(struct rte_eth_dev *dev, int64_t);
+/**< @internal Function used to adjust device clock */
+
+typedef int (*eth_timesync_time_get)(struct rte_eth_dev *dev,
+                                               struct timespec *timestamp);
+/**< @internal Function used to get time from device clock. */
+
+typedef int (*eth_timesync_time_set)(struct rte_eth_dev *dev,
+                                               struct timespec *timestamp);
+/**< @internal Function used to get time from device clock */
+
 typedef int (*eth_get_reg_length_t)(struct rte_eth_dev *dev);
 /**< @internal Retrieve device register count  */

@@ -1400,6 +1411,12 @@ struct eth_dev_ops {

        /** Get DCB information */
        eth_get_dcb_info get_dcb_info;
+       /** Adjust the device clock */
+       eth_timesync_time_adjust timesync_time_adjust;
+       /** Get the device clock timespec */
+       eth_timesync_time_get timesync_time_get;
+       /** Set the device clock timespec */
+       eth_timesync_time_set timesync_time_set;
 };

 /**
@@ -3755,6 +3772,53 @@ extern int rte_eth_timesync_read_tx_timestamp(uint8_t 
port_id,
                                              struct timespec *timestamp);

 /**
+ * Adjust the timesync clock on an Ethernet device..
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param delta
+ *   The adjustment in nanoseconds
+ *
+ * @return
+ *   - 0: Success.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+extern int rte_eth_timesync_time_adjust(uint8_t port_id, int64_t delta);
+
+/**
+ * Read the time from the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the timespec struct.
+ *
+ * @return
+ *   - 0: Success.
+ */
+extern int rte_eth_timesync_time_get(uint8_t port_id,
+             struct timespec *time);
+
+
+/**
+ * Set the time of the timesync clock on an Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param time
+ *   Pointer to the timespec struct.
+ *
+ * @return
+ *   - 0: Success.
+ *   - -EINVAL: No timestamp is available.
+ *   - -ENODEV: The port ID is invalid.
+ *   - -ENOTSUP: The function is not supported by the Ethernet driver.
+ */
+extern int rte_eth_timesync_time_set(uint8_t port_id,
+             struct timespec *time);
+
+/**
  * Copy pci device info to the Ethernet device data.
  *
  * @param eth_dev
@@ -3767,7 +3831,6 @@ extern int rte_eth_timesync_read_tx_timestamp(uint8_t 
port_id,
  */
 extern void rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct 
rte_pci_device *pci_dev);

-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_ether/rte_ether_version.map 
b/lib/librte_ether/rte_ether_version.map
index 9149aa7..bb9c808 100644
--- a/lib/librte_ether/rte_ether_version.map
+++ b/lib/librte_ether/rte_ether_version.map
@@ -135,5 +135,8 @@ DPDK_2.2 {
        rte_eth_dev_get_dcb_info;
        rte_eth_rx_queue_info_get;
        rte_eth_tx_queue_info_get;
+       rte_eth_timesync_time_adjust;
+       rte_eth_timesync_time_get;
+       rte_eth_timesync_time_set;

 } DPDK_2.1;
-- 
2.5.0

Reply via email to