1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2022-2024 NXP 3 */ 4 5 /* System headers */ 6 #include <stdio.h> 7 #include <inttypes.h> 8 #include <unistd.h> 9 10 #include <rte_ethdev.h> 11 #include <rte_log.h> 12 #include <rte_eth_ctrl.h> 13 #include <rte_malloc.h> 14 #include <rte_time.h> 15 16 #include <dpaa_ethdev.h> 17 #include <dpaa_rxtx.h> 18 19 int 20 dpaa_timesync_enable(struct rte_eth_dev *dev __rte_unused) 21 { 22 return 0; 23 } 24 25 int 26 dpaa_timesync_disable(struct rte_eth_dev *dev __rte_unused) 27 { 28 return 0; 29 } 30 31 int 32 dpaa_timesync_read_time(struct rte_eth_dev *dev, 33 struct timespec *timestamp) 34 { 35 uint32_t *tmr_cnt_h, *tmr_cnt_l; 36 struct __fman_if *__fif; 37 struct fman_if *fif; 38 uint64_t time; 39 40 fif = dev->process_private; 41 __fif = container_of(fif, struct __fman_if, __if); 42 43 tmr_cnt_h = &((struct rtc_regs *)__fif->rtc_map)->tmr_cnt_h; 44 tmr_cnt_l = &((struct rtc_regs *)__fif->rtc_map)->tmr_cnt_l; 45 46 time = (uint64_t)in_be32(tmr_cnt_l); 47 time |= ((uint64_t)in_be32(tmr_cnt_h) << 32); 48 49 *timestamp = rte_ns_to_timespec(time); 50 return 0; 51 } 52 53 int 54 dpaa_timesync_write_time(struct rte_eth_dev *dev, 55 const struct timespec *ts) 56 { 57 uint32_t *tmr_cnt_h, *tmr_cnt_l; 58 struct __fman_if *__fif; 59 struct fman_if *fif; 60 uint64_t time; 61 62 fif = dev->process_private; 63 __fif = container_of(fif, struct __fman_if, __if); 64 65 tmr_cnt_h = &((struct rtc_regs *)__fif->rtc_map)->tmr_cnt_h; 66 tmr_cnt_l = &((struct rtc_regs *)__fif->rtc_map)->tmr_cnt_l; 67 68 time = rte_timespec_to_ns(ts); 69 70 out_be32(tmr_cnt_l, (uint32_t)time); 71 out_be32(tmr_cnt_h, (uint32_t)(time >> 32)); 72 73 return 0; 74 } 75 76 int 77 dpaa_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta) 78 { 79 struct timespec ts = {0, 0}, *timestamp = &ts; 80 uint64_t ns; 81 82 dpaa_timesync_read_time(dev, timestamp); 83 84 ns = rte_timespec_to_ns(timestamp); 85 ns += delta; 86 *timestamp = rte_ns_to_timespec(ns); 87 88 dpaa_timesync_write_time(dev, timestamp); 89 90 return 0; 91 } 92 93 int 94 dpaa_timesync_read_tx_timestamp(struct rte_eth_dev *dev, 95 struct timespec *timestamp) 96 { 97 struct dpaa_if *dpaa_intf = dev->data->dev_private; 98 99 if (dpaa_intf->next_tx_conf_queue) { 100 while (!dpaa_intf->tx_timestamp) 101 dpaa_eth_tx_conf(dpaa_intf->next_tx_conf_queue); 102 } else { 103 return -1; 104 } 105 *timestamp = rte_ns_to_timespec(dpaa_intf->tx_timestamp); 106 107 return 0; 108 } 109 110 int 111 dpaa_timesync_read_rx_timestamp(struct rte_eth_dev *dev, 112 struct timespec *timestamp, 113 uint32_t flags __rte_unused) 114 { 115 struct dpaa_if *dpaa_intf = dev->data->dev_private; 116 *timestamp = rte_ns_to_timespec(dpaa_intf->rx_timestamp); 117 return 0; 118 } 119