Module Name:    src
Committed By:   skrll
Date:           Tue Oct 20 15:31:21 UTC 2015

Modified Files:
        src/sys/arch/mips/adm5120/dev [nick-nhusb]: ahci.c
        src/sys/dev/ic [nick-nhusb]: sl811hs.c
        src/sys/dev/usb [nick-nhusb]: ehci.c motg.c motgvar.h ohci.c ohcivar.h
            uhci.c uhcivar.h xhci.c xhcivar.h
        src/sys/rump/dev/lib/libugenhc [nick-nhusb]: ugenhc.c

Log Message:
Consistently providei/use *_{XFER,PIPE,BUS}2SC, etc macros


To generate a diff of this commit:
cvs rdiff -u -r1.12.6.13 -r1.12.6.14 src/sys/arch/mips/adm5120/dev/ahci.c
cvs rdiff -u -r1.47.6.13 -r1.47.6.14 src/sys/dev/ic/sl811hs.c
cvs rdiff -u -r1.234.2.57 -r1.234.2.58 src/sys/dev/usb/ehci.c
cvs rdiff -u -r1.12.2.20 -r1.12.2.21 src/sys/dev/usb/motg.c
cvs rdiff -u -r1.4.2.6 -r1.4.2.7 src/sys/dev/usb/motgvar.h
cvs rdiff -u -r1.254.2.24 -r1.254.2.25 src/sys/dev/usb/ohci.c
cvs rdiff -u -r1.55.6.6 -r1.55.6.7 src/sys/dev/usb/ohcivar.h
cvs rdiff -u -r1.264.4.36 -r1.264.4.37 src/sys/dev/usb/uhci.c
cvs rdiff -u -r1.52.14.7 -r1.52.14.8 src/sys/dev/usb/uhcivar.h
cvs rdiff -u -r1.28.2.41 -r1.28.2.42 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.4.12.5 -r1.4.12.6 src/sys/dev/usb/xhcivar.h
cvs rdiff -u -r1.22.4.10 -r1.22.4.11 src/sys/rump/dev/lib/libugenhc/ugenhc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/adm5120/dev/ahci.c
diff -u src/sys/arch/mips/adm5120/dev/ahci.c:1.12.6.13 src/sys/arch/mips/adm5120/dev/ahci.c:1.12.6.14
--- src/sys/arch/mips/adm5120/dev/ahci.c:1.12.6.13	Sun Oct 11 09:17:50 2015
+++ src/sys/arch/mips/adm5120/dev/ahci.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahci.c,v 1.12.6.13 2015/10/11 09:17:50 skrll Exp $	*/
+/*	$NetBSD: ahci.c,v 1.12.6.14 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.12.6.13 2015/10/11 09:17:50 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.12.6.14 2015/10/20 15:31:21 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -409,6 +409,11 @@ ahci_poll(struct usbd_bus *bus)
 	DPRINTF(D_TRACE, ("%s()", __func__));
 }
 
+#define AHCI_BUS2SC(bus)	((bus)->ub_hcpriv)
+#define AHCI_PIPE2SC(pipe)	AHCI_BUS2SC((pipe)->up_dev->ud_bus)
+#define AHCI_XFER2SC(xfer)	AHCI_PIPE2SC((xfer)->ux_pipe)
+#define AHCI_APIPE2SC(ap)	AHCI_BUS2SC((d)->pipe.up_dev->ud_bus)
+
 /*
  * Emulation of interrupt transfer for status change endpoint
  * of root hub.
@@ -417,8 +422,7 @@ void
 ahci_poll_hub(void *arg)
 {
 	struct usbd_xfer *xfer = arg;
-	struct usbd_pipe *pipe = xfer->ux_pipe;
-	struct ahci_softc *sc = (struct ahci_softc *)pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	u_char *p;
 	static int p0_state=0;
 	static int p1_state=0;
@@ -453,7 +457,7 @@ ahci_poll_hub(void *arg)
 struct usbd_xfer *
 ahci_allocx(struct usbd_bus *bus, unsigned int nframes)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)bus;
+	struct ahci_softc *sc = AHCI_BUS2SC(bus);
 	struct usbd_xfer *xfer;
 
 	DPRINTF(D_MEM, ("SLallocx"));
@@ -484,7 +488,7 @@ ahci_allocx(struct usbd_bus *bus, unsign
 void
 ahci_freex(struct usbd_bus *bus, struct usbd_xfer *xfer)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)bus;
+	struct ahci_softc *sc = AHCI_BUS2SC(bus);
 
 	DPRINTF(D_MEM, ("SLfreex"));
 
@@ -502,7 +506,7 @@ ahci_freex(struct usbd_bus *bus, struct 
 static void
 ahci_get_lock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct ahci_softc *sc = bus->ub_hcpriv;
+	struct ahci_softc *sc = AHCI_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }
@@ -521,7 +525,7 @@ static int
 ahci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	struct ahci_softc *sc = bus->ub_hcpriv;
+	struct ahci_softc *sc = AHCI_BUS2SC(bus);
 	uint16_t len, value, index;
 	usb_port_status_t ps;
 	int totlen = 0;
@@ -700,7 +704,7 @@ ahci_roothub_ctrl(struct usbd_bus *bus, 
 static usbd_status
 ahci_root_intr_transfer(struct usbd_xfer *xfer)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)xfer->ux_pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	usbd_status error;
 
 	DPRINTF(D_TRACE, ("SLRItransfer "));
@@ -722,8 +726,7 @@ ahci_root_intr_transfer(struct usbd_xfer
 static usbd_status
 ahci_root_intr_start(struct usbd_xfer *xfer)
 {
-	struct usbd_pipe *pipe = xfer->ux_pipe;
-	struct ahci_softc *sc = (struct ahci_softc *)pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 
 	DPRINTF(D_TRACE, ("SLRIstart "));
 
@@ -742,7 +745,7 @@ ahci_root_intr_abort(struct usbd_xfer *x
 static void
 ahci_root_intr_close(struct usbd_pipe *pipe)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_PIPE2SC(pipe);
 
 	DPRINTF(D_TRACE, ("SLRIclose "));
 
@@ -759,7 +762,7 @@ ahci_root_intr_done(struct usbd_xfer *xf
 static usbd_status
 ahci_device_ctrl_transfer(struct usbd_xfer *xfer)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)xfer->ux_pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	usbd_status error;
 
 	DPRINTF(D_TRACE, ("C"));
@@ -783,7 +786,7 @@ ahci_device_ctrl_start(struct usbd_xfer 
 	static usb_dma_t reqdma;
 	struct usbd_pipe *pipe = xfer->ux_pipe;
 	usb_device_request_t *req = &xfer->ux_request;
-	struct ahci_softc *sc = (struct ahci_softc *)pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	int len, isread;
 
 
@@ -946,7 +949,7 @@ ahci_device_ctrl_done(struct usbd_xfer *
 static usbd_status
 ahci_device_intr_transfer(struct usbd_xfer *xfer)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)xfer->ux_pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	usbd_status error;
 
 	DPRINTF(D_TRACE, ("INTRtrans "));
@@ -994,7 +997,7 @@ ahci_poll_device(void *arg)
 	struct ahci_xfer *sx = (struct ahci_xfer *)arg;
 	struct usbd_xfer *xfer = sx->sx_xfer;
 	struct usbd_pipe *pipe = xfer->ux_pipe;
-	struct ahci_softc *sc = (struct ahci_softc *)pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	void *buf;
 	int pid;
 	int r;
@@ -1090,7 +1093,7 @@ ahci_device_isoc_done(struct usbd_xfer *
 static usbd_status
 ahci_device_bulk_transfer(struct usbd_xfer *xfer)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)xfer->ux_pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	usbd_status error;
 
 	DPRINTF(D_TRACE, ("B"));
@@ -1114,7 +1117,7 @@ ahci_device_bulk_start(struct usbd_xfer 
 	static struct admhcd_ed ep_v __attribute__((aligned(16))), *ep;
 	static struct admhcd_td td_v[NBULK_TDS] __attribute__((aligned(16))), *td[NBULK_TDS];
 	struct usbd_pipe *pipe = xfer->ux_pipe;
-	struct ahci_softc *sc = (struct ahci_softc *)pipe->up_dev->ud_bus;
+	struct ahci_softc *sc = AHCI_XFER2SC(xfer);
 	int endpt, i, len, tlen, segs, offset, isread, toggle, short_ok;
 	struct ahci_pipe *apipe = (struct ahci_pipe *)xfer->ux_pipe;
 

Index: src/sys/dev/ic/sl811hs.c
diff -u src/sys/dev/ic/sl811hs.c:1.47.6.13 src/sys/dev/ic/sl811hs.c:1.47.6.14
--- src/sys/dev/ic/sl811hs.c:1.47.6.13	Sun Oct 11 09:17:51 2015
+++ src/sys/dev/ic/sl811hs.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: sl811hs.c,v 1.47.6.13 2015/10/11 09:17:51 skrll Exp $	*/
+/*	$NetBSD: sl811hs.c,v 1.47.6.14 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Not (c) 2007 Matthew Orgass
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sl811hs.c,v 1.47.6.13 2015/10/11 09:17:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sl811hs.c,v 1.47.6.14 2015/10/20 15:31:21 skrll Exp $");
 
 #include "opt_slhci.h"
 
@@ -292,6 +292,12 @@ struct slhci_pipe {
 	uint8_t 	ptype;		/* Pipe type */
 };
 
