Commit 6e9e2eed authored by Kory Maincent's avatar Kory Maincent Committed by David S. Miller
Browse files

net: ethtool: Add support for tsconfig command to get/set hwtstamp config



Introduce support for ETHTOOL_MSG_TSCONFIG_GET/SET ethtool netlink socket
to read and configure hwtstamp configuration of a PHC provider. Note that
simultaneous hwtstamp isn't supported; configuring a new one disables the
previous setting.

Signed-off-by: default avatarKory Maincent <kory.maincent@bootlin.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b9e3f7dc
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -1489,6 +1489,33 @@ attribute-sets:
      -
        name: downstream-sfp-name
        type: string
  -
    name: tsconfig
    attr-cnt-name: __ethtool-a-tsconfig-cnt
    attributes:
      -
        name: unspec
        type: unused
        value: 0
      -
        name: header
        type: nest
        nested-attributes: header
      -
        name: hwtstamp-provider
        type: nest
        nested-attributes: ts-hwtstamp-provider
      -
        name: tx-types
        type: nest
        nested-attributes: bitset
      -
        name: rx-filters
        type: nest
        nested-attributes: bitset
      -
        name: hwtstamp-flags
        type: u32

operations:
  enum-model: directional
@@ -2314,3 +2341,32 @@ operations:
      name: phy-ntf
      doc: Notification for change in PHY devices.
      notify: phy-get
    -
      name: tsconfig-get
      doc: Get hwtstamp config.

      attribute-set: tsconfig

      do: &tsconfig-get-op
        request:
          attributes:
            - header
        reply:
          attributes: &tsconfig
            - header
            - hwtstamp-provider
            - tx-types
            - rx-filters
            - hwtstamp-flags
      dump: *tsconfig-get-op
    -
      name: tsconfig-set
      doc: Set hwtstamp config.

      attribute-set: tsconfig

      do:
        request:
          attributes: *tsconfig
        reply:
          attributes: *tsconfig
+75 −0
Original line number Diff line number Diff line
@@ -237,6 +237,8 @@ Userspace to kernel:
  ``ETHTOOL_MSG_MM_SET``                set MAC merge layer parameters
  ``ETHTOOL_MSG_MODULE_FW_FLASH_ACT``   flash transceiver module firmware
  ``ETHTOOL_MSG_PHY_GET``               get Ethernet PHY information
  ``ETHTOOL_MSG_TSCONFIG_GET``          get hw timestamping configuration
  ``ETHTOOL_MSG_TSCONFIG_SET``          set hw timestamping configuration
  ===================================== =================================

Kernel to userspace:
@@ -286,6 +288,8 @@ Kernel to userspace:
  ``ETHTOOL_MSG_MODULE_FW_FLASH_NTF``      transceiver module flash updates
  ``ETHTOOL_MSG_PHY_GET_REPLY``            Ethernet PHY information
  ``ETHTOOL_MSG_PHY_NTF``                  Ethernet PHY information change
  ``ETHTOOL_MSG_TSCONFIG_GET_REPLY``       hw timestamping configuration
  ``ETHTOOL_MSG_TSCONFIG_SET_REPLY``       new hw timestamping configuration
  ======================================== =================================

``GET`` requests are sent by userspace applications to retrieve device
@@ -2244,6 +2248,75 @@ Kernel response contents:
When ``ETHTOOL_A_PHY_UPSTREAM_TYPE`` is PHY_UPSTREAM_PHY, the PHY's parent is
another PHY.

TSCONFIG_GET
============

Retrieves the information about the current hardware timestamping source and
configuration.

It is similar to the deprecated ``SIOCGHWTSTAMP`` ioctl request.

Request contents:

  ====================================  ======  ==========================
  ``ETHTOOL_A_TSCONFIG_HEADER``         nested  request header
  ====================================  ======  ==========================

