On Fri, Nov 08, 2024 at 11:09:30AM +0000, Russell King (Oracle) wrote: > On Wed, Nov 06, 2024 at 01:22:38PM +0100, Christian Marangi wrote: > > +/* MII Registers Page 1 */ > > +#define AN8855_PHY_EXT_REG_14 0x14 > > +#define AN8855_PHY_EN_DOWN_SHFIT BIT(4) > > Shouldn't "AN8855_PHY_EN_DOWN_SHFIT" be "AN8855_PHY_EN_DOWN_SHIFT" > (notice the I and F are swapped) ? > Typo from SDK that I didn't notice fun. > > +static int an8855_get_downshift(struct phy_device *phydev, u8 *data) > > +{ > > + int saved_page; > > + int val; > > + int ret; > > + > > + saved_page = phy_select_page(phydev, AN8855_PHY_PAGE_EXTENDED_1); > > + if (saved_page >= 0) > > + val = __phy_read(phydev, AN8855_PHY_EXT_REG_14); > > + ret = phy_restore_page(phydev, saved_page, val); > > + if (ret) > > + return ret; > > This function is entirely broken. > > phy_restore_page() will return "val" if everything went successfully, > so here you end up returning "val" via this very return statement > without executing any further code in the function. The only time > further code will be executed is if "val" was successfully read as > zero. > > Please use the helpers provided: > > ret = phy_read_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1, > AN8855_PHY_EXT_REG_14); > if (ret < 0) > return ret; > > ret now contains what you're using as "val" below. No need to open code > phy_read_paged(). Thanks for the explaination, totally got confused by reading the restore_page code. Anyway yes I will use the helper. > > > + > > + *data = val & AN8855_PHY_EXT_REG_14 ? DOWNSHIFT_DEV_DEFAULT_COUNT : > > + DOWNSHIFT_DEV_DISABLE; > > Here, the test is against the register number rather than the bit that > controls downshift. Shouldn't AN8855_PHY_EXT_REG_14 be > AN8855_PHY_EN_DOWN_SH(F)I(F)T ? Copy paste error, was already staged to fix, thanks for extra eye on this. > > > +static int an8855_set_downshift(struct phy_device *phydev, u8 cnt) > > +{ > > + int saved_page; > > + int ret; > > + > > + saved_page = phy_select_page(phydev, AN8855_PHY_PAGE_EXTENDED_1); > > + if (saved_page >= 0) { > > + if (cnt != DOWNSHIFT_DEV_DISABLE) > > + ret = __phy_set_bits(phydev, AN8855_PHY_EXT_REG_14, > > + AN8855_PHY_EN_DOWN_SHFIT); > > + else > > + ret = __phy_clear_bits(phydev, AN8855_PHY_EXT_REG_14, > > + AN8855_PHY_EN_DOWN_SHFIT); > > + } > > + > > + return phy_restore_page(phydev, saved_page, ret); > > This entire thing can be simplified to: > > u16 ds = cnt != DOWNSHIFT_DEV_DISABLE ? AN8855_PHY_EN_DOWN_SHFIT: 0; > > return phy_modify_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1, > AN8855_PHY_EXT_REG_14, AN8855_PHY_EN_DOWN_SHFIT, > ds); Funnly in rechecking I produced the same exact change. > > Thanks. Thanks to you for the review. > > -- > RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! -- Ansuel