usbdivar.h revision 1.11 1 /* $NetBSD: usbdivar.h,v 1.11 1998/12/26 12:53:04 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 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 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 usbd_device_state state;
99 struct usbd_pipe *default_pipe;
100 u_int8_t address;
101 u_int8_t depth;
102 u_int8_t lowspeed;
103 u_int16_t power;
104 u_int8_t self_powered;
105 int config;
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 void *softc; /* device softc if attached */
115 };
116
117 struct usbd_interface {
118 struct usbd_device *device;
119 usbd_interface_state state;
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 usbd_pipe_state state;
133 int32_t refcnt;
134 char running;
135 SIMPLEQ_HEAD(, usbd_request) queue;
136 LIST_ENTRY(usbd_pipe) next;
137
138 void (*disco) __P((void *));
139 void *discoarg;
140
141 usbd_request_handle intrreqh; /* used for repeating requests */
142 usbd_request_handle curreqh; /* currently running request */
143
144 /* Filled by HC driver. */
145 struct usbd_methods *methods;
146 };
147
148 struct usbd_request {
149 struct usbd_pipe *pipe;
150 void *priv;
151 void *buffer;
152 u_int32_t length;
153 u_int32_t actlen;
154 u_int16_t flags;
155 u_int32_t timeout;
156 usbd_status status;
157 usbd_callback callback;
158 usbd_xfercb xfercb;
159 u_int32_t retries;
160 char done;
161
162 usb_device_request_t request;
163 u_int8_t isreq;
164
165 SIMPLEQ_ENTRY(usbd_request) next;
166
167 void *hcpriv; /* XXX private use by the HC driver */
168
169 #if defined(__FreeBSD__)
170 struct callout_handle timo_handle;
171 #endif
172 };
173
174 void usbd_init __P((void));
175
176 /* Routines from usb_subr.c */
177 int usbctlprint __P((void *, const char *));
178 void usbd_delay_ms __P((usbd_bus_handle, int));
179 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
180 usbd_status usbd_set_config_no __P((usbd_device_handle, int, int));
181 usbd_status usbd_reset_port __P((usbd_device_handle dev,
182 int port, usb_port_status_t *ps));
183 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
184 usbd_interface_handle iface,
185 struct usbd_endpoint *,
186 usbd_pipe_handle *pipe));
187 usbd_status usbd_new_device __P((bdevice *parent,
188 usbd_bus_handle bus, int depth,
189 int lowspeed, int port,
190 struct usbd_port *));
191 void usbd_remove_device __P((usbd_device_handle,
192 struct usbd_port *));
193 int usbd_printBCD __P((char *cp, int bcd));
194 usbd_status usbd_fill_iface_data __P((usbd_device_handle dev,
195 int i, int a));
196
197 /* Routines from usb.c */
198 int usb_bus_count __P((void));
199 usbd_status usb_get_bus_handle __P((int, usbd_bus_handle *));
200 void usb_needs_explore __P((usbd_bus_handle));
201
202 #if defined(__FreeBSD__)
203 int usb_driver_load __P((module_t mod, int what, void *arg));
204 void usb_device_set_desc __P((device_t device, char *devinfo));
205 #endif
206
207 extern int usbd_use_polling;
208
209 /* Locator stuff. */
210
211 #if defined(__NetBSD__)
212 #include "locators.h"
213 #endif
214
215 #define uhubcf_port cf_loc[UHUBCF_PORT]
216 #define uhubcf_configuration cf_loc[UHUBCF_CONFIGURATION]
217 #define uhubcf_interface cf_loc[UHUBCF_INTERFACE]
218 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
219 #define UHUB_UNK_CONFIGURATION UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
220 #define UHUB_UNK_INTERFACE UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
221
222