From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8C3ADA0547; Fri, 5 Mar 2021 14:44:10 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D416722A3EB; Fri, 5 Mar 2021 14:40:50 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 51C0622A3CD for ; Fri, 5 Mar 2021 14:40:48 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 125DelHT001661 for ; Fri, 5 Mar 2021 05:40:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=x6Kz+rXR48+KFrokThaNi2ApAYBf/m0WQf95TF1W1Gk=; b=Zc1VTsAn0yWvat7+bphDbonT4isaBINuMn/XddQKi+OwGFA65ViMfbVVqXIwFeGcSvux 6NeB11LCQqP3AVHk49nAz85G+pdrrfOlYDA9wLFFp38lspxtD0M/cQ9CDgNPxwL/Tl2v po72MVbl+E4ui5u0PfWT2VVAHlaRBd3bFDJPHAcjlTHrSIgMiyipvLhomN8+HsKOjMcV 4qi/P8FwO1KtCM1Hsy3i0FkPjLWbyPlDTcEJ63zVY0Xk7SrYh4I8pCZvwPfXYWQvmlkC Bt1JFHL2NUFUklNTcB3U7koEYBeShoCeDFUkmIlLUG3GjgSavHCwbrGuH1ZKR2fnczLm ig== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 372s2umrpa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 05 Mar 2021 05:40:47 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 5 Mar 2021 05:40:44 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 5 Mar 2021 05:40:43 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 5 Mar 2021 05:40:43 -0800 Received: from hyd1588t430.marvell.com (unknown [10.29.52.204]) by maili.marvell.com (Postfix) with ESMTP id 6E1C23F703F; Fri, 5 Mar 2021 05:40:41 -0800 (PST) From: Nithin Dabilpuram To: CC: , , , , , , Date: Fri, 5 Mar 2021 19:08:51 +0530 Message-ID: <20210305133918.8005-26-ndabilpuram@marvell.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20210305133918.8005-1-ndabilpuram@marvell.com> References: <20210305133918.8005-1-ndabilpuram@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.761 definitions=2021-03-05_08:2021-03-03, 2021-03-05 signatures=0 Subject: [dpdk-dev] [PATCH 25/52] common/cnxk: add nix ptp support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Sunil Kumar Kori Add support to enable/disable Rx and Tx PTP timestamping support. Also provide API's to register ptp info callbacks to get config change update from Kernel. Signed-off-by: Sunil Kumar Kori --- drivers/common/cnxk/meson.build | 1 + drivers/common/cnxk/roc_nix.h | 11 ++++ drivers/common/cnxk/roc_nix_ptp.c | 122 ++++++++++++++++++++++++++++++++++++++ drivers/common/cnxk/version.map | 6 ++ 4 files changed, 140 insertions(+) create mode 100644 drivers/common/cnxk/roc_nix_ptp.c diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build index 36c3ada..65dadd9 100644 --- a/drivers/common/cnxk/meson.build +++ b/drivers/common/cnxk/meson.build @@ -21,6 +21,7 @@ sources = files('roc_dev.c', 'roc_nix_mac.c', 'roc_nix_mcast.c', 'roc_nix_npc.c', + 'roc_nix_ptp.c', 'roc_nix_queue.c', 'roc_nix_rss.c', 'roc_npa.c', diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h index 0409040..90a5ac9 100644 --- a/drivers/common/cnxk/roc_nix.h +++ b/drivers/common/cnxk/roc_nix.h @@ -244,6 +244,17 @@ int __roc_api roc_nix_cq_fini(struct roc_nix_cq *cq); int __roc_api roc_nix_sq_init(struct roc_nix *roc_nix, struct roc_nix_sq *sq); int __roc_api roc_nix_sq_fini(struct roc_nix_sq *sq); +/* PTP */ +int __roc_api roc_nix_ptp_rx_ena_dis(struct roc_nix *roc_nix, int enable); +int __roc_api roc_nix_ptp_tx_ena_dis(struct roc_nix *roc_nix, int enable); +int __roc_api roc_nix_ptp_clock_read(struct roc_nix *roc_nix, uint64_t *clock, + uint64_t *tsc, uint8_t is_pmu); +int __roc_api roc_nix_ptp_sync_time_adjust(struct roc_nix *roc_nix, + int64_t delta); +int __roc_api roc_nix_ptp_info_cb_register(struct roc_nix *roc_nix, + ptp_info_update_t ptp_update); +void __roc_api roc_nix_ptp_info_cb_unregister(struct roc_nix *roc_nix); + /* MCAST*/ int __roc_api roc_nix_mcast_mcam_entry_alloc(struct roc_nix *roc_nix, uint16_t nb_entries, diff --git a/drivers/common/cnxk/roc_nix_ptp.c b/drivers/common/cnxk/roc_nix_ptp.c new file mode 100644 index 0000000..05c40ca --- /dev/null +++ b/drivers/common/cnxk/roc_nix_ptp.c @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell. + */ + +#include "roc_api.h" +#include "roc_priv.h" + +#define PTP_FREQ_ADJUST (1 << 9) + +static inline struct mbox * +get_mbox(struct roc_nix *roc_nix) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct dev *dev = &nix->dev; + + return dev->mbox; +} + +int +roc_nix_ptp_rx_ena_dis(struct roc_nix *roc_nix, int enable) +{ + struct mbox *mbox = get_mbox(roc_nix); + + if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix)) + return NIX_ERR_PARAM; + + if (enable) + mbox_alloc_msg_cgx_ptp_rx_enable(mbox); + else + mbox_alloc_msg_cgx_ptp_rx_disable(mbox); + + return mbox_process(mbox); +} + +int +roc_nix_ptp_tx_ena_dis(struct roc_nix *roc_nix, int enable) +{ + struct mbox *mbox = get_mbox(roc_nix); + + if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix)) + return NIX_ERR_PARAM; + + if (enable) + mbox_alloc_msg_nix_lf_ptp_tx_enable(mbox); + else + mbox_alloc_msg_nix_lf_ptp_tx_disable(mbox); + + return mbox_process(mbox); +} + +int +roc_nix_ptp_clock_read(struct roc_nix *roc_nix, uint64_t *clock, uint64_t *tsc, + uint8_t is_pmu) +{ + struct mbox *mbox = get_mbox(roc_nix); + struct ptp_req *req; + struct ptp_rsp *rsp; + int rc = -ENOSPC; + + req = mbox_alloc_msg_ptp_op(mbox); + if (req == NULL) + return rc; + req->op = PTP_OP_GET_CLOCK; + req->is_pmu = is_pmu; + rc = mbox_process_msg(mbox, (void *)&rsp); + if (rc) + return rc; + + if (clock) + *clock = rsp->clk; + + if (tsc) + *tsc = rsp->tsc; + + return 0; +} + +int +roc_nix_ptp_sync_time_adjust(struct roc_nix *roc_nix, int64_t delta) +{ + struct mbox *mbox = get_mbox(roc_nix); + struct ptp_req *req; + struct ptp_rsp *rsp; + int rc = -ENOSPC; + + if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix)) + return NIX_ERR_PARAM; + + if ((delta <= -PTP_FREQ_ADJUST) || (delta >= PTP_FREQ_ADJUST)) + return NIX_ERR_INVALID_RANGE; + + req = mbox_alloc_msg_ptp_op(mbox); + if (req == NULL) + return rc; + req->op = PTP_OP_ADJFINE; + req->scaled_ppm = delta; + + return mbox_process_msg(mbox, (void *)&rsp); +} + +int +roc_nix_ptp_info_cb_register(struct roc_nix *roc_nix, + ptp_info_update_t ptp_update) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct dev *dev = &nix->dev; + + if (ptp_update == NULL) + return NIX_ERR_PARAM; + + dev->ops->ptp_info_update = (ptp_info_t)ptp_update; + return 0; +} + +void +roc_nix_ptp_info_cb_unregister(struct roc_nix *roc_nix) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct dev *dev = &nix->dev; + + dev->ops->ptp_info_update = NULL; +} diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map index f8f6b89..bd3b834 100644 --- a/drivers/common/cnxk/version.map +++ b/drivers/common/cnxk/version.map @@ -56,6 +56,12 @@ INTERNAL { roc_nix_npc_promisc_ena_dis; roc_nix_npc_rx_ena_dis; roc_nix_npc_mcast_config; + roc_nix_ptp_clock_read; + roc_nix_ptp_info_cb_register; + roc_nix_ptp_info_cb_unregister; + roc_nix_ptp_rx_ena_dis; + roc_nix_ptp_sync_time_adjust; + roc_nix_ptp_tx_ena_dis; roc_nix_ras_intr_ena_dis; roc_nix_register_cq_irqs; roc_nix_register_queue_irqs; -- 2.8.4