]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/usb/usbdivar.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / usb / usbdivar.h
1 /*      $NetBSD: usbdivar.h,v 1.70 2002/07/11 21:14:36 augustss Exp $   */
2 /*      $FreeBSD$       */
3
4 /*-
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Lennart Augustsson (lennart@augustsson.net) at
10  * Carlstedt Research & Technology.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *        This product includes software developed by the NetBSD
23  *        Foundation, Inc. and its contributors.
24  * 4. Neither the name of The NetBSD Foundation nor the names of its
25  *    contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40
41 /* From usb_mem.h */
42 struct usb_dma_block;
43 typedef struct {
44         struct usb_dma_block *block;
45         u_int offs;
46         u_int len;
47 } usb_dma_t;
48
49 struct usbd_xfer;
50 struct usbd_pipe;
51
52 struct usbd_endpoint {
53         usb_endpoint_descriptor_t *edesc;
54         int                     refcnt;
55         int                     savedtoggle;
56 };
57
58 struct usbd_bus_methods {
59         usbd_status           (*open_pipe)(struct usbd_pipe *pipe);
60         void                  (*soft_intr)(void *);
61         void                  (*do_poll)(struct usbd_bus *);
62         usbd_status           (*allocm)(struct usbd_bus *, usb_dma_t *,
63                                         u_int32_t bufsize);
64         void                  (*freem)(struct usbd_bus *, usb_dma_t *);
65         struct usbd_xfer *    (*allocx)(struct usbd_bus *);
66         void                  (*freex)(struct usbd_bus *, struct usbd_xfer *);
67 };
68
69 struct usbd_pipe_methods {
70         usbd_status           (*transfer)(usbd_xfer_handle xfer);
71         usbd_status           (*start)(usbd_xfer_handle xfer);
72         void                  (*abort)(usbd_xfer_handle xfer);
73         void                  (*close)(usbd_pipe_handle pipe);
74         void                  (*cleartoggle)(usbd_pipe_handle pipe);
75         void                  (*done)(usbd_xfer_handle xfer);
76 };
77
78 struct usbd_tt {
79         struct usbd_hub         *hub;
80 };
81
82 struct usbd_port {
83         usb_port_status_t       status;
84         u_int16_t               power;  /* mA of current on port */
85         u_int8_t                portno;
86         u_int8_t                restartcnt;
87 #define USBD_RESTART_MAX 5
88         struct usbd_device     *device; /* Connected device */
89         struct usbd_device     *parent; /* The ports hub */
90         struct usbd_tt         *tt; /* Transaction translator (if any) */
91 };
92
93 struct usbd_hub {
94         usbd_status           (*explore)(usbd_device_handle hub);
95         void                   *hubsoftc;
96         usb_hub_descriptor_t    hubdesc;
97         struct usbd_port        ports[1];
98 };
99
100 struct usb_softc;
101
102 /*****/
103
104 struct usbd_bus {
105         /* Filled by HC driver */
106         device_t                bdev; /* base device, host adapter */
107         struct usbd_bus_methods *methods;
108         u_int32_t               pipe_size; /* size of a pipe struct */
109         /* Filled by usb driver */
110         struct usbd_device     *root_hub;
111         usbd_device_handle      devices[USB_MAX_DEVICES];
112         char                    needs_explore;/* a hub a signalled a change */
113         char                    use_polling;
114         struct usb_softc       *usbctl;
115         struct usb_device_stats stats;
116         int                     intr_context;
117         u_int                   no_intrs;
118         int                     usbrev; /* USB revision */
119 #define USBREV_UNKNOWN  0
120 #define USBREV_PRE_1_0  1
121 #define USBREV_1_0      2
122 #define USBREV_1_1      3
123 #define USBREV_2_0      4
124 #define USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0" }
125
126 #ifdef USB_USE_SOFTINTR
127 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
128         void                   *soft; /* soft interrupt cookie */
129 #else
130         struct callout          softi;
131 #endif
132 #endif
133
134         bus_dma_tag_t           parent_dmatag;  /* Base DMA tag */
135         bus_dma_tag_t           buffer_dmatag;  /* Tag for transfer buffers */
136 };
137
138 struct usbd_device {
139         struct usbd_bus        *bus;           /* our controller */
140         struct usbd_pipe       *default_pipe;  /* pipe 0 */
141         u_int8_t                address;       /* device addess */
142         u_int8_t                config;        /* current configuration # */
143         u_int8_t                depth;         /* distance from root hub */
144         u_int8_t                speed;         /* low/full/high speed */
145         u_int8_t                self_powered;  /* flag for self powered */
146         u_int16_t               power;         /* mA the device uses */
147         int16_t                 langid;        /* language for strings */
148 #define USBD_NOLANG (-1)
149         usb_event_cookie_t      cookie;        /* unique connection id */
150         struct usbd_port       *powersrc;      /* upstream hub port, or 0 */
151         struct usbd_device     *myhub;         /* upstream hub */
152         struct usbd_port       *myhsport;      /* closest high speed port */
153         struct usbd_endpoint    def_ep;        /* for pipe 0 */
154         usb_endpoint_descriptor_t def_ep_desc; /* for pipe 0 */
155         struct usbd_interface  *ifaces;        /* array of all interfaces */
156         usb_device_descriptor_t ddesc;         /* device descriptor */
157         usb_config_descriptor_t *cdesc;        /* full config descr */
158         const struct usbd_quirks     *quirks;  /* device quirks, always set */
159         struct usbd_hub        *hub;           /* only if this is a hub */
160         device_t               *subdevs;       /* sub-devices, 0 terminated */
161         uint8_t                *ifacenums;     /* sub-device interfacenumbers */
162 };
163
164 struct usbd_interface {
165         struct usbd_device     *device;
166         usb_interface_descriptor_t *idesc;
167         int                     index;
168         int                     altindex;
169         struct usbd_endpoint   *endpoints;
170         void                   *priv;
171         LIST_HEAD(, usbd_pipe)  pipes;
172 };
173
174 struct usbd_pipe {
175         struct usbd_interface  *iface;
176         struct usbd_device     *device;
177         struct usbd_endpoint   *endpoint;
178         int                     refcnt;
179         char                    running;
180         char                    aborting;
181         STAILQ_HEAD(, usbd_xfer) queue;
182         LIST_ENTRY(usbd_pipe)   next;
183
184         usbd_xfer_handle        intrxfer; /* used for repeating requests */
185         char                    repeat;
186         int                     interval;
187
188         /* Filled by HC driver. */
189         struct usbd_pipe_methods *methods;
190 };
191
192 #define USB_DMA_NSEG (btoc(MAXPHYS) + 1)
193
194 /* DMA-capable memory buffer. */
195 struct usb_dma_mapping {
196         bus_dma_segment_t segs[USB_DMA_NSEG];   /* The physical segments. */
197         int nsegs;                              /* Number of segments. */
198         bus_dmamap_t map;                       /* DMA mapping. */
199 };
200
201 struct usbd_xfer {
202         struct usbd_pipe       *pipe;
203         void                   *priv;
204         void                   *buffer;
205         u_int32_t               length;
206         u_int32_t               actlen;
207         u_int16_t               flags;
208         u_int32_t               timeout;
209         usbd_status             status;
210         usbd_callback           callback;
211         __volatile char         done;
212 #ifdef DIAGNOSTIC
213         u_int32_t               busy_free;
214 #define XFER_FREE 0x46524545
215 #define XFER_BUSY 0x42555359
216 #define XFER_ONQU 0x4f4e5155
217 #endif
218
219         /* For control pipe */
220         usb_device_request_t    request;
221
222         /* For isoc */
223         u_int16_t               *frlengths;
224         int                     nframes;
225
226         /* For memory allocation */
227         struct usbd_device     *device;
228         struct usb_dma_mapping  dmamap;
229         void                    *allocbuf;
230
231         int                     rqflags;
232 #define URQ_REQUEST     0x01
233 #define URQ_AUTO_DMABUF 0x10
234 #define URQ_DEV_DMABUF  0x20
235
236         STAILQ_ENTRY(usbd_xfer) next;
237
238         void                   *hcpriv; /* private use by the HC driver */
239
240         struct callout          timeout_handle;
241 };
242
243 void usbd_init(void);
244 void usbd_finish(void);
245
246 #ifdef USB_DEBUG
247 void usbd_dump_iface(struct usbd_interface *iface);
248 void usbd_dump_device(struct usbd_device *dev);
249 void usbd_dump_endpoint(struct usbd_endpoint *endp);
250 void usbd_dump_queue(usbd_pipe_handle pipe);
251 void usbd_dump_pipe(usbd_pipe_handle pipe);
252 #endif
253
254 /* Routines from usb_subr.c */
255 int             usbctlprint(void *, const char *);
256 void            usb_delay_ms(usbd_bus_handle, u_int);
257 usbd_status     usbd_reset_port(usbd_device_handle dev,
258                                 int port, usb_port_status_t *ps);
259 usbd_status     usbd_setup_pipe(usbd_device_handle dev,
260                                 usbd_interface_handle iface,
261                                 struct usbd_endpoint *, int,
262                                 usbd_pipe_handle *pipe);
263 usbd_status     usbd_new_device(device_t parent,
264                                 usbd_bus_handle bus, int depth,
265                                 int lowspeed, int port,
266                                 struct usbd_port *);
267 void            usbd_remove_device(usbd_device_handle, struct usbd_port *);
268 int             usbd_printBCD(char *cp, int bcd);
269 usbd_status     usbd_fill_iface_data(usbd_device_handle dev, int i, int a);
270 void            usb_free_device(usbd_device_handle);
271
272 usbd_status     usb_insert_transfer(usbd_xfer_handle xfer);
273 void            usb_transfer_complete(usbd_xfer_handle xfer);
274 void            usb_disconnect_port(struct usbd_port *up, device_t);
275
276 /* Routines from usb.c */
277 void            usb_needs_explore(usbd_device_handle);
278 void            usb_schedsoftintr(struct usbd_bus *);
279
280 /*
281  * XXX This check is extremely bogus. Bad Bad Bad.
282  */
283 #if defined(DIAGNOSTIC) && 0
284 #define SPLUSBCHECK \
285         do { int _s = splusb(), _su = splusb(); \
286              if (!cold && _s != _su) printf("SPLUSBCHECK failed 0x%x!=0x%x, %s:%d\n", \
287                                    _s, _su, __FILE__, __LINE__); \
288              splx(_s); \
289         } while (0)
290 #else
291 #define SPLUSBCHECK
292 #endif
293
294 /* Locator stuff. */
295
296 /* XXX these values are used to statically bind some elements in the USB tree
297  * to specific driver instances. This should be somehow emulated in FreeBSD
298  * but can be done later on.
299  * The values are copied from the files.usb file in the NetBSD sources.
300  */
301 #define UHUBCF_PORT_DEFAULT -1
302 #define UHUBCF_CONFIGURATION_DEFAULT -1
303 #define UHUBCF_INTERFACE_DEFAULT -1
304 #define UHUBCF_VENDOR_DEFAULT -1
305 #define UHUBCF_PRODUCT_DEFAULT -1
306 #define UHUBCF_RELEASE_DEFAULT -1
307
308 #define uhubcf_port             cf_loc[UHUBCF_PORT]
309 #define uhubcf_configuration    cf_loc[UHUBCF_CONFIGURATION]
310 #define uhubcf_interface        cf_loc[UHUBCF_INTERFACE]
311 #define uhubcf_vendor           cf_loc[UHUBCF_VENDOR]
312 #define uhubcf_product          cf_loc[UHUBCF_PRODUCT]
313 #define uhubcf_release          cf_loc[UHUBCF_RELEASE]
314 #define UHUB_UNK_PORT           UHUBCF_PORT_DEFAULT /* wildcarded 'port' */
315 #define UHUB_UNK_CONFIGURATION  UHUBCF_CONFIGURATION_DEFAULT /* wildcarded 'configuration' */
316 #define UHUB_UNK_INTERFACE      UHUBCF_INTERFACE_DEFAULT /* wildcarded 'interface' */
317 #define UHUB_UNK_VENDOR         UHUBCF_VENDOR_DEFAULT /* wildcarded 'vendor' */
318 #define UHUB_UNK_PRODUCT        UHUBCF_PRODUCT_DEFAULT /* wildcarded 'product' */
319 #define UHUB_UNK_RELEASE        UHUBCF_RELEASE_DEFAULT /* wildcarded 'release' */
320