Pull USB fixes from Greg KH: "Here are a number of USB fixes for 4.14-rc4 to resolved reported issues. There's a bunch of stuff in here based on the great work Andrey Konovalov is doing in fuzzing the USB stack. Lots of bug fixes when dealing with corrupted USB descriptors that we've never seen in "normal" operation, but is now ensuring the stack is much more hardened overall. There's also the usual XHCI and gadget driver fixes as well, and a build error fix, and a few other minor things, full details in the shortlog. All of these have been in linux-next with no reported issues" * tag 'usb-4.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (38 commits) usb: dwc3: of-simple: Add compatible for Spreadtrum SC9860 platform usb: gadget: udc: atmel: set vbus irqflags explicitly usb: gadget: ffs: handle I/O completion in-order usb: renesas_usbhs: fix usbhsf_fifo_clear() for RX direction usb: renesas_usbhs: fix the BCLR setting condition for non-DCP pipe usb: gadget: udc: renesas_usb3: Fix return value of usb3_write_pipe() usb: gadget: udc: renesas_usb3: fix Pn_RAMMAP.Pn_MPKT value usb: gadget: udc: renesas_usb3: fix for no-data control transfer USB: dummy-hcd: Fix erroneous synchronization change USB: dummy-hcd: fix infinite-loop resubmission bug USB: dummy-hcd: fix connection failures (wrong speed) USB: cdc-wdm: ignore -EPIPE from GetEncapsulatedResponse USB: devio: Don't corrupt user memory USB: devio: Prevent integer overflow in proc_do_submiturb() USB: g_mass_storage: Fix deadlock when driver is unbound USB: gadgetfs: Fix crash caused by inadequate synchronization USB: gadgetfs: fix copy_to_user while holding spinlock USB: uas: fix bug in handling of alternate settings usb-storage: unusual_devs entry to fix write-access regression for Seagate external drives usb-storage: fix bogus hardware error messages for ATA pass-thru devices ...
Unified · Split
| @@ -190,8 +190,10 @@ static void wdm_in_callback(struct urb *urb) · 189 unmodified lines | |||
| 190 | /* | 190 | /* |
| 191 | * only set a new error if there is no previous error. | 191 | * only set a new error if there is no previous error. |
| 192 | * Errors are only cleared during read/open | 192 | * Errors are only cleared during read/open |
| 193 | * Avoid propagating -EPIPE (stall) to userspace since it is | ||
| 194 | * better handled as an empty read | ||
| 193 | */ | 195 | */ |
| 194 | if (desc->rerr == 0) | 196 | if (desc->rerr == 0 && status != -EPIPE) |
| 195 | desc->rerr = status; | 197 | desc->rerr = status; |
| 196 | 198 | ||
| 197 | if (length + desc->length > desc->wMaxCommand) { | 199 | if (length + desc->length > desc->wMaxCommand) { |
| @@ -643,15 +643,23 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 642 unmodified lines | |||
| 643 | 643 | ||
| 644 | } else if (header->bDescriptorType == | 644 | } else if (header->bDescriptorType == |
| 645 | USB_DT_INTERFACE_ASSOCIATION) { | 645 | USB_DT_INTERFACE_ASSOCIATION) { |
| 646 | struct usb_interface_assoc_descriptor *d; | ||
| 647 | |||
| 648 | d = (struct usb_interface_assoc_descriptor *)header; | ||
| 649 | if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) { | ||
| 650 | dev_warn(ddev, | ||
| 651 | "config %d has an invalid interface association descriptor of length %d, skipping\n", | ||
| 652 | cfgno, d->bLength); | ||
| 653 | continue; | ||
| 654 | } | ||
| 655 | |||
| 646 | if (iad_num == USB_MAXIADS) { | 656 | if (iad_num == USB_MAXIADS) { |
| 647 | dev_warn(ddev, "found more Interface " | 657 | dev_warn(ddev, "found more Interface " |
| 648 | "Association Descriptors " | 658 | "Association Descriptors " |
| 649 | "than allocated for in " | 659 | "than allocated for in " |
| 650 | "configuration %d\n", cfgno); | 660 | "configuration %d\n", cfgno); |
| 651 | } else { | 661 | } else { |
| 652 | config->intf_assoc[iad_num] = | 662 | config->intf_assoc[iad_num] = d; |
| 653 | (struct usb_interface_assoc_descriptor | ||
| 654 | *)header; | ||
| 655 | iad_num++; | 663 | iad_num++; |
| 656 | } | 664 | } |
| 657 | 665 | ||
| @@ -852,7 +860,7 @@ int usb_get_configuration(struct usb_device *dev) · 194 unmodified lines | |||
| 852 | } | 860 | } |
| 853 | 861 | ||
| 854 | if (dev->quirks & USB_QUIRK_DELAY_INIT) | 862 | if (dev->quirks & USB_QUIRK_DELAY_INIT) |
| 855 | msleep(100); | 863 | msleep(200); |
| 856 | 864 | ||
| 857 | result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, | 865 | result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, |
| 858 | bigbuffer, length); | 866 | bigbuffer, length); |
| @@ -140,6 +140,9 @@ module_param(usbfs_memory_mb, uint, 0644); · 139 unmodified lines | |||
| 140 | MODULE_PARM_DESC(usbfs_memory_mb, | 140 | MODULE_PARM_DESC(usbfs_memory_mb, |
| 141 | "maximum MB allowed for usbfs buffers (0 = no limit)"); | 141 | "maximum MB allowed for usbfs buffers (0 = no limit)"); |
| 142 | 142 | ||
| 143 | /* Hard limit, necessary to avoid arithmetic overflow */ | ||
| 144 | #define USBFS_XFER_MAX (UINT_MAX / 2 - 1000000) | ||
| 145 | |||
| 143 | static atomic64_t usbfs_memory_usage; /* Total memory currently allocated */ | 146 | static atomic64_t usbfs_memory_usage; /* Total memory currently allocated */ |
| 144 | 147 | ||
| 145 | /* Check whether it's okay to allocate more memory for a transfer */ | 148 | /* Check whether it's okay to allocate more memory for a transfer */ |
| @@ -1460,6 +1463,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb · 1314 unmodified lines | |||
| 1460 | USBDEVFS_URB_ZERO_PACKET | | 1463 | USBDEVFS_URB_ZERO_PACKET | |
| 1461 | USBDEVFS_URB_NO_INTERRUPT)) | 1464 | USBDEVFS_URB_NO_INTERRUPT)) |
| 1462 | return -EINVAL; | 1465 | return -EINVAL; |
| 1466 | if ((unsigned int)uurb->buffer_length >= USBFS_XFER_MAX) | ||
| 1467 | return -EINVAL; | ||
| 1463 | if (uurb->buffer_length > 0 && !uurb->buffer) | 1468 | if (uurb->buffer_length > 0 && !uurb->buffer) |
| 1464 | return -EINVAL; | 1469 | return -EINVAL; |
| 1465 | if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && | 1470 | if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL && |
| @@ -1571,7 +1576,11 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb · 105 unmodified lines | |||
| 1571 | totlen += isopkt[u].length; | 1576 | totlen += isopkt[u].length; |
| 1572 | } | 1577 | } |
| 1573 | u *= sizeof(struct usb_iso_packet_descriptor); | 1578 | u *= sizeof(struct usb_iso_packet_descriptor); |
| 1574 | uurb->buffer_length = totlen; | 1579 | if (totlen <= uurb->buffer_length) |
| 1580 | uurb->buffer_length = totlen; | ||
| 1581 | else | ||
| 1582 | WARN_ONCE(1, "uurb->buffer_length is too short %d vs %d", | ||
| 1583 | totlen, uurb->buffer_length); | ||
| 1575 | break; | 1584 | break; |
| 1576 | 1585 | ||
| 1577 | default: | 1586 | default: |
| @@ -4838,7 +4838,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, · 4837 unmodified lines | |||
| 4838 | goto loop; | 4838 | goto loop; |
| 4839 | 4839 | ||
| 4840 | if (udev->quirks & USB_QUIRK_DELAY_INIT) | 4840 | if (udev->quirks & USB_QUIRK_DELAY_INIT) |
| 4841 | msleep(1000); | 4841 | msleep(2000); |
| 4842 | 4842 | ||
| 4843 | /* consecutive bus-powered hubs aren't reliable; they can | 4843 | /* consecutive bus-powered hubs aren't reliable; they can |
| 4844 | * violate the voltage drop budget. if the new child has | 4844 | * violate the voltage drop budget. if the new child has |
| @@ -2069,6 +2069,10 @@ int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr, · 2068 unmodified lines | |||
| 2069 | elength = 1; | 2069 | elength = 1; |
| 2070 | goto next_desc; | 2070 | goto next_desc; |
| 2071 | } | 2071 | } |
| 2072 | if ((buflen < elength) || (elength < 3)) { | ||
| 2073 | dev_err(&intf->dev, "invalid descriptor buffer length\n"); | ||
| 2074 | break; | ||
| 2075 | } | ||
| 2072 | if (buffer[1] != USB_DT_CS_INTERFACE) { | 2076 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
| 2073 | dev_err(&intf->dev, "skipping garbage\n"); | 2077 | dev_err(&intf->dev, "skipping garbage\n"); |
| 2074 | goto next_desc; | 2078 | goto next_desc; |
| @@ -177,6 +177,7 @@ static const struct of_device_id of_dwc3_simple_match[] = { · 176 unmodified lines | |||
| 177 | { .compatible = "rockchip,rk3399-dwc3" }, | 177 | { .compatible = "rockchip,rk3399-dwc3" }, |
| 178 | { .compatible = "xlnx,zynqmp-dwc3" }, | 178 | { .compatible = "xlnx,zynqmp-dwc3" }, |
| 179 | { .compatible = "cavium,octeon-7130-usb-uctl" }, | 179 | { .compatible = "cavium,octeon-7130-usb-uctl" }, |
| 180 | { .compatible = "sprd,sc9860-dwc3" }, | ||
| 180 | { /* Sentinel */ } | 181 | { /* Sentinel */ } |
| 181 | }; | 182 | }; |
| 182 | MODULE_DEVICE_TABLE(of, of_dwc3_simple_match); | 183 | MODULE_DEVICE_TABLE(of, of_dwc3_simple_match); |
| @@ -990,6 +990,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, · 989 unmodified lines | |||
| 990 | DWC3_TRBCTL_CONTROL_DATA, | 990 | DWC3_TRBCTL_CONTROL_DATA, |
| 991 | true); | 991 | true); |
| 992 | 992 | ||
| 993 | req->trb = &dwc->ep0_trb[dep->trb_enqueue - 1]; | ||
| 994 | |||
| 993 | /* Now prepare one extra TRB to align transfer size */ | 995 | /* Now prepare one extra TRB to align transfer size */ |
| 994 | dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, | 996 | dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, |
| 995 | maxpacket - rem, | 997 | maxpacket - rem, |
| @@ -1015,6 +1017,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, · 19 unmodified lines | |||
| 1015 | DWC3_TRBCTL_CONTROL_DATA, | 1017 | DWC3_TRBCTL_CONTROL_DATA, |
| 1016 | true); | 1018 | true); |
| 1017 | 1019 | ||
| 1020 | req->trb = &dwc->ep0_trb[dep->trb_enqueue - 1]; | ||
| 1021 | |||
| 1018 | /* Now prepare one extra TRB to align transfer size */ | 1022 | /* Now prepare one extra TRB to align transfer size */ |
| 1019 | dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, | 1023 | dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, |
| 1020 | 0, DWC3_TRBCTL_CONTROL_DATA, | 1024 | 0, DWC3_TRBCTL_CONTROL_DATA, |
| @@ -1029,6 +1033,9 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, · 8 unmodified lines | |||
| 1029 | dwc3_ep0_prepare_one_trb(dep, req->request.dma, | 1033 | dwc3_ep0_prepare_one_trb(dep, req->request.dma, |
| 1030 | req->request.length, DWC3_TRBCTL_CONTROL_DATA, | 1034 | req->request.length, DWC3_TRBCTL_CONTROL_DATA, |
| 1031 | false); | 1035 | false); |
| 1036 | |||
| 1037 | req->trb = &dwc->ep0_trb[dep->trb_enqueue]; | ||
| 1038 | |||
| 1032 | ret = dwc3_ep0_start_trans(dep); | 1039 | ret = dwc3_ep0_start_trans(dep); |
| 1033 | } | 1040 | } |
| 1034 | 1041 | ||
| @@ -46,7 +46,8 @@ · 45 unmodified lines | |||
| 46 | static void ffs_data_get(struct ffs_data *ffs); | 46 | static void ffs_data_get(struct ffs_data *ffs); |
| 47 | static void ffs_data_put(struct ffs_data *ffs); | 47 | static void ffs_data_put(struct ffs_data *ffs); |
| 48 | /* Creates new ffs_data object. */ | 48 | /* Creates new ffs_data object. */ |
| 49 | static struct ffs_data *__must_check ffs_data_new(void) __attribute__((malloc)); | 49 | static struct ffs_data *__must_check ffs_data_new(const char *dev_name) |
| 50 | __attribute__((malloc)); | ||
| 50 | 51 | ||
| 51 | /* Opened counter handling. */ | 52 | /* Opened counter handling. */ |
| 52 | static void ffs_data_opened(struct ffs_data *ffs); | 53 | static void ffs_data_opened(struct ffs_data *ffs); |
| @@ -780,11 +781,12 @@ static void ffs_epfile_async_io_complete(struct usb_ep *_ep, · 727 unmodified lines | |||
| 780 | struct usb_request *req) | 781 | struct usb_request *req) |
| 781 | { | 782 | { |
| 782 | struct ffs_io_data *io_data = req->context; | 783 | struct ffs_io_data *io_data = req->context; |
| 784 | struct ffs_data *ffs = io_data->ffs; | ||
| 783 | 785 | ||
| 784 | ENTER(); | 786 | ENTER(); |
| 785 | 787 | ||
| 786 | INIT_WORK(&io_data->work, ffs_user_copy_worker); | 788 | INIT_WORK(&io_data->work, ffs_user_copy_worker); |
| 787 | schedule_work(&io_data->work); | 789 | queue_work(ffs->io_completion_wq, &io_data->work); |
| 788 | } | 790 | } |
| 789 | 791 | ||
| 790 | static void __ffs_epfile_read_buffer_free(struct ffs_epfile *epfile) | 792 | static void __ffs_epfile_read_buffer_free(struct ffs_epfile *epfile) |
| @@ -1500,7 +1502,7 @@ ffs_fs_mount(struct file_system_type *t, int flags, · 709 unmodified lines | |||
| 1500 | if (unlikely(ret < 0)) | 1502 | if (unlikely(ret < 0)) |
| 1501 | return ERR_PTR(ret); | 1503 | return ERR_PTR(ret); |
| 1502 | 1504 | ||
| 1503 | ffs = ffs_data_new(); | 1505 | ffs = ffs_data_new(dev_name); |
| 1504 | if (unlikely(!ffs)) | 1506 | if (unlikely(!ffs)) |
| 1505 | return ERR_PTR(-ENOMEM); | 1507 | return ERR_PTR(-ENOMEM); |
| 1506 | ffs->file_perms = data.perms; | 1508 | ffs->file_perms = data.perms; |
| @@ -1610,6 +1612,7 @@ static void ffs_data_put(struct ffs_data *ffs) · 103 unmodified lines | |||
| 1610 | BUG_ON(waitqueue_active(&ffs->ev.waitq) || | 1612 | BUG_ON(waitqueue_active(&ffs->ev.waitq) || |
| 1611 | waitqueue_active(&ffs->ep0req_completion.wait) || | 1613 | waitqueue_active(&ffs->ep0req_completion.wait) || |
| 1612 | waitqueue_active(&ffs->wait)); | 1614 | waitqueue_active(&ffs->wait)); |
| 1615 | destroy_workqueue(ffs->io_completion_wq); | ||
| 1613 | kfree(ffs->dev_name); | 1616 | kfree(ffs->dev_name); |
| 1614 | kfree(ffs); | 1617 | kfree(ffs); |
| 1615 | } | 1618 | } |
| @@ -1642,7 +1645,7 @@ static void ffs_data_closed(struct ffs_data *ffs) · 26 unmodified lines | |||
| 1642 | ffs_data_put(ffs); | 1645 | ffs_data_put(ffs); |
| 1643 | } | 1646 | } |
| 1644 | 1647 | ||
| 1645 | static struct ffs_data *ffs_data_new(void) | 1648 | static struct ffs_data *ffs_data_new(const char *dev_name) |
| 1646 | { | 1649 | { |
| 1647 | struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); | 1650 | struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); |
| 1648 | if (unlikely(!ffs)) | 1651 | if (unlikely(!ffs)) |
| @@ -1650,6 +1653,12 @@ static struct ffs_data *ffs_data_new(void) · 1 unmodified line | |||
| 1650 | 1653 | ||
| 1651 | ENTER(); | 1654 | ENTER(); |
| 1652 | 1655 | ||
| 1656 | ffs->io_completion_wq = alloc_ordered_workqueue("%s", 0, dev_name); | ||
| 1657 | if (!ffs->io_completion_wq) { | ||
| 1658 | kfree(ffs); | ||
| 1659 | return NULL; | ||
| 1660 | } | ||
| 1661 | |||
| 1653 | refcount_set(&ffs->ref, 1); | 1662 | refcount_set(&ffs->ref, 1); |
| 1654 | atomic_set(&ffs->opened, 0); | 1663 | atomic_set(&ffs->opened, 0); |
| 1655 | ffs->state = FFS_READ_DESCRIPTORS; | 1664 | ffs->state = FFS_READ_DESCRIPTORS; |
| @@ -307,8 +307,6 @@ struct fsg_common { · 306 unmodified lines | |||
| 307 | struct completion thread_notifier; | 307 | struct completion thread_notifier; |
| 308 | struct task_struct *thread_task; | 308 | struct task_struct *thread_task; |
| 309 | 309 | ||
| 310 | /* Callback functions. */ | ||
| 311 | const struct fsg_operations *ops; | ||
| 312 | /* Gadget's private data. */ | 310 | /* Gadget's private data. */ |
| 313 | void *private_data; | 311 | void *private_data; |
| 314 | 312 | ||
| @@ -2438,6 +2436,7 @@ static void handle_exception(struct fsg_common *common) · 2123 unmodified lines | |||
| 2438 | static int fsg_main_thread(void *common_) | 2436 | static int fsg_main_thread(void *common_) |
| 2439 | { | 2437 | { |
| 2440 | struct fsg_common *common = common_; | 2438 | struct fsg_common *common = common_; |
| 2439 | int i; | ||
| 2441 | 2440 | ||
| 2442 | /* | 2441 | /* |
| 2443 | * Allow the thread to be killed by a signal, but set the signal mask | 2442 | * Allow the thread to be killed by a signal, but set the signal mask |
| @@ -2476,21 +2475,16 @@ static int fsg_main_thread(void *common_) · 32 unmodified lines | |||
| 2476 | common->thread_task = NULL; | 2475 | common->thread_task = NULL; |
| 2477 | spin_unlock_irq(&common->lock); | 2476 | spin_unlock_irq(&common->lock); |
| 2478 | 2477 | ||
| 2479 | if (!common->ops || !common->ops->thread_exits | 2478 | /* Eject media from all LUNs */ |
| 2480 | || common->ops->thread_exits(common) < 0) { | ||
| 2481 | int i; | ||
| 2482 | 2479 | ||
| 2483 | down_write(&common->filesem); | 2480 | down_write(&common->filesem); |
| 2484 | for (i = 0; i < ARRAY_SIZE(common->luns); i++) { | 2481 | for (i = 0; i < ARRAY_SIZE(common->luns); i++) { |
| 2485 | struct fsg_lun *curlun = common->luns[i]; | 2482 | struct fsg_lun *curlun = common->luns[i]; |
| 2486 | if (!curlun || !fsg_lun_is_open(curlun)) | ||
| 2487 | continue; | ||
| 2488 | 2483 | ||
| 2484 | if (curlun && fsg_lun_is_open(curlun)) | ||
| 2489 | fsg_lun_close(curlun); | 2485 | fsg_lun_close(curlun); |
| 2490 | curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT; | ||
| 2491 | } | ||
| 2492 | up_write(&common->filesem); | ||
| 2493 | } | 2486 | } |
| 2487 | up_write(&common->filesem); | ||
| 2494 | 2488 | ||
| 2495 | /* Let fsg_unbind() know the thread has exited */ | 2489 | /* Let fsg_unbind() know the thread has exited */ |
| 2496 | complete_and_exit(&common->thread_notifier, 0); | 2490 | complete_and_exit(&common->thread_notifier, 0); |
| @@ -2681,13 +2675,6 @@ void fsg_common_remove_luns(struct fsg_common *common) · 184 unmodified lines | |||
| 2681 | } | 2675 | } |
| 2682 | EXPORT_SYMBOL_GPL(fsg_common_remove_luns); | 2676 | EXPORT_SYMBOL_GPL(fsg_common_remove_luns); |
| 2683 | 2677 | ||
| 2684 | void fsg_common_set_ops(struct fsg_common *common, | ||
| 2685 | const struct fsg_operations *ops) | ||
| 2686 | { | ||
| 2687 | common->ops = ops; | ||
| 2688 | } | ||
| 2689 | EXPORT_SYMBOL_GPL(fsg_common_set_ops); | ||
| 2690 | |||
| 2691 | void fsg_common_free_buffers(struct fsg_common *common) | 2678 | void fsg_common_free_buffers(struct fsg_common *common) |
| 2692 | { | 2679 | { |
| 2693 | _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); | 2680 | _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers); |
| @@ -60,17 +60,6 @@ struct fsg_module_parameters { · 59 unmodified lines | |||
| 60 | struct fsg_common; | 60 | struct fsg_common; |
| 61 | 61 | ||
| 62 | /* FSF callback functions */ | 62 | /* FSF callback functions */ |
| 63 | struct fsg_operations { | ||
| 64 | /* | ||
| 65 | * Callback function to call when thread exits. If no | ||
| 66 | * callback is set or it returns value lower then zero MSF | ||
| 67 | * will force eject all LUNs it operates on (including those | ||
| 68 | * marked as non-removable or with prevent_medium_removal flag | ||
| 69 | * set). | ||
| 70 | */ | ||
| 71 | int (*thread_exits)(struct fsg_common *common); | ||
| 72 | }; | ||
| 73 | |||
| 74 | struct fsg_lun_opts { | 63 | struct fsg_lun_opts { |
| 75 | struct config_group group; | 64 | struct config_group group; |
| 76 | struct fsg_lun *lun; | 65 | struct fsg_lun *lun; |
| @@ -142,9 +131,6 @@ void fsg_common_remove_lun(struct fsg_lun *lun); · 65 unmodified lines | |||
| 142 | 131 | ||
| 143 | void fsg_common_remove_luns(struct fsg_common *common); | 132 | void fsg_common_remove_luns(struct fsg_common *common); |
| 144 | 133 | ||
| 145 | void fsg_common_set_ops(struct fsg_common *common, | ||
| 146 | const struct fsg_operations *ops); | ||
| 147 | |||
| 148 | int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, | 134 | int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, |
| 149 | unsigned int id, const char *name, | 135 | unsigned int id, const char *name, |
| 150 | const char **name_pfx); | 136 | const char **name_pfx); |
| @@ -555,6 +555,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) · 554 unmodified lines | |||
| 555 | size_t size; /* Amount of data in a TX request. */ | 555 | size_t size; /* Amount of data in a TX request. */ |
| 556 | size_t bytes_copied = 0; | 556 | size_t bytes_copied = 0; |
| 557 | struct usb_request *req; | 557 | struct usb_request *req; |
| 558 | int value; | ||
| 558 | 559 | ||
| 559 | DBG(dev, "printer_write trying to send %d bytes\n", (int)len); | 560 | DBG(dev, "printer_write trying to send %d bytes\n", (int)len); |
| 560 | 561 | ||
| @@ -634,7 +635,11 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) · 73 unmodified lines | |||
| 634 | return -EAGAIN; | 635 | return -EAGAIN; |
| 635 | } | 636 | } |
| 636 | 637 | ||
| 637 | if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { | 638 | /* here, we unlock, and only unlock, to avoid deadlock. */ |
| 639 | spin_unlock(&dev->lock); | ||
| 640 | value = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC); | ||
| 641 | spin_lock(&dev->lock); | ||
| 642 | if (value) { | ||
| 638 | list_add(&req->list, &dev->tx_reqs); | 643 | list_add(&req->list, &dev->tx_reqs); |
| 639 | spin_unlock_irqrestore(&dev->lock, flags); | 644 | spin_unlock_irqrestore(&dev->lock, flags); |
| 640 | mutex_unlock(&dev->lock_printer_io); | 645 | mutex_unlock(&dev->lock_printer_io); |
| @@ -279,6 +279,7 @@ struct ffs_data { · 278 unmodified lines | |||
| 279 | } file_perms; | 279 | } file_perms; |
| 280 | 280 | ||
| 281 | struct eventfd_ctx *ffs_eventfd; | 281 | struct eventfd_ctx *ffs_eventfd; |
| 282 | struct workqueue_struct *io_completion_wq; | ||
| 282 | bool no_disconnect; | 283 | bool no_disconnect; |
| 283 | struct work_struct reset_work; | 284 | struct work_struct reset_work; |
| 284 | 285 | ||
| @@ -28,7 +28,7 @@ · 27 unmodified lines | |||
| 28 | #include <linux/aio.h> | 28 | #include <linux/aio.h> |
| 29 | #include <linux/uio.h> | 29 | #include <linux/uio.h> |
| 30 | #include <linux/refcount.h> | 30 | #include <linux/refcount.h> |
| 31 | 31 | #include <linux/delay.h> | |
| 32 | #include <linux/device.h> | 32 | #include <linux/device.h> |
| 33 | #include <linux/moduleparam.h> | 33 | #include <linux/moduleparam.h> |
| 34 | 34 | ||
| @@ -116,6 +116,7 @@ enum ep0_state { · 81 unmodified lines | |||
| 116 | struct dev_data { | 116 | struct dev_data { |
| 117 | spinlock_t lock; | 117 | spinlock_t lock; |
| 118 | refcount_t count; | 118 | refcount_t count; |
| 119 | int udc_usage; | ||
| 119 | enum ep0_state state; /* P: lock */ | 120 | enum ep0_state state; /* P: lock */ |
| 120 | struct usb_gadgetfs_event event [N_EVENT]; | 121 | struct usb_gadgetfs_event event [N_EVENT]; |
| 121 | unsigned ev_next; | 122 | unsigned ev_next; |
| @@ -513,9 +514,9 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req) · 391 unmodified lines | |||
| 513 | INIT_WORK(&priv->work, ep_user_copy_worker); | 514 | INIT_WORK(&priv->work, ep_user_copy_worker); |
| 514 | schedule_work(&priv->work); | 515 | schedule_work(&priv->work); |
| 515 | } | 516 | } |
| 516 | spin_unlock(&epdata->dev->lock); | ||
| 517 | 517 | ||
| 518 | usb_ep_free_request(ep, req); | 518 | usb_ep_free_request(ep, req); |
| 519 | spin_unlock(&epdata->dev->lock); | ||
| 519 | put_ep(epdata); | 520 | put_ep(epdata); |
| 520 | } | 521 | } |
| 521 | 522 | ||
| @@ -939,9 +940,11 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) · 417 unmodified lines | |||
| 939 | struct usb_request *req = dev->req; | 940 | struct usb_request *req = dev->req; |
| 940 | 941 | ||
| 941 | if ((retval = setup_req (ep, req, 0)) == 0) { | 942 | if ((retval = setup_req (ep, req, 0)) == 0) { |
| 943 | ++dev->udc_usage; | ||
| 942 | spin_unlock_irq (&dev->lock); | 944 | spin_unlock_irq (&dev->lock); |
| 943 | retval = usb_ep_queue (ep, req, GFP_KERNEL); | 945 | retval = usb_ep_queue (ep, req, GFP_KERNEL); |
| 944 | spin_lock_irq (&dev->lock); | 946 | spin_lock_irq (&dev->lock); |
| 947 | --dev->udc_usage; | ||
| 945 | } | 948 | } |
| 946 | dev->state = STATE_DEV_CONNECTED; | 949 | dev->state = STATE_DEV_CONNECTED; |
| 947 | 950 | ||
| @@ -983,11 +986,14 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) · 35 unmodified lines | |||
| 983 | retval = -EIO; | 986 | retval = -EIO; |
| 984 | else { | 987 | else { |
| 985 | len = min (len, (size_t)dev->req->actual); | 988 | len = min (len, (size_t)dev->req->actual); |
| 986 | // FIXME don't call this with the spinlock held ... | 989 | ++dev->udc_usage; |
| 990 | spin_unlock_irq(&dev->lock); | ||
| 987 | if (copy_to_user (buf, dev->req->buf, len)) | 991 | if (copy_to_user (buf, dev->req->buf, len)) |
| 988 | retval = -EFAULT; | 992 | retval = -EFAULT; |
| 989 | else | 993 | else |
| 990 | retval = len; | 994 | retval = len; |
| 995 | spin_lock_irq(&dev->lock); | ||
| 996 | --dev->udc_usage; | ||
| 991 | clean_req (dev->gadget->ep0, dev->req); | 997 | clean_req (dev->gadget->ep0, dev->req); |
| 992 | /* NOTE userspace can't yet choose to stall */ | 998 | /* NOTE userspace can't yet choose to stall */ |
| 993 | } | 999 | } |
| @@ -1131,6 +1137,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) · 137 unmodified lines | |||
| 1131 | retval = setup_req (dev->gadget->ep0, dev->req, len); | 1137 | retval = setup_req (dev->gadget->ep0, dev->req, len); |
| 1132 | if (retval == 0) { | 1138 | if (retval == 0) { |
| 1133 | dev->state = STATE_DEV_CONNECTED; | 1139 | dev->state = STATE_DEV_CONNECTED; |
| 1140 | ++dev->udc_usage; | ||
| 1134 | spin_unlock_irq (&dev->lock); | 1141 | spin_unlock_irq (&dev->lock); |
| 1135 | if (copy_from_user (dev->req->buf, buf, len)) | 1142 | if (copy_from_user (dev->req->buf, buf, len)) |
| 1136 | retval = -EFAULT; | 1143 | retval = -EFAULT; |
| @@ -1142,6 +1149,7 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) · 5 unmodified lines | |||
| 1142 | GFP_KERNEL); | 1149 | GFP_KERNEL); |
| 1143 | } | 1150 | } |
| 1144 | spin_lock_irq(&dev->lock); | 1151 | spin_lock_irq(&dev->lock); |
| 1152 | --dev->udc_usage; | ||
| 1145 | if (retval < 0) { | 1153 | if (retval < 0) { |
| 1146 | clean_req (dev->gadget->ep0, dev->req); | 1154 | clean_req (dev->gadget->ep0, dev->req); |
| 1147 | } else | 1155 | } else |
| @@ -1243,9 +1251,21 @@ static long dev_ioctl (struct file *fd, unsigned code, unsigned long value) · 95 unmodified lines | |||
| 1243 | struct usb_gadget *gadget = dev->gadget; | 1251 | struct usb_gadget *gadget = dev->gadget; |
| 1244 | long ret = -ENOTTY; | 1252 | long ret = -ENOTTY; |
| 1245 | 1253 | ||
| 1246 | if (gadget->ops->ioctl) | 1254 | spin_lock_irq(&dev->lock); |
| 1255 | if (dev->state == STATE_DEV_OPENED || | ||
| 1256 | dev->state == STATE_DEV_UNBOUND) { | ||
| 1257 | /* Not bound to a UDC */ | ||
| 1258 | } else if (gadget->ops->ioctl) { | ||
| 1259 | ++dev->udc_usage; | ||
| 1260 | spin_unlock_irq(&dev->lock); | ||
| 1261 | |||
| 1247 | ret = gadget->ops->ioctl (gadget, code, value); | 1262 | ret = gadget->ops->ioctl (gadget, code, value); |
| 1248 | 1263 | ||
| 1264 | spin_lock_irq(&dev->lock); | ||
| 1265 | --dev->udc_usage; | ||
| 1266 | } | ||
| 1267 | spin_unlock_irq(&dev->lock); | ||
| 1268 | |||
| 1249 | return ret; | 1269 | return ret; |
| 1250 | } | 1270 | } |
| 1251 | 1271 | ||
| @@ -1463,10 +1483,12 @@ delegate: · 211 unmodified lines | |||
| 1463 | if (value < 0) | 1483 | if (value < 0) |
| 1464 | break; | 1484 | break; |
| 1465 | 1485 | ||
| 1486 | ++dev->udc_usage; | ||
| 1466 | spin_unlock (&dev->lock); | 1487 | spin_unlock (&dev->lock); |
| 1467 | value = usb_ep_queue (gadget->ep0, dev->req, | 1488 | value = usb_ep_queue (gadget->ep0, dev->req, |
| 1468 | GFP_KERNEL); | 1489 | GFP_KERNEL); |
| 1469 | spin_lock (&dev->lock); | 1490 | spin_lock (&dev->lock); |
| 1491 | --dev->udc_usage; | ||
| 1470 | if (value < 0) { | 1492 | if (value < 0) { |
| 1471 | clean_req (gadget->ep0, dev->req); | 1493 | clean_req (gadget->ep0, dev->req); |
| 1472 | break; | 1494 | break; |
| @@ -1490,8 +1512,12 @@ delegate: · 17 unmodified lines | |||
| 1490 | req->length = value; | 1512 | req->length = value; |
| 1491 | req->zero = value < w_length; | 1513 | req->zero = value < w_length; |
| 1492 | 1514 | ||
| 1515 | ++dev->udc_usage; | ||
| 1493 | spin_unlock (&dev->lock); | 1516 | spin_unlock (&dev->lock); |
| 1494 | value = usb_ep_queue (gadget->ep0, req, GFP_KERNEL); | 1517 | value = usb_ep_queue (gadget->ep0, req, GFP_KERNEL); |
| 1518 | spin_lock(&dev->lock); | ||
| 1519 | --dev->udc_usage; | ||
| 1520 | spin_unlock(&dev->lock); | ||
| 1495 | if (value < 0) { | 1521 | if (value < 0) { |
| 1496 | DBG (dev, "ep_queue --> %d\n", value); | 1522 | DBG (dev, "ep_queue --> %d\n", value); |
| 1497 | req->status = 0; | 1523 | req->status = 0; |
| @@ -1518,21 +1544,24 @@ static void destroy_ep_files (struct dev_data *dev) · 20 unmodified lines | |||
| 1518 | /* break link to FS */ | 1544 | /* break link to FS */ |
| 1519 | ep = list_first_entry (&dev->epfiles, struct ep_data, epfiles); | 1545 | ep = list_first_entry (&dev->epfiles, struct ep_data, epfiles); |
| 1520 | list_del_init (&ep->epfiles); | 1546 | list_del_init (&ep->epfiles); |
| 1547 | spin_unlock_irq (&dev->lock); | ||
| 1548 | |||
| 1521 | dentry = ep->dentry; | 1549 | dentry = ep->dentry; |
| 1522 | ep->dentry = NULL; | 1550 | ep->dentry = NULL; |
| 1523 | parent = d_inode(dentry->d_parent); | 1551 | parent = d_inode(dentry->d_parent); |
| 1524 | 1552 | ||
| 1525 | /* break link to controller */ | 1553 | /* break link to controller */ |
| 1554 | mutex_lock(&ep->lock); | ||
| 1526 | if (ep->state == STATE_EP_ENABLED) | 1555 | if (ep->state == STATE_EP_ENABLED) |
| 1527 | (void) usb_ep_disable (ep->ep); | 1556 | (void) usb_ep_disable (ep->ep); |
| 1528 | ep->state = STATE_EP_UNBOUND; | 1557 | ep->state = STATE_EP_UNBOUND; |
| 1529 | usb_ep_free_request (ep->ep, ep->req); | 1558 | usb_ep_free_request (ep->ep, ep->req); |
| 1530 | ep->ep = NULL; | 1559 | ep->ep = NULL; |
| 1560 | mutex_unlock(&ep->lock); | ||
| 1561 | |||
| 1531 | wake_up (&ep->wait); | 1562 | wake_up (&ep->wait); |
| 1532 | put_ep (ep); | 1563 | put_ep (ep); |
| 1533 | 1564 | ||
| 1534 | spin_unlock_irq (&dev->lock); | ||
| 1535 | |||
| 1536 | /* break link to dcache */ | 1565 | /* break link to dcache */ |
| 1537 | inode_lock(parent); | 1566 | inode_lock(parent); |
| 1538 | d_delete (dentry); | 1567 | d_delete (dentry); |
| @@ -1603,6 +1632,11 @@ gadgetfs_unbind (struct usb_gadget *gadget) · 64 unmodified lines | |||
| 1603 | 1632 | ||
| 1604 | spin_lock_irq (&dev->lock); | 1633 | spin_lock_irq (&dev->lock); |
| 1605 | dev->state = STATE_DEV_UNBOUND; | 1634 | dev->state = STATE_DEV_UNBOUND; |
| 1635 | while (dev->udc_usage > 0) { | ||
| 1636 | spin_unlock_irq(&dev->lock); | ||
| 1637 | usleep_range(1000, 2000); | ||
| 1638 | spin_lock_irq(&dev->lock); | ||
| 1639 | } | ||
| 1606 | spin_unlock_irq (&dev->lock); | 1640 | spin_unlock_irq (&dev->lock); |
| 1607 | 1641 | ||
| 1608 | destroy_ep_files (dev); | 1642 | destroy_ep_files (dev); |
| @@ -107,15 +107,6 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS; · 106 unmodified lines | |||
| 107 | 107 | ||
| 108 | FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); | 108 | FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); |
| 109 | 109 | ||
| 110 | static unsigned long msg_registered; | ||
| 111 | static void msg_cleanup(void); | ||
| 112 | |||
| 113 | static int msg_thread_exits(struct fsg_common *common) | ||
| 114 | { | ||
| 115 | msg_cleanup(); | ||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | static int msg_do_config(struct usb_configuration *c) | 110 | static int msg_do_config(struct usb_configuration *c) |
| 120 | { | 111 | { |
| 121 | struct fsg_opts *opts; | 112 | struct fsg_opts *opts; |
| @@ -154,9 +145,6 @@ static struct usb_configuration msg_config_driver = { · 32 unmodified lines | |||
| 154 | 145 | ||
| 155 | static int msg_bind(struct usb_composite_dev *cdev) | 146 | static int msg_bind(struct usb_composite_dev *cdev) |
| 156 | { | 147 | { |
| 157 | static const struct fsg_operations ops = { | ||
| 158 | .thread_exits = msg_thread_exits, | ||
| 159 | }; | ||
| 160 | struct fsg_opts *opts; | 148 | struct fsg_opts *opts; |
| 161 | struct fsg_config config; | 149 | struct fsg_config config; |
| 162 | int status; | 150 | int status; |
| @@ -173,8 +161,6 @@ static int msg_bind(struct usb_composite_dev *cdev) · 10 unmodified lines | |||
| 173 | if (status) | 161 | if (status) |
| 174 | goto fail; | 162 | goto fail; |
| 175 | 163 | ||
| 176 | fsg_common_set_ops(opts->common, &ops); | ||
| 177 | |||
| 178 | status = fsg_common_set_cdev(opts->common, cdev, config.can_stall); | 164 | status = fsg_common_set_cdev(opts->common, cdev, config.can_stall); |
| 179 | if (status) | 165 | if (status) |
| 180 | goto fail_set_cdev; | 166 | goto fail_set_cdev; |
| @@ -256,18 +242,12 @@ MODULE_LICENSE("GPL"); · 75 unmodified lines | |||
| 256 | 242 | ||
| 257 | static int __init msg_init(void) | 243 | static int __init msg_init(void) |
| 258 | { | 244 | { |
| 259 | int ret; | 245 | return usb_composite_probe(&msg_driver); |
| 260 | |||
| 261 | ret = usb_composite_probe(&msg_driver); | ||
| 262 | set_bit(0, &msg_registered); | ||
| 263 | |||
| 264 | return ret; | ||
| 265 | } | 246 | } |
| 266 | module_init(msg_init); | 247 | module_init(msg_init); |
| 267 | 248 | ||
| 268 | static void msg_cleanup(void) | 249 | static void __exit msg_cleanup(void) |
| 269 | { | 250 | { |
| 270 | if (test_and_clear_bit(0, &msg_registered)) | 251 | usb_composite_unregister(&msg_driver); |
| 271 | usb_composite_unregister(&msg_driver); | ||
| 272 | } | 252 | } |
| 273 | module_exit(msg_cleanup); | 253 | module_exit(msg_cleanup); |
| @@ -273,6 +273,7 @@ config USB_SNP_CORE · 272 unmodified lines | |||
| 273 | config USB_SNP_UDC_PLAT | 273 | config USB_SNP_UDC_PLAT |
| 274 | tristate "Synopsys USB 2.0 Device controller" | 274 | tristate "Synopsys USB 2.0 Device controller" |
| 275 | depends on USB_GADGET && OF && HAS_DMA | 275 | depends on USB_GADGET && OF && HAS_DMA |
| 276 | depends on EXTCON || EXTCON=n | ||
| 276 | select USB_GADGET_DUALSPEED | 277 | select USB_GADGET_DUALSPEED |
| 277 | select USB_SNP_CORE | 278 | select USB_SNP_CORE |
| 278 | default ARCH_BCM_IPROC | 279 | default ARCH_BCM_IPROC |
| @@ -29,6 +29,8 @@ · 28 unmodified lines | |||
| 29 | #include <linux/of_gpio.h> | 29 | #include <linux/of_gpio.h> |
| 30 | 30 | ||
| 31 | #include "atmel_usba_udc.h" | 31 | #include "atmel_usba_udc.h" |
| 32 | #define USBA_VBUS_IRQFLAGS (IRQF_ONESHOT \ | ||
| 33 | | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING) | ||
| 32 | 34 | ||
| 33 | #ifdef CONFIG_USB_GADGET_DEBUG_FS | 35 | #ifdef CONFIG_USB_GADGET_DEBUG_FS |
| 34 | #include <linux/debugfs.h> | 36 | #include <linux/debugfs.h> |
| @@ -2361,7 +2363,7 @@ static int usba_udc_probe(struct platform_device *pdev) · 2326 unmodified lines | |||
| 2361 | IRQ_NOAUTOEN); | 2363 | IRQ_NOAUTOEN); |
| 2362 | ret = devm_request_threaded_irq(&pdev->dev, | 2364 | ret = devm_request_threaded_irq(&pdev->dev, |
| 2363 | gpio_to_irq(udc->vbus_pin), NULL, | 2365 | gpio_to_irq(udc->vbus_pin), NULL, |
| 2364 | usba_vbus_irq_thread, IRQF_ONESHOT, | 2366 | usba_vbus_irq_thread, USBA_VBUS_IRQFLAGS, |
| 2365 | "atmel_usba_udc", udc); | 2367 | "atmel_usba_udc", udc); |
| 2366 | if (ret) { | 2368 | if (ret) { |
| 2367 | udc->vbus_pin = -ENODEV; | 2369 | udc->vbus_pin = -ENODEV; |
| @@ -1320,8 +1320,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri · 1319 unmodified lines | |||
| 1320 | udc->dev.driver = &driver->driver; | 1320 | udc->dev.driver = &driver->driver; |
| 1321 | udc->gadget->dev.driver = &driver->driver; | 1321 | udc->gadget->dev.driver = &driver->driver; |
| 1322 | 1322 | ||
| 1323 | if (driver->max_speed < udc->gadget->max_speed) | 1323 | usb_gadget_udc_set_speed(udc, driver->max_speed); |
| 1324 | usb_gadget_udc_set_speed(udc, driver->max_speed); | ||
| 1325 | 1324 | ||
| 1326 | ret = driver->bind(udc->gadget, driver); | 1325 | ret = driver->bind(udc->gadget, driver); |
| 1327 | if (ret) | 1326 | if (ret) |
| @@ -237,6 +237,8 @@ struct dummy_hcd { · 236 unmodified lines | |||
| 237 | 237 | ||
| 238 | struct usb_device *udev; | 238 | struct usb_device *udev; |
| 239 | struct list_head urbp_list; | 239 | struct list_head urbp_list; |
| 240 | struct urbp *next_frame_urbp; | ||
| 241 | |||
| 240 | u32 stream_en_ep; | 242 | u32 stream_en_ep; |
| 241 | u8 num_stream[30 / 2]; | 243 | u8 num_stream[30 / 2]; |
| 242 | 244 | ||
| @@ -253,11 +255,13 @@ struct dummy { · 10 unmodified lines | |||
| 253 | */ | 255 | */ |
| 254 | struct dummy_ep ep[DUMMY_ENDPOINTS]; | 256 | struct dummy_ep ep[DUMMY_ENDPOINTS]; |
| 255 | int address; | 257 | int address; |
| 258 | int callback_usage; | ||
| 256 | struct usb_gadget gadget; | 259 | struct usb_gadget gadget; |
| 257 | struct usb_gadget_driver *driver; | 260 | struct usb_gadget_driver *driver; |
| 258 | struct dummy_request fifo_req; | 261 | struct dummy_request fifo_req; |
| 259 | u8 fifo_buf[FIFO_SIZE]; | 262 | u8 fifo_buf[FIFO_SIZE]; |
| 260 | u16 devstatus; | 263 | u16 devstatus; |
| 264 | unsigned ints_enabled:1; | ||
| 261 | unsigned udc_suspended:1; | 265 | unsigned udc_suspended:1; |
| 262 | unsigned pullup:1; | 266 | unsigned pullup:1; |
| 263 | 267 | ||
| @@ -375,11 +379,10 @@ static void set_link_state_by_speed(struct dummy_hcd *dum_hcd) · 111 unmodified lines | |||
| 375 | USB_PORT_STAT_CONNECTION) == 0) | 379 | USB_PORT_STAT_CONNECTION) == 0) |
| 376 | dum_hcd->port_status |= | 380 | dum_hcd->port_status |= |
| 377 | (USB_PORT_STAT_C_CONNECTION << 16); | 381 | (USB_PORT_STAT_C_CONNECTION << 16); |
| 378 | if ((dum_hcd->port_status & | 382 | if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) && |
| 379 | USB_PORT_STAT_ENABLE) == 1 && | 383 | (dum_hcd->port_status & |
| 380 | (dum_hcd->port_status & | 384 | USB_PORT_STAT_LINK_STATE) == USB_SS_PORT_LS_U0 && |
| 381 | USB_SS_PORT_LS_U0) == 1 && | 385 | dum_hcd->rh_state != DUMMY_RH_SUSPENDED) |
| 382 | dum_hcd->rh_state != DUMMY_RH_SUSPENDED) | ||
| 383 | dum_hcd->active = 1; | 386 | dum_hcd->active = 1; |
| 384 | } | 387 | } |
| 385 | } else { | 388 | } else { |
| @@ -440,18 +443,27 @@ static void set_link_state(struct dummy_hcd *dum_hcd) · 54 unmodified lines | |||
| 440 | (~dum_hcd->old_status) & dum_hcd->port_status; | 443 | (~dum_hcd->old_status) & dum_hcd->port_status; |
| 441 | 444 | ||
| 442 | /* Report reset and disconnect events to the driver */ | 445 | /* Report reset and disconnect events to the driver */ |
| 443 | if (dum->driver && (disconnect || reset)) { | 446 | if (dum->ints_enabled && (disconnect || reset)) { |
| 444 | stop_activity(dum); | 447 | stop_activity(dum); |
| 448 | ++dum->callback_usage; | ||
| 449 | spin_unlock(&dum->lock); | ||
| 445 | if (reset) | 450 | if (reset) |
| 446 | usb_gadget_udc_reset(&dum->gadget, dum->driver); | 451 | usb_gadget_udc_reset(&dum->gadget, dum->driver); |
| 447 | else | 452 | else |
| 448 | dum->driver->disconnect(&dum->gadget); | 453 | dum->driver->disconnect(&dum->gadget); |
| 454 | spin_lock(&dum->lock); | ||
| 455 | --dum->callback_usage; | ||
| 449 | } | 456 | } |
| 450 | } else if (dum_hcd->active != dum_hcd->old_active) { | 457 | } else if (dum_hcd->active != dum_hcd->old_active && |
| 458 | dum->ints_enabled) { | ||
| 459 | ++dum->callback_usage; | ||
| 460 | spin_unlock(&dum->lock); | ||
| 451 | if (dum_hcd->old_active && dum->driver->suspend) | 461 | if (dum_hcd->old_active && dum->driver->suspend) |
| 452 | dum->driver->suspend(&dum->gadget); | 462 | dum->driver->suspend(&dum->gadget); |
| 453 | else if (!dum_hcd->old_active && dum->driver->resume) | 463 | else if (!dum_hcd->old_active && dum->driver->resume) |
| 454 | dum->driver->resume(&dum->gadget); | 464 | dum->driver->resume(&dum->gadget); |
| 465 | spin_lock(&dum->lock); | ||
| 466 | --dum->callback_usage; | ||
| 455 | } | 467 | } |
| 456 | 468 | ||
| 457 | dum_hcd->old_status = dum_hcd->port_status; | 469 | dum_hcd->old_status = dum_hcd->port_status; |
| @@ -972,8 +984,11 @@ static int dummy_udc_start(struct usb_gadget *g, · 514 unmodified lines | |||
| 972 | * can't enumerate without help from the driver we're binding. | 984 | * can't enumerate without help from the driver we're binding. |
| 973 | */ | 985 | */ |
| 974 | 986 | ||
| 987 | spin_lock_irq(&dum->lock); | ||
| 975 | dum->devstatus = 0; | 988 | dum->devstatus = 0; |
| 976 | dum->driver = driver; | 989 | dum->driver = driver; |
| 990 | dum->ints_enabled = 1; | ||
| 991 | spin_unlock_irq(&dum->lock); | ||
| 977 | 992 | ||
| 978 | return 0; | 993 | return 0; |
| 979 | } | 994 | } |
| @@ -984,6 +999,16 @@ static int dummy_udc_stop(struct usb_gadget *g) · 4 unmodified lines | |||
| 984 | struct dummy *dum = dum_hcd->dum; | 999 | struct dummy *dum = dum_hcd->dum; |
| 985 | 1000 | ||
| 986 | spin_lock_irq(&dum->lock); | 1001 | spin_lock_irq(&dum->lock); |
| 1002 | dum->ints_enabled = 0; | ||
| 1003 | stop_activity(dum); | ||
| 1004 | |||
| 1005 | /* emulate synchronize_irq(): wait for callbacks to finish */ | ||
| 1006 | while (dum->callback_usage > 0) { | ||
| 1007 | spin_unlock_irq(&dum->lock); | ||
| 1008 | usleep_range(1000, 2000); | ||
| 1009 | spin_lock_irq(&dum->lock); | ||
| 1010 | } | ||
| 1011 | |||
| 987 | dum->driver = NULL; | 1012 | dum->driver = NULL; |
| 988 | spin_unlock_irq(&dum->lock); | 1013 | spin_unlock_irq(&dum->lock); |
| 989 | 1014 | ||
| @@ -1037,7 +1062,12 @@ static int dummy_udc_probe(struct platform_device *pdev) · 47 unmodified lines | |||
| 1037 | memzero_explicit(&dum->gadget, sizeof(struct usb_gadget)); | 1062 | memzero_explicit(&dum->gadget, sizeof(struct usb_gadget)); |
| 1038 | dum->gadget.name = gadget_name; | 1063 | dum->gadget.name = gadget_name; |
| 1039 | dum->gadget.ops = &dummy_ops; | 1064 | dum->gadget.ops = &dummy_ops; |
| 1040 | dum->gadget.max_speed = USB_SPEED_SUPER; | 1065 | if (mod_data.is_super_speed) |
| 1066 | dum->gadget.max_speed = USB_SPEED_SUPER; | ||
| 1067 | else if (mod_data.is_high_speed) | ||
| 1068 | dum->gadget.max_speed = USB_SPEED_HIGH; | ||
| 1069 | else | ||
| 1070 | dum->gadget.max_speed = USB_SPEED_FULL; | ||
| 1041 | 1071 | ||
| 1042 | dum->gadget.dev.parent = &pdev->dev; | 1072 | dum->gadget.dev.parent = &pdev->dev; |
| 1043 | init_dummy_udc_hw(dum); | 1073 | init_dummy_udc_hw(dum); |
| @@ -1246,6 +1276,8 @@ static int dummy_urb_enqueue( · 202 unmodified lines | |||
| 1246 | 1276 | ||
| 1247 | list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list); | 1277 | list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list); |
| 1248 | urb->hcpriv = urbp; | 1278 | urb->hcpriv = urbp; |
| 1279 | if (!dum_hcd->next_frame_urbp) | ||
| 1280 | dum_hcd->next_frame_urbp = urbp; | ||
| 1249 | if (usb_pipetype(urb->pipe) == PIPE_CONTROL) | 1281 | if (usb_pipetype(urb->pipe) == PIPE_CONTROL) |
| 1250 | urb->error_count = 1; /* mark as a new urb */ | 1282 | urb->error_count = 1; /* mark as a new urb */ |
| 1251 | 1283 | ||
| @@ -1521,6 +1553,8 @@ static struct dummy_ep *find_endpoint(struct dummy *dum, u8 address) · 269 unmodified lines | |||
| 1521 | if (!is_active((dum->gadget.speed == USB_SPEED_SUPER ? | 1553 | if (!is_active((dum->gadget.speed == USB_SPEED_SUPER ? |
| 1522 | dum->ss_hcd : dum->hs_hcd))) | 1554 | dum->ss_hcd : dum->hs_hcd))) |
| 1523 | return NULL; | 1555 | return NULL; |
| 1556 | if (!dum->ints_enabled) | ||
| 1557 | return NULL; | ||
| 1524 | if ((address & ~USB_DIR_IN) == 0) | 1558 | if ((address & ~USB_DIR_IN) == 0) |
| 1525 | return &dum->ep[0]; | 1559 | return &dum->ep[0]; |
| 1526 | for (i = 1; i < DUMMY_ENDPOINTS; i++) { | 1560 | for (i = 1; i < DUMMY_ENDPOINTS; i++) { |
| @@ -1762,6 +1796,7 @@ static void dummy_timer(unsigned long _dum_hcd) · 235 unmodified lines | |||
| 1762 | spin_unlock_irqrestore(&dum->lock, flags); | 1796 | spin_unlock_irqrestore(&dum->lock, flags); |
| 1763 | return; | 1797 | return; |
| 1764 | } | 1798 | } |
| 1799 | dum_hcd->next_frame_urbp = NULL; | ||
| 1765 | 1800 | ||
| 1766 | for (i = 0; i < DUMMY_ENDPOINTS; i++) { | 1801 | for (i = 0; i < DUMMY_ENDPOINTS; i++) { |
| 1767 | if (!ep_info[i].name) | 1802 | if (!ep_info[i].name) |
| @@ -1778,6 +1813,10 @@ restart: · 10 unmodified lines | |||
| 1778 | int type; | 1813 | int type; |
| 1779 | int status = -EINPROGRESS; | 1814 | int status = -EINPROGRESS; |
| 1780 | 1815 | ||
| 1816 | /* stop when we reach URBs queued after the timer interrupt */ | ||
| 1817 | if (urbp == dum_hcd->next_frame_urbp) | ||
| 1818 | break; | ||
| 1819 | |||
| 1781 | urb = urbp->urb; | 1820 | urb = urbp->urb; |
| 1782 | if (urb->unlinked) | 1821 | if (urb->unlinked) |
| 1783 | goto return_urb; | 1822 | goto return_urb; |
| @@ -1857,10 +1896,12 @@ restart: · 73 unmodified lines | |||
| 1857 | * until setup() returns; no reentrancy issues etc. | 1896 | * until setup() returns; no reentrancy issues etc. |
| 1858 | */ | 1897 | */ |
| 1859 | if (value > 0) { | 1898 | if (value > 0) { |
| 1899 | ++dum->callback_usage; | ||
| 1860 | spin_unlock(&dum->lock); | 1900 | spin_unlock(&dum->lock); |
| 1861 | value = dum->driver->setup(&dum->gadget, | 1901 | value = dum->driver->setup(&dum->gadget, |
| 1862 | &setup); | 1902 | &setup); |
| 1863 | spin_lock(&dum->lock); | 1903 | spin_lock(&dum->lock); |
| 1904 | --dum->callback_usage; | ||
| 1864 | 1905 | ||
| 1865 | if (value >= 0) { | 1906 | if (value >= 0) { |
| 1866 | /* no delays (max 64KB data stage) */ | 1907 | /* no delays (max 64KB data stage) */ |
| @@ -2561,8 +2602,6 @@ static struct hc_driver dummy_hcd = { · 694 unmodified lines | |||
| 2561 | .product_desc = "Dummy host controller", | 2602 | .product_desc = "Dummy host controller", |
| 2562 | .hcd_priv_size = sizeof(struct dummy_hcd), | 2603 | .hcd_priv_size = sizeof(struct dummy_hcd), |
| 2563 | 2604 | ||
| 2564 | .flags = HCD_USB3 | HCD_SHARED, | ||
| 2565 | |||
| 2566 | .reset = dummy_setup, | 2605 | .reset = dummy_setup, |
| 2567 | .start = dummy_start, | 2606 | .start = dummy_start, |
| 2568 | .stop = dummy_stop, | 2607 | .stop = dummy_stop, |
| @@ -2591,8 +2630,12 @@ static int dummy_hcd_probe(struct platform_device *pdev) · 22 unmodified lines | |||
| 2591 | dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc); | 2630 | dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc); |
| 2592 | dum = *((void **)dev_get_platdata(&pdev->dev)); | 2631 | dum = *((void **)dev_get_platdata(&pdev->dev)); |
| 2593 | 2632 | ||
| 2594 | if (!mod_data.is_super_speed) | 2633 | if (mod_data.is_super_speed) |
| 2634 | dummy_hcd.flags = HCD_USB3 | HCD_SHARED; | ||
| 2635 | else if (mod_data.is_high_speed) | ||
| 2595 | dummy_hcd.flags = HCD_USB2; | 2636 | dummy_hcd.flags = HCD_USB2; |
| 2637 | else | ||
| 2638 | dummy_hcd.flags = HCD_USB11; | ||
| 2596 | hs_hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev)); | 2639 | hs_hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev)); |
| 2597 | if (!hs_hcd) | 2640 | if (!hs_hcd) |
| 2598 | return -ENOMEM; | 2641 | return -ENOMEM; |
| @@ -1038,7 +1038,7 @@ static int usb3_write_pipe(struct renesas_usb3_ep *usb3_ep, · 1037 unmodified lines | |||
| 1038 | usb3_ep->ep.maxpacket); | 1038 | usb3_ep->ep.maxpacket); |
| 1039 | u8 *buf = usb3_req->req.buf + usb3_req->req.actual; | 1039 | u8 *buf = usb3_req->req.buf + usb3_req->req.actual; |
| 1040 | u32 tmp = 0; | 1040 | u32 tmp = 0; |
| 1041 | bool is_last; | 1041 | bool is_last = !len ? true : false; |
| 1042 | 1042 | ||
| 1043 | if (usb3_wait_pipe_status(usb3_ep, PX_STA_BUFSTS) < 0) | 1043 | if (usb3_wait_pipe_status(usb3_ep, PX_STA_BUFSTS) < 0) |
| 1044 | return -EBUSY; | 1044 | return -EBUSY; |
| @@ -1059,7 +1059,8 @@ static int usb3_write_pipe(struct renesas_usb3_ep *usb3_ep, · 14 unmodified lines | |||
| 1059 | usb3_write(usb3, tmp, fifo_reg); | 1059 | usb3_write(usb3, tmp, fifo_reg); |
| 1060 | } | 1060 | } |
| 1061 | 1061 | ||
| 1062 | is_last = usb3_is_transfer_complete(usb3_ep, usb3_req); | 1062 | if (!is_last) |
| 1063 | is_last = usb3_is_transfer_complete(usb3_ep, usb3_req); | ||
| 1063 | /* Send the data */ | 1064 | /* Send the data */ |
| 1064 | usb3_set_px_con_send(usb3_ep, len, is_last); | 1065 | usb3_set_px_con_send(usb3_ep, len, is_last); |
| 1065 | 1066 | ||
| @@ -1150,7 +1151,8 @@ static void usb3_start_pipe0(struct renesas_usb3_ep *usb3_ep, · 84 unmodified lines | |||
| 1150 | usb3_set_p0_con_for_ctrl_read_data(usb3); | 1151 | usb3_set_p0_con_for_ctrl_read_data(usb3); |
| 1151 | } else { | 1152 | } else { |
| 1152 | usb3_clear_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); | 1153 | usb3_clear_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); |
| 1153 | usb3_set_p0_con_for_ctrl_write_data(usb3); | 1154 | if (usb3_req->req.length) |
| 1155 | usb3_set_p0_con_for_ctrl_write_data(usb3); | ||
| 1154 | } | 1156 | } |
| 1155 | 1157 | ||
| 1156 | usb3_p0_xfer(usb3_ep, usb3_req); | 1158 | usb3_p0_xfer(usb3_ep, usb3_req); |
| @@ -2053,7 +2055,16 @@ static u32 usb3_calc_ramarea(int ram_size) · 896 unmodified lines | |||
| 2053 | static u32 usb3_calc_rammap_val(struct renesas_usb3_ep *usb3_ep, | 2055 | static u32 usb3_calc_rammap_val(struct renesas_usb3_ep *usb3_ep, |
| 2054 | const struct usb_endpoint_descriptor *desc) | 2056 | const struct usb_endpoint_descriptor *desc) |
| 2055 | { | 2057 | { |
| 2056 | return usb3_ep->rammap_val | PN_RAMMAP_MPKT(usb_endpoint_maxp(desc)); | 2058 | int i; |
| 2059 | const u32 max_packet_array[] = {8, 16, 32, 64, 512}; | ||
| 2060 | u32 mpkt = PN_RAMMAP_MPKT(1024); | ||
| 2061 | |||
| 2062 | for (i = 0; i < ARRAY_SIZE(max_packet_array); i++) { | ||
| 2063 | if (usb_endpoint_maxp(desc) <= max_packet_array[i]) | ||
| 2064 | mpkt = PN_RAMMAP_MPKT(max_packet_array[i]); | ||
| 2065 | } | ||
| 2066 | |||
| 2067 | return usb3_ep->rammap_val | mpkt; | ||
| 2057 | } | 2068 | } |
| 2058 | 2069 | ||
| 2059 | static int usb3_enable_pipe_n(struct renesas_usb3_ep *usb3_ep, | 2070 | static int usb3_enable_pipe_n(struct renesas_usb3_ep *usb3_ep, |
| @@ -447,7 +447,7 @@ static int usb_asmedia_wait_write(struct pci_dev *pdev) · 446 unmodified lines | |||
| 447 | if ((value & ASMT_CONTROL_WRITE_BIT) == 0) | 447 | if ((value & ASMT_CONTROL_WRITE_BIT) == 0) |
| 448 | return 0; | 448 | return 0; |
| 449 | 449 | ||
| 450 | usleep_range(40, 60); | 450 | udelay(50); |
| 451 | } | 451 | } |
| 452 | 452 | ||
| 453 | dev_warn(&pdev->dev, "%s: check_write_ready timeout", __func__); | 453 | dev_warn(&pdev->dev, "%s: check_write_ready timeout", __func__); |
| @@ -1022,7 +1022,7 @@ EXPORT_SYMBOL_GPL(usb_disable_xhci_ports); · 568 unmodified lines | |||
| 1022 | * | 1022 | * |
| 1023 | * Takes care of the handoff between the Pre-OS (i.e. BIOS) and the OS. | 1023 | * Takes care of the handoff between the Pre-OS (i.e. BIOS) and the OS. |
| 1024 | * It signals to the BIOS that the OS wants control of the host controller, | 1024 | * It signals to the BIOS that the OS wants control of the host controller, |
| 1025 | * and then waits 5 seconds for the BIOS to hand over control. | 1025 | * and then waits 1 second for the BIOS to hand over control. |
| 1026 | * If we timeout, assume the BIOS is broken and take control anyway. | 1026 | * If we timeout, assume the BIOS is broken and take control anyway. |
| 1027 | */ | 1027 | */ |
| 1028 | static void quirk_usb_handoff_xhci(struct pci_dev *pdev) | 1028 | static void quirk_usb_handoff_xhci(struct pci_dev *pdev) |
| @@ -1069,9 +1069,9 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev) · 40 unmodified lines | |||
| 1069 | if (val & XHCI_HC_BIOS_OWNED) { | 1069 | if (val & XHCI_HC_BIOS_OWNED) { |
| 1070 | writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset); | 1070 | writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset); |
| 1071 | 1071 | ||
| 1072 | /* Wait for 5 seconds with 10 microsecond polling interval */ | 1072 | /* Wait for 1 second with 10 microsecond polling interval */ |
| 1073 | timeout = handshake(base + ext_cap_offset, XHCI_HC_BIOS_OWNED, | 1073 | timeout = handshake(base + ext_cap_offset, XHCI_HC_BIOS_OWNED, |
| 1074 | 0, 5000, 10); | 1074 | 0, 1000000, 10); |
| 1075 | 1075 | ||
| 1076 | /* Assume a buggy BIOS and take HC ownership anyway */ | 1076 | /* Assume a buggy BIOS and take HC ownership anyway */ |
| 1077 | if (timeout) { | 1077 | if (timeout) { |
| @@ -1100,7 +1100,7 @@ hc_init: · 22 unmodified lines | |||
| 1100 | * operational or runtime registers. Wait 5 seconds and no more. | 1100 | * operational or runtime registers. Wait 5 seconds and no more. |
| 1101 | */ | 1101 | */ |
| 1102 | timeout = handshake(op_reg_base + XHCI_STS_OFFSET, XHCI_STS_CNR, 0, | 1102 | timeout = handshake(op_reg_base + XHCI_STS_OFFSET, XHCI_STS_CNR, 0, |
| 1103 | 5000, 10); | 1103 | 5000000, 10); |
| 1104 | /* Assume a buggy HC and start HC initialization anyway */ | 1104 | /* Assume a buggy HC and start HC initialization anyway */ |
| 1105 | if (timeout) { | 1105 | if (timeout) { |
| 1106 | val = readl(op_reg_base + XHCI_STS_OFFSET); | 1106 | val = readl(op_reg_base + XHCI_STS_OFFSET); |
| @@ -112,7 +112,7 @@ static int xhci_create_usb3_bos_desc(struct xhci_hcd *xhci, char *buf, · 111 unmodified lines | |||
| 112 | 112 | ||
| 113 | /* If PSI table exists, add the custom speed attributes from it */ | 113 | /* If PSI table exists, add the custom speed attributes from it */ |
| 114 | if (usb3_1 && xhci->usb3_rhub.psi_count) { | 114 | if (usb3_1 && xhci->usb3_rhub.psi_count) { |
| 115 | u32 ssp_cap_base, bm_attrib, psi; | 115 | u32 ssp_cap_base, bm_attrib, psi, psi_mant, psi_exp; |
| 116 | int offset; | 116 | int offset; |
| 117 | 117 | ||
| 118 | ssp_cap_base = USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE; | 118 | ssp_cap_base = USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE; |
| @@ -139,6 +139,15 @@ static int xhci_create_usb3_bos_desc(struct xhci_hcd *xhci, char *buf, · 20 unmodified lines | |||
| 139 | for (i = 0; i < xhci->usb3_rhub.psi_count; i++) { | 139 | for (i = 0; i < xhci->usb3_rhub.psi_count; i++) { |
| 140 | psi = xhci->usb3_rhub.psi[i]; | 140 | psi = xhci->usb3_rhub.psi[i]; |
| 141 | psi &= ~USB_SSP_SUBLINK_SPEED_RSVD; | 141 | psi &= ~USB_SSP_SUBLINK_SPEED_RSVD; |
| 142 | psi_exp = XHCI_EXT_PORT_PSIE(psi); | ||
| 143 | psi_mant = XHCI_EXT_PORT_PSIM(psi); | ||
| 144 | |||
| 145 | /* Shift to Gbps and set SSP Link BIT(14) if 10Gpbs */ | ||
| 146 | for (; psi_exp < 3; psi_exp++) | ||
| 147 | psi_mant /= 1000; | ||
| 148 | if (psi_mant >= 10) | ||
| 149 | psi |= BIT(14); | ||
| 150 | |||
| 142 | if ((psi & PLT_MASK) == PLT_SYM) { | 151 | if ((psi & PLT_MASK) == PLT_SYM) { |
| 143 | /* Symmetric, create SSA RX and TX from one PSI entry */ | 152 | /* Symmetric, create SSA RX and TX from one PSI entry */ |
| 144 | put_unaligned_le32(psi, &buf[offset]); | 153 | put_unaligned_le32(psi, &buf[offset]); |
| @@ -1506,9 +1515,6 @@ int xhci_bus_suspend(struct usb_hcd *hcd) · 1361 unmodified lines | |||
| 1506 | t2 |= PORT_WKOC_E | PORT_WKCONN_E; | 1515 | t2 |= PORT_WKOC_E | PORT_WKCONN_E; |
| 1507 | t2 &= ~PORT_WKDISC_E; | 1516 | t2 &= ~PORT_WKDISC_E; |
| 1508 | } | 1517 | } |
| 1509 | if ((xhci->quirks & XHCI_U2_DISABLE_WAKE) && | ||
| 1510 | (hcd->speed < HCD_USB3)) | ||
| 1511 | t2 &= ~PORT_WAKE_BITS; | ||
| 1512 | } else | 1518 | } else |
| 1513 | t2 &= ~PORT_WAKE_BITS; | 1519 | t2 &= ~PORT_WAKE_BITS; |
| 1514 | 1520 | ||
| @@ -54,11 +54,6 @@ · 53 unmodified lines | |||
| 54 | #define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8 | 54 | #define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8 |
| 55 | #define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0 | 55 | #define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0 |
| 56 | 56 | ||
| 57 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9 | ||
| 58 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba | ||
| 59 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb | ||
| 60 | #define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc | ||
| 61 | |||
| 62 | #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142 | 57 | #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142 |
| 63 | 58 | ||
| 64 | static const char hcd_name[] = "xhci_hcd"; | 59 | static const char hcd_name[] = "xhci_hcd"; |
| @@ -142,13 +137,6 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) · 77 unmodified lines | |||
| 142 | if (pdev->vendor == PCI_VENDOR_ID_AMD) | 137 | if (pdev->vendor == PCI_VENDOR_ID_AMD) |
| 143 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; | 138 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
| 144 | 139 | ||
| 145 | if ((pdev->vendor == PCI_VENDOR_ID_AMD) && | ||
| 146 | ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) || | ||
| 147 | (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) || | ||
| 148 | (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) || | ||
| 149 | (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1))) | ||
| 150 | xhci->quirks |= XHCI_U2_DISABLE_WAKE; | ||
| 151 | |||
| 152 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) { | 140 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) { |
| 153 | xhci->quirks |= XHCI_LPM_SUPPORT; | 141 | xhci->quirks |= XHCI_LPM_SUPPORT; |
| 154 | xhci->quirks |= XHCI_INTEL_HOST; | 142 | xhci->quirks |= XHCI_INTEL_HOST; |
| @@ -178,14 +178,18 @@ static int xhci_plat_probe(struct platform_device *pdev) · 177 unmodified lines | |||
| 178 | * 2. xhci_plat is child of a device from firmware (dwc3-plat) | 178 | * 2. xhci_plat is child of a device from firmware (dwc3-plat) |
| 179 | * 3. xhci_plat is grandchild of a pci device (dwc3-pci) | 179 | * 3. xhci_plat is grandchild of a pci device (dwc3-pci) |
| 180 | */ | 180 | */ |
| 181 | sysdev = &pdev->dev; | 181 | for (sysdev = &pdev->dev; sysdev; sysdev = sysdev->parent) { |
| 182 | if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node) | 182 | if (is_of_node(sysdev->fwnode) || |
| 183 | sysdev = sysdev->parent; | 183 | is_acpi_device_node(sysdev->fwnode)) |
| 184 | break; | ||
| 184 | #ifdef CONFIG_PCI | 185 | #ifdef CONFIG_PCI |
| 185 | else if (sysdev->parent && sysdev->parent->parent && | 186 | else if (sysdev->bus == &pci_bus_type) |
| 186 | sysdev->parent->parent->bus == &pci_bus_type) | 187 | break; |
| 187 | sysdev = sysdev->parent->parent; | ||
| 188 | #endif | 188 | #endif |
| 189 | } | ||
| 190 | |||
| 191 | if (!sysdev) | ||
| 192 | sysdev = &pdev->dev; | ||
| 189 | 193 | ||
| 190 | /* Try to set 64-bit DMA first */ | 194 | /* Try to set 64-bit DMA first */ |
| 191 | if (WARN_ON(!sysdev->dma_mask)) | 195 | if (WARN_ON(!sysdev->dma_mask)) |
| @@ -1703,7 +1703,8 @@ static int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 1702 unmodified lines | |||
| 1703 | if (xhci->quirks & XHCI_MTK_HOST) { | 1703 | if (xhci->quirks & XHCI_MTK_HOST) { |
| 1704 | ret = xhci_mtk_add_ep_quirk(hcd, udev, ep); | 1704 | ret = xhci_mtk_add_ep_quirk(hcd, udev, ep); |
| 1705 | if (ret < 0) { | 1705 | if (ret < 0) { |
| 1706 | xhci_free_endpoint_ring(xhci, virt_dev, ep_index); | 1706 | xhci_ring_free(xhci, virt_dev->eps[ep_index].new_ring); |
| 1707 | virt_dev->eps[ep_index].new_ring = NULL; | ||
| 1707 | return ret; | 1708 | return ret; |
| 1708 | } | 1709 | } |
| 1709 | } | 1710 | } |
| @@ -735,6 +735,8 @@ struct xhci_ep_ctx { · 734 unmodified lines | |||
| 735 | #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) | 735 | #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) |
| 736 | /* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ | 736 | /* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ |
| 737 | #define EP_HAS_LSA (1 << 15) | 737 | #define EP_HAS_LSA (1 << 15) |
| 738 | /* hosts with LEC=1 use bits 31:24 as ESIT high bits. */ | ||
| 739 | #define CTX_TO_MAX_ESIT_PAYLOAD_HI(p) (((p) >> 24) & 0xff) | ||
| 738 | 740 | ||
| 739 | /* ep_info2 bitmasks */ | 741 | /* ep_info2 bitmasks */ |
| 740 | /* | 742 | /* |
| @@ -1681,7 +1683,7 @@ struct xhci_bus_state { · 940 unmodified lines | |||
| 1681 | 1683 | ||
| 1682 | static inline unsigned int hcd_index(struct usb_hcd *hcd) | 1684 | static inline unsigned int hcd_index(struct usb_hcd *hcd) |
| 1683 | { | 1685 | { |
| 1684 | if (hcd->speed == HCD_USB3) | 1686 | if (hcd->speed >= HCD_USB3) |
| 1685 | return 0; | 1687 | return 0; |
| 1686 | else | 1688 | else |
| 1687 | return 1; | 1689 | return 1; |
| @@ -1826,7 +1828,7 @@ struct xhci_hcd { · 138 unmodified lines | |||
| 1826 | /* For controller with a broken Port Disable implementation */ | 1828 | /* For controller with a broken Port Disable implementation */ |
| 1827 | #define XHCI_BROKEN_PORT_PED (1 << 25) | 1829 | #define XHCI_BROKEN_PORT_PED (1 << 25) |
| 1828 | #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26) | 1830 | #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26) |
| 1829 | #define XHCI_U2_DISABLE_WAKE (1 << 27) | 1831 | /* Reserved. It was XHCI_U2_DISABLE_WAKE */ |
| 1830 | #define XHCI_ASMEDIA_MODIFY_FLOWCONTROL (1 << 28) | 1832 | #define XHCI_ASMEDIA_MODIFY_FLOWCONTROL (1 << 28) |
| 1831 | 1833 | ||
| 1832 | unsigned int num_active_eps; | 1834 | unsigned int num_active_eps; |
| @@ -2540,8 +2542,8 @@ static inline const char *xhci_decode_ep_context(u32 info, u32 info2, u64 deq, · 707 unmodified lines | |||
| 2540 | u8 lsa; | 2542 | u8 lsa; |
| 2541 | u8 hid; | 2543 | u8 hid; |
| 2542 | 2544 | ||
| 2543 | esit = EP_MAX_ESIT_PAYLOAD_HI(info) << 16 | | 2545 | esit = CTX_TO_MAX_ESIT_PAYLOAD_HI(info) << 16 | |
| 2544 | EP_MAX_ESIT_PAYLOAD_LO(tx_info); | 2546 | CTX_TO_MAX_ESIT_PAYLOAD(tx_info); |
| 2545 | 2547 | ||
| 2546 | ep_state = info & EP_STATE_MASK; | 2548 | ep_state = info & EP_STATE_MASK; |
| 2547 | max_pstr = info & EP_MAXPSTREAMS_MASK; | 2549 | max_pstr = info & EP_MAXPSTREAMS_MASK; |
| @@ -282,11 +282,26 @@ static void usbhsf_fifo_clear(struct usbhs_pipe *pipe, · 281 unmodified lines | |||
| 282 | struct usbhs_fifo *fifo) | 282 | struct usbhs_fifo *fifo) |
| 283 | { | 283 | { |
| 284 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); | 284 | struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); |
| 285 | int ret = 0; | ||
| 285 | 286 | ||
| 286 | if (!usbhs_pipe_is_dcp(pipe)) | 287 | if (!usbhs_pipe_is_dcp(pipe)) { |
| 287 | usbhsf_fifo_barrier(priv, fifo); | 288 | /* |
| 289 | * This driver checks the pipe condition first to avoid -EBUSY | ||
| 290 | * from usbhsf_fifo_barrier() with about 10 msec delay in | ||
| 291 | * the interrupt handler if the pipe is RX direction and empty. | ||
| 292 | */ | ||
| 293 | if (usbhs_pipe_is_dir_in(pipe)) | ||
| 294 | ret = usbhs_pipe_is_accessible(pipe); | ||
| 295 | if (!ret) | ||
| 296 | ret = usbhsf_fifo_barrier(priv, fifo); | ||
| 297 | } | ||
| 288 | 298 | ||
| 289 | usbhs_write(priv, fifo->ctr, BCLR); | 299 | /* |
| 300 | * if non-DCP pipe, this driver should set BCLR when | ||
| 301 | * usbhsf_fifo_barrier() returns 0. | ||
| 302 | */ | ||
| 303 | if (!ret) | ||
| 304 | usbhs_write(priv, fifo->ctr, BCLR); | ||
| 290 | } | 305 | } |
| 291 | 306 | ||
| 292 | static int usbhsf_fifo_rcv_len(struct usbhs_priv *priv, | 307 | static int usbhsf_fifo_rcv_len(struct usbhs_priv *priv, |
| @@ -834,13 +834,25 @@ Retry_Sense: · 833 unmodified lines | |||
| 834 | if (result == USB_STOR_TRANSPORT_GOOD) { | 834 | if (result == USB_STOR_TRANSPORT_GOOD) { |
| 835 | srb->result = SAM_STAT_GOOD; | 835 | srb->result = SAM_STAT_GOOD; |
| 836 | srb->sense_buffer[0] = 0x0; | 836 | srb->sense_buffer[0] = 0x0; |
| 837 | } | ||
| 838 | |||
| 839 | /* | ||
| 840 | * ATA-passthru commands use sense data to report | ||
| 841 | * the command completion status, and often devices | ||
| 842 | * return Check Condition status when nothing is | ||
| 843 | * wrong. | ||
| 844 | */ | ||
| 845 | else if (srb->cmnd[0] == ATA_16 || | ||
| 846 | srb->cmnd[0] == ATA_12) { | ||
| 847 | /* leave the data alone */ | ||
| 848 | } | ||
| 837 | 849 | ||
| 838 | /* | 850 | /* |
| 839 | * If there was a problem, report an unspecified | 851 | * If there was a problem, report an unspecified |
| 840 | * hardware error to prevent the higher layers from | 852 | * hardware error to prevent the higher layers from |
| 841 | * entering an infinite retry loop. | 853 | * entering an infinite retry loop. |
| 842 | */ | 854 | */ |
| 843 | } else { | 855 | else { |
| 844 | srb->result = DID_ERROR << 16; | 856 | srb->result = DID_ERROR << 16; |
| 845 | if ((sshdr.response_code & 0x72) == 0x72) | 857 | if ((sshdr.response_code & 0x72) == 0x72) |
| 846 | srb->sense_buffer[1] = HARDWARE_ERROR; | 858 | srb->sense_buffer[1] = HARDWARE_ERROR; |
| @@ -9,7 +9,8 @@ static int uas_is_interface(struct usb_host_interface *intf) · 8 unmodified lines | |||
| 9 | intf->desc.bInterfaceProtocol == USB_PR_UAS); | 9 | intf->desc.bInterfaceProtocol == USB_PR_UAS); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | static int uas_find_uas_alt_setting(struct usb_interface *intf) | 12 | static struct usb_host_interface *uas_find_uas_alt_setting( |
| 13 | struct usb_interface *intf) | ||
| 13 | { | 14 | { |
| 14 | int i; | 15 | int i; |
| 15 | 16 | ||
| @@ -17,10 +18,10 @@ static int uas_find_uas_alt_setting(struct usb_interface *intf) · 1 unmodified line | |||
| 17 | struct usb_host_interface *alt = &intf->altsetting[i]; | 18 | struct usb_host_interface *alt = &intf->altsetting[i]; |
| 18 | 19 | ||
| 19 | if (uas_is_interface(alt)) | 20 | if (uas_is_interface(alt)) |
| 20 | return alt->desc.bAlternateSetting; | 21 | return alt; |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | return -ENODEV; | 24 | return NULL; |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | static int uas_find_endpoints(struct usb_host_interface *alt, | 27 | static int uas_find_endpoints(struct usb_host_interface *alt, |
| @@ -58,14 +59,14 @@ static int uas_use_uas_driver(struct usb_interface *intf, · 31 unmodified lines | |||
| 58 | struct usb_device *udev = interface_to_usbdev(intf); | 59 | struct usb_device *udev = interface_to_usbdev(intf); |
| 59 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | 60 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
| 60 | unsigned long flags = id->driver_info; | 61 | unsigned long flags = id->driver_info; |
| 61 | int r, alt; | 62 | struct usb_host_interface *alt; |
| 62 | 63 | int r; | |
| 63 | 64 | ||
| 64 | alt = uas_find_uas_alt_setting(intf); | 65 | alt = uas_find_uas_alt_setting(intf); |
| 65 | if (alt < 0) | 66 | if (!alt) |
| 66 | return 0; | 67 | return 0; |
| 67 | 68 | ||
| 68 | r = uas_find_endpoints(&intf->altsetting[alt], eps); | 69 | r = uas_find_endpoints(alt, eps); |
| 69 | if (r < 0) | 70 | if (r < 0) |
| 70 | return 0; | 71 | return 0; |
| 71 | 72 | ||
| @@ -873,14 +873,14 @@ MODULE_DEVICE_TABLE(usb, uas_usb_ids); · 872 unmodified lines | |||
| 873 | static int uas_switch_interface(struct usb_device *udev, | 873 | static int uas_switch_interface(struct usb_device *udev, |
| 874 | struct usb_interface *intf) | 874 | struct usb_interface *intf) |
| 875 | { | 875 | { |
| 876 | int alt; | 876 | struct usb_host_interface *alt; |
| 877 | 877 | ||
| 878 | alt = uas_find_uas_alt_setting(intf); | 878 | alt = uas_find_uas_alt_setting(intf); |
| 879 | if (alt < 0) | 879 | if (!alt) |
| 880 | return alt; | 880 | return -ENODEV; |
| 881 | 881 | ||
| 882 | return usb_set_interface(udev, | 882 | return usb_set_interface(udev, alt->desc.bInterfaceNumber, |
| 883 | intf->altsetting[0].desc.bInterfaceNumber, alt); | 883 | alt->desc.bAlternateSetting); |
| 884 | } | 884 | } |
| 885 | 885 | ||
| 886 | static int uas_configure_endpoints(struct uas_dev_info *devinfo) | 886 | static int uas_configure_endpoints(struct uas_dev_info *devinfo) |
| @@ -1459,6 +1459,13 @@ UNUSUAL_DEV( 0x0bc2, 0x3010, 0x0000, 0x0000, · 1458 unmodified lines | |||
| 1459 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | 1459 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, |
| 1460 | US_FL_SANE_SENSE ), | 1460 | US_FL_SANE_SENSE ), |
| 1461 | 1461 | ||
| 1462 | /* Reported by Kris Lindgren <kris.lindgren@gmail.com> */ | ||
| 1463 | UNUSUAL_DEV( 0x0bc2, 0x3332, 0x0000, 0x9999, | ||
| 1464 | "Seagate", | ||
| 1465 | "External", | ||
| 1466 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | ||
| 1467 | US_FL_NO_WP_DETECT ), | ||
| 1468 | |||
| 1462 | UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999, | 1469 | UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999, |
| 1463 | "Maxtor", | 1470 | "Maxtor", |
| 1464 | "USB to SATA", | 1471 | "USB to SATA", |
| @@ -825,6 +825,8 @@ static int hwarc_probe(struct usb_interface *iface, · 824 unmodified lines | |||
| 825 | 825 | ||
| 826 | if (iface->cur_altsetting->desc.bNumEndpoints < 1) | 826 | if (iface->cur_altsetting->desc.bNumEndpoints < 1) |
| 827 | return -ENODEV; | 827 | return -ENODEV; |
| 828 | if (!usb_endpoint_xfer_int(&iface->cur_altsetting->endpoint[0].desc)) | ||
| 829 | return -ENODEV; | ||
| 828 | 830 | ||
| 829 | result = -ENOMEM; | 831 | result = -ENOMEM; |
| 830 | uwb_rc = uwb_rc_alloc(); | 832 | uwb_rc = uwb_rc_alloc(); |
| @@ -302,18 +302,22 @@ static int uwbd(void *param) · 301 unmodified lines | |||
| 302 | /** Start the UWB daemon */ | 302 | /** Start the UWB daemon */ |
| 303 | void uwbd_start(struct uwb_rc *rc) | 303 | void uwbd_start(struct uwb_rc *rc) |
| 304 | { | 304 | { |
| 305 | rc->uwbd.task = kthread_run(uwbd, rc, "uwbd"); | 305 | struct task_struct *task = kthread_run(uwbd, rc, "uwbd"); |
| 306 | if (rc->uwbd.task == NULL) | 306 | if (IS_ERR(task)) { |
| 307 | rc->uwbd.task = NULL; | ||
| 307 | printk(KERN_ERR "UWB: Cannot start management daemon; " | 308 | printk(KERN_ERR "UWB: Cannot start management daemon; " |
| 308 | "UWB won't work\n"); | 309 | "UWB won't work\n"); |
| 309 | else | 310 | } else { |
| 311 | rc->uwbd.task = task; | ||
| 310 | rc->uwbd.pid = rc->uwbd.task->pid; | 312 | rc->uwbd.pid = rc->uwbd.task->pid; |
| 313 | } | ||
| 311 | } | 314 | } |
| 312 | 315 | ||
| 313 | /* Stop the UWB daemon and free any unprocessed events */ | 316 | /* Stop the UWB daemon and free any unprocessed events */ |
| 314 | void uwbd_stop(struct uwb_rc *rc) | 317 | void uwbd_stop(struct uwb_rc *rc) |
| 315 | { | 318 | { |
| 316 | kthread_stop(rc->uwbd.task); | 319 | if (rc->uwbd.task) |
| 320 | kthread_stop(rc->uwbd.task); | ||
| 317 | uwbd_flush(rc); | 321 | uwbd_flush(rc); |
| 318 | } | 322 | } |
| 319 | 323 | ||
| @@ -780,6 +780,7 @@ struct usb_interface_assoc_descriptor { · 779 unmodified lines | |||
| 780 | __u8 iFunction; | 780 | __u8 iFunction; |
| 781 | } __attribute__ ((packed)); | 781 | } __attribute__ ((packed)); |
| 782 | 782 | ||
| 783 | #define USB_DT_INTERFACE_ASSOCIATION_SIZE 8 | ||
| 783 | 784 | ||
| 784 | /*-------------------------------------------------------------------------*/ | 785 | /*-------------------------------------------------------------------------*/ |
| 785 | 786 | ||