usb_device.h revision 189172
1/* $FreeBSD: head/sys/dev/usb/usb_device.h 189172 2009-02-28 17:14:03Z thompsa $ */ 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef _USB2_DEVICE_H_ 28#define _USB2_DEVICE_H_ 29 30struct usb2_symlink; 31 32#define USB_DEFAULT_XFER_MAX 2 33 34struct usb2_clear_stall_msg { 35 struct usb2_proc_msg hdr; 36 struct usb2_device *udev; 37}; 38 39/* 40 * The following structure defines an USB pipe which is equal to an 41 * USB endpoint. 42 */ 43struct usb2_pipe { 44 struct usb2_xfer_queue pipe_q; /* queue of USB transfers */ 45 46 struct usb2_xfer *xfer_block; /* blocking USB transfer */ 47 struct usb2_endpoint_descriptor *edesc; 48 struct usb2_pipe_methods *methods; /* set by HC driver */ 49 50 uint16_t isoc_next; 51 uint16_t refcount; 52 53 uint8_t toggle_next:1; /* next data toggle value */ 54 uint8_t is_stalled:1; /* set if pipe is stalled */ 55 uint8_t is_synced:1; /* set if we a synchronised */ 56 uint8_t unused:5; 57 uint8_t iface_index; /* not used by "default pipe" */ 58}; 59 60/* 61 * The following structure defines an USB interface. 62 */ 63struct usb2_interface { 64 struct usb2_interface_descriptor *idesc; 65 device_t subdev; 66 uint8_t alt_index; 67 uint8_t parent_iface_index; 68}; 69 70/* 71 * The following structure defines the USB device flags. 72 */ 73struct usb2_device_flags { 74 uint8_t usb2_mode:1; /* USB mode (see USB_MODE_XXX) */ 75 uint8_t self_powered:1; /* set if USB device is self powered */ 76 uint8_t suspended:1; /* set if USB device is suspended */ 77 uint8_t no_strings:1; /* set if USB device does not support 78 * strings */ 79 uint8_t remote_wakeup:1; /* set if remote wakeup is enabled */ 80 uint8_t uq_bus_powered:1; /* set if BUS powered quirk is present */ 81 uint8_t uq_power_claim:1; /* set if power claim quirk is present */ 82}; 83 84/* 85 * The following structure is used for power-save purposes. The data 86 * in this structure is protected by the USB BUS lock. 87 */ 88struct usb2_power_save { 89 int last_xfer_time; /* copy of "ticks" */ 90 uint32_t type_refs[4]; /* transfer reference count */ 91 uint32_t read_refs; /* data read references */ 92 uint32_t write_refs; /* data write references */ 93 uint8_t suspended; /* set if USB device is suspended */ 94}; 95 96/* 97 * The following structure defines an USB device. There exists one of 98 * these structures for every USB device. 99 */ 100struct usb2_device { 101 struct usb2_clear_stall_msg cs_msg[2]; /* generic clear stall 102 * messages */ 103 struct sx default_sx[2]; 104 struct mtx default_mtx[1]; 105 struct cv default_cv[2]; 106 struct usb2_interface ifaces[USB_IFACE_MAX]; 107 struct usb2_pipe default_pipe; /* Control Endpoint 0 */ 108 struct cdev *default_dev; /* Control Endpoint 0 device node */ 109 struct usb2_pipe pipes[USB_EP_MAX]; 110 struct usb2_power_save pwr_save;/* power save data */ 111 112 struct usb2_bus *bus; /* our USB BUS */ 113 device_t parent_dev; /* parent device */ 114 struct usb2_device *parent_hub; 115 struct usb2_config_descriptor *cdesc; /* full config descr */ 116 struct usb2_hub *hub; /* only if this is a hub */ 117 struct usb_device *linux_dev; 118 struct usb2_xfer *default_xfer[USB_DEFAULT_XFER_MAX]; 119 struct usb2_temp_data *usb2_template_ptr; 120 struct usb2_pipe *pipe_curr; /* current clear stall pipe */ 121 struct usb2_fifo *fifo[USB_FIFO_MAX]; 122 123 char ugen_name[20]; /* name of ugenX.X device */ 124 struct usb2_symlink *ugen_symlink; /* our generic symlink */ 125 126 LIST_HEAD(,usb2_fs_privdata) pd_list; 127 128 uint32_t plugtime; /* copy of "ticks" */ 129 130 uint16_t ep_rd_opened; /* bitmask of endpoints opened */ 131 uint16_t ep_wr_opened; /* from the device nodes. */ 132 uint16_t refcount; 133#define USB_DEV_REF_MAX 0xffff 134 135 uint16_t power; /* mA the device uses */ 136 uint16_t langid; /* language for strings */ 137 138 uint8_t address; /* device addess */ 139 uint8_t device_index; /* device index in "bus->devices" */ 140 uint8_t curr_config_index; /* current configuration index */ 141 uint8_t curr_config_no; /* current configuration number */ 142 uint8_t depth; /* distance from root HUB */ 143 uint8_t speed; /* low/full/high speed */ 144 uint8_t port_index; /* parent HUB port index */ 145 uint8_t port_no; /* parent HUB port number */ 146 uint8_t hs_hub_addr; /* high-speed HUB address */ 147 uint8_t hs_port_no; /* high-speed HUB port number */ 148 uint8_t driver_added_refcount; /* our driver added generation count */ 149 uint8_t power_mode; /* see USB_POWER_XXX */ 150 151 /* the "flags" field is write-protected by "bus->mtx" */ 152 153 struct usb2_device_flags flags; 154 155 struct usb2_endpoint_descriptor default_ep_desc; /* for pipe 0 */ 156 struct usb2_device_descriptor ddesc; /* device descriptor */ 157 158 char serial[64]; /* serial number */ 159 char manufacturer[64]; /* manufacturer string */ 160 char product[64]; /* product string */ 161}; 162 163/* globals */ 164 165extern int usb2_template; 166 167/* function prototypes */ 168 169struct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus, 170 struct usb2_device *parent_hub, uint8_t depth, 171 uint8_t port_index, uint8_t port_no, uint8_t speed, 172 uint8_t usb2_mode); 173struct usb2_pipe *usb2_get_pipe(struct usb2_device *udev, uint8_t iface_index, 174 const struct usb2_config *setup); 175struct usb2_pipe *usb2_get_pipe_by_addr(struct usb2_device *udev, uint8_t ea_val); 176usb2_error_t usb2_interface_count(struct usb2_device *udev, uint8_t *count); 177usb2_error_t usb2_probe_and_attach(struct usb2_device *udev, 178 uint8_t iface_index); 179usb2_error_t usb2_reset_iface_endpoints(struct usb2_device *udev, 180 uint8_t iface_index); 181usb2_error_t usb2_set_config_index(struct usb2_device *udev, uint8_t index); 182usb2_error_t usb2_set_endpoint_stall(struct usb2_device *udev, 183 struct usb2_pipe *pipe, uint8_t do_stall); 184usb2_error_t usb2_suspend_resume(struct usb2_device *udev, 185 uint8_t do_suspend); 186void usb2_detach_device(struct usb2_device *udev, uint8_t iface_index, 187 uint8_t free_subdev); 188void usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len); 189void usb2_free_device(struct usb2_device *udev); 190void *usb2_find_descriptor(struct usb2_device *udev, void *id, 191 uint8_t iface_index, uint8_t type, uint8_t type_mask, 192 uint8_t subtype, uint8_t subtype_mask); 193void usb_linux_free_device(struct usb_device *dev); 194uint8_t usb2_peer_can_wakeup(struct usb2_device *udev); 195struct usb2_pipe *usb2_pipe_foreach(struct usb2_device *udev, struct usb2_pipe *pipe); 196 197#endif /* _USB2_DEVICE_H_ */ 198