Skip to contentSkip to conversation

RFC new ethtool command

PATCH Andy Fleming 3 participants 4 messages Mar 1, 2005 – Mar 2, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

I propose adding a new command to ethtool which allows ethernet drivers to specify a command list. A command list would consist of a name/value pair, conforming to the cmdline_info structure already present in ethtool. I see two immediate benefits of this system:

1) controllers which have "cutting-edge", or at least unusual, features can easily add support for these features. As an example, the 85xx allows the ethernet controller's DMA engine to allocate and/or lock buffer descriptors into the L2 cache of the processor. Using this method, a command could be created which is specific to that driver which allows users to turn this feature on or off.

2) When debugging a new driver, or a new feature for an old driver, it is easy to add a quick interface to change the testing parameters without having to add new /proc entries.

Three patches follow; the first allows ethtool to use this new feature, the second allows the kernel to invoke the new feature, and the third is an example of how the gianfar driver uses this feature to expose failure testing features in the PHY-level code (note that this third patch is not a final version. It also contains a few elements from the PHY abstraction patch, which can be ignored for the purposes of this discussion).

Andy Fleming
Open Source Software
Freescale Semiconductor, Inc

drivers/net/gianfar_ethtool.c 2005-02-28 17:57:34 -06:00 +107 -19
diff -Nru a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
@@ -118,6 +116,12 @@
        "tx-fragmented-frames",
 };
 
+static struct cmdline_info gfar_xcmds[] = {
+       {"phytest", CMDL_BOOL, NULL, NULL},
+       {"ptest_reg", CMDL_INT, NULL, NULL},
+       {"ptest_read", CMDL_BOOL, NULL, NULL},
+};
+
 /* Fill in an array of 64-bit statistics from various sources.
  * This array will be appended to the end of the ethtool_stats
  * structure, and returned to user space
@@ -179,34 +183,75 @@
        drvinfo->testinfo_len = 0;
        drvinfo->regdump_len = 0;
        drvinfo->eedump_len = 0;
+       drvinfo->n_xcmds = (sizeof(gfar_xcmds)/sizeof(gfar_xcmds[0]));
+}
+
+
+static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+       struct gfar_private *priv = netdev_priv(dev);
+       struct phy_device *phydev = priv->phydev;
+
+       if (NULL == phydev)
+               return -ENODEV;
+
+       /* We make sure that we don't pass unsupported
+        * values in to the PHY */
+       cmd->advertising &= phydev->supported;
+
+       /* Verify the settings we care about. */
+       if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE)
+               return -EINVAL;
+
+       if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0)
+               return -EINVAL;
+
+       if (cmd->autoneg == AUTONEG_DISABLE
+                       && ((cmd->speed != SPEED_1000
+                                       && cmd->speed != SPEED_100
+                                       && cmd->speed != SPEED_10)
+                               || (cmd->duplex != DUPLEX_HALF 
+                                       && cmd->duplex != DUPLEX_FULL)))
+               return -EINVAL;
+
+       phydev->autoneg = cmd->autoneg;
+
+       phydev->speed = cmd->speed;
+
+       phydev->advertising = cmd->advertising;
+
+       if (AUTONEG_ENABLE == cmd->autoneg)
+               phydev->advertising |= ADVERTISED_Autoneg;
+       else
+               phydev->advertising &= ~ADVERTISED_Autoneg;
+
+       phydev->duplex = cmd->duplex;
+
+       /* Restart the PHY */
+       phy_start_aneg(phydev);
+
+       return 0;
 }
 
 /* Return the current settings in the ethtool_cmd structure */
 int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct gfar_private *priv = netdev_priv(dev);
