]> git.ipfire.org Git - thirdparty/openwrt.git/blob
041d364b89eb2cc88b90592d663c8d1d2a36a9f6
[thirdparty/openwrt.git] /
1 From 0735c2177b95550b4464158b325c399f556a846d Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.org>
3 Date: Tue, 11 Jun 2019 11:33:39 +0100
4 Subject: [PATCH] xhci: implement xhci_fixup_endpoint for interval adjustments
5
6 Must be called in a non-atomic context, after the endpoint
7 has been registered with the hardware via xhci_add_endpoint
8 and before the first URB is submitted for the endpoint.
9
10 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.org>
11 ---
12 drivers/usb/host/xhci.c | 104 ++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 104 insertions(+)
14
15 --- a/drivers/usb/host/xhci.c
16 +++ b/drivers/usb/host/xhci.c
17 @@ -1517,6 +1517,109 @@ static int xhci_check_ep0_maxpacket(stru
18 }
19
20 /*
21 + * RPI: Fixup endpoint intervals when requested
22 + * - Check interval versus the (cached) endpoint context
23 + * - set the endpoint interval to the new value
24 + * - force an endpoint configure command
25 + * XXX: bandwidth is not recalculated. We should probably do that.
26 + */
27 +
28 +static unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index)
29 +{
30 + return 1 << (ep_index + 1);
31 +}
32 +
33 +static void xhci_fixup_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
34 + struct usb_host_endpoint *ep, int interval)
35 +{
36 + struct xhci_hcd *xhci;
37 + struct xhci_ep_ctx *ep_ctx_out, *ep_ctx_in;
38 + struct xhci_command *command;
39 + struct xhci_input_control_ctx *ctrl_ctx;
40 + struct xhci_virt_device *vdev;
41 + int xhci_interval;
42 + int ret;
43 + int ep_index;
44 + unsigned long flags;
45 + u32 ep_info_tmp;
46 +
47 + xhci = hcd_to_xhci(hcd);
48 + ep_index = xhci_get_endpoint_index(&ep->desc);
49 +
50 + /* FS/LS interval translations */
51 + if ((udev->speed == USB_SPEED_FULL ||
52 + udev->speed == USB_SPEED_LOW))
53 + interval *= 8;
54 +
55 + mutex_lock(&xhci->mutex);
56 +
57 + spin_lock_irqsave(&xhci->lock, flags);
58 +
59 + vdev = xhci->devs[udev->slot_id];
60 + /* Get context-derived endpoint interval */
61 + ep_ctx_out = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index);
62 + ep_ctx_in = xhci_get_ep_ctx(xhci, vdev->in_ctx, ep_index);
63 + xhci_interval = EP_INTERVAL_TO_UFRAMES(le32_to_cpu(ep_ctx_out->ep_info));
64 +
65 + if (interval == xhci_interval) {
66 + spin_unlock_irqrestore(&xhci->lock, flags);
67 + mutex_unlock(&xhci->mutex);
68 + return;
69 + }
70 +
71 + xhci_dbg(xhci, "Fixup interval=%d xhci_interval=%d\n",
72 + interval, xhci_interval);
73 + command = xhci_alloc_command_with_ctx(xhci, true, GFP_ATOMIC);
74 + if (!command) {
75 + /* Failure here is benign, poll at the original rate */
76 + spin_unlock_irqrestore(&xhci->lock, flags);
77 + mutex_unlock(&xhci->mutex);
78 + return;
79 + }
80 +
81 + /* xHCI uses exponents for intervals... */
82 + xhci_interval = fls(interval) - 1;
83 + xhci_interval = clamp_val(xhci_interval, 3, 10);
84 + ep_info_tmp = le32_to_cpu(ep_ctx_out->ep_info);
85 + ep_info_tmp &= ~EP_INTERVAL(255);
86 + ep_info_tmp |= EP_INTERVAL(xhci_interval);
87 +
88 + /* Keep the endpoint context up-to-date while issuing the command. */
89 + xhci_endpoint_copy(xhci, vdev->in_ctx,
90 + vdev->out_ctx, ep_index);
91 + ep_ctx_in->ep_info = cpu_to_le32(ep_info_tmp);
92 +
93 + /*
94 + * We need to drop the lock, so take an explicit copy
95 + * of the ep context.
96 + */
97 + xhci_endpoint_copy(xhci, command->in_ctx, vdev->in_ctx, ep_index);
98 +
99 + ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx);
100 + if (!ctrl_ctx) {
101 + xhci_warn(xhci,
102 + "%s: Could not get input context, bad type.\n",
103 + __func__);
104 + spin_unlock_irqrestore(&xhci->lock, flags);
105 + xhci_free_command(xhci, command);
106 + mutex_unlock(&xhci->mutex);
107 + return;
108 + }
109 + ctrl_ctx->add_flags = xhci_get_endpoint_flag_from_index(ep_index);
110 + ctrl_ctx->drop_flags = 0;
111 +
112 + spin_unlock_irqrestore(&xhci->lock, flags);
113 +
114 + ret = xhci_configure_endpoint(xhci, udev, command,
115 + false, false);
116 + if (ret)
117 + xhci_warn(xhci, "%s: Configure endpoint failed: %d\n",
118 + __func__, ret);
119 + xhci_free_command(xhci, command);
120 + mutex_unlock(&xhci->mutex);
121 +}
122 +
123 +/*
124 * non-error returns are a promise to giveback() the urb later
125 * we drop ownership so next owner (or urb unlink) can get it
126 */
127 @@ -5381,6 +5484,7 @@ static const struct hc_driver xhci_hc_dr
128 .endpoint_reset = xhci_endpoint_reset,
129 .check_bandwidth = xhci_check_bandwidth,
130 .reset_bandwidth = xhci_reset_bandwidth,
131 + .fixup_endpoint = xhci_fixup_endpoint,
132 .address_device = xhci_address_device,
133 .enable_device = xhci_enable_device,
134 .update_hub_device = xhci_update_hub_device,