On 12/12/18 4:33 AM, Joakim Tjernlund wrote: > This allows to control carrier from /sys/class/net/ethX/carrier for > Fixed PHYs. > > Signed-off-by: Joakim Tjernlund <joakim.tjernl...@infinera.com> > --- > v2 - Only allow carrier changes for Fixed PHYs > > Florian: I have reimpl. this as I think you meant by registering > a Fixed PHY callback. > Andrew: Are happy with this as well?
Yes that is exactly what I had in mind, thanks for listening and translating that into code :) Looking forward to the generic version being submitted. Thanks! > > If this is OK I will sent the other 2 drivers. > > drivers/net/ethernet/freescale/gianfar.c | 26 ++++++++++++++++++++++++ > drivers/net/ethernet/freescale/gianfar.h | 2 +- > 2 files changed, 27 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/freescale/gianfar.c > b/drivers/net/ethernet/freescale/gianfar.c > index 63daae120b2d..49971093e10f 100644 > --- a/drivers/net/ethernet/freescale/gianfar.c > +++ b/drivers/net/ethernet/freescale/gianfar.c > @@ -491,7 +491,28 @@ static int gfar_set_mac_addr(struct net_device *dev, > void *p) > > return 0; > } > +static int gfar_fixed_phy_link_update(struct net_device *dev, > + struct fixed_phy_status *status) > +{ > + struct gfar_private *priv; > + > + if (dev && dev->phydev && status) { > + priv = netdev_priv(dev); > + status->link = !priv->no_carrier; > + } > + return 0; > +} > +static int gfar_change_carrier(struct net_device *dev, bool new_carrier) > +{ > + struct phy_device *phydev = dev->phydev; > + struct gfar_private *priv; > > + if (!phy_is_pseudo_fixed_link(phydev)) > + return -EINVAL; > + priv = netdev_priv(dev); > + priv->no_carrier = !new_carrier; > + return 0; > +} > static const struct net_device_ops gfar_netdev_ops = { > .ndo_open = gfar_enet_open, > .ndo_start_xmit = gfar_start_xmit, > @@ -502,6 +523,7 @@ static const struct net_device_ops gfar_netdev_ops = { > .ndo_tx_timeout = gfar_timeout, > .ndo_do_ioctl = gfar_ioctl, > .ndo_get_stats = gfar_get_stats, > + .ndo_change_carrier = gfar_change_carrier, > .ndo_set_mac_address = gfar_set_mac_addr, > .ndo_validate_addr = eth_validate_addr, > #ifdef CONFIG_NET_POLL_CONTROLLER > @@ -1807,6 +1829,10 @@ static int init_phy(struct net_device *dev) > return -ENODEV; > } > > + if (phy_is_pseudo_fixed_link(phydev)) > + fixed_phy_set_link_update(phydev, > + gfar_fixed_phy_link_update); > + > if (interface == PHY_INTERFACE_MODE_SGMII) > gfar_configure_serdes(dev); > > diff --git a/drivers/net/ethernet/freescale/gianfar.h > b/drivers/net/ethernet/freescale/gianfar.h > index 5aa814799d70..94a64d2dcc6f 100644 > --- a/drivers/net/ethernet/freescale/gianfar.h > +++ b/drivers/net/ethernet/freescale/gianfar.h > @@ -1158,7 +1158,7 @@ struct gfar_private { > int oldspeed; > int oldduplex; > int oldlink; > - > + bool no_carrier; > uint32_t msg_enable; > > struct work_struct reset_task; > -- Florian