Commit c156174a authored by Yangbo Lu's avatar Yangbo Lu Committed by David S. Miller
Browse files

ethtool: add a new command for getting PHC virtual clocks



Add an interface for getting PHC (PTP Hardware Clock)
virtual clocks, which are based on PHC physical clock
providing hardware timestamp to network packets.

Signed-off-by: default avatarYangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent acb288e8
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ Userspace to kernel:
  ``ETHTOOL_MSG_FEC_SET``               set FEC settings
  ``ETHTOOL_MSG_MODULE_EEPROM_GET``     read SFP module EEPROM
  ``ETHTOOL_MSG_STATS_GET``             get standard statistics
  ``ETHTOOL_MSG_PHC_VCLOCKS_GET``       get PHC virtual clocks info
  ===================================== ================================

Kernel to userspace:
@@ -250,6 +251,7 @@ Kernel to userspace:
  ``ETHTOOL_MSG_FEC_NTF``                  FEC settings
  ``ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY``  read SFP module EEPROM
  ``ETHTOOL_MSG_STATS_GET_REPLY``          standard statistics
  ``ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY``    PHC virtual clocks info
  ======================================== =================================

``GET`` requests are sent by userspace applications to retrieve device
@@ -1477,6 +1479,25 @@ Low and high bounds are inclusive, for example:
 etherStatsPkts512to1023Octets 512  1023
 ============================= ==== ====

PHC_VCLOCKS_GET
===============

Query device PHC virtual clocks information.

Request contents:

  ====================================  ======  ==========================
  ``ETHTOOL_A_PHC_VCLOCKS_HEADER``      nested  request header
  ====================================  ======  ==========================

Kernel response contents:

  ====================================  ======  ==========================
  ``ETHTOOL_A_PHC_VCLOCKS_HEADER``      nested  reply header
  ``ETHTOOL_A_PHC_VCLOCKS_NUM``         u32     PHC virtual clocks number
  ``ETHTOOL_A_PHC_VCLOCKS_INDEX``       s32     PHC index array
  ====================================  ======  ==========================

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

@@ -1575,4 +1596,5 @@ are netlink only.
  n/a                                 ``ETHTOOL_MSG_CABLE_TEST_ACT``
  n/a                                 ``ETHTOOL_MSG_CABLE_TEST_TDR_ACT``
  n/a                                 ``ETHTOOL_MSG_TUNNEL_INFO_GET``
  n/a                                 ``ETHTOOL_MSG_PHC_VCLOCKS_GET``
  =================================== =====================================
+10 −0
Original line number Diff line number Diff line
@@ -757,6 +757,16 @@ void
ethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings,
			      enum ethtool_link_mode_bit_indices link_mode);

/**
 * ethtool_get_phc_vclocks - Derive phc vclocks information, and caller
 *                           is responsible to free memory of vclock_index
 * @dev: pointer to net_device structure
 * @vclock_index: pointer to pointer of vclock index
 *
 * Return number of phc vclocks
 */
int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index);

/**
 * ethtool_sprintf - Write formatted string to ethtool string data
 * @data: Pointer to start of string to update
+15 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ enum {
	ETHTOOL_MSG_FEC_SET,
	ETHTOOL_MSG_MODULE_EEPROM_GET,
	ETHTOOL_MSG_STATS_GET,
	ETHTOOL_MSG_PHC_VCLOCKS_GET,

	/* add new constants above here */
	__ETHTOOL_MSG_USER_CNT,
@@ -88,6 +89,7 @@ enum {
	ETHTOOL_MSG_FEC_NTF,
	ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY,
	ETHTOOL_MSG_STATS_GET_REPLY,
	ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY,

	/* add new constants above here */
	__ETHTOOL_MSG_KERNEL_CNT,
@@ -440,6 +442,19 @@ enum {
	ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
};

/* PHC VCLOCKS */

enum {
	ETHTOOL_A_PHC_VCLOCKS_UNSPEC,
	ETHTOOL_A_PHC_VCLOCKS_HEADER,			/* nest - _A_HEADER_* */
	ETHTOOL_A_PHC_VCLOCKS_NUM,			/* u32 */
	ETHTOOL_A_PHC_VCLOCKS_INDEX,			/* array, s32 */

	/* add new constants above here */
	__ETHTOOL_A_PHC_VCLOCKS_CNT,
	ETHTOOL_A_PHC_VCLOCKS_MAX = (__ETHTOOL_A_PHC_VCLOCKS_CNT - 1)
};

/* CABLE TEST */

enum {
+1 −1
Original line number Diff line number Diff line
@@ -7,4 +7,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 tsinfo.o cabletest.o \
		   tunnels.o fec.o eeprom.o stats.o
		   tunnels.o fec.o eeprom.o stats.o phc_vclocks.o
+13 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
#include <linux/net_tstamp.h>
#include <linux/phy.h>
#include <linux/rtnetlink.h>
#include <linux/ptp_clock_kernel.h>

#include "common.h"

@@ -554,6 +555,18 @@ int __ethtool_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
	return 0;
}

int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index)
{
	struct ethtool_ts_info info = { };
	int num = 0;

	if (!__ethtool_get_ts_info(dev, &info))
		num = ptp_get_vclocks_index(info.phc_index, vclock_index);

	return num;
}
EXPORT_SYMBOL(ethtool_get_phc_vclocks);

const struct ethtool_phy_ops *ethtool_phy_ops;

void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops)
Loading