From: Andrew Lunn <andrew@lunn.ch>
To: "Kamil Horák (2N)" <kamilh@axis.com>
Cc: florian.fainelli@broadcom.com,
bcm-kernel-feedback-list@broadcom.com, hkallweit1@gmail.com,
linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, netdev@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 4/4] net: phy: bcm-phy-lib: Implement BroadR-Reach link modes
Date: Thu, 11 Jul 2024 21:01:56 +0200 [thread overview]
Message-ID: <885eec03-b4d0-4bd1-869f-c334bb22888c@lunn.ch> (raw)
In-Reply-To: <20240708102716.1246571-5-kamilh@axis.com>
> +static int bcm5481x_get_brrmode(struct phy_device *phydev, u8 *data)
> {
> - int err, reg;
> + int reg;
>
> - /* Disable BroadR-Reach function. */
> reg = bcm_phy_read_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL);
> - reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN;
> - err = bcm_phy_write_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL,
> - reg);
> - if (err < 0)
bcm_phy_read_exp() could fail. So you should keep the test. Also, the
caller of this function does look at the return value.
> +/**
> + * bcm5481x_read_abilities - read PHY abilities from LRESR or Clause 22
> + * (BMSR) registers, based on whether the PHY is in BroadR-Reach or IEEE mode
> + * @phydev: target phy_device struct
> + *
> + * Description: Reads the PHY's abilities and populates
> + * phydev->supported accordingly. The register to read the abilities from is
> + * determined by current brr mode setting of the PHY.
> + * Note that the LRE and IEEE sets of abilities are disjunct.
> + *
> + * Returns: 0 on success, < 0 on failure
> + */
> +static int bcm5481x_read_abilities(struct phy_device *phydev)
> +{
> + int i, val, err;
> + u8 brr_mode;
> +
> + for (i = 0; i < ARRAY_SIZE(bcm54811_linkmodes); i++)
> + linkmode_clear_bit(bcm54811_linkmodes[i], phydev->supported);
> +
> + err = bcm5481x_get_brrmode(phydev, &brr_mode);
> +static int bcm5481x_set_brrmode(struct phy_device *phydev, bool on)
> +{
> + int reg;
> + int err;
> + u16 val;
> +
> + reg = bcm_phy_read_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL);
> +
> + if (on)
> + reg |= BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN;
> + else
> + reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN;
> +
> +static int bcm54811_config_init(struct phy_device *phydev)
> +{
> + struct device_node *np = phydev->mdio.dev.of_node;
> + bool brr = false;
> + int err, reg;
> +
> err = bcm54xx_config_init(phydev);
>
> /* Enable CLK125 MUX on LED4 if ref clock is enabled. */
> @@ -576,29 +687,80 @@ static int bcm54811_config_init(struct phy_device *phydev)
> return err;
> }
>
> - return err;
> + /* Configure BroadR-Reach function. */
> + brr = of_property_read_bool(np, "brr-mode");
> +
> + /* With BCM54811, BroadR-Reach implies no autoneg */
> + if (brr)
> + phydev->autoneg = 0;
> +
> + return bcm5481x_set_brrmode(phydev, brr);
> }
The ordering seems a bit strange here.
phy_probe() will call phydrv->get_features. At this point, the PHY is
in whatever mode it resets to, or maybe what it is strapped
to. phydev->supported could thus be set to standard IEEE modes,
despite the board design is actually for BroadR-Reach.
Sometime later, when the MAC is connected to the PHY config_init() is
called. At that point, you poke around in DT and find how the PHY is
connected to the cable. At that point, you set the PHY mode, and
change phydev->supported to reflect reality.
I really think that reading DT should be done much earlier, maybe in
the driver probe function, or maybe get_features. get_features should
always return the correct values from the board.
> +static int bcm5481_config_aneg(struct phy_device *phydev)
> +{
> + u8 brr_mode;
> + int ret;
> +
> + ret = bcm5481x_get_brrmode(phydev, &brr_mode);
Rather than read it from the hardware every single time, could you
store the DT value in bcm54xx_phy_priv ?
> +/* Read LDS Link Partner Ability in BroadR-Reach mode */
> +static int bcm_read_lpa(struct phy_device *phydev)
This function seems to be missing an lds or lre prefix.
> +static int bcm_read_status_fixed(struct phy_device *phydev)
and here. Please make sure the naming is consistent. Anything which
only accesses lre or lds registers should make that clear in its name.
> +static int bcm54811_read_status(struct phy_device *phydev)
> +{
> + u8 brr_mode;
> + int err;
> +
> + err = bcm5481x_get_brrmode(phydev, &brr_mode);
> +
> + if (err)
> + return err;
> +
> + if (brr_mode) {
> + /* Get the status in BroadRReach mode just like
> + * genphy_read_status does in normal mode
> + */
> +
> + int err, old_link = phydev->link;
> +
> + /* Update the link, but return if there was an error */
> +
> + err = lre_update_link(phydev);
> + if (err)
> + return err;
> +
> + /* why bother the PHY if nothing can have changed */
> + if (phydev->autoneg ==
> + AUTONEG_ENABLE && old_link && phydev->link)
> + return 0;
> +
> + phydev->speed = SPEED_UNKNOWN;
> + phydev->duplex = DUPLEX_UNKNOWN;
> + phydev->pause = 0;
> + phydev->asym_pause = 0;
> +
> + err = bcm_read_master_slave(phydev);
> + if (err < 0)
> + return err;
> +
> + /* Read LDS Link Partner Ability */
> + err = bcm_read_lpa(phydev);
> + if (err < 0)
> + return err;
> +
> + if (phydev->autoneg ==
> + AUTONEG_ENABLE && phydev->autoneg_complete) {
> + phy_resolve_aneg_linkmode(phydev);
> + } else if (phydev->autoneg == AUTONEG_DISABLE) {
> + err = bcm_read_status_fixed(phydev);
> + if (err < 0)
> + return err;
> + }
This would probably look better if you pulled this code out into a
helper bcm54811_lre_read_status().
Andrew
---
pw-bot: cr
next prev parent reply other threads:[~2024-07-11 19:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-08 10:27 [PATCH v11 0/4] net: phy: bcm5481x: add support for BroadR-Reach mode Kamil Horák (2N)
2024-07-08 10:27 ` [PATCH v11 1/4] net: phy: bcm54811: New link mode for BroadR-Reach Kamil Horák (2N)
2024-07-11 16:56 ` Jakub Kicinski
2024-07-11 18:28 ` Andrew Lunn
2024-07-29 8:31 ` Russell King (Oracle)
2024-07-08 10:27 ` [PATCH v11 2/4] net: phy: bcm54811: Add LRE registers definitions Kamil Horák (2N)
2024-07-08 10:27 ` [PATCH v11 3/4] dt-bindings: ethernet-phy: add optional brr-mode flag Kamil Horák (2N)
2024-07-08 14:44 ` Rob Herring (Arm)
2024-07-08 10:27 ` [PATCH v11 4/4] net: phy: bcm-phy-lib: Implement BroadR-Reach link modes Kamil Horák (2N)
2024-07-11 19:01 ` Andrew Lunn [this message]
2024-07-12 15:10 ` Kamil Horák (2N)
2024-07-12 15:45 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=885eec03-b4d0-4bd1-869f-c334bb22888c@lunn.ch \
--to=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=hkallweit1@gmail.com \
--cc=kamilh@axis.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®