netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matej Zachar <zachar.matej@gmail.com>
To: netdev@vger.kernel.org
Subject: [DSA] fallback PTP to master port when switch does not support it
Date: Mon, 4 Apr 2022 21:28:08 +0200	[thread overview]
Message-ID: <25688175-1039-44C7-A57E-EB93527B1615@gmail.com> (raw)

 Hi,

in my embedded setup I have CPU (master) port with full PTP support connected to the onboard switch (without PTP support) through DSA. As the ioctl and ts_info is passed to the switch driver I made small change to fallback to the master net_device. This however requires that the switch which does not support PTP must not implement .get_ts_info and .port_hwtstamp_get/set from dsa_switch_ops struct.

Do you think this is good approach - I’m happy to work on patch if it makes sense.

I understand that better solution would be to have PTP capable switch, but thats not the situation on this board.

Thank you,
Matej.


diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 65b125bb3b8606e35e5a4a5963c04543266c6114..c78b202e86f3b12d2046de718fd5a1ddcec277cd 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -251,16 +251,25 @@ 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;
+	struct net_device *master = dsa_slave_to_master(dev);
 
 	/* 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);
+
+		if (master->netdev_ops->ndo_do_ioctl)
+			return master->netdev_ops->ndo_do_ioctl(master, ifr, cmd);
+
 		break;
 	case SIOCSHWTSTAMP:
 		if (ds->ops->port_hwtstamp_set)
 			return ds->ops->port_hwtstamp_set(ds, port, ifr);
+
+		if (master->netdev_ops->ndo_do_ioctl)
+			return master->netdev_ops->ndo_do_ioctl(master, ifr, cmd);
+
 		break;
 	}
 
@@ -1292,11 +1303,12 @@ static int dsa_slave_get_ts_info(struct net_device *dev,
 {
 	struct dsa_slave_priv *p = netdev_priv(dev);
 	struct dsa_switch *ds = p->dp->ds;
+	struct net_device *master = dsa_slave_to_master(dev);
 
-	if (!ds->ops->get_ts_info)
-		return -EOPNOTSUPP;
+	if (ds->ops->get_ts_info)
+		return ds->ops->get_ts_info(ds, p->dp->index, ts);
 
-	return ds->ops->get_ts_info(ds, p->dp->index, ts);
+	return master->ethtool_ops->get_ts_info(master, ts);
 }
 
 static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,

             reply	other threads:[~2022-04-04 21:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 19:28 Matej Zachar [this message]
2022-04-04 22:04 ` [DSA] fallback PTP to master port when switch does not support it Andrew Lunn
2022-04-05 14:21   ` Matej Zachar
2022-04-05 19:48   ` Jakub Kicinski
2022-04-07  9:44     ` Vladimir Oltean
2022-05-25 15:00       ` Rodolfo Giometti
2022-05-25 15:55         ` Vladimir Oltean
2022-05-26  7:45           ` Rodolfo Giometti
2022-05-26 12:31             ` Vladimir Oltean
2022-05-25 18:18         ` Andrew Lunn

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=25688175-1039-44C7-A57E-EB93527B1615@gmail.com \
    --to=zachar.matej@gmail.com \
    --cc=netdev@vger.kernel.org \
    /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).