netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2] gianfar: Add gfar_change_carrier() for Fixed PHYs
@ 2018-12-12 12:33 Joakim Tjernlund
  2018-12-12 12:42 ` Andrew Lunn
  2018-12-12 18:34 ` Florian Fainelli
  0 siblings, 2 replies; 8+ messages in thread
From: Joakim Tjernlund @ 2018-12-12 12:33 UTC (permalink / raw)
  To: netdev @ vger . kernel . org, claudiu . manoil @ nxp . com,
	Florian Fainelli, Andrew Lunn
  Cc: Joakim Tjernlund

This allows to control carrier from /sys/class/net/ethX/carrier for
Fixed PHYs.

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@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?

 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;
-- 
2.18.1

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

end of thread, other threads:[~2018-12-12 18:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-12 12:33 [PATCHv2] gianfar: Add gfar_change_carrier() for Fixed PHYs Joakim Tjernlund
2018-12-12 12:42 ` Andrew Lunn
2018-12-12 13:10   ` Claudiu Manoil
2018-12-12 13:30     ` Joakim Tjernlund
2018-12-12 14:25     ` Joakim Tjernlund
2018-12-12 14:51       ` Andrew Lunn
2018-12-12 17:25         ` Joakim Tjernlund
2018-12-12 18:34 ` Florian Fainelli

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