usbnet.c (5b805f2a7675634fbdf9ac1c9b2256905ab2ea68) | usbnet.c (0547fad2dd7ccaaf3c914ba49073fa37e4e241eb) |
---|---|
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 --- 1144 unchanged lines hidden (view full) --- 1153 1154#ifdef CONFIG_PM 1155 /* if this triggers the device is still a sleep */ 1156 if (test_bit(EVENT_DEV_ASLEEP, &dev->flags)) { 1157 /* transmission will be done in resume */ 1158 usb_anchor_urb(urb, &dev->deferred); 1159 /* no use to process more packets */ 1160 netif_stop_queue(net); | 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 --- 1144 unchanged lines hidden (view full) --- 1153 1154#ifdef CONFIG_PM 1155 /* if this triggers the device is still a sleep */ 1156 if (test_bit(EVENT_DEV_ASLEEP, &dev->flags)) { 1157 /* transmission will be done in resume */ 1158 usb_anchor_urb(urb, &dev->deferred); 1159 /* no use to process more packets */ 1160 netif_stop_queue(net); |
1161 usb_put_urb(urb); | |
1162 spin_unlock_irqrestore(&dev->txq.lock, flags); 1163 netdev_dbg(dev->net, "Delaying transmission for resumption\n"); 1164 goto deferred; 1165 } 1166#endif 1167 1168 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { 1169 case -EPIPE: --- 136 unchanged lines hidden (view full) --- 1306 xdev->bus->bus_name, xdev->devpath, 1307 dev->driver_info->description); 1308 1309 net = dev->net; 1310 unregister_netdev (net); 1311 1312 cancel_work_sync(&dev->kevent); 1313 | 1161 spin_unlock_irqrestore(&dev->txq.lock, flags); 1162 netdev_dbg(dev->net, "Delaying transmission for resumption\n"); 1163 goto deferred; 1164 } 1165#endif 1166 1167 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { 1168 case -EPIPE: --- 136 unchanged lines hidden (view full) --- 1305 xdev->bus->bus_name, xdev->devpath, 1306 dev->driver_info->description); 1307 1308 net = dev->net; 1309 unregister_netdev (net); 1310 1311 cancel_work_sync(&dev->kevent); 1312 |
1314 usb_scuttle_anchored_urbs(&dev->deferred); 1315 | |
1316 if (dev->driver_info->unbind) 1317 dev->driver_info->unbind (dev, intf); 1318 1319 usb_kill_urb(dev->interrupt); 1320 usb_free_urb(dev->interrupt); 1321 1322 free_netdev(net); 1323} --- 285 unchanged lines hidden (view full) --- 1609 if (!test_and_set_bit(EVENT_DEVICE_REPORT_IDLE, &dev->flags)) { 1610 dev->intf->needs_remote_wakeup = 1; 1611 usb_autopm_put_interface_async(dev->intf); 1612 } 1613} 1614EXPORT_SYMBOL(usbnet_device_suggests_idle); 1615 1616/*-------------------------------------------------------------------------*/ | 1313 if (dev->driver_info->unbind) 1314 dev->driver_info->unbind (dev, intf); 1315 1316 usb_kill_urb(dev->interrupt); 1317 usb_free_urb(dev->interrupt); 1318 1319 free_netdev(net); 1320} --- 285 unchanged lines hidden (view full) --- 1606 if (!test_and_set_bit(EVENT_DEVICE_REPORT_IDLE, &dev->flags)) { 1607 dev->intf->needs_remote_wakeup = 1; 1608 usb_autopm_put_interface_async(dev->intf); 1609 } 1610} 1611EXPORT_SYMBOL(usbnet_device_suggests_idle); 1612 1613/*-------------------------------------------------------------------------*/ |
1614static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, 1615 u16 value, u16 index, void *data, u16 size) 1616{ 1617 void *buf = NULL; 1618 int err = -ENOMEM; |
|
1617 | 1619 |
1620 netdev_dbg(dev->net, "usbnet_read_cmd cmd=0x%02x reqtype=%02x" 1621 " value=0x%04x index=0x%04x size=%d\n", 1622 cmd, reqtype, value, index, size); 1623 1624 if (data) { 1625 buf = kmalloc(size, GFP_KERNEL); 1626 if (!buf) 1627 goto out; 1628 } 1629 1630 err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), 1631 cmd, reqtype, value, index, buf, size, 1632 USB_CTRL_GET_TIMEOUT); 1633 if (err > 0 && err <= size) 1634 memcpy(data, buf, err); 1635 kfree(buf); 1636out: 1637 return err; 1638} 1639 1640static int __usbnet_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, 1641 u16 value, u16 index, const void *data, 1642 u16 size) 1643{ 1644 void *buf = NULL; 1645 int err = -ENOMEM; 1646 1647 netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" 1648 " value=0x%04x index=0x%04x size=%d\n", 1649 cmd, reqtype, value, index, size); 1650 1651 if (data) { 1652 buf = kmemdup(data, size, GFP_KERNEL); 1653 if (!buf) 1654 goto out; 1655 } 1656 1657 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), 1658 cmd, reqtype, value, index, buf, size, 1659 USB_CTRL_SET_TIMEOUT); 1660 kfree(buf); 1661 1662out: 1663 return err; 1664} 1665 1666/* 1667 * The function can't be called inside suspend/resume callback, 1668 * otherwise deadlock will be caused. 1669 */ 1670int usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, 1671 u16 value, u16 index, void *data, u16 size) 1672{ 1673 return __usbnet_read_cmd(dev, cmd, reqtype, value, index, 1674 data, size); 1675} 1676EXPORT_SYMBOL_GPL(usbnet_read_cmd); 1677 1678/* 1679 * The function can't be called inside suspend/resume callback, 1680 * otherwise deadlock will be caused. 1681 */ 1682int usbnet_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, 1683 u16 value, u16 index, const void *data, u16 size) 1684{ 1685 return __usbnet_write_cmd(dev, cmd, reqtype, value, index, 1686 data, size); 1687} 1688EXPORT_SYMBOL_GPL(usbnet_write_cmd); 1689 1690/* 1691 * The function can be called inside suspend/resume callback safely 1692 * and should only be called by suspend/resume callback generally. 1693 */ 1694int usbnet_read_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype, 1695 u16 value, u16 index, void *data, u16 size) 1696{ 1697 return __usbnet_read_cmd(dev, cmd, reqtype, value, index, 1698 data, size); 1699} 1700EXPORT_SYMBOL_GPL(usbnet_read_cmd_nopm); 1701 1702/* 1703 * The function can be called inside suspend/resume callback safely 1704 * and should only be called by suspend/resume callback generally. 1705 */ 1706int usbnet_write_cmd_nopm(struct usbnet *dev, u8 cmd, u8 reqtype, 1707 u16 value, u16 index, const void *data, 1708 u16 size) 1709{ 1710 return __usbnet_write_cmd(dev, cmd, reqtype, value, index, 1711 data, size); 1712} 1713EXPORT_SYMBOL_GPL(usbnet_write_cmd_nopm); 1714 1715static void usbnet_async_cmd_cb(struct urb *urb) 1716{ 1717 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; 1718 int status = urb->status; 1719 1720 if (status < 0) 1721 dev_dbg(&urb->dev->dev, "%s failed with %d", 1722 __func__, status); 1723 1724 kfree(req); 1725 usb_free_urb(urb); 1726} 1727 1728/* 1729 * The caller must make sure that device can't be put into suspend 1730 * state until the control URB completes. 1731 */ 1732int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype, 1733 u16 value, u16 index, const void *data, u16 size) 1734{ 1735 struct usb_ctrlrequest *req = NULL; 1736 struct urb *urb; 1737 int err = -ENOMEM; 1738 void *buf = NULL; 1739 1740 netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" 1741 " value=0x%04x index=0x%04x size=%d\n", 1742 cmd, reqtype, value, index, size); 1743 1744 urb = usb_alloc_urb(0, GFP_ATOMIC); 1745 if (!urb) { 1746 netdev_err(dev->net, "Error allocating URB in" 1747 " %s!\n", __func__); 1748 goto fail; 1749 } 1750 1751 if (data) { 1752 buf = kmemdup(data, size, GFP_ATOMIC); 1753 if (!buf) { 1754 netdev_err(dev->net, "Error allocating buffer" 1755 " in %s!\n", __func__); 1756 goto fail_free; 1757 } 1758 } 1759 1760 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC); 1761 if (!req) { 1762 netdev_err(dev->net, "Failed to allocate memory for %s\n", 1763 __func__); 1764 goto fail_free_buf; 1765 } 1766 1767 req->bRequestType = reqtype; 1768 req->bRequest = cmd; 1769 req->wValue = cpu_to_le16(value); 1770 req->wIndex = cpu_to_le16(index); 1771 req->wLength = cpu_to_le16(size); 1772 1773 usb_fill_control_urb(urb, dev->udev, 1774 usb_sndctrlpipe(dev->udev, 0), 1775 (void *)req, buf, size, 1776 usbnet_async_cmd_cb, req); 1777 urb->transfer_flags |= URB_FREE_BUFFER; 1778 1779 err = usb_submit_urb(urb, GFP_ATOMIC); 1780 if (err < 0) { 1781 netdev_err(dev->net, "Error submitting the control" 1782 " message: status=%d\n", err); 1783 goto fail_free; 1784 } 1785 return 0; 1786 1787fail_free_buf: 1788 kfree(buf); 1789fail_free: 1790 kfree(req); 1791 usb_free_urb(urb); 1792fail: 1793 return err; 1794 1795} 1796EXPORT_SYMBOL_GPL(usbnet_write_cmd_async); 1797/*-------------------------------------------------------------------------*/ 1798 |
|
1618static int __init usbnet_init(void) 1619{ 1620 /* Compiler should optimize this out. */ 1621 BUILD_BUG_ON( 1622 FIELD_SIZEOF(struct sk_buff, cb) < sizeof(struct skb_data)); 1623 1624 eth_random_addr(node_id); 1625 return 0; 1626} 1627module_init(usbnet_init); 1628 1629static void __exit usbnet_exit(void) 1630{ 1631} 1632module_exit(usbnet_exit); 1633 1634MODULE_AUTHOR("David Brownell"); 1635MODULE_DESCRIPTION("USB network driver framework"); 1636MODULE_LICENSE("GPL"); | 1799static int __init usbnet_init(void) 1800{ 1801 /* Compiler should optimize this out. */ 1802 BUILD_BUG_ON( 1803 FIELD_SIZEOF(struct sk_buff, cb) < sizeof(struct skb_data)); 1804 1805 eth_random_addr(node_id); 1806 return 0; 1807} 1808module_init(usbnet_init); 1809 1810static void __exit usbnet_exit(void) 1811{ 1812} 1813module_exit(usbnet_exit); 1814 1815MODULE_AUTHOR("David Brownell"); 1816MODULE_DESCRIPTION("USB network driver framework"); 1817MODULE_LICENSE("GPL"); |