-       uint gigabit_support = 
-               priv->einfo->flags & GFAR_HAS_GIGABIT ? SUPPORTED_1000baseT_Full : 0;
-       uint gigabit_advert = 
-               priv->einfo->flags & GFAR_HAS_GIGABIT ? ADVERTISED_1000baseT_Full: 0;
-
-       cmd->supported = (SUPPORTED_10baseT_Half
-                         | SUPPORTED_100baseT_Half
-                         | SUPPORTED_100baseT_Full
-                         | gigabit_support | SUPPORTED_Autoneg);
-
-       /* For now, we always advertise everything */
-       cmd->advertising = (ADVERTISED_10baseT_Half
-                           | ADVERTISED_100baseT_Half
-                           | ADVERTISED_100baseT_Full
-                           | gigabit_advert | ADVERTISED_Autoneg);
+       struct phy_device *phydev = priv->phydev;
+
+       if (NULL == phydev)
+               return -ENODEV;
+
+       cmd->supported = phydev->supported;
+
+       cmd->advertising = phydev->advertising;
 
-       cmd->speed = priv->mii_info->speed;
-       cmd->duplex = priv->mii_info->duplex;
+       cmd->speed = phydev->speed;
+       cmd->duplex = phydev->duplex;
        cmd->port = PORT_MII;
-       cmd->phy_address = priv->mii_info->mii_id;
+       cmd->phy_address = phydev->addr;
        cmd->transceiver = XCVR_EXTERNAL;
-       cmd->autoneg = AUTONEG_ENABLE;
+       cmd->autoneg = phydev->autoneg;
        cmd->maxtxpkt = priv->txcount;
        cmd->maxrxpkt = priv->rxcount;
 
@@ -461,7 +512,33 @@
        return err;
 }
 
+static void gfar_gxcmds(struct net_device *dev,
+               struct ethtool_xcmd *xcmd, void *data)
+{
+       memcpy(data, &gfar_xcmds, sizeof(gfar_xcmds));
+}
+
+static void gfar_gxvals(struct net_device *dev,
+               struct ethtool_xcmd *xcmd, void *data)
+{
+       struct gfar_private *priv = netdev_priv(dev);
+
+       memcpy(data, &priv->xvals, sizeof(struct gfar_xvals));
+}
+
+static void gfar_sxvals(struct net_device *dev, struct ethtool_xcmd *xcmd)
+{
+       struct gfar_private *priv = netdev_priv(dev);
+       struct gfar_xvals *xvals = (struct gfar_xvals *)&(xcmd->data[0]);
+
+       priv->xvals = *xvals;
+
+       gfar_phy_test(priv->mii_bus, priv->phydev, xvals->phytest, 
+                       xvals->ptest_reg, xvals->ptest_read);
+}
+
 struct ethtool_ops gfar_ethtool_ops = {
+       .set_settings = gfar_ssettings,
        .get_settings = gfar_gsettings,
        .get_drvinfo = gfar_gdrvinfo,
        .get_regs_len = gfar_reglen,
@@ -474,9 +551,13 @@
        .get_strings = gfar_gstrings,
        .get_stats_count = gfar_stats_count,
        .get_ethtool_stats = gfar_fill_stats,
+       .get_ethtool_xcmds = gfar_gxcmds,
+       .get_ethtool_xcmd_vals = gfar_gxvals,
+       .set_ethtool_xcmd_vals = gfar_sxvals,
 };
 
 struct ethtool_ops gfar_normon_nocoalesce_ethtool_ops = {
+       .set_settings = gfar_ssettings,
        .get_settings = gfar_gsettings,
        .get_drvinfo = gfar_gdrvinfo,
        .get_regs_len = gfar_reglen,
@@ -487,9 +568,13 @@
        .get_strings = gfar_gstrings_normon,
        .get_stats_count = gfar_stats_count_normon,
        .get_ethtool_stats = gfar_fill_stats_normon,
+       .get_ethtool_xcmds = gfar_gxcmds,
+       .get_ethtool_xcmd_vals = gfar_gxvals,
+       .set_ethtool_xcmd_vals = gfar_sxvals,
 };
 
 struct ethtool_ops gfar_nocoalesce_ethtool_ops = {
+       .set_settings = gfar_ssettings,
        .get_settings = gfar_gsettings,
        .get_drvinfo = gfar_gdrvinfo,
        .get_regs_len = gfar_reglen,
@@ -500,9 +585,13 @@
        .get_strings = gfar_gstrings,
        .get_stats_count = gfar_stats_count,
        .get_ethtool_stats = gfar_fill_stats,
+       .get_ethtool_xcmds = gfar_gxcmds,
+       .get_ethtool_xcmd_vals = gfar_gxvals,
+       .set_ethtool_xcmd_vals = gfar_sxvals,
 };
 
 struct ethtool_ops gfar_normon_ethtool_ops = {
+       .set_settings = gfar_ssettings,
        .get_settings = gfar_gsettings,
        .get_drvinfo = gfar_gdrvinfo,
        .get_regs_len = gfar_reglen,
@@ -515,6 +604,9 @@
        .get_strings = gfar_gstrings_normon,
        .get_stats_count = gfar_stats_count_normon,
        .get_ethtool_stats = gfar_fill_stats_normon,
+       .get_ethtool_xcmds = gfar_gxcmds,
+       .get_ethtool_xcmd_vals = gfar_gxvals,
+       .set_ethtool_xcmd_vals = gfar_sxvals,
 };
 
 struct ethtool_ops *gfar_op_array[] = {
net/core/ethtool.c 2005-02-28 17:57:35 -06:00 +104 -0

116 lines not on this page · raw message

include/linux/ethtool.h 2005-02-28 17:57:34 -06:00 +32 -0
diff -Nru a/include/linux/ethtool.h b/include/linux/ethtool.h
@@ -44,6 +44,8 @@
        u32     testinfo_len;
        u32     eedump_len;     /* Size of data from ETHTOOL_GEEPROM (bytes) */
        u32     regdump_len;    /* Size of data from ETHTOOL_GREGS (bytes) */
+       u32     n_xcmds;        /* number of driver-defined commands */
+
 };
 
 #define SOPASS_MAX     6