Kernel response contents:

  ======================================== ======  ============================
  ``ETHTOOL_A_TSCONFIG_HEADER``            nested  request header
  ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested  PTP hw clock provider
  ``ETHTOOL_A_TSCONFIG_TX_TYPES``          bitset  hwtstamp Tx type
  ``ETHTOOL_A_TSCONFIG_RX_FILTERS``        bitset  hwtstamp Rx filter
  ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS``	   u32     hwtstamp flags
  ======================================== ======  ============================

When set the ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` attribute identifies the
source of the hw timestamping provider. It is composed by
``ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX`` attribute which describe the index of
the PTP device and ``ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER`` which describe
the qualifier of the timestamp.

When set the ``ETHTOOL_A_TSCONFIG_TX_TYPES``, ``ETHTOOL_A_TSCONFIG_RX_FILTERS``
and the ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` attributes identify the Tx
type, the Rx filter and the flags configured for the current hw timestamping
provider. The attributes are propagated to the driver through the following
structure:

.. kernel-doc:: include/linux/net_tstamp.h
    :identifiers: kernel_hwtstamp_config

TSCONFIG_SET
============

Set the information about the current hardware timestamping source and
configuration.

It is similar to the deprecated ``SIOCSHWTSTAMP`` ioctl request.

Request contents:

  ======================================== ======  ============================
  ``ETHTOOL_A_TSCONFIG_HEADER``            nested  request header
  ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested  PTP hw clock provider
  ``ETHTOOL_A_TSCONFIG_TX_TYPES``          bitset  hwtstamp Tx type
  ``ETHTOOL_A_TSCONFIG_RX_FILTERS``        bitset  hwtstamp Rx filter
  ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS``	   u32     hwtstamp flags
  ======================================== ======  ============================

Kernel response contents:

  ======================================== ======  ============================
  ``ETHTOOL_A_TSCONFIG_HEADER``            nested  request header
  ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested  PTP hw clock provider
  ``ETHTOOL_A_TSCONFIG_TX_TYPES``          bitset  hwtstamp Tx type
  ``ETHTOOL_A_TSCONFIG_RX_FILTERS``        bitset  hwtstamp Rx filter
  ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS``	   u32     hwtstamp flags
  ======================================== ======  ============================

For a description of each attribute, see ``TSCONFIG_GET``.

Request translation
===================

@@ -2352,4 +2425,6 @@ are netlink only.
  n/a                                 ``ETHTOOL_MSG_MM_SET``
  n/a                                 ``ETHTOOL_MSG_MODULE_FW_FLASH_ACT``
  n/a                                 ``ETHTOOL_MSG_PHY_GET``
  ``SIOCGHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_GET``
  ``SIOCSHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_SET``
  =================================== =====================================
+24 −14
Original line number Diff line number Diff line
@@ -525,8 +525,8 @@ implicitly defined. ts[0] holds a software timestamp if set, ts[1]
is again deprecated and ts[2] holds a hardware timestamp if set.


3. Hardware Timestamping configuration: SIOCSHWTSTAMP and SIOCGHWTSTAMP
=======================================================================
3. Hardware Timestamping configuration: ETHTOOL_MSG_TSCONFIG_SET/GET
====================================================================

Hardware time stamping must also be initialized for each device driver
that is expected to do hardware time stamping. The parameter is defined in
@@ -539,12 +539,14 @@ include/uapi/linux/net_tstamp.h as::
	};

Desired behavior is passed into the kernel and to a specific device by
calling ioctl(SIOCSHWTSTAMP) with a pointer to a struct ifreq whose
ifr_data points to a struct hwtstamp_config. The tx_type and
rx_filter are hints to the driver what it is expected to do. If
the requested fine-grained filtering for incoming packets is not
supported, the driver may time stamp more than just the requested types
of packets.
calling the tsconfig netlink socket ``ETHTOOL_MSG_TSCONFIG_SET``.
The ``ETHTOOL_A_TSCONFIG_TX_TYPES``, ``ETHTOOL_A_TSCONFIG_RX_FILTERS`` and
``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` netlink attributes are then used to set
the struct hwtstamp_config accordingly.

The ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` netlink nested attribute is used
to select the source of the hardware time stamping. It is composed of an index
for the device source and a qualifier for the type of time stamping.

