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, linusw@kernel.org,
linux@armlinux.org.uk
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 v4 net-next 1/8] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access
Date: Fri, 18 Sep 2026 15:28:45 +0800 [thread overview]
Message-ID: <20260918072852.501420-2-wei.fang@oss.nxp.com> (raw)
In-Reply-To: <20260918072852.501420-1-wei.fang@oss.nxp.com>
From: Wei Fang <wei.fang@nxp.com>
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 <wei.fang@nxp.com>
---
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 19ca99d80e95..376b3b0d1a38 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)
@@ -500,22 +473,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
next prev parent reply other threads:[~2026-09-18 7:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 7:28 [PATCH v4 net-next 0/8] net: dsa: netc: add PTP support for NETC switch wei.fang
2026-09-18 7:28 ` wei.fang [this message]
2026-09-30 13:26 ` [PATCH v4 net-next 1/8] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access Linus Walleij
2026-09-18 7:28 ` [PATCH v4 net-next 2/8] ptp: netc: remove unnecessary pcie_flr() call in probe wei.fang
2026-09-18 7:28 ` [PATCH v4 net-next 3/8] ptp: netc: export netc_timer_get_current_time() for cross-driver use wei.fang
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-22 9:48 ` Wei Fang
2026-09-18 7:28 ` [PATCH v4 net-next 4/8] net: dsa: netc: use entry ID instead of pointer to track host flood rule wei.fang
2026-09-18 7:28 ` [PATCH v4 net-next 5/8] net: dsa: netc: check return value of ntmp_ipft_delete_entry() wei.fang
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-22 10:34 ` Wei Fang
2026-09-18 7:28 ` [PATCH v4 net-next 6/8] net: dsa: netc: enable ingress port filtering lookup by default wei.fang
2026-09-18 7:28 ` [PATCH v4 net-next 7/8] net: dsa: netc: add PTP two-step timestamping support wei.fang
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-23 2:43 ` Wei Fang
2026-09-18 7:28 ` [PATCH v4 net-next 8/8] net: dsa: netc: add PTP one-step " wei.fang
2026-09-19 7:26 ` sashiko-bot
2026-09-21 2:31 ` Wei Fang (OSS)
2026-09-22 8:25 ` netdev-bot+sashiko
2026-09-23 6:11 ` Wei Fang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260918072852.501420-2-wei.fang@oss.nxp.com \
--to=wei.fang@oss.nxp.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.