* [PATCHv1] forcedeth: Allow ethtool to enable/disable loopback.
@ 2011-05-04 1:22 Mahesh Bandewar
2011-05-05 1:36 ` [PATCHv2] " Mahesh Bandewar
0 siblings, 1 reply; 3+ messages in thread
From: Mahesh Bandewar @ 2011-05-04 1:22 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Tom Herbert, Mahesh Bandewar
This patch updates nv_set_features() to handle loopback mode.
When enabled; it sets internal-PHY loopback.
Signed-off-by: Mahesh Bandewar <maheshb@google.com>
---
drivers/net/forcedeth.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 55 insertions(+), 1 deletions(-)
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index d09e8b0..10d522e 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -4474,6 +4474,53 @@ static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam*
return 0;
}
+static int nv_set_loopback(struct net_device *dev, u32 features)
+{
+ struct fe_priv *np = netdev_priv(dev);
+ unsigned long flags;
+ u32 miicontrol;
+ int err, retval = 0;
+
+ spin_lock_irqsave(&np->lock, flags);
+ miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
+ if (features & NETIF_F_LOOPBACK) {
+ if (miicontrol & BMCR_LOOPBACK) {
+ spin_unlock_irqrestore(&np->lock, flags);
+ return retval;
+ }
+ nv_disable_irq(dev);
+ /* Turn on loopback mode */
+ miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX;
+ err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol);
+ if (err) {
+ retval = -EAGAIN;
+ spin_unlock_irqrestore(&np->lock, flags);
+ phy_init(dev);
+ } else {
+ /* Force link up */
+ netif_carrier_on(dev);
+ spin_unlock_irqrestore(&np->lock, flags);
+ netdev_info(dev, "Internal PHY loopback mode enabled.\n");
+ }
+ } else {
+ if (!(miicontrol & BMCR_LOOPBACK)) {
+ spin_unlock_irqrestore(&np->lock, flags);
+ return retval;
+ }
+ nv_disable_irq(dev);
+ /* Turn off loopback */
+ spin_unlock_irqrestore(&np->lock, flags);
+ netdev_info(dev, "Internal PHY loopback mode disabled.\n");
+ phy_init(dev);
+ }
+ msleep(500);
+ spin_lock_irqsave(&np->lock, flags);
+ nv_enable_irq(dev);
+ spin_unlock_irqrestore(&np->lock, flags);
+
+ return retval;
+}
+
static u32 nv_fix_features(struct net_device *dev, u32 features)
{
/* vlan is dependent on rx checksum offload */
@@ -4488,6 +4535,7 @@ static int nv_set_features(struct net_device *dev, u32 features)
struct fe_priv *np = netdev_priv(dev);
u8 __iomem *base = get_hwbase(dev);
u32 changed = dev->features ^ features;
+ int retval = 0;
if (changed & NETIF_F_RXCSUM) {
spin_lock_irq(&np->lock);
@@ -4502,8 +4550,11 @@ static int nv_set_features(struct net_device *dev, u32 features)
spin_unlock_irq(&np->lock);
}
+ if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
+ retval = nv_set_loopback(dev, features);
+ }
- return 0;
+ return retval;
}
static int nv_get_sset_count(struct net_device *dev, int sset)
@@ -5341,6 +5392,9 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
dev->features |= dev->hw_features;
}
+ /* Add loopback capability to the device. */
+ dev->hw_features |= NETIF_F_LOOPBACK;
+
np->vlanctl_bits = 0;
if (id->driver_data & DEV_HAS_VLAN) {
np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
--
1.7.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCHv2] forcedeth: Allow ethtool to enable/disable loopback.
2011-05-04 1:22 [PATCHv1] forcedeth: Allow ethtool to enable/disable loopback Mahesh Bandewar
@ 2011-05-05 1:36 ` Mahesh Bandewar
2011-05-08 22:57 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Mahesh Bandewar @ 2011-05-05 1:36 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Tom Herbert, Mahesh Bandewar
This patch updates nv_set_features() to handle loopback mode.
When enabled; it sets internal-PHY loopback.
Signed-off-by: Mahesh Bandewar <maheshb@google.com>
---
Changes since v1:
Clear the loopback bit in ndo_open callback to avoid features discrepancy.
drivers/net/forcedeth.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index d09e8b0..55eb558 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -4474,6 +4474,53 @@ static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam*
return 0;
}
+static int nv_set_loopback(struct net_device *dev, u32 features)
+{
+ struct fe_priv *np = netdev_priv(dev);
+ unsigned long flags;
+ u32 miicontrol;
+ int err, retval = 0;
+
+ spin_lock_irqsave(&np->lock, flags);
+ miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
+ if (features & NETIF_F_LOOPBACK) {
+ if (miicontrol & BMCR_LOOPBACK) {
+ spin_unlock_irqrestore(&np->lock, flags);
+ return retval;
+ }
+ nv_disable_irq(dev);
+ /* Turn on loopback mode */
+ miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX;
+ err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol);
+ if (err) {
+ err = -EAGAIN;
+ spin_unlock_irqrestore(&np->lock, flags);
+ phy_init(dev);
+ } else {
+ /* Force link up */
+ netif_carrier_on(dev);
+ spin_unlock_irqrestore(&np->lock, flags);
+ netdev_info(dev, "Internal PHY loopback mode enabled.\n");
+ }
+ } else {
+ if (!(miicontrol & BMCR_LOOPBACK)) {
+ spin_unlock_irqrestore(&np->lock, flags);
+ return retval;
+ }
+ nv_disable_irq(dev);
+ /* Turn off loopback */
+ spin_unlock_irqrestore(&np->lock, flags);
+ netdev_info(dev, "Internal PHY loopback mode disabled.\n");
+ phy_init(dev);
+ }
+ msleep(500);
+ spin_lock_irqsave(&np->lock, flags);
+ nv_enable_irq(dev);
+ spin_unlock_irqrestore(&np->lock, flags);
+
+ return retval;
+}
+
static u32 nv_fix_features(struct net_device *dev, u32 features)
{
/* vlan is dependent on rx checksum offload */
@@ -4502,6 +4549,9 @@ static int nv_set_features(struct net_device *dev, u32 features)
spin_unlock_irq(&np->lock);
}
+ if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
+ nv_set_loopback(dev, features);
+ }
return 0;
}
@@ -5142,6 +5192,14 @@ static int nv_open(struct net_device *dev)
spin_unlock_irq(&np->lock);
+ /* If the loopback feature was set while the device was down, make sure
+ * that it's cleared to avoid any discrepancy in features reporting.
+ */
+ if (dev->features & NETIF_F_LOOPBACK) {
+ dev->features &= ~NETIF_F_LOOPBACK;
+ dev->wanted_features &= ~NETIF_F_LOOPBACK;
+ }
+
return 0;
out_drain:
nv_drain_rxtx(dev);
@@ -5341,6 +5399,9 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
dev->features |= dev->hw_features;
}
+ /* Add loopback capability to the device. */
+ dev->hw_features |= NETIF_F_LOOPBACK;
+
np->vlanctl_bits = 0;
if (id->driver_data & DEV_HAS_VLAN) {
np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
--
1.7.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCHv2] forcedeth: Allow ethtool to enable/disable loopback.
2011-05-05 1:36 ` [PATCHv2] " Mahesh Bandewar
@ 2011-05-08 22:57 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2011-05-08 22:57 UTC (permalink / raw)
To: maheshb; +Cc: netdev, therbert
From: Mahesh Bandewar <maheshb@google.com>
Date: Wed, 4 May 2011 18:36:40 -0700
> @@ -4502,6 +4549,9 @@ static int nv_set_features(struct net_device *dev, u32 features)
>
> spin_unlock_irq(&np->lock);
> }
> + if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
> + nv_set_loopback(dev, features);
> + }
>
Please do not create a braced basic block just for a single
line of code. Simply:
> + if ((changed & NETIF_F_LOOPBACK) && netif_running(dev))
> + nv_set_loopback(dev, features);
is sufficient.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-05-08 22:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-04 1:22 [PATCHv1] forcedeth: Allow ethtool to enable/disable loopback Mahesh Bandewar
2011-05-05 1:36 ` [PATCHv2] " Mahesh Bandewar
2011-05-08 22:57 ` David Miller
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).