Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2019, 2023 NXP
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : :
13 : : #include <ethdev_driver.h>
14 : : #include <rte_log.h>
15 : : #include <rte_eth_ctrl.h>
16 : : #include <rte_malloc.h>
17 : : #include <rte_time.h>
18 : :
19 : : #include <bus_fslmc_driver.h>
20 : : #include <fsl_dprtc.h>
21 : : #include <fsl_dpkg.h>
22 : :
23 : : #include <dpaa2_ethdev.h>
24 : : #include <dpaa2_pmd_logs.h>
25 : :
26 : : struct dpaa2_dprtc_dev {
27 : : struct fsl_mc_io dprtc; /** handle to DPRTC portal object */
28 : : uint16_t token;
29 : : uint32_t dprtc_id; /*HW ID for DPRTC object */
30 : : };
31 : : static struct dpaa2_dprtc_dev *dprtc_dev;
32 : :
33 : 0 : int dpaa2_timesync_enable(struct rte_eth_dev *dev __rte_unused)
34 : : {
35 : 0 : return 0;
36 : : }
37 : :
38 : 0 : int dpaa2_timesync_disable(struct rte_eth_dev *dev __rte_unused)
39 : : {
40 : 0 : return 0;
41 : : }
42 : :
43 : 0 : int dpaa2_timesync_read_time(struct rte_eth_dev *dev,
44 : : struct timespec *timestamp)
45 : : {
46 : : uint64_t ns;
47 : : int ret = 0;
48 : :
49 : : RTE_SET_USED(dev);
50 : :
51 : 0 : ret = dprtc_get_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
52 : 0 : dprtc_dev->token, &ns);
53 [ # # ]: 0 : if (ret) {
54 : 0 : DPAA2_PMD_ERR("dprtc_get_time failed ret: %d", ret);
55 : 0 : return ret;
56 : : }
57 : :
58 [ # # ]: 0 : *timestamp = rte_ns_to_timespec(ns);
59 : :
60 : 0 : return 0;
61 : : }
62 : :
63 : 0 : int dpaa2_timesync_write_time(struct rte_eth_dev *dev,
64 : : const struct timespec *ts)
65 : : {
66 : : uint64_t ns;
67 : : int ret = 0;
68 : :
69 : : RTE_SET_USED(dev);
70 : :
71 : : ns = rte_timespec_to_ns(ts);
72 : :
73 : 0 : ret = dprtc_set_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
74 : 0 : dprtc_dev->token, ns);
75 [ # # ]: 0 : if (ret) {
76 : 0 : DPAA2_PMD_ERR("dprtc_set_time failed ret: %d", ret);
77 : 0 : return ret;
78 : : }
79 : :
80 : : return 0;
81 : : }
82 : :
83 : 0 : int dpaa2_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
84 : : {
85 : : uint64_t ns;
86 : : int ret = 0;
87 : :
88 : : RTE_SET_USED(dev);
89 : :
90 : 0 : ret = dprtc_get_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
91 : 0 : dprtc_dev->token, &ns);
92 [ # # ]: 0 : if (ret) {
93 : 0 : DPAA2_PMD_ERR("dprtc_get_time failed ret: %d", ret);
94 : 0 : return ret;
95 : : }
96 : :
97 : 0 : ns += delta;
98 : :
99 : 0 : ret = dprtc_set_time(&dprtc_dev->dprtc, CMD_PRI_LOW,
100 : 0 : dprtc_dev->token, ns);
101 [ # # ]: 0 : if (ret) {
102 : 0 : DPAA2_PMD_ERR("dprtc_set_time failed ret: %d", ret);
103 : 0 : return ret;
104 : : }
105 : :
106 : : return 0;
107 : : }
108 : :
109 : 0 : int dpaa2_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
110 : : struct timespec *timestamp)
111 : : {
112 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
113 : :
114 [ # # ]: 0 : if (priv->next_tx_conf_queue) {
115 [ # # ]: 0 : while (!priv->tx_timestamp)
116 : 0 : dpaa2_dev_tx_conf(priv->next_tx_conf_queue);
117 : : } else {
118 : : return -1;
119 : : }
120 : 0 : *timestamp = rte_ns_to_timespec(priv->tx_timestamp);
121 : :
122 : 0 : return 0;
123 : : }
124 : :
125 : 0 : int dpaa2_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
126 : : struct timespec *timestamp,
127 : : uint32_t flags __rte_unused)
128 : : {
129 : 0 : struct dpaa2_dev_priv *priv = dev->data->dev_private;
130 [ # # ]: 0 : *timestamp = rte_ns_to_timespec(priv->rx_timestamp);
131 : 0 : return 0;
132 : : }
133 : :
134 : : #if defined(RTE_LIBRTE_IEEE1588)
135 : : static int
136 : : dpaa2_create_dprtc_device(int vdev_fd __rte_unused,
137 : : struct vfio_device_info *obj_info __rte_unused,
138 : : struct rte_dpaa2_device *obj)
139 : : {
140 : : struct dprtc_attr attr;
141 : : int ret, dprtc_id = obj->object_id;
142 : :
143 : : PMD_INIT_FUNC_TRACE();
144 : :
145 : : /* Allocate DPAA2 dprtc handle */
146 : : dprtc_dev = rte_malloc(NULL, sizeof(struct dpaa2_dprtc_dev), 0);
147 : : if (!dprtc_dev) {
148 : : DPAA2_PMD_ERR("Memory allocation failed for DPRTC Device");
149 : : return -1;
150 : : }
151 : :
152 : : /* Open the dprtc object */
153 : : dprtc_dev->dprtc.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
154 : : ret = dprtc_open(&dprtc_dev->dprtc, CMD_PRI_LOW, dprtc_id,
155 : : &dprtc_dev->token);
156 : : if (ret) {
157 : : DPAA2_PMD_ERR("Unable to open dprtc object: err(%d)", ret);
158 : : goto init_err;
159 : : }
160 : :
161 : : ret = dprtc_get_attributes(&dprtc_dev->dprtc, CMD_PRI_LOW,
162 : : dprtc_dev->token, &attr);
163 : : if (ret) {
164 : : DPAA2_PMD_ERR("Unable to get dprtc attr: err(%d)", ret);
165 : : goto init_err;
166 : : }
167 : :
168 : : dprtc_dev->dprtc_id = dprtc_id;
169 : :
170 : : return 0;
171 : :
172 : : init_err:
173 : : rte_free(dprtc_dev);
174 : :
175 : : return -1;
176 : : }
177 : :
178 : : static struct rte_dpaa2_object rte_dpaa2_dprtc_obj = {
179 : : .dev_type = DPAA2_DPRTC,
180 : : .create = dpaa2_create_dprtc_device,
181 : : };
182 : :
183 : : RTE_PMD_REGISTER_DPAA2_OBJECT(dprtc, rte_dpaa2_dprtc_obj);
184 : : #endif
|