Commit 92b740a4 authored by Raju Lakkaraju's avatar Raju Lakkaraju Committed by David S. Miller

net: lan743x: Create separate Link Speed Duplex state function

Create separate Link Speed Duplex (LSD) update state function from
lan743x_sgmii_config () to use as subroutine.
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarRaju Lakkaraju <Raju.Lakkaraju@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ef025045
...@@ -992,6 +992,42 @@ static int lan743x_sgmii_write(struct lan743x_adapter *adapter, ...@@ -992,6 +992,42 @@ static int lan743x_sgmii_write(struct lan743x_adapter *adapter,
return ret; return ret;
} }
static int lan743x_get_lsd(int speed, int duplex, u8 mss)
{
int lsd;
switch (speed) {
case SPEED_2500:
if (mss == MASTER_SLAVE_STATE_SLAVE)
lsd = LINK_2500_SLAVE;
else
lsd = LINK_2500_MASTER;
break;
case SPEED_1000:
if (mss == MASTER_SLAVE_STATE_SLAVE)
lsd = LINK_1000_SLAVE;
else
lsd = LINK_1000_MASTER;
break;
case SPEED_100:
if (duplex == DUPLEX_FULL)
lsd = LINK_100FD;
else
lsd = LINK_100HD;
break;
case SPEED_10:
if (duplex == DUPLEX_FULL)
lsd = LINK_10FD;
else
lsd = LINK_10HD;
break;
default:
lsd = -EINVAL;
}
return lsd;
}
static int lan743x_sgmii_mpll_set(struct lan743x_adapter *adapter, static int lan743x_sgmii_mpll_set(struct lan743x_adapter *adapter,
u16 baud) u16 baud)
{ {
...@@ -1179,42 +1215,21 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter) ...@@ -1179,42 +1215,21 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
{ {
struct net_device *netdev = adapter->netdev; struct net_device *netdev = adapter->netdev;
struct phy_device *phydev = netdev->phydev; struct phy_device *phydev = netdev->phydev;
enum lan743x_sgmii_lsd lsd = POWER_DOWN;
bool status; bool status;
int ret; int ret;
switch (phydev->speed) { ret = lan743x_get_lsd(phydev->speed, phydev->duplex,
case SPEED_2500: phydev->master_slave_state);
if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER) if (ret < 0) {
lsd = LINK_2500_MASTER;
else
lsd = LINK_2500_SLAVE;
break;
case SPEED_1000:
if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER)
lsd = LINK_1000_MASTER;
else
lsd = LINK_1000_SLAVE;
break;
case SPEED_100:
if (phydev->duplex)
lsd = LINK_100FD;
else
lsd = LINK_100HD;
break;
case SPEED_10:
if (phydev->duplex)
lsd = LINK_10FD;
else
lsd = LINK_10HD;
break;
default:
netif_err(adapter, drv, adapter->netdev, netif_err(adapter, drv, adapter->netdev,
"Invalid speed %d\n", phydev->speed); "error %d link-speed-duplex(LSD) invalid\n", ret);
return -EINVAL; return ret;
} }
adapter->sgmii_lsd = lsd; adapter->sgmii_lsd = ret;
netif_dbg(adapter, drv, adapter->netdev,
"Link Speed Duplex (lsd) : 0x%X\n", adapter->sgmii_lsd);
ret = lan743x_sgmii_aneg_update(adapter); ret = lan743x_sgmii_aneg_update(adapter);
if (ret < 0) { if (ret < 0) {
netif_err(adapter, drv, adapter->netdev, netif_err(adapter, drv, adapter->netdev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment