Lines Matching +full:transfer +full:- +full:function

1 // SPDX-License-Identifier: GPL-2.0
24 if (urb->transfer_flags & URB_FREE_BUFFER) in urb_destroy()
25 kfree(urb->transfer_buffer); in urb_destroy()
31 * usb_init_urb - initializes a urb so that it can be used by a USB driver
37 * necessary to call this function. Only use this if you allocate the
38 * space for a struct urb on your own. If you call this function, be
42 * Only use this function if you _really_ understand what you are doing.
48 kref_init(&urb->kref); in usb_init_urb()
49 INIT_LIST_HEAD(&urb->urb_list); in usb_init_urb()
50 INIT_LIST_HEAD(&urb->anchor_list); in usb_init_urb()
56 * usb_alloc_urb - creates a new urb for a USB driver to use
85 * usb_free_urb - frees the memory used by a urb when all users of it are finished
89 * of the urb calls this function, the memory of the urb is freed.
91 * Note: The transfer buffer associated with the urb is not freed unless the
92 * URB_FREE_BUFFER transfer flag is set.
97 kref_put(&urb->kref, urb_destroy); in usb_free_urb()
102 * usb_get_urb - increments the reference count of the urb
114 kref_get(&urb->kref); in usb_get_urb()
120 * usb_anchor_urb - anchors an URB while it is processed
131 spin_lock_irqsave(&anchor->lock, flags); in usb_anchor_urb()
133 list_add_tail(&urb->anchor_list, &anchor->urb_list); in usb_anchor_urb()
134 urb->anchor = anchor; in usb_anchor_urb()
136 if (unlikely(anchor->poisoned)) in usb_anchor_urb()
137 atomic_inc(&urb->reject); in usb_anchor_urb()
139 spin_unlock_irqrestore(&anchor->lock, flags); in usb_anchor_urb()
145 return atomic_read(&anchor->suspend_wakeups) == 0 && in usb_anchor_check_wakeup()
146 list_empty(&anchor->urb_list); in usb_anchor_check_wakeup()
149 /* Callers must hold anchor->lock */
152 urb->anchor = NULL; in __usb_unanchor_urb()
153 list_del(&urb->anchor_list); in __usb_unanchor_urb()
156 wake_up(&anchor->wait); in __usb_unanchor_urb()
160 * usb_unanchor_urb - unanchors an URB
173 anchor = urb->anchor; in usb_unanchor_urb()
177 spin_lock_irqsave(&anchor->lock, flags); in usb_unanchor_urb()
183 if (likely(anchor == urb->anchor)) in usb_unanchor_urb()
185 spin_unlock_irqrestore(&anchor->lock, flags); in usb_unanchor_urb()
189 /*-------------------------------------------------------------------*/
196 * usb_pipe_type_check - sanity check of a specific pipe for a usb device
200 * This performs a light-weight sanity check for the endpoint in the
210 return -EINVAL; in usb_pipe_type_check()
211 if (usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)]) in usb_pipe_type_check()
212 return -EINVAL; in usb_pipe_type_check()
218 * usb_urb_ep_type_check - sanity check of endpoint in the given urb
221 * This performs a light-weight sanity check for the endpoint in the
227 return usb_pipe_type_check(urb->dev, urb->pipe); in usb_urb_ep_type_check()
232 * usb_submit_urb - issue an asynchronous transfer request for an endpoint
237 * This submits a transfer request, and transfers control of the URB
241 * (a software-induced fault, also called "request cancellation").
248 * the particular kind of transfer, although they will not initialize
249 * any transfer flags.
253 * (HCD) are finished with the URB. When the completion function is called,
260 * The exceptions relate to periodic transfer scheduling. For both
262 * urb->interval is modified to reflect the actual transfer period used
264 * urb->start_frame is modified to reflect when the URB's transfers were
267 * Not all isochronous transfer scheduling policies will work, but most
269 * until 10-200 msec into the future. Drivers should try to keep at
281 * usb_iso_packet_descriptor's status field will return -EXDEV. If this
283 * -EXDEV error code.
286 * often used (in non-interrupt context) instead of this call.
305 * As of Linux 2.6, all USB endpoint transfer queues support depths greater
306 * than one. This was previously a HCD-specific behavior, except for ISO
307 * transfers. Non-isochronous endpoint queues are inactive during cleanup
308 * after faults (transfer errors or cancellation).
329 * they need, by reinitializing and resubmitting the just-completed urb
346 * (c) current->state != TASK_RUNNING, this is the case only after
376 if (!urb || !urb->complete) in usb_submit_urb()
377 return -EINVAL; in usb_submit_urb()
378 if (urb->hcpriv) { in usb_submit_urb()
380 return -EBUSY; in usb_submit_urb()
383 dev = urb->dev; in usb_submit_urb()
384 if ((!dev) || (dev->state < USB_STATE_UNAUTHENTICATED)) in usb_submit_urb()
385 return -ENODEV; in usb_submit_urb()
388 * will be required to set urb->ep directly and we will eliminate in usb_submit_urb()
389 * urb->pipe. in usb_submit_urb()
391 ep = usb_pipe_endpoint(dev, urb->pipe); in usb_submit_urb()
393 return -ENOENT; in usb_submit_urb()
395 urb->ep = ep; in usb_submit_urb()
396 urb->status = -EINPROGRESS; in usb_submit_urb()
397 urb->actual_length = 0; in usb_submit_urb()
402 xfertype = usb_endpoint_type(&ep->desc); in usb_submit_urb()
405 (struct usb_ctrlrequest *) urb->setup_packet; in usb_submit_urb()
408 return -ENOEXEC; in usb_submit_urb()
409 is_out = !(setup->bRequestType & USB_DIR_IN) || in usb_submit_urb()
410 !setup->wLength; in usb_submit_urb()
411 dev_WARN_ONCE(&dev->dev, (usb_pipeout(urb->pipe) != is_out), in usb_submit_urb()
413 urb->pipe, setup->bRequestType); in usb_submit_urb()
414 if (le16_to_cpu(setup->wLength) != urb->transfer_buffer_length) { in usb_submit_urb()
415 dev_dbg(&dev->dev, "BOGUS control len %d doesn't match transfer length %d\n", in usb_submit_urb()
416 le16_to_cpu(setup->wLength), in usb_submit_urb()
417 urb->transfer_buffer_length); in usb_submit_urb()
418 return -EBADR; in usb_submit_urb()
421 is_out = usb_endpoint_dir_out(&ep->desc); in usb_submit_urb()
425 urb->transfer_flags &= ~(URB_DIR_MASK | URB_DMA_MAP_SINGLE | in usb_submit_urb()
429 urb->transfer_flags |= (is_out ? URB_DIR_OUT : URB_DIR_IN); in usb_submit_urb()
433 dev->state < USB_STATE_CONFIGURED) in usb_submit_urb()
434 return -ENODEV; in usb_submit_urb()
436 max = usb_endpoint_maxp(&ep->desc); in usb_submit_urb()
438 dev_dbg(&dev->dev, in usb_submit_urb()
440 usb_endpoint_num(&ep->desc), is_out ? "out" : "in", in usb_submit_urb()
442 return -EMSGSIZE; in usb_submit_urb()
455 if (dev->speed >= USB_SPEED_SUPER) { in usb_submit_urb()
456 int burst = 1 + ep->ss_ep_comp.bMaxBurst; in usb_submit_urb()
457 int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes); in usb_submit_urb()
462 if (dev->speed == USB_SPEED_SUPER_PLUS && in usb_submit_urb()
463 USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) { in usb_submit_urb()
466 isoc_ep_comp = &ep->ssp_isoc_ep_comp; in usb_submit_urb()
467 max = le32_to_cpu(isoc_ep_comp->dwBytesPerInterval); in usb_submit_urb()
470 /* "high bandwidth" mode, 1-3 packets/uframe? */ in usb_submit_urb()
471 if (dev->speed == USB_SPEED_HIGH) in usb_submit_urb()
472 max *= usb_endpoint_maxp_mult(&ep->desc); in usb_submit_urb()
474 if (urb->number_of_packets <= 0) in usb_submit_urb()
475 return -EINVAL; in usb_submit_urb()
476 for (n = 0; n < urb->number_of_packets; n++) { in usb_submit_urb()
477 len = urb->iso_frame_desc[n].length; in usb_submit_urb()
479 return -EMSGSIZE; in usb_submit_urb()
480 urb->iso_frame_desc[n].status = -EXDEV; in usb_submit_urb()
481 urb->iso_frame_desc[n].actual_length = 0; in usb_submit_urb()
483 } else if (urb->num_sgs && !urb->dev->bus->no_sg_constraint) { in usb_submit_urb()
487 for_each_sg(urb->sg, sg, urb->num_sgs - 1, i) in usb_submit_urb()
488 if (sg->length % max) in usb_submit_urb()
489 return -EINVAL; in usb_submit_urb()
493 if (urb->transfer_buffer_length > INT_MAX) in usb_submit_urb()
494 return -EMSGSIZE; in usb_submit_urb()
502 if (usb_pipe_type_check(urb->dev, urb->pipe)) in usb_submit_urb()
503 dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n", in usb_submit_urb()
504 usb_pipetype(urb->pipe), pipetypes[xfertype]); in usb_submit_urb()
515 default: /* all non-iso endpoints */ in usb_submit_urb()
523 allowed &= urb->transfer_flags; in usb_submit_urb()
526 if (allowed != urb->transfer_flags) in usb_submit_urb()
527 dev_WARN(&dev->dev, "BOGUS urb flags, %x --> %x\n", in usb_submit_urb()
528 urb->transfer_flags, allowed); in usb_submit_urb()
531 * Force periodic transfer intervals to be legal values that are in usb_submit_urb()
534 * FIXME want bus->{intr,iso}_sched_horizon values here. Each HC in usb_submit_urb()
536 * EHCI can use smaller non-default values). in usb_submit_urb()
542 if (urb->interval <= 0) in usb_submit_urb()
543 return -EINVAL; in usb_submit_urb()
546 switch (dev->speed) { in usb_submit_urb()
549 /* Handle up to 2^(16-1) microframes */ in usb_submit_urb()
550 if (urb->interval > (1 << 15)) in usb_submit_urb()
551 return -EINVAL; in usb_submit_urb()
556 if (urb->interval > (1024 * 8)) in usb_submit_urb()
557 urb->interval = 1024 * 8; in usb_submit_urb()
563 if (urb->interval > 255) in usb_submit_urb()
564 return -EINVAL; in usb_submit_urb()
568 if (urb->interval > 1024) in usb_submit_urb()
569 urb->interval = 1024; in usb_submit_urb()
575 return -EINVAL; in usb_submit_urb()
578 urb->interval = min(max, 1 << ilog2(urb->interval)); in usb_submit_urb()
585 /*-------------------------------------------------------------------*/
588 * usb_unlink_urb - abort/cancel a transfer request for an endpoint
592 * This routine cancels an in-progress request. URBs complete only once
601 * method has returned. The disconnect function should synchronize with
602 * a driver's I/O routines to insure that all URB-related activity has
605 * This request is asynchronous, however the HCD might call the ->complete()
607 * must not hold any locks that may be taken by the completion function.
608 * Success is indicated by returning -EINPROGRESS, at which time the URB will
610 * eventually called, the completion function will see @urb->status ==
611 * -ECONNRESET.
621 * Return: -EINPROGRESS on success. See description for other values on
640 * URB terminates with any sort of error, including -ECONNRESET, -ENOENT,
641 * and -EREMOTEIO. Control endpoint queues behave the same way except
642 * that they are not guaranteed to stop for -EREMOTEIO errors. Queues
650 * received will generate a -EREMOTEIO error if and only if the
653 * and clean them up reliably after any sort of aborted transfer by
656 * When a control URB terminates with an error other than -EREMOTEIO, it
657 * is quite likely that the status stage of the transfer will not take
663 return -EINVAL; in usb_unlink_urb()
664 if (!urb->dev) in usb_unlink_urb()
665 return -ENODEV; in usb_unlink_urb()
666 if (!urb->ep) in usb_unlink_urb()
667 return -EIDRM; in usb_unlink_urb()
668 return usb_hcd_unlink_urb(urb, -ECONNRESET); in usb_unlink_urb()
673 * usb_kill_urb - cancel a transfer request and wait for it to finish
677 * This routine cancels an in-progress request. It is guaranteed that
681 * function. If the request has not already finished or been unlinked
682 * the completion handler will see urb->status == -ENOENT.
685 * with error -EPERM. Thus even if the URB's completion handler always
702 if (!(urb && urb->dev && urb->ep)) in usb_kill_urb()
704 atomic_inc(&urb->reject); in usb_kill_urb()
706 * Order the write of urb->reject above before the read in usb_kill_urb()
707 * of urb->use_count below. Pairs with the barriers in in usb_kill_urb()
712 usb_hcd_unlink_urb(urb, -ENOENT); in usb_kill_urb()
713 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); in usb_kill_urb()
715 atomic_dec(&urb->reject); in usb_kill_urb()
720 * usb_poison_urb - reliably kill a transfer and prevent further use of an URB
724 * This routine cancels an in-progress request. It is guaranteed that
729 * the completion handler will see urb->status == -ENOENT.
732 * with error -EPERM. Thus even if the URB's completion handler always
751 atomic_inc(&urb->reject); in usb_poison_urb()
753 * Order the write of urb->reject above before the read in usb_poison_urb()
754 * of urb->use_count below. Pairs with the barriers in in usb_poison_urb()
759 if (!urb->dev || !urb->ep) in usb_poison_urb()
762 usb_hcd_unlink_urb(urb, -ENOENT); in usb_poison_urb()
763 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); in usb_poison_urb()
772 atomic_dec(&urb->reject); in usb_unpoison_urb()
777 * usb_block_urb - reliably prevent further use of an URB
781 * with error -EPERM. Thus even if the URB's completion handler always
793 atomic_inc(&urb->reject); in usb_block_urb()
798 * usb_kill_anchored_urbs - kill all URBs associated with an anchor
803 * anchor after this function returns.
814 spin_lock_irq(&anchor->lock); in usb_kill_anchored_urbs()
815 while (!list_empty(&anchor->urb_list)) { in usb_kill_anchored_urbs()
816 victim = list_entry(anchor->urb_list.prev, in usb_kill_anchored_urbs()
820 spin_unlock_irq(&anchor->lock); in usb_kill_anchored_urbs()
824 spin_lock_irq(&anchor->lock); in usb_kill_anchored_urbs()
828 spin_unlock_irq(&anchor->lock); in usb_kill_anchored_urbs()
836 * usb_poison_anchored_urbs - cease all traffic from an anchor
852 spin_lock_irq(&anchor->lock); in usb_poison_anchored_urbs()
853 anchor->poisoned = 1; in usb_poison_anchored_urbs()
854 while (!list_empty(&anchor->urb_list)) { in usb_poison_anchored_urbs()
855 victim = list_entry(anchor->urb_list.prev, in usb_poison_anchored_urbs()
859 spin_unlock_irq(&anchor->lock); in usb_poison_anchored_urbs()
863 spin_lock_irq(&anchor->lock); in usb_poison_anchored_urbs()
867 spin_unlock_irq(&anchor->lock); in usb_poison_anchored_urbs()
874 * usb_unpoison_anchored_urbs - let an anchor be used successfully again
885 spin_lock_irqsave(&anchor->lock, flags); in usb_unpoison_anchored_urbs()
886 list_for_each_entry(lazarus, &anchor->urb_list, anchor_list) { in usb_unpoison_anchored_urbs()
889 anchor->poisoned = 0; in usb_unpoison_anchored_urbs()
890 spin_unlock_irqrestore(&anchor->lock, flags); in usb_unpoison_anchored_urbs()
894 * usb_unlink_anchored_urbs - asynchronously cancel transfer requests en masse
898 * from the back of the queue. This function is asynchronous.
900 * function has returned.
921 * usb_wait_anchor_empty_timeout waiters. This is used in the hcd urb give-
927 atomic_inc(&anchor->suspend_wakeups); in usb_anchor_suspend_wakeups()
943 atomic_dec(&anchor->suspend_wakeups); in usb_anchor_resume_wakeups()
945 wake_up(&anchor->wait); in usb_anchor_resume_wakeups()
950 * usb_wait_anchor_empty_timeout - wait for an anchor to be unused
957 * Return: Non-zero if the anchor became unused. Zero on timeout.
962 return wait_event_timeout(anchor->wait, in usb_wait_anchor_empty_timeout()
969 * usb_get_from_anchor - get an anchor's oldest urb
983 spin_lock_irqsave(&anchor->lock, flags); in usb_get_from_anchor()
984 if (!list_empty(&anchor->urb_list)) { in usb_get_from_anchor()
985 victim = list_entry(anchor->urb_list.next, struct urb, in usb_get_from_anchor()
992 spin_unlock_irqrestore(&anchor->lock, flags); in usb_get_from_anchor()
1000 * usb_scuttle_anchored_urbs - unanchor all an anchor's urbs
1012 spin_lock_irqsave(&anchor->lock, flags); in usb_scuttle_anchored_urbs()
1013 while (!list_empty(&anchor->urb_list)) { in usb_scuttle_anchored_urbs()
1014 victim = list_entry(anchor->urb_list.prev, in usb_scuttle_anchored_urbs()
1020 spin_unlock_irqrestore(&anchor->lock, flags); in usb_scuttle_anchored_urbs()
1028 * usb_anchor_empty - is an anchor empty
1035 return list_empty(&anchor->urb_list); in usb_anchor_empty()