Commit 409c188c authored by Vincent Mailhol's avatar Vincent Mailhol Committed by Marc Kleine-Budde
Browse files

can: tree-wide: advertise software timestamping capabilities



Currently, some CAN drivers support hardware timestamping, some do
not. But userland has no method to query which features are supported
(aside maybe of getting RX messages and observe whether or not
hardware timestamps stay at zero).

The canonical way for a network driver to advertised what kind of
timestamping it supports is to implement ethtool_ops::get_ts_info().

This patch only targets the CAN drivers which *do not* support
hardware timestamping.  For each of those CAN drivers, implement the
get_ts_info() using the generic ethtool_op_get_ts_info().

This way, userland can do:

| $ ethtool --show-time-stamping canX

to confirm the device timestamping capacities.

N.B. the drivers which support hardware timestamping will be migrated
in separate patches.

Signed-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/all/20220727101641.198847-6-mailhol.vincent@wanadoo.fr


[mkl: mscan: add missing mscan_ethtool_ops]
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 6a37a28b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

#include <linux/clk.h>
#include <linux/errno.h>
#include <linux/ethtool.h>
#include <linux/if_arp.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
@@ -1152,6 +1153,10 @@ static const struct net_device_ops at91_netdev_ops = {
	.ndo_change_mtu = can_change_mtu,
};

static const struct ethtool_ops at91_ethtool_ops = {
	.get_ts_info = ethtool_op_get_ts_info,
};

static ssize_t mb0_id_show(struct device *dev,
			   struct device_attribute *attr, char *buf)
{
@@ -1293,6 +1298,7 @@ static int at91_can_probe(struct platform_device *pdev)
	}

	dev->netdev_ops	= &at91_netdev_ops;
	dev->ethtool_ops = &at91_ethtool_ops;
	dev->irq = irq;
	dev->flags |= IFF_ECHO;

+1 −0
Original line number Diff line number Diff line
@@ -26,4 +26,5 @@ static void c_can_get_ringparam(struct net_device *netdev,

const struct ethtool_ops c_can_ethtool_ops = {
	.get_ringparam = c_can_get_ringparam,
	.get_ts_info = ethtool_op_get_ts_info,
};
+5 −0
Original line number Diff line number Diff line
@@ -850,6 +850,10 @@ static const struct net_device_ops can327_netdev_ops = {
	.ndo_change_mtu = can_change_mtu,
};

static const struct ethtool_ops can327_ethtool_ops = {
	.get_ts_info = ethtool_op_get_ts_info,
};

static bool can327_is_valid_rx_char(u8 c)
{
	static const bool lut_char_is_valid['z'] = {
@@ -1034,6 +1038,7 @@ static int can327_ldisc_open(struct tty_struct *tty)
	/* Configure netdev interface */
	elm->dev = dev;
	dev->netdev_ops = &can327_netdev_ops;
	dev->ethtool_ops = &can327_ethtool_ops;

	/* Mark ldisc channel as alive */
	elm->tty = tty;
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <linux/ptrace.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/ethtool.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/if_ether.h>
@@ -836,6 +837,10 @@ static const struct net_device_ops cc770_netdev_ops = {
	.ndo_change_mtu = can_change_mtu,
};

static const struct ethtool_ops cc770_ethtool_ops = {
	.get_ts_info = ethtool_op_get_ts_info,
};

int register_cc770dev(struct net_device *dev)
{
	struct cc770_priv *priv = netdev_priv(dev);
@@ -846,6 +851,7 @@ int register_cc770dev(struct net_device *dev)
		return err;

	dev->netdev_ops = &cc770_netdev_ops;
	dev->ethtool_ops = &cc770_ethtool_ops;

	dev->flags |= IFF_ECHO;	/* we support local echo */

+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <linux/clk.h>
#include <linux/errno.h>
#include <linux/ethtool.h>
#include <linux/init.h>
#include <linux/bitfield.h>
#include <linux/interrupt.h>
@@ -1301,6 +1302,10 @@ static const struct net_device_ops ctucan_netdev_ops = {
	.ndo_change_mtu	= can_change_mtu,
};

static const struct ethtool_ops ctucan_ethtool_ops = {
	.get_ts_info = ethtool_op_get_ts_info,
};

int ctucan_suspend(struct device *dev)
{
	struct net_device *ndev = dev_get_drvdata(dev);
@@ -1377,6 +1382,7 @@ int ctucan_probe_common(struct device *dev, void __iomem *addr, int irq, unsigne
		set_drvdata_fnc(dev, ndev);
	SET_NETDEV_DEV(ndev, dev);
	ndev->netdev_ops = &ctucan_netdev_ops;
	ndev->ethtool_ops = &ctucan_ethtool_ops;

	/* Getting the can_clk info */
	if (!can_clk_rate) {
Loading