CVS commit: src/sys/dev/usb

2021-07-15 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Jul 15 15:23:46 UTC 2021

Modified Files:
src/sys/dev/usb: if_mue.c

Log Message:
back out the previous accidental commit


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/usb/if_mue.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/if_mue.c
diff -u src/sys/dev/usb/if_mue.c:1.61 src/sys/dev/usb/if_mue.c:1.62
--- src/sys/dev/usb/if_mue.c:1.61	Thu Jul 15 03:25:50 2021
+++ src/sys/dev/usb/if_mue.c	Thu Jul 15 15:23:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mue.c,v 1.61 2021/07/15 03:25:50 nisimura Exp $	*/
+/*	$NetBSD: if_mue.c,v 1.62 2021/07/15 15:23:46 nisimura Exp $	*/
 /*	$OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $	*/
 
 /*
@@ -20,7 +20,7 @@
 /* Driver for Microchip LAN7500/LAN7800 chipsets. */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.61 2021/07/15 03:25:50 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.62 2021/07/15 15:23:46 nisimura Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -98,7 +98,7 @@ static void	mue_setmtu_locked(struct usb
 static void	mue_reset(struct usbnet *);
 
 static void	mue_uno_stop(struct ifnet *, int);
-static int	mue_uno_override_ioctl(struct ifnet *, u_long, void *);
+static int	mue_uno_ioctl(struct ifnet *, u_long, void *);
 static int	mue_uno_mii_read_reg(struct usbnet *, int, int, uint16_t *);
 static int	mue_uno_mii_write_reg(struct usbnet *, int, int, uint16_t);
 static void	mue_uno_mii_statchg(struct ifnet *);
@@ -110,7 +110,7 @@ static int	mue_uno_init(struct ifnet *);
 
 static const struct usbnet_ops mue_ops = {
 	.uno_stop = mue_uno_stop,
-	.uno_override_ioctl = mue_uno_override_ioctl,
+	.uno_ioctl = mue_uno_ioctl,
 	.uno_read_reg = mue_uno_mii_read_reg,
 	.uno_write_reg = mue_uno_mii_write_reg,
 	.uno_statchg = mue_uno_mii_statchg,
@@ -137,14 +137,7 @@ static const struct usbnet_ops mue_ops =
 #define ETHER_IS_ZERO(addr) \
 	(!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]))
 
