Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 2 | /* |
| 3 | * USB HOST XHCI Controller stack |
| 4 | * |
| 5 | * Based on xHCI host controller driver in linux-kernel |
| 6 | * by Sarah Sharp. |
| 7 | * |
| 8 | * Copyright (C) 2008 Intel Corp. |
| 9 | * Author: Sarah Sharp |
| 10 | * |
| 11 | * Copyright (C) 2013 Samsung Electronics Co.Ltd |
| 12 | * Authors: Vivek Gautam <gautam.vivek@samsung.com> |
| 13 | * Vikas Sajjan <vikas.sajjan@samsung.com> |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <common.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 17 | #include <cpu_func.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 18 | #include <log.h> |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 19 | #include <asm/byteorder.h> |
| 20 | #include <usb.h> |
| 21 | #include <asm/unaligned.h> |
Simon Glass | c06c1be | 2020-05-10 11:40:08 -0600 | [diff] [blame] | 22 | #include <linux/bug.h> |
Masahiro Yamada | 64e4f7f | 2016-09-21 11:28:57 +0900 | [diff] [blame] | 23 | #include <linux/errno.h> |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 24 | |
Jean-Jacques Hiblot | ad4142b | 2019-09-11 11:33:46 +0200 | [diff] [blame] | 25 | #include <usb/xhci.h> |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 26 | |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 27 | /* |
| 28 | * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA |
| 29 | * address of the TRB. |
| 30 | */ |
| 31 | dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, |
| 32 | union xhci_trb *trb) |
| 33 | { |
| 34 | unsigned long segment_offset; |
| 35 | |
| 36 | if (!seg || !trb || trb < seg->trbs) |
| 37 | return 0; |
| 38 | /* offset in TRBs */ |
| 39 | segment_offset = trb - seg->trbs; |
| 40 | if (segment_offset >= TRBS_PER_SEGMENT) |
| 41 | return 0; |
| 42 | return seg->dma + (segment_offset * sizeof(*trb)); |
| 43 | } |
| 44 | |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 45 | /** |
| 46 | * Is this TRB a link TRB or was the last TRB the last TRB in this event ring |
| 47 | * segment? I.e. would the updated event TRB pointer step off the end of the |
| 48 | * event seg ? |
| 49 | * |
| 50 | * @param ctrl Host controller data structure |
| 51 | * @param ring pointer to the ring |
| 52 | * @param seg poniter to the segment to which TRB belongs |
| 53 | * @param trb poniter to the ring trb |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 54 | * Return: 1 if this TRB a link TRB else 0 |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 55 | */ |
| 56 | static int last_trb(struct xhci_ctrl *ctrl, struct xhci_ring *ring, |
| 57 | struct xhci_segment *seg, union xhci_trb *trb) |
| 58 | { |
| 59 | if (ring == ctrl->event_ring) |
| 60 | return trb == &seg->trbs[TRBS_PER_SEGMENT]; |
| 61 | else |
| 62 | return TRB_TYPE_LINK_LE32(trb->link.control); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Does this link TRB point to the first segment in a ring, |
| 67 | * or was the previous TRB the last TRB on the last segment in the ERST? |
| 68 | * |
| 69 | * @param ctrl Host controller data structure |
| 70 | * @param ring pointer to the ring |
| 71 | * @param seg poniter to the segment to which TRB belongs |
| 72 | * @param trb poniter to the ring trb |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 73 | * Return: 1 if this TRB is the last TRB on the last segment else 0 |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 74 | */ |
| 75 | static bool last_trb_on_last_seg(struct xhci_ctrl *ctrl, |
| 76 | struct xhci_ring *ring, |
| 77 | struct xhci_segment *seg, |
| 78 | union xhci_trb *trb) |
| 79 | { |
| 80 | if (ring == ctrl->event_ring) |
| 81 | return ((trb == &seg->trbs[TRBS_PER_SEGMENT]) && |
| 82 | (seg->next == ring->first_seg)); |
| 83 | else |
| 84 | return le32_to_cpu(trb->link.control) & LINK_TOGGLE; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * See Cycle bit rules. SW is the consumer for the event ring only. |
| 89 | * Don't make a ring full of link TRBs. That would be dumb and this would loop. |
| 90 | * |
| 91 | * If we've just enqueued a TRB that is in the middle of a TD (meaning the |
| 92 | * chain bit is set), then set the chain bit in all the following link TRBs. |
| 93 | * If we've enqueued the last TRB in a TD, make sure the following link TRBs |
| 94 | * have their chain bit cleared (so that each Link TRB is a separate TD). |
| 95 | * |
| 96 | * Section 6.4.4.1 of the 0.95 spec says link TRBs cannot have the chain bit |
| 97 | * set, but other sections talk about dealing with the chain bit set. This was |
| 98 | * fixed in the 0.96 specification errata, but we have to assume that all 0.95 |
| 99 | * xHCI hardware can't handle the chain bit being cleared on a link TRB. |
| 100 | * |
| 101 | * @param ctrl Host controller data structure |
| 102 | * @param ring pointer to the ring |
| 103 | * @param more_trbs_coming flag to indicate whether more trbs |
| 104 | * are expected or NOT. |
| 105 | * Will you enqueue more TRBs before calling |
| 106 | * prepare_ring()? |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 107 | * Return: none |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 108 | */ |
| 109 | static void inc_enq(struct xhci_ctrl *ctrl, struct xhci_ring *ring, |
| 110 | bool more_trbs_coming) |
| 111 | { |
| 112 | u32 chain; |
| 113 | union xhci_trb *next; |
| 114 | |
| 115 | chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN; |
| 116 | next = ++(ring->enqueue); |
| 117 | |
| 118 | /* |
| 119 | * Update the dequeue pointer further if that was a link TRB or we're at |
| 120 | * the end of an event ring segment (which doesn't have link TRBS) |
| 121 | */ |
| 122 | while (last_trb(ctrl, ring, ring->enq_seg, next)) { |
| 123 | if (ring != ctrl->event_ring) { |
| 124 | /* |
| 125 | * If the caller doesn't plan on enqueueing more |
| 126 | * TDs before ringing the doorbell, then we |
| 127 | * don't want to give the link TRB to the |
| 128 | * hardware just yet. We'll give the link TRB |
| 129 | * back in prepare_ring() just before we enqueue |
| 130 | * the TD at the top of the ring. |
| 131 | */ |
| 132 | if (!chain && !more_trbs_coming) |
| 133 | break; |
| 134 | |
| 135 | /* |
| 136 | * If we're not dealing with 0.95 hardware or |
| 137 | * isoc rings on AMD 0.96 host, |
| 138 | * carry over the chain bit of the previous TRB |
| 139 | * (which may mean the chain bit is cleared). |
| 140 | */ |
| 141 | next->link.control &= cpu_to_le32(~TRB_CHAIN); |
| 142 | next->link.control |= cpu_to_le32(chain); |
| 143 | |
| 144 | next->link.control ^= cpu_to_le32(TRB_CYCLE); |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 145 | xhci_flush_cache((uintptr_t)next, |
| 146 | sizeof(union xhci_trb)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 147 | } |
| 148 | /* Toggle the cycle bit after the last ring segment. */ |
| 149 | if (last_trb_on_last_seg(ctrl, ring, |
| 150 | ring->enq_seg, next)) |
| 151 | ring->cycle_state = (ring->cycle_state ? 0 : 1); |
| 152 | |
| 153 | ring->enq_seg = ring->enq_seg->next; |
| 154 | ring->enqueue = ring->enq_seg->trbs; |
| 155 | next = ring->enqueue; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * See Cycle bit rules. SW is the consumer for the event ring only. |
| 161 | * Don't make a ring full of link TRBs. That would be dumb and this would loop. |
| 162 | * |
| 163 | * @param ctrl Host controller data structure |
| 164 | * @param ring Ring whose Dequeue TRB pointer needs to be incremented. |
| 165 | * return none |
| 166 | */ |
| 167 | static void inc_deq(struct xhci_ctrl *ctrl, struct xhci_ring *ring) |
| 168 | { |
| 169 | do { |
| 170 | /* |
| 171 | * Update the dequeue pointer further if that was a link TRB or |
| 172 | * we're at the end of an event ring segment (which doesn't have |
| 173 | * link TRBS) |
| 174 | */ |
| 175 | if (last_trb(ctrl, ring, ring->deq_seg, ring->dequeue)) { |
| 176 | if (ring == ctrl->event_ring && |
| 177 | last_trb_on_last_seg(ctrl, ring, |
| 178 | ring->deq_seg, ring->dequeue)) { |
| 179 | ring->cycle_state = (ring->cycle_state ? 0 : 1); |
| 180 | } |
| 181 | ring->deq_seg = ring->deq_seg->next; |
| 182 | ring->dequeue = ring->deq_seg->trbs; |
| 183 | } else { |
| 184 | ring->dequeue++; |
| 185 | } |
| 186 | } while (last_trb(ctrl, ring, ring->deq_seg, ring->dequeue)); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Generic function for queueing a TRB on a ring. |
| 191 | * The caller must have checked to make sure there's room on the ring. |
| 192 | * |
| 193 | * @param more_trbs_coming: Will you enqueue more TRBs before calling |
| 194 | * prepare_ring()? |
| 195 | * @param ctrl Host controller data structure |
| 196 | * @param ring pointer to the ring |
| 197 | * @param more_trbs_coming flag to indicate whether more trbs |
| 198 | * @param trb_fields pointer to trb field array containing TRB contents |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 199 | * Return: pointer to the enqueued trb |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 200 | */ |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 201 | static dma_addr_t queue_trb(struct xhci_ctrl *ctrl, struct xhci_ring *ring, |
| 202 | bool more_trbs_coming, unsigned int *trb_fields) |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 203 | { |
| 204 | struct xhci_generic_trb *trb; |
| 205 | int i; |
| 206 | |
| 207 | trb = &ring->enqueue->generic; |
| 208 | |
| 209 | for (i = 0; i < 4; i++) |
| 210 | trb->field[i] = cpu_to_le32(trb_fields[i]); |
| 211 | |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 212 | xhci_flush_cache((uintptr_t)trb, sizeof(struct xhci_generic_trb)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 213 | |
| 214 | inc_enq(ctrl, ring, more_trbs_coming); |
| 215 | |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 216 | return xhci_trb_virt_to_dma(ring->enq_seg, (union xhci_trb *)trb); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Does various checks on the endpoint ring, and makes it ready |
| 221 | * to queue num_trbs. |
| 222 | * |
| 223 | * @param ctrl Host controller data structure |
| 224 | * @param ep_ring pointer to the EP Transfer Ring |
| 225 | * @param ep_state State of the End Point |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 226 | * Return: error code in case of invalid ep_state, 0 on success |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 227 | */ |
| 228 | static int prepare_ring(struct xhci_ctrl *ctrl, struct xhci_ring *ep_ring, |
| 229 | u32 ep_state) |
| 230 | { |
| 231 | union xhci_trb *next = ep_ring->enqueue; |
| 232 | |
| 233 | /* Make sure the endpoint has been added to xHC schedule */ |
| 234 | switch (ep_state) { |
| 235 | case EP_STATE_DISABLED: |
| 236 | /* |
| 237 | * USB core changed config/interfaces without notifying us, |
| 238 | * or hardware is reporting the wrong state. |
| 239 | */ |
| 240 | puts("WARN urb submitted to disabled ep\n"); |
| 241 | return -ENOENT; |
| 242 | case EP_STATE_ERROR: |
| 243 | puts("WARN waiting for error on ep to be cleared\n"); |
| 244 | return -EINVAL; |
| 245 | case EP_STATE_HALTED: |
Hector Martin | 1b823e2 | 2023-10-29 15:37:42 +0900 | [diff] [blame^] | 246 | puts("WARN endpoint is halted\n"); |
| 247 | return -EINVAL; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 248 | case EP_STATE_STOPPED: |
| 249 | case EP_STATE_RUNNING: |
| 250 | debug("EP STATE RUNNING.\n"); |
| 251 | break; |
| 252 | default: |
| 253 | puts("ERROR unknown endpoint state for ep\n"); |
| 254 | return -EINVAL; |
| 255 | } |
| 256 | |
| 257 | while (last_trb(ctrl, ep_ring, ep_ring->enq_seg, next)) { |
| 258 | /* |
| 259 | * If we're not dealing with 0.95 hardware or isoc rings |
| 260 | * on AMD 0.96 host, clear the chain bit. |
| 261 | */ |
| 262 | next->link.control &= cpu_to_le32(~TRB_CHAIN); |
| 263 | |
| 264 | next->link.control ^= cpu_to_le32(TRB_CYCLE); |
| 265 | |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 266 | xhci_flush_cache((uintptr_t)next, sizeof(union xhci_trb)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 267 | |
| 268 | /* Toggle the cycle bit after the last ring segment. */ |
| 269 | if (last_trb_on_last_seg(ctrl, ep_ring, |
| 270 | ep_ring->enq_seg, next)) |
| 271 | ep_ring->cycle_state = (ep_ring->cycle_state ? 0 : 1); |
| 272 | ep_ring->enq_seg = ep_ring->enq_seg->next; |
| 273 | ep_ring->enqueue = ep_ring->enq_seg->trbs; |
| 274 | next = ep_ring->enqueue; |
| 275 | } |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Generic function for queueing a command TRB on the command ring. |
| 282 | * Check to make sure there's room on the command ring for one command TRB. |
| 283 | * |
| 284 | * @param ctrl Host controller data structure |
| 285 | * @param ptr Pointer address to write in the first two fields (opt.) |
| 286 | * @param slot_id Slot ID to encode in the flags field (opt.) |
| 287 | * @param ep_index Endpoint index to encode in the flags field (opt.) |
| 288 | * @param cmd Command type to enqueue |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 289 | * Return: none |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 290 | */ |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 291 | void xhci_queue_command(struct xhci_ctrl *ctrl, dma_addr_t addr, u32 slot_id, |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 292 | u32 ep_index, trb_type cmd) |
| 293 | { |
| 294 | u32 fields[4]; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 295 | |
| 296 | BUG_ON(prepare_ring(ctrl, ctrl->cmd_ring, EP_STATE_RUNNING)); |
| 297 | |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 298 | fields[0] = lower_32_bits(addr); |
| 299 | fields[1] = upper_32_bits(addr); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 300 | fields[2] = 0; |
Bin Meng | 474b250 | 2017-07-19 21:49:54 +0800 | [diff] [blame] | 301 | fields[3] = TRB_TYPE(cmd) | SLOT_ID_FOR_TRB(slot_id) | |
| 302 | ctrl->cmd_ring->cycle_state; |
| 303 | |
| 304 | /* |
| 305 | * Only 'reset endpoint', 'stop endpoint' and 'set TR dequeue pointer' |
| 306 | * commands need endpoint id encoded. |
| 307 | */ |
| 308 | if (cmd >= TRB_RESET_EP && cmd <= TRB_SET_DEQ) |
| 309 | fields[3] |= EP_ID_FOR_TRB(ep_index); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 310 | |
| 311 | queue_trb(ctrl, ctrl->cmd_ring, false, fields); |
| 312 | |
| 313 | /* Ring the command ring doorbell */ |
| 314 | xhci_writel(&ctrl->dba->doorbell[0], DB_VALUE_HOST); |
| 315 | } |
| 316 | |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 317 | /* |
| 318 | * For xHCI 1.0 host controllers, TD size is the number of max packet sized |
| 319 | * packets remaining in the TD (*not* including this TRB). |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 320 | * |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 321 | * Total TD packet count = total_packet_count = |
| 322 | * DIV_ROUND_UP(TD size in bytes / wMaxPacketSize) |
| 323 | * |
| 324 | * Packets transferred up to and including this TRB = packets_transferred = |
| 325 | * rounddown(total bytes transferred including this TRB / wMaxPacketSize) |
| 326 | * |
| 327 | * TD size = total_packet_count - packets_transferred |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 328 | * |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 329 | * For xHCI 0.96 and older, TD size field should be the remaining bytes |
| 330 | * including this TRB, right shifted by 10 |
| 331 | * |
| 332 | * For all hosts it must fit in bits 21:17, so it can't be bigger than 31. |
| 333 | * This is taken care of in the TRB_TD_SIZE() macro |
| 334 | * |
| 335 | * The last TRB in a TD must have the TD size set to zero. |
| 336 | * |
| 337 | * @param ctrl host controller data structure |
| 338 | * @param transferred total size sent so far |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 339 | * @param trb_buff_len length of the TRB Buffer |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 340 | * @param td_total_len total packet count |
| 341 | * @param maxp max packet size of current pipe |
| 342 | * @param more_trbs_coming indicate last trb in TD |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 343 | * Return: remainder |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 344 | */ |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 345 | static u32 xhci_td_remainder(struct xhci_ctrl *ctrl, int transferred, |
| 346 | int trb_buff_len, unsigned int td_total_len, |
| 347 | int maxp, bool more_trbs_coming) |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 348 | { |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 349 | u32 total_packet_count; |
| 350 | |
developer | 8039053 | 2020-09-08 18:59:57 +0200 | [diff] [blame] | 351 | /* MTK xHCI 0.96 contains some features from 1.0 */ |
| 352 | if (ctrl->hci_version < 0x100 && !(ctrl->quirks & XHCI_MTK_HOST)) |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 353 | return ((td_total_len - transferred) >> 10); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 354 | |
| 355 | /* One TRB with a zero-length data packet. */ |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 356 | if (!more_trbs_coming || (transferred == 0 && trb_buff_len == 0) || |
| 357 | trb_buff_len == td_total_len) |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 358 | return 0; |
| 359 | |
developer | 8039053 | 2020-09-08 18:59:57 +0200 | [diff] [blame] | 360 | /* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */ |
| 361 | if ((ctrl->quirks & XHCI_MTK_HOST) && (ctrl->hci_version < 0x100)) |
| 362 | trb_buff_len = 0; |
| 363 | |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 364 | total_packet_count = DIV_ROUND_UP(td_total_len, maxp); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 365 | |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 366 | /* Queueing functions don't count the current TRB into transferred */ |
| 367 | return (total_packet_count - ((transferred + trb_buff_len) / maxp)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Ring the doorbell of the End Point |
| 372 | * |
| 373 | * @param udev pointer to the USB device structure |
| 374 | * @param ep_index index of the endpoint |
| 375 | * @param start_cycle cycle flag of the first TRB |
| 376 | * @param start_trb pionter to the first TRB |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 377 | * Return: none |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 378 | */ |
| 379 | static void giveback_first_trb(struct usb_device *udev, int ep_index, |
| 380 | int start_cycle, |
| 381 | struct xhci_generic_trb *start_trb) |
| 382 | { |
Simon Glass | a49e27b | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 383 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 384 | |
| 385 | /* |
| 386 | * Pass all the TRBs to the hardware at once and make sure this write |
| 387 | * isn't reordered. |
| 388 | */ |
| 389 | if (start_cycle) |
| 390 | start_trb->field[3] |= cpu_to_le32(start_cycle); |
| 391 | else |
| 392 | start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE); |
| 393 | |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 394 | xhci_flush_cache((uintptr_t)start_trb, sizeof(struct xhci_generic_trb)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 395 | |
| 396 | /* Ringing EP doorbell here */ |
| 397 | xhci_writel(&ctrl->dba->doorbell[udev->slot_id], |
| 398 | DB_VALUE(ep_index, 0)); |
| 399 | |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | /**** POLLING mechanism for XHCI ****/ |
| 404 | |
| 405 | /** |
| 406 | * Finalizes a handled event TRB by advancing our dequeue pointer and giving |
| 407 | * the TRB back to the hardware for recycling. Must call this exactly once at |
| 408 | * the end of each event handler, and not touch the TRB again afterwards. |
| 409 | * |
| 410 | * @param ctrl Host controller data structure |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 411 | * Return: none |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 412 | */ |
| 413 | void xhci_acknowledge_event(struct xhci_ctrl *ctrl) |
| 414 | { |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 415 | dma_addr_t deq; |
| 416 | |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 417 | /* Advance our dequeue pointer to the next event */ |
| 418 | inc_deq(ctrl, ctrl->event_ring); |
| 419 | |
| 420 | /* Inform the hardware */ |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 421 | deq = xhci_trb_virt_to_dma(ctrl->event_ring->deq_seg, |
| 422 | ctrl->event_ring->dequeue); |
| 423 | xhci_writeq(&ctrl->ir_set->erst_dequeue, deq | ERST_EHB); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Checks if there is a new event to handle on the event ring. |
| 428 | * |
| 429 | * @param ctrl Host controller data structure |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 430 | * Return: 0 if failure else 1 on success |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 431 | */ |
| 432 | static int event_ready(struct xhci_ctrl *ctrl) |
| 433 | { |
| 434 | union xhci_trb *event; |
| 435 | |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 436 | xhci_inval_cache((uintptr_t)ctrl->event_ring->dequeue, |
| 437 | sizeof(union xhci_trb)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 438 | |
| 439 | event = ctrl->event_ring->dequeue; |
| 440 | |
| 441 | /* Does the HC or OS own the TRB? */ |
| 442 | if ((le32_to_cpu(event->event_cmd.flags) & TRB_CYCLE) != |
| 443 | ctrl->event_ring->cycle_state) |
| 444 | return 0; |
| 445 | |
| 446 | return 1; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Waits for a specific type of event and returns it. Discards unexpected |
| 451 | * events. Caller *must* call xhci_acknowledge_event() after it is finished |
| 452 | * processing the event, and must not access the returned pointer afterwards. |
| 453 | * |
| 454 | * @param ctrl Host controller data structure |
| 455 | * @param expected TRB type expected from Event TRB |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 456 | * Return: pointer to event trb |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 457 | */ |
| 458 | union xhci_trb *xhci_wait_for_event(struct xhci_ctrl *ctrl, trb_type expected) |
| 459 | { |
| 460 | trb_type type; |
| 461 | unsigned long ts = get_timer(0); |
| 462 | |
| 463 | do { |
| 464 | union xhci_trb *event = ctrl->event_ring->dequeue; |
| 465 | |
| 466 | if (!event_ready(ctrl)) |
| 467 | continue; |
| 468 | |
| 469 | type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->event_cmd.flags)); |
Hector Martin | 191772f | 2023-10-29 15:37:39 +0900 | [diff] [blame] | 470 | if (type == expected || |
| 471 | (expected == TRB_NONE && type != TRB_PORT_STATUS)) |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 472 | return event; |
| 473 | |
| 474 | if (type == TRB_PORT_STATUS) |
| 475 | /* TODO: remove this once enumeration has been reworked */ |
| 476 | /* |
| 477 | * Port status change events always have a |
| 478 | * successful completion code |
| 479 | */ |
| 480 | BUG_ON(GET_COMP_CODE( |
| 481 | le32_to_cpu(event->generic.field[2])) != |
| 482 | COMP_SUCCESS); |
| 483 | else |
| 484 | printf("Unexpected XHCI event TRB, skipping... " |
| 485 | "(%08x %08x %08x %08x)\n", |
| 486 | le32_to_cpu(event->generic.field[0]), |
| 487 | le32_to_cpu(event->generic.field[1]), |
| 488 | le32_to_cpu(event->generic.field[2]), |
| 489 | le32_to_cpu(event->generic.field[3])); |
| 490 | |
| 491 | xhci_acknowledge_event(ctrl); |
| 492 | } while (get_timer(ts) < XHCI_TIMEOUT); |
| 493 | |
| 494 | if (expected == TRB_TRANSFER) |
| 495 | return NULL; |
| 496 | |
| 497 | printf("XHCI timeout on event type %d... cannot recover.\n", expected); |
| 498 | BUG(); |
| 499 | } |
| 500 | |
| 501 | /* |
Stefan Agner | ec2b73d | 2021-09-27 14:42:58 +0200 | [diff] [blame] | 502 | * Send reset endpoint command for given endpoint. This recovers from a |
| 503 | * halted endpoint (e.g. due to a stall error). |
| 504 | */ |
| 505 | static void reset_ep(struct usb_device *udev, int ep_index) |
| 506 | { |
| 507 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
| 508 | struct xhci_ring *ring = ctrl->devs[udev->slot_id]->eps[ep_index].ring; |
| 509 | union xhci_trb *event; |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 510 | u64 addr; |
Stefan Agner | ec2b73d | 2021-09-27 14:42:58 +0200 | [diff] [blame] | 511 | u32 field; |
| 512 | |
| 513 | printf("Resetting EP %d...\n", ep_index); |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 514 | xhci_queue_command(ctrl, 0, udev->slot_id, ep_index, TRB_RESET_EP); |
Stefan Agner | ec2b73d | 2021-09-27 14:42:58 +0200 | [diff] [blame] | 515 | event = xhci_wait_for_event(ctrl, TRB_COMPLETION); |
Hector Martin | c5d7dac | 2023-10-29 15:37:38 +0900 | [diff] [blame] | 516 | if (!event) |
| 517 | return; |
| 518 | |
Stefan Agner | ec2b73d | 2021-09-27 14:42:58 +0200 | [diff] [blame] | 519 | field = le32_to_cpu(event->trans_event.flags); |
| 520 | BUG_ON(TRB_TO_SLOT_ID(field) != udev->slot_id); |
| 521 | xhci_acknowledge_event(ctrl); |
| 522 | |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 523 | addr = xhci_trb_virt_to_dma(ring->enq_seg, |
| 524 | (void *)((uintptr_t)ring->enqueue | ring->cycle_state)); |
| 525 | xhci_queue_command(ctrl, addr, udev->slot_id, ep_index, TRB_SET_DEQ); |
Stefan Agner | ec2b73d | 2021-09-27 14:42:58 +0200 | [diff] [blame] | 526 | event = xhci_wait_for_event(ctrl, TRB_COMPLETION); |
Hector Martin | c5d7dac | 2023-10-29 15:37:38 +0900 | [diff] [blame] | 527 | if (!event) |
| 528 | return; |
| 529 | |
Stefan Agner | ec2b73d | 2021-09-27 14:42:58 +0200 | [diff] [blame] | 530 | BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)) |
| 531 | != udev->slot_id || GET_COMP_CODE(le32_to_cpu( |
| 532 | event->event_cmd.status)) != COMP_SUCCESS); |
| 533 | xhci_acknowledge_event(ctrl); |
| 534 | } |
| 535 | |
| 536 | /* |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 537 | * Stops transfer processing for an endpoint and throws away all unprocessed |
| 538 | * TRBs by setting the xHC's dequeue pointer to our enqueue pointer. The next |
| 539 | * xhci_bulk_tx/xhci_ctrl_tx on this enpoint will add new transfers there and |
| 540 | * ring the doorbell, causing this endpoint to start working again. |
| 541 | * (Careful: This will BUG() when there was no transfer in progress. Shouldn't |
| 542 | * happen in practice for current uses and is too complicated to fix right now.) |
| 543 | */ |
| 544 | static void abort_td(struct usb_device *udev, int ep_index) |
| 545 | { |
Simon Glass | a49e27b | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 546 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 547 | struct xhci_ring *ring = ctrl->devs[udev->slot_id]->eps[ep_index].ring; |
| 548 | union xhci_trb *event; |
Hector Martin | f28db6b | 2023-10-29 15:37:40 +0900 | [diff] [blame] | 549 | xhci_comp_code comp; |
Hector Martin | 191772f | 2023-10-29 15:37:39 +0900 | [diff] [blame] | 550 | trb_type type; |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 551 | u64 addr; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 552 | u32 field; |
| 553 | |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 554 | xhci_queue_command(ctrl, 0, udev->slot_id, ep_index, TRB_STOP_RING); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 555 | |
Hector Martin | 191772f | 2023-10-29 15:37:39 +0900 | [diff] [blame] | 556 | event = xhci_wait_for_event(ctrl, TRB_NONE); |
Hector Martin | c5d7dac | 2023-10-29 15:37:38 +0900 | [diff] [blame] | 557 | if (!event) |
| 558 | return; |
| 559 | |
Hector Martin | 191772f | 2023-10-29 15:37:39 +0900 | [diff] [blame] | 560 | type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->event_cmd.flags)); |
| 561 | if (type == TRB_TRANSFER) { |
| 562 | field = le32_to_cpu(event->trans_event.flags); |
| 563 | BUG_ON(TRB_TO_SLOT_ID(field) != udev->slot_id); |
| 564 | BUG_ON(TRB_TO_EP_INDEX(field) != ep_index); |
| 565 | BUG_ON(GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len |
| 566 | != COMP_STOP))); |
| 567 | xhci_acknowledge_event(ctrl); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 568 | |
Hector Martin | 191772f | 2023-10-29 15:37:39 +0900 | [diff] [blame] | 569 | event = xhci_wait_for_event(ctrl, TRB_COMPLETION); |
| 570 | if (!event) |
| 571 | return; |
| 572 | type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->event_cmd.flags)); |
Hector Martin | c5d7dac | 2023-10-29 15:37:38 +0900 | [diff] [blame] | 573 | |
Hector Martin | 191772f | 2023-10-29 15:37:39 +0900 | [diff] [blame] | 574 | } else { |
| 575 | printf("abort_td: Expected a TRB_TRANSFER TRB first\n"); |
| 576 | } |
| 577 | |
Hector Martin | f28db6b | 2023-10-29 15:37:40 +0900 | [diff] [blame] | 578 | comp = GET_COMP_CODE(le32_to_cpu(event->event_cmd.status)); |
Hector Martin | 191772f | 2023-10-29 15:37:39 +0900 | [diff] [blame] | 579 | BUG_ON(type != TRB_COMPLETION || |
| 580 | TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)) |
Hector Martin | f28db6b | 2023-10-29 15:37:40 +0900 | [diff] [blame] | 581 | != udev->slot_id || (comp != COMP_SUCCESS && comp |
| 582 | != COMP_CTX_STATE)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 583 | xhci_acknowledge_event(ctrl); |
| 584 | |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 585 | addr = xhci_trb_virt_to_dma(ring->enq_seg, |
| 586 | (void *)((uintptr_t)ring->enqueue | ring->cycle_state)); |
| 587 | xhci_queue_command(ctrl, addr, udev->slot_id, ep_index, TRB_SET_DEQ); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 588 | event = xhci_wait_for_event(ctrl, TRB_COMPLETION); |
Hector Martin | c5d7dac | 2023-10-29 15:37:38 +0900 | [diff] [blame] | 589 | if (!event) |
| 590 | return; |
| 591 | |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 592 | BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags)) |
| 593 | != udev->slot_id || GET_COMP_CODE(le32_to_cpu( |
| 594 | event->event_cmd.status)) != COMP_SUCCESS); |
| 595 | xhci_acknowledge_event(ctrl); |
| 596 | } |
| 597 | |
| 598 | static void record_transfer_result(struct usb_device *udev, |
| 599 | union xhci_trb *event, int length) |
| 600 | { |
| 601 | udev->act_len = min(length, length - |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 602 | (int)EVENT_TRB_LEN(le32_to_cpu(event->trans_event.transfer_len))); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 603 | |
| 604 | switch (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len))) { |
| 605 | case COMP_SUCCESS: |
| 606 | BUG_ON(udev->act_len != length); |
| 607 | /* fallthrough */ |
| 608 | case COMP_SHORT_TX: |
| 609 | udev->status = 0; |
| 610 | break; |
| 611 | case COMP_STALL: |
| 612 | udev->status = USB_ST_STALLED; |
| 613 | break; |
| 614 | case COMP_DB_ERR: |
| 615 | case COMP_TRB_ERR: |
| 616 | udev->status = USB_ST_BUF_ERR; |
| 617 | break; |
| 618 | case COMP_BABBLE: |
| 619 | udev->status = USB_ST_BABBLE_DET; |
| 620 | break; |
| 621 | default: |
| 622 | udev->status = 0x80; /* USB_ST_TOO_LAZY_TO_MAKE_A_NEW_MACRO */ |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | /**** Bulk and Control transfer methods ****/ |
| 627 | /** |
| 628 | * Queues up the BULK Request |
| 629 | * |
| 630 | * @param udev pointer to the USB device structure |
| 631 | * @param pipe contains the DIR_IN or OUT , devnum |
| 632 | * @param length length of the buffer |
| 633 | * @param buffer buffer to be read/written based on the request |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 634 | * Return: returns 0 if successful else -1 on failure |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 635 | */ |
| 636 | int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe, |
| 637 | int length, void *buffer) |
| 638 | { |
| 639 | int num_trbs = 0; |
| 640 | struct xhci_generic_trb *start_trb; |
Gustavo A. R. Silva | 0a1ef7c | 2018-01-20 02:37:31 -0600 | [diff] [blame] | 641 | bool first_trb = false; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 642 | int start_cycle; |
| 643 | u32 field = 0; |
| 644 | u32 length_field = 0; |
Simon Glass | a49e27b | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 645 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 646 | int slot_id = udev->slot_id; |
| 647 | int ep_index; |
| 648 | struct xhci_virt_device *virt_dev; |
| 649 | struct xhci_ep_ctx *ep_ctx; |
| 650 | struct xhci_ring *ring; /* EP transfer ring */ |
| 651 | union xhci_trb *event; |
| 652 | |
| 653 | int running_total, trb_buff_len; |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 654 | bool more_trbs_coming = true; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 655 | int maxpacketsize; |
| 656 | u64 addr; |
| 657 | int ret; |
| 658 | u32 trb_fields[4]; |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 659 | u64 buf_64 = xhci_dma_map(ctrl, buffer, length); |
| 660 | dma_addr_t last_transfer_trb_addr; |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 661 | int available_length; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 662 | |
| 663 | debug("dev=%p, pipe=%lx, buffer=%p, length=%d\n", |
| 664 | udev, pipe, buffer, length); |
| 665 | |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 666 | available_length = length; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 667 | ep_index = usb_pipe_ep_index(pipe); |
| 668 | virt_dev = ctrl->devs[slot_id]; |
| 669 | |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 670 | xhci_inval_cache((uintptr_t)virt_dev->out_ctx->bytes, |
| 671 | virt_dev->out_ctx->size); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 672 | |
| 673 | ep_ctx = xhci_get_ep_ctx(ctrl, virt_dev->out_ctx, ep_index); |
| 674 | |
Hector Martin | 6d20437 | 2023-10-29 15:37:41 +0900 | [diff] [blame] | 675 | /* |
| 676 | * If the endpoint was halted due to a prior error, resume it before |
| 677 | * the next transfer. It is the responsibility of the upper layer to |
| 678 | * have dealt with whatever caused the error. |
| 679 | */ |
| 680 | if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) == EP_STATE_HALTED) |
| 681 | reset_ep(udev, ep_index); |
| 682 | |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 683 | ring = virt_dev->eps[ep_index].ring; |
| 684 | /* |
| 685 | * How much data is (potentially) left before the 64KB boundary? |
| 686 | * XHCI Spec puts restriction( TABLE 49 and 6.4.1 section of XHCI Spec) |
| 687 | * that the buffer should not span 64KB boundary. if so |
| 688 | * we send request in more than 1 TRB by chaining them. |
| 689 | */ |
| 690 | running_total = TRB_MAX_BUFF_SIZE - |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 691 | (lower_32_bits(buf_64) & (TRB_MAX_BUFF_SIZE - 1)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 692 | trb_buff_len = running_total; |
| 693 | running_total &= TRB_MAX_BUFF_SIZE - 1; |
| 694 | |
| 695 | /* |
| 696 | * If there's some data on this 64KB chunk, or we have to send a |
| 697 | * zero-length transfer, we need at least one TRB |
| 698 | */ |
| 699 | if (running_total != 0 || length == 0) |
| 700 | num_trbs++; |
| 701 | |
| 702 | /* How many more 64KB chunks to transfer, how many more TRBs? */ |
| 703 | while (running_total < length) { |
| 704 | num_trbs++; |
| 705 | running_total += TRB_MAX_BUFF_SIZE; |
| 706 | } |
| 707 | |
| 708 | /* |
| 709 | * XXX: Calling routine prepare_ring() called in place of |
| 710 | * prepare_trasfer() as there in 'Linux' since we are not |
| 711 | * maintaining multiple TDs/transfer at the same time. |
| 712 | */ |
| 713 | ret = prepare_ring(ctrl, ring, |
| 714 | le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK); |
| 715 | if (ret < 0) |
| 716 | return ret; |
| 717 | |
| 718 | /* |
| 719 | * Don't give the first TRB to the hardware (by toggling the cycle bit) |
| 720 | * until we've finished creating all the other TRBs. The ring's cycle |
| 721 | * state may change as we enqueue the other TRBs, so save it too. |
| 722 | */ |
| 723 | start_trb = &ring->enqueue->generic; |
| 724 | start_cycle = ring->cycle_state; |
| 725 | |
| 726 | running_total = 0; |
| 727 | maxpacketsize = usb_maxpacket(udev, pipe); |
| 728 | |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 729 | /* How much data is in the first TRB? */ |
| 730 | /* |
| 731 | * How much data is (potentially) left before the 64KB boundary? |
| 732 | * XHCI Spec puts restriction( TABLE 49 and 6.4.1 section of XHCI Spec) |
| 733 | * that the buffer should not span 64KB boundary. if so |
| 734 | * we send request in more than 1 TRB by chaining them. |
| 735 | */ |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 736 | addr = buf_64; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 737 | |
| 738 | if (trb_buff_len > length) |
| 739 | trb_buff_len = length; |
| 740 | |
| 741 | first_trb = true; |
| 742 | |
| 743 | /* flush the buffer before use */ |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 744 | xhci_flush_cache((uintptr_t)buffer, length); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 745 | |
| 746 | /* Queue the first TRB, even if it's zero-length */ |
| 747 | do { |
| 748 | u32 remainder = 0; |
| 749 | field = 0; |
| 750 | /* Don't change the cycle bit of the first TRB until later */ |
| 751 | if (first_trb) { |
| 752 | first_trb = false; |
| 753 | if (start_cycle == 0) |
| 754 | field |= TRB_CYCLE; |
| 755 | } else { |
| 756 | field |= ring->cycle_state; |
| 757 | } |
| 758 | |
| 759 | /* |
| 760 | * Chain all the TRBs together; clear the chain bit in the last |
| 761 | * TRB to indicate it's the last TRB in the chain. |
| 762 | */ |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 763 | if (num_trbs > 1) { |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 764 | field |= TRB_CHAIN; |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 765 | } else { |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 766 | field |= TRB_IOC; |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 767 | more_trbs_coming = false; |
| 768 | } |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 769 | |
| 770 | /* Only set interrupt on short packet for IN endpoints */ |
| 771 | if (usb_pipein(pipe)) |
| 772 | field |= TRB_ISP; |
| 773 | |
| 774 | /* Set the TRB length, TD size, and interrupter fields. */ |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 775 | remainder = xhci_td_remainder(ctrl, running_total, trb_buff_len, |
| 776 | length, maxpacketsize, |
| 777 | more_trbs_coming); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 778 | |
developer | 6cabb14 | 2020-09-08 19:00:00 +0200 | [diff] [blame] | 779 | length_field = (TRB_LEN(trb_buff_len) | |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 780 | TRB_TD_SIZE(remainder) | |
developer | 6cabb14 | 2020-09-08 19:00:00 +0200 | [diff] [blame] | 781 | TRB_INTR_TARGET(0)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 782 | |
| 783 | trb_fields[0] = lower_32_bits(addr); |
| 784 | trb_fields[1] = upper_32_bits(addr); |
| 785 | trb_fields[2] = length_field; |
developer | 497dcfa | 2020-09-08 18:59:59 +0200 | [diff] [blame] | 786 | trb_fields[3] = field | TRB_TYPE(TRB_NORMAL); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 787 | |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 788 | last_transfer_trb_addr = queue_trb(ctrl, ring, (num_trbs > 1), trb_fields); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 789 | |
| 790 | --num_trbs; |
| 791 | |
| 792 | running_total += trb_buff_len; |
| 793 | |
| 794 | /* Calculate length for next transfer */ |
| 795 | addr += trb_buff_len; |
| 796 | trb_buff_len = min((length - running_total), TRB_MAX_BUFF_SIZE); |
| 797 | } while (running_total < length); |
| 798 | |
| 799 | giveback_first_trb(udev, ep_index, start_cycle, start_trb); |
| 800 | |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 801 | again: |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 802 | event = xhci_wait_for_event(ctrl, TRB_TRANSFER); |
| 803 | if (!event) { |
| 804 | debug("XHCI bulk transfer timed out, aborting...\n"); |
| 805 | abort_td(udev, ep_index); |
| 806 | udev->status = USB_ST_NAK_REC; /* closest thing to a timeout */ |
| 807 | udev->act_len = 0; |
| 808 | return -ETIMEDOUT; |
| 809 | } |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 810 | |
Stefan Roese | 5e3c146 | 2021-01-15 08:52:56 +0100 | [diff] [blame] | 811 | if ((uintptr_t)(le64_to_cpu(event->trans_event.buffer)) != |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 812 | (uintptr_t)last_transfer_trb_addr) { |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 813 | available_length -= |
| 814 | (int)EVENT_TRB_LEN(le32_to_cpu(event->trans_event.transfer_len)); |
| 815 | xhci_acknowledge_event(ctrl); |
| 816 | goto again; |
| 817 | } |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 818 | |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 819 | field = le32_to_cpu(event->trans_event.flags); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 820 | BUG_ON(TRB_TO_SLOT_ID(field) != slot_id); |
| 821 | BUG_ON(TRB_TO_EP_INDEX(field) != ep_index); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 822 | |
Ran Wang | a050583 | 2020-11-18 15:49:02 +0800 | [diff] [blame] | 823 | record_transfer_result(udev, event, available_length); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 824 | xhci_acknowledge_event(ctrl); |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 825 | xhci_inval_cache((uintptr_t)buffer, length); |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 826 | xhci_dma_unmap(ctrl, buf_64, length); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 827 | |
| 828 | return (udev->status != USB_ST_NOT_PROC) ? 0 : -1; |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * Queues up the Control Transfer Request |
| 833 | * |
| 834 | * @param udev pointer to the USB device structure |
| 835 | * @param pipe contains the DIR_IN or OUT , devnum |
| 836 | * @param req request type |
| 837 | * @param length length of the buffer |
| 838 | * @param buffer buffer to be read/written based on the request |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 839 | * Return: returns 0 if successful else error code on failure |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 840 | */ |
| 841 | int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe, |
| 842 | struct devrequest *req, int length, |
| 843 | void *buffer) |
| 844 | { |
| 845 | int ret; |
| 846 | int start_cycle; |
| 847 | int num_trbs; |
| 848 | u32 field; |
| 849 | u32 length_field; |
| 850 | u64 buf_64 = 0; |
| 851 | struct xhci_generic_trb *start_trb; |
Simon Glass | a49e27b | 2015-03-25 12:22:49 -0600 | [diff] [blame] | 852 | struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 853 | int slot_id = udev->slot_id; |
| 854 | int ep_index; |
| 855 | u32 trb_fields[4]; |
| 856 | struct xhci_virt_device *virt_dev = ctrl->devs[slot_id]; |
| 857 | struct xhci_ring *ep_ring; |
| 858 | union xhci_trb *event; |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 859 | u32 remainder; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 860 | |
| 861 | debug("req=%u (%#x), type=%u (%#x), value=%u (%#x), index=%u\n", |
| 862 | req->request, req->request, |
| 863 | req->requesttype, req->requesttype, |
| 864 | le16_to_cpu(req->value), le16_to_cpu(req->value), |
| 865 | le16_to_cpu(req->index)); |
| 866 | |
| 867 | ep_index = usb_pipe_ep_index(pipe); |
| 868 | |
| 869 | ep_ring = virt_dev->eps[ep_index].ring; |
| 870 | |
| 871 | /* |
| 872 | * Check to see if the max packet size for the default control |
| 873 | * endpoint changed during FS device enumeration |
| 874 | */ |
| 875 | if (udev->speed == USB_SPEED_FULL) { |
| 876 | ret = xhci_check_maxpacket(udev); |
| 877 | if (ret < 0) |
| 878 | return ret; |
| 879 | } |
| 880 | |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 881 | xhci_inval_cache((uintptr_t)virt_dev->out_ctx->bytes, |
| 882 | virt_dev->out_ctx->size); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 883 | |
| 884 | struct xhci_ep_ctx *ep_ctx = NULL; |
| 885 | ep_ctx = xhci_get_ep_ctx(ctrl, virt_dev->out_ctx, ep_index); |
| 886 | |
| 887 | /* 1 TRB for setup, 1 for status */ |
| 888 | num_trbs = 2; |
| 889 | /* |
| 890 | * Don't need to check if we need additional event data and normal TRBs, |
| 891 | * since data in control transfers will never get bigger than 16MB |
| 892 | * XXX: can we get a buffer that crosses 64KB boundaries? |
| 893 | */ |
| 894 | |
| 895 | if (length > 0) |
| 896 | num_trbs++; |
| 897 | /* |
| 898 | * XXX: Calling routine prepare_ring() called in place of |
| 899 | * prepare_trasfer() as there in 'Linux' since we are not |
| 900 | * maintaining multiple TDs/transfer at the same time. |
| 901 | */ |
| 902 | ret = prepare_ring(ctrl, ep_ring, |
| 903 | le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK); |
| 904 | |
| 905 | if (ret < 0) |
| 906 | return ret; |
| 907 | |
| 908 | /* |
| 909 | * Don't give the first TRB to the hardware (by toggling the cycle bit) |
| 910 | * until we've finished creating all the other TRBs. The ring's cycle |
| 911 | * state may change as we enqueue the other TRBs, so save it too. |
| 912 | */ |
| 913 | start_trb = &ep_ring->enqueue->generic; |
| 914 | start_cycle = ep_ring->cycle_state; |
| 915 | |
| 916 | debug("start_trb %p, start_cycle %d\n", start_trb, start_cycle); |
| 917 | |
| 918 | /* Queue setup TRB - see section 6.4.1.2.1 */ |
| 919 | /* FIXME better way to translate setup_packet into two u32 fields? */ |
| 920 | field = 0; |
developer | 497dcfa | 2020-09-08 18:59:59 +0200 | [diff] [blame] | 921 | field |= TRB_IDT | TRB_TYPE(TRB_SETUP); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 922 | if (start_cycle == 0) |
| 923 | field |= 0x1; |
| 924 | |
| 925 | /* xHCI 1.0 6.4.1.2.1: Transfer Type field */ |
developer | 8039053 | 2020-09-08 18:59:57 +0200 | [diff] [blame] | 926 | if (ctrl->hci_version >= 0x100 || ctrl->quirks & XHCI_MTK_HOST) { |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 927 | if (length > 0) { |
| 928 | if (req->requesttype & USB_DIR_IN) |
developer | 57c052b | 2020-09-08 19:00:01 +0200 | [diff] [blame] | 929 | field |= TRB_TX_TYPE(TRB_DATA_IN); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 930 | else |
developer | 57c052b | 2020-09-08 19:00:01 +0200 | [diff] [blame] | 931 | field |= TRB_TX_TYPE(TRB_DATA_OUT); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
Stefan Roese | ede9de1 | 2021-04-06 12:10:18 +0200 | [diff] [blame] | 935 | debug("req->requesttype = %d, req->request = %d, req->value = %d, req->index = %d, req->length = %d\n", |
| 936 | req->requesttype, req->request, le16_to_cpu(req->value), |
| 937 | le16_to_cpu(req->index), le16_to_cpu(req->length)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 938 | |
| 939 | trb_fields[0] = req->requesttype | req->request << 8 | |
| 940 | le16_to_cpu(req->value) << 16; |
| 941 | trb_fields[1] = le16_to_cpu(req->index) | |
| 942 | le16_to_cpu(req->length) << 16; |
| 943 | /* TRB_LEN | (TRB_INTR_TARGET) */ |
developer | 6cabb14 | 2020-09-08 19:00:00 +0200 | [diff] [blame] | 944 | trb_fields[2] = (TRB_LEN(8) | TRB_INTR_TARGET(0)); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 945 | /* Immediate data in pointer */ |
| 946 | trb_fields[3] = field; |
| 947 | queue_trb(ctrl, ep_ring, true, trb_fields); |
| 948 | |
| 949 | /* Re-initializing field to zero */ |
| 950 | field = 0; |
| 951 | /* If there's data, queue data TRBs */ |
| 952 | /* Only set interrupt on short packet for IN endpoints */ |
| 953 | if (usb_pipein(pipe)) |
developer | 497dcfa | 2020-09-08 18:59:59 +0200 | [diff] [blame] | 954 | field = TRB_ISP | TRB_TYPE(TRB_DATA); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 955 | else |
developer | 497dcfa | 2020-09-08 18:59:59 +0200 | [diff] [blame] | 956 | field = TRB_TYPE(TRB_DATA); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 957 | |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 958 | remainder = xhci_td_remainder(ctrl, 0, length, length, |
| 959 | usb_maxpacket(udev, pipe), true); |
developer | 6cabb14 | 2020-09-08 19:00:00 +0200 | [diff] [blame] | 960 | length_field = TRB_LEN(length) | TRB_TD_SIZE(remainder) | |
| 961 | TRB_INTR_TARGET(0); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 962 | debug("length_field = %d, length = %d," |
| 963 | "xhci_td_remainder(length) = %d , TRB_INTR_TARGET(0) = %d\n", |
developer | 6cabb14 | 2020-09-08 19:00:00 +0200 | [diff] [blame] | 964 | length_field, TRB_LEN(length), |
developer | 570c2a9 | 2020-09-08 18:59:56 +0200 | [diff] [blame] | 965 | TRB_TD_SIZE(remainder), 0); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 966 | |
| 967 | if (length > 0) { |
| 968 | if (req->requesttype & USB_DIR_IN) |
| 969 | field |= TRB_DIR_IN; |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 970 | buf_64 = xhci_dma_map(ctrl, buffer, length); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 971 | |
| 972 | trb_fields[0] = lower_32_bits(buf_64); |
| 973 | trb_fields[1] = upper_32_bits(buf_64); |
| 974 | trb_fields[2] = length_field; |
| 975 | trb_fields[3] = field | ep_ring->cycle_state; |
| 976 | |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 977 | xhci_flush_cache((uintptr_t)buffer, length); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 978 | queue_trb(ctrl, ep_ring, true, trb_fields); |
| 979 | } |
| 980 | |
| 981 | /* |
| 982 | * Queue status TRB - |
| 983 | * see Table 7 and sections 4.11.2.2 and 6.4.1.2.3 |
| 984 | */ |
| 985 | |
| 986 | /* If the device sent data, the status stage is an OUT transfer */ |
| 987 | field = 0; |
| 988 | if (length > 0 && req->requesttype & USB_DIR_IN) |
| 989 | field = 0; |
| 990 | else |
| 991 | field = TRB_DIR_IN; |
| 992 | |
| 993 | trb_fields[0] = 0; |
| 994 | trb_fields[1] = 0; |
developer | 6cabb14 | 2020-09-08 19:00:00 +0200 | [diff] [blame] | 995 | trb_fields[2] = TRB_INTR_TARGET(0); |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 996 | /* Event on completion */ |
| 997 | trb_fields[3] = field | TRB_IOC | |
developer | 497dcfa | 2020-09-08 18:59:59 +0200 | [diff] [blame] | 998 | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state; |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 999 | |
| 1000 | queue_trb(ctrl, ep_ring, false, trb_fields); |
| 1001 | |
| 1002 | giveback_first_trb(udev, ep_index, start_cycle, start_trb); |
| 1003 | |
| 1004 | event = xhci_wait_for_event(ctrl, TRB_TRANSFER); |
| 1005 | if (!event) |
| 1006 | goto abort; |
| 1007 | field = le32_to_cpu(event->trans_event.flags); |
| 1008 | |
| 1009 | BUG_ON(TRB_TO_SLOT_ID(field) != slot_id); |
| 1010 | BUG_ON(TRB_TO_EP_INDEX(field) != ep_index); |
| 1011 | |
| 1012 | record_transfer_result(udev, event, length); |
| 1013 | xhci_acknowledge_event(ctrl); |
Stefan Agner | ec2b73d | 2021-09-27 14:42:58 +0200 | [diff] [blame] | 1014 | if (udev->status == USB_ST_STALLED) { |
| 1015 | reset_ep(udev, ep_index); |
| 1016 | return -EPIPE; |
| 1017 | } |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1018 | |
| 1019 | /* Invalidate buffer to make it available to usb-core */ |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 1020 | if (length > 0) { |
Sergey Temerkhanov | 3859346 | 2015-04-01 17:18:45 +0300 | [diff] [blame] | 1021 | xhci_inval_cache((uintptr_t)buffer, length); |
Mark Kettenis | fac410c | 2023-01-21 20:27:55 +0100 | [diff] [blame] | 1022 | xhci_dma_unmap(ctrl, buf_64, length); |
| 1023 | } |
Vivek Gautam | 4912dcc | 2013-09-14 14:02:45 +0530 | [diff] [blame] | 1024 | |
| 1025 | if (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len)) |
| 1026 | == COMP_SHORT_TX) { |
| 1027 | /* Short data stage, clear up additional status stage event */ |
| 1028 | event = xhci_wait_for_event(ctrl, TRB_TRANSFER); |
| 1029 | if (!event) |
| 1030 | goto abort; |
| 1031 | BUG_ON(TRB_TO_SLOT_ID(field) != slot_id); |
| 1032 | BUG_ON(TRB_TO_EP_INDEX(field) != ep_index); |
| 1033 | xhci_acknowledge_event(ctrl); |
| 1034 | } |
| 1035 | |
| 1036 | return (udev->status != USB_ST_NOT_PROC) ? 0 : -1; |
| 1037 | |
| 1038 | abort: |
| 1039 | debug("XHCI control transfer timed out, aborting...\n"); |
| 1040 | abort_td(udev, ep_index); |
| 1041 | udev->status = USB_ST_NAK_REC; |
| 1042 | udev->act_len = 0; |
| 1043 | return -ETIMEDOUT; |
| 1044 | } |