1 From 8a84d16debf7243c49bc63a38732c51e16781bc1 Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.org>
3 Date: Tue, 11 Jun 2019 10:55:00 +0100
4 Subject: [PATCH 654/773] usb: add plumbing for updating interrupt endpoint
7 xHCI caches device and endpoint data after the interface is configured,
8 so an explicit command needs to be issued for any device driver wanting
9 to alter the polling interval of an endpoint.
11 Add usb_fixup_endpoint() to allow drivers to do this. The fixup must be
12 called after calculating endpoint bandwidth requirements but before any
15 If polling intervals are shortened, any bandwidth reservations are no
16 longer valid but in practice polling intervals are only ever relaxed.
18 Limit the scope to interrupt transfers for now.
20 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.org>
22 drivers/usb/core/hcd.c | 10 ++++++++++
23 drivers/usb/core/message.c | 15 +++++++++++++++
24 include/linux/usb.h | 2 ++
25 include/linux/usb/hcd.h | 7 +++++++
26 4 files changed, 34 insertions(+)
28 --- a/drivers/usb/core/hcd.c
29 +++ b/drivers/usb/core/hcd.c
30 @@ -2071,6 +2071,16 @@ reset:
34 +void usb_hcd_fixup_endpoint(struct usb_device *udev,
35 + struct usb_host_endpoint *ep, int interval)
37 + struct usb_hcd *hcd;
39 + hcd = bus_to_hcd(udev->bus);
40 + if (hcd->driver->fixup_endpoint)
41 + hcd->driver->fixup_endpoint(hcd, udev, ep, interval);
44 /* Disables the endpoint: synchronizes with the hcd to make sure all
45 * endpoint state is gone from hardware. usb_hcd_flush_endpoint() must
46 * have been called previously. Use for set_configuration, set_interface,
47 --- a/drivers/usb/core/message.c
48 +++ b/drivers/usb/core/message.c
49 @@ -1113,6 +1113,21 @@ static void remove_intf_ep_devs(struct u
50 intf->ep_devs_created = 0;
53 +void usb_fixup_endpoint(struct usb_device *dev, int epaddr, int interval)
55 + unsigned int epnum = epaddr & USB_ENDPOINT_NUMBER_MASK;
56 + struct usb_host_endpoint *ep;
58 + if (usb_endpoint_out(epaddr))
59 + ep = dev->ep_out[epnum];
61 + ep = dev->ep_in[epnum];
63 + if (ep && usb_endpoint_xfer_int(&ep->desc))
64 + usb_hcd_fixup_endpoint(dev, ep, interval);
66 +EXPORT_SYMBOL_GPL(usb_fixup_endpoint);
69 * usb_disable_endpoint -- Disable an endpoint by address
70 * @dev: the device whose endpoint is being disabled
71 --- a/include/linux/usb.h
72 +++ b/include/linux/usb.h
73 @@ -1809,6 +1809,8 @@ extern int usb_clear_halt(struct usb_dev
74 extern int usb_reset_configuration(struct usb_device *dev);
75 extern int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);
76 extern void usb_reset_endpoint(struct usb_device *dev, unsigned int epaddr);
77 +extern void usb_fixup_endpoint(struct usb_device *dev, int epaddr,
80 /* this request isn't really synchronous, but it belongs with the others */
81 extern int usb_driver_set_configuration(struct usb_device *udev, int config);
82 --- a/include/linux/usb/hcd.h
83 +++ b/include/linux/usb/hcd.h
84 @@ -379,6 +379,11 @@ struct hc_driver {
85 * or bandwidth constraints.
87 void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
88 + /* Override the endpoint-derived interval
89 + * (if there is any cached hardware state).
91 + void (*fixup_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
92 + struct usb_host_endpoint *ep, int interval);
93 /* Returns the hardware-chosen device address */
94 int (*address_device)(struct usb_hcd *, struct usb_device *udev);
95 /* prepares the hardware to send commands to the device */
96 @@ -435,6 +440,8 @@ extern void usb_hcd_unmap_urb_setup_for_
97 extern void usb_hcd_unmap_urb_for_dma(struct usb_hcd *, struct urb *);
98 extern void usb_hcd_flush_endpoint(struct usb_device *udev,
99 struct usb_host_endpoint *ep);
100 +extern void usb_hcd_fixup_endpoint(struct usb_device *udev,
101 + struct usb_host_endpoint *ep, int interval);
102 extern void usb_hcd_disable_endpoint(struct usb_device *udev,
103 struct usb_host_endpoint *ep);
104 extern void usb_hcd_reset_endpoint(struct usb_device *udev,