diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2016-06-23 16:50:15 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-06-27 17:40:57 +0300 |
commit | 68888ce075a5e77f0df659b128a7cb7c597a73cb (patch) | |
tree | ecf50f5ecda7b35b709b01267d86e79812a2f0f8 /drivers/net/phy/swphy.c | |
parent | 0629bf17eaab9330bef427bdf4a3985c2d8972af (diff) | |
download | linux-68888ce075a5e77f0df659b128a7cb7c597a73cb.tar.xz |
phy: separate swphy state validation from register generation
Separate out the generation of MII registers from the state validation.
This allows us to simplify the error handing in fixed_phy() by allowing
earlier error detection.
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/swphy.c')
-rw-r--r-- | drivers/net/phy/swphy.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/drivers/net/phy/swphy.c b/drivers/net/phy/swphy.c index c88a194b4cb6..21a9bd8a7830 100644 --- a/drivers/net/phy/swphy.c +++ b/drivers/net/phy/swphy.c @@ -87,6 +87,29 @@ static int swphy_decode_speed(int speed) } /** + * swphy_validate_state - validate the software phy status + * @state: software phy status + * + * This checks that we can represent the state stored in @state can be + * represented in the emulated MII registers. Returns 0 if it can, + * otherwise returns -EINVAL. + */ +int swphy_validate_state(const struct fixed_phy_status *state) +{ + int err; + + if (state->link) { + err = swphy_decode_speed(state->speed); + if (err < 0) { + pr_warn("swphy: unknown speed\n"); + return -EINVAL; + } + } + return 0; +} +EXPORT_SYMBOL_GPL(swphy_validate_state); + +/** * swphy_update_regs - update MII register array with fixed phy state * @regs: array of 32 registers to update * @state: fixed phy status @@ -94,7 +117,7 @@ static int swphy_decode_speed(int speed) * Update the array of MII registers with the fixed phy link, speed, * duplex and pause mode settings. */ -int swphy_update_regs(u16 *regs, const struct fixed_phy_status *state) +void swphy_update_regs(u16 *regs, const struct fixed_phy_status *state) { int speed_index, duplex_index; u16 bmsr = BMSR_ANEGCAPABLE; @@ -103,10 +126,8 @@ int swphy_update_regs(u16 *regs, const struct fixed_phy_status *state) u16 lpa = 0; speed_index = swphy_decode_speed(state->speed); - if (speed_index < 0) { - pr_warn("swphy: unknown speed\n"); - return -EINVAL; - } + if (WARN_ON(speed_index < 0)) + return; duplex_index = state->duplex ? SWMII_DUPLEX_FULL : SWMII_DUPLEX_HALF; @@ -133,7 +154,5 @@ int swphy_update_regs(u16 *regs, const struct fixed_phy_status *state) regs[MII_BMCR] = bmcr; regs[MII_LPA] = lpa; regs[MII_STAT1000] = lpagb; - - return 0; } EXPORT_SYMBOL_GPL(swphy_update_regs); |