Add support for optional rx/tx-internal-delay-ps from devicetree.
- When rx/tx-internal-delay-ps is/are specified, these take priority
- When either is absent,
1) use 2ns for respective settings if rgmii-id/rxid/txid is/are present
2) use 0.2ns for respective settings if mode is rgmii
Signed-off-by: Harini Katakam <[email protected]>
---
v4:
Fix type of rx_delay and tx_delay
Reported by Simon Horman and
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
v3 - Patch split:
- Use rx/tx-internal-delay-ps with phy_get_internal_delay
- Change RGMII delay selection precedence
- Update commit description and subject everywhere to say RGMII delays
instead of RGMII tuning.
drivers/net/phy/mscc/mscc.h | 2 ++
drivers/net/phy/mscc/mscc_main.c | 35 +++++++++++++++++++++++++-------
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/drivers/net/phy/mscc/mscc.h b/drivers/net/phy/mscc/mscc.h
index 9acee8759105..900bf37db9de 100644
--- a/drivers/net/phy/mscc/mscc.h
+++ b/drivers/net/phy/mscc/mscc.h
@@ -374,6 +374,8 @@ struct vsc8531_private {
* package.
*/
unsigned int base_addr;
+ s32 rx_delay;
+ s32 tx_delay;
#if IS_ENABLED(CONFIG_MACSEC)
/* MACsec fields:
diff --git a/drivers/net/phy/mscc/mscc_main.c b/drivers/net/phy/mscc/mscc_main.c
index 91010524e03d..9e856231e464 100644
--- a/drivers/net/phy/mscc/mscc_main.c
+++ b/drivers/net/phy/mscc/mscc_main.c
@@ -525,17 +525,14 @@ static int vsc85xx_rgmii_set_skews(struct phy_device *phydev, u32 rgmii_cntl,
{
u16 rgmii_rx_delay_pos = ffs(rgmii_rx_delay_mask) - 1;
u16 rgmii_tx_delay_pos = ffs(rgmii_tx_delay_mask) - 1;
+ struct vsc8531_private *vsc8531 = phydev->priv;
u16 reg_val = 0;
int rc;
mutex_lock(&phydev->lock);
- if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
- phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
- reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_rx_delay_pos;
- if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
- phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
- reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_tx_delay_pos;
+ reg_val |= vsc8531->rx_delay << rgmii_rx_delay_pos;
+ reg_val |= vsc8531->tx_delay << rgmii_tx_delay_pos;
rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED_2,
rgmii_cntl,
@@ -1808,10 +1805,34 @@ static irqreturn_t vsc8584_handle_interrupt(struct phy_device *phydev)
return IRQ_HANDLED;
}
+static const int vsc8531_internal_delay[] = {200, 800, 1100, 1700, 2000, 2300,
+ 2600, 3400};
static int vsc85xx_config_init(struct phy_device *phydev)
{
- int rc, i, phy_id;
+ int delay_size = ARRAY_SIZE(vsc8531_internal_delay);
struct vsc8531_private *vsc8531 = phydev->priv;
+ struct device *dev = &phydev->mdio.dev;
+ int rc, i, phy_id;
+
+ vsc8531->rx_delay = phy_get_internal_delay(phydev, dev, &vsc8531_internal_delay[0],
+ delay_size, true);
+ if (vsc8531->rx_delay < 0) {
+ if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
+ phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
+ vsc8531->rx_delay = RGMII_CLK_DELAY_2_0_NS;
+ else
+ vsc8531->rx_delay = RGMII_CLK_DELAY_0_2_NS;
+ }
+
+ vsc8531->tx_delay = phy_get_internal_delay(phydev, dev, &vsc8531_internal_delay[0],
+ delay_size, false);
+ if (vsc8531->tx_delay < 0) {
+ if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
+ phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
+ vsc8531->rx_delay = RGMII_CLK_DELAY_2_0_NS;
+ else
+ vsc8531->rx_delay = RGMII_CLK_DELAY_0_2_NS;
+ }
rc = vsc85xx_default_config(phydev);
if (rc)
--
2.17.1
On Mon, 22 May 2023 17:58:29 +0530 Harini Katakam wrote:
> Add support for optional rx/tx-internal-delay-ps from devicetree.
> - When rx/tx-internal-delay-ps is/are specified, these take priority
> - When either is absent,
> 1) use 2ns for respective settings if rgmii-id/rxid/txid is/are present
> 2) use 0.2ns for respective settings if mode is rgmii
>
> Signed-off-by: Harini Katakam <[email protected]>
PHY folks, looks good?
On Mon, May 22, 2023 at 05:58:29PM +0530, Harini Katakam wrote:
> diff --git a/drivers/net/phy/mscc/mscc_main.c b/drivers/net/phy/mscc/mscc_main.c
> index 91010524e03d..9e856231e464 100644
> --- a/drivers/net/phy/mscc/mscc_main.c
> +++ b/drivers/net/phy/mscc/mscc_main.c
> @@ -525,17 +525,14 @@ static int vsc85xx_rgmii_set_skews(struct phy_device *phydev, u32 rgmii_cntl,
> {
> u16 rgmii_rx_delay_pos = ffs(rgmii_rx_delay_mask) - 1;
> u16 rgmii_tx_delay_pos = ffs(rgmii_tx_delay_mask) - 1;
> + struct vsc8531_private *vsc8531 = phydev->priv;
> u16 reg_val = 0;
> int rc;
>
> mutex_lock(&phydev->lock);
>
> - if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
> - phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
> - reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_rx_delay_pos;
> - if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
> - phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
> - reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_tx_delay_pos;
> + reg_val |= vsc8531->rx_delay << rgmii_rx_delay_pos;
> + reg_val |= vsc8531->tx_delay << rgmii_tx_delay_pos;
What about vsc8584_config_init() -> vsc85xx_rgmii_set_skews()? Who will
have configured rx_delay and tx_delay for that call path?
Isn't it better to absorb the device tree parsing logic into
vsc85xx_rgmii_set_skews(), I wonder?
And if we do that, is it still necessary to use struct vsc8531_private
as temporary storage space from vsc85xx_config_init() to vsc85xx_rgmii_set_skews(),
or will two local variables (rx_delay, tx_delay) serve that purpose just fine?
>
> rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED_2,
> rgmii_cntl,
> @@ -1808,10 +1805,34 @@ static irqreturn_t vsc8584_handle_interrupt(struct phy_device *phydev)
> return IRQ_HANDLED;
> }
>
> +static const int vsc8531_internal_delay[] = {200, 800, 1100, 1700, 2000, 2300,
> + 2600, 3400};
Could you please avoid intermingling this with the function code, and
move it at the top of mscc_main.c?
Also, vsc8531_internal_delay[] or vsc85xx_internal_delay[]? The values
are also good for VSC8572, the other caller of vsc85xx_rgmii_set_skews().
> static int vsc85xx_config_init(struct phy_device *phydev)
> {
> - int rc, i, phy_id;
> + int delay_size = ARRAY_SIZE(vsc8531_internal_delay);
> struct vsc8531_private *vsc8531 = phydev->priv;
> + struct device *dev = &phydev->mdio.dev;
> + int rc, i, phy_id;
> +
> + vsc8531->rx_delay = phy_get_internal_delay(phydev, dev, &vsc8531_internal_delay[0],
You can just write "x" rather than "&x[0]".
> + delay_size, true);
> + if (vsc8531->rx_delay < 0) {
> + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
> + phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
> + vsc8531->rx_delay = RGMII_CLK_DELAY_2_0_NS;
> + else
> + vsc8531->rx_delay = RGMII_CLK_DELAY_0_2_NS;
> + }
> +
> + vsc8531->tx_delay = phy_get_internal_delay(phydev, dev, &vsc8531_internal_delay[0],
> + delay_size, false);
> + if (vsc8531->tx_delay < 0) {
> + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
> + phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
> + vsc8531->rx_delay = RGMII_CLK_DELAY_2_0_NS;
> + else
> + vsc8531->rx_delay = RGMII_CLK_DELAY_0_2_NS;
> + }
>
> rc = vsc85xx_default_config(phydev);
> if (rc)
> --
> 2.17.1
>
Hi Vladimir,
> -----Original Message-----
> From: Vladimir Oltean <[email protected]>
> Sent: Wednesday, May 24, 2023 3:39 PM
> To: Katakam, Harini <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; Simek, Michal
> <[email protected]>; Pandey, Radhey Shyam
> <[email protected]>
> Subject: Re: [PATCH net-next v4 2/2] phy: mscc: Add support for RGMII delay
> configuration
>
> On Mon, May 22, 2023 at 05:58:29PM +0530, Harini Katakam wrote:
> > diff --git a/drivers/net/phy/mscc/mscc_main.c
> b/drivers/net/phy/mscc/mscc_main.c
> > index 91010524e03d..9e856231e464 100644
> > --- a/drivers/net/phy/mscc/mscc_main.c
> > +++ b/drivers/net/phy/mscc/mscc_main.c
> > @@ -525,17 +525,14 @@ static int vsc85xx_rgmii_set_skews(struct
> phy_device *phydev, u32 rgmii_cntl,
> > {
> > u16 rgmii_rx_delay_pos = ffs(rgmii_rx_delay_mask) - 1;
> > u16 rgmii_tx_delay_pos = ffs(rgmii_tx_delay_mask) - 1;
> > + struct vsc8531_private *vsc8531 = phydev->priv;
> > u16 reg_val = 0;
> > int rc;
> >
> > mutex_lock(&phydev->lock);
> >
> > - if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
> > - phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
> > - reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_rx_delay_pos;
> > - if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
> > - phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
> > - reg_val |= RGMII_CLK_DELAY_2_0_NS << rgmii_tx_delay_pos;
> > + reg_val |= vsc8531->rx_delay << rgmii_rx_delay_pos;
> > + reg_val |= vsc8531->tx_delay << rgmii_tx_delay_pos;
>
> What about vsc8584_config_init() -> vsc85xx_rgmii_set_skews()? Who will
> have configured rx_delay and tx_delay for that call path?
In my current series "rx_delay" and "tx_delay" would end up 0 and a
delay of 0.2 ns will be programmed (default for that field).
I guess if the phy-mode is RGMII/-ID on VSC8584, 2ns will not be programmed.
This will be a problem for any device not using vsc85xx_config_init
>
> Isn't it better to absorb the device tree parsing logic into
> vsc85xx_rgmii_set_skews(), I wonder?
Yes, that is possible, let me respin. That will ensure existing values are not broken
for any VSC85xx user, if they do not have delay properties in the DT.
>
> And if we do that, is it still necessary to use struct vsc8531_private
> as temporary storage space from vsc85xx_config_init() to
> vsc85xx_rgmii_set_skews(),
> or will two local variables (rx_delay, tx_delay) serve that purpose just fine?
No need of the structure member, local variables will do.
>
> >
> > rc = phy_modify_paged(phydev, MSCC_PHY_PAGE_EXTENDED_2,
> > rgmii_cntl,
> > @@ -1808,10 +1805,34 @@ static irqreturn_t
> vsc8584_handle_interrupt(struct phy_device *phydev)
> > return IRQ_HANDLED;
> > }
> >
> > +static const int vsc8531_internal_delay[] = {200, 800, 1100, 1700, 2000,
> 2300,
> > + 2600, 3400};
>
> Could you please avoid intermingling this with the function code, and
> move it at the top of mscc_main.c?
>
> Also, vsc8531_internal_delay[] or vsc85xx_internal_delay[]? The values
> are also good for VSC8572, the other caller of vsc85xx_rgmii_set_skews().
vsc85xx_internal_delay is more appropriate, will change.
Thanks for the review.
Regards,
Harini