dpdk/drivers/common/cnxk/roc_nix_ptp.c
<<
>>
Prefs
   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
  10static inline struct mbox *
  11get_mbox(struct roc_nix *roc_nix)
  12{
  13        struct nix *nix = roc_nix_to_nix_priv(roc_nix);
  14        struct dev *dev = &nix->dev;
  15
  16        return dev->mbox;
  17}
  18
  19int
  20roc_nix_ptp_rx_ena_dis(struct roc_nix *roc_nix, int enable)
  21{
  22        struct mbox *mbox = get_mbox(roc_nix);
  23
  24        if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
  25                return NIX_ERR_PARAM;
  26
  27        if (enable)
  28                mbox_alloc_msg_cgx_ptp_rx_enable(mbox);
  29        else
  30                mbox_alloc_msg_cgx_ptp_rx_disable(mbox);
  31
  32        return mbox_process(mbox);
  33}
  34
  35int
  36roc_nix_ptp_tx_ena_dis(struct roc_nix *roc_nix, int enable)
  37{
  38        struct mbox *mbox = get_mbox(roc_nix);
  39
  40        if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
  41                return NIX_ERR_PARAM;
  42
  43        if (enable)
  44                mbox_alloc_msg_nix_lf_ptp_tx_enable(mbox);
  45        else
  46                mbox_alloc_msg_nix_lf_ptp_tx_disable(mbox);
  47
  48        return mbox_process(mbox);
  49}
  50
  51int
  52roc_nix_ptp_clock_read(struct roc_nix *roc_nix, uint64_t *clock, uint64_t *tsc,
  53                       uint8_t is_pmu)
  54{
  55        struct mbox *mbox = get_mbox(roc_nix);
  56        struct ptp_req *req;
  57        struct ptp_rsp *rsp;
  58        int rc = -ENOSPC;
  59
  60        req = mbox_alloc_msg_ptp_op(mbox);
  61        if (req == NULL)
  62                return rc;
  63        req->op = PTP_OP_GET_CLOCK;
  64        req->is_pmu = is_pmu;
  65        rc = mbox_process_msg(mbox, (void *)&rsp);
  66        if (rc)
  67                return rc;
  68
  69        if (clock)
  70                *clock = rsp->clk;
  71
  72        if (tsc)
  73                *tsc = rsp->tsc;
  74
  75        return 0;
  76}
  77
  78int
  79roc_nix_ptp_sync_time_adjust(struct roc_nix *roc_nix, int64_t delta)
  80{
  81        struct mbox *mbox = get_mbox(roc_nix);
  82        struct ptp_req *req;
  83        struct ptp_rsp *rsp;
  84        int rc = -ENOSPC;
  85
  86        if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
  87                return NIX_ERR_PARAM;
  88
  89        if ((delta <= -PTP_FREQ_ADJUST) || (delta >= PTP_FREQ_ADJUST))
  90                return NIX_ERR_INVALID_RANGE;
  91
  92        req = mbox_alloc_msg_ptp_op(mbox);
  93        if (req == NULL)
  94                return rc;
  95        req->op = PTP_OP_ADJFINE;
  96        req->scaled_ppm = delta;
  97
  98        return mbox_process_msg(mbox, (void *)&rsp);
  99}
 100
 101int
 102roc_nix_ptp_info_cb_register(struct roc_nix *roc_nix,
 103                             ptp_info_update_t ptp_update)
 104{
 105        struct nix *nix = roc_nix_to_nix_priv(roc_nix);
 106        struct dev *dev = &nix->dev;
 107
 108        if (ptp_update == NULL)
 109                return NIX_ERR_PARAM;
 110
 111        dev->ops->ptp_info_update = (ptp_info_t)ptp_update;
 112        return 0;
 113}
 114
 115void
 116roc_nix_ptp_info_cb_unregister(struct roc_nix *roc_nix)
 117{
 118        struct nix *nix = roc_nix_to_nix_priv(roc_nix);
 119        struct dev *dev = &nix->dev;
 120
 121        dev->ops->ptp_info_update = NULL;
 122}
 123
 124bool
 125roc_nix_ptp_is_enable(struct roc_nix *roc_nix)
 126{
 127        struct nix *nix = roc_nix_to_nix_priv(roc_nix);
 128
 129        return nix->ptp_en;
 130}
 131