net: add unknown state to sysfs NIC duplex export
authorNikolay Aleksandrov <naleksan@redhat.com>
Wed, 5 Sep 2012 04:11:28 +0000 (04:11 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 5 Sep 2012 21:40:07 +0000 (17:40 -0400)
Currently when the NIC duplex state is DUPLEX_UNKNOWN it is exported as
full through sysfs, this patch adds support for DUPLEX_UNKNOWN. It is
handled the same way as in ethtool.

Signed-off-by: Nikolay Aleksandrov <naleksan@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/net-sysfs.c

index 72607174ea5a4af158855f588b767b5c4c86d973..bcf02f608cbfa76ad06da490f2dbf423e728fc17 100644 (file)
@@ -166,9 +166,21 @@ static ssize_t show_duplex(struct device *dev,
 
        if (netif_running(netdev)) {
                struct ethtool_cmd cmd;
-               if (!__ethtool_get_settings(netdev, &cmd))
-                       ret = sprintf(buf, "%s\n",
-                                     cmd.duplex ? "full" : "half");
+               if (!__ethtool_get_settings(netdev, &cmd)) {
+                       const char *duplex;
+                       switch (cmd.duplex) {
+                       case DUPLEX_HALF:
+                               duplex = "half";
+                               break;
+                       case DUPLEX_FULL:
+                               duplex = "full";
+                               break;
+                       default:
+                               duplex = "unknown";
+                               break;
+                       }
+                       ret = sprintf(buf, "%s\n", duplex);
+               }
        }
        rtnl_unlock();
        return ret;