All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antoine Tenart <antoine.tenart@bootlin.com>
To: Richard Cochran <richardcochran@gmail.com>
Cc: davem@davemloft.net, andrew@lunn.ch, f.fainelli@gmail.com,
	hkallweit1@gmail.com, alexandre.belloni@bootlin.com,
	UNGLinuxDriver@microchip.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com,
	allan.nielsen@microchip.com, foss@0leil.net
Subject: Re: [PATCH net-next 6/8] net: phy: mscc: timestamping and PHC support
Date: Thu, 28 May 2020 17:23:52 +0200	[thread overview]
Message-ID: <159067943270.870467.1676119924358159280@kwain> (raw)
In-Reply-To: <20200528143440.GB14844@localhost>

Hello Richard,

Quoting Richard Cochran (2020-05-28 16:34:40)
> On Wed, May 27, 2020 at 06:41:56PM +0200, Antoine Tenart wrote:
> 
> > +static struct vsc85xx_ptphdr *get_ptp_header(struct sk_buff *skb)
> > +{
> > +     struct ethhdr *ethhdr = eth_hdr(skb);
> > +     struct iphdr *iphdr = ip_hdr(skb);
> > +     struct udphdr *udphdr;
> > +     __u8 proto;
> > +
> > +     if (ethhdr->h_proto == htons(ETH_P_1588))
> > +             return (struct vsc85xx_ptphdr *)(((unsigned char *)ethhdr) +
> > +                                      skb_mac_header_len(skb));
> > +
> > +     if (ethhdr->h_proto != htons(ETH_P_IP))
> > +             return NULL;
> > +
> > +     proto = iphdr->protocol;
> > +     if (proto != IPPROTO_UDP)
> > +             return NULL;
> > +
> > +     udphdr = udp_hdr(skb);
> > +
> > +     if (udphdr->source != ntohs(PTP_EV_PORT) ||
> > +         udphdr->dest != ntohs(PTP_EV_PORT))
> > +             return NULL;
> > +
> > +     return (struct vsc85xx_ptphdr *)(((unsigned char *)udphdr) + UDP_HLEN);
> > +}
> 
> This looks a lot like get_ptp_header_rx() below.  Are you sure you
> need two almost identical methods?

That's right, good catch. I'll look into merging the two.

> > +static void vsc85xx_get_tx_ts(struct vsc85xx_ptp *ptp)
> > +{
> > +     struct skb_shared_hwtstamps shhwtstamps;
> > +     struct sk_buff *skb, *first_skb = NULL;
> > +     struct vsc85xx_ts_fifo fifo;
> > +     u8 i, skb_sig[16], *p;
> > +     unsigned long ns;
> > +     s64 secs;
> > +     u32 reg;
> > +
> > +next_in_fifo:
> > +     memset(&fifo, 0, sizeof(fifo));
> > +     p = (u8 *)&fifo;
> > +
> > +     reg = vsc85xx_ts_read_csr(ptp->phydev, PROCESSOR,
> > +                               MSCC_PHY_PTP_EGR_TS_FIFO(0));
> > +     if (reg & PTP_EGR_TS_FIFO_EMPTY)
> > +             goto out;
> > +
> > +     *p++ = reg & 0xff;
> > +     *p++ = (reg >> 8) & 0xff;
> > +
> > +     /* Reading FIFO6 pops the FIFO item */
> > +     for (i = 1; i < 7; i++) {
> > +             reg = vsc85xx_ts_read_csr(ptp->phydev, PROCESSOR,
> > +                                       MSCC_PHY_PTP_EGR_TS_FIFO(i));
> > +             *p++ = reg & 0xff;
> > +             *p++ = (reg >> 8) & 0xff;
> > +             *p++ = (reg >> 16) & 0xff;
> > +             *p++ = (reg >> 24) & 0xff;
> > +     }
> > +
> > +next_in_queue:
> > +     skb = skb_dequeue(&ptp->tx_queue);
> > +     if (!skb || skb == first_skb)
> > +             goto out;
> > +
> > +     /* Keep the first skb to avoid looping over it again. */
> > +     if (!first_skb)
> > +             first_skb = skb;
> > +
> > +     /* Can't get the signature of the packet, won't ever
> > +      * be able to have one so let's dequeue the packet.
> > +      */
> > +     if (get_sig(skb, skb_sig) < 0)
> > +             goto next_in_queue;
> > +
> > +     /* Valid signature but does not match the one of the
> > +      * packet in the FIFO right now, reschedule it for later
> > +      * packets.
> > +      */
> > +     if (memcmp(skb_sig, fifo.sig, sizeof(fifo.sig))) {
> > +             skb_queue_tail(&ptp->tx_queue, skb);
> > +             goto next_in_queue;
> > +     }
> > +
> > +     ns = fifo.ns;
> > +     secs = fifo.secs;
> > +
> > +     memset(&shhwtstamps, 0, sizeof(shhwtstamps));
> > +     shhwtstamps.hwtstamp = ktime_set(secs, ns);
> > +     skb_complete_tx_timestamp(skb, &shhwtstamps);
> > +
> > +out:
> > +     /* If other timestamps are available in the FIFO, process them. */
> > +     reg = vsc85xx_ts_read_csr(ptp->phydev, PROCESSOR,
> > +                               MSCC_PHY_PTP_EGR_TS_FIFO_CTRL);
> > +     if (PTP_EGR_FIFO_LEVEL_LAST_READ(reg) > 1)
> > +             goto next_in_fifo;
> > +}
> 
> AFAICT, there is no need for labels and jumps here.  Two nested 'for'
> loops will do nicely.  The inner skb loop can be in a helper function
> for clarity.  Be sure to use the "safe" iterator over the skbs.

