From nobody Wed Nov 27 03:46:51 2024 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9445F1E4110; Tue, 15 Oct 2024 10:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728989687; cv=none; b=MT5UpaWkFU3Eu6plrgC+FUEHHQIt9dBO0AP3RkAz+z+LygNPWcHEmaDIxxFY4IIn4OdCK3BEYRAdWN3JsjfW52gmsnoHZdpSkr5CNugRaLyZaeOuwrjM9WWyKwz93q7yehwEm6k6nsHeFvhavJ6ppLqiHPO5Gi9rCeoBTBMvBio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728989687; c=relaxed/simple; bh=0k/jNEZc9lfw3abXbvYAwbVUgS/oBQHM402EpxxJEL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bz3GaOKnFvo2xGTkTqLvuyaFzNwnlOdE9Bvvgt5Fd2J7YZKyS1QS2UQdqtWaJu1IweS2geasP0McbGflGWzJ2g36JM9Helj7p4onjUjncH3dh2tcG1s1S9MUvulPPKZ2NN83Ew4RTQnEuPjX1Sdb6BwhrjO1QS9XvuU4VHgQiF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=OOXssZ4S; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="OOXssZ4S" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49F8PH6T023757; Tue, 15 Oct 2024 10:54:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=xWzekMjwCNm9ExClS aAQzXmfQqt81BO5Jsxrhu4BjCI=; b=OOXssZ4Se4fF7xTxZozqpzo8QUn90El61 vNB4ecoOfC12mhYFPuwDSIZ6tlAhiptIU0o6HrsZxPsSjJzyLevnjBccgK5qELF0 L17Y0eR4/0VAa1y158oXJ09ebQF4HjORFCyzhtxBxeYx/UjJZt8PNOTGJP4UCb6W t9C2EJK5+lXFdJXPOy7lr4Lmg5ma7AVpJHHZ23PmpNA0zmyLucZXuQILN0nS1FtX 9npwH58ODtSV9HZ+LN7/+Nzl5NpZBJSS+RhBYvlVOzbkTjXN/5rMBw+APsuxLtLK cnfZfmVe75k8ooZim6ja7RKf5zUOFVvwj/iYaOtVE7RSjwQAUb2cg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 429mv4rq5f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 15 Oct 2024 10:54:35 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 49FAsZg4030367; Tue, 15 Oct 2024 10:54:35 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 429mv4rq57-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 15 Oct 2024 10:54:35 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49FAaibc027444; Tue, 15 Oct 2024 10:54:34 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4283txkdvw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 15 Oct 2024 10:54:33 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49FAsUFn51970378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Oct 2024 10:54:30 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CDA482004F; Tue, 15 Oct 2024 10:54:29 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1AC420040; Tue, 15 Oct 2024 10:54:29 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTPS; Tue, 15 Oct 2024 10:54:29 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55390) id 80EA7E055C; Tue, 15 Oct 2024 12:54:29 +0200 (CEST) From: Sven Schnelle To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Richard Cochran , Greg Kroah-Hartman , "Ricardo B. Marliere" Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 3/3] s390/time: Add PtP driver Date: Tue, 15 Oct 2024 12:54:14 +0200 Message-ID: <20241015105414.2825635-4-svens@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241015105414.2825635-1-svens@linux.ibm.com> References: <20241015105414.2825635-1-svens@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: jECDl6rk-BHAvlkDz4_BbmrA8OgcOX7S X-Proofpoint-ORIG-GUID: -GpnZA_NsMDY0Tv2iWPt-UqVL1JdW3Xo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 mlxscore=0 suspectscore=0 phishscore=0 adultscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410150072 Content-Type: text/plain; charset="utf-8" Add a small PtP driver which allows user space to get the values of the physical and tod clock. This allows programs like chrony to use STP as clock source and steer the kernel clock. The physical clock can be used as a debugging aid to get the clock without any additional offsets like STP steering or LPAR offset. Signed-off-by: Sven Schnelle --- MAINTAINERS | 6 ++ arch/s390/include/asm/timex.h | 8 +++ arch/s390/kernel/time.c | 7 ++ drivers/ptp/Kconfig | 11 +++ drivers/ptp/Makefile | 1 + drivers/ptp/ptp_s390.c | 127 ++++++++++++++++++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 drivers/ptp/ptp_s390.c diff --git a/MAINTAINERS b/MAINTAINERS index 7ad507f49324..94793c935e86 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20328,6 +20328,12 @@ F: Documentation/arch/s390/pci.rst F: arch/s390/pci/ F: drivers/pci/hotplug/s390_pci_hpc.c =20 +S390 PTP DRIVER +M: Sven Schnelle +L: linux-s390@vger.kernel.org +S: Supported +F: drivers/ptp/ptp_s390.c + S390 SCM DRIVER M: Vineeth Vijayan L: linux-s390@vger.kernel.org diff --git a/arch/s390/include/asm/timex.h b/arch/s390/include/asm/timex.h index 640901f2fbc3..4fc88a1493f0 100644 --- a/arch/s390/include/asm/timex.h +++ b/arch/s390/include/asm/timex.h @@ -93,6 +93,7 @@ extern unsigned char ptff_function_mask[16]; #define PTFF_QAF 0x00 /* query available functions */ #define PTFF_QTO 0x01 /* query tod offset */ #define PTFF_QSI 0x02 /* query steering information */ +#define PTFF_QPT 0x03 /* query physical clock */ #define PTFF_QUI 0x04 /* query UTC information */ #define PTFF_ATO 0x40 /* adjust tod offset */ #define PTFF_STO 0x41 /* set tod offset */ @@ -250,6 +251,12 @@ static __always_inline unsigned long tod_to_ns(unsigne= d long todval) return ((todval >> 9) * 125) + (((todval & 0x1ff) * 125) >> 9); } =20 +static __always_inline unsigned long eitod_to_ns(union tod_clock *clk) +{ + clk->eitod -=3D TOD_UNIX_EPOCH; + return ((clk->eitod >> 9) * 125) + (((clk->eitod & 0x1ff) * 125) >> 9); +} + /** * tod_after - compare two 64 bit TOD values * @a: first 64 bit TOD timestamp @@ -278,4 +285,5 @@ static inline int tod_after_eq(unsigned long a, unsigne= d long b) return a >=3D b; } =20 +bool stp_enabled(void); #endif diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c index 4214901c3ab0..47b20235953c 100644 --- a/arch/s390/kernel/time.c +++ b/arch/s390/kernel/time.c @@ -469,6 +469,13 @@ static void __init stp_reset(void) } } =20 +bool stp_enabled(void) +{ + return test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags) && + stp_online; +} +EXPORT_SYMBOL(stp_enabled); + static void stp_timeout(struct timer_list *unused) { queue_work(time_sync_wq, &stp_work); diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig index 604541dcb320..907330413ef8 100644 --- a/drivers/ptp/Kconfig +++ b/drivers/ptp/Kconfig @@ -224,4 +224,15 @@ config PTP_DFL_TOD To compile this driver as a module, choose M here: the module will be called ptp_dfl_tod. =20 +config PTP_S390 + tristate "S390 PTP driver" + depends on PTP_1588_CLOCK + default y + help + This driver adds support for S390 time steering via the PtP + interface. This works by adding a in-kernel clock delta value, + which is always added to time values used in the kernel. The PtP + driver provides the raw clock value without the delta to + userspace. That way userspace programs like chrony could steer + the kernel clock. endmenu diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile index 68bf02078053..4dd9f35eb0cf 100644 --- a/drivers/ptp/Makefile +++ b/drivers/ptp/Makefile @@ -21,3 +21,4 @@ obj-$(CONFIG_PTP_1588_CLOCK_MOCK) +=3D ptp_mock.o obj-$(CONFIG_PTP_1588_CLOCK_VMW) +=3D ptp_vmw.o obj-$(CONFIG_PTP_1588_CLOCK_OCP) +=3D ptp_ocp.o obj-$(CONFIG_PTP_DFL_TOD) +=3D ptp_dfl_tod.o +obj-$(CONFIG_PTP_S390) +=3D ptp_s390.o diff --git a/drivers/ptp/ptp_s390.c b/drivers/ptp/ptp_s390.c new file mode 100644 index 000000000000..4edccebcf2b5 --- /dev/null +++ b/drivers/ptp/ptp_s390.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * s390 PTP clock driver + * + */ + +#include "ptp_private.h" +#include +static struct ptp_clock *ptp_stcke_clock, *ptp_qpt_clock; + +static int ptp_s390_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) +{ + return -EOPNOTSUPP; +} + +static int ptp_s390_adjtime(struct ptp_clock_info *ptp, s64 delta) +{ + return -EOPNOTSUPP; +} + +static struct timespec64 eitod_to_timespec64(union tod_clock *clk) +{ + return ns_to_timespec64(eitod_to_ns(clk)); +} + +static struct timespec64 tod_to_timespec64(unsigned long tod) +{ + return ns_to_timespec64(tod_to_ns(tod - TOD_UNIX_EPOCH)); +} + +static int ptp_s390_stcke_gettime(struct ptp_clock_info *ptp, + struct timespec64 *ts) +{ + union tod_clock tod; + + if (!stp_enabled()) + return -EOPNOTSUPP; + + store_tod_clock_ext_cc(&tod); + *ts =3D eitod_to_timespec64(&tod); + return 0; +} + +static int ptp_s390_qpt_gettime(struct ptp_clock_info *ptp, + struct timespec64 *ts) +{ + unsigned long tod; + + ptff(&tod, sizeof(tod), PTFF_QPT); + *ts =3D tod_to_timespec64(tod); + return 0; +} + +static int ptp_s390_settime(struct ptp_clock_info *ptp, + const struct timespec64 *ts) +{ + return -EOPNOTSUPP; +} + +static int s390_arch_ptp_get_crosststamp(ktime_t *device_time, + struct system_counterval_t *system_counter, + void *ctx) +{ + union tod_clock clk; + + store_tod_clock_ext_cc(&clk); + *device_time =3D ns_to_ktime(tod_to_ns(clk.tod - TOD_UNIX_EPOCH)); + system_counter->cycles =3D clk.tod; + system_counter->cs_id =3D CSID_S390_TOD; + return 0; +} + +static int ptp_s390_getcrosststamp(struct ptp_clock_info *ptp, + struct system_device_crosststamp *xtstamp) +{ + if (!stp_enabled()) + return -EOPNOTSUPP; + return get_device_system_crosststamp(s390_arch_ptp_get_crosststamp, NULL,= NULL, xtstamp); +} + +static struct ptp_clock_info ptp_s390_stcke_info =3D { + .owner =3D THIS_MODULE, + .name =3D "IBM Z STCKE Clock", + .max_adj =3D 0, + .adjfine =3D ptp_s390_adjfine, + .adjtime =3D ptp_s390_adjtime, + .gettime64 =3D ptp_s390_stcke_gettime, + .settime64 =3D ptp_s390_settime, + .getcrosststamp =3D ptp_s390_getcrosststamp, +}; + +static struct ptp_clock_info ptp_s390_qpt_info =3D { + .owner =3D THIS_MODULE, + .name =3D "IBM Z Physical Clock", + .max_adj =3D 0, + .adjfine =3D ptp_s390_adjfine, + .adjtime =3D ptp_s390_adjtime, + .gettime64 =3D ptp_s390_qpt_gettime, + .settime64 =3D ptp_s390_settime, +}; + +static __init int ptp_s390_init(void) +{ + ptp_stcke_clock =3D ptp_clock_register(&ptp_s390_stcke_info, NULL); + if (IS_ERR(ptp_stcke_clock)) + return PTR_ERR(ptp_stcke_clock); + + ptp_qpt_clock =3D ptp_clock_register(&ptp_s390_qpt_info, NULL); + if (IS_ERR(ptp_qpt_clock)) { + ptp_clock_unregister(ptp_stcke_clock); + return PTR_ERR(ptp_qpt_clock); + } + return 0; +} + +static __exit void ptp_s390_exit(void) +{ + ptp_clock_unregister(ptp_qpt_clock); + ptp_clock_unregister(ptp_stcke_clock); +} + +module_init(ptp_s390_init); +module_exit(ptp_s390_exit); + +MODULE_AUTHOR("Sven Schnelle "); +MODULE_LICENSE("GPL"); --=20 2.43.0