linux_usb.c (190174) | linux_usb.c (190181) |
---|---|
1/* $FreeBSD: head/sys/dev/usb/usb_compat_linux.c 190174 2009-03-20 19:04:31Z thompsa $ */ | 1/* $FreeBSD: head/sys/dev/usb/usb_compat_linux.c 190181 2009-03-20 21:50:54Z thompsa $ */ |
2/*- 3 * Copyright (c) 2007 Luigi Rizzo - Universita` di Pisa. All rights reserved. 4 * Copyright (c) 2007 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright --- 52 unchanged lines hidden (view full) --- 62static device_shutdown_t usb_linux_shutdown; 63 64static usb2_callback_t usb_linux_isoc_callback; 65static usb2_callback_t usb_linux_non_isoc_callback; 66 67static usb_complete_t usb_linux_wait_complete; 68 69static uint16_t usb_max_isoc_frames(struct usb_device *); | 2/*- 3 * Copyright (c) 2007 Luigi Rizzo - Universita` di Pisa. All rights reserved. 4 * Copyright (c) 2007 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright --- 52 unchanged lines hidden (view full) --- 62static device_shutdown_t usb_linux_shutdown; 63 64static usb2_callback_t usb_linux_isoc_callback; 65static usb2_callback_t usb_linux_non_isoc_callback; 66 67static usb_complete_t usb_linux_wait_complete; 68 69static uint16_t usb_max_isoc_frames(struct usb_device *); |
70static int usb_start_wait_urb(struct urb *, uint32_t, uint16_t *); | 70static int usb_start_wait_urb(struct urb *, usb2_timeout_t, uint16_t *); |
71static const struct usb_device_id *usb_linux_lookup_id( 72 const struct usb_device_id *, struct usb2_attach_arg *); 73static struct usb_driver *usb_linux_get_usb_driver(struct usb_linux_softc *); 74static struct usb_device *usb_linux_create_usb_device(struct usb2_device *, 75 device_t); 76static void usb_linux_cleanup_interface(struct usb_device *, 77 struct usb_interface *); 78static void usb_linux_complete(struct usb2_xfer *); --- 480 unchanged lines hidden (view full) --- 559 560/*------------------------------------------------------------------------* 561 * usb_start_wait_urb 562 * 563 * This is an internal function that is used to perform synchronous 564 * Linux USB transfers. 565 *------------------------------------------------------------------------*/ 566static int | 71static const struct usb_device_id *usb_linux_lookup_id( 72 const struct usb_device_id *, struct usb2_attach_arg *); 73static struct usb_driver *usb_linux_get_usb_driver(struct usb_linux_softc *); 74static struct usb_device *usb_linux_create_usb_device(struct usb2_device *, 75 device_t); 76static void usb_linux_cleanup_interface(struct usb_device *, 77 struct usb_interface *); 78static void usb_linux_complete(struct usb2_xfer *); --- 480 unchanged lines hidden (view full) --- 559 560/*------------------------------------------------------------------------* 561 * usb_start_wait_urb 562 * 563 * This is an internal function that is used to perform synchronous 564 * Linux USB transfers. 565 *------------------------------------------------------------------------*/ 566static int |
567usb_start_wait_urb(struct urb *urb, uint32_t timeout, uint16_t *p_actlen) | 567usb_start_wait_urb(struct urb *urb, usb2_timeout_t timeout, uint16_t *p_actlen) |
568{ 569 int err; 570 571 /* you must have a timeout! */ 572 if (timeout == 0) { 573 timeout = 1; 574 } 575 urb->complete = &usb_linux_wait_complete; --- 39 unchanged lines hidden (view full) --- 615 * 0: Success 616 * < 0: Failure 617 * > 0: Acutal length 618 *------------------------------------------------------------------------*/ 619int 620usb_control_msg(struct usb_device *dev, struct usb_host_endpoint *uhe, 621 uint8_t request, uint8_t requesttype, 622 uint16_t value, uint16_t index, void *data, | 568{ 569 int err; 570 571 /* you must have a timeout! */ 572 if (timeout == 0) { 573 timeout = 1; 574 } 575 urb->complete = &usb_linux_wait_complete; --- 39 unchanged lines hidden (view full) --- 615 * 0: Success 616 * < 0: Failure 617 * > 0: Acutal length 618 *------------------------------------------------------------------------*/ 619int 620usb_control_msg(struct usb_device *dev, struct usb_host_endpoint *uhe, 621 uint8_t request, uint8_t requesttype, 622 uint16_t value, uint16_t index, void *data, |
623 uint16_t size, uint32_t timeout) | 623 uint16_t size, usb2_timeout_t timeout) |
624{ 625 struct usb2_device_request req; 626 struct urb *urb; 627 int err; 628 uint16_t actlen; 629 uint8_t type; 630 uint8_t addr; 631 --- 104 unchanged lines hidden (view full) --- 736 * The maximum buffer size is per URB. If you don't call this function 737 * to set a maximum buffer size, the endpoint will not be functional. 738 * Note that for isochronous endpoints the maximum buffer size must be 739 * a non-zero dummy, hence this function will base the maximum buffer 740 * size on "wMaxPacketSize". 741 *------------------------------------------------------------------------*/ 742int 743usb_setup_endpoint(struct usb_device *dev, | 624{ 625 struct usb2_device_request req; 626 struct urb *urb; 627 int err; 628 uint16_t actlen; 629 uint8_t type; 630 uint8_t addr; 631 --- 104 unchanged lines hidden (view full) --- 736 * The maximum buffer size is per URB. If you don't call this function 737 * to set a maximum buffer size, the endpoint will not be functional. 738 * Note that for isochronous endpoints the maximum buffer size must be 739 * a non-zero dummy, hence this function will base the maximum buffer 740 * size on "wMaxPacketSize". 741 *------------------------------------------------------------------------*/ 742int 743usb_setup_endpoint(struct usb_device *dev, |
744 struct usb_host_endpoint *uhe, uint32_t bufsize) | 744 struct usb_host_endpoint *uhe, usb2_size_t bufsize) |
745{ 746 struct usb2_config cfg[2]; 747 uint8_t type = uhe->desc.bmAttributes & UE_XFERTYPE; 748 uint8_t addr = uhe->desc.bEndpointAddress; 749 750 if (uhe->fbsd_buf_size == bufsize) { 751 /* optimize */ 752 return (0); --- 78 unchanged lines hidden (view full) --- 831 struct usb2_config_descriptor *cd = usb2_get_config_descriptor(udev); 832 struct usb2_descriptor *desc; 833 struct usb2_interface_descriptor *id; 834 struct usb2_endpoint_descriptor *ed; 835 struct usb_device *p_ud = NULL; 836 struct usb_interface *p_ui = NULL; 837 struct usb_host_interface *p_uhi = NULL; 838 struct usb_host_endpoint *p_uhe = NULL; | 745{ 746 struct usb2_config cfg[2]; 747 uint8_t type = uhe->desc.bmAttributes & UE_XFERTYPE; 748 uint8_t addr = uhe->desc.bEndpointAddress; 749 750 if (uhe->fbsd_buf_size == bufsize) { 751 /* optimize */ 752 return (0); --- 78 unchanged lines hidden (view full) --- 831 struct usb2_config_descriptor *cd = usb2_get_config_descriptor(udev); 832 struct usb2_descriptor *desc; 833 struct usb2_interface_descriptor *id; 834 struct usb2_endpoint_descriptor *ed; 835 struct usb_device *p_ud = NULL; 836 struct usb_interface *p_ui = NULL; 837 struct usb_host_interface *p_uhi = NULL; 838 struct usb_host_endpoint *p_uhe = NULL; |
839 uint32_t size; | 839 usb2_size_t size; |
840 uint16_t niface_total; 841 uint16_t nedesc; 842 uint16_t iface_no_curr; 843 uint16_t iface_index; 844 uint8_t pass; 845 uint8_t iface_no; 846 847 /* --- 118 unchanged lines hidden (view full) --- 966 * you must specifiy the maximum number of "iso_packets" which you 967 * plan to transfer per URB. This function is always blocking, and 968 * "mem_flags" are not regarded like on Linux. 969 *------------------------------------------------------------------------*/ 970struct urb * 971usb_alloc_urb(uint16_t iso_packets, uint16_t mem_flags) 972{ 973 struct urb *urb; | 840 uint16_t niface_total; 841 uint16_t nedesc; 842 uint16_t iface_no_curr; 843 uint16_t iface_index; 844 uint8_t pass; 845 uint8_t iface_no; 846 847 /* --- 118 unchanged lines hidden (view full) --- 966 * you must specifiy the maximum number of "iso_packets" which you 967 * plan to transfer per URB. This function is always blocking, and 968 * "mem_flags" are not regarded like on Linux. 969 *------------------------------------------------------------------------*/ 970struct urb * 971usb_alloc_urb(uint16_t iso_packets, uint16_t mem_flags) 972{ 973 struct urb *urb; |
974 uint32_t size; | 974 usb2_size_t size; |
975 976 if (iso_packets == 0xFFFF) { 977 /* 978 * FreeBSD specific magic value to ask for control transfer 979 * memory allocation: 980 */ 981 size = sizeof(*urb) + sizeof(struct usb2_device_request) + mem_flags; 982 } else { --- 114 unchanged lines hidden (view full) --- 1097 } 1098 return (NULL); 1099} 1100 1101/*------------------------------------------------------------------------* 1102 * usb_buffer_alloc 1103 *------------------------------------------------------------------------*/ 1104void * | 975 976 if (iso_packets == 0xFFFF) { 977 /* 978 * FreeBSD specific magic value to ask for control transfer 979 * memory allocation: 980 */ 981 size = sizeof(*urb) + sizeof(struct usb2_device_request) + mem_flags; 982 } else { --- 114 unchanged lines hidden (view full) --- 1097 } 1098 return (NULL); 1099} 1100 1101/*------------------------------------------------------------------------* 1102 * usb_buffer_alloc 1103 *------------------------------------------------------------------------*/ 1104void * |
1105usb_buffer_alloc(struct usb_device *dev, uint32_t size, uint16_t mem_flags, uint8_t *dma_addr) | 1105usb_buffer_alloc(struct usb_device *dev, usb2_size_t size, uint16_t mem_flags, uint8_t *dma_addr) |
1106{ 1107 return (malloc(size, M_USBDEV, M_WAITOK | M_ZERO)); 1108} 1109 1110/*------------------------------------------------------------------------* 1111 * usb_get_intfdata 1112 *------------------------------------------------------------------------*/ 1113void * --- 74 unchanged lines hidden (view full) --- 1188 err = usb_setup_endpoint(dev, &dev->ep0, 0); 1189 free(dev, M_USBDEV); 1190} 1191 1192/*------------------------------------------------------------------------* 1193 * usb_buffer_free 1194 *------------------------------------------------------------------------*/ 1195void | 1106{ 1107 return (malloc(size, M_USBDEV, M_WAITOK | M_ZERO)); 1108} 1109 1110/*------------------------------------------------------------------------* 1111 * usb_get_intfdata 1112 *------------------------------------------------------------------------*/ 1113void * --- 74 unchanged lines hidden (view full) --- 1188 err = usb_setup_endpoint(dev, &dev->ep0, 0); 1189 free(dev, M_USBDEV); 1190} 1191 1192/*------------------------------------------------------------------------* 1193 * usb_buffer_free 1194 *------------------------------------------------------------------------*/ 1195void |
1196usb_buffer_free(struct usb_device *dev, uint32_t size, | 1196usb_buffer_free(struct usb_device *dev, usb2_size_t size, |
1197 void *addr, uint8_t dma_addr) 1198{ 1199 free(addr, M_USBDEV); 1200} 1201 1202/*------------------------------------------------------------------------* 1203 * usb_free_urb 1204 *------------------------------------------------------------------------*/ --- 116 unchanged lines hidden (view full) --- 1321 * The following is the FreeBSD isochronous USB callback. Isochronous 1322 * frames are USB packets transferred 1000 or 8000 times per second, 1323 * depending on whether a full- or high- speed USB transfer is 1324 * used. 1325 *------------------------------------------------------------------------*/ 1326static void 1327usb_linux_isoc_callback(struct usb2_xfer *xfer) 1328{ | 1197 void *addr, uint8_t dma_addr) 1198{ 1199 free(addr, M_USBDEV); 1200} 1201 1202/*------------------------------------------------------------------------* 1203 * usb_free_urb 1204 *------------------------------------------------------------------------*/ --- 116 unchanged lines hidden (view full) --- 1321 * The following is the FreeBSD isochronous USB callback. Isochronous 1322 * frames are USB packets transferred 1000 or 8000 times per second, 1323 * depending on whether a full- or high- speed USB transfer is 1324 * used. 1325 *------------------------------------------------------------------------*/ 1326static void 1327usb_linux_isoc_callback(struct usb2_xfer *xfer) 1328{ |
1329 uint32_t max_frame = xfer->max_frame_size; 1330 uint32_t offset; 1331 uint16_t x; | 1329 usb2_frlength_t max_frame = xfer->max_frame_size; 1330 usb2_frlength_t offset; 1331 usb2_frcount_t x; |
1332 struct urb *urb = xfer->priv_fifo; 1333 struct usb_host_endpoint *uhe = xfer->priv_sc; 1334 struct usb_iso_packet_descriptor *uipd; 1335 1336 DPRINTF("\n"); 1337 1338 switch (USB_GET_STATE(xfer)) { 1339 case USB_ST_TRANSFERRED: --- 155 unchanged lines hidden (view full) --- 1495usb_linux_non_isoc_callback(struct usb2_xfer *xfer) 1496{ 1497 enum { 1498 REQ_SIZE = sizeof(struct usb2_device_request) 1499 }; 1500 struct urb *urb = xfer->priv_fifo; 1501 struct usb_host_endpoint *uhe = xfer->priv_sc; 1502 uint8_t *ptr; | 1332 struct urb *urb = xfer->priv_fifo; 1333 struct usb_host_endpoint *uhe = xfer->priv_sc; 1334 struct usb_iso_packet_descriptor *uipd; 1335 1336 DPRINTF("\n"); 1337 1338 switch (USB_GET_STATE(xfer)) { 1339 case USB_ST_TRANSFERRED: --- 155 unchanged lines hidden (view full) --- 1495usb_linux_non_isoc_callback(struct usb2_xfer *xfer) 1496{ 1497 enum { 1498 REQ_SIZE = sizeof(struct usb2_device_request) 1499 }; 1500 struct urb *urb = xfer->priv_fifo; 1501 struct usb_host_endpoint *uhe = xfer->priv_sc; 1502 uint8_t *ptr; |
1503 uint32_t max_bulk = xfer->max_data_length; | 1503 usb2_frlength_t max_bulk = xfer->max_data_length; |
1504 uint8_t data_frame = xfer->flags_int.control_xfr ? 1 : 0; 1505 1506 DPRINTF("\n"); 1507 1508 switch (USB_GET_STATE(xfer)) { 1509 case USB_ST_TRANSFERRED: 1510 1511 if (xfer->flags_int.control_xfr) { --- 141 unchanged lines hidden --- | 1504 uint8_t data_frame = xfer->flags_int.control_xfr ? 1 : 0; 1505 1506 DPRINTF("\n"); 1507 1508 switch (USB_GET_STATE(xfer)) { 1509 case USB_ST_TRANSFERRED: 1510 1511 if (xfer->flags_int.control_xfr) { --- 141 unchanged lines hidden --- |