From patchwork Tue May 19 21:05:53 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Lala X-Patchwork-Id: 27426 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 1ED84B707D for ; Wed, 20 May 2009 07:15:38 +1000 (EST) Received: by ozlabs.org (Postfix) id 1040BDE140; Wed, 20 May 2009 07:15:38 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id A9E8FDE127 for ; Wed, 20 May 2009 07:15:37 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755141AbZESVPG (ORCPT ); Tue, 19 May 2009 17:15:06 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754675AbZESVPF (ORCPT ); Tue, 19 May 2009 17:15:05 -0400 Received: from smtp2.riverbed.com ([206.169.144.7]:49665 "EHLO smtp2.riverbed.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755089AbZESVPD (ORCPT ); Tue, 19 May 2009 17:15:03 -0400 X-Greylist: delayed 580 seconds by postgrey-1.27 at vger.kernel.org; Tue, 19 May 2009 17:15:03 EDT Received: from unknown (HELO tlssmtp) ([10.16.4.52]) by smtp2.riverbed.com with ESMTP; 19 May 2009 14:05:24 -0700 Received: from localhost (unknown [216.52.20.2]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by tlssmtp (Postfix) with ESMTP id DC3016B8EB; Tue, 19 May 2009 14:20:42 -0700 (PDT) Date: Tue, 19 May 2009 14:05:53 -0700 From: Chaitanya Lala To: jeffrey.t.kirsher@intel.com Cc: netdev@vger.kernel.org Subject: [net-next PATCH 1/1] e1000e: Expose MDI-X state via sysfs Message-ID: <20090519210553.GA2491@clala-laptop> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org While debugging network connectivity problems, it is often helpful to report the MDI-X state. The is_mdix variable holds the current state which we expose on a per-interface basis as a sysfs attribute. We use sysfs over methods such as netlink due to the convenience of reading a file (using the cat command) as opposed to connecting to a netlink socket. If we use a fiber PHY then is_mdix will always be zero as the mdi-x feature only applies to copper PHYs. Signed-off-by: Chaitanya Lala Signed-off-by: Arthur Jones --- drivers/net/e1000e/netdev.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c index ccaaee0..1c131b6 100644 --- a/drivers/net/e1000e/netdev.c +++ b/drivers/net/e1000e/netdev.c @@ -4765,6 +4765,32 @@ static const struct net_device_ops e1000e_netdev_ops = { #endif }; +static ssize_t e1000e_show_is_mdix(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct net_device *netdev = container_of(dev, struct net_device, dev); + struct e1000_adapter *adapter; + struct e1000_hw *hw; + ssize_t ret = -EINVAL; + + if (!buf) + goto err; + + read_lock(&dev_base_lock); + if (NETREG_REGISTERED == netdev->reg_state) { + adapter = netdev_priv(netdev); + hw = &adapter->hw; + ret = sprintf(buf, "%d\n", (hw->phy.is_mdix ? 1 : 0)); + } + read_unlock(&dev_base_lock); +err: + return ret; +} + +/* Export attributes for the device */ +static struct device_attribute device_attr_is_mdix = + __ATTR(is_mdix, S_IRUGO, e1000e_show_is_mdix, NULL); + /** * e1000_probe - Device Initialization Routine * @pdev: PCI device information struct @@ -5046,6 +5072,10 @@ static int __devinit e1000_probe(struct pci_dev *pdev, if (err) goto err_register; + err = device_create_file(&netdev->dev, &device_attr_is_mdix); + if (err) + goto err_sys_attr; + /* carrier off reporting is important to ethtool even BEFORE open */ netif_carrier_off(netdev); @@ -5053,6 +5083,9 @@ static int __devinit e1000_probe(struct pci_dev *pdev, return 0; +err_sys_attr: + unregister_netdev(netdev); + err_register: if (!(adapter->flags & FLAG_HAS_AMT)) e1000_release_hw_control(adapter); @@ -5105,6 +5138,8 @@ static void __devexit e1000_remove(struct pci_dev *pdev) flush_scheduled_work(); + device_remove_file(&netdev->dev, &device_attr_is_mdix); + /* * Release control of h/w to f/w. If f/w is AMT enabled, this * would have already happened in close and is redundant.