Merge tag 'usb-5.7-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB fixes from Greg KH:
"Here are a number of USB fixes for 5.7-rc6

The "largest" in here is a bunch of raw-gadget fixes and api changes
as the driver just showed up in -rc1 and work has been done to fix up
some uapi issues found with the original submission, before it shows
up in a -final release.

Other than that, a bunch of other small USB gadget fixes, xhci fixes,
some quirks, andother tiny fixes for reported issues.

All of these have been in linux-next with no reported issues"

* tag 'usb-5.7-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (26 commits)
USB: gadget: fix illegal array access in binding with UDC
usb: core: hub: limit HUB_QUIRK_DISABLE_AUTOSUSPEND to USB5534B
USB: usbfs: fix mmap dma mismatch
usb: host: xhci-plat: keep runtime active when removing host
usb: xhci: Fix NULL pointer dereference when enqueuing trbs from urb sg list
usb: cdns3: gadget: make a bunch of functions static
usb: mtu3: constify struct debugfs_reg32
usb: gadget: udc: atmel: Make some symbols static
usb: raw-gadget: fix null-ptr-deref when reenabling endpoints
usb: raw-gadget: documentation updates
usb: raw-gadget: support stalling/halting/wedging endpoints
usb: raw-gadget: fix gadget endpoint selection
usb: raw-gadget: improve uapi headers comments
usb: typec: mux: intel: Fix DP_HPD_LVL bit field
usb: raw-gadget: fix return value of ep read ioctls
usb: dwc3: select USB_ROLE_SWITCH
usb: gadget: legacy: fix error return code in gncm_bind()
usb: gadget: legacy: fix error return code in cdc_bind()
usb: gadget: legacy: fix redundant initialization warnings
usb: gadget: tegra-xudc: Fix idle suspend/resume
...

