From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70780ECE58F for ; Tue, 15 Oct 2019 22:09:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B5D820854 for ; Tue, 15 Oct 2019 22:09:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="Gs3ZYcFM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389106AbfJOWJm (ORCPT ); Tue, 15 Oct 2019 18:09:42 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:46750 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726231AbfJOWJm (ORCPT ); Tue, 15 Oct 2019 18:09:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VQY7kyXQnV7HJfQmywx1SmCW7S/WPSYFdOWu76GYWnY=; b=Gs3ZYcFMXya+INRHGOSEM2hnZ V4Lxsuo5n2EqcV+3JNqXnyg8k8J1cqtxpWUEFy7J/PBXX6e7F8/Xk1vAGU5CMpYzf35fePzKYAksB YlhdDdWjaPeETOOpUcuLbxkJLJy13Sr2BM57hwJIPJvfQkUJIid2+WDgVWpuxbDolpuCkBesV6SnE dn2fS+AFcM2jMlKxtFrHVg0jm2eupU2RNL94eNWUodfXZbA+HvsVBQG4awdesxQc5jjzrsIB0eb/a lFYaaxlv3JIfIUFfUTFihRZZ5kJXRypiUPhykdUDWKqszGKq3XMOwpz14p3S4oOfAK9W/jL+qT57i o4DTegDDw==; Received: from shell.armlinux.org.uk ([2002:4e20:1eda:1:5054:ff:fe00:4ec]:51296) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iKV0T-00076f-Jh; Tue, 15 Oct 2019 23:09:29 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1iKV0P-0006YJ-W2; Tue, 15 Oct 2019 23:09:26 +0100 Date: Tue, 15 Oct 2019 23:09:25 +0100 From: Russell King - ARM Linux admin To: Heiner Kallweit Cc: Woojung Huh , Microchip Linux Driver Support , Andrew Lunn , Florian Fainelli , Daniel Wagner , netdev@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Stefan Wahren , linux-arm-kernel@lists.infradead.org, linux-rpi-kernel@lists.infradead.org Subject: Re: lan78xx and phy_state_machine Message-ID: <20191015220925.GW25745@shell.armlinux.org.uk> References: <20191014140604.iddhmg5ckqhzlbkw@beryllium.lan> <20191014163004.GP25745@shell.armlinux.org.uk> <20191014192529.z7c5x6hzixxeplvw@beryllium.lan> <25cfc92d-f72b-d195-71b1-f5f238c7988d@gmx.net> <20191014221211.GR25745@shell.armlinux.org.uk> <524267e6-df8e-d884-aeef-1ed8700e4e58@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <524267e6-df8e-d884-aeef-1ed8700e4e58@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Oct 15, 2019 at 09:38:22PM +0200, Heiner Kallweit wrote: > On 15.10.2019 00:12, Russell King - ARM Linux admin wrote: > > On Mon, Oct 14, 2019 at 10:20:15PM +0200, Heiner Kallweit wrote: > >> On 14.10.2019 21:51, Stefan Wahren wrote: > >>> [add more recipients] > >>> > >>> Am 14.10.19 um 21:25 schrieb Daniel Wagner: > >>>> Moving the phy_prepare_link() up in phy_connect_direct() ensures that > >>>> phydev->adjust_link is set when the phy_check_link_status() is called. > >>>> > >>>> diff --git a/drivers/net/phy/phy_device.c > >>>> b/drivers/net/phy/phy_device.c index 9d2bbb13293e..2a61812bcb0d 100644 > >>>> --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c > >>>> @@ -951,11 +951,12 @@ int phy_connect_direct(struct net_device *dev, > >>>> struct phy_device *phydev, if (!dev) return -EINVAL; > >>>> > >>>> + phy_prepare_link(phydev, handler); > >>>> + > >>>> rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); > >>>> if (rc) > >> > >> If phy_attach_direct() fails we may have to reset phydev->adjust_link to NULL, > >> as we do in phy_disconnect(). Apart from that change looks good to me. > > > > Sorry, but it doesn't look good to me. > > > > I think there's a deeper question here - why is the phy state machine > > trying to call the link change function during attach? > After your comment I had a closer look at the lm78xx driver and few things > look suspicious: > > - lan78xx_phy_init() (incl. the call to phy_connect_direct()) is called > after register_netdev(). This may cause races. That isn't a problem. We have lots of network device drivers that do this - in their open() function. > - The following is wrong, irq = 0 doesn't mean polling. > PHY_POLL is defined as -1. Also in case of irq = 0 phy_interrupt_is_valid() > returns true. > > /* if phyirq is not set, use polling mode in phylib */ > if (dev->domain_data.phyirq > 0) > phydev->irq = dev->domain_data.phyirq; > else > phydev->irq = 0; Also unlikely to be the cause of this problem. phy_connect_direct() is called with an adjust link function, which is set via phy_prepare_link() in phy_connect_direct(), before interrupts are even considered. So, the window for the bug is somewhere before the call to phy_prepare_link() in phy_connect_direct(), but after lan78xx_mdio_init(). > - Manually calling genphy_config_aneg() in lan78xx_phy_init() isn't > needed, however this should not cause our problem. Again, way after the point where phydev->adjust_link is non-NULL, so this can't be it. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF3C1ECE58F for ; Tue, 15 Oct 2019 22:12:06 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B454B20873 for ; Tue, 15 Oct 2019 22:12:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ft9CF2pu"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="Gs3ZYcFM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B454B20873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XpErCmFjvN9DRqL/nzzKuelnvYWC23vnfFoiWwQyd0g=; b=Ft9CF2puko3wX/ 18Y3xTHGeqvwwYc7nWeIavW5w6BPfozltS9C8TUAgqSu3JzuNEJ6nPzavevFV8w532kAq6bv2+vtZ iW4i6EF/R/FxLM4cbyzkzM4mY5PQxmaGa38Lggm+DhEAKNoVTRjeiUIKSttnjOEKCL+DHSog6uUZT Tlqwg6Gc6U2gAOILIvDxIMPIGCsu+ptlahKDGEC/xkjumq0G9tiJlBr61j+JND+j7dO3ze0zQUc9V lH+Nle6/oerUH3H0biK+1c9ZzvdHdxIYIO/hfbDw1D0/jvejX/tZklWuZSVO7Qw2O74nD1M020fuD rnj6bVWOdal3EC3QMX+A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iKV2u-0006BS-1c; Tue, 15 Oct 2019 22:12:00 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iKV2p-0004ln-4H; Tue, 15 Oct 2019 22:11:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VQY7kyXQnV7HJfQmywx1SmCW7S/WPSYFdOWu76GYWnY=; b=Gs3ZYcFMXya+INRHGOSEM2hnZ V4Lxsuo5n2EqcV+3JNqXnyg8k8J1cqtxpWUEFy7J/PBXX6e7F8/Xk1vAGU5CMpYzf35fePzKYAksB YlhdDdWjaPeETOOpUcuLbxkJLJy13Sr2BM57hwJIPJvfQkUJIid2+WDgVWpuxbDolpuCkBesV6SnE dn2fS+AFcM2jMlKxtFrHVg0jm2eupU2RNL94eNWUodfXZbA+HvsVBQG4awdesxQc5jjzrsIB0eb/a lFYaaxlv3JIfIUFfUTFihRZZ5kJXRypiUPhykdUDWKqszGKq3XMOwpz14p3S4oOfAK9W/jL+qT57i o4DTegDDw==; Received: from shell.armlinux.org.uk ([2002:4e20:1eda:1:5054:ff:fe00:4ec]:51296) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iKV0T-00076f-Jh; Tue, 15 Oct 2019 23:09:29 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1iKV0P-0006YJ-W2; Tue, 15 Oct 2019 23:09:26 +0100 Date: Tue, 15 Oct 2019 23:09:25 +0100 From: Russell King - ARM Linux admin To: Heiner Kallweit Subject: Re: lan78xx and phy_state_machine Message-ID: <20191015220925.GW25745@shell.armlinux.org.uk> References: <20191014140604.iddhmg5ckqhzlbkw@beryllium.lan> <20191014163004.GP25745@shell.armlinux.org.uk> <20191014192529.z7c5x6hzixxeplvw@beryllium.lan> <25cfc92d-f72b-d195-71b1-f5f238c7988d@gmx.net> <20191014221211.GR25745@shell.armlinux.org.uk> <524267e6-df8e-d884-aeef-1ed8700e4e58@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <524267e6-df8e-d884-aeef-1ed8700e4e58@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191015_151155_173064_A8A774E6 X-CRM114-Status: GOOD ( 18.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Woojung Huh , Andrew Lunn , Florian Fainelli , Daniel Wagner , netdev@vger.kernel.org, Microchip Linux Driver Support , bcm-kernel-feedback-list@broadcom.com, Stefan Wahren , linux-arm-kernel@lists.infradead.org, linux-rpi-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Oct 15, 2019 at 09:38:22PM +0200, Heiner Kallweit wrote: > On 15.10.2019 00:12, Russell King - ARM Linux admin wrote: > > On Mon, Oct 14, 2019 at 10:20:15PM +0200, Heiner Kallweit wrote: > >> On 14.10.2019 21:51, Stefan Wahren wrote: > >>> [add more recipients] > >>> > >>> Am 14.10.19 um 21:25 schrieb Daniel Wagner: > >>>> Moving the phy_prepare_link() up in phy_connect_direct() ensures that > >>>> phydev->adjust_link is set when the phy_check_link_status() is called. > >>>> > >>>> diff --git a/drivers/net/phy/phy_device.c > >>>> b/drivers/net/phy/phy_device.c index 9d2bbb13293e..2a61812bcb0d 100644 > >>>> --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c > >>>> @@ -951,11 +951,12 @@ int phy_connect_direct(struct net_device *dev, > >>>> struct phy_device *phydev, if (!dev) return -EINVAL; > >>>> > >>>> + phy_prepare_link(phydev, handler); > >>>> + > >>>> rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); > >>>> if (rc) > >> > >> If phy_attach_direct() fails we may have to reset phydev->adjust_link to NULL, > >> as we do in phy_disconnect(). Apart from that change looks good to me. > > > > Sorry, but it doesn't look good to me. > > > > I think there's a deeper question here - why is the phy state machine > > trying to call the link change function during attach? > After your comment I had a closer look at the lm78xx driver and few things > look suspicious: > > - lan78xx_phy_init() (incl. the call to phy_connect_direct()) is called > after register_netdev(). This may cause races. That isn't a problem. We have lots of network device drivers that do this - in their open() function. > - The following is wrong, irq = 0 doesn't mean polling. > PHY_POLL is defined as -1. Also in case of irq = 0 phy_interrupt_is_valid() > returns true. > > /* if phyirq is not set, use polling mode in phylib */ > if (dev->domain_data.phyirq > 0) > phydev->irq = dev->domain_data.phyirq; > else > phydev->irq = 0; Also unlikely to be the cause of this problem. phy_connect_direct() is called with an adjust link function, which is set via phy_prepare_link() in phy_connect_direct(), before interrupts are even considered. So, the window for the bug is somewhere before the call to phy_prepare_link() in phy_connect_direct(), but after lan78xx_mdio_init(). > - Manually calling genphy_config_aneg() in lan78xx_phy_init() isn't > needed, however this should not cause our problem. Again, way after the point where phydev->adjust_link is non-NULL, so this can't be it. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel