Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758178AbdCUQdB (ORCPT ); Tue, 21 Mar 2017 12:33:01 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36823 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756993AbdCUQc4 (ORCPT ); Tue, 21 Mar 2017 12:32:56 -0400 Subject: Re: [PATCH net-next] stmmac: call stmmac_init_phy from stmmac_dvr_probe To: Niklas Cassel , peppe.cavallaro@st.com, alexandre.torgue@st.com, Joao.Pinto@synopsys.com References: <20170320172915.8313-1-niklass@axis.com> <257f3b05-805d-fd59-5435-89ede6b0fe4b@gmail.com> <82fbc595-5269-bcd9-d75f-778fbd8d2bdb@axis.com> <285d0fe6-9257-5e44-1272-be22dc271094@gmail.com> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org From: Florian Fainelli Message-ID: Date: Tue, 21 Mar 2017 09:32:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3804 Lines: 91 On 03/21/2017 02:04 AM, Niklas Cassel wrote: > On 03/20/2017 11:07 PM, Florian Fainelli wrote: >> >> (snip) >>> >>> However, it is kind of sad that drivers are so inconsistent of what goes >>> in probe and what goes in ndo_open...which is tied together with the >>> whole mess of when certain ethtool commands work or do not work. >> Well, inconsistent here is kind of big statement, what I meant to say is >> that your proposed change actually makes thing inconsistent. > > What I mean is that it is about 50/50 if something e.g. phy_connect > is called from probe or from ndo_open. > This is what I think is inconsistent. > > git grep -p -E "phy_connect\(|phy_connect_direct\(" drivers/net/ethernet/ | grep open | wc -l > 12 > > git grep -p -E "phy_connect\(|phy_connect_direct\(" drivers/net/ethernet/ | grep probe | wc -l > 27 > even if we exclude *_mii_probe/*_mdio_probe which are done > git grep -p mii_probe drivers/net/ethernet/ | grep open | wc -l > 6 > git grep -p mdio_probe drivers/net/ethernet/ | grep open | wc -l > 2 > > phy_connect done from probe: > 27-6-2=19 > > phy_connect done from ndo_open: > 12+6+2=20 > > >> >>> Do you know of a good way to avoid the -EBUSY in stmmac_ethtool_get_link_ksettings, >>> but still keep phy_connect in ndo_open? >> Let me rephrase this: doing an ethtool operation on an interface that is >> not open is not a defined behavior which adheres to a contract with the >> kernel. ethtool operations on interfaces that are DOWN, may succeed if >> they do not involve a piece of hardware that needs to be active (e.g: >> the PHY) but there is no guarantee that a) the change is immediately >> applied, or b) that the results are consistent. >> >> The best thing to do IMHO is just silence the warning, return an error >> coed, and come back configuring the interface at a later time when it is >> guaranteed to be operational. > > Thank you for your feedback. I agree with you, > silencing the warning would be the best way forward. > David, please ignore this patch. > > > > However, since ethtool is a user interface, I think that it would > have been nice if it wasn't so driver specific regarding to if a > command works before the interface is open or not. On premise I agree, in practice, every HW and driver is different, and enforcing standard behaviors is even more difficult as there are multiple pieces of HW interconnected to each other: MAC, MDIO bus, PHY etc. all with different power management capabilities and properties, and different requirements, and of course, varying degrees of brokenness. > > If the user does some ethtool operation that affects e.g. the PHY > before the interface is open, perhaps there is a way to save this > setting so it could be applied when the resource is available. Well behaving driver will connect to the PHY as one of their final driver's ndo_open() step, any call in between will result in phydev being NULL which will return a proper error code and should be acted upon by the application doing the ethtool calls (or the one doing ioctl() calls similar to ethtool). > > For the PHY case, net_device has a pointer to a phy_device, > register_netdev could create a dummy phy_device if > ndev->phy_device is NULL, that way changes could be saved > and applied when phy_connect replaces the dummy device > (or perhaps when phy_start() is called). > (If it isn't a dummy phy_device, changes could be applied immediately.) > This way it would not matter if phy_connect is done from probe > or from ndo_open. > I don't think there is a need for a dummy PHY device, you can do this in your driver if you want to, but this adds a lot of complexity for little value, and, keep in mind that before ndo_open() is complete, most operations against your network driver can be undefined. -- Florian