From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sergei Shtylyov Subject: Re: [PATCHv4 2/5] net: phy: extend fixed driver with fixed_phy_register() Date: Thu, 3 Sep 2015 22:35:12 +0300 Message-ID: <55E8A0F0.5090702@cogentembedded.com> References: <1400249647-4643-1-git-send-email-thomas.petazzoni@free-electrons.com> <1400249647-4643-3-git-send-email-thomas.petazzoni@free-electrons.com> <55E89D83.1090401@cogentembedded.com> <55E89E27.6050708@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Tawfik Bayouk , Nadav Haklai , Lior Amsalem , Gregory Clement , Ezequiel Garcia , linux-arm-kernel@lists.infradead.org, Grant Likely , Rob Herring , Mark Rutland , Sascha Hauer , Christian Gmeiner To: Florian Fainelli , Thomas Petazzoni , "David S. Miller" , netdev@vger.kernel.org, devicetree@vger.kernel.org Return-path: Received: from mail-lb0-f174.google.com ([209.85.217.174]:34347 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757671AbbICTfQ (ORCPT ); Thu, 3 Sep 2015 15:35:16 -0400 Received: by lbbmp1 with SMTP id mp1so30495304lbb.1 for ; Thu, 03 Sep 2015 12:35:14 -0700 (PDT) In-Reply-To: <55E89E27.6050708@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Hello. On 09/03/2015 10:23 PM, Florian Fainelli wrote: >>> The existing fixed_phy_add() function has several drawbacks that >>> prevents it from being used as is for OF-based declaration of fixed >>> PHYs: >>> >>> * The address of the PHY on the fake bus needs to be passed, while a >>> dynamic allocation is desired. >>> >>> * Since the phy_device instantiation is post-poned until the next >>> mdiobus scan, there is no way to associate the fixed PHY with its >>> OF node, which later prevents of_phy_connect() from finding this >>> fixed PHY from a given OF node. >>> >>> To solve this, this commit introduces fixed_phy_register(), which will >>> allocate an available PHY address, add the PHY using fixed_phy_add() >>> and instantiate the phy_device structure associated with the provided >>> OF node. >>> >>> Signed-off-by: Thomas Petazzoni >>> Acked-by: Florian Fainelli >>> Acked-by: Grant Likely >>> --- >>> drivers/net/phy/fixed.c | 61 >>> +++++++++++++++++++++++++++++++++++++++++++++++ >>> include/linux/phy_fixed.h | 11 +++++++++ >>> 2 files changed, 72 insertions(+) >>> >>> diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c >>> index e41546d..d60d875 100644 >>> --- a/drivers/net/phy/fixed.c >>> +++ b/drivers/net/phy/fixed.c >> [...] >>> @@ -203,6 +204,66 @@ err_regs: >> [...] >>> +int fixed_phy_register(unsigned int irq, >>> + struct fixed_phy_status *status, >>> + struct device_node *np) >>> +{ >>> + struct fixed_mdio_bus *fmb = &platform_fmb; >>> + struct phy_device *phy; >>> + int phy_addr; >>> + int ret; >>> + >>> + /* Get the next available PHY address, up to PHY_MAX_ADDR */ >>> + spin_lock(&phy_fixed_addr_lock); >>> + if (phy_fixed_addr == PHY_MAX_ADDR) { >>> + spin_unlock(&phy_fixed_addr_lock); >>> + return -ENOSPC; >>> + } >>> + phy_addr = phy_fixed_addr++; >>> + spin_unlock(&phy_fixed_addr_lock); >>> + >>> + ret = fixed_phy_add(PHY_POLL, phy_addr, status); >> >> Was rummaging in the fixed_phy driver and a bug sprang right at me: >> 'phy' should have been passed here, not PHY_POLL. Luckily, all callers >> pass PHY_POLL anyway... > Are we looking at the same header file for the prototype of fixed_phy_add()? Probably not. I was looking at Linus' tree, yours is probably net-next. :-) > extern int fixed_phy_add(unsigned int irq, int phy_id, > struct fixed_phy_status *status, > int link_gpio); > First argument is correct here.. No, fixed_phy_register() gets 'irq' passed to it and it should in its turn call fixed_phy_add() with this argument, not PHY_POLL; otherwise the 'irq' parameter gets completely ignored... > at any rate, if something needs fixing, just go ahead and submit a patch. OK. > -- > Florian MBR, Sergei From mboxrd@z Thu Jan 1 00:00:00 1970 From: sergei.shtylyov@cogentembedded.com (Sergei Shtylyov) Date: Thu, 3 Sep 2015 22:35:12 +0300 Subject: [PATCHv4 2/5] net: phy: extend fixed driver with fixed_phy_register() In-Reply-To: <55E89E27.6050708@gmail.com> References: <1400249647-4643-1-git-send-email-thomas.petazzoni@free-electrons.com> <1400249647-4643-3-git-send-email-thomas.petazzoni@free-electrons.com> <55E89D83.1090401@cogentembedded.com> <55E89E27.6050708@gmail.com> Message-ID: <55E8A0F0.5090702@cogentembedded.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org Hello. On 09/03/2015 10:23 PM, Florian Fainelli wrote: >>> The existing fixed_phy_add() function has several drawbacks that >>> prevents it from being used as is for OF-based declaration of fixed >>> PHYs: >>> >>> * The address of the PHY on the fake bus needs to be passed, while a >>> dynamic allocation is desired. >>> >>> * Since the phy_device instantiation is post-poned until the next >>> mdiobus scan, there is no way to associate the fixed PHY with its >>> OF node, which later prevents of_phy_connect() from finding this >>> fixed PHY from a given OF node. >>> >>> To solve this, this commit introduces fixed_phy_register(), which will >>> allocate an available PHY address, add the PHY using fixed_phy_add() >>> and instantiate the phy_device structure associated with the provided >>> OF node. >>> >>> Signed-off-by: Thomas Petazzoni >>> Acked-by: Florian Fainelli >>> Acked-by: Grant Likely >>> --- >>> drivers/net/phy/fixed.c | 61 >>> +++++++++++++++++++++++++++++++++++++++++++++++ >>> include/linux/phy_fixed.h | 11 +++++++++ >>> 2 files changed, 72 insertions(+) >>> >>> diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c >>> index e41546d..d60d875 100644 >>> --- a/drivers/net/phy/fixed.c >>> +++ b/drivers/net/phy/fixed.c >> [...] >>> @@ -203,6 +204,66 @@ err_regs: >> [...] >>> +int fixed_phy_register(unsigned int irq, >>> + struct fixed_phy_status *status, >>> + struct device_node *np) >>> +{ >>> + struct fixed_mdio_bus *fmb = &platform_fmb; >>> + struct phy_device *phy; >>> + int phy_addr; >>> + int ret; >>> + >>> + /* Get the next available PHY address, up to PHY_MAX_ADDR */ >>> + spin_lock(&phy_fixed_addr_lock); >>> + if (phy_fixed_addr == PHY_MAX_ADDR) { >>> + spin_unlock(&phy_fixed_addr_lock); >>> + return -ENOSPC; >>> + } >>> + phy_addr = phy_fixed_addr++; >>> + spin_unlock(&phy_fixed_addr_lock); >>> + >>> + ret = fixed_phy_add(PHY_POLL, phy_addr, status); >> >> Was rummaging in the fixed_phy driver and a bug sprang right at me: >> 'phy' should have been passed here, not PHY_POLL. Luckily, all callers >> pass PHY_POLL anyway... > Are we looking at the same header file for the prototype of fixed_phy_add()? Probably not. I was looking at Linus' tree, yours is probably net-next. :-) > extern int fixed_phy_add(unsigned int irq, int phy_id, > struct fixed_phy_status *status, > int link_gpio); > First argument is correct here.. No, fixed_phy_register() gets 'irq' passed to it and it should in its turn call fixed_phy_add() with this argument, not PHY_POLL; otherwise the 'irq' parameter gets completely ignored... > at any rate, if something needs fixing, just go ahead and submit a patch. OK. > -- > Florian MBR, Sergei