From patchwork Thu Dec 7 21:12:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Halaney X-Patchwork-Id: 13483970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1237CC4167B for ; Thu, 7 Dec 2023 21:13:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=2bEDTlVye+s5UEipQLDC9VMub329X8zRwBHmbAj1BCg=; b=2y8V1cIXseCGC9 7Nf/BJbjLQ0xRkOo6WkfQxDOPOnVS9O8imGtGEJmGVC2K6rPch3mpY9nbbClbpGadNs+18SLVgFI8 oOKuQrId+3bpBjO0KbQcOXWKuSFjPrxzWjtoyW5QJ7nESEA96JPG51NWqVTRKjV8SrbPxZyNVLmtM txCEU6rQ482qCqoNL64RQ9Y8AIu7L0SDjxEWePd0G6R8rdKUPh2aLFAzVoJ5uajvgMig1Hk9c/MlV NbBrqKzxlMhzYx/NlyEXzVknu0iJpxUXoGfwgRiZqIUyDq3sEQxaYJgrKWPUkt+WwRU4NnybMnafS CUmFvywf6Jfhb8y6qbMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBLfz-00DvxK-1Z; Thu, 07 Dec 2023 21:12:55 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBLfw-00Dvvq-0E for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2023 21:12:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701983570; 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; bh=m0tm0lsXPlnCiFdUXwz3yeCYNRe8/nR8iqlVxg/Ese8=; b=boS7PvmUV+CxrMwZmUNFPqBTVEPqRI5FT4VrXcUTTKy0DpSkJyuT+MPZtxq8M2oJERjR0E vTDnwR9PA0STqH5mA+VtWU1GIv2Bp6arNWkzY+ipFEqbwnk6irpDMiV6Idjq6HdBrF8tjq RANyXihlIcZRnSl7029PZgwzDijaD9M= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-KSb0bQJxOl2fXMu_6RE-9w-1; Thu, 07 Dec 2023 16:12:48 -0500 X-MC-Unique: KSb0bQJxOl2fXMu_6RE-9w-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-77f10001de7so130703685a.3 for ; Thu, 07 Dec 2023 13:12:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701983568; x=1702588368; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=m0tm0lsXPlnCiFdUXwz3yeCYNRe8/nR8iqlVxg/Ese8=; b=ntI9Vfq5E4x65MgJda2zIPwB28qP9ITMRq2zEvrHM00Vu8SuZSUz/3xhCNsOTVzIIB uJV79BrVEu7l+JK8O9OC2C6+ggbSKzIeke17dxj76oMhD16OaA4u31Wxj1ygA/koZ/TV qS2uXfAKoX7uDOtO67AIa0MvnHcEsMgMfy91J3v0aCjzONQa8nwa67902l4eHek/CXtn Fx8TZNFaBy29JvVo3FfHbMEFiFlS/Pgr98AaxhBN2R8q8JVCUPVnvznrsBOGF2se3fdp Vat4YQazbdkqVJo12w6UHE4x9y7/0b/IuoUJsX2vFAmASbslWsEj7a1SKeLPQICmZUfE gbOQ== X-Gm-Message-State: AOJu0Yz3hP+UYTm2Wqe3DJEO+jhjAO4Wcasje1Qe77VwLpa5G97MMH7V b8t8oM8icGBMD4gcaxjp6Vim1L99hLVjsuwnuMIQ1iztGbnxP0rMh0xHZGDh1nPpc1tmbGRDnIP 6OZ2kVHN2mWAxZP/phiHskxtSEYQosLEe/TY= X-Received: by 2002:a05:620a:12d9:b0:77e:fba3:8206 with SMTP id e25-20020a05620a12d900b0077efba38206mr1847331qkl.156.1701983567817; Thu, 07 Dec 2023 13:12:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7z86zXmymay8jxRxW4MSE3B+0PAsE8XNJYAsWbEq3pdPF6yTm8ycxXKBFDbgo28pcWyd13w== X-Received: by 2002:a05:620a:12d9:b0:77e:fba3:8206 with SMTP id e25-20020a05620a12d900b0077efba38206mr1847324qkl.156.1701983567552; Thu, 07 Dec 2023 13:12:47 -0800 (PST) Received: from [192.168.1.164] ([2600:1700:1ff0:d0e0::47]) by smtp.gmail.com with ESMTPSA id rb3-20020a05620a8d0300b00774350813ccsm180707qkn.118.2023.12.07.13.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:12:47 -0800 (PST) From: Andrew Halaney Date: Thu, 07 Dec 2023 15:12:40 -0600 Subject: [PATCH net-next v3] net: stmmac: don't create a MDIO bus if unnecessary MIME-Version: 1.0 Message-Id: <20231207-stmmac-no-mdio-node-v3-1-34b870f2bafb@redhat.com> X-B4-Tracking: v=1; b=H4sIAEc1cmUC/22OQQ6DIBBFr2Jm3TEC1WpXvUfjAmGqJAUMENLGe PdSF1119f/PZF7eBpGCoQjXaoNA2UTjXRniVIFapJsJjS4beMMFY/yCMVkrFTqPVhtfUhMyPQ1 a9pK3eoDyuQZ6mNdBvYOjhI5eCcZyeQRvMS2B5I/a9E3PSmnPNWNdK5DhFObnbZo15Xp9foGLi cmH92GZ+YE9hHjT/RXKvFCEEErSeZiYkrdAepGpVt7CuO/7BxyLB074AAAA To: Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Andrew Halaney X-Mailer: b4 0.12.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_131252_182821_94F2AE58 X-CRM114-Status: GOOD ( 27.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Co-developed-by: Bartosz Golaszewski Signed-off-by: Bartosz Golaszewski Signed-off-by: Andrew Halaney Reviewed-by: Serge Semin --- Changes in v3: - Keep logic out of stmmac_probe_config_dt() since it's already massive (Serge) Changes in v2: - Handle the fixed-link + mdio case (Andrew Lunn) - Reworded commit message - Still handle the "legacy" case mentioned in the commit - Bit further refactoring of the function for readability - Link to v2: https://lore.kernel.org/r/20231206-stmmac-no-mdio-node-v2-1-333cae49b1ca@redhat.com - Link to v1: https://lore.kernel.org/netdev/20230808120254.11653-1-brgl@bgdev.pl/ --- .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 91 +++++++++++++--------- 1 file changed, 54 insertions(+), 37 deletions(-) --- base-commit: fd8a79b63710acb84321be3ce74be23c876873fb change-id: 20231127-stmmac-no-mdio-node-1db9da8a25d9 Best regards, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 1ffde555da47..d6079c1432c7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -296,62 +296,80 @@ 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) { + return mdio_node; +} + +/** + * stmmac_mdio_setup() - Populate platform related MDIO structures. + * @plat: driver data platform structure + * @np: devicetree node + * @dev: device pointer + * + * This searches for MDIO information from the devicetree. + * If an MDIO node is found, it's assigned to plat->mdio_node and + * plat->mdio_bus_data is allocated. + * If no connection can be determined, just plat->mdio_bus_data is allocated + * to indicate a bus should be created and scanned for a phy. + * If it's determined there's no MDIO bus needed, both are left NULL. + * + * This expects that plat->phy_node has already been searched for. + * + * Return: 0 on success, errno otherwise. + */ +static int stmmac_mdio_setup(struct plat_stmmacenet_data *plat, + struct device_node *np, struct device *dev) +{ + bool legacy_mdio; + + plat->mdio_node = stmmac_of_get_mdio(np); + 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); + /* 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(dev, "Deprecated MDIO bus assumption used\n"); + + if (plat->mdio_node || legacy_mdio) { + plat->mdio_bus_data = devm_kzalloc(dev, + sizeof(struct stmmac_mdio_bus_data), + GFP_KERNEL); if (!plat->mdio_bus_data) return -ENOMEM; @@ -471,8 +489,7 @@ 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); + rc = stmmac_mdio_setup(plat, np, &pdev->dev); if (rc) return ERR_PTR(rc);