diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-20 19:13:02 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-20 19:13:02 -0500 |
commit | ec513b16c480c6cdda1e3d597e611eafca05227b (patch) | |
tree | ba8855093dbf4ca15f864947d947d65fdfa2a76d /drivers/usb/gadget | |
parent | bcee63488ece9a0fca8be19951428a7b41001e66 (diff) | |
parent | 2fc5a7dace3c43e62402ab4e8800a8f1834ffe2a (diff) |
Merge tag 'usb-3.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB updates from Greg KH:
"Here's the big USB pull request for 3.14-rc1
Lots of little things all over the place, and the usual USB gadget
updates, and XHCI fixes (some for an issue reported by a lot of
people). USB PHY updates as well as chipidea updates and fixes.
All of these have been in the linux-next tree with no reported issues"
* tag 'usb-3.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (318 commits)
usb: chipidea: udc: using MultO at TD as real mult value for ISO-TX
usb: chipidea: need to mask INT_STATUS when write otgsc
usb: chipidea: put hw_phymode_configure before ci_usb_phy_init
usb: chipidea: Fix Internal error: : 808 [#1] ARM related to STS flag
usb: chipidea: imx: set CI_HDRC_IMX28_WRITE_FIX for imx28
usb: chipidea: add freescale imx28 special write register method
usb: ehci: add freescale imx28 special write register method
usb: core: check for valid id_table when using the RefId feature
usb: cdc-wdm: resp_count can be 0 even if WDM_READ is set
usb: core: bail out if user gives an unknown RefId when using new_id
usb: core: allow a reference device for new_id
usb: core: add sanity checks when using bInterfaceClass with new_id
USB: image: correct spelling mistake in comment
USB: c67x00: correct spelling mistakes in comments
usb: delete non-required instances of include <linux/init.h>
usb:hub set hub->change_bits when over-current happens
Revert "usb: chipidea: imx: set CI_HDRC_IMX28_WRITE_FIX for imx28"
xhci: Set scatter-gather limit to avoid failed block writes.
xhci: Avoid infinite loop when sg urb requires too many trbs
usb: gadget: remove unused variable in gr_queue_int()
...
Diffstat (limited to 'drivers/usb/gadget')
58 files changed, 4451 insertions, 1064 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index f66d96ad1f51..8154165aa601 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -216,6 +216,13 @@ config USB_FOTG210_UDC | |||
216 | Say "y" to link the driver statically, or "m" to build a | 216 | Say "y" to link the driver statically, or "m" to build a |
217 | dynamically linked module called "fotg210_udc". | 217 | dynamically linked module called "fotg210_udc". |
218 | 218 | ||
219 | config USB_GR_UDC | ||
220 | tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver" | ||
221 | depends on HAS_DMA | ||
222 | help | ||
223 | Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB | ||
224 | VHDL IP core library. | ||
225 | |||
219 | config USB_OMAP | 226 | config USB_OMAP |
220 | tristate "OMAP USB Device Controller" | 227 | tristate "OMAP USB Device Controller" |
221 | depends on ARCH_OMAP1 | 228 | depends on ARCH_OMAP1 |
@@ -294,11 +301,11 @@ config USB_PXA27X | |||
294 | gadget drivers to also be dynamically linked. | 301 | gadget drivers to also be dynamically linked. |
295 | 302 | ||
296 | config USB_S3C_HSOTG | 303 | config USB_S3C_HSOTG |
297 | tristate "S3C HS/OtG USB Device controller" | 304 | depends on ARM |
298 | depends on S3C_DEV_USB_HSOTG | 305 | tristate "Designware/S3C HS/OtG USB Device controller" |
299 | help | 306 | help |
300 | The Samsung S3C64XX USB2.0 high-speed gadget controller | 307 | The Designware USB2.0 high-speed gadget controller |
301 | integrated into the S3C64XX series SoC. | 308 | integrated into many SoCs. |
302 | 309 | ||
303 | config USB_S3C2410 | 310 | config USB_S3C2410 |
304 | tristate "S3C2410 USB Device Controller" | 311 | tristate "S3C2410 USB Device Controller" |
@@ -512,9 +519,6 @@ config USB_U_SERIAL | |||
512 | config USB_U_ETHER | 519 | config USB_U_ETHER |
513 | tristate | 520 | tristate |
514 | 521 | ||
515 | config USB_U_RNDIS | ||
516 | tristate | ||
517 | |||
518 | config USB_F_SERIAL | 522 | config USB_F_SERIAL |
519 | tristate | 523 | tristate |
520 | 524 | ||
@@ -542,6 +546,9 @@ config USB_F_RNDIS | |||
542 | config USB_F_MASS_STORAGE | 546 | config USB_F_MASS_STORAGE |
543 | tristate | 547 | tristate |
544 | 548 | ||
549 | config USB_F_FS | ||
550 | tristate | ||
551 | |||
545 | choice | 552 | choice |
546 | tristate "USB Gadget Drivers" | 553 | tristate "USB Gadget Drivers" |
547 | default USB_ETH | 554 | default USB_ETH |
@@ -642,7 +649,6 @@ config USB_CONFIGFS_RNDIS | |||
642 | depends on USB_CONFIGFS | 649 | depends on USB_CONFIGFS |
643 | depends on NET | 650 | depends on NET |
644 | select USB_U_ETHER | 651 | select USB_U_ETHER |
645 | select USB_U_RNDIS | ||
646 | select USB_F_RNDIS | 652 | select USB_F_RNDIS |
647 | help | 653 | help |
648 | Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, | 654 | Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol, |
@@ -690,6 +696,31 @@ config USB_CONFIGFS_MASS_STORAGE | |||
690 | device (in much the same way as the "loop" device driver), | 696 | device (in much the same way as the "loop" device driver), |
691 | specified as a module parameter or sysfs option. | 697 | specified as a module parameter or sysfs option. |
692 | 698 | ||
699 | config USB_CONFIGFS_F_LB_SS | ||
700 | boolean "Loopback and sourcesink function (for testing)" | ||
701 | depends on USB_CONFIGFS | ||
702 | select USB_F_SS_LB | ||
703 | help | ||
704 | Loopback function loops back a configurable number of transfers. | ||
705 | Sourcesink function either sinks and sources bulk data. | ||
706 | It also implements control requests, for "chapter 9" conformance. | ||
707 | Make this be the first driver you try using on top of any new | ||
708 | USB peripheral controller driver. Then you can use host-side | ||
709 | test software, like the "usbtest" driver, to put your hardware | ||
710 | and its driver through a basic set of functional tests. | ||
711 | |||
712 | config USB_CONFIGFS_F_FS | ||
713 | boolean "Function filesystem (FunctionFS)" | ||
714 | depends on USB_CONFIGFS | ||
715 | select USB_F_FS | ||
716 | help | ||
717 | The Function Filesystem (FunctionFS) lets one create USB | ||
718 | composite functions in user space in the same way GadgetFS | ||
719 | lets one create USB gadgets in user space. This allows creation | ||
720 | of composite gadgets such that some of the functions are | ||
721 | implemented in kernel space (for instance Ethernet, serial or | ||
722 | mass storage) and other are implemented in user space. | ||
723 | |||
693 | config USB_ZERO | 724 | config USB_ZERO |
694 | tristate "Gadget Zero (DEVELOPMENT)" | 725 | tristate "Gadget Zero (DEVELOPMENT)" |
695 | select USB_LIBCOMPOSITE | 726 | select USB_LIBCOMPOSITE |
@@ -760,7 +791,6 @@ config USB_ETH | |||
760 | depends on NET | 791 | depends on NET |
761 | select USB_LIBCOMPOSITE | 792 | select USB_LIBCOMPOSITE |
762 | select USB_U_ETHER | 793 | select USB_U_ETHER |
763 | select USB_U_RNDIS | ||
764 | select USB_F_ECM | 794 | select USB_F_ECM |
765 | select USB_F_SUBSET | 795 | select USB_F_SUBSET |
766 | select CRC32 | 796 | select CRC32 |
@@ -864,6 +894,7 @@ config USB_GADGETFS | |||
864 | config USB_FUNCTIONFS | 894 | config USB_FUNCTIONFS |
865 | tristate "Function Filesystem" | 895 | tristate "Function Filesystem" |
866 | select USB_LIBCOMPOSITE | 896 | select USB_LIBCOMPOSITE |
897 | select USB_F_FS | ||
867 | select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) | 898 | select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) |
868 | help | 899 | help |
869 | The Function Filesystem (FunctionFS) lets one create USB | 900 | The Function Filesystem (FunctionFS) lets one create USB |
@@ -883,6 +914,8 @@ config USB_FUNCTIONFS_ETH | |||
883 | bool "Include configuration with CDC ECM (Ethernet)" | 914 | bool "Include configuration with CDC ECM (Ethernet)" |
884 | depends on USB_FUNCTIONFS && NET | 915 | depends on USB_FUNCTIONFS && NET |
885 | select USB_U_ETHER | 916 | select USB_U_ETHER |
917 | select USB_F_ECM | ||
918 | select USB_F_SUBSET | ||
886 | help | 919 | help |
887 | Include a configuration with CDC ECM function (Ethernet) and the | 920 | Include a configuration with CDC ECM function (Ethernet) and the |
888 | Function Filesystem. | 921 | Function Filesystem. |
@@ -891,7 +924,7 @@ config USB_FUNCTIONFS_RNDIS | |||
891 | bool "Include configuration with RNDIS (Ethernet)" | 924 | bool "Include configuration with RNDIS (Ethernet)" |
892 | depends on USB_FUNCTIONFS && NET | 925 | depends on USB_FUNCTIONFS && NET |
893 | select USB_U_ETHER | 926 | select USB_U_ETHER |
894 | select USB_U_RNDIS | 927 | select USB_F_RNDIS |
895 | help | 928 | help |
896 | Include a configuration with RNDIS function (Ethernet) and the Filesystem. | 929 | Include a configuration with RNDIS function (Ethernet) and the Filesystem. |
897 | 930 | ||
@@ -1065,7 +1098,6 @@ config USB_G_MULTI | |||
1065 | config USB_G_MULTI_RNDIS | 1098 | config USB_G_MULTI_RNDIS |
1066 | bool "RNDIS + CDC Serial + Storage configuration" | 1099 | bool "RNDIS + CDC Serial + Storage configuration" |
1067 | depends on USB_G_MULTI | 1100 | depends on USB_G_MULTI |
1068 | select USB_U_RNDIS | ||
1069 | select USB_F_RNDIS | 1101 | select USB_F_RNDIS |
1070 | default y | 1102 | default y |
1071 | help | 1103 | help |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index f1af39603d4d..5f150bc1b4bc 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -7,7 +7,7 @@ ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG | |||
7 | obj-$(CONFIG_USB_GADGET) += udc-core.o | 7 | obj-$(CONFIG_USB_GADGET) += udc-core.o |
8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o | 8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o |
9 | libcomposite-y := usbstring.o config.o epautoconf.o | 9 | libcomposite-y := usbstring.o config.o epautoconf.o |
10 | libcomposite-y += composite.o functions.o configfs.o | 10 | libcomposite-y += composite.o functions.o configfs.o u_f.o |
11 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o | 11 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o |
12 | obj-$(CONFIG_USB_NET2272) += net2272.o | 12 | obj-$(CONFIG_USB_NET2272) += net2272.o |
13 | obj-$(CONFIG_USB_NET2280) += net2280.o | 13 | obj-$(CONFIG_USB_NET2280) += net2280.o |
@@ -35,6 +35,7 @@ mv_udc-y := mv_udc_core.o | |||
35 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | 35 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o |
36 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o | 36 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o |
37 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o | 37 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o |
38 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o | ||
38 | 39 | ||
39 | # USB Functions | 40 | # USB Functions |
40 | usb_f_acm-y := f_acm.o | 41 | usb_f_acm-y := f_acm.o |
@@ -47,8 +48,6 @@ obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o | |||
47 | usb_f_obex-y := f_obex.o | 48 | usb_f_obex-y := f_obex.o |
48 | obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o | 49 | obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o |
49 | obj-$(CONFIG_USB_U_ETHER) += u_ether.o | 50 | obj-$(CONFIG_USB_U_ETHER) += u_ether.o |
50 | u_rndis-y := rndis.o | ||
51 | obj-$(CONFIG_USB_U_RNDIS) += u_rndis.o | ||
52 | usb_f_ncm-y := f_ncm.o | 51 | usb_f_ncm-y := f_ncm.o |
53 | obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o | 52 | obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o |
54 | usb_f_ecm-y := f_ecm.o | 53 | usb_f_ecm-y := f_ecm.o |
@@ -59,10 +58,12 @@ usb_f_eem-y := f_eem.o | |||
59 | obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o | 58 | obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o |
60 | usb_f_ecm_subset-y := f_subset.o | 59 | usb_f_ecm_subset-y := f_subset.o |
61 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o | 60 | obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o |
62 | usb_f_rndis-y := f_rndis.o | 61 | usb_f_rndis-y := f_rndis.o rndis.o |
63 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o | 62 | obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o |
64 | usb_f_mass_storage-y := f_mass_storage.o storage_common.o | 63 | usb_f_mass_storage-y := f_mass_storage.o storage_common.o |
65 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o | 64 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o |
65 | usb_f_fs-y := f_fs.o | ||
66 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o | ||
66 | 67 | ||
67 | # | 68 | # |
68 | # USB gadget drivers | 69 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c index 7bfa134fe0e3..a252444cc0a7 100644 --- a/drivers/usb/gadget/acm_ms.c +++ b/drivers/usb/gadget/acm_ms.c | |||
@@ -107,7 +107,7 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | |||
107 | */ | 107 | */ |
108 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | 108 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS |
109 | 109 | ||
110 | #endif /* CONFIG_USB_DEBUG */ | 110 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
111 | 111 | ||
112 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | 112 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); |
113 | 113 | ||
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 54a1e2954cea..41b062eb4de0 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -40,7 +40,6 @@ | |||
40 | #include <linux/sched.h> | 40 | #include <linux/sched.h> |
41 | #include <linux/slab.h> | 41 | #include <linux/slab.h> |
42 | #include <linux/errno.h> | 42 | #include <linux/errno.h> |
43 | #include <linux/init.h> | ||
44 | #include <linux/timer.h> | 43 | #include <linux/timer.h> |
45 | #include <linux/list.h> | 44 | #include <linux/list.h> |
46 | #include <linux/interrupt.h> | 45 | #include <linux/interrupt.h> |
@@ -446,7 +445,7 @@ static void ep_init(struct udc_regs __iomem *regs, struct udc_ep *ep) | |||
446 | ep->ep.ops = &udc_ep_ops; | 445 | ep->ep.ops = &udc_ep_ops; |
447 | INIT_LIST_HEAD(&ep->queue); | 446 | INIT_LIST_HEAD(&ep->queue); |
448 | 447 | ||
449 | ep->ep.maxpacket = (u16) ~0; | 448 | usb_ep_set_maxpacket_limit(&ep->ep,(u16) ~0); |
450 | /* set NAK */ | 449 | /* set NAK */ |
451 | tmp = readl(&ep->regs->ctl); | 450 | tmp = readl(&ep->regs->ctl); |
452 | tmp |= AMD_BIT(UDC_EPCTL_SNAK); | 451 | tmp |= AMD_BIT(UDC_EPCTL_SNAK); |
@@ -1564,12 +1563,15 @@ static void udc_setup_endpoints(struct udc *dev) | |||
1564 | } | 1563 | } |
1565 | /* EP0 max packet */ | 1564 | /* EP0 max packet */ |
1566 | if (dev->gadget.speed == USB_SPEED_FULL) { | 1565 | if (dev->gadget.speed == USB_SPEED_FULL) { |
1567 | dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_FS_EP0IN_MAX_PKT_SIZE; | 1566 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IX].ep, |
1568 | dev->ep[UDC_EP0OUT_IX].ep.maxpacket = | 1567 | UDC_FS_EP0IN_MAX_PKT_SIZE); |
1569 | UDC_FS_EP0OUT_MAX_PKT_SIZE; | 1568 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IX].ep, |
1569 | UDC_FS_EP0OUT_MAX_PKT_SIZE); | ||
1570 | } else if (dev->gadget.speed == USB_SPEED_HIGH) { | 1570 | } else if (dev->gadget.speed == USB_SPEED_HIGH) { |
1571 | dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE; | 1571 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IX].ep, |
1572 | dev->ep[UDC_EP0OUT_IX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE; | 1572 | UDC_EP0IN_MAX_PKT_SIZE); |
1573 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IX].ep, | ||
1574 | UDC_EP0OUT_MAX_PKT_SIZE); | ||
1573 | } | 1575 | } |
1574 | 1576 | ||
1575 | /* | 1577 | /* |
@@ -3338,7 +3340,7 @@ static int udc_remote_wakeup(struct udc *dev) | |||
3338 | } | 3340 | } |
3339 | 3341 | ||
3340 | /* PCI device parameters */ | 3342 | /* PCI device parameters */ |
3341 | static DEFINE_PCI_DEVICE_TABLE(pci_id) = { | 3343 | static const struct pci_device_id pci_id[] = { |
3342 | { | 3344 | { |
3343 | PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096), | 3345 | PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096), |
3344 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, | 3346 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 4cc4fd6d1473..cea8c20a1425 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/ioport.h> | 21 | #include <linux/ioport.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | #include <linux/errno.h> | 23 | #include <linux/errno.h> |
24 | #include <linux/init.h> | ||
25 | #include <linux/list.h> | 24 | #include <linux/list.h> |
26 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
27 | #include <linux/proc_fs.h> | 26 | #include <linux/proc_fs.h> |
@@ -834,7 +833,7 @@ static void udc_reinit(struct at91_udc *udc) | |||
834 | ep->ep.desc = NULL; | 833 | ep->ep.desc = NULL; |
835 | ep->stopped = 0; | 834 | ep->stopped = 0; |
836 | ep->fifo_bank = 0; | 835 | ep->fifo_bank = 0; |
837 | ep->ep.maxpacket = ep->maxpacket; | 836 | usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); |
838 | ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); | 837 | ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i); |
839 | /* initialize one queue per endpoint */ | 838 | /* initialize one queue per endpoint */ |
840 | INIT_LIST_HEAD(&ep->queue); | 839 | INIT_LIST_HEAD(&ep->queue); |
@@ -1759,15 +1758,15 @@ static int at91udc_probe(struct platform_device *pdev) | |||
1759 | 1758 | ||
1760 | /* newer chips have more FIFO memory than rm9200 */ | 1759 | /* newer chips have more FIFO memory than rm9200 */ |
1761 | if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) { | 1760 | if (cpu_is_at91sam9260() || cpu_is_at91sam9g20()) { |
1762 | udc->ep[0].maxpacket = 64; | 1761 | usb_ep_set_maxpacket_limit(&udc->ep[0].ep, 64); |
1763 | udc->ep[3].maxpacket = 64; | 1762 | usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); |
1764 | udc->ep[4].maxpacket = 512; | 1763 | usb_ep_set_maxpacket_limit(&udc->ep[4].ep, 512); |
1765 | udc->ep[5].maxpacket = 512; | 1764 | usb_ep_set_maxpacket_limit(&udc->ep[5].ep, 512); |
1766 | } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { | 1765 | } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) { |
1767 | udc->ep[3].maxpacket = 64; | 1766 | usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); |
1768 | } else if (cpu_is_at91sam9263()) { | 1767 | } else if (cpu_is_at91sam9263()) { |
1769 | udc->ep[0].maxpacket = 64; | 1768 | usb_ep_set_maxpacket_limit(&udc->ep[0].ep, 64); |
1770 | udc->ep[3].maxpacket = 64; | 1769 | usb_ep_set_maxpacket_limit(&udc->ep[3].ep, 64); |
1771 | } | 1770 | } |
1772 | 1771 | ||
1773 | udc->udp_baseaddr = ioremap(res->start, resource_size(res)); | 1772 | udc->udp_baseaddr = ioremap(res->start, resource_size(res)); |
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 2cb52e0438df..38bf67b1a97d 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -1012,7 +1012,7 @@ static void nop_release(struct device *dev) | |||
1012 | 1012 | ||
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | struct usb_gadget usba_gadget_template = { | 1015 | static struct usb_gadget usba_gadget_template = { |
1016 | .ops = &usba_udc_ops, | 1016 | .ops = &usba_udc_ops, |
1017 | .max_speed = USB_SPEED_HIGH, | 1017 | .max_speed = USB_SPEED_HIGH, |
1018 | .name = "atmel_usba_udc", | 1018 | .name = "atmel_usba_udc", |
@@ -1904,7 +1904,7 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, | |||
1904 | ep->dma_regs = udc->regs + USBA_DMA_BASE(i); | 1904 | ep->dma_regs = udc->regs + USBA_DMA_BASE(i); |
1905 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); | 1905 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); |
1906 | ep->ep.ops = &usba_ep_ops; | 1906 | ep->ep.ops = &usba_ep_ops; |
1907 | ep->ep.maxpacket = ep->fifo_size; | 1907 | usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); |
1908 | ep->udc = udc; | 1908 | ep->udc = udc; |
1909 | INIT_LIST_HEAD(&ep->queue); | 1909 | INIT_LIST_HEAD(&ep->queue); |
1910 | 1910 | ||
@@ -1957,7 +1957,8 @@ static struct usba_ep * usba_udc_pdata(struct platform_device *pdev, | |||
1957 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); | 1957 | ep->fifo = udc->fifo + USBA_FIFO_BASE(i); |
1958 | ep->ep.ops = &usba_ep_ops; | 1958 | ep->ep.ops = &usba_ep_ops; |
1959 | ep->ep.name = pdata->ep[i].name; | 1959 | ep->ep.name = pdata->ep[i].name; |
1960 | ep->fifo_size = ep->ep.maxpacket = pdata->ep[i].fifo_size; | 1960 | ep->fifo_size = pdata->ep[i].fifo_size; |
1961 | usb_ep_set_maxpacket_limit(&ep->ep, ep->fifo_size); | ||
1961 | ep->udc = udc; | 1962 | ep->udc = udc; |
1962 | INIT_LIST_HEAD(&ep->queue); | 1963 | INIT_LIST_HEAD(&ep->queue); |
1963 | ep->nr_banks = pdata->ep[i].nr_banks; | 1964 | ep->nr_banks = pdata->ep[i].nr_banks; |
@@ -1995,14 +1996,12 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
1995 | if (irq < 0) | 1996 | if (irq < 0) |
1996 | return irq; | 1997 | return irq; |
1997 | 1998 | ||
1998 | pclk = clk_get(&pdev->dev, "pclk"); | 1999 | pclk = devm_clk_get(&pdev->dev, "pclk"); |
1999 | if (IS_ERR(pclk)) | 2000 | if (IS_ERR(pclk)) |
2000 | return PTR_ERR(pclk); | 2001 | return PTR_ERR(pclk); |
2001 | hclk = clk_get(&pdev->dev, "hclk"); | 2002 | hclk = devm_clk_get(&pdev->dev, "hclk"); |
2002 | if (IS_ERR(hclk)) { | 2003 | if (IS_ERR(hclk)) |
2003 | ret = PTR_ERR(hclk); | 2004 | return PTR_ERR(hclk); |
2004 | goto err_get_hclk; | ||
2005 | } | ||
2006 | 2005 | ||
2007 | spin_lock_init(&udc->lock); | 2006 | spin_lock_init(&udc->lock); |
2008 | udc->pdev = pdev; | 2007 | udc->pdev = pdev; |
@@ -2011,17 +2010,17 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2011 | udc->vbus_pin = -ENODEV; | 2010 | udc->vbus_pin = -ENODEV; |
2012 | 2011 | ||
2013 | ret = -ENOMEM; | 2012 | ret = -ENOMEM; |
2014 | udc->regs = ioremap(regs->start, resource_size(regs)); | 2013 | udc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); |
2015 | if (!udc->regs) { | 2014 | if (!udc->regs) { |
2016 | dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n"); | 2015 | dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n"); |
2017 | goto err_map_regs; | 2016 | return ret; |
2018 | } | 2017 | } |
2019 | dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n", | 2018 | dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n", |
2020 | (unsigned long)regs->start, udc->regs); | 2019 | (unsigned long)regs->start, udc->regs); |
2021 | udc->fifo = ioremap(fifo->start, resource_size(fifo)); | 2020 | udc->fifo = devm_ioremap(&pdev->dev, fifo->start, resource_size(fifo)); |
2022 | if (!udc->fifo) { | 2021 | if (!udc->fifo) { |
2023 | dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n"); | 2022 | dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n"); |
2024 | goto err_map_fifo; | 2023 | return ret; |
2025 | } | 2024 | } |
2026 | dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", | 2025 | dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", |
2027 | (unsigned long)fifo->start, udc->fifo); | 2026 | (unsigned long)fifo->start, udc->fifo); |
@@ -2032,7 +2031,7 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2032 | ret = clk_prepare_enable(pclk); | 2031 | ret = clk_prepare_enable(pclk); |
2033 | if (ret) { | 2032 | if (ret) { |
2034 | dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n"); | 2033 | dev_err(&pdev->dev, "Unable to enable pclk, aborting.\n"); |
2035 | goto err_clk_enable; | 2034 | return ret; |
2036 | } | 2035 | } |
2037 | toggle_bias(0); | 2036 | toggle_bias(0); |
2038 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | 2037 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); |
@@ -2043,22 +2042,22 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2043 | else | 2042 | else |
2044 | udc->usba_ep = usba_udc_pdata(pdev, udc); | 2043 | udc->usba_ep = usba_udc_pdata(pdev, udc); |
2045 | 2044 | ||
2046 | if (IS_ERR(udc->usba_ep)) { | 2045 | if (IS_ERR(udc->usba_ep)) |
2047 | ret = PTR_ERR(udc->usba_ep); | 2046 | return PTR_ERR(udc->usba_ep); |
2048 | goto err_alloc_ep; | ||
2049 | } | ||
2050 | 2047 | ||
2051 | ret = request_irq(irq, usba_udc_irq, 0, "atmel_usba_udc", udc); | 2048 | ret = devm_request_irq(&pdev->dev, irq, usba_udc_irq, 0, |
2049 | "atmel_usba_udc", udc); | ||
2052 | if (ret) { | 2050 | if (ret) { |
2053 | dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n", | 2051 | dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n", |
2054 | irq, ret); | 2052 | irq, ret); |
2055 | goto err_request_irq; | 2053 | return ret; |
2056 | } | 2054 | } |
2057 | udc->irq = irq; | 2055 | udc->irq = irq; |
2058 | 2056 | ||
2059 | if (gpio_is_valid(udc->vbus_pin)) { | 2057 | if (gpio_is_valid(udc->vbus_pin)) { |
2060 | if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { | 2058 | if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { |
2061 | ret = request_irq(gpio_to_irq(udc->vbus_pin), | 2059 | ret = devm_request_irq(&pdev->dev, |
2060 | gpio_to_irq(udc->vbus_pin), | ||
2062 | usba_vbus_irq, 0, | 2061 | usba_vbus_irq, 0, |
2063 | "atmel_usba_udc", udc); | 2062 | "atmel_usba_udc", udc); |
2064 | if (ret) { | 2063 | if (ret) { |
@@ -2077,31 +2076,13 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2077 | 2076 | ||
2078 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | 2077 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); |
2079 | if (ret) | 2078 | if (ret) |
2080 | goto err_add_udc; | 2079 | return ret; |
2081 | 2080 | ||
2082 | usba_init_debugfs(udc); | 2081 | usba_init_debugfs(udc); |
2083 | for (i = 1; i < udc->num_ep; i++) | 2082 | for (i = 1; i < udc->num_ep; i++) |
2084 | usba_ep_init_debugfs(udc, &udc->usba_ep[i]); | 2083 | usba_ep_init_debugfs(udc, &udc->usba_ep[i]); |
2085 | 2084 | ||
2086 | return 0; | 2085 | return 0; |
2087 | |||
2088 | err_add_udc: | ||
2089 | if (gpio_is_valid(udc->vbus_pin)) | ||
2090 | free_irq(gpio_to_irq(udc->vbus_pin), udc); | ||
2091 | |||
2092 | free_irq(irq, udc); | ||
2093 | err_request_irq: | ||
2094 | err_alloc_ep: | ||
2095 | err_clk_enable: | ||
2096 | iounmap(udc->fifo); | ||
2097 | err_map_fifo: | ||
2098 | iounmap(udc->regs); | ||
2099 | err_map_regs: | ||
2100 | clk_put(hclk); | ||
2101 | err_get_hclk: | ||
2102 | clk_put(pclk); | ||
2103 | |||
2104 | return ret; | ||
2105 | } | 2086 | } |
2106 | 2087 | ||
2107 | static int __exit usba_udc_remove(struct platform_device *pdev) | 2088 | static int __exit usba_udc_remove(struct platform_device *pdev) |
@@ -2117,16 +2098,6 @@ static int __exit usba_udc_remove(struct platform_device *pdev) | |||
2117 | usba_ep_cleanup_debugfs(&udc->usba_ep[i]); | 2098 | usba_ep_cleanup_debugfs(&udc->usba_ep[i]); |
2118 | usba_cleanup_debugfs(udc); | 2099 | usba_cleanup_debugfs(udc); |
2119 | 2100 | ||
2120 | if (gpio_is_valid(udc->vbus_pin)) { | ||
2121 | free_irq(gpio_to_irq(udc->vbus_pin), udc); | ||
2122 | } | ||
2123 | |||
2124 | free_irq(udc->irq, udc); | ||
2125 | iounmap(udc->fifo); | ||
2126 | iounmap(udc->regs); | ||
2127 | clk_put(udc->hclk); | ||
2128 | clk_put(udc->pclk); | ||
2129 | |||
2130 | return 0; | 2101 | return 0; |
2131 | } | 2102 | } |
2132 | 2103 | ||
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c index c58fcf1ebe41..888fbb43b338 100644 --- a/drivers/usb/gadget/bcm63xx_udc.c +++ b/drivers/usb/gadget/bcm63xx_udc.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/device.h> | 19 | #include <linux/device.h> |
20 | #include <linux/dma-mapping.h> | 20 | #include <linux/dma-mapping.h> |
21 | #include <linux/errno.h> | 21 | #include <linux/errno.h> |
22 | #include <linux/init.h> | ||
23 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
24 | #include <linux/ioport.h> | 23 | #include <linux/ioport.h> |
25 | #include <linux/kconfig.h> | 24 | #include <linux/kconfig.h> |
@@ -549,7 +548,7 @@ static void bcm63xx_ep_setup(struct bcm63xx_udc *udc) | |||
549 | 548 | ||
550 | if (idx < 0) | 549 | if (idx < 0) |
551 | continue; | 550 | continue; |
552 | udc->bep[idx].ep.maxpacket = max_pkt; | 551 | usb_ep_set_maxpacket_limit(&udc->bep[idx].ep, max_pkt); |
553 | 552 | ||
554 | val = (idx << USBD_CSR_EP_LOG_SHIFT) | | 553 | val = (idx << USBD_CSR_EP_LOG_SHIFT) | |
555 | (cfg->dir << USBD_CSR_EP_DIR_SHIFT) | | 554 | (cfg->dir << USBD_CSR_EP_DIR_SHIFT) | |
@@ -943,7 +942,7 @@ static int bcm63xx_init_udc_hw(struct bcm63xx_udc *udc) | |||
943 | bep->ep.ops = &bcm63xx_udc_ep_ops; | 942 | bep->ep.ops = &bcm63xx_udc_ep_ops; |
944 | list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); | 943 | list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); |
945 | bep->halted = 0; | 944 | bep->halted = 0; |
946 | bep->ep.maxpacket = BCM63XX_MAX_CTRL_PKT; | 945 | usb_ep_set_maxpacket_limit(&bep->ep, BCM63XX_MAX_CTRL_PKT); |
947 | bep->udc = udc; | 946 | bep->udc = udc; |
948 | bep->ep.desc = NULL; | 947 | bep->ep.desc = NULL; |
949 | INIT_LIST_HEAD(&bep->queue); | 948 | INIT_LIST_HEAD(&bep->queue); |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 2018ba1a2172..d742bed7a5fa 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -1452,8 +1452,22 @@ unknown: | |||
1452 | struct usb_configuration *c; | 1452 | struct usb_configuration *c; |
1453 | 1453 | ||
1454 | c = cdev->config; | 1454 | c = cdev->config; |
1455 | if (c && c->setup) | 1455 | if (!c) |
1456 | goto done; | ||
1457 | |||
1458 | /* try current config's setup */ | ||
1459 | if (c->setup) { | ||
1456 | value = c->setup(c, ctrl); | 1460 | value = c->setup(c, ctrl); |
1461 | goto done; | ||
1462 | } | ||
1463 | |||
1464 | /* try the only function in the current config */ | ||
1465 | if (!list_is_singular(&c->functions)) | ||
1466 | goto done; | ||
1467 | f = list_first_entry(&c->functions, struct usb_function, | ||
1468 | list); | ||
1469 | if (f->setup) | ||
1470 | value = f->setup(f, ctrl); | ||
1457 | } | 1471 | } |
1458 | 1472 | ||
1459 | goto done; | 1473 | goto done; |
@@ -1714,7 +1728,7 @@ composite_resume(struct usb_gadget *gadget) | |||
1714 | { | 1728 | { |
1715 | struct usb_composite_dev *cdev = get_gadget_data(gadget); | 1729 | struct usb_composite_dev *cdev = get_gadget_data(gadget); |
1716 | struct usb_function *f; | 1730 | struct usb_function *f; |
1717 | u8 maxpower; | 1731 | u16 maxpower; |
1718 | 1732 | ||
1719 | /* REVISIT: should we have config level | 1733 | /* REVISIT: should we have config level |
1720 | * suspend/resume callbacks? | 1734 | * suspend/resume callbacks? |
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 25885112fa35..7d1cc01796b6 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <linux/device.h> | 4 | #include <linux/device.h> |
5 | #include <linux/usb/composite.h> | 5 | #include <linux/usb/composite.h> |
6 | #include <linux/usb/gadget_configfs.h> | 6 | #include <linux/usb/gadget_configfs.h> |
7 | #include "configfs.h" | ||
7 | 8 | ||
8 | int check_user_usb_string(const char *name, | 9 | int check_user_usb_string(const char *name, |
9 | struct usb_gadget_strings *stringtab_dev) | 10 | struct usb_gadget_strings *stringtab_dev) |
@@ -564,6 +565,13 @@ static struct config_group *function_make( | |||
564 | usb_put_function_instance(fi); | 565 | usb_put_function_instance(fi); |
565 | return ERR_PTR(ret); | 566 | return ERR_PTR(ret); |
566 | } | 567 | } |
568 | if (fi->set_inst_name) { | ||
569 | ret = fi->set_inst_name(fi, instance_name); | ||
570 | if (ret) { | ||
571 | usb_put_function_instance(fi); | ||
572 | return ERR_PTR(ret); | ||
573 | } | ||
574 | } | ||
567 | 575 | ||
568 | gi = container_of(group, struct gadget_info, functions_group); | 576 | gi = container_of(group, struct gadget_info, functions_group); |
569 | 577 | ||
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 8f4dae310923..8c06430dcc47 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -951,7 +951,7 @@ static void init_dummy_udc_hw(struct dummy *dum) | |||
951 | list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list); | 951 | list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list); |
952 | ep->halted = ep->wedged = ep->already_seen = | 952 | ep->halted = ep->wedged = ep->already_seen = |
953 | ep->setup_stage = 0; | 953 | ep->setup_stage = 0; |
954 | ep->ep.maxpacket = ~0; | 954 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
955 | ep->ep.max_streams = 16; | 955 | ep->ep.max_streams = 16; |
956 | ep->last_io = jiffies; | 956 | ep->last_io = jiffies; |
957 | ep->gadget = &dum->gadget; | 957 | ep->gadget = &dum->gadget; |
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index a777f7bd11b4..0567cca1465e 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c | |||
@@ -11,7 +11,6 @@ | |||
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/init.h> | ||
15 | #include <linux/types.h> | 14 | #include <linux/types.h> |
16 | #include <linux/device.h> | 15 | #include <linux/device.h> |
17 | 16 | ||
@@ -58,7 +57,7 @@ ep_matches ( | |||
58 | return 0; | 57 | return 0; |
59 | 58 | ||
60 | /* only support ep0 for portable CONTROL traffic */ | 59 | /* only support ep0 for portable CONTROL traffic */ |
61 | type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | 60 | type = usb_endpoint_type(desc); |
62 | if (USB_ENDPOINT_XFER_CONTROL == type) | 61 | if (USB_ENDPOINT_XFER_CONTROL == type) |
63 | return 0; | 62 | return 0; |
64 | 63 | ||
@@ -129,7 +128,7 @@ ep_matches ( | |||
129 | * and wants to know the maximum possible, provide the info. | 128 | * and wants to know the maximum possible, provide the info. |
130 | */ | 129 | */ |
131 | if (desc->wMaxPacketSize == 0) | 130 | if (desc->wMaxPacketSize == 0) |
132 | desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket); | 131 | desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket_limit); |
133 | 132 | ||
134 | /* endpoint maxpacket size is an input parameter, except for bulk | 133 | /* endpoint maxpacket size is an input parameter, except for bulk |
135 | * where it's an output parameter representing the full speed limit. | 134 | * where it's an output parameter representing the full speed limit. |
@@ -145,7 +144,7 @@ ep_matches ( | |||
145 | 144 | ||
146 | case USB_ENDPOINT_XFER_ISOC: | 145 | case USB_ENDPOINT_XFER_ISOC: |
147 | /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ | 146 | /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ |
148 | if (ep->maxpacket < max) | 147 | if (ep->maxpacket_limit < max) |
149 | return 0; | 148 | return 0; |
150 | if (!gadget_is_dualspeed(gadget) && max > 1023) | 149 | if (!gadget_is_dualspeed(gadget) && max > 1023) |
151 | return 0; | 150 | return 0; |
@@ -178,7 +177,7 @@ ep_matches ( | |||
178 | 177 | ||
179 | /* report (variable) full speed bulk maxpacket */ | 178 | /* report (variable) full speed bulk maxpacket */ |
180 | if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) { | 179 | if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) { |
181 | int size = ep->maxpacket; | 180 | int size = ep->maxpacket_limit; |
182 | 181 | ||
183 | /* min() doesn't work on bitfields with gcc-3.5 */ | 182 | /* min() doesn't work on bitfields with gcc-3.5 */ |
184 | if (size > 64) | 183 | if (size > 64) |
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c index 8d9e6f7e8f1a..798760fa7e70 100644 --- a/drivers/usb/gadget/f_ecm.c +++ b/drivers/usb/gadget/f_ecm.c | |||
@@ -691,7 +691,6 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
691 | int status; | 691 | int status; |
692 | struct usb_ep *ep; | 692 | struct usb_ep *ep; |
693 | 693 | ||
694 | #ifndef USBF_ECM_INCLUDED | ||
695 | struct f_ecm_opts *ecm_opts; | 694 | struct f_ecm_opts *ecm_opts; |
696 | 695 | ||
697 | if (!can_support_ecm(cdev->gadget)) | 696 | if (!can_support_ecm(cdev->gadget)) |
@@ -715,7 +714,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
715 | return status; | 714 | return status; |
716 | ecm_opts->bound = true; | 715 | ecm_opts->bound = true; |
717 | } | 716 | } |
718 | #endif | 717 | |
719 | us = usb_gstrings_attach(cdev, ecm_strings, | 718 | us = usb_gstrings_attach(cdev, ecm_strings, |
720 | ARRAY_SIZE(ecm_string_defs)); | 719 | ARRAY_SIZE(ecm_string_defs)); |
721 | if (IS_ERR(us)) | 720 | if (IS_ERR(us)) |
@@ -834,74 +833,6 @@ fail: | |||
834 | return status; | 833 | return status; |
835 | } | 834 | } |
836 | 835 | ||
837 | #ifdef USBF_ECM_INCLUDED | ||
838 | |||
839 | static void | ||
840 | ecm_old_unbind(struct usb_configuration *c, struct usb_function *f) | ||
841 | { | ||
842 | struct f_ecm *ecm = func_to_ecm(f); | ||
843 | |||
844 | DBG(c->cdev, "ecm unbind\n"); | ||
845 | |||
846 | usb_free_all_descriptors(f); | ||
847 | |||
848 | kfree(ecm->notify_req->buf); | ||
849 | usb_ep_free_request(ecm->notify, ecm->notify_req); | ||
850 | kfree(ecm); | ||
851 | } | ||
852 | |||
853 | /** | ||
854 | * ecm_bind_config - add CDC Ethernet network link to a configuration | ||
855 | * @c: the configuration to support the network link | ||
856 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
857 | * side of the link was recorded | ||
858 | * @dev: eth_dev structure | ||
859 | * Context: single threaded during gadget setup | ||
860 | * | ||
861 | * Returns zero on success, else negative errno. | ||
862 | * | ||
863 | * Caller must have called @gether_setup(). Caller is also responsible | ||
864 | * for calling @gether_cleanup() before module unload. | ||
865 | */ | ||
866 | int | ||
867 | ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
868 | struct eth_dev *dev) | ||
869 | { | ||
870 | struct f_ecm *ecm; | ||
871 | int status; | ||
872 | |||
873 | if (!can_support_ecm(c->cdev->gadget) || !ethaddr) | ||
874 | return -EINVAL; | ||
875 | |||
876 | /* allocate and initialize one new instance */ | ||
877 | ecm = kzalloc(sizeof *ecm, GFP_KERNEL); | ||
878 | if (!ecm) | ||
879 | return -ENOMEM; | ||
880 | |||
881 | /* export host's Ethernet address in CDC format */ | ||
882 | snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); | ||
883 | ecm_string_defs[1].s = ecm->ethaddr; | ||
884 | |||
885 | ecm->port.ioport = dev; | ||
886 | ecm->port.cdc_filter = DEFAULT_FILTER; | ||
887 | |||
888 | ecm->port.func.name = "cdc_ethernet"; | ||
889 | /* descriptors are per-instance copies */ | ||
890 | ecm->port.func.bind = ecm_bind; | ||
891 | ecm->port.func.unbind = ecm_old_unbind; | ||
892 | ecm->port.func.set_alt = ecm_set_alt; | ||
893 | ecm->port.func.get_alt = ecm_get_alt; | ||
894 | ecm->port.func.setup = ecm_setup; | ||
895 | ecm->port.func.disable = ecm_disable; | ||
896 | |||
897 | status = usb_add_function(c, &ecm->port.func); | ||
898 | if (status) | ||
899 | kfree(ecm); | ||
900 | return status; | ||
901 | } | ||
902 | |||
903 | #else | ||
904 | |||
905 | static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item) | 836 | static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item) |
906 | { | 837 | { |
907 | return container_of(to_config_group(item), struct f_ecm_opts, | 838 | return container_of(to_config_group(item), struct f_ecm_opts, |
@@ -1040,5 +971,3 @@ static struct usb_function *ecm_alloc(struct usb_function_instance *fi) | |||
1040 | DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc); | 971 | DECLARE_USB_FUNCTION_INIT(ecm, ecm_alloc_inst, ecm_alloc); |
1041 | MODULE_LICENSE("GPL"); | 972 | MODULE_LICENSE("GPL"); |
1042 | MODULE_AUTHOR("David Brownell"); | 973 | MODULE_AUTHOR("David Brownell"); |
1043 | |||
1044 | #endif | ||
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 241fc873ffa4..306a2b52125c 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -22,218 +22,42 @@ | |||
22 | #include <linux/pagemap.h> | 22 | #include <linux/pagemap.h> |
23 | #include <linux/export.h> | 23 | #include <linux/export.h> |
24 | #include <linux/hid.h> | 24 | #include <linux/hid.h> |
25 | #include <linux/module.h> | ||
25 | #include <asm/unaligned.h> | 26 | #include <asm/unaligned.h> |
26 | 27 | ||
27 | #include <linux/usb/composite.h> | 28 | #include <linux/usb/composite.h> |
28 | #include <linux/usb/functionfs.h> | 29 | #include <linux/usb/functionfs.h> |
29 | 30 | ||
31 | #include "u_fs.h" | ||
32 | #include "configfs.h" | ||
30 | 33 | ||
31 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ | 34 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ |
32 | 35 | ||
33 | 36 | /* Variable Length Array Macros **********************************************/ | |
34 | /* Debugging ****************************************************************/ | 37 | #define vla_group(groupname) size_t groupname##__next = 0 |
35 | 38 | #define vla_group_size(groupname) groupname##__next | |
36 | #ifdef VERBOSE_DEBUG | 39 | |
37 | #ifndef pr_vdebug | 40 | #define vla_item(groupname, type, name, n) \ |
38 | # define pr_vdebug pr_debug | 41 | size_t groupname##_##name##__offset = ({ \ |
39 | #endif /* pr_vdebug */ | 42 | size_t align_mask = __alignof__(type) - 1; \ |
40 | # define ffs_dump_mem(prefix, ptr, len) \ | 43 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ |
41 | print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) | 44 | size_t size = (n) * sizeof(type); \ |
42 | #else | 45 | groupname##__next = offset + size; \ |
43 | #ifndef pr_vdebug | 46 | offset; \ |
44 | # define pr_vdebug(...) do { } while (0) | 47 | }) |
45 | #endif /* pr_vdebug */ | 48 | |
46 | # define ffs_dump_mem(prefix, ptr, len) do { } while (0) | 49 | #define vla_item_with_sz(groupname, type, name, n) \ |
47 | #endif /* VERBOSE_DEBUG */ | 50 | size_t groupname##_##name##__sz = (n) * sizeof(type); \ |
48 | 51 | size_t groupname##_##name##__offset = ({ \ | |
49 | #define ENTER() pr_vdebug("%s()\n", __func__) | 52 | size_t align_mask = __alignof__(type) - 1; \ |
50 | 53 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ | |
51 | 54 | size_t size = groupname##_##name##__sz; \ | |
52 | /* The data structure and setup file ****************************************/ | 55 | groupname##__next = offset + size; \ |
53 | 56 | offset; \ | |
54 | enum ffs_state { | 57 | }) |
55 | /* | 58 | |
56 | * Waiting for descriptors and strings. | 59 | #define vla_ptr(ptr, groupname, name) \ |
57 | * | 60 | ((void *) ((char *)ptr + groupname##_##name##__offset)) |
58 | * In this state no open(2), read(2) or write(2) on epfiles | ||
59 | * may succeed (which should not be the problem as there | ||
60 | * should be no such files opened in the first place). | ||
61 | */ | ||
62 | FFS_READ_DESCRIPTORS, | ||
63 | FFS_READ_STRINGS, | ||
64 | |||
65 | /* | ||
66 | * We've got descriptors and strings. We are or have called | ||
67 | * functionfs_ready_callback(). functionfs_bind() may have | ||
68 | * been called but we don't know. | ||
69 | * | ||
70 | * This is the only state in which operations on epfiles may | ||
71 | * succeed. | ||
72 | */ | ||
73 | FFS_ACTIVE, | ||
74 | |||
75 | /* | ||
76 | * All endpoints have been closed. This state is also set if | ||
77 | * we encounter an unrecoverable error. The only | ||
78 | * unrecoverable error is situation when after reading strings | ||
79 | * from user space we fail to initialise epfiles or | ||
80 | * functionfs_ready_callback() returns with error (<0). | ||
81 | * | ||
82 | * In this state no open(2), read(2) or write(2) (both on ep0 | ||
83 | * as well as epfile) may succeed (at this point epfiles are | ||
84 | * unlinked and all closed so this is not a problem; ep0 is | ||
85 | * also closed but ep0 file exists and so open(2) on ep0 must | ||
86 | * fail). | ||
87 | */ | ||
88 | FFS_CLOSING | ||
89 | }; | ||
90 | |||
91 | |||
92 | enum ffs_setup_state { | ||
93 | /* There is no setup request pending. */ | ||
94 | FFS_NO_SETUP, | ||
95 | /* | ||
96 | * User has read events and there was a setup request event | ||
97 | * there. The next read/write on ep0 will handle the | ||
98 | * request. | ||
99 | */ | ||
100 | FFS_SETUP_PENDING, | ||
101 | /* | ||
102 | * There was event pending but before user space handled it | ||
103 | * some other event was introduced which canceled existing | ||
104 | * setup. If this state is set read/write on ep0 return | ||
105 | * -EIDRM. This state is only set when adding event. | ||
106 | */ | ||
107 | FFS_SETUP_CANCELED | ||
108 | }; | ||
109 | |||
110 | |||
111 | |||
112 | struct ffs_epfile; | ||
113 | struct ffs_function; | ||
114 | |||
115 | struct ffs_data { | ||
116 | struct usb_gadget *gadget; | ||
117 | |||
118 | /* | ||
119 | * Protect access read/write operations, only one read/write | ||
120 | * at a time. As a consequence protects ep0req and company. | ||
121 | * While setup request is being processed (queued) this is | ||
122 | * held. | ||
123 | */ | ||
124 | struct mutex mutex; | ||
125 | |||
126 | /* | ||
127 | * Protect access to endpoint related structures (basically | ||
128 | * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for | ||
129 | * endpoint zero. | ||
130 | */ | ||
131 | spinlock_t eps_lock; | ||
132 | |||
133 | /* | ||
134 | * XXX REVISIT do we need our own request? Since we are not | ||
135 | * handling setup requests immediately user space may be so | ||
136 | * slow that another setup will be sent to the gadget but this | ||
137 | * time not to us but another function and then there could be | ||
138 | * a race. Is that the case? Or maybe we can use cdev->req | ||
139 | * after all, maybe we just need some spinlock for that? | ||
140 | */ | ||
141 | struct usb_request *ep0req; /* P: mutex */ | ||
142 | struct completion ep0req_completion; /* P: mutex */ | ||
143 | int ep0req_status; /* P: mutex */ | ||
144 | |||
145 | /* reference counter */ | ||
146 | atomic_t ref; | ||
147 | /* how many files are opened (EP0 and others) */ | ||
148 | atomic_t opened; | ||
149 | |||
150 | /* EP0 state */ | ||
151 | enum ffs_state state; | ||
152 | |||
153 | /* | ||
154 | * Possible transitions: | ||
155 | * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock | ||
156 | * happens only in ep0 read which is P: mutex | ||
157 | * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock | ||
158 | * happens only in ep0 i/o which is P: mutex | ||
159 | * + FFS_SETUP_PENDING -> FFS_SETUP_CANCELED -- P: ev.waitq.lock | ||
160 | * + FFS_SETUP_CANCELED -> FFS_NO_SETUP -- cmpxchg | ||
161 | */ | ||
162 | enum ffs_setup_state setup_state; | ||
163 | |||
164 | #define FFS_SETUP_STATE(ffs) \ | ||
165 | ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state, \ | ||
166 | FFS_SETUP_CANCELED, FFS_NO_SETUP)) | ||
167 | |||
168 | /* Events & such. */ | ||
169 | struct { | ||
170 | u8 types[4]; | ||
171 | unsigned short count; | ||
172 | /* XXX REVISIT need to update it in some places, or do we? */ | ||
173 | unsigned short can_stall; | ||
174 | struct usb_ctrlrequest setup; | ||
175 | |||
176 | wait_queue_head_t waitq; | ||
177 | } ev; /* the whole structure, P: ev.waitq.lock */ | ||
178 | |||
179 | /* Flags */ | ||
180 | unsigned long flags; | ||
181 | #define FFS_FL_CALL_CLOSED_CALLBACK 0 | ||
182 | #define FFS_FL_BOUND 1 | ||
183 | |||
184 | /* Active function */ | ||
185 | struct ffs_function *func; | ||
186 | |||
187 | /* | ||
188 | * Device name, write once when file system is mounted. | ||
189 | * Intended for user to read if she wants. | ||
190 | */ | ||
191 | const char *dev_name; | ||
192 | /* Private data for our user (ie. gadget). Managed by user. */ | ||
193 | void *private_data; | ||
194 | |||
195 | /* filled by __ffs_data_got_descs() */ | ||
196 | /* | ||
197 | * Real descriptors are 16 bytes after raw_descs (so you need | ||
198 | * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the | ||
199 | * first full speed descriptor). raw_descs_length and | ||
200 | * raw_fs_descs_length do not have those 16 bytes added. | ||
201 | */ | ||
202 | const void *raw_descs; | ||
203 | unsigned raw_descs_length; | ||
204 | unsigned raw_fs_descs_length; | ||
205 | unsigned fs_descs_count; | ||
206 | unsigned hs_descs_count; | ||
207 | |||
208 | unsigned short strings_count; | ||
209 | unsigned short interfaces_count; | ||
210 | unsigned short eps_count; | ||
211 | unsigned short _pad1; | ||
212 | |||
213 | /* filled by __ffs_data_got_strings() */ | ||
214 | /* ids in stringtabs are set in functionfs_bind() */ | ||
215 | const void *raw_strings; | ||
216 | struct usb_gadget_strings **stringtabs; | ||
217 | |||
218 | /* | ||
219 | * File system's super block, write once when file system is | ||
220 | * mounted. | ||
221 | */ | ||
222 | struct super_block *sb; | ||
223 | |||
224 | /* File permissions, written once when fs is mounted */ | ||
225 | struct ffs_file_perms { | ||
226 | umode_t mode; | ||
227 | kuid_t uid; | ||
228 | kgid_t gid; | ||
229 | } file_perms; | ||
230 | |||
231 | /* | ||
232 | * The endpoint files, filled by ffs_epfiles_create(), | ||
233 | * destroyed by ffs_epfiles_destroy(). | ||
234 | */ | ||
235 | struct ffs_epfile *epfiles; | ||
236 | }; | ||
237 | 61 | ||
238 | /* Reference counter handling */ | 62 | /* Reference counter handling */ |
239 | static void ffs_data_get(struct ffs_data *ffs); | 63 | static void ffs_data_get(struct ffs_data *ffs); |
@@ -274,15 +98,12 @@ static struct ffs_function *ffs_func_from_usb(struct usb_function *f) | |||
274 | return container_of(f, struct ffs_function, function); | 98 | return container_of(f, struct ffs_function, function); |
275 | } | 99 | } |
276 | 100 | ||
277 | static void ffs_func_free(struct ffs_function *func); | ||
278 | 101 | ||
279 | static void ffs_func_eps_disable(struct ffs_function *func); | 102 | static void ffs_func_eps_disable(struct ffs_function *func); |
280 | static int __must_check ffs_func_eps_enable(struct ffs_function *func); | 103 | static int __must_check ffs_func_eps_enable(struct ffs_function *func); |
281 | 104 | ||
282 | static int ffs_func_bind(struct usb_configuration *, | 105 | static int ffs_func_bind(struct usb_configuration *, |
283 | struct usb_function *); | 106 | struct usb_function *); |
284 | static void ffs_func_unbind(struct usb_configuration *, | ||
285 | struct usb_function *); | ||
286 | static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned); | 107 | static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned); |
287 | static void ffs_func_disable(struct usb_function *); | 108 | static void ffs_func_disable(struct usb_function *); |
288 | static int ffs_func_setup(struct usb_function *, | 109 | static int ffs_func_setup(struct usb_function *, |
@@ -335,6 +156,17 @@ ffs_sb_create_file(struct super_block *sb, const char *name, void *data, | |||
335 | const struct file_operations *fops, | 156 | const struct file_operations *fops, |
336 | struct dentry **dentry_p); | 157 | struct dentry **dentry_p); |
337 | 158 | ||
159 | /* Devices management *******************************************************/ | ||
160 | |||
161 | DEFINE_MUTEX(ffs_lock); | ||
162 | EXPORT_SYMBOL(ffs_lock); | ||
163 | |||
164 | static struct ffs_dev *ffs_find_dev(const char *name); | ||
165 | static int _ffs_name_dev(struct ffs_dev *dev, const char *name); | ||
166 | static void *ffs_acquire_dev(const char *dev_name); | ||
167 | static void ffs_release_dev(struct ffs_data *ffs_data); | ||
168 | static int ffs_ready(struct ffs_data *ffs); | ||
169 | static void ffs_closed(struct ffs_data *ffs); | ||
338 | 170 | ||
339 | /* Misc helper functions ****************************************************/ | 171 | /* Misc helper functions ****************************************************/ |
340 | 172 | ||
@@ -460,7 +292,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, | |||
460 | ffs->state = FFS_ACTIVE; | 292 | ffs->state = FFS_ACTIVE; |
461 | mutex_unlock(&ffs->mutex); | 293 | mutex_unlock(&ffs->mutex); |
462 | 294 | ||
463 | ret = functionfs_ready_callback(ffs); | 295 | ret = ffs_ready(ffs); |
464 | if (unlikely(ret < 0)) { | 296 | if (unlikely(ret < 0)) { |
465 | ffs->state = FFS_CLOSING; | 297 | ffs->state = FFS_CLOSING; |
466 | return ret; | 298 | return ret; |
@@ -753,78 +585,71 @@ static ssize_t ffs_epfile_io(struct file *file, | |||
753 | char __user *buf, size_t len, int read) | 585 | char __user *buf, size_t len, int read) |
754 | { | 586 | { |
755 | struct ffs_epfile *epfile = file->private_data; | 587 | struct ffs_epfile *epfile = file->private_data; |
588 | struct usb_gadget *gadget = epfile->ffs->gadget; | ||
756 | struct ffs_ep *ep; | 589 | struct ffs_ep *ep; |
757 | char *data = NULL; | 590 | char *data = NULL; |
758 | ssize_t ret; | 591 | ssize_t ret, data_len; |
759 | int halt; | 592 | int halt; |
760 | 593 | ||
761 | goto first_try; | 594 | /* Are we still active? */ |
762 | do { | 595 | if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) { |
763 | spin_unlock_irq(&epfile->ffs->eps_lock); | 596 | ret = -ENODEV; |
764 | mutex_unlock(&epfile->mutex); | 597 | goto error; |
598 | } | ||
765 | 599 | ||
766 | first_try: | 600 | /* Wait for endpoint to be enabled */ |
767 | /* Are we still active? */ | 601 | ep = epfile->ep; |
768 | if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) { | 602 | if (!ep) { |
769 | ret = -ENODEV; | 603 | if (file->f_flags & O_NONBLOCK) { |
604 | ret = -EAGAIN; | ||
770 | goto error; | 605 | goto error; |
771 | } | 606 | } |
772 | 607 | ||
773 | /* Wait for endpoint to be enabled */ | 608 | ret = wait_event_interruptible(epfile->wait, (ep = epfile->ep)); |
774 | ep = epfile->ep; | 609 | if (ret) { |
775 | if (!ep) { | 610 | ret = -EINTR; |
776 | if (file->f_flags & O_NONBLOCK) { | ||
777 | ret = -EAGAIN; | ||
778 | goto error; | ||
779 | } | ||
780 | |||
781 | if (wait_event_interruptible(epfile->wait, | ||
782 | (ep = epfile->ep))) { | ||
783 | ret = -EINTR; | ||
784 | goto error; | ||
785 | } | ||
786 | } | ||
787 | |||
788 | /* Do we halt? */ | ||
789 | halt = !read == !epfile->in; | ||
790 | if (halt && epfile->isoc) { | ||
791 | ret = -EINVAL; | ||
792 | goto error; | 611 | goto error; |
793 | } | 612 | } |
613 | } | ||
794 | 614 | ||
795 | /* Allocate & copy */ | 615 | /* Do we halt? */ |
796 | if (!halt && !data) { | 616 | halt = !read == !epfile->in; |
797 | data = kzalloc(len, GFP_KERNEL); | 617 | if (halt && epfile->isoc) { |
798 | if (unlikely(!data)) | 618 | ret = -EINVAL; |
799 | return -ENOMEM; | 619 | goto error; |
620 | } | ||
800 | 621 | ||
801 | if (!read && | 622 | /* Allocate & copy */ |
802 | unlikely(__copy_from_user(data, buf, len))) { | 623 | if (!halt) { |
803 | ret = -EFAULT; | 624 | /* |
804 | goto error; | 625 | * Controller may require buffer size to be aligned to |
805 | } | 626 | * maxpacketsize of an out endpoint. |
806 | } | 627 | */ |
628 | data_len = read ? usb_ep_align_maybe(gadget, ep->ep, len) : len; | ||
629 | |||
630 | data = kmalloc(data_len, GFP_KERNEL); | ||
631 | if (unlikely(!data)) | ||
632 | return -ENOMEM; | ||
807 | 633 | ||
808 | /* We will be using request */ | 634 | if (!read && unlikely(copy_from_user(data, buf, len))) { |
809 | ret = ffs_mutex_lock(&epfile->mutex, | 635 | ret = -EFAULT; |
810 | file->f_flags & O_NONBLOCK); | ||
811 | if (unlikely(ret)) | ||
812 | goto error; | 636 | goto error; |
637 | } | ||
638 | } | ||
813 | 639 | ||
814 | /* | 640 | /* We will be using request */ |
815 | * We're called from user space, we can use _irq rather then | 641 | ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); |
816 | * _irqsave | 642 | if (unlikely(ret)) |
817 | */ | 643 | goto error; |
818 | spin_lock_irq(&epfile->ffs->eps_lock); | ||
819 | 644 | ||
820 | /* | 645 | spin_lock_irq(&epfile->ffs->eps_lock); |
821 | * While we were acquiring mutex endpoint got disabled | ||
822 | * or changed? | ||
823 | */ | ||
824 | } while (unlikely(epfile->ep != ep)); | ||
825 | 646 | ||
826 | /* Halt */ | 647 | if (epfile->ep != ep) { |
827 | if (unlikely(halt)) { | 648 | /* In the meantime, endpoint got disabled or changed. */ |
649 | ret = -ESHUTDOWN; | ||
650 | spin_unlock_irq(&epfile->ffs->eps_lock); | ||
651 | } else if (halt) { | ||
652 | /* Halt */ | ||
828 | if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep)) | 653 | if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep)) |
829 | usb_ep_set_halt(ep->ep); | 654 | usb_ep_set_halt(ep->ep); |
830 | spin_unlock_irq(&epfile->ffs->eps_lock); | 655 | spin_unlock_irq(&epfile->ffs->eps_lock); |
@@ -837,7 +662,7 @@ first_try: | |||
837 | req->context = &done; | 662 | req->context = &done; |
838 | req->complete = ffs_epfile_io_complete; | 663 | req->complete = ffs_epfile_io_complete; |
839 | req->buf = data; | 664 | req->buf = data; |
840 | req->length = len; | 665 | req->length = data_len; |
841 | 666 | ||
842 | ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); | 667 | ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC); |
843 | 668 | ||
@@ -849,9 +674,17 @@ first_try: | |||
849 | ret = -EINTR; | 674 | ret = -EINTR; |
850 | usb_ep_dequeue(ep->ep, req); | 675 | usb_ep_dequeue(ep->ep, req); |
851 | } else { | 676 | } else { |
677 | /* | ||
678 | * XXX We may end up silently droping data here. | ||
679 | * Since data_len (i.e. req->length) may be bigger | ||
680 | * than len (after being rounded up to maxpacketsize), | ||
681 | * we may end up with more data then user space has | ||
682 | * space for. | ||
683 | */ | ||
852 | ret = ep->status; | 684 | ret = ep->status; |
853 | if (read && ret > 0 && | 685 | if (read && ret > 0 && |
854 | unlikely(copy_to_user(buf, data, ret))) | 686 | unlikely(copy_to_user(buf, data, |
687 | min_t(size_t, ret, len)))) | ||
855 | ret = -EFAULT; | 688 | ret = -EFAULT; |
856 | } | 689 | } |
857 | } | 690 | } |
@@ -1191,7 +1024,7 @@ ffs_fs_mount(struct file_system_type *t, int flags, | |||
1191 | return ERR_PTR(-ENOMEM); | 1024 | return ERR_PTR(-ENOMEM); |
1192 | } | 1025 | } |
1193 | 1026 | ||
1194 | ffs_dev = functionfs_acquire_dev_callback(dev_name); | 1027 | ffs_dev = ffs_acquire_dev(dev_name); |
1195 | if (IS_ERR(ffs_dev)) { | 1028 | if (IS_ERR(ffs_dev)) { |
1196 | ffs_data_put(ffs); | 1029 | ffs_data_put(ffs); |
1197 | return ERR_CAST(ffs_dev); | 1030 | return ERR_CAST(ffs_dev); |
@@ -1201,7 +1034,7 @@ ffs_fs_mount(struct file_system_type *t, int flags, | |||
1201 | 1034 | ||
1202 | rv = mount_nodev(t, flags, &data, ffs_sb_fill); | 1035 | rv = mount_nodev(t, flags, &data, ffs_sb_fill); |
1203 | if (IS_ERR(rv) && data.ffs_data) { | 1036 | if (IS_ERR(rv) && data.ffs_data) { |
1204 | functionfs_release_dev_callback(data.ffs_data); | 1037 | ffs_release_dev(data.ffs_data); |
1205 | ffs_data_put(data.ffs_data); | 1038 | ffs_data_put(data.ffs_data); |
1206 | } | 1039 | } |
1207 | return rv; | 1040 | return rv; |
@@ -1214,7 +1047,7 @@ ffs_fs_kill_sb(struct super_block *sb) | |||
1214 | 1047 | ||
1215 | kill_litter_super(sb); | 1048 | kill_litter_super(sb); |
1216 | if (sb->s_fs_info) { | 1049 | if (sb->s_fs_info) { |
1217 | functionfs_release_dev_callback(sb->s_fs_info); | 1050 | ffs_release_dev(sb->s_fs_info); |
1218 | ffs_data_put(sb->s_fs_info); | 1051 | ffs_data_put(sb->s_fs_info); |
1219 | } | 1052 | } |
1220 | } | 1053 | } |
@@ -1327,7 +1160,7 @@ static void ffs_data_clear(struct ffs_data *ffs) | |||
1327 | ENTER(); | 1160 | ENTER(); |
1328 | 1161 | ||
1329 | if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags)) | 1162 | if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags)) |
1330 | functionfs_closed_callback(ffs); | 1163 | ffs_closed(ffs); |
1331 | 1164 | ||
1332 | BUG_ON(ffs->gadget); | 1165 | BUG_ON(ffs->gadget); |
1333 | 1166 | ||
@@ -1463,71 +1296,6 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) | |||
1463 | kfree(epfiles); | 1296 | kfree(epfiles); |
1464 | } | 1297 | } |
1465 | 1298 | ||
1466 | static int functionfs_bind_config(struct usb_composite_dev *cdev, | ||
1467 | struct usb_configuration *c, | ||
1468 | struct ffs_data *ffs) | ||
1469 | { | ||
1470 | struct ffs_function *func; | ||
1471 | int ret; | ||
1472 | |||
1473 | ENTER(); | ||
1474 | |||
1475 | func = kzalloc(sizeof *func, GFP_KERNEL); | ||
1476 | if (unlikely(!func)) | ||
1477 | return -ENOMEM; | ||
1478 | |||
1479 | func->function.name = "Function FS Gadget"; | ||
1480 | func->function.strings = ffs->stringtabs; | ||
1481 | |||
1482 | func->function.bind = ffs_func_bind; | ||
1483 | func->function.unbind = ffs_func_unbind; | ||
1484 | func->function.set_alt = ffs_func_set_alt; | ||
1485 | func->function.disable = ffs_func_disable; | ||
1486 | func->function.setup = ffs_func_setup; | ||
1487 | func->function.suspend = ffs_func_suspend; | ||
1488 | func->function.resume = ffs_func_resume; | ||
1489 | |||
1490 | func->conf = c; | ||
1491 | func->gadget = cdev->gadget; | ||
1492 | func->ffs = ffs; | ||
1493 | ffs_data_get(ffs); | ||
1494 | |||
1495 | ret = usb_add_function(c, &func->function); | ||
1496 | if (unlikely(ret)) | ||
1497 | ffs_func_free(func); | ||
1498 | |||
1499 | return ret; | ||
1500 | } | ||
1501 | |||
1502 | static void ffs_func_free(struct ffs_function *func) | ||
1503 | { | ||
1504 | struct ffs_ep *ep = func->eps; | ||
1505 | unsigned count = func->ffs->eps_count; | ||
1506 | unsigned long flags; | ||
1507 | |||
1508 | ENTER(); | ||
1509 | |||
1510 | /* cleanup after autoconfig */ | ||
1511 | spin_lock_irqsave(&func->ffs->eps_lock, flags); | ||
1512 | do { | ||
1513 | if (ep->ep && ep->req) | ||
1514 | usb_ep_free_request(ep->ep, ep->req); | ||
1515 | ep->req = NULL; | ||
1516 | ++ep; | ||
1517 | } while (--count); | ||
1518 | spin_unlock_irqrestore(&func->ffs->eps_lock, flags); | ||
1519 | |||
1520 | ffs_data_put(func->ffs); | ||
1521 | |||
1522 | kfree(func->eps); | ||
1523 | /* | ||
1524 | * eps and interfaces_nums are allocated in the same chunk so | ||
1525 | * only one free is required. Descriptors are also allocated | ||
1526 | * in the same chunk. | ||
1527 | */ | ||
1528 | |||
1529 | kfree(func); | ||
1530 | } | ||
1531 | 1299 | ||
1532 | static void ffs_func_eps_disable(struct ffs_function *func) | 1300 | static void ffs_func_eps_disable(struct ffs_function *func) |
1533 | { | 1301 | { |
@@ -1901,30 +1669,34 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, | |||
1901 | 1669 | ||
1902 | /* Allocate everything in one chunk so there's less maintenance. */ | 1670 | /* Allocate everything in one chunk so there's less maintenance. */ |
1903 | { | 1671 | { |
1904 | struct { | ||
1905 | struct usb_gadget_strings *stringtabs[lang_count + 1]; | ||
1906 | struct usb_gadget_strings stringtab[lang_count]; | ||
1907 | struct usb_string strings[lang_count*(needed_count+1)]; | ||
1908 | } *d; | ||
1909 | unsigned i = 0; | 1672 | unsigned i = 0; |
1673 | vla_group(d); | ||
1674 | vla_item(d, struct usb_gadget_strings *, stringtabs, | ||
1675 | lang_count + 1); | ||
1676 | vla_item(d, struct usb_gadget_strings, stringtab, lang_count); | ||
1677 | vla_item(d, struct usb_string, strings, | ||
1678 | lang_count*(needed_count+1)); | ||
1679 | |||
1680 | char *vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); | ||
1910 | 1681 | ||
1911 | d = kmalloc(sizeof *d, GFP_KERNEL); | 1682 | if (unlikely(!vlabuf)) { |
1912 | if (unlikely(!d)) { | ||
1913 | kfree(_data); | 1683 | kfree(_data); |
1914 | return -ENOMEM; | 1684 | return -ENOMEM; |
1915 | } | 1685 | } |
1916 | 1686 | ||
1917 | stringtabs = d->stringtabs; | 1687 | /* Initialize the VLA pointers */ |
1918 | t = d->stringtab; | 1688 | stringtabs = vla_ptr(vlabuf, d, stringtabs); |
1689 | t = vla_ptr(vlabuf, d, stringtab); | ||
1919 | i = lang_count; | 1690 | i = lang_count; |
1920 | do { | 1691 | do { |
1921 | *stringtabs++ = t++; | 1692 | *stringtabs++ = t++; |
1922 | } while (--i); | 1693 | } while (--i); |
1923 | *stringtabs = NULL; | 1694 | *stringtabs = NULL; |
1924 | 1695 | ||
1925 | stringtabs = d->stringtabs; | 1696 | /* stringtabs = vlabuf = d_stringtabs for later kfree */ |
1926 | t = d->stringtab; | 1697 | stringtabs = vla_ptr(vlabuf, d, stringtabs); |
1927 | s = d->strings; | 1698 | t = vla_ptr(vlabuf, d, stringtab); |
1699 | s = vla_ptr(vlabuf, d, strings); | ||
1928 | strings = s; | 1700 | strings = s; |
1929 | } | 1701 | } |
1930 | 1702 | ||
@@ -2187,8 +1959,57 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, | |||
2187 | return 0; | 1959 | return 0; |
2188 | } | 1960 | } |
2189 | 1961 | ||
2190 | static int ffs_func_bind(struct usb_configuration *c, | 1962 | static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f, |
2191 | struct usb_function *f) | 1963 | struct usb_configuration *c) |
1964 | { | ||
1965 | struct ffs_function *func = ffs_func_from_usb(f); | ||
1966 | struct f_fs_opts *ffs_opts = | ||
1967 | container_of(f->fi, struct f_fs_opts, func_inst); | ||
1968 | int ret; | ||
1969 | |||
1970 | ENTER(); | ||
1971 | |||
1972 | /* | ||
1973 | * Legacy gadget triggers binding in functionfs_ready_callback, | ||
1974 | * which already uses locking; taking the same lock here would | ||
1975 | * cause a deadlock. | ||
1976 | * | ||
1977 | * Configfs-enabled gadgets however do need ffs_dev_lock. | ||
1978 | */ | ||
1979 | if (!ffs_opts->no_configfs) | ||
1980 | ffs_dev_lock(); | ||
1981 | ret = ffs_opts->dev->desc_ready ? 0 : -ENODEV; | ||
1982 | func->ffs = ffs_opts->dev->ffs_data; | ||
1983 | if (!ffs_opts->no_configfs) | ||
1984 | ffs_dev_unlock(); | ||
1985 | if (ret) | ||
1986 | return ERR_PTR(ret); | ||
1987 | |||
1988 | func->conf = c; | ||
1989 | func->gadget = c->cdev->gadget; | ||
1990 | |||
1991 | ffs_data_get(func->ffs); | ||
1992 | |||
1993 | /* | ||
1994 | * in drivers/usb/gadget/configfs.c:configfs_composite_bind() | ||
1995 | * configurations are bound in sequence with list_for_each_entry, | ||
1996 | * in each configuration its functions are bound in sequence | ||
1997 | * with list_for_each_entry, so we assume no race condition | ||
1998 | * with regard to ffs_opts->bound access | ||
1999 | */ | ||
2000 | if (!ffs_opts->refcnt) { | ||
2001 | ret = functionfs_bind(func->ffs, c->cdev); | ||
2002 | if (ret) | ||
2003 | return ERR_PTR(ret); | ||
2004 | } | ||
2005 | ffs_opts->refcnt++; | ||
2006 | func->function.strings = func->ffs->stringtabs; | ||
2007 | |||
2008 | return ffs_opts; | ||
2009 | } | ||
2010 | |||
2011 | static int _ffs_func_bind(struct usb_configuration *c, | ||
2012 | struct usb_function *f) | ||
2192 | { | 2013 | { |
2193 | struct ffs_function *func = ffs_func_from_usb(f); | 2014 | struct ffs_function *func = ffs_func_from_usb(f); |
2194 | struct ffs_data *ffs = func->ffs; | 2015 | struct ffs_data *ffs = func->ffs; |
@@ -2200,16 +2021,16 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2200 | int ret; | 2021 | int ret; |
2201 | 2022 | ||
2202 | /* Make it a single chunk, less management later on */ | 2023 | /* Make it a single chunk, less management later on */ |
2203 | struct { | 2024 | vla_group(d); |
2204 | struct ffs_ep eps[ffs->eps_count]; | 2025 | vla_item_with_sz(d, struct ffs_ep, eps, ffs->eps_count); |
2205 | struct usb_descriptor_header | 2026 | vla_item_with_sz(d, struct usb_descriptor_header *, fs_descs, |
2206 | *fs_descs[full ? ffs->fs_descs_count + 1 : 0]; | 2027 | full ? ffs->fs_descs_count + 1 : 0); |
2207 | struct usb_descriptor_header | 2028 | vla_item_with_sz(d, struct usb_descriptor_header *, hs_descs, |
2208 | *hs_descs[high ? ffs->hs_descs_count + 1 : 0]; | 2029 | high ? ffs->hs_descs_count + 1 : 0); |
2209 | short inums[ffs->interfaces_count]; | 2030 | vla_item_with_sz(d, short, inums, ffs->interfaces_count); |
2210 | char raw_descs[high ? ffs->raw_descs_length | 2031 | vla_item_with_sz(d, char, raw_descs, |
2211 | : ffs->raw_fs_descs_length]; | 2032 | high ? ffs->raw_descs_length : ffs->raw_fs_descs_length); |
2212 | } *data; | 2033 | char *vlabuf; |
2213 | 2034 | ||
2214 | ENTER(); | 2035 | ENTER(); |
2215 | 2036 | ||
@@ -2217,21 +2038,28 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2217 | if (unlikely(!(full | high))) | 2038 | if (unlikely(!(full | high))) |
2218 | return -ENOTSUPP; | 2039 | return -ENOTSUPP; |
2219 | 2040 | ||
2220 | /* Allocate */ | 2041 | /* Allocate a single chunk, less management later on */ |
2221 | data = kmalloc(sizeof *data, GFP_KERNEL); | 2042 | vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL); |
2222 | if (unlikely(!data)) | 2043 | if (unlikely(!vlabuf)) |
2223 | return -ENOMEM; | 2044 | return -ENOMEM; |
2224 | 2045 | ||
2225 | /* Zero */ | 2046 | /* Zero */ |
2226 | memset(data->eps, 0, sizeof data->eps); | 2047 | memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz); |
2227 | memcpy(data->raw_descs, ffs->raw_descs + 16, sizeof data->raw_descs); | 2048 | memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs + 16, |
2228 | memset(data->inums, 0xff, sizeof data->inums); | 2049 | d_raw_descs__sz); |
2229 | for (ret = ffs->eps_count; ret; --ret) | 2050 | memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz); |
2230 | data->eps[ret].num = -1; | 2051 | for (ret = ffs->eps_count; ret; --ret) { |
2052 | struct ffs_ep *ptr; | ||
2053 | |||
2054 | ptr = vla_ptr(vlabuf, d, eps); | ||
2055 | ptr[ret].num = -1; | ||
2056 | } | ||
2231 | 2057 | ||
2232 | /* Save pointers */ | 2058 | /* Save pointers |
2233 | func->eps = data->eps; | 2059 | * d_eps == vlabuf, func->eps used to kfree vlabuf later |
2234 | func->interfaces_nums = data->inums; | 2060 | */ |
2061 | func->eps = vla_ptr(vlabuf, d, eps); | ||
2062 | func->interfaces_nums = vla_ptr(vlabuf, d, inums); | ||
2235 | 2063 | ||
2236 | /* | 2064 | /* |
2237 | * Go through all the endpoint descriptors and allocate | 2065 | * Go through all the endpoint descriptors and allocate |
@@ -2239,10 +2067,10 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2239 | * numbers without worrying that it may be described later on. | 2067 | * numbers without worrying that it may be described later on. |
2240 | */ | 2068 | */ |
2241 | if (likely(full)) { | 2069 | if (likely(full)) { |
2242 | func->function.fs_descriptors = data->fs_descs; | 2070 | func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); |
2243 | ret = ffs_do_descs(ffs->fs_descs_count, | 2071 | ret = ffs_do_descs(ffs->fs_descs_count, |
2244 | data->raw_descs, | 2072 | vla_ptr(vlabuf, d, raw_descs), |
2245 | sizeof data->raw_descs, | 2073 | d_raw_descs__sz, |
2246 | __ffs_func_bind_do_descs, func); | 2074 | __ffs_func_bind_do_descs, func); |
2247 | if (unlikely(ret < 0)) | 2075 | if (unlikely(ret < 0)) |
2248 | goto error; | 2076 | goto error; |
@@ -2251,10 +2079,10 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2251 | } | 2079 | } |
2252 | 2080 | ||
2253 | if (likely(high)) { | 2081 | if (likely(high)) { |
2254 | func->function.hs_descriptors = data->hs_descs; | 2082 | func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); |
2255 | ret = ffs_do_descs(ffs->hs_descs_count, | 2083 | ret = ffs_do_descs(ffs->hs_descs_count, |
2256 | data->raw_descs + ret, | 2084 | vla_ptr(vlabuf, d, raw_descs) + ret, |
2257 | (sizeof data->raw_descs) - ret, | 2085 | d_raw_descs__sz - ret, |
2258 | __ffs_func_bind_do_descs, func); | 2086 | __ffs_func_bind_do_descs, func); |
2259 | if (unlikely(ret < 0)) | 2087 | if (unlikely(ret < 0)) |
2260 | goto error; | 2088 | goto error; |
@@ -2267,7 +2095,7 @@ static int ffs_func_bind(struct usb_configuration *c, | |||
2267 | */ | 2095 | */ |
2268 | ret = ffs_do_descs(ffs->fs_descs_count + | 2096 | ret = ffs_do_descs(ffs->fs_descs_count + |
2269 | (high ? ffs->hs_descs_count : 0), | 2097 | (high ? ffs->hs_descs_count : 0), |
2270 | data->raw_descs, sizeof data->raw_descs, | 2098 | vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz, |
2271 | __ffs_func_bind_do_nums, func); | 2099 | __ffs_func_bind_do_nums, func); |
2272 | if (unlikely(ret < 0)) | 2100 | if (unlikely(ret < 0)) |
2273 | goto error; | 2101 | goto error; |
@@ -2281,26 +2109,19 @@ error: | |||
2281 | return ret; | 2109 | return ret; |
2282 | } | 2110 | } |
2283 | 2111 | ||
2284 | 2112 | static int ffs_func_bind(struct usb_configuration *c, | |
2285 | /* Other USB function hooks *************************************************/ | 2113 | struct usb_function *f) |
2286 | |||
2287 | static void ffs_func_unbind(struct usb_configuration *c, | ||
2288 | struct usb_function *f) | ||
2289 | { | 2114 | { |
2290 | struct ffs_function *func = ffs_func_from_usb(f); | 2115 | struct f_fs_opts *ffs_opts = ffs_do_functionfs_bind(f, c); |
2291 | struct ffs_data *ffs = func->ffs; | ||
2292 | 2116 | ||
2293 | ENTER(); | 2117 | if (IS_ERR(ffs_opts)) |
2118 | return PTR_ERR(ffs_opts); | ||
2294 | 2119 | ||
2295 | if (ffs->func == func) { | 2120 | return _ffs_func_bind(c, f); |
2296 | ffs_func_eps_disable(func); | 2121 | } |
2297 | ffs->func = NULL; | ||
2298 | } | ||
2299 | 2122 | ||
2300 | ffs_event_add(ffs, FUNCTIONFS_UNBIND); | ||
2301 | 2123 | ||
2302 | ffs_func_free(func); | 2124 | /* Other USB function hooks *************************************************/ |
2303 | } | ||
2304 | 2125 | ||
2305 | static int ffs_func_set_alt(struct usb_function *f, | 2126 | static int ffs_func_set_alt(struct usb_function *f, |
2306 | unsigned interface, unsigned alt) | 2127 | unsigned interface, unsigned alt) |
@@ -2428,6 +2249,411 @@ static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf) | |||
2428 | } | 2249 | } |
2429 | 2250 | ||
2430 | 2251 | ||
2252 | /* Devices management *******************************************************/ | ||
2253 | |||
2254 | static LIST_HEAD(ffs_devices); | ||
2255 | |||
2256 | static struct ffs_dev *_ffs_find_dev(const char *name) | ||
2257 | { | ||
2258 | struct ffs_dev *dev; | ||
2259 | |||
2260 | list_for_each_entry(dev, &ffs_devices, entry) { | ||
2261 | if (!dev->name || !name) | ||
2262 | continue; | ||
2263 | if (strcmp(dev->name, name) == 0) | ||
2264 | return dev; | ||
2265 | } | ||
2266 | |||
2267 | return NULL; | ||
2268 | } | ||
2269 | |||
2270 | /* | ||
2271 | * ffs_lock must be taken by the caller of this function | ||
2272 | */ | ||
2273 | static struct ffs_dev *ffs_get_single_dev(void) | ||
2274 | { | ||
2275 | struct ffs_dev *dev; | ||
2276 | |||
2277 | if (list_is_singular(&ffs_devices)) { | ||
2278 | dev = list_first_entry(&ffs_devices, struct ffs_dev, entry); | ||
2279 | if (dev->single) | ||
2280 | return dev; | ||
2281 | } | ||
2282 | |||
2283 | return NULL; | ||
2284 | } | ||
2285 | |||
2286 | /* | ||
2287 | * ffs_lock must be taken by the caller of this function | ||
2288 | */ | ||
2289 | static struct ffs_dev *ffs_find_dev(const char *name) | ||
2290 | { | ||
2291 | struct ffs_dev *dev; | ||
2292 | |||
2293 | dev = ffs_get_single_dev(); | ||
2294 | if (dev) | ||
2295 | return dev; | ||
2296 | |||
2297 | return _ffs_find_dev(name); | ||
2298 | } | ||
2299 | |||
2300 | /* Configfs support *********************************************************/ | ||
2301 | |||
2302 | static inline struct f_fs_opts *to_ffs_opts(struct config_item *item) | ||
2303 | { | ||
2304 | return container_of(to_config_group(item), struct f_fs_opts, | ||
2305 | func_inst.group); | ||
2306 | } | ||
2307 | |||
2308 | static void ffs_attr_release(struct config_item *item) | ||
2309 | { | ||
2310 | struct f_fs_opts *opts = to_ffs_opts(item); | ||
2311 | |||
2312 | usb_put_function_instance(&opts->func_inst); | ||
2313 | } | ||
2314 | |||
2315 | static struct configfs_item_operations ffs_item_ops = { | ||
2316 | .release = ffs_attr_release, | ||
2317 | }; | ||
2318 | |||
2319 | static struct config_item_type ffs_func_type = { | ||
2320 | .ct_item_ops = &ffs_item_ops, | ||
2321 | .ct_owner = THIS_MODULE, | ||
2322 | }; | ||
2323 | |||
2324 | |||
2325 | /* Function registration interface ******************************************/ | ||
2326 | |||
2327 | static void ffs_free_inst(struct usb_function_instance *f) | ||
2328 | { | ||
2329 | struct f_fs_opts *opts; | ||
2330 | |||
2331 | opts = to_f_fs_opts(f); | ||
2332 | ffs_dev_lock(); | ||
2333 | ffs_free_dev(opts->dev); | ||
2334 | ffs_dev_unlock(); | ||
2335 | kfree(opts); | ||
2336 | } | ||
2337 | |||
2338 | #define MAX_INST_NAME_LEN 40 | ||
2339 | |||
2340 | static int ffs_set_inst_name(struct usb_function_instance *fi, const char *name) | ||
2341 | { | ||
2342 | struct f_fs_opts *opts; | ||
2343 | char *ptr; | ||
2344 | const char *tmp; | ||
2345 | int name_len, ret; | ||
2346 | |||
2347 | name_len = strlen(name) + 1; | ||
2348 | if (name_len > MAX_INST_NAME_LEN) | ||
2349 | return -ENAMETOOLONG; | ||
2350 | |||
2351 | ptr = kstrndup(name, name_len, GFP_KERNEL); | ||
2352 | if (!ptr) | ||
2353 | return -ENOMEM; | ||
2354 | |||
2355 | opts = to_f_fs_opts(fi); | ||
2356 | tmp = NULL; | ||
2357 | |||
2358 | ffs_dev_lock(); | ||
2359 | |||
2360 | tmp = opts->dev->name_allocated ? opts->dev->name : NULL; | ||
2361 | ret = _ffs_name_dev(opts->dev, ptr); | ||
2362 | if (ret) { | ||
2363 | kfree(ptr); | ||
2364 | ffs_dev_unlock(); | ||
2365 | return ret; | ||
2366 | } | ||
2367 | opts->dev->name_allocated = true; | ||
2368 | |||
2369 | ffs_dev_unlock(); | ||
2370 | |||
2371 | kfree(tmp); | ||
2372 | |||
2373 | return 0; | ||
2374 | } | ||
2375 | |||
2376 | static struct usb_function_instance *ffs_alloc_inst(void) | ||
2377 | { | ||
2378 | struct f_fs_opts *opts; | ||
2379 | struct ffs_dev *dev; | ||
2380 | |||
2381 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
2382 | if (!opts) | ||
2383 | return ERR_PTR(-ENOMEM); | ||
2384 | |||
2385 | opts->func_inst.set_inst_name = ffs_set_inst_name; | ||
2386 | opts->func_inst.free_func_inst = ffs_free_inst; | ||
2387 | ffs_dev_lock(); | ||
2388 | dev = ffs_alloc_dev(); | ||
2389 | ffs_dev_unlock(); | ||
2390 | if (IS_ERR(dev)) { | ||
2391 | kfree(opts); | ||
2392 | return ERR_CAST(dev); | ||
2393 | } | ||
2394 | opts->dev = dev; | ||
2395 | dev->opts = opts; | ||
2396 | |||
2397 | config_group_init_type_name(&opts->func_inst.group, "", | ||
2398 | &ffs_func_type); | ||
2399 | return &opts->func_inst; | ||
2400 | } | ||
2401 | |||
2402 | static void ffs_free(struct usb_function *f) | ||
2403 | { | ||
2404 | kfree(ffs_func_from_usb(f)); | ||
2405 | } | ||
2406 | |||
2407 | static void ffs_func_unbind(struct usb_configuration *c, | ||
2408 | struct usb_function *f) | ||
2409 | { | ||
2410 | struct ffs_function *func = ffs_func_from_usb(f); | ||
2411 | struct ffs_data *ffs = func->ffs; | ||
2412 | struct f_fs_opts *opts = | ||
2413 | container_of(f->fi, struct f_fs_opts, func_inst); | ||
2414 | struct ffs_ep *ep = func->eps; | ||
2415 | unsigned count = ffs->eps_count; | ||
2416 | unsigned long flags; | ||
2417 | |||
2418 | ENTER(); | ||
2419 | if (ffs->func == func) { | ||
2420 | ffs_func_eps_disable(func); | ||
2421 | ffs->func = NULL; | ||
2422 | } | ||
2423 | |||
2424 | if (!--opts->refcnt) | ||
2425 | functionfs_unbind(ffs); | ||
2426 | |||
2427 | /* cleanup after autoconfig */ | ||
2428 | spin_lock_irqsave(&func->ffs->eps_lock, flags); | ||
2429 | do { | ||
2430 | if (ep->ep && ep->req) | ||
2431 | usb_ep_free_request(ep->ep, ep->req); | ||
2432 | ep->req = NULL; | ||
2433 | ++ep; | ||
2434 | } while (--count); | ||
2435 | spin_unlock_irqrestore(&func->ffs->eps_lock, flags); | ||
2436 | kfree(func->eps); | ||
2437 | func->eps = NULL; | ||
2438 | /* | ||
2439 | * eps, descriptors and interfaces_nums are allocated in the | ||
2440 | * same chunk so only one free is required. | ||
2441 | */ | ||
2442 | func->function.fs_descriptors = NULL; | ||
2443 | func->function.hs_descriptors = NULL; | ||
2444 | func->interfaces_nums = NULL; | ||
2445 | |||
2446 | ffs_event_add(ffs, FUNCTIONFS_UNBIND); | ||
2447 | } | ||
2448 | |||
2449 | static struct usb_function *ffs_alloc(struct usb_function_instance *fi) | ||
2450 | { | ||
2451 | struct ffs_function *func; | ||
2452 | |||
2453 | ENTER(); | ||
2454 | |||
2455 | func = kzalloc(sizeof(*func), GFP_KERNEL); | ||
2456 | if (unlikely(!func)) | ||
2457 | return ERR_PTR(-ENOMEM); | ||
2458 | |||
2459 | func->function.name = "Function FS Gadget"; | ||
2460 | |||
2461 | func->function.bind = ffs_func_bind; | ||
2462 | func->function.unbind = ffs_func_unbind; | ||
2463 | func->function.set_alt = ffs_func_set_alt; | ||
2464 | func->function.disable = ffs_func_disable; | ||
2465 | func->function.setup = ffs_func_setup; | ||
2466 | func->function.suspend = ffs_func_suspend; | ||
2467 | func->function.resume = ffs_func_resume; | ||
2468 | func->function.free_func = ffs_free; | ||
2469 | |||
2470 | return &func->function; | ||
2471 | } | ||
2472 | |||
2473 | /* | ||
2474 | * ffs_lock must be taken by the caller of this function | ||
2475 | */ | ||
2476 | struct ffs_dev *ffs_alloc_dev(void) | ||
2477 | { | ||
2478 | struct ffs_dev *dev; | ||
2479 | int ret; | ||
2480 | |||
2481 | if (ffs_get_single_dev()) | ||
2482 | return ERR_PTR(-EBUSY); | ||
2483 | |||
2484 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
2485 | if (!dev) | ||
2486 | return ERR_PTR(-ENOMEM); | ||
2487 | |||
2488 | if (list_empty(&ffs_devices)) { | ||
2489 | ret = functionfs_init(); | ||
2490 | if (ret) { | ||
2491 | kfree(dev); | ||
2492 | return ERR_PTR(ret); | ||
2493 | } | ||
2494 | } | ||
2495 | |||
2496 | list_add(&dev->entry, &ffs_devices); | ||
2497 | |||
2498 | return dev; | ||
2499 | } | ||
2500 | |||
2501 | /* | ||
2502 | * ffs_lock must be taken by the caller of this function | ||
2503 | * The caller is responsible for "name" being available whenever f_fs needs it | ||
2504 | */ | ||
2505 | static int _ffs_name_dev(struct ffs_dev *dev, const char *name) | ||
2506 | { | ||
2507 | struct ffs_dev *existing; | ||
2508 | |||
2509 | existing = _ffs_find_dev(name); | ||
2510 | if (existing) | ||
2511 | return -EBUSY; | ||
2512 | |||
2513 | dev->name = name; | ||
2514 | |||
2515 | return 0; | ||
2516 | } | ||
2517 | |||
2518 | /* | ||
2519 | * The caller is responsible for "name" being available whenever f_fs needs it | ||
2520 | */ | ||
2521 | int ffs_name_dev(struct ffs_dev *dev, const char *name) | ||
2522 | { | ||
2523 | int ret; | ||
2524 | |||
2525 | ffs_dev_lock(); | ||
2526 | ret = _ffs_name_dev(dev, name); | ||
2527 | ffs_dev_unlock(); | ||
2528 | |||
2529 | return ret; | ||
2530 | } | ||
2531 | EXPORT_SYMBOL(ffs_name_dev); | ||
2532 | |||
2533 | int ffs_single_dev(struct ffs_dev *dev) | ||
2534 | { | ||
2535 | int ret; | ||
2536 | |||
2537 | ret = 0; | ||
2538 | ffs_dev_lock(); | ||
2539 | |||
2540 | if (!list_is_singular(&ffs_devices)) | ||
2541 | ret = -EBUSY; | ||
2542 | else | ||
2543 | dev->single = true; | ||
2544 | |||
2545 | ffs_dev_unlock(); | ||
2546 | return ret; | ||
2547 | } | ||
2548 | EXPORT_SYMBOL(ffs_single_dev); | ||
2549 | |||
2550 | /* | ||
2551 | * ffs_lock must be taken by the caller of this function | ||
2552 | */ | ||
2553 | void ffs_free_dev(struct ffs_dev *dev) | ||
2554 | { | ||
2555 | list_del(&dev->entry); | ||
2556 | if (dev->name_allocated) | ||
2557 | kfree(dev->name); | ||
2558 | kfree(dev); | ||
2559 | if (list_empty(&ffs_devices)) | ||
2560 | functionfs_cleanup(); | ||
2561 | } | ||
2562 | |||
2563 | static void *ffs_acquire_dev(const char *dev_name) | ||
2564 | { | ||
2565 | struct ffs_dev *ffs_dev; | ||
2566 | |||
2567 | ENTER(); | ||
2568 | ffs_dev_lock(); | ||
2569 | |||
2570 | ffs_dev = ffs_find_dev(dev_name); | ||
2571 | if (!ffs_dev) | ||
2572 | ffs_dev = ERR_PTR(-ENODEV); | ||
2573 | else if (ffs_dev->mounted) | ||
2574 | ffs_dev = ERR_PTR(-EBUSY); | ||
2575 | else if (ffs_dev->ffs_acquire_dev_callback && | ||
2576 | ffs_dev->ffs_acquire_dev_callback(ffs_dev)) | ||
2577 | ffs_dev = ERR_PTR(-ENODEV); | ||
2578 | else | ||
2579 | ffs_dev->mounted = true; | ||
2580 | |||
2581 | ffs_dev_unlock(); | ||
2582 | return ffs_dev; | ||
2583 | } | ||
2584 | |||
2585 | static void ffs_release_dev(struct ffs_data *ffs_data) | ||
2586 | { | ||
2587 | struct ffs_dev *ffs_dev; | ||
2588 | |||
2589 | ENTER(); | ||
2590 | ffs_dev_lock(); | ||
2591 | |||
2592 | ffs_dev = ffs_data->private_data; | ||
2593 | if (ffs_dev) | ||
2594 | ffs_dev->mounted = false; | ||
2595 | |||
2596 | if (ffs_dev->ffs_release_dev_callback) | ||
2597 | ffs_dev->ffs_release_dev_callback(ffs_dev); | ||
2598 | |||
2599 | ffs_dev_unlock(); | ||
2600 | } | ||
2601 | |||
2602 | static int ffs_ready(struct ffs_data *ffs) | ||
2603 | { | ||
2604 | struct ffs_dev *ffs_obj; | ||
2605 | int ret = 0; | ||
2606 | |||
2607 | ENTER(); | ||
2608 | ffs_dev_lock(); | ||
2609 | |||
2610 | ffs_obj = ffs->private_data; | ||
2611 | if (!ffs_obj) { | ||
2612 | ret = -EINVAL; | ||
2613 | goto done; | ||
2614 | } | ||
2615 | if (WARN_ON(ffs_obj->desc_ready)) { | ||
2616 | ret = -EBUSY; | ||
2617 | goto done; | ||
2618 | } | ||
2619 | |||
2620 | ffs_obj->desc_ready = true; | ||
2621 | ffs_obj->ffs_data = ffs; | ||
2622 | |||
2623 | if (ffs_obj->ffs_ready_callback) | ||
2624 | ret = ffs_obj->ffs_ready_callback(ffs); | ||
2625 | |||
2626 | done: | ||
2627 | ffs_dev_unlock(); | ||
2628 | return ret; | ||
2629 | } | ||
2630 | |||
2631 | static void ffs_closed(struct ffs_data *ffs) | ||
2632 | { | ||
2633 | struct ffs_dev *ffs_obj; | ||
2634 | |||
2635 | ENTER(); | ||
2636 | ffs_dev_lock(); | ||
2637 | |||
2638 | ffs_obj = ffs->private_data; | ||
2639 | if (!ffs_obj) | ||
2640 | goto done; | ||
2641 | |||
2642 | ffs_obj->desc_ready = false; | ||
2643 | |||
2644 | if (ffs_obj->ffs_closed_callback) | ||
2645 | ffs_obj->ffs_closed_callback(ffs); | ||
2646 | |||
2647 | if (!ffs_obj->opts || ffs_obj->opts->no_configfs | ||
2648 | || !ffs_obj->opts->func_inst.group.cg_item.ci_parent) | ||
2649 | goto done; | ||
2650 | |||
2651 | unregister_gadget_item(ffs_obj->opts-> | ||
2652 | func_inst.group.cg_item.ci_parent->ci_parent); | ||
2653 | done: | ||
2654 | ffs_dev_unlock(); | ||
2655 | } | ||
2656 | |||
2431 | /* Misc helper functions ****************************************************/ | 2657 | /* Misc helper functions ****************************************************/ |
2432 | 2658 | ||
2433 | static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) | 2659 | static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) |
@@ -2458,3 +2684,7 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len) | |||
2458 | 2684 | ||
2459 | return data; | 2685 | return data; |
2460 | } | 2686 | } |
2687 | |||
2688 | DECLARE_USB_FUNCTION_INIT(ffs, ffs_alloc_inst, ffs_alloc); | ||
2689 | MODULE_LICENSE("GPL"); | ||
2690 | MODULE_AUTHOR("Michal Nazarewicz"); | ||
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c index 6e69a8e8d22a..a95290a1289f 100644 --- a/drivers/usb/gadget/f_hid.c +++ b/drivers/usb/gadget/f_hid.c | |||
@@ -20,6 +20,8 @@ | |||
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/usb/g_hid.h> | 21 | #include <linux/usb/g_hid.h> |
22 | 22 | ||
23 | #include "u_f.h" | ||
24 | |||
23 | static int major, minors; | 25 | static int major, minors; |
24 | static struct class *hidg_class; | 26 | static struct class *hidg_class; |
25 | 27 | ||
@@ -334,20 +336,10 @@ static int f_hidg_open(struct inode *inode, struct file *fd) | |||
334 | /*-------------------------------------------------------------------------*/ | 336 | /*-------------------------------------------------------------------------*/ |
335 | /* usb_function */ | 337 | /* usb_function */ |
336 | 338 | ||
337 | static struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, unsigned length) | 339 | static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep, |
340 | unsigned length) | ||
338 | { | 341 | { |
339 | struct usb_request *req; | 342 | return alloc_ep_req(ep, length, length); |
340 | |||
341 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
342 | if (req) { | ||
343 | req->length = length; | ||
344 | req->buf = kmalloc(length, GFP_ATOMIC); | ||
345 | if (!req->buf) { | ||
346 | usb_ep_free_request(ep, req); | ||
347 | req = NULL; | ||
348 | } | ||
349 | } | ||
350 | return req; | ||
351 | } | 343 | } |
352 | 344 | ||
353 | static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req) | 345 | static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req) |
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index 4a3873a0f2d0..4557cd03f0b1 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/usb/composite.h> | 20 | #include <linux/usb/composite.h> |
21 | 21 | ||
22 | #include "g_zero.h" | 22 | #include "g_zero.h" |
23 | #include "u_f.h" | ||
23 | 24 | ||
24 | /* | 25 | /* |
25 | * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, | 26 | * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, |
@@ -119,7 +120,7 @@ static struct usb_endpoint_descriptor ss_loop_source_desc = { | |||
119 | .wMaxPacketSize = cpu_to_le16(1024), | 120 | .wMaxPacketSize = cpu_to_le16(1024), |
120 | }; | 121 | }; |
121 | 122 | ||
122 | struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = { | 123 | static struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = { |
123 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 124 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
124 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 125 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
125 | .bMaxBurst = 0, | 126 | .bMaxBurst = 0, |
@@ -135,7 +136,7 @@ static struct usb_endpoint_descriptor ss_loop_sink_desc = { | |||
135 | .wMaxPacketSize = cpu_to_le16(1024), | 136 | .wMaxPacketSize = cpu_to_le16(1024), |
136 | }; | 137 | }; |
137 | 138 | ||
138 | struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = { | 139 | static struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = { |
139 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 140 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
140 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 141 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
141 | .bMaxBurst = 0, | 142 | .bMaxBurst = 0, |
@@ -230,6 +231,14 @@ autoconf_fail: | |||
230 | 231 | ||
231 | static void lb_free_func(struct usb_function *f) | 232 | static void lb_free_func(struct usb_function *f) |
232 | { | 233 | { |
234 | struct f_lb_opts *opts; | ||
235 | |||
236 | opts = container_of(f->fi, struct f_lb_opts, func_inst); | ||
237 | |||
238 | mutex_lock(&opts->lock); | ||
239 | opts->refcnt--; | ||
240 | mutex_unlock(&opts->lock); | ||
241 | |||
233 | usb_free_all_descriptors(f); | 242 | usb_free_all_descriptors(f); |
234 | kfree(func_to_loop(f)); | 243 | kfree(func_to_loop(f)); |
235 | } | 244 | } |
@@ -293,6 +302,11 @@ static void disable_loopback(struct f_loopback *loop) | |||
293 | VDBG(cdev, "%s disabled\n", loop->function.name); | 302 | VDBG(cdev, "%s disabled\n", loop->function.name); |
294 | } | 303 | } |
295 | 304 | ||
305 | static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len) | ||
306 | { | ||
307 | return alloc_ep_req(ep, len, buflen); | ||
308 | } | ||
309 | |||
296 | static int | 310 | static int |
297 | enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) | 311 | enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) |
298 | { | 312 | { |
@@ -332,7 +346,7 @@ fail0: | |||
332 | * than 'buflen' bytes each. | 346 | * than 'buflen' bytes each. |
333 | */ | 347 | */ |
334 | for (i = 0; i < qlen && result == 0; i++) { | 348 | for (i = 0; i < qlen && result == 0; i++) { |
335 | req = alloc_ep_req(ep, 0); | 349 | req = lb_alloc_ep_req(ep, 0); |
336 | if (req) { | 350 | if (req) { |
337 | req->complete = loopback_complete; | 351 | req->complete = loopback_complete; |
338 | result = usb_ep_queue(ep, req, GFP_ATOMIC); | 352 | result = usb_ep_queue(ep, req, GFP_ATOMIC); |
@@ -380,6 +394,11 @@ static struct usb_function *loopback_alloc(struct usb_function_instance *fi) | |||
380 | return ERR_PTR(-ENOMEM); | 394 | return ERR_PTR(-ENOMEM); |
381 | 395 | ||
382 | lb_opts = container_of(fi, struct f_lb_opts, func_inst); | 396 | lb_opts = container_of(fi, struct f_lb_opts, func_inst); |
397 | |||
398 | mutex_lock(&lb_opts->lock); | ||
399 | lb_opts->refcnt++; | ||
400 | mutex_unlock(&lb_opts->lock); | ||
401 | |||
383 | buflen = lb_opts->bulk_buflen; | 402 | buflen = lb_opts->bulk_buflen; |
384 | qlen = lb_opts->qlen; | 403 | qlen = lb_opts->qlen; |
385 | if (!qlen) | 404 | if (!qlen) |
@@ -396,6 +415,118 @@ static struct usb_function *loopback_alloc(struct usb_function_instance *fi) | |||
396 | return &loop->function; | 415 | return &loop->function; |
397 | } | 416 | } |
398 | 417 | ||
418 | static inline struct f_lb_opts *to_f_lb_opts(struct config_item *item) | ||
419 | { | ||
420 | return container_of(to_config_group(item), struct f_lb_opts, | ||
421 | func_inst.group); | ||
422 | } | ||
423 | |||
424 | CONFIGFS_ATTR_STRUCT(f_lb_opts); | ||
425 | CONFIGFS_ATTR_OPS(f_lb_opts); | ||
426 | |||
427 | static void lb_attr_release(struct config_item *item) | ||
428 | { | ||
429 | struct f_lb_opts *lb_opts = to_f_lb_opts(item); | ||
430 | |||
431 | usb_put_function_instance(&lb_opts->func_inst); | ||
432 | } | ||
433 | |||
434 | static struct configfs_item_operations lb_item_ops = { | ||
435 | .release = lb_attr_release, | ||
436 | .show_attribute = f_lb_opts_attr_show, | ||
437 | .store_attribute = f_lb_opts_attr_store, | ||
438 | }; | ||
439 | |||
440 | static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page) | ||
441 | { | ||
442 | int result; | ||
443 | |||
444 | mutex_lock(&opts->lock); | ||
445 | result = sprintf(page, "%d", opts->qlen); | ||
446 | mutex_unlock(&opts->lock); | ||
447 | |||
448 | return result; | ||
449 | } | ||
450 | |||
451 | static ssize_t f_lb_opts_qlen_store(struct f_lb_opts *opts, | ||
452 | const char *page, size_t len) | ||
453 | { | ||
454 | int ret; | ||
455 | u32 num; | ||
456 | |||
457 | mutex_lock(&opts->lock); | ||
458 | if (opts->refcnt) { | ||
459 | ret = -EBUSY; | ||
460 | goto end; | ||
461 | } | ||
462 | |||
463 | ret = kstrtou32(page, 0, &num); | ||
464 | if (ret) | ||
465 | goto end; | ||
466 | |||
467 | opts->qlen = num; | ||
468 | ret = len; | ||
469 | end: | ||
470 | mutex_unlock(&opts->lock); | ||
471 | return ret; | ||
472 | } | ||
473 | |||
474 | static struct f_lb_opts_attribute f_lb_opts_qlen = | ||
475 | __CONFIGFS_ATTR(qlen, S_IRUGO | S_IWUSR, | ||
476 | f_lb_opts_qlen_show, | ||
477 | f_lb_opts_qlen_store); | ||
478 | |||
479 | static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page) | ||
480 | { | ||
481 | int result; | ||
482 | |||
483 | mutex_lock(&opts->lock); | ||
484 | result = sprintf(page, "%d", opts->bulk_buflen); | ||
485 | mutex_unlock(&opts->lock); | ||
486 | |||
487 | return result; | ||
488 | } | ||
489 | |||
490 | static ssize_t f_lb_opts_bulk_buflen_store(struct f_lb_opts *opts, | ||
491 | const char *page, size_t len) | ||
492 | { | ||
493 | int ret; | ||
494 | u32 num; | ||
495 | |||
496 | mutex_lock(&opts->lock); | ||
497 | if (opts->refcnt) { | ||
498 | ret = -EBUSY; | ||
499 | goto end; | ||
500 | } | ||
501 | |||
502 | ret = kstrtou32(page, 0, &num); | ||
503 | if (ret) | ||
504 | goto end; | ||
505 | |||
506 | opts->bulk_buflen = num; | ||
507 | ret = len; | ||
508 | end: | ||
509 | mutex_unlock(&opts->lock); | ||
510 | return ret; | ||
511 | } | ||
512 | |||
513 | static struct f_lb_opts_attribute f_lb_opts_bulk_buflen = | ||
514 | __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR, | ||
515 | f_lb_opts_bulk_buflen_show, | ||
516 | f_lb_opts_bulk_buflen_store); | ||
517 | |||
518 | static struct configfs_attribute *lb_attrs[] = { | ||
519 | &f_lb_opts_qlen.attr, | ||
520 | &f_lb_opts_bulk_buflen.attr, | ||
521 | NULL, | ||
522 | }; | ||
523 | |||
524 | static struct config_item_type lb_func_type = { | ||
525 | .ct_item_ops = &lb_item_ops, | ||
526 | .ct_attrs = lb_attrs, | ||
527 | .ct_owner = THIS_MODULE, | ||
528 | }; | ||
529 | |||
399 | static void lb_free_instance(struct usb_function_instance *fi) | 530 | static void lb_free_instance(struct usb_function_instance *fi) |
400 | { | 531 | { |
401 | struct f_lb_opts *lb_opts; | 532 | struct f_lb_opts *lb_opts; |
@@ -411,7 +542,14 @@ static struct usb_function_instance *loopback_alloc_instance(void) | |||
411 | lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); | 542 | lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); |
412 | if (!lb_opts) | 543 | if (!lb_opts) |
413 | return ERR_PTR(-ENOMEM); | 544 | return ERR_PTR(-ENOMEM); |
545 | mutex_init(&lb_opts->lock); | ||
414 | lb_opts->func_inst.free_func_inst = lb_free_instance; | 546 | lb_opts->func_inst.free_func_inst = lb_free_instance; |
547 | lb_opts->bulk_buflen = GZERO_BULK_BUFLEN; | ||
548 | lb_opts->qlen = GZERO_QLEN; | ||
549 | |||
550 | config_group_init_type_name(&lb_opts->func_inst.group, "", | ||
551 | &lb_func_type); | ||
552 | |||
415 | return &lb_opts->func_inst; | 553 | return &lb_opts->func_inst; |
416 | } | 554 | } |
417 | DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc); | 555 | DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc); |
diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c index 263e721c2694..36d4bb23087f 100644 --- a/drivers/usb/gadget/f_midi.c +++ b/drivers/usb/gadget/f_midi.c | |||
@@ -32,6 +32,8 @@ | |||
32 | #include <linux/usb/audio.h> | 32 | #include <linux/usb/audio.h> |
33 | #include <linux/usb/midi.h> | 33 | #include <linux/usb/midi.h> |
34 | 34 | ||
35 | #include "u_f.h" | ||
36 | |||
35 | MODULE_AUTHOR("Ben Williamson"); | 37 | MODULE_AUTHOR("Ben Williamson"); |
36 | MODULE_LICENSE("GPL v2"); | 38 | MODULE_LICENSE("GPL v2"); |
37 | 39 | ||
@@ -191,20 +193,10 @@ static struct usb_gadget_strings *midi_strings[] = { | |||
191 | NULL, | 193 | NULL, |
192 | }; | 194 | }; |
193 | 195 | ||
194 | static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) | 196 | static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep, |
197 | unsigned length) | ||
195 | { | 198 | { |
196 | struct usb_request *req; | 199 | return alloc_ep_req(ep, length, length); |
197 | |||
198 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
199 | if (req) { | ||
200 | req->length = length; | ||
201 | req->buf = kmalloc(length, GFP_ATOMIC); | ||
202 | if (!req->buf) { | ||
203 | usb_ep_free_request(ep, req); | ||
204 | req = NULL; | ||
205 | } | ||
206 | } | ||
207 | return req; | ||
208 | } | 200 | } |
209 | 201 | ||
210 | static void free_ep_req(struct usb_ep *ep, struct usb_request *req) | 202 | static void free_ep_req(struct usb_ep *ep, struct usb_request *req) |
@@ -365,7 +357,7 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
365 | /* allocate a bunch of read buffers and queue them all at once. */ | 357 | /* allocate a bunch of read buffers and queue them all at once. */ |
366 | for (i = 0; i < midi->qlen && err == 0; i++) { | 358 | for (i = 0; i < midi->qlen && err == 0; i++) { |
367 | struct usb_request *req = | 359 | struct usb_request *req = |
368 | alloc_ep_req(midi->out_ep, midi->buflen); | 360 | midi_alloc_ep_req(midi->out_ep, midi->buflen); |
369 | if (req == NULL) | 361 | if (req == NULL) |
370 | return -ENOMEM; | 362 | return -ENOMEM; |
371 | 363 | ||
@@ -546,7 +538,7 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req) | |||
546 | return; | 538 | return; |
547 | 539 | ||
548 | if (!req) | 540 | if (!req) |
549 | req = alloc_ep_req(ep, midi->buflen); | 541 | req = midi_alloc_ep_req(ep, midi->buflen); |
550 | 542 | ||
551 | if (!req) { | 543 | if (!req) { |
552 | ERROR(midi, "gmidi_transmit: alloc_ep_request failed\n"); | 544 | ERROR(midi, "gmidi_transmit: alloc_ep_request failed\n"); |
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c index 1c28fe13328a..a9499fd30792 100644 --- a/drivers/usb/gadget/f_ncm.c +++ b/drivers/usb/gadget/f_ncm.c | |||
@@ -1386,7 +1386,7 @@ static void ncm_unbind(struct usb_configuration *c, struct usb_function *f) | |||
1386 | usb_ep_free_request(ncm->notify, ncm->notify_req); | 1386 | usb_ep_free_request(ncm->notify, ncm->notify_req); |
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | struct usb_function *ncm_alloc(struct usb_function_instance *fi) | 1389 | static struct usb_function *ncm_alloc(struct usb_function_instance *fi) |
1390 | { | 1390 | { |
1391 | struct f_ncm *ncm; | 1391 | struct f_ncm *ncm; |
1392 | struct f_ncm_opts *opts; | 1392 | struct f_ncm_opts *opts; |
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c index ad39f1dacba3..aebae1853bce 100644 --- a/drivers/usb/gadget/f_obex.c +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -499,7 +499,7 @@ static void obex_unbind(struct usb_configuration *c, struct usb_function *f) | |||
499 | usb_free_all_descriptors(f); | 499 | usb_free_all_descriptors(f); |
500 | } | 500 | } |
501 | 501 | ||
502 | struct usb_function *obex_alloc(struct usb_function_instance *fi) | 502 | static struct usb_function *obex_alloc(struct usb_function_instance *fi) |
503 | { | 503 | { |
504 | struct f_obex *obex; | 504 | struct f_obex *obex; |
505 | struct f_serial_opts *opts; | 505 | struct f_serial_opts *opts; |
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c index eb3aa817a662..f2b781773eed 100644 --- a/drivers/usb/gadget/f_phonet.c +++ b/drivers/usb/gadget/f_phonet.c | |||
@@ -689,7 +689,7 @@ static void pn_unbind(struct usb_configuration *c, struct usb_function *f) | |||
689 | usb_free_all_descriptors(f); | 689 | usb_free_all_descriptors(f); |
690 | } | 690 | } |
691 | 691 | ||
692 | struct usb_function *phonet_alloc(struct usb_function_instance *fi) | 692 | static struct usb_function *phonet_alloc(struct usb_function_instance *fi) |
693 | { | 693 | { |
694 | struct f_phonet *fp; | 694 | struct f_phonet *fp; |
695 | struct f_phonet_opts *opts; | 695 | struct f_phonet_opts *opts; |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 717ed7f95639..c11761ce5113 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -675,7 +675,6 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
675 | int status; | 675 | int status; |
676 | struct usb_ep *ep; | 676 | struct usb_ep *ep; |
677 | 677 | ||
678 | #ifndef USB_FRNDIS_INCLUDED | ||
679 | struct f_rndis_opts *rndis_opts; | 678 | struct f_rndis_opts *rndis_opts; |
680 | 679 | ||
681 | if (!can_support_rndis(c)) | 680 | if (!can_support_rndis(c)) |
@@ -697,7 +696,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
697 | return status; | 696 | return status; |
698 | rndis_opts->bound = true; | 697 | rndis_opts->bound = true; |
699 | } | 698 | } |
700 | #endif | 699 | |
701 | us = usb_gstrings_attach(cdev, rndis_strings, | 700 | us = usb_gstrings_attach(cdev, rndis_strings, |
702 | ARRAY_SIZE(rndis_string_defs)); | 701 | ARRAY_SIZE(rndis_string_defs)); |
703 | if (IS_ERR(us)) | 702 | if (IS_ERR(us)) |
@@ -782,13 +781,6 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
782 | rndis->port.open = rndis_open; | 781 | rndis->port.open = rndis_open; |
783 | rndis->port.close = rndis_close; | 782 | rndis->port.close = rndis_close; |
784 | 783 | ||
785 | #ifdef USB_FRNDIS_INCLUDED | ||
786 | status = rndis_register(rndis_response_available, rndis); | ||
787 | if (status < 0) | ||
788 | goto fail; | ||
789 | rndis->config = status; | ||
790 | #endif | ||
791 | |||
792 | rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); | 784 | rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); |
793 | rndis_set_host_mac(rndis->config, rndis->ethaddr); | 785 | rndis_set_host_mac(rndis->config, rndis->ethaddr); |
794 | 786 | ||
@@ -830,66 +822,6 @@ fail: | |||
830 | return status; | 822 | return status; |
831 | } | 823 | } |
832 | 824 | ||
833 | #ifdef USB_FRNDIS_INCLUDED | ||
834 | |||
835 | static void | ||
836 | rndis_old_unbind(struct usb_configuration *c, struct usb_function *f) | ||
837 | { | ||
838 | struct f_rndis *rndis = func_to_rndis(f); | ||
839 | |||
840 | rndis_deregister(rndis->config); | ||
841 | |||
842 | usb_free_all_descriptors(f); | ||
843 | |||
844 | kfree(rndis->notify_req->buf); | ||
845 | usb_ep_free_request(rndis->notify, rndis->notify_req); | ||
846 | |||
847 | kfree(rndis); | ||
848 | } | ||
849 | |||
850 | int | ||
851 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
852 | u32 vendorID, const char *manufacturer, struct eth_dev *dev) | ||
853 | { | ||
854 | struct f_rndis *rndis; | ||
855 | int status; | ||
856 | |||
857 | /* allocate and initialize one new instance */ | ||
858 | status = -ENOMEM; | ||
859 | rndis = kzalloc(sizeof *rndis, GFP_KERNEL); | ||
860 | if (!rndis) | ||
861 | goto fail; | ||
862 | |||
863 | memcpy(rndis->ethaddr, ethaddr, ETH_ALEN); | ||
864 | rndis->vendorID = vendorID; | ||
865 | rndis->manufacturer = manufacturer; | ||
866 | |||
867 | rndis->port.ioport = dev; | ||
868 | /* RNDIS activates when the host changes this filter */ | ||
869 | rndis->port.cdc_filter = 0; | ||
870 | |||
871 | /* RNDIS has special (and complex) framing */ | ||
872 | rndis->port.header_len = sizeof(struct rndis_packet_msg_type); | ||
873 | rndis->port.wrap = rndis_add_header; | ||
874 | rndis->port.unwrap = rndis_rm_hdr; | ||
875 | |||
876 | rndis->port.func.name = "rndis"; | ||
877 | /* descriptors are per-instance copies */ | ||
878 | rndis->port.func.bind = rndis_bind; | ||
879 | rndis->port.func.unbind = rndis_old_unbind; | ||
880 | rndis->port.func.set_alt = rndis_set_alt; | ||
881 | rndis->port.func.setup = rndis_setup; | ||
882 | rndis->port.func.disable = rndis_disable; | ||
883 | |||
884 | status = usb_add_function(c, &rndis->port.func); | ||
885 | if (status) | ||
886 | kfree(rndis); | ||
887 | fail: | ||
888 | return status; | ||
889 | } | ||
890 | |||
891 | #else | ||
892 | |||
893 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net) | 825 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net) |
894 | { | 826 | { |
895 | struct f_rndis_opts *opts; | 827 | struct f_rndis_opts *opts; |
@@ -1047,8 +979,26 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi) | |||
1047 | return &rndis->port.func; | 979 | return &rndis->port.func; |
1048 | } | 980 | } |
1049 | 981 | ||
1050 | DECLARE_USB_FUNCTION_INIT(rndis, rndis_alloc_inst, rndis_alloc); | 982 | DECLARE_USB_FUNCTION(rndis, rndis_alloc_inst, rndis_alloc); |
983 | |||
984 | static int __init rndis_mod_init(void) | ||
985 | { | ||
986 | int ret; | ||
987 | |||
988 | ret = rndis_init(); | ||
989 | if (ret) | ||
990 | return ret; | ||
991 | |||
992 | return usb_function_register(&rndisusb_func); | ||
993 | } | ||
994 | module_init(rndis_mod_init); | ||
995 | |||
996 | static void __exit rndis_mod_exit(void) | ||
997 | { | ||
998 | usb_function_unregister(&rndisusb_func); | ||
999 | rndis_exit(); | ||
1000 | } | ||
1001 | module_exit(rndis_mod_exit); | ||
1002 | |||
1051 | MODULE_LICENSE("GPL"); | 1003 | MODULE_LICENSE("GPL"); |
1052 | MODULE_AUTHOR("David Brownell"); | 1004 | MODULE_AUTHOR("David Brownell"); |
1053 | |||
1054 | #endif | ||
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c index 981113c9924d..9ecbcbf36a45 100644 --- a/drivers/usb/gadget/f_serial.c +++ b/drivers/usb/gadget/f_serial.c | |||
@@ -354,7 +354,7 @@ static void gser_unbind(struct usb_configuration *c, struct usb_function *f) | |||
354 | usb_free_all_descriptors(f); | 354 | usb_free_all_descriptors(f); |
355 | } | 355 | } |
356 | 356 | ||
357 | struct usb_function *gser_alloc(struct usb_function_instance *fi) | 357 | static struct usb_function *gser_alloc(struct usb_function_instance *fi) |
358 | { | 358 | { |
359 | struct f_gser *gser; | 359 | struct f_gser *gser; |
360 | struct f_serial_opts *opts; | 360 | struct f_serial_opts *opts; |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index a8895859a221..d3cd52db78fe 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "g_zero.h" | 22 | #include "g_zero.h" |
23 | #include "gadget_chips.h" | 23 | #include "gadget_chips.h" |
24 | #include "u_f.h" | ||
24 | 25 | ||
25 | /* | 26 | /* |
26 | * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral | 27 | * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral |
@@ -201,7 +202,7 @@ static struct usb_endpoint_descriptor ss_source_desc = { | |||
201 | .wMaxPacketSize = cpu_to_le16(1024), | 202 | .wMaxPacketSize = cpu_to_le16(1024), |
202 | }; | 203 | }; |
203 | 204 | ||
204 | struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { | 205 | static struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { |
205 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 206 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
206 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 207 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
207 | 208 | ||
@@ -218,7 +219,7 @@ static struct usb_endpoint_descriptor ss_sink_desc = { | |||
218 | .wMaxPacketSize = cpu_to_le16(1024), | 219 | .wMaxPacketSize = cpu_to_le16(1024), |
219 | }; | 220 | }; |
220 | 221 | ||
221 | struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { | 222 | static struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { |
222 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 223 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
223 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 224 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
224 | 225 | ||
@@ -236,7 +237,7 @@ static struct usb_endpoint_descriptor ss_iso_source_desc = { | |||
236 | .bInterval = 4, | 237 | .bInterval = 4, |
237 | }; | 238 | }; |
238 | 239 | ||
239 | struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = { | 240 | static struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = { |
240 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 241 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
241 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 242 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
242 | 243 | ||
@@ -254,7 +255,7 @@ static struct usb_endpoint_descriptor ss_iso_sink_desc = { | |||
254 | .bInterval = 4, | 255 | .bInterval = 4, |
255 | }; | 256 | }; |
256 | 257 | ||
257 | struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { | 258 | static struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { |
258 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 259 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
259 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 260 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
260 | 261 | ||
@@ -301,23 +302,9 @@ static struct usb_gadget_strings *sourcesink_strings[] = { | |||
301 | 302 | ||
302 | /*-------------------------------------------------------------------------*/ | 303 | /*-------------------------------------------------------------------------*/ |
303 | 304 | ||
304 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len) | 305 | static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len) |
305 | { | 306 | { |
306 | struct usb_request *req; | 307 | return alloc_ep_req(ep, len, buflen); |
307 | |||
308 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
309 | if (req) { | ||
310 | if (len) | ||
311 | req->length = len; | ||
312 | else | ||
313 | req->length = buflen; | ||
314 | req->buf = kmalloc(req->length, GFP_ATOMIC); | ||
315 | if (!req->buf) { | ||
316 | usb_ep_free_request(ep, req); | ||
317 | req = NULL; | ||
318 | } | ||
319 | } | ||
320 | return req; | ||
321 | } | 308 | } |
322 | 309 | ||
323 | void free_ep_req(struct usb_ep *ep, struct usb_request *req) | 310 | void free_ep_req(struct usb_ep *ep, struct usb_request *req) |
@@ -490,6 +477,14 @@ no_iso: | |||
490 | static void | 477 | static void |
491 | sourcesink_free_func(struct usb_function *f) | 478 | sourcesink_free_func(struct usb_function *f) |
492 | { | 479 | { |
480 | struct f_ss_opts *opts; | ||
481 | |||
482 | opts = container_of(f->fi, struct f_ss_opts, func_inst); | ||
483 | |||
484 | mutex_lock(&opts->lock); | ||
485 | opts->refcnt--; | ||
486 | mutex_unlock(&opts->lock); | ||
487 | |||
493 | usb_free_all_descriptors(f); | 488 | usb_free_all_descriptors(f); |
494 | kfree(func_to_ss(f)); | 489 | kfree(func_to_ss(f)); |
495 | } | 490 | } |
@@ -628,10 +623,10 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, | |||
628 | break; | 623 | break; |
629 | } | 624 | } |
630 | ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; | 625 | ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; |
631 | req = alloc_ep_req(ep, size); | 626 | req = ss_alloc_ep_req(ep, size); |
632 | } else { | 627 | } else { |
633 | ep = is_in ? ss->in_ep : ss->out_ep; | 628 | ep = is_in ? ss->in_ep : ss->out_ep; |
634 | req = alloc_ep_req(ep, 0); | 629 | req = ss_alloc_ep_req(ep, 0); |
635 | } | 630 | } |
636 | 631 | ||
637 | if (!req) | 632 | if (!req) |
@@ -878,6 +873,11 @@ static struct usb_function *source_sink_alloc_func( | |||
878 | return NULL; | 873 | return NULL; |
879 | 874 | ||
880 | ss_opts = container_of(fi, struct f_ss_opts, func_inst); | 875 | ss_opts = container_of(fi, struct f_ss_opts, func_inst); |
876 | |||
877 | mutex_lock(&ss_opts->lock); | ||
878 | ss_opts->refcnt++; | ||
879 | mutex_unlock(&ss_opts->lock); | ||
880 | |||
881 | pattern = ss_opts->pattern; | 881 | pattern = ss_opts->pattern; |
882 | isoc_interval = ss_opts->isoc_interval; | 882 | isoc_interval = ss_opts->isoc_interval; |
883 | isoc_maxpacket = ss_opts->isoc_maxpacket; | 883 | isoc_maxpacket = ss_opts->isoc_maxpacket; |
@@ -898,6 +898,303 @@ static struct usb_function *source_sink_alloc_func( | |||
898 | return &ss->function; | 898 | return &ss->function; |
899 | } | 899 | } |
900 | 900 | ||
901 | static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item) | ||
902 | { | ||
903 | return container_of(to_config_group(item), struct f_ss_opts, | ||
904 | func_inst.group); | ||
905 | } | ||
906 | |||
907 | CONFIGFS_ATTR_STRUCT(f_ss_opts); | ||
908 | CONFIGFS_ATTR_OPS(f_ss_opts); | ||
909 | |||
910 | static void ss_attr_release(struct config_item *item) | ||
911 | { | ||
912 | struct f_ss_opts *ss_opts = to_f_ss_opts(item); | ||
913 | |||
914 | usb_put_function_instance(&ss_opts->func_inst); | ||
915 | } | ||
916 | |||
917 | static struct configfs_item_operations ss_item_ops = { | ||
918 | .release = ss_attr_release, | ||
919 | .show_attribute = f_ss_opts_attr_show, | ||
920 | .store_attribute = f_ss_opts_attr_store, | ||
921 | }; | ||
922 | |||
923 | static ssize_t f_ss_opts_pattern_show(struct f_ss_opts *opts, char *page) | ||
924 | { | ||
925 | int result; | ||
926 | |||
927 | mutex_lock(&opts->lock); | ||
928 | result = sprintf(page, "%d", opts->pattern); | ||
929 | mutex_unlock(&opts->lock); | ||
930 | |||
931 | return result; | ||
932 | } | ||
933 | |||
934 | static ssize_t f_ss_opts_pattern_store(struct f_ss_opts *opts, | ||
935 | const char *page, size_t len) | ||
936 | { | ||
937 | int ret; | ||
938 | u8 num; | ||
939 | |||
940 | mutex_lock(&opts->lock); | ||
941 | if (opts->refcnt) { | ||
942 | ret = -EBUSY; | ||
943 | goto end; | ||
944 | } | ||
945 | |||
946 | ret = kstrtou8(page, 0, &num); | ||
947 | if (ret) | ||
948 | goto end; | ||
949 | |||
950 | if (num != 0 && num != 1 && num != 2) { | ||
951 | ret = -EINVAL; | ||
952 | goto end; | ||
953 | } | ||
954 | |||
955 | opts->pattern = num; | ||
956 | ret = len; | ||
957 | end: | ||
958 | mutex_unlock(&opts->lock); | ||
959 | return ret; | ||
960 | } | ||
961 | |||
962 | static struct f_ss_opts_attribute f_ss_opts_pattern = | ||
963 | __CONFIGFS_ATTR(pattern, S_IRUGO | S_IWUSR, | ||
964 | f_ss_opts_pattern_show, | ||
965 | f_ss_opts_pattern_store); | ||
966 | |||
967 | static ssize_t f_ss_opts_isoc_interval_show(struct f_ss_opts *opts, char *page) | ||
968 | { | ||
969 | int result; | ||
970 | |||
971 | mutex_lock(&opts->lock); | ||
972 | result = sprintf(page, "%d", opts->isoc_interval); | ||
973 | mutex_unlock(&opts->lock); | ||
974 | |||
975 | return result; | ||
976 | } | ||
977 | |||
978 | static ssize_t f_ss_opts_isoc_interval_store(struct f_ss_opts *opts, | ||
979 | const char *page, size_t len) | ||
980 | { | ||
981 | int ret; | ||
982 | u8 num; | ||
983 | |||
984 | mutex_lock(&opts->lock); | ||
985 | if (opts->refcnt) { | ||
986 | ret = -EBUSY; | ||
987 | goto end; | ||
988 | } | ||
989 | |||
990 | ret = kstrtou8(page, 0, &num); | ||
991 | if (ret) | ||
992 | goto end; | ||
993 | |||
994 | if (num > 16) { | ||
995 | ret = -EINVAL; | ||
996 | goto end; | ||
997 | } | ||
998 | |||
999 | opts->isoc_interval = num; | ||
1000 | ret = len; | ||
1001 | end: | ||
1002 | mutex_unlock(&opts->lock); | ||
1003 | return ret; | ||
1004 | } | ||
1005 | |||
1006 | static struct f_ss_opts_attribute f_ss_opts_isoc_interval = | ||
1007 | __CONFIGFS_ATTR(isoc_interval, S_IRUGO | S_IWUSR, | ||
1008 | f_ss_opts_isoc_interval_show, | ||
1009 | f_ss_opts_isoc_interval_store); | ||
1010 | |||
1011 | static ssize_t f_ss_opts_isoc_maxpacket_show(struct f_ss_opts *opts, char *page) | ||
1012 | { | ||
1013 | int result; | ||
1014 | |||
1015 | mutex_lock(&opts->lock); | ||
1016 | result = sprintf(page, "%d", opts->isoc_maxpacket); | ||
1017 | mutex_unlock(&opts->lock); | ||
1018 | |||
1019 | return result; | ||
1020 | } | ||
1021 | |||
1022 | static ssize_t f_ss_opts_isoc_maxpacket_store(struct f_ss_opts *opts, | ||
1023 | const char *page, size_t len) | ||
1024 | { | ||
1025 | int ret; | ||
1026 | u16 num; | ||
1027 | |||
1028 | mutex_lock(&opts->lock); | ||
1029 | if (opts->refcnt) { | ||
1030 | ret = -EBUSY; | ||
1031 | goto end; | ||
1032 | } | ||
1033 | |||
1034 | ret = kstrtou16(page, 0, &num); | ||
1035 | if (ret) | ||
1036 | goto end; | ||
1037 | |||
1038 | if (num > 1024) { | ||
1039 | ret = -EINVAL; | ||
1040 | goto end; | ||
1041 | } | ||
1042 | |||
1043 | opts->isoc_maxpacket = num; | ||
1044 | ret = len; | ||
1045 | end: | ||
1046 | mutex_unlock(&opts->lock); | ||
1047 | return ret; | ||
1048 | } | ||
1049 | |||
1050 | static struct f_ss_opts_attribute f_ss_opts_isoc_maxpacket = | ||
1051 | __CONFIGFS_ATTR(isoc_maxpacket, S_IRUGO | S_IWUSR, | ||
1052 | f_ss_opts_isoc_maxpacket_show, | ||
1053 | f_ss_opts_isoc_maxpacket_store); | ||
1054 | |||
1055 | static ssize_t f_ss_opts_isoc_mult_show(struct f_ss_opts *opts, char *page) | ||
1056 | { | ||
1057 | int result; | ||
1058 | |||
1059 | mutex_lock(&opts->lock); | ||
1060 | result = sprintf(page, "%d", opts->isoc_mult); | ||
1061 | mutex_unlock(&opts->lock); | ||
1062 | |||
1063 | return result; | ||
1064 | } | ||
1065 | |||
1066 | static ssize_t f_ss_opts_isoc_mult_store(struct f_ss_opts *opts, | ||
1067 | const char *page, size_t len) | ||
1068 | { | ||
1069 | int ret; | ||
1070 | u8 num; | ||
1071 | |||
1072 | mutex_lock(&opts->lock); | ||
1073 | if (opts->refcnt) { | ||
1074 | ret = -EBUSY; | ||
1075 | goto end; | ||
1076 | } | ||
1077 | |||
1078 | ret = kstrtou8(page, 0, &num); | ||
1079 | if (ret) | ||
1080 | goto end; | ||
1081 | |||
1082 | if (num > 2) { | ||
1083 | ret = -EINVAL; | ||
1084 | goto end; | ||
1085 | } | ||
1086 | |||
1087 | opts->isoc_mult = num; | ||
1088 | ret = len; | ||
1089 | end: | ||
1090 | mutex_unlock(&opts->lock); | ||
1091 | return ret; | ||
1092 | } | ||
1093 | |||
1094 | static struct f_ss_opts_attribute f_ss_opts_isoc_mult = | ||
1095 | __CONFIGFS_ATTR(isoc_mult, S_IRUGO | S_IWUSR, | ||
1096 | f_ss_opts_isoc_mult_show, | ||
1097 | f_ss_opts_isoc_mult_store); | ||
1098 | |||
1099 | static ssize_t f_ss_opts_isoc_maxburst_show(struct f_ss_opts *opts, char *page) | ||
1100 | { | ||
1101 | int result; | ||
1102 | |||
1103 | mutex_lock(&opts->lock); | ||
1104 | result = sprintf(page, "%d", opts->isoc_maxburst); | ||
1105 | mutex_unlock(&opts->lock); | ||
1106 | |||
1107 | return result; | ||
1108 | } | ||
1109 | |||
1110 | static ssize_t f_ss_opts_isoc_maxburst_store(struct f_ss_opts *opts, | ||
1111 | const char *page, size_t len) | ||
1112 | { | ||
1113 | int ret; | ||
1114 | u8 num; | ||
1115 | |||
1116 | mutex_lock(&opts->lock); | ||
1117 | if (opts->refcnt) { | ||
1118 | ret = -EBUSY; | ||
1119 | goto end; | ||
1120 | } | ||
1121 | |||
1122 | ret = kstrtou8(page, 0, &num); | ||
1123 | if (ret) | ||
1124 | goto end; | ||
1125 | |||
1126 | if (num > 15) { | ||
1127 | ret = -EINVAL; | ||
1128 | goto end; | ||
1129 | } | ||
1130 | |||
1131 | opts->isoc_maxburst = num; | ||
1132 | ret = len; | ||
1133 | end: | ||
1134 | mutex_unlock(&opts->lock); | ||
1135 | return ret; | ||
1136 | } | ||
1137 | |||
1138 | static struct f_ss_opts_attribute f_ss_opts_isoc_maxburst = | ||
1139 | __CONFIGFS_ATTR(isoc_maxburst, S_IRUGO | S_IWUSR, | ||
1140 | f_ss_opts_isoc_maxburst_show, | ||
1141 | f_ss_opts_isoc_maxburst_store); | ||
1142 | |||
1143 | static ssize_t f_ss_opts_bulk_buflen_show(struct f_ss_opts *opts, char *page) | ||
1144 | { | ||
1145 | int result; | ||
1146 | |||
1147 | mutex_lock(&opts->lock); | ||
1148 | result = sprintf(page, "%d", opts->bulk_buflen); | ||
1149 | mutex_unlock(&opts->lock); | ||
1150 | |||
1151 | return result; | ||
1152 | } | ||
1153 | |||
1154 | static ssize_t f_ss_opts_bulk_buflen_store(struct f_ss_opts *opts, | ||
1155 | const char *page, size_t len) | ||
1156 | { | ||
1157 | int ret; | ||
1158 | u32 num; | ||
1159 | |||
1160 | mutex_lock(&opts->lock); | ||
1161 | if (opts->refcnt) { | ||
1162 | ret = -EBUSY; | ||
1163 | goto end; | ||
1164 | } | ||
1165 | |||
1166 | ret = kstrtou32(page, 0, &num); | ||
1167 | if (ret) | ||
1168 | goto end; | ||
1169 | |||
1170 | opts->bulk_buflen = num; | ||
1171 | ret = len; | ||
1172 | end: | ||
1173 | mutex_unlock(&opts->lock); | ||
1174 | return ret; | ||
1175 | } | ||
1176 | |||
1177 | static struct f_ss_opts_attribute f_ss_opts_bulk_buflen = | ||
1178 | __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR, | ||
1179 | f_ss_opts_bulk_buflen_show, | ||
1180 | f_ss_opts_bulk_buflen_store); | ||
1181 | |||
1182 | static struct configfs_attribute *ss_attrs[] = { | ||
1183 | &f_ss_opts_pattern.attr, | ||
1184 | &f_ss_opts_isoc_interval.attr, | ||
1185 | &f_ss_opts_isoc_maxpacket.attr, | ||
1186 | &f_ss_opts_isoc_mult.attr, | ||
1187 | &f_ss_opts_isoc_maxburst.attr, | ||
1188 | &f_ss_opts_bulk_buflen.attr, | ||
1189 | NULL, | ||
1190 | }; | ||
1191 | |||
1192 | static struct config_item_type ss_func_type = { | ||
1193 | .ct_item_ops = &ss_item_ops, | ||
1194 | .ct_attrs = ss_attrs, | ||
1195 | .ct_owner = THIS_MODULE, | ||
1196 | }; | ||
1197 | |||
901 | static void source_sink_free_instance(struct usb_function_instance *fi) | 1198 | static void source_sink_free_instance(struct usb_function_instance *fi) |
902 | { | 1199 | { |
903 | struct f_ss_opts *ss_opts; | 1200 | struct f_ss_opts *ss_opts; |
@@ -913,7 +1210,15 @@ static struct usb_function_instance *source_sink_alloc_inst(void) | |||
913 | ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); | 1210 | ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); |
914 | if (!ss_opts) | 1211 | if (!ss_opts) |
915 | return ERR_PTR(-ENOMEM); | 1212 | return ERR_PTR(-ENOMEM); |
1213 | mutex_init(&ss_opts->lock); | ||
916 | ss_opts->func_inst.free_func_inst = source_sink_free_instance; | 1214 | ss_opts->func_inst.free_func_inst = source_sink_free_instance; |
1215 | ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; | ||
1216 | ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; | ||
1217 | ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; | ||
1218 | |||
1219 | config_group_init_type_name(&ss_opts->func_inst.group, "", | ||
1220 | &ss_func_type); | ||
1221 | |||
917 | return &ss_opts->func_inst; | 1222 | return &ss_opts->func_inst; |
918 | } | 1223 | } |
919 | DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst, | 1224 | DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst, |
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c index 7c8674fa7e80..f1a59190ac9a 100644 --- a/drivers/usb/gadget/f_subset.c +++ b/drivers/usb/gadget/f_subset.c | |||
@@ -301,7 +301,6 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
301 | int status; | 301 | int status; |
302 | struct usb_ep *ep; | 302 | struct usb_ep *ep; |
303 | 303 | ||
304 | #ifndef USB_FSUBSET_INCLUDED | ||
305 | struct f_gether_opts *gether_opts; | 304 | struct f_gether_opts *gether_opts; |
306 | 305 | ||
307 | gether_opts = container_of(f->fi, struct f_gether_opts, func_inst); | 306 | gether_opts = container_of(f->fi, struct f_gether_opts, func_inst); |
@@ -322,7 +321,7 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
322 | return status; | 321 | return status; |
323 | gether_opts->bound = true; | 322 | gether_opts->bound = true; |
324 | } | 323 | } |
325 | #endif | 324 | |
326 | us = usb_gstrings_attach(cdev, geth_strings, | 325 | us = usb_gstrings_attach(cdev, geth_strings, |
327 | ARRAY_SIZE(geth_string_defs)); | 326 | ARRAY_SIZE(geth_string_defs)); |
328 | if (IS_ERR(us)) | 327 | if (IS_ERR(us)) |
@@ -393,61 +392,6 @@ fail: | |||
393 | return status; | 392 | return status; |
394 | } | 393 | } |
395 | 394 | ||
396 | #ifdef USB_FSUBSET_INCLUDED | ||
397 | |||
398 | static void | ||
399 | geth_old_unbind(struct usb_configuration *c, struct usb_function *f) | ||
400 | { | ||
401 | geth_string_defs[0].id = 0; | ||
402 | usb_free_all_descriptors(f); | ||
403 | kfree(func_to_geth(f)); | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * geth_bind_config - add CDC Subset network link to a configuration | ||
408 | * @c: the configuration to support the network link | ||
409 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
410 | * side of the link was recorded | ||
411 | * @dev: eth_dev structure | ||
412 | * Context: single threaded during gadget setup | ||
413 | * | ||
414 | * Returns zero on success, else negative errno. | ||
415 | * | ||
416 | * Caller must have called @gether_setup(). Caller is also responsible | ||
417 | * for calling @gether_cleanup() before module unload. | ||
418 | */ | ||
419 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
420 | struct eth_dev *dev) | ||
421 | { | ||
422 | struct f_gether *geth; | ||
423 | int status; | ||
424 | |||
425 | /* allocate and initialize one new instance */ | ||
426 | geth = kzalloc(sizeof *geth, GFP_KERNEL); | ||
427 | if (!geth) | ||
428 | return -ENOMEM; | ||
429 | |||
430 | /* export host's Ethernet address in CDC format */ | ||
431 | snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); | ||
432 | geth_string_defs[1].s = geth->ethaddr; | ||
433 | |||
434 | geth->port.ioport = dev; | ||
435 | geth->port.cdc_filter = DEFAULT_FILTER; | ||
436 | |||
437 | geth->port.func.name = "cdc_subset"; | ||
438 | geth->port.func.bind = geth_bind; | ||
439 | geth->port.func.unbind = geth_old_unbind; | ||
440 | geth->port.func.set_alt = geth_set_alt; | ||
441 | geth->port.func.disable = geth_disable; | ||
442 | |||
443 | status = usb_add_function(c, &geth->port.func); | ||
444 | if (status) | ||
445 | kfree(geth); | ||
446 | return status; | ||
447 | } | ||
448 | |||
449 | #else | ||
450 | |||
451 | static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item) | 395 | static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item) |
452 | { | 396 | { |
453 | return container_of(to_config_group(item), struct f_gether_opts, | 397 | return container_of(to_config_group(item), struct f_gether_opts, |
@@ -573,5 +517,3 @@ static struct usb_function *geth_alloc(struct usb_function_instance *fi) | |||
573 | DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc); | 517 | DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc); |
574 | MODULE_LICENSE("GPL"); | 518 | MODULE_LICENSE("GPL"); |
575 | MODULE_AUTHOR("David Brownell"); | 519 | MODULE_AUTHOR("David Brownell"); |
576 | |||
577 | #endif | ||
diff --git a/drivers/usb/gadget/fotg210-udc.c b/drivers/usb/gadget/fotg210-udc.c index bbbfd1948778..2d0305280e8c 100644 --- a/drivers/usb/gadget/fotg210-udc.c +++ b/drivers/usb/gadget/fotg210-udc.c | |||
@@ -1157,8 +1157,9 @@ static int fotg210_udc_probe(struct platform_device *pdev) | |||
1157 | INIT_LIST_HEAD(&ep->queue); | 1157 | INIT_LIST_HEAD(&ep->queue); |
1158 | ep->ep.name = fotg210_ep_name[i]; | 1158 | ep->ep.name = fotg210_ep_name[i]; |
1159 | ep->ep.ops = &fotg210_ep_ops; | 1159 | ep->ep.ops = &fotg210_ep_ops; |
1160 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); | ||
1160 | } | 1161 | } |
1161 | fotg210->ep[0]->ep.maxpacket = 0x40; | 1162 | usb_ep_set_maxpacket_limit(&fotg210->ep[0]->ep, 0x40); |
1162 | fotg210->gadget.ep0 = &fotg210->ep[0]->ep; | 1163 | fotg210->gadget.ep0 = &fotg210->ep[0]->ep; |
1163 | INIT_LIST_HEAD(&fotg210->gadget.ep0->ep_list); | 1164 | INIT_LIST_HEAD(&fotg210->gadget.ep0->ep_list); |
1164 | 1165 | ||
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index 807127d56fa3..ad5483335167 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -22,7 +22,6 @@ | |||
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/init.h> | ||
26 | #include <linux/ioport.h> | 25 | #include <linux/ioport.h> |
27 | #include <linux/types.h> | 26 | #include <linux/types.h> |
28 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
@@ -2429,7 +2428,7 @@ static int qe_ep_config(struct qe_udc *udc, unsigned char pipe_num) | |||
2429 | 2428 | ||
2430 | ep->ep.ops = &qe_ep_ops; | 2429 | ep->ep.ops = &qe_ep_ops; |
2431 | ep->stopped = 1; | 2430 | ep->stopped = 1; |
2432 | ep->ep.maxpacket = (unsigned short) ~0; | 2431 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
2433 | ep->ep.desc = NULL; | 2432 | ep->ep.desc = NULL; |
2434 | ep->dir = 0xff; | 2433 | ep->dir = 0xff; |
2435 | ep->epnum = (u8)pipe_num; | 2434 | ep->epnum = (u8)pipe_num; |
@@ -2717,7 +2716,7 @@ MODULE_DEVICE_TABLE(of, qe_udc_match); | |||
2717 | 2716 | ||
2718 | static struct platform_driver udc_driver = { | 2717 | static struct platform_driver udc_driver = { |
2719 | .driver = { | 2718 | .driver = { |
2720 | .name = (char *)driver_name, | 2719 | .name = driver_name, |
2721 | .owner = THIS_MODULE, | 2720 | .owner = THIS_MODULE, |
2722 | .of_match_table = qe_udc_match, | 2721 | .of_match_table = qe_udc_match, |
2723 | }, | 2722 | }, |
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index 36ac7cfba91d..15960af0f67e 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -2311,7 +2311,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index, | |||
2311 | /* for ep0: maxP defined in desc | 2311 | /* for ep0: maxP defined in desc |
2312 | * for other eps, maxP is set by epautoconfig() called by gadget layer | 2312 | * for other eps, maxP is set by epautoconfig() called by gadget layer |
2313 | */ | 2313 | */ |
2314 | ep->ep.maxpacket = (unsigned short) ~0; | 2314 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
2315 | 2315 | ||
2316 | /* the queue lists any req for this ep */ | 2316 | /* the queue lists any req for this ep */ |
2317 | INIT_LIST_HEAD(&ep->queue); | 2317 | INIT_LIST_HEAD(&ep->queue); |
@@ -2469,7 +2469,8 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2469 | * for other eps, gadget layer called ep_enable with defined desc | 2469 | * for other eps, gadget layer called ep_enable with defined desc |
2470 | */ | 2470 | */ |
2471 | udc_controller->eps[0].ep.desc = &fsl_ep0_desc; | 2471 | udc_controller->eps[0].ep.desc = &fsl_ep0_desc; |
2472 | udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD; | 2472 | usb_ep_set_maxpacket_limit(&udc_controller->eps[0].ep, |
2473 | USB_MAX_CTRL_PAYLOAD); | ||
2473 | 2474 | ||
2474 | /* setup the udc->eps[] for non-control endpoints and link | 2475 | /* setup the udc->eps[] for non-control endpoints and link |
2475 | * to gadget.ep_list */ | 2476 | * to gadget.ep_list */ |
@@ -2666,7 +2667,7 @@ static struct platform_driver udc_driver = { | |||
2666 | .suspend = fsl_udc_suspend, | 2667 | .suspend = fsl_udc_suspend, |
2667 | .resume = fsl_udc_resume, | 2668 | .resume = fsl_udc_resume, |
2668 | .driver = { | 2669 | .driver = { |
2669 | .name = (char *)driver_name, | 2670 | .name = driver_name, |
2670 | .owner = THIS_MODULE, | 2671 | .owner = THIS_MODULE, |
2671 | /* udc suspend/resume called from OTG driver */ | 2672 | /* udc suspend/resume called from OTG driver */ |
2672 | .suspend = fsl_udc_otg_suspend, | 2673 | .suspend = fsl_udc_otg_suspend, |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c index b278abe52453..6423f1840ed9 100644 --- a/drivers/usb/gadget/fusb300_udc.c +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -1452,9 +1452,9 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1452 | INIT_LIST_HEAD(&ep->queue); | 1452 | INIT_LIST_HEAD(&ep->queue); |
1453 | ep->ep.name = fusb300_ep_name[i]; | 1453 | ep->ep.name = fusb300_ep_name[i]; |
1454 | ep->ep.ops = &fusb300_ep_ops; | 1454 | ep->ep.ops = &fusb300_ep_ops; |
1455 | ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE; | 1455 | usb_ep_set_maxpacket_limit(&ep->ep, HS_BULK_MAX_PACKET_SIZE); |
1456 | } | 1456 | } |
1457 | fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE; | 1457 | usb_ep_set_maxpacket_limit(&fusb300->ep[0]->ep, HS_CTL_MAX_PACKET_SIZE); |
1458 | fusb300->ep[0]->epnum = 0; | 1458 | fusb300->ep[0]->epnum = 0; |
1459 | fusb300->gadget.ep0 = &fusb300->ep[0]->ep; | 1459 | fusb300->gadget.ep0 = &fusb300->ep[0]->ep; |
1460 | INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list); | 1460 | INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list); |
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 2344efe4f4ce..fe12e6a27448 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -13,14 +13,10 @@ | |||
13 | #define pr_fmt(fmt) "g_ffs: " fmt | 13 | #define pr_fmt(fmt) "g_ffs: " fmt |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | /* | 16 | |
17 | * kbuild is not very cooperative with respect to linking separately | ||
18 | * compiled library objects into one module. So for now we won't use | ||
19 | * separate compilation ... ensuring init/exit sections work to shrink | ||
20 | * the runtime footprint, and giving us at least some parts of what | ||
21 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
22 | */ | ||
23 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | 17 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
18 | #include <linux/netdevice.h> | ||
19 | |||
24 | # if defined USB_ETH_RNDIS | 20 | # if defined USB_ETH_RNDIS |
25 | # undef USB_ETH_RNDIS | 21 | # undef USB_ETH_RNDIS |
26 | # endif | 22 | # endif |
@@ -28,31 +24,31 @@ | |||
28 | # define USB_ETH_RNDIS y | 24 | # define USB_ETH_RNDIS y |
29 | # endif | 25 | # endif |
30 | 26 | ||
31 | #define USBF_ECM_INCLUDED | 27 | # include "u_ecm.h" |
32 | # include "f_ecm.c" | 28 | # include "u_gether.h" |
33 | #define USB_FSUBSET_INCLUDED | ||
34 | # include "f_subset.c" | ||
35 | # ifdef USB_ETH_RNDIS | 29 | # ifdef USB_ETH_RNDIS |
36 | # define USB_FRNDIS_INCLUDED | 30 | # include "u_rndis.h" |
37 | # include "f_rndis.c" | ||
38 | # include "rndis.h" | 31 | # include "rndis.h" |
39 | # endif | 32 | # endif |
40 | # include "u_ether.h" | 33 | # include "u_ether.h" |
41 | 34 | ||
42 | static u8 gfs_host_mac[ETH_ALEN]; | 35 | USB_ETHERNET_MODULE_PARAMETERS(); |
43 | static struct eth_dev *the_dev; | 36 | |
44 | # ifdef CONFIG_USB_FUNCTIONFS_ETH | 37 | # ifdef CONFIG_USB_FUNCTIONFS_ETH |
45 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | 38 | static int eth_bind_config(struct usb_configuration *c); |
46 | struct eth_dev *dev); | 39 | static struct usb_function_instance *fi_ecm; |
40 | static struct usb_function *f_ecm; | ||
41 | static struct usb_function_instance *fi_geth; | ||
42 | static struct usb_function *f_geth; | ||
43 | # endif | ||
44 | # ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
45 | static int bind_rndis_config(struct usb_configuration *c); | ||
46 | static struct usb_function_instance *fi_rndis; | ||
47 | static struct usb_function *f_rndis; | ||
47 | # endif | 48 | # endif |
48 | #else | ||
49 | # define the_dev NULL | ||
50 | # define gether_cleanup(dev) do { } while (0) | ||
51 | # define gfs_host_mac NULL | ||
52 | struct eth_dev; | ||
53 | #endif | 49 | #endif |
54 | 50 | ||
55 | #include "f_fs.c" | 51 | #include "u_fs.h" |
56 | 52 | ||
57 | #define DRIVER_NAME "g_ffs" | 53 | #define DRIVER_NAME "g_ffs" |
58 | #define DRIVER_DESC "USB Function Filesystem" | 54 | #define DRIVER_DESC "USB Function Filesystem" |
@@ -67,19 +63,8 @@ MODULE_LICENSE("GPL"); | |||
67 | 63 | ||
68 | #define GFS_MAX_DEVS 10 | 64 | #define GFS_MAX_DEVS 10 |
69 | 65 | ||
70 | struct gfs_ffs_obj { | ||
71 | const char *name; | ||
72 | bool mounted; | ||
73 | bool desc_ready; | ||
74 | struct ffs_data *ffs_data; | ||
75 | }; | ||
76 | |||
77 | USB_GADGET_COMPOSITE_OPTIONS(); | 66 | USB_GADGET_COMPOSITE_OPTIONS(); |
78 | 67 | ||
79 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | ||
80 | USB_ETHERNET_MODULE_PARAMETERS(); | ||
81 | #endif | ||
82 | |||
83 | static struct usb_device_descriptor gfs_dev_desc = { | 68 | static struct usb_device_descriptor gfs_dev_desc = { |
84 | .bLength = sizeof gfs_dev_desc, | 69 | .bLength = sizeof gfs_dev_desc, |
85 | .bDescriptorType = USB_DT_DEVICE, | 70 | .bDescriptorType = USB_DT_DEVICE, |
@@ -146,12 +131,12 @@ static struct usb_gadget_strings *gfs_dev_strings[] = { | |||
146 | 131 | ||
147 | struct gfs_configuration { | 132 | struct gfs_configuration { |
148 | struct usb_configuration c; | 133 | struct usb_configuration c; |
149 | int (*eth)(struct usb_configuration *c, u8 *ethaddr, | 134 | int (*eth)(struct usb_configuration *c); |
150 | struct eth_dev *dev); | 135 | int num; |
151 | } gfs_configurations[] = { | 136 | } gfs_configurations[] = { |
152 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | 137 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
153 | { | 138 | { |
154 | .eth = rndis_bind_config, | 139 | .eth = bind_rndis_config, |
155 | }, | 140 | }, |
156 | #endif | 141 | #endif |
157 | 142 | ||
@@ -167,10 +152,15 @@ struct gfs_configuration { | |||
167 | #endif | 152 | #endif |
168 | }; | 153 | }; |
169 | 154 | ||
155 | static void *functionfs_acquire_dev(struct ffs_dev *dev); | ||
156 | static void functionfs_release_dev(struct ffs_dev *dev); | ||
157 | static int functionfs_ready_callback(struct ffs_data *ffs); | ||
158 | static void functionfs_closed_callback(struct ffs_data *ffs); | ||
170 | static int gfs_bind(struct usb_composite_dev *cdev); | 159 | static int gfs_bind(struct usb_composite_dev *cdev); |
171 | static int gfs_unbind(struct usb_composite_dev *cdev); | 160 | static int gfs_unbind(struct usb_composite_dev *cdev); |
172 | static int gfs_do_config(struct usb_configuration *c); | 161 | static int gfs_do_config(struct usb_configuration *c); |
173 | 162 | ||
163 | |||
174 | static __refdata struct usb_composite_driver gfs_driver = { | 164 | static __refdata struct usb_composite_driver gfs_driver = { |
175 | .name = DRIVER_NAME, | 165 | .name = DRIVER_NAME, |
176 | .dev = &gfs_dev_desc, | 166 | .dev = &gfs_dev_desc, |
@@ -180,206 +170,244 @@ static __refdata struct usb_composite_driver gfs_driver = { | |||
180 | .unbind = gfs_unbind, | 170 | .unbind = gfs_unbind, |
181 | }; | 171 | }; |
182 | 172 | ||
183 | static DEFINE_MUTEX(gfs_lock); | ||
184 | static unsigned int missing_funcs; | 173 | static unsigned int missing_funcs; |
185 | static bool gfs_ether_setup; | ||
186 | static bool gfs_registered; | 174 | static bool gfs_registered; |
187 | static bool gfs_single_func; | 175 | static bool gfs_single_func; |
188 | static struct gfs_ffs_obj *ffs_tab; | 176 | static struct usb_function_instance **fi_ffs; |
177 | static struct usb_function **f_ffs[] = { | ||
178 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
179 | NULL, | ||
180 | #endif | ||
181 | |||
182 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | ||
183 | NULL, | ||
184 | #endif | ||
185 | |||
186 | #ifdef CONFIG_USB_FUNCTIONFS_GENERIC | ||
187 | NULL, | ||
188 | #endif | ||
189 | }; | ||
190 | |||
191 | #define N_CONF ARRAY_SIZE(f_ffs) | ||
189 | 192 | ||
190 | static int __init gfs_init(void) | 193 | static int __init gfs_init(void) |
191 | { | 194 | { |
195 | struct f_fs_opts *opts; | ||
192 | int i; | 196 | int i; |
197 | int ret = 0; | ||
193 | 198 | ||
194 | ENTER(); | 199 | ENTER(); |
195 | 200 | ||
196 | if (!func_num) { | 201 | if (func_num < 2) { |
197 | gfs_single_func = true; | 202 | gfs_single_func = true; |
198 | func_num = 1; | 203 | func_num = 1; |
199 | } | 204 | } |
200 | 205 | ||
201 | ffs_tab = kcalloc(func_num, sizeof *ffs_tab, GFP_KERNEL); | 206 | /* |
202 | if (!ffs_tab) | 207 | * Allocate in one chunk for easier maintenance |
203 | return -ENOMEM; | 208 | */ |
209 | f_ffs[0] = kcalloc(func_num * N_CONF, sizeof(*f_ffs), GFP_KERNEL); | ||
210 | if (!f_ffs[0]) { | ||
211 | ret = -ENOMEM; | ||
212 | goto no_func; | ||
213 | } | ||
214 | for (i = 1; i < N_CONF; ++i) | ||
215 | f_ffs[i] = f_ffs[0] + i * func_num; | ||
204 | 216 | ||
205 | if (!gfs_single_func) | 217 | fi_ffs = kcalloc(func_num, sizeof(*fi_ffs), GFP_KERNEL); |
206 | for (i = 0; i < func_num; i++) | 218 | if (!fi_ffs) { |
207 | ffs_tab[i].name = func_names[i]; | 219 | ret = -ENOMEM; |
220 | goto no_func; | ||
221 | } | ||
222 | |||
223 | for (i = 0; i < func_num; i++) { | ||
224 | fi_ffs[i] = usb_get_function_instance("ffs"); | ||
225 | if (IS_ERR(fi_ffs[i])) { | ||
226 | ret = PTR_ERR(fi_ffs[i]); | ||
227 | --i; | ||
228 | goto no_dev; | ||
229 | } | ||
230 | opts = to_f_fs_opts(fi_ffs[i]); | ||
231 | if (gfs_single_func) | ||
232 | ret = ffs_single_dev(opts->dev); | ||
233 | else | ||
234 | ret = ffs_name_dev(opts->dev, func_names[i]); | ||
235 | if (ret) | ||
236 | goto no_dev; | ||
237 | opts->dev->ffs_ready_callback = functionfs_ready_callback; | ||
238 | opts->dev->ffs_closed_callback = functionfs_closed_callback; | ||
239 | opts->dev->ffs_acquire_dev_callback = functionfs_acquire_dev; | ||
240 | opts->dev->ffs_release_dev_callback = functionfs_release_dev; | ||
241 | opts->no_configfs = true; | ||
242 | } | ||
208 | 243 | ||
209 | missing_funcs = func_num; | 244 | missing_funcs = func_num; |
210 | 245 | ||
211 | return functionfs_init(); | 246 | return 0; |
247 | no_dev: | ||
248 | while (i >= 0) | ||
249 | usb_put_function_instance(fi_ffs[i--]); | ||
250 | kfree(fi_ffs); | ||
251 | no_func: | ||
252 | kfree(f_ffs[0]); | ||
253 | return ret; | ||
212 | } | 254 | } |
213 | module_init(gfs_init); | 255 | module_init(gfs_init); |
214 | 256 | ||
215 | static void __exit gfs_exit(void) | 257 | static void __exit gfs_exit(void) |
216 | { | 258 | { |
259 | int i; | ||
260 | |||
217 | ENTER(); | 261 | ENTER(); |
218 | mutex_lock(&gfs_lock); | ||
219 | 262 | ||
220 | if (gfs_registered) | 263 | if (gfs_registered) |
221 | usb_composite_unregister(&gfs_driver); | 264 | usb_composite_unregister(&gfs_driver); |
222 | gfs_registered = false; | 265 | gfs_registered = false; |
223 | 266 | ||
224 | functionfs_cleanup(); | 267 | kfree(f_ffs[0]); |
268 | |||
269 | for (i = 0; i < func_num; i++) | ||
270 | usb_put_function_instance(fi_ffs[i]); | ||
225 | 271 | ||
226 | mutex_unlock(&gfs_lock); | 272 | kfree(fi_ffs); |
227 | kfree(ffs_tab); | ||
228 | } | 273 | } |
229 | module_exit(gfs_exit); | 274 | module_exit(gfs_exit); |
230 | 275 | ||
231 | static struct gfs_ffs_obj *gfs_find_dev(const char *dev_name) | 276 | static void *functionfs_acquire_dev(struct ffs_dev *dev) |
232 | { | 277 | { |
233 | int i; | 278 | if (!try_module_get(THIS_MODULE)) |
234 | 279 | return ERR_PTR(-ENODEV); | |
235 | ENTER(); | 280 | |
236 | 281 | return 0; | |
237 | if (gfs_single_func) | 282 | } |
238 | return &ffs_tab[0]; | ||
239 | |||
240 | for (i = 0; i < func_num; i++) | ||
241 | if (strcmp(ffs_tab[i].name, dev_name) == 0) | ||
242 | return &ffs_tab[i]; | ||
243 | 283 | ||
244 | return NULL; | 284 | static void functionfs_release_dev(struct ffs_dev *dev) |
285 | { | ||
286 | module_put(THIS_MODULE); | ||
245 | } | 287 | } |
246 | 288 | ||
289 | /* | ||
290 | * The caller of this function takes ffs_lock | ||
291 | */ | ||
247 | static int functionfs_ready_callback(struct ffs_data *ffs) | 292 | static int functionfs_ready_callback(struct ffs_data *ffs) |
248 | { | 293 | { |
249 | struct gfs_ffs_obj *ffs_obj; | 294 | int ret = 0; |
250 | int ret; | ||
251 | |||
252 | ENTER(); | ||
253 | mutex_lock(&gfs_lock); | ||
254 | 295 | ||
255 | ffs_obj = ffs->private_data; | 296 | if (--missing_funcs) |
256 | if (!ffs_obj) { | 297 | return 0; |
257 | ret = -EINVAL; | ||
258 | goto done; | ||
259 | } | ||
260 | 298 | ||
261 | if (WARN_ON(ffs_obj->desc_ready)) { | 299 | if (gfs_registered) |
262 | ret = -EBUSY; | 300 | return -EBUSY; |
263 | goto done; | ||
264 | } | ||
265 | ffs_obj->desc_ready = true; | ||
266 | ffs_obj->ffs_data = ffs; | ||
267 | |||
268 | if (--missing_funcs) { | ||
269 | ret = 0; | ||
270 | goto done; | ||
271 | } | ||
272 | 301 | ||
273 | if (gfs_registered) { | ||
274 | ret = -EBUSY; | ||
275 | goto done; | ||
276 | } | ||
277 | gfs_registered = true; | 302 | gfs_registered = true; |
278 | 303 | ||
279 | ret = usb_composite_probe(&gfs_driver); | 304 | ret = usb_composite_probe(&gfs_driver); |
280 | if (unlikely(ret < 0)) | 305 | if (unlikely(ret < 0)) |
281 | gfs_registered = false; | 306 | gfs_registered = false; |
282 | 307 | ||
283 | done: | ||
284 | mutex_unlock(&gfs_lock); | ||
285 | return ret; | 308 | return ret; |
286 | } | 309 | } |
287 | 310 | ||
311 | /* | ||
312 | * The caller of this function takes ffs_lock | ||
313 | */ | ||
288 | static void functionfs_closed_callback(struct ffs_data *ffs) | 314 | static void functionfs_closed_callback(struct ffs_data *ffs) |
289 | { | 315 | { |
290 | struct gfs_ffs_obj *ffs_obj; | ||
291 | |||
292 | ENTER(); | ||
293 | mutex_lock(&gfs_lock); | ||
294 | |||
295 | ffs_obj = ffs->private_data; | ||
296 | if (!ffs_obj) | ||
297 | goto done; | ||
298 | |||
299 | ffs_obj->desc_ready = false; | ||
300 | missing_funcs++; | 316 | missing_funcs++; |
301 | 317 | ||
302 | if (gfs_registered) | 318 | if (gfs_registered) |
303 | usb_composite_unregister(&gfs_driver); | 319 | usb_composite_unregister(&gfs_driver); |
304 | gfs_registered = false; | 320 | gfs_registered = false; |
305 | |||
306 | done: | ||
307 | mutex_unlock(&gfs_lock); | ||
308 | } | 321 | } |
309 | 322 | ||
310 | static void *functionfs_acquire_dev_callback(const char *dev_name) | 323 | /* |
324 | * It is assumed that gfs_bind is called from a context where ffs_lock is held | ||
325 | */ | ||
326 | static int gfs_bind(struct usb_composite_dev *cdev) | ||
311 | { | 327 | { |
312 | struct gfs_ffs_obj *ffs_dev; | 328 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
329 | struct net_device *net; | ||
330 | #endif | ||
331 | int ret, i; | ||
313 | 332 | ||
314 | ENTER(); | 333 | ENTER(); |
315 | mutex_lock(&gfs_lock); | ||
316 | |||
317 | ffs_dev = gfs_find_dev(dev_name); | ||
318 | if (!ffs_dev) { | ||
319 | ffs_dev = ERR_PTR(-ENODEV); | ||
320 | goto done; | ||
321 | } | ||
322 | 334 | ||
323 | if (ffs_dev->mounted) { | 335 | if (missing_funcs) |
324 | ffs_dev = ERR_PTR(-EBUSY); | 336 | return -ENODEV; |
325 | goto done; | 337 | #if defined CONFIG_USB_FUNCTIONFS_ETH |
338 | if (can_support_ecm(cdev->gadget)) { | ||
339 | struct f_ecm_opts *ecm_opts; | ||
340 | |||
341 | fi_ecm = usb_get_function_instance("ecm"); | ||
342 | if (IS_ERR(fi_ecm)) | ||
343 | return PTR_ERR(fi_ecm); | ||
344 | ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); | ||
345 | net = ecm_opts->net; | ||
346 | } else { | ||
347 | struct f_gether_opts *geth_opts; | ||
348 | |||
349 | fi_geth = usb_get_function_instance("geth"); | ||
350 | if (IS_ERR(fi_geth)) | ||
351 | return PTR_ERR(fi_geth); | ||
352 | geth_opts = container_of(fi_geth, struct f_gether_opts, | ||
353 | func_inst); | ||
354 | net = geth_opts->net; | ||
326 | } | 355 | } |
327 | ffs_dev->mounted = true; | 356 | #endif |
328 | 357 | ||
329 | done: | 358 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
330 | mutex_unlock(&gfs_lock); | 359 | { |
331 | return ffs_dev; | 360 | struct f_rndis_opts *rndis_opts; |
332 | } | ||
333 | 361 | ||
334 | static void functionfs_release_dev_callback(struct ffs_data *ffs_data) | 362 | fi_rndis = usb_get_function_instance("rndis"); |
335 | { | 363 | if (IS_ERR(fi_rndis)) { |
336 | struct gfs_ffs_obj *ffs_dev; | 364 | ret = PTR_ERR(fi_rndis); |
365 | goto error; | ||
366 | } | ||
367 | rndis_opts = container_of(fi_rndis, struct f_rndis_opts, | ||
368 | func_inst); | ||
369 | #ifndef CONFIG_USB_FUNCTIONFS_ETH | ||
370 | net = rndis_opts->net; | ||
371 | #endif | ||
372 | } | ||
373 | #endif | ||
337 | 374 | ||
338 | ENTER(); | 375 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS |
339 | mutex_lock(&gfs_lock); | 376 | gether_set_qmult(net, qmult); |
377 | if (!gether_set_host_addr(net, host_addr)) | ||
378 | pr_info("using host ethernet address: %s", host_addr); | ||
379 | if (!gether_set_dev_addr(net, dev_addr)) | ||
380 | pr_info("using self ethernet address: %s", dev_addr); | ||
381 | #endif | ||
340 | 382 | ||
341 | ffs_dev = ffs_data->private_data; | 383 | #if defined CONFIG_USB_FUNCTIONFS_RNDIS && defined CONFIG_USB_FUNCTIONFS_ETH |
342 | if (ffs_dev) | 384 | gether_set_gadget(net, cdev->gadget); |
343 | ffs_dev->mounted = false; | 385 | ret = gether_register_netdev(net); |
386 | if (ret) | ||
387 | goto error_rndis; | ||
344 | 388 | ||
345 | mutex_unlock(&gfs_lock); | 389 | if (can_support_ecm(cdev->gadget)) { |
346 | } | 390 | struct f_ecm_opts *ecm_opts; |
347 | 391 | ||
348 | /* | 392 | ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); |
349 | * It is assumed that gfs_bind is called from a context where gfs_lock is held | 393 | ecm_opts->bound = true; |
350 | */ | 394 | } else { |
351 | static int gfs_bind(struct usb_composite_dev *cdev) | 395 | struct f_gether_opts *geth_opts; |
352 | { | ||
353 | int ret, i; | ||
354 | 396 | ||
355 | ENTER(); | 397 | geth_opts = container_of(fi_geth, struct f_gether_opts, |
398 | func_inst); | ||
399 | geth_opts->bound = true; | ||
400 | } | ||
356 | 401 | ||
357 | if (missing_funcs) | 402 | rndis_borrow_net(fi_rndis, net); |
358 | return -ENODEV; | ||
359 | #if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS | ||
360 | the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, gfs_host_mac, | ||
361 | qmult); | ||
362 | #endif | 403 | #endif |
363 | if (IS_ERR(the_dev)) { | ||
364 | ret = PTR_ERR(the_dev); | ||
365 | goto error_quick; | ||
366 | } | ||
367 | gfs_ether_setup = true; | ||
368 | 404 | ||
405 | /* TODO: gstrings_attach? */ | ||
369 | ret = usb_string_ids_tab(cdev, gfs_strings); | 406 | ret = usb_string_ids_tab(cdev, gfs_strings); |
370 | if (unlikely(ret < 0)) | 407 | if (unlikely(ret < 0)) |
371 | goto error; | 408 | goto error_rndis; |
372 | gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; | 409 | gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; |
373 | 410 | ||
374 | for (i = func_num; i--; ) { | ||
375 | ret = functionfs_bind(ffs_tab[i].ffs_data, cdev); | ||
376 | if (unlikely(ret < 0)) { | ||
377 | while (++i < func_num) | ||
378 | functionfs_unbind(ffs_tab[i].ffs_data); | ||
379 | goto error; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { | 411 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { |
384 | struct gfs_configuration *c = gfs_configurations + i; | 412 | struct gfs_configuration *c = gfs_configurations + i; |
385 | int sid = USB_GADGET_FIRST_AVAIL_IDX + i; | 413 | int sid = USB_GADGET_FIRST_AVAIL_IDX + i; |
@@ -389,6 +417,8 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
389 | c->c.bConfigurationValue = 1 + i; | 417 | c->c.bConfigurationValue = 1 + i; |
390 | c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; | 418 | c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; |
391 | 419 | ||
420 | c->num = i; | ||
421 | |||
392 | ret = usb_add_config(cdev, &c->c, gfs_do_config); | 422 | ret = usb_add_config(cdev, &c->c, gfs_do_config); |
393 | if (unlikely(ret < 0)) | 423 | if (unlikely(ret < 0)) |
394 | goto error_unbind; | 424 | goto error_unbind; |
@@ -396,18 +426,24 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
396 | usb_composite_overwrite_options(cdev, &coverwrite); | 426 | usb_composite_overwrite_options(cdev, &coverwrite); |
397 | return 0; | 427 | return 0; |
398 | 428 | ||
429 | /* TODO */ | ||
399 | error_unbind: | 430 | error_unbind: |
400 | for (i = 0; i < func_num; i++) | 431 | error_rndis: |
401 | functionfs_unbind(ffs_tab[i].ffs_data); | 432 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
433 | usb_put_function_instance(fi_rndis); | ||
402 | error: | 434 | error: |
403 | gether_cleanup(the_dev); | 435 | #endif |
404 | error_quick: | 436 | #if defined CONFIG_USB_FUNCTIONFS_ETH |
405 | gfs_ether_setup = false; | 437 | if (can_support_ecm(cdev->gadget)) |
438 | usb_put_function_instance(fi_ecm); | ||
439 | else | ||
440 | usb_put_function_instance(fi_geth); | ||
441 | #endif | ||
406 | return ret; | 442 | return ret; |
407 | } | 443 | } |
408 | 444 | ||
409 | /* | 445 | /* |
410 | * It is assumed that gfs_unbind is called from a context where gfs_lock is held | 446 | * It is assumed that gfs_unbind is called from a context where ffs_lock is held |
411 | */ | 447 | */ |
412 | static int gfs_unbind(struct usb_composite_dev *cdev) | 448 | static int gfs_unbind(struct usb_composite_dev *cdev) |
413 | { | 449 | { |
@@ -415,28 +451,30 @@ static int gfs_unbind(struct usb_composite_dev *cdev) | |||
415 | 451 | ||
416 | ENTER(); | 452 | ENTER(); |
417 | 453 | ||
418 | /* | ||
419 | * We may have been called in an error recovery from | ||
420 | * composite_bind() after gfs_unbind() failure so we need to | ||
421 | * check if gfs_ffs_data is not NULL since gfs_bind() handles | ||
422 | * all error recovery itself. I'd rather we werent called | ||
423 | * from composite on orror recovery, but what you're gonna | ||
424 | * do...? | ||
425 | */ | ||
426 | if (gfs_ether_setup) | ||
427 | gether_cleanup(the_dev); | ||
428 | gfs_ether_setup = false; | ||
429 | 454 | ||
430 | for (i = func_num; i--; ) | 455 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS |
431 | if (ffs_tab[i].ffs_data) | 456 | usb_put_function(f_rndis); |
432 | functionfs_unbind(ffs_tab[i].ffs_data); | 457 | usb_put_function_instance(fi_rndis); |
458 | #endif | ||
459 | |||
460 | #if defined CONFIG_USB_FUNCTIONFS_ETH | ||
461 | if (can_support_ecm(cdev->gadget)) { | ||
462 | usb_put_function(f_ecm); | ||
463 | usb_put_function_instance(fi_ecm); | ||
464 | } else { | ||
465 | usb_put_function(f_geth); | ||
466 | usb_put_function_instance(fi_geth); | ||
467 | } | ||
468 | #endif | ||
469 | for (i = 0; i < N_CONF * func_num; ++i) | ||
470 | usb_put_function(*(f_ffs[0] + i)); | ||
433 | 471 | ||
434 | return 0; | 472 | return 0; |
435 | } | 473 | } |
436 | 474 | ||
437 | /* | 475 | /* |
438 | * It is assumed that gfs_do_config is called from a context where | 476 | * It is assumed that gfs_do_config is called from a context where |
439 | * gfs_lock is held | 477 | * ffs_lock is held |
440 | */ | 478 | */ |
441 | static int gfs_do_config(struct usb_configuration *c) | 479 | static int gfs_do_config(struct usb_configuration *c) |
442 | { | 480 | { |
@@ -454,15 +492,22 @@ static int gfs_do_config(struct usb_configuration *c) | |||
454 | } | 492 | } |
455 | 493 | ||
456 | if (gc->eth) { | 494 | if (gc->eth) { |
457 | ret = gc->eth(c, gfs_host_mac, the_dev); | 495 | ret = gc->eth(c); |
458 | if (unlikely(ret < 0)) | 496 | if (unlikely(ret < 0)) |
459 | return ret; | 497 | return ret; |
460 | } | 498 | } |
461 | 499 | ||
462 | for (i = 0; i < func_num; i++) { | 500 | for (i = 0; i < func_num; i++) { |
463 | ret = functionfs_bind_config(c->cdev, c, ffs_tab[i].ffs_data); | 501 | f_ffs[gc->num][i] = usb_get_function(fi_ffs[i]); |
464 | if (unlikely(ret < 0)) | 502 | if (IS_ERR(f_ffs[gc->num][i])) { |
465 | return ret; | 503 | ret = PTR_ERR(f_ffs[gc->num][i]); |
504 | goto error; | ||
505 | } | ||
506 | ret = usb_add_function(c, f_ffs[gc->num][i]); | ||
507 | if (ret < 0) { | ||
508 | usb_put_function(f_ffs[gc->num][i]); | ||
509 | goto error; | ||
510 | } | ||
466 | } | 511 | } |
467 | 512 | ||
468 | /* | 513 | /* |
@@ -479,16 +524,59 @@ static int gfs_do_config(struct usb_configuration *c) | |||
479 | c->interface[c->next_interface_id] = NULL; | 524 | c->interface[c->next_interface_id] = NULL; |
480 | 525 | ||
481 | return 0; | 526 | return 0; |
527 | error: | ||
528 | while (--i >= 0) { | ||
529 | if (!IS_ERR(f_ffs[gc->num][i])) | ||
530 | usb_remove_function(c, f_ffs[gc->num][i]); | ||
531 | usb_put_function(f_ffs[gc->num][i]); | ||
532 | } | ||
533 | return ret; | ||
482 | } | 534 | } |
483 | 535 | ||
484 | #ifdef CONFIG_USB_FUNCTIONFS_ETH | 536 | #ifdef CONFIG_USB_FUNCTIONFS_ETH |
485 | 537 | ||
486 | static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | 538 | static int eth_bind_config(struct usb_configuration *c) |
487 | struct eth_dev *dev) | 539 | { |
540 | int status = 0; | ||
541 | |||
542 | if (can_support_ecm(c->cdev->gadget)) { | ||
543 | f_ecm = usb_get_function(fi_ecm); | ||
544 | if (IS_ERR(f_ecm)) | ||
545 | return PTR_ERR(f_ecm); | ||
546 | |||
547 | status = usb_add_function(c, f_ecm); | ||
548 | if (status < 0) | ||
549 | usb_put_function(f_ecm); | ||
550 | |||
551 | } else { | ||
552 | f_geth = usb_get_function(fi_geth); | ||
553 | if (IS_ERR(f_geth)) | ||
554 | return PTR_ERR(f_geth); | ||
555 | |||
556 | status = usb_add_function(c, f_geth); | ||
557 | if (status < 0) | ||
558 | usb_put_function(f_geth); | ||
559 | } | ||
560 | return status; | ||
561 | } | ||
562 | |||
563 | #endif | ||
564 | |||
565 | #ifdef CONFIG_USB_FUNCTIONFS_RNDIS | ||
566 | |||
567 | static int bind_rndis_config(struct usb_configuration *c) | ||
488 | { | 568 | { |
489 | return can_support_ecm(c->cdev->gadget) | 569 | int status = 0; |
490 | ? ecm_bind_config(c, ethaddr, dev) | 570 | |
491 | : geth_bind_config(c, ethaddr, dev); | 571 | f_rndis = usb_get_function(fi_rndis); |
572 | if (IS_ERR(f_rndis)) | ||
573 | return PTR_ERR(f_rndis); | ||
574 | |||
575 | status = usb_add_function(c, f_rndis); | ||
576 | if (status < 0) | ||
577 | usb_put_function(f_rndis); | ||
578 | |||
579 | return status; | ||
492 | } | 580 | } |
493 | 581 | ||
494 | #endif | 582 | #endif |
diff --git a/drivers/usb/gadget/g_zero.h b/drivers/usb/gadget/g_zero.h index ef3e8515272b..15f180904f8a 100644 --- a/drivers/usb/gadget/g_zero.h +++ b/drivers/usb/gadget/g_zero.h | |||
@@ -6,6 +6,11 @@ | |||
6 | #ifndef __G_ZERO_H | 6 | #ifndef __G_ZERO_H |
7 | #define __G_ZERO_H | 7 | #define __G_ZERO_H |
8 | 8 | ||
9 | #define GZERO_BULK_BUFLEN 4096 | ||
10 | #define GZERO_QLEN 32 | ||
11 | #define GZERO_ISOC_INTERVAL 4 | ||
12 | #define GZERO_ISOC_MAXPACKET 1024 | ||
13 | |||
9 | struct usb_zero_options { | 14 | struct usb_zero_options { |
10 | unsigned pattern; | 15 | unsigned pattern; |
11 | unsigned isoc_interval; | 16 | unsigned isoc_interval; |
@@ -24,19 +29,36 @@ struct f_ss_opts { | |||
24 | unsigned isoc_mult; | 29 | unsigned isoc_mult; |
25 | unsigned isoc_maxburst; | 30 | unsigned isoc_maxburst; |
26 | unsigned bulk_buflen; | 31 | unsigned bulk_buflen; |
32 | |||
33 | /* | ||
34 | * Read/write access to configfs attributes is handled by configfs. | ||
35 | * | ||
36 | * This is to protect the data from concurrent access by read/write | ||
37 | * and create symlink/remove symlink. | ||
38 | */ | ||
39 | struct mutex lock; | ||
40 | int refcnt; | ||
27 | }; | 41 | }; |
28 | 42 | ||
29 | struct f_lb_opts { | 43 | struct f_lb_opts { |
30 | struct usb_function_instance func_inst; | 44 | struct usb_function_instance func_inst; |
31 | unsigned bulk_buflen; | 45 | unsigned bulk_buflen; |
32 | unsigned qlen; | 46 | unsigned qlen; |
47 | |||
48 | /* | ||
49 | * Read/write access to configfs attributes is handled by configfs. | ||
50 | * | ||
51 | * This is to protect the data from concurrent access by read/write | ||
52 | * and create symlink/remove symlink. | ||
53 | */ | ||
54 | struct mutex lock; | ||
55 | int refcnt; | ||
33 | }; | 56 | }; |
34 | 57 | ||
35 | void lb_modexit(void); | 58 | void lb_modexit(void); |
36 | int lb_modinit(void); | 59 | int lb_modinit(void); |
37 | 60 | ||
38 | /* common utilities */ | 61 | /* common utilities */ |
39 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len); | ||
40 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); | 62 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); |
41 | void disable_endpoints(struct usb_composite_dev *cdev, | 63 | void disable_endpoints(struct usb_composite_dev *cdev, |
42 | struct usb_ep *in, struct usb_ep *out, | 64 | struct usb_ep *in, struct usb_ep *out, |
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index f82768015715..6c85839e15ad 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/ioport.h> | 30 | #include <linux/ioport.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
33 | #include <linux/init.h> | ||
34 | #include <linux/timer.h> | 33 | #include <linux/timer.h> |
35 | #include <linux/list.h> | 34 | #include <linux/list.h> |
36 | #include <linux/interrupt.h> | 35 | #include <linux/interrupt.h> |
@@ -231,7 +230,7 @@ static void ep_reset(struct goku_udc_regs __iomem *regs, struct goku_ep *ep) | |||
231 | } | 230 | } |
232 | } | 231 | } |
233 | 232 | ||
234 | ep->ep.maxpacket = MAX_FIFO_SIZE; | 233 | usb_ep_set_maxpacket_limit(&ep->ep, MAX_FIFO_SIZE); |
235 | ep->ep.desc = NULL; | 234 | ep->ep.desc = NULL; |
236 | ep->stopped = 1; | 235 | ep->stopped = 1; |
237 | ep->irqs = 0; | 236 | ep->irqs = 0; |
@@ -1251,7 +1250,7 @@ static void udc_reinit (struct goku_udc *dev) | |||
1251 | } | 1250 | } |
1252 | 1251 | ||
1253 | dev->ep[0].reg_mode = NULL; | 1252 | dev->ep[0].reg_mode = NULL; |
1254 | dev->ep[0].ep.maxpacket = MAX_EP0_SIZE; | 1253 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, MAX_EP0_SIZE); |
1255 | list_del_init (&dev->ep[0].ep.ep_list); | 1254 | list_del_init (&dev->ep[0].ep.ep_list); |
1256 | } | 1255 | } |
1257 | 1256 | ||
@@ -1350,16 +1349,12 @@ static int goku_udc_start(struct usb_gadget *g, | |||
1350 | return 0; | 1349 | return 0; |
1351 | } | 1350 | } |
1352 | 1351 | ||
1353 | static void | 1352 | static void stop_activity(struct goku_udc *dev) |
1354 | stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) | ||
1355 | { | 1353 | { |
1356 | unsigned i; | 1354 | unsigned i; |
1357 | 1355 | ||
1358 | DBG (dev, "%s\n", __func__); | 1356 | DBG (dev, "%s\n", __func__); |
1359 | 1357 | ||
1360 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1361 | driver = NULL; | ||
1362 | |||
1363 | /* disconnect gadget driver after quiesceing hw and the driver */ | 1358 | /* disconnect gadget driver after quiesceing hw and the driver */ |
1364 | udc_reset (dev); | 1359 | udc_reset (dev); |
1365 | for (i = 0; i < 4; i++) | 1360 | for (i = 0; i < 4; i++) |
@@ -1377,7 +1372,7 @@ static int goku_udc_stop(struct usb_gadget *g, | |||
1377 | 1372 | ||
1378 | spin_lock_irqsave(&dev->lock, flags); | 1373 | spin_lock_irqsave(&dev->lock, flags); |
1379 | dev->driver = NULL; | 1374 | dev->driver = NULL; |
1380 | stop_activity(dev, driver); | 1375 | stop_activity(dev); |
1381 | spin_unlock_irqrestore(&dev->lock, flags); | 1376 | spin_unlock_irqrestore(&dev->lock, flags); |
1382 | 1377 | ||
1383 | return 0; | 1378 | return 0; |
@@ -1521,7 +1516,7 @@ rescan: | |||
1521 | if (unlikely(stat & INT_DEVWIDE)) { | 1516 | if (unlikely(stat & INT_DEVWIDE)) { |
1522 | if (stat & INT_SYSERROR) { | 1517 | if (stat & INT_SYSERROR) { |
1523 | ERROR(dev, "system error\n"); | 1518 | ERROR(dev, "system error\n"); |
1524 | stop_activity(dev, dev->driver); | 1519 | stop_activity(dev); |
1525 | stat = 0; | 1520 | stat = 0; |
1526 | handled = 1; | 1521 | handled = 1; |
1527 | // FIXME have a neater way to prevent re-enumeration | 1522 | // FIXME have a neater way to prevent re-enumeration |
@@ -1536,7 +1531,7 @@ rescan: | |||
1536 | } else { | 1531 | } else { |
1537 | DBG(dev, "disconnect\n"); | 1532 | DBG(dev, "disconnect\n"); |
1538 | if (dev->gadget.speed == USB_SPEED_FULL) | 1533 | if (dev->gadget.speed == USB_SPEED_FULL) |
1539 | stop_activity(dev, dev->driver); | 1534 | stop_activity(dev); |
1540 | dev->ep0state = EP0_DISCONNECT; | 1535 | dev->ep0state = EP0_DISCONNECT; |
1541 | dev->int_enable = INT_DEVWIDE; | 1536 | dev->int_enable = INT_DEVWIDE; |
1542 | writel(dev->int_enable, &dev->regs->int_enable); | 1537 | writel(dev->int_enable, &dev->regs->int_enable); |
diff --git a/drivers/usb/gadget/gr_udc.c b/drivers/usb/gadget/gr_udc.c new file mode 100644 index 000000000000..914cbd84ee40 --- /dev/null +++ b/drivers/usb/gadget/gr_udc.c | |||
@@ -0,0 +1,2238 @@ | |||
1 | /* | ||
2 | * USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC. | ||
3 | * | ||
4 | * 2013 (c) Aeroflex Gaisler AB | ||
5 | * | ||
6 | * This driver supports GRUSBDC USB Device Controller cores available in the | ||
7 | * GRLIB VHDL IP core library. | ||
8 | * | ||
9 | * Full documentation of the GRUSBDC core can be found here: | ||
10 | * http://www.gaisler.com/products/grlib/grip.pdf | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License as published by the | ||
14 | * Free Software Foundation; either version 2 of the License, or (at your | ||
15 | * option) any later version. | ||
16 | * | ||
17 | * Contributors: | ||
18 | * - Andreas Larsson <andreas@gaisler.com> | ||
19 | * - Marko Isomaki | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * A GRUSBDC core can have up to 16 IN endpoints and 16 OUT endpoints each | ||
24 | * individually configurable to any of the four USB transfer types. This driver | ||
25 | * only supports cores in DMA mode. | ||
26 | */ | ||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/spinlock.h> | ||
32 | #include <linux/errno.h> | ||
33 | #include <linux/list.h> | ||
34 | #include <linux/interrupt.h> | ||
35 | #include <linux/device.h> | ||
36 | #include <linux/usb/ch9.h> | ||
37 | #include <linux/usb/gadget.h> | ||
38 | #include <linux/dma-mapping.h> | ||
39 | #include <linux/dmapool.h> | ||
40 | #include <linux/debugfs.h> | ||
41 | #include <linux/seq_file.h> | ||
42 | #include <linux/of_platform.h> | ||
43 | #include <linux/of_irq.h> | ||
44 | #include <linux/of_address.h> | ||
45 | |||
46 | #include <asm/byteorder.h> | ||
47 | |||
48 | #include "gr_udc.h" | ||
49 | |||
50 | #define DRIVER_NAME "gr_udc" | ||
51 | #define DRIVER_DESC "Aeroflex Gaisler GRUSBDC USB Peripheral Controller" | ||
52 | |||
53 | static const char driver_name[] = DRIVER_NAME; | ||
54 | static const char driver_desc[] = DRIVER_DESC; | ||
55 | |||
56 | #define gr_read32(x) (ioread32be((x))) | ||
57 | #define gr_write32(x, v) (iowrite32be((v), (x))) | ||
58 | |||
59 | /* USB speed and corresponding string calculated from status register value */ | ||
60 | #define GR_SPEED(status) \ | ||
61 | ((status & GR_STATUS_SP) ? USB_SPEED_FULL : USB_SPEED_HIGH) | ||
62 | #define GR_SPEED_STR(status) usb_speed_string(GR_SPEED(status)) | ||
63 | |||
64 | /* Size of hardware buffer calculated from epctrl register value */ | ||
65 | #define GR_BUFFER_SIZE(epctrl) \ | ||
66 | ((((epctrl) & GR_EPCTRL_BUFSZ_MASK) >> GR_EPCTRL_BUFSZ_POS) * \ | ||
67 | GR_EPCTRL_BUFSZ_SCALER) | ||
68 | |||
69 | /* ---------------------------------------------------------------------- */ | ||
70 | /* Debug printout functionality */ | ||
71 | |||
72 | static const char * const gr_modestring[] = {"control", "iso", "bulk", "int"}; | ||
73 | |||
74 | static const char *gr_ep0state_string(enum gr_ep0state state) | ||
75 | { | ||
76 | static const char *const names[] = { | ||
77 | [GR_EP0_DISCONNECT] = "disconnect", | ||
78 | [GR_EP0_SETUP] = "setup", | ||
79 | [GR_EP0_IDATA] = "idata", | ||
80 | [GR_EP0_ODATA] = "odata", | ||
81 | [GR_EP0_ISTATUS] = "istatus", | ||
82 | [GR_EP0_OSTATUS] = "ostatus", | ||
83 | [GR_EP0_STALL] = "stall", | ||
84 | [GR_EP0_SUSPEND] = "suspend", | ||
85 | }; | ||
86 | |||
87 | if (state < 0 || state >= ARRAY_SIZE(names)) | ||
88 | return "UNKNOWN"; | ||
89 | |||
90 | return names[state]; | ||
91 | } | ||
92 | |||
93 | #ifdef VERBOSE_DEBUG | ||
94 | |||
95 | static void gr_dbgprint_request(const char *str, struct gr_ep *ep, | ||
96 | struct gr_request *req) | ||
97 | { | ||
98 | int buflen = ep->is_in ? req->req.length : req->req.actual; | ||
99 | int rowlen = 32; | ||
100 | int plen = min(rowlen, buflen); | ||
101 | |||
102 | dev_dbg(ep->dev->dev, "%s: 0x%p, %d bytes data%s:\n", str, req, buflen, | ||
103 | (buflen > plen ? " (truncated)" : "")); | ||
104 | print_hex_dump_debug(" ", DUMP_PREFIX_NONE, | ||
105 | rowlen, 4, req->req.buf, plen, false); | ||
106 | } | ||
107 | |||
108 | static void gr_dbgprint_devreq(struct gr_udc *dev, u8 type, u8 request, | ||
109 | u16 value, u16 index, u16 length) | ||
110 | { | ||
111 | dev_vdbg(dev->dev, "REQ: %02x.%02x v%04x i%04x l%04x\n", | ||
112 | type, request, value, index, length); | ||
113 | } | ||
114 | #else /* !VERBOSE_DEBUG */ | ||
115 | |||
116 | static void gr_dbgprint_request(const char *str, struct gr_ep *ep, | ||
117 | struct gr_request *req) {} | ||
118 | |||
119 | static void gr_dbgprint_devreq(struct gr_udc *dev, u8 type, u8 request, | ||
120 | u16 value, u16 index, u16 length) {} | ||
121 | |||
122 | #endif /* VERBOSE_DEBUG */ | ||
123 | |||
124 | /* ---------------------------------------------------------------------- */ | ||
125 | /* Debugfs functionality */ | ||
126 | |||
127 | #ifdef CONFIG_USB_GADGET_DEBUG_FS | ||
128 | |||
129 | static void gr_seq_ep_show(struct seq_file *seq, struct gr_ep *ep) | ||
130 | { | ||
131 | u32 epctrl = gr_read32(&ep->regs->epctrl); | ||
132 | u32 epstat = gr_read32(&ep->regs->epstat); | ||
133 | int mode = (epctrl & GR_EPCTRL_TT_MASK) >> GR_EPCTRL_TT_POS; | ||
134 | struct gr_request *req; | ||
135 | |||
136 | seq_printf(seq, "%s:\n", ep->ep.name); | ||
137 | seq_printf(seq, " mode = %s\n", gr_modestring[mode]); | ||
138 | seq_printf(seq, " halted: %d\n", !!(epctrl & GR_EPCTRL_EH)); | ||
139 | seq_printf(seq, " disabled: %d\n", !!(epctrl & GR_EPCTRL_ED)); | ||
140 | seq_printf(seq, " valid: %d\n", !!(epctrl & GR_EPCTRL_EV)); | ||
141 | seq_printf(seq, " dma_start = %d\n", ep->dma_start); | ||
142 | seq_printf(seq, " stopped = %d\n", ep->stopped); | ||
143 | seq_printf(seq, " wedged = %d\n", ep->wedged); | ||
144 | seq_printf(seq, " callback = %d\n", ep->callback); | ||
145 | seq_printf(seq, " maxpacket = %d\n", ep->ep.maxpacket); | ||
146 | seq_printf(seq, " bytes_per_buffer = %d\n", ep->bytes_per_buffer); | ||
147 | if (mode == 1 || mode == 3) | ||
148 | seq_printf(seq, " nt = %d\n", | ||
149 | (epctrl & GR_EPCTRL_NT_MASK) >> GR_EPCTRL_NT_POS); | ||
150 | |||
151 | seq_printf(seq, " Buffer 0: %s %s%d\n", | ||
152 | epstat & GR_EPSTAT_B0 ? "valid" : "invalid", | ||
153 | epstat & GR_EPSTAT_BS ? " " : "selected ", | ||
154 | (epstat & GR_EPSTAT_B0CNT_MASK) >> GR_EPSTAT_B0CNT_POS); | ||
155 | seq_printf(seq, " Buffer 1: %s %s%d\n", | ||
156 | epstat & GR_EPSTAT_B1 ? "valid" : "invalid", | ||
157 | epstat & GR_EPSTAT_BS ? "selected " : " ", | ||
158 | (epstat & GR_EPSTAT_B1CNT_MASK) >> GR_EPSTAT_B1CNT_POS); | ||
159 | |||
160 | if (list_empty(&ep->queue)) { | ||
161 | seq_puts(seq, " Queue: empty\n\n"); | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | seq_puts(seq, " Queue:\n"); | ||
166 | list_for_each_entry(req, &ep->queue, queue) { | ||
167 | struct gr_dma_desc *desc; | ||
168 | struct gr_dma_desc *next; | ||
169 | |||
170 | seq_printf(seq, " 0x%p: 0x%p %d %d\n", req, | ||
171 | &req->req.buf, req->req.actual, req->req.length); | ||
172 | |||
173 | next = req->first_desc; | ||
174 | do { | ||
175 | desc = next; | ||
176 | next = desc->next_desc; | ||
177 | seq_printf(seq, " %c 0x%p (0x%08x): 0x%05x 0x%08x\n", | ||
178 | desc == req->curr_desc ? 'c' : ' ', | ||
179 | desc, desc->paddr, desc->ctrl, desc->data); | ||
180 | } while (desc != req->last_desc); | ||
181 | } | ||
182 | seq_puts(seq, "\n"); | ||
183 | } | ||
184 | |||
185 | |||
186 | static int gr_seq_show(struct seq_file *seq, void *v) | ||
187 | { | ||
188 | struct gr_udc *dev = seq->private; | ||
189 | u32 control = gr_read32(&dev->regs->control); | ||
190 | u32 status = gr_read32(&dev->regs->status); | ||
191 | struct gr_ep *ep; | ||
192 | |||
193 | seq_printf(seq, "usb state = %s\n", | ||
194 | usb_state_string(dev->gadget.state)); | ||
195 | seq_printf(seq, "address = %d\n", | ||
196 | (control & GR_CONTROL_UA_MASK) >> GR_CONTROL_UA_POS); | ||
197 | seq_printf(seq, "speed = %s\n", GR_SPEED_STR(status)); | ||
198 | seq_printf(seq, "ep0state = %s\n", gr_ep0state_string(dev->ep0state)); | ||
199 | seq_printf(seq, "irq_enabled = %d\n", dev->irq_enabled); | ||
200 | seq_printf(seq, "remote_wakeup = %d\n", dev->remote_wakeup); | ||
201 | seq_printf(seq, "test_mode = %d\n", dev->test_mode); | ||
202 | seq_puts(seq, "\n"); | ||
203 | |||
204 | list_for_each_entry(ep, &dev->ep_list, ep_list) | ||
205 | gr_seq_ep_show(seq, ep); | ||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int gr_dfs_open(struct inode *inode, struct file *file) | ||
211 | { | ||
212 | return single_open(file, gr_seq_show, inode->i_private); | ||
213 | } | ||
214 | |||
215 | static const struct file_operations gr_dfs_fops = { | ||
216 | .owner = THIS_MODULE, | ||
217 | .open = gr_dfs_open, | ||
218 | .read = seq_read, | ||
219 | .llseek = seq_lseek, | ||
220 | .release = single_release, | ||
221 | }; | ||
222 | |||
223 | static void gr_dfs_create(struct gr_udc *dev) | ||
224 | { | ||
225 | const char *name = "gr_udc_state"; | ||
226 | |||
227 | dev->dfs_root = debugfs_create_dir(dev_name(dev->dev), NULL); | ||
228 | if (IS_ERR(dev->dfs_root)) { | ||
229 | dev_err(dev->dev, "Failed to create debugfs directory\n"); | ||
230 | return; | ||
231 | } | ||
232 | dev->dfs_state = debugfs_create_file(name, 0444, dev->dfs_root, | ||
233 | dev, &gr_dfs_fops); | ||
234 | if (IS_ERR(dev->dfs_state)) | ||
235 | dev_err(dev->dev, "Failed to create debugfs file %s\n", name); | ||
236 | } | ||
237 | |||
238 | static void gr_dfs_delete(struct gr_udc *dev) | ||
239 | { | ||
240 | /* Handles NULL and ERR pointers internally */ | ||
241 | debugfs_remove(dev->dfs_state); | ||
242 | debugfs_remove(dev->dfs_root); | ||
243 | } | ||
244 | |||
245 | #else /* !CONFIG_USB_GADGET_DEBUG_FS */ | ||
246 | |||
247 | static void gr_dfs_create(struct gr_udc *dev) {} | ||
248 | static void gr_dfs_delete(struct gr_udc *dev) {} | ||
249 | |||
250 | #endif /* CONFIG_USB_GADGET_DEBUG_FS */ | ||
251 | |||
252 | /* ---------------------------------------------------------------------- */ | ||
253 | /* DMA and request handling */ | ||
254 | |||
255 | /* Allocates a new struct gr_dma_desc, sets paddr and zeroes the rest */ | ||
256 | static struct gr_dma_desc *gr_alloc_dma_desc(struct gr_ep *ep, gfp_t gfp_flags) | ||
257 | { | ||
258 | dma_addr_t paddr; | ||
259 | struct gr_dma_desc *dma_desc; | ||
260 | |||
261 | dma_desc = dma_pool_alloc(ep->dev->desc_pool, gfp_flags, &paddr); | ||
262 | if (!dma_desc) { | ||
263 | dev_err(ep->dev->dev, "Could not allocate from DMA pool\n"); | ||
264 | return NULL; | ||
265 | } | ||
266 | |||
267 | memset(dma_desc, 0, sizeof(*dma_desc)); | ||
268 | dma_desc->paddr = paddr; | ||
269 | |||
270 | return dma_desc; | ||
271 | } | ||
272 | |||
273 | static inline void gr_free_dma_desc(struct gr_udc *dev, | ||
274 | struct gr_dma_desc *desc) | ||
275 | { | ||
276 | dma_pool_free(dev->desc_pool, desc, (dma_addr_t)desc->paddr); | ||
277 | } | ||
278 | |||
279 | /* Frees the chain of struct gr_dma_desc for the given request */ | ||
280 | static void gr_free_dma_desc_chain(struct gr_udc *dev, struct gr_request *req) | ||
281 | { | ||
282 | struct gr_dma_desc *desc; | ||
283 | struct gr_dma_desc *next; | ||
284 | |||
285 | next = req->first_desc; | ||
286 | if (!next) | ||
287 | return; | ||
288 | |||
289 | do { | ||
290 | desc = next; | ||
291 | next = desc->next_desc; | ||
292 | gr_free_dma_desc(dev, desc); | ||
293 | } while (desc != req->last_desc); | ||
294 | |||
295 | req->first_desc = NULL; | ||
296 | req->curr_desc = NULL; | ||
297 | req->last_desc = NULL; | ||
298 | } | ||
299 | |||
300 | static void gr_ep0_setup(struct gr_udc *dev, struct gr_request *req); | ||
301 | |||
302 | /* | ||
303 | * Frees allocated resources and calls the appropriate completion function/setup | ||
304 | * package handler for a finished request. | ||
305 | * | ||
306 | * Must be called with dev->lock held and irqs disabled. | ||
307 | */ | ||
308 | static void gr_finish_request(struct gr_ep *ep, struct gr_request *req, | ||
309 | int status) | ||
310 | __releases(&dev->lock) | ||
311 | __acquires(&dev->lock) | ||
312 | { | ||
313 | struct gr_udc *dev; | ||
314 | |||
315 | list_del_init(&req->queue); | ||
316 | |||
317 | if (likely(req->req.status == -EINPROGRESS)) | ||
318 | req->req.status = status; | ||
319 | else | ||
320 | status = req->req.status; | ||
321 | |||
322 | dev = ep->dev; | ||
323 | usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); | ||
324 | gr_free_dma_desc_chain(dev, req); | ||
325 | |||
326 | if (ep->is_in) /* For OUT, actual gets updated bit by bit */ | ||
327 | req->req.actual = req->req.length; | ||
328 | |||
329 | if (!status) { | ||
330 | if (ep->is_in) | ||
331 | gr_dbgprint_request("SENT", ep, req); | ||
332 | else | ||
333 | gr_dbgprint_request("RECV", ep, req); | ||
334 | } | ||
335 | |||
336 | /* Prevent changes to ep->queue during callback */ | ||
337 | ep->callback = 1; | ||
338 | if (req == dev->ep0reqo && !status) { | ||
339 | if (req->setup) | ||
340 | gr_ep0_setup(dev, req); | ||
341 | else | ||
342 | dev_err(dev->dev, | ||
343 | "Unexpected non setup packet on ep0in\n"); | ||
344 | } else if (req->req.complete) { | ||
345 | spin_unlock(&dev->lock); | ||
346 | |||
347 | req->req.complete(&ep->ep, &req->req); | ||
348 | |||
349 | spin_lock(&dev->lock); | ||
350 | } | ||
351 | ep->callback = 0; | ||
352 | } | ||
353 | |||
354 | static struct usb_request *gr_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | ||
355 | { | ||
356 | struct gr_request *req; | ||
357 | |||
358 | req = kzalloc(sizeof(*req), gfp_flags); | ||
359 | if (!req) | ||
360 | return NULL; | ||
361 | |||
362 | INIT_LIST_HEAD(&req->queue); | ||
363 | |||
364 | return &req->req; | ||
365 | } | ||
366 | |||
367 | /* | ||
368 | * Starts DMA for endpoint ep if there are requests in the queue. | ||
369 | * | ||
370 | * Must be called with dev->lock held and with !ep->stopped. | ||
371 | */ | ||
372 | static void gr_start_dma(struct gr_ep *ep) | ||
373 | { | ||
374 | struct gr_request *req; | ||
375 | u32 dmactrl; | ||
376 | |||
377 | if (list_empty(&ep->queue)) { | ||
378 | ep->dma_start = 0; | ||
379 | return; | ||
380 | } | ||
381 | |||
382 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
383 | |||
384 | /* A descriptor should already have been allocated */ | ||
385 | BUG_ON(!req->curr_desc); | ||
386 | |||
387 | wmb(); /* Make sure all is settled before handing it over to DMA */ | ||
388 | |||
389 | /* Set the descriptor pointer in the hardware */ | ||
390 | gr_write32(&ep->regs->dmaaddr, req->curr_desc->paddr); | ||
391 | |||
392 | /* Announce available descriptors */ | ||
393 | dmactrl = gr_read32(&ep->regs->dmactrl); | ||
394 | gr_write32(&ep->regs->dmactrl, dmactrl | GR_DMACTRL_DA); | ||
395 | |||
396 | ep->dma_start = 1; | ||
397 | } | ||
398 | |||
399 | /* | ||
400 | * Finishes the first request in the ep's queue and, if available, starts the | ||
401 | * next request in queue. | ||
402 | * | ||
403 | * Must be called with dev->lock held, irqs disabled and with !ep->stopped. | ||
404 | */ | ||
405 | static void gr_dma_advance(struct gr_ep *ep, int status) | ||
406 | { | ||
407 | struct gr_request *req; | ||
408 | |||
409 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
410 | gr_finish_request(ep, req, status); | ||
411 | gr_start_dma(ep); /* Regardless of ep->dma_start */ | ||
412 | } | ||
413 | |||
414 | /* | ||
415 | * Abort DMA for an endpoint. Sets the abort DMA bit which causes an ongoing DMA | ||
416 | * transfer to be canceled and clears GR_DMACTRL_DA. | ||
417 | * | ||
418 | * Must be called with dev->lock held. | ||
419 | */ | ||
420 | static void gr_abort_dma(struct gr_ep *ep) | ||
421 | { | ||
422 | u32 dmactrl; | ||
423 | |||
424 | dmactrl = gr_read32(&ep->regs->dmactrl); | ||
425 | gr_write32(&ep->regs->dmactrl, dmactrl | GR_DMACTRL_AD); | ||
426 | } | ||
427 | |||
428 | /* | ||
429 | * Allocates and sets up a struct gr_dma_desc and putting it on the descriptor | ||
430 | * chain. | ||
431 | * | ||
432 | * Size is not used for OUT endpoints. Hardware can not be instructed to handle | ||
433 | * smaller buffer than MAXPL in the OUT direction. | ||
434 | */ | ||
435 | static int gr_add_dma_desc(struct gr_ep *ep, struct gr_request *req, | ||
436 | dma_addr_t data, unsigned size, gfp_t gfp_flags) | ||
437 | { | ||
438 | struct gr_dma_desc *desc; | ||
439 | |||
440 | desc = gr_alloc_dma_desc(ep, gfp_flags); | ||
441 | if (!desc) | ||
442 | return -ENOMEM; | ||
443 | |||
444 | desc->data = data; | ||
445 | if (ep->is_in) | ||
446 | desc->ctrl = | ||
447 | (GR_DESC_IN_CTRL_LEN_MASK & size) | GR_DESC_IN_CTRL_EN; | ||
448 | else | ||
449 | desc->ctrl = GR_DESC_OUT_CTRL_IE; | ||
450 | |||
451 | if (!req->first_desc) { | ||
452 | req->first_desc = desc; | ||
453 | req->curr_desc = desc; | ||
454 | } else { | ||
455 | req->last_desc->next_desc = desc; | ||
456 | req->last_desc->next = desc->paddr; | ||
457 | req->last_desc->ctrl |= GR_DESC_OUT_CTRL_NX; | ||
458 | } | ||
459 | req->last_desc = desc; | ||
460 | |||
461 | return 0; | ||
462 | } | ||
463 | |||
464 | /* | ||
465 | * Sets up a chain of struct gr_dma_descriptors pointing to buffers that | ||
466 | * together covers req->req.length bytes of the buffer at DMA address | ||
467 | * req->req.dma for the OUT direction. | ||
468 | * | ||
469 | * The first descriptor in the chain is enabled, the rest disabled. The | ||
470 | * interrupt handler will later enable them one by one when needed so we can | ||
471 | * find out when the transfer is finished. For OUT endpoints, all descriptors | ||
472 | * therefore generate interrutps. | ||
473 | */ | ||
474 | static int gr_setup_out_desc_list(struct gr_ep *ep, struct gr_request *req, | ||
475 | gfp_t gfp_flags) | ||
476 | { | ||
477 | u16 bytes_left; /* Bytes left to provide descriptors for */ | ||
478 | u16 bytes_used; /* Bytes accommodated for */ | ||
479 | int ret = 0; | ||
480 | |||
481 | req->first_desc = NULL; /* Signals that no allocation is done yet */ | ||
482 | bytes_left = req->req.length; | ||
483 | bytes_used = 0; | ||
484 | while (bytes_left > 0) { | ||
485 | dma_addr_t start = req->req.dma + bytes_used; | ||
486 | u16 size = min(bytes_left, ep->bytes_per_buffer); | ||
487 | |||
488 | /* Should not happen however - gr_queue stops such lengths */ | ||
489 | if (size < ep->bytes_per_buffer) | ||
490 | dev_warn(ep->dev->dev, | ||
491 | "Buffer overrun risk: %u < %u bytes/buffer\n", | ||
492 | size, ep->bytes_per_buffer); | ||
493 | |||
494 | ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); | ||
495 | if (ret) | ||
496 | goto alloc_err; | ||
497 | |||
498 | bytes_left -= size; | ||
499 | bytes_used += size; | ||
500 | } | ||
501 | |||
502 | req->first_desc->ctrl |= GR_DESC_OUT_CTRL_EN; | ||
503 | |||
504 | return 0; | ||
505 | |||
506 | alloc_err: | ||
507 | gr_free_dma_desc_chain(ep->dev, req); | ||
508 | |||
509 | return ret; | ||
510 | } | ||
511 | |||
512 | /* | ||
513 | * Sets up a chain of struct gr_dma_descriptors pointing to buffers that | ||
514 | * together covers req->req.length bytes of the buffer at DMA address | ||
515 | * req->req.dma for the IN direction. | ||
516 | * | ||
517 | * When more data is provided than the maximum payload size, the hardware splits | ||
518 | * this up into several payloads automatically. Moreover, ep->bytes_per_buffer | ||
519 | * is always set to a multiple of the maximum payload (restricted to the valid | ||
520 | * number of maximum payloads during high bandwidth isochronous or interrupt | ||
521 | * transfers) | ||
522 | * | ||
523 | * All descriptors are enabled from the beginning and we only generate an | ||
524 | * interrupt for the last one indicating that the entire request has been pushed | ||
525 | * to hardware. | ||
526 | */ | ||
527 | static int gr_setup_in_desc_list(struct gr_ep *ep, struct gr_request *req, | ||
528 | gfp_t gfp_flags) | ||
529 | { | ||
530 | u16 bytes_left; /* Bytes left in req to provide descriptors for */ | ||
531 | u16 bytes_used; /* Bytes in req accommodated for */ | ||
532 | int ret = 0; | ||
533 | |||
534 | req->first_desc = NULL; /* Signals that no allocation is done yet */ | ||
535 | bytes_left = req->req.length; | ||
536 | bytes_used = 0; | ||
537 | do { /* Allow for zero length packets */ | ||
538 | dma_addr_t start = req->req.dma + bytes_used; | ||
539 | u16 size = min(bytes_left, ep->bytes_per_buffer); | ||
540 | |||
541 | ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); | ||
542 | if (ret) | ||
543 | goto alloc_err; | ||
544 | |||
545 | bytes_left -= size; | ||
546 | bytes_used += size; | ||
547 | } while (bytes_left > 0); | ||
548 | |||
549 | /* | ||
550 | * Send an extra zero length packet to indicate that no more data is | ||
551 | * available when req->req.zero is set and the data length is even | ||
552 | * multiples of ep->ep.maxpacket. | ||
553 | */ | ||
554 | if (req->req.zero && (req->req.length % ep->ep.maxpacket == 0)) { | ||
555 | ret = gr_add_dma_desc(ep, req, 0, 0, gfp_flags); | ||
556 | if (ret) | ||
557 | goto alloc_err; | ||
558 | } | ||
559 | |||
560 | /* | ||
561 | * For IN packets we only want to know when the last packet has been | ||
562 | * transmitted (not just put into internal buffers). | ||
563 | */ | ||
564 | req->last_desc->ctrl |= GR_DESC_IN_CTRL_PI; | ||
565 | |||
566 | return 0; | ||
567 | |||
568 | alloc_err: | ||
569 | gr_free_dma_desc_chain(ep->dev, req); | ||
570 | |||
571 | return ret; | ||
572 | } | ||
573 | |||
574 | /* Must be called with dev->lock held */ | ||
575 | static int gr_queue(struct gr_ep *ep, struct gr_request *req, gfp_t gfp_flags) | ||
576 | { | ||
577 | struct gr_udc *dev = ep->dev; | ||
578 | int ret; | ||
579 | |||
580 | if (unlikely(!ep->ep.desc && ep->num != 0)) { | ||
581 | dev_err(dev->dev, "No ep descriptor for %s\n", ep->ep.name); | ||
582 | return -EINVAL; | ||
583 | } | ||
584 | |||
585 | if (unlikely(!req->req.buf || !list_empty(&req->queue))) { | ||
586 | dev_err(dev->dev, | ||
587 | "Invalid request for %s: buf=%p list_empty=%d\n", | ||
588 | ep->ep.name, req->req.buf, list_empty(&req->queue)); | ||
589 | return -EINVAL; | ||
590 | } | ||
591 | |||
592 | /* | ||
593 | * The DMA controller can not handle smaller OUT buffers than | ||
594 | * maxpacket. It could lead to buffer overruns if unexpectedly long | ||
595 | * packet are received. | ||
596 | */ | ||
597 | if (!ep->is_in && (req->req.length % ep->ep.maxpacket) != 0) { | ||
598 | dev_err(dev->dev, | ||
599 | "OUT request length %d is not multiple of maxpacket\n", | ||
600 | req->req.length); | ||
601 | return -EMSGSIZE; | ||
602 | } | ||
603 | |||
604 | if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { | ||
605 | dev_err(dev->dev, "-ESHUTDOWN"); | ||
606 | return -ESHUTDOWN; | ||
607 | } | ||
608 | |||
609 | /* Can't touch registers when suspended */ | ||
610 | if (dev->ep0state == GR_EP0_SUSPEND) { | ||
611 | dev_err(dev->dev, "-EBUSY"); | ||
612 | return -EBUSY; | ||
613 | } | ||
614 | |||
615 | /* Set up DMA mapping in case the caller didn't */ | ||
616 | ret = usb_gadget_map_request(&dev->gadget, &req->req, ep->is_in); | ||
617 | if (ret) { | ||
618 | dev_err(dev->dev, "usb_gadget_map_request"); | ||
619 | return ret; | ||
620 | } | ||
621 | |||
622 | if (ep->is_in) | ||
623 | ret = gr_setup_in_desc_list(ep, req, gfp_flags); | ||
624 | else | ||
625 | ret = gr_setup_out_desc_list(ep, req, gfp_flags); | ||
626 | if (ret) | ||
627 | return ret; | ||
628 | |||
629 | req->req.status = -EINPROGRESS; | ||
630 | req->req.actual = 0; | ||
631 | list_add_tail(&req->queue, &ep->queue); | ||
632 | |||
633 | /* Start DMA if not started, otherwise interrupt handler handles it */ | ||
634 | if (!ep->dma_start && likely(!ep->stopped)) | ||
635 | gr_start_dma(ep); | ||
636 | |||
637 | return 0; | ||
638 | } | ||
639 | |||
640 | /* | ||
641 | * Queue a request from within the driver. | ||
642 | * | ||
643 | * Must be called with dev->lock held. | ||
644 | */ | ||
645 | static inline int gr_queue_int(struct gr_ep *ep, struct gr_request *req, | ||
646 | gfp_t gfp_flags) | ||
647 | { | ||
648 | if (ep->is_in) | ||
649 | gr_dbgprint_request("RESP", ep, req); | ||
650 | |||
651 | return gr_queue(ep, req, gfp_flags); | ||
652 | } | ||
653 | |||
654 | /* ---------------------------------------------------------------------- */ | ||
655 | /* General helper functions */ | ||
656 | |||
657 | /* | ||
658 | * Dequeue ALL requests. | ||
659 | * | ||
660 | * Must be called with dev->lock held and irqs disabled. | ||
661 | */ | ||
662 | static void gr_ep_nuke(struct gr_ep *ep) | ||
663 | { | ||
664 | struct gr_request *req; | ||
665 | |||
666 | ep->stopped = 1; | ||
667 | ep->dma_start = 0; | ||
668 | gr_abort_dma(ep); | ||
669 | |||
670 | while (!list_empty(&ep->queue)) { | ||
671 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
672 | gr_finish_request(ep, req, -ESHUTDOWN); | ||
673 | } | ||
674 | } | ||
675 | |||
676 | /* | ||
677 | * Reset the hardware state of this endpoint. | ||
678 | * | ||
679 | * Must be called with dev->lock held. | ||
680 | */ | ||
681 | static void gr_ep_reset(struct gr_ep *ep) | ||
682 | { | ||
683 | gr_write32(&ep->regs->epctrl, 0); | ||
684 | gr_write32(&ep->regs->dmactrl, 0); | ||
685 | |||
686 | ep->ep.maxpacket = MAX_CTRL_PL_SIZE; | ||
687 | ep->ep.desc = NULL; | ||
688 | ep->stopped = 1; | ||
689 | ep->dma_start = 0; | ||
690 | } | ||
691 | |||
692 | /* | ||
693 | * Generate STALL on ep0in/out. | ||
694 | * | ||
695 | * Must be called with dev->lock held. | ||
696 | */ | ||
697 | static void gr_control_stall(struct gr_udc *dev) | ||
698 | { | ||
699 | u32 epctrl; | ||
700 | |||
701 | epctrl = gr_read32(&dev->epo[0].regs->epctrl); | ||
702 | gr_write32(&dev->epo[0].regs->epctrl, epctrl | GR_EPCTRL_CS); | ||
703 | epctrl = gr_read32(&dev->epi[0].regs->epctrl); | ||
704 | gr_write32(&dev->epi[0].regs->epctrl, epctrl | GR_EPCTRL_CS); | ||
705 | |||
706 | dev->ep0state = GR_EP0_STALL; | ||
707 | } | ||
708 | |||
709 | /* | ||
710 | * Halts, halts and wedges, or clears halt for an endpoint. | ||
711 | * | ||
712 | * Must be called with dev->lock held. | ||
713 | */ | ||
714 | static int gr_ep_halt_wedge(struct gr_ep *ep, int halt, int wedge, int fromhost) | ||
715 | { | ||
716 | u32 epctrl; | ||
717 | int retval = 0; | ||
718 | |||
719 | if (ep->num && !ep->ep.desc) | ||
720 | return -EINVAL; | ||
721 | |||
722 | if (ep->num && ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) | ||
723 | return -EOPNOTSUPP; | ||
724 | |||
725 | /* Never actually halt ep0, and therefore never clear halt for ep0 */ | ||
726 | if (!ep->num) { | ||
727 | if (halt && !fromhost) { | ||
728 | /* ep0 halt from gadget - generate protocol stall */ | ||
729 | gr_control_stall(ep->dev); | ||
730 | dev_dbg(ep->dev->dev, "EP: stall ep0\n"); | ||
731 | return 0; | ||
732 | } | ||
733 | return -EINVAL; | ||
734 | } | ||
735 | |||
736 | dev_dbg(ep->dev->dev, "EP: %s halt %s\n", | ||
737 | (halt ? (wedge ? "wedge" : "set") : "clear"), ep->ep.name); | ||
738 | |||
739 | epctrl = gr_read32(&ep->regs->epctrl); | ||
740 | if (halt) { | ||
741 | /* Set HALT */ | ||
742 | gr_write32(&ep->regs->epctrl, epctrl | GR_EPCTRL_EH); | ||
743 | ep->stopped = 1; | ||
744 | if (wedge) | ||
745 | ep->wedged = 1; | ||
746 | } else { | ||
747 | gr_write32(&ep->regs->epctrl, epctrl & ~GR_EPCTRL_EH); | ||
748 | ep->stopped = 0; | ||
749 | ep->wedged = 0; | ||
750 | |||
751 | /* Things might have been queued up in the meantime */ | ||
752 | if (!ep->dma_start) | ||
753 | gr_start_dma(ep); | ||
754 | } | ||
755 | |||
756 | return retval; | ||
757 | } | ||
758 | |||
759 | /* Must be called with dev->lock held */ | ||
760 | static inline void gr_set_ep0state(struct gr_udc *dev, enum gr_ep0state value) | ||
761 | { | ||
762 | if (dev->ep0state != value) | ||
763 | dev_vdbg(dev->dev, "STATE: ep0state=%s\n", | ||
764 | gr_ep0state_string(value)); | ||
765 | dev->ep0state = value; | ||
766 | } | ||
767 | |||
768 | /* | ||
769 | * Should only be called when endpoints can not generate interrupts. | ||
770 | * | ||
771 | * Must be called with dev->lock held. | ||
772 | */ | ||
773 | static void gr_disable_interrupts_and_pullup(struct gr_udc *dev) | ||
774 | { | ||
775 | gr_write32(&dev->regs->control, 0); | ||
776 | wmb(); /* Make sure that we do not deny one of our interrupts */ | ||
777 | dev->irq_enabled = 0; | ||
778 | } | ||
779 | |||
780 | /* | ||
781 | * Stop all device activity and disable data line pullup. | ||
782 | * | ||
783 | * Must be called with dev->lock held and irqs disabled. | ||
784 | */ | ||
785 | static void gr_stop_activity(struct gr_udc *dev) | ||
786 | { | ||
787 | struct gr_ep *ep; | ||
788 | |||
789 | list_for_each_entry(ep, &dev->ep_list, ep_list) | ||
790 | gr_ep_nuke(ep); | ||
791 | |||
792 | gr_disable_interrupts_and_pullup(dev); | ||
793 | |||
794 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); | ||
795 | usb_gadget_set_state(&dev->gadget, USB_STATE_NOTATTACHED); | ||
796 | } | ||
797 | |||
798 | /* ---------------------------------------------------------------------- */ | ||
799 | /* ep0 setup packet handling */ | ||
800 | |||
801 | static void gr_ep0_testmode_complete(struct usb_ep *_ep, | ||
802 | struct usb_request *_req) | ||
803 | { | ||
804 | struct gr_ep *ep; | ||
805 | struct gr_udc *dev; | ||
806 | u32 control; | ||
807 | |||
808 | ep = container_of(_ep, struct gr_ep, ep); | ||
809 | dev = ep->dev; | ||
810 | |||
811 | spin_lock(&dev->lock); | ||
812 | |||
813 | control = gr_read32(&dev->regs->control); | ||
814 | control |= GR_CONTROL_TM | (dev->test_mode << GR_CONTROL_TS_POS); | ||
815 | gr_write32(&dev->regs->control, control); | ||
816 | |||
817 | spin_unlock(&dev->lock); | ||
818 | } | ||
819 | |||
820 | static void gr_ep0_dummy_complete(struct usb_ep *_ep, struct usb_request *_req) | ||
821 | { | ||
822 | /* Nothing needs to be done here */ | ||
823 | } | ||
824 | |||
825 | /* | ||
826 | * Queue a response on ep0in. | ||
827 | * | ||
828 | * Must be called with dev->lock held. | ||
829 | */ | ||
830 | static int gr_ep0_respond(struct gr_udc *dev, u8 *buf, int length, | ||
831 | void (*complete)(struct usb_ep *ep, | ||
832 | struct usb_request *req)) | ||
833 | { | ||
834 | u8 *reqbuf = dev->ep0reqi->req.buf; | ||
835 | int status; | ||
836 | int i; | ||
837 | |||
838 | for (i = 0; i < length; i++) | ||
839 | reqbuf[i] = buf[i]; | ||
840 | dev->ep0reqi->req.length = length; | ||
841 | dev->ep0reqi->req.complete = complete; | ||
842 | |||
843 | status = gr_queue_int(&dev->epi[0], dev->ep0reqi, GFP_ATOMIC); | ||
844 | if (status < 0) | ||
845 | dev_err(dev->dev, | ||
846 | "Could not queue ep0in setup response: %d\n", status); | ||
847 | |||
848 | return status; | ||
849 | } | ||
850 | |||
851 | /* | ||
852 | * Queue a 2 byte response on ep0in. | ||
853 | * | ||
854 | * Must be called with dev->lock held. | ||
855 | */ | ||
856 | static inline int gr_ep0_respond_u16(struct gr_udc *dev, u16 response) | ||
857 | { | ||
858 | __le16 le_response = cpu_to_le16(response); | ||
859 | |||
860 | return gr_ep0_respond(dev, (u8 *)&le_response, 2, | ||
861 | gr_ep0_dummy_complete); | ||
862 | } | ||
863 | |||
864 | /* | ||
865 | * Queue a ZLP response on ep0in. | ||
866 | * | ||
867 | * Must be called with dev->lock held. | ||
868 | */ | ||
869 | static inline int gr_ep0_respond_empty(struct gr_udc *dev) | ||
870 | { | ||
871 | return gr_ep0_respond(dev, NULL, 0, gr_ep0_dummy_complete); | ||
872 | } | ||
873 | |||
874 | /* | ||
875 | * This is run when a SET_ADDRESS request is received. First writes | ||
876 | * the new address to the control register which is updated internally | ||
877 | * when the next IN packet is ACKED. | ||
878 | * | ||
879 | * Must be called with dev->lock held. | ||
880 | */ | ||
881 | static void gr_set_address(struct gr_udc *dev, u8 address) | ||
882 | { | ||
883 | u32 control; | ||
884 | |||
885 | control = gr_read32(&dev->regs->control) & ~GR_CONTROL_UA_MASK; | ||
886 | control |= (address << GR_CONTROL_UA_POS) & GR_CONTROL_UA_MASK; | ||
887 | control |= GR_CONTROL_SU; | ||
888 | gr_write32(&dev->regs->control, control); | ||
889 | } | ||
890 | |||
891 | /* | ||
892 | * Returns negative for STALL, 0 for successful handling and positive for | ||
893 | * delegation. | ||
894 | * | ||
895 | * Must be called with dev->lock held. | ||
896 | */ | ||
897 | static int gr_device_request(struct gr_udc *dev, u8 type, u8 request, | ||
898 | u16 value, u16 index) | ||
899 | { | ||
900 | u16 response; | ||
901 | u8 test; | ||
902 | |||
903 | switch (request) { | ||
904 | case USB_REQ_SET_ADDRESS: | ||
905 | dev_dbg(dev->dev, "STATUS: address %d\n", value & 0xff); | ||
906 | gr_set_address(dev, value & 0xff); | ||
907 | if (value) | ||
908 | usb_gadget_set_state(&dev->gadget, USB_STATE_ADDRESS); | ||
909 | else | ||
910 | usb_gadget_set_state(&dev->gadget, USB_STATE_DEFAULT); | ||
911 | return gr_ep0_respond_empty(dev); | ||
912 | |||
913 | case USB_REQ_GET_STATUS: | ||
914 | /* Self powered | remote wakeup */ | ||
915 | response = 0x0001 | (dev->remote_wakeup ? 0x0002 : 0); | ||
916 | return gr_ep0_respond_u16(dev, response); | ||
917 | |||
918 | case USB_REQ_SET_FEATURE: | ||
919 | switch (value) { | ||
920 | case USB_DEVICE_REMOTE_WAKEUP: | ||
921 | /* Allow remote wakeup */ | ||
922 | dev->remote_wakeup = 1; | ||
923 | return gr_ep0_respond_empty(dev); | ||
924 | |||
925 | case USB_DEVICE_TEST_MODE: | ||
926 | /* The hardware does not support TEST_FORCE_EN */ | ||
927 | test = index >> 8; | ||
928 | if (test >= TEST_J && test <= TEST_PACKET) { | ||
929 | dev->test_mode = test; | ||
930 | return gr_ep0_respond(dev, NULL, 0, | ||
931 | gr_ep0_testmode_complete); | ||
932 | } | ||
933 | } | ||
934 | break; | ||
935 | |||
936 | case USB_REQ_CLEAR_FEATURE: | ||
937 | switch (value) { | ||
938 | case USB_DEVICE_REMOTE_WAKEUP: | ||
939 | /* Disallow remote wakeup */ | ||
940 | dev->remote_wakeup = 0; | ||
941 | return gr_ep0_respond_empty(dev); | ||
942 | } | ||
943 | break; | ||
944 | } | ||
945 | |||
946 | return 1; /* Delegate the rest */ | ||
947 | } | ||
948 | |||
949 | /* | ||
950 | * Returns negative for STALL, 0 for successful handling and positive for | ||
951 | * delegation. | ||
952 | * | ||
953 | * Must be called with dev->lock held. | ||
954 | */ | ||
955 | static int gr_interface_request(struct gr_udc *dev, u8 type, u8 request, | ||
956 | u16 value, u16 index) | ||
957 | { | ||
958 | if (dev->gadget.state != USB_STATE_CONFIGURED) | ||
959 | return -1; | ||
960 | |||
961 | /* | ||
962 | * Should return STALL for invalid interfaces, but udc driver does not | ||
963 | * know anything about that. However, many gadget drivers do not handle | ||
964 | * GET_STATUS so we need to take care of that. | ||
965 | */ | ||
966 | |||
967 | switch (request) { | ||
968 | case USB_REQ_GET_STATUS: | ||
969 | return gr_ep0_respond_u16(dev, 0x0000); | ||
970 | |||
971 | case USB_REQ_SET_FEATURE: | ||
972 | case USB_REQ_CLEAR_FEATURE: | ||
973 | /* | ||
974 | * No possible valid standard requests. Still let gadget drivers | ||
975 | * have a go at it. | ||
976 | */ | ||
977 | break; | ||
978 | } | ||
979 | |||
980 | return 1; /* Delegate the rest */ | ||
981 | } | ||
982 | |||
983 | /* | ||
984 | * Returns negative for STALL, 0 for successful handling and positive for | ||
985 | * delegation. | ||
986 | * | ||
987 | * Must be called with dev->lock held. | ||
988 | */ | ||
989 | static int gr_endpoint_request(struct gr_udc *dev, u8 type, u8 request, | ||
990 | u16 value, u16 index) | ||
991 | { | ||
992 | struct gr_ep *ep; | ||
993 | int status; | ||
994 | int halted; | ||
995 | u8 epnum = index & USB_ENDPOINT_NUMBER_MASK; | ||
996 | u8 is_in = index & USB_ENDPOINT_DIR_MASK; | ||
997 | |||
998 | if ((is_in && epnum >= dev->nepi) || (!is_in && epnum >= dev->nepo)) | ||
999 | return -1; | ||
1000 | |||
1001 | if (dev->gadget.state != USB_STATE_CONFIGURED && epnum != 0) | ||
1002 | return -1; | ||
1003 | |||
1004 | ep = (is_in ? &dev->epi[epnum] : &dev->epo[epnum]); | ||
1005 | |||
1006 | switch (request) { | ||
1007 | case USB_REQ_GET_STATUS: | ||
1008 | halted = gr_read32(&ep->regs->epctrl) & GR_EPCTRL_EH; | ||
1009 | return gr_ep0_respond_u16(dev, halted ? 0x0001 : 0); | ||
1010 | |||
1011 | case USB_REQ_SET_FEATURE: | ||
1012 | switch (value) { | ||
1013 | case USB_ENDPOINT_HALT: | ||
1014 | status = gr_ep_halt_wedge(ep, 1, 0, 1); | ||
1015 | if (status >= 0) | ||
1016 | status = gr_ep0_respond_empty(dev); | ||
1017 | return status; | ||
1018 | } | ||
1019 | break; | ||
1020 | |||
1021 | case USB_REQ_CLEAR_FEATURE: | ||
1022 | switch (value) { | ||
1023 | case USB_ENDPOINT_HALT: | ||
1024 | if (ep->wedged) | ||
1025 | return -1; | ||
1026 | status = gr_ep_halt_wedge(ep, 0, 0, 1); | ||
1027 | if (status >= 0) | ||
1028 | status = gr_ep0_respond_empty(dev); | ||
1029 | return status; | ||
1030 | } | ||
1031 | break; | ||
1032 | } | ||
1033 | |||
1034 | return 1; /* Delegate the rest */ | ||
1035 | } | ||
1036 | |||
1037 | /* Must be called with dev->lock held */ | ||
1038 | static void gr_ep0out_requeue(struct gr_udc *dev) | ||
1039 | { | ||
1040 | int ret = gr_queue_int(&dev->epo[0], dev->ep0reqo, GFP_ATOMIC); | ||
1041 | |||
1042 | if (ret) | ||
1043 | dev_err(dev->dev, "Could not queue ep0out setup request: %d\n", | ||
1044 | ret); | ||
1045 | } | ||
1046 | |||
1047 | /* | ||
1048 | * The main function dealing with setup requests on ep0. | ||
1049 | * | ||
1050 | * Must be called with dev->lock held and irqs disabled | ||
1051 | */ | ||
1052 | static void gr_ep0_setup(struct gr_udc *dev, struct gr_request *req) | ||
1053 | __releases(&dev->lock) | ||
1054 | __acquires(&dev->lock) | ||
1055 | { | ||
1056 | union { | ||
1057 | struct usb_ctrlrequest ctrl; | ||
1058 | u8 raw[8]; | ||
1059 | u32 word[2]; | ||
1060 | } u; | ||
1061 | u8 type; | ||
1062 | u8 request; | ||
1063 | u16 value; | ||
1064 | u16 index; | ||
1065 | u16 length; | ||
1066 | int i; | ||
1067 | int status; | ||
1068 | |||
1069 | /* Restore from ep0 halt */ | ||
1070 | if (dev->ep0state == GR_EP0_STALL) { | ||
1071 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1072 | if (!req->req.actual) | ||
1073 | goto out; | ||
1074 | } | ||
1075 | |||
1076 | if (dev->ep0state == GR_EP0_ISTATUS) { | ||
1077 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1078 | if (req->req.actual > 0) | ||
1079 | dev_dbg(dev->dev, | ||
1080 | "Unexpected setup packet at state %s\n", | ||
1081 | gr_ep0state_string(GR_EP0_ISTATUS)); | ||
1082 | else | ||
1083 | goto out; /* Got expected ZLP */ | ||
1084 | } else if (dev->ep0state != GR_EP0_SETUP) { | ||
1085 | dev_info(dev->dev, | ||
1086 | "Unexpected ep0out request at state %s - stalling\n", | ||
1087 | gr_ep0state_string(dev->ep0state)); | ||
1088 | gr_control_stall(dev); | ||
1089 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1090 | goto out; | ||
1091 | } else if (!req->req.actual) { | ||
1092 | dev_dbg(dev->dev, "Unexpected ZLP at state %s\n", | ||
1093 | gr_ep0state_string(dev->ep0state)); | ||
1094 | goto out; | ||
1095 | } | ||
1096 | |||
1097 | /* Handle SETUP packet */ | ||
1098 | for (i = 0; i < req->req.actual; i++) | ||
1099 | u.raw[i] = ((u8 *)req->req.buf)[i]; | ||
1100 | |||
1101 | type = u.ctrl.bRequestType; | ||
1102 | request = u.ctrl.bRequest; | ||
1103 | value = le16_to_cpu(u.ctrl.wValue); | ||
1104 | index = le16_to_cpu(u.ctrl.wIndex); | ||
1105 | length = le16_to_cpu(u.ctrl.wLength); | ||
1106 | |||
1107 | gr_dbgprint_devreq(dev, type, request, value, index, length); | ||
1108 | |||
1109 | /* Check for data stage */ | ||
1110 | if (length) { | ||
1111 | if (type & USB_DIR_IN) | ||
1112 | gr_set_ep0state(dev, GR_EP0_IDATA); | ||
1113 | else | ||
1114 | gr_set_ep0state(dev, GR_EP0_ODATA); | ||
1115 | } | ||
1116 | |||
1117 | status = 1; /* Positive status flags delegation */ | ||
1118 | if ((type & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | ||
1119 | switch (type & USB_RECIP_MASK) { | ||
1120 | case USB_RECIP_DEVICE: | ||
1121 | status = gr_device_request(dev, type, request, | ||
1122 | value, index); | ||
1123 | break; | ||
1124 | case USB_RECIP_ENDPOINT: | ||
1125 | status = gr_endpoint_request(dev, type, request, | ||
1126 | value, index); | ||
1127 | break; | ||
1128 | case USB_RECIP_INTERFACE: | ||
1129 | status = gr_interface_request(dev, type, request, | ||
1130 | value, index); | ||
1131 | break; | ||
1132 | } | ||
1133 | } | ||
1134 | |||
1135 | if (status > 0) { | ||
1136 | spin_unlock(&dev->lock); | ||
1137 | |||
1138 | dev_vdbg(dev->dev, "DELEGATE\n"); | ||
1139 | status = dev->driver->setup(&dev->gadget, &u.ctrl); | ||
1140 | |||
1141 | spin_lock(&dev->lock); | ||
1142 | } | ||
1143 | |||
1144 | /* Generate STALL on both ep0out and ep0in if requested */ | ||
1145 | if (unlikely(status < 0)) { | ||
1146 | dev_vdbg(dev->dev, "STALL\n"); | ||
1147 | gr_control_stall(dev); | ||
1148 | } | ||
1149 | |||
1150 | if ((type & USB_TYPE_MASK) == USB_TYPE_STANDARD && | ||
1151 | request == USB_REQ_SET_CONFIGURATION) { | ||
1152 | if (!value) { | ||
1153 | dev_dbg(dev->dev, "STATUS: deconfigured\n"); | ||
1154 | usb_gadget_set_state(&dev->gadget, USB_STATE_ADDRESS); | ||
1155 | } else if (status >= 0) { | ||
1156 | /* Not configured unless gadget OK:s it */ | ||
1157 | dev_dbg(dev->dev, "STATUS: configured: %d\n", value); | ||
1158 | usb_gadget_set_state(&dev->gadget, | ||
1159 | USB_STATE_CONFIGURED); | ||
1160 | } | ||
1161 | } | ||
1162 | |||
1163 | /* Get ready for next stage */ | ||
1164 | if (dev->ep0state == GR_EP0_ODATA) | ||
1165 | gr_set_ep0state(dev, GR_EP0_OSTATUS); | ||
1166 | else if (dev->ep0state == GR_EP0_IDATA) | ||
1167 | gr_set_ep0state(dev, GR_EP0_ISTATUS); | ||
1168 | else | ||
1169 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1170 | |||
1171 | out: | ||
1172 | gr_ep0out_requeue(dev); | ||
1173 | } | ||
1174 | |||
1175 | /* ---------------------------------------------------------------------- */ | ||
1176 | /* VBUS and USB reset handling */ | ||
1177 | |||
1178 | /* Must be called with dev->lock held and irqs disabled */ | ||
1179 | static void gr_vbus_connected(struct gr_udc *dev, u32 status) | ||
1180 | { | ||
1181 | u32 control; | ||
1182 | |||
1183 | dev->gadget.speed = GR_SPEED(status); | ||
1184 | usb_gadget_set_state(&dev->gadget, USB_STATE_POWERED); | ||
1185 | |||
1186 | /* Turn on full interrupts and pullup */ | ||
1187 | control = (GR_CONTROL_SI | GR_CONTROL_UI | GR_CONTROL_VI | | ||
1188 | GR_CONTROL_SP | GR_CONTROL_EP); | ||
1189 | gr_write32(&dev->regs->control, control); | ||
1190 | } | ||
1191 | |||
1192 | /* Must be called with dev->lock held */ | ||
1193 | static void gr_enable_vbus_detect(struct gr_udc *dev) | ||
1194 | { | ||
1195 | u32 status; | ||
1196 | |||
1197 | dev->irq_enabled = 1; | ||
1198 | wmb(); /* Make sure we do not ignore an interrupt */ | ||
1199 | gr_write32(&dev->regs->control, GR_CONTROL_VI); | ||
1200 | |||
1201 | /* Take care of the case we are already plugged in at this point */ | ||
1202 | status = gr_read32(&dev->regs->status); | ||
1203 | if (status & GR_STATUS_VB) | ||
1204 | gr_vbus_connected(dev, status); | ||
1205 | } | ||
1206 | |||
1207 | /* Must be called with dev->lock held and irqs disabled */ | ||
1208 | static void gr_vbus_disconnected(struct gr_udc *dev) | ||
1209 | { | ||
1210 | gr_stop_activity(dev); | ||
1211 | |||
1212 | /* Report disconnect */ | ||
1213 | if (dev->driver && dev->driver->disconnect) { | ||
1214 | spin_unlock(&dev->lock); | ||
1215 | |||
1216 | dev->driver->disconnect(&dev->gadget); | ||
1217 | |||
1218 | spin_lock(&dev->lock); | ||
1219 | } | ||
1220 | |||
1221 | gr_enable_vbus_detect(dev); | ||
1222 | } | ||
1223 | |||
1224 | /* Must be called with dev->lock held and irqs disabled */ | ||
1225 | static void gr_udc_usbreset(struct gr_udc *dev, u32 status) | ||
1226 | { | ||
1227 | gr_set_address(dev, 0); | ||
1228 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1229 | usb_gadget_set_state(&dev->gadget, USB_STATE_DEFAULT); | ||
1230 | dev->gadget.speed = GR_SPEED(status); | ||
1231 | |||
1232 | gr_ep_nuke(&dev->epo[0]); | ||
1233 | gr_ep_nuke(&dev->epi[0]); | ||
1234 | dev->epo[0].stopped = 0; | ||
1235 | dev->epi[0].stopped = 0; | ||
1236 | gr_ep0out_requeue(dev); | ||
1237 | } | ||
1238 | |||
1239 | /* ---------------------------------------------------------------------- */ | ||
1240 | /* Irq handling */ | ||
1241 | |||
1242 | /* | ||
1243 | * Handles interrupts from in endpoints. Returns whether something was handled. | ||
1244 | * | ||
1245 | * Must be called with dev->lock held, irqs disabled and with !ep->stopped. | ||
1246 | */ | ||
1247 | static int gr_handle_in_ep(struct gr_ep *ep) | ||
1248 | { | ||
1249 | struct gr_request *req; | ||
1250 | |||
1251 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
1252 | if (!req->last_desc) | ||
1253 | return 0; | ||
1254 | |||
1255 | if (ACCESS_ONCE(req->last_desc->ctrl) & GR_DESC_IN_CTRL_EN) | ||
1256 | return 0; /* Not put in hardware buffers yet */ | ||
1257 | |||
1258 | if (gr_read32(&ep->regs->epstat) & (GR_EPSTAT_B1 | GR_EPSTAT_B0)) | ||
1259 | return 0; /* Not transmitted yet, still in hardware buffers */ | ||
1260 | |||
1261 | /* Write complete */ | ||
1262 | gr_dma_advance(ep, 0); | ||
1263 | |||
1264 | return 1; | ||
1265 | } | ||
1266 | |||
1267 | /* | ||
1268 | * Handles interrupts from out endpoints. Returns whether something was handled. | ||
1269 | * | ||
1270 | * Must be called with dev->lock held, irqs disabled and with !ep->stopped. | ||
1271 | */ | ||
1272 | static int gr_handle_out_ep(struct gr_ep *ep) | ||
1273 | { | ||
1274 | u32 ep_dmactrl; | ||
1275 | u32 ctrl; | ||
1276 | u16 len; | ||
1277 | struct gr_request *req; | ||
1278 | struct gr_udc *dev = ep->dev; | ||
1279 | |||
1280 | req = list_first_entry(&ep->queue, struct gr_request, queue); | ||
1281 | if (!req->curr_desc) | ||
1282 | return 0; | ||
1283 | |||
1284 | ctrl = ACCESS_ONCE(req->curr_desc->ctrl); | ||
1285 | if (ctrl & GR_DESC_OUT_CTRL_EN) | ||
1286 | return 0; /* Not received yet */ | ||
1287 | |||
1288 | /* Read complete */ | ||
1289 | len = ctrl & GR_DESC_OUT_CTRL_LEN_MASK; | ||
1290 | req->req.actual += len; | ||
1291 | if (ctrl & GR_DESC_OUT_CTRL_SE) | ||
1292 | req->setup = 1; | ||
1293 | |||
1294 | if (len < ep->ep.maxpacket || req->req.actual == req->req.length) { | ||
1295 | /* Short packet or the expected size - we are done */ | ||
1296 | |||
1297 | if ((ep == &dev->epo[0]) && (dev->ep0state == GR_EP0_OSTATUS)) { | ||
1298 | /* | ||
1299 | * Send a status stage ZLP to ack the DATA stage in the | ||
1300 | * OUT direction. This needs to be done before | ||
1301 | * gr_dma_advance as that can lead to a call to | ||
1302 | * ep0_setup that can change dev->ep0state. | ||
1303 | */ | ||
1304 | gr_ep0_respond_empty(dev); | ||
1305 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1306 | } | ||
1307 | |||
1308 | gr_dma_advance(ep, 0); | ||
1309 | } else { | ||
1310 | /* Not done yet. Enable the next descriptor to receive more. */ | ||
1311 | req->curr_desc = req->curr_desc->next_desc; | ||
1312 | req->curr_desc->ctrl |= GR_DESC_OUT_CTRL_EN; | ||
1313 | |||
1314 | ep_dmactrl = gr_read32(&ep->regs->dmactrl); | ||
1315 | gr_write32(&ep->regs->dmactrl, ep_dmactrl | GR_DMACTRL_DA); | ||
1316 | } | ||
1317 | |||
1318 | return 1; | ||
1319 | } | ||
1320 | |||
1321 | /* | ||
1322 | * Handle state changes. Returns whether something was handled. | ||
1323 | * | ||
1324 | * Must be called with dev->lock held and irqs disabled. | ||
1325 | */ | ||
1326 | static int gr_handle_state_changes(struct gr_udc *dev) | ||
1327 | { | ||
1328 | u32 status = gr_read32(&dev->regs->status); | ||
1329 | int handled = 0; | ||
1330 | int powstate = !(dev->gadget.state == USB_STATE_NOTATTACHED || | ||
1331 | dev->gadget.state == USB_STATE_ATTACHED); | ||
1332 | |||
1333 | /* VBUS valid detected */ | ||
1334 | if (!powstate && (status & GR_STATUS_VB)) { | ||
1335 | dev_dbg(dev->dev, "STATUS: vbus valid detected\n"); | ||
1336 | gr_vbus_connected(dev, status); | ||
1337 | handled = 1; | ||
1338 | } | ||
1339 | |||
1340 | /* Disconnect */ | ||
1341 | if (powstate && !(status & GR_STATUS_VB)) { | ||
1342 | dev_dbg(dev->dev, "STATUS: vbus invalid detected\n"); | ||
1343 | gr_vbus_disconnected(dev); | ||
1344 | handled = 1; | ||
1345 | } | ||
1346 | |||
1347 | /* USB reset detected */ | ||
1348 | if (status & GR_STATUS_UR) { | ||
1349 | dev_dbg(dev->dev, "STATUS: USB reset - speed is %s\n", | ||
1350 | GR_SPEED_STR(status)); | ||
1351 | gr_write32(&dev->regs->status, GR_STATUS_UR); | ||
1352 | gr_udc_usbreset(dev, status); | ||
1353 | handled = 1; | ||
1354 | } | ||
1355 | |||
1356 | /* Speed change */ | ||
1357 | if (dev->gadget.speed != GR_SPEED(status)) { | ||
1358 | dev_dbg(dev->dev, "STATUS: USB Speed change to %s\n", | ||
1359 | GR_SPEED_STR(status)); | ||
1360 | dev->gadget.speed = GR_SPEED(status); | ||
1361 | handled = 1; | ||
1362 | } | ||
1363 | |||
1364 | /* Going into suspend */ | ||
1365 | if ((dev->ep0state != GR_EP0_SUSPEND) && !(status & GR_STATUS_SU)) { | ||
1366 | dev_dbg(dev->dev, "STATUS: USB suspend\n"); | ||
1367 | gr_set_ep0state(dev, GR_EP0_SUSPEND); | ||
1368 | dev->suspended_from = dev->gadget.state; | ||
1369 | usb_gadget_set_state(&dev->gadget, USB_STATE_SUSPENDED); | ||
1370 | |||
1371 | if ((dev->gadget.speed != USB_SPEED_UNKNOWN) && | ||
1372 | dev->driver && dev->driver->suspend) { | ||
1373 | spin_unlock(&dev->lock); | ||
1374 | |||
1375 | dev->driver->suspend(&dev->gadget); | ||
1376 | |||
1377 | spin_lock(&dev->lock); | ||
1378 | } | ||
1379 | handled = 1; | ||
1380 | } | ||
1381 | |||
1382 | /* Coming out of suspend */ | ||
1383 | if ((dev->ep0state == GR_EP0_SUSPEND) && (status & GR_STATUS_SU)) { | ||
1384 | dev_dbg(dev->dev, "STATUS: USB resume\n"); | ||
1385 | if (dev->suspended_from == USB_STATE_POWERED) | ||
1386 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); | ||
1387 | else | ||
1388 | gr_set_ep0state(dev, GR_EP0_SETUP); | ||
1389 | usb_gadget_set_state(&dev->gadget, dev->suspended_from); | ||
1390 | |||
1391 | if ((dev->gadget.speed != USB_SPEED_UNKNOWN) && | ||
1392 | dev->driver && dev->driver->resume) { | ||
1393 | spin_unlock(&dev->lock); | ||
1394 | |||
1395 | dev->driver->resume(&dev->gadget); | ||
1396 | |||
1397 | spin_lock(&dev->lock); | ||
1398 | } | ||
1399 | handled = 1; | ||
1400 | } | ||
1401 | |||
1402 | return handled; | ||
1403 | } | ||
1404 | |||
1405 | /* Non-interrupt context irq handler */ | ||
1406 | static irqreturn_t gr_irq_handler(int irq, void *_dev) | ||
1407 | { | ||
1408 | struct gr_udc *dev = _dev; | ||
1409 | struct gr_ep *ep; | ||
1410 | int handled = 0; | ||
1411 | int i; | ||
1412 | unsigned long flags; | ||
1413 | |||
1414 | spin_lock_irqsave(&dev->lock, flags); | ||
1415 | |||
1416 | if (!dev->irq_enabled) | ||
1417 | goto out; | ||
1418 | |||
1419 | /* | ||
1420 | * Check IN ep interrupts. We check these before the OUT eps because | ||
1421 | * some gadgets reuse the request that might already be currently | ||
1422 | * outstanding and needs to be completed (mainly setup requests). | ||
1423 | */ | ||
1424 | for (i = 0; i < dev->nepi; i++) { | ||
1425 | ep = &dev->epi[i]; | ||
1426 | if (!ep->stopped && !ep->callback && !list_empty(&ep->queue)) | ||
1427 | handled = gr_handle_in_ep(ep) || handled; | ||
1428 | } | ||
1429 | |||
1430 | /* Check OUT ep interrupts */ | ||
1431 | for (i = 0; i < dev->nepo; i++) { | ||
1432 | ep = &dev->epo[i]; | ||
1433 | if (!ep->stopped && !ep->callback && !list_empty(&ep->queue)) | ||
1434 | handled = gr_handle_out_ep(ep) || handled; | ||
1435 | } | ||
1436 | |||
1437 | /* Check status interrupts */ | ||
1438 | handled = gr_handle_state_changes(dev) || handled; | ||
1439 | |||
1440 | /* | ||
1441 | * Check AMBA DMA errors. Only check if we didn't find anything else to | ||
1442 | * handle because this shouldn't happen if we did everything right. | ||
1443 | */ | ||
1444 | if (!handled) { | ||
1445 | list_for_each_entry(ep, &dev->ep_list, ep_list) { | ||
1446 | if (gr_read32(&ep->regs->dmactrl) & GR_DMACTRL_AE) { | ||
1447 | dev_err(dev->dev, | ||
1448 | "AMBA Error occurred for %s\n", | ||
1449 | ep->ep.name); | ||
1450 | handled = 1; | ||
1451 | } | ||
1452 | } | ||
1453 | } | ||
1454 | |||
1455 | out: | ||
1456 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1457 | |||
1458 | return handled ? IRQ_HANDLED : IRQ_NONE; | ||
1459 | } | ||
1460 | |||
1461 | /* Interrupt context irq handler */ | ||
1462 | static irqreturn_t gr_irq(int irq, void *_dev) | ||
1463 | { | ||
1464 | struct gr_udc *dev = _dev; | ||
1465 | |||
1466 | if (!dev->irq_enabled) | ||
1467 | return IRQ_NONE; | ||
1468 | |||
1469 | return IRQ_WAKE_THREAD; | ||
1470 | } | ||
1471 | |||
1472 | /* ---------------------------------------------------------------------- */ | ||
1473 | /* USB ep ops */ | ||
1474 | |||
1475 | /* Enable endpoint. Not for ep0in and ep0out that are handled separately. */ | ||
1476 | static int gr_ep_enable(struct usb_ep *_ep, | ||
1477 | const struct usb_endpoint_descriptor *desc) | ||
1478 | { | ||
1479 | struct gr_udc *dev; | ||
1480 | struct gr_ep *ep; | ||
1481 | u8 mode; | ||
1482 | u8 nt; | ||
1483 | u16 max; | ||
1484 | u16 buffer_size = 0; | ||
1485 | u32 epctrl; | ||
1486 | |||
1487 | ep = container_of(_ep, struct gr_ep, ep); | ||
1488 | if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) | ||
1489 | return -EINVAL; | ||
1490 | |||
1491 | dev = ep->dev; | ||
1492 | |||
1493 | /* 'ep0' IN and OUT are reserved */ | ||
1494 | if (ep == &dev->epo[0] || ep == &dev->epi[0]) | ||
1495 | return -EINVAL; | ||
1496 | |||
1497 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1498 | return -ESHUTDOWN; | ||
1499 | |||
1500 | /* Make sure we are clear for enabling */ | ||
1501 | epctrl = gr_read32(&ep->regs->epctrl); | ||
1502 | if (epctrl & GR_EPCTRL_EV) | ||
1503 | return -EBUSY; | ||
1504 | |||
1505 | /* Check that directions match */ | ||
1506 | if (!ep->is_in != !usb_endpoint_dir_in(desc)) | ||
1507 | return -EINVAL; | ||
1508 | |||
1509 | /* Check ep num */ | ||
1510 | if ((!ep->is_in && ep->num >= dev->nepo) || | ||
1511 | (ep->is_in && ep->num >= dev->nepi)) | ||
1512 | return -EINVAL; | ||
1513 | |||
1514 | if (usb_endpoint_xfer_control(desc)) { | ||
1515 | mode = 0; | ||
1516 | } else if (usb_endpoint_xfer_isoc(desc)) { | ||
1517 | mode = 1; | ||
1518 | } else if (usb_endpoint_xfer_bulk(desc)) { | ||
1519 | mode = 2; | ||
1520 | } else if (usb_endpoint_xfer_int(desc)) { | ||
1521 | mode = 3; | ||
1522 | } else { | ||
1523 | dev_err(dev->dev, "Unknown transfer type for %s\n", | ||
1524 | ep->ep.name); | ||
1525 | return -EINVAL; | ||
1526 | } | ||
1527 | |||
1528 | /* | ||
1529 | * Bits 10-0 set the max payload. 12-11 set the number of | ||
1530 | * additional transactions. | ||
1531 | */ | ||
1532 | max = 0x7ff & usb_endpoint_maxp(desc); | ||
1533 | nt = 0x3 & (usb_endpoint_maxp(desc) >> 11); | ||
1534 | buffer_size = GR_BUFFER_SIZE(epctrl); | ||
1535 | if (nt && (mode == 0 || mode == 2)) { | ||
1536 | dev_err(dev->dev, | ||
1537 | "%s mode: multiple trans./microframe not valid\n", | ||
1538 | (mode == 2 ? "Bulk" : "Control")); | ||
1539 | return -EINVAL; | ||
1540 | } else if (nt == 0x11) { | ||
1541 | dev_err(dev->dev, "Invalid value for trans./microframe\n"); | ||
1542 | return -EINVAL; | ||
1543 | } else if ((nt + 1) * max > buffer_size) { | ||
1544 | dev_err(dev->dev, "Hw buffer size %d < max payload %d * %d\n", | ||
1545 | buffer_size, (nt + 1), max); | ||
1546 | return -EINVAL; | ||
1547 | } else if (max == 0) { | ||
1548 | dev_err(dev->dev, "Max payload cannot be set to 0\n"); | ||
1549 | return -EINVAL; | ||
1550 | } | ||
1551 | |||
1552 | spin_lock(&ep->dev->lock); | ||
1553 | |||
1554 | if (!ep->stopped) { | ||
1555 | spin_unlock(&ep->dev->lock); | ||
1556 | return -EBUSY; | ||
1557 | } | ||
1558 | |||
1559 | ep->stopped = 0; | ||
1560 | ep->wedged = 0; | ||
1561 | ep->ep.desc = desc; | ||
1562 | ep->ep.maxpacket = max; | ||
1563 | ep->dma_start = 0; | ||
1564 | |||
1565 | |||
1566 | if (nt) { | ||
1567 | /* | ||
1568 | * Maximum possible size of all payloads in one microframe | ||
1569 | * regardless of direction when using high-bandwidth mode. | ||
1570 | */ | ||
1571 | ep->bytes_per_buffer = (nt + 1) * max; | ||
1572 | } else if (ep->is_in) { | ||
1573 | /* | ||
1574 | * The biggest multiple of maximum packet size that fits into | ||
1575 | * the buffer. The hardware will split up into many packets in | ||
1576 | * the IN direction. | ||
1577 | */ | ||
1578 | ep->bytes_per_buffer = (buffer_size / max) * max; | ||
1579 | } else { | ||
1580 | /* | ||
1581 | * Only single packets will be placed the buffers in the OUT | ||
1582 | * direction. | ||
1583 | */ | ||
1584 | ep->bytes_per_buffer = max; | ||
1585 | } | ||
1586 | |||
1587 | epctrl = (max << GR_EPCTRL_MAXPL_POS) | ||
1588 | | (nt << GR_EPCTRL_NT_POS) | ||
1589 | | (mode << GR_EPCTRL_TT_POS) | ||
1590 | | GR_EPCTRL_EV; | ||
1591 | if (ep->is_in) | ||
1592 | epctrl |= GR_EPCTRL_PI; | ||
1593 | gr_write32(&ep->regs->epctrl, epctrl); | ||
1594 | |||
1595 | gr_write32(&ep->regs->dmactrl, GR_DMACTRL_IE | GR_DMACTRL_AI); | ||
1596 | |||
1597 | spin_unlock(&ep->dev->lock); | ||
1598 | |||
1599 | dev_dbg(ep->dev->dev, "EP: %s enabled - %s with %d bytes/buffer\n", | ||
1600 | ep->ep.name, gr_modestring[mode], ep->bytes_per_buffer); | ||
1601 | return 0; | ||
1602 | } | ||
1603 | |||
1604 | /* Disable endpoint. Not for ep0in and ep0out that are handled separately. */ | ||
1605 | static int gr_ep_disable(struct usb_ep *_ep) | ||
1606 | { | ||
1607 | struct gr_ep *ep; | ||
1608 | struct gr_udc *dev; | ||
1609 | unsigned long flags; | ||
1610 | |||
1611 | ep = container_of(_ep, struct gr_ep, ep); | ||
1612 | if (!_ep || !ep->ep.desc) | ||
1613 | return -ENODEV; | ||
1614 | |||
1615 | dev = ep->dev; | ||
1616 | |||
1617 | /* 'ep0' IN and OUT are reserved */ | ||
1618 | if (ep == &dev->epo[0] || ep == &dev->epi[0]) | ||
1619 | return -EINVAL; | ||
1620 | |||
1621 | if (dev->ep0state == GR_EP0_SUSPEND) | ||
1622 | return -EBUSY; | ||
1623 | |||
1624 | dev_dbg(ep->dev->dev, "EP: disable %s\n", ep->ep.name); | ||
1625 | |||
1626 | spin_lock_irqsave(&dev->lock, flags); | ||
1627 | |||
1628 | gr_ep_nuke(ep); | ||
1629 | gr_ep_reset(ep); | ||
1630 | ep->ep.desc = NULL; | ||
1631 | |||
1632 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1633 | |||
1634 | return 0; | ||
1635 | } | ||
1636 | |||
1637 | /* | ||
1638 | * Frees a request, but not any DMA buffers associated with it | ||
1639 | * (gr_finish_request should already have taken care of that). | ||
1640 | */ | ||
1641 | static void gr_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
1642 | { | ||
1643 | struct gr_request *req; | ||
1644 | |||
1645 | if (!_ep || !_req) | ||
1646 | return; | ||
1647 | req = container_of(_req, struct gr_request, req); | ||
1648 | |||
1649 | /* Leads to memory leak */ | ||
1650 | WARN(!list_empty(&req->queue), | ||
1651 | "request not dequeued properly before freeing\n"); | ||
1652 | |||
1653 | kfree(req); | ||
1654 | } | ||
1655 | |||
1656 | /* Queue a request from the gadget */ | ||
1657 | static int gr_queue_ext(struct usb_ep *_ep, struct usb_request *_req, | ||
1658 | gfp_t gfp_flags) | ||
1659 | { | ||
1660 | struct gr_ep *ep; | ||
1661 | struct gr_request *req; | ||
1662 | struct gr_udc *dev; | ||
1663 | int ret; | ||
1664 | |||
1665 | if (unlikely(!_ep || !_req)) | ||
1666 | return -EINVAL; | ||
1667 | |||
1668 | ep = container_of(_ep, struct gr_ep, ep); | ||
1669 | req = container_of(_req, struct gr_request, req); | ||
1670 | dev = ep->dev; | ||
1671 | |||
1672 | spin_lock(&ep->dev->lock); | ||
1673 | |||
1674 | /* | ||
1675 | * The ep0 pointer in the gadget struct is used both for ep0in and | ||
1676 | * ep0out. In a data stage in the out direction ep0out needs to be used | ||
1677 | * instead of the default ep0in. Completion functions might use | ||
1678 | * driver_data, so that needs to be copied as well. | ||
1679 | */ | ||
1680 | if ((ep == &dev->epi[0]) && (dev->ep0state == GR_EP0_ODATA)) { | ||
1681 | ep = &dev->epo[0]; | ||
1682 | ep->ep.driver_data = dev->epi[0].ep.driver_data; | ||
1683 | } | ||
1684 | |||
1685 | if (ep->is_in) | ||
1686 | gr_dbgprint_request("EXTERN", ep, req); | ||
1687 | |||
1688 | ret = gr_queue(ep, req, gfp_flags); | ||
1689 | |||
1690 | spin_unlock(&ep->dev->lock); | ||
1691 | |||
1692 | return ret; | ||
1693 | } | ||
1694 | |||
1695 | /* Dequeue JUST ONE request */ | ||
1696 | static int gr_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
1697 | { | ||
1698 | struct gr_request *req; | ||
1699 | struct gr_ep *ep; | ||
1700 | struct gr_udc *dev; | ||
1701 | int ret = 0; | ||
1702 | unsigned long flags; | ||
1703 | |||
1704 | ep = container_of(_ep, struct gr_ep, ep); | ||
1705 | if (!_ep || !_req || (!ep->ep.desc && ep->num != 0)) | ||
1706 | return -EINVAL; | ||
1707 | dev = ep->dev; | ||
1708 | if (!dev->driver) | ||
1709 | return -ESHUTDOWN; | ||
1710 | |||
1711 | /* We can't touch (DMA) registers when suspended */ | ||
1712 | if (dev->ep0state == GR_EP0_SUSPEND) | ||
1713 | return -EBUSY; | ||
1714 | |||
1715 | spin_lock_irqsave(&dev->lock, flags); | ||
1716 | |||
1717 | /* Make sure it's actually queued on this endpoint */ | ||
1718 | list_for_each_entry(req, &ep->queue, queue) { | ||
1719 | if (&req->req == _req) | ||
1720 | break; | ||
1721 | } | ||
1722 | if (&req->req != _req) { | ||
1723 | ret = -EINVAL; | ||
1724 | goto out; | ||
1725 | } | ||
1726 | |||
1727 | if (list_first_entry(&ep->queue, struct gr_request, queue) == req) { | ||
1728 | /* This request is currently being processed */ | ||
1729 | gr_abort_dma(ep); | ||
1730 | if (ep->stopped) | ||
1731 | gr_finish_request(ep, req, -ECONNRESET); | ||
1732 | else | ||
1733 | gr_dma_advance(ep, -ECONNRESET); | ||
1734 | } else if (!list_empty(&req->queue)) { | ||
1735 | /* Not being processed - gr_finish_request dequeues it */ | ||
1736 | gr_finish_request(ep, req, -ECONNRESET); | ||
1737 | } else { | ||
1738 | ret = -EOPNOTSUPP; | ||
1739 | } | ||
1740 | |||
1741 | out: | ||
1742 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1743 | |||
1744 | return ret; | ||
1745 | } | ||
1746 | |||
1747 | /* Helper for gr_set_halt and gr_set_wedge */ | ||
1748 | static int gr_set_halt_wedge(struct usb_ep *_ep, int halt, int wedge) | ||
1749 | { | ||
1750 | int ret; | ||
1751 | struct gr_ep *ep; | ||
1752 | |||
1753 | if (!_ep) | ||
1754 | return -ENODEV; | ||
1755 | ep = container_of(_ep, struct gr_ep, ep); | ||
1756 | |||
1757 | spin_lock(&ep->dev->lock); | ||
1758 | |||
1759 | /* Halting an IN endpoint should fail if queue is not empty */ | ||
1760 | if (halt && ep->is_in && !list_empty(&ep->queue)) { | ||
1761 | ret = -EAGAIN; | ||
1762 | goto out; | ||
1763 | } | ||
1764 | |||
1765 | ret = gr_ep_halt_wedge(ep, halt, wedge, 0); | ||
1766 | |||
1767 | out: | ||
1768 | spin_unlock(&ep->dev->lock); | ||
1769 | |||
1770 | return ret; | ||
1771 | } | ||
1772 | |||
1773 | /* Halt endpoint */ | ||
1774 | static int gr_set_halt(struct usb_ep *_ep, int halt) | ||
1775 | { | ||
1776 | return gr_set_halt_wedge(_ep, halt, 0); | ||
1777 | } | ||
1778 | |||
1779 | /* Halt and wedge endpoint */ | ||
1780 | static int gr_set_wedge(struct usb_ep *_ep) | ||
1781 | { | ||
1782 | return gr_set_halt_wedge(_ep, 1, 1); | ||
1783 | } | ||
1784 | |||
1785 | /* | ||
1786 | * Return the total number of bytes currently stored in the internal buffers of | ||
1787 | * the endpoint. | ||
1788 | */ | ||
1789 | static int gr_fifo_status(struct usb_ep *_ep) | ||
1790 | { | ||
1791 | struct gr_ep *ep; | ||
1792 | u32 epstat; | ||
1793 | u32 bytes = 0; | ||
1794 | |||
1795 | if (!_ep) | ||
1796 | return -ENODEV; | ||
1797 | ep = container_of(_ep, struct gr_ep, ep); | ||
1798 | |||
1799 | epstat = gr_read32(&ep->regs->epstat); | ||
1800 | |||
1801 | if (epstat & GR_EPSTAT_B0) | ||
1802 | bytes += (epstat & GR_EPSTAT_B0CNT_MASK) >> GR_EPSTAT_B0CNT_POS; | ||
1803 | if (epstat & GR_EPSTAT_B1) | ||
1804 | bytes += (epstat & GR_EPSTAT_B1CNT_MASK) >> GR_EPSTAT_B1CNT_POS; | ||
1805 | |||
1806 | return bytes; | ||
1807 | } | ||
1808 | |||
1809 | |||
1810 | /* Empty data from internal buffers of an endpoint. */ | ||
1811 | static void gr_fifo_flush(struct usb_ep *_ep) | ||
1812 | { | ||
1813 | struct gr_ep *ep; | ||
1814 | u32 epctrl; | ||
1815 | |||
1816 | if (!_ep) | ||
1817 | return; | ||
1818 | ep = container_of(_ep, struct gr_ep, ep); | ||
1819 | dev_vdbg(ep->dev->dev, "EP: flush fifo %s\n", ep->ep.name); | ||
1820 | |||
1821 | spin_lock(&ep->dev->lock); | ||
1822 | |||
1823 | epctrl = gr_read32(&ep->regs->epctrl); | ||
1824 | epctrl |= GR_EPCTRL_CB; | ||
1825 | gr_write32(&ep->regs->epctrl, epctrl); | ||
1826 | |||
1827 | spin_unlock(&ep->dev->lock); | ||
1828 | } | ||
1829 | |||
1830 | static struct usb_ep_ops gr_ep_ops = { | ||
1831 | .enable = gr_ep_enable, | ||
1832 | .disable = gr_ep_disable, | ||
1833 | |||
1834 | .alloc_request = gr_alloc_request, | ||
1835 | .free_request = gr_free_request, | ||
1836 | |||
1837 | .queue = gr_queue_ext, | ||
1838 | .dequeue = gr_dequeue, | ||
1839 | |||
1840 | .set_halt = gr_set_halt, | ||
1841 | .set_wedge = gr_set_wedge, | ||
1842 | .fifo_status = gr_fifo_status, | ||
1843 | .fifo_flush = gr_fifo_flush, | ||
1844 | }; | ||
1845 | |||
1846 | /* ---------------------------------------------------------------------- */ | ||
1847 | /* USB Gadget ops */ | ||
1848 | |||
1849 | static int gr_get_frame(struct usb_gadget *_gadget) | ||
1850 | { | ||
1851 | struct gr_udc *dev; | ||
1852 | |||
1853 | if (!_gadget) | ||
1854 | return -ENODEV; | ||
1855 | dev = container_of(_gadget, struct gr_udc, gadget); | ||
1856 | return gr_read32(&dev->regs->status) & GR_STATUS_FN_MASK; | ||
1857 | } | ||
1858 | |||
1859 | static int gr_wakeup(struct usb_gadget *_gadget) | ||
1860 | { | ||
1861 | struct gr_udc *dev; | ||
1862 | |||
1863 | if (!_gadget) | ||
1864 | return -ENODEV; | ||
1865 | dev = container_of(_gadget, struct gr_udc, gadget); | ||
1866 | |||
1867 | /* Remote wakeup feature not enabled by host*/ | ||
1868 | if (!dev->remote_wakeup) | ||
1869 | return -EINVAL; | ||
1870 | |||
1871 | spin_lock(&dev->lock); | ||
1872 | |||
1873 | gr_write32(&dev->regs->control, | ||
1874 | gr_read32(&dev->regs->control) | GR_CONTROL_RW); | ||
1875 | |||
1876 | spin_unlock(&dev->lock); | ||
1877 | |||
1878 | return 0; | ||
1879 | } | ||
1880 | |||
1881 | static int gr_pullup(struct usb_gadget *_gadget, int is_on) | ||
1882 | { | ||
1883 | struct gr_udc *dev; | ||
1884 | u32 control; | ||
1885 | |||
1886 | if (!_gadget) | ||
1887 | return -ENODEV; | ||
1888 | dev = container_of(_gadget, struct gr_udc, gadget); | ||
1889 | |||
1890 | spin_lock(&dev->lock); | ||
1891 | |||
1892 | control = gr_read32(&dev->regs->control); | ||
1893 | if (is_on) | ||
1894 | control |= GR_CONTROL_EP; | ||
1895 | else | ||
1896 | control &= ~GR_CONTROL_EP; | ||
1897 | gr_write32(&dev->regs->control, control); | ||
1898 | |||
1899 | spin_unlock(&dev->lock); | ||
1900 | |||
1901 | return 0; | ||
1902 | } | ||
1903 | |||
1904 | static int gr_udc_start(struct usb_gadget *gadget, | ||
1905 | struct usb_gadget_driver *driver) | ||
1906 | { | ||
1907 | struct gr_udc *dev = to_gr_udc(gadget); | ||
1908 | |||
1909 | spin_lock(&dev->lock); | ||
1910 | |||
1911 | /* Hook up the driver */ | ||
1912 | driver->driver.bus = NULL; | ||
1913 | dev->driver = driver; | ||
1914 | |||
1915 | /* Get ready for host detection */ | ||
1916 | gr_enable_vbus_detect(dev); | ||
1917 | |||
1918 | spin_unlock(&dev->lock); | ||
1919 | |||
1920 | dev_info(dev->dev, "Started with gadget driver '%s'\n", | ||
1921 | driver->driver.name); | ||
1922 | |||
1923 | return 0; | ||
1924 | } | ||
1925 | |||
1926 | static int gr_udc_stop(struct usb_gadget *gadget, | ||
1927 | struct usb_gadget_driver *driver) | ||
1928 | { | ||
1929 | struct gr_udc *dev = to_gr_udc(gadget); | ||
1930 | unsigned long flags; | ||
1931 | |||
1932 | spin_lock_irqsave(&dev->lock, flags); | ||
1933 | |||
1934 | dev->driver = NULL; | ||
1935 | gr_stop_activity(dev); | ||
1936 | |||
1937 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1938 | |||
1939 | dev_info(dev->dev, "Stopped\n"); | ||
1940 | |||
1941 | return 0; | ||
1942 | } | ||
1943 | |||
1944 | static const struct usb_gadget_ops gr_ops = { | ||
1945 | .get_frame = gr_get_frame, | ||
1946 | .wakeup = gr_wakeup, | ||
1947 | .pullup = gr_pullup, | ||
1948 | .udc_start = gr_udc_start, | ||
1949 | .udc_stop = gr_udc_stop, | ||
1950 | /* Other operations not supported */ | ||
1951 | }; | ||
1952 | |||
1953 | /* ---------------------------------------------------------------------- */ | ||
1954 | /* Module probe, removal and of-matching */ | ||
1955 | |||
1956 | static const char * const onames[] = { | ||
1957 | "ep0out", "ep1out", "ep2out", "ep3out", "ep4out", "ep5out", | ||
1958 | "ep6out", "ep7out", "ep8out", "ep9out", "ep10out", "ep11out", | ||
1959 | "ep12out", "ep13out", "ep14out", "ep15out" | ||
1960 | }; | ||
1961 | |||
1962 | static const char * const inames[] = { | ||
1963 | "ep0in", "ep1in", "ep2in", "ep3in", "ep4in", "ep5in", | ||
1964 | "ep6in", "ep7in", "ep8in", "ep9in", "ep10in", "ep11in", | ||
1965 | "ep12in", "ep13in", "ep14in", "ep15in" | ||
1966 | }; | ||
1967 | |||
1968 | /* Must be called with dev->lock held */ | ||
1969 | static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit) | ||
1970 | { | ||
1971 | struct gr_ep *ep; | ||
1972 | struct gr_request *req; | ||
1973 | struct usb_request *_req; | ||
1974 | void *buf; | ||
1975 | |||
1976 | if (is_in) { | ||
1977 | ep = &dev->epi[num]; | ||
1978 | ep->ep.name = inames[num]; | ||
1979 | ep->regs = &dev->regs->epi[num]; | ||
1980 | } else { | ||
1981 | ep = &dev->epo[num]; | ||
1982 | ep->ep.name = onames[num]; | ||
1983 | ep->regs = &dev->regs->epo[num]; | ||
1984 | } | ||
1985 | |||
1986 | gr_ep_reset(ep); | ||
1987 | ep->num = num; | ||
1988 | ep->is_in = is_in; | ||
1989 | ep->dev = dev; | ||
1990 | ep->ep.ops = &gr_ep_ops; | ||
1991 | INIT_LIST_HEAD(&ep->queue); | ||
1992 | |||
1993 | if (num == 0) { | ||
1994 | _req = gr_alloc_request(&ep->ep, GFP_KERNEL); | ||
1995 | buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_KERNEL); | ||
1996 | if (!_req || !buf) { | ||
1997 | /* possible _req freed by gr_probe via gr_remove */ | ||
1998 | return -ENOMEM; | ||
1999 | } | ||
2000 | |||
2001 | req = container_of(_req, struct gr_request, req); | ||
2002 | req->req.buf = buf; | ||
2003 | req->req.length = MAX_CTRL_PL_SIZE; | ||
2004 | |||
2005 | if (is_in) | ||
2006 | dev->ep0reqi = req; /* Complete gets set as used */ | ||
2007 | else | ||
2008 | dev->ep0reqo = req; /* Completion treated separately */ | ||
2009 | |||
2010 | usb_ep_set_maxpacket_limit(&ep->ep, MAX_CTRL_PL_SIZE); | ||
2011 | ep->bytes_per_buffer = MAX_CTRL_PL_SIZE; | ||
2012 | } else { | ||
2013 | usb_ep_set_maxpacket_limit(&ep->ep, (u16)maxplimit); | ||
2014 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); | ||
2015 | } | ||
2016 | list_add_tail(&ep->ep_list, &dev->ep_list); | ||
2017 | |||
2018 | return 0; | ||
2019 | } | ||
2020 | |||
2021 | /* Must be called with dev->lock held */ | ||
2022 | static int gr_udc_init(struct gr_udc *dev) | ||
2023 | { | ||
2024 | struct device_node *np = dev->dev->of_node; | ||
2025 | u32 epctrl_val; | ||
2026 | u32 dmactrl_val; | ||
2027 | int i; | ||
2028 | int ret = 0; | ||
2029 | u32 *bufsizes; | ||
2030 | u32 bufsize; | ||
2031 | int len; | ||
2032 | |||
2033 | gr_set_address(dev, 0); | ||
2034 | |||
2035 | INIT_LIST_HEAD(&dev->gadget.ep_list); | ||
2036 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
2037 | dev->gadget.ep0 = &dev->epi[0].ep; | ||
2038 | |||
2039 | INIT_LIST_HEAD(&dev->ep_list); | ||
2040 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); | ||
2041 | |||
2042 | bufsizes = (u32 *)of_get_property(np, "epobufsizes", &len); | ||
2043 | len /= sizeof(u32); | ||
2044 | for (i = 0; i < dev->nepo; i++) { | ||
2045 | bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; | ||
2046 | ret = gr_ep_init(dev, i, 0, bufsize); | ||
2047 | if (ret) | ||
2048 | return ret; | ||
2049 | } | ||
2050 | |||
2051 | bufsizes = (u32 *)of_get_property(np, "epibufsizes", &len); | ||
2052 | len /= sizeof(u32); | ||
2053 | for (i = 0; i < dev->nepi; i++) { | ||
2054 | bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; | ||
2055 | ret = gr_ep_init(dev, i, 1, bufsize); | ||
2056 | if (ret) | ||
2057 | return ret; | ||
2058 | } | ||
2059 | |||
2060 | /* Must be disabled by default */ | ||
2061 | dev->remote_wakeup = 0; | ||
2062 | |||
2063 | /* Enable ep0out and ep0in */ | ||
2064 | epctrl_val = (MAX_CTRL_PL_SIZE << GR_EPCTRL_MAXPL_POS) | GR_EPCTRL_EV; | ||
2065 | dmactrl_val = GR_DMACTRL_IE | GR_DMACTRL_AI; | ||
2066 | gr_write32(&dev->epo[0].regs->epctrl, epctrl_val); | ||
2067 | gr_write32(&dev->epi[0].regs->epctrl, epctrl_val | GR_EPCTRL_PI); | ||
2068 | gr_write32(&dev->epo[0].regs->dmactrl, dmactrl_val); | ||
2069 | gr_write32(&dev->epi[0].regs->dmactrl, dmactrl_val); | ||
2070 | |||
2071 | return 0; | ||
2072 | } | ||
2073 | |||
2074 | static int gr_remove(struct platform_device *ofdev) | ||
2075 | { | ||
2076 | struct gr_udc *dev = dev_get_drvdata(&ofdev->dev); | ||
2077 | |||
2078 | if (dev->added) | ||
2079 | usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ | ||
2080 | if (dev->driver) | ||
2081 | return -EBUSY; | ||
2082 | |||
2083 | gr_dfs_delete(dev); | ||
2084 | if (dev->desc_pool) | ||
2085 | dma_pool_destroy(dev->desc_pool); | ||
2086 | dev_set_drvdata(&ofdev->dev, NULL); | ||
2087 | |||
2088 | gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); | ||
2089 | gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); | ||
2090 | |||
2091 | return 0; | ||
2092 | } | ||
2093 | static int gr_request_irq(struct gr_udc *dev, int irq) | ||
2094 | { | ||
2095 | return devm_request_threaded_irq(dev->dev, irq, gr_irq, gr_irq_handler, | ||
2096 | IRQF_SHARED, driver_name, dev); | ||
2097 | } | ||
2098 | |||
2099 | static int gr_probe(struct platform_device *ofdev) | ||
2100 | { | ||
2101 | struct gr_udc *dev; | ||
2102 | struct resource *res; | ||
2103 | struct gr_regs __iomem *regs; | ||
2104 | int retval; | ||
2105 | u32 status; | ||
2106 | |||
2107 | dev = devm_kzalloc(&ofdev->dev, sizeof(*dev), GFP_KERNEL); | ||
2108 | if (!dev) | ||
2109 | return -ENOMEM; | ||
2110 | dev->dev = &ofdev->dev; | ||
2111 | |||
2112 | res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); | ||
2113 | regs = devm_ioremap_resource(dev->dev, res); | ||
2114 | if (IS_ERR(regs)) | ||
2115 | return PTR_ERR(regs); | ||
2116 | |||
2117 | dev->irq = irq_of_parse_and_map(dev->dev->of_node, 0); | ||
2118 | if (!dev->irq) { | ||
2119 | dev_err(dev->dev, "No irq found\n"); | ||
2120 | return -ENODEV; | ||
2121 | } | ||
2122 | |||
2123 | /* Some core configurations has separate irqs for IN and OUT events */ | ||
2124 | dev->irqi = irq_of_parse_and_map(dev->dev->of_node, 1); | ||
2125 | if (dev->irqi) { | ||
2126 | dev->irqo = irq_of_parse_and_map(dev->dev->of_node, 2); | ||
2127 | if (!dev->irqo) { | ||
2128 | dev_err(dev->dev, "Found irqi but not irqo\n"); | ||
2129 | return -ENODEV; | ||
2130 | } | ||
2131 | } | ||
2132 | |||
2133 | dev->gadget.name = driver_name; | ||
2134 | dev->gadget.max_speed = USB_SPEED_HIGH; | ||
2135 | dev->gadget.ops = &gr_ops; | ||
2136 | dev->gadget.quirk_ep_out_aligned_size = true; | ||
2137 | |||
2138 | spin_lock_init(&dev->lock); | ||
2139 | dev->regs = regs; | ||
2140 | |||
2141 | dev_set_drvdata(&ofdev->dev, dev); | ||
2142 | |||
2143 | /* Determine number of endpoints and data interface mode */ | ||
2144 | status = gr_read32(&dev->regs->status); | ||
2145 | dev->nepi = ((status & GR_STATUS_NEPI_MASK) >> GR_STATUS_NEPI_POS) + 1; | ||
2146 | dev->nepo = ((status & GR_STATUS_NEPO_MASK) >> GR_STATUS_NEPO_POS) + 1; | ||
2147 | |||
2148 | if (!(status & GR_STATUS_DM)) { | ||
2149 | dev_err(dev->dev, "Slave mode cores are not supported\n"); | ||
2150 | return -ENODEV; | ||
2151 | } | ||
2152 | |||
2153 | /* --- Effects of the following calls might need explicit cleanup --- */ | ||
2154 | |||
2155 | /* Create DMA pool for descriptors */ | ||
2156 | dev->desc_pool = dma_pool_create("desc_pool", dev->dev, | ||
2157 | sizeof(struct gr_dma_desc), 4, 0); | ||
2158 | if (!dev->desc_pool) { | ||
2159 | dev_err(dev->dev, "Could not allocate DMA pool"); | ||
2160 | return -ENOMEM; | ||
2161 | } | ||
2162 | |||
2163 | spin_lock(&dev->lock); | ||
2164 | |||
2165 | /* Inside lock so that no gadget can use this udc until probe is done */ | ||
2166 | retval = usb_add_gadget_udc(dev->dev, &dev->gadget); | ||
2167 | if (retval) { | ||
2168 | dev_err(dev->dev, "Could not add gadget udc"); | ||
2169 | goto out; | ||
2170 | } | ||
2171 | dev->added = 1; | ||
2172 | |||
2173 | retval = gr_udc_init(dev); | ||
2174 | if (retval) | ||
2175 | goto out; | ||
2176 | |||
2177 | gr_dfs_create(dev); | ||
2178 | |||
2179 | /* Clear all interrupt enables that might be left on since last boot */ | ||
2180 | gr_disable_interrupts_and_pullup(dev); | ||
2181 | |||
2182 | retval = gr_request_irq(dev, dev->irq); | ||
2183 | if (retval) { | ||
2184 | dev_err(dev->dev, "Failed to request irq %d\n", dev->irq); | ||
2185 | goto out; | ||
2186 | } | ||
2187 | |||
2188 | if (dev->irqi) { | ||
2189 | retval = gr_request_irq(dev, dev->irqi); | ||
2190 | if (retval) { | ||
2191 | dev_err(dev->dev, "Failed to request irqi %d\n", | ||
2192 | dev->irqi); | ||
2193 | goto out; | ||
2194 | } | ||
2195 | retval = gr_request_irq(dev, dev->irqo); | ||
2196 | if (retval) { | ||
2197 | dev_err(dev->dev, "Failed to request irqo %d\n", | ||
2198 | dev->irqo); | ||
2199 | goto out; | ||
2200 | } | ||
2201 | } | ||
2202 | |||
2203 | if (dev->irqi) | ||
2204 | dev_info(dev->dev, "regs: %p, irqs %d, %d, %d\n", dev->regs, | ||
2205 | dev->irq, dev->irqi, dev->irqo); | ||
2206 | else | ||
2207 | dev_info(dev->dev, "regs: %p, irq %d\n", dev->regs, dev->irq); | ||
2208 | |||
2209 | out: | ||
2210 | spin_unlock(&dev->lock); | ||
2211 | |||
2212 | if (retval) | ||
2213 | gr_remove(ofdev); | ||
2214 | |||
2215 | return retval; | ||
2216 | } | ||
2217 | |||
2218 | static struct of_device_id gr_match[] = { | ||
2219 | {.name = "GAISLER_USBDC"}, | ||
2220 | {.name = "01_021"}, | ||
2221 | {}, | ||
2222 | }; | ||
2223 | MODULE_DEVICE_TABLE(of, gr_match); | ||
2224 | |||
2225 | static struct platform_driver gr_driver = { | ||
2226 | .driver = { | ||
2227 | .name = DRIVER_NAME, | ||
2228 | .owner = THIS_MODULE, | ||
2229 | .of_match_table = gr_match, | ||
2230 | }, | ||
2231 | .probe = gr_probe, | ||
2232 | .remove = gr_remove, | ||
2233 | }; | ||
2234 | module_platform_driver(gr_driver); | ||
2235 | |||
2236 | MODULE_AUTHOR("Aeroflex Gaisler AB."); | ||
2237 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
2238 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/gr_udc.h b/drivers/usb/gadget/gr_udc.h new file mode 100644 index 000000000000..8388897d9ec3 --- /dev/null +++ b/drivers/usb/gadget/gr_udc.h | |||
@@ -0,0 +1,220 @@ | |||
1 | /* | ||
2 | * USB Peripheral Controller driver for Aeroflex Gaisler GRUSBDC. | ||
3 | * | ||
4 | * 2013 (c) Aeroflex Gaisler AB | ||
5 | * | ||
6 | * This driver supports GRUSBDC USB Device Controller cores available in the | ||
7 | * GRLIB VHDL IP core library. | ||
8 | * | ||
9 | * Full documentation of the GRUSBDC core can be found here: | ||
10 | * http://www.gaisler.com/products/grlib/grip.pdf | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License as published by the | ||
14 | * Free Software Foundation; either version 2 of the License, or (at your | ||
15 | * option) any later version. | ||
16 | * | ||
17 | * Contributors: | ||
18 | * - Andreas Larsson <andreas@gaisler.com> | ||
19 | * - Marko Isomaki | ||
20 | */ | ||
21 | |||
22 | /* Control registers on the AMBA bus */ | ||
23 | |||
24 | #define GR_MAXEP 16 /* Max # endpoints for *each* direction */ | ||
25 | |||
26 | struct gr_epregs { | ||
27 | u32 epctrl; | ||
28 | union { | ||
29 | struct { /* Slave mode*/ | ||
30 | u32 slvctrl; | ||
31 | u32 slvdata; | ||
32 | }; | ||
33 | struct { /* DMA mode*/ | ||
34 | u32 dmactrl; | ||
35 | u32 dmaaddr; | ||
36 | }; | ||
37 | }; | ||
38 | u32 epstat; | ||
39 | }; | ||
40 | |||
41 | struct gr_regs { | ||
42 | struct gr_epregs epo[GR_MAXEP]; /* 0x000 - 0x0fc */ | ||
43 | struct gr_epregs epi[GR_MAXEP]; /* 0x100 - 0x1fc */ | ||
44 | u32 control; /* 0x200 */ | ||
45 | u32 status; /* 0x204 */ | ||
46 | }; | ||
47 | |||
48 | #define GR_EPCTRL_BUFSZ_SCALER 8 | ||
49 | #define GR_EPCTRL_BUFSZ_MASK 0xffe00000 | ||
50 | #define GR_EPCTRL_BUFSZ_POS 21 | ||
51 | #define GR_EPCTRL_PI BIT(20) | ||
52 | #define GR_EPCTRL_CB BIT(19) | ||
53 | #define GR_EPCTRL_CS BIT(18) | ||
54 | #define GR_EPCTRL_MAXPL_MASK 0x0003ff80 | ||
55 | #define GR_EPCTRL_MAXPL_POS 7 | ||
56 | #define GR_EPCTRL_NT_MASK 0x00000060 | ||
57 | #define GR_EPCTRL_NT_POS 5 | ||
58 | #define GR_EPCTRL_TT_MASK 0x00000018 | ||
59 | #define GR_EPCTRL_TT_POS 3 | ||
60 | #define GR_EPCTRL_EH BIT(2) | ||
61 | #define GR_EPCTRL_ED BIT(1) | ||
62 | #define GR_EPCTRL_EV BIT(0) | ||
63 | |||
64 | #define GR_DMACTRL_AE BIT(10) | ||
65 | #define GR_DMACTRL_AD BIT(3) | ||
66 | #define GR_DMACTRL_AI BIT(2) | ||
67 | #define GR_DMACTRL_IE BIT(1) | ||
68 | #define GR_DMACTRL_DA BIT(0) | ||
69 | |||
70 | #define GR_EPSTAT_PT BIT(29) | ||
71 | #define GR_EPSTAT_PR BIT(29) | ||
72 | #define GR_EPSTAT_B1CNT_MASK 0x1fff0000 | ||
73 | #define GR_EPSTAT_B1CNT_POS 16 | ||
74 | #define GR_EPSTAT_B0CNT_MASK 0x0000fff8 | ||
75 | #define GR_EPSTAT_B0CNT_POS 3 | ||
76 | #define GR_EPSTAT_B1 BIT(2) | ||
77 | #define GR_EPSTAT_B0 BIT(1) | ||
78 | #define GR_EPSTAT_BS BIT(0) | ||
79 | |||
80 | #define GR_CONTROL_SI BIT(31) | ||
81 | #define GR_CONTROL_UI BIT(30) | ||
82 | #define GR_CONTROL_VI BIT(29) | ||
83 | #define GR_CONTROL_SP BIT(28) | ||
84 | #define GR_CONTROL_FI BIT(27) | ||
85 | #define GR_CONTROL_EP BIT(14) | ||
86 | #define GR_CONTROL_DH BIT(13) | ||
87 | #define GR_CONTROL_RW BIT(12) | ||
88 | #define GR_CONTROL_TS_MASK 0x00000e00 | ||
89 | #define GR_CONTROL_TS_POS 9 | ||
90 | #define GR_CONTROL_TM BIT(8) | ||
91 | #define GR_CONTROL_UA_MASK 0x000000fe | ||
92 | #define GR_CONTROL_UA_POS 1 | ||
93 | #define GR_CONTROL_SU BIT(0) | ||
94 | |||
95 | #define GR_STATUS_NEPI_MASK 0xf0000000 | ||
96 | #define GR_STATUS_NEPI_POS 28 | ||
97 | #define GR_STATUS_NEPO_MASK 0x0f000000 | ||
98 | #define GR_STATUS_NEPO_POS 24 | ||
99 | #define GR_STATUS_DM BIT(23) | ||
100 | #define GR_STATUS_SU BIT(17) | ||
101 | #define GR_STATUS_UR BIT(16) | ||
102 | #define GR_STATUS_VB BIT(15) | ||
103 | #define GR_STATUS_SP BIT(14) | ||
104 | #define GR_STATUS_AF_MASK 0x00003800 | ||
105 | #define GR_STATUS_AF_POS 11 | ||
106 | #define GR_STATUS_FN_MASK 0x000007ff | ||
107 | #define GR_STATUS_FN_POS 0 | ||
108 | |||
109 | |||
110 | #define MAX_CTRL_PL_SIZE 64 /* As per USB standard for full and high speed */ | ||
111 | |||
112 | /*-------------------------------------------------------------------------*/ | ||
113 | |||
114 | /* Driver data structures and utilities */ | ||
115 | |||
116 | struct gr_dma_desc { | ||
117 | u32 ctrl; | ||
118 | u32 data; | ||
119 | u32 next; | ||
120 | |||
121 | /* These must be last because hw uses the previous three */ | ||
122 | u32 paddr; | ||
123 | struct gr_dma_desc *next_desc; | ||
124 | }; | ||
125 | |||
126 | #define GR_DESC_OUT_CTRL_SE BIT(17) | ||
127 | #define GR_DESC_OUT_CTRL_IE BIT(15) | ||
128 | #define GR_DESC_OUT_CTRL_NX BIT(14) | ||
129 | #define GR_DESC_OUT_CTRL_EN BIT(13) | ||
130 | #define GR_DESC_OUT_CTRL_LEN_MASK 0x00001fff | ||
131 | |||
132 | #define GR_DESC_IN_CTRL_MO BIT(18) | ||
133 | #define GR_DESC_IN_CTRL_PI BIT(17) | ||
134 | #define GR_DESC_IN_CTRL_ML BIT(16) | ||
135 | #define GR_DESC_IN_CTRL_IE BIT(15) | ||
136 | #define GR_DESC_IN_CTRL_NX BIT(14) | ||
137 | #define GR_DESC_IN_CTRL_EN BIT(13) | ||
138 | #define GR_DESC_IN_CTRL_LEN_MASK 0x00001fff | ||
139 | |||
140 | #define GR_DESC_DMAADDR_MASK 0xfffffffc | ||
141 | |||
142 | struct gr_ep { | ||
143 | struct usb_ep ep; | ||
144 | struct gr_udc *dev; | ||
145 | u16 bytes_per_buffer; | ||
146 | unsigned int dma_start; | ||
147 | struct gr_epregs __iomem *regs; | ||
148 | |||
149 | unsigned num:8; | ||
150 | unsigned is_in:1; | ||
151 | unsigned stopped:1; | ||
152 | unsigned wedged:1; | ||
153 | unsigned callback:1; | ||
154 | |||
155 | /* analogous to a host-side qh */ | ||
156 | struct list_head queue; | ||
157 | |||
158 | struct list_head ep_list; | ||
159 | }; | ||
160 | |||
161 | struct gr_request { | ||
162 | struct usb_request req; | ||
163 | struct list_head queue; | ||
164 | |||
165 | /* Chain of dma descriptors */ | ||
166 | struct gr_dma_desc *first_desc; /* First in the chain */ | ||
167 | struct gr_dma_desc *curr_desc; /* Current descriptor */ | ||
168 | struct gr_dma_desc *last_desc; /* Last in the chain */ | ||
169 | |||
170 | u8 setup; /* Setup packet */ | ||
171 | }; | ||
172 | |||
173 | enum gr_ep0state { | ||
174 | GR_EP0_DISCONNECT = 0, /* No host */ | ||
175 | GR_EP0_SETUP, /* Between STATUS ack and SETUP report */ | ||
176 | GR_EP0_IDATA, /* IN data stage */ | ||
177 | GR_EP0_ODATA, /* OUT data stage */ | ||
178 | GR_EP0_ISTATUS, /* Status stage after IN data stage */ | ||
179 | GR_EP0_OSTATUS, /* Status stage after OUT data stage */ | ||
180 | GR_EP0_STALL, /* Data or status stages */ | ||
181 | GR_EP0_SUSPEND, /* USB suspend */ | ||
182 | }; | ||
183 | |||
184 | struct gr_udc { | ||
185 | struct usb_gadget gadget; | ||
186 | struct gr_ep epi[GR_MAXEP]; | ||
187 | struct gr_ep epo[GR_MAXEP]; | ||
188 | struct usb_gadget_driver *driver; | ||
189 | struct dma_pool *desc_pool; | ||
190 | struct device *dev; | ||
191 | |||
192 | enum gr_ep0state ep0state; | ||
193 | struct gr_request *ep0reqo; | ||
194 | struct gr_request *ep0reqi; | ||
195 | |||
196 | struct gr_regs __iomem *regs; | ||
197 | int irq; | ||
198 | int irqi; | ||
199 | int irqo; | ||
200 | |||
201 | unsigned added:1; | ||
202 | unsigned irq_enabled:1; | ||
203 | unsigned remote_wakeup:1; | ||
204 | |||
205 | u8 test_mode; | ||
206 | |||
207 | enum usb_device_state suspended_from; | ||
208 | |||
209 | unsigned int nepi; | ||
210 | unsigned int nepo; | ||
211 | |||
212 | struct list_head ep_list; | ||
213 | |||
214 | spinlock_t lock; /* General lock, a.k.a. "dev->lock" in comments */ | ||
215 | |||
216 | struct dentry *dfs_root; | ||
217 | struct dentry *dfs_state; | ||
218 | }; | ||
219 | |||
220 | #define to_gr_udc(gadget) (container_of((gadget), struct gr_udc, gadget)) | ||
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c index 6a2a65aa0057..049ebab0d360 100644 --- a/drivers/usb/gadget/lpc32xx_udc.c +++ b/drivers/usb/gadget/lpc32xx_udc.c | |||
@@ -1449,7 +1449,7 @@ static void udc_reinit(struct lpc32xx_udc *udc) | |||
1449 | 1449 | ||
1450 | if (i != 0) | 1450 | if (i != 0) |
1451 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | 1451 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); |
1452 | ep->ep.maxpacket = ep->maxpacket; | 1452 | usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); |
1453 | INIT_LIST_HEAD(&ep->queue); | 1453 | INIT_LIST_HEAD(&ep->queue); |
1454 | ep->req_pending = 0; | 1454 | ep->req_pending = 0; |
1455 | } | 1455 | } |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index d5f050d30edf..8cae01d88597 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -1647,9 +1647,9 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1647 | INIT_LIST_HEAD(&ep->queue); | 1647 | INIT_LIST_HEAD(&ep->queue); |
1648 | ep->ep.name = m66592_ep_name[i]; | 1648 | ep->ep.name = m66592_ep_name[i]; |
1649 | ep->ep.ops = &m66592_ep_ops; | 1649 | ep->ep.ops = &m66592_ep_ops; |
1650 | ep->ep.maxpacket = 512; | 1650 | usb_ep_set_maxpacket_limit(&ep->ep, 512); |
1651 | } | 1651 | } |
1652 | m66592->ep[0].ep.maxpacket = 64; | 1652 | usb_ep_set_maxpacket_limit(&m66592->ep[0].ep, 64); |
1653 | m66592->ep[0].pipenum = 0; | 1653 | m66592->ep[0].pipenum = 0; |
1654 | m66592->ep[0].fifoaddr = M66592_CFIFO; | 1654 | m66592->ep[0].fifoaddr = M66592_CFIFO; |
1655 | m66592->ep[0].fifosel = M66592_CFIFOSEL; | 1655 | m66592->ep[0].fifosel = M66592_CFIFOSEL; |
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 4fdaa54a2a2a..940f6cde8e89 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c | |||
@@ -134,7 +134,7 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; | |||
134 | */ | 134 | */ |
135 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS | 135 | #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS |
136 | 136 | ||
137 | #endif /* CONFIG_USB_DEBUG */ | 137 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
138 | 138 | ||
139 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); | 139 | FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); |
140 | 140 | ||
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c index 234711eabea1..d2ca59e7b477 100644 --- a/drivers/usb/gadget/mv_u3d_core.c +++ b/drivers/usb/gadget/mv_u3d_core.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/sched.h> | 15 | #include <linux/sched.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/errno.h> | 17 | #include <linux/errno.h> |
18 | #include <linux/init.h> | ||
19 | #include <linux/timer.h> | 18 | #include <linux/timer.h> |
20 | #include <linux/list.h> | 19 | #include <linux/list.h> |
21 | #include <linux/notifier.h> | 20 | #include <linux/notifier.h> |
@@ -1336,7 +1335,7 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d) | |||
1336 | ep->ep.name = ep->name; | 1335 | ep->ep.name = ep->name; |
1337 | ep->ep.ops = &mv_u3d_ep_ops; | 1336 | ep->ep.ops = &mv_u3d_ep_ops; |
1338 | ep->wedge = 0; | 1337 | ep->wedge = 0; |
1339 | ep->ep.maxpacket = MV_U3D_EP0_MAX_PKT_SIZE; | 1338 | usb_ep_set_maxpacket_limit(&ep->ep, MV_U3D_EP0_MAX_PKT_SIZE); |
1340 | ep->ep_num = 0; | 1339 | ep->ep_num = 0; |
1341 | ep->ep.desc = &mv_u3d_ep0_desc; | 1340 | ep->ep.desc = &mv_u3d_ep0_desc; |
1342 | INIT_LIST_HEAD(&ep->queue); | 1341 | INIT_LIST_HEAD(&ep->queue); |
@@ -1361,7 +1360,7 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d) | |||
1361 | ep->ep.name = ep->name; | 1360 | ep->ep.name = ep->name; |
1362 | 1361 | ||
1363 | ep->ep.ops = &mv_u3d_ep_ops; | 1362 | ep->ep.ops = &mv_u3d_ep_ops; |
1364 | ep->ep.maxpacket = (unsigned short) ~0; | 1363 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
1365 | ep->ep_num = i / 2; | 1364 | ep->ep_num = i / 2; |
1366 | 1365 | ||
1367 | INIT_LIST_HEAD(&ep->queue); | 1366 | INIT_LIST_HEAD(&ep->queue); |
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c index 104cdbea635a..fcff3a571b45 100644 --- a/drivers/usb/gadget/mv_udc_core.c +++ b/drivers/usb/gadget/mv_udc_core.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/errno.h> | 21 | #include <linux/errno.h> |
22 | #include <linux/err.h> | 22 | #include <linux/err.h> |
23 | #include <linux/init.h> | ||
24 | #include <linux/timer.h> | 23 | #include <linux/timer.h> |
25 | #include <linux/list.h> | 24 | #include <linux/list.h> |
26 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
@@ -1261,7 +1260,7 @@ static int eps_init(struct mv_udc *udc) | |||
1261 | ep->ep.ops = &mv_ep_ops; | 1260 | ep->ep.ops = &mv_ep_ops; |
1262 | ep->wedge = 0; | 1261 | ep->wedge = 0; |
1263 | ep->stopped = 0; | 1262 | ep->stopped = 0; |
1264 | ep->ep.maxpacket = EP0_MAX_PKT_SIZE; | 1263 | usb_ep_set_maxpacket_limit(&ep->ep, EP0_MAX_PKT_SIZE); |
1265 | ep->ep_num = 0; | 1264 | ep->ep_num = 0; |
1266 | ep->ep.desc = &mv_ep0_desc; | 1265 | ep->ep.desc = &mv_ep0_desc; |
1267 | INIT_LIST_HEAD(&ep->queue); | 1266 | INIT_LIST_HEAD(&ep->queue); |
@@ -1284,7 +1283,7 @@ static int eps_init(struct mv_udc *udc) | |||
1284 | 1283 | ||
1285 | ep->ep.ops = &mv_ep_ops; | 1284 | ep->ep.ops = &mv_ep_ops; |
1286 | ep->stopped = 0; | 1285 | ep->stopped = 0; |
1287 | ep->ep.maxpacket = (unsigned short) ~0; | 1286 | usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0); |
1288 | ep->ep_num = i / 2; | 1287 | ep->ep_num = i / 2; |
1289 | 1288 | ||
1290 | INIT_LIST_HEAD(&ep->queue); | 1289 | INIT_LIST_HEAD(&ep->queue); |
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c index bf2bb39f35a2..ca15405583e2 100644 --- a/drivers/usb/gadget/net2272.c +++ b/drivers/usb/gadget/net2272.c | |||
@@ -266,7 +266,7 @@ static void net2272_ep_reset(struct net2272_ep *ep) | |||
266 | ep->desc = NULL; | 266 | ep->desc = NULL; |
267 | INIT_LIST_HEAD(&ep->queue); | 267 | INIT_LIST_HEAD(&ep->queue); |
268 | 268 | ||
269 | ep->ep.maxpacket = ~0; | 269 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
270 | ep->ep.ops = &net2272_ep_ops; | 270 | ep->ep.ops = &net2272_ep_ops; |
271 | 271 | ||
272 | /* disable irqs, endpoint */ | 272 | /* disable irqs, endpoint */ |
@@ -1409,7 +1409,7 @@ net2272_usb_reinit(struct net2272 *dev) | |||
1409 | ep->fifo_size = 64; | 1409 | ep->fifo_size = 64; |
1410 | net2272_ep_reset(ep); | 1410 | net2272_ep_reset(ep); |
1411 | } | 1411 | } |
1412 | dev->ep[0].ep.maxpacket = 64; | 1412 | usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64); |
1413 | 1413 | ||
1414 | dev->gadget.ep0 = &dev->ep[0].ep; | 1414 | dev->gadget.ep0 = &dev->ep[0].ep; |
1415 | dev->ep[0].stopped = 0; | 1415 | dev->ep[0].stopped = 0; |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index fc852177c087..43e5e2f9888f 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -293,7 +293,7 @@ static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) | |||
293 | ep->desc = NULL; | 293 | ep->desc = NULL; |
294 | INIT_LIST_HEAD (&ep->queue); | 294 | INIT_LIST_HEAD (&ep->queue); |
295 | 295 | ||
296 | ep->ep.maxpacket = ~0; | 296 | usb_ep_set_maxpacket_limit(&ep->ep, ~0); |
297 | ep->ep.ops = &net2280_ep_ops; | 297 | ep->ep.ops = &net2280_ep_ops; |
298 | 298 | ||
299 | /* disable the dma, irqs, endpoint... */ | 299 | /* disable the dma, irqs, endpoint... */ |
@@ -1805,9 +1805,9 @@ static void usb_reinit (struct net2280 *dev) | |||
1805 | ep->regs = &dev->epregs [tmp]; | 1805 | ep->regs = &dev->epregs [tmp]; |
1806 | ep_reset (dev->regs, ep); | 1806 | ep_reset (dev->regs, ep); |
1807 | } | 1807 | } |
1808 | dev->ep [0].ep.maxpacket = 64; | 1808 | usb_ep_set_maxpacket_limit(&dev->ep [0].ep, 64); |
1809 | dev->ep [5].ep.maxpacket = 64; | 1809 | usb_ep_set_maxpacket_limit(&dev->ep [5].ep, 64); |
1810 | dev->ep [6].ep.maxpacket = 64; | 1810 | usb_ep_set_maxpacket_limit(&dev->ep [6].ep, 64); |
1811 | 1811 | ||
1812 | dev->gadget.ep0 = &dev->ep [0].ep; | 1812 | dev->gadget.ep0 = &dev->ep [0].ep; |
1813 | dev->ep [0].stopped = 0; | 1813 | dev->ep [0].stopped = 0; |
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 0a8099a488c4..3ab386167519 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c | |||
@@ -126,9 +126,9 @@ static int __init nokia_bind_config(struct usb_configuration *c) | |||
126 | struct usb_function *f_ecm; | 126 | struct usb_function *f_ecm; |
127 | struct usb_function *f_obex2 = NULL; | 127 | struct usb_function *f_obex2 = NULL; |
128 | int status = 0; | 128 | int status = 0; |
129 | int obex1_stat = 0; | 129 | int obex1_stat = -1; |
130 | int obex2_stat = 0; | 130 | int obex2_stat = -1; |
131 | int phonet_stat = 0; | 131 | int phonet_stat = -1; |
132 | 132 | ||
133 | if (!IS_ERR(fi_phonet)) { | 133 | if (!IS_ERR(fi_phonet)) { |
134 | f_phonet = usb_get_function(fi_phonet); | 134 | f_phonet = usb_get_function(fi_phonet); |
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 83957cc225d9..2ae4f6d69f74 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include <linux/errno.h> | 22 | #include <linux/errno.h> |
23 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/init.h> | ||
26 | #include <linux/timer.h> | 25 | #include <linux/timer.h> |
27 | #include <linux/list.h> | 26 | #include <linux/list.h> |
28 | #include <linux/interrupt.h> | 27 | #include <linux/interrupt.h> |
@@ -2586,7 +2585,8 @@ omap_ep_setup(char *name, u8 addr, u8 type, | |||
2586 | 2585 | ||
2587 | ep->ep.name = ep->name; | 2586 | ep->ep.name = ep->name; |
2588 | ep->ep.ops = &omap_ep_ops; | 2587 | ep->ep.ops = &omap_ep_ops; |
2589 | ep->ep.maxpacket = ep->maxpacket = maxp; | 2588 | ep->maxpacket = maxp; |
2589 | usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); | ||
2590 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | 2590 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); |
2591 | 2591 | ||
2592 | return buf; | 2592 | return buf; |
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index 32d5e923750b..eb8c3bedb57a 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -2896,12 +2896,12 @@ static void pch_udc_pcd_reinit(struct pch_udc_dev *dev) | |||
2896 | ep->offset_addr = (UDC_EPINT_OUT_SHIFT + ep->num) * | 2896 | ep->offset_addr = (UDC_EPINT_OUT_SHIFT + ep->num) * |
2897 | UDC_EP_REG_SHIFT; | 2897 | UDC_EP_REG_SHIFT; |
2898 | /* need to set ep->ep.maxpacket and set Default Configuration?*/ | 2898 | /* need to set ep->ep.maxpacket and set Default Configuration?*/ |
2899 | ep->ep.maxpacket = UDC_BULK_MAX_PKT_SIZE; | 2899 | usb_ep_set_maxpacket_limit(&ep->ep, UDC_BULK_MAX_PKT_SIZE); |
2900 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); | 2900 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); |
2901 | INIT_LIST_HEAD(&ep->queue); | 2901 | INIT_LIST_HEAD(&ep->queue); |
2902 | } | 2902 | } |
2903 | dev->ep[UDC_EP0IN_IDX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE; | 2903 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0IN_IDX].ep, UDC_EP0IN_MAX_PKT_SIZE); |
2904 | dev->ep[UDC_EP0OUT_IDX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE; | 2904 | usb_ep_set_maxpacket_limit(&dev->ep[UDC_EP0OUT_IDX].ep, UDC_EP0OUT_MAX_PKT_SIZE); |
2905 | 2905 | ||
2906 | /* remove ep0 in and out from the list. They have own pointer */ | 2906 | /* remove ep0 in and out from the list. They have own pointer */ |
2907 | list_del_init(&dev->ep[UDC_EP0IN_IDX].ep.ep_list); | 2907 | list_del_init(&dev->ep[UDC_EP0IN_IDX].ep.ep_list); |
@@ -3210,7 +3210,7 @@ finished: | |||
3210 | return retval; | 3210 | return retval; |
3211 | } | 3211 | } |
3212 | 3212 | ||
3213 | static DEFINE_PCI_DEVICE_TABLE(pch_udc_pcidev_id) = { | 3213 | static const struct pci_device_id pch_udc_pcidev_id[] = { |
3214 | { | 3214 | { |
3215 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EG20T_UDC), | 3215 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EG20T_UDC), |
3216 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, | 3216 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index 409a3c45a36a..9984437d2952 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/init.h> | ||
28 | #include <linux/timer.h> | 27 | #include <linux/timer.h> |
29 | #include <linux/list.h> | 28 | #include <linux/list.h> |
30 | #include <linux/interrupt.h> | 29 | #include <linux/interrupt.h> |
@@ -1194,6 +1193,7 @@ static void udc_reinit(struct pxa25x_udc *dev) | |||
1194 | ep->stopped = 0; | 1193 | ep->stopped = 0; |
1195 | INIT_LIST_HEAD (&ep->queue); | 1194 | INIT_LIST_HEAD (&ep->queue); |
1196 | ep->pio_irqs = 0; | 1195 | ep->pio_irqs = 0; |
1196 | usb_ep_set_maxpacket_limit(&ep->ep, ep->ep.maxpacket); | ||
1197 | } | 1197 | } |
1198 | 1198 | ||
1199 | /* the rest was statically initialized, and is read-only */ | 1199 | /* the rest was statically initialized, and is read-only */ |
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 3c97da7760da..cdf4d678be96 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -1737,9 +1737,12 @@ static void udc_init_data(struct pxa_udc *dev) | |||
1737 | } | 1737 | } |
1738 | 1738 | ||
1739 | /* USB endpoints init */ | 1739 | /* USB endpoints init */ |
1740 | for (i = 1; i < NR_USB_ENDPOINTS; i++) | 1740 | for (i = 1; i < NR_USB_ENDPOINTS; i++) { |
1741 | list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, | 1741 | list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, |
1742 | &dev->gadget.ep_list); | 1742 | &dev->gadget.ep_list); |
1743 | usb_ep_set_maxpacket_limit(&dev->udc_usb_ep[i].usb_ep, | ||
1744 | dev->udc_usb_ep[i].usb_ep.maxpacket); | ||
1745 | } | ||
1743 | } | 1746 | } |
1744 | 1747 | ||
1745 | /** | 1748 | /** |
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c index 68be48d33404..aff0a6718bc6 100644 --- a/drivers/usb/gadget/r8a66597-udc.c +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -1833,7 +1833,7 @@ static int __exit r8a66597_remove(struct platform_device *pdev) | |||
1833 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | 1833 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); |
1834 | 1834 | ||
1835 | if (r8a66597->pdata->on_chip) { | 1835 | if (r8a66597->pdata->on_chip) { |
1836 | clk_disable(r8a66597->clk); | 1836 | clk_disable_unprepare(r8a66597->clk); |
1837 | clk_put(r8a66597->clk); | 1837 | clk_put(r8a66597->clk); |
1838 | } | 1838 | } |
1839 | 1839 | ||
@@ -1931,7 +1931,7 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1931 | ret = PTR_ERR(r8a66597->clk); | 1931 | ret = PTR_ERR(r8a66597->clk); |
1932 | goto clean_up; | 1932 | goto clean_up; |
1933 | } | 1933 | } |
1934 | clk_enable(r8a66597->clk); | 1934 | clk_prepare_enable(r8a66597->clk); |
1935 | } | 1935 | } |
1936 | 1936 | ||
1937 | if (r8a66597->pdata->sudmac) { | 1937 | if (r8a66597->pdata->sudmac) { |
@@ -1964,9 +1964,9 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1964 | INIT_LIST_HEAD(&ep->queue); | 1964 | INIT_LIST_HEAD(&ep->queue); |
1965 | ep->ep.name = r8a66597_ep_name[i]; | 1965 | ep->ep.name = r8a66597_ep_name[i]; |
1966 | ep->ep.ops = &r8a66597_ep_ops; | 1966 | ep->ep.ops = &r8a66597_ep_ops; |
1967 | ep->ep.maxpacket = 512; | 1967 | usb_ep_set_maxpacket_limit(&ep->ep, 512); |
1968 | } | 1968 | } |
1969 | r8a66597->ep[0].ep.maxpacket = 64; | 1969 | usb_ep_set_maxpacket_limit(&r8a66597->ep[0].ep, 64); |
1970 | r8a66597->ep[0].pipenum = 0; | 1970 | r8a66597->ep[0].pipenum = 0; |
1971 | r8a66597->ep[0].fifoaddr = CFIFO; | 1971 | r8a66597->ep[0].fifoaddr = CFIFO; |
1972 | r8a66597->ep[0].fifosel = CFIFOSEL; | 1972 | r8a66597->ep[0].fifosel = CFIFOSEL; |
@@ -1996,7 +1996,7 @@ clean_up3: | |||
1996 | free_irq(irq, r8a66597); | 1996 | free_irq(irq, r8a66597); |
1997 | clean_up2: | 1997 | clean_up2: |
1998 | if (r8a66597->pdata->on_chip) { | 1998 | if (r8a66597->pdata->on_chip) { |
1999 | clk_disable(r8a66597->clk); | 1999 | clk_disable_unprepare(r8a66597->clk); |
2000 | clk_put(r8a66597->clk); | 2000 | clk_put(r8a66597->clk); |
2001 | } | 2001 | } |
2002 | clean_up: | 2002 | clean_up: |
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index a3ad732bc812..d822d822efb3 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/moduleparam.h> | 25 | #include <linux/moduleparam.h> |
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/init.h> | ||
29 | #include <linux/list.h> | 28 | #include <linux/list.h> |
30 | #include <linux/proc_fs.h> | 29 | #include <linux/proc_fs.h> |
31 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
@@ -1142,7 +1141,7 @@ static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; | |||
1142 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ | 1141 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
1143 | 1142 | ||
1144 | 1143 | ||
1145 | static int rndis_init(void) | 1144 | int rndis_init(void) |
1146 | { | 1145 | { |
1147 | u8 i; | 1146 | u8 i; |
1148 | 1147 | ||
@@ -1174,9 +1173,8 @@ static int rndis_init(void) | |||
1174 | 1173 | ||
1175 | return 0; | 1174 | return 0; |
1176 | } | 1175 | } |
1177 | module_init(rndis_init); | ||
1178 | 1176 | ||
1179 | static void rndis_exit(void) | 1177 | void rndis_exit(void) |
1180 | { | 1178 | { |
1181 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | 1179 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
1182 | u8 i; | 1180 | u8 i; |
@@ -1188,6 +1186,4 @@ static void rndis_exit(void) | |||
1188 | } | 1186 | } |
1189 | #endif | 1187 | #endif |
1190 | } | 1188 | } |
1191 | module_exit(rndis_exit); | ||
1192 | 1189 | ||
1193 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index e20bc109fdd7..1172eaeddd85 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -30,14 +30,13 @@ | |||
30 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
31 | #include <linux/regulator/consumer.h> | 31 | #include <linux/regulator/consumer.h> |
32 | #include <linux/of_platform.h> | 32 | #include <linux/of_platform.h> |
33 | #include <linux/phy/phy.h> | ||
33 | 34 | ||
34 | #include <linux/usb/ch9.h> | 35 | #include <linux/usb/ch9.h> |
35 | #include <linux/usb/gadget.h> | 36 | #include <linux/usb/gadget.h> |
36 | #include <linux/usb/phy.h> | 37 | #include <linux/usb/phy.h> |
37 | #include <linux/platform_data/s3c-hsotg.h> | 38 | #include <linux/platform_data/s3c-hsotg.h> |
38 | 39 | ||
39 | #include <mach/map.h> | ||
40 | |||
41 | #include "s3c-hsotg.h" | 40 | #include "s3c-hsotg.h" |
42 | 41 | ||
43 | static const char * const s3c_hsotg_supply_names[] = { | 42 | static const char * const s3c_hsotg_supply_names[] = { |
@@ -140,11 +139,13 @@ struct s3c_hsotg_ep { | |||
140 | * @dev: The parent device supplied to the probe function | 139 | * @dev: The parent device supplied to the probe function |
141 | * @driver: USB gadget driver | 140 | * @driver: USB gadget driver |
142 | * @phy: The otg phy transceiver structure for phy control. | 141 | * @phy: The otg phy transceiver structure for phy control. |
142 | * @uphy: The otg phy transceiver structure for old USB phy control. | ||
143 | * @plat: The platform specific configuration data. This can be removed once | 143 | * @plat: The platform specific configuration data. This can be removed once |
144 | * all SoCs support usb transceiver. | 144 | * all SoCs support usb transceiver. |
145 | * @regs: The memory area mapped for accessing registers. | 145 | * @regs: The memory area mapped for accessing registers. |
146 | * @irq: The IRQ number we are using | 146 | * @irq: The IRQ number we are using |
147 | * @supplies: Definition of USB power supplies | 147 | * @supplies: Definition of USB power supplies |
148 | * @phyif: PHY interface width | ||
148 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | 149 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. |
149 | * @num_of_eps: Number of available EPs (excluding EP0) | 150 | * @num_of_eps: Number of available EPs (excluding EP0) |
150 | * @debug_root: root directrory for debugfs. | 151 | * @debug_root: root directrory for debugfs. |
@@ -161,7 +162,8 @@ struct s3c_hsotg_ep { | |||
161 | struct s3c_hsotg { | 162 | struct s3c_hsotg { |
162 | struct device *dev; | 163 | struct device *dev; |
163 | struct usb_gadget_driver *driver; | 164 | struct usb_gadget_driver *driver; |
164 | struct usb_phy *phy; | 165 | struct phy *phy; |
166 | struct usb_phy *uphy; | ||
165 | struct s3c_hsotg_plat *plat; | 167 | struct s3c_hsotg_plat *plat; |
166 | 168 | ||
167 | spinlock_t lock; | 169 | spinlock_t lock; |
@@ -172,6 +174,7 @@ struct s3c_hsotg { | |||
172 | 174 | ||
173 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | 175 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; |
174 | 176 | ||
177 | u32 phyif; | ||
175 | unsigned int dedicated_fifos:1; | 178 | unsigned int dedicated_fifos:1; |
176 | unsigned char num_of_eps; | 179 | unsigned char num_of_eps; |
177 | 180 | ||
@@ -2086,13 +2089,13 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
2086 | case DSTS_EnumSpd_FS48: | 2089 | case DSTS_EnumSpd_FS48: |
2087 | hsotg->gadget.speed = USB_SPEED_FULL; | 2090 | hsotg->gadget.speed = USB_SPEED_FULL; |
2088 | ep0_mps = EP0_MPS_LIMIT; | 2091 | ep0_mps = EP0_MPS_LIMIT; |
2089 | ep_mps = 64; | 2092 | ep_mps = 1023; |
2090 | break; | 2093 | break; |
2091 | 2094 | ||
2092 | case DSTS_EnumSpd_HS: | 2095 | case DSTS_EnumSpd_HS: |
2093 | hsotg->gadget.speed = USB_SPEED_HIGH; | 2096 | hsotg->gadget.speed = USB_SPEED_HIGH; |
2094 | ep0_mps = EP0_MPS_LIMIT; | 2097 | ep0_mps = EP0_MPS_LIMIT; |
2095 | ep_mps = 512; | 2098 | ep_mps = 1024; |
2096 | break; | 2099 | break; |
2097 | 2100 | ||
2098 | case DSTS_EnumSpd_LS: | 2101 | case DSTS_EnumSpd_LS: |
@@ -2156,6 +2159,9 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2156 | s3c_hsotg_complete_request(hsotg, ep, req, | 2159 | s3c_hsotg_complete_request(hsotg, ep, req, |
2157 | result); | 2160 | result); |
2158 | } | 2161 | } |
2162 | if(hsotg->dedicated_fifos) | ||
2163 | if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) | ||
2164 | s3c_hsotg_txfifo_flush(hsotg, ep->index); | ||
2159 | } | 2165 | } |
2160 | 2166 | ||
2161 | #define call_gadget(_hs, _entry) \ | 2167 | #define call_gadget(_hs, _entry) \ |
@@ -2283,7 +2289,7 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2283 | */ | 2289 | */ |
2284 | 2290 | ||
2285 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | 2291 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
2286 | writel(GUSBCFG_PHYIf16 | GUSBCFG_TOutCal(7) | | 2292 | writel(hsotg->phyif | GUSBCFG_TOutCal(7) | |
2287 | (0x5 << 10), hsotg->regs + GUSBCFG); | 2293 | (0x5 << 10), hsotg->regs + GUSBCFG); |
2288 | 2294 | ||
2289 | s3c_hsotg_init_fifo(hsotg); | 2295 | s3c_hsotg_init_fifo(hsotg); |
@@ -2908,8 +2914,11 @@ static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) | |||
2908 | 2914 | ||
2909 | dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); | 2915 | dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); |
2910 | 2916 | ||
2911 | if (hsotg->phy) | 2917 | if (hsotg->phy) { |
2912 | usb_phy_init(hsotg->phy); | 2918 | phy_init(hsotg->phy); |
2919 | phy_power_on(hsotg->phy); | ||
2920 | } else if (hsotg->uphy) | ||
2921 | usb_phy_init(hsotg->uphy); | ||
2913 | else if (hsotg->plat->phy_init) | 2922 | else if (hsotg->plat->phy_init) |
2914 | hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); | 2923 | hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); |
2915 | } | 2924 | } |
@@ -2925,8 +2934,11 @@ static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg) | |||
2925 | { | 2934 | { |
2926 | struct platform_device *pdev = to_platform_device(hsotg->dev); | 2935 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
2927 | 2936 | ||
2928 | if (hsotg->phy) | 2937 | if (hsotg->phy) { |
2929 | usb_phy_shutdown(hsotg->phy); | 2938 | phy_power_off(hsotg->phy); |
2939 | phy_exit(hsotg->phy); | ||
2940 | } else if (hsotg->uphy) | ||
2941 | usb_phy_shutdown(hsotg->uphy); | ||
2930 | else if (hsotg->plat->phy_exit) | 2942 | else if (hsotg->plat->phy_exit) |
2931 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); | 2943 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); |
2932 | } | 2944 | } |
@@ -3152,7 +3164,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3152 | 3164 | ||
3153 | hs_ep->parent = hsotg; | 3165 | hs_ep->parent = hsotg; |
3154 | hs_ep->ep.name = hs_ep->name; | 3166 | hs_ep->ep.name = hs_ep->name; |
3155 | hs_ep->ep.maxpacket = epnum ? 1024 : EP0_MPS_LIMIT; | 3167 | usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT); |
3156 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; | 3168 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
3157 | 3169 | ||
3158 | /* | 3170 | /* |
@@ -3533,7 +3545,8 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | |||
3533 | static int s3c_hsotg_probe(struct platform_device *pdev) | 3545 | static int s3c_hsotg_probe(struct platform_device *pdev) |
3534 | { | 3546 | { |
3535 | struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev); | 3547 | struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev); |
3536 | struct usb_phy *phy; | 3548 | struct phy *phy; |
3549 | struct usb_phy *uphy; | ||
3537 | struct device *dev = &pdev->dev; | 3550 | struct device *dev = &pdev->dev; |
3538 | struct s3c_hsotg_ep *eps; | 3551 | struct s3c_hsotg_ep *eps; |
3539 | struct s3c_hsotg *hsotg; | 3552 | struct s3c_hsotg *hsotg; |
@@ -3548,19 +3561,26 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3548 | return -ENOMEM; | 3561 | return -ENOMEM; |
3549 | } | 3562 | } |
3550 | 3563 | ||
3551 | phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | 3564 | /* |
3565 | * Attempt to find a generic PHY, then look for an old style | ||
3566 | * USB PHY, finally fall back to pdata | ||
3567 | */ | ||
3568 | phy = devm_phy_get(&pdev->dev, "usb2-phy"); | ||
3552 | if (IS_ERR(phy)) { | 3569 | if (IS_ERR(phy)) { |
3553 | /* Fallback for pdata */ | 3570 | uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
3554 | plat = dev_get_platdata(&pdev->dev); | 3571 | if (IS_ERR(uphy)) { |
3555 | if (!plat) { | 3572 | /* Fallback for pdata */ |
3556 | dev_err(&pdev->dev, "no platform data or transceiver defined\n"); | 3573 | plat = dev_get_platdata(&pdev->dev); |
3557 | return -EPROBE_DEFER; | 3574 | if (!plat) { |
3558 | } else { | 3575 | dev_err(&pdev->dev, |
3576 | "no platform data or transceiver defined\n"); | ||
3577 | return -EPROBE_DEFER; | ||
3578 | } | ||
3559 | hsotg->plat = plat; | 3579 | hsotg->plat = plat; |
3560 | } | 3580 | } else |
3561 | } else { | 3581 | hsotg->uphy = uphy; |
3582 | } else | ||
3562 | hsotg->phy = phy; | 3583 | hsotg->phy = phy; |
3563 | } | ||
3564 | 3584 | ||
3565 | hsotg->dev = dev; | 3585 | hsotg->dev = dev; |
3566 | 3586 | ||
@@ -3627,6 +3647,19 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3627 | goto err_supplies; | 3647 | goto err_supplies; |
3628 | } | 3648 | } |
3629 | 3649 | ||
3650 | /* Set default UTMI width */ | ||
3651 | hsotg->phyif = GUSBCFG_PHYIf16; | ||
3652 | |||
3653 | /* | ||
3654 | * If using the generic PHY framework, check if the PHY bus | ||
3655 | * width is 8-bit and set the phyif appropriately. | ||
3656 | */ | ||
3657 | if (hsotg->phy && (phy_get_bus_width(phy) == 8)) | ||
3658 | hsotg->phyif = GUSBCFG_PHYIf8; | ||
3659 | |||
3660 | if (hsotg->phy) | ||
3661 | phy_init(hsotg->phy); | ||
3662 | |||
3630 | /* usb phy enable */ | 3663 | /* usb phy enable */ |
3631 | s3c_hsotg_phy_enable(hsotg); | 3664 | s3c_hsotg_phy_enable(hsotg); |
3632 | 3665 | ||
@@ -3720,6 +3753,8 @@ static int s3c_hsotg_remove(struct platform_device *pdev) | |||
3720 | } | 3753 | } |
3721 | 3754 | ||
3722 | s3c_hsotg_phy_disable(hsotg); | 3755 | s3c_hsotg_phy_disable(hsotg); |
3756 | if (hsotg->phy) | ||
3757 | phy_exit(hsotg->phy); | ||
3723 | clk_disable_unprepare(hsotg->clk); | 3758 | clk_disable_unprepare(hsotg->clk); |
3724 | 3759 | ||
3725 | return 0; | 3760 | return 0; |
@@ -3733,6 +3768,7 @@ static int s3c_hsotg_remove(struct platform_device *pdev) | |||
3733 | #ifdef CONFIG_OF | 3768 | #ifdef CONFIG_OF |
3734 | static const struct of_device_id s3c_hsotg_of_ids[] = { | 3769 | static const struct of_device_id s3c_hsotg_of_ids[] = { |
3735 | { .compatible = "samsung,s3c6400-hsotg", }, | 3770 | { .compatible = "samsung,s3c6400-hsotg", }, |
3771 | { .compatible = "snps,dwc2", }, | ||
3736 | { /* sentinel */ } | 3772 | { /* sentinel */ } |
3737 | }; | 3773 | }; |
3738 | MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids); | 3774 | MODULE_DEVICE_TABLE(of, s3c_hsotg_of_ids); |
diff --git a/drivers/usb/gadget/s3c-hsotg.h b/drivers/usb/gadget/s3c-hsotg.h index d650b1295831..85f549ff8c1f 100644 --- a/drivers/usb/gadget/s3c-hsotg.h +++ b/drivers/usb/gadget/s3c-hsotg.h | |||
@@ -55,6 +55,7 @@ | |||
55 | #define GUSBCFG_HNPCap (1 << 9) | 55 | #define GUSBCFG_HNPCap (1 << 9) |
56 | #define GUSBCFG_SRPCap (1 << 8) | 56 | #define GUSBCFG_SRPCap (1 << 8) |
57 | #define GUSBCFG_PHYIf16 (1 << 3) | 57 | #define GUSBCFG_PHYIf16 (1 << 3) |
58 | #define GUSBCFG_PHYIf8 (0 << 3) | ||
58 | #define GUSBCFG_TOutCal_MASK (0x7 << 0) | 59 | #define GUSBCFG_TOutCal_MASK (0x7 << 0) |
59 | #define GUSBCFG_TOutCal_SHIFT (0) | 60 | #define GUSBCFG_TOutCal_SHIFT (0) |
60 | #define GUSBCFG_TOutCal_LIMIT (0x7) | 61 | #define GUSBCFG_TOutCal_LIMIT (0x7) |
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c index 1a1a41498db2..ea4bbfe72ec0 100644 --- a/drivers/usb/gadget/s3c-hsudc.c +++ b/drivers/usb/gadget/s3c-hsudc.c | |||
@@ -999,7 +999,7 @@ static void s3c_hsudc_initep(struct s3c_hsudc *hsudc, | |||
999 | 999 | ||
1000 | hsep->dev = hsudc; | 1000 | hsep->dev = hsudc; |
1001 | hsep->ep.name = hsep->name; | 1001 | hsep->ep.name = hsep->name; |
1002 | hsep->ep.maxpacket = epnum ? 512 : 64; | 1002 | usb_ep_set_maxpacket_limit(&hsep->ep, epnum ? 512 : 64); |
1003 | hsep->ep.ops = &s3c_hsudc_ep_ops; | 1003 | hsep->ep.ops = &s3c_hsudc_ep_ops; |
1004 | hsep->fifo = hsudc->regs + S3C_BR(epnum); | 1004 | hsep->fifo = hsudc->regs + S3C_BR(epnum); |
1005 | hsep->ep.desc = NULL; | 1005 | hsep->ep.desc = NULL; |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index c72d810e6b36..f04b2c3154de 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1629,6 +1629,7 @@ static void s3c2410_udc_reinit(struct s3c2410_udc *dev) | |||
1629 | ep->ep.desc = NULL; | 1629 | ep->ep.desc = NULL; |
1630 | ep->halted = 0; | 1630 | ep->halted = 0; |
1631 | INIT_LIST_HEAD(&ep->queue); | 1631 | INIT_LIST_HEAD(&ep->queue); |
1632 | usb_ep_set_maxpacket_limit(&ep->ep, &ep->ep.maxpacket); | ||
1632 | } | 1633 | } |
1633 | } | 1634 | } |
1634 | 1635 | ||
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 2aae0d61bb19..b7d4f82872b7 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -753,7 +753,7 @@ static struct device_type gadget_type = { | |||
753 | * gadget driver using this framework. The link layer addresses are | 753 | * gadget driver using this framework. The link layer addresses are |
754 | * set up using module parameters. | 754 | * set up using module parameters. |
755 | * | 755 | * |
756 | * Returns negative errno, or zero on success | 756 | * Returns an eth_dev pointer on success, or an ERR_PTR on failure. |
757 | */ | 757 | */ |
758 | struct eth_dev *gether_setup_name(struct usb_gadget *g, | 758 | struct eth_dev *gether_setup_name(struct usb_gadget *g, |
759 | const char *dev_addr, const char *host_addr, | 759 | const char *dev_addr, const char *host_addr, |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index fb23d1fde8eb..0f0290acea7e 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -106,7 +106,7 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, | |||
106 | * gadget driver using this framework. The link layer addresses are | 106 | * gadget driver using this framework. The link layer addresses are |
107 | * set up using module parameters. | 107 | * set up using module parameters. |
108 | * | 108 | * |
109 | * Returns negative errno, or zero on success | 109 | * Returns a eth_dev pointer on success, or an ERR_PTR on failure |
110 | */ | 110 | */ |
111 | static inline struct eth_dev *gether_setup(struct usb_gadget *g, | 111 | static inline struct eth_dev *gether_setup(struct usb_gadget *g, |
112 | const char *dev_addr, const char *host_addr, | 112 | const char *dev_addr, const char *host_addr, |
@@ -267,45 +267,4 @@ static inline bool can_support_ecm(struct usb_gadget *gadget) | |||
267 | return true; | 267 | return true; |
268 | } | 268 | } |
269 | 269 | ||
270 | /* each configuration may bind one instance of an ethernet link */ | ||
271 | int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
272 | struct eth_dev *dev); | ||
273 | int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
274 | struct eth_dev *dev); | ||
275 | |||
276 | #ifdef USB_ETH_RNDIS | ||
277 | |||
278 | int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
279 | u32 vendorID, const char *manufacturer, struct eth_dev *dev); | ||
280 | |||
281 | #else | ||
282 | |||
283 | static inline int | ||
284 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], | ||
285 | u32 vendorID, const char *manufacturer, struct eth_dev *dev) | ||
286 | { | ||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | #endif | ||
291 | |||
292 | /** | ||
293 | * rndis_bind_config - add RNDIS network link to a configuration | ||
294 | * @c: the configuration to support the network link | ||
295 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
296 | * side of the link was recorded | ||
297 | * Context: single threaded during gadget setup | ||
298 | * | ||
299 | * Returns zero on success, else negative errno. | ||
300 | * | ||
301 | * Caller must have called @gether_setup(). Caller is also responsible | ||
302 | * for calling @gether_cleanup() before module unload. | ||
303 | */ | ||
304 | static inline int rndis_bind_config(struct usb_configuration *c, | ||
305 | u8 ethaddr[ETH_ALEN], struct eth_dev *dev) | ||
306 | { | ||
307 | return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev); | ||
308 | } | ||
309 | |||
310 | |||
311 | #endif /* __U_ETHER_H */ | 270 | #endif /* __U_ETHER_H */ |
diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c new file mode 100644 index 000000000000..63b6642c162b --- /dev/null +++ b/drivers/usb/gadget/u_f.c | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | * u_f.c -- USB function utilities for Gadget stack | ||
3 | * | ||
4 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
5 | * http://www.samsung.com | ||
6 | * | ||
7 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | */ | ||
13 | |||
14 | #include <linux/usb/gadget.h> | ||
15 | #include "u_f.h" | ||
16 | |||
17 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len) | ||
18 | { | ||
19 | struct usb_request *req; | ||
20 | |||
21 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | ||
22 | if (req) { | ||
23 | req->length = len ?: default_len; | ||
24 | req->buf = kmalloc(req->length, GFP_ATOMIC); | ||
25 | if (!req->buf) { | ||
26 | usb_ep_free_request(ep, req); | ||
27 | req = NULL; | ||
28 | } | ||
29 | } | ||
30 | return req; | ||
31 | } | ||
32 | EXPORT_SYMBOL(alloc_ep_req); | ||
diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h new file mode 100644 index 000000000000..71034c061fca --- /dev/null +++ b/drivers/usb/gadget/u_f.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * u_f.h | ||
3 | * | ||
4 | * Utility definitions for USB functions | ||
5 | * | ||
6 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
7 | * http://www.samsung.com | ||
8 | * | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef __U_F_H__ | ||
17 | #define __U_F_H__ | ||
18 | |||
19 | struct usb_ep; | ||
20 | struct usb_request; | ||
21 | |||
22 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len); | ||
23 | |||
24 | #endif /* __U_F_H__ */ | ||
25 | |||
26 | |||
diff --git a/drivers/usb/gadget/u_fs.h b/drivers/usb/gadget/u_fs.h new file mode 100644 index 000000000000..bc2d3718219b --- /dev/null +++ b/drivers/usb/gadget/u_fs.h | |||
@@ -0,0 +1,267 @@ | |||
1 | /* | ||
2 | * u_fs.h | ||
3 | * | ||
4 | * Utility definitions for the FunctionFS | ||
5 | * | ||
6 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
7 | * http://www.samsung.com | ||
8 | * | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef U_FFS_H | ||
17 | #define U_FFS_H | ||
18 | |||
19 | #include <linux/usb/composite.h> | ||
20 | #include <linux/list.h> | ||
21 | #include <linux/mutex.h> | ||
22 | |||
23 | #ifdef VERBOSE_DEBUG | ||
24 | #ifndef pr_vdebug | ||
25 | # define pr_vdebug pr_debug | ||
26 | #endif /* pr_vdebug */ | ||
27 | # define ffs_dump_mem(prefix, ptr, len) \ | ||
28 | print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len) | ||
29 | #else | ||
30 | #ifndef pr_vdebug | ||
31 | # define pr_vdebug(...) do { } while (0) | ||
32 | #endif /* pr_vdebug */ | ||
33 | # define ffs_dump_mem(prefix, ptr, len) do { } while (0) | ||
34 | #endif /* VERBOSE_DEBUG */ | ||
35 | |||
36 | #define ENTER() pr_vdebug("%s()\n", __func__) | ||
37 | |||
38 | struct f_fs_opts; | ||
39 | |||
40 | struct ffs_dev { | ||
41 | const char *name; | ||
42 | bool name_allocated; | ||
43 | bool mounted; | ||
44 | bool desc_ready; | ||
45 | bool single; | ||
46 | struct ffs_data *ffs_data; | ||
47 | struct f_fs_opts *opts; | ||
48 | struct list_head entry; | ||
49 | |||
50 | int (*ffs_ready_callback)(struct ffs_data *ffs); | ||
51 | void (*ffs_closed_callback)(struct ffs_data *ffs); | ||
52 | void *(*ffs_acquire_dev_callback)(struct ffs_dev *dev); | ||
53 | void (*ffs_release_dev_callback)(struct ffs_dev *dev); | ||
54 | }; | ||
55 | |||
56 | extern struct mutex ffs_lock; | ||
57 | |||
58 | static inline void ffs_dev_lock(void) | ||
59 | { | ||
60 | mutex_lock(&ffs_lock); | ||
61 | } | ||
62 | |||
63 | static inline void ffs_dev_unlock(void) | ||
64 | { | ||
65 | mutex_unlock(&ffs_lock); | ||
66 | } | ||
67 | |||
68 | struct ffs_dev *ffs_alloc_dev(void); | ||
69 | int ffs_name_dev(struct ffs_dev *dev, const char *name); | ||
70 | int ffs_single_dev(struct ffs_dev *dev); | ||
71 | void ffs_free_dev(struct ffs_dev *dev); | ||
72 | |||
73 | struct ffs_epfile; | ||
74 | struct ffs_function; | ||
75 | |||
76 | enum ffs_state { | ||
77 | /* | ||
78 | * Waiting for descriptors and strings. | ||
79 | * | ||
80 | * In this state no open(2), read(2) or write(2) on epfiles | ||
81 | * may succeed (which should not be the problem as there | ||
82 | * should be no such files opened in the first place). | ||
83 | */ | ||
84 | FFS_READ_DESCRIPTORS, | ||
85 | FFS_READ_STRINGS, | ||
86 | |||
87 | /* | ||
88 | * We've got descriptors and strings. We are or have called | ||
89 | * functionfs_ready_callback(). functionfs_bind() may have | ||
90 | * been called but we don't know. | ||
91 | * | ||
92 | * This is the only state in which operations on epfiles may | ||
93 | * succeed. | ||
94 | */ | ||
95 | FFS_ACTIVE, | ||
96 | |||
97 | /* | ||
98 | * All endpoints have been closed. This state is also set if | ||
99 | * we encounter an unrecoverable error. The only | ||
100 | * unrecoverable error is situation when after reading strings | ||
101 | * from user space we fail to initialise epfiles or | ||
102 | * functionfs_ready_callback() returns with error (<0). | ||
103 | * | ||
104 | * In this state no open(2), read(2) or write(2) (both on ep0 | ||
105 | * as well as epfile) may succeed (at this point epfiles are | ||
106 | * unlinked and all closed so this is not a problem; ep0 is | ||
107 | * also closed but ep0 file exists and so open(2) on ep0 must | ||
108 | * fail). | ||
109 | */ | ||
110 | FFS_CLOSING | ||
111 | }; | ||
112 | |||
113 | enum ffs_setup_state { | ||
114 | /* There is no setup request pending. */ | ||
115 | FFS_NO_SETUP, | ||
116 | /* | ||
117 | * User has read events and there was a setup request event | ||
118 | * there. The next read/write on ep0 will handle the | ||
119 | * request. | ||
120 | */ | ||
121 | FFS_SETUP_PENDING, | ||
122 | /* | ||
123 | * There was event pending but before user space handled it | ||
124 | * some other event was introduced which canceled existing | ||
125 | * setup. If this state is set read/write on ep0 return | ||
126 | * -EIDRM. This state is only set when adding event. | ||
127 | */ | ||
128 | FFS_SETUP_CANCELED | ||
129 | }; | ||
130 | |||
131 | struct ffs_data { | ||
132 | struct usb_gadget *gadget; | ||
133 | |||
134 | /* | ||
135 | * Protect access read/write operations, only one read/write | ||
136 | * at a time. As a consequence protects ep0req and company. | ||
137 | * While setup request is being processed (queued) this is | ||
138 | * held. | ||
139 | */ | ||
140 | struct mutex mutex; | ||
141 | |||
142 | /* | ||
143 | * Protect access to endpoint related structures (basically | ||
144 | * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for | ||
145 | * endpoint zero. | ||
146 | */ | ||
147 | spinlock_t eps_lock; | ||
148 | |||
149 | /* | ||
150 | * XXX REVISIT do we need our own request? Since we are not | ||
151 | * handling setup requests immediately user space may be so | ||
152 | * slow that another setup will be sent to the gadget but this | ||
153 | * time not to us but another function and then there could be | ||
154 | * a race. Is that the case? Or maybe we can use cdev->req | ||
155 | * after all, maybe we just need some spinlock for that? | ||
156 | */ | ||
157 | struct usb_request *ep0req; /* P: mutex */ | ||
158 | struct completion ep0req_completion; /* P: mutex */ | ||
159 | int ep0req_status; /* P: mutex */ | ||
160 | |||
161 | /* reference counter */ | ||
162 | atomic_t ref; | ||
163 | /* how many files are opened (EP0 and others) */ | ||
164 | atomic_t opened; | ||
165 | |||
166 | /* EP0 state */ | ||
167 | enum ffs_state state; | ||
168 | |||
169 | /* | ||
170 | * Possible transitions: | ||
171 | * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock | ||
172 | * happens only in ep0 read which is P: mutex | ||
173 | * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock | ||
174 | * happens only in ep0 i/o which is P: mutex | ||
175 | * + FFS_SETUP_PENDING -> FFS_SETUP_CANCELED -- P: ev.waitq.lock | ||
176 | * + FFS_SETUP_CANCELED -> FFS_NO_SETUP -- cmpxchg | ||
177 | */ | ||
178 | enum ffs_setup_state setup_state; | ||
179 | |||
180 | #define FFS_SETUP_STATE(ffs) \ | ||
181 | ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state, \ | ||
182 | FFS_SETUP_CANCELED, FFS_NO_SETUP)) | ||
183 | |||
184 | /* Events & such. */ | ||
185 | struct { | ||
186 | u8 types[4]; | ||
187 | unsigned short count; | ||
188 | /* XXX REVISIT need to update it in some places, or do we? */ | ||
189 | unsigned short can_stall; | ||
190 | struct usb_ctrlrequest setup; | ||
191 | |||
192 | wait_queue_head_t waitq; | ||
193 | } ev; /* the whole structure, P: ev.waitq.lock */ | ||
194 | |||
195 | /* Flags */ | ||
196 | unsigned long flags; | ||
197 | #define FFS_FL_CALL_CLOSED_CALLBACK 0 | ||
198 | #define FFS_FL_BOUND 1 | ||
199 | |||
200 | /* Active function */ | ||
201 | struct ffs_function *func; | ||
202 | |||
203 | /* | ||
204 | * Device name, write once when file system is mounted. | ||
205 | * Intended for user to read if she wants. | ||
206 | */ | ||
207 | const char *dev_name; | ||
208 | /* Private data for our user (ie. gadget). Managed by user. */ | ||
209 | void *private_data; | ||
210 | |||
211 | /* filled by __ffs_data_got_descs() */ | ||
212 | /* | ||
213 | * Real descriptors are 16 bytes after raw_descs (so you need | ||
214 | * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the | ||
215 | * first full speed descriptor). raw_descs_length and | ||
216 | * raw_fs_descs_length do not have those 16 bytes added. | ||
217 | */ | ||
218 | const void *raw_descs; | ||
219 | unsigned raw_descs_length; | ||
220 | unsigned raw_fs_descs_length; | ||
221 | unsigned fs_descs_count; | ||
222 | unsigned hs_descs_count; | ||
223 | |||
224 | unsigned short strings_count; | ||
225 | unsigned short interfaces_count; | ||
226 | unsigned short eps_count; | ||
227 | unsigned short _pad1; | ||
228 | |||
229 | /* filled by __ffs_data_got_strings() */ | ||
230 | /* ids in stringtabs are set in functionfs_bind() */ | ||
231 | const void *raw_strings; | ||
232 | struct usb_gadget_strings **stringtabs; | ||
233 | |||
234 | /* | ||
235 | * File system's super block, write once when file system is | ||
236 | * mounted. | ||
237 | */ | ||
238 | struct super_block *sb; | ||
239 | |||
240 | /* File permissions, written once when fs is mounted */ | ||
241 | struct ffs_file_perms { | ||
242 | umode_t mode; | ||
243 | kuid_t uid; | ||
244 | kgid_t gid; | ||
245 | } file_perms; | ||
246 | |||
247 | /* | ||
248 | * The endpoint files, filled by ffs_epfiles_create(), | ||
249 | * destroyed by ffs_epfiles_destroy(). | ||
250 | */ | ||
251 | struct ffs_epfile *epfiles; | ||
252 | }; | ||
253 | |||
254 | |||
255 | struct f_fs_opts { | ||
256 | struct usb_function_instance func_inst; | ||
257 | struct ffs_dev *dev; | ||
258 | unsigned refcnt; | ||
259 | bool no_configfs; | ||
260 | }; | ||
261 | |||
262 | static inline struct f_fs_opts *to_f_fs_opts(struct usb_function_instance *fi) | ||
263 | { | ||
264 | return container_of(fi, struct f_fs_opts, func_inst); | ||
265 | } | ||
266 | |||
267 | #endif /* U_FFS_H */ | ||
diff --git a/drivers/usb/gadget/u_rndis.h b/drivers/usb/gadget/u_rndis.h index c62ba82e9600..7291b15c9dce 100644 --- a/drivers/usb/gadget/u_rndis.h +++ b/drivers/usb/gadget/u_rndis.h | |||
@@ -36,6 +36,8 @@ struct f_rndis_opts { | |||
36 | int refcnt; | 36 | int refcnt; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | int rndis_init(void); | ||
40 | void rndis_exit(void); | ||
39 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net); | 41 | void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net); |
40 | 42 | ||
41 | #endif /* U_RNDIS_H */ | 43 | #endif /* U_RNDIS_H */ |
diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c index 1f49fce0f0b7..73a4dfba0edb 100644 --- a/drivers/usb/gadget/usbstring.c +++ b/drivers/usb/gadget/usbstring.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #include <linux/list.h> | 13 | #include <linux/list.h> |
14 | #include <linux/string.h> | 14 | #include <linux/string.h> |
15 | #include <linux/device.h> | 15 | #include <linux/device.h> |
16 | #include <linux/init.h> | ||
17 | #include <linux/nls.h> | 16 | #include <linux/nls.h> |
18 | 17 | ||
19 | #include <linux/usb/ch9.h> | 18 | #include <linux/usb/ch9.h> |
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index f49b0b61ecc8..9f170c53e3d9 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -64,10 +64,10 @@ static bool loopdefault = 0; | |||
64 | module_param(loopdefault, bool, S_IRUGO|S_IWUSR); | 64 | module_param(loopdefault, bool, S_IRUGO|S_IWUSR); |
65 | 65 | ||
66 | static struct usb_zero_options gzero_options = { | 66 | static struct usb_zero_options gzero_options = { |
67 | .isoc_interval = 4, | 67 | .isoc_interval = GZERO_ISOC_INTERVAL, |
68 | .isoc_maxpacket = 1024, | 68 | .isoc_maxpacket = GZERO_ISOC_MAXPACKET, |
69 | .bulk_buflen = 4096, | 69 | .bulk_buflen = GZERO_BULK_BUFLEN, |
70 | .qlen = 32, | 70 | .qlen = GZERO_QLEN, |
71 | }; | 71 | }; |
72 | 72 | ||
73 | /*-------------------------------------------------------------------------*/ | 73 | /*-------------------------------------------------------------------------*/ |