summaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-01-30 08:39:20 -0500
committerLinus Walleij <linus.walleij@linaro.org>2017-01-30 08:39:20 -0500
commit7f36f5d11cda050b118f76d774151427a18d15ef (patch)
tree9d4fa3b830785b767525a5e6a065fe4297cd8112 /drivers/usb
parent2b24efa8e5c5042b0f126c09622b3e9e3c86a4fa (diff)
parent566cf877a1fcb6d6dc0126b076aad062054c2637 (diff)
Merge tag 'v4.10-rc6' into devel
Linux 4.10-rc6 Resolved conflicts in: drivers/pinctrl/pinctrl-amd.c drivers/pinctrl/samsung/pinctrl-exynos.c
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/core/config.c10
-rw-r--r--drivers/usb/core/hub.c59
-rw-r--r--drivers/usb/dwc2/core.h4
-rw-r--r--drivers/usb/dwc2/gadget.c20
-rw-r--r--drivers/usb/dwc2/hcd.c7
-rw-r--r--drivers/usb/dwc2/params.c40
-rw-r--r--drivers/usb/dwc3/core.h10
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c4
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c6
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c17
-rw-r--r--drivers/usb/dwc3/ep0.c46
-rw-r--r--drivers/usb/dwc3/gadget.c24
-rw-r--r--drivers/usb/gadget/composite.c14
-rw-r--r--drivers/usb/gadget/function/f_fs.c26
-rw-r--r--drivers/usb/gadget/function/f_hid.c2
-rw-r--r--drivers/usb/gadget/legacy/inode.c18
-rw-r--r--drivers/usb/gadget/udc/atmel_usba_udc.c3
-rw-r--r--drivers/usb/gadget/udc/atmel_usba_udc.h1
-rw-r--r--drivers/usb/gadget/udc/core.c6
-rw-r--r--drivers/usb/gadget/udc/dummy_hcd.c6
-rw-r--r--drivers/usb/host/ohci-at91.c24
-rw-r--r--drivers/usb/host/xhci-mem.c46
-rw-r--r--drivers/usb/host/xhci-mtk.c4
-rw-r--r--drivers/usb/host/xhci-pci.c3
-rw-r--r--drivers/usb/host/xhci-plat.c2
-rw-r--r--drivers/usb/host/xhci-ring.c262
-rw-r--r--drivers/usb/host/xhci.c17
-rw-r--r--drivers/usb/host/xhci.h5
-rw-r--r--drivers/usb/musb/blackfin.c1
-rw-r--r--drivers/usb/musb/musb_core.c2
-rw-r--r--drivers/usb/musb/musb_core.h7
-rw-r--r--drivers/usb/musb/musb_debugfs.c20
-rw-r--r--drivers/usb/musb/musb_dsps.c12
-rw-r--r--drivers/usb/musb/musb_host.c10
-rw-r--r--drivers/usb/musb/musbhsdma.h2
-rw-r--r--drivers/usb/serial/ch341.c108
-rw-r--r--drivers/usb/serial/cyberjack.c10
-rw-r--r--drivers/usb/serial/f81534.c8
-rw-r--r--drivers/usb/serial/garmin_gps.c1
-rw-r--r--drivers/usb/serial/io_edgeport.c5
-rw-r--r--drivers/usb/serial/io_ti.c22
-rw-r--r--drivers/usb/serial/iuu_phoenix.c11
-rw-r--r--drivers/usb/serial/keyspan_pda.c14
-rw-r--r--drivers/usb/serial/kl5kusb105.c9
-rw-r--r--drivers/usb/serial/kobil_sct.c12
-rw-r--r--drivers/usb/serial/mos7720.c56
-rw-r--r--drivers/usb/serial/mos7840.c24
-rw-r--r--drivers/usb/serial/omninet.c13
-rw-r--r--drivers/usb/serial/oti6858.c16
-rw-r--r--drivers/usb/serial/pl2303.c8
-rw-r--r--drivers/usb/serial/quatech2.c4
-rw-r--r--drivers/usb/serial/spcp8x5.c14
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c7
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/usb/wusbcore/crypto.c3
55 files changed, 678 insertions, 414 deletions
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 0aa9e7d697a5..25dbd8c7aec7 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -239,6 +239,16 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
239 if (ifp->desc.bNumEndpoints >= num_ep) 239 if (ifp->desc.bNumEndpoints >= num_ep)
240 goto skip_to_next_endpoint_or_interface_descriptor; 240 goto skip_to_next_endpoint_or_interface_descriptor;
241 241
242 /* Check for duplicate endpoint addresses */
243 for (i = 0; i < ifp->desc.bNumEndpoints; ++i) {
244 if (ifp->endpoint[i].desc.bEndpointAddress ==
245 d->bEndpointAddress) {
246 dev_warn(ddev, "config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n",
247 cfgno, inum, asnum, d->bEndpointAddress);
248 goto skip_to_next_endpoint_or_interface_descriptor;
249 }
250 }
251
242 endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints]; 252 endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints];
243 ++ifp->desc.bNumEndpoints; 253 ++ifp->desc.bNumEndpoints;
244 254
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 1fa5c0f29c64..a56c75e09786 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -103,8 +103,7 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
103 103
104static void hub_release(struct kref *kref); 104static void hub_release(struct kref *kref);
105static int usb_reset_and_verify_device(struct usb_device *udev); 105static int usb_reset_and_verify_device(struct usb_device *udev);
106static void hub_usb3_port_prepare_disable(struct usb_hub *hub, 106static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
107 struct usb_port *port_dev);
108 107
109static inline char *portspeed(struct usb_hub *hub, int portstatus) 108static inline char *portspeed(struct usb_hub *hub, int portstatus)
110{ 109{
@@ -903,34 +902,6 @@ static int hub_set_port_link_state(struct usb_hub *hub, int port1,
903} 902}
904 903
905/* 904/*
906 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
907 * a connection with a plugged-in cable but will signal the host when the cable
908 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
909 */
910static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
911{
912 struct usb_port *port_dev = hub->ports[port1 - 1];
913 struct usb_device *hdev = hub->hdev;
914 int ret = 0;
915
916 if (!hub->error) {
917 if (hub_is_superspeed(hub->hdev)) {
918 hub_usb3_port_prepare_disable(hub, port_dev);
919 ret = hub_set_port_link_state(hub, port_dev->portnum,
920 USB_SS_PORT_LS_U3);
921 } else {
922 ret = usb_clear_port_feature(hdev, port1,
923 USB_PORT_FEAT_ENABLE);
924 }
925 }
926 if (port_dev->child && set_state)
927 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED);
928 if (ret && ret != -ENODEV)
929 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret);
930 return ret;
931}
932
933/*
934 * Disable a port and mark a logical connect-change event, so that some 905 * Disable a port and mark a logical connect-change event, so that some
935 * time later hub_wq will disconnect() any existing usb_device on the port 906 * time later hub_wq will disconnect() any existing usb_device on the port
936 * and will re-enumerate if there actually is a device attached. 907 * and will re-enumerate if there actually is a device attached.
@@ -4162,6 +4133,34 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
4162 4133
4163#endif /* CONFIG_PM */ 4134#endif /* CONFIG_PM */
4164 4135
4136/*
4137 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4138 * a connection with a plugged-in cable but will signal the host when the cable
4139 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
4140 */
4141static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
4142{
4143 struct usb_port *port_dev = hub->ports[port1 - 1];
4144 struct usb_device *hdev = hub->hdev;
4145 int ret = 0;
4146
4147 if (!hub->error) {
4148 if (hub_is_superspeed(hub->hdev)) {
4149 hub_usb3_port_prepare_disable(hub, port_dev);
4150 ret = hub_set_port_link_state(hub, port_dev->portnum,
4151 USB_SS_PORT_LS_U3);
4152 } else {
4153 ret = usb_clear_port_feature(hdev, port1,
4154 USB_PORT_FEAT_ENABLE);
4155 }
4156 }
4157 if (port_dev->child && set_state)
4158 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED);
4159 if (ret && ret != -ENODEV)
4160 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret);
4161 return ret;
4162}
4163
4165 4164
4166/* USB 2.0 spec, 7.1.7.3 / fig 7-29: 4165/* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4167 * 4166 *
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 9548d3e03453..302b8f5f7d27 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -513,8 +513,8 @@ struct dwc2_core_params {
513 /* Gadget parameters */ 513 /* Gadget parameters */
514 bool g_dma; 514 bool g_dma;
515 bool g_dma_desc; 515 bool g_dma_desc;
516 u16 g_rx_fifo_size; 516 u32 g_rx_fifo_size;
517 u16 g_np_tx_fifo_size; 517 u32 g_np_tx_fifo_size;
518 u32 g_tx_fifo_size[MAX_EPS_CHANNELS]; 518 u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
519}; 519};
520 520
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index b95930f20d90..77c5fcf3a5bf 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3169,7 +3169,7 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
3169 /* keep other bits untouched (so e.g. forced modes are not lost) */ 3169 /* keep other bits untouched (so e.g. forced modes are not lost) */
3170 usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 3170 usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
3171 usbcfg &= ~(GUSBCFG_TOUTCAL_MASK | GUSBCFG_PHYIF16 | GUSBCFG_SRPCAP | 3171 usbcfg &= ~(GUSBCFG_TOUTCAL_MASK | GUSBCFG_PHYIF16 | GUSBCFG_SRPCAP |
3172 GUSBCFG_HNPCAP); 3172 GUSBCFG_HNPCAP | GUSBCFG_USBTRDTIM_MASK);
3173 3173
3174 if (hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS && 3174 if (hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS &&
3175 (hsotg->params.speed == DWC2_SPEED_PARAM_FULL || 3175 (hsotg->params.speed == DWC2_SPEED_PARAM_FULL ||
@@ -3749,11 +3749,11 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
3749 __func__, epctrl, epctrl_reg); 3749 __func__, epctrl, epctrl_reg);
3750 3750
3751 /* Allocate DMA descriptor chain for non-ctrl endpoints */ 3751 /* Allocate DMA descriptor chain for non-ctrl endpoints */
3752 if (using_desc_dma(hsotg)) { 3752 if (using_desc_dma(hsotg) && !hs_ep->desc_list) {
3753 hs_ep->desc_list = dma_alloc_coherent(hsotg->dev, 3753 hs_ep->desc_list = dmam_alloc_coherent(hsotg->dev,
3754 MAX_DMA_DESC_NUM_GENERIC * 3754 MAX_DMA_DESC_NUM_GENERIC *
3755 sizeof(struct dwc2_dma_desc), 3755 sizeof(struct dwc2_dma_desc),
3756 &hs_ep->desc_list_dma, GFP_KERNEL); 3756 &hs_ep->desc_list_dma, GFP_ATOMIC);
3757 if (!hs_ep->desc_list) { 3757 if (!hs_ep->desc_list) {
3758 ret = -ENOMEM; 3758 ret = -ENOMEM;
3759 goto error2; 3759 goto error2;
@@ -3872,7 +3872,7 @@ error1:
3872 3872
3873error2: 3873error2:
3874 if (ret && using_desc_dma(hsotg) && hs_ep->desc_list) { 3874 if (ret && using_desc_dma(hsotg) && hs_ep->desc_list) {
3875 dma_free_coherent(hsotg->dev, MAX_DMA_DESC_NUM_GENERIC * 3875 dmam_free_coherent(hsotg->dev, MAX_DMA_DESC_NUM_GENERIC *
3876 sizeof(struct dwc2_dma_desc), 3876 sizeof(struct dwc2_dma_desc),
3877 hs_ep->desc_list, hs_ep->desc_list_dma); 3877 hs_ep->desc_list, hs_ep->desc_list_dma);
3878 hs_ep->desc_list = NULL; 3878 hs_ep->desc_list = NULL;
@@ -3902,14 +3902,6 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep)
3902 return -EINVAL; 3902 return -EINVAL;
3903 } 3903 }
3904 3904
3905 /* Remove DMA memory allocated for non-control Endpoints */
3906 if (using_desc_dma(hsotg)) {
3907 dma_free_coherent(hsotg->dev, MAX_DMA_DESC_NUM_GENERIC *
3908 sizeof(struct dwc2_dma_desc),
3909 hs_ep->desc_list, hs_ep->desc_list_dma);
3910 hs_ep->desc_list = NULL;
3911 }
3912
3913 epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); 3905 epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
3914 3906
3915 spin_lock_irqsave(&hsotg->lock, flags); 3907 spin_lock_irqsave(&hsotg->lock, flags);
@@ -4131,7 +4123,7 @@ static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg)
4131 /* keep other bits untouched (so e.g. forced modes are not lost) */ 4123 /* keep other bits untouched (so e.g. forced modes are not lost) */
4132 usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 4124 usbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
4133 usbcfg &= ~(GUSBCFG_TOUTCAL_MASK | GUSBCFG_PHYIF16 | GUSBCFG_SRPCAP | 4125 usbcfg &= ~(GUSBCFG_TOUTCAL_MASK | GUSBCFG_PHYIF16 | GUSBCFG_SRPCAP |
4134 GUSBCFG_HNPCAP); 4126 GUSBCFG_HNPCAP | GUSBCFG_USBTRDTIM_MASK);
4135 4127
4136 /* set the PLL on, remove the HNP/SRP and set the PHY */ 4128 /* set the PLL on, remove the HNP/SRP and set the PHY */
4137 trdtim = (hsotg->phyif == GUSBCFG_PHYIF8) ? 9 : 5; 4129 trdtim = (hsotg->phyif == GUSBCFG_PHYIF8) ? 9 : 5;
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 911c3b36ac06..46d0ad5105e4 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4367,6 +4367,9 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
4367 if (!HCD_HW_ACCESSIBLE(hcd)) 4367 if (!HCD_HW_ACCESSIBLE(hcd))
4368 goto unlock; 4368 goto unlock;
4369 4369
4370 if (hsotg->op_state == OTG_STATE_B_PERIPHERAL)
4371 goto unlock;
4372
4370 if (!hsotg->params.hibernation) 4373 if (!hsotg->params.hibernation)
4371 goto skip_power_saving; 4374 goto skip_power_saving;
4372 4375
@@ -4489,8 +4492,8 @@ static void dwc2_dump_urb_info(struct usb_hcd *hcd, struct urb *urb,
4489{ 4492{
4490#ifdef VERBOSE_DEBUG 4493#ifdef VERBOSE_DEBUG
4491 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); 4494 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
4492 char *pipetype; 4495 char *pipetype = NULL;
4493 char *speed; 4496 char *speed = NULL;
4494 4497
4495 dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb); 4498 dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb);
4496 dev_vdbg(hsotg->dev, " Device address: %d\n", 4499 dev_vdbg(hsotg->dev, " Device address: %d\n",
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index a786256535b6..bcd1e19b4076 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -247,8 +247,6 @@ MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
247static void dwc2_get_device_property(struct dwc2_hsotg *hsotg, 247static void dwc2_get_device_property(struct dwc2_hsotg *hsotg,
248 char *property, u8 size, u64 *value) 248 char *property, u8 size, u64 *value)
249{ 249{
250 u8 val8;
251 u16 val16;
252 u32 val32; 250 u32 val32;
253 251
254 switch (size) { 252 switch (size) {
@@ -256,17 +254,7 @@ static void dwc2_get_device_property(struct dwc2_hsotg *hsotg,
256 *value = device_property_read_bool(hsotg->dev, property); 254 *value = device_property_read_bool(hsotg->dev, property);
257 break; 255 break;
258 case 1: 256 case 1:
259 if (device_property_read_u8(hsotg->dev, property, &val8))
260 return;
261
262 *value = val8;
263 break;
264 case 2: 257 case 2:
265 if (device_property_read_u16(hsotg->dev, property, &val16))
266 return;
267
268 *value = val16;
269 break;
270 case 4: 258 case 4:
271 if (device_property_read_u32(hsotg->dev, property, &val32)) 259 if (device_property_read_u32(hsotg->dev, property, &val32))
272 return; 260 return;
@@ -397,16 +385,16 @@ static void dwc2_set_param(struct dwc2_hsotg *hsotg, void *param,
397} 385}
398 386
399/** 387/**
400 * dwc2_set_param_u16() - Set a u16 parameter 388 * dwc2_set_param_u32() - Set a u32 parameter
401 * 389 *
402 * See dwc2_set_param(). 390 * See dwc2_set_param().
403 */ 391 */
404static void dwc2_set_param_u16(struct dwc2_hsotg *hsotg, u16 *param, 392static void dwc2_set_param_u32(struct dwc2_hsotg *hsotg, u32 *param,
405 bool lookup, char *property, u16 legacy, 393 bool lookup, char *property, u16 legacy,
406 u16 def, u16 min, u16 max) 394 u16 def, u16 min, u16 max)
407{ 395{
408 dwc2_set_param(hsotg, param, lookup, property, 396 dwc2_set_param(hsotg, param, lookup, property,
409 legacy, def, min, max, 2); 397 legacy, def, min, max, 4);
410} 398}
411 399
412/** 400/**
@@ -1100,13 +1088,13 @@ static void dwc2_set_gadget_dma(struct dwc2_hsotg *hsotg)
1100 /* Buffer DMA */ 1088 /* Buffer DMA */
1101 dwc2_set_param_bool(hsotg, &p->g_dma, 1089 dwc2_set_param_bool(hsotg, &p->g_dma,
1102 false, "gadget-dma", 1090 false, "gadget-dma",
1103 true, false, 1091 dma_capable, false,
1104 dma_capable); 1092 dma_capable);
1105 1093
1106 /* DMA Descriptor */ 1094 /* DMA Descriptor */
1107 dwc2_set_param_bool(hsotg, &p->g_dma_desc, false, 1095 dwc2_set_param_bool(hsotg, &p->g_dma_desc, false,
1108 "gadget-dma-desc", 1096 "gadget-dma-desc",
1109 p->g_dma, false, 1097 !!hw->dma_desc_enable, false,
1110 !!hw->dma_desc_enable); 1098 !!hw->dma_desc_enable);
1111} 1099}
1112 1100
@@ -1130,8 +1118,14 @@ static void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
1130 1118
1131 dwc2_set_param_bool(hsotg, &p->host_dma, 1119 dwc2_set_param_bool(hsotg, &p->host_dma,
1132 false, "host-dma", 1120 false, "host-dma",
1133 true, false, 1121 dma_capable, false,
1134 dma_capable); 1122 dma_capable);
1123 dwc2_set_param_host_rx_fifo_size(hsotg,
1124 params->host_rx_fifo_size);
1125 dwc2_set_param_host_nperio_tx_fifo_size(hsotg,
1126 params->host_nperio_tx_fifo_size);
1127 dwc2_set_param_host_perio_tx_fifo_size(hsotg,
1128 params->host_perio_tx_fifo_size);
1135 } 1129 }
1136 dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); 1130 dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable);
1137 dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable); 1131 dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable);
@@ -1140,12 +1134,6 @@ static void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
1140 params->host_support_fs_ls_low_power); 1134 params->host_support_fs_ls_low_power);
1141 dwc2_set_param_enable_dynamic_fifo(hsotg, 1135 dwc2_set_param_enable_dynamic_fifo(hsotg,
1142 params->enable_dynamic_fifo); 1136 params->enable_dynamic_fifo);
1143 dwc2_set_param_host_rx_fifo_size(hsotg,
1144 params->host_rx_fifo_size);
1145 dwc2_set_param_host_nperio_tx_fifo_size(hsotg,
1146 params->host_nperio_tx_fifo_size);
1147 dwc2_set_param_host_perio_tx_fifo_size(hsotg,
1148 params->host_perio_tx_fifo_size);
1149 dwc2_set_param_max_transfer_size(hsotg, 1137 dwc2_set_param_max_transfer_size(hsotg,
1150 params->max_transfer_size); 1138 params->max_transfer_size);
1151 dwc2_set_param_max_packet_count(hsotg, 1139 dwc2_set_param_max_packet_count(hsotg,
@@ -1190,12 +1178,12 @@ static void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
1190 * auto-detect if the hardware does not support the 1178 * auto-detect if the hardware does not support the
1191 * default. 1179 * default.
1192 */ 1180 */
1193 dwc2_set_param_u16(hsotg, &p->g_rx_fifo_size, 1181 dwc2_set_param_u32(hsotg, &p->g_rx_fifo_size,
1194 true, "g-rx-fifo-size", 2048, 1182 true, "g-rx-fifo-size", 2048,
1195 hw->rx_fifo_size, 1183 hw->rx_fifo_size,
1196 16, hw->rx_fifo_size); 1184 16, hw->rx_fifo_size);
1197 1185
1198 dwc2_set_param_u16(hsotg, &p->g_np_tx_fifo_size, 1186 dwc2_set_param_u32(hsotg, &p->g_np_tx_fifo_size,
1199 true, "g-np-tx-fifo-size", 1024, 1187 true, "g-np-tx-fifo-size", 1024,
1200 hw->dev_nperio_tx_fifo_size, 1188 hw->dev_nperio_tx_fifo_size,
1201 16, hw->dev_nperio_tx_fifo_size); 1189 16, hw->dev_nperio_tx_fifo_size);
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index de5a8570be04..14b760209680 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -45,9 +45,7 @@
45#define DWC3_XHCI_RESOURCES_NUM 2 45#define DWC3_XHCI_RESOURCES_NUM 2
46 46
47#define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */ 47#define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */
48#define DWC3_EVENT_SIZE 4 /* bytes */ 48#define DWC3_EVENT_BUFFERS_SIZE 4096
49#define DWC3_EVENT_MAX_NUM 64 /* 2 events/endpoint */
50#define DWC3_EVENT_BUFFERS_SIZE (DWC3_EVENT_SIZE * DWC3_EVENT_MAX_NUM)
51#define DWC3_EVENT_TYPE_MASK 0xfe 49#define DWC3_EVENT_TYPE_MASK 0xfe
52 50
53#define DWC3_EVENT_TYPE_DEV 0 51#define DWC3_EVENT_TYPE_DEV 0
@@ -311,9 +309,8 @@
311#define DWC3_DCFG_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */ 309#define DWC3_DCFG_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */
312#define DWC3_DCFG_SUPERSPEED (4 << 0) 310#define DWC3_DCFG_SUPERSPEED (4 << 0)
313#define DWC3_DCFG_HIGHSPEED (0 << 0) 311#define DWC3_DCFG_HIGHSPEED (0 << 0)
314#define DWC3_DCFG_FULLSPEED2 (1 << 0) 312#define DWC3_DCFG_FULLSPEED (1 << 0)
315#define DWC3_DCFG_LOWSPEED (2 << 0) 313#define DWC3_DCFG_LOWSPEED (2 << 0)
316#define DWC3_DCFG_FULLSPEED1 (3 << 0)
317 314
318#define DWC3_DCFG_NUMP_SHIFT 17 315#define DWC3_DCFG_NUMP_SHIFT 17
319#define DWC3_DCFG_NUMP(n) (((n) >> DWC3_DCFG_NUMP_SHIFT) & 0x1f) 316#define DWC3_DCFG_NUMP(n) (((n) >> DWC3_DCFG_NUMP_SHIFT) & 0x1f)
@@ -405,9 +402,8 @@
405#define DWC3_DSTS_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */ 402#define DWC3_DSTS_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */
406#define DWC3_DSTS_SUPERSPEED (4 << 0) 403#define DWC3_DSTS_SUPERSPEED (4 << 0)
407#define DWC3_DSTS_HIGHSPEED (0 << 0) 404#define DWC3_DSTS_HIGHSPEED (0 << 0)
408#define DWC3_DSTS_FULLSPEED2 (1 << 0) 405#define DWC3_DSTS_FULLSPEED (1 << 0)
409#define DWC3_DSTS_LOWSPEED (2 << 0) 406#define DWC3_DSTS_LOWSPEED (2 << 0)
410#define DWC3_DSTS_FULLSPEED1 (3 << 0)
411 407
412/* Device Generic Command Register */ 408/* Device Generic Command Register */
413#define DWC3_DGCMD_SET_LMP 0x01 409#define DWC3_DGCMD_SET_LMP 0x01
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index e27899bb5706..e956306d9b0f 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -138,7 +138,8 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
138 exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk"); 138 exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk");
139 if (IS_ERR(exynos->axius_clk)) { 139 if (IS_ERR(exynos->axius_clk)) {
140 dev_err(dev, "no AXI UpScaler clk specified\n"); 140 dev_err(dev, "no AXI UpScaler clk specified\n");
141 return -ENODEV; 141 ret = -ENODEV;
142 goto axius_clk_err;
142 } 143 }
143 clk_prepare_enable(exynos->axius_clk); 144 clk_prepare_enable(exynos->axius_clk);
144 } else { 145 } else {
@@ -196,6 +197,7 @@ err3:
196 regulator_disable(exynos->vdd33); 197 regulator_disable(exynos->vdd33);
197err2: 198err2:
198 clk_disable_unprepare(exynos->axius_clk); 199 clk_disable_unprepare(exynos->axius_clk);
200axius_clk_err:
199 clk_disable_unprepare(exynos->susp_clk); 201 clk_disable_unprepare(exynos->susp_clk);
200 clk_disable_unprepare(exynos->clk); 202 clk_disable_unprepare(exynos->clk);
201 return ret; 203 return ret;
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 29e80cc9b634..eb1b9cb3f9d1 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/irq.h>
22#include <linux/interrupt.h> 23#include <linux/interrupt.h>
23#include <linux/platform_device.h> 24#include <linux/platform_device.h>
24#include <linux/platform_data/dwc3-omap.h> 25#include <linux/platform_data/dwc3-omap.h>
@@ -510,7 +511,7 @@ static int dwc3_omap_probe(struct platform_device *pdev)
510 511
511 /* check the DMA Status */ 512 /* check the DMA Status */
512 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); 513 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
513 514 irq_set_status_flags(omap->irq, IRQ_NOAUTOEN);
514 ret = devm_request_threaded_irq(dev, omap->irq, dwc3_omap_interrupt, 515 ret = devm_request_threaded_irq(dev, omap->irq, dwc3_omap_interrupt,
515 dwc3_omap_interrupt_thread, IRQF_SHARED, 516 dwc3_omap_interrupt_thread, IRQF_SHARED,
516 "dwc3-omap", omap); 517 "dwc3-omap", omap);
@@ -531,7 +532,7 @@ static int dwc3_omap_probe(struct platform_device *pdev)
531 } 532 }
532 533
533 dwc3_omap_enable_irqs(omap); 534 dwc3_omap_enable_irqs(omap);
534 535 enable_irq(omap->irq);
535 return 0; 536 return 0;
536 537
537err2: 538err2:
@@ -552,6 +553,7 @@ static int dwc3_omap_remove(struct platform_device *pdev)
552 extcon_unregister_notifier(omap->edev, EXTCON_USB, &omap->vbus_nb); 553 extcon_unregister_notifier(omap->edev, EXTCON_USB, &omap->vbus_nb);
553 extcon_unregister_notifier(omap->edev, EXTCON_USB_HOST, &omap->id_nb); 554 extcon_unregister_notifier(omap->edev, EXTCON_USB_HOST, &omap->id_nb);
554 dwc3_omap_disable_irqs(omap); 555 dwc3_omap_disable_irqs(omap);
556 disable_irq(omap->irq);
555 of_platform_depopulate(omap->dev); 557 of_platform_depopulate(omap->dev);
556 pm_runtime_put_sync(&pdev->dev); 558 pm_runtime_put_sync(&pdev->dev);
557 pm_runtime_disable(&pdev->dev); 559 pm_runtime_disable(&pdev->dev);
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 2b73339f286b..cce0a220b6b0 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -38,6 +38,7 @@
38#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa 38#define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa
39#define PCI_DEVICE_ID_INTEL_APL 0x5aaa 39#define PCI_DEVICE_ID_INTEL_APL 0x5aaa
40#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0 40#define PCI_DEVICE_ID_INTEL_KBP 0xa2b0
41#define PCI_DEVICE_ID_INTEL_GLK 0x31aa
41 42
42#define PCI_INTEL_BXT_DSM_UUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511" 43#define PCI_INTEL_BXT_DSM_UUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
43#define PCI_INTEL_BXT_FUNC_PMU_PWR 4 44#define PCI_INTEL_BXT_FUNC_PMU_PWR 4
@@ -73,16 +74,6 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
73{ 74{
74 struct platform_device *dwc3 = dwc->dwc3; 75 struct platform_device *dwc3 = dwc->dwc3;
75 struct pci_dev *pdev = dwc->pci; 76 struct pci_dev *pdev = dwc->pci;
76 int ret;
77
78 struct property_entry sysdev_property[] = {
79 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
80 { },
81 };
82
83 ret = platform_device_add_properties(dwc3, sysdev_property);
84 if (ret)
85 return ret;
86 77
87 if (pdev->vendor == PCI_VENDOR_ID_AMD && 78 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
88 pdev->device == PCI_DEVICE_ID_AMD_NL_USB) { 79 pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
@@ -105,6 +96,7 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
105 PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"), 96 PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"),
106 PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"), 97 PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"),
107 PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), 98 PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"),
99 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
108 { }, 100 { },
109 }; 101 };
110 102
@@ -115,7 +107,8 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
115 int ret; 107 int ret;
116 108
117 struct property_entry properties[] = { 109 struct property_entry properties[] = {
118 PROPERTY_ENTRY_STRING("dr-mode", "peripheral"), 110 PROPERTY_ENTRY_STRING("dr_mode", "peripheral"),
111 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
119 { } 112 { }
120 }; 113 };
121 114
@@ -167,6 +160,7 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
167 PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 160 PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"),
168 PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 161 PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"),
169 PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 162 PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"),
163 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
170 { }, 164 { },
171 }; 165 };
172 166
@@ -274,6 +268,7 @@ static const struct pci_device_id dwc3_pci_id_table[] = {
274 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, 268 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), },
275 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, 269 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), },
276 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), }, 270 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), },
271 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), },
277 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), }, 272 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
278 { } /* Terminating Entry */ 273 { } /* Terminating Entry */
279}; 274};
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 4878d187c7d4..9bb1f8526f3e 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -39,18 +39,13 @@ static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep);
39static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, 39static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
40 struct dwc3_ep *dep, struct dwc3_request *req); 40 struct dwc3_ep *dep, struct dwc3_request *req);
41 41
42static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, 42static void dwc3_ep0_prepare_one_trb(struct dwc3 *dwc, u8 epnum,
43 u32 len, u32 type, bool chain) 43 dma_addr_t buf_dma, u32 len, u32 type, bool chain)
44{ 44{
45 struct dwc3_gadget_ep_cmd_params params;
46 struct dwc3_trb *trb; 45 struct dwc3_trb *trb;
47 struct dwc3_ep *dep; 46 struct dwc3_ep *dep;
48 47
49 int ret;
50
51 dep = dwc->eps[epnum]; 48 dep = dwc->eps[epnum];
52 if (dep->flags & DWC3_EP_BUSY)
53 return 0;
54 49
55 trb = &dwc->ep0_trb[dep->trb_enqueue]; 50 trb = &dwc->ep0_trb[dep->trb_enqueue];
56 51
@@ -71,15 +66,23 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
71 trb->ctrl |= (DWC3_TRB_CTRL_IOC 66 trb->ctrl |= (DWC3_TRB_CTRL_IOC
72 | DWC3_TRB_CTRL_LST); 67 | DWC3_TRB_CTRL_LST);
73 68
74 if (chain) 69 trace_dwc3_prepare_trb(dep, trb);
70}
71
72static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum)
73{
74 struct dwc3_gadget_ep_cmd_params params;
75 struct dwc3_ep *dep;
76 int ret;
77
78 dep = dwc->eps[epnum];
79 if (dep->flags & DWC3_EP_BUSY)
75 return 0; 80 return 0;
76 81
77 memset(&params, 0, sizeof(params)); 82 memset(&params, 0, sizeof(params));
78 params.param0 = upper_32_bits(dwc->ep0_trb_addr); 83 params.param0 = upper_32_bits(dwc->ep0_trb_addr);
79 params.param1 = lower_32_bits(dwc->ep0_trb_addr); 84 params.param1 = lower_32_bits(dwc->ep0_trb_addr);
80 85
81 trace_dwc3_prepare_trb(dep, trb);
82
83 ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_STARTTRANSFER, &params); 86 ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_STARTTRANSFER, &params);
84 if (ret < 0) 87 if (ret < 0)
85 return ret; 88 return ret;
@@ -280,8 +283,9 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
280 283
281 complete(&dwc->ep0_in_setup); 284 complete(&dwc->ep0_in_setup);
282 285
283 ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8, 286 dwc3_ep0_prepare_one_trb(dwc, 0, dwc->ctrl_req_addr, 8,
284 DWC3_TRBCTL_CONTROL_SETUP, false); 287 DWC3_TRBCTL_CONTROL_SETUP, false);
288 ret = dwc3_ep0_start_trans(dwc, 0);
285 WARN_ON(ret < 0); 289 WARN_ON(ret < 0);
286} 290}
287 291
@@ -912,9 +916,9 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
912 916
913 dwc->ep0_next_event = DWC3_EP0_COMPLETE; 917 dwc->ep0_next_event = DWC3_EP0_COMPLETE;
914 918
915 ret = dwc3_ep0_start_trans(dwc, epnum, 919 dwc3_ep0_prepare_one_trb(dwc, epnum, dwc->ctrl_req_addr,
916 dwc->ctrl_req_addr, 0, 920 0, DWC3_TRBCTL_CONTROL_DATA, false);
917 DWC3_TRBCTL_CONTROL_DATA, false); 921 ret = dwc3_ep0_start_trans(dwc, epnum);
918 WARN_ON(ret < 0); 922 WARN_ON(ret < 0);
919 } 923 }
920 } 924 }
@@ -993,9 +997,10 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
993 req->direction = !!dep->number; 997 req->direction = !!dep->number;
994 998
995 if (req->request.length == 0) { 999 if (req->request.length == 0) {
996 ret = dwc3_ep0_start_trans(dwc, dep->number, 1000 dwc3_ep0_prepare_one_trb(dwc, dep->number,
997 dwc->ctrl_req_addr, 0, 1001 dwc->ctrl_req_addr, 0,
998 DWC3_TRBCTL_CONTROL_DATA, false); 1002 DWC3_TRBCTL_CONTROL_DATA, false);
1003 ret = dwc3_ep0_start_trans(dwc, dep->number);
999 } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) 1004 } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket)
1000 && (dep->number == 0)) { 1005 && (dep->number == 0)) {
1001 u32 transfer_size = 0; 1006 u32 transfer_size = 0;
@@ -1011,7 +1016,7 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
1011 if (req->request.length > DWC3_EP0_BOUNCE_SIZE) { 1016 if (req->request.length > DWC3_EP0_BOUNCE_SIZE) {
1012 transfer_size = ALIGN(req->request.length - maxpacket, 1017 transfer_size = ALIGN(req->request.length - maxpacket,
1013 maxpacket); 1018 maxpacket);
1014 ret = dwc3_ep0_start_trans(dwc, dep->number, 1019 dwc3_ep0_prepare_one_trb(dwc, dep->number,
1015 req->request.dma, 1020 req->request.dma,
1016 transfer_size, 1021 transfer_size,
1017 DWC3_TRBCTL_CONTROL_DATA, 1022 DWC3_TRBCTL_CONTROL_DATA,
@@ -1023,18 +1028,20 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
1023 1028
1024 dwc->ep0_bounced = true; 1029 dwc->ep0_bounced = true;
1025 1030
1026 ret = dwc3_ep0_start_trans(dwc, dep->number, 1031 dwc3_ep0_prepare_one_trb(dwc, dep->number,
1027 dwc->ep0_bounce_addr, transfer_size, 1032 dwc->ep0_bounce_addr, transfer_size,
1028 DWC3_TRBCTL_CONTROL_DATA, false); 1033 DWC3_TRBCTL_CONTROL_DATA, false);
1034 ret = dwc3_ep0_start_trans(dwc, dep->number);
1029 } else { 1035 } else {
1030 ret = usb_gadget_map_request_by_dev(dwc->sysdev, 1036 ret = usb_gadget_map_request_by_dev(dwc->sysdev,
1031 &req->request, dep->number); 1037 &req->request, dep->number);
1032 if (ret) 1038 if (ret)
1033 return; 1039 return;
1034 1040
1035 ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma, 1041 dwc3_ep0_prepare_one_trb(dwc, dep->number, req->request.dma,
1036 req->request.length, DWC3_TRBCTL_CONTROL_DATA, 1042 req->request.length, DWC3_TRBCTL_CONTROL_DATA,
1037 false); 1043 false);
1044 ret = dwc3_ep0_start_trans(dwc, dep->number);
1038 } 1045 }
1039 1046
1040 WARN_ON(ret < 0); 1047 WARN_ON(ret < 0);
@@ -1048,8 +1055,9 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
1048 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3 1055 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3
1049 : DWC3_TRBCTL_CONTROL_STATUS2; 1056 : DWC3_TRBCTL_CONTROL_STATUS2;
1050 1057
1051 return dwc3_ep0_start_trans(dwc, dep->number, 1058 dwc3_ep0_prepare_one_trb(dwc, dep->number,
1052 dwc->ctrl_req_addr, 0, type, false); 1059 dwc->ctrl_req_addr, 0, type, false);
1060 return dwc3_ep0_start_trans(dwc, dep->number);
1053} 1061}
1054 1062
1055static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) 1063static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index efddaf5d11d1..204c754cc647 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -180,11 +180,11 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
180 if (req->request.status == -EINPROGRESS) 180 if (req->request.status == -EINPROGRESS)
181 req->request.status = status; 181 req->request.status = status;
182 182
183 if (dwc->ep0_bounced && dep->number == 0) 183 if (dwc->ep0_bounced && dep->number <= 1)
184 dwc->ep0_bounced = false; 184 dwc->ep0_bounced = false;
185 else 185
186 usb_gadget_unmap_request_by_dev(dwc->sysdev, 186 usb_gadget_unmap_request_by_dev(dwc->sysdev,
187 &req->request, req->direction); 187 &req->request, req->direction);
188 188
189 trace_dwc3_gadget_giveback(req); 189 trace_dwc3_gadget_giveback(req);
190 190
@@ -1720,7 +1720,7 @@ static int __dwc3_gadget_start(struct dwc3 *dwc)
1720 reg |= DWC3_DCFG_LOWSPEED; 1720 reg |= DWC3_DCFG_LOWSPEED;
1721 break; 1721 break;
1722 case USB_SPEED_FULL: 1722 case USB_SPEED_FULL:
1723 reg |= DWC3_DCFG_FULLSPEED1; 1723 reg |= DWC3_DCFG_FULLSPEED;
1724 break; 1724 break;
1725 case USB_SPEED_HIGH: 1725 case USB_SPEED_HIGH:
1726 reg |= DWC3_DCFG_HIGHSPEED; 1726 reg |= DWC3_DCFG_HIGHSPEED;
@@ -2232,9 +2232,14 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
2232 2232
2233 dep = dwc->eps[epnum]; 2233 dep = dwc->eps[epnum];
2234 2234
2235 if (!(dep->flags & DWC3_EP_ENABLED) && 2235 if (!(dep->flags & DWC3_EP_ENABLED)) {
2236 !(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) 2236 if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
2237 return; 2237 return;
2238
2239 /* Handle only EPCMDCMPLT when EP disabled */
2240 if (event->endpoint_event != DWC3_DEPEVT_EPCMDCMPLT)
2241 return;
2242 }
2238 2243
2239 if (epnum == 0 || epnum == 1) { 2244 if (epnum == 0 || epnum == 1) {
2240 dwc3_ep0_interrupt(dwc, event); 2245 dwc3_ep0_interrupt(dwc, event);
@@ -2531,8 +2536,7 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
2531 dwc->gadget.ep0->maxpacket = 64; 2536 dwc->gadget.ep0->maxpacket = 64;
2532 dwc->gadget.speed = USB_SPEED_HIGH; 2537 dwc->gadget.speed = USB_SPEED_HIGH;
2533 break; 2538 break;
2534 case DWC3_DSTS_FULLSPEED2: 2539 case DWC3_DSTS_FULLSPEED:
2535 case DWC3_DSTS_FULLSPEED1:
2536 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 2540 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64);
2537 dwc->gadget.ep0->maxpacket = 64; 2541 dwc->gadget.ep0->maxpacket = 64;
2538 dwc->gadget.speed = USB_SPEED_FULL; 2542 dwc->gadget.speed = USB_SPEED_FULL;
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 41ab61f9b6e0..49d685ad0da9 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1694,9 +1694,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1694 value = min(w_length, (u16) 1); 1694 value = min(w_length, (u16) 1);
1695 break; 1695 break;
1696 1696
1697 /* function drivers must handle get/set altsetting; if there's 1697 /* function drivers must handle get/set altsetting */
1698 * no get() method, we know only altsetting zero works.
1699 */
1700 case USB_REQ_SET_INTERFACE: 1698 case USB_REQ_SET_INTERFACE:
1701 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 1699 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
1702 goto unknown; 1700 goto unknown;
@@ -1705,7 +1703,13 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1705 f = cdev->config->interface[intf]; 1703 f = cdev->config->interface[intf];
1706 if (!f) 1704 if (!f)
1707 break; 1705 break;
1708 if (w_value && !f->set_alt) 1706
1707 /*
1708 * If there's no get_alt() method, we know only altsetting zero
1709 * works. There is no need to check if set_alt() is not NULL
1710 * as we check this in usb_add_function().
1711 */
1712 if (w_value && !f->get_alt)
1709 break; 1713 break;
1710 value = f->set_alt(f, w_index, w_value); 1714 value = f->set_alt(f, w_index, w_value);
1711 if (value == USB_GADGET_DELAYED_STATUS) { 1715 if (value == USB_GADGET_DELAYED_STATUS) {
@@ -2143,7 +2147,7 @@ int composite_os_desc_req_prepare(struct usb_composite_dev *cdev,
2143 cdev->os_desc_req->buf = kmalloc(4096, GFP_KERNEL); 2147 cdev->os_desc_req->buf = kmalloc(4096, GFP_KERNEL);
2144 if (!cdev->os_desc_req->buf) { 2148 if (!cdev->os_desc_req->buf) {
2145 ret = -ENOMEM; 2149 ret = -ENOMEM;
2146 kfree(cdev->os_desc_req); 2150 usb_ep_free_request(ep0, cdev->os_desc_req);
2147 goto end; 2151 goto end;
2148 } 2152 }
2149 cdev->os_desc_req->context = cdev; 2153 cdev->os_desc_req->context = cdev;
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index aab3fc1dbb94..5490fc51638e 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -1806,7 +1806,7 @@ static void ffs_func_eps_disable(struct ffs_function *func)
1806 unsigned long flags; 1806 unsigned long flags;
1807 1807
1808 spin_lock_irqsave(&func->ffs->eps_lock, flags); 1808 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1809 do { 1809 while (count--) {
1810 /* pending requests get nuked */ 1810 /* pending requests get nuked */
1811 if (likely(ep->ep)) 1811 if (likely(ep->ep))
1812 usb_ep_disable(ep->ep); 1812 usb_ep_disable(ep->ep);
@@ -1817,7 +1817,7 @@ static void ffs_func_eps_disable(struct ffs_function *func)
1817 __ffs_epfile_read_buffer_free(epfile); 1817 __ffs_epfile_read_buffer_free(epfile);
1818 ++epfile; 1818 ++epfile;
1819 } 1819 }
1820 } while (--count); 1820 }
1821 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 1821 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1822} 1822}
1823 1823
@@ -1831,7 +1831,7 @@ static int ffs_func_eps_enable(struct ffs_function *func)
1831 int ret = 0; 1831 int ret = 0;
1832 1832
1833 spin_lock_irqsave(&func->ffs->eps_lock, flags); 1833 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1834 do { 1834 while(count--) {
1835 struct usb_endpoint_descriptor *ds; 1835 struct usb_endpoint_descriptor *ds;
1836 int desc_idx; 1836 int desc_idx;
1837 1837
@@ -1867,7 +1867,7 @@ static int ffs_func_eps_enable(struct ffs_function *func)
1867 1867
1868 ++ep; 1868 ++ep;
1869 ++epfile; 1869 ++epfile;
1870 } while (--count); 1870 }
1871 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 1871 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1872 1872
1873 return ret; 1873 return ret;
@@ -2091,8 +2091,8 @@ static int __ffs_data_do_entity(enum ffs_entity_type type,
2091 2091
2092 case FFS_STRING: 2092 case FFS_STRING:
2093 /* 2093 /*
2094 * Strings are indexed from 1 (0 is magic ;) reserved 2094 * Strings are indexed from 1 (0 is reserved
2095 * for languages list or some such) 2095 * for languages list)
2096 */ 2096 */
2097 if (*valuep > helper->ffs->strings_count) 2097 if (*valuep > helper->ffs->strings_count)
2098 helper->ffs->strings_count = *valuep; 2098 helper->ffs->strings_count = *valuep;
@@ -2252,7 +2252,7 @@ static int __ffs_data_do_os_desc(enum ffs_os_desc_type type,
2252 2252
2253 if (len < sizeof(*d) || 2253 if (len < sizeof(*d) ||
2254 d->bFirstInterfaceNumber >= ffs->interfaces_count || 2254 d->bFirstInterfaceNumber >= ffs->interfaces_count ||
2255 !d->Reserved1) 2255 d->Reserved1)
2256 return -EINVAL; 2256 return -EINVAL;
2257 for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i) 2257 for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i)
2258 if (d->Reserved2[i]) 2258 if (d->Reserved2[i])
@@ -3448,12 +3448,12 @@ static void ffs_func_unbind(struct usb_configuration *c,
3448 3448
3449 /* cleanup after autoconfig */ 3449 /* cleanup after autoconfig */
3450 spin_lock_irqsave(&func->ffs->eps_lock, flags); 3450 spin_lock_irqsave(&func->ffs->eps_lock, flags);
3451 do { 3451 while (count--) {
3452 if (ep->ep && ep->req) 3452 if (ep->ep && ep->req)
3453 usb_ep_free_request(ep->ep, ep->req); 3453 usb_ep_free_request(ep->ep, ep->req);
3454 ep->req = NULL; 3454 ep->req = NULL;
3455 ++ep; 3455 ++ep;
3456 } while (--count); 3456 }
3457 spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 3457 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
3458 kfree(func->eps); 3458 kfree(func->eps);
3459 func->eps = NULL; 3459 func->eps = NULL;
@@ -3666,6 +3666,7 @@ static void ffs_closed(struct ffs_data *ffs)
3666{ 3666{
3667 struct ffs_dev *ffs_obj; 3667 struct ffs_dev *ffs_obj;
3668 struct f_fs_opts *opts; 3668 struct f_fs_opts *opts;
3669 struct config_item *ci;
3669 3670
3670 ENTER(); 3671 ENTER();
3671 ffs_dev_lock(); 3672 ffs_dev_lock();
@@ -3689,8 +3690,11 @@ static void ffs_closed(struct ffs_data *ffs)
3689 || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount)) 3690 || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount))
3690 goto done; 3691 goto done;
3691 3692
3692 unregister_gadget_item(ffs_obj->opts-> 3693 ci = opts->func_inst.group.cg_item.ci_parent->ci_parent;
3693 func_inst.group.cg_item.ci_parent->ci_parent); 3694 ffs_dev_unlock();
3695
3696 unregister_gadget_item(ci);
3697 return;
3694done: 3698done:
3695 ffs_dev_unlock(); 3699 ffs_dev_unlock();
3696} 3700}
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3151d2a0fe59..5f8139b8e601 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -593,7 +593,7 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
593 } 593 }
594 status = usb_ep_enable(hidg->out_ep); 594 status = usb_ep_enable(hidg->out_ep);
595 if (status < 0) { 595 if (status < 0) {
596 ERROR(cdev, "Enable IN endpoint FAILED!\n"); 596 ERROR(cdev, "Enable OUT endpoint FAILED!\n");
597 goto fail; 597 goto fail;
598 } 598 }
599 hidg->out_ep->driver_data = hidg; 599 hidg->out_ep->driver_data = hidg;
diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index e8f4102d19df..6bde4396927c 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1126,7 +1126,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1126 /* data and/or status stage for control request */ 1126 /* data and/or status stage for control request */
1127 } else if (dev->state == STATE_DEV_SETUP) { 1127 } else if (dev->state == STATE_DEV_SETUP) {
1128 1128
1129 /* IN DATA+STATUS caller makes len <= wLength */ 1129 len = min_t(size_t, len, dev->setup_wLength);
1130 if (dev->setup_in) { 1130 if (dev->setup_in) {
1131 retval = setup_req (dev->gadget->ep0, dev->req, len); 1131 retval = setup_req (dev->gadget->ep0, dev->req, len);
1132 if (retval == 0) { 1132 if (retval == 0) {
@@ -1734,10 +1734,12 @@ static struct usb_gadget_driver gadgetfs_driver = {
1734 * such as configuration notifications. 1734 * such as configuration notifications.
1735 */ 1735 */
1736 1736
1737static int is_valid_config (struct usb_config_descriptor *config) 1737static int is_valid_config(struct usb_config_descriptor *config,
1738 unsigned int total)
1738{ 1739{
1739 return config->bDescriptorType == USB_DT_CONFIG 1740 return config->bDescriptorType == USB_DT_CONFIG
1740 && config->bLength == USB_DT_CONFIG_SIZE 1741 && config->bLength == USB_DT_CONFIG_SIZE
1742 && total >= USB_DT_CONFIG_SIZE
1741 && config->bConfigurationValue != 0 1743 && config->bConfigurationValue != 0
1742 && (config->bmAttributes & USB_CONFIG_ATT_ONE) != 0 1744 && (config->bmAttributes & USB_CONFIG_ATT_ONE) != 0
1743 && (config->bmAttributes & USB_CONFIG_ATT_WAKEUP) == 0; 1745 && (config->bmAttributes & USB_CONFIG_ATT_WAKEUP) == 0;
@@ -1762,7 +1764,8 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1762 } 1764 }
1763 spin_unlock_irq(&dev->lock); 1765 spin_unlock_irq(&dev->lock);
1764 1766
1765 if (len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4)) 1767 if ((len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4)) ||
1768 (len > PAGE_SIZE * 4))
1766 return -EINVAL; 1769 return -EINVAL;
1767 1770
1768 /* we might need to change message format someday */ 1771 /* we might need to change message format someday */
@@ -1786,7 +1789,8 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1786 /* full or low speed config */ 1789 /* full or low speed config */
1787 dev->config = (void *) kbuf; 1790 dev->config = (void *) kbuf;
1788 total = le16_to_cpu(dev->config->wTotalLength); 1791 total = le16_to_cpu(dev->config->wTotalLength);
1789 if (!is_valid_config (dev->config) || total >= length) 1792 if (!is_valid_config(dev->config, total) ||
1793 total > length - USB_DT_DEVICE_SIZE)
1790 goto fail; 1794 goto fail;
1791 kbuf += total; 1795 kbuf += total;
1792 length -= total; 1796 length -= total;
@@ -1795,10 +1799,13 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1795 if (kbuf [1] == USB_DT_CONFIG) { 1799 if (kbuf [1] == USB_DT_CONFIG) {
1796 dev->hs_config = (void *) kbuf; 1800 dev->hs_config = (void *) kbuf;
1797 total = le16_to_cpu(dev->hs_config->wTotalLength); 1801 total = le16_to_cpu(dev->hs_config->wTotalLength);
1798 if (!is_valid_config (dev->hs_config) || total >= length) 1802 if (!is_valid_config(dev->hs_config, total) ||
1803 total > length - USB_DT_DEVICE_SIZE)
1799 goto fail; 1804 goto fail;
1800 kbuf += total; 1805 kbuf += total;
1801 length -= total; 1806 length -= total;
1807 } else {
1808 dev->hs_config = NULL;
1802 } 1809 }
1803 1810
1804 /* could support multiple configs, using another encoding! */ 1811 /* could support multiple configs, using another encoding! */
@@ -1811,7 +1818,6 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1811 || dev->dev->bDescriptorType != USB_DT_DEVICE 1818 || dev->dev->bDescriptorType != USB_DT_DEVICE
1812 || dev->dev->bNumConfigurations != 1) 1819 || dev->dev->bNumConfigurations != 1)
1813 goto fail; 1820 goto fail;
1814 dev->dev->bNumConfigurations = 1;
1815 dev->dev->bcdUSB = cpu_to_le16 (0x0200); 1821 dev->dev->bcdUSB = cpu_to_le16 (0x0200);
1816 1822
1817 /* triggers gadgetfs_bind(); then we can enumerate. */ 1823 /* triggers gadgetfs_bind(); then we can enumerate. */
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
index f3212db9bc37..12c7687216e6 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1978,7 +1978,8 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
1978 dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret); 1978 dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret);
1979 goto err; 1979 goto err;
1980 } 1980 }
1981 ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", ep->index); 1981 sprintf(ep->name, "ep%d", ep->index);
1982 ep->ep.name = ep->name;
1982 1983
1983 ep->ep_regs = udc->regs + USBA_EPT_BASE(i); 1984 ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
1984 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 1985 ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h b/drivers/usb/gadget/udc/atmel_usba_udc.h
index 3e1c9d589dfa..b03b2ebfc53a 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.h
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.h
@@ -280,6 +280,7 @@ struct usba_ep {
280 void __iomem *ep_regs; 280 void __iomem *ep_regs;
281 void __iomem *dma_regs; 281 void __iomem *dma_regs;
282 void __iomem *fifo; 282 void __iomem *fifo;
283 char name[8];
283 struct usb_ep ep; 284 struct usb_ep ep;
284 struct usba_udc *udc; 285 struct usba_udc *udc;
285 286
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 9483489080f6..0402177f93cd 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1317,7 +1317,11 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
1317 if (!ret) 1317 if (!ret)
1318 break; 1318 break;
1319 } 1319 }
1320 if (!ret && !udc->driver) 1320 if (ret)
1321 ret = -ENODEV;
1322 else if (udc->driver)
1323 ret = -EBUSY;
1324 else
1321 goto found; 1325 goto found;
1322 } else { 1326 } else {
1323 list_for_each_entry(udc, &udc_list, list) { 1327 list_for_each_entry(udc, &udc_list, list) {
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index 02b14e91ae6c..c60abe3a68f9 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -330,7 +330,7 @@ static void nuke(struct dummy *dum, struct dummy_ep *ep)
330/* caller must hold lock */ 330/* caller must hold lock */
331static void stop_activity(struct dummy *dum) 331static void stop_activity(struct dummy *dum)
332{ 332{
333 struct dummy_ep *ep; 333 int i;
334 334
335 /* prevent any more requests */ 335 /* prevent any more requests */
336 dum->address = 0; 336 dum->address = 0;
@@ -338,8 +338,8 @@ static void stop_activity(struct dummy *dum)
338 /* The timer is left running so that outstanding URBs can fail */ 338 /* The timer is left running so that outstanding URBs can fail */
339 339
340 /* nuke any pending requests first, so driver i/o is quiesced */ 340 /* nuke any pending requests first, so driver i/o is quiesced */
341 list_for_each_entry(ep, &dum->gadget.ep_list, ep.ep_list) 341 for (i = 0; i < DUMMY_ENDPOINTS; ++i)
342 nuke(dum, ep); 342 nuke(dum, &dum->ep[i]);
343 343
344 /* driver now does any non-usb quiescing necessary */ 344 /* driver now does any non-usb quiescing necessary */
345} 345}
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index be9e63836881..414e3c376dbb 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -43,7 +43,6 @@ struct at91_usbh_data {
43 struct gpio_desc *overcurrent_pin[AT91_MAX_USBH_PORTS]; 43 struct gpio_desc *overcurrent_pin[AT91_MAX_USBH_PORTS];
44 u8 ports; /* number of ports on root hub */ 44 u8 ports; /* number of ports on root hub */
45 u8 overcurrent_supported; 45 u8 overcurrent_supported;
46 u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS];
47 u8 overcurrent_status[AT91_MAX_USBH_PORTS]; 46 u8 overcurrent_status[AT91_MAX_USBH_PORTS];
48 u8 overcurrent_changed[AT91_MAX_USBH_PORTS]; 47 u8 overcurrent_changed[AT91_MAX_USBH_PORTS];
49}; 48};
@@ -266,8 +265,7 @@ static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int
266 if (!valid_port(port)) 265 if (!valid_port(port))
267 return; 266 return;
268 267
269 gpiod_set_value(pdata->vbus_pin[port], 268 gpiod_set_value(pdata->vbus_pin[port], enable);
270 pdata->vbus_pin_active_low[port] ^ enable);
271} 269}
272 270
273static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) 271static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
@@ -275,8 +273,7 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
275 if (!valid_port(port)) 273 if (!valid_port(port))
276 return -EINVAL; 274 return -EINVAL;
277 275
278 return gpiod_get_value(pdata->vbus_pin[port]) ^ 276 return gpiod_get_value(pdata->vbus_pin[port]);
279 pdata->vbus_pin_active_low[port];
280} 277}
281 278
282/* 279/*
@@ -533,18 +530,17 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
533 pdata->ports = ports; 530 pdata->ports = ports;
534 531
535 at91_for_each_port(i) { 532 at91_for_each_port(i) {
536 pdata->vbus_pin[i] = devm_gpiod_get_optional(&pdev->dev, 533 if (i >= pdata->ports)
537 "atmel,vbus-gpio", 534 break;
538 GPIOD_IN); 535
536 pdata->vbus_pin[i] =
537 devm_gpiod_get_index_optional(&pdev->dev, "atmel,vbus",
538 i, GPIOD_OUT_HIGH);
539 if (IS_ERR(pdata->vbus_pin[i])) { 539 if (IS_ERR(pdata->vbus_pin[i])) {
540 err = PTR_ERR(pdata->vbus_pin[i]); 540 err = PTR_ERR(pdata->vbus_pin[i]);
541 dev_err(&pdev->dev, "unable to claim gpio \"vbus\": %d\n", err); 541 dev_err(&pdev->dev, "unable to claim gpio \"vbus\": %d\n", err);
542 continue; 542 continue;
543 } 543 }
544
545 pdata->vbus_pin_active_low[i] = gpiod_get_value(pdata->vbus_pin[i]);
546
547 ohci_at91_usb_set_power(pdata, i, 1);
548 } 544 }
549 545
550 at91_for_each_port(i) { 546 at91_for_each_port(i) {
@@ -552,8 +548,8 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
552 break; 548 break;
553 549
554 pdata->overcurrent_pin[i] = 550 pdata->overcurrent_pin[i] =
555 devm_gpiod_get_optional(&pdev->dev, 551 devm_gpiod_get_index_optional(&pdev->dev, "atmel,oc",
556 "atmel,oc-gpio", GPIOD_IN); 552 i, GPIOD_IN);
557 if (IS_ERR(pdata->overcurrent_pin[i])) { 553 if (IS_ERR(pdata->overcurrent_pin[i])) {
558 err = PTR_ERR(pdata->overcurrent_pin[i]); 554 err = PTR_ERR(pdata->overcurrent_pin[i]);
559 dev_err(&pdev->dev, "unable to claim gpio \"overcurrent\": %d\n", err); 555 dev_err(&pdev->dev, "unable to claim gpio \"overcurrent\": %d\n", err);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 321de2e0161b..8414ed2a02de 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -979,6 +979,40 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
979 xhci->devs[slot_id] = NULL; 979 xhci->devs[slot_id] = NULL;
980} 980}
981 981
982/*
983 * Free a virt_device structure.
984 * If the virt_device added a tt_info (a hub) and has children pointing to
985 * that tt_info, then free the child first. Recursive.
986 * We can't rely on udev at this point to find child-parent relationships.
987 */
988void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
989{
990 struct xhci_virt_device *vdev;
991 struct list_head *tt_list_head;
992 struct xhci_tt_bw_info *tt_info, *next;
993 int i;
994
995 vdev = xhci->devs[slot_id];
996 if (!vdev)
997 return;
998
999 tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
1000 list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) {
1001 /* is this a hub device that added a tt_info to the tts list */
1002 if (tt_info->slot_id == slot_id) {
1003 /* are any devices using this tt_info? */
1004 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
1005 vdev = xhci->devs[i];
1006 if (vdev && (vdev->tt_info == tt_info))
1007 xhci_free_virt_devices_depth_first(
1008 xhci, i);
1009 }
1010 }
1011 }
1012 /* we are now at a leaf device */
1013 xhci_free_virt_device(xhci, slot_id);
1014}
1015
982int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, 1016int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
983 struct usb_device *udev, gfp_t flags) 1017 struct usb_device *udev, gfp_t flags)
984{ 1018{
@@ -1795,7 +1829,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1795 int size; 1829 int size;
1796 int i, j, num_ports; 1830 int i, j, num_ports;
1797 1831
1798 del_timer_sync(&xhci->cmd_timer); 1832 cancel_delayed_work_sync(&xhci->cmd_timer);
1799 1833
1800 /* Free the Event Ring Segment Table and the actual Event Ring */ 1834 /* Free the Event Ring Segment Table and the actual Event Ring */
1801 size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); 1835 size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries);
@@ -1828,8 +1862,8 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1828 } 1862 }
1829 } 1863 }
1830 1864
1831 for (i = 1; i < MAX_HC_SLOTS; ++i) 1865 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--)
1832 xhci_free_virt_device(xhci, i); 1866 xhci_free_virt_devices_depth_first(xhci, i);
1833 1867
1834 dma_pool_destroy(xhci->segment_pool); 1868 dma_pool_destroy(xhci->segment_pool);
1835 xhci->segment_pool = NULL; 1869 xhci->segment_pool = NULL;
@@ -2342,9 +2376,9 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2342 2376
2343 INIT_LIST_HEAD(&xhci->cmd_list); 2377 INIT_LIST_HEAD(&xhci->cmd_list);
2344 2378
2345 /* init command timeout timer */ 2379 /* init command timeout work */
2346 setup_timer(&xhci->cmd_timer, xhci_handle_command_timeout, 2380 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout);
2347 (unsigned long)xhci); 2381 init_completion(&xhci->cmd_ring_stop_completion);
2348 2382
2349 page_size = readl(&xhci->op_regs->page_size); 2383 page_size = readl(&xhci->op_regs->page_size);
2350 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2384 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 1094ebd2838f..bac961cd24ad 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -579,8 +579,10 @@ static int xhci_mtk_probe(struct platform_device *pdev)
579 goto disable_ldos; 579 goto disable_ldos;
580 580
581 irq = platform_get_irq(pdev, 0); 581 irq = platform_get_irq(pdev, 0);
582 if (irq < 0) 582 if (irq < 0) {
583 ret = irq;
583 goto disable_clk; 584 goto disable_clk;
585 }
584 586
585 /* Initialize dma_mask and coherent_dma_mask to 32-bits */ 587 /* Initialize dma_mask and coherent_dma_mask to 32-bits */
586 ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); 588 ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index e96ae80d107e..954abfd5014d 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -165,7 +165,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
165 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI || 165 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
166 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI || 166 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
167 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI || 167 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI ||
168 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI)) { 168 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI ||
169 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI)) {
169 xhci->quirks |= XHCI_PME_STUCK_QUIRK; 170 xhci->quirks |= XHCI_PME_STUCK_QUIRK;
170 } 171 }
171 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 172 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ddfab301e366..e5834dd9bcde 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -165,7 +165,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
165 return -ENODEV; 165 return -ENODEV;
166 166
167 /* Try to set 64-bit DMA first */ 167 /* Try to set 64-bit DMA first */
168 if (WARN_ON(!pdev->dev.dma_mask)) 168 if (!pdev->dev.dma_mask)
169 /* Platform did not initialize dma_mask */ 169 /* Platform did not initialize dma_mask */
170 ret = dma_coerce_mask_and_coherent(&pdev->dev, 170 ret = dma_coerce_mask_and_coherent(&pdev->dev,
171 DMA_BIT_MASK(64)); 171 DMA_BIT_MASK(64));
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index bdf6b13d9b67..e32029a31ca4 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -279,23 +279,76 @@ void xhci_ring_cmd_db(struct xhci_hcd *xhci)
279 readl(&xhci->dba->doorbell[0]); 279 readl(&xhci->dba->doorbell[0]);
280} 280}
281 281
282static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) 282static bool xhci_mod_cmd_timer(struct xhci_hcd *xhci, unsigned long delay)
283{
284 return mod_delayed_work(system_wq, &xhci->cmd_timer, delay);
285}
286
287static struct xhci_command *xhci_next_queued_cmd(struct xhci_hcd *xhci)
288{
289 return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command,
290 cmd_list);
291}
292
293/*
294 * Turn all commands on command ring with status set to "aborted" to no-op trbs.
295 * If there are other commands waiting then restart the ring and kick the timer.
296 * This must be called with command ring stopped and xhci->lock held.
297 */
298static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci,
299 struct xhci_command *cur_cmd)
300{
301 struct xhci_command *i_cmd;
302 u32 cycle_state;
303
304 /* Turn all aborted commands in list to no-ops, then restart */
305 list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) {
306
307 if (i_cmd->status != COMP_CMD_ABORT)
308 continue;
309
310 i_cmd->status = COMP_CMD_STOP;
311
312 xhci_dbg(xhci, "Turn aborted command %p to no-op\n",
313 i_cmd->command_trb);
314 /* get cycle state from the original cmd trb */
315 cycle_state = le32_to_cpu(
316 i_cmd->command_trb->generic.field[3]) & TRB_CYCLE;
317 /* modify the command trb to no-op command */
318 i_cmd->command_trb->generic.field[0] = 0;
319 i_cmd->command_trb->generic.field[1] = 0;
320 i_cmd->command_trb->generic.field[2] = 0;
321 i_cmd->command_trb->generic.field[3] = cpu_to_le32(
322 TRB_TYPE(TRB_CMD_NOOP) | cycle_state);
323
324 /*
325 * caller waiting for completion is called when command
326 * completion event is received for these no-op commands
327 */
328 }
329
330 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
331
332 /* ring command ring doorbell to restart the command ring */
333 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) &&
334 !(xhci->xhc_state & XHCI_STATE_DYING)) {
335 xhci->current_cmd = cur_cmd;
336 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT);
337 xhci_ring_cmd_db(xhci);
338 }
339}
340
341/* Must be called with xhci->lock held, releases and aquires lock back */
342static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags)
283{ 343{
284 u64 temp_64; 344 u64 temp_64;
285 int ret; 345 int ret;
286 346
287 xhci_dbg(xhci, "Abort command ring\n"); 347 xhci_dbg(xhci, "Abort command ring\n");
288 348
289 temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); 349 reinit_completion(&xhci->cmd_ring_stop_completion);
290 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED;
291 350
292 /* 351 temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
293 * Writing the CMD_RING_ABORT bit should cause a cmd completion event,
294 * however on some host hw the CMD_RING_RUNNING bit is correctly cleared
295 * but the completion event in never sent. Use the cmd timeout timer to
296 * handle those cases. Use twice the time to cover the bit polling retry
297 */
298 mod_timer(&xhci->cmd_timer, jiffies + (2 * XHCI_CMD_DEFAULT_TIMEOUT));
299 xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, 352 xhci_write_64(xhci, temp_64 | CMD_RING_ABORT,
300 &xhci->op_regs->cmd_ring); 353 &xhci->op_regs->cmd_ring);
301 354
@@ -315,17 +368,30 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci)
315 udelay(1000); 368 udelay(1000);
316 ret = xhci_handshake(&xhci->op_regs->cmd_ring, 369 ret = xhci_handshake(&xhci->op_regs->cmd_ring,
317 CMD_RING_RUNNING, 0, 3 * 1000 * 1000); 370 CMD_RING_RUNNING, 0, 3 * 1000 * 1000);
318 if (ret == 0) 371 if (ret < 0) {
319 return 0; 372 xhci_err(xhci, "Stopped the command ring failed, "
320 373 "maybe the host is dead\n");
321 xhci_err(xhci, "Stopped the command ring failed, " 374 xhci->xhc_state |= XHCI_STATE_DYING;
322 "maybe the host is dead\n"); 375 xhci_halt(xhci);
323 del_timer(&xhci->cmd_timer); 376 return -ESHUTDOWN;
324 xhci->xhc_state |= XHCI_STATE_DYING; 377 }
325 xhci_halt(xhci); 378 }
326 return -ESHUTDOWN; 379 /*
380 * Writing the CMD_RING_ABORT bit should cause a cmd completion event,
381 * however on some host hw the CMD_RING_RUNNING bit is correctly cleared
382 * but the completion event in never sent. Wait 2 secs (arbitrary
383 * number) to handle those cases after negation of CMD_RING_RUNNING.
384 */
385 spin_unlock_irqrestore(&xhci->lock, flags);
386 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion,
387 msecs_to_jiffies(2000));
388 spin_lock_irqsave(&xhci->lock, flags);
389 if (!ret) {
390 xhci_dbg(xhci, "No stop event for abort, ring start fail?\n");
391 xhci_cleanup_command_queue(xhci);
392 } else {
393 xhci_handle_stopped_cmd_ring(xhci, xhci_next_queued_cmd(xhci));
327 } 394 }
328
329 return 0; 395 return 0;
330} 396}
331 397
@@ -847,17 +913,6 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
847 spin_lock_irqsave(&xhci->lock, flags); 913 spin_lock_irqsave(&xhci->lock, flags);
848 914
849 ep->stop_cmds_pending--; 915 ep->stop_cmds_pending--;
850 if (xhci->xhc_state & XHCI_STATE_REMOVING) {
851 spin_unlock_irqrestore(&xhci->lock, flags);
852 return;
853 }
854 if (xhci->xhc_state & XHCI_STATE_DYING) {
855 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
856 "Stop EP timer ran, but another timer marked "
857 "xHCI as DYING, exiting.");
858 spin_unlock_irqrestore(&xhci->lock, flags);
859 return;
860 }
861 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) { 916 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) {
862 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, 917 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
863 "Stop EP timer ran, but no command pending, " 918 "Stop EP timer ran, but no command pending, "
@@ -1207,101 +1262,62 @@ void xhci_cleanup_command_queue(struct xhci_hcd *xhci)
1207 xhci_complete_del_and_free_cmd(cur_cmd, COMP_CMD_ABORT); 1262 xhci_complete_del_and_free_cmd(cur_cmd, COMP_CMD_ABORT);
1208} 1263}
1209 1264
1210/* 1265void xhci_handle_command_timeout(struct work_struct *work)
1211 * Turn all commands on command ring with status set to "aborted" to no-op trbs.
1212 * If there are other commands waiting then restart the ring and kick the timer.
1213 * This must be called with command ring stopped and xhci->lock held.
1214 */
1215static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci,
1216 struct xhci_command *cur_cmd)
1217{
1218 struct xhci_command *i_cmd, *tmp_cmd;
1219 u32 cycle_state;
1220
1221 /* Turn all aborted commands in list to no-ops, then restart */
1222 list_for_each_entry_safe(i_cmd, tmp_cmd, &xhci->cmd_list,
1223 cmd_list) {
1224
1225 if (i_cmd->status != COMP_CMD_ABORT)
1226 continue;
1227
1228 i_cmd->status = COMP_CMD_STOP;
1229
1230 xhci_dbg(xhci, "Turn aborted command %p to no-op\n",
1231 i_cmd->command_trb);
1232 /* get cycle state from the original cmd trb */
1233 cycle_state = le32_to_cpu(
1234 i_cmd->command_trb->generic.field[3]) & TRB_CYCLE;
1235 /* modify the command trb to no-op command */
1236 i_cmd->command_trb->generic.field[0] = 0;
1237 i_cmd->command_trb->generic.field[1] = 0;
1238 i_cmd->command_trb->generic.field[2] = 0;
1239 i_cmd->command_trb->generic.field[3] = cpu_to_le32(
1240 TRB_TYPE(TRB_CMD_NOOP) | cycle_state);
1241
1242 /*
1243 * caller waiting for completion is called when command
1244 * completion event is received for these no-op commands
1245 */
1246 }
1247
1248 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
1249
1250 /* ring command ring doorbell to restart the command ring */
1251 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) &&
1252 !(xhci->xhc_state & XHCI_STATE_DYING)) {
1253 xhci->current_cmd = cur_cmd;
1254 mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT);
1255 xhci_ring_cmd_db(xhci);
1256 }
1257 return;
1258}
1259
1260
1261void xhci_handle_command_timeout(unsigned long data)
1262{ 1266{
1263 struct xhci_hcd *xhci; 1267 struct xhci_hcd *xhci;
1264 int ret; 1268 int ret;
1265 unsigned long flags; 1269 unsigned long flags;
1266 u64 hw_ring_state; 1270 u64 hw_ring_state;
1267 bool second_timeout = false;
1268 xhci = (struct xhci_hcd *) data;
1269 1271
1270 /* mark this command to be cancelled */ 1272 xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer);
1273
1271 spin_lock_irqsave(&xhci->lock, flags); 1274 spin_lock_irqsave(&xhci->lock, flags);
1272 if (xhci->current_cmd) { 1275
1273 if (xhci->current_cmd->status == COMP_CMD_ABORT) 1276 /*
1274 second_timeout = true; 1277 * If timeout work is pending, or current_cmd is NULL, it means we
1275 xhci->current_cmd->status = COMP_CMD_ABORT; 1278 * raced with command completion. Command is handled so just return.
1279 */
1280 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) {
1281 spin_unlock_irqrestore(&xhci->lock, flags);
1282 return;
1276 } 1283 }
1284 /* mark this command to be cancelled */
1285 xhci->current_cmd->status = COMP_CMD_ABORT;
1277 1286
1278 /* Make sure command ring is running before aborting it */ 1287 /* Make sure command ring is running before aborting it */
1279 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); 1288 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
1280 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && 1289 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) &&
1281 (hw_ring_state & CMD_RING_RUNNING)) { 1290 (hw_ring_state & CMD_RING_RUNNING)) {
1282 spin_unlock_irqrestore(&xhci->lock, flags); 1291 /* Prevent new doorbell, and start command abort */
1292 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED;
1283 xhci_dbg(xhci, "Command timeout\n"); 1293 xhci_dbg(xhci, "Command timeout\n");
1284 ret = xhci_abort_cmd_ring(xhci); 1294 ret = xhci_abort_cmd_ring(xhci, flags);
1285 if (unlikely(ret == -ESHUTDOWN)) { 1295 if (unlikely(ret == -ESHUTDOWN)) {
1286 xhci_err(xhci, "Abort command ring failed\n"); 1296 xhci_err(xhci, "Abort command ring failed\n");
1287 xhci_cleanup_command_queue(xhci); 1297 xhci_cleanup_command_queue(xhci);
1298 spin_unlock_irqrestore(&xhci->lock, flags);
1288 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); 1299 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
1289 xhci_dbg(xhci, "xHCI host controller is dead.\n"); 1300 xhci_dbg(xhci, "xHCI host controller is dead.\n");
1301
1302 return;
1290 } 1303 }
1291 return; 1304
1305 goto time_out_completed;
1292 } 1306 }
1293 1307
1294 /* command ring failed to restart, or host removed. Bail out */ 1308 /* host removed. Bail out */
1295 if (second_timeout || xhci->xhc_state & XHCI_STATE_REMOVING) { 1309 if (xhci->xhc_state & XHCI_STATE_REMOVING) {
1296 spin_unlock_irqrestore(&xhci->lock, flags); 1310 xhci_dbg(xhci, "host removed, ring start fail?\n");
1297 xhci_dbg(xhci, "command timed out twice, ring start fail?\n");
1298 xhci_cleanup_command_queue(xhci); 1311 xhci_cleanup_command_queue(xhci);
1299 return; 1312
1313 goto time_out_completed;
1300 } 1314 }
1301 1315
1302 /* command timeout on stopped ring, ring can't be aborted */ 1316 /* command timeout on stopped ring, ring can't be aborted */
1303 xhci_dbg(xhci, "Command timeout on stopped ring\n"); 1317 xhci_dbg(xhci, "Command timeout on stopped ring\n");
1304 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); 1318 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd);
1319
1320time_out_completed:
1305 spin_unlock_irqrestore(&xhci->lock, flags); 1321 spin_unlock_irqrestore(&xhci->lock, flags);
1306 return; 1322 return;
1307} 1323}
@@ -1333,7 +1349,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1333 1349
1334 cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list); 1350 cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list);
1335 1351
1336 del_timer(&xhci->cmd_timer); 1352 cancel_delayed_work(&xhci->cmd_timer);
1337 1353
1338 trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event); 1354 trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event);
1339 1355
@@ -1341,7 +1357,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1341 1357
1342 /* If CMD ring stopped we own the trbs between enqueue and dequeue */ 1358 /* If CMD ring stopped we own the trbs between enqueue and dequeue */
1343 if (cmd_comp_code == COMP_CMD_STOP) { 1359 if (cmd_comp_code == COMP_CMD_STOP) {
1344 xhci_handle_stopped_cmd_ring(xhci, cmd); 1360 complete_all(&xhci->cmd_ring_stop_completion);
1345 return; 1361 return;
1346 } 1362 }
1347 1363
@@ -1359,8 +1375,11 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1359 */ 1375 */
1360 if (cmd_comp_code == COMP_CMD_ABORT) { 1376 if (cmd_comp_code == COMP_CMD_ABORT) {
1361 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; 1377 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED;
1362 if (cmd->status == COMP_CMD_ABORT) 1378 if (cmd->status == COMP_CMD_ABORT) {
1379 if (xhci->current_cmd == cmd)
1380 xhci->current_cmd = NULL;
1363 goto event_handled; 1381 goto event_handled;
1382 }
1364 } 1383 }
1365 1384
1366 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); 1385 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3]));
@@ -1421,7 +1440,9 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1421 if (cmd->cmd_list.next != &xhci->cmd_list) { 1440 if (cmd->cmd_list.next != &xhci->cmd_list) {
1422 xhci->current_cmd = list_entry(cmd->cmd_list.next, 1441 xhci->current_cmd = list_entry(cmd->cmd_list.next,
1423 struct xhci_command, cmd_list); 1442 struct xhci_command, cmd_list);
1424 mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); 1443 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT);
1444 } else if (xhci->current_cmd == cmd) {
1445 xhci->current_cmd = NULL;
1425 } 1446 }
1426 1447
1427event_handled: 1448event_handled:
@@ -1939,8 +1960,9 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1939 struct xhci_ep_ctx *ep_ctx; 1960 struct xhci_ep_ctx *ep_ctx;
1940 u32 trb_comp_code; 1961 u32 trb_comp_code;
1941 u32 remaining, requested; 1962 u32 remaining, requested;
1942 bool on_data_stage; 1963 u32 trb_type;
1943 1964
1965 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(ep_trb->generic.field[3]));
1944 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); 1966 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1945 xdev = xhci->devs[slot_id]; 1967 xdev = xhci->devs[slot_id];
1946 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; 1968 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1;
@@ -1950,14 +1972,11 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1950 requested = td->urb->transfer_buffer_length; 1972 requested = td->urb->transfer_buffer_length;
1951 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); 1973 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
1952 1974
1953 /* not setup (dequeue), or status stage means we are at data stage */
1954 on_data_stage = (ep_trb != ep_ring->dequeue && ep_trb != td->last_trb);
1955
1956 switch (trb_comp_code) { 1975 switch (trb_comp_code) {
1957 case COMP_SUCCESS: 1976 case COMP_SUCCESS:
1958 if (ep_trb != td->last_trb) { 1977 if (trb_type != TRB_STATUS) {
1959 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n", 1978 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n",
1960 on_data_stage ? "data" : "setup"); 1979 (trb_type == TRB_DATA) ? "data" : "setup");
1961 *status = -ESHUTDOWN; 1980 *status = -ESHUTDOWN;
1962 break; 1981 break;
1963 } 1982 }
@@ -1967,15 +1986,25 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1967 *status = 0; 1986 *status = 0;
1968 break; 1987 break;
1969 case COMP_STOP_SHORT: 1988 case COMP_STOP_SHORT:
1970 if (on_data_stage) 1989 if (trb_type == TRB_DATA || trb_type == TRB_NORMAL)
1971 td->urb->actual_length = remaining; 1990 td->urb->actual_length = remaining;
1972 else 1991 else
1973 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); 1992 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n");
1974 goto finish_td; 1993 goto finish_td;
1975 case COMP_STOP: 1994 case COMP_STOP:
1976 if (on_data_stage) 1995 switch (trb_type) {
1996 case TRB_SETUP:
1997 td->urb->actual_length = 0;
1998 goto finish_td;
1999 case TRB_DATA:
2000 case TRB_NORMAL:
1977 td->urb->actual_length = requested - remaining; 2001 td->urb->actual_length = requested - remaining;
1978 goto finish_td; 2002 goto finish_td;
2003 default:
2004 xhci_warn(xhci, "WARN: unexpected TRB Type %d\n",
2005 trb_type);
2006 goto finish_td;
2007 }
1979 case COMP_STOP_INVAL: 2008 case COMP_STOP_INVAL:
1980 goto finish_td; 2009 goto finish_td;
1981 default: 2010 default:
@@ -1987,7 +2016,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1987 /* else fall through */ 2016 /* else fall through */
1988 case COMP_STALL: 2017 case COMP_STALL:
1989 /* Did we transfer part of the data (middle) phase? */ 2018 /* Did we transfer part of the data (middle) phase? */
1990 if (on_data_stage) 2019 if (trb_type == TRB_DATA || trb_type == TRB_NORMAL)
1991 td->urb->actual_length = requested - remaining; 2020 td->urb->actual_length = requested - remaining;
1992 else if (!td->urb_length_set) 2021 else if (!td->urb_length_set)
1993 td->urb->actual_length = 0; 2022 td->urb->actual_length = 0;
@@ -1995,14 +2024,15 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1995 } 2024 }
1996 2025
1997 /* stopped at setup stage, no data transferred */ 2026 /* stopped at setup stage, no data transferred */
1998 if (ep_trb == ep_ring->dequeue) 2027 if (trb_type == TRB_SETUP)
1999 goto finish_td; 2028 goto finish_td;
2000 2029
2001 /* 2030 /*
2002 * if on data stage then update the actual_length of the URB and flag it 2031 * if on data stage then update the actual_length of the URB and flag it
2003 * as set, so it won't be overwritten in the event for the last TRB. 2032 * as set, so it won't be overwritten in the event for the last TRB.
2004 */ 2033 */
2005 if (on_data_stage) { 2034 if (trb_type == TRB_DATA ||
2035 trb_type == TRB_NORMAL) {
2006 td->urb_length_set = true; 2036 td->urb_length_set = true;
2007 td->urb->actual_length = requested - remaining; 2037 td->urb->actual_length = requested - remaining;
2008 xhci_dbg(xhci, "Waiting for status stage event\n"); 2038 xhci_dbg(xhci, "Waiting for status stage event\n");
@@ -3790,9 +3820,9 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd,
3790 3820
3791 /* if there are no other commands queued we start the timeout timer */ 3821 /* if there are no other commands queued we start the timeout timer */
3792 if (xhci->cmd_list.next == &cmd->cmd_list && 3822 if (xhci->cmd_list.next == &cmd->cmd_list &&
3793 !timer_pending(&xhci->cmd_timer)) { 3823 !delayed_work_pending(&xhci->cmd_timer)) {
3794 xhci->current_cmd = cmd; 3824 xhci->current_cmd = cmd;
3795 mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); 3825 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT);
3796 } 3826 }
3797 3827
3798 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, 3828 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3,
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 1cd56417cbec..9a0ec116654a 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1534,19 +1534,6 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1534 xhci_urb_free_priv(urb_priv); 1534 xhci_urb_free_priv(urb_priv);
1535 return ret; 1535 return ret;
1536 } 1536 }
1537 if ((xhci->xhc_state & XHCI_STATE_DYING) ||
1538 (xhci->xhc_state & XHCI_STATE_HALTED)) {
1539 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
1540 "Ep 0x%x: URB %p to be canceled on "
1541 "non-responsive xHCI host.",
1542 urb->ep->desc.bEndpointAddress, urb);
1543 /* Let the stop endpoint command watchdog timer (which set this
1544 * state) finish cleaning up the endpoint TD lists. We must
1545 * have caught it in the middle of dropping a lock and giving
1546 * back an URB.
1547 */
1548 goto done;
1549 }
1550 1537
1551 ep_index = xhci_get_endpoint_index(&urb->ep->desc); 1538 ep_index = xhci_get_endpoint_index(&urb->ep->desc);
1552 ep = &xhci->devs[urb->dev->slot_id]->eps[ep_index]; 1539 ep = &xhci->devs[urb->dev->slot_id]->eps[ep_index];
@@ -3787,8 +3774,10 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
3787 3774
3788 mutex_lock(&xhci->mutex); 3775 mutex_lock(&xhci->mutex);
3789 3776
3790 if (xhci->xhc_state) /* dying, removing or halted */ 3777 if (xhci->xhc_state) { /* dying, removing or halted */
3778 ret = -ESHUTDOWN;
3791 goto out; 3779 goto out;
3780 }
3792 3781
3793 if (!udev->slot_id) { 3782 if (!udev->slot_id) {
3794 xhci_dbg_trace(xhci, trace_xhci_dbg_address, 3783 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 8ccc11a974b8..2d7b6374b58d 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1568,7 +1568,8 @@ struct xhci_hcd {
1568#define CMD_RING_STATE_STOPPED (1 << 2) 1568#define CMD_RING_STATE_STOPPED (1 << 2)
1569 struct list_head cmd_list; 1569 struct list_head cmd_list;
1570 unsigned int cmd_ring_reserved_trbs; 1570 unsigned int cmd_ring_reserved_trbs;
1571 struct timer_list cmd_timer; 1571 struct delayed_work cmd_timer;
1572 struct completion cmd_ring_stop_completion;
1572 struct xhci_command *current_cmd; 1573 struct xhci_command *current_cmd;
1573 struct xhci_ring *event_ring; 1574 struct xhci_ring *event_ring;
1574 struct xhci_erst erst; 1575 struct xhci_erst erst;
@@ -1934,7 +1935,7 @@ void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1934 unsigned int slot_id, unsigned int ep_index, 1935 unsigned int slot_id, unsigned int ep_index,
1935 struct xhci_dequeue_state *deq_state); 1936 struct xhci_dequeue_state *deq_state);
1936void xhci_stop_endpoint_command_watchdog(unsigned long arg); 1937void xhci_stop_endpoint_command_watchdog(unsigned long arg);
1937void xhci_handle_command_timeout(unsigned long data); 1938void xhci_handle_command_timeout(struct work_struct *work);
1938 1939
1939void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, 1940void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1940 unsigned int ep_index, unsigned int stream_id); 1941 unsigned int ep_index, unsigned int stream_id);
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 310238c6b5cd..896798071817 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -469,6 +469,7 @@ static const struct musb_platform_ops bfin_ops = {
469 .init = bfin_musb_init, 469 .init = bfin_musb_init,
470 .exit = bfin_musb_exit, 470 .exit = bfin_musb_exit,
471 471
472 .fifo_offset = bfin_fifo_offset,
472 .readb = bfin_readb, 473 .readb = bfin_readb,
473 .writeb = bfin_writeb, 474 .writeb = bfin_writeb,
474 .readw = bfin_readw, 475 .readw = bfin_readw,
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 9e226468a13e..fca288bbc800 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2050,6 +2050,7 @@ struct musb_pending_work {
2050 struct list_head node; 2050 struct list_head node;
2051}; 2051};
2052 2052
2053#ifdef CONFIG_PM
2053/* 2054/*
2054 * Called from musb_runtime_resume(), musb_resume(), and 2055 * Called from musb_runtime_resume(), musb_resume(), and
2055 * musb_queue_resume_work(). Callers must take musb->lock. 2056 * musb_queue_resume_work(). Callers must take musb->lock.
@@ -2077,6 +2078,7 @@ static int musb_run_resume_work(struct musb *musb)
2077 2078
2078 return error; 2079 return error;
2079} 2080}
2081#endif
2080 2082
2081/* 2083/*
2082 * Called to run work if device is active or else queue the work to happen 2084 * Called to run work if device is active or else queue the work to happen
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index a611e2f67bdc..ade902ea1221 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -216,6 +216,7 @@ struct musb_platform_ops {
216 void (*pre_root_reset_end)(struct musb *musb); 216 void (*pre_root_reset_end)(struct musb *musb);
217 void (*post_root_reset_end)(struct musb *musb); 217 void (*post_root_reset_end)(struct musb *musb);
218 int (*phy_callback)(enum musb_vbus_id_status status); 218 int (*phy_callback)(enum musb_vbus_id_status status);
219 void (*clear_ep_rxintr)(struct musb *musb, int epnum);
219}; 220};
220 221
221/* 222/*
@@ -626,6 +627,12 @@ static inline void musb_platform_post_root_reset_end(struct musb *musb)
626 musb->ops->post_root_reset_end(musb); 627 musb->ops->post_root_reset_end(musb);
627} 628}
628 629
630static inline void musb_platform_clear_ep_rxintr(struct musb *musb, int epnum)
631{
632 if (musb->ops->clear_ep_rxintr)
633 musb->ops->clear_ep_rxintr(musb, epnum);
634}
635
629/* 636/*
630 * gets the "dr_mode" property from DT and converts it into musb_mode 637 * gets the "dr_mode" property from DT and converts it into musb_mode
631 * if the property is not found or not recognized returns MUSB_OTG 638 * if the property is not found or not recognized returns MUSB_OTG
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index 4fef50e5c8c1..dd70c88419d2 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -114,6 +114,7 @@ static int musb_regdump_show(struct seq_file *s, void *unused)
114 unsigned i; 114 unsigned i;
115 115
116 seq_printf(s, "MUSB (M)HDRC Register Dump\n"); 116 seq_printf(s, "MUSB (M)HDRC Register Dump\n");
117 pm_runtime_get_sync(musb->controller);
117 118
118 for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) { 119 for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
119 switch (musb_regmap[i].size) { 120 switch (musb_regmap[i].size) {
@@ -132,6 +133,8 @@ static int musb_regdump_show(struct seq_file *s, void *unused)
132 } 133 }
133 } 134 }
134 135
136 pm_runtime_mark_last_busy(musb->controller);
137 pm_runtime_put_autosuspend(musb->controller);
135 return 0; 138 return 0;
136} 139}
137 140
@@ -145,7 +148,10 @@ static int musb_test_mode_show(struct seq_file *s, void *unused)
145 struct musb *musb = s->private; 148 struct musb *musb = s->private;
146 unsigned test; 149 unsigned test;
147 150
151 pm_runtime_get_sync(musb->controller);
148 test = musb_readb(musb->mregs, MUSB_TESTMODE); 152 test = musb_readb(musb->mregs, MUSB_TESTMODE);
153 pm_runtime_mark_last_busy(musb->controller);
154 pm_runtime_put_autosuspend(musb->controller);
149 155
150 if (test & MUSB_TEST_FORCE_HOST) 156 if (test & MUSB_TEST_FORCE_HOST)
151 seq_printf(s, "force host\n"); 157 seq_printf(s, "force host\n");
@@ -194,11 +200,12 @@ static ssize_t musb_test_mode_write(struct file *file,
194 u8 test; 200 u8 test;
195 char buf[18]; 201 char buf[18];
196 202
203 pm_runtime_get_sync(musb->controller);
197 test = musb_readb(musb->mregs, MUSB_TESTMODE); 204 test = musb_readb(musb->mregs, MUSB_TESTMODE);
198 if (test) { 205 if (test) {
199 dev_err(musb->controller, "Error: test mode is already set. " 206 dev_err(musb->controller, "Error: test mode is already set. "
200 "Please do USB Bus Reset to start a new test.\n"); 207 "Please do USB Bus Reset to start a new test.\n");
201 return count; 208 goto ret;
202 } 209 }
203 210
204 memset(buf, 0x00, sizeof(buf)); 211 memset(buf, 0x00, sizeof(buf));
@@ -234,6 +241,9 @@ static ssize_t musb_test_mode_write(struct file *file,
234 241
235 musb_writeb(musb->mregs, MUSB_TESTMODE, test); 242 musb_writeb(musb->mregs, MUSB_TESTMODE, test);
236 243
244ret:
245 pm_runtime_mark_last_busy(musb->controller);
246 pm_runtime_put_autosuspend(musb->controller);
237 return count; 247 return count;
238} 248}
239 249
@@ -254,8 +264,13 @@ static int musb_softconnect_show(struct seq_file *s, void *unused)
254 switch (musb->xceiv->otg->state) { 264 switch (musb->xceiv->otg->state) {
255 case OTG_STATE_A_HOST: 265 case OTG_STATE_A_HOST:
256 case OTG_STATE_A_WAIT_BCON: 266 case OTG_STATE_A_WAIT_BCON:
267 pm_runtime_get_sync(musb->controller);
268
257 reg = musb_readb(musb->mregs, MUSB_DEVCTL); 269 reg = musb_readb(musb->mregs, MUSB_DEVCTL);
258 connect = reg & MUSB_DEVCTL_SESSION ? 1 : 0; 270 connect = reg & MUSB_DEVCTL_SESSION ? 1 : 0;
271
272 pm_runtime_mark_last_busy(musb->controller);
273 pm_runtime_put_autosuspend(musb->controller);
259 break; 274 break;
260 default: 275 default:
261 connect = -1; 276 connect = -1;
@@ -284,6 +299,7 @@ static ssize_t musb_softconnect_write(struct file *file,
284 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 299 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
285 return -EFAULT; 300 return -EFAULT;
286 301
302 pm_runtime_get_sync(musb->controller);
287 if (!strncmp(buf, "0", 1)) { 303 if (!strncmp(buf, "0", 1)) {
288 switch (musb->xceiv->otg->state) { 304 switch (musb->xceiv->otg->state) {
289 case OTG_STATE_A_HOST: 305 case OTG_STATE_A_HOST:
@@ -314,6 +330,8 @@ static ssize_t musb_softconnect_write(struct file *file,
314 } 330 }
315 } 331 }
316 332
333 pm_runtime_mark_last_busy(musb->controller);
334 pm_runtime_put_autosuspend(musb->controller);
317 return count; 335 return count;
318} 336}
319 337
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index feae1561b9ab..9f125e179acd 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -267,6 +267,17 @@ static void otg_timer(unsigned long _musb)
267 pm_runtime_put_autosuspend(dev); 267 pm_runtime_put_autosuspend(dev);
268} 268}
269 269
270void dsps_musb_clear_ep_rxintr(struct musb *musb, int epnum)
271{
272 u32 epintr;
273 struct dsps_glue *glue = dev_get_drvdata(musb->controller->parent);
274 const struct dsps_musb_wrapper *wrp = glue->wrp;
275
276 /* musb->lock might already been held */
277 epintr = (1 << epnum) << wrp->rxep_shift;
278 musb_writel(musb->ctrl_base, wrp->epintr_status, epintr);
279}
280
270static irqreturn_t dsps_interrupt(int irq, void *hci) 281static irqreturn_t dsps_interrupt(int irq, void *hci)
271{ 282{
272 struct musb *musb = hci; 283 struct musb *musb = hci;
@@ -622,6 +633,7 @@ static struct musb_platform_ops dsps_ops = {
622 633
623 .set_mode = dsps_musb_set_mode, 634 .set_mode = dsps_musb_set_mode,
624 .recover = dsps_musb_recover, 635 .recover = dsps_musb_recover,
636 .clear_ep_rxintr = dsps_musb_clear_ep_rxintr,
625}; 637};
626 638
627static u64 musb_dmamask = DMA_BIT_MASK(32); 639static u64 musb_dmamask = DMA_BIT_MASK(32);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index f6cdbad00dac..ac3a4952abb4 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2374,12 +2374,11 @@ static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh)
2374 int is_in = usb_pipein(urb->pipe); 2374 int is_in = usb_pipein(urb->pipe);
2375 int status = 0; 2375 int status = 0;
2376 u16 csr; 2376 u16 csr;
2377 struct dma_channel *dma = NULL;
2377 2378
2378 musb_ep_select(regs, hw_end); 2379 musb_ep_select(regs, hw_end);
2379 2380
2380 if (is_dma_capable()) { 2381 if (is_dma_capable()) {
2381 struct dma_channel *dma;
2382
2383 dma = is_in ? ep->rx_channel : ep->tx_channel; 2382 dma = is_in ? ep->rx_channel : ep->tx_channel;
2384 if (dma) { 2383 if (dma) {
2385 status = ep->musb->dma_controller->channel_abort(dma); 2384 status = ep->musb->dma_controller->channel_abort(dma);
@@ -2395,10 +2394,9 @@ static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh)
2395 /* giveback saves bulk toggle */ 2394 /* giveback saves bulk toggle */
2396 csr = musb_h_flush_rxfifo(ep, 0); 2395 csr = musb_h_flush_rxfifo(ep, 0);
2397 2396
2398 /* REVISIT we still get an irq; should likely clear the 2397 /* clear the endpoint's irq status here to avoid bogus irqs */
2399 * endpoint's irq status here to avoid bogus irqs. 2398 if (is_dma_capable() && dma)
2400 * clearing that status is platform-specific... 2399 musb_platform_clear_ep_rxintr(musb, ep->epnum);
2401 */
2402 } else if (ep->epnum) { 2400 } else if (ep->epnum) {
2403 musb_h_tx_flush_fifo(ep); 2401 musb_h_tx_flush_fifo(ep);
2404 csr = musb_readw(epio, MUSB_TXCSR); 2402 csr = musb_readw(epio, MUSB_TXCSR);
diff --git a/drivers/usb/musb/musbhsdma.h b/drivers/usb/musb/musbhsdma.h
index f7b13fd25257..a3dcbd55e436 100644
--- a/drivers/usb/musb/musbhsdma.h
+++ b/drivers/usb/musb/musbhsdma.h
@@ -157,5 +157,5 @@ struct musb_dma_controller {
157 void __iomem *base; 157 void __iomem *base;
158 u8 channel_count; 158 u8 channel_count;
159 u8 used_channels; 159 u8 used_channels;
160 u8 irq; 160 int irq;
161}; 161};
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 2597b83a8ae2..95aa5233726c 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -95,6 +95,7 @@ struct ch341_private {
95 unsigned baud_rate; /* set baud rate */ 95 unsigned baud_rate; /* set baud rate */
96 u8 line_control; /* set line control value RTS/DTR */ 96 u8 line_control; /* set line control value RTS/DTR */
97 u8 line_status; /* active status of modem control inputs */ 97 u8 line_status; /* active status of modem control inputs */
98 u8 lcr;
98}; 99};
99 100
100static void ch341_set_termios(struct tty_struct *tty, 101static void ch341_set_termios(struct tty_struct *tty,
@@ -112,6 +113,8 @@ static int ch341_control_out(struct usb_device *dev, u8 request,
112 r = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request, 113 r = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
113 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, 114 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
114 value, index, NULL, 0, DEFAULT_TIMEOUT); 115 value, index, NULL, 0, DEFAULT_TIMEOUT);
116 if (r < 0)
117 dev_err(&dev->dev, "failed to send control message: %d\n", r);
115 118
116 return r; 119 return r;
117} 120}
@@ -129,11 +132,24 @@ static int ch341_control_in(struct usb_device *dev,
129 r = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request, 132 r = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
130 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 133 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
131 value, index, buf, bufsize, DEFAULT_TIMEOUT); 134 value, index, buf, bufsize, DEFAULT_TIMEOUT);
132 return r; 135 if (r < bufsize) {
136 if (r >= 0) {
137 dev_err(&dev->dev,
138 "short control message received (%d < %u)\n",
139 r, bufsize);
140 r = -EIO;
141 }
142
143 dev_err(&dev->dev, "failed to receive control message: %d\n",
144 r);
145 return r;
146 }
147
148 return 0;
133} 149}
134 150
135static int ch341_init_set_baudrate(struct usb_device *dev, 151static int ch341_set_baudrate_lcr(struct usb_device *dev,
136 struct ch341_private *priv, unsigned ctrl) 152 struct ch341_private *priv, u8 lcr)
137{ 153{
138 short a; 154 short a;
139 int r; 155 int r;
@@ -156,9 +172,19 @@ static int ch341_init_set_baudrate(struct usb_device *dev,
156 factor = 0x10000 - factor; 172 factor = 0x10000 - factor;
157 a = (factor & 0xff00) | divisor; 173 a = (factor & 0xff00) | divisor;
158 174
159 /* 0x9c is "enable SFR_UART Control register and timer" */ 175 /*
160 r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 176 * CH341A buffers data until a full endpoint-size packet (32 bytes)
161 0x9c | (ctrl << 8), a | 0x80); 177 * has been received unless bit 7 is set.
178 */
179 a |= BIT(7);
180
181 r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x1312, a);
182 if (r)
183 return r;
184
185 r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, lcr);
186 if (r)
187 return r;
162 188
163 return r; 189 return r;
164} 190}
@@ -170,9 +196,9 @@ static int ch341_set_handshake(struct usb_device *dev, u8 control)
170 196
171static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv) 197static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv)
172{ 198{
199 const unsigned int size = 2;
173 char *buffer; 200 char *buffer;
174 int r; 201 int r;
175 const unsigned size = 8;
176 unsigned long flags; 202 unsigned long flags;
177 203
178 buffer = kmalloc(size, GFP_KERNEL); 204 buffer = kmalloc(size, GFP_KERNEL);
@@ -183,14 +209,9 @@ static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv)
183 if (r < 0) 209 if (r < 0)
184 goto out; 210 goto out;
185 211
186 /* setup the private status if available */ 212 spin_lock_irqsave(&priv->lock, flags);
187 if (r == 2) { 213 priv->line_status = (~(*buffer)) & CH341_BITS_MODEM_STAT;
188 r = 0; 214 spin_unlock_irqrestore(&priv->lock, flags);
189 spin_lock_irqsave(&priv->lock, flags);
190 priv->line_status = (~(*buffer)) & CH341_BITS_MODEM_STAT;
191 spin_unlock_irqrestore(&priv->lock, flags);
192 } else
193 r = -EPROTO;
194 215
195out: kfree(buffer); 216out: kfree(buffer);
196 return r; 217 return r;
@@ -200,9 +221,9 @@ out: kfree(buffer);
200 221
201static int ch341_configure(struct usb_device *dev, struct ch341_private *priv) 222static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
202{ 223{
224 const unsigned int size = 2;
203 char *buffer; 225 char *buffer;
204 int r; 226 int r;
205 const unsigned size = 8;
206 227
207 buffer = kmalloc(size, GFP_KERNEL); 228 buffer = kmalloc(size, GFP_KERNEL);
208 if (!buffer) 229 if (!buffer)
@@ -232,7 +253,7 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
232 if (r < 0) 253 if (r < 0)
233 goto out; 254 goto out;
234 255
235 r = ch341_init_set_baudrate(dev, priv, 0); 256 r = ch341_set_baudrate_lcr(dev, priv, priv->lcr);
236 if (r < 0) 257 if (r < 0)
237 goto out; 258 goto out;
238 259
@@ -258,7 +279,6 @@ static int ch341_port_probe(struct usb_serial_port *port)
258 279
259 spin_lock_init(&priv->lock); 280 spin_lock_init(&priv->lock);
260 priv->baud_rate = DEFAULT_BAUD_RATE; 281 priv->baud_rate = DEFAULT_BAUD_RATE;
261 priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;
262 282
263 r = ch341_configure(port->serial->dev, priv); 283 r = ch341_configure(port->serial->dev, priv);
264 if (r < 0) 284 if (r < 0)
@@ -320,7 +340,7 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port)
320 340
321 r = ch341_configure(serial->dev, priv); 341 r = ch341_configure(serial->dev, priv);
322 if (r) 342 if (r)
323 goto out; 343 return r;
324 344
325 if (tty) 345 if (tty)
326 ch341_set_termios(tty, port, NULL); 346 ch341_set_termios(tty, port, NULL);
@@ -330,12 +350,19 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port)
330 if (r) { 350 if (r) {
331 dev_err(&port->dev, "%s - failed to submit interrupt urb: %d\n", 351 dev_err(&port->dev, "%s - failed to submit interrupt urb: %d\n",
332 __func__, r); 352 __func__, r);
333 goto out; 353 return r;
334 } 354 }
335 355
336 r = usb_serial_generic_open(tty, port); 356 r = usb_serial_generic_open(tty, port);
357 if (r)
358 goto err_kill_interrupt_urb;
359
360 return 0;
361
362err_kill_interrupt_urb:
363 usb_kill_urb(port->interrupt_in_urb);
337 364
338out: return r; 365 return r;
339} 366}
340 367
341/* Old_termios contains the original termios settings and 368/* Old_termios contains the original termios settings and
@@ -356,7 +383,6 @@ static void ch341_set_termios(struct tty_struct *tty,
356 383
357 baud_rate = tty_get_baud_rate(tty); 384 baud_rate = tty_get_baud_rate(tty);
358 385
359 priv->baud_rate = baud_rate;
360 ctrl = CH341_LCR_ENABLE_RX | CH341_LCR_ENABLE_TX; 386 ctrl = CH341_LCR_ENABLE_RX | CH341_LCR_ENABLE_TX;
361 387
362 switch (C_CSIZE(tty)) { 388 switch (C_CSIZE(tty)) {
@@ -386,22 +412,25 @@ static void ch341_set_termios(struct tty_struct *tty,
386 ctrl |= CH341_LCR_STOP_BITS_2; 412 ctrl |= CH341_LCR_STOP_BITS_2;
387 413
388 if (baud_rate) { 414 if (baud_rate) {
389 spin_lock_irqsave(&priv->lock, flags); 415 priv->baud_rate = baud_rate;
390 priv->line_control |= (CH341_BIT_DTR | CH341_BIT_RTS); 416
391 spin_unlock_irqrestore(&priv->lock, flags); 417 r = ch341_set_baudrate_lcr(port->serial->dev, priv, ctrl);
392 r = ch341_init_set_baudrate(port->serial->dev, priv, ctrl);
393 if (r < 0 && old_termios) { 418 if (r < 0 && old_termios) {
394 priv->baud_rate = tty_termios_baud_rate(old_termios); 419 priv->baud_rate = tty_termios_baud_rate(old_termios);
395 tty_termios_copy_hw(&tty->termios, old_termios); 420 tty_termios_copy_hw(&tty->termios, old_termios);
421 } else if (r == 0) {
422 priv->lcr = ctrl;
396 } 423 }
397 } else {
398 spin_lock_irqsave(&priv->lock, flags);
399 priv->line_control &= ~(CH341_BIT_DTR | CH341_BIT_RTS);
400 spin_unlock_irqrestore(&priv->lock, flags);
401 } 424 }
402 425
403 ch341_set_handshake(port->serial->dev, priv->line_control); 426 spin_lock_irqsave(&priv->lock, flags);
427 if (C_BAUD(tty) == B0)
428 priv->line_control &= ~(CH341_BIT_DTR | CH341_BIT_RTS);
429 else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
430 priv->line_control |= (CH341_BIT_DTR | CH341_BIT_RTS);
431 spin_unlock_irqrestore(&priv->lock, flags);
404 432
433 ch341_set_handshake(port->serial->dev, priv->line_control);
405} 434}
406 435
407static void ch341_break_ctl(struct tty_struct *tty, int break_state) 436static void ch341_break_ctl(struct tty_struct *tty, int break_state)
@@ -576,14 +605,23 @@ static int ch341_tiocmget(struct tty_struct *tty)
576 605
577static int ch341_reset_resume(struct usb_serial *serial) 606static int ch341_reset_resume(struct usb_serial *serial)
578{ 607{
579 struct ch341_private *priv; 608 struct usb_serial_port *port = serial->port[0];
580 609 struct ch341_private *priv = usb_get_serial_port_data(port);
581 priv = usb_get_serial_port_data(serial->port[0]); 610 int ret;
582 611
583 /* reconfigure ch341 serial port after bus-reset */ 612 /* reconfigure ch341 serial port after bus-reset */
584 ch341_configure(serial->dev, priv); 613 ch341_configure(serial->dev, priv);
585 614
586 return 0; 615 if (tty_port_initialized(&port->port)) {
616 ret = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
617 if (ret) {
618 dev_err(&port->dev, "failed to submit interrupt urb: %d\n",
619 ret);
620 return ret;
621 }
622 }
623
624 return usb_serial_generic_resume(serial);
587} 625}
588 626
589static struct usb_serial_driver ch341_device = { 627static struct usb_serial_driver ch341_device = {
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 5f17a3b9916d..80260b08398b 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -50,6 +50,7 @@
50#define CYBERJACK_PRODUCT_ID 0x0100 50#define CYBERJACK_PRODUCT_ID 0x0100
51 51
52/* Function prototypes */ 52/* Function prototypes */
53static int cyberjack_attach(struct usb_serial *serial);
53static int cyberjack_port_probe(struct usb_serial_port *port); 54static int cyberjack_port_probe(struct usb_serial_port *port);
54static int cyberjack_port_remove(struct usb_serial_port *port); 55static int cyberjack_port_remove(struct usb_serial_port *port);
55static int cyberjack_open(struct tty_struct *tty, 56static int cyberjack_open(struct tty_struct *tty,
@@ -77,6 +78,7 @@ static struct usb_serial_driver cyberjack_device = {
77 .description = "Reiner SCT Cyberjack USB card reader", 78 .description = "Reiner SCT Cyberjack USB card reader",
78 .id_table = id_table, 79 .id_table = id_table,
79 .num_ports = 1, 80 .num_ports = 1,
81 .attach = cyberjack_attach,
80 .port_probe = cyberjack_port_probe, 82 .port_probe = cyberjack_port_probe,
81 .port_remove = cyberjack_port_remove, 83 .port_remove = cyberjack_port_remove,
82 .open = cyberjack_open, 84 .open = cyberjack_open,
@@ -100,6 +102,14 @@ struct cyberjack_private {
100 short wrsent; /* Data already sent */ 102 short wrsent; /* Data already sent */
101}; 103};
102 104
105static int cyberjack_attach(struct usb_serial *serial)
106{
107 if (serial->num_bulk_out < serial->num_ports)
108 return -ENODEV;
109
110 return 0;
111}
112
103static int cyberjack_port_probe(struct usb_serial_port *port) 113static int cyberjack_port_probe(struct usb_serial_port *port)
104{ 114{
105 struct cyberjack_private *priv; 115 struct cyberjack_private *priv;
diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c
index 8282a6a18fee..22f23a429a95 100644
--- a/drivers/usb/serial/f81534.c
+++ b/drivers/usb/serial/f81534.c
@@ -1237,6 +1237,7 @@ static int f81534_attach(struct usb_serial *serial)
1237static int f81534_port_probe(struct usb_serial_port *port) 1237static int f81534_port_probe(struct usb_serial_port *port)
1238{ 1238{
1239 struct f81534_port_private *port_priv; 1239 struct f81534_port_private *port_priv;
1240 int ret;
1240 1241
1241 port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL); 1242 port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL);
1242 if (!port_priv) 1243 if (!port_priv)
@@ -1246,10 +1247,11 @@ static int f81534_port_probe(struct usb_serial_port *port)
1246 mutex_init(&port_priv->mcr_mutex); 1247 mutex_init(&port_priv->mcr_mutex);
1247 1248
1248 /* Assign logic-to-phy mapping */ 1249 /* Assign logic-to-phy mapping */
1249 port_priv->phy_num = f81534_logic_to_phy_port(port->serial, port); 1250 ret = f81534_logic_to_phy_port(port->serial, port);
1250 if (port_priv->phy_num < 0 || port_priv->phy_num >= F81534_NUM_PORT) 1251 if (ret < 0)
1251 return -ENODEV; 1252 return ret;
1252 1253
1254 port_priv->phy_num = ret;
1253 usb_set_serial_port_data(port, port_priv); 1255 usb_set_serial_port_data(port, port_priv);
1254 dev_dbg(&port->dev, "%s: port_number: %d, phy_num: %d\n", __func__, 1256 dev_dbg(&port->dev, "%s: port_number: %d, phy_num: %d\n", __func__,
1255 port->port_number, port_priv->phy_num); 1257 port->port_number, port_priv->phy_num);
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 97cabf803c2f..b2f2e87aed94 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1043,6 +1043,7 @@ static int garmin_write_bulk(struct usb_serial_port *port,
1043 "%s - usb_submit_urb(write bulk) failed with status = %d\n", 1043 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
1044 __func__, status); 1044 __func__, status);
1045 count = status; 1045 count = status;
1046 kfree(buffer);
1046 } 1047 }
1047 1048
1048 /* we are done with this urb, so let the host driver 1049 /* we are done with this urb, so let the host driver
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index dcc0c58aaad5..d50e5773483f 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -2751,6 +2751,11 @@ static int edge_startup(struct usb_serial *serial)
2751 EDGE_COMPATIBILITY_MASK1, 2751 EDGE_COMPATIBILITY_MASK1,
2752 EDGE_COMPATIBILITY_MASK2 }; 2752 EDGE_COMPATIBILITY_MASK2 };
2753 2753
2754 if (serial->num_bulk_in < 1 || serial->num_interrupt_in < 1) {
2755 dev_err(&serial->interface->dev, "missing endpoints\n");
2756 return -ENODEV;
2757 }
2758
2754 dev = serial->dev; 2759 dev = serial->dev;
2755 2760
2756 /* create our private serial structure */ 2761 /* create our private serial structure */
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index c339163698eb..9a0db2965fbb 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -1499,8 +1499,7 @@ static int do_boot_mode(struct edgeport_serial *serial,
1499 1499
1500 dev_dbg(dev, "%s - Download successful -- Device rebooting...\n", __func__); 1500 dev_dbg(dev, "%s - Download successful -- Device rebooting...\n", __func__);
1501 1501
1502 /* return an error on purpose */ 1502 return 1;
1503 return -ENODEV;
1504 } 1503 }
1505 1504
1506stayinbootmode: 1505stayinbootmode:
@@ -1508,7 +1507,7 @@ stayinbootmode:
1508 dev_dbg(dev, "%s - STAYING IN BOOT MODE\n", __func__); 1507 dev_dbg(dev, "%s - STAYING IN BOOT MODE\n", __func__);
1509 serial->product_info.TiMode = TI_MODE_BOOT; 1508 serial->product_info.TiMode = TI_MODE_BOOT;
1510 1509
1511 return 0; 1510 return 1;
1512} 1511}
1513 1512
1514static int ti_do_config(struct edgeport_port *port, int feature, int on) 1513static int ti_do_config(struct edgeport_port *port, int feature, int on)
@@ -2546,6 +2545,13 @@ static int edge_startup(struct usb_serial *serial)
2546 int status; 2545 int status;
2547 u16 product_id; 2546 u16 product_id;
2548 2547
2548 /* Make sure we have the required endpoints when in download mode. */
2549 if (serial->interface->cur_altsetting->desc.bNumEndpoints > 1) {
2550 if (serial->num_bulk_in < serial->num_ports ||
2551 serial->num_bulk_out < serial->num_ports)
2552 return -ENODEV;
2553 }
2554
2549 /* create our private serial structure */ 2555 /* create our private serial structure */
2550 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); 2556 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
2551 if (!edge_serial) 2557 if (!edge_serial)
@@ -2553,14 +2559,18 @@ static int edge_startup(struct usb_serial *serial)
2553 2559
2554 mutex_init(&edge_serial->es_lock); 2560 mutex_init(&edge_serial->es_lock);
2555 edge_serial->serial = serial; 2561 edge_serial->serial = serial;
2562 INIT_DELAYED_WORK(&edge_serial->heartbeat_work, edge_heartbeat_work);
2556 usb_set_serial_data(serial, edge_serial); 2563 usb_set_serial_data(serial, edge_serial);
2557 2564
2558 status = download_fw(edge_serial); 2565 status = download_fw(edge_serial);
2559 if (status) { 2566 if (status < 0) {
2560 kfree(edge_serial); 2567 kfree(edge_serial);
2561 return status; 2568 return status;
2562 } 2569 }
2563 2570
2571 if (status > 0)
2572 return 1; /* bind but do not register any ports */
2573
2564 product_id = le16_to_cpu( 2574 product_id = le16_to_cpu(
2565 edge_serial->serial->dev->descriptor.idProduct); 2575 edge_serial->serial->dev->descriptor.idProduct);
2566 2576
@@ -2572,7 +2582,6 @@ static int edge_startup(struct usb_serial *serial)
2572 } 2582 }
2573 } 2583 }
2574 2584
2575 INIT_DELAYED_WORK(&edge_serial->heartbeat_work, edge_heartbeat_work);
2576 edge_heartbeat_schedule(edge_serial); 2585 edge_heartbeat_schedule(edge_serial);
2577 2586
2578 return 0; 2587 return 0;
@@ -2580,6 +2589,9 @@ static int edge_startup(struct usb_serial *serial)
2580 2589
2581static void edge_disconnect(struct usb_serial *serial) 2590static void edge_disconnect(struct usb_serial *serial)
2582{ 2591{
2592 struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
2593
2594 cancel_delayed_work_sync(&edge_serial->heartbeat_work);
2583} 2595}
2584 2596
2585static void edge_release(struct usb_serial *serial) 2597static void edge_release(struct usb_serial *serial)
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 344b4eea4bd5..d57fb5199218 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -68,6 +68,16 @@ struct iuu_private {
68 u32 clk; 68 u32 clk;
69}; 69};
70 70
71static int iuu_attach(struct usb_serial *serial)
72{
73 unsigned char num_ports = serial->num_ports;
74
75 if (serial->num_bulk_in < num_ports || serial->num_bulk_out < num_ports)
76 return -ENODEV;
77
78 return 0;
79}
80
71static int iuu_port_probe(struct usb_serial_port *port) 81static int iuu_port_probe(struct usb_serial_port *port)
72{ 82{
73 struct iuu_private *priv; 83 struct iuu_private *priv;
@@ -1196,6 +1206,7 @@ static struct usb_serial_driver iuu_device = {
1196 .tiocmset = iuu_tiocmset, 1206 .tiocmset = iuu_tiocmset,
1197 .set_termios = iuu_set_termios, 1207 .set_termios = iuu_set_termios,
1198 .init_termios = iuu_init_termios, 1208 .init_termios = iuu_init_termios,
1209 .attach = iuu_attach,
1199 .port_probe = iuu_port_probe, 1210 .port_probe = iuu_port_probe,
1200 .port_remove = iuu_port_remove, 1211 .port_remove = iuu_port_remove,
1201}; 1212};
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index e49ad0c63ad8..83523fcf6fb9 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -699,6 +699,19 @@ MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw");
699MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw"); 699MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw");
700#endif 700#endif
701 701
702static int keyspan_pda_attach(struct usb_serial *serial)
703{
704 unsigned char num_ports = serial->num_ports;
705
706 if (serial->num_bulk_out < num_ports ||
707 serial->num_interrupt_in < num_ports) {
708 dev_err(&serial->interface->dev, "missing endpoints\n");
709 return -ENODEV;
710 }
711
712 return 0;
713}
714
702static int keyspan_pda_port_probe(struct usb_serial_port *port) 715static int keyspan_pda_port_probe(struct usb_serial_port *port)
703{ 716{
704 717
@@ -776,6 +789,7 @@ static struct usb_serial_driver keyspan_pda_device = {
776 .break_ctl = keyspan_pda_break_ctl, 789 .break_ctl = keyspan_pda_break_ctl,
777 .tiocmget = keyspan_pda_tiocmget, 790 .tiocmget = keyspan_pda_tiocmget,
778 .tiocmset = keyspan_pda_tiocmset, 791 .tiocmset = keyspan_pda_tiocmset,
792 .attach = keyspan_pda_attach,
779 .port_probe = keyspan_pda_port_probe, 793 .port_probe = keyspan_pda_port_probe,
780 .port_remove = keyspan_pda_port_remove, 794 .port_remove = keyspan_pda_port_remove,
781}; 795};
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 0ee190fc1bf8..6cb45757818f 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -192,10 +192,11 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
192 status_buf, KLSI_STATUSBUF_LEN, 192 status_buf, KLSI_STATUSBUF_LEN,
193 10000 193 10000
194 ); 194 );
195 if (rc < 0) 195 if (rc != KLSI_STATUSBUF_LEN) {
196 dev_err(&port->dev, "Reading line status failed (error = %d)\n", 196 dev_err(&port->dev, "reading line status failed: %d\n", rc);
197 rc); 197 if (rc >= 0)
198 else { 198 rc = -EIO;
199 } else {
199 status = get_unaligned_le16(status_buf); 200 status = get_unaligned_le16(status_buf);
200 201
201 dev_info(&port->serial->dev->dev, "read status %x %x\n", 202 dev_info(&port->serial->dev->dev, "read status %x %x\n",
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 2363654cafc9..813035f51fe7 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -51,6 +51,7 @@
51 51
52 52
53/* Function prototypes */ 53/* Function prototypes */
54static int kobil_attach(struct usb_serial *serial);
54static int kobil_port_probe(struct usb_serial_port *probe); 55static int kobil_port_probe(struct usb_serial_port *probe);
55static int kobil_port_remove(struct usb_serial_port *probe); 56static int kobil_port_remove(struct usb_serial_port *probe);
56static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); 57static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port);
@@ -86,6 +87,7 @@ static struct usb_serial_driver kobil_device = {
86 .description = "KOBIL USB smart card terminal", 87 .description = "KOBIL USB smart card terminal",
87 .id_table = id_table, 88 .id_table = id_table,
88 .num_ports = 1, 89 .num_ports = 1,
90 .attach = kobil_attach,
89 .port_probe = kobil_port_probe, 91 .port_probe = kobil_port_probe,
90 .port_remove = kobil_port_remove, 92 .port_remove = kobil_port_remove,
91 .ioctl = kobil_ioctl, 93 .ioctl = kobil_ioctl,
@@ -113,6 +115,16 @@ struct kobil_private {
113}; 115};
114 116
115 117
118static int kobil_attach(struct usb_serial *serial)
119{
120 if (serial->num_interrupt_out < serial->num_ports) {
121 dev_err(&serial->interface->dev, "missing interrupt-out endpoint\n");
122 return -ENODEV;
123 }
124
125 return 0;
126}
127
116static int kobil_port_probe(struct usb_serial_port *port) 128static int kobil_port_probe(struct usb_serial_port *port)
117{ 129{
118 struct usb_serial *serial = port->serial; 130 struct usb_serial *serial = port->serial;
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index d52caa03679c..91bc170b408a 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -65,8 +65,6 @@ struct moschip_port {
65 struct urb *write_urb_pool[NUM_URBS]; 65 struct urb *write_urb_pool[NUM_URBS];
66}; 66};
67 67
68static struct usb_serial_driver moschip7720_2port_driver;
69
70#define USB_VENDOR_ID_MOSCHIP 0x9710 68#define USB_VENDOR_ID_MOSCHIP 0x9710
71#define MOSCHIP_DEVICE_ID_7720 0x7720 69#define MOSCHIP_DEVICE_ID_7720 0x7720
72#define MOSCHIP_DEVICE_ID_7715 0x7715 70#define MOSCHIP_DEVICE_ID_7715 0x7715
@@ -970,25 +968,6 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
970 tty_port_tty_wakeup(&mos7720_port->port->port); 968 tty_port_tty_wakeup(&mos7720_port->port->port);
971} 969}
972 970
973/*
974 * mos77xx_probe
975 * this function installs the appropriate read interrupt endpoint callback
976 * depending on whether the device is a 7720 or 7715, thus avoiding costly
977 * run-time checks in the high-frequency callback routine itself.
978 */
979static int mos77xx_probe(struct usb_serial *serial,
980 const struct usb_device_id *id)
981{
982 if (id->idProduct == MOSCHIP_DEVICE_ID_7715)
983 moschip7720_2port_driver.read_int_callback =
984 mos7715_interrupt_callback;
985 else
986 moschip7720_2port_driver.read_int_callback =
987 mos7720_interrupt_callback;
988
989 return 0;
990}
991
992static int mos77xx_calc_num_ports(struct usb_serial *serial) 971static int mos77xx_calc_num_ports(struct usb_serial *serial)
993{ 972{
994 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 973 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
@@ -1917,6 +1896,11 @@ static int mos7720_startup(struct usb_serial *serial)
1917 u16 product; 1896 u16 product;
1918 int ret_val; 1897 int ret_val;
1919 1898
1899 if (serial->num_bulk_in < 2 || serial->num_bulk_out < 2) {
1900 dev_err(&serial->interface->dev, "missing bulk endpoints\n");
1901 return -ENODEV;
1902 }
1903
1920 product = le16_to_cpu(serial->dev->descriptor.idProduct); 1904 product = le16_to_cpu(serial->dev->descriptor.idProduct);
1921 dev = serial->dev; 1905 dev = serial->dev;
1922 1906
@@ -1941,19 +1925,18 @@ static int mos7720_startup(struct usb_serial *serial)
1941 tmp->interrupt_in_endpointAddress; 1925 tmp->interrupt_in_endpointAddress;
1942 serial->port[1]->interrupt_in_urb = NULL; 1926 serial->port[1]->interrupt_in_urb = NULL;
1943 serial->port[1]->interrupt_in_buffer = NULL; 1927 serial->port[1]->interrupt_in_buffer = NULL;
1928
1929 if (serial->port[0]->interrupt_in_urb) {
1930 struct urb *urb = serial->port[0]->interrupt_in_urb;
1931
1932 urb->complete = mos7715_interrupt_callback;
1933 }
1944 } 1934 }
1945 1935
1946 /* setting configuration feature to one */ 1936 /* setting configuration feature to one */
1947 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1937 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1948 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5000); 1938 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5000);
1949 1939
1950 /* start the interrupt urb */
1951 ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL);
1952 if (ret_val)
1953 dev_err(&dev->dev,
1954 "%s - Error %d submitting control urb\n",
1955 __func__, ret_val);
1956
1957#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT 1940#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
1958 if (product == MOSCHIP_DEVICE_ID_7715) { 1941 if (product == MOSCHIP_DEVICE_ID_7715) {
1959 ret_val = mos7715_parport_init(serial); 1942 ret_val = mos7715_parport_init(serial);
@@ -1961,6 +1944,13 @@ static int mos7720_startup(struct usb_serial *serial)
1961 return ret_val; 1944 return ret_val;
1962 } 1945 }
1963#endif 1946#endif
1947 /* start the interrupt urb */
1948 ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL);
1949 if (ret_val) {
1950 dev_err(&dev->dev, "failed to submit interrupt urb: %d\n",
1951 ret_val);
1952 }
1953
1964 /* LSR For Port 1 */ 1954 /* LSR For Port 1 */
1965 read_mos_reg(serial, 0, MOS7720_LSR, &data); 1955 read_mos_reg(serial, 0, MOS7720_LSR, &data);
1966 dev_dbg(&dev->dev, "LSR:%x\n", data); 1956 dev_dbg(&dev->dev, "LSR:%x\n", data);
@@ -1970,6 +1960,8 @@ static int mos7720_startup(struct usb_serial *serial)
1970 1960
1971static void mos7720_release(struct usb_serial *serial) 1961static void mos7720_release(struct usb_serial *serial)
1972{ 1962{
1963 usb_kill_urb(serial->port[0]->interrupt_in_urb);
1964
1973#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT 1965#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
1974 /* close the parallel port */ 1966 /* close the parallel port */
1975 1967
@@ -2019,11 +2011,6 @@ static int mos7720_port_probe(struct usb_serial_port *port)
2019 if (!mos7720_port) 2011 if (!mos7720_port)
2020 return -ENOMEM; 2012 return -ENOMEM;
2021 2013
2022 /* Initialize all port interrupt end point to port 0 int endpoint.
2023 * Our device has only one interrupt endpoint common to all ports.
2024 */
2025 port->interrupt_in_endpointAddress =
2026 port->serial->port[0]->interrupt_in_endpointAddress;
2027 mos7720_port->port = port; 2014 mos7720_port->port = port;
2028 2015
2029 usb_set_serial_port_data(port, mos7720_port); 2016 usb_set_serial_port_data(port, mos7720_port);
@@ -2053,7 +2040,6 @@ static struct usb_serial_driver moschip7720_2port_driver = {
2053 .close = mos7720_close, 2040 .close = mos7720_close,
2054 .throttle = mos7720_throttle, 2041 .throttle = mos7720_throttle,
2055 .unthrottle = mos7720_unthrottle, 2042 .unthrottle = mos7720_unthrottle,
2056 .probe = mos77xx_probe,
2057 .attach = mos7720_startup, 2043 .attach = mos7720_startup,
2058 .release = mos7720_release, 2044 .release = mos7720_release,
2059 .port_probe = mos7720_port_probe, 2045 .port_probe = mos7720_port_probe,
@@ -2067,7 +2053,7 @@ static struct usb_serial_driver moschip7720_2port_driver = {
2067 .chars_in_buffer = mos7720_chars_in_buffer, 2053 .chars_in_buffer = mos7720_chars_in_buffer,
2068 .break_ctl = mos7720_break, 2054 .break_ctl = mos7720_break,
2069 .read_bulk_callback = mos7720_bulk_in_callback, 2055 .read_bulk_callback = mos7720_bulk_in_callback,
2070 .read_int_callback = NULL /* dynamically assigned in probe() */ 2056 .read_int_callback = mos7720_interrupt_callback,
2071}; 2057};
2072 2058
2073static struct usb_serial_driver * const serial_drivers[] = { 2059static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 9a220b8e810f..ea27fb23967a 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -214,7 +214,6 @@ MODULE_DEVICE_TABLE(usb, id_table);
214 214
215struct moschip_port { 215struct moschip_port {
216 int port_num; /*Actual port number in the device(1,2,etc) */ 216 int port_num; /*Actual port number in the device(1,2,etc) */
217 struct urb *write_urb; /* write URB for this port */
218 struct urb *read_urb; /* read URB for this port */ 217 struct urb *read_urb; /* read URB for this port */
219 __u8 shadowLCR; /* last LCR value received */ 218 __u8 shadowLCR; /* last LCR value received */
220 __u8 shadowMCR; /* last MCR value received */ 219 __u8 shadowMCR; /* last MCR value received */
@@ -1037,9 +1036,7 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
1037 serial, 1036 serial,
1038 serial->port[0]->interrupt_in_urb->interval); 1037 serial->port[0]->interrupt_in_urb->interval);
1039 1038
1040 /* start interrupt read for mos7840 * 1039 /* start interrupt read for mos7840 */
1041 * will continue as long as mos7840 is connected */
1042
1043 response = 1040 response =
1044 usb_submit_urb(serial->port[0]->interrupt_in_urb, 1041 usb_submit_urb(serial->port[0]->interrupt_in_urb,
1045 GFP_KERNEL); 1042 GFP_KERNEL);
@@ -1186,7 +1183,6 @@ static void mos7840_close(struct usb_serial_port *port)
1186 } 1183 }
1187 } 1184 }
1188 1185
1189 usb_kill_urb(mos7840_port->write_urb);
1190 usb_kill_urb(mos7840_port->read_urb); 1186 usb_kill_urb(mos7840_port->read_urb);
1191 mos7840_port->read_urb_busy = false; 1187 mos7840_port->read_urb_busy = false;
1192 1188
@@ -1199,12 +1195,6 @@ static void mos7840_close(struct usb_serial_port *port)
1199 } 1195 }
1200 } 1196 }
1201 1197
1202 if (mos7840_port->write_urb) {
1203 /* if this urb had a transfer buffer already (old tx) free it */
1204 kfree(mos7840_port->write_urb->transfer_buffer);
1205 usb_free_urb(mos7840_port->write_urb);
1206 }
1207
1208 Data = 0x0; 1198 Data = 0x0;
1209 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 1199 mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
1210 1200
@@ -2113,6 +2103,17 @@ static int mos7840_calc_num_ports(struct usb_serial *serial)
2113 return mos7840_num_ports; 2103 return mos7840_num_ports;
2114} 2104}
2115 2105
2106static int mos7840_attach(struct usb_serial *serial)
2107{
2108 if (serial->num_bulk_in < serial->num_ports ||
2109 serial->num_bulk_out < serial->num_ports) {
2110 dev_err(&serial->interface->dev, "missing endpoints\n");
2111 return -ENODEV;
2112 }
2113
2114 return 0;
2115}
2116
2116static int mos7840_port_probe(struct usb_serial_port *port) 2117static int mos7840_port_probe(struct usb_serial_port *port)
2117{ 2118{
2118 struct usb_serial *serial = port->serial; 2119 struct usb_serial *serial = port->serial;
@@ -2388,6 +2389,7 @@ static struct usb_serial_driver moschip7840_4port_device = {
2388 .tiocmset = mos7840_tiocmset, 2389 .tiocmset = mos7840_tiocmset,
2389 .tiocmiwait = usb_serial_generic_tiocmiwait, 2390 .tiocmiwait = usb_serial_generic_tiocmiwait,
2390 .get_icount = usb_serial_generic_get_icount, 2391 .get_icount = usb_serial_generic_get_icount,
2392 .attach = mos7840_attach,
2391 .port_probe = mos7840_port_probe, 2393 .port_probe = mos7840_port_probe,
2392 .port_remove = mos7840_port_remove, 2394 .port_remove = mos7840_port_remove,
2393 .read_bulk_callback = mos7840_bulk_in_callback, 2395 .read_bulk_callback = mos7840_bulk_in_callback,
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index f6c6900bccf0..a180b17d2432 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -38,6 +38,7 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
38 const unsigned char *buf, int count); 38 const unsigned char *buf, int count);
39static int omninet_write_room(struct tty_struct *tty); 39static int omninet_write_room(struct tty_struct *tty);
40static void omninet_disconnect(struct usb_serial *serial); 40static void omninet_disconnect(struct usb_serial *serial);
41static int omninet_attach(struct usb_serial *serial);
41static int omninet_port_probe(struct usb_serial_port *port); 42static int omninet_port_probe(struct usb_serial_port *port);
42static int omninet_port_remove(struct usb_serial_port *port); 43static int omninet_port_remove(struct usb_serial_port *port);
43 44
@@ -56,6 +57,7 @@ static struct usb_serial_driver zyxel_omninet_device = {
56 .description = "ZyXEL - omni.net lcd plus usb", 57 .description = "ZyXEL - omni.net lcd plus usb",
57 .id_table = id_table, 58 .id_table = id_table,
58 .num_ports = 1, 59 .num_ports = 1,
60 .attach = omninet_attach,
59 .port_probe = omninet_port_probe, 61 .port_probe = omninet_port_probe,
60 .port_remove = omninet_port_remove, 62 .port_remove = omninet_port_remove,
61 .open = omninet_open, 63 .open = omninet_open,
@@ -104,6 +106,17 @@ struct omninet_data {
104 __u8 od_outseq; /* Sequence number for bulk_out URBs */ 106 __u8 od_outseq; /* Sequence number for bulk_out URBs */
105}; 107};
106 108
109static int omninet_attach(struct usb_serial *serial)
110{
111 /* The second bulk-out endpoint is used for writing. */
112 if (serial->num_bulk_out < 2) {
113 dev_err(&serial->interface->dev, "missing endpoints\n");
114 return -ENODEV;
115 }
116
117 return 0;
118}
119
107static int omninet_port_probe(struct usb_serial_port *port) 120static int omninet_port_probe(struct usb_serial_port *port)
108{ 121{
109 struct omninet_data *od; 122 struct omninet_data *od;
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index a4b88bc038b6..b8bf52bf7a94 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -134,6 +134,7 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty);
134static int oti6858_tiocmget(struct tty_struct *tty); 134static int oti6858_tiocmget(struct tty_struct *tty);
135static int oti6858_tiocmset(struct tty_struct *tty, 135static int oti6858_tiocmset(struct tty_struct *tty,
136 unsigned int set, unsigned int clear); 136 unsigned int set, unsigned int clear);
137static int oti6858_attach(struct usb_serial *serial);
137static int oti6858_port_probe(struct usb_serial_port *port); 138static int oti6858_port_probe(struct usb_serial_port *port);
138static int oti6858_port_remove(struct usb_serial_port *port); 139static int oti6858_port_remove(struct usb_serial_port *port);
139 140
@@ -158,6 +159,7 @@ static struct usb_serial_driver oti6858_device = {
158 .write_bulk_callback = oti6858_write_bulk_callback, 159 .write_bulk_callback = oti6858_write_bulk_callback,
159 .write_room = oti6858_write_room, 160 .write_room = oti6858_write_room,
160 .chars_in_buffer = oti6858_chars_in_buffer, 161 .chars_in_buffer = oti6858_chars_in_buffer,
162 .attach = oti6858_attach,
161 .port_probe = oti6858_port_probe, 163 .port_probe = oti6858_port_probe,
162 .port_remove = oti6858_port_remove, 164 .port_remove = oti6858_port_remove,
163}; 165};
@@ -324,6 +326,20 @@ static void send_data(struct work_struct *work)
324 usb_serial_port_softint(port); 326 usb_serial_port_softint(port);
325} 327}
326 328
329static int oti6858_attach(struct usb_serial *serial)
330{
331 unsigned char num_ports = serial->num_ports;
332
333 if (serial->num_bulk_in < num_ports ||
334 serial->num_bulk_out < num_ports ||
335 serial->num_interrupt_in < num_ports) {
336 dev_err(&serial->interface->dev, "missing endpoints\n");
337 return -ENODEV;
338 }
339
340 return 0;
341}
342
327static int oti6858_port_probe(struct usb_serial_port *port) 343static int oti6858_port_probe(struct usb_serial_port *port)
328{ 344{
329 struct oti6858_private *priv; 345 struct oti6858_private *priv;
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index ae682e4eeaef..46fca6b75846 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -220,9 +220,17 @@ static int pl2303_probe(struct usb_serial *serial,
220static int pl2303_startup(struct usb_serial *serial) 220static int pl2303_startup(struct usb_serial *serial)
221{ 221{
222 struct pl2303_serial_private *spriv; 222 struct pl2303_serial_private *spriv;
223 unsigned char num_ports = serial->num_ports;
223 enum pl2303_type type = TYPE_01; 224 enum pl2303_type type = TYPE_01;
224 unsigned char *buf; 225 unsigned char *buf;
225 226
227 if (serial->num_bulk_in < num_ports ||
228 serial->num_bulk_out < num_ports ||
229 serial->num_interrupt_in < num_ports) {
230 dev_err(&serial->interface->dev, "missing endpoints\n");
231 return -ENODEV;
232 }
233
226 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 234 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
227 if (!spriv) 235 if (!spriv)
228 return -ENOMEM; 236 return -ENOMEM;
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index 659cb8606bd9..5709cc93b083 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -408,16 +408,12 @@ static void qt2_close(struct usb_serial_port *port)
408{ 408{
409 struct usb_serial *serial; 409 struct usb_serial *serial;
410 struct qt2_port_private *port_priv; 410 struct qt2_port_private *port_priv;
411 unsigned long flags;
412 int i; 411 int i;
413 412
414 serial = port->serial; 413 serial = port->serial;
415 port_priv = usb_get_serial_port_data(port); 414 port_priv = usb_get_serial_port_data(port);
416 415
417 spin_lock_irqsave(&port_priv->urb_lock, flags);
418 usb_kill_urb(port_priv->write_urb); 416 usb_kill_urb(port_priv->write_urb);
419 port_priv->urb_in_use = false;
420 spin_unlock_irqrestore(&port_priv->urb_lock, flags);
421 417
422 /* flush the port transmit buffer */ 418 /* flush the port transmit buffer */
423 i = usb_control_msg(serial->dev, 419 i = usb_control_msg(serial->dev,
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index ef0dbf0703c5..475e6c31b266 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -154,6 +154,19 @@ static int spcp8x5_probe(struct usb_serial *serial,
154 return 0; 154 return 0;
155} 155}
156 156
157static int spcp8x5_attach(struct usb_serial *serial)
158{
159 unsigned char num_ports = serial->num_ports;
160
161 if (serial->num_bulk_in < num_ports ||
162 serial->num_bulk_out < num_ports) {
163 dev_err(&serial->interface->dev, "missing endpoints\n");
164 return -ENODEV;
165 }
166
167 return 0;
168}
169
157static int spcp8x5_port_probe(struct usb_serial_port *port) 170static int spcp8x5_port_probe(struct usb_serial_port *port)
158{ 171{
159 const struct usb_device_id *id = usb_get_serial_data(port->serial); 172 const struct usb_device_id *id = usb_get_serial_data(port->serial);
@@ -477,6 +490,7 @@ static struct usb_serial_driver spcp8x5_device = {
477 .tiocmget = spcp8x5_tiocmget, 490 .tiocmget = spcp8x5_tiocmget,
478 .tiocmset = spcp8x5_tiocmset, 491 .tiocmset = spcp8x5_tiocmset,
479 .probe = spcp8x5_probe, 492 .probe = spcp8x5_probe,
493 .attach = spcp8x5_attach,
480 .port_probe = spcp8x5_port_probe, 494 .port_probe = spcp8x5_port_probe,
481 .port_remove = spcp8x5_port_remove, 495 .port_remove = spcp8x5_port_remove,
482}; 496};
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 8db9d071d940..64b85b8dedf3 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -579,6 +579,13 @@ static int ti_startup(struct usb_serial *serial)
579 goto free_tdev; 579 goto free_tdev;
580 } 580 }
581 581
582 if (serial->num_bulk_in < serial->num_ports ||
583 serial->num_bulk_out < serial->num_ports) {
584 dev_err(&serial->interface->dev, "missing endpoints\n");
585 status = -ENODEV;
586 goto free_tdev;
587 }
588
582 return 0; 589 return 0;
583 590
584free_tdev: 591free_tdev:
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index af3c7eecff91..16cc18369111 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -2109,6 +2109,13 @@ UNUSUAL_DEV( 0x152d, 0x2566, 0x0114, 0x0114,
2109 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 2109 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
2110 US_FL_BROKEN_FUA ), 2110 US_FL_BROKEN_FUA ),
2111 2111
2112/* Reported-by George Cherian <george.cherian@cavium.com> */
2113UNUSUAL_DEV(0x152d, 0x9561, 0x0000, 0x9999,
2114 "JMicron",
2115 "JMS56x",
2116 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
2117 US_FL_NO_REPORT_OPCODES),
2118
2112/* 2119/*
2113 * Entrega Technologies U1-SC25 (later Xircom PortGear PGSCSI) 2120 * Entrega Technologies U1-SC25 (later Xircom PortGear PGSCSI)
2114 * and Mac USB Dock USB-SCSI */ 2121 * and Mac USB Dock USB-SCSI */
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c
index 79451f7ef1b7..062c205f0046 100644
--- a/drivers/usb/wusbcore/crypto.c
+++ b/drivers/usb/wusbcore/crypto.c
@@ -216,7 +216,6 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
216 struct scatterlist sg[4], sg_dst; 216 struct scatterlist sg[4], sg_dst;
217 void *dst_buf; 217 void *dst_buf;
218 size_t dst_size; 218 size_t dst_size;
219 const u8 bzero[16] = { 0 };
220 u8 iv[crypto_skcipher_ivsize(tfm_cbc)]; 219 u8 iv[crypto_skcipher_ivsize(tfm_cbc)];
221 size_t zero_padding; 220 size_t zero_padding;
222 221
@@ -261,7 +260,7 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
261 sg_set_buf(&sg[1], &scratch->b1, sizeof(scratch->b1)); 260 sg_set_buf(&sg[1], &scratch->b1, sizeof(scratch->b1));
262 sg_set_buf(&sg[2], b, blen); 261 sg_set_buf(&sg[2], b, blen);
263 /* 0 if well behaved :) */ 262 /* 0 if well behaved :) */
264 sg_set_buf(&sg[3], bzero, zero_padding); 263 sg_set_page(&sg[3], ZERO_PAGE(0), zero_padding, 0);
265 sg_init_one(&sg_dst, dst_buf, dst_size); 264 sg_init_one(&sg_dst, dst_buf, dst_size);
266 265
267 skcipher_request_set_tfm(req, tfm_cbc); 266 skcipher_request_set_tfm(req, tfm_cbc);