Deleted Added
full compact
usb_device.h (190180) usb_device.h (190181)
1/* $FreeBSD: head/sys/dev/usb/usb_device.h 190180 2009-03-20 21:48:11Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb/usb_device.h 190181 2009-03-20 21:50:54Z 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;
31struct usb_device; /* linux compat */
32
33#define USB_DEFAULT_XFER_MAX 2
34
35struct usb2_clear_stall_msg {
36 struct usb2_proc_msg hdr;
37 struct usb2_device *udev;
38};
39
40/*
41 * The following structure defines an USB pipe which is equal to an
42 * USB endpoint.
43 */
44struct usb2_pipe {
45 struct usb2_xfer_queue pipe_q; /* queue of USB transfers */
46
47 struct usb2_xfer *xfer_block; /* blocking USB transfer */
48 struct usb2_endpoint_descriptor *edesc;
49 struct usb2_pipe_methods *methods; /* set by HC driver */
50
51 uint16_t isoc_next;
52 uint16_t refcount;
53
54 uint8_t toggle_next:1; /* next data toggle value */
55 uint8_t is_stalled:1; /* set if pipe is stalled */
56 uint8_t is_synced:1; /* set if we a synchronised */
57 uint8_t unused:5;
58 uint8_t iface_index; /* not used by "default pipe" */
59};
60
61/*
62 * The following structure defines an USB interface.
63 */
64struct usb2_interface {
65 struct usb2_interface_descriptor *idesc;
66 device_t subdev;
67 uint8_t alt_index;
68 uint8_t parent_iface_index;
69};
70
71/*
72 * The following structure defines the USB device flags.
73 */
74struct usb2_device_flags {
75 uint8_t usb2_mode:1; /* USB mode (see USB_MODE_XXX) */
76 uint8_t self_powered:1; /* set if USB device is self powered */
77 uint8_t suspended:1; /* set if USB device is suspended */
78 uint8_t no_strings:1; /* set if USB device does not support
79 * strings */
80 uint8_t remote_wakeup:1; /* set if remote wakeup is enabled */
81 uint8_t uq_bus_powered:1; /* set if BUS powered quirk is present */
82 uint8_t uq_power_claim:1; /* set if power claim quirk is present */
83};
84
85/*
86 * The following structure is used for power-save purposes. The data
87 * in this structure is protected by the USB BUS lock.
88 */
89struct usb2_power_save {
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;
31struct usb_device; /* linux compat */
32
33#define USB_DEFAULT_XFER_MAX 2
34
35struct usb2_clear_stall_msg {
36 struct usb2_proc_msg hdr;
37 struct usb2_device *udev;
38};
39
40/*
41 * The following structure defines an USB pipe which is equal to an
42 * USB endpoint.
43 */
44struct usb2_pipe {
45 struct usb2_xfer_queue pipe_q; /* queue of USB transfers */
46
47 struct usb2_xfer *xfer_block; /* blocking USB transfer */
48 struct usb2_endpoint_descriptor *edesc;
49 struct usb2_pipe_methods *methods; /* set by HC driver */
50
51 uint16_t isoc_next;
52 uint16_t refcount;
53
54 uint8_t toggle_next:1; /* next data toggle value */
55 uint8_t is_stalled:1; /* set if pipe is stalled */
56 uint8_t is_synced:1; /* set if we a synchronised */
57 uint8_t unused:5;
58 uint8_t iface_index; /* not used by "default pipe" */
59};
60
61/*
62 * The following structure defines an USB interface.
63 */
64struct usb2_interface {
65 struct usb2_interface_descriptor *idesc;
66 device_t subdev;
67 uint8_t alt_index;
68 uint8_t parent_iface_index;
69};
70
71/*
72 * The following structure defines the USB device flags.
73 */
74struct usb2_device_flags {
75 uint8_t usb2_mode:1; /* USB mode (see USB_MODE_XXX) */
76 uint8_t self_powered:1; /* set if USB device is self powered */
77 uint8_t suspended:1; /* set if USB device is suspended */
78 uint8_t no_strings:1; /* set if USB device does not support
79 * strings */
80 uint8_t remote_wakeup:1; /* set if remote wakeup is enabled */
81 uint8_t uq_bus_powered:1; /* set if BUS powered quirk is present */
82 uint8_t uq_power_claim:1; /* set if power claim quirk is present */
83};
84
85/*
86 * The following structure is used for power-save purposes. The data
87 * in this structure is protected by the USB BUS lock.
88 */
89struct usb2_power_save {
90 int last_xfer_time; /* copy of "ticks" */
91 uint32_t type_refs[4]; /* transfer reference count */
92 uint32_t read_refs; /* data read references */
93 uint32_t write_refs; /* data write references */
90 usb2_ticks_t last_xfer_time; /* copy of "ticks" */
91 usb2_size_t type_refs[4]; /* transfer reference count */
92 usb2_size_t read_refs; /* data read references */
93 usb2_size_t write_refs; /* data write references */
94 uint8_t suspended; /* set if USB device is suspended */
95};
96
97/*
98 * The following structure defines an USB device. There exists one of
99 * these structures for every USB device.
100 */
101struct usb2_device {
102 struct usb2_clear_stall_msg cs_msg[2]; /* generic clear stall
103 * messages */
104 struct sx default_sx[2];
105 struct mtx default_mtx[1];
106 struct cv default_cv[2];
107 struct usb2_interface ifaces[USB_IFACE_MAX];
108 struct usb2_pipe default_pipe; /* Control Endpoint 0 */
109 struct cdev *default_dev; /* Control Endpoint 0 device node */
110 struct usb2_pipe pipes[USB_EP_MAX];
111 struct usb2_power_save pwr_save;/* power save data */
112
113 struct usb2_bus *bus; /* our USB BUS */
114 device_t parent_dev; /* parent device */
115 struct usb2_device *parent_hub;
116 struct usb2_config_descriptor *cdesc; /* full config descr */
117 struct usb2_hub *hub; /* only if this is a hub */
118#if USB_HAVE_COMPAT_LINUX
119 struct usb_device *linux_dev;
120#endif
121 struct usb2_xfer *default_xfer[USB_DEFAULT_XFER_MAX];
122 struct usb2_temp_data *usb2_template_ptr;
123 struct usb2_pipe *pipe_curr; /* current clear stall pipe */
124 struct usb2_fifo *fifo[USB_FIFO_MAX];
125
126 char ugen_name[20]; /* name of ugenX.X device */
127 struct usb2_symlink *ugen_symlink; /* our generic symlink */
128
129 LIST_HEAD(,usb2_fs_privdata) pd_list;
130
94 uint8_t suspended; /* set if USB device is suspended */
95};
96
97/*
98 * The following structure defines an USB device. There exists one of
99 * these structures for every USB device.
100 */
101struct usb2_device {
102 struct usb2_clear_stall_msg cs_msg[2]; /* generic clear stall
103 * messages */
104 struct sx default_sx[2];
105 struct mtx default_mtx[1];
106 struct cv default_cv[2];
107 struct usb2_interface ifaces[USB_IFACE_MAX];
108 struct usb2_pipe default_pipe; /* Control Endpoint 0 */
109 struct cdev *default_dev; /* Control Endpoint 0 device node */
110 struct usb2_pipe pipes[USB_EP_MAX];
111 struct usb2_power_save pwr_save;/* power save data */
112
113 struct usb2_bus *bus; /* our USB BUS */
114 device_t parent_dev; /* parent device */
115 struct usb2_device *parent_hub;
116 struct usb2_config_descriptor *cdesc; /* full config descr */
117 struct usb2_hub *hub; /* only if this is a hub */
118#if USB_HAVE_COMPAT_LINUX
119 struct usb_device *linux_dev;
120#endif
121 struct usb2_xfer *default_xfer[USB_DEFAULT_XFER_MAX];
122 struct usb2_temp_data *usb2_template_ptr;
123 struct usb2_pipe *pipe_curr; /* current clear stall pipe */
124 struct usb2_fifo *fifo[USB_FIFO_MAX];
125
126 char ugen_name[20]; /* name of ugenX.X device */
127 struct usb2_symlink *ugen_symlink; /* our generic symlink */
128
129 LIST_HEAD(,usb2_fs_privdata) pd_list;
130
131 uint32_t plugtime; /* copy of "ticks" */
131 usb2_ticks_t plugtime; /* copy of "ticks" */
132
133 uint16_t refcount;
134#define USB_DEV_REF_MAX 0xffff
135
136 uint16_t power; /* mA the device uses */
137 uint16_t langid; /* language for strings */
138
139 uint8_t address; /* device addess */
140 uint8_t device_index; /* device index in "bus->devices" */
141 uint8_t curr_config_index; /* current configuration index */
142 uint8_t curr_config_no; /* current configuration number */
143 uint8_t depth; /* distance from root HUB */
144 uint8_t speed; /* low/full/high speed */
145 uint8_t port_index; /* parent HUB port index */
146 uint8_t port_no; /* parent HUB port number */
147 uint8_t hs_hub_addr; /* high-speed HUB address */
148 uint8_t hs_port_no; /* high-speed HUB port number */
149 uint8_t driver_added_refcount; /* our driver added generation count */
150 uint8_t power_mode; /* see USB_POWER_XXX */
151
152 /* the "flags" field is write-protected by "bus->mtx" */
153
154 struct usb2_device_flags flags;
155
156 struct usb2_endpoint_descriptor default_ep_desc; /* for pipe 0 */
157 struct usb2_device_descriptor ddesc; /* device descriptor */
158
159 char serial[64]; /* serial number */
160 char manufacturer[64]; /* manufacturer string */
161 char product[64]; /* product string */
162};
163
164/* globals */
165
166extern int usb2_template;
167
168/* function prototypes */
169
170struct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
171 struct usb2_device *parent_hub, uint8_t depth,
172 uint8_t port_index, uint8_t port_no, uint8_t speed,
173 uint8_t usb2_mode);
174struct usb2_pipe *usb2_get_pipe(struct usb2_device *udev, uint8_t iface_index,
175 const struct usb2_config *setup);
176struct usb2_pipe *usb2_get_pipe_by_addr(struct usb2_device *udev, uint8_t ea_val);
177usb2_error_t usb2_interface_count(struct usb2_device *udev, uint8_t *count);
178usb2_error_t usb2_probe_and_attach(struct usb2_device *udev,
179 uint8_t iface_index);
180usb2_error_t usb2_reset_iface_endpoints(struct usb2_device *udev,
181 uint8_t iface_index);
182usb2_error_t usb2_set_config_index(struct usb2_device *udev, uint8_t index);
183usb2_error_t usb2_set_endpoint_stall(struct usb2_device *udev,
184 struct usb2_pipe *pipe, uint8_t do_stall);
185usb2_error_t usb2_suspend_resume(struct usb2_device *udev,
186 uint8_t do_suspend);
187void usb2_detach_device(struct usb2_device *udev, uint8_t iface_index,
188 uint8_t free_subdev);
189void usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len);
190void usb2_free_device(struct usb2_device *udev);
191void *usb2_find_descriptor(struct usb2_device *udev, void *id,
192 uint8_t iface_index, uint8_t type, uint8_t type_mask,
193 uint8_t subtype, uint8_t subtype_mask);
194void usb_linux_free_device(struct usb_device *dev);
195uint8_t usb2_peer_can_wakeup(struct usb2_device *udev);
196struct usb2_pipe *usb2_pipe_foreach(struct usb2_device *udev, struct usb2_pipe *pipe);
197
198#endif /* _USB2_DEVICE_H_ */
132
133 uint16_t refcount;
134#define USB_DEV_REF_MAX 0xffff
135
136 uint16_t power; /* mA the device uses */
137 uint16_t langid; /* language for strings */
138
139 uint8_t address; /* device addess */
140 uint8_t device_index; /* device index in "bus->devices" */
141 uint8_t curr_config_index; /* current configuration index */
142 uint8_t curr_config_no; /* current configuration number */
143 uint8_t depth; /* distance from root HUB */
144 uint8_t speed; /* low/full/high speed */
145 uint8_t port_index; /* parent HUB port index */
146 uint8_t port_no; /* parent HUB port number */
147 uint8_t hs_hub_addr; /* high-speed HUB address */
148 uint8_t hs_port_no; /* high-speed HUB port number */
149 uint8_t driver_added_refcount; /* our driver added generation count */
150 uint8_t power_mode; /* see USB_POWER_XXX */
151
152 /* the "flags" field is write-protected by "bus->mtx" */
153
154 struct usb2_device_flags flags;
155
156 struct usb2_endpoint_descriptor default_ep_desc; /* for pipe 0 */
157 struct usb2_device_descriptor ddesc; /* device descriptor */
158
159 char serial[64]; /* serial number */
160 char manufacturer[64]; /* manufacturer string */
161 char product[64]; /* product string */
162};
163
164/* globals */
165
166extern int usb2_template;
167
168/* function prototypes */
169
170struct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
171 struct usb2_device *parent_hub, uint8_t depth,
172 uint8_t port_index, uint8_t port_no, uint8_t speed,
173 uint8_t usb2_mode);
174struct usb2_pipe *usb2_get_pipe(struct usb2_device *udev, uint8_t iface_index,
175 const struct usb2_config *setup);
176struct usb2_pipe *usb2_get_pipe_by_addr(struct usb2_device *udev, uint8_t ea_val);
177usb2_error_t usb2_interface_count(struct usb2_device *udev, uint8_t *count);
178usb2_error_t usb2_probe_and_attach(struct usb2_device *udev,
179 uint8_t iface_index);
180usb2_error_t usb2_reset_iface_endpoints(struct usb2_device *udev,
181 uint8_t iface_index);
182usb2_error_t usb2_set_config_index(struct usb2_device *udev, uint8_t index);
183usb2_error_t usb2_set_endpoint_stall(struct usb2_device *udev,
184 struct usb2_pipe *pipe, uint8_t do_stall);
185usb2_error_t usb2_suspend_resume(struct usb2_device *udev,
186 uint8_t do_suspend);
187void usb2_detach_device(struct usb2_device *udev, uint8_t iface_index,
188 uint8_t free_subdev);
189void usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len);
190void usb2_free_device(struct usb2_device *udev);
191void *usb2_find_descriptor(struct usb2_device *udev, void *id,
192 uint8_t iface_index, uint8_t type, uint8_t type_mask,
193 uint8_t subtype, uint8_t subtype_mask);
194void usb_linux_free_device(struct usb_device *dev);
195uint8_t usb2_peer_can_wakeup(struct usb2_device *udev);
196struct usb2_pipe *usb2_pipe_foreach(struct usb2_device *udev, struct usb2_pipe *pipe);
197
198#endif /* _USB2_DEVICE_H_ */