Lines Matching refs:p
129 static void do_token_setup(USBDevice *s, USBPacket *p) in do_token_setup() argument
134 if (p->iov.size != 8) { in do_token_setup()
135 p->status = USB_RET_STALL; in do_token_setup()
139 usb_packet_copy(p, s->setup_buf, p->iov.size); in do_token_setup()
141 p->actual_length = 0; in do_token_setup()
147 p->status = USB_RET_STALL; in do_token_setup()
157 usb_pcap_ctrl(p, true); in do_token_setup()
158 usb_device_handle_control(s, p, request, value, index, in do_token_setup()
160 if (p->status == USB_RET_ASYNC) { in do_token_setup()
163 if (p->status != USB_RET_SUCCESS) { in do_token_setup()
167 if (p->actual_length < s->setup_len) { in do_token_setup()
168 s->setup_len = p->actual_length; in do_token_setup()
178 p->actual_length = 8; in do_token_setup()
181 static void do_token_in(USBDevice *s, USBPacket *p) in do_token_in() argument
185 assert(p->ep->nr == 0); in do_token_in()
194 usb_pcap_ctrl(p, true); in do_token_in()
195 usb_device_handle_control(s, p, request, value, index, in do_token_in()
197 if (p->status == USB_RET_ASYNC) { in do_token_in()
201 p->actual_length = 0; in do_token_in()
202 usb_pcap_ctrl(p, false); in do_token_in()
209 if (len > p->iov.size) { in do_token_in()
210 len = p->iov.size; in do_token_in()
212 usb_packet_copy(p, s->data_buf + s->setup_index, len); in do_token_in()
220 p->status = USB_RET_STALL; in do_token_in()
221 usb_pcap_ctrl(p, false); in do_token_in()
225 p->status = USB_RET_STALL; in do_token_in()
229 static void do_token_out(USBDevice *s, USBPacket *p) in do_token_out() argument
231 assert(p->ep->nr == 0); in do_token_out()
237 usb_pcap_ctrl(p, false); in do_token_out()
247 if (len > p->iov.size) { in do_token_out()
248 len = p->iov.size; in do_token_out()
250 usb_packet_copy(p, s->data_buf + s->setup_index, len); in do_token_out()
258 p->status = USB_RET_STALL; in do_token_out()
259 usb_pcap_ctrl(p, false); in do_token_out()
263 p->status = USB_RET_STALL; in do_token_out()
267 static void do_parameter(USBDevice *s, USBPacket *p) in do_parameter() argument
273 s->setup_buf[i] = p->parameter >> (i*8); in do_parameter()
288 p->status = USB_RET_STALL; in do_parameter()
293 if (p->pid == USB_TOKEN_OUT) { in do_parameter()
294 usb_packet_copy(p, s->data_buf, s->setup_len); in do_parameter()
297 usb_pcap_ctrl(p, true); in do_parameter()
298 usb_device_handle_control(s, p, request, value, index, in do_parameter()
300 if (p->status == USB_RET_ASYNC) { in do_parameter()
304 if (p->actual_length < s->setup_len) { in do_parameter()
305 s->setup_len = p->actual_length; in do_parameter()
307 if (p->pid == USB_TOKEN_IN) { in do_parameter()
308 p->actual_length = 0; in do_parameter()
309 usb_packet_copy(p, s->data_buf, s->setup_len); in do_parameter()
311 usb_pcap_ctrl(p, false); in do_parameter()
318 void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p) in usb_generic_async_ctrl_complete() argument
320 if (p->status < 0) { in usb_generic_async_ctrl_complete()
322 usb_pcap_ctrl(p, false); in usb_generic_async_ctrl_complete()
327 if (p->actual_length < s->setup_len) { in usb_generic_async_ctrl_complete()
328 s->setup_len = p->actual_length; in usb_generic_async_ctrl_complete()
331 p->actual_length = 8; in usb_generic_async_ctrl_complete()
336 p->actual_length = 0; in usb_generic_async_ctrl_complete()
337 usb_pcap_ctrl(p, false); in usb_generic_async_ctrl_complete()
341 if (p->actual_length < s->setup_len) { in usb_generic_async_ctrl_complete()
342 s->setup_len = p->actual_length; in usb_generic_async_ctrl_complete()
344 if (p->pid == USB_TOKEN_IN) { in usb_generic_async_ctrl_complete()
345 p->actual_length = 0; in usb_generic_async_ctrl_complete()
346 usb_packet_copy(p, s->data_buf, s->setup_len); in usb_generic_async_ctrl_complete()
353 usb_packet_complete(s, p); in usb_generic_async_ctrl_complete()
369 static void usb_process_one(USBPacket *p) in usb_process_one() argument
371 USBDevice *dev = p->ep->dev; in usb_process_one()
379 nak = (p->status == USB_RET_NAK); in usb_process_one()
380 p->status = USB_RET_SUCCESS; in usb_process_one()
382 if (p->ep->nr == 0) { in usb_process_one()
384 if (p->parameter) { in usb_process_one()
385 do_parameter(dev, p); in usb_process_one()
388 switch (p->pid) { in usb_process_one()
390 do_token_setup(dev, p); in usb_process_one()
393 do_token_in(dev, p); in usb_process_one()
396 do_token_out(dev, p); in usb_process_one()
399 p->status = USB_RET_STALL; in usb_process_one()
404 usb_pcap_data(p, true); in usb_process_one()
406 usb_device_handle_data(dev, p); in usb_process_one()
410 static void usb_queue_one(USBPacket *p) in usb_queue_one() argument
412 usb_packet_set_state(p, USB_PACKET_QUEUED); in usb_queue_one()
413 QTAILQ_INSERT_TAIL(&p->ep->queue, p, queue); in usb_queue_one()
414 p->status = USB_RET_ASYNC; in usb_queue_one()
420 void usb_handle_packet(USBDevice *dev, USBPacket *p) in usb_handle_packet() argument
423 p->status = USB_RET_NODEV; in usb_handle_packet()
426 assert(dev == p->ep->dev); in usb_handle_packet()
428 usb_packet_check_state(p, USB_PACKET_SETUP); in usb_handle_packet()
429 assert(p->ep != NULL); in usb_handle_packet()
432 if (p->ep->halted) { in usb_handle_packet()
433 assert(QTAILQ_EMPTY(&p->ep->queue)); in usb_handle_packet()
434 p->ep->halted = false; in usb_handle_packet()
437 if (QTAILQ_EMPTY(&p->ep->queue) || p->ep->pipeline || p->stream) { in usb_handle_packet()
438 usb_process_one(p); in usb_handle_packet()
439 if (p->status == USB_RET_ASYNC) { in usb_handle_packet()
441 assert(p->ep->type != USB_ENDPOINT_XFER_ISOC); in usb_handle_packet()
443 assert(p->ep->type != USB_ENDPOINT_XFER_INT || in usb_handle_packet()
445 usb_packet_set_state(p, USB_PACKET_ASYNC); in usb_handle_packet()
446 QTAILQ_INSERT_TAIL(&p->ep->queue, p, queue); in usb_handle_packet()
447 } else if (p->status == USB_RET_ADD_TO_QUEUE) { in usb_handle_packet()
448 usb_queue_one(p); in usb_handle_packet()
454 assert(p->stream || !p->ep->pipeline || in usb_handle_packet()
455 QTAILQ_EMPTY(&p->ep->queue)); in usb_handle_packet()
456 if (p->status != USB_RET_NAK) { in usb_handle_packet()
457 usb_pcap_data(p, false); in usb_handle_packet()
458 usb_packet_set_state(p, USB_PACKET_COMPLETE); in usb_handle_packet()
462 usb_queue_one(p); in usb_handle_packet()
466 void usb_packet_complete_one(USBDevice *dev, USBPacket *p) in usb_packet_complete_one() argument
468 USBEndpoint *ep = p->ep; in usb_packet_complete_one()
470 assert(p->stream || QTAILQ_FIRST(&ep->queue) == p); in usb_packet_complete_one()
471 assert(p->status != USB_RET_ASYNC && p->status != USB_RET_NAK); in usb_packet_complete_one()
473 if (p->status != USB_RET_SUCCESS || in usb_packet_complete_one()
474 (p->short_not_ok && (p->actual_length < p->iov.size))) { in usb_packet_complete_one()
477 usb_pcap_data(p, false); in usb_packet_complete_one()
478 usb_packet_set_state(p, USB_PACKET_COMPLETE); in usb_packet_complete_one()
479 QTAILQ_REMOVE(&ep->queue, p, queue); in usb_packet_complete_one()
480 dev->port->ops->complete(dev->port, p); in usb_packet_complete_one()
486 void usb_packet_complete(USBDevice *dev, USBPacket *p) in usb_packet_complete() argument
488 USBEndpoint *ep = p->ep; in usb_packet_complete()
490 usb_packet_check_state(p, USB_PACKET_ASYNC); in usb_packet_complete()
491 usb_packet_complete_one(dev, p); in usb_packet_complete()
494 p = QTAILQ_FIRST(&ep->queue); in usb_packet_complete()
497 p->status = USB_RET_REMOVE_FROM_QUEUE; in usb_packet_complete()
498 dev->port->ops->complete(dev->port, p); in usb_packet_complete()
501 if (p->state == USB_PACKET_ASYNC) { in usb_packet_complete()
504 usb_packet_check_state(p, USB_PACKET_QUEUED); in usb_packet_complete()
505 usb_process_one(p); in usb_packet_complete()
506 if (p->status == USB_RET_ASYNC) { in usb_packet_complete()
507 usb_packet_set_state(p, USB_PACKET_ASYNC); in usb_packet_complete()
510 usb_packet_complete_one(ep->dev, p); in usb_packet_complete()
517 void usb_cancel_packet(USBPacket * p) in usb_cancel_packet() argument
519 bool callback = (p->state == USB_PACKET_ASYNC); in usb_cancel_packet()
520 assert(usb_packet_is_inflight(p)); in usb_cancel_packet()
521 usb_packet_set_state(p, USB_PACKET_CANCELED); in usb_cancel_packet()
522 QTAILQ_REMOVE(&p->ep->queue, p, queue); in usb_cancel_packet()
524 usb_device_cancel_packet(p->ep->dev, p); in usb_cancel_packet()
529 void usb_packet_init(USBPacket *p) in usb_packet_init() argument
531 qemu_iovec_init(&p->iov, 1); in usb_packet_init()
550 void usb_packet_check_state(USBPacket *p, USBPacketState expected) in usb_packet_check_state() argument
555 if (p->state == expected) { in usb_packet_check_state()
558 dev = p->ep->dev; in usb_packet_check_state()
560 trace_usb_packet_state_fault(bus->busnr, dev->port->path, p->ep->nr, p, in usb_packet_check_state()
561 usb_packet_state_name(p->state), in usb_packet_check_state()
566 void usb_packet_set_state(USBPacket *p, USBPacketState state) in usb_packet_set_state() argument
568 if (p->ep) { in usb_packet_set_state()
569 USBDevice *dev = p->ep->dev; in usb_packet_set_state()
571 trace_usb_packet_state_change(bus->busnr, dev->port->path, p->ep->nr, p, in usb_packet_set_state()
572 usb_packet_state_name(p->state), in usb_packet_set_state()
575 trace_usb_packet_state_change(-1, "", -1, p, in usb_packet_set_state()
576 usb_packet_state_name(p->state), in usb_packet_set_state()
579 p->state = state; in usb_packet_set_state()
582 void usb_packet_setup(USBPacket *p, int pid, in usb_packet_setup() argument
586 assert(!usb_packet_is_inflight(p)); in usb_packet_setup()
587 assert(p->iov.iov != NULL); in usb_packet_setup()
588 p->id = id; in usb_packet_setup()
589 p->pid = pid; in usb_packet_setup()
590 p->ep = ep; in usb_packet_setup()
591 p->stream = stream; in usb_packet_setup()
592 p->status = USB_RET_SUCCESS; in usb_packet_setup()
593 p->actual_length = 0; in usb_packet_setup()
594 p->parameter = 0; in usb_packet_setup()
595 p->short_not_ok = short_not_ok; in usb_packet_setup()
596 p->int_req = int_req; in usb_packet_setup()
597 p->combined = NULL; in usb_packet_setup()
598 qemu_iovec_reset(&p->iov); in usb_packet_setup()
599 usb_packet_set_state(p, USB_PACKET_SETUP); in usb_packet_setup()
602 void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len) in usb_packet_addbuf() argument
604 qemu_iovec_add(&p->iov, ptr, len); in usb_packet_addbuf()
607 void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes) in usb_packet_copy() argument
609 QEMUIOVector *iov = p->combined ? &p->combined->iov : &p->iov; in usb_packet_copy()
611 assert(p->actual_length >= 0); in usb_packet_copy()
612 assert(p->actual_length + bytes <= iov->size); in usb_packet_copy()
613 switch (p->pid) { in usb_packet_copy()
616 iov_to_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes); in usb_packet_copy()
619 iov_from_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes); in usb_packet_copy()
622 fprintf(stderr, "%s: invalid pid: %x\n", __func__, p->pid); in usb_packet_copy()
625 p->actual_length += bytes; in usb_packet_copy()
628 void usb_packet_skip(USBPacket *p, size_t bytes) in usb_packet_skip() argument
630 QEMUIOVector *iov = p->combined ? &p->combined->iov : &p->iov; in usb_packet_skip()
632 assert(p->actual_length >= 0); in usb_packet_skip()
633 assert(p->actual_length + bytes <= iov->size); in usb_packet_skip()
634 if (p->pid == USB_TOKEN_IN) { in usb_packet_skip()
635 iov_memset(iov->iov, iov->niov, p->actual_length, 0, bytes); in usb_packet_skip()
637 p->actual_length += bytes; in usb_packet_skip()
640 size_t usb_packet_size(USBPacket *p) in usb_packet_size() argument
642 return p->combined ? p->combined->iov.size : p->iov.size; in usb_packet_size()
645 void usb_packet_cleanup(USBPacket *p) in usb_packet_cleanup() argument
647 assert(!usb_packet_is_inflight(p)); in usb_packet_cleanup()
648 qemu_iovec_destroy(&p->iov); in usb_packet_cleanup()
812 USBPacket *p; in usb_ep_find_packet_by_id() local
814 QTAILQ_FOREACH(p, &uep->queue, queue) { in usb_ep_find_packet_by_id()
815 if (p->id == id) { in usb_ep_find_packet_by_id()
816 return p; in usb_ep_find_packet_by_id()