History

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 ...

Linus Torvalds committed 6 years ago

Commit fb27bc02 parents b48397c 157535822 files · +448 −123Browse files

Unified · Split

22 files
  1. Documentation/usb/raw-gadget.rst +30 −7
  2. drivers/usb/cdns3/gadget.c +11 −11
  3. drivers/usb/core/devio.c +13 −3
  4. drivers/usb/core/hub.c +5 −1
  5. drivers/usb/dwc3/Kconfig +1 −0
  6. drivers/usb/dwc3/dwc3-pci.c +1 −0
  7. drivers/usb/dwc3/gadget.c +0 −3
  8. drivers/usb/gadget/configfs.c +3 −0
  9. drivers/usb/gadget/legacy/audio.c +3 −1
  10. drivers/usb/gadget/legacy/cdc2.c +3 −1
  11. drivers/usb/gadget/legacy/inode.c +1 −2
  12. drivers/usb/gadget/legacy/ncm.c +3 −1
  13. drivers/usb/gadget/legacy/raw_gadget.c +252 −63
  14. drivers/usb/gadget/udc/atmel_usba_udc.c +2 −2
  15. drivers/usb/gadget/udc/net2272.c +2 −0
  16. drivers/usb/gadget/udc/tegra-xudc.c +4 −4
  17. drivers/usb/host/xhci-plat.c +3 −1
  18. drivers/usb/host/xhci-ring.c +2 −2
  19. drivers/usb/mtu3/mtu3_debugfs.c +2 −2
  20. drivers/usb/phy/phy-twl6030-usb.c +9 −3
  21. drivers/usb/typec/mux/intel_pmc_mux.c +3 −3
  22. include/uapi/linux/usb/raw_gadget.h +95 −13
