Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1595445rdb; Thu, 7 Dec 2023 03:56:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkBIVtTJn80ddqbWA1I0gT2gCenzxLXWawi517qxUBjKN/olnzvmsluxGag0Vl58PO70bn X-Received: by 2002:a05:6a20:9410:b0:18f:97c:9298 with SMTP id hl16-20020a056a20941000b0018f097c9298mr1718486pzb.125.1701950210603; Thu, 07 Dec 2023 03:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701950210; cv=none; d=google.com; s=arc-20160816; b=LU26sOMZgufQtpeg0fINqZxQS9NCv96n9rE8anTjO/hY8uvmMKX74iaQ0SeSyj1GQY Tyt6QmDxFQ9tMmHdpadr3mcWTOR5OBELo7lffnnrC7FgCv3ITW4fyqheiThiZxndJqLG QIP245a6PAUi2llX5BXh4JuvqDZavq1teDjVzHjUCiZVruMahr94akgRXORsNfY9Ah8U o94u3v123NcDsOoJEYbYuQPhIFTAWnC979CQpjWHUMOHXbUmpbGpDTH9DvjTOcyZunjY OIqhoRCmDJh6GrpFDjSZ8/PZ2vVz52afEQvWY+DBlInM2qLGh1oCqAZZZlJtWUqwKDjk DKdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Gls+WyCxKy2/T0zF66LnozzlvZPMTRXDjtHjhUio7sc=; fh=9E8n55BilXOQC0AR//CJQ9rU1RICdG0DsmpTdR9M0Kg=; b=cY653xvBgsP25Rgl8z532p6AygMQ99cifzeAuQnV1mrmBItF921d/+P4VL9V+LM5WU AZurwGJltL3/UHox5rL4Cy5JEAgR7QlrIybdUqJow3BFb38d21VHqY4TbZzM3sGQvu35 /ySb7/ddkDWBJ4+ZdGHpqW2C3yhYnvzKPQB3J93BeqkVJafWekN+0QuAUOWxk+9JoK2C aFtYQYP8824ClagzOyEwI2iIc60lkhBkMnWXReKr7x4N2rtQ3dfoPbU+PWUI8Y9J1U50 SWEJVY3o9gFQJe8uEcFjPhdxmM18zN+ceHjXM1R5ZM/gvvogvqQajHu1R4voMWoDoqGH 6klw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=B05OfpvM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id ay4-20020a056a00300400b006cea1c8a56csi1120299pfb.78.2023.12.07.03.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 03:56:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=B05OfpvM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 22390808726A; Thu, 7 Dec 2023 03:56:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232523AbjLGL42 (ORCPT + 99 others); Thu, 7 Dec 2023 06:56:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230234AbjLGL40 (ORCPT ); Thu, 7 Dec 2023 06:56:26 -0500 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A61A813D; Thu, 7 Dec 2023 03:56:31 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-50be58a751cso646664e87.2; Thu, 07 Dec 2023 03:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701950190; x=1702554990; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Gls+WyCxKy2/T0zF66LnozzlvZPMTRXDjtHjhUio7sc=; b=B05OfpvMo4MD2GjMGSLSZdtcE0cvCkVZ86xCEHph9MM4oJmhGV8OxA22ZKwQe89qFC hE4xO7oKuibCXOAnexObBtPKyUaK3ZmYk/k2rdZ6WXa/GWGA4+29zeZwEtLTT1PW0QeT UZEiPT9i9VGRIXR319w+APxIxXoornjJ4Ii6pEytiF6KXs/qi/y5E5lCxe+W+41SJqAY 5OR5yxfL+Jte5I8fl85DBVr9p29VBFrhoHbnpKaZg1kSkhxcl3PjKoixxpFdNVVXNcN2 4Ebl8DisSFcSTAhq6zSvLDY5Zk5DGhPqwTdTzz9Edc2zedoKzHguk+Hug+evsi2OByb7 +khw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701950190; x=1702554990; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Gls+WyCxKy2/T0zF66LnozzlvZPMTRXDjtHjhUio7sc=; b=P2gX2VLOu7b6wpzZWrgtCcKqtV8oIl7tFrIrEoA4NIBBy0T47yd1RblEfGA5vBbjMt fSP8mDVKhSC3NYuVyizj4JXJZbeCNHKnJt/jJLMBb6AxEJRI0FAsxZCSA5/SRMuQsRcW t9h3DZhuXF8fgFaZB3xhoa+SN9rhZvio8Bo2YZf7LnuA1DRR8RFu8xCAiy61xAIZZkED XWDj39rj6rwpOQT4ZumGCXrz8K0S0BBawpmuCcpZQXXRX31H22l/ZlNvS2VQOhrsqWWB cho4BLWc+jDqc1Kt3iC4O35+FkLDV1ge65fUeRHYBjuqaBoxkSLAz4zLH9T7EjkAKNle tQFg== X-Gm-Message-State: AOJu0YwVDlq4jyGtDHZtC6MJPOSNXKT/sYgMwyKunwlUSFEL7EAR+5jZ T4cIHz6SdROmb2Hy7N+yF2w= X-Received: by 2002:a05:6512:4859:b0:50b:fb93:bb02 with SMTP id ep25-20020a056512485900b0050bfb93bb02mr1201865lfb.115.1701950189592; Thu, 07 Dec 2023 03:56:29 -0800 (PST) Received: from mobilestation ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id c10-20020a056512074a00b0050bf1e8950esm154936lfs.10.2023.12.07.03.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 03:56:29 -0800 (PST) Date: Thu, 7 Dec 2023 14:56:25 +0300 From: Serge Semin To: Andrew Halaney Cc: Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH net-next v2] net: stmmac: don't create a MDIO bus if unnecessary Message-ID: References: <20231206-stmmac-no-mdio-node-v2-1-333cae49b1ca@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231206-stmmac-no-mdio-node-v2-1-333cae49b1ca@redhat.com> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 07 Dec 2023 03:56:46 -0800 (PST) Hi Andrew On Wed, Dec 06, 2023 at 05:46:09PM -0600, Andrew Halaney wrote: > The stmmac_dt_phy() function, which parses the devicetree node of the > MAC and ultimately causes MDIO bus allocation, misinterprets what > fixed-link means in relation to the MAC's MDIO bus. This results in > a MDIO bus being created in situations it need not be. > > Currently a MDIO bus is created if the description is either: > > 1. Not fixed-link > 2. fixed-link but contains a MDIO bus as well > > The "1" case above isn't always accurate. If there's a phy-handle, > it could be referencing a phy on another MDIO controller's bus[1]. In > this case currently the MAC will make a MDIO bus and scan it all > anyways unnecessarily. > > There's also a lot of upstream devicetrees[2] that expect a MDIO bus to > be created and scanned for a phy. This case can also be inferred from > the platform description by not having a phy-handle && not being > fixed-link. This hits case "1" in the current driver's logic. > > Let's improve the logic to create a MDIO bus if either: > > - Devicetree contains a MDIO bus > - !fixed-link && !phy-handle (legacy handling) > > Below upstream devicetree snippets can be found that explain some of > the cases above more concretely. > > Here's[0] a devicetree example where the MAC is both fixed-link and > driving a switch on MDIO (case "2" above). This needs a MDIO bus to > be created: > > &fec1 { > phy-mode = "rmii"; > > fixed-link { > speed = <100>; > full-duplex; > }; > > mdio1: mdio { > switch0: switch0@0 { > compatible = "marvell,mv88e6190"; > pinctrl-0 = <&pinctrl_gpio_switch0>; > }; > }; > }; > > Here's[1] an example where there is no MDIO bus or fixed-link for > the ethernet1 MAC, so no MDIO bus should be created since ethernet0 > is the MDIO master for ethernet1's phy: > > ðernet0 { > phy-mode = "sgmii"; > phy-handle = <&sgmii_phy0>; > > mdio { > compatible = "snps,dwmac-mdio"; > sgmii_phy0: phy@8 { > compatible = "ethernet-phy-id0141.0dd4"; > reg = <0x8>; > device_type = "ethernet-phy"; > }; > > sgmii_phy1: phy@a { > compatible = "ethernet-phy-id0141.0dd4"; > reg = <0xa>; > device_type = "ethernet-phy"; > }; > }; > }; > > ðernet1 { > phy-mode = "sgmii"; > phy-handle = <&sgmii_phy1>; > }; > > Finally there's descriptions like this[2] which don't describe the > MDIO bus but expect it to be created and the whole address space > scanned for a phy since there's no phy-handle or fixed-link described: > > &gmac { > phy-supply = <&vcc_lan>; > phy-mode = "rmii"; > snps,reset-gpio = <&gpio3 RK_PB4 GPIO_ACTIVE_HIGH>; > snps,reset-active-low; > snps,reset-delays-us = <0 10000 1000000>; > }; > > [0] https://elixir.bootlin.com/linux/v6.5-rc5/source/arch/arm/boot/dts/nxp/vf/vf610-zii-ssmb-dtu.dts > [1] https://elixir.bootlin.com/linux/v6.6-rc5/source/arch/arm64/boot/dts/qcom/sa8775p-ride.dts > [2] https://elixir.bootlin.com/linux/v6.6-rc5/source/arch/arm64/boot/dts/rockchip/rk3368-r88.dts#L164 Thank you for the patch. Please find a comment below. > > Co-developed-by: Bartosz Golaszewski > Signed-off-by: Bartosz Golaszewski > Signed-off-by: Andrew Halaney > --- > .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 85 ++++++++++------------ > 1 file changed, 37 insertions(+), 48 deletions(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c > index 1ffde555da47..7da461fe93f6 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c > @@ -296,69 +296,39 @@ static int stmmac_mtl_setup(struct platform_device *pdev, > } > > /** > - * stmmac_dt_phy - parse device-tree driver parameters to allocate PHY resources > - * @plat: driver data platform structure > - * @np: device tree node > - * @dev: device pointer > - * Description: > - * The mdio bus will be allocated in case of a phy transceiver is on board; > - * it will be NULL if the fixed-link is configured. > - * If there is the "snps,dwmac-mdio" sub-node the mdio will be allocated > - * in any case (for DSA, mdio must be registered even if fixed-link). > - * The table below sums the supported configurations: > - * ------------------------------- > - * snps,phy-addr | Y > - * ------------------------------- > - * phy-handle | Y > - * ------------------------------- > - * fixed-link | N > - * ------------------------------- > - * snps,dwmac-mdio | > - * even if | Y > - * fixed-link | > - * ------------------------------- > + * stmmac_of_get_mdio() - Gets the MDIO bus from the devicetree > + * @np: devicetree node > * > - * It returns 0 in case of success otherwise -ENODEV. > + * The MDIO bus will be searched for in the following ways: > + * 1. The compatible is "snps,dwc-qos-ethernet-4.10" && a "mdio" named > + * child node exists > + * 2. A child node with the "snps,dwmac-mdio" compatible is present > + * > + * Return: The MDIO node if present otherwise NULL > */ > -static int stmmac_dt_phy(struct plat_stmmacenet_data *plat, > - struct device_node *np, struct device *dev) > +static struct device_node *stmmac_of_get_mdio(struct device_node *np) > { > - bool mdio = !of_phy_is_fixed_link(np); > static const struct of_device_id need_mdio_ids[] = { > { .compatible = "snps,dwc-qos-ethernet-4.10" }, > {}, > }; > + struct device_node *mdio_node = NULL; > > if (of_match_node(need_mdio_ids, np)) { > - plat->mdio_node = of_get_child_by_name(np, "mdio"); > + mdio_node = of_get_child_by_name(np, "mdio"); > } else { > /** > * If snps,dwmac-mdio is passed from DT, always register > * the MDIO > */ > - for_each_child_of_node(np, plat->mdio_node) { > - if (of_device_is_compatible(plat->mdio_node, > + for_each_child_of_node(np, mdio_node) { > + if (of_device_is_compatible(mdio_node, > "snps,dwmac-mdio")) > break; > } > } > > - if (plat->mdio_node) { > - dev_dbg(dev, "Found MDIO subnode\n"); > - mdio = true; > - } > - > - if (mdio) { > - plat->mdio_bus_data = > - devm_kzalloc(dev, sizeof(struct stmmac_mdio_bus_data), > - GFP_KERNEL); > - if (!plat->mdio_bus_data) > - return -ENOMEM; > - > - plat->mdio_bus_data->needs_reset = true; > - } > - > - return 0; > + return mdio_node; > } > > /** > @@ -417,6 +387,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) > struct device_node *np = pdev->dev.of_node; > struct plat_stmmacenet_data *plat; > struct stmmac_dma_cfg *dma_cfg; > + bool legacy_mdio; > int phy_mode; > void *ret; > int rc; > @@ -471,10 +442,28 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) > if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0) > dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n"); > > - /* To Configure PHY by using all device-tree supported properties */ > - rc = stmmac_dt_phy(plat, np, &pdev->dev); > - if (rc) > - return ERR_PTR(rc); > + plat->mdio_node = stmmac_of_get_mdio(np); > + if (plat->mdio_node) > + dev_dbg(&pdev->dev, "Found MDIO subnode\n"); > + > + /* Legacy devicetrees allowed for no MDIO bus description and expect > + * the bus to be scanned for devices. If there's no phy or fixed-link > + * described assume this is the case since there must be something > + * connected to the MAC. > + */ > + legacy_mdio = !of_phy_is_fixed_link(np) && !plat->phy_node; > + if (legacy_mdio) > + dev_info(&pdev->dev, "Deprecated MDIO bus assumption used\n"); > + > + if (plat->mdio_node || legacy_mdio) { > + plat->mdio_bus_data = devm_kzalloc(&pdev->dev, > + sizeof(struct stmmac_mdio_bus_data), > + GFP_KERNEL); > + if (!plat->mdio_bus_data) > + return ERR_PTR(-ENOMEM); > + > + plat->mdio_bus_data->needs_reset = true; > + } Why did you decide to move this out of the dedicated function? stmmac_probe_config_dt() is already overwhelmed with various non-coherent actions. The method has already got to being too long to follow the kernel coding style limit (I have got a not submitted yet cleanup patchset which step-by-step fixes that). Could you please get the chunk above back to the respective function and, for instance, just change it's name to something like stmmac_mdio_setup()? (I prefer having "_setup" suffix because some of the locally defined static methods already use it: stmmac_axi_setup(), stmmac_mtl_setup().) -Serge(y) > > of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size); > > > --- > base-commit: fd8a79b63710acb84321be3ce74be23c876873fb > change-id: 20231127-stmmac-no-mdio-node-1db9da8a25d9 > > Best regards, > -- > Andrew Halaney > >