+#define SLHCI_BUS2SC(bus)	((bus)->ub_hcpriv)
+#define SLHCI_PIPE2SC(pipe)	SLHCI_BUS2SC((pipe)->up_dev->ud_bus)
+#define SLHCI_XFER2SC(xfer)	SLHCI_PIPE2SC((xfer)->ux_pipe)
+
+#define SLHCI_PIPE2SPIPE(pipe)	((struct slhci_pipe *)(pipe))
+
 #ifdef SLHCI_PROFILE_TRANSFER
 #if defined(__mips__)
 /*
@@ -786,7 +792,7 @@ slhci_freex(struct usbd_bus *bus, struct
 #endif
 #ifdef DIAGNOSTIC
 	if (xfer->ux_state != XFER_BUSY) {
-		struct slhci_softc *sc = bus->ub_hcpriv;
+		struct slhci_softc *sc = SLHCI_BUS2SC(bus);
 		printf("%s: slhci_freex: xfer=%p not busy, %#08x halted\n",
 		    SC_NAME(sc), xfer, xfer->ux_state);
 		DDOLOG("%s: slhci_freex: xfer=%p not busy, %#08x halted\n",
@@ -803,7 +809,7 @@ slhci_freex(struct usbd_bus *bus, struct
 static void
 slhci_get_lock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct slhci_softc *sc = bus->ub_hcpriv;
+	struct slhci_softc *sc = SLHCI_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }
@@ -811,7 +817,7 @@ slhci_get_lock(struct usbd_bus *bus, kmu
 usbd_status
 slhci_transfer(struct usbd_xfer *xfer)
 {
-	struct slhci_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct slhci_softc *sc = SLHCI_XFER2SC(xfer);
 	usbd_status error;
 
 	DLOG(D_TRACE, "%s transfer xfer %p spipe %p ",
@@ -845,9 +851,9 @@ slhci_transfer(struct usbd_xfer *xfer)
 usbd_status
 slhci_start(struct usbd_xfer *xfer)
 {
-	struct slhci_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct slhci_softc *sc = SLHCI_XFER2SC(xfer);
 	struct usbd_pipe *pipe = xfer->ux_pipe;
-	struct slhci_pipe *spipe = (struct slhci_pipe *)pipe;
+	struct slhci_pipe *spipe = SLHCI_PIPE2SPIPE(pipe);
 	struct slhci_transfers *t = &sc->sc_transfers;
 	usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
 	unsigned int max_packet;
@@ -980,8 +986,8 @@ slhci_root_start(struct usbd_xfer *xfer)
 	struct slhci_softc *sc;
 	struct slhci_pipe *spipe;
 
-	spipe = (struct slhci_pipe *)xfer->ux_pipe;
-	sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	spipe = SLHCI_PIPE2SPIPE(xfer->ux_pipe);
+	sc = SLHCI_XFER2SC(xfer);
 
 	return slhci_lock_call(sc, &slhci_root, spipe, xfer);
 }
@@ -997,8 +1003,8 @@ slhci_open(struct usbd_pipe *pipe)
 	uint8_t rhaddr;
 
 	dev = pipe->up_dev;
-	sc = dev->ud_bus->ub_hcpriv;
-	spipe = (struct slhci_pipe *)pipe;
+	sc = SLHCI_PIPE2SC(pipe);
+	spipe = SLHCI_PIPE2SPIPE(pipe);
 	ed = pipe->up_endpoint->ue_edesc;
 	rhaddr = dev->ud_bus->ub_rhaddr;
 
@@ -1289,12 +1295,12 @@ slhci_abort(struct usbd_xfer *xfer)
 	struct slhci_softc *sc;
 	struct slhci_pipe *spipe;
 
-	spipe = (struct slhci_pipe *)xfer->ux_pipe;
+	spipe = SLHCI_PIPE2SPIPE(xfer->ux_pipe);
 
 	if (spipe == NULL)
 		goto callback;
 
-	sc = spipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	sc = SLHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -1315,8 +1321,8 @@ slhci_close(struct usbd_pipe *pipe)
 	struct slhci_softc *sc;
 	struct slhci_pipe *spipe;
 
-	sc = pipe->up_dev->ud_bus->ub_hcpriv;
-	spipe = (struct slhci_pipe *)pipe;
+	sc = SLHCI_PIPE2SC(pipe);
+	spipe = SLHCI_PIPE2SPIPE(pipe);
 
 	DLOG(D_TRACE, "%s close spipe %p spipe->xfer %p",
 	    pnames(spipe->ptype), spipe, spipe->xfer, 0);
@@ -1329,7 +1335,7 @@ slhci_clear_toggle(struct usbd_pipe *pip
 {
 	struct slhci_pipe *spipe;
 
-	spipe = (struct slhci_pipe *)pipe;
+	spipe = SLHCI_PIPE2SPIPE(pipe);
 
 	DLOG(D_TRACE, "%s toggle spipe %p", pnames(spipe->ptype),
 	    spipe,0,0);
@@ -1355,7 +1361,7 @@ slhci_poll(struct usbd_bus *bus) /* XXX 
 {
 	struct slhci_softc *sc;
 
-	sc = bus->ub_hcpriv;
+	sc = SLHCI_BUS2SC(bus);
 
 	DLOG(D_TRACE, "slhci_poll", 0,0,0,0);
 
@@ -1377,7 +1383,7 @@ slhci_void(void *v) {}
 void
 slhci_mem_use(struct usbd_bus *bus, int val)
 {
-	struct slhci_softc *sc = bus->ub_hcpriv;
+	struct slhci_softc *sc = SLHCI_BUS2SC(bus);
 	int s;
 
 	mutex_enter(&sc->sc_intr_lock);
@@ -2441,7 +2447,7 @@ slhci_do_repeat(struct slhci_softc *sc, 
 	struct slhci_pipe *spipe;
 
 	t = &sc->sc_transfers;
-	spipe = (struct slhci_pipe *)xfer->ux_pipe;
+	spipe = SLHCI_PIPE2SPIPE(xfer->ux_pipe);
 
 	if (xfer == t->rootintr)
 		return;
@@ -3115,7 +3121,7 @@ static int
 slhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	struct slhci_softc *sc = bus->ub_hcpriv;
+	struct slhci_softc *sc = SLHCI_BUS2SC(bus);
 	struct slhci_transfers *t = &sc->sc_transfers;
 	usbd_status error = USBD_IOERROR; /* XXX should be STALL */
 	uint16_t len, value, index;

Index: src/sys/dev/usb/ehci.c
diff -u src/sys/dev/usb/ehci.c:1.234.2.57 src/sys/dev/usb/ehci.c:1.234.2.58
--- src/sys/dev/usb/ehci.c:1.234.2.57	Sat Oct 17 15:25:38 2015
+++ src/sys/dev/usb/ehci.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ehci.c,v 1.234.2.57 2015/10/17 15:25:38 skrll Exp $ */
+/*	$NetBSD: ehci.c,v 1.234.2.58 2015/10/20 15:31:21 skrll Exp $ */
 
 /*
  * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.57 2015/10/17 15:25:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.58 2015/10/20 15:31:21 skrll Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -749,7 +749,7 @@ Static void
 ehci_softintr(void *v)
 {
 	struct usbd_bus *bus = v;
-	ehci_softc_t *sc = bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_BUS2SC(bus);
 	struct ehci_xfer *ex, *nextex;
 
 	KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
@@ -999,7 +999,7 @@ ehci_idone(struct ehci_xfer *ex)
 {
 	struct usbd_xfer *xfer = &ex->ex_xfer;
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
-	struct ehci_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ehci_softc *sc = EHCI_XFER2SC(xfer);
 	ehci_soft_qtd_t *sqtd, *lsqtd;
 	uint32_t status = 0, nstatus = 0;
 	int actlen;
@@ -1292,7 +1292,7 @@ ehci_waitintr(ehci_softc_t *sc, struct u
 Static void
 ehci_poll(struct usbd_bus *bus)
 {
-	ehci_softc_t *sc = bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_BUS2SC(bus);
 
 	USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
 
@@ -1516,7 +1516,7 @@ ehci_shutdown(device_t self, int flags)
 Static struct usbd_xfer *
 ehci_allocx(struct usbd_bus *bus, unsigned int nframes)
 {
-	struct ehci_softc *sc = bus->ub_hcpriv;
+	struct ehci_softc *sc = EHCI_BUS2SC(bus);
 	struct usbd_xfer *xfer;
 
 	xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
@@ -1534,7 +1534,7 @@ ehci_allocx(struct usbd_bus *bus, unsign
 Static void
 ehci_freex(struct usbd_bus *bus, struct usbd_xfer *xfer)
 {
-	struct ehci_softc *sc = bus->ub_hcpriv;
+	struct ehci_softc *sc = EHCI_BUS2SC(bus);
 
 	KASSERT(xfer->ux_state == XFER_BUSY);
 	KASSERT(EHCI_XFER2EXFER(xfer)->ex_isdone);
@@ -1547,7 +1547,7 @@ ehci_freex(struct usbd_bus *bus, struct 
 Static void
 ehci_get_lock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct ehci_softc *sc = bus->ub_hcpriv;
+	struct ehci_softc *sc = EHCI_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }
@@ -1840,7 +1840,7 @@ Static usbd_status
 ehci_open(struct usbd_pipe *pipe)
 {
 	struct usbd_device *dev = pipe->up_dev;
-	ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_PIPE2SC(pipe);
 	usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
 	uint8_t rhaddr = dev->ud_bus->ub_rhaddr;
 	uint8_t addr = dev->ud_addr;
@@ -2259,7 +2259,7 @@ Static int
 ehci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	ehci_softc_t *sc = bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_BUS2SC(bus);
 	usb_hub_descriptor_t hubd;
 	usb_port_status_t ps;
 	uint16_t len, value, index;
@@ -2598,7 +2598,7 @@ ehci_disown(ehci_softc_t *sc, int index,
 Static usbd_status
 ehci_root_intr_transfer(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2615,8 +2615,7 @@ ehci_root_intr_transfer(struct usbd_xfer
 Static usbd_status
 ehci_root_intr_start(struct usbd_xfer *xfer)
 {
-	struct usbd_pipe *pipe = xfer->ux_pipe;
-	ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 
 	if (sc->sc_dying)
 		return USBD_IOERROR;
@@ -2632,7 +2631,7 @@ ehci_root_intr_start(struct usbd_xfer *x
 Static void
 ehci_root_intr_abort(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 	KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
@@ -2647,7 +2646,7 @@ ehci_root_intr_abort(struct usbd_xfer *x
 Static void
 ehci_root_intr_close(struct usbd_pipe *pipe)
 {
-	ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_PIPE2SC(pipe);
 
 	USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
 
@@ -3085,7 +3084,7 @@ Static void
 ehci_close_pipe(struct usbd_pipe *pipe, ehci_soft_qh_t *head)
 {
 	struct ehci_pipe *epipe = EHCI_PIPE2EPIPE(pipe);
-	ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_PIPE2SC(pipe);
 	ehci_soft_qh_t *sqh = epipe->sqh;
 
 	KASSERT(mutex_owned(&sc->sc_lock));
@@ -3111,7 +3110,7 @@ ehci_abort_xfer(struct usbd_xfer *xfer, 
 {
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
 	struct ehci_xfer *exfer = EHCI_XFER2EXFER(xfer);
-	ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	ehci_soft_qh_t *sqh = epipe->sqh;
 	ehci_soft_qtd_t *sqtd;
 	ehci_physaddr_t cur;
@@ -3256,7 +3255,6 @@ Static void
 ehci_abort_isoc_xfer(struct usbd_xfer *xfer, usbd_status status)
 {
 	ehci_isoc_trans_t trans_status;
-	struct ehci_pipe *epipe;
 	struct ehci_xfer *exfer;
 	ehci_softc_t *sc;
 	struct ehci_soft_itd *itd;
@@ -3265,11 +3263,10 @@ ehci_abort_isoc_xfer(struct usbd_xfer *x
 
 	USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
 
-	epipe = EHCI_XFER2EPIPE(xfer);
 	exfer = EHCI_XFER2EXFER(xfer);
-	sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	sc = EHCI_XFER2SC(xfer);
 
-	USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0);
+	USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, xfer->ux_pipe, 0, 0);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -3363,8 +3360,7 @@ ehci_timeout(void *addr)
 {
 	struct usbd_xfer *xfer = addr;
 	struct ehci_xfer *exfer = EHCI_XFER2EXFER(xfer);
-	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
-	ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 
 	USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
 
@@ -3392,7 +3388,7 @@ Static void
 ehci_timeout_task(void *addr)
 {
 	struct usbd_xfer *xfer = addr;
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 
 	USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
 
@@ -3408,7 +3404,7 @@ ehci_timeout_task(void *addr)
 Static usbd_status
 ehci_device_ctrl_transfer(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -3425,7 +3421,7 @@ ehci_device_ctrl_transfer(struct usbd_xf
 Static usbd_status
 ehci_device_ctrl_start(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	if (sc->sc_dying)
@@ -3448,7 +3444,7 @@ Static void
 ehci_device_ctrl_done(struct usbd_xfer *xfer)
 {
 	struct ehci_xfer *ex = EHCI_XFER2EXFER(xfer);
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
 	usb_device_request_t *req = &xfer->ux_request;
 	int len = UGETW(req->wLength);
@@ -3488,7 +3484,7 @@ ehci_device_ctrl_abort(struct usbd_xfer 
 Static void
 ehci_device_ctrl_close(struct usbd_pipe *pipe)
 {
-	ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_PIPE2SC(pipe);
 	/*struct ehci_pipe *epipe = EHCI_PIPE2EPIPE(pipe);*/
 
 	USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
