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