Using helper functions for clarity, I could move to using loops. I'll
try that and if it improves readability I'll change this for v2.

> > +static void vsc85xx_txtstamp(struct mii_timestamper *mii_ts,
> > +                          struct sk_buff *skb, int type)
> > +{
> > +     struct vsc8531_private *vsc8531 =
> > +             container_of(mii_ts, struct vsc8531_private, mii_ts);
> > +
> > +     if (!skb || !vsc8531->ptp->configured)
> 
> The skb cannot be NULL here.  See net/core/timestamping.c
> 
> > +             return;
> > +
> > +     if (vsc8531->ptp->tx_type == HWTSTAMP_TX_OFF) {
> > +             kfree_skb(skb);
> > +             return;
> > +     }
> > +
> > +     skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
> > +     skb_queue_tail(&vsc8531->ptp->tx_queue, skb);
> > +     /* Scheduling the work for the TS FIFO is handled by the IRQ routine */
> > +}
> > +
> > +static bool vsc85xx_rxtstamp(struct mii_timestamper *mii_ts,
> > +                          struct sk_buff *skb, int type)
> > +{
> > +     struct vsc8531_private *vsc8531 =
> > +             container_of(mii_ts, struct vsc8531_private, mii_ts);
> > +     struct skb_shared_hwtstamps *shhwtstamps = NULL;
> > +     struct vsc85xx_ptphdr *ptphdr;
> > +     struct timespec64 ts;
> > +     unsigned long ns;
> > +
> > +     if (!skb || !vsc8531->ptp->configured)
> 
> Again, skb can't be null.

Right, I'll fix the two.

Thanks for the review!
Antoine

-- 
Antoine Ténart, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2020-05-28 15:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-27 16:41 [PATCH net-next 0/8] net: phy: mscc: PHC and timestamping support Antoine Tenart
2020-05-27 16:41 ` [PATCH net-next 1/8] net: phy: add support for a common probe between shared PHYs Antoine Tenart
2020-05-27 16:41 ` [PATCH net-next 2/8] net: phy: mscc: fix copyright and author information in MACsec Antoine Tenart
2020-05-27 16:41 ` [PATCH net-next 3/8] net: phy: mscc: remove the TR CLK disable magic value Antoine Tenart
2020-05-27 16:41 ` [PATCH net-next 4/8] net: phy: mscc: take into account the 1588 block in MACsec init Antoine Tenart
2020-05-27 16:41 ` [PATCH net-next 5/8] net: phy: mscc: 1588 block initialization Antoine Tenart
2020-05-27 17:35   ` Jakub Kicinski
2020-05-28  6:57     ` Antoine Tenart
2020-05-27 22:04   ` kbuild test robot
2020-05-27 22:04     ` kbuild test robot
2020-05-27 16:41 ` [PATCH net-next 6/8] net: phy: mscc: timestamping and PHC support Antoine Tenart
2020-05-28 14:34   ` Richard Cochran
2020-05-28 15:23     ` Antoine Tenart [this message]
2020-05-27 16:41 ` [PATCH net-next 7/8] dt-bindings: net: phy: vsc8531: document the load/save GPIO Antoine Tenart
2020-05-27 16:41 ` [PATCH net-next 8/8] MIPS: dts: ocelot: describe " Antoine Tenart

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=159067943270.870467.1676119924358159280@kwain \
    --to=antoine.tenart@bootlin.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=allan.nielsen@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=foss@0leil.net \
    --cc=hkallweit1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=thomas.petazzoni@bootlin.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.