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 6/7] net: dsa: b53: Add logic for TX timestamping
Date: Fri, 5 Nov 2021 19:50:43 -0700 [thread overview]
Message-ID: <4f4e28f9-8d1e-f2e9-aa0c-37b2c4cd8e8a@gmail.com> (raw)
In-Reply-To: <20211104133204.19757-7-martin.kaistra@linutronix.de>
On 11/4/2021 6:32 AM, Martin Kaistra wrote:
> In order to get the switch to generate a timestamp for a transmitted
> packet, we need to set the TS bit in the BRCM tag. The switch will then
> create a status frame, which gets send back to the cpu.
> In b53_port_txtstamp() we put the skb into a waiting position.
>
> When a status frame is received, we extract the timestamp and put the time
> according to our timecounter into the waiting skb. When
> TX_TSTAMP_TIMEOUT is reached and we have no means to correctly get back
> a full timestamp, we cancel the process.
>
> As the status frame doesn't contain a reference to the original packet,
> only one packet with timestamp request can be sent at a time.
>
> Signed-off-by: Martin Kaistra <martin.kaistra@linutronix.de>
> ---
[snip]
> +static long b53_hwtstamp_work(struct ptp_clock_info *ptp)
> +{
> + struct b53_device *dev =
> + container_of(ptp, struct b53_device, ptp_clock_info);
> + struct dsa_switch *ds = dev->ds;
> + int i;
> +
> + for (i = 0; i < ds->num_ports; i++) {
> + struct b53_port_hwtstamp *ps;
> +
> + if (!dsa_is_user_port(ds, i))
> + continue;
Can you also check on !dsa_port_is_unused()?
[snip]
> #endif
> diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
> index 85dc47c22008..53cd0345df1b 100644
> --- a/net/dsa/tag_brcm.c
> +++ b/net/dsa/tag_brcm.c
> @@ -8,6 +8,7 @@
> #include <linux/dsa/brcm.h>
> #include <linux/etherdevice.h>
> #include <linux/list.h>
> +#include <linux/ptp_classify.h>
> #include <linux/slab.h>
> #include <linux/dsa/b53.h>
>
> @@ -85,9 +86,14 @@ static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
> unsigned int offset)
> {
> struct dsa_port *dp = dsa_slave_to_port(dev);
> + struct b53_device *b53_dev = dp->ds->priv;
> + unsigned int type = ptp_classify_raw(skb);
> u16 queue = skb_get_queue_mapping(skb);
> + struct b53_port_hwtstamp *ps;
> u8 *brcm_tag;
>
> + ps = &b53_dev->ports[dp->index].port_hwtstamp;
The dsa_port structure as a priv member which would be well suited to
store &b53_dev->ports[dp->index].port_hwtstamp and avoid traversing
multiple layers of objects here. You don't need to need b53_device at
all, and even if you did, you could easily add a back pointer to it in
port_hwstamp.
This applies below as well in brcm_tag_rcv_ll
[snip]
> +
> /* Frames with this tag have one of these two layouts:
> * -----------------------------------
> * | MAC DA | MAC SA | 4b tag | Type | DSA_TAG_PROTO_BRCM
> @@ -143,6 +181,9 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
> unsigned int offset,
> int *tag_len)
> {
> + struct b53_port_hwtstamp *ps;
> + struct b53_device *b53_dev;
> + struct dsa_port *dp;
> int source_port;
> u8 *brcm_tag;
> u32 tstamp;
> @@ -174,6 +215,16 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
> if (!skb->dev)
> return NULL;
>
> + /* Check whether this is a status frame */
> + if (*tag_len == 8 && brcm_tag[3] & 0x20) {
Can we have an unlikely() here, because this is unlikely to happen
except for switches that do support PTP, and we only have 53128 so far.
Also a define for this 0x20 would be nice, it is the timestamp bit for
the packet.
--
Florian
next prev parent reply other threads:[~2021-11-06 2:50 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
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 [this message]
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=4f4e28f9-8d1e-f2e9-aa0c-37b2c4cd8e8a@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).