43da9308718a84c85a34cedce93c3ae1142afa2a
[openwrt/staging/linusw.git] /
1 From e1cd62d5163e73d18b4e3083a8a09dfb9c67fd4b 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] usb: add plumbing for updating interrupt endpoint
5 interval state
6
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.
10
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
13 URBs are submitted.
14
15 If polling intervals are shortened, any bandwidth reservations are no
16 longer valid but in practice polling intervals are only ever relaxed.
17
18 Limit the scope to interrupt transfers for now.
19
20 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.org>
21 ---
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(+)
27
28 --- a/drivers/usb/core/hcd.c
29 +++ b/drivers/usb/core/hcd.c
30 @@ -1945,6 +1945,16 @@ reset:
31 return ret;
32 }
33
34 +void usb_hcd_fixup_endpoint(struct usb_device *udev,
35 + struct usb_host_endpoint *ep, int interval)
36 +{
37 + struct usb_hcd *hcd;
38 +
39 + hcd = bus_to_hcd(udev->bus);
40 + if (hcd->driver->fixup_endpoint)
41 + hcd->driver->fixup_endpoint(hcd, udev, ep, interval);
42 +}
43 +
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 @@ -1265,6 +1265,21 @@ static void remove_intf_ep_devs(struct u
50 intf->ep_devs_created = 0;
51 }
52
53 +void usb_fixup_endpoint(struct usb_device *dev, int epaddr, int interval)
54 +{
55 + unsigned int epnum = epaddr & USB_ENDPOINT_NUMBER_MASK;
56 + struct usb_host_endpoint *ep;
57 +
58 + if (usb_endpoint_out(epaddr))
59 + ep = dev->ep_out[epnum];
60 + else
61 + ep = dev->ep_in[epnum];
62 +
63 + if (ep && usb_endpoint_xfer_int(&ep->desc))
64 + usb_hcd_fixup_endpoint(dev, ep, interval);
65 +}
66 +EXPORT_SYMBOL_GPL(usb_fixup_endpoint);
67 +
68 /**
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 @@ -1838,6 +1838,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,
78 + int interval);
79
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 @@ -384,6 +384,11 @@ struct hc_driver {
85 * or bandwidth constraints.
86 */
87 void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
88 + /* Override the endpoint-derived interval
89 + * (if there is any cached hardware state).
90 + */
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 @@ -445,6 +450,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,