Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp113475pxv; Wed, 30 Jun 2021 01:05:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMQSF/aUYj1m7SyDGvR0T7cPYvRin/OpBZJgsX8n2RnQWZ8/BtGuK+rcVHcm7rBB7HQDfw X-Received: by 2002:a05:6402:845:: with SMTP id b5mr44679584edz.266.1625040329604; Wed, 30 Jun 2021 01:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625040329; cv=none; d=google.com; s=arc-20160816; b=gL7vLpNIgtPZY3SUk3FcW3c/a9aky5SFim7Jv3l/ziCKkZHXPO7HK9PJgVOQvWbODb Fm5QxCcmE/rBtQjVBs25Zx2sUKlJtJ8ZhJUC00T6LDAFKp6JrVqp8c2fis5DOBT4Njvg RvldGHD/VEZiiX7W0LVcvjcKjGaKLOvvRNhcCxDOIR71zrqsG481JTDubTcOGzdUhpNR aXEdA8PIhEY5cQRjk+VaeEkbu5sv8+G2iWUKDZjFd9Af1jEb5IXS/VFXyh0IbPNaCAMJ +/fvLIPKZJ8gWsxWWFs6GkLWLnnMyk/zd+QP/VizTL9g5L1c23cpMzm8m5WFEE8m82bG NaMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=zM9c5gsz+NGLlkgd6mCCc+trQmI4y3pBx3vPNK0RudY=; b=EMEvJ1L2knGzVeeiL6Mtx5crOtjDFaH3eSqM+3o89YceTCM3yiM2MySsunQsCKS931 5cDIUdcUU/ZPm4xWOSRkrtTUhTxk/RygD2Db+6iSKYXZw8DcspDo/cgR28TG8RWl/NaD GQWyIcxN/kV2gjjyix/a4+9/UW08sXotNun92r1DsLQsmiVy1zXNOhYNV3hoYqPdtzMa F+gzgGXU/aOEPqu8012RoneQaG86/PYnjMH8R+35uEw4G1vhpget7ABcrZkaKnzb6X93 rLv+ewrDBjCDyQaojq+k+4Izo0Y0dHmWKMC74YDBhdebw8Be2skzaSuYp2q469HEWMMH DqxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lt7si12902881ejb.640.2021.06.30.01.05.06; Wed, 30 Jun 2021 01:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233586AbhF3IEF (ORCPT + 99 others); Wed, 30 Jun 2021 04:04:05 -0400 Received: from inva020.nxp.com ([92.121.34.13]:36872 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233219AbhF3IDy (ORCPT ); Wed, 30 Jun 2021 04:03:54 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 23DC91A16B5; Wed, 30 Jun 2021 10:01:25 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id AF4041A16C4; Wed, 30 Jun 2021 10:01:24 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id B24ED183AC99; Wed, 30 Jun 2021 16:01:22 +0800 (+08) From: Yangbo Lu To: netdev@vger.kernel.org Cc: Yangbo Lu , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, mptcp@lists.linux.dev, Richard Cochran , "David S . Miller" , Jakub Kicinski , Mat Martineau , Matthieu Baerts , Shuah Khan , Michal Kubecek , Florian Fainelli , Andrew Lunn , Rui Sousa , Sebastien Laveze Subject: [net-next, v5, 04/11] ptp: add kernel API ptp_get_vclocks_index() Date: Wed, 30 Jun 2021 16:11:55 +0800 Message-Id: <20210630081202.4423-5-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210630081202.4423-1-yangbo.lu@nxp.com> References: <20210630081202.4423-1-yangbo.lu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add kernel API ptp_get_vclocks_index() to get all ptp vclocks index on pclock. This is preparation for supporting ptp vclocks info query through ethtool. Signed-off-by: Yangbo Lu --- Changes for v3: - Added this patch. Changes for v4: - Dynamically allocated memory for vclock index getting. Changes for v5: - None. --- drivers/ptp/ptp_clock.c | 3 ++- drivers/ptp/ptp_private.h | 2 ++ drivers/ptp/ptp_vclock.c | 35 ++++++++++++++++++++++++++++++++ include/linux/ptp_clock_kernel.h | 14 +++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 9205a9362a9d..f012fa581cf4 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -24,10 +24,11 @@ #define PTP_PPS_EVENT PPS_CAPTUREASSERT #define PTP_PPS_MODE (PTP_PPS_DEFAULTS | PPS_CANWAIT | PPS_TSFMT_TSPEC) +struct class *ptp_class; + /* private globals */ static dev_t ptp_devt; -static struct class *ptp_class; static DEFINE_IDA(ptp_clocks_map); diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index f75fadd9b244..dba6be477067 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -96,6 +96,8 @@ static inline bool ptp_vclock_in_use(struct ptp_clock *ptp) return in_use; } +extern struct class *ptp_class; + /* * see ptp_chardev.c */ diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index fc9205cc504d..cefab29a0592 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -148,3 +148,38 @@ void ptp_vclock_unregister(struct ptp_vclock *vclock) ptp_clock_unregister(vclock->clock); kfree(vclock); } + +int ptp_get_vclocks_index(int pclock_index, int **vclock_index) +{ + char name[PTP_CLOCK_NAME_LEN] = ""; + struct ptp_clock *ptp; + struct device *dev; + int num = 0; + + if (pclock_index < 0) + return num; + + snprintf(name, PTP_CLOCK_NAME_LEN, "ptp%d", pclock_index); + dev = class_find_device_by_name(ptp_class, name); + if (!dev) + return num; + + ptp = dev_get_drvdata(dev); + + if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) { + put_device(dev); + return num; + } + + *vclock_index = kzalloc(sizeof(int) * ptp->n_vclocks, GFP_KERNEL); + if (!(*vclock_index)) + goto out; + + memcpy(*vclock_index, ptp->vclock_index, sizeof(int) * ptp->n_vclocks); + num = ptp->n_vclocks; +out: + mutex_unlock(&ptp->n_vclocks_mux); + put_device(dev); + return num; +} +EXPORT_SYMBOL(ptp_get_vclocks_index); diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index b6fb771ee524..300a984fec87 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -306,6 +306,18 @@ int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay); */ void ptp_cancel_worker_sync(struct ptp_clock *ptp); +/** + * ptp_get_vclocks_index() - get all vclocks index on pclock, and + * caller is responsible to free memory + * of vclock_index + * + * @pclock_index: phc index of ptp pclock. + * @vclock_index: pointer to pointer of vclock index. + * + * return number of vclocks. + */ +int ptp_get_vclocks_index(int pclock_index, int **vclock_index); + #else static inline struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, struct device *parent) @@ -325,6 +337,8 @@ static inline int ptp_schedule_worker(struct ptp_clock *ptp, { return -EOPNOTSUPP; } static inline void ptp_cancel_worker_sync(struct ptp_clock *ptp) { } +static inline int ptp_get_vclocks_index(int pclock_index, int **vclock_index) +{ return 0; } #endif -- 2.25.1