linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <Claudiu.Beznea@microchip.com>
To: <harini.katakam@xilinx.com>, <Nicolas.Ferre@microchip.com>,
	<davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<michal.simek@xilinx.com>, <harinikatakamlinux@gmail.com>,
	<harinik@xilinx.com>, <shubhrajyoti.datta@xilinx.com>,
	<sai.pavan.boddu@xilinx.com>
Subject: Re: [PATCH v2 1/4] net: macb: Check MDIO state before read/write and use timeouts
Date: Mon, 26 Nov 2018 14:46:01 +0000	[thread overview]
Message-ID: <5de882e3-65ac-7ff1-bb55-7537666dfc77@microchip.com> (raw)
In-Reply-To: <1543216072-9623-2-git-send-email-harini.katakam@xilinx.com>

Hi Harini,

On 26.11.2018 09:07, Harini Katakam wrote:
> From: Harini Katakam <harinik@xilinx.com>
> 
> 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.

Is this MDIO bus busy check necessary? The caller of
macb_mdio_read/macb_mdio_write locks the mdio bus mutex before calling it
(e.g. mdiobus_read).

> 
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
> Signed-off-by: Harini Katakam <harinik@xilinx.com>
> ---
> v2 changes:
> Use readx_poll_timeout
> 
> Changes form RFC:
> Cleaned up timeout implementation and moved it to a helper.
> 
>  drivers/net/ethernet/cadence/macb.h      |  3 +++
>  drivers/net/ethernet/cadence/macb_main.c | 33 ++++++++++++++++++++++++++------
>  2 files changed, 30 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
> index 3d45f4c..df7bee1 100644
> --- a/drivers/net/ethernet/cadence/macb.h
> +++ b/drivers/net/ethernet/cadence/macb.h
> @@ -714,6 +714,9 @@
>  		__v; \
>  	})
>  
> +#define MACB_IDLE_MASK		(1 << MACB_IDLE_OFFSET)

You could use MACB_BIT(IDLE) instead.

> +#define MACB_READ_NSR(bp)	macb_readl(bp, NSR)

Is this necessary?


> +
>  /* struct macb_dma_desc - Hardware DMA descriptor
>   * @addr: DMA address of data buffer
>   * @ctrl: Control and status bits
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 1d86b4d..fd86ece 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -36,6 +36,7 @@
>  #include <linux/ip.h>
>  #include <linux/udp.h>
>  #include <linux/tcp.h>
> +#include <linux/iopoll.h>
>  #include "macb.h"
>  
>  #define MACB_RX_BUFFER_SIZE	128
> @@ -79,6 +80,8 @@
>   */
>  #define MACB_HALT_TIMEOUT	1230
>  
> +#define MACB_MDIO_TIMEOUT	1000000 /* in usecs */
> +
>  /* DMA buffer descriptor might be different size
>   * depends on hardware configuration:
>   *
> @@ -318,10 +321,23 @@ static void macb_get_hwaddr(struct macb *bp)
>  	eth_hw_addr_random(bp->dev);
>  }
>  
> +static int macb_mdio_wait_for_idle(struct macb *bp)
> +{
> +	u32 val;
> +
> +	return readx_poll_timeout(MACB_READ_NSR, bp, val, val & MACB_IDLE_MASK,
> +				  1, MACB_MDIO_TIMEOUT);
> +}
> +
>  static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
>  {
>  	struct macb *bp = bus->priv;
>  	int value;
> +	int err;
> +
> +	err = macb_mdio_wait_for_idle(bp);
> +	if (err < 0)
> +		return err;
>  
>  	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
>  			      | MACB_BF(RW, MACB_MAN_READ)
> @@ -329,9 +345,9 @@ static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
>  			      | MACB_BF(REGA, regnum)
>  			      | MACB_BF(CODE, MACB_MAN_CODE)));
>  
> -	/* wait for end of transfer */
> -	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> -		cpu_relax();
> +	err = macb_mdio_wait_for_idle(bp);
> +	if (err < 0)
> +		return err;
>  
>  	value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
>  
> @@ -342,6 +358,11 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
>  			   u16 value)
>  {
>  	struct macb *bp = bus->priv;
> +	int err;
> +
> +	err = macb_mdio_wait_for_idle(bp);
> +	if (err < 0)
> +		return err;
>  
>  	macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
>  			      | MACB_BF(RW, MACB_MAN_WRITE)
> @@ -350,9 +371,9 @@ static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
>  			      | MACB_BF(CODE, MACB_MAN_CODE)
>  			      | MACB_BF(DATA, value)));
>  
> -	/* wait for end of transfer */
> -	while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
> -		cpu_relax();
> +	err = macb_mdio_wait_for_idle(bp);
> +	if (err < 0)
> +		return err;
>  
>  	return 0;
>  }
> 

  parent reply	other threads:[~2018-11-26 14:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26  7:07 [PATCH v2 0/4] Macb power management support for ZynqMP Harini Katakam
2018-11-26  7:07 ` [PATCH v2 1/4] net: macb: Check MDIO state before read/write and use timeouts Harini Katakam
2018-11-26 14:39   ` Andrew Lunn
2018-11-27  5:38     ` Harini Katakam
2018-11-26 14:46   ` Claudiu.Beznea [this message]
2018-11-26 14:52     ` Andrew Lunn
2018-11-27  5:36       ` Harini Katakam
2018-11-27 10:25         ` Claudiu.Beznea
2018-11-27 10:49           ` Harini Katakam
2018-11-28  0:35           ` Andrew Lunn
2018-11-29 10:21             ` Claudiu.Beznea
2018-11-26  7:07 ` [PATCH v2 2/4] net: macb: Support clock management for tsu_clk Harini Katakam
2018-11-26  7:07 ` [PATCH v2 3/4] net: macb: Add pm runtime support Harini Katakam
2018-11-26 14:47   ` Andrew Lunn
2018-11-26 14:47   ` Claudiu.Beznea
2018-11-26  7:07 ` [PATCH v2 4/4] net: macb: Add support for suspend/resume with full power down Harini Katakam
2018-11-26 14:46   ` Claudiu.Beznea
2018-11-27  6:25     ` Harini Katakam
2018-11-27 10:31       ` Claudiu.Beznea

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5de882e3-65ac-7ff1-bb55-7537666dfc77@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=Nicolas.Ferre@microchip.com \
    --cc=davem@davemloft.net \
    --cc=harini.katakam@xilinx.com \
    --cc=harinik@xilinx.com \
    --cc=harinikatakamlinux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=netdev@vger.kernel.org \
    --cc=sai.pavan.boddu@xilinx.com \
    --cc=shubhrajyoti.datta@xilinx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).