[U-Boot] [U-boot] [Patch v2 5/5] net: keystone_net: use general get link function

Ivan Khoronzhuk ivan.khoronzhuk at ti.com
Mon Sep 29 22:25:36 CEST 2014


The phy framework has function to get link, so use it
instead of own implementation.

There is no reason to check SGMII link while sending each
packet, phy link is enough. Check SGMII link only while
ethernet open.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk at ti.com>
---
 arch/arm/include/asm/ti-common/keystone_net.h |  1 +
 drivers/net/keystone_net.c                    | 41 +++++++++++----------------
 2 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/ti-common/keystone_net.h b/arch/arm/include/asm/ti-common/keystone_net.h
index e56759d..011c03c 100644
--- a/arch/arm/include/asm/ti-common/keystone_net.h
+++ b/arch/arm/include/asm/ti-common/keystone_net.h
@@ -239,6 +239,7 @@ struct eth_priv_t {
 	int phy_addr;
 	int slave_port;
 	int sgmii_link_type;
+	struct phy_device *phy_dev;
 };
 
 int keystone2_emac_initialize(struct eth_priv_t *eth_priv);
diff --git a/drivers/net/keystone_net.c b/drivers/net/keystone_net.c
index 5789045..e3268da 100644
--- a/drivers/net/keystone_net.c
+++ b/drivers/net/keystone_net.c
@@ -42,12 +42,6 @@ struct rx_buff_desc net_rx_buffs = {
 
 static void keystone2_net_serdes_setup(void);
 
-static int gen_get_link_speed(int phy_addr);
-
-/* EMAC Addresses */
-static volatile struct mdio_regs	*adap_mdio =
-	(struct mdio_regs *)EMAC_MDIO_BASE_ADDR;
-
 int keystone2_eth_read_mac_addr(struct eth_device *dev)
 {
 	struct eth_priv_t *eth_priv;
@@ -141,19 +135,6 @@ static int keystone2_mdio_write(struct mii_dev *bus,
 	return 0;
 }
 
-/* PHY functions for a generic PHY */
-static int gen_get_link_speed(int phy_addr)
-{
-	u_int16_t tmp;
-
-	tmp = mdio_bus->read(mdio_bus, phy_addr,
-			     MDIO_DEVAD_NONE, MII_STATUS_REG);
-	if (tmp & 0x04)
-		return 0;
-
-	return -1;
-}
-
 static void  __attribute__((unused))
 	keystone2_eth_gigabit_enable(struct eth_device *dev)
 {
@@ -184,13 +165,15 @@ int keystone_sgmii_link_status(int port)
 
 	status = __raw_readl(SGMII_STATUS_REG(port));
 
-	return status & SGMII_REG_STATUS_LINK;
+	return (status & SGMII_REG_STATUS_LOCK) &&
+	       (status & SGMII_REG_STATUS_LINK);
 }
 
 
 int keystone_get_link_status(struct eth_device *dev)
 {
 	struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv;
+	struct phy_device *phy_dev = eth_priv->phy_dev;
 	int sgmii_link;
 	int link_state = 0;
 #if CONFIG_GET_LINK_STATUS_ATTEMPTS > 1
@@ -206,8 +189,8 @@ int keystone_get_link_status(struct eth_device *dev)
 			link_state = 1;
 
 			if (eth_priv->sgmii_link_type == SGMII_LINK_MAC_PHY)
-				if (gen_get_link_speed(eth_priv->phy_addr))
-					link_state = 0;
+				if (!genphy_update_link(phy_dev))
+					link_state = phy_dev->link;
 		}
 #if CONFIG_GET_LINK_STATUS_ATTEMPTS > 1
 	}
@@ -491,9 +474,15 @@ static int keystone2_eth_send_packet(struct eth_device *dev,
 {
 	int ret_status = -1;
 	struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv;
+	struct phy_device *phy_dev = eth_priv->phy_dev;
 
-	if (keystone_get_link_status(dev) == 0)
+	if (phy_dev) {
+		genphy_update_link(phy_dev);
+		if (phy_dev->link == 0)
+			return -1;
+	} else {
 		return -1;
+	}
 
 	if (cpmac_drv_send((u32 *)packet, length, eth_priv->slave_port) != 0)
 		return ret_status;
@@ -569,10 +558,12 @@ int keystone2_emac_initialize(struct eth_priv_t *eth_priv)
 		phy_dev = phy_connect(mdio_bus, eth_priv->phy_addr,
 				      dev, PHY_INTERFACE_MODE_SGMII);
 
-		if (phy_dev)
+		if (phy_dev) {
+			eth_priv->phy_dev = phy_dev;
 			phy_config(phy_dev);
-		else
+		} else {
 			return -1;
+		}
 	}
 
 	return 0;
-- 
1.8.3.2



More information about the U-Boot mailing list