Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /* Copyright (c) 2022 Amarula Solutions, Dario Binacchi <dario.binacchi@amarulasolutions.com>
0003  *
0004  */
0005 
0006 #include <linux/can/dev.h>
0007 #include <linux/ethtool.h>
0008 #include <linux/kernel.h>
0009 #include <linux/netdevice.h>
0010 #include <linux/platform_device.h>
0011 
0012 #include "slcan.h"
0013 
0014 static const char slcan_priv_flags_strings[][ETH_GSTRING_LEN] = {
0015 #define SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN BIT(0)
0016     "err-rst-on-open",
0017 };
0018 
0019 static void slcan_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
0020 {
0021     switch (stringset) {
0022     case ETH_SS_PRIV_FLAGS:
0023         memcpy(data, slcan_priv_flags_strings,
0024                sizeof(slcan_priv_flags_strings));
0025     }
0026 }
0027 
0028 static u32 slcan_get_priv_flags(struct net_device *ndev)
0029 {
0030     u32 flags = 0;
0031 
0032     if (slcan_err_rst_on_open(ndev))
0033         flags |= SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN;
0034 
0035     return flags;
0036 }
0037 
0038 static int slcan_set_priv_flags(struct net_device *ndev, u32 flags)
0039 {
0040     bool err_rst_op_open = !!(flags & SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN);
0041 
0042     return slcan_enable_err_rst_on_open(ndev, err_rst_op_open);
0043 }
0044 
0045 static int slcan_get_sset_count(struct net_device *netdev, int sset)
0046 {
0047     switch (sset) {
0048     case ETH_SS_PRIV_FLAGS:
0049         return ARRAY_SIZE(slcan_priv_flags_strings);
0050     default:
0051         return -EOPNOTSUPP;
0052     }
0053 }
0054 
0055 const struct ethtool_ops slcan_ethtool_ops = {
0056     .get_strings = slcan_get_strings,
0057     .get_priv_flags = slcan_get_priv_flags,
0058     .set_priv_flags = slcan_set_priv_flags,
0059     .get_sset_count = slcan_get_sset_count,
0060     .get_ts_info = ethtool_op_get_ts_info,
0061 };