netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] net: Set NOCARRIER bit of etherdev state at initialization
@ 2014-05-23 17:01 Balakumaran Kannan
  2014-05-23 17:38 ` Dan Williams
  0 siblings, 1 reply; 5+ messages in thread
From: Balakumaran Kannan @ 2014-05-23 17:01 UTC (permalink / raw)
  To: davem, stephen, avi.kp.137, edumazet, netdev

For any etherdev 'netif_carrier_ok' should succeed only after phy
layer determines carrier state through auto-negotiation or setting
it forcibly.

So ethernet drivers should set '__LINK_STATE_NOCARRIER' bit of
'dev->state' using 'netif_carrier_off' call at driver initialization.
As it is common for all ethernet devices, 'netif_carrier_off' call
could be moved to 'ether_setup'.

Signed-off-by: Balakumaran Kannan <kumaran.4353@gmail.com>
---
'netif_carrier_off' could be called anywhere in between
'alloc_etherdev' and 'phy_start'. For example,
1. e1000 driver calls at the end of 'e1000_probe'
2. intel i40e driver calls at the beginning of 'i40e_open'
3. realtek r8169 driver calls at the end of 'rtl_init_one'

But some driver misses this call. For example smsc911x driver doesn't
call 'netif_carrier_off' before calling 'phy_start'. So device starts
performing dhcp and IPv6 DAD even if carrier is not ready.

So it is better to move 'netif_carrier_off' call to 'ether_setup'. And
drivers can remove this call from their initialization functions.
---
 net/ethernet/eth.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 5dc638c..45f6703 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -369,6 +369,9 @@ void ether_setup(struct net_device *dev)
 
 	memset(dev->broadcast, 0xFF, ETH_ALEN);
 
+	/* Carrier state should be off initially */
+	netif_carrier_off(dev);
+
 }
 EXPORT_SYMBOL(ether_setup);
 
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] net: Set NOCARRIER bit of etherdev state at initialization
  2014-05-23 17:01 [PATCH 1/1] net: Set NOCARRIER bit of etherdev state at initialization Balakumaran Kannan
@ 2014-05-23 17:38 ` Dan Williams
  2014-05-23 18:15   ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Williams @ 2014-05-23 17:38 UTC (permalink / raw)
  To: Balakumaran Kannan; +Cc: davem, stephen, avi.kp.137, edumazet, netdev

On Fri, 2014-05-23 at 22:31 +0530, Balakumaran Kannan wrote:
> For any etherdev 'netif_carrier_ok' should succeed only after phy
> layer determines carrier state through auto-negotiation or setting
> it forcibly.
> 
> So ethernet drivers should set '__LINK_STATE_NOCARRIER' bit of
> 'dev->state' using 'netif_carrier_off' call at driver initialization.
> As it is common for all ethernet devices, 'netif_carrier_off' call
> could be moved to 'ether_setup'.

Unless I misunderstand, wouldn't this turn off carrier for all devices
until the driver explicitly sets the carrier up?

The current "carrier on until told otherwise" model is intentional,
because not all drivers support carrier detection, and thus we must
assume the carrier is on until the driver tells us it is not on.

Would this patch break that model?

Dan

