Message ID | Yc9uphz7RGb63kzM@makrotopia.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v9,1/3] net: mdio: add helpers to extract clause 45 regad and devad fields | expand |
On Fri, Dec 31, 2021 at 08:57:43PM +0000, Daniel Golle wrote: > From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk> > > Add a couple of helpers and definitions to extract the clause 45 regad > and devad fields from the regnum passed into MDIO drivers. > > Tested-by: Daniel Golle <daniel@makrotopia.org> > Signed-off-by: Daniel Golle <daniel@makrotopia.org> > Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Hi Daniel Since you are submitted this, your Signed-off-by: needs to be last. Andrew
Rework value and type of mdio read and write functions in mtk_eth_soc and generally clean up and unify both functions. Then add support to access Clause 45 phy registers, using newly introduced helper macros added by a patch Russell King has suggested in a reply to an earlier version of this series [1]. All three commits are tested on the Bananapi BPi-R64 board having MediaTek MT7531BE DSA gigE switch using clause 22 MDIO and Ubiquiti UniFi 6 LR access point having Aquantia AQR112C PHY using clause 45 MDIO. [1]: https://lore.kernel.org/netdev/Ycr5Cna76eg2B0An@shell.armlinux.org.uk/ v10: correct order of SoB lines in 2/3, change patch order in series v9: improved formatting and Cc missing maintainer v8: add patch from Russel King, switch to bitfield helper macros v7: remove unneeded variables and order OR-ed call parameters v6: further clean up functions and more cleanly separate patches v5: fix wrong variable name in first patch covered by follow-up patch v4: clean-up return values and types, split into two commits v3: return -1 instead of 0xffff on error in _mtk_mdio_write v2: use MII_DEVADDR_C45_SHIFT and MII_REGADDR_C45_MASK to extract device id and register address. Unify read and write functions to have identical types and parameter names where possible as we are anyway already replacing both function bodies. Daniel Golle (2): net: ethernet: mtk_eth_soc: fix return value and refactor MDIO ops net: ethernet: mtk_eth_soc: implement Clause 45 MDIO access Russell King (Oracle) (1): net: mdio: add helpers to extract clause 45 regad and devad fields drivers/net/ethernet/mediatek/mtk_eth_soc.c | 85 +++++++++++++++------ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 19 +++-- include/linux/mdio.h | 12 +++ 3 files changed, 89 insertions(+), 27 deletions(-)
On Sun, Jan 02, 2022 at 03:47:52PM +0000, Daniel Golle wrote: > Rework value and type of mdio read and write functions in mtk_eth_soc > and generally clean up and unify both functions. > Then add support to access Clause 45 phy registers, using newly > introduced helper macros added by a patch Russell King has suggested > in a reply to an earlier version of this series [1]. Can you please stop threading each re-post to the previous posting of the series. It's getting rather annoying after ten iterations to have the subject lines disappearing off the right hand side of the field. This is not a request to re-post, it is a request for the next posting. Thanks.
> +static int _mtk_mdio_write(struct mtk_eth *eth, u32 phy_addr, u32 phy_reg, > + u32 write_data) > { > if (mtk_mdio_busy_wait(eth)) > - return -1; > - > - write_data &= 0xffff; > + return -EBUSY; -ETIMEDOUT would be more normal. I would probably also change mtk_mdio_busy_wait() so that it either returned 0, or -ETIMEDOUT. That is the general pattern in Linux, return 0 on success, or a negative error code. Returning -1 is an invitation for trouble. The code would then become ret = mtk_mdio_busy_wait(eth); if (ret < 0) return ret; which is a very common pattern in Linux. Andrew
diff --git a/include/linux/mdio.h b/include/linux/mdio.h index 9f3587a61e145..ecac96d52e010 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -7,6 +7,7 @@ #define __LINUX_MDIO_H__ #include <uapi/linux/mdio.h> +#include <linux/bitfield.h> #include <linux/mod_devicetable.h> /* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit @@ -14,6 +15,7 @@ */ #define MII_ADDR_C45 (1<<30) #define MII_DEVADDR_C45_SHIFT 16 +#define MII_DEVADDR_C45_MASK GENMASK(20, 16) #define MII_REGADDR_C45_MASK GENMASK(15, 0) struct gpio_desc; @@ -381,6 +383,16 @@ static inline u32 mdiobus_c45_addr(int devad, u16 regnum) return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum; } +static inline u16 mdiobus_c45_regad(u32 regnum) +{ + return FIELD_GET(MII_REGADDR_C45_MASK, regnum); +} + +static inline u16 mdiobus_c45_devad(u32 regnum) +{ + return FIELD_GET(MII_DEVADDR_C45_MASK, regnum); +} + static inline int __mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad, u16 regnum) {