]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ethtool: Add generic options for tunables
authorGovindarajulu Varadarajan <_govind@gmx.com>
Tue, 2 Sep 2014 21:47:20 +0000 (03:17 +0530)
committerDavid S. Miller <davem@davemloft.net>
Fri, 5 Sep 2014 19:12:20 +0000 (12:12 -0700)
This patch adds new ethtool cmd, ETHTOOL_GTUNABLE & ETHTOOL_STUNABLE for getting
tunable values from driver.

Add get_tunable and set_tunable to ethtool_ops. Driver implements these
functions for getting/setting tunable value.

Signed-off-by: Govindarajulu Varadarajan <_govind@gmx.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/ethtool.h
include/uapi/linux/ethtool.h
net/core/ethtool.c

index e658229fee39c17ea8673eadcf7b49cfdce508e1..c1a2d60dfb82769c42b65dc2adc324517ed7e79c 100644 (file)
@@ -257,6 +257,10 @@ struct ethtool_ops {
                                     struct ethtool_eeprom *, u8 *);
        int     (*get_eee)(struct net_device *, struct ethtool_eee *);
        int     (*set_eee)(struct net_device *, struct ethtool_eee *);
+       int     (*get_tunable)(struct net_device *,
+                              const struct ethtool_tunable *, void *);
+       int     (*set_tunable)(struct net_device *,
+                              const struct ethtool_tunable *, const void *);
 
 
 };
index e3c7a719c76b4a586c40da9506adaa095857ede4..7a364f2f3d3faf71a6febe653eed26d24bb79708 100644 (file)
@@ -209,6 +209,32 @@ struct ethtool_value {
        __u32   data;
 };
 
+enum tunable_id {
+       ETHTOOL_ID_UNSPEC,
+       ETHTOOL_RX_COPYBREAK,
+};
+
+enum tunable_type_id {
+       ETHTOOL_TUNABLE_UNSPEC,
+       ETHTOOL_TUNABLE_U8,
+       ETHTOOL_TUNABLE_U16,
+       ETHTOOL_TUNABLE_U32,
+       ETHTOOL_TUNABLE_U64,
+       ETHTOOL_TUNABLE_STRING,
+       ETHTOOL_TUNABLE_S8,
+       ETHTOOL_TUNABLE_S16,
+       ETHTOOL_TUNABLE_S32,
+       ETHTOOL_TUNABLE_S64,
+};
+
+struct ethtool_tunable {
+       __u32   cmd;
+       __u32   id;
+       __u32   type_id;
+       __u32   len;
+       void    *data[0];
+};
+
 /**
  * struct ethtool_regs - hardware register dump
  * @cmd: Command number = %ETHTOOL_GREGS
@@ -1152,6 +1178,8 @@ enum ethtool_sfeatures_retval_bits {
 
 #define ETHTOOL_GRSSH          0x00000046 /* Get RX flow hash configuration */
 #define ETHTOOL_SRSSH          0x00000047 /* Set RX flow hash configuration */
+#define ETHTOOL_GTUNABLE       0x00000048 /* Get tunable configuration */
+#define ETHTOOL_STUNABLE       0x00000049 /* Set tunable configuration */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET         ETHTOOL_GSET
index 17cb912793fa5ef0d221abda0dfb447b216b4268..27e61b886520895995e6e946555b0d766bf4a55e 100644 (file)
@@ -1621,6 +1621,80 @@ static int ethtool_get_module_eeprom(struct net_device *dev,
                                      modinfo.eeprom_len);
 }
 
+static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
+{
+       switch (tuna->id) {
+       case ETHTOOL_RX_COPYBREAK:
+               if (tuna->len != sizeof(u32) ||
+                   tuna->type_id != ETHTOOL_TUNABLE_U32)
+                       return -EINVAL;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
+{
+       int ret;
+       struct ethtool_tunable tuna;
+       const struct ethtool_ops *ops = dev->ethtool_ops;
+       void *data;
+
+       if (!ops->get_tunable)
+               return -EOPNOTSUPP;
+       if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
+               return -EFAULT;
+       ret = ethtool_tunable_valid(&tuna);
+       if (ret)
+               return ret;
+       data = kmalloc(tuna.len, GFP_USER);
+       if (!data)
+               return -ENOMEM;
+       ret = ops->get_tunable(dev, &tuna, data);
+       if (ret)
+               goto out;
+       useraddr += sizeof(tuna);
+       ret = -EFAULT;
+       if (copy_to_user(useraddr, data, tuna.len))
+               goto out;
+       ret = 0;
+
+out:
+       kfree(data);
+       return ret;
+}
+
+static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
+{
+       int ret;
+       struct ethtool_tunable tuna;
+       const struct ethtool_ops *ops = dev->ethtool_ops;
+       void *data;
+
+       if (!ops->set_tunable)
+               return -EOPNOTSUPP;
+       if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
+               return -EFAULT;
+       ret = ethtool_tunable_valid(&tuna);
+       if (ret)
+               return ret;
+       data = kmalloc(tuna.len, GFP_USER);
+       if (!data)
+               return -ENOMEM;
+       useraddr += sizeof(tuna);
+       ret = -EFAULT;
+       if (copy_from_user(data, useraddr, tuna.len))
+               goto out;
+       ret = ops->set_tunable(dev, &tuna, data);
+
+out:
+       kfree(data);
+       return ret;
+}
+
 /* The main entry point in this file.  Called from net/core/dev_ioctl.c */
 
 int dev_ethtool(struct net *net, struct ifreq *ifr)
@@ -1670,6 +1744,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
        case ETHTOOL_GCHANNELS:
        case ETHTOOL_GET_TS_INFO:
        case ETHTOOL_GEEE:
+       case ETHTOOL_GTUNABLE:
                break;
        default:
                if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
@@ -1857,6 +1932,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
        case ETHTOOL_GMODULEEEPROM:
                rc = ethtool_get_module_eeprom(dev, useraddr);
                break;
+       case ETHTOOL_GTUNABLE:
+               rc = ethtool_get_tunable(dev, useraddr);
+               break;
+       case ETHTOOL_STUNABLE:
+               rc = ethtool_set_tunable(dev, useraddr);
+               break;
        default:
                rc = -EOPNOTSUPP;
        }