usbdivar.h revision 1.6 1 /* $NetBSD: usbdivar.h,v 1.6 1998/08/01 18:16:20 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Author: Lennart Augustsson <augustss (at) carlstedt.se>
8 * Carlstedt Research & Technology
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 struct usbd_request;
40 struct usbd_pipe;
41
42 struct usbd_endpoint {
43 usb_endpoint_descriptor_t *edesc;
44 usbd_endpoint_state state;
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 void (*abort)__P((usbd_request_handle reqh));
54 void (*close)__P((usbd_pipe_handle pipe));
55 };
56
57 struct usbd_port {
58 usb_port_status_t status;
59 int power; /* mA of current on port */
60 struct usbd_device *device;
61 struct usbd_device *parent; /* The ports hub */
62 };
63
64 struct usbd_hub {
65 usbd_status (*explore)__P((struct device *parent,
66 usbd_device_handle hub));
67 void *hubdata;
68 usb_hub_descriptor_t hubdesc;
69 struct usbd_port ports[1];
70 };
71
72 struct usb_softc;
73
74 /*****/
75
76 struct usbd_bus {
77 /* Filled by HC driver */
78 struct device bdev; /* base device */
79 usbd_status (*open_pipe)__P((struct usbd_pipe *pipe));
80 u_int32_t pipe_size; /* size of a pipe struct */
81 void (*do_poll)__P((struct usbd_bus *));
82 /* Filled by usb driver */
83 struct usbd_device *root_hub;
84 usbd_device_handle devices[USB_MAX_DEVICES];
85 char needs_explore;/* a hub a signalled a change */
86 char use_polling;
87 struct usb_softc *usbctl;
88 struct usb_device_stats stats;
89 };
90
91 struct usbd_device {
92 struct usbd_bus *bus;
93 usbd_device_state state;
94 struct usbd_pipe *default_pipe;
95 u_int8_t address;
96 u_int8_t depth;
97 u_int8_t lowspeed;
98 u_int16_t power;
99 u_int8_t self_powered;
100 int config;
101 struct usbd_port *powersrc;
102 struct usbd_endpoint def_ep; /* for pipe 0 */
103 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
104 struct usbd_interface *ifaces;
105 usb_device_descriptor_t ddesc;
106 usb_config_descriptor_t *cdesc; /* full config descr */
107 struct usbd_quirks *quirks;
108 struct usbd_hub *hub; /* only if this is a hub */
109 };
110
111 struct usbd_interface {
112 struct usbd_device *device;
113 usbd_interface_state state;
114 usb_interface_descriptor_t *idesc;
115 struct usbd_endpoint *endpoints;
116 void *priv;
117 LIST_HEAD(, usbd_pipe) pipes;
118 };
119
120 struct usbd_pipe {
121 struct usbd_interface *iface;
122 struct usbd_device *device;
123 struct usbd_endpoint *endpoint;
124 usbd_pipe_state state;
125 int32_t refcnt;
126 char running;
127 SIMPLEQ_HEAD(, usbd_request) queue;
128 LIST_ENTRY(usbd_pipe) next;
129
130 void (*disco) __P((void *));
131 void *discoarg;
132
133 usbd_request_handle intrreqh; /* used for repeating requests */
134 usbd_request_handle curreqh; /* currently running request */
135
136 /* Filled by HC driver. */
137 struct usbd_methods *methods;
138 };
139
140 struct usbd_request {
141 struct usbd_pipe *pipe;
142 void *priv;
143 void *buffer;
144 u_int32_t length;
145 u_int32_t actlen;
146 u_int16_t flags;
147 u_int32_t timeout;
148 usbd_status status;
149 usbd_callback callback;
150 usbd_xfercb xfercb;
151 u_int32_t retries;
152 char done;
153
154 usb_device_request_t request;
155 u_int8_t isreq;
156
157 SIMPLEQ_ENTRY(usbd_request) next;
158
159 void *hcpriv; /* XXX private use by the HC driver */
160 };
161
162 void usbd_init __P((void));
163
164 /* Routines from usb_subr.c */
165 int usbctlprint __P((void *, const char *));
166 void usbd_delay_ms __P((usbd_bus_handle, int));
167 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
168 usbd_status usbd_set_config_no __P((usbd_device_handle, int));
169 usbd_status usbd_reset_port __P((usbd_device_handle dev,
170 int port, usb_port_status_t *ps));
171 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
172 usbd_interface_handle iface,
173 struct usbd_endpoint *,
174 usbd_pipe_handle *pipe));
175 usbd_status usbd_new_device __P((struct device *parent,
176 usbd_bus_handle bus, int depth,
177 int lowspeed, int port,
178 struct usbd_port *));
179 int usbd_printBCD __P((char *cp, int bcd));
180
181 /* Routines from usb.c */
182 int usb_bus_count __P((void));
183 usbd_status usb_get_bus_handle __P((int, usbd_bus_handle *));
184 void usb_needs_explore __P((usbd_bus_handle));
185
186 extern int usbd_use_polling;
187
188 /* Locator stuff. */
189
190 #include "locators.h"
191
192 #define uhubcf_port cf_loc[UHUBCF_PORT]
193 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
194
195 /* Junk. */
196
197 /* XXX */
198 #define splusb splbio
199 #define IPL_USB IPL_BIO
200 /* XXX */
201
202