From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 674DEC5AC82 for ; Sat, 8 Aug 2026 03:18:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bdioCon70PuUezzxLROIeTJwV/awMUSpnt0xTZfqOKM=; b=KpKaqQLoUHQVjqNvJXzLtG7Z9O MGLQAr+Cl0Cazrgf6PzUFuemIEUSRv3KpauWEQ8smCVuUm0cRjBj6+WdLgVArsmWL0fzIRg+VIm4e F27HHKKzlZ4DdIAnWQ/+eEw18eyoxFAnFMu6dgBFFaxSn4PdDvuBJMWLGW0404pCe4iVVbROT8qQ+ BsUSVHM5HJvbwnsTd8ffAKQekEDBo6DoWsvPlWmMRZymAK7UWKzxIzDOz5wEuLfLa/cc3EJz3Y9rm gMtjVVK6erxLUj5GAk6fxhijFl7dRU8xpenylVfmuGgGes1tZ+27j9swgZf4mO7MEKmSQQc7xsmpk oVoPpM/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wsXZt-00000009124-3NzB; Sat, 08 Aug 2026 03:18:29 +0000 Received: from mail-norwayeastazlp170130007.outbound.protection.outlook.com ([2a01:111:f403:c20f::7] helo=OSPPR02CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wsXZo-000000090ys-3o7N for linux-arm-kernel@lists.infradead.org; Sat, 08 Aug 2026 03:18:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Lt7U+SqM4xjBf/Fsc9tyMkiGDDDOgbpXR9LUIr13IbhTTrqBWITOUrmUDVyJq61IC86MCoTAdvgfog00xe5jZ3zHAMHmoNk4NxTIc6IWfsUH85kpLwvzyvWKNfAI3GVgOURvRrBscsCS7YGJsf/dUVKRKrMRkIqiG2f/o5yKmW7Okz07RkapFNH5fInQHRptmKJcAzY2sfxSbUQ8k3yinhgvt0cd2hqJYRdcZBDJQxnc1XAW2W2KYFiYhqg073ACutycnts29JhcXjxj0OPVInpV2OXG23UTV9ekQ5fMyky0NLNkAWB6PTuS7qJu7so8GottezgQAuWW/W0OvLmkjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bdioCon70PuUezzxLROIeTJwV/awMUSpnt0xTZfqOKM=; b=CiVnrDvac7f4AdagFvzfj+hWKHmEuOqR+t+h58hGW0Ci4vUWCbHi0tCDwA15SYEz4p24ZYOLyfdExeXFEPKQWSuUzlzhD5cR4cQjzd575rMDNB8+vaOUczW6Gr+o0RlKV2+0nzyrA4iDFPKWQLIlEKc/hnOy3TrDUKzYKnkAyEIbHfR5nRCE5rLzVd+fXLDMjQ6P/Gv6eLBBxlg7/D1D1w96Gimh2LpS3H9QOMevFyq0ct+KG8Svuqg6eLVbqA7Ru435jXf3fzbHN+8enVRzGbf11LsLpFAp+LefOmw86QhoGrqDXG8YLcx6UPWeL4s/0OX7xcqsCDz7oHJLH7hd3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bdioCon70PuUezzxLROIeTJwV/awMUSpnt0xTZfqOKM=; b=ZZy1gXMzc+j4l7P41oftO8H78JD+bOg2wBZljjjJqg8GG3+MSA548Fha7qtt4hNfa+PJnqS4SMR61Q8mTxF8YL52bG5mpAK6f2t8fgirw3MvyC6NNnIksRQdVxlXln6sHef/r9kmddXuFsRBj1LhCR22GGIYXmzDGnXEz+Fsdz4CBXoTedhvPdXNdyJrQoLl0QyepXxrkXc7mE6tL7nBoQ7YyL8vHKir6DaIJwtmfWeJyQMfBazAQW2GCf9duLZQ8qn3AcbI14cecvl/5zYoVBPg/F4CDofhNT3m/xOkVsJ3RM+NSekJR35PRy1yL1nH7cOLfSpGJFB74Hwn/H35xA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB7216.eurprd04.prod.outlook.com (2603:10a6:800:1b0::22) by DU2PR04MB8936.eurprd04.prod.outlook.com (2603:10a6:10:2e3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.24; Sat, 8 Aug 2026 03:18:21 +0000 Received: from VE1PR04MB7216.eurprd04.prod.outlook.com ([fe80::a9a5:cf83:dbe8:1f74]) by VE1PR04MB7216.eurprd04.prod.outlook.com ([fe80::a9a5:cf83:dbe8:1f74%3]) with mapi id 15.21.0292.022; Sat, 8 Aug 2026 03:18:21 +0000 From: wei.fang@oss.nxp.com To: xiaoning.wang@nxp.com, andrew@lunn.ch, olteanv@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, richardcochran@gmail.com Cc: wei.fang@nxp.com, imx@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 net-next 1/7] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access Date: Sat, 8 Aug 2026 11:21:40 +0800 Message-Id: <20260808032146.2335723-3-wei.fang@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260808032146.2335723-1-wei.fang@oss.nxp.com> References: <20260808032146.2335723-1-wei.fang@oss.nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2PR01CA0001.apcprd01.prod.exchangelabs.com (2603:1096:4:191::13) To VE1PR04MB7216.eurprd04.prod.outlook.com (2603:10a6:800:1b0::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB7216:EE_|DU2PR04MB8936:EE_ X-MS-Office365-Filtering-Correlation-Id: 646b52ee-49c1-4d1b-d487-08def4fbb2ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|23010399003|366016|19092799006|18002099003|22082099003|56012099006|11063799006|10067099003|921020; X-Microsoft-Antispam-Message-Info: 9uXSOGpPjkeCUdeiPeJOUXCFJDgdsODVFk8OxftF0RDj0Tu5YkhiOmJ1EnbxLNSoyL4Zo3MfozcuMaHncA8VMaDyHnTu7MnjN2XsV/v5atSNvBHLB7rIYE6fSVzTu+uRjSTkVZe1rZqGA5H5/1OHLJvohZT9UPkbUXWQqGJkFHP5oyJm7HTR87Hi8Ehqr30HiIRZAko5basAXx6jDthpf8zkMHFTmRFc3iO/ImNwzggD1jfeyEJmKc5g7qLocdM4tgYLHqLn9d996wSaUsLYkF/stTqeTpXxfecmMHhvzckbTg8OfitnP5xU+MhPlnfiZYGIjAddpEqa2vfBPIDso6HH1CCPQscqibIYcdv7FPk/MsOXE7NyMupFKOSNdAeD70MuHMXLK+KBYtyR1yPlVU32/V+nsqZ3Nvt9gBi4k5mGJD3oGH4HEmkwQ5Yiq2wu2ywptoH2eAdots+3/l1zr33GdYYW1kDZzV3B7ruFDjry0UNFcbVpmS46gd/Tw3ujPPH1azKx5pZuxV/YEWn9P3Z6BKl7CWpvs6e5hrpzgdjnU898d7W2PFS7dMOK/gf9JwR2aSHdVoEPOLKTePKWywOk8KsMbNBWqsNuNSfXD2Wjg7/mCHkTT5HswyPIdThMbjqH6vmBMLfUF37pLFUi0495tRRtPS4d/Oej9xSestONr6lVQ9XM/3fATux6plUKpXwthKoPR5SMsm433E4/Lw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB7216.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(23010399003)(366016)(19092799006)(18002099003)(22082099003)(56012099006)(11063799006)(10067099003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?KxoCwxNIPyfSt7Rt3a0QBXN385ByDM4nyaTXE5U7h03n4OFAyVR2FXU9SCOa?= =?us-ascii?Q?zf9WyA+sM669kA18ITp6pXbFIAkUQhF5hLBDxxhJQeoGzSw9K+zTrNUONDrh?= =?us-ascii?Q?lfntBYIOWq4elvOOjFKLfqazKxyGwyAfx90FDqPp/41ZWkx/2CO+beiKvEkz?= =?us-ascii?Q?SThZKQP16+SdJUAfvRwu4lIPqJjHTxpydjeuIKojaAMm6ZkWsECyIZ4KyqSh?= =?us-ascii?Q?FDZA3YvoMn1BPZlt9q8SUuc5mgbndmFbrfHXfTg144F61nTM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EdnC1KcJ53cyhLQFRZ42pqEtzuZHL5a+L5d/qy3pQBha4?= =?us-ascii?Q?IFWkcd7iwUl4N2VrqssBLIcDQR8eYGwp2uKzxxfUZb/xrYxZjO0V/a7+M9QB?= =?us-ascii?Q?QV7VxeGVHzN8jqoo4hi+MlJKI6qpX0CdN5vpMQW3JtPN4gDRAhxWuLnjxwrW?= =?us-ascii?Q?HSbW82FPD9SK8Osh14q1tC7ttsAamTFRYYZJtHChHcqHaZXUIH6NUNKqGICs?= =?us-ascii?Q?8iDNvvy9KicfHcUA8Rnw+l6sqiKy7t0I73R+ZeWlc1k+hs0DkX+S/z3uNbQn?= =?us-ascii?Q?+mbt5eqfQU80iAiP6mnF7YiBkwVQgmmeGWC+gTLry/0RKuy+VA8EM4HhSrm8?= =?us-ascii?Q?8pZvQmjElpsunnH08LWZgeunGFwXMjDYLSBe44XOy/ni0ezKwYYN+zFCLJu0?= =?us-ascii?Q?PblCzTwCoPieoKQpJyRWK/zV1TUYjV4LADb1pfTzafikx/LmJ+ULyYWX7BHS?= =?us-ascii?Q?a0AWCTrdbxG366LdKmfoZHwIEjnb3HTUIsKE+TPat75LbegQt8ECpd5qI70a?= =?us-ascii?Q?Q12Bpqz9nWqWHc8zsoZHl6/G43GXiVTL8hrQXXcAtgaT2oMpEKp5CpOgV36i?= =?us-ascii?Q?mqb/TeS5UdW14UW6j2q9zQYPBBGyqGUWaI0Q9PcKx7sNP4M0QZKr?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 646b52ee-49c1-4d1b-d487-08def4fbb2ee X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB7216.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2026 03:18:21.0254 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fFPv9hWgfXXVuQcECiAGMN/NE0Mu8sdKFxEReBVJ9vLo121ztVr6FzVxRqMGADYcM4IqwW8zHgeeFvHKIs+bBvU5Qtj56hCFpXA7TJas6aSQYroK4MaWHjBMPCeBlwGD X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8936 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260807_201824_952980_F5A0C0FB X-CRM114-Status: GOOD ( 17.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Wei Fang Replace the open-coded 64-bit register read/write sequences with ioread64_lo_hi() and iowrite64_lo_hi() helpers. Introduce two new macros netc_timer_rd64() and netc_timer_wr64() that wrap these helpers and use them throughout the driver. This reduces boilerplate and makes the intent of each operation clearer. The high-half register defines (NETC_TMR_*_H) are kept to document the register map; they are not used directly since netc_timer_rd/wr64() address the 64-bit register pair via the low-half offset, relying on the hardware layout where H is always at L + 4. Signed-off-by: Wei Fang --- drivers/ptp/ptp_netc.c | 72 ++++++++++++------------------------------ 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/drivers/ptp/ptp_netc.c b/drivers/ptp/ptp_netc.c index 1c20d7efab92..0e0972596d88 100644 --- a/drivers/ptp/ptp_netc.c +++ b/drivers/ptp/ptp_netc.c @@ -127,6 +127,17 @@ struct netc_timer { #define netc_timer_rd(p, o) netc_read((p)->base + (o)) #define netc_timer_wr(p, o, v) netc_write((p)->base + (o), v) + +/* The 64-bit timer registers consist of a low (L) and high (H) register pair. + * Hardware requires a strict access order: for writes, TMR_xxx_L must be + * written first, which latches the value into a shadow register; the write + * to TMR_xxx_H then atomically transfers both shadow registers into the live + * counter. For reads, TMR_xxx_L must be read first to capture a coherent + * snapshot. iowrite64_lo_hi() and ioread64_lo_hi() enforce this L-before-H + * ordering. + */ +#define netc_timer_rd64(p, o) ioread64_lo_hi((p)->base + (o)) +#define netc_timer_wr64(p, o, v) iowrite64_lo_hi(v, (p)->base + (o)) #define ptp_to_netc_timer(ptp) container_of((ptp), struct netc_timer, caps) static const char *const timer_clk_src[] = { @@ -136,66 +147,28 @@ static const char *const timer_clk_src[] = { static void netc_timer_cnt_write(struct netc_timer *priv, u64 ns) { - u32 tmr_cnt_h = upper_32_bits(ns); - u32 tmr_cnt_l = lower_32_bits(ns); - - /* Writes to the TMR_CNT_L register copies the written value - * into the shadow TMR_CNT_L register. Writes to the TMR_CNT_H - * register copies the values written into the shadow TMR_CNT_H - * register. Contents of the shadow registers are copied into - * the TMR_CNT_L and TMR_CNT_H registers following a write into - * the TMR_CNT_H register. So the user must writes to TMR_CNT_L - * register first. Other H/L registers should have the same - * behavior. - */ - netc_timer_wr(priv, NETC_TMR_CNT_L, tmr_cnt_l); - netc_timer_wr(priv, NETC_TMR_CNT_H, tmr_cnt_h); + netc_timer_wr64(priv, NETC_TMR_CNT_L, ns); } static u64 netc_timer_offset_read(struct netc_timer *priv) { - u32 tmr_off_l, tmr_off_h; - u64 offset; - - tmr_off_l = netc_timer_rd(priv, NETC_TMR_OFF_L); - tmr_off_h = netc_timer_rd(priv, NETC_TMR_OFF_H); - offset = (((u64)tmr_off_h) << 32) | tmr_off_l; - - return offset; + return netc_timer_rd64(priv, NETC_TMR_OFF_L); } static void netc_timer_offset_write(struct netc_timer *priv, u64 offset) { - u32 tmr_off_h = upper_32_bits(offset); - u32 tmr_off_l = lower_32_bits(offset); - - netc_timer_wr(priv, NETC_TMR_OFF_L, tmr_off_l); - netc_timer_wr(priv, NETC_TMR_OFF_H, tmr_off_h); + netc_timer_wr64(priv, NETC_TMR_OFF_L, offset); } static u64 netc_timer_cur_time_read(struct netc_timer *priv) { - u32 time_h, time_l; - u64 ns; - - /* The user should read NETC_TMR_CUR_TIME_L first to - * get correct current time. - */ - time_l = netc_timer_rd(priv, NETC_TMR_CUR_TIME_L); - time_h = netc_timer_rd(priv, NETC_TMR_CUR_TIME_H); - ns = (u64)time_h << 32 | time_l; - - return ns; + return netc_timer_rd64(priv, NETC_TMR_CUR_TIME_L); } static void netc_timer_alarm_write(struct netc_timer *priv, u64 alarm, int index) { - u32 alarm_h = upper_32_bits(alarm); - u32 alarm_l = lower_32_bits(alarm); - - netc_timer_wr(priv, NETC_TMR_ALARM_L(index), alarm_l); - netc_timer_wr(priv, NETC_TMR_ALARM_H(index), alarm_h); + netc_timer_wr64(priv, NETC_TMR_ALARM_L(index), alarm); } static u32 netc_timer_get_integral_period(struct netc_timer *priv) @@ -497,22 +470,19 @@ static void netc_timer_handle_etts_event(struct netc_timer *priv, int index, bool update_event) { struct ptp_clock_event event; - u32 etts_l = 0, etts_h = 0; + u64 etts = 0; - while (netc_timer_rd(priv, NETC_TMR_STAT) & TMR_STAT_ETS_VLD(index)) { - etts_l = netc_timer_rd(priv, NETC_TMR_ETTS_L(index)); - etts_h = netc_timer_rd(priv, NETC_TMR_ETTS_H(index)); - } + while (netc_timer_rd(priv, NETC_TMR_STAT) & TMR_STAT_ETS_VLD(index)) + etts = netc_timer_rd64(priv, NETC_TMR_ETTS_L(index)); /* Invalid time stamp */ - if (!etts_l && !etts_h) + if (!etts) return; if (update_event) { event.type = PTP_CLOCK_EXTTS; event.index = index; - event.timestamp = (u64)etts_h << 32; - event.timestamp |= etts_l; + event.timestamp = etts; ptp_clock_event(priv->clock, &event); } } -- 2.34.1