diff mbox series

[net-next,v2,4/4] net: phy: add support for PHY package MMD read/write

Message ID 20231126235141.17996-4-ansuelsmth@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2,1/4] net: phy: extend PHY package API to support multiple global address | expand

Checks

Context Check Description
netdev/series_format warning Series does not have a cover letter
netdev/codegen success Generated files up to date
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1565 this patch: 1565
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 1158 this patch: 1158
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1602 this patch: 1602
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 84 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi Nov. 26, 2023, 11:51 p.m. UTC
Some PHY in PHY package may require to read/write MMD regs to correctly
configure the PHY package.

Add support for these additional required function in both lock and no
lock variant.

It's possible to set is_c45 bool for phy_package_read/write to true to
access mmd regs for accessing C45 PHY in PHY package for global
configuration.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Changes v2:
- Rework to use newly introduced helper
- Add common check for regnum and devad

 include/linux/phy.h | 78 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

Comments

Andrew Lunn Nov. 28, 2023, 12:51 a.m. UTC | #1
On Mon, Nov 27, 2023 at 12:51:41AM +0100, Christian Marangi wrote:
> Some PHY in PHY package may require to read/write MMD regs to correctly
> configure the PHY package.
> 
> Add support for these additional required function in both lock and no
> lock variant.
> 
> It's possible to set is_c45 bool for phy_package_read/write to true to
> access mmd regs for accessing C45 PHY in PHY package for global
> configuration.

I would just use phydev->is_c45. I would be very surprised if you have
a package with some PHYs being only C22 and some C45.

> 
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
> Changes v2:
> - Rework to use newly introduced helper
> - Add common check for regnum and devad
> 
>  include/linux/phy.h | 78 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 78 insertions(+)
> 
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 96f6f34be051..3e507bd2c3b4 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -2085,6 +2085,84 @@ static inline int __phy_package_write(struct phy_device *phydev,
>  	return __mdiobus_write(phydev->mdio.bus, addr, regnum, val);
>  }
>  
> +static inline int phy_package_read_mmd(struct phy_device *phydev,
> +				       unsigned int addr_offset, bool is_c45,
> +				       int devad, u32 regnum)
> +{

I also don't know why this should be in the header file?

  Andrew
Christian Marangi Nov. 28, 2023, 12:12 p.m. UTC | #2
On Tue, Nov 28, 2023 at 01:51:05AM +0100, Andrew Lunn wrote:
> On Mon, Nov 27, 2023 at 12:51:41AM +0100, Christian Marangi wrote:
> > Some PHY in PHY package may require to read/write MMD regs to correctly
> > configure the PHY package.
> > 
> > Add support for these additional required function in both lock and no
> > lock variant.
> > 
> > It's possible to set is_c45 bool for phy_package_read/write to true to
> > access mmd regs for accessing C45 PHY in PHY package for global
> > configuration.
> 
> I would just use phydev->is_c45. I would be very surprised if you have
> a package with some PHYs being only C22 and some C45.
>

Was being more careful about this. Ok will base everything on phydev.
Maybe will add a comment that we assume the entire package is C22 or
C45.

> > 
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> > ---
> > Changes v2:
> > - Rework to use newly introduced helper
> > - Add common check for regnum and devad
> > 
> >  include/linux/phy.h | 78 +++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 78 insertions(+)
> > 
> > diff --git a/include/linux/phy.h b/include/linux/phy.h
> > index 96f6f34be051..3e507bd2c3b4 100644
> > --- a/include/linux/phy.h
> > +++ b/include/linux/phy.h
> > @@ -2085,6 +2085,84 @@ static inline int __phy_package_write(struct phy_device *phydev,
> >  	return __mdiobus_write(phydev->mdio.bus, addr, regnum, val);
> >  }
> >  
> > +static inline int phy_package_read_mmd(struct phy_device *phydev,
> > +				       unsigned int addr_offset, bool is_c45,
> > +				       int devad, u32 regnum)
> > +{
> 
> I also don't know why this should be in the header file?
> 
>   Andrew
diff mbox series

Patch

diff --git a/include/linux/phy.h b/include/linux/phy.h
index 96f6f34be051..3e507bd2c3b4 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -2085,6 +2085,84 @@  static inline int __phy_package_write(struct phy_device *phydev,
 	return __mdiobus_write(phydev->mdio.bus, addr, regnum, val);
 }
 
+static inline int phy_package_read_mmd(struct phy_device *phydev,
+				       unsigned int addr_offset, bool is_c45,
+				       int devad, u32 regnum)
+{
+	struct phy_package_shared *shared = phydev->shared;
+	int addr = shared->base_addr + addr_offset;
+	int val;
+
+	if (addr >= PHY_MAX_ADDR)
+		return -EIO;
+
+	if (regnum > (u16)~0 || devad > 32)
+		return -EINVAL;
+
+	phy_lock_mdio_bus(phydev);
+	val = mmd_phy_read(phydev->mdio.bus, addr, is_c45, devad,
+			   regnum);
+	phy_unlock_mdio_bus(phydev);
+
+	return val;
+}
+
+static inline int __phy_package_read_mmd(struct phy_device *phydev,
+					 unsigned int addr_offset, bool is_c45,
+					 int devad, u32 regnum)
+{
+	struct phy_package_shared *shared = phydev->shared;
+	int addr = shared->base_addr + addr_offset;
+
+	if (addr >= PHY_MAX_ADDR)
+		return -EIO;
+
+	if (regnum > (u16)~0 || devad > 32)
+		return -EINVAL;
+
+	return mmd_phy_read(phydev->mdio.bus, addr, is_c45, devad,
+			    regnum);
+}
+
+static inline int phy_package_write_mmd(struct phy_device *phydev,
+					unsigned int addr_offset, bool is_c45,
+					int devad, u32 regnum, u16 val)
+{
+	struct phy_package_shared *shared = phydev->shared;
+	int addr = shared->base_addr + addr_offset;
+	int ret;
+
+	if (addr >= PHY_MAX_ADDR)
+		return -EIO;
+
+	if (regnum > (u16)~0 || devad > 32)
+		return -EINVAL;
+
+	phy_lock_mdio_bus(phydev);
+	ret = mmd_phy_write(phydev->mdio.bus, addr, is_c45, devad,
+			    regnum, val);
+	phy_unlock_mdio_bus(phydev);
+
+	return ret;
+}
+
+static inline int __phy_package_write_mmd(struct phy_device *phydev,
+					  unsigned int addr_offset, bool is_c45,
+					  int devad, u32 regnum, u16 val)
+{
+	struct phy_package_shared *shared = phydev->shared;
+	int addr = shared->base_addr + addr_offset;
+
+	if (addr >= PHY_MAX_ADDR)
+		return -EIO;
+
+	if (regnum > (u16)~0 || devad > 32)
+		return -EINVAL;
+
+	return mmd_phy_write(phydev->mdio.bus, addr, is_c45, devad,
+			     regnum, val);
+}
+
 static inline bool __phy_package_set_once(struct phy_device *phydev,
 					  unsigned int b)
 {