> Signed-off-by: Balakumaran Kannan <kumaran.4353@gmail.com>
> ---
> 'netif_carrier_off' could be called anywhere in between
> 'alloc_etherdev' and 'phy_start'. For example,
> 1. e1000 driver calls at the end of 'e1000_probe'
> 2. intel i40e driver calls at the beginning of 'i40e_open'
> 3. realtek r8169 driver calls at the end of 'rtl_init_one'
> 
> But some driver misses this call. For example smsc911x driver doesn't
> call 'netif_carrier_off' before calling 'phy_start'. So device starts
> performing dhcp and IPv6 DAD even if carrier is not ready.
> 
> So it is better to move 'netif_carrier_off' call to 'ether_setup'. And
> drivers can remove this call from their initialization functions.
> ---
>  net/ethernet/eth.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
> index 5dc638c..45f6703 100644
> --- a/net/ethernet/eth.c
> +++ b/net/ethernet/eth.c
> @@ -369,6 +369,9 @@ void ether_setup(struct net_device *dev)
>  
>  	memset(dev->broadcast, 0xFF, ETH_ALEN);
>  
> +	/* Carrier state should be off initially */
> +	netif_carrier_off(dev);
> +
>  }
>  EXPORT_SYMBOL(ether_setup);
>  

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] net: Set NOCARRIER bit of etherdev state at initialization
  2014-05-23 17:38 ` Dan Williams
@ 2014-05-23 18:15   ` David Miller
  2014-05-24 13:22     ` Balakumaran Kannan
  0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2014-05-23 18:15 UTC (permalink / raw)
  To: dcbw; +Cc: kumaran.4353, stephen, avi.kp.137, edumazet, netdev

From: Dan Williams <dcbw@redhat.com>
Date: Fri, 23 May 2014 12:38:01 -0500

> The current "carrier on until told otherwise" model is intentional,
> because not all drivers support carrier detection, and thus we must
> assume the carrier is on until the driver tells us it is not on.
> 
> Would this patch break that model?

Absolutely correct, this change is completely inappropriate.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] net: Set NOCARRIER bit of etherdev state at initialization
  2014-05-23 18:15   ` David Miller
@ 2014-05-24 13:22     ` Balakumaran Kannan
  2014-05-27 15:24       ` Dan Williams
  0 siblings, 1 reply; 5+ messages in thread
From: Balakumaran Kannan @ 2014-05-24 13:22 UTC (permalink / raw)
  To: David Miller
  Cc: dcbw, stephen, Avinash Kumar, Eric Dumazet,
	netdev@vger.kernel.org

On Fri, May 23, 2014 at 11:45 PM, David Miller <davem@davemloft.net> wrote:
> From: Dan Williams <dcbw@redhat.com>
> Date: Fri, 23 May 2014 12:38:01 -0500
>
>> The current "carrier on until told otherwise" model is intentional,
>> because not all drivers support carrier detection, and thus we must
>> assume the carrier is on until the driver tells us it is not on.
>>
>> Would this patch break that model?
>
> Absolutely correct, this change is completely inappropriate.

So it is driver's responsibility to maintain this flag appropriately.
Thus if a driver supports carrier detection, it should set "carrier
on" only after determining the carrier state. Then I'll add
'netif_carrier_off' call to smsc911x driver and send a new patch.

Thanks for the explanation.

Regards,
K.Balakumaran

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/1] net: Set NOCARRIER bit of etherdev state at initialization
  2014-05-24 13:22     ` Balakumaran Kannan
@ 2014-05-27 15:24       ` Dan Williams
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Williams @ 2014-05-27 15:24 UTC (permalink / raw)
  To: Balakumaran Kannan
  Cc: David Miller, stephen, Avinash Kumar, Eric Dumazet,
	netdev@vger.kernel.org

On Sat, 2014-05-24 at 18:52 +0530, Balakumaran Kannan wrote:
> On Fri, May 23, 2014 at 11:45 PM, David Miller <davem@davemloft.net> wrote:
> > From: Dan Williams <dcbw@redhat.com>
> > Date: Fri, 23 May 2014 12:38:01 -0500
> >
> >> The current "carrier on until told otherwise" model is intentional,
> >> because not all drivers support carrier detection, and thus we must
> >> assume the carrier is on until the driver tells us it is not on.
> >>
> >> Would this patch break that model?
> >
> > Absolutely correct, this change is completely inappropriate.
> 
> So it is driver's responsibility to maintain this flag appropriately.
> Thus if a driver supports carrier detection, it should set "carrier
> on" only after determining the carrier state. Then I'll add
> 'netif_carrier_off' call to smsc911x driver and send a new patch.

Correct.  Carrier state starts with ON.  If the driver knows it can
detect carrier state, then the driver should call netif_carrier_off()
early in the driver initialization, and then call on/off as appropriate
when it gets carrier change events.

Dan

> Thanks for the explanation.
> 
> Regards,
> K.Balakumaran
> --
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-05-27 15:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-23 17:01 [PATCH 1/1] net: Set NOCARRIER bit of etherdev state at initialization Balakumaran Kannan
2014-05-23 17:38 ` Dan Williams
2014-05-23 18:15   ` David Miller
2014-05-24 13:22     ` Balakumaran Kannan
2014-05-27 15:24       ` Dan Williams

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).