[Midnightbsd-cvs] src: dev/usb: merge enhancements

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Nov 29 11:07:33 EST 2008


Log Message:
-----------
merge enhancements

Modified Files:
--------------
    src/sys/dev/usb:
        FILES (r1.1.1.1 -> r1.2)
        dsbr100io.h (r1.1.1.1 -> r1.2)
        ehci.c (r1.2 -> r1.3)
        ehci_pci.c (r1.1.1.2 -> r1.2)
        ehcireg.h (r1.1.1.2 -> r1.2)
        ehcivar.h (r1.1.1.2 -> r1.2)
        hid.c (r1.2 -> r1.3)
        if_auereg.h (r1.1.1.1 -> r1.2)
        if_axe.c (r1.2 -> r1.3)
        if_axereg.h (r1.1.1.1 -> r1.2)
        if_cdce.c (r1.1.1.2 -> r1.2)
        if_cdcereg.h (r1.1.1.2 -> r1.2)
        if_cue.c (r1.1.1.1 -> r1.2)
        if_cuereg.h (r1.1.1.1 -> r1.2)
        if_kue.c (r1.1.1.1 -> r1.2)
        if_kuereg.h (r1.1.1.1 -> r1.2)
        if_rue.c (r1.2 -> r1.3)
        if_ruereg.h (r1.1.1.1 -> r1.2)
        if_udav.c (r1.2 -> r1.3)
        if_udavreg.h (r1.1.1.1 -> r1.2)
        if_uralreg.h (r1.1.1.2 -> r1.2)
        if_uralvar.h (r1.1.1.2 -> r1.2)
        kue_fw.h (r1.1.1.1 -> r1.2)
        ohci_pci.c (r1.1.1.2 -> r1.2)
        ohcireg.h (r1.1.1.1 -> r1.2)
        ohcivar.h (r1.1.1.1 -> r1.2)
        rio500_usb.h (r1.1.1.1 -> r1.2)
        ubsa.c (r1.1.1.1 -> r1.2)
        ubser.c (r1.1.1.2 -> r1.2)
        ucom.c (r1.1.1.1 -> r1.2)
        ucomvar.h (r1.1.1.1 -> r1.2)
        ucycom.c (r1.1.1.1 -> r1.2)
        udbp.c (r1.1.1.1 -> r1.2)
        ufm.c (r1.1.1.1 -> r1.2)
        uftdi.c (r1.1.1.1 -> r1.2)
        ugen.c (r1.1.1.1 -> r1.2)
        ugraphire_rdesc.h (r1.1.1.2 -> r1.2)
        uhci.c (r1.2 -> r1.3)
        uhci_pci.c (r1.1.1.1 -> r1.2)
        uhcivar.h (r1.1.1.1 -> r1.2)
        uhid.c (r1.1.1.2 -> r1.2)
        uhub.c (r1.1.1.2 -> r1.2)
        ulpt.c (r1.1.1.1 -> r1.2)
        umct.c (r1.1.1.1 -> r1.2)
        umodem.c (r1.1.1.1 -> r1.2)
        uplcom.c (r1.1.1.1 -> r1.2)
        urio.c (r1.1.1.1 -> r1.2)
        usb.c (r1.1.1.1 -> r1.2)
        usb.h (r1.1.1.2 -> r1.2)
        usb_ethersubr.c (r1.1.1.1 -> r1.2)
        usb_ethersubr.h (r1.1.1.1 -> r1.2)
        usb_mem.c (r1.1.1.1 -> r1.2)
        usb_mem.h (r1.1.1.1 -> r1.2)
        usb_port.h (r1.1.1.1 -> r1.2)
        usb_quirks.c (r1.1.1.2 -> r1.2)
        usb_quirks.h (r1.1.1.2 -> r1.2)
        usb_subr.c (r1.2 -> r1.3)
        usbdi.c (r1.1.1.1 -> r1.2)
        usbdi.h (r1.1.1.1 -> r1.2)
        usbdi_util.c (r1.1.1.1 -> r1.2)
        usbdi_util.h (r1.1.1.1 -> r1.2)
        uscanner.c (r1.1.1.2 -> r1.2)
        uvisor.c (r1.1.1.1 -> r1.2)
        uvscom.c (r1.1.1.1 -> r1.2)
        uxb360gp_rdesc.h (r1.1.1.1 -> r1.2)

-------------- next part --------------
Index: usb_port.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_port.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usb_port.h -L sys/dev/usb/usb_port.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usb_port.h
+++ sys/dev/usb/usb_port.h
@@ -1,6 +1,6 @@
 /*	$OpenBSD: usb_port.h,v 1.18 2000/09/06 22:42:10 rahnds Exp $ */
 /*	$NetBSD: usb_port.h,v 1.54 2002/03/28 21:49:19 ichiro Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/usb_port.h,v 1.74 2005/01/20 05:03:28 imp Exp $       */
+/*	$FreeBSD: src/sys/dev/usb/usb_port.h,v 1.98 2007/07/06 20:02:37 imp Exp $       */
 
 /* Also already merged from NetBSD:
  *	$NetBSD: usb_port.h,v 1.57 2002/09/27 20:42:01 thorpej Exp $
@@ -51,299 +51,10 @@
  * Macro's to cope with the differences between operating systems.
  */
 
-#if defined(__NetBSD__)
-/*
- * NetBSD
- */
-
-#include "opt_usbverbose.h"
-
-#define USB_USE_SOFTINTR
-
-#ifdef USB_DEBUG
-#define Static
-#else
-#define Static static
-#endif
-
-#define SCSI_MODE_SENSE		MODE_SENSE
-
-typedef struct proc *usb_proc_ptr;
-
-typedef struct device *device_ptr_t;
-#define USBBASEDEVICE struct device
-#define USBDEV(bdev) (&(bdev))
-#define USBDEVNAME(bdev) ((bdev).dv_xname)
-#define USBDEVUNIT(bdev) ((bdev).dv_unit)
-#define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
-#define USBGETSOFTC(d) ((void *)(d))
-
-#define DECLARE_USB_DMA_T \
-	struct usb_dma_block; \
-	typedef struct { \
-		struct usb_dma_block *block; \
-		u_int offs; \
-	} usb_dma_t
-
-typedef struct callout usb_callout_t;
-#define usb_callout_init(h)	callout_init(&(h))
-#define	usb_callout(h, t, f, d)	callout_reset(&(h), (t), (f), (d))
-#define	usb_uncallout(h, f, d)	callout_stop(&(h))
-
-#define usb_kthread_create1	kthread_create1
-#define usb_kthread_create	kthread_create
-
-typedef int usb_malloc_type;
-
-#define Ether_ifattach ether_ifattach
-#define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m))
-
-#define logprintf printf
-
-#define	USB_DNAME(dname)	dname
-#define USB_DECLARE_DRIVER(dname)  \
-int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \
-void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
-int __CONCAT(dname,_detach)(struct device *, int); \
-int __CONCAT(dname,_activate)(struct device *, enum devact); \
-\
-extern struct cfdriver __CONCAT(dname,_cd); \
-\
-CFATTACH_DECL(USB_DNAME(dname), \
-    sizeof(struct ___CONCAT(dname,_softc)), \
-    ___CONCAT(dname,_match), \
-    ___CONCAT(dname,_attach), \
-    ___CONCAT(dname,_detach), \
-    ___CONCAT(dname,_activate))
-
-#define USB_MATCH(dname) \
-int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux)
-
-#define USB_MATCH_START(dname, uaa) \
-	struct usb_attach_arg *uaa = aux
-
-#define USB_ATTACH(dname) \
-void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux)
-
-#define USB_ATTACH_START(dname, sc, uaa) \
-	struct __CONCAT(dname,_softc) *sc = \
-		(struct __CONCAT(dname,_softc) *)self; \
-	struct usb_attach_arg *uaa = aux
-
-/* Returns from attach */
-#define USB_ATTACH_ERROR_RETURN	return
-#define USB_ATTACH_SUCCESS_RETURN	return
-
-#define USB_ATTACH_SETUP
-	printf("\n%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
-
-#define USB_DETACH(dname) \
-int __CONCAT(dname,_detach)(struct device *self, int flags)
-
-#define USB_DETACH_START(dname, sc) \
-	struct __CONCAT(dname,_softc) *sc = \
-		(struct __CONCAT(dname,_softc) *)self
-
-#define USB_GET_SC_OPEN(dname, unit, sc) \
-	if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
-		return (ENXIO); \
-	sc = __CONCAT(dname,_cd).cd_devs[unit]; \
-	if (sc == NULL) \
-		return (ENXIO)
-
-#define USB_GET_SC(dname, unit, sc) \
-	sc = __CONCAT(dname,_cd).cd_devs[unit]
-
-#define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
-	(config_found_sm(parent, args, print, sub))
-
-#elif defined(__OpenBSD__)
-/*
- * OpenBSD
- */
-#define Static
-
-typedef struct proc *usb_proc_ptr;
-
-#define UCOMBUSCF_PORTNO		-1
-#define UCOMBUSCF_PORTNO_DEFAULT	-1
-
-#define SCSI_MODE_SENSE		MODE_SENSE
-#define XS_STS_DONE		ITSDONE
-#define XS_CTL_POLL		SCSI_POLL
-#define XS_CTL_DATA_IN		SCSI_DATA_IN
-#define XS_CTL_DATA_OUT		SCSI_DATA_OUT
-#define scsipi_adapter		scsi_adapter
-#define scsipi_cmd		scsi_cmd
-#define scsipi_device		scsi_device
-#define scsipi_done		scsi_done
-#define scsipi_link		scsi_link
-#define scsipi_minphys		scsi_minphys
-#define scsipi_sense		scsi_sense
-#define scsipi_xfer		scsi_xfer
-#define xs_control		flags
-#define xs_status		status
-
-#define	memcpy(d, s, l)		bcopy((s),(d),(l))
-#define	memset(d, v, l)		bzero((d),(l))
-#define bswap32(x)		swap32(x)
-#define bswap16(x)		swap16(x)
-
-/*
- * The UHCI/OHCI controllers are little endian, so on big endian machines
- * the data strored in memory needs to be swapped.
- */
-
-#if defined(letoh32)
-#define le32toh(x) letoh32(x)
-#define le16toh(x) letoh16(x)
-#endif
-
-#define usb_kthread_create1	kthread_create
-#define usb_kthread_create	kthread_create_deferred
-
-#define	config_pending_incr()
-#define	config_pending_decr()
-
-typedef int usb_malloc_type;
-
-#define Ether_ifattach(ifp, eaddr) ether_ifattach(ifp)
-#define if_deactivate(x)
-#define IF_INPUT(ifp, m) do {						\
-	struct ether_header *eh;					\
-									\
-	eh = mtod(m, struct ether_header *);				\
-	m_adj(m, sizeof(struct ether_header));				\
-	ether_input((ifp), (eh), (m));					\
-} while (0)
-
-#define	usbpoll			usbselect
-#define	uhidpoll		uhidselect
-#define	ugenpoll		ugenselect
-#define	uriopoll		urioselect
-#define uscannerpoll		uscannerselect
-
-#define powerhook_establish(fn, sc) (fn)
-#define powerhook_disestablish(hdl)
-#define PWR_RESUME 0
-
-#define logprintf printf
-
-#define swap_bytes_change_sign16_le swap_bytes_change_sign16
-#define change_sign16_swap_bytes_le change_sign16_swap_bytes
-#define change_sign16_le change_sign16
-
-#define realloc usb_realloc
-void *usb_realloc(void *, u_int, int, int);
-
-extern int cold;
-
-typedef struct device *device_ptr_t;
-#define USBBASEDEVICE struct device
-#define USBDEV(bdev) (&(bdev))
-#define USBDEVNAME(bdev) ((bdev).dv_xname)
-#define USBDEVUNIT(bdev) ((bdev).dv_unit)
-#define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname)
-#define USBGETSOFTC(d) ((void *)(d))
-
-#define DECLARE_USB_DMA_T \
-	struct usb_dma_block; \
-	typedef struct { \
-		struct usb_dma_block *block; \
-		u_int offs; \
-	} usb_dma_t
-
-typedef char usb_callout_t;
-#define usb_callout_init(h)
-#define usb_callout(h, t, f, d) timeout((f), (d), (t))
-#define usb_uncallout(h, f, d) untimeout((f), (d))
-
-#define USB_DECLARE_DRIVER(dname)  \
-int __CONCAT(dname,_match)(struct device *, void *, void *); \
-void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \
-int __CONCAT(dname,_detach)(struct device *, int); \
-int __CONCAT(dname,_activate)(struct device *, enum devact); \
-\
-struct cfdriver __CONCAT(dname,_cd) = { \
-	NULL, #dname, DV_DULL \
-}; \
-\
-const struct cfattach __CONCAT(dname,_ca) = { \
-	sizeof(struct __CONCAT(dname,_softc)), \
-	__CONCAT(dname,_match), \
-	__CONCAT(dname,_attach), \
-	__CONCAT(dname,_detach), \
-	__CONCAT(dname,_activate), \
-}
-
-#define USB_MATCH(dname) \
-int \
-__CONCAT(dname,_match)(parent, match, aux) \
-	struct device *parent; \
-	void *match; \
-	void *aux;
-
-#define USB_MATCH_START(dname, uaa) \
-	struct usb_attach_arg *uaa = aux
-
-#define USB_ATTACH(dname) \
-void \
-__CONCAT(dname,_attach)(parent, self, aux) \
-	struct device *parent; \
-	struct device *self; \
-	void *aux;
-
-#define USB_ATTACH_START(dname, sc, uaa) \
-	struct __CONCAT(dname,_softc) *sc = \
-		(struct __CONCAT(dname,_softc) *)self; \
-	struct usb_attach_arg *uaa = aux
-
-/* Returns from attach */
-#define USB_ATTACH_ERROR_RETURN	return
-#define USB_ATTACH_SUCCESS_RETURN	return
-
-#define USB_ATTACH_SETUP
-	printf("\n%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
-
-#define USB_DETACH(dname) \
-int \
-__CONCAT(dname,_detach)(self, flags) \
-	struct device *self; \
-	int flags;
-
-#define USB_DETACH_START(dname, sc) \
-	struct __CONCAT(dname,_softc) *sc = \
-		(struct __CONCAT(dname,_softc) *)self
-
-#define USB_GET_SC_OPEN(dname, unit, sc) \
-	if (unit >= __CONCAT(dname,_cd).cd_ndevs) \
-		return (ENXIO); \
-	sc = __CONCAT(dname,_cd).cd_devs[unit]; \
-	if (sc == NULL) \
-		return (ENXIO)
-
-#define USB_GET_SC(dname, unit, sc) \
-	sc = __CONCAT(dname,_cd).cd_devs[unit]
-
-#define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \
-	(config_found_sm(parent, args, print, sub))
-
-#elif defined(__FreeBSD__)
 /*
  * FreeBSD
  */
 
-#include "opt_usb.h"
-
-#if defined(_KERNEL)
-#include <sys/malloc.h>
-
-MALLOC_DECLARE(M_USB);
-MALLOC_DECLARE(M_USBDEV);
-MALLOC_DECLARE(M_USBHC);
-
-#endif
-
 /* We don't use the soft interrupt code in FreeBSD. */
 #if 0
 #define USB_USE_SOFTINTR
@@ -355,7 +66,6 @@
 #define USBBASEDEVICE device_t
 #define USBDEV(bdev) (bdev)
 #define USBDEVNAME(bdev) device_get_nameunit(bdev)
-#define USBDEVUNIT(bdev) device_get_unit(bdev)
 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
 #define USBDEVUNIT(bdev) device_get_unit(bdev)
 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
@@ -368,7 +78,6 @@
 		u_int len; \
 	} usb_dma_t
 
-#if __FreeBSD_version >= 500000
 typedef struct thread *usb_proc_ptr;
 
 #define uio_procp uio_td
@@ -387,37 +96,10 @@
 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
 #define usb_uncallout(h, f, d)  callout_stop(&(h))
 #define usb_uncallout_drain(h, f, d)  callout_drain(&(h))
-#else
-typedef struct proc *usb_proc_ptr;
-
-#define	PROC_LOCK(p)
-#define	PROC_UNLOCK(p)
-
-#define usb_kthread_create1(f, s, p, a0, a1) \
-		kthread_create((f), (s), (p), (a0), (a1))
-#define usb_kthread_create2(f, s, p, a0) \
-		kthread_create((f), (s), (p), (a0))
-#define usb_kthread_create	kthread_create
-
-#define	config_pending_incr()
-#define	config_pending_decr()
-
-typedef struct callout usb_callout_t;
-#define usb_callout_init(h)     callout_init(&(h))
-#define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
-#define usb_uncallout(h, f, d)  callout_stop(&(h))
-
-#define	BUS_DMA_COHERENT	0
-#define	ETHER_ALIGN		2
-#define	BPF_MTAP(ifp, m)	if ((ifp)->if_bpf) bpf_mtap((ifp), (m));
-#endif
 
 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
 #define clfree(p) clist_free_cblocks((p))
 
-#define PWR_RESUME 0
-#define PWR_SUSPEND 1
-
 #define config_detach(dev, flag) \
 	do { \
 		device_detach(dev); \
@@ -428,13 +110,13 @@
 typedef struct malloc_type *usb_malloc_type;
 
 #define USB_DECLARE_DRIVER_INIT(dname, init...) \
-Static device_probe_t __CONCAT(dname,_match); \
-Static device_attach_t __CONCAT(dname,_attach); \
-Static device_detach_t __CONCAT(dname,_detach); \
+static device_probe_t __CONCAT(dname,_match); \
+static device_attach_t __CONCAT(dname,_attach); \
+static device_detach_t __CONCAT(dname,_detach); \
 \
-Static devclass_t __CONCAT(dname,_devclass); \
+static devclass_t __CONCAT(dname,_devclass); \
 \
-Static device_method_t __CONCAT(dname,_methods)[] = { \
+static device_method_t __CONCAT(dname,_methods)[] = { \
         DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
         DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
         DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
@@ -442,7 +124,7 @@
         {0,0} \
 }; \
 \
-Static driver_t __CONCAT(dname,_driver) = { \
+static driver_t __CONCAT(dname,_driver) = { \
         #dname, \
         __CONCAT(dname,_methods), \
         sizeof(struct __CONCAT(dname,_softc)) \
@@ -454,7 +136,7 @@
 #define USB_DECLARE_DRIVER(dname)	USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
 
 #define USB_MATCH(dname) \
-Static int \
+static int \
 __CONCAT(dname,_match)(device_t self)
 
 #define USB_MATCH_START(dname, uaa) \
@@ -464,7 +146,7 @@
 	sc->sc_dev = self
 
 #define USB_ATTACH(dname) \
-Static int \
+static int \
 __CONCAT(dname,_attach)(device_t self)
 
 #define USB_ATTACH_START(dname, sc, uaa) \
@@ -476,14 +158,10 @@
 #define USB_ATTACH_SUCCESS_RETURN	return 0
 
 #define USB_ATTACH_SETUP \
-	do { \
-		sc->sc_dev = self; \
-		device_set_desc_copy(self, devinfo); \
-		device_printf(self, "%s\n", devinfo); \
-	} while (0);
+	sc->sc_dev = self; \
 
 #define USB_DETACH(dname) \
-Static int \
+static int \
 __CONCAT(dname,_detach)(device_t self)
 
 #define USB_DETACH_START(dname, sc) \
@@ -519,11 +197,4 @@
 */
 #define logprintf		printf
 
-#ifdef SYSCTL_DECL
-SYSCTL_DECL(_hw_usb);
-#endif
-
-#endif /* __FreeBSD__ */
-
 #endif /* _USB_PORT_H */
-
Index: umct.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/umct.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/umct.c -L sys/dev/usb/umct.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/umct.c
+++ sys/dev/usb/umct.c
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/umct.c,v 1.9 2004/10/05 04:03:00 scottl Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/umct.c,v 1.18 2007/06/18 22:27:57 imp Exp $");
 
 /*
  * Driver for the MCT (Magic Control Technology) USB-RS232 Converter.
@@ -85,15 +85,15 @@
 	struct task		sc_task;
 };
 
-Static void umct_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void umct_get_status(void *, int, u_char *, u_char *);
-Static void umct_set(void *, int, int, int);
-Static int  umct_param(void *, int, struct termios *);
-Static int  umct_open(void *, int);
-Static void umct_close(void *, int);
-Static void umct_notify(void *, int count);
+static void umct_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void umct_get_status(void *, int, u_char *, u_char *);
+static void umct_set(void *, int, int, int);
+static int  umct_param(void *, int, struct termios *);
+static int  umct_open(void *, int);
+static void umct_close(void *, int);
+static void umct_notify(void *, int count);
 
-Static struct ucom_callback umct_callback = {
+static struct ucom_callback umct_callback = {
 	umct_get_status,	/* ucom_get_status */
 	umct_set,		/* ucom_set */
 	umct_param,		/* ucom_param */
@@ -104,7 +104,7 @@
 	NULL			/* ucom_write */
 };
 
-Static const struct umct_product {
+static const struct umct_product {
 	uint16_t	vendor;
 	uint16_t	product;
 } umct_products[] = {
@@ -116,18 +116,18 @@
 	{ 0, 0 }
 };
 
-Static device_probe_t	umct_match;
-Static device_attach_t	umct_attach;
-Static device_detach_t	umct_detach;
+static device_probe_t	umct_match;
+static device_attach_t	umct_attach;
+static device_detach_t	umct_detach;
 
-Static device_method_t umct_methods[] = {
+static device_method_t umct_methods[] = {
 	DEVMETHOD(device_probe, umct_match),
 	DEVMETHOD(device_attach, umct_attach),
 	DEVMETHOD(device_detach, umct_detach),
 	{ 0, 0 }
 };
 
-Static driver_t umct_driver = {
+static driver_t umct_driver = {
 	"ucom",
 	umct_methods,
 	sizeof(struct umct_softc)
@@ -138,9 +138,10 @@
 MODULE_DEPEND(umct, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
 MODULE_VERSION(umct, 1);
 
-USB_MATCH(umct)
+static int
+umct_match(device_t self)
 {
-	USB_MATCH_START(umct, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	int i;
 
 	if (uaa->iface != NULL)
@@ -156,39 +157,34 @@
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(umct)
+static int
+umct_attach(device_t self)
 {
-	USB_ATTACH_START(umct, sc, uaa);
+	struct umct_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev;
 	struct ucom_softc *ucom;
 	usb_config_descriptor_t *cdesc;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char *devinfo;
 	const char *devname;
 	usbd_status err;
 	int i;
 
 	dev = uaa->device;
-	devinfo = malloc(1024, M_USBDEV, M_NOWAIT | M_ZERO);
-	if (devinfo == NULL)
-		return (ENOMEM);
 	bzero(sc, sizeof(struct umct_softc));
 	ucom = &sc->sc_ucom;
 	ucom->sc_dev = self;
 	ucom->sc_udev = dev;
 	ucom->sc_iface = uaa->iface;
 
-	usbd_devinfo(dev, 0, devinfo);
-	device_set_desc_copy(self, devinfo);
-	devname = USBDEVNAME(ucom->sc_dev);
-	printf("%s: %s\n", devname, devinfo);
-
 	ucom->sc_bulkout_no = -1;
 	ucom->sc_bulkin_no = -1;
 	sc->sc_intr_number = -1;
 	sc->sc_intr_pipe = NULL;
 
+	devname = device_get_nameunit(ucom->sc_dev);
+
 	err = usbd_set_config_index(dev, UMCT_CONFIG_INDEX, 1);
 	if (err) {
 		printf("%s: failed to set configuration: %s\n",
@@ -255,7 +251,7 @@
 	}
 
 	if (sc->sc_intr_number == -1) {
-		printf("%s: Could not fint interrupt in\n", devname);
+		printf("%s: Could not find interrupt in\n", devname);
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -274,18 +270,17 @@
 	ucom->sc_callback = &umct_callback;
 	ucom_attach(ucom);
 	TASK_INIT(&sc->sc_task, 0, umct_notify, sc);
-
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
 error:
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
-USB_DETACH(umct)
+static int
+umct_detach(device_t self)
 {
-	USB_DETACH_START(umct, sc);
+	struct umct_softc *sc = device_get_softc(self);
+
 	int rv;
 
 	if (sc->sc_intr_pipe != NULL) {
@@ -303,7 +298,7 @@
 	return (rv);
 }
 
-Static int
+static int
 umct_request(struct umct_softc *sc, uint8_t request, int len, uint32_t value)
 {
 	usb_device_request_t req;
@@ -320,11 +315,11 @@
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, oval);
 	if (err)
 		printf("%s: ubsa_request: %s\n",
-		    USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		    device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 	return (err);
 }
 
-Static void
+static void
 umct_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct umct_softc *sc;
@@ -353,7 +348,7 @@
 	taskqueue_enqueue(taskqueue_swi_giant, &sc->sc_task);
 }
 
-Static void
+static void
 umct_notify(void *arg, int count)
 {
 	struct umct_softc *sc;
@@ -363,7 +358,7 @@
 		ucom_status_change(&sc->sc_ucom);
 }
 
-Static void
+static void
 umct_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
 {
 	struct umct_softc *sc;
@@ -377,7 +372,7 @@
 	return;
 }
 
-Static void
+static void
 umct_set(void *addr, int portno, int reg, int onoff)
 {
 	struct umct_softc *sc;
@@ -404,7 +399,7 @@
 	}
 }
 
-Static int
+static int
 umct_calc_baud(u_int baud)
 {
 	switch(baud) {
@@ -426,7 +421,7 @@
 	return (0x0);
 }
 
-Static int
+static int
 umct_param(void *addr, int portno, struct termios *ti)
 {
 	struct umct_softc *sc;
@@ -463,7 +458,7 @@
 	return (0);
 }
 
-Static int
+static int
 umct_open(void *addr, int portno)
 {
 	struct umct_softc *sc;
@@ -481,7 +476,7 @@
 		    sc->sc_isize, umct_intr, UMCT_INTR_INTERVAL);
 		if (err) {
 			printf("%s: cannot open interrupt pipe (addr %d)\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev),
+			    device_get_nameunit(sc->sc_ucom.sc_dev),
 			    sc->sc_intr_number);
 			free(sc->sc_intr_buf, M_USBDEV);
 			return (EIO);
@@ -491,7 +486,7 @@
 	return (0);
 }
 
-Static void
+static void
 umct_close(void *addr, int portno)
 {
 	struct umct_softc *sc;
@@ -505,11 +500,11 @@
 		err = usbd_abort_pipe(sc->sc_intr_pipe);
 		if (err)
 			printf("%s: abort interrupt pipe failed: %s\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+			    device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_intr_pipe);
 		if (err)
 			printf("%s: close interrupt pipe failed: %s\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+			    device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 		free(sc->sc_intr_buf, M_USBDEV);
 		sc->sc_intr_pipe = NULL;
 	}
Index: ucom.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ucom.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ucom.c -L sys/dev/usb/ucom.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ucom.c
+++ sys/dev/usb/ucom.c
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ucom.c,v 1.57 2005/04/12 00:26:40 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ucom.c,v 1.64 2007/06/25 06:40:20 imp Exp $");
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -79,11 +79,7 @@
 #include <sys/tty.h>
 #include <sys/clist.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/proc.h>
 #include <sys/poll.h>
 #include <sys/sysctl.h>
@@ -105,35 +101,35 @@
 	   &ucomdebug, 0, "ucom debug level");
 #define DPRINTF(x)	do { \
 				if (ucomdebug) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 
 #define DPRINTFN(n, x)	do { \
 				if (ucomdebug > (n)) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n, x)
 #endif
 
-Static void ucom_cleanup(struct ucom_softc *);
-Static int ucomparam(struct tty *, struct termios *);
-Static void ucomstart(struct tty *);
-Static void ucomstop(struct tty *, int);
-Static void ucom_shutdown(struct ucom_softc *);
-Static void ucom_dtr(struct ucom_softc *, int);
-Static void ucom_rts(struct ucom_softc *, int);
-Static void ucombreak(struct tty *, int);
-Static usbd_status ucomstartread(struct ucom_softc *);
-Static void ucomreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void ucomwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void ucomstopread(struct ucom_softc *);
-
-Static t_open_t  ucomopen;
-Static t_close_t ucomclose;
-Static t_modem_t ucommodem;
-Static t_ioctl_t ucomioctl;
+static void ucom_cleanup(struct ucom_softc *);
+static int ucomparam(struct tty *, struct termios *);
+static void ucomstart(struct tty *);
+static void ucomstop(struct tty *, int);
+static void ucom_shutdown(struct ucom_softc *);
+static void ucom_dtr(struct ucom_softc *, int);
+static void ucom_rts(struct ucom_softc *, int);
+static void ucombreak(struct tty *, int);
+static usbd_status ucomstartread(struct ucom_softc *);
+static void ucomreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void ucomwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void ucomstopread(struct ucom_softc *);
+
+static t_open_t  ucomopen;
+static t_close_t ucomclose;
+static t_modem_t ucommodem;
+static t_ioctl_t ucomioctl;
 
 devclass_t ucom_devclass;
 
@@ -168,7 +164,7 @@
 
 	DPRINTF(("ucom_attach: tty_attach tp = %p\n", tp));
 
-	ttycreate(tp, NULL, unit, MINOR_CALLOUT, "U%d", unit);
+	ttycreate(tp, TS_CALLOUT, "U%d", unit);
 	DPRINTF(("ucom_attach: ttycreate: ttyU%d\n", unit));
 
 	return (0);
@@ -199,7 +195,7 @@
 	return (0);
 }
 
-Static void
+static void
 ucom_shutdown(struct ucom_softc *sc)
 {
 	struct tty *tp = sc->sc_tty;
@@ -215,7 +211,7 @@
 	}
 }
 
-Static int
+static int
 ucomopen(struct tty *tp, struct cdev *dev)
 {
 	struct ucom_softc *sc;
@@ -227,7 +223,7 @@
 	if (sc->sc_dying)
 		return (ENXIO);
 
-	DPRINTF(("%s: ucomopen: tp = %p\n", USBDEVNAME(sc->sc_dev), tp));
+	DPRINTF(("%s: ucomopen: tp = %p\n", device_get_nameunit(sc->sc_dev), tp));
 
 	sc->sc_poll = 0;
 	sc->sc_lsr = sc->sc_msr = sc->sc_mcr = 0;
@@ -253,7 +249,7 @@
 			     &sc->sc_bulkin_pipe);
 	if (err) {
 		printf("%s: open bulk in error (addr %d): %s\n",
-		       USBDEVNAME(sc->sc_dev), sc->sc_bulkin_no,
+		       device_get_nameunit(sc->sc_dev), sc->sc_bulkin_no,
 		       usbd_errstr(err));
 		error = EIO;
 		goto fail;
@@ -263,7 +259,7 @@
 			     USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
 	if (err) {
 		printf("%s: open bulk out error (addr %d): %s\n",
-		       USBDEVNAME(sc->sc_dev), sc->sc_bulkout_no,
+		       device_get_nameunit(sc->sc_dev), sc->sc_bulkout_no,
 		       usbd_errstr(err));
 		error = EIO;
 		goto fail;
@@ -316,7 +312,7 @@
 
 	sc = tp->t_sc;
 
-	DPRINTF(("%s: ucomclose \n", USBDEVNAME(sc->sc_dev)));
+	DPRINTF(("%s: ucomclose \n", device_get_nameunit(sc->sc_dev)));
 
 	ucom_cleanup(sc);
 
@@ -325,7 +321,7 @@
 }
 
 static int
-ucomioctl(struct tty *tp, u_long cmd, void *data, int flag, usb_proc_ptr p)
+ucomioctl(struct tty *tp, u_long cmd, void *data, int flag, struct thread *p)
 {
 	struct ucom_softc *sc;
 	int error;
@@ -344,7 +340,7 @@
 	return (error);
 }
 
-Static int
+static int
 ucommodem(struct tty *tp, int sigon, int sigoff)
 {
 	struct ucom_softc *sc;
@@ -393,7 +389,7 @@
 	return (0);
 }
 
-Static void
+static void
 ucombreak(struct tty *tp, int onoff)
 {
 	struct ucom_softc *sc;
@@ -406,7 +402,7 @@
 				  UCOM_SET_BREAK, onoff);
 }
 
-Static void
+static void
 ucom_dtr(struct ucom_softc *sc, int onoff)
 {
 	DPRINTF(("ucom_dtr: onoff = %d\n", onoff));
@@ -417,7 +413,7 @@
 				  UCOM_SET_DTR, onoff);
 }
 
-Static void
+static void
 ucom_rts(struct ucom_softc *sc, int onoff)
 {
 	DPRINTF(("ucom_rts: onoff = %d\n", onoff));
@@ -453,7 +449,7 @@
 	}
 }
 
-Static int
+static int
 ucomparam(struct tty *tp, struct termios *t)
 {
 	struct ucom_softc *sc;
@@ -520,7 +516,7 @@
 	return (0);
 }
 
-Static void
+static void
 ucomstart(struct tty *tp)
 {
 	struct ucom_softc *sc;
@@ -536,6 +532,16 @@
 	if (sc->sc_dying)
 		return;
 
+	/*
+	 * If there's no sc_oxfer, then ucomclose has removed it.  The buffer
+	 * has just been flushed in the ttyflush() in ttyclose().  ttyflush()
+	 * then calls tt_stop().  ucomstop calls ucomstart, so the right thing
+	 * to do here is just abort if sc_oxfer is NULL, as everything else
+	 * is cleaned up elsewhere.
+	 */
+	if (sc->sc_oxfer == NULL)
+		return;
+
 	s = spltty();
 
 	if (tp->t_state & TS_TBLOCK) {
@@ -612,7 +618,7 @@
 	splx(s);
 }
 
-Static void
+static void
 ucomstop(struct tty *tp, int flag)
 {
 	struct ucom_softc *sc;
@@ -644,7 +650,7 @@
 	DPRINTF(("ucomstop: done\n"));
 }
 
-Static void
+static void
 ucomwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
 {
 	struct ucom_softc *sc = (struct ucom_softc *)p;
@@ -659,7 +665,7 @@
 
 	if (status != USBD_NORMAL_COMPLETION) {
 		printf("%s: ucomwritecb: %s\n",
-		       USBDEVNAME(sc->sc_dev), usbd_errstr(status));
+		       device_get_nameunit(sc->sc_dev), usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
 		/* XXX we should restart after some delay. */
@@ -670,7 +676,7 @@
 	DPRINTF(("ucomwritecb: cc = %d\n", cc));
 	if (cc <= sc->sc_opkthdrlen) {
 		printf("%s: sent size too small, cc = %d\n",
-		       USBDEVNAME(sc->sc_dev), cc);
+		       device_get_nameunit(sc->sc_dev), cc);
 		goto error;
 	}
 
@@ -695,7 +701,7 @@
 	return;
 }
 
-Static usbd_status
+static usbd_status
 ucomstartread(struct ucom_softc *sc)
 {
 	usbd_status err;
@@ -722,7 +728,7 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static void
+static void
 ucomreadcb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
 {
 	struct ucom_softc *sc = (struct ucom_softc *)p;
@@ -738,7 +744,7 @@
 	if (status != USBD_NORMAL_COMPLETION) {
 		if (!(sc->sc_state & UCS_RXSTOP))
 			printf("%s: ucomreadcb: %s\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(status));
+			       device_get_nameunit(sc->sc_dev), usbd_errstr(status));
 		sc->sc_state |= UCS_RXSTOP;
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
@@ -758,7 +764,7 @@
 
 	if (cc > sc->sc_ibufsize) {
 		printf("%s: invalid receive data size, %d chars\n",
-		       USBDEVNAME(sc->sc_dev), cc);
+		       device_get_nameunit(sc->sc_dev), cc);
 		goto resubmit;
 	}
 	if (cc < 1)
@@ -782,7 +788,7 @@
 			ucomstart(tp);
 		}
 		if (lostcc > 0)
-			printf("%s: lost %d chars\n", USBDEVNAME(sc->sc_dev),
+			printf("%s: lost %d chars\n", device_get_nameunit(sc->sc_dev),
 			       lostcc);
 	} else {
 		/* Give characters to tty layer. */
@@ -791,7 +797,7 @@
 			if (ttyld_rint(tp, *cp) == -1) {
 				/* XXX what should we do? */
 				printf("%s: lost %d chars\n",
-				       USBDEVNAME(sc->sc_dev), cc);
+				       device_get_nameunit(sc->sc_dev), cc);
 				break;
 			}
 			cc--;
@@ -803,7 +809,7 @@
     resubmit:
 	err = ucomstartread(sc);
 	if (err) {
-		printf("%s: read start failed\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: read start failed\n", device_get_nameunit(sc->sc_dev));
 		/* XXX what should we dow now? */
 	}
 
@@ -812,7 +818,7 @@
 		ucommodem(tp, SER_RTS, 0);
 }
 
-Static void
+static void
 ucom_cleanup(struct ucom_softc *sc)
 {
 	DPRINTF(("ucom_cleanup: closing pipes\n"));
@@ -839,7 +845,7 @@
 	}
 }
 
-Static void
+static void
 ucomstopread(struct ucom_softc *sc)
 {
 	usbd_status err;
Index: ohci_pci.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ohci_pci.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/ohci_pci.c -L sys/dev/usb/ohci_pci.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/ohci_pci.c
+++ sys/dev/usb/ohci_pci.c
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ohci_pci.c,v 1.44.2.1 2006/01/29 01:26:46 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ohci_pci.c,v 1.50 2007/06/21 14:42:33 imp Exp $");
 
 /*
  * USB Open Host Controller driver.
@@ -55,6 +55,8 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
 #include <sys/bus.h>
 #include <sys/queue.h>
 #include <machine/bus.h>
@@ -126,10 +128,10 @@
 #define PCI_OHCI_BASE_REG	0x10
 
 
-static int ohci_pci_attach(device_t self);
-static int ohci_pci_detach(device_t self);
-static int ohci_pci_suspend(device_t self);
-static int ohci_pci_resume(device_t self);
+static device_attach_t ohci_pci_attach;
+static device_detach_t ohci_pci_detach;
+static device_suspend_t ohci_pci_suspend;
+static device_resume_t ohci_pci_resume;
 
 static int
 ohci_pci_suspend(device_t self)
@@ -295,14 +297,38 @@
 		sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
 	}
 
-	err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_BIO,
-	    (driver_intr_t *) ohci_intr, sc, &sc->ih);
+	err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_BIO, NULL, ohci_intr, 
+			     sc, &sc->ih);
 	if (err) {
 		device_printf(self, "Could not setup irq, %d\n", err);
 		sc->ih = NULL;
 		ohci_pci_detach(self);
 		return ENXIO;
 	}
+
+	/* Allocate a parent dma tag for DMA maps */
+	err = bus_dma_tag_create(bus_get_dma_tag(self), 1, 0,
+	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+	    BUS_SPACE_MAXSIZE_32BIT, USB_DMA_NSEG, BUS_SPACE_MAXSIZE_32BIT, 0,
+	    NULL, NULL, &sc->sc_bus.parent_dmatag);
+	if (err) {
+		device_printf(self, "Could not allocate parent DMA tag (%d)\n",
+		    err);
+		ohci_pci_detach(self);
+		return ENXIO;
+	}
+	/* Allocate a dma tag for transfer buffers */
+	err = bus_dma_tag_create(sc->sc_bus.parent_dmatag, 1, 0,
+	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+	    BUS_SPACE_MAXSIZE_32BIT, USB_DMA_NSEG, BUS_SPACE_MAXSIZE_32BIT, 0,
+	    busdma_lock_mutex, &Giant, &sc->sc_bus.buffer_dmatag);
+	if (err) {
+		device_printf(self, "Could not allocate transfer tag (%d)\n",
+		    err);
+		ohci_pci_detach(self);
+		return ENXIO;
+	}
+
 	err = ohci_init(sc);
 	if (!err) {
 		sc->sc_flags |= OHCI_SCFLG_DONEINIT;
@@ -327,6 +353,11 @@
 		sc->sc_flags &= ~OHCI_SCFLG_DONEINIT;
 	}
 
+	if (sc->sc_bus.parent_dmatag != NULL)
+		bus_dma_tag_destroy(sc->sc_bus.parent_dmatag);
+	if (sc->sc_bus.buffer_dmatag != NULL)
+		bus_dma_tag_destroy(sc->sc_bus.buffer_dmatag);
+
 	if (sc->irq_res && sc->ih) {
 		int err = bus_teardown_intr(self, sc->irq_res, sc->ih);
 
@@ -345,7 +376,8 @@
 		sc->irq_res = NULL;
 	}
 	if (sc->io_res) {
-		bus_release_resource(self, SYS_RES_MEMORY, PCI_CBMEM, sc->io_res);
+		bus_release_resource(self, SYS_RES_MEMORY, PCI_CBMEM,
+		    sc->io_res);
 		sc->io_res = NULL;
 		sc->iot = 0;
 		sc->ioh = 0;
Index: kue_fw.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/kue_fw.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/kue_fw.h -L sys/dev/usb/kue_fw.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/kue_fw.h
+++ sys/dev/usb/kue_fw.h
@@ -29,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/kue_fw.h,v 1.3 2005/01/06 01:43:27 imp Exp $
+ * $FreeBSD: src/sys/dev/usb/kue_fw.h,v 1.4 2006/09/06 23:44:24 imp Exp $
  */
 
 /*
@@ -85,7 +85,7 @@
 #define KUE_QTINTR_LOAD_CODE_HIGH	0x9C
 
 /* Firmware code segment */
-Static unsigned char kue_code_seg[] =
+static unsigned char kue_code_seg[] =
 {
     /******************************************/
     /* NOTE: B6/C3 is data header signature   */
@@ -577,7 +577,7 @@
 };
 
 /* Firmware fixup (data?) segment */
-Static unsigned char kue_fix_seg[] =
+static unsigned char kue_fix_seg[] =
 {
     /******************************************/
     /* NOTE: B6/C3 is data header signature   */
@@ -680,6 +680,6 @@
 
 /* Fixup command. */
 #define KUE_TRIGCMD_OFFSET	5
-Static unsigned char kue_trig_seg[] = {
+static unsigned char kue_trig_seg[] = {
 0xb6, 0xc3, 0x01, 0x00, 0x06, 0x64, 0x00, 0x00
 };
Index: uscanner.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uscanner.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/uscanner.c -L sys/dev/usb/uscanner.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/uscanner.c
+++ sys/dev/usb/uscanner.c
@@ -5,7 +5,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uscanner.c,v 1.63.2.1 2006/01/11 00:27:28 flz Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uscanner.c,v 1.89 2007/10/05 07:26:39 luigi Exp $");
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -50,22 +50,14 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
 #include <sys/filio.h>
-#endif
 #include <sys/tty.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/proc.h>
 #include <sys/poll.h>
 #include <sys/conf.h>
@@ -79,8 +71,8 @@
 #include "usbdevs.h"
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (uscannerdebug) logprintf x
-#define DPRINTFN(n,x)	if (uscannerdebug>(n)) logprintf x
+#define DPRINTF(x)	if (uscannerdebug) printf x
+#define DPRINTFN(n,x)	if (uscannerdebug>(n)) printf x
 int	uscannerdebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, uscanner, CTLFLAG_RW, 0, "USB uscanner");
 SYSCTL_INT(_hw_usb_uscanner, OID_AUTO, debug, CTLFLAG_RW,
@@ -100,7 +92,9 @@
 static const struct uscan_info uscanner_devs[] = {
   /* Acer Peripherals */
  {{ USB_VENDOR_ACERP, USB_PRODUCT_ACERP_ACERSCAN_320U }, 0 },
+ {{ USB_VENDOR_ACERP, USB_PRODUCT_ACERP_ACERSCAN_4300U }, 0 },
  {{ USB_VENDOR_ACERP, USB_PRODUCT_ACERP_ACERSCAN_640U }, 0 },
+ {{ USB_VENDOR_ACERP, USB_PRODUCT_ACERP_ACERSCAN_640BT }, 0 },
  {{ USB_VENDOR_ACERP, USB_PRODUCT_ACERP_ACERSCAN_620U }, 0 },
  {{ USB_VENDOR_ACERP, USB_PRODUCT_ACERP_ACERSCAN_1240U }, 0 },
  {{ USB_VENDOR_ACERP, USB_PRODUCT_ACERP_ACERSCAN_C310U }, 0 },
@@ -124,7 +118,9 @@
  {{ USB_VENDOR_CANON, USB_PRODUCT_CANON_N656U }, 0 },
  {{ USB_VENDOR_CANON, USB_PRODUCT_CANON_N676U }, 0 },
  {{ USB_VENDOR_CANON, USB_PRODUCT_CANON_N1220U }, 0 },
+ {{ USB_VENDOR_CANON, USB_PRODUCT_CANON_D660U }, 0 },
  {{ USB_VENDOR_CANON, USB_PRODUCT_CANON_N1240U }, 0 },
+ {{ USB_VENDOR_CANON, USB_PRODUCT_CANON_LIDE25 }, 0 },
 
   /* Kye */
  {{ USB_VENDOR_KYE, USB_PRODUCT_KYE_VIVIDPRO }, 0 },
@@ -143,6 +139,7 @@
  {{ USB_VENDOR_HP, USB_PRODUCT_HP_5400C }, 0 },
  {{ USB_VENDOR_HP, USB_PRODUCT_HP_6200C }, 0 },
  {{ USB_VENDOR_HP, USB_PRODUCT_HP_6300C }, 0 },
+ {{ USB_VENDOR_HP, USB_PRODUCT_HP_82x0C }, 0 },
 
   /* Microtek */
  {{ USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_336CX }, 0 },
@@ -203,9 +200,18 @@
  {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_1660 }, 0 },
  {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_1670 }, 0 },
  {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_1260 }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_1270 }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_RX425 }, 0 },
  {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_3200 }, USC_KEEP_OPEN },
  {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_GT9700F }, USC_KEEP_OPEN },
  {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_GT9300UF }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_2480 }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_3500 }, USC_KEEP_OPEN },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_3590 }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_4200 }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_4990 }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_5000 }, 0 },
+ {{ USB_VENDOR_EPSON, USB_PRODUCT_EPSON_6000 }, 0 },
 
   /* UMAX */
  {{ USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA1220U }, 0 },
@@ -233,12 +239,10 @@
 #define	USCANNER_BUFFERSIZE	1024
 
 struct uscanner_softc {
-	USBBASEDEVICE		sc_dev;		/* base device */
+	device_t		sc_dev;		/* base device */
 	usbd_device_handle	sc_udev;
 	usbd_interface_handle	sc_iface;
-#if defined(__FreeBSD__)
 	struct cdev *dev;
-#endif
 
 	u_int			sc_dev_flags;
 
@@ -263,9 +267,6 @@
 	u_char			sc_dying;
 };
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-cdev_decl(uscanner);
-#elif defined(__FreeBSD__)
 d_open_t  uscanneropen;
 d_close_t uscannerclose;
 d_read_t  uscannerread;
@@ -273,7 +274,7 @@
 d_poll_t  uscannerpoll;
 
 
-Static struct cdevsw uscanner_cdevsw = {
+static struct cdevsw uscanner_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
 	.d_open =	uscanneropen,
@@ -282,62 +283,104 @@
 	.d_write =	uscannerwrite,
 	.d_poll =	uscannerpoll,
 	.d_name =	"uscanner",
-#if __FreeBSD_version < 500014
-	.d_bmaj		-1
-#endif
 };
-#endif
 
-Static int uscanner_do_read(struct uscanner_softc *, struct uio *, int);
-Static int uscanner_do_write(struct uscanner_softc *, struct uio *, int);
-Static void uscanner_do_close(struct uscanner_softc *);
+static int uscanner_do_read(struct uscanner_softc *, struct uio *, int);
+static int uscanner_do_write(struct uscanner_softc *, struct uio *, int);
+static void uscanner_do_close(struct uscanner_softc *);
 
 #define USCANNERUNIT(n) (minor(n))
 
-USB_DECLARE_DRIVER(uscanner);
+static device_probe_t uscanner_match;
+static device_attach_t uscanner_attach;
+static device_detach_t uscanner_detach;
+
+static device_method_t uscanner_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		uscanner_match),
+	DEVMETHOD(device_attach,	uscanner_attach),
+	DEVMETHOD(device_detach,	uscanner_detach),
 
-USB_MATCH(uscanner)
+	{ 0, 0 }
+};
+
+static driver_t uscanner_driver = {
+	"uscanner",
+	uscanner_methods,
+	sizeof(struct uscanner_softc)
+};
+
+static devclass_t uscanner_devclass;
+
+static int
+uscanner_match(device_t self)
 {
-	USB_MATCH_START(uscanner, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
+	usb_interface_descriptor_t *id;
+
+	if (uaa->iface == NULL)
+		return UMATCH_NONE;	/* do not grab the entire device */
 
-	if (uaa->iface != NULL)
+	if (uscanner_lookup(uaa->vendor, uaa->product) == NULL)
+		return UMATCH_NONE;	/* not in the list of known devices */
+	id = usbd_get_interface_descriptor(uaa->iface);
+	if (id == NULL)
 		return UMATCH_NONE;
 
-	return (uscanner_lookup(uaa->vendor, uaa->product) != NULL ?
-		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
+	/*
+	 * There isn't a specific UICLASS for scanners, many vendors use
+	 * UICLASS_VENDOR, so detecting the right interface is not so easy.
+	 * But certainly we can exclude PRINTER and MASS - which some
+	 * multifunction devices implement.
+	 */
+	if (id->bInterfaceClass == UICLASS_PRINTER ||
+	    id->bInterfaceClass == UICLASS_MASS)
+		return UMATCH_NONE;
+
+	return UMATCH_VENDOR_PRODUCT;	/* ok we found it */
 }
 
-USB_ATTACH(uscanner)
+static int
+uscanner_attach(device_t self)
 {
-	USB_ATTACH_START(uscanner, sc, uaa);
+	struct uscanner_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_interface_descriptor_t *id = 0;
 	usb_endpoint_descriptor_t *ed, *ed_bulkin = NULL, *ed_bulkout = NULL;
-	char devinfo[1024];
 	int i;
 	usbd_status err;
+	int ifnum;
 
-	usbd_devinfo(uaa->device, 0, devinfo);
-	USB_ATTACH_SETUP;
-
+	sc->sc_dev = self;
 	sc->sc_dev_flags = uscanner_lookup(uaa->vendor, uaa->product)->flags;
-
 	sc->sc_udev = uaa->device;
 
+	id = usbd_get_interface_descriptor(uaa->iface);
+	ifnum = id->bInterfaceNumber;
+#if 0
+	/*
+	 * This was in the original driver, but we cannot change the
+	 * configuration of the whole device while attaching only to
+	 * one of its interfaces. This can kill other already-attached
+	 * driver, and/or possibly prevent this driver from attaching
+	 * if an error occurs in set_config_no.
+	 * If a device need setting the configuration, this must be done
+	 * before attaching drivers to the various interfaces.
+	 */
 	err = usbd_set_config_no(uaa->device, 1, 1); /* XXX */
 	if (err) {
 		printf("%s: setting config no failed\n",
-		    USBDEVNAME(sc->sc_dev));
-		USB_ATTACH_ERROR_RETURN;
+		    device_get_nameunit(sc->sc_dev));
+		return ENXIO;
 	}
-
-	/* XXX We only check the first interface */
-	err = usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface);
+#endif
+	err = usbd_device2interface_handle(sc->sc_udev, ifnum, &sc->sc_iface);
 	if (!err && sc->sc_iface)
 	    id = usbd_get_interface_descriptor(sc->sc_iface);
 	if (err || id == 0) {
 		printf("%s: could not get interface descriptor, err=%d,id=%p\n",
-		       USBDEVNAME(sc->sc_dev), err, id);
-		USB_ATTACH_ERROR_RETURN;
+		       device_get_nameunit(sc->sc_dev), err, id);
+		return ENXIO;
 	}
 
 	/* Find the two first bulk endpoints */
@@ -345,8 +388,8 @@
 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
 		if (ed == 0) {
 			printf("%s: could not read endpoint descriptor\n",
-			       USBDEVNAME(sc->sc_dev));
-			USB_ATTACH_ERROR_RETURN;
+			       device_get_nameunit(sc->sc_dev));
+			return ENXIO;
 		}
 
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN
@@ -364,33 +407,31 @@
 	/* Verify that we goething sensible */
 	if (ed_bulkin == NULL || ed_bulkout == NULL) {
 		printf("%s: bulk-in and/or bulk-out endpoint not found\n",
-			USBDEVNAME(sc->sc_dev));
-		USB_ATTACH_ERROR_RETURN;
+			device_get_nameunit(sc->sc_dev));
+		return ENXIO;
 	}
 
 	sc->sc_bulkin = ed_bulkin->bEndpointAddress;
 	sc->sc_bulkout = ed_bulkout->bEndpointAddress;
 
-#ifdef __FreeBSD__
 	/* the main device, ctrl endpoint */
-	sc->dev = make_dev(&uscanner_cdevsw, USBDEVUNIT(sc->sc_dev),
-		UID_ROOT, GID_OPERATOR, 0644, "%s", USBDEVNAME(sc->sc_dev));
-#endif
+	sc->dev = make_dev(&uscanner_cdevsw, device_get_unit(sc->sc_dev),
+		UID_ROOT, GID_OPERATOR, 0644, "%s", device_get_nameunit(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,sc->sc_dev);
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
-
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
 int
-uscanneropen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+uscanneropen(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	struct uscanner_softc *sc;
 	int unit = USCANNERUNIT(dev);
 	usbd_status err;
 
-	USB_GET_SC_OPEN(uscanner, unit, sc);
+	sc = devclass_get_softc(uscanner_devclass, unit);
+	if (sc == NULL)
+		return (ENXIO);
 
  	DPRINTFN(5, ("uscanneropen: flag=%d, mode=%d, unit=%d\n",
 		     flag, mode, unit));
@@ -416,7 +457,7 @@
 				     USBD_EXCLUSIVE_USE, &sc->sc_bulkin_pipe);
 		if (err) {
 			printf("%s: cannot open bulk-in pipe (addr %d)\n",
-			       USBDEVNAME(sc->sc_dev), sc->sc_bulkin);
+			       device_get_nameunit(sc->sc_dev), sc->sc_bulkin);
 			uscanner_do_close(sc);
 			return (EIO);
 		}
@@ -426,7 +467,7 @@
 				     USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
 		if (err) {
 			printf("%s: cannot open bulk-out pipe (addr %d)\n",
-			       USBDEVNAME(sc->sc_dev), sc->sc_bulkout);
+			       device_get_nameunit(sc->sc_dev), sc->sc_bulkout);
 			uscanner_do_close(sc);
 			return (EIO);
 		}
@@ -447,12 +488,11 @@
 }
 
 int
-uscannerclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+uscannerclose(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	struct uscanner_softc *sc;
 
-	USB_GET_SC(uscanner, USCANNERUNIT(dev), sc);
-
+	sc = devclass_get_softc(uscanner_devclass, USCANNERUNIT(dev));
 	DPRINTFN(5, ("uscannerclose: flag=%d, mode=%d, unit=%d\n",
 		     flag, mode, USCANNERUNIT(dev)));
 
@@ -505,14 +545,14 @@
 	sc->sc_state &= ~USCANNER_OPEN;
 }
 
-Static int
+static int
 uscanner_do_read(struct uscanner_softc *sc, struct uio *uio, int flag)
 {
 	u_int32_t n, tn;
 	usbd_status err;
 	int error = 0;
 
-	DPRINTFN(5, ("%s: uscannerread\n", USBDEVNAME(sc->sc_dev)));
+	DPRINTFN(5, ("%s: uscannerread\n", device_get_nameunit(sc->sc_dev)));
 
 	if (sc->sc_dying)
 		return (EIO);
@@ -550,24 +590,23 @@
 	struct uscanner_softc *sc;
 	int error;
 
-	USB_GET_SC(uscanner, USCANNERUNIT(dev), sc);
-
+	sc = devclass_get_softc(uscanner_devclass, USCANNERUNIT(dev));
 	sc->sc_refcnt++;
 	error = uscanner_do_read(sc, uio, flag);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 
 	return (error);
 }
 
-Static int
+static int
 uscanner_do_write(struct uscanner_softc *sc, struct uio *uio, int flag)
 {
 	u_int32_t n;
 	int error = 0;
 	usbd_status err;
 
-	DPRINTFN(5, ("%s: uscanner_do_write\n", USBDEVNAME(sc->sc_dev)));
+	DPRINTFN(5, ("%s: uscanner_do_write\n", device_get_nameunit(sc->sc_dev)));
 
 	if (sc->sc_dying)
 		return (EIO);
@@ -600,46 +639,21 @@
 	struct uscanner_softc *sc;
 	int error;
 
-	USB_GET_SC(uscanner, USCANNERUNIT(dev), sc);
-
+	sc = devclass_get_softc(uscanner_devclass, USCANNERUNIT(dev));
 	sc->sc_refcnt++;
 	error = uscanner_do_write(sc, uio, flag);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	return (error);
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-uscanner_activate(device_ptr_t self, enum devact act)
-{
-	struct uscanner_softc *sc = (struct uscanner_softc *)self;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		sc->sc_dying = 1;
-		break;
-	}
-	return (0);
-}
-#endif
-
-USB_DETACH(uscanner)
+static int
+uscanner_detach(device_t self)
 {
-	USB_DETACH_START(uscanner, sc);
+	struct uscanner_softc *sc = device_get_softc(self);
 	int s;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	int maj, mn;
-#endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	DPRINTF(("uscanner_detach: sc=%p flags=%d\n", sc, flags));
-#elif defined(__FreeBSD__)
 	DPRINTF(("uscanner_detach: sc=%p\n", sc));
-#endif
 
 	sc->sc_dying = 1;
 	sc->sc_dev_flags = 0;	/* make close really close device */
@@ -653,38 +667,24 @@
 	s = splusb();
 	if (--sc->sc_refcnt >= 0) {
 		/* Wait for processes to go away. */
-		usb_detach_wait(USBDEV(sc->sc_dev));
+		usb_detach_wait(sc->sc_dev);
 	}
 	splx(s);
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	/* locate the major number */
-	for (maj = 0; maj < nchrdev; maj++)
-		if (cdevsw[maj].d_open == uscanneropen)
-			break;
-
-	/* Nuke the vnodes for any open instances (calls close). */
-	mn = self->dv_unit * USB_MAX_ENDPOINTS;
-	vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);
-#elif defined(__FreeBSD__)
 	/* destroy the device for the control endpoint */
 	destroy_dev(sc->dev);
-#endif
-
-	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
 
 	return (0);
 }
 
 int
-uscannerpoll(struct cdev *dev, int events, usb_proc_ptr p)
+uscannerpoll(struct cdev *dev, int events, struct thread *p)
 {
 	struct uscanner_softc *sc;
 	int revents = 0;
 
-	USB_GET_SC(uscanner, USCANNERUNIT(dev), sc);
-
+	sc = devclass_get_softc(uscanner_devclass, USCANNERUNIT(dev));
 	if (sc->sc_dying)
 		return (EIO);
 
@@ -699,6 +699,5 @@
 	return (revents);
 }
 
-#if defined(__FreeBSD__)
+MODULE_DEPEND(uscanner, usb, 1, 1, 1);
 DRIVER_MODULE(uscanner, uhub, uscanner_driver, uscanner_devclass, usbd_driver_load, 0);
-#endif
Index: ucomvar.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ucomvar.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ucomvar.h -L sys/dev/usb/ucomvar.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ucomvar.h
+++ sys/dev/usb/ucomvar.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: ucomvar.h,v 1.9 2001/01/23 21:56:17 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/ucomvar.h,v 1.7 2005/01/06 01:43:28 imp Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/ucomvar.h,v 1.9 2007/06/12 17:30:54 imp Exp $	*/
 
 /*-
  * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama at jp.FreeBSD.org>.
@@ -97,7 +97,7 @@
 #define UCOM_SET_RTS 2
 #define UCOM_SET_BREAK 3
 	int (*ucom_param)(void *, int, struct termios *);
-	int (*ucom_ioctl)(void *, int, u_long, caddr_t, int, usb_proc_ptr);
+	int (*ucom_ioctl)(void *, int, u_long, caddr_t, int, struct thread *);
 	int (*ucom_open)(void *, int);
 	void (*ucom_close)(void *, int);
 	void (*ucom_read)(void *, int, u_char **, u_int32_t *);
@@ -120,7 +120,7 @@
 #define UCS_RTS_IFLOW	0x0008	/* use RTS input flow control */
 
 struct ucom_softc {
-	USBBASEDEVICE		sc_dev;		/* base device */
+	device_t		sc_dev;		/* base device */
 	usbd_device_handle	sc_udev;	/* USB device */
 	usbd_interface_handle	sc_iface;	/* data interface */
 
Index: uftdi.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uftdi.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/uftdi.c -L sys/dev/usb/uftdi.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/uftdi.c
+++ sys/dev/usb/uftdi.c
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uftdi.c,v 1.22 2005/04/05 22:09:18 ticso Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uftdi.c,v 1.37 2007/06/22 05:53:05 imp Exp $");
 
 /*
  * FTDI FT8U100AX serial adapter driver
@@ -57,11 +57,7 @@
 #include <sys/tty.h>
 #include <sys/file.h>
 
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 
 #include <sys/sysctl.h>
 
@@ -83,12 +79,12 @@
 	   &uftdidebug, 0, "uftdi debug level");
 #define DPRINTF(x)      do { \
 				if (uftdidebug) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 
 #define DPRINTFN(n, x)  do { \
 				if (uftdidebug > (n)) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 
 #else
@@ -109,26 +105,22 @@
 
 struct uftdi_softc {
 	struct ucom_softc	sc_ucom;
-
 	usbd_interface_handle	sc_iface;	/* interface */
-
 	enum uftdi_type		sc_type;
 	u_int			sc_hdrlen;
-
 	u_char			sc_msr;
 	u_char			sc_lsr;
-
 	u_int			last_lcr;
 };
 
-Static void	uftdi_get_status(void *, int portno, u_char *lsr, u_char *msr);
-Static void	uftdi_set(void *, int, int, int);
-Static int	uftdi_param(void *, int, struct termios *);
-Static int	uftdi_open(void *sc, int portno);
-Static void	uftdi_read(void *sc, int portno, u_char **ptr,u_int32_t *count);
-Static void	uftdi_write(void *sc, int portno, u_char *to, u_char *from,
+static void	uftdi_get_status(void *, int portno, u_char *lsr, u_char *msr);
+static void	uftdi_set(void *, int, int, int);
+static int	uftdi_param(void *, int, struct termios *);
+static int	uftdi_open(void *sc, int portno);
+static void	uftdi_read(void *sc, int portno, u_char **ptr,u_int32_t *count);
+static void	uftdi_write(void *sc, int portno, u_char *to, u_char *from,
 			    u_int32_t *count);
-Static void	uftdi_break(void *sc, int portno, int onoff);
+static void	uftdi_break(void *sc, int portno, int onoff);
 
 struct ucom_callback uftdi_callback = {
 	uftdi_get_status,
@@ -141,9 +133,10 @@
 	uftdi_write,
 };
 
-USB_MATCH(uftdi)
+static int
+uftdi_match(device_t self)
 {
-	USB_MATCH_START(uftdi, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 
 	if (uaa->iface != NULL) {
 		if (uaa->vendor == USB_VENDOR_FTDI &&
@@ -163,11 +156,20 @@
 	     uaa->product == USB_PRODUCT_FTDI_CFA_632 ||
 	     uaa->product == USB_PRODUCT_FTDI_CFA_633 ||
 	     uaa->product == USB_PRODUCT_FTDI_CFA_634 ||
+	     uaa->product == USB_PRODUCT_FTDI_CFA_635 ||
 	     uaa->product == USB_PRODUCT_FTDI_USBSERIAL ||
 	     uaa->product == USB_PRODUCT_FTDI_MX2_3 ||
 	     uaa->product == USB_PRODUCT_FTDI_MX4_5 ||
 	     uaa->product == USB_PRODUCT_FTDI_LK202 ||
-	     uaa->product == USB_PRODUCT_FTDI_LK204))
+	     uaa->product == USB_PRODUCT_FTDI_LK204 ||
+	     uaa->product == USB_PRODUCT_FTDI_TACTRIX_OPENPORT_13M ||
+	     uaa->product == USB_PRODUCT_FTDI_TACTRIX_OPENPORT_13S ||
+	     uaa->product == USB_PRODUCT_FTDI_TACTRIX_OPENPORT_13U ||
+	     uaa->product == USB_PRODUCT_FTDI_EISCOU ||
+	     uaa->product == USB_PRODUCT_FTDI_UOPTBR ||
+	     uaa->product == USB_PRODUCT_FTDI_EMCU2D ||
+	     uaa->product == USB_PRODUCT_FTDI_PCMSFU ||
+	     uaa->product == USB_PRODUCT_FTDI_EMCU2H ))
 		return (UMATCH_VENDOR_PRODUCT);
 	if (uaa->vendor == USB_VENDOR_SIIG2 &&
 	    (uaa->product == USB_PRODUCT_SIIG2_US2308))
@@ -179,53 +181,50 @@
 	if (uaa->vendor == USB_VENDOR_BBELECTRONICS &&
 	    (uaa->product == USB_PRODUCT_BBELECTRONICS_USOTL4))
 		return (UMATCH_VENDOR_PRODUCT);
+	if (uaa->vendor == USB_VENDOR_MELCO &&
+	    (uaa->product == USB_PRODUCT_MELCO_PCOPRS1))
+		return (UMATCH_VENDOR_PRODUCT);
 
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(uftdi)
+static int
+uftdi_attach(device_t self)
 {
-	USB_ATTACH_START(uftdi, sc, uaa);
+	struct uftdi_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev = uaa->device;
 	usbd_interface_handle iface;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char *devinfo;
-	const char *devname;
 	int i;
 	usbd_status err;
 	struct ucom_softc *ucom = &sc->sc_ucom;
 	DPRINTFN(10,("\nuftdi_attach: sc=%p\n", sc));
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
 
 	ucom->sc_dev = self;
 	ucom->sc_udev = dev;
 
-	devname = USBDEVNAME(ucom->sc_dev);
-
 	if (uaa->iface == NULL) {
 		/* Move the device into the configured state. */
 		err = usbd_set_config_index(dev, UFTDI_CONFIG_INDEX, 1);
 		if (err) {
-			printf("\n%s: failed to set configuration, err=%s\n",
-			       devname, usbd_errstr(err));
+			device_printf(ucom->sc_dev,
+			    "failed to set configuration, err=%s\n",
+			    usbd_errstr(err));
 			goto bad;
 		}
 
 		err = usbd_device2interface_handle(dev, UFTDI_IFACE_INDEX, &iface);
 		if (err) {
-			printf("\n%s: failed to get interface, err=%s\n",
-			       devname, usbd_errstr(err));
+			device_printf(ucom->sc_dev,
+			    "failed to get interface, err=%s\n", usbd_errstr(err));
 			goto bad;
 		}
 	} else {
 		iface = uaa->iface;
 	}
 
-	usbd_devinfo(dev, 0, devinfo);
-	/*	USB_ATTACH_SETUP;*/
-	printf("%s: %s\n", devname, devinfo);
-
 	id = usbd_get_interface_descriptor(iface);
 	ucom->sc_iface = iface;
 	switch( uaa->vendor ){
@@ -242,11 +241,20 @@
 		case USB_PRODUCT_FTDI_CFA_632:
 		case USB_PRODUCT_FTDI_CFA_633:
 		case USB_PRODUCT_FTDI_CFA_634:
+		case USB_PRODUCT_FTDI_CFA_635:
 		case USB_PRODUCT_FTDI_USBSERIAL:
 		case USB_PRODUCT_FTDI_MX2_3:
 		case USB_PRODUCT_FTDI_MX4_5:
 		case USB_PRODUCT_FTDI_LK202:
 		case USB_PRODUCT_FTDI_LK204:
+		case USB_PRODUCT_FTDI_TACTRIX_OPENPORT_13M:
+		case USB_PRODUCT_FTDI_TACTRIX_OPENPORT_13S:
+		case USB_PRODUCT_FTDI_TACTRIX_OPENPORT_13U:
+		case USB_PRODUCT_FTDI_EISCOU:
+		case USB_PRODUCT_FTDI_UOPTBR:
+		case USB_PRODUCT_FTDI_EMCU2D:
+		case USB_PRODUCT_FTDI_PCMSFU:
+		case USB_PRODUCT_FTDI_EMCU2H:
 			sc->sc_type = UFTDI_TYPE_8U232AM;
 			sc->sc_hdrlen = 0;
 			break;
@@ -293,6 +301,18 @@
 		}
 		break;
 
+	case USB_VENDOR_MELCO:
+		switch( uaa->product ){
+		case USB_PRODUCT_MELCO_PCOPRS1:
+			sc->sc_type = UFTDI_TYPE_8U232AM;
+			sc->sc_hdrlen = 0;
+			break;
+
+		default:		/* Can't happen */
+			goto bad;
+		}
+		break;
+
 	default:		/* Can't happen */
 		goto bad;
 	}
@@ -303,8 +323,8 @@
 		int addr, dir, attr;
 		ed = usbd_interface2endpoint_descriptor(iface, i);
 		if (ed == NULL) {
-			printf("%s: could not read endpoint descriptor\n",
-			    devname);
+			device_printf(ucom->sc_dev,
+			    "could not read endpoint descriptor\n");
 			goto bad;
 		}
 
@@ -312,25 +332,23 @@
 		dir = UE_GET_DIR(ed->bEndpointAddress);
 		attr = ed->bmAttributes & UE_XFERTYPE;
 		if (dir == UE_DIR_IN && attr == UE_BULK)
-		  ucom->sc_bulkin_no = addr;
+			ucom->sc_bulkin_no = addr;
 		else if (dir == UE_DIR_OUT && attr == UE_BULK)
-		  ucom->sc_bulkout_no = addr;
+			ucom->sc_bulkout_no = addr;
 		else {
-		  printf("%s: unexpected endpoint\n", devname);
-		  goto bad;
+			device_printf(ucom->sc_dev, "unexpected endpoint\n");
+			goto bad;
 		}
 	}
 	if (ucom->sc_bulkin_no == -1) {
-		printf("%s: Could not find data bulk in\n",
-		       devname);
+		device_printf(ucom->sc_dev, "Could not find data bulk in\n");
 		goto bad;
 	}
 	if (ucom->sc_bulkout_no == -1) {
-		printf("%s: Could not find data bulk out\n",
-		       devname);
+		device_printf(ucom->sc_dev, "Could not find data bulk out\n");
 		goto bad;
 	}
-        ucom->sc_parent  = sc;
+	ucom->sc_parent  = sc;
 	if (uaa->iface == NULL)
 		ucom->sc_portno = FTDI_PIT_SIOA;
 	else
@@ -346,24 +364,20 @@
 	ucom->sc_callback = &uftdi_callback;
 #if 0
 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
-			   USBDEV(ucom->sc_dev));
+	  ucom->sc_dev);
 #endif
 	DPRINTF(("uftdi: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no));
 	ucom_attach(&sc->sc_ucom);
-	free(devinfo, M_USBDEV);
-
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
 bad:
 	DPRINTF(("uftdi_attach: ATTACH ERROR\n"));
 	ucom->sc_dying = 1;
-	free(devinfo, M_USBDEV);
-
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 #if 0
 int
-uftdi_activate(device_ptr_t self, enum devact act)
+uftdi_activate(device_t self, enum devact act)
 {
 	struct uftdi_softc *sc = (struct uftdi_softc *)self;
 	int rv = 0;
@@ -381,10 +395,11 @@
 	return (rv);
 }
 #endif
-#if 1
-USB_DETACH(uftdi)
+
+static int
+uftdi_detach(device_t self)
 {
-	USB_DETACH_START(uftdi, sc);
+	struct uftdi_softc *sc = device_get_softc(self);
 
 	int rv = 0;
 
@@ -394,8 +409,8 @@
 
 	return rv;
 }
-#endif
-Static int
+
+static int
 uftdi_open(void *vsc, int portno)
 {
 	struct uftdi_softc *sc = vsc;
@@ -437,7 +452,7 @@
 	return (0);
 }
 
-Static void
+static void
 uftdi_read(void *vsc, int portno, u_char **ptr, u_int32_t *count)
 {
 	struct uftdi_softc *sc = vsc;
@@ -470,7 +485,7 @@
 	*count -= 2;
 }
 
-Static void
+static void
 uftdi_write(void *vsc, int portno, u_char *to, u_char *from, u_int32_t *count)
 {
 	struct uftdi_softc *sc = vsc;
@@ -486,7 +501,7 @@
 	*count += sc->sc_hdrlen;
 }
 
-Static void
+static void
 uftdi_set(void *vsc, int portno, int reg, int onoff)
 {
 	struct uftdi_softc *sc = vsc;
@@ -521,7 +536,7 @@
 	(void)usbd_do_request(ucom->sc_udev, &req, NULL);
 }
 
-Static int
+static int
 uftdi_param(void *vsc, int portno, struct termios *t)
 {
 	struct uftdi_softc *sc = vsc;
@@ -687,7 +702,7 @@
 	(void)usbd_do_request(ucom->sc_udev, &req, NULL);
 }
 
-Static device_method_t uftdi_methods[] = {
+static device_method_t uftdi_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe, uftdi_match),
 	DEVMETHOD(device_attach, uftdi_attach),
@@ -696,7 +711,7 @@
 	{ 0, 0 }
 };
 
-Static driver_t uftdi_driver = {
+static driver_t uftdi_driver = {
 	"ucom",
 	uftdi_methods,
 	sizeof (struct uftdi_softc)
Index: uplcom.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uplcom.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/uplcom.c -L sys/dev/usb/uplcom.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/uplcom.c
+++ sys/dev/usb/uplcom.c
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uplcom.c,v 1.29 2005/07/03 23:51:16 hrs Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uplcom.c,v 1.50 2007/06/20 05:10:53 imp Exp $");
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -98,11 +98,7 @@
 #include <sys/serial.h>
 #include <sys/tty.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/proc.h>
 #include <sys/poll.h>
 #include <sys/sysctl.h>
@@ -130,7 +126,7 @@
 
 #define DPRINTFN(n, x)	do { \
 				if (uplcomdebug > (n)) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 #else
 #define DPRINTFN(n, x)
@@ -188,25 +184,25 @@
 #define UPLCOMIBUFSIZE 256
 #define UPLCOMOBUFSIZE 256
 
-Static	usbd_status uplcom_reset(struct uplcom_softc *);
-Static	usbd_status uplcom_set_line_coding(struct uplcom_softc *,
+static	usbd_status uplcom_reset(struct uplcom_softc *);
+static	usbd_status uplcom_set_line_coding(struct uplcom_softc *,
 					   usb_cdc_line_state_t *);
-Static	usbd_status uplcom_set_crtscts(struct uplcom_softc *);
-Static	void uplcom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static	usbd_status uplcom_set_crtscts(struct uplcom_softc *);
+static	void uplcom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
 
-Static	void uplcom_set(void *, int, int, int);
-Static	void uplcom_dtr(struct uplcom_softc *, int);
-Static	void uplcom_rts(struct uplcom_softc *, int);
-Static	void uplcom_break(struct uplcom_softc *, int);
-Static	void uplcom_set_line_state(struct uplcom_softc *);
-Static	void uplcom_get_status(void *, int, u_char *, u_char *);
-#if TODO
-Static	int  uplcom_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr);
+static	void uplcom_set(void *, int, int, int);
+static	void uplcom_dtr(struct uplcom_softc *, int);
+static	void uplcom_rts(struct uplcom_softc *, int);
+static	void uplcom_break(struct uplcom_softc *, int);
+static	void uplcom_set_line_state(struct uplcom_softc *);
+static	void uplcom_get_status(void *, int, u_char *, u_char *);
+#if 0 /* TODO */
+static	int  uplcom_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr);
 #endif
-Static	int  uplcom_param(void *, int, struct termios *);
-Static	int  uplcom_open(void *, int);
-Static	void uplcom_close(void *, int);
-Static	void uplcom_notify(void *, int);
+static	int  uplcom_param(void *, int, struct termios *);
+static	int  uplcom_open(void *, int);
+static	void uplcom_close(void *, int);
+static	void uplcom_notify(void *, int);
 
 struct ucom_callback uplcom_callback = {
 	uplcom_get_status,
@@ -224,15 +220,24 @@
 	uint16_t	product;
 	int32_t		release;	 /* release is a 16bit entity,
 					  * if -1 is specified we "don't care"
+					  * This is a floor value.  The table
+					  * must have newer revs before older
+					  * revs (and -1 last).
 					  */
 	char		chiptype;
 } uplcom_products [] = {
+	{ USB_VENDOR_RADIOSHACK, USB_PRODUCT_RADIOSHACK_USBCABLE, -1, TYPE_PL2303 },
+
 	/* I/O DATA USB-RSAQ */
 	{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBRSAQ, -1, TYPE_PL2303 },
+	/* Prolific Pharos */
+	{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PHAROS, -1, TYPE_PL2303 },
 	/* I/O DATA USB-RSAQ2 */
 	{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_RSAQ2, -1, TYPE_PL2303 },
 	/* I/O DATA USB-RSAQ3 */
 	{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_RSAQ3, -1, TYPE_PL2303X },
+	/* Willcom W-SIM*/
+	{ USB_VENDOR_PROLIFIC2, USB_PRODUCT_PROLIFIC2_WSIM, -1, TYPE_PL2303X},
 	/* PLANEX USB-RS232 URS-03 */
 	{ USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC232A, -1, TYPE_PL2303 },
 	/* ST Lab USB-SERIAL-4 */
@@ -247,6 +252,8 @@
 	/* ELECOM UC-SGT */
 	{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_UCSGT, -1, TYPE_PL2303 },
 	{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_UCSGT0, -1, TYPE_PL2303 },
+	/* Sagem USB-Serial Controller */
+	{ USB_VENDOR_SAGEM, USB_PRODUCT_SAGEM_USBSERIAL, -1, TYPE_PL2303X },
 	/* Sony Ericsson USB Cable */
 	{ USB_VENDOR_SONYERICSSON, USB_PRODUCT_SONYERICSSON_DCU10,
 	  -1,TYPE_PL2303 },
@@ -260,14 +267,16 @@
 	{ USB_VENDOR_HAL, USB_PRODUCT_HAL_IMR001, -1, TYPE_PL2303 },
 	/* Sitecom USB to Serial */
 	{ USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_SERIAL, -1, TYPE_PL2303 },
+	/* Tripp-Lite U209-000-R */
+	{ USB_VENDOR_TRIPPLITE, USB_PRODUCT_TRIPPLITE_U209, -1, TYPE_PL2303X },
 	{ 0, 0 }
 };
 
-Static device_probe_t uplcom_match;
-Static device_attach_t uplcom_attach;
-Static device_detach_t uplcom_detach;
+static device_probe_t uplcom_match;
+static device_attach_t uplcom_attach;
+static device_detach_t uplcom_detach;
 
-Static device_method_t uplcom_methods[] = {
+static device_method_t uplcom_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe, uplcom_match),
 	DEVMETHOD(device_attach, uplcom_attach),
@@ -275,7 +284,7 @@
 	{ 0, 0 }
 };
 
-Static driver_t uplcom_driver = {
+static driver_t uplcom_driver = {
 	"ucom",
 	uplcom_methods,
 	sizeof (struct uplcom_softc)
@@ -294,7 +303,7 @@
 	int err, val;
 
 	val = uplcominterval;
-	err = sysctl_handle_int(oidp, &val, sizeof(val), req);
+	err = sysctl_handle_int(oidp, &val, 0, req);
 	if (err != 0 || req->newptr == NULL)
 		return (err);
 	if (0 < val && val <= 1000)
@@ -309,9 +318,10 @@
 	    0, sizeof(int), sysctl_hw_usb_uplcom_interval,
 	    "I", "uplcom interrupt pipe interval");
 
-USB_MATCH(uplcom)
+static int
+uplcom_match(device_t self)
 {
-	USB_MATCH_START(uplcom, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	int i;
 
 	if (uaa->iface != NULL)
@@ -320,7 +330,7 @@
 	for (i = 0; uplcom_products[i].vendor != 0; i++) {
 		if (uplcom_products[i].vendor == uaa->vendor &&
 		    uplcom_products[i].product == uaa->product &&
-		    (uplcom_products[i].release == uaa->release ||
+		    (uplcom_products[i].release <= uaa->release ||
 		     uplcom_products[i].release == -1)) {
 			return (UMATCH_VENDOR_PRODUCT);
 		}
@@ -328,35 +338,26 @@
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(uplcom)
+static int
+uplcom_attach(device_t self)
 {
-	USB_ATTACH_START(uplcom, sc, uaa);
+	struct uplcom_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev = uaa->device;
 	struct ucom_softc *ucom;
 	usb_config_descriptor_t *cdesc;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char *devinfo;
 	const char *devname;
 	usbd_status err;
 	int i;
 
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
 	ucom = &sc->sc_ucom;
-
-	bzero(sc, sizeof (struct uplcom_softc));
-
-	usbd_devinfo(dev, 0, devinfo);
-	/* USB_ATTACH_SETUP; */
 	ucom->sc_dev = self;
-	device_set_desc_copy(self, devinfo);
-	/* USB_ATTACH_SETUP; */
-
 	ucom->sc_udev = dev;
 	ucom->sc_iface = uaa->iface;
 
-	devname = USBDEVNAME(ucom->sc_dev);
-	printf("%s: %s\n", devname, devinfo);
+	devname = device_get_nameunit(ucom->sc_dev);
 
 	DPRINTF(("uplcom attach: sc = %p\n", sc));
 
@@ -409,7 +410,7 @@
 
 	if (cdesc == NULL) {
 		printf("%s: failed to get configuration descriptor\n",
-			USBDEVNAME(ucom->sc_dev));
+			device_get_nameunit(ucom->sc_dev));
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -433,7 +434,7 @@
 		ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
 		if (ed == NULL) {
 			printf("%s: no endpoint descriptor for %d\n",
-				USBDEVNAME(ucom->sc_dev), i);
+				device_get_nameunit(ucom->sc_dev), i);
 			ucom->sc_dying = 1;
 			goto error;
 		}
@@ -447,7 +448,7 @@
 
 	if (sc->sc_intr_number == -1) {
 		printf("%s: Could not find interrupt in\n",
-			USBDEVNAME(ucom->sc_dev));
+			device_get_nameunit(ucom->sc_dev));
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -488,7 +489,7 @@
 		ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
 		if (ed == NULL) {
 			printf("%s: no endpoint descriptor for %d\n",
-				USBDEVNAME(ucom->sc_dev), i);
+				device_get_nameunit(ucom->sc_dev), i);
 			ucom->sc_dying = 1;
 			goto error;
 		}
@@ -504,14 +505,14 @@
 
 	if (ucom->sc_bulkin_no == -1) {
 		printf("%s: Could not find data bulk in\n",
-			USBDEVNAME(ucom->sc_dev));
+			device_get_nameunit(ucom->sc_dev));
 		ucom->sc_dying = 1;
 		goto error;
 	}
 
 	if (ucom->sc_bulkout_no == -1) {
 		printf("%s: Could not find data bulk out\n",
-			USBDEVNAME(ucom->sc_dev));
+			device_get_nameunit(ucom->sc_dev));
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -530,7 +531,7 @@
 
 	if (err) {
 		printf("%s: reset failed: %s\n",
-		       USBDEVNAME(ucom->sc_dev), usbd_errstr(err));
+		       device_get_nameunit(ucom->sc_dev), usbd_errstr(err));
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -540,18 +541,16 @@
 
 	TASK_INIT(&sc->sc_task, 0, uplcom_notify, sc);
 	ucom_attach(&sc->sc_ucom);
-
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
 error:
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
-USB_DETACH(uplcom)
+static int
+uplcom_detach(device_t self)
 {
-	USB_DETACH_START(uplcom, sc);
+	struct uplcom_softc *sc = device_get_softc(self);
 	int rv = 0;
 
 	DPRINTF(("uplcom_detach: sc = %p\n", sc));
@@ -570,7 +569,7 @@
 	return (rv);
 }
 
-Static usbd_status
+static usbd_status
 uplcom_reset(struct uplcom_softc *sc)
 {
 	usb_device_request_t req;
@@ -585,7 +584,7 @@
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, 0);
 	if (err) {
 		printf("%s: uplcom_reset: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 		return (EIO);
 	}
 
@@ -600,7 +599,7 @@
 	uint16_t	length;
 };
 
-Static const struct pl2303x_init pl2303x[] = {
+static const struct pl2303x_init pl2303x[] = {
 	{ UT_READ_VENDOR_DEVICE,  UPLCOM_SET_REQUEST, 0x8484,    0, 0 },
 	{ UT_WRITE_VENDOR_DEVICE, UPLCOM_SET_REQUEST, 0x0404,    0, 0 },
 	{ UT_READ_VENDOR_DEVICE,  UPLCOM_SET_REQUEST, 0x8484,    0, 0 },
@@ -615,7 +614,7 @@
 };
 #define N_PL2302X_INIT	(sizeof(pl2303x)/sizeof(pl2303x[0]))
 
-Static usbd_status
+static usbd_status
 uplcom_pl2303x_init(struct uplcom_softc *sc)
 {
 	usb_device_request_t req;
@@ -632,7 +631,7 @@
 		err = usbd_do_request(sc->sc_ucom.sc_udev, &req, 0);
 		if (err) {
 			printf("%s: uplcom_pl2303x_init: %d: %s\n",
-				USBDEVNAME(sc->sc_ucom.sc_dev), i,
+				device_get_nameunit(sc->sc_ucom.sc_dev), i,
 				usbd_errstr(err));
 			return (EIO);
 		}
@@ -641,7 +640,7 @@
 	return (0);
 }
 
-Static void
+static void
 uplcom_set_line_state(struct uplcom_softc *sc)
 {
 	usb_device_request_t req;
@@ -659,10 +658,10 @@
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, 0);
 	if (err)
 		printf("%s: uplcom_set_line_status: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 }
 
-Static void
+static void
 uplcom_set(void *addr, int portno, int reg, int onoff)
 {
 	struct uplcom_softc *sc = addr;
@@ -682,7 +681,7 @@
 	}
 }
 
-Static void
+static void
 uplcom_dtr(struct uplcom_softc *sc, int onoff)
 {
 	DPRINTF(("uplcom_dtr: onoff = %d\n", onoff));
@@ -694,7 +693,7 @@
 	uplcom_set_line_state(sc);
 }
 
-Static void
+static void
 uplcom_rts(struct uplcom_softc *sc, int onoff)
 {
 	DPRINTF(("uplcom_rts: onoff = %d\n", onoff));
@@ -706,7 +705,7 @@
 	uplcom_set_line_state(sc);
 }
 
-Static void
+static void
 uplcom_break(struct uplcom_softc *sc, int onoff)
 {
 	usb_device_request_t req;
@@ -723,10 +722,10 @@
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, 0);
 	if (err)
 		printf("%s: uplcom_break: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 }
 
-Static usbd_status
+static usbd_status
 uplcom_set_crtscts(struct uplcom_softc *sc)
 {
 	usb_device_request_t req;
@@ -746,14 +745,14 @@
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, 0);
 	if (err) {
 		printf("%s: uplcom_set_crtscts: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 		return (err);
 	}
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static usbd_status
+static usbd_status
 uplcom_set_line_coding(struct uplcom_softc *sc, usb_cdc_line_state_t *state)
 {
 	usb_device_request_t req;
@@ -778,7 +777,7 @@
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, state);
 	if (err) {
 		printf("%s: uplcom_set_line_coding: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_ucom.sc_dev), usbd_errstr(err));
 		return (err);
 	}
 
@@ -787,7 +786,7 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static const int uplcom_rates[] = {
+static const int uplcom_rates[] = {
 	75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600, 14400,
 	19200, 28800, 38400, 57600, 115200,
 	/*
@@ -798,7 +797,7 @@
 };
 #define N_UPLCOM_RATES	(sizeof(uplcom_rates)/sizeof(uplcom_rates[0]))
 
-Static int
+static int
 uplcom_param(void *addr, int portno, struct termios *t)
 {
 	struct uplcom_softc *sc = addr;
@@ -857,7 +856,7 @@
 	return (0);
 }
 
-Static int
+static int
 uplcom_open(void *addr, int portno)
 {
 	struct uplcom_softc *sc = addr;
@@ -882,7 +881,7 @@
 					  uplcominterval);
 		if (err) {
 			printf("%s: cannot open interrupt pipe (addr %d)\n",
-			       USBDEVNAME(sc->sc_ucom.sc_dev),
+			       device_get_nameunit(sc->sc_ucom.sc_dev),
 			       sc->sc_intr_number);
 			return (EIO);
 		}
@@ -894,7 +893,7 @@
 	return (0);
 }
 
-Static void
+static void
 uplcom_close(void *addr, int portno)
 {
 	struct uplcom_softc *sc = addr;
@@ -909,19 +908,19 @@
 		err = usbd_abort_pipe(sc->sc_intr_pipe);
 		if (err)
 			printf("%s: abort interrupt pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_ucom.sc_dev),
+			       device_get_nameunit(sc->sc_ucom.sc_dev),
 			       usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_intr_pipe);
 		if (err)
 			printf("%s: close interrupt pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_ucom.sc_dev),
+			       device_get_nameunit(sc->sc_ucom.sc_dev),
 			       usbd_errstr(err));
 		free(sc->sc_intr_buf, M_USBDEV);
 		sc->sc_intr_pipe = NULL;
 	}
 }
 
-Static void
+static void
 uplcom_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct uplcom_softc *sc = priv;
@@ -936,14 +935,14 @@
 			return;
 
 		DPRINTF(("%s: uplcom_intr: abnormal status: %s\n",
-			USBDEVNAME(sc->sc_ucom.sc_dev),
+			device_get_nameunit(sc->sc_ucom.sc_dev),
 			usbd_errstr(status)));
 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
 		return;
 	}
 
 	DPRINTF(("%s: uplcom status = %02x\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), buf[8]));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), buf[8]));
 
 	sc->sc_lsr = sc->sc_msr = 0;
 	pstatus = buf[8];
@@ -964,7 +963,7 @@
 	taskqueue_enqueue(taskqueue_swi_giant, &sc->sc_task);
 }
 
-Static void
+static void
 uplcom_notify(void *arg, int count)
 {
 	struct uplcom_softc *sc;
@@ -975,7 +974,7 @@
 	ucom_status_change(&sc->sc_ucom);
 }
 
-Static void
+static void
 uplcom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
 {
 	struct uplcom_softc *sc = addr;
@@ -988,10 +987,10 @@
 		*msr = sc->sc_msr;
 }
 
-#if TODO
-Static int
+#if 0 /* TODO */
+static int
 uplcom_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
-	     usb_proc_ptr p)
+	     struct thread *p)
 {
 	struct uplcom_softc *sc = addr;
 	int error = 0;
Index: usb_mem.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_mem.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usb_mem.c -L sys/dev/usb/usb_mem.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usb_mem.c
+++ sys/dev/usb/usb_mem.c
@@ -1,5 +1,5 @@
 /*	$NetBSD: usb_mem.c,v 1.26 2003/02/01 06:23:40 thorpej Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/usb_mem.c,v 1.7 2005/01/06 01:43:29 imp Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/usb_mem.c,v 1.13 2007/06/20 05:10:53 imp Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -46,20 +46,15 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/usb_mem.c,v 1.7 2005/01/06 01:43:29 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/usb_mem.c,v 1.13 2007/06/20 05:10:53 imp Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
 #include <sys/kernel.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>		/* for usbdivar.h */
-#include <machine/bus.h>
-#elif defined(__FreeBSD__)
 #include <sys/endian.h>
 #include <sys/module.h>
 #include <sys/bus.h>
-#endif
 #include <sys/queue.h>
 
 #include <machine/bus.h>
@@ -75,8 +70,8 @@
 #include <dev/usb/usb_mem.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (usbdebug) logprintf x
-#define DPRINTFN(n,x)	if (usbdebug>(n)) logprintf x
+#define DPRINTF(x)	if (usbdebug) printf x
+#define DPRINTFN(n,x)	if (usbdebug>(n)) printf x
 extern int usbdebug;
 #else
 #define DPRINTF(x)
@@ -94,19 +89,19 @@
 	LIST_ENTRY(usb_frag_dma) next;
 };
 
-Static bus_dmamap_callback_t usbmem_callback;
-Static usbd_status	usb_block_allocmem(bus_dma_tag_t, size_t, size_t,
+static bus_dmamap_callback_t usbmem_callback;
+static usbd_status	usb_block_allocmem(bus_dma_tag_t, size_t, size_t,
 					   usb_dma_block_t **);
-Static void		usb_block_freemem(usb_dma_block_t *);
+static void		usb_block_freemem(usb_dma_block_t *);
 
-Static LIST_HEAD(, usb_dma_block) usb_blk_freelist =
+static LIST_HEAD(, usb_dma_block) usb_blk_freelist =
 	LIST_HEAD_INITIALIZER(usb_blk_freelist);
-Static int usb_blk_nfree = 0;
+static int usb_blk_nfree = 0;
 /* XXX should have different free list for different tags (for speed) */
-Static LIST_HEAD(, usb_frag_dma) usb_frag_freelist =
+static LIST_HEAD(, usb_frag_dma) usb_frag_freelist =
 	LIST_HEAD_INITIALIZER(usb_frag_freelist);
 
-Static void
+static void
 usbmem_callback(void *arg, bus_dma_segment_t *segs, int nseg, int error)
 {
 	int i;
@@ -122,7 +117,7 @@
 		p->segs[i] = segs[i];
 }
 
-Static usbd_status
+static usbd_status
 usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align,
 		   usb_dma_block_t **dmap)
 {
@@ -167,17 +162,10 @@
 	if (p == NULL)
 		return (USBD_NOMEM);
 
-#if __FreeBSD_version >= 500000
 	if (bus_dma_tag_create(tag, align, 0,
 	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
 	    size, sizeof(p->segs) / sizeof(p->segs[0]), size,
-	    BUS_DMA_ALLOCNOW, NULL, NULL, &p->tag) == ENOMEM)
-#else
-	if (bus_dma_tag_create(tag, align, 0,
-	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
-	    size, sizeof(p->segs) / sizeof(p->segs[0]), size,
-	    BUS_DMA_ALLOCNOW, &p->tag) == ENOMEM)
-#endif
+	    0, NULL, NULL, &p->tag) == ENOMEM)
 	{
 		goto free;
 	}
@@ -215,7 +203,7 @@
  * from an interrupt context and that is BAD.
  * XXX when should we really free?
  */
-Static void
+static void
 usb_block_freemem(usb_dma_block_t *p)
 {
 	int s;
@@ -230,7 +218,7 @@
 usbd_status
 usb_allocmem(usbd_bus_handle bus, size_t size, size_t align, usb_dma_t *p)
 {
-	bus_dma_tag_t tag = bus->dmatag;
+	bus_dma_tag_t tag = bus->parent_dmatag;
 	usbd_status err;
 	struct usb_frag_dma *f;
 	usb_dma_block_t *b;
Index: uvscom.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uvscom.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/uvscom.c -L sys/dev/usb/uvscom.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/uvscom.c
+++ sys/dev/usb/uvscom.c
@@ -27,11 +27,11 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uvscom.c,v 1.25 2005/01/31 13:58:10 akiyama Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uvscom.c,v 1.41 2007/07/05 06:28:46 imp Exp $");
 
 /*
  * uvscom: SUNTAC Slipper U VS-10U driver.
- * Slipper U is a PC card to USB converter for data communication card
+ * Slipper U is a PC Card to USB converter for data communication card
  * adapter.  It supports DDI Pocket's Air H" C at rd, C at rd H" 64, NTT's P-in,
  * P-in m at ater and various data communication card adapters.
  */
@@ -48,18 +48,9 @@
 #include <sys/serial.h>
 #include <sys/tty.h>
 #include <sys/file.h>
-#if defined(__FreeBSD__)
 #include <sys/bus.h>
 #include <sys/ioccom.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
-#else
-#include <sys/ioctl.h>
-#include <sys/device.h>
-#endif
 #include <sys/proc.h>
 #include <sys/poll.h>
 #include <sys/sysctl.h>
@@ -83,7 +74,7 @@
 
 #define DPRINTFN(n, x) do { \
 				if (uvscomdebug > (n)) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 #else
 #define DPRINTFN(n, x)
@@ -190,26 +181,26 @@
 #define UVSCOM_DEFAULT_OPKTSIZE	8
 #endif
 
-Static	usbd_status uvscom_shutdown(struct uvscom_softc *);
-Static	usbd_status uvscom_reset(struct uvscom_softc *);
-Static	usbd_status uvscom_set_line_coding(struct uvscom_softc *,
+static	usbd_status uvscom_shutdown(struct uvscom_softc *);
+static	usbd_status uvscom_reset(struct uvscom_softc *);
+static	usbd_status uvscom_set_line_coding(struct uvscom_softc *,
 					   uint16_t, uint16_t);
-Static	usbd_status uvscom_set_line(struct uvscom_softc *, uint16_t);
-Static	usbd_status uvscom_set_crtscts(struct uvscom_softc *);
-Static	void uvscom_get_status(void *, int, u_char *, u_char *);
-Static	void uvscom_dtr(struct uvscom_softc *, int);
-Static	void uvscom_rts(struct uvscom_softc *, int);
-Static	void uvscom_break(struct uvscom_softc *, int);
-
-Static	void uvscom_set(void *, int, int, int);
-Static	void uvscom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
-#if TODO
-Static	int  uvscom_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr);
+static	usbd_status uvscom_set_line(struct uvscom_softc *, uint16_t);
+static	usbd_status uvscom_set_crtscts(struct uvscom_softc *);
+static	void uvscom_get_status(void *, int, u_char *, u_char *);
+static	void uvscom_dtr(struct uvscom_softc *, int);
+static	void uvscom_rts(struct uvscom_softc *, int);
+static	void uvscom_break(struct uvscom_softc *, int);
+
+static	void uvscom_set(void *, int, int, int);
+static	void uvscom_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+#if 0 /* TODO */
+static	int  uvscom_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr);
 #endif
-Static	int  uvscom_param(void *, int, struct termios *);
-Static	int  uvscom_open(void *, int);
-Static	void uvscom_close(void *, int);
-Static	void uvscom_notify(void *, int);
+static	int  uvscom_param(void *, int, struct termios *);
+static	int  uvscom_open(void *, int);
+static	void uvscom_close(void *, int);
+static	void uvscom_notify(void *, int);
 
 struct ucom_callback uvscom_callback = {
 	uvscom_get_status,
@@ -236,11 +227,11 @@
 };
 #define uvscom_lookup(v, p) usb_lookup(uvscom_devs, v, p)
 
-Static device_probe_t uvscom_match;
-Static device_attach_t uvscom_attach;
-Static device_detach_t uvscom_detach;
+static device_probe_t uvscom_match;
+static device_attach_t uvscom_attach;
+static device_detach_t uvscom_detach;
 
-Static device_method_t uvscom_methods[] = {
+static device_method_t uvscom_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe, uvscom_match),
 	DEVMETHOD(device_attach, uvscom_attach),
@@ -248,7 +239,7 @@
 	{ 0, 0 }
 };
 
-Static driver_t uvscom_driver = {
+static driver_t uvscom_driver = {
 	"ucom",
 	uvscom_methods,
 	sizeof (struct uvscom_softc)
@@ -268,7 +259,7 @@
 	int err, val;
 
 	val = uvscomobufsiz;
-	err = sysctl_handle_int(oidp, &val, sizeof(val), req);
+	err = sysctl_handle_int(oidp, &val, 0, req);
 	if (err != 0 || req->newptr == NULL)
 		return (err);
 	if (0 < val && val <= UVSCOMOBUFSIZE)
@@ -285,7 +276,7 @@
 	int err, val;
 
 	val = uvscominterval;
-	err = sysctl_handle_int(oidp, &val, sizeof(val), req);
+	err = sysctl_handle_int(oidp, &val, 0, req);
 	if (err != 0 || req->newptr == NULL)
 		return (err);
 	if (0 < val && val <= 1000)
@@ -303,9 +294,10 @@
 	    0, sizeof(int), sysctl_hw_usb_uvscom_interval,
 	    "I", "uvscom interrpt pipe interval");
 
-USB_MATCH(uvscom)
+static int
+uvscom_match(device_t self)
 {
-	USB_MATCH_START(uvscom, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 
 	if (uaa->iface != NULL)
 		return (UMATCH_NONE);
@@ -314,36 +306,24 @@
 		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
 }
 
-USB_ATTACH(uvscom)
+static int
+uvscom_attach(device_t self)
 {
-	USB_ATTACH_START(uvscom, sc, uaa);
+	struct uvscom_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev = uaa->device;
 	struct ucom_softc *ucom;
 	usb_config_descriptor_t *cdesc;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char *devinfo;
-	const char *devname;
 	usbd_status err;
 	int i;
 
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
 	ucom = &sc->sc_ucom;
-
-	bzero(sc, sizeof (struct uvscom_softc));
-
-	usbd_devinfo(dev, 0, devinfo);
-	/* USB_ATTACH_SETUP; */
 	ucom->sc_dev = self;
-	device_set_desc_copy(self, devinfo);
-	/* USB_ATTACH_SETUP; */
-
 	ucom->sc_udev = dev;
 	ucom->sc_iface = uaa->iface;
 
-	devname = USBDEVNAME(ucom->sc_dev);
-	printf("%s: %s\n", devname, devinfo);
-
 	DPRINTF(("uvscom attach: sc = %p\n", sc));
 
 	/* initialize endpoints */
@@ -354,8 +334,8 @@
 	/* Move the device into the configured state. */
 	err = usbd_set_config_index(dev, UVSCOM_CONFIG_INDEX, 1);
 	if (err) {
-		printf("%s: failed to set configuration, err=%s\n",
-			devname, usbd_errstr(err));
+		device_printf(self, "failed to set configuration, err=%s\n",
+		    usbd_errstr(err));
 		goto error;
 	}
 
@@ -363,8 +343,7 @@
 	cdesc = usbd_get_config_descriptor(ucom->sc_udev);
 
 	if (cdesc == NULL) {
-		printf("%s: failed to get configuration descriptor\n",
-			USBDEVNAME(ucom->sc_dev));
+		device_printf(self, "failed to get configuration descriptor\n");
 		goto error;
 	}
 
@@ -372,8 +351,8 @@
 	err = usbd_device2interface_handle(dev, UVSCOM_IFACE_INDEX,
 					   &ucom->sc_iface);
 	if (err) {
-		printf("%s: failed to get interface, err=%s\n",
-			devname, usbd_errstr(err));
+		device_printf(self, "failed to get interface, err=%s\n",
+		    usbd_errstr(err));
 		goto error;
 	}
 
@@ -384,8 +363,8 @@
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
 		if (ed == NULL) {
-			printf("%s: no endpoint descriptor for %d\n",
-				USBDEVNAME(ucom->sc_dev), i);
+			device_printf(self, "no endpoint descriptor for %d\n",
+			    i);
 			goto error;
 		}
 
@@ -403,18 +382,15 @@
 	}
 
 	if (ucom->sc_bulkin_no == -1) {
-		printf("%s: Could not find data bulk in\n",
-			USBDEVNAME(ucom->sc_dev));
+		device_printf(self, "Could not find data bulk in\n");
 		goto error;
 	}
 	if (ucom->sc_bulkout_no == -1) {
-		printf("%s: Could not find data bulk out\n",
-			USBDEVNAME(ucom->sc_dev));
+		device_printf(self, "Could not find data bulk out\n");
 		goto error;
 	}
 	if (sc->sc_intr_number == -1) {
-		printf("%s: Could not find interrupt in\n",
-			USBDEVNAME(ucom->sc_dev));
+		device_printf(self, "Could not find interrupt in\n");
 		goto error;
 	}
 
@@ -433,8 +409,7 @@
 	err = uvscom_reset(sc);
 
 	if (err) {
-		printf("%s: reset failed, %s\n", USBDEVNAME(ucom->sc_dev),
-			usbd_errstr(err));
+		device_printf(self, "reset failed, %s\n", usbd_errstr(err));
 		goto error;
 	}
 
@@ -443,19 +418,17 @@
 
 	TASK_INIT(&sc->sc_task, 0, uvscom_notify, sc);
 	ucom_attach(&sc->sc_ucom);
-
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
 error:
 	ucom->sc_dying = 1;
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
-USB_DETACH(uvscom)
+static int
+uvscom_detach(device_t self)
 {
-	USB_DETACH_START(uvscom, sc);
+	struct uvscom_softc *sc = device_get_softc(self);
 	int rv = 0;
 
 	DPRINTF(("uvscom_detach: sc = %p\n", sc));
@@ -474,14 +447,14 @@
 	return (rv);
 }
 
-Static usbd_status
+static usbd_status
 uvscom_readstat(struct uvscom_softc *sc)
 {
 	usb_device_request_t req;
 	usbd_status err;
 	uint16_t r;
 
-	DPRINTF(("%s: send readstat\n", USBDEVNAME(sc->sc_ucom.sc_dev)));
+	DPRINTF(("%s: send readstat\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
 
 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
 	req.bRequest = UVSCOM_READ_STATUS;
@@ -491,24 +464,24 @@
 
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, &r);
 	if (err) {
-		printf("%s: uvscom_readstat: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		device_printf(sc->sc_ucom.sc_dev, "uvscom_readstat: %s\n",
+		    usbd_errstr(err));
 		return (err);
 	}
 
 	DPRINTF(("%s: uvscom_readstat: r = %d\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), r));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), r));
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static usbd_status
+static usbd_status
 uvscom_shutdown(struct uvscom_softc *sc)
 {
 	usb_device_request_t req;
 	usbd_status err;
 
-	DPRINTF(("%s: send shutdown\n", USBDEVNAME(sc->sc_ucom.sc_dev)));
+	DPRINTF(("%s: send shutdown\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
 
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
 	req.bRequest = UVSCOM_SHUTDOWN;
@@ -518,38 +491,38 @@
 
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
 	if (err) {
-		printf("%s: uvscom_shutdown: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		device_printf(sc->sc_ucom.sc_dev, "uvscom_shutdown: %s\n",
+		    usbd_errstr(err));
 		return (err);
 	}
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static usbd_status
+static usbd_status
 uvscom_reset(struct uvscom_softc *sc)
 {
-	DPRINTF(("%s: uvscom_reset\n", USBDEVNAME(sc->sc_ucom.sc_dev)));
+	DPRINTF(("%s: uvscom_reset\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static usbd_status
+static usbd_status
 uvscom_set_crtscts(struct uvscom_softc *sc)
 {
-	DPRINTF(("%s: uvscom_set_crtscts\n", USBDEVNAME(sc->sc_ucom.sc_dev)));
+	DPRINTF(("%s: uvscom_set_crtscts\n", device_get_nameunit(sc->sc_ucom.sc_dev)));
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static usbd_status
+static usbd_status
 uvscom_set_line(struct uvscom_softc *sc, uint16_t line)
 {
 	usb_device_request_t req;
 	usbd_status err;
 
 	DPRINTF(("%s: uvscom_set_line: %04x\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), line));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), line));
 
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
 	req.bRequest = UVSCOM_LINE_CTL;
@@ -559,22 +532,22 @@
 
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
 	if (err) {
-		printf("%s: uvscom_set_line: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		device_printf(sc->sc_ucom.sc_dev, "uvscom_set_line: %s\n",
+		    usbd_errstr(err));
 		return (err);
 	}
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static usbd_status
+static usbd_status
 uvscom_set_line_coding(struct uvscom_softc *sc, uint16_t lsp, uint16_t ls)
 {
 	usb_device_request_t req;
 	usbd_status err;
 
 	DPRINTF(("%s: uvscom_set_line_coding: %02x %02x\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), lsp, ls));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), lsp, ls));
 
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
 	req.bRequest = UVSCOM_SET_SPEED;
@@ -584,8 +557,8 @@
 
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
 	if (err) {
-		printf("%s: uvscom_set_line_coding: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		device_printf(sc->sc_ucom.sc_dev, "uvscom_set_line_coding: %s\n",
+		    usbd_errstr(err));
 		return (err);
 	}
 
@@ -597,19 +570,19 @@
 
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, NULL);
 	if (err) {
-		printf("%s: uvscom_set_line_coding: %s\n",
-		       USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		device_printf(sc->sc_ucom.sc_dev, "uvscom_set_line_coding: %s\n",
+		    usbd_errstr(err));
 		return (err);
 	}
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static void
+static void
 uvscom_dtr(struct uvscom_softc *sc, int onoff)
 {
 	DPRINTF(("%s: uvscom_dtr: onoff = %d\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), onoff));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
 
 	if (sc->sc_dtr == onoff)
 		return;			/* no change */
@@ -624,11 +597,11 @@
 	uvscom_set_line(sc, sc->sc_lcr);
 }
 
-Static void
+static void
 uvscom_rts(struct uvscom_softc *sc, int onoff)
 {
 	DPRINTF(("%s: uvscom_rts: onoff = %d\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), onoff));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
 
 	if (sc->sc_rts == onoff)
 		return;			/* no change */
@@ -643,17 +616,17 @@
 	uvscom_set_line(sc, sc->sc_lcr);
 }
 
-Static void
+static void
 uvscom_break(struct uvscom_softc *sc, int onoff)
 {
 	DPRINTF(("%s: uvscom_break: onoff = %d\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), onoff));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), onoff));
 
 	if (onoff)
 		uvscom_set_line(sc, SET(sc->sc_lcr, UVSCOM_BREAK));
 }
 
-Static void
+static void
 uvscom_set(void *addr, int portno, int reg, int onoff)
 {
 	struct uvscom_softc *sc = addr;
@@ -673,7 +646,7 @@
 	}
 }
 
-Static int
+static int
 uvscom_param(void *addr, int portno, struct termios *t)
 {
 	struct uvscom_softc *sc = addr;
@@ -682,7 +655,7 @@
 	uint16_t ls;
 
 	DPRINTF(("%s: uvscom_param: sc = %p\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), sc));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), sc));
 
 	ls = 0;
 
@@ -767,7 +740,7 @@
 	return (0);
 }
 
-Static int
+static int
 uvscom_open(void *addr, int portno)
 {
 	struct uvscom_softc *sc = addr;
@@ -790,7 +763,7 @@
 		err = uvscom_readstat(sc);
 		if (err) {
 			DPRINTF(("%s: uvscom_open: readstat faild\n",
-				 USBDEVNAME(sc->sc_ucom.sc_dev)));
+				 device_get_nameunit(sc->sc_ucom.sc_dev)));
 			return (ENXIO);
 		}
 
@@ -805,9 +778,9 @@
 					  uvscom_intr,
 					  uvscominterval);
 		if (err) {
-			printf("%s: cannot open interrupt pipe (addr %d)\n",
-				 USBDEVNAME(sc->sc_ucom.sc_dev),
-				 sc->sc_intr_number);
+			device_printf(sc->sc_ucom.sc_dev,
+			    "cannot open interrupt pipe (addr %d)\n",
+			    sc->sc_intr_number);
 			return (ENXIO);
 		}
 	} else {
@@ -818,20 +791,20 @@
 		/* unit is not ready */
 
 		for (i = UVSCOM_UNIT_WAIT; i > 0; --i) {
-			tsleep(&err, TTIPRI, "uvsop", hz);	/* XXX */
+			pause("uvsop", hz);	/* XXX */
 			if (ISSET(sc->sc_usr, UVSCOM_USTAT_MASK))
 				break;
 		}
 		if (i == 0) {
 			DPRINTF(("%s: unit is not ready\n",
-				 USBDEVNAME(sc->sc_ucom.sc_dev)));
+				 device_get_nameunit(sc->sc_ucom.sc_dev)));
 			return (ENXIO);
 		}
 
-		/* check PC card was inserted */
+		/* check PC Card was inserted */
 		if (ISSET(sc->sc_usr, UVSCOM_NOCARD)) {
 			DPRINTF(("%s: no card\n",
-				 USBDEVNAME(sc->sc_ucom.sc_dev)));
+				 device_get_nameunit(sc->sc_ucom.sc_dev)));
 			return (ENXIO);
 		}
 	}
@@ -839,7 +812,7 @@
 	return (0);
 }
 
-Static void
+static void
 uvscom_close(void *addr, int portno)
 {
 	struct uvscom_softc *sc = addr;
@@ -855,20 +828,20 @@
 	if (sc->sc_intr_pipe != NULL) {
 		err = usbd_abort_pipe(sc->sc_intr_pipe);
 		if (err)
-			printf("%s: abort interrupt pipe failed: %s\n",
-				USBDEVNAME(sc->sc_ucom.sc_dev),
-					   usbd_errstr(err));
+			device_printf(sc->sc_ucom.sc_dev,
+			    "abort interrupt pipe failed: %s\n",
+			    usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_intr_pipe);
 		if (err)
-			printf("%s: close interrupt pipe failed: %s\n",
-				USBDEVNAME(sc->sc_ucom.sc_dev),
-					   usbd_errstr(err));
+			device_printf(sc->sc_ucom.sc_dev,
+			    "close interrupt pipe failed: %s\n",
+			    usbd_errstr(err));
 		free(sc->sc_intr_buf, M_USBDEV);
 		sc->sc_intr_pipe = NULL;
 	}
 }
 
-Static void
+static void
 uvscom_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct uvscom_softc *sc = priv;
@@ -882,15 +855,15 @@
 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
 			return;
 
-		printf("%s: uvscom_intr: abnormal status: %s\n",
-			USBDEVNAME(sc->sc_ucom.sc_dev),
-			usbd_errstr(status));
+		device_printf(sc->sc_ucom.sc_dev,	
+		    "uvscom_intr: abnormal status: %s\n",
+		    usbd_errstr(status));
 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
 		return;
 	}
 
 	DPRINTFN(2, ("%s: uvscom status = %02x %02x\n",
-		 USBDEVNAME(sc->sc_ucom.sc_dev), buf[0], buf[1]));
+		 device_get_nameunit(sc->sc_ucom.sc_dev), buf[0], buf[1]));
 
 	sc->sc_lsr = sc->sc_msr = 0;
 	sc->sc_usr = buf[1];
@@ -913,7 +886,7 @@
 	taskqueue_enqueue(taskqueue_swi_giant, &sc->sc_task);
 }
 
-Static void
+static void
 uvscom_notify(void *arg, int count)
 {
 	struct uvscom_softc *sc;
@@ -924,7 +897,7 @@
 	ucom_status_change(&sc->sc_ucom);
 }
 
-Static void
+static void
 uvscom_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
 {
 	struct uvscom_softc *sc = addr;
@@ -935,10 +908,10 @@
 		*msr = sc->sc_msr;
 }
 
-#if TODO
-Static int
+#if 0 /* TODO */
+static int
 uvscom_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
-	     usb_proc_ptr p)
+	     struct thread *p)
 {
 	struct uvscom_softc *sc = addr;
 	int error = 0;
Index: if_uralvar.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_uralvar.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/if_uralvar.h -L sys/dev/usb/if_uralvar.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/if_uralvar.h
+++ sys/dev/usb/if_uralvar.h
@@ -1,7 +1,7 @@
-/*	$FreeBSD: src/sys/dev/usb/if_uralvar.h,v 1.3.2.3 2006/01/29 14:16:36 damien Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/if_uralvar.h,v 1.9 2007/06/11 03:36:52 sam Exp $	*/
 
 /*-
- * Copyright (c) 2005, 2006
+ * Copyright (c) 2005
  *	Damien Bergamini <damien.bergamini at free.fr>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -20,6 +20,11 @@
 #define RAL_RX_LIST_COUNT	1
 #define RAL_TX_LIST_COUNT	1
 
+#define URAL_SCAN_START         1
+#define URAL_SCAN_END           2
+#define URAL_SET_CHANNEL        3
+
+
 struct ural_rx_radiotap_header {
 	struct ieee80211_radiotap_header wr_ihdr;
 	uint8_t		wr_flags;
@@ -69,20 +74,12 @@
 	struct mbuf		*m;
 };
 
-struct ural_amrr {
-	int	txcnt;
-	int	retrycnt;
-	int	success;
-	int	success_threshold;
-	int	recovery;
-};
-
 struct ural_softc {
 	struct ifnet			*sc_ifp;
 	struct ieee80211com		sc_ic;
 	int				(*sc_newstate)(struct ieee80211com *,
 					    enum ieee80211_state, int);
-	USBBASEDEVICE			sc_dev;
+	device_t			sc_dev;
 	usbd_device_handle		sc_udev;
 	usbd_interface_handle		sc_iface;
 
@@ -98,9 +95,13 @@
 	usbd_pipe_handle		sc_tx_pipeh;
 
 	enum ieee80211_state		sc_state;
+	int				sc_arg;
+	int                             sc_scan_action; /* should be an enum */
 	struct usb_task			sc_task;
+	struct usb_task			sc_scantask;
 
-	struct ural_amrr		amrr;
+	struct ieee80211_amrr		amrr;
+	struct ieee80211_amrr_node	amn;
 
 	struct ural_rx_data		rx_data[RAL_RX_LIST_COUNT];
 	struct ural_tx_data		tx_data[RAL_TX_LIST_COUNT];
@@ -110,9 +111,8 @@
 
 	struct mtx			sc_mtx;
 
-	struct callout			scan_ch;
+	struct callout			watchdog_ch;
 	struct callout			amrr_ch;
-
 	int				sc_tx_timer;
 
 	uint16_t			sta[11];
Index: uxb360gp_rdesc.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uxb360gp_rdesc.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/uxb360gp_rdesc.h -L sys/dev/usb/uxb360gp_rdesc.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/uxb360gp_rdesc.h
+++ sys/dev/usb/uxb360gp_rdesc.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/uxb360gp_rdesc.h,v 1.2.2.1 2006/01/20 22:47:49 mux Exp $
+ * $FreeBSD: src/sys/dev/usb/uxb360gp_rdesc.h,v 1.2 2005/12/31 04:38:50 mux Exp $
  */
 
 /*
Index: ubsa.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ubsa.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ubsa.c -L sys/dev/usb/ubsa.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ubsa.c
+++ sys/dev/usb/ubsa.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ubsa.c,v 1.17 2005/01/06 01:43:28 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ubsa.c,v 1.32 2007/06/22 05:56:05 imp Exp $");
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -74,11 +74,7 @@
 #include <sys/conf.h>
 #include <sys/tty.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/proc.h>
 #include <sys/poll.h>
 #include <sys/sysctl.h>
@@ -94,14 +90,14 @@
 #include <dev/usb/ucomvar.h>
 
 #ifdef USB_DEBUG
-Static int	ubsadebug = 0;
+static int	ubsadebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, ubsa, CTLFLAG_RW, 0, "USB ubsa");
 SYSCTL_INT(_hw_usb_ubsa, OID_AUTO, debug, CTLFLAG_RW,
 	   &ubsadebug, 0, "ubsa debug level");
 
 #define	DPRINTFN(n, x)	do { \
 				if (ubsadebug > (n)) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 #else
 #define	DPRINTFN(n, x)
@@ -181,23 +177,23 @@
 	struct task		sc_task;
 };
 
-Static	void ubsa_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static	void ubsa_notify(void *, int count);
+static	void ubsa_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static	void ubsa_notify(void *, int count);
 
-Static	void ubsa_get_status(void *, int, u_char *, u_char *);
-Static	void ubsa_set(void *, int, int, int);
-Static	int  ubsa_param(void *, int, struct termios *);
-Static	int  ubsa_open(void *, int);
-Static	void ubsa_close(void *, int);
-
-Static	int  ubsa_request(struct ubsa_softc *, u_int8_t, u_int16_t);
-Static	void ubsa_dtr(struct ubsa_softc *, int);
-Static	void ubsa_rts(struct ubsa_softc *, int);
-Static	void ubsa_baudrate(struct ubsa_softc *, speed_t);
-Static	void ubsa_parity(struct ubsa_softc *, tcflag_t);
-Static	void ubsa_databits(struct ubsa_softc *, tcflag_t);
-Static	void ubsa_stopbits(struct ubsa_softc *, tcflag_t);
-Static	void ubsa_flow(struct ubsa_softc *, tcflag_t, tcflag_t);
+static	void ubsa_get_status(void *, int, u_char *, u_char *);
+static	void ubsa_set(void *, int, int, int);
+static	int  ubsa_param(void *, int, struct termios *);
+static	int  ubsa_open(void *, int);
+static	void ubsa_close(void *, int);
+
+static	int  ubsa_request(struct ubsa_softc *, u_int8_t, u_int16_t);
+static	void ubsa_dtr(struct ubsa_softc *, int);
+static	void ubsa_rts(struct ubsa_softc *, int);
+static	void ubsa_baudrate(struct ubsa_softc *, speed_t);
+static	void ubsa_parity(struct ubsa_softc *, tcflag_t);
+static	void ubsa_databits(struct ubsa_softc *, tcflag_t);
+static	void ubsa_stopbits(struct ubsa_softc *, tcflag_t);
+static	void ubsa_flow(struct ubsa_softc *, tcflag_t, tcflag_t);
 
 struct ucom_callback ubsa_callback = {
 	ubsa_get_status,
@@ -210,10 +206,12 @@
 	NULL
 };
 
-Static const struct ubsa_product {
+static const struct ubsa_product {
 	uint16_t	vendor;
 	uint16_t	product;
 } ubsa_products [] = {
+	/* AnyData ADU-E100A/H */
+	{ USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_ADU_E100X },
 	/* BELKIN F5U103 */
 	{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U103 },
 	/* BELKIN F5U120 */
@@ -224,16 +222,26 @@
 	{ USB_VENDOR_GOHUBS, USB_PRODUCT_GOHUBS_GOCOM232 },
 	/* Peracom */
 	{ USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_SERIAL1 },
-	/* Vodafone */
-	{ USB_VENDOR_VODAFONE, USB_PRODUCT_VODAFONE_MC3G },
+	/* Novatel Wireless Merlin cards */
+	{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U740 },
+	/* Option Vodafone MC3G */
+	{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_VODAFONEMC3G },
+	/* Option GlobeTrotter 3G */
+	{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3G },
+	/* Option GlobeTrotter 3G QUAD */
+	{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GQUAD },
+	/* Option GlobeTrotter 3G+ */
+	{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GPLUS },
+	/* Huawei Mobile */
+	{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_MOBILE },
 	{ 0, 0 }
 };
 
-Static device_probe_t ubsa_match;
-Static device_attach_t ubsa_attach;
-Static device_detach_t ubsa_detach;
+static device_probe_t ubsa_match;
+static device_attach_t ubsa_attach;
+static device_detach_t ubsa_detach;
 
-Static device_method_t ubsa_methods[] = {
+static device_method_t ubsa_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe, ubsa_match),
 	DEVMETHOD(device_attach, ubsa_attach),
@@ -241,7 +249,7 @@
 	{ 0, 0 }
 };
 
-Static driver_t ubsa_driver = {
+static driver_t ubsa_driver = {
 	"ucom",
 	ubsa_methods,
 	sizeof (struct ubsa_softc)
@@ -252,9 +260,10 @@
 MODULE_DEPEND(ubsa, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
 MODULE_VERSION(ubsa, UBSA_MODVER);
 
-USB_MATCH(ubsa)
+static int
+ubsa_match(device_t self)
 {
-	USB_MATCH_START(ubsa, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	int i;
 
 	if (uaa->iface != NULL)
@@ -269,25 +278,22 @@
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(ubsa)
+static int
+ubsa_attach(device_t self)
 {
-	USB_ATTACH_START(ubsa, sc, uaa);
+	struct ubsa_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev;
 	struct ucom_softc *ucom;
 	usb_config_descriptor_t *cdesc;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char *devinfo;
-	const char *devname;
 	usbd_status err;
 	int i;
 
 	dev = uaa->device;
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
 	ucom = &sc->sc_ucom;
 
-	bzero(sc, sizeof (struct ubsa_softc));
-
 	/*
 	 * initialize rts, dtr variables to something
 	 * different from boolean 0, 1
@@ -295,18 +301,10 @@
 	sc->sc_dtr = -1;
 	sc->sc_rts = -1;
 
-	usbd_devinfo(dev, 0, devinfo);
-	/* USB_ATTACH_SETUP; */
 	ucom->sc_dev = self;
-	device_set_desc_copy(self, devinfo);
-	/* USB_ATTACH_SETUP; */
-
 	ucom->sc_udev = dev;
 	ucom->sc_iface = uaa->iface;
 
-	devname = USBDEVNAME(ucom->sc_dev);
-	printf("%s: %s\n", devname, devinfo);
-
 	DPRINTF(("ubsa attach: sc = %p\n", sc));
 
 	/* initialize endpoints */
@@ -317,8 +315,8 @@
 	/* Move the device into the configured state. */
 	err = usbd_set_config_index(dev, UBSA_CONFIG_INDEX, 1);
 	if (err) {
-		printf("%s: failed to set configuration: %s\n",
-		    devname, usbd_errstr(err));
+		device_printf(ucom->sc_dev, "failed to set configuration: %s\n",
+		    usbd_errstr(err));
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -327,8 +325,8 @@
 	cdesc = usbd_get_config_descriptor(ucom->sc_udev);
 
 	if (cdesc == NULL) {
-		printf("%s: failed to get configuration descriptor\n",
-		    USBDEVNAME(ucom->sc_dev));
+		device_printf(ucom->sc_dev,
+		    "failed to get configuration descriptor\n");
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -337,8 +335,8 @@
 	err = usbd_device2interface_handle(dev, UBSA_IFACE_INDEX,
 	    &ucom->sc_iface);
 	if (err) {
-		printf("%s: failed to get interface: %s\n",
-			devname, usbd_errstr(err));
+		device_printf(ucom->sc_dev, "failed to get interface: %s\n",
+		    usbd_errstr(err));
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -351,8 +349,8 @@
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(ucom->sc_iface, i);
 		if (ed == NULL) {
-			printf("%s: no endpoint descriptor for %d\n",
-			    USBDEVNAME(ucom->sc_dev), i);
+			device_printf(ucom->sc_dev,
+			    "no endpoint descriptor for %d\n", i);
 			ucom->sc_dying = 1;
 			goto error;
 		}
@@ -373,8 +371,7 @@
 	}
 
 	if (sc->sc_intr_number == -1) {
-		printf("%s: Could not find interrupt in\n",
-		    USBDEVNAME(ucom->sc_dev));
+		device_printf(ucom->sc_dev, "Could not find interrupt in\n");
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -383,15 +380,13 @@
 	sc->sc_intr_iface = ucom->sc_iface;
 
 	if (ucom->sc_bulkin_no == -1) {
-		printf("%s: Could not find data bulk in\n",
-		    USBDEVNAME(ucom->sc_dev));
+		device_printf(ucom->sc_dev, "Could not find data bulk in\n");
 		ucom->sc_dying = 1;
 		goto error;
 	}
 
 	if (ucom->sc_bulkout_no == -1) {
-		printf("%s: Could not find data bulk out\n",
-		    USBDEVNAME(ucom->sc_dev));
+		device_printf(ucom->sc_dev, "Could not find data bulk out\n");
 		ucom->sc_dying = 1;
 		goto error;
 	}
@@ -408,21 +403,18 @@
 
 	TASK_INIT(&sc->sc_task, 0, ubsa_notify, sc); 
 	ucom_attach(ucom);
-
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
 error:
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
-USB_DETACH(ubsa)
+static int
+ubsa_detach(device_t self)
 {
-	USB_DETACH_START(ubsa, sc);
+	struct ubsa_softc *sc = device_get_softc(self);
 	int rv;
 
-
 	DPRINTF(("ubsa_detach: sc = %p\n", sc));
 
 	if (sc->sc_intr_pipe != NULL) {
@@ -441,7 +433,7 @@
 	return (rv);
 }
 
-Static int
+static int
 ubsa_request(struct ubsa_softc *sc, u_int8_t request, u_int16_t value)
 {
 	usb_device_request_t req;
@@ -455,12 +447,12 @@
 
 	err = usbd_do_request(sc->sc_ucom.sc_udev, &req, 0);
 	if (err)
-		printf("%s: ubsa_request: %s\n",
-		    USBDEVNAME(sc->sc_ucom.sc_dev), usbd_errstr(err));
+		device_printf(sc->sc_ucom.sc_dev, "ubsa_request: %s\n",
+		    usbd_errstr(err));
 	return (err);
 }
 
-Static void
+static void
 ubsa_dtr(struct ubsa_softc *sc, int onoff)
 {
 
@@ -473,7 +465,7 @@
 	ubsa_request(sc, UBSA_SET_DTR, onoff ? 1 : 0);
 }
 
-Static void
+static void
 ubsa_rts(struct ubsa_softc *sc, int onoff)
 {
 
@@ -486,7 +478,7 @@
 	ubsa_request(sc, UBSA_SET_RTS, onoff ? 1 : 0);
 }
 
-Static void
+static void
 ubsa_break(struct ubsa_softc *sc, int onoff)
 {
 
@@ -495,7 +487,7 @@
 	ubsa_request(sc, UBSA_SET_BREAK, onoff ? 1 : 0);
 }
 
-Static void
+static void
 ubsa_set(void *addr, int portno, int reg, int onoff)
 {
 	struct ubsa_softc *sc;
@@ -516,7 +508,7 @@
 	}
 }
 
-Static void
+static void
 ubsa_baudrate(struct ubsa_softc *sc, speed_t speed)
 {
 	u_int16_t value = 0;
@@ -540,9 +532,8 @@
 		value = B230400 / speed;
 		break;
 	default:
-		printf("%s: ubsa_param: unsupported baudrate, "
-		    "forcing default of 9600\n",
-		    USBDEVNAME(sc->sc_ucom.sc_dev));
+		device_printf(sc->sc_ucom.sc_dev,
+		    "ubsa_param: unsupported baud, forcing default of 9600\n");
 		value = B230400 / B9600;
 		break;
 	};
@@ -555,7 +546,7 @@
 		ubsa_request(sc, UBSA_SET_BAUDRATE, value);
 }
 
-Static void
+static void
 ubsa_parity(struct ubsa_softc *sc, tcflag_t cflag)
 {
 	int value;
@@ -570,7 +561,7 @@
 	ubsa_request(sc, UBSA_SET_PARITY, value);
 }
 
-Static void
+static void
 ubsa_databits(struct ubsa_softc *sc, tcflag_t cflag)
 {
 	int value;
@@ -583,16 +574,16 @@
 	case CS7: value = 2; break;
 	case CS8: value = 3; break;
 	default:
-		printf("%s: ubsa_param: unsupported databits requested, "
-		    "forcing default of 8\n",
-		    USBDEVNAME(sc->sc_ucom.sc_dev));
+		device_printf(sc->sc_ucom.sc_dev,
+		    "ubsa_param: unsupported databits requested, "
+		    "forcing default of 8\n");
 		value = 3;
 	}
 
 	ubsa_request(sc, UBSA_SET_DATA_BITS, value);
 }
 
-Static void
+static void
 ubsa_stopbits(struct ubsa_softc *sc, tcflag_t cflag)
 {
 	int value;
@@ -604,7 +595,7 @@
 	ubsa_request(sc, UBSA_SET_STOP_BITS, value);
 }
 
-Static void
+static void
 ubsa_flow(struct ubsa_softc *sc, tcflag_t cflag, tcflag_t iflag)
 {
 	int value;
@@ -620,7 +611,7 @@
 	ubsa_request(sc, UBSA_SET_FLOW_CTRL, value);
 }
 
-Static int
+static int
 ubsa_param(void *addr, int portno, struct termios *ti)
 {
 	struct ubsa_softc *sc;
@@ -638,7 +629,7 @@
 	return (0);
 }
 
-Static int
+static int
 ubsa_open(void *addr, int portno)
 {
 	struct ubsa_softc *sc;
@@ -662,8 +653,8 @@
 		    ubsa_intr,
 		    UBSA_INTR_INTERVAL);
 		if (err) {
-			printf("%s: cannot open interrupt pipe (addr %d)\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev),
+			device_printf(sc->sc_ucom.sc_dev,
+			    "cannot open interrupt pipe (addr %d)\n",
 			    sc->sc_intr_number);
 			return (EIO);
 		}
@@ -672,7 +663,7 @@
 	return (0);
 }
 
-Static void
+static void
 ubsa_close(void *addr, int portno)
 {
 	struct ubsa_softc *sc;
@@ -687,20 +678,20 @@
 	if (sc->sc_intr_pipe != NULL) {
 		err = usbd_abort_pipe(sc->sc_intr_pipe);
 		if (err)
-			printf("%s: abort interrupt pipe failed: %s\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev),
+			device_printf(sc->sc_ucom.sc_dev,
+			    "abort interrupt pipe failed: %s\n",
 			    usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_intr_pipe);
 		if (err)
-			printf("%s: close interrupt pipe failed: %s\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev),
+			device_printf(sc->sc_ucom.sc_dev,
+			    "close interrupt pipe failed: %s\n",
 			    usbd_errstr(err));
 		free(sc->sc_intr_buf, M_USBDEV);
 		sc->sc_intr_pipe = NULL;
 	}
 }
 
-Static void
+static void
 ubsa_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct ubsa_softc *sc;
@@ -716,7 +707,7 @@
 			return;
 
 		DPRINTF(("%s: ubsa_intr: abnormal status: %s\n",
-		    USBDEVNAME(sc->sc_ucom.sc_dev),
+		    device_get_nameunit(sc->sc_ucom.sc_dev),
 		    usbd_errstr(status)));
 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
 		return;
@@ -727,13 +718,13 @@
 	sc->sc_msr = buf[3];
 
 	DPRINTF(("%s: ubsa lsr = 0x%02x, msr = 0x%02x\n",
-	    USBDEVNAME(sc->sc_ucom.sc_dev), sc->sc_lsr, sc->sc_msr));
+	    device_get_nameunit(sc->sc_ucom.sc_dev), sc->sc_lsr, sc->sc_msr));
 
 	taskqueue_enqueue(taskqueue_swi_giant, &sc->sc_task);
 }
 
 /* Handle delayed events. */
-Static void
+static void
 ubsa_notify(void *arg, int count)
 {
 	struct ubsa_softc *sc;
@@ -742,7 +733,7 @@
 	ucom_status_change(&sc->sc_ucom);
 }
 
-Static void
+static void
 ubsa_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
 {
 	struct ubsa_softc *sc;
Index: uhcivar.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uhcivar.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/uhcivar.h -L sys/dev/usb/uhcivar.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/uhcivar.h
+++ sys/dev/usb/uhcivar.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: uhcivar.h,v 1.33 2002/02/11 11:41:30 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.40 2005/03/19 19:08:46 iedowse Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.45 2007/06/14 16:23:31 imp Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -100,6 +100,9 @@
 	uhci_td_t td;			/* The real TD, must be first */
 	uhci_soft_td_qh_t link; 	/* soft version of the td_link field */
 	uhci_physaddr_t physaddr;	/* TD's physical address. */
+	usb_dma_t aux_dma;		/* Auxillary storage if needed. */
+	void *aux_data;			/* Original aux data virtual address. */
+	int aux_len;			/* Auxillary storage size. */
 };
 /*
  * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
@@ -143,13 +146,10 @@
 	bus_space_tag_t iot;
 	bus_space_handle_t ioh;
 	bus_size_t sc_size;
-#if defined(__FreeBSD__)
 	void *ih;
 
 	struct resource *io_res;
 	struct resource *irq_res;
-#endif
-
 	uhci_physaddr_t *sc_pframes;
 	usb_dma_t sc_dma;
 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
@@ -166,7 +166,7 @@
 	uhci_soft_td_t *sc_freetds;	/* TD free list */
 	uhci_soft_qh_t *sc_freeqhs;	/* QH free list */
 
-	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
+	STAILQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
 
 	u_int8_t sc_addr;		/* device address */
 	u_int8_t sc_conf;		/* device configuration */
@@ -187,7 +187,7 @@
 	/* Info for the root hub interrupt channel. */
 	int sc_ival;			/* time between root hub intrs */
 	usbd_xfer_handle sc_intr_xfer;	/* root hub interrupt transfer */
-	usb_callout_t sc_poll_handle;
+	struct callout sc_poll_handle;
 
 	char sc_vendor[16];		/* vendor string for root hub */
 	int sc_id_vendor;		/* vendor ID for root hub */
@@ -196,19 +196,11 @@
 	void *sc_powerhook;		/* cookie from power hook */
 	void *sc_shutdownhook;		/* cookie from shutdown hook */
 #endif
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	device_ptr_t sc_child;		/* /dev/usb# device */
-#endif
 } uhci_softc_t;
 
 usbd_status	uhci_init(uhci_softc_t *);
 int		uhci_intr(void *);
 int		uhci_detach(uhci_softc_t *, int);
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int		uhci_activate(device_ptr_t, enum devact);
-#endif
-
 void		uhci_shutdown(void *v);
 void		uhci_power(int state, void *priv);
 
Index: usb_quirks.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_quirks.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/usb_quirks.h -L sys/dev/usb/usb_quirks.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/usb_quirks.h
+++ sys/dev/usb/usb_quirks.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: usb_quirks.h,v 1.20 2001/04/15 09:38:01 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/usb_quirks.h,v 1.17.2.3 2006/02/15 22:51:08 iedowse Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/usb_quirks.h,v 1.25 2007/06/29 21:07:41 imp Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -40,22 +40,23 @@
 
 struct usbd_quirks {
 	u_int32_t uq_flags;	/* Device problems: */
-#define UQ_NO_SET_PROTO	0x0001	/* cannot handle SET PROTOCOL. */
-#define UQ_SWAP_UNICODE	0x0002	/* has some Unicode strings swapped. */
-#define UQ_MS_REVZ	0x0004	/* mouse has Z-axis reversed */
-#define UQ_NO_STRINGS	0x0008	/* string descriptors are broken. */
-#define UQ_BAD_ADC	0x0010	/* bad audio spec version number. */
-#define UQ_BUS_POWERED	0x0020	/* device is bus powered, despite claim */
-#define UQ_BAD_AUDIO	0x0040	/* device claims audio class, but isn't */
-#define UQ_SPUR_BUT_UP	0x0080	/* spurious mouse button up events */
-#define UQ_AU_NO_XU	0x0100	/* audio device has broken extension unit */
-#define UQ_POWER_CLAIM	0x0200	/* hub lies about power status */
-#define UQ_AU_NO_FRAC	0x0400	/* don't adjust for fractional samples */
-#define UQ_AU_INP_ASYNC	0x0800	/* input is async despite claim of adaptive */
-#define UQ_ASSUME_CM_OVER_DATA 0x1000 /* modem device breaks on cm over data */
-#define UQ_BROKEN_BIDIR	0x2000	/* printer has broken bidir mode */
-#define UQ_HID_IGNORE	0x8000	/* device should be ignored by hid class */
-					
+#define UQ_SWAP_UNICODE	0x00000002 /* has some Unicode strings swapped. */
+#define UQ_MS_REVZ	0x00000004 /* mouse has Z-axis reversed */
+#define UQ_NO_STRINGS	0x00000008 /* string descriptors are broken. */
+#define UQ_BAD_ADC	0x00000010 /* bad audio spec version number. */
+#define UQ_BUS_POWERED	0x00000020 /* device is bus powered, despite claim */
+#define UQ_BAD_AUDIO	0x00000040 /* device claims audio class, but isn't */
+#define UQ_SPUR_BUT_UP	0x00000080 /* spurious mouse button up events */
+#define UQ_AU_NO_XU	0x00000100 /* audio device has broken extension unit */
+#define UQ_POWER_CLAIM	0x00000200 /* hub lies about power status */
+#define UQ_AU_NO_FRAC	0x00000400 /* don't adjust for fractional samples */
+#define UQ_AU_INP_ASYNC	0x00000800 /* input is async despite claim of adaptive */
+#define UQ_BROKEN_BIDIR	0x00002000 /* printer has broken bidir mode */
+#define UQ_OPEN_CLEARSTALL 0x04000 /* device needs clear endpoint stall */
+#define UQ_HID_IGNORE	0x00008000 /* device should be ignored by hid class */
+#define UQ_KBD_IGNORE	0x00018000 /* device should be ignored by both kbd and hid class */
+#define	UQ_MS_BAD_CLASS 0x00020000 /* doesn't identify properly */
+#define	UQ_MS_LEADING_BYTE 0x40000 /* mouse sends an unknown leading byte. */
 };
 
 extern const struct usbd_quirks usbd_no_quirk;
Index: ubser.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ubser.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/ubser.c -L sys/dev/usb/ubser.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/ubser.c
+++ sys/dev/usb/ubser.c
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ubser.c,v 1.16.2.1 2006/01/30 22:47:45 ticso Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ubser.c,v 1.30 2007/07/05 06:42:14 imp Exp $");
 
 /*
  * BWCT serial adapter driver
@@ -112,12 +112,12 @@
 	   &ubserdebug, 0, "ubser debug level");
 #define DPRINTF(x)      do { \
 				if (ubserdebug) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 
 #define DPRINTFN(n, x)  do { \
 				if (ubserdebug > (n)) \
-					logprintf x; \
+					printf x; \
 			} while (0)
 #else
 #define DPRINTF(x)
@@ -137,7 +137,7 @@
 };
 
 struct ubser_softc {
-	USBBASEDEVICE		sc_dev;
+	device_t		sc_dev;
 	usbd_device_handle	sc_udev;
 	usbd_interface_handle	sc_iface;	/* data interface */
 	int			sc_ifaceno;
@@ -164,24 +164,44 @@
 	struct ubser_port	*sc_port;
 };
 
-Static int ubserparam(struct tty *, struct termios *);
-Static void ubserstart(struct tty *);
-Static void ubserstop(struct tty *, int);
-Static usbd_status ubserstartread(struct ubser_softc *);
-Static void ubserreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void ubserwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void ubser_cleanup(struct ubser_softc *sc);
-
-Static t_break_t	ubserbreak;
-Static t_open_t		ubseropen;
-Static t_close_t	ubserclose;
-Static t_modem_t	ubsermodem;
+static int ubserparam(struct tty *, struct termios *);
+static void ubserstart(struct tty *);
+static void ubserstop(struct tty *, int);
+static usbd_status ubserstartread(struct ubser_softc *);
+static void ubserreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void ubserwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void ubser_cleanup(struct ubser_softc *sc);
+
+static t_break_t	ubserbreak;
+static t_open_t		ubseropen;
+static t_close_t	ubserclose;
+static t_modem_t	ubsermodem;
+
+static device_probe_t ubser_match;
+static device_attach_t ubser_attach;
+static device_detach_t ubser_detach;
+
+static device_method_t ubser_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		ubser_match),
+	DEVMETHOD(device_attach,	ubser_attach),
+	DEVMETHOD(device_detach,	ubser_detach),
 
-USB_DECLARE_DRIVER(ubser);
+	{ 0, 0 }
+};
+
+static driver_t ubser_driver = {
+	"ubser",
+	ubser_methods,
+	sizeof(struct ubser_softc)
+};
+
+static devclass_t ubser_devclass;
 
-USB_MATCH(ubser)
+static int
+ubser_match(device_t self)
 {
-	USB_MATCH_START(ubser, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_string_descriptor_t us;
 	usb_interface_descriptor_t *id;
 	usb_device_descriptor_t *dd;
@@ -218,14 +238,15 @@
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(ubser)
+static int
+ubser_attach(device_t self)
 {
-	USB_ATTACH_START(ubser, sc, uaa);
+	struct ubser_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle udev = uaa->device;
 	usb_endpoint_descriptor_t *ed;
 	usb_interface_descriptor_t *id;
 	usb_device_request_t req;
-	char *devinfo;
 	struct tty *tp;
 	usbd_status err;
 	int i;
@@ -233,9 +254,7 @@
 	uint8_t epcount;
 	struct ubser_port *pp;
 
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
-	usbd_devinfo(udev, 0, devinfo);
-	USB_ATTACH_SETUP;
+	sc->sc_dev = self;
 
 	DPRINTFN(10,("\nubser_attach: sc=%p\n", sc));
 
@@ -261,32 +280,29 @@
 	err = usbd_do_request_flags(udev, &req, &sc->sc_numser,
 	    USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT);
 	if (err) {
-		printf("%s: failed to get number of serials\n",
-		    USBDEVNAME(sc->sc_dev));
+		device_printf(self, "failed to get number of serials\n");
 		goto bad;
 	} else if (alen != 1) {
-		printf("%s: bogus answer on get_numser\n",
-		    USBDEVNAME(sc->sc_dev));
+		device_printf(self, "bogus answer on get_numser\n");
 		goto bad;
 	}
 	if (sc->sc_numser > MAX_SER)
 		sc->sc_numser = MAX_SER;
-	printf("%s: found %i serials\n", USBDEVNAME(sc->sc_dev), sc->sc_numser);
+	device_printf(self, "found %i serials\n", sc->sc_numser);
 
 	sc->sc_port = malloc(sizeof(*sc->sc_port) * sc->sc_numser,
 	    M_USBDEV, M_WAITOK);
 
 	/* find our bulk endpoints */
 	epcount = 0;
-	usbd_endpoint_count(sc->sc_iface, &epcount);
+	(void)usbd_endpoint_count(sc->sc_iface, &epcount);
 	sc->sc_bulkin_no = -1;
 	sc->sc_bulkout_no = -1;
 	for (i = 0; i < epcount; i++) {
 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
 		if (ed == NULL) {
-			printf("%s: couldn't get ep %d\n",
-			USBDEVNAME(sc->sc_dev), i);
-			USB_ATTACH_ERROR_RETURN;
+			device_printf(self, "couldn't get ep %d\n", i);
+			return ENXIO;
 		}
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
@@ -301,8 +317,7 @@
 		}
 	}
 	if (sc->sc_bulkin_no == -1 || sc->sc_bulkout_no == -1) {
-		printf("%s: could not find bulk in/out endpoint\n",
-		    USBDEVNAME(sc->sc_dev));
+		device_printf(self, "could not find bulk in/out endpoint\n");
 		sc->sc_dying = 1;
 		goto bad;
 	}
@@ -312,18 +327,16 @@
 	err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin_no, 0,
 			     &sc->sc_bulkin_pipe);
 	if (err) {
-		printf("%s: open bulk in error (addr %d): %s\n",
-		       USBDEVNAME(sc->sc_dev), sc->sc_bulkin_no,
-		       usbd_errstr(err));
+		device_printf(self, "open bulk in error (addr %d): %s\n",
+		    sc->sc_bulkin_no, usbd_errstr(err));
 		goto fail_0;
 	}
 	/* Bulk-out pipe */
 	err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout_no,
 			     USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
 	if (err) {
-		printf("%s: open bulk out error (addr %d): %s\n",
-		       USBDEVNAME(sc->sc_dev), sc->sc_bulkout_no,
-		       usbd_errstr(err));
+		device_printf(self, "open bulk out error (addr %d): %s\n",
+		    sc->sc_bulkout_no, usbd_errstr(err));
 		goto fail_1;
 	}
 
@@ -353,7 +366,7 @@
 		tp->t_open = ubseropen;
 		tp->t_close = ubserclose;
 		tp->t_modem = ubsermodem;
-		ttycreate(tp, NULL, 0, 0, "y%r%r", USBDEVUNIT(sc->sc_dev), i);
+		ttycreate(tp, 0, "y%r%r", device_get_unit(sc->sc_dev), i);
 	}
 
 
@@ -376,9 +389,7 @@
 	}
 
 	ubserstartread(sc);
-
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
 fail_4:
 	for (i = 0; i < sc->sc_numser; i++) {
@@ -413,14 +424,13 @@
 	}
 
 	DPRINTF(("ubser_attach: ATTACH ERROR\n"));
-	free(devinfo, M_USBDEV);
-
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
-USB_DETACH(ubser)
+static int
+ubser_detach(device_t self)
 {
-	USB_DETACH_START(ubser, sc);
+	struct ubser_softc *sc = device_get_softc(self);
 	int i;
 	struct ubser_port *pp;
 
@@ -450,13 +460,13 @@
 
 	if (--sc->sc_refcnt >= 0) {
 		/* Wait for processes to go away. */
-		usb_detach_wait(USBDEV(sc->sc_dev));
+		usb_detach_wait(sc->sc_dev);
 	}
 
 	return (0);
 }
 
-Static int
+static int
 ubserparam(struct tty *tp, struct termios *t)
 {
 	struct ubser_softc *sc;
@@ -516,7 +526,7 @@
 	return (0);
 }
 
-Static void
+static void
 ubserstart(struct tty *tp)
 {
 	struct ubser_softc *sc;
@@ -590,7 +600,7 @@
 	ttwwakeup(tp);
 }
 
-Static void
+static void
 ubserstop(struct tty *tp, int flag)
 {
 	struct ubser_softc *sc;
@@ -611,7 +621,7 @@
 	DPRINTF(("ubserstop: done\n"));
 }
 
-Static void
+static void
 ubserwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
 {
 	struct tty *tp;
@@ -629,8 +639,8 @@
 		goto error;
 
 	if (status != USBD_NORMAL_COMPLETION) {
-		printf("%s: ubserwritecb: %s\n",
-		       USBDEVNAME(sc->sc_dev), usbd_errstr(status));
+		device_printf(sc->sc_dev, "ubserwritecb: %s\n",
+		    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
 		/* XXX we should restart after some delay. */
@@ -640,8 +650,8 @@
 	usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
 	DPRINTF(("ubserwritecb: cc = %d\n", cc));
 	if (cc <= sc->sc_opkthdrlen) {
-		printf("%s: sent size too small, cc = %d\n",
-		       USBDEVNAME(sc->sc_dev), cc);
+		device_printf(sc->sc_dev, "sent size too small, cc = %d\n",
+		    cc);
 		goto error;
 	}
 
@@ -662,7 +672,7 @@
 	return;
 }
 
-Static usbd_status
+static usbd_status
 ubserstartread(struct ubser_softc *sc)
 {
 	usbd_status err;
@@ -687,7 +697,7 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static void
+static void
 ubserreadcb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
 {
 	struct ubser_softc *sc = (struct ubser_softc *)p;
@@ -698,8 +708,8 @@
 	int lostcc;
 
 	if (status == USBD_IOERROR) {
-		printf("%s: ubserreadcb: %s - restarting\n",
-		    USBDEVNAME(sc->sc_dev), usbd_errstr(status));
+		device_printf(sc->sc_dev, "ubserreadcb: %s - restarting\n",
+		    usbd_errstr(status));
 		goto resubmit;
 	}
 
@@ -707,8 +717,8 @@
 
 	if (status != USBD_NORMAL_COMPLETION) {
 		if (status != USBD_CANCELLED) {
-			printf("%s: ubserreadcb: %s\n",
-			    USBDEVNAME(sc->sc_dev), usbd_errstr(status));
+			device_printf(sc->sc_dev, "ubserreadcb: %s\n",
+			    usbd_errstr(status));
 		}
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
@@ -722,8 +732,8 @@
 		goto resubmit;
 
 	if (cc > sc->sc_ibufsizepad) {
-		printf("%s: invalid receive data size, %d chars\n",
-		       USBDEVNAME(sc->sc_dev), cc);
+		device_printf(sc->sc_dev, "invalid receive data size, %d chars\n",
+		    cc);
 		goto resubmit;
 	}
 
@@ -757,16 +767,15 @@
 			ubserstart(tp);
 		}
 		if (lostcc > 0)
-			printf("%s: lost %d chars\n", USBDEVNAME(sc->sc_dev),
-			       lostcc);
+			device_printf(sc->sc_dev, "lost %d chars\n", lostcc);
 	} else {
 		/* Give characters to tty layer. */
 		while (cc > 0) {
 			DPRINTFN(7, ("ubserreadcb: char = 0x%02x\n", *cp));
 			if (ttyld_rint(tp, *cp) == -1) {
 				/* XXX what should we do? */
-				printf("%s: lost %d chars\n",
-				       USBDEVNAME(sc->sc_dev), cc);
+				device_printf(sc->sc_dev, "lost %d chars\n",
+				    cc);
 				break;
 			}
 			cc--;
@@ -777,13 +786,13 @@
 resubmit:
 	err = ubserstartread(sc);
 	if (err) {
-		printf("%s: read start failed\n", USBDEVNAME(sc->sc_dev));
+		device_printf(sc->sc_dev, "read start failed\n");
 		/* XXX what should we do now? */
 	}
 
 }
 
-Static void
+static void
 ubser_cleanup(struct ubser_softc *sc)
 {
 	int i;
@@ -836,7 +845,7 @@
 	pp = tp->t_sc;
 	sc = pp->p_sc;
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 }
 
 static void
@@ -869,5 +878,5 @@
 	return (SER_DTR | SER_RTS | SER_DCD);
 }
 
+MODULE_DEPEND(ubser, usb, 1, 1, 1);
 DRIVER_MODULE(ubser, uhub, ubser_driver, ubser_devclass, usbd_driver_load, 0);
-
Index: if_axereg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_axereg.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_axereg.h -L sys/dev/usb/if_axereg.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_axereg.h
+++ sys/dev/usb/if_axereg.h
@@ -29,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/if_axereg.h,v 1.8 2005/06/10 16:49:15 brooks Exp $
+ * $FreeBSD: src/sys/dev/usb/if_axereg.h,v 1.16 2007/09/25 21:08:33 imp Exp $
  */
 
 /*
@@ -53,9 +53,11 @@
 #define AXE_CMD_LEN(x)	(((x) & 0xF000) >> 12)
 #define AXE_CMD_CMD(x)	((x) & 0x00FF)
 
-#define AXE_CMD_READ_RXTX_SRAM			0x2002
-#define AXE_CMD_WRITE_RX_SRAM			0x0103
-#define AXE_CMD_WRITE_TX_SRAM			0x0104
+#define AXE_172_CMD_READ_RXTX_SRAM		0x2002
+#define AXE_182_CMD_READ_RXTX_SRAM		0x8002
+#define AXE_172_CMD_WRITE_RX_SRAM		0x0103
+#define AXE_172_CMD_WRITE_TX_SRAM		0x0104
+#define AXE_182_CMD_WRITE_RXTX_SRAM		0x8103
 #define AXE_CMD_MII_OPMODE_SW			0x0106
 #define AXE_CMD_MII_READ_REG			0x2007
 #define AXE_CMD_MII_WRITE_REG			0x2108
@@ -68,35 +70,85 @@
 #define AXE_CMD_RXCTL_READ			0x200F
 #define AXE_CMD_RXCTL_WRITE			0x0110
 #define AXE_CMD_READ_IPG012			0x3011
-#define AXE_CMD_WRITE_IPG0			0x0112
-#define AXE_CMD_WRITE_IPG1			0x0113
-#define AXE_CMD_WRITE_IPG2			0x0114
+#define AXE_172_CMD_WRITE_IPG0			0x0112
+#define AXE_172_CMD_WRITE_IPG1			0x0113
+#define AXE_172_CMD_WRITE_IPG2			0x0114
+#define AXE_178_CMD_WRITE_IPG012		0x0112
 #define AXE_CMD_READ_MCAST			0x8015
 #define AXE_CMD_WRITE_MCAST			0x8116
-#define AXE_CMD_READ_NODEID			0x6017
-#define AXE_CMD_WRITE_NODEID			0x6118
+#define AXE_172_CMD_READ_NODEID			0x6017
+#define AXE_172_CMD_WRITE_NODEID		0x6118
+#define AXE_178_CMD_READ_NODEID			0x6013
+#define AXE_178_CMD_WRITE_NODEID		0x6114
 #define AXE_CMD_READ_PHYID			0x2019
-#define AXE_CMD_READ_MEDIA			0x101A
+#define AXE_172_CMD_READ_MEDIA			0x101A
+#define AXE_178_CMD_READ_MEDIA			0x201A
 #define AXE_CMD_WRITE_MEDIA			0x011B
 #define AXE_CMD_READ_MONITOR_MODE		0x101C
 #define AXE_CMD_WRITE_MONITOR_MODE		0x011D
 #define AXE_CMD_READ_GPIO			0x101E
 #define AXE_CMD_WRITE_GPIO			0x011F
+#define AXE_CMD_SW_RESET_REG			0x0120
+#define AXE_CMD_SW_PHY_STATUS			0x0021
+#define AXE_CMD_SW_PHY_SELECT			0x0122
+
+#define AXE_SW_RESET_CLEAR			0x00
+#define AXE_SW_RESET_RR				0x01
+#define AXE_SW_RESET_RT				0x02
+#define AXE_SW_RESET_PRTE			0x04
+#define AXE_SW_RESET_PRL			0x08
+#define AXE_SW_RESET_BZ				0x10
+#define AXE_SW_RESET_IPRL			0x20
+#define AXE_SW_RESET_IPPD			0x40
+
+/* AX88178 documentation says to always write this bit... */
+#define AXE_178_RESET_MAGIC			0x40
+
+#define AXE_178_MEDIA_GMII			0x0001
+#define AXE_MEDIA_FULL_DUPLEX			0x0002
+#define AXE_172_MEDIA_TX_ABORT_ALLOW		0x0004
+/* AX88178/88772 documentation says to always write 1 to bit 2 */
+#define AXE_178_MEDIA_MAGIC			0x0004
+/* AX88772 documentation says to always write 0 to bit 3 */
+#define AXE_178_MEDIA_ENCK			0x0008
+#define AXE_172_MEDIA_FLOW_CONTROL_EN		0x0010
+#define AXE_178_MEDIA_RXFLOW_CONTROL_EN		0x0010
+#define AXE_178_MEDIA_TXFLOW_CONTROL_EN		0x0020
+#define AXE_178_MEDIA_JUMBO_EN			0x0040
+#define AXE_178_MEDIA_LTPF_ONLY			0x0080
+#define AXE_178_MEDIA_RX_EN			0x0100
+#define AXE_178_MEDIA_100TX			0x0200
+#define AXE_178_MEDIA_SBP			0x0800
+#define AXE_178_MEDIA_SUPERMAC			0x1000
 
 #define AXE_RXCMD_PROMISC			0x0001
 #define AXE_RXCMD_ALLMULTI			0x0002
-#define AXE_RXCMD_UNICAST			0x0004
+#define AXE_172_RXCMD_UNICAST			0x0004
+#define AXE_178_RXCMD_KEEP_INVALID_CRC		0x0004
 #define AXE_RXCMD_BROADCAST			0x0008
 #define AXE_RXCMD_MULTICAST			0x0010
+#define AXE_178_RXCMD_AP			0x0020
 #define AXE_RXCMD_ENABLE			0x0080
+#define AXE_178_RXCMD_MFB			0x0300	/* Max Frame Burst */
+#define AXE_178_RXCMD_MFB_2048			0x0000
+#define AXE_178_RXCMD_MFB_4096			0x0100
+#define AXE_178_RXCMD_MFB_8192			0x0200
+#define AXE_178_RXCMD_MFB_16384			0x0300
 
 #define AXE_NOPHY				0xE0
+#define AXE_INTPHY				0x10
 
 #define AXE_TIMEOUT		1000
+#define AXE_172_BUFSZ		1536
+#define AXE_178_MIN_BUFSZ	2048
+#define AXE_178_MAX_BUFSZ	16384
 #define AXE_MIN_FRAMELEN	60
 #define AXE_RX_FRAMES		1
 #define AXE_TX_FRAMES		1
 
+#define AXE_RX_LIST_CNT		1
+#define AXE_TX_LIST_CNT		1
+
 #define AXE_CTL_READ		0x01
 #define AXE_CTL_WRITE		0x02
 
@@ -112,9 +164,17 @@
 #define AXE_ENDPT_INTR		0x2
 #define AXE_ENDPT_MAX		0x3
 
+struct axe_sframe_hdr {
+	uint16_t	len;
+	uint16_t	ilen;
+} __packed;
+
 struct axe_type {
-	u_int16_t		axe_vid;
-	u_int16_t		axe_did;
+	struct usb_devno        axe_dev;
+	uint32_t                axe_flags;
+#define	AX172	0x0000		/* AX88172 */
+#define	AX178	0x0001		/* AX88178 */
+#define	AX772	0x0002		/* AX88772 */
 };
 
 #define AXE_INC(x, y)		(x) = (x + 1) % y
@@ -132,21 +192,25 @@
 	device_t		axe_dev;
 	usbd_device_handle	axe_udev;
 	usbd_interface_handle	axe_iface;
+	u_int16_t		axe_vendor;
+	u_int16_t		axe_product;
+	u_int16_t		axe_flags;
 	int			axe_ed[AXE_ENDPT_MAX];
 	usbd_pipe_handle	axe_ep[AXE_ENDPT_MAX];
-	int			axe_unit;
 	int			axe_if_flags;
 	struct ue_cdata		axe_cdata;
 	struct callout_handle	axe_stat_ch;
-#if __FreeBSD_version >= 500000
 	struct mtx		axe_mtx;
-#endif
+	struct sx		axe_sleeplock;
 	char			axe_dying;
 	int			axe_link;
 	unsigned char		axe_ipgs[3];
 	unsigned char 		axe_phyaddrs[2];
 	struct timeval		axe_rx_notice;
 	struct usb_qdat		axe_qdat;
+	struct usb_task		axe_tick_task;
+	int			axe_bufsz;
+	int			axe_boundary;
 };
 
 #if 0
@@ -156,3 +220,6 @@
 #define	AXE_LOCK(_sc)
 #define	AXE_UNLOCK(_sc)
 #endif
+#define	AXE_SLEEPLOCK(_sc)	sx_xlock(&(_sc)->axe_sleeplock)
+#define	AXE_SLEEPUNLOCK(_sc)	sx_xunlock(&(_sc)->axe_sleeplock)
+#define	AXE_SLEEPLOCKASSERT(_sc) sx_assert(&(_sc)->axe_sleeplock, SX_XLOCKED)
Index: uhid.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uhid.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/uhid.c -L sys/dev/usb/uhid.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/uhid.c
+++ sys/dev/usb/uhid.c
@@ -5,7 +5,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uhid.c,v 1.77.2.3 2006/01/20 22:55:45 mux Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uhid.c,v 1.96 2007/06/21 14:42:33 imp Exp $");
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -48,34 +48,27 @@
  * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
  */
 
+/*
+ * XXX TODO: Convert this driver to use si_drv[12] rather than the
+ * devclass_get_softc junk
+ */
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
-#if __FreeBSD_version >= 500000
 #include <sys/mutex.h>
-#endif
 #include <sys/signalvar.h>
 #include <sys/fcntl.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#include <sys/ioctl.h>
-#include <sys/file.h>
-#elif defined(__FreeBSD__)
 #include <sys/ioccom.h>
 #include <sys/filio.h>
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/ioccom.h>
-#endif
 #include <sys/conf.h>
 #include <sys/tty.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/proc.h>
 #include <sys/poll.h>
 #include <sys/sysctl.h>
@@ -97,8 +90,8 @@
 #include <dev/usb/usb_quirks.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (uhiddebug) logprintf x
-#define DPRINTFN(n,x)	if (uhiddebug>(n)) logprintf x
+#define DPRINTF(x)	if (uhiddebug) printf x
+#define DPRINTFN(n,x)	if (uhiddebug>(n)) printf x
 int	uhiddebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, uhid, CTLFLAG_RW, 0, "USB uhid");
 SYSCTL_INT(_hw_usb_uhid, OID_AUTO, debug, CTLFLAG_RW,
@@ -109,7 +102,7 @@
 #endif
 
 struct uhid_softc {
-	USBBASEDEVICE sc_dev;			/* base device */
+	device_t sc_dev;			/* base device */
 	usbd_device_handle sc_udev;
 	usbd_interface_handle sc_iface;	/* interface */
 	usbd_pipe_handle sc_intrpipe;	/* interrupt pipe */
@@ -140,18 +133,13 @@
 	int sc_refcnt;
 	u_char sc_dying;
 
-#if defined(__FreeBSD__)
 	struct cdev *dev;
-#endif
 };
 
 #define	UHIDUNIT(dev)	(minor(dev))
 #define	UHID_CHUNK	128	/* chunk size for read */
 #define	UHID_BSIZE	1020	/* buffer size */
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-cdev_decl(uhid);
-#elif defined(__FreeBSD__)
 d_open_t	uhidopen;
 d_close_t	uhidclose;
 d_read_t	uhidread;
@@ -160,7 +148,7 @@
 d_poll_t	uhidpoll;
 
 
-Static struct cdevsw uhid_cdevsw = {
+static struct cdevsw uhid_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
 	.d_open =	uhidopen,
@@ -170,25 +158,45 @@
 	.d_ioctl =	uhidioctl,
 	.d_poll =	uhidpoll,
 	.d_name =	"uhid",
-#if __FreeBSD_version < 500014
-	.d_bmaj		-1
-#endif
 };
-#endif
 
-Static void uhid_intr(usbd_xfer_handle, usbd_private_handle,
+static void uhid_intr(usbd_xfer_handle, usbd_private_handle,
 			   usbd_status);
 
-Static int uhid_do_read(struct uhid_softc *, struct uio *uio, int);
-Static int uhid_do_write(struct uhid_softc *, struct uio *uio, int);
-Static int uhid_do_ioctl(struct uhid_softc *, u_long, caddr_t, int,
-			      usb_proc_ptr);
+static int uhid_do_read(struct uhid_softc *, struct uio *uio, int);
+static int uhid_do_write(struct uhid_softc *, struct uio *uio, int);
+static int uhid_do_ioctl(struct uhid_softc *, u_long, caddr_t, int,
+			      struct thread *);
+
+MODULE_DEPEND(uhid, usb, 1, 1, 1);
+
+static device_probe_t uhid_match;
+static device_attach_t uhid_attach;
+static device_detach_t uhid_detach;
+
+static device_method_t uhid_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		uhid_match),
+	DEVMETHOD(device_attach,	uhid_attach),
+	DEVMETHOD(device_detach,	uhid_detach),
+
+	{ 0, 0 }
+};
+
+static driver_t uhid_driver = {
+	"uhid",
+	uhid_methods,
+	sizeof(struct uhid_softc)
+};
 
-USB_DECLARE_DRIVER(uhid);
+static devclass_t uhid_devclass;
 
-USB_MATCH(uhid)
+DRIVER_MODULE(uhid, uhub, uhid_driver, uhid_devclass, usbd_driver_load, 0);
+
+static int
+uhid_match(device_t self)
 {
-	USB_MATCH_START(uhid, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_interface_descriptor_t *id;
 
 	if (uaa->iface == NULL)
@@ -213,9 +221,11 @@
 	return (UMATCH_IFACECLASS_GENERIC);
 }
 
-USB_ATTACH(uhid)
+static int
+uhid_attach(device_t self)
 {
-	USB_ATTACH_START(uhid, sc, uaa);
+	struct uhid_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_interface_handle iface = uaa->iface;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
@@ -223,20 +233,18 @@
 	void *desc;
 	const void *descptr;
 	usbd_status err;
-	char devinfo[1024];
 
+	sc->sc_dev = self;
 	sc->sc_udev = uaa->device;
 	sc->sc_iface = iface;
 	id = usbd_get_interface_descriptor(iface);
-	usbd_devinfo(uaa->device, USBD_SHOW_INTERFACE_CLASS, devinfo);
-	USB_ATTACH_SETUP;
 
 	ed = usbd_interface2endpoint_descriptor(iface, 0);
 	if (ed == NULL) {
 		printf("%s: could not read endpoint descriptor\n",
-		       USBDEVNAME(sc->sc_dev));
+		       device_get_nameunit(sc->sc_dev));
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 
 	DPRINTFN(10,("uhid_attach: bLength=%d bDescriptorType=%d "
@@ -250,9 +258,9 @@
 
 	if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
 	    (ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
-		printf("%s: unexpected endpoint\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: unexpected endpoint\n", device_get_nameunit(sc->sc_dev));
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 
 	sc->sc_ep_addr = ed->bEndpointAddress;
@@ -280,6 +288,12 @@
 	} else if (id->bInterfaceClass == UICLASS_VENDOR &&
 	    id->bInterfaceSubClass == UISUBCLASS_XBOX360_CONTROLLER &&
 	    id->bInterfaceProtocol == UIPROTO_XBOX360_GAMEPAD) {
+		static uByte reportbuf[] = {1, 3, 0};
+
+		/* The LEDs on the gamepad are blinking by default, turn off. */
+		usbd_set_report(uaa->iface, UHID_OUTPUT_REPORT, 0,
+		    &reportbuf, sizeof reportbuf);
+
 		/* The Xbox 360 gamepad has no report descriptor. */
 		size = sizeof uhid_xb360gp_report_descr;
 		descptr = uhid_xb360gp_report_descr;
@@ -299,9 +313,9 @@
 	}
 
 	if (err) {
-		printf("%s: no report descriptor\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: no report descriptor\n", device_get_nameunit(sc->sc_dev));
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 
 	(void)usbd_set_idle(iface, 0, 0);
@@ -312,48 +326,19 @@
 
 	sc->sc_repdesc = desc;
 	sc->sc_repdesc_size = size;
-
-#if defined(__FreeBSD__)
 	sc->dev = make_dev(&uhid_cdevsw, device_get_unit(self),
 			UID_ROOT, GID_OPERATOR,
 			0644, "uhid%d", device_get_unit(self));
-#endif
-
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-uhid_activate(device_ptr_t self, enum devact act)
+static int
+uhid_detach(device_t self)
 {
-	struct uhid_softc *sc = (struct uhid_softc *)self;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		sc->sc_dying = 1;
-		break;
-	}
-	return (0);
-}
-#endif
-
-USB_DETACH(uhid)
-{
-	USB_DETACH_START(uhid, sc);
+	struct uhid_softc *sc = device_get_softc(self);
 	int s;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	int maj, mn;
-#endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	DPRINTF(("uhid_detach: sc=%p flags=%d\n", sc, flags));
-#else
 	DPRINTF(("uhid_detach: sc=%p\n", sc));
-#endif
-
 	sc->sc_dying = 1;
 	if (sc->sc_intrpipe != NULL)
 		usbd_abort_pipe(sc->sc_intrpipe);
@@ -364,23 +349,11 @@
 			/* Wake everyone */
 			wakeup(&sc->sc_q);
 			/* Wait for processes to go away. */
-			usb_detach_wait(USBDEV(sc->sc_dev));
+			usb_detach_wait(sc->sc_dev);
 		}
 		splx(s);
 	}
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	/* locate the major number */
-	for (maj = 0; maj < nchrdev; maj++)
-		if (cdevsw[maj].d_open == uhidopen)
-			break;
-
-	/* Nuke the vnodes for any open instances (calls close). */
-	mn = self->dv_unit;
-	vdevgone(maj, mn, mn, VCHR);
-#elif defined(__FreeBSD__)
 	destroy_dev(sc->dev);
-#endif
 
 	if (sc->sc_repdesc)
 		free(sc->sc_repdesc, M_USBDEV);
@@ -433,12 +406,14 @@
 }
 
 int
-uhidopen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+uhidopen(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	struct uhid_softc *sc;
 	usbd_status err;
 
-	USB_GET_SC_OPEN(uhid, UHIDUNIT(dev), sc);
+	sc = devclass_get_softc(uhid_devclass, UHIDUNIT(dev));
+	if (sc == NULL)
+		return (ENXIO);
 
 	DPRINTF(("uhidopen: sc=%p\n", sc));
 
@@ -449,11 +424,7 @@
 		return (EBUSY);
 	sc->sc_state |= UHID_OPEN;
 
-	if (clalloc(&sc->sc_q, UHID_BSIZE, 0) == -1) {
-		sc->sc_state &= ~UHID_OPEN;
-		return (ENOMEM);
-	}
-
+	clist_alloc_cblocks(&sc->sc_q, UHID_BSIZE, UHID_BSIZE);
 	sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
 	sc->sc_obuf = malloc(sc->sc_osize, M_USBDEV, M_WAITOK);
 
@@ -480,11 +451,11 @@
 }
 
 int
-uhidclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+uhidclose(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	struct uhid_softc *sc;
 
-	USB_GET_SC(uhid, UHIDUNIT(dev), sc);
+	sc = devclass_get_softc(uhid_devclass, UHIDUNIT(dev));
 
 	DPRINTF(("uhidclose: sc=%p\n", sc));
 
@@ -494,7 +465,7 @@
 	sc->sc_intrpipe = 0;
 
 	ndflush(&sc->sc_q, sc->sc_q.c_cc);
-	clfree(&sc->sc_q);
+	clist_free_cblocks(&sc->sc_q);
 
 	free(sc->sc_ibuf, M_USBDEV);
 	free(sc->sc_obuf, M_USBDEV);
@@ -575,12 +546,11 @@
 	struct uhid_softc *sc;
 	int error;
 
-	USB_GET_SC(uhid, UHIDUNIT(dev), sc);
-
+	sc = devclass_get_softc(uhid_devclass, UHIDUNIT(dev));
 	sc->sc_refcnt++;
 	error = uhid_do_read(sc, uio, flag);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	return (error);
 }
 
@@ -621,18 +591,17 @@
 	struct uhid_softc *sc;
 	int error;
 
-	USB_GET_SC(uhid, UHIDUNIT(dev), sc);
-
+	sc = devclass_get_softc(uhid_devclass, UHIDUNIT(dev));
 	sc->sc_refcnt++;
 	error = uhid_do_write(sc, uio, flag);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	return (error);
 }
 
 int
 uhid_do_ioctl(struct uhid_softc *sc, u_long cmd, caddr_t addr, int flag,
-	      usb_proc_ptr p)
+	      struct thread *p)
 {
 	struct usb_ctl_report_desc *rd;
 	struct usb_ctl_report *re;
@@ -653,11 +622,7 @@
 		if (*(int *)addr) {
 			if (sc->sc_async != NULL)
 				return (EBUSY);
-#if __FreeBSD_version >= 500000
 			sc->sc_async = p->td_proc;
-#else
-			sc->sc_async = p;
-#endif
 			DPRINTF(("uhid_do_ioctl: FIOASYNC %p\n", sc->sc_async));
 		} else
 			sc->sc_async = NULL;
@@ -750,29 +715,27 @@
 }
 
 int
-uhidioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p)
+uhidioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *p)
 {
 	struct uhid_softc *sc;
 	int error;
 
-	USB_GET_SC(uhid, UHIDUNIT(dev), sc);
-
+	sc = devclass_get_softc(uhid_devclass, UHIDUNIT(dev));
 	sc->sc_refcnt++;
 	error = uhid_do_ioctl(sc, cmd, addr, flag, p);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	return (error);
 }
 
 int
-uhidpoll(struct cdev *dev, int events, usb_proc_ptr p)
+uhidpoll(struct cdev *dev, int events, struct thread *p)
 {
 	struct uhid_softc *sc;
 	int revents = 0;
 	int s;
 
-	USB_GET_SC(uhid, UHIDUNIT(dev), sc);
-
+	sc = devclass_get_softc(uhid_devclass, UHIDUNIT(dev));
 	if (sc->sc_dying)
 		return (EIO);
 
@@ -789,7 +752,3 @@
 	splx(s);
 	return (revents);
 }
-
-#if defined(__FreeBSD__)
-DRIVER_MODULE(uhid, uhub, uhid_driver, uhid_devclass, usbd_driver_load, 0);
-#endif
Index: FILES
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/FILES,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/FILES -L sys/dev/usb/FILES -u -r1.1.1.1 -r1.2
--- sys/dev/usb/FILES
+++ sys/dev/usb/FILES
@@ -1,17 +1,12 @@
-$FreeBSD: src/sys/dev/usb/FILES,v 1.7 2004/12/08 22:02:58 rsm Exp $
+$FreeBSD: src/sys/dev/usb/FILES,v 1.8 2006/11/21 22:29:06 dougb Exp $
 
 A small roadmap of the USB files:
 
 FILES			this file
-Makefile		to install .h files
-Makefile.usbdevs	to run devlist2h.awk
-TODO			just a list of things to do
-devlist2h.awk		script to generate usbdevs*.h
 dsbr100io.h		API for ufm.c
 ehci.c			Host controller driver for EHCI
 ehcireg.h		Hardware definitions for EHCI
 ehcivar.h		API for ehci.c
-files.usb		config include file
 hid.c			subroutines to parse and access HID data
 hid.h			API for hid.c
 if_aue.c		USB Pegasus Ethernet driver
@@ -22,12 +17,9 @@
 if_cuereg.h		  and definitions for it
 if_kue.c		USB Kawasaki Ethernet driver
 if_kuereg.h		  and definitions for it
-if_upl.c		USB Prolofic host-to-host driver
 ohci.c			Host controller driver for OHCI
 ohcireg.h		Hardware definitions for OHCI
 ohcivar.h		API for ohci.c
-uaudio.c		USB audio class driver
-uaudioreg.h		  and definitions for it
 ufm.c			USB fm radio driver
 [Merged] ugen.c		generic driver that can handle access to any USB device
 uhci.c			Host controller driver for UHCI
@@ -36,8 +28,6 @@
 uhid.c			USB HID class driver
 uhub.c			USB hub driver
 ukbd.c			USB keyboard driver
-ukbdmap.c		wscons key mapping for ukbd
-ukbdvar.h		API for ukbd.c
 ulpt.c			USB printer class driver
 umass.c			USB mass storage driver
 umodem.c		USB modem (CDC ACM) driver
@@ -53,8 +43,6 @@
 usb_subr.c		various subroutines used by USB code
 usbcdc.h		USB CDC class definitions
 usbdevs			data base of known device
-usbdevs.h		generated from usbdevs
-usbdevs_data.h		generated from usbdevs
 usbdi.c			implementation of the USBDI API, which all drivers use
 usbdi.h			API for usbdi.c
 usbdi_util.c		utilities built on top of usbdi.h
Index: usb_subr.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_subr.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/usb/usb_subr.c -L sys/dev/usb/usb_subr.c -u -r1.2 -r1.3
--- sys/dev/usb/usb_subr.c
+++ sys/dev/usb/usb_subr.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.76.2.3 2006/03/01 01:59:05 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.95 2007/06/30 20:18:44 imp Exp $");
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -56,14 +56,10 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#include <sys/select.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
-#endif
 #include <sys/proc.h>
+#include <sys/sysctl.h>
 
 #include <machine/bus.h>
 
@@ -75,36 +71,26 @@
 #include "usbdevs.h"
 #include <dev/usb/usb_quirks.h>
 
-#if defined(__FreeBSD__)
-#include <machine/clock.h>
 #define delay(d)         DELAY(d)
-#endif
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (usbdebug) logprintf x
-#define DPRINTFN(n,x)	if (usbdebug>(n)) logprintf x
+#define DPRINTF(x)	if (usbdebug) printf x
+#define DPRINTFN(n,x)	if (usbdebug>(n)) printf x
 extern int usbdebug;
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n,x)
 #endif
 
-Static usbd_status usbd_set_config(usbd_device_handle, int);
-Static void usbd_devinfo_vp(usbd_device_handle, char *, char *, int);
-Static int usbd_getnewaddr(usbd_bus_handle bus);
-#if defined(__NetBSD__)
-Static int usbd_print(void *aux, const char *pnp);
-Static int usbd_submatch(device_ptr_t, struct cfdata *cf, void *);
-#elif defined(__OpenBSD__)
-Static int usbd_print(void *aux, const char *pnp);
-Static int usbd_submatch(device_ptr_t, void *, void *);
-#endif
-Static void usbd_free_iface_data(usbd_device_handle dev, int ifcno);
-Static void usbd_kill_pipe(usbd_pipe_handle);
-Static usbd_status usbd_probe_and_attach(device_ptr_t parent,
+static usbd_status usbd_set_config(usbd_device_handle, int);
+static void usbd_devinfo_vp(usbd_device_handle, char *, char *, int);
+static int usbd_getnewaddr(usbd_bus_handle bus);
+static void usbd_free_iface_data(usbd_device_handle dev, int ifcno);
+static void usbd_kill_pipe(usbd_pipe_handle);
+static usbd_status usbd_probe_and_attach(device_t parent,
 				 usbd_device_handle dev, int port, int addr);
 
-Static u_int32_t usb_cookie_no = 0;
+static u_int32_t usb_cookie_no = 0;
 
 #ifdef USBVERBOSE
 typedef u_int16_t usb_vendor_id_t;
@@ -124,7 +110,7 @@
 #include "usbdevs_data.h"
 #endif /* USBVERBOSE */
 
-Static const char * const usbd_error_strs[] = {
+static const char * const usbd_error_strs[] = {
 	"NORMAL_COMPLETION",
 	"IN_PROGRESS",
 	"PENDING_REQUESTS",
@@ -196,7 +182,7 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static void
+static void
 usbd_trim_spaces(char *p)
 {
 	char *q, *e;
@@ -212,7 +198,7 @@
 	*e = 0;			/* kill trailing spaces */
 }
 
-Static void
+static void
 usbd_devinfo_vp(usbd_device_handle dev, char *v, char *p, int usedev)
 {
 	usb_device_descriptor_t *udd = &dev->ddesc;
@@ -227,12 +213,14 @@
 	}
 
 	if (usedev) {
-		if (usbd_get_string(dev, udd->iManufacturer, v))
+		if (usbd_get_string(dev, udd->iManufacturer, v,
+		    USB_MAX_STRING_LEN))
 			vendor = NULL;
 		else
 			vendor = v;
 		usbd_trim_spaces(vendor);
-		if (usbd_get_string(dev, udd->iProduct, p))
+		if (usbd_get_string(dev, udd->iProduct, p,
+		    USB_MAX_STRING_LEN))
 			product = NULL;
 		else
 			product = p;
@@ -321,7 +309,7 @@
 	if (bus->use_polling || cold)
 		delay((ms+1) * 1000);
 	else
-		tsleep(&ms, PRIBIO, "usbdly", (ms*hz+999)/1000 + 1);
+		pause("usbdly", (ms*hz+999)/1000 + 1);
 }
 
 /* Delay given a device handle. */
@@ -537,7 +525,7 @@
 		free(ifc->endpoints, M_USB);
 }
 
-Static usbd_status
+static usbd_status
 usbd_set_config(usbd_device_handle dev, int conf)
 {
 	usb_device_request_t req;
@@ -699,7 +687,7 @@
 		if (msg)
 			printf("%s: device addr %d (config %d) exceeds power "
 				 "budget, %d mA > %d mA\n",
-			       USBDEVNAME(dev->bus->bdev), dev->address,
+			       device_get_nameunit(dev->bus->bdev), dev->address,
 			       cdp->bConfigurationValue,
 			       power, dev->powersrc->power);
 		err = USBD_NO_POWER;
@@ -770,7 +758,7 @@
 	p->aborting = 0;
 	p->repeat = 0;
 	p->interval = ival;
-	SIMPLEQ_INIT(&p->queue);
+	STAILQ_INIT(&p->queue);
 	err = dev->bus->methods->open_pipe(p);
 	if (err) {
 		DPRINTFN(-1,("usbd_setup_pipe: endpoint=0x%x failed, error="
@@ -780,6 +768,18 @@
 		return (err);
 	}
 
+	if (dev->quirks->uq_flags & UQ_OPEN_CLEARSTALL) {
+		/* Clear any stall and make sure DATA0 toggle will be used next. */
+		if (UE_GET_ADDR(ep->edesc->bEndpointAddress) != USB_CONTROL_ENDPOINT) {
+			err = usbd_clear_endpoint_stall(p);
+			if (err && err != USBD_STALLED && err != USBD_TIMEOUT) {
+				printf("usbd_setup_pipe: failed to start "
+				    "endpoint, %s\n", usbd_errstr(err));
+				return (err);
+			}
+		}
+	}
+
 	*pipe = p;
 	return (USBD_NORMAL_COMPLETION);
 }
@@ -807,34 +807,38 @@
 
 
 usbd_status
-usbd_probe_and_attach(device_ptr_t parent, usbd_device_handle dev,
+usbd_probe_and_attach(device_t parent, usbd_device_handle dev,
 		      int port, int addr)
 {
 	struct usb_attach_arg uaa;
 	usb_device_descriptor_t *dd = &dev->ddesc;
 	int found, i, confi, nifaces;
 	usbd_status err;
-	device_ptr_t dv;
-	device_ptr_t *tmpdv;
+	device_t *tmpdv;
 	usbd_interface_handle ifaces[256]; /* 256 is the absolute max */
+	char *devinfo;
 
-#if defined(__FreeBSD__)
 	/* XXX FreeBSD may leak resources on failure cases -- fixme */
  	device_t bdev;
 	struct usb_attach_arg *uaap;
 
+	devinfo = malloc(1024, M_USB, M_NOWAIT);
+	if (devinfo == NULL) {
+		device_printf(parent, "Can't allocate memory for probe string\n");
+		return (USBD_NOMEM);
+	}
 	bdev = device_add_child(parent, NULL, -1);
 	if (!bdev) {
+		free(devinfo, M_USB);
 		device_printf(parent, "Device creation failed\n");
 		return (USBD_INVAL);
 	}
-	device_quiet(bdev);
 	uaap = malloc(sizeof(uaa), M_USB, M_NOWAIT);
 	if (uaap == NULL) {
+		free(devinfo, M_USB);
 		return (USBD_INVAL);
 	}
 	device_set_ivars(bdev, uaap);
-#endif
 	uaa.device = dev;
 	uaa.iface = NULL;
 	uaa.ifaces = NULL;
@@ -846,21 +850,27 @@
 	uaa.vendor = UGETW(dd->idVendor);
 	uaa.product = UGETW(dd->idProduct);
 	uaa.release = UGETW(dd->bcdDevice);
+	uaa.matchlvl = 0;
 
 	/* First try with device specific drivers. */
 	DPRINTF(("usbd_probe_and_attach: trying device specific drivers\n"));
 
 	dev->ifacenums = NULL;
-	dev->subdevs = malloc(2 * sizeof dv, M_USB, M_NOWAIT);
-	if (dev->subdevs == NULL)
+	dev->subdevs = malloc(2 * sizeof(device_t), M_USB, M_NOWAIT);
+	if (dev->subdevs == NULL) {
+		free(devinfo, M_USB);
 		return (USBD_NOMEM);
+	}
 	dev->subdevs[0] = bdev;
 	dev->subdevs[1] = 0;
 	*uaap = uaa;
-	dv = USB_DO_ATTACH(dev, bdev, parent, &uaa, usbd_print, usbd_submatch);
-	if (dv) {
+	usbd_devinfo(dev, 1, devinfo);
+	device_set_desc_copy(bdev, devinfo);
+	if (device_probe_and_attach(bdev) == 0) {
+		free(devinfo, M_USB);
 		return (USBD_NORMAL_COMPLETION);
 	}
+
 	/*
 	 * Free subdevs so we can reallocate it larger for the number of
 	 * interfaces 
@@ -880,12 +890,13 @@
 		if (err) {
 #ifdef USB_DEBUG
 			DPRINTF(("%s: port %d, set config at addr %d failed, "
-				 "error=%s\n", USBDEVPTRNAME(parent), port,
+				 "error=%s\n", device_get_nameunit(parent), port,
 				 addr, usbd_errstr(err)));
 #else
 			printf("%s: port %d, set config at addr %d failed\n",
-			       USBDEVPTRNAME(parent), port, addr);
+			       device_get_nameunit(parent), port, addr);
 #endif
+			free(devinfo, M_USB);
  			return (err);
 		}
 		nifaces = dev->cdesc->bNumInterface;
@@ -894,13 +905,15 @@
 			ifaces[i] = &dev->ifaces[i];
 		uaa.ifaces = ifaces;
 		uaa.nifaces = nifaces;
-		dev->subdevs = malloc((nifaces+1) * sizeof dv, M_USB,M_NOWAIT);
+		dev->subdevs = malloc((nifaces+1) * sizeof(device_t), M_USB,M_NOWAIT);
 		if (dev->subdevs == NULL) {
+			free(devinfo, M_USB);
 			return (USBD_NOMEM);
 		}
 		dev->ifacenums = malloc((nifaces) * sizeof(*dev->ifacenums),
 		    M_USB,M_NOWAIT);
 		if (dev->ifacenums == NULL) {
+			free(devinfo, M_USB);
 			return (USBD_NOMEM);
 		}
 
@@ -914,37 +927,35 @@
 			dev->subdevs[found + 1] = 0;
 			dev->ifacenums[found] = i;
 			*uaap = uaa;
-			dv = USB_DO_ATTACH(dev, bdev, parent, &uaa, usbd_print,
-					   usbd_submatch);
-			if (dv != NULL) {
+			usbd_devinfo(dev, 1, devinfo);
+			device_set_desc_copy(bdev, devinfo);
+			if (device_probe_and_attach(bdev) == 0) {
 				ifaces[i] = 0; /* consumed */
 				found++;
-
-#if defined(__FreeBSD__)
 				/* create another child for the next iface */
 				bdev = device_add_child(parent, NULL, -1);
 				if (!bdev) {
 					device_printf(parent,
 					    "Device add failed\n");
+					free(devinfo, M_USB);
 					return (USBD_NORMAL_COMPLETION);
 				}
 				uaap = malloc(sizeof(uaa), M_USB, M_NOWAIT);
 				if (uaap == NULL) {
+					free(devinfo, M_USB);
 					return (USBD_NOMEM);
 				}
 				device_set_ivars(bdev, uaap);
-				device_quiet(bdev);
-#endif
 			} else {
 				dev->subdevs[found] = 0;
 			}
 		}
 		if (found != 0) {
-#if defined(__FreeBSD__)
 			/* remove the last created child.  It is unused */
+			free(uaap, M_USB);
+			free(devinfo, M_USB);
 			device_delete_child(parent, bdev);
 			/* free(uaap, M_USB); */ /* May be needed? xxx */
-#endif
 			return (USBD_NORMAL_COMPLETION);
 		}
 		tmpdv = dev->subdevs;
@@ -965,17 +976,19 @@
 	uaa.usegeneric = 1;
 	uaa.configno = UHUB_UNK_CONFIGURATION;
 	uaa.ifaceno = UHUB_UNK_INTERFACE;
-	dev->subdevs = malloc(2 * sizeof dv, M_USB, M_NOWAIT);
+	dev->subdevs = malloc(2 * sizeof(device_t), M_USB, M_NOWAIT);
 	if (dev->subdevs == 0) {
+		free(devinfo, M_USB);
 		return (USBD_NOMEM);
 	}
 	dev->subdevs[0] = bdev;
 	dev->subdevs[1] = 0;
 	*uaap = uaa;
-	dv = USB_DO_ATTACH(dev, bdev, parent, &uaa, usbd_print, usbd_submatch);
-	if (dv != NULL) {
+	usbd_devinfo(dev, 1, devinfo);
+	device_set_desc_copy(bdev, devinfo);
+	free(devinfo, M_USB);
+	if (device_probe_and_attach(bdev) == 0)
 		return (USBD_NORMAL_COMPLETION);
-	}
 
 	/*
 	 * The generic attach failed, but leave the device as it is.
@@ -994,7 +1007,7 @@
  * and attach a driver.
  */
 usbd_status
-usbd_new_device(device_ptr_t parent, usbd_bus_handle bus, int depth,
+usbd_new_device(device_t parent, usbd_bus_handle bus, int depth,
 		int speed, int port, struct usbd_port *up)
 {
 	usbd_device_handle dev, adev;
@@ -1011,7 +1024,7 @@
 	addr = usbd_getnewaddr(bus);
 	if (addr < 0) {
 		printf("%s: No free USB addresses, new device ignored.\n",
-		       USBDEVNAME(bus->bdev));
+		       device_get_nameunit(bus->bdev));
 		return (USBD_NO_ADDR);
 	}
 
@@ -1041,6 +1054,20 @@
 
 	up->device = dev;
 
+	if (up->parent && speed > up->parent->speed) {
+#ifdef USB_DEBUG
+		printf("%s: maxium speed of attached "
+		    "device, %d, is higher than speed "
+		    "of parent HUB, %d.\n",
+		    __FUNCTION__, speed, up->parent->speed);
+#endif
+		/*
+		 * Reduce the speed, otherwise we won't setup the
+		 * proper transfer methods.
+		 */
+		speed = up->parent->speed;
+	}
+	
 	/* Locate port on upstream high speed hub */
 	for (adev = dev, hub = up->parent;
 	     hub != NULL && hub->speed != USB_SPEED_HIGH;
@@ -1071,11 +1098,12 @@
 		return (err);
 	}
 
-	/* Set the address.  Do this early; some devices need that. */
+	dd = &dev->ddesc;
 	/* Try a few times in case the device is slow (i.e. outside specs.) */
 	DPRINTFN(5,("usbd_new_device: setting device address=%d\n", addr));
 	for (i = 0; i < 15; i++) {
-		err = usbd_set_address(dev, addr);
+		/* Get the first 8 bytes of the device descriptor. */
+		err = usbd_get_desc(dev, UDESC_DEVICE, 0, USB_MAX_IPACKET, dd);
 		if (!err)
 			break;
 		usbd_delay_ms(dev, 200);
@@ -1084,21 +1112,8 @@
 			    "failed - trying a port reset\n", addr));
 			usbd_reset_port(up->parent, port, &ps);
 		}
-	}
-	if (err) {
-		DPRINTFN(-1,("usb_new_device: set address %d failed\n", addr));
-		err = USBD_SET_ADDR_FAILED;
-		usbd_remove_device(dev, up);
-		return (err);
-	}
-	/* Allow device time to set new address */
-	usbd_delay_ms(dev, USB_SET_ADDRESS_SETTLE);
-	dev->address = addr;	/* New device address now */
-	bus->devices[addr] = dev;
 
-	dd = &dev->ddesc;
-	/* Get the first 8 bytes of the device descriptor. */
-	err = usbd_get_desc(dev, UDESC_DEVICE, 0, USB_MAX_IPACKET, dd);
+	}
 	if (err) {
 		DPRINTFN(-1, ("usbd_new_device: addr=%d, getting first desc "
 			      "failed\n", addr));
@@ -1139,6 +1154,15 @@
 
 	USETW(dev->def_ep_desc.wMaxPacketSize, dd->bMaxPacketSize);
 
+	/* Re-establish the default pipe with the new max packet size. */
+	usbd_kill_pipe(dev->default_pipe);
+	err = usbd_setup_pipe(dev, 0, &dev->def_ep, USBD_DEFAULT_INTERVAL,
+	    &dev->default_pipe);
+	if (err) {
+		usbd_remove_device(dev, up);
+		return (err);
+	}
+
 	err = usbd_reload_device_desc(dev);
 	if (err) {
 		DPRINTFN(-1, ("usbd_new_device: addr=%d, getting full desc "
@@ -1147,6 +1171,30 @@
 		return (err);
 	}
 
+	/* Set the address */
+	DPRINTFN(5,("usbd_new_device: setting device address=%d\n", addr));
+	err = usbd_set_address(dev, addr);
+	if (err) {
+		DPRINTFN(-1,("usb_new_device: set address %d failed\n", addr));
+		err = USBD_SET_ADDR_FAILED;
+		usbd_remove_device(dev, up);
+		return (err);
+	}
+
+	/* Allow device time to set new address */
+	usbd_delay_ms(dev, USB_SET_ADDRESS_SETTLE);
+	dev->address = addr;	/* New device address now */
+	bus->devices[addr] = dev;
+
+	/* Re-establish the default pipe with the new address. */
+	usbd_kill_pipe(dev->default_pipe);
+	err = usbd_setup_pipe(dev, 0, &dev->def_ep, USBD_DEFAULT_INTERVAL,
+	    &dev->default_pipe);
+	if (err) {
+		usbd_remove_device(dev, up);
+		return (err);
+	}
+
 	/* Assume 100mA bus powered for now. Changed when configured. */
 	dev->power = USB_MIN_POWER;
 	dev->self_powered = 0;
@@ -1200,101 +1248,6 @@
 	free(dev, M_USB);
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-usbd_print(void *aux, const char *pnp)
-{
-	struct usb_attach_arg *uaa = aux;
-	char devinfo[1024];
-
-	DPRINTFN(15, ("usbd_print dev=%p\n", uaa->device));
-	if (pnp) {
-		if (!uaa->usegeneric)
-			return (QUIET);
-		usbd_devinfo(uaa->device, 1, devinfo);
-		printf("%s, %s", devinfo, pnp);
-	}
-	if (uaa->port != 0)
-		printf(" port %d", uaa->port);
-	if (uaa->configno != UHUB_UNK_CONFIGURATION)
-		printf(" configuration %d", uaa->configno);
-	if (uaa->ifaceno != UHUB_UNK_INTERFACE)
-		printf(" interface %d", uaa->ifaceno);
-#if 0
-	/*
-	 * It gets very crowded with these locators on the attach line.
-	 * They are not really needed since they are printed in the clear
-	 * by each driver.
-	 */
-	if (uaa->vendor != UHUB_UNK_VENDOR)
-		printf(" vendor 0x%04x", uaa->vendor);
-	if (uaa->product != UHUB_UNK_PRODUCT)
-		printf(" product 0x%04x", uaa->product);
-	if (uaa->release != UHUB_UNK_RELEASE)
-		printf(" release 0x%04x", uaa->release);
-#endif
-	return (UNCONF);
-}
-
-#if defined(__NetBSD__)
-int
-usbd_submatch(struct device *parent, struct cfdata *cf, void *aux)
-{
-#elif defined(__OpenBSD__)
-int
-usbd_submatch(struct device *parent, void *match, void *aux)
-{
-	struct cfdata *cf = match;
-#endif
-	struct usb_attach_arg *uaa = aux;
-
-	DPRINTFN(5,("usbd_submatch port=%d,%d configno=%d,%d "
-	    "ifaceno=%d,%d vendor=%d,%d product=%d,%d release=%d,%d\n",
-	    uaa->port, cf->uhubcf_port,
-	    uaa->configno, cf->uhubcf_configuration,
-	    uaa->ifaceno, cf->uhubcf_interface,
-	    uaa->vendor, cf->uhubcf_vendor,
-	    uaa->product, cf->uhubcf_product,
-	    uaa->release, cf->uhubcf_release));
-	if (uaa->port != 0 &&	/* root hub has port 0, it should match */
-	    ((uaa->port != 0 &&
-	      cf->uhubcf_port != UHUB_UNK_PORT &&
-	      cf->uhubcf_port != uaa->port) ||
-	     (uaa->configno != UHUB_UNK_CONFIGURATION &&
-	      cf->uhubcf_configuration != UHUB_UNK_CONFIGURATION &&
-	      cf->uhubcf_configuration != uaa->configno) ||
-	     (uaa->ifaceno != UHUB_UNK_INTERFACE &&
-	      cf->uhubcf_interface != UHUB_UNK_INTERFACE &&
-	      cf->uhubcf_interface != uaa->ifaceno) ||
-	     (uaa->vendor != UHUB_UNK_VENDOR &&
-	      cf->uhubcf_vendor != UHUB_UNK_VENDOR &&
-	      cf->uhubcf_vendor != uaa->vendor) ||
-	     (uaa->product != UHUB_UNK_PRODUCT &&
-	      cf->uhubcf_product != UHUB_UNK_PRODUCT &&
-	      cf->uhubcf_product != uaa->product) ||
-	     (uaa->release != UHUB_UNK_RELEASE &&
-	      cf->uhubcf_release != UHUB_UNK_RELEASE &&
-	      cf->uhubcf_release != uaa->release)
-	     )
-	   )
-		return 0;
-	if (cf->uhubcf_vendor != UHUB_UNK_VENDOR &&
-	    cf->uhubcf_vendor == uaa->vendor &&
-	    cf->uhubcf_product != UHUB_UNK_PRODUCT &&
-	    cf->uhubcf_product == uaa->product) {
-		/* We have a vendor&product locator match */
-		if (cf->uhubcf_release != UHUB_UNK_RELEASE &&
-		    cf->uhubcf_release == uaa->release)
-			uaa->matchlvl = UMATCH_VENDOR_PRODUCT_REV;
-		else
-			uaa->matchlvl = UMATCH_VENDOR_PRODUCT;
-	} else
-		uaa->matchlvl = 0;
-	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
-}
-
-#endif
-
 void
 usbd_fill_deviceinfo(usbd_device_handle dev, struct usb_device_info *di,
 		     int usedev)
@@ -1302,7 +1255,7 @@
 	struct usbd_port *p;
 	int i, err, s;
 
-	di->udi_bus = USBDEVUNIT(dev->bus->bdev);
+	di->udi_bus = device_get_unit(dev->bus->bdev);
 	di->udi_addr = dev->address;
 	di->udi_cookie = dev->cookie;
 	usbd_devinfo_vp(dev, di->udi_vendor, di->udi_product, usedev);
@@ -1321,7 +1274,7 @@
 		for (i = 0; dev->subdevs[i] && i < USB_MAX_DEVNAMES; i++) {
 			if (device_is_attached(dev->subdevs[i]))
 				strlcpy(di->udi_devnames[i],
-				    USBDEVPTRNAME(dev->subdevs[i]),
+				    device_get_nameunit(dev->subdevs[i]),
 				    USB_MAX_DEVNAMELEN);
 			else
 				di->udi_devnames[i][0] = 0;
@@ -1398,10 +1351,10 @@
  * been disconnected.
  */
 void
-usb_disconnect_port(struct usbd_port *up, device_ptr_t parent)
+usb_disconnect_port(struct usbd_port *up, device_t parent)
 {
 	usbd_device_handle dev = up->device;
-	const char *hubname = USBDEVPTRNAME(parent);
+	const char *hubname = device_get_nameunit(parent);
 	int i;
 
 	DPRINTFN(3,("uhub_disconnect: up=%p dev=%p port=%d\n",
@@ -1417,12 +1370,17 @@
 	if (dev->subdevs != NULL) {
 		DPRINTFN(3,("usb_disconnect_port: disconnect subdevs\n"));
 		for (i = 0; dev->subdevs[i]; i++) {
-			printf("%s: at %s", USBDEVPTRNAME(dev->subdevs[i]),
+			printf("%s: at %s", device_get_nameunit(dev->subdevs[i]),
 			       hubname);
 			if (up->portno != 0)
 				printf(" port %d", up->portno);
 			printf(" (addr %d) disconnected\n", dev->address);
-			config_detach(dev->subdevs[i], DETACH_FORCE);
+			struct usb_attach_arg *uaap =
+			    device_get_ivars(dev->subdevs[i]);
+			device_detach(dev->subdevs[i]);
+			free(uaap, M_USB);
+			device_delete_child(device_get_parent(dev->subdevs[i]),
+			    dev->subdevs[i]);
 			dev->subdevs[i] = NULL;
 		}
 	}
@@ -1432,17 +1390,3 @@
 	up->device = NULL;
 	usb_free_device(dev);
 }
-
-#ifdef __OpenBSD__
-void *usb_realloc(void *p, u_int size, int pool, int flags)
-{
-	void *q;
-
-	q = malloc(size, pool, flags);
-	if (q == NULL)
-		return (NULL);
-	bcopy(p, q, size);
-	free(p, pool);
-	return (q);
-}
-#endif
Index: usb.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/usb.h -L sys/dev/usb/usb.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/usb.h
+++ sys/dev/usb/usb.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: usb.h,v 1.69 2002/09/22 23:20:50 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/usb.h,v 1.39.2.1 2006/01/20 22:47:49 mux Exp $    */
+/*	$FreeBSD: src/sys/dev/usb/usb.h,v 1.47 2007/06/30 02:40:21 imp Exp $    */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -45,14 +45,27 @@
 #include <sys/types.h>
 #include <sys/time.h>
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/ioctl.h>
+#if defined(_KERNEL)
+#include "opt_usb.h"
+
+#ifdef SYSCTL_DECL
+SYSCTL_DECL(_hw_usb);
 #endif
 
-#if defined(_KERNEL)
-#include <dev/usb/usb_port.h>
+#include <sys/malloc.h>
+
+MALLOC_DECLARE(M_USB);
+MALLOC_DECLARE(M_USBDEV);
+MALLOC_DECLARE(M_USBHC);
 #endif /* _KERNEL */
 
+#define PWR_RESUME 0
+#define PWR_SUSPEND 1
+#define PWR_STANDBY 2
+#define PWR_SOFTSUSPEND 3
+#define PWR_SOFTSTANDBY 4
+#define PWR_SOFTRESUME 5
+
 /* These two defines are used by usbd to autoload the usb kld */
 #define USB_KLD		"usb"		/* name of usb module */
 #define USB_UHUB	"usb/uhub"	/* root hub */
@@ -98,11 +111,7 @@
 #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
 #endif
 
-#if defined(__FreeBSD__) && (__FreeBSD_version <= 500014)
-#define UPACKED __attribute__ ((packed))
-#else
 #define UPACKED __packed
-#endif
 
 typedef struct {
 	uByte		bmRequestType;
@@ -426,6 +435,7 @@
 #define UICLASS_HID		0x03
 #define  UISUBCLASS_BOOT	1
 #define  UIPROTO_BOOT_KEYBOARD	1
+#define  UIPROTO_MOUSE		2
 
 #define UICLASS_PHYSICAL	0x05
 
Index: if_auereg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_auereg.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_auereg.h -L sys/dev/usb/if_auereg.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_auereg.h
+++ sys/dev/usb/if_auereg.h
@@ -2,6 +2,9 @@
  * Copyright (c) 1997, 1998, 1999
  *	Bill Paul <wpaul at ee.columbia.edu>.  All rights reserved.
  *
+ * Copyright (c) 2006
+ *      Alfred Perlstein <alfred at freebsd.org>. All rights reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -29,7 +32,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/if_auereg.h,v 1.22 2005/06/10 16:49:15 brooks Exp $
+ * $FreeBSD: src/sys/dev/usb/if_auereg.h,v 1.27 2007/01/08 23:24:21 alfred Exp $
  */
 
 /*
@@ -46,6 +49,9 @@
  * the RX case, the data includes an optional RX status word.
  */
 
+#ifndef AUEREG_H
+#define AUEREG_H
+
 #define AUE_UR_READREG		0xF0
 #define AUE_UR_WRITEREG		0xF1
 
@@ -217,26 +223,72 @@
 	usbd_pipe_handle	aue_ep[AUE_ENDPT_MAX];
 	int			aue_unit;
 	u_int8_t		aue_link;
+	int			aue_timer;
 	int			aue_if_flags;
 	struct ue_cdata		aue_cdata;
-	struct callout_handle	aue_stat_ch;
-#if __FreeBSD_version >= 500000
+	struct callout		aue_tick_callout;
+	struct usb_taskqueue	aue_taskqueue;
+	struct task		aue_task;
 	struct mtx		aue_mtx;
-#endif
+	struct sx		aue_sx;
 	u_int16_t		aue_flags;
 	char			aue_dying;
 	struct timeval		aue_rx_notice;
 	struct usb_qdat		aue_qdat;
+	int			aue_deferedtasks;
 };
 
 #if 0
-#define	AUE_LOCK(_sc)		mtx_lock(&(_sc)->aue_mtx)
-#define	AUE_UNLOCK(_sc)		mtx_unlock(&(_sc)->aue_mtx)
+/*
+ * Some debug code to make sure we don't take a blocking lock in
+ * interrupt context.
+ */
+#include <sys/types.h>
+#include <sys/proc.h>
+#include <sys/kdb.h>
+
+#define AUE_DUMPSTATE(tag)	aue_dumpstate(__func__, tag)
+
+static inline void
+aue_dumpstate(const char *func, const char *tag)
+{
+	if ((curthread->td_pflags & TDP_NOSLEEPING) ||
+	    (curthread->td_pflags & TDP_ITHREAD)) {
+		kdb_backtrace();
+		printf("%s: %s sleep: %sok ithread: %s\n", func, tag,
+			curthread->td_pflags & TDP_NOSLEEPING ? "not" : "",
+			curthread->td_pflags & TDP_ITHREAD ?  "yes" : "no");
+	}
+}
 #else
-#define	AUE_LOCK(_sc)
-#define	AUE_UNLOCK(_sc)
+#define AUE_DUMPSTATE(tag)
 #endif
 
+#define AUE_LOCK(_sc)			mtx_lock(&(_sc)->aue_mtx)
+#define AUE_UNLOCK(_sc)			mtx_unlock(&(_sc)->aue_mtx)
+#define AUE_SXLOCK(_sc)	\
+    do { AUE_DUMPSTATE("sxlock"); sx_xlock(&(_sc)->aue_sx); } while(0)
+#define AUE_SXUNLOCK(_sc)		sx_xunlock(&(_sc)->aue_sx)
+#define AUE_SXASSERTLOCKED(_sc)		sx_assert(&(_sc)->aue_sx, SX_XLOCKED)
+#define AUE_SXASSERTUNLOCKED(_sc)	sx_assert(&(_sc)->aue_sx, SX_UNLOCKED)
+
 #define AUE_TIMEOUT		1000
 #define AUE_MIN_FRAMELEN	60
 #define AUE_INTR_INTERVAL	100 /* ms */
+
+/*
+ * These bits are used to notify the task about pending events.
+ * The names correspond to the interrupt context routines that would
+ * be normally called.  (example: AUE_TASK_WATCHDOG -> aue_watchdog())
+ */
+#define AUE_TASK_WATCHDOG	0x0001
+#define AUE_TASK_TICK		0x0002
+#define AUE_TASK_START		0x0004
+#define AUE_TASK_RXSTART	0x0008
+#define AUE_TASK_RXEOF		0x0010
+#define AUE_TASK_TXEOF		0x0020
+
+#define AUE_GIANTLOCK()		mtx_lock(&Giant);
+#define AUE_GIANTUNLOCK()	mtx_unlock(&Giant);
+
+#endif /* !AUEREG_H */
Index: uvisor.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uvisor.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/uvisor.c -L sys/dev/usb/uvisor.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/uvisor.c
+++ sys/dev/usb/uvisor.c
@@ -1,5 +1,5 @@
 /*	$NetBSD: uvisor.c,v 1.9 2001/01/23 14:04:14 augustss Exp $	*/
-/*      $FreeBSD: src/sys/dev/usb/uvisor.c,v 1.24.2.1 2005/12/12 19:52:52 bmah Exp $	*/
+/*      $FreeBSD: src/sys/dev/usb/uvisor.c,v 1.40 2007/07/05 06:28:46 imp Exp $	*/
 
 /* Also already merged from NetBSD:
  *	$NetBSD: uvisor.c,v 1.12 2001/11/13 06:24:57 lukem Exp $
@@ -58,12 +58,8 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
-#endif
 #include <sys/conf.h>
 #include <sys/tty.h>
 #include <sys/sysctl.h>
@@ -175,11 +171,11 @@
 	u_int16_t		sc_flags;
 };
 
-Static usbd_status uvisor_init(struct uvisor_softc *);
+static usbd_status uvisor_init(struct uvisor_softc *);
 
-/*Static usbd_status clie_3_5_init(struct uvisor_softc *);*/
+/*static usbd_status clie_3_5_init(struct uvisor_softc *);*/
 
-Static void uvisor_close(void *, int);
+static void uvisor_close(void *, int);
 
 struct ucom_callback uvisor_callback = {
 	NULL,
@@ -192,10 +188,10 @@
 	NULL,
 };
 
-Static device_probe_t uvisor_match;
-Static device_attach_t uvisor_attach;
-Static device_detach_t uvisor_detach;
-Static device_method_t uvisor_methods[] = {
+static device_probe_t uvisor_match;
+static device_attach_t uvisor_attach;
+static device_detach_t uvisor_detach;
+static device_method_t uvisor_methods[] = {
        /* Device interface */
        DEVMETHOD(device_probe, uvisor_match),
        DEVMETHOD(device_attach, uvisor_attach),
@@ -204,7 +200,7 @@
  };
 
 
-Static driver_t uvisor_driver = {
+static driver_t uvisor_driver = {
        "ucom",
        uvisor_methods,
        sizeof (struct uvisor_softc)
@@ -223,6 +219,9 @@
 #define PALM35  0x0004
 };
 static const struct uvisor_type uvisor_devs[] = {
+	{{ USB_VENDOR_ACEECA, USB_PRODUCT_ACEECA_MEZ1000 }, PALM4 },
+	{{ USB_VENDOR_GARMIN, USB_PRODUCT_GARMIN_IQUE_3600 }, PALM4 },
+	{{ USB_VENDOR_FOSSIL, USB_PRODUCT_FOSSIL_WRISTPDA }, PALM4 },
 	{{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_VISOR }, VISOR },
 	{{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO }, PALM4 },
 	{{ USB_VENDOR_HANDSPRING, USB_PRODUCT_HANDSPRING_TREO600 }, PALM4 },
@@ -236,20 +235,24 @@
 	{{ USB_VENDOR_PALM, USB_PRODUCT_PALM_TUNGSTEN_T }, PALM4 },
 	{{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE }, PALM4 },
 	{{ USB_VENDOR_PALM, USB_PRODUCT_PALM_ZIRE31 }, PALM4 },
+	{{ USB_VENDOR_SAMSUNG, USB_PRODUCT_SAMSUNG_I500 }, PALM4 }, 
 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40 }, 0 },
 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_41 }, PALM4 },
 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_S360 }, PALM4 },
 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_NX60 }, PALM4 },
 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_35 }, PALM35 },
 /*	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_25 }, PALM4 },*/
+/*	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TH55 }, PALM4 }, */	/* See PR 80935 */
 	{{ USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_TJ37 }, PALM4 },
+	{{ USB_VENDOR_TAPWAVE, USB_PRODUCT_TAPWAVE_ZODIAC }, PALM4 },
 };
 #define uvisor_lookup(v, p) ((const struct uvisor_type *)usb_lookup(uvisor_devs, v, p))
 
 
-USB_MATCH(uvisor)
+static int
+uvisor_match(device_t self)
 {
-	USB_MATCH_START(uvisor, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 
 	if (uaa->iface != NULL)
 		return (UMATCH_NONE);
@@ -261,53 +264,41 @@
 		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
 }
 
-USB_ATTACH(uvisor)
+static int
+uvisor_attach(device_t self)
 {
-	USB_ATTACH_START(uvisor, sc, uaa);
+	struct uvisor_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev = uaa->device;
 	usbd_interface_handle iface;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char *devinfo;
-	const char *devname;
 	int i;
 	usbd_status err;
 	struct ucom_softc *ucom;
 
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
 	ucom = &sc->sc_ucom;
-
-	bzero(sc, sizeof (struct uvisor_softc));
-	usbd_devinfo(dev, 0, devinfo);
-
 	ucom->sc_dev = self;
-	device_set_desc_copy(self, devinfo);
-
 	ucom->sc_udev = dev;
 	ucom->sc_iface = uaa->iface;
 
-	devname = USBDEVNAME(ucom->sc_dev);
-	printf("%s: %s\n", devname, devinfo);
-
 	DPRINTFN(10,("\nuvisor_attach: sc=%p\n", sc));
 
 	/* Move the device into the configured state. */
 	err = usbd_set_config_index(dev, UVISOR_CONFIG_INDEX, 1);
 	if (err) {
-		printf("\n%s: failed to set configuration, err=%s\n",
-		       devname, usbd_errstr(err));
+		device_printf(self, "failed to set configuration, err=%s\n",
+		    usbd_errstr(err));
 		goto bad;
 	}
 
 	err = usbd_device2interface_handle(dev, UVISOR_IFACE_INDEX, &iface);
 	if (err) {
-		printf("\n%s: failed to get interface, err=%s\n",
-		       devname, usbd_errstr(err));
+		device_printf(self, "failed to get interface, err=%s\n",
+		    usbd_errstr(err));
 		goto bad;
 	}
 
-	printf("%s: %s\n", devname, devinfo);
-
 	sc->sc_flags = uvisor_lookup(uaa->vendor, uaa->product)->uv_flags;
 
 	id = usbd_get_interface_descriptor(iface);
@@ -320,8 +311,9 @@
 		int addr, dir, attr;
 		ed = usbd_interface2endpoint_descriptor(iface, i);
 		if (ed == NULL) {
-			printf("%s: could not read endpoint descriptor"
-			       ": %s\n", devname, usbd_errstr(err));
+			device_printf(self,
+			    "could not read endpoint descriptor: %s\n",
+			    usbd_errstr(err));
 			goto bad;
 		}
 
@@ -333,18 +325,16 @@
 		else if (dir == UE_DIR_OUT && attr == UE_BULK)
 			ucom->sc_bulkout_no = addr;
 		else {
-			printf("%s: unexpected endpoint\n", devname);
+			device_printf(self, "unexpected endpoint\n");
 			goto bad;
 		}
 	}
 	if (ucom->sc_bulkin_no == -1) {
-		printf("%s: Could not find data bulk in\n",
-		       USBDEVNAME(ucom->sc_dev));
+		device_printf(self, "Could not find data bulk in\n");
 		goto bad;
 	}
 	if (ucom->sc_bulkout_no == -1) {
-		printf("%s: Could not find data bulk out\n",
-		       USBDEVNAME(ucom->sc_dev));
+		device_printf(self, "Could not find data bulk out\n");
 		goto bad;
 	}
 
@@ -366,29 +356,29 @@
 		err = uvisor_init(sc);
 
 	if (err) {
-		printf("%s: init failed, %s\n", USBDEVNAME(ucom->sc_dev),
-		       usbd_errstr(err));
+		device_printf(ucom->sc_dev, "init failed, %s\n",
+		    usbd_errstr(err));
 		goto bad;
 	}
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, ucom->sc_udev,
-			   USBDEV(ucom->sc_dev));
+	  ucom->sc_dev);
 
 	DPRINTF(("uvisor: in=0x%x out=0x%x\n", ucom->sc_bulkin_no, ucom->sc_bulkout_no));
 	ucom_attach(&sc->sc_ucom);
 
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
 bad:
 	DPRINTF(("uvisor_attach: ATTACH ERROR\n"));
 	ucom->sc_dying = 1;
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
 #if 0
 
 int
-uvisor_activate(device_ptr_t self, enum devact act)
+uvisor_activate(device_t self, enum devact act)
 {
 	struct uvisor_softc *sc = (struct uvisor_softc *)self;
 	int rv = 0;
@@ -409,9 +399,10 @@
 
 #endif
 
-USB_DETACH(uvisor)
+static int
+uvisor_detach(device_t self)
 {
-	USB_DETACH_START(uvisor, sc);
+	struct uvisor_softc *sc = device_get_softc(self);
 	int rv = 0;
 
 	DPRINTF(("uvisor_detach: sc=%p\n", sc));
@@ -419,7 +410,7 @@
 	rv = ucom_detach(&sc->sc_ucom);
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_ucom.sc_udev,
-			   USBDEV(sc->sc_ucom.sc_dev));
+	  sc->sc_ucom.sc_dev);
 
 	return (rv);
 }
@@ -454,7 +445,7 @@
 		char *string;
 
 		np = UGETW(coninfo.num_ports);
-		printf("%s: Number of ports: %d\n", USBDEVNAME(sc->sc_ucom.sc_dev), np);
+		device_printf(sc->sc_ucom.sc_dev, "Number of ports: %d\n", np);
 		for (i = 0; i < np; ++i) {
 			switch (coninfo.connections[i].port_function_id) {
 			case UVISOR_FUNCTION_GENERIC:
@@ -473,9 +464,9 @@
 				string = "unknown";
 				break;
 			}
-			printf("%s: port %d, is for %s\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev), coninfo.connections[i].port,
-			    string);
+			device_printf(sc->sc_ucom.sc_dev,
+			    "port %d, is for %s\n",
+			    coninfo.connections[i].port, string);
 		}
 	}
 #endif
@@ -595,7 +586,7 @@
 		char *string;
 
 		np = UGETW(coninfo.num_ports);
-		DPRINTF(("%s: Number of ports: %d\n", USBDEVNAME(sc->sc_ucom.sc_dev), np));
+		DPRINTF(("%s: Number of ports: %d\n", device_get_nameunit(sc->sc_ucom.sc_dev), np));
 		for (i = 0; i < np; ++i) {
 			switch (coninfo.connections[i].port_function_id) {
 			case UVISOR_FUNCTION_GENERIC:
@@ -615,7 +606,7 @@
 				break;	
 			}
 			DPRINTF(("%s: port %d, is for %s\n",
-			    USBDEVNAME(sc->sc_ucom.sc_dev), coninfo.connections[i].port,
+			    device_get_nameunit(sc->sc_ucom.sc_dev), coninfo.connections[i].port,
 			    string));
 		}
 	}
Index: usbdi.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usbdi.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usbdi.h -L sys/dev/usb/usbdi.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usbdi.h
+++ sys/dev/usb/usbdi.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: usbdi.h,v 1.64 2004/10/23 13:26:34 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/usbdi.h,v 1.59 2005/05/16 06:58:43 imp Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/usbdi.h,v 1.63 2007/06/30 20:18:44 imp Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -162,7 +162,7 @@
 const char *usbd_errstr(usbd_status);
 
 void usbd_add_dev_event(int, usbd_device_handle);
-void usbd_add_drv_event(int, usbd_device_handle, device_ptr_t);
+void usbd_add_drv_event(int, usbd_device_handle, device_t);
 
 void usbd_devinfo(usbd_device_handle, int, char *);
 const struct usbd_quirks *usbd_get_quirks(usbd_device_handle);
@@ -173,7 +173,8 @@
 
 int usbd_ratecheck(struct timeval *last);
 
-usbd_status usbd_get_string(usbd_device_handle dev, int si, char *buf);
+usbd_status usbd_get_string(usbd_device_handle dev, int si, char *buf,
+    size_t len);
 
 /* An iterator for descriptors. */
 typedef struct {
@@ -193,12 +194,16 @@
 	TAILQ_ENTRY(usb_task) next;
 	void (*fun)(void *);
 	void *arg;
-	char onqueue;
+	int queue;
 };
+#define USB_TASKQ_HC		0
+#define USB_TASKQ_DRIVER	1
+#define USB_NUM_TASKQS		2
+#define USB_TASKQ_NAMES		{"usbtask-hc", "usbtask-dr"}
 
-void usb_add_task(usbd_device_handle, struct usb_task *);
+void usb_add_task(usbd_device_handle, struct usb_task *, int queue);
 void usb_rem_task(usbd_device_handle, struct usb_task *);
-#define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->onqueue = 0)
+#define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->queue = -1)
 
 struct usb_devno {
 	u_int16_t ud_vendor;
@@ -228,29 +233,6 @@
 	int			nifaces; /* number of interfaces */
 };
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-/* Match codes. */
-/* First five codes is for a whole device. */
-#define UMATCH_VENDOR_PRODUCT_REV			14
-#define UMATCH_VENDOR_PRODUCT				13
-#define UMATCH_VENDOR_DEVCLASS_DEVPROTO			12
-#define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		11
-#define UMATCH_DEVCLASS_DEVSUBCLASS			10
-/* Next six codes are for interfaces. */
-#define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		 9
-#define UMATCH_VENDOR_PRODUCT_CONF_IFACE		 8
-#define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		 7
-#define UMATCH_VENDOR_IFACESUBCLASS			 6
-#define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	 5
-#define UMATCH_IFACECLASS_IFACESUBCLASS			 4
-#define UMATCH_IFACECLASS				 3
-#define UMATCH_IFACECLASS_GENERIC			 2
-/* Generic driver */
-#define UMATCH_GENERIC					 1
-/* No match */
-#define UMATCH_NONE					 0
-
-#elif defined(__FreeBSD__)
 /* FreeBSD needs values less than zero */
 #define UMATCH_VENDOR_PRODUCT_REV			(-10)
 #define UMATCH_VENDOR_PRODUCT				(-20)
@@ -268,12 +250,9 @@
 #define UMATCH_GENERIC					(-140)
 #define UMATCH_NONE					(ENXIO)
 
-#endif
-
 #define USBD_SHOW_DEVICE_CLASS		0x1
 #define USBD_SHOW_INTERFACE_CLASS	0x2
 
-#if defined(__FreeBSD__)
 int usbd_driver_load(module_t mod, int what, void *arg);
 
 static inline int
@@ -290,8 +269,6 @@
 	return (uap->iface);
 }
 
-#endif
-
 /* XXX Perhaps USB should have its own levels? */
 #ifdef USB_USE_SOFTINTR
 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
Index: ehcireg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ehcireg.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/ehcireg.h -L sys/dev/usb/ehcireg.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/ehcireg.h
+++ sys/dev/usb/ehcireg.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: ehcireg.h,v 1.18 2004/10/22 10:38:17 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/ehcireg.h,v 1.7.2.1 2006/01/26 01:43:13 iedowse Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/ehcireg.h,v 1.8 2005/09/18 11:45:39 netchild Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
Index: uhub.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uhub.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/uhub.c -L sys/dev/usb/uhub.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/uhub.c
+++ sys/dev/usb/uhub.c
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uhub.c,v 1.69.2.1 2005/12/18 15:51:31 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uhub.c,v 1.82 2007/06/30 20:18:44 imp Exp $");
 
 /*
  * USB spec: http://www.usb.org/developers/docs/usbspec.zip
@@ -48,15 +48,10 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#include <sys/proc.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
-#endif
 #include <sys/sysctl.h>
 
 #include <machine/bus.h>
@@ -69,8 +64,10 @@
 #define UHUB_INTR_INTERVAL 255	/* ms */
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (uhubdebug) logprintf x
-#define DPRINTFN(n,x)	if (uhubdebug>(n)) logprintf x
+#define DPRINTF(x)	if (uhubdebug) printf x
+#define DPRINTFN(n,x)	if (uhubdebug > (n)) printf x
+#define DEVPRINTF(x)	if (uhubdebug) device_printf x
+#define DEVPRINTFN(n, x)if (uhubdebug > (n)) device_printf x
 int	uhubdebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, uhub, CTLFLAG_RW, 0, "USB uhub");
 SYSCTL_INT(_hw_usb_uhub, OID_AUTO, debug, CTLFLAG_RW,
@@ -78,27 +75,23 @@
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n,x)
+#define DEVPRINTF(x)
+#define DEVPRINTFN(n,x)
 #endif
 
 struct uhub_softc {
-	USBBASEDEVICE		sc_dev;		/* base device */
+	device_t		sc_dev;		/* base device */
 	usbd_device_handle	sc_hub;		/* USB device */
 	usbd_pipe_handle	sc_ipipe;	/* interrupt pipe */
-	u_int8_t		sc_status[1];	/* XXX more ports */
+	u_int8_t		sc_status[32];	/* max 255 ports */
 	u_char			sc_running;
 };
 #define UHUB_PROTO(sc) ((sc)->sc_hub->ddesc.bDeviceProtocol)
 #define UHUB_IS_HIGH_SPEED(sc) (UHUB_PROTO(sc) != UDPROTO_FSHUB)
 #define UHUB_IS_SINGLE_TT(sc) (UHUB_PROTO(sc) == UDPROTO_HSHUBSTT)
 
-Static usbd_status uhub_explore(usbd_device_handle hub);
-Static void uhub_intr(usbd_xfer_handle, usbd_private_handle,usbd_status);
-
-#if defined(__FreeBSD__)
-Static bus_child_location_str_t uhub_child_location_str;
-Static bus_child_pnpinfo_str_t uhub_child_pnpinfo_str;
-#endif
-
+static usbd_status uhub_explore(usbd_device_handle hub);
+static void uhub_intr(usbd_xfer_handle, usbd_private_handle,usbd_status);
 
 /*
  * We need two attachment points:
@@ -106,49 +99,65 @@
  * Every other driver only connects to hubs
  */
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-USB_DECLARE_DRIVER(uhub);
+static device_probe_t uhub_match;
+static device_attach_t uhub_attach;
+static device_detach_t uhub_detach;
+static bus_child_location_str_t uhub_child_location_str;
+static bus_child_pnpinfo_str_t uhub_child_pnpinfo_str;
+
+static device_method_t uhub_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		uhub_match),
+	DEVMETHOD(device_attach,	uhub_attach),
+	DEVMETHOD(device_detach,	uhub_detach),
+	DEVMETHOD(device_suspend,	bus_generic_suspend),
+	DEVMETHOD(device_resume,	bus_generic_resume),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
 
-/* Create the driver instance for the hub connected to hub case */
-CFATTACH_DECL(uhub_uhub, sizeof(struct uhub_softc),
-    uhub_match, uhub_attach, uhub_detach, uhub_activate);
-#elif defined(__FreeBSD__)
-USB_DECLARE_DRIVER_INIT(uhub,
 	DEVMETHOD(bus_child_pnpinfo_str, uhub_child_pnpinfo_str),
 	DEVMETHOD(bus_child_location_str, uhub_child_location_str),
-	DEVMETHOD(bus_driver_added, bus_generic_driver_added),
-	DEVMETHOD(device_suspend, bus_generic_suspend),
-	DEVMETHOD(device_resume, bus_generic_resume),
-	DEVMETHOD(device_shutdown, bus_generic_shutdown)
-	);
+	/* XXX driver_added needs special care */
+	DEVMETHOD(bus_driver_added,	bus_generic_driver_added),
+	{ 0, 0 }
+};
+
+static driver_t uhub_driver = {
+	"uhub",
+	uhub_methods,
+	sizeof(struct uhub_softc)
+};
+
+static devclass_t uhub_devclass;
 
 /* Create the driver instance for the hub connected to usb case. */
 devclass_t uhubroot_devclass;
 
-Static device_method_t uhubroot_methods[] = {
+static device_method_t uhubroot_methods[] = {
+	DEVMETHOD(device_probe,		uhub_match),
+	DEVMETHOD(device_attach,	uhub_attach),
+	DEVMETHOD(device_detach,	uhub_detach),
+	DEVMETHOD(device_suspend,	bus_generic_suspend),
+	DEVMETHOD(device_resume,	bus_generic_resume),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+
 	DEVMETHOD(bus_child_location_str, uhub_child_location_str),
 	DEVMETHOD(bus_child_pnpinfo_str, uhub_child_pnpinfo_str),
-	DEVMETHOD(bus_driver_added, bus_generic_driver_added),
+	/* XXX driver_added needs special care */
+	DEVMETHOD(bus_driver_added,	bus_generic_driver_added),
 
-	DEVMETHOD(device_probe, uhub_match),
-	DEVMETHOD(device_attach, uhub_attach),
-	DEVMETHOD(device_detach, uhub_detach),
-	DEVMETHOD(device_suspend, bus_generic_suspend),
-	DEVMETHOD(device_resume, bus_generic_resume),
-	DEVMETHOD(device_shutdown, bus_generic_shutdown),
 	{0,0}
 };
 
-Static	driver_t uhubroot_driver = {
+static	driver_t uhubroot_driver = {
 	"uhub",
 	uhubroot_methods,
 	sizeof(struct uhub_softc)
 };
-#endif
 
-USB_MATCH(uhub)
+static int
+uhub_match(device_t self)
 {
-	USB_MATCH_START(uhub, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_device_descriptor_t *dd = usbd_get_device_descriptor(uaa->device);
 
 	DPRINTFN(5,("uhub_match, dd=%p\n", dd));
@@ -161,11 +170,12 @@
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(uhub)
+int
+uhub_attach(device_t self)
 {
-	USB_ATTACH_START(uhub, sc, uaa);
+	struct uhub_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev = uaa->device;
-	char *devinfo;
 	usbd_status err;
 	struct usbd_hub *hub = NULL;
 	usb_device_request_t req;
@@ -175,34 +185,26 @@
 	usb_endpoint_descriptor_t *ed;
 	struct usbd_tt *tts = NULL;
 
-	devinfo = malloc(1024, M_TEMP, M_NOWAIT);
-	if (devinfo == NULL) {
-		USB_ATTACH_ERROR_RETURN;
-	}
 	DPRINTFN(1,("uhub_attach\n"));
 	sc->sc_hub = dev;
-	usbd_devinfo(dev, 1, devinfo);
-	USB_ATTACH_SETUP;
+	sc->sc_dev = self;
 
 	if (dev->depth > 0 && UHUB_IS_HIGH_SPEED(sc)) {
-		printf("%s: %s transaction translator%s\n",
-		    USBDEVNAME(sc->sc_dev),
+		device_printf(sc->sc_dev, "%s transaction translator%s\n",
 		    UHUB_IS_SINGLE_TT(sc) ? "single" : "multiple",
 		    UHUB_IS_SINGLE_TT(sc) ? "" : "s");
 	}
 	err = usbd_set_config_index(dev, 0, 1);
 	if (err) {
-		DPRINTF(("%s: configuration failed, error=%s\n",
-			 USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
-		free(devinfo, M_TEMP);
-		USB_ATTACH_ERROR_RETURN;
+		DEVPRINTF((sc->sc_dev, "configuration failed, error=%s\n",
+		    usbd_errstr(err)));
+		return (ENXIO);
 	}
 
 	if (dev->depth > USB_HUB_MAX_DEPTH) {
-		printf("%s: hub depth (%d) exceeded, hub ignored\n",
-		       USBDEVNAME(sc->sc_dev), USB_HUB_MAX_DEPTH);
-		free(devinfo, M_TEMP);
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(sc->sc_dev, "hub depth (%d) exceeded, hub ignored\n",
+		    USB_HUB_MAX_DEPTH);
+		return (ENXIO);
 	}
 
 	/* Get hub descriptor. */
@@ -219,29 +221,27 @@
 		err = usbd_do_request(dev, &req, &hubdesc);
 	}
 	if (err) {
-		DPRINTF(("%s: getting hub descriptor failed, error=%s\n",
-			 USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
-		free(devinfo, M_TEMP);
-		USB_ATTACH_ERROR_RETURN;
+		DEVPRINTF((sc->sc_dev, "getting hub descriptor failed: %s\n",
+		    usbd_errstr(err)));
+		return (ENXIO);
 	}
 
 	for (nremov = 0, port = 1; port <= nports; port++)
 		if (!UHD_NOT_REMOV(&hubdesc, port))
 			nremov++;
-	printf("%s: %d port%s with %d removable, %s powered\n",
-	       USBDEVNAME(sc->sc_dev), nports, nports != 1 ? "s" : "",
-	       nremov, dev->self_powered ? "self" : "bus");
+	device_printf(sc->sc_dev, "%d port%s with %d removable, %s powered\n",
+	    nports, nports != 1 ? "s" : "", nremov,
+	    dev->self_powered ? "self" : "bus");
 
 	if (nports == 0) {
-		printf("%s: no ports, hub ignored\n", USBDEVNAME(sc->sc_dev));
+		device_printf(sc->sc_dev, "no ports, hub ignored\n");
 		goto bad;
 	}
 
 	hub = malloc(sizeof(*hub) + (nports-1) * sizeof(struct usbd_port),
 		     M_USBDEV, M_NOWAIT);
 	if (hub == NULL) {
-		free(devinfo, M_TEMP);
-		USB_ATTACH_ERROR_RETURN;
+		return (ENXIO);
 	}
 	dev->hub = hub;
 	dev->hub->hubsoftc = sc;
@@ -256,40 +256,39 @@
 
 	if (!dev->self_powered && dev->powersrc->parent != NULL &&
 	    !dev->powersrc->parent->self_powered) {
-		printf("%s: bus powered hub connected to bus powered hub, "
-		       "ignored\n", USBDEVNAME(sc->sc_dev));
+		device_printf(sc->sc_dev, "bus powered hub connected to bus "
+		    "powered hub, ignored\n");
 		goto bad;
 	}
 
 	/* Set up interrupt pipe. */
 	err = usbd_device2interface_handle(dev, 0, &iface);
 	if (err) {
-		printf("%s: no interface handle\n", USBDEVNAME(sc->sc_dev));
+		device_printf(sc->sc_dev, "no interface handle\n");
 		goto bad;
 	}
 	ed = usbd_interface2endpoint_descriptor(iface, 0);
 	if (ed == NULL) {
-		printf("%s: no endpoint descriptor\n", USBDEVNAME(sc->sc_dev));
+		device_printf(sc->sc_dev, "no endpoint descriptor\n");
 		goto bad;
 	}
 	if ((ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
-		printf("%s: bad interrupt endpoint\n", USBDEVNAME(sc->sc_dev));
+		device_printf(sc->sc_dev, "bad interrupt endpoint\n");
 		goto bad;
 	}
 
 	err = usbd_open_pipe_intr(iface, ed->bEndpointAddress,
 		  USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_status,
-		  sizeof(sc->sc_status), uhub_intr, UHUB_INTR_INTERVAL);
+	          (nports + 1 + 7) / 8, uhub_intr, UHUB_INTR_INTERVAL);
 	if (err) {
-		printf("%s: cannot open interrupt pipe\n",
-		       USBDEVNAME(sc->sc_dev));
+		device_printf(sc->sc_dev, "cannot open interrupt pipe\n");
 		goto bad;
 	}
 
 	/* Wait with power off for a while. */
 	usbd_delay_ms(dev, USB_POWER_DOWN_TIME);
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, USBDEV(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, sc->sc_dev);
 
 	/*
 	 * To have the best chance of success we do things in the exact same
@@ -351,9 +350,9 @@
 		/* Turn the power on. */
 		err = usbd_set_port_feature(dev, port, UHF_PORT_POWER);
 		if (err)
-			printf("%s: port %d power on failed, %s\n",
-			       USBDEVNAME(sc->sc_dev), port,
-			       usbd_errstr(err));
+			device_printf(sc->sc_dev,
+			    "port %d power on failed, %s\n", port,
+			    usbd_errstr(err));
 		DPRINTF(("usb_init_port: turn on port %d power\n", port));
 		/* Wait for stable power. */
 		usbd_delay_ms(dev, pwrdly);
@@ -362,15 +361,12 @@
 	/* The usual exploration will finish the setup. */
 
 	sc->sc_running = 1;
-
-	USB_ATTACH_SUCCESS_RETURN;
-
+	return (0);
  bad:
 	if (hub)
 		free(hub, M_USBDEV);
-	free(devinfo, M_TEMP);
 	dev->hub = NULL;
-	USB_ATTACH_ERROR_RETURN;
+	return (ENXIO);
 }
 
 usbd_status
@@ -403,8 +399,9 @@
 		}
 		status = UGETW(up->status.wPortStatus);
 		change = UGETW(up->status.wPortChange);
-		DPRINTFN(3,("uhub_explore: %s port %d status 0x%04x 0x%04x\n",
-			    USBDEVNAME(sc->sc_dev), port, status, change));
+		DEVPRINTFN(3,(sc->sc_dev,
+		    "uhub_explore: port %d status 0x%04x 0x%04x\n", port,
+		    status, change));
 		if (change & UPS_C_PORT_ENABLED) {
 			DPRINTF(("uhub_explore: C_PORT_ENABLED 0x%x\n", change));
 			usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE);
@@ -412,21 +409,21 @@
 				/* Ignore the port error if the device
 				   vanished. */
 			} else if (status & UPS_PORT_ENABLED) {
-				printf("%s: illegal enable change, port %d\n",
-				       USBDEVNAME(sc->sc_dev), port);
+				device_printf(sc->sc_dev,
+				    "illegal enable change, port %d\n", port);
 			} else {
 				/* Port error condition. */
 				if (up->restartcnt) /* no message first time */
-					printf("%s: port error, restarting "
-					       "port %d\n",
-					       USBDEVNAME(sc->sc_dev), port);
+					device_printf(sc->sc_dev,
+					    "port error, restarting port %d\n",
+					    port);
 
 				if (up->restartcnt++ < USBD_RESTART_MAX)
 					goto disco;
 				else
-					printf("%s: port error, giving up "
-					       "port %d\n",
-					  USBDEVNAME(sc->sc_dev), port);
+					device_printf(sc->sc_dev,
+					    "port error, giving up port %d\n",
+					    port);
 			}
 		}
 		if (!(change & UPS_C_CONNECT_STATUS)) {
@@ -438,8 +435,8 @@
 #if 0 && defined(DIAGNOSTIC)
 			if (up->device == NULL &&
 			    (status & UPS_CURRENT_CONNECT_STATUS))
-				printf("%s: connected, no device\n",
-				       USBDEVNAME(sc->sc_dev));
+				deivce_printf(sc->sc_dev,
+				    "connected, no device\n");
 #endif
 			continue;
 		}
@@ -462,7 +459,7 @@
 			/* Disconnected */
 			DPRINTF(("uhub_explore: device addr=%d disappeared "
 				 "on port %d\n", up->device->address, port));
-			usb_disconnect_port(up, USBDEV(sc->sc_dev));
+			usb_disconnect_port(up, sc->sc_dev);
 			usbd_clear_port_feature(dev, port,
 						UHF_C_PORT_CONNECTION);
 		}
@@ -476,16 +473,16 @@
 		/* Connected */
 
 		if (!(status & UPS_PORT_POWER))
-			printf("%s: strange, connected port %d has no power\n",
-			       USBDEVNAME(sc->sc_dev), port);
+			device_printf(sc->sc_dev,
+			    "strange, connected port %d has no power\n", port);
 
 		/* Wait for maximum device power up time. */
 		usbd_delay_ms(dev, USB_PORT_POWERUP_DELAY);
 
 		/* Reset port, which implies enabling it. */
 		if (usbd_reset_port(dev, port, &up->status)) {
-			printf("%s: port %d reset failed\n",
-			       USBDEVNAME(sc->sc_dev), port);
+			device_printf(sc->sc_dev, "port %d reset failed\n",
+			    port);
 			continue;
 		}
 		/* Get port status again, it might have changed during reset */
@@ -500,17 +497,17 @@
 		if (!(status & UPS_CURRENT_CONNECT_STATUS)) {
 			/* Nothing connected, just ignore it. */
 #ifdef DIAGNOSTIC
-			printf("%s: port %d, device disappeared after reset\n",
-			       USBDEVNAME(sc->sc_dev), port);
+			device_printf(sc->sc_dev,
+			    "port %d, device disappeared after reset\n", port);
 #endif
 			continue;
 		}
 
 #if 0
 		if (UHUB_IS_HIGH_SPEED(sc) && !(status & UPS_HIGH_SPEED)) {
-			printf("%s: port %d, transaction translation not "
-			    "implemented, low/full speed device ignored\n",
-			    USBDEVNAME(sc->sc_dev), port);
+			device_printf(sc->sc_dev,
+			    "port %d, transaction translation not implemented,"
+			    " low/full speed device ignored\n", port);
 			continue;
 		}
 #endif
@@ -523,7 +520,7 @@
 		else
 			speed = USB_SPEED_FULL;
 		/* Get device info and set its address. */
-		err = usbd_new_device(USBDEV(sc->sc_dev), dev->bus,
+		err = usbd_new_device(sc->sc_dev, dev->bus,
 		    dev->depth + 1, speed, port, up);
 		/* XXX retry a few times? */
 		if (err) {
@@ -537,8 +534,9 @@
 			 * some other serious problem.  Since we cannot leave
 			 * at 0 we have to disable the port instead.
 			 */
-			printf("%s: device problem (%s), disabling port %d\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(err), port);
+			device_printf(sc->sc_dev,
+			    "device problem (%s), disabling port %d\n",
+			    usbd_errstr(err), port);
 			usbd_clear_port_feature(dev, port, UHF_PORT_ENABLE);
 		} else {
 			/* The port set up succeeded, reset error count. */
@@ -551,53 +549,19 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-uhub_activate(device_ptr_t self, enum devact act)
-{
-	struct uhub_softc *sc = (struct uhub_softc *)self;
-	struct usbd_hub *hub = sc->sc_hub->hub;
-	usbd_device_handle dev;
-	int nports, port, i;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		if (hub == NULL) /* malfunctioning hub */
-			break;
-		nports = hub->hubdesc.bNbrPorts;
-		for(port = 0; port < nports; port++) {
-			dev = hub->ports[port].device;
-			if (dev != NULL && dev->subdevs != NULL) {
-				for (i = 0; dev->subdevs[i] != NULL; i++)
-					config_deactivate(dev->subdevs[i]);
-			}
-		}
-		break;
-	}
-	return (0);
-}
-#endif
-
 /*
  * Called from process context when the hub is gone.
  * Detach all devices on active ports.
  */
-USB_DETACH(uhub)
+static int
+uhub_detach(device_t self)
 {
-	USB_DETACH_START(uhub, sc);
+	struct uhub_softc *sc = device_get_softc(self);
 	struct usbd_hub *hub = sc->sc_hub->hub;
 	struct usbd_port *rup;
 	int port, nports;
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	DPRINTF(("uhub_detach: sc=%p flags=%d\n", sc, flags));
-#elif defined(__FreeBSD__)
 	DPRINTF(("uhub_detach: sc=%port\n", sc));
-#endif
-
 	if (hub == NULL)		/* Must be partially working */
 		return (0);
 
@@ -611,8 +575,7 @@
 			usb_disconnect_port(rup, self);
 	}
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_hub,
-			   USBDEV(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_hub, sc->sc_dev);
 
 	if (hub->ports[0].tt)
 		free(hub->ports[0].tt, M_USBDEV);
@@ -622,7 +585,6 @@
 	return (0);
 }
 
-#if defined(__FreeBSD__)
 int
 uhub_child_location_str(device_t cbdev, device_t child, char *buf,
     size_t buflen)
@@ -693,7 +655,8 @@
 
 found_dev:
 	/* XXX can sleep */
-	(void)usbd_get_string(dev, dev->ddesc.iSerialNumber, &serial[0]);
+	(void)usbd_get_string(dev, dev->ddesc.iSerialNumber, serial,
+	    sizeof(serial));
 	if (dev->ifacenums == NULL) {
 		snprintf(buf, buflen, "vendor=0x%04x product=0x%04x "
 		    "devclass=0x%02x devsubclass=0x%02x "
@@ -716,8 +679,6 @@
 	mtx_unlock(&Giant);
 	return (0);
 }
-#endif
-
 
 /*
  * Hub interrupt.
@@ -737,7 +698,6 @@
 		usb_needs_explore(sc->sc_hub);
 }
 
-#if defined(__FreeBSD__)
+MODULE_DEPEND(uhub, usb, 1, 1, 1);
 DRIVER_MODULE(uhub, usb, uhubroot_driver, uhubroot_devclass, 0, 0);
 DRIVER_MODULE(uhub, uhub, uhub_driver, uhub_devclass, usbd_driver_load, 0);
-#endif
Index: rio500_usb.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/rio500_usb.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/rio500_usb.h -L sys/dev/usb/rio500_usb.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/rio500_usb.h
+++ sys/dev/usb/rio500_usb.h
@@ -20,9 +20,8 @@
 
     ---------------------------------------------------------------------- */
 
-/*  $FreeBSD: src/sys/dev/usb/rio500_usb.h,v 1.2 2005/01/06 01:43:28 imp Exp $ */
+/*  $FreeBSD: src/sys/dev/usb/rio500_usb.h,v 1.3 2007/06/12 19:01:32 imp Exp $ */
 
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
 #include <sys/ioccom.h>
 #ifndef USB_VENDOR_DIAMOND
 #define USB_VENDOR_DIAMOND 0x841
@@ -30,15 +29,10 @@
 #ifndef USB_PRODUCT_DIAMOND_RIO500USB
 #define USB_PRODUCT_DIAMOND_RIO500USB 0x1
 #endif
-#endif
 
 struct RioCommand
 {
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
   u_int16_t  length;
-#else
-  short length;
-#endif
   int   request;
   int   requesttype;
   int   value;
@@ -47,13 +41,8 @@
   int  timeout;
 };
 
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
 #define RIO_SEND_COMMAND	_IOWR('U', 200, struct RioCommand)
 #define RIO_RECV_COMMAND	_IOWR('U', 201, struct RioCommand)
-#else
-#define RIO_SEND_COMMAND			0x1
-#define RIO_RECV_COMMAND			0x2
-#endif
 
 #define RIO_DIR_OUT               	        0x0
 #define RIO_DIR_IN				0x1
Index: if_kuereg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_kuereg.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_kuereg.h -L sys/dev/usb/if_kuereg.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_kuereg.h
+++ sys/dev/usb/if_kuereg.h
@@ -29,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/if_kuereg.h,v 1.18 2005/06/10 16:49:15 brooks Exp $
+ * $FreeBSD: src/sys/dev/usb/if_kuereg.h,v 1.20 2007/06/11 05:50:47 imp Exp $
  */
 
 /*
@@ -142,14 +142,11 @@
 	struct kue_ether_desc	kue_desc;
 	int			kue_ed[KUE_ENDPT_MAX];
 	usbd_pipe_handle	kue_ep[KUE_ENDPT_MAX];
-	int			kue_unit;
 	int			kue_if_flags;
 	u_int16_t		kue_rxfilt;
 	u_int8_t		*kue_mcfilters;
 	struct ue_cdata		kue_cdata;
-#if __FreeBSD_version >= 500000
 	struct mtx		kue_mtx;
-#endif
 	char			kue_dying;
 	struct timeval		kue_rx_notice;
 	struct usb_qdat		kue_qdat;
Index: usb_mem.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_mem.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usb_mem.h -L sys/dev/usb/usb_mem.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usb_mem.h
+++ sys/dev/usb/usb_mem.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: usb_mem.h,v 1.18 2002/05/28 17:45:17 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.21 2005/01/06 01:43:29 imp Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.22 2007/06/13 05:45:48 imp Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -41,11 +41,7 @@
 typedef struct usb_dma_block {
 	bus_dma_tag_t tag;
 	bus_dmamap_t map;
-#ifdef __FreeBSD__
 	void *kaddr;
-#else
-        caddr_t kaddr;
-#endif
         bus_dma_segment_t segs[1];
         int nsegs;
         size_t size;
@@ -54,11 +50,7 @@
 	LIST_ENTRY(usb_dma_block) next;
 } usb_dma_block_t;
 
-#ifdef __FreeBSD__
 #define DMAADDR(dma, o) ((dma)->block->segs[0].ds_addr + (dma)->offs + (o))
-#else
-#define DMAADDR(dma, o) (((char *)(dma)->block->map->dm_segs[0].ds_addr) + (dma)->offs + (o))
-#endif
 #define KERNADDR(dma, o) \
 	((void *)((char *)((dma)->block->kaddr) + (dma)->offs + (o)))
 
Index: if_udav.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_udav.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/usb/if_udav.c -L sys/dev/usb/if_udav.c -u -r1.2 -r1.3
--- sys/dev/usb/if_udav.c
+++ sys/dev/usb/if_udav.c
@@ -1,6 +1,6 @@
 /*	$NetBSD: if_udav.c,v 1.2 2003/09/04 15:17:38 tsutsui Exp $	*/
 /*	$nabe: if_udav.c,v 1.3 2003/08/21 16:57:19 nabe Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/if_udav.c,v 1.14.2.4 2006/03/17 21:30:56 glebius Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/if_udav.c,v 1.33 2007/07/24 14:44:23 imp Exp $	*/
 /*-
  * Copyright (c) 2003
  *     Shingo WATANABE <nabe at nabechan.org>.  All rights reserved.
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/if_udav.c,v 1.14.2.4 2006/03/17 21:30:56 glebius Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/if_udav.c,v 1.33 2007/07/24 14:44:23 imp Exp $");
 
 #include "opt_inet.h"
 #if defined(__NetBSD__)
@@ -78,7 +78,7 @@
 #include <sys/device.h>
 #endif
 
-#if NRND > 0
+#if defined(NRND) && NRND > 0
 #include <sys/rnd.h>
 #endif
 
@@ -122,13 +122,11 @@
 
 #include <sys/bus.h>
 #include <machine/bus.h>
-#if __FreeBSD_version < 500000
-#include <machine/clock.h>
-#endif
 
 #include <dev/mii/mii.h>
 #include <dev/mii/miivar.h>
 
+#include <dev/usb/usb_port.h>
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
@@ -144,7 +142,7 @@
 MODULE_DEPEND(udav, miibus, 1, 1, 1);
 #endif
 
-/* "controller miibus0" required.  See GENERIC if you get errors here. */
+/* "device miibus" required.  See GENERIC if you get errors here. */
 #include "miibus_if.h"
 
 #if !defined(__FreeBSD__)
@@ -153,54 +151,57 @@
 #endif
 
 #if defined(__FreeBSD__)
-Static int udav_match(device_ptr_t);
-Static int udav_attach(device_ptr_t);
-Static int udav_detach(device_ptr_t);
-Static void udav_shutdown(device_ptr_t);
-#endif
-
-Static int udav_openpipes(struct udav_softc *);
-Static void udav_start(struct ifnet *);
-Static int udav_send(struct udav_softc *, struct mbuf *, int);
-Static void udav_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-#if defined(__FreeBSD__)
-Static void udav_rxstart(struct ifnet *ifp);
-#endif
-Static void udav_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void udav_tick(void *);
-Static void udav_tick_task(void *);
-Static int udav_ioctl(struct ifnet *, u_long, caddr_t);
-Static void udav_stop_task(struct udav_softc *);
-Static void udav_stop(struct ifnet *, int);
-Static void udav_watchdog(struct ifnet *);
-Static int udav_ifmedia_change(struct ifnet *);
-Static void udav_ifmedia_status(struct ifnet *, struct ifmediareq *);
-Static void udav_lock_mii(struct udav_softc *);
-Static void udav_unlock_mii(struct udav_softc *);
-Static int udav_miibus_readreg(device_ptr_t, int, int);
-Static void udav_miibus_writereg(device_ptr_t, int, int, int);
-Static void udav_miibus_statchg(device_ptr_t);
-#if defined(__NetBSD__)
-Static int udav_init(struct ifnet *);
-#elif defined(__FreeBSD__)
-Static void udav_init(void *);
-#endif
-Static void udav_setmulti(struct udav_softc *);
-Static void udav_reset(struct udav_softc *);
-
-Static int udav_csr_read(struct udav_softc *, int, void *, int);
-Static int udav_csr_write(struct udav_softc *, int, void *, int);
-Static int udav_csr_read1(struct udav_softc *, int);
-Static int udav_csr_write1(struct udav_softc *, int, unsigned char);
+static device_probe_t udav_match;
+static device_attach_t udav_attach;
+static device_detach_t udav_detach;
+static device_shutdown_t udav_shutdown;
+static miibus_readreg_t udav_miibus_readreg;
+static miibus_writereg_t udav_miibus_writereg;
+static miibus_statchg_t udav_miibus_statchg;
+#endif
+
+static int udav_openpipes(struct udav_softc *);
+static void udav_start(struct ifnet *);
+static int udav_send(struct udav_softc *, struct mbuf *, int);
+static void udav_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+#if defined(__FreeBSD__)
+static void udav_rxstart(struct ifnet *ifp);
+#endif
+static void udav_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void udav_tick(void *);
+static void udav_tick_task(void *);
+static int udav_ioctl(struct ifnet *, u_long, caddr_t);
+static void udav_stop_task(struct udav_softc *);
+static void udav_stop(struct ifnet *, int);
+static void udav_watchdog(struct ifnet *);
+static int udav_ifmedia_change(struct ifnet *);
+static void udav_ifmedia_status(struct ifnet *, struct ifmediareq *);
+static void udav_lock_mii(struct udav_softc *);
+static void udav_unlock_mii(struct udav_softc *);
+#if defined(__NetBSD__)
+static int udav_miibus_readreg(device_t, int, int);
+static void udav_miibus_writereg(device_t, int, int, int);
+static void udav_miibus_statchg(device_t);
+static int udav_init(struct ifnet *);
+#elif defined(__FreeBSD__)
+static void udav_init(void *);
+#endif
+static void udav_setmulti(struct udav_softc *);
+static void udav_reset(struct udav_softc *);
+
+static int udav_csr_read(struct udav_softc *, int, void *, int);
+static int udav_csr_write(struct udav_softc *, int, void *, int);
+static int udav_csr_read1(struct udav_softc *, int);
+static int udav_csr_write1(struct udav_softc *, int, unsigned char);
 
 #if 0
-Static int udav_mem_read(struct udav_softc *, int, void *, int);
-Static int udav_mem_write(struct udav_softc *, int, void *, int);
-Static int udav_mem_write1(struct udav_softc *, int, unsigned char);
+static int udav_mem_read(struct udav_softc *, int, void *, int);
+static int udav_mem_write(struct udav_softc *, int, void *, int);
+static int udav_mem_write1(struct udav_softc *, int, unsigned char);
 #endif
 
 #if defined(__FreeBSD__)
-Static device_method_t udav_methods[] = {
+static device_method_t udav_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		udav_match),
 	DEVMETHOD(device_attach,	udav_attach),
@@ -219,13 +220,13 @@
 	{ 0, 0 }
 };
 
-Static driver_t udav_driver = {
+static driver_t udav_driver = {
 	"udav",
 	udav_methods,
 	sizeof(struct udav_softc)
 };
 
-Static devclass_t udav_devclass;
+static devclass_t udav_devclass;
 
 DRIVER_MODULE(udav, uhub, udav_driver, udav_devclass, usbd_driver_load, 0);
 DRIVER_MODULE(miibus, udav, miibus_driver, miibus_devclass, 0, 0);
@@ -234,8 +235,8 @@
 
 /* Macros */
 #ifdef UDAV_DEBUG
-#define DPRINTF(x)	if (udavdebug) logprintf x
-#define DPRINTFN(n,x)	if (udavdebug >= (n)) logprintf x
+#define DPRINTF(x)	if (udavdebug) printf x
+#define DPRINTFN(n,x)	if (udavdebug >= (n)) printf x
 int udavdebug = 0;
 #else
 #define DPRINTF(x)
@@ -257,6 +258,8 @@
 } udav_devs [] = {
 	/* Corega USB-TXC */
 	{{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXC }, 0},
+	/* ShanTou ST268 USB NIC */
+	{{ USB_VENDOR_SHANTOU, USB_PRODUCT_SHANTOU_ST268 }, 0},
 #if 0
 	/* DAVICOM DM9601 Generic? */
 	/*  XXX: The following ids was obtained from the data sheet. */
@@ -267,9 +270,10 @@
 
 
 /* Probe */
-USB_MATCH(udav)
+static int
+udav_match(device_t self)
 {
-	USB_MATCH_START(udav, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 
 	if (uaa->iface != NULL)
 		return (UMATCH_NONE);
@@ -279,7 +283,8 @@
 }
 
 /* Attach */
-USB_ATTACH(udav)
+static int
+udav_attach(device_t self)
 {
 	USB_ATTACH_START(udav, sc, uaa);
 	usbd_device_handle dev = uaa->device;
@@ -287,7 +292,6 @@
 	usbd_status err;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char devinfo[1024];
 	const char *devname ;
 	struct ifnet *ifp;
 #if defined(__NetBSD__)
@@ -299,13 +303,8 @@
 	int s;
 #endif
 
-	bzero(sc, sizeof(struct udav_softc));
-
-	usbd_devinfo(dev, 0, devinfo);
-	USB_ATTACH_SETUP;
-        devname = USBDEVNAME(sc->sc_dev);
-	printf("%s: %s\n", devname, devinfo);
-
+	sc->sc_dev = self;
+	devname = device_get_nameunit(self);
 	/* Move the device into the configured state. */
 	err = usbd_set_config_no(dev, UDAV_CONFIG_NO, 1);
 	if (err) {
@@ -357,7 +356,7 @@
 		goto bad;
 	}
 
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
+#if defined(__FreeBSD__)
 	mtx_init(&sc->sc_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
 	    MTX_DEF | MTX_RECURSE);
 #endif
@@ -447,11 +446,11 @@
 #elif defined(__FreeBSD__)
 	if (mii_phy_probe(self, &sc->sc_miibus,
 	    udav_ifmedia_change, udav_ifmedia_status)) {
-		printf("%s: MII without any PHY!\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: MII without any PHY!\n", device_get_nameunit(sc->sc_dev));
 		if_free(ifp);
 		UDAV_UNLOCK(sc);
 		mtx_destroy(&sc->sc_mtx);
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 
 	sc->sc_qdat.ifp = ifp;
@@ -464,7 +463,7 @@
 	ether_ifattach(ifp, eaddr);
 #endif
 
-#if NRND > 0
+#if defined(NRND) && NRND > 0
 	rnd_attach_source(&sc->rnd_source, devname, RND_TYPE_NET, 0);
 #endif
 
@@ -479,17 +478,18 @@
         UDAV_UNLOCK(sc);
 #endif
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, USBDEV(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, sc->sc_dev);
 
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
  bad:
 	sc->sc_dying = 1;
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
 /* detach */
-USB_DETACH(udav)
+static int
+udav_detach(device_t self)
 {
 	USB_DETACH_START(udav, sc);
 	struct ifnet *ifp = GET_IFP(sc);
@@ -497,7 +497,7 @@
 	int s;
 #endif
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	/* Detached before attached finished */
 	if (!sc->sc_attached)
@@ -519,7 +519,7 @@
 
 	if (--sc->sc_refcnt >= 0) {
 		/* Wait for processes to go away */
-		usb_detach_wait(USBDEV(sc->sc_dev));
+		usb_detach_wait(sc->sc_dev);
 	}
 #if defined(__FreeBSD__)
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
@@ -528,7 +528,7 @@
 #endif
 		udav_stop(GET_IFP(sc), 1);
 
-#if NRND > 0
+#if defined(NRND) && NRND > 0
 	rnd_detach_source(&sc->rnd_source);
 #endif
 #if defined(__NetBSD__)
@@ -546,13 +546,13 @@
 #ifdef DIAGNOSTIC
 	if (sc->sc_pipe_tx != NULL)
 		printf("%s: detach has active tx endpoint.\n",
-		       USBDEVNAME(sc->sc_dev));
+		       device_get_nameunit(sc->sc_dev));
 	if (sc->sc_pipe_rx != NULL)
 		printf("%s: detach has active rx endpoint.\n",
-		       USBDEVNAME(sc->sc_dev));
+		       device_get_nameunit(sc->sc_dev));
 	if (sc->sc_pipe_intr != NULL)
 		printf("%s: detach has active intr endpoint.\n",
-		       USBDEVNAME(sc->sc_dev));
+		       device_get_nameunit(sc->sc_dev));
 #endif
 	sc->sc_attached = 0;
 
@@ -566,14 +566,13 @@
 	mtx_destroy(&sc->sc_mtx);
 #endif
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
 	return (0);
 }
 
 #if 0
 /* read memory */
-Static int
+static int
 udav_mem_read(struct udav_softc *sc, int offset, void *buf, int len)
 {
 	usb_device_request_t req;
@@ -583,7 +582,7 @@
 		return (0);
 
 	DPRINTFN(0x200,
-		("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+		("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -600,17 +599,17 @@
 	sc->sc_refcnt++;
 	err = usbd_do_request(sc->sc_udev, &req, buf);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	if (err) {
 		DPRINTF(("%s: %s: read failed. off=%04x, err=%d\n",
-			 USBDEVNAME(sc->sc_dev), __func__, offset, err));
+			 device_get_nameunit(sc->sc_dev), __func__, offset, err));
 	}
 
 	return (err);
 }
 
 /* write memory */
-Static int
+static int
 udav_mem_write(struct udav_softc *sc, int offset, void *buf, int len)
 {
 	usb_device_request_t req;
@@ -620,7 +619,7 @@
 		return (0);
 
 	DPRINTFN(0x200,
-		("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+		("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -637,17 +636,17 @@
 	sc->sc_refcnt++;
 	err = usbd_do_request(sc->sc_udev, &req, buf);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	if (err) {
 		DPRINTF(("%s: %s: write failed. off=%04x, err=%d\n",
-			 USBDEVNAME(sc->sc_dev), __func__, offset, err));
+			 device_get_nameunit(sc->sc_dev), __func__, offset, err));
 	}
 
 	return (err);
 }
 
 /* write memory */
-Static int
+static int
 udav_mem_write1(struct udav_softc *sc, int offset, unsigned char ch)
 {
 	usb_device_request_t req;
@@ -657,7 +656,7 @@
 		return (0);
 
 	DPRINTFN(0x200,
-		("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+		("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -673,10 +672,10 @@
 	sc->sc_refcnt++;
 	err = usbd_do_request(sc->sc_udev, &req, NULL);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	if (err) {
 		DPRINTF(("%s: %s: write failed. off=%04x, err=%d\n",
-			 USBDEVNAME(sc->sc_dev), __func__, offset, err));
+			 device_get_nameunit(sc->sc_dev), __func__, offset, err));
 	}
 
 	return (err);
@@ -684,7 +683,7 @@
 #endif
 
 /* read register(s) */
-Static int
+static int
 udav_csr_read(struct udav_softc *sc, int offset, void *buf, int len)
 {
 	usb_device_request_t req;
@@ -694,7 +693,7 @@
 		return (0);
 
 	DPRINTFN(0x200,
-		("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+		("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -711,17 +710,17 @@
 	sc->sc_refcnt++;
 	err = usbd_do_request(sc->sc_udev, &req, buf);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	if (err) {
 		DPRINTF(("%s: %s: read failed. off=%04x, err=%d\n",
-			 USBDEVNAME(sc->sc_dev), __func__, offset, err));
+			 device_get_nameunit(sc->sc_dev), __func__, offset, err));
 	}
 
 	return (err);
 }
 
 /* write register(s) */
-Static int
+static int
 udav_csr_write(struct udav_softc *sc, int offset, void *buf, int len)
 {
 	usb_device_request_t req;
@@ -731,7 +730,7 @@
 		return (0);
 
 	DPRINTFN(0x200,
-		("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+		("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -748,16 +747,16 @@
 	sc->sc_refcnt++;
 	err = usbd_do_request(sc->sc_udev, &req, buf);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	if (err) {
 		DPRINTF(("%s: %s: write failed. off=%04x, err=%d\n",
-			 USBDEVNAME(sc->sc_dev), __func__, offset, err));
+			 device_get_nameunit(sc->sc_dev), __func__, offset, err));
 	}
 
 	return (err);
 }
 
-Static int
+static int
 udav_csr_read1(struct udav_softc *sc, int offset)
 {
 	u_int8_t val = 0;
@@ -766,7 +765,7 @@
 		return (0);
 
 	DPRINTFN(0x200,
-		("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+		("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -775,7 +774,7 @@
 }
 
 /* write a register */
-Static int
+static int
 udav_csr_write1(struct udav_softc *sc, int offset, unsigned char ch)
 {
 	usb_device_request_t req;
@@ -785,7 +784,7 @@
 		return (0);
 
 	DPRINTFN(0x200,
-		("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+		("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -801,20 +800,20 @@
 	sc->sc_refcnt++;
 	err = usbd_do_request(sc->sc_udev, &req, NULL);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	if (err) {
 		DPRINTF(("%s: %s: write failed. off=%04x, err=%d\n",
-			 USBDEVNAME(sc->sc_dev), __func__, offset, err));
+			 device_get_nameunit(sc->sc_dev), __func__, offset, err));
 	}
 
 	return (err);
 }
 
 #if defined(__NetBSD__)
-Static int
+static int
 udav_init(struct ifnet *ifp)
 #elif defined(__FreeBSD__)
-Static void
+static void
 udav_init(void *xsc)
 #endif
 {
@@ -830,7 +829,7 @@
 	int s;
 #endif
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 #if defined(__NetBSD__)
@@ -851,7 +850,7 @@
 #if defined(__NetBSD__)
 	eaddr = LLADDR(ifp->if_sadl);
 #elif defined(__FreeBSD__)
-	eaddr = IFP2ENADDR(ifp);
+	eaddr = IF_LLADDR(ifp);
 #endif
 	udav_csr_write(sc, UDAV_PAR, eaddr, ETHER_ADDR_LEN);
 
@@ -871,7 +870,7 @@
 	/* Initialize transmit ring */
 	if (usb_ether_tx_list_init(sc, &sc->sc_cdata,
 	    sc->sc_udev) == ENOBUFS) {
-		printf("%s: tx list init failed\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: tx list init failed\n", device_get_nameunit(sc->sc_dev));
 #if defined(__NetBSD__)
 		splx(s);
 		return (EIO);
@@ -885,7 +884,7 @@
 	/* Initialize receive ring */
 	if (usb_ether_rx_list_init(sc, &sc->sc_cdata,
 	    sc->sc_udev) == ENOBUFS) {
-		printf("%s: rx list init failed\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: rx list init failed\n", device_get_nameunit(sc->sc_dev));
 #if defined(__NetBSD__)
 		splx(s);
 		return (EIO);
@@ -942,12 +941,12 @@
 #endif
 }
 
-Static void
+static void
 udav_reset(struct udav_softc *sc)
 {
 	int i;
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return;
@@ -979,11 +978,11 @@
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 int
-udav_activate(device_ptr_t self, enum devact act)
+udav_activate(device_t self, enum devact act)
 {
 	struct udav_softc *sc = (struct udav_softc *)self;
 
-	DPRINTF(("%s: %s: enter, act=%d\n", USBDEVNAME(sc->sc_dev),
+	DPRINTF(("%s: %s: enter, act=%d\n", device_get_nameunit(sc->sc_dev),
 		 __func__, act));
 	switch (act) {
 	case DVACT_ACTIVATE:
@@ -1004,7 +1003,7 @@
 #define UDAV_CALCHASH(addr) \
 	(ether_crc32_le((addr), ETHER_ADDR_LEN) & ((1 << UDAV_BITS) - 1))
 
-Static void
+static void
 udav_setmulti(struct udav_softc *sc)
 {
 	struct ifnet *ifp;
@@ -1017,7 +1016,7 @@
 	u_int8_t hashes[8];
 	int h = 0;
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return;
@@ -1056,11 +1055,7 @@
 	}
 #elif defined(__FreeBSD__)
 	IF_ADDR_LOCK(ifp);
-#if __FreeBSD_version >= 500000
 	TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#else
-	LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#endif
 	{
 		if (ifma->ifma_addr->sa_family != AF_LINK)
 			continue;
@@ -1079,7 +1074,7 @@
 	udav_csr_write(sc, UDAV_MAR, hashes, sizeof(hashes));
 }
 
-Static int
+static int
 udav_openpipes(struct udav_softc *sc)
 {
 	struct ue_chain *c;
@@ -1097,7 +1092,7 @@
 			     USBD_EXCLUSIVE_USE, &sc->sc_pipe_rx);
 	if (err) {
 		printf("%s: open rx pipe failed: %s\n",
-		       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		error = EIO;
 		goto done;
 	}
@@ -1107,7 +1102,7 @@
 			     USBD_EXCLUSIVE_USE, &sc->sc_pipe_tx);
 	if (err) {
 		printf("%s: open tx pipe failed: %s\n",
-		       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		error = EIO;
 		goto done;
 	}
@@ -1121,7 +1116,7 @@
 				  udav_intr, UDAV_INTR_INTERVAL);
 	if (err) {
 		printf("%s: open intr pipe failed: %s\n",
-		       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+		       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		error = EIO;
 		goto done;
 	}
@@ -1136,24 +1131,24 @@
 				USBD_SHORT_XFER_OK | USBD_NO_COPY,
 				USBD_NO_TIMEOUT, udav_rxeof);
 		(void)usbd_transfer(c->ue_xfer);
-		DPRINTF(("%s: %s: start read\n", USBDEVNAME(sc->sc_dev),
+		DPRINTF(("%s: %s: start read\n", device_get_nameunit(sc->sc_dev),
 			 __func__));
 	}
 
  done:
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 
 	return (error);
 }
 
-Static void
+static void
 udav_start(struct ifnet *ifp)
 {
 	struct udav_softc *sc = ifp->if_softc;
 	struct mbuf *m_head = NULL;
 
-	DPRINTF(("%s: %s: enter, link=%d\n", USBDEVNAME(sc->sc_dev),
+	DPRINTF(("%s: %s: enter, link=%d\n", device_get_nameunit(sc->sc_dev),
 		 __func__, sc->sc_link));
 
 	if (sc->sc_dying)
@@ -1204,14 +1199,14 @@
 	ifp->if_timer = 5;
 }
 
-Static int
+static int
 udav_send(struct udav_softc *sc, struct mbuf *m, int idx)
 {
 	int total_len;
 	struct ue_chain *c;
 	usbd_status err;
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev),__func__));
 
 	c = &sc->sc_cdata.ue_tx_chain[idx];
 
@@ -1239,16 +1234,16 @@
 	sc->sc_refcnt++;
 	err = usbd_transfer(c->ue_xfer);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	if (err != USBD_IN_PROGRESS) {
-		printf("%s: udav_send error=%s\n", USBDEVNAME(sc->sc_dev),
+		printf("%s: udav_send error=%s\n", device_get_nameunit(sc->sc_dev),
 		       usbd_errstr(err));
 		/* Stop the interface */
-		usb_add_task(sc->sc_udev, &sc->sc_stop_task);
+		usb_add_task(sc->sc_udev, &sc->sc_stop_task, USB_TASKQ_DRIVER);
 		return (EIO);
 	}
 
-	DPRINTF(("%s: %s: send %d bytes\n", USBDEVNAME(sc->sc_dev),
+	DPRINTF(("%s: %s: send %d bytes\n", device_get_nameunit(sc->sc_dev),
 		 __func__, total_len));
 
 	sc->sc_cdata.ue_tx_cnt++;
@@ -1256,7 +1251,7 @@
 	return (0);
 }
 
-Static void
+static void
 udav_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct ue_chain *c = priv;
@@ -1275,7 +1270,7 @@
         UDAV_LOCK(sc);
 #endif
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	ifp->if_timer = 0;
 #if defined(__FreeBSD__)
@@ -1294,13 +1289,13 @@
 			return;
 		}
 		ifp->if_oerrors++;
-		printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->sc_dev),
+		printf("%s: usb error on tx: %s\n", device_get_nameunit(sc->sc_dev),
 		       usbd_errstr(status));
 		if (status == USBD_STALLED) {
 			sc->sc_refcnt++;
 			usbd_clear_endpoint_stall(sc->sc_pipe_tx);
 			if (--sc->sc_refcnt < 0)
-				usb_detach_wakeup(USBDEV(sc->sc_dev));
+				usb_detach_wakeup(sc->sc_dev);
 		}
 #if defined(__NetBSD__)
 		splx(s);
@@ -1329,7 +1324,7 @@
 #endif
 }
 
-Static void
+static void
 udav_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct ue_chain *c = priv;
@@ -1342,7 +1337,7 @@
 	int s;
 #endif
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev),__func__));
 
 	if (sc->sc_dying)
 		return;
@@ -1353,7 +1348,7 @@
 		sc->sc_rx_errs++;
 		if (usbd_ratecheck(&sc->sc_rx_notice)) {
 			printf("%s: %u usb errors on rx: %s\n",
-			       USBDEVNAME(sc->sc_dev), sc->sc_rx_errs,
+			       device_get_nameunit(sc->sc_dev), sc->sc_rx_errs,
 			       usbd_errstr(status));
 			sc->sc_rx_errs = 0;
 		}
@@ -1361,7 +1356,7 @@
 			sc->sc_refcnt++;
 			usbd_clear_endpoint_stall(sc->sc_pipe_rx);
 			if (--sc->sc_refcnt < 0)
-				usb_detach_wakeup(USBDEV(sc->sc_dev));
+				usb_detach_wakeup(sc->sc_dev);
 		}
 		goto done;
 	}
@@ -1375,7 +1370,7 @@
 	/* first byte in received data */
 	pktstat = mtod(m, u_int8_t *);
 	m_adj(m, sizeof(u_int8_t));
-	DPRINTF(("%s: RX Status: 0x%02x\n", USBDEVNAME(sc->sc_dev), *pktstat));
+	DPRINTF(("%s: RX Status: 0x%02x\n", device_get_nameunit(sc->sc_dev), *pktstat));
 
 	total_len = UGETW(mtod(m, u_int8_t *));
 	m_adj(m, sizeof(u_int16_t));
@@ -1411,7 +1406,7 @@
 	c->ue_mbuf = usb_ether_newbuf();
 	if (c->ue_mbuf == NULL) {
 		printf("%s: no memory for rx list "
-		    "-- packet dropped!\n", USBDEVNAME(sc->sc_dev));
+		    "-- packet dropped!\n", device_get_nameunit(sc->sc_dev));
 		ifp->if_ierrors++;
 		goto done1;
 	}
@@ -1421,7 +1416,7 @@
 	BPF_MTAP(ifp, m);
 #endif
 
-	DPRINTF(("%s: %s: deliver %d\n", USBDEVNAME(sc->sc_dev),
+	DPRINTF(("%s: %s: deliver %d\n", device_get_nameunit(sc->sc_dev),
 		 __func__, m->m_len));
 #if defined(__NetBSD__)
 	IF_INPUT(ifp, m);
@@ -1446,18 +1441,18 @@
 	sc->sc_refcnt++;
 	usbd_transfer(xfer);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 
-	DPRINTF(("%s: %s: start rx\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: start rx\n", device_get_nameunit(sc->sc_dev), __func__));
 }
 
 #if 0
-Static void udav_intr()
+static void udav_intr()
 {
 }
 #endif
 
-Static int
+static int
 udav_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 {
 	struct udav_softc *sc = ifp->if_softc;
@@ -1468,7 +1463,7 @@
 #endif
 	int error = 0;
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (EIO);
@@ -1535,7 +1530,7 @@
 	return (error);
 }
 
-Static void
+static void
 udav_watchdog(struct ifnet *ifp)
 {
 	struct udav_softc *sc = ifp->if_softc;
@@ -1545,10 +1540,10 @@
 	int s;
 #endif
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	ifp->if_oerrors++;
-	printf("%s: watchdog timeout\n", USBDEVNAME(sc->sc_dev));
+	printf("%s: watchdog timeout\n", device_get_nameunit(sc->sc_dev));
 
 #if defined(__NetBSD__)
 	s = splusb();
@@ -1572,20 +1567,20 @@
 #endif
 }
 
-Static void
+static void
 udav_stop_task(struct udav_softc *sc)
 {
 	udav_stop(GET_IFP(sc), 1);
 }
 
 /* Stop the adapter and free any mbufs allocated to the RX and TX lists. */
-Static void
+static void
 udav_stop(struct ifnet *ifp, int disable)
 {
 	struct udav_softc *sc = ifp->if_softc;
 	usbd_status err;
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	ifp->if_timer = 0;
 
@@ -1599,11 +1594,11 @@
 		err = usbd_abort_pipe(sc->sc_pipe_rx);
 		if (err)
 			printf("%s: abort rx pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_pipe_rx);
 		if (err)
 			printf("%s: close rx pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		sc->sc_pipe_rx = NULL;
 	}
 
@@ -1612,11 +1607,11 @@
 		err = usbd_abort_pipe(sc->sc_pipe_tx);
 		if (err)
 			printf("%s: abort tx pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_pipe_tx);
 		if (err)
 			printf("%s: close tx pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		sc->sc_pipe_tx = NULL;
 	}
 
@@ -1627,11 +1622,11 @@
 		err = usbd_abort_pipe(sc->sc_pipe_intr);
 		if (err)
 			printf("%s: abort intr pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_pipe_intr);
 		if (err)
 			printf("%s: close intr pipe failed: %s\n",
-			       USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			       device_get_nameunit(sc->sc_dev), usbd_errstr(err));
 		sc->sc_pipe_intr = NULL;
 	}
 #endif
@@ -1650,13 +1645,13 @@
 }
 
 /* Set media options */
-Static int
+static int
 udav_ifmedia_change(struct ifnet *ifp)
 {
 	struct udav_softc *sc = ifp->if_softc;
 	struct mii_data *mii = GET_MII(sc);
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return (0);
@@ -1673,13 +1668,13 @@
 }
 
 /* Report current media status. */
-Static void
+static void
 udav_ifmedia_status(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
 	struct udav_softc *sc = ifp->if_softc;
 	struct mii_data *mii = GET_MII(sc);
 
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 
 	if (sc->sc_dying)
 		return;
@@ -1699,7 +1694,7 @@
 	ifmr->ifm_status = mii->mii_media_status;
 }
 
-Static void
+static void
 udav_tick(void *xsc)
 {
 	struct udav_softc *sc = xsc;
@@ -1707,17 +1702,17 @@
 	if (sc == NULL)
 		return;
 
-	DPRINTFN(0xff, ("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),
+	DPRINTFN(0xff, ("%s: %s: enter\n", device_get_nameunit(sc->sc_dev),
 			__func__));
 
 	if (sc->sc_dying)
 		return;
 
 	/* Perform periodic stuff in process context */
-	usb_add_task(sc->sc_udev, &sc->sc_tick_task);
+	usb_add_task(sc->sc_udev, &sc->sc_tick_task, USB_TASKQ_DRIVER);
 }
 
-Static void
+static void
 udav_tick_task(void *xsc)
 {
 	struct udav_softc *sc = xsc;
@@ -1730,7 +1725,7 @@
 	if (sc == NULL)
 		return;
 
-	DPRINTFN(0xff, ("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),
+	DPRINTFN(0xff, ("%s: %s: enter\n", device_get_nameunit(sc->sc_dev),
 			__func__));
 
 	if (sc->sc_dying)
@@ -1754,7 +1749,7 @@
 		if (mii->mii_media_status & IFM_ACTIVE &&
 		    IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
 			DPRINTF(("%s: %s: got link\n",
-				 USBDEVNAME(sc->sc_dev), __func__));
+				 device_get_nameunit(sc->sc_dev), __func__));
 			sc->sc_link++;
 #if defined(__NetBSD__)
 			if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
@@ -1775,10 +1770,10 @@
 }
 
 /* Get exclusive access to the MII registers */
-Static void
+static void
 udav_lock_mii(struct udav_softc *sc)
 {
-	DPRINTFN(0xff, ("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),
+	DPRINTFN(0xff, ("%s: %s: enter\n", device_get_nameunit(sc->sc_dev),
 			__func__));
 
 	sc->sc_refcnt++;
@@ -1789,10 +1784,10 @@
 #endif
 }
 
-Static void
+static void
 udav_unlock_mii(struct udav_softc *sc)
 {
-	DPRINTFN(0xff, ("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),
+	DPRINTFN(0xff, ("%s: %s: enter\n", device_get_nameunit(sc->sc_dev),
 		       __func__));
 
 #if defined(__NetBSD__)
@@ -1801,11 +1796,11 @@
 	lockmgr(&sc->sc_mii_lock, LK_RELEASE, NULL, NULL);
 #endif
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 }
 
-Static int
-udav_miibus_readreg(device_ptr_t dev, int phy, int reg)
+static int
+udav_miibus_readreg(device_t dev, int phy, int reg)
 {
 	struct udav_softc *sc;
 	u_int8_t val[2];
@@ -1817,11 +1812,11 @@
 	sc = USBGETSOFTC(dev);
 
 	DPRINTFN(0xff, ("%s: %s: enter, phy=%d reg=0x%04x\n",
-		 USBDEVNAME(sc->sc_dev), __func__, phy, reg));
+		 device_get_nameunit(sc->sc_dev), __func__, phy, reg));
 
 	if (sc->sc_dying) {
 #ifdef DIAGNOSTIC
-		printf("%s: %s: dying\n", USBDEVNAME(sc->sc_dev),
+		printf("%s: %s: dying\n", device_get_nameunit(sc->sc_dev),
 		       __func__);
 #endif
 		return (0);
@@ -1830,7 +1825,7 @@
 	/* XXX: one PHY only for the internal PHY */
 	if (phy != 0) {
 		DPRINTFN(0xff, ("%s: %s: phy=%d is not supported\n",
-			 USBDEVNAME(sc->sc_dev), __func__, phy));
+			 device_get_nameunit(sc->sc_dev), __func__, phy));
 		return (0);
 	}
 
@@ -1856,38 +1851,38 @@
 	data16 = val[0] | (val[1] << 8);
 
 	DPRINTFN(0xff, ("%s: %s: phy=%d reg=0x%04x => 0x%04x\n",
-		 USBDEVNAME(sc->sc_dev), __func__, phy, reg, data16));
+		 device_get_nameunit(sc->sc_dev), __func__, phy, reg, data16));
 
 	return (data16);
 }
 
-Static void
-udav_miibus_writereg(device_ptr_t dev, int phy, int reg, int data)
+static int
+udav_miibus_writereg(device_t dev, int phy, int reg, int data)
 {
 	struct udav_softc *sc;
 	u_int8_t val[2];
 
 	if (dev == NULL)
-		return;
+		return (0);	/* XXX real error? */
 
 	sc = USBGETSOFTC(dev);
 
 	DPRINTFN(0xff, ("%s: %s: enter, phy=%d reg=0x%04x data=0x%04x\n",
-		 USBDEVNAME(sc->sc_dev), __func__, phy, reg, data));
+		 device_get_nameunit(sc->sc_dev), __func__, phy, reg, data));
 
 	if (sc->sc_dying) {
 #ifdef DIAGNOSTIC
-		printf("%s: %s: dying\n", USBDEVNAME(sc->sc_dev),
+		printf("%s: %s: dying\n", device_get_nameunit(sc->sc_dev),
 		       __func__);
 #endif
-		return;
+		return (0);	/* XXX real error? */
 	}
 
 	/* XXX: one PHY only for the internal PHY */
 	if (phy != 0) {
 		DPRINTFN(0xff, ("%s: %s: phy=%d is not supported\n",
-			 USBDEVNAME(sc->sc_dev), __func__, phy));
-		return;
+			 device_get_nameunit(sc->sc_dev), __func__, phy));
+		return (0);	/* XXX real error? */
 	}
 
 	udav_lock_mii(sc);
@@ -1911,11 +1906,11 @@
 
 	udav_unlock_mii(sc);
 
-	return;
+	return (0);
 }
 
-Static void
-udav_miibus_statchg(device_ptr_t dev)
+static void
+udav_miibus_statchg(device_t dev)
 {
 #ifdef UDAV_DEBUG
 	struct udav_softc *sc;
@@ -1924,7 +1919,7 @@
 		return;
 
 	sc = USBGETSOFTC(dev);
-	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));
+	DPRINTF(("%s: %s: enter\n", device_get_nameunit(sc->sc_dev), __func__));
 #endif
 	/* Nothing to do */
 }
@@ -1934,8 +1929,8 @@
  * Stop all chip I/O so that the kernel's probe routines don't
  * get confused by errant DMAs when rebooting.
  */
-Static void
-udav_shutdown(device_ptr_t dev)
+static int
+udav_shutdown(device_t dev)
 {
 	struct udav_softc	*sc;
 
@@ -1943,10 +1938,10 @@
 
 	udav_stop_task(sc);
 
-	return;
+	return (0);
 }
 
-Static void
+static void
 udav_rxstart(struct ifnet *ifp)
 {
 	struct udav_softc	*sc;
@@ -1959,7 +1954,7 @@
 	c->ue_mbuf = usb_ether_newbuf();
 	if (c->ue_mbuf == NULL) {
 		printf("%s: no memory for rx list "
-		    "-- packet dropped!\n", USBDEVNAME(sc->sc_dev));
+		    "-- packet dropped!\n", device_get_nameunit(sc->sc_dev));
 		ifp->if_ierrors++;
 		UDAV_UNLOCK(sc);
 		return;
Index: usbdi_util.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usbdi_util.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usbdi_util.h -L sys/dev/usb/usbdi_util.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usbdi_util.h
+++ sys/dev/usb/usbdi_util.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: usbdi_util.h,v 1.31 2004/12/03 08:53:40 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/usbdi_util.h,v 1.19 2005/03/01 08:01:22 sobomax Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/usbdi_util.h,v 1.21 2007/01/03 10:50:03 luigi Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,6 +38,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef _USBI_UTIL_H_
+#define _USBI_UTIL_H_
 usbd_status	usbd_get_desc(usbd_device_handle dev, int type,
 			      int index, int len, void *desc);
 usbd_status	usbd_get_config_desc(usbd_device_handle, int,
@@ -67,7 +69,7 @@
 				void *data, int len);
 usbd_status	usbd_set_idle(usbd_interface_handle iface, int duration, int id);
 usbd_status	usbd_read_report_desc(usbd_interface_handle ifc, void **descp,
-				      int *sizep, usb_malloc_type mem);
+				      int *sizep, struct malloc_type *mem);
 usbd_status	usbd_get_config(usbd_device_handle dev, u_int8_t *conf);
 usbd_status	usbd_get_string_desc(usbd_device_handle dev, int sindex,
 				     int langid,usb_string_descriptor_t *sdesc,
@@ -86,10 +88,11 @@
 			       u_int16_t flags, u_int32_t timeout, void *buf,
 			       u_int32_t *size, char *lbl);
 
-void usb_detach_wait(device_ptr_t);
-void usb_detach_wakeup(device_ptr_t);
+void usb_detach_wait(device_t);
+void usb_detach_wakeup(device_t);
 
 const usb_descriptor_t *usb_find_desc(usbd_device_handle dev, int type,
 				      int subtype);
 #define USBD_SUBTYPE_ANY (~0)
 
+#endif	/* _USBI_UTIL_H_ */
Index: ehci.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ehci.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/usb/ehci.c -L sys/dev/usb/ehci.c -u -r1.2 -r1.3
--- sys/dev/usb/ehci.c
+++ sys/dev/usb/ehci.c
@@ -59,16 +59,12 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ehci.c,v 1.36.2.2 2006/03/01 01:59:04 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ehci.c,v 1.56 2007/08/12 18:45:24 truckman Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
 #include <sys/kernel.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#include <sys/select.h>
-#elif defined(__FreeBSD__)
 #include <sys/endian.h>
 #include <sys/module.h>
 #include <sys/bus.h>
@@ -76,7 +72,6 @@
 #if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__)
 #include <machine/cpu.h>
 #endif
-#endif
 #include <sys/proc.h>
 #include <sys/queue.h>
 #include <sys/sysctl.h>
@@ -93,23 +88,17 @@
 #include <dev/usb/ehcireg.h>
 #include <dev/usb/ehcivar.h>
 
-#if defined(__FreeBSD__)
-#include <machine/clock.h>
-
 #define delay(d)                DELAY(d)
-#endif
 
 #ifdef USB_DEBUG
 #define EHCI_DEBUG USB_DEBUG
-#define DPRINTF(x)	do { if (ehcidebug) logprintf x; } while (0)
-#define DPRINTFN(n,x)	do { if (ehcidebug>(n)) logprintf x; } while (0)
+#define DPRINTF(x)	do { if (ehcidebug) printf x; } while (0)
+#define DPRINTFN(n,x)	do { if (ehcidebug>(n)) printf x; } while (0)
 int ehcidebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, ehci, CTLFLAG_RW, 0, "USB ehci");
 SYSCTL_INT(_hw_usb_ehci, OID_AUTO, debug, CTLFLAG_RW,
 	   &ehcidebug, 0, "ehci debug level");
-#ifndef __NetBSD__
 #define bitmask_snprintf(q,f,b,l) snprintf((b), (l), "%b", (q), (f))
-#endif
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n,x)
@@ -117,7 +106,6 @@
 
 struct ehci_pipe {
 	struct usbd_pipe pipe;
-	int nexttoggle;
 
 	ehci_soft_qh_t *sqh;
 	union {
@@ -144,104 +132,105 @@
 	} u;
 };
 
-Static usbd_status	ehci_open(usbd_pipe_handle);
-Static void		ehci_poll(struct usbd_bus *);
-Static void		ehci_softintr(void *);
-Static int		ehci_intr1(ehci_softc_t *);
-Static void		ehci_waitintr(ehci_softc_t *, usbd_xfer_handle);
-Static void		ehci_check_intr(ehci_softc_t *, struct ehci_xfer *);
-Static void		ehci_idone(struct ehci_xfer *);
-Static void		ehci_timeout(void *);
-Static void		ehci_timeout_task(void *);
-Static void		ehci_intrlist_timeout(void *);
-
-Static usbd_status	ehci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t);
-Static void		ehci_freem(struct usbd_bus *, usb_dma_t *);
-
-Static usbd_xfer_handle	ehci_allocx(struct usbd_bus *);
-Static void		ehci_freex(struct usbd_bus *, usbd_xfer_handle);
-
-Static usbd_status	ehci_root_ctrl_transfer(usbd_xfer_handle);
-Static usbd_status	ehci_root_ctrl_start(usbd_xfer_handle);
-Static void		ehci_root_ctrl_abort(usbd_xfer_handle);
-Static void		ehci_root_ctrl_close(usbd_pipe_handle);
-Static void		ehci_root_ctrl_done(usbd_xfer_handle);
-
-Static usbd_status	ehci_root_intr_transfer(usbd_xfer_handle);
-Static usbd_status	ehci_root_intr_start(usbd_xfer_handle);
-Static void		ehci_root_intr_abort(usbd_xfer_handle);
-Static void		ehci_root_intr_close(usbd_pipe_handle);
-Static void		ehci_root_intr_done(usbd_xfer_handle);
-
-Static usbd_status	ehci_device_ctrl_transfer(usbd_xfer_handle);
-Static usbd_status	ehci_device_ctrl_start(usbd_xfer_handle);
-Static void		ehci_device_ctrl_abort(usbd_xfer_handle);
-Static void		ehci_device_ctrl_close(usbd_pipe_handle);
-Static void		ehci_device_ctrl_done(usbd_xfer_handle);
-
-Static usbd_status	ehci_device_bulk_transfer(usbd_xfer_handle);
-Static usbd_status	ehci_device_bulk_start(usbd_xfer_handle);
-Static void		ehci_device_bulk_abort(usbd_xfer_handle);
-Static void		ehci_device_bulk_close(usbd_pipe_handle);
-Static void		ehci_device_bulk_done(usbd_xfer_handle);
-
-Static usbd_status	ehci_device_intr_transfer(usbd_xfer_handle);
-Static usbd_status	ehci_device_intr_start(usbd_xfer_handle);
-Static void		ehci_device_intr_abort(usbd_xfer_handle);
-Static void		ehci_device_intr_close(usbd_pipe_handle);
-Static void		ehci_device_intr_done(usbd_xfer_handle);
-
-Static usbd_status	ehci_device_isoc_transfer(usbd_xfer_handle);
-Static usbd_status	ehci_device_isoc_start(usbd_xfer_handle);
-Static void		ehci_device_isoc_abort(usbd_xfer_handle);
-Static void		ehci_device_isoc_close(usbd_pipe_handle);
-Static void		ehci_device_isoc_done(usbd_xfer_handle);
-
-Static void		ehci_device_clear_toggle(usbd_pipe_handle pipe);
-Static void		ehci_noop(usbd_pipe_handle pipe);
-
-Static int		ehci_str(usb_string_descriptor_t *, int, char *);
-Static void		ehci_pcd(ehci_softc_t *, usbd_xfer_handle);
-Static void		ehci_pcd_able(ehci_softc_t *, int);
-Static void		ehci_pcd_enable(void *);
-Static void		ehci_disown(ehci_softc_t *, int, int);
-
-Static ehci_soft_qh_t  *ehci_alloc_sqh(ehci_softc_t *);
-Static void		ehci_free_sqh(ehci_softc_t *, ehci_soft_qh_t *);
-
-Static ehci_soft_qtd_t  *ehci_alloc_sqtd(ehci_softc_t *);
-Static void		ehci_free_sqtd(ehci_softc_t *, ehci_soft_qtd_t *);
-Static usbd_status	ehci_alloc_sqtd_chain(struct ehci_pipe *,
+static usbd_status	ehci_open(usbd_pipe_handle);
+static void		ehci_poll(struct usbd_bus *);
+static void		ehci_softintr(void *);
+static int		ehci_intr1(ehci_softc_t *);
+static void		ehci_waitintr(ehci_softc_t *, usbd_xfer_handle);
+static void		ehci_check_intr(ehci_softc_t *, struct ehci_xfer *);
+static void		ehci_idone(struct ehci_xfer *);
+static void		ehci_timeout(void *);
+static void		ehci_timeout_task(void *);
+static void		ehci_intrlist_timeout(void *);
+
+static usbd_status	ehci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t);
+static void		ehci_freem(struct usbd_bus *, usb_dma_t *);
+
+static usbd_xfer_handle	ehci_allocx(struct usbd_bus *);
+static void		ehci_freex(struct usbd_bus *, usbd_xfer_handle);
+
+static usbd_status	ehci_root_ctrl_transfer(usbd_xfer_handle);
+static usbd_status	ehci_root_ctrl_start(usbd_xfer_handle);
+static void		ehci_root_ctrl_abort(usbd_xfer_handle);
+static void		ehci_root_ctrl_close(usbd_pipe_handle);
+static void		ehci_root_ctrl_done(usbd_xfer_handle);
+
+static usbd_status	ehci_root_intr_transfer(usbd_xfer_handle);
+static usbd_status	ehci_root_intr_start(usbd_xfer_handle);
+static void		ehci_root_intr_abort(usbd_xfer_handle);
+static void		ehci_root_intr_close(usbd_pipe_handle);
+static void		ehci_root_intr_done(usbd_xfer_handle);
+
+static usbd_status	ehci_device_ctrl_transfer(usbd_xfer_handle);
+static usbd_status	ehci_device_ctrl_start(usbd_xfer_handle);
+static void		ehci_device_ctrl_abort(usbd_xfer_handle);
+static void		ehci_device_ctrl_close(usbd_pipe_handle);
+static void		ehci_device_ctrl_done(usbd_xfer_handle);
+
+static usbd_status	ehci_device_bulk_transfer(usbd_xfer_handle);
+static usbd_status	ehci_device_bulk_start(usbd_xfer_handle);
+static void		ehci_device_bulk_abort(usbd_xfer_handle);
+static void		ehci_device_bulk_close(usbd_pipe_handle);
+static void		ehci_device_bulk_done(usbd_xfer_handle);
+
+static usbd_status	ehci_device_intr_transfer(usbd_xfer_handle);
+static usbd_status	ehci_device_intr_start(usbd_xfer_handle);
+static void		ehci_device_intr_abort(usbd_xfer_handle);
+static void		ehci_device_intr_close(usbd_pipe_handle);
+static void		ehci_device_intr_done(usbd_xfer_handle);
+
+static usbd_status	ehci_device_isoc_transfer(usbd_xfer_handle);
+static usbd_status	ehci_device_isoc_start(usbd_xfer_handle);
+static void		ehci_device_isoc_abort(usbd_xfer_handle);
+static void		ehci_device_isoc_close(usbd_pipe_handle);
+static void		ehci_device_isoc_done(usbd_xfer_handle);
+
+static void		ehci_device_clear_toggle(usbd_pipe_handle pipe);
+static void		ehci_noop(usbd_pipe_handle pipe);
+
+static int		ehci_str(usb_string_descriptor_t *, int, char *);
+static void		ehci_pcd(ehci_softc_t *, usbd_xfer_handle);
+static void		ehci_pcd_able(ehci_softc_t *, int);
+static void		ehci_pcd_enable(void *);
+static void		ehci_disown(ehci_softc_t *, int, int);
+
+static ehci_soft_qh_t  *ehci_alloc_sqh(ehci_softc_t *);
+static void		ehci_free_sqh(ehci_softc_t *, ehci_soft_qh_t *);
+
+static ehci_soft_qtd_t  *ehci_alloc_sqtd(ehci_softc_t *);
+static void		ehci_free_sqtd(ehci_softc_t *, ehci_soft_qtd_t *);
+static usbd_status	ehci_alloc_sqtd_chain(struct ehci_pipe *,
 			    ehci_softc_t *, int, int, usbd_xfer_handle,
+			    ehci_soft_qtd_t *, ehci_soft_qtd_t *,
 			    ehci_soft_qtd_t **, ehci_soft_qtd_t **);
-Static void		ehci_free_sqtd_chain(ehci_softc_t *, ehci_soft_qtd_t *,
-					    ehci_soft_qtd_t *);
+static void		ehci_free_sqtd_chain(ehci_softc_t *, ehci_soft_qh_t *,
+			    ehci_soft_qtd_t *, ehci_soft_qtd_t *);
 
-Static usbd_status	ehci_device_request(usbd_xfer_handle xfer);
+static usbd_status	ehci_device_request(usbd_xfer_handle xfer);
 
-Static usbd_status	ehci_device_setintr(ehci_softc_t *, ehci_soft_qh_t *,
+static usbd_status	ehci_device_setintr(ehci_softc_t *, ehci_soft_qh_t *,
 			    int ival);
 
-Static void		ehci_add_qh(ehci_soft_qh_t *, ehci_soft_qh_t *);
-Static void		ehci_rem_qh(ehci_softc_t *, ehci_soft_qh_t *,
+static void		ehci_add_qh(ehci_soft_qh_t *, ehci_soft_qh_t *);
+static void		ehci_rem_qh(ehci_softc_t *, ehci_soft_qh_t *,
 				    ehci_soft_qh_t *);
-Static void		ehci_set_qh_qtd(ehci_soft_qh_t *, ehci_soft_qtd_t *);
-Static void		ehci_sync_hc(ehci_softc_t *);
+static void		ehci_activate_qh(ehci_soft_qh_t *, ehci_soft_qtd_t *);
+static void		ehci_sync_hc(ehci_softc_t *);
 
-Static void		ehci_close_pipe(usbd_pipe_handle, ehci_soft_qh_t *);
-Static void		ehci_abort_xfer(usbd_xfer_handle, usbd_status);
+static void		ehci_close_pipe(usbd_pipe_handle, ehci_soft_qh_t *);
+static void		ehci_abort_xfer(usbd_xfer_handle, usbd_status);
 
 #ifdef EHCI_DEBUG
-Static void		ehci_dump_regs(ehci_softc_t *);
+static void		ehci_dump_regs(ehci_softc_t *);
 void			ehci_dump(void);
-Static ehci_softc_t 	*theehci;
-Static void		ehci_dump_link(ehci_link_t, int);
-Static void		ehci_dump_sqtds(ehci_soft_qtd_t *);
-Static void		ehci_dump_sqtd(ehci_soft_qtd_t *);
-Static void		ehci_dump_qtd(ehci_qtd_t *);
-Static void		ehci_dump_sqh(ehci_soft_qh_t *);
+static ehci_softc_t 	*theehci;
+static void		ehci_dump_link(ehci_link_t, int);
+static void		ehci_dump_sqtds(ehci_soft_qtd_t *);
+static void		ehci_dump_sqtd(ehci_soft_qtd_t *);
+static void		ehci_dump_qtd(ehci_qtd_t *);
+static void		ehci_dump_sqh(ehci_soft_qh_t *);
 #ifdef DIAGNOSTIC
-Static void		ehci_dump_exfer(struct ehci_xfer *);
+static void		ehci_dump_exfer(struct ehci_xfer *);
 #endif
 #endif
 
@@ -258,7 +247,7 @@
 	} while (0)
 #define ehci_active_intr_list(ex) ((ex)->inext.le_prev != NULL)
 
-Static struct usbd_bus_methods ehci_bus_methods = {
+static struct usbd_bus_methods ehci_bus_methods = {
 	ehci_open,
 	ehci_softintr,
 	ehci_poll,
@@ -268,7 +257,7 @@
 	ehci_freex,
 };
 
-Static struct usbd_pipe_methods ehci_root_ctrl_methods = {
+static struct usbd_pipe_methods ehci_root_ctrl_methods = {
 	ehci_root_ctrl_transfer,
 	ehci_root_ctrl_start,
 	ehci_root_ctrl_abort,
@@ -277,7 +266,7 @@
 	ehci_root_ctrl_done,
 };
 
-Static struct usbd_pipe_methods ehci_root_intr_methods = {
+static struct usbd_pipe_methods ehci_root_intr_methods = {
 	ehci_root_intr_transfer,
 	ehci_root_intr_start,
 	ehci_root_intr_abort,
@@ -286,7 +275,7 @@
 	ehci_root_intr_done,
 };
 
-Static struct usbd_pipe_methods ehci_device_ctrl_methods = {
+static struct usbd_pipe_methods ehci_device_ctrl_methods = {
 	ehci_device_ctrl_transfer,
 	ehci_device_ctrl_start,
 	ehci_device_ctrl_abort,
@@ -295,7 +284,7 @@
 	ehci_device_ctrl_done,
 };
 
-Static struct usbd_pipe_methods ehci_device_intr_methods = {
+static struct usbd_pipe_methods ehci_device_intr_methods = {
 	ehci_device_intr_transfer,
 	ehci_device_intr_start,
 	ehci_device_intr_abort,
@@ -304,7 +293,7 @@
 	ehci_device_intr_done,
 };
 
-Static struct usbd_pipe_methods ehci_device_bulk_methods = {
+static struct usbd_pipe_methods ehci_device_bulk_methods = {
 	ehci_device_bulk_transfer,
 	ehci_device_bulk_start,
 	ehci_device_bulk_abort,
@@ -313,7 +302,7 @@
 	ehci_device_bulk_done,
 };
 
-Static struct usbd_pipe_methods ehci_device_isoc_methods = {
+static struct usbd_pipe_methods ehci_device_isoc_methods = {
 	ehci_device_isoc_transfer,
 	ehci_device_isoc_start,
 	ehci_device_isoc_abort,
@@ -322,6 +311,39 @@
 	ehci_device_isoc_done,
 };
 
+static usbd_status
+ehci_hcreset(ehci_softc_t *sc)
+{
+	u_int32_t hcr;
+	u_int i;
+
+	EOWRITE4(sc, EHCI_USBCMD, 0);	/* Halt controller */
+	for (i = 0; i < 100; i++) {
+		usb_delay_ms(&sc->sc_bus, 1);
+		hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
+		if (hcr)
+			break;
+	}
+	if (!hcr)
+		/*
+                 * Fall through and try reset anyway even though
+                 * Table 2-9 in the EHCI spec says this will result
+                 * in undefined behavior.
+                 */
+		printf("%s: stop timeout\n",
+		       device_get_nameunit(sc->sc_bus.bdev));
+
+	EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
+	for (i = 0; i < 100; i++) {
+		usb_delay_ms(&sc->sc_bus, 1);
+		hcr = EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_HCRESET;
+		if (!hcr)
+			return (USBD_NORMAL_COMPLETION);
+	}
+	printf("%s: reset timeout\n", device_get_nameunit(sc->sc_bus.bdev));
+	return (USBD_IOERROR);
+}
+
 usbd_status
 ehci_init(ehci_softc_t *sc)
 {
@@ -340,7 +362,7 @@
 	sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
 
 	version = EREAD2(sc, EHCI_HCIVERSION);
-	printf("%s: EHCI version %x.%x\n", USBDEVNAME(sc->sc_bus.bdev),
+	printf("%s: EHCI version %x.%x\n", device_get_nameunit(sc->sc_bus.bdev),
 	       version >> 8, version & 0xff);
 
 	sparams = EREAD4(sc, EHCI_HCSPARAMS);
@@ -349,18 +371,18 @@
 	ncomp = EHCI_HCS_N_CC(sparams);
 	if (ncomp != sc->sc_ncomp) {
 		printf("%s: wrong number of companions (%d != %d)\n",
-		       USBDEVNAME(sc->sc_bus.bdev),
+		       device_get_nameunit(sc->sc_bus.bdev),
 		       ncomp, sc->sc_ncomp);
 		if (ncomp < sc->sc_ncomp)
 			sc->sc_ncomp = ncomp;
 	}
 	if (sc->sc_ncomp > 0) {
 		printf("%s: companion controller%s, %d port%s each:",
-		    USBDEVNAME(sc->sc_bus.bdev), sc->sc_ncomp!=1 ? "s" : "",
+		    device_get_nameunit(sc->sc_bus.bdev), sc->sc_ncomp!=1 ? "s" : "",
 		    EHCI_HCS_N_PCC(sparams),
 		    EHCI_HCS_N_PCC(sparams)!=1 ? "s" : "");
 		for (i = 0; i < sc->sc_ncomp; i++)
-			printf(" %s", USBDEVNAME(sc->sc_comps[i]->bdev));
+			printf(" %s", device_get_nameunit(sc->sc_comps[i]->bdev));
 		printf("\n");
 	}
 	sc->sc_noport = EHCI_HCS_N_PORTS(sparams);
@@ -375,21 +397,10 @@
 	sc->sc_bus.usbrev = USBREV_2_0;
 
 	/* Reset the controller */
-	DPRINTF(("%s: resetting\n", USBDEVNAME(sc->sc_bus.bdev)));
-	EOWRITE4(sc, EHCI_USBCMD, 0);	/* Halt controller */
-	usb_delay_ms(&sc->sc_bus, 1);
-	EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
-	for (i = 0; i < 100; i++) {
-		usb_delay_ms(&sc->sc_bus, 1);
-		hcr = EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_HCRESET;
-		if (!hcr)
-			break;
-	}
-	if (hcr) {
-		printf("%s: reset timeout\n",
-		    USBDEVNAME(sc->sc_bus.bdev));
-		return (USBD_IOERROR);
-	}
+	DPRINTF(("%s: resetting\n", device_get_nameunit(sc->sc_bus.bdev)));
+	err = ehci_hcreset(sc);
+	if (err != USBD_NORMAL_COMPLETION)
+		return (err);
 
 	/* frame list size at default, read back what we got and use that */
 	switch (EHCI_CMD_FLS(EOREAD4(sc, EHCI_USBCMD))) {
@@ -402,7 +413,7 @@
 	    EHCI_FLALIGN_ALIGN, &sc->sc_fldma);
 	if (err)
 		return (err);
-	DPRINTF(("%s: flsize=%d\n", USBDEVNAME(sc->sc_bus.bdev),sc->sc_flsize));
+	DPRINTF(("%s: flsize=%d\n", device_get_nameunit(sc->sc_bus.bdev),sc->sc_flsize));
 	sc->sc_flist = KERNADDR(&sc->sc_fldma, 0);
 	EOWRITE4(sc, EHCI_PERIODICLISTBASE, DMAADDR(&sc->sc_fldma, 0));
 
@@ -451,7 +462,6 @@
 		sqh->qh.qh_qtd.qtd_next = EHCI_NULL;
 		sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
 		sqh->qh.qh_qtd.qtd_status = htole32(EHCI_QTD_HALTED);
-		sqh->sqtd = NULL;
 	}
 	/* Point the frame list at the last level (128ms). */
 	for (i = 0; i < sc->sc_flsize; i++) {
@@ -477,8 +487,7 @@
 	/* Fill the overlay qTD */
 	sqh->qh.qh_qtd.qtd_next = EHCI_NULL;
 	sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
-	sqh->qh.qh_qtd.qtd_status = htole32(EHCI_QTD_HALTED);
-	sqh->sqtd = NULL;
+	sqh->qh.qh_qtd.qtd_status = htole32(0);
 #ifdef EHCI_DEBUG
 	if (ehcidebug) {
 		ehci_dump_sqh(sqh);
@@ -489,8 +498,8 @@
 	sc->sc_async_head = sqh;
 	EOWRITE4(sc, EHCI_ASYNCLISTADDR, sqh->physaddr | EHCI_LINK_QH);
 
-	usb_callout_init(sc->sc_tmo_pcd);
-	usb_callout_init(sc->sc_tmo_intrlist);
+	callout_init(&sc->sc_tmo_pcd, 0);
+	callout_init(&sc->sc_tmo_intrlist, 0);
 
 	lockinit(&sc->sc_doorbell_lock, PZERO, "ehcidb", 0, 0);
 
@@ -515,7 +524,7 @@
 			break;
 	}
 	if (hcr) {
-		printf("%s: run timeout\n", USBDEVNAME(sc->sc_bus.bdev));
+		printf("%s: run timeout\n", device_get_nameunit(sc->sc_bus.bdev));
 		return (USBD_IOERROR);
 	}
 
@@ -553,7 +562,7 @@
 	return (ehci_intr1(sc));
 }
 
-Static int
+static int
 ehci_intr1(ehci_softc_t *sc)
 {
 	u_int32_t intrs, eintrs;
@@ -596,7 +605,7 @@
 	}
 	if (eintrs & EHCI_STS_HSE) {
 		printf("%s: unrecoverable error, controller halted\n",
-		       USBDEVNAME(sc->sc_bus.bdev));
+		       device_get_nameunit(sc->sc_bus.bdev));
 		/* XXX what else */
 	}
 	if (eintrs & EHCI_STS_PCD) {
@@ -607,7 +616,7 @@
 		 */
 		ehci_pcd_able(sc, 0);
 		/* Do not allow RHSC interrupts > 1 per second */
-                usb_callout(sc->sc_tmo_pcd, hz, ehci_pcd_enable, sc);
+                callout_reset(&sc->sc_tmo_pcd, hz, ehci_pcd_enable, sc);
 		eintrs &= ~EHCI_STS_PCD;
 	}
 
@@ -618,7 +627,7 @@
 		sc->sc_eintrs &= ~eintrs;
 		EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
 		printf("%s: blocking intrs 0x%x\n",
-		       USBDEVNAME(sc->sc_bus.bdev), eintrs);
+		       device_get_nameunit(sc->sc_bus.bdev), eintrs);
 	}
 
 	return (1);
@@ -657,7 +666,7 @@
 
 	pipe = xfer->pipe;
 
-	p = KERNADDR(&xfer->dmabuf, 0);
+	p = xfer->buffer;
 	m = min(sc->sc_noport, xfer->length * 8 - 1);
 	memset(p, 0, xfer->length);
 	for (i = 1; i <= m; i++) {
@@ -678,7 +687,7 @@
 	ehci_softc_t *sc = v;
 	struct ehci_xfer *ex, *nextex;
 
-	DPRINTFN(10,("%s: ehci_softintr (%d)\n", USBDEVNAME(sc->sc_bus.bdev),
+	DPRINTFN(10,("%s: ehci_softintr (%d)\n", device_get_nameunit(sc->sc_bus.bdev),
 		     sc->sc_bus.intr_context));
 
 	sc->sc_bus.intr_context++;
@@ -697,8 +706,8 @@
 	/* Schedule a callout to catch any dropped transactions. */
 	if ((sc->sc_flags & EHCI_SCFLG_LOSTINTRBUG) &&
 	    !LIST_EMPTY(&sc->sc_intrhead))
-		usb_callout(sc->sc_tmo_intrlist, hz / 5, ehci_intrlist_timeout,
-		   sc);
+		callout_reset(&sc->sc_tmo_intrlist, hz / 5,
+		    ehci_intrlist_timeout, sc);
 
 #ifdef USB_USE_SOFTINTR
 	if (sc->sc_softwake) {
@@ -755,7 +764,7 @@
 	}
  done:
 	DPRINTFN(12, ("ehci_check_intr: ex=%p done\n", ex));
-	usb_uncallout(ex->xfer.timeout_handle, ehci_timeout, ex);
+	callout_stop(&ex->xfer.timeout_handle);
 	usb_rem_task(ex->xfer.pipe->device, &ex->abort_task);
 	ehci_idone(ex);
 }
@@ -767,8 +776,8 @@
 	struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;
 	ehci_soft_qtd_t *sqtd, *lsqtd;
 	u_int32_t status = 0, nstatus = 0;
+	ehci_physaddr_t nextphys, altnextphys;
 	int actlen, cerr;
-	u_int pkts_left;
 
 	DPRINTFN(/*12*/2, ("ehci_idone: ex=%p\n", ex));
 #ifdef DIAGNOSTIC
@@ -801,6 +810,30 @@
 		ehci_dump_sqtds(ex->sqtdstart);
 #endif
 
+	/*
+	 * Make sure that the QH overlay qTD does not reference any
+	 * of the qTDs we are about to free. This is probably only
+	 * necessary if the transfer is marked as HALTED.
+	 */
+	nextphys = EHCI_LINK_ADDR(le32toh(epipe->sqh->qh.qh_qtd.qtd_next));
+	altnextphys =
+	    EHCI_LINK_ADDR(le32toh(epipe->sqh->qh.qh_qtd.qtd_altnext));
+	for (sqtd = ex->sqtdstart; sqtd != ex->sqtdend->nextqtd;
+	     sqtd = sqtd->nextqtd) {
+		if (sqtd->physaddr == nextphys) {
+			epipe->sqh->qh.qh_qtd.qtd_next =
+			    htole32(ex->sqtdend->nextqtd->physaddr);
+			DPRINTFN(4, ("ehci_idone: updated overlay next ptr\n"));
+
+		}
+		if (sqtd->physaddr == altnextphys) {
+			DPRINTFN(4,
+			    ("ehci_idone: updated overlay altnext ptr\n"));
+			epipe->sqh->qh.qh_qtd.qtd_altnext =
+			    htole32(ex->sqtdend->nextqtd->physaddr);
+		}
+	}
+
 	/* The transfer is done, compute actual length and status. */
 	lsqtd = ex->sqtdend;
 	actlen = 0;
@@ -811,36 +844,12 @@
 
 		status = nstatus;
 		/* halt is ok if descriptor is last, and complete */
-		if (sqtd->qtd.qtd_next == EHCI_NULL &&
-		    EHCI_QTD_GET_BYTES(status) == 0)
+		if (sqtd == lsqtd && EHCI_QTD_GET_BYTES(status) == 0)
 			status &= ~EHCI_QTD_HALTED;
 		if (EHCI_QTD_GET_PID(status) !=	EHCI_QTD_PID_SETUP)
 			actlen += sqtd->len - EHCI_QTD_GET_BYTES(status);
 	}
 
-	/*
-	 * If there are left over TDs we need to update the toggle.
-	 * The default pipe doesn't need it since control transfers
-	 * start the toggle at 0 every time.
-	 */
-	if (sqtd != lsqtd->nextqtd &&
-	    xfer->pipe->device->default_pipe != xfer->pipe) {
-		DPRINTF(("ehci_idone: need toggle update status=%08x nstatus=%08x\n", status, nstatus));
-#if 0
-		ehci_dump_sqh(epipe->sqh);
-		ehci_dump_sqtds(ex->sqtdstart);
-#endif
-		epipe->nexttoggle = EHCI_QTD_GET_TOGGLE(nstatus);
-	}
-
-	/*
-	 * For a short transfer we need to update the toggle for the missing
-	 * packets within the qTD.
-	 */
-	pkts_left = EHCI_QTD_GET_BYTES(status) /
-	    UGETW(xfer->pipe->endpoint->edesc->wMaxPacketSize);
-	epipe->nexttoggle ^= pkts_left % 2;
-
 	cerr = EHCI_QTD_GET_CERR(status);
 	DPRINTFN(/*10*/2, ("ehci_idone: len=%d, actlen=%d, cerr=%d, "
 	    "status=0x%x\n", xfer->length, actlen, cerr, status));
@@ -937,21 +946,12 @@
 {
 	int rv = 0;
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	if (sc->sc_child != NULL)
-		rv = config_detach(sc->sc_child, flags);
-
-	if (rv != 0)
-		return (rv);
-#else
 	sc->sc_dying = 1;
-#endif
 
 	EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
-	EOWRITE4(sc, EHCI_USBCMD, 0);
-	EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
-	usb_uncallout(sc->sc_tmo_intrlist, ehci_intrlist_timeout, sc);
-	usb_uncallout(sc->sc_tmo_pcd, ehci_pcd_enable, sc);
+	(void) ehci_hcreset(sc);
+	callout_stop(&sc->sc_tmo_intrlist);
+	callout_stop(&sc->sc_tmo_pcd);
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 	if (sc->sc_powerhook != NULL)
@@ -959,7 +959,6 @@
 	if (sc->sc_shutdownhook != NULL)
 		shutdownhook_disestablish(sc->sc_shutdownhook);
 #endif
-
 	usb_delay_ms(&sc->sc_bus, 300); /* XXX let stray task complete */
 
 	usb_freemem(&sc->sc_bus, &sc->sc_fldma);
@@ -968,27 +967,6 @@
 	return (rv);
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-ehci_activate(device_ptr_t self, enum devact act)
-{
-	struct ehci_softc *sc = (struct ehci_softc *)self;
-	int rv = 0;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		if (sc->sc_child != NULL)
-			rv = config_deactivate(sc->sc_child);
-		sc->sc_dying = 1;
-		break;
-	}
-	return (rv);
-}
-#endif
-
 /*
  * Handle suspend/resume.
  *
@@ -1012,9 +990,7 @@
 	s = splhardusb();
 	switch (why) {
 	case PWR_SUSPEND:
-#if defined(__NetBSD__) || defined(__OpenBSD__)
 	case PWR_STANDBY:
-#endif
 		sc->sc_bus.use_polling++;
 
 		for (i = 1; i <= sc->sc_noport; i++) {
@@ -1040,7 +1016,7 @@
 		}
 		if (hcr != 0) {
 			printf("%s: reset timeout\n",
-			    USBDEVNAME(sc->sc_bus.bdev));
+			    device_get_nameunit(sc->sc_bus.bdev));
 		}
 
 		cmd &= ~EHCI_CMD_RS;
@@ -1055,7 +1031,7 @@
 		}
 		if (hcr != EHCI_STS_HCH) {
 			printf("%s: config timeout\n",
-			    USBDEVNAME(sc->sc_bus.bdev));
+			    device_get_nameunit(sc->sc_bus.bdev));
 		}
 
 		sc->sc_bus.use_polling--;
@@ -1105,19 +1081,17 @@
 		}
 		if (hcr == EHCI_STS_HCH) {
 			printf("%s: config timeout\n",
-			    USBDEVNAME(sc->sc_bus.bdev));
+			    device_get_nameunit(sc->sc_bus.bdev));
 		}
 
 		usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT);
 
 		sc->sc_bus.use_polling--;
 		break;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
 	case PWR_SOFTSUSPEND:
 	case PWR_SOFTSTANDBY:
 	case PWR_SOFTRESUME:
 		break;
-#endif
 	}
 	splx(s);
 
@@ -1137,8 +1111,7 @@
 	ehci_softc_t *sc = v;
 
 	DPRINTF(("ehci_shutdown: stopping the HC\n"));
-	EOWRITE4(sc, EHCI_USBCMD, 0);	/* Halt controller */
-	EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
+	(void) ehci_hcreset(sc);
 }
 
 usbd_status
@@ -1166,9 +1139,9 @@
 	struct ehci_softc *sc = (struct ehci_softc *)bus;
 	usbd_xfer_handle xfer;
 
-	xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
+	xfer = STAILQ_FIRST(&sc->sc_free_xfers);
 	if (xfer != NULL) {
-		SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
+		STAILQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
 #ifdef DIAGNOSTIC
 		if (xfer->busy_free != XFER_FREE) {
 			printf("ehci_allocx: xfer=%p not free, 0x%08x\n", xfer,
@@ -1208,10 +1181,10 @@
 		return;
 	}
 #endif
-	SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
+	STAILQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
 }
 
-Static void
+static void
 ehci_device_clear_toggle(usbd_pipe_handle pipe)
 {
 	struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
@@ -1222,10 +1195,13 @@
 	if (ehcidebug)
 		usbd_dump_pipe(pipe);
 #endif
-	epipe->nexttoggle = 0;
+	KASSERT((epipe->sqh->qh.qh_qtd.qtd_status &
+	    htole32(EHCI_QTD_ACTIVE)) == 0,
+	    ("ehci_device_clear_toggle: queue active"));
+	epipe->sqh->qh.qh_qtd.qtd_status &= htole32(~EHCI_QTD_TOGGLE_MASK);
 }
 
-Static void
+static void
 ehci_noop(usbd_pipe_handle pipe)
 {
 }
@@ -1331,6 +1307,7 @@
 	u_int32_t endp, endphub;
 
 	printf("QH(%p) at 0x%08x:\n", sqh, sqh->physaddr);
+	printf("  sqtd=%p inactivesqtd=%p\n", sqh->sqtd, sqh->inactivesqtd);
 	printf("  link="); ehci_dump_link(qh->qh_link, 1); printf("\n");
 	endp = le32toh(qh->qh_endp);
 	printf("  endp=0x%08x\n", endp);
@@ -1353,7 +1330,7 @@
 }
 
 #ifdef DIAGNOSTIC
-Static void
+static void
 ehci_dump_exfer(struct ehci_xfer *ex)
 {
 	printf("ehci_dump_exfer: ex=%p\n", ex);
@@ -1390,8 +1367,6 @@
 	if (sc->sc_dying)
 		return (USBD_IOERROR);
 
-	epipe->nexttoggle = pipe->endpoint->savedtoggle;
-
 	if (addr == sc->sc_addr) {
 		switch (ed->bEndpointAddress) {
 		case USB_CONTROL_ENDPOINT:
@@ -1416,7 +1391,7 @@
 	if (speed != EHCI_QH_SPEED_HIGH && xfertype == UE_ISOCHRONOUS) {
 		printf("%s: *** WARNING: opening low/full speed device, this "
 		       "does not work yet.\n",
-		       USBDEVNAME(sc->sc_bus.bdev));
+		       device_get_nameunit(sc->sc_bus.bdev));
 		DPRINTFN(1,("ehci_open: hshubaddr=%d hshubport=%d\n",
 			    hshubaddr, hshubport));
 		return USBD_INVAL;
@@ -1431,7 +1406,7 @@
 		EHCI_QH_SET_ADDR(addr) |
 		EHCI_QH_SET_ENDPT(UE_GET_ADDR(ed->bEndpointAddress)) |
 		EHCI_QH_SET_EPS(speed) |
-		EHCI_QH_DTC |
+		(xfertype == UE_CONTROL ? EHCI_QH_DTC : 0) |
 		EHCI_QH_SET_MPL(UGETW(ed->wMaxPacketSize)) |
 		(speed != EHCI_QH_SPEED_HIGH && xfertype == UE_CONTROL ?
 		 EHCI_QH_CTL : 0) |
@@ -1445,10 +1420,9 @@
 		EHCI_QH_SET_SMASK(xfertype == UE_INTERRUPT ? 0x01 : 0)
 		);
 	sqh->qh.qh_curqtd = EHCI_NULL;
-	/* Fill the overlay qTD */
-	sqh->qh.qh_qtd.qtd_next = EHCI_NULL;
-	sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
-	sqh->qh.qh_qtd.qtd_status = htole32(0);
+	/* The overlay qTD was already set up by ehci_alloc_sqh(). */
+	sqh->qh.qh_qtd.qtd_status =
+	    htole32(EHCI_QTD_SET_TOGGLE(pipe->endpoint->savedtoggle));
 
 	epipe->sqh = sqh;
 
@@ -1535,27 +1509,38 @@
 	ehci_sync_hc(sc);
 }
 
+/* Restart a QH following the addition of a qTD. */
 void
-ehci_set_qh_qtd(ehci_soft_qh_t *sqh, ehci_soft_qtd_t *sqtd)
+ehci_activate_qh(ehci_soft_qh_t *sqh, ehci_soft_qtd_t *sqtd)
 {
-	int i;
-	u_int32_t status;
+	KASSERT((sqtd->qtd.qtd_status & htole32(EHCI_QTD_ACTIVE)) == 0,
+	    ("ehci_activate_qh: already active"));
 
-	/* Save toggle bit and ping status. */
-	status = sqh->qh.qh_qtd.qtd_status &
-	    htole32(EHCI_QTD_TOGGLE_MASK |
-		    EHCI_QTD_SET_STATUS(EHCI_QTD_PINGSTATE));
-	/* Set HALTED to make hw leave it alone. */
-	sqh->qh.qh_qtd.qtd_status =
-	    htole32(EHCI_QTD_SET_STATUS(EHCI_QTD_HALTED));
-	sqh->qh.qh_curqtd = 0;
-	sqh->qh.qh_qtd.qtd_next = htole32(sqtd->physaddr);
-	sqh->qh.qh_qtd.qtd_altnext = 0;
-	for (i = 0; i < EHCI_QTD_NBUFFERS; i++)
-		sqh->qh.qh_qtd.qtd_buffer[i] = 0;
-	sqh->sqtd = sqtd;
-	/* Set !HALTED && !ACTIVE to start execution, preserve some fields */
-	sqh->qh.qh_qtd.qtd_status = status;
+	/*
+	 * When a QH is idle, the overlay qTD should be marked as not
+	 * halted and not active. This causes the host controller to
+	 * retrieve the real qTD on each pass (rather than just examinig
+	 * the overlay), so it will notice when we activate the qTD.
+	 */
+	if (sqtd == sqh->sqtd) {
+		/* Check that the hardware is in the state we expect. */
+		if (EHCI_LINK_ADDR(le32toh(sqh->qh.qh_qtd.qtd_next)) !=
+		    sqtd->physaddr) {
+#ifdef EHCI_DEBUG
+			printf("ehci_activate_qh: unexpected next ptr\n");
+			ehci_dump_sqh(sqh);
+			ehci_dump_sqtds(sqh->sqtd);
+#endif
+			sqh->qh.qh_qtd.qtd_next = htole32(sqtd->physaddr);
+			sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
+		}
+		/* Ensure the flags are correct. */
+		sqh->qh.qh_qtd.qtd_status &= htole32(EHCI_QTD_PINGSTATE |
+		    EHCI_QTD_TOGGLE_MASK);
+	}
+
+	/* Now activate the qTD. */
+	sqtd->qtd.qtd_status |= htole32(EHCI_QTD_ACTIVE);
 }
 
 /*
@@ -1599,7 +1584,7 @@
 /*
  * Data structures and routines to emulate the root hub.
  */
-Static usb_device_descriptor_t ehci_devd = {
+static usb_device_descriptor_t ehci_devd = {
 	USB_DEVICE_DESCRIPTOR_SIZE,
 	UDESC_DEVICE,		/* type */
 	{0x00, 0x02},		/* USB version */
@@ -1612,7 +1597,7 @@
 	1			/* # of configurations */
 };
 
-Static usb_device_qualifier_t ehci_odevd = {
+static usb_device_qualifier_t ehci_odevd = {
 	USB_DEVICE_DESCRIPTOR_SIZE,
 	UDESC_DEVICE_QUALIFIER,	/* type */
 	{0x00, 0x02},		/* USB version */
@@ -1624,7 +1609,7 @@
 	0
 };
 
-Static usb_config_descriptor_t ehci_confd = {
+static usb_config_descriptor_t ehci_confd = {
 	USB_CONFIG_DESCRIPTOR_SIZE,
 	UDESC_CONFIG,
 	{USB_CONFIG_DESCRIPTOR_SIZE +
@@ -1637,7 +1622,7 @@
 	0			/* max power */
 };
 
-Static usb_interface_descriptor_t ehci_ifcd = {
+static usb_interface_descriptor_t ehci_ifcd = {
 	USB_INTERFACE_DESCRIPTOR_SIZE,
 	UDESC_INTERFACE,
 	0,
@@ -1649,7 +1634,7 @@
 	0
 };
 
-Static usb_endpoint_descriptor_t ehci_endpd = {
+static usb_endpoint_descriptor_t ehci_endpd = {
 	USB_ENDPOINT_DESCRIPTOR_SIZE,
 	UDESC_ENDPOINT,
 	UE_DIR_IN | EHCI_INTR_ENDPT,
@@ -1658,7 +1643,7 @@
 	255
 };
 
-Static usb_hub_descriptor_t ehci_hubd = {
+static usb_hub_descriptor_t ehci_hubd = {
 	USB_HUB_DESCRIPTOR_SIZE,
 	UDESC_HUB,
 	0,
@@ -1668,7 +1653,7 @@
 	{0},
 };
 
-Static int
+static int
 ehci_str(usb_string_descriptor_t *p, int l, char *s)
 {
 	int i;
@@ -1688,7 +1673,7 @@
 /*
  * Simulate a hardware hub by handling all the necessary requests.
  */
-Static usbd_status
+static usbd_status
 ehci_root_ctrl_transfer(usbd_xfer_handle xfer)
 {
 	usbd_status err;
@@ -1699,10 +1684,10 @@
 		return (err);
 
 	/* Pipe isn't running, start first */
-	return (ehci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (ehci_root_ctrl_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
-Static usbd_status
+static usbd_status
 ehci_root_ctrl_start(usbd_xfer_handle xfer)
 {
 	ehci_softc_t *sc = (ehci_softc_t *)xfer->pipe->device->bus;
@@ -1733,7 +1718,7 @@
 	index = UGETW(req->wIndex);
 
 	if (len != 0)
-		buf = KERNADDR(&xfer->dmabuf, 0);
+		buf = xfer->buffer;
 
 #define C(x,y) ((x) | ((y) << 8))
 	switch(C(req->bRequest, req->bmRequestType)) {
@@ -2041,7 +2026,7 @@
 			DPRINTF(("ehci after reset, status=0x%08x\n", v));
 			if (v & EHCI_PS_PR) {
 				printf("%s: port reset timeout\n",
-				       USBDEVNAME(sc->sc_bus.bdev));
+				       device_get_nameunit(sc->sc_bus.bdev));
 				return (USBD_TIMEOUT);
 			}
 			if (!(v & EHCI_PS_PE)) {
@@ -2103,15 +2088,15 @@
 		int i = (index-1) / sc->sc_npcomp;
 		if (i >= sc->sc_ncomp)
 			printf("%s: strange port\n",
-			       USBDEVNAME(sc->sc_bus.bdev));
+			       device_get_nameunit(sc->sc_bus.bdev));
 		else
 			printf("%s: handing over %s speed device on "
 			       "port %d to %s\n",
-			       USBDEVNAME(sc->sc_bus.bdev),
+			       device_get_nameunit(sc->sc_bus.bdev),
 			       lowspeed ? "low" : "full",
-			       index, USBDEVNAME(sc->sc_comps[i]->bdev));
+			       index, device_get_nameunit(sc->sc_comps[i]->bdev));
 	} else {
-		printf("%s: npcomp == 0\n", USBDEVNAME(sc->sc_bus.bdev));
+		printf("%s: npcomp == 0\n", device_get_nameunit(sc->sc_bus.bdev));
 	}
 #endif
 	port = EHCI_PORTSC(index);
@@ -2120,14 +2105,14 @@
 }
 
 /* Abort a root control request. */
-Static void
+static void
 ehci_root_ctrl_abort(usbd_xfer_handle xfer)
 {
 	/* Nothing to do, all transfers are synchronous. */
 }
 
 /* Close the root pipe. */
-Static void
+static void
 ehci_root_ctrl_close(usbd_pipe_handle pipe)
 {
 	DPRINTF(("ehci_root_ctrl_close\n"));
@@ -2139,7 +2124,7 @@
 {
 }
 
-Static usbd_status
+static usbd_status
 ehci_root_intr_transfer(usbd_xfer_handle xfer)
 {
 	usbd_status err;
@@ -2150,10 +2135,10 @@
 		return (err);
 
 	/* Pipe isn't running, start first */
-	return (ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (ehci_root_intr_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
-Static usbd_status
+static usbd_status
 ehci_root_intr_start(usbd_xfer_handle xfer)
 {
 	usbd_pipe_handle pipe = xfer->pipe;
@@ -2168,7 +2153,7 @@
 }
 
 /* Abort a root interrupt request. */
-Static void
+static void
 ehci_root_intr_abort(usbd_xfer_handle xfer)
 {
 	int s;
@@ -2184,7 +2169,7 @@
 }
 
 /* Close the root pipe. */
-Static void
+static void
 ehci_root_intr_close(usbd_pipe_handle pipe)
 {
 	ehci_softc_t *sc = (ehci_softc_t *)pipe->device->bus;
@@ -2205,6 +2190,7 @@
 ehci_alloc_sqh(ehci_softc_t *sc)
 {
 	ehci_soft_qh_t *sqh;
+	ehci_soft_qtd_t *sqtd;
 	usbd_status err;
 	int i, offs;
 	usb_dma_t dma;
@@ -2227,17 +2213,36 @@
 			sc->sc_freeqhs = sqh;
 		}
 	}
+	/* Allocate the initial inactive sqtd. */
+	sqtd = ehci_alloc_sqtd(sc);
+	if (sqtd == NULL)
+		return (NULL);
+	sqtd->qtd.qtd_status = htole32(0);
+	sqtd->qtd.qtd_next = EHCI_NULL;
+	sqtd->qtd.qtd_altnext = EHCI_NULL;
+
 	sqh = sc->sc_freeqhs;
 	sc->sc_freeqhs = sqh->next;
-	memset(&sqh->qh, 0, sizeof(ehci_qh_t));
+
+	/* The overlay QTD should begin zeroed. */
+	sqh->qh.qh_qtd.qtd_next = htole32(sqtd->physaddr);
+	sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
+	sqh->qh.qh_qtd.qtd_status = 0;
+	for (i = 0; i < EHCI_QTD_NBUFFERS; i++) {
+		sqh->qh.qh_qtd.qtd_buffer[i] = 0;
+		sqh->qh.qh_qtd.qtd_buffer_hi[i] = 0;
+	}
 	sqh->next = NULL;
 	sqh->prev = NULL;
+	sqh->sqtd = sqtd;
+	sqh->inactivesqtd = sqtd;
 	return (sqh);
 }
 
 void
 ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh)
 {
+	ehci_free_sqtd(sc, sqh->inactivesqtd);
 	sqh->next = sc->sc_freeqhs;
 	sc->sc_freeqhs = sqh;
 }
@@ -2275,7 +2280,13 @@
 	s = splusb();
 	sqtd = sc->sc_freeqtds;
 	sc->sc_freeqtds = sqtd->nextqtd;
-	memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t));
+	sqtd->qtd.qtd_next = EHCI_NULL;
+	sqtd->qtd.qtd_altnext = EHCI_NULL;
+	sqtd->qtd.qtd_status = 0;
+	for (i = 0; i < EHCI_QTD_NBUFFERS; i++) {
+		sqtd->qtd.qtd_buffer[i] = 0;
+		sqtd->qtd.qtd_buffer_hi[i] = 0;
+	}
 	sqtd->nextqtd = NULL;
 	sqtd->xfer = NULL;
 	splx(s);
@@ -2296,26 +2307,22 @@
 
 usbd_status
 ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc,
-		     int alen, int rd, usbd_xfer_handle xfer,
-		     ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep)
+     int alen, int rd, usbd_xfer_handle xfer, ehci_soft_qtd_t *start,
+     ehci_soft_qtd_t *newinactive, ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep)
 {
 	ehci_soft_qtd_t *next, *cur;
-	ehci_physaddr_t dataphys, dataphyspage, dataphyslastpage, nextphys;
+	ehci_physaddr_t dataphys, nextphys;
 	u_int32_t qtdstatus;
-	int len, curlen, mps, offset;
-	int i, tog;
-	usb_dma_t *dma = &xfer->dmabuf;
+	int adj, len, curlen, mps, offset, pagelen, seg, segoff;
+	int i, iscontrol, forceshort;
+	struct usb_dma_mapping *dma = &xfer->dmamap;
 
 	DPRINTFN(alen<4*4096,("ehci_alloc_sqtd_chain: start len=%d\n", alen));
 
 	offset = 0;
 	len = alen;
-	dataphys = DMAADDR(dma, 0);
-	dataphyslastpage = EHCI_PAGE(DMAADDR(dma, len - 1));
-#if 0
-printf("status=%08x toggle=%d\n", epipe->sqh->qh.qh_qtd.qtd_status,
-    epipe->nexttoggle);
-#endif
+	iscontrol = (epipe->pipe.endpoint->edesc->bmAttributes & UE_XFERTYPE) ==
+	    UE_CONTROL;
 	qtdstatus = EHCI_QTD_ACTIVE |
 	    EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) |
 	    EHCI_QTD_SET_CERR(3)
@@ -2323,70 +2330,86 @@
 	    /* BYTES set below */
 	    ;
 	mps = UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize);
-	tog = epipe->nexttoggle;
-	qtdstatus |= EHCI_QTD_SET_TOGGLE(tog);
+	forceshort = ((xfer->flags & USBD_FORCE_SHORT_XFER) || len == 0) &&
+	    len % mps == 0;
+	/*
+	 * The control transfer data stage always starts with a toggle of 1.
+	 * For other transfers we let the hardware track the toggle state.
+	 */
+	if (iscontrol)
+		qtdstatus |= EHCI_QTD_SET_TOGGLE(1);
 
-	cur = ehci_alloc_sqtd(sc);
-	*sp = cur;
-	if (cur == NULL)
-		goto nomem;
+	if (start != NULL) {
+		/*
+		 * If we are given a starting qTD, assume it is linked into
+		 * an active QH so be careful not to mark it active.
+		 */
+		cur = start;
+		*sp = cur;
+		qtdstatus &= ~EHCI_QTD_ACTIVE;
+	} else {
+		cur = ehci_alloc_sqtd(sc);
+		*sp = cur;
+		if (cur == NULL)
+			goto nomem;
+	}
+	seg = 0;
+	segoff = 0;
 	for (;;) {
-		dataphyspage = EHCI_PAGE(dataphys);
+		curlen = 0;
+
 		/* The EHCI hardware can handle at most 5 pages. */
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-		if (dataphyslastpage - dataphyspage <
-		    EHCI_QTD_NBUFFERS * EHCI_PAGE_SIZE) {
-			/* we can handle it in this QTD */
-			curlen = len;
-		}
-#elif defined(__FreeBSD__)
-		/* XXX This is pretty broken: Because we do not allocate
-		 * a contiguous buffer (contiguous in physical pages) we
-		 * can only transfer one page in one go.
-		 * So check whether the start and end of the buffer are on
-		 * the same page.
-		 */
-		if (dataphyspage == dataphyslastpage) {
-			curlen = len;
+		for (i = 0; i < EHCI_QTD_NBUFFERS && curlen < len; i++) {
+			KASSERT(seg < dma->nsegs,
+			    ("ehci_alloc_sqtd_chain: overrun"));
+			dataphys = dma->segs[seg].ds_addr + segoff;
+			pagelen = dma->segs[seg].ds_len - segoff;
+			if (pagelen > len - curlen)
+				pagelen = len - curlen;
+			if (pagelen > EHCI_PAGE_SIZE -
+			    EHCI_PAGE_OFFSET(dataphys))
+				pagelen = EHCI_PAGE_SIZE -
+				    EHCI_PAGE_OFFSET(dataphys);
+			segoff += pagelen;
+			if (segoff >= dma->segs[seg].ds_len) {
+				KASSERT(segoff == dma->segs[seg].ds_len,
+				    ("ehci_alloc_sqtd_chain: overlap"));
+				seg++;
+				segoff = 0;
+			}
+
+			cur->qtd.qtd_buffer[i] = htole32(dataphys);
+			cur->qtd.qtd_buffer_hi[i] = 0;
+			curlen += pagelen;
+
+			/*
+			 * Must stop if there is any gap before or after
+			 * the page boundary.
+			 */
+			if (EHCI_PAGE_OFFSET(dataphys + pagelen) != 0)
+				break;
+			if (seg < dma->nsegs && EHCI_PAGE_OFFSET(segoff +
+			    dma->segs[seg].ds_addr) != 0)
+				break;
 		}
-#endif
-		else {
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-			/* must use multiple TDs, fill as much as possible. */
-			curlen = EHCI_QTD_NBUFFERS * EHCI_PAGE_SIZE -
-				 EHCI_PAGE_OFFSET(dataphys);
-#ifdef DIAGNOSTIC
-			if (curlen > len) {
-				printf("ehci_alloc_sqtd_chain: curlen=0x%x "
-				       "len=0x%x offs=0x%x\n", curlen, len,
-				       EHCI_PAGE_OFFSET(dataphys));
-				printf("lastpage=0x%x page=0x%x phys=0x%x\n",
-				       dataphyslastpage, dataphyspage,
-				       dataphys);
-				curlen = len;
+		/* Adjust down to a multiple of mps if not at the end. */
+		if (curlen < len && curlen % mps != 0) {
+			adj = curlen % mps;
+			curlen -= adj;
+			KASSERT(curlen > 0,
+			    ("ehci_alloc_sqtd_chain: need to copy"));
+			segoff -= adj;
+			if (segoff < 0) {
+				seg--;
+				segoff += dma->segs[seg].ds_len;
 			}
-#endif
-#elif defined(__FreeBSD__)
-			/* See comment above (XXX) */
-			curlen = EHCI_PAGE_SIZE -
-				 EHCI_PAGE_MASK(dataphys);
-#endif
-			/* the length must be a multiple of the max size */
-			curlen -= curlen % mps;
-			DPRINTFN(1,("ehci_alloc_sqtd_chain: multiple QTDs, "
-				    "curlen=%d\n", curlen));
-#ifdef DIAGNOSTIC
-			if (curlen == 0)
-				panic("ehci_alloc_std: curlen == 0");
-#endif
-		}
-		DPRINTFN(4,("ehci_alloc_sqtd_chain: dataphys=0x%08x "
-			    "dataphyslastpage=0x%08x len=%d curlen=%d\n",
-			    dataphys, dataphyslastpage,
-			    len, curlen));
+			KASSERT(seg >= 0 && segoff >= 0,
+			    ("ehci_alloc_sqtd_chain: adjust to mps"));
+		}
+
 		len -= curlen;
 
-		if (len != 0) {
+		if (len != 0 || forceshort) {
 			next = ehci_alloc_sqtd(sc);
 			if (next == NULL)
 				goto nomem;
@@ -2396,43 +2419,35 @@
 			nextphys = EHCI_NULL;
 		}
 
-		for (i = 0; i * EHCI_PAGE_SIZE < curlen; i++) {
-			ehci_physaddr_t a = dataphys + i * EHCI_PAGE_SIZE;
-			if (i != 0) /* use offset only in first buffer */
-				a = EHCI_PAGE(a);
-			cur->qtd.qtd_buffer[i] = htole32(a);
-			cur->qtd.qtd_buffer_hi[i] = 0;
-#ifdef DIAGNOSTIC
-			if (i >= EHCI_QTD_NBUFFERS) {
-				printf("ehci_alloc_sqtd_chain: i=%d\n", i);
-				goto nomem;
-			}
-#endif
-		}
 		cur->nextqtd = next;
-		cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys;
+		cur->qtd.qtd_next = nextphys;
+		/* Make sure to stop after a short transfer. */
+		cur->qtd.qtd_altnext = htole32(newinactive->physaddr);
 		cur->qtd.qtd_status =
 		    htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen));
 		cur->xfer = xfer;
 		cur->len = curlen;
-		DPRINTFN(10,("ehci_alloc_sqtd_chain: cbp=0x%08x end=0x%08x\n",
-			    dataphys, dataphys + curlen));
-		/* adjust the toggle based on the number of packets in this
-		   qtd */
-		if (((curlen + mps - 1) / mps) & 1) {
-			tog ^= 1;
-			qtdstatus ^= EHCI_QTD_TOGGLE_MASK;
+		DPRINTFN(10,("ehci_alloc_sqtd_chain: curlen=%d\n", curlen));
+		if (iscontrol) {
+			/*
+			 * adjust the toggle based on the number of packets
+			 * in this qtd
+			 */
+			if ((((curlen + mps - 1) / mps) & 1) || curlen == 0)
+				qtdstatus ^= EHCI_QTD_TOGGLE_MASK;
+		}
+		qtdstatus |= EHCI_QTD_ACTIVE;
+		if (len == 0) {
+			if (!forceshort)
+				break;
+			forceshort = 0;
 		}
-		if (len == 0)
-			break;
 		DPRINTFN(10,("ehci_alloc_sqtd_chain: extend chain\n"));
 		offset += curlen;
-		dataphys = DMAADDR(dma, offset);
 		cur = next;
 	}
 	cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC);
 	*ep = cur;
-	epipe->nexttoggle = tog;
 
 	DPRINTFN(10,("ehci_alloc_sqtd_chain: return sqtd=%p sqtdend=%p\n",
 		     *sp, *ep));
@@ -2445,16 +2460,27 @@
 	return (USBD_NOMEM);
 }
 
-Static void
-ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd,
-		    ehci_soft_qtd_t *sqtdend)
+/* Free the chain starting at sqtd and end at the qTD before sqtdend */
+static void
+ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qh_t *sqh,
+    ehci_soft_qtd_t *sqtd, ehci_soft_qtd_t *sqtdend)
 {
-	ehci_soft_qtd_t *p;
+	ehci_soft_qtd_t *p, **prevp;
 	int i;
 
 	DPRINTFN(10,("ehci_free_sqtd_chain: sqtd=%p sqtdend=%p\n",
 		     sqtd, sqtdend));
 
+	/* First unlink the chain from the QH's software qTD list. */
+	prevp = &sqh->sqtd;
+	for (p = sqh->sqtd; p != NULL; p = p->nextqtd) {
+		if (p == sqtd) {
+			*prevp = sqtdend;
+			break;
+		}
+		prevp = &p->nextqtd;
+	}
+	KASSERT(p != NULL, ("ehci_free_sqtd_chain: chain not found"));
 	for (i = 0; sqtd != sqtdend; sqtd = p, i++) {
 		p = sqtd->nextqtd;
 		ehci_free_sqtd(sc, sqtd);
@@ -2478,9 +2504,9 @@
 	s = splusb();
 	ehci_rem_qh(sc, sqh, head);
 	splx(s);
+	pipe->endpoint->savedtoggle =
+	    EHCI_QTD_GET_TOGGLE(le32toh(sqh->qh.qh_qtd.qtd_status));
 	ehci_free_sqh(sc, epipe->sqh);
-
-	pipe->endpoint->savedtoggle = epipe->nexttoggle;
 }
 
 /*
@@ -2500,10 +2526,10 @@
 	struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;
 	ehci_softc_t *sc = (ehci_softc_t *)epipe->pipe.device->bus;
 	ehci_soft_qh_t *sqh = epipe->sqh;
-	ehci_soft_qtd_t *sqtd, *snext, **psqtd;
+	ehci_soft_qtd_t *sqtd, *snext;
 	ehci_physaddr_t cur, us, next;
 	int s;
-	int hit;
+	int hit, i;
 	/* int count = 0; */
 	ehci_soft_qh_t *psqh;
 
@@ -2513,7 +2539,7 @@
 		/* If we're dying, just do the software part. */
 		s = splusb();
 		xfer->status = status;	/* make software ignore it */
-		usb_uncallout(xfer->timeout_handle, ehci_timeout, xfer);
+		callout_stop(&xfer->timeout_handle);
 		usb_rem_task(epipe->pipe.device, &exfer->abort_task);
 		usb_transfer_complete(xfer);
 		splx(s);
@@ -2547,7 +2573,7 @@
 	s = splusb();
 	exfer->ehci_xfer_flags |= EHCI_XFER_ABORTING;
 	xfer->status = status;	/* make software ignore it */
-	usb_uncallout(xfer->timeout_handle, ehci_timeout, xfer);
+	callout_stop(&xfer->timeout_handle);
 	usb_rem_task(epipe->pipe.device, &exfer->abort_task);
 	splx(s);
 
@@ -2596,13 +2622,12 @@
 
 	/* We will change them to point here */
 	snext = exfer->sqtdend->nextqtd;
-	next = snext ? htole32(snext->physaddr) : EHCI_NULL;
+	next = htole32(snext->physaddr);
 
 	/*
 	 * Now loop through any qTDs before us and keep track of the pointer
 	 * that points to us for the end.
 	 */
-	psqtd = &sqh->sqtd;
 	sqtd = sqh->sqtd;
 	while (sqtd && sqtd != exfer->sqtdstart) {
 		hit |= (cur == sqtd->physaddr);
@@ -2610,11 +2635,8 @@
 			sqtd->qtd.qtd_next = next;
 		if (EHCI_LINK_ADDR(le32toh(sqtd->qtd.qtd_altnext)) == us)
 			sqtd->qtd.qtd_altnext = next;
-		psqtd = &sqtd->nextqtd;
 		sqtd = sqtd->nextqtd;
 	}
-		/* make the software pointer bypass us too */
-	*psqtd = exfer->sqtdend->nextqtd;
 
 	/*
 	 * If we already saw the active one then we are pretty much done.
@@ -2626,14 +2648,11 @@
 		 * Now reinitialise the QH to point to the next qTD
 		 * (if there is one). We only need to do this if
 		 * it was previously pointing to us.
-		 * XXX Not quite sure what to do about the data toggle.
 		 */
-		sqtd = exfer->sqtdstart;
 		for (sqtd = exfer->sqtdstart; ; sqtd = sqtd->nextqtd) {
 			if (cur == sqtd->physaddr) {
 				hit++;
 			}
-			/* count++; */
 			if (sqtd == exfer->sqtdend)
 				break;
 		}
@@ -2643,16 +2662,13 @@
 		 * that we are removing.
 		 */
 		if (hit) {
-			if (snext) {
-				ehci_set_qh_qtd(sqh, snext);
-			} else {
-
-				sqh->qh.qh_curqtd = 0; /* unlink qTDs */
-				sqh->qh.qh_qtd.qtd_status = 0;
-				sqh->qh.qh_qtd.qtd_next =
-				    sqh->qh.qh_qtd.qtd_altnext
-				        = EHCI_NULL;
-				DPRINTFN(1,("ehci_abort_xfer: no hit\n"));
+			sqh->qh.qh_qtd.qtd_next = htole32(snext->physaddr);
+			sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
+			sqh->qh.qh_qtd.qtd_status &=
+			    htole32(EHCI_QTD_TOGGLE_MASK);
+			for (i = 0; i < EHCI_QTD_NBUFFERS; i++) {
+				sqh->qh.qh_qtd.qtd_buffer[i] = 0;
+				sqh->qh.qh_qtd.qtd_buffer_hi[i] = 0;
 			}
 		}
 	}
@@ -2695,7 +2711,8 @@
 	}
 
 	/* Execute the abort in a process context. */
-	usb_add_task(exfer->xfer.pipe->device, &exfer->abort_task);
+	usb_add_task(exfer->xfer.pipe->device, &exfer->abort_task,
+	    USB_TASKQ_HC);
 }
 
 void
@@ -2736,7 +2753,7 @@
 
 /************************/
 
-Static usbd_status
+static usbd_status
 ehci_device_ctrl_transfer(usbd_xfer_handle xfer)
 {
 	usbd_status err;
@@ -2747,10 +2764,10 @@
 		return (err);
 
 	/* Pipe isn't running, start first */
-	return (ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (ehci_device_ctrl_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
-Static usbd_status
+static usbd_status
 ehci_device_ctrl_start(usbd_xfer_handle xfer)
 {
 	ehci_softc_t *sc = (ehci_softc_t *)xfer->pipe->device->bus;
@@ -2781,7 +2798,7 @@
 {
 	struct ehci_xfer *ex = EXFER(xfer);
 	ehci_softc_t *sc = (ehci_softc_t *)xfer->pipe->device->bus;
-	/*struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;*/
+	struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;
 
 	DPRINTFN(10,("ehci_ctrl_done: xfer=%p\n", xfer));
 
@@ -2793,14 +2810,15 @@
 
 	if (xfer->status != USBD_NOMEM && ehci_active_intr_list(ex)) {
 		ehci_del_intr_list(ex);	/* remove from active list */
-		ehci_free_sqtd_chain(sc, ex->sqtdstart, NULL);
+		ehci_free_sqtd_chain(sc, epipe->sqh, ex->sqtdstart,
+		    ex->sqtdend->nextqtd);
 	}
 
 	DPRINTFN(5, ("ehci_ctrl_done: length=%d\n", xfer->actlen));
 }
 
 /* Abort a device control request. */
-Static void
+static void
 ehci_device_ctrl_abort(usbd_xfer_handle xfer)
 {
 	DPRINTF(("ehci_device_ctrl_abort: xfer=%p\n", xfer));
@@ -2808,7 +2826,7 @@
 }
 
 /* Close a device control pipe. */
-Static void
+static void
 ehci_device_ctrl_close(usbd_pipe_handle pipe)
 {
 	ehci_softc_t *sc = (ehci_softc_t *)pipe->device->bus;
@@ -2826,8 +2844,7 @@
 	usb_device_request_t *req = &xfer->request;
 	usbd_device_handle dev = epipe->pipe.device;
 	ehci_softc_t *sc = (ehci_softc_t *)dev->bus;
-	int addr = dev->address;
-	ehci_soft_qtd_t *setup, *stat, *next;
+	ehci_soft_qtd_t *newinactive, *setup, *stat, *next;
 	ehci_soft_qh_t *sqh;
 	int isread;
 	int len;
@@ -2840,14 +2857,17 @@
 	DPRINTFN(3,("ehci_device_request: type=0x%02x, request=0x%02x, "
 		    "wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n",
 		    req->bmRequestType, req->bRequest, UGETW(req->wValue),
-		    UGETW(req->wIndex), len, addr,
+		    UGETW(req->wIndex), len, dev->address,
 		    epipe->pipe.endpoint->edesc->bEndpointAddress));
 
-	setup = ehci_alloc_sqtd(sc);
-	if (setup == NULL) {
+	newinactive = ehci_alloc_sqtd(sc);
+	if (newinactive == NULL) {
 		err = USBD_NOMEM;
 		goto bad1;
 	}
+	newinactive->qtd.qtd_status = htole32(0);
+	newinactive->qtd.qtd_next = EHCI_NULL;
+	newinactive->qtd.qtd_altnext = EHCI_NULL;
 	stat = ehci_alloc_sqtd(sc);
 	if (stat == NULL) {
 		err = USBD_NOMEM;
@@ -2855,42 +2875,30 @@
 	}
 
 	sqh = epipe->sqh;
+	setup = sqh->inactivesqtd;
+	sqh->inactivesqtd = newinactive;
 	epipe->u.ctl.length = len;
 
-	/* Update device address and length since they may have changed
-	   during the setup of the control pipe in usbd_new_device(). */
-	/* XXX This only needs to be done once, but it's too early in open. */
-	/* XXXX Should not touch ED here! */
-	sqh->qh.qh_endp =
-	    (sqh->qh.qh_endp & htole32(~(EHCI_QH_ADDRMASK | EHCI_QH_MPLMASK))) |
-	    htole32(
-	     EHCI_QH_SET_ADDR(addr) |
-	     EHCI_QH_SET_MPL(UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize))
-	    );
-
 	/* Set up data transaction */
 	if (len != 0) {
 		ehci_soft_qtd_t *end;
 
-		/* Start toggle at 1. */
-		epipe->nexttoggle = 1;
 		err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
-			  &next, &end);
+		    NULL, newinactive, &next, &end);
 		if (err)
 			goto bad3;
 		end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC);
 		end->nextqtd = stat;
-		end->qtd.qtd_next =
-		end->qtd.qtd_altnext = htole32(stat->physaddr);
+		end->qtd.qtd_next = htole32(stat->physaddr);
+		end->qtd.qtd_altnext = htole32(newinactive->physaddr);
 	} else {
 		next = stat;
 	}
 
 	memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof *req);
 
-	/* Clear toggle */
+	/* Clear toggle, and do not activate until complete */
 	setup->qtd.qtd_status = htole32(
-	    EHCI_QTD_ACTIVE |
 	    EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) |
 	    EHCI_QTD_SET_CERR(3) |
 	    EHCI_QTD_SET_TOGGLE(0) |
@@ -2899,7 +2907,8 @@
 	setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0));
 	setup->qtd.qtd_buffer_hi[0] = 0;
 	setup->nextqtd = next;
-	setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr);
+	setup->qtd.qtd_next = htole32(next->physaddr);
+	setup->qtd.qtd_altnext = htole32(newinactive->physaddr);
 	setup->xfer = xfer;
 	setup->len = sizeof *req;
 
@@ -2912,8 +2921,9 @@
 	    );
 	stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */
 	stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */
-	stat->nextqtd = NULL;
-	stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL;
+	stat->nextqtd = newinactive;
+	stat->qtd.qtd_next = htole32(newinactive->physaddr);
+	stat->qtd.qtd_altnext = htole32(newinactive->physaddr);
 	stat->xfer = xfer;
 	stat->len = 0;
 
@@ -2934,12 +2944,12 @@
 	exfer->isdone = 0;
 #endif
 
-	/* Insert qTD in QH list. */
+	/* Activate the new qTD in the QH list. */
 	s = splusb();
-	ehci_set_qh_qtd(sqh, setup);
+	ehci_activate_qh(sqh, setup);
 	if (xfer->timeout && !sc->sc_bus.use_polling) {
-                usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
-			    ehci_timeout, xfer);
+                callout_reset(&xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
+		    ehci_timeout, xfer);
 	}
 	ehci_add_intr_list(sc, exfer);
 	xfer->status = USBD_IN_PROGRESS;
@@ -2960,9 +2970,10 @@
 	return (USBD_NORMAL_COMPLETION);
 
  bad3:
+	sqh->inactivesqtd = setup;
 	ehci_free_sqtd(sc, stat);
  bad2:
-	ehci_free_sqtd(sc, setup);
+	ehci_free_sqtd(sc, newinactive);
  bad1:
 	DPRINTFN(-1,("ehci_device_request: no memory\n"));
 	xfer->status = err;
@@ -2973,7 +2984,7 @@
 
 /************************/
 
-Static usbd_status
+static usbd_status
 ehci_device_bulk_transfer(usbd_xfer_handle xfer)
 {
 	usbd_status err;
@@ -2984,7 +2995,7 @@
 		return (err);
 
 	/* Pipe isn't running, start first */
-	return (ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (ehci_device_bulk_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
 usbd_status
@@ -2994,7 +3005,7 @@
 	struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;
 	usbd_device_handle dev = epipe->pipe.device;
 	ehci_softc_t *sc = (ehci_softc_t *)dev->bus;
-	ehci_soft_qtd_t *data, *dataend;
+	ehci_soft_qtd_t *data, *dataend, *newinactive;
 	ehci_soft_qh_t *sqh;
 	usbd_status err;
 	int len, isread, endpt;
@@ -3018,14 +3029,30 @@
 
 	epipe->u.bulk.length = len;
 
-	err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data,
-				   &dataend);
+	newinactive = ehci_alloc_sqtd(sc);
+	if (newinactive == NULL) {
+		DPRINTFN(-1,("ehci_device_bulk_start: no sqtd memory\n"));
+		err = USBD_NOMEM;
+		xfer->status = err;
+		usb_transfer_complete(xfer);
+		return (err);
+	}
+	newinactive->qtd.qtd_status = htole32(0);
+	newinactive->qtd.qtd_next = EHCI_NULL;
+	newinactive->qtd.qtd_altnext = EHCI_NULL;
+	err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
+	    sqh->inactivesqtd, newinactive, &data, &dataend);
 	if (err) {
 		DPRINTFN(-1,("ehci_device_bulk_start: no memory\n"));
+		ehci_free_sqtd(sc, newinactive);
 		xfer->status = err;
 		usb_transfer_complete(xfer);
 		return (err);
 	}
+	dataend->nextqtd = newinactive;
+	dataend->qtd.qtd_next = htole32(newinactive->physaddr);
+	dataend->qtd.qtd_altnext = htole32(newinactive->physaddr);
+	sqh->inactivesqtd = newinactive;
 
 #ifdef EHCI_DEBUG
 	if (ehcidebug > 5) {
@@ -3046,10 +3073,10 @@
 #endif
 
 	s = splusb();
-	ehci_set_qh_qtd(sqh, data);
+	ehci_activate_qh(sqh, data);
 	if (xfer->timeout && !sc->sc_bus.use_polling) {
-		usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
-			    ehci_timeout, xfer);
+		callout_reset(&xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
+		    ehci_timeout, xfer);
 	}
 	ehci_add_intr_list(sc, exfer);
 	xfer->status = USBD_IN_PROGRESS;
@@ -3078,7 +3105,7 @@
 #undef exfer
 }
 
-Static void
+static void
 ehci_device_bulk_abort(usbd_xfer_handle xfer)
 {
 	DPRINTF(("ehci_device_bulk_abort: xfer=%p\n", xfer));
@@ -3088,7 +3115,7 @@
 /*
  * Close a device bulk pipe.
  */
-Static void
+static void
 ehci_device_bulk_close(usbd_pipe_handle pipe)
 {
 	ehci_softc_t *sc = (ehci_softc_t *)pipe->device->bus;
@@ -3102,14 +3129,15 @@
 {
 	struct ehci_xfer *ex = EXFER(xfer);
 	ehci_softc_t *sc = (ehci_softc_t *)xfer->pipe->device->bus;
-	/*struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;*/
+	struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;
 
 	DPRINTFN(10,("ehci_bulk_done: xfer=%p, actlen=%d\n",
 		     xfer, xfer->actlen));
 
 	if (xfer->status != USBD_NOMEM && ehci_active_intr_list(ex)) {
 		ehci_del_intr_list(ex);	/* remove from active list */
-		ehci_free_sqtd_chain(sc, ex->sqtdstart, NULL);
+		ehci_free_sqtd_chain(sc, epipe->sqh, ex->sqtdstart,
+		    ex->sqtdend->nextqtd);
 	}
 
 	DPRINTFN(5, ("ehci_bulk_done: length=%d\n", xfer->actlen));
@@ -3117,7 +3145,7 @@
 
 /************************/
 
-Static usbd_status
+static usbd_status
 ehci_device_setintr(ehci_softc_t *sc, ehci_soft_qh_t *sqh, int ival)
 {
 	struct ehci_soft_islot *isp;
@@ -3139,7 +3167,7 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static usbd_status
+static usbd_status
 ehci_device_intr_transfer(usbd_xfer_handle xfer)
 {
 	usbd_status err;
@@ -3153,17 +3181,17 @@
 	 * Pipe isn't running (otherwise err would be USBD_INPROG),
 	 * so start it first.
 	 */
-	return (ehci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (ehci_device_intr_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
-Static usbd_status
+static usbd_status
 ehci_device_intr_start(usbd_xfer_handle xfer)
 {
 #define exfer EXFER(xfer)
 	struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;
 	usbd_device_handle dev = xfer->pipe->device;
 	ehci_softc_t *sc = (ehci_softc_t *)dev->bus;
-	ehci_soft_qtd_t *data, *dataend;
+	ehci_soft_qtd_t *data, *dataend, *newinactive;
 	ehci_soft_qh_t *sqh;
 	usbd_status err;
 	int len, isread, endpt;
@@ -3187,14 +3215,29 @@
 
 	epipe->u.intr.length = len;
 
-	err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data,
-	    &dataend);
+	newinactive = ehci_alloc_sqtd(sc);
+	if (newinactive == NULL) {
+		DPRINTFN(-1,("ehci_device_intr_start: no sqtd memory\n"));
+		err = USBD_NOMEM;
+		xfer->status = err;
+		usb_transfer_complete(xfer);
+		return (err);
+	}
+	newinactive->qtd.qtd_status = htole32(0);
+	newinactive->qtd.qtd_next = EHCI_NULL;
+	newinactive->qtd.qtd_altnext = EHCI_NULL;
+	err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
+	    sqh->inactivesqtd, newinactive, &data, &dataend);
 	if (err) {
 		DPRINTFN(-1, ("ehci_device_intr_start: no memory\n"));
 		xfer->status = err;
 		usb_transfer_complete(xfer);
 		return (err);
 	}
+	dataend->nextqtd = newinactive;
+	dataend->qtd.qtd_next = htole32(newinactive->physaddr);
+	dataend->qtd.qtd_altnext = htole32(newinactive->physaddr);
+	sqh->inactivesqtd = newinactive;
 
 #ifdef EHCI_DEBUG
 	if (ehcidebug > 5) {
@@ -3215,9 +3258,9 @@
 #endif
 
 	s = splusb();
-	ehci_set_qh_qtd(sqh, data);
+	ehci_activate_qh(sqh, data);
 	if (xfer->timeout && !sc->sc_bus.use_polling) {
-		usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
+		callout_reset(&xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
 		    ehci_timeout, xfer);
 	}
 	ehci_add_intr_list(sc, exfer);
@@ -3243,7 +3286,7 @@
 #undef exfer
 }
 
-Static void
+static void
 ehci_device_intr_abort(usbd_xfer_handle xfer)
 {
 	DPRINTFN(1, ("ehci_device_intr_abort: xfer=%p\n", xfer));
@@ -3254,7 +3297,7 @@
 	ehci_abort_xfer(xfer, USBD_CANCELLED);
 }
 
-Static void
+static void
 ehci_device_intr_close(usbd_pipe_handle pipe)
 {
 	ehci_softc_t *sc = (ehci_softc_t *)pipe->device->bus;
@@ -3265,14 +3308,14 @@
 	ehci_close_pipe(pipe, isp->sqh);
 }
 
-Static void
+static void
 ehci_device_intr_done(usbd_xfer_handle xfer)
 {
 #define exfer EXFER(xfer)
 	struct ehci_xfer *ex = EXFER(xfer);
 	ehci_softc_t *sc = (ehci_softc_t *)xfer->pipe->device->bus;
 	struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;
-	ehci_soft_qtd_t *data, *dataend;
+	ehci_soft_qtd_t *data, *dataend, *newinactive;
 	ehci_soft_qh_t *sqh;
 	usbd_status err;
 	int len, isread, endpt, s;
@@ -3280,22 +3323,38 @@
 	DPRINTFN(10, ("ehci_device_intr_done: xfer=%p, actlen=%d\n",
 	    xfer, xfer->actlen));
 
+	sqh = epipe->sqh;
 	if (xfer->pipe->repeat) {
-		ehci_free_sqtd_chain(sc, ex->sqtdstart, NULL);
+		ehci_free_sqtd_chain(sc, sqh, ex->sqtdstart,
+		    ex->sqtdend->nextqtd);
 
 		len = epipe->u.intr.length;
 		xfer->length = len;
 		endpt = epipe->pipe.endpoint->edesc->bEndpointAddress;
 		isread = UE_GET_DIR(endpt) == UE_DIR_IN;
-		sqh = epipe->sqh;
 
+		newinactive = ehci_alloc_sqtd(sc);
+		if (newinactive == NULL) {
+			DPRINTFN(-1,
+			    ("ehci_device_intr_done: no sqtd memory\n"));
+			err = USBD_NOMEM;
+			xfer->status = err;
+			return;
+		}
+		newinactive->qtd.qtd_status = htole32(0);
+		newinactive->qtd.qtd_next = EHCI_NULL;
+		newinactive->qtd.qtd_altnext = EHCI_NULL;
 		err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
-		    &data, &dataend);
+		    sqh->inactivesqtd, newinactive, &data, &dataend);
 		if (err) {
 			DPRINTFN(-1, ("ehci_device_intr_done: no memory\n"));
 			xfer->status = err;
 			return;
 		}
+		dataend->nextqtd = newinactive;
+		dataend->qtd.qtd_next = htole32(newinactive->physaddr);
+		dataend->qtd.qtd_altnext = htole32(newinactive->physaddr);
+		sqh->inactivesqtd = newinactive;
 
 		/* Set up interrupt info. */
 		exfer->sqtdstart = data;
@@ -3309,9 +3368,9 @@
 #endif
 
 		s = splusb();
-		ehci_set_qh_qtd(sqh, data);
+		ehci_activate_qh(sqh, data);
 		if (xfer->timeout && !sc->sc_bus.use_polling) {
-			usb_callout(xfer->timeout_handle,
+			callout_reset(&xfer->timeout_handle,
 			    MS_TO_TICKS(xfer->timeout), ehci_timeout, xfer);
 		}
 		splx(s);
@@ -3319,15 +3378,16 @@
 		xfer->status = USBD_IN_PROGRESS;
 	} else if (xfer->status != USBD_NOMEM && ehci_active_intr_list(ex)) {
 		ehci_del_intr_list(ex); /* remove from active list */
-		ehci_free_sqtd_chain(sc, ex->sqtdstart, NULL);
+		ehci_free_sqtd_chain(sc, sqh, ex->sqtdstart,
+		    ex->sqtdend->nextqtd);
 	}
 #undef exfer
 }
 
 /************************/
 
-Static usbd_status	ehci_device_isoc_transfer(usbd_xfer_handle xfer) { return USBD_IOERROR; }
-Static usbd_status	ehci_device_isoc_start(usbd_xfer_handle xfer) { return USBD_IOERROR; }
-Static void		ehci_device_isoc_abort(usbd_xfer_handle xfer) { }
-Static void		ehci_device_isoc_close(usbd_pipe_handle pipe) { }
-Static void		ehci_device_isoc_done(usbd_xfer_handle xfer) { }
+static usbd_status	ehci_device_isoc_transfer(usbd_xfer_handle xfer) { return USBD_IOERROR; }
+static usbd_status	ehci_device_isoc_start(usbd_xfer_handle xfer) { return USBD_IOERROR; }
+static void		ehci_device_isoc_abort(usbd_xfer_handle xfer) { }
+static void		ehci_device_isoc_close(usbd_pipe_handle pipe) { }
+static void		ehci_device_isoc_done(usbd_xfer_handle xfer) { }
Index: usbdi_util.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usbdi_util.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usbdi_util.c -L sys/dev/usb/usbdi_util.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usbdi_util.c
+++ sys/dev/usb/usbdi_util.c
@@ -38,19 +38,14 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/usbdi_util.c,v 1.34 2005/03/01 08:01:22 sobomax Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/usbdi_util.c,v 1.38 2007/06/20 05:10:54 imp Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/proc.h>
-#include <sys/device.h>
-#elif defined(__FreeBSD__)
 #include <sys/bus.h>
-#endif
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbhid.h>
@@ -59,8 +54,8 @@
 #include <dev/usb/usbdi_util.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (usbdebug) logprintf x
-#define DPRINTFN(n,x)	if (usbdebug>(n)) logprintf x
+#define DPRINTF(x)	if (usbdebug) printf x
+#define DPRINTFN(n,x)	if (usbdebug>(n)) printf x
 extern int usbdebug;
 #else
 #define DPRINTF(x)
@@ -384,7 +379,7 @@
 
 usbd_status
 usbd_read_report_desc(usbd_interface_handle ifc, void **descp, int *sizep,
-		      usb_malloc_type mem)
+		      struct malloc_type *mem)
 {
 	usb_interface_descriptor_t *id;
 	usb_hid_descriptor_t *hid;
@@ -425,9 +420,9 @@
 	return (usbd_do_request(dev, &req, conf));
 }
 
-Static void usbd_bulk_transfer_cb(usbd_xfer_handle xfer,
+static void usbd_bulk_transfer_cb(usbd_xfer_handle xfer,
 				  usbd_private_handle priv, usbd_status status);
-Static void
+static void
 usbd_bulk_transfer_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
 		      usbd_status status)
 {
@@ -467,9 +462,9 @@
 	return (err);
 }
 
-Static void usbd_intr_transfer_cb(usbd_xfer_handle xfer,
+static void usbd_intr_transfer_cb(usbd_xfer_handle xfer,
 				  usbd_private_handle priv, usbd_status status);
-Static void
+static void
 usbd_intr_transfer_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
 		      usbd_status status)
 {
@@ -510,19 +505,19 @@
 }
 
 void
-usb_detach_wait(device_ptr_t dv)
+usb_detach_wait(device_t dv)
 {
-	DPRINTF(("usb_detach_wait: waiting for %s\n", USBDEVPTRNAME(dv)));
+	DPRINTF(("usb_detach_wait: waiting for %s\n", device_get_nameunit(dv)));
 	if (tsleep(dv, PZERO, "usbdet", hz * 60))
 		printf("usb_detach_wait: %s didn't detach\n",
-		        USBDEVPTRNAME(dv));
-	DPRINTF(("usb_detach_wait: %s done\n", USBDEVPTRNAME(dv)));
+		        device_get_nameunit(dv));
+	DPRINTF(("usb_detach_wait: %s done\n", device_get_nameunit(dv)));
 }
 
 void
-usb_detach_wakeup(device_ptr_t dv)
+usb_detach_wakeup(device_t dv)
 {
-	DPRINTF(("usb_detach_wakeup: for %s\n", USBDEVPTRNAME(dv)));
+	DPRINTF(("usb_detach_wakeup: for %s\n", device_get_nameunit(dv)));
 	wakeup(dv);
 }
 
Index: hid.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/hid.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/usb/hid.c -L sys/dev/usb/hid.c -u -r1.2 -r1.3
--- sys/dev/usb/hid.c
+++ sys/dev/usb/hid.c
@@ -2,7 +2,7 @@
 
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/hid.c,v 1.25.2.1 2006/03/25 04:46:52 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/hid.c,v 1.29 2007/06/20 05:10:52 imp Exp $");
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -42,9 +42,6 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#if defined(__NetBSD__)
-#include <sys/kernel.h>
-#endif
 #include <sys/malloc.h>
 
 #include <dev/usb/usb.h>
@@ -53,15 +50,15 @@
 #include <dev/usb/hid.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (usbdebug) logprintf x
-#define DPRINTFN(n,x)	if (usbdebug>(n)) logprintf x
+#define DPRINTF(x)	if (usbdebug) printf x
+#define DPRINTFN(n,x)	if (usbdebug>(n)) printf x
 extern int usbdebug;
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n,x)
 #endif
 
-Static void hid_clear_local(struct hid_item *);
+static void hid_clear_local(struct hid_item *);
 
 #define MAXUSAGE 100
 struct hid_data {
@@ -77,7 +74,7 @@
 	int kindset;
 };
 
-Static void
+static void
 hid_clear_local(struct hid_item *c)
 {
 
Index: usb.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usb.c -L sys/dev/usb/usb.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usb.c
+++ sys/dev/usb/usb.c
@@ -8,7 +8,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/usb.c,v 1.106 2005/03/27 15:31:23 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/usb.c,v 1.120 2007/06/20 05:10:53 imp Exp $");
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -58,28 +58,18 @@
 #include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
-#if __FreeBSD_version >= 500000
 #include <sys/mutex.h>
-#endif
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#elif defined(__FreeBSD__)
 #include <sys/unistd.h>
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/fcntl.h>
 #include <sys/filio.h>
 #include <sys/uio.h>
-#endif
 #include <sys/kthread.h>
 #include <sys/proc.h>
 #include <sys/conf.h>
 #include <sys/poll.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/signalvar.h>
 #include <sys/sysctl.h>
 #include <sys/uio.h>
@@ -91,13 +81,11 @@
 #define USBUNIT(d)	(minor(d))	/* usb_discover device nodes, kthread */
 #define USB_DEV_MINOR	255		/* event queue device */
 
-#if defined(__FreeBSD__)
 MALLOC_DEFINE(M_USB, "USB", "USB");
 MALLOC_DEFINE(M_USBDEV, "USBdev", "USB device");
 MALLOC_DEFINE(M_USBHC, "USBHC", "USB host controller");
 
 #include "usb_if.h"
-#endif /* defined(__FreeBSD__) */
 
 #include <machine/bus.h>
 
@@ -110,8 +98,8 @@
 SYSCTL_NODE(_hw, OID_AUTO, usb, CTLFLAG_RW, 0, "USB debugging");
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (usbdebug) logprintf x
-#define DPRINTFN(n,x)	if (usbdebug>(n)) logprintf x
+#define DPRINTF(x)	if (usbdebug) printf x
+#define DPRINTFN(n,x)	if (usbdebug>(n)) printf x
 int	usbdebug = 0;
 SYSCTL_INT(_hw_usb, OID_AUTO, debug, CTLFLAG_RW,
 	   &usbdebug, 0, "usb debug level");
@@ -127,11 +115,9 @@
 #endif
 
 struct usb_softc {
-	USBBASEDEVICE	sc_dev;		/* base device */
-#ifdef __FreeBSD__
+	device_t	sc_dev;		/* base device */
 	struct cdev	*sc_usbdev;	/* /dev/usbN device */
 	TAILQ_ENTRY(usb_softc) sc_coldexplist; /* cold needs-explore list */
-#endif
 	usbd_bus_handle sc_bus;		/* USB controller */
 	struct usbd_port sc_port;	/* dummy port for root hub */
 
@@ -140,11 +126,15 @@
 	char		sc_dying;
 };
 
-TAILQ_HEAD(, usb_task) usb_all_tasks;
+struct usb_taskq {
+	TAILQ_HEAD(, usb_task) tasks;
+	struct proc *task_thread_proc;
+	const char *name;
+	int taskcreated;		/* task thread exists. */
+};
+
+static struct usb_taskq usb_taskq[USB_NUM_TASKQS];
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-cdev_decl(usb);
-#elif defined(__FreeBSD__)
 d_open_t  usbopen;
 d_close_t usbclose;
 d_read_t usbread;
@@ -160,72 +150,82 @@
 	.d_ioctl =	usbioctl,
 	.d_poll =	usbpoll,
 	.d_name =	"usb",
-#if __FreeBSD_version < 500014
-	.d_bmaj =	-1
-#endif
 };
-#endif
 
-Static void	usb_discover(void *);
-#ifdef __FreeBSD__
-Static bus_child_detached_t usb_child_detached;
-#endif
-Static void	usb_create_event_thread(void *);
-Static void	usb_event_thread(void *);
-Static void	usb_task_thread(void *);
-Static struct proc *usb_task_thread_proc = NULL;
-
-#ifdef __FreeBSD__
-Static struct cdev *usb_dev;		/* The /dev/usb device. */
-Static int usb_ndevs;			/* Number of /dev/usbN devices. */
-Static int usb_taskcreated;		/* USB task thread exists. */
+static void	usb_discover(void *);
+static void	usb_create_event_thread(void *);
+static void	usb_event_thread(void *);
+static void	usb_task_thread(void *);
+
+static struct cdev *usb_dev;		/* The /dev/usb device. */
+static int usb_ndevs;			/* Number of /dev/usbN devices. */
 /* Busses to explore at the end of boot-time device configuration. */
-Static TAILQ_HEAD(, usb_softc) usb_coldexplist =
+static TAILQ_HEAD(, usb_softc) usb_coldexplist =
     TAILQ_HEAD_INITIALIZER(usb_coldexplist);
-#endif
 
 #define USB_MAX_EVENTS 100
 struct usb_event_q {
 	struct usb_event ue;
 	TAILQ_ENTRY(usb_event_q) next;
 };
-Static TAILQ_HEAD(, usb_event_q) usb_events =
+static TAILQ_HEAD(, usb_event_q) usb_events =
 	TAILQ_HEAD_INITIALIZER(usb_events);
-Static int usb_nevents = 0;
-Static struct selinfo usb_selevent;
-Static struct proc *usb_async_proc;  /* process that wants USB SIGIO */
-Static int usb_dev_open = 0;
-Static void usb_add_event(int, struct usb_event *);
-
-Static int usb_get_next_event(struct usb_event *);
-
-Static const char *usbrev_str[] = USBREV_STR;
-
-USB_DECLARE_DRIVER_INIT(usb,
-			DEVMETHOD(bus_child_detached, usb_child_detached),
-			DEVMETHOD(device_suspend, bus_generic_suspend),
-			DEVMETHOD(device_resume, bus_generic_resume),
-			DEVMETHOD(device_shutdown, bus_generic_shutdown)
-			);
+static int usb_nevents = 0;
+static struct selinfo usb_selevent;
+static struct proc *usb_async_proc;  /* process that wants USB SIGIO */
+static int usb_dev_open = 0;
+static void usb_add_event(int, struct usb_event *);
+
+static int usb_get_next_event(struct usb_event *);
+
+static const char *usbrev_str[] = USBREV_STR;
+
+static device_probe_t usb_match;
+static device_attach_t usb_attach;
+static device_detach_t usb_detach;
+static bus_child_detached_t usb_child_detached;
+
+static device_method_t usb_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		usb_match),
+	DEVMETHOD(device_attach,	usb_attach),
+	DEVMETHOD(device_detach,	usb_detach),
+	DEVMETHOD(device_suspend,	bus_generic_suspend),
+	DEVMETHOD(device_resume,	bus_generic_resume),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+
+	/* Bus interface */
+	DEVMETHOD(bus_child_detached,	usb_child_detached),
+
+	{ 0, 0 }
+};
 
-#if defined(__FreeBSD__)
+static driver_t usb_driver = {
+	"usb",
+	usb_methods,
+	sizeof(struct usb_softc)
+};
+
+static devclass_t usb_devclass;
+
+DRIVER_MODULE(usb, ohci, usb_driver, usb_devclass, 0, 0);
+DRIVER_MODULE(usb, uhci, usb_driver, usb_devclass, 0, 0);
+DRIVER_MODULE(usb, ehci, usb_driver, usb_devclass, 0, 0);
+DRIVER_MODULE(usb, slhci, usb_driver, usb_devclass, 0, 0);
 MODULE_VERSION(usb, 1);
-#endif
 
-USB_MATCH(usb)
+static int
+usb_match(device_t self)
 {
 	DPRINTF(("usbd_match\n"));
 	return (UMATCH_GENERIC);
 }
 
-USB_ATTACH(usb)
+static int
+usb_attach(device_t self)
 {
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	struct usb_softc *sc = (struct usb_softc *)self;
-#elif defined(__FreeBSD__)
 	struct usb_softc *sc = device_get_softc(self);
 	void *aux = device_get_ivars(self);
-#endif
 	usbd_device_handle dev;
 	usbd_status err;
 	int usbrev;
@@ -241,9 +241,7 @@
 	sc->sc_bus->usbctl = sc;
 	sc->sc_port.power = USB_MAX_POWER;
 
-#if defined(__FreeBSD__)
-	printf("%s", USBDEVNAME(sc->sc_dev));
-#endif
+	printf("%s", device_get_nameunit(sc->sc_dev));
 	usbrev = sc->sc_bus->usbrev;
 	printf(": USB revision %s", usbrev_str[usbrev]);
 	switch (usbrev) {
@@ -257,7 +255,7 @@
 	default:
 		printf(", not supported\n");
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 	printf("\n");
 
@@ -265,7 +263,7 @@
 	if (cold)
 		sc->sc_bus->use_polling++;
 
-	ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev);
+	ue.u.ue_ctrlr.ue_bus = device_get_unit(sc->sc_dev);
 	usb_add_event(USB_EVENT_CTRLR_ATTACH, &ue);
 
 #ifdef USB_USE_SOFTINTR
@@ -274,24 +272,24 @@
 	sc->sc_bus->soft = softintr_establish(IPL_SOFTNET,
 	    sc->sc_bus->methods->soft_intr, sc->sc_bus);
 	if (sc->sc_bus->soft == NULL) {
-		printf("%s: can't register softintr\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: can't register softintr\n", device_get_nameunit(sc->sc_dev));
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 #else
 	usb_callout_init(sc->sc_bus->softi);
 #endif
 #endif
 
-	err = usbd_new_device(USBDEV(sc->sc_dev), sc->sc_bus, 0, speed, 0,
+	err = usbd_new_device(sc->sc_dev, sc->sc_bus, 0, speed, 0,
 		  &sc->sc_port);
 	if (!err) {
 		dev = sc->sc_port.device;
 		if (dev->hub == NULL) {
 			sc->sc_dying = 1;
 			printf("%s: root device is not a hub\n",
-			       USBDEVNAME(sc->sc_dev));
-			USB_ATTACH_ERROR_RETURN;
+			       device_get_nameunit(sc->sc_dev));
+			return ENXIO;
 		}
 		sc->sc_bus->root_hub = dev;
 #if 1
@@ -300,7 +298,6 @@
 		 * until the USB event thread is running, which means that
 		 * the keyboard will not work until after cold boot.
 		 */
-#if defined(__FreeBSD__)
 		if (cold) {
 			/* Explore high-speed busses before others. */
 			if (speed == USB_SPEED_HIGH)
@@ -309,25 +306,16 @@
 				TAILQ_INSERT_TAIL(&usb_coldexplist, sc,
 				    sc_coldexplist);
 		}
-#else
-		if (cold && (sc->sc_dev.dv_cfdata->cf_flags & 1))
-			dev->hub->explore(sc->sc_bus->root_hub);
-#endif
 #endif
 	} else {
 		printf("%s: root hub problem, error=%d\n",
-		       USBDEVNAME(sc->sc_dev), err);
+		       device_get_nameunit(sc->sc_dev), err);
 		sc->sc_dying = 1;
 	}
 	if (cold)
 		sc->sc_bus->use_polling--;
 
-	config_pending_incr();
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	usb_kthread_create(usb_create_event_thread, sc);
-#endif
-
-#if defined(__FreeBSD__)
+	/* XXX really do right config_pending_incr(); */
 	usb_create_event_thread(sc);
 	/* The per controller devices (used for usb_discover) */
 	/* XXX This is redundant now, but old usbd's will want it */
@@ -338,29 +326,37 @@
 		usb_dev = make_dev(&usb_cdevsw, USB_DEV_MINOR, UID_ROOT,
 		    GID_OPERATOR, 0660, "usb");
 	}
-#endif
-
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
+static const char *taskq_names[] = USB_TASKQ_NAMES;
+
 void
 usb_create_event_thread(void *arg)
 {
 	struct usb_softc *sc = arg;
+	struct usb_taskq *taskq;
+	int i;
 
-	if (usb_kthread_create1(usb_event_thread, sc, &sc->sc_event_thread,
-			   "%s", USBDEVNAME(sc->sc_dev))) {
+	if (kthread_create(usb_event_thread, sc, &sc->sc_event_thread,
+	      RFHIGHPID, 0, device_get_nameunit(sc->sc_dev))) {
 		printf("%s: unable to create event thread for\n",
-		       USBDEVNAME(sc->sc_dev));
+		       device_get_nameunit(sc->sc_dev));
 		panic("usb_create_event_thread");
 	}
-	if (usb_taskcreated == 0) {
-		usb_taskcreated = 1;
-		TAILQ_INIT(&usb_all_tasks);
-		if (usb_kthread_create2(usb_task_thread, NULL,
-					&usb_task_thread_proc, "usbtask")) {
-			printf("unable to create task thread\n");
-			panic("usb_create_event_thread task");
+	for (i = 0; i < USB_NUM_TASKQS; i++) {
+		taskq = &usb_taskq[i];
+
+		if (taskq->taskcreated == 0) {
+			taskq->taskcreated = 1;
+			taskq->name = taskq_names[i];
+			TAILQ_INIT(&taskq->tasks);
+			if (kthread_create(usb_task_thread, taskq,
+			    &taskq->task_thread_proc, RFHIGHPID, 0,
+			    taskq->name)) {
+				printf("unable to create task thread\n");
+				panic("usb_create_event_thread task");
+			}
 		}
 	}
 }
@@ -371,31 +367,35 @@
  * context ASAP.
  */
 void
-usb_add_task(usbd_device_handle dev, struct usb_task *task)
+usb_add_task(usbd_device_handle dev, struct usb_task *task, int queue)
 {
+	struct usb_taskq *taskq;
 	int s;
 
 	s = splusb();
-	if (!task->onqueue) {
+	taskq = &usb_taskq[queue];
+	if (task->queue == -1) {
 		DPRINTFN(2,("usb_add_task: task=%p\n", task));
-		TAILQ_INSERT_TAIL(&usb_all_tasks, task, next);
-		task->onqueue = 1;
+		TAILQ_INSERT_TAIL(&taskq->tasks, task, next);
+		task->queue = queue;
 	} else {
 		DPRINTFN(3,("usb_add_task: task=%p on q\n", task));
 	}
-	wakeup(&usb_all_tasks);
+	wakeup(&taskq->tasks);
 	splx(s);
 }
 
 void
 usb_rem_task(usbd_device_handle dev, struct usb_task *task)
 {
+	struct usb_taskq *taskq;
 	int s;
 
 	s = splusb();
-	if (task->onqueue) {
-		TAILQ_REMOVE(&usb_all_tasks, task, next);
-		task->onqueue = 0;
+	if (task->queue != -1) {
+		taskq = &usb_taskq[task->queue];
+		TAILQ_REMOVE(&taskq->tasks, task, next);
+		task->queue = -1;
 	}
 	splx(s);
 }
@@ -403,28 +403,35 @@
 void
 usb_event_thread(void *arg)
 {
+	static int newthread_wchan;
 	struct usb_softc *sc = arg;
 
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
 	mtx_lock(&Giant);
-#endif
 
 	DPRINTF(("usb_event_thread: start\n"));
 
 	/*
 	 * In case this controller is a companion controller to an
 	 * EHCI controller we need to wait until the EHCI controller
-	 * has grabbed the port.
-	 * XXX It would be nicer to do this with a tsleep(), but I don't
-	 * know how to synchronize the creation of the threads so it
-	 * will work.
+	 * has grabbed the port. What we do here is wait until no new
+	 * USB threads have been created in a while. XXX we actually
+	 * just want to wait for the PCI slot to be fully scanned.
+	 *
+	 * Note that when you `kldload usb' it actually attaches the
+	 * devices in order that the drivers appear in the kld, not the
+	 * normal PCI order, since the addition of each driver within
+	 * usb.ko (ohci, ehci etc.) causes a separate PCI bus re-scan.
 	 */
-	usb_delay_ms(sc->sc_bus, 500);
+	wakeup(&newthread_wchan);
+	for (;;) {
+		if (tsleep(&newthread_wchan , PWAIT, "usbets", hz * 4) != 0)
+			break;
+	}
 
 	/* Make sure first discover does something. */
 	sc->sc_bus->needs_explore = 1;
 	usb_discover(sc);
-	config_pending_decr();
+	/* XXX really do right config_pending_decr(); */
 
 	while (!sc->sc_dying) {
 #ifdef USB_DEBUG
@@ -453,25 +460,25 @@
 usb_task_thread(void *arg)
 {
 	struct usb_task *task;
+	struct usb_taskq *taskq;
 	int s;
 
-#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
 	mtx_lock(&Giant);
-#endif
 
-	DPRINTF(("usb_task_thread: start\n"));
+	taskq = arg;
+	DPRINTF(("usb_task_thread: start taskq %s\n", taskq->name));
 
 	s = splusb();
 	while (usb_ndevs > 0) {
-		task = TAILQ_FIRST(&usb_all_tasks);
+		task = TAILQ_FIRST(&taskq->tasks);
 		if (task == NULL) {
-			tsleep(&usb_all_tasks, PWAIT, "usbtsk", 0);
-			task = TAILQ_FIRST(&usb_all_tasks);
+			tsleep(&taskq->tasks, PWAIT, "usbtsk", 0);
+			task = TAILQ_FIRST(&taskq->tasks);
 		}
 		DPRINTFN(2,("usb_task_thread: woke up task=%p\n", task));
 		if (task != NULL) {
-			TAILQ_REMOVE(&usb_all_tasks, task, next);
-			task->onqueue = 0;
+			TAILQ_REMOVE(&taskq->tasks, task, next);
+			task->queue = -1;
 			splx(s);
 			task->fun(task->arg);
 			s = splusb();
@@ -479,27 +486,15 @@
 	}
 	splx(s);
 
-	usb_taskcreated = 0;
-	wakeup(&usb_taskcreated);
+	taskq->taskcreated = 0;
+	wakeup(&taskq->taskcreated);
 
 	DPRINTF(("usb_event_thread: exit\n"));
 	kthread_exit(0);
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-usbctlprint(void *aux, const char *pnp)
-{
-	/* only "usb"es can attach to host controllers */
-	if (pnp)
-		printf("usb at %s", pnp);
-
-	return (UNCONF);
-}
-#endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
-
 int
-usbopen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+usbopen(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	int unit = USBUNIT(dev);
 	struct usb_softc *sc;
@@ -511,9 +506,9 @@
 		usb_async_proc = 0;
 		return (0);
 	}
-
-	USB_GET_SC_OPEN(usb, unit, sc);
-
+	sc = devclass_get_softc(usb_devclass, unit);
+	if (sc == NULL)
+		return (ENXIO);
 	if (sc->sc_dying)
 		return (EIO);
 
@@ -555,7 +550,7 @@
 }
 
 int
-usbclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+usbclose(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	int unit = USBUNIT(dev);
 
@@ -568,7 +563,7 @@
 }
 
 int
-usbioctl(struct cdev *devt, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
+usbioctl(struct cdev *devt, u_long cmd, caddr_t data, int flag, struct thread *p)
 {
 	struct usb_softc *sc;
 	int unit = USBUNIT(devt);
@@ -581,11 +576,7 @@
 
 		case FIOASYNC:
 			if (*(int *)data)
-#if __FreeBSD_version >= 500000
 				usb_async_proc = p->td_proc;
-#else
-				usb_async_proc = p;
-#endif
 			else
 				usb_async_proc = 0;
 			return (0);
@@ -594,18 +585,14 @@
 			return (EINVAL);
 		}
 	}
-
-	USB_GET_SC(usb, unit, sc);
-
+	sc = devclass_get_softc(usb_devclass, unit);
 	if (sc->sc_dying)
 		return (EIO);
 
 	switch (cmd) {
-#if defined(__FreeBSD__)
 	/* This part should be deleted */
   	case USB_DISCOVER:
   		break;
-#endif
 	case USB_REQUEST:
 	{
 		struct usb_ctl_request *ur = (void *)data;
@@ -634,7 +621,7 @@
 			uio.uio_rw =
 				ur->ucr_request.bmRequestType & UT_READ ?
 				UIO_READ : UIO_WRITE;
-			uio.uio_procp = p;
+			uio.uio_td = p;
 			ptr = malloc(len, M_TEMP, M_WAITOK);
 			if (uio.uio_rw == UIO_WRITE) {
 				error = uiomove(ptr, len, &uio);
@@ -688,7 +675,7 @@
 }
 
 int
-usbpoll(struct cdev *dev, int events, usb_proc_ptr p)
+usbpoll(struct cdev *dev, int events, struct thread *p)
 {
 	int revents, mask, s;
 	int unit = USBUNIT(dev);
@@ -706,24 +693,18 @@
 
 		return (revents);
 	} else {
-#if defined(__FreeBSD__)
 		return (0);	/* select/poll never wakes up - back compat */
-#else
-		return (ENXIO);
-#endif
 	}
 }
 
 /* Explore device tree from the root. */
-Static void
+static void
 usb_discover(void *v)
 {
 	struct usb_softc *sc = v;
 
-#if defined(__FreeBSD__)
 	/* splxxx should be changed to mutexes for preemption safety some day */
 	int s;
-#endif
 
 	DPRINTFN(2,("usb_discover\n"));
 #ifdef USB_DEBUG
@@ -736,22 +717,14 @@
 	 * but this is guaranteed since this function is only called
 	 * from the event thread for the controller.
 	 */
-#if defined(__FreeBSD__)
 	s = splusb();
-#endif
 	while (sc->sc_bus->needs_explore && !sc->sc_dying) {
 		sc->sc_bus->needs_explore = 0;
-#if defined(__FreeBSD__)
 		splx(s);
-#endif
 		sc->sc_bus->root_hub->hub->explore(sc->sc_bus->root_hub);
-#if defined(__FreeBSD__)
 		s = splusb();
-#endif
 	}
-#if defined(__FreeBSD__)
 	splx(s);
-#endif
 }
 
 void
@@ -795,12 +768,12 @@
 }
 
 void
-usbd_add_drv_event(int type, usbd_device_handle udev, device_ptr_t dev)
+usbd_add_drv_event(int type, usbd_device_handle udev, device_t dev)
 {
 	struct usb_event ue;
 
 	ue.u.ue_driver.ue_cookie = udev->cookie;
-	strncpy(ue.u.ue_driver.ue_devname, USBDEVPTRNAME(dev),
+	strncpy(ue.u.ue_driver.ue_devname, device_get_nameunit(dev),
 	    sizeof ue.u.ue_driver.ue_devname);
 	usb_add_event(type, &ue);
 }
@@ -872,34 +845,13 @@
 #endif /* USB_USE_SOFTINTR */
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-usb_activate(device_ptr_t self, enum devact act)
+static int
+usb_detach(device_t self)
 {
-	struct usb_softc *sc = (struct usb_softc *)self;
-	usbd_device_handle dev = sc->sc_port.device;
-	int i, rv = 0;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		sc->sc_dying = 1;
-		if (dev != NULL && dev->cdesc != NULL && dev->subdevs != NULL) {
-			for (i = 0; dev->subdevs[i]; i++)
-				rv |= config_deactivate(dev->subdevs[i]);
-		}
-		break;
-	}
-	return (rv);
-}
-#endif
-
-USB_DETACH(usb)
-{
-	USB_DETACH_START(usb, sc);
+	struct usb_softc *sc = device_get_softc(self);
 	struct usb_event ue;
+	struct usb_taskq *taskq;
+	int i;
 
 	DPRINTF(("usb_detach: start\n"));
 
@@ -914,20 +866,24 @@
 		wakeup(&sc->sc_bus->needs_explore);
 		if (tsleep(sc, PWAIT, "usbdet", hz * 60))
 			printf("%s: event thread didn't die\n",
-			       USBDEVNAME(sc->sc_dev));
+			       device_get_nameunit(sc->sc_dev));
 		DPRINTF(("usb_detach: event thread dead\n"));
 	}
 
-#ifdef __FreeBSD__
 	destroy_dev(sc->sc_usbdev);
 	if (--usb_ndevs == 0) {
 		destroy_dev(usb_dev);
 		usb_dev = NULL;
-		wakeup(&usb_all_tasks);
-		if (tsleep(&usb_taskcreated, PWAIT, "usbtdt", hz * 60))
-			printf("usb task thread didn't die\n");
+		for (i = 0; i < USB_NUM_TASKQS; i++) {
+			taskq = &usb_taskq[i];
+			wakeup(&taskq->tasks);
+			if (tsleep(&taskq->taskcreated, PWAIT, "usbtdt",
+			    hz * 60)) {
+				printf("usb task thread %s didn't die\n",
+				    taskq->name);
+			}
+		}
 	}
-#endif
 
 	usbd_finish();
 
@@ -942,14 +898,13 @@
 #endif
 #endif
 
-	ue.u.ue_ctrlr.ue_bus = USBDEVUNIT(sc->sc_dev);
+	ue.u.ue_ctrlr.ue_bus = device_get_unit(sc->sc_dev);
 	usb_add_event(USB_EVENT_CTRLR_DETACH, &ue);
 
 	return (0);
 }
 
-#if defined(__FreeBSD__)
-Static void
+static void
 usb_child_detached(device_t self, device_t child)
 {
 	struct usb_softc *sc = device_get_softc(self);
@@ -959,7 +914,7 @@
 }
 
 /* Explore USB busses at the end of device configuration. */
-Static void
+static void
 usb_cold_explore(void *arg)
 {
 	struct usb_softc *sc;
@@ -976,9 +931,5 @@
 	}
 }
 
-DRIVER_MODULE(usb, ohci, usb_driver, usb_devclass, 0, 0);
-DRIVER_MODULE(usb, uhci, usb_driver, usb_devclass, 0, 0);
-DRIVER_MODULE(usb, ehci, usb_driver, usb_devclass, 0, 0);
 SYSINIT(usb_cold_explore, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE,
     usb_cold_explore, NULL);
-#endif
Index: if_ruereg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_ruereg.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_ruereg.h -L sys/dev/usb/if_ruereg.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_ruereg.h
+++ sys/dev/usb/if_ruereg.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/if_ruereg.h,v 1.6 2005/06/10 16:49:15 brooks Exp $
+ * $FreeBSD: src/sys/dev/usb/if_ruereg.h,v 1.8 2007/07/09 20:56:39 imp Exp $
  */
 
 #ifndef _IF_RUEREG_H_
@@ -200,12 +200,11 @@
 	int			rue_if_flags;
 	struct ue_cdata		rue_cdata;
 	struct callout_handle	rue_stat_ch;
-#if __FreeBSD_version >= 500000
 	struct mtx		rue_mtx;
-#endif
 	char			rue_dying;
 	struct timeval		rue_rx_notice;
 	struct usb_qdat		rue_qdat;
+	struct usb_task		rue_tick_task;
 };
 
 #if defined(__FreeBSD__)
Index: ohcireg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ohcireg.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ohcireg.h -L sys/dev/usb/ohcireg.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ohcireg.h
+++ sys/dev/usb/ohcireg.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: ohcireg.h,v 1.17 2000/04/01 09:27:35 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/ohcireg.h,v 1.22 2005/01/06 01:43:28 imp Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/ohcireg.h,v 1.23 2006/05/28 05:27:08 iedowse Exp $	*/
 
 
 /*-
@@ -220,7 +220,8 @@
 	u_int16_t	itd_offset[OHCI_ITD_NOFFSET];	/* Buffer offsets */
 #define itd_pswn itd_offset				/* Packet Status Word*/
 #define OHCI_ITD_PAGE_SELECT	0x00001000
-#define OHCI_ITD_MK_OFFS(len)	(0xe000 | ((len) & 0x1fff))
+#define OHCI_ITD_MK_OFFS(page, off) \
+     (0xe000 | ((page) ? OHCI_ITD_PAGE_SELECT : 0) | ((off) & 0xfff))
 #define OHCI_ITD_PSW_LENGTH(x)	((x) & 0xfff)		/* Transfer length */
 #define OHCI_ITD_PSW_GET_CC(x)	((x) >> 12)		/* Condition Code */
 } ohci_itd_t;
Index: ugen.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ugen.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ugen.c -L sys/dev/usb/ugen.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ugen.c
+++ sys/dev/usb/ugen.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.59 2002/07/11 21:14:28 augustss Exp $	*/
+/*	$NetBSD: ugen.c,v 1.79 2006/03/01 12:38:13 yamt Exp $	*/
 
 /* Also already merged from NetBSD:
  *	$NetBSD: ugen.c,v 1.61 2002/09/23 05:51:20 simonb Exp $
@@ -8,7 +8,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ugen.c,v 1.103 2005/01/06 01:43:28 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ugen.c,v 1.111 2007/06/28 06:22:40 imp Exp $");
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -52,24 +52,15 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#include <sys/ioctl.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/ioccom.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
 #include <sys/filio.h>
-#endif
 #include <sys/tty.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/poll.h>
 #include <sys/sysctl.h>
 #include <sys/uio.h>
@@ -79,8 +70,8 @@
 #include <dev/usb/usbdi_util.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (ugendebug) logprintf x
-#define DPRINTFN(n,x)	if (ugendebug>(n)) logprintf x
+#define DPRINTF(x)	if (ugendebug) printf x
+#define DPRINTFN(n,x)	if (ugendebug>(n)) printf x
 int	ugendebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, ugen, CTLFLAG_RW, 0, "USB ugen");
 SYSCTL_INT(_hw_usb_ugen, OID_AUTO, debug, CTLFLAG_RW,
@@ -100,9 +91,7 @@
 
 struct ugen_endpoint {
 	struct ugen_softc *sc;
-#if defined(__FreeBSD__)
 	struct cdev *dev;
-#endif
 	usb_endpoint_descriptor_t *edesc;
 	usbd_interface_handle iface;
 	int state;
@@ -125,18 +114,15 @@
 };
 
 struct ugen_softc {
-	USBBASEDEVICE sc_dev;		/* base device */
+	device_t sc_dev;		/* base device */
 	usbd_device_handle sc_udev;
-#if defined(__FreeBSD__)
 	struct cdev *dev;
-#endif
 
 	char sc_is_open[USB_MAX_ENDPOINTS];
 	struct ugen_endpoint sc_endpoints[USB_MAX_ENDPOINTS][2];
 #define OUT 0
 #define IN  1
 
-#ifdef __FreeBSD__
 #define	UGEN_DEV_REF(dev, sc)					\
 	if ((sc)->sc_dying || dev_refthread(dev) == NULL)	\
 		return (ENXIO)
@@ -146,26 +132,9 @@
 	/* handled by dev layer */
 #define	UGEN_DEV_CLOSE(dev, sc)		\
 	/* handled by dev layer */
-#else
-	int sc_refcnt;
-#define	UGEN_DEV_REF(dev, sc)	\
-	if ((sc)->sc_dying)	\
-		return (ENXIO);	\
-	(sc)->sc_refcnt++
-#define	UGEN_DEV_RELE(dev, sc)				\
-	if (--(sc)->sc_refcnt < 0)			\
-		usb_detach_wakeup(USBDEV((sc)->sc_dev))
-#define	UGEN_DEV_OPEN(dev, sc)	\
-	(sc)->sc_refcnt++
-#define	UGEN_DEV_CLOSE(dev, sc)	\
-	UGEN_DEV_RELE(dev, sc)
-#endif
 	u_char sc_dying;
 };
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-cdev_decl(ugen);
-#elif defined(__FreeBSD__)
 d_open_t  ugenopen;
 d_close_t ugenclose;
 d_read_t  ugenread;
@@ -174,7 +143,7 @@
 d_poll_t  ugenpoll;
 d_purge_t ugenpurge;
 
-Static struct cdevsw ugenctl_cdevsw = {
+static struct cdevsw ugenctl_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
 	.d_open =	ugenopen,
@@ -182,12 +151,9 @@
 	.d_ioctl =	ugenioctl,
 	.d_purge =	ugenpurge,
 	.d_name =	"ugenctl",
-#if __FreeBSD_version < 500014
-	.d_bmaj		-1
-#endif
 };
 
-Static struct cdevsw ugen_cdevsw = {
+static struct cdevsw ugen_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
 	.d_open =	ugenopen,
@@ -198,39 +164,54 @@
 	.d_poll =	ugenpoll,
 	.d_purge =	ugenpurge,
 	.d_name =	"ugen",
-#if __FreeBSD_version < 500014
-	.d_bmaj		-1
-#endif
 };
-#endif
 
-Static void ugenintr(usbd_xfer_handle xfer, usbd_private_handle addr,
+static void ugenintr(usbd_xfer_handle xfer, usbd_private_handle addr,
 		     usbd_status status);
-Static void ugen_isoc_rintr(usbd_xfer_handle xfer, usbd_private_handle addr,
+static void ugen_isoc_rintr(usbd_xfer_handle xfer, usbd_private_handle addr,
 			    usbd_status status);
-Static int ugen_do_read(struct ugen_softc *, int, struct uio *, int);
-Static int ugen_do_write(struct ugen_softc *, int, struct uio *, int);
-Static int ugen_do_ioctl(struct ugen_softc *, int, u_long,
-			 caddr_t, int, usb_proc_ptr);
-#if defined(__FreeBSD__)
-Static void ugen_make_devnodes(struct ugen_softc *sc);
-Static void ugen_destroy_devnodes(struct ugen_softc *sc);
-#endif
-Static int ugen_set_config(struct ugen_softc *sc, int configno);
-Static usb_config_descriptor_t *ugen_get_cdesc(struct ugen_softc *sc,
+static int ugen_do_read(struct ugen_softc *, int, struct uio *, int);
+static int ugen_do_write(struct ugen_softc *, int, struct uio *, int);
+static int ugen_do_ioctl(struct ugen_softc *, int, u_long,
+			 caddr_t, int, struct thread *);
+static void ugen_make_devnodes(struct ugen_softc *sc);
+static void ugen_destroy_devnodes(struct ugen_softc *sc);
+static int ugen_set_config(struct ugen_softc *sc, int configno);
+static usb_config_descriptor_t *ugen_get_cdesc(struct ugen_softc *sc,
 					       int index, int *lenp);
-Static usbd_status ugen_set_interface(struct ugen_softc *, int, int);
-Static int ugen_get_alt_index(struct ugen_softc *sc, int ifaceidx);
+static usbd_status ugen_set_interface(struct ugen_softc *, int, int);
+static int ugen_get_alt_index(struct ugen_softc *sc, int ifaceidx);
 
 #define UGENUNIT(n) ((minor(n) >> 4) & 0xf)
 #define UGENENDPOINT(n) (minor(n) & 0xf)
 #define UGENMINOR(u, e) (((u) << 4) | (e))
 
-USB_DECLARE_DRIVER(ugen);
+static device_probe_t ugen_match;
+static device_attach_t ugen_attach;
+static device_detach_t ugen_detach;
+
+static devclass_t ugen_devclass;
+
+static device_method_t ugen_methods[] = {
+	DEVMETHOD(device_probe, ugen_match),
+	DEVMETHOD(device_attach, ugen_attach),
+	DEVMETHOD(device_detach, ugen_detach),
+	{0,0},
+	{0,0}
+};
+
+static driver_t ugen_driver = {
+	"ugen",
+        ugen_methods,
+        sizeof(struct ugen_softc)
+};
+
+MODULE_DEPEND(ugen, usb, 1, 1, 1);
 
-USB_MATCH(ugen)
+static int
+ugen_match(device_t self)
 {
-	USB_MATCH_START(ugen, uaa);
+        struct usb_attach_arg *uaa = device_get_ivars(self);
 
 #if 0
 	if (uaa->matchlvl)
@@ -242,17 +223,16 @@
 		return (UMATCH_NONE);
 }
 
-USB_ATTACH(ugen)
+static int
+ugen_attach(device_t self)
 {
-	USB_ATTACH_START(ugen, sc, uaa);
+        struct ugen_softc *sc = device_get_softc(self);
+        struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle udev;
-	char devinfo[1024];
 	usbd_status err;
 	int conf;
 
-	usbd_devinfo(uaa->device, 0, devinfo);
-	USB_ATTACH_SETUP;
-
+	sc->sc_dev = self;
 	sc->sc_udev = udev = uaa->device;
 
 	memset(sc->sc_endpoints, 0, sizeof sc->sc_endpoints);
@@ -261,9 +241,9 @@
 	err = usbd_set_config_index(udev, 0, 0);
 	if (err) {
 		printf("%s: setting configuration index 0 failed\n",
-		       USBDEVNAME(sc->sc_dev));
+		       device_get_nameunit(sc->sc_dev));
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return (ENXIO);
 	}
 	conf = usbd_get_config_descriptor(udev)->bConfigurationValue;
 
@@ -271,24 +251,21 @@
 	err = ugen_set_config(sc, conf);
 	if (err) {
 		printf("%s: setting configuration %d failed\n",
-		       USBDEVNAME(sc->sc_dev), conf);
+		       device_get_nameunit(sc->sc_dev), conf);
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return (ENXIO);
 	}
 
-#if defined(__FreeBSD__)
 	/* the main device, ctrl endpoint */
 	sc->dev = make_dev(&ugenctl_cdevsw,
-	    UGENMINOR(USBDEVUNIT(sc->sc_dev), 0), UID_ROOT, GID_OPERATOR, 0644,
-	    "%s", USBDEVNAME(sc->sc_dev));
+	    UGENMINOR(device_get_unit(sc->sc_dev), 0), UID_ROOT, GID_OPERATOR, 0644,
+	    "%s", device_get_nameunit(sc->sc_dev));
 	ugen_make_devnodes(sc);
-#endif
-
-	USB_ATTACH_SUCCESS_RETURN;
+	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
+	return (0);
 }
 
-#if defined(__FreeBSD__)
-Static void
+static void
 ugen_make_devnodes(struct ugen_softc *sc)
 {
 	int endptno;
@@ -306,10 +283,10 @@
 			 * of the structs is populated.
 			 */
 			dev = make_dev(&ugen_cdevsw,
-				UGENMINOR(USBDEVUNIT(sc->sc_dev), endptno),
+				UGENMINOR(device_get_unit(sc->sc_dev), endptno),
 				UID_ROOT, GID_OPERATOR, 0644,
 				"%s.%d",
-				USBDEVNAME(sc->sc_dev), endptno);
+				device_get_nameunit(sc->sc_dev), endptno);
 			dev_depends(sc->dev, dev);
 			if (sc->sc_endpoints[endptno][IN].sc != NULL)
 				sc->sc_endpoints[endptno][IN].dev = dev;
@@ -319,12 +296,14 @@
 	}
 }
 
-Static void
+static void
 ugen_destroy_devnodes(struct ugen_softc *sc)
 {
-	int endptno;
+	int endptno, prev_sc_dying;
 	struct cdev *dev;
 
+	prev_sc_dying = sc->sc_dying;
+	sc->sc_dying = 1;
 	/* destroy all devices for the other (existing) endpoints as well */
 	for (endptno = 1; endptno < USB_MAX_ENDPOINTS; endptno++) {
 		if (sc->sc_endpoints[endptno][IN].sc != NULL ||
@@ -341,13 +320,20 @@
 				dev = sc->sc_endpoints[endptno][IN].dev;
 			else
 				dev = sc->sc_endpoints[endptno][OUT].dev;
-			destroy_dev(dev);
+
+			KASSERT(dev != NULL,
+			    ("ugen_destroy_devnodes: NULL dev"));
+			if(dev != NULL)
+				destroy_dev(dev);
+
+			sc->sc_endpoints[endptno][IN].sc = NULL;
+			sc->sc_endpoints[endptno][OUT].sc = NULL;
 		}
 	}
+	sc->sc_dying = prev_sc_dying;
 }
-#endif
 
-Static int
+static int
 ugen_set_config(struct ugen_softc *sc, int configno)
 {
 	usbd_device_handle dev = sc->sc_udev;
@@ -360,7 +346,7 @@
 	int dir;
 
 	DPRINTFN(1,("ugen_set_config: %s to configno %d, sc=%p\n",
-		    USBDEVNAME(sc->sc_dev), configno, sc));
+		    device_get_nameunit(sc->sc_dev), configno, sc));
 
 	/* We start at 1, not 0, because we don't care whether the
 	 * control endpoint is open or not. It is always present.
@@ -369,7 +355,7 @@
 		if (sc->sc_is_open[endptno]) {
 			DPRINTFN(1,
 			     ("ugen_set_config: %s - endpoint %d is open\n",
-			      USBDEVNAME(sc->sc_dev), endptno));
+			      device_get_nameunit(sc->sc_dev), endptno));
 			return (USBD_IN_USE);
 		}
 
@@ -378,9 +364,10 @@
 		return (err);
 	/* store an array of endpoint descriptors to clear if the configuration
 	 * change succeeds - these aren't available afterwards */
-	nendpt_cache = malloc(sizeof(u_int8_t) * niface, M_TEMP, M_WAITOK);
+	nendpt_cache = malloc(sizeof(u_int8_t) * niface, M_TEMP, M_WAITOK |
+	    M_ZERO);
 	sce_cache_arr = malloc(sizeof(struct ugen_endpoint **) * niface, M_TEMP,
-		 M_WAITOK);
+	    M_WAITOK | M_ZERO);
 	niface_cache = niface;
 
 	for (ifaceno = 0; ifaceno < niface; ifaceno++) {
@@ -419,9 +406,7 @@
 		}
 	}
 
-#if defined(__FreeBSD__)
 	ugen_destroy_devnodes(sc);
-#endif
 
 	/* now we can clear the old interface's ugen_endpoints */
 	for(ifaceno = 0; ifaceno < niface_cache; ifaceno++) {
@@ -477,7 +462,7 @@
 }
 
 int
-ugenopen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+ugenopen(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	struct ugen_softc *sc;
 	int unit = UGENUNIT(dev);
@@ -490,7 +475,9 @@
 	void *buf;
 	int i, j;
 
-	USB_GET_SC_OPEN(ugen, unit, sc);
+	sc = devclass_get_softc(ugen_devclass, unit);
+	if (sc == NULL)
+		return (ENXIO);
 
  	DPRINTFN(5, ("ugenopen: flag=%d, mode=%d, unit=%d endpt=%d\n",
 		     flag, mode, unit, endpt));
@@ -542,7 +529,8 @@
 			sce->ibuf = malloc(isize, M_USBDEV, M_WAITOK);
 			DPRINTFN(5, ("ugenopen: intr endpt=%d,isize=%d\n",
 				     endpt, isize));
-			if (clalloc(&sce->q, UGEN_IBSIZE, 0) == -1)
+			if ((clist_alloc_cblocks(&sce->q, UGEN_IBSIZE,
+			    UGEN_IBSIZE), 0) == -1)
 				return (ENOMEM);
 			err = usbd_open_pipe_intr(sce->iface,
 				  edesc->bEndpointAddress,
@@ -551,7 +539,7 @@
 				  USBD_DEFAULT_INTERVAL);
 			if (err) {
 				free(sce->ibuf, M_USBDEV);
-				clfree(&sce->q);
+				clist_free_cblocks(&sce->q);
 				return (EIO);
 			}
 			DPRINTFN(5, ("ugenopen: interrupt open done\n"));
@@ -619,7 +607,7 @@
 }
 
 int
-ugenclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+ugenclose(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	int endpt = UGENENDPOINT(dev);
 	struct ugen_softc *sc;
@@ -627,7 +615,7 @@
 	int dir;
 	int i;
 
-	USB_GET_SC(ugen, UGENUNIT(dev), sc);
+	sc = devclass_get_softc(ugen_devclass, UGENUNIT(dev));
 
 	DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%d, endpt=%d\n",
 		     flag, mode, UGENUNIT(dev), endpt));
@@ -662,7 +650,7 @@
 		switch (sce->edesc->bmAttributes & UE_XFERTYPE) {
 		case UE_INTERRUPT:
 			ndflush(&sce->q, sce->q.c_cc);
-			clfree(&sce->q);
+			clist_free_cblocks(&sce->q);
 			break;
 		case UE_ISOCHRONOUS:
 			for (i = 0; i < UGEN_NISOREQS; ++i)
@@ -675,7 +663,7 @@
 		if (sce->ibuf != NULL) {
 			free(sce->ibuf, M_USBDEV);
 			sce->ibuf = NULL;
-			clfree(&sce->q);
+			clist_free_cblocks(&sce->q);
 		}
 	}
 	sc->sc_is_open[endpt] = 0;
@@ -684,7 +672,7 @@
 	return (0);
 }
 
-Static int
+static int
 ugen_do_read(struct ugen_softc *sc, int endpt, struct uio *uio, int flag)
 {
 	struct ugen_endpoint *sce = &sc->sc_endpoints[endpt][IN];
@@ -693,10 +681,10 @@
 	usbd_xfer_handle xfer;
 	usbd_status err;
 	int s;
-	int error = 0;
+	int error = 0, doneone = 0;
 	u_char buffer[UGEN_CHUNK];
 
-	DPRINTFN(5, ("%s: ugenread: %d\n", USBDEVNAME(sc->sc_dev), endpt));
+	DPRINTFN(5, ("%s: ugenread: %d\n", device_get_nameunit(sc->sc_dev), endpt));
 
 	if (sc->sc_dying)
 		return (EIO);
@@ -726,14 +714,18 @@
 			}
 			sce->state |= UGEN_ASLP;
 			DPRINTFN(5, ("ugenread: sleep on %p\n", sce));
-			error = tsleep(sce, PZERO | PCATCH, "ugenri", 0);
+			error = tsleep(sce, PZERO | PCATCH, "ugenri",
+			    (sce->timeout * hz + 999) / 1000);
+			sce->state &= ~UGEN_ASLP;
 			DPRINTFN(5, ("ugenread: woke, error=%d\n", error));
 			if (sc->sc_dying)
 				error = EIO;
-			if (error) {
-				sce->state &= ~UGEN_ASLP;
+			if (error == EAGAIN) {
+				error = 0;	/* timeout, return 0 bytes */
 				break;
 			}
+			if (error)
+				break;
 		}
 		splx(s);
 
@@ -757,9 +749,11 @@
 		xfer = usbd_alloc_xfer(sc->sc_udev);
 		if (xfer == 0)
 			return (ENOMEM);
-		while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0) {
+		while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0 ||
+		    !doneone) {
 			DPRINTFN(1, ("ugenread: start transfer %d bytes\n",n));
 			tn = n;
+			doneone = 1;
 			err = usbd_bulk_transfer(
 				  xfer, sce->pipeh,
 				  sce->state & UGEN_SHORT_OK ?
@@ -790,18 +784,22 @@
 			}
 			sce->state |= UGEN_ASLP;
 			DPRINTFN(5, ("ugenread: sleep on %p\n", sce));
-			error = tsleep(sce, PZERO | PCATCH, "ugenri", 0);
+			error = tsleep(sce, PZERO | PCATCH, "ugenri",
+			    (sce->timeout * hz + 999) / 1000);
+			sce->state &= ~UGEN_ASLP;
 			DPRINTFN(5, ("ugenread: woke, error=%d\n", error));
 			if (sc->sc_dying)
 				error = EIO;
-			if (error) {
-				sce->state &= ~UGEN_ASLP;
+			if (error == EAGAIN) {
+				error = 0;	/* timeout, return 0 bytes */
 				break;
 			}
+			if (error)
+				break;
 		}
 
 		while (sce->cur != sce->fill && uio->uio_resid > 0 && !error) {
-			if(sce->fill > sce->cur)
+			if (sce->fill > sce->cur)
 				n = min(sce->fill - sce->cur, uio->uio_resid);
 			else
 				n = min(sce->limit - sce->cur, uio->uio_resid);
@@ -833,7 +831,10 @@
 	struct ugen_softc *sc;
 	int error;
 
-	USB_GET_SC(ugen, UGENUNIT(dev), sc);
+	sc = devclass_get_softc(ugen_devclass, UGENUNIT(dev));
+
+	if (sc->sc_dying)
+		return (EIO);
 
 	UGEN_DEV_REF(dev, sc);
 	error = ugen_do_read(sc, endpt, uio, flag);
@@ -841,17 +842,17 @@
 	return (error);
 }
 
-Static int
+static int
 ugen_do_write(struct ugen_softc *sc, int endpt, struct uio *uio, int flag)
 {
 	struct ugen_endpoint *sce = &sc->sc_endpoints[endpt][OUT];
 	u_int32_t n;
-	int error = 0;
+	int error = 0, doneone = 0;
 	char buf[UGEN_BBSIZE];
 	usbd_xfer_handle xfer;
 	usbd_status err;
 
-	DPRINTFN(5, ("%s: ugenwrite: %d\n", USBDEVNAME(sc->sc_dev), endpt));
+	DPRINTFN(5, ("%s: ugenwrite: %d\n", device_get_nameunit(sc->sc_dev), endpt));
 
 	if (sc->sc_dying)
 		return (EIO);
@@ -875,7 +876,9 @@
 		xfer = usbd_alloc_xfer(sc->sc_udev);
 		if (xfer == 0)
 			return (EIO);
-		while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0) {
+		while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0 ||
+		    !doneone) {
+			doneone = 1;
 			error = uiomove(buf, n, uio);
 			if (error)
 				break;
@@ -899,7 +902,8 @@
 		if (xfer == 0)
 			return (EIO);
 		while ((n = min(UGETW(sce->edesc->wMaxPacketSize),
-		    uio->uio_resid)) != 0) {
+		    uio->uio_resid)) != 0 || !doneone) {
+			doneone = 1;
 			error = uiomove(buf, n, uio);
 			if (error)
 				break;
@@ -931,7 +935,10 @@
 	struct ugen_softc *sc;
 	int error;
 
-	USB_GET_SC(ugen, UGENUNIT(dev), sc);
+	sc = devclass_get_softc(ugen_devclass, UGENUNIT(dev));
+
+	if (sc->sc_dying)
+		return (EIO);
 
 	UGEN_DEV_REF(dev, sc);
 	error = ugen_do_write(sc, endpt, uio, flag);
@@ -939,25 +946,6 @@
 	return (error);
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-ugen_activate(device_ptr_t self, enum devact act)
-{
-	struct ugen_softc *sc = (struct ugen_softc *)self;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		sc->sc_dying = 1;
-		break;
-	}
-	return (0);
-}
-#endif
-
-#ifdef __FreeBSD__
 void
 ugenpurge(struct cdev *dev)
 {
@@ -967,27 +955,34 @@
 
 	if (endpt == USB_CONTROL_ENDPOINT)
 		return;
-	USB_GET_SC(ugen, UGENUNIT(dev), sc);
+	sc = devclass_get_softc(ugen_devclass, UGENUNIT(dev));
 	sce = &sc->sc_endpoints[endpt][IN];
 	if (sce->pipeh)
 		usbd_abort_pipe(sce->pipeh);
+	if (sce->state & UGEN_ASLP) {
+		DPRINTFN(5, ("ugenpurge: waking %p\n", sce));
+		wakeup(sce);
+	}
+	selwakeuppri(&sce->rsel, PZERO);
+
+	sce = &sc->sc_endpoints[endpt][OUT];
+	if (sce->pipeh)
+		usbd_abort_pipe(sce->pipeh);
+	if (sce->state & UGEN_ASLP) {
+		DPRINTFN(5, ("ugenpurge: waking %p\n", sce));
+		wakeup(sce);
+	}
+	selwakeuppri(&sce->rsel, PZERO);
 }
-#endif
 
-USB_DETACH(ugen)
+static int
+ugen_detach(device_t self)
 {
-	USB_DETACH_START(ugen, sc);
+	struct ugen_softc *sc = device_get_softc(self);
 	struct ugen_endpoint *sce;
 	int i, dir;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	int maj, mn, c, s;
-#endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	DPRINTF(("ugen_detach: sc=%p flags=%d\n", sc, flags));
-#elif defined(__FreeBSD__)
 	DPRINTF(("ugen_detach: sc=%p\n", sc));
-#endif
 
 	sc->sc_dying = 1;
 	/* Abort all pipes.  Causes processes waiting for transfer to wake. */
@@ -996,49 +991,17 @@
 			sce = &sc->sc_endpoints[i][dir];
 			if (sce->pipeh)
 				usbd_abort_pipe(sce->pipeh);
+			selwakeuppri(&sce->rsel, PZERO);
 		}
 	}
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	s = splusb();
-	if (sc->sc_refcnt > 0) {
-		/* Wake everyone */
-		for (i = 0; i < USB_MAX_ENDPOINTS; i++)
-			wakeup(&sc->sc_endpoints[i][IN]);
-		/* Wait for processes to go away. */
-		while (sc->sc_refcnt > 0)
-			usb_detach_wait(USBDEV(sc->sc_dev));
-	}
-	splx(s);
-
-	/* Wait for opens to go away. */
-	do {
-		c = 0;
-		for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
-			if (sc->sc_is_open[i])
-				c++;
-		}
-		if (c != 0)
-			tsleep(&sc->sc_dying, PZERO, "ugendr", hz);
-	} while (c != 0);
-
-	/* locate the major number */
-	for (maj = 0; maj < nchrdev; maj++)
-		if (cdevsw[maj].d_open == ugenopen)
-			break;
-
-	/* Nuke the vnodes for any open instances (calls close). */
-	mn = self->dv_unit * USB_MAX_ENDPOINTS;
-	vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);
-#elif defined(__FreeBSD__)
 	/* destroy the device for the control endpoint */
 	destroy_dev(sc->dev);
-#endif
-
+	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
 	return (0);
 }
 
-Static void
+static void
 ugenintr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
 {
 	struct ugen_endpoint *sce = addr;
@@ -1074,7 +1037,7 @@
 	selwakeuppri(&sce->rsel, PZERO);
 }
 
-Static void
+static void
 ugen_isoc_rintr(usbd_xfer_handle xfer, usbd_private_handle addr,
 		usbd_status status)
 {
@@ -1088,8 +1051,7 @@
 		return;
 
 	usbd_get_xfer_status(xfer, NULL, NULL, &count, NULL);
-	DPRINTFN(5,("ugen_isoc_rintr: xfer %d, count=%d\n",
-		    (int)(req - sce->isoreqs),
+	DPRINTFN(5,("ugen_isoc_rintr: xfer %td, count=%d\n", req - sce->isoreqs,
 		    count));
 
 	/* throw away oldest input if the buffer is full */
@@ -1134,7 +1096,7 @@
 	selwakeuppri(&sce->rsel, PZERO);
 }
 
-Static usbd_status
+static usbd_status
 ugen_set_interface(struct ugen_softc *sc, int ifaceidx, int altno)
 {
 	usbd_interface_handle iface;
@@ -1182,10 +1144,8 @@
 	if (err)
 		panic("ugen_set_interface: endpoint count failed");
 
-#if defined(__FreeBSD__)
 	/* destroy the existing devices, we remake the new ones in a moment */
 	ugen_destroy_devnodes(sc);
-#endif
 
 	/* now we can clear the old interface's ugen_endpoints */
 	for (endptno = 0; endptno < nendpt_cache; endptno++) {
@@ -1207,16 +1167,14 @@
 		sce->iface = iface;
 	}
 
-#if defined(__FreeBSD__)
 	/* make the new devices */
 	ugen_make_devnodes(sc);
-#endif
 
 	return (0);
 }
 
 /* Retrieve a complete descriptor for a certain device and index. */
-Static usb_config_descriptor_t *
+static usb_config_descriptor_t *
 ugen_get_cdesc(struct ugen_softc *sc, int index, int *lenp)
 {
 	usb_config_descriptor_t *cdesc, *tdesc, cdescr;
@@ -1249,7 +1207,7 @@
 	return (cdesc);
 }
 
-Static int
+static int
 ugen_get_alt_index(struct ugen_softc *sc, int ifaceidx)
 {
 	usbd_interface_handle iface;
@@ -1261,9 +1219,9 @@
 	return (usbd_get_interface_altindex(iface));
 }
 
-Static int
+static int
 ugen_do_ioctl(struct ugen_softc *sc, int endpt, u_long cmd,
-	      caddr_t addr, int flag, usb_proc_ptr p)
+	      caddr_t addr, int flag, struct thread *p)
 {
 	struct ugen_endpoint *sce;
 	usbd_status err;
@@ -1306,6 +1264,8 @@
 	case USB_SET_TIMEOUT:
 		sce = &sc->sc_endpoints[endpt][IN];
 		sce->timeout = *(int *)addr;
+		sce = &sc->sc_endpoints[endpt][OUT];
+		sce->timeout = *(int *)addr;
 		return (0);
 	default:
 		break;
@@ -1332,9 +1292,7 @@
 		err = ugen_set_config(sc, *(int *)addr);
 		switch (err) {
 		case USBD_NORMAL_COMPLETION:
-#if defined(__FreeBSD__)
 			ugen_make_devnodes(sc);
-#endif
 			break;
 		case USBD_IN_USE:
 			return (EBUSY);
@@ -1448,7 +1406,7 @@
 		uio.uio_offset = 0;
 		uio.uio_segflg = UIO_USERSPACE;
 		uio.uio_rw = UIO_READ;
-		uio.uio_procp = p;
+		uio.uio_td = p;
 		error = uiomove((void *)cdesc, len, &uio);
 		free(cdesc, M_TEMP);
 		return (error);
@@ -1496,7 +1454,7 @@
 			uio.uio_rw =
 				ur->ucr_request.bmRequestType & UT_READ ?
 				UIO_READ : UIO_WRITE;
-			uio.uio_procp = p;
+			uio.uio_td = p;
 			ptr = malloc(len, M_TEMP, M_WAITOK);
 			if (uio.uio_rw == UIO_WRITE) {
 				error = uiomove(ptr, len, &uio);
@@ -1534,13 +1492,17 @@
 }
 
 int
-ugenioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p)
+ugenioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
+    struct thread *p)
 {
 	int endpt = UGENENDPOINT(dev);
 	struct ugen_softc *sc;
 	int error;
 
-	USB_GET_SC(ugen, UGENUNIT(dev), sc);
+	sc = devclass_get_softc(ugen_devclass, UGENUNIT(dev));
+
+	if (sc->sc_dying)
+		return (EIO);
 
 	UGEN_DEV_REF(dev, sc);
 	error = ugen_do_ioctl(sc, endpt, cmd, addr, flag, p);
@@ -1549,46 +1511,60 @@
 }
 
 int
-ugenpoll(struct cdev *dev, int events, usb_proc_ptr p)
+ugenpoll(struct cdev *dev, int events, struct thread *p)
 {
 	struct ugen_softc *sc;
-	struct ugen_endpoint *sce;
+	struct ugen_endpoint *sce_in, *sce_out;
+	usb_endpoint_descriptor_t *edesc;
 	int revents = 0;
 	int s;
 
-	USB_GET_SC(ugen, UGENUNIT(dev), sc);
+	sc = devclass_get_softc(ugen_devclass, UGENUNIT(dev));
 
 	if (sc->sc_dying)
-		return (EIO);
+		return ((events & (POLLIN | POLLOUT | POLLRDNORM |
+		    POLLWRNORM)) | POLLHUP);
+	/* Do not allow to poll a control endpoint */
+	if (UGENENDPOINT(dev) == USB_CONTROL_ENDPOINT)
+		return (events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
+
+	sce_in = &sc->sc_endpoints[UGENENDPOINT(dev)][IN];
+	sce_out = &sc->sc_endpoints[UGENENDPOINT(dev)][OUT];
+	edesc = (sce_in->edesc != NULL) ? sce_in->edesc : sce_out->edesc;
+	KASSERT(edesc != NULL, ("ugenpoll: NULL edesc"));
+	if (sce_in->edesc == NULL || sce_in->pipeh == NULL)
+		sce_in = NULL;
+	if (sce_out->edesc == NULL || sce_out->pipeh == NULL)
+		sce_out = NULL;
 
-	/* XXX always IN */
-	sce = &sc->sc_endpoints[UGENENDPOINT(dev)][IN];
-#ifdef DIAGNOSTIC
-	if (!sce->edesc) {
-		printf("ugenpoll: no edesc\n");
-		return (EIO);
-	}
-	if (!sce->pipeh) {
-		printf("ugenpoll: no pipe\n");
-		return (EIO);
-	}
-#endif
 	s = splusb();
-	switch (sce->edesc->bmAttributes & UE_XFERTYPE) {
+	switch (edesc->bmAttributes & UE_XFERTYPE) {
 	case UE_INTERRUPT:
-		if (events & (POLLIN | POLLRDNORM)) {
-			if (sce->q.c_cc > 0)
+		if (sce_in != NULL && (events & (POLLIN | POLLRDNORM))) {
+			if (sce_in->q.c_cc > 0)
 				revents |= events & (POLLIN | POLLRDNORM);
 			else
-				selrecord(p, &sce->rsel);
+				selrecord(p, &sce_in->rsel);
+		}
+		if (sce_out != NULL && (events & (POLLOUT | POLLWRNORM))) {
+			if (sce_out->q.c_cc > 0)
+				revents |= events & (POLLOUT | POLLWRNORM);
+			else
+				selrecord(p, &sce_out->rsel);
 		}
 		break;
 	case UE_ISOCHRONOUS:
-		if (events & (POLLIN | POLLRDNORM)) {
-			if (sce->cur != sce->fill)
+		if (sce_in != NULL && (events & (POLLIN | POLLRDNORM))) {
+			if (sce_in->cur != sce_in->fill)
 				revents |= events & (POLLIN | POLLRDNORM);
 			else
-				selrecord(p, &sce->rsel);
+				selrecord(p, &sce_in->rsel);
+		}
+		if (sce_out != NULL && (events & (POLLOUT | POLLWRNORM))) {
+			if (sce_out->cur != sce_out->fill)
+				revents |= events & (POLLOUT | POLLWRNORM);
+			else
+				selrecord(p, &sce_out->rsel);
 		}
 		break;
 	case UE_BULK:
@@ -1607,6 +1583,4 @@
 	return (revents);
 }
 
-#if defined(__FreeBSD__)
 DRIVER_MODULE(ugen, uhub, ugen_driver, ugen_devclass, usbd_driver_load, 0);
-#endif
Index: if_cue.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_cue.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_cue.c -L sys/dev/usb/if_cue.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_cue.c
+++ sys/dev/usb/if_cue.c
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/if_cue.c,v 1.57.2.3 2005/10/09 03:59:36 delphij Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/if_cue.c,v 1.72 2007/06/23 06:29:19 imp Exp $");
 
 /*
  * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
@@ -70,9 +70,6 @@
 
 #include <sys/bus.h>
 #include <machine/bus.h>
-#if __FreeBSD_version < 500000
-#include <machine/clock.h>
-#endif
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -86,43 +83,44 @@
 /*
  * Various supported device vendors/products.
  */
-Static struct cue_type cue_devs[] = {
+static struct cue_type cue_devs[] = {
 	{ USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
 	{ USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
 	{ USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
+        /* Belkin F5U111 adapter covered by NETMATE entry */
 	{ 0, 0 }
 };
 
-Static int cue_match(device_ptr_t);
-Static int cue_attach(device_ptr_t);
-Static int cue_detach(device_ptr_t);
-
-Static int cue_encap(struct cue_softc *, struct mbuf *, int);
-Static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void cue_tick(void *);
-Static void cue_rxstart(struct ifnet *);
-Static void cue_start(struct ifnet *);
-Static int cue_ioctl(struct ifnet *, u_long, caddr_t);
-Static void cue_init(void *);
-Static void cue_stop(struct cue_softc *);
-Static void cue_watchdog(struct ifnet *);
-Static void cue_shutdown(device_ptr_t);
-
-Static void cue_setmulti(struct cue_softc *);
-Static uint32_t cue_mchash(const uint8_t *);
-Static void cue_reset(struct cue_softc *);
-
-Static int cue_csr_read_1(struct cue_softc *, int);
-Static int cue_csr_write_1(struct cue_softc *, int, int);
-Static int cue_csr_read_2(struct cue_softc *, int);
+static device_probe_t cue_match;
+static device_attach_t cue_attach;
+static device_detach_t cue_detach;
+static device_shutdown_t cue_shutdown;
+
+static int cue_encap(struct cue_softc *, struct mbuf *, int);
+static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void cue_tick(void *);
+static void cue_rxstart(struct ifnet *);
+static void cue_start(struct ifnet *);
+static int cue_ioctl(struct ifnet *, u_long, caddr_t);
+static void cue_init(void *);
+static void cue_stop(struct cue_softc *);
+static void cue_watchdog(struct ifnet *);
+
+static void cue_setmulti(struct cue_softc *);
+static uint32_t cue_mchash(const uint8_t *);
+static void cue_reset(struct cue_softc *);
+
+static int cue_csr_read_1(struct cue_softc *, int);
+static int cue_csr_write_1(struct cue_softc *, int, int);
+static int cue_csr_read_2(struct cue_softc *, int);
 #ifdef notdef
-Static int cue_csr_write_2(struct cue_softc *, int, int);
+static int cue_csr_write_2(struct cue_softc *, int, int);
 #endif
-Static int cue_mem(struct cue_softc *, int, int, void *, int);
-Static int cue_getmac(struct cue_softc *, void *);
+static int cue_mem(struct cue_softc *, int, int, void *, int);
+static int cue_getmac(struct cue_softc *, void *);
 
-Static device_method_t cue_methods[] = {
+static device_method_t cue_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		cue_match),
 	DEVMETHOD(device_attach,	cue_attach),
@@ -132,13 +130,13 @@
 	{ 0, 0 }
 };
 
-Static driver_t cue_driver = {
+static driver_t cue_driver = {
 	"cue",
 	cue_methods,
 	sizeof(struct cue_softc)
 };
 
-Static devclass_t cue_devclass;
+static devclass_t cue_devclass;
 
 DRIVER_MODULE(cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
 MODULE_DEPEND(cue, usb, 1, 1, 1);
@@ -150,7 +148,7 @@
 #define CUE_CLRBIT(sc, reg, x)				\
 	cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
 
-Static int
+static int
 cue_csr_read_1(struct cue_softc *sc, int reg)
 {
 	usb_device_request_t	req;
@@ -178,7 +176,7 @@
 	return(val);
 }
 
-Static int
+static int
 cue_csr_read_2(struct cue_softc *sc, int reg)
 {
 	usb_device_request_t	req;
@@ -206,7 +204,7 @@
 	return(val);
 }
 
-Static int
+static int
 cue_csr_write_1(struct cue_softc *sc, int reg, int val)
 {
 	usb_device_request_t	req;
@@ -234,7 +232,7 @@
 }
 
 #ifdef notdef
-Static int
+static int
 cue_csr_write_2(struct cue_softc *sc, int reg, int val)
 {
 	usb_device_request_t	req;
@@ -262,7 +260,7 @@
 }
 #endif
 
-Static int
+static int
 cue_mem(struct cue_softc *sc, int cmd, int addr, void *buf, int len)
 {
 	usb_device_request_t	req;
@@ -292,7 +290,7 @@
 	return(0);
 }
 
-Static int
+static int
 cue_getmac(struct cue_softc *sc, void *buf)
 {
 	usb_device_request_t	req;
@@ -314,7 +312,7 @@
 	CUE_UNLOCK(sc);
 
 	if (err) {
-		printf("cue%d: read MAC address failed\n", sc->cue_unit);
+		device_printf(sc->cue_dev, "read MAC address failed\n");
 		return(-1);
 	}
 
@@ -323,7 +321,7 @@
 
 #define CUE_BITS	9
 
-Static uint32_t
+static uint32_t
 cue_mchash(const uint8_t *addr)
 {
 	uint32_t crc;
@@ -334,7 +332,7 @@
 	return (crc & ((1 << CUE_BITS) - 1));
 }
 
-Static void
+static void
 cue_setmulti(struct cue_softc *sc)
 {
 	struct ifnet		*ifp;
@@ -357,11 +355,7 @@
 
 	/* now program new ones */
 	IF_ADDR_LOCK(ifp);
-#if __FreeBSD_version >= 500000
 	TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#else
-	LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#endif
 	{
 		if (ifma->ifma_addr->sa_family != AF_LINK)
 			continue;
@@ -375,11 +369,7 @@
 	 * so we can receive broadcast frames.
  	 */
 	if (ifp->if_flags & IFF_BROADCAST) {
-#if __FreeBSD_version >= 500000
 		h = cue_mchash(ifp->if_broadcastaddr);
-#else
-		h = cue_mchash(etherbroadcastaddr);
-#endif
 		sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
 	}
 
@@ -389,7 +379,7 @@
 	return;
 }
 
-Static void
+static void
 cue_reset(struct cue_softc *sc)
 {
 	usb_device_request_t	req;
@@ -405,7 +395,7 @@
 	USETW(req.wLength, 0);
 	err = usbd_do_request(sc->cue_udev, &req, NULL);
 	if (err)
-		printf("cue%d: reset failed\n", sc->cue_unit);
+		device_printf(sc->cue_dev, "reset failed\n");
 
 	/* Wait a little while for the chip to get its brains in order. */
 	DELAY(1000);
@@ -415,9 +405,10 @@
 /*
  * Probe for a Pegasus chip.
  */
-USB_MATCH(cue)
+static int
+cue_match(device_t self)
 {
-	USB_MATCH_START(cue, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	struct cue_type			*t;
 
 	if (!uaa->iface)
@@ -439,41 +430,34 @@
  * Attach the interface. Allocate softc structures, do ifmedia
  * setup and ethernet/BPF attach.
  */
-USB_ATTACH(cue)
+static int
+cue_attach(device_t self)
 {
-	USB_ATTACH_START(cue, sc, uaa);
-	char			devinfo[1024];
+	struct cue_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	u_char			eaddr[ETHER_ADDR_LEN];
 	struct ifnet		*ifp;
 	usb_interface_descriptor_t	*id;
 	usb_endpoint_descriptor_t	*ed;
 	int			i;
 
-	bzero(sc, sizeof(struct cue_softc));
 	sc->cue_dev = self;
 	sc->cue_iface = uaa->iface;
 	sc->cue_udev = uaa->device;
-	sc->cue_unit = device_get_unit(self);
 
 	if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) {
-		printf("cue%d: getting interface handle failed\n",
-		    sc->cue_unit);
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(sc->cue_dev, "getting interface handle failed\n");
+		return ENXIO;
 	}
 
 	id = usbd_get_interface_descriptor(uaa->iface);
 
-	usbd_devinfo(uaa->device, 0, devinfo);
-	device_set_desc_copy(self, devinfo);
-	printf("%s: %s\n", USBDEVNAME(self), devinfo);
-
 	/* Find endpoints. */
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
 		if (!ed) {
-			printf("cue%d: couldn't get ep %d\n",
-			    sc->cue_unit, i);
-			USB_ATTACH_ERROR_RETURN;
+			device_printf(sc->cue_dev, "couldn't get ep %d\n", i);
+			return ENXIO;
 		}
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
@@ -487,10 +471,8 @@
 		}
 	}
 
-#if __FreeBSD_version >= 500000
 	mtx_init(&sc->cue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
 	    MTX_DEF | MTX_RECURSE);
-#endif
 	CUE_LOCK(sc);
 
 #ifdef notdef
@@ -504,15 +486,13 @@
 
 	ifp = sc->cue_ifp = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
-		printf("cue%d: can not if_alloc()\n", sc->cue_unit);
+		device_printf(sc->cue_dev, "can not if_alloc()\n");
 		CUE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
 		mtx_destroy(&sc->cue_mtx);
-#endif
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 	ifp->if_softc = sc;
-	if_initname(ifp, "cue", sc->cue_unit);
+	if_initname(ifp, "cue", device_get_unit(sc->cue_dev));
 	ifp->if_mtu = ETHERMTU;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
 	    IFF_NEEDSGIANT;
@@ -529,21 +509,17 @@
 	/*
 	 * Call MI attach routine.
 	 */
-#if __FreeBSD_version >= 500000
 	ether_ifattach(ifp, eaddr);
-#else
-	ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
-#endif
 	callout_handle_init(&sc->cue_stat_ch);
 	usb_register_netisr();
 	sc->cue_dying = 0;
 
 	CUE_UNLOCK(sc);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
-Static int
-cue_detach(device_ptr_t dev)
+static int
+cue_detach(device_t dev)
 {
 	struct cue_softc	*sc;
 	struct ifnet		*ifp;
@@ -554,12 +530,8 @@
 
 	sc->cue_dying = 1;
 	untimeout(cue_tick, sc, sc->cue_stat_ch);
-#if __FreeBSD_version >= 500000
 	ether_ifdetach(ifp);
 	if_free(ifp);
-#else
-	ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
-#endif
 
 	if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
 		usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
@@ -569,14 +541,12 @@
 		usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
 
 	CUE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
 	mtx_destroy(&sc->cue_mtx);
-#endif
 
 	return(0);
 }
 
-Static void
+static void
 cue_rxstart(struct ifnet *ifp)
 {
 	struct cue_softc	*sc;
@@ -588,8 +558,8 @@
 
 	c->ue_mbuf = usb_ether_newbuf();
 	if (c->ue_mbuf == NULL) {
-		printf("%s: no memory for rx list "
-		    "-- packet dropped!\n", USBDEVNAME(sc->cue_dev));
+		device_printf(sc->cue_dev, "no memory for rx list "
+		    "-- packet dropped!\n");
 		ifp->if_ierrors++;
 		CUE_UNLOCK(sc);
 		return;
@@ -609,7 +579,7 @@
  * A frame has been uploaded: pass the resulting mbuf chain up to
  * the higher level protocols.
  */
-Static void
+static void
 cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct cue_softc	*sc;
@@ -635,7 +605,7 @@
 			return;
 		}
 		if (usbd_ratecheck(&sc->cue_rx_notice))
-			printf("cue%d: usb error on rx: %s\n", sc->cue_unit,
+			device_printf(sc->cue_dev, "usb error on rx: %s\n",
 			    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
@@ -681,7 +651,7 @@
  * the list buffers.
  */
 
-Static void
+static void
 cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct cue_softc	*sc;
@@ -699,7 +669,7 @@
 			CUE_UNLOCK(sc);
 			return;
 		}
-		printf("cue%d: usb error on tx: %s\n", sc->cue_unit,
+		device_printf(sc->cue_dev, "usb error on tx: %s\n",
 		    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
@@ -727,7 +697,7 @@
 	return;
 }
 
-Static void
+static void
 cue_tick(void *xsc)
 {
 	struct cue_softc	*sc;
@@ -756,7 +726,7 @@
 	return;
 }
 
-Static int
+static int
 cue_encap(struct cue_softc *sc, struct mbuf *m, int idx)
 {
 	int			total_len;
@@ -793,7 +763,7 @@
 	return(0);
 }
 
-Static void
+static void
 cue_start(struct ifnet *ifp)
 {
 	struct cue_softc	*sc;
@@ -837,7 +807,7 @@
 	return;
 }
 
-Static void
+static void
 cue_init(void *xsc)
 {
 	struct cue_softc	*sc = xsc;
@@ -860,7 +830,7 @@
 
 	/* Set MAC address */
 	for (i = 0; i < ETHER_ADDR_LEN; i++)
-		cue_csr_write_1(sc, CUE_PAR0 - i, IFP2ENADDR(sc->cue_ifp)[i]);
+		cue_csr_write_1(sc, CUE_PAR0 - i, IF_LLADDR(sc->cue_ifp)[i]);
 
 	/* Enable RX logic. */
 	cue_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
@@ -875,7 +845,7 @@
 	/* Init TX ring. */
 	if (usb_ether_tx_list_init(sc, &sc->cue_cdata,
 	    sc->cue_udev) == ENOBUFS) {
-		printf("cue%d: tx list init failed\n", sc->cue_unit);
+		device_printf(sc->cue_dev, "tx list init failed\n");
 		CUE_UNLOCK(sc);
 		return;
 	}
@@ -883,7 +853,7 @@
 	/* Init RX ring. */
 	if (usb_ether_rx_list_init(sc, &sc->cue_cdata,
 	    sc->cue_udev) == ENOBUFS) {
-		printf("cue%d: rx list init failed\n", sc->cue_unit);
+		device_printf(sc->cue_dev, "rx list init failed\n");
 		CUE_UNLOCK(sc);
 		return;
 	}
@@ -909,16 +879,16 @@
 	err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
 	    USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
 	if (err) {
-		printf("cue%d: open rx pipe failed: %s\n",
-		    sc->cue_unit, usbd_errstr(err));
+		device_printf(sc->cue_dev, "open rx pipe failed: %s\n",
+		    usbd_errstr(err));
 		CUE_UNLOCK(sc);
 		return;
 	}
 	err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
 	    USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
 	if (err) {
-		printf("cue%d: open tx pipe failed: %s\n",
-		    sc->cue_unit, usbd_errstr(err));
+		device_printf(sc->cue_dev, "open tx pipe failed: %s\n",
+		    usbd_errstr(err));
 		CUE_UNLOCK(sc);
 		return;
 	}
@@ -942,7 +912,7 @@
 	return;
 }
 
-Static int
+static int
 cue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
 {
 	struct cue_softc	*sc = ifp->if_softc;
@@ -987,7 +957,7 @@
 	return(error);
 }
 
-Static void
+static void
 cue_watchdog(struct ifnet *ifp)
 {
 	struct cue_softc	*sc;
@@ -998,7 +968,7 @@
 	CUE_LOCK(sc);
 
 	ifp->if_oerrors++;
-	printf("cue%d: watchdog timeout\n", sc->cue_unit);
+	device_printf(sc->cue_dev, "watchdog timeout\n");
 
 	c = &sc->cue_cdata.ue_tx_chain[0];
 	usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
@@ -1015,7 +985,7 @@
  * Stop the adapter and free any mbufs allocated to the
  * RX and TX lists.
  */
-Static void
+static void
 cue_stop(struct cue_softc *sc)
 {
 	usbd_status		err;
@@ -1034,13 +1004,13 @@
 	if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
 		err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
 		if (err) {
-			printf("cue%d: abort rx pipe failed: %s\n",
-		    	sc->cue_unit, usbd_errstr(err));
+			device_printf(sc->cue_dev, "abort rx pipe failed: %s\n",
+		    	usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
 		if (err) {
-			printf("cue%d: close rx pipe failed: %s\n",
-		    	sc->cue_unit, usbd_errstr(err));
+			device_printf(sc->cue_dev, "close rx pipe failed: %s\n",
+		    	usbd_errstr(err));
 		}
 		sc->cue_ep[CUE_ENDPT_RX] = NULL;
 	}
@@ -1048,13 +1018,13 @@
 	if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
 		err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
 		if (err) {
-			printf("cue%d: abort tx pipe failed: %s\n",
-		    	sc->cue_unit, usbd_errstr(err));
+			device_printf(sc->cue_dev, "abort tx pipe failed: %s\n",
+		    	usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
 		if (err) {
-			printf("cue%d: close tx pipe failed: %s\n",
-			    sc->cue_unit, usbd_errstr(err));
+			device_printf(sc->cue_dev, "close tx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->cue_ep[CUE_ENDPT_TX] = NULL;
 	}
@@ -1062,13 +1032,13 @@
 	if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
 		err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
 		if (err) {
-			printf("cue%d: abort intr pipe failed: %s\n",
-		    	sc->cue_unit, usbd_errstr(err));
+			device_printf(sc->cue_dev, "abort intr pipe failed: %s\n",
+		    	usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
 		if (err) {
-			printf("cue%d: close intr pipe failed: %s\n",
-			    sc->cue_unit, usbd_errstr(err));
+			device_printf(sc->cue_dev, "close intr pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->cue_ep[CUE_ENDPT_INTR] = NULL;
 	}
@@ -1088,8 +1058,8 @@
  * Stop all chip I/O so that the kernel's probe routines don't
  * get confused by errant DMAs when rebooting.
  */
-Static void
-cue_shutdown(device_ptr_t dev)
+static int
+cue_shutdown(device_t dev)
 {
 	struct cue_softc	*sc;
 
@@ -1100,5 +1070,5 @@
 	cue_stop(sc);
 	CUE_UNLOCK(sc);
 
-	return;
+	return (0);
 }
Index: usb_ethersubr.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_ethersubr.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usb_ethersubr.c -L sys/dev/usb/usb_ethersubr.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usb_ethersubr.c
+++ sys/dev/usb/usb_ethersubr.c
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/usb_ethersubr.c,v 1.20 2005/03/25 12:42:30 sobomax Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/usb_ethersubr.c,v 1.23 2007/01/08 23:21:06 alfred Exp $");
 
 /*
  * Callbacks in the USB code operate at splusb() (actually splbio()
@@ -57,6 +57,7 @@
 #include <sys/mbuf.h>
 #include <sys/malloc.h>
 #include <sys/socket.h>
+#include <sys/taskqueue.h>
 
 #include <net/if.h>
 #include <net/if_types.h>
@@ -68,13 +69,14 @@
 #include <dev/usb/usb.h>
 #include <dev/usb/usb_ethersubr.h>
 
-Static struct ifqueue usbq_rx;
-Static struct ifqueue usbq_tx;
-Static int mtx_inited = 0;
+static struct ifqueue usbq_rx;
+static struct ifqueue usbq_tx;
+static int mtx_inited = 0;
 
-Static void usbintr		(void);
+static void usbintr		(void);
 
-Static void usbintr(void)
+static void
+usbintr(void)
 {
 	struct mbuf		*m;
 	struct usb_qdat		*q;
@@ -110,7 +112,8 @@
 	return;
 }
 
-void usb_register_netisr()
+void
+usb_register_netisr(void)
 {
 	if (mtx_inited)
 		return;
@@ -125,7 +128,8 @@
  * Must be called at splusb() (actually splbio()). This should be
  * the case when called from a transfer callback routine.
  */
-void usb_ether_input(m)
+void
+usb_ether_input(m)
 	struct mbuf		*m;
 {
 	IF_ENQUEUE(&usbq_rx, m);
@@ -134,7 +138,8 @@
 	return;
 }
 
-void usb_tx_done(m)
+void
+usb_tx_done(m)
 	struct mbuf		*m;
 {
 	IF_ENQUEUE(&usbq_tx, m);
@@ -242,3 +247,32 @@
 		}
 	}
 }
+
+void
+usb_ether_task_init(device_t dev, int flags, struct usb_taskqueue *tq)
+{
+
+	/* nothing for now. */
+}
+
+void
+usb_ether_task_enqueue(struct usb_taskqueue *tq, struct task *task)
+{
+
+	taskqueue_enqueue(taskqueue_thread, task);
+}
+
+void
+usb_ether_task_drain(struct usb_taskqueue *tq, struct task *task)
+{
+
+	taskqueue_drain(taskqueue_thread, task);
+}
+
+void
+usb_ether_task_destroy(struct usb_taskqueue *tq)
+{
+
+	/* nothing for now */
+
+}
Index: dsbr100io.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/dsbr100io.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/dsbr100io.h -L sys/dev/usb/dsbr100io.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/dsbr100io.h
+++ sys/dev/usb/dsbr100io.h
@@ -28,22 +28,12 @@
  * its contributors.
  */
 
-/*  $FreeBSD: src/sys/dev/usb/dsbr100io.h,v 1.2 2005/01/06 01:36:28 imp Exp $ */
+/*  $FreeBSD: src/sys/dev/usb/dsbr100io.h,v 1.3 2007/06/12 19:01:32 imp Exp $ */
 
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
 #include <sys/ioccom.h>
-#endif
 
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
 #define FM_SET_FREQ	_IOWR('U', 200, int)
 #define FM_GET_FREQ	_IOWR('U', 201, int)
 #define FM_START	_IOWR('U', 202, int)
 #define FM_STOP		_IOWR('U', 203, int)
 #define FM_GET_STAT	_IOWR('U', 204, int)
-#else
-#define FM_SET_FREQ		0x1
-#define FM_GET_FREQ		0x2
-#define FM_START		0x3
-#define FM_STOP			0x4
-#define FM_GET_STAT		0x5
-#endif
Index: ohcivar.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ohcivar.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ohcivar.h -L sys/dev/usb/ohcivar.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ohcivar.h
+++ sys/dev/usb/ohcivar.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: ohcivar.h,v 1.30 2001/12/31 12:20:35 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/ohcivar.h,v 1.40.2.1 2005/12/04 05:52:23 iedowse Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/ohcivar.h,v 1.47 2007/06/14 16:23:31 imp Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -91,12 +91,10 @@
 	bus_space_handle_t ioh;
 	bus_size_t sc_size;
 
-#if defined(__FreeBSD__)
 	void *ih;
 
 	struct resource *io_res;
 	struct resource *irq_res;
-#endif
 
 	usb_dma_t sc_hccadma;
 	struct ohci_hcca *sc_hcca;
@@ -124,7 +122,7 @@
 	ohci_soft_td_t *sc_freetds;
 	ohci_soft_itd_t *sc_freeitds;
 
-	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
+	STAILQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
 
 	usbd_xfer_handle sc_intrxfer;
 
@@ -144,11 +142,7 @@
 	u_int sc_overrun_cnt;
 	struct timeval sc_overrun_ntc;
 
-	usb_callout_t sc_tmo_rhsc;
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	device_ptr_t sc_child;
-#endif
+	struct callout sc_tmo_rhsc;
 	char sc_dying;
 } ohci_softc_t;
 
@@ -157,20 +151,14 @@
 	struct usb_task	abort_task;
 	u_int32_t ohci_xfer_flags;
 };
-#define OHCI_ISOC_DIRTY  0x01
-#define OHCI_XFER_ABORTING	0x02	/* xfer is aborting. */
-#define OHCI_XFER_ABORTWAIT	0x04	/* abort completion is being awaited. */
+#define OHCI_XFER_ABORTING	0x01	/* xfer is aborting. */
+#define OHCI_XFER_ABORTWAIT	0x02	/* abort completion is being awaited. */
 
 #define OXFER(xfer) ((struct ohci_xfer *)(xfer))
+#define MS_TO_TICKS(ms) ((ms) * hz / 1000)
 
 usbd_status	ohci_init(ohci_softc_t *);
-int		ohci_intr(void *);
+void		ohci_intr(void *);
 int	 	ohci_detach(ohci_softc_t *, int);
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int		ohci_activate(device_ptr_t, enum devact);
-#endif
-
-#define MS_TO_TICKS(ms) ((ms) * hz / 1000)
-
 void		ohci_shutdown(void *v);
 void		ohci_power(int state, void *priv);
Index: if_cuereg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_cuereg.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_cuereg.h -L sys/dev/usb/if_cuereg.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_cuereg.h
+++ sys/dev/usb/if_cuereg.h
@@ -29,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/if_cuereg.h,v 1.18 2005/06/10 16:49:15 brooks Exp $
+ * $FreeBSD: src/sys/dev/usb/if_cuereg.h,v 1.20 2007/06/11 05:42:47 imp Exp $
  */
 
 /*
@@ -148,15 +148,12 @@
 	usbd_interface_handle	cue_iface;
 	int			cue_ed[CUE_ENDPT_MAX];
 	usbd_pipe_handle	cue_ep[CUE_ENDPT_MAX];
-	int			cue_unit;
 	u_int8_t		cue_mctab[CUE_MCAST_TABLE_LEN];
 	int			cue_if_flags;
 	u_int16_t		cue_rxfilt;
 	struct ue_cdata		cue_cdata;
 	struct callout_handle	cue_stat_ch;
-#if __FreeBSD_version >= 500000
 	struct mtx		cue_mtx;
-#endif
 	char			cue_dying;
 	struct timeval		cue_rx_notice;
 	struct usb_qdat		cue_qdat;
Index: urio.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/urio.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/urio.c -L sys/dev/usb/urio.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/urio.c
+++ sys/dev/usb/urio.c
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/urio.c,v 1.35 2005/01/06 01:43:29 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/urio.c,v 1.48 2007/06/21 14:42:34 imp Exp $");
 
 
 /*
@@ -48,25 +48,16 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__)
-#include <sys/device.h>
-#include <sys/ioctl.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/ioccom.h>
-#endif
 #include <sys/fcntl.h>
 #include <sys/filio.h>
 #include <sys/conf.h>
 #include <sys/uio.h>
 #include <sys/tty.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/poll.h>
 #include <sys/sysctl.h>
 #include <sys/uio.h>
@@ -79,8 +70,8 @@
 #include <dev/usb/rio500_usb.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (uriodebug) logprintf x
-#define DPRINTFN(n,x)	if (uriodebug>(n)) logprintf x
+#define DPRINTF(x)	if (uriodebug) printf x
+#define DPRINTFN(n,x)	if (uriodebug>(n)) printf x
 int	uriodebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, urio, CTLFLAG_RW, 0, "USB urio");
 SYSCTL_INT(_hw_usb_urio, OID_AUTO, debug, CTLFLAG_RW,
@@ -97,18 +88,6 @@
 #define RIO_IN  1
 #define RIO_NODIR  2
 
-#if defined(__NetBSD__)
-int urioopen(dev_t, int, int, struct proc *);
-int urioclose(dev_t, int, int, struct proc *p);
-int urioread(dev_t, struct uio *uio, int);
-int uriowrite(dev_t, struct uio *uio, int);
-int urioioctl(dev_t, u_long, caddr_t, int, struct proc *);
-
-cdev_decl(urio);
-#define RIO_UE_GET_DIR(p) ((UE_GET_DIR(p) == UE_DIR_IN) ? RIO_IN :\
-			  ((UE_GET_DIR(p) == UE_DIR_OUT) ? RIO_OUT :\
-							   RIO_NODIR))
-#elif defined(__FreeBSD__)
 d_open_t  urioopen;
 d_close_t urioclose;
 d_read_t  urioread;
@@ -116,7 +95,7 @@
 d_ioctl_t urioioctl;
 
 
-Static struct cdevsw urio_cdevsw = {
+static struct cdevsw urio_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
 	.d_open =	urioopen,
@@ -125,19 +104,15 @@
 	.d_write =	uriowrite,
 	.d_ioctl =	urioioctl,
 	.d_name =	"urio",
-#if __FreeBSD_version < 500014
- 	.d_bmaj =	-1
-#endif
 };
 #define RIO_UE_GET_DIR(p) ((UE_GET_DIR(p) == UE_DIR_IN) ? RIO_IN :\
 		 	  ((UE_GET_DIR(p) == UE_DIR_OUT) ? RIO_OUT :\
 			    				   RIO_NODIR))
-#endif  /*defined(__FreeBSD__)*/
 
 #define	URIO_BBSIZE	1024
 
 struct urio_softc {
- 	USBBASEDEVICE sc_dev;
+ 	device_t sc_dev;
 	usbd_device_handle sc_udev;
 	usbd_interface_handle sc_iface;
 
@@ -147,23 +122,39 @@
 	int sc_epaddr[2];
 
 	int sc_refcnt;
-#if defined(__FreeBSD__)
 	struct cdev *sc_dev_t;
-#endif	/* defined(__FreeBSD__) */
-#if defined(__NetBSD__) || defined(__OpenBSD__)
 	u_char sc_dying;
-#endif
 };
 
 #define URIOUNIT(n) (minor(n))
 
 #define RIO_RW_TIMEOUT 4000	/* ms */
 
-USB_DECLARE_DRIVER(urio);
+static device_probe_t urio_match;
+static device_attach_t urio_attach;
+static device_detach_t urio_detach;
+
+static device_method_t urio_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		urio_match),
+	DEVMETHOD(device_attach,	urio_attach),
+	DEVMETHOD(device_detach,	urio_detach),
 
-USB_MATCH(urio)
+	{ 0, 0 }
+};
+
+static driver_t urio_driver = {
+	"urio",
+	urio_methods,
+	sizeof(struct urio_softc)
+};
+
+static devclass_t urio_devclass;
+
+static int
+urio_match(device_t self)
 {
-	USB_MATCH_START(urio, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_device_descriptor_t *dd;
 
 	DPRINTFN(10,("urio_match\n"));
@@ -183,49 +174,27 @@
 		return UMATCH_NONE;
 }
 
-USB_ATTACH(urio)
+static int
+urio_attach(device_t self)
 {
-	USB_ATTACH_START(urio, sc, uaa);
-	char devinfo[1024];
+	struct urio_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle udev;
 	usbd_interface_handle iface;
 	u_int8_t epcount;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	u_int8_t niface;
-#endif
 	usbd_status r;
 	char * ermsg = "<none>";
 	int i;
 
 	DPRINTFN(10,("urio_attach: sc=%p\n", sc));
-	usbd_devinfo(uaa->device, 0, devinfo);
-	USB_ATTACH_SETUP;
-
+	sc->sc_dev = self;
 	sc->sc_udev = udev = uaa->device;
 
-#if defined(__FreeBSD__)
  	if ((!uaa->device) || (!uaa->iface)) {
 		ermsg = "device or iface";
  		goto nobulk;
 	}
 	sc->sc_iface = iface = uaa->iface;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
- 	if (!udev) {
-		ermsg = "device";
- 		goto nobulk;
-	}
-	r = usbd_interface_count(udev, &niface);
-	if (r) {
-		ermsg = "iface";
-		goto nobulk;
-	}
-	r = usbd_device2interface_handle(udev, 0, &iface);
-	if (r) {
-		ermsg = "iface";
-		goto nobulk;
-	}
-	sc->sc_iface = iface;
-#endif
 	sc->sc_opened = 0;
 	sc->sc_pipeh_in = 0;
 	sc->sc_pipeh_out = 0;
@@ -260,34 +229,27 @@
 		goto nobulk;
 	}
 
-#if defined(__FreeBSD__)
-	/* XXX no error trapping, no storing of struct cdev **/
 	sc->sc_dev_t = make_dev(&urio_cdevsw, device_get_unit(self),
 			UID_ROOT, GID_OPERATOR,
 			0644, "urio%d", device_get_unit(self));
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
-#endif
-
 	DPRINTFN(10, ("urio_attach: %p\n", sc->sc_udev));
 
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
  nobulk:
-	printf("%s: could not find %s\n", USBDEVNAME(sc->sc_dev),ermsg);
-	USB_ATTACH_ERROR_RETURN;
+	printf("%s: could not find %s\n", device_get_nameunit(sc->sc_dev),ermsg);
+	return ENXIO;
 }
 
 
 int
-urioopen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+urioopen(struct cdev *dev, int flag, int mode, struct thread *p)
 {
-#if (USBDI >= 1)
 	struct urio_softc * sc;
-#endif
 	int unit = URIOUNIT(dev);
-	USB_GET_SC_OPEN(urio, unit, sc);
+	sc = devclass_get_softc(urio_devclass, unit);
+	if (sc == NULL)
+		return (ENXIO);
 
 	DPRINTFN(5, ("urioopen: flag=%d, mode=%d, unit=%d\n",
 		     flag, mode, unit));
@@ -321,13 +283,11 @@
 }
 
 int
-urioclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+urioclose(struct cdev *dev, int flag, int mode, struct thread *p)
 {
-#if (USBDI >= 1)
 	struct urio_softc * sc;
-#endif
 	int unit = URIOUNIT(dev);
-	USB_GET_SC(urio, unit, sc);
+	sc = devclass_get_softc(urio_devclass, unit);
 
 	DPRINTFN(5, ("urioclose: flag=%d, mode=%d, unit=%d\n", flag, mode, unit));
 	if (sc->sc_pipeh_in)
@@ -346,49 +306,29 @@
 int
 urioread(struct cdev *dev, struct uio *uio, int flag)
 {
-#if (USBDI >= 1)
 	struct urio_softc * sc;
 	usbd_xfer_handle reqh;
-#else
-	usbd_request_handle reqh;
-	usbd_private_handle r_priv;
-        void *r_buff;
-        usbd_status r_status;
-#endif
 	int unit = URIOUNIT(dev);
 	usbd_status r;
 	char buf[URIO_BBSIZE];
 	u_int32_t n, tn;
 	int error = 0;
 
-	USB_GET_SC(urio, unit, sc);
+	sc = devclass_get_softc(urio_devclass, unit);
 
 	DPRINTFN(5, ("urioread: %d\n", unit));
 	if (!sc->sc_opened)
 		return EIO;
 
-#if (USBDI >= 1)
 	sc->sc_refcnt++;
 	reqh = usbd_alloc_xfer(sc->sc_udev);
-#else
-	reqh = usbd_alloc_request();
-#endif
 	if (reqh == 0)
 		return ENOMEM;
 	while ((n = min(URIO_BBSIZE, uio->uio_resid)) != 0) {
 		DPRINTFN(1, ("urioread: start transfer %d bytes\n", n));
 		tn = n;
-#if (USBDI >= 1)
  		usbd_setup_xfer(reqh, sc->sc_pipeh_in, 0, buf, tn,
 				       0, RIO_RW_TIMEOUT, 0);
-#else
-		r = usbd_setup_request(reqh, sc->sc_pipeh_in, 0, buf, tn,
-				       0, RIO_RW_TIMEOUT, 0);
-		if (r != USBD_NORMAL_COMPLETION) {
-			error = EIO;
-			break;
-		}
-#endif
 		r = usbd_sync_transfer(reqh);
 		if (r != USBD_NORMAL_COMPLETION) {
 			DPRINTFN(1, ("urioread: error=%d\n", r));
@@ -397,53 +337,35 @@
 			error = EIO;
 			break;
 		}
-#if (USBDI >= 1)
 		usbd_get_xfer_status(reqh, 0, 0, &tn, 0);
-#else
-		usbd_get_request_status(reqh, &r_priv, &r_buff, &tn, &r_status);
-#endif
 
 		DPRINTFN(1, ("urioread: got %d bytes\n", tn));
 		error = uiomove(buf, tn, uio);
 		if (error || tn < n)
 			break;
 	}
-#if (USBDI >= 1)
 	usbd_free_xfer(reqh);
-#else
-	usbd_free_request(reqh);
-#endif
-
 	return error;
 }
 
 int
 uriowrite(struct cdev *dev, struct uio *uio, int flag)
 {
-#if (USBDI >= 1)
 	struct urio_softc * sc;
 	usbd_xfer_handle reqh;
-#else
-	usbd_request_handle reqh;
-#endif
 	int unit = URIOUNIT(dev);
 	usbd_status r;
 	char buf[URIO_BBSIZE];
 	u_int32_t n;
 	int error = 0;
 
-	USB_GET_SC(urio, unit, sc);
-
+	sc = devclass_get_softc(urio_devclass, unit);
 	DPRINTFN(5, ("uriowrite: %d\n", unit));
 	if (!sc->sc_opened)
 		return EIO;
 
-#if (USBDI >= 1)
 	sc->sc_refcnt++;
 	reqh = usbd_alloc_xfer(sc->sc_udev);
-#else
-	reqh = usbd_alloc_request();
-#endif
 	if (reqh == 0)
 		return EIO;
 	while ((n = min(URIO_BBSIZE, uio->uio_resid)) != 0) {
@@ -451,17 +373,8 @@
 		if (error)
 			break;
 		DPRINTFN(1, ("uriowrite: transfer %d bytes\n", n));
-#if (USBDI >= 1)
  		usbd_setup_xfer(reqh, sc->sc_pipeh_out, 0, buf, n,
 				       0, RIO_RW_TIMEOUT, 0);
-#else
-		r = usbd_setup_request(reqh, sc->sc_pipeh_out, 0, buf, n,
-				       0, RIO_RW_TIMEOUT, 0);
-		if (r != USBD_NORMAL_COMPLETION) {
-			error = EIO;
-			break;
-		}
-#endif
 		r = usbd_sync_transfer(reqh);
 		if (r != USBD_NORMAL_COMPLETION) {
 			DPRINTFN(1, ("uriowrite: error=%d\n", r));
@@ -469,27 +382,18 @@
 			error = EIO;
 			break;
 		}
-#if (USBDI >= 1)
 		usbd_get_xfer_status(reqh, 0, 0, 0, 0);
-#endif
 	}
 
-#if (USBDI >= 1)
 	usbd_free_xfer(reqh);
-#else
-	usbd_free_request(reqh);
-#endif
-
 	return error;
 }
 
 
 int
-urioioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p)
+urioioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *p)
 {
-#if (USBDI >= 1)
 	struct urio_softc * sc;
-#endif
 	int unit = URIOUNIT(dev);
 	struct RioCommand *rio_cmd;
 	int requesttype, len;
@@ -501,8 +405,7 @@
 	int error = 0;
 	usbd_status r;
 
-	USB_GET_SC(urio, unit, sc);
-
+	sc = devclass_get_softc(urio_devclass, unit);
 	switch (cmd) {
 	case RIO_RECV_COMMAND:
 		if (!(flag & FWRITE))
@@ -555,7 +458,7 @@
 		uio.uio_rw =
 			req.bmRequestType & UT_READ ?
 			UIO_READ : UIO_WRITE;
-		uio.uio_procp = p;
+		uio.uio_td = p;
 		ptr = malloc(len, M_TEMP, M_WAITOK);
 		if (uio.uio_rw == UIO_WRITE) {
 			error = uiomove(ptr, len, &uio);
@@ -584,60 +487,14 @@
 	return error;
 }
 
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-urio_activate(device_ptr_t self, enum devact act)
-{
-	struct urio_softc *sc = (struct urio_softc *)self;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-		break;
-
-	case DVACT_DEACTIVATE:
-		sc->sc_dying = 1;
-		break;
-	}
-	return (0);
-}
-
-USB_DETACH(urio)
+static int
+urio_detach(device_t self)
 {
-	USB_DETACH_START(urio, sc);
-	struct urio_endpoint *sce;
-	int i, dir;
+	struct urio_softc *sc = device_get_softc(self);
 	int s;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	int maj, mn;
 
-	DPRINTF(("urio_detach: sc=%p flags=%d\n", sc, flags));
-#elif defined(__FreeBSD__)
 	DPRINTF(("urio_detach: sc=%p\n", sc));
-#endif
-
 	sc->sc_dying = 1;
-	/* Abort all pipes.  Causes processes waiting for transfer to wake. */
-#if 0
-	for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
-		for (dir = OUT; dir <= IN; dir++) {
-			sce = &sc->sc_endpoints[i][dir];
-			if (sce && sce->pipeh)
-				usbd_abort_pipe(sce->pipeh);
-		}
-	}
-
-	s = splusb();
-	if (--sc->sc_refcnt >= 0) {
-		/* Wake everyone */
-		for (i = 0; i < USB_MAX_ENDPOINTS; i++)
-			wakeup(&sc->sc_endpoints[i][IN]);
-		/* Wait for processes to go away. */
-		usb_detach_wait(USBDEV(sc->sc_dev));
-	}
-	splx(s);
-#else
 	if (sc->sc_pipeh_in)
 		usbd_abort_pipe(sc->sc_pipeh_in);
 
@@ -647,41 +504,15 @@
 	s = splusb();
 	if (--sc->sc_refcnt >= 0) {
 		/* Wait for processes to go away. */
-		usb_detach_wait(USBDEV(sc->sc_dev));
+		usb_detach_wait(sc->sc_dev);
 	}
 	splx(s);
-#endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	/* locate the major number */
-	for (maj = 0; maj < nchrdev; maj++)
-		if (cdevsw[maj].d_open == urioopen)
-			break;
-
-	/* Nuke the vnodes for any open instances (calls close). */
-	mn = self->dv_unit * USB_MAX_ENDPOINTS;
-	vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);
-#endif
-
-	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
-
-	return (0);
-}
-#endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
-
-#if defined(__FreeBSD__)
-Static int
-urio_detach(device_t self)
-{
-	struct urio_softc *sc = device_get_softc(self);
-
-	DPRINTF(("%s: disconnected\n", USBDEVNAME(self)));
 	destroy_dev(sc->sc_dev_t);
 	/* XXX not implemented yet */
 	device_set_desc(self, NULL);
 	return 0;
 }
 
+MODULE_DEPEND(uscanner, usb, 1, 1, 1);
 DRIVER_MODULE(urio, uhub, urio_driver, urio_devclass, usbd_driver_load, 0);
-#endif
Index: ulpt.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ulpt.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ulpt.c -L sys/dev/usb/ulpt.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ulpt.c
+++ sys/dev/usb/ulpt.c
@@ -38,25 +38,22 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ulpt.c,v 1.66.2.1 2005/11/20 03:18:22 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ulpt.c,v 1.80 2007/06/21 14:42:34 imp Exp $");
 
 /*
  * Printer Class spec: http://www.usb.org/developers/data/devclass/usbprint109.PDF
  */
 
+/* XXXimp: need to migrate from devclass_get_softc */
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/kernel.h>
 #include <sys/fcntl.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#include <sys/ioctl.h>
-#elif defined(__FreeBSD__)
 #include <sys/ioccom.h>
 #include <sys/module.h>
 #include <sys/bus.h>
-#endif
 #include <sys/uio.h>
 #include <sys/conf.h>
 #include <sys/syslog.h>
@@ -78,8 +75,8 @@
 #define ULPT_READ_TIMO 10
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (ulptdebug) logprintf x
-#define DPRINTFN(n,x)	if (ulptdebug>(n)) logprintf x
+#define DPRINTF(x)	if (ulptdebug) printf x
+#define DPRINTFN(n,x)	if (ulptdebug>(n)) printf x
 int	ulptdebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, ulpt, CTLFLAG_RW, 0, "USB ulpt");
 SYSCTL_INT(_hw_usb_ulpt, OID_AUTO, debug, CTLFLAG_RW,
@@ -100,7 +97,7 @@
 #define LPS_MASK        (LPS_SELECT|LPS_NERR|LPS_NOPAPER)
 
 struct ulpt_softc {
-	USBBASEDEVICE sc_dev;
+	device_t sc_dev;
 	usbd_device_handle sc_udev;	/* device */
 	usbd_interface_handle sc_iface;	/* interface */
 	int sc_ifaceno;
@@ -115,7 +112,7 @@
 	usbd_xfer_handle sc_in_xfer;
 	void *sc_in_buf;
 
-	usb_callout_t sc_read_callout;
+	struct callout sc_read_callout;
 	int sc_has_callout;
 
 	u_char sc_state;
@@ -129,34 +126,18 @@
 	int sc_refcnt;
 	u_char sc_dying;
 
-#if defined(__FreeBSD__)
 	struct cdev *dev;
 	struct cdev *dev_noprime;
-#endif
 };
 
-#if defined(__NetBSD__)
-dev_type_open(ulptopen);
-dev_type_close(ulptclose);
-dev_type_write(ulptwrite);
-dev_type_read(ulptread);
-dev_type_ioctl(ulptioctl);
-
-const struct cdevsw ulpt_cdevsw = {
-	ulptopen, ulptclose, ulptread, ulptwrite, ulptioctl,
-	nostop, notty, nopoll, nommap, nokqfilter,
-};
-#elif defined(__OpenBSD__)
-cdev_decl(ulpt);
-#elif defined(__FreeBSD__)
-Static d_open_t ulptopen;
-Static d_close_t ulptclose;
-Static d_write_t ulptwrite;
-Static d_read_t ulptread;
-Static d_ioctl_t ulptioctl;
+static d_open_t ulptopen;
+static d_close_t ulptclose;
+static d_write_t ulptwrite;
+static d_read_t ulptread;
+static d_ioctl_t ulptioctl;
 
 
-Static struct cdevsw ulpt_cdevsw = {
+static struct cdevsw ulpt_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
 	.d_open =	ulptopen,
@@ -165,11 +146,7 @@
 	.d_read =	ulptread,
 	.d_ioctl =	ulptioctl,
 	.d_name =	"ulpt",
-#if __FreeBSD_version < 500014
-	.d_bmaj		-1
-#endif
 };
-#endif
 
 void ulpt_disco(void *);
 
@@ -189,12 +166,34 @@
 #define	ULPTUNIT(s)	(minor(s) & 0x1f)
 #define	ULPTFLAGS(s)	(minor(s) & 0xe0)
 
+static device_probe_t ulpt_match;
+static device_attach_t ulpt_attach;
+static device_detach_t ulpt_detach;
+
+static device_method_t ulpt_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		ulpt_match),
+	DEVMETHOD(device_attach,	ulpt_attach),
+	DEVMETHOD(device_detach,	ulpt_detach),
 
-USB_DECLARE_DRIVER(ulpt);
+	{ 0, 0 }
+};
+
+static driver_t ulpt_driver = {
+	"ulpt",
+	ulpt_methods,
+	sizeof(struct ulpt_softc)
+};
+
+static devclass_t ulpt_devclass;
+
+MODULE_DEPEND(umass, usb, 1, 1, 1);
+DRIVER_MODULE(ulpt, uhub, ulpt_driver, ulpt_devclass, usbd_driver_load, 0);
 
-USB_MATCH(ulpt)
+static int
+ulpt_match(device_t self)
 {
-	USB_MATCH_START(ulpt, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_interface_descriptor_t *id;
 
 	DPRINTFN(10,("ulpt_match\n"));
@@ -211,23 +210,23 @@
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(ulpt)
+static int
+ulpt_attach(device_t self)
 {
-	USB_ATTACH_START(ulpt, sc, uaa);
+	struct ulpt_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev = uaa->device;
 	usbd_interface_handle iface = uaa->iface;
 	usb_interface_descriptor_t *ifcd = usbd_get_interface_descriptor(iface);
 	usb_interface_descriptor_t *id, *iend;
 	usb_config_descriptor_t *cdesc;
 	usbd_status err;
-	char devinfo[1024];
 	usb_endpoint_descriptor_t *ed;
 	u_int8_t epcount;
 	int i, altno;
 
 	DPRINTFN(10,("ulpt_attach: sc=%p\n", sc));
-	usbd_devinfo(uaa->device, USBD_SHOW_INTERFACE_CLASS, devinfo);
-	USB_ATTACH_SETUP;
+	sc->sc_dev = self;
 
 	/* XXX
 	 * Stepping through the alternate settings needs to be abstracted out.
@@ -235,8 +234,8 @@
 	cdesc = usbd_get_config_descriptor(dev);
 	if (cdesc == NULL) {
 		printf("%s: failed to get configuration descriptor\n",
-		       USBDEVNAME(sc->sc_dev));
-		USB_ATTACH_ERROR_RETURN;
+		       device_get_nameunit(sc->sc_dev));
+		return ENXIO;
 	}
 	iend = (usb_interface_descriptor_t *)
 		   ((char *)cdesc + UGETW(cdesc->wTotalLength));
@@ -267,9 +266,9 @@
 		err = usbd_set_interface(iface, altno);
 		if (err) {
 			printf("%s: setting alternate interface failed\n",
-			       USBDEVNAME(sc->sc_dev));
+			       device_get_nameunit(sc->sc_dev));
 			sc->sc_dying = 1;
-			USB_ATTACH_ERROR_RETURN;
+			return ENXIO;
 		}
 	}
 
@@ -282,8 +281,8 @@
 		ed = usbd_interface2endpoint_descriptor(iface, i);
 		if (ed == NULL) {
 			printf("%s: couldn't get ep %d\n",
-			    USBDEVNAME(sc->sc_dev), i);
-			USB_ATTACH_ERROR_RETURN;
+			    device_get_nameunit(sc->sc_dev), i);
+			return ENXIO;
 		}
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
@@ -295,9 +294,9 @@
 	}
 	if (sc->sc_out == -1) {
 		printf("%s: could not find bulk out endpoint\n",
-		    USBDEVNAME(sc->sc_dev));
+		    device_get_nameunit(sc->sc_dev));
 		sc->sc_dying = 1;
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 
 	if (usbd_get_quirks(dev)->uq_flags & UQ_BROKEN_BIDIR) {
@@ -305,7 +304,7 @@
 		sc->sc_in = -1;
 	}
 
-	printf("%s: using %s-directional mode\n", USBDEVNAME(sc->sc_dev),
+	printf("%s: using %s-directional mode\n", device_get_nameunit(sc->sc_dev),
 	       sc->sc_in >= 0 ? "bi" : "uni");
 
 	DPRINTFN(10, ("ulpt_attach: bulk=%d\n", sc->sc_out));
@@ -333,68 +332,42 @@
 	err = usbd_do_request_flags(dev, &req, devinfo, USBD_SHORT_XFER_OK,
 		  &alen, USBD_DEFAULT_TIMEOUT);
 	if (err) {
-		printf("%s: cannot get device id\n", USBDEVNAME(sc->sc_dev));
+		printf("%s: cannot get device id\n", device_get_nameunit(sc->sc_dev));
 	} else if (alen <= 2) {
 		printf("%s: empty device id, no printer connected?\n",
-		       USBDEVNAME(sc->sc_dev));
+		       device_get_nameunit(sc->sc_dev));
 	} else {
 		/* devinfo now contains an IEEE-1284 device ID */
 		len = ((devinfo[0] & 0xff) << 8) | (devinfo[1] & 0xff);
 		if (len > sizeof devinfo - 3)
 			len = sizeof devinfo - 3;
 		devinfo[len] = 0;
-		printf("%s: device id <", USBDEVNAME(sc->sc_dev));
+		printf("%s: device id <", device_get_nameunit(sc->sc_dev));
 		ieee1284_print_id(devinfo+2);
 		printf(">\n");
 	}
 	}
 #endif
 
-#if defined(__FreeBSD__)
 	sc->dev = make_dev(&ulpt_cdevsw, device_get_unit(self),
 		UID_ROOT, GID_OPERATOR, 0644, "ulpt%d", device_get_unit(self));
 	sc->dev_noprime = make_dev(&ulpt_cdevsw,
 		device_get_unit(self)|ULPT_NOPRIME,
 		UID_ROOT, GID_OPERATOR, 0644, "unlpt%d", device_get_unit(self));
-#endif
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev);
 
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-ulpt_activate(device_ptr_t self, enum devact act)
-{
-	struct ulpt_softc *sc = (struct ulpt_softc *)self;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		sc->sc_dying = 1;
-		break;
-	}
-	return (0);
-}
-#endif
 
-USB_DETACH(ulpt)
+static int
+ulpt_detach(device_t self)
 {
-	USB_DETACH_START(ulpt, sc);
+	struct ulpt_softc *sc = device_get_softc(self);
 	int s;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	int maj, mn;
-#endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	DPRINTF(("ulpt_detach: sc=%p flags=%d\n", sc, flags));
-#elif defined(__FreeBSD__)
 	DPRINTF(("ulpt_detach: sc=%p\n", sc));
-#endif
 
 	sc->sc_dying = 1;
 	if (sc->sc_out_pipe != NULL)
@@ -406,30 +379,14 @@
 	if (--sc->sc_refcnt >= 0) {
 		/* There is noone to wake, aborting the pipe is enough */
 		/* Wait for processes to go away. */
-		usb_detach_wait(USBDEV(sc->sc_dev));
+		usb_detach_wait(sc->sc_dev);
 	}
 	splx(s);
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	/* locate the major number */
-#if defined(__NetBSD__)
-	maj = cdevsw_lookup_major(&ulpt_cdevsw);
-#elif defined(__OpenBSD__)
-	for (maj = 0; maj < nchrdev; maj++)
-		if (cdevsw[maj].d_open == ulptopen)
-			break;
-#endif
-
-	/* Nuke the vnodes for any open instances (calls close). */
-	mn = self->dv_unit;
-	vdevgone(maj, mn, mn, VCHR);
-#elif defined(__FreeBSD__)
 	destroy_dev(sc->dev);
 	destroy_dev(sc->dev_noprime);
-#endif
 
-	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
+	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
 
 	return (0);
 }
@@ -504,14 +461,16 @@
  * Reset the printer, then wait until it's selected and not busy.
  */
 int
-ulptopen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+ulptopen(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	u_char flags = ULPTFLAGS(dev);
 	struct ulpt_softc *sc;
 	usbd_status err;
-	int spin, error;
+	int error;
 
-	USB_GET_SC_OPEN(ulpt, ULPTUNIT(dev), sc);
+	sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
+	if (sc == NULL)
+		return (ENXIO);
 
 	if (sc == NULL || sc->sc_iface == NULL || sc->sc_dying)
 		return (ENXIO);
@@ -523,7 +482,7 @@
 	sc->sc_flags = flags;
 	DPRINTF(("ulptopen: flags=0x%x\n", (unsigned)flags));
 
-#if defined(USB_DEBUG) && defined(__FreeBSD__)
+#if defined(USB_DEBUG)
 	/* Ignoring these flags might not be a good idea */
 	if ((flags & ~ULPT_NOPRIME) != 0)
 		printf("ulptopen: flags ignored: %b\n", flags,
@@ -543,28 +502,6 @@
 		}
 	}
 
-	for (spin = 0; (ulpt_status(sc) & LPS_SELECT) == 0; spin += STEP) {
-		DPRINTF(("ulpt_open: waiting a while\n"));
-		if (spin >= TIMEOUT) {
-			error = EBUSY;
-			sc->sc_state = 0;
-			goto done;
-		}
-
-		/* wait 1/4 second, give up if we get a signal */
-		error = tsleep(sc, LPTPRI | PCATCH, "ulptop", STEP);
-		if (error != EWOULDBLOCK) {
-			sc->sc_state = 0;
-			goto done;
-		}
-
-		if (sc->sc_dying) {
-			error = ENXIO;
-			sc->sc_state = 0;
-			goto done;
-		}
-	}
-
 	err = usbd_open_pipe(sc->sc_iface, sc->sc_out, 0, &sc->sc_out_pipe);
 	if (err) {
 		error = EIO;
@@ -602,8 +539,9 @@
 		/* If it's not opened for read the set up a reader. */
 		if (!(flag & FREAD)) {
 			DPRINTF(("ulpt_open: start read callout\n"));
-			usb_callout_init(sc->sc_read_callout);
-			usb_callout(sc->sc_read_callout, hz/5, ulpt_tick, sc);
+			callout_init(&sc->sc_read_callout, 0);
+			callout_reset(&sc->sc_read_callout, hz/5, ulpt_tick,
+			    sc);
 			sc->sc_has_callout = 1;
 		}
 	}
@@ -628,7 +566,7 @@
 
  done:
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 
 	DPRINTF(("ulptopen: done, error=%d\n", error));
 	return (error);
@@ -644,28 +582,28 @@
 	sc->sc_laststatus = status;
 
 	if (new & LPS_SELECT)
-		log(LOG_NOTICE, "%s: offline\n", USBDEVNAME(sc->sc_dev));
+		log(LOG_NOTICE, "%s: offline\n", device_get_nameunit(sc->sc_dev));
 	else if (new & LPS_NOPAPER)
-		log(LOG_NOTICE, "%s: out of paper\n", USBDEVNAME(sc->sc_dev));
+		log(LOG_NOTICE, "%s: out of paper\n", device_get_nameunit(sc->sc_dev));
 	else if (new & LPS_NERR)
-		log(LOG_NOTICE, "%s: output error\n", USBDEVNAME(sc->sc_dev));
+		log(LOG_NOTICE, "%s: output error\n", device_get_nameunit(sc->sc_dev));
 
 	return (status);
 }
 
 int
-ulptclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
+ulptclose(struct cdev *dev, int flag, int mode, struct thread *p)
 {
 	struct ulpt_softc *sc;
 
-	USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
+	sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
 
 	if (sc->sc_state != ULPT_OPEN)
 		/* We are being forced to close before the open completed. */
 		return (0);
 
 	if (sc->sc_has_callout) {
-		usb_uncallout(sc->sc_read_callout, ulpt_tick, sc);
+		callout_stop(&sc->sc_read_callout);
 		sc->sc_has_callout = 0;
 	}
 
@@ -731,7 +669,7 @@
 	struct ulpt_softc *sc;
 	int error;
 
-	USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
+	sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
 
 	if (sc->sc_dying)
 		return (EIO);
@@ -739,7 +677,7 @@
 	sc->sc_refcnt++;
 	error = ulpt_do_write(sc, uio, flags);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	return (error);
 }
 
@@ -786,7 +724,7 @@
 	struct ulpt_softc *sc;
 	int error;
 
-	USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
+	sc = devclass_get_softc(ulpt_devclass, ULPTUNIT(dev));
 
 	if (sc->sc_dying)
 		return (EIO);
@@ -794,7 +732,7 @@
 	sc->sc_refcnt++;
 	error = ulpt_do_read(sc, uio, flags);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_wakeup(USBDEV(sc->sc_dev));
+		usb_detach_wakeup(sc->sc_dev);
 	return (error);
 }
 
@@ -817,8 +755,8 @@
 		DPRINTF(("ulpt_tick: discarding %d bytes\n", n));
 #endif
 	if (!err || err == USBD_TIMEOUT)
-		usb_callout(sc->sc_read_callout, hz / ULPT_READS_PER_SEC,
-			    ulpt_tick, sc);
+		callout_reset(&sc->sc_read_callout, hz / ULPT_READS_PER_SEC,
+		    ulpt_tick, sc);
 }
 
 void
@@ -840,7 +778,7 @@
 }
 
 int
-ulptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
+ulptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *p)
 {
 	int error = 0;
 
@@ -875,7 +813,3 @@
 	}
 }
 #endif
-
-#if defined(__FreeBSD__)
-DRIVER_MODULE(ulpt, uhub, ulpt_driver, ulpt_devclass, usbd_driver_load, 0);
-#endif
Index: umodem.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/umodem.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/umodem.c -L sys/dev/usb/umodem.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/umodem.c
+++ sys/dev/usb/umodem.c
@@ -2,7 +2,7 @@
 
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/umodem.c,v 1.57 2005/01/31 13:58:10 akiyama Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/umodem.c,v 1.71 2007/07/29 18:16:43 imp Exp $");
 /*-
  * Copyright (c) 2003, M. Warner Losh <imp at freebsd.org>.
  * All rights reserved.
@@ -112,7 +112,7 @@
 SYSCTL_NODE(_hw_usb, OID_AUTO, umodem, CTLFLAG_RW, 0, "USB umodem");
 SYSCTL_INT(_hw_usb_umodem, OID_AUTO, debug, CTLFLAG_RW,
 	   &umodemdebug, 0, "umodem debug level");
-#define DPRINTFN(n, x)	if (umodemdebug > (n)) logprintf x
+#define DPRINTFN(n, x)	if (umodemdebug > (n)) printf x
 #else
 #define DPRINTFN(n, x)
 #endif
@@ -125,23 +125,25 @@
 } umodem_products[] = {
 	/* Kyocera AH-K3001V*/
 	{ USB_VENDOR_KYOCERA, USB_PRODUCT_KYOCERA_AHK3001V, 0 },
+	{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720, 0 },
+	{ USB_VENDOR_CURITEL, USB_PRODUCT_CURITEL_PC5740, 0 },
 	{ 0, 0, 0 },
 };
 
 /*
  * These are the maximum number of bytes transferred per frame.
- * If some really high speed devices should use this driver they
- * may need to be increased, but this is good enough for normal modems.
+ * As speeds for umodem deivces increase, these numbers will need to
+ * be increased.  They should be good for G3 speeds and below.
  */
-#define UMODEMIBUFSIZE 64
-#define UMODEMOBUFSIZE 256
+#define UMODEMIBUFSIZE 1024
+#define UMODEMOBUFSIZE 1024
 
 #define UMODEM_MODVER			1	/* module version */
 
 struct umodem_softc {
 	struct ucom_softc	sc_ucom;
 
-	USBBASEDEVICE		sc_dev;		/* base device */
+	device_t		sc_dev;		/* base device */
 
 	usbd_device_handle	sc_udev;	/* USB device */
 
@@ -170,28 +172,28 @@
 	struct task		sc_task;
 };
 
-Static void	*umodem_get_desc(usbd_device_handle dev, int type, int subtype);
-Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
+static void	*umodem_get_desc(usbd_device_handle dev, int type, int subtype);
+static usbd_status umodem_set_comm_feature(struct umodem_softc *sc,
 					   int feature, int state);
-Static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
+static usbd_status umodem_set_line_coding(struct umodem_softc *sc,
 					  usb_cdc_line_state_t *state);
 
-Static void	umodem_get_caps(usbd_device_handle, int *, int *);
+static void	umodem_get_caps(usbd_device_handle, int *, int *);
 
-Static void	umodem_get_status(void *, int portno, u_char *lsr, u_char *msr);
-Static void	umodem_set(void *, int, int, int);
-Static void	umodem_dtr(struct umodem_softc *, int);
-Static void	umodem_rts(struct umodem_softc *, int);
-Static void	umodem_break(struct umodem_softc *, int);
-Static void	umodem_set_line_state(struct umodem_softc *);
-Static int	umodem_param(void *, int, struct termios *);
-Static int	umodem_ioctl(void *, int, u_long, caddr_t, int, usb_proc_ptr );
-Static int	umodem_open(void *, int portno);
-Static void	umodem_close(void *, int portno);
-Static void	umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void	umodem_notify(void *, int);
+static void	umodem_get_status(void *, int portno, u_char *lsr, u_char *msr);
+static void	umodem_set(void *, int, int, int);
+static void	umodem_dtr(struct umodem_softc *, int);
+static void	umodem_rts(struct umodem_softc *, int);
+static void	umodem_break(struct umodem_softc *, int);
+static void	umodem_set_line_state(struct umodem_softc *);
+static int	umodem_param(void *, int, struct termios *);
+static int	umodem_ioctl(void *, int, u_long, caddr_t, int, struct thread *);
+static int	umodem_open(void *, int portno);
+static void	umodem_close(void *, int portno);
+static void	umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void	umodem_notify(void *, int);
 
-Static struct ucom_callback umodem_callback = {
+static struct ucom_callback umodem_callback = {
 	umodem_get_status,
 	umodem_set,
 	umodem_param,
@@ -202,11 +204,11 @@
 	NULL,
 };
 
-Static device_probe_t umodem_match;
-Static device_attach_t umodem_attach;
-Static device_detach_t umodem_detach;
+static device_probe_t umodem_match;
+static device_attach_t umodem_attach;
+static device_detach_t umodem_detach;
 
-Static device_method_t umodem_methods[] = {
+static device_method_t umodem_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe, umodem_match),
 	DEVMETHOD(device_attach, umodem_attach),
@@ -214,7 +216,7 @@
 	{ 0, 0 }
 };
 
-Static driver_t umodem_driver = {
+static driver_t umodem_driver = {
 	"ucom",
 	umodem_methods,
 	sizeof (struct umodem_softc)
@@ -225,9 +227,10 @@
 MODULE_DEPEND(umodem, ucom, UCOM_MINVER, UCOM_PREFVER, UCOM_MAXVER);
 MODULE_VERSION(umodem, UMODEM_MODVER);
 
-USB_MATCH(umodem)
+static int
+umodem_match(device_t self)
 {
-	USB_MATCH_START(umodem, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_interface_descriptor_t *id;
 	usb_device_descriptor_t *dd;
 	int cm, acm, i, ret;
@@ -268,54 +271,46 @@
 	return ret;
 }
 
-USB_ATTACH(umodem)
+static int
+umodem_attach(device_t self)
 {
-	USB_ATTACH_START(umodem, sc, uaa);
+	struct umodem_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_device_handle dev = uaa->device;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
 	usb_cdc_cm_descriptor_t *cmd;
-	char *devinfo = NULL;
-	const char *devname;
-	usbd_status err;
 	int data_ifcno;
 	int i;
 	struct ucom_softc *ucom;
 
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
-	usbd_devinfo(dev, 0, devinfo);
 	ucom = &sc->sc_ucom;
 	ucom->sc_dev = self;
 	sc->sc_dev = self;
-	device_set_desc_copy(self, devinfo);
 	ucom->sc_udev = dev;
 	ucom->sc_iface = uaa->iface;
-	/*USB_ATTACH_SETUP; */
 
 	sc->sc_udev = dev;
 	sc->sc_ctl_iface = uaa->iface;
-
-	devname = USBDEVNAME(sc->sc_dev);
-	/* XXX ? use something else ? XXX */
 	id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
-	printf("%s: %s, iclass %d/%d\n", devname, devinfo,
-	  id->bInterfaceClass, id->bInterfaceSubClass);
 	sc->sc_ctl_iface_no = id->bInterfaceNumber;
+	device_printf(self, "iclass %d/%d\n", id->bInterfaceClass,
+	  id->bInterfaceSubClass);
 
 	umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap);
 
 	/* Get the data interface no. */
 	cmd = umodem_get_desc(dev, UDESC_CS_INTERFACE, UDESCSUB_CDC_CM);
 	if (cmd == NULL) {
-		printf("%s: no CM descriptor\n", devname);
+		device_printf(sc->sc_dev, "no CM descriptor\n");
 		goto bad;
 	}
 	sc->sc_data_iface_no = data_ifcno = cmd->bDataInterface;
 
-	printf("%s: data interface %d, has %sCM over data, has %sbreak\n",
-	       devname, data_ifcno,
-	       sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
-	       sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
+	device_printf(sc->sc_dev,
+	    "data interface %d, has %sCM over data, has %sbreak\n",
+	    data_ifcno, sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ",
+	    sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no ");
 
 	/* Get the data interface too. */
 	for (i = 0; i < uaa->nifaces; i++) {
@@ -328,7 +323,7 @@
 		}
 	}
 	if (sc->sc_data_iface == NULL) {
-		printf("%s: no data interface\n", devname);
+		device_printf(sc->sc_dev, "no data interface\n");
 		goto bad;
 	}
 	ucom->sc_iface = sc->sc_data_iface;
@@ -343,8 +338,8 @@
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i);
 		if (ed == NULL) {
-			printf("%s: no endpoint descriptor for %d\n", devname,
-			    i);
+			device_printf(sc->sc_dev,
+			    "no endpoint descriptor for %d\n", i);
 			goto bad;
 		}
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
@@ -357,31 +352,19 @@
         }
 
 	if (ucom->sc_bulkin_no == -1) {
-		printf("%s: Could not find data bulk in\n", devname);
+		device_printf(sc->sc_dev, "Could not find data bulk in\n");
 		goto bad;
 	}
 	if (ucom->sc_bulkout_no == -1) {
-		printf("%s: Could not find data bulk out\n", devname);
+		device_printf(sc->sc_dev, "Could not find data bulk out\n");
 		goto bad;
 	}
 
-	if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) {
-		DPRINTF(("Quirk says to assume CM over data\n"));
+	if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
+		if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
+			umodem_set_comm_feature(sc, UCDC_ABSTRACT_STATE,
+			    UCDC_DATA_MULTIPLEXED);
 		sc->sc_cm_over_data = 1;
-	} else {
-		if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) {
-			if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE)
-				err = umodem_set_comm_feature(sc,
-				    UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED);
-			else
-				err = 0;
-			if (err) {
-				printf("%s: could not set data multiplex mode\n",
-				    devname);
-				goto bad;
-			}
-			sc->sc_cm_over_data = 1;
-		}
 	}
 
 	/*
@@ -402,8 +385,8 @@
 
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
 		    (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
-			printf("%s: status change notification available\n",
-			    devname);
+			device_printf(sc->sc_dev, 
+			    "status change notification available\n");
 			sc->sc_ctl_notify = ed->bEndpointAddress;
 		}
 	}
@@ -421,17 +404,14 @@
 
 	TASK_INIT(&sc->sc_task, 0, umodem_notify, sc);
 	ucom_attach(&sc->sc_ucom);
-
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
  bad:
 	ucom->sc_dying = 1;
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
-Static int
+static int
 umodem_open(void *addr, int portno)
 {
 	struct umodem_softc *sc = addr;
@@ -455,7 +435,7 @@
 	return 0;
 }
 
-Static void
+static void
 umodem_close(void *addr, int portno)
 {
 	struct umodem_softc *sc = addr;
@@ -466,17 +446,19 @@
 	if (sc->sc_notify_pipe != NULL) {
 		err = usbd_abort_pipe(sc->sc_notify_pipe);
 		if (err)
-			printf("%s: abort notify pipe failed: %s\n",
-			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			device_printf(sc->sc_dev, 
+			    "abort notify pipe failed: %s\n",
+			    usbd_errstr(err));
 		err = usbd_close_pipe(sc->sc_notify_pipe);
 		if (err)
-			printf("%s: close notify pipe failed: %s\n",
-			    USBDEVNAME(sc->sc_dev), usbd_errstr(err));
+			device_printf(sc->sc_dev,
+			    "close notify pipe failed: %s\n",
+			    usbd_errstr(err));
 		sc->sc_notify_pipe = NULL;
 	}
 }
 
-Static void
+static void
 umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct umodem_softc *sc = priv;
@@ -488,14 +470,14 @@
 	if (status != USBD_NORMAL_COMPLETION) {
 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
 			return;
-		printf("%s: abnormal status: %s\n", USBDEVNAME(sc->sc_dev),
-		       usbd_errstr(status));
+		device_printf(sc->sc_dev, "abnormal status: %s\n",
+		    usbd_errstr(status));
 		return;
 	}
 
 	if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) {
 		DPRINTF(("%s: unknown message type (%02x) on notify pipe\n",
-			 USBDEVNAME(sc->sc_dev),
+			 device_get_nameunit(sc->sc_dev),
 			 sc->sc_notify_buf.bmRequestType));
 		return;
 	}
@@ -507,13 +489,13 @@
 		 * the bits from the notify message
 		 */
 		if (UGETW(sc->sc_notify_buf.wLength) != 2) {
-			printf("%s: Invalid notification length! (%d)\n",
-			       USBDEVNAME(sc->sc_dev),
-			       UGETW(sc->sc_notify_buf.wLength));
+			device_printf(sc->sc_dev,
+			    "Invalid notification length! (%d)\n",
+			    UGETW(sc->sc_notify_buf.wLength));
 			break;
 		}
 		DPRINTF(("%s: notify bytes = %02x%02x\n",
-			 USBDEVNAME(sc->sc_dev),
+			 device_get_nameunit(sc->sc_dev),
 			 sc->sc_notify_buf.data[0],
 			 sc->sc_notify_buf.data[1]));
 		/* Currently, lsr is always zero. */
@@ -531,13 +513,13 @@
 		break;
 	default:
 		DPRINTF(("%s: unknown notify message: %02x\n",
-			 USBDEVNAME(sc->sc_dev),
+			 device_get_nameunit(sc->sc_dev),
 			 sc->sc_notify_buf.bNotification));
 		break;
 	}
 }
 
-Static void
+static void
 umodem_notify(void *arg, int count)
 {
 	struct umodem_softc *sc;
@@ -630,7 +612,7 @@
 
 int
 umodem_ioctl(void *addr, int portno, u_long cmd, caddr_t data, int flag,
-	     usb_proc_ptr p)
+	     struct thread *p)
 {
 	struct umodem_softc *sc = addr;
 	int error = 0;
@@ -820,9 +802,10 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-USB_DETACH(umodem)
+static int
+umodem_detach(device_t self)
 {
-	USB_DETACH_START(umodem, sc);
+	struct umodem_softc *sc = device_get_softc(self);
 	int rv = 0;
 
 	DPRINTF(("umodem_detach: sc=%p\n", sc));
Index: if_rue.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_rue.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/usb/if_rue.c -L sys/dev/usb/if_rue.c -u -r1.2 -r1.3
--- sys/dev/usb/if_rue.c
+++ sys/dev/usb/if_rue.c
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama at FreeBSD.org>.
+ * Copyright (c) 1997, 1998, 1999, 2000 Bill Paul <wpaul at ee.columbia.edu>.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -56,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/if_rue.c,v 1.21.2.4 2006/03/17 21:30:56 glebius Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/if_rue.c,v 1.40 2007/07/09 16:58:07 imp Exp $");
 
 /*
  * RealTek RTL8150 USB to fast ethernet controller driver.
@@ -85,9 +86,6 @@
 
 #include <sys/bus.h>
 #include <machine/bus.h>
-#if __FreeBSD_version < 500000
-#include <machine/clock.h>
-#endif
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -101,18 +99,18 @@
 
 #include <dev/usb/if_ruereg.h>
 
-/* "controller miibus0" required.  See GENERIC if you get errors here. */
+/* "device miibus" required.  See GENERIC if you get errors here. */
 #include "miibus_if.h"
 
 #ifdef USB_DEBUG
-Static int	ruedebug = 0;
+static int	ruedebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, rue, CTLFLAG_RW, 0, "USB rue");
 SYSCTL_INT(_hw_usb_rue, OID_AUTO, debug, CTLFLAG_RW,
 	   &ruedebug, 0, "rue debug level");
 
 #define DPRINTFN(n, x)	do { \
 				if (ruedebug > (n)) \
-					logprintf x; \
+					printf x; \
 			} while (0);
 #else
 #define DPRINTFN(n, x)
@@ -123,49 +121,49 @@
  * Various supported device vendors/products.
  */
 
-Static struct rue_type rue_devs[] = {
+static struct rue_type rue_devs[] = {
 	{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAKTX },
 	{ USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_USBKR100 },
 	{ 0, 0 }
 };
 
-Static int rue_match(device_ptr_t);
-Static int rue_attach(device_ptr_t);
-Static int rue_detach(device_ptr_t);
+static device_probe_t rue_match;
+static device_attach_t rue_attach;
+static device_detach_t rue_detach;
+static device_shutdown_t rue_shutdown;
+static miibus_readreg_t rue_miibus_readreg;
+static miibus_writereg_t rue_miibus_writereg;
+static miibus_statchg_t rue_miibus_statchg;
 
-Static int rue_encap(struct rue_softc *, struct mbuf *, int);
+static int rue_encap(struct rue_softc *, struct mbuf *, int);
 #ifdef RUE_INTR_PIPE
-Static void rue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void rue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
 #endif
-Static void rue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void rue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void rue_tick(void *);
-Static void rue_rxstart(struct ifnet *);
-Static void rue_start(struct ifnet *);
-Static int rue_ioctl(struct ifnet *, u_long, caddr_t);
-Static void rue_init(void *);
-Static void rue_stop(struct rue_softc *);
-Static void rue_watchdog(struct ifnet *);
-Static void rue_shutdown(device_ptr_t);
-Static int rue_ifmedia_upd(struct ifnet *);
-Static void rue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
-
-Static int rue_miibus_readreg(device_ptr_t, int, int);
-Static int rue_miibus_writereg(device_ptr_t, int, int, int);
-Static void rue_miibus_statchg(device_ptr_t);
-
-Static void rue_setmulti(struct rue_softc *);
-Static void rue_reset(struct rue_softc *);
-
-Static int rue_read_mem(struct rue_softc *, u_int16_t, void *, u_int16_t);
-Static int rue_write_mem(struct rue_softc *, u_int16_t, void *, u_int16_t);
-Static int rue_csr_read_1(struct rue_softc *, int);
-Static int rue_csr_write_1(struct rue_softc *, int, u_int8_t);
-Static int rue_csr_read_2(struct rue_softc *, int);
-Static int rue_csr_write_2(struct rue_softc *, int, u_int16_t);
-Static int rue_csr_write_4(struct rue_softc *, int, u_int32_t);
+static void rue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void rue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void rue_tick(void *);
+static void rue_tick_task(void *);
+static void rue_rxstart(struct ifnet *);
+static void rue_start(struct ifnet *);
+static int rue_ioctl(struct ifnet *, u_long, caddr_t);
+static void rue_init(void *);
+static void rue_stop(struct rue_softc *);
+static void rue_watchdog(struct ifnet *);
+static int rue_ifmedia_upd(struct ifnet *);
+static void rue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
+
+static void rue_setmulti(struct rue_softc *);
+static void rue_reset(struct rue_softc *);
+
+static int rue_read_mem(struct rue_softc *, u_int16_t, void *, u_int16_t);
+static int rue_write_mem(struct rue_softc *, u_int16_t, void *, u_int16_t);
+static int rue_csr_read_1(struct rue_softc *, int);
+static int rue_csr_write_1(struct rue_softc *, int, u_int8_t);
+static int rue_csr_read_2(struct rue_softc *, int);
+static int rue_csr_write_2(struct rue_softc *, int, u_int16_t);
+static int rue_csr_write_4(struct rue_softc *, int, u_int32_t);
 
-Static device_method_t rue_methods[] = {
+static device_method_t rue_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe, rue_match),
 	DEVMETHOD(device_attach, rue_attach),
@@ -184,13 +182,13 @@
 	{ 0, 0 }
 };
 
-Static driver_t rue_driver = {
+static driver_t rue_driver = {
 	"rue",
 	rue_methods,
 	sizeof(struct rue_softc)
 };
 
-Static devclass_t rue_devclass;
+static devclass_t rue_devclass;
 
 DRIVER_MODULE(rue, uhub, rue_driver, rue_devclass, usbd_driver_load, 0);
 DRIVER_MODULE(miibus, rue, miibus_driver, miibus_devclass, 0, 0);
@@ -210,7 +208,7 @@
 #define RUE_CLRBIT_2(sc, reg, x) \
 	rue_csr_write_2(sc, reg, rue_csr_read_2(sc, reg) & ~(x))
 
-Static int
+static int
 rue_read_mem(struct rue_softc *sc, u_int16_t addr, void *buf, u_int16_t len)
 {
 	usb_device_request_t	req;
@@ -232,15 +230,15 @@
 	RUE_UNLOCK(sc);
 
 	if (err) {
-		printf("rue%d: control pipe read failed: %s\n",
-		       sc->rue_unit, usbd_errstr(err));
+		device_printf(sc->rue_dev, "control pipe read failed: %s\n",
+		    usbd_errstr(err));
 		return (-1);
 	}
 
 	return (0);
 }
 
-Static int
+static int
 rue_write_mem(struct rue_softc *sc, u_int16_t addr, void *buf, u_int16_t len)
 {
 	usb_device_request_t	req;
@@ -262,15 +260,15 @@
 	RUE_UNLOCK(sc);
 
 	if (err) {
-		printf("rue%d: control pipe write failed: %s\n",
-		       sc->rue_unit, usbd_errstr(err));
+		device_printf(sc->rue_dev, "control pipe write failed: %s\n",
+		    usbd_errstr(err));
 		return (-1);
 	}
 
 	return (0);
 }
 
-Static int
+static int
 rue_csr_read_1(struct rue_softc *sc, int reg)
 {
 	int		err;
@@ -284,7 +282,7 @@
 	return (val);
 }
 
-Static int
+static int
 rue_csr_read_2(struct rue_softc *sc, int reg)
 {
 	int		err;
@@ -301,7 +299,7 @@
 	return (val);
 }
 
-Static int
+static int
 rue_csr_write_1(struct rue_softc *sc, int reg, u_int8_t val)
 {
 	int	err;
@@ -314,7 +312,7 @@
 	return (0);
 }
 
-Static int
+static int
 rue_csr_write_2(struct rue_softc *sc, int reg, u_int16_t val)
 {
 	int	err;
@@ -329,7 +327,7 @@
 	return (0);
 }
 
-Static int
+static int
 rue_csr_write_4(struct rue_softc *sc, int reg, u_int32_t val)
 {
 	int	err;
@@ -344,10 +342,10 @@
 	return (0);
 }
 
-Static int
-rue_miibus_readreg(device_ptr_t dev, int phy, int reg)
+static int
+rue_miibus_readreg(device_t dev, int phy, int reg)
 {
-	struct rue_softc	*sc = USBGETSOFTC(dev);
+	struct rue_softc	*sc = device_get_softc(dev);
 	int			rval;
 	int			ruereg;
 
@@ -379,7 +377,7 @@
 			rval = rue_csr_read_1(sc, reg);
 			return (rval);
 		}
-		printf("rue%d: bad phy register\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "bad phy register\n");
 		return (0);
 	}
 
@@ -388,10 +386,10 @@
 	return (rval);
 }
 
-Static int
-rue_miibus_writereg(device_ptr_t dev, int phy, int reg, int data)
+static int
+rue_miibus_writereg(device_t dev, int phy, int reg, int data)
 {
-	struct rue_softc	*sc = USBGETSOFTC(dev);
+	struct rue_softc	*sc = device_get_softc(dev);
 	int			ruereg;
 
 	if (phy != 0)		/* RTL8150 supports PHY == 0, only */
@@ -422,7 +420,7 @@
 			rue_csr_write_1(sc, reg, data);
 			return (0);
 		}
-		printf("rue%d: bad phy register\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "bad phy register\n");
 		return (0);
 	}
 	rue_csr_write_2(sc, ruereg, data);
@@ -430,8 +428,8 @@
 	return (0);
 }
 
-Static void
-rue_miibus_statchg(device_ptr_t dev)
+static void
+rue_miibus_statchg(device_t dev)
 {
 	/*
 	 * When the code below is enabled the card starts doing weird
@@ -444,7 +442,7 @@
 	 * out, so that disable it for good.
 	 */
 #if 0
-	struct rue_softc	*sc = USBGETSOFTC(dev);
+	struct rue_softc	*sc = device_get_softc(dev);
 	struct mii_data		*mii = GET_MII(sc);
 	int			bmcr;
 
@@ -472,7 +470,7 @@
  * Program the 64-bit multicast hash filter.
  */
 
-Static void
+static void
 rue_setmulti(struct rue_softc *sc)
 {
 	struct ifnet		*ifp;
@@ -501,11 +499,7 @@
 
 	/* now program new ones */
 	IF_ADDR_LOCK(ifp);
-#if __FreeBSD_version >= 500000
 	TAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link)
-#else
-	LIST_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link)
-#endif
 	{
 		if (ifma->ifma_addr->sa_family != AF_LINK)
 			continue;
@@ -531,7 +525,7 @@
 	rue_csr_write_4(sc, RUE_MAR4, hashes[1]);
 }
 
-Static void
+static void
 rue_reset(struct rue_softc *sc)
 {
 	int	i;
@@ -544,7 +538,7 @@
 			break;
 	}
 	if (i == RUE_TIMEOUT)
-		printf("rue%d: reset never completed!\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "reset never completed!\n");
 
 	DELAY(10000);
 }
@@ -553,9 +547,10 @@
  * Probe for a RTL8150 chip.
  */
 
-USB_MATCH(rue)
+static int
+rue_match(device_t self)
 {
-	USB_MATCH_START(rue, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	struct rue_type	*t;
 
 	if (uaa->iface == NULL)
@@ -578,10 +573,11 @@
  * setup and ethernet/BPF attach.
  */
 
-USB_ATTACH(rue)
+static int
+rue_attach(device_t self)
 {
-	USB_ATTACH_START(rue, sc, uaa);
-	char				*devinfo;
+	struct rue_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	u_char				eaddr[ETHER_ADDR_LEN];
 	struct ifnet			*ifp;
 	usbd_interface_handle		iface;
@@ -591,25 +587,19 @@
 	int				i;
 	struct rue_type			*t;
 
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
-
-	bzero(sc, sizeof (struct rue_softc));
-	usbd_devinfo(uaa->device, 0, devinfo);
-
 	sc->rue_dev = self;
 	sc->rue_udev = uaa->device;
-	sc->rue_unit = device_get_unit(self);
 
 	if (usbd_set_config_no(sc->rue_udev, RUE_CONFIG_NO, 0)) {
-		printf("rue%d: getting interface handle failed\n",
-			sc->rue_unit);
+		device_printf(sc->rue_dev, "getting interface handle failed\n");
 		goto error;
 	}
 
+	usb_init_task(&sc->rue_tick_task, rue_tick_task, sc);
+
 	err = usbd_device2interface_handle(uaa->device, RUE_IFACE_IDX, &iface);
 	if (err) {
-		printf("rue%d: getting interface handle failed\n",
-		       sc->rue_unit);
+		device_printf(sc->rue_dev, "getting interface handle failed\n");
 		goto error;
 	}
 
@@ -627,15 +617,11 @@
 
 	id = usbd_get_interface_descriptor(sc->rue_iface);
 
-	usbd_devinfo(uaa->device, 0, devinfo);
-	device_set_desc_copy(self, devinfo);
-	printf("%s: %s\n", USBDEVNAME(self), devinfo);
-
 	/* Find endpoints */
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(iface, i);
 		if (ed == NULL) {
-			printf("rue%d: couldn't get ep %d\n", sc->rue_unit, i);
+			device_printf(sc->rue_dev, "couldn't get ep %d\n", i);
 			goto error;
 		}
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
@@ -650,10 +636,8 @@
 		}
 	}
 
-#if __FreeBSD_version >= 500000
 	mtx_init(&sc->rue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
 		 MTX_DEF | MTX_RECURSE);
-#endif
 	RUE_LOCK(sc);
 
 	/* Reset the adapter */
@@ -663,17 +647,17 @@
 	err = rue_read_mem(sc, RUE_EEPROM_IDR0,
 			   (caddr_t)&eaddr, ETHER_ADDR_LEN);
 	if (err) {
-		printf("rue%d: couldn't get station address\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "couldn't get station address\n");
 		goto error1;
 	}
 
 	ifp = sc->rue_ifp = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
-		printf("rue%d: can not if_alloc()\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "can not if_alloc()\n");
 		goto error1;
 	}
 	ifp->if_softc = sc;
-	if_initname(ifp, "rue", sc->rue_unit);
+	if_initname(ifp, "rue", device_get_unit(sc->rue_dev));
 	ifp->if_mtu = ETHERMTU;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
 	    IFF_NEEDSGIANT;
@@ -686,7 +670,7 @@
 	/* MII setup */
 	if (mii_phy_probe(self, &sc->rue_miibus,
 			  rue_ifmedia_upd, rue_ifmedia_sts)) {
-		printf("rue%d: MII without any PHY!\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "MII without any PHY!\n");
 		goto error2;
 	}
 
@@ -694,33 +678,25 @@
 	sc->rue_qdat.if_rxstart = rue_rxstart;
 
 	/* Call MI attach routine */
-#if __FreeBSD_version >= 500000
 	ether_ifattach(ifp, eaddr);
-#else
-	ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
-#endif
 	callout_handle_init(&sc->rue_stat_ch);
 	usb_register_netisr();
 	sc->rue_dying = 0;
 
 	RUE_UNLOCK(sc);
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
     error2:
 	if_free(ifp);
     error1:
 	RUE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
 	mtx_destroy(&sc->rue_mtx);
-#endif
     error:
-	free(devinfo, M_USBDEV);
-	USB_ATTACH_ERROR_RETURN;
+	return ENXIO;
 }
 
-Static int
-rue_detach(device_ptr_t dev)
+static int
+rue_detach(device_t dev)
 {
 	struct rue_softc	*sc;
 	struct ifnet		*ifp;
@@ -731,12 +707,9 @@
 
 	sc->rue_dying = 1;
 	untimeout(rue_tick, sc, sc->rue_stat_ch);
-#if __FreeBSD_version >= 500000
+	usb_rem_task(sc->rue_udev, &sc->rue_tick_task);
 	ether_ifdetach(ifp);
 	if_free(ifp);
-#else
-	ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
-#endif
 
 	if (sc->rue_ep[RUE_ENDPT_TX] != NULL)
 		usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_TX]);
@@ -748,15 +721,13 @@
 #endif
 
 	RUE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
 	mtx_destroy(&sc->rue_mtx);
-#endif
 
 	return (0);
 }
 
 #ifdef RUE_INTR_PIPE
-Static void
+static void
 rue_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct rue_softc	*sc = priv;
@@ -776,8 +747,8 @@
 			RUE_UNLOCK(sc);
 			return;
 		}
-		printf("rue%d: usb error on intr: %s\n", sc->rue_unit,
-			usbd_errstr(status));
+		device_printf(sc->rue_dev, "usb error on intr: %s\n",
+		    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->rue_ep[RUE_ENDPT_INTR]);
 		RUE_UNLOCK(sc);
@@ -794,7 +765,7 @@
 }
 #endif
 
-Static void
+static void
 rue_rxstart(struct ifnet *ifp)
 {
 	struct rue_softc	*sc;
@@ -807,7 +778,7 @@
 	c->ue_mbuf = usb_ether_newbuf();
 	if (c->ue_mbuf == NULL) {
 		printf("%s: no memory for rx list "
-		    "-- packet dropped!\n", USBDEVNAME(sc->rue_dev));
+		    "-- packet dropped!\n", device_get_nameunit(sc->rue_dev));
 		ifp->if_ierrors++;
 		RUE_UNLOCK(sc);
 		return;
@@ -827,7 +798,7 @@
  * the higher level protocols.
  */
 
-Static void
+static void
 rue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct ue_chain	*c = priv;
@@ -853,8 +824,8 @@
 			return;
 		}
 		if (usbd_ratecheck(&sc->rue_rx_notice))
-			printf("rue%d: usb error on rx: %s\n", sc->rue_unit,
-			       usbd_errstr(status));
+			device_printf(sc->rue_dev, "usb error on rx: %s\n",
+			    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->rue_ep[RUE_ENDPT_RX]);
 		goto done;
@@ -903,7 +874,7 @@
  * the list buffers.
  */
 
-Static void
+static void
 rue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct ue_chain	*c = priv;
@@ -920,8 +891,8 @@
 			RUE_UNLOCK(sc);
 			return;
 		}
-		printf("rue%d: usb error on tx: %s\n", sc->rue_unit,
-			usbd_errstr(status));
+		device_printf(sc->rue_dev, "usb error on tx: %s\n",
+		    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->rue_ep[RUE_ENDPT_TX]);
 		RUE_UNLOCK(sc);
@@ -946,9 +917,23 @@
 	RUE_UNLOCK(sc);
 }
 
-Static void
+static void
 rue_tick(void *xsc)
 {
+	struct rue_softc *sc = xsc;
+
+	if (sc == NULL)
+		return;
+	if (sc->rue_dying)
+		return;
+
+	/* Perform periodic stuff in process context */
+	usb_add_task(sc->rue_udev, &sc->rue_tick_task, USB_TASKQ_DRIVER);
+}
+
+static void
+rue_tick_task(void *xsc)
+{
 	struct rue_softc	*sc = xsc;
 	struct ifnet		*ifp;
 	struct mii_data		*mii;
@@ -978,7 +963,7 @@
 	RUE_UNLOCK(sc);
 }
 
-Static int
+static int
 rue_encap(struct rue_softc *sc, struct mbuf *m, int idx)
 {
 	int			total_len;
@@ -1019,7 +1004,7 @@
 	return (0);
 }
 
-Static void
+static void
 rue_start(struct ifnet *ifp)
 {
 	struct rue_softc	*sc = ifp->if_softc;
@@ -1066,7 +1051,7 @@
 	RUE_UNLOCK(sc);
 }
 
-Static void
+static void
 rue_init(void *xsc)
 {
 	struct rue_softc	*sc = xsc;
@@ -1090,13 +1075,13 @@
 	rue_reset(sc);
 
 	/* Set MAC address */
-	rue_write_mem(sc, RUE_IDR0, IFP2ENADDR(sc->rue_ifp),
+	rue_write_mem(sc, RUE_IDR0, IF_LLADDR(sc->rue_ifp),
 	    ETHER_ADDR_LEN);
 
 	/* Init TX ring. */
 	if (usb_ether_tx_list_init(sc, &sc->rue_cdata,
 	    sc->rue_udev) == ENOBUFS) {
-		printf("rue%d: tx list init failed\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "tx list init failed\n");
 		RUE_UNLOCK(sc);
 		return;
 	}
@@ -1104,7 +1089,7 @@
 	/* Init RX ring. */
 	if (usb_ether_rx_list_init(sc, &sc->rue_cdata,
 	    sc->rue_udev) == ENOBUFS) {
-		printf("rue%d: rx list init failed\n", sc->rue_unit);
+		device_printf(sc->rue_dev, "rx list init failed\n");
 		RUE_UNLOCK(sc);
 		return;
 	}
@@ -1146,16 +1131,16 @@
 	err = usbd_open_pipe(sc->rue_iface, sc->rue_ed[RUE_ENDPT_RX],
 			     USBD_EXCLUSIVE_USE, &sc->rue_ep[RUE_ENDPT_RX]);
 	if (err) {
-		printf("rue%d: open rx pipe failed: %s\n",
-			sc->rue_unit, usbd_errstr(err));
+		device_printf(sc->rue_dev, "open rx pipe failed: %s\n",
+		    usbd_errstr(err));
 		RUE_UNLOCK(sc);
 		return;
 	}
 	err = usbd_open_pipe(sc->rue_iface, sc->rue_ed[RUE_ENDPT_TX],
 			     USBD_EXCLUSIVE_USE, &sc->rue_ep[RUE_ENDPT_TX]);
 	if (err) {
-		printf("rue%d: open tx pipe failed: %s\n",
-			sc->rue_unit, usbd_errstr(err));
+		device_printf(sc->rue_dev, "open tx pipe failed: %s\n",
+		    usbd_errstr(err));
 		RUE_UNLOCK(sc);
 		return;
 	}
@@ -1167,8 +1152,8 @@
 				  sc->rue_cdata.ue_ibuf, RUE_INTR_PKTLEN,
 				  rue_intr, RUE_INTR_INTERVAL);
 	if (err) {
-		printf("rue%d: open intr pipe failed: %s\n",
-			sc->rue_unit, usbd_errstr(err));
+		device_printf(sc->rue_dev, "open intr pipe failed: %s\n",
+		    usbd_errstr(err));
 		RUE_UNLOCK(sc);
 		return;
 	}
@@ -1195,7 +1180,7 @@
  * Set media options.
  */
 
-Static int
+static int
 rue_ifmedia_upd(struct ifnet *ifp)
 {
 	struct rue_softc	*sc = ifp->if_softc;
@@ -1216,7 +1201,7 @@
  * Report current media status.
  */
 
-Static void
+static void
 rue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
 	struct rue_softc	*sc = ifp->if_softc;
@@ -1227,7 +1212,7 @@
 	ifmr->ifm_status = mii->mii_media_status;
 }
 
-Static int
+static int
 rue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
 {
 	struct rue_softc	*sc = ifp->if_softc;
@@ -1281,7 +1266,7 @@
 	return (error);
 }
 
-Static void
+static void
 rue_watchdog(struct ifnet *ifp)
 {
 	struct rue_softc	*sc = ifp->if_softc;
@@ -1291,7 +1276,7 @@
 	RUE_LOCK(sc);
 
 	ifp->if_oerrors++;
-	printf("rue%d: watchdog timeout\n", sc->rue_unit);
+	device_printf(sc->rue_dev, "watchdog timeout\n");
 
 	c = &sc->rue_cdata.ue_tx_chain[0];
 	usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
@@ -1308,7 +1293,7 @@
  * RX and TX lists.
  */
 
-Static void
+static void
 rue_stop(struct rue_softc *sc)
 {
 	usbd_status	err;
@@ -1328,13 +1313,13 @@
 	if (sc->rue_ep[RUE_ENDPT_RX] != NULL) {
 		err = usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_RX]);
 		if (err) {
-			printf("rue%d: abort rx pipe failed: %s\n",
-			       sc->rue_unit, usbd_errstr(err));
+			device_printf(sc->rue_dev, "abort rx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->rue_ep[RUE_ENDPT_RX]);
 		if (err) {
-			printf("rue%d: close rx pipe failed: %s\n",
-			       sc->rue_unit, usbd_errstr(err));
+			device_printf(sc->rue_dev, "close rx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->rue_ep[RUE_ENDPT_RX] = NULL;
 	}
@@ -1342,13 +1327,13 @@
 	if (sc->rue_ep[RUE_ENDPT_TX] != NULL) {
 		err = usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_TX]);
 		if (err) {
-			printf("rue%d: abort tx pipe failed: %s\n",
-			       sc->rue_unit, usbd_errstr(err));
+			device_printf(sc->rue_dev, "abort tx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->rue_ep[RUE_ENDPT_TX]);
 		if (err) {
-			printf("rue%d: close tx pipe failed: %s\n",
-			       sc->rue_unit, usbd_errstr(err));
+			device_printf(sc->rue_dev, "close tx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->rue_ep[RUE_ENDPT_TX] = NULL;
 	}
@@ -1357,13 +1342,13 @@
 	if (sc->rue_ep[RUE_ENDPT_INTR] != NULL) {
 		err = usbd_abort_pipe(sc->rue_ep[RUE_ENDPT_INTR]);
 		if (err) {
-			printf("rue%d: abort intr pipe failed: %s\n",
-			       sc->rue_unit, usbd_errstr(err));
+			device_printf(sc->rue_dev, "abort intr pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->rue_ep[RUE_ENDPT_INTR]);
 		if (err) {
-			printf("rue%d: close intr pipe failed: %s\n",
-			       sc->rue_unit, usbd_errstr(err));
+			device_printf(sc->rue_dev, "close intr pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->rue_ep[RUE_ENDPT_INTR] = NULL;
 	}
@@ -1391,8 +1376,8 @@
  * get confused by errant DMAs when rebooting.
  */
 
-Static void
-rue_shutdown(device_ptr_t dev)
+static int
+rue_shutdown(device_t dev)
 {
 	struct rue_softc	*sc;
 
@@ -1403,4 +1388,6 @@
 	rue_reset(sc);
 	rue_stop(sc);
 	RUE_UNLOCK(sc);
+
+	return (0);
 }
Index: usb_quirks.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_quirks.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/usb_quirks.c -L sys/dev/usb/usb_quirks.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/usb_quirks.c
+++ sys/dev/usb/usb_quirks.c
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.41.2.4 2006/02/15 22:51:08 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.63.4.1 2008/01/07 23:12:45 brix Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -54,13 +54,12 @@
 
 #define ANY 0xffff
 
-Static const struct usbd_quirk_entry {
+static const struct usbd_quirk_entry {
 	u_int16_t idVendor;
 	u_int16_t idProduct;
 	u_int16_t bcdDevice;
 	struct usbd_quirks quirks;
 } usb_quirks[] = {
- { USB_VENDOR_KYE, USB_PRODUCT_KYE_NICHE,	    0x100, { UQ_NO_SET_PROTO}},
  { USB_VENDOR_INSIDEOUT, USB_PRODUCT_INSIDEOUT_EDGEPORT4,
    						    0x094, { UQ_SWAP_UNICODE}},
  { USB_VENDOR_DALLAS, USB_PRODUCT_DALLAS_J6502,	    0x0a2, { UQ_BAD_ADC }},
@@ -71,14 +70,11 @@
  { USB_VENDOR_ALCOR2, USB_PRODUCT_ALCOR2_KBD_HUB,   0x001, { UQ_SPUR_BUT_UP }},
  { USB_VENDOR_MCT, USB_PRODUCT_MCT_HUB0100,         0x102, { UQ_BUS_POWERED }},
  { USB_VENDOR_MCT, USB_PRODUCT_MCT_USB232,          0x102, { UQ_BUS_POWERED }},
- { USB_VENDOR_METRICOM, USB_PRODUCT_METRICOM_RICOCHET_GS,
- 	0x100, { UQ_ASSUME_CM_OVER_DATA }},
- { USB_VENDOR_SANYO, USB_PRODUCT_SANYO_SCP4900,
- 	0x000, { UQ_ASSUME_CM_OVER_DATA }},
  { USB_VENDOR_TI, USB_PRODUCT_TI_UTUSB41,	    0x110, { UQ_POWER_CLAIM }},
  { USB_VENDOR_TELEX, USB_PRODUCT_TELEX_MIC1,	    0x009, { UQ_AU_NO_FRAC }},
  { USB_VENDOR_SILICONPORTALS, USB_PRODUCT_SILICONPORTALS_YAPPHONE,
    						    0x100, { UQ_AU_INP_ASYNC }},
+ { USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_UN53B, ANY, { UQ_NO_STRINGS }},
  /* XXX These should have a revision number, but I don't know what they are. */
  { USB_VENDOR_HP, USB_PRODUCT_HP_895C,		    ANY,   { UQ_BROKEN_BIDIR }},
  { USB_VENDOR_HP, USB_PRODUCT_HP_880C,		    ANY,   { UQ_BROKEN_BIDIR }},
@@ -86,30 +82,36 @@
  { USB_VENDOR_HP, USB_PRODUCT_HP_810C,		    ANY,   { UQ_BROKEN_BIDIR }},
  { USB_VENDOR_HP, USB_PRODUCT_HP_830C,		    ANY,   { UQ_BROKEN_BIDIR }},
  { USB_VENDOR_HP, USB_PRODUCT_HP_1220C,		    ANY,   { UQ_BROKEN_BIDIR }},
- /* YAMAHA router's ucdDevice is the version of farmware and often changes. */
- { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTA54I,
-	ANY, { UQ_ASSUME_CM_OVER_DATA }},
- { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTA55I,
-	ANY, { UQ_ASSUME_CM_OVER_DATA }},
- { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTW65B,
-	ANY, { UQ_ASSUME_CM_OVER_DATA }},
- { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTW65I,
-	ANY, { UQ_ASSUME_CM_OVER_DATA }},
- { USB_VENDOR_QUALCOMM, USB_PRODUCT_QUALCOMM_CDMA_MSM,
-	ANY, { UQ_ASSUME_CM_OVER_DATA }},
- { USB_VENDOR_QUALCOMM2, USB_PRODUCT_QUALCOMM2_CDMA_MSM,
-	ANY, { UQ_ASSUME_CM_OVER_DATA }},
- { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_AS64LX,
-	0x100, { UQ_ASSUME_CM_OVER_DATA }},
+ { USB_VENDOR_XEROX, USB_PRODUCT_XEROX_WCM15,	    ANY,   { UQ_BROKEN_BIDIR }},
+ /* MS keyboards do weird things */
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_WLNOTEBOOK,
+   ANY, { UQ_MS_BAD_CLASS | UQ_MS_LEADING_BYTE }},
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_WLNOTEBOOK2,
+   ANY, { UQ_MS_BAD_CLASS | UQ_MS_LEADING_BYTE }},
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_WLINTELLIMOUSE,
+   ANY, { UQ_MS_LEADING_BYTE }},
+
  /* Devices which should be ignored by uhid */
  { USB_VENDOR_APC, USB_PRODUCT_APC_UPS,
 	ANY, { UQ_HID_IGNORE }},
+ { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F6C550AVR,
+	ANY, { UQ_HID_IGNORE }},
  { USB_VENDOR_DELORME, USB_PRODUCT_DELORME_EARTHMATE,
 	ANY, { UQ_HID_IGNORE }},
+ { USB_VENDOR_ITUNERNET, USB_PRODUCT_ITUNERNET_USBLCD2X20,
+	ANY, { UQ_HID_IGNORE }},
  { USB_VENDOR_MGE, USB_PRODUCT_MGE_UPS1,
 	ANY, { UQ_HID_IGNORE }},
  { USB_VENDOR_MGE, USB_PRODUCT_MGE_UPS2,
 	ANY, { UQ_HID_IGNORE }},
+
+ /* Devices which should be ignored by both ukbd and uhid */
+ { USB_VENDOR_CYPRESS, USB_PRODUCT_CYPRESS_WISPY1A,
+	ANY, { UQ_KBD_IGNORE }},
+ { USB_VENDOR_METAGEEK, USB_PRODUCT_METAGEEK_WISPY1B,
+	ANY, { UQ_KBD_IGNORE }},
+ { USB_VENDOR_METAGEEK, USB_PRODUCT_METAGEEK_WISPY24X,
+	ANY, { UQ_KBD_IGNORE }},
  { 0, 0, 0, { 0 } }
 };
 
@@ -131,7 +133,7 @@
 	}
 #ifdef USB_DEBUG
 	if (usbdebug && t->quirks.uq_flags)
-		logprintf("usbd_find_quirk 0x%04x/0x%04x/%x: %d\n",
+		printf("usbd_find_quirk 0x%04x/0x%04x/%x: %d\n",
 			  UGETW(d->idVendor), UGETW(d->idProduct),
 			  UGETW(d->bcdDevice), t->quirks.uq_flags);
 #endif
Index: if_cdce.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_cdce.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/if_cdce.c -L sys/dev/usb/if_cdce.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/if_cdce.c
+++ sys/dev/usb/if_cdce.c
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/if_cdce.c,v 1.7.2.5 2006/01/14 14:21:59 netchild Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/if_cdce.c,v 1.25 2007/06/30 20:18:44 imp Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -73,43 +73,66 @@
 #include "usbdevs.h"
 #include <dev/usb/if_cdcereg.h>
 
-Static device_shutdown_t cdce_shutdown;
-USB_DECLARE_DRIVER_INIT(cdce,
-	DEVMETHOD(device_probe, cdce_match),
-	DEVMETHOD(device_attach, cdce_attach),
-	DEVMETHOD(device_detach, cdce_detach),
-	DEVMETHOD(device_shutdown, cdce_shutdown)
-	);
+static device_probe_t cdce_match;
+static device_attach_t cdce_attach;
+static device_detach_t cdce_detach;
+static device_shutdown_t cdce_shutdown;
+
+static device_method_t cdce_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		cdce_match),
+	DEVMETHOD(device_attach,	cdce_attach),
+	DEVMETHOD(device_detach,	cdce_detach),
+	DEVMETHOD(device_shutdown,	cdce_shutdown),
+
+	{ 0, 0 }
+};
+
+static driver_t cdce_driver = {
+	"cdce",
+	cdce_methods,
+	sizeof(struct cdce_softc)
+};
+
+static devclass_t cdce_devclass;
+
 DRIVER_MODULE(cdce, uhub, cdce_driver, cdce_devclass, usbd_driver_load, 0);
 MODULE_VERSION(cdce, 0);
+MODULE_DEPEND(cdce, usb, 1, 1, 1);
 
-Static int	 cdce_encap(struct cdce_softc *, struct mbuf *, int);
-Static void	 cdce_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void	 cdce_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void	 cdce_start(struct ifnet *);
-Static int	 cdce_ioctl(struct ifnet *, u_long, caddr_t);
-Static void	 cdce_init(void *);
-Static void	 cdce_reset(struct cdce_softc *);
-Static void	 cdce_stop(struct cdce_softc *);
-Static void	 cdce_rxstart(struct ifnet *);
-Static int	 cdce_ifmedia_upd(struct ifnet *ifp);
-Static void	 cdce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr);
-
-Static const struct cdce_type cdce_devs[] = {
+static int	 cdce_encap(struct cdce_softc *, struct mbuf *, int);
+static void	 cdce_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void	 cdce_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void	 cdce_start(struct ifnet *);
+static int	 cdce_ioctl(struct ifnet *, u_long, caddr_t);
+static void	 cdce_init(void *);
+static void	 cdce_reset(struct cdce_softc *);
+static void	 cdce_stop(struct cdce_softc *);
+static void	 cdce_rxstart(struct ifnet *);
+static int	 cdce_ifmedia_upd(struct ifnet *ifp);
+static void	 cdce_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr);
+
+static const struct cdce_type cdce_devs[] = {
+  {{ USB_VENDOR_ACERLABS, USB_PRODUCT_ACERLABS_M5632 }, CDCE_NO_UNION },
+  {{ USB_VENDOR_AMBIT, USB_PRODUCT_AMBIT_NTL_250 }, CDCE_NO_UNION },
+  {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_IPAQLINUX }, CDCE_NO_UNION },
+  {{ USB_VENDOR_GMATE, USB_PRODUCT_GMATE_YP3X00 }, CDCE_NO_UNION },
+  {{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN }, CDCE_ZAURUS | CDCE_NO_UNION },
+  {{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN2 }, CDCE_ZAURUS | CDCE_NO_UNION },
+  {{ USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_ETHERNETGADGET }, CDCE_NO_UNION },
   {{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2501 }, CDCE_NO_UNION },
   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5500 }, CDCE_ZAURUS },
-  {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SLA300 }, CDCE_ZAURUS | CDCE_NO_UNION },
   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5600 }, CDCE_ZAURUS | CDCE_NO_UNION },
+  {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SLA300 }, CDCE_ZAURUS | CDCE_NO_UNION },
   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SLC700 }, CDCE_ZAURUS | CDCE_NO_UNION },
   {{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SLC750 }, CDCE_ZAURUS | CDCE_NO_UNION },
-  {{ USB_VENDOR_GMATE, USB_PRODUCT_GMATE_YP3X00 }, CDCE_NO_UNION },
-  {{ USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_ETHERNETGADGET }, CDCE_NO_UNION },
 };
 #define cdce_lookup(v, p) ((const struct cdce_type *)usb_lookup(cdce_devs, v, p))
 
-USB_MATCH(cdce)
+static int
+cdce_match(device_t self)
 {
-	USB_MATCH_START(cdce, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_interface_descriptor_t *id;
 
 	if (uaa->iface == NULL)
@@ -129,9 +152,11 @@
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(cdce)
+static int
+cdce_attach(device_t self)
 {
-	USB_ATTACH_START(cdce, sc, uaa);
+	struct cdce_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	struct ifnet			*ifp;
 	usbd_device_handle		 dev = uaa->device;
 	const struct cdce_type		*t;
@@ -145,14 +170,8 @@
 	const usb_cdc_ethernet_descriptor_t *ue;
 	char				 eaddr_str[USB_MAX_STRING_LEN];
 
-	bzero(sc, sizeof(struct cdce_softc));
 	sc->cdce_dev = self;
-	usbd_devinfo(dev, 0, sc->devinfo);
-	device_set_desc_copy(self, sc->devinfo);
-	printf("%s: %s\n", USBDEVNAME(sc->cdce_dev), sc->devinfo);
-
 	sc->cdce_udev = uaa->device;
-	sc->cdce_unit = device_get_unit(self);
 
 	t = cdce_lookup(uaa->vendor, uaa->product);
 	if (t)
@@ -164,9 +183,8 @@
 		ud = (const usb_cdc_union_descriptor_t *)usb_find_desc(sc->cdce_udev,
 		    UDESC_CS_INTERFACE, UDESCSUB_CDC_UNION);
 		if (ud == NULL) {
-			printf("%s: no union descriptor\n",
-			    USBDEVNAME(sc->cdce_dev));
-			USB_ATTACH_ERROR_RETURN;
+			device_printf(sc->cdce_dev, "no union descriptor\n");
+			return ENXIO;
 		}
 		data_ifcno = ud->bSlaveInterface[0];
 
@@ -184,8 +202,8 @@
 	}
 
 	if (sc->cdce_data_iface == NULL) {
-		printf("%s: no data interface\n", USBDEVNAME(sc->cdce_dev));
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(sc->cdce_dev, "no data interface\n");
+		return ENXIO;
 	}
 
 	/*
@@ -212,9 +230,9 @@
 
 	for (j = 0; j < numalts; j++) {
 		if (usbd_set_interface(sc->cdce_data_iface, j)) {
-			printf("%s: setting alternate interface failed\n",
-			    USBDEVNAME(sc->cdce_dev));
-			USB_ATTACH_ERROR_RETURN;
+			device_printf(sc->cdce_dev,	
+			    "setting alternate interface failed\n");
+			return ENXIO;
 		}
 		/* Find endpoints. */
 		id = usbd_get_interface_descriptor(sc->cdce_data_iface);
@@ -222,9 +240,9 @@
 		for (i = 0; i < id->bNumEndpoints; i++) {
 			ed = usbd_interface2endpoint_descriptor(sc->cdce_data_iface, i);
 			if (!ed) {
-				printf("%s: could not read endpoint descriptor\n",
-				    USBDEVNAME(sc->cdce_dev));
-				USB_ATTACH_ERROR_RETURN;
+				device_printf(sc->cdce_dev,
+				    "could not read endpoint descriptor\n");
+				return ENXIO;
 			}
 			if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
 			    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
@@ -237,8 +255,8 @@
 				/* XXX: CDC spec defines an interrupt pipe, but it is not
 				 * needed for simple host-to-host applications. */
 			} else {
-				printf("%s: unexpected endpoint\n",
-				    USBDEVNAME(sc->cdce_dev));
+				device_printf(sc->cdce_dev,
+				    "unexpected endpoint\n");
 			}
 		}
 		/* If we found something, try and use it... */
@@ -247,29 +265,28 @@
 	}
 
 	if (sc->cdce_bulkin_no == -1) {
-		printf("%s: could not find data bulk in\n",
-		    USBDEVNAME(sc->cdce_dev));
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(sc->cdce_dev, "could not find data bulk in\n");
+		return ENXIO;
 	}
 	if (sc->cdce_bulkout_no == -1 ) {
-		printf("%s: could not find data bulk out\n",
-		    USBDEVNAME(sc->cdce_dev));
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(sc->cdce_dev, "could not find data bulk out\n");
+		return ENXIO;
 	}
 
-	mtx_init(&sc->cdce_mtx, USBDEVNAME(sc->cdce_dev), MTX_NETWORK_LOCK,
+	mtx_init(&sc->cdce_mtx, device_get_nameunit(sc->cdce_dev), MTX_NETWORK_LOCK,
 	    MTX_DEF | MTX_RECURSE);
 	ifmedia_init(&sc->cdce_ifmedia, 0, cdce_ifmedia_upd, cdce_ifmedia_sts);
 	CDCE_LOCK(sc);
 
 	ue = (const usb_cdc_ethernet_descriptor_t *)usb_find_desc(dev,
 	    UDESC_INTERFACE, UDESCSUB_CDC_ENF);
-	if (!ue || usbd_get_string(dev, ue->iMacAddress, eaddr_str)) {
+	if (!ue || usbd_get_string(dev, ue->iMacAddress, eaddr_str,
+	    sizeof(eaddr_str))) {
 		/* Fake MAC address */
-		printf("%s: faking MAC address\n", USBDEVNAME(sc->cdce_dev));
+		device_printf(sc->cdce_dev, "faking MAC address\n");
 		eaddr[0]= 0x2a;
 		memcpy(&eaddr[1], &ticks, sizeof(u_int32_t));
-		eaddr[5] = (u_int8_t)(sc->cdce_unit);
+		eaddr[5] = (u_int8_t)device_get_unit(sc->cdce_dev);
 	} else {
 		int i;
 
@@ -290,13 +307,13 @@
 
 	ifp = GET_IFP(sc) = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
-		printf("%s: can not if_alloc()\n", USBDEVNAME(sc->cdce_dev));
+		device_printf(sc->cdce_dev, "can not if_alloc()\n");
 		CDCE_UNLOCK(sc);
 		mtx_destroy(&sc->cdce_mtx);
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 	ifp->if_softc = sc;
-	if_initname(ifp, "cdce", sc->cdce_unit);
+	if_initname(ifp, "cdce", device_get_unit(sc->cdce_dev));
 	ifp->if_mtu = ETHERMTU;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
 		IFF_NEEDSGIANT;
@@ -320,14 +337,15 @@
 	CDCE_UNLOCK(sc);
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->cdce_udev,
-	    USBDEV(sc->cdce_dev));
+	  sc->cdce_dev);
 
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
-USB_DETACH(cdce)
+static int
+cdce_detach(device_t self)
 {
-	USB_DETACH_START(cdce, sc);
+	struct cdce_softc *sc = device_get_softc(self);
 	struct ifnet	*ifp;
 
 	CDCE_LOCK(sc);
@@ -343,12 +361,12 @@
 	mtx_destroy(&sc->cdce_mtx);
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->cdce_udev,
-		USBDEV(sc->cdce_dev));
+	  sc->cdce_dev);
 
 	return (0);
 }
 
-Static void
+static void
 cdce_start(struct ifnet *ifp)
 {
 	struct cdce_softc	*sc;
@@ -387,7 +405,7 @@
 	return;
 }
 
-Static int
+static int
 cdce_encap(struct cdce_softc *sc, struct mbuf *m, int idx)
 {
 	struct ue_chain	*c;
@@ -420,7 +438,7 @@
 	return (0);
 }
 
-Static void
+static void
 cdce_stop(struct cdce_softc *sc)
 {
 	usbd_status	 err;
@@ -436,24 +454,24 @@
 	if (sc->cdce_bulkin_pipe != NULL) {
 		err = usbd_abort_pipe(sc->cdce_bulkin_pipe);
 		if (err)
-			printf("%s: abort rx pipe failed: %s\n",
-			    USBDEVNAME(sc->cdce_dev), usbd_errstr(err));
+			device_printf(sc->cdce_dev,
+			    "abort rx pipe failed: %s\n", usbd_errstr(err));
 		err = usbd_close_pipe(sc->cdce_bulkin_pipe);
 		if (err)
-			printf("%s: close rx pipe failed: %s\n",
-			    USBDEVNAME(sc->cdce_dev), usbd_errstr(err));
+			device_printf(sc->cdce_dev,
+			    "close rx pipe failed: %s\n", usbd_errstr(err));
 		sc->cdce_bulkin_pipe = NULL;
 	}
 
 	if (sc->cdce_bulkout_pipe != NULL) {
 		err = usbd_abort_pipe(sc->cdce_bulkout_pipe);
 		if (err)
-			printf("%s: abort tx pipe failed: %s\n",
-			    USBDEVNAME(sc->cdce_dev), usbd_errstr(err));
+			device_printf(sc->cdce_dev,
+			    "abort tx pipe failed: %s\n", usbd_errstr(err));
 		err = usbd_close_pipe(sc->cdce_bulkout_pipe);
 		if (err)
-			printf("%s: close tx pipe failed: %s\n",
-			    USBDEVNAME(sc->cdce_dev), usbd_errstr(err));
+			device_printf(sc->cdce_dev,
+			    "close tx pipe failed: %s\n", usbd_errstr(err));
 		sc->cdce_bulkout_pipe = NULL;
 	}
 
@@ -466,8 +484,8 @@
 	return;
 }
 
-Static int
-cdce_shutdown(device_ptr_t dev)
+static int
+cdce_shutdown(device_t dev)
 {
 	struct cdce_softc *sc;
 
@@ -477,7 +495,7 @@
 	return (0);
 }
 
-Static int
+static int
 cdce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
 {
 	struct cdce_softc	*sc = ifp->if_softc;
@@ -512,14 +530,14 @@
 	return (error);
 }
 
-Static void
+static void
 cdce_reset(struct cdce_softc *sc)
 {
 	/* XXX Maybe reset the bulk pipes here? */
 	return;
 }
 
-Static void
+static void
 cdce_init(void *xsc)
 {
 	struct cdce_softc	*sc = xsc;
@@ -536,14 +554,14 @@
 
 	if (usb_ether_tx_list_init(sc, &sc->cdce_cdata,
 	    sc->cdce_udev) == ENOBUFS) {
-		printf("%s: tx list init failed\n", USBDEVNAME(sc->cdce_dev));
+		device_printf(sc->cdce_dev, "tx list init failed\n");
 		CDCE_UNLOCK(sc);
 		return;
 	}
 
 	if (usb_ether_rx_list_init(sc, &sc->cdce_cdata,
 	    sc->cdce_udev) == ENOBUFS) {
-		printf("%s: rx list init failed\n", USBDEVNAME(sc->cdce_dev));
+		device_printf(sc->cdce_dev, "rx list init failed\n");
 		CDCE_UNLOCK(sc);
 		return;
 	}
@@ -553,7 +571,7 @@
 	err = usbd_open_pipe(sc->cdce_data_iface, sc->cdce_bulkin_no,
 	    USBD_EXCLUSIVE_USE, &sc->cdce_bulkin_pipe);
 	if (err) {
-		printf("%s: open rx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev),
+		device_printf(sc->cdce_dev, "open rx pipe failed: %s\n",
 		    usbd_errstr(err));
 		CDCE_UNLOCK(sc);
 		return;
@@ -562,7 +580,7 @@
 	err = usbd_open_pipe(sc->cdce_data_iface, sc->cdce_bulkout_no,
 	    USBD_EXCLUSIVE_USE, &sc->cdce_bulkout_pipe);
 	if (err) {
-		printf("%s: open tx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev),
+		device_printf(sc->cdce_dev, "open tx pipe failed: %s\n",
 		    usbd_errstr(err));
 		CDCE_UNLOCK(sc);
 		return;
@@ -584,7 +602,7 @@
 	return;
 }
 
-Static void
+static void
 cdce_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct ue_chain	*c = priv;
@@ -607,10 +625,10 @@
 			return;
 		}
 		if (sc->cdce_rxeof_errors == 0)
-			printf("%s: usb error on rx: %s\n",
-			    USBDEVNAME(sc->cdce_dev), usbd_errstr(status));
+			device_printf(sc->cdce_dev, "usb error on rx: %s\n",
+			    usbd_errstr(status));
 		if (status == USBD_STALLED)
-			usbd_clear_endpoint_stall(sc->cdce_bulkin_pipe);
+			usbd_clear_endpoint_stall_async(sc->cdce_bulkin_pipe);
 		DELAY(sc->cdce_rxeof_errors * 10000);
 		sc->cdce_rxeof_errors++;
 		goto done;
@@ -652,7 +670,7 @@
 	return;
 }
 
-Static void
+static void
 cdce_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct ue_chain	*c = priv;
@@ -675,10 +693,10 @@
 			return;
 		}
 		ifp->if_oerrors++;
-		printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->cdce_dev),
+		device_printf(sc->cdce_dev, "usb error on tx: %s\n",
 		    usbd_errstr(status));
 		if (status == USBD_STALLED)
-			usbd_clear_endpoint_stall(sc->cdce_bulkout_pipe);
+			usbd_clear_endpoint_stall_async(sc->cdce_bulkout_pipe);
 		CDCE_UNLOCK(sc);
 		return;
 	}
@@ -702,7 +720,7 @@
 	return;
 }
 
-Static void
+static void
 cdce_rxstart(struct ifnet *ifp)
 {
 	struct cdce_softc   *sc;
@@ -720,8 +738,8 @@
 
 	c->ue_mbuf = usb_ether_newbuf();
 	if (c->ue_mbuf == NULL) {
-		printf("%s: no memory for rx list "
-		    "-- packet dropped!\n", USBDEVNAME(sc->cdce_dev));
+		device_printf(sc->cdce_dev, "no memory for rx list "
+		    "-- packet dropped!\n");
 		ifp->if_ierrors++;
 		CDCE_UNLOCK(sc);
 		return;
@@ -736,7 +754,7 @@
 	return;
 }
 
-Static int
+static int
 cdce_ifmedia_upd(struct ifnet *ifp)
 {
 
@@ -744,7 +762,7 @@
 	return 0;
 }
 
-Static void
+static void
 cdce_ifmedia_sts(struct ifnet * const ifp, struct ifmediareq *req)
 {
 
Index: if_udavreg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_udavreg.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_udavreg.h -L sys/dev/usb/if_udavreg.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_udavreg.h
+++ sys/dev/usb/if_udavreg.h
@@ -1,6 +1,6 @@
 /*	$NetBSD: if_udavreg.h,v 1.2 2003/09/04 15:17:39 tsutsui Exp $	*/
 /*	$nabe: if_udavreg.h,v 1.2 2003/08/21 16:26:40 nabe Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/if_udavreg.h,v 1.5 2005/06/10 16:49:15 brooks Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/if_udavreg.h,v 1.7 2006/09/07 00:06:41 imp Exp $	*/
 /*-
  * Copyright (c) 2003
  *     Shingo WATANABE <nabe at nabechan.org>.  All rights reserved.
@@ -164,7 +164,7 @@
 #if defined(__FreeBSD__)
 	struct ifnet		*sc_ifp;
 #endif
-	USBBASEDEVICE		sc_dev;	/* base device */
+	device_t		sc_dev;	/* base device */
 	usbd_device_handle	sc_udev;
 
 	/* USB */
@@ -194,7 +194,7 @@
 	struct lock		sc_mii_lock;
 	int			sc_link;
 #define	sc_media udav_mii.mii_media
-#if NRND > 0
+#if defined(NRND) && NRND > 0
 	rndsource_element_t	rnd_source;
 #endif
 	struct ue_cdata		sc_cdata;
Index: udbp.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/udbp.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/udbp.c -L sys/dev/usb/udbp.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/udbp.c
+++ sys/dev/usb/udbp.c
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/udbp.c,v 1.29 2005/01/06 01:43:28 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/udbp.c,v 1.41 2007/07/05 15:25:32 imp Exp $");
 
 /* Driver for arbitrary double bulk pipe devices.
  * The driver assumes that there will be the same driver on the other side.
@@ -79,11 +79,7 @@
 #include <sys/bus.h>
 #include <sys/conf.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/poll.h>
 #include <sys/mbuf.h>
 #include <sys/socket.h>
@@ -108,8 +104,8 @@
 #include <netgraph/netgraph.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (udbpdebug) logprintf x
-#define DPRINTFN(n,x)	if (udbpdebug>(n)) logprintf x
+#define DPRINTF(x)	if (udbpdebug) printf x
+#define DPRINTFN(n,x)	if (udbpdebug>(n)) printf x
 int	udbpdebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, udbp, CTLFLAG_RW, 0, "USB udbp");
 SYSCTL_INT(_hw_usb_udbp, OID_AUTO, debug, CTLFLAG_RW,
@@ -159,24 +155,24 @@
 
 
 
-Static ng_constructor_t	ng_udbp_constructor;
-Static ng_rcvmsg_t	ng_udbp_rcvmsg;
-Static ng_shutdown_t	ng_udbp_rmnode;
-Static ng_newhook_t	ng_udbp_newhook;
-Static ng_connect_t	ng_udbp_connect;
-Static ng_rcvdata_t	ng_udbp_rcvdata;
-Static ng_disconnect_t	ng_udbp_disconnect;
+static ng_constructor_t	ng_udbp_constructor;
+static ng_rcvmsg_t	ng_udbp_rcvmsg;
+static ng_shutdown_t	ng_udbp_rmnode;
+static ng_newhook_t	ng_udbp_newhook;
+static ng_connect_t	ng_udbp_connect;
+static ng_rcvdata_t	ng_udbp_rcvdata;
+static ng_disconnect_t	ng_udbp_disconnect;
 
 /* Parse type for struct ngudbpstat */
-Static const struct ng_parse_struct_field
+static const struct ng_parse_struct_field
 	ng_udbp_stat_type_fields[] = NG_UDBP_STATS_TYPE_INFO;
-Static const struct ng_parse_type ng_udbp_stat_type = {
+static const struct ng_parse_type ng_udbp_stat_type = {
 	&ng_parse_struct_type,
 	&ng_udbp_stat_type_fields
 };
 
 /* List of commands and how to convert arguments to/from ASCII */
-Static const struct ng_cmdlist ng_udbp_cmdlist[] = {
+static const struct ng_cmdlist ng_udbp_cmdlist[] = {
 	{
 	  NGM_UDBP_COOKIE,
 	  NGM_UDBP_GET_STATUS,
@@ -195,7 +191,7 @@
 };
 
 /* Netgraph node type descriptor */
-Static struct ng_type ng_udbp_typestruct = {
+static struct ng_type ng_udbp_typestruct = {
 	.version =	NG_ABI_VERSION,
 	.name =		NG_UDBP_NODE_TYPE,
 	.constructor =	ng_udbp_constructor,
@@ -208,21 +204,41 @@
 	.cmdlist =	ng_udbp_cmdlist,
 };
 
-Static int udbp_setup_in_transfer	(udbp_p sc);
-Static void udbp_in_transfer_cb		(usbd_xfer_handle xfer,
+static int udbp_setup_in_transfer	(udbp_p sc);
+static void udbp_in_transfer_cb		(usbd_xfer_handle xfer,
 					usbd_private_handle priv,
 					usbd_status err);
 
-Static int udbp_setup_out_transfer	(udbp_p sc);
-Static void udbp_out_transfer_cb	(usbd_xfer_handle xfer,
+static int udbp_setup_out_transfer	(udbp_p sc);
+static void udbp_out_transfer_cb	(usbd_xfer_handle xfer,
 					usbd_private_handle priv,
 					usbd_status err);
 
-USB_DECLARE_DRIVER(udbp);
+static device_probe_t udbp_match;
+static device_attach_t udbp_attach;
+static device_detach_t udbp_detach;
+
+static device_method_t udbp_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		udbp_match),
+	DEVMETHOD(device_attach,	udbp_attach),
+	DEVMETHOD(device_detach,	udbp_detach),
 
-USB_MATCH(udbp)
+	{ 0, 0 }
+};
+
+static driver_t udbp_driver = {
+	"udbp",
+	udbp_methods,
+	sizeof(struct udbp_softc)
+};
+
+static devclass_t udbp_devclass;
+
+static int
+udbp_match(device_t self)
 {
-	USB_MATCH_START(udbp, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_interface_descriptor_t *id;
 	if (!uaa->iface)
 	  return (UMATCH_NONE);
@@ -238,28 +254,33 @@
 	 */
 	if ((uaa->vendor == USB_VENDOR_NETCHIP &&
 	     uaa->product == USB_PRODUCT_NETCHIP_TURBOCONNECT))
-		return(UMATCH_VENDOR_PRODUCT);
+		return (UMATCH_VENDOR_PRODUCT);
 
 	if ((uaa->vendor == USB_VENDOR_PROLIFIC &&
 	     (uaa->product == USB_PRODUCT_PROLIFIC_PL2301 ||
 	      uaa->product == USB_PRODUCT_PROLIFIC_PL2302)))
-		return(UMATCH_VENDOR_PRODUCT);
+		return (UMATCH_VENDOR_PRODUCT);
 
 	if ((uaa->vendor == USB_VENDOR_ANCHOR &&
 	     uaa->product == USB_PRODUCT_ANCHOR_EZLINK))
-		return(UMATCH_VENDOR_PRODUCT);
+		return (UMATCH_VENDOR_PRODUCT);
+
+	if ((uaa->vendor == USB_VENDOR_GENESYS &&
+	     uaa->product == USB_PRODUCT_GENESYS_GL620USB))
+		return (UMATCH_VENDOR_PRODUCT);
 
 	return (UMATCH_NONE);
 }
 
-USB_ATTACH(udbp)
+static int
+udbp_attach(device_t self)
 {
-	USB_ATTACH_START(udbp, sc, uaa);
+	struct udbp_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usbd_interface_handle iface = uaa->iface;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed, *ed_bulkin = NULL, *ed_bulkout = NULL;
 	usbd_status err;
-	char devinfo[1024];
 	int i;
 	static int ngudbp_done_init=0;
 
@@ -267,16 +288,14 @@
 	/* fetch the interface handle for the first interface */
 	(void) usbd_device2interface_handle(uaa->device, 0, &iface);
 	id = usbd_get_interface_descriptor(iface);
-	usbd_devinfo(uaa->device, USBD_SHOW_INTERFACE_CLASS, devinfo);
-	USB_ATTACH_SETUP;
+	sc->sc_dev = self;
 
 	/* Find the two first bulk endpoints */
 	for (i = 0 ; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(iface, i);
 		if (!ed) {
-			printf("%s: could not read endpoint descriptor\n",
-			       USBDEVNAME(sc->sc_dev));
-			USB_ATTACH_ERROR_RETURN;
+			device_printf(self, "could not read endpoint descriptor\n");
+			return ENXIO;
 		}
 
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN
@@ -293,27 +312,26 @@
 
 	/* Verify that we goething sensible */
 	if (ed_bulkin == NULL || ed_bulkout == NULL) {
-		printf("%s: bulk-in and/or bulk-out endpoint not found\n",
-			USBDEVNAME(sc->sc_dev));
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(self, "bulk-in and/or bulk-out endpoint not found\n");
+		return ENXIO;
 	}
 
 	if (ed_bulkin->wMaxPacketSize[0] != ed_bulkout->wMaxPacketSize[0] ||
 	   ed_bulkin->wMaxPacketSize[1] != ed_bulkout->wMaxPacketSize[1]) {
-		printf("%s: bulk-in and bulk-out have different packet sizes %d %d %d %d\n",
-			USBDEVNAME(sc->sc_dev),
-		       ed_bulkin->wMaxPacketSize[0],
-		       ed_bulkout->wMaxPacketSize[0],
-		       ed_bulkin->wMaxPacketSize[1],
-		       ed_bulkout->wMaxPacketSize[1]);
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(self,
+		    "bulk-in and bulk-out have different packet sizes %d %d %d %d\n",
+		    ed_bulkin->wMaxPacketSize[0],
+		    ed_bulkout->wMaxPacketSize[0],
+		    ed_bulkin->wMaxPacketSize[1],
+		    ed_bulkout->wMaxPacketSize[1]);
+		return ENXIO;
 	}
 
 	sc->sc_bulkin = ed_bulkin->bEndpointAddress;
 	sc->sc_bulkout = ed_bulkout->bEndpointAddress;
 
 	DPRINTF(("%s: Bulk-in: 0x%02x, bulk-out 0x%02x, packet size = %d\n",
-		USBDEVNAME(sc->sc_dev), sc->sc_bulkin, sc->sc_bulkout,
+		device_get_nameunit(sc->sc_dev), sc->sc_bulkin, sc->sc_bulkout,
 		ed_bulkin->wMaxPacketSize[0]));
 
 	/* Allocate the in transfer struct */
@@ -340,15 +358,15 @@
 	err = usbd_open_pipe(iface, sc->sc_bulkin,
 				USBD_EXCLUSIVE_USE, &sc->sc_bulkin_pipe);
 	if (err) {
-		printf("%s: cannot open bulk-in pipe (addr %d)\n",
-			USBDEVNAME(sc->sc_dev), sc->sc_bulkin);
+		device_printf(self, "cannot open bulk-in pipe (addr %d)\n",
+		    sc->sc_bulkin);
 		goto bad;
 	}
 	err = usbd_open_pipe(iface, sc->sc_bulkout,
 				USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
 	if (err) {
-		printf("%s: cannot open bulk-out pipe (addr %d)\n",
-			USBDEVNAME(sc->sc_dev), sc->sc_bulkout);
+		device_printf(self, "cannot open bulk-out pipe (addr %d)\n",
+		    sc->sc_bulkout);
 		goto bad;
 	}
 
@@ -362,7 +380,7 @@
 
 	if ((err = ng_make_node_common(&ng_udbp_typestruct, &sc->node)) == 0) {
 		char	nodename[128];
-		sprintf(nodename, "%s", USBDEVNAME(sc->sc_dev));
+		sprintf(nodename, "%s", device_get_nameunit(sc->sc_dev));
 		if ((err = ng_name_node(sc->node, nodename))) {
 			NG_NODE_UNREF(sc->node);
 			sc->node = NULL;
@@ -389,7 +407,7 @@
 	if (err) {
 		goto bad;
 	}
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 bad:
 #if 0 /* probably done in udbp_detach() */
 		if (sc->sc_bulkout_buffer) {
@@ -406,17 +424,18 @@
 		}
 #endif
 		udbp_detach(self);
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 }
 
 
-USB_DETACH(udbp)
+static int
+udbp_detach(device_t self)
 {
-	USB_DETACH_START(udbp, sc);
+	struct udbp_softc *sc = device_get_softc(self);
 
 	sc->flags |= DISCONNECTED;
 
-	DPRINTF(("%s: disconnected\n", USBDEVNAME(self)));
+	DPRINTF(("%s: disconnected\n", device_get_nameunit(self)));
 
 	if (sc->sc_bulkin_pipe) {
 		usbd_abort_pipe(sc->sc_bulkin_pipe);
@@ -447,7 +466,7 @@
 }
 
 
-Static int
+static int
 udbp_setup_in_transfer(udbp_p sc)
 {
 	void *priv = sc;	/* XXX this should probably be some pointer to
@@ -475,14 +494,14 @@
 	err = usbd_transfer(sc->sc_bulkin_xfer);
 	if (err && err != USBD_IN_PROGRESS) {
 		DPRINTF(("%s: failed to setup in-transfer, %s\n",
-			USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
+			device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
 		return(err);
 	}
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static void
+static void
 udbp_in_transfer_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
 			usbd_status err)
 {
@@ -494,7 +513,7 @@
 	if (err) {
 		if (err != USBD_CANCELLED) {
 			DPRINTF(("%s: bulk-out transfer failed: %s\n",
-				USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
+				device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
 		} else {
 			/* USBD_CANCELLED happens at unload of the driver */
 			return;
@@ -519,7 +538,7 @@
 }
 
 
-Static int
+static int
 udbp_setup_out_transfer(udbp_p sc)
 {
 	void *priv = sc;	/* XXX this should probably be some pointer to
@@ -551,9 +570,8 @@
 
 	pktlen = m->m_pkthdr.len;
 	if (pktlen > sc->sc_bulkout_bufferlen) {
-		printf("%s: Packet too large, %d > %d\n",
-			USBDEVNAME(sc->sc_dev), pktlen,
-			sc->sc_bulkout_bufferlen);
+		device_printf(sc->sc_dev, "Packet too large, %d > %d\n",
+		    pktlen, sc->sc_bulkout_bufferlen);
 		return (USBD_IOERROR);
 	}
 
@@ -574,14 +592,14 @@
 	err = usbd_transfer(sc->sc_bulkout_xfer);
 	if (err && err != USBD_IN_PROGRESS) {
 		DPRINTF(("%s: failed to setup out-transfer, %s\n",
-			USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
+			device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
 		return(err);
 	}
 
 	return (USBD_NORMAL_COMPLETION);
 }
 
-Static void
+static void
 udbp_out_transfer_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
 			usbd_status err)
 {
@@ -590,7 +608,7 @@
 
 	if (err) {
 		DPRINTF(("%s: bulk-out transfer failed: %s\n",
-			USBDEVNAME(sc->sc_dev), usbd_errstr(err)));
+			device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
 		/* Transfer has failed, packet is not transmitted */
 		/* XXX Invalidate packet */
 		return;
@@ -606,6 +624,7 @@
 
 DRIVER_MODULE(udbp, uhub, udbp_driver, udbp_devclass, usbd_driver_load, 0);
 MODULE_DEPEND(udbp, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION);
+MODULE_DEPEND(udbp, usb, 1, 1, 1);
 
 
 /***********************************************************************
@@ -617,7 +636,7 @@
  * routine and the constructor will return EINVAL as you should not be able
  * to create nodes that depend on hardware (unless you can add the hardware :)
  */
-Static int
+static int
 ng_udbp_constructor(node_p node)
 {
 	return (EINVAL);
@@ -634,7 +653,7 @@
  * pointer of each hook points to the appropriate UDBP_hookinfo struct
  * so that the source of an input packet is easily identified.
  */
-Static int
+static int
 ng_udbp_newhook(node_p node, hook_p hook, const char *name)
 {
 	const udbp_p sc = NG_NODE_PRIVATE(node);
@@ -666,7 +685,7 @@
  * the cookie in the header didn't match what we consider to be current
  * (so that old userland programs could continue to work).
  */
-Static int
+static int
 ng_udbp_rcvmsg(node_p node, item_p item, hook_p lasthook)
 {
 	const udbp_p sc = NG_NODE_PRIVATE(node);
@@ -719,7 +738,7 @@
 /*
  * Accept data from the hook and queue it for output.
  */
-Static int
+static int
 ng_udbp_rcvdata(hook_p hook, item_p item)
 {
 	const udbp_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
@@ -770,7 +789,7 @@
  * We are a persistant device, we refuse to go away, and
  * only remove our links and reset ourself.
  */
-Static int
+static int
 ng_udbp_rmnode(node_p node)
 {
 	const udbp_p sc = NG_NODE_PRIVATE(node);
@@ -797,7 +816,7 @@
 
 	if ((err = ng_make_node_common(&ng_udbp_typestruct, &sc->node)) == 0) {
 		char	nodename[128];
-		sprintf(nodename, "%s", USBDEVNAME(sc->sc_dev));
+		sprintf(nodename, "%s", device_get_nameunit(sc->sc_dev));
 		if ((err = ng_name_node(sc->node, nodename))) {
 			NG_NODE_UNREF(sc->node); /* out damned spot! */
 			sc->flags &= ~NETGRAPH_INITIALISED;
@@ -813,7 +832,7 @@
  * This is called once we've already connected a new hook to the other node.
  * It gives us a chance to balk at the last minute.
  */
-Static int
+static int
 ng_udbp_connect(hook_p hook)
 {
 	/* probably not at splnet, force outward queueing */
@@ -827,7 +846,7 @@
  *
  * For this type, removal of the last link destroys the node
  */
-Static int
+static int
 ng_udbp_disconnect(hook_p hook)
 {
 	const udbp_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
Index: if_uralreg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_uralreg.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/if_uralreg.h -L sys/dev/usb/if_uralreg.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/if_uralreg.h
+++ sys/dev/usb/if_uralreg.h
@@ -1,4 +1,4 @@
-/*	$FreeBSD: src/sys/dev/usb/if_uralreg.h,v 1.1.2.1 2006/01/29 14:16:36 damien Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/if_uralreg.h,v 1.6 2007/06/11 03:36:52 sam Exp $	*/
 
 /*-
  * Copyright (c) 2005, 2006
@@ -17,6 +17,9 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#define RAL_NOISE_FLOOR		-95
+#define RAL_RSSI_CORR		120
+
 #define RAL_RX_DESC_SIZE	(sizeof (struct ural_rx_desc))
 #define RAL_TX_DESC_SIZE	(sizeof (struct ural_tx_desc))
 
Index: if_axe.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_axe.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/usb/if_axe.c -L sys/dev/usb/if_axe.c -u -r1.2 -r1.3
--- sys/dev/usb/if_axe.c
+++ sys/dev/usb/if_axe.c
@@ -31,11 +31,11 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/if_axe.c,v 1.30.2.4 2006/03/17 21:30:56 glebius Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/if_axe.c,v 1.55 2007/09/25 21:08:33 imp Exp $");
 
 /*
- * ASIX Electronics AX88172 USB 2.0 ethernet driver. Used in the
- * LinkSys USB200M and various other adapters.
+ * ASIX Electronics AX88172/AX88178/AX88778 USB 2.0 ethernet driver.
+ * Used in the LinkSys USB200M and various other adapters.
  *
  * Manuals available from:
  * http://www.asix.com.tw/datasheet/mac/Ax88172.PDF
@@ -69,12 +69,15 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/endian.h>
 #include <sys/sockio.h>
 #include <sys/mbuf.h>
 #include <sys/malloc.h>
+#include <sys/lock.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
 #include <sys/socket.h>
+#include <sys/sx.h>
 
 #include <net/if.h>
 #include <net/if_arp.h>
@@ -87,9 +90,6 @@
 
 #include <sys/bus.h>
 #include <machine/bus.h>
-#if __FreeBSD_version < 500000
-#include <machine/clock.h>
-#endif
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -101,7 +101,7 @@
 #include <dev/mii/mii.h>
 #include <dev/mii/miivar.h>
 
-/* "controller miibus0" required.  See GENERIC if you get errors here. */
+/* "device miibus" required.  See GENERIC if you get errors here. */
 #include "miibus_if.h"
 
 #include <dev/usb/if_axereg.h>
@@ -109,43 +109,61 @@
 /*
  * Various supported device vendors/products.
  */
-Static struct axe_type axe_devs[] = {
-	{ USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88172 },
-	{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DUBE100 },
-	{ USB_VENDOR_JVC, USB_PRODUCT_JVC_MP_PRX1 },
-	{ USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_USB200M },
-	{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAU2KTX },
-	{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA120 },
-	{ USB_VENDOR_SYSTEMTALKS, USB_PRODUCT_SYSTEMTALKS_SGCX2UL },
-	{ USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_LN029 },
-	{ 0, 0 }
+const struct axe_type axe_devs[] = {
+        { { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UF200}, 0 },
+        { { USB_VENDOR_ACERCM, USB_PRODUCT_ACERCM_EP1427X2}, 0 },
+        { { USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88172}, 0 },
+        { { USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88772}, AX772 },
+        { { USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88178}, AX178 },
+        { { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC210T}, 0 },
+        { { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5D5055 }, AX178 },
+        { { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB2AR}, 0},
+        { { USB_VENDOR_CISCOLINKSYS, USB_PRODUCT_CISCOLINKSYS_USB200MV2}, AX772 },
+        { { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB2_TX }, 0},
+        { { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DUBE100}, 0 },
+        { { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DUBE100B1 }, AX772 },
+        { { USB_VENDOR_GOODWAY, USB_PRODUCT_GOODWAY_GWUSB2E}, 0 },
+        { { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_ETGUS2 }, AX178 },
+        { { USB_VENDOR_JVC, USB_PRODUCT_JVC_MP_PRX1}, 0 },
+        { { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_USB200M}, 0 },
+        { { USB_VENDOR_LINKSYS4, USB_PRODUCT_LINKSYS4_USB1000 }, AX178 },
+        { { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAU2KTX}, 0 },
+        { { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA120}, 0 },
+        { { USB_VENDOR_OQO, USB_PRODUCT_OQO_ETHER01PLUS }, AX772 },
+        { { USB_VENDOR_PLANEX3, USB_PRODUCT_PLANEX3_GU1000T }, AX178 },
+        { { USB_VENDOR_SYSTEMTALKS, USB_PRODUCT_SYSTEMTALKS_SGCX2UL}, 0 },
+        { { USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_LN029}, 0 },
+        { { USB_VENDOR_SITECOMEU, USB_PRODUCT_SITECOMEU_LN028 }, AX178 }
 };
 
-Static int axe_match(device_ptr_t);
-Static int axe_attach(device_ptr_t);
-Static int axe_detach(device_ptr_t);
-
-Static int axe_encap(struct axe_softc *, struct mbuf *, int);
-Static void axe_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void axe_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void axe_tick(void *);
-Static void axe_rxstart(struct ifnet *);
-Static void axe_start(struct ifnet *);
-Static int axe_ioctl(struct ifnet *, u_long, caddr_t);
-Static void axe_init(void *);
-Static void axe_stop(struct axe_softc *);
-Static void axe_watchdog(struct ifnet *);
-Static void axe_shutdown(device_ptr_t);
-Static int axe_miibus_readreg(device_ptr_t, int, int);
-Static int axe_miibus_writereg(device_ptr_t, int, int, int);
-Static void axe_miibus_statchg(device_ptr_t);
-Static int axe_cmd(struct axe_softc *, int, int, int, void *);
-Static int axe_ifmedia_upd(struct ifnet *);
-Static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
+#define axe_lookup(v, p) ((const struct axe_type *)usb_lookup(axe_devs, v, p))
+
+static device_probe_t axe_match;
+static device_attach_t axe_attach;
+static device_detach_t axe_detach;
+static device_shutdown_t axe_shutdown;
+static miibus_readreg_t axe_miibus_readreg;
+static miibus_writereg_t axe_miibus_writereg;
+static miibus_statchg_t axe_miibus_statchg;
+
+static int axe_encap(struct axe_softc *, struct mbuf *, int);
+static void axe_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void axe_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void axe_tick(void *);
+static void axe_tick_task(void *);
+static void axe_rxstart(struct ifnet *);
+static void axe_start(struct ifnet *);
+static int axe_ioctl(struct ifnet *, u_long, caddr_t);
+static void axe_init(void *);
+static void axe_stop(struct axe_softc *);
+static void axe_watchdog(struct ifnet *);
+static int axe_cmd(struct axe_softc *, int, int, int, void *);
+static int axe_ifmedia_upd(struct ifnet *);
+static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
 
-Static void axe_setmulti(struct axe_softc *);
+static void axe_setmulti(struct axe_softc *);
 
-Static device_method_t axe_methods[] = {
+static device_method_t axe_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		axe_match),
 	DEVMETHOD(device_attach,	axe_attach),
@@ -164,25 +182,26 @@
 	{ 0, 0 }
 };
 
-Static driver_t axe_driver = {
+static driver_t axe_driver = {
 	"axe",
 	axe_methods,
 	sizeof(struct axe_softc)
 };
 
-Static devclass_t axe_devclass;
+static devclass_t axe_devclass;
 
 DRIVER_MODULE(axe, uhub, axe_driver, axe_devclass, usbd_driver_load, 0);
 DRIVER_MODULE(miibus, axe, miibus_driver, miibus_devclass, 0, 0);
 MODULE_DEPEND(axe, usb, 1, 1, 1);
 MODULE_DEPEND(axe, miibus, 1, 1, 1);
 
-Static int
+static int
 axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
 {
 	usb_device_request_t	req;
 	usbd_status		err;
 
+	AXE_SLEEPLOCKASSERT(sc);
 	if (sc->axe_dying)
 		return(0);
 
@@ -203,16 +222,17 @@
 	return(0);
 }
 
-Static int
-axe_miibus_readreg(device_ptr_t dev, int phy, int reg)
+static int
+axe_miibus_readreg(device_t dev, int phy, int reg)
 {
-	struct axe_softc	*sc = USBGETSOFTC(dev);
+	struct axe_softc	*sc = device_get_softc(dev);
 	usbd_status		err;
 	u_int16_t		val;
 
 	if (sc->axe_dying)
 		return(0);
 
+	AXE_SLEEPLOCKASSERT(sc);
 #ifdef notdef
 	/*
 	 * The chip tells us the MII address of any supported
@@ -235,7 +255,7 @@
 	AXE_UNLOCK(sc);
 
 	if (err) {
-		printf("axe%d: read PHY failed\n", sc->axe_unit);
+		device_printf(sc->axe_dev, "read PHY failed\n");
 		return(-1);
 	}
 
@@ -245,15 +265,16 @@
 	return (val);
 }
 
-Static int
-axe_miibus_writereg(device_ptr_t dev, int phy, int reg, int val)
+static int
+axe_miibus_writereg(device_t dev, int phy, int reg, int val)
 {
-	struct axe_softc	*sc = USBGETSOFTC(dev);
+	struct axe_softc	*sc = device_get_softc(dev);
 	usbd_status		err;
 
 	if (sc->axe_dying)
 		return(0);
 
+	AXE_SLEEPLOCKASSERT(sc);
 	AXE_LOCK(sc);
 	axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
 	err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, (void *)&val);
@@ -261,29 +282,46 @@
 	AXE_UNLOCK(sc);
 
 	if (err) {
-		printf("axe%d: write PHY failed\n", sc->axe_unit);
+		device_printf(sc->axe_dev, "write PHY failed\n");
 		return(-1);
 	}
 
 	return (0);
 }
 
-Static void
-axe_miibus_statchg(device_ptr_t dev)
+static void
+axe_miibus_statchg(device_t dev)
 {
-#ifdef notdef
-	struct axe_softc	*sc = USBGETSOFTC(dev);
+	struct axe_softc	*sc = device_get_softc(dev);
 	struct mii_data		*mii = GET_MII(sc);
-#endif
-	/* doesn't seem to be necessary */
+	int			val, err;
 
-	return;
+	val = (mii->mii_media_active & IFM_GMASK) == IFM_FDX ?
+	    AXE_MEDIA_FULL_DUPLEX : 0;
+	if (sc->axe_flags & (AX178|AX772)) {
+		val |= AXE_178_MEDIA_RX_EN | AXE_178_MEDIA_MAGIC;
+
+		switch (IFM_SUBTYPE(mii->mii_media_active)) {
+		case IFM_1000_T:
+			val |= AXE_178_MEDIA_GMII | AXE_178_MEDIA_ENCK;
+			break;
+		case IFM_100_TX:
+			val |= AXE_178_MEDIA_100TX;
+			break;
+		case IFM_10_T:
+			/* doesn't need to be handled */
+			break;
+		}
+	}
+	err = axe_cmd(sc, AXE_CMD_WRITE_MEDIA, 0, val, NULL);
+	if (err)
+		device_printf(dev, "media change failed, error %d\n", err);
 }
 
 /*
  * Set media options.
  */
-Static int
+static int
 axe_ifmedia_upd(struct ifnet *ifp)
 {
         struct axe_softc        *sc = ifp->if_softc;
@@ -303,7 +341,7 @@
 /*
  * Report current media status.
  */
-Static void
+static void
 axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
         struct axe_softc        *sc = ifp->if_softc;
@@ -316,7 +354,7 @@
         return;
 }
 
-Static void
+static void
 axe_setmulti(struct axe_softc *sc)
 {
 	struct ifnet		*ifp;
@@ -339,11 +377,7 @@
 		rxmode &= ~AXE_RXCMD_ALLMULTI;
 
 	IF_ADDR_LOCK(ifp);
-#if __FreeBSD_version >= 500000
 	TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#else
-	LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#endif
 	{
 		if (ifma->ifma_addr->sa_family != AF_LINK)
 			continue;
@@ -360,7 +394,94 @@
 	return;
 }
 
-Static void
+static void
+axe_ax88178_init(struct axe_softc *sc)
+{
+	int gpio0 = 0, phymode = 0;
+	u_int16_t eeprom;
+
+	axe_cmd(sc, AXE_CMD_SROM_WR_ENABLE, 0, 0, NULL);
+	/* XXX magic */
+	axe_cmd(sc, AXE_CMD_SROM_READ, 0, 0x0017, &eeprom);
+	axe_cmd(sc, AXE_CMD_SROM_WR_DISABLE, 0, 0, NULL);
+
+	/* if EEPROM is invalid we have to use to GPIO0 */
+	if (eeprom == 0xffff) {
+		phymode = 0;
+		gpio0 = 1;
+	} else {
+		phymode = eeprom & 7;
+		gpio0 = (eeprom & 0x80) ? 0 : 1;
+	}
+
+	axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x008c, NULL);
+	usbd_delay_ms(sc->axe_udev, 40);
+	if ((eeprom >> 8) != 1) {
+		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x003c, NULL);
+		usbd_delay_ms(sc->axe_udev, 30);
+
+		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x001c, NULL);
+		usbd_delay_ms(sc->axe_udev, 300);
+
+		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x003c, NULL);
+		usbd_delay_ms(sc->axe_udev, 30);
+	} else {
+		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x0004, NULL);
+		usbd_delay_ms(sc->axe_udev, 30);
+		axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x000c, NULL);
+		usbd_delay_ms(sc->axe_udev, 30);
+	}
+
+	/* soft reset */
+	axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, 0, NULL);
+	usbd_delay_ms(sc->axe_udev, 150);
+	axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
+	    AXE_SW_RESET_PRL | AXE_178_RESET_MAGIC, NULL);
+	usbd_delay_ms(sc->axe_udev, 150);
+	axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, 0, NULL);
+}
+
+static void
+axe_ax88772_init(struct axe_softc *sc)
+{
+	axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x00b0, NULL);
+	usbd_delay_ms(sc->axe_udev, 40);
+
+	if (sc->axe_phyaddrs[1] == AXE_INTPHY) {
+		/* ask for embedded PHY */
+		axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0x01, NULL);
+		usbd_delay_ms(sc->axe_udev, 10);
+
+		/* power down and reset state, pin reset state */
+		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, AXE_SW_RESET_CLEAR, NULL);
+		usbd_delay_ms(sc->axe_udev, 60);
+
+		/* power down/reset state, pin operating state */
+		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
+		    AXE_SW_RESET_IPPD | AXE_SW_RESET_PRL, NULL);
+		usbd_delay_ms(sc->axe_udev, 150);
+
+		/* power up, reset */
+		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, AXE_SW_RESET_PRL, NULL);
+
+		/* power up, operating */
+		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
+		    AXE_SW_RESET_IPRL | AXE_SW_RESET_PRL, NULL);
+	} else {
+		/* ask for external PHY */
+		axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0x00, NULL);
+		usbd_delay_ms(sc->axe_udev, 10);
+
+		/* power down/reset state, pin operating state */
+		axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0,
+		    AXE_SW_RESET_IPPD | AXE_SW_RESET_PRL, NULL);
+	}
+
+	usbd_delay_ms(sc->axe_udev, 150);
+	axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, 0, NULL);
+}
+
+static void
 axe_reset(struct axe_softc *sc)
 {
 	if (sc->axe_dying)
@@ -369,8 +490,7 @@
 	if (usbd_set_config_no(sc->axe_udev, AXE_CONFIG_NO, 1) ||
 	    usbd_device2interface_handle(sc->axe_udev, AXE_IFACE_IDX,
 	    &sc->axe_iface)) {
-		printf("axe%d: getting interface handle failed\n",
-		    sc->axe_unit);
+		device_printf(sc->axe_dev, "getting interface handle failed\n");
 	}
 
 	/* Wait a little while for the chip to get its brains in order. */
@@ -381,71 +501,80 @@
 /*
  * Probe for a AX88172 chip.
  */
-USB_MATCH(axe)
+static int
+axe_match(device_t self)
 {
-	USB_MATCH_START(axe, uaa);
-	struct axe_type			*t;
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 
 	if (!uaa->iface)
 		return(UMATCH_NONE);
-
-	t = axe_devs;
-	while(t->axe_vid) {
-		if (uaa->vendor == t->axe_vid &&
-		    uaa->product == t->axe_did) {
-			return(UMATCH_VENDOR_PRODUCT);
-		}
-		t++;
-	}
-
-	return(UMATCH_NONE);
+	return (axe_lookup(uaa->vendor, uaa->product) != NULL ?
+		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
 }
 
 /*
  * Attach the interface. Allocate softc structures, do ifmedia
  * setup and ethernet/BPF attach.
  */
-USB_ATTACH(axe)
+static int
+axe_attach(device_t self)
 {
-	USB_ATTACH_START(axe, sc, uaa);
-	char			devinfo[1024];
+	struct axe_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
+	const struct axe_type *type;
 	u_char			eaddr[ETHER_ADDR_LEN];
 	struct ifnet		*ifp;
 	usb_interface_descriptor_t	*id;
 	usb_endpoint_descriptor_t	*ed;
 	int			i;
 
-	bzero(sc, sizeof(struct axe_softc));
 	sc->axe_udev = uaa->device;
 	sc->axe_dev = self;
-	sc->axe_unit = device_get_unit(self);
+	type = axe_lookup(uaa->vendor, uaa->product);
+	if (type != NULL)
+		sc->axe_flags = type->axe_flags;
 
 	if (usbd_set_config_no(sc->axe_udev, AXE_CONFIG_NO, 1)) {
-		printf("axe%d: getting interface handle failed\n",
-		    sc->axe_unit);
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(sc->axe_dev, "getting interface handle failed\n");
+		return ENXIO;
 	}
 
+	usb_init_task(&sc->axe_tick_task, axe_tick_task, sc);
+
 	if (usbd_device2interface_handle(uaa->device,
 	    AXE_IFACE_IDX, &sc->axe_iface)) {
-		printf("axe%d: getting interface handle failed\n",
-		    sc->axe_unit);
-		USB_ATTACH_ERROR_RETURN;
+		device_printf(sc->axe_dev, "getting interface handle failed\n");
+		return ENXIO;
 	}
 
-	id = usbd_get_interface_descriptor(sc->axe_iface);
+	sc->axe_boundary = 64;
+#if 0
+	if (sc->axe_flags & (AX178|AX772)) {
+		if (sc->axe_udev->speed == USB_SPEED_HIGH) {
+			sc->axe_bufsz = AXE_178_MAX_BUFSZ;
+			sc->axe_boundary = 512;
+		} else
+			sc->axe_bufsz = AXE_178_MIN_BUFSZ;
+	} else
+		sc->axe_bufsz = AXE_172_BUFSZ
+#else
+	sc->axe_bufsz = AXE_172_BUFSZ;
+#endif
+{ /* XXX debug */
+device_printf(sc->axe_dev, "%s, bufsz %d, boundary %d\n",
+	sc->axe_flags & AX178 ? "AX88178" :
+	sc->axe_flags & AX772 ? "AX88772" : "AX88172",
+	sc->axe_bufsz, sc->axe_boundary);
+}
 
-	usbd_devinfo(uaa->device, 0, devinfo);
-	device_set_desc_copy(self, devinfo);
-	printf("%s: %s\n", USBDEVNAME(self), devinfo);
+	id = usbd_get_interface_descriptor(sc->axe_iface);
 
 	/* Find endpoints. */
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(sc->axe_iface, i);
 		if (!ed) {
-			printf("axe%d: couldn't get ep %d\n",
-			    sc->axe_unit, i);
-			USB_ATTACH_ERROR_RETURN;
+			device_printf(sc->axe_dev, "couldn't get ep %d\n", i);
+			return ENXIO;
 		}
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
@@ -459,22 +588,32 @@
 		}
 	}
 
-#if __FreeBSD_version >= 500000
 	mtx_init(&sc->axe_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
 	    MTX_DEF | MTX_RECURSE);
-#endif
+	sx_init(&sc->axe_sleeplock, device_get_nameunit(self));
+	AXE_SLEEPLOCK(sc);
 	AXE_LOCK(sc);
 
+	/* We need the PHYID for the init dance in some cases */
+	axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs);
+
+	if (sc->axe_flags & AX178)
+		axe_ax88178_init(sc);
+	else if (sc->axe_flags & AX772)
+		axe_ax88772_init(sc);
+
 	/*
 	 * Get station address.
 	 */
-	axe_cmd(sc, AXE_CMD_READ_NODEID, 0, 0, &eaddr);
+	if (sc->axe_flags & (AX178|AX772))
+		axe_cmd(sc, AXE_178_CMD_READ_NODEID, 0, 0, &eaddr);
+	else
+		axe_cmd(sc, AXE_172_CMD_READ_NODEID, 0, 0, &eaddr);
 
 	/*
-	 * Load IPG values and PHY indexes.
+	 * Fetch IPG values.
 	 */
 	axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, (void *)&sc->axe_ipgs);
-	axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs);
 
 	/*
 	 * Work around broken adapters that appear to lie about
@@ -484,15 +623,15 @@
 
 	ifp = sc->axe_ifp = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
-		printf("axe%d: can not if_alloc()\n", sc->axe_unit);
+		device_printf(sc->axe_dev, "can not if_alloc()\n");
 		AXE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
+		AXE_SLEEPUNLOCK(sc);
+		sx_destroy(&sc->axe_sleeplock);
 		mtx_destroy(&sc->axe_mtx);
-#endif
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 	ifp->if_softc = sc;
-	if_initname(ifp, "axe", sc->axe_unit);
+	if_initname(ifp, "axe", device_get_unit(sc->axe_dev));
 	ifp->if_mtu = ETHERMTU;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
 	    IFF_NEEDSGIANT;
@@ -500,43 +639,42 @@
 	ifp->if_start = axe_start;
 	ifp->if_watchdog = axe_watchdog;
 	ifp->if_init = axe_init;
-	ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
+	IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
+	ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
+	IFQ_SET_READY(&ifp->if_snd);
 
 	sc->axe_qdat.ifp = ifp;
 	sc->axe_qdat.if_rxstart = axe_rxstart;
 
 	if (mii_phy_probe(self, &sc->axe_miibus,
 	    axe_ifmedia_upd, axe_ifmedia_sts)) {
-		printf("axe%d: MII without any PHY!\n", sc->axe_unit);
+		device_printf(sc->axe_dev, "MII without any PHY!\n");
 		if_free(ifp);
 		AXE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
+		AXE_SLEEPUNLOCK(sc);
+		sx_destroy(&sc->axe_sleeplock);
 		mtx_destroy(&sc->axe_mtx);
-#endif
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 
 	/*
 	 * Call MI attach routine.
 	 */
 
-#if __FreeBSD_version >= 500000
 	ether_ifattach(ifp, eaddr);
-#else
-	ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
-#endif
 	callout_handle_init(&sc->axe_stat_ch);
 	usb_register_netisr();
 
 	sc->axe_dying = 0;
 
 	AXE_UNLOCK(sc);
+	AXE_SLEEPUNLOCK(sc);
 
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
-Static int
-axe_detach(device_ptr_t dev)
+static int
+axe_detach(device_t dev)
 {
 	struct axe_softc	*sc;
 	struct ifnet		*ifp;
@@ -547,12 +685,10 @@
 
 	sc->axe_dying = 1;
 	untimeout(axe_tick, sc, sc->axe_stat_ch);
-#if __FreeBSD_version >= 500000
+	usb_rem_task(sc->axe_udev, &sc->axe_tick_task);
+
 	ether_ifdetach(ifp);
 	if_free(ifp);
-#else
-	ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
-#endif
 
 	if (sc->axe_ep[AXE_ENDPT_TX] != NULL)
 		usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
@@ -562,14 +698,13 @@
 		usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
 
 	AXE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
+	sx_destroy(&sc->axe_sleeplock);
 	mtx_destroy(&sc->axe_mtx);
-#endif
 
 	return(0);
 }
 
-Static void
+static void
 axe_rxstart(struct ifnet *ifp)
 {
 	struct axe_softc	*sc;
@@ -581,8 +716,8 @@
 
 	c->ue_mbuf = usb_ether_newbuf();
 	if (c->ue_mbuf == NULL) {
-		printf("%s: no memory for rx list "
-		    "-- packet dropped!\n", USBDEVNAME(sc->axe_dev));
+		device_printf(sc->axe_dev, "no memory for rx list "
+		    "-- packet dropped!\n");
 		ifp->if_ierrors++;
 		AXE_UNLOCK(sc);
 		return;
@@ -602,14 +737,15 @@
  * A frame has been uploaded: pass the resulting mbuf chain up to
  * the higher level protocols.
  */
-Static void
+static void
 axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct axe_softc	*sc;
 	struct ue_chain	*c;
         struct mbuf		*m;
         struct ifnet		*ifp;
-	int			total_len = 0;
+	struct axe_sframe_hdr	hdr;
+	int			total_len = 0, pktlen;
 
 	c = priv;
 	sc = c->ue_sc;
@@ -627,7 +763,7 @@
 			return;
 		}
 		if (usbd_ratecheck(&sc->axe_rx_notice))
-			printf("axe%d: usb error on rx: %s\n", sc->axe_unit,
+			device_printf(sc->axe_dev, "usb error on rx: %s\n",
 			    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_RX]);
@@ -637,15 +773,36 @@
 	usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
 
 	m = c->ue_mbuf;
+	/* XXX don't handle multiple packets in one transfer */
+	if (sc->axe_flags & (AX178|AX772)) {
+		if (total_len < sizeof(hdr)) {
+			ifp->if_ierrors++;
+			goto done;
+		}
+		m_copydata(m, 0, sizeof(hdr), (caddr_t) &hdr);
+		total_len -= sizeof(hdr);
 
-	if (total_len < sizeof(struct ether_header)) {
-		ifp->if_ierrors++;
-		goto done;
+		if ((hdr.len ^ hdr.ilen) != 0xffff) {
+			ifp->if_ierrors++;
+			goto done;
+		}
+		pktlen = le16toh(hdr.len);
+		if (pktlen > total_len) {
+			ifp->if_ierrors++;
+			goto done;
+		}
+		m_adj(m, sizeof(hdr));
+	} else {
+		if (total_len < sizeof(struct ether_header)) {
+			ifp->if_ierrors++;
+			goto done;
+		}
+		pktlen = total_len;
 	}
 
 	ifp->if_ipackets++;
 	m->m_pkthdr.rcvif = (void *)&sc->axe_qdat;
-	m->m_pkthdr.len = m->m_len = total_len;
+	m->m_pkthdr.len = m->m_len = pktlen;
 
 	/* Put the packet on the special USB input queue. */
 	usb_ether_input(m);
@@ -668,7 +825,7 @@
  * the list buffers.
  */
 
-Static void
+static void
 axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct axe_softc	*sc;
@@ -686,7 +843,7 @@
 			AXE_UNLOCK(sc);
 			return;
 		}
-		printf("axe%d: usb error on tx: %s\n", sc->axe_unit,
+		device_printf(sc->axe_dev, "usb error on tx: %s\n",
 		    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_TX]);
@@ -714,9 +871,23 @@
 	return;
 }
 
-Static void
+static void
 axe_tick(void *xsc)
 {
+	struct axe_softc *sc = xsc;
+
+	if (sc == NULL)
+		return;
+	if (sc->axe_dying)
+		return;
+
+	/* Perform periodic stuff in process context */
+	usb_add_task(sc->axe_udev, &sc->axe_tick_task, USB_TASKQ_DRIVER);
+}
+
+static void
+axe_tick_task(void *xsc)
+{
 	struct axe_softc	*sc;
 	struct ifnet		*ifp;
 	struct mii_data		*mii;
@@ -726,12 +897,14 @@
 	if (sc == NULL)
 		return;
 
+	AXE_SLEEPLOCK(sc);
 	AXE_LOCK(sc);
 
 	ifp = sc->axe_ifp;
 	mii = GET_MII(sc);
 	if (mii == NULL) {
 		AXE_UNLOCK(sc);
+		AXE_SLEEPUNLOCK(sc);
 		return;
 	}
 
@@ -739,22 +912,25 @@
 	if (!sc->axe_link && mii->mii_media_status & IFM_ACTIVE &&
 	    IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
 		sc->axe_link++;
-		if (ifp->if_snd.ifq_head != NULL)
+		if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
 			axe_start(ifp);
 	}
 
 	sc->axe_stat_ch = timeout(axe_tick, sc, hz);
 
 	AXE_UNLOCK(sc);
+	AXE_SLEEPUNLOCK(sc);
 
 	return;
 }
 
-Static int
+static int
 axe_encap(struct axe_softc *sc, struct mbuf *m, int idx)
 {
 	struct ue_chain	*c;
 	usbd_status		err;
+	struct axe_sframe_hdr	hdr;
+	int			length;
 
 	c = &sc->axe_cdata.ue_tx_chain[idx];
 
@@ -762,17 +938,38 @@
 	 * Copy the mbuf data into a contiguous buffer, leaving two
 	 * bytes at the beginning to hold the frame length.
 	 */
-	m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf);
+	if (sc->axe_flags & (AX178|AX772)) {
+		hdr.len = htole16(m->m_pkthdr.len);
+		hdr.ilen = ~hdr.len;
+
+		memcpy(c->ue_buf, &hdr, sizeof(hdr));
+		length = sizeof(hdr);
+
+		m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf + sizeof(hdr));
+		length += m->m_pkthdr.len;
+
+		if ((length % sc->axe_boundary) == 0) {
+			hdr.len = 0;
+			hdr.ilen = 0xffff;
+			memcpy(c->ue_buf + length, &hdr, sizeof(hdr));
+			length += sizeof(hdr);
+		}
+	} else {
+		m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf);
+		length = m->m_pkthdr.len;
+	}
 	c->ue_mbuf = m;
 
 	usbd_setup_xfer(c->ue_xfer, sc->axe_ep[AXE_ENDPT_TX],
-	    c, c->ue_buf, m->m_pkthdr.len, USBD_FORCE_SHORT_XFER,
-	    10000, axe_txeof);
+	    c, c->ue_buf, length, USBD_FORCE_SHORT_XFER, 10000, axe_txeof);
 
 	/* Transmit */
 	err = usbd_transfer(c->ue_xfer);
 	if (err != USBD_IN_PROGRESS) {
+		/* XXX probably don't want to sleep here */
+		AXE_SLEEPLOCK(sc);
 		axe_stop(sc);
+		AXE_SLEEPUNLOCK(sc);
 		return(EIO);
 	}
 
@@ -781,7 +978,7 @@
 	return(0);
 }
 
-Static void
+static void
 axe_start(struct ifnet *ifp)
 {
 	struct axe_softc	*sc;
@@ -800,14 +997,14 @@
 		return;
 	}
 
-	IF_DEQUEUE(&ifp->if_snd, m_head);
+	IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
 	if (m_head == NULL) {
 		AXE_UNLOCK(sc);
 		return;
 	}
 
 	if (axe_encap(sc, m_head, 0)) {
-		IF_PREPEND(&ifp->if_snd, m_head);
+		IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
 		ifp->if_drv_flags |= IFF_DRV_OACTIVE;
 		AXE_UNLOCK(sc);
 		return;
@@ -830,7 +1027,7 @@
 	return;
 }
 
-Static void
+static void
 axe_init(void *xsc)
 {
 	struct axe_softc	*sc = xsc;
@@ -843,6 +1040,7 @@
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING)
 		return;
 
+	AXE_SLEEPLOCK(sc);
 	AXE_LOCK(sc);
 
 	/*
@@ -853,7 +1051,7 @@
 
 #ifdef notdef
 	/* Set MAC address */
-	axe_mac(sc, IFP2ENADDR(sc->axe_ifp), 1);
+	axe_mac(sc, IF_LLADDR(sc->axe_ifp), 1);
 #endif
 
 	/* Enable RX logic. */
@@ -861,26 +1059,38 @@
 	/* Init TX ring. */
 	if (usb_ether_tx_list_init(sc, &sc->axe_cdata,
 	    sc->axe_udev) == ENOBUFS) {
-		printf("axe%d: tx list init failed\n", sc->axe_unit);
+		device_printf(sc->axe_dev, "tx list init failed\n");
 		AXE_UNLOCK(sc);
+		AXE_SLEEPUNLOCK(sc);
 		return;
 	}
 
 	/* Init RX ring. */
 	if (usb_ether_rx_list_init(sc, &sc->axe_cdata,
 	    sc->axe_udev) == ENOBUFS) {
-		printf("axe%d: rx list init failed\n", sc->axe_unit);
+		device_printf(sc->axe_dev, "rx list init failed\n");
 		AXE_UNLOCK(sc);
+		AXE_SLEEPUNLOCK(sc);
 		return;
 	}
 
 	/* Set transmitter IPG values */
-	axe_cmd(sc, AXE_CMD_WRITE_IPG0, 0, sc->axe_ipgs[0], NULL);
-	axe_cmd(sc, AXE_CMD_WRITE_IPG1, 0, sc->axe_ipgs[1], NULL);
-	axe_cmd(sc, AXE_CMD_WRITE_IPG2, 0, sc->axe_ipgs[2], NULL);
+	if (sc->axe_flags & (AX178|AX772)) {
+		axe_cmd(sc, AXE_178_CMD_WRITE_IPG012, sc->axe_ipgs[2],
+		    (sc->axe_ipgs[1]<<8) | sc->axe_ipgs[0], NULL);
+	} else {
+		axe_cmd(sc, AXE_172_CMD_WRITE_IPG0, 0, sc->axe_ipgs[0], NULL);
+		axe_cmd(sc, AXE_172_CMD_WRITE_IPG1, 0, sc->axe_ipgs[1], NULL);
+		axe_cmd(sc, AXE_172_CMD_WRITE_IPG2, 0, sc->axe_ipgs[2], NULL);
+	}
 
 	/* Enable receiver, set RX mode */
-	rxmode = AXE_RXCMD_UNICAST|AXE_RXCMD_MULTICAST|AXE_RXCMD_ENABLE;
+	rxmode = AXE_RXCMD_MULTICAST|AXE_RXCMD_ENABLE;
+	if (sc->axe_flags & (AX178|AX772)) {
+		if (sc->axe_bufsz == AXE_178_MAX_BUFSZ)
+			rxmode |= AXE_178_RXCMD_MFB_16384;
+	} else
+		rxmode |= AXE_172_RXCMD_UNICAST;
 
 	/* If we want promiscuous mode, set the allframes bit. */
 	if (ifp->if_flags & IFF_PROMISC)
@@ -898,18 +1108,20 @@
 	err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_RX],
 	    USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_RX]);
 	if (err) {
-		printf("axe%d: open rx pipe failed: %s\n",
-		    sc->axe_unit, usbd_errstr(err));
+		device_printf(sc->axe_dev, "open rx pipe failed: %s\n",
+		    usbd_errstr(err));
 		AXE_UNLOCK(sc);
+		AXE_SLEEPUNLOCK(sc);
 		return;
 	}
 
 	err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_TX],
 	    USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_TX]);
 	if (err) {
-		printf("axe%d: open tx pipe failed: %s\n",
-		    sc->axe_unit, usbd_errstr(err));
+		device_printf(sc->axe_dev, "open tx pipe failed: %s\n",
+		    usbd_errstr(err));
 		AXE_UNLOCK(sc);
+		AXE_SLEEPUNLOCK(sc);
 		return;
 	}
 
@@ -926,13 +1138,14 @@
 	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
 
 	AXE_UNLOCK(sc);
+	AXE_SLEEPUNLOCK(sc);
 
 	sc->axe_stat_ch = timeout(axe_tick, sc, hz);
 
 	return;
 }
 
-Static int
+static int
 axe_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
 {
 	struct axe_softc	*sc = ifp->if_softc;
@@ -947,6 +1160,7 @@
 			if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
 			    ifp->if_flags & IFF_PROMISC &&
 			    !(sc->axe_if_flags & IFF_PROMISC)) {
+				AXE_SLEEPLOCK(sc);
 				AXE_LOCK(sc);
 				axe_cmd(sc, AXE_CMD_RXCTL_READ,
 					0, 0, (void *)&rxmode);
@@ -955,9 +1169,11 @@
 					0, rxmode, NULL);
 				AXE_UNLOCK(sc);
 				axe_setmulti(sc);
+				AXE_SLEEPUNLOCK(sc);
 			} else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
 			    !(ifp->if_flags & IFF_PROMISC) &&
 			    sc->axe_if_flags & IFF_PROMISC) {
+				AXE_SLEEPLOCK(sc);
 				AXE_LOCK(sc);
 				axe_cmd(sc, AXE_CMD_RXCTL_READ,
 					0, 0, (void *)&rxmode);
@@ -966,24 +1182,32 @@
 					0, rxmode, NULL);
 				AXE_UNLOCK(sc);
 				axe_setmulti(sc);
+				AXE_SLEEPUNLOCK(sc);
 			} else if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
 				axe_init(sc);
 		} else {
-			if (ifp->if_drv_flags & IFF_DRV_RUNNING)
+			if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+				AXE_SLEEPLOCK(sc);
 				axe_stop(sc);
+				AXE_SLEEPUNLOCK(sc);
+			}
 		}
 		sc->axe_if_flags = ifp->if_flags;
 		error = 0;
 		break;
 	case SIOCADDMULTI:
 	case SIOCDELMULTI:
+		AXE_SLEEPLOCK(sc);
 		axe_setmulti(sc);
+		AXE_SLEEPUNLOCK(sc);
 		error = 0;
 		break;
 	case SIOCGIFMEDIA:
 	case SIOCSIFMEDIA:
+		AXE_SLEEPLOCK(sc);
 		mii = GET_MII(sc);
 		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
+		AXE_SLEEPUNLOCK(sc);
 		break;
 
 	default:
@@ -991,12 +1215,10 @@
 		break;
 	}
 
-	AXE_UNLOCK(sc);
-
 	return(error);
 }
 
-Static void
+static void
 axe_watchdog(struct ifnet *ifp)
 {
 	struct axe_softc	*sc;
@@ -1007,7 +1229,7 @@
 	AXE_LOCK(sc);
 
 	ifp->if_oerrors++;
-	printf("axe%d: watchdog timeout\n", sc->axe_unit);
+	device_printf(sc->axe_dev, "watchdog timeout\n");
 
 	c = &sc->axe_cdata.ue_tx_chain[0];
 	usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
@@ -1015,7 +1237,7 @@
 
 	AXE_UNLOCK(sc);
 
-	if (ifp->if_snd.ifq_head != NULL)
+	if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
 		axe_start(ifp);
 
 	return;
@@ -1025,12 +1247,13 @@
  * Stop the adapter and free any mbufs allocated to the
  * RX and TX lists.
  */
-Static void
+static void
 axe_stop(struct axe_softc *sc)
 {
 	usbd_status		err;
 	struct ifnet		*ifp;
 
+	AXE_SLEEPLOCKASSERT(sc);
 	AXE_LOCK(sc);
 
 	ifp = sc->axe_ifp;
@@ -1042,13 +1265,13 @@
 	if (sc->axe_ep[AXE_ENDPT_RX] != NULL) {
 		err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]);
 		if (err) {
-			printf("axe%d: abort rx pipe failed: %s\n",
-		    	sc->axe_unit, usbd_errstr(err));
+			device_printf(sc->axe_dev, "abort rx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_RX]);
 		if (err) {
-			printf("axe%d: close rx pipe failed: %s\n",
-		    	sc->axe_unit, usbd_errstr(err));
+			device_printf(sc->axe_dev, "close rx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->axe_ep[AXE_ENDPT_RX] = NULL;
 	}
@@ -1056,13 +1279,13 @@
 	if (sc->axe_ep[AXE_ENDPT_TX] != NULL) {
 		err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
 		if (err) {
-			printf("axe%d: abort tx pipe failed: %s\n",
-		    	sc->axe_unit, usbd_errstr(err));
+			device_printf(sc->axe_dev, "abort tx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_TX]);
 		if (err) {
-			printf("axe%d: close tx pipe failed: %s\n",
-			    sc->axe_unit, usbd_errstr(err));
+			device_printf(sc->axe_dev, "close tx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->axe_ep[AXE_ENDPT_TX] = NULL;
 	}
@@ -1070,13 +1293,13 @@
 	if (sc->axe_ep[AXE_ENDPT_INTR] != NULL) {
 		err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
 		if (err) {
-			printf("axe%d: abort intr pipe failed: %s\n",
-		    	sc->axe_unit, usbd_errstr(err));
+			device_printf(sc->axe_dev,
+			    "abort intr pipe failed: %s\n", usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
 		if (err) {
-			printf("axe%d: close intr pipe failed: %s\n",
-			    sc->axe_unit, usbd_errstr(err));
+			device_printf(sc->axe_dev,
+			    "close intr pipe failed: %s\n", usbd_errstr(err));
 		}
 		sc->axe_ep[AXE_ENDPT_INTR] = NULL;
 	}
@@ -1099,14 +1322,16 @@
  * Stop all chip I/O so that the kernel's probe routines don't
  * get confused by errant DMAs when rebooting.
  */
-Static void
-axe_shutdown(device_ptr_t dev)
+static int
+axe_shutdown(device_t dev)
 {
 	struct axe_softc	*sc;
 
 	sc = device_get_softc(dev);
 
+	AXE_SLEEPLOCK(sc);
 	axe_stop(sc);
+	AXE_SLEEPUNLOCK(sc);
 
-	return;
+	return (0);
 }
Index: uhci_pci.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uhci_pci.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/uhci_pci.c -L sys/dev/usb/uhci_pci.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/uhci_pci.c
+++ sys/dev/usb/uhci_pci.c
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uhci_pci.c,v 1.57 2005/03/01 07:50:11 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uhci_pci.c,v 1.61.2.1 2007/11/26 18:21:42 jfv Exp $");
 
 /* Universal Host Controller Interface
  *
@@ -54,15 +54,15 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
 #include <sys/bus.h>
 #include <sys/queue.h>
-#if defined(__FreeBSD__)
 #include <sys/bus.h>
 
 #include <machine/bus.h>
 #include <machine/resource.h>
 #include <sys/rman.h>
-#endif
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
@@ -139,6 +139,18 @@
 #define PCI_UHCI_DEVICEID_ICH6_D	0x265b8086
 static const char *uhci_device_ich6_d = "Intel 82801FB/FR/FW/FRW (ICH6) USB controller USB-D";
 
+#define PCI_UHCI_DEVICEID_63XXESB_1	0x26888086
+static const char *uhci_device_esb_1 = "Intel 631XESB/632XESB/3100 USB controller USB-1";
+
+#define PCI_UHCI_DEVICEID_63XXESB_2	0x26898086
+static const char *uhci_device_esb_2 = "Intel 631XESB/632XESB/3100 USB controller USB-2";
+
+#define PCI_UHCI_DEVICEID_63XXESB_3	0x268a8086
+static const char *uhci_device_esb_3 = "Intel 631XESB/632XESB/3100 USB controller USB-3";
+
+#define PCI_UHCI_DEVICEID_63XXESB_4	0x268b8086
+static const char *uhci_device_esb_4 = "Intel 631XESB/632XESB/3100 USB controller USB-4";
+
 #define PCI_UHCI_DEVICEID_440MX		0x719a8086
 static const char *uhci_device_440mx = "Intel 82443MX USB controller";
 
@@ -153,11 +165,10 @@
 #define PCI_UHCI_BASE_REG               0x20
 
 
-static int uhci_pci_attach(device_t self);
-static int uhci_pci_detach(device_t self);
-static int uhci_pci_suspend(device_t self);
-static int uhci_pci_resume(device_t self);
-
+static device_attach_t uhci_pci_attach;
+static device_detach_t uhci_pci_detach;
+static device_suspend_t uhci_pci_suspend;
+static device_resume_t uhci_pci_resume;
 
 static int
 uhci_pci_suspend(device_t self)
@@ -231,6 +242,14 @@
 		return (uhci_device_ich6_c);
 	} else if (device_id == PCI_UHCI_DEVICEID_ICH6_D) {
 		return (uhci_device_ich6_d);
+	} else if (device_id == PCI_UHCI_DEVICEID_63XXESB_1) {
+		return (uhci_device_esb_1);
+	} else if (device_id == PCI_UHCI_DEVICEID_63XXESB_2) {
+		return (uhci_device_esb_2);
+	} else if (device_id == PCI_UHCI_DEVICEID_63XXESB_3) {
+		return (uhci_device_esb_3);
+	} else if (device_id == PCI_UHCI_DEVICEID_63XXESB_4) {
+		return (uhci_device_esb_4);
 	} else if (device_id == PCI_UHCI_DEVICEID_440MX) {
 		return (uhci_device_440mx);
 	} else if (device_id == PCI_UHCI_DEVICEID_460GX) {
@@ -328,7 +347,7 @@
 	}
 
 	err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_BIO,
-	    (driver_intr_t *) uhci_intr, sc, &sc->ih);
+	    NULL, (driver_intr_t *) uhci_intr, sc, &sc->ih);
 	if (err) {
 		device_printf(self, "Could not setup irq, %d\n", err);
 		sc->ih = NULL;
@@ -348,6 +367,29 @@
 #endif
 	pci_write_config(self, PCI_LEGSUP, PCI_LEGSUP_USBPIRQDEN, 2);
 
+	/* Allocate a parent dma tag for DMA maps */
+	err = bus_dma_tag_create(bus_get_dma_tag(self), 1, 0,
+	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+	    BUS_SPACE_MAXSIZE_32BIT, USB_DMA_NSEG, BUS_SPACE_MAXSIZE_32BIT, 0,
+	    NULL, NULL, &sc->sc_bus.parent_dmatag);
+	if (err) {
+		device_printf(self, "Could not allocate parent DMA tag (%d)\n",
+		    err);
+		uhci_pci_detach(self);
+		return ENXIO;
+	}
+	/* Allocate a dma tag for transfer buffers */
+	err = bus_dma_tag_create(sc->sc_bus.parent_dmatag, 1, 0,
+	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+	    BUS_SPACE_MAXSIZE_32BIT, USB_DMA_NSEG, BUS_SPACE_MAXSIZE_32BIT, 0,
+	    busdma_lock_mutex, &Giant, &sc->sc_bus.buffer_dmatag);
+	if (err) {
+		device_printf(self, "Could not allocate transfer tag (%d)\n",
+		    err);
+		uhci_pci_detach(self);
+		return ENXIO;
+	}
+
 	err = uhci_init(sc);
 	if (!err) {
 		sc->sc_flags |= UHCI_SCFLG_DONEINIT;
@@ -372,6 +414,10 @@
 		sc->sc_flags &= ~UHCI_SCFLG_DONEINIT;
 	}
 
+	if (sc->sc_bus.parent_dmatag != NULL)
+		bus_dma_tag_destroy(sc->sc_bus.parent_dmatag);
+	if (sc->sc_bus.buffer_dmatag != NULL)
+		bus_dma_tag_destroy(sc->sc_bus.buffer_dmatag);
 
 	if (sc->irq_res && sc->ih) {
 		int err = bus_teardown_intr(self, sc->irq_res, sc->ih);
Index: uhci.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/uhci.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/usb/uhci.c -L sys/dev/usb/uhci.c -u -r1.2 -r1.3
--- sys/dev/usb/uhci.c
+++ sys/dev/usb/uhci.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/uhci.c,v 1.162.2.1 2006/03/01 01:59:04 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/uhci.c,v 1.175 2007/06/14 16:23:31 imp Exp $");
 
 
 /*-
@@ -65,17 +65,12 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/device.h>
-#include <sys/select.h>
-#elif defined(__FreeBSD__)
 #include <sys/endian.h>
 #include <sys/module.h>
 #include <sys/bus.h>
 #if defined(DIAGNOSTIC) && defined(__i386__)
 #include <machine/cpu.h>
 #endif
-#endif
 #include <sys/proc.h>
 #include <sys/queue.h>
 #include <sys/sysctl.h>
@@ -95,20 +90,10 @@
 /* Use bandwidth reclamation for control transfers. Some devices choke on it. */
 /*#define UHCI_CTL_LOOP */
 
-#if defined(__FreeBSD__)
-#include <machine/clock.h>
-
 #define delay(d)		DELAY(d)
-#endif
 
 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
 
-#if defined(__OpenBSD__)
-struct cfdriver uhci_cd = {
-	NULL, "uhci", DV_DULL
-};
-#endif
-
 #ifdef USB_DEBUG
 uhci_softc_t *thesc;
 #define DPRINTF(x)	if (uhcidebug) printf x
@@ -120,28 +105,12 @@
 	   &uhcidebug, 0, "uhci debug level");
 SYSCTL_INT(_hw_usb_uhci, OID_AUTO, loop, CTLFLAG_RW,
 	   &uhcinoloop, 0, "uhci noloop");
-#ifndef __NetBSD__
 #define bitmask_snprintf(q,f,b,l) snprintf((b), (l), "%b", (q), (f))
-#endif
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n,x)
 #endif
 
-/*
- * The UHCI controller is little endian, so on big endian machines
- * the data strored in memory needs to be swapped.
- */
-#if defined(__OpenBSD__)
-#if BYTE_ORDER == BIG_ENDIAN
-#define htole32(x) (bswap32(x))
-#define le32toh(x) (bswap32(x))
-#else
-#define htole32(x) (x)
-#define le32toh(x) (x)
-#endif
-#endif
-
 struct uhci_pipe {
 	struct usbd_pipe pipe;
 	int nexttoggle;
@@ -178,118 +147,124 @@
 	} u;
 };
 
-Static void		uhci_globalreset(uhci_softc_t *);
-Static usbd_status	uhci_portreset(uhci_softc_t*, int);
-Static void		uhci_reset(uhci_softc_t *);
+static void		uhci_globalreset(uhci_softc_t *);
+static usbd_status	uhci_portreset(uhci_softc_t*, int);
+static void		uhci_reset(uhci_softc_t *);
 #if defined(__NetBSD__) || defined(__OpenBSD__)
-Static void		uhci_shutdown(void *v);
-Static void		uhci_power(int, void *);
+static void		uhci_shutdown(void *v);
+static void		uhci_power(int, void *);
 #endif
-Static usbd_status	uhci_run(uhci_softc_t *, int run);
-Static uhci_soft_td_t  *uhci_alloc_std(uhci_softc_t *);
-Static void		uhci_free_std(uhci_softc_t *, uhci_soft_td_t *);
-Static uhci_soft_qh_t  *uhci_alloc_sqh(uhci_softc_t *);
-Static void		uhci_free_sqh(uhci_softc_t *, uhci_soft_qh_t *);
+static usbd_status	uhci_run(uhci_softc_t *, int run);
+static uhci_soft_td_t  *uhci_alloc_std(uhci_softc_t *);
+static void		uhci_free_std(uhci_softc_t *, uhci_soft_td_t *);
+static uhci_soft_qh_t  *uhci_alloc_sqh(uhci_softc_t *);
+static void		uhci_free_sqh(uhci_softc_t *, uhci_soft_qh_t *);
+static usbd_status	uhci_aux_dma_alloc(uhci_softc_t *, uhci_soft_td_t *,
+			    void *data, int len);
+static uhci_physaddr_t	uhci_aux_dma_prepare(uhci_soft_td_t *, int);
+static void		uhci_aux_dma_complete(uhci_soft_td_t *, int);
 #if 0
-Static void		uhci_enter_ctl_q(uhci_softc_t *, uhci_soft_qh_t *,
+static void		uhci_enter_ctl_q(uhci_softc_t *, uhci_soft_qh_t *,
 					 uhci_intr_info_t *);
-Static void		uhci_exit_ctl_q(uhci_softc_t *, uhci_soft_qh_t *);
+static void		uhci_exit_ctl_q(uhci_softc_t *, uhci_soft_qh_t *);
 #endif
 
-Static void		uhci_free_std_chain(uhci_softc_t *,
+static void		uhci_free_std_chain(uhci_softc_t *,
 					    uhci_soft_td_t *, uhci_soft_td_t *);
-Static usbd_status	uhci_alloc_std_chain(struct uhci_pipe *,
-			    uhci_softc_t *, int, int, u_int16_t, usb_dma_t *,
+static usbd_status	uhci_alloc_std_chain(struct uhci_pipe *,
+			    uhci_softc_t *, int, int, u_int16_t,
+			    usbd_xfer_handle xfer,
 			    uhci_soft_td_t **, uhci_soft_td_t **);
-Static void		uhci_poll_hub(void *);
-Static void		uhci_waitintr(uhci_softc_t *, usbd_xfer_handle);
-Static void		uhci_check_intr(uhci_softc_t *, uhci_intr_info_t *);
-Static void		uhci_idone(uhci_intr_info_t *);
-
-Static void		uhci_abort_xfer(usbd_xfer_handle, usbd_status status);
-
-Static void		uhci_timeout(void *);
-Static void		uhci_timeout_task(void *);
-Static void		uhci_add_ls_ctrl(uhci_softc_t *, uhci_soft_qh_t *);
-Static void		uhci_add_hs_ctrl(uhci_softc_t *, uhci_soft_qh_t *);
-Static void		uhci_add_bulk(uhci_softc_t *, uhci_soft_qh_t *);
-Static void		uhci_remove_ls_ctrl(uhci_softc_t *,uhci_soft_qh_t *);
-Static void		uhci_remove_hs_ctrl(uhci_softc_t *,uhci_soft_qh_t *);
-Static void		uhci_remove_bulk(uhci_softc_t *,uhci_soft_qh_t *);
-Static int		uhci_str(usb_string_descriptor_t *, int, char *);
-Static void		uhci_add_loop(uhci_softc_t *sc);
-Static void		uhci_rem_loop(uhci_softc_t *sc);
-
-Static usbd_status	uhci_setup_isoc(usbd_pipe_handle pipe);
-Static void		uhci_device_isoc_enter(usbd_xfer_handle);
-
-Static usbd_status	uhci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t);
-Static void		uhci_freem(struct usbd_bus *, usb_dma_t *);
-
-Static usbd_xfer_handle	uhci_allocx(struct usbd_bus *);
-Static void		uhci_freex(struct usbd_bus *, usbd_xfer_handle);
-
-Static usbd_status	uhci_device_ctrl_transfer(usbd_xfer_handle);
-Static usbd_status	uhci_device_ctrl_start(usbd_xfer_handle);
-Static void		uhci_device_ctrl_abort(usbd_xfer_handle);
-Static void		uhci_device_ctrl_close(usbd_pipe_handle);
-Static void		uhci_device_ctrl_done(usbd_xfer_handle);
-
-Static usbd_status	uhci_device_intr_transfer(usbd_xfer_handle);
-Static usbd_status	uhci_device_intr_start(usbd_xfer_handle);
-Static void		uhci_device_intr_abort(usbd_xfer_handle);
-Static void		uhci_device_intr_close(usbd_pipe_handle);
-Static void		uhci_device_intr_done(usbd_xfer_handle);
-
-Static usbd_status	uhci_device_bulk_transfer(usbd_xfer_handle);
-Static usbd_status	uhci_device_bulk_start(usbd_xfer_handle);
-Static void		uhci_device_bulk_abort(usbd_xfer_handle);
-Static void		uhci_device_bulk_close(usbd_pipe_handle);
-Static void		uhci_device_bulk_done(usbd_xfer_handle);
-
-Static usbd_status	uhci_device_isoc_transfer(usbd_xfer_handle);
-Static usbd_status	uhci_device_isoc_start(usbd_xfer_handle);
-Static void		uhci_device_isoc_abort(usbd_xfer_handle);
-Static void		uhci_device_isoc_close(usbd_pipe_handle);
-Static void		uhci_device_isoc_done(usbd_xfer_handle);
-
-Static usbd_status	uhci_root_ctrl_transfer(usbd_xfer_handle);
-Static usbd_status	uhci_root_ctrl_start(usbd_xfer_handle);
-Static void		uhci_root_ctrl_abort(usbd_xfer_handle);
-Static void		uhci_root_ctrl_close(usbd_pipe_handle);
-Static void		uhci_root_ctrl_done(usbd_xfer_handle);
-
-Static usbd_status	uhci_root_intr_transfer(usbd_xfer_handle);
-Static usbd_status	uhci_root_intr_start(usbd_xfer_handle);
-Static void		uhci_root_intr_abort(usbd_xfer_handle);
-Static void		uhci_root_intr_close(usbd_pipe_handle);
-Static void		uhci_root_intr_done(usbd_xfer_handle);
-
-Static usbd_status	uhci_open(usbd_pipe_handle);
-Static void		uhci_poll(struct usbd_bus *);
-Static void		uhci_softintr(void *);
-
-Static usbd_status	uhci_device_request(usbd_xfer_handle xfer);
-
-Static void		uhci_add_intr(uhci_softc_t *, uhci_soft_qh_t *);
-Static void		uhci_remove_intr(uhci_softc_t *, uhci_soft_qh_t *);
-Static usbd_status	uhci_device_setintr(uhci_softc_t *sc,
+static void		uhci_poll_hub(void *);
+static void		uhci_waitintr(uhci_softc_t *, usbd_xfer_handle);
+static void		uhci_check_intr(uhci_softc_t *, uhci_intr_info_t *);
+static void		uhci_idone(uhci_intr_info_t *);
+
+static void		uhci_abort_xfer(usbd_xfer_handle, usbd_status status);
+static void		uhci_transfer_complete(usbd_xfer_handle xfer);
+
+static void		uhci_timeout(void *);
+static void		uhci_timeout_task(void *);
+static void		uhci_add_ls_ctrl(uhci_softc_t *, uhci_soft_qh_t *);
+static void		uhci_add_hs_ctrl(uhci_softc_t *, uhci_soft_qh_t *);
+static void		uhci_add_bulk(uhci_softc_t *, uhci_soft_qh_t *);
+static void		uhci_remove_ls_ctrl(uhci_softc_t *,uhci_soft_qh_t *);
+static void		uhci_remove_hs_ctrl(uhci_softc_t *,uhci_soft_qh_t *);
+static void		uhci_remove_bulk(uhci_softc_t *,uhci_soft_qh_t *);
+static int		uhci_str(usb_string_descriptor_t *, int, char *);
+static void		uhci_add_loop(uhci_softc_t *sc);
+static void		uhci_rem_loop(uhci_softc_t *sc);
+
+static usbd_status	uhci_setup_isoc(usbd_pipe_handle pipe);
+static void		uhci_device_isoc_enter(usbd_xfer_handle);
+
+static usbd_status	uhci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t);
+static void		uhci_freem(struct usbd_bus *, usb_dma_t *);
+
+static usbd_xfer_handle	uhci_allocx(struct usbd_bus *);
+static void		uhci_freex(struct usbd_bus *, usbd_xfer_handle);
+
+static usbd_status	uhci_device_ctrl_transfer(usbd_xfer_handle);
+static usbd_status	uhci_device_ctrl_start(usbd_xfer_handle);
+static void		uhci_device_ctrl_abort(usbd_xfer_handle);
+static void		uhci_device_ctrl_close(usbd_pipe_handle);
+static void		uhci_device_ctrl_done(usbd_xfer_handle);
+
+static usbd_status	uhci_device_intr_transfer(usbd_xfer_handle);
+static usbd_status	uhci_device_intr_start(usbd_xfer_handle);
+static void		uhci_device_intr_abort(usbd_xfer_handle);
+static void		uhci_device_intr_close(usbd_pipe_handle);
+static void		uhci_device_intr_done(usbd_xfer_handle);
+
+static usbd_status	uhci_device_bulk_transfer(usbd_xfer_handle);
+static usbd_status	uhci_device_bulk_start(usbd_xfer_handle);
+static void		uhci_device_bulk_abort(usbd_xfer_handle);
+static void		uhci_device_bulk_close(usbd_pipe_handle);
+static void		uhci_device_bulk_done(usbd_xfer_handle);
+
+static usbd_status	uhci_device_isoc_transfer(usbd_xfer_handle);
+static usbd_status	uhci_device_isoc_start(usbd_xfer_handle);
+static void		uhci_device_isoc_abort(usbd_xfer_handle);
+static void		uhci_device_isoc_close(usbd_pipe_handle);
+static void		uhci_device_isoc_done(usbd_xfer_handle);
+
+static usbd_status	uhci_root_ctrl_transfer(usbd_xfer_handle);
+static usbd_status	uhci_root_ctrl_start(usbd_xfer_handle);
+static void		uhci_root_ctrl_abort(usbd_xfer_handle);
+static void		uhci_root_ctrl_close(usbd_pipe_handle);
+static void		uhci_root_ctrl_done(usbd_xfer_handle);
+
+static usbd_status	uhci_root_intr_transfer(usbd_xfer_handle);
+static usbd_status	uhci_root_intr_start(usbd_xfer_handle);
+static void		uhci_root_intr_abort(usbd_xfer_handle);
+static void		uhci_root_intr_close(usbd_pipe_handle);
+static void		uhci_root_intr_done(usbd_xfer_handle);
+
+static usbd_status	uhci_open(usbd_pipe_handle);
+static void		uhci_poll(struct usbd_bus *);
+static void		uhci_softintr(void *);
+
+static usbd_status	uhci_device_request(usbd_xfer_handle xfer);
+
+static void		uhci_add_intr(uhci_softc_t *, uhci_soft_qh_t *);
+static void		uhci_remove_intr(uhci_softc_t *, uhci_soft_qh_t *);
+static usbd_status	uhci_device_setintr(uhci_softc_t *sc,
 			    struct uhci_pipe *pipe, int ival);
 
-Static void		uhci_device_clear_toggle(usbd_pipe_handle pipe);
-Static void		uhci_noop(usbd_pipe_handle pipe);
+static void		uhci_device_clear_toggle(usbd_pipe_handle pipe);
+static void		uhci_noop(usbd_pipe_handle pipe);
 
-Static __inline uhci_soft_qh_t *uhci_find_prev_qh(uhci_soft_qh_t *,
+static __inline uhci_soft_qh_t *uhci_find_prev_qh(uhci_soft_qh_t *,
 						  uhci_soft_qh_t *);
 
 #ifdef USB_DEBUG
-Static void		uhci_dump_all(uhci_softc_t *);
-Static void		uhci_dumpregs(uhci_softc_t *);
-Static void		uhci_dump_qhs(uhci_soft_qh_t *);
-Static void		uhci_dump_qh(uhci_soft_qh_t *);
-Static void		uhci_dump_tds(uhci_soft_td_t *);
-Static void		uhci_dump_td(uhci_soft_td_t *);
-Static void		uhci_dump_ii(uhci_intr_info_t *ii);
+static void		uhci_dump_all(uhci_softc_t *);
+static void		uhci_dumpregs(uhci_softc_t *);
+static void		uhci_dump_qhs(uhci_soft_qh_t *);
+static void		uhci_dump_qh(uhci_soft_qh_t *);
+static void		uhci_dump_tds(uhci_soft_td_t *);
+static void		uhci_dump_td(uhci_soft_td_t *);
+static void		uhci_dump_ii(uhci_intr_info_t *ii);
 void			uhci_dump(void);
 #endif
 
@@ -390,7 +365,7 @@
 	} while (0)
 #define uhci_active_intr_info(ii) ((ii)->list.le_prev != NULL)
 
-Static __inline uhci_soft_qh_t *
+static __inline uhci_soft_qh_t *
 uhci_find_prev_qh(uhci_soft_qh_t *pqh, uhci_soft_qh_t *sqh)
 {
 	DPRINTFN(15,("uhci_find_prev_qh: pqh=%p sqh=%p\n", pqh, sqh));
@@ -493,7 +468,7 @@
 	clsqh = uhci_alloc_sqh(sc);
 	if (clsqh == NULL)
 		return (USBD_NOMEM);
-	clsqh->hlink = bsqh;
+	clsqh->hlink = chsqh;
 	clsqh->qh.qh_hlink = htole32(chsqh->physaddr | UHCI_PTR_QH);
 	clsqh->elink = NULL;
 	clsqh->qh.qh_elink = htole32(UHCI_PTR_T);
@@ -530,9 +505,9 @@
 
 	LIST_INIT(&sc->sc_intrhead);
 
-	SIMPLEQ_INIT(&sc->sc_free_xfers);
+	STAILQ_INIT(&sc->sc_free_xfers);
 
-	usb_callout_init(sc->sc_poll_handle);
+	callout_init(&sc->sc_poll_handle, 0);
 
 	/* Set up the bus struct. */
 	sc->sc_bus.methods = &uhci_bus_methods;
@@ -553,39 +528,13 @@
 	return (uhci_run(sc, 1));		/* and here we go... */
 }
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-uhci_activate(device_ptr_t self, enum devact act)
-{
-	struct uhci_softc *sc = (struct uhci_softc *)self;
-	int rv = 0;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-
-	case DVACT_DEACTIVATE:
-		if (sc->sc_child != NULL)
-			rv = config_deactivate(sc->sc_child);
-		break;
-	}
-	return (rv);
-}
-#endif
-
 int
 uhci_detach(struct uhci_softc *sc, int flags)
 {
 	usbd_xfer_handle xfer;
 	int rv = 0;
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	if (sc->sc_child != NULL)
-		rv = config_detach(sc->sc_child, flags);
-
-	if (rv != 0)
-		return (rv);
-#endif
+	sc->sc_dying = 1;
 
 	UWRITE2(sc, UHCI_INTR, 0);		/* disable interrupts */
 	uhci_run(sc, 0);
@@ -597,10 +546,10 @@
 
 	/* Free all xfers associated with this HC. */
 	for (;;) {
-		xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
+		xfer = STAILQ_FIRST(&sc->sc_free_xfers);
 		if (xfer == NULL)
 			break;
-		SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
+		STAILQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
 		free(xfer, M_USB);
 	}
 
@@ -628,9 +577,9 @@
 	struct uhci_softc *sc = (struct uhci_softc *)bus;
 	usbd_xfer_handle xfer;
 
-	xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
+	xfer = STAILQ_FIRST(&sc->sc_free_xfers);
 	if (xfer != NULL) {
-		SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
+		STAILQ_REMOVE_HEAD(&sc->sc_free_xfers, next);
 #ifdef DIAGNOSTIC
 		if (xfer->busy_free != XFER_FREE) {
 			printf("uhci_allocx: xfer=%p not free, 0x%08x\n", xfer,
@@ -671,7 +620,7 @@
 		return;
 	}
 #endif
-	SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
+	STAILQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
 }
 
 /*
@@ -712,10 +661,10 @@
 			uhci_dumpregs(sc);
 #endif
 		if (sc->sc_intr_xfer != NULL)
-			usb_uncallout(sc->sc_poll_handle, uhci_poll_hub,
-			    sc->sc_intr_xfer);
+			callout_stop(&sc->sc_poll_handle);
 		sc->sc_bus.use_polling++;
 		uhci_run(sc, 0); /* stop the controller */
+		cmd &= ~UHCI_CMD_RS;
 
 		/* save some state if BIOS doesn't */
 		sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM);
@@ -759,8 +708,8 @@
 		usb_delay_ms(&sc->sc_bus, USB_RESUME_RECOVERY);
 		sc->sc_bus.use_polling--;
 		if (sc->sc_intr_xfer != NULL)
-			usb_callout(sc->sc_poll_handle, sc->sc_ival,
-				    uhci_poll_hub, sc->sc_intr_xfer);
+			callout_reset(&sc->sc_poll_handle, sc->sc_ival,
+			    uhci_poll_hub, sc->sc_intr_xfer);
 #ifdef USB_DEBUG
 		if (uhcidebug > 2)
 			uhci_dumpregs(sc);
@@ -770,12 +719,12 @@
 }
 
 #ifdef USB_DEBUG
-Static void
+static void
 uhci_dumpregs(uhci_softc_t *sc)
 {
 	DPRINTFN(-1,("%s regs: cmd=%04x, sts=%04x, intr=%04x, frnum=%04x, "
 		     "flbase=%08x, sof=%04x, portsc1=%04x, portsc2=%04x\n",
-		     USBDEVNAME(sc->sc_bus.bdev),
+		     device_get_nameunit(sc->sc_bus.bdev),
 		     UREAD2(sc, UHCI_CMD),
 		     UREAD2(sc, UHCI_STS),
 		     UREAD2(sc, UHCI_INTR),
@@ -894,7 +843,7 @@
 	}
 }
 
-Static void
+static void
 uhci_dump_ii(uhci_intr_info_t *ii)
 {
 	usbd_pipe_handle pipe;
@@ -967,15 +916,16 @@
 {
 	usbd_xfer_handle xfer = addr;
 	usbd_pipe_handle pipe = xfer->pipe;
-	uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
+	usbd_device_handle dev = pipe->device;
+	uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
 	int s;
 	u_char *p;
 
 	DPRINTFN(20, ("uhci_poll_hub\n"));
 
-	usb_callout(sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, xfer);
+	callout_reset(&sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, xfer);
 
-	p = KERNADDR(&xfer->dmabuf, 0);
+	p = xfer->buffer;
 	p[0] = 0;
 	if (UREAD2(sc, UHCI_PORTSC1) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC))
 		p[0] |= 1<<1;
@@ -988,9 +938,9 @@
 	xfer->actlen = 1;
 	xfer->status = USBD_NORMAL_COMPLETION;
 	s = splusb();
-	xfer->device->bus->intr_context++;
-	usb_transfer_complete(xfer);
-	xfer->device->bus->intr_context--;
+	dev->bus->intr_context++;
+	uhci_transfer_complete(xfer);
+	dev->bus->intr_context--;
 	splx(s);
 }
 
@@ -1169,7 +1119,7 @@
 		sc->sc_bulk_end = pqh;
 }
 
-Static int uhci_intr1(uhci_softc_t *);
+static int uhci_intr1(uhci_softc_t *);
 
 int
 uhci_intr(void *arg)
@@ -1214,7 +1164,7 @@
 
 #ifdef USB_DEBUG
 	if (uhcidebug > 15) {
-		DPRINTF(("%s: uhci_intr1\n", USBDEVNAME(sc->sc_bus.bdev)));
+		DPRINTF(("%s: uhci_intr1\n", device_get_nameunit(sc->sc_bus.bdev)));
 		uhci_dumpregs(sc);
 	}
 #endif
@@ -1229,7 +1179,7 @@
 
 	if (sc->sc_suspend != PWR_RESUME) {
 		printf("%s: interrupt while not operating ignored\n",
-		       USBDEVNAME(sc->sc_bus.bdev));
+		       device_get_nameunit(sc->sc_bus.bdev));
 		UWRITE2(sc, UHCI_STS, status); /* acknowledge the ints */
 		return (0);
 	}
@@ -1242,23 +1192,23 @@
 	if (status & UHCI_STS_RD) {
 		ack |= UHCI_STS_RD;
 #ifdef USB_DEBUG
-		printf("%s: resume detect\n", USBDEVNAME(sc->sc_bus.bdev));
+		printf("%s: resume detect\n", device_get_nameunit(sc->sc_bus.bdev));
 #endif
 	}
 	if (status & UHCI_STS_HSE) {
 		ack |= UHCI_STS_HSE;
-		printf("%s: host system error\n", USBDEVNAME(sc->sc_bus.bdev));
+		printf("%s: host system error\n", device_get_nameunit(sc->sc_bus.bdev));
 	}
 	if (status & UHCI_STS_HCPE) {
 		ack |= UHCI_STS_HCPE;
 		printf("%s: host controller process error\n",
-		       USBDEVNAME(sc->sc_bus.bdev));
+		       device_get_nameunit(sc->sc_bus.bdev));
 	}
 	if (status & UHCI_STS_HCH) {
 		/* no acknowledge needed */
 		if (!sc->sc_dying) {
 			printf("%s: host controller halted\n",
-			    USBDEVNAME(sc->sc_bus.bdev));
+			    device_get_nameunit(sc->sc_bus.bdev));
 #ifdef USB_DEBUG
 			uhci_dump_all(sc);
 #endif
@@ -1273,7 +1223,7 @@
 	sc->sc_bus.no_intrs++;
 	usb_schedsoftintr(&sc->sc_bus);
 
-	DPRINTFN(15, ("%s: uhci_intr: exit\n", USBDEVNAME(sc->sc_bus.bdev)));
+	DPRINTFN(15, ("%s: uhci_intr: exit\n", device_get_nameunit(sc->sc_bus.bdev)));
 
 	return (1);
 }
@@ -1284,7 +1234,7 @@
 	uhci_softc_t *sc = v;
 	uhci_intr_info_t *ii, *nextii;
 
-	DPRINTFN(10,("%s: uhci_softintr (%d)\n", USBDEVNAME(sc->sc_bus.bdev),
+	DPRINTFN(10,("%s: uhci_softintr (%d)\n", device_get_nameunit(sc->sc_bus.bdev),
 		     sc->sc_bus.intr_context));
 
 	sc->sc_bus.intr_context++;
@@ -1369,7 +1319,7 @@
 	}
  done:
 	DPRINTFN(12, ("uhci_check_intr: ii=%p done\n", ii));
-	usb_uncallout(ii->xfer->timeout_handle, uhci_timeout, ii);
+	callout_stop(&ii->xfer->timeout_handle);
 	usb_rem_task(ii->xfer->pipe->device, &UXFER(ii->xfer)->abort_task);
 	uhci_idone(ii);
 }
@@ -1496,7 +1446,7 @@
 	}
 
  end:
-	usb_transfer_complete(xfer);
+	uhci_transfer_complete(xfer);
 	DPRINTFN(12, ("uhci_idone: ii=%p done\n", ii));
 }
 
@@ -1519,7 +1469,8 @@
 	}
 
 	/* Execute the abort in a process context. */
-	usb_add_task(uxfer->xfer.pipe->device, &uxfer->abort_task);
+	usb_add_task(uxfer->xfer.pipe->device, &uxfer->abort_task,
+	    USB_TASKQ_HC);
 }
 
 void
@@ -1593,7 +1544,7 @@
 		usb_delay_ms(&sc->sc_bus, 1);
 	if (n >= UHCI_RESET_TIMEOUT)
 		printf("%s: controller did not reset\n",
-		       USBDEVNAME(sc->sc_bus.bdev));
+		       device_get_nameunit(sc->sc_bus.bdev));
 }
 
 usbd_status
@@ -1623,7 +1574,7 @@
 		usb_delay_ms(&sc->sc_bus, 1);
 	}
 	splx(s);
-	printf("%s: cannot %s\n", USBDEVNAME(sc->sc_bus.bdev),
+	printf("%s: cannot %s\n", device_get_nameunit(sc->sc_bus.bdev),
 	       run ? "start" : "stop");
 	return (USBD_IOERROR);
 }
@@ -1657,6 +1608,9 @@
 			std = KERNADDR(&dma, offs);
 			std->physaddr = DMAADDR(&dma, offs);
 			std->link.std = sc->sc_freetds;
+			std->aux_dma.block = NULL;
+			std->aux_data = NULL;
+			std->aux_len = 0;
 			sc->sc_freetds = std;
 		}
 	}
@@ -1677,6 +1631,12 @@
 	}
 	std->td.td_token = htole32(TD_IS_FREE);
 #endif
+	if (std->aux_dma.block != NULL) {
+		usb_freemem(&sc->sc_bus, &std->aux_dma);
+		std->aux_dma.block = NULL;
+		std->aux_data = NULL;
+		std->aux_len = 0;
+	}
 	std->link.std = sc->sc_freetds;
 	sc->sc_freetds = std;
 }
@@ -1730,12 +1690,12 @@
 
 usbd_status
 uhci_alloc_std_chain(struct uhci_pipe *upipe, uhci_softc_t *sc, int len,
-		     int rd, u_int16_t flags, usb_dma_t *dma,
+		     int rd, u_int16_t flags, usbd_xfer_handle xfer,
 		     uhci_soft_td_t **sp, uhci_soft_td_t **ep)
 {
-	uhci_soft_td_t *p, *lastp;
-	uhci_physaddr_t lastlink;
-	int i, ntd, l, tog, maxp;
+	struct usb_dma_mapping *dma = &xfer->dmamap;
+	uhci_soft_td_t *p, *prevp, *startp;
+	int err, i, ntd, l, tog, maxp, seg, segoff;
 	u_int32_t status;
 	int addr = upipe->pipe.device->address;
 	int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
@@ -1749,38 +1709,38 @@
 		return (USBD_INVAL);
 	}
 	ntd = (len + maxp - 1) / maxp;
+	if (len == 0)
+		flags |= USBD_FORCE_SHORT_XFER;
 	if ((flags & USBD_FORCE_SHORT_XFER) && len % maxp == 0)
 		ntd++;
 	DPRINTFN(10, ("uhci_alloc_std_chain: maxp=%d ntd=%d\n", maxp, ntd));
-	if (ntd == 0) {
-		*sp = *ep = 0;
-		DPRINTFN(-1,("uhci_alloc_std_chain: ntd=0\n"));
-		return (USBD_NORMAL_COMPLETION);
-	}
+	KASSERT(ntd > 0, ("uhci_alloc_std_chain: ntd=0"));
 	tog = upipe->nexttoggle;
-	if (ntd % 2 == 0)
-		tog ^= 1;
-	upipe->nexttoggle = tog ^ 1;
-	lastp = NULL;
-	lastlink = UHCI_PTR_T;
-	ntd--;
+	prevp = NULL;
+	startp = NULL;
 	status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(3) | UHCI_TD_ACTIVE);
 	if (upipe->pipe.device->speed == USB_SPEED_LOW)
 		status |= UHCI_TD_LS;
 	if (flags & USBD_SHORT_XFER_OK)
 		status |= UHCI_TD_SPD;
-	for (i = ntd; i >= 0; i--) {
+	seg = 0;
+	segoff = 0;
+	for (i = 0; i < ntd; i++) {
 		p = uhci_alloc_std(sc);
 		if (p == NULL) {
-			uhci_free_std_chain(sc, lastp, NULL);
+			uhci_free_std_chain(sc, startp, NULL);
 			return (USBD_NOMEM);
 		}
-		p->link.std = lastp;
-		p->td.td_link = htole32(lastlink | UHCI_PTR_VF | UHCI_PTR_TD);
-		lastp = p;
-		lastlink = p->physaddr;
+		p->link.std = NULL;
+		if (prevp != NULL) {
+			prevp->link.std = p;
+			prevp->td.td_link = htole32(p->physaddr | UHCI_PTR_VF |
+			    UHCI_PTR_TD);
+		} else {
+			startp = p;
+		}
 		p->td.td_status = htole32(status);
-		if (i == ntd) {
+		if (i == ntd - 1) {
 			/* last TD */
 			l = len % maxp;
 			if (l == 0 && !(flags & USBD_FORCE_SHORT_XFER))
@@ -1791,15 +1751,102 @@
 		p->td.td_token =
 		    htole32(rd ? UHCI_TD_IN (l, endpt, addr, tog) :
 				 UHCI_TD_OUT(l, endpt, addr, tog));
-		p->td.td_buffer = htole32(DMAADDR(dma, i * maxp));
+
+		KASSERT(seg < dma->nsegs || l == 0,
+		    ("uhci_alloc_std_chain: too few segments"));
+		if (l == 0) {
+			p->td.td_buffer = 0;
+		} else if (l > dma->segs[seg].ds_len - segoff) {
+			/* UHCI can't handle non-contiguous data. */
+			err = uhci_aux_dma_alloc(sc, p, (char *)xfer->buffer +
+			    i * maxp, l);
+			if (err) {
+				uhci_free_std_chain(sc, startp, NULL);
+				return (err);
+			}
+			p->td.td_buffer = htole32(uhci_aux_dma_prepare(p, rd));
+			l -= dma->segs[seg].ds_len - segoff;
+			seg++;
+			KASSERT(seg < dma->nsegs,
+			    ("uhci_alloc_std_chain: too few segments 2"));
+			segoff = 0;
+		} else {
+			p->td.td_buffer = htole32(dma->segs[seg].ds_addr +
+			    segoff);
+		}
+		segoff += l;
+		if (l > 0 && segoff >= dma->segs[seg].ds_len) {
+			KASSERT(segoff == dma->segs[seg].ds_len,
+			    ("uhci_alloc_std_chain: overlap"));
+			if (i * maxp + l != len) {
+				seg++;
+				segoff = 0;
+			}
+		}
+		prevp = p;
 		tog ^= 1;
 	}
-	*sp = lastp;
+	prevp->td.td_link = htole32(UHCI_PTR_T | UHCI_PTR_VF | UHCI_PTR_TD);
+	upipe->nexttoggle = tog;
+	*sp = startp;
 	DPRINTFN(10, ("uhci_alloc_std_chain: nexttog=%d\n",
 		      upipe->nexttoggle));
 	return (USBD_NORMAL_COMPLETION);
 }
 
+/*
+ * Allocate a physically contiguous buffer to handle cases where UHCI
+ * cannot handle a packet because it is not physically contiguous.
+ * If the usb_dma_t was already allocated this just ensures it is
+ * large enough for the specified size.
+ */
+static usbd_status
+uhci_aux_dma_alloc(uhci_softc_t *sc, uhci_soft_td_t *std, void *data, int len)
+{
+	int err, align;
+
+	if (std->aux_dma.block == NULL || std->aux_dma.block->size < len) {
+		/* Align to avoid crossing a page boundary. */
+		if (powerof2(len))
+			align = len;
+		else
+			align = 1 << fls(len);
+
+		if (std->aux_dma.block != NULL)
+			usb_freemem(&sc->sc_bus, &std->aux_dma);
+		std->aux_dma.block = NULL;
+		err = usb_allocmem(&sc->sc_bus, len, align, &std->aux_dma);
+		if (err)
+			return (err);
+	}
+	std->aux_data = data;
+	std->aux_len = len;
+
+	return (USBD_NORMAL_COMPLETION);
+}
+
+static uhci_physaddr_t
+uhci_aux_dma_prepare(uhci_soft_td_t *std, int isread)
+{
+	if (!isread) {
+		bcopy(std->aux_data, KERNADDR(&std->aux_dma, 0), std->aux_len);
+		bus_dmamap_sync(std->aux_dma.block->tag,
+		    std->aux_dma.block->map, BUS_DMASYNC_PREWRITE);
+	}
+
+	return (DMAADDR(&std->aux_dma, 0));
+}
+
+static void
+uhci_aux_dma_complete(uhci_soft_td_t *std, int isread)
+{
+	if (isread) {
+		bus_dmamap_sync(std->aux_dma.block->tag,
+		    std->aux_dma.block->map, BUS_DMASYNC_POSTREAD);
+		bcopy(KERNADDR(&std->aux_dma, 0), std->aux_data, std->aux_len);
+	}
+}
+
 void
 uhci_device_clear_toggle(usbd_pipe_handle pipe)
 {
@@ -1826,7 +1873,7 @@
 	 * Pipe isn't running (otherwise err would be USBD_INPROG),
 	 * so start it first.
 	 */
-	return (uhci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (uhci_device_bulk_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
 usbd_status
@@ -1861,8 +1908,8 @@
 	upipe->u.bulk.isread = isread;
 	upipe->u.bulk.length = len;
 
-	err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
-				   &xfer->dmabuf, &data, &dataend);
+	err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags, xfer,
+	    &data, &dataend);
 	if (err)
 		return (err);
 	dataend->td.td_status |= htole32(UHCI_TD_IOC);
@@ -1893,7 +1940,7 @@
 	uhci_add_intr_info(sc, ii);
 
 	if (xfer->timeout && !sc->sc_bus.use_polling) {
-		usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
+		callout_reset(&xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
 			    uhci_timeout, ii);
 	}
 	xfer->status = USBD_IN_PROGRESS;
@@ -1946,9 +1993,9 @@
 		/* If we're dying, just do the software part. */
 		s = splusb();
 		xfer->status = status;	/* make software ignore it */
-		usb_uncallout(xfer->timeout_handle, uhci_timeout, xfer);
+		callout_stop(&xfer->timeout_handle);
 		usb_rem_task(xfer->pipe->device, &UXFER(xfer)->abort_task);
-		usb_transfer_complete(xfer);
+		uhci_transfer_complete(xfer);
 		splx(s);
 		return;
 	}
@@ -1980,7 +2027,7 @@
 	s = splusb();
 	uxfer->uhci_xfer_flags |= UHCI_XFER_ABORTING;
 	xfer->status = status;	/* make software ignore it */
-	usb_uncallout(xfer->timeout_handle, uhci_timeout, ii);
+	callout_stop(&xfer->timeout_handle);
 	usb_rem_task(xfer->pipe->device, &UXFER(xfer)->abort_task);
 	DPRINTFN(1,("uhci_abort_xfer: stop ii=%p\n", ii));
 	for (std = ii->stdstart; std != NULL; std = std->link.std)
@@ -2018,10 +2065,50 @@
 		uxfer->uhci_xfer_flags &= ~UHCI_XFER_ABORTWAIT;
 		wakeup(&uxfer->uhci_xfer_flags);
 	}
-	usb_transfer_complete(xfer);
+	uhci_transfer_complete(xfer);
 	splx(s);
 }
 
+/*
+ * Perform any UHCI-specific transfer completion operations, then
+ * call usb_transfer_complete().
+ */
+static void
+uhci_transfer_complete(usbd_xfer_handle xfer)
+{
+	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
+	uhci_soft_td_t *p;
+	int i, isread, n;
+
+	/* XXX, must be an easier way to detect reads... */
+	isread = ((xfer->rqflags & URQ_REQUEST) &&
+	    (xfer->request.bmRequestType & UT_READ)) ||
+            (xfer->pipe->endpoint->edesc->bEndpointAddress & UE_DIR_IN);
+
+	/* Copy back from any auxillary buffers after a read operation. */
+	if (xfer->nframes == 0) {
+		for (p = ii->stdstart; p != NULL; p = p->link.std) {
+			if (p->aux_data != NULL)
+				uhci_aux_dma_complete(p, isread);
+		}
+	} else {
+		if (xfer->nframes != 0) {
+			/* Isoc transfer, do things differently. */
+			n = UXFER(xfer)->curframe;
+			for (i = 0; i < xfer->nframes; i++) {
+				p = upipe->u.iso.stds[n];
+				if (p->aux_data != NULL)
+					uhci_aux_dma_complete(p, isread);
+				if (++n >= UHCI_VFRAMELIST_COUNT)
+				n = 0;
+			}
+		}
+	}
+
+	usb_transfer_complete(xfer);
+}
+
 /* Close a device bulk pipe. */
 void
 uhci_device_bulk_close(usbd_pipe_handle pipe)
@@ -2048,7 +2135,7 @@
 	 * Pipe isn't running (otherwise err would be USBD_INPROG),
 	 * so start it first.
 	 */
-	return (uhci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (uhci_device_ctrl_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
 usbd_status
@@ -2088,7 +2175,7 @@
 	 * Pipe isn't running (otherwise err would be USBD_INPROG),
 	 * so start it first.
 	 */
-	return (uhci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (uhci_device_intr_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
 usbd_status
@@ -2121,9 +2208,8 @@
 
 	upipe->u.intr.isread = isread;
 
-	err = uhci_alloc_std_chain(upipe, sc, xfer->length, isread,
-				   xfer->flags, &xfer->dmabuf, &data,
-				   &dataend);
+	err = uhci_alloc_std_chain(upipe, sc, xfer->length, isread, xfer->flags,
+	     xfer, &data, &dataend);
 	if (err)
 		return (err);
 	dataend->td.td_status |= htole32(UHCI_TD_IOC);
@@ -2261,7 +2347,7 @@
 	if (len != 0) {
 		upipe->nexttoggle = 1;
 		err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
-					   &xfer->dmabuf, &data, &dataend);
+		    xfer, &data, &dataend);
 		if (err)
 			return (err);
 		next = data;
@@ -2345,7 +2431,7 @@
 	}
 #endif
 	if (xfer->timeout && !sc->sc_bus.use_polling) {
-		usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
+		callout_reset(&xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
 			    uhci_timeout, ii);
 	}
 	xfer->status = USBD_IN_PROGRESS;
@@ -2375,7 +2461,7 @@
 
 	/* and start if the pipe wasn't running */
 	if (!err)
-		uhci_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
+		uhci_device_isoc_start(STAILQ_FIRST(&xfer->pipe->queue));
 
 	return (err);
 }
@@ -2388,8 +2474,9 @@
 	uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
 	struct iso *iso = &upipe->u.iso;
 	uhci_soft_td_t *std;
-	u_int32_t buf, len, status;
-	int s, i, next, nframes;
+	void *dataptr;
+	u_int32_t len, status;
+	int err, s, i, isread, next, nframes, seg, segoff;
 
 	DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d xfer=%p "
 		    "nframes=%d\n",
@@ -2419,7 +2506,10 @@
 	xfer->status = USBD_IN_PROGRESS;
 	UXFER(xfer)->curframe = next;
 
-	buf = DMAADDR(&xfer->dmabuf, 0);
+	seg = 0;
+	segoff = 0;
+	dataptr = xfer->allocbuf; /* Normal buffers not possible for isoc? */
+	isread = xfer->pipe->endpoint->edesc->bEndpointAddress & UE_DIR_IN;
 	status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) |
 				     UHCI_TD_ACTIVE |
 				     UHCI_TD_IOS);
@@ -2430,7 +2520,35 @@
 		if (++next >= UHCI_VFRAMELIST_COUNT)
 			next = 0;
 		len = xfer->frlengths[i];
-		std->td.td_buffer = htole32(buf);
+		KASSERT(seg < xfer->dmamap.nsegs,
+		    ("uhci_device_isoc_enter: too few segments"));
+		if (len + segoff > xfer->dmamap.segs[seg].ds_len) {
+			/* UHCI can't handle non-contiguous data. */
+			err = uhci_aux_dma_alloc(sc, std, dataptr, len);
+			/* XXX */
+			if (err)
+				printf("uhci_device_isoc_enter: aux alloc\n");
+			std->td.td_buffer = htole32(uhci_aux_dma_prepare(std,
+			    isread));
+			segoff += len;
+			while (segoff >= xfer->dmamap.segs[seg].ds_len) {
+				KASSERT(seg < xfer->dmamap.nsegs - 1 ||
+				    segoff == xfer->dmamap.segs[seg].ds_len,
+				    ("uhci_device_isoc_enter: overlap2"));
+				segoff -= xfer->dmamap.segs[seg].ds_len;
+				seg++;
+			}
+		} else {
+			std->td.td_buffer =
+			    htole32(xfer->dmamap.segs[seg].ds_addr + segoff);
+			segoff += len;
+			if (segoff >= xfer->dmamap.segs[seg].ds_len) {
+				KASSERT(segoff == xfer->dmamap.segs[seg].ds_len,
+				    ("uhci_device_isoc_enter: overlap"));
+				segoff = 0;
+				seg++;
+			}
+		}
 		if (i == nframes - 1)
 			status |= UHCI_TD_IOC;
 		std->td.td_status = htole32(status);
@@ -2442,7 +2560,7 @@
 			uhci_dump_td(std);
 		}
 #endif
-		buf += len;
+		dataptr = (char *)dataptr + len;
 	}
 	iso->next = next;
 	iso->inuse += xfer->nframes;
@@ -2541,7 +2659,7 @@
 	UXFER(xfer)->iinfo.isdone = 1;
 #endif
 	/* Run callback and remove from interrupt list. */
-	usb_transfer_complete(xfer);
+	uhci_transfer_complete(xfer);
 
 	splx(s);
 }
@@ -2689,6 +2807,8 @@
 		return;
 	}
 #endif
+	ii->stdstart = NULL;
+	ii->stdend = NULL;
 }
 
 void
@@ -2718,8 +2838,8 @@
 
 		/* This alloc cannot fail since we freed the chain above. */
 		uhci_alloc_std_chain(upipe, sc, xfer->length,
-				     upipe->u.intr.isread, xfer->flags,
-				     &xfer->dmabuf, &data, &dataend);
+				     upipe->u.intr.isread, xfer->flags, xfer,
+				     &data, &dataend);
 		dataend->td.td_status |= htole32(UHCI_TD_IOC);
 
 #ifdef USB_DEBUG
@@ -2747,8 +2867,11 @@
 		/* The ii is already on the examined list, just leave it. */
 	} else {
 		DPRINTFN(5,("uhci_device_intr_done: removing\n"));
-		if (uhci_active_intr_info(ii))
+		if (uhci_active_intr_info(ii)) {
 			uhci_del_intr_info(ii);
+			ii->stdstart = NULL;
+			ii->stdend = NULL;
+		}
 	}
 }
 
@@ -2777,6 +2900,8 @@
 
 	if (upipe->u.ctl.length != 0)
 		uhci_free_std_chain(sc, ii->stdstart->link.std, ii->stdend);
+	ii->stdstart = NULL;
+	ii->stdend = NULL;
 
 	DPRINTFN(5, ("uhci_device_ctrl_done: length=%d\n", xfer->actlen));
 }
@@ -2800,6 +2925,8 @@
 	uhci_remove_bulk(sc, upipe->u.bulk.sqh);
 
 	uhci_free_std_chain(sc, ii->stdstart, NULL);
+	ii->stdstart = NULL;
+	ii->stdend = NULL;
 
 	DPRINTFN(5, ("uhci_device_bulk_done: length=%d\n", xfer->actlen));
 }
@@ -3068,7 +3195,7 @@
  * outstanding "port enable change" and "connection status change"
  * events have been reset.
  */
-Static usbd_status
+static usbd_status
 uhci_portreset(uhci_softc_t *sc, int index)
 {
 	int lim, port, x;
@@ -3169,7 +3296,7 @@
 	 * Pipe isn't running (otherwise err would be USBD_INPROG),
 	 * so start it first.
 	 */
-	return (uhci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (uhci_root_ctrl_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
 usbd_status
@@ -3200,7 +3327,7 @@
 	index = UGETW(req->wIndex);
 
 	if (len != 0)
-		buf = KERNADDR(&xfer->dmabuf, 0);
+		buf = xfer->buffer;
 
 #define C(x,y) ((x) | ((y) << 8))
 	switch(C(req->bRequest, req->bmRequestType)) {
@@ -3490,7 +3617,7 @@
  ret:
 	xfer->status = err;
 	s = splusb();
-	usb_transfer_complete(xfer);
+	uhci_transfer_complete(xfer);
 	splx(s);
 	return (USBD_IN_PROGRESS);
 }
@@ -3515,7 +3642,7 @@
 {
 	uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
 
-	usb_uncallout(sc->sc_poll_handle, uhci_poll_hub, xfer);
+	callout_stop(&sc->sc_poll_handle);
 	sc->sc_intr_xfer = NULL;
 
 	if (xfer->pipe->intrxfer == xfer) {
@@ -3526,7 +3653,7 @@
 #ifdef DIAGNOSTIC
 	UXFER(xfer)->iinfo.isdone = 1;
 #endif
-	usb_transfer_complete(xfer);
+	uhci_transfer_complete(xfer);
 }
 
 usbd_status
@@ -3543,7 +3670,7 @@
 	 * Pipe isn't running (otherwise err would be USBD_INPROG),
 	 * so start it first.
 	 */
-	return (uhci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
+	return (uhci_root_intr_start(STAILQ_FIRST(&xfer->pipe->queue)));
 }
 
 /* Start a transfer on the root interrupt pipe */
@@ -3560,7 +3687,7 @@
 		return (USBD_IOERROR);
 
 	sc->sc_ival = MS_TO_TICKS(xfer->pipe->endpoint->edesc->bInterval);
-	usb_callout(sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, xfer);
+	callout_reset(&sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, xfer);
 	sc->sc_intr_xfer = xfer;
 	return (USBD_IN_PROGRESS);
 }
@@ -3571,7 +3698,7 @@
 {
 	uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
 
-	usb_uncallout(sc->sc_poll_handle, uhci_poll_hub, sc->sc_intr_xfer);
+	callout_stop(&sc->sc_poll_handle);
 	sc->sc_intr_xfer = NULL;
 	DPRINTF(("uhci_root_intr_close\n"));
 }
Index: usb_ethersubr.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usb_ethersubr.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usb_ethersubr.h -L sys/dev/usb/usb_ethersubr.h -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usb_ethersubr.h
+++ sys/dev/usb/usb_ethersubr.h
@@ -29,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/usb_ethersubr.h,v 1.10 2005/03/25 13:22:58 sobomax Exp $
+ * $FreeBSD: src/sys/dev/usb/usb_ethersubr.h,v 1.12 2007/01/08 23:21:06 alfred Exp $
  */
 
 #ifndef _USB_ETHERSUBR_H_
@@ -55,6 +55,7 @@
 	char			*ue_buf;
 	struct mbuf		*ue_mbuf;
 	int			ue_idx;
+	usbd_status		ue_status;
 };
 
 struct ue_cdata {
@@ -78,4 +79,13 @@
 void usb_ether_rx_list_free	(struct ue_cdata *);
 void usb_ether_tx_list_free	(struct ue_cdata *);
 
+struct usb_taskqueue {
+	int dummy;
+};
+
+void usb_ether_task_init(device_t, int, struct usb_taskqueue *);
+void usb_ether_task_enqueue(struct usb_taskqueue *, struct task *);
+void usb_ether_task_drain(struct usb_taskqueue *, struct task *);
+void usb_ether_task_destroy(struct usb_taskqueue *);
+
 #endif /* _USB_ETHERSUBR_H_ */
Index: ehcivar.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ehcivar.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/ehcivar.h -L sys/dev/usb/ehcivar.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/ehcivar.h
+++ sys/dev/usb/ehcivar.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: ehcivar.h,v 1.19 2005/04/29 15:04:29 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/ehcivar.h,v 1.9.2.1 2006/01/26 01:43:13 iedowse Exp $	*/
+/*	$FreeBSD: src/sys/dev/usb/ehcivar.h,v 1.17 2007/06/14 16:23:31 imp Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -53,6 +53,7 @@
 	struct ehci_soft_qh *next;
 	struct ehci_soft_qh *prev;
 	struct ehci_soft_qtd *sqtd;
+	struct ehci_soft_qtd *inactivesqtd;
 	ehci_physaddr_t physaddr;
 	int islot;		/* Interrupt list slot. */
 } ehci_soft_qh_t;
@@ -149,16 +150,13 @@
 	u_int32_t sc_eintrs;
 	ehci_soft_qh_t *sc_async_head;
 
-	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
+	STAILQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
 
 	struct lock sc_doorbell_lock;
 
-	usb_callout_t sc_tmo_pcd;
-	usb_callout_t sc_tmo_intrlist;
+	struct callout sc_tmo_pcd;
+	struct callout sc_tmo_intrlist;
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	device_ptr_t sc_child;		/* /dev/usb# device */
-#endif
 	char sc_dying;
 #if defined(__NetBSD__)
 	struct usb_dma_reserve sc_dma_reserve;
@@ -182,7 +180,7 @@
 int		ehci_intr(void *);
 int		ehci_detach(ehci_softc_t *, int);
 #if defined(__NetBSD__) || defined(__OpenBSD__)
-int		ehci_activate(device_ptr_t, enum devact);
+int		ehci_activate(device_t, enum devact);
 #endif
 void		ehci_power(int state, void *priv);
 void		ehci_shutdown(void *v);
Index: ucycom.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ucycom.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ucycom.c -L sys/dev/usb/ucycom.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ucycom.c
+++ sys/dev/usb/ucycom.c
@@ -25,7 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/ucycom.c,v 1.3 2004/10/12 09:21:03 phk Exp $
+ * $FreeBSD: src/sys/dev/usb/ucycom.c,v 1.6 2007/06/21 14:42:33 imp Exp $
  */
 
 /*
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ucycom.c,v 1.3 2004/10/12 09:21:03 phk Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ucycom.c,v 1.6 2007/06/21 14:42:33 imp Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -52,7 +52,6 @@
 
 #include "usbdevs.h"
 #include <dev/usb/usb.h>
-#include <dev/usb/usb_port.h>
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
 #include <dev/usb/usbhid.h>
@@ -103,9 +102,9 @@
 	char			 sc_dying;
 };
 
-static int ucycom_probe(device_t);
-static int ucycom_attach(device_t);
-static int ucycom_detach(device_t);
+static device_probe_t ucycom_probe;
+static device_attach_t ucycom_attach;
+static device_detach_t ucycom_detach;
 static t_open_t ucycom_open;
 static t_close_t ucycom_close;
 static void ucycom_start(struct tty *);
@@ -177,7 +176,6 @@
 	struct ucycom_softc *sc;
 	struct ucycom_device *ud;
 	usb_endpoint_descriptor_t *ued;
-	char *devinfo;
 	void *urd;
 	int error, urdlen;
 
@@ -188,14 +186,6 @@
 	sc->sc_dev = dev;
 	sc->sc_usbdev = uaa->device;
 
-	/* get device description */
-	/* XXX usb_devinfo() has little or no overflow protection */
-	devinfo = malloc(1024, M_USBDEV, M_WAITOK);
-	usbd_devinfo(sc->sc_usbdev, 0, devinfo);
-	device_set_desc_copy(dev, devinfo);
-	device_printf(dev, "%s\n", devinfo);
-	free(devinfo, M_USBDEV);
-
 	/* get chip model */
 	for (ud = ucycom_devices; ud->model != 0; ++ud)
 		if (ud->vendor == uaa->vendor && ud->product == uaa->product)
@@ -284,7 +274,7 @@
 	    "output bytes");
 
 	/* create character device node */
-	ttycreate(sc->sc_tty, NULL, 0, 0, "y%r", device_get_unit(sc->sc_dev));
+	ttycreate(sc->sc_tty, 0, "y%r", device_get_unit(sc->sc_dev));
 
 	return (0);
 }
Index: ufm.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ufm.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/ufm.c -L sys/dev/usb/ufm.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/ufm.c
+++ sys/dev/usb/ufm.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2001 M. Warner Losh
+ * Copyright (c) 2001-2007 M. Warner Losh
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,32 +29,22 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ufm.c,v 1.23 2005/01/06 01:43:28 imp Exp $");
-
+__FBSDID("$FreeBSD: src/sys/dev/usb/ufm.c,v 1.36 2007/06/21 14:42:33 imp Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#if defined(__NetBSD__)
-#include <sys/device.h>
-#include <sys/ioctl.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
 #include <sys/ioccom.h>
-#endif
 #include <sys/fcntl.h>
 #include <sys/filio.h>
 #include <sys/conf.h>
 #include <sys/uio.h>
 #include <sys/tty.h>
 #include <sys/file.h>
-#if __FreeBSD_version >= 500014
 #include <sys/selinfo.h>
-#else
-#include <sys/select.h>
-#endif
 #include <sys/poll.h>
 #include <sys/sysctl.h>
 
@@ -66,8 +56,8 @@
 #include <dev/usb/dsbr100io.h>
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (ufmdebug) logprintf x
-#define DPRINTFN(n,x)	if (ufmdebug>(n)) logprintf x
+#define DPRINTF(x)	if (ufmdebug) printf x
+#define DPRINTFN(n,x)	if (ufmdebug>(n)) printf x
 int	ufmdebug = 0;
 SYSCTL_NODE(_hw_usb, OID_AUTO, ufm, CTLFLAG_RW, 0, "USB ufm");
 SYSCTL_INT(_hw_usb_ufm, OID_AUTO, debug, CTLFLAG_RW,
@@ -77,36 +67,25 @@
 #define DPRINTFN(n,x)
 #endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int ufmopen(dev_t, int, int, usb_proc_ptr);
-int ufmclose(dev_t, int, int, usb_proc_ptr);
-int ufmioctl(dev_t, u_long, caddr_t, int, usb_proc_ptr);
-
-cdev_decl(ufm);
-#elif defined(__FreeBSD__)
 d_open_t  ufmopen;
 d_close_t ufmclose;
 d_ioctl_t ufmioctl;
 
-Static struct cdevsw ufm_cdevsw = {
+static struct cdevsw ufm_cdevsw = {
 	.d_version =	D_VERSION,
 	.d_flags =	D_NEEDGIANT,
 	.d_open =	ufmopen,
 	.d_close =	ufmclose,
 	.d_ioctl =	ufmioctl,
 	.d_name =	"ufm",
-#if (__FreeBSD_version < 500014)
- 	.d_bmaj =	-1
-#endif
 };
-#endif  /*defined(__FreeBSD__)*/
 
 #define FM_CMD0		0x00
 #define FM_CMD_SET_FREQ	0x01
 #define FM_CMD2		0x02
 
 struct ufm_softc {
- 	USBBASEDEVICE sc_dev;
+ 	device_t sc_dev;
 	usbd_device_handle sc_udev;
 	usbd_interface_handle sc_iface;
 
@@ -115,18 +94,35 @@
 	int sc_freq;
 
 	int sc_refcnt;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	u_char sc_dying;
-#endif
 };
 
 #define UFMUNIT(n) (minor(n))
 
-USB_DECLARE_DRIVER(ufm);
+static device_probe_t ufm_match;
+static device_attach_t ufm_attach;
+static device_detach_t ufm_detach;
+
+static device_method_t ufm_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		ufm_match),
+	DEVMETHOD(device_attach,	ufm_attach),
+	DEVMETHOD(device_detach,	ufm_detach),
 
-USB_MATCH(ufm)
+	{ 0, 0 }
+};
+
+static driver_t ufm_driver = {
+	"ufm",
+	ufm_methods,
+	sizeof(struct ufm_softc)
+};
+
+static devclass_t ufm_devclass;
+
+static int
+ufm_match(device_t self)
 {
-	USB_MATCH_START(ufm, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_device_descriptor_t *dd;
 
 	DPRINTFN(10,("ufm_match\n"));
@@ -143,49 +139,27 @@
 		return UMATCH_NONE;
 }
 
-USB_ATTACH(ufm)
+static int
+ufm_attach(device_t self)
 {
-	USB_ATTACH_START(ufm, sc, uaa);
-	char devinfo[1024];
+	struct ufm_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	usb_endpoint_descriptor_t *edesc;
 	usbd_device_handle udev;
 	usbd_interface_handle iface;
 	u_int8_t epcount;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	u_int8_t niface;
-#endif
 	usbd_status r;
 	char * ermsg = "<none>";
 
 	DPRINTFN(10,("ufm_attach: sc=%p\n", sc));
-	usbd_devinfo(uaa->device, 0, devinfo);
-	USB_ATTACH_SETUP;
-
+	sc->sc_dev = self;
 	sc->sc_udev = udev = uaa->device;
 
-#if defined(__FreeBSD__)
  	if ((!uaa->device) || (!uaa->iface)) {
 		ermsg = "device or iface";
  		goto nobulk;
 	}
 	sc->sc_iface = iface = uaa->iface;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
- 	if (!udev) {
-		ermsg = "device";
- 		goto nobulk;
-	}
-	r = usbd_interface_count(udev, &niface);
-	if (r) {
-		ermsg = "iface";
-		goto nobulk;
-	}
-	r = usbd_device2interface_handle(udev, 0, &iface);
-	if (r) {
-		ermsg = "iface";
-		goto nobulk;
-	}
-	sc->sc_iface = iface;
-#endif
 	sc->sc_opened = 0;
 	sc->sc_refcnt = 0;
 
@@ -202,33 +176,28 @@
 	}
 	sc->sc_epaddr = edesc->bEndpointAddress;
 
-#if defined(__FreeBSD__)
 	/* XXX no error trapping, no storing of struct cdev **/
 	(void) make_dev(&ufm_cdevsw, device_get_unit(self),
 			UID_ROOT, GID_OPERATOR,
 			0644, "ufm%d", device_get_unit(self));
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
-#endif
-
 	DPRINTFN(10, ("ufm_attach: %p\n", sc->sc_udev));
-
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 
  nobulk:
-	printf("%s: could not find %s\n", USBDEVNAME(sc->sc_dev),ermsg);
-	USB_ATTACH_ERROR_RETURN;
+	device_printf(sc->sc_dev, "could not find %s\n", ermsg);
+	return ENXIO;
 }
 
 
 int
-ufmopen(struct cdev *dev, int flag, int mode, usb_proc_ptr td)
+ufmopen(struct cdev *dev, int flag, int mode, struct thread *td)
 {
 	struct ufm_softc *sc;
 
 	int unit = UFMUNIT(dev);
-	USB_GET_SC_OPEN(ufm, unit, sc);
+	sc = devclass_get_softc(ufm_devclass, unit);
+	if (sc == NULL)
+		return (ENXIO);
 
 	DPRINTFN(5, ("ufmopen: flag=%d, mode=%d, unit=%d\n",
 		     flag, mode, unit));
@@ -244,12 +213,12 @@
 }
 
 int
-ufmclose(struct cdev *dev, int flag, int mode, usb_proc_ptr td)
+ufmclose(struct cdev *dev, int flag, int mode, struct thread *td)
 {
 	struct ufm_softc *sc;
 
 	int unit = UFMUNIT(dev);
-	USB_GET_SC(ufm, unit, sc);
+	sc = devclass_get_softc(ufm_devclass, unit);
 
 	DPRINTFN(5, ("ufmclose: flag=%d, mode=%d, unit=%d\n", flag, mode, unit));
 	sc->sc_opened = 0;
@@ -274,10 +243,8 @@
 	err = usbd_do_request_flags(sc->sc_udev, &req, retbuf, 0, NULL,
 	    USBD_DEFAULT_TIMEOUT);
 	splx(s);
-	if (err) {
-		printf("usbd_do_request_flags returned %#x\n", err);
+	if (err)
 		return (EIO);
-	}
 	return (0);
 }
 
@@ -367,14 +334,14 @@
 }
 
 int
-ufmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr td)
+ufmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 {
 	struct ufm_softc *sc;
 
 	int unit = UFMUNIT(dev);
 	int error = 0;
 
-	USB_GET_SC(ufm, unit, sc);
+	sc = devclass_get_softc(ufm_devclass, unit);
 
 	switch (cmd) {
 	case FM_SET_FREQ:
@@ -399,75 +366,11 @@
 	return error;
 }
 
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-int
-ufm_activate(device_ptr_t self, enum devact act)
-{
-	struct ufm_softc *sc = (struct ufm_softc *)self;
-
-	switch (act) {
-	case DVACT_ACTIVATE:
-		return (EOPNOTSUPP);
-		break;
-
-	case DVACT_DEACTIVATE:
-		sc->sc_dying = 1;
-		break;
-	}
-	return (0);
-}
-
-USB_DETACH(ufm)
-{
-	USB_DETACH_START(ufm, sc);
-	struct ufm_endpoint *sce;
-	int i, dir;
-	int s;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	int maj, mn;
-
-	DPRINTF(("ufm_detach: sc=%p flags=%d\n", sc, flags));
-#elif defined(__FreeBSD__)
-	DPRINTF(("ufm_detach: sc=%p\n", sc));
-#endif
-
-	sc->sc_dying = 1;
-
-	s = splusb();
-	if (--sc->sc_refcnt >= 0) {
-		/* Wait for processes to go away. */
-		usb_detach_wait(USBDEV(sc->sc_dev));
-	}
-	splx(s);
-
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	/* locate the major number */
-	for (maj = 0; maj < nchrdev; maj++)
-		if (cdevsw[maj].d_open == ufmopen)
-			break;
-
-	/* Nuke the vnodes for any open instances (calls close). */
-	mn = self->dv_unit * USB_MAX_ENDPOINTS;
-	vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);
-#elif defined(__FreeBSD__)
-	/* XXX not implemented yet */
-#endif
-
-	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
-			   USBDEV(sc->sc_dev));
-
-	return (0);
-}
-#endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
-
-#if defined(__FreeBSD__)
-Static int
+static int
 ufm_detach(device_t self)
 {
-	DPRINTF(("%s: disconnected\n", USBDEVNAME(self)));
 	return 0;
 }
 
+MODULE_DEPEND(ufm, usb, 1, 1, 1);
 DRIVER_MODULE(ufm, uhub, ufm_driver, ufm_devclass, usbd_driver_load, 0);
-#endif
Index: usbdi.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/usbdi.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/usbdi.c -L sys/dev/usb/usbdi.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/usbdi.c
+++ sys/dev/usb/usbdi.c
@@ -1,7 +1,7 @@
 /*	$NetBSD: usbdi.c,v 1.106 2004/10/24 12:52:40 augustss Exp $	*/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/usbdi.c,v 1.91.2.1 2005/12/15 00:36:00 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/usbdi.c,v 1.103 2007/06/30 20:18:44 imp Exp $");
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -42,17 +42,12 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-#include <sys/kernel.h>
-#include <sys/device.h>
-#elif defined(__FreeBSD__)
 #include <sys/module.h>
 #include <sys/bus.h>
 #include "usb_if.h"
 #if defined(DIAGNOSTIC) && defined(__i386__)
 #include <machine/cpu.h>
 #endif
-#endif
 #include <sys/malloc.h>
 #include <sys/proc.h>
 
@@ -65,30 +60,31 @@
 #include <dev/usb/usb_mem.h>
 #include <dev/usb/usb_quirks.h>
 
-#if defined(__FreeBSD__)
 #include "usb_if.h"
-#include <machine/clock.h>
 #define delay(d)	DELAY(d)
-#endif
 
 #ifdef USB_DEBUG
-#define DPRINTF(x)	if (usbdebug) logprintf x
-#define DPRINTFN(n,x)	if (usbdebug>(n)) logprintf x
+#define DPRINTF(x)	if (usbdebug) printf x
+#define DPRINTFN(n,x)	if (usbdebug>(n)) printf x
 extern int usbdebug;
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n,x)
 #endif
 
-Static usbd_status usbd_ar_pipe(usbd_pipe_handle pipe);
-Static void usbd_do_request_async_cb
+static usbd_status usbd_ar_pipe(usbd_pipe_handle pipe);
+static void usbd_do_request_async_cb
 	(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void usbd_start_next(usbd_pipe_handle pipe);
-Static usbd_status usbd_open_pipe_ival
+static void usbd_start_next(usbd_pipe_handle pipe);
+static usbd_status usbd_open_pipe_ival
 	(usbd_interface_handle, u_int8_t, u_int8_t, usbd_pipe_handle *, int);
-Static int usbd_xfer_isread(usbd_xfer_handle xfer);
+static int usbd_xfer_isread(usbd_xfer_handle xfer);
+static void usbd_start_transfer(void *arg, bus_dma_segment_t *segs, int nseg,
+    int error);
+static void usbd_alloc_callback(void *arg, bus_dma_segment_t *segs, int nseg,
+    int error);
 
-Static int usbd_nbuses = 0;
+static int usbd_nbuses = 0;
 
 void
 usbd_init(void)
@@ -155,7 +151,7 @@
 	usbd_xfer_handle xfer;
 
 	printf("usbd_dump_queue: pipe=%p\n", pipe);
-	SIMPLEQ_FOREACH(xfer, &pipe->queue, next) {
+	STAILQ_FOREACH(xfer, &pipe->queue, next) {
 		printf("  xfer=%p\n", xfer);
 	}
 }
@@ -268,7 +264,7 @@
 
 	if (--pipe->refcnt != 0)
 		return (USBD_NORMAL_COMPLETION);
-	if (! SIMPLEQ_EMPTY(&pipe->queue))
+	if (! STAILQ_EMPTY(&pipe->queue))
 		return (USBD_PENDING_REQUESTS);
 	LIST_REMOVE(pipe, next);
 	pipe->endpoint->refcnt--;
@@ -283,7 +279,7 @@
 usbd_transfer(usbd_xfer_handle xfer)
 {
 	usbd_pipe_handle pipe = xfer->pipe;
-	usb_dma_t *dmap = &xfer->dmabuf;
+	struct usb_dma_mapping *dmap = &xfer->dmamap;
 	usbd_status err;
 	u_int size;
 	int s;
@@ -302,43 +298,36 @@
 	size = xfer->length;
 	/* If there is no buffer, allocate one. */
 	if (!(xfer->rqflags & URQ_DEV_DMABUF) && size != 0) {
-		struct usbd_bus *bus = pipe->device->bus;
+		bus_dma_tag_t tag = pipe->device->bus->buffer_dmatag;
 
 #ifdef DIAGNOSTIC
 		if (xfer->rqflags & URQ_AUTO_DMABUF)
 			printf("usbd_transfer: has old buffer!\n");
 #endif
-		err = bus->methods->allocm(bus, dmap, size);
+		err = bus_dmamap_create(tag, 0, &dmap->map);
 		if (err)
-			return (err);
-		xfer->rqflags |= URQ_AUTO_DMABUF;
-	}
-
-	/* Copy data if going out. */
-	if (!(xfer->flags & USBD_NO_COPY) && size != 0 &&
-	    !usbd_xfer_isread(xfer))
-		memcpy(KERNADDR(dmap, 0), xfer->buffer, size);
-
-	err = pipe->methods->transfer(xfer);
-
-	if (err != USBD_IN_PROGRESS && err) {
-		/* The transfer has not been queued, so free buffer. */
-		if (xfer->rqflags & URQ_AUTO_DMABUF) {
-			struct usbd_bus *bus = pipe->device->bus;
+			return (USBD_NOMEM);
 
-			bus->methods->freem(bus, &xfer->dmabuf);
+		xfer->rqflags |= URQ_AUTO_DMABUF;
+		err = bus_dmamap_load(tag, dmap->map, xfer->buffer, size,
+		    usbd_start_transfer, xfer, 0);
+		if (err != 0 && err != EINPROGRESS) {
 			xfer->rqflags &= ~URQ_AUTO_DMABUF;
+			bus_dmamap_destroy(tag, dmap->map);
+			return (USBD_INVAL);
 		}
+	} else if (size != 0) {
+		usbd_start_transfer(xfer, dmap->segs, dmap->nsegs, 0);
+	} else {
+		usbd_start_transfer(xfer, NULL, 0, 0);
 	}
 
 	if (!(xfer->flags & USBD_SYNCHRONOUS))
-		return (err);
+		return (xfer->done ? 0 : USBD_IN_PROGRESS);
 
 	/* Sync transfer, wait for completion. */
-	if (err != USBD_IN_PROGRESS)
-		return (err);
 	s = splusb();
-	if (!xfer->done) {
+	while (!xfer->done) {
 		if (pipe->device->bus->use_polling)
 			panic("usbd_transfer: not done");
 		tsleep(xfer, PRIBIO, "usbsyn", 0);
@@ -347,6 +336,68 @@
 	return (xfer->status);
 }
 
+static void
+usbd_start_transfer(void *arg, bus_dma_segment_t *segs, int nseg, int error)
+{
+	usbd_xfer_handle xfer = arg;
+	usbd_pipe_handle pipe = xfer->pipe;
+	struct usb_dma_mapping *dmap = &xfer->dmamap;
+	bus_dma_tag_t tag = pipe->device->bus->buffer_dmatag;
+	int err, i;
+
+	if (error != 0) {
+		KASSERT(xfer->rqflags & URQ_AUTO_DMABUF,
+		    ("usbd_start_transfer: error with non-auto buf"));
+		if (nseg > 0)
+			bus_dmamap_unload(tag, dmap->map);
+		bus_dmamap_destroy(tag, dmap->map);
+		/* XXX */
+		usb_insert_transfer(xfer);
+		xfer->status = USBD_IOERROR;
+		usb_transfer_complete(xfer);
+		return;
+	}
+
+	if (segs != dmap->segs) {
+		for (i = 0; i < nseg; i++)
+			dmap->segs[i] = segs[i];
+	}
+	dmap->nsegs = nseg;
+
+	if (nseg > 0) {
+		if (!usbd_xfer_isread(xfer)) {
+			/*
+			 * Copy data if it is not already in the correct
+			 * buffer.
+			 */
+			if (!(xfer->flags & USBD_NO_COPY) &&
+			    xfer->allocbuf != NULL &&
+			    xfer->buffer != xfer->allocbuf)
+				memcpy(xfer->allocbuf, xfer->buffer,
+				    xfer->length);
+			bus_dmamap_sync(tag, dmap->map, BUS_DMASYNC_PREWRITE);
+		} else if (xfer->rqflags & URQ_REQUEST) {
+			/*
+			 * Even if we have no data portion we still need to
+			 * sync the dmamap for the request data in the SETUP
+			 * packet.
+			 */
+			bus_dmamap_sync(tag, dmap->map, BUS_DMASYNC_PREWRITE);
+		}
+	}
+	err = pipe->methods->transfer(xfer);
+	if (err != USBD_IN_PROGRESS && err) {
+		if (xfer->rqflags & URQ_AUTO_DMABUF) {
+			bus_dmamap_unload(tag, dmap->map);
+			bus_dmamap_destroy(tag, dmap->map);
+			xfer->rqflags &= ~URQ_AUTO_DMABUF;
+		}
+		xfer->status = err;
+		usb_transfer_complete(xfer);
+		return;
+	}
+}
+
 /* Like usbd_transfer(), but waits for completion. */
 usbd_status
 usbd_sync_transfer(usbd_xfer_handle xfer)
@@ -355,42 +406,103 @@
 	return (usbd_transfer(xfer));
 }
 
+struct usbd_allocstate {
+	usbd_xfer_handle xfer;
+	int done;
+	int error;
+	int waiting;
+};
+
 void *
 usbd_alloc_buffer(usbd_xfer_handle xfer, u_int32_t size)
 {
-	struct usbd_bus *bus = xfer->device->bus;
+	struct usbd_allocstate allocstate;
+	struct usb_dma_mapping *dmap = &xfer->dmamap;
+	bus_dma_tag_t tag = xfer->device->bus->buffer_dmatag;
+	void *buf;
 	usbd_status err;
+	int error, s;
 
-#ifdef DIAGNOSTIC
-	if (xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF))
-		printf("usbd_alloc_buffer: xfer already has a buffer\n");
-#endif
-	err = bus->methods->allocm(bus, &xfer->dmabuf, size);
+	KASSERT((xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF)) == 0,
+	    ("usbd_alloc_buffer: xfer already has a buffer"));
+	err = bus_dmamap_create(tag, 0, &dmap->map);
 	if (err)
 		return (NULL);
+	buf = malloc(size, M_USB, M_WAITOK);
+
+	allocstate.xfer = xfer;
+	allocstate.done = 0;
+	allocstate.error = 0;
+	allocstate.waiting = 0;
+	error = bus_dmamap_load(tag, dmap->map, buf, size, usbd_alloc_callback,
+	    &allocstate, 0);
+	if (error && error != EINPROGRESS) {
+		bus_dmamap_destroy(tag, dmap->map);
+		free(buf, M_USB);
+		return (NULL);
+	}
+	if (error == EINPROGRESS) {
+		/* Wait for completion. */
+		s = splusb();
+		allocstate.waiting = 1;
+		while (!allocstate.done)
+			tsleep(&allocstate, PRIBIO, "usbdab", 0);
+		splx(s);
+		error = allocstate.error;
+	}
+	if (error) {
+		bus_dmamap_unload(tag, dmap->map);
+		bus_dmamap_destroy(tag, dmap->map);
+		free(buf, M_USB);
+		return (NULL);
+	}
+
+	xfer->allocbuf = buf;
 	xfer->rqflags |= URQ_DEV_DMABUF;
-	return (KERNADDR(&xfer->dmabuf, 0));
+	return (buf);
 }
 
 void
 usbd_free_buffer(usbd_xfer_handle xfer)
 {
-#ifdef DIAGNOSTIC
-	if (!(xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF))) {
-		printf("usbd_free_buffer: no buffer\n");
-		return;
-	}
-#endif
-	xfer->rqflags &= ~(URQ_DEV_DMABUF | URQ_AUTO_DMABUF);
-	xfer->device->bus->methods->freem(xfer->device->bus, &xfer->dmabuf);
+	struct usb_dma_mapping *dmap = &xfer->dmamap;
+	bus_dma_tag_t tag = xfer->device->bus->buffer_dmatag;
+
+	KASSERT((xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF)) ==
+	    URQ_DEV_DMABUF, ("usbd_free_buffer: no/auto buffer"));
+
+	xfer->rqflags &= ~URQ_DEV_DMABUF;
+	bus_dmamap_unload(tag, dmap->map);
+	bus_dmamap_destroy(tag, dmap->map);
+	free(xfer->allocbuf, M_USB);
+	xfer->allocbuf = NULL;
 }
 
 void *
 usbd_get_buffer(usbd_xfer_handle xfer)
 {
 	if (!(xfer->rqflags & URQ_DEV_DMABUF))
-		return (0);
-	return (KERNADDR(&xfer->dmabuf, 0));
+		return (NULL);
+	return (xfer->allocbuf);
+}
+
+static void
+usbd_alloc_callback(void *arg, bus_dma_segment_t *segs, int nseg, int error)
+{
+	struct usbd_allocstate *allocstate = arg;
+	usbd_xfer_handle xfer = allocstate->xfer;
+	struct usb_dma_mapping *dmap = &xfer->dmamap;
+	int i;
+
+	allocstate->error = error;
+	if (error == 0) {
+		for (i = 0; i < nseg; i++)
+			dmap->segs[i] = segs[i];
+		dmap->nsegs = nseg;
+	}
+	allocstate->done = 1;
+	if (allocstate->waiting)
+		wakeup(&allocstate);
 }
 
 usbd_xfer_handle
@@ -402,7 +514,7 @@
 	if (xfer == NULL)
 		return (NULL);
 	xfer->device = dev;
-	usb_callout_init(xfer->timeout_handle);
+	callout_init(&xfer->timeout_handle, 0);
 	DPRINTFN(5,("usbd_alloc_xfer() = %p\n", xfer));
 	return (xfer);
 }
@@ -411,8 +523,9 @@
 usbd_free_xfer(usbd_xfer_handle xfer)
 {
 	DPRINTFN(5,("usbd_free_xfer: %p\n", xfer));
-	if (xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF))
+	if (xfer->rqflags & URQ_DEV_DMABUF)
 		usbd_free_buffer(xfer);
+/* XXX Does FreeBSD need to do something similar? */
 #if defined(__NetBSD__) && defined(DIAGNOSTIC)
 	if (callout_pending(&xfer->timeout_handle)) {
 		callout_stop(&xfer->timeout_handle);
@@ -468,10 +581,14 @@
 		     usbd_private_handle priv, u_int16_t *frlengths,
 		     u_int32_t nframes, u_int16_t flags, usbd_callback callback)
 {
+	int i;
+
 	xfer->pipe = pipe;
 	xfer->priv = priv;
 	xfer->buffer = 0;
 	xfer->length = 0;
+	for (i = 0; i < nframes; i++)
+		xfer->length += frlengths[i];
 	xfer->actlen = 0;
 	xfer->flags = flags;
 	xfer->timeout = USBD_NO_TIMEOUT;
@@ -741,7 +858,7 @@
 /*** Internal routines ***/
 
 /* Dequeue all pipe operations, called at splusb(). */
-Static usbd_status
+static usbd_status
 usbd_ar_pipe(usbd_pipe_handle pipe)
 {
 	usbd_xfer_handle xfer;
@@ -755,11 +872,12 @@
 #endif
 	pipe->repeat = 0;
 	pipe->aborting = 1;
-	while ((xfer = SIMPLEQ_FIRST(&pipe->queue)) != NULL) {
+	while ((xfer = STAILQ_FIRST(&pipe->queue)) != NULL) {
 		DPRINTFN(2,("usbd_ar_pipe: pipe=%p xfer=%p (methods=%p)\n",
 			    pipe, xfer, pipe->methods));
 		/* Make the HC abort it (and invoke the callback). */
 		pipe->methods->abort(xfer);
+		KASSERT(STAILQ_FIRST(&pipe->queue) != xfer, ("usbd_ar_pipe"));
 		/* XXX only for non-0 usbd_clear_endpoint_stall(pipe); */
 	}
 	pipe->aborting = 0;
@@ -771,7 +889,8 @@
 usb_transfer_complete(usbd_xfer_handle xfer)
 {
 	usbd_pipe_handle pipe = xfer->pipe;
-	usb_dma_t *dmap = &xfer->dmabuf;
+	struct usb_dma_mapping *dmap = &xfer->dmamap;
+	bus_dma_tag_t tag = pipe->device->bus->buffer_dmatag;
 	int sync = xfer->flags & USBD_SYNCHRONOUS;
 	int erred = xfer->status == USBD_CANCELLED ||
 	    xfer->status == USBD_TIMEOUT;
@@ -801,23 +920,19 @@
 	if (polling)
 		pipe->running = 0;
 
-	if (!(xfer->flags & USBD_NO_COPY) && xfer->actlen != 0 &&
-	    usbd_xfer_isread(xfer)) {
-#ifdef DIAGNOSTIC
-		if (xfer->actlen > xfer->length) {
-			printf("usb_transfer_complete: actlen > len %d > %d\n",
-			       xfer->actlen, xfer->length);
-			xfer->actlen = xfer->length;
-		}
-#endif
-		memcpy(xfer->buffer, KERNADDR(dmap, 0), xfer->actlen);
+	if (xfer->actlen != 0 && usbd_xfer_isread(xfer)) {
+		bus_dmamap_sync(tag, dmap->map, BUS_DMASYNC_POSTREAD);
+		/* Copy data if it is not already in the correct buffer. */
+		if (!(xfer->flags & USBD_NO_COPY) && xfer->allocbuf != NULL &&
+		    xfer->buffer != xfer->allocbuf)
+			memcpy(xfer->buffer, xfer->allocbuf, xfer->actlen);
 	}
 
-	/* if we allocated the buffer in usbd_transfer() we free it here. */
+	/* if we mapped the buffer in usbd_transfer() we unmap it here. */
 	if (xfer->rqflags & URQ_AUTO_DMABUF) {
 		if (!repeat) {
-			struct usbd_bus *bus = pipe->device->bus;
-			bus->methods->freem(bus, dmap);
+			bus_dmamap_unload(tag, dmap->map);
+			bus_dmamap_destroy(tag, dmap->map);
 			xfer->rqflags &= ~URQ_AUTO_DMABUF;
 		}
 	}
@@ -825,15 +940,14 @@
 	if (!repeat) {
 		/* Remove request from queue. */
 #ifdef DIAGNOSTIC
-		if (xfer != SIMPLEQ_FIRST(&pipe->queue))
-			printf("usb_transfer_complete: bad dequeue %p != %p\n",
-			       xfer, SIMPLEQ_FIRST(&pipe->queue));
 		xfer->busy_free = XFER_BUSY;
 #endif
-		SIMPLEQ_REMOVE_HEAD(&pipe->queue, next);
+		KASSERT(STAILQ_FIRST(&pipe->queue) == xfer,
+		    ("usb_transfer_complete: bad dequeue"));
+		STAILQ_REMOVE_HEAD(&pipe->queue, next);
 	}
 	DPRINTFN(5,("usb_transfer_complete: repeat=%d new head=%p\n",
-		    repeat, SIMPLEQ_FIRST(&pipe->queue)));
+		    repeat, STAILQ_FIRST(&pipe->queue)));
 
 	/* Count completed transfers. */
 	++pipe->device->bus->stats.uds_requests
@@ -893,7 +1007,8 @@
 	xfer->busy_free = XFER_ONQU;
 #endif
 	s = splusb();
-	SIMPLEQ_INSERT_TAIL(&pipe->queue, xfer, next);
+	KASSERT(STAILQ_FIRST(&pipe->queue) != xfer, ("usb_insert_transfer"));
+	STAILQ_INSERT_TAIL(&pipe->queue, xfer, next);
 	if (pipe->running)
 		err = USBD_IN_PROGRESS;
 	else {
@@ -925,7 +1040,7 @@
 #endif
 
 	/* Get next request in queue. */
-	xfer = SIMPLEQ_FIRST(&pipe->queue);
+	xfer = STAILQ_FIRST(&pipe->queue);
 	DPRINTFN(5, ("usbd_start_next: pipe=%p, xfer=%p\n", pipe, xfer));
 	if (xfer == NULL) {
 		pipe->running = 0;
@@ -963,7 +1078,8 @@
 	usbd_status err;
 
 #ifdef DIAGNOSTIC
-#if defined(__i386__) && defined(__FreeBSD__)
+/* XXX amd64 too? */
+#if defined(__i386__)
 	KASSERT(curthread->td_intr_nesting_level == 0,
 	       	("usbd_do_request: in interrupt context"));
 #endif
@@ -1194,7 +1310,7 @@
 }
 
 usbd_status
-usbd_get_string(usbd_device_handle dev, int si, char *buf)
+usbd_get_string(usbd_device_handle dev, int si, char *buf, size_t len)
 {
 	int swap = dev->quirks->uq_flags & UQ_SWAP_UNICODE;
 	usb_string_descriptor_t us;
@@ -1205,6 +1321,8 @@
 	int size;
 
 	buf[0] = '\0';
+	if (len == 0)
+		return (USBD_NORMAL_COMPLETION);
 	if (si == 0)
 		return (USBD_INVAL);
 	if (dev->quirks->uq_flags & UQ_NO_STRINGS)
@@ -1226,7 +1344,7 @@
 		return (err);
 	s = buf;
 	n = size / 2 - 1;
-	for (i = 0; i < n; i++) {
+	for (i = 0; i < n && i < len - 1; i++) {
 		c = UGETW(us.bString[i]);
 		/* Convert from Unicode, handle buggy strings. */
 		if ((c & 0xff00) == 0)
@@ -1240,7 +1358,6 @@
 	return (USBD_NORMAL_COMPLETION);
 }
 
-#if defined(__FreeBSD__)
 int
 usbd_driver_load(module_t mod, int what, void *arg)
 {
@@ -1248,5 +1365,3 @@
 
  	return (0);
 }
-
-#endif
Index: if_cdcereg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_cdcereg.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/if_cdcereg.h -L sys/dev/usb/if_cdcereg.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/if_cdcereg.h
+++ sys/dev/usb/if_cdcereg.h
@@ -29,7 +29,7 @@
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/usb/if_cdcereg.h,v 1.5.2.1 2005/12/29 05:30:39 sobomax Exp $
+ * $FreeBSD: src/sys/dev/usb/if_cdcereg.h,v 1.8 2007/06/10 07:33:48 imp Exp $
  */
 
 #ifndef _USB_IF_CDCEREG_H_
@@ -55,7 +55,6 @@
 	usbd_pipe_handle	 cdce_bulkout_pipe;
 	char			 cdce_dying;
 	device_t		 cdce_dev;
-	int			 cdce_unit;
 
 	struct ue_cdata		 cdce_cdata;
 	struct timeval		 cdce_rx_notice;
@@ -66,8 +65,6 @@
 	struct mtx		 cdce_mtx;
 
 	struct usb_qdat		 q;
-
-	char			 devinfo[1024];
 };
 
 /* We are still under Giant */
Index: if_kue.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/if_kue.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/usb/if_kue.c -L sys/dev/usb/if_kue.c -u -r1.1.1.1 -r1.2
--- sys/dev/usb/if_kue.c
+++ sys/dev/usb/if_kue.c
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/if_kue.c,v 1.64.2.3 2005/10/09 03:59:36 delphij Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/if_kue.c,v 1.82 2007/06/23 06:47:43 imp Exp $");
 
 /*
  * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver.
@@ -85,9 +85,6 @@
 
 #include <sys/bus.h>
 #include <machine/bus.h>
-#if __FreeBSD_version < 500000
-#include <machine/clock.h>
-#endif
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -105,53 +102,69 @@
 /*
  * Various supported device vendors/products.
  */
-Static struct kue_type kue_devs[] = {
-	{ USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
-	{ USB_VENDOR_KLSI, USB_PRODUCT_AOX_USB101 },
+static struct kue_type kue_devs[] = {
+	{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 },
+	{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460 },
+	{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_URE450 },
 	{ USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT },
+	{ USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BTX },
+	{ USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
+	{ USB_VENDOR_ASANTE, USB_PRODUCT_ASANTE_EA },
 	{ USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC10T },
-	{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 },
-	{ USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET },
-	{ USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 },
-	{ USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 },
-	{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 },
+	{ USB_VENDOR_ATEN, USB_PRODUCT_ATEN_DSB650C },
 	{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_ETHER_USB_T },
 	{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650C },
-	{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB },
-	{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T },
+	{ USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 },
+	{ USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_XX1 },
+	{ USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_XX2 },
+	{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETT },
+	{ USB_VENDOR_JATON, USB_PRODUCT_JATON_EDA },
+	{ USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_XX1 },
+	{ USB_VENDOR_KLSI, USB_PRODUCT_AOX_USB101 },
 	{ USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BT },
 	{ USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BTN },
+	{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T },
+	{ USB_VENDOR_MOBILITY, USB_PRODUCT_MOBILITY_EA },
+	{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 },
+	{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101X },
+	{ USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET },
+	{ USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 },
 	{ USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET3 },
-	{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETT },
-	{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_URE450 },
+	{ USB_VENDOR_PORTGEAR, USB_PRODUCT_PORTGEAR_EA8 },
+	{ USB_VENDOR_PORTGEAR, USB_PRODUCT_PORTGEAR_EA9 },
+	{ USB_VENDOR_PORTSMITH, USB_PRODUCT_PORTSMITH_EEA },
+	{ USB_VENDOR_SHARK, USB_PRODUCT_SHARK_PA },
+	{ USB_VENDOR_SILICOM, USB_PRODUCT_SILICOM_U2E },
+	{ USB_VENDOR_SILICOM, USB_PRODUCT_SILICOM_GPE },
+	{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB },
 	{ 0, 0 }
 };
 
-Static int kue_match(device_ptr_t);
-Static int kue_attach(device_ptr_t);
-Static int kue_detach(device_ptr_t);
-Static void kue_shutdown(device_ptr_t);
-Static int kue_encap(struct kue_softc *, struct mbuf *, int);
-Static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
-Static void kue_start(struct ifnet *);
-Static void kue_rxstart(struct ifnet *);
-Static int kue_ioctl(struct ifnet *, u_long, caddr_t);
-Static void kue_init(void *);
-Static void kue_stop(struct kue_softc *);
-Static void kue_watchdog(struct ifnet *);
+static device_probe_t kue_match;
+static device_attach_t kue_attach;
+static device_detach_t kue_detach;
+static device_shutdown_t kue_shutdown;
+static int kue_encap(struct kue_softc *, struct mbuf *, int);
+static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
+static void kue_start(struct ifnet *);
+static void kue_rxstart(struct ifnet *);
+static int kue_ioctl(struct ifnet *, u_long, caddr_t);
+static void kue_init(void *);
+static void kue_stop(struct kue_softc *);
+static void kue_watchdog(struct ifnet *);
 
-Static void kue_setmulti(struct kue_softc *);
-Static void kue_reset(struct kue_softc *);
+static void kue_setmulti(struct kue_softc *);
+static void kue_reset(struct kue_softc *);
 
-Static usbd_status kue_do_request(usbd_device_handle,
+static usbd_status kue_do_request(usbd_device_handle,
 				  usb_device_request_t *, void *);
-Static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t,
+static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t,
 			   u_int16_t, char *, int);
-Static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t);
-Static int kue_load_fw(struct kue_softc *);
+static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t);
+static int kue_load_fw(struct kue_softc *);
 
-Static device_method_t kue_methods[] = {
+static device_method_t kue_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		kue_match),
 	DEVMETHOD(device_attach,	kue_attach),
@@ -161,13 +174,13 @@
 	{ 0, 0 }
 };
 
-Static driver_t kue_driver = {
+static driver_t kue_driver = {
 	"kue",
 	kue_methods,
 	sizeof(struct kue_softc)
 };
 
-Static devclass_t kue_devclass;
+static devclass_t kue_devclass;
 
 DRIVER_MODULE(kue, uhub, kue_driver, kue_devclass, usbd_driver_load, 0);
 
@@ -178,7 +191,7 @@
  * to download the firmware to the device, which can take longer
  * than the default timeout.
  */
-Static usbd_status
+static usbd_status
 kue_do_request(usbd_device_handle dev, usb_device_request_t *req, void *data)
 {
 	usbd_xfer_handle	xfer;
@@ -192,7 +205,7 @@
 	return(err);
 }
 
-Static usbd_status
+static usbd_status
 kue_setword(struct kue_softc *sc, u_int8_t breq, u_int16_t word)
 {
 	usbd_device_handle	dev;
@@ -220,7 +233,7 @@
 	return(err);
 }
 
-Static usbd_status
+static usbd_status
 kue_ctl(struct kue_softc *sc, int rw, u_int8_t breq, u_int16_t val,
 	char *data, int len)
 {
@@ -252,7 +265,7 @@
 	return(err);
 }
 
-Static int
+static int
 kue_load_fw(struct kue_softc *sc)
 {
 	usbd_status		err;
@@ -283,33 +296,33 @@
 	err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
 	    0, kue_code_seg, sizeof(kue_code_seg));
 	if (err) {
-		printf("kue%d: failed to load code segment: %s\n",
-		    sc->kue_unit, usbd_errstr(err));
-			return(ENXIO);
+		device_printf(sc->kue_dev, "failed to load code segment: %s\n",
+		    usbd_errstr(err));
+		return(ENXIO);
 	}
 
 	/* Load fixup segment */
 	err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
 	    0, kue_fix_seg, sizeof(kue_fix_seg));
 	if (err) {
-		printf("kue%d: failed to load fixup segment: %s\n",
-		    sc->kue_unit, usbd_errstr(err));
-			return(ENXIO);
+		device_printf(sc->kue_dev, "failed to load fixup segment: %s\n",
+		    usbd_errstr(err));
+		return(ENXIO);
 	}
 
 	/* Send trigger command. */
 	err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
 	    0, kue_trig_seg, sizeof(kue_trig_seg));
 	if (err) {
-		printf("kue%d: failed to load trigger segment: %s\n",
-		    sc->kue_unit, usbd_errstr(err));
-			return(ENXIO);
+		device_printf(sc->kue_dev, "failed to load trigger segment: %s\n",
+		    usbd_errstr(err));
+		return(ENXIO);
 	}
 
 	return(0);
 }
 
-Static void
+static void
 kue_setmulti(struct kue_softc *sc)
 {
 	struct ifnet		*ifp;
@@ -328,11 +341,7 @@
 	sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI;
 
 	IF_ADDR_LOCK(ifp);
-#if __FreeBSD_version >= 500000
 	TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#else
-	LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
-#endif
 	{
 		if (ifma->ifma_addr->sa_family != AF_LINK)
 			continue;
@@ -366,14 +375,13 @@
  * done after the firmware is loaded into the adapter in order to
  * bring it into proper operation.
  */
-Static void
+static void
 kue_reset(struct kue_softc *sc)
 {
 	if (usbd_set_config_no(sc->kue_udev, KUE_CONFIG_NO, 0) ||
 	    usbd_device2interface_handle(sc->kue_udev, KUE_IFACE_IDX,
 	    &sc->kue_iface)) {
-		printf("kue%d: getting interface handle failed\n",
-		    sc->kue_unit);
+		device_printf(sc->kue_dev, "getting interface handle failed\n");
 	}
 
 	/* Wait a little while for the chip to get its brains in order. */
@@ -384,59 +392,51 @@
 /*
  * Probe for a KLSI chip.
  */
-USB_MATCH(kue)
+static int
+kue_match(device_t self)
 {
-	USB_MATCH_START(kue, uaa);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	struct kue_type			*t;
 
 	if (!uaa->iface)
 		return(UMATCH_NONE);
 
 	t = kue_devs;
-	while(t->kue_vid) {
-		if (uaa->vendor == t->kue_vid &&
-		    uaa->product == t->kue_did) {
-			return(UMATCH_VENDOR_PRODUCT);
-		}
+	while (t->kue_vid) {
+		if (uaa->vendor == t->kue_vid && uaa->product == t->kue_did)
+			return (UMATCH_VENDOR_PRODUCT);
 		t++;
 	}
-
-	return(UMATCH_NONE);
+	return (UMATCH_NONE);
 }
 
 /*
  * Attach the interface. Allocate softc structures, do
  * setup and ethernet/BPF attach.
  */
-USB_ATTACH(kue)
+static int
+kue_attach(device_t self)
 {
-	USB_ATTACH_START(kue, sc, uaa);
-	char			devinfo[1024];
+	struct kue_softc *sc = device_get_softc(self);
+	struct usb_attach_arg *uaa = device_get_ivars(self);
 	struct ifnet		*ifp;
 	usbd_status		err;
 	usb_interface_descriptor_t	*id;
 	usb_endpoint_descriptor_t	*ed;
 	int			i;
 
-	bzero(sc, sizeof(struct kue_softc));
 	sc->kue_dev = self;
 	sc->kue_iface = uaa->iface;
 	sc->kue_udev = uaa->device;
-	sc->kue_unit = device_get_unit(self);
 
 	id = usbd_get_interface_descriptor(uaa->iface);
 
-	usbd_devinfo(uaa->device, 0, devinfo);
-	device_set_desc_copy(self, devinfo);
-	printf("%s: %s\n", USBDEVNAME(self), devinfo);
-
 	/* Find endpoints. */
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
 		if (!ed) {
-			printf("kue%d: couldn't get ep %d\n",
-			    sc->kue_unit, i);
-			USB_ATTACH_ERROR_RETURN;
+			device_printf(sc->kue_dev, "couldn't get ep %d\n", i);
+			return ENXIO;
 		}
 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
@@ -450,19 +450,15 @@
 		}
 	}
 
-#if __FreeBSD_version >= 500000
 	mtx_init(&sc->kue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
 	    MTX_DEF | MTX_RECURSE);
-#endif
 	KUE_LOCK(sc);
 
 	/* Load the firmware into the NIC. */
 	if (kue_load_fw(sc)) {
 		KUE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
 		mtx_destroy(&sc->kue_mtx);
-#endif
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 
 	/* Reset the adapter. */
@@ -477,15 +473,13 @@
 
 	ifp = sc->kue_ifp = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
-		printf("kue%d: can not if_alloc()\n", sc->kue_unit);
+		device_printf(sc->kue_dev, "can not if_alloc()\n");
 		KUE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
 		mtx_destroy(&sc->kue_mtx);
-#endif
-		USB_ATTACH_ERROR_RETURN;
+		return ENXIO;
 	}
 	ifp->if_softc = sc;
-	if_initname(ifp, "kue", sc->kue_unit);
+	if_initname(ifp, "kue", device_get_unit(sc->kue_dev));
 	ifp->if_mtu = ETHERMTU;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
 	    IFF_NEEDSGIANT;
@@ -502,21 +496,17 @@
 	/*
 	 * Call MI attach routine.
 	 */
-#if __FreeBSD_version >= 500000
 	ether_ifattach(ifp, sc->kue_desc.kue_macaddr);
-#else
-	ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
-#endif
 	usb_register_netisr();
 	sc->kue_dying = 0;
 
 	KUE_UNLOCK(sc);
 
-	USB_ATTACH_SUCCESS_RETURN;
+	return 0;
 }
 
-Static int
-kue_detach(device_ptr_t dev)
+static int
+kue_detach(device_t dev)
 {
 	struct kue_softc	*sc;
 	struct ifnet		*ifp;
@@ -527,13 +517,10 @@
 
 	sc->kue_dying = 1;
 
-	if (ifp != NULL)
-#if __FreeBSD_version >= 500000
+	if (ifp != NULL) {
 		ether_ifdetach(ifp);
 		if_free(ifp);
-#else
-		ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
-#endif
+	}
 
 	if (sc->kue_ep[KUE_ENDPT_TX] != NULL)
 		usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
@@ -546,14 +533,12 @@
 		free(sc->kue_mcfilters, M_USBDEV);
 
 	KUE_UNLOCK(sc);
-#if __FreeBSD_version >= 500000
 	mtx_destroy(&sc->kue_mtx);
-#endif
 
 	return(0);
 }
 
-Static void
+static void
 kue_rxstart(struct ifnet *ifp)
 {
 	struct kue_softc	*sc;
@@ -565,8 +550,8 @@
 
 	c->ue_mbuf = usb_ether_newbuf();
 	if (c->ue_mbuf == NULL) {
-		printf("%s: no memory for rx list "
-		    "-- packet dropped!\n", USBDEVNAME(sc->kue_dev));
+		device_printf(sc->kue_dev, "no memory for rx list "
+		    "-- packet dropped!\n");
 		ifp->if_ierrors++;
 		KUE_UNLOCK(sc);
 		return;
@@ -587,7 +572,7 @@
  * A frame has been uploaded: pass the resulting mbuf chain up to
  * the higher level protocols.
  */
-Static void kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv,
+static void kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv,
 		      usbd_status status)
 {
 	struct kue_softc	*sc;
@@ -613,7 +598,7 @@
 			return;
 		}
 		if (usbd_ratecheck(&sc->kue_rx_notice))
-			printf("kue%d: usb error on rx: %s\n", sc->kue_unit,
+			device_printf(sc->kue_dev, "usb error on rx: %s\n",
 			    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_RX]);
@@ -662,7 +647,7 @@
  * the list buffers.
  */
 
-Static void
+static void
 kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
 {
 	struct kue_softc	*sc;
@@ -683,7 +668,7 @@
 			KUE_UNLOCK(sc);
 			return;
 		}
-		printf("kue%d: usb error on tx: %s\n", sc->kue_unit,
+		device_printf(sc->kue_dev, "usb error on tx: %s\n",
 		    usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_TX]);
@@ -709,7 +694,7 @@
 	return;
 }
 
-Static int
+static int
 kue_encap(struct kue_softc *sc, struct mbuf *m, int idx)
 {
 	int			total_len;
@@ -747,7 +732,7 @@
 	return(0);
 }
 
-Static void
+static void
 kue_start(struct ifnet *ifp)
 {
 	struct kue_softc	*sc;
@@ -791,7 +776,7 @@
 	return;
 }
 
-Static void
+static void
 kue_init(void *xsc)
 {
 	struct kue_softc	*sc = xsc;
@@ -809,7 +794,7 @@
 
 	/* Set MAC address */
 	kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC,
-	    0, IFP2ENADDR(sc->kue_ifp), ETHER_ADDR_LEN);
+	    0, IF_LLADDR(sc->kue_ifp), ETHER_ADDR_LEN);
 
 	sc->kue_rxfilt = KUE_RXFILT_UNICAST|KUE_RXFILT_BROADCAST;
 
@@ -832,7 +817,7 @@
 	/* Init TX ring. */
 	if (usb_ether_tx_list_init(sc, &sc->kue_cdata,
 	    sc->kue_udev) == ENOBUFS) {
-		printf("kue%d: tx list init failed\n", sc->kue_unit);
+		device_printf(sc->kue_dev, "tx list init failed\n");
 		KUE_UNLOCK(sc);
 		return;
 	}
@@ -840,7 +825,7 @@
 	/* Init RX ring. */
 	if (usb_ether_rx_list_init(sc, &sc->kue_cdata,
 	    sc->kue_udev) == ENOBUFS) {
-		printf("kue%d: rx list init failed\n", sc->kue_unit);
+		device_printf(sc->kue_dev, "rx list init failed\n");
 		KUE_UNLOCK(sc);
 		return;
 	}
@@ -852,8 +837,8 @@
 	err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_RX],
 	    USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_RX]);
 	if (err) {
-		printf("kue%d: open rx pipe failed: %s\n",
-		    sc->kue_unit, usbd_errstr(err));
+		device_printf(sc->kue_dev, "open rx pipe failed: %s\n",
+		    usbd_errstr(err));
 		KUE_UNLOCK(sc);
 		return;
 	}
@@ -861,8 +846,8 @@
 	err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_TX],
 	    USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_TX]);
 	if (err) {
-		printf("kue%d: open tx pipe failed: %s\n",
-		    sc->kue_unit, usbd_errstr(err));
+		device_printf(sc->kue_dev, "open tx pipe failed: %s\n",
+		    usbd_errstr(err));
 		KUE_UNLOCK(sc);
 		return;
 	}
@@ -884,7 +869,7 @@
 	return;
 }
 
-Static int
+static int
 kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
 {
 	struct kue_softc	*sc = ifp->if_softc;
@@ -931,7 +916,7 @@
 	return(error);
 }
 
-Static void
+static void
 kue_watchdog(struct ifnet *ifp)
 {
 	struct kue_softc	*sc;
@@ -941,7 +926,7 @@
 	sc = ifp->if_softc;
 	KUE_LOCK(sc);
 	ifp->if_oerrors++;
-	printf("kue%d: watchdog timeout\n", sc->kue_unit);
+	device_printf(sc->kue_dev, "watchdog timeout\n");
 
 	c = &sc->kue_cdata.ue_tx_chain[0];
 	usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
@@ -958,7 +943,7 @@
  * Stop the adapter and free any mbufs allocated to the
  * RX and TX lists.
  */
-Static void
+static void
 kue_stop(struct kue_softc *sc)
 {
 	usbd_status		err;
@@ -972,13 +957,13 @@
 	if (sc->kue_ep[KUE_ENDPT_RX] != NULL) {
 		err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
 		if (err) {
-			printf("kue%d: abort rx pipe failed: %s\n",
-		    	sc->kue_unit, usbd_errstr(err));
+			device_printf(sc->kue_dev, "abort rx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]);
 		if (err) {
-			printf("kue%d: close rx pipe failed: %s\n",
-		    	sc->kue_unit, usbd_errstr(err));
+			device_printf(sc->kue_dev, "close rx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->kue_ep[KUE_ENDPT_RX] = NULL;
 	}
@@ -986,13 +971,13 @@
 	if (sc->kue_ep[KUE_ENDPT_TX] != NULL) {
 		err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
 		if (err) {
-			printf("kue%d: abort tx pipe failed: %s\n",
-		    	sc->kue_unit, usbd_errstr(err));
+			device_printf(sc->kue_dev, "abort tx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]);
 		if (err) {
-			printf("kue%d: close tx pipe failed: %s\n",
-			    sc->kue_unit, usbd_errstr(err));
+			device_printf(sc->kue_dev, "close tx pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->kue_ep[KUE_ENDPT_TX] = NULL;
 	}
@@ -1000,13 +985,13 @@
 	if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) {
 		err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
 		if (err) {
-			printf("kue%d: abort intr pipe failed: %s\n",
-		    	sc->kue_unit, usbd_errstr(err));
+			device_printf(sc->kue_dev, "abort intr pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
 		if (err) {
-			printf("kue%d: close intr pipe failed: %s\n",
-			    sc->kue_unit, usbd_errstr(err));
+			device_printf(sc->kue_dev, "close intr pipe failed: %s\n",
+			    usbd_errstr(err));
 		}
 		sc->kue_ep[KUE_ENDPT_INTR] = NULL;
 	}
@@ -1026,8 +1011,8 @@
  * Stop all chip I/O so that the kernel's probe routines don't
  * get confused by errant DMAs when rebooting.
  */
-Static void
-kue_shutdown(device_ptr_t dev)
+static int
+kue_shutdown(device_t dev)
 {
 	struct kue_softc	*sc;
 
@@ -1035,5 +1020,5 @@
 
 	kue_stop(sc);
 
-	return;
+	return (0);
 }
Index: ehci_pci.c
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ehci_pci.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/ehci_pci.c -L sys/dev/usb/ehci_pci.c -u -r1.1.1.2 -r1.2
--- sys/dev/usb/ehci_pci.c
+++ sys/dev/usb/ehci_pci.c
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/usb/ehci_pci.c,v 1.18.2.1 2006/01/26 01:43:13 iedowse Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/usb/ehci_pci.c,v 1.28.2.1 2007/11/26 18:21:42 jfv Exp $");
 
 /*
  * USB Enhanced Host Controller Driver, a.k.a. USB 2.0 controller.
@@ -58,6 +58,8 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
 #include <sys/bus.h>
 #include <sys/queue.h>
 #include <sys/lockmgr.h>
@@ -115,6 +117,8 @@
 static const char *ehci_device_ich6 = "Intel 82801FB (ICH6) USB 2.0 controller";
 #define PCI_EHCI_DEVICEID_ICH7		0x27cc8086
 static const char *ehci_device_ich7 = "Intel 82801GB/R (ICH7) USB 2.0 controller";
+#define PCI_EHCI_DEVICEID_63XX		0x268c8086
+static const char *ehci_device_63XX = "Intel 63XXESB USB 2.0 controller";
  
 /* NEC */
 #define PCI_EHCI_DEVICEID_NEC		0x00e01033
@@ -145,17 +149,17 @@
 
 #ifdef USB_DEBUG
 #define EHCI_DEBUG USB_DEBUG
-#define DPRINTF(x)	do { if (ehcidebug) logprintf x; } while (0)
+#define DPRINTF(x)	do { if (ehcidebug) printf x; } while (0)
 extern int ehcidebug;
 #else
 #define DPRINTF(x)
 #endif
 
-static int ehci_pci_attach(device_t self);
-static int ehci_pci_detach(device_t self);
-static int ehci_pci_shutdown(device_t self);
-static int ehci_pci_suspend(device_t self);
-static int ehci_pci_resume(device_t self);
+static device_attach_t ehci_pci_attach;
+static device_detach_t ehci_pci_detach;
+static device_shutdown_t ehci_pci_shutdown;
+static device_suspend_t ehci_pci_suspend;
+static device_resume_t ehci_pci_resume;
 static void ehci_pci_givecontroller(device_t self);
 static void ehci_pci_takecontroller(device_t self);
 
@@ -216,6 +220,8 @@
 		return (ehci_device_sb400);
 	case PCI_EHCI_DEVICEID_6300:
 		return (ehci_device_6300);
+	case PCI_EHCI_DEVICEID_63XX:
+		return (ehci_device_63XX);
 	case PCI_EHCI_DEVICEID_ICH4:
 		return (ehci_device_ich4);
 	case PCI_EHCI_DEVICEID_ICH5:
@@ -268,6 +274,7 @@
 ehci_pci_attach(device_t self)
 {
 	ehci_softc_t *sc = device_get_softc(self);
+	devclass_t dc;
 	device_t parent;
 	device_t *neighbors;
 	device_t *nbus;
@@ -285,7 +292,7 @@
 	case PCI_USBREV_1_0:
 	case PCI_USBREV_1_1:
 		sc->sc_bus.usbrev = USBREV_UNKNOWN;
-		printf("pre-2.0 USB rev\n");
+		device_printf(self, "pre-2.0 USB rev\n");
 		return ENXIO;
 	case PCI_USBREV_2_0:
 		sc->sc_bus.usbrev = USBREV_2_0;
@@ -368,7 +375,7 @@
 	}
 
 	err = bus_setup_intr(self, sc->irq_res, INTR_TYPE_BIO,
-	    (driver_intr_t *) ehci_intr, sc, &sc->ih);
+	    NULL, (driver_intr_t *)ehci_intr, sc, &sc->ih);
 	if (err) {
 		device_printf(self, "Could not setup irq, %d\n", err);
 		sc->ih = NULL;
@@ -401,6 +408,7 @@
 		return ENXIO;
 	}
 	ncomp = 0;
+	dc = devclass_find("usb");
 	slot = pci_get_slot(self);
 	function = pci_get_function(self);
 	for (i = 0; i < count; i++) {
@@ -408,11 +416,20 @@
 			pci_get_function(neighbors[i]) < function) {
 			res = device_get_children(neighbors[i],
 				&nbus, &buscount);
-			if (res != 0 || buscount != 1)
+			if (res != 0)
 				continue;
+			if (buscount != 1) {
+				free(nbus, M_TEMP);
+				continue;
+			}
+			if (device_get_devclass(nbus[0]) != dc) {
+				free(nbus, M_TEMP);
+				continue;
+			}
 			bsc = device_get_softc(nbus[0]);
+			free(nbus, M_TEMP);
 			DPRINTF(("ehci_pci_attach: companion %s\n",
-			    USBDEVNAME(bsc->bdev)));
+			    device_get_nameunit(bsc->bdev)));
 			sc->sc_comps[ncomp++] = bsc;
 			if (ncomp >= EHCI_COMPANION_MAX)
 				break;
@@ -420,6 +437,30 @@
 	}
 	sc->sc_ncomp = ncomp;
 
+	/* Allocate a parent dma tag for DMA maps */
+	err = bus_dma_tag_create(bus_get_dma_tag(self), 1, 0,
+	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+	    BUS_SPACE_MAXSIZE_32BIT, USB_DMA_NSEG, BUS_SPACE_MAXSIZE_32BIT, 0,
+	    NULL, NULL, &sc->sc_bus.parent_dmatag);
+	if (err) {
+		device_printf(self, "Could not allocate parent DMA tag (%d)\n",
+		    err);
+		ehci_pci_detach(self);
+		return ENXIO;
+	}
+
+	/* Allocate a dma tag for transfer buffers */
+	err = bus_dma_tag_create(sc->sc_bus.parent_dmatag, 1, 0,
+	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
+	    BUS_SPACE_MAXSIZE_32BIT, USB_DMA_NSEG, BUS_SPACE_MAXSIZE_32BIT, 0,
+	    busdma_lock_mutex, &Giant, &sc->sc_bus.buffer_dmatag);
+	if (err) {
+		device_printf(self, "Could not allocate buffer DMA tag (%d)\n",
+		    err);
+		ehci_pci_detach(self);
+		return ENXIO;
+	}
+
 	ehci_pci_takecontroller(self);
 	err = ehci_init(sc);
 	if (!err) {
@@ -450,6 +491,10 @@
 	 */
 	if (sc->iot && sc->ioh)
 		bus_space_write_4(sc->iot, sc->ioh, EHCI_USBINTR, 0);
+	if (sc->sc_bus.parent_dmatag != NULL)
+		bus_dma_tag_destroy(sc->sc_bus.parent_dmatag);
+	if (sc->sc_bus.buffer_dmatag != NULL)
+		bus_dma_tag_destroy(sc->sc_bus.buffer_dmatag);
 
 	if (sc->irq_res && sc->ih) {
 		int err = bus_teardown_intr(self, sc->irq_res, sc->ih);
@@ -496,7 +541,7 @@
 		pci_write_config(self, eecp, legsup | EHCI_LEGSUP_OSOWNED, 4);
 		if (legsup & EHCI_LEGSUP_BIOSOWNED) {
 			printf("%s: waiting for BIOS to give up control\n",
-			    USBDEVNAME(sc->sc_bus.bdev));
+			    device_get_nameunit(sc->sc_bus.bdev));
 			for (i = 0; i < 5000; i++) {
 				legsup = pci_read_config(self, eecp, 4);
 				if ((legsup & EHCI_LEGSUP_BIOSOWNED) == 0)
@@ -505,7 +550,7 @@
 			}
 			if (legsup & EHCI_LEGSUP_BIOSOWNED)
 				printf("%s: timed out waiting for BIOS\n",
-				    USBDEVNAME(sc->sc_bus.bdev));
+				    device_get_nameunit(sc->sc_bus.bdev));
 		}
 	}
 }
Index: ugraphire_rdesc.h
===================================================================
RCS file: /home/cvs/src/sys/dev/usb/ugraphire_rdesc.h,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sys/dev/usb/ugraphire_rdesc.h -L sys/dev/usb/ugraphire_rdesc.h -u -r1.1.1.2 -r1.2
--- sys/dev/usb/ugraphire_rdesc.h
+++ sys/dev/usb/ugraphire_rdesc.h
@@ -1,5 +1,5 @@
 /*	$NetBSD: usb/ugraphire_rdesc.h,v 1.1 2000/12/29 01:47:49 augustss Exp $	*/
-/*	$FreeBSD: src/sys/dev/usb/ugraphire_rdesc.h,v 1.2.2.1 2006/01/20 22:55:45 mux Exp $ */
+/*	$FreeBSD: src/sys/dev/usb/ugraphire_rdesc.h,v 1.3 2005/12/31 04:38:50 mux Exp $ */
 /*-
  * Copyright (c) 2000 Nick Hibma <n_hibma at freebsd.org>
  * All rights reserved.


More information about the Midnightbsd-cvs mailing list