+448 -123
+30 -7
Documentation/usb/raw-gadget.rst
··· 27 3. Raw Gadget provides a way to select a UDC device/driver to bind to, 28 while GadgetFS currently binds to the first available UDC. 29 30 - 4. Raw Gadget uses predictable endpoint names (handles) across different 31 - UDCs (as long as UDCs have enough endpoints of each required transfer 32 - type). 33 34 5. Raw Gadget has ioctl-based interface instead of a filesystem-based one. 35 ··· 49 Raw Gadget and react to those depending on what kind of USB device 50 needs to be emulated. 51 52 Potential future improvements 53 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 54 55 - - Implement ioctl's for setting/clearing halt status on endpoints. 56 - 57 - - Reporting more events (suspend, resume, etc.) through 58 - USB_RAW_IOCTL_EVENT_FETCH. 59 60 - Support O_NONBLOCK I/O.
··· 27 3. Raw Gadget provides a way to select a UDC device/driver to bind to, 28 while GadgetFS currently binds to the first available UDC. 29 30 + 4. Raw Gadget explicitly exposes information about endpoints addresses and 31 + capabilities allowing a user to write UDC-agnostic gadgets. 32 33 5. Raw Gadget has ioctl-based interface instead of a filesystem-based one. 34 ··· 50 Raw Gadget and react to those depending on what kind of USB device 51 needs to be emulated. 52 53 + Note, that some UDC drivers have fixed addresses assigned to endpoints, and 54 + therefore arbitrary endpoint addresses can't be used in the descriptors. 55 + Nevertheles, Raw Gadget provides a UDC-agnostic way to write USB gadgets. 56 + Once a USB_RAW_EVENT_CONNECT event is received via USB_RAW_IOCTL_EVENT_FETCH, 57 + the USB_RAW_IOCTL_EPS_INFO ioctl can be used to find out information about 58 + endpoints that the UDC driver has. Based on that information, the user must 59 + chose UDC endpoints that will be used for the gadget being emulated, and 60 + properly assign addresses in endpoint descriptors. 61 + 62 + You can find usage examples (along with a test suite) here: 63 + 64 + https://github.com/xairy/raw-gadget 65 + 66 + Internal details 67 + ~~~~~~~~~~~~~~~~ 68 + 69 + Currently every endpoint read/write ioctl submits a USB request and waits until 70 + its completion. This is the desired mode for coverage-guided fuzzing (as we'd 71 + like all USB request processing happen during the lifetime of a syscall), 72 + and must be kept in the implementation. (This might be slow for real world 73 + applications, thus the O_NONBLOCK improvement suggestion below.) 74 + 75 Potential future improvements 76 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 77 78 + - Report more events (suspend, resume, etc.) through USB_RAW_IOCTL_EVENT_FETCH. 79 80 - Support O_NONBLOCK I/O. 81 + 82 + - Support USB 3 features (accept SS endpoint companion descriptor when 83 + enabling endpoints; allow providing stream_id for bulk transfers). 84 + 85 + - Support ISO transfer features (expose frame_number for completed requests).
+11 -11
drivers/usb/cdns3/gadget.c
··· 82 * @ptr: address of device controller register to be read and changed 83 * @mask: bits requested to clar 84 */ 85 - void cdns3_clear_register_bit(void __iomem *ptr, u32 mask) 86 { 87 mask = readl(ptr) & ~mask; 88 writel(mask, ptr); ··· 137 * 138 * Returns buffer or NULL if no buffers in list 139 */ 140 - struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) 141 { 142 return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); 143 } ··· 148 * 149 * Returns request or NULL if no requests in list 150 */ 151 - struct cdns3_request *cdns3_next_priv_request(struct list_head *list) 152 { 153 return list_first_entry_or_null(list, struct cdns3_request, list); 154 } ··· 190 return priv_ep->trb_pool_dma + offset; 191 } 192 193 - int cdns3_ring_size(struct cdns3_endpoint *priv_ep) 194 { 195 switch (priv_ep->type) { 196 case USB_ENDPOINT_XFER_ISOC: ··· 345 cdns3_ep_inc_trb(&priv_ep->dequeue, &priv_ep->ccs, priv_ep->num_trbs); 346 } 347 348 - void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req) 349 { 350 struct cdns3_endpoint *priv_ep = priv_req->priv_ep; 351 int current_trb = priv_req->start_trb; ··· 511 } 512 } 513 514 - struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev, 515 struct cdns3_endpoint *priv_ep, 516 struct cdns3_request *priv_req) 517 { ··· 551 return &priv_req->request; 552 } 553 554 - int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev, 555 struct cdns3_endpoint *priv_ep, 556 struct cdns3_request *priv_req) 557 { ··· 836 cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); 837 } 838 839 - void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep) 840 { 841 /* Work around for stale data address in TRB*/ 842 if (priv_ep->wa1_set) { ··· 1904 return 0; 1905 } 1906 1907 - void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev, 1908 struct cdns3_endpoint *priv_ep) 1909 { 1910 if (!priv_ep->use_streams || priv_dev->gadget.speed < USB_SPEED_SUPER) ··· 1925 EP_CFG_TDL_CHK | EP_CFG_SID_CHK); 1926 } 1927 1928 - void cdns3_configure_dmult(struct cdns3_device *priv_dev, 1929 struct cdns3_endpoint *priv_ep) 1930 { 1931 struct cdns3_usb_regs __iomem *regs = priv_dev->regs; ··· 2548 link_trb = priv_req->trb; 2549 2550 /* Update ring only if removed request is on pending_req_list list */ 2551 - if (req_on_hw_ring) { 2552 link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma + 2553 ((priv_req->end_trb + 1) * TRB_SIZE)); 2554 link_trb->control = (link_trb->control & TRB_CYCLE) |
··· 82 * @ptr: address of device controller register to be read and changed 83 * @mask: bits requested to clar 84 */ 85 + static void cdns3_clear_register_bit(void __iomem *ptr, u32 mask) 86 { 87 mask = readl(ptr) & ~mask; 88 writel(mask, ptr); ··· 137 * 138 * Returns buffer or NULL if no buffers in list 139 */ 140 + static struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) 141 { 142 return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); 143 } ··· 148 * 149 * Returns request or NULL if no requests in list 150 */ 151 + static struct cdns3_request *cdns3_next_priv_request(struct list_head *list) 152 { 153 return list_first_entry_or_null(list, struct cdns3_request, list); 154 } ··· 190 return priv_ep->trb_pool_dma + offset; 191 } 192 193 + static int cdns3_ring_size(struct cdns3_endpoint *priv_ep) 194 { 195 switch (priv_ep->type) { 196 case USB_ENDPOINT_XFER_ISOC: ··· 345 cdns3_ep_inc_trb(&priv_ep->dequeue, &priv_ep->ccs, priv_ep->num_trbs); 346 } 347 348 + static void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req) 349 { 350 struct cdns3_endpoint *priv_ep = priv_req->priv_ep; 351 int current_trb = priv_req->start_trb; ··· 511 } 512 } 513 514 + static struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev, 515 struct cdns3_endpoint *priv_ep, 516 struct cdns3_request *priv_req) 517 { ··· 551 return &priv_req->request; 552 } 553 554 + static int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev, 555 struct cdns3_endpoint *priv_ep, 556 struct cdns3_request *priv_req) 557 { ··· 836 cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); 837 } 838 839 + static void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep) 840 { 841 /* Work around for stale data address in TRB*/ 842 if (priv_ep->wa1_set) { ··· 1904 return 0; 1905 } 1906 1907 + static void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev, 1908 struct cdns3_endpoint *priv_ep) 1909 { 1910 if (!priv_ep->use_streams || priv_dev->gadget.speed < USB_SPEED_SUPER) ··· 1925 EP_CFG_TDL_CHK | EP_CFG_SID_CHK); 1926 } 1927 1928 + static void cdns3_configure_dmult(struct cdns3_device *priv_dev, 1929 struct cdns3_endpoint *priv_ep) 1930 { 1931 struct cdns3_usb_regs __iomem *regs = priv_dev->regs; ··· 2548 link_trb = priv_req->trb; 2549 2550 /* Update ring only if removed request is on pending_req_list list */ 2551 + if (req_on_hw_ring && link_trb) { 2552 link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma + 2553 ((priv_req->end_trb + 1) * TRB_SIZE)); 2554 link_trb->control = (link_trb->control & TRB_CYCLE) |
+13 -3
drivers/usb/core/devio.c
··· 251 usbm->vma_use_count = 1; 252 INIT_LIST_HEAD(&usbm->memlist); 253 254 - if (dma_mmap_coherent(hcd->self.sysdev, vma, mem, dma_handle, size)) { 255 - dec_usb_memory_use_count(usbm, &usbm->vma_use_count); 256 - return -EAGAIN; 257 } 258 259 vma->vm_flags |= VM_IO;
··· 251 usbm->vma_use_count = 1; 252 INIT_LIST_HEAD(&usbm->memlist); 253 254 + if (hcd->localmem_pool || !hcd_uses_dma(hcd)) { 255 + if (remap_pfn_range(vma, vma->vm_start, 256 + virt_to_phys(usbm->mem) >> PAGE_SHIFT, 257 + size, vma->vm_page_prot) < 0) { 258 + dec_usb_memory_use_count(usbm, &usbm->vma_use_count); 259 + return -EAGAIN; 260 + } 261 + } else { 262 + if (dma_mmap_coherent(hcd->self.sysdev, vma, mem, dma_handle, 263 + size)) { 264 + dec_usb_memory_use_count(usbm, &usbm->vma_use_count); 265 + return -EAGAIN; 266 + } 267 } 268 269 vma->vm_flags |= VM_IO;
+5 -1
drivers/usb/core/hub.c
··· 39 40 #define USB_VENDOR_GENESYS_LOGIC 0x05e3 41 #define USB_VENDOR_SMSC 0x0424 42 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 43 #define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02 44 ··· 5622 } 5623 5624 static const struct usb_device_id hub_id_table[] = { 5625 - { .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_CLASS, 5626 .idVendor = USB_VENDOR_SMSC, 5627 .bInterfaceClass = USB_CLASS_HUB, 5628 .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, 5629 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR
··· 39 40 #define USB_VENDOR_GENESYS_LOGIC 0x05e3 41 #define USB_VENDOR_SMSC 0x0424 42 + #define USB_PRODUCT_USB5534B 0x5534 43 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 44 #define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02 45 ··· 5621 } 5622 5623 static const struct usb_device_id hub_id_table[] = { 5624 + { .match_flags = USB_DEVICE_ID_MATCH_VENDOR 5625 + | USB_DEVICE_ID_MATCH_PRODUCT 5626 + | USB_DEVICE_ID_MATCH_INT_CLASS, 5627 .idVendor = USB_VENDOR_SMSC, 5628 + .idProduct = USB_PRODUCT_USB5534B, 5629 .bInterfaceClass = USB_CLASS_HUB, 5630 .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, 5631 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR
+1
drivers/usb/dwc3/Kconfig
··· 4 tristate "DesignWare USB3 DRD Core Support" 5 depends on (USB || USB_GADGET) && HAS_DMA 6 select USB_XHCI_PLATFORM if USB_XHCI_HCD 7 help 8 Say Y or M here if your system has a Dual Role SuperSpeed 9 USB controller based on the DesignWare USB3 IP Core.
··· 4 tristate "DesignWare USB3 DRD Core Support" 5 depends on (USB || USB_GADGET) && HAS_DMA 6 select USB_XHCI_PLATFORM if USB_XHCI_HCD 7 + select USB_ROLE_SWITCH if USB_DWC3_DUAL_ROLE 8 help 9 Say Y or M here if your system has a Dual Role SuperSpeed 10 USB controller based on the DesignWare USB3 IP Core.
+1
drivers/usb/dwc3/dwc3-pci.c
··· 114 115 static const struct property_entry dwc3_pci_mrfld_properties[] = { 116 PROPERTY_ENTRY_STRING("dr_mode", "otg"), 117 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 118 {} 119 };
··· 114 115 static const struct property_entry dwc3_pci_mrfld_properties[] = { 116 PROPERTY_ENTRY_STRING("dr_mode", "otg"), 117 + PROPERTY_ENTRY_STRING("linux,extcon-name", "mrfld_bcove_pwrsrc"), 118 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 119 {} 120 };
-3
drivers/usb/dwc3/gadget.c
··· 2483 for_each_sg(sg, s, pending, i) { 2484 trb = &dep->trb_pool[dep->trb_dequeue]; 2485 2486 - if (trb->ctrl & DWC3_TRB_CTRL_HWO) 2487 - break; 2488 - 2489 req->sg = sg_next(s); 2490 req->num_pending_sgs--; 2491
··· 2483 for_each_sg(sg, s, pending, i) { 2484 trb = &dep->trb_pool[dep->trb_dequeue]; 2485 2486 req->sg = sg_next(s); 2487 req->num_pending_sgs--; 2488
+3
drivers/usb/gadget/configfs.c
··· 260 char *name; 261 int ret; 262 263 name = kstrdup(page, GFP_KERNEL); 264 if (!name) 265 return -ENOMEM;
··· 260 char *name; 261 int ret; 262 263 + if (strlen(page) < len) 264 + return -EOVERFLOW; 265 + 266 name = kstrdup(page, GFP_KERNEL); 267 if (!name) 268 return -ENOMEM;
+3 -1
drivers/usb/gadget/legacy/audio.c
··· 300 struct usb_descriptor_header *usb_desc; 301 302 usb_desc = usb_otg_descriptor_alloc(cdev->gadget); 303 - if (!usb_desc) 304 goto fail; 305 usb_otg_descriptor_init(cdev->gadget, usb_desc); 306 otg_desc[0] = usb_desc; 307 otg_desc[1] = NULL;
··· 300 struct usb_descriptor_header *usb_desc; 301 302 usb_desc = usb_otg_descriptor_alloc(cdev->gadget); 303 + if (!usb_desc) { 304 + status = -ENOMEM; 305 goto fail; 306 + } 307 usb_otg_descriptor_init(cdev->gadget, usb_desc); 308 otg_desc[0] = usb_desc; 309 otg_desc[1] = NULL;
+3 -1
drivers/usb/gadget/legacy/cdc2.c
··· 179 struct usb_descriptor_header *usb_desc; 180 181 usb_desc = usb_otg_descriptor_alloc(gadget); 182 - if (!usb_desc) 183 goto fail1; 184 usb_otg_descriptor_init(gadget, usb_desc); 185 otg_desc[0] = usb_desc; 186 otg_desc[1] = NULL;
··· 179 struct usb_descriptor_header *usb_desc; 180 181 usb_desc = usb_otg_descriptor_alloc(gadget); 182 + if (!usb_desc) { 183 + status = -ENOMEM; 184 goto fail1; 185 + } 186 usb_otg_descriptor_init(gadget, usb_desc); 187 otg_desc[0] = usb_desc; 188 otg_desc[1] = NULL;
+1 -2
drivers/usb/gadget/legacy/inode.c
··· 1361 1362 req->buf = dev->rbuf; 1363 req->context = NULL; 1364 - value = -EOPNOTSUPP; 1365 switch (ctrl->bRequest) { 1366 1367 case USB_REQ_GET_DESCRIPTOR: ··· 1783 dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) 1784 { 1785 struct dev_data *dev = fd->private_data; 1786 - ssize_t value = len, length = len; 1787 unsigned total; 1788 u32 tag; 1789 char *kbuf;
··· 1361 1362 req->buf = dev->rbuf; 1363 req->context = NULL; 1364 switch (ctrl->bRequest) { 1365 1366 case USB_REQ_GET_DESCRIPTOR: ··· 1784 dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) 1785 { 1786 struct dev_data *dev = fd->private_data; 1787 + ssize_t value, length = len; 1788 unsigned total; 1789 u32 tag; 1790 char *kbuf;
+3 -1
drivers/usb/gadget/legacy/ncm.c
··· 156 struct usb_descriptor_header *usb_desc; 157 158 usb_desc = usb_otg_descriptor_alloc(gadget); 159 - if (!usb_desc) 160 goto fail; 161 usb_otg_descriptor_init(gadget, usb_desc); 162 otg_desc[0] = usb_desc; 163 otg_desc[1] = NULL;
··· 156 struct usb_descriptor_header *usb_desc; 157 158 usb_desc = usb_otg_descriptor_alloc(gadget); 159 + if (!usb_desc) { 160 + status = -ENOMEM; 161 goto fail; 162 + } 163 usb_otg_descriptor_init(gadget, usb_desc); 164 otg_desc[0] = usb_desc; 165 otg_desc[1] = NULL;
+252 -63
drivers/usb/gadget/legacy/raw_gadget.c
··· 7 */ 8 9 #include <linux/compiler.h> 10 #include <linux/debugfs.h> 11 #include <linux/delay.h> 12 #include <linux/kref.h> ··· 124 125 struct raw_dev; 126 127 - #define USB_RAW_MAX_ENDPOINTS 32 128 - 129 enum ep_state { 130 STATE_EP_DISABLED, 131 STATE_EP_ENABLED, ··· 133 struct raw_dev *dev; 134 enum ep_state state; 135 struct usb_ep *ep; 136 struct usb_request *req; 137 bool urb_queued; 138 bool disabling; ··· 168 bool ep0_out_pending; 169 bool ep0_urb_queued; 170 ssize_t ep0_status; 171 - struct raw_ep eps[USB_RAW_MAX_ENDPOINTS]; 172 173 struct completion ep0_done; 174 struct raw_event_queue queue; ··· 203 usb_ep_free_request(dev->gadget->ep0, dev->req); 204 } 205 raw_event_queue_destroy(&dev->queue); 206 - for (i = 0; i < USB_RAW_MAX_ENDPOINTS; i++) { 207 - if (dev->eps[i].state != STATE_EP_ENABLED) 208 continue; 209 usb_ep_disable(dev->eps[i].ep); 210 usb_ep_free_request(dev->eps[i].ep, dev->eps[i].req); ··· 250 complete(&dev->ep0_done); 251 } 252 253 static int gadget_bind(struct usb_gadget *gadget, 254 struct usb_gadget_driver *driver) 255 { 256 - int ret = 0; 257 struct raw_dev *dev = container_of(driver, struct raw_dev, driver); 258 struct usb_request *req; 259 unsigned long flags; 260 261 if (strcmp(gadget->name, dev->udc_name) != 0) ··· 288 dev->req->context = dev; 289 dev->req->complete = gadget_ep0_complete; 290 dev->gadget = gadget; 291 spin_unlock_irqrestore(&dev->lock, flags); 292 293 /* Matches kref_put() in gadget_unbind(). */ ··· 577 578 if (copy_from_user(io, ptr, sizeof(*io))) 579 return ERR_PTR(-EFAULT); 580 - if (io->ep >= USB_RAW_MAX_ENDPOINTS) 581 return ERR_PTR(-EINVAL); 582 if (!usb_raw_io_flags_valid(io->flags)) 583 return ERR_PTR(-EINVAL); ··· 691 if (IS_ERR(data)) 692 return PTR_ERR(data); 693 ret = raw_process_ep0_io(dev, &io, data, false); 694 - if (ret) 695 goto free; 696 697 length = min(io.length, (unsigned int)ret); 698 if (copy_to_user((void __user *)(value + sizeof(io)), data, length)) 699 ret = -EFAULT; 700 free: 701 kfree(data); 702 return ret; 703 } 704 705 - static bool check_ep_caps(struct usb_ep *ep, 706 - struct usb_endpoint_descriptor *desc) 707 { 708 - switch (usb_endpoint_type(desc)) { 709 - case USB_ENDPOINT_XFER_ISOC: 710 - if (!ep->caps.type_iso) 711 - return false; 712 - break; 713 - case USB_ENDPOINT_XFER_BULK: 714 - if (!ep->caps.type_bulk) 715 - return false; 716 - break; 717 - case USB_ENDPOINT_XFER_INT: 718 - if (!ep->caps.type_int) 719 - return false; 720 - break; 721 - default: 722 - return false; 723 } 724 725 - if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in) 726 - return false; 727 - if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out) 728 - return false; 729 730 - return true; 731 } 732 733 static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) ··· 753 int ret = 0, i; 754 unsigned long flags; 755 struct usb_endpoint_descriptor *desc; 756 - struct usb_ep *ep = NULL; 757 758 desc = memdup_user((void __user *)value, sizeof(*desc)); 759 if (IS_ERR(desc)) ··· 781 goto out_free; 782 } 783 784 - for (i = 0; i < USB_RAW_MAX_ENDPOINTS; i++) { 785 - if (dev->eps[i].state == STATE_EP_ENABLED) 786 continue; 787 - break; 788 - } 789 - if (i == USB_RAW_MAX_ENDPOINTS) { 790 - dev_dbg(&dev->gadget->dev, 791 - "fail, no device endpoints available\n"); 792 - ret = -EBUSY; 793 - goto out_free; 794 - } 795 - 796 - gadget_for_each_ep(ep, dev->gadget) { 797 - if (ep->enabled) 798 continue; 799 - if (!check_ep_caps(ep, desc)) 800 continue; 801 - ep->desc = desc; 802 - ret = usb_ep_enable(ep); 803 if (ret < 0) { 804 dev_err(&dev->gadget->dev, 805 "fail, usb_ep_enable returned %d\n", ret); 806 goto out_free; 807 } 808 - dev->eps[i].req = usb_ep_alloc_request(ep, GFP_ATOMIC); 809 - if (!dev->eps[i].req) { 810 dev_err(&dev->gadget->dev, 811 "fail, usb_ep_alloc_request failed\n"); 812 - usb_ep_disable(ep); 813 ret = -ENOMEM; 814 goto out_free; 815 } 816 - dev->eps[i].ep = ep; 817 - dev->eps[i].state = STATE_EP_ENABLED; 818 - ep->driver_data = &dev->eps[i]; 819 ret = i; 820 goto out_unlock; 821 } ··· 825 { 826 int ret = 0, i = value; 827 unsigned long flags; 828 - const void *desc; 829 - 830 - if (i < 0 || i >= USB_RAW_MAX_ENDPOINTS) 831 - return -EINVAL; 832 833 spin_lock_irqsave(&dev->lock, flags); 834 if (dev->state != STATE_DEV_RUNNING) { ··· 837 ret = -EBUSY; 838 goto out_unlock; 839 } 840 - if (dev->eps[i].state != STATE_EP_ENABLED) { 841 dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n"); 842 ret = -EINVAL; 843 goto out_unlock; ··· 866 867 spin_lock_irqsave(&dev->lock, flags); 868 usb_ep_free_request(dev->eps[i].ep, dev->eps[i].req); 869 - desc = dev->eps[i].ep->desc; 870 - dev->eps[i].ep = NULL; 871 dev->eps[i].state = STATE_EP_DISABLED; 872 - kfree(desc); 873 dev->eps[i].disabling = false; 874 875 out_unlock: 876 spin_unlock_irqrestore(&dev->lock, flags); ··· 964 { 965 int ret = 0; 966 unsigned long flags; 967 - struct raw_ep *ep = &dev->eps[io->ep]; 968 DECLARE_COMPLETION_ONSTACK(done); 969 970 spin_lock_irqsave(&dev->lock, flags); ··· 978 ret = -EBUSY; 979 goto out_unlock; 980 } 981 if (ep->state != STATE_EP_ENABLED) { 982 dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n"); 983 ret = -EBUSY; ··· 1068 if (IS_ERR(data)) 1069 return PTR_ERR(data); 1070 ret = raw_process_ep_io(dev, &io, data, false); 1071 - if (ret) 1072 goto free; 1073 1074 length = min(io.length, (unsigned int)ret); 1075 if (copy_to_user((void __user *)(value + sizeof(io)), data, length)) 1076 ret = -EFAULT; 1077 free: 1078 kfree(data); 1079 return ret; ··· 1129 return ret; 1130 } 1131 1132 static long raw_ioctl(struct file *fd, unsigned int cmd, unsigned long value) 1133 { 1134 struct raw_dev *dev = fd->private_data; ··· 1235 break; 1236 case USB_RAW_IOCTL_VBUS_DRAW: 1237 ret = raw_ioctl_vbus_draw(dev, value); 1238 break; 1239 default: 1240 ret = -EINVAL;
··· 7 */ 8 9 #include <linux/compiler.h> 10 + #include <linux/ctype.h> 11 #include <linux/debugfs.h> 12 #include <linux/delay.h> 13 #include <linux/kref.h> ··· 123 124 struct raw_dev; 125 126 enum ep_state { 127 STATE_EP_DISABLED, 128 STATE_EP_ENABLED, ··· 134 struct raw_dev *dev; 135 enum ep_state state; 136 struct usb_ep *ep; 137 + u8 addr; 138 struct usb_request *req; 139 bool urb_queued; 140 bool disabling; ··· 168 bool ep0_out_pending; 169 bool ep0_urb_queued; 170 ssize_t ep0_status; 171 + struct raw_ep eps[USB_RAW_EPS_NUM_MAX]; 172 + int eps_num; 173 174 struct completion ep0_done; 175 struct raw_event_queue queue; ··· 202 usb_ep_free_request(dev->gadget->ep0, dev->req); 203 } 204 raw_event_queue_destroy(&dev->queue); 205 + for (i = 0; i < dev->eps_num; i++) { 206 + if (dev->eps[i].state == STATE_EP_DISABLED) 207 continue; 208 usb_ep_disable(dev->eps[i].ep); 209 usb_ep_free_request(dev->eps[i].ep, dev->eps[i].req); ··· 249 complete(&dev->ep0_done); 250 } 251 252 + static u8 get_ep_addr(const char *name) 253 + { 254 + /* If the endpoint has fixed function (named as e.g. "ep12out-bulk"), 255 + * parse the endpoint address from its name. We deliberately use 256 + * deprecated simple_strtoul() function here, as the number isn't 257 + * followed by '\0' nor '\n'. 258 + */ 259 + if (isdigit(name[2])) 260 + return simple_strtoul(&name[2], NULL, 10); 261 + /* Otherwise the endpoint is configurable (named as e.g. "ep-a"). */ 262 + return USB_RAW_EP_ADDR_ANY; 263 + } 264 + 265 static int gadget_bind(struct usb_gadget *gadget, 266 struct usb_gadget_driver *driver) 267 { 268 + int ret = 0, i = 0; 269 struct raw_dev *dev = container_of(driver, struct raw_dev, driver); 270 struct usb_request *req; 271 + struct usb_ep *ep; 272 unsigned long flags; 273 274 if (strcmp(gadget->name, dev->udc_name) != 0) ··· 273 dev->req->context = dev; 274 dev->req->complete = gadget_ep0_complete; 275 dev->gadget = gadget; 276 + gadget_for_each_ep(ep, dev->gadget) { 277 + dev->eps[i].ep = ep; 278 + dev->eps[i].addr = get_ep_addr(ep->name); 279 + dev->eps[i].state = STATE_EP_DISABLED; 280 + i++; 281 + } 282 + dev->eps_num = i; 283 spin_unlock_irqrestore(&dev->lock, flags); 284 285 /* Matches kref_put() in gadget_unbind(). */ ··· 555 556 if (copy_from_user(io, ptr, sizeof(*io))) 557 return ERR_PTR(-EFAULT); 558 + if (io->ep >= USB_RAW_EPS_NUM_MAX) 559 return ERR_PTR(-EINVAL); 560 if (!usb_raw_io_flags_valid(io->flags)) 561 return ERR_PTR(-EINVAL); ··· 669 if (IS_ERR(data)) 670 return PTR_ERR(data); 671 ret = raw_process_ep0_io(dev, &io, data, false); 672 + if (ret < 0) 673 goto free; 674 675 length = min(io.length, (unsigned int)ret); 676 if (copy_to_user((void __user *)(value + sizeof(io)), data, length)) 677 ret = -EFAULT; 678 + else 679 + ret = length; 680 free: 681 kfree(data); 682 return ret; 683 } 684 685 + static int raw_ioctl_ep0_stall(struct raw_dev *dev, unsigned long value) 686 { 687 + int ret = 0; 688 + unsigned long flags; 689 + 690 + if (value) 691 + return -EINVAL; 692 + spin_lock_irqsave(&dev->lock, flags); 693 + if (dev->state != STATE_DEV_RUNNING) { 694 + dev_dbg(dev->dev, "fail, device is not running\n"); 695 + ret = -EINVAL; 696 + goto out_unlock; 697 + } 698 + if (!dev->gadget) { 699 + dev_dbg(dev->dev, "fail, gadget is not bound\n"); 700 + ret = -EBUSY; 701 + goto out_unlock; 702 + } 703 + if (dev->ep0_urb_queued) { 704 + dev_dbg(&dev->gadget->dev, "fail, urb already queued\n"); 705 + ret = -EBUSY; 706 + goto out_unlock; 707 + } 708 + if (!dev->ep0_in_pending && !dev->ep0_out_pending) { 709 + dev_dbg(&dev->gadget->dev, "fail, no request pending\n"); 710 + ret = -EBUSY; 711 + goto out_unlock; 712 } 713 714 + ret = usb_ep_set_halt(dev->gadget->ep0); 715 + if (ret < 0) 716 + dev_err(&dev->gadget->dev, 717 + "fail, usb_ep_set_halt returned %d\n", ret); 718 719 + if (dev->ep0_in_pending) 720 + dev->ep0_in_pending = false; 721 + else 722 + dev->ep0_out_pending = false; 723 + 724 + out_unlock: 725 + spin_unlock_irqrestore(&dev->lock, flags); 726 + return ret; 727 } 728 729 static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) ··· 713 int ret = 0, i; 714 unsigned long flags; 715 struct usb_endpoint_descriptor *desc; 716 + struct raw_ep *ep; 717 718 desc = memdup_user((void __user *)value, sizeof(*desc)); 719 if (IS_ERR(desc)) ··· 741 goto out_free; 742 } 743 744 + for (i = 0; i < dev->eps_num; i++) { 745 + ep = &dev->eps[i]; 746 + if (ep->state != STATE_EP_DISABLED) 747 continue; 748 + if (ep->addr != usb_endpoint_num(desc) && 749 + ep->addr != USB_RAW_EP_ADDR_ANY) 750 continue; 751 + if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL)) 752 continue; 753 + ep->ep->desc = desc; 754 + ret = usb_ep_enable(ep->ep); 755 if (ret < 0) { 756 dev_err(&dev->gadget->dev, 757 "fail, usb_ep_enable returned %d\n", ret); 758 goto out_free; 759 } 760 + ep->req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC); 761 + if (!ep->req) { 762 dev_err(&dev->gadget->dev, 763 "fail, usb_ep_alloc_request failed\n"); 764 + usb_ep_disable(ep->ep); 765 ret = -ENOMEM; 766 goto out_free; 767 } 768 + ep->state = STATE_EP_ENABLED; 769 + ep->ep->driver_data = ep; 770 ret = i; 771 goto out_unlock; 772 } ··· 794 { 795 int ret = 0, i = value; 796 unsigned long flags; 797 798 spin_lock_irqsave(&dev->lock, flags); 799 if (dev->state != STATE_DEV_RUNNING) { ··· 810 ret = -EBUSY; 811 goto out_unlock; 812 } 813 + if (i < 0 || i >= dev->eps_num) { 814 + dev_dbg(dev->dev, "fail, invalid endpoint\n"); 815 + ret = -EBUSY; 816 + goto out_unlock; 817 + } 818 + if (dev->eps[i].state == STATE_EP_DISABLED) { 819 dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n"); 820 ret = -EINVAL; 821 goto out_unlock; ··· 834 835 spin_lock_irqsave(&dev->lock, flags); 836 usb_ep_free_request(dev->eps[i].ep, dev->eps[i].req); 837 + kfree(dev->eps[i].ep->desc); 838 dev->eps[i].state = STATE_EP_DISABLED; 839 dev->eps[i].disabling = false; 840 + 841 + out_unlock: 842 + spin_unlock_irqrestore(&dev->lock, flags); 843 + return ret; 844 + } 845 + 846 + static int raw_ioctl_ep_set_clear_halt_wedge(struct raw_dev *dev, 847 + unsigned long value, bool set, bool halt) 848 + { 849 + int ret = 0, i = value; 850 + unsigned long flags; 851 + 852 + spin_lock_irqsave(&dev->lock, flags); 853 + if (dev->state != STATE_DEV_RUNNING) { 854 + dev_dbg(dev->dev, "fail, device is not running\n"); 855 + ret = -EINVAL; 856 + goto out_unlock; 857 + } 858 + if (!dev->gadget) { 859 + dev_dbg(dev->dev, "fail, gadget is not bound\n"); 860 + ret = -EBUSY; 861 + goto out_unlock; 862 + } 863 + if (i < 0 || i >= dev->eps_num) { 864 + dev_dbg(dev->dev, "fail, invalid endpoint\n"); 865 + ret = -EBUSY; 866 + goto out_unlock; 867 + } 868 + if (dev->eps[i].state == STATE_EP_DISABLED) { 869 + dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n"); 870 + ret = -EINVAL; 871 + goto out_unlock; 872 + } 873 + if (dev->eps[i].disabling) { 874 + dev_dbg(&dev->gadget->dev, 875 + "fail, disable is in progress\n"); 876 + ret = -EINVAL; 877 + goto out_unlock; 878 + } 879 + if (dev->eps[i].urb_queued) { 880 + dev_dbg(&dev->gadget->dev, 881 + "fail, waiting for urb completion\n"); 882 + ret = -EINVAL; 883 + goto out_unlock; 884 + } 885 + if (usb_endpoint_xfer_isoc(dev->eps[i].ep->desc)) { 886 + dev_dbg(&dev->gadget->dev, 887 + "fail, can't halt/wedge ISO endpoint\n"); 888 + ret = -EINVAL; 889 + goto out_unlock; 890 + } 891 + 892 + if (set && halt) { 893 + ret = usb_ep_set_halt(dev->eps[i].ep); 894 + if (ret < 0) 895 + dev_err(&dev->gadget->dev, 896 + "fail, usb_ep_set_halt returned %d\n", ret); 897 + } else if (!set && halt) { 898 + ret = usb_ep_clear_halt(dev->eps[i].ep); 899 + if (ret < 0) 900 + dev_err(&dev->gadget->dev, 901 + "fail, usb_ep_clear_halt returned %d\n", ret); 902 + } else if (set && !halt) { 903 + ret = usb_ep_set_wedge(dev->eps[i].ep); 904 + if (ret < 0) 905 + dev_err(&dev->gadget->dev, 906 + "fail, usb_ep_set_wedge returned %d\n", ret); 907 + } 908 909 out_unlock: 910 spin_unlock_irqrestore(&dev->lock, flags); ··· 866 { 867 int ret = 0; 868 unsigned long flags; 869 + struct raw_ep *ep; 870 DECLARE_COMPLETION_ONSTACK(done); 871 872 spin_lock_irqsave(&dev->lock, flags); ··· 880 ret = -EBUSY; 881 goto out_unlock; 882 } 883 + if (io->ep >= dev->eps_num) { 884 + dev_dbg(&dev->gadget->dev, "fail, invalid endpoint\n"); 885 + ret = -EINVAL; 886 + goto out_unlock; 887 + } 888 + ep = &dev->eps[io->ep]; 889 if (ep->state != STATE_EP_ENABLED) { 890 dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n"); 891 ret = -EBUSY; ··· 964 if (IS_ERR(data)) 965 return PTR_ERR(data); 966 ret = raw_process_ep_io(dev, &io, data, false); 967 + if (ret < 0) 968 goto free; 969 970 length = min(io.length, (unsigned int)ret); 971 if (copy_to_user((void __user *)(value + sizeof(io)), data, length)) 972 ret = -EFAULT; 973 + else 974 + ret = length; 975 free: 976 kfree(data); 977 return ret; ··· 1023 return ret; 1024 } 1025 1026 + static void fill_ep_caps(struct usb_ep_caps *caps, 1027 + struct usb_raw_ep_caps *raw_caps) 1028 + { 1029 + raw_caps->type_control = caps->type_control; 1030 + raw_caps->type_iso = caps->type_iso; 1031 + raw_caps->type_bulk = caps->type_bulk; 1032 + raw_caps->type_int = caps->type_int; 1033 + raw_caps->dir_in = caps->dir_in; 1034 + raw_caps->dir_out = caps->dir_out; 1035 + } 1036 + 1037 + static void fill_ep_limits(struct usb_ep *ep, struct usb_raw_ep_limits *limits) 1038 + { 1039 + limits->maxpacket_limit = ep->maxpacket_limit; 1040 + limits->max_streams = ep->max_streams; 1041 + } 1042 + 1043 + static int raw_ioctl_eps_info(struct raw_dev *dev, unsigned long value) 1044 + { 1045 + int ret = 0, i; 1046 + unsigned long flags; 1047 + struct usb_raw_eps_info *info; 1048 + struct raw_ep *ep; 1049 + 1050 + info = kmalloc(sizeof(*info), GFP_KERNEL); 1051 + if (!info) { 1052 + ret = -ENOMEM; 1053 + goto out; 1054 + } 1055 + 1056 + spin_lock_irqsave(&dev->lock, flags); 1057 + if (dev->state != STATE_DEV_RUNNING) { 1058 + dev_dbg(dev->dev, "fail, device is not running\n"); 1059 + ret = -EINVAL; 1060 + spin_unlock_irqrestore(&dev->lock, flags); 1061 + goto out_free; 1062 + } 1063 + if (!dev->gadget) { 1064 + dev_dbg(dev->dev, "fail, gadget is not bound\n"); 1065 + ret = -EBUSY; 1066 + spin_unlock_irqrestore(&dev->lock, flags); 1067 + goto out_free; 1068 + } 1069 + 1070 + memset(info, 0, sizeof(*info)); 1071 + for (i = 0; i < dev->eps_num; i++) { 1072 + ep = &dev->eps[i]; 1073 + strscpy(&info->eps[i].name[0], ep->ep->name, 1074 + USB_RAW_EP_NAME_MAX); 1075 + info->eps[i].addr = ep->addr; 1076 + fill_ep_caps(&ep->ep->caps, &info->eps[i].caps); 1077 + fill_ep_limits(ep->ep, &info->eps[i].limits); 1078 + } 1079 + ret = dev->eps_num; 1080 + spin_unlock_irqrestore(&dev->lock, flags); 1081 + 1082 + if (copy_to_user((void __user *)value, info, sizeof(*info))) 1083 + ret = -EFAULT; 1084 + 1085 + out_free: 1086 + kfree(info); 1087 + out: 1088 + return ret; 1089 + } 1090 + 1091 static long raw_ioctl(struct file *fd, unsigned int cmd, unsigned long value) 1092 { 1093 struct raw_dev *dev = fd->private_data; ··· 1064 break; 1065 case USB_RAW_IOCTL_VBUS_DRAW: 1066 ret = raw_ioctl_vbus_draw(dev, value); 1067 + break; 1068 + case USB_RAW_IOCTL_EPS_INFO: 1069 + ret = raw_ioctl_eps_info(dev, value); 1070 + break; 1071 + case USB_RAW_IOCTL_EP0_STALL: 1072 + ret = raw_ioctl_ep0_stall(dev, value); 1073 + break; 1074 + case USB_RAW_IOCTL_EP_SET_HALT: 1075 + ret = raw_ioctl_ep_set_clear_halt_wedge( 1076 + dev, value, true, true); 1077 + break; 1078 + case USB_RAW_IOCTL_EP_CLEAR_HALT: 1079 + ret = raw_ioctl_ep_set_clear_halt_wedge( 1080 + dev, value, false, true); 1081 + break; 1082 + case USB_RAW_IOCTL_EP_SET_WEDGE: 1083 + ret = raw_ioctl_ep_set_clear_halt_wedge( 1084 + dev, value, true, false); 1085 break; 1086 default: 1087 ret = -EINVAL;
+2 -2
drivers/usb/gadget/udc/atmel_usba_udc.c
··· 185 return 0; 186 } 187 188 - const struct file_operations queue_dbg_fops = { 189 .owner = THIS_MODULE, 190 .open = queue_dbg_open, 191 .llseek = no_llseek, ··· 193 .release = queue_dbg_release, 194 }; 195 196 - const struct file_operations regs_dbg_fops = { 197 .owner = THIS_MODULE, 198 .open = regs_dbg_open, 199 .llseek = generic_file_llseek,
··· 185 return 0; 186 } 187 188 + static const struct file_operations queue_dbg_fops = { 189 .owner = THIS_MODULE, 190 .open = queue_dbg_open, 191 .llseek = no_llseek, ··· 193 .release = queue_dbg_release, 194 }; 195 196 + static const struct file_operations regs_dbg_fops = { 197 .owner = THIS_MODULE, 198 .open = regs_dbg_open, 199 .llseek = generic_file_llseek,
+2
drivers/usb/gadget/udc/net2272.c
··· 2647 err_req: 2648 release_mem_region(base, len); 2649 err: 2650 return ret; 2651 } 2652
··· 2647 err_req: 2648 release_mem_region(base, len); 2649 err: 2650 + kfree(dev); 2651 + 2652 return ret; 2653 } 2654
+4 -4
drivers/usb/gadget/udc/tegra-xudc.c
··· 3840 3841 flush_work(&xudc->usb_role_sw_work); 3842 3843 - /* Forcibly disconnect before powergating. */ 3844 - tegra_xudc_device_mode_off(xudc); 3845 - 3846 - if (!pm_runtime_status_suspended(dev)) 3847 tegra_xudc_powergate(xudc); 3848 3849 pm_runtime_disable(dev); 3850
··· 3840 3841 flush_work(&xudc->usb_role_sw_work); 3842 3843 + if (!pm_runtime_status_suspended(dev)) { 3844 + /* Forcibly disconnect before powergating. */ 3845 + tegra_xudc_device_mode_off(xudc); 3846 tegra_xudc_powergate(xudc); 3847 + } 3848 3849 pm_runtime_disable(dev); 3850
+3 -1
drivers/usb/host/xhci-plat.c
··· 362 struct clk *reg_clk = xhci->reg_clk; 363 struct usb_hcd *shared_hcd = xhci->shared_hcd; 364 365 xhci->xhc_state |= XHCI_STATE_REMOVING; 366 367 usb_remove_hcd(shared_hcd); ··· 376 clk_disable_unprepare(reg_clk); 377 usb_put_hcd(hcd); 378 379 - pm_runtime_set_suspended(&dev->dev); 380 pm_runtime_disable(&dev->dev); 381 382 return 0; 383 }
··· 362 struct clk *reg_clk = xhci->reg_clk; 363 struct usb_hcd *shared_hcd = xhci->shared_hcd; 364 365 + pm_runtime_get_sync(&dev->dev); 366 xhci->xhc_state |= XHCI_STATE_REMOVING; 367 368 usb_remove_hcd(shared_hcd); ··· 375 clk_disable_unprepare(reg_clk); 376 usb_put_hcd(hcd); 377 378 pm_runtime_disable(&dev->dev); 379 + pm_runtime_put_noidle(&dev->dev); 380 + pm_runtime_set_suspended(&dev->dev); 381 382 return 0; 383 }
+2 -2
drivers/usb/host/xhci-ring.c
··· 3433 /* New sg entry */ 3434 --num_sgs; 3435 sent_len -= block_len; 3436 - if (num_sgs != 0) { 3437 - sg = sg_next(sg); 3438 block_len = sg_dma_len(sg); 3439 addr = (u64) sg_dma_address(sg); 3440 addr += sent_len;
··· 3433 /* New sg entry */ 3434 --num_sgs; 3435 sent_len -= block_len; 3436 + sg = sg_next(sg); 3437 + if (num_sgs != 0 && sg) { 3438 block_len = sg_dma_len(sg); 3439 addr = (u64) sg_dma_address(sg); 3440 addr += sent_len;
+2 -2
drivers/usb/mtu3/mtu3_debugfs.c
··· 276 .release = single_release, 277 }; 278 279 - static struct debugfs_reg32 mtu3_prb_regs[] = { 280 dump_prb_reg("enable", U3D_SSUSB_PRB_CTRL0), 281 dump_prb_reg("byte-sell", U3D_SSUSB_PRB_CTRL1), 282 dump_prb_reg("byte-selh", U3D_SSUSB_PRB_CTRL2), ··· 349 static void mtu3_debugfs_create_prb_files(struct mtu3 *mtu) 350 { 351 struct ssusb_mtk *ssusb = mtu->ssusb; 352 - struct debugfs_reg32 *regs; 353 struct dentry *dir_prb; 354 int i; 355
··· 276 .release = single_release, 277 }; 278 279 + static const struct debugfs_reg32 mtu3_prb_regs[] = { 280 dump_prb_reg("enable", U3D_SSUSB_PRB_CTRL0), 281 dump_prb_reg("byte-sell", U3D_SSUSB_PRB_CTRL1), 282 dump_prb_reg("byte-selh", U3D_SSUSB_PRB_CTRL2), ··· 349 static void mtu3_debugfs_create_prb_files(struct mtu3 *mtu) 350 { 351 struct ssusb_mtk *ssusb = mtu->ssusb; 352 + const struct debugfs_reg32 *regs; 353 struct dentry *dir_prb; 354 int i; 355
+9 -3
drivers/usb/phy/phy-twl6030-usb.c
··· 377 if (status < 0) { 378 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", 379 twl->irq1, status); 380 - return status; 381 } 382 383 status = request_threaded_irq(twl->irq2, NULL, twl6030_usb_irq, ··· 386 if (status < 0) { 387 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", 388 twl->irq2, status); 389 - free_irq(twl->irq1, twl); 390 - return status; 391 } 392 393 twl->asleep = 0; ··· 395 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n"); 396 397 return 0; 398 } 399 400 static int twl6030_usb_remove(struct platform_device *pdev)
··· 377 if (status < 0) { 378 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", 379 twl->irq1, status); 380 + goto err_put_regulator; 381 } 382 383 status = request_threaded_irq(twl->irq2, NULL, twl6030_usb_irq, ··· 386 if (status < 0) { 387 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", 388 twl->irq2, status); 389 + goto err_free_irq1; 390 } 391 392 twl->asleep = 0; ··· 396 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n"); 397 398 return 0; 399 + 400 + err_free_irq1: 401 + free_irq(twl->irq1, twl); 402 + err_put_regulator: 403 + regulator_put(twl->usb3v3); 404 + 405 + return status; 406 } 407 408 static int twl6030_usb_remove(struct platform_device *pdev)
+3 -3
drivers/usb/typec/mux/intel_pmc_mux.c
··· 63 #define PMC_USB_ALTMODE_DP_MODE_SHIFT 8 64 65 /* TBT specific Mode Data bits */ 66 #define PMC_USB_ALTMODE_TBT_TYPE BIT(17) 67 #define PMC_USB_ALTMODE_CABLE_TYPE BIT(18) 68 #define PMC_USB_ALTMODE_ACTIVE_LINK BIT(20) ··· 75 #define PMC_USB_ALTMODE_TBT_GEN(_g_) (((_g_) & GENMASK(1, 0)) << 28) 76 77 /* Display HPD Request bits */ 78 #define PMC_USB_DP_HPD_IRQ BIT(5) 79 - #define PMC_USB_DP_HPD_LVL BIT(6) 80 81 struct pmc_usb; 82 ··· 159 PMC_USB_ALTMODE_DP_MODE_SHIFT; 160 161 if (data->status & DP_STATUS_HPD_STATE) 162 - req.mode_data |= PMC_USB_DP_HPD_LVL << 163 - PMC_USB_ALTMODE_DP_MODE_SHIFT; 164 165 return pmc_usb_command(port, (void *)&req, sizeof(req)); 166 }
··· 63 #define PMC_USB_ALTMODE_DP_MODE_SHIFT 8 64 65 /* TBT specific Mode Data bits */ 66 + #define PMC_USB_ALTMODE_HPD_HIGH BIT(14) 67 #define PMC_USB_ALTMODE_TBT_TYPE BIT(17) 68 #define PMC_USB_ALTMODE_CABLE_TYPE BIT(18) 69 #define PMC_USB_ALTMODE_ACTIVE_LINK BIT(20) ··· 74 #define PMC_USB_ALTMODE_TBT_GEN(_g_) (((_g_) & GENMASK(1, 0)) << 28) 75 76 /* Display HPD Request bits */ 77 + #define PMC_USB_DP_HPD_LVL BIT(4) 78 #define PMC_USB_DP_HPD_IRQ BIT(5) 79 80 struct pmc_usb; 81 ··· 158 PMC_USB_ALTMODE_DP_MODE_SHIFT; 159 160 if (data->status & DP_STATUS_HPD_STATE) 161 + req.mode_data |= PMC_USB_ALTMODE_HPD_HIGH; 162 163 return pmc_usb_command(port, (void *)&req, sizeof(req)); 164 }
+95 -13
include/uapi/linux/usb/raw_gadget.h
··· 93 __u8 data[0]; 94 }; 95 96 /* 97 * Initializes a Raw Gadget instance. 98 * Accepts a pointer to the usb_raw_init struct as an argument. ··· 173 #define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event) 174 175 /* 176 - * Queues an IN (OUT for READ) urb as a response to the last control request 177 - * received on endpoint 0, provided that was an IN (OUT for READ) request and 178 - * waits until the urb is completed. Copies received data to user for READ. 179 * Accepts a pointer to the usb_raw_ep_io struct as an argument. 180 - * Returns length of trasferred data on success or negative error code on 181 * failure. 182 */ 183 #define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io) 184 #define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io) 185 186 /* 187 - * Finds an endpoint that supports the transfer type specified in the 188 - * descriptor and enables it. 189 - * Accepts a pointer to the usb_endpoint_descriptor struct as an argument. 190 * Returns enabled endpoint handle on success or negative error code on failure. 191 */ 192 #define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor) 193 194 - /* Disables specified endpoint. 195 * Accepts endpoint handle as an argument. 196 * Returns 0 on success or negative error code on failure. 197 */ 198 #define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32) 199 200 /* 201 - * Queues an IN (OUT for READ) urb as a response to the last control request 202 - * received on endpoint usb_raw_ep_io.ep, provided that was an IN (OUT for READ) 203 - * request and waits until the urb is completed. Copies received data to user 204 - * for READ. 205 * Accepts a pointer to the usb_raw_ep_io struct as an argument. 206 - * Returns length of trasferred data on success or negative error code on 207 * failure. 208 */ 209 #define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io) ··· 222 * Returns 0 on success or negative error code on failure. 223 */ 224 #define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32) 225 226 #endif /* _UAPI__LINUX_USB_RAW_GADGET_H */
··· 93 __u8 data[0]; 94 }; 95 96 + /* Maximum number of non-control endpoints in struct usb_raw_eps_info. */ 97 + #define USB_RAW_EPS_NUM_MAX 30 98 + 99 + /* Maximum length of UDC endpoint name in struct usb_raw_ep_info. */ 100 + #define USB_RAW_EP_NAME_MAX 16 101 + 102 + /* Used as addr in struct usb_raw_ep_info if endpoint accepts any address. */ 103 + #define USB_RAW_EP_ADDR_ANY 0xff 104 + 105 + /* 106 + * struct usb_raw_ep_caps - exposes endpoint capabilities from struct usb_ep 107 + * (technically from its member struct usb_ep_caps). 108 + */ 109 + struct usb_raw_ep_caps { 110 + __u32 type_control : 1; 111 + __u32 type_iso : 1; 112 + __u32 type_bulk : 1; 113 + __u32 type_int : 1; 114 + __u32 dir_in : 1; 115 + __u32 dir_out : 1; 116 + }; 117 + 118 + /* 119 + * struct usb_raw_ep_limits - exposes endpoint limits from struct usb_ep. 120 + * @maxpacket_limit: Maximum packet size value supported by this endpoint. 121 + * @max_streams: maximum number of streams supported by this endpoint 122 + * (actual number is 2^n). 123 + * @reserved: Empty, reserved for potential future extensions. 124 + */ 125 + struct usb_raw_ep_limits { 126 + __u16 maxpacket_limit; 127 + __u16 max_streams; 128 + __u32 reserved; 129 + }; 130 + 131 + /* 132 + * struct usb_raw_ep_info - stores information about a gadget endpoint. 133 + * @name: Name of the endpoint as it is defined in the UDC driver. 134 + * @addr: Address of the endpoint that must be specified in the endpoint 135 + * descriptor passed to USB_RAW_IOCTL_EP_ENABLE ioctl. 136 + * @caps: Endpoint capabilities. 137 + * @limits: Endpoint limits. 138 + */ 139 + struct usb_raw_ep_info { 140 + __u8 name[USB_RAW_EP_NAME_MAX]; 141 + __u32 addr; 142 + struct usb_raw_ep_caps caps; 143 + struct usb_raw_ep_limits limits; 144 + }; 145 + 146 + /* 147 + * struct usb_raw_eps_info - argument for USB_RAW_IOCTL_EPS_INFO ioctl. 148 + * eps: Structures that store information about non-control endpoints. 149 + */ 150 + struct usb_raw_eps_info { 151 + struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX]; 152 + }; 153 + 154 /* 155 * Initializes a Raw Gadget instance. 156 * Accepts a pointer to the usb_raw_init struct as an argument. ··· 115 #define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event) 116 117 /* 118 + * Queues an IN (OUT for READ) request as a response to the last setup request 119 + * received on endpoint 0 (provided that was an IN (OUT for READ) request), and 120 + * waits until the request is completed. Copies received data to user for READ. 121 * Accepts a pointer to the usb_raw_ep_io struct as an argument. 122 + * Returns length of transferred data on success or negative error code on 123 * failure. 124 */ 125 #define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io) 126 #define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io) 127 128 /* 129 + * Finds an endpoint that satisfies the parameters specified in the provided 130 + * descriptors (address, transfer type, etc.) and enables it. 131 + * Accepts a pointer to the usb_raw_ep_descs struct as an argument. 132 * Returns enabled endpoint handle on success or negative error code on failure. 133 */ 134 #define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor) 135 136 + /* 137 + * Disables specified endpoint. 138 * Accepts endpoint handle as an argument. 139 * Returns 0 on success or negative error code on failure. 140 */ 141 #define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32) 142 143 /* 144 + * Queues an IN (OUT for READ) request as a response to the last setup request 145 + * received on endpoint usb_raw_ep_io.ep (provided that was an IN (OUT for READ) 146 + * request), and waits until the request is completed. Copies received data to 147 + * user for READ. 148 * Accepts a pointer to the usb_raw_ep_io struct as an argument. 149 + * Returns length of transferred data on success or negative error code on 150 * failure. 151 */ 152 #define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io) ··· 163 * Returns 0 on success or negative error code on failure. 164 */ 165 #define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32) 166 + 167 + /* 168 + * Fills in the usb_raw_eps_info structure with information about non-control 169 + * endpoints available for the currently connected UDC. 170 + * Returns the number of available endpoints on success or negative error code 171 + * on failure. 172 + */ 173 + #define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info) 174 + 175 + /* 176 + * Stalls a pending control request on endpoint 0. 177 + * Returns 0 on success or negative error code on failure. 178 + */ 179 + #define USB_RAW_IOCTL_EP0_STALL _IO('U', 12) 180 + 181 + /* 182 + * Sets or clears halt or wedge status of the endpoint. 183 + * Accepts endpoint handle as an argument. 184 + * Returns 0 on success or negative error code on failure. 185 + */ 186 + #define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32) 187 + #define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32) 188 + #define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32) 189 190 #endif /* _UAPI__LINUX_USB_RAW_GADGET_H */