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 	strscpy(info->driver, "c_can", sizeof(info->driver));
19 	strscpy(info->bus_info, dev_name(priv->device), sizeof(info->bus_info));
20 }
21 
22 static void c_can_get_ringparam(struct net_device *netdev,
23 				struct ethtool_ringparam *ring,
24 				struct kernel_ethtool_ringparam *kernel_ring,
25 				struct netlink_ext_ack *extack)
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