@@ -215,6 +217,29 @@
        u32     tx_pause;
 };
 
+/* For getting the driver-specified command list, and also for
+ * getting the current values for those commands */
+struct ethtool_xcmd {
+       u32 cmd;
+       u32 nr_xcmds;
+       u8 data[0];
+};
+
+typedef enum {
+       CMDL_NONE,
+       CMDL_BOOL,
+       CMDL_INT,
+} cmdline_type_t;
+
+#define CMDLINE_NAME_LEN 32
+struct cmdline_info {
+       const char name[CMDLINE_NAME_LEN];
+       cmdline_type_t type;
+       void *wanted_val;
+       void *ioctl_val;
+};
+
+
 #define ETH_GSTRING_LEN                32
 enum ethtool_stringset {
        ETH_SS_TEST             = 0,
@@ -351,6 +376,9 @@
        int     (*phys_id)(struct net_device *, u32);
        int     (*get_stats_count)(struct net_device *);
        void    (*get_ethtool_stats)(struct net_device *, struct ethtool_stats *, u64 *);
+       void    (*get_ethtool_xcmds)(struct net_device *, struct ethtool_xcmd *, void *);
+       void    (*get_ethtool_xcmd_vals)(struct net_device *, struct ethtool_xcmd *, void *);
+       void    (*set_ethtool_xcmd_vals)(struct net_device *, struct ethtool_xcmd *);
        int     (*begin)(struct net_device *);
        void    (*complete)(struct net_device *);
 };
@@ -388,6 +416,10 @@
 #define ETHTOOL_GSTATS         0x0000001d /* get NIC-specific statistics */
 #define ETHTOOL_GTSO           0x0000001e /* Get TSO enable (ethtool_value) */
 #define ETHTOOL_STSO           0x0000001f /* Set TSO enable (ethtool_value) */
