usbdivar.h revision 1.30 1 /* $NetBSD: usbdivar.h,v 1.30 1999/09/11 08:19:27 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 /* From usb_mem.h */
41 DECLARE_USB_DMA_T;
42
43 struct usbd_request;
44 struct usbd_pipe;
45
46 struct usbd_endpoint {
47 usb_endpoint_descriptor_t *edesc;
48 int refcnt;
49 };
50
51 struct usbd_bus_methods {
52 usbd_status (*open_pipe)__P((struct usbd_pipe *pipe));
53 void (*do_poll)__P((struct usbd_bus *));
54 usbd_status (*allocm)__P((struct usbd_bus *, usb_dma_t *,
55 u_int32_t bufsize));
56 void (*freem)__P((struct usbd_bus *, usb_dma_t *));
57 };
58
59 struct usbd_pipe_methods {
60 usbd_status (*transfer)__P((usbd_request_handle reqh));
61 usbd_status (*start)__P((usbd_request_handle reqh));
62 void (*abort)__P((usbd_request_handle reqh));
63 void (*close)__P((usbd_pipe_handle pipe));
64 void (*cleartoggle)__P((usbd_pipe_handle pipe));
65 void (*done)__P((usbd_request_handle reqh));
66 };
67
68 struct usbd_port {
69 usb_port_status_t status;
70 u_int16_t power; /* mA of current on port */
71 u_int8_t portno;
72 u_int8_t restartcnt;
73 #define USBD_RESTART_MAX 5
74 struct usbd_device *device;
75 struct usbd_device *parent; /* The ports hub */
76 };
77
78 struct usbd_hub {
79 usbd_status (*explore)__P((usbd_device_handle hub));
80 void *hubsoftc;
81 usb_hub_descriptor_t hubdesc;
82 struct usbd_port ports[1];
83 };
84
85 struct usb_softc;
86
87 /*****/
88
89 struct usbd_bus {
90 /* Filled by HC driver */
91 USBBASEDEVICE bdev; /* base device, host adapter */
92 struct usbd_bus_methods *methods;
93 u_int32_t pipe_size; /* size of a pipe struct */
94 /* Filled by usb driver */
95 struct usbd_device *root_hub;
96 usbd_device_handle devices[USB_MAX_DEVICES];
97 char needs_explore;/* a hub a signalled a change */
98 char use_polling;
99 struct usb_softc *usbctl;
100 struct usb_device_stats stats;
101 };
102
103 struct usbd_device {
104 struct usbd_bus *bus;
105 struct usbd_pipe *default_pipe;
106 u_int8_t address;
107 u_int8_t depth;
108 u_int8_t lowspeed;
109 u_int16_t power;
110 u_int8_t self_powered;
111 int config;
112 int langid; /* language to use for strings */
113 #define USBD_NOLANG (-1)
114 struct usbd_port *powersrc;
115 struct usbd_endpoint def_ep; /* for pipe 0 */
116 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
117 struct usbd_interface *ifaces;
118 usb_device_descriptor_t ddesc;
119 usb_config_descriptor_t *cdesc; /* full config descr */
120 struct usbd_quirks *quirks;
121 struct usbd_hub *hub; /* only if this is a hub */
122 device_ptr_t *subdevs; /* sub-devices, 0 terminated */
123 };
124
125 struct usbd_interface {
126 struct usbd_device *device;
127 usb_interface_descriptor_t *idesc;
128 int index;
129 int altindex;
130 struct usbd_endpoint *endpoints;
131 void *priv;
132 LIST_HEAD(, usbd_pipe) pipes;
133 };
134
135 struct usbd_pipe {
136 struct usbd_interface *iface;
137 struct usbd_device *device;
138 struct usbd_endpoint *endpoint;
139 int refcnt;
140 char running;
141 SIMPLEQ_HEAD(, usbd_request) queue;
142 LIST_ENTRY(usbd_pipe) next;
143
144 usbd_request_handle intrreqh; /* used for repeating requests */
145 char repeat;
146
147 /* Filled by HC driver. */
148 struct usbd_pipe_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 __volatile char done;
162
163 /* For control pipe */
164 usb_device_request_t request;
165
166 /* For isoc */
167 u_int16_t *frlengths;
168 int nframes;
169
170 /* For memory allocation */
171 struct usbd_device *device;
172 usb_dma_t dmabuf;
173
174 int rqflags;
175 #define URQ_REQUEST 0x01
176 #define URQ_AUTO_DMABUF 0x10
177 #define URQ_DEV_DMABUF 0x20
178
179 SIMPLEQ_ENTRY(usbd_request) next;
180
181 void *hcpriv; /* private use by the HC driver */
182 int hcprivint; /* ditto */
183
184 #if defined(__FreeBSD__)
185 struct callout_handle timo_handle;
186 #endif
187 };
188
189 void usbd_init __P((void));
190
191 /* Routines from usb_subr.c */
192 int usbctlprint __P((void *, const char *));
193 void usb_delay_ms __P((usbd_bus_handle, u_int));
194 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
195 usbd_status usbd_reset_port __P((usbd_device_handle dev,
196 int port, usb_port_status_t *ps));
197 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
198 usbd_interface_handle iface,
199 struct usbd_endpoint *,
200 usbd_pipe_handle *pipe));
201 usbd_status usbd_new_device __P((device_ptr_t parent,
202 usbd_bus_handle bus, int depth,
203 int lowspeed, int port,
204 struct usbd_port *));
205 void usbd_remove_device __P((usbd_device_handle,
206 struct usbd_port *));
207 int usbd_printBCD __P((char *cp, int bcd));
208 usbd_status usbd_fill_iface_data __P((usbd_device_handle dev,
209 int i, int a));
210 void usb_free_device __P((usbd_device_handle));
211
212 usbd_status usb_insert_transfer __P((usbd_request_handle reqh));
213 void usb_transfer_complete __P((usbd_request_handle reqh));
214
215 /* Routines from usb.c */
216 int usb_bus_count __P((void));
217 void usb_needs_explore __P((usbd_bus_handle));
218
219 /* Locator stuff. */
220
221 #if defined(__NetBSD__)
222 #include "locators.h"
223 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
224 /* XXX these values are used to statically bind some elements in the USB tree
225 * to specific driver instances. This should be somehow emulated in FreeBSD
226 * but can be done later on.
227 * The values are copied from the files.usb file in the NetBSD sources.
228 */
229 #define UHUBCF_PORT_DEFAULT -1
230 #define UHUBCF_CONFIGURATION_DEFAULT -1
231 #define UHUBCF_INTERFACE_DEFAULT -1
232 #define UHUBCF_VENDOR_DEFAULT -1
233 #define UHUBCF_PRODUCT_DEFAULT -1
234 #define UHUBCF_RELEASE_DEFAULT -1
235 #endif
236
237 #if defined (__OpenBSD__)
238 #define UHUBCF_PORT 0
239 #define UHUBCF_CONFIGURATION 1
240 #define UHUBCF_INTERFACE 2
241 #define UHUBCF_VENDOR 3
242 #define UHUBCF_PRODUCT 4
243 #define UHUBCF_RELEASE 5
244 #endif
245
246 #define uhubcf_port cf_loc[UHUBCF_PORT]
247 #define uhubcf_configuration cf_loc[UHUBCF_CONFIGURATION]
248 #define uhubcf_interface cf_loc[UHUBCF_INTERFACE]
249 #define uhubcf_vendor cf_loc[UHUBCF_VENDOR]
250 #define uhubcf_product cf_loc[UHUBCF_PRODUCT]
251 #define uhubcf_release cf_loc[UHUBCF_RELEASE]
252 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
253 #define UHUB_UNK_CONFIGURATION UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
254 #define UHUB_UNK_INTERFACE UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
255 #define UHUB_UNK_VENDOR UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
256 #define UHUB_UNK_PRODUCT UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
257 #define UHUB_UNK_RELEASE UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
258
259