From: Rahul Rameshbabu <rrameshbabu@nvidia.com>
To: rrameshbabu@nvidia.com
Cc: ahmed.zaki@intel.com, aleksander.lobakin@intel.com,
alexandre.torgue@foss.st.com, andrew@lunn.ch, corbet@lwn.net,
davem@davemloft.net, dtatulea@nvidia.com, edumazet@google.com,
gal@nvidia.com, hkallweit1@gmail.com, jacob.e.keller@intel.com,
jiri@resnulli.us, joabreu@synopsys.com, justinstitt@google.com,
kory.maincent@bootlin.com, kuba@kernel.org, leon@kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
liuhangbin@gmail.com, maxime.chevallier@bootlin.com,
netdev@vger.kernel.org, pabeni@redhat.com,
paul.greenwalt@intel.com, przemyslaw.kitszel@intel.com,
rdunlap@infradead.org, richardcochran@gmail.com,
saeed@kernel.org, tariqt@nvidia.com, vadim.fedorenko@linux.dev,
vladimir.oltean@nxp.com, wojciech.drewek@intel.com
Subject: [PATCH RFC v2 1/6] ethtool: add interface to read Tx hardware timestamping statistics
Date: Sat, 9 Mar 2024 00:44:35 -0800 [thread overview]
Message-ID: <20240309084440.299358-2-rrameshbabu@nvidia.com> (raw)
In-Reply-To: <20240309084440.299358-1-rrameshbabu@nvidia.com>
Multiple network devices that support hardware timestamping appear to have
common behavior with regards to timestamp handling. Implement common Tx
hardware timestamping statistics in a tx_stats struct_group. Common Rx
hardware timestamping statistics can subsequently be implemented in a
rx_stats struct_group for ethtool_ts_stats.
Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
---
Documentation/netlink/specs/ethtool.yaml | 20 +++++++++
include/linux/ethtool.h | 21 ++++++++++
include/uapi/linux/ethtool_netlink.h | 15 +++++++
net/ethtool/tsinfo.c | 52 +++++++++++++++++++++++-
4 files changed, 107 insertions(+), 1 deletion(-)
diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml
index 197208f419dc..f99b003c78c0 100644
--- a/Documentation/netlink/specs/ethtool.yaml
+++ b/Documentation/netlink/specs/ethtool.yaml
@@ -559,6 +559,21 @@ attribute-sets:
-
name: tx-lpi-timer
type: u32
+ -
+ name: ts-stat
+ attributes:
+ -
+ name: pad
+ type: pad
+ -
+ name: tx-pkts
+ type: u64
+ -
+ name: tx-lost
+ type: u64
+ -
+ name: tx-err
+ type: u64
-
name: tsinfo
attributes:
@@ -581,6 +596,10 @@ attribute-sets:
-
name: phc-index
type: u32
+ -
+ name: stats
+ type: nest
+ nested-attributes: ts-stat
-
name: cable-result
attributes:
@@ -1388,6 +1407,7 @@ operations:
- tx-types
- rx-filters
- phc-index
+ - stats
dump: *tsinfo-get-op
-
name: cable-test-act
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index b90c33607594..a1704938a6fb 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -483,6 +483,24 @@ struct ethtool_rmon_stats {
);
};
+/**
+ * struct ethtool_ts_stats - HW timestamping statistics
+ * @tx_stats: struct group for TX HW timestamping
+ * @pkts: Number of packets successfully timestamped by the queried
+ * layer.
+ * @lost: Number of packet timestamps that failed to get applied on a
+ * packet by the queried layer.
+ * @err: Number of timestamping errors that occurred on the queried
+ * layer.
+ */
+struct ethtool_ts_stats {
+ struct_group(tx_stats,
+ u64 pkts;
+ u64 lost;
+ u64 err;
+ );
+};
+
#define ETH_MODULE_EEPROM_PAGE_LEN 128
#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f
@@ -759,6 +777,7 @@ struct ethtool_rxfh_param {
* It may be called with RCU, or rtnl or reference on the device.
* Drivers supporting transmit time stamps in software should set this to
* ethtool_op_get_ts_info().
+ * @get_ts_stats: Query the device hardware timestamping statistics.
* @get_module_info: Get the size and type of the eeprom contained within
* a plug-in module.
* @get_module_eeprom: Get the eeprom information from the plug-in module
@@ -901,6 +920,8 @@ struct ethtool_ops {
struct ethtool_dump *, void *);
int (*set_dump)(struct net_device *, struct ethtool_dump *);
int (*get_ts_info)(struct net_device *, struct ethtool_ts_info *);
+ void (*get_ts_stats)(struct net_device *dev,
+ struct ethtool_ts_stats *ts_stats);
int (*get_module_info)(struct net_device *,
struct ethtool_modinfo *);
int (*get_module_eeprom)(struct net_device *,
diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h
index 3f89074aa06c..046a78d9421d 100644
--- a/include/uapi/linux/ethtool_netlink.h
+++ b/include/uapi/linux/ethtool_netlink.h
@@ -478,12 +478,27 @@ enum {
ETHTOOL_A_TSINFO_TX_TYPES, /* bitset */
ETHTOOL_A_TSINFO_RX_FILTERS, /* bitset */
ETHTOOL_A_TSINFO_PHC_INDEX, /* u32 */
+ ETHTOOL_A_TSINFO_STATS, /* nest - _A_TSINFO_STAT */
/* add new constants above here */
__ETHTOOL_A_TSINFO_CNT,
ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
};
+enum {
+ ETHTOOL_A_TS_STAT_UNSPEC,
+ ETHTOOL_A_TS_STAT_PAD,
+
+ ETHTOOL_A_TS_STAT_TX_PKT, /* array, u64 */
+ ETHTOOL_A_TS_STAT_TX_LOST, /* array, u64 */
+ ETHTOOL_A_TS_STAT_TX_ERR, /* array, u64 */
+
+ /* add new constants above here */
+ __ETHTOOL_A_TS_STAT_CNT,
+ ETHTOOL_A_TS_STAT_MAX = (__ETHTOOL_A_TS_STAT_CNT - 1)
+
+};
+
/* PHC VCLOCKS */
enum {
diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
index 9daed0aab162..0d1370ded122 100644
--- a/net/ethtool/tsinfo.c
+++ b/net/ethtool/tsinfo.c
@@ -13,14 +13,18 @@ struct tsinfo_req_info {
struct tsinfo_reply_data {
struct ethnl_reply_data base;
struct ethtool_ts_info ts_info;
+ struct ethtool_ts_stats stats;
};
#define TSINFO_REPDATA(__reply_base) \
container_of(__reply_base, struct tsinfo_reply_data, base)
+#define ETHTOOL_TS_STAT_CNT \
+ (__ETHTOOL_A_TS_STAT_CNT - (ETHTOOL_A_TS_STAT_PAD + 1))
+
const struct nla_policy ethnl_tsinfo_get_policy[] = {
[ETHTOOL_A_TSINFO_HEADER] =
- NLA_POLICY_NESTED(ethnl_header_policy),
+ NLA_POLICY_NESTED(ethnl_header_policy_stats),
};
static int tsinfo_prepare_data(const struct ethnl_req_info *req_base,
@@ -34,6 +38,12 @@ static int tsinfo_prepare_data(const struct ethnl_req_info *req_base,
ret = ethnl_ops_begin(dev);
if (ret < 0)
return ret;
+ if (req_base->flags & ETHTOOL_FLAG_STATS &&
+ dev->ethtool_ops->get_ts_stats) {
+ ethtool_stats_init((u64 *)&data->stats,
+ sizeof(data->stats) / sizeof(u64));
+ dev->ethtool_ops->get_ts_stats(dev, &data->stats);
+ }
ret = __ethtool_get_ts_info(dev, &data->ts_info);
ethnl_ops_complete(dev);
@@ -79,10 +89,47 @@ static int tsinfo_reply_size(const struct ethnl_req_info *req_base,
}
if (ts_info->phc_index >= 0)
len += nla_total_size(sizeof(u32)); /* _TSINFO_PHC_INDEX */
+ if (req_base->flags & ETHTOOL_FLAG_STATS)
+ len += nla_total_size(0) + /* _TSINFO_STATS */
+ nla_total_size_64bit(sizeof(u64)) * ETHTOOL_TS_STAT_CNT;
return len;
}
+static int tsinfo_put_stat(struct sk_buff *skb, u64 val, u16 attrtype)
+{
+ if (val == ETHTOOL_STAT_NOT_SET)
+ return 0;
+ if (nla_put_u64_64bit(skb, attrtype, val, ETHTOOL_A_TS_STAT_PAD))
+ return -EMSGSIZE;
+ return 0;
+}
+
+static int tsinfo_put_stats(struct sk_buff *skb,
+ const struct ethtool_ts_stats *stats)
+{
+ struct nlattr *nest;
+
+ nest = nla_nest_start(skb, ETHTOOL_A_TSINFO_STATS);
+ if (!nest)
+ return -EMSGSIZE;
+
+ if (tsinfo_put_stat(skb, stats->tx_stats.pkts,
+ ETHTOOL_A_TS_STAT_TX_PKT) ||
+ tsinfo_put_stat(skb, stats->tx_stats.lost,
+ ETHTOOL_A_TS_STAT_TX_LOST) ||
+ tsinfo_put_stat(skb, stats->tx_stats.err,
+ ETHTOOL_A_TS_STAT_TX_ERR))
+ goto err_cancel;
+
+ nla_nest_end(skb, nest);
+ return 0;
+
+err_cancel:
+ nla_nest_cancel(skb, nest);
+ return -EMSGSIZE;
+}
+
static int tsinfo_fill_reply(struct sk_buff *skb,
const struct ethnl_req_info *req_base,
const struct ethnl_reply_data *reply_base)
@@ -119,6 +166,9 @@ static int tsinfo_fill_reply(struct sk_buff *skb,
if (ts_info->phc_index >= 0 &&
nla_put_u32(skb, ETHTOOL_A_TSINFO_PHC_INDEX, ts_info->phc_index))
return -EMSGSIZE;
+ if (req_base->flags & ETHTOOL_FLAG_STATS &&
+ tsinfo_put_stats(skb, &data->stats))
+ return -EMSGSIZE;
return 0;
}
--
2.42.0
next prev parent reply other threads:[~2024-03-09 8:45 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-23 19:24 [PATCH RFC net-next v1 0/6] ethtool HW timestamping statistics Rahul Rameshbabu
2024-02-23 19:24 ` [PATCH RFC net-next v1 1/6] ethtool: add interface to read Tx hardware " Rahul Rameshbabu
2024-02-23 21:07 ` Jacob Keller
2024-02-23 22:21 ` Rahul Rameshbabu
2024-02-23 22:48 ` Jacob Keller
2024-02-23 23:43 ` Rahul Rameshbabu
2024-02-26 19:54 ` Jacob Keller
2024-03-07 18:47 ` Rahul Rameshbabu
2024-03-08 3:29 ` Jacob Keller
2024-03-08 5:09 ` Rahul Rameshbabu
2024-03-08 22:28 ` Jacob Keller
2024-03-08 22:30 ` Rahul Rameshbabu
2024-02-26 8:59 ` Köry Maincent
2024-02-26 10:09 ` Köry Maincent
2024-02-29 2:05 ` Jakub Kicinski
2024-02-29 22:20 ` Rahul Rameshbabu
2024-02-23 19:24 ` [PATCH RFC net-next v1 2/6] net/mlx5e: Introduce lost_cqe statistic counter for PTP Tx port timestamping CQ Rahul Rameshbabu
2024-02-23 19:24 ` [PATCH RFC net-next v1 3/6] net/mlx5e: Introduce timestamps statistic counter for Tx DMA layer Rahul Rameshbabu
2024-02-23 19:24 ` [PATCH RFC net-next v1 4/6] net/mlx5e: Implement ethtool hardware timestamping statistics Rahul Rameshbabu
2024-02-26 9:26 ` Köry Maincent
2024-02-23 19:24 ` [PATCH RFC net-next v1 5/6] tools: ynl: ethtool.py: Make tool invokable from any CWD Rahul Rameshbabu
2024-02-23 21:08 ` Jacob Keller
2024-02-23 22:39 ` Rahul Rameshbabu
2024-02-29 2:08 ` Jakub Kicinski
2024-02-23 19:24 ` [PATCH RFC net-next v1 6/6] tools: ynl: ethtool.py: Add ts ethtool statistics group Rahul Rameshbabu
2024-02-23 21:00 ` [PATCH RFC net-next v1 0/6] ethtool HW timestamping statistics Jacob Keller
2024-02-23 21:12 ` Jacob Keller
2024-02-23 22:47 ` Rahul Rameshbabu
2024-03-09 8:44 ` [PATCH RFC v2 " Rahul Rameshbabu
2024-03-09 8:44 ` Rahul Rameshbabu [this message]
2024-03-12 23:53 ` [PATCH RFC v2 1/6] ethtool: add interface to read Tx hardware " Jakub Kicinski
2024-03-14 0:26 ` Rahul Rameshbabu
2024-03-14 0:41 ` Jakub Kicinski
2024-03-14 0:50 ` Rahul Rameshbabu
2024-03-14 1:40 ` Jakub Kicinski
2024-03-14 4:19 ` Rahul Rameshbabu
2024-03-14 17:50 ` Keller, Jacob E
2024-03-14 18:48 ` Rahul Rameshbabu
2024-03-14 17:01 ` Rahul Rameshbabu
2024-03-14 17:59 ` Jakub Kicinski
2024-03-14 18:43 ` Rahul Rameshbabu
2024-03-14 19:06 ` Jakub Kicinski
2024-03-14 20:16 ` Rahul Rameshbabu
2024-03-09 8:44 ` [PATCH RFC v2 2/6] net/mlx5e: Introduce lost_cqe statistic counter for PTP Tx port timestamping CQ Rahul Rameshbabu
2024-03-09 8:44 ` [PATCH RFC v2 3/6] net/mlx5e: Introduce timestamps statistic counter for Tx DMA layer Rahul Rameshbabu
2024-03-09 8:44 ` [PATCH RFC v2 4/6] net/mlx5e: Implement ethtool hardware timestamping statistics Rahul Rameshbabu
2024-03-09 8:44 ` [PATCH RFC v2 5/6] tools: ynl: ethtool.py: Make tool invokable from any CWD Rahul Rameshbabu
2024-03-11 12:43 ` Köry Maincent
2024-03-09 8:44 ` [PATCH RFC v2 6/6] tools: ynl: ethtool.py: Output timestamping statistics from tsinfo-get operation Rahul Rameshbabu
2024-03-12 23:55 ` Jakub Kicinski
2024-03-14 0:22 ` Rahul Rameshbabu
2024-03-14 0:47 ` Jakub Kicinski
2024-03-14 6:07 ` Rahul Rameshbabu
2024-03-14 18:05 ` Jakub Kicinski
2024-03-14 18:39 ` Rahul Rameshbabu
2024-03-14 20:04 ` Jakub Kicinski
2024-03-14 20:05 ` Rahul Rameshbabu
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=20240309084440.299358-2-rrameshbabu@nvidia.com \
--to=rrameshbabu@nvidia.com \
--cc=ahmed.zaki@intel.com \
--cc=aleksander.lobakin@intel.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew@lunn.ch \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=hkallweit1@gmail.com \
--cc=jacob.e.keller@intel.com \
--cc=jiri@resnulli.us \
--cc=joabreu@synopsys.com \
--cc=justinstitt@google.com \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuhangbin@gmail.com \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=paul.greenwalt@intel.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=rdunlap@infradead.org \
--cc=richardcochran@gmail.com \
--cc=saeed@kernel.org \
--cc=tariqt@nvidia.com \
--cc=vadim.fedorenko@linux.dev \
--cc=vladimir.oltean@nxp.com \
--cc=wojciech.drewek@intel.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).