Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp708426pxv; Thu, 15 Jul 2021 14:04:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVeOWtMxhr6iZfGoAP7xEUM/Hi7MdnaESKV/1FW6RblGFmsPl52HIiiKyNBCSf+A0Z7XQ5 X-Received: by 2002:a17:906:cb86:: with SMTP id mf6mr7806317ejb.116.1626383088021; Thu, 15 Jul 2021 14:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383088; cv=none; d=google.com; s=arc-20160816; b=mmAZ8SULUDOk+t231vQcYpdJBC6hTVbXRG5FJ+BUg+aCMiCcVb05spdMPCNQnJmzao i5cq4fHi3+nmi8C27lKlLTeS16SoI/TGHyWD752V69uekB/G2bSEdwtcHO9y1n9VQR8j Q+fzdVI9R5+/LbogG6sN4zAxL8DmCr1sEEU+1djqwKb5+kRfzJl7ktkuLbmu3eLTTQqg GpuqVD2yaaepCkriZyfgSOUP97M54zH5fC4BguDk8wtmgUBts/mY8yp0rYWiL/LugmHP w+xJcc+srido3s6kyZrIlhuXmSg1wSoXEIsp56ncqu5H7RbcjC+3AdmwBVkrhufa6hJj lQqQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eFyZyE7t0X0oAw0u0ag5szuu9iwlD4nCeu+vH3dCv0Q=; b=csqQ1AP847BvXaOhF65ny04x3zM67t2MEAQHiPrIiMw5UqTyWdWEtgo6tQTbApkWC3 +QYTppS0Z68SB35zuWctwuEcqyH0L5dZabef9wfpPOixz+QzibXiqqdNHvUXbMgDo9eh s8hg0AzMMBs8CN1VItsAr6RvQJbbDuep7KYRr8w+D9BCfhpkT2MxTNtiTun9CCT8UI+m 4p+FuONgcjsLRp6GdPG+DY7DnuE8sbTlUNQoqpmK75MXZqZhPGUFYf22Og8/sasCuCai 8eDx6GtjDPEs4sQT3QJ7Qw/1NHAPEDOsRSH1+7fiqAkUDkckUGDapB+iV/rafyT337mV qJIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hg8Da8vw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c18si8868196eds.371.2021.07.15.14.04.25; Thu, 15 Jul 2021 14:04:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hg8Da8vw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244063AbhGOTPd (ORCPT + 99 others); Thu, 15 Jul 2021 15:15:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:34728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238947AbhGOS6Z (ORCPT ); Thu, 15 Jul 2021 14:58:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 322F7613CF; Thu, 15 Jul 2021 18:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375331; bh=nAhI8lIzEIovRd+ILJuBnP4fLOSRmMpp03U/bbbWxKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hg8Da8vwW65MHOIEygFehT126C19JOM+pSNp3hQoggMCrNgoQHplBg4QyaeeCrEWG odiO/GtrgF4mppyQ9DGwAQuM5cuiL848HkpORG20CNUk2JgWMkWPKzNYLc+x6nkltE voN4EUaJX/SHOqOG0t5Zb9WzKWHhb+hEI4qjXxJM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.12 041/242] net: stmmac: the XPCS obscures a potential "PHY not found" error Date: Thu, 15 Jul 2021 20:36:43 +0200 Message-Id: <20210715182559.277798128@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean [ Upstream commit 4751d2aa321f2828d8c5d2f7ce4ed18a01e47f46 ] stmmac_mdio_register() has logic to search for PHYs on the MDIO bus and assign them IRQ lines, as well as to set priv->plat->phy_addr. If no PHY is found, the "found" variable remains set to 0 and the function errors out. After the introduction of commit f213bbe8a9d6 ("net: stmmac: Integrate it with DesignWare XPCS"), the "found" variable was immediately reused for searching for a PCS on the same MDIO bus. This can result in 2 types of potential problems (none of them seems to be seen on the only Intel system that sets has_xpcs = true, otherwise it would have been reported): 1. If a PCS is found but a PHY is not, then the code happily exits with no error. One might say "yes, but this is not possible, because of_mdiobus_register will probe a PHY for all MDIO addresses, including for the XPCS, so if an XPCS exists, then a PHY certainly exists too". Well, that is not true, see intel_mgbe_common_data(): /* Ensure mdio bus scan skips intel serdes and pcs-xpcs */ plat->mdio_bus_data->phy_mask = 1 << INTEL_MGBE_ADHOC_ADDR; plat->mdio_bus_data->phy_mask |= 1 << INTEL_MGBE_XPCS_ADDR; 2. A PHY is found but an MDIO device with the XPCS PHY ID isn't, and in that case, the error message will be "No PHY found". Confusing. Signed-off-by: Vladimir Oltean Link: https://lore.kernel.org/r/20210527155959.3270478-1-olteanv@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index d64116e0543e..a4ba27bf3131 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -444,6 +444,12 @@ int stmmac_mdio_register(struct net_device *ndev) found = 1; } + if (!found && !mdio_node) { + dev_warn(dev, "No PHY found\n"); + err = -ENODEV; + goto no_phy_found; + } + /* Try to probe the XPCS by scanning all addresses. */ if (priv->hw->xpcs) { struct mdio_xpcs_args *xpcs = &priv->hw->xpcs_args; @@ -452,6 +458,7 @@ int stmmac_mdio_register(struct net_device *ndev) xpcs->bus = new_bus; + found = 0; for (addr = 0; addr < max_addr; addr++) { xpcs->addr = addr; @@ -461,13 +468,12 @@ int stmmac_mdio_register(struct net_device *ndev) break; } } - } - if (!found && !mdio_node) { - dev_warn(dev, "No PHY found\n"); - mdiobus_unregister(new_bus); - mdiobus_free(new_bus); - return -ENODEV; + if (!found && !mdio_node) { + dev_warn(dev, "No XPCS found\n"); + err = -ENODEV; + goto no_xpcs_found; + } } bus_register_done: @@ -475,6 +481,9 @@ bus_register_done: return 0; +no_xpcs_found: +no_phy_found: + mdiobus_unregister(new_bus); bus_register_fail: mdiobus_free(new_bus); return err; -- 2.30.2