xref: /linux/drivers/net/can/c_can/c_can_ethtool.c (revision bdd1a21b52557ea8f61d0a5dc2f77151b576eb70)
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 }
44