1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
8 #define PTP_FREQ_ADJUST (1 << 9)
10 static inline struct mbox *
11 get_mbox(struct roc_nix *roc_nix)
13 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
14 struct dev *dev = &nix->dev;
20 roc_nix_ptp_rx_ena_dis(struct roc_nix *roc_nix, int enable)
22 struct mbox *mbox = get_mbox(roc_nix);
24 if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
28 mbox_alloc_msg_cgx_ptp_rx_enable(mbox);
30 mbox_alloc_msg_cgx_ptp_rx_disable(mbox);
32 return mbox_process(mbox);
36 roc_nix_ptp_tx_ena_dis(struct roc_nix *roc_nix, int enable)
38 struct mbox *mbox = get_mbox(roc_nix);
40 if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
44 mbox_alloc_msg_nix_lf_ptp_tx_enable(mbox);
46 mbox_alloc_msg_nix_lf_ptp_tx_disable(mbox);
48 return mbox_process(mbox);
52 roc_nix_ptp_clock_read(struct roc_nix *roc_nix, uint64_t *clock, uint64_t *tsc,
55 struct mbox *mbox = get_mbox(roc_nix);
60 req = mbox_alloc_msg_ptp_op(mbox);
63 req->op = PTP_OP_GET_CLOCK;
65 rc = mbox_process_msg(mbox, (void *)&rsp);
79 roc_nix_ptp_sync_time_adjust(struct roc_nix *roc_nix, int64_t delta)
81 struct mbox *mbox = get_mbox(roc_nix);
86 if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
89 if ((delta <= -PTP_FREQ_ADJUST) || (delta >= PTP_FREQ_ADJUST))
90 return NIX_ERR_INVALID_RANGE;
92 req = mbox_alloc_msg_ptp_op(mbox);
95 req->op = PTP_OP_ADJFINE;
96 req->scaled_ppm = delta;
98 return mbox_process_msg(mbox, (void *)&rsp);
102 roc_nix_ptp_info_cb_register(struct roc_nix *roc_nix,
103 ptp_info_update_t ptp_update)
105 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
106 struct dev *dev = &nix->dev;
108 if (ptp_update == NULL)
109 return NIX_ERR_PARAM;
111 dev->ops->ptp_info_update = (ptp_info_t)ptp_update;
116 roc_nix_ptp_info_cb_unregister(struct roc_nix *roc_nix)
118 struct nix *nix = roc_nix_to_nix_priv(roc_nix);
119 struct dev *dev = &nix->dev;
121 dev->ops->ptp_info_update = NULL;