Subject: Re: [patch net-next-2.6 1/2] net: allow to change carrier via sysfs

From: Nicolas de Pesloüan<[email-masked]>
Date: Wed, 31 Aug 2011 22:03:40 +0200

Le 31/08/2011 10:45, Jiri Pirko a écrit :

>>>> Do you expect drivers using implementation different than just calling
>>>> netif_carrier_on/off? Or is it supposed to also e.g. power down PHYs?
>>> Yes, generally it can be used also for en/disable phy, for testing
>>> purposes if hw and driver would support it.
>>
>> I'd like to see this working for GRE tunnel devices (for keepalive
>> daemon to be able to indicate to routing daemons whether tunnel is
>> really working) - implementation would be identical to dummy's case.
>> Should I prepare a patch or can I leave it to you?
>
> Ok, I can include it to this patchset (I'm going to repost first patch
> anyway)

Can't we assume that the dummy's case is the default behavior and register this default 
ndo_change_carrier callback for every device ?

Device drivers willing to do something different can install a different callback if appropriate.

This would avoid duplicating the following code in most drivers, that don't need something special.

static int dummy_change_carrier(struct net_device *dev, bool new_carrier)
{
	if (new_carrier)
		netif_carrier_on(dev);
	else
		netif_carrier_off(dev);
	return 0;
}

If someone is not confident with this default callback registered for all device, at least, we can 
put this code in a common place, so that a driver willing to use it doesn't need to have its own 
version of it.

	Nicolas.