From: Richard Cochran <richardcochran@gmail.com>
To: Jiawen Wu <jiawenwu@trustnetic.com>
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk,
horms@kernel.org, jacob.e.keller@intel.com,
netdev@vger.kernel.org, vadim.fedorenko@linux.dev,
mengyuanlou@net-swift.com
Subject: Re: [PATCH net-next v3 4/4] net: ngbe: Add support for 1PPS and TOD
Date: Sat, 11 Jan 2025 09:18:48 -0800 [thread overview]
Message-ID: <Z4Kn-OtfLdScC38H@hoboy.vegasvil.org> (raw)
In-Reply-To: <20250110031716.2120642-5-jiawenwu@trustnetic.com>
On Fri, Jan 10, 2025 at 11:17:16AM +0800, Jiawen Wu wrote:
This code...
> +static void wx_ptp_setup_sdp(struct wx *wx)
> +{
...
> + /* disable the pin first */
> + wr32ptp(wx, WX_TSC_1588_AUX_CTL, 0);
> + WX_WRITE_FLUSH(wx);
> +
> + if (!test_bit(WX_FLAG_PTP_PPS_ENABLED, wx->flags)) {
> + if (wx->pps_enabled) {
> + wx->pps_enabled = false;
> + wx_set_pps(wx, false, 0, 0);
> + }
> + return;
> + }
> +
> + wx->pps_enabled = true;
> +
> + tssdp = WX_TSC_1588_SDP_FUN_SEL_TT0;
> + tssdp |= WX_TSC_1588_SDP_OUT_LEVEL_H;
> + tssdp1 = WX_TSC_1588_SDP_FUN_SEL_TS0;
> + tsauxc = WX_TSC_1588_AUX_CTL_PLSG | WX_TSC_1588_AUX_CTL_EN_TT0 |
> + WX_TSC_1588_AUX_CTL_EN_TT1 | WX_TSC_1588_AUX_CTL_EN_TS0;
> +
> + /* Read the current clock time, and save the cycle counter value */
> + spin_lock_irqsave(&wx->tmreg_lock, flags);
> + ns = timecounter_read(&wx->hw_tc);
> + wx->pps_edge_start = wx->hw_tc.cycle_last;
> + spin_unlock_irqrestore(&wx->tmreg_lock, flags);
> + wx->pps_edge_end = wx->pps_edge_start;
> +
> + /* Figure out how far past the next second we are */
> + div_u64_rem(ns, WX_NS_PER_SEC, &rem);
> +
> + /* Figure out how many nanoseconds to add to round the clock edge up
> + * to the next full second
> + */
> + rem = (WX_NS_PER_SEC - rem);
> +
> + /* Adjust the clock edge to align with the next full second. */
> + wx->pps_edge_start += div_u64(((u64)rem << cc->shift), cc->mult);
> + trgttiml0 = (u32)wx->pps_edge_start;
> + trgttimh0 = (u32)(wx->pps_edge_start >> 32);
> +
> + wx_set_pps(wx, wx->pps_enabled, ns + rem, wx->pps_edge_start);
> +
> + rem += wx->pps_width;
> + wx->pps_edge_end += div_u64(((u64)rem << cc->shift), cc->mult);
> + trgttiml1 = (u32)wx->pps_edge_end;
> + trgttimh1 = (u32)(wx->pps_edge_end >> 32);
> +
> + wr32ptp(wx, WX_TSC_1588_TRGT_L(0), trgttiml0);
> + wr32ptp(wx, WX_TSC_1588_TRGT_H(0), trgttimh0);
> + wr32ptp(wx, WX_TSC_1588_TRGT_L(1), trgttiml1);
> + wr32ptp(wx, WX_TSC_1588_TRGT_H(1), trgttimh1);
> + wr32ptp(wx, WX_TSC_1588_SDP(0), tssdp);
> + wr32ptp(wx, WX_TSC_1588_SDP(1), tssdp1);
> + wr32ptp(wx, WX_TSC_1588_AUX_CTL, tsauxc);
> + wr32ptp(wx, WX_TSC_1588_INT_EN, WX_TSC_1588_INT_EN_TT1);
> + WX_WRITE_FLUSH(wx);
> +
> + rem = WX_NS_PER_SEC;
> + /* Adjust the clock edge to align with the next full second. */
> + wx->sec_to_cc = div_u64(((u64)rem << cc->shift), cc->mult);
> +}
Looks almost identical this code ...
> +void wx_ptp_check_pps_event(struct wx *wx)
> +{
...
> + if (int_status & WX_TSC_1588_INT_ST_TT1) {
> + /* disable the pin first */
> + wr32ptp(wx, WX_TSC_1588_AUX_CTL, 0);
> + WX_WRITE_FLUSH(wx);
> +
> + tsauxc = WX_TSC_1588_AUX_CTL_PLSG | WX_TSC_1588_AUX_CTL_EN_TT0 |
> + WX_TSC_1588_AUX_CTL_EN_TT1 | WX_TSC_1588_AUX_CTL_EN_TS0;
> +
> + /* Read the current clock time, and save the cycle counter value */
> + spin_lock_irqsave(&wx->tmreg_lock, flags);
> + ns = timecounter_read(&wx->hw_tc);
> + wx->pps_edge_start = wx->hw_tc.cycle_last;
> + spin_unlock_irqrestore(&wx->tmreg_lock, flags);
> + wx->pps_edge_end = wx->pps_edge_start;
> +
> + /* Figure out how far past the next second we are */
> + div_u64_rem(ns, WX_NS_PER_SEC, &rem);
> +
> + /* Figure out how many nanoseconds to add to round the clock edge up
> + * to the next full second
> + */
> + rem = (WX_NS_PER_SEC - rem);
> +
> + /* Adjust the clock edge to align with the next full second. */
> + wx->pps_edge_start += div_u64(((u64)rem << cc->shift), cc->mult);
> + trgttiml0 = (u32)wx->pps_edge_start;
> + trgttimh0 = (u32)(wx->pps_edge_start >> 32);
> +
> + rem += wx->pps_width;
> + wx->pps_edge_end += div_u64(((u64)rem << cc->shift), cc->mult);
> + trgttiml1 = (u32)wx->pps_edge_end;
> + trgttimh1 = (u32)(wx->pps_edge_end >> 32);
> +
> + wr32ptp(wx, WX_TSC_1588_TRGT_L(0), trgttiml0);
> + wr32ptp(wx, WX_TSC_1588_TRGT_H(0), trgttimh0);
> + wr32ptp(wx, WX_TSC_1588_TRGT_L(1), trgttiml1);
> + wr32ptp(wx, WX_TSC_1588_TRGT_H(1), trgttimh1);
> + wr32ptp(wx, WX_TSC_1588_AUX_CTL, tsauxc);
> + WX_WRITE_FLUSH(wx);
> + }
> +}
So can the trigger calculation logic be refactored into one place?
Thanks,
Richard
prev parent reply other threads:[~2025-01-11 17:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 3:17 [PATCH net-next v3 0/4] Support PTP clock for Wangxun NICs Jiawen Wu
2025-01-10 3:17 ` [PATCH net-next v3 1/4] net: wangxun: Add support for PTP clock Jiawen Wu
2025-01-10 13:35 ` Vadim Fedorenko
2025-01-13 7:16 ` Jiawen Wu
2025-01-13 10:38 ` Vadim Fedorenko
2025-01-10 3:17 ` [PATCH net-next v3 2/4] net: wangxun: Support to get ts info Jiawen Wu
2025-01-10 3:17 ` [PATCH net-next v3 3/4] net: wangxun: Implement do_aux_work of ptp_clock_info Jiawen Wu
2025-01-10 13:42 ` Vadim Fedorenko
2025-01-10 3:17 ` [PATCH net-next v3 4/4] net: ngbe: Add support for 1PPS and TOD Jiawen Wu
2025-01-11 16:42 ` Richard Cochran
2025-01-11 16:56 ` Richard Cochran
2025-01-11 17:15 ` Richard Cochran
2025-01-13 6:30 ` Jiawen Wu
2025-01-14 16:21 ` Richard Cochran
2025-01-11 17:18 ` Richard Cochran [this message]
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=Z4Kn-OtfLdScC38H@hoboy.vegasvil.org \
--to=richardcochran@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jiawenwu@trustnetic.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mengyuanlou@net-swift.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vadim.fedorenko@linux.dev \
/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).