usb_device.h revision 185948
1184610Salfred/* $FreeBSD: head/sys/dev/usb2/core/usb2_device.h 185948 2008-12-11 23:13:02Z 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/*
86184610Salfred * The following structure defines an USB device. There exists one of
87184610Salfred * these structures for every USB device.
88184610Salfred */
89184610Salfredstruct usb2_device {
90184610Salfred	struct usb2_clear_stall_msg cs_msg[2];	/* generic clear stall
91184610Salfred						 * messages */
92184610Salfred	struct usb2_perm perm;
93184610Salfred	struct sx default_sx[2];
94184610Salfred	struct mtx default_mtx[1];
95184610Salfred	struct cv default_cv[2];
96184610Salfred	struct usb2_interface ifaces[USB_IFACE_MAX];
97184610Salfred	struct usb2_pipe default_pipe;	/* Control Endpoint 0 */
98184610Salfred	struct usb2_pipe pipes[USB_EP_MAX];
99184610Salfred
100184610Salfred	struct usb2_bus *bus;		/* our USB BUS */
101184610Salfred	device_t parent_dev;		/* parent device */
102184610Salfred	struct usb2_device *parent_hub;
103184610Salfred	struct usb2_config_descriptor *cdesc;	/* full config descr */
104184610Salfred	struct usb2_hub *hub;		/* only if this is a hub */
105184610Salfred	struct usb_device *linux_dev;
106184610Salfred	struct usb2_xfer *default_xfer[USB_DEFAULT_XFER_MAX];
107184610Salfred	struct usb2_temp_data *usb2_template_ptr;
108184610Salfred	struct usb2_pipe *pipe_curr;	/* current clear stall pipe */
109184610Salfred	struct usb2_fifo *fifo[USB_FIFO_MAX];
110184610Salfred	struct usb2_symlink *ugen_symlink;	/* our generic symlink */
111184610Salfred
112184610Salfred	uint32_t plugtime;		/* copy of "ticks" */
113184610Salfred
114184610Salfred	uint16_t refcount;
115184610Salfred#define	USB_DEV_REF_MAX 0xffff
116184610Salfred
117184610Salfred	uint16_t power;			/* mA the device uses */
118184610Salfred	uint16_t langid;		/* language for strings */
119184610Salfred
120184610Salfred	uint8_t	address;		/* device addess */
121184610Salfred	uint8_t	device_index;		/* device index in "bus->devices" */
122184610Salfred	uint8_t	curr_config_index;	/* current configuration index */
123184610Salfred	uint8_t	curr_config_no;		/* current configuration number */
124184610Salfred	uint8_t	depth;			/* distance from root HUB */
125184610Salfred	uint8_t	speed;			/* low/full/high speed */
126184610Salfred	uint8_t	port_index;		/* parent HUB port index */
127184610Salfred	uint8_t	port_no;		/* parent HUB port number */
128184610Salfred	uint8_t	hs_hub_addr;		/* high-speed HUB address */
129184610Salfred	uint8_t	hs_port_no;		/* high-speed HUB port number */
130184610Salfred	uint8_t	driver_added_refcount;	/* our driver added generation count */
131184610Salfred	uint8_t	power_mode;		/* see USB_POWER_XXX */
132184610Salfred
133184610Salfred	/* the "flags" field is write-protected by "bus->mtx" */
134184610Salfred
135184610Salfred	struct usb2_device_flags flags;
136184610Salfred
137184610Salfred	struct usb2_endpoint_descriptor default_ep_desc;	/* for pipe 0 */
138184610Salfred	struct usb2_device_descriptor ddesc;	/* device descriptor */
139184610Salfred
140184610Salfred	char	serial[64];		/* serial number */
141184610Salfred	char	manufacturer[64];	/* manufacturer string */
142184610Salfred	char	product[64];		/* product string */
143184610Salfred};
144184610Salfred
145184610Salfred/* function prototypes */
146184610Salfred
147185948Sthompsastruct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
148185948Sthompsa		    struct usb2_device *parent_hub, uint8_t depth,
149185948Sthompsa		    uint8_t port_index, uint8_t port_no, uint8_t speed,
150185948Sthompsa		    uint8_t usb2_mode);
151185948Sthompsastruct usb2_pipe *usb2_get_pipe(struct usb2_device *udev, uint8_t iface_index,
152185948Sthompsa		    const struct usb2_config *setup);
153184610Salfredstruct usb2_pipe *usb2_get_pipe_by_addr(struct usb2_device *udev, uint8_t ea_val);
154185948Sthompsausb2_error_t	usb2_interface_count(struct usb2_device *udev, uint8_t *count);
155185948Sthompsausb2_error_t	usb2_probe_and_attach(struct usb2_device *udev,
156185948Sthompsa		    uint8_t iface_index);
157185948Sthompsausb2_error_t	usb2_reset_iface_endpoints(struct usb2_device *udev,
158185948Sthompsa		    uint8_t iface_index);
159185948Sthompsausb2_error_t	usb2_set_config_index(struct usb2_device *udev, uint8_t index);
160185948Sthompsausb2_error_t	usb2_set_endpoint_stall(struct usb2_device *udev,
161185948Sthompsa		    struct usb2_pipe *pipe, uint8_t do_stall);
162185948Sthompsausb2_error_t	usb2_suspend_resume(struct usb2_device *udev,
163185948Sthompsa		    uint8_t do_suspend);
164185948Sthompsavoid	usb2_detach_device(struct usb2_device *udev, uint8_t iface_index,
165185948Sthompsa	    uint8_t free_subdev);
166184610Salfredvoid	usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len);
167184610Salfredvoid	usb2_free_device(struct usb2_device *udev);
168185948Sthompsavoid	*usb2_find_descriptor(struct usb2_device *udev, void *id,
169185948Sthompsa	    uint8_t iface_index, uint8_t type, uint8_t type_mask,
170185948Sthompsa	    uint8_t subtype, uint8_t subtype_mask);
171184610Salfredvoid	usb_linux_free_device(struct usb_device *dev);
172184610Salfred
173184610Salfred#endif					/* _USB2_DEVICE_H_ */
174