CVS commit: src/sys/net

2016-10-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Oct 28 05:52:05 UTC 2016

Modified Files:
src/sys/net: if.c

Log Message:
Fix the position of IFADDR_ENTRY_DESTROY

It must be called after all readers left, i.e, after pserialize_perform.


To generate a diff of this commit:
cvs rdiff -u -r1.359 -r1.360 src/sys/net/if.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/net/if.c
diff -u src/sys/net/if.c:1.359 src/sys/net/if.c:1.360
--- src/sys/net/if.c:1.359	Tue Oct 18 07:30:30 2016
+++ src/sys/net/if.c	Fri Oct 28 05:52:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.359 2016/10/18 07:30:30 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.360 2016/10/28 05:52:05 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.359 2016/10/18 07:30:30 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.360 2016/10/28 05:52:05 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1621,7 +1621,6 @@ ifa_remove(struct ifnet *ifp, struct ifa
 	IFNET_LOCK();
 	TAILQ_REMOVE(>if_addrlist, ifa, ifa_list);
 	IFADDR_WRITER_REMOVE(ifa);
-	IFADDR_ENTRY_DESTROY(ifa);
 #ifdef NET_MPSAFE
 	pserialize_perform(ifnet_psz);
 #endif
@@ -1630,6 +1629,7 @@ ifa_remove(struct ifnet *ifp, struct ifa
 #ifdef NET_MPSAFE
 	psref_target_destroy(>ifa_psref, ifa_psref_class);
 #endif
+	IFADDR_ENTRY_DESTROY(ifa);
 	ifafree(ifa);
 }
 



CVS commit: src/sys/dev

2016-10-27 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Oct 28 05:50:18 UTC 2016

Modified Files:
src/sys/dev/mii: igphyreg.h ikphyreg.h inbmphyreg.h
src/sys/dev/pci: if_wm.c

Log Message:
- Use MII_ADDRMASK.
- Remove debug printf().


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/mii/igphyreg.h
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/mii/ikphyreg.h
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/mii/inbmphyreg.h
cvs rdiff -u -r1.431 -r1.432 src/sys/dev/pci/if_wm.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/dev/mii/igphyreg.h
diff -u src/sys/dev/mii/igphyreg.h:1.8 src/sys/dev/mii/igphyreg.h:1.9
--- src/sys/dev/mii/igphyreg.h:1.8	Mon Oct 26 02:31:31 2015
+++ src/sys/dev/mii/igphyreg.h	Fri Oct 28 05:50:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: igphyreg.h,v 1.8 2015/10/26 02:31:31 msaitoh Exp $	*/
+/*	$NetBSD: igphyreg.h,v 1.9 2016/10/28 05:50:18 msaitoh Exp $	*/
 
 /***
 
@@ -165,9 +165,8 @@
  * IGP3 regs
  */
 #define IGP3_PAGE_SHIFT		5
-#define IGP3_MAX_REG_ADDRESS	0x1f  /* 5 bit address bus (0-0x1f) */
 #define IGP3_REG(page, reg) \
-	(((page) << IGP3_PAGE_SHIFT) | ((reg) & IGP3_MAX_REG_ADDRESS))
+	(((page) << IGP3_PAGE_SHIFT) | ((reg) & MII_MAXREGADDR))
 
 #define IGP3_VR_CTRL	IGP3_REG(776, 18)
 #define IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK	0x0300

Index: src/sys/dev/mii/ikphyreg.h
diff -u src/sys/dev/mii/ikphyreg.h:1.2 src/sys/dev/mii/ikphyreg.h:1.3
--- src/sys/dev/mii/ikphyreg.h:1.2	Mon Nov 29 23:04:42 2010
+++ src/sys/dev/mii/ikphyreg.h	Fri Oct 28 05:50:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ikphyreg.h,v 1.2 2010/11/29 23:04:42 jym Exp $	*/
+/*	$NetBSD: ikphyreg.h,v 1.3 2016/10/28 05:50:18 msaitoh Exp $	*/
 /***
 Copyright (c) 2001-2005, Intel Corporation 
 All rights reserved.
@@ -41,10 +41,9 @@ POSSIBILITY OF SUCH DAMAGE.
  */
 #define GG82563_PAGE_SHIFT5
 #define GG82563_REG(page, reg)\
-(((page) << GG82563_PAGE_SHIFT) | ((reg) & GG82563_MAX_REG_ADDRESS))
+(((page) << GG82563_PAGE_SHIFT) | ((reg) & MII_ADDRMASK))
 #define GG82563_MIN_ALT_REG   30
 
-#define GG82563_MAX_REG_ADDRESS0x1F  /* 5 bit address bus (0-0x1F) */
 #define GG82563_MAX_MULTI_PAGE_REG 0xF   /* Registers equal on all pages */
 
 

Index: src/sys/dev/mii/inbmphyreg.h
diff -u src/sys/dev/mii/inbmphyreg.h:1.6 src/sys/dev/mii/inbmphyreg.h:1.7
--- src/sys/dev/mii/inbmphyreg.h:1.6	Wed Oct 19 08:22:57 2016
+++ src/sys/dev/mii/inbmphyreg.h	Fri Oct 28 05:50:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: inbmphyreg.h,v 1.6 2016/10/19 08:22:57 msaitoh Exp $	*/
+/*	$NetBSD: inbmphyreg.h,v 1.7 2016/10/28 05:50:18 msaitoh Exp $	*/
 /***
 Copyright (c) 2001-2005, Intel Corporation 
 All rights reserved.
@@ -44,16 +44,15 @@ POSSIBILITY OF SUCH DAMAGE.
  */
 #define BME1000_PAGE_SHIFT5
 #define BME1000_REG(page, reg)\
-(((page) << BME1000_PAGE_SHIFT) | ((reg) & BME1000_MAX_REG_ADDRESS))
+(((page) << BME1000_PAGE_SHIFT) | ((reg) & MII_ADDRMASK))
 
-#define BME1000_MAX_REG_ADDRESS0x1f  /* 5 bit address bus (0-0x1f) */
 #define BME1000_MAX_MULTI_PAGE_REG 0xf   /* Registers equal on all pages */
 
 #define	BM_PHY_REG_PAGE(offset)			\
 	((uint16_t)(((offset) >> BME1000_PAGE_SHIFT) & 0x))
-#define	BM_PHY_REG_NUM(offset)			\
-	((uint16_t)((offset) & BME1000_MAX_REG_ADDRESS)		\
-	| (((offset) >> (21 - BME1000_PAGE_SHIFT)) & ~BME1000_MAX_REG_ADDRESS))
+#define	BM_PHY_REG_NUM(offset)\
+	((uint16_t)((offset) & MII_ADDRMASK)		\
+	| (((offset) >> (21 - BME1000_PAGE_SHIFT)) & ~MII_ADDRMASK))
 
 /* BME1000 Specific Registers */
 #define BME1000_PHY_SPEC_CTRL	BME1000_REG(0, 16) /* PHY Specific Control */

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.431 src/sys/dev/pci/if_wm.c:1.432
--- src/sys/dev/pci/if_wm.c:1.431	Fri Oct 28 05:29:11 2016
+++ src/sys/dev/pci/if_wm.c	Fri Oct 28 05:50:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.431 2016/10/28 05:29:11 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.432 2016/10/28 05:50:18 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.431 2016/10/28 05:29:11 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.432 2016/10/28 05:50:18 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -8685,7 +8685,7 @@ wm_gmii_i80003_readreg(device_t self, in
 		return 0;
 	}
 
-	if ((reg & GG82563_MAX_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
+	if ((reg & MII_ADDRMASK) < GG82563_MIN_ALT_REG) {
 		wm_gmii_mdic_writereg(self, phy, GG82563_PHY_PAGE_SELECT,
 		reg >> GG82563_PAGE_SHIFT);
 	} else {
@@ -8694,7 +8694,7 @@ wm_gmii_i80003_readreg(device_t self, 

CVS commit: src/sys/dev/mii

2016-10-27 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Oct 28 05:47:17 UTC 2016

Modified Files:
src/sys/dev/mii: mii.h

Log Message:
Define MII_ADDRBITS and MII_ADDRMASK.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/mii/mii.h

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

Modified files:

Index: src/sys/dev/mii/mii.h
diff -u src/sys/dev/mii/mii.h:1.19 src/sys/dev/mii/mii.h:1.20
--- src/sys/dev/mii/mii.h:1.19	Tue Jul 21 02:04:24 2015
+++ src/sys/dev/mii/mii.h	Fri Oct 28 05:47:16 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mii.h,v 1.19 2015/07/21 02:04:24 msaitoh Exp $	*/
+/*	$NetBSD: mii.h,v 1.20 2016/10/28 05:47:16 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
@@ -35,6 +35,8 @@
  */
 
 #define	MII_NPHY	32	/* max # of PHYs per MII */
+#define	MII_ADDRBITS	5	/* Register address bits (0x00..0x1f) */
+#define	MII_ADDRMASK	0x1f	/* Address mask */
 
 /*
  * MII commands, used if a device must drive the MII lines



CVS commit: src/sys/dev/pci

2016-10-27 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Oct 28 05:29:11 UTC 2016

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix wm(4) input drop packet counter.

WMREG_RNBC is incremented when there is no available buffers in host
memory. However, ethernet controller can receive packets in such case
if there is space in phy's FIFO. That is, ethernet controller drops
packet only if there is no available buffers *and* there is no space
in phy's FIFO.
So, the number of dropped packets should be added WMREG_MPC only.

ok by msaitoh@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.430 -r1.431 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.430 src/sys/dev/pci/if_wm.c:1.431
--- src/sys/dev/pci/if_wm.c:1.430	Fri Oct 28 05:21:48 2016
+++ src/sys/dev/pci/if_wm.c	Fri Oct 28 05:29:11 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.430 2016/10/28 05:21:48 msaitoh Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.431 2016/10/28 05:29:11 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.430 2016/10/28 05:21:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.431 2016/10/28 05:29:11 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -2866,7 +2866,16 @@ wm_tick(void *arg)
 	+ CSR_READ(sc, WMREG_SEC)
 	+ CSR_READ(sc, WMREG_CEXTERR)
 	+ CSR_READ(sc, WMREG_RLEC);
-	ifp->if_iqdrops += CSR_READ(sc, WMREG_MPC) + CSR_READ(sc, WMREG_RNBC);
+	/*
+	 * WMREG_RNBC is incremented when there is no available buffers in host
+	 * memory. It does not mean the number of dropped packet. Because
+	 * ethernet controller can receive packets in such case if there is
+	 * space in phy's FIFO.
+	 *
+	 * If you want to know the nubmer of WMREG_RMBC, you should use such as
+	 * own EVCNT instead of if_iqdrops.
+	 */
+	ifp->if_iqdrops += CSR_READ(sc, WMREG_MPC);
 
 	if (sc->sc_flags & WM_F_HAS_MII)
 		mii_tick(>sc_mii);



CVS commit: src/sys/dev/pci

2016-10-27 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Oct 28 05:21:49 UTC 2016

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
- Remove an 82578 workaround which was for PCH rev < 3. FreeBSD removed this
  workaround in r228386.
- Add an 82578 workaround which is for PHY rev < 2. From FreeBSD and Linux.
- Add some DPRINTF()s.


To generate a diff of this commit:
cvs rdiff -u -r1.429 -r1.430 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.429 src/sys/dev/pci/if_wm.c:1.430
--- src/sys/dev/pci/if_wm.c:1.429	Fri Oct 28 04:14:13 2016
+++ src/sys/dev/pci/if_wm.c	Fri Oct 28 05:21:48 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.429 2016/10/28 04:14:13 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.430 2016/10/28 05:21:48 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.429 2016/10/28 04:14:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.430 2016/10/28 05:21:48 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -12120,6 +12120,9 @@ wm_lplu_d0_disable(struct wm_softc *sc)
 {
 	uint32_t reg;
 
+	DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+		device_xname(sc->sc_dev), __func__));
+
 	reg = CSR_READ(sc, WMREG_PHY_CTRL);
 	reg &= ~(PHY_CTRL_GBE_DIS | PHY_CTRL_D0A_LPLU);
 	CSR_WRITE(sc, WMREG_PHY_CTRL, reg);
@@ -12130,6 +12133,9 @@ wm_lplu_d0_disable_pch(struct wm_softc *
 {
 	uint32_t reg;
 
+	DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+		device_xname(sc->sc_dev), __func__));
+
 	reg = wm_gmii_hv_readreg(sc->sc_dev, 1, HV_OEM_BITS);
 	reg &= ~(HV_OEM_BITS_A1KDIS | HV_OEM_BITS_LPLU);
 	reg |= HV_OEM_BITS_ANEGNOW;
@@ -12240,6 +12246,8 @@ static void
 wm_hv_phy_workaround_ich8lan(struct wm_softc *sc)
 {
 
+	DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+		device_xname(sc->sc_dev), __func__));
 	KASSERT(sc->sc_type == WM_T_PCH);
 
 	if (sc->sc_phytype == WMPHY_82577)
@@ -12251,20 +12259,23 @@ wm_hv_phy_workaround_ich8lan(struct wm_s
 
 	/* 82578 */
 	if (sc->sc_phytype == WMPHY_82578) {
-		/* PCH rev. < 3 */
-		if (sc->sc_rev < 3) {
-			/* XXX 6 bit shift? Why? Is it page2? */
-			wm_gmii_hv_writereg(sc->sc_dev, 1, ((1 << 6) | 0x29),
-			0x66c0);
-			wm_gmii_hv_writereg(sc->sc_dev, 1, ((1 << 6) | 0x1e),
-			0x);
-		}
+		struct mii_softc *child;
 
-		/* XXX phy rev. < 2 */
+		/*
+		 * Return registers to default by doing a soft reset then
+		 * writing 0x3140 to the control register
+		 * 0x3140 == BMCR_SPEED0 | BMCR_AUTOEN | BMCR_FDX | BMCR_SPEED1
+		 */
+		child = LIST_FIRST(>sc_mii.mii_phys);
+		if ((child != NULL) && (child->mii_mpd_rev < 2)) {
+			printf("XXX 82578 rev < 2\n");
+			PHY_RESET(child);
+			sc->sc_mii.mii_writereg(sc->sc_dev, 2, MII_BMCR,
+			0x3140);
+		}
 	}
 
 	/* Select page 0 */
-
 	sc->phy.acquire(sc);
 	wm_gmii_mdic_writereg(sc->sc_dev, 1, MII_IGPHY_PAGE_SELECT, 0);
 	sc->phy.release(sc);
@@ -12280,6 +12291,8 @@ static void
 wm_lv_phy_workaround_ich8lan(struct wm_softc *sc)
 {
 
+	DPRINTF(WM_DEBUG_INIT, ("%s: %s called\n",
+		device_xname(sc->sc_dev), __func__));
 	KASSERT(sc->sc_type == WM_T_PCH2);
 
 	wm_set_mdio_slow_mode_hv(sc);



CVS commit: src/sys/dev/pci

2016-10-27 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Oct 28 04:14:13 UTC 2016

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix sc_stopping race.

To scale, separate sc_stopping flag to wm_softc and each tx,rx queues.

Pointed out by skrll@n.o, thanks.

ok by msaitoh@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.428 -r1.429 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.428 src/sys/dev/pci/if_wm.c:1.429
--- src/sys/dev/pci/if_wm.c:1.428	Wed Oct 26 10:21:44 2016
+++ src/sys/dev/pci/if_wm.c	Fri Oct 28 04:14:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.428 2016/10/26 10:21:44 msaitoh Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.429 2016/10/28 04:14:13 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.428 2016/10/26 10:21:44 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.429 2016/10/28 04:14:13 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -324,6 +324,8 @@ struct wm_txqueue {
 	int txq_flags;			/* flags for H/W queue, see below */
 #define	WM_TXQ_NO_SPACE	0x1
 
+	bool txq_stopping;
+
 #ifdef WM_EVENT_COUNTERS
 	WM_Q_EVCNT_DEFINE(txq, txsstall)	/* Tx stalled due to no txs */
 	WM_Q_EVCNT_DEFINE(txq, txdstall)	/* Tx stalled due to no txd */
@@ -373,6 +375,8 @@ struct wm_rxqueue {
 	struct mbuf *rxq_tail;
 	struct mbuf **rxq_tailp;
 
+	bool rxq_stopping;
+
 #ifdef WM_EVENT_COUNTERS
 	WM_Q_EVCNT_DEFINE(rxq, rxintr);		/* Rx interrupts */
 
@@ -447,7 +451,7 @@ struct wm_softc {
 	int sc_link_intr_idx;		/* index of MSI-X tables */
 
 	callout_t sc_tick_ch;		/* tick callout */
-	bool sc_stopping;
+	bool sc_core_stopping;
 
 	int sc_nvm_ver_major;
 	int sc_nvm_ver_minor;
@@ -643,6 +647,8 @@ static int	wm_setup_legacy(struct wm_sof
 static int	wm_setup_msix(struct wm_softc *);
 static int	wm_init(struct ifnet *);
 static int	wm_init_locked(struct ifnet *);
+static void	wm_turnon(struct wm_softc *);
+static void	wm_turnoff(struct wm_softc *);
 static void	wm_stop(struct ifnet *, int);
 static void	wm_stop_locked(struct ifnet *, int);
 static void	wm_dump_mbuf_chain(struct wm_softc *, struct mbuf *);
@@ -1596,7 +1602,7 @@ wm_attach(device_t parent, device_t self
 
 	sc->sc_dev = self;
 	callout_init(>sc_tick_ch, CALLOUT_FLAGS);
-	sc->sc_stopping = false;
+	sc->sc_core_stopping = false;
 
 	wmp = wm_lookup(pa);
 #ifdef DIAGNOSTIC
@@ -2840,7 +2846,7 @@ wm_tick(void *arg)
 
 	WM_CORE_LOCK(sc);
 
-	if (sc->sc_stopping)
+	if (sc->sc_core_stopping)
 		goto out;
 
 	if (sc->sc_type >= WM_T_82542_2_1) {
@@ -2876,7 +2882,7 @@ out:
 	splx(s);
 #endif
 
-	if (!sc->sc_stopping)
+	if (!sc->sc_core_stopping)
 		callout_reset(>sc_tick_ch, hz, wm_tick, sc);
 }
 
@@ -4552,6 +4558,52 @@ wm_setup_msix(struct wm_softc *sc)
 	return ENOMEM;
 }
 
+static void
+wm_turnon(struct wm_softc *sc)
+{
+	int i;
+
+	for(i = 0; i < sc->sc_nqueues; i++) {
+		struct wm_txqueue *txq = >sc_queue[i].wmq_txq;
+		struct wm_rxqueue *rxq = >sc_queue[i].wmq_rxq;
+
+		mutex_enter(txq->txq_lock);
+		txq->txq_stopping = false;
+		mutex_exit(txq->txq_lock);
+
+		mutex_enter(rxq->rxq_lock);
+		rxq->rxq_stopping = false;
+		mutex_exit(rxq->rxq_lock);
+	}
+
+	WM_CORE_LOCK(sc);
+	sc->sc_core_stopping = false;
+	WM_CORE_UNLOCK(sc);
+}
+
+static void
+wm_turnoff(struct wm_softc *sc)
+{
+	int i;
+
+	WM_CORE_LOCK(sc);
+	sc->sc_core_stopping = true;
+	WM_CORE_UNLOCK(sc);
+
+	for(i = 0; i < sc->sc_nqueues; i++) {
+		struct wm_rxqueue *rxq = >sc_queue[i].wmq_rxq;
+		struct wm_txqueue *txq = >sc_queue[i].wmq_txq;
+
+		mutex_enter(rxq->rxq_lock);
+		rxq->rxq_stopping = true;
+		mutex_exit(rxq->rxq_lock);
+
+		mutex_enter(txq->txq_lock);
+		txq->txq_stopping = true;
+		mutex_exit(txq->txq_lock);
+	}
+}
+
 /*
  * wm_init:		[ifnet interface function]
  *
@@ -5086,7 +5138,7 @@ wm_init_locked(struct ifnet *ifp)
 		}
 	}
 
-	sc->sc_stopping = false;
+	wm_turnon(sc);
 
 	/* Start the one second link check clock. */
 	callout_reset(>sc_tick_ch, hz, wm_tick, sc);
@@ -5129,7 +5181,7 @@ wm_stop_locked(struct ifnet *ifp, int di
 		device_xname(sc->sc_dev), __func__));
 	KASSERT(WM_CORE_LOCKED(sc));
 
-	sc->sc_stopping = true;
+	wm_turnoff(sc);
 
 	/* Stop the one second clock. */
 	callout_stop(>sc_tick_ch);
@@ -5276,7 +5328,7 @@ wm_82547_txfifo_stall(void *arg)
 
 	mutex_enter(txq->txq_lock);
 
-	if (sc->sc_stopping)
+	if (txq->txq_stopping)
 		goto out;
 
 	if (txq->txq_fifo_stall) {
@@ -6217,7 +6269,7 @@ wm_start(struct ifnet *ifp)
 	KASSERT(ifp->if_extflags & IFEF_START_MPSAFE);
 
 	mutex_enter(txq->txq_lock);
-	if (!sc->sc_stopping)
+	if (!txq->txq_stopping)
 		wm_start_locked(ifp);
 	mutex_exit(txq->txq_lock);
 }
@@ -6736,7 +6788,7 @@ wm_nq_start(struct ifnet *ifp)
 	KASSERT(ifp->if_extflags & IFEF_START_MPSAFE);
 
 	

CVS commit: src/doc

2016-10-27 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Thu Oct 27 15:21:07 UTC 2016

Modified Files:
src/doc: 3RDPARTY

Log Message:
We have root.cache 2016102001 (October 20, 2016).


To generate a diff of this commit:
cvs rdiff -u -r1.1372 -r1.1373 src/doc/3RDPARTY

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

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1372 src/doc/3RDPARTY:1.1373
--- src/doc/3RDPARTY:1.1372	Thu Oct 27 15:20:09 2016
+++ src/doc/3RDPARTY	Thu Oct 27 15:21:07 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1372 2016/10/27 15:20:09 taca Exp $
+#	$NetBSD: 3RDPARTY,v 1.1373 2016/10/27 15:21:07 taca Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -1211,7 +1211,7 @@ Notes:
 Old versions are available from Purdue (ftp.cs.purdue.edu:/pub/RCS).
 
 Package:	root.cache
-Version:	2016082500 (August 25, 2016)
+Version:	2016102001 (October 20, 2016)
 Current Vers:	2016102001 (October 20, 2016)
 Maintainer:	InterNIC
 Archive Site:	ftp://ftp.internic.net/domain/named.root



CVS commit: src/etc/namedb

2016-10-27 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Thu Oct 27 15:20:32 UTC 2016

Modified Files:
src/etc/namedb: root.cache

Log Message:
Update root.cache to 2016102001 (October 20, 2016).


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/etc/namedb/root.cache

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

Modified files:

Index: src/etc/namedb/root.cache
diff -u src/etc/namedb/root.cache:1.21 src/etc/namedb/root.cache:1.22
--- src/etc/namedb/root.cache:1.21	Sun Sep  4 14:36:31 2016
+++ src/etc/namedb/root.cache	Thu Oct 27 15:20:32 2016
@@ -1,4 +1,4 @@
-;	$NetBSD: root.cache,v 1.21 2016/09/04 14:36:31 taca Exp $
+;	$NetBSD: root.cache,v 1.22 2016/10/27 15:20:32 taca Exp $
 ;   This file holds the information on root name servers needed to
 ;   initialize cache of Internet domain name servers
 ;   (e.g. reference this file in the "cache  .  "
@@ -10,8 +10,8 @@
 ;   on server   FTP.INTERNIC.NET
 ;   -OR-RS.INTERNIC.NET
 ;
-;   last update:August 25, 2016
-;   related version of root zone:   2016082500
+;   last update:October 20, 2016
+;   related version of root zone:   2016102001
 ;
 ; formerly NS.INTERNIC.NET
 ;
@@ -53,6 +53,7 @@ F.ROOT-SERVERS.NET.  360  AA
 ;
 .360  NSG.ROOT-SERVERS.NET.
 G.ROOT-SERVERS.NET.  360  A 192.112.36.4
+G.ROOT-SERVERS.NET.  360    2001:500:12::d0d
 ;
 ; FORMERLY AOS.ARL.ARMY.MIL
 ;



CVS commit: src/doc

2016-10-27 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Thu Oct 27 15:20:09 UTC 2016

Modified Files:
src/doc: 3RDPARTY

Log Message:
named.root 2016102001 (October 20, 2016) has out.


To generate a diff of this commit:
cvs rdiff -u -r1.1371 -r1.1372 src/doc/3RDPARTY

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

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1371 src/doc/3RDPARTY:1.1372
--- src/doc/3RDPARTY:1.1371	Wed Oct 26 20:05:21 2016
+++ src/doc/3RDPARTY	Thu Oct 27 15:20:09 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1371 2016/10/26 20:05:21 christos Exp $
+#	$NetBSD: 3RDPARTY,v 1.1372 2016/10/27 15:20:09 taca Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -1212,7 +1212,7 @@ Old versions are available from Purdue (
 
 Package:	root.cache
 Version:	2016082500 (August 25, 2016)
-Current Vers:	2016082500 (August 25, 2016)
+Current Vers:	2016102001 (October 20, 2016)
 Maintainer:	InterNIC
 Archive Site:	ftp://ftp.internic.net/domain/named.root
 Home Page:	ftp://ftp.internic.net/domain/named.root



CVS commit: src/external/gpl3/gdb/dist/gdb

2016-10-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Oct 27 14:30:55 UTC 2016

Modified Files:
src/external/gpl3/gdb/dist/gdb: inf-ptrace.c

Log Message:
it might not be a breakpoint, so make the message what it actually is.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/external/gpl3/gdb/dist/gdb/inf-ptrace.c

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

Modified files:

Index: src/external/gpl3/gdb/dist/gdb/inf-ptrace.c
diff -u src/external/gpl3/gdb/dist/gdb/inf-ptrace.c:1.14 src/external/gpl3/gdb/dist/gdb/inf-ptrace.c:1.15
--- src/external/gpl3/gdb/dist/gdb/inf-ptrace.c:1.14	Mon Oct 24 17:22:33 2016
+++ src/external/gpl3/gdb/dist/gdb/inf-ptrace.c	Thu Oct 27 10:30:55 2016
@@ -500,9 +500,10 @@ inf_ptrace_xfer_partial (struct target_o
 	   to indicate failure.  */
 	if (errno == EACCES)
 	  {
-	fprintf_unfiltered (gdb_stderr, "Cannot set breakpoint at %p (%s). "
+	fprintf_unfiltered (gdb_stderr, "Cannot %s process at %p (%s). "
 "Is PaX MPROTECT active? See security(7), "
-"sysctl(7), paxctl(8)\n", piod.piod_offs,
+"sysctl(7), paxctl(8)\n", writebuf ? "write to" :
+"read from", piod.piod_offs,
 strerror(errno));
 	return TARGET_XFER_E_IO;	/* Some other error perhaps? */
 	  }



CVS commit: [nick-nhusb] src/sys/dev/usb

2016-10-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct 27 12:30:54 UTC 2016

Modified Files:
src/sys/dev/usb [nick-nhusb]: ucom.c

Log Message:
Style and sprinkle const.


To generate a diff of this commit:
cvs rdiff -u -r1.108.2.24 -r1.108.2.25 src/sys/dev/usb/ucom.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/dev/usb/ucom.c
diff -u src/sys/dev/usb/ucom.c:1.108.2.24 src/sys/dev/usb/ucom.c:1.108.2.25
--- src/sys/dev/usb/ucom.c:1.108.2.24	Thu Oct 27 07:46:19 2016
+++ src/sys/dev/usb/ucom.c	Thu Oct 27 12:30:54 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucom.c,v 1.108.2.24 2016/10/27 07:46:19 skrll Exp $	*/
+/*	$NetBSD: ucom.c,v 1.108.2.25 2016/10/27 12:30:54 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.24 2016/10/27 07:46:19 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.25 2016/10/27 12:30:54 skrll Exp $");
 
 #include 
 #include 
@@ -538,8 +538,8 @@ ucom_shutdown(struct ucom_softc *sc)
 int
 ucomopen(dev_t dev, int flag, int mode, struct lwp *l)
 {
-	int unit = UCOMUNIT(dev);
-	struct ucom_softc *sc = device_lookup_private(_cd, unit);
+	const int unit = UCOMUNIT(dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 	struct ucom_buffer *ub;
 	int error;
 
@@ -701,7 +701,8 @@ bad:
 int
 ucomclose(dev_t dev, int flag, int mode, struct lwp *l)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd, UCOMUNIT(dev));
+	const int unit = UCOMUNIT(dev);
+	struct ucom_softc *sc = device_lookup_private(_cd, unit);
 
 	UCOMHIST_FUNC(); UCOMHIST_CALLED();
 
@@ -753,7 +754,8 @@ out:
 int
 ucomread(dev_t dev, struct uio *uio, int flag)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd, UCOMUNIT(dev));
+	const int unit = UCOMUNIT(dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 	int error;
 
 	UCOMHIST_FUNC(); UCOMHIST_CALLED();
@@ -785,7 +787,8 @@ ucomread(dev_t dev, struct uio *uio, int
 int
 ucomwrite(dev_t dev, struct uio *uio, int flag)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd, UCOMUNIT(dev));
+	const int unit = UCOMUNIT(dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 	int error;
 
 	if (sc == NULL)
@@ -815,10 +818,9 @@ ucomwrite(dev_t dev, struct uio *uio, in
 int
 ucompoll(dev_t dev, int events, struct lwp *l)
 {
-	struct ucom_softc *sc;
-	int revents;
+	const int unit = UCOMUNIT(dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 
-	sc = device_lookup_private(_cd, UCOMUNIT(dev));
 	if (sc == NULL)
 		return POLLHUP;
 
@@ -832,7 +834,7 @@ ucompoll(dev_t dev, int events, struct l
 	sc->sc_refcnt++;
 	mutex_exit(>sc_lock);
 
-	revents = ((*tp->t_linesw->l_poll)(tp, events, l));
+	int revents = ((*tp->t_linesw->l_poll)(tp, events, l));
 
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt < 0)
@@ -845,7 +847,8 @@ ucompoll(dev_t dev, int events, struct l
 struct tty *
 ucomtty(dev_t dev)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd, UCOMUNIT(dev));
+	const int unit = UCOMUNIT(dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 
 	return sc != NULL ? sc->sc_tty : NULL;
 }
@@ -853,7 +856,8 @@ ucomtty(dev_t dev)
 int
 ucomioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd, UCOMUNIT(dev));
+	const int unit = UCOMUNIT(dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 	int error;
 
 	if (sc == NULL)
@@ -,8 +1115,8 @@ ucom_status_change(struct ucom_softc *sc
 static int
 ucomparam(struct tty *tp, struct termios *t)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd,
-	UCOMUNIT(tp->t_dev));
+	const int unit = UCOMUNIT(tp->t_dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 	int error;
 
 	UCOMHIST_FUNC(); UCOMHIST_CALLED();
@@ -1182,8 +1186,8 @@ XXX what if the hardware is not open
 static int
 ucomhwiflow(struct tty *tp, int block)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd,
-	UCOMUNIT(tp->t_dev));
+	const int unit = UCOMUNIT(tp->t_dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 	int old;
 
 	if (sc == NULL)
@@ -1205,8 +1209,8 @@ ucomhwiflow(struct tty *tp, int block)
 static void
 ucomstart(struct tty *tp)
 {
-	struct ucom_softc *sc = device_lookup_private(_cd,
-	UCOMUNIT(tp->t_dev));
+	const int unit = UCOMUNIT(tp->t_dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 	struct ucom_buffer *ub;
 	u_char *data;
 	int cnt;
@@ -1270,8 +1274,8 @@ void
 ucomstop(struct tty *tp, int flag)
 {
 #if 0
-	struct ucom_softc *sc =
-	device_lookup_private(_cd, UCOMUNIT(tp->t_dev));
+	const int unit = UCOMUNIT(tp->t_dev);
+	struct ucom_softc * const sc = device_lookup_private(_cd, unit);
 
 	mutex_enter(>sc_lock);
 	mutex_spin_enter(_lock);



CVS commit: src/external/gpl3/gdb/dist/gdb/config/pa

2016-10-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct 27 11:48:24 UTC 2016

Removed Files:
src/external/gpl3/gdb/dist/gdb/config/pa: nbsd.mt

Log Message:
.mt files are dead


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r0 src/external/gpl3/gdb/dist/gdb/config/pa/nbsd.mt

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



CVS commit: src/tests/net/if_pppoe

2016-10-27 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 27 09:59:17 UTC 2016

Modified Files:
src/tests/net/if_pppoe: t_pppoe.sh

Log Message:
fix rarely rump.ping6 failures by "UDP connect". and fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/net/if_pppoe/t_pppoe.sh

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

Modified files:

Index: src/tests/net/if_pppoe/t_pppoe.sh
diff -u src/tests/net/if_pppoe/t_pppoe.sh:1.8 src/tests/net/if_pppoe/t_pppoe.sh:1.9
--- src/tests/net/if_pppoe/t_pppoe.sh:1.8	Wed Oct 26 03:55:56 2016
+++ src/tests/net/if_pppoe/t_pppoe.sh	Thu Oct 27 09:59:17 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_pppoe.sh,v 1.8 2016/10/26 03:55:56 knakahara Exp $
+#	$NetBSD: t_pppoe.sh,v 1.9 2016/10/27 09:59:17 knakahara Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -180,7 +180,7 @@ run_test()
 	atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
 	unset RUMP_SERVER
 
-	# test for recconecting
+	# test for reconnecting
 	export RUMP_SERVER=$CLIENT
 	atf_check -s exit:0 -x rump.ifconfig pppoe0 up
 	wait_for_session_established
@@ -189,6 +189,7 @@ run_test()
 	unset RUMP_SERVER
 
 	export RUMP_SERVER=$SERVER
+	atf_check -s exit:0 rump.ifconfig -w 10
 	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $CLIENT_IP
 	atf_check -s exit:0 -o match:'session' -x "$HIJACKING pppoectl -d pppoe0"
 	$DEBUG && HIJACKING pppoectl -d pppoe0
@@ -322,7 +323,7 @@ run_test6()
 	atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
 	unset RUMP_SERVER
 
-	# test for recconecting
+	# test for reconnecting
 	export RUMP_SERVER=$CLIENT
 	atf_check -s exit:0 rump.ifconfig pppoe0 up
 	wait_for_session_established
@@ -333,6 +334,7 @@ run_test6()
 	unset RUMP_SERVER
 
 	export RUMP_SERVER=$SERVER
+	atf_check -s exit:0 rump.ifconfig -w 10
 	atf_check -s exit:0 -o ignore rump.ping6 -c 1 -X $TIMEOUT $CLIENT_IP6
 	atf_check -s exit:0 -o match:'session' -x "$HIJACKING pppoectl -d pppoe0"
 	$DEBUG && HIJACKING pppoectl -d pppoe0



CVS commit: [nick-nhusb] src/sys/dev/usb

2016-10-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct 27 07:46:19 UTC 2016

Modified Files:
src/sys/dev/usb [nick-nhusb]: ucom.c ugen.c uhid.c umass.c umidi.c
usbdi_util.c usbdi_util.h

Log Message:
Retire usb_detach_{wait,broadcast} and simply use condvar(9) instead


To generate a diff of this commit:
cvs rdiff -u -r1.108.2.23 -r1.108.2.24 src/sys/dev/usb/ucom.c
cvs rdiff -u -r1.126.2.15 -r1.126.2.16 src/sys/dev/usb/ugen.c
cvs rdiff -u -r1.92.4.10 -r1.92.4.11 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.149.2.14 -r1.149.2.15 src/sys/dev/usb/umass.c
cvs rdiff -u -r1.65.14.12 -r1.65.14.13 src/sys/dev/usb/umidi.c
cvs rdiff -u -r1.63.2.13 -r1.63.2.14 src/sys/dev/usb/usbdi_util.c
cvs rdiff -u -r1.45.6.9 -r1.45.6.10 src/sys/dev/usb/usbdi_util.h

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

Modified files:

Index: src/sys/dev/usb/ucom.c
diff -u src/sys/dev/usb/ucom.c:1.108.2.23 src/sys/dev/usb/ucom.c:1.108.2.24
--- src/sys/dev/usb/ucom.c:1.108.2.23	Tue Oct 25 07:32:25 2016
+++ src/sys/dev/usb/ucom.c	Thu Oct 27 07:46:19 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucom.c,v 1.108.2.23 2016/10/25 07:32:25 skrll Exp $	*/
+/*	$NetBSD: ucom.c,v 1.108.2.24 2016/10/27 07:46:19 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.23 2016/10/25 07:32:25 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.108.2.24 2016/10/27 07:46:19 skrll Exp $");
 
 #include 
 #include 
@@ -440,7 +440,10 @@ ucom_detach(device_t self, int flags)
 			mutex_spin_exit(_lock);
 		}
 		/* Wait for processes to go away. */
-		usb_detach_wait(sc->sc_dev, >sc_detachcv, >sc_lock);
+		if (cv_timedwait(>sc_detachcv, >sc_lock, hz * 60)) {
+			printf("%s: %s didn't detach\n", __func__,
+			device_xname(sc->sc_dev));
+		}
 	}
 
 	softint_disestablish(sc->sc_si);
@@ -736,7 +739,7 @@ ucomclose(dev_t dev, int flag, int mode,
 		sc->sc_methods->ucom_close(sc->sc_parent, sc->sc_portno);
 
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detachcv);
+		cv_broadcast(>sc_detachcv);
 
 out:
 	sc->sc_closing = 0;
@@ -773,7 +776,7 @@ ucomread(dev_t dev, struct uio *uio, int
 
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detachcv);
+		cv_broadcast(>sc_detachcv);
 	mutex_exit(>sc_lock);
 
 	return error;
@@ -803,7 +806,7 @@ ucomwrite(dev_t dev, struct uio *uio, in
 
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detachcv);
+		cv_broadcast(>sc_detachcv);
 	mutex_exit(>sc_lock);
 
 	return error;
@@ -833,7 +836,7 @@ ucompoll(dev_t dev, int events, struct l
 
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detachcv);
+		cv_broadcast(>sc_detachcv);
 	mutex_exit(>sc_lock);
 
 	return revents;
@@ -869,7 +872,7 @@ ucomioctl(dev_t dev, u_long cmd, void *d
 
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detachcv);
+		cv_broadcast(>sc_detachcv);
 	mutex_exit(>sc_lock);
 
 	return error;

Index: src/sys/dev/usb/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.126.2.15 src/sys/dev/usb/ugen.c:1.126.2.16
--- src/sys/dev/usb/ugen.c:1.126.2.15	Sat Jul  9 20:25:16 2016
+++ src/sys/dev/usb/ugen.c	Thu Oct 27 07:46:19 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.126.2.15 2016/07/09 20:25:16 skrll Exp $	*/
+/*	$NetBSD: ugen.c,v 1.126.2.16 2016/10/27 07:46:19 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.126.2.15 2016/07/09 20:25:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.126.2.16 2016/10/27 07:46:19 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -812,7 +812,7 @@ ugenread(dev_t dev, struct uio *uio, int
 
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detach_cv);
+		cv_broadcast(>sc_detach_cv);
 	mutex_exit(>sc_lock);
 
 	return error;
@@ -1006,7 +1006,7 @@ ugenwrite(dev_t dev, struct uio *uio, in
 
 	mutex_enter(>sc_lock);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detach_cv);
+		cv_broadcast(>sc_detach_cv);
 	mutex_exit(>sc_lock);
 
 	return error;
@@ -1053,7 +1053,10 @@ ugen_detach(device_t self, int flags)
 		for (i = 0; i < USB_MAX_ENDPOINTS; i++)
 			cv_signal(>sc_endpoints[i][IN].cv);
 		/* Wait for processes to go away. */
-		usb_detach_wait(sc->sc_dev, >sc_detach_cv, >sc_lock);
+		if (cv_timedwait(>sc_detach_cv, >sc_lock, hz * 60)) {
+			printf("%s: %s didn't detach\n", __func__, 
+			device_xname(sc->sc_dev));
+		}
 	}
 	mutex_exit(>sc_lock);
 
@@ -1836,7 +1839,7 @@ ugenioctl(dev_t dev, u_long cmd, void *a
 	sc->sc_refcnt++;
 	error = ugen_do_ioctl(sc, endpt, cmd, addr, flag, l);
 	if (--sc->sc_refcnt < 0)
-		usb_detach_broadcast(sc->sc_dev, >sc_detach_cv);
+