netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yangbo Lu <yangbo.lu@nxp.com>
To: netdev@vger.kernel.org
Cc: Yangbo Lu <yangbo.lu@nxp.com>,
	"David S . Miller" <davem@davemloft.net>,
	Richard Cochran <richardcochran@gmail.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Jakub Kicinski <kuba@kernel.org>
Subject: [net-next, v2, 0/7] ptp: support virtual clocks for multiple
Date: Fri, 21 May 2021 12:36:12 +0800	[thread overview]
Message-ID: <20210521043619.44694-1-yangbo.lu@nxp.com> (raw)

Current PTP driver exposes one PTP device to user which binds network
interface/interfaces to provide timestamping. Actually we have a way
utilizing timecounter/cyclecounter to virtualize any number of PTP
clocks based on a same free running physical clock for using.
The purpose of having multiple PTP virtual clocks is for user space
to directly/easily use them for multiple domains synchronization.

               +------------------------------+
MAC driver:    |      rx/tx PTP packet        |
               +------------------------------+
                               ^
                               | Match vclock via domain value
                               | Convert HW timestamp to domain time
                               v
         +--------------+--------------+--------------+
vclock:  | ptp1 domain1 | ptp2 domain2 | ptpN domainN |
         +--------------+--------------+--------------+
pclock:  |             ptp0 free running              |
         +--------------------------------------------+

The block diagram may explain how it works. Besides the PTP virtual
clocks, the PTP packet HW timestamp converting to domain time is also
done in kernel.

An example to use it:

  Run two ptp4l jobs on each of two boards for domain 1 and 2 synchronziation.

  Board1:
    # echo 2 > /sys/class/ptp/ptp0/num_vclocks
    [  282.230432] ptp ptp0: new virtual clock ptp2
    [  282.235211] ptp ptp0: new virtual clock ptp3
    [  282.240354] ptp ptp0: guarantee physical clock free running
    # echo 1 > /sys/class/ptp/ptp2/domain
    # echo 2 > /sys/class/ptp/ptp3/domain
    #
    # ptp4l -i eno0 -p/dev/ptp2 -m --domainNumber=1 --priority1=127 > domain1-master.log 2>&1 &
    # ptp4l -i eno0 -p/dev/ptp3 -m --domainNumber=2 --priority1=128 > domain2-slave.log 2>&1 &

  Board2:
    # echo 2 > /sys/class/ptp/ptp0/num_vclocks
    [  259.619382] ptp ptp0: new virtual clock ptp2
    [  259.624140] ptp ptp0: new virtual clock ptp3
    [  259.629315] ptp ptp0: guarantee physical clock free running
    # echo 1 > /sys/class/ptp/ptp2/domain
    # echo 2 > /sys/class/ptp/ptp3/domain
    #
    # ptp4l -i eno0 -p/dev/ptp2 -m --domainNumber=1 --priority1=128 > domain1-slave.log 2>&1 &
    # ptp4l -i eno0 -p/dev/ptp3 -m --domainNumber=2 --priority1=127 > domain2-master.log 2>&1 &

  Physical clock is guaranteed to stay free running when virtual clocks
  are created. To back use physical clock,

    # echo 0 > /sys/class/ptp/ptp0/num_vclocks
    [  531.249944] ptp ptp0: delete virtual clock ptp3
    [  531.254971] ptp ptp0: delete virtual clock ptp2
    [  531.259976] ptp ptp0: only physical clock in use now

How the patch-set affect current ptp drivers/function:

  - For current drivers, no impact on all existing function.

  - For drivers adapted to use it in the future, no impact on all
    existing function unless configuring value to num_vclocks in
    sysfs to convert to using virtual clocks.

  - For drivers adapted to use it with virtual clocks in using
    - Manual configurations are required for domain value in sysfs.
    - Manual configurations are required for application to specify
      right ptp device for domain on which the application will run.
    Note,
    - Physical clock is guaranteed to stay free running. Operation on it
      returns error.
    - If domain value of application has no PTP clock matched, the
      original HW timestamp will be used.

How to adapt drivers to use the feature:

  - During normally registering PTP clock for physical clock with
    ptp_clock_info, just fill the new member vclock_cc which contains
    cyclecounter info for virtual clock.

  - Timestamp conversion to domain time need to be done in MAC driver.
    When get HW timestamp, parse PTP packet domain value and convert
    timestamp to domain time by calling API ptp_clock_domain_tstamp(),
    before submitting to upper stack.

