Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3515898pxj; Tue, 15 Jun 2021 02:38:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVHUqkjS3vspK7BqJrftuZcxk7H8zwUfrCCa2gvoJeOT0wRU5ZXL3iRm91gFhElY+HMsDk X-Received: by 2002:a17:907:c1f:: with SMTP id ga31mr2199501ejc.438.1623749917147; Tue, 15 Jun 2021 02:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623749917; cv=none; d=google.com; s=arc-20160816; b=JpzXKbCPUErMnP2MHdi9/IC828BttvFilcsknKFbfVc9GQbnhWqf6An38v03rgFn57 eFRjmQ0HHA2K6EpgGwt1iPH/akYhjzR20/CLNyIxWNaRWH8M5o9j2z3M+E/dJDmhw5DT 08gnwCfmssRwjYacAVr7ece23uXSKMWPGSD8sgMATo6V2ZAQy0j+08/I1oI1G9cmrgMI VTe7KIkAX9ClKoymN2D9IDt79ft/bvNQGCCShigFvfl9xIHro9vFyKvzgJuRoVW28xWE 9rA4D6waMoM8t3W6y5HqnCNJk6O1bW+lDR92zULGcdeNT1Xca4GqKzdQ57niewIIdWfV Z7kw== 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=6j9usRxDNzzdvTG2tJ7ZBLbuqpTUbwTcKcWJd+PMBI0=; b=roXza+Pj/DT+9Vmcy37W4m8znRJzdGWJPKaXoFnqBmbEhhe6qCXBhBQQTUb58RXe23 G9CGgCEWn8XU+xSkVYDIlaQGKYFlg9RIALmc9QtB6s3fZN+e6RiUz+5CCr2nW3Aau9SP XD//7fUvJwOEvUMhd6HGMCQlzXd2prbVS+KT8gNsOiNNpBuE/dhR+QuEZCOy+d8zzFTc h5CZh8cMZA2ITmxb7X85IqwlX65VsmRltCS1Xf/kzWx0mo35PN76++RseZRj5kszzEVb UGpjNkUaWxFC099kGjj6aOiBopwzhJLwyKb/WCweGhatwAqL11w9ifLZExHAuobCIQ6f barQ== 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 c10si15399604edn.209.2021.06.15.02.38.14; Tue, 15 Jun 2021 02:38:37 -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 S231639AbhFOJix (ORCPT + 99 others); Tue, 15 Jun 2021 05:38:53 -0400 Received: from inva020.nxp.com ([92.121.34.13]:56686 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231577AbhFOJio (ORCPT ); Tue, 15 Jun 2021 05:38:44 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id AD78D1A29CC; Tue, 15 Jun 2021 11:36:39 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 593A81A0494; Tue, 15 Jun 2021 11:36:33 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id D785740341; Tue, 15 Jun 2021 17:36:24 +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, v3, 04/10] ptp: add kernel API ptp_get_vclocks_index() Date: Tue, 15 Jun 2021 17:45:11 +0800 Message-Id: <20210615094517.48752-5-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210615094517.48752-1-yangbo.lu@nxp.com> References: <20210615094517.48752-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. --- drivers/ptp/ptp_clock.c | 3 ++- drivers/ptp/ptp_private.h | 2 ++ drivers/ptp/ptp_vclock.c | 24 ++++++++++++++++++++++++ include/linux/ptp_clock_kernel.h | 12 ++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 38842a76acf8..88e43451b062 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 5671710ca0fa..16b7ba583ddd 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -91,6 +91,8 @@ static inline bool ptp_guaranteed_pclock(struct ptp_clock *ptp) return false; } +extern struct class *ptp_class; + /* * see ptp_chardev.c */ diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index b8f500677314..8944b4fe32d8 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -152,3 +152,27 @@ 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); + num = ptp->n_vclocks; + memcpy(vclock_index, ptp->vclock_index, sizeof(int) * ptp->n_vclocks); + 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 af12cc1e76d7..37f49d3e761e 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -306,6 +306,16 @@ 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 + * + * @pclock_index: phc index of ptp pclock. + * @vclock_index: pointer to phc index of ptp vclocks. + * + * 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 +335,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 int ptp_get_vclocks_index(int pclock_index, int *vclock_index) +{ return 0; } #endif -- 2.25.1