can: c_can: add ethtool support
authorDario Binacchi <dariobin@libero.it>
Fri, 14 May 2021 16:55:47 +0000 (18:55 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 27 May 2021 07:42:23 +0000 (09:42 +0200)
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>
drivers/net/can/c_can/Makefile
drivers/net/can/c_can/c_can.h
drivers/net/can/c_can/c_can_ethtool.c [new file with mode: 0644]
drivers/net/can/c_can/c_can_main.c [moved from drivers/net/can/c_can/c_can.c with 99% similarity]

index e6a94c9..6fa3b2b 100644 (file)
@@ -4,5 +4,10 @@
 #
 
 obj-$(CONFIG_CAN_C_CAN) += c_can.o
+
+c_can-objs :=
+c_can-objs += c_can_ethtool.o
+c_can-objs += c_can_main.o
+
 obj-$(CONFIG_CAN_C_CAN_PLATFORM) += c_can_platform.o
 obj-$(CONFIG_CAN_C_CAN_PCI) += c_can_pci.o
index 517845c..4247ff8 100644 (file)
@@ -218,4 +218,6 @@ int c_can_power_up(struct net_device *dev);
 int c_can_power_down(struct net_device *dev);
 #endif
 
+void c_can_set_ethtool_ops(struct net_device *dev);
+
 #endif /* C_CAN_H */
diff --git a/drivers/net/can/c_can/c_can_ethtool.c b/drivers/net/can/c_can/c_can_ethtool.c
new file mode 100644 (file)
index 0000000..cd5f07f
--- /dev/null
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2021, Dario Binacchi <dariobin@libero.it>
+ */
+
+#include <linux/ethtool.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/netdevice.h>
+#include <linux/can/dev.h>
+
+#include "c_can.h"
+
+static void c_can_get_drvinfo(struct net_device *netdev,
+                             struct ethtool_drvinfo *info)
+{
+       struct c_can_priv *priv = netdev_priv(netdev);
+       struct platform_device *pdev = to_platform_device(priv->device);
+
+       strscpy(info->driver, "c_can", sizeof(info->driver));
+       strscpy(info->bus_info, pdev->name, sizeof(info->bus_info));
+}
+
+static void c_can_get_ringparam(struct net_device *netdev,
+                               struct ethtool_ringparam *ring)
+{
+       struct c_can_priv *priv = netdev_priv(netdev);
+
+       ring->rx_max_pending = priv->msg_obj_num;
+       ring->tx_max_pending = priv->msg_obj_num;
+       ring->rx_pending = priv->msg_obj_rx_num;
+       ring->tx_pending = priv->msg_obj_tx_num;
+}
+
+static const struct ethtool_ops c_can_ethtool_ops = {
+       .get_drvinfo = c_can_get_drvinfo,
+       .get_ringparam = c_can_get_ringparam,
+};
+
+void c_can_set_ethtool_ops(struct net_device *netdev)
+{
+       netdev->ethtool_ops = &c_can_ethtool_ops;
+}
similarity index 99%
rename from drivers/net/can/c_can/c_can.c
rename to drivers/net/can/c_can/c_can_main.c
index 1fa4796..7588f70 100644 (file)
@@ -1334,6 +1334,7 @@ int register_c_can_dev(struct net_device *dev)
 
        dev->flags |= IFF_ECHO; /* we support local echo */
        dev->netdev_ops = &c_can_netdev_ops;
+       c_can_set_ethtool_ops(dev);
 
        err = register_candev(dev);
        if (!err)