5 #include <linux/usb/ch9.h>
8 #define USB_DEVICE_MAJOR 189
13 #include <linux/errno.h>
16 #include <linux/list.h>
18 #include <linux/device.h>
21 #include <linux/sched.h>
64 struct usb_host_endpoint {
77 struct usb_host_interface {
91 enum usb_interface_condition {
92 USB_INTERFACE_UNBOUND = 0,
93 USB_INTERFACE_BINDING,
95 USB_INTERFACE_UNBINDING,
163 struct usb_host_interface *altsetting;
165 struct usb_host_interface *cur_altsetting;
167 unsigned num_altsetting;
175 enum usb_interface_condition condition;
176 unsigned sysfs_files_created:1;
177 unsigned ep_devs_created:1;
178 unsigned unregistering:1;
179 unsigned needs_remote_wakeup:1;
180 unsigned needs_altsetting0:1;
181 unsigned needs_binding:1;
182 unsigned reset_running:1;
183 unsigned resetting_device:1;
190 #define to_usb_interface(d) container_of(d, struct usb_interface, dev)
206 #define USB_MAXINTERFACES 32
207 #define USB_MAXIADS (USB_MAXINTERFACES/2)
223 struct usb_interface_cache {
224 unsigned num_altsetting;
229 struct usb_host_interface altsetting[0];
231 #define ref_to_usb_interface_cache(r) \
232 container_of(r, struct usb_interface_cache, ref)
233 #define altsetting_to_usb_interface_cache(a) \
234 container_of(a, struct usb_interface_cache, altsetting[0])
275 struct usb_host_config {
290 struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];
292 unsigned char *
extra;
297 struct usb_host_bos {
307 unsigned char type,
void **
ptr);
308 #define usb_get_extra_descriptor(ifpoint, type, ptr) \
309 __usb_get_extra_descriptor((ifpoint)->extra, \
310 (ifpoint)->extralen, \
317 unsigned long devicemap[128 / (8*
sizeof(
unsigned long))];
326 const char *bus_name;
328 u8 uses_pio_for_control;
333 unsigned is_b_host:1;
334 unsigned b_hnp_enable:1;
335 unsigned no_stop_on_short:1;
340 unsigned sg_tablesize;
345 struct usb_devmap devmap;
346 struct usb_device *root_hub;
347 struct usb_bus *hs_companion;
350 int bandwidth_allocated;
357 int bandwidth_int_reqs;
358 int bandwidth_isoc_reqs;
360 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
377 #define USB_MAXCHILDREN (31)
381 enum usb_device_removable {
382 USB_DEVICE_REMOVABLE_UNKNOWN = 0,
383 USB_DEVICE_REMOVABLE,
387 enum usb_port_connect_type {
388 USB_PORT_CONNECT_TYPE_UNKNOWN = 0,
389 USB_PORT_CONNECT_TYPE_HOT_PLUG,
390 USB_PORT_CONNECT_TYPE_HARD_WIRED,
401 struct usb3_lpm_parameters {
512 struct usb_device *
parent;
514 struct usb_host_endpoint ep0;
519 struct usb_host_bos *
bos;
520 struct usb_host_config *
config;
522 struct usb_host_config *actconfig;
523 struct usb_host_endpoint *ep_in[16];
524 struct usb_host_endpoint *ep_out[16];
526 char **rawdescriptors;
528 unsigned short bus_mA;
532 unsigned can_submit:1;
533 unsigned persist_enabled:1;
534 unsigned have_langid:1;
535 unsigned authorized:1;
536 unsigned authenticated:1;
538 unsigned lpm_capable:1;
539 unsigned usb2_hw_lpm_capable:1;
540 unsigned usb2_hw_lpm_enabled:1;
541 unsigned usb3_lpm_enabled:1;
556 unsigned long active_duration;
559 unsigned long connect_time;
561 unsigned do_remote_wakeup:1;
562 unsigned reset_resume:1;
567 struct usb3_lpm_parameters u1_params;
568 struct usb3_lpm_parameters u2_params;
569 unsigned lpm_disable_count;
571 #define to_usb_device(d) container_of(d, struct usb_device, dev)
575 return to_usb_device(intf->dev.parent);
589 #define usb_hub_for_each_child(hdev, port1, child) \
590 for (port1 = 1, child = usb_hub_find_child(hdev, port1); \
591 port1 <= hdev->maxchild; \
592 child = usb_hub_find_child(hdev, ++port1))
595 #define usb_lock_device(udev) device_lock(&(udev)->dev)
596 #define usb_unlock_device(udev) device_unlock(&(udev)->dev)
597 #define usb_trylock_device(udev) device_trylock(&(udev)->dev)
611 bool enable) {
return 0; }
617 #ifdef CONFIG_USB_SUSPEND
618 extern void usb_enable_autosuspend(
struct usb_device *
udev);
619 extern void usb_disable_autosuspend(
struct usb_device *
udev);
628 static inline void usb_mark_last_busy(
struct usb_device *
udev)
630 pm_runtime_mark_last_busy(&udev->dev);
635 static inline int usb_enable_autosuspend(
struct usb_device *
udev)
637 static inline int usb_disable_autosuspend(
struct usb_device *
udev)
649 static inline void usb_autopm_get_interface_no_resume(
652 static inline void usb_autopm_put_interface_no_suspend(
655 static inline void usb_mark_last_busy(
struct usb_device *
udev)
668 static inline bool usb_device_supports_ltm(
struct usb_device *
udev)
670 if (udev->speed !=
USB_SPEED_SUPER || !udev->bos || !udev->bos->ss_cap)
683 struct usb_host_endpoint **eps,
unsigned int num_eps,
684 unsigned int num_streams,
gfp_t mem_flags);
688 struct usb_host_endpoint **eps,
unsigned int num_eps,
705 static inline int usb_interface_claimed(
struct usb_interface *iface)
707 return (iface->dev.driver !=
NULL);
724 struct usb_host_config *
config,
726 unsigned int alt_num);
753 static inline int usb_make_path(
struct usb_device *
dev,
char *
buf,
size_t size)
756 actual =
snprintf(buf, size,
"usb-%s-%s", dev->bus->bus_name,
758 return (actual >= (
int)size) ? -1 : actual;
763 #define USB_DEVICE_ID_MATCH_DEVICE \
764 (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
765 #define USB_DEVICE_ID_MATCH_DEV_RANGE \
766 (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
767 #define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
768 (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
769 #define USB_DEVICE_ID_MATCH_DEV_INFO \
770 (USB_DEVICE_ID_MATCH_DEV_CLASS | \
771 USB_DEVICE_ID_MATCH_DEV_SUBCLASS | \
772 USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
773 #define USB_DEVICE_ID_MATCH_INT_INFO \
774 (USB_DEVICE_ID_MATCH_INT_CLASS | \
775 USB_DEVICE_ID_MATCH_INT_SUBCLASS | \
776 USB_DEVICE_ID_MATCH_INT_PROTOCOL)
786 #define USB_DEVICE(vend, prod) \
787 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
788 .idVendor = (vend), \
800 #define USB_DEVICE_VER(vend, prod, lo, hi) \
801 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \
802 .idVendor = (vend), \
803 .idProduct = (prod), \
804 .bcdDevice_lo = (lo), \
816 #define USB_DEVICE_INTERFACE_PROTOCOL(vend, prod, pr) \
817 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
818 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
819 .idVendor = (vend), \
820 .idProduct = (prod), \
821 .bInterfaceProtocol = (pr)
832 #define USB_DEVICE_INTERFACE_NUMBER(vend, prod, num) \
833 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
834 USB_DEVICE_ID_MATCH_INT_NUMBER, \
835 .idVendor = (vend), \
836 .idProduct = (prod), \
837 .bInterfaceNumber = (num)
848 #define USB_DEVICE_INFO(cl, sc, pr) \
849 .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, \
850 .bDeviceClass = (cl), \
851 .bDeviceSubClass = (sc), \
852 .bDeviceProtocol = (pr)
863 #define USB_INTERFACE_INFO(cl, sc, pr) \
864 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \
865 .bInterfaceClass = (cl), \
866 .bInterfaceSubClass = (sc), \
867 .bInterfaceProtocol = (pr)
883 #define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \
884 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
885 | USB_DEVICE_ID_MATCH_DEVICE, \
886 .idVendor = (vend), \
887 .idProduct = (prod), \
888 .bInterfaceClass = (cl), \
889 .bInterfaceSubClass = (sc), \
890 .bInterfaceProtocol = (pr)
905 #define USB_VENDOR_AND_INTERFACE_INFO(vend, cl, sc, pr) \
906 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
907 | USB_DEVICE_ID_MATCH_VENDOR, \
908 .idVendor = (vend), \
909 .bInterfaceClass = (cl), \
910 .bInterfaceSubClass = (sc), \
911 .bInterfaceProtocol = (pr)
926 extern ssize_t usb_store_new_id(
struct usb_dynids *dynids,
928 const char *buf,
size_t count);
930 extern ssize_t usb_show_dynids(
struct usb_dynids *dynids,
char *buf);
1021 struct usb_dynids dynids;
1022 struct usbdrv_wrap drvwrap;
1023 unsigned int no_dynamic_id:1;
1024 unsigned int supports_autosuspend:1;
1025 unsigned int disable_hub_initiated_lpm:1;
1026 unsigned int soft_unbind:1;
1028 #define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver)
1049 struct usb_device_driver {
1052 int (*probe) (
struct usb_device *
udev);
1057 struct usbdrv_wrap drvwrap;
1058 unsigned int supports_autosuspend:1;
1060 #define to_usb_device_driver(d) container_of(d, struct usb_device_driver, \
1077 struct usb_class_driver {
1092 #define usb_register(driver) \
1093 usb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
1105 #define module_usb_driver(__usb_driver) \
1106 module_driver(__usb_driver, usb_register, \
1114 struct usb_class_driver *class_driver);
1116 struct usb_class_driver *class_driver);
1131 #define URB_SHORT_NOT_OK 0x0001
1132 #define URB_ISO_ASAP 0x0002
1134 #define URB_NO_TRANSFER_DMA_MAP 0x0004
1135 #define URB_NO_FSBR 0x0020
1136 #define URB_ZERO_PACKET 0x0040
1137 #define URB_NO_INTERRUPT 0x0080
1139 #define URB_FREE_BUFFER 0x0100
1142 #define URB_DIR_IN 0x0200
1143 #define URB_DIR_OUT 0
1144 #define URB_DIR_MASK URB_DIR_IN
1146 #define URB_DMA_MAP_SINGLE 0x00010000
1147 #define URB_DMA_MAP_PAGE 0x00020000
1148 #define URB_DMA_MAP_SG 0x00040000
1149 #define URB_MAP_LOCAL 0x00080000
1150 #define URB_SETUP_MAP_SINGLE 0x00100000
1151 #define URB_SETUP_MAP_LOCAL 0x00200000
1152 #define URB_DMA_SG_COMBINED 0x00400000
1153 #define URB_ALIGNED_TEMP_BUFFER 0x00800000
1155 struct usb_iso_packet_descriptor {
1158 unsigned int actual_length;
1168 unsigned int poisoned:1;
1171 static inline void init_usb_anchor(
struct usb_anchor *
anchor)
1173 INIT_LIST_HEAD(&anchor->urb_list);
1178 typedef void (*usb_complete_t)(
struct urb *);
1368 struct usb_anchor *
anchor;
1369 struct usb_device *
dev;
1370 struct usb_host_endpoint *ep;
1372 unsigned int stream_id;
1374 unsigned int transfer_flags;
1380 u32 transfer_buffer_length;
1382 unsigned char *setup_packet;
1385 int number_of_packets;
1391 struct usb_iso_packet_descriptor iso_frame_desc[0];
1411 static inline void usb_fill_control_urb(
struct urb *
urb,
1412 struct usb_device *dev,
1414 unsigned char *setup_packet,
1417 usb_complete_t complete_fn,
1422 urb->setup_packet = setup_packet;
1425 urb->complete = complete_fn;
1442 static inline void usb_fill_bulk_urb(
struct urb *
urb,
1443 struct usb_device *dev,
1447 usb_complete_t complete_fn,
1454 urb->complete = complete_fn;
1483 static inline void usb_fill_int_urb(
struct urb *
urb,
1484 struct usb_device *dev,
1488 usb_complete_t complete_fn,
1496 urb->complete = complete_fn;
1499 urb->interval = 1 << (interval - 1);
1502 urb->start_frame = -1;
1508 #define usb_put_urb usb_free_urb
1523 unsigned int timeout);
1528 #define usb_unblock_urb usb_unpoison_urb
1537 static inline int usb_urb_dir_in(
struct urb *urb)
1539 return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_IN;
1549 static inline int usb_urb_dir_out(
struct urb *urb)
1551 return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT;
1560 struct urb *usb_buffer_map(
struct urb *urb);
1561 void usb_buffer_dmasync(
struct urb *urb);
1562 void usb_buffer_unmap(
struct urb *urb);
1566 int usb_buffer_map_sg(
const struct usb_device *dev,
int is_in,
1569 void usb_buffer_dmasync_sg(
const struct usb_device *dev,
int is_in,
1572 void usb_buffer_unmap_sg(
const struct usb_device *dev,
int is_in,
1583 void *
data,
int len,
int *actual_length,
int timeout);
1584 extern int usb_bulk_msg(
struct usb_device *usb_dev,
unsigned int pipe,
1585 void *
data,
int len,
int *actual_length,
1590 unsigned char descindex,
void *buf,
int size);
1594 char *buf,
size_t size);
1611 #define USB_CTRL_GET_TIMEOUT 5000
1612 #define USB_CTRL_SET_TIMEOUT 5000
1631 struct usb_sg_request {
1641 struct usb_device *
dev;
1652 struct usb_sg_request *
io,
1653 struct usb_device *dev,
1686 #define PIPE_ISOCHRONOUS 0
1687 #define PIPE_INTERRUPT 1
1688 #define PIPE_CONTROL 2
1691 #define usb_pipein(pipe) ((pipe) & USB_DIR_IN)
1692 #define usb_pipeout(pipe) (!usb_pipein(pipe))
1694 #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
1695 #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
1697 #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
1698 #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
1699 #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
1700 #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
1701 #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
1703 static inline unsigned int __create_pipe(
struct usb_device *dev,
1706 return (dev->devnum << 8) | (endpoint << 15);
1710 #define usb_sndctrlpipe(dev, endpoint) \
1711 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint))
1712 #define usb_rcvctrlpipe(dev, endpoint) \
1713 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1714 #define usb_sndisocpipe(dev, endpoint) \
1715 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint))
1716 #define usb_rcvisocpipe(dev, endpoint) \
1717 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1718 #define usb_sndbulkpipe(dev, endpoint) \
1719 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
1720 #define usb_rcvbulkpipe(dev, endpoint) \
1721 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1722 #define usb_sndintpipe(dev, endpoint) \
1723 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint))
1724 #define usb_rcvintpipe(dev, endpoint) \
1725 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1727 static inline struct usb_host_endpoint *
1728 usb_pipe_endpoint(
struct usb_device *dev,
unsigned int pipe)
1730 struct usb_host_endpoint **eps;
1731 eps = usb_pipein(pipe) ? dev->ep_in : dev->ep_out;
1732 return eps[usb_pipeendpoint(pipe)];
1738 usb_maxpacket(
struct usb_device *udev,
int pipe,
int is_out)
1740 struct usb_host_endpoint *ep;
1741 unsigned epnum = usb_pipeendpoint(pipe);
1745 ep = udev->ep_out[epnum];
1748 ep = udev->ep_in[epnum];
1754 return usb_endpoint_maxp(&ep->desc);
1760 static inline int usb_translate_errors(
int error_code)
1762 switch (error_code) {
1774 #define USB_DEVICE_ADD 0x0001
1775 #define USB_DEVICE_REMOVE 0x0002
1776 #define USB_BUS_ADD 0x0003
1777 #define USB_BUS_REMOVE 0x0004