All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Sergey Organov <sorganov@gmail.com>
Cc: richardcochran@gmail.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Fugang Duan <fugang.duan@nxp.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	andrew@lunn.ch
Subject: Re: [PATCH  1/5] net: fec: properly support external PTP PHY for hardware time stamping
Date: Mon, 6 Jul 2020 18:47:28 +0300	[thread overview]
Message-ID: <20200706154728.lfywhchrtaeeda4g@skbuf> (raw)
In-Reply-To: <87zh8cu0rs.fsf@osv.gnss.ru>

On Mon, Jul 06, 2020 at 06:21:59PM +0300, Sergey Organov wrote:
> Vladimir Oltean <olteanv@gmail.com> writes:
> 
> > Hi Sergey,
> >
> > On Mon, Jul 06, 2020 at 05:26:12PM +0300, Sergey Organov wrote:
> >> When external PTP-aware PHY is in use, it's that PHY that is to time
> >> stamp network packets, and it's that PHY where configuration requests
> >> of time stamping features are to be routed.
> >> 
> >> To achieve these goals:
> >> 
> >> 1. Make sure we don't time stamp packets when external PTP PHY is in use
> >> 
> >> 2. Make sure we redirect ioctl() related to time stamping of Ethernet
> >>    packets to connected PTP PHY rather than handle them ourselves
> 
> [...]
> 
> >> diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> >> index 2d0d313..995ea2e 100644
> >> --- a/drivers/net/ethernet/freescale/fec_main.c
> >> +++ b/drivers/net/ethernet/freescale/fec_main.c
> >> @@ -1298,7 +1298,11 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id)
> >>  			ndev->stats.tx_bytes += skb->len;
> >>  		}
> >>  
> >> +		/* It could be external PHY that had set SKBTX_IN_PROGRESS, so
> >> +		 * we still need to check it's we who are to time stamp
> >> +		 */
> >>  		if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) &&
> >> +		    unlikely(fep->hwts_tx_en) &&
> >
> > I think this could qualify as a pretty significant fix in its own right,
> > that should go to stable trees. Right now, this patch appears pretty
> > easy to overlook.
> >
> > Is this the same situation as what is being described here for the
> > gianfar driver?
> >
> > https://patchwork.ozlabs.org/project/netdev/patch/20191227004435.21692-2-olteanv@gmail.com/
> 
> Yes, it sounds exactly like that!
> 

Cool. Join the club! You were lucky though, in your case it was pretty
evident where the problem might be, so you were already on your way even
though you didn't know exactly what was going on.

Towards the point that you brought up in that thread:

> Could somebody please help me implement (or point me to) proper fix to
> reliably use external PHY to timestamp network packets?

We do it like this:
- DSA: If there is a timestamping switch stacked on top of a
  timestamping Ethernet MAC, the switch hijacks the .ndo_do_ioctl of the
  host port, and you are supposed to use the PTP clock of the switch,
  through the .ndo_do_ioctl of its own (virtual) net devices. This
  approach works without changing any code in each individual Ethernet
  MAC driver.
- PHY: The Ethernet MAC driver needs to be kind enough to check whether
  the PHY supports hw timestamping, and pass this ioctl to that PHY
  while making sure it doesn't do anything stupid in the meanwhile, like
  also acting upon that timestamping request itself.

Both are finicky in their own ways. There is no real way for the user to
select which PHC they want to use. The assumption is that you'd always
want to use the outermost one, and that things in the kernel side always
collaborate towards that end.

> However, I'd insist that the second part of the patch is as important.
> Please refer to my original post for the description of nasty confusion
> the second part of the patch fixes:
> 
> https://lore.kernel.org/netdev/87r1uqtybr.fsf@osv.gnss.ru/
> 
> Basically, you get PHY response when you ask for capabilities, but then
> MAC executes ioctl() request for corresponding configuration!
> 
> [...]
> 

Yup, sure, _but_ my point is: PHY timestamping is not supposed to work
unless you do that phy_has_hwtstamp dance in .ndo_do_ioctl and pass it
to the PHY driver. Whereas, timestamping on a DSA switch is supposed to
just work. So, the double-TX-timestamp fix is common for both DSA and
PHY timestamping, and it should be a separate patch that goes to David's
"net" tree and has an according Fixes: tag for the stable people to pick
it up. Then, the PHY timestamping patch is technically a new feature,
because the driver wasn't looking at the PHY's ability to perform PTP
timestamping, and now it does. So that part is a patch for "net-next".

> Thanks,
> -- Sergey

