usbnet.c (17d5ca91cfc59ae91da5ff9da74ab09a9a2a17d9) | usbnet.c (14a0d635d18d0fb552dcc979d6d25106e6541f2e) |
---|---|
1/* 2 * USB Network driver infrastructure 3 * Copyright (C) 2000-2005 by David Brownell 4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 738 unchanged lines hidden (view full) --- 747} 748EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs); 749 750/*-------------------------------------------------------------------------*/ 751 752// precondition: never called in_interrupt 753static void usbnet_terminate_urbs(struct usbnet *dev) 754{ | 1/* 2 * USB Network driver infrastructure 3 * Copyright (C) 2000-2005 by David Brownell 4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 738 unchanged lines hidden (view full) --- 747} 748EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs); 749 750/*-------------------------------------------------------------------------*/ 751 752// precondition: never called in_interrupt 753static void usbnet_terminate_urbs(struct usbnet *dev) 754{ |
755 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup); | |
756 DECLARE_WAITQUEUE(wait, current); 757 int temp; 758 759 /* ensure there are no more active urbs */ | 755 DECLARE_WAITQUEUE(wait, current); 756 int temp; 757 758 /* ensure there are no more active urbs */ |
760 add_wait_queue(&unlink_wakeup, &wait); | 759 add_wait_queue(&dev->wait, &wait); |
761 set_current_state(TASK_UNINTERRUPTIBLE); | 760 set_current_state(TASK_UNINTERRUPTIBLE); |
762 dev->wait = &unlink_wakeup; | |
763 temp = unlink_urbs(dev, &dev->txq) + 764 unlink_urbs(dev, &dev->rxq); 765 766 /* maybe wait for deletions to finish. */ 767 while (!skb_queue_empty(&dev->rxq) 768 && !skb_queue_empty(&dev->txq) 769 && !skb_queue_empty(&dev->done)) { 770 schedule_timeout(msecs_to_jiffies(UNLINK_TIMEOUT_MS)); 771 set_current_state(TASK_UNINTERRUPTIBLE); 772 netif_dbg(dev, ifdown, dev->net, 773 "waited for %d urb completions\n", temp); 774 } 775 set_current_state(TASK_RUNNING); | 761 temp = unlink_urbs(dev, &dev->txq) + 762 unlink_urbs(dev, &dev->rxq); 763 764 /* maybe wait for deletions to finish. */ 765 while (!skb_queue_empty(&dev->rxq) 766 && !skb_queue_empty(&dev->txq) 767 && !skb_queue_empty(&dev->done)) { 768 schedule_timeout(msecs_to_jiffies(UNLINK_TIMEOUT_MS)); 769 set_current_state(TASK_UNINTERRUPTIBLE); 770 netif_dbg(dev, ifdown, dev->net, 771 "waited for %d urb completions\n", temp); 772 } 773 set_current_state(TASK_RUNNING); |
776 dev->wait = NULL; 777 remove_wait_queue(&unlink_wakeup, &wait); | 774 remove_wait_queue(&dev->wait, &wait); |
778} 779 780int usbnet_stop (struct net_device *net) 781{ 782 struct usbnet *dev = netdev_priv(net); 783 struct driver_info *info = dev->driver_info; | 775} 776 777int usbnet_stop (struct net_device *net) 778{ 779 struct usbnet *dev = netdev_priv(net); 780 struct driver_info *info = dev->driver_info; |
784 int retval; | 781 int retval, pm; |
785 786 clear_bit(EVENT_DEV_OPEN, &dev->flags); 787 netif_stop_queue (net); 788 789 netif_info(dev, ifdown, dev->net, 790 "stop stats: rx/tx %lu/%lu, errs %lu/%lu\n", 791 net->stats.rx_packets, net->stats.tx_packets, 792 net->stats.rx_errors, net->stats.tx_errors); 793 | 782 783 clear_bit(EVENT_DEV_OPEN, &dev->flags); 784 netif_stop_queue (net); 785 786 netif_info(dev, ifdown, dev->net, 787 "stop stats: rx/tx %lu/%lu, errs %lu/%lu\n", 788 net->stats.rx_packets, net->stats.tx_packets, 789 net->stats.rx_errors, net->stats.tx_errors); 790 |
791 /* to not race resume */ 792 pm = usb_autopm_get_interface(dev->intf); |
|
794 /* allow minidriver to stop correctly (wireless devices to turn off 795 * radio etc) */ 796 if (info->stop) { 797 retval = info->stop(dev); 798 if (retval < 0) 799 netif_info(dev, ifdown, dev->net, 800 "stop fail (%d) usbnet usb-%s-%s, %s\n", 801 retval, --- 10 unchanged lines hidden (view full) --- 812 813 /* deferred work (task, timer, softirq) must also stop. 814 * can't flush_scheduled_work() until we drop rtnl (later), 815 * else workers could deadlock; so make workers a NOP. 816 */ 817 dev->flags = 0; 818 del_timer_sync (&dev->delay); 819 tasklet_kill (&dev->bh); | 793 /* allow minidriver to stop correctly (wireless devices to turn off 794 * radio etc) */ 795 if (info->stop) { 796 retval = info->stop(dev); 797 if (retval < 0) 798 netif_info(dev, ifdown, dev->net, 799 "stop fail (%d) usbnet usb-%s-%s, %s\n", 800 retval, --- 10 unchanged lines hidden (view full) --- 811 812 /* deferred work (task, timer, softirq) must also stop. 813 * can't flush_scheduled_work() until we drop rtnl (later), 814 * else workers could deadlock; so make workers a NOP. 815 */ 816 dev->flags = 0; 817 del_timer_sync (&dev->delay); 818 tasklet_kill (&dev->bh); |
819 if (!pm) 820 usb_autopm_put_interface(dev->intf); 821 |
|
820 if (info->manage_power && 821 !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags)) 822 info->manage_power(dev, 0); 823 else 824 usb_autopm_put_interface(dev->intf); 825 826 return 0; 827} --- 604 unchanged lines hidden (view full) --- 1432 default: 1433 netdev_dbg(dev->net, "bogus skb state %d\n", entry->state); 1434 } 1435 } 1436 1437 /* restart RX again after disabling due to high error rate */ 1438 clear_bit(EVENT_RX_KILL, &dev->flags); 1439 | 822 if (info->manage_power && 823 !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags)) 824 info->manage_power(dev, 0); 825 else 826 usb_autopm_put_interface(dev->intf); 827 828 return 0; 829} --- 604 unchanged lines hidden (view full) --- 1434 default: 1435 netdev_dbg(dev->net, "bogus skb state %d\n", entry->state); 1436 } 1437 } 1438 1439 /* restart RX again after disabling due to high error rate */ 1440 clear_bit(EVENT_RX_KILL, &dev->flags); 1441 |
1440 // waiting for all pending urbs to complete? 1441 if (dev->wait) { 1442 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) { 1443 wake_up (dev->wait); 1444 } | 1442 /* waiting for all pending urbs to complete? 1443 * only then can we forgo submitting anew 1444 */ 1445 if (waitqueue_active(&dev->wait)) { 1446 if (dev->txq.qlen + dev->rxq.qlen + dev->done.qlen == 0) 1447 wake_up_all(&dev->wait); |
1445 1446 // or are we maybe short a few urbs? 1447 } else if (netif_running (dev->net) && 1448 netif_device_present (dev->net) && 1449 netif_carrier_ok(dev->net) && 1450 !timer_pending (&dev->delay) && 1451 !test_bit (EVENT_RX_HALT, &dev->flags)) { 1452 int temp = dev->rxq.qlen; --- 122 unchanged lines hidden (view full) --- 1575 1576 dev = netdev_priv(net); 1577 dev->udev = xdev; 1578 dev->intf = udev; 1579 dev->driver_info = info; 1580 dev->driver_name = name; 1581 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV 1582 | NETIF_MSG_PROBE | NETIF_MSG_LINK); | 1448 1449 // or are we maybe short a few urbs? 1450 } else if (netif_running (dev->net) && 1451 netif_device_present (dev->net) && 1452 netif_carrier_ok(dev->net) && 1453 !timer_pending (&dev->delay) && 1454 !test_bit (EVENT_RX_HALT, &dev->flags)) { 1455 int temp = dev->rxq.qlen; --- 122 unchanged lines hidden (view full) --- 1578 1579 dev = netdev_priv(net); 1580 dev->udev = xdev; 1581 dev->intf = udev; 1582 dev->driver_info = info; 1583 dev->driver_name = name; 1584 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV 1585 | NETIF_MSG_PROBE | NETIF_MSG_LINK); |
1586 init_waitqueue_head(&dev->wait); |
|
1583 skb_queue_head_init (&dev->rxq); 1584 skb_queue_head_init (&dev->txq); 1585 skb_queue_head_init (&dev->done); 1586 skb_queue_head_init(&dev->rxq_pause); 1587 dev->bh.func = usbnet_bh; 1588 dev->bh.data = (unsigned long) dev; 1589 INIT_WORK (&dev->kevent, kevent); 1590 init_usb_anchor(&dev->deferred); --- 195 unchanged lines hidden (view full) --- 1786 } 1787 } 1788 1789 smp_mb(); 1790 clear_bit(EVENT_DEV_ASLEEP, &dev->flags); 1791 spin_unlock_irq(&dev->txq.lock); 1792 1793 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) { | 1587 skb_queue_head_init (&dev->rxq); 1588 skb_queue_head_init (&dev->txq); 1589 skb_queue_head_init (&dev->done); 1590 skb_queue_head_init(&dev->rxq_pause); 1591 dev->bh.func = usbnet_bh; 1592 dev->bh.data = (unsigned long) dev; 1593 INIT_WORK (&dev->kevent, kevent); 1594 init_usb_anchor(&dev->deferred); --- 195 unchanged lines hidden (view full) --- 1790 } 1791 } 1792 1793 smp_mb(); 1794 clear_bit(EVENT_DEV_ASLEEP, &dev->flags); 1795 spin_unlock_irq(&dev->txq.lock); 1796 1797 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) { |
1794 /* handle remote wakeup ASAP */ 1795 if (!dev->wait && 1796 netif_device_present(dev->net) && | 1798 /* handle remote wakeup ASAP 1799 * we cannot race against stop 1800 */ 1801 if (netif_device_present(dev->net) && |
1797 !timer_pending(&dev->delay) && 1798 !test_bit(EVENT_RX_HALT, &dev->flags)) 1799 rx_alloc_submit(dev, GFP_NOIO); 1800 1801 if (!(dev->txq.qlen >= TX_QLEN(dev))) 1802 netif_tx_wake_all_queues(dev->net); 1803 tasklet_schedule (&dev->bh); 1804 } --- 262 unchanged lines hidden --- | 1802 !timer_pending(&dev->delay) && 1803 !test_bit(EVENT_RX_HALT, &dev->flags)) 1804 rx_alloc_submit(dev, GFP_NOIO); 1805 1806 if (!(dev->txq.qlen >= TX_QLEN(dev))) 1807 netif_tx_wake_all_queues(dev->net); 1808 tasklet_schedule (&dev->bh); 1809 } --- 262 unchanged lines hidden --- |