Lines Matching +full:transfer +full:- +full:function
1 /*-
2 * Copyright (c) 2007 Luigi Rizzo - Universita` di Pisa. All rights reserved.
100 /*------------------------------------------------------------------------*
102 *------------------------------------------------------------------------*/
127 /*------------------------------------------------------------------------*
134 *------------------------------------------------------------------------*/
146 for (; id->match_flags; id++) { in usb_linux_lookup_id()
147 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && in usb_linux_lookup_id()
148 (id->idVendor != uaa->info.idVendor)) { in usb_linux_lookup_id()
151 if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) && in usb_linux_lookup_id()
152 (id->idProduct != uaa->info.idProduct)) { in usb_linux_lookup_id()
155 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) && in usb_linux_lookup_id()
156 (id->bcdDevice_lo > uaa->info.bcdDevice)) { in usb_linux_lookup_id()
159 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) && in usb_linux_lookup_id()
160 (id->bcdDevice_hi < uaa->info.bcdDevice)) { in usb_linux_lookup_id()
163 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) && in usb_linux_lookup_id()
164 (id->bDeviceClass != uaa->info.bDeviceClass)) { in usb_linux_lookup_id()
167 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) && in usb_linux_lookup_id()
168 (id->bDeviceSubClass != uaa->info.bDeviceSubClass)) { in usb_linux_lookup_id()
171 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) && in usb_linux_lookup_id()
172 (id->bDeviceProtocol != uaa->info.bDeviceProtocol)) { in usb_linux_lookup_id()
175 if ((uaa->info.bDeviceClass == 0xFF) && in usb_linux_lookup_id()
176 !(id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) && in usb_linux_lookup_id()
177 (id->match_flags & (USB_DEVICE_ID_MATCH_INT_CLASS | in usb_linux_lookup_id()
182 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) && in usb_linux_lookup_id()
183 (id->bInterfaceClass != uaa->info.bInterfaceClass)) { in usb_linux_lookup_id()
186 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) && in usb_linux_lookup_id()
187 (id->bInterfaceSubClass != uaa->info.bInterfaceSubClass)) { in usb_linux_lookup_id()
190 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) && in usb_linux_lookup_id()
191 (id->bInterfaceProtocol != uaa->info.bInterfaceProtocol)) { in usb_linux_lookup_id()
202 /*------------------------------------------------------------------------*
205 * This function is the FreeBSD probe callback. It is called from the
206 * FreeBSD USB stack through the "device_probe_and_attach()" function.
207 *------------------------------------------------------------------------*/
215 if (uaa->usb_mode != USB_MODE_HOST) { in usb_linux_probe()
220 if (usb_linux_lookup_id(udrv->id_table, uaa)) { in usb_linux_probe()
230 /*------------------------------------------------------------------------*
233 * This function returns the pointer to the "struct usb_driver" where
236 *------------------------------------------------------------------------*/
243 udrv = sc->sc_udrv; in usb_linux_get_usb_driver()
248 /*------------------------------------------------------------------------*
251 * This function is the FreeBSD attach callback. It is called from the
252 * FreeBSD USB stack through the "device_probe_and_attach()" function.
253 * This function is called when "usb_linux_probe()" returns zero.
254 *------------------------------------------------------------------------*/
265 id = usb_linux_lookup_id(udrv->id_table, uaa); in usb_linux_attach()
274 if (usb_linux_create_usb_device(uaa->device, dev) != 0) in usb_linux_attach()
278 sc->sc_fbsd_udev = uaa->device; in usb_linux_attach()
279 sc->sc_fbsd_dev = dev; in usb_linux_attach()
280 sc->sc_udrv = udrv; in usb_linux_attach()
281 sc->sc_ui = usb_ifnum_to_if(uaa->device, uaa->info.bIfaceNum); in usb_linux_attach()
282 if (sc->sc_ui == NULL) { in usb_linux_attach()
285 if (udrv->probe) { in usb_linux_attach()
286 if ((udrv->probe) (sc->sc_ui, id)) { in usb_linux_attach()
298 /*------------------------------------------------------------------------*
301 * This function is the FreeBSD detach callback. It is called from the
302 * FreeBSD USB stack through the "device_detach()" function.
303 *------------------------------------------------------------------------*/
311 if (sc->sc_attached_list.le_prev) { in usb_linux_detach()
313 sc->sc_attached_list.le_prev = NULL; in usb_linux_detach()
314 udrv = sc->sc_udrv; in usb_linux_detach()
315 sc->sc_udrv = NULL; in usb_linux_detach()
319 if (udrv && udrv->disconnect) { in usb_linux_detach()
320 (udrv->disconnect) (sc->sc_ui); in usb_linux_detach()
327 usb_linux_cleanup_interface(sc->sc_fbsd_udev, sc->sc_ui); in usb_linux_detach()
331 /*------------------------------------------------------------------------*
334 * This function is the FreeBSD suspend callback. Usually it does nothing.
335 *------------------------------------------------------------------------*/
345 if (udrv && udrv->suspend) { in usb_linux_suspend()
347 err = (udrv->suspend) (sc->sc_ui, pm_msg); in usb_linux_suspend()
349 return (-err); in usb_linux_suspend()
352 /*------------------------------------------------------------------------*
355 * This function is the FreeBSD resume callback. Usually it does nothing.
356 *------------------------------------------------------------------------*/
365 if (udrv && udrv->resume) in usb_linux_resume()
366 err = (udrv->resume) (sc->sc_ui); in usb_linux_resume()
367 return (-err); in usb_linux_resume()
370 /*------------------------------------------------------------------------*
372 *------------------------------------------------------------------------*/
374 /*------------------------------------------------------------------------*
377 * The following function returns the maximum number of isochronous
379 *------------------------------------------------------------------------*/
393 /*------------------------------------------------------------------------*
396 * This function is used to queue an URB after that it has been
397 * initialized. If it returns non-zero, it means that the URB was not
399 *------------------------------------------------------------------------*/
408 return (-EINVAL); in usb_submit_urb()
414 if (urb->endpoint == NULL) { in usb_submit_urb()
415 err = -EINVAL; in usb_submit_urb()
422 * being re-submitted (e.g. from its completion callback in usb_submit_urb()
423 * function). in usb_submit_urb()
425 if (urb->kill_count != 0) { in usb_submit_urb()
426 err = -EPERM; in usb_submit_urb()
430 uhe = urb->endpoint; in usb_submit_urb()
433 * Check that we have got a FreeBSD USB transfer that will dequeue in usb_submit_urb()
434 * the URB structure and do the real transfer. If there are no USB in usb_submit_urb()
437 if (uhe->bsd_xfer[0] || in usb_submit_urb()
438 uhe->bsd_xfer[1]) { in usb_submit_urb()
441 TAILQ_INSERT_TAIL(&uhe->bsd_urb_list, urb, bsd_urb_list); in usb_submit_urb()
443 urb->status = -EINPROGRESS; in usb_submit_urb()
445 usbd_transfer_start(uhe->bsd_xfer[0]); in usb_submit_urb()
446 usbd_transfer_start(uhe->bsd_xfer[1]); in usb_submit_urb()
450 urb->status = -EINVAL; in usb_submit_urb()
451 err = -EINVAL; in usb_submit_urb()
459 /*------------------------------------------------------------------------*
462 * This function is used to stop an URB after that it is been
464 *------------------------------------------------------------------------*/
479 if (xfer->priv_fifo == (void *)urb) { in usb_unlink_bsd()
500 return (-EINVAL); in usb_unlink_urb_sub()
506 urb->kill_count++; in usb_unlink_urb_sub()
508 if (urb->endpoint == NULL) { in usb_unlink_urb_sub()
509 err = -EINVAL; in usb_unlink_urb_sub()
512 uhe = urb->endpoint; in usb_unlink_urb_sub()
514 if (urb->bsd_urb_list.tqe_prev) { in usb_unlink_urb_sub()
516 TAILQ_REMOVE(&uhe->bsd_urb_list, urb, bsd_urb_list); in usb_unlink_urb_sub()
517 urb->bsd_urb_list.tqe_prev = NULL; in usb_unlink_urb_sub()
518 urb->status = -ECONNRESET; in usb_unlink_urb_sub()
519 urb->actual_length = 0; in usb_unlink_urb_sub()
521 for (x = 0; x < urb->number_of_packets; x++) { in usb_unlink_urb_sub()
522 urb->iso_frame_desc[x].actual_length = 0; in usb_unlink_urb_sub()
525 if (urb->complete) { in usb_unlink_urb_sub()
526 (urb->complete) (urb); in usb_unlink_urb_sub()
531 * the FreeBSD USB transfer are processing the current URB. in usb_unlink_urb_sub()
532 * If so, re-start that transfer, which will lead to the in usb_unlink_urb_sub()
535 usb_unlink_bsd(uhe->bsd_xfer[0], urb, drain); in usb_unlink_urb_sub()
536 usb_unlink_bsd(uhe->bsd_xfer[1], urb, drain); in usb_unlink_urb_sub()
541 urb->kill_count--; in usb_unlink_urb_sub()
547 /*------------------------------------------------------------------------*
550 * This function must always be used to clear the stall. Stall is when
553 *------------------------------------------------------------------------*/
563 return (-EINVAL); in usb_clear_halt()
565 type = uhe->desc.bmAttributes & UE_XFERTYPE; in usb_clear_halt()
566 addr = uhe->desc.bEndpointAddress; in usb_clear_halt()
574 ep = usbd_get_endpoint(dev, uhe->bsd_iface_index, cfg); in usb_clear_halt()
576 return (-EINVAL); in usb_clear_halt()
580 return (usb_control_msg(dev, &dev->ep0, in usb_clear_halt()
585 /*------------------------------------------------------------------------*
588 * This is an internal function that is used to perform synchronous
590 *------------------------------------------------------------------------*/
601 urb->complete = &usb_linux_wait_complete; in usb_start_wait_urb()
602 urb->timeout = timeout; in usb_start_wait_urb()
603 urb->transfer_flags |= URB_WAIT_WAKEUP; in usb_start_wait_urb()
604 urb->transfer_flags &= ~URB_IS_SLEEPING; in usb_start_wait_urb()
617 while (urb->transfer_flags & URB_WAIT_WAKEUP) { in usb_start_wait_urb()
618 urb->transfer_flags |= URB_IS_SLEEPING; in usb_start_wait_urb()
619 cv_wait(&urb->cv_wait, &Giant); in usb_start_wait_urb()
620 urb->transfer_flags &= ~URB_IS_SLEEPING; in usb_start_wait_urb()
623 err = urb->status; in usb_start_wait_urb()
632 *p_actlen = urb->actual_length; in usb_start_wait_urb()
637 /*------------------------------------------------------------------------*
640 * The following function performs a control transfer sequence one any
642 * transfer means that you transfer an 8-byte header first followed by
643 * a data-phase as indicated by the 8-byte header. The "timeout" is
650 *------------------------------------------------------------------------*/
671 return (-EINVAL); in usb_control_msg()
673 type = (uhe->desc.bmAttributes & UE_XFERTYPE); in usb_control_msg()
674 addr = (uhe->desc.bEndpointAddress & UE_ADDR); in usb_control_msg()
677 return (-EINVAL); in usb_control_msg()
688 err = -EPIPE; in usb_control_msg()
694 if (dev->flags.usb_mode != USB_MODE_HOST) { in usb_control_msg()
696 return (-EINVAL); in usb_control_msg()
702 * transfer data to/from the stack! in usb_control_msg()
708 urb->dev = dev; in usb_control_msg()
709 urb->endpoint = uhe; in usb_control_msg()
711 memcpy(urb->setup_packet, &req, sizeof(req)); in usb_control_msg()
715 memcpy(USB_ADD_BYTES(urb->setup_packet, sizeof(req)), in usb_control_msg()
722 bcopy(USB_ADD_BYTES(urb->setup_packet, in usb_control_msg()
734 /*------------------------------------------------------------------------*
737 * The following function will select which alternate setting of an
741 *------------------------------------------------------------------------*/
749 return (-EINVAL); in usb_set_interface()
750 if (alt_index >= p_ui->num_altsetting) in usb_set_interface()
751 return (-EINVAL); in usb_set_interface()
753 err = -usbd_set_alt_interface_index(dev, in usb_set_interface()
754 p_ui->bsd_iface_index, alt_index); in usb_set_interface()
756 p_ui->cur_altsetting = p_ui->altsetting + alt_index; in usb_set_interface()
761 /*------------------------------------------------------------------------*
764 * The following function is an extension to the Linux USB API that
766 * The maximum buffer size is per URB. If you don't call this function
769 * a non-zero dummy, hence this function will base the maximum buffer
771 *------------------------------------------------------------------------*/
777 uint8_t type = uhe->desc.bmAttributes & UE_XFERTYPE; in usb_setup_endpoint()
778 uint8_t addr = uhe->desc.bEndpointAddress; in usb_setup_endpoint()
780 if (uhe->fbsd_buf_size == bufsize) { in usb_setup_endpoint()
784 usbd_transfer_unsetup(uhe->bsd_xfer, 2); in usb_setup_endpoint()
786 uhe->fbsd_buf_size = bufsize; in usb_setup_endpoint()
796 * into the BULK/INTR/CONTROL transfer model. in usb_setup_endpoint()
808 * The Linux USB API allows non back-to-back in usb_setup_endpoint()
810 * isochronous frames are not back-to-back we need to in usb_setup_endpoint()
822 if (usbd_transfer_setup(dev, &uhe->bsd_iface_index, in usb_setup_endpoint()
823 uhe->bsd_xfer, cfg, 2, uhe, &Giant)) { in usb_setup_endpoint()
824 return (-EINVAL); in usb_setup_endpoint()
831 /* Allocate and setup one generic FreeBSD USB transfer */ in usb_setup_endpoint()
838 cfg[0].flags.ext_buffer = 1; /* enable zero-copy */ in usb_setup_endpoint()
842 if (usbd_transfer_setup(dev, &uhe->bsd_iface_index, in usb_setup_endpoint()
843 uhe->bsd_xfer, cfg, 1, uhe, &Giant)) { in usb_setup_endpoint()
844 return (-EINVAL); in usb_setup_endpoint()
850 /*------------------------------------------------------------------------*
853 * The following function is used to build up a per USB device
855 * is returned by this function.
856 *------------------------------------------------------------------------*/
895 switch (desc->bDescriptorType) { in usb_linux_create_usb_device()
901 if ((ed->bLength < sizeof(*ed)) || in usb_linux_create_usb_device()
905 bcopy(ed, &p_uhe->desc, sizeof(p_uhe->desc)); in usb_linux_create_usb_device()
906 p_uhe->bsd_iface_index = iface_index - 1; in usb_linux_create_usb_device()
907 TAILQ_INIT(&p_uhe->bsd_urb_list); in usb_linux_create_usb_device()
911 (p_uhi - 1)->desc.bNumEndpoints++; in usb_linux_create_usb_device()
918 if (id->bLength < sizeof(*id)) in usb_linux_create_usb_device()
921 bcopy(id, &p_uhi->desc, sizeof(p_uhi->desc)); in usb_linux_create_usb_device()
922 p_uhi->desc.bNumEndpoints = 0; in usb_linux_create_usb_device()
923 p_uhi->endpoint = p_uhe; in usb_linux_create_usb_device()
924 p_uhi->string = ""; in usb_linux_create_usb_device()
925 p_uhi->bsd_iface_index = iface_index; in usb_linux_create_usb_device()
928 iface_no = id->bInterfaceNumber; in usb_linux_create_usb_device()
932 p_ui->altsetting = p_uhi - 1; in usb_linux_create_usb_device()
933 p_ui->cur_altsetting = p_uhi - 1; in usb_linux_create_usb_device()
934 p_ui->bsd_iface_index = iface_index; in usb_linux_create_usb_device()
935 p_ui->linux_udev = udev; in usb_linux_create_usb_device()
957 udev->linux_iface_start = p_ui; in usb_linux_create_usb_device()
958 udev->linux_iface_end = p_ui + iface_index; in usb_linux_create_usb_device()
959 udev->linux_endpoint_start = p_uhe; in usb_linux_create_usb_device()
960 udev->linux_endpoint_end = p_uhe + nedesc; in usb_linux_create_usb_device()
961 udev->devnum = device_get_unit(dev); in usb_linux_create_usb_device()
962 bcopy(&udev->ddesc, &udev->descriptor, in usb_linux_create_usb_device()
963 sizeof(udev->descriptor)); in usb_linux_create_usb_device()
964 bcopy(udev->ctrl_ep.edesc, &udev->ep0.desc, in usb_linux_create_usb_device()
965 sizeof(udev->ep0.desc)); in usb_linux_create_usb_device()
971 /*------------------------------------------------------------------------*
974 * This function should always be used when you allocate an URB for
975 * use with the USB Linux stack. In case of an isochronous transfer
977 * plan to transfer per URB. This function is always blocking, and
979 *------------------------------------------------------------------------*/
988 * FreeBSD specific magic value to ask for control transfer in usb_alloc_urb()
993 size = sizeof(*urb) + (iso_packets * sizeof(urb->iso_frame_desc[0])); in usb_alloc_urb()
998 cv_init(&urb->cv_wait, "URBWAIT"); in usb_alloc_urb()
1000 urb->setup_packet = (void *)(urb + 1); in usb_alloc_urb()
1001 urb->transfer_buffer = (void *)(urb->setup_packet + in usb_alloc_urb()
1004 urb->number_of_packets = iso_packets; in usb_alloc_urb()
1009 /*------------------------------------------------------------------------*
1012 * The following function will return the Linux USB host endpoint
1014 * value. If no match is found, NULL is returned. This function is not
1016 *------------------------------------------------------------------------*/
1043 for (ui = dev->linux_iface_start; in usb_find_host_endpoint()
1044 ui != dev->linux_iface_end; in usb_find_host_endpoint()
1046 uhi = ui->cur_altsetting; in usb_find_host_endpoint()
1048 uhe_end = uhi->endpoint + uhi->desc.bNumEndpoints; in usb_find_host_endpoint()
1049 for (uhe = uhi->endpoint; in usb_find_host_endpoint()
1052 ea = uhe->desc.bEndpointAddress; in usb_find_host_endpoint()
1053 at = uhe->desc.bmAttributes; in usb_find_host_endpoint()
1064 return (&dev->ep0); in usb_find_host_endpoint()
1069 /*------------------------------------------------------------------------*
1072 * The following function returns a pointer to an alternate setting by
1077 *------------------------------------------------------------------------*/
1081 if (alt_index >= intf->num_altsetting) { in usb_altnum_to_altsetting()
1084 return (intf->altsetting + alt_index); in usb_altnum_to_altsetting()
1087 /*------------------------------------------------------------------------*
1090 * The following function searches up an USB interface by
1092 *------------------------------------------------------------------------*/
1098 for (p_ui = dev->linux_iface_start; in usb_ifnum_to_if()
1099 p_ui != dev->linux_iface_end; in usb_ifnum_to_if()
1101 if ((p_ui->num_altsetting > 0) && in usb_ifnum_to_if()
1102 (p_ui->altsetting->desc.bInterfaceNumber == iface_no)) { in usb_ifnum_to_if()
1109 /*------------------------------------------------------------------------*
1111 *------------------------------------------------------------------------*/
1118 /*------------------------------------------------------------------------*
1120 *------------------------------------------------------------------------*/
1124 return (intf->bsd_priv_sc); in usbd_get_intfdata()
1127 /*------------------------------------------------------------------------*
1130 * The following function is used by the "USB_DRIVER_EXPORT()" macro,
1133 * function is not part of the Linux USB API, and is for internal use
1135 *------------------------------------------------------------------------*/
1148 /*------------------------------------------------------------------------*
1151 * The following function is used by the "USB_DRIVER_EXPORT()" macro,
1152 * and is used to deregister a Linux USB driver. This function will
1155 * unloaded. This function is not part of the Linux USB API, and is
1157 *------------------------------------------------------------------------*/
1167 if (sc->sc_udrv == drv) { in usb_linux_deregister()
1170 device_detach(sc->sc_fbsd_dev); in usb_linux_deregister()
1179 /*------------------------------------------------------------------------*
1182 * The following function is only used by the FreeBSD USB stack, to
1184 *------------------------------------------------------------------------*/
1191 uhe = dev->linux_endpoint_start; in usb_linux_free_device()
1192 uhe_end = dev->linux_endpoint_end; in usb_linux_free_device()
1197 usb_setup_endpoint(dev, &dev->ep0, 0); in usb_linux_free_device()
1198 free(dev->linux_endpoint_start, M_USBDEV); in usb_linux_free_device()
1201 /*------------------------------------------------------------------------*
1203 *------------------------------------------------------------------------*/
1211 /*------------------------------------------------------------------------*
1213 *------------------------------------------------------------------------*/
1224 cv_destroy(&urb->cv_wait); in usb_free_urb()
1230 /*------------------------------------------------------------------------*
1233 * The following function can be used to initialize a custom URB. It
1234 * is not recommended to use this function. Use "usb_alloc_urb()"
1236 *------------------------------------------------------------------------*/
1246 /*------------------------------------------------------------------------*
1248 *------------------------------------------------------------------------*/
1255 /*------------------------------------------------------------------------*
1258 * The following function sets the per Linux USB interface private
1260 *------------------------------------------------------------------------*/
1264 intf->bsd_priv_sc = data; in usb_set_intfdata()
1267 /*------------------------------------------------------------------------*
1270 * The following function will release all FreeBSD USB transfers
1272 *------------------------------------------------------------------------*/
1281 uhi = iface->altsetting; in usb_linux_cleanup_interface()
1282 uhi_end = iface->altsetting + iface->num_altsetting; in usb_linux_cleanup_interface()
1284 uhe = uhi->endpoint; in usb_linux_cleanup_interface()
1285 uhe_end = uhi->endpoint + uhi->desc.bNumEndpoints; in usb_linux_cleanup_interface()
1294 /*------------------------------------------------------------------------*
1297 * The following function is used by "usb_start_wait_urb()" to wake it
1298 * up, when an USB transfer has finished.
1299 *------------------------------------------------------------------------*/
1303 if (urb->transfer_flags & URB_IS_SLEEPING) { in usb_linux_wait_complete()
1304 cv_signal(&urb->cv_wait); in usb_linux_wait_complete()
1306 urb->transfer_flags &= ~URB_WAIT_WAKEUP; in usb_linux_wait_complete()
1309 /*------------------------------------------------------------------------*
1311 *------------------------------------------------------------------------*/
1319 if (urb->complete) { in usb_linux_complete()
1320 (urb->complete) (urb); in usb_linux_complete()
1324 /*------------------------------------------------------------------------*
1329 * depending on whether a full- or high- speed USB transfer is
1331 *------------------------------------------------------------------------*/
1335 usb_frlength_t max_frame = xfer->max_frame_size; in usb_linux_isoc_callback()
1347 if (urb->bsd_isread) { in usb_linux_isoc_callback()
1352 for (x = 0; x < urb->number_of_packets; x++) { in usb_linux_isoc_callback()
1353 uipd = urb->iso_frame_desc + x; in usb_linux_isoc_callback()
1354 if (uipd->length > xfer->frlengths[x]) { in usb_linux_isoc_callback()
1355 if (urb->transfer_flags & URB_SHORT_NOT_OK) { in usb_linux_isoc_callback()
1357 uipd->status = -EPIPE; in usb_linux_isoc_callback()
1359 uipd->status = 0; in usb_linux_isoc_callback()
1362 uipd->status = 0; in usb_linux_isoc_callback()
1364 uipd->actual_length = xfer->frlengths[x]; in usb_linux_isoc_callback()
1365 if (!xfer->flags.ext_buffer) { in usb_linux_isoc_callback()
1366 usbd_copy_out(xfer->frbuffers, offset, in usb_linux_isoc_callback()
1367 USB_ADD_BYTES(urb->transfer_buffer, in usb_linux_isoc_callback()
1368 uipd->offset), uipd->actual_length); in usb_linux_isoc_callback()
1373 for (x = 0; x < urb->number_of_packets; x++) { in usb_linux_isoc_callback()
1374 uipd = urb->iso_frame_desc + x; in usb_linux_isoc_callback()
1375 uipd->actual_length = xfer->frlengths[x]; in usb_linux_isoc_callback()
1376 uipd->status = 0; in usb_linux_isoc_callback()
1380 urb->actual_length = xfer->actlen; in usb_linux_isoc_callback()
1382 /* check for short transfer */ in usb_linux_isoc_callback()
1383 if (xfer->actlen < xfer->sumlen) { in usb_linux_isoc_callback()
1384 /* short transfer */ in usb_linux_isoc_callback()
1385 if (urb->transfer_flags & URB_SHORT_NOT_OK) { in usb_linux_isoc_callback()
1387 urb->status = -EPIPE; in usb_linux_isoc_callback()
1389 urb->status = 0; in usb_linux_isoc_callback()
1393 urb->status = 0; in usb_linux_isoc_callback()
1402 if (xfer->priv_fifo == NULL) { in usb_linux_isoc_callback()
1403 /* get next transfer */ in usb_linux_isoc_callback()
1404 urb = TAILQ_FIRST(&uhe->bsd_urb_list); in usb_linux_isoc_callback()
1409 TAILQ_REMOVE(&uhe->bsd_urb_list, urb, bsd_urb_list); in usb_linux_isoc_callback()
1410 urb->bsd_urb_list.tqe_prev = NULL; in usb_linux_isoc_callback()
1412 x = xfer->max_frame_count; in usb_linux_isoc_callback()
1413 if (urb->number_of_packets > x) { in usb_linux_isoc_callback()
1414 /* XXX simply truncate the transfer */ in usb_linux_isoc_callback()
1415 urb->number_of_packets = x; in usb_linux_isoc_callback()
1418 DPRINTF("Already got a transfer\n"); in usb_linux_isoc_callback()
1420 /* already got a transfer (should not happen) */ in usb_linux_isoc_callback()
1424 urb->bsd_isread = (uhe->desc.bEndpointAddress & UE_DIR_IN) ? 1 : 0; in usb_linux_isoc_callback()
1426 if (xfer->flags.ext_buffer) { in usb_linux_isoc_callback()
1428 usbd_xfer_set_frame_data(xfer, 0, urb->transfer_buffer, 0); in usb_linux_isoc_callback()
1430 if (!(urb->bsd_isread)) { in usb_linux_isoc_callback()
1435 for (x = 0; x < urb->number_of_packets; x++) { in usb_linux_isoc_callback()
1436 uipd = urb->iso_frame_desc + x; in usb_linux_isoc_callback()
1437 usbd_xfer_set_frame_len(xfer, x, uipd->length); in usb_linux_isoc_callback()
1438 if (!xfer->flags.ext_buffer) { in usb_linux_isoc_callback()
1439 usbd_copy_in(xfer->frbuffers, offset, in usb_linux_isoc_callback()
1440 USB_ADD_BYTES(urb->transfer_buffer, in usb_linux_isoc_callback()
1441 uipd->offset), uipd->length); in usb_linux_isoc_callback()
1443 offset += uipd->length; in usb_linux_isoc_callback()
1447 * compute the transfer length into the "offset" in usb_linux_isoc_callback()
1451 offset = urb->number_of_packets * max_frame; in usb_linux_isoc_callback()
1455 for (x = 0; x < urb->number_of_packets; x++) { in usb_linux_isoc_callback()
1456 uipd = urb->iso_frame_desc + x; in usb_linux_isoc_callback()
1461 xfer->flags.force_short_xfer = 0; in usb_linux_isoc_callback()
1462 xfer->timeout = urb->timeout; in usb_linux_isoc_callback()
1463 xfer->nframes = urb->number_of_packets; in usb_linux_isoc_callback()
1468 if (xfer->error == USB_ERR_CANCELLED) { in usb_linux_isoc_callback()
1469 urb->status = -ECONNRESET; in usb_linux_isoc_callback()
1471 urb->status = -EPIPE; /* stalled */ in usb_linux_isoc_callback()
1475 urb->actual_length = 0; in usb_linux_isoc_callback()
1478 for (x = 0; x < urb->number_of_packets; x++) { in usb_linux_isoc_callback()
1479 urb->iso_frame_desc[x].actual_length = 0; in usb_linux_isoc_callback()
1480 urb->iso_frame_desc[x].status = urb->status; in usb_linux_isoc_callback()
1486 if (xfer->error == USB_ERR_CANCELLED) { in usb_linux_isoc_callback()
1494 /*------------------------------------------------------------------------*
1499 * the URB fields into a FreeBSD USB transfer, and defragments the USB
1500 * transfer as required. When the transfer is complete the "complete"
1502 *------------------------------------------------------------------------*/
1513 uint8_t data_frame = xfer->flags_int.control_xfr ? 1 : 0; in usb_linux_non_isoc_callback()
1520 if (xfer->flags_int.control_xfr) { in usb_linux_non_isoc_callback()
1521 /* don't transfer the setup packet again: */ in usb_linux_non_isoc_callback()
1525 if (urb->bsd_isread && (!xfer->flags.ext_buffer)) { in usb_linux_non_isoc_callback()
1527 usbd_copy_out(xfer->frbuffers + data_frame, 0, in usb_linux_non_isoc_callback()
1528 urb->bsd_data_ptr, xfer->frlengths[data_frame]); in usb_linux_non_isoc_callback()
1530 urb->bsd_length_rem -= xfer->frlengths[data_frame]; in usb_linux_non_isoc_callback()
1531 urb->bsd_data_ptr += xfer->frlengths[data_frame]; in usb_linux_non_isoc_callback()
1532 urb->actual_length += xfer->frlengths[data_frame]; in usb_linux_non_isoc_callback()
1534 /* check for short transfer */ in usb_linux_non_isoc_callback()
1535 if (xfer->actlen < xfer->sumlen) { in usb_linux_non_isoc_callback()
1536 urb->bsd_length_rem = 0; in usb_linux_non_isoc_callback()
1538 /* short transfer */ in usb_linux_non_isoc_callback()
1539 if (urb->transfer_flags & URB_SHORT_NOT_OK) { in usb_linux_non_isoc_callback()
1540 urb->status = -EPIPE; in usb_linux_non_isoc_callback()
1542 urb->status = 0; in usb_linux_non_isoc_callback()
1546 if (urb->bsd_length_rem > 0) { in usb_linux_non_isoc_callback()
1550 urb->status = 0; in usb_linux_non_isoc_callback()
1558 /* get next transfer */ in usb_linux_non_isoc_callback()
1559 urb = TAILQ_FIRST(&uhe->bsd_urb_list); in usb_linux_non_isoc_callback()
1564 TAILQ_REMOVE(&uhe->bsd_urb_list, urb, bsd_urb_list); in usb_linux_non_isoc_callback()
1565 urb->bsd_urb_list.tqe_prev = NULL; in usb_linux_non_isoc_callback()
1568 xfer->flags.force_short_xfer = 0; in usb_linux_non_isoc_callback()
1569 xfer->timeout = urb->timeout; in usb_linux_non_isoc_callback()
1571 if (xfer->flags_int.control_xfr) { in usb_linux_non_isoc_callback()
1576 if (!xfer->flags.ext_buffer) { in usb_linux_non_isoc_callback()
1577 usbd_copy_in(xfer->frbuffers, 0, in usb_linux_non_isoc_callback()
1578 urb->setup_packet, REQ_SIZE); in usb_linux_non_isoc_callback()
1583 urb->setup_packet, REQ_SIZE); in usb_linux_non_isoc_callback()
1586 ptr = urb->setup_packet; in usb_linux_non_isoc_callback()
1588 /* setup data transfer direction and length */ in usb_linux_non_isoc_callback()
1589 urb->bsd_isread = (ptr[0] & UT_READ) ? 1 : 0; in usb_linux_non_isoc_callback()
1590 urb->bsd_length_rem = ptr[6] | (ptr[7] << 8); in usb_linux_non_isoc_callback()
1593 /* setup data transfer direction */ in usb_linux_non_isoc_callback()
1595 urb->bsd_length_rem = urb->transfer_buffer_length; in usb_linux_non_isoc_callback()
1596 urb->bsd_isread = (uhe->desc.bEndpointAddress & in usb_linux_non_isoc_callback()
1600 urb->bsd_data_ptr = urb->transfer_buffer; in usb_linux_non_isoc_callback()
1601 urb->actual_length = 0; in usb_linux_non_isoc_callback()
1604 if (max_bulk > urb->bsd_length_rem) { in usb_linux_non_isoc_callback()
1605 max_bulk = urb->bsd_length_rem; in usb_linux_non_isoc_callback()
1607 /* check if we need to force a short transfer */ in usb_linux_non_isoc_callback()
1609 if ((max_bulk == urb->bsd_length_rem) && in usb_linux_non_isoc_callback()
1610 (urb->transfer_flags & URB_ZERO_PACKET) && in usb_linux_non_isoc_callback()
1611 (!xfer->flags_int.control_xfr)) { in usb_linux_non_isoc_callback()
1612 xfer->flags.force_short_xfer = 1; in usb_linux_non_isoc_callback()
1616 if (xfer->flags.ext_buffer) { in usb_linux_non_isoc_callback()
1619 urb->bsd_data_ptr, max_bulk); in usb_linux_non_isoc_callback()
1620 } else if (!urb->bsd_isread) { in usb_linux_non_isoc_callback()
1622 usbd_copy_in(xfer->frbuffers + data_frame, 0, in usb_linux_non_isoc_callback()
1623 urb->bsd_data_ptr, max_bulk); in usb_linux_non_isoc_callback()
1626 if (xfer->flags_int.control_xfr) { in usb_linux_non_isoc_callback()
1628 xfer->nframes = 2; in usb_linux_non_isoc_callback()
1630 xfer->nframes = 1; in usb_linux_non_isoc_callback()
1633 xfer->nframes = 1; in usb_linux_non_isoc_callback()
1639 if (xfer->error == USB_ERR_CANCELLED) { in usb_linux_non_isoc_callback()
1640 urb->status = -ECONNRESET; in usb_linux_non_isoc_callback()
1642 urb->status = -EPIPE; in usb_linux_non_isoc_callback()
1646 urb->actual_length = 0; in usb_linux_non_isoc_callback()
1651 if (xfer->error == USB_ERR_CANCELLED) { in usb_linux_non_isoc_callback()
1659 /*------------------------------------------------------------------------*
1661 *------------------------------------------------------------------------*/
1667 urb->dev = udev; in usb_fill_bulk_urb()
1668 urb->endpoint = uhe; in usb_fill_bulk_urb()
1669 urb->transfer_buffer = buf; in usb_fill_bulk_urb()
1670 urb->transfer_buffer_length = length; in usb_fill_bulk_urb()
1671 urb->complete = callback; in usb_fill_bulk_urb()
1672 urb->context = arg; in usb_fill_bulk_urb()
1675 /*------------------------------------------------------------------------*
1678 * NOTE: This function can also be used for interrupt endpoints!
1683 *------------------------------------------------------------------------*/
1692 return (-EINVAL); in usb_bulk_msg()
1694 return (-EINVAL); in usb_bulk_msg()
1716 /* register our function */ in usb_linux_init()