usb_device.h revision 188987
1184610Salfred/* $FreeBSD: head/sys/dev/usb/usb_device.h 188987 2009-02-24 03:43:05Z thompsa $ */ 2184610Salfred/*- 3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4184610Salfred * 5184610Salfred * Redistribution and use in source and binary forms, with or without 6184610Salfred * modification, are permitted provided that the following conditions 7184610Salfred * are met: 8184610Salfred * 1. Redistributions of source code must retain the above copyright 9184610Salfred * notice, this list of conditions and the following disclaimer. 10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 11184610Salfred * notice, this list of conditions and the following disclaimer in the 12184610Salfred * documentation and/or other materials provided with the distribution. 13184610Salfred * 14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24184610Salfred * SUCH DAMAGE. 25184610Salfred */ 26184610Salfred 27184610Salfred#ifndef _USB2_DEVICE_H_ 28184610Salfred#define _USB2_DEVICE_H_ 29184610Salfred 30184610Salfredstruct usb2_symlink; 31184610Salfred 32184610Salfred#define USB_DEFAULT_XFER_MAX 2 33184610Salfred 34184610Salfredstruct usb2_clear_stall_msg { 35184610Salfred struct usb2_proc_msg hdr; 36184610Salfred struct usb2_device *udev; 37184610Salfred}; 38184610Salfred 39184610Salfred/* 40184610Salfred * The following structure defines an USB pipe which is equal to an 41184610Salfred * USB endpoint. 42184610Salfred */ 43184610Salfredstruct usb2_pipe { 44184610Salfred struct usb2_xfer_queue pipe_q; /* queue of USB transfers */ 45184610Salfred 46184610Salfred struct usb2_xfer *xfer_block; /* blocking USB transfer */ 47184610Salfred struct usb2_endpoint_descriptor *edesc; 48184610Salfred struct usb2_pipe_methods *methods; /* set by HC driver */ 49184610Salfred 50184610Salfred uint16_t isoc_next; 51184610Salfred uint16_t refcount; 52184610Salfred 53184610Salfred uint8_t toggle_next:1; /* next data toggle value */ 54184610Salfred uint8_t is_stalled:1; /* set if pipe is stalled */ 55184610Salfred uint8_t is_synced:1; /* set if we a synchronised */ 56184610Salfred uint8_t unused:5; 57184610Salfred uint8_t iface_index; /* not used by "default pipe" */ 58184610Salfred}; 59184610Salfred 60184610Salfred/* 61184610Salfred * The following structure defines an USB interface. 62184610Salfred */ 63184610Salfredstruct usb2_interface { 64184610Salfred struct usb2_perm perm; /* interface permissions */ 65184610Salfred struct usb2_interface_descriptor *idesc; 66184610Salfred device_t subdev; 67184610Salfred uint8_t alt_index; 68184610Salfred uint8_t parent_iface_index; 69184610Salfred}; 70184610Salfred 71184610Salfred/* 72184610Salfred * The following structure defines the USB device flags. 73184610Salfred */ 74184610Salfredstruct usb2_device_flags { 75184610Salfred uint8_t usb2_mode:1; /* USB mode (see USB_MODE_XXX) */ 76184610Salfred uint8_t self_powered:1; /* set if USB device is self powered */ 77184610Salfred uint8_t suspended:1; /* set if USB device is suspended */ 78184610Salfred uint8_t no_strings:1; /* set if USB device does not support 79184610Salfred * strings */ 80184610Salfred uint8_t remote_wakeup:1; /* set if remote wakeup is enabled */ 81184610Salfred uint8_t uq_bus_powered:1; /* set if BUS powered quirk is present */ 82184610Salfred uint8_t uq_power_claim:1; /* set if power claim quirk is present */ 83184610Salfred}; 84184610Salfred 85184610Salfred/* 86186730Salfred * The following structure is used for power-save purposes. The data 87186730Salfred * in this structure is protected by the USB BUS lock. 88186730Salfred */ 89186730Salfredstruct usb2_power_save { 90186730Salfred int last_xfer_time; /* copy of "ticks" */ 91186730Salfred uint32_t type_refs[4]; /* transfer reference count */ 92186730Salfred uint32_t read_refs; /* data read references */ 93186730Salfred uint32_t write_refs; /* data write references */ 94186730Salfred uint8_t suspended; /* set if USB device is suspended */ 95186730Salfred}; 96186730Salfred 97186730Salfred/* 98184610Salfred * The following structure defines an USB device. There exists one of 99184610Salfred * these structures for every USB device. 100184610Salfred */ 101184610Salfredstruct usb2_device { 102184610Salfred struct usb2_clear_stall_msg cs_msg[2]; /* generic clear stall 103184610Salfred * messages */ 104184610Salfred struct usb2_perm perm; 105184610Salfred struct sx default_sx[2]; 106184610Salfred struct mtx default_mtx[1]; 107184610Salfred struct cv default_cv[2]; 108184610Salfred struct usb2_interface ifaces[USB_IFACE_MAX]; 109184610Salfred struct usb2_pipe default_pipe; /* Control Endpoint 0 */ 110184610Salfred struct usb2_pipe pipes[USB_EP_MAX]; 111186730Salfred struct usb2_power_save pwr_save;/* power save data */ 112184610Salfred 113184610Salfred struct usb2_bus *bus; /* our USB BUS */ 114184610Salfred device_t parent_dev; /* parent device */ 115184610Salfred struct usb2_device *parent_hub; 116184610Salfred struct usb2_config_descriptor *cdesc; /* full config descr */ 117184610Salfred struct usb2_hub *hub; /* only if this is a hub */ 118184610Salfred struct usb_device *linux_dev; 119184610Salfred struct usb2_xfer *default_xfer[USB_DEFAULT_XFER_MAX]; 120184610Salfred struct usb2_temp_data *usb2_template_ptr; 121184610Salfred struct usb2_pipe *pipe_curr; /* current clear stall pipe */ 122184610Salfred struct usb2_fifo *fifo[USB_FIFO_MAX]; 123184610Salfred struct usb2_symlink *ugen_symlink; /* our generic symlink */ 124184610Salfred 125184610Salfred uint32_t plugtime; /* copy of "ticks" */ 126184610Salfred 127184610Salfred uint16_t refcount; 128184610Salfred#define USB_DEV_REF_MAX 0xffff 129184610Salfred 130184610Salfred uint16_t power; /* mA the device uses */ 131184610Salfred uint16_t langid; /* language for strings */ 132184610Salfred 133184610Salfred uint8_t address; /* device addess */ 134184610Salfred uint8_t device_index; /* device index in "bus->devices" */ 135184610Salfred uint8_t curr_config_index; /* current configuration index */ 136184610Salfred uint8_t curr_config_no; /* current configuration number */ 137184610Salfred uint8_t depth; /* distance from root HUB */ 138184610Salfred uint8_t speed; /* low/full/high speed */ 139184610Salfred uint8_t port_index; /* parent HUB port index */ 140184610Salfred uint8_t port_no; /* parent HUB port number */ 141184610Salfred uint8_t hs_hub_addr; /* high-speed HUB address */ 142184610Salfred uint8_t hs_port_no; /* high-speed HUB port number */ 143184610Salfred uint8_t driver_added_refcount; /* our driver added generation count */ 144184610Salfred uint8_t power_mode; /* see USB_POWER_XXX */ 145184610Salfred 146184610Salfred /* the "flags" field is write-protected by "bus->mtx" */ 147184610Salfred 148184610Salfred struct usb2_device_flags flags; 149184610Salfred 150184610Salfred struct usb2_endpoint_descriptor default_ep_desc; /* for pipe 0 */ 151184610Salfred struct usb2_device_descriptor ddesc; /* device descriptor */ 152184610Salfred 153184610Salfred char serial[64]; /* serial number */ 154184610Salfred char manufacturer[64]; /* manufacturer string */ 155184610Salfred char product[64]; /* product string */ 156184610Salfred}; 157184610Salfred 158188987Sthompsa/* globals */ 159188987Sthompsa 160188987Sthompsaextern int usb2_template; 161188987Sthompsa 162184610Salfred/* function prototypes */ 163184610Salfred 164185948Sthompsastruct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus, 165185948Sthompsa struct usb2_device *parent_hub, uint8_t depth, 166185948Sthompsa uint8_t port_index, uint8_t port_no, uint8_t speed, 167185948Sthompsa uint8_t usb2_mode); 168185948Sthompsastruct usb2_pipe *usb2_get_pipe(struct usb2_device *udev, uint8_t iface_index, 169185948Sthompsa const struct usb2_config *setup); 170184610Salfredstruct usb2_pipe *usb2_get_pipe_by_addr(struct usb2_device *udev, uint8_t ea_val); 171185948Sthompsausb2_error_t usb2_interface_count(struct usb2_device *udev, uint8_t *count); 172185948Sthompsausb2_error_t usb2_probe_and_attach(struct usb2_device *udev, 173185948Sthompsa uint8_t iface_index); 174185948Sthompsausb2_error_t usb2_reset_iface_endpoints(struct usb2_device *udev, 175185948Sthompsa uint8_t iface_index); 176185948Sthompsausb2_error_t usb2_set_config_index(struct usb2_device *udev, uint8_t index); 177185948Sthompsausb2_error_t usb2_set_endpoint_stall(struct usb2_device *udev, 178185948Sthompsa struct usb2_pipe *pipe, uint8_t do_stall); 179185948Sthompsausb2_error_t usb2_suspend_resume(struct usb2_device *udev, 180185948Sthompsa uint8_t do_suspend); 181185948Sthompsavoid usb2_detach_device(struct usb2_device *udev, uint8_t iface_index, 182185948Sthompsa uint8_t free_subdev); 183184610Salfredvoid usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len); 184184610Salfredvoid usb2_free_device(struct usb2_device *udev); 185185948Sthompsavoid *usb2_find_descriptor(struct usb2_device *udev, void *id, 186185948Sthompsa uint8_t iface_index, uint8_t type, uint8_t type_mask, 187185948Sthompsa uint8_t subtype, uint8_t subtype_mask); 188184610Salfredvoid usb_linux_free_device(struct usb_device *dev); 189186730Salfreduint8_t usb2_peer_can_wakeup(struct usb2_device *udev); 190188985Sthompsastruct usb2_pipe *usb2_pipe_foreach(struct usb2_device *udev, struct usb2_pipe *pipe); 191184610Salfred 192184610Salfred#endif /* _USB2_DEVICE_H_ */ 193