netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chaitanya Lala <clala@riverbed.com>
To: jeffrey.t.kirsher@intel.com
Cc: netdev@vger.kernel.org
Subject: [net-next PATCH 1/1] e1000e: Expose MDI-X state via sysfs
Date: Tue, 19 May 2009 14:05:53 -0700	[thread overview]
Message-ID: <20090519210553.GA2491@clala-laptop> (raw)

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 <clala@riverbed.com>
Signed-off-by: Arthur Jones <ajones@riverbed.com>
---
 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.
-- 
1.6.0.4


             reply	other threads:[~2009-05-19 21:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-19 21:05 Chaitanya Lala [this message]
2009-05-19 21:55 ` [net-next PATCH 1/1] e1000e: Expose MDI-X state via sysfs Jeff Kirsher
2009-05-19 22:22   ` Chaitanya Lala
2009-05-19 23:45     ` Brandeburg, Jesse
2009-05-20 17:14       ` Chaitanya Lala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090519210553.GA2491@clala-laptop \
    --to=clala@riverbed.com \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).