Skip to content

Commit b9a0e6f

Browse files
vincent-mailholgregkh
authored andcommitted
can: dev: add generic function can_ethtool_op_get_ts_info_hwts()
[ Upstream commit 7fb48d2 ] Add function can_ethtool_op_get_ts_info_hwts(). This function will be used by CAN devices with hardware TX/RX timestamping support to implement ethtool_ops::get_ts_info. This function does not offer support to activate/deactivate hardware timestamps at device level nor support the filter options (which is currently the case for all CAN devices with hardware timestamping support). The fact that hardware timestamp can not be deactivated at hardware level does not impact the userland. As long as the user do not set SO_TIMESTAMPING using a setsockopt() or ioctl(), the kernel will not emit TX timestamps (RX timestamps will still be reproted as it is the case currently). Drivers which need more fine grained control remains free to implement their own function, but we foresee that the generic function introduced here will be sufficient for the majority. Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Link: https://lore.kernel.org/all/20220727101641.198847-8-mailhol.vincent@wanadoo.fr Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Stable-dep-of: 38c0aba ("can: etas_es58x: populate ndo_change_mtu() to prevent buffer overflow") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 533e322 commit b9a0e6f

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

drivers/net/can/dev/dev.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,27 @@ int can_change_mtu(struct net_device *dev, int new_mtu)
331331
}
332332
EXPORT_SYMBOL_GPL(can_change_mtu);
333333

334+
/* generic implementation of ethtool_ops::get_ts_info for CAN devices
335+
* supporting hardware timestamps
336+
*/
337+
int can_ethtool_op_get_ts_info_hwts(struct net_device *dev,
338+
struct ethtool_ts_info *info)
339+
{
340+
info->so_timestamping =
341+
SOF_TIMESTAMPING_TX_SOFTWARE |
342+
SOF_TIMESTAMPING_RX_SOFTWARE |
343+
SOF_TIMESTAMPING_SOFTWARE |
344+
SOF_TIMESTAMPING_TX_HARDWARE |
345+
SOF_TIMESTAMPING_RX_HARDWARE |
346+
SOF_TIMESTAMPING_RAW_HARDWARE;
347+
info->phc_index = -1;
348+
info->tx_types = BIT(HWTSTAMP_TX_ON);
349+
info->rx_filters = BIT(HWTSTAMP_FILTER_ALL);
350+
351+
return 0;
352+
}
353+
EXPORT_SYMBOL(can_ethtool_op_get_ts_info_hwts);
354+
334355
/* Common open function when the device gets opened.
335356
*
336357
* This function should be called in the open function of the device

include/linux/can/dev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/can/length.h>
2222
#include <linux/can/netlink.h>
2323
#include <linux/can/skb.h>
24+
#include <linux/ethtool.h>
2425
#include <linux/netdevice.h>
2526

2627
/*
@@ -132,6 +133,8 @@ struct can_priv *safe_candev_priv(struct net_device *dev);
132133
int open_candev(struct net_device *dev);
133134
void close_candev(struct net_device *dev);
134135
int can_change_mtu(struct net_device *dev, int new_mtu);
136+
int can_ethtool_op_get_ts_info_hwts(struct net_device *dev,
137+
struct ethtool_ts_info *info);
135138

136139
int register_candev(struct net_device *dev);
137140
void unregister_candev(struct net_device *dev);

0 commit comments

Comments
 (0)