From: Florian Fainelli <f.fainelli@gmail.com>
To: Martin Kaistra <martin.kaistra@linutronix.de>,
Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>
Cc: Richard Cochran <richardcochran@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
John Stultz <john.stultz@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@kernel.org>,
Russell King <linux@armlinux.org.uk>,
Marc Kleine-Budde <mkl@pengutronix.de>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH 4/7] net: dsa: b53: Add PHC clock support
Date: Fri, 5 Nov 2021 19:32:53 -0700 [thread overview]
Message-ID: <666b195b-e7d7-6f1f-e09d-bfe113c2f4fe@gmail.com> (raw)
In-Reply-To: <20211104133204.19757-5-martin.kaistra@linutronix.de>
On 11/4/2021 6:31 AM, Martin Kaistra wrote:
> The BCM53128 switch has an internal clock, which can be used for
> timestamping. Add support for it.
>
> The 32-bit free running clock counts nanoseconds. In order to account
> for the wrap-around at 999999999 (0x3B9AC9FF) while using the cycle
> counter infrastructure, we need to set a 30bit mask and use the
> overflow_point property.
>
> Enable the Broadsync HD timestamping feature in b53_ptp_init() for PTPv2
> Ethertype (0x88f7).
>
> Signed-off-by: Martin Kaistra <martin.kaistra@linutronix.de>
> ---
[snip]
> +int b53_ptp_init(struct b53_device *dev)
> +{
> + mutex_init(&dev->ptp_mutex);
> +
> + INIT_DELAYED_WORK(&dev->overflow_work, b53_ptp_overflow_check);
> +
> + /* Enable BroadSync HD for all ports */
> + b53_write16(dev, B53_BROADSYNC_PAGE, B53_BROADSYNC_EN_CTRL1, 0x00ff);
Can you do this for all enabled user ports instead of each port, that
way it is clera that this register is supposed to be a bitmask of ports
for which you desire PTP timestamping to be enabled?
> +
> + /* Enable BroadSync HD Time Stamping Reporting (Egress) */
> + b53_write8(dev, B53_BROADSYNC_PAGE, B53_BROADSYNC_TS_REPORT_CTRL, 0x01);
Can you add a define for this bit in b53_regs.h and name it:
#define TSRPT_PKT_EN BIT(0)
which will enable timestamp reporting towards the IMP port.
> +
> + /* Enable BroadSync HD Time Stamping for PTPv2 ingress */
> +
> + /* MPORT_CTRL0 | MPORT0_TS_EN */
> + b53_write16(dev, B53_ARLCTRL_PAGE, 0x0e, (1 << 15) | 0x01);
Please add a definition for 0x0e which is the multi-port control
register and is 16-bit wide.
Bit 15 is MPORT0_TS_EN and it will ensure that packets matching
multiport 0 (address or ethertype) will be timestamped.
and then add a macro or generic definitions that are applicable to all
multiport control registers, something like:
#define MPORT_CTRL_DIS_FORWARD 0
#define MPORT_CTRL_CMP_ADDR 1
#define MPORT_CTRL_CMP_ETYPE 2
#define MPORT_CTRL_CMP_ADDR_ETYPE 3
#define MPORT_CTRL_SHIFT(x) ((x) << 2)
#define MPORT_CTRL_MASK 0x3
> + /* Forward to IMP port 8 */
> + b53_write64(dev, B53_ARLCTRL_PAGE, 0x18, (1 << 8));
0x18 is the multiport vector N register so we would want a macro to
define the multiprot vector being used (up to 6 of them), and this is a
32-bit register, not a 64-bit register. The 8 here should be checked
against the actual CPU port index number, it is 8 for you, it could be 5
for someone else, or 7, even.
> + /* PTPv2 Ether Type */
> + b53_write64(dev, B53_ARLCTRL_PAGE, 0x10, (u64)0x88f7 << 48);
Use ETH_P_1588 here and 0x10 deserves a define which is the multiport
address N register. Likewise, we need a base offset of 0x10 and then a
macro to address the 6 multiports that exists.
> +
> + /* Setup PTP clock */
> + dev->ptp_clock_info.owner = THIS_MODULE;
> + snprintf(dev->ptp_clock_info.name, sizeof(dev->ptp_clock_info.name),
> + dev_name(dev->dev));
> +
> + dev->ptp_clock_info.max_adj = 1000000000ULL;
> + dev->ptp_clock_info.n_alarm = 0;
> + dev->ptp_clock_info.n_pins = 0;
> + dev->ptp_clock_info.n_ext_ts = 0;
> + dev->ptp_clock_info.n_per_out = 0;
> + dev->ptp_clock_info.pps = 0;
memset the structure ahead of time so you only need explicit
initialization where needed?
> + dev->ptp_clock_info.adjfine = b53_ptp_adjfine;
> + dev->ptp_clock_info.adjtime = b53_ptp_adjtime;
> + dev->ptp_clock_info.gettime64 = b53_ptp_gettime;
> + dev->ptp_clock_info.settime64 = b53_ptp_settime;
> + dev->ptp_clock_info.enable = b53_ptp_enable;
> +
> + dev->ptp_clock = ptp_clock_register(&dev->ptp_clock_info, dev->dev);
> + if (IS_ERR(dev->ptp_clock))
> + return PTR_ERR(dev->ptp_clock);
> +
> + /* The switch provides a 32 bit free running counter. Use the Linux
> + * cycle counter infrastructure which is suited for such scenarios.
> + */
> + dev->cc.read = b53_ptp_read;
> + dev->cc.mask = CYCLECOUNTER_MASK(30);
> + dev->cc.overflow_point = 999999999;
> + dev->cc.mult = (1 << 28);
> + dev->cc.shift = 28;
> +
> + b53_write32(dev, B53_BROADSYNC_PAGE, B53_BROADSYNC_TIMEBASE_ADJ1, 40);
You are writing the default value of the register, is that of any use?
--
Florian
next prev parent reply other threads:[~2021-11-06 2:33 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 13:31 [PATCH 0/7] Add PTP support for BCM53128 switch Martin Kaistra
2021-11-04 13:31 ` [PATCH 1/7] net: dsa: b53: Add BroadSync HD register definitions Martin Kaistra
2021-11-06 2:29 ` Florian Fainelli
2021-11-04 13:31 ` [PATCH 2/7] net: dsa: b53: Move struct b53_device to include/linux/dsa/b53.h Martin Kaistra
2021-11-04 13:31 ` [PATCH 3/7] timecounter: allow for non-power of two overflow Martin Kaistra
2021-11-04 13:31 ` [PATCH 4/7] net: dsa: b53: Add PHC clock support Martin Kaistra
2021-11-04 17:28 ` Richard Cochran
2021-11-04 17:49 ` Richard Cochran
2021-11-06 2:32 ` Florian Fainelli [this message]
2021-11-08 15:00 ` Martin Kaistra
2021-11-04 13:31 ` [PATCH 5/7] net: dsa: b53: Add logic for RX timestamping Martin Kaistra
2021-11-06 2:36 ` Florian Fainelli
2021-11-04 13:32 ` [PATCH 6/7] net: dsa: b53: Add logic for TX timestamping Martin Kaistra
2021-11-06 2:50 ` Florian Fainelli
2021-11-08 9:57 ` Martin Kaistra
2021-11-04 13:32 ` [PATCH 7/7] net: dsa: b53: Expose PTP timestamping ioctls to userspace Martin Kaistra
2021-11-04 17:42 ` Richard Cochran
2021-11-05 13:38 ` Martin Kaistra
2021-11-05 14:13 ` Richard Cochran
2021-11-05 14:14 ` Richard Cochran
2021-11-05 14:28 ` Vladimir Oltean
2021-11-05 15:09 ` Jakub Kicinski
2021-11-05 17:25 ` Vladimir Oltean
2021-11-06 0:18 ` Richard Cochran
2021-11-06 0:36 ` Vladimir Oltean
2021-11-07 14:05 ` Richard Cochran
2021-11-07 14:27 ` Vladimir Oltean
2021-11-08 14:48 ` Richard Cochran
2021-11-25 17:05 ` Vladimir Oltean
2021-11-26 8:42 ` Kurt Kanzenbach
2021-11-26 16:31 ` Richard Cochran
2021-11-26 16:42 ` Vladimir Oltean
2021-11-26 17:03 ` Richard Cochran
2021-11-26 17:18 ` Vladimir Oltean
2021-11-04 17:29 ` [PATCH 0/7] Add PTP support for BCM53128 switch Jakub Kicinski
2021-11-05 13:08 ` Martin Kaistra
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=666b195b-e7d7-6f1f-e09d-bfe113c2f4fe@gmail.com \
--to=f.fainelli@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=john.stultz@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=martin.kaistra@linutronix.de \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=richardcochran@gmail.com \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=vivien.didelot@gmail.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).