+#define ETHTOOL_GXCMDS          0x00000020 /* Get XCMD list */
+#define ETHTOOL_GXCMDVALS       0x00000021 /* Get current XCMD values */
+#define ETHTOOL_SXCMDVALS       0x00000022 /* Set current XCMD values */
+
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET         ETHTOOL_GSET

? xcmd.patch
Index: ChangeLog
===================================================================
RCS file: /cvsroot/gkernel/ethtool/ChangeLog,v
retrieving revision 1.60

ChangeLog +5 -0
diff -u -r1.60 ChangeLog
@@ -1,3 +1,8 @@
+Mon Feb 28 2005  Andy Fleming <[email protected]>
+
+	* ethtool.c, ethtool-copy.h: Added a new command (-x)
+	which allows drivers to specify command-line arguments
+
 Tue Aug 17 2004  Jeff Garzik <[email protected]>
 
 	* NEWS, configure.ac:  Release version 2

Index: ethtool-copy.h
===================================================================
RCS file: /cvsroot/gkernel/ethtool/ethtool-copy.h,v retrieving revision 1.13

ethtool-copy.h +12 -0
diff -u -r1.13 ethtool-copy.h
@@ -44,6 +44,7 @@
 	u32	testinfo_len;
 	u32	eedump_len;	/* Size of data from ETHTOOL_GEEPROM (bytes) */
 	u32	regdump_len;	/* Size of data from ETHTOOL_GREGS (bytes) */
+	u32	n_xcmds;	/* number of driver-defined commands */
 };
 
 #define SOPASS_MAX	6
@@ -215,6 +216,14 @@
 	u32	tx_pause;
 };
 
+/* For getting the driver-specified command list, and also for getting
+ * the current values for those commands */
+struct ethtool_xcmd {
+	u32 cmd;
+	u32 nr_xcmds;
+	u8 data[0];
+};
+
 #define ETH_GSTRING_LEN		32
 enum ethtool_stringset {
 	ETH_SS_TEST		= 0,
@@ -283,6 +292,9 @@
 #define ETHTOOL_GSTATS		0x0000001d /* get NIC-specific statistics */
 #define ETHTOOL_GTSO		0x0000001e /* Get TSO enable (ethtool_value) */
 #define ETHTOOL_STSO		0x0000001f /* Set TSO enable (ethtool_value) */
+#define ETHTOOL_GXCMDS		0x00000020 /* Get XCMD list */
+#define ETHTOOL_GXCMDVALS	0x00000021 /* Get current XCMD values */
+#define ETHTOOL_SXCMDVALS	0x00000022 /* Set current XCMD values */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET

Index: ethtool.c
===================================================================
RCS file: /cvsroot/gkernel/ethtool/ethtool.c,v
retrieving revision 1.50

ethtool.c +179 -5

267 lines not on this page · raw message

#1 lore raw
Quoted 16 lines · On Tue, 1 Mar 2005 09:22:07 -0600 Andy Fleming <[email protected]> wrote:

I propose adding a new command to ethtool which allows ethernet drivers to specify a command list. A command list would consist of a name/value pair, conforming to the cmdline_info structure already present in ethtool. I see two immediate benefits of this system:

1) controllers which have "cutting-edge", or at least unusual, features can easily add support for these features. As an example, the 85xx allows the ethernet controller's DMA engine to allocate and/or lock buffer descriptors into the L2 cache of the processor. Using this method, a command could be created which is specific to that driver which allows users to turn this feature on or off.

2) When debugging a new driver, or a new feature for an old driver, it is easy to add a quick interface to change the testing parameters without having to add new /proc entries.

Quoted 7 lines

Three patches follow; the first allows ethtool to use this new feature, the second allows the kernel to invoke the new feature, and the third is an example of how the gianfar driver uses this feature to expose failure testing features in the PHY-level code (note that this third patch is not a final version. It also contains a few elements from the PHY abstraction patch, which can be ignored for the purposes of this discussion).

