Commit 5b071c59 authored by Michal Kubecek's avatar Michal Kubecek Committed by David S. Miller
Browse files

ethtool: provide timestamping information with TSINFO_GET request



Implement TSINFO_GET request to get timestamping information for a network
device. This is traditionally available via ETHTOOL_GET_TS_INFO ioctl
request.

Move part of ethtool_get_ts_info() into common.c so that ioctl and netlink
code use the same logic to get timestamping information from the device.

v3: use "TSINFO" rather than "TIMESTAMP", suggested by Richard Cochran

Signed-off-by: default avatarMichal Kubecek <mkubecek@suse.cz>
Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f76510b4
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -203,6 +203,7 @@ Userspace to kernel:
  ``ETHTOOL_MSG_PAUSE_SET``             set pause parameters
  ``ETHTOOL_MSG_EEE_GET``               get EEE settings
  ``ETHTOOL_MSG_EEE_SET``               set EEE settings
  ``ETHTOOL_MSG_TSINFO_GET``		get timestamping info
  ===================================== ================================

Kernel to userspace:
@@ -233,6 +234,7 @@ Kernel to userspace:
  ``ETHTOOL_MSG_PAUSE_NTF``             pause parameters
  ``ETHTOOL_MSG_EEE_GET_REPLY``         EEE settings
  ``ETHTOOL_MSG_EEE_NTF``               EEE settings
  ``ETHTOOL_MSG_TSINFO_GET_REPLY``	timestamping info
  ===================================== =================================

``GET`` requests are sent by userspace applications to retrieve device
@@ -928,6 +930,32 @@ but only first 32 can be set at the moment as that is what the ``ethtool_ops``
callback supports.


TSINFO_GET
==========

Gets timestamping information like ``ETHTOOL_GET_TS_INFO`` ioctl request.

Request contents:

  =====================================  ======  ==========================
  ``ETHTOOL_A_TSINFO_HEADER``            nested  request header
  =====================================  ======  ==========================

Kernel response contents:

  =====================================  ======  ==========================
  ``ETHTOOL_A_TSINFO_HEADER``            nested  request header
  ``ETHTOOL_A_TSINFO_TIMESTAMPING``      bitset  SO_TIMESTAMPING flags
  ``ETHTOOL_A_TSINFO_TX_TYPES``          bitset  supported Tx types
  ``ETHTOOL_A_TSINFO_RX_FILTERS``        bitset  supported Rx filters
  ``ETHTOOL_A_TSINFO_PHC_INDEX``         u32     PTP hw clock index
  =====================================  ======  ==========================

``ETHTOOL_A_TSINFO_PHC_INDEX`` is absent if there is no associated PHC (there
is no special value for this case). The bitset attributes are omitted if they
would be empty (no bit set).


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

@@ -1003,7 +1031,7 @@ have their netlink replacement yet.
  ``ETHTOOL_SET_DUMP``                n/a
  ``ETHTOOL_GET_DUMP_FLAG``           n/a
  ``ETHTOOL_GET_DUMP_DATA``           n/a
  ``ETHTOOL_GET_TS_INFO``             n/a
  ``ETHTOOL_GET_TS_INFO``             ``ETHTOOL_MSG_TSINFO_GET``
  ``ETHTOOL_GMODULEINFO``             n/a
  ``ETHTOOL_GMODULEEEPROM``           n/a
  ``ETHTOOL_GEEE``                    ``ETHTOOL_MSG_EEE_GET``
+17 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ enum {
	ETHTOOL_MSG_PAUSE_SET,
	ETHTOOL_MSG_EEE_GET,
	ETHTOOL_MSG_EEE_SET,
	ETHTOOL_MSG_TSINFO_GET,

	/* add new constants above here */
	__ETHTOOL_MSG_USER_CNT,
@@ -72,6 +73,7 @@ enum {
	ETHTOOL_MSG_PAUSE_NTF,
	ETHTOOL_MSG_EEE_GET_REPLY,
	ETHTOOL_MSG_EEE_NTF,
	ETHTOOL_MSG_TSINFO_GET_REPLY,

	/* add new constants above here */
	__ETHTOOL_MSG_KERNEL_CNT,
@@ -386,6 +388,21 @@ enum {
	ETHTOOL_A_EEE_MAX = (__ETHTOOL_A_EEE_CNT - 1)
};

/* TSINFO */

enum {
	ETHTOOL_A_TSINFO_UNSPEC,
	ETHTOOL_A_TSINFO_HEADER,			/* nest - _A_HEADER_* */
	ETHTOOL_A_TSINFO_TIMESTAMPING,			/* bitset */
	ETHTOOL_A_TSINFO_TX_TYPES,			/* bitset */
	ETHTOOL_A_TSINFO_RX_FILTERS,			/* bitset */
	ETHTOOL_A_TSINFO_PHC_INDEX,			/* u32 */

	/* add new constants above here */
	__ETHTOOL_A_TSINFO_CNT,
	ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
};

/* generic netlink info */
#define ETHTOOL_GENL_NAME "ethtool"
#define ETHTOOL_GENL_VERSION 1
+1 −1
Original line number Diff line number Diff line
@@ -6,4 +6,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o

ethtool_nl-y	:= netlink.o bitset.o strset.o linkinfo.o linkmodes.o \
		   linkstate.o debug.o wol.o features.o privflags.o rings.o \
		   channels.o coalesce.o pause.o eee.o
		   channels.o coalesce.o pause.o eee.o tsinfo.o
+21 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only

#include <linux/net_tstamp.h>
#include <linux/phy.h>

#include "common.h"

@@ -350,3 +351,23 @@ int ethtool_check_ops(const struct ethtool_ops *ops)
	 */
	return 0;
}

int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
{
	const struct ethtool_ops *ops = dev->ethtool_ops;
	struct phy_device *phydev = dev->phydev;

	memset(info, 0, sizeof(*info));
	info->cmd = ETHTOOL_GET_TS_INFO;

	if (phy_has_tsinfo(phydev))
		return phy_ts_info(phydev, info);
	if (ops->get_ts_info)
		return ops->get_ts_info(dev, info);

	info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
				SOF_TIMESTAMPING_SOFTWARE;
	info->phc_index = -1;

	return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -35,5 +35,6 @@ bool convert_legacy_settings_to_link_ksettings(
	struct ethtool_link_ksettings *link_ksettings,
	const struct ethtool_cmd *legacy_settings);
int ethtool_get_max_rxfh_channel(struct net_device *dev, u32 *max);
int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info);

#endif /* _ETHTOOL_COMMON_H */
Loading