From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Fainelli Subject: Re: [RFC] managing PHY carrier from user space Date: Tue, 11 Sep 2018 09:56:21 -0700 Message-ID: References: <2fcf4c20a9adf410db98706f6f2508e46aade2c1.camel@infinera.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit To: Joakim Tjernlund , "netdev@vger.kernel.org" , "andrew@lunn.ch" Return-path: Received: from mail-wr1-f68.google.com ([209.85.221.68]:36910 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726989AbeIKV4r (ORCPT ); Tue, 11 Sep 2018 17:56:47 -0400 Received: by mail-wr1-f68.google.com with SMTP id u12-v6so26739767wrr.4 for ; Tue, 11 Sep 2018 09:56:34 -0700 (PDT) In-Reply-To: <2fcf4c20a9adf410db98706f6f2508e46aade2c1.camel@infinera.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 09/11/2018 09:41 AM, Joakim Tjernlund wrote: > I am looking for a way to induce carrier state from user space, primarily > for Fixed PHYs as these are always up. ifplugd/dhcp etc. does not behave properly > if the link is up when it really isn't. Was my suggestion in my email to you somehow not working? This is obviously not acceptable for upstream, there is no reason, even for a fixed PHY, to attempt to mangle with the carrier state for any reasonable production purposes. > > I came up with a new 'phy_carrier' attribute in /sys/class/net/eth0/phydev > where I can induce carrier state: > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index a1e7ea4d4b16..f82beeabdd75 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c > @@ -612,10 +612,39 @@ phy_has_fixups_show(struct device *dev, struct device_attribute *attr, > } > static DEVICE_ATTR_RO(phy_has_fixups); > > +static ssize_t > +phy_carrier_show(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + struct phy_device *phydev = to_phy_device(dev); > + struct net_device *netdev = phydev->attached_dev; > + > + return sprintf(buf, "%d\n", netif_carrier_ok(netdev)); > +} > + > +static ssize_t phy_carrier_store(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t len) > +{ > + struct phy_device *phydev = to_phy_device(dev); > + struct net_device *netdev = phydev->attached_dev; > + bool enable; > + > + if (strtobool(buf, &enable)) > + return -EINVAL; > + > + if (enable) > + netif_carrier_on(netdev); > + else > + netif_carrier_off(netdev); > + return len; > +} > +static DEVICE_ATTR_RW(phy_carrier); > + > static struct attribute *phy_dev_attrs[] = { > &dev_attr_phy_id.attr, > &dev_attr_phy_interface.attr, > &dev_attr_phy_has_fixups.attr, > + &dev_attr_phy_carrier.attr, > NULL, > }; > ATTRIBUTE_GROUPS(phy_dev); > > I would like to know if this acceptable for linux proper or if there is > a better way to do this? > > Jocke > -- Florian