Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7959626rdb; Thu, 4 Jan 2024 13:25:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLBLMPMXJYEy1E2TsZuP8dmtcMz6Q/kgYzGTRDUXVct2r+73S45rKx6ZzzQUDgrvF2Z53Q X-Received: by 2002:a05:6358:63aa:b0:16d:bc51:7601 with SMTP id k42-20020a05635863aa00b0016dbc517601mr907758rwh.9.1704403528533; Thu, 04 Jan 2024 13:25:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704403528; cv=none; d=google.com; s=arc-20160816; b=NDDoMv5t76AvlLq4D2LpVTUAktoRzMwVtlD1LUNhWNoC1VFUiA7PVz5qfUDfdaOsd/ vvZC///4mviNMDE5Oym8mOgEoHclDdqStJ0Q52XJy2hgvRmxU7YAhC4dr7NFAXDfmwyg pqVpUwae1REqTngRoVe3ZXMWOKQ4BIwhFJn8zND4clI5odhV3UI8s09YdvCZYMJgbTg0 /QS0WxVbCzfqvYfzMQDD8cuT0rCkdQHdIsdq5RoxTOtbRDVTz+V1GeTF7sb6chnU8ALJ 0d0mNt/2lqeDS+8Qzp7YTehIJthMDNawtD08oHPDUBz2RiHPmIF2qQ1EKhexup2Z6rDR Y8EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=YsAJCiIBvgndyLh0nU4MixTydeQR6acGfzT1miAC0JA=; fh=eue65t437wyhmkSPHQRWvmcc1fbOXiku5Au2KSH9hQ4=; b=t8679NpoAxyvP9ktMcejBGluOnL55Y+n5i35yeK3jTRExI8NXz82B2ZN9aPwkW735F jIPMOZVxCCNyRyulM21fUuPk23bOP1/fTKdP1KKRo6Ks9p8DUewd6QeZ9Y8NnV2SnfDf pdKhp51IEuXfGGH+ykAgfjSLIob5apD7XxVH0ryaigu+BDphGyMLYi00t0Ak/hRwqI/J wmmQGsWAdFghmqfAyQwppmyniuchMQAsBEytSdwM6IHuhoGBIdXbp8tvSEHFAnFm1Z0o zxOshYUVx48fRZA3ikpJk3N6Yu+wVeEiD4iUBaswN6VQ/gXBR+YIR0Cd0g1ptsQEdVoe FyQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RyjBMIql; spf=pass (google.com: domain of linux-kernel+bounces-17236-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l24-20020a656818000000b005cdff1f4816si196445pgt.424.2024.01.04.13.25.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:25:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17236-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RyjBMIql; spf=pass (google.com: domain of linux-kernel+bounces-17236-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F77C2864E0 for ; Thu, 4 Jan 2024 21:25:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98CAF2D021; Thu, 4 Jan 2024 21:24:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RyjBMIql" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BA852C87D for ; Thu, 4 Jan 2024 21:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--maheshb.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbe053d5d91so1383463276.2 for ; Thu, 04 Jan 2024 13:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704403482; x=1705008282; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=YsAJCiIBvgndyLh0nU4MixTydeQR6acGfzT1miAC0JA=; b=RyjBMIqlE311DaqGjKy8LExpBMxE+BQp2X6F8mvzCH95q6TVq1tKDY0T54uYsB+5DP b0Z6IfUCXrj9WSq1O5DCiZLWC2oEXltk8NegwpqELO8BloDjjeiG9SQvijPnzQGJ90ra XOZLBtCzT7t65EX4DpnYDzgn/fTHcncyPgvr6Dx1PRLMqHZqUoBHRqrbjFQf7AeEz4Tx ePKE3F+zt6nZ3SeUP9DsqsirNN5uOHG2oyjpby+AjvyON4jGyX6u0wgw0+DiebrKOaE5 omRjs0L/tdPO22I8DLCok5ETkYbNJF/X+/yg5+2T4xA6HbLvcYuLRTdYvet4Njd8XQPL qpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704403482; x=1705008282; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YsAJCiIBvgndyLh0nU4MixTydeQR6acGfzT1miAC0JA=; b=uwugIzTabKfCaSkLz1EdyuIbJuMqQNJ7BF/fP06SM4Yq5FvfG8psePuhg3j45svmgA fbJrZBP+0bGYjrwoMSSZ+v9jMj/WXRkqwPFUd5ixXC0cedgtehKN0GbDjRunIEDYJrfu VfQPgz1arpbTtbowV/lqfjldN0WJOgZzn1XnZ4dtA9lZSlvO0gPN0GvrYkZO8qCYaa9g T/a6MHEPgtDk+9J5HCSEtBeU1iWGxafshn6Jpf6q1TNjWpwGS3puW/HEreUObdXHdl0b vPeFkoi1E9D1Y9q9wEgHE5tXJcz1vPLACabt4JGNFIEJ4sE/hCAB4MXQUXoFF1efk0Mf YSqQ== X-Gm-Message-State: AOJu0YxMco8iwAmm3AO26WoyAJdq18VG0naQw3Xgnj9iLaADeSGdLWZc KYf3w3/PmOgjoSxkudHWsyJp+2gfrQ2iwqDS4JY= X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a05:690c:368b:b0:5de:9c9f:3ee4 with SMTP id fu11-20020a05690c368b00b005de9c9f3ee4mr625667ywb.6.1704403482530; Thu, 04 Jan 2024 13:24:42 -0800 (PST) Date: Thu, 4 Jan 2024 13:24:39 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.195.gebba966016-goog Message-ID: <20240104212439.3276458-1-maheshb@google.com> Subject: [PATCHv3 net-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 , Willem de Bruijn Content-Type: text/plain; charset="UTF-8" add an ioctl op PTP_SYS_OFFSET_ANY to support newly added ptp_gettimex64any() method Signed-off-by: Mahesh Bandewar CC: Richard Cochran CC: "David S. Miller" CC: John Stultz CC: Jakub Kicinski CC: "Willem de Bruijn" CC: netdev@vger.kernel.org --- drivers/ptp/ptp_chardev.c | 37 ++++++++++++++++++++++++++++++++++ include/uapi/linux/ptp_clock.h | 14 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index 7513018c9f9a..f20d43c34aec 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -161,6 +161,7 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, struct ptp_clock *ptp = container_of(pccontext->clk, 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; @@ -378,6 +379,42 @@ long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd, err = -EFAULT; break; + case PTP_SYS_OFFSET_ANY: + 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->rsv[0] || anyoff->rsv[1] + || (anyoff->clockid != CLOCK_REALTIME + && anyoff->clockid != CLOCK_MONOTONIC + && anyoff->clockid != CLOCK_MONOTONIC_RAW)) { + err = -EINVAL; + break; + } + + for (i = 0; i < anyoff->n_samples; i++) { + err = ptp->info->gettimex64any(ptp->info, &ts, &sts, + anyoff->clockid); + 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 da700999cad4..a3143df8de2b 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -158,6 +158,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. */ + clockid_t clockid; /* One of the supported ClockID */ + 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; @@ -226,6 +238,8 @@ struct ptp_pin_desc { _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended) #define PTP_MASK_CLEAR_ALL _IO(PTP_CLK_MAGIC, 19) #define PTP_MASK_EN_SINGLE _IOW(PTP_CLK_MAGIC, 20, unsigned int) +#define PTP_SYS_OFFSET_ANY \ + _IOWR(PTP_CLK_MAGIC, 21, struct ptp_sys_offset_any) struct ptp_extts_event { struct ptp_clock_time t; /* Time event occured. */ -- 2.43.0.195.gebba966016-goog