I understand the motivation, but it seems to go against the philosophy of having a general purpose interface. Rather than having device driver specific special cases, why not add useful abstractions for new features. Phy interface testing and management is generic, and several devices could support it.

This proposal is basically a device specific multiplexing interface like ioctl or SIOCDEVPRIVATE. This style of interface is considered bad, and undesirable.

For the first case, of "cutting-edge" controller's, the best solution is to always turn the feature on and make it work correctly. If you can't make it work correctly then use module parameter or chip set detection to turn it off. Another option to expose warts is using sysfs attribute groups to add additional fields to /sys/class/net/ethXX/.

When debugging a new driver, module parameters work find for controlling test parameters. If this needs to make into production code, sysfs could also be used.

#2 lore raw
Quoted 6 lines · Stephen Hemminger

I understand the motivation, but it seems to go against the philosophy of having a general purpose interface. Rather than having device driver specific special cases, why not add useful abstractions for new features. Phy interface testing and management is generic, and several devices could support it.

Ok, I probably shouldn't have mentioned the PHY testing, which was just a hack to inject errors into some code I was working on. My point in this case was it is easy using this method to add temporary debug parameters. I concede that ethtool may not be the best place for debug support.

The problem I'm trying to solve is for the new features I mentioned before. I have an ethernet controller which is part of an SOC, and has access to the L2 cache. As such, the controller can read and write buffer descriptors directly from/to the L2 cache, and even lock them into the L2.

Adding an abstraction for this to ethtool when there's only one driver that uses it seems premature. If no other controllers implement such a feature, then ethtool is cluttered up with what amounts to driver-specific code. If other controllers implement a similar feature, it's quite possible that the abstraction will need to change. Changing the abstraction (or adding a new one) can take up a significant amount of time, since the driver writer now has to modify the ethtool source, the ethtool kernel support, and then get the changes accepted.

I agree that, eventually, it would be the goal to implement an abstraction, and go through the process of getting the changes accepted, but not until there's a "market" for the abstraction.

Quoted 6 lines

For the first case, of "cutting-edge" controller's, the best solution is to always turn the feature on and make it work correctly. If you can't make it work correctly then use module parameter or chip set detection to turn it off. Another option to expose warts is using sysfs attribute groups to add additional fields to /sys/class/net/ethXX/.

Well, some features are a little more complex than on/off. The stashing feature in the 85xx ethernet controllers allows a portion of each incoming packet to be extracted and placed directly in L2. This has performance implications, and so it is useful to be able to tune the parameters at runtime. Especially for benchmarking purposes, but also, once benchmarking has been done, to tune performance to the workload.

Quoted 4 lines

When debugging a new driver, module parameters work find for controlling test parameters. If this needs to make into production code, sysfs could also be used.

Module parameters are fine as long as you aren't trying to root your filesystem over NFS using the driver.

Quoted 4 lines

This proposal is basically a device specific multiplexing interface like ioctl or SIOCDEVPRIVATE. This style of interface is considered bad, and undesirable.

Well, yes... it uses ioctl and SIOCETHTOOL. I can see how sysfs could be used to do everything I'm trying to do. However, the same could be said about everything ethtool does. Is ethtool no longer the correct tool to use for tuning ethernet performance? I'm not philosophically opposed to the idea of supporting these features through sysfs, but it seems easier to be able to point people at ethtool for all their performance tuning needs.

Andy Fleming
Open Source Team
Freescale Semiconductor, Inc

#3 lore raw
In reply to Andy Fleming

Stephen guessed right. We don't need to add yet another "black hole" (a.k.a. untyped / dynamic) userland interface.

One of two directions is suggested:

* Create a generalized interface, and add new ethtool commands.

* Create a driver-specific ioctl, and submit a patch to userland ethtool which supports this. Driver-specific / device-specific code in userland ethtool is acceptable.

Jeff