Thank you,
-Vladimir

  reply	other threads:[~2020-07-06 15:47 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 14:26 [PATCH 0/5] net: fec: fix external PTP PHY support Sergey Organov
2020-07-06 14:26 ` [PATCH 1/5] net: fec: properly support external PTP PHY for hardware time stamping Sergey Organov
2020-07-06 15:08   ` Vladimir Oltean
2020-07-06 15:21     ` Sergey Organov
2020-07-06 15:47       ` Vladimir Oltean [this message]
2020-07-06 18:33         ` Sergey Organov
2020-07-07  7:04           ` Vladimir Oltean
2020-07-07 15:29             ` Sergey Organov
2020-07-08 11:00             ` Richard Cochran
2020-07-08 10:55           ` Richard Cochran
2020-07-06 14:26 ` [PATCH 2/5] net: fec: enable to use PPS feature without " Sergey Organov
2020-07-07  4:05   ` [EXT] " Andy Duan
2020-07-07 14:29     ` Sergey Organov
2020-07-06 14:26 ` [PATCH 3/5] net: fec: initialize clock with 0 rather than current kernel time Sergey Organov
2020-07-06 15:27   ` Vladimir Oltean
2020-07-06 18:24     ` Sergey Organov
2020-07-07  6:36       ` Vladimir Oltean
2020-07-07 16:07         ` Sergey Organov
2020-07-07 16:43           ` Vladimir Oltean
2020-07-07 17:09             ` Sergey Organov
2020-07-07 17:12               ` Vladimir Oltean
2020-07-07 17:56                 ` Sergey Organov
2020-07-08 11:15                   ` Richard Cochran
2020-07-08 12:14                     ` Sergey Organov
2020-07-08 11:11             ` Richard Cochran
2020-07-08 11:04     ` Richard Cochran
2020-07-08 12:24       ` Sergey Organov
2020-07-08 12:37       ` Sergey Organov
2020-07-08 14:48         ` Richard Cochran
2020-07-08 17:18           ` Sergey Organov
2020-07-06 14:26 ` [PATCH 4/5] net: fec: get rid of redundant code in fec_ptp_set() Sergey Organov
2020-07-07  4:08   ` [EXT] " Andy Duan
2020-07-07 14:43     ` Sergey Organov
2020-07-08  5:34       ` Andy Duan
2020-07-08  8:48         ` Sergey Organov
2020-07-08  8:57           ` Andy Duan
2020-07-08 12:26             ` Sergey Organov
2020-07-06 14:26 ` [PATCH 5/5] net: fec: replace snprintf() with strlcpy() in fec_ptp_init() Sergey Organov
2020-07-11 12:08 ` [PATCH v2 net] net: fec: fix hardware time stamping by external devices Sergey Organov
2020-07-11 23:19   ` Vladimir Oltean
2020-07-12 14:16     ` Sergey Organov
2020-07-12 14:47       ` Andrew Lunn
2020-07-12 15:01       ` Vladimir Oltean
2020-07-12 17:29         ` Sergey Organov
2020-07-12 19:33           ` Vladimir Oltean
2020-07-12 22:32             ` Sergey Organov
2020-07-12 23:15               ` Vladimir Oltean
2020-07-14 12:39                 ` Sergey Organov
2020-07-14 14:23                   ` Vladimir Oltean
2020-07-14 14:35                     ` Sergey Organov
2020-07-14 14:44                     ` Vladimir Oltean
2020-07-14 16:18                       ` Sergey Organov
2020-07-14 14:01   ` Richard Cochran
2020-07-14 14:27     ` Sergey Organov
2020-07-14 16:28 ` [PATCH v3 " Sergey Organov
2020-07-16 18:24   ` Jakub Kicinski
2020-07-16 20:38     ` Sergey Organov
2020-07-16 21:06       ` Jakub Kicinski
2020-07-16 21:18         ` Sergey Organov
2020-07-15 15:42 ` [PATCH net-next v2 0/4] net: fec: a few improvements Sergey Organov
2020-07-15 15:42   ` [PATCH net-next v2 1/4] net: fec: enable to use PPS feature without time stamping Sergey Organov
2020-07-15 15:42   ` [PATCH net-next v2 2/4] net: fec: initialize clock with 0 rather than current kernel time Sergey Organov
2020-07-15 15:42   ` [PATCH net-next v2 3/4] net: fec: get rid of redundant code in fec_ptp_set() Sergey Organov
2020-07-15 15:43   ` [PATCH net-next v2 4/4] net: fec: replace snprintf() with strlcpy() in fec_ptp_init() Sergey Organov
2020-07-16  3:00   ` [EXT] [PATCH net-next v2 0/4] net: fec: a few improvements Andy Duan
2020-07-16 18:37     ` Jakub Kicinski

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=20200706154728.lfywhchrtaeeda4g@skbuf \
    --to=olteanv@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=fugang.duan@nxp.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=sorganov@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 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.