Re: [PATCH net-next v2 1/6] net: phy: mscc: migrate to phy_select/restore_page functions
From: Andrew Lunn <andrew@lunn.ch>
Date: 2018-10-04 15:16:39
Also in:
lkml
On Thu, Oct 04, 2018 at 02:47:23PM +0200, Quentin Schulz wrote:
quoted hunk ↗ jump to hunk
@@ -197,25 +199,30 @@ static int vsc85xx_mdix_set(struct phy_device *phydev, u8 mdix) if (rc != 0) return rc; - rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED); - if (rc != 0) - return rc; + oldpage = phy_select_page(phydev, MSCC_PHY_PAGE_EXTENDED); + if (oldpage < 0) { + rc = oldpage; + goto out; + } - reg_val = phy_read(phydev, MSCC_PHY_EXT_MODE_CNTL); + reg_val = __phy_read(phydev, MSCC_PHY_EXT_MODE_CNTL); reg_val &= ~(FORCE_MDI_CROSSOVER_MASK); if (mdix == ETH_TP_MDI) reg_val |= FORCE_MDI_CROSSOVER_MDI; else if (mdix == ETH_TP_MDI_X) reg_val |= FORCE_MDI_CROSSOVER_MDIX;
Hi Quentin Could you use phy_modify_paged() here? This function only accesses a single register, so using the wrapper should not have any disadvantages. The same should apply for any function modifying a single register.
quoted hunk ↗ jump to hunk
- rc = phy_write(phydev, MSCC_PHY_EXT_MODE_CNTL, reg_val); + rc = __phy_write(phydev, MSCC_PHY_EXT_MODE_CNTL, reg_val); if (rc != 0) - return rc; + goto out; - rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD); - if (rc != 0) + rc = phy_restore_page(phydev, oldpage, rc); + if (rc < 0) return rc; return genphy_restart_aneg(phydev); + +out: + return phy_restore_page(phydev, oldpage, rc); } static int vsc85xx_downshift_get(struct phy_device *phydev, u8 *count)@@ -223,25 +230,24 @@ static int vsc85xx_downshift_get(struct phy_device *phydev, u8 *count) int rc; u16 reg_val; - rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED); - if (rc != 0) + rc = phy_select_page(phydev, MSCC_PHY_PAGE_EXTENDED); + if (rc < 0) goto out; - reg_val = phy_read(phydev, MSCC_PHY_ACTIPHY_CNTL); + reg_val = __phy_read(phydev, MSCC_PHY_ACTIPHY_CNTL); reg_val &= DOWNSHIFT_CNTL_MASK; if (!(reg_val & DOWNSHIFT_EN)) *count = DOWNSHIFT_DEV_DISABLE; else *count = ((reg_val & ~DOWNSHIFT_EN) >> DOWNSHIFT_CNTL_POS) + 2;
phy_read_paged()? Any function which just accesses a single register should try to use phy_read_paged(), phy_write_paged() or phy_modify_paged() to avoid a lot of boilerplate code. Andrew