From: Simon Horman <horms@kernel.org>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: Paul Barker <paul@pbarker.dev>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Magnus Damm <magnus.damm@gmail.com>,
Richard Cochran <richardcochran@gmail.com>,
netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [net-next,v2 7/7] net: ravb: Use common defines for time stamping control
Date: Fri, 7 Nov 2025 17:50:02 +0000 [thread overview]
Message-ID: <aQ4xSv9629XF-Bt3@horms.kernel.org> (raw)
In-Reply-To: <20251104222420.882731-8-niklas.soderlund+renesas@ragnatech.se>
On Tue, Nov 04, 2025 at 11:24:20PM +0100, Niklas Söderlund wrote:
> Instead of translating to/from driver specific flags for packet time
> stamp control use the common flags directly. This simplifies the driver
> as the translating code can be removed while at the same time making it
> clear the flags are not flags written to hardware registers.
>
> The change from a device specific bit-field track variable to the common
> enum datatypes forces us to touch the ravb_rx_rcar_hwstamp() in a non
> trivial way. To make this cleaner and easier to understand expand the
> nested conditions.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
...
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index 5477bb5c69ae..1680e94b9242 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -950,13 +950,14 @@ static void ravb_rx_rcar_hwstamp(struct ravb_private *priv, int q,
> struct ravb_ex_rx_desc *desc,
> struct sk_buff *skb)
> {
> - u32 get_ts = priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE;
> struct skb_shared_hwtstamps *shhwtstamps;
> struct timespec64 ts;
> + bool get_ts;
>
> - get_ts &= (q == RAVB_NC) ?
> - RAVB_RXTSTAMP_TYPE_V2_L2_EVENT :
> - ~RAVB_RXTSTAMP_TYPE_V2_L2_EVENT;
> + if (q == RAVB_NC)
> + get_ts = priv->tstamp_rx_ctrl == HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
> + else
> + get_ts = priv->tstamp_rx_ctrl != HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
>
> if (!get_ts)
> return;
Hi Niklas,
It is Friday evening and I'm exercising a new tool, so please forgive me if
this analysis is wrong. But it seems that there are cases where there old
bit-based logic and the new integer equality based logic don't match.
1. If q == RAVB_NC then previously timestamping would occur
for HWTSTAMP_FILTER_ALL, because:
(RAVB_TXTSTAMP_ENABLED | RAVB_RXTSTAMP_TYPE_ALL) &
RAVB_RXTSTAMP_TYPE & RAVB_RXTSTAMP_TYPE_V2_L2_EVENT =
(0x10 | 0x6) & 0x06 & 0x02 = 0x2, which is non-zero.
But with the new logic timestamping does not occur because:
HWTSTAMP_FILTER_ALL == HWTSTAMP_FILTER_PTP_V2_L2_EVENT is false
2. If q != RAVB_NC then previously timestamping would not occur
for HWTSTAMP_FILTER_NONE because:
0 & RAVB_RXTSTAMP_TYPE & RAVB_RXTSTAMP_TYPE_V2_L2_EVENT = 0
But with the new logic timestamping does occur because:
HWTSTAMP_FILTER_NONE != HWTSTAMP_FILTER_PTP_V2_L2_EVENT is true
I came across this by chance because this patch is currently
the most recent patch in net-next that touches C code. And I was
exercising Claude Code with https://github.com/masoncl/review-prompts
It reported the above and after significantly
more thinking I've come to agree with it.
But it is Friday evening, so YMMV.
For reference, I've provided the text generated by Claude Code at the end of
this email.
...
> @@ -2446,15 +2437,13 @@ static int ravb_hwtstamp_set(struct net_device *ndev,
> struct netlink_ext_ack *extack)
> {
> struct ravb_private *priv = netdev_priv(ndev);
> - u32 tstamp_rx_ctrl = RAVB_RXTSTAMP_ENABLED;
> - u32 tstamp_tx_ctrl;
> + enum hwtstamp_rx_filters tstamp_rx_ctrl;
> + enum hwtstamp_tx_types tstamp_tx_ctrl;
>
> switch (config->tx_type) {
> case HWTSTAMP_TX_OFF:
> - tstamp_tx_ctrl = 0;
> - break;
> case HWTSTAMP_TX_ON:
> - tstamp_tx_ctrl = RAVB_TXTSTAMP_ENABLED;
> + tstamp_tx_ctrl = config->tx_type;
> break;
> default:
> return -ERANGE;
> @@ -2462,14 +2451,12 @@ static int ravb_hwtstamp_set(struct net_device *ndev,
>
> switch (config->rx_filter) {
> case HWTSTAMP_FILTER_NONE:
> - tstamp_rx_ctrl = 0;
> - break;
> case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
> - tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_V2_L2_EVENT;
> + tstamp_rx_ctrl = config->rx_filter;
> break;
> default:
> config->rx_filter = HWTSTAMP_FILTER_ALL;
> - tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_ALL;
> + tstamp_rx_ctrl = HWTSTAMP_FILTER_ALL;
> }
>
> priv->tstamp_tx_ctrl = tstamp_tx_ctrl;
> --
> 2.51.1
>
>
Text generated by Claude Code:
Is this logic translation correct? Looking at the old bit-field
operations and new enum comparisons, the behavior seems to change in
two cases:
Old behavior (from ravb_hwtstamp_set):
- FILTER_NONE stored as 0
- FILTER_PTP_V2_L2_EVENT stored as 0x12 (ENABLED | TYPE_V2_L2)
- FILTER_ALL stored as 0x16 (ENABLED | TYPE_ALL)
Old ravb_rx_rcar_hwstamp for RAVB_NC queue:
get_ts = (0x12 & 0x06) & 0x02 = 0x02 & 0x02 = 0x02 (timestamp)
get_ts = (0x16 & 0x06) & 0x02 = 0x06 & 0x02 = 0x02 (timestamp)
So the old code timestamps RAVB_NC queue packets for both
FILTER_PTP_V2_L2_EVENT and FILTER_ALL.
New ravb_rx_rcar_hwstamp for RAVB_NC queue with FILTER_ALL:
get_ts = (HWTSTAMP_FILTER_ALL == HWTSTAMP_FILTER_PTP_V2_L2_EVENT)
get_ts = (1 == 9) = false (no timestamp)
Similarly for non-RAVB_NC queue, old behavior with FILTER_NONE:
get_ts = (0 & 0x06) & ~0x02 = 0 & ~0x02 = 0 (no timestamp)
New behavior for non-RAVB_NC queue with FILTER_NONE:
get_ts = (HWTSTAMP_FILTER_NONE != HWTSTAMP_FILTER_PTP_V2_L2_EVENT)
get_ts = (0 != 9) = true (timestamp)
Can the refactoring introduce these two behavior changes?
1. RAVB_NC queue with FILTER_ALL: old code timestamps, new code doesn't
2. Non-RAVB_NC queue with FILTER_NONE: old code doesn't timestamp, new
code does
next prev parent reply other threads:[~2025-11-07 17:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 22:24 [net-next,v2 0/7] net: renesas: Cleanup usage of gPTP flags Niklas Söderlund
2025-11-04 22:24 ` [net-next,v2 1/7] net: rswitch: Move definition of S4 gPTP offset Niklas Söderlund
2025-11-04 22:24 ` [net-next,v2 2/7] net: rcar_gen4_ptp: Move control fields to users Niklas Söderlund
2025-11-04 22:24 ` [net-next,v2 3/7] net: rswitch: Use common defines for time stamping control Niklas Söderlund
2025-11-04 22:24 ` [net-next,v2 4/7] net: rtsn: " Niklas Söderlund
2025-11-04 22:24 ` [net-next,v2 5/7] net: rcar_gen4_ptp: Remove unused defines Niklas Söderlund
2025-11-04 22:24 ` [net-next,v2 6/7] net: ravb: Break out Rx hardware timestamping Niklas Söderlund
2025-11-04 22:24 ` [net-next,v2 7/7] net: ravb: Use common defines for time stamping control Niklas Söderlund
2025-11-07 17:50 ` Simon Horman [this message]
2025-11-07 19:10 ` Niklas Söderlund
2025-11-07 1:50 ` [net-next,v2 0/7] net: renesas: Cleanup usage of gPTP flags patchwork-bot+netdevbpf
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=aQ4xSv9629XF-Bt3@horms.kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=geert+renesas@glider.be \
--cc=kuba@kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=pabeni@redhat.com \
--cc=paul@pbarker.dev \
--cc=richardcochran@gmail.com \
--cc=yoshihiro.shimoda.uh@renesas.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).