usbdivar.h revision 1.22 1 /* $NetBSD: usbdivar.h,v 1.22 1999/06/30 06:44:23 augustss 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 int toggle; /* XXX */
47 };
48
49 typedef void (*usbd_xfercb)__P((usbd_request_handle req));
50
51 struct usbd_methods {
52 usbd_status (*transfer)__P((usbd_request_handle reqh));
53 usbd_status (*start)__P((usbd_request_handle reqh));
54 void (*abort)__P((usbd_request_handle reqh));
55 void (*close)__P((usbd_pipe_handle pipe));
56 usbd_status (*isobuf)__P((usbd_pipe_handle pipe,
57 u_int32_t bufsize,u_int32_t nbuf));
58 };
59
60 struct usbd_port {
61 usb_port_status_t status;
62 u_int16_t power; /* mA of current on port */
63 u_int8_t portno;
64 u_int8_t restartcnt;
65 #define USBD_RESTART_MAX 5
66 struct usbd_device *device;
67 struct usbd_device *parent; /* The ports hub */
68 };
69
70 struct usbd_hub {
71 usbd_status (*explore)__P((usbd_device_handle hub));
72 void *hubsoftc;
73 usb_hub_descriptor_t hubdesc;
74 struct usbd_port ports[1];
75 };
76
77 struct usb_softc;
78
79 /*****/
80
81 struct usbd_bus {
82 /* Filled by HC driver */
83 bdevice bdev; /* base device, host adapter */
84 usbd_status (*open_pipe)__P((struct usbd_pipe *pipe));
85 u_int32_t pipe_size; /* size of a pipe struct */
86 void (*do_poll)__P((struct usbd_bus *));
87 /* Filled by usb driver */
88 struct usbd_device *root_hub;
89 usbd_device_handle devices[USB_MAX_DEVICES];
90 char needs_explore;/* a hub a signalled a change */
91 char use_polling;
92 struct usb_softc *usbctl;
93 struct usb_device_stats stats;
94 };
95
96 struct usbd_device {
97 struct usbd_bus *bus;
98 struct usbd_pipe *default_pipe;
99 u_int8_t address;
100 u_int8_t depth;
101 u_int8_t lowspeed;
102 u_int16_t power;
103 u_int8_t self_powered;
104 int config;
105 int langid; /* language to use for strings */
106 #define USBD_NOLANG (-1)
107 struct usbd_port *powersrc;
108 struct usbd_endpoint def_ep; /* for pipe 0 */
109 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
110 struct usbd_interface *ifaces;
111 usb_device_descriptor_t ddesc;
112 usb_config_descriptor_t *cdesc; /* full config descr */
113 struct usbd_quirks *quirks;
114 struct usbd_hub *hub; /* only if this is a hub */
115 struct device **subdevs; /* sub-devices, 0 terminated */
116 };
117
118 struct usbd_interface {
119 struct usbd_device *device;
120 usb_interface_descriptor_t *idesc;
121 int index;
122 int altindex;
123 struct usbd_endpoint *endpoints;
124 void *priv;
125 LIST_HEAD(, usbd_pipe) pipes;
126 };
127
128 struct usbd_pipe {
129 struct usbd_interface *iface;
130 struct usbd_device *device;
131 struct usbd_endpoint *endpoint;
132 int refcnt;
133 char running;
134 SIMPLEQ_HEAD(, usbd_request) queue;
135 LIST_ENTRY(usbd_pipe) next;
136
137 usbd_request_handle intrreqh; /* used for repeating requests */
138 char repeat;
139
140 /* Filled by HC driver. */
141 struct usbd_methods *methods;
142 };
143
144 struct usbd_request {
145 struct usbd_pipe *pipe;
146 void *priv;
147 void *buffer;
148 u_int32_t length;
149 u_int32_t actlen;
150 u_int16_t flags;
151 u_int32_t timeout;
152 usbd_status status;
153 usbd_callback callback;
154 usbd_xfercb xfercb;
155 u_int32_t retries;
156 char done;
157
158 usb_device_request_t request;
159 u_int8_t isreq;
160
161 SIMPLEQ_ENTRY(usbd_request) next;
162
163 void *hcpriv; /* XXX private use by the HC driver */
164
165 #if defined(__FreeBSD__)
166 struct callout_handle timo_handle;
167 #endif
168 };
169
170 void usbd_init __P((void));
171
172 /* Routines from usb_subr.c */
173 int usbctlprint __P((void *, const char *));
174 void usb_delay_ms __P((usbd_bus_handle, u_int));
175 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
176 usbd_status usbd_reset_port __P((usbd_device_handle dev,
177 int port, usb_port_status_t *ps));
178 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
179 usbd_interface_handle iface,
180 struct usbd_endpoint *,
181 usbd_pipe_handle *pipe));
182 usbd_status usbd_new_device __P((bdevice *parent,
183 usbd_bus_handle bus, int depth,
184 int lowspeed, int port,
185 struct usbd_port *));
186 void usbd_remove_device __P((usbd_device_handle,
187 struct usbd_port *));
188 int usbd_printBCD __P((char *cp, int bcd));
189 usbd_status usb_insert_transfer __P((usbd_request_handle reqh));
190 void usb_start_next __P((usbd_pipe_handle pipe));
191 usbd_status usbd_fill_iface_data __P((usbd_device_handle dev,
192 int i, int a));
193 void usb_free_device __P((usbd_device_handle));
194
195 /* Routines from usb.c */
196 int usb_bus_count __P((void));
197 void usb_needs_explore __P((usbd_bus_handle));
198 #if 0
199 usbd_status usb_get_bus_handle __P((int, usbd_bus_handle *));
200 #endif
201
202 /* Locator stuff. */
203
204 #if defined(__NetBSD__)
205 #include "locators.h"
206 #elif defined(__FreeBSD__)
207 /* XXX these values are used to statically bind some elements in the USB tree
208 * to specific driver instances. This should be somehow emulated in FreeBSD
209 * but can be done later on.
210 * The values are copied from the files.usb file in the NetBSD sources.
211 */
212 #define UHUBCF_PORT_DEFAULT -1
213 #define UHUBCF_CONFIGURATION_DEFAULT -1
214 #define UHUBCF_INTERFACE_DEFAULT -1
215 #define UHUBCF_VENDOR_DEFAULT -1
216 #define UHUBCF_PRODUCT_DEFAULT -1
217 #define UHUBCF_RELEASE_DEFAULT -1
218 #endif
219
220 #define uhubcf_port cf_loc[UHUBCF_PORT]
221 #define uhubcf_configuration cf_loc[UHUBCF_CONFIGURATION]
222 #define uhubcf_interface cf_loc[UHUBCF_INTERFACE]
223 #define uhubcf_vendor cf_loc[UHUBCF_VENDOR]
224 #define uhubcf_product cf_loc[UHUBCF_PRODUCT]
225 #define uhubcf_release cf_loc[UHUBCF_RELEASE]
226 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
227 #define UHUB_UNK_CONFIGURATION UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
228 #define UHUB_UNK_INTERFACE UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
229 #define UHUB_UNK_VENDOR UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
230 #define UHUB_UNK_PRODUCT UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
231 #define UHUB_UNK_RELEASE UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
232
233