LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_nix_ptp.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 57 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 30 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "roc_api.h"
       6                 :            : #include "roc_priv.h"
       7                 :            : 
       8                 :            : #define PTP_FREQ_ADJUST (1 << 9)
       9                 :            : 
      10                 :            : int
      11                 :          0 : roc_nix_ptp_rx_ena_dis(struct roc_nix *roc_nix, int enable)
      12                 :            : {
      13                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      14                 :            :         struct dev *dev = &nix->dev;
      15                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      16                 :            :         int rc;
      17                 :            : 
      18   [ #  #  #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix)) {
      19                 :            :                 rc = NIX_ERR_PARAM;
      20                 :          0 :                 goto exit;
      21                 :            :         }
      22                 :            : 
      23         [ #  # ]:          0 :         if (enable)
      24                 :          0 :                 mbox_alloc_msg_cgx_ptp_rx_enable(mbox);
      25                 :            :         else
      26                 :          0 :                 mbox_alloc_msg_cgx_ptp_rx_disable(mbox);
      27                 :            : 
      28                 :          0 :         rc = mbox_process(mbox);
      29                 :          0 : exit:
      30                 :            :         mbox_put(mbox);
      31                 :          0 :         return rc;
      32                 :            : }
      33                 :            : 
      34                 :            : int
      35                 :          0 : roc_nix_ptp_tx_ena_dis(struct roc_nix *roc_nix, int enable)
      36                 :            : {
      37                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      38                 :            :         struct dev *dev = &nix->dev;
      39                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      40                 :            :         int rc;
      41                 :            : 
      42   [ #  #  #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix)) {
      43                 :            :                 rc = NIX_ERR_PARAM;
      44                 :          0 :                 goto exit;
      45                 :            :         }
      46                 :            : 
      47         [ #  # ]:          0 :         if (enable)
      48                 :          0 :                 mbox_alloc_msg_nix_lf_ptp_tx_enable(mbox);
      49                 :            :         else
      50                 :          0 :                 mbox_alloc_msg_nix_lf_ptp_tx_disable(mbox);
      51                 :            : 
      52                 :          0 :         rc = mbox_process(mbox);
      53                 :          0 : exit:
      54                 :            :         mbox_put(mbox);
      55                 :          0 :         return rc;
      56                 :            : }
      57                 :            : 
      58                 :            : int
      59                 :          0 : roc_nix_ptp_clock_read(struct roc_nix *roc_nix, uint64_t *clock, uint64_t *tsc,
      60                 :            :                        uint8_t is_pmu)
      61                 :            : {
      62                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      63                 :            :         struct dev *dev = &nix->dev;
      64                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      65                 :            :         struct ptp_req *req;
      66                 :            :         struct ptp_rsp *rsp;
      67                 :            :         int rc = -ENOSPC;
      68                 :            : 
      69                 :          0 :         req = mbox_alloc_msg_ptp_op(mbox);
      70         [ #  # ]:          0 :         if (req == NULL)
      71                 :          0 :                 goto exit;
      72                 :          0 :         req->op = PTP_OP_GET_CLOCK;
      73                 :          0 :         req->is_pmu = is_pmu;
      74                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
      75         [ #  # ]:          0 :         if (rc)
      76                 :          0 :                 goto exit;
      77                 :            : 
      78         [ #  # ]:          0 :         if (clock)
      79                 :          0 :                 *clock = rsp->clk;
      80                 :            : 
      81         [ #  # ]:          0 :         if (tsc)
      82                 :          0 :                 *tsc = rsp->tsc;
      83                 :            : 
      84                 :            :         rc = 0;
      85                 :          0 : exit:
      86                 :            :         mbox_put(mbox);
      87                 :          0 :         return rc;
      88                 :            : }
      89                 :            : 
      90                 :            : int
      91                 :          0 : roc_nix_ptp_sync_time_adjust(struct roc_nix *roc_nix, int64_t delta)
      92                 :            : {
      93                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      94                 :            :         struct dev *dev = &nix->dev;
      95                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      96                 :            :         struct ptp_req *req;
      97                 :            :         struct ptp_rsp *rsp;
      98                 :            :         int rc = -ENOSPC;
      99                 :            : 
     100   [ #  #  #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix)) {
     101                 :            :                 rc = NIX_ERR_PARAM;
     102                 :          0 :                 goto exit;
     103                 :            :         }
     104                 :            : 
     105         [ #  # ]:          0 :         if ((delta <= -PTP_FREQ_ADJUST) || (delta >= PTP_FREQ_ADJUST)) {
     106                 :            :                 rc = NIX_ERR_INVALID_RANGE;
     107                 :          0 :                 goto exit;
     108                 :            :         }
     109                 :            : 
     110                 :          0 :         req = mbox_alloc_msg_ptp_op(mbox);
     111         [ #  # ]:          0 :         if (req == NULL)
     112                 :          0 :                 goto exit;
     113                 :          0 :         req->op = PTP_OP_ADJFINE;
     114                 :          0 :         req->scaled_ppm = delta;
     115                 :            : 
     116                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     117                 :          0 : exit:
     118                 :            :         mbox_put(mbox);
     119                 :          0 :         return rc;
     120                 :            : }
     121                 :            : 
     122                 :            : int
     123                 :          0 : roc_nix_ptp_info_cb_register(struct roc_nix *roc_nix,
     124                 :            :                              ptp_info_update_t ptp_update)
     125                 :            : {
     126                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     127                 :            :         struct dev *dev = &nix->dev;
     128                 :            : 
     129         [ #  # ]:          0 :         if (ptp_update == NULL)
     130                 :            :                 return NIX_ERR_PARAM;
     131                 :            : 
     132                 :          0 :         dev->ops->ptp_info_update = (ptp_info_t)ptp_update;
     133                 :          0 :         return 0;
     134                 :            : }
     135                 :            : 
     136                 :            : void
     137                 :          0 : roc_nix_ptp_info_cb_unregister(struct roc_nix *roc_nix)
     138                 :            : {
     139                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     140                 :            :         struct dev *dev = &nix->dev;
     141                 :            : 
     142                 :          0 :         dev->ops->ptp_info_update = NULL;
     143                 :          0 : }
     144                 :            : 
     145                 :            : bool
     146                 :          0 : roc_nix_ptp_is_enable(struct roc_nix *roc_nix)
     147                 :            : {
     148                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     149                 :            : 
     150                 :          0 :         return nix->ptp_en;
     151                 :            : }

Generated by: LCOV version 1.14