Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mcs7830: Fix link state detection

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>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ondrej Zary and committed by
David S. Miller
dabdaf0c 93ac0ef0

+21 -9
+21 -9
drivers/net/usb/mcs7830.c
··· 117 117 struct mcs7830_data { 118 118 u8 multi_filter[8]; 119 119 u8 config; 120 + u8 link_counter; 120 121 }; 121 122 122 123 static const char driver_name[] = "MOSCHIP usb-ethernet driver"; ··· 633 632 static void mcs7830_status(struct usbnet *dev, struct urb *urb) 634 633 { 635 634 u8 *buf = urb->transfer_buffer; 636 - bool link; 635 + bool link, link_changed; 636 + struct mcs7830_data *data = mcs7830_get_data(dev); 637 637 638 638 if (urb->actual_length < 16) 639 639 return; 640 640 641 641 link = !(buf[1] & 0x20); 642 - if (netif_carrier_ok(dev->net) != link) { 643 - if (link) { 644 - netif_carrier_on(dev->net); 645 - usbnet_defer_kevent(dev, EVENT_LINK_RESET); 646 - } else 647 - netif_carrier_off(dev->net); 648 - netdev_dbg(dev->net, "Link Status is: %d\n", link); 649 - } 642 + link_changed = netif_carrier_ok(dev->net) != link; 643 + if (link_changed) { 644 + data->link_counter++; 645 + /* 646 + track link state 20 times to guard against erroneous 647 + link state changes reported sometimes by the chip 648 + */ 649 + if (data->link_counter > 20) { 650 + data->link_counter = 0; 651 + if (link) { 652 + netif_carrier_on(dev->net); 653 + usbnet_defer_kevent(dev, EVENT_LINK_RESET); 654 + } else 655 + netif_carrier_off(dev->net); 656 + netdev_dbg(dev->net, "Link Status is: %d\n", link); 657 + } 658 + } else 659 + data->link_counter = 0; 650 660 } 651 661 652 662 static const struct driver_info moschip_info = {