From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Lunn Subject: Re: [PATCH 1/4] net: macb: Check MDIO state before read/write and use timeouts Date: Wed, 31 Oct 2018 14:48:10 +0100 Message-ID: <20181031134810.GD20889@lunn.ch> References: <1540957223-30984-1-git-send-email-harini.katakam@xilinx.com> <1540957223-30984-2-git-send-email-harini.katakam@xilinx.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: nicolas.ferre@microchip.com, davem@davemloft.net, claudiu.beznea@microchip.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, michal.simek@xilinx.com, harinikatakamlinux@gmail.com, Harini Katakam , Shubhrajyoti Datta , Sai Pavan Boddu To: Harini Katakam Return-path: Content-Disposition: inline In-Reply-To: <1540957223-30984-2-git-send-email-harini.katakam@xilinx.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On Wed, Oct 31, 2018 at 09:10:20AM +0530, Harini Katakam wrote: > From: Harini Katakam > > Replace the while loop in MDIO read/write functions with a timeout. > In addition, add a check for MDIO bus busy before initiating a new > operation as well to make sure there is no ongoing MDIO operation. > > Signed-off-by: Shubhrajyoti Datta > Signed-off-by: Sai Pavan Boddu > Signed-off-by: Harini Katakam > --- > Changes form RFC: > Cleaned up timeout implementation and moved it to a helper. > > drivers/net/ethernet/cadence/macb_main.c | 44 +++++++++++++++++++++++++++----- > 1 file changed, 38 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c > index 0acaef3..b4e26c1 100644 > --- a/drivers/net/ethernet/cadence/macb_main.c > +++ b/drivers/net/ethernet/cadence/macb_main.c > @@ -318,10 +318,36 @@ static void macb_get_hwaddr(struct macb *bp) > eth_hw_addr_random(bp->dev); > } > > +static int macb_mdio_wait_for_idle(struct macb *bp) > +{ > + ulong timeout; > + > + timeout = jiffies + msecs_to_jiffies(1000); > + /* wait for end of transfer */ > + while (1) { > + if (MACB_BFEXT(IDLE, macb_readl(bp, NSR))) > + break; > + > + if (time_after_eq(jiffies, timeout)) { > + netdev_err(bp->dev, "wait for end of transfer timed out\n"); > + return -ETIMEDOUT; > + } > + > + cpu_relax(); > + } > + > + return 0; > +} Hi Harini Could you make use of readx_poll_timeout(). You will need to add a helper for the read of the register, since readx_poll_timeout() only allows one parameter. Otherwise, this looks O.K. Andrew