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-common.h"
31 void usb_attach(USBPort
*port
)
33 USBDevice
*dev
= port
->dev
;
36 assert(dev
->attached
);
37 assert(dev
->state
== USB_STATE_NOTATTACHED
);
38 port
->ops
->attach(port
);
39 dev
->state
= USB_STATE_ATTACHED
;
40 usb_device_handle_attach(dev
);
43 void usb_detach(USBPort
*port
)
45 USBDevice
*dev
= port
->dev
;
48 assert(dev
->state
!= USB_STATE_NOTATTACHED
);
49 port
->ops
->detach(port
);
50 dev
->state
= USB_STATE_NOTATTACHED
;
53 void usb_port_reset(USBPort
*port
)
55 USBDevice
*dev
= port
->dev
;
60 usb_device_reset(dev
);
63 void usb_device_reset(USBDevice
*dev
)
65 if (dev
== NULL
|| !dev
->attached
) {
68 dev
->remote_wakeup
= 0;
70 dev
->state
= USB_STATE_DEFAULT
;
71 usb_device_handle_reset(dev
);
74 void usb_wakeup(USBEndpoint
*ep
, unsigned int stream
)
76 USBDevice
*dev
= ep
->dev
;
77 USBBus
*bus
= usb_bus_from_device(dev
);
79 if (dev
->remote_wakeup
&& dev
->port
&& dev
->port
->ops
->wakeup
) {
80 dev
->port
->ops
->wakeup(dev
->port
);
82 if (bus
->ops
->wakeup_endpoint
) {
83 bus
->ops
->wakeup_endpoint(bus
, ep
, stream
);
87 /**********************/
89 /* generic USB device helpers (you are not forced to use them when
90 writing your USB device driver, but they help handling the
94 #define SETUP_STATE_IDLE 0
95 #define SETUP_STATE_SETUP 1
96 #define SETUP_STATE_DATA 2
97 #define SETUP_STATE_ACK 3
98 #define SETUP_STATE_PARAM 4
100 static void do_token_setup(USBDevice
*s
, USBPacket
*p
)
102 int request
, value
, index
;
104 if (p
->iov
.size
!= 8) {
105 p
->status
= USB_RET_STALL
;
109 usb_packet_copy(p
, s
->setup_buf
, p
->iov
.size
);
110 p
->actual_length
= 0;
111 s
->setup_len
= (s
->setup_buf
[7] << 8) | s
->setup_buf
[6];
114 request
= (s
->setup_buf
[0] << 8) | s
->setup_buf
[1];
115 value
= (s
->setup_buf
[3] << 8) | s
->setup_buf
[2];
116 index
= (s
->setup_buf
[5] << 8) | s
->setup_buf
[4];
118 if (s
->setup_buf
[0] & USB_DIR_IN
) {
119 usb_device_handle_control(s
, p
, request
, value
, index
,
120 s
->setup_len
, s
->data_buf
);
121 if (p
->status
== USB_RET_ASYNC
) {
122 s
->setup_state
= SETUP_STATE_SETUP
;
124 if (p
->status
!= USB_RET_SUCCESS
) {
128 if (p
->actual_length
< s
->setup_len
) {
129 s
->setup_len
= p
->actual_length
;
131 s
->setup_state
= SETUP_STATE_DATA
;
133 if (s
->setup_len
> sizeof(s
->data_buf
)) {
135 "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
136 s
->setup_len
, sizeof(s
->data_buf
));
137 p
->status
= USB_RET_STALL
;
140 if (s
->setup_len
== 0)
141 s
->setup_state
= SETUP_STATE_ACK
;
143 s
->setup_state
= SETUP_STATE_DATA
;
146 p
->actual_length
= 8;
149 static void do_token_in(USBDevice
*s
, USBPacket
*p
)
151 int request
, value
, index
;
153 assert(p
->ep
->nr
== 0);
155 request
= (s
->setup_buf
[0] << 8) | s
->setup_buf
[1];
156 value
= (s
->setup_buf
[3] << 8) | s
->setup_buf
[2];
157 index
= (s
->setup_buf
[5] << 8) | s
->setup_buf
[4];
159 switch(s
->setup_state
) {
160 case SETUP_STATE_ACK
:
161 if (!(s
->setup_buf
[0] & USB_DIR_IN
)) {
162 usb_device_handle_control(s
, p
, request
, value
, index
,
163 s
->setup_len
, s
->data_buf
);
164 if (p
->status
== USB_RET_ASYNC
) {
167 s
->setup_state
= SETUP_STATE_IDLE
;
168 p
->actual_length
= 0;
172 case SETUP_STATE_DATA
:
173 if (s
->setup_buf
[0] & USB_DIR_IN
) {
174 int len
= s
->setup_len
- s
->setup_index
;
175 if (len
> p
->iov
.size
) {
178 usb_packet_copy(p
, s
->data_buf
+ s
->setup_index
, len
);
179 s
->setup_index
+= len
;
180 if (s
->setup_index
>= s
->setup_len
) {
181 s
->setup_state
= SETUP_STATE_ACK
;
185 s
->setup_state
= SETUP_STATE_IDLE
;
186 p
->status
= USB_RET_STALL
;
190 p
->status
= USB_RET_STALL
;
194 static void do_token_out(USBDevice
*s
, USBPacket
*p
)
196 assert(p
->ep
->nr
== 0);
198 switch(s
->setup_state
) {
199 case SETUP_STATE_ACK
:
200 if (s
->setup_buf
[0] & USB_DIR_IN
) {
201 s
->setup_state
= SETUP_STATE_IDLE
;
204 /* ignore additional output */
208 case SETUP_STATE_DATA
:
209 if (!(s
->setup_buf
[0] & USB_DIR_IN
)) {
210 int len
= s
->setup_len
- s
->setup_index
;
211 if (len
> p
->iov
.size
) {
214 usb_packet_copy(p
, s
->data_buf
+ s
->setup_index
, len
);
215 s
->setup_index
+= len
;
216 if (s
->setup_index
>= s
->setup_len
) {
217 s
->setup_state
= SETUP_STATE_ACK
;
221 s
->setup_state
= SETUP_STATE_IDLE
;
222 p
->status
= USB_RET_STALL
;
226 p
->status
= USB_RET_STALL
;
230 static void do_parameter(USBDevice
*s
, USBPacket
*p
)
232 int i
, request
, value
, index
;
234 for (i
= 0; i
< 8; i
++) {
235 s
->setup_buf
[i
] = p
->parameter
>> (i
*8);
238 s
->setup_state
= SETUP_STATE_PARAM
;
239 s
->setup_len
= (s
->setup_buf
[7] << 8) | s
->setup_buf
[6];
242 request
= (s
->setup_buf
[0] << 8) | s
->setup_buf
[1];
243 value
= (s
->setup_buf
[3] << 8) | s
->setup_buf
[2];
244 index
= (s
->setup_buf
[5] << 8) | s
->setup_buf
[4];
246 if (s
->setup_len
> sizeof(s
->data_buf
)) {
248 "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
249 s
->setup_len
, sizeof(s
->data_buf
));
250 p
->status
= USB_RET_STALL
;
254 if (p
->pid
== USB_TOKEN_OUT
) {
255 usb_packet_copy(p
, s
->data_buf
, s
->setup_len
);
258 usb_device_handle_control(s
, p
, request
, value
, index
,
259 s
->setup_len
, s
->data_buf
);
260 if (p
->status
== USB_RET_ASYNC
) {
264 if (p
->actual_length
< s
->setup_len
) {
265 s
->setup_len
= p
->actual_length
;
267 if (p
->pid
== USB_TOKEN_IN
) {
268 p
->actual_length
= 0;
269 usb_packet_copy(p
, s
->data_buf
, s
->setup_len
);
273 /* ctrl complete function for devices which use usb_generic_handle_packet and
274 may return USB_RET_ASYNC from their handle_control callback. Device code
275 which does this *must* call this function instead of the normal
276 usb_packet_complete to complete their async control packets. */
277 void usb_generic_async_ctrl_complete(USBDevice
*s
, USBPacket
*p
)
280 s
->setup_state
= SETUP_STATE_IDLE
;
283 switch (s
->setup_state
) {
284 case SETUP_STATE_SETUP
:
285 if (p
->actual_length
< s
->setup_len
) {
286 s
->setup_len
= p
->actual_length
;
288 s
->setup_state
= SETUP_STATE_DATA
;
289 p
->actual_length
= 8;
292 case SETUP_STATE_ACK
:
293 s
->setup_state
= SETUP_STATE_IDLE
;
294 p
->actual_length
= 0;
297 case SETUP_STATE_PARAM
:
298 if (p
->actual_length
< s
->setup_len
) {
299 s
->setup_len
= p
->actual_length
;
301 if (p
->pid
== USB_TOKEN_IN
) {
302 p
->actual_length
= 0;
303 usb_packet_copy(p
, s
->data_buf
, s
->setup_len
);
310 usb_packet_complete(s
, p
);
313 /* XXX: fix overflow */
314 int set_usb_string(uint8_t *buf
, const char *str
)
323 for(i
= 0; i
< len
; i
++) {
330 USBDevice
*usb_find_device(USBPort
*port
, uint8_t addr
)
332 USBDevice
*dev
= port
->dev
;
334 if (dev
== NULL
|| !dev
->attached
|| dev
->state
!= USB_STATE_DEFAULT
) {
337 if (dev
->addr
== addr
) {
340 return usb_device_find_device(dev
, addr
);
343 static void usb_process_one(USBPacket
*p
)
345 USBDevice
*dev
= p
->ep
->dev
;
348 * Handlers expect status to be initialized to USB_RET_SUCCESS, but it
349 * can be USB_RET_NAK here from a previous usb_process_one() call,
350 * or USB_RET_ASYNC from going through usb_queue_one().
352 p
->status
= USB_RET_SUCCESS
;
354 if (p
->ep
->nr
== 0) {
357 do_parameter(dev
, p
);
361 case USB_TOKEN_SETUP
:
362 do_token_setup(dev
, p
);
368 do_token_out(dev
, p
);
371 p
->status
= USB_RET_STALL
;
375 usb_device_handle_data(dev
, p
);
379 static void usb_queue_one(USBPacket
*p
)
381 usb_packet_set_state(p
, USB_PACKET_QUEUED
);
382 QTAILQ_INSERT_TAIL(&p
->ep
->queue
, p
, queue
);
383 p
->status
= USB_RET_ASYNC
;
386 /* Hand over a packet to a device for processing. p->status ==
387 USB_RET_ASYNC indicates the processing isn't finished yet, the
388 driver will call usb_packet_complete() when done processing it. */
389 void usb_handle_packet(USBDevice
*dev
, USBPacket
*p
)
392 p
->status
= USB_RET_NODEV
;
395 assert(dev
== p
->ep
->dev
);
396 assert(dev
->state
== USB_STATE_DEFAULT
);
397 usb_packet_check_state(p
, USB_PACKET_SETUP
);
398 assert(p
->ep
!= NULL
);
400 /* Submitting a new packet clears halt */
402 assert(QTAILQ_EMPTY(&p
->ep
->queue
));
403 p
->ep
->halted
= false;
406 if (QTAILQ_EMPTY(&p
->ep
->queue
) || p
->ep
->pipeline
|| p
->stream
) {
408 if (p
->status
== USB_RET_ASYNC
) {
409 /* hcd drivers cannot handle async for isoc */
410 assert(p
->ep
->type
!= USB_ENDPOINT_XFER_ISOC
);
411 /* using async for interrupt packets breaks migration */
412 assert(p
->ep
->type
!= USB_ENDPOINT_XFER_INT
||
413 (dev
->flags
& (1 << USB_DEV_FLAG_IS_HOST
)));
414 usb_packet_set_state(p
, USB_PACKET_ASYNC
);
415 QTAILQ_INSERT_TAIL(&p
->ep
->queue
, p
, queue
);
416 } else if (p
->status
== USB_RET_ADD_TO_QUEUE
) {
420 * When pipelining is enabled usb-devices must always return async,
421 * otherwise packets can complete out of order!
423 assert(p
->stream
|| !p
->ep
->pipeline
||
424 QTAILQ_EMPTY(&p
->ep
->queue
));
425 if (p
->status
!= USB_RET_NAK
) {
426 usb_packet_set_state(p
, USB_PACKET_COMPLETE
);
434 void usb_packet_complete_one(USBDevice
*dev
, USBPacket
*p
)
436 USBEndpoint
*ep
= p
->ep
;
438 assert(p
->stream
|| QTAILQ_FIRST(&ep
->queue
) == p
);
439 assert(p
->status
!= USB_RET_ASYNC
&& p
->status
!= USB_RET_NAK
);
441 if (p
->status
!= USB_RET_SUCCESS
||
442 (p
->short_not_ok
&& (p
->actual_length
< p
->iov
.size
))) {
445 usb_packet_set_state(p
, USB_PACKET_COMPLETE
);
446 QTAILQ_REMOVE(&ep
->queue
, p
, queue
);
447 dev
->port
->ops
->complete(dev
->port
, p
);
450 /* Notify the controller that an async packet is complete. This should only
451 be called for packets previously deferred by returning USB_RET_ASYNC from
453 void usb_packet_complete(USBDevice
*dev
, USBPacket
*p
)
455 USBEndpoint
*ep
= p
->ep
;
457 usb_packet_check_state(p
, USB_PACKET_ASYNC
);
458 usb_packet_complete_one(dev
, p
);
460 while (!QTAILQ_EMPTY(&ep
->queue
)) {
461 p
= QTAILQ_FIRST(&ep
->queue
);
463 /* Empty the queue on a halt */
464 p
->status
= USB_RET_REMOVE_FROM_QUEUE
;
465 dev
->port
->ops
->complete(dev
->port
, p
);
468 if (p
->state
== USB_PACKET_ASYNC
) {
471 usb_packet_check_state(p
, USB_PACKET_QUEUED
);
473 if (p
->status
== USB_RET_ASYNC
) {
474 usb_packet_set_state(p
, USB_PACKET_ASYNC
);
477 usb_packet_complete_one(ep
->dev
, p
);
481 /* Cancel an active packet. The packed must have been deferred by
482 returning USB_RET_ASYNC from handle_packet, and not yet
484 void usb_cancel_packet(USBPacket
* p
)
486 bool callback
= (p
->state
== USB_PACKET_ASYNC
);
487 assert(usb_packet_is_inflight(p
));
488 usb_packet_set_state(p
, USB_PACKET_CANCELED
);
489 QTAILQ_REMOVE(&p
->ep
->queue
, p
, queue
);
491 usb_device_cancel_packet(p
->ep
->dev
, p
);
496 void usb_packet_init(USBPacket
*p
)
498 qemu_iovec_init(&p
->iov
, 1);
501 static const char *usb_packet_state_name(USBPacketState state
)
503 static const char *name
[] = {
504 [USB_PACKET_UNDEFINED
] = "undef",
505 [USB_PACKET_SETUP
] = "setup",
506 [USB_PACKET_QUEUED
] = "queued",
507 [USB_PACKET_ASYNC
] = "async",
508 [USB_PACKET_COMPLETE
] = "complete",
509 [USB_PACKET_CANCELED
] = "canceled",
511 if (state
< ARRAY_SIZE(name
)) {
517 void usb_packet_check_state(USBPacket
*p
, USBPacketState expected
)
522 if (p
->state
== expected
) {
526 bus
= usb_bus_from_device(dev
);
527 trace_usb_packet_state_fault(bus
->busnr
, dev
->port
->path
, p
->ep
->nr
, p
,
528 usb_packet_state_name(p
->state
),
529 usb_packet_state_name(expected
));
530 assert(!"usb packet state check failed");
533 void usb_packet_set_state(USBPacket
*p
, USBPacketState state
)
536 USBDevice
*dev
= p
->ep
->dev
;
537 USBBus
*bus
= usb_bus_from_device(dev
);
538 trace_usb_packet_state_change(bus
->busnr
, dev
->port
->path
, p
->ep
->nr
, p
,
539 usb_packet_state_name(p
->state
),
540 usb_packet_state_name(state
));
542 trace_usb_packet_state_change(-1, "", -1, p
,
543 usb_packet_state_name(p
->state
),
544 usb_packet_state_name(state
));
549 void usb_packet_setup(USBPacket
*p
, int pid
,
550 USBEndpoint
*ep
, unsigned int stream
,
551 uint64_t id
, bool short_not_ok
, bool int_req
)
553 assert(!usb_packet_is_inflight(p
));
554 assert(p
->iov
.iov
!= NULL
);
559 p
->status
= USB_RET_SUCCESS
;
560 p
->actual_length
= 0;
562 p
->short_not_ok
= short_not_ok
;
563 p
->int_req
= int_req
;
565 qemu_iovec_reset(&p
->iov
);
566 usb_packet_set_state(p
, USB_PACKET_SETUP
);
569 void usb_packet_addbuf(USBPacket
*p
, void *ptr
, size_t len
)
571 qemu_iovec_add(&p
->iov
, ptr
, len
);
574 void usb_packet_copy(USBPacket
*p
, void *ptr
, size_t bytes
)
576 QEMUIOVector
*iov
= p
->combined
? &p
->combined
->iov
: &p
->iov
;
578 assert(p
->actual_length
>= 0);
579 assert(p
->actual_length
+ bytes
<= iov
->size
);
581 case USB_TOKEN_SETUP
:
583 iov_to_buf(iov
->iov
, iov
->niov
, p
->actual_length
, ptr
, bytes
);
586 iov_from_buf(iov
->iov
, iov
->niov
, p
->actual_length
, ptr
, bytes
);
589 fprintf(stderr
, "%s: invalid pid: %x\n", __func__
, p
->pid
);
592 p
->actual_length
+= bytes
;
595 void usb_packet_skip(USBPacket
*p
, size_t bytes
)
597 QEMUIOVector
*iov
= p
->combined
? &p
->combined
->iov
: &p
->iov
;
599 assert(p
->actual_length
>= 0);
600 assert(p
->actual_length
+ bytes
<= iov
->size
);
601 if (p
->pid
== USB_TOKEN_IN
) {
602 iov_memset(iov
->iov
, iov
->niov
, p
->actual_length
, 0, bytes
);
604 p
->actual_length
+= bytes
;
607 size_t usb_packet_size(USBPacket
*p
)
609 return p
->combined
? p
->combined
->iov
.size
: p
->iov
.size
;
612 void usb_packet_cleanup(USBPacket
*p
)
614 assert(!usb_packet_is_inflight(p
));
615 qemu_iovec_destroy(&p
->iov
);
618 void usb_ep_reset(USBDevice
*dev
)
623 dev
->ep_ctl
.type
= USB_ENDPOINT_XFER_CONTROL
;
624 dev
->ep_ctl
.ifnum
= 0;
625 dev
->ep_ctl
.max_packet_size
= 64;
626 dev
->ep_ctl
.dev
= dev
;
627 dev
->ep_ctl
.pipeline
= false;
628 for (ep
= 0; ep
< USB_MAX_ENDPOINTS
; ep
++) {
629 dev
->ep_in
[ep
].nr
= ep
+ 1;
630 dev
->ep_out
[ep
].nr
= ep
+ 1;
631 dev
->ep_in
[ep
].pid
= USB_TOKEN_IN
;
632 dev
->ep_out
[ep
].pid
= USB_TOKEN_OUT
;
633 dev
->ep_in
[ep
].type
= USB_ENDPOINT_XFER_INVALID
;
634 dev
->ep_out
[ep
].type
= USB_ENDPOINT_XFER_INVALID
;
635 dev
->ep_in
[ep
].ifnum
= USB_INTERFACE_INVALID
;
636 dev
->ep_out
[ep
].ifnum
= USB_INTERFACE_INVALID
;
637 dev
->ep_in
[ep
].max_packet_size
= 0;
638 dev
->ep_out
[ep
].max_packet_size
= 0;
639 dev
->ep_in
[ep
].dev
= dev
;
640 dev
->ep_out
[ep
].dev
= dev
;
641 dev
->ep_in
[ep
].pipeline
= false;
642 dev
->ep_out
[ep
].pipeline
= false;
646 void usb_ep_init(USBDevice
*dev
)
651 QTAILQ_INIT(&dev
->ep_ctl
.queue
);
652 for (ep
= 0; ep
< USB_MAX_ENDPOINTS
; ep
++) {
653 QTAILQ_INIT(&dev
->ep_in
[ep
].queue
);
654 QTAILQ_INIT(&dev
->ep_out
[ep
].queue
);
658 void usb_ep_dump(USBDevice
*dev
)
660 static const char *tname
[] = {
661 [USB_ENDPOINT_XFER_CONTROL
] = "control",
662 [USB_ENDPOINT_XFER_ISOC
] = "isoc",
663 [USB_ENDPOINT_XFER_BULK
] = "bulk",
664 [USB_ENDPOINT_XFER_INT
] = "int",
666 int ifnum
, ep
, first
;
668 fprintf(stderr
, "Device \"%s\", config %d\n",
669 dev
->product_desc
, dev
->configuration
);
670 for (ifnum
= 0; ifnum
< 16; ifnum
++) {
672 for (ep
= 0; ep
< USB_MAX_ENDPOINTS
; ep
++) {
673 if (dev
->ep_in
[ep
].type
!= USB_ENDPOINT_XFER_INVALID
&&
674 dev
->ep_in
[ep
].ifnum
== ifnum
) {
677 fprintf(stderr
, " Interface %d, alternative %d\n",
678 ifnum
, dev
->altsetting
[ifnum
]);
680 fprintf(stderr
, " Endpoint %d, IN, %s, %d max\n", ep
,
681 tname
[dev
->ep_in
[ep
].type
],
682 dev
->ep_in
[ep
].max_packet_size
);
684 if (dev
->ep_out
[ep
].type
!= USB_ENDPOINT_XFER_INVALID
&&
685 dev
->ep_out
[ep
].ifnum
== ifnum
) {
688 fprintf(stderr
, " Interface %d, alternative %d\n",
689 ifnum
, dev
->altsetting
[ifnum
]);
691 fprintf(stderr
, " Endpoint %d, OUT, %s, %d max\n", ep
,
692 tname
[dev
->ep_out
[ep
].type
],
693 dev
->ep_out
[ep
].max_packet_size
);
697 fprintf(stderr
, "--\n");
700 struct USBEndpoint
*usb_ep_get(USBDevice
*dev
, int pid
, int ep
)
702 struct USBEndpoint
*eps
;
707 eps
= (pid
== USB_TOKEN_IN
) ? dev
->ep_in
: dev
->ep_out
;
711 assert(pid
== USB_TOKEN_IN
|| pid
== USB_TOKEN_OUT
);
712 assert(ep
> 0 && ep
<= USB_MAX_ENDPOINTS
);
716 uint8_t usb_ep_get_type(USBDevice
*dev
, int pid
, int ep
)
718 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
722 void usb_ep_set_type(USBDevice
*dev
, int pid
, int ep
, uint8_t type
)
724 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
728 uint8_t usb_ep_get_ifnum(USBDevice
*dev
, int pid
, int ep
)
730 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
734 void usb_ep_set_ifnum(USBDevice
*dev
, int pid
, int ep
, uint8_t ifnum
)
736 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
740 void usb_ep_set_max_packet_size(USBDevice
*dev
, int pid
, int ep
,
743 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
744 int size
, microframes
;
747 switch ((raw
>> 11) & 3) {
758 uep
->max_packet_size
= size
* microframes
;
761 int usb_ep_get_max_packet_size(USBDevice
*dev
, int pid
, int ep
)
763 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
764 return uep
->max_packet_size
;
767 void usb_ep_set_pipeline(USBDevice
*dev
, int pid
, int ep
, bool enabled
)
769 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
770 uep
->pipeline
= enabled
;
773 void usb_ep_set_halted(USBDevice
*dev
, int pid
, int ep
, bool halted
)
775 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
776 uep
->halted
= halted
;
779 USBPacket
*usb_ep_find_packet_by_id(USBDevice
*dev
, int pid
, int ep
,
782 struct USBEndpoint
*uep
= usb_ep_get(dev
, pid
, ep
);
785 QTAILQ_FOREACH(p
, &uep
->queue
, queue
) {