LCOV - code coverage report
Current view: top level - drivers/net/dpaa - dpaa_ptp.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 50 0.0 %
Date: 2025-12-01 19:08:10 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 32 0.0 %

           Branch data     Line data    Source code
       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                 :          0 : dpaa_timesync_enable(struct rte_eth_dev *dev)
      21                 :            : {
      22                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
      23                 :            :         int loop, ret = 0;
      24                 :            : 
      25         [ #  # ]:          0 :         for (loop = 0; loop < MAX_DPAA_CORES; loop++) {
      26         [ #  # ]:          0 :                 if (!dpaa_intf->tx_queues[loop].tx_conf_queue) {
      27                 :          0 :                         ret = dpaa_tx_conf_queue_init(&dpaa_intf->tx_conf_queues[loop]);
      28         [ #  # ]:          0 :                         if (ret)
      29                 :            :                                 break;
      30                 :          0 :                         dpaa_intf->tx_conf_queues[loop].dpaa_intf = dpaa_intf;
      31                 :          0 :                         dpaa_intf->tx_queues[loop].tx_conf_queue = &dpaa_intf->tx_conf_queues[loop];
      32                 :            :                 }
      33                 :            :         }
      34                 :            : 
      35         [ #  # ]:          0 :         if (ret)
      36                 :            :                 return ret;
      37                 :            : 
      38                 :          0 :         dpaa_intf->ts_enable = true;
      39                 :          0 :         return 0;
      40                 :            : }
      41                 :            : 
      42                 :            : int
      43                 :          0 : dpaa_timesync_disable(struct rte_eth_dev *dev)
      44                 :            : {
      45                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
      46                 :            : 
      47                 :          0 :         dpaa_intf->ts_enable = false;
      48                 :          0 :         return 0;
      49                 :            : }
      50                 :            : 
      51                 :            : int
      52                 :          0 : dpaa_timesync_read_time(struct rte_eth_dev *dev,
      53                 :            :         struct timespec *timestamp)
      54                 :            : {
      55                 :            :         uint32_t *tmr_cnt_h, *tmr_cnt_l;
      56                 :            :         struct fman_if *fif;
      57                 :            :         uint64_t time;
      58                 :            : 
      59                 :          0 :         fif = dev->process_private;
      60                 :            : 
      61                 :          0 :         tmr_cnt_h = &((struct rtc_regs *)fif->fman->time_vir)->tmr_cnt_h;
      62                 :            :         tmr_cnt_l = &((struct rtc_regs *)fif->fman->time_vir)->tmr_cnt_l;
      63                 :            : 
      64                 :          0 :         time = (uint64_t)in_be32(tmr_cnt_l);
      65         [ #  # ]:          0 :         time |= ((uint64_t)in_be32(tmr_cnt_h) << 32);
      66                 :            : 
      67                 :          0 :         *timestamp = rte_ns_to_timespec(time);
      68                 :          0 :         return 0;
      69                 :            : }
      70                 :            : 
      71                 :            : int
      72                 :          0 : dpaa_timesync_write_time(struct rte_eth_dev *dev,
      73                 :            :         const struct timespec *ts)
      74                 :            : {
      75                 :            :         uint32_t *tmr_cnt_h, *tmr_cnt_l;
      76                 :            :         struct fman_if *fif;
      77                 :            :         uint64_t time;
      78                 :            : 
      79                 :          0 :         fif = dev->process_private;
      80                 :            : 
      81         [ #  # ]:          0 :         tmr_cnt_h = &((struct rtc_regs *)fif->fman->time_vir)->tmr_cnt_h;
      82                 :            :         tmr_cnt_l = &((struct rtc_regs *)fif->fman->time_vir)->tmr_cnt_l;
      83                 :            : 
      84                 :            :         time = rte_timespec_to_ns(ts);
      85                 :            : 
      86         [ #  # ]:          0 :         out_be32(tmr_cnt_l, (uint32_t)time);
      87         [ #  # ]:          0 :         out_be32(tmr_cnt_h, (uint32_t)(time >> 32));
      88                 :            : 
      89                 :          0 :         return 0;
      90                 :            : }
      91                 :            : 
      92                 :            : int
      93                 :          0 : dpaa_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
      94                 :            : {
      95                 :          0 :         struct timespec ts = {0, 0}, *timestamp = &ts;
      96                 :            :         uint64_t ns;
      97                 :            : 
      98                 :          0 :         dpaa_timesync_read_time(dev, timestamp);
      99                 :            : 
     100                 :            :         ns = rte_timespec_to_ns(timestamp);
     101         [ #  # ]:          0 :         ns += delta;
     102                 :          0 :         *timestamp = rte_ns_to_timespec(ns);
     103                 :            : 
     104                 :          0 :         dpaa_timesync_write_time(dev, timestamp);
     105                 :            : 
     106                 :          0 :         return 0;
     107                 :            : }
     108                 :            : 
     109                 :            : int
     110                 :          0 : dpaa_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
     111                 :            :         struct timespec *timestamp)
     112                 :            : {
     113                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     114                 :            :         int read_count = 10000;
     115                 :            : 
     116   [ #  #  #  # ]:          0 :         if (dpaa_intf->ts_enable && dpaa_intf->next_tx_conf_queue) {
     117         [ #  # ]:          0 :                 while (dpaa_intf->tx_timestamp == dpaa_intf->tx_old_timestamp) {
     118                 :          0 :                         dpaa_eth_tx_conf(dpaa_intf->next_tx_conf_queue);
     119         [ #  # ]:          0 :                         if (read_count <= 0)
     120                 :            :                                 return -EAGAIN;
     121                 :          0 :                         read_count--;
     122                 :            :                 }
     123         [ #  # ]:          0 :                 dpaa_intf->tx_old_timestamp = dpaa_intf->tx_timestamp;
     124                 :            :         } else {
     125                 :            :                 return -ENOTSUP;
     126                 :            :         }
     127                 :          0 :         *timestamp = rte_ns_to_timespec(dpaa_intf->tx_timestamp);
     128                 :            : 
     129                 :          0 :         return 0;
     130                 :            : }
     131                 :            : 
     132                 :            : int
     133                 :          0 : dpaa_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
     134                 :            :         struct timespec *timestamp, uint32_t flags __rte_unused)
     135                 :            : {
     136                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     137                 :            : 
     138         [ #  # ]:          0 :         if (!dpaa_intf->ts_enable)
     139                 :            :                 return -ENOTSUP;
     140                 :            : 
     141         [ #  # ]:          0 :         *timestamp = rte_ns_to_timespec(dpaa_intf->rx_timestamp);
     142                 :            : 
     143                 :          0 :         return 0;
     144                 :            : }

Generated by: LCOV version 1.14