All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mcs7830: Fix link state detection
@ 2012-10-11 10:33 Ondrej Zary
  2012-10-11 18:37 ` Andreas Mohr
  2012-10-11 19:20 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Ondrej Zary @ 2012-10-11 10:33 UTC (permalink / raw)
  To: Andreas Mohr
  Cc: Greg KH, davem, Michael Leun, netdev, Michael Leun, linux-kernel

The device had an undocumented "feature": it can provide a sequence of
spurious link-down status data even if the link is up all the time.
A sequence of 10 was seen so update the link state only after the device
reports the same link state 20 times.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Reported-by: Michael Leun <lkml20120218@newton.leun.net>
Tested-by: Michael Leun <lkml20120218@newton.leun.net>
---
 drivers/net/usb/mcs7830.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/net/usb/mcs7830.c b/drivers/net/usb/mcs7830.c
index 03c2d8d..3a02a5d 100644
--- a/drivers/net/usb/mcs7830.c
+++ b/drivers/net/usb/mcs7830.c
@@ -117,6 +117,7 @@ enum {
 struct mcs7830_data {
 	u8 multi_filter[8];
 	u8 config;
+	u8 link_counter;
 };
 
 static const char driver_name[] = "MOSCHIP usb-ethernet driver";
@@ -633,19 +634,25 @@ static void mcs7830_status(struct usbnet *dev, struct 
urb *urb)
 {
 	u8 *buf = urb->transfer_buffer;
 	bool link;
+	struct mcs7830_data *data = mcs7830_get_data(dev);
 
 	if (urb->actual_length < 16)
 		return;
 
 	link = !(buf[1] & 0x20);
 	if (netif_carrier_ok(dev->net) != link) {
-		if (link) {
-			netif_carrier_on(dev->net);
-			usbnet_defer_kevent(dev, EVENT_LINK_RESET);
-		} else
-			netif_carrier_off(dev->net);
-		netdev_dbg(dev->net, "Link Status is: %d\n", link);
-	}
+		data->link_counter++;
+		if (data->link_counter > 20) {
+			data->link_counter = 0;
+			if (link) {
+				netif_carrier_on(dev->net);
+				usbnet_defer_kevent(dev, EVENT_LINK_RESET);
+			} else
+				netif_carrier_off(dev->net);
+			netdev_dbg(dev->net, "Link Status is: %d\n", link);
+		}
+	} else
+		data->link_counter = 0;
 }
 
 static const struct driver_info moschip_info = {
-- 
Ondrej Zary

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mcs7830: Fix link state detection
  2012-10-11 10:33 [PATCH] mcs7830: Fix link state detection Ondrej Zary
@ 2012-10-11 18:37 ` Andreas Mohr
  2012-10-11 19:20 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Mohr @ 2012-10-11 18:37 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Andreas Mohr, Greg KH, davem, Michael Leun, netdev, linux-kernel

Hi,

On Thu, Oct 11, 2012 at 12:33:28PM +0200, Ondrej Zary wrote:
>  	u8 *buf = urb->transfer_buffer;
>  	bool link;
> +	struct mcs7830_data *data = mcs7830_get_data(dev);
>  
>  	if (urb->actual_length < 16)
>  		return;

Alternatively could do *data = NULL; and then actually assign after the conditional.
But since the conditional most likely is coldpath
I think your chosen implementation is best.


>  
>  	link = !(buf[1] & 0x20);
>  	if (netif_carrier_ok(dev->net) != link) {

I usually like to introduce helper bools to clearly express the intention
behind things (source code should be readable like a book, yet it all
too often is everything but...).
I.e.
bool link_state_change_detected = (netif_carrier_ok......);
if (bool)

Might be an idea here, too.


The logic behind your counter implementation seems solid to me
(short explanatory comment "track link state several times, to guard against
transient erroneous link state of (some versions of?) this chip"
might have been useful though).

Thank you very much for your patch!

Andreas Mohr

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mcs7830: Fix link state detection
  2012-10-11 10:33 [PATCH] mcs7830: Fix link state detection Ondrej Zary
  2012-10-11 18:37 ` Andreas Mohr
@ 2012-10-11 19:20 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2012-10-11 19:20 UTC (permalink / raw)
  To: linux; +Cc: andi, gregkh, lkml20120218, netdev, linux-kernel

From: Ondrej Zary <linux@rainbow-software.org>
Date: Thu, 11 Oct 2012 12:33:28 +0200

> The device had an undocumented "feature": it can provide a sequence of
> spurious link-down status data even if the link is up all the time.
> A sequence of 10 was seen so update the link state only after the device
> reports the same link state 20 times.
> 
> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> Reported-by: Michael Leun <lkml20120218@newton.leun.net>
> Tested-by: Michael Leun <lkml20120218@newton.leun.net>

You've been given feedback on this patch, and also it doesn't apply
cleanly.  Perhaps it was corrupted by your email client.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-11 19:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-11 10:33 [PATCH] mcs7830: Fix link state detection Ondrej Zary
2012-10-11 18:37 ` Andreas Mohr
2012-10-11 19:20 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.