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