All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Georgiev <glipus@gmail.com>
To: kory.maincent@bootlin.com
Cc: kuba@kernel.org, netdev@vger.kernel.org, glipus@gmail.com,
	maxime.chevallier@bootlin.com, vladimir.oltean@nxp.com,
	vadim.fedorenko@linux.dev, richardcochran@gmail.com,
	gerhard@engleder-embedded.com, liuhangbin@gmail.com
Subject: [RFC PATCH net-next v6 5/5] netdevsim: Implement ndo_hwtstamp_get/set methods in netdevsim driver
Date: Mon,  1 May 2023 22:31:50 -0600	[thread overview]
Message-ID: <20230502043150.17097-6-glipus@gmail.com> (raw)
In-Reply-To: <20230502043150.17097-1-glipus@gmail.com>

Implementing ndo_hwtstamp_get/set methods in netdevsim driver
to use the newly introduced ndo_hwtstamp_get/setmake it respond to
 SIOCGHWTSTAMP/SIOCSHWTSTAMP IOCTLs.
 Also adding .get_ts_info ethtool method allowing to monitor
 HW timestamp configuration values set using SIOCSHWTSTAMP·IOCTL.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Maxim Georgiev <glipus@gmail.com>
---

Notes:
  Changes in v6:
  - Patch title was updated. No code changes.
  Changes in V4:
  - Implemented .get_ts_info·ethtool·method.
  - Tested the patch using  hwstamp_ctl and ethtool:

[root@centosvm kernel-net-next]# ethtool -T eni0np1
Time stamping parameters for eni0np1:
Capabilities:
        software-transmit
        software-receive
        software-system-clock
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes: none
Hardware Receive Filter Modes: none
[root@centosvm kernel-net-next]# hwstamp_ctl -i eni0np1 -t 1 -r 0
current settings:
tx_type 0
rx_filter 0
new settings:
tx_type 1
rx_filter 0
[root@centosvm kernel-net-next]# ethtool -T eni0np1
Time stamping parameters for eni0np1:
Capabilities:
        software-transmit
        software-receive
        software-system-clock
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes:
        off
Hardware Receive Filter Modes: none
[root@centosvm kernel-net-next]# hwstamp_ctl -i eni0np1 -t 1 -r 14
current settings:
tx_type 1
rx_filter 0
new settings:
tx_type 1
rx_filter 14
[root@centosvm kernel-net-next]# ethtool -T eni0np1
Time stamping parameters for eni0np1:
Capabilities:
        software-transmit
        software-receive
        software-system-clock
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes:
        off
Hardware Receive Filter Modes:
        all
        some
        ptpv1-l4-event
---
 drivers/net/netdevsim/ethtool.c   | 11 +++++++++++
 drivers/net/netdevsim/netdev.c    | 24 ++++++++++++++++++++++++
 drivers/net/netdevsim/netdevsim.h |  1 +
 3 files changed, 36 insertions(+)

diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c
index ffd9f84b6644..cbb8e261b759 100644
--- a/drivers/net/netdevsim/ethtool.c
+++ b/drivers/net/netdevsim/ethtool.c
@@ -140,6 +140,16 @@ nsim_set_fecparam(struct net_device *dev, struct ethtool_fecparam *fecparam)
 	return 0;
 }
 
+static int nsim_get_ts_info(struct net_device *netdev,
+			    struct ethtool_ts_info *info)
+{
+	struct netdevsim *ns = netdev_priv(netdev);
+
+	info->tx_types = ns->hw_tstamp_config.tx_type;
+	info->rx_filters = ns->hw_tstamp_config.rx_filter;
+	return ethtool_op_get_ts_info(netdev, info);
+}
+
 static const struct ethtool_ops nsim_ethtool_ops = {
 	.supported_coalesce_params	= ETHTOOL_COALESCE_ALL_PARAMS,
 	.get_pause_stats	        = nsim_get_pause_stats,
@@ -153,6 +163,7 @@ static const struct ethtool_ops nsim_ethtool_ops = {
 	.set_channels			= nsim_set_channels,
 	.get_fecparam			= nsim_get_fecparam,
 	.set_fecparam			= nsim_set_fecparam,
+	.get_ts_info			= nsim_get_ts_info,
 };
 
 static void nsim_ethtool_ring_init(struct netdevsim *ns)
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 35fa1ca98671..6c29dfa3bb4e 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -238,6 +238,28 @@ nsim_set_features(struct net_device *dev, netdev_features_t features)
 	return 0;
 }
 
