From patchwork Fri Sep 29 02:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 146412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3769314vqu; Thu, 28 Sep 2023 21:11:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGA3PP2cmFkgvTnC6oj2THwdquFAnpXERc/lHnyQH03FWQ5Yh0gfpKAtfMwSI2dwsCA/OXb X-Received: by 2002:a05:6358:2794:b0:135:85ec:a080 with SMTP id l20-20020a056358279400b0013585eca080mr3164150rwb.32.1695960699078; Thu, 28 Sep 2023 21:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695960699; cv=none; d=google.com; s=arc-20160816; b=y11VaMkbq3/c7d/A52cS4W02/ratTYyJCcknhtjTT+glBs5I1+Nt8ET+aCpMQ+3lja JMcQSQyrVaCwQAjxBWbiys5v/3M0V15uj1kSfS1D7NtzrQABJDsCIGPWERh3EYvhVzVQ APApjJjdo/DHyDsDJeZpk9+Be+z+EFFNCJm7ldKiuO5mI/iuEJ+zhGYjxjD9iDk23H2M YQ0QzyWEK0xiSeVI7mTIGSrfO0wkojltWtdBI4IIMaROFpIsjWUpdgp1M3a/g0q7g/ZR Fhl2+w6w1hFWJBL8Exkz77NdOUXUTKnNP/y3N6GUPBoOra/0J63xXD3qu8tJxaNqR1mi OrEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=nIHaxhAoJd7uqW2IBjHfoZybMFoN9LgbXxplOyXZzn8=; fh=iarKena/8n2PABjKSiA6ahZy/I7+DXKOpLweDXOz6ZE=; b=SZWAa8mDgyKXb7m4SDykdSRUiQSFMnwIPT76vadZH3EBnlgTbuneHfxIRRsXNLtM8Y 8vDmJRLQ2v1+vObpXfujbGyFFzJwAeHDGpjGYyB1y2cCvI3SavZUVw97by6bKb1wBuqQ //AblU8Ma2FnA7T2bNSWI1R1YWIGZJaGtQ0QD1NkblG1Y7PeXm6UOT6ukmHlWVie+mYt jASF9yD3khUefv7H01nyWSgRogk432RgGiKjeHNH6YK3uHF1cNe3JucKPrpB0ckKN26u +NKctbF8AQ0xp1m8YiswFlWDRqb8OK7z2sG/CVxZoswGTokYTdH+ZLPuzll4UlYmH/Ff 915w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bPuh26LG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ct27-20020a056a000f9b00b0068fca125aaasi16244750pfb.232.2023.09.28.21.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 21:11:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bPuh26LG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 4D90784AB80B; Thu, 28 Sep 2023 19:38:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232321AbjI2Cht (ORCPT + 21 others); Thu, 28 Sep 2023 22:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbjI2Chp (ORCPT ); Thu, 28 Sep 2023 22:37:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D01F11A4 for ; Thu, 28 Sep 2023 19:37:43 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81c02bf2beso20635963276.2 for ; Thu, 28 Sep 2023 19:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695955063; x=1696559863; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=nIHaxhAoJd7uqW2IBjHfoZybMFoN9LgbXxplOyXZzn8=; b=bPuh26LGYqk1JacugXDz8GvIhf08jQ7HS1VIUdM9HaKGEHRAcpwvsywdpmzStfaU6x 6U3NMhmQbVR/6WqmE6qrnlbNlNz8l5HZuRchJBZe9gkp49ovHKQSDWKiVFjrylUSUBwY 3kN5g1R5VusA3wPQKqWDCyCe33hHn7FPYsN54SxxPYWOxOGvEFitqzhMP5VpWLXq3psy BSmNlhFML0K2KLGEhlAgITBi3fPfyYew+H0Wj7fXKTToF792DZzkKHY7ANTUjQ3WfEZz Ok51cih6JuIJ1bkC7fnmeIvlGOqV79jtaPFBm18iv70t6jVOx53Zeb40nxQwAU0fR1TY xAlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695955063; x=1696559863; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nIHaxhAoJd7uqW2IBjHfoZybMFoN9LgbXxplOyXZzn8=; b=dJpG2amSFVhFTU3kC1qI7exBDQa1trap+ZFudtYHdu9kQyaod7XnZAQrF/7e3IuZZ3 tk0mgjOAhqslwmrbiU5ZW6FbIHYIG/1SgCKU3Fe8Q1Lm/ZYBg0/b4e7vrVnr1yGctsE/ jDEsFoqeBToOoHyr1mr5LTzz7a6HDkNqh0OhsTtZ6yLhmwHdFjU0Je5m7GWO198VKKWt EPkfsIwxIqrlggwgJoMajlYv2rCVv9K9HZytWl67FBSXQcm3/S/fRO9AGnlyP1fNvdT5 sK+8bQi3/UZOcyfLn9Bx+tRJ1Jr2YeTrbeEFnWNCtIzmGW40xj40f+uJDXBHsJc7iXxy k8/A== X-Gm-Message-State: AOJu0Ywg/akGbNV9q1ifnaShnKtvRtqjCbT1J3SUVZJnzGRVV8iUGS4m XevvRkWRVD88DiuPpxCSJBSYRDe5jJHI X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a05:6902:136b:b0:d81:4107:7a1 with SMTP id bt11-20020a056902136b00b00d81410707a1mr40041ybb.2.1695955063070; Thu, 28 Sep 2023 19:37:43 -0700 (PDT) Date: Thu, 28 Sep 2023 19:37:40 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929023740.1611161-1-maheshb@google.com> Subject: [PATCH 2/4] ptp: add ptp_gettimex64any() support From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Richard Cochran X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 28 Sep 2023 19:38:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778343686274562101 X-GMAIL-MSGID: 1778343686274562101 add support for TS sandwich of the user preferred timebase. The options supported are PTP_TS_REAL (CLOCK_REALTIME), PTP_TS_MONO (CLOCK_MONOTONIC), PTP_TS_RAW (CLOCK_MONOTONIC_RAW), PTP_TS_CYCLES (raw-cycles) The option PTP_TS_CYCLES will return the cycles in 'struct timespec64' format so something equivalent of timespec64_to_ns() need to be applied to covert back into cycles. Option of PTP_TS_REAL is equivalent of using ptp_gettimex64(). Signed-off-by: Mahesh Bandewar CC: Richard Cochran CC: "David S. Miller" CC: netdev@vger.kernel.org --- include/linux/ptp_clock_kernel.h | 57 ++++++++++++++++++++++++++++++++ include/uapi/linux/ptp_clock.h | 8 +++++ 2 files changed, 65 insertions(+) diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index 1ef4e0f9bd2a..87e75354d687 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -102,6 +102,15 @@ struct ptp_system_timestamp { * reading the lowest bits of the PHC timestamp and the second * reading immediately follows that. * + * @gettimex64any: Reads the current time from the hardware clock and + optionally also any of the MONO, MONO_RAW, or SYS clock. + * parameter ts: Holds the PHC timestamp. + * parameter sts: If not NULL, it holds a pair of timestamps from + * the clock of choice. The first reading is made right before + * reading the lowest bits of the PHC timestamp and the second + * reading immediately follows that. + * parameter type: any one of the TS opt from ptp_timestamp_types. + * * @getcrosststamp: Reads the current time from the hardware clock and * system clock simultaneously. * parameter cts: Contains timestamp (device,system) pair, @@ -180,6 +189,9 @@ struct ptp_clock_info { int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts); int (*gettimex64)(struct ptp_clock_info *ptp, struct timespec64 *ts, struct ptp_system_timestamp *sts); + int (*gettimex64any)(struct ptp_clock_info *ptp, struct timespec64 *ts, + struct ptp_system_timestamp *sts, + enum ptp_ts_types type); int (*getcrosststamp)(struct ptp_clock_info *ptp, struct system_device_crosststamp *cts); int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts); @@ -464,4 +476,49 @@ static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts) ktime_get_real_ts64(&sts->post_ts); } +static inline void ptp_read_any_prets(struct ptp_system_timestamp *sts, + enum ptp_ts_types type) +{ + if (sts) { + switch (type) { + case PTP_TS_CYCLES: + ktime_get_cycles64(&sts->pre_ts); + break; + case PTP_TS_REAL: + ktime_get_real_ts64(&sts->pre_ts); + break; + case PTP_TS_MONO: + ktime_get_ts64(&sts->pre_ts); + break; + case PTP_TS_RAW: + ktime_get_raw_ts64(&sts->pre_ts); + break; + default: + break; + } + } +} + +static inline void ptp_read_any_postts(struct ptp_system_timestamp *sts, + enum ptp_ts_types type) +{ + if (sts) { + switch (type) { + case PTP_TS_CYCLES: + ktime_get_cycles64(&sts->post_ts); + break; + case PTP_TS_REAL: + ktime_get_real_ts64(&sts->post_ts); + break; + case PTP_TS_MONO: + ktime_get_ts64(&sts->post_ts); + break; + case PTP_TS_RAW: + ktime_get_raw_ts64(&sts->post_ts); + break; + default: + break; + } + } +} #endif diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h index 05cc35fc94ac..1f1e98966cff 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -69,6 +69,14 @@ */ #define PTP_PEROUT_V1_VALID_FLAGS (0) +enum ptp_ts_types { + PTP_TS_CYCLES = 0, + PTP_TS_REAL, + PTP_TS_MONO, + PTP_TS_RAW, + PTP_TS_MAX, +}; + /* * struct ptp_clock_time - represents a time value *