From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: "Russell King (Oracle)" <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org,
Heiner Kallweit <hkallweit1@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Madalin Bucur <madalin.bucur@nxp.com>,
Ioana Ciornei <ioana.ciornei@nxp.com>,
Camelia Groza <camelia.groza@nxp.com>,
Li Yang <leoyang.li@nxp.com>, Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor@kernel.org>,
Sean Anderson <sean.anderson@seco.com>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@kernel.org>
Subject: Re: [RFC PATCH v2 net-next 15/15] net: pcs: lynx: use MTIP AN/LT block for copper backplanes
Date: Tue, 3 Oct 2023 22:00:11 +0300 [thread overview]
Message-ID: <20231003190011.jcpahazy3uqlz7q4@skbuf> (raw)
In-Reply-To: <ZRwTwd18xWczDnur@shell.armlinux.org.uk>
Hi Russell,
On Tue, Oct 03, 2023 at 02:14:41PM +0100, Russell King (Oracle) wrote:
> On Sat, Sep 23, 2023 at 04:49:04PM +0300, Vladimir Oltean wrote:
> > +static int lynx_pcs_parse_fwnode(struct lynx_pcs *lynx)
> > +{
> > + struct fwnode_handle *node = lynx->mdio->dev.fwnode;
> > + enum mtip_model model = MTIP_MODEL_AUTODETECT;
> > + struct device_node *np = to_of_node(node);
> > + struct mdio_device *mdio = lynx->mdio;
> > + struct device *dev = &mdio->dev;
> > + struct phy *phy;
> > + int i, err;
> > +
> > + if (!node)
> > + return 0;
> > +
> > + lynx->backplane_mode = fwnode_property_present(node, "fsl,backplane-mode");
> > + if (!lynx->backplane_mode)
> > + return 0;
> > +
> > + if (fwnode_device_is_compatible(node, "fsl,lx2160a-lynx-pcs"))
> > + model = MTIP_MODEL_LX2160A;
> > +
> > + lynx->num_lanes = of_count_phandle_with_args(np, "phys", "#phy-cells");
> > + if (lynx->num_lanes < 0)
> > + return lynx->num_lanes;
>
> Is it possible for ->num_lanes to be zero at this point? If that is
> possible, then ->anlt[PRIMARY_LANE] will be NULL but ->backplane_mode
> will be set, so won't that cause the mtip_* calls above to pass a
> NULL pointer into those functions? Is that safe? Should we trap that
> case here?
Assuming the dt-bindings as proposed here, that case would be an invalid
device tree ("fsl,backplane-mode" present but "phys" isn't present),
which I indeed failed to catch.
But in my reply to Krzysztof here:
https://lore.kernel.org/netdev/20231002121958.xybzovgjzldfiae2@skbuf/
I said that for v3, I'm looking to move the "phys" property from the PCS
to the MAC (it's already in the MAC for the non-backplane use cases).
On LS1028A (ENETC, Felix), the lynx-pcs is not OF-based (we use
lynx_pcs_create_mdiodev()), but it would be good to support the
1000Base-KX link mode there also. As I'm starting to look beyond
LX2160A, I'm starting to see why adding extra dt-bindings to the
lynx-pcs (both "phys" and "fsl,backplane-mode") will be problematic
if there is no OF node to speak of.
I will leave a separate comment with some new ideas.
> If that's correct, then I don't see any point in storing
> ->backplane_mode, since we can then use ->num_lanes > PRIMARY_LANE
> or similar instead.
Well, in v3, my plan is for the caller of lynx_pcs_create() (aka the MAC)
to always pass an array of phys (the ones from its own OF node). In that
case, we would indeed need the "fsl,backplane-mode" property in the PCS,
because otherwise, with your proposal, the PCS would instantiate the
AN/LT block even when it's not expected.
> > +
> > + if (WARN_ON(lynx->num_lanes > MAX_NUM_LANES))
> > + return -EINVAL;
>
> Do we need to use WARN_ON() here, or would it be better to print a short
> error-level message?
Admittedly I may not have the best intuition here, but I didn't want to
over-complicate the code with error messages that can only be triggered
with invalid device trees.
> > +
> > + for (i = 0; i < lynx->num_lanes; i++) {
> > + phy = devm_of_phy_get_by_index(dev, np, i);
> > + if (IS_ERR(phy))
> > + return dev_err_probe(dev, PTR_ERR(phy),
> > + "Failed to get SerDes PHY %d\n", i);
> > +
> > + lynx->anlt[i] = mtip_backplane_create(mdio, phy, model);
> > + if (IS_ERR(lynx->anlt[i])) {
> > + err = PTR_ERR(lynx->anlt[i]);
> > +
> > + while (i-- > 0)
> > + mtip_backplane_destroy(lynx->anlt[i]);
> > +
> > + return err;
> > + }
> > + }
> > +
> > + for (i = 1; i < lynx->num_lanes; i++) {
> > + err = mtip_backplane_add_subordinate(lynx->anlt[PRIMARY_LANE],
> > + lynx->anlt[i]);
> > + if (WARN_ON(err)) {
>
> Again, does this need to be a backtrace-producing WARN_ON()?
mtip_backplane_add_subordinate() will only return -ERANGE if called too
many times (more than MTIP_MAX_NUM_SUBORDINATES times, aka more than
"MAX_NUM_LANES - 1" times).
Given the way that the code is constructed, it is technically impossible
for that to happen, but only because MTIP_MAX_NUM_SUBORDINATES is
hand-crafted to be 3 and MAX_NUM_LANES to be 4. I think that if I define
MTIP_MAX_NUM_SUBORDINATES in terms of MAX_NUM_LANES - 1, I can simply
make mtip_backplane_add_subordinate() return void.
What I want to avoid is to add error handling for errors which cannot
take place. Which is where the WARN_ON() came from.
> > + /* Too many SerDes lanes in the device tree? */
> > + for (i = 0; i < lynx->num_lanes; i++)
> > + mtip_backplane_destroy(lynx->anlt[i]);
> > + return err;
> > + }
> > + }
> > +
> > + return 0;
> > +}
> > +
> > static struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio)
> > {
> > struct lynx_pcs *lynx;
> > + int err;
> >
> > lynx = kzalloc(sizeof(*lynx), GFP_KERNEL);
> > if (!lynx)
> > @@ -327,6 +451,12 @@ static struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio)
> > lynx->pcs.neg_mode = true;
> > lynx->pcs.poll = true;
> >
> > + err = lynx_pcs_parse_fwnode(lynx);
> > + if (err) {
> > + kfree(lynx);
> > + return ERR_PTR(err);
> > + }
> > +
> > return lynx_to_phylink_pcs(lynx);
> > }
> >
> > @@ -392,6 +522,11 @@ EXPORT_SYMBOL_GPL(lynx_pcs_create_fwnode);
> > void lynx_pcs_destroy(struct phylink_pcs *pcs)
> > {
> > struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs);
> > + int i;
> > +
> > + if (lynx->backplane_mode)
> > + for (i = 0; i < lynx->num_lanes; i++)
> > + mtip_backplane_destroy(lynx->anlt[i]);
>
> Won't ->num_lanes only be non-zero when ->backplane_mode is set, so
> isn't the test for ->backplane_mode redundant here?
I think it won't be redundant anymore once the series reaches a less
"WIP" state.
> >
> > mdio_device_put(lynx->mdio);
> > kfree(lynx);
> > --
> > 2.34.1
> >
> >
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
prev parent reply other threads:[~2023-10-03 19:00 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-23 13:48 [RFC PATCH v2 net-next 00/15] Add C72/C73 copper backplane support for LX2160 Vladimir Oltean
2023-09-23 13:48 ` [RFC PATCH v2 net-next 01/15] phy: introduce phy_get_status() and use it to report CDR lock Vladimir Oltean
2023-10-02 19:16 ` Florian Fainelli
2023-09-23 13:48 ` [RFC PATCH v2 net-next 02/15] phy: introduce the PHY_MODE_ETHTOOL mode for phy_set_mode_ext() Vladimir Oltean
2023-10-02 19:19 ` Florian Fainelli
2023-10-03 16:04 ` Vladimir Oltean
2023-09-23 13:48 ` [RFC PATCH v2 net-next 03/15] phy: ethernet: add configuration interface for copper backplane Ethernet PHYs Vladimir Oltean
2023-09-28 13:36 ` Simon Horman
2023-09-28 19:05 ` Simon Horman
2023-10-02 13:11 ` Vladimir Oltean
2023-10-02 17:20 ` Simon Horman
2023-09-23 13:48 ` [RFC PATCH v2 net-next 04/15] phy: allow querying the address of protocol converters through phy_get_status() Vladimir Oltean
2023-09-29 16:23 ` Vinod Koul
2023-10-02 10:09 ` Vladimir Oltean
2023-09-23 13:48 ` [RFC PATCH v2 net-next 05/15] net: add 25GBase-KR-S and 25GBase-CR-S to ethtool link mode UAPI Vladimir Oltean
2023-10-03 11:19 ` Russell King (Oracle)
2023-09-23 13:48 ` [RFC PATCH v2 net-next 06/15] net: mii: add C73 base page helpers Vladimir Oltean
2023-09-23 13:48 ` [RFC PATCH v2 net-next 07/15] net: phylink: centralize phy_interface_mode_is_8023z() && phylink_autoneg_inband() checks Vladimir Oltean
2023-09-28 13:38 ` Simon Horman
2023-10-03 11:27 ` Russell King (Oracle)
2023-10-03 21:03 ` Vladimir Oltean
2023-09-23 13:48 ` [RFC PATCH v2 net-next 08/15] net: phylink: allow PCS to handle C73 autoneg for phy-mode = "internal" Vladimir Oltean
2023-09-23 13:48 ` [RFC PATCH v2 net-next 09/15] net: ethtool: introduce ethtool_link_mode_str() Vladimir Oltean
2023-10-03 11:30 ` Russell King (Oracle)
2023-10-04 0:08 ` Florian Fainelli
2023-09-23 13:48 ` [RFC PATCH v2 net-next 10/15] net: phylink: support all ethtool port modes with inband modes Vladimir Oltean
2023-09-23 13:49 ` [RFC PATCH v2 net-next 11/15] net: phylink: support the 25GBase-KR-S and 25GBase-CR-S link modes too Vladimir Oltean
2023-10-03 11:31 ` Russell King (Oracle)
2023-10-03 16:24 ` Vladimir Oltean
2023-09-23 13:49 ` [RFC PATCH v2 net-next 12/15] net: phylink: add the 25G link modes to phylink_c73_priority_resolution[] Vladimir Oltean
2023-10-03 13:16 ` Russell King (Oracle)
2023-10-03 16:33 ` Vladimir Oltean
2023-09-23 13:49 ` [RFC PATCH v2 net-next 13/15] dt-bindings: lynx-pcs: add properties for backplane mode Vladimir Oltean
2023-09-24 11:49 ` Krzysztof Kozlowski
2023-10-02 12:19 ` Vladimir Oltean
2023-09-23 13:49 ` [RFC PATCH v2 net-next 14/15] net: pcs: mtip_backplane: add driver for MoreThanIP backplane AN/LT core Vladimir Oltean
2023-09-28 19:06 ` Simon Horman
2023-09-23 13:49 ` [RFC PATCH v2 net-next 15/15] net: pcs: lynx: use MTIP AN/LT block for copper backplanes Vladimir Oltean
2023-10-03 13:14 ` Russell King (Oracle)
2023-10-03 19:00 ` Vladimir Oltean [this message]
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=20231003190011.jcpahazy3uqlz7q4@skbuf \
--to=vladimir.oltean@nxp.com \
--cc=andrew@lunn.ch \
--cc=camelia.groza@nxp.com \
--cc=conor@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=ioana.ciornei@nxp.com \
--cc=kishon@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=leoyang.li@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=madalin.bucur@nxp.com \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sean.anderson@seco.com \
--cc=vkoul@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