Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp240142pxx; Wed, 28 Oct 2020 03:49:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIadTX8TVoLyklNSDdmFp4q/wVOu3mbQ162i2eHv+rQ7SmFpt1EAY33J4obDX+3A5ZhQWA X-Received: by 2002:a17:906:2895:: with SMTP id o21mr7207171ejd.332.1603882193678; Wed, 28 Oct 2020 03:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603882193; cv=none; d=google.com; s=arc-20160816; b=mEfHaagx5fFO3u1zSQNhvwnA8TEx3zoYAoJyv/R7KhgxGHKIyiRUdhLZ0DI4UeG7SJ 3dYwKXOzCvTk6Up1WPznQs7NaVLYuQG5+WekjxqYsXNu5YerCvB6qTF7HyboWgHuvqeB Nzs9Qv7yRKCCKzNIRpxqnwUxHDstUVFLdW47mxHgNZl05T9qSP+zWeWK++HNOYJKZh1a FcCtcPyn8EK2MwZ+WxdaKBdVJGwGoWg4/mx9RsXrHuXbmXvGVve6q4cEewxby00D+x3t uLjd6I6b4icirkMMNmZaJl0I8djt5T2WvGSRWlSkxnnd89S8PMY3OSF3d7JLugRMeacf /lbA== 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=RH5WpVE+kGM9WDKlxGZ9lB0u+Fb/JSEET18lGNhwV5M=; b=R/JU8VWJVPuQs72mtClFzA2q3XmXoxJxSdC5LaSgZDbpQ0pzAJShguqcnCgJKGELP4 9XdE2TpptKsv5TPZGUWKJGWTRZ7n04LVRZALPL0QxpjKEDZpxe9bv3tJPbaHyKDFEI8W /p0DWVXHh2sTdXS70/H0ZiHHE5qQ9YpRMgf4Wg8+mj5mbUbrqhnOq/ZuLuP1Y3XtzefK +smd/N2+fV9ycVt5AMJ4x5QRxcPai2j0Zy4DrqlUTKhfO90j95k8HE2kVrQZPEmoBW5N kVMNcvq5AKrZM/YHsyC/AMAt8x0RE/m5aZVWfw2HgPWpW9QXfGB9zr3rSfS4Yx7cY9py GTyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tdpMCYEm; 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=fail (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 w11si2719069ejq.533.2020.10.28.03.49.31; Wed, 28 Oct 2020 03:49:53 -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=@kernel.org header.s=default header.b=tdpMCYEm; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751918AbgJ0OxE (ORCPT + 99 others); Tue, 27 Oct 2020 10:53:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:49760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1767839AbgJ0Otj (ORCPT ); Tue, 27 Oct 2020 10:49:39 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6106A21556; Tue, 27 Oct 2020 14:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810178; bh=/5GQWw4D3rmI8Jl9NL7ePNH4PhUrnkEXubXjxBQkMXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tdpMCYEmfn3EPuyyDY6knK9+sXDO7wbP2Cq7NCDUDmAjUe/jIjwnP9DRludYGS6mq VI9m7qKa/uV2YLrXk6T8M/EAMYQ6SD5CjJ82JcCkKbl+GbRH78t9oaAHwgzKGBveRx 0fPSY06n+byFrs8zy9LHWWISn3tOihIvBBuPqDWk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Vasut , Christoph Niedermaier , "David S. Miller" , NXP Linux Team , Richard Leitner , Shawn Guo , Jakub Kicinski Subject: [PATCH 5.8 007/633] net: fec: Fix phy_device lookup for phy_reset_after_clk_enable() Date: Tue, 27 Oct 2020 14:45:50 +0100 Message-Id: <20201027135523.026579559@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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: Marek Vasut [ Upstream commit 64a632da538a6827fad0ea461925cedb9899ebe2 ] The phy_reset_after_clk_enable() is always called with ndev->phydev, however that pointer may be NULL even though the PHY device instance already exists and is sufficient to perform the PHY reset. This condition happens in fec_open(), where the clock must be enabled first, then the PHY must be reset, and then the PHY IDs can be read out of the PHY. If the PHY still is not bound to the MAC, but there is OF PHY node and a matching PHY device instance already, use the OF PHY node to obtain the PHY device instance, and then use that PHY device instance when triggering the PHY reset. Fixes: 1b0a83ac04e3 ("net: fec: add phy_reset_after_clk_enable() support") Signed-off-by: Marek Vasut Cc: Christoph Niedermaier Cc: David S. Miller Cc: NXP Linux Team Cc: Richard Leitner Cc: Shawn Guo Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/freescale/fec_main.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1913,6 +1913,27 @@ out: return ret; } +static void fec_enet_phy_reset_after_clk_enable(struct net_device *ndev) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct phy_device *phy_dev = ndev->phydev; + + if (phy_dev) { + phy_reset_after_clk_enable(phy_dev); + } else if (fep->phy_node) { + /* + * If the PHY still is not bound to the MAC, but there is + * OF PHY node and a matching PHY device instance already, + * use the OF PHY node to obtain the PHY device instance, + * and then use that PHY device instance when triggering + * the PHY reset. + */ + phy_dev = of_phy_find_device(fep->phy_node); + phy_reset_after_clk_enable(phy_dev); + put_device(&phy_dev->mdio.dev); + } +} + static int fec_enet_clk_enable(struct net_device *ndev, bool enable) { struct fec_enet_private *fep = netdev_priv(ndev); @@ -1939,7 +1960,7 @@ static int fec_enet_clk_enable(struct ne if (ret) goto failed_clk_ref; - phy_reset_after_clk_enable(ndev->phydev); + fec_enet_phy_reset_after_clk_enable(ndev); } else { clk_disable_unprepare(fep->clk_enet_out); if (fep->clk_ptp) { @@ -2994,7 +3015,7 @@ fec_enet_open(struct net_device *ndev) * phy_reset_after_clk_enable() before because the PHY wasn't probed. */ if (reset_again) - phy_reset_after_clk_enable(ndev->phydev); + fec_enet_phy_reset_after_clk_enable(ndev); if (fep->quirks & FEC_QUIRK_ERR006687) imx6q_cpuidle_fec_irqs_used();