* [PATCH v3 1/2] can: c_can: add ethtool support
@ 2021-05-14 16:55 Dario Binacchi
2021-05-14 17:28 ` Andrew Lunn
2021-05-14 20:40 ` Marc Kleine-Budde
0 siblings, 2 replies; 3+ messages in thread
From: Dario Binacchi @ 2021-05-14 16:55 UTC (permalink / raw)
To: linux-kernel
Cc: Dario Binacchi, Andrew Lunn, David S. Miller, Jakub Kicinski,
Marc Kleine-Budde, Oliver Hartkopp, Vincent Mailhol,
Wolfgang Grandegger, YueHaibing, Zhang Qilong, linux-can, netdev
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.
Signed-off-by: Dario Binacchi <dariobin@libero.it>
---
Changes in v3:
- Remove the version info so that ethtool will return the version of the
kernel the driver is actually being used in.
Changes in v2:
- Use get_ringparam instead of get_channels.
drivers/net/can/c_can/Makefile | 3 ++
drivers/net/can/c_can/c_can.h | 2 +
drivers/net/can/c_can/c_can_ethtool.c | 43 +++++++++++++++++++
.../net/can/c_can/{c_can.c => c_can_main.c} | 1 +
4 files changed, 49 insertions(+)
create mode 100644 drivers/net/can/c_can/c_can_ethtool.c
rename drivers/net/can/c_can/{c_can.c => c_can_main.c} (99%)
diff --git a/drivers/net/can/c_can/Makefile b/drivers/net/can/c_can/Makefile
index e6a94c948531..ac2bca39d6ff 100644
--- a/drivers/net/can/c_can/Makefile
+++ b/drivers/net/can/c_can/Makefile
@@ -4,5 +4,8 @@
#
obj-$(CONFIG_CAN_C_CAN) += c_can.o
+
+c_can-objs := c_can_main.o c_can_ethtool.o
+
obj-$(CONFIG_CAN_C_CAN_PLATFORM) += c_can_platform.o
obj-$(CONFIG_CAN_C_CAN_PCI) += c_can_pci.o
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 06045f610f0e..f9001072514a 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -219,4 +219,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
index 000000000000..6e50308c3aac
--- /dev/null
+++ b/drivers/net/can/c_can/c_can_ethtool.c
@@ -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;
+}
diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can_main.c
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 313793f6922d..1903b87d5384 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can_main.c
@@ -1335,6 +1335,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)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 1/2] can: c_can: add ethtool support
2021-05-14 16:55 [PATCH v3 1/2] can: c_can: add ethtool support Dario Binacchi
@ 2021-05-14 17:28 ` Andrew Lunn
2021-05-14 20:40 ` Marc Kleine-Budde
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2021-05-14 17:28 UTC (permalink / raw)
To: Dario Binacchi
Cc: linux-kernel, David S. Miller, Jakub Kicinski, Marc Kleine-Budde,
Oliver Hartkopp, Vincent Mailhol, Wolfgang Grandegger,
YueHaibing, Zhang Qilong, linux-can, netdev
On Fri, May 14, 2021 at 06:55:47PM +0200, Dario Binacchi wrote:
> 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.
>
> Signed-off-by: Dario Binacchi <dariobin@libero.it>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 1/2] can: c_can: add ethtool support
2021-05-14 16:55 [PATCH v3 1/2] can: c_can: add ethtool support Dario Binacchi
2021-05-14 17:28 ` Andrew Lunn
@ 2021-05-14 20:40 ` Marc Kleine-Budde
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-05-14 20:40 UTC (permalink / raw)
To: Dario Binacchi
Cc: linux-kernel, Andrew Lunn, David S. Miller, Jakub Kicinski,
Oliver Hartkopp, Vincent Mailhol, Wolfgang Grandegger,
YueHaibing, Zhang Qilong, linux-can, netdev
[-- Attachment #1: Type: text/plain, Size: 697 bytes --]
On 14.05.2021 18:55:47, Dario Binacchi wrote:
> 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.
>
> Signed-off-by: Dario Binacchi <dariobin@libero.it>
Applied to linux-can-next/testing
Thanks,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-14 20:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 16:55 [PATCH v3 1/2] can: c_can: add ethtool support Dario Binacchi
2021-05-14 17:28 ` Andrew Lunn
2021-05-14 20:40 ` Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).