Drivers are free to use a more permissive configuration than the requested
configuration. It is expected that drivers should only implement directly the
@@ -563,9 +565,16 @@ Only a processes with admin rights may change the configuration. User
space is responsible to ensure that multiple processes don't interfere
with each other and that the settings are reset.

Any process can read the actual configuration by passing this
structure to ioctl(SIOCGHWTSTAMP) in the same way.  However, this has
not been implemented in all drivers.
Any process can read the actual configuration by requesting tsconfig netlink
socket ``ETHTOOL_MSG_TSCONFIG_GET``.

The legacy configuration is the use of the ioctl(SIOCSHWTSTAMP) with a pointer
to a struct ifreq whose ifr_data points to a struct hwtstamp_config.
The tx_type and rx_filter are hints to the driver what it is expected to do.
If the requested fine-grained filtering for incoming packets is not
supported, the driver may time stamp more than just the requested types
of packets. ioctl(SIOCGHWTSTAMP) is used in the same way as the
ioctl(SIOCSHWTSTAMP). However, this has not been implemented in all drivers.

::

@@ -610,9 +619,10 @@ not been implemented in all drivers.
--------------------------------------------------------

A driver which supports hardware time stamping must support the
SIOCSHWTSTAMP ioctl and update the supplied struct hwtstamp_config with
the actual values as described in the section on SIOCSHWTSTAMP.  It
should also support SIOCGHWTSTAMP.
ndo_hwtstamp_set NDO or the legacy SIOCSHWTSTAMP ioctl and update the
supplied struct hwtstamp_config with the actual values as described in
the section on SIOCSHWTSTAMP. It should also support ndo_hwtstamp_get or
the legacy SIOCGHWTSTAMP.

Time stamps for received packets must be stored in the skb. To get a pointer
to the shared time stamp structure of the skb call skb_hwtstamps(). Then
+16 −0
Original line number Diff line number Diff line
@@ -694,6 +694,18 @@ enum {
	ETHTOOL_A_PHY_MAX = (__ETHTOOL_A_PHY_CNT - 1)
};

enum {
	ETHTOOL_A_TSCONFIG_UNSPEC,
	ETHTOOL_A_TSCONFIG_HEADER,
	ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER,
	ETHTOOL_A_TSCONFIG_TX_TYPES,
	ETHTOOL_A_TSCONFIG_RX_FILTERS,
	ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS,

	__ETHTOOL_A_TSCONFIG_CNT,
	ETHTOOL_A_TSCONFIG_MAX = (__ETHTOOL_A_TSCONFIG_CNT - 1)
};

enum {
	ETHTOOL_MSG_USER_NONE = 0,
	ETHTOOL_MSG_STRSET_GET = 1,
@@ -741,6 +753,8 @@ enum {
	ETHTOOL_MSG_MM_SET,
	ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
	ETHTOOL_MSG_PHY_GET,
	ETHTOOL_MSG_TSCONFIG_GET,
	ETHTOOL_MSG_TSCONFIG_SET,

	__ETHTOOL_MSG_USER_CNT,
	ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
@@ -794,6 +808,8 @@ enum {
	ETHTOOL_MSG_MODULE_FW_FLASH_NTF,
	ETHTOOL_MSG_PHY_GET_REPLY,
	ETHTOOL_MSG_PHY_NTF,
	ETHTOOL_MSG_TSCONFIG_GET_REPLY,
	ETHTOOL_MSG_TSCONFIG_SET_REPLY,

	__ETHTOOL_MSG_KERNEL_CNT,
	ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)
+1 −1
Original line number Diff line number Diff line
@@ -9,4 +9,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \
		   channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
		   tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
		   module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o mm.o \
		   phy.o
		   phy.o tsconfig.o
Loading