From patchwork Tue Oct 3 04:17:01 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: 147608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1845420vqb; Mon, 2 Oct 2023 21:17:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/NkvFKkVusIEZLndc1hEZdw7W4WGVGME41RwMxMhPQ52wnt65Fcqpfl1IjLWk3SHjLUau X-Received: by 2002:a17:90b:1094:b0:279:310e:33fd with SMTP id gj20-20020a17090b109400b00279310e33fdmr7439711pjb.22.1696306647908; Mon, 02 Oct 2023 21:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696306647; cv=none; d=google.com; s=arc-20160816; b=IbyqhxnPkeznuFfWCX1o/60tvMLnwojmjoq5FNSKqu10Lu4K5FABRY9i3H8hpYmH3E p8O/ehLnURpYKRoTmokPhEHU6SXHIyBW20B40tSRazZhbYxxGHYP/VfAfYozJSO8XfrS 9Xw+SmFiG4Mwb+UPCInVT57Q3fOaR3ECs4QuYLhTjoUrXCIWAQkLZbXV66fR5UmWzdjh oiBLKtFi1sEXy+RqDJxFniLFjrvyg1NDY8kZlgVhAM4+Mw0eCFY0VK4WY//1CsEqCURR rsmCpk5QxfyeNgIkSc3M6XDSx1tDuj0mjnh8bRRqprgZo6Y9kBTXDU9mL8Io9VqQlFbx tsrA== 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=aGh7NZY3G/0+YsZGvHoKe2ZjMznUVNFroVuVfb1sCeU=; fh=JCCkRR+jaVR7fn011zWVb20aTZYoZR4zVy6LlbDUFS4=; b=Xhg2B5i/s5SVGTwxi1XPaOxi7ya9tK8U3vz/BLvS4r4uY3IPuTz0gM0oxJzFT8cp07 QnXpFmrqwP3iPOmflYlE1OY/0f51t/PzkfzmyK9TNdWzR38wSh1COBQ/glbn/NTP4xBA GBH5LA3DKyle19E7Q8E8Wm5wGDAms1KqwdudOiCYQKJBUDuJDdvNZaTvaj7VY0rQE41R 2TzJX5HAjkw1WbzpRZlECOr87ZHka6kf/Vk7fIbE41qQXxMBS3Iy09YK6PJsf9cq7zGr 58A4Q8fn39UDqRQGBi9N6daF5hFGwo8C09AUH7WVmMryQ/BOyGh1wjre4llgmJJ5pWch T6MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4DxFbGdL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id nv11-20020a17090b1b4b00b00278ea235413si10351722pjb.31.2023.10.02.21.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 21:17:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4DxFbGdL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 21866811F90F; Mon, 2 Oct 2023 21:17:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239055AbjJCERN (ORCPT + 18 others); Tue, 3 Oct 2023 00:17:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233697AbjJCERI (ORCPT ); Tue, 3 Oct 2023 00:17:08 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9694C4 for ; Mon, 2 Oct 2023 21:17:04 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a23fed55d7so8469157b3.2 for ; Mon, 02 Oct 2023 21:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696306624; x=1696911424; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=aGh7NZY3G/0+YsZGvHoKe2ZjMznUVNFroVuVfb1sCeU=; b=4DxFbGdLAcLEZW/nYnlExMyot3rLmOaPvn16YQb3HxUjP9JiEkA/Wtfyphh3w4FzBX 4po+XgWtuyIWaxUjkxMl+xRl0Bln9kmA5jojlOldippa0aR6tBBAUY9ypxxYicd75z2L bvTpFhp0RZ7bD+p7QuB6nf+WSWZNDvOG65KaDkW1AW69YdKJe5LqnKzYf6HEwqTTqxC9 c4dtQcIpmLhmQ0fv6+ZRO3zwUM+xSeI1k/W5xYa7qseFYZANq4g6NVYgYhq5VSpDDFdt oSyvZuTw4P5LclTmLUUNpsy8LFaH0cV05ED6Q9YhOOWGSFjvcSdBpz0yQquKWzni8Wac SigA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696306624; x=1696911424; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aGh7NZY3G/0+YsZGvHoKe2ZjMznUVNFroVuVfb1sCeU=; b=vZ5Kwo5fpeFbpTx/bl57DINntyh1BWZgUu1R75XG/ag9rZlrPGMxdMK7IObaUz+Hz5 aQjrUoygPee/ww375xFZpB5h2aSIUBppNL5ellb4ozqcaxZwMR6IwvHaUHdNELNlupbp clBxTOUIL88ln27UEj5M3Rmpd1UnrkiHUMXFfEeN8CH0BccgEIzaUou1ezZTn4yTXmGN 6FvtRZSZm0s7VQUuqbbM8g638hoPy9YQI47gf9emtI8wzf1khNzvWCkIchFLhE35sint hbnVKRo/Zc9halcpTjYCJC/OiiFAAwaU3OISUjtno+8c1G1u6ZqL6IiIDFkbu+8QW2gn ciSA== X-Gm-Message-State: AOJu0YxQRrHTyoPy0Amj5RI/kET4PZaVs2GL9RFhFnJsvRWMLDA4mlug Drx8B5rBKprA+Cu0lArwsYR1TdUkqygH X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a81:ca41:0:b0:59b:e684:3c76 with SMTP id y1-20020a81ca41000000b0059be6843c76mr215109ywk.2.1696306623933; Mon, 02 Oct 2023 21:17:03 -0700 (PDT) Date: Mon, 2 Oct 2023 21:17:01 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20231003041701.1745953-1-maheshb@google.com> Subject: [PATCHv2 next 1/3] ptp: add ptp_gettimex64any() support From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , John Stultz , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Richard Cochran X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 21:17:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778343686274562101 X-GMAIL-MSGID: 1778706439778523296 add support for TS sandwich of the user preferred timebase. The options supported are PTP_TS_REAL (CLOCK_REALTIME), PTP_TS_MONO (CLOCK_MONOTONIC), and PTP_TS_RAW (CLOCK_MONOTONIC_RAW) 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 | 51 ++++++++++++++++++++++++++++++++ include/uapi/linux/ptp_clock.h | 7 +++++ 2 files changed, 58 insertions(+) diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index 1ef4e0f9bd2a..fd7be98e7bba 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,43 @@ 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_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_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..dc44e34f8146 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -69,6 +69,13 @@ */ #define PTP_PEROUT_V1_VALID_FLAGS (0) +enum ptp_ts_types { + PTP_TS_REAL = 0, + PTP_TS_MONO, + PTP_TS_RAW, + PTP_TS_MAX, +}; + /* * struct ptp_clock_time - represents a time value * From patchwork Tue Oct 3 04:17:04 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: 147610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1845475vqb; Mon, 2 Oct 2023 21:17:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzgk+XmWm51oO4XDTgjKIgqyv2UTwyiyLABYSRa6/c29ozXmaWEfbnIKuh9SnkT0BUI/+9 X-Received: by 2002:a05:6830:1bea:b0:6c4:9fda:a1e2 with SMTP id k10-20020a0568301bea00b006c49fdaa1e2mr12139070otb.4.1696306659480; Mon, 02 Oct 2023 21:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696306659; cv=none; d=google.com; s=arc-20160816; b=ex82zdhgakn63t1hWkv33w7tWXqa4lpA0FxflDNkFDqLKhaDJU86Cl/cNnfoQmbEzy K34UuAJTiggrpMvfEXg67BCCKzm4nv6lWazqL+nkwQFS615zXQ9pyYfTKOfvab5pfj5v kuIeYHe+en+qJwZ1VeibJMCWdQRYpUxrWasEX4Zlmf1xtThHA+rxIHUqBVdzUzUDHxfE ykBCsF0NVU+tDyuEh4TMi+m4e/5eSEr1Selo3pFFbWQ9Q79l5Cfh2sRU6RfyOIvCcVtO 2v9xFxz/eKm7jjtouqHkhKLZFmY+Ngqs/SyLvwgv+n77a8JAUmPNCEC52X/06SZHUPkt 6KSg== 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=yYq0uo4Y2Gfz3+tHCOAtr3XBow0LxI3rKbo8nyoJx34=; fh=RHNQidIbO5dR1Sd/niiH8WwxAdKbtyOqwr3qKN25czk=; b=iXt0ILGgxkIYmINzovDVEpdBrO9ssIdAqsTVaB+COBN/W2CgXJCu5NAnvJ89aTIRGn o8WRdhv3jizbmi0VmtMwVZlUF8J0XU00VGhz/ETl0wYwXePKGzS+H9L8BfgG/ZxZehi4 Tg42KfU1oyb7oWQuCtGIv8LgsaNttK0Ks3oiIZKqqjBFd1D1QuFXbDGaPhrmm2+XhU12 B/K8w9dCtlWuRlzbveu/NxCVHlpSTe0ZuANjibgryHwLA2rZkSiP15EQiyYMCDzHbkly qqdk1gNEEM3P1J0ffsMf6LD7gCuqvBMeTcTaBamb5h5oUONgONFoRZHHZ+KYqndsZv8I jnIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CF0TrnO8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id s85-20020a632c58000000b0056b83e0ae92si533395pgs.465.2023.10.02.21.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 21:17:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CF0TrnO8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 50DF8805AA19; Mon, 2 Oct 2023 21:17:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239078AbjJCERS (ORCPT + 18 others); Tue, 3 Oct 2023 00:17:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239006AbjJCERL (ORCPT ); Tue, 3 Oct 2023 00:17:11 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33E8FBB for ; Mon, 2 Oct 2023 21:17:07 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a21c283542so8200027b3.3 for ; Mon, 02 Oct 2023 21:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696306626; x=1696911426; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yYq0uo4Y2Gfz3+tHCOAtr3XBow0LxI3rKbo8nyoJx34=; b=CF0TrnO8ODXXQxMLO0w0W8vDQlGw8ZPRStKeLzEqdnP5FM9GLXOs1lOAC4VZFJoI1M 7ULmb4edrRabkakzGDHptpU2KUFPmy2WgAt026+jTDr+c4qI18AHkdqcw5PBaHXDBFfu Erw1k/qW4NJgMvw6neszxKga5cL/Azvc1Ww/sSqUsq09VcKn0d8TNE4qNcvwg8V7t7af Doc2IuNcziJPPnPRMDF0xS2NyWumX3Mv6KLgMk2zxBAmvjOo22ijb/4Z62KD+ZNJtueV 9NsRQVIMqJ2JdtcCTzJoSenR++CDsTNPTc+MWAW9gegp9A+kAJNngAJtOUdur/PEgA7D 3dqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696306626; x=1696911426; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yYq0uo4Y2Gfz3+tHCOAtr3XBow0LxI3rKbo8nyoJx34=; b=gjLMaH8pDrE5dl0fndYe6aodXdsB3IAipXUNJ6TzU4kmcwDhtzAoKQqP5rEe0261Th AA8ztvE7GOHVljju7EF3+OaSzhWZ+cB8w6ntyEdeFrcxz4wJ48XSetZnQipxiMVWTHmO WLj6der0nbOJq4kmUsroT1AMeCFhkvsWBlBRxeQs2jTleKRogdypoz2xUcyHvlqnJv8z xqhSLn3VROfX6SmIA2Udy+x4iK48yCN/Pnygtd4bBPXKhjoJO2WYYSXyw36tNabn9A8b JurRyUXta01W3fTzQlsVHDVuJOgumbmdXJ0QTKB0RvqBAb2sVWoy/k9JIxH3skyPl/ZR w4aA== X-Gm-Message-State: AOJu0YyBHBcEsFuiQqpSjHKcKfuorKZEgWwp+ODM3nHNRI7lxaxqamSm 8sXo/AsGVNIhjWOmV3QU9A7wLErklvuZ X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a81:7611:0:b0:59b:eace:d465 with SMTP id r17-20020a817611000000b0059beaced465mr225387ywc.2.1696306626466; Mon, 02 Oct 2023 21:17:06 -0700 (PDT) Date: Mon, 2 Oct 2023 21:17:04 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20231003041704.1746303-1-maheshb@google.com> Subject: [PATCHv2 next 2/3] ptp: add ioctl interface for ptp_gettimex64any() From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , John Stultz , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Richard Cochran , Rahul Rameshbabu 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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 02 Oct 2023 21:17:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778359063234677968 X-GMAIL-MSGID: 1778706451926794992 add an ioctl op PTP_SYS_OFFSET_ANY2 to support ptp_gettimex64any() method Signed-off-by: Mahesh Bandewar CC: Richard Cochran CC: Rahul Rameshbabu CC: "David S. Miller" CC: netdev@vger.kernel.org --- drivers/ptp/ptp_chardev.c | 34 ++++++++++++++++++++++++++++++++++ include/uapi/linux/ptp_clock.h | 14 ++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index 362bf756e6b7..fef1c7e7e6e6 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -110,6 +110,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) { struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); struct ptp_sys_offset_extended *extoff = NULL; + struct ptp_sys_offset_any *anyoff = NULL; struct ptp_sys_offset_precise precise_offset; struct system_device_crosststamp xtstamp; struct ptp_clock_info *ops = ptp->info; @@ -324,6 +325,39 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) err = -EFAULT; break; + case PTP_SYS_OFFSET_ANY2: + if (!ptp->info->gettimex64any) { + err = -EOPNOTSUPP; + break; + } + anyoff = memdup_user((void __user *)arg, sizeof(*anyoff)); + if (IS_ERR(anyoff)) { + err = PTR_ERR(anyoff); + anyoff = NULL; + break; + } + if (anyoff->n_samples > PTP_MAX_SAMPLES + || anyoff->ts_type >= PTP_TS_MAX + || anyoff->rsv[0] || anyoff->rsv[1]) { + err = -EINVAL; + break; + } + for (i = 0; i < anyoff->n_samples; i++) { + err = ptp->info->gettimex64any(ptp->info, &ts, &sts, + anyoff->ts_type); + if (err) + goto out; + anyoff->ts[i][0].sec = sts.pre_ts.tv_sec; + anyoff->ts[i][0].nsec = sts.pre_ts.tv_nsec; + anyoff->ts[i][1].sec = ts.tv_sec; + anyoff->ts[i][1].nsec = ts.tv_nsec; + anyoff->ts[i][2].sec = sts.post_ts.tv_sec; + anyoff->ts[i][2].nsec = sts.post_ts.tv_nsec; + } + if (copy_to_user((void __user *)arg, anyoff, sizeof(*anyoff))) + err = -EFAULT; + break; + case PTP_SYS_OFFSET: case PTP_SYS_OFFSET2: sysoff = memdup_user((void __user *)arg, sizeof(*sysoff)); diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h index dc44e34f8146..b4e71e754b35 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -165,6 +165,18 @@ struct ptp_sys_offset_extended { struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; }; +struct ptp_sys_offset_any { + unsigned int n_samples; /* Desired number of measurements. */ + enum ptp_ts_types ts_type; /* One of the TS types */ + unsigned int rsv[2]; /* Reserved for future use. */ + /* + * Array of [TS, phc, TS] time stamps. The kernel will provide + * 3*n_samples time stamps. + * TS is any of the ts_type requested. + */ + struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; +}; + struct ptp_sys_offset_precise { struct ptp_clock_time device; struct ptp_clock_time sys_realtime; @@ -231,6 +243,8 @@ struct ptp_pin_desc { _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise) #define PTP_SYS_OFFSET_EXTENDED2 \ _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended) +#define PTP_SYS_OFFSET_ANY2 \ + _IOWR(PTP_CLK_MAGIC, 19, struct ptp_sys_offset_any) struct ptp_extts_event { struct ptp_clock_time t; /* Time event occured. */ From patchwork Tue Oct 3 04:17:06 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: 147609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1845442vqb; Mon, 2 Oct 2023 21:17:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBg3dsW0BWAkXt4nNWjzEmv5JprfHf2t3/EytXGBGS/7UY7Ji/6Bgq+42rBWN9Gp6mclj2 X-Received: by 2002:a17:902:f543:b0:1bc:2d43:c747 with SMTP id h3-20020a170902f54300b001bc2d43c747mr19142485plf.38.1696306652781; Mon, 02 Oct 2023 21:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696306652; cv=none; d=google.com; s=arc-20160816; b=YD4L8c0gqIdDBss4elCvq2G5y8HMSpJs49z+1Y20OoIFKT7DTzInB2AMd+5l9J6vI9 WQ+r1DtgpaOasFO6yZvXX9/wRr/AS4G7eCvRdVKlja1K31y/LAok2e198q60NFrmSQdn nDM/m+LenovMhlsufKcM0lviXLEQntFlDaPRcxo1vp+3QKJsU+JUZsBnzDNRM55DnFoC /p/HNRwNKcHa6vJnffB7oLYvT7nJnwjqzN5iruCNDPLKrohiOmxTTgjCj7d9R13I/hi3 8jCfIcE3t40dhxqi+9kLtv2aw7N6B3DMhmPikn9fO0NBYJsQAlWwfBLBneWyWSKh1Yz3 m89A== 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=xVHKEQiikdMgbU+y27225hg2LnDyDOWoRLfGIfsc16c=; fh=02BoE9IUMwbSc1va0HZXHRK+uDFUfdNNI83HDyu9gWM=; b=HuOO9GbrmFQ0ItMHYry5RNis6e27ZvGRBPfMhZ77KKYr+PzVMw1Vqf/yVW18VxHChH 6gxBLQEwkmjYmABIVnk+fMHJIjrPr7EWwmmlTdKV8pokMOpPt7t3astY413YPC8+aYGR 7K+w3uvLl0l1lOjJ+1H1qbplZApgeaDWhmQpUQj45DWMqseATIA1q3YKVeu3E2HYkDrz sJWt/ejeqPpyTZwLTLoG0rejWiZUxRFBKHiVzljkt/5Hid3bNf+7E+nxCfrF15nlg66y Jge0G7ip2CiDKLc9iwww4iZ9/sZe4UE6yvN7xRi3gmUccSEGTtQ4+/Xq5hK26xWTaw3v jwLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B9VnI/1U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z20-20020a170903409400b001bef085a37dsi520019plc.86.2023.10.02.21.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 21:17:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B9VnI/1U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id E498E811F90F; Mon, 2 Oct 2023 21:17:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239056AbjJCERY (ORCPT + 18 others); Tue, 3 Oct 2023 00:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbjJCERN (ORCPT ); Tue, 3 Oct 2023 00:17:13 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B6A3BB for ; Mon, 2 Oct 2023 21:17:10 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a234ffeb90so7691417b3.3 for ; Mon, 02 Oct 2023 21:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696306629; x=1696911429; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=xVHKEQiikdMgbU+y27225hg2LnDyDOWoRLfGIfsc16c=; b=B9VnI/1U+P3xlO4fshby72X1h0LoXSFnHMrojuo6YWrsKx3lPVsRzgBGYUPvKTcBGK FcDjpFGTsF8FMbho+oWi11Zr2vpj/IrIDZm4firEiv0SkSPlnyZKPlvcj/CM9DK976cA xAITZzRrXuR6nGTe6iPkLbJbvGQK1ukPIEOXVVHuDGbPH4G0MICihiBssgdWgPbWzEIW ju0iCM2CC8ow2EIEUNXUFgKh4eSUUS5N6SQyEMz9fyga3VF8Wom/LeWIinyTyLNKHpfy NcHJe67AvH1rq8VVyX/7hA7zZTG1kVWSaO9FezEwWZGi9IoiV8mRia8fsG8Ff+KyzGAY aLXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696306629; x=1696911429; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xVHKEQiikdMgbU+y27225hg2LnDyDOWoRLfGIfsc16c=; b=tfvRUQm0QvSHLbpKkgNS91LxeDTIt2YJCsWAO8ZdkWiwykMAbBaJU4GfccYcVnhu3u jhpHYFgdlAucA1O2TUGqg1LWy0IO89c820emI5k8G1kdqU/ChcSbTnIDB0wPrj6ZMndD dTeSKWmFJ+EHOfHoBzfjU8MoS6Qe7k13W0xvLMweH4smuKT2hFZ5jXmAkcWky3q3nDWU Y4FbM5DwZKHxDyaxC5UoESo09iyGPQGcz516+QuRweiky3Z5TJ3zROlFepkgCyzN/JCW EIdxqw5AxpPa7tvsLuSKP84bP9F9o4pXmOxOFw80D7TJkAKOsVszuhNbnzs5XbhE6qkU b0fg== X-Gm-Message-State: AOJu0Yyrr0uGMT2IvzsorrkLVpA4zhghKmiNOMhKknb81R1TMHH3BT0c eEtktuzjPBJfO1ITaya+bONO32wrEuuo X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a25:abaf:0:b0:d7b:9830:c172 with SMTP id v44-20020a25abaf000000b00d7b9830c172mr211752ybi.0.1696306629637; Mon, 02 Oct 2023 21:17:09 -0700 (PDT) Date: Mon, 2 Oct 2023 21:17:06 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20231003041706.1746634-1-maheshb@google.com> Subject: [PATCHv2 next 3/3] selftes/ptp: extend test to include ptp_gettimex64any() From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , John Stultz , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Shuah Khan , Richard Cochran , Rahul Rameshbabu , linux-kselftest@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 21:17:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778706444691059143 X-GMAIL-MSGID: 1778706444691059143 add -y/-Y options to support PTP_SYS_OFFSET_ANY2 op. where -y represents samples to collect while -Y is to choose the timebase from available options of cycles, real, mono, or raw. Signed-off-by: Mahesh Bandewar CC: Shuah Khan CC: Richard Cochran CC: "David S. Miller" CC: Rahul Rameshbabu CC: Jakub Kicinski CC: linux-kselftest@vger.kernel.org CC: netdev@vger.kernel.org --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/ptp/testptp.c | 76 ++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 42806add0114..c5e59cfc9830 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -66,6 +66,7 @@ TARGETS += powerpc TARGETS += prctl TARGETS += proc TARGETS += pstore +TARGETS += ptp TARGETS += ptrace TARGETS += openat2 TARGETS += resctrl diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c index c9f6cca4feb4..549f0861e897 100644 --- a/tools/testing/selftests/ptp/testptp.c +++ b/tools/testing/selftests/ptp/testptp.c @@ -37,6 +37,12 @@ #define NSEC_PER_SEC 1000000000LL +static char *time_base_arr[PTP_TS_MAX] = { + "system time", + "monotonic time", + "raw-monotonic time", +}; + /* clock_adjtime is not available in GLIBC < 2.14 */ #if !__GLIBC_PREREQ(2, 14) #include @@ -145,8 +151,10 @@ static void usage(char *progname) " -T val set the ptp clock time to 'val' seconds\n" " -x val get an extended ptp clock time with the desired number of samples (up to %d)\n" " -X get a ptp clock cross timestamp\n" + " -y val get an extended-any ptp clock time with the desired number of samples (up to %d) with given time-base for sandwich (with -Y opt)\n" + " -Y val sandwich timebase to use {real|mono|raw}\n" " -z test combinations of rising/falling external time stamp flags\n", - progname, PTP_MAX_SAMPLES); + progname, PTP_MAX_SAMPLES, PTP_MAX_SAMPLES); } int main(int argc, char *argv[]) @@ -162,6 +170,7 @@ int main(int argc, char *argv[]) struct ptp_sys_offset *sysoff; struct ptp_sys_offset_extended *soe; struct ptp_sys_offset_precise *xts; + struct ptp_sys_offset_any *ats; char *progname; unsigned int i; @@ -182,6 +191,8 @@ int main(int argc, char *argv[]) int pct_offset = 0; int getextended = 0; int getcross = 0; + int get_ext_any = 0; + int ext_any_type = -1; int n_samples = 0; int pin_index = -1, pin_func; int pps = -1; @@ -196,7 +207,7 @@ int main(int argc, char *argv[]) progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) { + while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xy:Y:z"))) { switch (c) { case 'c': capabilities = 1; @@ -273,6 +284,29 @@ int main(int argc, char *argv[]) case 'X': getcross = 1; break; + case 'y': + get_ext_any = atoi(optarg); + if (get_ext_any < 1 || get_ext_any > PTP_MAX_SAMPLES) { + fprintf(stderr, + "number of extended-any timestamp samples must be between 1 and %d; was asked for %d\n", + PTP_MAX_SAMPLES, get_ext_any); + return -1; + } + break; + case 'Y': + if (!strcasecmp(optarg, "real")) + ext_any_type = PTP_TS_REAL; + else if (!strcasecmp(optarg, "mono")) + ext_any_type = PTP_TS_MONO; + else if (!strcasecmp(optarg, "raw")) + ext_any_type = PTP_TS_RAW; + else { + fprintf(stderr, + "type needs to be one of real,mono,raw only; was given %s\n", + optarg); + return -1; + } + break; case 'z': flagtest = 1; break; @@ -286,6 +320,14 @@ int main(int argc, char *argv[]) } } + /* For ptp_sys_offset_any both options 'y' and 'Y' must be given */ + if (get_ext_any > 0 && ext_any_type == -1) { + fprintf(stderr, + "For extended-any TS both options -y, and -Y are required.\n"); + usage(progname); + return -1; + } + fd = open(device, O_RDWR); if (fd < 0) { fprintf(stderr, "opening %s: %s\n", device, strerror(errno)); @@ -604,6 +646,36 @@ int main(int argc, char *argv[]) free(xts); } + if (get_ext_any) { + ats = calloc(1, sizeof(*ats)); + if (!ats) { + perror("calloc"); + return -1; + } + + ats->n_samples = get_ext_any; + ats->ts_type = ext_any_type; + + if (ioctl(fd, PTP_SYS_OFFSET_ANY2, ats)) { + perror("PTP_SYS_OFFSET_ANY2"); + } else { + printf("extended-any timestamp request returned %d samples\n", + get_ext_any); + + for (i = 0; i < get_ext_any; i++) { + printf("sample #%2d: %s before: %lld.%09u\n", + i, time_base_arr[ext_any_type], + ats->ts[i][0].sec, ats->ts[i][0].nsec); + printf(" phc time: %lld.%09u\n", + ats->ts[i][1].sec, ats->ts[i][1].nsec); + printf(" %s after: %lld.%09u\n", + time_base_arr[ext_any_type], + ats->ts[i][2].sec, ats->ts[i][2].nsec); + } + } + + free(ats); + } close(fd); return 0; }