* [RFC] managing PHY carrier from user space
@ 2018-09-11 16:41 Joakim Tjernlund
2018-09-11 16:56 ` Florian Fainelli
0 siblings, 1 reply; 3+ messages in thread
From: Joakim Tjernlund @ 2018-09-11 16:41 UTC (permalink / raw)
To: netdev@vger.kernel.org, f.fainelli@gmail.com, andrew@lunn.ch
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.
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC] managing PHY carrier from user space
2018-09-11 16:41 [RFC] managing PHY carrier from user space Joakim Tjernlund
@ 2018-09-11 16:56 ` Florian Fainelli
2018-09-11 19:21 ` Joakim Tjernlund
0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2018-09-11 16:56 UTC (permalink / raw)
To: Joakim Tjernlund, netdev@vger.kernel.org, andrew@lunn.ch
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC] managing PHY carrier from user space
2018-09-11 16:56 ` Florian Fainelli
@ 2018-09-11 19:21 ` Joakim Tjernlund
0 siblings, 0 replies; 3+ messages in thread
From: Joakim Tjernlund @ 2018-09-11 19:21 UTC (permalink / raw)
To: netdev@vger.kernel.org, f.fainelli@gmail.com, andrew@lunn.ch
On Tue, 2018-09-11 at 09:56 -0700, Florian Fainelli wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
>
> 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.
Ohh, I never got that mail. Scanning the netdev archives I found it though, thanks.
I will go down the ndo_change_carrier() way and see whether I can work out what to
do w.r.t fixed link status callback.
Thanks
Jocke
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-09-12 0:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-11 16:41 [RFC] managing PHY carrier from user space Joakim Tjernlund
2018-09-11 16:56 ` Florian Fainelli
2018-09-11 19:21 ` Joakim Tjernlund
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).