* [PATCH] net: sfp: workaround GPIO input signals bounce
@ 2022-09-13 7:43 Baruch Siach
2022-09-13 7:48 ` Russell King (Oracle)
0 siblings, 1 reply; 3+ messages in thread
From: Baruch Siach @ 2022-09-13 7:43 UTC (permalink / raw)
To: Russell King; +Cc: netdev, Andrew Lunn, Baruch Siach
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>
---
drivers/net/phy/sfp.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 63f90fe9a4d2..ce6565872f54 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,15 @@ static unsigned int sfp_gpio_get_state(struct sfp *sfp)
state |= BIT(i);
}
+ /* Trivial debounce. 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 && repeat > 0) {
+ udelay(10);
+ repeat--;
+ goto again;
+ }
+
return state;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] net: sfp: workaround GPIO input signals bounce
2022-09-13 7:43 [PATCH] net: sfp: workaround GPIO input signals bounce Baruch Siach
@ 2022-09-13 7:48 ` Russell King (Oracle)
2022-09-13 9:54 ` Baruch Siach
0 siblings, 1 reply; 3+ messages in thread
From: Russell King (Oracle) @ 2022-09-13 7:48 UTC (permalink / raw)
To: Baruch Siach; +Cc: netdev, Andrew Lunn, Baruch Siach
On Tue, Sep 13, 2022 at 10:43:38AM +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.
NAK. This needs more inteligent handling. For systems where we poll,
your code introduces a 100us delay each time we poll and there has
been no change.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: sfp: workaround GPIO input signals bounce
2022-09-13 7:48 ` Russell King (Oracle)
@ 2022-09-13 9:54 ` Baruch Siach
0 siblings, 0 replies; 3+ messages in thread
From: Baruch Siach @ 2022-09-13 9:54 UTC (permalink / raw)
To: Russell King (Oracle); +Cc: netdev, Andrew Lunn, Baruch Siach
Hi Russell,
On Tue, Sep 13 2022, Russell King (Oracle) wrote:
> On Tue, Sep 13, 2022 at 10:43:38AM +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.
>
> NAK. This needs more inteligent handling. For systems where we poll,
> your code introduces a 100us delay each time we poll and there has
> been no change.
I think we can avoid delay in the poll case by skipping the delay loop
when sfp->need_poll is true.
I'll send v2 with that fixed tomorrow.
Thanks for reviewing,
baruch
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-13 9:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-13 7:43 [PATCH] net: sfp: workaround GPIO input signals bounce Baruch Siach
2022-09-13 7:48 ` Russell King (Oracle)
2022-09-13 9:54 ` Baruch Siach
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).