usbdivar.h revision 1.27 1 /* $NetBSD: usbdivar.h,v 1.27 1999/08/29 17:57:25 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss (at) carlstedt.se) at
9 * Carlstedt Research & Technology.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 struct usbd_request;
41 struct usbd_pipe;
42
43 struct usbd_endpoint {
44 usb_endpoint_descriptor_t *edesc;
45 int refcnt;
46 };
47
48 struct usbd_methods {
49 usbd_status (*transfer)__P((usbd_request_handle reqh));
50 usbd_status (*start)__P((usbd_request_handle reqh));
51 void (*abort)__P((usbd_request_handle reqh));
52 void (*close)__P((usbd_pipe_handle pipe));
53 void (*cleartoggle)__P((usbd_pipe_handle pipe));
54 void (*done)__P((usbd_request_handle reqh));
55 usbd_status (*isobuf)__P((usbd_pipe_handle pipe,
56 u_int32_t bufsize,u_int32_t nbuf));
57 };
58
59 struct usbd_port {
60 usb_port_status_t status;
61 u_int16_t power; /* mA of current on port */
62 u_int8_t portno;
63 u_int8_t restartcnt;
64 #define USBD_RESTART_MAX 5
65 struct usbd_device *device;
66 struct usbd_device *parent; /* The ports hub */
67 };
68
69 struct usbd_hub {
70 usbd_status (*explore)__P((usbd_device_handle hub));
71 void *hubsoftc;
72 usb_hub_descriptor_t hubdesc;
73 struct usbd_port ports[1];
74 };
75
76 struct usb_softc;
77
78 /*****/
79
80 struct usbd_bus {
81 /* Filled by HC driver */
82 bdevice bdev; /* base device, host adapter */
83 usbd_status (*open_pipe)__P((struct usbd_pipe *pipe));
84 u_int32_t pipe_size; /* size of a pipe struct */
85 void (*do_poll)__P((struct usbd_bus *));
86 /* Filled by usb driver */
87 struct usbd_device *root_hub;
88 usbd_device_handle devices[USB_MAX_DEVICES];
89 char needs_explore;/* a hub a signalled a change */
90 char use_polling;
91 struct usb_softc *usbctl;
92 struct usb_device_stats stats;
93 };
94
95 struct usbd_device {
96 struct usbd_bus *bus;
97 struct usbd_pipe *default_pipe;
98 u_int8_t address;
99 u_int8_t depth;
100 u_int8_t lowspeed;
101 u_int16_t power;
102 u_int8_t self_powered;
103 int config;
104 int langid; /* language to use for strings */
105 #define USBD_NOLANG (-1)
106 struct usbd_port *powersrc;
107 struct usbd_endpoint def_ep; /* for pipe 0 */
108 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
109 struct usbd_interface *ifaces;
110 usb_device_descriptor_t ddesc;
111 usb_config_descriptor_t *cdesc; /* full config descr */
112 struct usbd_quirks *quirks;
113 struct usbd_hub *hub; /* only if this is a hub */
114 bdevice **subdevs; /* sub-devices, 0 terminated */
115 };
116
117 struct usbd_interface {
118 struct usbd_device *device;
119 usb_interface_descriptor_t *idesc;
120 int index;
121 int altindex;
122 struct usbd_endpoint *endpoints;
123 void *priv;
124 LIST_HEAD(, usbd_pipe) pipes;
125 };
126
127 struct usbd_pipe {
128 struct usbd_interface *iface;
129 struct usbd_device *device;
130 struct usbd_endpoint *endpoint;
131 int refcnt;
132 char running;
133 SIMPLEQ_HEAD(, usbd_request) queue;
134 LIST_ENTRY(usbd_pipe) next;
135
136 usbd_request_handle intrreqh; /* used for repeating requests */
137 char repeat;
138
139 /* Filled by HC driver. */
140 struct usbd_methods *methods;
141 };
142
143 struct usbd_request {
144 struct usbd_pipe *pipe;
145 void *priv;
146 void *buffer;
147 u_int32_t length;
148 u_int32_t actlen;
149 u_int16_t flags;
150 u_int32_t timeout;
151 usbd_status status;
152 usbd_callback callback;
153 __volatile char done;
154
155 usb_device_request_t request;
156 char isreq;
157
158 SIMPLEQ_ENTRY(usbd_request) next;
159
160 void *hcpriv; /* XXX private use by the HC driver */
161
162 #if defined(__FreeBSD__)
163 struct callout_handle timo_handle;
164 #endif
165 };
166
167 void usbd_init __P((void));
168
169 /* Routines from usb_subr.c */
170 int usbctlprint __P((void *, const char *));
171 void usb_delay_ms __P((usbd_bus_handle, u_int));
172 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
173 usbd_status usbd_reset_port __P((usbd_device_handle dev,
174 int port, usb_port_status_t *ps));
175 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
176 usbd_interface_handle iface,
177 struct usbd_endpoint *,
178 usbd_pipe_handle *pipe));
179 usbd_status usbd_new_device __P((bdevice *parent,
180 usbd_bus_handle bus, int depth,
181 int lowspeed, int port,
182 struct usbd_port *));
183 void usbd_remove_device __P((usbd_device_handle,
184 struct usbd_port *));
185 int usbd_printBCD __P((char *cp, int bcd));
186 usbd_status usbd_fill_iface_data __P((usbd_device_handle dev,
187 int i, int a));
188 void usb_free_device __P((usbd_device_handle));
189
190 usbd_status usb_insert_transfer __P((usbd_request_handle reqh));
191 void usb_transfer_complete __P((usbd_request_handle reqh));
192
193 /* Routines from usb.c */
194 int usb_bus_count __P((void));
195 void usb_needs_explore __P((usbd_bus_handle));
196 #if 0
197 usbd_status usb_get_bus_handle __P((int, usbd_bus_handle *));
198 #endif
199
200 /* Locator stuff. */
201
202 #if defined(__NetBSD__)
203 #include "locators.h"
204 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
205 /* XXX these values are used to statically bind some elements in the USB tree
206 * to specific driver instances. This should be somehow emulated in FreeBSD
207 * but can be done later on.
208 * The values are copied from the files.usb file in the NetBSD sources.
209 */
210 #define UHUBCF_PORT_DEFAULT -1
211 #define UHUBCF_CONFIGURATION_DEFAULT -1
212 #define UHUBCF_INTERFACE_DEFAULT -1
213 #define UHUBCF_VENDOR_DEFAULT -1
214 #define UHUBCF_PRODUCT_DEFAULT -1
215 #define UHUBCF_RELEASE_DEFAULT -1
216 #endif
217
218 #if defined (__OpenBSD__)
219 #define UHUBCF_PORT 0
220 #define UHUBCF_CONFIGURATION 1
221 #define UHUBCF_INTERFACE 2
222 #define UHUBCF_VENDOR 3
223 #define UHUBCF_PRODUCT 4
224 #define UHUBCF_RELEASE 5
225 #endif
226
227 #define uhubcf_port cf_loc[UHUBCF_PORT]
228 #define uhubcf_configuration cf_loc[UHUBCF_CONFIGURATION]
229 #define uhubcf_interface cf_loc[UHUBCF_INTERFACE]
230 #define uhubcf_vendor cf_loc[UHUBCF_VENDOR]
231 #define uhubcf_product cf_loc[UHUBCF_PRODUCT]
232 #define uhubcf_release cf_loc[UHUBCF_RELEASE]
233 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
234 #define UHUB_UNK_CONFIGURATION UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
235 #define UHUB_UNK_INTERFACE UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
236 #define UHUB_UNK_VENDOR UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
237 #define UHUB_UNK_PRODUCT UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
238 #define UHUB_UNK_RELEASE UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
239
240