net: export device speed and duplex via sysfs
authorAndy Gospodarek <andy@greyhouse.net>
Fri, 2 Oct 2009 09:26:12 +0000 (09:26 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 5 Oct 2009 07:43:35 +0000 (00:43 -0700)
commitd519e17e2d01a0ee9abe083019532061b4438065
tree3f90e369fe65ff84dc46ec513f758b51a2834559
parent053a93dd126f68ba37973f95f00af6045fa7c957
net: export device speed and duplex via sysfs

This patch exports the link-speed (in Mbps) and duplex of an interface
via sysfs.  This eliminates the need to use ethtool just to check the
link-speed.  Not requiring 'ethtool' and not relying on the SIOCETHTOOL
ioctl should be helpful in an embedded environment where space is at a
premium as well.

NOTE: This patch also intentionally allows non-root users to check the link
speed and duplex -- something not possible with ethtool.

Here's some sample output:

# cat /sys/class/net/eth0/speed
100
# cat /sys/class/net/eth0/duplex
half
# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  Not reported
        Advertised auto-negotiation: No
        Speed: 100Mb/s
        Duplex: Half
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x000000ff (255)
        Link detected: yes

Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/net-sysfs.c