netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Russell King <linux@armlinux.org.uk>
Cc: Baruch Siach <baruch@tkos.co.il>,
	netdev@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
	Baruch Siach <baruch.siach@siklu.com>
Subject: Re: [PATCH v2] net: sfp: workaround GPIO input signals bounce
Date: Tue, 20 Sep 2022 08:19:11 -0700	[thread overview]
Message-ID: <20220920081911.619ffeef@kernel.org> (raw)
In-Reply-To: <931ac53e9d6421f71f776190b2039abaa69f7d43.1663133795.git.baruch@tkos.co.il>

On Wed, 14 Sep 2022 08:36:35 +0300 Baruch Siach wrote:
> From: Baruch Siach <baruch.siach@siklu.com>
> 
> Add a trivial debounce to avoid miss of state changes when there is no
> proper hardware debounce on the input signals. Otherwise a GPIO might
> randomly indicate high level when the signal is actually going down,
> and vice versa.
> 
> This fixes observed miss of link up event when LOS signal goes down on
> Armada 8040 based system with an optical SFP module.
> 
> Signed-off-by: Baruch Siach <baruch.siach@siklu.com>
> ---
> v2:
>   Skip delay in the polling case (RMK)

Is this acceptable now, Russell?

> diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> index 63f90fe9a4d2..b0ba144c9633 100644
> --- a/drivers/net/phy/sfp.c
> +++ b/drivers/net/phy/sfp.c
> @@ -313,7 +313,9 @@ static unsigned long poll_jiffies;
>  static unsigned int sfp_gpio_get_state(struct sfp *sfp)
>  {
>  	unsigned int i, state, v;
> +	int repeat = 10;
>  
> +again:
>  	for (i = state = 0; i < GPIO_MAX; i++) {
>  		if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i])
>  			continue;
> @@ -323,6 +325,16 @@ static unsigned int sfp_gpio_get_state(struct sfp *sfp)
>  			state |= BIT(i);
>  	}
>  
> +	/* Trivial debounce for the interrupt case. When no state change is
> +	 * detected, wait for up to a limited bound time interval for the
> +	 * signal state to settle.
> +	 */
> +	if (state == sfp->state && !sfp->need_poll && repeat > 0) {
> +		udelay(10);
> +		repeat--;
> +		goto again;
> +	}
> +
>  	return state;
>  }
>  


  reply	other threads:[~2022-09-20 15:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14  5:36 [PATCH v2] net: sfp: workaround GPIO input signals bounce Baruch Siach
2022-09-20 15:19 ` Jakub Kicinski [this message]
2022-09-20 17:21   ` Russell King (Oracle)
2022-09-21  4:57     ` Baruch Siach

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=20220920081911.619ffeef@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=baruch.siach@siklu.com \
    --cc=baruch@tkos.co.il \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    /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).