-struct mue_softc {
-	struct usbnet	   sc_un;
-	struct usbnet_intr sc_intr;
-	uint8_t sc_ibuf[8];
-	unsigned sc_flowflags;		/* 802.3x PAUSE flow control */
-};
-
-CFATTACH_DECL_NEW(mue, sizeof(struct mue_softc), mue_match, mue_attach,
+CFATTACH_DECL_NEW(mue, sizeof(struct usbnet), mue_match, mue_attach,
 usbnet_detach, usbnet_activate);
 
 static uint32_t
@@ -767,15 +760,14 @@ static void
 mue_attach(device_t parent, device_t self, void *aux)
 {
 	USBNET_MII_DECL_DEFAULT(unm);
+	struct usbnet * const un = device_private(self);
 	prop_dictionary_t dict = device_properties(self);
-	struct mue_softc * const sc = device_private(self);
 	struct usb_attach_arg *uaa = aux;
 	struct usbd_device *dev = uaa->uaa_device;
-	struct usbnet *un = >sc_un;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	usbd_status err;
 	char *devinfop;
+	usbd_status err;
 	const char *descr;
 	uint32_t id_rev;
 	uint8_t i;
@@ -790,7 +782,7 @@ mue_attach(device_t parent, device_t sel
 
 	un->un_dev = self;
 	un->un_udev = dev;
-	un->un_sc = sc; /* @@! */
+	un->un_sc = un;
 	un->un_ops = _ops;
 	un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
 	un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
@@ -892,8 +884,6 @@ mue_attach(device_t parent, device_t sel
 	ec->ec_capabilities = ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU;
 #endif
 
-	unm.un_mii_phyloc = un->un_phyno;	/* use internal PHY 1 */
-	unm.un_mii_flags |= MIIF_DOPAUSE;	/* use PAUSE cap. */
 	usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
 	0, );
 }
@@ -1007,93 +997,90 @@ mue_setiff_locked(struct usbnet *un)
 {
 	struct ethercom *ec = usbnet_ec(un);
 	struct ifnet * const ifp = usbnet_ifp(un);
-	struct ether_multistep step;
+	const uint8_t *enaddr = CLLADDR(ifp->if_sadl);
 	struct ether_multi *enm;
-	uint32_t mchash[MUE_DP_SEL_VHF_HASH_LEN];
-	uint32_t rfe, rxfilt, crc, hireg, loreg;
+	struct ether_multistep step;
+	uint32_t pfiltbl[MUE_NUM_ADDR_FILTX][2];
+	uint32_t hashtbl[MUE_DP_SEL_VHF_HASH_LEN];
+	uint32_t reg, rxfilt, h, hireg, loreg;
 	size_t i;
 
 	if (usbnet_isdying(un))
 		return;
 
-	for (i = 1; i < MUE_NUM_ADDR_FILTX; i++) {
-		hireg = (un->un_flags & LAN7500)
-		? MUE_7500_ADDR_FILTX(i) : MUE_7800_ADDR_FILTX(i);
-		mue_csr_write(un, hireg, 0);
-	}
-	memset(mchash, 0, sizeof(mchash));
+	/* Clear perfect filter and hash tables. */
+	memset(pfiltbl, 0, sizeof(pfiltbl));
+	memset(hashtbl, 0, sizeof(hashtbl));
 
-	rfe = (un->un_flags & LAN7500) ? MUE_7500_RFE_CTL : MUE_7800_RFE_CTL;
-	rxfilt = mue_csr_read(un, rfe);
-	rxfilt &= ~(MUE_RFE_CTL_MULTICAST_HASH |
+	reg = (un->un_flags & LAN7500) ? MUE_7500_RFE_CTL : MUE_7800_RFE_CTL;
+	rxfilt = mue_csr_read(un, reg);
+	rxfilt &= ~(MUE_RFE_CTL_PERFECT | MUE_RFE_CTL_MULTICAST_HASH |
 	MUE_RFE_CTL_UNICAST | MUE_RFE_CTL_MULTICAST);
 
-	ETHER_LOCK(ec);
+	/* Always accept broadcast frames. */
+	rxfilt |= MUE_RFE_CTL_BROADCAST;
+
 

CVS commit: src/sys/dev/usb

2021-07-14 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Jul 15 03:25:50 UTC 2021

Modified Files:
src/sys/dev/usb: if_mue.c uchcom.c

Log Message:
explanation typo


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/usb/if_mue.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/usb/uchcom.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/if_mue.c
diff -u src/sys/dev/usb/if_mue.c:1.60 src/sys/dev/usb/if_mue.c:1.61
--- src/sys/dev/usb/if_mue.c:1.60	Sat Jun 27 13:33:26 2020
+++ src/sys/dev/usb/if_mue.c	Thu Jul 15 03:25:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mue.c,v 1.60 2020/06/27 13:33:26 jmcneill Exp $	*/
+/*	$NetBSD: if_mue.c,v 1.61 2021/07/15 03:25:50 nisimura Exp $	*/
 /*	$OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $	*/
 
 /*
@@ -20,7 +20,7 @@
 /* Driver for Microchip LAN7500/LAN7800 chipsets. */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.60 2020/06/27 13:33:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.61 2021/07/15 03:25:50 nisimura Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -98,7 +98,7 @@ static void	mue_setmtu_locked(struct usb
 static void	mue_reset(struct usbnet *);
 
 static void	mue_uno_stop(struct ifnet *, int);
-static int	mue_uno_ioctl(struct ifnet *, u_long, void *);
+static int	mue_uno_override_ioctl(struct ifnet *, u_long, void *);
 static int	mue_uno_mii_read_reg(struct usbnet *, int, int, uint16_t *);
 static int	mue_uno_mii_write_reg(struct usbnet *, int, int, uint16_t);
 static void	mue_uno_mii_statchg(struct ifnet *);
@@ -110,7 +110,7 @@ static int	mue_uno_init(struct ifnet *);
 
 static const struct usbnet_ops mue_ops = {
 	.uno_stop = mue_uno_stop,
-	.uno_ioctl = mue_uno_ioctl,
+	.uno_override_ioctl = mue_uno_override_ioctl,
 	.uno_read_reg = mue_uno_mii_read_reg,
 	.uno_write_reg = mue_uno_mii_write_reg,
 	.uno_statchg = mue_uno_mii_statchg,
@@ -137,7 +137,14 @@ static const struct usbnet_ops mue_ops =
 #define ETHER_IS_ZERO(addr) \
 	(!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]))
 
-CFATTACH_DECL_NEW(mue, sizeof(struct usbnet), mue_match, mue_attach,
+struct mue_softc {
+	struct usbnet	   sc_un;
+	struct usbnet_intr sc_intr;
+	uint8_t sc_ibuf[8];
+	unsigned sc_flowflags;		/* 802.3x PAUSE flow control */
+};
+
+CFATTACH_DECL_NEW(mue, sizeof(struct mue_softc), mue_match, mue_attach,
 usbnet_detach, usbnet_activate);
 
 static uint32_t
@@ -760,14 +767,15 @@ static void
 mue_attach(device_t parent, device_t self, void *aux)
 {
 	USBNET_MII_DECL_DEFAULT(unm);
-	struct usbnet * const un = device_private(self);
 	prop_dictionary_t dict = device_properties(self);
+	struct mue_softc * const sc = device_private(self);
 	struct usb_attach_arg *uaa = aux;
 	struct usbd_device *dev = uaa->uaa_device;
+	struct usbnet *un = >sc_un;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
-	char *devinfop;
 	usbd_status err;
+	char *devinfop;
 	const char *descr;
 	uint32_t id_rev;
 	uint8_t i;
@@ -782,7 +790,7 @@ mue_attach(device_t parent, device_t sel
 
 	un->un_dev = self;
 	un->un_udev = dev;
-	un->un_sc = un;
+	un->un_sc = sc; /* @@! */
 	un->un_ops = _ops;
 	un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
 	un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
@@ -884,6 +892,8 @@ mue_attach(device_t parent, device_t sel
 	ec->ec_capabilities = ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU;
 #endif
 
+	unm.un_mii_phyloc = un->un_phyno;	/* use internal PHY 1 */
+	unm.un_mii_flags |= MIIF_DOPAUSE;	/* use PAUSE cap. */
 	usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
 	0, );
 }
@@ -997,90 +1007,93 @@ mue_setiff_locked(struct usbnet *un)
 {
 	struct ethercom *ec = usbnet_ec(un);
 	struct ifnet * const ifp = usbnet_ifp(un);
-	const uint8_t *enaddr = CLLADDR(ifp->if_sadl);
-	struct ether_multi *enm;
 	struct ether_multistep step;
-	uint32_t pfiltbl[MUE_NUM_ADDR_FILTX][2];
-	uint32_t hashtbl[MUE_DP_SEL_VHF_HASH_LEN];
-	uint32_t reg, rxfilt, h, hireg, loreg;
+	struct ether_multi *enm;
+	uint32_t mchash[MUE_DP_SEL_VHF_HASH_LEN];
+	uint32_t rfe, rxfilt, crc, hireg, loreg;
 	size_t i;
 
 	if (usbnet_isdying(un))
 		return;
 
-	/* Clear perfect filter and hash tables. */
-	memset(pfiltbl, 0, sizeof(pfiltbl));
-	memset(hashtbl, 0, sizeof(hashtbl));
+	for (i = 1; i < MUE_NUM_ADDR_FILTX; i++) {
+		hireg = (un->un_flags & LAN7500)
+		? MUE_7500_ADDR_FILTX(i) : MUE_7800_ADDR_FILTX(i);
+		mue_csr_write(un, hireg, 0);
+	}
+	memset(mchash, 0, sizeof(mchash));
 
-	reg = (un->un_flags & LAN7500) ? MUE_7500_RFE_CTL : MUE_7800_RFE_CTL;
-	rxfilt = mue_csr_read(un, reg);
-	rxfilt &= ~(MUE_RFE_CTL_PERFECT | MUE_RFE_CTL_MULTICAST_HASH |
+	rfe = (un->un_flags & LAN7500) ? MUE_7500_RFE_CTL : MUE_7800_RFE_CTL;
+	rxfilt = mue_csr_read(un, rfe);
+	rxfilt &= ~(MUE_RFE_CTL_MULTICAST_HASH |
 	MUE_RFE_CTL_UNICAST | MUE_RFE_CTL_MULTICAST);
 
-	/* Always accept broadcast frames. */
-	rxfilt |= 

CVS commit: src/sys/dev/usb

2021-07-14 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Wed Jul 14 07:34:16 UTC 2021

Modified Files:
src/sys/dev/usb: uchcom.c

Log Message:
The second REQ_RESET USB request by reset_chip() makes LCR, PRE and DIV
registers to have default values 8N1 and 19200 just as the first req does.
Nuke reset_chip() and rundandant set_dte_rate() to amend.
While here added some narrative about prescale/divisor calculation.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/usb/uchcom.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/uchcom.c
diff -u src/sys/dev/usb/uchcom.c:1.37 src/sys/dev/usb/uchcom.c:1.38
--- src/sys/dev/usb/uchcom.c:1.37	Sat Apr 24 23:36:59 2021
+++ src/sys/dev/usb/uchcom.c	Wed Jul 14 07:34:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uchcom.c,v 1.37 2021/04/24 23:36:59 thorpej Exp $	*/
+/*	$NetBSD: uchcom.c,v 1.38 2021/07/14 07:34:16 nisimura Exp $	*/
 
 /*
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uchcom.c,v 1.37 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uchcom.c,v 1.38 2021/07/14 07:34:16 nisimura Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -118,9 +118,6 @@ int	uchcomdebug = 0;
 #define UCHCOMIBUFSIZE 256
 #define UCHCOMOBUFSIZE 256
 
-#define UCHCOM_RESET_VALUE	0x501F
-#define UCHCOM_RESET_INDEX	0xD90A
-
 struct uchcom_softc
 {
 	device_t		sc_dev;
@@ -155,6 +152,7 @@ struct uchcom_divider
 	uint8_t		dv_div;
 };
 
+/* 0,1,2,3,7 are prescale factors for given 4x 1200 clock formula */
 static const uint32_t rates4x[8] = {
 	[0] = 4 * 1200 / 1024,
 	[1] = 4 * 1200 / 128,
@@ -618,6 +616,24 @@ set_break(struct uchcom_softc *sc, int o
 static int
 calc_divider_settings(struct uchcom_divider *dp, uint32_t rate)
 {
+/*
+ * combined with rates4x[] defined above, this routine generates,
+ *   1200: prescale = 1/0x1, divisor = 178/0xb2
+ *   2400: prescale = 1/0x1, divisor = 217/0xd9
+ *   4800: prescale = 2/0x2, divisor = 100/0x64
+ *   9600: prescale = 2/0x2, divisor = 178/0xb2
+ *  19200: prescale = 2/0x2, divisor = 217/0xd9
+ *  38400: prescale = 3/0x3, divisor = 100/0x64
+ *  57600: prescale = 2/0x2, divisor = 243/0xf3
+ * 115200: prescale = 3/0x3, divisor = 204/0xcc
+ * 921600: prescale = 7/0x7, divisor = 243/0xf3
+ * 50: prescale = 3/0x3, divisor = 244/0xf4
+ * 100: prescale = 3/0x3, divisor = 250/0xfa
+ * 150: prescale = 3/0x3, divisor = 252/0xfc
+ * 200: prescale = 3/0x3, divisor = 253/0xfd
+ * 250: unsupported
+ * 300: prescale = 3/0x3, divisor = 254/0xfe
+ */
 	size_t i;
 	uint32_t best, div, pre;
 	const uint32_t rate4x = rate * 4U;
@@ -652,7 +668,7 @@ calc_divider_settings(struct uchcom_divi
 		return -1;
 
 	dp->dv_prescaler = pre;
-	dp->dv_div = (uint8_t)-div;
+	dp->dv_div = 256 - div;
 
 	return 0;
 }
@@ -740,26 +756,12 @@ clear_chip(struct uchcom_softc *sc)
 		usbd_errstr(err));
 		return EIO;
 	}
-
-	return 0;
-}
-
-static int
-reset_chip(struct uchcom_softc *sc)
-{
-	usbd_status err;
-
-	err = generic_control_out(sc, UCHCOM_REQ_RESET,
-	UCHCOM_RESET_VALUE, UCHCOM_RESET_INDEX);
-	if (err)
-		goto failed;
-
+	/*
+	 * this REQ_RESET call ends up with
+	 * LCR=0xc0 (8N1)
+	 * PRE=0x02, DIV=0xb2 (19200)
+	 */
 	return 0;
-
-failed:
-	printf("%s: cannot reset: %s\n",
-	   device_xname(sc->sc_dev), usbd_errstr(err));
-	return EIO;
 }
 
 static int
@@ -787,14 +789,6 @@ setup_comm(struct uchcom_softc *sc)
 	if (ret)
 		return ret;
 
-	ret = reset_chip(sc);
-	if (ret)
-		return ret;
-
-	ret = set_dte_rate(sc, TTYDEF_SPEED); /* XXX */
-	if (ret)
-		return ret;
-
 	sc->sc_dtr = sc->sc_rts = 1;
 	ret = set_dtrrts(sc, sc->sc_dtr, sc->sc_rts);
 	if (ret)



CVS commit: src/sys/dev/usb

2021-06-27 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Jun 27 22:41:55 UTC 2021

Modified Files:
src/sys/dev/usb: ukbd.c

Log Message:
Since there's a bit of code that is conditionally compiled based on
USBVERBOSE, we need to include the opt_usbverbose.h header to get any
possible definition of this macro.

XXX Note that this code will NOT get included in the loadable module
XXX for USBVERBOSE.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/dev/usb/ukbd.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/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.150 src/sys/dev/usb/ukbd.c:1.151
--- src/sys/dev/usb/ukbd.c:1.150	Sat Apr 24 23:36:59 2021
+++ src/sys/dev/usb/ukbd.c	Sun Jun 27 22:41:55 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: ukbd.c,v 1.150 2021/04/24 23:36:59 thorpej Exp $*/
+/*  $NetBSD: ukbd.c,v 1.151 2021/06/27 22:41:55 pgoyette Exp $*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,13 +35,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.150 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.151 2021/06/27 22:41:55 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
 #include "opt_ukbd.h"
 #include "opt_ukbd_layout.h"
 #include "opt_usb.h"
+#include "opt_usbverbose.h"
 #include "opt_wsdisplay_compat.h"
 #endif /* _KERNEL_OPT */
 



CVS commit: src/sys/dev/usb

2021-06-24 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Jun 24 23:01:37 UTC 2021

Modified Files:
src/sys/dev/usb: usbnet.h

Log Message:
clarify some comments about what the "send callback" is.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/usb/usbnet.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/usbnet.h
diff -u src/sys/dev/usb/usbnet.h:1.20 src/sys/dev/usb/usbnet.h:1.21
--- src/sys/dev/usb/usbnet.h:1.20	Mon Mar  1 22:59:52 2021
+++ src/sys/dev/usb/usbnet.h	Thu Jun 24 23:01:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.h,v 1.20 2021/03/01 22:59:52 mrg Exp $	*/
+/*	$NetBSD: usbnet.h,v 1.21 2021/06/24 23:01:36 mrg Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -59,7 +59,7 @@
  *   - ioctl can use either a device-specific override (useful for special
  * cases), but provides a normal handler with callback to handle
  * ENETRESET conditions that should be sufficient for most users
- *   - start uses usbnet send callback
+ *   - start uses usbnet transmit prepare callback (uno_tx_prepare)
  * - interface init and stop have helper functions
  *   - device specific init should use usbnet_init_rx_tx() to open pipes
  * to the device and setup the rx/tx chains for use after any device
@@ -73,9 +73,9 @@
  * packets, which can use usbnet_enqueue() to provide data to the
  * higher layers
  *   - for tx, usbnet_start (if_start) will pull entries out of the
- * transmit queue and use the send callback for the given mbuf.
- * the usb callback will use usbnet_txeof() for the transmit
- * completion function (internal to usbnet)
+ * transmit queue and use the transmit prepare callback (uno_tx_prepare)
+ * for the given mbuf.  the usb callback will use usbnet_txeof() for
+ * the transmit completion function (internal to usbnet)
  *   - there is special interrupt pipe handling
  * - timer/tick:
  *   - the uno_tick callback will be called once a second if present.



CVS commit: src/sys/dev/usb

2021-06-24 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Jun 24 23:01:03 UTC 2021

Modified Files:
src/sys/dev/usb: ohci.c

Log Message:
turn off ohcidebug by default.  none of the other HCs do this.

next up:  options to set these by default


To generate a diff of this commit:
cvs rdiff -u -r1.316 -r1.317 src/sys/dev/usb/ohci.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/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.316 src/sys/dev/usb/ohci.c:1.317
--- src/sys/dev/usb/ohci.c:1.316	Tue Jun 15 23:39:43 2021
+++ src/sys/dev/usb/ohci.c	Thu Jun 24 23:01:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.316 2021/06/15 23:39:43 riastradh Exp $	*/
+/*	$NetBSD: ohci.c,v 1.317 2021/06/24 23:01:03 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012, 2016, 2020 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.316 2021/06/15 23:39:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.317 2021/06/24 23:01:03 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -77,7 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.3
 #ifndef OHCI_DEBUG
 #define ohcidebug 0
 #else
-static int ohcidebug = 10;
+static int ohcidebug = 0;
 
 SYSCTL_SETUP(sysctl_hw_ohci_setup, "sysctl hw.ohci setup")
 {



CVS commit: src/sys/dev/usb

2021-06-24 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Jun 24 23:00:14 UTC 2021

Modified Files:
src/sys/dev/usb: TODO.usbmp

Log Message:
update a couple of lists of drivers that have had a few changes


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

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/TODO.usbmp
diff -u src/sys/dev/usb/TODO.usbmp:1.19 src/sys/dev/usb/TODO.usbmp:1.20
--- src/sys/dev/usb/TODO.usbmp:1.19	Sat May 16 13:46:12 2020
+++ src/sys/dev/usb/TODO.usbmp	Thu Jun 24 23:00:14 2021
@@ -1,4 +1,4 @@
-$NetBSD: TODO.usbmp,v 1.19 2020/05/16 13:46:12 maya Exp $
+$NetBSD: TODO.usbmp,v 1.20 2021/06/24 23:00:14 mrg Exp $
 
 
 the majority of the USB MP device interface is documented in usbdivar.h.
@@ -20,20 +20,17 @@ KERNEL_LOCK
 
 usb_detach_{waitold,wakeup} to usb_detach_{wait,broadcast} conversion:
   - drivers:
-  if_aue.c
-  stuirda.c
-  ubt.c
-  ucom.c
-  ucycom.c
-  udsir.c
-  uhso.c
-  uirda.c
-  ulpt.c
-  umass.c		- done, partially done -- need to check umass_scsipi.c change
-  uscanner.c
-  usscanner.c
-  ustir.c
-  utoppy.c
+  - stuirda.c
+  - ubt.c
+  - ucycom.c
+  - udsir.c
+  - uhso.c
+  - uirda.c
+  - ulpt.c
+  - uscanner.c
+  - usscanner.c
+  - ustir.c
+  - utoppy.c
 
 
 use usb_delay_ms_locked() in places
@@ -81,20 +78,18 @@ splusb drivers to convert:
   - uvideo.c
 
 wakeup/tsleep drivers:
-  - if_otus.c
+  - if_rum.c
   - if_run.c
   - if_upgt.c
-  - if_urtwn.c
-  - if_zyd.c
-  - ucom.c
+  - if_ural.c
   - ucycom.c
   - udsir.c
   - uirda.c
-  - ulpt.c
-  - umass_isdata.c
+  - umcs.h
+  - usb.c
+  - usb_subr.c
+  - usbdi.c
   - ustir.c
-  - uthum.c
-  - uvscom.c
 
 missing D_MPSAFE drivers:
   - ucom



CVS commit: src/sys/dev/usb

2021-06-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Jun 24 08:20:42 UTC 2021

Modified Files:
src/sys/dev/usb: ucom.c

Log Message:
ucom(4): Fix earlier mistake causing pipes not to be closed.

In revision 1.123, mrg@ changed what he thought was a double-close,
but was actually abort (as is appropriate) to just abort (which
is not enough -- leaks the pipe).  This restores the abort

The original `bug' was found by code inspection, whereas this bug was
found by asserting in usb_subr.c that no pipes are open on device
disconnection after detach; the asserts actually triggered with
several ucom(4) devices, and no longer trigger with this change.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 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.128 src/sys/dev/usb/ucom.c:1.129
--- src/sys/dev/usb/ucom.c:1.128	Mon Oct 26 12:24:10 2020
+++ src/sys/dev/usb/ucom.c	Thu Jun 24 08:20:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucom.c,v 1.128 2020/10/26 12:24:10 mrg Exp $	*/
+/*	$NetBSD: ucom.c,v 1.129 2021/06/24 08:20:42 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.128 2020/10/26 12:24:10 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.129 2021/06/24 08:20:42 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -414,11 +414,9 @@ ucom_detach(device_t self, int flags)
 
 	if (sc->sc_bulkin_pipe != NULL) {
 		usbd_abort_pipe(sc->sc_bulkin_pipe);
-		sc->sc_bulkin_pipe = NULL;
 	}
 	if (sc->sc_bulkout_pipe != NULL) {
 		usbd_abort_pipe(sc->sc_bulkout_pipe);
-		sc->sc_bulkout_pipe = NULL;
 	}
 
 	mutex_enter(>sc_lock);



CVS commit: src/sys/dev/usb

2021-06-18 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jun 19 05:50:48 UTC 2021

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Relax identification of interfaces and endpoints. Now also attaches
headsets like Jabra Evolve 75.


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/sys/dev/usb/uaudio.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/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.171 src/sys/dev/usb/uaudio.c:1.172
--- src/sys/dev/usb/uaudio.c:1.171	Sun Jun 13 07:51:09 2021
+++ src/sys/dev/usb/uaudio.c	Sat Jun 19 05:50:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.171 2021/06/13 07:51:09 mlelstv Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.172 2021/06/19 05:50:48 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.171 2021/06/13 07:51:09 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.172 2021/06/19 05:50:48 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -561,8 +561,14 @@ uaudio_find_iface(const char *tbuf, int 
 {
 	const usb_interface_descriptor_t *d;
 
-	while (*offsp < size) {
+	while (*offsp + sizeof(*d) <= size) {
 		d = (const void *)(tbuf + *offsp);
+		DPRINTFN(3, "%d + %d <= %d type %d class %d/%d iface %d\n",
+		*offsp, d->bLength, size,
+		d->bDescriptorType,
+		d->bInterfaceClass,
+		d->bInterfaceSubClass,
+		d->bInterfaceNumber);
 		*offsp += d->bLength;
 		if (d->bDescriptorType == UDESC_INTERFACE &&
 		d->bInterfaceClass == UICLASS_AUDIO &&
@@ -1533,7 +1539,6 @@ uaudio_add_alt(struct uaudio_softc *sc, 
 Static usbd_status
 uaudio_process_as(struct uaudio_softc *sc, const char *tbuf, int *offsp,
 		  int size, const usb_interface_descriptor_t *id)
-#define offs (*offsp)
 {
 	const struct usb_audio_streaming_interface_descriptor *asid;
 	const struct usb_audio_streaming_type1_descriptor *asf1d;
@@ -1541,55 +1546,151 @@ uaudio_process_as(struct uaudio_softc *s
 	const usb_endpoint_descriptor_audio_t *epdesc1;
 	const struct usb_audio_streaming_endpoint_descriptor *sed;
 	int format, chan __unused, prec, enc;
-	int dir, type, sync;
+	int dir, type, sync, epcount;
 	struct as_info ai;
 	const char *format_str __unused;
+	const uaudio_cs_descriptor_t *desc;
 
-	asid = (const void *)(tbuf + offs);
-	if (asid->bDescriptorType != UDESC_CS_INTERFACE ||
-	asid->bDescriptorSubtype != AS_GENERAL)
-		return USBD_INVAL;
-	DPRINTF("asid: bTerminalLink=%d wFormatTag=%d\n",
-		 asid->bTerminalLink, UGETW(asid->wFormatTag));
-	offs += asid->bLength;
-	if (offs > size)
-		return USBD_INVAL;
+	DPRINTF("offset = %d < %d\n", *offsp, size);
 
-	asf1d = (const void *)(tbuf + offs);
-	if (asf1d->bDescriptorType != UDESC_CS_INTERFACE ||
-	asf1d->bDescriptorSubtype != FORMAT_TYPE)
-		return USBD_INVAL;
-	offs += asf1d->bLength;
-	if (offs > size)
-		return USBD_INVAL;
+	epcount = 0;
+	asid = NULL;
+	asf1d = NULL;
+	ed = NULL;
+	epdesc1 = NULL;
+	sed = NULL;
 
-	if (asf1d->bFormatType != FORMAT_TYPE_I) {
-		aprint_normal_dev(sc->sc_dev,
-		"ignored setting with type %d format\n", UGETW(asid->wFormatTag));
-		return USBD_NORMAL_COMPLETION;
+	while (*offsp < size) {
+		desc = (const uaudio_cs_descriptor_t *)(tbuf + *offsp);
+		if (*offsp + desc->bLength > size)
+			return USBD_INVAL;
+
+		switch (desc->bDescriptorType) {
+		case UDESC_CS_INTERFACE:
+			switch (desc->bDescriptorSubtype) {
+			case AS_GENERAL:
+if (asid != NULL)
+	goto ignore;
+asid = (const struct usb_audio_streaming_interface_descriptor *) desc;
+DPRINTF("asid: bTerminalLink=%d wFormatTag=%d bLength=%d\n",
+	 asid->bTerminalLink, UGETW(asid->wFormatTag), asid->bLength);
+break;
+			case FORMAT_TYPE:
+if (asf1d != NULL)
+	goto ignore;
+asf1d = (const struct usb_audio_streaming_type1_descriptor *) desc;
+DPRINTF("asf1d: bDescriptorType=%d bDescriptorSubtype=%d\n",
+ asf1d->bDescriptorType, asf1d->bDescriptorSubtype);
+if (asf1d->bFormatType != FORMAT_TYPE_I) {
+	aprint_normal_dev(sc->sc_dev,
+	"ignored setting with type %d format\n", UGETW(asid->wFormatTag));
+	return USBD_NORMAL_COMPLETION;
+}
+break;
+			default:
+goto ignore;
+			}
+			break;
+		case UDESC_ENDPOINT:
+			epcount++;
+			if (epcount > id->bNumEndpoints)
+goto ignore;
+			switch (epcount) {
+			case 1:
+ed = (const usb_endpoint_descriptor_audio_t *) desc;
+DPRINTF("endpoint[0] bLength=%d bDescriptorType=%d "
+	 "bEndpointAddress=%d bmAttributes=%#x wMaxPacketSize=%d "
+	 "bInterval=%d bRefresh=%d bSynchAddress=%d\n",
+	 ed->bLength, ed->bDescriptorType, ed->bEndpointAddress,
+	 ed->bmAttributes, UGETW(ed->wMaxPacketSize),
+	 ed->bInterval, ed->bRefresh, ed->bSynchAddress);
+if (UE_GET_XFERTYPE(ed->bmAttributes) != UE_ISOCHRONOUS)
+	return USBD_INVAL;
+			

CVS commit: src/sys/dev/usb

2021-06-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jun 16 13:20:49 UTC 2021

Modified Files:
src/sys/dev/usb: usbdi.c

Log Message:
usb(4): Fix uninitialized variable for error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/sys/dev/usb/usbdi.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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.217 src/sys/dev/usb/usbdi.c:1.218
--- src/sys/dev/usb/usbdi.c:1.217	Mon Jun 14 15:35:34 2021
+++ src/sys/dev/usb/usbdi.c	Wed Jun 16 13:20:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.217 2021/06/14 15:35:34 mlelstv Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.218 2021/06/16 13:20:49 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.217 2021/06/14 15:35:34 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.218 2021/06/16 13:20:49 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -223,7 +223,7 @@ usbd_status
 usbd_open_pipe_ival(struct usbd_interface *iface, uint8_t address,
 		uint8_t flags, struct usbd_pipe **pipe, int ival)
 {
-	struct usbd_pipe *p;
+	struct usbd_pipe *p = NULL;
 	struct usbd_endpoint *ep = NULL /* XXXGCC */;
 	bool piperef = false;
 	usbd_status err;



CVS commit: src/sys/dev/usb

2021-06-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 15 23:39:43 UTC 2021

Modified Files:
src/sys/dev/usb: ohci.c

Log Message:
ohci(4): Constify a constant debug string table.


To generate a diff of this commit:
cvs rdiff -u -r1.315 -r1.316 src/sys/dev/usb/ohci.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/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.315 src/sys/dev/usb/ohci.c:1.316
--- src/sys/dev/usb/ohci.c:1.315	Tue Jan  5 18:00:21 2021
+++ src/sys/dev/usb/ohci.c	Tue Jun 15 23:39:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.315 2021/01/05 18:00:21 skrll Exp $	*/
+/*	$NetBSD: ohci.c,v 1.316 2021/06/15 23:39:43 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012, 2016, 2020 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.315 2021/01/05 18:00:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.316 2021/06/15 23:39:43 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1403,7 +1403,7 @@ ohci_rhsc_enable(void *v_sc)
 }
 
 #ifdef OHCI_DEBUG
-const char *ohci_cc_strs[] = {
+const char *const ohci_cc_strs[] = {
 	"NO_ERROR",
 	"CRC",
 	"BIT_STUFFING",



CVS commit: src/sys/dev/usb

2021-06-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Jun 14 15:35:34 UTC 2021

Modified Files:
src/sys/dev/usb: usbdi.c

Log Message:
appease gcc9


To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 src/sys/dev/usb/usbdi.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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.216 src/sys/dev/usb/usbdi.c:1.217
--- src/sys/dev/usb/usbdi.c:1.216	Sun Jun 13 00:13:24 2021
+++ src/sys/dev/usb/usbdi.c	Mon Jun 14 15:35:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.216 2021/06/13 00:13:24 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.217 2021/06/14 15:35:34 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.216 2021/06/13 00:13:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.217 2021/06/14 15:35:34 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -224,7 +224,7 @@ usbd_open_pipe_ival(struct usbd_interfac
 		uint8_t flags, struct usbd_pipe **pipe, int ival)
 {
 	struct usbd_pipe *p;
-	struct usbd_endpoint *ep;
+	struct usbd_endpoint *ep = NULL /* XXXGCC */;
 	bool piperef = false;
 	usbd_status err;
 	int i;



CVS commit: src/sys/dev/usb

2021-06-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 13 14:48:10 UTC 2021

Modified Files:
src/sys/dev/usb: uhub.c usb.c usb_subr.c usbdi.h

Log Message:
usb(4): Bus exploration is single-threaded -- assert it so.

New usb_in_event_thread(dev) returns true if dev is a USB device --
that is, a device with a usbN ancestor -- and the current thread is
the USB event thread.

(Kinda kludgey to pass around the device_t instead of, say, struct
usbd_bus, but I don't see a good way to get to the usbN device_t or
struct usb_softc from there.)


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.195 -r1.196 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.264 -r1.265 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.102 -r1.103 src/sys/dev/usb/usbdi.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/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.152 src/sys/dev/usb/uhub.c:1.153
--- src/sys/dev/usb/uhub.c:1.152	Sun Jun 13 14:46:07 2021
+++ src/sys/dev/usb/uhub.c	Sun Jun 13 14:48:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.152 2021/06/13 14:46:07 riastradh Exp $	*/
+/*	$NetBSD: uhub.c,v 1.153 2021/06/13 14:48:10 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.152 2021/06/13 14:46:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.153 2021/06/13 14:48:10 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -269,10 +269,12 @@ uhub_attach(device_t parent, device_t se
 	usb_endpoint_descriptor_t *ed;
 	struct usbd_tt *tts = NULL;
 
-	config_pending_incr(self);
-
 	UHUBHIST_FUNC(); UHUBHIST_CALLED();
 
+	KASSERT(usb_in_event_thread(parent));
+
+	config_pending_incr(self);
+
 	sc->sc_dev = self;
 	sc->sc_hub = dev;
 	sc->sc_proto = uaa->uaa_proto;
@@ -498,7 +500,7 @@ uhub_explore(struct usbd_device *dev)
 	device_unit(sc->sc_dev), (uintptr_t)dev, dev->ud_addr,
 	dev->ud_speed);
 
-	KASSERT(KERNEL_LOCKED_P());
+	KASSERT(usb_in_event_thread(sc->sc_dev));
 
 	if (!sc->sc_running)
 		return USBD_NOT_STARTED;

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.195 src/sys/dev/usb/usb.c:1.196
--- src/sys/dev/usb/usb.c:1.195	Sat Jun 12 12:13:10 2021
+++ src/sys/dev/usb/usb.c	Sun Jun 13 14:48:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.195 2021/06/12 12:13:10 riastradh Exp $	*/
+/*	$NetBSD: usb.c,v 1.196 2021/06/13 14:48:10 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.195 2021/06/12 12:13:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.196 2021/06/13 14:48:10 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -142,6 +142,7 @@ struct usb_softc {
 	struct usbd_port sc_port;	/* dummy port for root hub */
 
 	struct lwp	*sc_event_thread;
+	struct lwp	*sc_attach_thread;
 
 	char		sc_dying;
 	bool		sc_pmf_registered;
@@ -483,8 +484,10 @@ usb_doattach(device_t self)
 	ue->u.ue_ctrlr.ue_bus = device_unit(self);
 	usb_add_event(USB_EVENT_CTRLR_ATTACH, ue);
 
+	sc->sc_attach_thread = curlwp;
 	err = usbd_new_device(self, sc->sc_bus, 0, speed, 0,
 		  >sc_port);
+	sc->sc_attach_thread = NULL;
 	if (!err) {
 		dev = sc->sc_port.up_dev;
 		if (dev->ud_hub == NULL) {
@@ -529,6 +532,25 @@ usb_create_event_thread(device_t self)
 	}
 }
 
+bool
+usb_in_event_thread(device_t dev)
+{
+	struct usb_softc *sc;
+
+	if (cold)
+		return true;
+
+	for (; dev; dev = device_parent(dev)) {
+		if (device_is_a(dev, "usb"))
+			break;
+	}
+	if (dev == NULL)
+		return false;
+	sc = device_private(dev);
+
+	return curlwp == sc->sc_event_thread || curlwp == sc->sc_attach_thread;
+}
+
 /*
  * Add a task to be performed by the task thread.  This function can be
  * called from any context and the task will be executed in a process

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.264 src/sys/dev/usb/usb_subr.c:1.265
--- src/sys/dev/usb/usb_subr.c:1.264	Sun Jun 13 09:12:24 2021
+++ src/sys/dev/usb/usb_subr.c	Sun Jun 13 14:48:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.264 2021/06/13 09:12:24 mlelstv Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.265 2021/06/13 14:48:10 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.264 2021/06/13 09:12:24 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.265 2021/06/13 14:48:10 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1097,6 +1097,8 @@ usbd_attachwholedevice(device_t parent, 
 	device_t dv;
 	int dlocs[USBDEVIFCF_NLOCS];
 
+	KASSERT(usb_in_event_thread(parent));
+
 	uaa.uaa_device = dev;
 	

CVS commit: src/sys/dev/usb

2021-06-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 13 14:46:07 UTC 2021

Modified Files:
src/sys/dev/usb: uhub.c

Log Message:
uhub(4): Defer rescan to USB event thread.

Keep all of the USB bus exploration in a single thread -- this
appears to have been the original assumption, violated back in 2008
when uhub_rescan was added, and will make everything simpler.


To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/sys/dev/usb/uhub.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/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.151 src/sys/dev/usb/uhub.c:1.152
--- src/sys/dev/usb/uhub.c:1.151	Sun Jun 13 00:11:57 2021
+++ src/sys/dev/usb/uhub.c	Sun Jun 13 14:46:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.151 2021/06/13 00:11:57 riastradh Exp $	*/
+/*	$NetBSD: uhub.c,v 1.152 2021/06/13 14:46:07 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.151 2021/06/13 00:11:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.152 2021/06/13 14:46:07 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -119,6 +119,7 @@ struct uhub_softc {
 	bool			 sc_explorepending;
 	bool			 sc_first_explore;
 	bool			 sc_running;
+	bool			 sc_rescan;
 
 	struct lwp		*sc_exploring;
 };
@@ -130,8 +131,6 @@ struct uhub_softc {
 #define PORTSTAT_ISSET(sc, port) \
 	((sc)->sc_status[(port) / 8] & (1 << ((port) % 8)))
 
-Static usbd_status uhub_explore_enter(struct uhub_softc *);
-Static void uhub_explore_exit(struct uhub_softc *);
 Static usbd_status uhub_explore(struct usbd_device *);
 Static void uhub_intr(struct usbd_xfer *, void *, usbd_status);
 
@@ -482,51 +481,17 @@ uhub_attach(device_t parent, device_t se
 	config_pending_decr(self);
 }
 
-Static usbd_status
-uhub_explore_enter(struct uhub_softc *sc)
-{
-	usbd_status err;
-
-	mutex_enter(>sc_lock);
-	for (;;) {
-		if (sc->sc_exploring == NULL) {
-			sc->sc_exploring = curlwp;
-			err = 0;
-			break;
-		}
-		KASSERT(sc->sc_exploring != curlwp);
-		if (cv_wait_sig(>sc_cv, >sc_lock)) {
-			err = USBD_INTERRUPTED;
-			break;
-		}
-	}
-	mutex_exit(>sc_lock);
-
-	return err;
-}
-
-Static void
-uhub_explore_exit(struct uhub_softc *sc)
-{
-
-	mutex_enter(>sc_lock);
-	KASSERTMSG(sc->sc_exploring == curlwp, "lwp %p exploring %s",
-	sc->sc_exploring, device_xname(sc->sc_dev));
-	sc->sc_exploring = NULL;
-	cv_broadcast(>sc_cv);
-	mutex_exit(>sc_lock);
-}
-
 usbd_status
 uhub_explore(struct usbd_device *dev)
 {
 	usb_hub_descriptor_t *hd = >ud_hub->uh_hubdesc;
 	struct uhub_softc *sc = dev->ud_hub->uh_hubsoftc;
 	struct usbd_port *up;
+	struct usbd_device *subdev;
 	usbd_status err;
 	int speed;
 	int port;
-	int change, status, reconnect;
+	int change, status, reconnect, rescan;
 
 	UHUBHIST_FUNC();
 	UHUBHIST_CALLARGS("uhub%jd dev=%#jx addr=%jd speed=%ju",
@@ -542,10 +507,19 @@ uhub_explore(struct usbd_device *dev)
 	if (dev->ud_depth > USB_HUB_MAX_DEPTH)
 		return USBD_TOO_DEEP;
 
-	/* Only one explore at a time, please.  */
-	err = uhub_explore_enter(sc);
-	if (err)
-		return err;
+	/* Process rescan if requested.  */
+	mutex_enter(>sc_lock);
+	rescan = sc->sc_rescan;
+	sc->sc_rescan = false;
+	mutex_exit(>sc_lock);
+	if (rescan) {
+		for (port = 1; port <= hd->bNbrPorts; port++) {
+			subdev = dev->ud_hub->uh_ports[port - 1].up_dev;
+			if (subdev == NULL)
+continue;
+			usbd_reattach_device(sc->sc_dev, subdev, port, NULL);
+		}
+	}
 
 	if (PORTSTAT_ISSET(sc, 0)) { /* hub status change */
 		usb_hub_status_t hs;
@@ -851,7 +825,6 @@ uhub_explore(struct usbd_device *dev)
 		}
 	}
 	mutex_exit(>sc_lock);
-	uhub_explore_exit(sc);
 	if (sc->sc_first_explore) {
 		config_pending_decr(sc->sc_dev);
 		sc->sc_first_explore = false;
@@ -928,26 +901,17 @@ static int
 uhub_rescan(device_t self, const char *ifattr, const int *locators)
 {
 	struct uhub_softc *sc = device_private(self);
-	struct usbd_hub *hub = sc->sc_hub->ud_hub;
-	struct usbd_device *dev;
-	int port;
 
 	UHUBHIST_FUNC();
 	UHUBHIST_CALLARGS("uhub%jd", device_unit(sc->sc_dev), 0, 0, 0);
 
 	KASSERT(KERNEL_LOCKED_P());
 
-	if (uhub_explore_enter(sc) != 0)
-		return EBUSY;
-	for (port = 1; port <= hub->uh_hubdesc.bNbrPorts; port++) {
-		dev = hub->uh_ports[port - 1].up_dev;
-		if (dev == NULL)
-			continue;
-		usbd_reattach_device(sc->sc_dev, dev, port, locators);
-	}
-	uhub_explore_exit(sc);
-
-	/* Arrange to recursively explore hubs we may have found.  */
+	/* Trigger bus exploration.  */
+	/* XXX locators */
+	mutex_enter(>sc_lock);
+	sc->sc_rescan = true;
+	mutex_exit(>sc_lock);
 	usb_needs_explore(sc->sc_hub);
 
 	return 0;



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:32:01 UTC 2021

Modified Files:
src/sys/dev/usb: ubsa.c

Log Message:
Refactor handling of "quad utms" devices and more.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/usb/ubsa.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/ubsa.c
diff -u src/sys/dev/usb/ubsa.c:1.41 src/sys/dev/usb/ubsa.c:1.42
--- src/sys/dev/usb/ubsa.c:1.41	Sat Apr 24 23:36:59 2021
+++ src/sys/dev/usb/ubsa.c	Sun Jun 13 09:32:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ubsa.c,v 1.41 2021/04/24 23:36:59 thorpej Exp $	*/
+/*	$NetBSD: ubsa.c,v 1.42 2021/06/13 09:32:01 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2002, Alexander Kabaev .
@@ -55,7 +55,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ubsa.c,v 1.41 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ubsa.c,v 1.42 2021/06/13 09:32:01 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -107,25 +107,28 @@ static const struct	ucom_methods ubsa_me
 	.ucom_close = ubsa_close,
 };
 
-Static const struct usb_devno ubsa_devs[] = {
+Static const struct ubsa_type {
+	struct usb_devno ubsa_dev;
+	int ubsa_quadumts;
+} ubsa_devs[] = {
 	/* BELKIN F5U103 */
-	{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U103 },
+	{ { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U103 }, 0 },
 	/* BELKIN F5U120 */
-	{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U120 },
+	{ { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U120 }, 0 },
 	/* GoHubs GO-COM232 */
-	{ USB_VENDOR_ETEK, USB_PRODUCT_ETEK_1COM },
+	{ { USB_VENDOR_ETEK, USB_PRODUCT_ETEK_1COM }, 0 },
 	/* GoHubs GO-COM232 */
-	{ USB_VENDOR_GOHUBS, USB_PRODUCT_GOHUBS_GOCOM232 },
+	{ { USB_VENDOR_GOHUBS, USB_PRODUCT_GOHUBS_GOCOM232 }, 0 },
 	/* Peracom */
-	{ USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_SERIAL1 },
+	{ { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_SERIAL1 }, 0 },
 	/* Option N.V. */
-	{ USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_MC3G },
-	{ USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_QUADUMTS2 },
-	{ USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_QUADUMTS },
-	/* AnyDATA ADU-E100H */
-	{ USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_ADU_E100H },
+	{ { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_MC3G }, 0 },
+	{ { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_QUADUMTS2 }, 1 },
+	{ { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_QUADUMTS }, 1 },
+	{ { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_QUADPLUSUMTS }, 1 },
+	{ { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_HSDPA }, 1 },
 };
-#define ubsa_lookup(v, p) usb_lookup(ubsa_devs, v, p)
+#define ubsa_lookup(v, p) ((const struct ubsa_type *)usb_lookup(ubsa_devs, v, p))
 
 int ubsa_match(device_t, cfdata_t, void *);
 void ubsa_attach(device_t, device_t, void *);
@@ -183,15 +186,7 @@ ubsa_attach(device_t parent, device_t se
 	 * Quad UMTS cards use different requests to
 	 * control com settings and only some.
 	 */
-	sc->sc_quadumts = 0;
-	if (uaa->uaa_vendor == USB_VENDOR_OPTIONNV) {
-		switch (uaa->uaa_product) {
-		case USB_PRODUCT_OPTIONNV_QUADUMTS:
-		case USB_PRODUCT_OPTIONNV_QUADUMTS2:
-			sc->sc_quadumts = 1;
-			break;
-		}
-	}
+	sc->sc_quadumts = ubsa_lookup(uaa->uaa_vendor, uaa->uaa_product)->ubsa_quadumts;
 
 	DPRINTF(("ubsa attach: sc = %p\n", sc));
 



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:29:38 UTC 2021

Modified Files:
src/sys/dev/usb: ubsa_common.c

Log Message:
Handle IXON,IXOFF individually.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/usb/ubsa_common.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/ubsa_common.c
diff -u src/sys/dev/usb/ubsa_common.c:1.14 src/sys/dev/usb/ubsa_common.c:1.15
--- src/sys/dev/usb/ubsa_common.c:1.14	Sat Mar 14 02:35:33 2020
+++ src/sys/dev/usb/ubsa_common.c	Sun Jun 13 09:29:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ubsa_common.c,v 1.14 2020/03/14 02:35:33 christos Exp $	*/
+/*	$NetBSD: ubsa_common.c,v 1.15 2021/06/13 09:29:38 mlelstv Exp $	*/
 /*-
  * Copyright (c) 2002, Alexander Kabaev .
  * All rights reserved.
@@ -54,7 +54,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ubsa_common.c,v 1.14 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ubsa_common.c,v 1.15 2021/06/13 09:29:38 mlelstv Exp $");
 
 #include 
 #include 
@@ -316,8 +316,10 @@ ubsa_flow(struct ubsa_softc *sc, int por
 	value = 0;
 	if (cflag & CRTSCTS)
 		value |= UBSA_FLOW_OCTS | UBSA_FLOW_IRTS;
-	if (iflag & (IXON|IXOFF))
-		value |= UBSA_FLOW_OXON | UBSA_FLOW_IXON;
+	if (iflag & IXOFF)
+		value |= UBSA_FLOW_OXON;
+	if (iflag & IXON)
+		value |= UBSA_FLOW_IXON;
 
 	ubsa_request(sc, portno, UBSA_SET_FLOW_CTRL, value);
 }



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:28:23 UTC 2021

Modified Files:
src/sys/dev/usb: uthum.c

Log Message:
Fix envsys detach paths.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/usb/uthum.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/uthum.c
diff -u src/sys/dev/usb/uthum.c:1.20 src/sys/dev/usb/uthum.c:1.21
--- src/sys/dev/usb/uthum.c:1.20	Sat Mar 14 02:35:33 2020
+++ src/sys/dev/usb/uthum.c	Sun Jun 13 09:28:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uthum.c,v 1.20 2020/03/14 02:35:33 christos Exp $   */
+/*	$NetBSD: uthum.c,v 1.21 2021/06/13 09:28:23 mlelstv Exp $   */
 /*	$OpenBSD: uthum.c,v 1.6 2010/01/03 18:43:02 deraadt Exp $   */
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uthum.c,v 1.20 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uthum.c,v 1.21 2021/06/13 09:28:23 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -206,12 +206,14 @@ uthum_attach(device_t parent, device_t s
 		sc->sc_sme->sme_refresh = uthum_refresh;
 
 		if (sysmon_envsys_register(sc->sc_sme)) {
+			sysmon_envsys_destroy(sc->sc_sme);
+			sc->sc_sme = NULL;
 			aprint_error_dev(self,
 			"unable to register with sysmon\n");
-			sysmon_envsys_destroy(sc->sc_sme);
 		}
 	} else {
 		sysmon_envsys_destroy(sc->sc_sme);
+		sc->sc_sme = NULL;
 	}
 
 	DPRINTF(("uthum_attach: complete\n"));
@@ -225,9 +227,8 @@ uthum_detach(device_t self, int flags)
 
 	sc->sc_dying = 1;
 
-	if (sc->sc_num_sensors > 0) {
+	if (sc->sc_sme != NULL)
 		sysmon_envsys_unregister(sc->sc_sme);
-	}
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
 	sc->sc_hdev.sc_dev);



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:27:20 UTC 2021

Modified Files:
src/sys/dev/usb: uhso.c

Log Message:
Remove duplicate.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/usb/uhso.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/uhso.c
diff -u src/sys/dev/usb/uhso.c:1.34 src/sys/dev/usb/uhso.c:1.35
--- src/sys/dev/usb/uhso.c:1.34	Sat Mar 14 02:35:33 2020
+++ src/sys/dev/usb/uhso.c	Sun Jun 13 09:27:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhso.c,v 1.34 2020/03/14 02:35:33 christos Exp $	*/
+/*	$NetBSD: uhso.c,v 1.35 2021/06/13 09:27:20 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2009 Iain Hibbert
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhso.c,v 1.34 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhso.c,v 1.35 2021/06/13 09:27:20 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -233,7 +233,6 @@ struct uhso_dev {
 #define UHSOTYPE_CONFIG		3
 
 Static const struct uhso_dev uhso_devs[] = {
-{ USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_MAXHSDPA,UHSOTYPE_DEFAULT },
 { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_GSICON72,UHSOTYPE_DEFAULT },
 { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_ICON225, UHSOTYPE_DEFAULT },
 { USB_VENDOR_OPTIONNV, USB_PRODUCT_OPTIONNV_GEHSUPA, UHSOTYPE_DEFAULT },



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:26:24 UTC 2021

Modified Files:
src/sys/dev/usb: if_kue.c

Log Message:
Align product name.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/usb/if_kue.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/if_kue.c
diff -u src/sys/dev/usb/if_kue.c:1.104 src/sys/dev/usb/if_kue.c:1.105
--- src/sys/dev/usb/if_kue.c:1.104	Sat Mar 21 06:55:22 2020
+++ src/sys/dev/usb/if_kue.c	Sun Jun 13 09:26:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_kue.c,v 1.104 2020/03/21 06:55:22 skrll Exp $	*/
+/*	$NetBSD: if_kue.c,v 1.105 2021/06/13 09:26:24 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.104 2020/03/21 06:55:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_kue.c,v 1.105 2021/06/13 09:26:24 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -131,7 +131,7 @@ static const struct usb_devno kue_devs[]
 	{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_URE450 },
 	{ USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT },
 	{ USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BTX },
-	{ USB_VENDOR_ACTIONTEC, USB_PRODUCT_ACTIONTEC_KL5KUSB101 },
+	{ USB_VENDOR_ACTIONTEC, USB_PRODUCT_ACTIONTEC_AR9287 },
 	{ USB_VENDOR_ALLIEDTELESYN, USB_PRODUCT_ALLIEDTELESYN_AT_USB10 },
 	{ USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
 	{ USB_VENDOR_ASANTE, USB_PRODUCT_ASANTE_EA },



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:24:33 UTC 2021

Modified Files:
src/sys/dev/usb: if_zyd.c

Log Message:
Remove duplicate


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/usb/if_zyd.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/if_zyd.c
diff -u src/sys/dev/usb/if_zyd.c:1.59 src/sys/dev/usb/if_zyd.c:1.60
--- src/sys/dev/usb/if_zyd.c:1.59	Sun Mar 15 23:04:51 2020
+++ src/sys/dev/usb/if_zyd.c	Sun Jun 13 09:24:33 2021
@@ -1,5 +1,5 @@
 /*	$OpenBSD: if_zyd.c,v 1.52 2007/02/11 00:08:04 jsg Exp $	*/
-/*	$NetBSD: if_zyd.c,v 1.59 2020/03/15 23:04:51 thorpej Exp $	*/
+/*	$NetBSD: if_zyd.c,v 1.60 2021/06/13 09:24:33 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2006 by Damien Bergamini 
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_zyd.c,v 1.59 2020/03/15 23:04:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_zyd.c,v 1.60 2021/06/13 09:24:33 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -141,8 +141,7 @@ static const struct zyd_type {
 	ZYD_ZD1211B_DEV(SITECOMEU,	ZD1211B),
 	ZYD_ZD1211B_DEV(SONY,		IFU_WLM2),
 	ZYD_ZD1211B_DEV(UMEDIA,		TEW429UBC1),
-	ZYD_ZD1211B_DEV(UNKNOWN1,	ZD1211B_1),
-	ZYD_ZD1211B_DEV(UNKNOWN1,	ZD1211B_2),
+	ZYD_ZD1211B_DEV(UNKNOWN1,	ZD1211B),
 	ZYD_ZD1211B_DEV(UNKNOWN2,	ZD1211B),
 	ZYD_ZD1211B_DEV(UNKNOWN3,	ZD1211B),
 	ZYD_ZD1211B_DEV(USR,		USR5423),



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:23:42 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs

Log Message:
Correct some vendor names, remove duplicates.


To generate a diff of this commit:
cvs rdiff -u -r1.793 -r1.794 src/sys/dev/usb/usbdevs

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/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.793 src/sys/dev/usb/usbdevs:1.794
--- src/sys/dev/usb/usbdevs:1.793	Mon Mar 15 07:29:26 2021
+++ src/sys/dev/usb/usbdevs	Sun Jun 13 09:23:42 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.793 2021/03/15 07:29:26 nia Exp $
+$NetBSD: usbdevs,v 1.794 2021/06/13 09:23:42 mlelstv Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -430,7 +430,6 @@ vendor ADDONICS2	0x0bf6	Addonics Technol
 vendor FSC		0x0bf8	Fujitsu Siemens Computers
 vendor AGATE		0x0c08	Agate Technologies
 vendor DMI		0x0c0b	DMI
-vendor CHICONY2		0x0c45	Chicony Electronics
 vendor MICRODIA		0x0c45	Microdia / Sonix Technology Co., Ltd.
 vendor SEALEVEL		0x0c52	Sealevel System
 vendor LUWEN		0x0c76	EasyDisk
@@ -445,7 +444,7 @@ vendor CMEDIA		0x0d8c	C-Media Electronic
 vendor CONCEPTRONIC2	0x0d8e	Conceptronic
 vendor MSI		0x0db0	Micro Star
 vendor ELCON		0x0db7	ELCON Systemtechnik
-vendor UNKNOWN5		0x0dcd	Unknown Vendor
+vendor NETWORKFAB	0x0dcd	NetworkFab Corporation
 vendor SITECOMEU	0x0df6	Sitecom Europe
 vendor AMIGO		0x0e0b	Amigo Technology
 vendor HAWKING		0x0e66	Hawking
@@ -571,7 +570,6 @@ vendor PARA		0x20b8	PARA Industrial
 vendor TRENDNET		0x20f4	TRENDnet
 vendor RTSYS		0x2100	RT Systems
 vendor DLINK3		0x2101	D-Link
-vendor INTENSO		0x2109	INTENSO
 vendor VIALABS		0x2109	VIA Labs
 vendor ERICSSON		0x2282	Ericsson
 vendor MOTOROLA2	0x22b8	Motorola
@@ -729,7 +727,6 @@ product ACERW WARPLINK		0x0204	Warplink
 product ACTIONTEC PRISM_25	0x0408	Prism2.5 WLAN
 product ACTIONTEC PRISM_25A	0x0421	Prism2.5 WLAN A
 product ACTIONTEC AR9287	0x1200	AR9287+AR7010
-product ACTIONTEC KL5KUSB101	0x1200	KL5KUSB101 USB Ethernet adapter
 product ACTIONTEC FREELAN	0x6106	ROPEX FreeLan 802.11b
 product ACTIONTEC UAT1		0x7605	UAT1 Wireless Ethernet adapter
 
@@ -1182,8 +1179,10 @@ product CHICONY RTL8188CUS_3	0xaff9	RTL8
 product CHICONY RTL8188CUS_4	0xaffa	RTL8188CUS
 product CHICONY RTL8188CUS_5	0xaffb	RTL8188CUS
 product CHICONY RTL8188CUS_6	0xaffc	RTL8188CUS
-product CHICONY2 TWINKLECAM	0x600d	TwinkleCam USB camera
-product CHICONY2 BWC35HL01	0x602c	Buffalo WBC-35H/L01
+
+/* Microdia / Sonix products */
+product MICRODIA TWINKLECAM	0x600d	TwinkleCam USB camera
+product MICRODIA BWC35HL01	0x602c	Buffalo WBC-35H/L01
 
 /* CH Products */
 product CHPRODUCTS PROTHROTTLE	0x00f1	Pro Throttle
@@ -2592,7 +2591,6 @@ product OPTIONNV QUADUMTS2	0x6000	GlobeT
 product OPTIONNV QUADUMTS	0x6300	GlobeTrotter Fusion Quad Lite 3D
 product OPTIONNV QUADPLUSUMTS	0x6600	GlobeTrotter 3G Quad Plus
 product OPTIONNV HSDPA		0x6701	GlobeTrotter HSDPA Modem
-product OPTIONNV MAXHSDPA	0x6701	GlobeTrotter Max HSDPA Modem
 product OPTIONNV GSICON72	0x6911	GlobeSurfer iCON 7.2
 product OPTIONNV ICON225	0x6971	iCON 225
 product OPTIONNV GTMAXHSUPA	0x7001	GlobeTrotter HSUPA
@@ -3463,8 +3461,7 @@ product UMEDIA ALL0298V2	0x3204	ALL0298 
 product UNIACCESS PANACHE	0x0101	Panache Surf USB ISDN Adapter
 
 /* Unknown vendor 1 */
-product UNKNOWN1 ZD1211B_1	0x5301	ZD1211B
-product UNKNOWN1 ZD1211B_2	0x5301	ZD1211B
+product UNKNOWN1 ZD1211B	0x5301	ZD1211B
 
 /* Unknown vendor 2 */
 product UNKNOWN2 ZD1211B	0x0105	ZD1211B
@@ -3473,8 +3470,8 @@ product UNKNOWN2 NW3100		0x145f	NW-3100
 /* Unknown vendor 3 */
 product UNKNOWN3 ZD1211B	0x1233 ZD1211B
 
-/* Unknown vendor 5 */
-product UNKNOWN5 NF_RIC		0x0001	NF RIC
+/* NetworkFab Corporation products */
+product NETWORKFAB NF_RIC	0x0001	NF RIC
 
 /* U.S. Robotics products */
 product USR USR1120		0x00eb	USR1120 WLAN



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 09:12:24 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
Fix last patch.


To generate a diff of this commit:
cvs rdiff -u -r1.263 -r1.264 src/sys/dev/usb/usb_subr.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.263 src/sys/dev/usb/usb_subr.c:1.264
--- src/sys/dev/usb/usb_subr.c:1.263	Sun Jun 13 08:50:33 2021
+++ src/sys/dev/usb/usb_subr.c	Sun Jun 13 09:12:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.263 2021/06/13 08:50:33 mlelstv Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.264 2021/06/13 09:12:24 mlelstv Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.263 2021/06/13 08:50:33 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.264 2021/06/13 09:12:24 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -421,7 +421,7 @@ usbd_iface_init(struct usbd_device *dev,
 static void
 usbd_iface_fini(struct usbd_device *dev, int ifaceidx)
 {
-	struct usbd_interface *ifc = >ud_ifaces[ifaceidx] __diagused;
+	struct usbd_interface *ifc __diagused = >ud_ifaces[ifaceidx];
 
 	KASSERT(ifc->ui_dev == dev);
 	KASSERT(ifc->ui_idesc == NULL);



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 08:50:33 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
Use correct integer lengths for properties.
Change property names vendor -> vendor-id, product -> product-id to match other 
users.


To generate a diff of this commit:
cvs rdiff -u -r1.262 -r1.263 src/sys/dev/usb/usb_subr.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.262 src/sys/dev/usb/usb_subr.c:1.263
--- src/sys/dev/usb/usb_subr.c:1.262	Sun Jun 13 08:48:29 2021
+++ src/sys/dev/usb/usb_subr.c	Sun Jun 13 08:50:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.262 2021/06/13 08:48:29 mlelstv Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.263 2021/06/13 08:50:33 mlelstv Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.262 2021/06/13 08:48:29 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.263 2021/06/13 08:50:33 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -421,7 +421,7 @@ usbd_iface_init(struct usbd_device *dev,
 static void
 usbd_iface_fini(struct usbd_device *dev, int ifaceidx)
 {
-	struct usbd_interface *ifc __diagused = >ud_ifaces[ifaceidx];
+	struct usbd_interface *ifc = >ud_ifaces[ifaceidx] __diagused;
 
 	KASSERT(ifc->ui_dev == dev);
 	KASSERT(ifc->ui_idesc == NULL);
@@ -1067,12 +1067,12 @@ usbd_properties(device_t dv, struct usbd
 	vendor = UGETW(dd->idVendor);
 	product = UGETW(dd->idProduct);
 
-	prop_dictionary_set_uint16(dict, "class", class);
-	prop_dictionary_set_uint16(dict, "subclass", subclass);
+	prop_dictionary_set_uint8(dict, "class", class);
+	prop_dictionary_set_uint8(dict, "subclass", subclass);
 	prop_dictionary_set_uint16(dict, "release", release);
-	prop_dictionary_set_uint16(dict, "proto", proto);
-	prop_dictionary_set_uint16(dict, "vendor", vendor);
-	prop_dictionary_set_uint16(dict, "product", product);
+	prop_dictionary_set_uint8(dict, "proto", proto);
+	prop_dictionary_set_uint16(dict, "vendor-id", vendor);
+	prop_dictionary_set_uint16(dict, "product-id", product);
 
 	if (dev->ud_vendor) {
 		prop_dictionary_set_string(dict,



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 08:48:29 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
Fix non-DIAGNOSTIC build.


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/sys/dev/usb/usb_subr.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.261 src/sys/dev/usb/usb_subr.c:1.262
--- src/sys/dev/usb/usb_subr.c:1.261	Sun Jun 13 00:13:24 2021
+++ src/sys/dev/usb/usb_subr.c	Sun Jun 13 08:48:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.261 2021/06/13 00:13:24 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.262 2021/06/13 08:48:29 mlelstv Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.261 2021/06/13 00:13:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.262 2021/06/13 08:48:29 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -421,7 +421,7 @@ usbd_iface_init(struct usbd_device *dev,
 static void
 usbd_iface_fini(struct usbd_device *dev, int ifaceidx)
 {
-	struct usbd_interface *ifc = >ud_ifaces[ifaceidx];
+	struct usbd_interface *ifc __diagused = >ud_ifaces[ifaceidx];
 
 	KASSERT(ifc->ui_dev == dev);
 	KASSERT(ifc->ui_idesc == NULL);



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 07:51:09 UTC 2021

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Don't use aprint* for non-autoconf errors. Also print status value.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/dev/usb/uaudio.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/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.170 src/sys/dev/usb/uaudio.c:1.171
--- src/sys/dev/usb/uaudio.c:1.170	Sun Jun 13 07:49:43 2021
+++ src/sys/dev/usb/uaudio.c	Sun Jun 13 07:51:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.170 2021/06/13 07:49:43 mlelstv Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.171 2021/06/13 07:51:09 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.170 2021/06/13 07:49:43 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.171 2021/06/13 07:51:09 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2835,8 +2835,9 @@ uaudio_chan_pintr(struct usbd_xfer *xfer
 		count, ch->transferred);
 #ifdef DIAGNOSTIC
 	if (count != cb->size) {
-		aprint_error("uaudio_chan_pintr: count(%d) != size(%d)\n",
-		   count, cb->size);
+		device_printf(ch->sc->sc_dev,
+		"uaudio_chan_pintr: count(%d) != size(%d), status(%d)\n",
+		count, cb->size, status);
 	}
 #endif
 
@@ -2918,8 +2919,9 @@ uaudio_chan_rintr(struct usbd_xfer *xfer
 	/* count < cb->size is normal for asynchronous source */
 #ifdef DIAGNOSTIC
 	if (count > cb->size) {
-		aprint_error("uaudio_chan_rintr: count(%d) > size(%d)\n",
-		   count, cb->size);
+		device_printf(ch->sc->sc_dev,
+		"uaudio_chan_rintr: count(%d) > size(%d) status(%d)\n",
+		count, cb->size, status);
 	}
 #endif
 



CVS commit: src/sys/dev/usb

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 07:49:43 UTC 2021

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Don't ignore detach errors from children.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/dev/usb/uaudio.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/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.169 src/sys/dev/usb/uaudio.c:1.170
--- src/sys/dev/usb/uaudio.c:1.169	Mon Feb 15 13:39:18 2021
+++ src/sys/dev/usb/uaudio.c	Sun Jun 13 07:49:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.169 2021/02/15 13:39:18 isaki Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.170 2021/06/13 07:49:43 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.169 2021/02/15 13:39:18 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.170 2021/06/13 07:49:43 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -519,7 +519,7 @@ static int
 uaudio_detach(device_t self, int flags)
 {
 	struct uaudio_softc *sc = device_private(self);
-	int rv = 0;
+	int rv;
 
 	sc->sc_dying = 1;
 
@@ -529,8 +529,11 @@ uaudio_detach(device_t self, int flags)
 	uaudio_halt_out_dma_unlocked(sc);
 	uaudio_halt_in_dma_unlocked(sc);
 
-	if (sc->sc_audiodev != NULL)
+	if (sc->sc_audiodev != NULL) {
 		rv = config_detach(sc->sc_audiodev, flags);
+		if (rv)
+			return rv;
+	}
 
 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
 
@@ -541,7 +544,7 @@ uaudio_detach(device_t self, int flags)
 	mutex_destroy(>sc_lock);
 	mutex_destroy(>sc_intr_lock);
 
-	return rv;
+	return 0;
 }
 
 Static int



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 13 00:13:24 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c usbdivar.h

Log Message:
usb(4): Tighten interface locking and pipe references.

- Just use a reference count, not a list of pipes.

- Take the reference in usbd_open_pipe*, before we even look up the
  endpoint by address; the endpoint is not stable until we hold the
  interface and prevent usbd_set_interface.

- Make opening pipes just fail if usbd_set_interface is in progress.
  => No need to block -- might block for a while, and this is
 essentially a driver error rather than a legitimate reason to
 block.
  => This should maybe be a kassert, but it's not clear that ugen(4)
 doesn't have a user-triggerable path to that kassert, so let's
 keep it as a graceful failure for now until someone can audit
 ugen(4) and make an informed decision.

- No need for a separate interface pipe lock; just use the bus lock.

This is a little bit longer than before, but makes the bracketed
nature of the references a little clearer and introduces more
kasserts to detect mistakes with internal API usage.


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.215 -r1.216 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.127 -r1.128 src/sys/dev/usb/usbdivar.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.260 src/sys/dev/usb/usb_subr.c:1.261
--- src/sys/dev/usb/usb_subr.c:1.260	Sat Jun 12 15:49:45 2021
+++ src/sys/dev/usb/usb_subr.c	Sun Jun 13 00:13:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.260 2021/06/12 15:49:45 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.261 2021/06/13 00:13:24 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.260 2021/06/12 15:49:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.261 2021/06/13 00:13:24 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -415,8 +415,7 @@ usbd_iface_init(struct usbd_device *dev,
 	ifc->ui_index = 0;
 	ifc->ui_altindex = 0;
 	ifc->ui_endpoints = NULL;
-	LIST_INIT(>ui_pipes);
-	mutex_init(>ui_pipelock, MUTEX_DEFAULT, IPL_NONE);
+	ifc->ui_busy = 0;
 }
 
 static void
@@ -429,9 +428,100 @@ usbd_iface_fini(struct usbd_device *dev,
 	KASSERT(ifc->ui_index == 0);
 	KASSERT(ifc->ui_altindex == 0);
 	KASSERT(ifc->ui_endpoints == NULL);
-	KASSERT(LIST_EMPTY(>ui_pipes));
+	KASSERTMSG(ifc->ui_busy == 0, "%"PRId64, ifc->ui_busy);
+}
+
+/*
+ * usbd_iface_lock/locked/unlock, usbd_iface_piperef/pipeunref
+ *
+ *	We lock the interface while we are setting it, and we acquire a
+ *	reference to the interface for each pipe opened on it.
+ *
+ *	Setting the interface while pipes are open is forbidden, and
+ *	opening pipes while the interface is being set is forbidden.
+ */
+
+bool
+usbd_iface_locked(struct usbd_interface *iface)
+{
+	bool locked;
+
+	mutex_enter(iface->ui_dev->ud_bus->ub_lock);
+	locked = (iface->ui_busy == -1);
+	mutex_exit(iface->ui_dev->ud_bus->ub_lock);
+
+	return locked;
+}
+
+static void
+usbd_iface_exlock(struct usbd_interface *iface)
+{
+
+	mutex_enter(iface->ui_dev->ud_bus->ub_lock);
+	KASSERTMSG(iface->ui_busy == 0, "interface is not idle,"
+	" busy=%"PRId64, iface->ui_busy);
+	iface->ui_busy = -1;
+	mutex_exit(iface->ui_dev->ud_bus->ub_lock);
+}
+
+usbd_status
+usbd_iface_lock(struct usbd_interface *iface)
+{
+	usbd_status err;
+
+	mutex_enter(iface->ui_dev->ud_bus->ub_lock);
+	KASSERTMSG(iface->ui_busy != -1, "interface is locked");
+	KASSERTMSG(iface->ui_busy >= 0, "%"PRId64, iface->ui_busy);
+	if (iface->ui_busy) {
+		err = USBD_IN_USE;
+	} else {
+		iface->ui_busy = -1;
+		err = 0;
+	}
+	mutex_exit(iface->ui_dev->ud_bus->ub_lock);
+
+	return err;
+}
+
+void
+usbd_iface_unlock(struct usbd_interface *iface)
+{
+
+	mutex_enter(iface->ui_dev->ud_bus->ub_lock);
+	KASSERTMSG(iface->ui_busy == -1, "interface is not locked,"
+	" busy=%"PRId64, iface->ui_busy);
+	iface->ui_busy = 0;
+	mutex_exit(iface->ui_dev->ud_bus->ub_lock);
+}
+
+usbd_status
+usbd_iface_piperef(struct usbd_interface *iface)
+{
+	usbd_status err;
+
+	mutex_enter(iface->ui_dev->ud_bus->ub_lock);
+	KASSERTMSG(iface->ui_busy >= -1, "%"PRId64, iface->ui_busy);
+	if (iface->ui_busy == -1) {
+		err = USBD_IN_USE;
+	} else {
+		iface->ui_busy++;
+		err = 0;
+	}
+	mutex_exit(iface->ui_dev->ud_bus->ub_lock);
+
+	return err;
+}
 
-	mutex_destroy(>ui_pipelock);
+void
+usbd_iface_pipeunref(struct usbd_interface *iface)
+{
+
+	mutex_enter(iface->ui_dev->ud_bus->ub_lock);
+	KASSERTMSG(iface->ui_busy != -1, "interface is locked");
+	KASSERTMSG(iface->ui_busy != 0, "interface not in use");
+	KASSERTMSG(iface->ui_busy >= 1, "%"PRId64, iface->ui_busy);
+	

CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 13 00:11:57 UTC 2021

Modified Files:
src/sys/dev/usb: uhub.c

Log Message:
uhub(4): Trigger bus exploration after rescanning children.

Otherwise, if uhub4 is attached at uhub1, then when we do

# drvctl -d uhub4
# drvctl -r -a usbdevif uhub1

the rescan never discovers devices attached recursively at uhub4, and
uhub4 leaks a config_pending_incr count so it can't be detached.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/dev/usb/uhub.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/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.150 src/sys/dev/usb/uhub.c:1.151
--- src/sys/dev/usb/uhub.c:1.150	Sat Jun 12 12:13:23 2021
+++ src/sys/dev/usb/uhub.c	Sun Jun 13 00:11:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.150 2021/06/12 12:13:23 riastradh Exp $	*/
+/*	$NetBSD: uhub.c,v 1.151 2021/06/13 00:11:57 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.150 2021/06/12 12:13:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.151 2021/06/13 00:11:57 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -946,6 +946,10 @@ uhub_rescan(device_t self, const char *i
 		usbd_reattach_device(sc->sc_dev, dev, port, locators);
 	}
 	uhub_explore_exit(sc);
+
+	/* Arrange to recursively explore hubs we may have found.  */
+	usb_needs_explore(sc->sc_hub);
+
 	return 0;
 }
 



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 15:49:45 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c usbdivar.h

Log Message:
usb(4): Nix unused struct usbd_interface::ui_priv.


To generate a diff of this commit:
cvs rdiff -u -r1.259 -r1.260 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.214 -r1.215 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.126 -r1.127 src/sys/dev/usb/usbdivar.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.259 src/sys/dev/usb/usb_subr.c:1.260
--- src/sys/dev/usb/usb_subr.c:1.259	Sat Jun 12 15:41:22 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 15:49:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.259 2021/06/12 15:41:22 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.260 2021/06/12 15:49:45 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.259 2021/06/12 15:41:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.260 2021/06/12 15:49:45 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -415,7 +415,6 @@ usbd_iface_init(struct usbd_device *dev,
 	ifc->ui_index = 0;
 	ifc->ui_altindex = 0;
 	ifc->ui_endpoints = NULL;
-	ifc->ui_priv = NULL;
 	LIST_INIT(>ui_pipes);
 	mutex_init(>ui_pipelock, MUTEX_DEFAULT, IPL_NONE);
 }
@@ -430,7 +429,6 @@ usbd_iface_fini(struct usbd_device *dev,
 	KASSERT(ifc->ui_index == 0);
 	KASSERT(ifc->ui_altindex == 0);
 	KASSERT(ifc->ui_endpoints == NULL);
-	KASSERT(ifc->ui_priv == NULL);
 	KASSERT(LIST_EMPTY(>ui_pipes));
 
 	mutex_destroy(>ui_pipelock);

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.214 src/sys/dev/usb/usbdi.c:1.215
--- src/sys/dev/usb/usbdi.c:1.214	Sat Jun 12 15:41:22 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 15:49:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.214 2021/06/12 15:41:22 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.215 2021/06/12 15:49:45 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.214 2021/06/12 15:41:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.215 2021/06/12 15:49:45 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -141,8 +141,8 @@ usbd_dump_iface(struct usbd_interface *i
 	USBHIST_LOG(usbdebug, " device = %#jx idesc = %#jx index = %jd",
 	(uintptr_t)iface->ui_dev, (uintptr_t)iface->ui_idesc,
 	iface->ui_index, 0);
-	USBHIST_LOG(usbdebug, " altindex=%jd priv=%#jx",
-	iface->ui_altindex, (uintptr_t)iface->ui_priv, 0, 0);
+	USBHIST_LOG(usbdebug, " altindex=%jd",
+	iface->ui_altindex, 0, 0, 0);
 }
 
 void

Index: src/sys/dev/usb/usbdivar.h
diff -u src/sys/dev/usb/usbdivar.h:1.126 src/sys/dev/usb/usbdivar.h:1.127
--- src/sys/dev/usb/usbdivar.h:1.126	Sat Jun 12 14:43:27 2021
+++ src/sys/dev/usb/usbdivar.h	Sat Jun 12 15:49:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdivar.h,v 1.126 2021/06/12 14:43:27 riastradh Exp $	*/
+/*	$NetBSD: usbdivar.h,v 1.127 2021/06/12 15:49:45 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -230,7 +230,6 @@ struct usbd_interface {
 	int			ui_index;
 	int			ui_altindex;
 	struct usbd_endpoint   *ui_endpoints;
-	void		   *ui_priv;
 	kmutex_t		ui_pipelock;
 	LIST_HEAD(, usbd_pipe)	ui_pipes;
 };



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 15:41:22 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c

Log Message:
usb(4): Make usbd_fill_iface_data atomic.

Now either it replaces and frees the old endpoints array, or it
leaves everything in place; it never leaves a partial update nor
requires the caller to free the old array.


To generate a diff of this commit:
cvs rdiff -u -r1.258 -r1.259 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.213 -r1.214 src/sys/dev/usb/usbdi.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.258 src/sys/dev/usb/usb_subr.c:1.259
--- src/sys/dev/usb/usb_subr.c:1.258	Sat Jun 12 15:39:57 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 15:41:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.258 2021/06/12 15:39:57 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.259 2021/06/12 15:41:22 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.258 2021/06/12 15:39:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.259 2021/06/12 15:41:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -444,6 +444,7 @@ usbd_fill_iface_data(struct usbd_device 
 	ifaceidx, altidx, 0, 0);
 	struct usbd_interface *ifc = >ud_ifaces[ifaceidx];
 	usb_interface_descriptor_t *idesc;
+	struct usbd_endpoint *endpoints;
 	char *p, *end;
 	int endpt, nendpt;
 
@@ -453,18 +454,16 @@ usbd_fill_iface_data(struct usbd_device 
 	idesc = usbd_find_idesc(dev->ud_cdesc, ifaceidx, altidx);
 	if (idesc == NULL)
 		return USBD_INVAL;
-	ifc->ui_idesc = idesc;
-	ifc->ui_index = ifaceidx;
-	ifc->ui_altindex = altidx;
-	nendpt = ifc->ui_idesc->bNumEndpoints;
+
+	nendpt = idesc->bNumEndpoints;
 	DPRINTFN(4, "found idesc nendpt=%jd", nendpt, 0, 0, 0);
 	if (nendpt != 0) {
-		ifc->ui_endpoints = kmem_alloc(nendpt * sizeof(struct usbd_endpoint),
-KM_SLEEP);
+		endpoints = kmem_alloc(nendpt * sizeof(struct usbd_endpoint),
+		KM_SLEEP);
 	} else
-		ifc->ui_endpoints = NULL;
-	ifc->ui_priv = NULL;
-	p = (char *)ifc->ui_idesc + ifc->ui_idesc->bLength;
+		endpoints = NULL;
+
+	p = (char *)idesc + idesc->bLength;
 	end = (char *)dev->ud_cdesc + UGETW(dev->ud_cdesc->wTotalLength);
 #define ed ((usb_endpoint_descriptor_t *)p)
 	for (endpt = 0; endpt < nendpt; endpt++) {
@@ -495,7 +494,7 @@ usbd_fill_iface_data(struct usbd_device 
 		}
 		goto bad;
 	found:
-		ifc->ui_endpoints[endpt].ue_edesc = ed;
+		endpoints[endpt].ue_edesc = ed;
 		if (dev->ud_speed == USB_SPEED_HIGH) {
 			u_int mps;
 			/* Control and bulk endpoints have max packet limits. */
@@ -518,18 +517,28 @@ usbd_fill_iface_data(struct usbd_device 
 break;
 			}
 		}
-		ifc->ui_endpoints[endpt].ue_refcnt = 0;
-		ifc->ui_endpoints[endpt].ue_toggle = 0;
+		endpoints[endpt].ue_refcnt = 0;
+		endpoints[endpt].ue_toggle = 0;
 		p += ed->bLength;
 	}
 #undef ed
+
+	/* Success!  Free the old endpoints and commit the changes.  */
+	if (ifc->ui_endpoints) {
+		kmem_free(ifc->ui_endpoints, (sizeof(ifc->ui_endpoints[0]) *
+			ifc->ui_idesc->bNumEndpoints));
+	}
+
+	ifc->ui_idesc = idesc;
+	ifc->ui_index = ifaceidx;
+	ifc->ui_altindex = altidx;
+	ifc->ui_endpoints = endpoints;
+
 	return USBD_NORMAL_COMPLETION;
 
  bad:
-	if (ifc->ui_endpoints != NULL) {
-		kmem_free(ifc->ui_endpoints, nendpt * sizeof(struct usbd_endpoint));
-		ifc->ui_endpoints = NULL;
-	}
+	if (endpoints)
+		kmem_free(endpoints, nendpt * sizeof(struct usbd_endpoint));
 	return USBD_INVAL;
 }
 

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.213 src/sys/dev/usb/usbdi.c:1.214
--- src/sys/dev/usb/usbdi.c:1.213	Sat Jun 12 15:40:07 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 15:41:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.213 2021/06/12 15:40:07 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.214 2021/06/12 15:41:22 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.213 2021/06/12 15:40:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.214 2021/06/12 15:41:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -867,9 +867,9 @@ usbd_set_interface(struct usbd_interface
 {
 	usb_device_request_t req;
 	usbd_status err;
-	void *endpoints;
 
 	USBHIST_FUNC();
+	USBHIST_CALLARGS(usbdebug, "iface %#jx", (uintptr_t)iface, 0, 0, 0);
 
 	mutex_enter(>ui_pipelock);
 	if (LIST_FIRST(>ui_pipes) != NULL) {
@@ -877,23 +877,10 @@ usbd_set_interface(struct usbd_interface
 		goto out;
 	}
 
-	endpoints = iface->ui_endpoints;
-	int nendpt = iface->ui_idesc->bNumEndpoints;
-	USBHIST_CALLARGS(usbdebug, "iface %#jx endpoints = %#jx nendpt %jd",
-	(uintptr_t)iface, (uintptr_t)endpoints,
-	

CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 15:40:07 UTC 2021

Modified Files:
src/sys/dev/usb: usbdi.c

Log Message:
usb(4): Tweak style in usbd_close_pipe.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/sys/dev/usb/usbdi.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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.212 src/sys/dev/usb/usbdi.c:1.213
--- src/sys/dev/usb/usbdi.c:1.212	Sat Jun 12 15:39:57 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 15:40:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.212 2021/06/12 15:39:57 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.213 2021/06/12 15:40:07 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.212 2021/06/12 15:39:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.213 2021/06/12 15:40:07 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -303,19 +303,16 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 
 	usbd_lock_pipe(pipe);
 	SDT_PROBE1(usb, device, pipe, close,  pipe);
-
 	if (!SIMPLEQ_EMPTY(>up_queue)) {
 		printf("WARNING: pipe closed with active xfers on addr %d\n",
 		pipe->up_dev->ud_addr);
 		usbd_ar_pipe(pipe);
 	}
-
 	KASSERT(SIMPLEQ_EMPTY(>up_queue));
-
 	pipe->up_methods->upm_close(pipe);
-
 	usbd_unlock_pipe(pipe);
-	if (pipe->up_intrxfer != NULL)
+
+	if (pipe->up_intrxfer)
 		usbd_destroy_xfer(pipe->up_intrxfer);
 	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
 	NULL);



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 15:39:57 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c

Log Message:
usb(4): Merge logic in usbd_kill_pipe and usbd_close_pipe.

usbd_kill_pipe is now just usbd_abort/close_pipe.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.257 -r1.258 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.211 -r1.212 src/sys/dev/usb/usbdi.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.257 src/sys/dev/usb/usb_subr.c:1.258
--- src/sys/dev/usb/usb_subr.c:1.257	Sat Jun 12 15:39:46 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 15:39:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.257 2021/06/12 15:39:46 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.258 2021/06/12 15:39:57 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.257 2021/06/12 15:39:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.258 2021/06/12 15:39:57 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -900,19 +900,13 @@ usbd_endpoint_release(struct usbd_device
 	mutex_exit(dev->ud_bus->ub_lock);
 }
 
-/* Abort the device control pipe. */
+/* Abort and close the device control pipe. */
 void
 usbd_kill_pipe(struct usbd_pipe *pipe)
 {
+
 	usbd_abort_pipe(pipe);
-	usbd_lock_pipe(pipe);
-	pipe->up_methods->upm_close(pipe);
-	usbd_unlock_pipe(pipe);
-	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
-	NULL);
-	KASSERT(pipe->up_iface == NULL);
-	usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
-	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
+	usbd_close_pipe(pipe);
 }
 
 int

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.211 src/sys/dev/usb/usbdi.c:1.212
--- src/sys/dev/usb/usbdi.c:1.211	Sat Jun 12 15:39:46 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 15:39:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.211 2021/06/12 15:39:46 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.212 2021/06/12 15:39:57 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.211 2021/06/12 15:39:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.212 2021/06/12 15:39:57 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -319,9 +319,11 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 		usbd_destroy_xfer(pipe->up_intrxfer);
 	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
 	NULL);
-	mutex_enter(>up_iface->ui_pipelock);
-	LIST_REMOVE(pipe, up_next);
-	mutex_exit(>up_iface->ui_pipelock);
+	if (pipe->up_iface) {
+		mutex_enter(>up_iface->ui_pipelock);
+		LIST_REMOVE(pipe, up_next);
+		mutex_exit(>up_iface->ui_pipelock);
+	}
 	usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 15:39:46 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c

Log Message:
usb(4): Fix fix for interface change pipe fix.

If there is an interface:
- Always put the pipe on the list in usbd_setup_pipe (if successful).
- Always have the pipe on the list from _before_ upm_open.
- Always keep the pipe on the list to _after_ upm_close, and after
  the async task has completed.

This brings the logic in usbd_close_pipe and usbd_kill_pipe closer.


To generate a diff of this commit:
cvs rdiff -u -r1.256 -r1.257 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.210 -r1.211 src/sys/dev/usb/usbdi.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.256 src/sys/dev/usb/usb_subr.c:1.257
--- src/sys/dev/usb/usb_subr.c:1.256	Sat Jun 12 14:43:27 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 15:39:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.256 2021/06/12 14:43:27 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.257 2021/06/12 15:39:46 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.256 2021/06/12 14:43:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.257 2021/06/12 15:39:46 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -840,10 +840,22 @@ usbd_setup_pipe_flags(struct usbd_device
 	p->up_interval = ival;
 	p->up_flags = flags;
 	SIMPLEQ_INIT(>up_queue);
+
+	if (iface) {
+		mutex_enter(>ui_pipelock);
+		LIST_INSERT_HEAD(>ui_pipes, p, up_next);
+		mutex_exit(>ui_pipelock);
+	}
+
 	err = dev->ud_bus->ub_methods->ubm_open(p);
 	if (err) {
 		DPRINTF("endpoint=%#jx failed, error=%jd",
 		(uintptr_t)ep->ue_edesc->bEndpointAddress, err, 0, 0);
+		if (iface) {
+			mutex_enter(>ui_pipelock);
+			LIST_REMOVE(p, up_next);
+			mutex_exit(>ui_pipelock);
+		}
 		kmem_free(p, dev->ud_bus->ub_pipesize);
 		usbd_endpoint_release(dev, ep);
 		return err;
@@ -898,6 +910,7 @@ usbd_kill_pipe(struct usbd_pipe *pipe)
 	usbd_unlock_pipe(pipe);
 	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
 	NULL);
+	KASSERT(pipe->up_iface == NULL);
 	usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 }

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.210 src/sys/dev/usb/usbdi.c:1.211
--- src/sys/dev/usb/usbdi.c:1.210	Sat Jun 12 15:09:18 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 15:39:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.210 2021/06/12 15:09:18 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.211 2021/06/12 15:39:46 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.210 2021/06/12 15:09:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.211 2021/06/12 15:39:46 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -244,9 +244,6 @@ usbd_open_pipe_ival(struct usbd_interfac
 	err = usbd_setup_pipe_flags(iface->ui_dev, iface, ep, ival, , flags);
 	if (err)
 		return err;
-	mutex_enter(>ui_pipelock);
-	LIST_INSERT_HEAD(>ui_pipes, p, up_next);
-	mutex_exit(>ui_pipelock);
 	*pipe = p;
 	SDT_PROBE5(usb, device, pipe, open,
 	iface, address, flags, ival, p);
@@ -320,11 +317,11 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 	usbd_unlock_pipe(pipe);
 	if (pipe->up_intrxfer != NULL)
 		usbd_destroy_xfer(pipe->up_intrxfer);
+	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
+	NULL);
 	mutex_enter(>up_iface->ui_pipelock);
 	LIST_REMOVE(pipe, up_next);
 	mutex_exit(>up_iface->ui_pipelock);
-	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
-	NULL);
 	usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 15:09:18 UTC 2021

Modified Files:
src/sys/dev/usb: usbdi.c

Log Message:
Revert "usb(4): Fix mistake in previous fix for pipe/interface-change races."

Little too fast on the commit trigger there before testing, oops.
We don't have the pipe yet until usbd_setup_pipe_flags returns!


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/dev/usb/usbdi.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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.209 src/sys/dev/usb/usbdi.c:1.210
--- src/sys/dev/usb/usbdi.c:1.209	Sat Jun 12 14:57:53 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 15:09:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.209 2021/06/12 14:57:53 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.210 2021/06/12 15:09:18 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.209 2021/06/12 14:57:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.210 2021/06/12 15:09:18 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -241,16 +241,12 @@ usbd_open_pipe_ival(struct usbd_interfac
 	}
 	return USBD_BAD_ADDRESS;
  found:
+	err = usbd_setup_pipe_flags(iface->ui_dev, iface, ep, ival, , flags);
+	if (err)
+		return err;
 	mutex_enter(>ui_pipelock);
 	LIST_INSERT_HEAD(>ui_pipes, p, up_next);
 	mutex_exit(>ui_pipelock);
-	err = usbd_setup_pipe_flags(iface->ui_dev, iface, ep, ival, , flags);
-	if (err) {
-		mutex_enter(>ui_pipelock);
-		LIST_REMOVE(p, up_next);
-		mutex_exit(>ui_pipelock);
-		return err;
-	}
 	*pipe = p;
 	SDT_PROBE5(usb, device, pipe, open,
 	iface, address, flags, ival, p);



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 14:57:53 UTC 2021

Modified Files:
src/sys/dev/usb: usbdi.c

Log Message:
usb(4): Fix mistake in previous fix for pipe/interface-change races.

Must block interface changes _before_ we enter usbd_setup_pipe_flags,
which calls the bus pipe open method.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/dev/usb/usbdi.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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.208 src/sys/dev/usb/usbdi.c:1.209
--- src/sys/dev/usb/usbdi.c:1.208	Sat Jun 12 14:43:27 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 14:57:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.208 2021/06/12 14:43:27 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.209 2021/06/12 14:57:53 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.208 2021/06/12 14:43:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.209 2021/06/12 14:57:53 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -241,12 +241,16 @@ usbd_open_pipe_ival(struct usbd_interfac
 	}
 	return USBD_BAD_ADDRESS;
  found:
-	err = usbd_setup_pipe_flags(iface->ui_dev, iface, ep, ival, , flags);
-	if (err)
-		return err;
 	mutex_enter(>ui_pipelock);
 	LIST_INSERT_HEAD(>ui_pipes, p, up_next);
 	mutex_exit(>ui_pipelock);
+	err = usbd_setup_pipe_flags(iface->ui_dev, iface, ep, ival, , flags);
+	if (err) {
+		mutex_enter(>ui_pipelock);
+		LIST_REMOVE(p, up_next);
+		mutex_exit(>ui_pipelock);
+		return err;
+	}
 	*pipe = p;
 	SDT_PROBE5(usb, device, pipe, open,
 	iface, address, flags, ival, p);



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 14:43:27 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c usbdivar.h

Log Message:
usb(4): Fix races between usbd_open_pipe* and usbd_set_interface.


To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.207 -r1.208 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.125 -r1.126 src/sys/dev/usb/usbdivar.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.255 src/sys/dev/usb/usb_subr.c:1.256
--- src/sys/dev/usb/usb_subr.c:1.255	Sat Jun 12 13:58:05 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 14:43:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.255 2021/06/12 13:58:05 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.256 2021/06/12 14:43:27 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.255 2021/06/12 13:58:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.256 2021/06/12 14:43:27 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -403,6 +403,39 @@ usbd_find_edesc(usb_config_descriptor_t 
 	return NULL;
 }
 
+static void
+usbd_iface_init(struct usbd_device *dev, int ifaceidx)
+{
+	struct usbd_interface *ifc = >ud_ifaces[ifaceidx];
+
+	memset(ifc, 0, sizeof(*ifc));
+
+	ifc->ui_dev = dev;
+	ifc->ui_idesc = NULL;
+	ifc->ui_index = 0;
+	ifc->ui_altindex = 0;
+	ifc->ui_endpoints = NULL;
+	ifc->ui_priv = NULL;
+	LIST_INIT(>ui_pipes);
+	mutex_init(>ui_pipelock, MUTEX_DEFAULT, IPL_NONE);
+}
+
+static void
+usbd_iface_fini(struct usbd_device *dev, int ifaceidx)
+{
+	struct usbd_interface *ifc = >ud_ifaces[ifaceidx];
+
+	KASSERT(ifc->ui_dev == dev);
+	KASSERT(ifc->ui_idesc == NULL);
+	KASSERT(ifc->ui_index == 0);
+	KASSERT(ifc->ui_altindex == 0);
+	KASSERT(ifc->ui_endpoints == NULL);
+	KASSERT(ifc->ui_priv == NULL);
+	KASSERT(LIST_EMPTY(>ui_pipes));
+
+	mutex_destroy(>ui_pipelock);
+}
+
 usbd_status
 usbd_fill_iface_data(struct usbd_device *dev, int ifaceidx, int altidx)
 {
@@ -414,10 +447,12 @@ usbd_fill_iface_data(struct usbd_device 
 	char *p, *end;
 	int endpt, nendpt;
 
+	KASSERT(ifc->ui_dev == dev);
+	KASSERT(LIST_EMPTY(>ui_pipes));
+
 	idesc = usbd_find_idesc(dev->ud_cdesc, ifaceidx, altidx);
 	if (idesc == NULL)
 		return USBD_INVAL;
-	ifc->ui_dev = dev;
 	ifc->ui_idesc = idesc;
 	ifc->ui_index = ifaceidx;
 	ifc->ui_altindex = altidx;
@@ -488,7 +523,6 @@ usbd_fill_iface_data(struct usbd_device 
 		p += ed->bLength;
 	}
 #undef ed
-	LIST_INIT(>ui_pipes);
 	return USBD_NORMAL_COMPLETION;
 
  bad:
@@ -499,16 +533,25 @@ usbd_fill_iface_data(struct usbd_device 
 	return USBD_INVAL;
 }
 
-void
+Static void
 usbd_free_iface_data(struct usbd_device *dev, int ifcno)
 {
 	struct usbd_interface *ifc = >ud_ifaces[ifcno];
+
+	KASSERT(ifc->ui_dev == dev);
+	KASSERT(ifc->ui_idesc != NULL);
+	KASSERT(LIST_EMPTY(>ui_pipes));
+
 	if (ifc->ui_endpoints) {
 		int nendpt = ifc->ui_idesc->bNumEndpoints;
 		size_t sz = nendpt * sizeof(struct usbd_endpoint);
 		kmem_free(ifc->ui_endpoints, sz);
 		ifc->ui_endpoints = NULL;
 	}
+
+	ifc->ui_altindex = 0;
+	ifc->ui_index = 0;
+	ifc->ui_idesc = NULL;
 }
 
 usbd_status
@@ -557,8 +600,10 @@ usbd_set_config_index(struct usbd_device
 		DPRINTF("free old config", 0, 0, 0, 0);
 		/* Free all configuration data structures. */
 		nifc = dev->ud_cdesc->bNumInterface;
-		for (ifcidx = 0; ifcidx < nifc; ifcidx++)
+		for (ifcidx = 0; ifcidx < nifc; ifcidx++) {
 			usbd_free_iface_data(dev, ifcidx);
+			usbd_iface_fini(dev, ifcidx);
+		}
 		kmem_free(dev->ud_ifaces, nifc * sizeof(struct usbd_interface));
 		kmem_free(dev->ud_cdesc, UGETW(dev->ud_cdesc->wTotalLength));
 		if (dev->ud_bdesc != NULL)
@@ -730,10 +775,13 @@ usbd_set_config_index(struct usbd_device
 	dev->ud_cdesc = cdp;
 	dev->ud_config = cdp->bConfigurationValue;
 	for (ifcidx = 0; ifcidx < nifc; ifcidx++) {
+		usbd_iface_init(dev, ifcidx);
 		err = usbd_fill_iface_data(dev, ifcidx, 0);
 		if (err) {
-			while (--ifcidx >= 0)
+			while (--ifcidx >= 0) {
 usbd_free_iface_data(dev, ifcidx);
+usbd_iface_fini(dev, ifcidx);
+			}
 			kmem_free(dev->ud_ifaces,
 			nifc * sizeof(struct usbd_interface));
 			dev->ud_ifaces = NULL;
@@ -1649,8 +1697,10 @@ usb_free_device(struct usbd_device *dev)
 		usbd_kill_pipe(dev->ud_pipe0);
 	if (dev->ud_ifaces != NULL) {
 		nifc = dev->ud_cdesc->bNumInterface;
-		for (ifcidx = 0; ifcidx < nifc; ifcidx++)
+		for (ifcidx = 0; ifcidx < nifc; ifcidx++) {
 			usbd_free_iface_data(dev, ifcidx);
+			usbd_iface_fini(dev, ifcidx);
+		}
 		kmem_free(dev->ud_ifaces,
 		nifc * sizeof(struct usbd_interface));
 	}

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.207 src/sys/dev/usb/usbdi.c:1.208
--- 

CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 13:58:06 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c usbdi.c usbdivar.h xhci.c

Log Message:
usb(4): Fix racy endpoint reference counting.

Rules:

1. After usbd_setup_pipe*, must usbd_kill_pipe.
2. After usbd_open_pipe*, must usbd_close_pipe.

Still haven't merged the logic in usbd_kill_pipe and usbd_close_pipe,
but getting closer.


To generate a diff of this commit:
cvs rdiff -u -r1.254 -r1.255 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.206 -r1.207 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.124 -r1.125 src/sys/dev/usb/usbdivar.h
cvs rdiff -u -r1.145 -r1.146 src/sys/dev/usb/xhci.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.254 src/sys/dev/usb/usb_subr.c:1.255
--- src/sys/dev/usb/usb_subr.c:1.254	Sat Jun 12 12:13:23 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 13:58:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.254 2021/06/12 12:13:23 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.255 2021/06/12 13:58:05 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.254 2021/06/12 12:13:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.255 2021/06/12 13:58:05 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -775,12 +775,15 @@ usbd_setup_pipe_flags(struct usbd_device
 	struct usbd_pipe *p;
 	usbd_status err;
 
+	err = usbd_endpoint_acquire(dev, ep, flags & USBD_EXCLUSIVE_USE);
+	if (err)
+		return err;
+
 	p = kmem_alloc(dev->ud_bus->ub_pipesize, KM_SLEEP);
 	DPRINTFN(1, "pipe=%#jx", (uintptr_t)p, 0, 0, 0);
 	p->up_dev = dev;
 	p->up_iface = iface;
 	p->up_endpoint = ep;
-	ep->ue_refcnt++;
 	p->up_intrxfer = NULL;
 	p->up_running = 0;
 	p->up_aborting = 0;
@@ -794,6 +797,7 @@ usbd_setup_pipe_flags(struct usbd_device
 		DPRINTF("endpoint=%#jx failed, error=%jd",
 		(uintptr_t)ep->ue_edesc->bEndpointAddress, err, 0, 0);
 		kmem_free(p, dev->ud_bus->ub_pipesize);
+		usbd_endpoint_release(dev, ep);
 		return err;
 	}
 
@@ -806,6 +810,36 @@ usbd_setup_pipe_flags(struct usbd_device
 	return USBD_NORMAL_COMPLETION;
 }
 
+usbd_status
+usbd_endpoint_acquire(struct usbd_device *dev, struct usbd_endpoint *ep,
+int flags)
+{
+	usbd_status err;
+
+	mutex_enter(dev->ud_bus->ub_lock);
+	if (ep->ue_refcnt == INT_MAX) {
+		err = USBD_IN_USE; /* XXX rule out or switch to 64-bit */
+	} else if ((flags & USBD_EXCLUSIVE_USE) && ep->ue_refcnt) {
+		err = USBD_IN_USE;
+	} else {
+		ep->ue_refcnt++;
+		err = 0;
+	}
+	mutex_exit(dev->ud_bus->ub_lock);
+
+	return err;
+}
+
+void
+usbd_endpoint_release(struct usbd_device *dev, struct usbd_endpoint *ep)
+{
+
+	mutex_enter(dev->ud_bus->ub_lock);
+	KASSERT(ep->ue_refcnt);
+	ep->ue_refcnt--;
+	mutex_exit(dev->ud_bus->ub_lock);
+}
+
 /* Abort the device control pipe. */
 void
 usbd_kill_pipe(struct usbd_pipe *pipe)
@@ -816,7 +850,7 @@ usbd_kill_pipe(struct usbd_pipe *pipe)
 	usbd_unlock_pipe(pipe);
 	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
 	NULL);
-	pipe->up_endpoint->ue_refcnt--;
+	usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 }
 

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.206 src/sys/dev/usb/usbdi.c:1.207
--- src/sys/dev/usb/usbdi.c:1.206	Sat Jun 12 13:57:51 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 13:58:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.206 2021/06/12 13:57:51 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.207 2021/06/12 13:58:05 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.206 2021/06/12 13:57:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.207 2021/06/12 13:58:05 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -241,8 +241,6 @@ usbd_open_pipe_ival(struct usbd_interfac
 	}
 	return USBD_BAD_ADDRESS;
  found:
-	if ((flags & USBD_EXCLUSIVE_USE) && ep->ue_refcnt != 0)
-		return USBD_IN_USE;
 	err = usbd_setup_pipe_flags(iface->ui_dev, iface, ep, ival, , flags);
 	if (err)
 		return err;
@@ -316,7 +314,6 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 	KASSERT(SIMPLEQ_EMPTY(>up_queue));
 
 	LIST_REMOVE(pipe, up_next);
-	pipe->up_endpoint->ue_refcnt--;
 
 	pipe->up_methods->upm_close(pipe);
 
@@ -325,6 +322,7 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 		usbd_destroy_xfer(pipe->up_intrxfer);
 	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
 	NULL);
+	usbd_endpoint_release(pipe->up_dev, pipe->up_endpoint);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 
 	return USBD_NORMAL_COMPLETION;

Index: src/sys/dev/usb/usbdivar.h
diff -u 

CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 13:57:51 UTC 2021

Modified Files:
src/sys/dev/usb: usbdi.c

Log Message:
usb(4): Omit needless lock/unlock cycle in usbd_pipe_close.

pipe->up_intrxfer is stable after construction, so no need to hold
the lock to check it.


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/dev/usb/usbdi.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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.205 src/sys/dev/usb/usbdi.c:1.206
--- src/sys/dev/usb/usbdi.c:1.205	Sat Jun 12 13:57:40 2021
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 13:57:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.205 2021/06/12 13:57:40 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.206 2021/06/12 13:57:51 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.205 2021/06/12 13:57:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.206 2021/06/12 13:57:51 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -320,13 +320,9 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 
 	pipe->up_methods->upm_close(pipe);
 
-	if (pipe->up_intrxfer != NULL) {
-		usbd_unlock_pipe(pipe);
-		usbd_destroy_xfer(pipe->up_intrxfer);
-		usbd_lock_pipe(pipe);
-	}
-
 	usbd_unlock_pipe(pipe);
+	if (pipe->up_intrxfer != NULL)
+		usbd_destroy_xfer(pipe->up_intrxfer);
 	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
 	NULL);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 13:57:40 UTC 2021

Modified Files:
src/sys/dev/usb: usbdi.c

Log Message:
usb(4): Cancel and wait for async task on closing pipe.

XXX usbd_kill_pipe and usbd_close_pipe should not be copypasta; there
should be only one instance of this logic.


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 src/sys/dev/usb/usbdi.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/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.204 src/sys/dev/usb/usbdi.c:1.205
--- src/sys/dev/usb/usbdi.c:1.204	Wed Aug 19 02:19:07 2020
+++ src/sys/dev/usb/usbdi.c	Sat Jun 12 13:57:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.204 2020/08/19 02:19:07 msaitoh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.205 2021/06/12 13:57:40 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.204 2020/08/19 02:19:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.205 2021/06/12 13:57:40 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -327,6 +327,8 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 	}
 
 	usbd_unlock_pipe(pipe);
+	usb_rem_task_wait(pipe->up_dev, >up_async_task, USB_TASKQ_DRIVER,
+	NULL);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 
 	return USBD_NORMAL_COMPLETION;



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 12:13:23 UTC 2021

Modified Files:
src/sys/dev/usb: uhub.c usb_subr.c

Log Message:
usb(4), uhub(4): Sprinkle usbhist.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.253 -r1.254 src/sys/dev/usb/usb_subr.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/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.149 src/sys/dev/usb/uhub.c:1.150
--- src/sys/dev/usb/uhub.c:1.149	Sat Jun 12 12:13:10 2021
+++ src/sys/dev/usb/uhub.c	Sat Jun 12 12:13:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.149 2021/06/12 12:13:10 riastradh Exp $	*/
+/*	$NetBSD: uhub.c,v 1.150 2021/06/12 12:13:23 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.149 2021/06/12 12:13:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.150 2021/06/12 12:13:23 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -932,6 +932,9 @@ uhub_rescan(device_t self, const char *i
 	struct usbd_device *dev;
 	int port;
 
+	UHUBHIST_FUNC();
+	UHUBHIST_CALLARGS("uhub%jd", device_unit(sc->sc_dev), 0, 0, 0);
+
 	KASSERT(KERNEL_LOCKED_P());
 
 	if (uhub_explore_enter(sc) != 0)

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.253 src/sys/dev/usb/usb_subr.c:1.254
--- src/sys/dev/usb/usb_subr.c:1.253	Sat Jun 12 12:13:10 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 12:13:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.253 2021/06/12 12:13:10 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.254 2021/06/12 12:13:23 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.253 2021/06/12 12:13:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.254 2021/06/12 12:13:23 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1116,6 +1116,10 @@ usbd_reattach_device(device_t parent, st
 {
 	int i, loc;
 
+	USBHIST_FUNC();
+	USBHIST_CALLARGS(usbdebug, "uhub%jd port=%jd",
+	device_unit(parent), port, 0, 0);
+
 	KASSERT(KERNEL_LOCKED_P());
 
 	if (locators != NULL) {



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 12:13:11 UTC 2021

Modified Files:
src/sys/dev/usb: uhub.c usb.c usb_subr.c xhci.c

Log Message:
usb(4): Sprinkle kernel lock assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.194 -r1.195 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.252 -r1.253 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.144 -r1.145 src/sys/dev/usb/xhci.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/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.148 src/sys/dev/usb/uhub.c:1.149
--- src/sys/dev/usb/uhub.c:1.148	Sat Jun 12 12:11:01 2021
+++ src/sys/dev/usb/uhub.c	Sat Jun 12 12:13:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.148 2021/06/12 12:11:01 riastradh Exp $	*/
+/*	$NetBSD: uhub.c,v 1.149 2021/06/12 12:13:10 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.148 2021/06/12 12:11:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.149 2021/06/12 12:13:10 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -533,6 +533,8 @@ uhub_explore(struct usbd_device *dev)
 	device_unit(sc->sc_dev), (uintptr_t)dev, dev->ud_addr,
 	dev->ud_speed);
 
+	KASSERT(KERNEL_LOCKED_P());
+
 	if (!sc->sc_running)
 		return USBD_NOT_STARTED;
 
@@ -930,6 +932,8 @@ uhub_rescan(device_t self, const char *i
 	struct usbd_device *dev;
 	int port;
 
+	KASSERT(KERNEL_LOCKED_P());
+
 	if (uhub_explore_enter(sc) != 0)
 		return EBUSY;
 	for (port = 1; port <= hub->uh_hubdesc.bNbrPorts; port++) {
@@ -953,6 +957,8 @@ uhub_childdet(device_t self, device_t ch
 	int port;
 	int i;
 
+	KASSERT(KERNEL_LOCKED_P());
+
 	if (!devhub->ud_hub)
 		/* should never happen; children are only created after init */
 		panic("hub not fully initialised, but child deleted?");

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.194 src/sys/dev/usb/usb.c:1.195
--- src/sys/dev/usb/usb.c:1.194	Sat Jun 12 12:11:38 2021
+++ src/sys/dev/usb/usb.c	Sat Jun 12 12:13:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.194 2021/06/12 12:11:38 riastradh Exp $	*/
+/*	$NetBSD: usb.c,v 1.195 2021/06/12 12:13:10 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.194 2021/06/12 12:11:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.195 2021/06/12 12:13:10 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -453,6 +453,8 @@ usb_doattach(device_t self)
 
 	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
 
+	KASSERT(KERNEL_LOCKED_P());
+
 	/* Protected by KERNEL_LOCK */
 	nusbbusses++;
 
@@ -690,6 +692,8 @@ usb_event_thread(void *arg)
 
 	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
 
+	KASSERT(KERNEL_LOCKED_P());
+
 	/*
 	 * In case this controller is a companion controller to an
 	 * EHCI controller we need to wait until the EHCI controller
@@ -1146,6 +1150,7 @@ usb_discover(struct usb_softc *sc)
 
 	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
 
+	KASSERT(KERNEL_LOCKED_P());
 	KASSERT(mutex_owned(bus->ub_lock));
 
 	if (usb_noexplore > 1)

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.252 src/sys/dev/usb/usb_subr.c:1.253
--- src/sys/dev/usb/usb_subr.c:1.252	Sat Jun 12 12:11:27 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 12:13:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.252 2021/06/12 12:11:27 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.253 2021/06/12 12:13:10 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.252 2021/06/12 12:11:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.253 2021/06/12 12:13:10 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -957,6 +957,9 @@ usbd_attachinterfaces(device_t parent, s
 	int i, j, loc;
 	device_t dv;
 
+	/* Needed for access to dev->ud_subdevs.  */
+	KASSERT(KERNEL_LOCKED_P());
+
 	nifaces = dev->ud_cdesc->bNumInterface;
 	ifaces = kmem_zalloc(nifaces * sizeof(*ifaces), KM_SLEEP);
 	for (i = 0; i < nifaces; i++) {
@@ -1047,6 +1050,8 @@ usbd_probe_and_attach(device_t parent, s
 	int confi, nifaces;
 	usbd_status err;
 
+	KASSERT(KERNEL_LOCKED_P());
+
 	/* First try with device specific drivers. */
 	err = usbd_attachwholedevice(parent, dev, port, 0);
 	if (dev->ud_nifaces_claimed || err)
@@ -,6 +1116,8 @@ usbd_reattach_device(device_t parent, st
 {
 	int i, loc;
 
+	KASSERT(KERNEL_LOCKED_P());
+
 	if (locators != NULL) {
 		loc = locators[USBIFIFCF_PORT];
 		if (loc != USBIFIFCF_PORT_DEFAULT && loc != port)
@@ -1169,6 +1176,8 @@ usbd_new_device(device_t 

CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 12:11:38 UTC 2021

Modified Files:
src/sys/dev/usb: usb.c

Log Message:
usb(4): usb event thread is not actually MP-safe.

Still requires a lot of work in usb(4), uhub(4), and autoconf(9).


To generate a diff of this commit:
cvs rdiff -u -r1.193 -r1.194 src/sys/dev/usb/usb.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/usb.c
diff -u src/sys/dev/usb/usb.c:1.193 src/sys/dev/usb/usb.c:1.194
--- src/sys/dev/usb/usb.c:1.193	Wed Feb 24 01:46:57 2021
+++ src/sys/dev/usb/usb.c	Sat Jun 12 12:11:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.193 2021/02/24 01:46:57 mrg Exp $	*/
+/*	$NetBSD: usb.c,v 1.194 2021/06/12 12:11:38 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.193 2021/02/24 01:46:57 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.194 2021/06/12 12:11:38 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -518,7 +518,7 @@ usb_create_event_thread(device_t self)
 {
 	struct usb_softc *sc = device_private(self);
 
-	if (kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
+	if (kthread_create(PRI_NONE, 0, NULL,
 	usb_event_thread, sc, >sc_event_thread,
 	"%s", device_xname(self))) {
 		printf("%s: unable to create event thread for\n",



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 12:11:28 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
usb(4): Verify dev->ud_subdevs is still there before freeing it.

usbd_attachinterfaces may sleep, and if it does, it releases the
kernel lock, in which case another thread may free dev->ud_subdevs.


To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/sys/dev/usb/usb_subr.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.251 src/sys/dev/usb/usb_subr.c:1.252
--- src/sys/dev/usb/usb_subr.c:1.251	Sat Jun 12 12:11:11 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 12:11:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.251 2021/06/12 12:11:11 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.252 2021/06/12 12:11:27 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.251 2021/06/12 12:11:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.252 2021/06/12 12:11:27 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1072,7 +1072,7 @@ usbd_probe_and_attach(device_t parent, s
 
 		err = usbd_attachinterfaces(parent, dev, port, NULL);
 
-		if (!dev->ud_nifaces_claimed) {
+		if (dev->ud_subdevs && dev->ud_nifaces_claimed == 0) {
 			kmem_free(dev->ud_subdevs,
 			dev->ud_subdevlen * sizeof(device_t));
 			dev->ud_subdevs = 0;



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 12:11:11 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
usb(4): kmem_zalloc(KM_SLEEP) cannot fail; nix error branch.


To generate a diff of this commit:
cvs rdiff -u -r1.250 -r1.251 src/sys/dev/usb/usb_subr.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.250 src/sys/dev/usb/usb_subr.c:1.251
--- src/sys/dev/usb/usb_subr.c:1.250	Sat Apr 24 23:36:59 2021
+++ src/sys/dev/usb/usb_subr.c	Sat Jun 12 12:11:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.250 2021/04/24 23:36:59 thorpej Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.251 2021/06/12 12:11:11 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.250 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.251 2021/06/12 12:11:11 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1068,8 +1068,6 @@ usbd_probe_and_attach(device_t parent, s
 		nifaces = dev->ud_cdesc->bNumInterface;
 		dev->ud_subdevs = kmem_zalloc(nifaces * sizeof(device_t),
 		KM_SLEEP);
-		if (dev->ud_subdevs == NULL)
-			return USBD_NOMEM;
 		dev->ud_subdevlen = nifaces;
 
 		err = usbd_attachinterfaces(parent, dev, port, NULL);



CVS commit: src/sys/dev/usb

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 12:11:01 UTC 2021

Modified Files:
src/sys/dev/usb: uhub.c

Log Message:
uhub(4): Allow only one explore/rescan at a time.

Otherwise we might simultaneously attach two autoconf instances of
the same device, which leads to no good.


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 src/sys/dev/usb/uhub.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/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.147 src/sys/dev/usb/uhub.c:1.148
--- src/sys/dev/usb/uhub.c:1.147	Fri Jun  5 17:20:56 2020
+++ src/sys/dev/usb/uhub.c	Sat Jun 12 12:11:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.147 2020/06/05 17:20:56 maxv Exp $	*/
+/*	$NetBSD: uhub.c,v 1.148 2021/06/12 12:11:01 riastradh Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.147 2020/06/05 17:20:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.148 2021/06/12 12:11:01 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -110,6 +110,7 @@ struct uhub_softc {
 	struct usbd_pipe	*sc_ipipe;	/* interrupt pipe */
 
 	kmutex_t		 sc_lock;
+	kcondvar_t		 sc_cv;
 
 	uint8_t			*sc_statusbuf;
 	uint8_t			*sc_statuspend;
@@ -118,6 +119,8 @@ struct uhub_softc {
 	bool			 sc_explorepending;
 	bool			 sc_first_explore;
 	bool			 sc_running;
+
+	struct lwp		*sc_exploring;
 };
 
 #define UHUB_IS_HIGH_SPEED(sc) \
@@ -127,6 +130,8 @@ struct uhub_softc {
 #define PORTSTAT_ISSET(sc, port) \
 	((sc)->sc_status[(port) / 8] & (1 << ((port) % 8)))
 
+Static usbd_status uhub_explore_enter(struct uhub_softc *);
+Static void uhub_explore_exit(struct uhub_softc *);
 Static usbd_status uhub_explore(struct usbd_device *);
 Static void uhub_intr(struct usbd_xfer *, void *, usbd_status);
 
@@ -365,6 +370,7 @@ uhub_attach(device_t parent, device_t se
 	sc->sc_statuspend = kmem_zalloc(sc->sc_statuslen, KM_SLEEP);
 	sc->sc_status = kmem_alloc(sc->sc_statuslen, KM_SLEEP);
 	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB);
+	cv_init(>sc_cv, "uhubex");
 
 	/* force initial scan */
 	memset(sc->sc_status, 0xff, sc->sc_statuslen);
@@ -476,6 +482,41 @@ uhub_attach(device_t parent, device_t se
 	config_pending_decr(self);
 }
 
+Static usbd_status
+uhub_explore_enter(struct uhub_softc *sc)
+{
+	usbd_status err;
+
+	mutex_enter(>sc_lock);
+	for (;;) {
+		if (sc->sc_exploring == NULL) {
+			sc->sc_exploring = curlwp;
+			err = 0;
+			break;
+		}
+		KASSERT(sc->sc_exploring != curlwp);
+		if (cv_wait_sig(>sc_cv, >sc_lock)) {
+			err = USBD_INTERRUPTED;
+			break;
+		}
+	}
+	mutex_exit(>sc_lock);
+
+	return err;
+}
+
+Static void
+uhub_explore_exit(struct uhub_softc *sc)
+{
+
+	mutex_enter(>sc_lock);
+	KASSERTMSG(sc->sc_exploring == curlwp, "lwp %p exploring %s",
+	sc->sc_exploring, device_xname(sc->sc_dev));
+	sc->sc_exploring = NULL;
+	cv_broadcast(>sc_cv);
+	mutex_exit(>sc_lock);
+}
+
 usbd_status
 uhub_explore(struct usbd_device *dev)
 {
@@ -499,6 +540,11 @@ uhub_explore(struct usbd_device *dev)
 	if (dev->ud_depth > USB_HUB_MAX_DEPTH)
 		return USBD_TOO_DEEP;
 
+	/* Only one explore at a time, please.  */
+	err = uhub_explore_enter(sc);
+	if (err)
+		return err;
+
 	if (PORTSTAT_ISSET(sc, 0)) { /* hub status change */
 		usb_hub_status_t hs;
 
@@ -803,6 +849,7 @@ uhub_explore(struct usbd_device *dev)
 		}
 	}
 	mutex_exit(>sc_lock);
+	uhub_explore_exit(sc);
 	if (sc->sc_first_explore) {
 		config_pending_decr(sc->sc_dev);
 		sc->sc_first_explore = false;
@@ -866,6 +913,7 @@ uhub_detach(device_t self, int flags)
 	if (sc->sc_statusbuf)
 		kmem_free(sc->sc_statusbuf, sc->sc_statuslen);
 
+	cv_destroy(>sc_cv);
 	mutex_destroy(>sc_lock);
 
 	/* XXXSMP usb */
@@ -882,12 +930,15 @@ uhub_rescan(device_t self, const char *i
 	struct usbd_device *dev;
 	int port;
 
+	if (uhub_explore_enter(sc) != 0)
+		return EBUSY;
 	for (port = 1; port <= hub->uh_hubdesc.bNbrPorts; port++) {
 		dev = hub->uh_ports[port - 1].up_dev;
 		if (dev == NULL)
 			continue;
 		usbd_reattach_device(sc->sc_dev, dev, port, locators);
 	}
+	uhub_explore_exit(sc);
 	return 0;
 }
 



CVS commit: src/sys/dev/usb

2021-06-06 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Jun  6 18:37:20 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c

Log Message:
also reset xs->xs_xr[dci] to NULL when closing the pipe

avoids KASSERT() on next xhci_open()

should fix PR kern/56194 by nia


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/sys/dev/usb/xhci.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.143 src/sys/dev/usb/xhci.c:1.144
--- src/sys/dev/usb/xhci.c:1.143	Sat May 29 16:49:30 2021
+++ src/sys/dev/usb/xhci.c	Sun Jun  6 18:37:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.143 2021/05/29 16:49:30 riastradh Exp $	*/
+/*	$NetBSD: xhci.c,v 1.144 2021/06/06 18:37:20 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.143 2021/05/29 16:49:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.144 2021/06/06 18:37:20 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2159,6 +2159,7 @@ xhci_close_pipe(struct usbd_pipe *pipe)
 	usb_syncmem(>xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD);
 
 	xhci_ring_free(sc, >xs_xr[dci]);
+	xs->xs_xr[dci] = NULL;
 }
 
 /*



CVS commit: src/sys/dev/usb

2021-05-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May 29 16:49:30 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c

Log Message:
xhci(4): Wait USB_RESUME_WAIT ms, not 20 ms.

Better to use the named constant, and although the spec says 20 ms is
enough, apparently for some devices it's not.


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/dev/usb/xhci.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.142 src/sys/dev/usb/xhci.c:1.143
--- src/sys/dev/usb/xhci.c:1.142	Thu May 27 11:09:15 2021
+++ src/sys/dev/usb/xhci.c	Sat May 29 16:49:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.142 2021/05/27 11:09:15 skrll Exp $	*/
+/*	$NetBSD: xhci.c,v 1.143 2021/05/29 16:49:30 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.142 2021/05/27 11:09:15 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.143 2021/05/29 16:49:30 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1027,7 +1027,7 @@ xhci_resume(device_t self, const pmf_qua
 v |= XHCI_PS_LWS;
 v |= XHCI_PS_PLS_SET(XHCI_PS_PLS_SETRESUME);
 xhci_op_write_4(sc, port, v);
-usb_delay_ms(>sc_bus, 20);
+usb_delay_ms(>sc_bus, USB_RESUME_WAIT);
 			} else {
 KASSERT(sc->sc_bus.ub_revision > USBREV_2_0);
 			}



CVS commit: src/sys/dev/usb

2021-05-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May 29 08:45:19 UTC 2021

Modified Files:
src/sys/dev/usb: ualea.c

Log Message:
ualea(4): Null suspend/resume handler.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/usb/ualea.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/ualea.c
diff -u src/sys/dev/usb/ualea.c:1.12 src/sys/dev/usb/ualea.c:1.13
--- src/sys/dev/usb/ualea.c:1.12	Mon Jul 13 13:53:04 2020
+++ src/sys/dev/usb/ualea.c	Sat May 29 08:45:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ualea.c,v 1.12 2020/07/13 13:53:04 simonb Exp $	*/
+/*	$NetBSD: ualea.c,v 1.13 2021/05/29 08:45:19 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.12 2020/07/13 13:53:04 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.13 2021/05/29 08:45:19 riastradh Exp $");
 
 #include 
 #include 
@@ -139,6 +139,10 @@ ualea_attach(device_t parent, device_t s
 		return;
 	}
 
+	if (!pmf_device_register(self, NULL, NULL))
+		aprint_error_dev(sc->sc_dev, "failed to register power handler"
+		"\n");
+
 	/* Success!  We are ready to run.  */
 	sc->sc_attached = true;
 	rndsource_setcb(>sc_rnd, ualea_get, sc);



CVS commit: src/sys/dev/usb

2021-05-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu May 27 11:09:15 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c

Log Message:
Fix error handling botch in 1.138. Thanks to jmcneill@ for spotting it.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/dev/usb/xhci.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.141 src/sys/dev/usb/xhci.c:1.142
--- src/sys/dev/usb/xhci.c:1.141	Wed May 26 22:37:21 2021
+++ src/sys/dev/usb/xhci.c	Thu May 27 11:09:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.141 2021/05/26 22:37:21 riastradh Exp $	*/
+/*	$NetBSD: xhci.c,v 1.142 2021/05/27 11:09:15 skrll Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.141 2021/05/26 22:37:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.142 2021/05/27 11:09:15 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -3437,7 +3437,7 @@ xhci_init_slot(struct usbd_device *dev, 
 	if (err) {
 		DPRINTFN(1, "failed to allocmem input device context %jd",
 		err, 0, 0, 0);
-		return USBD_NOMEM;
+		goto bad1;
 	}
 
 	memset(>xs_xr[0], 0, sizeof(xs->xs_xr));
@@ -3445,6 +3445,7 @@ xhci_init_slot(struct usbd_device *dev, 
 
 	return USBD_NORMAL_COMPLETION;
 
+bad1:
 	usb_freemem(>sc_bus, >xs_dc_dma);
 	xs->xs_idx = 0;
 	return USBD_NOMEM;



CVS commit: src/sys/dev/usb

2021-05-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu May 27 10:44:29 UTC 2021

Modified Files:
src/sys/dev/usb: usb_mem.c

Log Message:
Honour USBMALLOC_ZERO when reusing blocks from the freelist.

>From sc.dying on tech-kern


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/usb/usb_mem.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/usb_mem.c
diff -u src/sys/dev/usb/usb_mem.c:1.80 src/sys/dev/usb/usb_mem.c:1.81
--- src/sys/dev/usb/usb_mem.c:1.80	Tue Jan  5 18:00:21 2021
+++ src/sys/dev/usb/usb_mem.c	Thu May 27 10:44:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_mem.c,v 1.80 2021/01/05 18:00:21 skrll Exp $	*/
+/*	$NetBSD: usb_mem.c,v 1.81 2021/05/27 10:44:29 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.80 2021/01/05 18:00:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.81 2021/05/27 10:44:29 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -118,8 +118,13 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 	KASSERT(size != 0);
 	KASSERT(mutex_owned(_blk_lock));
 
+#ifdef USB_FRAG_DMA_WORKAROUND
+	flags |= USBMALLOC_ZERO;
+#endif
+
 	bool multiseg = (flags & USBMALLOC_MULTISEG) != 0;
 	bool coherent = (flags & USBMALLOC_COHERENT) != 0;
+	bool zero = (flags & USBMALLOC_ZERO) != 0;
 	u_int dmaflags = coherent ? USB_DMA_COHERENT : 0;
 
 	/* First check the free list. */
@@ -134,6 +139,11 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 			LIST_REMOVE(b, next);
 			usb_blk_nfree--;
 			*dmap = b;
+			if (zero) {
+memset(b->kaddr, 0, b->size);
+bus_dmamap_sync(b->tag, b->map, 0, b->size,
+BUS_DMASYNC_PREWRITE);
+			}
 			DPRINTFN(6, "free list size=%ju", b->size, 0, 0, 0);
 			return 0;
 		}
@@ -180,10 +190,7 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 
 	*dmap = b;
 
-#ifdef USB_FRAG_DMA_WORKAROUND
-	flags |= USBMALLOC_ZERO;
-#endif
-	if ((flags & USBMALLOC_ZERO) != 0) {
+	if (zero) {
 		memset(b->kaddr, 0, b->size);
 		bus_dmamap_sync(b->tag, b->map, 0, b->size,
 		BUS_DMASYNC_PREWRITE);



CVS commit: src/sys/dev/usb

2021-05-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 26 22:37:21 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c

Log Message:
xhci: Fix logic in waiting for command queue access.

_Either_ an existing command in progress, _or_ an existing suspend in
progress that is not done by us, should block us; the logic I wrote
previously erroneously blocked only if both conditions happened at
the same time.

Should fix issue reported by Andrius V in the PR kern/56050 followup
discussion.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/dev/usb/xhci.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.140 src/sys/dev/usb/xhci.c:1.141
--- src/sys/dev/usb/xhci.c:1.140	Sun May 23 21:12:28 2021
+++ src/sys/dev/usb/xhci.c	Wed May 26 22:37:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.140 2021/05/23 21:12:28 riastradh Exp $	*/
+/*	$NetBSD: xhci.c,v 1.141 2021/05/26 22:37:21 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.140 2021/05/23 21:12:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.141 2021/05/26 22:37:21 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -3194,9 +3194,8 @@ xhci_do_command_locked(struct xhci_softc
 	KASSERTMSG(!cpu_intr_p() && !cpu_softintr_p(), "called from intr ctx");
 	KASSERT(mutex_owned(>sc_lock));
 
-	while (sc->sc_command_addr != 0 &&
-	sc->sc_suspender != NULL &&
-	sc->sc_suspender != curlwp)
+	while (sc->sc_command_addr != 0 ||
+	(sc->sc_suspender != NULL && sc->sc_suspender != curlwp))
 		cv_wait(>sc_cmdbusy_cv, >sc_lock);
 
 	/*



CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 21:12:29 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c xhcivar.h

Log Message:
xhci(4): Block commands and issue Stop Endpoint on suspend.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/usb/xhcivar.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.139 src/sys/dev/usb/xhci.c:1.140
--- src/sys/dev/usb/xhci.c:1.139	Sun May 23 11:49:45 2021
+++ src/sys/dev/usb/xhci.c	Sun May 23 21:12:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $	*/
+/*	$NetBSD: xhci.c,v 1.140 2021/05/23 21:12:28 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.140 2021/05/23 21:12:28 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -157,6 +157,8 @@ static int xhci_roothub_ctrl(struct usbd
 static usbd_status xhci_configure_endpoint(struct usbd_pipe *);
 //static usbd_status xhci_unconfigure_endpoint(struct usbd_pipe *);
 static usbd_status xhci_reset_endpoint(struct usbd_pipe *);
+static usbd_status xhci_stop_endpoint_cmd(struct xhci_softc *,
+struct xhci_slot *, u_int, uint32_t);
 static usbd_status xhci_stop_endpoint(struct usbd_pipe *);
 
 static void xhci_host_dequeue(struct xhci_ring * const);
@@ -699,14 +701,70 @@ bool
 xhci_suspend(device_t self, const pmf_qual_t *qual)
 {
 	struct xhci_softc * const sc = device_private(self);
-	size_t i, j, bn;
+	size_t i, j, bn, dci;
 	int port;
 	uint32_t v;
+	usbd_status err;
+	bool ok = false;
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
+	mutex_enter(>sc_lock);
+
+	/*
+	 * Block issuance of new commands, and wait for all pending
+	 * commands to complete.
+	 */
+	KASSERT(sc->sc_suspender == NULL);
+	sc->sc_suspender = curlwp;
+	while (sc->sc_command_addr != 0)
+		cv_wait(>sc_cmdbusy_cv, >sc_lock);
+
+	/*
+	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
+	 * xHCI Power Management, p. 342
+	 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342
+	 */
+
+	/*
+	 * `1. Stop all USB activity by issuing Stop Endpoint Commands
+	 * for Busy endpoints in the Running state.  If the Force
+	 * Save Context Capability (FSC = ``0'') is not supported,
+	 * then Stop Endpoint Commands shall be issued for all idle
+	 * endpoints in the Running state as well.  The Stop
+	 * Endpoint Command causes the xHC to update the respective
+	 * Endpoint or Stream Contexts in system memory, e.g. the
+	 * TR Dequeue Pointer, DCS, etc. fields.  Refer to
+	 * Implementation Note "0".'
+	 */
+	for (i = 0; i < sc->sc_maxslots; i++) {
+		struct xhci_slot *xs = >sc_slots[i];
+
+		/* Skip if the slot is not in use.  */
+		if (xs->xs_idx == 0)
+			continue;
+
+		for (dci = XHCI_DCI_SLOT; dci <= XHCI_MAX_DCI; dci++) {
+			/* Skip if the endpoint is not Running.  */
+			/* XXX What about Busy?  */
+			if (xhci_get_epstate(sc, xs, dci) !=
+			XHCI_EPSTATE_RUNNING)
+continue;
+
+			/* Stop endpoint.  */
+			err = xhci_stop_endpoint_cmd(sc, xs, dci,
+			XHCI_TRB_3_SUSP_EP_BIT);
+			if (err) {
+device_printf(self, "failed to stop endpoint"
+" slot %zu dci %zu err %d\n",
+i, dci, err);
+goto out;
+			}
+		}
+	}
+
 	/*
-	 * First, suspend all the ports:
+	 * Next, suspend all the ports:
 	 *
 	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.15:
 	 * Suspend-Resume, pp. 276-283
@@ -767,33 +825,12 @@ xhci_suspend(device_t self, const pmf_qu
 device_printf(self,
 "suspend timeout on bus %zu port %zu\n",
 bn, i);
-return false;
+goto out;
 			}
 		}
 	}
 
 	/*
-	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
-	 * xHCI Power Management, p. 342
-	 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342
-	 */
-
-	/*
-	 * `1. Stop all USB activity by issuing Stop Endpoint Commands
-	 * for Busy endpoints in the Running state.  If the Force
-	 * Save Context Capability (FSC = ``0'') is not supported,
-	 * then Stop Endpoint Commands shall be issued for all Idle
-	 * endpoints in the Running state as well.  The Stop
-	 * Endpoint Command causes the xHC to update the respective
-	 * Endpoint or Stream Contexts in system memory, e.g. the
-	 * TR Dequeue Pointer, DCS, etc. fields.  Refer to
-	 * Implementation Note "0".'
-	 *
-	 * XXX Not entirely sure if this is necessary for us; also it
-	 * probably has to happen before suspending the ports.
-	 */
-
-	/*
 	 * `2. 

CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 11:49:45 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c xhcireg.h xhcivar.h

Log Message:
xhci(4): Draft suspend/resume.

Work almost entirely done and tested by maya@ based on xhci 1.2 spec;
tidied up and tweaked by me.

Not sure about issuing Stop Endpoint commands or ensuring the Command
Ring is in the Stopped or Idle state, but this seems to work as is,
so it's already an improvement over what we had before which was no
xhci suspend/resume at all.

In particular, it's not clear to us:

- if we don't have any pending USB activity whether we need to issue
  the Stop Endpoints or quiesce the command ring; but

- if we do have any pending USB activity whether issuing Stop
  Endpoint is enough or whether we also need to do anything to
  synchronize with other software logic to quiesce it too.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/usb/xhcireg.h
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/usb/xhcivar.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.138 src/sys/dev/usb/xhci.c:1.139
--- src/sys/dev/usb/xhci.c:1.138	Tue Jan  5 18:00:21 2021
+++ src/sys/dev/usb/xhci.c	Sun May 23 11:49:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $	*/
+/*	$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -388,7 +388,6 @@ xhci_rt_write_4(const struct xhci_softc 
 	bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset, value);
 }
 
-#if 0 /* unused */
 static inline uint64_t
 xhci_rt_read_8(const struct xhci_softc * const sc, bus_size_t offset)
 {
@@ -408,7 +407,6 @@ xhci_rt_read_8(const struct xhci_softc *
 
 	return value;
 }
-#endif /* unused */
 
 static inline void
 xhci_rt_write_8(const struct xhci_softc * const sc, bus_size_t offset,
@@ -698,15 +696,357 @@ xhci_activate(device_t self, enum devact
 }
 
 bool
-xhci_suspend(device_t dv, const pmf_qual_t *qual)
+xhci_suspend(device_t self, const pmf_qual_t *qual)
 {
-	return false;
+	struct xhci_softc * const sc = device_private(self);
+	size_t i, j, bn;
+	int port;
+	uint32_t v;
+
+	XHCIHIST_FUNC(); XHCIHIST_CALLED();
+
+	/*
+	 * First, suspend all the ports:
+	 *
+	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.15:
+	 * Suspend-Resume, pp. 276-283
+	 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=276
+	 */
+	for (bn = 0; bn < 2; bn++) {
+		for (i = 1; i <= sc->sc_rhportcount[bn]; i++) {
+			/* 4.15.1: Port Suspend.  */
+			port = XHCI_PORTSC(xhci_rhport2ctlrport(sc, bn, i));
+
+			/*
+			 * `System software places individual ports
+			 *  into suspend mode by writing a ``3'' into
+			 *  the appropriate PORTSC register Port Link
+			 *  State (PLS) field (refer to Section 5.4.8).
+			 *  Software should only set the PLS field to
+			 *  ``3'' when the port is in the Enabled
+			 *  state.'
+			 *
+			 * `Software should not attempt to suspend a
+			 *  port unless the port reports that it is in
+			 *  the enabled (PED = ``1''; PLS < ``3'')
+			 *  state (refer to Section 5.4.8 for more
+			 *  information about PED and PLS).'
+			 */
+			v = xhci_op_read_4(sc, port);
+			if (((v & XHCI_PS_PED) == 0) ||
+			XHCI_PS_PLS_GET(v) >= XHCI_PS_PLS_U3)
+continue;
+			v &= ~(XHCI_PS_PLS_MASK | XHCI_PS_CLEAR);
+			v |= XHCI_PS_LWS | XHCI_PS_PLS_SET(XHCI_PS_PLS_SETU3);
+			xhci_op_write_4(sc, port, v);
+
+			/*
+			 * `When the PLS field is written with U3
+			 *  (``3''), the status of the PLS bit will not
+			 *  change to the target U state U3 until the
+			 *  suspend signaling has completed to the
+			 *  attached device (which may be as long as
+			 *  10ms.).'
+			 *
+			 * `Software is required to wait for U3
+			 *  transitions to complete before it puts the
+			 *  xHC into a low power state, and before
+			 *  resuming the port.'
+			 *
+			 * XXX Take advantage of the technique to
+			 * reduce polling on host controllers that
+			 * support the U3C capability.
+			 */
+			for (j = 0; j < XHCI_WAIT_PLS_U3; j++) {
+v = xhci_op_read_4(sc, port);
+if (XHCI_PS_PLS_GET(v) == XHCI_PS_PLS_U3)
+	break;
+usb_delay_ms(>sc_bus, 1);
+			}
+			if (j == XHCI_WAIT_PLS_U3) {
+device_printf(self,
+"suspend timeout on bus %zu port %zu\n",
+bn, i);
+return false;
+			}
+		}
+	}
+
+	/*
+	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
+	 * xHCI Power Management, p. 342
+	 * 

CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 08:42:32 UTC 2021

Modified Files:
src/sys/dev/usb: umass_scsipi.c

Log Message:
umass(4): Use an empty function callback, not null pointer.

This stupid bug, with an `XXX Broken!' comment right above, has been
preventing NetBSD from suspend/resume with a USB drive plugged in for
longer than I want to even think about admitting.  *sigh*


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/usb/umass_scsipi.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/umass_scsipi.c
diff -u src/sys/dev/usb/umass_scsipi.c:1.67 src/sys/dev/usb/umass_scsipi.c:1.68
--- src/sys/dev/usb/umass_scsipi.c:1.67	Sat Apr 24 23:36:59 2021
+++ src/sys/dev/usb/umass_scsipi.c	Sun May 23 08:42:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass_scsipi.c,v 1.67 2021/04/24 23:36:59 thorpej Exp $	*/
+/*	$NetBSD: umass_scsipi.c,v 1.68 2021/05/23 08:42:32 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.67 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.68 2021/05/23 08:42:32 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -101,6 +101,8 @@ Static int umass_scsipi_ioctl(struct scs
 Static int umass_scsipi_getgeom(struct scsipi_periph *,
 struct disk_parms *, u_long);
 
+Static void umass_null_cb(struct umass_softc *, void *,
+			  int, int);
 Static void umass_scsipi_cb(struct umass_softc *, void *,
 			int, int);
 Static void umass_scsipi_sense_cb(struct umass_softc *, void *,
@@ -321,7 +323,7 @@ umass_scsipi_request(struct scsipi_chann
 		  cmdlen, xs->data,
 		  xs->datalen, dir,
 		  xs->timeout, USBD_SYNCHRONOUS,
-		  0, xs);
+		  umass_null_cb, xs);
 			DPRINTFM(UDMASS_SCSI, "done err=%jd",
 			scbus->sc_sync_status, 0, 0, 0);
 			switch (scbus->sc_sync_status) {
@@ -421,6 +423,12 @@ umass_scsipi_getgeom(struct scsipi_perip
 }
 
 Static void
+umass_null_cb(struct umass_softc *sc, void *priv, int residue, int status)
+{
+	UMASSHIST_FUNC(); UMASSHIST_CALLED();
+}
+
+Static void
 umass_scsipi_cb(struct umass_softc *sc, void *priv, int residue, int status)
 {
 	UMASSHIST_FUNC(); UMASSHIST_CALLED();



CVS commit: src/sys/dev/usb

2021-05-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 23 08:42:47 UTC 2021

Modified Files:
src/sys/dev/usb: umass.c

Log Message:
umass(4): Assert that we got a cb up front.

Avoids jump to zero waaay down the line where we've forgotten why
we wanted to jump into oblivion.


To generate a diff of this commit:
cvs rdiff -u -r1.184 -r1.185 src/sys/dev/usb/umass.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/umass.c
diff -u src/sys/dev/usb/umass.c:1.184 src/sys/dev/usb/umass.c:1.185
--- src/sys/dev/usb/umass.c:1.184	Mon Apr 13 09:26:43 2020
+++ src/sys/dev/usb/umass.c	Sun May 23 08:42:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass.c,v 1.184 2020/04/13 09:26:43 jdolecek Exp $	*/
+/*	$NetBSD: umass.c,v 1.185 2021/05/23 08:42:47 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -124,7 +124,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.184 2020/04/13 09:26:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.185 2021/05/23 08:42:47 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1177,6 +1177,7 @@ umass_bbb_transfer(struct umass_softc *s
 	sc, cb, priv, data, datalen, dir, timeout);
 	static int dCBWtag = 42;	/* unique for CBW of transfer */
 
+	KASSERT(cb);
 	DPRINTFM(UDMASS_BBB, "sc %#jx cmd=0x%02jx", (uintptr_t)sc,
 	*(u_char *)cmd, 0, 0);
 
@@ -1708,6 +1709,7 @@ umass_cbi_transfer(struct umass_softc *s
 	DPRINTFM(UDMASS_CBI, "sc %#jx: cmd=0x%02jx, len=%jd",
 	 (uintptr_t)sc, *(u_char *)cmd, datalen, 0);
 
+	KASSERT(cb);
 	KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I),
 		   "sc->sc_wire == 0x%02x wrong for umass_cbi_transfer\n",
 		   sc->sc_wire);



CVS commit: src/sys/dev/usb

2021-05-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun May 16 09:17:23 UTC 2021

Modified Files:
src/sys/dev/usb: uvideo.c

Log Message:
close pipe before freeing frame length array.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/usb/uvideo.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/uvideo.c
diff -u src/sys/dev/usb/uvideo.c:1.59 src/sys/dev/usb/uvideo.c:1.60
--- src/sys/dev/usb/uvideo.c:1.59	Mon Aug 10 19:27:27 2020
+++ src/sys/dev/usb/uvideo.c	Sun May 16 09:17:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvideo.c,v 1.59 2020/08/10 19:27:27 rjs Exp $	*/
+/*	$NetBSD: uvideo.c,v 1.60 2021/05/16 09:17:23 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2008 Patrick Mahoney
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.59 2020/08/10 19:27:27 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.60 2021/05/16 09:17:23 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1659,7 +1659,15 @@ uvideo_stream_stop_xfer(struct uvideo_st
 usbd_destroy_xfer(isoc->i_xfer);
 isoc->i_xfer = NULL;
 			}
+		}
+
+		if (ix->ix_pipe != NULL) {
+			usbd_close_pipe(ix->ix_pipe);
+			ix->ix_pipe = NULL;
+		}
 
+		for (i = 0; i < UVIDEO_NXFERS; i++) {
+			struct uvideo_isoc *isoc = >ix_i[i];
 			if (isoc->i_frlengths != NULL) {
 kmem_free(isoc->i_frlengths,
   sizeof(isoc->i_frlengths[0]) *
@@ -1668,10 +1676,6 @@ uvideo_stream_stop_xfer(struct uvideo_st
 			}
 		}
 
-		if (ix->ix_pipe != NULL) {
-			usbd_close_pipe(ix->ix_pipe);
-			ix->ix_pipe = NULL;
-		}
 		/* Give it some time to settle */
 		usbd_delay_ms(vs->vs_parent->sc_udev, 1000);
 



CVS commit: src/sys/dev/usb

2021-04-24 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Apr 25 05:16:27 UTC 2021

Modified Files:
src/sys/dev/usb: if_smsc.c

Log Message:
Sample # of RX packets as entropy source.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/dev/usb/if_smsc.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/if_smsc.c
diff -u src/sys/dev/usb/if_smsc.c:1.69 src/sys/dev/usb/if_smsc.c:1.70
--- src/sys/dev/usb/if_smsc.c:1.69	Sat Jun 27 13:33:26 2020
+++ src/sys/dev/usb/if_smsc.c	Sun Apr 25 05:16:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_smsc.c,v 1.69 2020/06/27 13:33:26 jmcneill Exp $	*/
+/*	$NetBSD: if_smsc.c,v 1.70 2021/04/25 05:16:26 rin Exp $	*/
 
 /*	$OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.69 2020/06/27 13:33:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.70 2021/04/25 05:16:26 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -918,13 +918,15 @@ smsc_attach(device_t parent, device_t se
 }
 
 static void
-smsc_uno_rx_loop(struct usbnet * un, struct usbnet_chain *c, uint32_t total_len)
+smsc_uno_rx_loop(struct usbnet *un, struct usbnet_chain *c, uint32_t total_len)
 {
 	USMSCHIST_FUNC(); USMSCHIST_CALLED();
 	struct smsc_softc * const sc = usbnet_softc(un);
 	struct ifnet *ifp = usbnet_ifp(un);
 	uint8_t *buf = c->unc_buf;
+	int count;
 
+	count = 0;
 	DPRINTF("total_len %jd/%#jx", total_len, total_len, 0, 0);
 	while (total_len != 0) {
 		uint32_t rxhdr;
@@ -1045,7 +1047,12 @@ smsc_uno_rx_loop(struct usbnet * un, str
 		/* push the packet up */
 		usbnet_enqueue(un, pktbuf, buflen, csum_flags, csum_data,
 		mbuf_flags);
+
+		count++;
 	}
+
+	if (count != 0)
+		rnd_add_uint32(usbnet_rndsrc(un), count);
 }
 
 static unsigned



CVS commit: src/sys/dev/usb

2021-04-24 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Apr 25 05:15:20 UTC 2021

Modified Files:
src/sys/dev/usb: usbnet.c

Log Message:
Sample # of TX packets as entropy source.

For RX packets, individual drivers need to be modified.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/usb/usbnet.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/usbnet.c
diff -u src/sys/dev/usb/usbnet.c:1.40 src/sys/dev/usb/usbnet.c:1.41
--- src/sys/dev/usb/usbnet.c:1.40	Mon Mar  1 17:41:44 2021
+++ src/sys/dev/usb/usbnet.c	Sun Apr 25 05:15:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.c,v 1.40 2021/03/01 17:41:44 jakllsch Exp $	*/
+/*	$NetBSD: usbnet.c,v 1.41 2021/04/25 05:15:20 rin Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.40 2021/03/01 17:41:44 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.41 2021/04/25 05:15:20 rin Exp $");
 
 #include 
 #include 
@@ -478,7 +478,7 @@ usbnet_start_locked(struct ifnet *ifp)
 	struct mbuf *m;
 	unsigned length;
 	bool done_transmit = false;
-	int idx;
+	int idx, count;
 
 	USBNETHIST_CALLARGS("%jd: tx_cnt %jd list_cnt %jd link %jd",
 	unp->unp_number, cd->uncd_tx_cnt, un->un_tx_list_cnt,
@@ -500,6 +500,7 @@ usbnet_start_locked(struct ifnet *ifp)
 	}
 
 	idx = cd->uncd_tx_prod;
+	count = 0;
 	while (cd->uncd_tx_cnt < un->un_tx_list_cnt) {
 		IFQ_POLL(>if_snd, m);
 		if (m == NULL) {
@@ -547,6 +548,7 @@ usbnet_start_locked(struct ifnet *ifp)
 
 		idx = (idx + 1) % un->un_tx_list_cnt;
 		cd->uncd_tx_cnt++;
+		count++;
 	}
 	cd->uncd_tx_prod = idx;
 
@@ -558,6 +560,9 @@ usbnet_start_locked(struct ifnet *ifp)
 	 */
 	if (done_transmit)
 		unp->unp_timer = 5;
+
+	if (count != 0)
+		rnd_add_uint32(>unp_rndsrc, count);
 }
 
 static void



CVS commit: src/sys/dev/usb

2021-04-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Apr  2 09:27:44 UTC 2021

Modified Files:
src/sys/dev/usb: if_udav.c

Log Message:
Call usbnet_attach before usbnet_{lock_core,busy}

kern/56090: panic in udav_attach


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/dev/usb/if_udav.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/if_udav.c
diff -u src/sys/dev/usb/if_udav.c:1.77 src/sys/dev/usb/if_udav.c:1.78
--- src/sys/dev/usb/if_udav.c:1.77	Sun Mar 15 23:04:51 2020
+++ src/sys/dev/usb/if_udav.c	Fri Apr  2 09:27:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_udav.c,v 1.77 2020/03/15 23:04:51 thorpej Exp $	*/
+/*	$NetBSD: if_udav.c,v 1.78 2021/04/02 09:27:44 skrll Exp $	*/
 /*	$nabe: if_udav.c,v 1.3 2003/08/21 16:57:19 nabe Exp $	*/
 
 /*
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.77 2020/03/15 23:04:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.78 2021/04/02 09:27:44 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -237,14 +237,14 @@ udav_attach(device_t parent, device_t se
 	/* Not supported yet. */
 	un->un_ed[USBNET_ENDPT_INTR] = 0;
 
+	usbnet_attach(un, "udavdet");
+
 	usbnet_lock_core(un);
 	usbnet_busy(un);
 
 // 	/* reset the adapter */
 // 	udav_reset(un);
 
-	usbnet_attach(un, "udavdet");
-
 	/* Get Ethernet Address */
 	err = udav_csr_read(un, UDAV_PAR, un->un_eaddr, ETHER_ADDR_LEN);
 	usbnet_unbusy(un);



CVS commit: src/sys/dev/usb

2021-03-15 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Mon Mar 15 07:30:40 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs.h usbdevs_data.h

Log Message:
regen


To generate a diff of this commit:
cvs rdiff -u -r1.781 -r1.782 src/sys/dev/usb/usbdevs.h \
src/sys/dev/usb/usbdevs_data.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/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.781 src/sys/dev/usb/usbdevs.h:1.782
--- src/sys/dev/usb/usbdevs.h:1.781	Tue Mar  9 16:39:18 2021
+++ src/sys/dev/usb/usbdevs.h	Mon Mar 15 07:30:40 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.781 2021/03/09 16:39:18 ryo Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.782 2021/03/15 07:30:40 nia Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.792 2021/03/09 16:38:49 ryo Exp
+ *	NetBSD: usbdevs,v 1.793 2021/03/15 07:29:26 nia Exp
  */
 
 /*-
@@ -1094,7 +1094,7 @@
 #define	USB_PRODUCT_BELKIN_F5D7051	0x7051		/* F5D7051 54g USB Network Adapter */
 #define	USB_PRODUCT_BELKIN_F5D7050A	0x705a		/* F5D705A 54g USB Network Adapter */
 #define	USB_PRODUCT_BELKIN_F5D7050C	0x705c		/* F5D705C 54g USB Network Adapter */
-#define	USB_PRODUCT_BELKIN_F5D7050E	0x705c		/* F5D705E 54g USB Network Adapter */
+#define	USB_PRODUCT_BELKIN_F5D7050E	0x705e		/* F5D705E 54g USB Network Adapter */
 #define	USB_PRODUCT_BELKIN_RT2870_1	0x8053		/* RT2870 */
 #define	USB_PRODUCT_BELKIN_RT2870_2	0x805c		/* RT2870 */
 #define	USB_PRODUCT_BELKIN_F5D8053V3	0x815c		/* F5D8053 v3 */
Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.781 src/sys/dev/usb/usbdevs_data.h:1.782
--- src/sys/dev/usb/usbdevs_data.h:1.781	Tue Mar  9 16:39:18 2021
+++ src/sys/dev/usb/usbdevs_data.h	Mon Mar 15 07:30:40 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.781 2021/03/09 16:39:18 ryo Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.782 2021/03/15 07:30:40 nia Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.792 2021/03/09 16:38:49 ryo Exp
+ *	NetBSD: usbdevs,v 1.793 2021/03/15 07:29:26 nia Exp
  */
 
 /*-



CVS commit: src/sys/dev/usb

2021-03-15 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Mon Mar 15 07:29:27 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs

Log Message:
correct usb device id for BELKIN F5D7050E

matches freebsd / openbsd (sources of urtw driver), various online
sources

PR kern/56056


To generate a diff of this commit:
cvs rdiff -u -r1.792 -r1.793 src/sys/dev/usb/usbdevs

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/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.792 src/sys/dev/usb/usbdevs:1.793
--- src/sys/dev/usb/usbdevs:1.792	Tue Mar  9 16:38:49 2021
+++ src/sys/dev/usb/usbdevs	Mon Mar 15 07:29:26 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.792 2021/03/09 16:38:49 ryo Exp $
+$NetBSD: usbdevs,v 1.793 2021/03/15 07:29:26 nia Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -1087,7 +1087,7 @@ product BELKIN F5D7050		0x7050	F5D7050 5
 product BELKIN F5D7051		0x7051	F5D7051 54g USB Network Adapter
 product BELKIN F5D7050A		0x705a	F5D705A 54g USB Network Adapter
 product BELKIN F5D7050C		0x705c	F5D705C 54g USB Network Adapter
-product BELKIN F5D7050E		0x705c	F5D705E 54g USB Network Adapter
+product BELKIN F5D7050E		0x705e	F5D705E 54g USB Network Adapter
 product BELKIN RT2870_1		0x8053	RT2870
 product BELKIN RT2870_2		0x805c	RT2870
 product BELKIN F5D8053V3	0x815c	F5D8053 v3



CVS commit: src/sys/dev/usb

2021-03-09 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Tue Mar  9 16:38:49 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs

Log Message:
Add ASUSTEK AURALED


To generate a diff of this commit:
cvs rdiff -u -r1.791 -r1.792 src/sys/dev/usb/usbdevs

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/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.791 src/sys/dev/usb/usbdevs:1.792
--- src/sys/dev/usb/usbdevs:1.791	Tue Mar  9 16:37:23 2021
+++ src/sys/dev/usb/usbdevs	Tue Mar  9 16:38:49 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.791 2021/03/09 16:37:23 ryo Exp $
+$NetBSD: usbdevs,v 1.792 2021/03/09 16:38:49 ryo Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -961,6 +961,7 @@ product ASUSTEK RTL8192CU	0x17ab	RTL8192
 product ASUSTEK USBN66		0x17ad	USB-N66
 product ASUSTEK USBN10NANO	0x17ba	USB-N10 Nano
 product ASUSTEK RTL8192CU_3	0x17c0	RTL8192CU_3
+product ASUSTEK AURALED		0x18f3	AURA LED
 product ASUSTEK MYPAL_A730	0x4202	MyPal A730
 product ASUSTEK2 USBN11		0x0b05	USB-N11
 



CVS commit: src/sys/dev/usb

2021-03-09 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Tue Mar  9 16:37:24 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs

Log Message:
Add CoolerMaster, and AMD SR4 lamplight Control device (Wraith Prism RGB CPU 
Cooler)


To generate a diff of this commit:
cvs rdiff -u -r1.790 -r1.791 src/sys/dev/usb/usbdevs

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/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.790 src/sys/dev/usb/usbdevs:1.791
--- src/sys/dev/usb/usbdevs:1.790	Wed Feb  3 23:23:42 2021
+++ src/sys/dev/usb/usbdevs	Tue Mar  9 16:37:23 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.790 2021/02/03 23:23:42 thorpej Exp $
+$NetBSD: usbdevs,v 1.791 2021/03/09 16:37:23 ryo Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -580,6 +580,7 @@ vendor ARDUINO		0x2341	Arduino SA
 vendor TPLINK		0x2357	TP-Link
 vendor WMR		0x2405	West Mountain Radio
 vendor TRIPPLITE	0x2478	Tripp-Lite
+vendor COOLERMASTER	0x2516	Cooler Master Technology Inc.
 vendor HAILUCK		0x258a	HAILUCK Co., Ltd
 vendor HIROSE		0x2631	Hirose Electric
 vendor NHJ		0x2770	NHJ
@@ -1253,6 +1254,9 @@ product CONCORDCAMERA EYE_Q_3X	0x0100	Ey
 /* Connectix products */
 product CONNECTIX QUICKCAM	0x0001	QuickCam
 
+/* Cooler Master Technology Inc. */
+product	COOLERMASTER AMD_SR4_LAMPLIGHT	0x0051	AMD SR4 lamplight Control
+
 /* Corega products */
 product COREGA ETHER_USB_T	0x0001	Ether USB-T
 product COREGA FETHER_USB_TX	0x0004	FEther USB-TX



CVS commit: src/sys/dev/usb

2021-03-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Mar  2 22:21:38 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
OppsRemove irrelavent debug code and don't free_m before IFQ_DEQUEUE().

Identified and reported by Patrick Welche and remedy found by Martin Husemann.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/dev/usb/if_urtwn.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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.95 src/sys/dev/usb/if_urtwn.c:1.96
--- src/sys/dev/usb/if_urtwn.c:1.95	Fri Feb 26 01:38:44 2021
+++ src/sys/dev/usb/if_urtwn.c	Tue Mar  2 22:21:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.96 2021/03/02 22:21:38 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.96 2021/03/02 22:21:38 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1470,10 +1470,6 @@ urtwn_read_rom(struct urtwn_softc *sc)
 	sc->pa_setting, sc->board_type, sc->regulatory, 0);
 
 	IEEE80211_ADDR_COPY(ic->ic_myaddr, rom->macaddr);
-#if 0
-	uint8_t new_myaddr[6] = {0x90,0x0a,0x1a,0xe7,0x1e,0xf0}; //Camera
-	IEEE80211_ADDR_COPY(ic->ic_myaddr, new_myaddr);
-#endif
 
 	sc->sc_rf_write = urtwn_r92c_rf_write;
 	sc->sc_power_on = urtwn_r92c_power_on;
@@ -2913,7 +2909,6 @@ urtwn_start(struct ifnet *ifp)
 		data = urtwn_get_tx_data(sc, sc->ac2idx[qid]);
 
 		if (data == NULL) {
-			m_freem(m);
 			ifp->if_flags |= IFF_OACTIVE;
 			DPRINTFN(DBG_TX, "empty tx_free_list", 0, 0, 0, 0);
 			return;



CVS commit: src/sys/dev/usb

2021-03-01 Thread Greg Troxel
Module Name:src
Committed By:   gdt
Date:   Tue Mar  2 00:18:22 UTC 2021

Modified Files:
src/sys/dev/usb: ukbd.c

Log Message:
ukbd: GC some 20 year old code (NFC)

Long ago, code was improved to allow detaching keyboards that were the
console, but the old commen and panic() were #if 0'd instead of
removed.


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/sys/dev/usb/ukbd.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/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.148 src/sys/dev/usb/ukbd.c:1.149
--- src/sys/dev/usb/ukbd.c:1.148	Tue Mar  2 00:01:27 2021
+++ src/sys/dev/usb/ukbd.c	Tue Mar  2 00:18:22 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: ukbd.c,v 1.148 2021/03/02 00:01:27 gdt Exp $*/
+/*  $NetBSD: ukbd.c,v 1.149 2021/03/02 00:18:22 gdt Exp $*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.148 2021/03/02 00:01:27 gdt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.149 2021/03/02 00:18:22 gdt Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -555,17 +555,6 @@ ukbd_detach(device_t self, int flags)
 	pmf_device_deregister(self);
 
 	if (sc->sc_console_keyboard) {
-#if 0
-		/*
-		 * XXX Should probably disconnect our consops,
-		 * XXX and either notify some other keyboard that
-		 * XXX it can now be the console, or if there aren't
-		 * XXX any more USB keyboards, set ukbd_is_console
-		 * XXX back to 1 so that the next USB keyboard attached
-		 * XXX to the system will get it.
-		 */
-		panic("ukbd_detach: console keyboard");
-#else
 		/*
 		 * Disconnect our consops and set ukbd_is_console
 		 * back to 1 so that the next USB keyboard attached
@@ -577,7 +566,6 @@ ukbd_detach(device_t self, int flags)
 		   device_xname(sc->sc_hdev.sc_dev));
 		wskbd_cndetach();
 		ukbd_is_console = 1;
-#endif
 	}
 	/* No need to do reference counting of ukbd, wskbd has all the goo. */
 	if (sc->sc_wskbddev != NULL)



CVS commit: src/sys/dev/usb

2021-03-01 Thread Greg Troxel
Module Name:src
Committed By:   gdt
Date:   Tue Mar  2 00:01:27 UTC 2021

Modified Files:
src/sys/dev/usb: ukbd.c

Log Message:
ukbd: Condition probe-time verbosity on USBVERBOSE

Previously, this driver switched on more verbose messages based on
DIAGNOSTIC.  But, the messages weren't about an impossible-to-reach
condition, just extra keys.  Change the condition to USBVERBOSE,
documented as serving this purpose.


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 src/sys/dev/usb/ukbd.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/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.147 src/sys/dev/usb/ukbd.c:1.148
--- src/sys/dev/usb/ukbd.c:1.147	Sat Sep 12 18:10:37 2020
+++ src/sys/dev/usb/ukbd.c	Tue Mar  2 00:01:27 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: ukbd.c,v 1.147 2020/09/12 18:10:37 macallan Exp $*/
+/*  $NetBSD: ukbd.c,v 1.148 2021/03/02 00:01:27 gdt Exp $*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.147 2020/09/12 18:10:37 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.148 2021/03/02 00:01:27 gdt Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -435,7 +435,7 @@ ukbd_attach(device_t parent, device_t se
 		sc->sc_flags = FLAG_GDIUM_FN;
 #endif
 
-#ifdef DIAGNOSTIC
+#ifdef USBVERBOSE
 	aprint_normal(": %d Variable keys, %d Array codes", sc->sc_nkeyloc,
 	   sc->sc_nkeycode);
 	if (sc->sc_flags & FLAG_APPLE_FN)



CVS commit: src/sys/dev/usb

2021-03-01 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Mar  1 22:59:52 UTC 2021

Modified Files:
src/sys/dev/usb: usbnet.h

Log Message:
note that "enum usbnet_ep un_ed" member is the wrong type, and should
be "uByte un_ed", and fix when we version this next.  noticed by martin@


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/usb/usbnet.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/usbnet.h
diff -u src/sys/dev/usb/usbnet.h:1.19 src/sys/dev/usb/usbnet.h:1.20
--- src/sys/dev/usb/usbnet.h:1.19	Wed Oct 28 01:51:45 2020
+++ src/sys/dev/usb/usbnet.h	Mon Mar  1 22:59:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.h,v 1.19 2020/10/28 01:51:45 mrg Exp $	*/
+/*	$NetBSD: usbnet.h,v 1.20 2021/03/01 22:59:52 mrg Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -261,6 +261,9 @@ struct usbnet {
 	/*
 	 * This section should be filled in before calling
 	 * usbnet_attach_ifp().
+	 *
+	 * XXX This should be of type "uByte".  enum usbnet_ep
+	 * is the index.  Fix this in a kernel version bump.
 	 */
 	enum usbnet_ep		un_ed[USBNET_ENDPT_MAX];
 



CVS commit: src/sys/dev/usb

2021-03-01 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Mar  1 17:41:44 UTC 2021

Modified Files:
src/sys/dev/usb: usbnet.c

Log Message:
reduce aprint_error(9) abuse


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/usb/usbnet.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/usbnet.c
diff -u src/sys/dev/usb/usbnet.c:1.39 src/sys/dev/usb/usbnet.c:1.40
--- src/sys/dev/usb/usbnet.c:1.39	Fri Aug 28 17:05:32 2020
+++ src/sys/dev/usb/usbnet.c	Mon Mar  1 17:41:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.c,v 1.39 2020/08/28 17:05:32 riastradh Exp $	*/
+/*	$NetBSD: usbnet.c,v 1.40 2021/03/01 17:41:44 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.39 2020/08/28 17:05:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.40 2021/03/01 17:41:44 jakllsch Exp $");
 
 #include 
 #include 
@@ -350,7 +350,7 @@ usbnet_rxeof(struct usbd_xfer *xfer, voi
 
 	if (status != USBD_NORMAL_COMPLETION) {
 		if (usbd_ratecheck(>unp_rx_notice))
-			aprint_error_dev(un->un_dev, "usb errors on rx: %s\n",
+			device_printf(un->un_dev, "usb errors on rx: %s\n",
 			usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_RX]);
@@ -422,7 +422,7 @@ usbnet_txeof(struct usbd_xfer *xfer, voi
 
 		if_statinc(ifp, if_oerrors);
 		if (usbd_ratecheck(>unp_tx_notice))
-			aprint_error_dev(un->un_dev, "usb error on tx: %s\n",
+			device_printf(un->un_dev, "usb error on tx: %s\n",
 			usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_TX]);
@@ -1139,13 +1139,13 @@ usbnet_watchdog(struct ifnet *ifp)
 	usbd_status err;
 
 	if_statinc(ifp, if_oerrors);
-	aprint_error_dev(un->un_dev, "watchdog timeout\n");
+	device_printf(un->un_dev, "watchdog timeout\n");
 
 	if (cd->uncd_tx_cnt > 0) {
 		DPRINTF("uncd_tx_cnt=%ju non zero, aborting pipe", 0, 0, 0, 0);
 		err = usbd_abort_pipe(unp->unp_ep[USBNET_ENDPT_TX]);
 		if (err)
-			aprint_error_dev(un->un_dev, "pipe abort failed: %s\n",
+			device_printf(un->un_dev, "pipe abort failed: %s\n",
 			usbd_errstr(err));
 		if (cd->uncd_tx_cnt != 0)
 			DPRINTF("uncd_tx_cnt now %ju", cd->uncd_tx_cnt, 0, 0, 0);



CVS commit: src/sys/dev/usb

2021-03-01 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Mar  1 17:41:00 UTC 2021

Modified Files:
src/sys/dev/usb: if_axe.c

Log Message:
reduce aprint_error(9) abuse


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/dev/usb/if_axe.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/if_axe.c
diff -u src/sys/dev/usb/if_axe.c:1.131 src/sys/dev/usb/if_axe.c:1.132
--- src/sys/dev/usb/if_axe.c:1.131	Fri Mar 27 18:04:45 2020
+++ src/sys/dev/usb/if_axe.c	Mon Mar  1 17:41:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axe.c,v 1.131 2020/03/27 18:04:45 nisimura Exp $	*/
+/*	$NetBSD: if_axe.c,v 1.132 2021/03/01 17:41:00 jakllsch Exp $	*/
 /*	$OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.131 2020/03/27 18:04:45 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.132 2021/03/01 17:41:00 jakllsch Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -335,7 +335,7 @@ axe_uno_mii_read_reg(struct usbnet *un, 
 	axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
 
 	if (err) {
-		aprint_error_dev(un->un_dev, "read PHY failed\n");
+		device_printf(un->un_dev, "read PHY failed\n");
 		return EIO;
 	}
 
@@ -422,7 +422,7 @@ axe_uno_mii_statchg(struct ifnet *ifp)
 	DPRINTF("val=%#jx", val, 0, 0, 0);
 	err = axe_cmd(sc, AXE_CMD_WRITE_MEDIA, 0, val, NULL);
 	if (err)
-		aprint_error_dev(un->un_dev, "media change failed\n");
+		device_printf(un->un_dev, "media change failed\n");
 }
 
 static void
@@ -442,7 +442,7 @@ axe_rcvfilt_locked(struct usbnet *un)
 		return;
 
 	if (axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, )) {
-		aprint_error_dev(un->un_dev, "can't read rxmode");
+		device_printf(un->un_dev, "can't read rxmode");
 		return;
 	}
 	rxmode = le16toh(rxmode);



CVS commit: src/sys/dev/usb

2021-02-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Feb 26 01:38:44 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
Also free assocated mbufs.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/usb/if_urtwn.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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.94 src/sys/dev/usb/if_urtwn.c:1.95
--- src/sys/dev/usb/if_urtwn.c:1.94	Sun Feb 21 23:06:13 2021
+++ src/sys/dev/usb/if_urtwn.c	Fri Feb 26 01:38:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1470,6 +1470,10 @@ urtwn_read_rom(struct urtwn_softc *sc)
 	sc->pa_setting, sc->board_type, sc->regulatory, 0);
 
 	IEEE80211_ADDR_COPY(ic->ic_myaddr, rom->macaddr);
+#if 0
+	uint8_t new_myaddr[6] = {0x90,0x0a,0x1a,0xe7,0x1e,0xf0}; //Camera
+	IEEE80211_ADDR_COPY(ic->ic_myaddr, new_myaddr);
+#endif
 
 	sc->sc_rf_write = urtwn_r92c_rf_write;
 	sc->sc_power_on = urtwn_r92c_power_on;
@@ -2660,6 +2664,7 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		k = ieee80211_crypto_encap(ic, ni, m);
 		if (k == NULL) {
 			urtwn_put_tx_data(sc, data);
+			m_free(m);
 			return ENOBUFS;
 		}
 
@@ -2908,6 +2913,7 @@ urtwn_start(struct ifnet *ifp)
 		data = urtwn_get_tx_data(sc, sc->ac2idx[qid]);
 
 		if (data == NULL) {
+			m_freem(m);
 			ifp->if_flags |= IFF_OACTIVE;
 			DPRINTFN(DBG_TX, "empty tx_free_list", 0, 0, 0, 0);
 			return;
@@ -2919,16 +2925,17 @@ urtwn_start(struct ifnet *ifp)
 			device_printf(sc->sc_dev, "m_pullup failed\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
 		eh = mtod(m, struct ether_header *);
 		ni = ieee80211_find_txnode(ic, eh->ether_dhost);
 		if (ni == NULL) {
-			m_freem(m);
 			device_printf(sc->sc_dev,
 			"unable to find transmit node\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
 
@@ -2940,6 +2947,7 @@ urtwn_start(struct ifnet *ifp)
 			"unable to encapsulate packet\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
  sendit:



CVS commit: src/sys/dev/usb

2021-02-23 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Feb 24 01:46:57 UTC 2021

Modified Files:
src/sys/dev/usb: usb.c

Log Message:
fix sparc build:  db_expr_t is larger than a pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.192 -r1.193 src/sys/dev/usb/usb.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/usb.c
diff -u src/sys/dev/usb/usb.c:1.192 src/sys/dev/usb/usb.c:1.193
--- src/sys/dev/usb/usb.c:1.192	Tue Feb 23 08:51:36 2021
+++ src/sys/dev/usb/usb.c	Wed Feb 24 01:46:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.192 2021/02/23 08:51:36 mrg Exp $	*/
+/*	$NetBSD: usb.c,v 1.193 2021/02/24 01:46:57 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.192 2021/02/23 08:51:36 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.193 2021/02/24 01:46:57 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -339,7 +339,7 @@ static void
 db_usb_xfer(db_expr_t addr, bool have_addr, db_expr_t count,
 const char *modif)
 {
-	struct usbd_xfer *xfer = (struct usbd_xfer *)addr;
+	struct usbd_xfer *xfer = (struct usbd_xfer *)(uintptr_t)addr;
 
 	if (!have_addr) {
 		db_printf("%s: need usbd_xfer address\n", __func__);
@@ -360,7 +360,7 @@ static void
 db_usb_xferlist(db_expr_t addr, bool have_addr, db_expr_t count,
 const char *modif)
 {
-	struct usbd_pipe *pipe = (struct usbd_pipe *)addr;
+	struct usbd_pipe *pipe = (struct usbd_pipe *)(uintptr_t)addr;
 	struct usbd_xfer *xfer;
 
 	if (!have_addr) {



CVS commit: src/sys/dev/usb

2021-02-23 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Feb 23 08:51:36 UTC 2021

Modified Files:
src/sys/dev/usb: usb.c

Log Message:
fix the formating for 'show usbxferlist'.


To generate a diff of this commit:
cvs rdiff -u -r1.191 -r1.192 src/sys/dev/usb/usb.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/usb.c
diff -u src/sys/dev/usb/usb.c:1.191 src/sys/dev/usb/usb.c:1.192
--- src/sys/dev/usb/usb.c:1.191	Tue Feb 23 07:13:53 2021
+++ src/sys/dev/usb/usb.c	Tue Feb 23 08:51:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.191 2021/02/23 07:13:53 mrg Exp $	*/
+/*	$NetBSD: usb.c,v 1.192 2021/02/23 08:51:36 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.191 2021/02/23 07:13:53 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.192 2021/02/23 08:51:36 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -369,8 +369,11 @@ db_usb_xferlist(db_expr_t addr, bool hav
 	}
 
 	db_printf("usb pipe: %p\n", pipe);
+	unsigned xfercount = 0;
 	SIMPLEQ_FOREACH(xfer, >up_queue, ux_next) {
-		db_printf(" xfer = %p", xfer);
+		db_printf("  xfer = %p%s", xfer,
+		xfercount == 0 || xfercount % 2 == 0 ? "" : "\n");
+		xfercount++;
 	}
 }
 



CVS commit: src/sys/dev/usb

2021-02-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Feb 22 20:45:29 UTC 2021

Modified Files:
src/sys/dev/usb: usb.c

Log Message:
fix formatting and db_usb_command_table[] static.  idea from rillig@.


To generate a diff of this commit:
cvs rdiff -u -r1.189 -r1.190 src/sys/dev/usb/usb.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/usb.c
diff -u src/sys/dev/usb/usb.c:1.189 src/sys/dev/usb/usb.c:1.190
--- src/sys/dev/usb/usb.c:1.189	Sun Feb 21 23:06:39 2021
+++ src/sys/dev/usb/usb.c	Mon Feb 22 20:45:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.189 2021/02/21 23:06:39 mrg Exp $	*/
+/*	$NetBSD: usb.c,v 1.190 2021/02/22 20:45:28 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.189 2021/02/21 23:06:39 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.190 2021/02/22 20:45:28 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -341,7 +341,7 @@ db_usb_xfer(db_expr_t addr, bool have_ad
 {
 	struct usbd_xfer *xfer = (struct usbd_xfer *)addr;
 
-	if (!have_addr){
+	if (!have_addr) {
 		db_printf("%s: need usbd_xfer address\n", __func__);
 		return;
 	}
@@ -363,7 +363,7 @@ db_usb_xferlist(db_expr_t addr, bool hav
 	struct usbd_pipe *pipe = (struct usbd_pipe *)addr;
 	struct usbd_xfer *xfer;
 
-	if (!have_addr){
+	if (!have_addr) {
 		db_printf("%s: need usbd_pipe address\n", __func__);
 		return;
 	}
@@ -374,7 +374,7 @@ db_usb_xferlist(db_expr_t addr, bool hav
 	}
 }
 
-const struct db_command db_usb_command_table[] = {
+static const struct db_command db_usb_command_table[] = {
 	{ DDB_ADD_CMD("usbxfer",	db_usb_xfer,	0, 
 	  "display a USB xfer structure",
 	  NULL, NULL) },



CVS commit: src/sys/dev/usb

2021-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Feb 21 23:06:39 UTC 2021

Modified Files:
src/sys/dev/usb: usb.c

Log Message:
add ddb commands to inspect usb xfer and xferlist structures.


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.189 src/sys/dev/usb/usb.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/usb.c
diff -u src/sys/dev/usb/usb.c:1.188 src/sys/dev/usb/usb.c:1.189
--- src/sys/dev/usb/usb.c:1.188	Fri Dec 18 01:40:20 2020
+++ src/sys/dev/usb/usb.c	Sun Feb 21 23:06:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.188 2020/12/18 01:40:20 thorpej Exp $	*/
+/*	$NetBSD: usb.c,v 1.189 2021/02/21 23:06:39 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,10 +37,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.188 2020/12/18 01:40:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.189 2021/02/21 23:06:39 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
+#include "opt_ddb.h"
 #include "opt_compat_netbsd.h"
 #endif
 
@@ -329,6 +330,70 @@ usb_attach(device_t parent, device_t sel
 	config_interrupts(self, usb_doattach);
 }
 
+#ifdef DDB
+#include 
+#include 
+#include 
+
+static void
+db_usb_xfer(db_expr_t addr, bool have_addr, db_expr_t count,
+const char *modif)
+{
+	struct usbd_xfer *xfer = (struct usbd_xfer *)addr;
+
+	if (!have_addr){
+		db_printf("%s: need usbd_xfer address\n", __func__);
+		return;
+	}
+
+	db_printf("usb xfer: %p pipe %p priv %p buffer %p\n",
+	xfer, xfer->ux_pipe, xfer->ux_priv, xfer->ux_buffer);
+	db_printf(" len %x actlen %x flags %x timeout %x status %x\n",
+	xfer->ux_length, xfer->ux_actlen, xfer->ux_flags, xfer->ux_timeout,
+	xfer->ux_status);
+	db_printf(" callback %p done %x state %x tm_set %x tm_reset %x\n",
+	xfer->ux_callback, xfer->ux_done, xfer->ux_state,
+	xfer->ux_timeout_set, xfer->ux_timeout_reset);
+}
+
+static void
+db_usb_xferlist(db_expr_t addr, bool have_addr, db_expr_t count,
+const char *modif)
+{
+	struct usbd_pipe *pipe = (struct usbd_pipe *)addr;
+	struct usbd_xfer *xfer;
+
+	if (!have_addr){
+		db_printf("%s: need usbd_pipe address\n", __func__);
+		return;
+	}
+
+	db_printf("usb pipe: %p\n", pipe);
+	SIMPLEQ_FOREACH(xfer, >up_queue, ux_next) {
+		db_printf(" xfer = %p", xfer);
+	}
+}
+
+const struct db_command db_usb_command_table[] = {
+	{ DDB_ADD_CMD("usbxfer",	db_usb_xfer,	0, 
+	  "display a USB xfer structure",
+	  NULL, NULL) },
+	{ DDB_ADD_CMD("usbxferlist",	db_usb_xferlist,	0, 
+	  "display a USB xfer structure given pipe",
+	  NULL, NULL) },
+	{ DDB_ADD_CMD(NULL,	NULL,	0, NULL, NULL, NULL) }
+};
+
+static void
+usb_init_ddb(void)
+{
+
+	(void)db_register_tbl(DDB_SHOW_CMD, db_usb_command_table);
+}
+#else
+#define usb_init_ddb() /* nothing */
+#endif
+
 static int
 usb_once_init(void)
 {
@@ -369,6 +434,8 @@ usb_once_init(void)
 	usb_async_sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE,
 	   usb_async_intr, NULL);
 
+	usb_init_ddb();
+
 	return 0;
 }
 



CVS commit: src/sys/dev/usb

2021-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Feb 21 23:06:13 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
replace printf "ERROR" with device_printf() and useful messages.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/usb/if_urtwn.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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.93 src/sys/dev/usb/if_urtwn.c:1.94
--- src/sys/dev/usb/if_urtwn.c:1.93	Tue Feb  2 10:46:17 2021
+++ src/sys/dev/usb/if_urtwn.c	Sun Feb 21 23:06:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.93 2021/02/02 10:46:17 yamt Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.93 2021/02/02 10:46:17 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2621,7 +2621,7 @@ urtwn_txeof(struct usbd_xfer *xfer, void
 struct usbd_pipe *pipe = sc->tx_pipe[pidx];
 usbd_clear_endpoint_stall_async(pipe);
 			}
-			printf("ERROR1\n");
+			device_printf(sc->sc_dev, "device timeout\n");
 			if_statinc(ifp, if_oerrors);
 		}
 		splx(s);
@@ -2916,7 +2916,7 @@ urtwn_start(struct ifnet *ifp)
 
 		if (m->m_len < (int)sizeof(*eh) &&
 		(m = m_pullup(m, sizeof(*eh))) == NULL) {
-			printf("ERROR6\n");
+			device_printf(sc->sc_dev, "m_pullup failed\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
 			continue;
@@ -2925,7 +2925,8 @@ urtwn_start(struct ifnet *ifp)
 		ni = ieee80211_find_txnode(ic, eh->ether_dhost);
 		if (ni == NULL) {
 			m_freem(m);
-			printf("ERROR5\n");
+			device_printf(sc->sc_dev,
+			"unable to find transmit node\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
 			continue;
@@ -2935,7 +2936,8 @@ urtwn_start(struct ifnet *ifp)
 
 		if ((m = ieee80211_encap(ic, m, ni)) == NULL) {
 			ieee80211_free_node(ni);
-			printf("ERROR4\n");
+			device_printf(sc->sc_dev,
+			"unable to encapsulate packet\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
 			continue;
@@ -2946,7 +2948,8 @@ urtwn_start(struct ifnet *ifp)
 		if (urtwn_tx(sc, m, ni, data) != 0) {
 			m_freem(m);
 			ieee80211_free_node(ni);
-			printf("ERROR3\n");
+			device_printf(sc->sc_dev,
+			"unable to transmit packet\n");
 			if_statinc(ifp, if_oerrors);
 			continue;
 		}
@@ -2968,9 +2971,8 @@ urtwn_watchdog(struct ifnet *ifp)
 
 	if (sc->tx_timer > 0) {
 		if (--sc->tx_timer == 0) {
-			aprint_error_dev(sc->sc_dev, "device timeout\n");
+			device_printf(sc->sc_dev, "device timeout\n");
 			/* urtwn_init(ifp); XXX needs a process context! */
-			printf("ERROR2\n");
 			if_statinc(ifp, if_oerrors);
 			return;
 		}



CVS commit: src/sys/dev/usb

2021-02-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 21 12:36:39 UTC 2021

Modified Files:
src/sys/dev/usb: usb_quirks.c

Log Message:
Add a bunch of USB loader devices for Freescale SoC that should not
attach as HID devices.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/usb/usb_quirks.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/usb_quirks.c
diff -u src/sys/dev/usb/usb_quirks.c:1.96 src/sys/dev/usb/usb_quirks.c:1.97
--- src/sys/dev/usb/usb_quirks.c:1.96	Sat Dec 26 22:15:37 2020
+++ src/sys/dev/usb/usb_quirks.c	Sun Feb 21 12:36:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_quirks.c,v 1.96 2020/12/26 22:15:37 jym Exp $	*/
+/*	$NetBSD: usb_quirks.c,v 1.97 2021/02/21 12:36:38 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.30 2003/01/02 04:15:55 imp Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.96 2020/12/26 22:15:37 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.97 2021/02/21 12:36:38 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -307,6 +307,55 @@ Static const struct usbd_quirk_entry {
  { USB_VENDOR_APPLE,		USB_PRODUCT_APPLE_IPHONE_3GS,		ANY,
 	{ UQ_HID_IGNORE | UQ_BAD_AUDIO, NULL }},
 
+ /*
+  * Various devices using serial boot loader protocol, as supported
+  * by pkgsrc/sysutils/imx_usb_loader
+  */
+ { 0x066f,			0x3780,		/* mx23 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x004f,		/* mx28 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0052,		/* mx50 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0054,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0061,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0063,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0071,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x007d,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0080,		/* mx6ull */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x0128,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0076,		/* mx7 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x0126,		/* mx7ulp */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x0041,		/* mx51 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x004e,		/* mx53 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x15a2,			0x006a,		/* vybrid */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x066f,			0x37ff,		/* linux_gadget */	ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1b67,			0x4fff,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x0525,			0xb4a4,		/* mx6 */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x012b,		/* mx8mq */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x0134,		/* mx8mm */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x1fc9,			0x013e,		/* mx8mn */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+ { 0x3016,			0x1001, 	/* mx8mn */		ANY,
+	{ UQ_HID_IGNORE, NULL }},
+
  { USB_VENDOR_LG,		USB_PRODUCT_LG_CDMA_MSM,		ANY,
 	{ UQ_ASSUME_CM_OVER_DATA, NULL }},
  { USB_VENDOR_QUALCOMM2,	USB_PRODUCT_QUALCOMM2_CDMA_MSM,		ANY,



CVS commit: src/sys/dev/usb

2021-02-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Feb 17 06:30:57 UTC 2021

Modified Files:
src/sys/dev/usb: usb_subr.c

Log Message:
Expose more descriptor items as device properties.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/sys/dev/usb/usb_subr.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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.248 src/sys/dev/usb/usb_subr.c:1.249
--- src/sys/dev/usb/usb_subr.c:1.248	Thu Jun 11 02:39:30 2020
+++ src/sys/dev/usb/usb_subr.c	Wed Feb 17 06:30:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.248 2020/06/11 02:39:30 thorpej Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.249 2021/02/17 06:30:57 mlelstv Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.248 2020/06/11 02:39:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.249 2021/02/17 06:30:57 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -862,10 +862,36 @@ usbd_attach_roothub(device_t parent, str
 }
 
 static void
-usbd_serialnumber(device_t dv, struct usbd_device *dev)
+usbd_properties(device_t dv, struct usbd_device *dev)
 {
+	usb_device_descriptor_t *dd = >ud_ddesc;
+	prop_dictionary_t dict = device_properties(dv);
+	int class, subclass, release, proto, vendor, product;
+
+	class = dd->bDeviceClass;
+	subclass = dd->bDeviceSubClass;
+	release = UGETW(dd->bcdDevice);
+	proto = dd->bDeviceProtocol;
+	vendor = UGETW(dd->idVendor);
+	product = UGETW(dd->idProduct);
+
+	prop_dictionary_set_uint16(dict, "class", class);
+	prop_dictionary_set_uint16(dict, "subclass", subclass);
+	prop_dictionary_set_uint16(dict, "release", release);
+	prop_dictionary_set_uint16(dict, "proto", proto);
+	prop_dictionary_set_uint16(dict, "vendor", vendor);
+	prop_dictionary_set_uint16(dict, "product", product);
+
+	if (dev->ud_vendor) {
+		prop_dictionary_set_string(dict,
+		"vendor-string", dev->ud_vendor);
+	}
+	if (dev->ud_product) {
+		prop_dictionary_set_string(dict,
+		"product-string", dev->ud_product);
+	}
 	if (dev->ud_serial) {
-		prop_dictionary_set_string(device_properties(dv),
+		prop_dictionary_set_string(dict,
 		"serialnumber", dev->ud_serial);
 	}
 }
@@ -907,7 +933,7 @@ usbd_attachwholedevice(device_t parent, 
 		dev->ud_subdevs[0] = dv;
 		dev->ud_subdevlen = 1;
 		dev->ud_nifaces_claimed = 1; /* XXX */
-		usbd_serialnumber(dv, dev);
+		usbd_properties(dv, dev);
 	}
 	config_pending_decr(parent);
 	return USBD_NORMAL_COMPLETION;
@@ -983,7 +1009,7 @@ usbd_attachinterfaces(device_t parent, s
 		if (!dv)
 			continue;
 
-		usbd_serialnumber(dv, dev);
+		usbd_properties(dv, dev);
 
 		/* claim */
 		ifaces[i] = NULL;



CVS commit: src/sys/dev/usb

2021-02-15 Thread Tetsuya Isaki
Module Name:src
Committed By:   isaki
Date:   Mon Feb 15 13:39:18 UTC 2021

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Fix my copy-and-paste bug in rev1.160.
This fixes recording sample dropout.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/dev/usb/uaudio.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/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.168 src/sys/dev/usb/uaudio.c:1.169
--- src/sys/dev/usb/uaudio.c:1.168	Sun Jan 10 15:50:16 2021
+++ src/sys/dev/usb/uaudio.c	Mon Feb 15 13:39:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.168 2021/01/10 15:50:16 ryoon Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.169 2021/02/15 13:39:18 isaki Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.168 2021/01/10 15:50:16 ryoon Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.169 2021/02/15 13:39:18 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -3020,7 +3020,8 @@ uaudio_set_format(void *addr, int setmod
 		raltidx = audio_indexof_format(sc->sc_formats, sc->sc_nformats,
 		AUMODE_RECORD, rec);
 		/* Transfer should have halted */
-		uaudio_chan_init(>sc_recchan, raltidx, rec, 0);
+		uaudio_chan_init(>sc_recchan, raltidx, rec,
+		UGETW(sc->sc_alts[raltidx].edesc->wMaxPacketSize));
 	}
 
 	if ((setmode & AUMODE_PLAY) && sc->sc_playchan.altidx != -1) {



CVS commit: src/sys/dev/usb

2021-02-03 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Feb  3 23:26:08 UTC 2021

Modified Files:
src/sys/dev/usb: ums.c

Log Message:
I have a cheap USB optical mouse (CHICONY product 0x0939, also known
as "PixArt USB Optical Mouse") that likes to disconnect after 60 seconds
and then reattach 2 seconds later (ad nauseum) unless it's kept open,
so use the "always open" quirk on that device as well.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/usb/ums.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/ums.c
diff -u src/sys/dev/usb/ums.c:1.99 src/sys/dev/usb/ums.c:1.100
--- src/sys/dev/usb/ums.c:1.99	Sat Oct 10 21:47:42 2020
+++ src/sys/dev/usb/ums.c	Wed Feb  3 23:26:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ums.c,v 1.99 2020/10/10 21:47:42 jmcneill Exp $	*/
+/*	$NetBSD: ums.c,v 1.100 2021/02/03 23:26:08 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1998, 2017 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.99 2020/10/10 21:47:42 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.100 2021/02/03 23:26:08 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -210,6 +210,16 @@ ums_attach(device_t parent, device_t sel
 		sc->sc_alwayson = true;
 	}
 
+	if (uha->uiaa->uiaa_vendor == USB_VENDOR_CHICONY &&
+	uha->uiaa->uiaa_product == USB_PRODUCT_CHICONY_OPTMOUSE0939) {
+		/*
+		 * This cheap mouse will disconnect after 60 seconds,
+		 * reconnect, and then disconnect again (ad nauseum)
+		 * unless it's kept open.
+		 */
+		sc->sc_alwayson = true;
+	}
+
 	tpcalib_init(>sc_ms.sc_tpcalib);
 
 	/* calibrate the pointer if it reports absolute events */



CVS commit: src/sys/dev/usb

2021-02-03 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Feb  3 23:24:08 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs.h usbdevs_data.h

Log Message:
Regen for addition of CHICONY optical mouse.


To generate a diff of this commit:
cvs rdiff -u -r1.779 -r1.780 src/sys/dev/usb/usbdevs.h \
src/sys/dev/usb/usbdevs_data.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/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.779 src/sys/dev/usb/usbdevs.h:1.780
--- src/sys/dev/usb/usbdevs.h:1.779	Mon Feb  1 04:49:02 2021
+++ src/sys/dev/usb/usbdevs.h	Wed Feb  3 23:24:07 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.779 2021/02/01 04:49:02 nia Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.780 2021/02/03 23:24:07 thorpej Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.789 2021/02/01 04:46:33 nia Exp
+ *	NetBSD: usbdevs,v 1.790 2021/02/03 23:23:42 thorpej Exp
  */
 
 /*-
@@ -1180,6 +1180,7 @@
 
 /* Chicony products */
 #define	USB_PRODUCT_CHICONY_KB8933	0x0001		/* KB-8933 keyboard */
+#define	USB_PRODUCT_CHICONY_OPTMOUSE0939	0x0939		/* USB Optical Mouse */
 #define	USB_PRODUCT_CHICONY_RTL8188CUS_1	0xaff7		/* RTL8188CUS */
 #define	USB_PRODUCT_CHICONY_RTL8188CUS_2	0xaff8		/* RTL8188CUS */
 #define	USB_PRODUCT_CHICONY_RTL8188CUS_3	0xaff9		/* RTL8188CUS */
Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.779 src/sys/dev/usb/usbdevs_data.h:1.780
--- src/sys/dev/usb/usbdevs_data.h:1.779	Mon Feb  1 04:49:02 2021
+++ src/sys/dev/usb/usbdevs_data.h	Wed Feb  3 23:24:07 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.779 2021/02/01 04:49:02 nia Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.780 2021/02/03 23:24:07 thorpej Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.789 2021/02/01 04:46:33 nia Exp
+ *	NetBSD: usbdevs,v 1.790 2021/02/03 23:23:42 thorpej Exp
  */
 
 /*-
@@ -1400,6 +1400,8 @@ static const uint16_t usb_products[] = {
 	771, 4922, 6459, 0,
 	USB_VENDOR_CHICONY, USB_PRODUCT_CHICONY_KB8933, 
 	8033, 8009, 0,
+	USB_VENDOR_CHICONY, USB_PRODUCT_CHICONY_OPTMOUSE0939, 
+	4922, 3363, 6459, 0,
 	USB_VENDOR_CHICONY, USB_PRODUCT_CHICONY_RTL8188CUS_1, 
 	7469, 0,
 	USB_VENDOR_CHICONY, USB_PRODUCT_CHICONY_RTL8188CUS_2, 
@@ -5465,7 +5467,7 @@ static const char usb_words[] = { "." 
 	"Cambridge\0" /* 1 refs @ 3342 */
 	"Radio\0" /* 8 refs @ 3352 */
 	"Trek\0" /* 1 refs @ 3358 */
-	"Optical\0" /* 6 refs @ 3363 */
+	"Optical\0" /* 7 refs @ 3363 */
 	"ShanTou\0" /* 1 refs @ 3371 */
 	"MediaGear\0" /* 1 refs @ 3379 */
 	"Broadcom\0" /* 2 refs @ 3389 */
@@ -5674,7 +5676,7 @@ static const char usb_words[] = { "." 
 	"GNU\0" /* 1 refs @ 4901 */
 	"USRP\0" /* 2 refs @ 4905 */
 	"HomeConnect\0" /* 4 refs @ 4910 */
-	"USB\0" /* 211 refs @ 4922 */
+	"USB\0" /* 212 refs @ 4922 */
 	"Bluetooth\0" /* 26 refs @ 4926 */
 	"Adapter\0" /* 79 refs @ 4936 */
 	"3C19250\0" /* 1 refs @ 4944 */
@@ -5868,7 +5870,7 @@ static const char usb_words[] = { "." 
 	"(Wellspring2/JIS)\0" /* 1 refs @ 6428 */
 	"mouse\0" /* 16 refs @ 6446 */
 	"Mighty\0" /* 2 refs @ 6452 */
-	"Mouse\0" /* 14 refs @ 6459 */
+	"Mouse\0" /* 15 refs @ 6459 */
 	"Trackpad\0" /* 3 refs @ 6465 */
 	"(Fountain)\0" /* 1 refs @ 6474 */
 	"(Geyser)\0" /* 1 refs @ 6485 */



CVS commit: src/sys/dev/usb

2021-02-03 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Feb  3 23:23:42 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs

Log Message:
Add a CHICONY optical mouse product ID.


To generate a diff of this commit:
cvs rdiff -u -r1.789 -r1.790 src/sys/dev/usb/usbdevs

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/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.789 src/sys/dev/usb/usbdevs:1.790
--- src/sys/dev/usb/usbdevs:1.789	Mon Feb  1 04:46:33 2021
+++ src/sys/dev/usb/usbdevs	Wed Feb  3 23:23:42 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.789 2021/02/01 04:46:33 nia Exp $
+$NetBSD: usbdevs,v 1.790 2021/02/03 23:23:42 thorpej Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -1173,6 +1173,7 @@ product CHIC CYPRESS		0x0003	Cypress USB
 
 /* Chicony products */
 product CHICONY KB8933		0x0001	KB-8933 keyboard
+product CHICONY OPTMOUSE0939	0x0939	USB Optical Mouse
 product CHICONY RTL8188CUS_1	0xaff7	RTL8188CUS
 product CHICONY RTL8188CUS_2	0xaff8	RTL8188CUS
 product CHICONY RTL8188CUS_3	0xaff9	RTL8188CUS



CVS commit: src/sys/dev/usb

2021-02-02 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Tue Feb  2 10:46:18 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
if_urtwn.c: Plug a few leaks

Can be a cause of PR/55968


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/usb/if_urtwn.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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.92 src/sys/dev/usb/if_urtwn.c:1.93
--- src/sys/dev/usb/if_urtwn.c:1.92	Tue Feb  2 00:27:38 2021
+++ src/sys/dev/usb/if_urtwn.c	Tue Feb  2 10:46:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.92 2021/02/02 00:27:38 yamt Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.93 2021/02/02 10:46:17 yamt Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.92 2021/02/02 00:27:38 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.93 2021/02/02 10:46:17 yamt Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2587,6 +2587,17 @@ urtwn_rxeof(struct usbd_xfer *xfer, void
 }
 
 static void
+urtwn_put_tx_data(struct urtwn_softc *sc, struct urtwn_tx_data *data)
+{
+	size_t pidx = data->pidx;
+
+	mutex_enter(>sc_tx_mtx);
+	/* Put this Tx buffer back to our free list. */
+	TAILQ_INSERT_TAIL(>tx_free_list[pidx], data, next);
+	mutex_exit(>sc_tx_mtx);
+}
+
+static void
 urtwn_txeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {
 	struct urtwn_tx_data *data = priv;
@@ -2598,10 +2609,7 @@ urtwn_txeof(struct usbd_xfer *xfer, void
 	URTWNHIST_FUNC(); URTWNHIST_CALLED();
 	DPRINTFN(DBG_TX, "status=%jd", status, 0, 0, 0);
 
-	mutex_enter(>sc_tx_mtx);
-	/* Put this Tx buffer back to our free list. */
-	TAILQ_INSERT_TAIL(>tx_free_list[pidx], data, next);
-	mutex_exit(>sc_tx_mtx);
+	urtwn_put_tx_data(sc, data);
 
 	s = splnet();
 	sc->tx_timer = 0;
@@ -2650,8 +2658,10 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 
 	if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
 		k = ieee80211_crypto_encap(ic, ni, m);
-		if (k == NULL)
+		if (k == NULL) {
+			urtwn_put_tx_data(sc, data);
 			return ENOBUFS;
+		}
 
 		/* packet header may have moved, reset our local pointer */
 		wh = mtod(m, struct ieee80211_frame *);
@@ -2908,6 +2918,7 @@ urtwn_start(struct ifnet *ifp)
 		(m = m_pullup(m, sizeof(*eh))) == NULL) {
 			printf("ERROR6\n");
 			if_statinc(ifp, if_oerrors);
+			urtwn_put_tx_data(sc, data);
 			continue;
 		}
 		eh = mtod(m, struct ether_header *);
@@ -2916,6 +2927,7 @@ urtwn_start(struct ifnet *ifp)
 			m_freem(m);
 			printf("ERROR5\n");
 			if_statinc(ifp, if_oerrors);
+			urtwn_put_tx_data(sc, data);
 			continue;
 		}
 
@@ -2925,6 +2937,7 @@ urtwn_start(struct ifnet *ifp)
 			ieee80211_free_node(ni);
 			printf("ERROR4\n");
 			if_statinc(ifp, if_oerrors);
+			urtwn_put_tx_data(sc, data);
 			continue;
 		}
  sendit:



CVS commit: src/sys/dev/usb

2021-02-01 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Tue Feb  2 00:27:38 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
if_urtwn: Add a missing newline to an aprint_error_dev message


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/usb/if_urtwn.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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.91 src/sys/dev/usb/if_urtwn.c:1.92
--- src/sys/dev/usb/if_urtwn.c:1.91	Mon Feb  1 06:59:37 2021
+++ src/sys/dev/usb/if_urtwn.c	Tue Feb  2 00:27:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.91 2021/02/01 06:59:37 riastradh Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.92 2021/02/02 00:27:38 yamt Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.91 2021/02/01 06:59:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.92 2021/02/02 00:27:38 yamt Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -883,7 +883,7 @@ urtwn_task(void *arg)
 		}
 
 		if (urtwn_tx_beacon(sc, m, ic->ic_bss) != 0) {
-			aprint_error_dev(sc->sc_dev, "could not send beacon");
+			aprint_error_dev(sc->sc_dev, "could not send beacon\n");
 		}
 
 		/* beacon is no longer needed */



CVS commit: src/sys/dev/usb

2021-01-31 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb  1 06:59:37 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
urtwn(4): Check for allocation failure in urtwn_tx_beacon.

Candidate fix for PR kern/55968.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/usb/if_urtwn.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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.90 src/sys/dev/usb/if_urtwn.c:1.91
--- src/sys/dev/usb/if_urtwn.c:1.90	Mon Feb  1 04:46:33 2021
+++ src/sys/dev/usb/if_urtwn.c	Mon Feb  1 06:59:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.90 2021/02/01 04:46:33 nia Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.91 2021/02/01 06:59:37 riastradh Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.90 2021/02/01 04:46:33 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.91 2021/02/01 06:59:37 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -854,6 +854,10 @@ urtwn_tx_beacon(struct urtwn_softc *sc, 
 {
 	struct urtwn_tx_data *data =
 	urtwn_get_tx_data(sc, sc->ac2idx[WME_AC_VO]);
+
+	if (data == NULL)
+		return ENOBUFS;
+
 	return urtwn_tx(sc, m, ni, data);
 }
 



CVS commit: src/sys/dev/usb

2021-01-31 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Mon Feb  1 04:49:02 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs.h usbdevs_data.h

Log Message:
regen


To generate a diff of this commit:
cvs rdiff -u -r1.778 -r1.779 src/sys/dev/usb/usbdevs.h \
src/sys/dev/usb/usbdevs_data.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/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.778 src/sys/dev/usb/usbdevs.h:1.779
--- src/sys/dev/usb/usbdevs.h:1.778	Sun Jan 31 18:11:43 2021
+++ src/sys/dev/usb/usbdevs.h	Mon Feb  1 04:49:02 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.778 2021/01/31 18:11:43 nia Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.779 2021/02/01 04:49:02 nia Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.788 2021/01/31 18:05:38 nia Exp
+ *	NetBSD: usbdevs,v 1.789 2021/02/01 04:46:33 nia Exp
  */
 
 /*-
@@ -3408,8 +3408,9 @@
 
 /* TP-Link products */
 #define	USB_PRODUCT_TPLINK_RTL8192CU	0x0100		/* RTL8192CU */
-#define	USB_PRODUCT_TPLINK_WN821N	0x0107		/* WN821N */
-#define	USB_PRODUCT_TPLINK_RTL8192EU	0x0109		/* RTL8192EU */
+#define	USB_PRODUCT_TPLINK_WN821NV5	0x0107		/* TL-WN821N v5 */
+#define	USB_PRODUCT_TPLINK_WN822NV4	0x0108		/* TL-WN822N v4 */
+#define	USB_PRODUCT_TPLINK_WN823NV2	0x0109		/* TL-WN823N v2 */
 #define	USB_PRODUCT_TPLINK_RTL8188EU	0x010c		/* RTL8188EU */
 #define	USB_PRODUCT_TPLINK_T4UV2	0x010d		/* Archer T4U ver 2 */
 #define	USB_PRODUCT_TPLINK_T4UHV2	0x010e		/* Archer T4UH ver 2 */
Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.778 src/sys/dev/usb/usbdevs_data.h:1.779
--- src/sys/dev/usb/usbdevs_data.h:1.778	Sun Jan 31 18:11:43 2021
+++ src/sys/dev/usb/usbdevs_data.h	Mon Feb  1 04:49:02 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.778 2021/01/31 18:11:43 nia Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.779 2021/02/01 04:49:02 nia Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.788 2021/01/31 18:05:38 nia Exp
+ *	NetBSD: usbdevs,v 1.789 2021/02/01 04:46:33 nia Exp
  */
 
 /*-
@@ -4666,72 +4666,74 @@ static const uint16_t usb_products[] = {
 	8781, 6564, 5057, 5827, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8192CU, 
 	5236, 0,
-	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN821N, 
-	19667, 0,
-	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8192EU, 
-	17202, 0,
+	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN821NV5, 
+	19667, 19677, 0,
+	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN822NV4, 
+	19680, 18556, 0,
+	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN823NV2, 
+	19690, 7588, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8188EU, 
 	5246, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_T4UV2, 
-	19674, 19681, 7599, 6589, 0,
+	19700, 19707, 7599, 6589, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_T4UHV2, 
-	19674, 19685, 7599, 6589, 0,
+	19700, 19711, 7599, 6589, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_T2UNANO, 
-	19674, 19690, 6940, 0,
+	19700, 19716, 6940, 0,
 	USB_VENDOR_TREK, USB_PRODUCT_TREK_THUMBDRIVE, 
-	19694, 0,
+	19720, 0,
 	USB_VENDOR_TREK, USB_PRODUCT_TREK_THUMBDRIVE_8MB, 
-	19694, 19705, 0,
+	19720, 19731, 0,
 	USB_VENDOR_TRENDNET, USB_PRODUCT_TRENDNET_RTL8192CU, 
 	5236, 0,
 	USB_VENDOR_TRENDNET, USB_PRODUCT_TRENDNET_RTL8188CU, 
 	5256, 0,
 	USB_VENDOR_TRIPPLITE, USB_PRODUCT_TRIPPLITE_U209, 
-	19709, 7000, 4961, 0,
+	19735, 7000, 4961, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_UPS, 
 	3200, 3206, 480, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_SMARTLCD, 
-	19714, 480, 0,
+	19740, 480, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_AVR550U, 
-	3200, 3206, 19723, 0,
+	3200, 3206, 19749, 0,
 	USB_VENDOR_TRUMPION, USB_PRODUCT_TRUMPION_T33521, 
-	19731, 19739, 0,
+	19757, 19765, 0,
 	USB_VENDOR_TRUMPION, USB_PRODUCT_TRUMPION_XXX1100, 
-	16073, 19747, 0,
+	16073, 19773, 0,
 	USB_VENDOR_TSUNAMI, USB_PRODUCT_TSUNAMI_SM2000, 
-	19752, 0,
+	19778, 0,
 	USB_VENDOR_TWINMOS, USB_PRODUCT_TWINMOS_G240, 
-	19760, 0,
+	19786, 0,
 	USB_VENDOR_ULTIMA, USB_PRODUCT_ULTIMA_1200UBPLUS, 
 	11355, 14962, 11245, 7301, 0,
 	USB_VENDOR_ULTIMA, USB_PRODUCT_ULTIMA_T14BR, 
-	19765, 19771, 6910, 0,
+	19791, 19797, 6910, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA1236U, 
-	19777, 5743, 19783, 0,
+	19803, 5743, 19809, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA1220U, 
-	19777, 19791, 19783, 0,
+	19803, 19817, 19809, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA2000U, 
-	19777, 19797, 19783, 0,
+	19803, 19823, 19809, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA3400, 
-	19777, 19803, 19783, 0,
+	19803, 19829, 19809, 0,
 	   

CVS commit: src/sys/dev/usb

2021-01-31 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Mon Feb  1 04:46:33 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c usbdevs

Log Message:
add another TPLINK RTL8192EU variant

to avoid confusion use TP-Link's names for these variants, matching
FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/usb/if_urtwn.c
cvs rdiff -u -r1.788 -r1.789 src/sys/dev/usb/usbdevs

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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.89 src/sys/dev/usb/if_urtwn.c:1.90
--- src/sys/dev/usb/if_urtwn.c:1.89	Sun Jan 31 18:05:38 2021
+++ src/sys/dev/usb/if_urtwn.c	Mon Feb  1 04:46:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.89 2021/01/31 18:05:38 nia Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.90 2021/02/01 04:46:33 nia Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.89 2021/01/31 18:05:38 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.90 2021/02/01 04:46:33 nia Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -217,8 +217,9 @@ static const struct urtwn_dev {
 	/* URTWN_RTL8192EU */
 	URTWN_RTL8192EU_DEV(DLINK,	DWA131E),
 	URTWN_RTL8192EU_DEV(REALTEK,	RTL8192EU),
-	URTWN_RTL8192EU_DEV(TPLINK,	RTL8192EU),
-	URTWN_RTL8192EU_DEV(TPLINK,	WN821N),
+	URTWN_RTL8192EU_DEV(TPLINK,	WN821NV5),
+	URTWN_RTL8192EU_DEV(TPLINK,	WN822NV4),
+	URTWN_RTL8192EU_DEV(TPLINK,	WN823NV2),
 };
 #undef URTWN_DEV
 #undef URTWN_RTL8188E_DEV

Index: src/sys/dev/usb/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.788 src/sys/dev/usb/usbdevs:1.789
--- src/sys/dev/usb/usbdevs:1.788	Sun Jan 31 18:05:38 2021
+++ src/sys/dev/usb/usbdevs	Mon Feb  1 04:46:33 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.788 2021/01/31 18:05:38 nia Exp $
+$NetBSD: usbdevs,v 1.789 2021/02/01 04:46:33 nia Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -3401,8 +3401,9 @@ product TOSHIBA HSDPA_MODEM_EU870DT1	0x1
 
 /* TP-Link products */
 product TPLINK RTL8192CU	0x0100	RTL8192CU
-product TPLINK WN821N		0x0107	WN821N
-product TPLINK RTL8192EU	0x0109	RTL8192EU
+product	TPLINK WN821NV5		0x0107	TL-WN821N v5
+product	TPLINK WN822NV4		0x0108	TL-WN822N v4
+product	TPLINK WN823NV2		0x0109	TL-WN823N v2
 product TPLINK RTL8188EU	0x010c	RTL8188EU
 product	TPLINK T4UV2		0x010d  Archer T4U ver 2
 product	TPLINK T4UHV2		0x010e  Archer T4UH ver 2



CVS commit: src/sys/dev/usb

2021-01-31 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sun Jan 31 18:11:44 UTC 2021

Modified Files:
src/sys/dev/usb: usbdevs.h usbdevs_data.h

Log Message:
regen


To generate a diff of this commit:
cvs rdiff -u -r1.777 -r1.778 src/sys/dev/usb/usbdevs.h \
src/sys/dev/usb/usbdevs_data.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/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.777 src/sys/dev/usb/usbdevs.h:1.778
--- src/sys/dev/usb/usbdevs.h:1.777	Sat Dec 26 22:11:20 2020
+++ src/sys/dev/usb/usbdevs.h	Sun Jan 31 18:11:43 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.777 2020/12/26 22:11:20 jym Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.778 2021/01/31 18:11:43 nia Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.787 2020/12/26 22:09:18 jym Exp
+ *	NetBSD: usbdevs,v 1.788 2021/01/31 18:05:38 nia Exp
  */
 
 /*-
@@ -3408,6 +3408,7 @@
 
 /* TP-Link products */
 #define	USB_PRODUCT_TPLINK_RTL8192CU	0x0100		/* RTL8192CU */
+#define	USB_PRODUCT_TPLINK_WN821N	0x0107		/* WN821N */
 #define	USB_PRODUCT_TPLINK_RTL8192EU	0x0109		/* RTL8192EU */
 #define	USB_PRODUCT_TPLINK_RTL8188EU	0x010c		/* RTL8188EU */
 #define	USB_PRODUCT_TPLINK_T4UV2	0x010d		/* Archer T4U ver 2 */
Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.777 src/sys/dev/usb/usbdevs_data.h:1.778
--- src/sys/dev/usb/usbdevs_data.h:1.777	Sat Dec 26 22:11:20 2020
+++ src/sys/dev/usb/usbdevs_data.h	Sun Jan 31 18:11:43 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.777 2020/12/26 22:11:20 jym Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.778 2021/01/31 18:11:43 nia Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.787 2020/12/26 22:09:18 jym Exp
+ *	NetBSD: usbdevs,v 1.788 2021/01/31 18:05:38 nia Exp
  */
 
 /*-
@@ -4666,70 +4666,72 @@ static const uint16_t usb_products[] = {
 	8781, 6564, 5057, 5827, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8192CU, 
 	5236, 0,
+	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN821N, 
+	19667, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8192EU, 
 	17202, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8188EU, 
 	5246, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_T4UV2, 
-	19667, 19674, 7599, 6589, 0,
+	19674, 19681, 7599, 6589, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_T4UHV2, 
-	19667, 19678, 7599, 6589, 0,
+	19674, 19685, 7599, 6589, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_T2UNANO, 
-	19667, 19683, 6940, 0,
+	19674, 19690, 6940, 0,
 	USB_VENDOR_TREK, USB_PRODUCT_TREK_THUMBDRIVE, 
-	19687, 0,
+	19694, 0,
 	USB_VENDOR_TREK, USB_PRODUCT_TREK_THUMBDRIVE_8MB, 
-	19687, 19698, 0,
+	19694, 19705, 0,
 	USB_VENDOR_TRENDNET, USB_PRODUCT_TRENDNET_RTL8192CU, 
 	5236, 0,
 	USB_VENDOR_TRENDNET, USB_PRODUCT_TRENDNET_RTL8188CU, 
 	5256, 0,
 	USB_VENDOR_TRIPPLITE, USB_PRODUCT_TRIPPLITE_U209, 
-	19702, 7000, 4961, 0,
+	19709, 7000, 4961, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_UPS, 
 	3200, 3206, 480, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_SMARTLCD, 
-	19707, 480, 0,
+	19714, 480, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_AVR550U, 
-	3200, 3206, 19716, 0,
+	3200, 3206, 19723, 0,
 	USB_VENDOR_TRUMPION, USB_PRODUCT_TRUMPION_T33521, 
-	19724, 19732, 0,
+	19731, 19739, 0,
 	USB_VENDOR_TRUMPION, USB_PRODUCT_TRUMPION_XXX1100, 
-	16073, 19740, 0,
+	16073, 19747, 0,
 	USB_VENDOR_TSUNAMI, USB_PRODUCT_TSUNAMI_SM2000, 
-	19745, 0,
+	19752, 0,
 	USB_VENDOR_TWINMOS, USB_PRODUCT_TWINMOS_G240, 
-	19753, 0,
+	19760, 0,
 	USB_VENDOR_ULTIMA, USB_PRODUCT_ULTIMA_1200UBPLUS, 
 	11355, 14962, 11245, 7301, 0,
 	USB_VENDOR_ULTIMA, USB_PRODUCT_ULTIMA_T14BR, 
-	19758, 19764, 6910, 0,
+	19765, 19771, 6910, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA1236U, 
-	19770, 5743, 19776, 0,
+	19777, 5743, 19783, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA1220U, 
-	19770, 19784, 19776, 0,
+	19777, 19791, 19783, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA2000U, 
-	19770, 19790, 19776, 0,
+	19777, 19797, 19783, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA3400, 
-	19770, 19796, 19776, 0,
+	19777, 19803, 19783, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA2100U, 
-	19770, 19801, 19776, 0,
+	19777, 19808, 19783, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA2200U, 
-	19770, 19807, 19776, 0,
+	19777, 19814, 19783, 0,
 	USB_VENDOR_UMEDIA, USB_PRODUCT_UMEDIA_TEW429UB_A, 
-	19813, 0,
+	19820, 0,
 	USB_VENDOR_UMEDIA, USB_PRODUCT_UMEDIA_TEW429UB, 
-	19825, 0,
+	19832, 0,
 	USB_VENDOR_UMEDIA, USB_PRODUCT_UMEDIA_TEW429UBC1, 
-	19825, 9292, 0,
+	19832, 

CVS commit: src/sys/dev/usb

2021-01-31 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sun Jan 31 18:05:38 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c usbdevs

Log Message:
urtwn(4): add TPLINK WN821N to the list of USB device ids

reported by kfmut on the unitedbsd forums.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/usb/if_urtwn.c
cvs rdiff -u -r1.787 -r1.788 src/sys/dev/usb/usbdevs

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/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.88 src/sys/dev/usb/if_urtwn.c:1.89
--- src/sys/dev/usb/if_urtwn.c:1.88	Sat Jun 27 14:34:45 2020
+++ src/sys/dev/usb/if_urtwn.c	Sun Jan 31 18:05:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.88 2020/06/27 14:34:45 jdolecek Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.89 2021/01/31 18:05:38 nia Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.88 2020/06/27 14:34:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.89 2021/01/31 18:05:38 nia Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -218,6 +218,7 @@ static const struct urtwn_dev {
 	URTWN_RTL8192EU_DEV(DLINK,	DWA131E),
 	URTWN_RTL8192EU_DEV(REALTEK,	RTL8192EU),
 	URTWN_RTL8192EU_DEV(TPLINK,	RTL8192EU),
+	URTWN_RTL8192EU_DEV(TPLINK,	WN821N),
 };
 #undef URTWN_DEV
 #undef URTWN_RTL8188E_DEV

Index: src/sys/dev/usb/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.787 src/sys/dev/usb/usbdevs:1.788
--- src/sys/dev/usb/usbdevs:1.787	Sat Dec 26 22:09:18 2020
+++ src/sys/dev/usb/usbdevs	Sun Jan 31 18:05:38 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.787 2020/12/26 22:09:18 jym Exp $
+$NetBSD: usbdevs,v 1.788 2021/01/31 18:05:38 nia Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -3401,6 +3401,7 @@ product TOSHIBA HSDPA_MODEM_EU870DT1	0x1
 
 /* TP-Link products */
 product TPLINK RTL8192CU	0x0100	RTL8192CU
+product TPLINK WN821N		0x0107	WN821N
 product TPLINK RTL8192EU	0x0109	RTL8192EU
 product TPLINK RTL8188EU	0x010c	RTL8188EU
 product	TPLINK T4UV2		0x010d  Archer T4U ver 2



CVS commit: src/sys/dev/usb

2021-01-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jan 20 22:46:33 UTC 2021

Modified Files:
src/sys/dev/usb: umidi.c

Log Message:
fix free_all_endpoints() to not try calling free_pipe() when no endpoints
are allocated; this can happen during config_detach() after attach fails

Reported-by: syzbot+6e8a4c978358ecead...@syzkaller.appspotmail.com
Reported-by: syzbot+b25ba25b57561144a...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/usb/umidi.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/umidi.c
diff -u src/sys/dev/usb/umidi.c:1.82 src/sys/dev/usb/umidi.c:1.83
--- src/sys/dev/usb/umidi.c:1.82	Thu Jan  2 08:08:30 2020
+++ src/sys/dev/usb/umidi.c	Wed Jan 20 22:46:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umidi.c,v 1.82 2020/01/02 08:08:30 maxv Exp $	*/
+/*	$NetBSD: umidi.c,v 1.83 2021/01/20 22:46:33 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2001, 2012, 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.82 2020/01/02 08:08:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.83 2021/01/20 22:46:33 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -756,10 +756,14 @@ free_all_endpoints(struct umidi_softc *s
 {
 	int i;
 
+	if (sc->sc_endpoints == NULL) {
+		/* nothing to free */
+		return;
+	}
+
 	for (i=0; isc_in_num_endpoints+sc->sc_out_num_endpoints; i++)
 		free_pipe(>sc_endpoints[i]);
-	if (sc->sc_endpoints != NULL)
-		kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
+	kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
 	sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;
 }
 



CVS commit: src/sys/dev/usb

2021-01-10 Thread Ryo ONODERA
Module Name:src
Committed By:   ryoon
Date:   Sun Jan 10 15:50:16 UTC 2021

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Add whitespace after comma


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/dev/usb/uaudio.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/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.167 src/sys/dev/usb/uaudio.c:1.168
--- src/sys/dev/usb/uaudio.c:1.167	Sun Jan 10 13:17:44 2021
+++ src/sys/dev/usb/uaudio.c	Sun Jan 10 15:50:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.167 2021/01/10 13:17:44 ryoon Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.168 2021/01/10 15:50:16 ryoon Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.167 2021/01/10 13:17:44 ryoon Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.168 2021/01/10 15:50:16 ryoon Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1786,7 +1786,7 @@ uaudio_identify_as(struct uaudio_softc *
 			 id->bNumEndpoints);
 			break;
 		}
-		id = uaudio_find_iface(tbuf, size, ,UISUBCLASS_AUDIOSTREAM);
+		id = uaudio_find_iface(tbuf, size, , UISUBCLASS_AUDIOSTREAM);
 		if (id == NULL)
 			break;
 	}



CVS commit: src/sys/dev/usb

2021-01-10 Thread Ryo ONODERA
Module Name:src
Committed By:   ryoon
Date:   Sun Jan 10 13:17:44 UTC 2021

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
Fix a typo in debug message


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/usb/uaudio.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/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.166 src/sys/dev/usb/uaudio.c:1.167
--- src/sys/dev/usb/uaudio.c:1.166	Tue Dec 29 08:04:59 2020
+++ src/sys/dev/usb/uaudio.c	Sun Jan 10 13:17:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.166 2020/12/29 08:04:59 jdc Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.167 2021/01/10 13:17:44 ryoon Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.166 2020/12/29 08:04:59 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.167 2021/01/10 13:17:44 ryoon Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1546,7 +1546,7 @@ uaudio_process_as(struct uaudio_softc *s
 	if (asid->bDescriptorType != UDESC_CS_INTERFACE ||
 	asid->bDescriptorSubtype != AS_GENERAL)
 		return USBD_INVAL;
-	DPRINTF("asid: bTerminakLink=%d wFormatTag=%d\n",
+	DPRINTF("asid: bTerminalLink=%d wFormatTag=%d\n",
 		 asid->bTerminalLink, UGETW(asid->wFormatTag));
 	offs += asid->bLength;
 	if (offs > size)



CVS commit: src/sys/dev/usb

2021-01-05 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jan  5 18:00:21 UTC 2021

Modified Files:
src/sys/dev/usb: ehci.c ohci.c uhci.c usb_mem.c usb_mem.h xhci.c

Log Message:
More converstion from usbd_status to int for function error reporting.
This time it's the turn of usb_allocmem.


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 src/sys/dev/usb/ehci.c
cvs rdiff -u -r1.314 -r1.315 src/sys/dev/usb/ohci.c
cvs rdiff -u -r1.305 -r1.306 src/sys/dev/usb/uhci.c
cvs rdiff -u -r1.79 -r1.80 src/sys/dev/usb/usb_mem.c
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/usb/usb_mem.h
cvs rdiff -u -r1.137 -r1.138 src/sys/dev/usb/xhci.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/ehci.c
diff -u src/sys/dev/usb/ehci.c:1.284 src/sys/dev/usb/ehci.c:1.285
--- src/sys/dev/usb/ehci.c:1.284	Tue Dec 22 01:07:23 2020
+++ src/sys/dev/usb/ehci.c	Tue Jan  5 18:00:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ehci.c,v 1.284 2020/12/22 01:07:23 riastradh Exp $ */
+/*	$NetBSD: ehci.c,v 1.285 2021/01/05 18:00:21 skrll Exp $ */
 
 /*
  * Copyright (c) 2004-2012,2016,2020 The NetBSD Foundation, Inc.
@@ -54,7 +54,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.284 2020/12/22 01:07:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.285 2021/01/05 18:00:21 skrll Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -2845,7 +2845,6 @@ Static ehci_soft_qtd_t *
 ehci_alloc_sqtd(ehci_softc_t *sc)
 {
 	ehci_soft_qtd_t *sqtd = NULL;
-	usbd_status err;
 	int i, offs;
 	usb_dma_t dma;
 
@@ -2856,8 +2855,10 @@ ehci_alloc_sqtd(ehci_softc_t *sc)
 		DPRINTF("allocating chunk", 0, 0, 0, 0);
 		mutex_exit(>sc_lock);
 
-		err = usb_allocmem(>sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK,
-		EHCI_PAGE_SIZE, USBMALLOC_COHERENT, );
+		int err = usb_allocmem(>sc_bus,
+		EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK,
+		EHCI_PAGE_SIZE, USBMALLOC_COHERENT,
+		);
 #ifdef EHCI_DEBUG
 		if (err)
 			printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err);
@@ -3102,7 +3103,6 @@ Static ehci_soft_itd_t *
 ehci_alloc_itd(ehci_softc_t *sc)
 {
 	struct ehci_soft_itd *itd, *freeitd;
-	usbd_status err;
 	usb_dma_t dma;
 
 	EHCIHIST_FUNC(); EHCIHIST_CALLED();
@@ -3113,8 +3113,7 @@ ehci_alloc_itd(ehci_softc_t *sc)
 	if (freeitd == NULL) {
 		DPRINTF("allocating chunk", 0, 0, 0, 0);
 		mutex_exit(>sc_lock);
-
-		err = usb_allocmem(>sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK,
+		int err = usb_allocmem(>sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK,
 		EHCI_PAGE_SIZE, USBMALLOC_COHERENT, );
 
 		if (err) {
@@ -3151,7 +3150,6 @@ Static ehci_soft_sitd_t *
 ehci_alloc_sitd(ehci_softc_t *sc)
 {
 	struct ehci_soft_sitd *sitd, *freesitd;
-	usbd_status err;
 	int i, offs;
 	usb_dma_t dma;
 
@@ -3162,8 +3160,7 @@ ehci_alloc_sitd(ehci_softc_t *sc)
 	if (freesitd == NULL) {
 		DPRINTF("allocating chunk", 0, 0, 0, 0);
 		mutex_exit(>sc_lock);
-
-		err = usb_allocmem(>sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK,
+		int err = usb_allocmem(>sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK,
 		EHCI_PAGE_SIZE, USBMALLOC_COHERENT, );
 
 		if (err) {

Index: src/sys/dev/usb/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.314 src/sys/dev/usb/ohci.c:1.315
--- src/sys/dev/usb/ohci.c:1.314	Tue Dec 22 01:07:23 2020
+++ src/sys/dev/usb/ohci.c	Tue Jan  5 18:00:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.314 2020/12/22 01:07:23 riastradh Exp $	*/
+/*	$NetBSD: ohci.c,v 1.315 2021/01/05 18:00:21 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012, 2016, 2020 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.314 2020/12/22 01:07:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.315 2021/01/05 18:00:21 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -399,7 +399,6 @@ ohci_soft_ed_t *
 ohci_alloc_sed(ohci_softc_t *sc)
 {
 	ohci_soft_ed_t *sed;
-	usbd_status err;
 	int i, offs;
 	usb_dma_t dma;
 
@@ -410,8 +409,8 @@ ohci_alloc_sed(ohci_softc_t *sc)
 		DPRINTFN(2, "allocating chunk", 0, 0, 0, 0);
 		mutex_exit(>sc_lock);
 
-		err = usb_allocmem(>sc_bus, OHCI_SED_SIZE * OHCI_SED_CHUNK,
-		OHCI_ED_ALIGN, USBMALLOC_COHERENT, );
+		int err = usb_allocmem(>sc_bus, OHCI_SED_SIZE * OHCI_SED_CHUNK,
+		OHCI_ED_ALIGN, 0 /*!USBMALLOC_COHERENT*/, );
 		if (err)
 			return NULL;
 
@@ -458,7 +457,6 @@ ohci_soft_td_t *
 ohci_alloc_std(ohci_softc_t *sc)
 {
 	ohci_soft_td_t *std;
-	usbd_status err;
 	int i, offs;
 	usb_dma_t dma;
 
@@ -469,8 +467,8 @@ ohci_alloc_std(ohci_softc_t *sc)
 		DPRINTFN(2, "allocating chunk", 0, 0, 0, 0);
 		mutex_exit(>sc_lock);
 
-		err = usb_allocmem(>sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK,
-		OHCI_TD_ALIGN, USBMALLOC_COHERENT, );
+		int err = usb_allocmem(>sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK,
+		   OHCI_TD_ALIGN, USBMALLOC_COHERENT, );
 		if (err)
 			return NULL;
 
@@ -711,7 +709,6 @@ ohci_soft_itd_t *
 ohci_alloc_sitd(ohci_softc_t *sc)
 {
 	ohci_soft_itd_t *sitd;
-	

CVS commit: src/sys/dev/usb

2021-01-05 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jan  5 16:15:09 UTC 2021

Modified Files:
src/sys/dev/usb: usb_mem.c

Log Message:
Replace home grown #ifdef DIAGNOSTIC check with ASSERT_SLEEPABLE


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/dev/usb/usb_mem.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/usb_mem.c
diff -u src/sys/dev/usb/usb_mem.c:1.78 src/sys/dev/usb/usb_mem.c:1.79
--- src/sys/dev/usb/usb_mem.c:1.78	Sat Jan  2 12:39:03 2021
+++ src/sys/dev/usb/usb_mem.c	Tue Jan  5 16:15:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_mem.c,v 1.78 2021/01/02 12:39:03 jmcneill Exp $	*/
+/*	$NetBSD: usb_mem.c,v 1.79 2021/01/05 16:15:09 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.78 2021/01/02 12:39:03 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.79 2021/01/05 16:15:09 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -211,12 +211,8 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 void
 usb_block_real_freemem(usb_dma_block_t *b)
 {
-#ifdef DIAGNOSTIC
-	if (cpu_softintr_p() || cpu_intr_p()) {
-		printf("usb_block_real_freemem: in interrupt context\n");
-		return;
-	}
-#endif
+	ASSERT_SLEEPABLE();
+
 	bus_dmamap_unload(b->tag, b->map);
 	bus_dmamap_destroy(b->tag, b->map);
 	bus_dmamem_unmap(b->tag, b->kaddr, b->size);



CVS commit: src/sys/dev/usb

2021-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan  2 12:39:33 UTC 2021

Modified Files:
src/sys/dev/usb: xhci.c

Log Message:
Use USBMALLOC_ZERO to ensure that all DMA memory is zero initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/dev/usb/xhci.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.136 src/sys/dev/usb/xhci.c:1.137
--- src/sys/dev/usb/xhci.c:1.136	Tue Dec 22 01:07:23 2020
+++ src/sys/dev/usb/xhci.c	Sat Jan  2 12:39:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.136 2020/12/22 01:07:23 riastradh Exp $	*/
+/*	$NetBSD: xhci.c,v 1.137 2021/01/02 12:39:33 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.136 2020/12/22 01:07:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.137 2021/01/02 12:39:33 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1087,7 +1087,8 @@ xhci_init(struct xhci_softc *sc)
 	if (sc->sc_maxspbuf != 0) {
 		err = usb_allocmem(>sc_bus,
 		sizeof(uint64_t) * sc->sc_maxspbuf, sizeof(uint64_t),
-		USBMALLOC_COHERENT, >sc_spbufarray_dma);
+		USBMALLOC_COHERENT | USBMALLOC_ZERO,
+		>sc_spbufarray_dma);
 		if (err) {
 			aprint_error_dev(sc->sc_dev,
 			"spbufarray init fail, err %d\n", err);
@@ -1101,7 +1102,8 @@ xhci_init(struct xhci_softc *sc)
 			usb_dma_t * const dma = >sc_spbuf_dma[i];
 			/* allocate contexts */
 			err = usb_allocmem(>sc_bus, sc->sc_pgsz,
-			sc->sc_pgsz, USBMALLOC_COHERENT, dma);
+			sc->sc_pgsz, USBMALLOC_COHERENT | USBMALLOC_ZERO,
+			dma);
 			if (err) {
 aprint_error_dev(sc->sc_dev,
 "spbufarray_dma init fail, err %d\n", err);
@@ -1149,7 +1151,8 @@ xhci_init(struct xhci_softc *sc)
 	XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN);
 	KASSERTMSG(size <= (512 * 1024), "eventst size %zu too large", size);
 	align = XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN;
-	err = usb_allocmem(>sc_bus, size, align, USBMALLOC_COHERENT, dma);
+	err = usb_allocmem(>sc_bus, size, align,
+	USBMALLOC_COHERENT | USBMALLOC_ZERO, dma);
 	if (err) {
 		aprint_error_dev(sc->sc_dev, "eventst init fail, err %d\n",
 		err);
@@ -1157,8 +1160,6 @@ xhci_init(struct xhci_softc *sc)
 		goto bad3;
 	}
 
-	memset(KERNADDR(dma, 0), 0, size);
-	usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE);
 	aprint_debug_dev(sc->sc_dev, "eventst: 0x%016jx %p %zx\n",
 	(uintmax_t)DMAADDR(>sc_eventst_dma, 0),
 	KERNADDR(>sc_eventst_dma, 0),
@@ -1168,7 +1169,8 @@ xhci_init(struct xhci_softc *sc)
 	size = (1 + sc->sc_maxslots) * sizeof(uint64_t);
 	KASSERTMSG(size <= 2048, "dcbaa size %zu too large", size);
 	align = XHCI_DEVICE_CONTEXT_BASE_ADDRESS_ARRAY_ALIGN;
-	err = usb_allocmem(>sc_bus, size, align, USBMALLOC_COHERENT, dma);
+	err = usb_allocmem(>sc_bus, size, align,
+	USBMALLOC_COHERENT | USBMALLOC_ZERO, dma);
 	if (err) {
 		aprint_error_dev(sc->sc_dev, "dcbaa init fail, err %d\n", err);
 		rv = ENOMEM;
@@ -1179,15 +1181,14 @@ xhci_init(struct xhci_softc *sc)
 	KERNADDR(>sc_dcbaa_dma, 0),
 	sc->sc_dcbaa_dma.udma_block->size);
 
-	memset(KERNADDR(dma, 0), 0, size);
 	if (sc->sc_maxspbuf != 0) {
 		/*
 		 * DCBA entry 0 hold the scratchbuf array pointer.
 		 */
 		*(uint64_t *)KERNADDR(dma, 0) =
 		htole64(DMAADDR(>sc_spbufarray_dma, 0));
+		usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE);
 	}
-	usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE);
 
 	sc->sc_slots = kmem_zalloc(sizeof(*sc->sc_slots) * sc->sc_maxslots,
 	KM_SLEEP);
@@ -2580,8 +2581,8 @@ xhci_ring_init(struct xhci_softc * const
 	xr = kmem_zalloc(sizeof(struct xhci_ring), KM_SLEEP);
 	DPRINTFN(1, "ring %#jx", (uintptr_t)xr, 0, 0, 0);
 
-	err = usb_allocmem(>sc_bus, size, align, USBMALLOC_COHERENT,
-	>xr_dma);
+	err = usb_allocmem(>sc_bus, size, align,
+	USBMALLOC_COHERENT | USBMALLOC_ZERO, >xr_dma);
 	if (err) {
 		kmem_free(xr, sizeof(struct xhci_ring));
 		DPRINTFN(1, "alloc xr_dma failed %jd", err, 0, 0, 0);
@@ -3020,22 +3021,20 @@ xhci_init_slot(struct usbd_device *dev, 
 
 	/* allocate contexts */
 	err = usb_allocmem(>sc_bus, sc->sc_pgsz, sc->sc_pgsz,
-	USBMALLOC_COHERENT, >xs_dc_dma);
+	USBMALLOC_COHERENT | USBMALLOC_ZERO, >xs_dc_dma);
 	if (err) {
 		DPRINTFN(1, "failed to allocmem output device context %jd",
 		err, 0, 0, 0);
 		return err;
 	}
-	memset(KERNADDR(>xs_dc_dma, 0), 0, sc->sc_pgsz);
 
 	err = usb_allocmem(>sc_bus, sc->sc_pgsz, sc->sc_pgsz,
-	USBMALLOC_COHERENT, >xs_ic_dma);
+	USBMALLOC_COHERENT | USBMALLOC_ZERO, >xs_ic_dma);
 	if (err) {
 		DPRINTFN(1, "failed to allocmem input device context %jd",
 		err, 0, 0, 0);
 		goto bad1;
 	}
-	memset(KERNADDR(>xs_ic_dma, 0), 0, sc->sc_pgsz);
 
 	memset(>xs_xr[0], 0, sizeof(xs->xs_xr));
 	xs->xs_idx = slot;



CVS commit: src/sys/dev/usb

2021-01-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan  2 12:39:03 UTC 2021

Modified Files:
src/sys/dev/usb: usb_mem.c usb_mem.h

Log Message:
Add USBMALLOC_ZERO flag for requesting zero initialized DMA memory.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/dev/usb/usb_mem.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/usb/usb_mem.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/usb_mem.c
diff -u src/sys/dev/usb/usb_mem.c:1.77 src/sys/dev/usb/usb_mem.c:1.78
--- src/sys/dev/usb/usb_mem.c:1.77	Fri May 15 06:26:44 2020
+++ src/sys/dev/usb/usb_mem.c	Sat Jan  2 12:39:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_mem.c,v 1.77 2020/05/15 06:26:44 skrll Exp $	*/
+/*	$NetBSD: usb_mem.c,v 1.78 2021/01/02 12:39:03 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.77 2020/05/15 06:26:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.78 2021/01/02 12:39:03 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -179,9 +179,16 @@ usb_block_allocmem(bus_dma_tag_t tag, si
 		goto destroy;
 
 	*dmap = b;
+
 #ifdef USB_FRAG_DMA_WORKAROUND
-	memset(b->kaddr, 0, b->size);
+	flags |= USBMALLOC_ZERO;
 #endif
+	if ((flags & USBMALLOC_ZERO) != 0) {
+		memset(b->kaddr, 0, b->size);
+		bus_dmamap_sync(b->tag, b->map, 0, b->size,
+		BUS_DMASYNC_PREWRITE);
+	}
+
 	mutex_enter(_blk_lock);
 
 	return USBD_NORMAL_COMPLETION;

Index: src/sys/dev/usb/usb_mem.h
diff -u src/sys/dev/usb/usb_mem.h:1.32 src/sys/dev/usb/usb_mem.h:1.33
--- src/sys/dev/usb/usb_mem.h:1.32	Sun Apr  5 20:59:38 2020
+++ src/sys/dev/usb/usb_mem.h	Sat Jan  2 12:39:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_mem.h,v 1.32 2020/04/05 20:59:38 skrll Exp $	*/
+/*	$NetBSD: usb_mem.h,v 1.33 2021/01/02 12:39:03 jmcneill Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.9 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -49,6 +49,7 @@ typedef struct usb_dma_block {
 
 #define USBMALLOC_MULTISEG	__BIT(0)
 #define USBMALLOC_COHERENT	__BIT(1)
+#define USBMALLOC_ZERO		__BIT(2)
 
 usbd_status	usb_allocmem(struct usbd_bus *, size_t, size_t, u_int, usb_dma_t *);
 void		usb_freemem(struct usbd_bus *, usb_dma_t *);



CVS commit: src/sys/dev/usb

2020-12-29 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Tue Dec 29 08:04:59 UTC 2020

Modified Files:
src/sys/dev/usb: uaudio.c

Log Message:
During detach, re-use the functions that halt playback and record DMA.
Prevents a panic during shutdown when media is playing.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/dev/usb/uaudio.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/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.165 src/sys/dev/usb/uaudio.c:1.166
--- src/sys/dev/usb/uaudio.c:1.165	Sat Mar 14 02:35:33 2020
+++ src/sys/dev/usb/uaudio.c	Tue Dec 29 08:04:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.165 2020/03/14 02:35:33 christos Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.166 2020/12/29 08:04:59 jdc Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.165 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.166 2020/12/29 08:04:59 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -343,6 +343,8 @@ Static int	uaudio_trigger_input
 	 const audio_params_t *);
 Static int	uaudio_halt_in_dma(void *);
 Static int	uaudio_halt_out_dma(void *);
+Static void	uaudio_halt_in_dma_unlocked(struct uaudio_softc *);
+Static void	uaudio_halt_out_dma_unlocked(struct uaudio_softc *);
 Static int	uaudio_getdev(void *, struct audio_device *);
 Static int	uaudio_mixer_set_port(void *, mixer_ctrl_t *);
 Static int	uaudio_mixer_get_port(void *, mixer_ctrl_t *);
@@ -519,10 +521,13 @@ uaudio_detach(device_t self, int flags)
 	struct uaudio_softc *sc = device_private(self);
 	int rv = 0;
 
+	sc->sc_dying = 1;
+
 	pmf_device_deregister(self);
 
 	/* Wait for outstanding requests to complete. */
-	usbd_delay_ms(sc->sc_udev, UAUDIO_NCHANBUFS * UAUDIO_NFRAMES);
+	uaudio_halt_out_dma_unlocked(sc);
+	uaudio_halt_in_dma_unlocked(sc);
 
 	if (sc->sc_audiodev != NULL)
 		rv = config_detach(sc->sc_audiodev, flags);
@@ -2167,15 +2172,21 @@ uaudio_halt_out_dma(void *addr)
 	DPRINTF("%s", "enter\n");
 
 	mutex_exit(>sc_intr_lock);
+	uaudio_halt_out_dma_unlocked(sc);
+	mutex_enter(>sc_intr_lock);
+
+	return 0;
+}
+
+Static void
+uaudio_halt_out_dma_unlocked(struct uaudio_softc *sc)
+{
 	if (sc->sc_playchan.pipe != NULL) {
 		uaudio_chan_abort(sc, >sc_playchan);
 		uaudio_chan_free_buffers(sc, >sc_playchan);
 		uaudio_chan_close(sc, >sc_playchan);
 		sc->sc_playchan.intr = NULL;
 	}
-	mutex_enter(>sc_intr_lock);
-
-	return 0;
 }
 
 Static int
@@ -2186,15 +2197,21 @@ uaudio_halt_in_dma(void *addr)
 	DPRINTF("%s", "enter\n");
 
 	mutex_exit(>sc_intr_lock);
+	uaudio_halt_in_dma_unlocked(sc);
+	mutex_enter(>sc_intr_lock);
+
+	return 0;
+}
+
+Static void
+uaudio_halt_in_dma_unlocked(struct uaudio_softc *sc)
+{
 	if (sc->sc_recchan.pipe != NULL) {
 		uaudio_chan_abort(sc, >sc_recchan);
 		uaudio_chan_free_buffers(sc, >sc_recchan);
 		uaudio_chan_close(sc, >sc_recchan);
 		sc->sc_recchan.intr = NULL;
 	}
-	mutex_enter(>sc_intr_lock);
-
-	return 0;
 }
 
 Static int



CVS commit: src/sys/dev/usb

2020-12-26 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sat Dec 26 22:15:37 UTC 2020

Modified Files:
src/sys/dev/usb: usb_quirks.c

Log Message:
Add WayTech USB to Serial device to quirks routines, in order to prevent
uhid(4) from attaching and leave it to ugen(4) so libusb can query it.

It is used by some UPS peripherals for their management, especially the
ones from Infosec and Megatec.

Tested with Infosec E3 UPS through ups-nut-usb and `blazer_usb' driver
using the following configuration (ups.conf):

[infosec]
driver = blazer_usb
port = auto
vendorid = 0665
productid = 5161

Make sure the associated /dev/ugenXXX is accessible to `nut' user if you
use ups-nut.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/dev/usb/usb_quirks.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/usb_quirks.c
diff -u src/sys/dev/usb/usb_quirks.c:1.95 src/sys/dev/usb/usb_quirks.c:1.96
--- src/sys/dev/usb/usb_quirks.c:1.95	Sat Mar 14 03:01:36 2020
+++ src/sys/dev/usb/usb_quirks.c	Sat Dec 26 22:15:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_quirks.c,v 1.95 2020/03/14 03:01:36 christos Exp $	*/
+/*	$NetBSD: usb_quirks.c,v 1.96 2020/12/26 22:15:37 jym Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.30 2003/01/02 04:15:55 imp Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.95 2020/03/14 03:01:36 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.96 2020/12/26 22:15:37 jym Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -206,6 +206,8 @@ Static const struct usbd_quirk_entry {
 	{ UQ_HID_IGNORE, NULL }},
  { USB_VENDOR_XRITE,		ANY,	ANY,
 	{ UQ_HID_IGNORE, NULL }},
+ { USB_VENDOR_WAYTECH,		USB_PRODUCT_WAYTECH_USB2SERIAL,		ANY,
+	{ UQ_HID_IGNORE, NULL }},
  { USB_VENDOR_KYE,		USB_PRODUCT_KYE_NICHE,			0x100,
 	{ UQ_NO_SET_PROTO, NULL }},
  { USB_VENDOR_INSIDEOUT,	USB_PRODUCT_INSIDEOUT_EDGEPORT4,	0x094,



CVS commit: src/sys/dev/usb

2020-12-26 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sat Dec 26 22:09:18 UTC 2020

Modified Files:
src/sys/dev/usb: usbdevs

Log Message:
Add WayTech Development USB to Serial product.

It is used by some UPS devices, notably Infosec and Megatec.

The vendor ID (0x0665) is known differently from various mainstream OSes;
but it is officially registered by USB-IF as `WayTech Development, Inc.'. So
be it.


To generate a diff of this commit:
cvs rdiff -u -r1.786 -r1.787 src/sys/dev/usb/usbdevs

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/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.786 src/sys/dev/usb/usbdevs:1.787
--- src/sys/dev/usb/usbdevs:1.786	Mon Sep  7 06:32:13 2020
+++ src/sys/dev/usb/usbdevs	Sat Dec 26 22:09:18 2020
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.786 2020/09/07 06:32:13 ryoon Exp $
+$NetBSD: usbdevs,v 1.787 2020/12/26 22:09:18 jym Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -250,6 +250,7 @@ vendor AVISION		0x0638	Avision
 vendor TEAC		0x0644	TEAC
 vendor SGI		0x065e	Silicon Graphics
 vendor SANWASUPPLY	0x0663	Sanwa Supply
+vendor WAYTECH		0x0665	WayTech Development, Inc.
 vendor LINKSYS		0x066b	Linksys
 vendor ACERSA		0x066e	Acer Semiconductor America
 vendor SIGMATEL		0x066f	Sigmatel
@@ -2231,6 +2232,9 @@ product MCT ML_4500		0x0302	ML-4500
 /* MediaGear products */
 product MEDIAGEAR READER9IN1	0x5003	USB2.0 9 in 1 Reader
 
+/* WayTech Development, Inc. products */
+product WAYTECH USB2SERIAL	0x5161	USB to Serial
+
 /* Meinberg Funkuhren products */
 product MEINBERG USB5131	0x0301	USB 5131 DCF77 - Radio Clock
 



CVS commit: src/sys/dev/usb

2020-12-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Dec 18 01:40:20 UTC 2020

Modified Files:
src/sys/dev/usb: udsir.c ugen.c uhid.c uirda.c usb.c uscanner.c ustir.c

Log Message:
Use sel{record,remove}_knote().


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/usb/udsir.c
cvs rdiff -u -r1.157 -r1.158 src/sys/dev/usb/ugen.c
cvs rdiff -u -r1.116 -r1.117 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/usb/uirda.c
cvs rdiff -u -r1.187 -r1.188 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.84 -r1.85 src/sys/dev/usb/uscanner.c
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/usb/ustir.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/udsir.c
diff -u src/sys/dev/usb/udsir.c:1.11 src/sys/dev/usb/udsir.c:1.12
--- src/sys/dev/usb/udsir.c:1.11	Sat Mar 14 02:35:33 2020
+++ src/sys/dev/usb/udsir.c	Fri Dec 18 01:40:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: udsir.c,v 1.11 2020/03/14 02:35:33 christos Exp $	*/
+/*	$NetBSD: udsir.c,v 1.12 2020/12/18 01:40:20 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udsir.c,v 1.11 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udsir.c,v 1.12 2020/12/18 01:40:20 thorpej Exp $");
 
 #include 
 #include 
@@ -680,16 +680,16 @@ static int
 udsir_kqfilter(void *h, struct knote *kn)
 {
 	struct udsir_softc *sc = h;
-	struct klist *klist;
+	struct selinfo *sip;
 	int s;
 
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
-		klist = >sc_rd_sel.sel_klist;
+		sip = >sc_rd_sel;
 		kn->kn_fop = _filtops;
 		break;
 	case EVFILT_WRITE:
-		klist = >sc_wr_sel.sel_klist;
+		sip = >sc_wr_sel;
 		kn->kn_fop = _filtops;
 		break;
 	default:
@@ -699,7 +699,7 @@ udsir_kqfilter(void *h, struct knote *kn
 	kn->kn_hook = sc;
 
 	s = splusb();
-	SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+	selrecord_knote(sip, kn);
 	splx(s);
 
 	return 0;
@@ -772,7 +772,7 @@ filt_udsirrdetach(struct knote *kn)
 	int s;
 
 	s = splusb();
-	SLIST_REMOVE(>sc_rd_sel.sel_klist, kn, knote, kn_selnext);
+	selremove_knote(>sc_rd_sel, kn);
 	splx(s);
 }
 
@@ -793,7 +793,7 @@ filt_udsirwdetach(struct knote *kn)
 	int s;
 
 	s = splusb();
-	SLIST_REMOVE(>sc_wr_sel.sel_klist, kn, knote, kn_selnext);
+	selremove_knote(>sc_wr_sel, kn);
 	splx(s);
 }
 

Index: src/sys/dev/usb/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.157 src/sys/dev/usb/ugen.c:1.158
--- src/sys/dev/usb/ugen.c:1.157	Tue Aug 18 14:32:34 2020
+++ src/sys/dev/usb/ugen.c	Fri Dec 18 01:40:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.157 2020/08/18 14:32:34 riastradh Exp $	*/
+/*	$NetBSD: ugen.c,v 1.158 2020/12/18 01:40:20 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.157 2020/08/18 14:32:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.158 2020/12/18 01:40:20 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -2031,7 +2031,7 @@ filt_ugenrdetach(struct knote *kn)
 	struct ugen_softc *sc = sce->sc;
 
 	mutex_enter(>sc_lock);
-	SLIST_REMOVE(>rsel.sel_klist, kn, knote, kn_selnext);
+	selremove_knote(>rsel, kn);
 	mutex_exit(>sc_lock);
 }
 
@@ -2168,7 +2168,7 @@ ugenkqfilter(dev_t dev, struct knote *kn
 {
 	struct ugen_softc *sc;
 	struct ugen_endpoint *sce;
-	struct klist *klist;
+	struct selinfo *sip;
 	int error;
 
 	if ((sc = ugenif_acquire(UGENUNIT(dev))) == NULL)
@@ -2187,7 +2187,7 @@ ugenkqfilter(dev_t dev, struct knote *kn
 			goto out;
 		}
 
-		klist = >rsel.sel_klist;
+		sip = >rsel;
 		switch (sce->edesc->bmAttributes & UE_XFERTYPE) {
 		case UE_INTERRUPT:
 			kn->kn_fop = _intr_filtops;
@@ -2211,7 +2211,7 @@ ugenkqfilter(dev_t dev, struct knote *kn
 			goto out;
 		}
 
-		klist = >rsel.sel_klist;
+		sip = >rsel;
 		switch (sce->edesc->bmAttributes & UE_XFERTYPE) {
 		case UE_INTERRUPT:
 		case UE_ISOCHRONOUS:
@@ -2236,7 +2236,7 @@ ugenkqfilter(dev_t dev, struct knote *kn
 	kn->kn_hook = sce;
 
 	mutex_enter(>sc_lock);
-	SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+	selrecord_knote(sip, kn);
 	mutex_exit(>sc_lock);
 
 	error = 0;

Index: src/sys/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.116 src/sys/dev/usb/uhid.c:1.117
--- src/sys/dev/usb/uhid.c:1.116	Mon Nov 30 00:48:35 2020
+++ src/sys/dev/usb/uhid.c	Fri Dec 18 01:40:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.116 2020/11/30 00:48:35 riastradh Exp $	*/
+/*	$NetBSD: uhid.c,v 1.117 2020/12/18 01:40:20 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.116 2020/11/30 00:48:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.117 2020/12/18 01:40:20 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -831,7 +831,7 @@ filt_uhidrdetach(struct knote *kn)
 	struct uhid_softc *sc = 

CVS commit: src/sys/dev/usb

2020-12-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Dec 10 20:50:24 UTC 2020

Modified Files:
src/sys/dev/usb: ohci.c

Log Message:
Another leading space


To generate a diff of this commit:
cvs rdiff -u -r1.312 -r1.313 src/sys/dev/usb/ohci.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/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.312 src/sys/dev/usb/ohci.c:1.313
--- src/sys/dev/usb/ohci.c:1.312	Thu Dec 10 20:48:33 2020
+++ src/sys/dev/usb/ohci.c	Thu Dec 10 20:50:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.312 2020/12/10 20:48:33 skrll Exp $	*/
+/*	$NetBSD: ohci.c,v 1.313 2020/12/10 20:50:24 skrll Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012, 2016, 2020 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.312 2020/12/10 20:48:33 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.313 2020/12/10 20:50:24 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -612,7 +612,7 @@ ohci_reset_std_chain(ohci_softc_t *sc, s
 
 	usb_syncmem(dma, 0, len,
 	rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
- 	const uint32_t tdflags = HTOO32(
+	const uint32_t tdflags = HTOO32(
 	OHCI_TD_SET_DP(rd ? OHCI_TD_DP_IN : OHCI_TD_DP_OUT) |
 	OHCI_TD_SET_CC(OHCI_TD_NOCC) |
 	OHCI_TD_SET_TOGGLE(OHCI_TD_TOGGLE_CARRY) |



  1   2   3   4   5   6   7   8   9   10   >