+static int
+nsim_hwtstamp_get(struct net_device *dev,
+		  struct kernel_hwtstamp_config *kernel_config,
+		  struct netlink_ext_ack *extack)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	*kernel_config = ns->hw_tstamp_config;
+	return 0;
+}
+
+static int
+nsim_hwtstamp_set(struct net_device *dev,
+		  struct kernel_hwtstamp_config *kernel_config,
+		  struct netlink_ext_ack *extack)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	ns->hw_tstamp_config = *kernel_config;
+	return 0;
+}
+
 static const struct net_device_ops nsim_netdev_ops = {
 	.ndo_start_xmit		= nsim_start_xmit,
 	.ndo_set_rx_mode	= nsim_set_rx_mode,
@@ -256,6 +278,8 @@ static const struct net_device_ops nsim_netdev_ops = {
 	.ndo_setup_tc		= nsim_setup_tc,
 	.ndo_set_features	= nsim_set_features,
 	.ndo_bpf		= nsim_bpf,
+	.ndo_hwtstamp_get	= nsim_hwtstamp_get,
+	.ndo_hwtstamp_set	= nsim_hwtstamp_set,
 };
 
 static const struct net_device_ops nsim_vf_netdev_ops = {
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 7d8ed8d8df5c..e78e88a0baa1 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -102,6 +102,7 @@ struct netdevsim {
 	} udp_ports;
 
 	struct nsim_ethtool ethtool;
+	struct kernel_hwtstamp_config hw_tstamp_config;
 };
 
 struct netdevsim *
-- 
2.40.1


  parent reply	other threads:[~2023-05-02  4:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02  4:31 [RFC PATCH net-next v6 0/5] New NDO methods ndo_hwtstamp_get/set Maxim Georgiev
2023-05-02  4:31 ` [RFC PATCH net-next v6 1/5] net: Add NDOs for hardware timestamp get/set Maxim Georgiev
2023-05-11 12:32   ` Vladimir Oltean
2023-05-12  3:22     ` Max Georgiev
2023-05-12 17:41       ` Jakub Kicinski
2023-05-15 15:36         ` Max Georgiev
2023-05-02  4:31 ` [RFC PATCH net-next v6 2/5] net: Add ifreq pointer field to kernel_hwtstamp_config structure Maxim Georgiev
2023-05-04  3:05   ` Jakub Kicinski
2023-05-04 15:21     ` Max Georgiev
2023-05-04 15:41       ` Jakub Kicinski
2023-05-11  9:30   ` Vladimir Oltean
2023-05-02  4:31 ` [RFC PATCH net-next v6 3/5] vlan/macvlan: Add ndo_hwtstamp_get/set support to vlan/macvlan code path Maxim Georgiev
2023-05-02  4:31 ` [RFC PATCH net-next v6 4/5] bond: Add ndo_hwtstamp_get/set support to bond driver Maxim Georgiev
2023-05-02  4:31 ` Maxim Georgiev [this message]
2023-06-21  2:23 ` [RFC PATCH net-next v6 0/5] New NDO methods ndo_hwtstamp_get/set Jakub Kicinski
2023-07-01 10:03   ` Vladimir Oltean
2023-07-01 14:51     ` Max Georgiev

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=20230502043150.17097-6-glipus@gmail.com \
    --to=glipus@gmail.com \
    --cc=gerhard@engleder-embedded.com \
    --cc=kory.maincent@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=liuhangbin@gmail.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=vladimir.oltean@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.