TODO:

  - PTP physical clock and its timestamping capabilities is still
    binding to network interface/interfaces through ethtool_ts_info.
    New way is needed to support querying all PTP virtual clocks
    and their timestamping capabilities. Making application to use
    PTP virtual clocks dynamically is a direction.

  - PTP packet parsing for domain value and one-step sync (not related
    to this patch-set) is common used. Make such functions common.

Changes for v2:
	- Converted to num_vclocks for creating virtual clocks.
	- Guranteed physical clock free running when using virtual
	  clocks.
	- Fixed build warning.
	- Updated copyright.

Yangbo Lu (7):
  ptp: add ptp virtual clock driver framework
  ptp: support ptp physical/virtual clocks conversion
  ptp: support domains and timestamp conversion
  ptp_qoriq: export ptp clock reading function for cyclecounter
  enetc_ptp: support ptp virtual clock
  enetc: store ptp device pointer
  enetc: support PTP domain timestamp conversion

 Documentation/ABI/testing/sysfs-ptp           |  25 +++
 MAINTAINERS                                   |   6 +
 drivers/net/ethernet/freescale/enetc/enetc.c  |  39 +++-
 drivers/net/ethernet/freescale/enetc/enetc.h  |   3 +-
 .../net/ethernet/freescale/enetc/enetc_pf.c   |  14 +-
 .../net/ethernet/freescale/enetc/enetc_ptp.c  |  13 +-
 .../net/ethernet/freescale/enetc/enetc_vf.c   |  14 +-
 drivers/ptp/Makefile                          |   2 +-
 drivers/ptp/ptp_clock.c                       |  12 ++
 drivers/ptp/ptp_private.h                     |  42 +++++
 drivers/ptp/ptp_qoriq.c                       |  16 ++
 drivers/ptp/ptp_sysfs.c                       | 134 +++++++++++++
 drivers/ptp/ptp_vclock.c                      | 176 ++++++++++++++++++
 include/linux/fsl/ptp_qoriq.h                 |   3 +-
 include/linux/ptp_clock_kernel.h              |  57 +++++-
 15 files changed, 545 insertions(+), 11 deletions(-)
 create mode 100644 drivers/ptp/ptp_vclock.c


base-commit: 86544c3de6a2185409c5a3d02f674ea223a14217
-- 
2.25.1


             reply	other threads:[~2021-05-21  4:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21  4:36 Yangbo Lu [this message]
2021-05-21  4:36 ` [net-next, v2, 1/7] ptp: add ptp virtual clock driver framework Yangbo Lu
2021-05-23 21:24   ` Richard Cochran
2021-05-31 10:38     ` Y.b. Lu
2021-05-21  4:36 ` [net-next, v2, 2/7] ptp: support ptp physical/virtual clocks conversion Yangbo Lu
2021-05-25 11:33   ` Richard Cochran
2021-05-31 10:39     ` Y.b. Lu
2021-05-25 12:28   ` Richard Cochran
2021-05-31 10:40     ` Y.b. Lu
2021-05-21  4:36 ` [net-next, v2, 3/7] ptp: support domains and timestamp conversion Yangbo Lu
2021-05-21  4:36 ` [net-next, v2, 4/7] ptp_qoriq: export ptp clock reading function for cyclecounter Yangbo Lu
2021-05-21  4:36 ` [net-next, v2, 5/7] enetc_ptp: support ptp virtual clock Yangbo Lu
2021-05-21  4:36 ` [net-next, v2, 6/7] enetc: store ptp device pointer Yangbo Lu
2021-05-21  4:36 ` [net-next, v2, 7/7] enetc: support PTP domain timestamp conversion Yangbo Lu
2021-05-22 20:46   ` Claudiu Manoil
2021-05-25 12:37   ` Richard Cochran
2021-05-25 12:48     ` Richard Cochran
2021-05-31 11:26       ` Y.b. Lu
2021-05-31 13:49         ` Richard Cochran
2021-06-15  9:44           ` Y.b. Lu
2021-05-31 10:51     ` Y.b. Lu
2021-05-31 11:31       ` Y.b. Lu
2021-05-31 13:54         ` Richard Cochran

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=20210521043619.44694-1-yangbo.lu@nxp.com \
    --to=yangbo.lu@nxp.com \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@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).