ethtool: add timestamping related string sets
authorMichal Kubecek <mkubecek@suse.cz>
Fri, 27 Mar 2020 23:01:53 +0000 (00:01 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 30 Mar 2020 05:32:36 +0000 (22:32 -0700)
Add three string sets related to timestamping information:

  ETH_SS_SOF_TIMESTAMPING: SOF_TIMESTAMPING_* flags
  ETH_SS_TS_TX_TYPES:      timestamping Tx types
  ETH_SS_TS_RX_FILTERS:    timestamping Rx filters

These will be used for TIMESTAMP_GET request.

v2: avoid compiler warning ("enumeration value not handled in switch")
    in net_hwtstamp_validate()

v3: omit dash in Tx type names ("one-step-*" -> "onestep-*"), suggested by
    Richard Cochran

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/ethtool.h
include/uapi/linux/net_tstamp.h
net/core/dev_ioctl.c
net/ethtool/common.c
net/ethtool/common.h
net/ethtool/strset.c

index d586ee5e10a1b2f86ec019bd8f4b9b311620f3a4..92f737f1011781745118a5254d4a7957dc11f1f8 100644 (file)
@@ -596,6 +596,9 @@ struct ethtool_pauseparam {
  * @ETH_SS_LINK_MODES: link mode names
  * @ETH_SS_MSG_CLASSES: debug message class names
  * @ETH_SS_WOL_MODES: wake-on-lan modes
+ * @ETH_SS_SOF_TIMESTAMPING: SOF_TIMESTAMPING_* flags
+ * @ETH_SS_TS_TX_TYPES: timestamping Tx types
+ * @ETH_SS_TS_RX_FILTERS: timestamping Rx filters
  */
 enum ethtool_stringset {
        ETH_SS_TEST             = 0,
@@ -610,6 +613,9 @@ enum ethtool_stringset {
        ETH_SS_LINK_MODES,
        ETH_SS_MSG_CLASSES,
        ETH_SS_WOL_MODES,
+       ETH_SS_SOF_TIMESTAMPING,
+       ETH_SS_TS_TX_TYPES,
+       ETH_SS_TS_RX_FILTERS,
 
        /* add new constants above here */
        ETH_SS_COUNT
index f96e650d0af992158ac53ffce3d9f5414e733f59..7ed0b3d1c00a1df5d43d597f176ead321d56c7f4 100644 (file)
@@ -98,6 +98,9 @@ enum hwtstamp_tx_types {
         * receive a time stamp via the socket error queue.
         */
        HWTSTAMP_TX_ONESTEP_P2P,
+
+       /* add new constants above here */
+       __HWTSTAMP_TX_CNT
 };
 
 /* possible values for hwtstamp_config->rx_filter */
@@ -140,6 +143,9 @@ enum hwtstamp_rx_filters {
 
        /* NTP, UDP, all versions and packet modes */
        HWTSTAMP_FILTER_NTP_ALL,
+
+       /* add new constants above here */
+       __HWTSTAMP_FILTER_CNT
 };
 
 /* SCM_TIMESTAMPING_PKTINFO control message */
index dbaebbe573f001b0a46bc7997f2a93d7359ef17f..547b587c1950822d3e8f7f01270f7795022d9712 100644 (file)
@@ -190,6 +190,9 @@ static int net_hwtstamp_validate(struct ifreq *ifr)
        case HWTSTAMP_TX_ONESTEP_P2P:
                tx_type_valid = 1;
                break;
+       case __HWTSTAMP_TX_CNT:
+               /* not a real value */
+               break;
        }
 
        switch (rx_filter) {
@@ -211,6 +214,9 @@ static int net_hwtstamp_validate(struct ifreq *ifr)
        case HWTSTAMP_FILTER_NTP_ALL:
                rx_filter_valid = 1;
                break;
+       case __HWTSTAMP_FILTER_CNT:
+               /* not a real value */
+               break;
        }
 
        if (!tx_type_valid || !rx_filter_valid)
index 51a0941fc62f1fe730e84657ed7b3fcdefdff4d2..150ff405cca4cb884706c7ded5e09e6162f544c3 100644 (file)
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#include <linux/net_tstamp.h>
+
 #include "common.h"
 
 const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
@@ -204,6 +206,53 @@ const char wol_mode_names[][ETH_GSTRING_LEN] = {
 };
 static_assert(ARRAY_SIZE(wol_mode_names) == WOL_MODE_COUNT);
 
+const char sof_timestamping_names[][ETH_GSTRING_LEN] = {
+       [const_ilog2(SOF_TIMESTAMPING_TX_HARDWARE)]  = "hardware-transmit",
+       [const_ilog2(SOF_TIMESTAMPING_TX_SOFTWARE)]  = "software-transmit",
+       [const_ilog2(SOF_TIMESTAMPING_RX_HARDWARE)]  = "hardware-receive",
+       [const_ilog2(SOF_TIMESTAMPING_RX_SOFTWARE)]  = "software-receive",
+       [const_ilog2(SOF_TIMESTAMPING_SOFTWARE)]     = "software-system-clock",
+       [const_ilog2(SOF_TIMESTAMPING_SYS_HARDWARE)] = "hardware-legacy-clock",
+       [const_ilog2(SOF_TIMESTAMPING_RAW_HARDWARE)] = "hardware-raw-clock",
+       [const_ilog2(SOF_TIMESTAMPING_OPT_ID)]       = "option-id",
+       [const_ilog2(SOF_TIMESTAMPING_TX_SCHED)]     = "sched-transmit",
+       [const_ilog2(SOF_TIMESTAMPING_TX_ACK)]       = "ack-transmit",
+       [const_ilog2(SOF_TIMESTAMPING_OPT_CMSG)]     = "option-cmsg",
+       [const_ilog2(SOF_TIMESTAMPING_OPT_TSONLY)]   = "option-tsonly",
+       [const_ilog2(SOF_TIMESTAMPING_OPT_STATS)]    = "option-stats",
+       [const_ilog2(SOF_TIMESTAMPING_OPT_PKTINFO)]  = "option-pktinfo",
+       [const_ilog2(SOF_TIMESTAMPING_OPT_TX_SWHW)]  = "option-tx-swhw",
+};
+static_assert(ARRAY_SIZE(sof_timestamping_names) == __SOF_TIMESTAMPING_CNT);
+
+const char ts_tx_type_names[][ETH_GSTRING_LEN] = {
+       [HWTSTAMP_TX_OFF]               = "off",
+       [HWTSTAMP_TX_ON]                = "on",
+       [HWTSTAMP_TX_ONESTEP_SYNC]      = "onestep-sync",
+       [HWTSTAMP_TX_ONESTEP_P2P]       = "onestep-p2p",
+};
+static_assert(ARRAY_SIZE(ts_tx_type_names) == __HWTSTAMP_TX_CNT);
+
+const char ts_rx_filter_names[][ETH_GSTRING_LEN] = {
+       [HWTSTAMP_FILTER_NONE]                  = "none",
+       [HWTSTAMP_FILTER_ALL]                   = "all",
+       [HWTSTAMP_FILTER_SOME]                  = "some",
+       [HWTSTAMP_FILTER_PTP_V1_L4_EVENT]       = "ptpv1-l4-event",
+       [HWTSTAMP_FILTER_PTP_V1_L4_SYNC]        = "ptpv1-l4-sync",
+       [HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ]   = "ptpv1-l4-delay-req",
+       [HWTSTAMP_FILTER_PTP_V2_L4_EVENT]       = "ptpv2-l4-event",
+       [HWTSTAMP_FILTER_PTP_V2_L4_SYNC]        = "ptpv2-l4-sync",
+       [HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ]   = "ptpv2-l4-delay-req",
+       [HWTSTAMP_FILTER_PTP_V2_L2_EVENT]       = "ptpv2-l2-event",
+       [HWTSTAMP_FILTER_PTP_V2_L2_SYNC]        = "ptpv2-l2-sync",
+       [HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ]   = "ptpv2-l2-delay-req",
+       [HWTSTAMP_FILTER_PTP_V2_EVENT]          = "ptpv2-event",
+       [HWTSTAMP_FILTER_PTP_V2_SYNC]           = "ptpv2-sync",
+       [HWTSTAMP_FILTER_PTP_V2_DELAY_REQ]      = "ptpv2-delay-req",
+       [HWTSTAMP_FILTER_NTP_ALL]               = "ntp-all",
+};
+static_assert(ARRAY_SIZE(ts_rx_filter_names) == __HWTSTAMP_FILTER_CNT);
+
 /* return false if legacy contained non-0 deprecated fields
  * maxtxpkt/maxrxpkt. rest of ksettings always updated
  */
index 03946e16e623439750bd44128970fb77f58b35ab..c54c8d57fd8f787fa058a540760ab6c6ced3eccb 100644 (file)
@@ -12,6 +12,8 @@
 #define ETHTOOL_LINK_MODE(speed, type, duplex) \
        ETHTOOL_LINK_MODE_ ## speed ## base ## type ## _ ## duplex ## _BIT
 
+#define __SOF_TIMESTAMPING_CNT (const_ilog2(SOF_TIMESTAMPING_LAST) + 1)
+
 extern const char
 netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN];
 extern const char
@@ -23,6 +25,9 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
 extern const char link_mode_names[][ETH_GSTRING_LEN];
 extern const char netif_msg_class_names[][ETH_GSTRING_LEN];
 extern const char wol_mode_names[][ETH_GSTRING_LEN];
+extern const char sof_timestamping_names[][ETH_GSTRING_LEN];
+extern const char ts_tx_type_names[][ETH_GSTRING_LEN];
+extern const char ts_rx_filter_names[][ETH_GSTRING_LEN];
 
 int __ethtool_get_link(struct net_device *dev);
 
index 8e5911887b4c00f2e28b926111982a80881e3f27..95eae5c68a52420404d2e7cbcebb28b764056fc1 100644 (file)
@@ -60,6 +60,21 @@ static const struct strset_info info_template[] = {
                .count          = WOL_MODE_COUNT,
                .strings        = wol_mode_names,
        },
+       [ETH_SS_SOF_TIMESTAMPING] = {
+               .per_dev        = false,
+               .count          = __SOF_TIMESTAMPING_CNT,
+               .strings        = sof_timestamping_names,
+       },
+       [ETH_SS_TS_TX_TYPES] = {
+               .per_dev        = false,
+               .count          = __HWTSTAMP_TX_CNT,
+               .strings        = ts_tx_type_names,
+       },
+       [ETH_SS_TS_RX_FILTERS] = {
+               .per_dev        = false,
+               .count          = __HWTSTAMP_FILTER_CNT,
+               .strings        = ts_rx_filter_names,
+       },
 };
 
 struct strset_req_info {