From: Dimitri Fedrau <dimitri.fedrau@liebherr.com>
Add helper which returns the tx amplitude gain defined in device tree.
Modifying it can be necessary to compensate losses on the PCB and
connector, so the voltages measured on the RJ45 pins are conforming.
Signed-off-by: Dimitri Fedrau <dimitri.fedrau@liebherr.com>
---
drivers/net/phy/phy_device.c | 20 ++++++++++++++++----
include/linux/phy.h | 3 +++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 46713d27412b76077d2e51e29b8d84f4f8f0a86d..c42e3e22eba6f7508cefa3568ccb4629cedce6b2 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -3096,7 +3096,7 @@ void phy_get_pause(struct phy_device *phydev, bool *tx_pause, bool *rx_pause)
EXPORT_SYMBOL(phy_get_pause);
#if IS_ENABLED(CONFIG_OF_MDIO)
-static int phy_get_int_delay_property(struct device *dev, const char *name)
+static int phy_get_u32_property(struct device *dev, const char *name)
{
s32 int_delay;
int ret;
@@ -3108,7 +3108,7 @@ static int phy_get_int_delay_property(struct device *dev, const char *name)
return int_delay;
}
#else
-static int phy_get_int_delay_property(struct device *dev, const char *name)
+static int phy_get_u32_property(struct device *dev, const char *name)
{
return -EINVAL;
}
@@ -3137,7 +3137,7 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
int i;
if (is_rx) {
- delay = phy_get_int_delay_property(dev, "rx-internal-delay-ps");
+ delay = phy_get_u32_property(dev, "rx-internal-delay-ps");
if (delay < 0 && size == 0) {
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
@@ -3147,7 +3147,7 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
}
} else {
- delay = phy_get_int_delay_property(dev, "tx-internal-delay-ps");
+ delay = phy_get_u32_property(dev, "tx-internal-delay-ps");
if (delay < 0 && size == 0) {
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
@@ -3193,6 +3193,18 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
}
EXPORT_SYMBOL(phy_get_internal_delay);
+s32 phy_get_tx_amplitude_gain(struct phy_device *phydev, struct device *dev,
+ enum ethtool_link_mode_bit_indices linkmode)
+{
+ switch (linkmode) {
+ case ETHTOOL_LINK_MODE_100baseT_Full_BIT:
+ return phy_get_u32_property(dev, "tx-amplitude-100base-tx-percent");
+ default:
+ return -EINVAL;
+ }
+}
+EXPORT_SYMBOL(phy_get_tx_amplitude_gain);
+
static int phy_led_set_brightness(struct led_classdev *led_cdev,
enum led_brightness value)
{
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 19f076a71f9462cd37588a5da240a1d54df0fe0f..abdd768b7acece3db9ffb0f9de7d20cf86e72bc7 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -2114,6 +2114,9 @@ void phy_get_pause(struct phy_device *phydev, bool *tx_pause, bool *rx_pause);
s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
const int *delay_values, int size, bool is_rx);
+s32 phy_get_tx_amplitude_gain(struct phy_device *phydev, struct device *dev,
+ enum ethtool_link_mode_bit_indices linkmode);
+
void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv,
bool *tx_pause, bool *rx_pause);
--
2.39.5
On Tue, Feb 04, 2025 at 02:09:16PM +0100, Dimitri Fedrau via B4 Relay wrote:
> #if IS_ENABLED(CONFIG_OF_MDIO)
> -static int phy_get_int_delay_property(struct device *dev, const char *name)
> +static int phy_get_u32_property(struct device *dev, const char *name)
> {
> s32 int_delay;
> int ret;
> @@ -3108,7 +3108,7 @@ static int phy_get_int_delay_property(struct device *dev, const char *name)
> return int_delay;
Hmm. You're changing the name of this function from "int" to "u32", yet
it still returns "int".
What range of values are you expecting to be returned by this function?
If it's the full range of u32 values, then that overlaps with the error
range returned by device_property_read_u32().
I'm wondering whether it would be better to follow the example set by
these device_* functions, and pass a pointer for the value to them, and
just have the return value indicating success/failure.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Am Tue, Feb 04, 2025 at 05:54:53PM +0000 schrieb Russell King (Oracle):
> On Tue, Feb 04, 2025 at 02:09:16PM +0100, Dimitri Fedrau via B4 Relay wrote:
> > #if IS_ENABLED(CONFIG_OF_MDIO)
> > -static int phy_get_int_delay_property(struct device *dev, const char *name)
> > +static int phy_get_u32_property(struct device *dev, const char *name)
> > {
> > s32 int_delay;
> > int ret;
> > @@ -3108,7 +3108,7 @@ static int phy_get_int_delay_property(struct device *dev, const char *name)
> > return int_delay;
>
> Hmm. You're changing the name of this function from "int" to "u32", yet
> it still returns "int".
>
I just wanted to reuse code for retrieving the u32, I found
phy_get_int_delay_property and renamed it. But the renaming from "int"
to "u32" is wrong as you outlined.
> What range of values are you expecting to be returned by this function?
> If it's the full range of u32 values, then that overlaps with the error
> range returned by device_property_read_u32().
>
Values are in percent, u8 would already be enough, so it wouldn't
overlap with the error range.
> I'm wondering whether it would be better to follow the example set by
> these device_* functions, and pass a pointer for the value to them, and
> just have the return value indicating success/failure.
>
I would prefer this, but this would mean changes in phy_get_internal_delay
if we don't want to duplicate code, as phy_get_internal_delay relies on
phy_get_int_delay_property and we change function parameters of
phy_get_int_delay_property as you described. I would switch from
static int phy_get_int_delay_property(struct device *dev, const char *name)
to
static int phy_get_u32_property(struct device *dev, const char *name, u32 *val)
Do you agree ?
Best regards,
Dimitri Fedrau
On Wed, Feb 05, 2025 at 06:22:18AM +0100, Dimitri Fedrau wrote:
> Am Tue, Feb 04, 2025 at 05:54:53PM +0000 schrieb Russell King (Oracle):
> > On Tue, Feb 04, 2025 at 02:09:16PM +0100, Dimitri Fedrau via B4 Relay wrote:
> > > #if IS_ENABLED(CONFIG_OF_MDIO)
> > > -static int phy_get_int_delay_property(struct device *dev, const char *name)
> > > +static int phy_get_u32_property(struct device *dev, const char *name)
> > > {
> > > s32 int_delay;
> > > int ret;
> > > @@ -3108,7 +3108,7 @@ static int phy_get_int_delay_property(struct device *dev, const char *name)
> > > return int_delay;
> >
> > Hmm. You're changing the name of this function from "int" to "u32", yet
> > it still returns "int".
> >
>
> I just wanted to reuse code for retrieving the u32, I found
> phy_get_int_delay_property and renamed it. But the renaming from "int"
> to "u32" is wrong as you outlined.
>
> > What range of values are you expecting to be returned by this function?
> > If it's the full range of u32 values, then that overlaps with the error
> > range returned by device_property_read_u32().
> >
>
> Values are in percent, u8 would already be enough, so it wouldn't
> overlap with the error range.
>
> > I'm wondering whether it would be better to follow the example set by
> > these device_* functions, and pass a pointer for the value to them, and
> > just have the return value indicating success/failure.
> >
>
> I would prefer this, but this would mean changes in phy_get_internal_delay
> if we don't want to duplicate code, as phy_get_internal_delay relies on
> phy_get_int_delay_property and we change function parameters of
> phy_get_int_delay_property as you described. I would switch from
> static int phy_get_int_delay_property(struct device *dev, const char *name)
> to
> static int phy_get_u32_property(struct device *dev, const char *name, u32 *val)
>
> Do you agree ?
This looks O.K. You should also rename the local variable int_delay.
Humm, that function has other issues.
static int phy_get_int_delay_property(struct device *dev, const char *name)
{
s32 int_delay;
int ret;
ret = device_property_read_u32(dev, name, &int_delay);
if (ret)
return ret;
return int_delay;
}
int_delay should really be a u32. if ret is not an error, there should
be a range check to ensure int_long actually fits in an s32, otherwise
-EINVAL, or maybe -ERANGE.
For delays, we never expect too much more than 2000ps, so no valid DT
blob should trigger issues here.
Andrew
Am Wed, Feb 05, 2025 at 06:08:47PM +0100 schrieb Andrew Lunn:
> On Wed, Feb 05, 2025 at 06:22:18AM +0100, Dimitri Fedrau wrote:
> > Am Tue, Feb 04, 2025 at 05:54:53PM +0000 schrieb Russell King (Oracle):
> > > On Tue, Feb 04, 2025 at 02:09:16PM +0100, Dimitri Fedrau via B4 Relay wrote:
> > > > #if IS_ENABLED(CONFIG_OF_MDIO)
> > > > -static int phy_get_int_delay_property(struct device *dev, const char *name)
> > > > +static int phy_get_u32_property(struct device *dev, const char *name)
> > > > {
> > > > s32 int_delay;
> > > > int ret;
> > > > @@ -3108,7 +3108,7 @@ static int phy_get_int_delay_property(struct device *dev, const char *name)
> > > > return int_delay;
> > >
> > > Hmm. You're changing the name of this function from "int" to "u32", yet
> > > it still returns "int".
> > >
> >
> > I just wanted to reuse code for retrieving the u32, I found
> > phy_get_int_delay_property and renamed it. But the renaming from "int"
> > to "u32" is wrong as you outlined.
> >
> > > What range of values are you expecting to be returned by this function?
> > > If it's the full range of u32 values, then that overlaps with the error
> > > range returned by device_property_read_u32().
> > >
> >
> > Values are in percent, u8 would already be enough, so it wouldn't
> > overlap with the error range.
> >
> > > I'm wondering whether it would be better to follow the example set by
> > > these device_* functions, and pass a pointer for the value to them, and
> > > just have the return value indicating success/failure.
> > >
> >
> > I would prefer this, but this would mean changes in phy_get_internal_delay
> > if we don't want to duplicate code, as phy_get_internal_delay relies on
> > phy_get_int_delay_property and we change function parameters of
> > phy_get_int_delay_property as you described. I would switch from
> > static int phy_get_int_delay_property(struct device *dev, const char *name)
> > to
> > static int phy_get_u32_property(struct device *dev, const char *name, u32 *val)
> >
> > Do you agree ?
>
> This looks O.K. You should also rename the local variable int_delay.
>
> Humm, that function has other issues.
>
> static int phy_get_int_delay_property(struct device *dev, const char *name)
> {
> s32 int_delay;
> int ret;
>
> ret = device_property_read_u32(dev, name, &int_delay);
> if (ret)
> return ret;
>
> return int_delay;
> }
>
> int_delay should really be a u32. if ret is not an error, there should
> be a range check to ensure int_long actually fits in an s32, otherwise
> -EINVAL, or maybe -ERANGE.
>
> For delays, we never expect too much more than 2000ps, so no valid DT
> blob should trigger issues here.
>
I think you mention this because you want to avoid changes in
phy_get_internal_delay because this would lead to changes in other
drivers too. Is it worth fixing this ? Then we didn't have to workaround by
checking if int_long actually fits in an s32.
Best regards,
Dimitri Fedrau
© 2016 - 2025 Red Hat, Inc.