usbdivar.h revision 1.5 1 /* $NetBSD: usbdivar.h,v 1.5 1998/07/26 17:42:49 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 struct usb_softc *usbctl;
87 struct usb_device_stats stats;
88 };
89
90 struct usbd_device {
91 struct usbd_bus *bus;
92 usbd_device_state state;
93 struct usbd_pipe *default_pipe;
94 u_int8_t address;
95 u_int8_t depth;
96 u_int8_t lowspeed;
97 u_int16_t power;
98 u_int8_t self_powered;
99 int config;
100 struct usbd_port *powersrc;
101 struct usbd_endpoint def_ep; /* for pipe 0 */
102 usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
103 struct usbd_interface *ifaces;
104 usb_device_descriptor_t ddesc;
105 usb_config_descriptor_t *cdesc; /* full config descr */
106 struct usbd_quirks *quirks;
107 struct usbd_hub *hub; /* only if this is a hub */
108 };
109
110 struct usbd_interface {
111 struct usbd_device *device;
112 usbd_interface_state state;
113 usb_interface_descriptor_t *idesc;
114 struct usbd_endpoint *endpoints;
115 void *priv;
116 LIST_HEAD(, usbd_pipe) pipes;
117 };
118
119 struct usbd_pipe {
120 struct usbd_interface *iface;
121 struct usbd_device *device;
122 struct usbd_endpoint *endpoint;
123 usbd_pipe_state state;
124 int32_t refcnt;
125 char running;
126 SIMPLEQ_HEAD(, usbd_request) queue;
127 LIST_ENTRY(usbd_pipe) next;
128
129 void (*disco) __P((void *));
130 void *discoarg;
131
132 usbd_request_handle intrreqh; /* used for repeating requests */
133 usbd_request_handle curreqh; /* currently running request */
134
135 /* Filled by HC driver. */
136 struct usbd_methods *methods;
137 };
138
139 struct usbd_request {
140 struct usbd_pipe *pipe;
141 void *priv;
142 void *buffer;
143 u_int32_t length;
144 u_int32_t actlen;
145 u_int16_t flags;
146 u_int32_t timeout;
147 usbd_status status;
148 usbd_callback callback;
149 usbd_xfercb xfercb;
150 u_int32_t retries;
151 char done;
152
153 usb_device_request_t request;
154 u_int8_t isreq;
155
156 SIMPLEQ_ENTRY(usbd_request) next;
157
158 void *hcpriv; /* XXX private use by the HC driver */
159 };
160
161 void usbd_init __P((void));
162
163 /* Routines from usb_subr.c */
164 int usbctlprint __P((void *, const char *));
165 void usbd_delay_ms __P((int));
166 void usbd_devinfo_vp __P((usbd_device_handle, char *, char *));
167 usbd_status usbd_set_config_no __P((usbd_device_handle, int));
168 usbd_status usbd_reset_port __P((usbd_device_handle dev,
169 int port, usb_port_status_t *ps));
170 usbd_status usbd_setup_pipe __P((usbd_device_handle dev,
171 usbd_interface_handle iface,
172 struct usbd_endpoint *,
173 usbd_pipe_handle *pipe));
174 usbd_status usbd_new_device __P((struct device *parent,
175 usbd_bus_handle bus, int depth,
176 int lowspeed, int port,
177 struct usbd_port *));
178 int usbd_printBCD __P((char *cp, int bcd));
179
180 /* Routines from usb.c */
181 int usb_bus_count __P((void));
182 usbd_status usb_get_bus_handle __P((int, usbd_bus_handle *));
183 void usb_needs_explore __P((usbd_bus_handle));
184
185 extern int usbd_use_polling;
186
187 /* Locator stuff. */
188
189 #include "locators.h"
190
191 #define uhubcf_port cf_loc[UHUBCF_PORT]
192 #define UHUB_UNK_PORT UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
193
194 /* Junk. */
195
196 /* XXX */
197 #define splusb splbio
198 #define IPL_USB IPL_BIO
199 /* XXX */
200
201