netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v4 5/5] Implement ndo_hwtstamp_get/set methods in netdevsim driver
@ 2023-04-23  3:29 Maxim Georgiev
  2023-05-02  9:42 ` Jiri Pirko
  0 siblings, 1 reply; 3+ messages in thread
From: Maxim Georgiev @ 2023-04-23  3:29 UTC (permalink / raw)
  To: kory.maincent
  Cc: kuba, netdev, glipus, maxime.chevallier, vladimir.oltean,
	vadim.fedorenko, richardcochran, gerhard

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 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.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH v4 5/5] Implement ndo_hwtstamp_get/set methods in netdevsim driver
  2023-04-23  3:29 [RFC PATCH v4 5/5] Implement ndo_hwtstamp_get/set methods in netdevsim driver Maxim Georgiev
@ 2023-05-02  9:42 ` Jiri Pirko
  2023-05-03  5:24   ` Max Georgiev
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Pirko @ 2023-05-02  9:42 UTC (permalink / raw)
  To: Maxim Georgiev
  Cc: kory.maincent, kuba, netdev, maxime.chevallier, vladimir.oltean,
	vadim.fedorenko, richardcochran, gerhard

Sun, Apr 23, 2023 at 05:29:08AM CEST, glipus@gmail.com wrote:
>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>

You need to bundle selftest using this feature in to patch.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH v4 5/5] Implement ndo_hwtstamp_get/set methods in netdevsim driver
  2023-05-02  9:42 ` Jiri Pirko
@ 2023-05-03  5:24   ` Max Georgiev
  0 siblings, 0 replies; 3+ messages in thread
From: Max Georgiev @ 2023-05-03  5:24 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: kory.maincent, kuba, netdev, maxime.chevallier, vladimir.oltean,
	vadim.fedorenko, richardcochran, gerhard

On Tue, May 2, 2023 at 3:42 AM Jiri Pirko <jiri@resnulli.us> wrote:
>
> Sun, Apr 23, 2023 at 05:29:08AM CEST, glipus@gmail.com wrote:
> >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>
>
> You need to bundle selftest using this feature in to patch.

Yes, Jakub mentioned that, but I didn't get to it.
Thank you for pointing it out! I'll add the selftest.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-03  5:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-23  3:29 [RFC PATCH v4 5/5] Implement ndo_hwtstamp_get/set methods in netdevsim driver Maxim Georgiev
2023-05-02  9:42 ` Jiri Pirko
2023-05-03  5:24   ` Max Georgiev

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).