From patchwork Fri Sep 29 02:37:43 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: 146451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3861245vqu; Fri, 29 Sep 2023 01:16:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBe3ADfjgXuOZb/uZRzEeTSMMcVrX/q1dypr39qmvdDmmy4pL7PVQ176C47rsD35JF2K3m X-Received: by 2002:a05:6a20:4422:b0:14b:8b82:867f with SMTP id ce34-20020a056a20442200b0014b8b82867fmr4117005pzb.50.1695975363965; Fri, 29 Sep 2023 01:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695975363; cv=none; d=google.com; s=arc-20160816; b=Pj0BkmyLe71nBUrj50V0YvNqSdpJytaMWTq15RQSa/cKm9F0/aH54TSy2h4CJrNqhN RTLxvFFQuxRnqGcfWiolEGVOj4unYLFtGjH5lmoND3MkFo353+VlEM+r9mv99PQwdbPc 6l5IekcZv7w8/tQd7jRBchZfgFL2EMfYkDyyqFX0MCaeh+lZTPNg9SAntoEqUo4Vo4j2 iJ3bCunKcfs2/0PxPDzTySwZb/EYNb+AB1vu5IHIlTKH6gMP+napxnP4FJkrFdI9+ov+ PobtOi92lh59QBy3nurpfTPfAJqgkEqu4AwYaX+NJZiIW+KKJOoujAYylGo1f8yb03Oj 1OCg== 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=lqddVV7lEvzc1PVC4l13jtQo0ILYRjKD+2QyANiZoos=; fh=cLvLkL9HGfZLaTe/GCdTFm7AOHVempMxHhTK0cDjnek=; b=df4rrt50BGm6BTJ5TTwsq5sK8ovF+y86y+7bqMAm6LHzEiATxmfoIfclkpMBhQGxc0 Gcaql+dc3/E3mZgHhqpBMYl/NH7uXmgx/jfQKCVQgRxFLu3p1AdrtK4VzmDCp5ejvas1 GkgdXSYOSJC9KfubaMomQH65SGtyIN2LiwOyKWs6JwQGBTLd1llDNjAv0Fl0sRjrejgV u/OLkIViNsKltzmDAvBSTXc59sPFO2+m1WtiBSJetOfjyK9uZKUBPJn8+KDZx4bQ1arW 4S2nGAx+jHZlNSOf4cAGgjjGohdUaEYr41J3ZLD88zdRmeDmCGvyHHCyWj6voabXzoYx 7CDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ThPgjp8H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id i8-20020a170902c94800b001c724f99800si7653533pla.44.2023.09.29.01.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 01:16:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ThPgjp8H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 5D71F80AF829; Thu, 28 Sep 2023 19:37:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbjI2Chx (ORCPT + 21 others); Thu, 28 Sep 2023 22:37:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231576AbjI2Cht (ORCPT ); Thu, 28 Sep 2023 22:37:49 -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 0A6ED1A3 for ; Thu, 28 Sep 2023 19:37:47 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d84acda47aeso23067111276.3 for ; Thu, 28 Sep 2023 19:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695955066; x=1696559866; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lqddVV7lEvzc1PVC4l13jtQo0ILYRjKD+2QyANiZoos=; b=ThPgjp8HumPnZygQEdqfj+AMQ7/gwrbgp9JnRffJGAeVrCn2MnH4Ask+NxAgde3Zwf zjUfw4FxmdHLqg2ZNo6F8+kM8pOIHq84nEaVP7f3jq9N1B1Jkkr99J50aydr05WCr7PS SW9jtIugb306IU5p3ljLkIJ5er7tyV2nPD7XYbnYFR2T6/XjM1G4T6/rdwa3keHActIs Abfcjhceco1w1RXYyU973auO1ma6cQ5z6lVs3z7bBC7DPNXsMgJXvHnszrX9XA+1B4tK Ru3DawxuwnCnXpWDF9aLZeW+RyGk4elRoASVDvAKavNc0HXrKisAcN2o2+2+l0hhhMwM azCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695955066; x=1696559866; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lqddVV7lEvzc1PVC4l13jtQo0ILYRjKD+2QyANiZoos=; b=HWLEx54vJZ0Uv/8y4AbkjNCell7UrP1bAAJTgpEXmFP39aW8TF2TM/cJCflxQnUlNF Y5kRlf4uESYrJ4FBOAuKS176hjj9Gr6ICCblJEro11Ll5m2LDbuKjeHQW5KQi4GSSttg 3s5gzlsQM4tzUr+By61HUsWchiXhENdY3ZHceG3WSRpGLzsGZSkyQufbD7J0j5zsKANi PbcymVsQeCXRinsXMNCh1MoeHroFvuX5USlx4Koc8JqeWjKYx87SAN0EW3oAaeyE4MwU k89DdzW2gVJp3qqMq4p/jHK/ah8I0/qSxmqbrF8YXaGKdYT3PpT5zF1B36GTKeWNSR6Y Uz/g== X-Gm-Message-State: AOJu0YzzCoOTl9emDn1LW3qTLOa2PhNx9trtSKWWsmI2q4Crr45KmHMh btDMpigrr3/0OsYYq3TzSqaj46Wgttqa X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a25:6f54:0:b0:d77:bcce:eb11 with SMTP id k81-20020a256f54000000b00d77bcceeb11mr41975ybc.10.1695955065762; Thu, 28 Sep 2023 19:37:45 -0700 (PDT) Date: Thu, 28 Sep 2023 19:37:43 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929023743.1611460-1-maheshb@google.com> Subject: [PATCH 3/4] ptp: add ioctl interface for ptp_gettimex64any() 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 , Rahul Rameshbabu 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_BLOCKED,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 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 19:37:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778359063234677968 X-GMAIL-MSGID: 1778359063234677968 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 1f1e98966cff..73bd17055a37 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -166,6 +166,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; @@ -232,6 +244,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. */