aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/at91_udc.c37
-rw-r--r--drivers/usb/gadget/at91_udc.h1
-rw-r--r--drivers/usb/gadget/config.c2
-rw-r--r--drivers/usb/gadget/dummy_hcd.c1
-rw-r--r--drivers/usb/gadget/epautoconf.c2
-rw-r--r--drivers/usb/gadget/ether.c149
-rw-r--r--drivers/usb/gadget/file_storage.c35
-rw-r--r--drivers/usb/gadget/gadget_chips.h8
-rw-r--r--drivers/usb/gadget/gmidi.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c3
-rw-r--r--drivers/usb/gadget/inode.c240
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.h2
-rw-r--r--drivers/usb/gadget/net2280.c3
-rw-r--r--drivers/usb/gadget/omap_udc.c3
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c5
-rw-r--r--drivers/usb/gadget/rndis.c1
-rw-r--r--drivers/usb/gadget/serial.c4
-rw-r--r--drivers/usb/gadget/usbstring.c2
-rw-r--r--drivers/usb/gadget/zero.c3
19 files changed, 271 insertions, 232 deletions
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 8afecb8a98ee..a4677802fb20 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -30,7 +30,6 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/ioport.h> 32#include <linux/ioport.h>
33#include <linux/sched.h>
34#include <linux/slab.h> 33#include <linux/slab.h>
35#include <linux/smp_lock.h> 34#include <linux/smp_lock.h>
36#include <linux/errno.h> 35#include <linux/errno.h>
@@ -39,7 +38,7 @@
39#include <linux/interrupt.h> 38#include <linux/interrupt.h>
40#include <linux/proc_fs.h> 39#include <linux/proc_fs.h>
41#include <linux/clk.h> 40#include <linux/clk.h>
42#include <linux/usb_ch9.h> 41#include <linux/usb/ch9.h>
43#include <linux/usb_gadget.h> 42#include <linux/usb_gadget.h>
44 43
45#include <asm/byteorder.h> 44#include <asm/byteorder.h>
@@ -785,7 +784,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
785 return status; 784 return status;
786} 785}
787 786
788static struct usb_ep_ops at91_ep_ops = { 787static const struct usb_ep_ops at91_ep_ops = {
789 .enable = at91_ep_enable, 788 .enable = at91_ep_enable,
790 .disable = at91_ep_disable, 789 .disable = at91_ep_disable,
791 .alloc_request = at91_ep_alloc_request, 790 .alloc_request = at91_ep_alloc_request,
@@ -1652,7 +1651,7 @@ static void at91udc_shutdown(struct platform_device *dev)
1652 pullup(platform_get_drvdata(dev), 0); 1651 pullup(platform_get_drvdata(dev), 0);
1653} 1652}
1654 1653
1655static int __devinit at91udc_probe(struct platform_device *pdev) 1654static int __init at91udc_probe(struct platform_device *pdev)
1656{ 1655{
1657 struct device *dev = &pdev->dev; 1656 struct device *dev = &pdev->dev;
1658 struct at91_udc *udc; 1657 struct at91_udc *udc;
@@ -1763,7 +1762,7 @@ fail0:
1763 return retval; 1762 return retval;
1764} 1763}
1765 1764
1766static int __devexit at91udc_remove(struct platform_device *pdev) 1765static int __exit at91udc_remove(struct platform_device *pdev)
1767{ 1766{
1768 struct at91_udc *udc = platform_get_drvdata(pdev); 1767 struct at91_udc *udc = platform_get_drvdata(pdev);
1769 struct resource *res; 1768 struct resource *res;
@@ -1807,16 +1806,13 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
1807 || !wake 1806 || !wake
1808 || at91_suspend_entering_slow_clock()) { 1807 || at91_suspend_entering_slow_clock()) {
1809 pullup(udc, 0); 1808 pullup(udc, 0);
1810 disable_irq_wake(udc->udp_irq); 1809 wake = 0;
1811 } else 1810 } else
1812 enable_irq_wake(udc->udp_irq); 1811 enable_irq_wake(udc->udp_irq);
1813 1812
1814 if (udc->board.vbus_pin > 0) { 1813 udc->active_suspend = wake;
1815 if (wake) 1814 if (udc->board.vbus_pin > 0 && wake)
1816 enable_irq_wake(udc->board.vbus_pin); 1815 enable_irq_wake(udc->board.vbus_pin);
1817 else
1818 disable_irq_wake(udc->board.vbus_pin);
1819 }
1820 return 0; 1816 return 0;
1821} 1817}
1822 1818
@@ -1824,8 +1820,14 @@ static int at91udc_resume(struct platform_device *pdev)
1824{ 1820{
1825 struct at91_udc *udc = platform_get_drvdata(pdev); 1821 struct at91_udc *udc = platform_get_drvdata(pdev);
1826 1822
1823 if (udc->board.vbus_pin > 0 && udc->active_suspend)
1824 disable_irq_wake(udc->board.vbus_pin);
1825
1827 /* maybe reconnect to host; if so, clocks on */ 1826 /* maybe reconnect to host; if so, clocks on */
1828 pullup(udc, 1); 1827 if (udc->active_suspend)
1828 disable_irq_wake(udc->udp_irq);
1829 else
1830 pullup(udc, 1);
1829 return 0; 1831 return 0;
1830} 1832}
1831#else 1833#else
@@ -1834,8 +1836,7 @@ static int at91udc_resume(struct platform_device *pdev)
1834#endif 1836#endif
1835 1837
1836static struct platform_driver at91_udc = { 1838static struct platform_driver at91_udc = {
1837 .probe = at91udc_probe, 1839 .remove = __exit_p(at91udc_remove),
1838 .remove = __devexit_p(at91udc_remove),
1839 .shutdown = at91udc_shutdown, 1840 .shutdown = at91udc_shutdown,
1840 .suspend = at91udc_suspend, 1841 .suspend = at91udc_suspend,
1841 .resume = at91udc_resume, 1842 .resume = at91udc_resume,
@@ -1845,13 +1846,13 @@ static struct platform_driver at91_udc = {
1845 }, 1846 },
1846}; 1847};
1847 1848
1848static int __devinit udc_init_module(void) 1849static int __init udc_init_module(void)
1849{ 1850{
1850 return platform_driver_register(&at91_udc); 1851 return platform_driver_probe(&at91_udc, at91udc_probe);
1851} 1852}
1852module_init(udc_init_module); 1853module_init(udc_init_module);
1853 1854
1854static void __devexit udc_exit_module(void) 1855static void __exit udc_exit_module(void)
1855{ 1856{
1856 platform_driver_unregister(&at91_udc); 1857 platform_driver_unregister(&at91_udc);
1857} 1858}
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index 677089baa59d..7e34e2f864f9 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -136,6 +136,7 @@ struct at91_udc {
136 unsigned wait_for_addr_ack:1; 136 unsigned wait_for_addr_ack:1;
137 unsigned wait_for_config_ack:1; 137 unsigned wait_for_config_ack:1;
138 unsigned selfpowered:1; 138 unsigned selfpowered:1;
139 unsigned active_suspend:1;
139 u8 addr; 140 u8 addr;
140 struct at91_udc_data board; 141 struct at91_udc_data board;
141 struct clk *iclk, *fclk; 142 struct clk *iclk, *fclk;
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index 83b4866df9af..d18901b92cda 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -24,7 +24,7 @@
24#include <linux/string.h> 24#include <linux/string.h>
25#include <linux/device.h> 25#include <linux/device.h>
26 26
27#include <linux/usb_ch9.h> 27#include <linux/usb/ch9.h>
28#include <linux/usb_gadget.h> 28#include <linux/usb_gadget.h>
29 29
30 30
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 3c2bc075ef4f..7d7909cf2558 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -40,7 +40,6 @@
40#include <linux/kernel.h> 40#include <linux/kernel.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/ioport.h> 42#include <linux/ioport.h>
43#include <linux/sched.h>
44#include <linux/slab.h> 43#include <linux/slab.h>
45#include <linux/smp_lock.h> 44#include <linux/smp_lock.h>
46#include <linux/errno.h> 45#include <linux/errno.h>
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 53d584589c26..f28af06905a5 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -27,7 +27,7 @@
27#include <linux/ctype.h> 27#include <linux/ctype.h>
28#include <linux/string.h> 28#include <linux/string.h>
29 29
30#include <linux/usb_ch9.h> 30#include <linux/usb/ch9.h>
31#include <linux/usb_gadget.h> 31#include <linux/usb_gadget.h>
32 32
33#include "gadget_chips.h" 33#include "gadget_chips.h"
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index d15bf22b9a03..04e6b8508fb6 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -27,7 +27,6 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/ioport.h> 29#include <linux/ioport.h>
30#include <linux/sched.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
32#include <linux/smp_lock.h> 31#include <linux/smp_lock.h>
33#include <linux/errno.h> 32#include <linux/errno.h>
@@ -47,7 +46,7 @@
47#include <asm/uaccess.h> 46#include <asm/uaccess.h>
48#include <asm/unaligned.h> 47#include <asm/unaligned.h>
49 48
50#include <linux/usb_ch9.h> 49#include <linux/usb/ch9.h>
51#include <linux/usb/cdc.h> 50#include <linux/usb/cdc.h>
52#include <linux/usb_gadget.h> 51#include <linux/usb_gadget.h>
53 52
@@ -72,9 +71,18 @@
72 * 71 *
73 * There's some hardware that can't talk CDC. We make that hardware 72 * There's some hardware that can't talk CDC. We make that hardware
74 * implement a "minimalist" vendor-agnostic CDC core: same framing, but 73 * implement a "minimalist" vendor-agnostic CDC core: same framing, but
75 * link-level setup only requires activating the configuration. 74 * link-level setup only requires activating the configuration. Only the
76 * Linux supports it, but other host operating systems may not. 75 * endpoint descriptors, and product/vendor IDs, are relevant; no control
77 * (This is a subset of CDC Ethernet.) 76 * operations are available. Linux supports it, but other host operating
77 * systems may not. (This is a subset of CDC Ethernet.)
78 *
79 * It turns out that if you add a few descriptors to that "CDC Subset",
80 * (Windows) host side drivers from MCCI can treat it as one submode of
81 * a proprietary scheme called "SAFE" ... without needing to know about
82 * specific product/vendor IDs. So we do that, making it easier to use
83 * those MS-Windows drivers. Those added descriptors make it resemble a
84 * CDC MDLM device, but they don't change device behavior at all. (See
85 * MCCI Engineering report 950198 "SAFE Networking Functions".)
78 * 86 *
79 * A third option is also in use. Rather than CDC Ethernet, or something 87 * A third option is also in use. Rather than CDC Ethernet, or something
80 * simpler, Microsoft pushes their own approach: RNDIS. The published 88 * simpler, Microsoft pushes their own approach: RNDIS. The published
@@ -254,6 +262,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
254#define DEV_CONFIG_CDC 262#define DEV_CONFIG_CDC
255#endif 263#endif
256 264
265#ifdef CONFIG_USB_GADGET_S3C2410
266#define DEV_CONFIG_CDC
267#endif
268
257#ifdef CONFIG_USB_GADGET_AT91 269#ifdef CONFIG_USB_GADGET_AT91
258#define DEV_CONFIG_CDC 270#define DEV_CONFIG_CDC
259#endif 271#endif
@@ -266,6 +278,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
266#define DEV_CONFIG_CDC 278#define DEV_CONFIG_CDC
267#endif 279#endif
268 280
281#ifdef CONFIG_USB_GADGET_HUSB2DEV
282#define DEV_CONFIG_CDC
283#endif
284
269 285
270/* For CDC-incapable hardware, choose the simple cdc subset. 286/* For CDC-incapable hardware, choose the simple cdc subset.
271 * Anything that talks bulk (without notable bugs) can do this. 287 * Anything that talks bulk (without notable bugs) can do this.
@@ -283,9 +299,6 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
283#define DEV_CONFIG_SUBSET 299#define DEV_CONFIG_SUBSET
284#endif 300#endif
285 301
286#ifdef CONFIG_USB_GADGET_S3C2410
287#define DEV_CONFIG_CDC
288#endif
289 302
290/*-------------------------------------------------------------------------*/ 303/*-------------------------------------------------------------------------*/
291 304
@@ -487,8 +500,17 @@ rndis_config = {
487 * endpoint. Both have a "data" interface and two bulk endpoints. 500 * endpoint. Both have a "data" interface and two bulk endpoints.
488 * There are also differences in how control requests are handled. 501 * There are also differences in how control requests are handled.
489 * 502 *
490 * RNDIS shares a lot with CDC-Ethernet, since it's a variant of 503 * RNDIS shares a lot with CDC-Ethernet, since it's a variant of the
491 * the CDC-ACM (modem) spec. 504 * CDC-ACM (modem) spec. Unfortunately MSFT's RNDIS driver is buggy; it
505 * may hang or oops. Since bugfixes (or accurate specs, letting Linux
506 * work around those bugs) are unlikely to ever come from MSFT, you may
507 * wish to avoid using RNDIS.
508 *
509 * MCCI offers an alternative to RNDIS if you need to connect to Windows
510 * but have hardware that can't support CDC Ethernet. We add descriptors
511 * to present the CDC Subset as a (nonconformant) CDC MDLM variant called
512 * "SAFE". That borrows from both CDC Ethernet and CDC MDLM. You can
513 * get those drivers from MCCI, or bundled with various products.
492 */ 514 */
493 515
494#ifdef DEV_CONFIG_CDC 516#ifdef DEV_CONFIG_CDC
@@ -522,8 +544,6 @@ rndis_control_intf = {
522}; 544};
523#endif 545#endif
524 546
525#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
526
527static const struct usb_cdc_header_desc header_desc = { 547static const struct usb_cdc_header_desc header_desc = {
528 .bLength = sizeof header_desc, 548 .bLength = sizeof header_desc,
529 .bDescriptorType = USB_DT_CS_INTERFACE, 549 .bDescriptorType = USB_DT_CS_INTERFACE,
@@ -532,6 +552,8 @@ static const struct usb_cdc_header_desc header_desc = {
532 .bcdCDC = __constant_cpu_to_le16 (0x0110), 552 .bcdCDC = __constant_cpu_to_le16 (0x0110),
533}; 553};
534 554
555#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
556
535static const struct usb_cdc_union_desc union_desc = { 557static const struct usb_cdc_union_desc union_desc = {
536 .bLength = sizeof union_desc, 558 .bLength = sizeof union_desc,
537 .bDescriptorType = USB_DT_CS_INTERFACE, 559 .bDescriptorType = USB_DT_CS_INTERFACE,
@@ -564,7 +586,40 @@ static const struct usb_cdc_acm_descriptor acm_descriptor = {
564 586
565#endif 587#endif
566 588
567#ifdef DEV_CONFIG_CDC 589#ifndef DEV_CONFIG_CDC
590
591/* "SAFE" loosely follows CDC WMC MDLM, violating the spec in various
592 * ways: data endpoints live in the control interface, there's no data
593 * interface, and it's not used to talk to a cell phone radio.
594 */
595
596static const struct usb_cdc_mdlm_desc mdlm_desc = {
597 .bLength = sizeof mdlm_desc,
598 .bDescriptorType = USB_DT_CS_INTERFACE,
599 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
600
601 .bcdVersion = __constant_cpu_to_le16(0x0100),
602 .bGUID = {
603 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
604 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
605 },
606};
607
608/* since "usb_cdc_mdlm_detail_desc" is a variable length structure, we
609 * can't really use its struct. All we do here is say that we're using
610 * the submode of "SAFE" which directly matches the CDC Subset.
611 */
612static const u8 mdlm_detail_desc[] = {
613 6,
614 USB_DT_CS_INTERFACE,
615 USB_CDC_MDLM_DETAIL_TYPE,
616
617 0, /* "SAFE" */
618 0, /* network control capabilities (none) */
619 0, /* network data capabilities ("raw" encapsulation) */
620};
621
622#endif
568 623
569static const struct usb_cdc_ether_desc ether_desc = { 624static const struct usb_cdc_ether_desc ether_desc = {
570 .bLength = sizeof ether_desc, 625 .bLength = sizeof ether_desc,
@@ -579,7 +634,6 @@ static const struct usb_cdc_ether_desc ether_desc = {
579 .bNumberPowerFilters = 0, 634 .bNumberPowerFilters = 0,
580}; 635};
581 636
582#endif
583 637
584#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 638#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
585 639
@@ -672,6 +726,9 @@ rndis_data_intf = {
672/* 726/*
673 * "Simple" CDC-subset option is a simple vendor-neutral model that most 727 * "Simple" CDC-subset option is a simple vendor-neutral model that most
674 * full speed controllers can handle: one interface, two bulk endpoints. 728 * full speed controllers can handle: one interface, two bulk endpoints.
729 *
730 * To assist host side drivers, we fancy it up a bit, and add descriptors
731 * so some host side drivers will understand it as a "SAFE" variant.
675 */ 732 */
676 733
677static const struct usb_interface_descriptor 734static const struct usb_interface_descriptor
@@ -682,8 +739,8 @@ subset_data_intf = {
682 .bInterfaceNumber = 0, 739 .bInterfaceNumber = 0,
683 .bAlternateSetting = 0, 740 .bAlternateSetting = 0,
684 .bNumEndpoints = 2, 741 .bNumEndpoints = 2,
685 .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 742 .bInterfaceClass = USB_CLASS_COMM,
686 .bInterfaceSubClass = 0, 743 .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM,
687 .bInterfaceProtocol = 0, 744 .bInterfaceProtocol = 0,
688 .iInterface = STRING_DATA, 745 .iInterface = STRING_DATA,
689}; 746};
@@ -731,10 +788,15 @@ static const struct usb_descriptor_header *fs_eth_function [11] = {
731static inline void __init fs_subset_descriptors(void) 788static inline void __init fs_subset_descriptors(void)
732{ 789{
733#ifdef DEV_CONFIG_SUBSET 790#ifdef DEV_CONFIG_SUBSET
791 /* behavior is "CDC Subset"; extra descriptors say "SAFE" */
734 fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf; 792 fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
735 fs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc; 793 fs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
736 fs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc; 794 fs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
737 fs_eth_function[4] = NULL; 795 fs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
796 fs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc;
797 fs_eth_function[6] = (struct usb_descriptor_header *) &fs_source_desc;
798 fs_eth_function[7] = (struct usb_descriptor_header *) &fs_sink_desc;
799 fs_eth_function[8] = NULL;
738#else 800#else
739 fs_eth_function[1] = NULL; 801 fs_eth_function[1] = NULL;
740#endif 802#endif
@@ -828,10 +890,15 @@ static const struct usb_descriptor_header *hs_eth_function [11] = {
828static inline void __init hs_subset_descriptors(void) 890static inline void __init hs_subset_descriptors(void)
829{ 891{
830#ifdef DEV_CONFIG_SUBSET 892#ifdef DEV_CONFIG_SUBSET
893 /* behavior is "CDC Subset"; extra descriptors say "SAFE" */
831 hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf; 894 hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
832 hs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc; 895 hs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
833 hs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc; 896 hs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
834 hs_eth_function[4] = NULL; 897 hs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
898 hs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc;
899 hs_eth_function[6] = (struct usb_descriptor_header *) &hs_source_desc;
900 hs_eth_function[7] = (struct usb_descriptor_header *) &hs_sink_desc;
901 hs_eth_function[8] = NULL;
835#else 902#else
836 hs_eth_function[1] = NULL; 903 hs_eth_function[1] = NULL;
837#endif 904#endif
@@ -878,10 +945,8 @@ static char manufacturer [50];
878static char product_desc [40] = DRIVER_DESC; 945static char product_desc [40] = DRIVER_DESC;
879static char serial_number [20]; 946static char serial_number [20];
880 947
881#ifdef DEV_CONFIG_CDC
882/* address that the host will use ... usually assigned at random */ 948/* address that the host will use ... usually assigned at random */
883static char ethaddr [2 * ETH_ALEN + 1]; 949static char ethaddr [2 * ETH_ALEN + 1];
884#endif
885 950
886/* static strings, in UTF-8 */ 951/* static strings, in UTF-8 */
887static struct usb_string strings [] = { 952static struct usb_string strings [] = {
@@ -889,9 +954,9 @@ static struct usb_string strings [] = {
889 { STRING_PRODUCT, product_desc, }, 954 { STRING_PRODUCT, product_desc, },
890 { STRING_SERIALNUMBER, serial_number, }, 955 { STRING_SERIALNUMBER, serial_number, },
891 { STRING_DATA, "Ethernet Data", }, 956 { STRING_DATA, "Ethernet Data", },
957 { STRING_ETHADDR, ethaddr, },
892#ifdef DEV_CONFIG_CDC 958#ifdef DEV_CONFIG_CDC
893 { STRING_CDC, "CDC Ethernet", }, 959 { STRING_CDC, "CDC Ethernet", },
894 { STRING_ETHADDR, ethaddr, },
895 { STRING_CONTROL, "CDC Communications Control", }, 960 { STRING_CONTROL, "CDC Communications Control", },
896#endif 961#endif
897#ifdef DEV_CONFIG_SUBSET 962#ifdef DEV_CONFIG_SUBSET
@@ -986,10 +1051,10 @@ set_ether_config (struct eth_dev *dev, gfp_t gfp_flags)
986 } 1051 }
987#endif 1052#endif
988 1053
989 dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 1054 dev->in = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
990 dev->in_ep->driver_data = dev; 1055 dev->in_ep->driver_data = dev;
991 1056
992 dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); 1057 dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
993 dev->out_ep->driver_data = dev; 1058 dev->out_ep->driver_data = dev;
994 1059
995 /* With CDC, the host isn't allowed to use these two data 1060 /* With CDC, the host isn't allowed to use these two data
@@ -2278,10 +2343,10 @@ eth_bind (struct usb_gadget *gadget)
2278 "RNDIS/%s", driver_desc); 2343 "RNDIS/%s", driver_desc);
2279 2344
2280 /* CDC subset ... recognized by Linux since 2.4.10, but Windows 2345 /* CDC subset ... recognized by Linux since 2.4.10, but Windows
2281 * drivers aren't widely available. 2346 * drivers aren't widely available. (That may be improved by
2347 * supporting one submode of the "SAFE" variant of MDLM.)
2282 */ 2348 */
2283 } else if (!cdc) { 2349 } else if (!cdc) {
2284 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
2285 device_desc.idVendor = 2350 device_desc.idVendor =
2286 __constant_cpu_to_le16(SIMPLE_VENDOR_NUM); 2351 __constant_cpu_to_le16(SIMPLE_VENDOR_NUM);
2287 device_desc.idProduct = 2352 device_desc.idProduct =
@@ -2352,6 +2417,10 @@ autoconf_fail:
2352 if (!cdc) { 2417 if (!cdc) {
2353 eth_config.bNumInterfaces = 1; 2418 eth_config.bNumInterfaces = 1;
2354 eth_config.iConfiguration = STRING_SUBSET; 2419 eth_config.iConfiguration = STRING_SUBSET;
2420
2421 /* use functions to set these up, in case we're built to work
2422 * with multiple controllers and must override CDC Ethernet.
2423 */
2355 fs_subset_descriptors(); 2424 fs_subset_descriptors();
2356 hs_subset_descriptors(); 2425 hs_subset_descriptors();
2357 } 2426 }
@@ -2415,22 +2484,20 @@ autoconf_fail:
2415 2484
2416 /* Module params for these addresses should come from ID proms. 2485 /* Module params for these addresses should come from ID proms.
2417 * The host side address is used with CDC and RNDIS, and commonly 2486 * The host side address is used with CDC and RNDIS, and commonly
2418 * ends up in a persistent config database. 2487 * ends up in a persistent config database. It's not clear if
2488 * host side code for the SAFE thing cares -- its original BLAN
2489 * thing didn't, Sharp never assigned those addresses on Zaurii.
2419 */ 2490 */
2420 if (get_ether_addr(dev_addr, net->dev_addr)) 2491 if (get_ether_addr(dev_addr, net->dev_addr))
2421 dev_warn(&gadget->dev, 2492 dev_warn(&gadget->dev,
2422 "using random %s ethernet address\n", "self"); 2493 "using random %s ethernet address\n", "self");
2423 if (cdc || rndis) { 2494 if (get_ether_addr(host_addr, dev->host_mac))
2424 if (get_ether_addr(host_addr, dev->host_mac)) 2495 dev_warn(&gadget->dev,
2425 dev_warn(&gadget->dev, 2496 "using random %s ethernet address\n", "host");
2426 "using random %s ethernet address\n", "host"); 2497 snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X",
2427#ifdef DEV_CONFIG_CDC 2498 dev->host_mac [0], dev->host_mac [1],
2428 snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X", 2499 dev->host_mac [2], dev->host_mac [3],
2429 dev->host_mac [0], dev->host_mac [1], 2500 dev->host_mac [4], dev->host_mac [5]);
2430 dev->host_mac [2], dev->host_mac [3],
2431 dev->host_mac [4], dev->host_mac [5]);
2432#endif
2433 }
2434 2501
2435 if (rndis) { 2502 if (rndis) {
2436 status = rndis_init(); 2503 status = rndis_init();
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 72f2ae96fbf3..c6b6479fa4dd 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -253,7 +253,7 @@
253#include <linux/freezer.h> 253#include <linux/freezer.h>
254#include <linux/utsname.h> 254#include <linux/utsname.h>
255 255
256#include <linux/usb_ch9.h> 256#include <linux/usb/ch9.h>
257#include <linux/usb_gadget.h> 257#include <linux/usb_gadget.h>
258 258
259#include "gadget_chips.h" 259#include "gadget_chips.h"
@@ -1148,7 +1148,7 @@ static int ep0_queue(struct fsg_dev *fsg)
1148 1148
1149static void ep0_complete(struct usb_ep *ep, struct usb_request *req) 1149static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
1150{ 1150{
1151 struct fsg_dev *fsg = (struct fsg_dev *) ep->driver_data; 1151 struct fsg_dev *fsg = ep->driver_data;
1152 1152
1153 if (req->actual > 0) 1153 if (req->actual > 0)
1154 dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual); 1154 dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
@@ -1170,8 +1170,8 @@ static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
1170 1170
1171static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req) 1171static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
1172{ 1172{
1173 struct fsg_dev *fsg = (struct fsg_dev *) ep->driver_data; 1173 struct fsg_dev *fsg = ep->driver_data;
1174 struct fsg_buffhd *bh = (struct fsg_buffhd *) req->context; 1174 struct fsg_buffhd *bh = req->context;
1175 1175
1176 if (req->status || req->actual != req->length) 1176 if (req->status || req->actual != req->length)
1177 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1177 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__,
@@ -1190,8 +1190,8 @@ static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
1190 1190
1191static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) 1191static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
1192{ 1192{
1193 struct fsg_dev *fsg = (struct fsg_dev *) ep->driver_data; 1193 struct fsg_dev *fsg = ep->driver_data;
1194 struct fsg_buffhd *bh = (struct fsg_buffhd *) req->context; 1194 struct fsg_buffhd *bh = req->context;
1195 1195
1196 dump_msg(fsg, "bulk-out", req->buf, req->actual); 1196 dump_msg(fsg, "bulk-out", req->buf, req->actual);
1197 if (req->status || req->actual != bh->bulk_out_intended_length) 1197 if (req->status || req->actual != bh->bulk_out_intended_length)
@@ -1214,8 +1214,8 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
1214#ifdef CONFIG_USB_FILE_STORAGE_TEST 1214#ifdef CONFIG_USB_FILE_STORAGE_TEST
1215static void intr_in_complete(struct usb_ep *ep, struct usb_request *req) 1215static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
1216{ 1216{
1217 struct fsg_dev *fsg = (struct fsg_dev *) ep->driver_data; 1217 struct fsg_dev *fsg = ep->driver_data;
1218 struct fsg_buffhd *bh = (struct fsg_buffhd *) req->context; 1218 struct fsg_buffhd *bh = req->context;
1219 1219
1220 if (req->status || req->actual != req->length) 1220 if (req->status || req->actual != req->length)
1221 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__, 1221 DBG(fsg, "%s --> %d, %u/%u\n", __FUNCTION__,
@@ -1953,7 +1953,7 @@ static void invalidate_sub(struct lun *curlun)
1953 struct inode *inode = filp->f_path.dentry->d_inode; 1953 struct inode *inode = filp->f_path.dentry->d_inode;
1954 unsigned long rc; 1954 unsigned long rc;
1955 1955
1956 rc = invalidate_inode_pages(inode->i_mapping); 1956 rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
1957 VLDBG(curlun, "invalidate_inode_pages -> %ld\n", rc); 1957 VLDBG(curlun, "invalidate_inode_pages -> %ld\n", rc);
1958} 1958}
1959 1959
@@ -2577,7 +2577,7 @@ static int send_status(struct fsg_dev *fsg)
2577 } 2577 }
2578 2578
2579 if (transport_is_bbb()) { 2579 if (transport_is_bbb()) {
2580 struct bulk_cs_wrap *csw = (struct bulk_cs_wrap *) bh->buf; 2580 struct bulk_cs_wrap *csw = bh->buf;
2581 2581
2582 /* Store and send the Bulk-only CSW */ 2582 /* Store and send the Bulk-only CSW */
2583 csw->Signature = __constant_cpu_to_le32(USB_BULK_CS_SIG); 2583 csw->Signature = __constant_cpu_to_le32(USB_BULK_CS_SIG);
@@ -2596,8 +2596,7 @@ static int send_status(struct fsg_dev *fsg)
2596 return 0; 2596 return 0;
2597 2597
2598 } else { // USB_PR_CBI 2598 } else { // USB_PR_CBI
2599 struct interrupt_data *buf = (struct interrupt_data *) 2599 struct interrupt_data *buf = bh->buf;
2600 bh->buf;
2601 2600
2602 /* Store and send the Interrupt data. UFI sends the ASC 2601 /* Store and send the Interrupt data. UFI sends the ASC
2603 * and ASCQ bytes. Everything else sends a Type (which 2602 * and ASCQ bytes. Everything else sends a Type (which
@@ -2982,7 +2981,7 @@ static int do_scsi_command(struct fsg_dev *fsg)
2982static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) 2981static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2983{ 2982{
2984 struct usb_request *req = bh->outreq; 2983 struct usb_request *req = bh->outreq;
2985 struct bulk_cb_wrap *cbw = (struct bulk_cb_wrap *) req->buf; 2984 struct bulk_cb_wrap *cbw = req->buf;
2986 2985
2987 /* Was this a real packet? */ 2986 /* Was this a real packet? */
2988 if (req->status) 2987 if (req->status)
@@ -3428,7 +3427,7 @@ static void handle_exception(struct fsg_dev *fsg)
3428 3427
3429static int fsg_main_thread(void *fsg_) 3428static int fsg_main_thread(void *fsg_)
3430{ 3429{
3431 struct fsg_dev *fsg = (struct fsg_dev *) fsg_; 3430 struct fsg_dev *fsg = fsg_;
3432 3431
3433 /* Allow the thread to be killed by a signal, but set the signal mask 3432 /* Allow the thread to be killed by a signal, but set the signal mask
3434 * to block everything but INT, TERM, KILL, and USR1. */ 3433 * to block everything but INT, TERM, KILL, and USR1. */
@@ -3600,7 +3599,7 @@ static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char *
3600static ssize_t show_file(struct device *dev, struct device_attribute *attr, char *buf) 3599static ssize_t show_file(struct device *dev, struct device_attribute *attr, char *buf)
3601{ 3600{
3602 struct lun *curlun = dev_to_lun(dev); 3601 struct lun *curlun = dev_to_lun(dev);
3603 struct fsg_dev *fsg = (struct fsg_dev *) dev_get_drvdata(dev); 3602 struct fsg_dev *fsg = dev_get_drvdata(dev);
3604 char *p; 3603 char *p;
3605 ssize_t rc; 3604 ssize_t rc;
3606 3605
@@ -3629,7 +3628,7 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr, const
3629{ 3628{
3630 ssize_t rc = count; 3629 ssize_t rc = count;
3631 struct lun *curlun = dev_to_lun(dev); 3630 struct lun *curlun = dev_to_lun(dev);
3632 struct fsg_dev *fsg = (struct fsg_dev *) dev_get_drvdata(dev); 3631 struct fsg_dev *fsg = dev_get_drvdata(dev);
3633 int i; 3632 int i;
3634 3633
3635 if (sscanf(buf, "%d", &i) != 1) 3634 if (sscanf(buf, "%d", &i) != 1)
@@ -3652,7 +3651,7 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr, const
3652static ssize_t store_file(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 3651static ssize_t store_file(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
3653{ 3652{
3654 struct lun *curlun = dev_to_lun(dev); 3653 struct lun *curlun = dev_to_lun(dev);
3655 struct fsg_dev *fsg = (struct fsg_dev *) dev_get_drvdata(dev); 3654 struct fsg_dev *fsg = dev_get_drvdata(dev);
3656 int rc = 0; 3655 int rc = 0;
3657 3656
3658 if (curlun->prevent_medium_removal && backing_file_is_open(curlun)) { 3657 if (curlun->prevent_medium_removal && backing_file_is_open(curlun)) {
@@ -3700,7 +3699,7 @@ static void fsg_release(struct kref *ref)
3700 3699
3701static void lun_release(struct device *dev) 3700static void lun_release(struct device *dev)
3702{ 3701{
3703 struct fsg_dev *fsg = (struct fsg_dev *) dev_get_drvdata(dev); 3702 struct fsg_dev *fsg = dev_get_drvdata(dev);
3704 3703
3705 kref_put(&fsg->ref, fsg_release); 3704 kref_put(&fsg->ref, fsg_release);
3706} 3705}
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index aa80f0910720..2e3d6620d216 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -75,6 +75,12 @@
75#define gadget_is_pxa27x(g) 0 75#define gadget_is_pxa27x(g) 0
76#endif 76#endif
77 77
78#ifdef CONFIG_USB_GADGET_HUSB2DEV
79#define gadget_is_husb2dev(g) !strcmp("husb2_udc", (g)->name)
80#else
81#define gadget_is_husb2dev(g) 0
82#endif
83
78#ifdef CONFIG_USB_GADGET_S3C2410 84#ifdef CONFIG_USB_GADGET_S3C2410
79#define gadget_is_s3c2410(g) !strcmp("s3c2410_udc", (g)->name) 85#define gadget_is_s3c2410(g) !strcmp("s3c2410_udc", (g)->name)
80#else 86#else
@@ -169,5 +175,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
169 return 0x16; 175 return 0x16;
170 else if (gadget_is_mpc8272(gadget)) 176 else if (gadget_is_mpc8272(gadget))
171 return 0x17; 177 return 0x17;
178 else if (gadget_is_husb2dev(gadget))
179 return 0x18;
172 return -ENOENT; 180 return -ENOENT;
173} 181}
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index f1a679656c96..d08a8d0e6427 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -35,7 +35,7 @@
35#include <sound/initval.h> 35#include <sound/initval.h>
36#include <sound/rawmidi.h> 36#include <sound/rawmidi.h>
37 37
38#include <linux/usb_ch9.h> 38#include <linux/usb/ch9.h>
39#include <linux/usb_gadget.h> 39#include <linux/usb_gadget.h>
40#include <linux/usb/audio.h> 40#include <linux/usb/audio.h>
41#include <linux/usb/midi.h> 41#include <linux/usb/midi.h>
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index d0ef1d6b3fac..7b3a326b57ab 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -29,7 +29,6 @@
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/ioport.h> 31#include <linux/ioport.h>
32#include <linux/sched.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
@@ -39,7 +38,7 @@
39#include <linux/interrupt.h> 38#include <linux/interrupt.h>
40#include <linux/proc_fs.h> 39#include <linux/proc_fs.h>
41#include <linux/device.h> 40#include <linux/device.h>
42#include <linux/usb_ch9.h> 41#include <linux/usb/ch9.h>
43#include <linux/usb_gadget.h> 42#include <linux/usb_gadget.h>
44 43
45#include <asm/byteorder.h> 44#include <asm/byteorder.h>
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 3fb1044a4db0..34296e79edcf 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -20,7 +20,7 @@
20 */ 20 */
21 21
22 22
23// #define DEBUG /* data to help fault diagnosis */ 23// #define DEBUG /* data to help fault diagnosis */
24// #define VERBOSE /* extra debug messages (success too) */ 24// #define VERBOSE /* extra debug messages (success too) */
25 25
26#include <linux/init.h> 26#include <linux/init.h>
@@ -59,11 +59,11 @@
59 * may serve as a source of device events, used to handle all control 59 * may serve as a source of device events, used to handle all control
60 * requests other than basic enumeration. 60 * requests other than basic enumeration.
61 * 61 *
62 * - Then either immediately, or after a SET_CONFIGURATION control request, 62 * - Then, after a SET_CONFIGURATION control request, ep_config() is
63 * ep_config() is called when each /dev/gadget/ep* file is configured 63 * called when each /dev/gadget/ep* file is configured (by writing
64 * (by writing endpoint descriptors). Afterwards these files are used 64 * endpoint descriptors). Afterwards these files are used to write()
65 * to write() IN data or to read() OUT data. To halt the endpoint, a 65 * IN data or to read() OUT data. To halt the endpoint, a "wrong
66 * "wrong direction" request is issued (like reading an IN endpoint). 66 * direction" request is issued (like reading an IN endpoint).
67 * 67 *
68 * Unlike "usbfs" the only ioctl()s are for things that are rare, and maybe 68 * Unlike "usbfs" the only ioctl()s are for things that are rare, and maybe
69 * not possible on all hardware. For example, precise fault handling with 69 * not possible on all hardware. For example, precise fault handling with
@@ -98,16 +98,16 @@ enum ep0_state {
98 * must always write descriptors to initialize the device, then 98 * must always write descriptors to initialize the device, then
99 * the device becomes UNCONNECTED until enumeration. 99 * the device becomes UNCONNECTED until enumeration.
100 */ 100 */
101 STATE_OPENED, 101 STATE_DEV_OPENED,
102 102
103 /* From then on, ep0 fd is in either of two basic modes: 103 /* From then on, ep0 fd is in either of two basic modes:
104 * - (UN)CONNECTED: read usb_gadgetfs_event(s) from it 104 * - (UN)CONNECTED: read usb_gadgetfs_event(s) from it
105 * - SETUP: read/write will transfer control data and succeed; 105 * - SETUP: read/write will transfer control data and succeed;
106 * or if "wrong direction", performs protocol stall 106 * or if "wrong direction", performs protocol stall
107 */ 107 */
108 STATE_UNCONNECTED, 108 STATE_DEV_UNCONNECTED,
109 STATE_CONNECTED, 109 STATE_DEV_CONNECTED,
110 STATE_SETUP, 110 STATE_DEV_SETUP,
111 111
112 /* UNBOUND means the driver closed ep0, so the device won't be 112 /* UNBOUND means the driver closed ep0, so the device won't be
113 * accessible again (DEV_DISABLED) until all fds are closed. 113 * accessible again (DEV_DISABLED) until all fds are closed.
@@ -121,7 +121,7 @@ enum ep0_state {
121struct dev_data { 121struct dev_data {
122 spinlock_t lock; 122 spinlock_t lock;
123 atomic_t count; 123 atomic_t count;
124 enum ep0_state state; 124 enum ep0_state state; /* P: lock */
125 struct usb_gadgetfs_event event [N_EVENT]; 125 struct usb_gadgetfs_event event [N_EVENT];
126 unsigned ev_next; 126 unsigned ev_next;
127 struct fasync_struct *fasync; 127 struct fasync_struct *fasync;
@@ -188,7 +188,6 @@ static struct dev_data *dev_new (void)
188enum ep_state { 188enum ep_state {
189 STATE_EP_DISABLED = 0, 189 STATE_EP_DISABLED = 0,
190 STATE_EP_READY, 190 STATE_EP_READY,
191 STATE_EP_DEFER_ENABLE,
192 STATE_EP_ENABLED, 191 STATE_EP_ENABLED,
193 STATE_EP_UNBOUND, 192 STATE_EP_UNBOUND,
194}; 193};
@@ -313,18 +312,10 @@ nonblock:
313 312
314 if ((val = down_interruptible (&epdata->lock)) < 0) 313 if ((val = down_interruptible (&epdata->lock)) < 0)
315 return val; 314 return val;
316newstate: 315
317 switch (epdata->state) { 316 switch (epdata->state) {
318 case STATE_EP_ENABLED: 317 case STATE_EP_ENABLED:
319 break; 318 break;
320 case STATE_EP_DEFER_ENABLE:
321 DBG (epdata->dev, "%s wait for host\n", epdata->name);
322 if ((val = wait_event_interruptible (epdata->wait,
323 epdata->state != STATE_EP_DEFER_ENABLE
324 || epdata->dev->state == STATE_DEV_UNBOUND
325 )) < 0)
326 goto fail;
327 goto newstate;
328 // case STATE_EP_DISABLED: /* "can't happen" */ 319 // case STATE_EP_DISABLED: /* "can't happen" */
329 // case STATE_EP_READY: /* "can't happen" */ 320 // case STATE_EP_READY: /* "can't happen" */
330 default: /* error! */ 321 default: /* error! */
@@ -333,7 +324,6 @@ newstate:
333 // FALLTHROUGH 324 // FALLTHROUGH
334 case STATE_EP_UNBOUND: /* clean disconnect */ 325 case STATE_EP_UNBOUND: /* clean disconnect */
335 val = -ENODEV; 326 val = -ENODEV;
336fail:
337 up (&epdata->lock); 327 up (&epdata->lock);
338 } 328 }
339 return val; 329 return val;
@@ -565,29 +555,28 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb)
565 ssize_t len, total; 555 ssize_t len, total;
566 int i; 556 int i;
567 557
568 /* we "retry" to get the right mm context for this: */ 558 /* we "retry" to get the right mm context for this: */
569 559
570 /* copy stuff into user buffers */ 560 /* copy stuff into user buffers */
571 total = priv->actual; 561 total = priv->actual;
572 len = 0; 562 len = 0;
573 for (i=0; i < priv->nr_segs; i++) { 563 for (i=0; i < priv->nr_segs; i++) {
574 ssize_t this = min((ssize_t)(priv->iv[i].iov_len), total); 564 ssize_t this = min((ssize_t)(priv->iv[i].iov_len), total);
575 565
576 if (copy_to_user(priv->iv[i].iov_base, priv->buf, this)) { 566 if (copy_to_user(priv->iv[i].iov_base, priv->buf, this)) {
577 if (len == 0) 567 if (len == 0)
578 len = -EFAULT; 568 len = -EFAULT;
579 break; 569 break;
580 } 570 }
581 571
582 total -= this; 572 total -= this;
583 len += this; 573 len += this;
584 if (total == 0) 574 if (total == 0)
585 break; 575 break;
586 } 576 }
587 kfree(priv->buf); 577 kfree(priv->buf);
588 kfree(priv); 578 kfree(priv);
589 aio_put_req(iocb); 579 return len;
590 return len;
591} 580}
592 581
593static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req) 582static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
@@ -600,18 +589,17 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
600 spin_lock(&epdata->dev->lock); 589 spin_lock(&epdata->dev->lock);
601 priv->req = NULL; 590 priv->req = NULL;
602 priv->epdata = NULL; 591 priv->epdata = NULL;
603 if (priv->iv == NULL 592
604 || unlikely(req->actual == 0) 593 /* if this was a write or a read returning no data then we
605 || unlikely(kiocbIsCancelled(iocb))) { 594 * don't need to copy anything to userspace, so we can
595 * complete the aio request immediately.
596 */
597 if (priv->iv == NULL || unlikely(req->actual == 0)) {
606 kfree(req->buf); 598 kfree(req->buf);
607 kfree(priv); 599 kfree(priv);
608 iocb->private = NULL; 600 iocb->private = NULL;
609 /* aio_complete() reports bytes-transferred _and_ faults */ 601 /* aio_complete() reports bytes-transferred _and_ faults */
610 if (unlikely(kiocbIsCancelled(iocb))) 602 aio_complete(iocb, req->actual ? req->actual : req->status,
611 aio_put_req(iocb);
612 else
613 aio_complete(iocb,
614 req->actual ? req->actual : req->status,
615 req->status); 603 req->status);
616 } else { 604 } else {
617 /* retry() won't report both; so we hide some faults */ 605 /* retry() won't report both; so we hide some faults */
@@ -636,7 +624,7 @@ ep_aio_rwtail(
636 size_t len, 624 size_t len,
637 struct ep_data *epdata, 625 struct ep_data *epdata,
638 const struct iovec *iv, 626 const struct iovec *iv,
639 unsigned long nr_segs 627 unsigned long nr_segs
640) 628)
641{ 629{
642 struct kiocb_priv *priv; 630 struct kiocb_priv *priv;
@@ -852,9 +840,9 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
852 break; 840 break;
853#endif 841#endif
854 default: 842 default:
855 DBG (data->dev, "unconnected, %s init deferred\n", 843 DBG(data->dev, "unconnected, %s init abandoned\n",
856 data->name); 844 data->name);
857 data->state = STATE_EP_DEFER_ENABLE; 845 value = -EINVAL;
858 } 846 }
859 if (value == 0) { 847 if (value == 0) {
860 fd->f_op = &ep_io_operations; 848 fd->f_op = &ep_io_operations;
@@ -943,22 +931,24 @@ static void clean_req (struct usb_ep *ep, struct usb_request *req)
943static void ep0_complete (struct usb_ep *ep, struct usb_request *req) 931static void ep0_complete (struct usb_ep *ep, struct usb_request *req)
944{ 932{
945 struct dev_data *dev = ep->driver_data; 933 struct dev_data *dev = ep->driver_data;
934 unsigned long flags;
946 int free = 1; 935 int free = 1;
947 936
948 /* for control OUT, data must still get to userspace */ 937 /* for control OUT, data must still get to userspace */
938 spin_lock_irqsave(&dev->lock, flags);
949 if (!dev->setup_in) { 939 if (!dev->setup_in) {
950 dev->setup_out_error = (req->status != 0); 940 dev->setup_out_error = (req->status != 0);
951 if (!dev->setup_out_error) 941 if (!dev->setup_out_error)
952 free = 0; 942 free = 0;
953 dev->setup_out_ready = 1; 943 dev->setup_out_ready = 1;
954 ep0_readable (dev); 944 ep0_readable (dev);
955 } else if (dev->state == STATE_SETUP) 945 }
956 dev->state = STATE_CONNECTED;
957 946
958 /* clean up as appropriate */ 947 /* clean up as appropriate */
959 if (free && req->buf != &dev->rbuf) 948 if (free && req->buf != &dev->rbuf)
960 clean_req (ep, req); 949 clean_req (ep, req);
961 req->complete = epio_complete; 950 req->complete = epio_complete;
951 spin_unlock_irqrestore(&dev->lock, flags);
962} 952}
963 953
964static int setup_req (struct usb_ep *ep, struct usb_request *req, u16 len) 954static int setup_req (struct usb_ep *ep, struct usb_request *req, u16 len)
@@ -998,13 +988,13 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
998 } 988 }
999 989
1000 /* control DATA stage */ 990 /* control DATA stage */
1001 if ((state = dev->state) == STATE_SETUP) { 991 if ((state = dev->state) == STATE_DEV_SETUP) {
1002 992
1003 if (dev->setup_in) { /* stall IN */ 993 if (dev->setup_in) { /* stall IN */
1004 VDEBUG(dev, "ep0in stall\n"); 994 VDEBUG(dev, "ep0in stall\n");
1005 (void) usb_ep_set_halt (dev->gadget->ep0); 995 (void) usb_ep_set_halt (dev->gadget->ep0);
1006 retval = -EL2HLT; 996 retval = -EL2HLT;
1007 dev->state = STATE_CONNECTED; 997 dev->state = STATE_DEV_CONNECTED;
1008 998
1009 } else if (len == 0) { /* ack SET_CONFIGURATION etc */ 999 } else if (len == 0) { /* ack SET_CONFIGURATION etc */
1010 struct usb_ep *ep = dev->gadget->ep0; 1000 struct usb_ep *ep = dev->gadget->ep0;
@@ -1012,7 +1002,7 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
1012 1002
1013 if ((retval = setup_req (ep, req, 0)) == 0) 1003 if ((retval = setup_req (ep, req, 0)) == 0)
1014 retval = usb_ep_queue (ep, req, GFP_ATOMIC); 1004 retval = usb_ep_queue (ep, req, GFP_ATOMIC);
1015 dev->state = STATE_CONNECTED; 1005 dev->state = STATE_DEV_CONNECTED;
1016 1006
1017 /* assume that was SET_CONFIGURATION */ 1007 /* assume that was SET_CONFIGURATION */
1018 if (dev->current_config) { 1008 if (dev->current_config) {
@@ -1040,6 +1030,13 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
1040 spin_lock_irq (&dev->lock); 1030 spin_lock_irq (&dev->lock);
1041 if (retval) 1031 if (retval)
1042 goto done; 1032 goto done;
1033
1034 if (dev->state != STATE_DEV_SETUP) {
1035 retval = -ECANCELED;
1036 goto done;
1037 }
1038 dev->state = STATE_DEV_CONNECTED;
1039
1043 if (dev->setup_out_error) 1040 if (dev->setup_out_error)
1044 retval = -EIO; 1041 retval = -EIO;
1045 else { 1042 else {
@@ -1066,39 +1063,36 @@ scan:
1066 /* return queued events right away */ 1063 /* return queued events right away */
1067 if (dev->ev_next != 0) { 1064 if (dev->ev_next != 0) {
1068 unsigned i, n; 1065 unsigned i, n;
1069 int tmp = dev->ev_next;
1070 1066
1071 len = min (len, tmp * sizeof (struct usb_gadgetfs_event));
1072 n = len / sizeof (struct usb_gadgetfs_event); 1067 n = len / sizeof (struct usb_gadgetfs_event);
1068 if (dev->ev_next < n)
1069 n = dev->ev_next;
1073 1070
1074 /* ep0 can't deliver events when STATE_SETUP */ 1071 /* ep0 i/o has special semantics during STATE_DEV_SETUP */
1075 for (i = 0; i < n; i++) { 1072 for (i = 0; i < n; i++) {
1076 if (dev->event [i].type == GADGETFS_SETUP) { 1073 if (dev->event [i].type == GADGETFS_SETUP) {
1077 len = i + 1; 1074 dev->state = STATE_DEV_SETUP;
1078 len *= sizeof (struct usb_gadgetfs_event); 1075 n = i + 1;
1079 n = 0;
1080 break; 1076 break;
1081 } 1077 }
1082 } 1078 }
1083 spin_unlock_irq (&dev->lock); 1079 spin_unlock_irq (&dev->lock);
1080 len = n * sizeof (struct usb_gadgetfs_event);
1084 if (copy_to_user (buf, &dev->event, len)) 1081 if (copy_to_user (buf, &dev->event, len))
1085 retval = -EFAULT; 1082 retval = -EFAULT;
1086 else 1083 else
1087 retval = len; 1084 retval = len;
1088 if (len > 0) { 1085 if (len > 0) {
1089 len /= sizeof (struct usb_gadgetfs_event);
1090
1091 /* NOTE this doesn't guard against broken drivers; 1086 /* NOTE this doesn't guard against broken drivers;
1092 * concurrent ep0 readers may lose events. 1087 * concurrent ep0 readers may lose events.
1093 */ 1088 */
1094 spin_lock_irq (&dev->lock); 1089 spin_lock_irq (&dev->lock);
1095 dev->ev_next -= len; 1090 if (dev->ev_next > n) {
1096 if (dev->ev_next != 0) 1091 memmove(&dev->event[0], &dev->event[n],
1097 memmove (&dev->event, &dev->event [len],
1098 sizeof (struct usb_gadgetfs_event) 1092 sizeof (struct usb_gadgetfs_event)
1099 * (tmp - len)); 1093 * (dev->ev_next - n));
1100 if (n == 0) 1094 }
1101 dev->state = STATE_SETUP; 1095 dev->ev_next -= n;
1102 spin_unlock_irq (&dev->lock); 1096 spin_unlock_irq (&dev->lock);
1103 } 1097 }
1104 return retval; 1098 return retval;
@@ -1113,8 +1107,8 @@ scan:
1113 DBG (dev, "fail %s, state %d\n", __FUNCTION__, state); 1107 DBG (dev, "fail %s, state %d\n", __FUNCTION__, state);
1114 retval = -ESRCH; 1108 retval = -ESRCH;
1115 break; 1109 break;
1116 case STATE_UNCONNECTED: 1110 case STATE_DEV_UNCONNECTED:
1117 case STATE_CONNECTED: 1111 case STATE_DEV_CONNECTED:
1118 spin_unlock_irq (&dev->lock); 1112 spin_unlock_irq (&dev->lock);
1119 DBG (dev, "%s wait\n", __FUNCTION__); 1113 DBG (dev, "%s wait\n", __FUNCTION__);
1120 1114
@@ -1141,7 +1135,7 @@ next_event (struct dev_data *dev, enum usb_gadgetfs_event_type type)
1141 switch (type) { 1135 switch (type) {
1142 /* these events purge the queue */ 1136 /* these events purge the queue */
1143 case GADGETFS_DISCONNECT: 1137 case GADGETFS_DISCONNECT:
1144 if (dev->state == STATE_SETUP) 1138 if (dev->state == STATE_DEV_SETUP)
1145 dev->setup_abort = 1; 1139 dev->setup_abort = 1;
1146 // FALL THROUGH 1140 // FALL THROUGH
1147 case GADGETFS_CONNECT: 1141 case GADGETFS_CONNECT:
@@ -1153,7 +1147,7 @@ next_event (struct dev_data *dev, enum usb_gadgetfs_event_type type)
1153 for (i = 0; i != dev->ev_next; i++) { 1147 for (i = 0; i != dev->ev_next; i++) {
1154 if (dev->event [i].type != type) 1148 if (dev->event [i].type != type)
1155 continue; 1149 continue;
1156 DBG (dev, "discard old event %d\n", type); 1150 DBG(dev, "discard old event[%d] %d\n", i, type);
1157 dev->ev_next--; 1151 dev->ev_next--;
1158 if (i == dev->ev_next) 1152 if (i == dev->ev_next)
1159 break; 1153 break;
@@ -1166,9 +1160,9 @@ next_event (struct dev_data *dev, enum usb_gadgetfs_event_type type)
1166 default: 1160 default:
1167 BUG (); 1161 BUG ();
1168 } 1162 }
1163 VDEBUG(dev, "event[%d] = %d\n", dev->ev_next, type);
1169 event = &dev->event [dev->ev_next++]; 1164 event = &dev->event [dev->ev_next++];
1170 BUG_ON (dev->ev_next > N_EVENT); 1165 BUG_ON (dev->ev_next > N_EVENT);
1171 VDEBUG (dev, "ev %d, next %d\n", type, dev->ev_next);
1172 memset (event, 0, sizeof *event); 1166 memset (event, 0, sizeof *event);
1173 event->type = type; 1167 event->type = type;
1174 return event; 1168 return event;
@@ -1188,12 +1182,13 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1188 retval = -EIDRM; 1182 retval = -EIDRM;
1189 1183
1190 /* data and/or status stage for control request */ 1184 /* data and/or status stage for control request */
1191 } else if (dev->state == STATE_SETUP) { 1185 } else if (dev->state == STATE_DEV_SETUP) {
1192 1186
1193 /* IN DATA+STATUS caller makes len <= wLength */ 1187 /* IN DATA+STATUS caller makes len <= wLength */
1194 if (dev->setup_in) { 1188 if (dev->setup_in) {
1195 retval = setup_req (dev->gadget->ep0, dev->req, len); 1189 retval = setup_req (dev->gadget->ep0, dev->req, len);
1196 if (retval == 0) { 1190 if (retval == 0) {
1191 dev->state = STATE_DEV_CONNECTED;
1197 spin_unlock_irq (&dev->lock); 1192 spin_unlock_irq (&dev->lock);
1198 if (copy_from_user (dev->req->buf, buf, len)) 1193 if (copy_from_user (dev->req->buf, buf, len))
1199 retval = -EFAULT; 1194 retval = -EFAULT;
@@ -1219,7 +1214,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1219 VDEBUG(dev, "ep0out stall\n"); 1214 VDEBUG(dev, "ep0out stall\n");
1220 (void) usb_ep_set_halt (dev->gadget->ep0); 1215 (void) usb_ep_set_halt (dev->gadget->ep0);
1221 retval = -EL2HLT; 1216 retval = -EL2HLT;
1222 dev->state = STATE_CONNECTED; 1217 dev->state = STATE_DEV_CONNECTED;
1223 } else { 1218 } else {
1224 DBG(dev, "bogus ep0out stall!\n"); 1219 DBG(dev, "bogus ep0out stall!\n");
1225 } 1220 }
@@ -1261,7 +1256,9 @@ dev_release (struct inode *inode, struct file *fd)
1261 put_dev (dev); 1256 put_dev (dev);
1262 1257
1263 /* other endpoints were all decoupled from this device */ 1258 /* other endpoints were all decoupled from this device */
1259 spin_lock_irq(&dev->lock);
1264 dev->state = STATE_DEV_DISABLED; 1260 dev->state = STATE_DEV_DISABLED;
1261 spin_unlock_irq(&dev->lock);
1265 return 0; 1262 return 0;
1266} 1263}
1267 1264
@@ -1282,7 +1279,7 @@ ep0_poll (struct file *fd, poll_table *wait)
1282 goto out; 1279 goto out;
1283 } 1280 }
1284 1281
1285 if (dev->state == STATE_SETUP) { 1282 if (dev->state == STATE_DEV_SETUP) {
1286 if (dev->setup_in || dev->setup_can_stall) 1283 if (dev->setup_in || dev->setup_can_stall)
1287 mask = POLLOUT; 1284 mask = POLLOUT;
1288 } else { 1285 } else {
@@ -1392,52 +1389,29 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1392 1389
1393 spin_lock (&dev->lock); 1390 spin_lock (&dev->lock);
1394 dev->setup_abort = 0; 1391 dev->setup_abort = 0;
1395 if (dev->state == STATE_UNCONNECTED) { 1392 if (dev->state == STATE_DEV_UNCONNECTED) {
1396 struct usb_ep *ep;
1397 struct ep_data *data;
1398
1399 dev->state = STATE_CONNECTED;
1400 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
1401
1402#ifdef CONFIG_USB_GADGET_DUALSPEED 1393#ifdef CONFIG_USB_GADGET_DUALSPEED
1403 if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == 0) { 1394 if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == 0) {
1395 spin_unlock(&dev->lock);
1404 ERROR (dev, "no high speed config??\n"); 1396 ERROR (dev, "no high speed config??\n");
1405 return -EINVAL; 1397 return -EINVAL;
1406 } 1398 }
1407#endif /* CONFIG_USB_GADGET_DUALSPEED */ 1399#endif /* CONFIG_USB_GADGET_DUALSPEED */
1408 1400
1401 dev->state = STATE_DEV_CONNECTED;
1402 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
1403
1409 INFO (dev, "connected\n"); 1404 INFO (dev, "connected\n");
1410 event = next_event (dev, GADGETFS_CONNECT); 1405 event = next_event (dev, GADGETFS_CONNECT);
1411 event->u.speed = gadget->speed; 1406 event->u.speed = gadget->speed;
1412 ep0_readable (dev); 1407 ep0_readable (dev);
1413 1408
1414 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
1415 data = ep->driver_data;
1416 /* ... down_trylock (&data->lock) ... */
1417 if (data->state != STATE_EP_DEFER_ENABLE)
1418 continue;
1419#ifdef CONFIG_USB_GADGET_DUALSPEED
1420 if (gadget->speed == USB_SPEED_HIGH)
1421 value = usb_ep_enable (ep, &data->hs_desc);
1422 else
1423#endif /* CONFIG_USB_GADGET_DUALSPEED */
1424 value = usb_ep_enable (ep, &data->desc);
1425 if (value) {
1426 ERROR (dev, "deferred %s enable --> %d\n",
1427 data->name, value);
1428 continue;
1429 }
1430 data->state = STATE_EP_ENABLED;
1431 wake_up (&data->wait);
1432 DBG (dev, "woke up %s waiters\n", data->name);
1433 }
1434
1435 /* host may have given up waiting for response. we can miss control 1409 /* host may have given up waiting for response. we can miss control
1436 * requests handled lower down (device/endpoint status and features); 1410 * requests handled lower down (device/endpoint status and features);
1437 * then ep0_{read,write} will report the wrong status. controller 1411 * then ep0_{read,write} will report the wrong status. controller
1438 * driver will have aborted pending i/o. 1412 * driver will have aborted pending i/o.
1439 */ 1413 */
1440 } else if (dev->state == STATE_SETUP) 1414 } else if (dev->state == STATE_DEV_SETUP)
1441 dev->setup_abort = 1; 1415 dev->setup_abort = 1;
1442 1416
1443 req->buf = dev->rbuf; 1417 req->buf = dev->rbuf;
@@ -1583,7 +1557,7 @@ delegate:
1583 } 1557 }
1584 1558
1585 /* proceed with data transfer and status phases? */ 1559 /* proceed with data transfer and status phases? */
1586 if (value >= 0 && dev->state != STATE_SETUP) { 1560 if (value >= 0 && dev->state != STATE_DEV_SETUP) {
1587 req->length = value; 1561 req->length = value;
1588 req->zero = value < w_length; 1562 req->zero = value < w_length;
1589 value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); 1563 value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
@@ -1747,7 +1721,9 @@ gadgetfs_bind (struct usb_gadget *gadget)
1747 goto enomem; 1721 goto enomem;
1748 1722
1749 INFO (dev, "bound to %s driver\n", gadget->name); 1723 INFO (dev, "bound to %s driver\n", gadget->name);
1750 dev->state = STATE_UNCONNECTED; 1724 spin_lock_irq(&dev->lock);
1725 dev->state = STATE_DEV_UNCONNECTED;
1726 spin_unlock_irq(&dev->lock);
1751 get_dev (dev); 1727 get_dev (dev);
1752 return 0; 1728 return 0;
1753 1729
@@ -1762,11 +1738,9 @@ gadgetfs_disconnect (struct usb_gadget *gadget)
1762 struct dev_data *dev = get_gadget_data (gadget); 1738 struct dev_data *dev = get_gadget_data (gadget);
1763 1739
1764 spin_lock (&dev->lock); 1740 spin_lock (&dev->lock);
1765 if (dev->state == STATE_UNCONNECTED) { 1741 if (dev->state == STATE_DEV_UNCONNECTED)
1766 DBG (dev, "already unconnected\n");
1767 goto exit; 1742 goto exit;
1768 } 1743 dev->state = STATE_DEV_UNCONNECTED;
1769 dev->state = STATE_UNCONNECTED;
1770 1744
1771 INFO (dev, "disconnected\n"); 1745 INFO (dev, "disconnected\n");
1772 next_event (dev, GADGETFS_DISCONNECT); 1746 next_event (dev, GADGETFS_DISCONNECT);
@@ -1783,9 +1757,9 @@ gadgetfs_suspend (struct usb_gadget *gadget)
1783 INFO (dev, "suspended from state %d\n", dev->state); 1757 INFO (dev, "suspended from state %d\n", dev->state);
1784 spin_lock (&dev->lock); 1758 spin_lock (&dev->lock);
1785 switch (dev->state) { 1759 switch (dev->state) {
1786 case STATE_SETUP: // VERY odd... host died?? 1760 case STATE_DEV_SETUP: // VERY odd... host died??
1787 case STATE_CONNECTED: 1761 case STATE_DEV_CONNECTED:
1788 case STATE_UNCONNECTED: 1762 case STATE_DEV_UNCONNECTED:
1789 next_event (dev, GADGETFS_SUSPEND); 1763 next_event (dev, GADGETFS_SUSPEND);
1790 ep0_readable (dev); 1764 ep0_readable (dev);
1791 /* FALLTHROUGH */ 1765 /* FALLTHROUGH */
@@ -1808,7 +1782,7 @@ static struct usb_gadget_driver gadgetfs_driver = {
1808 .disconnect = gadgetfs_disconnect, 1782 .disconnect = gadgetfs_disconnect,
1809 .suspend = gadgetfs_suspend, 1783 .suspend = gadgetfs_suspend,
1810 1784
1811 .driver = { 1785 .driver = {
1812 .name = (char *) shortname, 1786 .name = (char *) shortname,
1813 }, 1787 },
1814}; 1788};
@@ -1829,7 +1803,7 @@ static struct usb_gadget_driver probe_driver = {
1829 .unbind = gadgetfs_nop, 1803 .unbind = gadgetfs_nop,
1830 .setup = (void *)gadgetfs_nop, 1804 .setup = (void *)gadgetfs_nop,
1831 .disconnect = gadgetfs_nop, 1805 .disconnect = gadgetfs_nop,
1832 .driver = { 1806 .driver = {
1833 .name = "nop", 1807 .name = "nop",
1834 }, 1808 },
1835}; 1809};
@@ -1849,19 +1823,16 @@ static struct usb_gadget_driver probe_driver = {
1849 * . full/low speed config ... all wTotalLength bytes (with interface, 1823 * . full/low speed config ... all wTotalLength bytes (with interface,
1850 * class, altsetting, endpoint, and other descriptors) 1824 * class, altsetting, endpoint, and other descriptors)
1851 * . high speed config ... all descriptors, for high speed operation; 1825 * . high speed config ... all descriptors, for high speed operation;
1852 * this one's optional except for high-speed hardware 1826 * this one's optional except for high-speed hardware
1853 * . device descriptor 1827 * . device descriptor
1854 * 1828 *
1855 * Endpoints are not yet enabled. Drivers may want to immediately 1829 * Endpoints are not yet enabled. Drivers must wait until device
1856 * initialize them, using the /dev/gadget/ep* files that are available 1830 * configuration and interface altsetting changes create
1857 * as soon as the kernel sees the configuration, or they can wait
1858 * until device configuration and interface altsetting changes create
1859 * the need to configure (or unconfigure) them. 1831 * the need to configure (or unconfigure) them.
1860 * 1832 *
1861 * After initialization, the device stays active for as long as that 1833 * After initialization, the device stays active for as long as that
1862 * $CHIP file is open. Events may then be read from that descriptor, 1834 * $CHIP file is open. Events must then be read from that descriptor,
1863 * such as configuration notifications. More complex drivers will handle 1835 * such as configuration notifications.
1864 * some control requests in user space.
1865 */ 1836 */
1866 1837
1867static int is_valid_config (struct usb_config_descriptor *config) 1838static int is_valid_config (struct usb_config_descriptor *config)
@@ -1884,9 +1855,6 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1884 u32 tag; 1855 u32 tag;
1885 char *kbuf; 1856 char *kbuf;
1886 1857
1887 if (dev->state != STATE_OPENED)
1888 return -EEXIST;
1889
1890 if (len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4)) 1858 if (len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4))
1891 return -EINVAL; 1859 return -EINVAL;
1892 1860
@@ -1978,13 +1946,15 @@ dev_open (struct inode *inode, struct file *fd)
1978 struct dev_data *dev = inode->i_private; 1946 struct dev_data *dev = inode->i_private;
1979 int value = -EBUSY; 1947 int value = -EBUSY;
1980 1948
1949 spin_lock_irq(&dev->lock);
1981 if (dev->state == STATE_DEV_DISABLED) { 1950 if (dev->state == STATE_DEV_DISABLED) {
1982 dev->ev_next = 0; 1951 dev->ev_next = 0;
1983 dev->state = STATE_OPENED; 1952 dev->state = STATE_DEV_OPENED;
1984 fd->private_data = dev; 1953 fd->private_data = dev;
1985 get_dev (dev); 1954 get_dev (dev);
1986 value = 0; 1955 value = 0;
1987 } 1956 }
1957 spin_unlock_irq(&dev->lock);
1988 return value; 1958 return value;
1989} 1959}
1990 1960
diff --git a/drivers/usb/gadget/lh7a40x_udc.h b/drivers/usb/gadget/lh7a40x_udc.h
index e3bb78524c88..b3fe197e1eeb 100644
--- a/drivers/usb/gadget/lh7a40x_udc.h
+++ b/drivers/usb/gadget/lh7a40x_udc.h
@@ -49,7 +49,7 @@
49#include <asm/unaligned.h> 49#include <asm/unaligned.h>
50#include <asm/hardware.h> 50#include <asm/hardware.h>
51 51
52#include <linux/usb_ch9.h> 52#include <linux/usb/ch9.h>
53#include <linux/usb_gadget.h> 53#include <linux/usb_gadget.h>
54 54
55/* 55/*
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 569eb8ccf232..49d737725f70 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -53,7 +53,6 @@
53#include <linux/kernel.h> 53#include <linux/kernel.h>
54#include <linux/delay.h> 54#include <linux/delay.h>
55#include <linux/ioport.h> 55#include <linux/ioport.h>
56#include <linux/sched.h>
57#include <linux/slab.h> 56#include <linux/slab.h>
58#include <linux/smp_lock.h> 57#include <linux/smp_lock.h>
59#include <linux/errno.h> 58#include <linux/errno.h>
@@ -63,7 +62,7 @@
63#include <linux/interrupt.h> 62#include <linux/interrupt.h>
64#include <linux/moduleparam.h> 63#include <linux/moduleparam.h>
65#include <linux/device.h> 64#include <linux/device.h>
66#include <linux/usb_ch9.h> 65#include <linux/usb/ch9.h>
67#include <linux/usb_gadget.h> 66#include <linux/usb_gadget.h>
68 67
69#include <asm/byteorder.h> 68#include <asm/byteorder.h>
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index cdcfd42843d4..8f9a2b615422 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -28,7 +28,6 @@
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/errno.h> 29#include <linux/errno.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/sched.h>
32#include <linux/slab.h> 31#include <linux/slab.h>
33#include <linux/init.h> 32#include <linux/init.h>
34#include <linux/timer.h> 33#include <linux/timer.h>
@@ -38,7 +37,7 @@
38#include <linux/mm.h> 37#include <linux/mm.h>
39#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
40#include <linux/platform_device.h> 39#include <linux/platform_device.h>
41#include <linux/usb_ch9.h> 40#include <linux/usb/ch9.h>
42#include <linux/usb_gadget.h> 41#include <linux/usb_gadget.h>
43#include <linux/usb/otg.h> 42#include <linux/usb/otg.h>
44#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 3547f049237e..f01890dc8751 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -33,7 +33,6 @@
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/sched.h>
37#include <linux/slab.h> 36#include <linux/slab.h>
38#include <linux/init.h> 37#include <linux/init.h>
39#include <linux/timer.h> 38#include <linux/timer.h>
@@ -56,7 +55,7 @@
56#include <asm/arch/pxa-regs.h> 55#include <asm/arch/pxa-regs.h>
57#endif 56#endif
58 57
59#include <linux/usb_ch9.h> 58#include <linux/usb/ch9.h>
60#include <linux/usb_gadget.h> 59#include <linux/usb_gadget.h>
61 60
62#include <asm/arch/udc.h> 61#include <asm/arch/udc.h>
@@ -2612,7 +2611,7 @@ lubbock_fail0:
2612#endif 2611#endif
2613 if (vbus_irq) { 2612 if (vbus_irq) {
2614 retval = request_irq(vbus_irq, udc_vbus_irq, 2613 retval = request_irq(vbus_irq, udc_vbus_irq,
2615 SA_INTERRUPT | SA_SAMPLE_RANDOM, 2614 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
2616 driver_name, dev); 2615 driver_name, dev);
2617 if (retval != 0) { 2616 if (retval != 0) {
2618 printk(KERN_ERR "%s: can't get irq %i, err %d\n", 2617 printk(KERN_ERR "%s: can't get irq %i, err %d\n",
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 408c3380d602..6ec8cf1a3ccb 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1419,7 +1419,6 @@ int __devinit rndis_init (void)
1419 return -EIO; 1419 return -EIO;
1420 } 1420 }
1421 1421
1422 rndis_connect_state [i]->nlink = 1;
1423 rndis_connect_state [i]->write_proc = rndis_proc_write; 1422 rndis_connect_state [i]->write_proc = rndis_proc_write;
1424 rndis_connect_state [i]->read_proc = rndis_proc_read; 1423 rndis_connect_state [i]->read_proc = rndis_proc_read;
1425 rndis_connect_state [i]->data = (void *) 1424 rndis_connect_state [i]->data = (void *)
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index f8a3ec64635d..e552668d36b3 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -21,7 +21,6 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/ioport.h> 23#include <linux/ioport.h>
24#include <linux/sched.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
26#include <linux/smp_lock.h> 25#include <linux/smp_lock.h>
27#include <linux/errno.h> 26#include <linux/errno.h>
@@ -43,7 +42,7 @@
43#include <asm/unaligned.h> 42#include <asm/unaligned.h>
44#include <asm/uaccess.h> 43#include <asm/uaccess.h>
45 44
46#include <linux/usb_ch9.h> 45#include <linux/usb/ch9.h>
47#include <linux/usb/cdc.h> 46#include <linux/usb/cdc.h>
48#include <linux/usb_gadget.h> 47#include <linux/usb_gadget.h>
49 48
@@ -1700,6 +1699,7 @@ static int gs_setup_class(struct usb_gadget *gadget,
1700 memcpy(&port->port_line_coding, req->buf, ret); 1699 memcpy(&port->port_line_coding, req->buf, ret);
1701 spin_unlock(&port->port_lock); 1700 spin_unlock(&port->port_lock);
1702 } 1701 }
1702 ret = 0;
1703 break; 1703 break;
1704 1704
1705 case USB_CDC_REQ_GET_LINE_CODING: 1705 case USB_CDC_REQ_GET_LINE_CODING:
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c
index b1735767660b..3459ea6c6c0b 100644
--- a/drivers/usb/gadget/usbstring.c
+++ b/drivers/usb/gadget/usbstring.c
@@ -14,7 +14,7 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/init.h> 15#include <linux/init.h>
16 16
17#include <linux/usb_ch9.h> 17#include <linux/usb/ch9.h>
18#include <linux/usb_gadget.h> 18#include <linux/usb_gadget.h>
19 19
20#include <asm/unaligned.h> 20#include <asm/unaligned.h>
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 40710ea1b490..8c85e33f74a4 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -66,7 +66,6 @@
66#include <linux/kernel.h> 66#include <linux/kernel.h>
67#include <linux/delay.h> 67#include <linux/delay.h>
68#include <linux/ioport.h> 68#include <linux/ioport.h>
69#include <linux/sched.h>
70#include <linux/slab.h> 69#include <linux/slab.h>
71#include <linux/smp_lock.h> 70#include <linux/smp_lock.h>
72#include <linux/errno.h> 71#include <linux/errno.h>
@@ -84,7 +83,7 @@
84#include <asm/system.h> 83#include <asm/system.h>
85#include <asm/unaligned.h> 84#include <asm/unaligned.h>
86 85
87#include <linux/usb_ch9.h> 86#include <linux/usb/ch9.h>
88#include <linux/usb_gadget.h> 87#include <linux/usb_gadget.h>
89 88
90#include "gadget_chips.h" 89#include "gadget_chips.h"