4 * Copyright (c) 2005 Fabrice Bellard
6 * 2008 Generic packet handler rewrite by Max Krasnyansky
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include "qemu/osdep.h"
27 #include "qemu-common.h"
32 void usb_pick_speed(USBPort
*port
)
34 static const int speeds
[] = {
40 USBDevice
*udev
= port
->dev
;
43 for (i
= 0; i
< ARRAY_SIZE(speeds
); i
++) {
44 if ((udev
->speedmask
& (1 << speeds
[i
])) &&
45 (port
->speedmask
& (1 << speeds
[i
]))) {
46 udev
->speed
= speeds
[i
];
52 void usb_attach(USBPort
*port
)
54 USBDevice
*dev
= port
->dev
;
57 assert(dev
->attached
);
58 assert(dev
->state
== USB_STATE_NOTATTACHED
);
60 port
->ops
->attach(port
);
61 dev
->state
= USB_STATE_ATTACHED
;
62 usb_device_handle_attach(dev
);
65 void usb_detach(USBPort
*port
)
67 USBDevice
*dev
= port
->dev
;
70 assert(dev
->state
!= USB_STATE_NOTATTACHED
);
71 port
->ops
->detach(port
);
72 dev
->state
= USB_STATE_NOTATTACHED
;
75 void usb_port_reset(USBPort
*port
)
77 USBDevice
*dev
= port
->dev
;
82 usb_device_reset(dev
);
85 void usb_device_reset(USBDevice
*dev
)
87 if (dev
== NULL
|| !dev
->attached
) {
90 dev
->remote_wakeup
= 0;
92 dev
->state
= USB_STATE_DEFAULT
;
93 usb_device_handle_reset(dev
);
96 void usb_wakeup(USBEndpoint
*ep
, unsigned int stream
)
98 USBDevice
*dev
= ep
->dev
;
99 USBBus
*bus
= usb_bus_from_device(dev
);
101 if (dev
->remote_wakeup
&& dev
->port
&& dev
->port
->ops
->wakeup
) {
102 dev
->port
->ops
->wakeup(dev
->port
);
104 if (bus
->ops
->wakeup_endpoint
) {
105 bus
->ops
->wakeup_endpoint(bus
, ep
, stream
);
109 /**********************/
111 /* generic USB device helpers (you are not forced to use them when
112 writing your USB device driver, but they help handling the
116 #define SETUP_STATE_IDLE 0
117 #define SETUP_STATE_SETUP 1
118 #define SETUP_STATE_DATA 2
119 #define SETUP_STATE_ACK 3
120 #define SETUP_STATE_PARAM 4
122 static void do_token_setup(USBDevice
*s
, USBPacket
*p
)
124 int request
, value
, index
;
126 if (p
->iov
.size
!= 8) {
127 p
->status
= USB_RET_STALL
;
131 usb_packet_copy(p
, s
->setup_buf
, p
->iov
.size
);
133 p
->actual_length
= 0;
134 s
->setup_len
= (s
->setup_buf
[7] << 8) | s
->setup_buf
[6];
135 if (s
->setup_len
> sizeof(s
->data_buf
)) {
137 "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
138 s
->setup_len
, sizeof(s
->data_buf
));
139 p
->status
= USB_RET_STALL
;
143 request
= (s
->setup_buf
[0] << 8) | s
->setup_buf
[1];
144 value
= (s
->setup_buf
[3] << 8) | s
->setup_buf
[2];
145 index
= (s
->setup_buf
[5] << 8) | s
->setup_buf
[4];
147 if (s
->setup_buf
[0] & USB_DIR_IN
) {
148 usb_device_handle_control(s
, p
, request
, value
, index
,
149 s
->setup_len
, s
->data_buf
);
150 if (p
->status
== USB_RET_ASYNC
) {
151 s
->setup_state
= SETUP_STATE_SETUP
;
153 if (p
->status
!= USB_RET_SUCCESS
) {
157 if (p
->actual_length
< s
->setup_len
) {
158 s
->setup_len
= p
->actual_length
;
160 s
->setup_state
= SETUP_STATE_DATA
;
162 if (s
->setup_len
== 0)
163 s
->setup_state
= SETUP_STATE_ACK
;
165 s
->setup_state
= SETUP_STATE_DATA
;
168 p
->actual_length
= 8;
171 static void do_token_in(USBDevice
*s
, USBPacket
*p
)
173 int request
, value
, index
;
175 assert(p
->ep
->nr
== 0);
177 request
= (s
->setup_buf
[0] << 8) | s
->setup_buf
[1];
178 value
= (s
->setup_buf
[3] << 8) | s
->setup_buf
[2];
179 index
= (s
->setup_buf
[5] << 8) | s
->setup_buf
[4];
181 switch(s
->setup_state
) {
182 case SETUP_STATE_ACK
:
183 if (!(s
->setup_buf
[0] & USB_DIR_IN
)) {
184 usb_device_handle_control(s
, p
, request
, value
, index
,
185 s
->setup_len
, s
->data_buf
);
186 if (p
->status
== USB_RET_ASYNC
) {
189 s
->setup_state
= SETUP_STATE_IDLE
;
190 p
->actual_length
= 0;
194 case SETUP_STATE_DATA
:
195 if (s
->setup_buf
[0] & USB_DIR_IN
) {
196 int len
= s
->setup_len
- s
->setup_index
;
197 if (len
> p
->iov
.size
) {
200 usb_packet_copy(p
, s
->data_buf
+ s
->setup_index
, len
);
201 s
->setup_index
+= len
;
202 if (s
->setup_index
>= s
->setup_len
) {
203 s
->setup_state
= SETUP_STATE_ACK
;
207 s
->setup_state
= SETUP_STATE_IDLE
;
208 p
->status
= USB_RET_STALL
;
212 p
->status
= USB_RET_STALL
;
216 static void do_token_out(USBDevice
*s
, USBPacket
*p
)
218 assert(p
->ep
->nr
== 0);
220 switch(s
->setup_state
) {
221 case SETUP_STATE_ACK
:
222 if (s
->setup_buf
[0] & USB_DIR_IN
) {
223 s
->setup_state
= SETUP_STATE_IDLE
;
226 /* ignore additional output */
230 case SETUP_STATE_DATA
:
231 if (!(s
->setup_buf
[0] & USB_DIR_IN
)) {
232 int len
= s
->setup_len
- s
->setup_index
;
233 if (len
> p
->iov
.size
) {
236 usb_packet_copy(p
, s
->data_buf
+ s
->setup_index
, len
);
237 s
->setup_index
+= len
;
238 if (s
->setup_index
>= s
->setup_len
) {
239 s
->setup_state
= SETUP_STATE_ACK
;
243 s
->setup_state
= SETUP_STATE_IDLE
;
244 p
->status
= USB_RET_STALL
;
248 p
->status
= USB_RET_STALL
;
252 static void do_parameter(USBDevice
*s
, USBPacket
*p
)
254 int i
, request
, value
, index
;
256 for (i
= 0; i
< 8; i
++) {
257 s
->setup_buf
[i
] = p
->parameter
>> (i
*8);
260 s
->setup_state
= SETUP_STATE_PARAM
;
261 s
->setup_len
= (s
->setup_buf
[7] << 8) | s
->setup_buf
[6];
264 request
= (s
->setup_buf
[0] << 8) | s
->setup_buf
[1];
265 value
= (s
->setup_buf
[3] << 8) | s
->setup_buf
[2];
266 index
= (s
->setup_buf
[5] << 8) | s
->setup_buf
[4];
268 if (s
->setup_len
> sizeof(s
->data_buf
)) {
270 "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
271 s
->setup_len
, sizeof(s
->data_buf
));
272 p
->status
= USB_RET_STALL
;
276 if (p
->pid
== USB_TOKEN_OUT
) {
277 usb_packet_copy(p
, s
->data_buf
, s
->setup_len
);
280 usb_device_handle_control(s
, p
, request
, value
, index
,
281 s
->setup_len
, s
->data_buf
);
282 if (p
->status
== USB_RET_ASYNC
) {
286 if (p
->actual_length
< s
->setup_len
) {
287 s
->setup_len
= p
->actual_length
;
289 if (p
->pid
== USB_TOKEN_IN
) {
290 p
->actual_length
= 0;
291 usb_packet_copy(p
, s
->data_buf
, s
->setup_len
);
295 /* ctrl complete function for devices which use usb_generic_handle_packet and
296 may return USB_RET_ASYNC from their handle_control callback. Device code
297 which does this *must* call this function instead of the normal
298 usb_packet_complete to complete their async control packets. */
299 void usb_generic_async_ctrl_complete(USBDevice
*s
, USBPacket
*p
)
302 s
->setup_state
= SETUP_STATE_IDLE
;
305 switch (s
->setup_state
) {
306 case SETUP_STATE_SETUP
:
307 if (p
->actual_length
< s
->setup_len
) {
308 s
->setup_len
= p
->actual_length
;
310 s
->setup_state
= SETUP_STATE_DATA
;
311 p
->actual_length
= 8;
314 case SETUP_STATE_ACK
:
315 s
->setup_state
= SETUP_STATE_IDLE
;
316 p
->actual_length
= 0;
319 case SETUP_STATE_PARAM
:
320 if (p
->actual_length
< s
->setup_len
) {
321 s
->setup_len
= p
->actual_length
;
323 if (p
->pid
== USB_TOKEN_IN
) {
324 p
->actual_length
= 0;
325 usb_packet_copy(p
, s
->data_buf
, s
->setup_len
);
332 usb_packet_complete(s
, p
);
335 USBDevice
*usb_find_device(USBPort
*port
, uint8_t addr
)
337 USBDevice
*dev
= port
->dev
;
339 if (dev
== NULL
|| !dev
->attached
|| dev
->state
!= USB_STATE_DEFAULT
) {
342 if (dev
->addr
== addr
) {
345 return usb_device_find_device(dev
, addr
);
348 static void usb_process_one(USBPacket
*p
)
350 USBDevice
*dev
= p
->ep
->dev
;
353 * Handlers expect status to be initialized to USB_RET_SUCCESS, but it
354 * can be USB_RET_NAK here from a previous usb_process_one() call,
355 * or USB_RET_ASYNC from going through usb_queue_one().
357 p
->status
= USB_RET_SUCCESS
;
359 if (p
->ep
->nr
== 0) {
362 do_parameter(dev
, p
);
366 case USB_TOKEN_SETUP
:
367 do_token_setup(dev
, p
);
373 do_token_out(dev
, p
);
376 p
->status
= USB_RET_STALL
;
380 usb_device_handle_data(dev
, p
);
384 static void usb_queue_one(USBPacket
*p
)
386 usb_packet_set_state(p
, USB_PACKET_QUEUED
);
387 QTAILQ_INSERT_TAIL(&p
->ep
->queue
, p
, queue
);
388 p
->status
= USB_RET_ASYNC
;
391 /* Hand over a packet to a device for processing. p->status ==
392 USB_RET_ASYNC indicates the processing isn't finished yet, the
393 driver will call usb_packet_complete() when done processing it. */
394 void usb_handle_packet(USBDevice
*dev
, USBPacket
*p
)
397 p
->status
= USB_RET_NODEV
;
400 assert(dev
== p
->ep
->dev
);
401 assert(dev
->state
== USB_STATE_DEFAULT
);
402 usb_packet_check_state(p
, USB_PACKET_SETUP
);
403 assert(p
->ep
!= NULL
);
405 /* Submitting a new packet clears halt */
407 assert(QTAILQ_EMPTY(&p
->ep
->queue
));
408 p
->ep
->halted
= false;
411 if (QTAILQ_EMPTY(&p
->ep
->queue
) || p
->ep
->pipeline
|| p
->stream
) {
413 if (p
->status
== USB_RET_ASYNC
) {
414 /* hcd drivers cannot handle async for isoc */
415 assert(p
->ep
->type
!= USB_ENDPOINT_XFER_ISOC
);
416 /* using async for interrupt packets breaks migration */
417 assert(p
->ep
->type
!= USB_ENDPOINT_XFER_INT
||
418 (dev
->flags
& (1 << USB_DEV_FLAG_IS_HOST
)));
419 usb_packet_set_state(p
, USB_PACKET_ASYNC
);
420 QTAILQ_INSERT_TAIL(&p
->ep
->queue
, p
, queue
);
421 } else if (p
->status
== USB_RET_ADD_TO_QUEUE
) {
425 * When pipelining is enabled usb-devices must always return async,
426 * otherwise packets can complete out of order!
428 assert(p
->stream
|| !p
->ep
->pipeline
||
429 QTAILQ_EMPTY(&p
->ep
->queue
));
430 if (p
->status
!= USB_RET_NAK
) {
431 usb_packet_set_state(p
, USB_PACKET_COMPLETE
);
439 void usb_packet_complete_one(USBDevice
*dev
, USBPacket
*p
)
441 USBEndpoint
*ep
= p
->ep
;
443 assert(p
->stream
|| QTAILQ_FIRST(&ep
->queue
) == p
);
444 assert(p
->status
!= USB_RET_ASYNC
&& p
->status
!= USB_RET_NAK
);
446 if (p
->status
!= USB_RET_SUCCESS
||
447 (p
->short_not_ok
&& (p
->actual_length
< p
->iov
.size
))) {
450 usb_packet_set_state(p
, USB_PACKET_COMPLETE
);
451 QTAILQ_REMOVE(&ep
->queue
, p
, queue
);
452 dev
->port
->ops
->complete(dev
->port
, p
);
455 /* Notify the controller that an async packet is complete. This should only
456 be called for packets previously deferred by returning USB_RET_ASYNC from
458 void usb_packet_complete(USBDevice
*dev
, USBPacket
*p
)
460 USBEndpoint
*ep
= p
->ep
;
462 usb_packet_check_state(p
, USB_PACKET_ASYNC
);
463 usb_packet_complete_one(dev
, p
);
465 while (!QTAILQ_EMPTY(&ep
->queue
)) {
466 p
= QTAILQ_FIRST(&ep
->queue
);
468 /* Empty the queue on a halt */
469 p
->status
= USB_RET_REMOVE_FROM_QUEUE
;
470 dev
->port
->ops
->complete(dev
->port
, p
);
473 if (p
->state
== USB_PACKET_ASYNC
) {
476 usb_packet_check_state(p
, USB_PACKET_QUEUED
);
478 if (p
->status
== USB_RET_ASYNC
) {
479 usb_packet_set_state(p
, USB_PACKET_ASYNC
);
482 usb_packet_complete_one(ep
->dev
, p
);
486 /* Cancel an active packet. The packed must have been deferred by
487 returning USB_RET_ASYNC from handle_packet, and not yet
489 void usb_cancel_packet(USBPacket
* p
)
491 bool callback
= (p
->state
== USB_PACKET_ASYNC
);
492 assert(usb_packet_is_inflight(p
));
493 usb_packet_set_state(p
, USB_PACKET_CANCELED
);
494 QTAILQ_REMOVE(&p
->ep
->queue
, p
, queue
);
496 usb_device_cancel_packet(p
->ep
->dev
, p
);
501 void usb_packet_init(USBPacket
*p
)
503 qemu_iovec_init(&p
->iov
, 1);
506 static const char *usb_packet_state_name(USBPacketState state
)
508 static const char *name
[] = {
509 [USB_PACKET_UNDEFINED
] = "undef",
510 [USB_PACKET_SETUP
] = "setup",
511 [USB_PACKET_QUEUED
] = "queued",
512 [USB_PACKET_ASYNC
] = "async",
513 [USB_PACKET_COMPLETE
] = "complete",
514 [USB_PACKET_CANCELED
] = "canceled",
516 if (state
< ARRAY_SIZE(name
)) {
522 void usb_packet_check_state(USBPacket
*p
, USBPacketState expected
)
527 if (p
->state
== expected
) {
531 bus
= usb_bus_from_device(dev
);
532 trace_usb_packet_state_fault(bus
->busnr
, dev
->port
->path
, p
->ep
->nr
, p
,
533 usb_packet_state_name(p
->state
),
534 usb_packet_state_name(expected
));
535 assert(!"usb packet state check failed");
538 void usb_packet_set_state(USBPacket
*p
, USBPacketState state
)
541 USBDevice
*dev
= p
->ep
->dev
;
542 USBBus
*bus
= usb_bus_from_device(dev
);
543 trace_usb_packet_state_change(bus
->busnr
, dev
->port
->path
, p
->ep
->nr
, p
,
544 usb_packet_state_name(p
->state
),
545 usb_packet_state_name(state
));
547 trace_usb_packet_state_change(-1, "", -1, p
,
548 usb_packet_state_name(p
->state
),
549 usb_packet_state_name(state
));
554 void usb_packet_setup(USBPacket
*p
, int pid
,
555 USBEndpoint
*ep
, unsigned int stream
,
556 uint64_t id
, bool short_not_ok
, bool int_req
)
558 assert(!usb_packet_is_inflight(p
));
559 assert(p
->iov
.iov
!= NULL
);
564 p
->status
= USB_RET_SUCCESS
;
565 p
->actual_length
= 0;
567 p
->short_not_ok
= short_not_ok
;
568 p
->int_req
= int_req
;
570 qemu_iovec_reset(&p
->iov
);
571 usb_packet_set_state(p
, USB_PACKET_SETUP
);
574 void usb_packet_addbuf(USBPacket
*p
, void *ptr
, size_t len
)
576 qemu_iovec_add(&p
->iov
, ptr
, len
);
579 void usb_packet_copy(USBPacket
*p
, void *ptr
, size_t bytes
)
581 QEMUIOVector
*iov
= p
->combined
? &p
->combined
->iov
: &p
->iov
;
583 assert(p
->actual_length
>= 0);
584 assert(p
->actual_length
+ bytes
<= iov
->size
);
586 case USB_TOKEN_SETUP
:
588 iov_to_buf(iov
->iov
, iov
->niov
, p
->actual_length
, ptr
, bytes
);
591 iov_from_buf(iov
->iov
, iov
->niov
, p
->actual_length
, ptr
, bytes
);
594 fprintf(stderr
, "%s: invalid pid: %x\n", __func__
, p
->pid
);
597 p
->actual_length
+= bytes
;
600 void usb_packet_skip(USBPacket
*p
, size_t bytes
)
602 QEMUIOVector
*iov
= p
->combined
? &p
->combined
->iov
: &p
->iov
;
604 assert(p
->actual_length
>= 0);
605 assert(p
->actual_length
+ bytes
<= iov
->size
);
606 if (p
->pid
== USB_TOKEN_IN
) {
607 iov_memset(iov
->iov
, iov
->niov
, p
->actual_length
, 0, bytes
);
609 p
->actual_length
+= bytes
;
612 size_t usb_packet_size(USBPacket
*p
)
614 return p
->combined
? p
->combined
->iov
.size
: p
->iov
.size
;
617 void usb_packet_cleanup(USBPacket
*p
)
619 assert(!usb_packet_is_inflight(p
));
620 qemu_iovec_destroy(&p
->iov
);
623 void usb_ep_reset(USBDevice
*dev
)
628 dev
->ep_ctl
.type
= USB_ENDPOINT_XFER_CONTROL
;
629 dev
->ep_ctl
.ifnum
= 0;
630 dev
->ep_ctl
.max_packet_size
= 64;
631 dev
->ep_ctl
.max_streams
= 0;
632 dev
->ep_ctl
.dev
= dev
;
633 dev
->ep_ctl
.pipeline
= false;
634 for (ep
= 0; ep
< USB_MAX_ENDPOINTS
; ep
++) {
635 dev
->ep_in
[ep
].nr
= ep
+ 1;
636 dev
->ep_out
[ep
].nr
= ep
+ 1;
637 dev
->ep_in
[ep
].pid
= USB_TOKEN_IN
;
638 dev
->ep_out
[ep
].pid
= USB_TOKEN_OUT
;
639 dev
->ep_in
[ep
].type
= USB_ENDPOINT_XFER_INVALID
;
640 dev
->ep_out
[ep
].type
= USB_ENDPOINT_XFER_INVALID
;
641 dev
->ep_in
[ep
].ifnum
= USB_INTERFACE_INVALID
;
642 dev
->ep_out
[ep
].ifnum
= USB_INTERFACE_INVALID
;
643 dev
->ep_in
[ep
].max_packet_size
= 0;
644 dev
->ep_out
[ep
].max_packet_size
= 0;
645 dev
->ep_in
[ep
].max_streams
= 0;
646 dev
->ep_out
[ep
].max_streams
= 0;
647 dev
->ep_in
[ep
].dev
= dev
;
648 dev
->ep_out
[ep
].dev
= dev
;
649 dev
->ep_in
[ep
].pipeline
= false;
650 dev
->ep_out
[ep
].pipeline
= false;
654 void usb_ep_init(USBDevice
*dev
)
659 QTAILQ_INIT(&dev
->ep_ctl
.queue
);
660 for (ep
= 0; ep
< USB_MAX_ENDPOINTS
; ep
++) {
661 QTAILQ_INIT(&dev
->ep_in
[ep
].queue
);
662 QTAILQ_INIT(&dev
->ep_out
[ep
].queue
);
666 void usb_ep_dump(USBDevice
*dev
)
668 static const char *tname
[] = {
669 [USB_ENDPOINT_XFER_CONTROL
] = "control",
670 [USB_ENDPOINT_XFER_ISOC
] = "isoc",
671 [USB_ENDPOINT_XFER_BULK
] = "bulk",
672 [USB_ENDPOINT_XFER_INT
] = "int",
674 int ifnum
, ep
, first
;
676 fprintf(stderr
, "Device \"%s\", config %d\n",
677 dev
->product_desc
, dev
->configuration
);
678 for (ifnum
= 0; ifnum
< 16; ifnum
++) {
680 for (ep
= 0; ep
< USB_MAX_ENDPOINTS
; ep
++) {
681 if (dev
->ep_in
[ep
].type
!= USB_ENDPOINT_XFER_INVALID
&&
682 dev
->ep_in
[ep
].ifnum
== ifnum
) {
685 fprintf(stderr
, " Interface %d, alternative %d\n",
686 ifnum
, dev
->altsetting
[ifnum
]);
688 fprintf(stderr
, " Endpoint %d, IN, %s, %d max\n", ep
,
689 tname
[dev
->ep_in
[ep
].type
],
690 dev
->ep_in
[ep
].max_packet_size
);
692 if (dev
->ep_out
[ep
].type
!= USB_ENDPOINT_XFER_INVALID
&&
693 dev
->ep_out
[ep
].ifnum
== ifnum
) {
696 fprintf(stderr
, " Interface %d, alternative %d\n",
697 ifnum
, dev
->altsetting
[ifnum
]);
699 fprintf(stderr
, " Endpoint %d, OUT, %s, %d max\n", ep
,
700 tname
[dev
->ep_out
[ep
].type
],
701 dev
->ep_out
[ep
].max_packet_size
);
705 fprintf(stderr
, "--\n");
708 struct USBEndpoint
*usb_ep_get(USBDevice
*dev
, int pid
, int ep
)
710 struct USBEndpoint
*eps
;
715 eps
= (pid
== USB_TOKEN_IN
) ? dev
->ep_in
: dev
->ep_out
;
719 assert(pid
== USB_TOKEN_IN
|| pid
== USB_TOKEN_OUT
);
720 assert(ep
> 0 && ep
<= USB_MAX_ENDPOINTS
);
724 uint8_t usb_ep_get_type(USBDevice
*dev
, int pid
, int ep
)
726 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
730 void usb_ep_set_type(USBDevice
*dev
, int pid
, int ep
, uint8_t type
)
732 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
736 void usb_ep_set_ifnum(USBDevice
*dev
, int pid
, int ep
, uint8_t ifnum
)
738 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
742 void usb_ep_set_max_packet_size(USBDevice
*dev
, int pid
, int ep
,
745 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
746 int size
, microframes
;
749 switch ((raw
>> 11) & 3) {
760 uep
->max_packet_size
= size
* microframes
;
763 void usb_ep_set_max_streams(USBDevice
*dev
, int pid
, int ep
, uint8_t raw
)
765 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
768 MaxStreams
= raw
& 0x1f;
770 uep
->max_streams
= 1 << MaxStreams
;
772 uep
->max_streams
= 0;
776 void usb_ep_set_halted(USBDevice
*dev
, int pid
, int ep
, bool halted
)
778 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
779 uep
->halted
= halted
;
782 USBPacket
*usb_ep_find_packet_by_id(USBDevice
*dev
, int pid
, int ep
,
785 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
788 QTAILQ_FOREACH(p
, &uep
->queue
, queue
) {