Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: c_can: add ethtool support

With commit 132f2d45fb23 ("can: c_can: add support to 64 message
objects") the number of message objects used for reception /
transmission depends on FIFO size.

The ethtools API support allows you to retrieve this info. Driver info
has been added too.

Link: https://lore.kernel.org/r/20210514165549.14365-2-dariobin@libero.it
Signed-off-by: Dario Binacchi <dariobin@libero.it>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Dario Binacchi and committed by
Marc Kleine-Budde
2722ac98 c7b0f688

+51
+5
drivers/net/can/c_can/Makefile
··· 4 4 # 5 5 6 6 obj-$(CONFIG_CAN_C_CAN) += c_can.o 7 + 8 + c_can-objs := 9 + c_can-objs += c_can_ethtool.o 10 + c_can-objs += c_can_main.o 11 + 7 12 obj-$(CONFIG_CAN_C_CAN_PLATFORM) += c_can_platform.o 8 13 obj-$(CONFIG_CAN_C_CAN_PCI) += c_can_pci.o
+1
drivers/net/can/c_can/c_can.c drivers/net/can/c_can/c_can_main.c
··· 1334 1334 1335 1335 dev->flags |= IFF_ECHO; /* we support local echo */ 1336 1336 dev->netdev_ops = &c_can_netdev_ops; 1337 + c_can_set_ethtool_ops(dev); 1337 1338 1338 1339 err = register_candev(dev); 1339 1340 if (!err)
+2
drivers/net/can/c_can/c_can.h
··· 218 218 int c_can_power_down(struct net_device *dev); 219 219 #endif 220 220 221 + void c_can_set_ethtool_ops(struct net_device *dev); 222 + 221 223 #endif /* C_CAN_H */
+43
drivers/net/can/c_can/c_can_ethtool.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright 2021, Dario Binacchi <dariobin@libero.it> 4 + */ 5 + 6 + #include <linux/ethtool.h> 7 + #include <linux/kernel.h> 8 + #include <linux/platform_device.h> 9 + #include <linux/netdevice.h> 10 + #include <linux/can/dev.h> 11 + 12 + #include "c_can.h" 13 + 14 + static void c_can_get_drvinfo(struct net_device *netdev, 15 + struct ethtool_drvinfo *info) 16 + { 17 + struct c_can_priv *priv = netdev_priv(netdev); 18 + struct platform_device *pdev = to_platform_device(priv->device); 19 + 20 + strscpy(info->driver, "c_can", sizeof(info->driver)); 21 + strscpy(info->bus_info, pdev->name, sizeof(info->bus_info)); 22 + } 23 + 24 + static void c_can_get_ringparam(struct net_device *netdev, 25 + struct ethtool_ringparam *ring) 26 + { 27 + struct c_can_priv *priv = netdev_priv(netdev); 28 + 29 + ring->rx_max_pending = priv->msg_obj_num; 30 + ring->tx_max_pending = priv->msg_obj_num; 31 + ring->rx_pending = priv->msg_obj_rx_num; 32 + ring->tx_pending = priv->msg_obj_tx_num; 33 + } 34 + 35 + static const struct ethtool_ops c_can_ethtool_ops = { 36 + .get_drvinfo = c_can_get_drvinfo, 37 + .get_ringparam = c_can_get_ringparam, 38 + }; 39 + 40 + void c_can_set_ethtool_ops(struct net_device *netdev) 41 + { 42 + netdev->ethtool_ops = &c_can_ethtool_ops; 43 + }