1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <common.h>
17#include <asm/byteorder.h>
18#include <usb.h>
19#include <asm/unaligned.h>
20#include <linux/errno.h>
21
22#include "xhci.h"
23
24
25
26
27
28
29
30
31
32
33
34
35static int last_trb(struct xhci_ctrl *ctrl, struct xhci_ring *ring,
36 struct xhci_segment *seg, union xhci_trb *trb)
37{
38 if (ring == ctrl->event_ring)
39 return trb == &seg->trbs[TRBS_PER_SEGMENT];
40 else
41 return TRB_TYPE_LINK_LE32(trb->link.control);
42}
43
44
45
46
47
48
49
50
51
52
53
54static bool last_trb_on_last_seg(struct xhci_ctrl *ctrl,
55 struct xhci_ring *ring,
56 struct xhci_segment *seg,
57 union xhci_trb *trb)
58{
59 if (ring == ctrl->event_ring)
60 return ((trb == &seg->trbs[TRBS_PER_SEGMENT]) &&
61 (seg->next == ring->first_seg));
62 else
63 return le32_to_cpu(trb->link.control) & LINK_TOGGLE;
64}
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88static void inc_enq(struct xhci_ctrl *ctrl, struct xhci_ring *ring,
89 bool more_trbs_coming)
90{
91 u32 chain;
92 union xhci_trb *next;
93
94 chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN;
95 next = ++(ring->enqueue);
96
97
98
99
100
101 while (last_trb(ctrl, ring, ring->enq_seg, next)) {
102 if (ring != ctrl->event_ring) {
103
104
105
106
107
108
109
110
111 if (!chain && !more_trbs_coming)
112 break;
113
114
115
116
117
118
119
120 next->link.control &= cpu_to_le32(~TRB_CHAIN);
121 next->link.control |= cpu_to_le32(chain);
122
123 next->link.control ^= cpu_to_le32(TRB_CYCLE);
124 xhci_flush_cache((uintptr_t)next,
125 sizeof(union xhci_trb));
126 }
127
128 if (last_trb_on_last_seg(ctrl, ring,
129 ring->enq_seg, next))
130 ring->cycle_state = (ring->cycle_state ? 0 : 1);
131
132 ring->enq_seg = ring->enq_seg->next;
133 ring->enqueue = ring->enq_seg->trbs;
134 next = ring->enqueue;
135 }
136}
137
138
139
140
141
142
143
144
145
146static void inc_deq(struct xhci_ctrl *ctrl, struct xhci_ring *ring)
147{
148 do {
149
150
151
152
153
154 if (last_trb(ctrl, ring, ring->deq_seg, ring->dequeue)) {
155 if (ring == ctrl->event_ring &&
156 last_trb_on_last_seg(ctrl, ring,
157 ring->deq_seg, ring->dequeue)) {
158 ring->cycle_state = (ring->cycle_state ? 0 : 1);
159 }
160 ring->deq_seg = ring->deq_seg->next;
161 ring->dequeue = ring->deq_seg->trbs;
162 } else {
163 ring->dequeue++;
164 }
165 } while (last_trb(ctrl, ring, ring->deq_seg, ring->dequeue));
166}
167
168
169
170
171
172
173
174
175
176
177
178
179
180static struct xhci_generic_trb *queue_trb(struct xhci_ctrl *ctrl,
181 struct xhci_ring *ring,
182 bool more_trbs_coming,
183 unsigned int *trb_fields)
184{
185 struct xhci_generic_trb *trb;
186 int i;
187
188 trb = &ring->enqueue->generic;
189
190 for (i = 0; i < 4; i++)
191 trb->field[i] = cpu_to_le32(trb_fields[i]);
192
193 xhci_flush_cache((uintptr_t)trb, sizeof(struct xhci_generic_trb));
194
195 inc_enq(ctrl, ring, more_trbs_coming);
196
197 return trb;
198}
199
200
201
202
203
204
205
206
207
208
209static int prepare_ring(struct xhci_ctrl *ctrl, struct xhci_ring *ep_ring,
210 u32 ep_state)
211{
212 union xhci_trb *next = ep_ring->enqueue;
213
214
215 switch (ep_state) {
216 case EP_STATE_DISABLED:
217
218
219
220
221 puts("WARN urb submitted to disabled ep\n");
222 return -ENOENT;
223 case EP_STATE_ERROR:
224 puts("WARN waiting for error on ep to be cleared\n");
225 return -EINVAL;
226 case EP_STATE_HALTED:
227 puts("WARN halted endpoint, queueing URB anyway.\n");
228 case EP_STATE_STOPPED:
229 case EP_STATE_RUNNING:
230 debug("EP STATE RUNNING.\n");
231 break;
232 default:
233 puts("ERROR unknown endpoint state for ep\n");
234 return -EINVAL;
235 }
236
237 while (last_trb(ctrl, ep_ring, ep_ring->enq_seg, next)) {
238
239
240
241
242 next->link.control &= cpu_to_le32(~TRB_CHAIN);
243
244 next->link.control ^= cpu_to_le32(TRB_CYCLE);
245
246 xhci_flush_cache((uintptr_t)next, sizeof(union xhci_trb));
247
248
249 if (last_trb_on_last_seg(ctrl, ep_ring,
250 ep_ring->enq_seg, next))
251 ep_ring->cycle_state = (ep_ring->cycle_state ? 0 : 1);
252 ep_ring->enq_seg = ep_ring->enq_seg->next;
253 ep_ring->enqueue = ep_ring->enq_seg->trbs;
254 next = ep_ring->enqueue;
255 }
256
257 return 0;
258}
259
260
261
262
263
264
265
266
267
268
269
270
271void xhci_queue_command(struct xhci_ctrl *ctrl, u8 *ptr, u32 slot_id,
272 u32 ep_index, trb_type cmd)
273{
274 u32 fields[4];
275 u64 val_64 = (uintptr_t)ptr;
276
277 BUG_ON(prepare_ring(ctrl, ctrl->cmd_ring, EP_STATE_RUNNING));
278
279 fields[0] = lower_32_bits(val_64);
280 fields[1] = upper_32_bits(val_64);
281 fields[2] = 0;
282 fields[3] = TRB_TYPE(cmd) | SLOT_ID_FOR_TRB(slot_id) |
283 ctrl->cmd_ring->cycle_state;
284
285
286
287
288
289 if (cmd >= TRB_RESET_EP && cmd <= TRB_SET_DEQ)
290 fields[3] |= EP_ID_FOR_TRB(ep_index);
291
292 queue_trb(ctrl, ctrl->cmd_ring, false, fields);
293
294
295 xhci_writel(&ctrl->dba->doorbell[0], DB_VALUE_HOST);
296}
297
298
299
300
301
302
303
304
305
306static u32 xhci_td_remainder(unsigned int remainder)
307{
308 u32 max = (1 << (21 - 17 + 1)) - 1;
309
310 if ((remainder >> 10) >= max)
311 return max << 17;
312 else
313 return (remainder >> 10) << 17;
314}
315
316
317
318
319
320
321
322
323
324
325
326static u32 xhci_v1_0_td_remainder(int running_total,
327 int trb_buff_len,
328 unsigned int total_packet_count,
329 int maxpacketsize,
330 unsigned int num_trbs_left)
331{
332 int packets_transferred;
333
334
335 if (num_trbs_left == 0 || (running_total == 0 && trb_buff_len == 0))
336 return 0;
337
338
339
340
341
342 packets_transferred = (running_total + trb_buff_len) / maxpacketsize;
343
344 if ((total_packet_count - packets_transferred) > 31)
345 return 31 << 17;
346 return (total_packet_count - packets_transferred) << 17;
347}
348
349
350
351
352
353
354
355
356
357
358static void giveback_first_trb(struct usb_device *udev, int ep_index,
359 int start_cycle,
360 struct xhci_generic_trb *start_trb)
361{
362 struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
363
364
365
366
367
368 if (start_cycle)
369 start_trb->field[3] |= cpu_to_le32(start_cycle);
370 else
371 start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE);
372
373 xhci_flush_cache((uintptr_t)start_trb, sizeof(struct xhci_generic_trb));
374
375
376 xhci_writel(&ctrl->dba->doorbell[udev->slot_id],
377 DB_VALUE(ep_index, 0));
378
379 return;
380}
381
382
383
384
385
386
387
388
389
390
391
392void xhci_acknowledge_event(struct xhci_ctrl *ctrl)
393{
394
395 inc_deq(ctrl, ctrl->event_ring);
396
397
398 xhci_writeq(&ctrl->ir_set->erst_dequeue,
399 (uintptr_t)ctrl->event_ring->dequeue | ERST_EHB);
400}
401
402
403
404
405
406
407
408static int event_ready(struct xhci_ctrl *ctrl)
409{
410 union xhci_trb *event;
411
412 xhci_inval_cache((uintptr_t)ctrl->event_ring->dequeue,
413 sizeof(union xhci_trb));
414
415 event = ctrl->event_ring->dequeue;
416
417
418 if ((le32_to_cpu(event->event_cmd.flags) & TRB_CYCLE) !=
419 ctrl->event_ring->cycle_state)
420 return 0;
421
422 return 1;
423}
424
425
426
427
428
429
430
431
432
433
434union xhci_trb *xhci_wait_for_event(struct xhci_ctrl *ctrl, trb_type expected)
435{
436 trb_type type;
437 unsigned long ts = get_timer(0);
438
439 do {
440 union xhci_trb *event = ctrl->event_ring->dequeue;
441
442 if (!event_ready(ctrl))
443 continue;
444
445 type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->event_cmd.flags));
446 if (type == expected)
447 return event;
448
449 if (type == TRB_PORT_STATUS)
450
451
452
453
454
455 BUG_ON(GET_COMP_CODE(
456 le32_to_cpu(event->generic.field[2])) !=
457 COMP_SUCCESS);
458 else
459 printf("Unexpected XHCI event TRB, skipping... "
460 "(%08x %08x %08x %08x)\n",
461 le32_to_cpu(event->generic.field[0]),
462 le32_to_cpu(event->generic.field[1]),
463 le32_to_cpu(event->generic.field[2]),
464 le32_to_cpu(event->generic.field[3]));
465
466 xhci_acknowledge_event(ctrl);
467 } while (get_timer(ts) < XHCI_TIMEOUT);
468
469 if (expected == TRB_TRANSFER)
470 return NULL;
471
472 printf("XHCI timeout on event type %d... cannot recover.\n", expected);
473 BUG();
474}
475
476
477
478
479
480
481
482
483
484static void abort_td(struct usb_device *udev, int ep_index)
485{
486 struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
487 struct xhci_ring *ring = ctrl->devs[udev->slot_id]->eps[ep_index].ring;
488 union xhci_trb *event;
489 u32 field;
490
491 xhci_queue_command(ctrl, NULL, udev->slot_id, ep_index, TRB_STOP_RING);
492
493 event = xhci_wait_for_event(ctrl, TRB_TRANSFER);
494 field = le32_to_cpu(event->trans_event.flags);
495 BUG_ON(TRB_TO_SLOT_ID(field) != udev->slot_id);
496 BUG_ON(TRB_TO_EP_INDEX(field) != ep_index);
497 BUG_ON(GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len
498 != COMP_STOP)));
499 xhci_acknowledge_event(ctrl);
500
501 event = xhci_wait_for_event(ctrl, TRB_COMPLETION);
502 BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags))
503 != udev->slot_id || GET_COMP_CODE(le32_to_cpu(
504 event->event_cmd.status)) != COMP_SUCCESS);
505 xhci_acknowledge_event(ctrl);
506
507 xhci_queue_command(ctrl, (void *)((uintptr_t)ring->enqueue |
508 ring->cycle_state), udev->slot_id, ep_index, TRB_SET_DEQ);
509 event = xhci_wait_for_event(ctrl, TRB_COMPLETION);
510 BUG_ON(TRB_TO_SLOT_ID(le32_to_cpu(event->event_cmd.flags))
511 != udev->slot_id || GET_COMP_CODE(le32_to_cpu(
512 event->event_cmd.status)) != COMP_SUCCESS);
513 xhci_acknowledge_event(ctrl);
514}
515
516static void record_transfer_result(struct usb_device *udev,
517 union xhci_trb *event, int length)
518{
519 udev->act_len = min(length, length -
520 (int)EVENT_TRB_LEN(le32_to_cpu(event->trans_event.transfer_len)));
521
522 switch (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len))) {
523 case COMP_SUCCESS:
524 BUG_ON(udev->act_len != length);
525
526 case COMP_SHORT_TX:
527 udev->status = 0;
528 break;
529 case COMP_STALL:
530 udev->status = USB_ST_STALLED;
531 break;
532 case COMP_DB_ERR:
533 case COMP_TRB_ERR:
534 udev->status = USB_ST_BUF_ERR;
535 break;
536 case COMP_BABBLE:
537 udev->status = USB_ST_BABBLE_DET;
538 break;
539 default:
540 udev->status = 0x80;
541 }
542}
543
544
545
546
547
548
549
550
551
552
553
554int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe,
555 int length, void *buffer)
556{
557 int num_trbs = 0;
558 struct xhci_generic_trb *start_trb;
559 bool first_trb = false;
560 int start_cycle;
561 u32 field = 0;
562 u32 length_field = 0;
563 struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
564 int slot_id = udev->slot_id;
565 int ep_index;
566 struct xhci_virt_device *virt_dev;
567 struct xhci_ep_ctx *ep_ctx;
568 struct xhci_ring *ring;
569 union xhci_trb *event;
570
571 int running_total, trb_buff_len;
572 unsigned int total_packet_count;
573 int maxpacketsize;
574 u64 addr;
575 int ret;
576 u32 trb_fields[4];
577 u64 val_64 = (uintptr_t)buffer;
578
579 debug("dev=%p, pipe=%lx, buffer=%p, length=%d\n",
580 udev, pipe, buffer, length);
581
582 ep_index = usb_pipe_ep_index(pipe);
583 virt_dev = ctrl->devs[slot_id];
584
585 xhci_inval_cache((uintptr_t)virt_dev->out_ctx->bytes,
586 virt_dev->out_ctx->size);
587
588 ep_ctx = xhci_get_ep_ctx(ctrl, virt_dev->out_ctx, ep_index);
589
590 ring = virt_dev->eps[ep_index].ring;
591
592
593
594
595
596
597 running_total = TRB_MAX_BUFF_SIZE -
598 (lower_32_bits(val_64) & (TRB_MAX_BUFF_SIZE - 1));
599 trb_buff_len = running_total;
600 running_total &= TRB_MAX_BUFF_SIZE - 1;
601
602
603
604
605
606 if (running_total != 0 || length == 0)
607 num_trbs++;
608
609
610 while (running_total < length) {
611 num_trbs++;
612 running_total += TRB_MAX_BUFF_SIZE;
613 }
614
615
616
617
618
619
620 ret = prepare_ring(ctrl, ring,
621 le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK);
622 if (ret < 0)
623 return ret;
624
625
626
627
628
629
630 start_trb = &ring->enqueue->generic;
631 start_cycle = ring->cycle_state;
632
633 running_total = 0;
634 maxpacketsize = usb_maxpacket(udev, pipe);
635
636 total_packet_count = DIV_ROUND_UP(length, maxpacketsize);
637
638
639
640
641
642
643
644
645 addr = val_64;
646
647 if (trb_buff_len > length)
648 trb_buff_len = length;
649
650 first_trb = true;
651
652
653 xhci_flush_cache((uintptr_t)buffer, length);
654
655
656 do {
657 u32 remainder = 0;
658 field = 0;
659
660 if (first_trb) {
661 first_trb = false;
662 if (start_cycle == 0)
663 field |= TRB_CYCLE;
664 } else {
665 field |= ring->cycle_state;
666 }
667
668
669
670
671
672 if (num_trbs > 1)
673 field |= TRB_CHAIN;
674 else
675 field |= TRB_IOC;
676
677
678 if (usb_pipein(pipe))
679 field |= TRB_ISP;
680
681
682 if (HC_VERSION(xhci_readl(&ctrl->hccr->cr_capbase)) < 0x100)
683 remainder = xhci_td_remainder(length - running_total);
684 else
685 remainder = xhci_v1_0_td_remainder(running_total,
686 trb_buff_len,
687 total_packet_count,
688 maxpacketsize,
689 num_trbs - 1);
690
691 length_field = ((trb_buff_len & TRB_LEN_MASK) |
692 remainder |
693 ((0 & TRB_INTR_TARGET_MASK) <<
694 TRB_INTR_TARGET_SHIFT));
695
696 trb_fields[0] = lower_32_bits(addr);
697 trb_fields[1] = upper_32_bits(addr);
698 trb_fields[2] = length_field;
699 trb_fields[3] = field | (TRB_NORMAL << TRB_TYPE_SHIFT);
700
701 queue_trb(ctrl, ring, (num_trbs > 1), trb_fields);
702
703 --num_trbs;
704
705 running_total += trb_buff_len;
706
707
708 addr += trb_buff_len;
709 trb_buff_len = min((length - running_total), TRB_MAX_BUFF_SIZE);
710 } while (running_total < length);
711
712 giveback_first_trb(udev, ep_index, start_cycle, start_trb);
713
714 event = xhci_wait_for_event(ctrl, TRB_TRANSFER);
715 if (!event) {
716 debug("XHCI bulk transfer timed out, aborting...\n");
717 abort_td(udev, ep_index);
718 udev->status = USB_ST_NAK_REC;
719 udev->act_len = 0;
720 return -ETIMEDOUT;
721 }
722 field = le32_to_cpu(event->trans_event.flags);
723
724 BUG_ON(TRB_TO_SLOT_ID(field) != slot_id);
725 BUG_ON(TRB_TO_EP_INDEX(field) != ep_index);
726 BUG_ON(*(void **)(uintptr_t)le64_to_cpu(event->trans_event.buffer) -
727 buffer > (size_t)length);
728
729 record_transfer_result(udev, event, length);
730 xhci_acknowledge_event(ctrl);
731 xhci_inval_cache((uintptr_t)buffer, length);
732
733 return (udev->status != USB_ST_NOT_PROC) ? 0 : -1;
734}
735
736
737
738
739
740
741
742
743
744
745
746int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe,
747 struct devrequest *req, int length,
748 void *buffer)
749{
750 int ret;
751 int start_cycle;
752 int num_trbs;
753 u32 field;
754 u32 length_field;
755 u64 buf_64 = 0;
756 struct xhci_generic_trb *start_trb;
757 struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
758 int slot_id = udev->slot_id;
759 int ep_index;
760 u32 trb_fields[4];
761 struct xhci_virt_device *virt_dev = ctrl->devs[slot_id];
762 struct xhci_ring *ep_ring;
763 union xhci_trb *event;
764
765 debug("req=%u (%#x), type=%u (%#x), value=%u (%#x), index=%u\n",
766 req->request, req->request,
767 req->requesttype, req->requesttype,
768 le16_to_cpu(req->value), le16_to_cpu(req->value),
769 le16_to_cpu(req->index));
770
771 ep_index = usb_pipe_ep_index(pipe);
772
773 ep_ring = virt_dev->eps[ep_index].ring;
774
775
776
777
778
779 if (udev->speed == USB_SPEED_FULL) {
780 ret = xhci_check_maxpacket(udev);
781 if (ret < 0)
782 return ret;
783 }
784
785 xhci_inval_cache((uintptr_t)virt_dev->out_ctx->bytes,
786 virt_dev->out_ctx->size);
787
788 struct xhci_ep_ctx *ep_ctx = NULL;
789 ep_ctx = xhci_get_ep_ctx(ctrl, virt_dev->out_ctx, ep_index);
790
791
792 num_trbs = 2;
793
794
795
796
797
798
799 if (length > 0)
800 num_trbs++;
801
802
803
804
805
806 ret = prepare_ring(ctrl, ep_ring,
807 le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK);
808
809 if (ret < 0)
810 return ret;
811
812
813
814
815
816
817 start_trb = &ep_ring->enqueue->generic;
818 start_cycle = ep_ring->cycle_state;
819
820 debug("start_trb %p, start_cycle %d\n", start_trb, start_cycle);
821
822
823
824 field = 0;
825 field |= TRB_IDT | (TRB_SETUP << TRB_TYPE_SHIFT);
826 if (start_cycle == 0)
827 field |= 0x1;
828
829
830 if (HC_VERSION(xhci_readl(&ctrl->hccr->cr_capbase)) == 0x100) {
831 if (length > 0) {
832 if (req->requesttype & USB_DIR_IN)
833 field |= (TRB_DATA_IN << TRB_TX_TYPE_SHIFT);
834 else
835 field |= (TRB_DATA_OUT << TRB_TX_TYPE_SHIFT);
836 }
837 }
838
839 debug("req->requesttype = %d, req->request = %d,"
840 "le16_to_cpu(req->value) = %d,"
841 "le16_to_cpu(req->index) = %d,"
842 "le16_to_cpu(req->length) = %d\n",
843 req->requesttype, req->request, le16_to_cpu(req->value),
844 le16_to_cpu(req->index), le16_to_cpu(req->length));
845
846 trb_fields[0] = req->requesttype | req->request << 8 |
847 le16_to_cpu(req->value) << 16;
848 trb_fields[1] = le16_to_cpu(req->index) |
849 le16_to_cpu(req->length) << 16;
850
851 trb_fields[2] = (8 | ((0 & TRB_INTR_TARGET_MASK) <<
852 TRB_INTR_TARGET_SHIFT));
853
854 trb_fields[3] = field;
855 queue_trb(ctrl, ep_ring, true, trb_fields);
856
857
858 field = 0;
859
860
861 if (usb_pipein(pipe))
862 field = TRB_ISP | (TRB_DATA << TRB_TYPE_SHIFT);
863 else
864 field = (TRB_DATA << TRB_TYPE_SHIFT);
865
866 length_field = (length & TRB_LEN_MASK) | xhci_td_remainder(length) |
867 ((0 & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT);
868 debug("length_field = %d, length = %d,"
869 "xhci_td_remainder(length) = %d , TRB_INTR_TARGET(0) = %d\n",
870 length_field, (length & TRB_LEN_MASK),
871 xhci_td_remainder(length), 0);
872
873 if (length > 0) {
874 if (req->requesttype & USB_DIR_IN)
875 field |= TRB_DIR_IN;
876 buf_64 = (uintptr_t)buffer;
877
878 trb_fields[0] = lower_32_bits(buf_64);
879 trb_fields[1] = upper_32_bits(buf_64);
880 trb_fields[2] = length_field;
881 trb_fields[3] = field | ep_ring->cycle_state;
882
883 xhci_flush_cache((uintptr_t)buffer, length);
884 queue_trb(ctrl, ep_ring, true, trb_fields);
885 }
886
887
888
889
890
891
892
893 field = 0;
894 if (length > 0 && req->requesttype & USB_DIR_IN)
895 field = 0;
896 else
897 field = TRB_DIR_IN;
898
899 trb_fields[0] = 0;
900 trb_fields[1] = 0;
901 trb_fields[2] = ((0 & TRB_INTR_TARGET_MASK) << TRB_INTR_TARGET_SHIFT);
902
903 trb_fields[3] = field | TRB_IOC |
904 (TRB_STATUS << TRB_TYPE_SHIFT) |
905 ep_ring->cycle_state;
906
907 queue_trb(ctrl, ep_ring, false, trb_fields);
908
909 giveback_first_trb(udev, ep_index, start_cycle, start_trb);
910
911 event = xhci_wait_for_event(ctrl, TRB_TRANSFER);
912 if (!event)
913 goto abort;
914 field = le32_to_cpu(event->trans_event.flags);
915
916 BUG_ON(TRB_TO_SLOT_ID(field) != slot_id);
917 BUG_ON(TRB_TO_EP_INDEX(field) != ep_index);
918
919 record_transfer_result(udev, event, length);
920 xhci_acknowledge_event(ctrl);
921
922
923 if (length > 0)
924 xhci_inval_cache((uintptr_t)buffer, length);
925
926 if (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len))
927 == COMP_SHORT_TX) {
928
929 event = xhci_wait_for_event(ctrl, TRB_TRANSFER);
930 if (!event)
931 goto abort;
932 BUG_ON(TRB_TO_SLOT_ID(field) != slot_id);
933 BUG_ON(TRB_TO_EP_INDEX(field) != ep_index);
934 xhci_acknowledge_event(ctrl);
935 }
936
937 return (udev->status != USB_ST_NOT_PROC) ? 0 : -1;
938
939abort:
940 debug("XHCI control transfer timed out, aborting...\n");
941 abort_td(udev, ep_index);
942 udev->status = USB_ST_NAK_REC;
943 udev->act_len = 0;
944 return -ETIMEDOUT;
945}
946