From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Simon Horman <simon.horman@corigine.com>
Cc: Mark Brown <broonie@kernel.org>,
davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, alexis.lothore@bootlin.com,
thomas.petazzoni@bootlin.com, Andrew Lunn <andrew@lunn.ch>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Vladimir Oltean <vladimir.oltean@nxp.com>,
Ioana Ciornei <ioana.ciornei@nxp.com>,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Jose Abreu <joabreu@synopsys.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Giuseppe Cavallaro <peppe.cavallaro@st.com>
Subject: Re: [PATCH net-next v3 2/4] net: ethernet: altera-tse: Convert to mdio-regmap and use PCS Lynx
Date: Fri, 26 May 2023 19:03:04 +0200 [thread overview]
Message-ID: <20230526190304.0b9ce032@pc-7.home> (raw)
In-Reply-To: <ZHBwLBnKacQCG2/U@corigine.com>
Hello Simon,
On Fri, 26 May 2023 10:39:08 +0200
Simon Horman <simon.horman@corigine.com> wrote:
> On Fri, May 26, 2023 at 09:42:50AM +0200, Maxime Chevallier wrote:
> > The newly introduced regmap-based MDIO driver allows for an easy
> > mapping of an mdiodevice onto the memory-mapped TSE PCS, which is
> > actually a Lynx PCS.
> >
> > Convert Altera TSE to use this PCS instead of the pcs-altera-tse,
> > which is nothing more than a memory-mapped Lynx PCS.
> >
> > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
>
> Hi Maxime,
>
> I have some concerns about the error paths in this patch.
Heh I didn't do a very good job in that regard indeed :/ I'll address
these, but I'll wait for Russell series to make it through though.
Thanks for spotting this.
> ...
>
> > @@ -1134,13 +1136,21 @@ static int altera_tse_probe(struct
> > platform_device *pdev) const struct of_device_id *of_id = NULL;
> > struct altera_tse_private *priv;
> > struct resource *control_port;
> > + struct regmap *pcs_regmap;
> > struct resource *dma_res;
> > struct resource *pcs_res;
> > + struct mii_bus *pcs_bus;
> > struct net_device *ndev;
> > void __iomem *descmap;
> > - int pcs_reg_width = 2;
> > int ret = -ENODEV;
> >
> > + struct regmap_config pcs_regmap_cfg;
>
> nit: this probably belongs in with the bunch of declarations above it.
>
> > +
> > + struct mdio_regmap_config mrc = {
> > + .parent = &pdev->dev,
> > + .valid_addr = 0x0,
> > + };
>
> nit: maybe this too.
>
> > +
> > ndev = alloc_etherdev(sizeof(struct altera_tse_private));
> > if (!ndev) {
> > dev_err(&pdev->dev, "Could not allocate network
> > device\n"); @@ -1258,10 +1268,29 @@ static int
> > altera_tse_probe(struct platform_device *pdev) ret =
> > request_and_map(pdev, "pcs", &pcs_res, &priv->pcs_base);
> > if (ret) {
> > + /* If we can't find a dedicated resource for the
> > PCS, fallback
> > + * to the internal PCS, that has a different
> > address stride
> > + */
> > priv->pcs_base = priv->mac_dev +
> > tse_csroffs(mdio_phy0);
> > - pcs_reg_width = 4;
> > + pcs_regmap_cfg.reg_bits = 32;
> > + /* Values are MDIO-like values, on 16 bits */
> > + pcs_regmap_cfg.val_bits = 16;
> > + pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(2);
> > + } else {
> > + pcs_regmap_cfg.reg_bits = 16;
> > + pcs_regmap_cfg.val_bits = 16;
> > + pcs_regmap_cfg.reg_shift = REGMAP_UPSHIFT(1);
> > }
> >
> > + /* Create a regmap for the PCS so that it can be used by
> > the PCS driver */
> > + pcs_regmap = devm_regmap_init_mmio(&pdev->dev,
> > priv->pcs_base,
> > + &pcs_regmap_cfg);
> > + if (IS_ERR(pcs_regmap)) {
> > + ret = PTR_ERR(pcs_regmap);
> > + goto err_free_netdev;
> > + }
> > + mrc.regmap = pcs_regmap;
> > +
> > /* Rx IRQ */
> > priv->rx_irq = platform_get_irq_byname(pdev, "rx_irq");
> > if (priv->rx_irq == -ENXIO) {
> > @@ -1384,7 +1413,20 @@ static int altera_tse_probe(struct
> > platform_device *pdev) (unsigned long) control_port->start,
> > priv->rx_irq, priv->tx_irq);
> >
> > - priv->pcs = alt_tse_pcs_create(ndev, priv->pcs_base,
> > pcs_reg_width);
> > + snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii",
> > ndev->name);
> > + pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc);
> > + if (IS_ERR(pcs_bus)) {
> > + ret = PTR_ERR(pcs_bus);
> > + goto err_init_phy;
> > + }
> > +
> > + priv->pcs_mdiodev = mdio_device_create(pcs_bus, 0);
>
> mdio_device_create() can fail. Should that be handled here?
>
> > +
> > + priv->pcs = lynx_pcs_create(priv->pcs_mdiodev);
> > + if (!priv->pcs) {
> > + ret = -ENODEV;
> > + goto err_init_phy;
>
> Does this leak priv->pcs_mdiodev?
>
> > + }
> >
> > priv->phylink_config.dev = &ndev->dev;
> > priv->phylink_config.type = PHYLINK_NETDEV;
> > @@ -1407,11 +1449,12 @@ static int altera_tse_probe(struct
> > platform_device *pdev) if (IS_ERR(priv->phylink)) {
> > dev_err(&pdev->dev, "failed to create phylink\n");
> > ret = PTR_ERR(priv->phylink);
> > - goto err_init_phy;
> > + goto err_pcs;
>
> Does this leak priv->pcs ?
>
> > }
> >
> > return 0;
> > -
> > +err_pcs:
> > + mdio_device_free(priv->pcs_mdiodev);
> > err_init_phy:
> > unregister_netdev(ndev);
> > err_register_netdev:
> > @@ -1433,6 +1476,8 @@ static int altera_tse_remove(struct
> > platform_device *pdev) altera_tse_mdio_destroy(ndev);
> > unregister_netdev(ndev);
> > phylink_destroy(priv->phylink);
> > + mdio_device_free(priv->pcs_mdiodev);
> > +
> > free_netdev(ndev);
> >
> > return 0;
> > diff --git a/include/linux/mdio/mdio-regmap.h
> > b/include/linux/mdio/mdio-regmap.h index b8508f152552..679d9069846b
> > 100644 --- a/include/linux/mdio/mdio-regmap.h
> > +++ b/include/linux/mdio/mdio-regmap.h
> > @@ -7,6 +7,8 @@
> > #ifndef MDIO_REGMAP_H
> > #define MDIO_REGMAP_H
> >
> > +#include <linux/phy.h>
> > +
> > struct device;
> > struct regmap;
> >
>
> This hunk doesn't seem strictly related to the patch.
> Perhaps the include belongs elsewhere.
> Or the hunk belongs in another patch.
Indeed, I had the same issue in another patch in this series. I'll
re-split everything correctly.
Thank you for the review,
Maxime
next prev parent reply other threads:[~2023-05-26 17:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 7:42 [PATCH net-next v3 0/4] net: add a regmap-based mdio driver and drop TSE PCS Maxime Chevallier
2023-05-26 7:42 ` [PATCH net-next v3 1/4] net: mdio: Introduce a regmap-based mdio driver Maxime Chevallier
2023-05-26 10:21 ` Vladimir Oltean
2023-05-26 16:59 ` Maxime Chevallier
2023-05-26 7:42 ` [PATCH net-next v3 2/4] net: ethernet: altera-tse: Convert to mdio-regmap and use PCS Lynx Maxime Chevallier
2023-05-26 8:39 ` Simon Horman
2023-05-26 9:05 ` Russell King (Oracle)
2023-05-26 10:42 ` Russell King (Oracle)
2023-05-26 17:03 ` Maxime Chevallier [this message]
2023-05-26 7:42 ` [PATCH net-next v3 3/4] net: pcs: Drop the TSE PCS driver Maxime Chevallier
2023-05-26 8:43 ` Simon Horman
2023-05-26 17:07 ` Maxime Chevallier
2023-05-26 7:42 ` [PATCH net-next v3 4/4] net: stmmac: dwmac-sogfpga: use the lynx pcs driver Maxime Chevallier
2023-05-26 8:52 ` Simon Horman
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=20230526190304.0b9ce032@pc-7.home \
--to=maxime.chevallier@bootlin.com \
--cc=alexandre.torgue@foss.st.com \
--cc=alexis.lothore@bootlin.com \
--cc=andrew@lunn.ch \
--cc=broonie@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=ioana.ciornei@nxp.com \
--cc=joabreu@synopsys.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux@armlinux.org.uk \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peppe.cavallaro@st.com \
--cc=simon.horman@corigine.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.com \
/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;
as well as URLs for NNTP newsgroup(s).