usb_device.h revision 188987
155714Skris/* $FreeBSD: head/sys/dev/usb/usb_device.h 188987 2009-02-24 03:43:05Z thompsa $ */ 255714Skris/*- 355714Skris * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 455714Skris * 555714Skris * Redistribution and use in source and binary forms, with or without 655714Skris * modification, are permitted provided that the following conditions 755714Skris * are met: 855714Skris * 1. Redistributions of source code must retain the above copyright 955714Skris * notice, this list of conditions and the following disclaimer. 1055714Skris * 2. Redistributions in binary form must reproduce the above copyright 1155714Skris * notice, this list of conditions and the following disclaimer in the 1255714Skris * documentation and/or other materials provided with the distribution. 1355714Skris * 1455714Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1555714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1655714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1755714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1855714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1955714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2055714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2155714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2255714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2355714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2455714Skris * SUCH DAMAGE. 2555714Skris */ 2655714Skris 2755714Skris#ifndef _USB2_DEVICE_H_ 2855714Skris#define _USB2_DEVICE_H_ 2955714Skris 3055714Skrisstruct usb2_symlink; 3155714Skris 3255714Skris#define USB_DEFAULT_XFER_MAX 2 3355714Skris 3455714Skrisstruct usb2_clear_stall_msg { 3555714Skris struct usb2_proc_msg hdr; 3655714Skris struct usb2_device *udev; 3755714Skris}; 3855714Skris 3955714Skris/* 4055714Skris * The following structure defines an USB pipe which is equal to an 4155714Skris * USB endpoint. 4255714Skris */ 4355714Skrisstruct usb2_pipe { 4455714Skris struct usb2_xfer_queue pipe_q; /* queue of USB transfers */ 4555714Skris 4655714Skris struct usb2_xfer *xfer_block; /* blocking USB transfer */ 4755714Skris struct usb2_endpoint_descriptor *edesc; 4855714Skris struct usb2_pipe_methods *methods; /* set by HC driver */ 4955714Skris 5055714Skris uint16_t isoc_next; 5155714Skris uint16_t refcount; 5255714Skris 5355714Skris uint8_t toggle_next:1; /* next data toggle value */ 5455714Skris uint8_t is_stalled:1; /* set if pipe is stalled */ 5555714Skris uint8_t is_synced:1; /* set if we a synchronised */ 5655714Skris uint8_t unused:5; 5755714Skris uint8_t iface_index; /* not used by "default pipe" */ 5855714Skris}; 59160814Ssimon 60160814Ssimon/* 61160814Ssimon * The following structure defines an USB interface. 62160814Ssimon */ 63160814Ssimonstruct usb2_interface { 6455714Skris struct usb2_perm perm; /* interface permissions */ 65160814Ssimon struct usb2_interface_descriptor *idesc; 6655714Skris device_t subdev; 6755714Skris uint8_t alt_index; 6855714Skris uint8_t parent_iface_index; 69160814Ssimon}; 70160814Ssimon 71160814Ssimon/* 72160814Ssimon * The following structure defines the USB device flags. 73160814Ssimon */ 74160814Ssimonstruct usb2_device_flags { 75160814Ssimon uint8_t usb2_mode:1; /* USB mode (see USB_MODE_XXX) */ 76160814Ssimon uint8_t self_powered:1; /* set if USB device is self powered */ 77160814Ssimon uint8_t suspended:1; /* set if USB device is suspended */ 78160814Ssimon uint8_t no_strings:1; /* set if USB device does not support 79160814Ssimon * strings */ 80160814Ssimon uint8_t remote_wakeup:1; /* set if remote wakeup is enabled */ 81160814Ssimon uint8_t uq_bus_powered:1; /* set if BUS powered quirk is present */ 82160814Ssimon uint8_t uq_power_claim:1; /* set if power claim quirk is present */ 83160814Ssimon}; 84160814Ssimon 85160814Ssimon/* 86160814Ssimon * The following structure is used for power-save purposes. The data 87160814Ssimon * in this structure is protected by the USB BUS lock. 88160814Ssimon */ 89160814Ssimonstruct usb2_power_save { 90160814Ssimon int last_xfer_time; /* copy of "ticks" */ 91160814Ssimon uint32_t type_refs[4]; /* transfer reference count */ 92160814Ssimon uint32_t read_refs; /* data read references */ 93160814Ssimon uint32_t write_refs; /* data write references */ 94160814Ssimon uint8_t suspended; /* set if USB device is suspended */ 95160814Ssimon}; 96160814Ssimon 97160814Ssimon/* 98160814Ssimon * The following structure defines an USB device. There exists one of 99160814Ssimon * these structures for every USB device. 100160814Ssimon */ 101160814Ssimonstruct usb2_device { 102160814Ssimon struct usb2_clear_stall_msg cs_msg[2]; /* generic clear stall 103160814Ssimon * messages */ 104160814Ssimon struct usb2_perm perm; 105160814Ssimon struct sx default_sx[2]; 106160814Ssimon struct mtx default_mtx[1]; 107160814Ssimon struct cv default_cv[2]; 108160814Ssimon struct usb2_interface ifaces[USB_IFACE_MAX]; 109160814Ssimon struct usb2_pipe default_pipe; /* Control Endpoint 0 */ 110160814Ssimon struct usb2_pipe pipes[USB_EP_MAX]; 111160814Ssimon struct usb2_power_save pwr_save;/* power save data */ 112160814Ssimon 113160814Ssimon struct usb2_bus *bus; /* our USB BUS */ 114160814Ssimon device_t parent_dev; /* parent device */ 115160814Ssimon struct usb2_device *parent_hub; 116160814Ssimon struct usb2_config_descriptor *cdesc; /* full config descr */ 117160814Ssimon struct usb2_hub *hub; /* only if this is a hub */ 118160814Ssimon struct usb_device *linux_dev; 119160814Ssimon struct usb2_xfer *default_xfer[USB_DEFAULT_XFER_MAX]; 120160814Ssimon struct usb2_temp_data *usb2_template_ptr; 121160814Ssimon struct usb2_pipe *pipe_curr; /* current clear stall pipe */ 122160814Ssimon struct usb2_fifo *fifo[USB_FIFO_MAX]; 123160814Ssimon struct usb2_symlink *ugen_symlink; /* our generic symlink */ 124160814Ssimon 125160814Ssimon uint32_t plugtime; /* copy of "ticks" */ 126160814Ssimon 127160814Ssimon uint16_t refcount; 128160814Ssimon#define USB_DEV_REF_MAX 0xffff 129160814Ssimon 130160814Ssimon uint16_t power; /* mA the device uses */ 131160814Ssimon uint16_t langid; /* language for strings */ 132160814Ssimon 133160814Ssimon uint8_t address; /* device addess */ 134160814Ssimon uint8_t device_index; /* device index in "bus->devices" */ 135160814Ssimon uint8_t curr_config_index; /* current configuration index */ 136160814Ssimon uint8_t curr_config_no; /* current configuration number */ 137160814Ssimon uint8_t depth; /* distance from root HUB */ 138160814Ssimon uint8_t speed; /* low/full/high speed */ 139160814Ssimon uint8_t port_index; /* parent HUB port index */ 140160814Ssimon uint8_t port_no; /* parent HUB port number */ 141160814Ssimon uint8_t hs_hub_addr; /* high-speed HUB address */ 142160814Ssimon uint8_t hs_port_no; /* high-speed HUB port number */ 143160814Ssimon uint8_t driver_added_refcount; /* our driver added generation count */ 144160814Ssimon uint8_t power_mode; /* see USB_POWER_XXX */ 145160814Ssimon 146160814Ssimon /* the "flags" field is write-protected by "bus->mtx" */ 147160814Ssimon 148160814Ssimon struct usb2_device_flags flags; 149160814Ssimon 150160814Ssimon struct usb2_endpoint_descriptor default_ep_desc; /* for pipe 0 */ 151160814Ssimon struct usb2_device_descriptor ddesc; /* device descriptor */ 152160814Ssimon 153160814Ssimon char serial[64]; /* serial number */ 154160814Ssimon char manufacturer[64]; /* manufacturer string */ 155160814Ssimon char product[64]; /* product string */ 156160814Ssimon}; 157160814Ssimon 158160814Ssimon/* globals */ 159160814Ssimon 160160814Ssimonextern int usb2_template; 161160814Ssimon 162160814Ssimon/* function prototypes */ 163160814Ssimon 164160814Ssimonstruct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus, 165160814Ssimon struct usb2_device *parent_hub, uint8_t depth, 166160814Ssimon uint8_t port_index, uint8_t port_no, uint8_t speed, 167160814Ssimon uint8_t usb2_mode); 168160814Ssimonstruct usb2_pipe *usb2_get_pipe(struct usb2_device *udev, uint8_t iface_index, 169160814Ssimon const struct usb2_config *setup); 170160814Ssimonstruct usb2_pipe *usb2_get_pipe_by_addr(struct usb2_device *udev, uint8_t ea_val); 171160814Ssimonusb2_error_t usb2_interface_count(struct usb2_device *udev, uint8_t *count); 172160814Ssimonusb2_error_t usb2_probe_and_attach(struct usb2_device *udev, 173160814Ssimon uint8_t iface_index); 174160814Ssimonusb2_error_t usb2_reset_iface_endpoints(struct usb2_device *udev, 175160814Ssimon uint8_t iface_index); 176160814Ssimonusb2_error_t usb2_set_config_index(struct usb2_device *udev, uint8_t index); 177160814Ssimonusb2_error_t usb2_set_endpoint_stall(struct usb2_device *udev, 178160814Ssimon struct usb2_pipe *pipe, uint8_t do_stall); 179160814Ssimonusb2_error_t usb2_suspend_resume(struct usb2_device *udev, 180160814Ssimon uint8_t do_suspend); 181160814Ssimonvoid usb2_detach_device(struct usb2_device *udev, uint8_t iface_index, 182160814Ssimon uint8_t free_subdev); 183160814Ssimonvoid usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len); 184160814Ssimonvoid usb2_free_device(struct usb2_device *udev); 185160814Ssimonvoid *usb2_find_descriptor(struct usb2_device *udev, void *id, 186160814Ssimon uint8_t iface_index, uint8_t type, uint8_t type_mask, 187160814Ssimon uint8_t subtype, uint8_t subtype_mask); 188160814Ssimonvoid usb_linux_free_device(struct usb_device *dev); 189160814Ssimonuint8_t usb2_peer_can_wakeup(struct usb2_device *udev); 190160814Ssimonstruct usb2_pipe *usb2_pipe_foreach(struct usb2_device *udev, struct usb2_pipe *pipe); 191160814Ssimon 192160814Ssimon#endif /* _USB2_DEVICE_H_ */ 193160814Ssimon