From patchwork Thu Oct 11 10:33:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Zary X-Patchwork-Id: 190867 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 898D72C0040 for ; Thu, 11 Oct 2012 21:34:34 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758589Ab2JKKeP (ORCPT ); Thu, 11 Oct 2012 06:34:15 -0400 Received: from mail-1-out2.atlantis.sk ([80.94.52.71]:57374 "EHLO mail.atlantis.sk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758576Ab2JKKeM (ORCPT ); Thu, 11 Oct 2012 06:34:12 -0400 Received: (qmail 32600 invoked from network); 11 Oct 2012 10:34:08 -0000 Received: from unknown (HELO ?192.168.0.3?) (rainbow@rainbow-software.org@62.176.172.51) by mail-1.atlantis.sk with ESMTPA; 11 Oct 2012 10:34:08 -0000 From: Ondrej Zary To: "Andreas Mohr" Subject: [PATCH] mcs7830: Fix link state detection Date: Thu, 11 Oct 2012 12:33:28 +0200 User-Agent: KMail/1.9.10 (enterprise35 0.20100827.1168748) Cc: "Greg KH" , davem@davemloft.net, Michael Leun , netdev@vger.kernel.org, Michael Leun , linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Disposition: inline Message-Id: <201210111233.28652.linux@rainbow-software.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Reported-by: Michael Leun Tested-by: Michael Leun --- drivers/net/usb/mcs7830.c | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-) static const struct driver_info moschip_info = { 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; }