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