Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2722627rwd; Fri, 26 May 2023 10:13:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4d93rYH6KSU9v5R+gftguv4GVA0i0jyYtmbLm8b5RkHQDCtV3DbAF501uxq/3ro+myF6J4 X-Received: by 2002:a05:6a20:7d9f:b0:10d:d42:f6bc with SMTP id v31-20020a056a207d9f00b0010d0d42f6bcmr3608810pzj.41.1685121182651; Fri, 26 May 2023 10:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685121182; cv=none; d=google.com; s=arc-20160816; b=wS3YA7pq141uvVHQibKupPTVvydNGQfUfmvVnE8/Hm2kvqnZtZlfmHx9k7y0MvzHU6 nkKRrX8VjEIiTFteHBeYLnXQOkCK+b5RF5pxXC8Y19wB1SxNzeqMGjKO6tcXpTgAS0m2 EEXA52cgUqcvqIY+1dbbJEhfP7WQTLkjOcn8npVXfBAxhk52pzKVw0JYoOYHs71IPHC6 FW9+PekKmNaB+VJqVNglWPv9jcoRFTns2nSGqAMt5UBo+VrsbvFFzx2SH8D7umOm1rCd hXOUma01E6QJoM6FmgY7OEIelMpuCTxgyj3GK6xGSlva1so2JlHRmHuphn9IMmn7bDfV Q+DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=OWL96i2b6wLdc7YFdYrED44ksL215UVHjxBXdsVvpkg=; b=o3EuO4ipCz7cWZQy8+oRt2Po8itFWmKVginmCadtUt1qfWucB6nSyI1qtm0lUIstTc /TObNfsPDQfHOjFRiTcYOLmsn8EHTzPoRYRhFW3exMKLFoBrtWg6k6SlvSJd5gRNu6Nm t2FK3dR71yhYScUZk6lfE9hEEisoMvoXYnRMiQ1dajG9GmdNVsc1GLXhoi2wOigBJygi s7y6Q/gQUBI24tihfL6+0e0M2Vdtzkd4qSmxw5+VVVPH29AC1V1JzU6omqCtCFh8NoNi 2NlFGkbNGNhSskA2RyYwLeJRtY0VZfJU+ZvSsewofmQkSk/fGh3XABxXb3UO1On3CKr1 TIpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dJrvSZ0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i189-20020a6387c6000000b0053f352478fasi3477527pge.307.2023.05.26.10.12.50; Fri, 26 May 2023 10:13:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dJrvSZ0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbjEZRDO (ORCPT + 99 others); Fri, 26 May 2023 13:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjEZRDN (ORCPT ); Fri, 26 May 2023 13:03:13 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1C3BC; Fri, 26 May 2023 10:03:10 -0700 (PDT) X-GND-Sasl: maxime.chevallier@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1685120589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OWL96i2b6wLdc7YFdYrED44ksL215UVHjxBXdsVvpkg=; b=dJrvSZ0w7jWKXlkvJy6LRn2l1Po5KnPlV9dToIWd+vf2A66cp3cQTc13GLMXU8aOUicbcO m9zQsJbqFN1Ja+oSK1YgC/pP7Yzz5rflqUDLjRFR5gvZLveyuQlhLc0qysL45sCA4QdSJK O42yMaMjZ194KFrM/RYpm7HX78FlKY5JM05ChCIv+egvwu9gb2pleQF9SvDJPmk3fNk2JF oIl8xNiWOKqUFxhQhB01EUL2rOg3pH/gSNKlnDMSutaf0tPRDqGe+wUYCxCSrST3CjUha4 2JYgkknvshk1s/ftK74053h1F/fQEEEBiVwrUdo+TKsxdezrI1GV8PxWm3US0w== X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id CFCD0C000C; Fri, 26 May 2023 17:03:05 +0000 (UTC) Date: Fri, 26 May 2023 19:03:04 +0200 From: Maxime Chevallier To: Simon Horman Cc: Mark Brown , davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alexis.lothore@bootlin.com, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Florian Fainelli , Heiner Kallweit , Russell King , Vladimir Oltean , Ioana Ciornei , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Maxime Coquelin , Jose Abreu , Alexandre Torgue , Giuseppe Cavallaro Subject: Re: [PATCH net-next v3 2/4] net: ethernet: altera-tse: Convert to mdio-regmap and use PCS Lynx Message-ID: <20230526190304.0b9ce032@pc-7.home> In-Reply-To: References: <20230526074252.480200-1-maxime.chevallier@bootlin.com> <20230526074252.480200-3-maxime.chevallier@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Simon, On Fri, 26 May 2023 10:39:08 +0200 Simon Horman 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 > > 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 > > + > > 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