diff mbox

[net-next,5/7] qlcnic: fix default operating state of interface

Message ID 1308256659-19895-5-git-send-email-anirban.chakraborty@qlogic.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Anirban Chakraborty June 16, 2011, 8:37 p.m. UTC
From: Amit Kumar Salecha <amit.salecha@qlogic.com>

Currently interface shows status as RUNNING, even if there is no link.
To fix this, netif_carrier_off should be called after register_netdev().

netif_carrier_off calls linkwatch_fire_event(dev); only if netdev is registered,
otherwise it skips. linkwatch_fire_event set default state of nic interface.

Signed-off-by: Amit Kumar Salecha <amit.salecha@qlogic.com>
Signed-off-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
---
 drivers/net/qlcnic/qlcnic_main.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Comments

David Miller June 17, 2011, 4:10 a.m. UTC | #1
From: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
Date: Thu, 16 Jun 2011 13:37:36 -0700

> From: Amit Kumar Salecha <amit.salecha@qlogic.com>
> 
> Currently interface shows status as RUNNING, even if there is no link.
> To fix this, netif_carrier_off should be called after register_netdev().
> 
> netif_carrier_off calls linkwatch_fire_event(dev); only if netdev is registered,
> otherwise it skips. linkwatch_fire_event set default state of nic interface.
> 
> Signed-off-by: Amit Kumar Salecha <amit.salecha@qlogic.com>
> Signed-off-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>

You cannot do this.

The exact second that register_netdev() is called, the device can
be brought up asynchronously and the link brought into the up state.

Your netif_carrier_off() call will race with this.

This is why no other (properly functioning) driver does what you're
trying to do here.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
stephen hemminger June 17, 2011, 7 p.m. UTC | #2
On Fri, 17 Jun 2011 00:10:35 -0400 (EDT)
David Miller <davem@davemloft.net> wrote:

> From: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
> Date: Thu, 16 Jun 2011 13:37:36 -0700
> 
> > From: Amit Kumar Salecha <amit.salecha@qlogic.com>
> > 
> > Currently interface shows status as RUNNING, even if there is no link.
> > To fix this, netif_carrier_off should be called after register_netdev().
> > 
> > netif_carrier_off calls linkwatch_fire_event(dev); only if netdev is registered,
> > otherwise it skips. linkwatch_fire_event set default state of nic interface.
> > 
> > Signed-off-by: Amit Kumar Salecha <amit.salecha@qlogic.com>
> > Signed-off-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
> 
> You cannot do this.
> 
> The exact second that register_netdev() is called, the device can
> be brought up asynchronously and the link brought into the up state.
> 
> Your netif_carrier_off() call will race with this.
> 
> This is why no other (properly functioning) driver does what you're
> trying to do here.

The proper place to do this is in the open() routine.
When device is not open, the carrier state is undefined; and devices
that are trying to save power turn off PHY when device is not in use.

Therefore the open() routine should ensure that the carrier is in
the proper state when returning. Just doing something like:

static int qlcnic_open() {
...
	netif_carrier_off()

        err = __qlcnic_up();
	...
}

static int __qlcnic_up() {
	...
	(lots of tests)
	...

        netif_carrier_on();
	adapter->reset_context = 0;
	set_bit(__QLCNIC_DEV_UP, &adapter->state);
	return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Anirban Chakraborty June 20, 2011, 4:14 a.m. UTC | #3
On Jun 16, 2011, at 9:10 PM, David Miller wrote:

> From: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
> Date: Thu, 16 Jun 2011 13:37:36 -0700
> 
>> From: Amit Kumar Salecha <amit.salecha@qlogic.com>
>> 
>> Currently interface shows status as RUNNING, even if there is no link.
>> To fix this, netif_carrier_off should be called after register_netdev().
>> 
>> netif_carrier_off calls linkwatch_fire_event(dev); only if netdev is registered,
>> otherwise it skips. linkwatch_fire_event set default state of nic interface.
>> 
>> Signed-off-by: Amit Kumar Salecha <amit.salecha@qlogic.com>
>> Signed-off-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
> 
> You cannot do this.
> 
> The exact second that register_netdev() is called, the device can
> be brought up asynchronously and the link brought into the up state.
> 
> Your netif_carrier_off() call will race with this.
> 
> This is why no other (properly functioning) driver does what you're
> trying to do here.
> 

We will take care of it. Please ignore the series. 

thanks much,
Anirban



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
amit salecha June 22, 2011, 7:01 a.m. UTC | #4
> -----Original Message-----
> From: Stephen Hemminger [mailto:shemminger@vyatta.com]
> 
> David Miller <davem@davemloft.net> wrote:
> 
> > From: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
> > Date: Thu, 16 Jun 2011 13:37:36 -0700
> >
> > > From: Amit Kumar Salecha <amit.salecha@qlogic.com>
> > >
> > > Currently interface shows status as RUNNING, even if there is no
> link.
> > > To fix this, netif_carrier_off should be called after
> register_netdev().
> > >
> > > netif_carrier_off calls linkwatch_fire_event(dev); only if netdev
> is registered,
> > > otherwise it skips. linkwatch_fire_event set default state of nic
> interface.
> > >
> > > Signed-off-by: Amit Kumar Salecha <amit.salecha@qlogic.com>
> > > Signed-off-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com>
> >
> > You cannot do this.
> >
> > The exact second that register_netdev() is called, the device can
> > be brought up asynchronously and the link brought into the up state.
> >
> > Your netif_carrier_off() call will race with this.
> >
> > This is why no other (properly functioning) driver does what you're
> > trying to do here.
> 
> The proper place to do this is in the open() routine.
> When device is not open, the carrier state is undefined; and devices
> that are trying to save power turn off PHY when device is not in use.
> 
> Therefore the open() routine should ensure that the carrier is in
> the proper state when returning. Just doing something like:
> 
> static int qlcnic_open() {
> ...
> 	netif_carrier_off()
> 
>         err = __qlcnic_up();
> 	...
> }
> 
> static int __qlcnic_up() {
> 	...
> 	(lots of tests)
> 	...
> 
>         netif_carrier_on();
> 	adapter->reset_context = 0;
> 	set_bit(__QLCNIC_DEV_UP, &adapter->state);
> 	return 0;
> }

netif_carrier_off() is ok, should be call from qlcnic_open().
netif_carrier_on() will be call during asynchronous notification from fw.

-Thanks.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index 8c07c4e..5348dba 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -1485,14 +1485,14 @@  qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
 
 	netdev->irq = adapter->msix_entries[0].vector;
 
-	netif_carrier_off(netdev);
-
 	err = register_netdev(netdev);
 	if (err) {
 		dev_err(&pdev->dev, "failed to register net device\n");
 		return err;
 	}
 
+	netif_carrier_off(netdev);
+
 	return 0;
 }