Merge from vendor branch SENDMAIL:
[dragonfly.git] / sys / bus / usb / usb_port.h
1 /*
2  * $OpenBSD: usb_port.h,v 1.18 2000/09/06 22:42:10 rahnds Exp $
3  * $NetBSD: usb_port.h,v 1.68 2005/07/30 06:14:50 skrll Exp $
4  * $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.65 2003/11/09 23:54:21 joe Exp $
5  * $DragonFly: src/sys/bus/usb/usb_port.h,v 1.14 2005/11/28 17:13:23 dillon Exp $
6  */
7
8 /* Also already merged from NetBSD:
9  *      $NetBSD: usb_port.h,v 1.57 2002/09/27 20:42:01 thorpej Exp $
10  *      $NetBSD: usb_port.h,v 1.58 2002/10/01 01:25:26 thorpej Exp $
11  */
12
13 /*
14  * Copyright (c) 1998 The NetBSD Foundation, Inc.
15  * All rights reserved.
16  *
17  * This code is derived from software contributed to The NetBSD Foundation
18  * by Lennart Augustsson (lennart@augustsson.net) at
19  * Carlstedt Research & Technology.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  * 3. All advertising materials mentioning features or use of this software
30  *    must display the following acknowledgement:
31  *        This product includes software developed by the NetBSD
32  *        Foundation, Inc. and its contributors.
33  * 4. Neither the name of The NetBSD Foundation nor the names of its
34  *    contributors may be used to endorse or promote products derived
35  *    from this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
38  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
39  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
41  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47  * POSSIBILITY OF SUCH DAMAGE.
48  */
49
50 #ifndef _USB_PORT_H
51 #define _USB_PORT_H
52
53 /*
54  * Macro's to cope with the differences between operating systems.
55  */
56
57 #if defined(__NetBSD__)
58 /*
59  * NetBSD
60  */
61
62 #include "opt_usbverbose.h"
63
64 #if defined(_KERNEL)
65 #include <sys/mallocvar.h>
66
67 MALLOC_DECLARE(M_USB);
68 MALLOC_DECLARE(M_USBDEV);
69 MALLOC_DECLARE(M_USBHC);
70
71 #endif
72
73 #define USB_USE_SOFTINTR
74
75 #ifdef USB_DEBUG
76 #define Static
77 #else
78 #define Static static
79 #endif
80
81 #define SCSI_MODE_SENSE         MODE_SENSE
82
83 typedef struct proc *usb_proc_ptr;
84
85 typedef struct device *device_ptr_t;
86 #define USBBASEDEVICE struct device
87 #define USBDEV(bdev) (&(bdev))
88 #define USBDEVNAME(bdev) ((bdev).dv_xname)
89 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
90 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
91 #define USBGETSOFTC(d) ((void *)(d))
92
93 #define DECLARE_USB_DMA_T \
94         struct usb_dma_block; \
95         typedef struct { \
96                 struct usb_dma_block *block; \
97                 u_int offs; \
98         } usb_dma_t
99
100 typedef struct callout usb_callout_t;
101 #define usb_callout_init(h)     callout_init(&(h))
102 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
103 #define usb_uncallout(h, f, d)  callout_stop(&(h))
104
105 #define usb_kthread_create1     kthread_create1
106 #define usb_kthread_create      kthread_create
107
108 typedef struct malloc_type *usb_malloc_type;
109
110 #define Ether_ifattach ether_ifattach
111
112 #define logprintf printf
113
114 #define USB_DNAME(dname)        dname
115 #define USB_DECLARE_DRIVER(dname)  \
116 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
117 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
118 int __CONCAT(dname,_detach)(struct device *, int); \
119 int __CONCAT(dname,_activate)(struct device *, enum devact); \
120 \
121 extern struct cfdriver __CONCAT(dname,_cd); \
122 \
123 CFATTACH_DECL(USB_DNAME(dname), \
124     sizeof(struct ___CONCAT(dname,_softc)), \
125     ___CONCAT(dname,_match), \
126     ___CONCAT(dname,_attach), \
127     ___CONCAT(dname,_detach), \
128     ___CONCAT(dname,_activate))
129
130 #define USB_MATCH(dname) \
131 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
132
133 #define USB_MATCH_START(dname, uaa) \
134         struct usb_attach_arg *uaa = aux
135
136 #define USB_ATTACH(dname) \
137 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
138
139 #define USB_ATTACH_START(dname, sc, uaa) \
140         struct __CONCAT(dname,_softc) *sc = \
141                 (struct __CONCAT(dname,_softc) *)self; \
142         struct usb_attach_arg *uaa = aux
143
144 /* Returns from attach */
145 #define USB_ATTACH_ERROR_RETURN return
146 #define USB_ATTACH_SUCCESS_RETURN       return
147
148 #define USB_ATTACH_SETUP printf("\n")
149
150 #define USB_DETACH(dname) \
151 int __CONCAT(dname,_detach)(struct device *self, int flags)
152
153 #define USB_DETACH_START(dname, sc) \
154         struct __CONCAT(dname,_softc) *sc = \
155                 (struct __CONCAT(dname,_softc) *)self
156
157 #define USB_GET_SC_OPEN(dname, unit, sc) \
158         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
159                 return (ENXIO); \
160         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
161         if (sc == NULL) \
162                 return (ENXIO)
163
164 #define USB_GET_SC(dname, unit, sc) \
165         sc = __CONCAT(dname,_cd).cd_devs[unit]
166
167 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
168         (config_found_sm_loc(parent, (args)->port == 0 ? "usb" : "uhub", \
169                              NULL, args, print, sub))
170
171 #elif defined(__OpenBSD__)
172 /*
173  * OpenBSD
174  */
175 #define Static
176
177 typedef struct proc *usb_proc_ptr;
178
179 #define UCOMBUSCF_PORTNO                -1
180 #define UCOMBUSCF_PORTNO_DEFAULT        -1
181
182 #define SCSI_MODE_SENSE         MODE_SENSE
183 #define XS_STS_DONE             ITSDONE
184 #define XS_CTL_POLL             SCSI_POLL
185 #define XS_CTL_DATA_IN          SCSI_DATA_IN
186 #define XS_CTL_DATA_OUT         SCSI_DATA_OUT
187 #define scsipi_adapter          scsi_adapter
188 #define scsipi_cmd              scsi_cmd
189 #define scsipi_device           scsi_device
190 #define scsipi_done             scsi_done
191 #define scsipi_link             scsi_link
192 #define scsipi_minphys          scsi_minphys
193 #define scsipi_sense            scsi_sense
194 #define scsipi_xfer             scsi_xfer
195 #define xs_control              flags
196 #define xs_status               status
197
198 #define memcpy(d, s, l)         bcopy((s),(d),(l))
199 #define memset(d, v, l)         bzero((d),(l))
200 #define bswap32(x)              swap32(x)
201 #define bswap16(x)              swap16(x)
202
203 /*
204  * The UHCI/OHCI controllers are little endian, so on big endian machines
205  * the data strored in memory needs to be swapped.
206  */
207
208 #if defined(letoh32)
209 #define le32toh(x) letoh32(x)
210 #define le16toh(x) letoh16(x)
211 #endif
212
213 #define usb_kthread_create1     kthread_create
214 #define usb_kthread_create      kthread_create_deferred
215
216 #define usb_lockmgr(lk, mode, ptr) lockmgr(lk, mode, ptr, curproc)
217
218 #define config_pending_incr()
219 #define config_pending_decr()
220
221 typedef int usb_malloc_type;
222
223 #define Ether_ifattach ether_ifattach
224 #define if_deactivate(x)
225
226 #define usbpoll                 usbselect
227 #define uhidpoll                uhidselect
228 #define ugenpoll                ugenselect
229 #define uscannerpoll            uscannerselect
230
231 #define powerhook_establish(fn, sc) (fn)
232 #define powerhook_disestablish(hdl)
233 #define PWR_RESUME 0
234
235 #define logprintf printf
236
237 #define swap_bytes_change_sign16_le swap_bytes_change_sign16
238 #define change_sign16_swap_bytes_le change_sign16_swap_bytes
239 #define change_sign16_le change_sign16
240
241 #define realloc usb_realloc
242 void *usb_realloc(void *, u_int, int, int);
243
244 extern int cold;
245
246 typedef struct device *device_ptr_t;
247 #define USBBASEDEVICE struct device
248 #define USBDEV(bdev) (&(bdev))
249 #define USBDEVNAME(bdev) ((bdev).dv_xname)
250 #define USBDEVUNIT(bdev) ((bdev).dv_unit)
251 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
252 #define USBGETSOFTC(d) ((void *)(d))
253
254 #define DECLARE_USB_DMA_T \
255         struct usb_dma_block; \
256         typedef struct { \
257                 struct usb_dma_block *block; \
258                 u_int offs; \
259         } usb_dma_t
260
261 typedef char usb_callout_t;
262 #define usb_callout_init(h)
263 #define usb_callout(h, t, f, d) timeout((f), (d), (t))
264 #define usb_uncallout(h, f, d) untimeout((f), (d))
265
266 #define USB_DECLARE_DRIVER(dname)  \
267 int __CONCAT(dname,_match)(struct device *, void *, void *); \
268 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
269 int __CONCAT(dname,_detach)(struct device *, int); \
270 int __CONCAT(dname,_activate)(struct device *, enum devact); \
271 \
272 struct cfdriver __CONCAT(dname,_cd) = { \
273         NULL, #dname, DV_DULL \
274 }; \
275 \
276 const struct cfattach __CONCAT(dname,_ca) = { \
277         sizeof(struct __CONCAT(dname,_softc)), \
278         __CONCAT(dname,_match), \
279         __CONCAT(dname,_attach), \
280         __CONCAT(dname,_detach), \
281         __CONCAT(dname,_activate), \
282 }
283
284 #define USB_MATCH(dname) \
285 int \
286 __CONCAT(dname,_match)(parent, match, aux) \
287         struct device *parent; \
288         void *match; \
289         void *aux;
290
291 #define USB_MATCH_START(dname, uaa) \
292         struct usb_attach_arg *uaa = aux
293
294 #define USB_ATTACH(dname) \
295 void \
296 __CONCAT(dname,_attach)(parent, self, aux) \
297         struct device *parent; \
298         struct device *self; \
299         void *aux;
300
301 #define USB_ATTACH_START(dname, sc, uaa) \
302         struct __CONCAT(dname,_softc) *sc = \
303                 (struct __CONCAT(dname,_softc) *)self; \
304         struct usb_attach_arg *uaa = aux
305
306 /* Returns from attach */
307 #define USB_ATTACH_ERROR_RETURN return
308 #define USB_ATTACH_SUCCESS_RETURN       return
309
310 #define USB_ATTACH_SETUP printf("\n")
311
312 #define USB_DETACH(dname) \
313 int \
314 __CONCAT(dname,_detach)(self, flags) \
315         struct device *self; \
316         int flags;
317
318 #define USB_DETACH_START(dname, sc) \
319         struct __CONCAT(dname,_softc) *sc = \
320                 (struct __CONCAT(dname,_softc) *)self
321
322 #define USB_GET_SC_OPEN(dname, unit, sc) \
323         if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
324                 return (ENXIO); \
325         sc = __CONCAT(dname,_cd).cd_devs[unit]; \
326         if (sc == NULL) \
327                 return (ENXIO)
328
329 #define USB_GET_SC(dname, unit, sc) \
330         sc = __CONCAT(dname,_cd).cd_devs[unit]
331
332 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
333         (config_found_sm(parent, args, print, sub))
334
335 #elif defined(__DragonFly__)
336 /***************************************************************************
337  *                                      DRAGONFLY
338  */
339 #include "opt_usb.h"
340
341 #if defined(_KERNEL)
342 #include <sys/malloc.h>
343
344 MALLOC_DECLARE(M_USB);
345 MALLOC_DECLARE(M_USBDEV);
346 MALLOC_DECLARE(M_USBHC);
347
348 #endif
349
350 #define USBVERBOSE
351
352 /* We don't use the soft interrupt code in FreeBSD. */
353 /* #undef USB_USE_SOFTINTR */
354
355 #define Static static
356
357 #define device_ptr_t device_t
358 #define USBBASEDEVICE device_t
359 #define USBDEV(bdev) (bdev)
360 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
361 #define USBDEVUNIT(bdev) device_get_unit(bdev)
362 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
363 #define USBDEVUNIT(bdev) device_get_unit(bdev)
364 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
365
366 #define DECLARE_USB_DMA_T \
367         struct usb_dma_block; \
368         typedef struct { \
369                 struct usb_dma_block *block; \
370                 u_int offs; \
371                 u_int len; \
372         } usb_dma_t
373
374 #define PROC_LOCK(p)
375 #define PROC_UNLOCK(p)
376 #define uio_procp uio_td
377
378 #define selwakeuppri(p, pri)    selwakeup(p)
379
380 typedef struct thread *usb_proc_ptr;
381
382 /* XXX Change this when FreeBSD has memset */
383 #define memcpy(d, s, l)         bcopy((s),(d),(l))
384 #define memset(d, v, l)         bzero((d),(l))
385
386 #define config_pending_incr()
387 #define config_pending_decr()
388
389 #define usb_kthread_create(f, s)                        \
390                 kthread_create(f, s, NULL, "dummy")
391 #define usb_kthread_create1(f, s, p, name, arg)         \
392                 kthread_create(f, s, p, name, arg)
393 #define usb_kthread_create2(f, s, p, name)              \
394                 kthread_create(f, s, p, name)
395
396 typedef struct callout usb_callout_t;
397 #define usb_callout_init(h)     callout_init(&(h))
398 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
399 #define usb_uncallout(h, f, d)  callout_stop(&(h))
400
401 #define usb_lockmgr lockmgr
402
403 #define ETHER_ALIGN             2
404
405 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
406 #define clfree(p) clist_free_cblocks((p))
407
408 #define PWR_RESUME 0
409 #define PWR_SUSPEND 1
410
411 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
412
413 typedef struct malloc_type *usb_malloc_type;
414
415 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
416 Static device_probe_t __CONCAT(dname,_match); \
417 Static device_attach_t __CONCAT(dname,_attach); \
418 Static device_detach_t __CONCAT(dname,_detach); \
419 \
420 Static devclass_t __CONCAT(dname,_devclass); \
421 \
422 Static device_method_t __CONCAT(dname,_methods)[] = { \
423         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
424         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
425         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
426         init, \
427         {0,0} \
428 }; \
429 \
430 Static driver_t __CONCAT(dname,_driver) = { \
431         #dname, \
432         __CONCAT(dname,_methods), \
433         sizeof(struct __CONCAT(dname,_softc)) \
434 }; \
435 MODULE_DEPEND(dname, usb, 1, 1, 1)
436
437
438 #define METHODS_NONE                    {0,0}
439 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
440
441 #define USB_MATCH(dname) \
442 Static int \
443 __CONCAT(dname,_match)(device_t self)
444
445 #define USB_MATCH_START(dname, uaa) \
446         struct usb_attach_arg *uaa = device_get_ivars(self)
447
448 #define USB_MATCH_SETUP \
449         sc->sc_dev = self
450
451 #define USB_ATTACH(dname) \
452 Static int \
453 __CONCAT(dname,_attach)(device_t self)
454
455 #define USB_ATTACH_START(dname, sc, uaa) \
456         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
457         struct usb_attach_arg *uaa = device_get_ivars(self)
458
459 /* Returns from attach */
460 #define USB_ATTACH_ERROR_RETURN return ENXIO
461 #define USB_ATTACH_SUCCESS_RETURN       return 0
462
463 #define USB_ATTACH_SETUP \
464         sc->sc_dev = self; \
465         device_set_desc_copy(self, devinfo)
466
467 #define USB_DETACH(dname) \
468 Static int \
469 __CONCAT(dname,_detach)(device_t self)
470
471 #define USB_DETACH_START(dname, sc) \
472         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
473
474 #define USB_GET_SC_OPEN(dname, unit, sc) \
475         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
476         if (sc == NULL) \
477                 return (ENXIO)
478
479 #define USB_GET_SC(dname, unit, sc) \
480         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
481
482 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
483         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
484
485 /* conversion from one type of queue to the other */
486 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
487 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
488 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
489 #define SIMPLEQ_NEXT            STAILQ_NEXT
490 #define SIMPLEQ_FIRST           STAILQ_FIRST
491 #define SIMPLEQ_HEAD            STAILQ_HEAD
492 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
493 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
494 #define SIMPLEQ_INIT            STAILQ_INIT
495 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
496 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
497
498 #include <sys/syslog.h>
499 /*
500 #define logprintf(args...)      log(LOG_DEBUG, args)
501 */
502 #define logprintf               printf
503
504 #ifdef SYSCTL_DECL
505 SYSCTL_DECL(_hw_usb);
506 #endif
507
508 #elif defined(__FreeBSD__) || defined(__DragonFly__)
509 /***************************************************************************
510  *                                      FREEBSD
511  */
512
513 #include "opt_usb.h"
514
515 #if defined(_KERNEL)
516 #include <sys/malloc.h>
517
518 MALLOC_DECLARE(M_USB);
519 MALLOC_DECLARE(M_USBDEV);
520 MALLOC_DECLARE(M_USBHC);
521
522 #endif
523
524 #define USBVERBOSE
525
526 /* We don't use the soft interrupt code in FreeBSD. */
527 #if 0
528 #define USB_USE_SOFTINTR
529 #endif
530
531 #define Static static
532
533 #define device_ptr_t device_t
534 #define USBBASEDEVICE device_t
535 #define USBDEV(bdev) (bdev)
536 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
537 #define USBDEVUNIT(bdev) device_get_unit(bdev)
538 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
539 #define USBDEVUNIT(bdev) device_get_unit(bdev)
540 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
541
542 #define DECLARE_USB_DMA_T \
543         struct usb_dma_block; \
544         typedef struct { \
545                 struct usb_dma_block *block; \
546                 u_int offs; \
547                 u_int len; \
548         } usb_dma_t
549
550 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
551 typedef struct thread *usb_proc_ptr;
552
553 #define uio_procp uio_td
554
555 #define usb_kthread_create1(f, s, p, a0, a1) \
556                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0), (a1))
557 #define usb_kthread_create2(f, s, p, a0) \
558                 kthread_create((f), (s), (p), RFHIGHPID, 0, (a0))
559 #define usb_kthread_create      kthread_create
560
561 #define config_pending_incr()
562 #define config_pending_decr()
563
564 typedef struct callout usb_callout_t;
565 #define usb_callout_init(h)     callout_init(&(h), 0)
566 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
567 #define usb_uncallout(h, f, d)  callout_stop(&(h))
568 #else
569 typedef struct proc *usb_proc_ptr;
570
571 #define PROC_LOCK(p)
572 #define PROC_UNLOCK(p)
573
574 #define usb_kthread_create1(f, s, p, a0, a1) \
575                 kthread_create((f), (s), (p), (a0), (a1))
576 #define usb_kthread_create2(f, s, p, a0) \
577                 kthread_create((f), (s), (p), (a0))
578 #define usb_kthread_create      kthread_create
579
580 #define config_pending_incr()
581 #define config_pending_decr()
582
583 typedef struct callout usb_callout_t;
584 #define usb_callout_init(h)     callout_init(&(h))
585 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
586 #define usb_uncallout(h, f, d)  callout_stop(&(h))
587 #endif
588
589 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
590 #define clfree(p) clist_free_cblocks((p))
591
592 #define PWR_RESUME 0
593 #define PWR_SUSPEND 1
594
595 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev)
596
597 typedef struct malloc_type *usb_malloc_type;
598
599 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
600 Static device_probe_t __CONCAT(dname,_match); \
601 Static device_attach_t __CONCAT(dname,_attach); \
602 Static device_detach_t __CONCAT(dname,_detach); \
603 \
604 Static devclass_t __CONCAT(dname,_devclass); \
605 \
606 Static device_method_t __CONCAT(dname,_methods)[] = { \
607         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
608         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
609         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
610         init, \
611         {0,0} \
612 }; \
613 \
614 Static driver_t __CONCAT(dname,_driver) = { \
615         #dname, \
616         __CONCAT(dname,_methods), \
617         sizeof(struct __CONCAT(dname,_softc)) \
618 }; \
619 MODULE_DEPEND(dname, usb, 1, 1, 1)
620
621
622 #define METHODS_NONE                    {0,0}
623 #define USB_DECLARE_DRIVER(dname)       USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
624
625 #define USB_MATCH(dname) \
626 Static int \
627 __CONCAT(dname,_match)(device_t self)
628
629 #define USB_MATCH_START(dname, uaa) \
630         struct usb_attach_arg *uaa = device_get_ivars(self)
631
632 #define USB_MATCH_SETUP \
633         sc->sc_dev = self
634
635 #define USB_ATTACH(dname) \
636 Static int \
637 __CONCAT(dname,_attach)(device_t self)
638
639 #define USB_ATTACH_START(dname, sc, uaa) \
640         struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
641         struct usb_attach_arg *uaa = device_get_ivars(self)
642
643 /* Returns from attach */
644 #define USB_ATTACH_ERROR_RETURN return ENXIO
645 #define USB_ATTACH_SUCCESS_RETURN       return 0
646
647 #define USB_ATTACH_SETUP \
648         sc->sc_dev = self; \
649         device_set_desc_copy(self, devinfo)
650
651 #define USB_DETACH(dname) \
652 Static int \
653 __CONCAT(dname,_detach)(device_t self)
654
655 #define USB_DETACH_START(dname, sc) \
656         struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
657
658 #define USB_GET_SC_OPEN(dname, unit, sc) \
659         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
660         if (sc == NULL) \
661                 return (ENXIO)
662
663 #define USB_GET_SC(dname, unit, sc) \
664         sc = devclass_get_softc(__CONCAT(dname,_devclass), unit)
665
666 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
667         (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0)
668
669 /* conversion from one type of queue to the other */
670 #define SIMPLEQ_REMOVE_HEAD     STAILQ_REMOVE_HEAD
671 #define SIMPLEQ_INSERT_HEAD     STAILQ_INSERT_HEAD
672 #define SIMPLEQ_INSERT_TAIL     STAILQ_INSERT_TAIL
673 #define SIMPLEQ_NEXT            STAILQ_NEXT
674 #define SIMPLEQ_FIRST           STAILQ_FIRST
675 #define SIMPLEQ_HEAD            STAILQ_HEAD
676 #define SIMPLEQ_EMPTY           STAILQ_EMPTY
677 #define SIMPLEQ_FOREACH         STAILQ_FOREACH
678 #define SIMPLEQ_INIT            STAILQ_INIT
679 #define SIMPLEQ_HEAD_INITIALIZER        STAILQ_HEAD_INITIALIZER
680 #define SIMPLEQ_ENTRY           STAILQ_ENTRY
681
682 #include <sys/syslog.h>
683 /*
684 #define logprintf(args...)      log(LOG_DEBUG, args)
685 */
686 #define logprintf               printf
687
688 #ifdef SYSCTL_DECL
689 SYSCTL_DECL(_hw_usb);
690 #endif
691
692 #endif /* __FreeBSD__ */
693
694 #endif /* _USB_PORT_H */
695