From patchwork Mon Dec 21 18:55:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Zapolskiy X-Patchwork-Id: 559679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E36B61402D9 for ; Tue, 22 Dec 2015 05:55:42 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9F6F04B6DC; Mon, 21 Dec 2015 19:55:39 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5CH1yJOj1wrp; Mon, 21 Dec 2015 19:55:39 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 073424B667; Mon, 21 Dec 2015 19:55:39 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 574694B667 for ; Mon, 21 Dec 2015 19:55:36 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NCYBkUE2iQDr for ; Mon, 21 Dec 2015 19:55:36 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.mleia.com (mleia.com [178.79.152.223]) by theia.denx.de (Postfix) with ESMTPS id 224824B65D for ; Mon, 21 Dec 2015 19:55:32 +0100 (CET) Received: from mail.mleia.com (localhost [127.0.0.1]) by mail.mleia.com (Postfix) with ESMTP id A671E401BBE; Mon, 21 Dec 2015 18:55:44 +0000 (GMT) Message-ID: <56784B22.20105@mleia.com> Date: Mon, 21 Dec 2015 20:55:30 +0200 From: Vladimir Zapolskiy User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: amessier.tyco@gmail.com, u-boot@lists.denx.de References: <1450291066-15805-1-git-send-email-amessier.tyco@gmail.com> In-Reply-To: <1450291066-15805-1-git-send-email-amessier.tyco@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-49551924 X-CRM114-CacheID: sfid-20151221_185544_703580_8BA5B245 X-CRM114-Status: GOOD ( 23.17 ) Cc: joe.hershberger@ni.com Subject: Re: [U-Boot] [PATCH] net: lpc32xx: Fix MDIO busy wait X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Hi Alexandre, On 16.12.2015 20:37, amessier.tyco@gmail.com wrote: > From: Alexandre Messier > > The MDIO read function waits on the busy flag after issuing the read > command, that's correct, after issuing the read command and before register read. > while the MDIO write function waits on the busy flag before > issuing the write command. and that is not correct, I believe. From the spec (MII Mgmt Indicators Register): For PHY Write if scan is not used: 1. Write 0 to MCMD 2. Write PHY address and register address to MADR 3. Write data to MWTD --> 4. Wait for busy bit to be cleared in MIND For PHY Read if scan is not used: 1. Write 1 to MCMD 2. Write PHY address and register address to MADR --> 3. Wait for busy bit to be cleared in MIND 4. Write 0 to MCMD 5. Read data from MRDD Could you please test/review an alternative fix? I believe it adds proper serialization of all command sequences (read/read, read/write, write/read and write/write). Thank you in advance. do { @@ -319,13 +326,6 @@ static int mii_reg_write(const char *devname, u8 phy_adr, u8 reg_ofs, u16 data) return -EFAULT; } - /* write the phy and reg addressse into the MII address reg */ - writel((phy_adr << MADR_PHY_OFFSET) | (reg_ofs << MADR_REG_OFFSET), - ®s->madr); - - /* write data to the MII write register */ - writel(data, ®s->mwtd); - /*debug("%s:(adr %d, off %d) <= %04x\n", __func__, phy_adr, reg_ofs, data);*/ > This causes an issue when writing then immediately reading. As the MDIO > module is still busy, the read command is not processed. The wait on > busy flag in the read command passes because the previous write command > finishes. In the end, the value returned by the read function is > whatever was present in the MDIO data register. > > Fix the issue by making sure the busy flag is cleared before issuing a > read command. This way, it is still possible to issue a write command > and continue executing u-boot code while the command is processed by > the hardware. Any following MDIO read/write commands after a write > command will wait for a cleared busy flag. --- With best wishes, Vladimir diff --git a/drivers/net/lpc32xx_eth.c b/drivers/net/lpc32xx_eth.c index e76e9bc..3ba5b4b 100644 --- a/drivers/net/lpc32xx_eth.c +++ b/drivers/net/lpc32xx_eth.c @@ -304,6 +304,13 @@ static int mii_reg_write(const char *devname, u8 phy_adr, u8 reg_ofs, u16 data) return -EFAULT; } + /* write the phy and reg addressse into the MII address reg */ + writel((phy_adr << MADR_PHY_OFFSET) | (reg_ofs << MADR_REG_OFFSET), + ®s->madr); + + /* write data to the MII write register */ + writel(data, ®s->mwtd); + /* wait till the MII is not busy */ timeout = MII_TIMEOUT;