diff mbox series

[net-next] macvlan: Pass SIOC[SG]HWTSTAMP ioctls and get_ts_info to lower device

Message ID 20180118011233.GA14152@HTGD74-02.ds.mot.com
State Rejected, archived
Delegated to: David Miller
Headers show
Series [net-next] macvlan: Pass SIOC[SG]HWTSTAMP ioctls and get_ts_info to lower device | expand

Commit Message

grzegorz.halat@gmail.com Jan. 18, 2018, 1:12 a.m. UTC
This patch allows to enable hardware timestamping on macvlan intefaces and find out capabilities of the lower device.

Signed-off-by: Grzegorz Halat <grzegorz.halat@gmail.com>
---
 drivers/net/macvlan.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

--
2.7.4

Comments

Jiri Benc Jan. 18, 2018, 10:57 a.m. UTC | #1
On Thu, 18 Jan 2018 02:12:34 +0100, grzegorz.halat@gmail.com wrote:
> This patch allows to enable hardware timestamping on macvlan intefaces and find out capabilities of the lower device.
> 
> Signed-off-by: Grzegorz Halat <grzegorz.halat@gmail.com>

NACK. This does not work.

For start, how do you deal with fwd_priv? When a packet is sent to
other software ports, it wouldn't be time stamped. And I expect more
cases like this to be there in macvlan, I only spent 10 seconds
checking it.

Please study how time stamping in the kernel works. A good start is
Documentation/networking/timestamping.txt. Then examine all possible
packet paths with macvlan, both egress and ingress.

> +static int macvlan_ethtool_get_ts_info(struct net_device *dev,
> +					struct ethtool_ts_info *ts_info)
> +{
> +	const struct macvlan_dev *vlan = netdev_priv(dev);
> +	const struct ethtool_ops *eth_ops = vlan->lowerdev->ethtool_ops;
> +
> +	if (eth_ops->get_ts_info)
> +		return eth_ops->get_ts_info(vlan->lowerdev, ts_info);
> +
> +	ts_info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
> +				   SOF_TIMESTAMPING_SOFTWARE;
> +	ts_info->phc_index = -1;

What calls skb_tx_timestamp if the driver does not support it?

 Jiri
diff mbox series

Patch

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index a0f2be8..314e878 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -23,6 +23,7 @@ 
 #include <linux/rculist.h>
 #include <linux/notifier.h>
 #include <linux/netdevice.h>
+#include <linux/net_tstamp.h>
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
 #include <linux/if_arp.h>
@@ -942,6 +943,30 @@  static void macvlan_dev_get_stats64(struct net_device *dev,
	}
 }

+static int macvlan_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
+{
+	struct macvlan_dev *vlan = netdev_priv(dev);
+	const struct net_device_ops *ops = vlan->lowerdev->netdev_ops;
+	struct ifreq ifrl;
+	int err = -EOPNOTSUPP;
+
+	strncpy(ifrl.ifr_name, vlan->lowerdev->name, IFNAMSIZ);
+	ifrl.ifr_ifru = ifr->ifr_ifru;
+
+	switch (cmd) {
+	case SIOCGHWTSTAMP:
+	case SIOCSHWTSTAMP:
+		if (ops->ndo_do_ioctl)
+			err = ops->ndo_do_ioctl(vlan->lowerdev, &ifrl, cmd);
+		break;
+	}
+
+	if (!err)
+		ifr->ifr_ifru = ifrl.ifr_ifru;
+
+	return err;
+}
+
 static int macvlan_vlan_rx_add_vid(struct net_device *dev,
				   __be16 proto, u16 vid)
 {
@@ -1022,6 +1047,22 @@  static int macvlan_ethtool_get_link_ksettings(struct net_device *dev,
	return __ethtool_get_link_ksettings(vlan->lowerdev, cmd);
 }

+static int macvlan_ethtool_get_ts_info(struct net_device *dev,
+					struct ethtool_ts_info *ts_info)
+{
+	const struct macvlan_dev *vlan = netdev_priv(dev);
+	const struct ethtool_ops *eth_ops = vlan->lowerdev->ethtool_ops;
+
+	if (eth_ops->get_ts_info)
+		return eth_ops->get_ts_info(vlan->lowerdev, ts_info);
+
+	ts_info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
+				   SOF_TIMESTAMPING_SOFTWARE;
+	ts_info->phc_index = -1;
+
+	return 0;
+}
+
 static netdev_features_t macvlan_fix_features(struct net_device *dev,
					      netdev_features_t features)
 {
@@ -1096,6 +1137,7 @@  static const struct ethtool_ops macvlan_ethtool_ops = {
	.get_link		= ethtool_op_get_link,
	.get_link_ksettings	= macvlan_ethtool_get_link_ksettings,
	.get_drvinfo		= macvlan_ethtool_get_drvinfo,
+	.get_ts_info		= macvlan_ethtool_get_ts_info,
 };

 static const struct net_device_ops macvlan_netdev_ops = {
@@ -1111,6 +1153,7 @@  static const struct net_device_ops macvlan_netdev_ops = {
	.ndo_set_rx_mode	= macvlan_set_mac_lists,
	.ndo_get_stats64	= macvlan_dev_get_stats64,
	.ndo_validate_addr	= eth_validate_addr,
+	.ndo_do_ioctl		= macvlan_do_ioctl,
	.ndo_vlan_rx_add_vid	= macvlan_vlan_rx_add_vid,
	.ndo_vlan_rx_kill_vid	= macvlan_vlan_rx_kill_vid,
	.ndo_fdb_add		= macvlan_fdb_add,