Commit 9590fc4a authored by Oleksij Rempel's avatar Oleksij Rempel Committed by David S. Miller

net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy

Now ksz_pread/ksz_pwrite can return error value. So, make use of it.
Signed-off-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: default avatarVladimir Oltean <olteanv@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9da975e1
...@@ -560,14 +560,24 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) ...@@ -560,14 +560,24 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
u8 val1, val2; u8 val1, val2;
u16 data = 0; u16 data = 0;
u8 p = phy; u8 p = phy;
int ret;
regs = dev->info->regs; regs = dev->info->regs;
switch (reg) { switch (reg) {
case MII_BMCR: case MII_BMCR:
ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart); ret = ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart);
ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed); if (ret)
ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl); return ret;
ret = ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed);
if (ret)
return ret;
ret = ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
if (ret)
return ret;
if (restart & PORT_PHY_LOOPBACK) if (restart & PORT_PHY_LOOPBACK)
data |= BMCR_LOOPBACK; data |= BMCR_LOOPBACK;
if (ctrl & PORT_FORCE_100_MBIT) if (ctrl & PORT_FORCE_100_MBIT)
...@@ -597,7 +607,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) ...@@ -597,7 +607,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
data |= KSZ886X_BMCR_DISABLE_LED; data |= KSZ886X_BMCR_DISABLE_LED;
break; break;
case MII_BMSR: case MII_BMSR:
ksz_pread8(dev, p, regs[P_LINK_STATUS], &link); ret = ksz_pread8(dev, p, regs[P_LINK_STATUS], &link);
if (ret)
return ret;
data = BMSR_100FULL | data = BMSR_100FULL |
BMSR_100HALF | BMSR_100HALF |
BMSR_10FULL | BMSR_10FULL |
...@@ -618,7 +631,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) ...@@ -618,7 +631,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
data = KSZ8795_ID_LO; data = KSZ8795_ID_LO;
break; break;
case MII_ADVERTISE: case MII_ADVERTISE:
ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl); ret = ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl);
if (ret)
return ret;
data = ADVERTISE_CSMA; data = ADVERTISE_CSMA;
if (ctrl & PORT_AUTO_NEG_SYM_PAUSE) if (ctrl & PORT_AUTO_NEG_SYM_PAUSE)
data |= ADVERTISE_PAUSE_CAP; data |= ADVERTISE_PAUSE_CAP;
...@@ -632,7 +648,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) ...@@ -632,7 +648,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
data |= ADVERTISE_10HALF; data |= ADVERTISE_10HALF;
break; break;
case MII_LPA: case MII_LPA:
ksz_pread8(dev, p, regs[P_REMOTE_STATUS], &link); ret = ksz_pread8(dev, p, regs[P_REMOTE_STATUS], &link);
if (ret)
return ret;
data = LPA_SLCT; data = LPA_SLCT;
if (link & PORT_REMOTE_SYM_PAUSE) if (link & PORT_REMOTE_SYM_PAUSE)
data |= LPA_PAUSE_CAP; data |= LPA_PAUSE_CAP;
...@@ -648,8 +667,14 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) ...@@ -648,8 +667,14 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
data |= LPA_LPACK; data |= LPA_LPACK;
break; break;
case PHY_REG_LINK_MD: case PHY_REG_LINK_MD:
ksz_pread8(dev, p, REG_PORT_LINK_MD_CTRL, &val1); ret = ksz_pread8(dev, p, REG_PORT_LINK_MD_CTRL, &val1);
ksz_pread8(dev, p, REG_PORT_LINK_MD_RESULT, &val2); if (ret)
return ret;
ret = ksz_pread8(dev, p, REG_PORT_LINK_MD_RESULT, &val2);
if (ret)
return ret;
if (val1 & PORT_START_CABLE_DIAG) if (val1 & PORT_START_CABLE_DIAG)
data |= PHY_START_CABLE_DIAG; data |= PHY_START_CABLE_DIAG;
...@@ -664,7 +689,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) ...@@ -664,7 +689,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
FIELD_GET(PORT_CABLE_FAULT_COUNTER_L, val2)); FIELD_GET(PORT_CABLE_FAULT_COUNTER_L, val2));
break; break;
case PHY_REG_PHY_CTRL: case PHY_REG_PHY_CTRL:
ksz_pread8(dev, p, regs[P_LINK_STATUS], &link); ret = ksz_pread8(dev, p, regs[P_LINK_STATUS], &link);
if (ret)
return ret;
if (link & PORT_MDIX_STATUS) if (link & PORT_MDIX_STATUS)
data |= KSZ886X_CTRL_MDIX_STAT; data |= KSZ886X_CTRL_MDIX_STAT;
break; break;
...@@ -683,6 +711,7 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) ...@@ -683,6 +711,7 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
u8 restart, speed, ctrl, data; u8 restart, speed, ctrl, data;
const u16 *regs; const u16 *regs;
u8 p = phy; u8 p = phy;
int ret;
regs = dev->info->regs; regs = dev->info->regs;
...@@ -692,15 +721,26 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) ...@@ -692,15 +721,26 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
/* Do not support PHY reset function. */ /* Do not support PHY reset function. */
if (val & BMCR_RESET) if (val & BMCR_RESET)
break; break;
ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed); ret = ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed);
if (ret)
return ret;
data = speed; data = speed;
if (val & KSZ886X_BMCR_HP_MDIX) if (val & KSZ886X_BMCR_HP_MDIX)
data |= PORT_HP_MDIX; data |= PORT_HP_MDIX;
else else
data &= ~PORT_HP_MDIX; data &= ~PORT_HP_MDIX;
if (data != speed)
ksz_pwrite8(dev, p, regs[P_SPEED_STATUS], data); if (data != speed) {
ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl); ret = ksz_pwrite8(dev, p, regs[P_SPEED_STATUS], data);
if (ret)
return ret;
}
ret = ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
if (ret)
return ret;
data = ctrl; data = ctrl;
if (ksz_is_ksz88x3(dev)) { if (ksz_is_ksz88x3(dev)) {
if ((val & BMCR_ANENABLE)) if ((val & BMCR_ANENABLE))
...@@ -726,9 +766,17 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) ...@@ -726,9 +766,17 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
data |= PORT_FORCE_FULL_DUPLEX; data |= PORT_FORCE_FULL_DUPLEX;
else else
data &= ~PORT_FORCE_FULL_DUPLEX; data &= ~PORT_FORCE_FULL_DUPLEX;
if (data != ctrl)
ksz_pwrite8(dev, p, regs[P_FORCE_CTRL], data); if (data != ctrl) {
ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart); ret = ksz_pwrite8(dev, p, regs[P_FORCE_CTRL], data);
if (ret)
return ret;
}
ret = ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart);
if (ret)
return ret;
data = restart; data = restart;
if (val & KSZ886X_BMCR_DISABLE_LED) if (val & KSZ886X_BMCR_DISABLE_LED)
data |= PORT_LED_OFF; data |= PORT_LED_OFF;
...@@ -758,11 +806,19 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) ...@@ -758,11 +806,19 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
data |= PORT_PHY_LOOPBACK; data |= PORT_PHY_LOOPBACK;
else else
data &= ~PORT_PHY_LOOPBACK; data &= ~PORT_PHY_LOOPBACK;
if (data != restart)
ksz_pwrite8(dev, p, regs[P_NEG_RESTART_CTRL], data); if (data != restart) {
ret = ksz_pwrite8(dev, p, regs[P_NEG_RESTART_CTRL],
data);
if (ret)
return ret;
}
break; break;
case MII_ADVERTISE: case MII_ADVERTISE:
ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl); ret = ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl);
if (ret)
return ret;
data = ctrl; data = ctrl;
data &= ~(PORT_AUTO_NEG_SYM_PAUSE | data &= ~(PORT_AUTO_NEG_SYM_PAUSE |
PORT_AUTO_NEG_100BTX_FD | PORT_AUTO_NEG_100BTX_FD |
...@@ -779,8 +835,12 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) ...@@ -779,8 +835,12 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
data |= PORT_AUTO_NEG_10BT_FD; data |= PORT_AUTO_NEG_10BT_FD;
if (val & ADVERTISE_10HALF) if (val & ADVERTISE_10HALF)
data |= PORT_AUTO_NEG_10BT; data |= PORT_AUTO_NEG_10BT;
if (data != ctrl)
ksz_pwrite8(dev, p, regs[P_LOCAL_CTRL], data); if (data != ctrl) {
ret = ksz_pwrite8(dev, p, regs[P_LOCAL_CTRL], data);
if (ret)
return ret;
}
break; break;
case PHY_REG_LINK_MD: case PHY_REG_LINK_MD:
if (val & PHY_START_CABLE_DIAG) if (val & PHY_START_CABLE_DIAG)
......
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