1 /* SPDX-License-Identifier: BSD-3-Clause
13 #include <rte_ethdev.h>
15 #include <rte_eth_ctrl.h>
16 #include <rte_malloc.h>
19 #include <rte_fslmc.h>
20 #include <fsl_dprtc.h>
23 #include <dpaa2_ethdev.h>
24 #include <dpaa2_pmd_logs.h>
26 struct dpaa2_dprtc_dev {
27 struct fsl_mc_io dprtc; /** handle to DPRTC portal object */
29 uint32_t dprtc_id; /*HW ID for DPRTC object */
31 static struct dpaa2_dprtc_dev *dprtc_dev;
33 int dpaa2_timesync_enable(struct rte_eth_dev *dev __rte_unused)
38 int dpaa2_timesync_disable(struct rte_eth_dev *dev __rte_unused)
43 int dpaa2_timesync_read_time(struct rte_eth_dev *dev,
44 struct timespec *timestamp)
51 ret = dprtc_get_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
52 dprtc_dev->token, &ns);
54 DPAA2_PMD_ERR("dprtc_get_time failed ret: %d", ret);
58 *timestamp = rte_ns_to_timespec(ns);
63 int dpaa2_timesync_write_time(struct rte_eth_dev *dev,
64 const struct timespec *ts)
71 ns = rte_timespec_to_ns(ts);
73 ret = dprtc_set_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
74 dprtc_dev->token, ns);
76 DPAA2_PMD_ERR("dprtc_set_time failed ret: %d", ret);
83 int dpaa2_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
90 ret = dprtc_get_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
91 dprtc_dev->token, &ns);
93 DPAA2_PMD_ERR("dprtc_get_time failed ret: %d", ret);
99 ret = dprtc_set_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
100 dprtc_dev->token, ns);
102 DPAA2_PMD_ERR("dprtc_set_time failed ret: %d", ret);
109 int dpaa2_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
110 struct timespec *timestamp)
112 struct dpaa2_dev_priv *priv = dev->data->dev_private;
114 if (priv->next_tx_conf_queue)
115 dpaa2_dev_tx_conf(priv->next_tx_conf_queue);
118 *timestamp = rte_ns_to_timespec(priv->tx_timestamp);
123 int dpaa2_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
124 struct timespec *timestamp,
125 uint32_t flags __rte_unused)
127 struct dpaa2_dev_priv *priv = dev->data->dev_private;
128 *timestamp = rte_ns_to_timespec(priv->rx_timestamp);
133 dpaa2_create_dprtc_device(int vdev_fd __rte_unused,
134 struct vfio_device_info *obj_info __rte_unused,
137 struct dprtc_attr attr;
140 PMD_INIT_FUNC_TRACE();
142 /* Allocate DPAA2 dprtc handle */
143 dprtc_dev = rte_malloc(NULL, sizeof(struct dpaa2_dprtc_dev), 0);
145 DPAA2_PMD_ERR("Memory allocation failed for DPRTC Device");
149 /* Open the dprtc object */
150 dprtc_dev->dprtc.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
151 ret = dprtc_open(&dprtc_dev->dprtc, CMD_PRI_LOW, dprtc_id,
154 DPAA2_PMD_ERR("Unable to open dprtc object: err(%d)", ret);
158 ret = dprtc_get_attributes(&dprtc_dev->dprtc, CMD_PRI_LOW,
159 dprtc_dev->token, &attr);
161 DPAA2_PMD_ERR("Unable to get dprtc attr: err(%d)", ret);
165 dprtc_dev->dprtc_id = dprtc_id;
176 static struct rte_dpaa2_object rte_dpaa2_dprtc_obj = {
177 .dev_type = DPAA2_DPRTC,
178 .create = dpaa2_create_dprtc_device,
181 RTE_PMD_REGISTER_DPAA2_OBJECT(dprtc, rte_dpaa2_dprtc_obj);