@@ -3506,8 +3502,8 @@ ehci_device_request(struct usbd_xfer *xf
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
 	struct ehci_xfer *exfer = EHCI_XFER2EXFER(xfer);
 	usb_device_request_t *req = &xfer->ux_request;
-	struct usbd_device *dev = epipe->pipe.up_dev;
-	ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
+	struct usbd_device *dev __diagused = epipe->pipe.up_dev;
 	ehci_soft_qtd_t *setup, *stat, *next;
 	ehci_soft_qh_t *sqh;
 	int isread;
@@ -3682,7 +3678,7 @@ ehci_intrlist_timeout(void *arg)
 Static usbd_status
 ehci_device_bulk_transfer(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -3701,8 +3697,7 @@ ehci_device_bulk_start(struct usbd_xfer 
 {
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
 	struct ehci_xfer *exfer = EHCI_XFER2EXFER(xfer);
-	struct usbd_device *dev = epipe->pipe.up_dev;
-	ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);;
 	ehci_soft_qtd_t *data, *dataend;
 	ehci_soft_qh_t *sqh;
 	usbd_status err;
@@ -3794,7 +3789,7 @@ ehci_device_bulk_abort(struct usbd_xfer 
 Static void
 ehci_device_bulk_close(struct usbd_pipe *pipe)
 {
-	ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_PIPE2SC(pipe);
 	struct ehci_pipe *epipe = EHCI_PIPE2EPIPE(pipe);
 
 	USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
@@ -3810,7 +3805,7 @@ Static void
 ehci_device_bulk_done(struct usbd_xfer *xfer)
 {
 	struct ehci_xfer *ex = EHCI_XFER2EXFER(xfer);
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
 	int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
 	int rd = UE_GET_DIR(endpt) == UE_DIR_IN;
@@ -3862,7 +3857,7 @@ ehci_device_setintr(ehci_softc_t *sc, eh
 Static usbd_status
 ehci_device_intr_transfer(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -3884,8 +3879,7 @@ ehci_device_intr_start(struct usbd_xfer 
 {
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
 	struct ehci_xfer *exfer = EHCI_XFER2EXFER(xfer);
-	struct usbd_device *dev = xfer->ux_pipe->up_dev;
-	ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);;
 	ehci_soft_qtd_t *data, *dataend;
 	ehci_soft_qh_t *sqh;
 	usbd_status err;
@@ -3979,7 +3973,7 @@ ehci_device_intr_abort(struct usbd_xfer 
 Static void
 ehci_device_intr_close(struct usbd_pipe *pipe)
 {
-	ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_PIPE2SC(pipe);
 	struct ehci_pipe *epipe = EHCI_PIPE2EPIPE(pipe);
 	struct ehci_soft_islot *isp;
 
@@ -3992,7 +3986,7 @@ ehci_device_intr_close(struct usbd_pipe 
 Static void
 ehci_device_intr_done(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	struct ehci_xfer *exfer = EHCI_XFER2EXFER(xfer);
 	struct ehci_pipe *epipe = EHCI_XFER2EPIPE(xfer);
 	ehci_soft_qtd_t *data, *dataend;
@@ -4056,7 +4050,7 @@ ehci_device_intr_done(struct usbd_xfer *
 Static usbd_status
 ehci_device_fs_isoc_transfer(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	mutex_enter(&sc->sc_lock);
@@ -4090,7 +4084,7 @@ ehci_device_fs_isoc_start(struct usbd_xf
 	sitd = NULL;
 	total_length = 0;
 	exfer = EHCI_XFER2EXFER(xfer);
-	sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	sc = EHCI_XFER2SC(xfer);
 	dev = xfer->ux_pipe->up_dev;
 	epipe = EHCI_XFER2EPIPE(xfer);
 
@@ -4370,7 +4364,7 @@ ehci_device_fs_isoc_done(struct usbd_xfe
 	struct ehci_pipe *epipe;
 
 	exfer = EHCI_XFER2EXFER(xfer);
-	sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	sc = EHCI_XFER2SC(xfer);
 	epipe = EHCI_XFER2EPIPE(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
@@ -4387,7 +4381,7 @@ ehci_device_fs_isoc_done(struct usbd_xfe
 Static usbd_status
 ehci_device_isoc_transfer(struct usbd_xfer *xfer)
 {
-	ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ehci_softc_t *sc = EHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	mutex_enter(&sc->sc_lock);
@@ -4419,7 +4413,7 @@ ehci_device_isoc_start(struct usbd_xfer 
 	trans_count = 0;
 	total_length = 0;
 	exfer = EHCI_XFER2EXFER(xfer);
-	sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	sc = EHCI_XFER2SC(xfer);
 	epipe = EHCI_XFER2EPIPE(xfer);
 
 	/*
@@ -4698,7 +4692,7 @@ ehci_device_isoc_done(struct usbd_xfer *
 	struct ehci_pipe *epipe;
 
 	exfer = EHCI_XFER2EXFER(xfer);
-	sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	sc = EHCI_XFER2SC(xfer);
 	epipe = EHCI_XFER2EPIPE(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));

Index: src/sys/dev/usb/motg.c
diff -u src/sys/dev/usb/motg.c:1.12.2.20 src/sys/dev/usb/motg.c:1.12.2.21
--- src/sys/dev/usb/motg.c:1.12.2.20	Tue Oct 20 15:17:54 2015
+++ src/sys/dev/usb/motg.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: motg.c,v 1.12.2.20 2015/10/20 15:17:54 skrll Exp $	*/
+/*	$NetBSD: motg.c,v 1.12.2.21 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012, 2014 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
 #include "opt_motg.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: motg.c,v 1.12.2.20 2015/10/20 15:17:54 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: motg.c,v 1.12.2.21 2015/10/20 15:31:21 skrll Exp $");
 
 #include <sys/param.h>
 
@@ -521,7 +521,7 @@ motg_select_ep(struct motg_softc *sc, st
 usbd_status
 motg_open(struct usbd_pipe *pipe)
 {
-	struct motg_softc *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_PIPE2SC(pipe);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)pipe;
 	usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
 	uint8_t rhaddr = pipe->up_dev->ud_bus->ub_rhaddr;
@@ -592,7 +592,7 @@ void
 motg_softintr(void *v)
 {
 	struct usbd_bus *bus = v;
-	struct motg_softc *sc = bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_BUS2SC(bus);
 	uint16_t rx_status, tx_status;
 	uint8_t ctrl_status;
 	uint32_t val;
@@ -706,7 +706,7 @@ motg_softintr(void *v)
 void
 motg_poll(struct usbd_bus *bus)
 {
-	struct motg_softc *sc = bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_BUS2SC(bus);
 
 	sc->sc_intr_poll(sc->sc_intr_poll_arg);
 	mutex_enter(&sc->sc_lock);
@@ -748,7 +748,7 @@ motg_intr_vbus(struct motg_softc *sc, in
 struct usbd_xfer *
 motg_allocx(struct usbd_bus *bus, unsigned int nframes)
 {
-	struct motg_softc *sc = bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_BUS2SC(bus);
 	struct usbd_xfer *xfer;
 
 	xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
@@ -764,7 +764,7 @@ motg_allocx(struct usbd_bus *bus, unsign
 void
 motg_freex(struct usbd_bus *bus, struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_BUS2SC(bus);
 
 #ifdef DIAGNOSTIC
 	if (xfer->ux_state != XFER_BUSY) {
@@ -779,7 +779,7 @@ motg_freex(struct usbd_bus *bus, struct 
 static void
 motg_get_lock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct motg_softc *sc = bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }
@@ -791,7 +791,7 @@ Static int
 motg_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	struct motg_softc *sc = bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_BUS2SC(bus);
 	int status, change, totlen = 0;
 	uint16_t len, value, index;
 	usb_port_status_t ps;
@@ -994,7 +994,7 @@ motg_roothub_ctrl(struct usbd_bus *bus, 
 void
 motg_root_intr_abort(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 	KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
@@ -1008,7 +1008,7 @@ motg_root_intr_abort(struct usbd_xfer *x
 usbd_status
 motg_root_intr_transfer(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -1030,7 +1030,7 @@ usbd_status
 motg_root_intr_start(struct usbd_xfer *xfer)
 {
 	struct usbd_pipe *pipe = xfer->ux_pipe;
-	struct motg_softc *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_PIPE2SC(pipe);
 
 	MOTGHIST_FUNC(); MOTGHIST_CALLED();
 
@@ -1048,7 +1048,7 @@ motg_root_intr_start(struct usbd_xfer *x
 void
 motg_root_intr_close(struct usbd_pipe *pipe)
 {
-	struct motg_softc *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_PIPE2SC(pipe);
 	MOTGHIST_FUNC(); MOTGHIST_CALLED();
 
 	KASSERT(mutex_owned(&sc->sc_lock));
@@ -1158,7 +1158,7 @@ motg_type(uint8_t type)
 static void
 motg_setup_endpoint_tx(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)xfer->ux_pipe;
 	struct usbd_device *dev = otgpipe->pipe.up_dev;
 	int epnumber = otgpipe->hw_ep->ep_number;
@@ -1207,7 +1207,7 @@ motg_setup_endpoint_tx(struct usbd_xfer 
 static void
 motg_setup_endpoint_rx(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	struct usbd_device *dev = xfer->ux_pipe->up_dev;
 	struct motg_pipe *otgpipe = (struct motg_pipe *)xfer->ux_pipe;
 	int epnumber = otgpipe->hw_ep->ep_number;
@@ -1256,7 +1256,7 @@ motg_setup_endpoint_rx(struct usbd_xfer 
 static usbd_status
 motg_device_ctrl_transfer(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -1277,7 +1277,7 @@ motg_device_ctrl_transfer(struct usbd_xf
 static usbd_status
 motg_device_ctrl_start(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	usbd_status err;
 	mutex_enter(&sc->sc_lock);
 	err = motg_device_ctrl_start1(sc);
@@ -1384,7 +1384,7 @@ end:
 static void
 motg_device_ctrl_read(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)xfer->ux_pipe;
 	/* assume endpoint already selected */
 	motg_setup_endpoint_rx(xfer);
@@ -1663,7 +1663,7 @@ motg_device_ctrl_abort(struct usbd_xfer 
 void
 motg_device_ctrl_close(struct usbd_pipe *pipe)
 {
-	struct motg_softc *sc __diagused = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc __diagused = MOTG_PIPE2SC(pipe);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)pipe;
 	struct motg_pipe *otgpipeiter;
 
@@ -1698,7 +1698,7 @@ motg_device_ctrl_done(struct usbd_xfer *
 static usbd_status
 motg_device_data_transfer(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	usbd_status err;
 
 	MOTGHIST_FUNC(); MOTGHIST_CALLED();
@@ -1722,7 +1722,7 @@ motg_device_data_transfer(struct usbd_xf
 static usbd_status
 motg_device_data_start(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)xfer->ux_pipe;
 	usbd_status err;
 
@@ -1829,7 +1829,7 @@ end:
 static void
 motg_device_data_read(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)xfer->ux_pipe;
 	uint32_t val;
 
@@ -1860,7 +1860,7 @@ motg_device_data_read(struct usbd_xfer *
 static void
 motg_device_data_write(struct usbd_xfer *xfer)
 {
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)xfer->ux_pipe;
 	struct motg_hw_ep *ep = otgpipe->hw_ep;
 	int datalen;
@@ -2127,7 +2127,7 @@ void
 motg_device_data_abort(struct usbd_xfer *xfer)
 {
 #ifdef DIAGNOSTIC
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 #endif
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2140,7 +2140,7 @@ motg_device_data_abort(struct usbd_xfer 
 void
 motg_device_data_close(struct usbd_pipe *pipe)
 {
-	struct motg_softc *sc __diagused = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc __diagused = MOTG_PIPE2SC(pipe);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)pipe;
 	struct motg_pipe *otgpipeiter;
 
@@ -2222,7 +2222,7 @@ motg_device_xfer_abort(struct usbd_xfer 
 {
 	int wake;
 	uint8_t csr;
-	struct motg_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct motg_softc *sc = MOTG_XFER2SC(xfer);
 	struct motg_pipe *otgpipe = (struct motg_pipe *)xfer->ux_pipe;
 	KASSERT(mutex_owned(&sc->sc_lock));
 

Index: src/sys/dev/usb/motgvar.h
diff -u src/sys/dev/usb/motgvar.h:1.4.2.6 src/sys/dev/usb/motgvar.h:1.4.2.7
--- src/sys/dev/usb/motgvar.h:1.4.2.6	Tue Oct 20 15:17:54 2015
+++ src/sys/dev/usb/motgvar.h	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: motgvar.h,v 1.4.2.6 2015/10/20 15:17:54 skrll Exp $	*/
+/*	$NetBSD: motgvar.h,v 1.4.2.7 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -113,6 +113,13 @@ struct motg_xfer {
 	struct usbd_xfer xfer;
 };
 
+#define MOTG_BUS2SC(bus)	((bus)->ub_hcpriv)
+#define MOTG_PIPE2SC(pipe)	MOTG_BUS2SC((pipe)->up_dev->ud_bus)
+#define MOTG_XFER2SC(xfer)	MOTG_PIPE2SC((xfer)->ux_pipe)
+#define MOTG_OTGPIPE2SC(mpipe)	MOTG_BUS2SC((mpipe)->pipe.up_dev->ud_bus)
+
+#define MOTG_XFER2MXFER(xfer)	((struct motg_xfer *)(xfer))
+
 int		motg_init(struct motg_softc *);
 int		motg_intr(struct motg_softc *, uint16_t, uint16_t, uint8_t);
 int		motg_intr_vbus(struct motg_softc *, int);

Index: src/sys/dev/usb/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.254.2.24 src/sys/dev/usb/ohci.c:1.254.2.25
--- src/sys/dev/usb/ohci.c:1.254.2.24	Mon Oct 12 07:02:49 2015
+++ src/sys/dev/usb/ohci.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.254.2.24 2015/10/12 07:02:49 skrll Exp $	*/
+/*	$NetBSD: ohci.c,v 1.254.2.25 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.254.2.24 2015/10/12 07:02:49 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.254.2.25 2015/10/20 15:31:21 skrll Exp $");
 
 #include "opt_usb.h"
 
@@ -945,7 +945,7 @@ ohci_init(ohci_softc_t *sc)
 struct usbd_xfer *
 ohci_allocx(struct usbd_bus *bus, unsigned int nframes)
 {
-	struct ohci_softc *sc = bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_BUS2SC(bus);
 	struct usbd_xfer *xfer;
 
 	xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
@@ -961,7 +961,7 @@ ohci_allocx(struct usbd_bus *bus, unsign
 void
 ohci_freex(struct usbd_bus *bus, struct usbd_xfer *xfer)
 {
-	struct ohci_softc *sc = bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_BUS2SC(bus);
 
 	KASSERTMSG(xfer->ux_state == XFER_BUSY,
 	    "xfer=%p not busy, 0x%08x\n", xfer, xfer->ux_state);
@@ -974,7 +974,7 @@ ohci_freex(struct usbd_bus *bus, struct 
 Static void
 ohci_get_lock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct ohci_softc *sc = bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }
@@ -1256,7 +1256,7 @@ void
 ohci_softintr(void *v)
 {
 	struct usbd_bus *bus = v;
-	ohci_softc_t *sc = bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_BUS2SC(bus);
 	ohci_soft_itd_t *sitd, *sidone, *sitdnext;
 	ohci_soft_td_t  *std,  *sdone,  *stdnext;
 	struct usbd_xfer *xfer;
@@ -1362,7 +1362,7 @@ ohci_softintr(void *v)
 			 * the endpoint.
 			 */
 			ohci_soft_td_t *p, *n;
-			opipe = (struct ohci_pipe *)xfer->ux_pipe;
+			opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
 
 			DPRINTFN(15, "error cc=%d",
 			    OHCI_TD_GET_CC(O32TOH(std->td.td_flags)), 0, 0, 0);
@@ -1414,7 +1414,7 @@ ohci_softintr(void *v)
 		if (sitd->flags & OHCI_CALL_DONE) {
 			ohci_soft_itd_t *next;
 
-			opipe = (struct ohci_pipe *)xfer->ux_pipe;
+			opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
 			opipe->isoc.inuse -= xfer->ux_nframes;
 			uedir = UE_GET_DIR(xfer->ux_pipe->up_endpoint->ue_edesc->
 			    bEndpointAddress);
@@ -1470,10 +1470,8 @@ ohci_softintr(void *v)
 void
 ohci_device_ctrl_done(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
-#ifdef DIAGNOSTIC
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
-#endif
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
+	ohci_softc_t *sc __diagused = OHCI_XFER2SC(xfer);
 	int len = UGETW(xfer->ux_request.wLength);
 	int isread = (xfer->ux_request.bmRequestType & UT_READ);
 
@@ -1493,8 +1491,8 @@ ohci_device_ctrl_done(struct usbd_xfer *
 void
 ohci_device_intr_done(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
-	ohci_softc_t *sc = opipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	ohci_soft_ed_t *sed = opipe->sed;
 	ohci_soft_td_t *data, *tail;
 	int isread =
@@ -1546,9 +1544,8 @@ ohci_device_intr_done(struct usbd_xfer *
 void
 ohci_device_bulk_done(struct usbd_xfer *xfer)
 {
-#ifdef DIAGNOSTIC
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
-#endif
+	ohci_softc_t *sc __diagused = OHCI_XFER2SC(xfer);
+
 	int isread =
 	    (UE_GET_DIR(xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress) == UE_DIR_IN);
 
@@ -1661,7 +1658,7 @@ done:
 void
 ohci_poll(struct usbd_bus *bus)
 {
-	ohci_softc_t *sc = bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_BUS2SC(bus);
 	OHCIHIST_FUNC(); OHCIHIST_CALLED();
 
 #ifdef OHCI_DEBUG
@@ -1684,10 +1681,10 @@ ohci_poll(struct usbd_bus *bus)
 usbd_status
 ohci_device_request(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
 	usb_device_request_t *req = &xfer->ux_request;
-	struct usbd_device *dev = opipe->pipe.up_dev;
-	ohci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	struct usbd_device *dev __diagused = opipe->pipe.up_dev;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	ohci_soft_td_t *setup, *stat, *next, *tail;
 	ohci_soft_ed_t *sed;
 	int isread;
@@ -1979,16 +1976,16 @@ ohci_hash_find_itd(ohci_softc_t *sc, ohc
 void
 ohci_timeout(void *addr)
 {
-	struct ohci_xfer *oxfer = addr;
-	struct ohci_pipe *opipe = (struct ohci_pipe *)oxfer->xfer.ux_pipe;
-	ohci_softc_t *sc = opipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	struct usbd_xfer *xfer = addr;
+	struct ohci_xfer *oxfer = OHCI_XFER2OXFER(xfer);
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 
 	OHCIHIST_FUNC(); OHCIHIST_CALLED();
 	DPRINTF("oxfer=%p", oxfer, 0, 0, 0);
 
 	if (sc->sc_dying) {
 		mutex_enter(&sc->sc_lock);
-		ohci_abort_xfer(&oxfer->xfer, USBD_TIMEOUT);
+		ohci_abort_xfer(xfer, USBD_TIMEOUT);
 		mutex_exit(&sc->sc_lock);
 		return;
 	}
@@ -1996,7 +1993,7 @@ ohci_timeout(void *addr)
 	/* Execute the abort in a process context. */
 	usb_init_task(&oxfer->abort_task, ohci_timeout_task, addr,
 	    USB_TASKQ_MPSAFE);
-	usb_add_task(oxfer->xfer.ux_pipe->up_dev, &oxfer->abort_task,
+	usb_add_task(xfer->ux_pipe->up_dev, &oxfer->abort_task,
 	    USB_TASKQ_HC);
 }
 
@@ -2004,7 +2001,7 @@ void
 ohci_timeout_task(void *addr)
 {
 	struct usbd_xfer *xfer = addr;
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 
 	OHCIHIST_FUNC(); OHCIHIST_CALLED();
 
@@ -2119,9 +2116,9 @@ ohci_open(struct usbd_pipe *pipe)
 {
 	struct usbd_device *dev = pipe->up_dev;
 	struct usbd_bus *bus = dev->ud_bus;
-	ohci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 	usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
 	uint8_t addr = dev->ud_addr;
 	uint8_t xfertype = ed->bmAttributes & UE_XFERTYPE;
 	ohci_soft_ed_t *sed;
@@ -2251,8 +2248,8 @@ ohci_open(struct usbd_pipe *pipe)
 void
 ohci_close_pipe(struct usbd_pipe *pipe, ohci_soft_ed_t *head)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 	ohci_soft_ed_t *sed = opipe->sed;
 
 	KASSERT(mutex_owned(&sc->sc_lock));
@@ -2303,8 +2300,8 @@ ohci_close_pipe(struct usbd_pipe *pipe, 
 void
 ohci_abort_xfer(struct usbd_xfer *xfer, usbd_status status)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
-	ohci_softc_t *sc = opipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	ohci_soft_ed_t *sed = opipe->sed;
 	ohci_soft_td_t *p, *n;
 	ohci_physaddr_t headp;
@@ -2441,7 +2438,7 @@ Static int
 ohci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	ohci_softc_t *sc = bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_BUS2SC(bus);
 	usb_port_status_t ps;
 	uint16_t len, value, index;
 	int l, totlen = 0;
@@ -2643,7 +2640,7 @@ ohci_roothub_ctrl(struct usbd_bus *bus, 
 Static usbd_status
 ohci_root_intr_transfer(struct usbd_xfer *xfer)
 {
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2660,8 +2657,7 @@ ohci_root_intr_transfer(struct usbd_xfer
 Static usbd_status
 ohci_root_intr_start(struct usbd_xfer *xfer)
 {
-	struct usbd_pipe *pipe = xfer->ux_pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 
 	if (sc->sc_dying)
 		return USBD_IOERROR;
@@ -2678,7 +2674,7 @@ ohci_root_intr_start(struct usbd_xfer *x
 Static void
 ohci_root_intr_abort(struct usbd_xfer *xfer)
 {
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 	KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
@@ -2693,7 +2689,7 @@ ohci_root_intr_abort(struct usbd_xfer *x
 Static void
 ohci_root_intr_close(struct usbd_pipe *pipe)
 {
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2707,7 +2703,7 @@ ohci_root_intr_close(struct usbd_pipe *p
 Static usbd_status
 ohci_device_ctrl_transfer(struct usbd_xfer *xfer)
 {
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2724,7 +2720,7 @@ ohci_device_ctrl_transfer(struct usbd_xf
 Static usbd_status
 ohci_device_ctrl_start(struct usbd_xfer *xfer)
 {
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	if (sc->sc_dying)
@@ -2747,9 +2743,7 @@ ohci_device_ctrl_start(struct usbd_xfer 
 Static void
 ohci_device_ctrl_abort(struct usbd_xfer *xfer)
 {
-#ifdef DIAGNOSTIC
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
-#endif
+	ohci_softc_t *sc __diagused = OHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2762,8 +2756,8 @@ ohci_device_ctrl_abort(struct usbd_xfer 
 Static void
 ohci_device_ctrl_close(struct usbd_pipe *pipe)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2778,8 +2772,8 @@ ohci_device_ctrl_close(struct usbd_pipe 
 Static void
 ohci_device_clear_toggle(struct usbd_pipe *pipe)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 
 	opipe->sed->ed.ed_headp &= HTOO32(~OHCI_TOGGLECARRY);
 }
@@ -2792,7 +2786,7 @@ ohci_noop(struct usbd_pipe *pipe)
 Static usbd_status
 ohci_device_bulk_transfer(struct usbd_xfer *xfer)
 {
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2809,9 +2803,9 @@ ohci_device_bulk_transfer(struct usbd_xf
 Static usbd_status
 ohci_device_bulk_start(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
 	struct usbd_device *dev = opipe->pipe.up_dev;
-	ohci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	int addr = dev->ud_addr;
 	ohci_soft_td_t *data, *tail, *tdp;
 	ohci_soft_ed_t *sed;
@@ -2918,9 +2912,8 @@ ohci_device_bulk_start(struct usbd_xfer 
 Static void
 ohci_device_bulk_abort(struct usbd_xfer *xfer)
 {
-#ifdef DIAGNOSTIC
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
-#endif
+	ohci_softc_t *sc __diagused = OHCI_XFER2SC(xfer);
+
 	OHCIHIST_FUNC(); OHCIHIST_CALLED();
 
 	KASSERT(mutex_owned(&sc->sc_lock));
@@ -2935,8 +2928,8 @@ ohci_device_bulk_abort(struct usbd_xfer 
 Static void
 ohci_device_bulk_close(struct usbd_pipe *pipe)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2952,7 +2945,7 @@ ohci_device_bulk_close(struct usbd_pipe 
 Static usbd_status
 ohci_device_intr_transfer(struct usbd_xfer *xfer)
 {
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2969,9 +2962,8 @@ ohci_device_intr_transfer(struct usbd_xf
 Static usbd_status
 ohci_device_intr_start(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
-	struct usbd_device *dev = opipe->pipe.up_dev;
-	ohci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	ohci_soft_ed_t *sed = opipe->sed;
 	ohci_soft_td_t *data, *tail;
 	int len, isread, endpt;
@@ -3057,9 +3049,7 @@ ohci_device_intr_start(struct usbd_xfer 
 Static void
 ohci_device_intr_abort(struct usbd_xfer *xfer)
 {
-#ifdef DIAGNOSTIC
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
-#endif
+	ohci_softc_t *sc __diagused = OHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 	KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
@@ -3071,8 +3061,8 @@ ohci_device_intr_abort(struct usbd_xfer 
 Static void
 ohci_device_intr_close(struct usbd_pipe *pipe)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 	int nslots = opipe->intr.nslots;
 	int pos = opipe->intr.pos;
 	int j;
@@ -3186,7 +3176,7 @@ ohci_device_setintr(ohci_softc_t *sc, st
 usbd_status
 ohci_device_isoc_transfer(struct usbd_xfer *xfer)
 {
-	ohci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	OHCIHIST_FUNC(); OHCIHIST_CALLED();
@@ -3217,9 +3207,8 @@ ohci_device_isoc_transfer(struct usbd_xf
 void
 ohci_device_isoc_enter(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
-	struct usbd_device *dev = opipe->pipe.up_dev;
-	ohci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	ohci_soft_ed_t *sed = opipe->sed;
 	struct isoc *isoc = &opipe->isoc;
 	ohci_soft_itd_t *sitd, *nsitd;
@@ -3350,8 +3339,7 @@ ohci_device_isoc_enter(struct usbd_xfer 
 usbd_status
 ohci_device_isoc_start(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
-	ohci_softc_t *sc = opipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 
 	OHCIHIST_FUNC(); OHCIHIST_CALLED();
 	DPRINTFN(5, "xfer=%p", xfer, 0, 0, 0);
@@ -3379,8 +3367,8 @@ ohci_device_isoc_start(struct usbd_xfer 
 void
 ohci_device_isoc_abort(struct usbd_xfer *xfer)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->ux_pipe;
-	ohci_softc_t *sc = opipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(xfer->ux_pipe);
+	ohci_softc_t *sc = OHCI_XFER2SC(xfer);
 	ohci_soft_ed_t *sed;
 	ohci_soft_itd_t *sitd;
 
@@ -3441,8 +3429,8 @@ ohci_device_isoc_done(struct usbd_xfer *
 usbd_status
 ohci_setup_isoc(struct usbd_pipe *pipe)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 	struct isoc *isoc = &opipe->isoc;
 
 	isoc->next = -1;
@@ -3458,8 +3446,8 @@ ohci_setup_isoc(struct usbd_pipe *pipe)
 void
 ohci_device_isoc_close(struct usbd_pipe *pipe)
 {
-	struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
-	ohci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ohci_pipe *opipe = OHCI_PIPE2OPIPE(pipe);
+	ohci_softc_t *sc = OHCI_PIPE2SC(pipe);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 

Index: src/sys/dev/usb/ohcivar.h
diff -u src/sys/dev/usb/ohcivar.h:1.55.6.6 src/sys/dev/usb/ohcivar.h:1.55.6.7
--- src/sys/dev/usb/ohcivar.h:1.55.6.6	Thu Mar 19 17:26:43 2015
+++ src/sys/dev/usb/ohcivar.h	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohcivar.h,v 1.55.6.6 2015/03/19 17:26:43 skrll Exp $	*/
+/*	$NetBSD: ohcivar.h,v 1.55.6.7 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -148,6 +148,13 @@ struct ohci_xfer {
 	struct usb_task	abort_task;
 };
 
+#define OHCI_BUS2SC(bus)	((bus)->ub_hcpriv)
+#define OHCI_PIPE2SC(pipe)	OHCI_BUS2SC((pipe)->up_dev->ud_bus)
+#define OHCI_XFER2SC(xfer)	OHCI_PIPE2SC((xfer)->ux_pipe)
+
+#define OHCI_XFER2OXFER(xfer)	((struct ohci_xfer *)(xfer))
+#define OHCI_PIPE2OPIPE(pipe)	((struct ohci_pipe *)(pipe))
+
 int		ohci_init(ohci_softc_t *);
 int		ohci_intr(void *);
 int		ohci_detach(ohci_softc_t *, int);

Index: src/sys/dev/usb/uhci.c
diff -u src/sys/dev/usb/uhci.c:1.264.4.36 src/sys/dev/usb/uhci.c:1.264.4.37
--- src/sys/dev/usb/uhci.c:1.264.4.36	Sun Oct 11 09:17:51 2015
+++ src/sys/dev/usb/uhci.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhci.c,v 1.264.4.36 2015/10/11 09:17:51 skrll Exp $	*/
+/*	$NetBSD: uhci.c,v 1.264.4.37 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.264.4.36 2015/10/11 09:17:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.264.4.37 2015/10/20 15:31:21 skrll Exp $");
 
 #include "opt_usb.h"
 
@@ -616,14 +616,14 @@ uhci_detach(struct uhci_softc *sc, int f
 struct usbd_xfer *
 uhci_allocx(struct usbd_bus *bus, unsigned int nframes)
 {
-	struct uhci_softc *sc = bus->ub_hcpriv;
+	struct uhci_softc *sc = UHCI_BUS2SC(bus);
 	struct usbd_xfer *xfer;
 
 	xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
 	if (xfer != NULL) {
 		memset(xfer, 0, sizeof(struct uhci_xfer));
 
-		struct uhci_xfer *uxfer = UXFER(xfer);
+		struct uhci_xfer *uxfer = UHCI_XFER2UXFER(xfer);
 		uxfer->iinfo.sc = sc;
 #ifdef DIAGNOSTIC
 		uxfer->iinfo.isdone = true;
@@ -636,8 +636,8 @@ uhci_allocx(struct usbd_bus *bus, unsign
 void
 uhci_freex(struct usbd_bus *bus, struct usbd_xfer *xfer)
 {
-	struct uhci_softc *sc = bus->ub_hcpriv;
-	struct uhci_xfer *uxfer __diagused = UXFER(xfer);
+	struct uhci_softc *sc = UHCI_BUS2SC(bus);
+	struct uhci_xfer *uxfer __diagused = UHCI_XFER2UXFER(xfer);
 
 	KASSERTMSG(xfer->ux_state == XFER_BUSY, "xfer %p state %d\n", xfer,
 	    xfer->ux_state);
@@ -651,7 +651,7 @@ uhci_freex(struct usbd_bus *bus, struct 
 Static void
 uhci_get_lock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct uhci_softc *sc = bus->ub_hcpriv;
+	struct uhci_softc *sc = UHCI_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }
@@ -975,7 +975,7 @@ uhci_poll_hub(void *addr)
 
 	if (__predict_false(pipe->up_dev == NULL || pipe->up_dev->ud_bus == NULL))
 		return;	/* device has detached */
-	sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	sc = UHCI_PIPE2SC(pipe);
 	callout_reset(&sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, xfer);
 
 	p = xfer->ux_buf;
@@ -1363,7 +1363,7 @@ void
 uhci_softintr(void *v)
 {
 	struct usbd_bus *bus = v;
-	uhci_softc_t *sc = bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_BUS2SC(bus);
 	uhci_intr_info_t *ii, *nextii;
 
 	UHCIHIST_FUNC(); UHCIHIST_CALLED();
@@ -1507,7 +1507,7 @@ void
 uhci_idone(uhci_intr_info_t *ii)
 {
 	struct usbd_xfer *xfer = ii->xfer;
-	uhci_softc_t *sc __diagused = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc __diagused = UHCI_XFER2SC(xfer);
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
 	uhci_soft_td_t *std;
 	uint32_t status = 0, nstatus;
@@ -1539,7 +1539,7 @@ uhci_idone(uhci_intr_info_t *ii)
 
 		nframes = xfer->ux_nframes;
 		actlen = 0;
-		n = UXFER(xfer)->curframe;
+		n = UHCI_XFER2UXFER(xfer)->curframe;
 		for (i = 0; i < nframes; i++) {
 			std = stds[n];
 #ifdef UHCI_DEBUG
@@ -1643,9 +1643,8 @@ void
 uhci_timeout(void *addr)
 {
 	uhci_intr_info_t *ii = addr;
-	struct uhci_xfer *uxfer = UXFER(ii->xfer);
-	struct uhci_pipe *upipe = (struct uhci_pipe *)uxfer->xfer.ux_pipe;
-	uhci_softc_t *sc = upipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	struct uhci_xfer *uxfer = UHCI_XFER2UXFER(ii->xfer);
+	uhci_softc_t *sc = UHCI_XFER2SC(ii->xfer);
 
 	UHCIHIST_FUNC(); UHCIHIST_CALLED();
 
@@ -1669,7 +1668,7 @@ void
 uhci_timeout_task(void *addr)
 {
 	struct usbd_xfer *xfer = addr;
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 
 	UHCIHIST_FUNC(); UHCIHIST_CALLED();
 
@@ -1729,7 +1728,7 @@ done:
 void
 uhci_poll(struct usbd_bus *bus)
 {
-	uhci_softc_t *sc = bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_BUS2SC(bus);
 
 	if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) {
 		mutex_spin_enter(&sc->sc_intr_lock);
@@ -2024,7 +2023,7 @@ uhci_noop(struct usbd_pipe *pipe)
 usbd_status
 uhci_device_bulk_transfer(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2045,9 +2044,8 @@ usbd_status
 uhci_device_bulk_start(struct usbd_xfer *xfer)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
-	struct usbd_device *dev = upipe->pipe.up_dev;
-	uhci_softc_t *sc = dev->ud_bus->ub_hcpriv;
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	uhci_soft_td_t *data, *dataend;
 	uhci_soft_qh_t *sqh;
 	usbd_status err;
@@ -2133,7 +2131,7 @@ uhci_device_bulk_start(struct usbd_xfer 
 void
 uhci_device_bulk_abort(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc __diagused = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc __diagused = UHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2157,9 +2155,9 @@ uhci_device_bulk_abort(struct usbd_xfer 
 void
 uhci_abort_xfer(struct usbd_xfer *xfer, usbd_status status)
 {
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
-	uhci_softc_t *sc = upipe->pipe.up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	uhci_soft_td_t *std;
 	int wake;
 
@@ -2248,8 +2246,7 @@ void
 uhci_device_bulk_close(struct usbd_pipe *pipe)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
-	struct usbd_device *dev = upipe->pipe.up_dev;
-	uhci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_PIPE2SC(pipe);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2261,7 +2258,7 @@ uhci_device_bulk_close(struct usbd_pipe 
 usbd_status
 uhci_device_ctrl_transfer(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2281,7 +2278,7 @@ uhci_device_ctrl_transfer(struct usbd_xf
 usbd_status
 uhci_device_ctrl_start(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	if (sc->sc_dying)
@@ -2303,7 +2300,7 @@ uhci_device_ctrl_start(struct usbd_xfer 
 usbd_status
 uhci_device_intr_transfer(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -2324,9 +2321,8 @@ usbd_status
 uhci_device_intr_start(struct usbd_xfer *xfer)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
-	struct usbd_device *dev = upipe->pipe.up_dev;
-	uhci_softc_t *sc = dev->ud_bus->ub_hcpriv;
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	uhci_soft_td_t *data, *dataend;
 	uhci_soft_qh_t *sqh;
 	usbd_status err;
@@ -2412,7 +2408,7 @@ uhci_device_intr_start(struct usbd_xfer 
 void
 uhci_device_ctrl_abort(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc __diagused = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc __diagused = UHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 
@@ -2430,7 +2426,7 @@ uhci_device_ctrl_close(struct usbd_pipe 
 void
 uhci_device_intr_abort(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc __diagused = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc __diagused = UHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 	KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
@@ -2446,7 +2442,7 @@ void
 uhci_device_intr_close(struct usbd_pipe *pipe)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
-	uhci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_PIPE2SC(pipe);
 	int i, npoll;
 
 	KASSERT(mutex_owned(&sc->sc_lock));
@@ -2475,10 +2471,10 @@ uhci_device_request(struct usbd_xfer *xf
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
 	usb_device_request_t *req = &xfer->ux_request;
 	struct usbd_device *dev = upipe->pipe.up_dev;
-	uhci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	int addr = dev->ud_addr;
 	int endpt = upipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	uhci_soft_td_t *setup, *data, *stat, *next, *dataend;
 	uhci_soft_qh_t *sqh;
 	int len;
@@ -2614,7 +2610,7 @@ uhci_device_request(struct usbd_xfer *xf
 usbd_status
 uhci_device_isoc_transfer(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	UHCIHIST_FUNC(); UHCIHIST_CALLED();
@@ -2645,8 +2641,7 @@ void
 uhci_device_isoc_enter(struct usbd_xfer *xfer)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
-	struct usbd_device *dev = upipe->pipe.up_dev;
-	uhci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	struct isoc *isoc = &upipe->isoc;
 	uhci_soft_td_t *std;
 	uint32_t buf, len, status, offs;
@@ -2679,7 +2674,7 @@ uhci_device_isoc_enter(struct usbd_xfer 
 	}
 
 	xfer->ux_status = USBD_IN_PROGRESS;
-	UXFER(xfer)->curframe = next;
+	UHCI_XFER2UXFER(xfer)->curframe = next;
 
 	buf = DMAADDR(&xfer->ux_dmabuf, 0);
 	offs = 0;
@@ -2724,8 +2719,8 @@ usbd_status
 uhci_device_isoc_start(struct usbd_xfer *xfer)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
-	uhci_softc_t *sc = upipe->pipe.up_dev->ud_bus->ub_hcpriv;
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	uhci_soft_td_t *end;
 	int i;
 
@@ -2745,7 +2740,7 @@ uhci_device_isoc_start(struct usbd_xfer 
 #endif
 
 	/* Find the last TD */
-	i = UXFER(xfer)->curframe + xfer->ux_nframes;
+	i = UHCI_XFER2UXFER(xfer)->curframe + xfer->ux_nframes;
 	if (i >= UHCI_VFRAMELIST_COUNT)
 		i -= UHCI_VFRAMELIST_COUNT;
 	end = upipe->isoc.stds[i];
@@ -2771,7 +2766,7 @@ uhci_device_isoc_start(struct usbd_xfer 
 void
 uhci_device_isoc_abort(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc __diagused = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc __diagused = UHCI_XFER2SC(xfer);
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
 	uhci_soft_td_t **stds = upipe->isoc.stds;
 	uhci_soft_td_t *std;
@@ -2790,7 +2785,7 @@ uhci_device_isoc_abort(struct usbd_xfer 
 
 	/* make hardware ignore it, */
 	nframes = xfer->ux_nframes;
-	n = UXFER(xfer)->curframe;
+	n = UHCI_XFER2UXFER(xfer)->curframe;
 	maxlen = 0;
 	for (i = 0; i < nframes; i++) {
 		std = stds[n];
@@ -2818,7 +2813,7 @@ uhci_device_isoc_abort(struct usbd_xfer 
 	delay(maxlen);
 
 #ifdef DIAGNOSTIC
-	UXFER(xfer)->iinfo.isdone = true;
+	UHCI_XFER2UXFER(xfer)->iinfo.isdone = true;
 #endif
 	/* Run callback and remove from interrupt list. */
 	usb_transfer_complete(xfer);
@@ -2830,8 +2825,7 @@ void
 uhci_device_isoc_close(struct usbd_pipe *pipe)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
-	struct usbd_device *dev = upipe->pipe.up_dev;
-	uhci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_PIPE2SC(pipe);
 	uhci_soft_td_t *std, *vstd;
 	struct isoc *isoc;
 	int i;
@@ -2893,8 +2887,7 @@ usbd_status
 uhci_setup_isoc(struct usbd_pipe *pipe)
 {
 	struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
-	struct usbd_device *dev = upipe->pipe.up_dev;
-	uhci_softc_t *sc = dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_PIPE2SC(pipe);
 	int addr = upipe->pipe.up_dev->ud_addr;
 	int endpt = upipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
 	int rd = UE_GET_DIR(endpt) == UE_DIR_IN;
@@ -2966,7 +2959,7 @@ uhci_setup_isoc(struct usbd_pipe *pipe)
 void
 uhci_device_isoc_done(struct usbd_xfer *xfer)
 {
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
 	int i, offs;
 	int rd = UE_GET_DIR(upipe->pipe.up_endpoint->ue_edesc->bEndpointAddress) == UE_DIR_IN;
@@ -3017,7 +3010,7 @@ uhci_device_isoc_done(struct usbd_xfer *
 void
 uhci_device_intr_done(struct usbd_xfer *xfer)
 {
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	uhci_softc_t *sc = ii->sc;
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
 	uhci_soft_qh_t *sqh;
@@ -3097,7 +3090,7 @@ uhci_device_intr_done(struct usbd_xfer *
 void
 uhci_device_ctrl_done(struct usbd_xfer *xfer)
 {
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	uhci_softc_t *sc = ii->sc;
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
 	int len = UGETW(xfer->ux_request.wLength);
@@ -3136,7 +3129,7 @@ uhci_device_ctrl_done(struct usbd_xfer *
 void
 uhci_device_bulk_done(struct usbd_xfer *xfer)
 {
-	uhci_intr_info_t *ii = &UXFER(xfer)->iinfo;
+	uhci_intr_info_t *ii = &UHCI_XFER2UXFER(xfer)->iinfo;
 	uhci_softc_t *sc = ii->sc;
 	struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->ux_pipe;
 
@@ -3291,7 +3284,7 @@ uhci_device_setintr(uhci_softc_t *sc, st
 usbd_status
 uhci_open(struct usbd_pipe *pipe)
 {
-	uhci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_PIPE2SC(pipe);
 	struct usbd_bus *bus = pipe->up_dev->ud_bus;
 	struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
 	usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
@@ -3474,7 +3467,7 @@ Static int
 uhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	uhci_softc_t *sc = bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_BUS2SC(bus);
 	int port, x;
 	int status, change, totlen = 0;
 	uint16_t len, value, index;
@@ -3710,7 +3703,7 @@ uhci_roothub_ctrl(struct usbd_bus *bus, 
 void
 uhci_root_intr_abort(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 
 	KASSERT(mutex_owned(&sc->sc_lock));
 	KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
@@ -3720,7 +3713,7 @@ uhci_root_intr_abort(struct usbd_xfer *x
 
 	xfer->ux_status = USBD_CANCELLED;
 #ifdef DIAGNOSTIC
-	UXFER(xfer)->iinfo.isdone = 1;
+	UHCI_XFER2UXFER(xfer)->iinfo.isdone = 1;
 #endif
 	usb_transfer_complete(xfer);
 }
@@ -3728,7 +3721,7 @@ uhci_root_intr_abort(struct usbd_xfer *x
 usbd_status
 uhci_root_intr_transfer(struct usbd_xfer *xfer)
 {
-	uhci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	/* Insert last in queue. */
@@ -3750,7 +3743,7 @@ usbd_status
 uhci_root_intr_start(struct usbd_xfer *xfer)
 {
 	struct usbd_pipe *pipe = xfer->ux_pipe;
-	uhci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_PIPE2SC(pipe);
 	unsigned int ival;
 
 	UHCIHIST_FUNC(); UHCIHIST_CALLED();
@@ -3772,7 +3765,7 @@ uhci_root_intr_start(struct usbd_xfer *x
 void
 uhci_root_intr_close(struct usbd_pipe *pipe)
 {
-	uhci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	uhci_softc_t *sc = UHCI_PIPE2SC(pipe);
 	UHCIHIST_FUNC(); UHCIHIST_CALLED();
 
 	KASSERT(mutex_owned(&sc->sc_lock));

Index: src/sys/dev/usb/uhcivar.h
diff -u src/sys/dev/usb/uhcivar.h:1.52.14.7 src/sys/dev/usb/uhcivar.h:1.52.14.8
--- src/sys/dev/usb/uhcivar.h:1.52.14.7	Tue Sep 29 11:38:29 2015
+++ src/sys/dev/usb/uhcivar.h	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhcivar.h,v 1.52.14.7 2015/09/29 11:38:29 skrll Exp $	*/
+/*	$NetBSD: uhcivar.h,v 1.52.14.8 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -82,7 +82,12 @@ struct uhci_xfer {
 	int curframe;
 };
 
-#define UXFER(xfer) ((struct uhci_xfer *)(xfer))
+#define UHCI_BUS2SC(bus)	((bus)->ub_hcpriv)
+#define UHCI_PIPE2SC(pipe)	UHCI_BUS2SC((pipe)->up_dev->ud_bus)
+#define UHCI_XFER2SC(xfer)	UHCI_PIPE2SC((xfer)->ux_pipe)
+#define UHCI_UPIPE2SC(d)	UHCI_BUS2SC((d)->pipe.up_dev->ud_bus)
+
+#define UHCI_XFER2UXFER(xfer)	((struct uhci_xfer *)(xfer))
 
 /*
  * Extra information that we need for a TD.

Index: src/sys/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.28.2.41 src/sys/dev/usb/xhci.c:1.28.2.42
--- src/sys/dev/usb/xhci.c:1.28.2.41	Sun Oct 11 09:17:51 2015
+++ src/sys/dev/usb/xhci.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.28.2.41 2015/10/11 09:17:51 skrll Exp $	*/
+/*	$NetBSD: xhci.c,v 1.28.2.42 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.28.2.41 2015/10/11 09:17:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.28.2.42 2015/10/20 15:31:21 skrll Exp $");
 
 #include "opt_usb.h"
 
@@ -1368,7 +1368,7 @@ xhci_setup_endp_ctx(struct usbd_pipe *pi
 static usbd_status
 xhci_configure_endpoint(struct usbd_pipe *pipe)
 {
-	struct xhci_softc * const sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 	struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc);
 	struct xhci_trb trb;
@@ -1437,7 +1437,7 @@ xhci_unconfigure_endpoint(struct usbd_pi
 static usbd_status
 xhci_reset_endpoint(struct usbd_pipe *pipe)
 {
-	struct xhci_softc * const sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 	struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc);
 	struct xhci_trb trb;
@@ -1467,7 +1467,7 @@ xhci_reset_endpoint(struct usbd_pipe *pi
 static usbd_status
 xhci_stop_endpoint(struct usbd_pipe *pipe)
 {
-	struct xhci_softc * const sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 	struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv;
 	struct xhci_trb trb;
 	usbd_status err;
@@ -1498,7 +1498,7 @@ xhci_stop_endpoint(struct usbd_pipe *pip
 static usbd_status
 xhci_set_dequeue(struct usbd_pipe *pipe)
 {
-	struct xhci_softc * const sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 	struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc);
 	struct xhci_ring * const xr = &xs->xs_ep[dci].xe_tr;
@@ -1537,7 +1537,7 @@ static usbd_status
 xhci_open(struct usbd_pipe *pipe)
 {
 	struct usbd_device * const dev = pipe->up_dev;
-	struct xhci_softc * const sc = dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(dev->ud_bus);
 	usb_endpoint_descriptor_t * const ed = pipe->up_endpoint->ue_edesc;
 	const uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes);
 
@@ -1600,7 +1600,7 @@ xhci_open(struct usbd_pipe *pipe)
 static void
 xhci_close_pipe(struct usbd_pipe *pipe)
 {
-	struct xhci_softc * const sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 	struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv;
 	usb_endpoint_descriptor_t * const ed = pipe->up_endpoint->ue_edesc;
 	const u_int dci = xhci_ep_get_dci(ed);
@@ -1669,7 +1669,7 @@ xhci_close_pipe(struct usbd_pipe *pipe)
 static void
 xhci_abort_xfer(struct usbd_xfer *xfer, usbd_status status)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 	DPRINTFN(4, "xfer %p pipe %p status %d",
@@ -1706,7 +1706,7 @@ static void
 xhci_clear_endpoint_stall_async_task(void *cookie)
 {
 	struct usbd_xfer * const xfer = cookie;
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	struct xhci_slot * const xs = xfer->ux_pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(xfer->ux_pipe->up_endpoint->ue_edesc);
 	struct xhci_ring * const tr = &xs->xs_ep[dci].xe_tr;
@@ -1727,7 +1727,7 @@ xhci_clear_endpoint_stall_async_task(voi
 static usbd_status
 xhci_clear_endpoint_stall_async(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	struct xhci_pipe * const xp = (struct xhci_pipe *)xfer->ux_pipe;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
@@ -1998,7 +1998,7 @@ static void
 xhci_softintr(void *v)
 {
 	struct usbd_bus * const bus = v;
-	struct xhci_softc * const sc = bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(bus);
 	struct xhci_ring * const er = &sc->sc_er;
 	struct xhci_trb *trb;
 	int i, j, k;
@@ -2042,7 +2042,7 @@ xhci_softintr(void *v)
 static void
 xhci_poll(struct usbd_bus *bus)
 {
-	struct xhci_softc * const sc = bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(bus);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -2056,7 +2056,7 @@ xhci_poll(struct usbd_bus *bus)
 static struct usbd_xfer *
 xhci_allocx(struct usbd_bus *bus, unsigned int nframes)
 {
-	struct xhci_softc * const sc = bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(bus);
 	struct usbd_xfer *xfer;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
@@ -2075,7 +2075,7 @@ xhci_allocx(struct usbd_bus *bus, unsign
 static void
 xhci_freex(struct usbd_bus *bus, struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(bus);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -2092,7 +2092,7 @@ xhci_freex(struct usbd_bus *bus, struct 
 static void
 xhci_get_lock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct xhci_softc * const sc = bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }
@@ -2113,7 +2113,7 @@ static usbd_status
 xhci_new_device(device_t parent, struct usbd_bus *bus, int depth,
     int speed, int port, struct usbd_port *up)
 {
-	struct xhci_softc * const sc = bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(bus);
 	struct usbd_device *dev;
 	usbd_status err;
 	usb_device_descriptor_t *dd;
@@ -2693,7 +2693,7 @@ xhci_set_dcba(struct xhci_softc * const 
 static usbd_status
 xhci_init_slot(struct usbd_device *dev, uint32_t slot, int route, int rhport)
 {
-	struct xhci_softc * const sc = dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(dev->ud_bus);
 	struct xhci_slot *xs;
 	usbd_status err;
 	u_int dci;
@@ -2807,7 +2807,7 @@ static int
 xhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	struct xhci_softc * const sc = bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_BUS2SC(bus);
 	usb_port_status_t ps;
 	int l, totlen = 0;
 	uint16_t len, value, index;
@@ -3057,7 +3057,7 @@ xhci_roothub_ctrl(struct usbd_bus *bus, 
 static usbd_status
 xhci_root_intr_transfer(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
@@ -3077,7 +3077,7 @@ xhci_root_intr_transfer(struct usbd_xfer
 static usbd_status
 xhci_root_intr_start(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -3094,7 +3094,7 @@ xhci_root_intr_start(struct usbd_xfer *x
 static void
 xhci_root_intr_abort(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -3110,7 +3110,7 @@ xhci_root_intr_abort(struct usbd_xfer *x
 static void
 xhci_root_intr_close(struct usbd_pipe *pipe)
 {
-	struct xhci_softc * const sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -3133,7 +3133,7 @@ xhci_root_intr_done(struct usbd_xfer *xf
 static usbd_status
 xhci_device_ctrl_transfer(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
@@ -3152,7 +3152,7 @@ xhci_device_ctrl_transfer(struct usbd_xf
 static usbd_status
 xhci_device_ctrl_start(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	struct xhci_slot * const xs = xfer->ux_pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(xfer->ux_pipe->up_endpoint->ue_edesc);
 	struct xhci_ring * const tr = &xs->xs_ep[dci].xe_tr;
@@ -3286,7 +3286,7 @@ xhci_device_ctrl_close(struct usbd_pipe 
 static usbd_status
 xhci_device_bulk_transfer(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
@@ -3308,7 +3308,7 @@ xhci_device_bulk_transfer(struct usbd_xf
 static usbd_status
 xhci_device_bulk_start(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	struct xhci_slot * const xs = xfer->ux_pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(xfer->ux_pipe->up_endpoint->ue_edesc);
 	struct xhci_ring * const tr = &xs->xs_ep[dci].xe_tr;
@@ -3404,7 +3404,7 @@ xhci_device_bulk_close(struct usbd_pipe 
 static usbd_status
 xhci_device_intr_transfer(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	usbd_status err;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
@@ -3426,7 +3426,7 @@ xhci_device_intr_transfer(struct usbd_xf
 static usbd_status
 xhci_device_intr_start(struct usbd_xfer *xfer)
 {
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	struct xhci_slot * const xs = xfer->ux_pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(xfer->ux_pipe->up_endpoint->ue_edesc);
 	struct xhci_ring * const tr = &xs->xs_ep[dci].xe_tr;
@@ -3474,7 +3474,7 @@ static void
 xhci_device_intr_done(struct usbd_xfer *xfer)
 {
 	struct xhci_softc * const sc __diagused =
-		xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+		XHCI_XFER2SC(xfer);
 #ifdef USB_DEBUG
 	struct xhci_slot * const xs = xfer->ux_pipe->up_dev->ud_hcpriv;
 	const u_int dci = xhci_ep_get_dci(xfer->ux_pipe->up_endpoint->ue_edesc);
@@ -3510,7 +3510,7 @@ static void
 xhci_device_intr_abort(struct usbd_xfer *xfer)
 {
 	struct xhci_softc * const sc __diagused =
-				    xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+				    XHCI_XFER2SC(xfer);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -3523,7 +3523,7 @@ xhci_device_intr_abort(struct usbd_xfer 
 static void
 xhci_device_intr_close(struct usbd_pipe *pipe)
 {
-	//struct xhci_softc * const sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	//struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 	DPRINTFN(15, "%p", pipe, 0, 0, 0);
@@ -3538,7 +3538,7 @@ xhci_timeout(void *addr)
 {
 	struct xhci_xfer * const xx = addr;
 	struct usbd_xfer * const xfer = &xx->xx_xfer;
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -3556,7 +3556,7 @@ static void
 xhci_timeout_task(void *addr)
 {
 	struct usbd_xfer * const xfer = addr;
-	struct xhci_softc * const sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 

Index: src/sys/dev/usb/xhcivar.h
diff -u src/sys/dev/usb/xhcivar.h:1.4.12.5 src/sys/dev/usb/xhcivar.h:1.4.12.6
--- src/sys/dev/usb/xhcivar.h:1.4.12.5	Mon Aug 31 08:33:03 2015
+++ src/sys/dev/usb/xhcivar.h	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhcivar.h,v 1.4.12.5 2015/08/31 08:33:03 skrll Exp $	*/
+/*	$NetBSD: xhcivar.h,v 1.4.12.6 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -39,6 +39,13 @@ struct xhci_xfer {
 	struct xhci_trb xx_trb[XHCI_XFER_NTRB];
 };
 
+#define XHCI_BUS2SC(bus)	((bus)->ub_hcpriv)
+#define XHCI_PIPE2SC(pipe)	XHCI_BUS2SC((pipe)->up_dev->ud_bus)
+#define XHCI_XFER2SC(xfer)	XHCI_PIPE2SC((xfer)->ux_pipe)
+#define XHCI_XPIPE2SC(d)	XHCI_BUS2SC((d)->pipe.up_dev->ud_bus)
+
+#define XHCI_XFER2XXFER(xfer)	((struct xhci_xfer *)(xfer))
+
 struct xhci_ring {
 	usb_dma_t xr_dma;
 	kmutex_t xr_lock;

Index: src/sys/rump/dev/lib/libugenhc/ugenhc.c
diff -u src/sys/rump/dev/lib/libugenhc/ugenhc.c:1.22.4.10 src/sys/rump/dev/lib/libugenhc/ugenhc.c:1.22.4.11
--- src/sys/rump/dev/lib/libugenhc/ugenhc.c:1.22.4.10	Sun Oct 11 09:17:51 2015
+++ src/sys/rump/dev/lib/libugenhc/ugenhc.c	Tue Oct 20 15:31:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugenhc.c,v 1.22.4.10 2015/10/11 09:17:51 skrll Exp $	*/
+/*	$NetBSD: ugenhc.c,v 1.22.4.11 2015/10/20 15:31:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ugenhc.c,v 1.22.4.10 2015/10/11 09:17:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugenhc.c,v 1.22.4.11 2015/10/20 15:31:21 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -118,6 +118,10 @@ struct rusb_xfer {
 };
 #define RUSB(x) ((struct rusb_xfer *)x)
 
+#define UGENHC_BUS2SC(bus)	((bus)->ub_hcpriv)
+#define UGENHC_PIPE2SC(pipe)	UGENHC_BUS2SC((pipe)->up_dev->ud_bus)
+#define UGENHC_XFER2SC(pipe)	UGENHC_PIPE2SC((xfer)->ux_pipe)
+
 #define UGENDEV_BASESTR "/dev/ugen"
 #define UGENDEV_BUFSIZE 32
 static void
@@ -132,7 +136,7 @@ static int
 ugenhc_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
-	struct ugenhc_softc *sc = bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_BUS2SC(bus);
 	int totlen = 0;
 	uint16_t len, value;
 
@@ -216,7 +220,7 @@ static usbd_status
 rumpusb_device_ctrl_start(struct usbd_xfer *xfer)
 {
 	usb_device_request_t *req = &xfer->ux_request;
-	struct ugenhc_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_XFER2SC(xfer);
 	uint8_t *buf = NULL;
 	int len, totlen;
 	int value;
@@ -397,7 +401,7 @@ rumpusb_device_ctrl_start(struct usbd_xf
 static usbd_status
 rumpusb_device_ctrl_transfer(struct usbd_xfer *xfer)
 {
-	struct ugenhc_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_XFER2SC(xfer);
 	usbd_status err;
 
 	mutex_enter(&sc->sc_lock);
@@ -517,7 +521,7 @@ rhscintr(void *arg)
 static usbd_status
 rumpusb_root_intr_start(struct usbd_xfer *xfer)
 {
-	struct ugenhc_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_XFER2SC(xfer);
 	int error;
 
 	mutex_enter(&sc->sc_lock);
@@ -536,7 +540,7 @@ rumpusb_root_intr_start(struct usbd_xfer
 static usbd_status
 rumpusb_root_intr_transfer(struct usbd_xfer *xfer)
 {
-	struct ugenhc_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_XFER2SC(xfer);
 	usbd_status err;
 
 	mutex_enter(&sc->sc_lock);
@@ -584,7 +588,7 @@ static const struct usbd_pipe_methods ru
 static usbd_status
 rumpusb_device_bulk_start(struct usbd_xfer *xfer)
 {
-	struct ugenhc_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_XFER2SC(xfer);
 	usb_endpoint_descriptor_t *ed = xfer->ux_pipe->up_endpoint->ue_edesc;
 	size_t n, done;
 	bool isread;
@@ -689,7 +693,7 @@ static void
 doxfer_kth(void *arg)
 {
 	struct usbd_pipe *pipe = arg;
-	struct ugenhc_softc *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_PIPE2SC(pipe);
 
 	mutex_enter(&sc->sc_lock);
 	do {
@@ -705,7 +709,7 @@ doxfer_kth(void *arg)
 static usbd_status
 rumpusb_device_bulk_transfer(struct usbd_xfer *xfer)
 {
-	struct ugenhc_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_XFER2SC(xfer);
 	usbd_status err;
 
 	if (!rump_threads) {
@@ -752,7 +756,7 @@ rumpusb_device_bulk_abort(struct usbd_xf
 static void
 rumpusb_device_bulk_close(struct usbd_pipe *pipe)
 {
-	struct ugenhc_softc *sc = pipe->up_dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_PIPE2SC(pipe);
 	int endpt = pipe->up_endpoint->ue_edesc->bEndpointAddress;
 	struct usbd_xfer *xfer;
 
@@ -793,7 +797,7 @@ static usbd_status
 ugenhc_open(struct usbd_pipe *pipe)
 {
 	struct usbd_device *dev = pipe->up_dev;
-	struct ugenhc_softc *sc = dev->ud_bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_PIPE2SC(pipe);
 	usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
 	uint8_t rhaddr = dev->ud_bus->ub_rhaddr;
 	uint8_t addr = dev->ud_addr;
@@ -903,7 +907,7 @@ ugenhc_freex(struct usbd_bus *bus, struc
 static void
 ugenhc_getlock(struct usbd_bus *bus, kmutex_t **lock)
 {
-	struct ugenhc_softc *sc = bus->ub_hcpriv;
+	struct ugenhc_softc *sc = UGENHC_BUS2SC(bus);
 
 	*lock = &sc->sc_lock;
 }

Reply via email to