netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: netdev <netdev@vger.kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
	sean.wang@mediatek.com, Woojung.Huh@microchip.com,
	john@phrozen.org, jbe@pengutronix.de, richardcochran@gmail.com,
	Brandon Streiff <brandon.streiff@ni.com>,
	Andrew Lunn <andrew@lunn.ch>
Subject: [RFC PATCH 07/10] net: dsa: forward hardware timestamping ioctls to switch driver
Date: Sat,  3 Feb 2018 22:40:11 +0100	[thread overview]
Message-ID: <1517694016-6692-8-git-send-email-andrew@lunn.ch> (raw)
In-Reply-To: <1517694016-6692-1-git-send-email-andrew@lunn.ch>

From: Brandon Streiff <brandon.streiff@ni.com>

This patch adds support to the dsa slave network device so that
switch drivers can implement the SIOC[GS]HWTSTAMP ioctls and the
ethtool timestamp-info interface.

Signed-off-by: Brandon Streiff <brandon.streiff@ni.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 include/net/dsa.h | 15 +++++++++++++++
 net/dsa/slave.c   | 29 +++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 6cb602dd970c..4c0df83dddaf 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -19,6 +19,7 @@
 #include <linux/workqueue.h>
 #include <linux/of.h>
 #include <linux/ethtool.h>
+#include <linux/net_tstamp.h>
 #include <net/devlink.h>
 #include <net/switchdev.h>
 
@@ -367,6 +368,12 @@ struct dsa_switch_ops {
 	int	(*set_wol)(struct dsa_switch *ds, int port,
 			   struct ethtool_wolinfo *w);
 
+	/*
+	 * ethtool timestamp info
+	 */
+	int	(*get_ts_info)(struct dsa_switch *ds, int port,
+			       struct ethtool_ts_info *ts);
+
 	/*
 	 * Suspend and resume
 	 */
@@ -469,6 +476,14 @@ struct dsa_switch_ops {
 					 int port, struct net_device *br);
 	void	(*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index,
 					  int port, struct net_device *br);
+
+	/*
+	 * PTP functionality
+	 */
+	int	(*port_hwtstamp_get)(struct dsa_switch *ds, int port,
+				     struct ifreq *ifr);
+	int	(*port_hwtstamp_set)(struct dsa_switch *ds, int port,
+				     struct ifreq *ifr);
 };
 
 struct dsa_switch_driver {
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index f52307296de4..935d93f0d36c 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -255,6 +255,22 @@ dsa_slave_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
 
 static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
+	struct dsa_slave_priv *p = netdev_priv(dev);
+	struct dsa_switch *ds = p->dp->ds;
+	int port = p->dp->index;
+
+	/* Pass through to switch driver if it supports timestamping */
+	switch (cmd) {
+	case SIOCGHWTSTAMP:
+		if (ds->ops->port_hwtstamp_get)
+			return ds->ops->port_hwtstamp_get(ds, port, ifr);
+		break;
+	case SIOCSHWTSTAMP:
+		if (ds->ops->port_hwtstamp_set)
+			return ds->ops->port_hwtstamp_set(ds, port, ifr);
+		break;
+	}
+
 	if (!dev->phydev)
 		return -ENODEV;
 
@@ -918,6 +934,18 @@ static int dsa_slave_set_rxnfc(struct net_device *dev,
 	return ds->ops->set_rxnfc(ds, dp->index, nfc);
 }
 
+static int dsa_slave_get_ts_info(struct net_device *dev,
+				 struct ethtool_ts_info *ts)
+{
+	struct dsa_slave_priv *p = netdev_priv(dev);
+	struct dsa_switch *ds = p->dp->ds;
+
+	if (!ds->ops->get_ts_info)
+		return -EOPNOTSUPP;
+
+	return ds->ops->get_ts_info(ds, p->dp->index, ts);
+}
+
 static const struct ethtool_ops dsa_slave_ethtool_ops = {
 	.get_drvinfo		= dsa_slave_get_drvinfo,
 	.get_regs_len		= dsa_slave_get_regs_len,
@@ -938,6 +966,7 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
 	.set_link_ksettings	= phy_ethtool_set_link_ksettings,
 	.get_rxnfc		= dsa_slave_get_rxnfc,
 	.set_rxnfc		= dsa_slave_set_rxnfc,
+	.get_ts_info		= dsa_slave_get_ts_info,
 };
 
 /* legacy way, bypassing the bridge *****************************************/
-- 
2.15.1

  parent reply	other threads:[~2018-02-03 21:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-03 21:40 [RFC PATCH 00/10] PTP support for DSA and mv88e6xxx driver Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 01/10] net: ptp: Add stub for ptp_classify_raw() Andrew Lunn
2018-02-04  9:34   ` Sergei Shtylyov
2018-02-03 21:40 ` [RFC PATCH 02/10] net: dsa: mv88e6xxx: export g2 register accessors Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 03/10] net: dsa: mv88e6xxx: add accessors for PTP/TAI registers Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 04/10] net: dsa: mv88e6xxx: expose switch time as a PTP hardware clock Andrew Lunn
2018-02-09 20:33   ` Richard Cochran
2018-02-09 21:04     ` Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 05/10] net: dsa: mv88e6xxx: add support for GPIO configuration Andrew Lunn
2018-02-04 19:53   ` Florian Fainelli
2018-02-04 20:17     ` Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 06/10] net: dsa: mv88e6xxx: add support for event capture Andrew Lunn
2018-02-03 21:40 ` Andrew Lunn [this message]
2018-02-03 21:40 ` [RFC PATCH 08/10] net: dsa: forward timestamping callbacks to switch drivers Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 09/10] net: dsa: mv88e6xxx: add rx/tx timestamping support Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 10/10] net: dsa: mv88e6xxx: add workaround for 6341 timestamping Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 11/12] net: dsa: mv88e6xxx: Release mutex between each statistics read Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 12/12] net: dsa: mv88e6xxx: Release mutex between each ATU read Andrew Lunn
2018-02-06 19:44 ` [RFC PATCH 00/10] PTP support for DSA and mv88e6xxx driver Brandon Streiff

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=1517694016-6692-8-git-send-email-andrew@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=Woojung.Huh@microchip.com \
    --cc=brandon.streiff@ni.com \
    --cc=f.fainelli@gmail.com \
    --cc=jbe@pengutronix.de \
    --cc=john@phrozen.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=sean.wang@mediatek.com \
    --cc=vivien.didelot@savoirfairelinux.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).