Documentation/usb/raw-gadget.rst+30−7
@@ -27,9 +27,8 @@ differences are: · 26 unmodified lines
2727 3. Raw Gadget provides a way to select a UDC device/driver to bind to,
2828 while GadgetFS currently binds to the first available UDC.
2929
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).
30+4. Raw Gadget explicitly exposes information about endpoints addresses and
31+ capabilities allowing a user to write UDC-agnostic gadgets.
3332
3433 5. Raw Gadget has ioctl-based interface instead of a filesystem-based one.
3534
@@ -50,12 +49,36 @@ The typical usage of Raw Gadget looks like: · 14 unmodified lines
5049 Raw Gadget and react to those depending on what kind of USB device
5150 needs to be emulated.
5251
52+Note, that some UDC drivers have fixed addresses assigned to endpoints, and
53+therefore arbitrary endpoint addresses can't be used in the descriptors.
54+Nevertheles, Raw Gadget provides a UDC-agnostic way to write USB gadgets.
55+Once a USB_RAW_EVENT_CONNECT event is received via USB_RAW_IOCTL_EVENT_FETCH,
56+the USB_RAW_IOCTL_EPS_INFO ioctl can be used to find out information about
57+endpoints that the UDC driver has. Based on that information, the user must
58+chose UDC endpoints that will be used for the gadget being emulated, and
59+properly assign addresses in endpoint descriptors.
60+
61+You can find usage examples (along with a test suite) here:
62+
63+https://github.com/xairy/raw-gadget
64+
65+Internal details
66+~~~~~~~~~~~~~~~~
67+
68+Currently every endpoint read/write ioctl submits a USB request and waits until
69+its completion. This is the desired mode for coverage-guided fuzzing (as we'd
70+like all USB request processing happen during the lifetime of a syscall),
71+and must be kept in the implementation. (This might be slow for real world
72+applications, thus the O_NONBLOCK improvement suggestion below.)
73+
5374 Potential future improvements
5475 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5576
56−- Implement ioctl's for setting/clearing halt status on endpoints.
57−
58−- Reporting more events (suspend, resume, etc.) through
59− USB_RAW_IOCTL_EVENT_FETCH.
77+- Report more events (suspend, resume, etc.) through USB_RAW_IOCTL_EVENT_FETCH.
6078
6179 - Support O_NONBLOCK I/O.
80+
81+- Support USB 3 features (accept SS endpoint companion descriptor when
82+ enabling endpoints; allow providing stream_id for bulk transfers).
83+
84+- Support ISO transfer features (expose frame_number for completed requests).
drivers/usb/cdns3/gadget.c+11−11
@@ -82,7 +82,7 @@ static int cdns3_ep_run_stream_transfer(struct cdns3_endpoint *priv_ep, · 81 unmodified lines
8282 * @ptr: address of device controller register to be read and changed
8383 * @mask: bits requested to clar
8484 */
85−void cdns3_clear_register_bit(void __iomem *ptr, u32 mask)
85+static void cdns3_clear_register_bit(void __iomem *ptr, u32 mask)
8686 {
8787 mask = readl(ptr) & ~mask;
8888 writel(mask, ptr);
@@ -137,7 +137,7 @@ struct usb_request *cdns3_next_request(struct list_head *list) · 48 unmodified lines
137137 *
138138 * Returns buffer or NULL if no buffers in list
139139 */
140−struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list)
140+static struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list)
141141 {
142142 return list_first_entry_or_null(list, struct cdns3_aligned_buf, list);
143143 }
@@ -148,7 +148,7 @@ struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) · 4 unmodified lines
148148 *
149149 * Returns request or NULL if no requests in list
150150 */
151−struct cdns3_request *cdns3_next_priv_request(struct list_head *list)
151+static struct cdns3_request *cdns3_next_priv_request(struct list_head *list)
152152 {
153153 return list_first_entry_or_null(list, struct cdns3_request, list);
154154 }
@@ -190,7 +190,7 @@ dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, · 35 unmodified lines
190190 return priv_ep->trb_pool_dma + offset;
191191 }
192192
193−int cdns3_ring_size(struct cdns3_endpoint *priv_ep)
193+static int cdns3_ring_size(struct cdns3_endpoint *priv_ep)
194194 {
195195 switch (priv_ep->type) {
196196 case USB_ENDPOINT_XFER_ISOC:
@@ -345,7 +345,7 @@ static void cdns3_ep_inc_deq(struct cdns3_endpoint *priv_ep) · 148 unmodified lines
345345 cdns3_ep_inc_trb(&priv_ep->dequeue, &priv_ep->ccs, priv_ep->num_trbs);
346346 }
347347
348−void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req)
348+static void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req)
349349 {
350350 struct cdns3_endpoint *priv_ep = priv_req->priv_ep;
351351 int current_trb = priv_req->start_trb;
@@ -511,7 +511,7 @@ static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep, · 159 unmodified lines
511511 }
512512 }
513513
514−struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev,
514+static struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev,
515515 struct cdns3_endpoint *priv_ep,
516516 struct cdns3_request *priv_req)
517517 {
@@ -551,7 +551,7 @@ struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev, · 33 unmodified lines
551551 return &priv_req->request;
552552 }
553553
554−int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev,
554+static int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev,
555555 struct cdns3_endpoint *priv_ep,
556556 struct cdns3_request *priv_req)
557557 {
@@ -836,7 +836,7 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, · 278 unmodified lines
836836 cdns3_gadget_ep_free_request(&priv_ep->endpoint, request);
837837 }
838838
839−void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep)
839+static void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep)
840840 {
841841 /* Work around for stale data address in TRB*/
842842 if (priv_ep->wa1_set) {
@@ -1904,7 +1904,7 @@ static int cdns3_ep_onchip_buffer_reserve(struct cdns3_device *priv_dev, · 1061 unmodified lines
19041904 return 0;
19051905 }
19061906
1907−void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev,
1907+static void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev,
19081908 struct cdns3_endpoint *priv_ep)
19091909 {
19101910 if (!priv_ep->use_streams || priv_dev->gadget.speed < USB_SPEED_SUPER)
@@ -1925,7 +1925,7 @@ void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev, · 14 unmodified lines
19251925 EP_CFG_TDL_CHK | EP_CFG_SID_CHK);
19261926 }
19271927
1928−void cdns3_configure_dmult(struct cdns3_device *priv_dev,
1928+static void cdns3_configure_dmult(struct cdns3_device *priv_dev,
19291929 struct cdns3_endpoint *priv_ep)
19301930 {
19311931 struct cdns3_usb_regs __iomem *regs = priv_dev->regs;
@@ -2548,7 +2548,7 @@ found: · 616 unmodified lines
25482548 link_trb = priv_req->trb;
25492549
25502550 /* Update ring only if removed request is on pending_req_list list */
2551− if (req_on_hw_ring) {
2551+ if (req_on_hw_ring && link_trb) {
25522552 link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma +
25532553 ((priv_req->end_trb + 1) * TRB_SIZE));
25542554 link_trb->control = (link_trb->control & TRB_CYCLE) |
drivers/usb/core/devio.c+13−3
@@ -251,9 +251,19 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma) · 250 unmodified lines
251251 usbm->vma_use_count = 1;
252252 INIT_LIST_HEAD(&usbm->memlist);
253253
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;
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+ }
257267 }
258268
259269 vma->vm_flags |= VM_IO;
drivers/usb/core/hub.c+5−1
@@ -39,6 +39,7 @@ · 38 unmodified lines
3939
4040 #define USB_VENDOR_GENESYS_LOGIC 0x05e3
4141 #define USB_VENDOR_SMSC 0x0424
42+#define USB_PRODUCT_USB5534B 0x5534
4243 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01
4344 #define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02
4445
@@ -5621,8 +5622,11 @@ out_hdev_lock: · 5576 unmodified lines
56215622 }
56225623
56235624 static const struct usb_device_id hub_id_table[] = {
5624− { .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_CLASS,
5625+ { .match_flags = USB_DEVICE_ID_MATCH_VENDOR
5626+ | USB_DEVICE_ID_MATCH_PRODUCT
5627+ | USB_DEVICE_ID_MATCH_INT_CLASS,
56255628 .idVendor = USB_VENDOR_SMSC,
5629+ .idProduct = USB_PRODUCT_USB5534B,
56265630 .bInterfaceClass = USB_CLASS_HUB,
56275631 .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND},
56285632 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR
drivers/usb/dwc3/Kconfig+1−0
@@ -4,6 +4,7 @@ config USB_DWC3 · 3 unmodified lines
44 tristate "DesignWare USB3 DRD Core Support"
55 depends on (USB || USB_GADGET) && HAS_DMA
66 select USB_XHCI_PLATFORM if USB_XHCI_HCD
7+ select USB_ROLE_SWITCH if USB_DWC3_DUAL_ROLE
78 help
89 Say Y or M here if your system has a Dual Role SuperSpeed
910 USB controller based on the DesignWare USB3 IP Core.
drivers/usb/dwc3/dwc3-pci.c+1−0
@@ -114,6 +114,7 @@ static const struct property_entry dwc3_pci_intel_properties[] = { · 113 unmodified lines
114114
115115 static const struct property_entry dwc3_pci_mrfld_properties[] = {
116116 PROPERTY_ENTRY_STRING("dr_mode", "otg"),
117+ PROPERTY_ENTRY_STRING("linux,extcon-name", "mrfld_bcove_pwrsrc"),
117118 PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
118119 {}
119120 };
drivers/usb/dwc3/gadget.c+0−3
@@ -2483,9 +2483,6 @@ static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep, · 2482 unmodified lines
24832483 for_each_sg(sg, s, pending, i) {
24842484 trb = &dep->trb_pool[dep->trb_dequeue];
24852485
2486− if (trb->ctrl & DWC3_TRB_CTRL_HWO)
2487− break;
2488−
24892486 req->sg = sg_next(s);
24902487 req->num_pending_sgs--;
24912488
drivers/usb/gadget/configfs.c+3−0
@@ -260,6 +260,9 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item, · 259 unmodified lines
260260 char *name;
261261 int ret;
262262
263+ if (strlen(page) < len)
264+ return -EOVERFLOW;
265+
263266 name = kstrdup(page, GFP_KERNEL);
264267 if (!name)
265268 return -ENOMEM;
drivers/usb/gadget/legacy/audio.c+3−1
@@ -300,8 +300,10 @@ static int audio_bind(struct usb_composite_dev *cdev) · 299 unmodified lines
300300 struct usb_descriptor_header *usb_desc;
301301
302302 usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
303− if (!usb_desc)
303+ if (!usb_desc) {
304+ status = -ENOMEM;
304305 goto fail;
306+ }
305307 usb_otg_descriptor_init(cdev->gadget, usb_desc);
306308 otg_desc[0] = usb_desc;
307309 otg_desc[1] = NULL;
drivers/usb/gadget/legacy/cdc2.c+3−1
@@ -179,8 +179,10 @@ static int cdc_bind(struct usb_composite_dev *cdev) · 178 unmodified lines
179179 struct usb_descriptor_header *usb_desc;
180180
181181 usb_desc = usb_otg_descriptor_alloc(gadget);
182− if (!usb_desc)
182+ if (!usb_desc) {
183+ status = -ENOMEM;
183184 goto fail1;
185+ }
184186 usb_otg_descriptor_init(gadget, usb_desc);
185187 otg_desc[0] = usb_desc;
186188 otg_desc[1] = NULL;
drivers/usb/gadget/legacy/inode.c+1−2
@@ -1361,7 +1361,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) · 1360 unmodified lines
13611361
13621362 req->buf = dev->rbuf;
13631363 req->context = NULL;
1364− value = -EOPNOTSUPP;
13651364 switch (ctrl->bRequest) {
13661365
13671366 case USB_REQ_GET_DESCRIPTOR:
@@ -1784,7 +1783,7 @@ static ssize_t · 416 unmodified lines
17841783 dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
17851784 {
17861785 struct dev_data *dev = fd->private_data;
1787− ssize_t value = len, length = len;
1786+ ssize_t value, length = len;
17881787 unsigned total;
17891788 u32 tag;
17901789 char *kbuf;
drivers/usb/gadget/legacy/ncm.c+3−1
@@ -156,8 +156,10 @@ static int gncm_bind(struct usb_composite_dev *cdev) · 155 unmodified lines
156156 struct usb_descriptor_header *usb_desc;
157157
158158 usb_desc = usb_otg_descriptor_alloc(gadget);
159− if (!usb_desc)
159+ if (!usb_desc) {
160+ status = -ENOMEM;
160161 goto fail;
162+ }
161163 usb_otg_descriptor_init(gadget, usb_desc);
162164 otg_desc[0] = usb_desc;
163165 otg_desc[1] = NULL;
drivers/usb/gadget/legacy/raw_gadget.c+252−63
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 */
88
99 #include <linux/compiler.h>
10+#include <linux/ctype.h>
1011 #include <linux/debugfs.h>
1112 #include <linux/delay.h>
1213 #include <linux/kref.h>
@@ -123,8 +124,6 @@ static void raw_event_queue_destroy(struct raw_event_queue *queue) · 110 unmodified lines
123124
124125 struct raw_dev;
125126
126−#define USB_RAW_MAX_ENDPOINTS 32
127−
128127 enum ep_state {
129128 STATE_EP_DISABLED,
130129 STATE_EP_ENABLED,
@@ -134,6 +133,7 @@ struct raw_ep { · 3 unmodified lines
134133 struct raw_dev *dev;
135134 enum ep_state state;
136135 struct usb_ep *ep;
136+ u8 addr;
137137 struct usb_request *req;
138138 bool urb_queued;
139139 bool disabling;
@@ -168,7 +168,8 @@ struct raw_dev { · 28 unmodified lines
168168 bool ep0_out_pending;
169169 bool ep0_urb_queued;
170170 ssize_t ep0_status;
171− struct raw_ep eps[USB_RAW_MAX_ENDPOINTS];
171+ struct raw_ep eps[USB_RAW_EPS_NUM_MAX];
172+ int eps_num;
172173
173174 struct completion ep0_done;
174175 struct raw_event_queue queue;
@@ -202,8 +203,8 @@ static void dev_free(struct kref *kref) · 27 unmodified lines
202203 usb_ep_free_request(dev->gadget->ep0, dev->req);
203204 }
204205 raw_event_queue_destroy(&dev->queue);
205− for (i = 0; i < USB_RAW_MAX_ENDPOINTS; i++) {
206− if (dev->eps[i].state != STATE_EP_ENABLED)
206+ for (i = 0; i < dev->eps_num; i++) {
207+ if (dev->eps[i].state == STATE_EP_DISABLED)
207208 continue;
208209 usb_ep_disable(dev->eps[i].ep);
209210 usb_ep_free_request(dev->eps[i].ep, dev->eps[i].req);
@@ -249,12 +250,26 @@ static void gadget_ep0_complete(struct usb_ep *ep, struct usb_request *req) · 39 unmodified lines
249250 complete(&dev->ep0_done);
250251 }
251252
253+static u8 get_ep_addr(const char *name)
254+{
255+ /* If the endpoint has fixed function (named as e.g. "ep12out-bulk"),
256+ * parse the endpoint address from its name. We deliberately use
257+ * deprecated simple_strtoul() function here, as the number isn't
258+ * followed by '\0' nor '\n'.
259+ */
260+ if (isdigit(name[2]))
261+ return simple_strtoul(&name[2], NULL, 10);
262+ /* Otherwise the endpoint is configurable (named as e.g. "ep-a"). */
263+ return USB_RAW_EP_ADDR_ANY;
264+}
265+
252266 static int gadget_bind(struct usb_gadget *gadget,
253267 struct usb_gadget_driver *driver)
254268 {
255− int ret = 0;
269+ int ret = 0, i = 0;
256270 struct raw_dev *dev = container_of(driver, struct raw_dev, driver);
257271 struct usb_request *req;
272+ struct usb_ep *ep;
258273 unsigned long flags;
259274
260275 if (strcmp(gadget->name, dev->udc_name) != 0)
@@ -273,6 +288,13 @@ static int gadget_bind(struct usb_gadget *gadget, · 12 unmodified lines
273288 dev->req->context = dev;
274289 dev->req->complete = gadget_ep0_complete;
275290 dev->gadget = gadget;
291+ gadget_for_each_ep(ep, dev->gadget) {
292+ dev->eps[i].ep = ep;
293+ dev->eps[i].addr = get_ep_addr(ep->name);
294+ dev->eps[i].state = STATE_EP_DISABLED;
295+ i++;
296+ }
297+ dev->eps_num = i;
276298 spin_unlock_irqrestore(&dev->lock, flags);
277299
278300 /* Matches kref_put() in gadget_unbind(). */
@@ -555,7 +577,7 @@ static void *raw_alloc_io_data(struct usb_raw_ep_io *io, void __user *ptr, · 276 unmodified lines
555577
556578 if (copy_from_user(io, ptr, sizeof(*io)))
557579 return ERR_PTR(-EFAULT);
558− if (io->ep >= USB_RAW_MAX_ENDPOINTS)
580+ if (io->ep >= USB_RAW_EPS_NUM_MAX)
559581 return ERR_PTR(-EINVAL);
560582 if (!usb_raw_io_flags_valid(io->flags))
561583 return ERR_PTR(-EINVAL);
@@ -669,43 +691,61 @@ static int raw_ioctl_ep0_read(struct raw_dev *dev, unsigned long value) · 107 unmodified lines
669691 if (IS_ERR(data))
670692 return PTR_ERR(data);
671693 ret = raw_process_ep0_io(dev, &io, data, false);
672− if (ret)
694+ if (ret < 0)
673695 goto free;
674696
675697 length = min(io.length, (unsigned int)ret);
676698 if (copy_to_user((void __user *)(value + sizeof(io)), data, length))
677699 ret = -EFAULT;
700+ else
701+ ret = length;
678702 free:
679703 kfree(data);
680704 return ret;
681705 }
682706
683−static bool check_ep_caps(struct usb_ep *ep,
684− struct usb_endpoint_descriptor *desc)
707+static int raw_ioctl_ep0_stall(struct raw_dev *dev, unsigned long value)
685708 {
686− switch (usb_endpoint_type(desc)) {
687− case USB_ENDPOINT_XFER_ISOC:
688− if (!ep->caps.type_iso)
689− return false;
690− break;
691− case USB_ENDPOINT_XFER_BULK:
692− if (!ep->caps.type_bulk)
693− return false;
694− break;
695− case USB_ENDPOINT_XFER_INT:
696− if (!ep->caps.type_int)
697− return false;
698− break;
699− default:
700− return false;
709+ int ret = 0;
710+ unsigned long flags;
711+
712+ if (value)
713+ return -EINVAL;
714+ spin_lock_irqsave(&dev->lock, flags);
715+ if (dev->state != STATE_DEV_RUNNING) {
716+ dev_dbg(dev->dev, "fail, device is not running\n");
717+ ret = -EINVAL;
718+ goto out_unlock;
719+ }
720+ if (!dev->gadget) {
721+ dev_dbg(dev->dev, "fail, gadget is not bound\n");
722+ ret = -EBUSY;
723+ goto out_unlock;
724+ }
725+ if (dev->ep0_urb_queued) {
726+ dev_dbg(&dev->gadget->dev, "fail, urb already queued\n");
727+ ret = -EBUSY;
728+ goto out_unlock;
729+ }
730+ if (!dev->ep0_in_pending && !dev->ep0_out_pending) {
731+ dev_dbg(&dev->gadget->dev, "fail, no request pending\n");
732+ ret = -EBUSY;
733+ goto out_unlock;
701734 }
702735
703− if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in)
704− return false;
705− if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out)
706− return false;
736+ ret = usb_ep_set_halt(dev->gadget->ep0);
737+ if (ret < 0)
738+ dev_err(&dev->gadget->dev,
739+ "fail, usb_ep_set_halt returned %d\n", ret);
740+
741+ if (dev->ep0_in_pending)
742+ dev->ep0_in_pending = false;
743+ else
744+ dev->ep0_out_pending = false;
707745
708− return true;
746+out_unlock:
747+ spin_unlock_irqrestore(&dev->lock, flags);
748+ return ret;
709749 }
710750
711751 static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
@@ -713,7 +753,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) · 1 unmodified line
713753 int ret = 0, i;
714754 unsigned long flags;
715755 struct usb_endpoint_descriptor *desc;
716− struct usb_ep *ep = NULL;
756+ struct raw_ep *ep;
717757
718758 desc = memdup_user((void __user *)value, sizeof(*desc));
719759 if (IS_ERR(desc))
@@ -741,41 +781,32 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) · 21 unmodified lines
741781 goto out_free;
742782 }
743783
744− for (i = 0; i < USB_RAW_MAX_ENDPOINTS; i++) {
745− if (dev->eps[i].state == STATE_EP_ENABLED)
784+ for (i = 0; i < dev->eps_num; i++) {
785+ ep = &dev->eps[i];
786+ if (ep->state != STATE_EP_DISABLED)
746787 continue;
747− break;
748− }
749− if (i == USB_RAW_MAX_ENDPOINTS) {
750− dev_dbg(&dev->gadget->dev,
751− "fail, no device endpoints available\n");
752− ret = -EBUSY;
753− goto out_free;
754− }
755−
756− gadget_for_each_ep(ep, dev->gadget) {
757− if (ep->enabled)
788+ if (ep->addr != usb_endpoint_num(desc) &&
789+ ep->addr != USB_RAW_EP_ADDR_ANY)
758790 continue;
759− if (!check_ep_caps(ep, desc))
791+ if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
760792 continue;
761− ep->desc = desc;
762− ret = usb_ep_enable(ep);
793+ ep->ep->desc = desc;
794+ ret = usb_ep_enable(ep->ep);
763795 if (ret < 0) {
764796 dev_err(&dev->gadget->dev,
765797 "fail, usb_ep_enable returned %d\n", ret);
766798 goto out_free;
767799 }
768− dev->eps[i].req = usb_ep_alloc_request(ep, GFP_ATOMIC);
769− if (!dev->eps[i].req) {
800+ ep->req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC);
801+ if (!ep->req) {
770802 dev_err(&dev->gadget->dev,
771803 "fail, usb_ep_alloc_request failed\n");
772− usb_ep_disable(ep);
804+ usb_ep_disable(ep->ep);
773805 ret = -ENOMEM;
774806 goto out_free;
775807 }
776− dev->eps[i].ep = ep;
777− dev->eps[i].state = STATE_EP_ENABLED;
778− ep->driver_data = &dev->eps[i];
808+ ep->state = STATE_EP_ENABLED;
809+ ep->ep->driver_data = ep;
779810 ret = i;
780811 goto out_unlock;
781812 }
@@ -794,10 +825,6 @@ static int raw_ioctl_ep_disable(struct raw_dev *dev, unsigned long value) · 12 unmodified lines
794825 {
795826 int ret = 0, i = value;
796827 unsigned long flags;
797− const void *desc;
798−
799− if (i < 0 || i >= USB_RAW_MAX_ENDPOINTS)
800− return -EINVAL;
801828
802829 spin_lock_irqsave(&dev->lock, flags);
803830 if (dev->state != STATE_DEV_RUNNING) {
@@ -810,7 +837,12 @@ static int raw_ioctl_ep_disable(struct raw_dev *dev, unsigned long value) · 6 unmodified lines
810837 ret = -EBUSY;
811838 goto out_unlock;
812839 }
813− if (dev->eps[i].state != STATE_EP_ENABLED) {
840+ if (i < 0 || i >= dev->eps_num) {
841+ dev_dbg(dev->dev, "fail, invalid endpoint\n");
842+ ret = -EBUSY;
843+ goto out_unlock;
844+ }
845+ if (dev->eps[i].state == STATE_EP_DISABLED) {
814846 dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n");
815847 ret = -EINVAL;
816848 goto out_unlock;
@@ -834,10 +866,8 @@ static int raw_ioctl_ep_disable(struct raw_dev *dev, unsigned long value) · 17 unmodified lines
834866
835867 spin_lock_irqsave(&dev->lock, flags);
836868 usb_ep_free_request(dev->eps[i].ep, dev->eps[i].req);
837− desc = dev->eps[i].ep->desc;
838− dev->eps[i].ep = NULL;
869+ kfree(dev->eps[i].ep->desc);
839870 dev->eps[i].state = STATE_EP_DISABLED;
840− kfree(desc);
841871 dev->eps[i].disabling = false;
842872
843873 out_unlock:
@@ -845,6 +875,74 @@ out_unlock: · 1 unmodified line
845875 return ret;
846876 }
847877
878+static int raw_ioctl_ep_set_clear_halt_wedge(struct raw_dev *dev,
879+ unsigned long value, bool set, bool halt)
880+{
881+ int ret = 0, i = value;
882+ unsigned long flags;
883+
884+ spin_lock_irqsave(&dev->lock, flags);
885+ if (dev->state != STATE_DEV_RUNNING) {
886+ dev_dbg(dev->dev, "fail, device is not running\n");
887+ ret = -EINVAL;
888+ goto out_unlock;
889+ }
890+ if (!dev->gadget) {
891+ dev_dbg(dev->dev, "fail, gadget is not bound\n");
892+ ret = -EBUSY;
893+ goto out_unlock;
894+ }
895+ if (i < 0 || i >= dev->eps_num) {
896+ dev_dbg(dev->dev, "fail, invalid endpoint\n");
897+ ret = -EBUSY;
898+ goto out_unlock;
899+ }
900+ if (dev->eps[i].state == STATE_EP_DISABLED) {
901+ dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n");
902+ ret = -EINVAL;
903+ goto out_unlock;
904+ }
905+ if (dev->eps[i].disabling) {
906+ dev_dbg(&dev->gadget->dev,
907+ "fail, disable is in progress\n");
908+ ret = -EINVAL;
909+ goto out_unlock;
910+ }
911+ if (dev->eps[i].urb_queued) {
912+ dev_dbg(&dev->gadget->dev,
913+ "fail, waiting for urb completion\n");
914+ ret = -EINVAL;
915+ goto out_unlock;
916+ }
917+ if (usb_endpoint_xfer_isoc(dev->eps[i].ep->desc)) {
918+ dev_dbg(&dev->gadget->dev,
919+ "fail, can't halt/wedge ISO endpoint\n");
920+ ret = -EINVAL;
921+ goto out_unlock;
922+ }
923+
924+ if (set && halt) {
925+ ret = usb_ep_set_halt(dev->eps[i].ep);
926+ if (ret < 0)
927+ dev_err(&dev->gadget->dev,
928+ "fail, usb_ep_set_halt returned %d\n", ret);
929+ } else if (!set && halt) {
930+ ret = usb_ep_clear_halt(dev->eps[i].ep);
931+ if (ret < 0)
932+ dev_err(&dev->gadget->dev,
933+ "fail, usb_ep_clear_halt returned %d\n", ret);
934+ } else if (set && !halt) {
935+ ret = usb_ep_set_wedge(dev->eps[i].ep);
936+ if (ret < 0)
937+ dev_err(&dev->gadget->dev,
938+ "fail, usb_ep_set_wedge returned %d\n", ret);
939+ }
940+
941+out_unlock:
942+ spin_unlock_irqrestore(&dev->lock, flags);
943+ return ret;
944+}
945+
848946 static void gadget_ep_complete(struct usb_ep *ep, struct usb_request *req)
849947 {
850948 struct raw_ep *r_ep = (struct raw_ep *)ep->driver_data;
@@ -866,7 +964,7 @@ static int raw_process_ep_io(struct raw_dev *dev, struct usb_raw_ep_io *io, · 15 unmodified lines
866964 {
867965 int ret = 0;
868966 unsigned long flags;
869− struct raw_ep *ep = &dev->eps[io->ep];
967+ struct raw_ep *ep;
870968 DECLARE_COMPLETION_ONSTACK(done);
871969
872970 spin_lock_irqsave(&dev->lock, flags);
@@ -880,6 +978,12 @@ static int raw_process_ep_io(struct raw_dev *dev, struct usb_raw_ep_io *io, · 7 unmodified lines
880978 ret = -EBUSY;
881979 goto out_unlock;
882980 }
981+ if (io->ep >= dev->eps_num) {
982+ dev_dbg(&dev->gadget->dev, "fail, invalid endpoint\n");
983+ ret = -EINVAL;
984+ goto out_unlock;
985+ }
986+ ep = &dev->eps[io->ep];
883987 if (ep->state != STATE_EP_ENABLED) {
884988 dev_dbg(&dev->gadget->dev, "fail, endpoint is not enabled\n");
885989 ret = -EBUSY;
@@ -964,12 +1068,14 @@ static int raw_ioctl_ep_read(struct raw_dev *dev, unsigned long value) · 78 unmodified lines
9641068 if (IS_ERR(data))
9651069 return PTR_ERR(data);
9661070 ret = raw_process_ep_io(dev, &io, data, false);
967− if (ret)
1071+ if (ret < 0)
9681072 goto free;
9691073
9701074 length = min(io.length, (unsigned int)ret);
9711075 if (copy_to_user((void __user *)(value + sizeof(io)), data, length))
9721076 ret = -EFAULT;
1077+ else
1078+ ret = length;
9731079 free:
9741080 kfree(data);
9751081 return ret;
@@ -1023,6 +1129,71 @@ out_unlock: · 47 unmodified lines
10231129 return ret;
10241130 }
10251131
1132+static void fill_ep_caps(struct usb_ep_caps *caps,
1133+ struct usb_raw_ep_caps *raw_caps)
1134+{
1135+ raw_caps->type_control = caps->type_control;
1136+ raw_caps->type_iso = caps->type_iso;
1137+ raw_caps->type_bulk = caps->type_bulk;
1138+ raw_caps->type_int = caps->type_int;
1139+ raw_caps->dir_in = caps->dir_in;
1140+ raw_caps->dir_out = caps->dir_out;
1141+}
1142+
1143+static void fill_ep_limits(struct usb_ep *ep, struct usb_raw_ep_limits *limits)
1144+{
1145+ limits->maxpacket_limit = ep->maxpacket_limit;
1146+ limits->max_streams = ep->max_streams;
1147+}
1148+
1149+static int raw_ioctl_eps_info(struct raw_dev *dev, unsigned long value)
1150+{
1151+ int ret = 0, i;
1152+ unsigned long flags;
1153+ struct usb_raw_eps_info *info;
1154+ struct raw_ep *ep;
1155+
1156+ info = kmalloc(sizeof(*info), GFP_KERNEL);
1157+ if (!info) {
1158+ ret = -ENOMEM;
1159+ goto out;
1160+ }
1161+
1162+ spin_lock_irqsave(&dev->lock, flags);
1163+ if (dev->state != STATE_DEV_RUNNING) {
1164+ dev_dbg(dev->dev, "fail, device is not running\n");
1165+ ret = -EINVAL;
1166+ spin_unlock_irqrestore(&dev->lock, flags);
1167+ goto out_free;
1168+ }
1169+ if (!dev->gadget) {
1170+ dev_dbg(dev->dev, "fail, gadget is not bound\n");
1171+ ret = -EBUSY;
1172+ spin_unlock_irqrestore(&dev->lock, flags);
1173+ goto out_free;
1174+ }
1175+
1176+ memset(info, 0, sizeof(*info));
1177+ for (i = 0; i < dev->eps_num; i++) {
1178+ ep = &dev->eps[i];
1179+ strscpy(&info->eps[i].name[0], ep->ep->name,
1180+ USB_RAW_EP_NAME_MAX);
1181+ info->eps[i].addr = ep->addr;
1182+ fill_ep_caps(&ep->ep->caps, &info->eps[i].caps);
1183+ fill_ep_limits(ep->ep, &info->eps[i].limits);
1184+ }
1185+ ret = dev->eps_num;
1186+ spin_unlock_irqrestore(&dev->lock, flags);
1187+
1188+ if (copy_to_user((void __user *)value, info, sizeof(*info)))
1189+ ret = -EFAULT;
1190+
1191+out_free:
1192+ kfree(info);
1193+out:
1194+ return ret;
1195+}
1196+
10261197 static long raw_ioctl(struct file *fd, unsigned int cmd, unsigned long value)
10271198 {
10281199 struct raw_dev *dev = fd->private_data;
@@ -1065,6 +1236,24 @@ static long raw_ioctl(struct file *fd, unsigned int cmd, unsigned long value) · 36 unmodified lines
10651236 case USB_RAW_IOCTL_VBUS_DRAW:
10661237 ret = raw_ioctl_vbus_draw(dev, value);
10671238 break;
1239+ case USB_RAW_IOCTL_EPS_INFO:
1240+ ret = raw_ioctl_eps_info(dev, value);
1241+ break;
1242+ case USB_RAW_IOCTL_EP0_STALL:
1243+ ret = raw_ioctl_ep0_stall(dev, value);
1244+ break;
1245+ case USB_RAW_IOCTL_EP_SET_HALT:
1246+ ret = raw_ioctl_ep_set_clear_halt_wedge(
1247+ dev, value, true, true);
1248+ break;
1249+ case USB_RAW_IOCTL_EP_CLEAR_HALT:
1250+ ret = raw_ioctl_ep_set_clear_halt_wedge(
1251+ dev, value, false, true);
1252+ break;
1253+ case USB_RAW_IOCTL_EP_SET_WEDGE:
1254+ ret = raw_ioctl_ep_set_clear_halt_wedge(
1255+ dev, value, true, false);
1256+ break;
10681257 default:
10691258 ret = -EINVAL;
10701259 }
drivers/usb/gadget/udc/atmel_usba_udc.c+2−2
@@ -185,7 +185,7 @@ static int regs_dbg_release(struct inode *inode, struct file *file) · 184 unmodified lines
185185 return 0;
186186 }
187187
188−const struct file_operations queue_dbg_fops = {
188+static const struct file_operations queue_dbg_fops = {
189189 .owner = THIS_MODULE,
190190 .open = queue_dbg_open,
191191 .llseek = no_llseek,
@@ -193,7 +193,7 @@ const struct file_operations queue_dbg_fops = { · 1 unmodified line
193193 .release = queue_dbg_release,
194194 };
195195
196−const struct file_operations regs_dbg_fops = {
196+static const struct file_operations regs_dbg_fops = {
197197 .owner = THIS_MODULE,
198198 .open = regs_dbg_open,
199199 .llseek = generic_file_llseek,
drivers/usb/gadget/udc/net2272.c+2−0
@@ -2647,6 +2647,8 @@ net2272_plat_probe(struct platform_device *pdev) · 2646 unmodified lines
26472647 err_req:
26482648 release_mem_region(base, len);
26492649 err:
2650+ kfree(dev);
2651+
26502652 return ret;
26512653 }
26522654
drivers/usb/gadget/udc/tegra-xudc.c+4−4
@@ -3840,11 +3840,11 @@ static int __maybe_unused tegra_xudc_suspend(struct device *dev) · 3839 unmodified lines
38403840
38413841 flush_work(&xudc->usb_role_sw_work);
38423842
3843− /* Forcibly disconnect before powergating. */
3844− tegra_xudc_device_mode_off(xudc);
3845−
3846− if (!pm_runtime_status_suspended(dev))
3843+ if (!pm_runtime_status_suspended(dev)) {
3844+ /* Forcibly disconnect before powergating. */
3845+ tegra_xudc_device_mode_off(xudc);
38473846 tegra_xudc_powergate(xudc);
3847+ }
38483848
38493849 pm_runtime_disable(dev);
38503850
drivers/usb/host/xhci-plat.c+3−1
@@ -362,6 +362,7 @@ static int xhci_plat_remove(struct platform_device *dev) · 361 unmodified lines
362362 struct clk *reg_clk = xhci->reg_clk;
363363 struct usb_hcd *shared_hcd = xhci->shared_hcd;
364364
365+ pm_runtime_get_sync(&dev->dev);
365366 xhci->xhc_state |= XHCI_STATE_REMOVING;
366367
367368 usb_remove_hcd(shared_hcd);
@@ -375,8 +376,9 @@ static int xhci_plat_remove(struct platform_device *dev) · 7 unmodified lines
375376 clk_disable_unprepare(reg_clk);
376377 usb_put_hcd(hcd);
377378
378− pm_runtime_set_suspended(&dev->dev);
379379 pm_runtime_disable(&dev->dev);
380+ pm_runtime_put_noidle(&dev->dev);
381+ pm_runtime_set_suspended(&dev->dev);
380382
381383 return 0;
382384 }
drivers/usb/host/xhci-ring.c+2−2
@@ -3433,8 +3433,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, · 3432 unmodified lines
34333433 /* New sg entry */
34343434 --num_sgs;
34353435 sent_len -= block_len;
3436− if (num_sgs != 0) {
3437− sg = sg_next(sg);
3436+ sg = sg_next(sg);
3437+ if (num_sgs != 0 && sg) {
34383438 block_len = sg_dma_len(sg);
34393439 addr = (u64) sg_dma_address(sg);
34403440 addr += sent_len;
drivers/usb/mtu3/mtu3_debugfs.c+2−2
@@ -276,7 +276,7 @@ static const struct file_operations mtu3_ep_fops = { · 275 unmodified lines
276276 .release = single_release,
277277 };
278278
279−static struct debugfs_reg32 mtu3_prb_regs[] = {
279+static const struct debugfs_reg32 mtu3_prb_regs[] = {
280280 dump_prb_reg("enable", U3D_SSUSB_PRB_CTRL0),
281281 dump_prb_reg("byte-sell", U3D_SSUSB_PRB_CTRL1),
282282 dump_prb_reg("byte-selh", U3D_SSUSB_PRB_CTRL2),
@@ -349,7 +349,7 @@ static const struct file_operations mtu3_probe_fops = { · 66 unmodified lines
349349 static void mtu3_debugfs_create_prb_files(struct mtu3 *mtu)
350350 {
351351 struct ssusb_mtk *ssusb = mtu->ssusb;
352− struct debugfs_reg32 *regs;
352+ const struct debugfs_reg32 *regs;
353353 struct dentry *dir_prb;
354354 int i;
355355
drivers/usb/phy/phy-twl6030-usb.c+9−3
@@ -377,7 +377,7 @@ static int twl6030_usb_probe(struct platform_device *pdev) · 376 unmodified lines
377377 if (status < 0) {
378378 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
379379 twl->irq1, status);
380− return status;
380+ goto err_put_regulator;
381381 }
382382
383383 status = request_threaded_irq(twl->irq2, NULL, twl6030_usb_irq,
@@ -386,8 +386,7 @@ static int twl6030_usb_probe(struct platform_device *pdev) · 2 unmodified lines
386386 if (status < 0) {
387387 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
388388 twl->irq2, status);
389− free_irq(twl->irq1, twl);
390− return status;
389+ goto err_free_irq1;
391390 }
392391
393392 twl->asleep = 0;
@@ -396,6 +395,13 @@ static int twl6030_usb_probe(struct platform_device *pdev) · 2 unmodified lines
396395 dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");
397396
398397 return 0;
398+
399+err_free_irq1:
400+ free_irq(twl->irq1, twl);
401+err_put_regulator:
402+ regulator_put(twl->usb3v3);
403+
404+ return status;
399405 }
400406
401407 static int twl6030_usb_remove(struct platform_device *pdev)
drivers/usb/typec/mux/intel_pmc_mux.c+3−3
@@ -63,6 +63,7 @@ enum { · 62 unmodified lines
6363 #define PMC_USB_ALTMODE_DP_MODE_SHIFT 8
6464
6565 /* TBT specific Mode Data bits */
66+#define PMC_USB_ALTMODE_HPD_HIGH BIT(14)
6667 #define PMC_USB_ALTMODE_TBT_TYPE BIT(17)
6768 #define PMC_USB_ALTMODE_CABLE_TYPE BIT(18)
6869 #define PMC_USB_ALTMODE_ACTIVE_LINK BIT(20)
@@ -74,8 +75,8 @@ enum { · 5 unmodified lines
7475 #define PMC_USB_ALTMODE_TBT_GEN(_g_) (((_g_) & GENMASK(1, 0)) << 28)
7576
7677 /* Display HPD Request bits */
78+#define PMC_USB_DP_HPD_LVL BIT(4)
7779 #define PMC_USB_DP_HPD_IRQ BIT(5)
78−#define PMC_USB_DP_HPD_LVL BIT(6)
7980
8081 struct pmc_usb;
8182
@@ -158,8 +159,7 @@ pmc_usb_mux_dp(struct pmc_usb_port *port, struct typec_mux_state *state) · 76 unmodified lines
158159 PMC_USB_ALTMODE_DP_MODE_SHIFT;
159160
160161 if (data->status & DP_STATUS_HPD_STATE)
161− req.mode_data |= PMC_USB_DP_HPD_LVL <<
162− PMC_USB_ALTMODE_DP_MODE_SHIFT;
162+ req.mode_data |= PMC_USB_ALTMODE_HPD_HIGH;
163163
164164 return pmc_usb_command(port, (void *)&req, sizeof(req));
165165 }
include/uapi/linux/usb/raw_gadget.h+95−13
@@ -93,6 +93,64 @@ struct usb_raw_ep_io { · 92 unmodified lines
9393 __u8 data[0];
9494 };
9595
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+
96154 /*
97155 * Initializes a Raw Gadget instance.
98156 * Accepts a pointer to the usb_raw_init struct as an argument.
@@ -115,37 +173,38 @@ struct usb_raw_ep_io { · 16 unmodified lines
115173 #define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event)
116174
117175 /*
118− * Queues an IN (OUT for READ) urb as a response to the last control request
119− * received on endpoint 0, provided that was an IN (OUT for READ) request and
120− * waits until the urb is completed. Copies received data to user for READ.
176+ * Queues an IN (OUT for READ) request as a response to the last setup request
177+ * received on endpoint 0 (provided that was an IN (OUT for READ) request), and
178+ * waits until the request is completed. Copies received data to user for READ.
121179 * Accepts a pointer to the usb_raw_ep_io struct as an argument.
122− * Returns length of trasferred data on success or negative error code on
180+ * Returns length of transferred data on success or negative error code on
123181 * failure.
124182 */
125183 #define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io)
126184 #define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io)
127185
128186 /*
129− * Finds an endpoint that supports the transfer type specified in the
130− * descriptor and enables it.
131− * Accepts a pointer to the usb_endpoint_descriptor struct as an argument.
187+ * Finds an endpoint that satisfies the parameters specified in the provided
188+ * descriptors (address, transfer type, etc.) and enables it.
189+ * Accepts a pointer to the usb_raw_ep_descs struct as an argument.
132190 * Returns enabled endpoint handle on success or negative error code on failure.
133191 */
134192 #define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor)
135193
136−/* Disables specified endpoint.
194+/*
195+ * Disables specified endpoint.
137196 * Accepts endpoint handle as an argument.
138197 * Returns 0 on success or negative error code on failure.
139198 */
140199 #define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32)
141200
142201 /*
143− * Queues an IN (OUT for READ) urb as a response to the last control request
144− * received on endpoint usb_raw_ep_io.ep, provided that was an IN (OUT for READ)
145− * request and waits until the urb is completed. Copies received data to user
146− * for READ.
202+ * Queues an IN (OUT for READ) request as a response to the last setup request
203+ * received on endpoint usb_raw_ep_io.ep (provided that was an IN (OUT for READ)
204+ * request), and waits until the request is completed. Copies received data to
205+ * user for READ.
147206 * Accepts a pointer to the usb_raw_ep_io struct as an argument.
148− * Returns length of trasferred data on success or negative error code on
207+ * Returns length of transferred data on success or negative error code on
149208 * failure.
150209 */
151210 #define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io)
@@ -164,4 +223,27 @@ struct usb_raw_ep_io { · 12 unmodified lines
164223 */
165224 #define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32)
166225
226+/*
227+ * Fills in the usb_raw_eps_info structure with information about non-control
228+ * endpoints available for the currently connected UDC.
229+ * Returns the number of available endpoints on success or negative error code
230+ * on failure.
231+ */
232+#define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info)
233+
234+/*
235+ * Stalls a pending control request on endpoint 0.
236+ * Returns 0 on success or negative error code on failure.
237+ */
238+#define USB_RAW_IOCTL_EP0_STALL _IO('U', 12)
239+
240+/*
241+ * Sets or clears halt or wedge status of the endpoint.
242+ * Accepts endpoint handle as an argument.
243+ * Returns 0 on success or negative error code on failure.
244+ */
245+#define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32)
246+#define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32)
247+#define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32)
248+
167249 #endif /* _UAPI__LINUX_USB_RAW_GADGET_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t