[Midnightbsd-cvs] src [10056] trunk/sys/dev/usb: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun May 27 18:50:51 EDT 2018


Revision: 10056
          http://svnweb.midnightbsd.org/src/?rev=10056
Author:   laffer1
Date:     2018-05-27 18:50:50 -0400 (Sun, 27 May 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/sys/dev/usb/ufm_ioctl.h
    trunk/sys/dev/usb/uftdiio.h
    trunk/sys/dev/usb/usb.h
    trunk/sys/dev/usb/usb_bus.h
    trunk/sys/dev/usb/usb_busdma.c
    trunk/sys/dev/usb/usb_busdma.h
    trunk/sys/dev/usb/usb_cdc.h
    trunk/sys/dev/usb/usb_compat_linux.c
    trunk/sys/dev/usb/usb_compat_linux.h
    trunk/sys/dev/usb/usb_controller.h
    trunk/sys/dev/usb/usb_core.c
    trunk/sys/dev/usb/usb_core.h
    trunk/sys/dev/usb/usb_debug.c
    trunk/sys/dev/usb/usb_debug.h
    trunk/sys/dev/usb/usb_dev.c
    trunk/sys/dev/usb/usb_dev.h
    trunk/sys/dev/usb/usb_device.c
    trunk/sys/dev/usb/usb_device.h
    trunk/sys/dev/usb/usb_dynamic.c
    trunk/sys/dev/usb/usb_dynamic.h
    trunk/sys/dev/usb/usb_endian.h
    trunk/sys/dev/usb/usb_error.c
    trunk/sys/dev/usb/usb_freebsd.h
    trunk/sys/dev/usb/usb_generic.c
    trunk/sys/dev/usb/usb_generic.h
    trunk/sys/dev/usb/usb_handle_request.c
    trunk/sys/dev/usb/usb_hid.c
    trunk/sys/dev/usb/usb_hub.c
    trunk/sys/dev/usb/usb_hub.h
    trunk/sys/dev/usb/usb_if.m
    trunk/sys/dev/usb/usb_ioctl.h
    trunk/sys/dev/usb/usb_lookup.c
    trunk/sys/dev/usb/usb_mbuf.c
    trunk/sys/dev/usb/usb_mbuf.h
    trunk/sys/dev/usb/usb_msctest.c
    trunk/sys/dev/usb/usb_msctest.h
    trunk/sys/dev/usb/usb_parse.c
    trunk/sys/dev/usb/usb_pci.h
    trunk/sys/dev/usb/usb_pf.c
    trunk/sys/dev/usb/usb_pf.h
    trunk/sys/dev/usb/usb_process.c
    trunk/sys/dev/usb/usb_process.h
    trunk/sys/dev/usb/usb_request.c
    trunk/sys/dev/usb/usb_request.h
    trunk/sys/dev/usb/usb_transfer.c
    trunk/sys/dev/usb/usb_transfer.h
    trunk/sys/dev/usb/usb_util.h

Added Paths:
-----------
    trunk/sys/dev/usb/uled_ioctl.h
    trunk/sys/dev/usb/usb_freebsd_loader.h

Property Changed:
----------------
    trunk/sys/dev/usb/usb_if.m

Modified: trunk/sys/dev/usb/ufm_ioctl.h
===================================================================
--- trunk/sys/dev/usb/ufm_ioctl.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/ufm_ioctl.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,3 +1,5 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/ufm_ioctl.h 246115 2013-01-30 10:59:42Z hselasky $ */
 /*-
  * Copyright (c) 2001 M. Warner Losh
  * All rights reserved.
@@ -28,7 +30,8 @@
  * its contributors.
  */
 
-/*  $FreeBSD: stable/9/sys/dev/usb/ufm_ioctl.h 196219 2009-08-14 20:03:53Z jhb $ */
+#ifndef _UFM_IOCTL_H_
+#define	_UFM_IOCTL_H_
 
 #include <sys/ioccom.h>
 
@@ -37,3 +40,5 @@
 #define	FM_START	_IOWR('U', 202, int)
 #define	FM_STOP		_IOWR('U', 203, int)
 #define	FM_GET_STAT	_IOWR('U', 204, int)
+
+#endif			/* _UFM_IOCTL_H_ */

Modified: trunk/sys/dev/usb/uftdiio.h
===================================================================
--- trunk/sys/dev/usb/uftdiio.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/uftdiio.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright 2008-2012 - Symmetricom, Inc.
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *  $FreeBSD: stable/9/sys/dev/usb/uftdiio.h 265050 2014-04-28 13:28:10Z ian $ 
+ *  $FreeBSD: stable/10/sys/dev/usb/uftdiio.h 287035 2015-08-23 16:17:00Z ian $ 
  */
 
 /*
@@ -43,7 +44,7 @@
 	UFTDI_BITMODE_CPU_EMUL = 3,
 	UFTDI_BITMODE_FAST_SERIAL = 4,
 	UFTDI_BITMODE_CBUS = 5,
-	UFTDI_BITMODE_NONE = 0xff,
+	UFTDI_BITMODE_NONE = 0xff,	/* aka UART mode. */
 };
 
 /*
@@ -52,8 +53,9 @@
  *   iomask = Mask of bits enabled for bitbang output.
  *
  * For UFTDIIOC_GET_BITMODE:
- *   mode   = Unused.
- *   iomask = Returned snapshot of bitbang pin states at time of call.
+ *   mode   = Mode most recently set using UFTDIIOC_SET_BITMODE.
+ *   iomask = Returned snapshot of DBUS0..DBUS7 pin states at time of call.
+ *            Pin states can be read in any mode, not just bitbang modes.
  */
 struct uftdi_bitmode
 {
@@ -61,6 +63,26 @@
 	uint8_t iomask;
 };
 
+/*
+ * For UFTDIIOC_READ_EEPROM, UFTDIIOC_WRITE_EEPROM:
+ *
+ * IO is done in 16-bit words at the chip level; offset and length are in bytes,
+ * but must each be evenly divisible by two.
+ *
+ * It is not necessary to erase before writing.  For the FT232R device (only)
+ * you must set the latency timer to 0x77 before doing a series of eeprom writes
+ * (and restore it to the prior value when done).
+ */
+struct uftdi_eeio
+{
+	uint16_t offset;
+	uint16_t length;
+	uint16_t data[64];
+};
+
+/* Pass this value to confirm that eeprom erase request is not accidental. */
+#define	UFTDI_CONFIRM_ERASE	0x26139108
+
 #define	UFTDIIOC_RESET_IO	_IO('c', 0)	/* Reset config, flush fifos.*/
 #define	UFTDIIOC_RESET_RX	_IO('c', 1)	/* Flush input fifo. */
 #define	UFTDIIOC_RESET_TX	_IO('c', 2)	/* Flush output fifo. */
@@ -71,5 +93,8 @@
 #define	UFTDIIOC_SET_LATENCY	_IOW('c', 7, int)	/* 1-255 ms */
 #define	UFTDIIOC_GET_LATENCY	_IOR('c', 8, int)
 #define	UFTDIIOC_GET_HWREV	_IOR('c', 9, int)
+#define	UFTDIIOC_READ_EEPROM	_IOWR('c', 10, struct uftdi_eeio)
+#define	UFTDIIOC_WRITE_EEPROM	_IOW('c', 11, struct uftdi_eeio)
+#define	UFTDIIOC_ERASE_EEPROM	_IOW('c', 12, int)
 
 #endif

Added: trunk/sys/dev/usb/uled_ioctl.h
===================================================================
--- trunk/sys/dev/usb/uled_ioctl.h	                        (rev 0)
+++ trunk/sys/dev/usb/uled_ioctl.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -0,0 +1,44 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2014 Kevin Lo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/sys/dev/usb/uled_ioctl.h 273882 2014-10-31 07:33:56Z hselasky $
+ */
+
+#ifndef _ULED_IOCTL_H_
+#define _ULED_IOCTL_H_
+
+#include <sys/ioccom.h>
+
+struct uled_color {
+	uint8_t	red;
+	uint8_t	green;
+	uint8_t	blue;
+};
+
+#define	ULED_GET_COLOR	_IOR('U', 205, struct uled_color)
+#define	ULED_SET_COLOR	_IOW('U', 206, struct uled_color)
+
+#endif	/* _ULED_IOCTL_H_ */


Property changes on: trunk/sys/dev/usb/uled_ioctl.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/dev/usb/usb.h
===================================================================
--- trunk/sys/dev/usb/usb.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb.h 282510 2015-05-05 20:00:20Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb.h 282509 2015-05-05 19:59:15Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
@@ -40,7 +41,9 @@
 #define	_USB_STANDARD_H_
 
 #if defined(_KERNEL)
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include "opt_usb.h"
+#endif
 
 /* Declare parent SYSCTL USB node. */
 #ifdef SYSCTL_DECL
@@ -47,7 +50,9 @@
 SYSCTL_DECL(_hw_usb);
 #endif
 
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <sys/malloc.h>
+#endif
 
 MALLOC_DECLARE(M_USB);
 MALLOC_DECLARE(M_USBDEV);
@@ -54,8 +59,10 @@
 MALLOC_DECLARE(M_USBHC);
 #endif /* _KERNEL */
 
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <dev/usb/usb_endian.h>
 #include <dev/usb/usb_freebsd.h>
+#endif
 
 #define	USB_STACK_VERSION 2000		/* 2.0 */
 
@@ -552,6 +559,8 @@
 	uByte	bDescriptorType;
 	uByte	bMaxBurst;
 	uByte	bmAttributes;
+#define	UE_GET_BULK_STREAMS(x) ((x) & 0x0F)
+#define	UE_GET_SS_ISO_MULT(x) ((x) & 0x03)
 	uWord	wBytesPerInterval;
 } __packed;
 typedef struct usb_endpoint_ss_comp_descriptor
@@ -566,17 +575,23 @@
 typedef struct usb_string_descriptor usb_string_descriptor_t;
 
 #define	USB_MAKE_STRING_DESC(m,name)	\
-struct name {				\
+static const struct {			\
   uByte bLength;			\
   uByte bDescriptorType;		\
   uByte bData[sizeof((uint8_t []){m})];	\
-} __packed;				\
-static const struct name name = {	\
-  .bLength = sizeof(struct name),	\
+} __packed name = {			\
+  .bLength = sizeof(name),		\
   .bDescriptorType = UDESC_STRING,	\
   .bData = { m },			\
 }
 
+struct usb_string_lang {
+	uByte bLength;
+	uByte bDescriptorType;
+	uByte bData[2];
+} __packed;
+typedef struct usb_string_lang usb_string_lang_t;
+
 struct usb_hub_descriptor {
 	uByte	bDescLength;
 	uByte	bDescriptorType;
@@ -750,7 +765,7 @@
 #define	USB_REV_MAX	(USB_REV_3_0+1)
 
 /*
- * Supported host contoller modes.
+ * Supported host controller modes.
  */
 enum usb_hc_mode {
 	USB_MODE_HOST,		/* initiates transfers */
@@ -760,7 +775,7 @@
 #define	USB_MODE_MAX	(USB_MODE_DUAL+1)
 
 /*
- * The "USB_MODE" macros defines all the supported device states.
+ * The "USB_STATE" enums define all the supported device states.
  */
 enum usb_dev_state {
 	USB_STATE_DETACHED,
@@ -770,4 +785,18 @@
 	USB_STATE_CONFIGURED,
 };
 #define	USB_STATE_MAX	(USB_STATE_CONFIGURED+1)
+
+/*
+ * The "USB_EP_MODE" macros define all the currently supported
+ * endpoint modes.
+ */
+enum usb_ep_mode {
+	USB_EP_MODE_DEFAULT,
+	USB_EP_MODE_STREAMS,	/* USB3.0 specific */
+	USB_EP_MODE_HW_MASS_STORAGE,
+	USB_EP_MODE_HW_SERIAL,
+	USB_EP_MODE_HW_ETHERNET_CDC,
+	USB_EP_MODE_HW_ETHERNET_NCM,
+	USB_EP_MODE_MAX
+};
 #endif					/* _USB_STANDARD_H_ */

Modified: trunk/sys/dev/usb/usb_bus.h
===================================================================
--- trunk/sys/dev/usb/usb_bus.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_bus.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_bus.h 278291 2015-02-05 21:37:59Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_bus.h 287274 2015-08-29 06:23:40Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -53,14 +54,30 @@
 struct usb_bus {
 	struct usb_bus_stat stats_err;
 	struct usb_bus_stat stats_ok;
+#if USB_HAVE_ROOT_MOUNT_HOLD
 	struct root_hold_token *bus_roothold;
+#endif
+
+/* convenience macros */
+#define	USB_BUS_TT_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
+#define	USB_BUS_CS_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
+  
+#if USB_HAVE_PER_BUS_PROCESS
+#define	USB_BUS_GIANT_PROC(bus) (&(bus)->giant_callback_proc)
+#define	USB_BUS_NON_GIANT_ISOC_PROC(bus) (&(bus)->non_giant_isoc_callback_proc)
+#define	USB_BUS_NON_GIANT_BULK_PROC(bus) (&(bus)->non_giant_bulk_callback_proc)
+#define	USB_BUS_EXPLORE_PROC(bus) (&(bus)->explore_proc)
+#define	USB_BUS_CONTROL_XFER_PROC(bus) (&(bus)->control_xfer_proc)
 	/*
-	 * There are two callback processes. One for Giant locked
-	 * callbacks. One for non-Giant locked callbacks. This should
-	 * avoid congestion and reduce response time in most cases.
+	 * There are three callback processes. One for Giant locked
+	 * callbacks. One for non-Giant locked non-periodic callbacks
+	 * and one for non-Giant locked periodic callbacks. This
+	 * should avoid congestion and reduce response time in most
+	 * cases.
 	 */
 	struct usb_process giant_callback_proc;
-	struct usb_process non_giant_callback_proc;
+	struct usb_process non_giant_isoc_callback_proc;
+	struct usb_process non_giant_bulk_callback_proc;
 
 	/* Explore process */
 	struct usb_process explore_proc;
@@ -67,6 +84,7 @@
 
 	/* Control request process */
 	struct usb_process control_xfer_proc;
+#endif
 
 	struct usb_bus_msg explore_msg[2];
 	struct usb_bus_msg detach_msg[2];
@@ -83,6 +101,7 @@
 	 * This mutex protects the USB hardware:
 	 */
 	struct mtx bus_mtx;
+	struct mtx bus_spin_lock;
 	struct usb_xfer_queue intr_q;
 	struct usb_callout power_wdog;	/* power management */
 

Modified: trunk/sys/dev/usb/usb_busdma.c
===================================================================
--- trunk/sys/dev/usb/usb_busdma.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_busdma.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_busdma.c 291251 2015-11-24 12:19:20Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_busdma.c 291250 2015-11-24 12:17:00Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -59,6 +63,7 @@
 
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 #if USB_HAVE_BUSDMA
 static void	usb_dma_tag_create(struct usb_dma_tag *, usb_size_t, usb_size_t);
@@ -240,7 +245,9 @@
     struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len)
 {
 	struct usb_m_copy_in_arg arg = {cache, dst_offset};
-	(void) m_apply(m, src_offset, src_len, &usbd_m_copy_in_cb, &arg);
+	int error;
+
+	error = m_apply(m, src_offset, src_len, &usbd_m_copy_in_cb, &arg);
 }
 #endif
 

Modified: trunk/sys/dev/usb/usb_busdma.h
===================================================================
--- trunk/sys/dev/usb/usb_busdma.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_busdma.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_busdma.h 291063 2015-11-19 09:54:28Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_busdma.h 291062 2015-11-19 09:52:46Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -27,10 +28,12 @@
 #ifndef _USB_BUSDMA_H_
 #define	_USB_BUSDMA_H_
 
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <sys/uio.h>
 #include <sys/mbuf.h>
 
 #include <machine/bus.h>
+#endif
 
 /* defines */
 

Modified: trunk/sys/dev/usb/usb_cdc.h
===================================================================
--- trunk/sys/dev/usb/usb_cdc.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_cdc.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: usbcdc.h,v 1.9 2004/10/23 13:24:24 augustss Exp $	*/
-/*	$FreeBSD: stable/9/sys/dev/usb/usb_cdc.h 213809 2010-10-13 22:04:55Z hselasky $	*/
+/*	$FreeBSD: stable/10/sys/dev/usb/usb_cdc.h 213809 2010-10-13 22:04:55Z hselasky $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.

Modified: trunk/sys/dev/usb/usb_compat_linux.c
===================================================================
--- trunk/sys/dev/usb/usb_compat_linux.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_compat_linux.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_compat_linux.c 254555 2013-08-20 07:28:24Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_compat_linux.c 254243 2013-08-12 09:17:48Z hselasky $ */
 /*-
  * Copyright (c) 2007 Luigi Rizzo - Universita` di Pisa. All rights reserved.
  * Copyright (c) 2007 Hans Petter Selasky. All rights reserved.
@@ -25,6 +26,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -60,6 +64,7 @@
 #include <dev/usb/usb_hub.h>
 #include <dev/usb/usb_request.h>
 #include <dev/usb/usb_debug.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 struct usb_linux_softc {
 	LIST_ENTRY(usb_linux_softc) sc_attached_list;
@@ -108,7 +113,7 @@
 	DEVMETHOD(device_suspend, usb_linux_suspend),
 	DEVMETHOD(device_resume, usb_linux_resume),
 
-	{0, 0}
+	DEVMETHOD_END
 };
 
 static driver_t usb_linux_driver = {

Modified: trunk/sys/dev/usb/usb_compat_linux.h
===================================================================
--- trunk/sys/dev/usb/usb_compat_linux.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_compat_linux.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_compat_linux.h 198776 2009-11-01 21:48:18Z thompsa $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_compat_linux.h 198776 2009-11-01 21:48:18Z thompsa $ */
 /*-
  * Copyright (c) 2007 Luigi Rizzo - Universita` di Pisa. All rights reserved.
  * Copyright (c) 2007 Hans Petter Selasky. All rights reserved.

Modified: trunk/sys/dev/usb/usb_controller.h
===================================================================
--- trunk/sys/dev/usb/usb_controller.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_controller.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_controller.h 259602 2013-12-19 07:12:40Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_controller.h 259603 2013-12-19 07:13:59Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -107,7 +108,8 @@
 	/* USB Device mode only - Mandatory */
 
 	void    (*get_hw_ep_profile) (struct usb_device *udev, const struct usb_hw_ep_profile **ppf, uint8_t ep_addr);
-	void    (*set_stall) (struct usb_device *udev, struct usb_xfer *xfer, struct usb_endpoint *ep, uint8_t *did_stall);
+	void    (*xfer_stall) (struct usb_xfer *xfer);
+	void    (*set_stall) (struct usb_device *udev, struct usb_endpoint *ep, uint8_t *did_stall);
 
 	/* USB Device mode mandatory. USB Host mode optional. */
 
@@ -142,6 +144,10 @@
 	/* Optional for host mode */
 
 	usb_error_t	(*set_address) (struct usb_device *, struct mtx *, uint16_t);
+
+	/* Optional for device and host mode */
+
+	usb_error_t	(*set_endpoint_mode) (struct usb_device *, struct usb_endpoint *, uint8_t);
 };
 
 /*

Modified: trunk/sys/dev/usb/usb_core.c
===================================================================
--- trunk/sys/dev/usb/usb_core.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_core.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_core.c 217265 2011-01-11 13:59:06Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_core.c 246123 2013-01-30 15:46:26Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -30,6 +31,9 @@
  * http://www.usb.org/developers/devclass_docs/
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -51,7 +55,13 @@
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
+const struct usb_string_lang usb_string_lang_en = {
+	sizeof(usb_string_lang_en), UDESC_STRING,
+	{ 0x09, 0x04 } /* American English */
+};
+
 MALLOC_DEFINE(M_USB, "USB", "USB");
 MALLOC_DEFINE(M_USBDEV, "USBdev", "USB device");
 MALLOC_DEFINE(M_USBHC, "USBHC", "USB host controller");

Modified: trunk/sys/dev/usb/usb_core.h
===================================================================
--- trunk/sys/dev/usb/usb_core.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_core.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_core.h 278508 2015-02-10 13:18:48Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_core.h 278507 2015-02-10 13:16:53Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -44,6 +45,9 @@
 #define	USB_BUS_LOCK(_b)		mtx_lock(&(_b)->bus_mtx)
 #define	USB_BUS_UNLOCK(_b)		mtx_unlock(&(_b)->bus_mtx)
 #define	USB_BUS_LOCK_ASSERT(_b, _t)	mtx_assert(&(_b)->bus_mtx, _t)
+#define	USB_BUS_SPIN_LOCK(_b)		mtx_lock_spin(&(_b)->bus_spin_lock)
+#define	USB_BUS_SPIN_UNLOCK(_b)		mtx_unlock_spin(&(_b)->bus_spin_lock)
+#define	USB_BUS_SPIN_LOCK_ASSERT(_b, _t)	mtx_assert(&(_b)->bus_spin_lock, _t)
 #define	USB_XFER_LOCK(_x)		mtx_lock((_x)->xroot->xfer_mtx)
 #define	USB_XFER_UNLOCK(_x)		mtx_unlock((_x)->xroot->xfer_mtx)
 #define	USB_XFER_LOCK_ASSERT(_x, _t)	mtx_assert((_x)->xroot->xfer_mtx, _t)
@@ -69,6 +73,7 @@
 struct usb_page_cache;
 struct usb_xfer;
 struct usb_xfer_root;
+struct usb_string_lang;
 
 /* typedefs */
 
@@ -154,6 +159,7 @@
 	usb_frcount_t nframes;		/* number of USB frames to transfer */
 	usb_frcount_t aframes;		/* actual number of USB frames
 					 * transferred */
+	usb_stream_t stream_id;		/* USB3.0 specific field */
 
 	uint16_t max_packet_size;
 	uint16_t max_frame_size;
@@ -176,6 +182,7 @@
 /* external variables */
 
 extern struct mtx usb_ref_lock;
+extern const struct usb_string_lang usb_string_lang_en;
 
 /* typedefs */
 

Modified: trunk/sys/dev/usb/usb_debug.c
===================================================================
--- trunk/sys/dev/usb/usb_debug.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_debug.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_debug.c 242775 2012-11-08 16:13:51Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_debug.c 246122 2013-01-30 15:26:04Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -55,6 +59,7 @@
 
 #include <ddb/ddb.h>
 #include <ddb/db_sym.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 /*
  * Define this unconditionally in case a kernel module is loaded that
@@ -161,10 +166,12 @@
 usb_dump_queue(struct usb_endpoint *ep)
 {
 	struct usb_xfer *xfer;
+	usb_stream_t x;
 
 	printf("usb_dump_queue: endpoint=%p xfer: ", ep);
-	TAILQ_FOREACH(xfer, &ep->endpoint_q.head, wait_entry) {
-		printf(" %p", xfer);
+	for (x = 0; x != USB_MAX_EP_STREAMS; x++) {
+		TAILQ_FOREACH(xfer, &ep->endpoint_q[x].head, wait_entry)
+			printf(" %p", xfer);
 	}
 	printf("\n");
 }

Modified: trunk/sys/dev/usb/usb_debug.h
===================================================================
--- trunk/sys/dev/usb/usb_debug.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_debug.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_debug.h 242775 2012-11-08 16:13:51Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_debug.h 250205 2013-05-03 10:13:29Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -38,7 +39,7 @@
 #define	DPRINTFN(n,fmt,...) do {		\
   if ((USB_DEBUG_VAR) >= (n)) {			\
     printf("%s: " fmt,				\
-	   __FUNCTION__,## __VA_ARGS__);	\
+	   __FUNCTION__ ,##__VA_ARGS__);	\
   }						\
 } while (0)
 #define	DPRINTF(...)	DPRINTFN(1, __VA_ARGS__)

Modified: trunk/sys/dev/usb/usb_dev.c
===================================================================
--- trunk/sys/dev/usb/usb_dev.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_dev.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_dev.c 301254 2016-06-03 08:56:54Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_dev.c 301253 2016-06-03 08:55:28Z hselasky $ */
 /*-
  * Copyright (c) 2006-2008 Hans Petter Selasky. All rights reserved.
  *
@@ -27,6 +28,9 @@
  * usb_dev.c - An abstraction layer for creating devices under /dev/...
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -75,6 +79,7 @@
 #include <sys/syscallsubr.h>
 
 #include <machine/stdarg.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 #if USB_HAVE_UGEN
 

Modified: trunk/sys/dev/usb/usb_dev.h
===================================================================
--- trunk/sys/dev/usb/usb_dev.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_dev.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_dev.h 247090 2013-02-21 07:48:07Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_dev.h 246759 2013-02-13 12:35:17Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -27,11 +28,13 @@
 #ifndef _USB_DEV_H_
 #define	_USB_DEV_H_
 
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <sys/file.h>
 #include <sys/selinfo.h>
 #include <sys/poll.h>
 #include <sys/signalvar.h>
 #include <sys/proc.h>
+#endif
 
 struct usb_fifo;
 struct usb_mbuf;

Modified: trunk/sys/dev/usb/usb_device.c
===================================================================
--- trunk/sys/dev/usb/usb_device.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_device.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_device.c 310283 2016-12-19 18:32:26Z trasz $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_device.c 310281 2016-12-19 18:27:22Z trasz $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -78,6 +82,7 @@
 
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 /* function prototypes  */
 
@@ -108,7 +113,11 @@
 
 /* This variable is global to allow easy access to it: */
 
-int	usb_template = 0;
+#ifdef	USB_TEMPLATE
+int	usb_template = USB_TEMPLATE;
+#else
+int	usb_template;
+#endif
 
 TUNABLE_INT("hw.usb.usb_template", &usb_template);
 SYSCTL_INT(_hw_usb, OID_AUTO, template, CTLFLAG_RW | CTLFLAG_TUN,
@@ -202,7 +211,7 @@
 	/*
 	 * The default endpoint is always present and is checked separately:
 	 */
-	if ((udev->ctrl_ep.edesc) &&
+	if ((udev->ctrl_ep.edesc != NULL) &&
 	    ((udev->ctrl_ep.edesc->bEndpointAddress & EA_MASK) == ea_val)) {
 		ep = &udev->ctrl_ep;
 		goto found;
@@ -320,7 +329,7 @@
 	 * address" and "any direction" returns the first endpoint of the
 	 * interface. "iface_index" and "direction" is ignored:
 	 */
-	if ((udev->ctrl_ep.edesc) &&
+	if ((udev->ctrl_ep.edesc != NULL) &&
 	    ((udev->ctrl_ep.edesc->bEndpointAddress & ea_mask) == ea_val) &&
 	    ((udev->ctrl_ep.edesc->bmAttributes & type_mask) == type_val) &&
 	    (!index)) {
@@ -355,7 +364,6 @@
 	return (USB_ERR_NORMAL_COMPLETION);
 }
 
-
 /*------------------------------------------------------------------------*
  *	usb_init_endpoint
  *
@@ -370,6 +378,7 @@
     struct usb_endpoint *ep)
 {
 	struct usb_bus_methods *methods;
+	usb_stream_t x;
 
 	methods = udev->bus->methods;
 
@@ -379,13 +388,26 @@
 	ep->edesc = edesc;
 	ep->ecomp = ecomp;
 	ep->iface_index = iface_index;
-	TAILQ_INIT(&ep->endpoint_q.head);
-	ep->endpoint_q.command = &usbd_pipe_start;
 
+	/* setup USB stream queues */
+	for (x = 0; x != USB_MAX_EP_STREAMS; x++) {
+		TAILQ_INIT(&ep->endpoint_q[x].head);
+		ep->endpoint_q[x].command = &usbd_pipe_start;
+	}
+
 	/* the pipe is not supported by the hardware */
  	if (ep->methods == NULL)
 		return;
 
+	/* check for SUPER-speed streams mode endpoint */
+	if (udev->speed == USB_SPEED_SUPER && ecomp != NULL &&
+	    (edesc->bmAttributes & UE_XFERTYPE) == UE_BULK &&
+	    (UE_GET_BULK_STREAMS(ecomp->bmAttributes) != 0)) {
+		usbd_set_endpoint_mode(udev, ep, USB_EP_MODE_STREAMS);
+	} else {
+		usbd_set_endpoint_mode(udev, ep, USB_EP_MODE_DEFAULT);
+	}
+
 	/* clear stall, if any */
 	if (methods->clear_stall != NULL) {
 		USB_BUS_LOCK(udev->bus);
@@ -499,7 +521,7 @@
 	/* free "cdesc" after "ifaces" and "endpoints", if any */
 	if (udev->cdesc != NULL) {
 		if (udev->flags.usb_mode != USB_MODE_DEVICE)
-			free(udev->cdesc, M_USB);
+			usbd_free_config_desc(udev, udev->cdesc);
 		udev->cdesc = NULL;
 	}
 	/* set unconfigured state */
@@ -558,7 +580,7 @@
 	} else {
 		/* normal request */
 		err = usbd_req_get_config_desc_full(udev,
-		    NULL, &cdp, M_USB, index);
+		    NULL, &cdp, index);
 	}
 	if (err) {
 		goto done;
@@ -735,10 +757,6 @@
 
 	while ((id = usb_idesc_foreach(udev->cdesc, &ips))) {
 
-		/* check for interface overflow */
-		if (ips.iface_index == USB_IFACE_MAX)
-			break;			/* crazy */
-
 		iface = udev->ifaces + ips.iface_index;
 
 		/* check for specific interface match */
@@ -785,8 +803,11 @@
 		/* iterate all the endpoint descriptors */
 		while ((ed = usb_edesc_foreach(udev->cdesc, ed))) {
 
-			if (temp == USB_EP_MAX)
-				break;			/* crazy */
+			/* check if endpoint limit has been reached */
+			if (temp >= USB_MAX_EP_UNITS) {
+				DPRINTF("Endpoint limit reached\n");
+				break;
+			}
 
 			ep = udev->endpoints + temp;
 
@@ -813,6 +834,7 @@
 
 	if (cmd == USB_CFG_ALLOC) {
 		udev->ifaces_max = ips.iface_index;
+#if (USB_HAVE_FIXED_IFACE == 0)
 		udev->ifaces = NULL;
 		if (udev->ifaces_max != 0) {
 			udev->ifaces = malloc(sizeof(*iface) * udev->ifaces_max,
@@ -822,6 +844,8 @@
 				goto done;
 			}
 		}
+#endif
+#if (USB_HAVE_FIXED_ENDPOINT == 0)
 		if (ep_max != 0) {
 			udev->endpoints = malloc(sizeof(*ep) * ep_max,
 			        M_USB, M_WAITOK | M_ZERO);
@@ -832,6 +856,7 @@
 		} else {
 			udev->endpoints = NULL;
 		}
+#endif
 		USB_BUS_LOCK(udev->bus);
 		udev->endpoints_max = ep_max;
 		/* reset any ongoing clear-stall */
@@ -838,8 +863,9 @@
 		udev->ep_curr = NULL;
 		USB_BUS_UNLOCK(udev->bus);
 	}
-
+#if (USB_HAVE_FIXED_IFACE == 0) || (USB_HAVE_FIXED_ENDPOINT == 0) 
 done:
+#endif
 	if (err) {
 		if (cmd == USB_CFG_ALLOC) {
 cleanup:
@@ -849,14 +875,14 @@
 			udev->ep_curr = NULL;
 			USB_BUS_UNLOCK(udev->bus);
 
-			/* cleanup */
-			if (udev->ifaces != NULL)
-				free(udev->ifaces, M_USB);
-			if (udev->endpoints != NULL)
-				free(udev->endpoints, M_USB);
-
+#if (USB_HAVE_FIXED_IFACE == 0)
+			free(udev->ifaces, M_USB);
 			udev->ifaces = NULL;
+#endif
+#if (USB_HAVE_FIXED_ENDPOINT == 0)
+			free(udev->endpoints, M_USB);
 			udev->endpoints = NULL;
+#endif
 			udev->ifaces_max = 0;
 		}
 	}
@@ -942,6 +968,7 @@
     uint8_t do_stall)
 {
 	struct usb_xfer *xfer;
+	usb_stream_t x;
 	uint8_t et;
 	uint8_t was_stalled;
 
@@ -984,18 +1011,22 @@
 
 	if (do_stall || (!was_stalled)) {
 		if (!was_stalled) {
-			/* lookup the current USB transfer, if any */
-			xfer = ep->endpoint_q.curr;
-		} else {
-			xfer = NULL;
+			for (x = 0; x != USB_MAX_EP_STREAMS; x++) {
+				/* lookup the current USB transfer, if any */
+				xfer = ep->endpoint_q[x].curr;
+				if (xfer != NULL) {
+					/*
+					 * The "xfer_stall" method
+					 * will complete the USB
+					 * transfer like in case of a
+					 * timeout setting the error
+					 * code "USB_ERR_STALLED".
+					 */
+					(udev->bus->methods->xfer_stall) (xfer);
+				}
+			}
 		}
-
-		/*
-		 * If "xfer" is non-NULL the "set_stall" method will
-		 * complete the USB transfer like in case of a timeout
-		 * setting the error code "USB_ERR_STALLED".
-		 */
-		(udev->bus->methods->set_stall) (udev, xfer, ep, &do_stall);
+		(udev->bus->methods->set_stall) (udev, ep, &do_stall);
 	}
 	if (!do_stall) {
 		ep->toggle_next = 0;	/* reset data toggle */
@@ -1003,8 +1034,11 @@
 
 		(udev->bus->methods->clear_stall) (udev, ep);
 
-		/* start up the current or next transfer, if any */
-		usb_command_wrapper(&ep->endpoint_q, ep->endpoint_q.curr);
+		/* start the current or next transfer, if any */
+		for (x = 0; x != USB_MAX_EP_STREAMS; x++) {
+			usb_command_wrapper(&ep->endpoint_q[x],
+			    ep->endpoint_q[x].curr);
+		}
 	}
 	USB_BUS_UNLOCK(udev->bus);
 	return (0);
@@ -1862,6 +1896,7 @@
 			config_index++;
 			goto repeat_set_config;
 		}
+#if USB_HAVE_MSCTEST
 		if (config_index == 0) {
 			/*
 			 * Try to figure out if we have an
@@ -1874,7 +1909,9 @@
 				goto repeat_set_config;
 			}
 		}
+#endif
 	}
+#if USB_HAVE_MSCTEST
 	if (set_config_failed == 0 && config_index == 0 &&
 	    usb_test_quirk(&uaa, UQ_MSC_NO_SYNC_CACHE) == 0 &&
 	    usb_test_quirk(&uaa, UQ_MSC_NO_GETMAXLUN) == 0) {
@@ -1890,6 +1927,7 @@
 			goto repeat_set_config;
 		}
 	}
+#endif
 
 config_done:
 	DPRINTF("new dev (addr %d), udev=%p, parent_hub=%p\n",
@@ -1999,7 +2037,7 @@
 	USB_BUS_LOCK(bus);
 	LIST_INSERT_HEAD(&bus->pd_cleanup_list, pd, pd_next);
 	/* get cleanup going */
-	usb_proc_msignal(&bus->explore_proc,
+	usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus),
 	    &bus->cleanup_msg[0], &bus->cleanup_msg[1]);
 	USB_BUS_UNLOCK(bus);
 }
@@ -2149,7 +2187,7 @@
 	 * anywhere:
 	 */
 	USB_BUS_LOCK(udev->bus);
-	usb_proc_mwait(&udev->bus->non_giant_callback_proc,
+	usb_proc_mwait(USB_BUS_CS_PROC(udev->bus),
 	    &udev->cs_msg[0], &udev->cs_msg[1]);
 	USB_BUS_UNLOCK(udev->bus);
 
@@ -2869,3 +2907,41 @@
 	}
 	return (USB_ERR_NOMEM);
 }
+
+/*
+ * The following function is used to select the endpoint mode. It
+ * should not be called outside enumeration context.
+ */
+
+usb_error_t
+usbd_set_endpoint_mode(struct usb_device *udev, struct usb_endpoint *ep,
+    uint8_t ep_mode)
+{   
+	usb_error_t error;
+	uint8_t do_unlock;
+
+	/* Prevent re-enumeration */
+	do_unlock = usbd_enum_lock(udev);
+
+	if (udev->bus->methods->set_endpoint_mode != NULL) {
+		error = (udev->bus->methods->set_endpoint_mode) (
+		    udev, ep, ep_mode);
+	} else if (ep_mode != USB_EP_MODE_DEFAULT) {
+		error = USB_ERR_INVAL;
+	} else {
+		error = 0;
+	}
+
+	/* only set new mode regardless of error */
+	ep->ep_mode = ep_mode;
+
+	if (do_unlock)
+		usbd_enum_unlock(udev);
+	return (error);
+}
+
+uint8_t
+usbd_get_endpoint_mode(struct usb_device *udev, struct usb_endpoint *ep)
+{
+	return (ep->ep_mode);
+}

Modified: trunk/sys/dev/usb/usb_device.h
===================================================================
--- trunk/sys/dev/usb/usb_device.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_device.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_device.h 305735 2016-09-12 10:20:44Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_device.h 305734 2016-09-12 10:17:25Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -42,7 +43,7 @@
 
 #define	USB_CTRL_XFER_MAX 2
 
-/* "usb_parse_config()" commands */
+/* "usb_config_parse()" commands */
 
 #define	USB_CFG_ALLOC 0
 #define	USB_CFG_FREE 1
@@ -187,9 +188,17 @@
 	struct mtx device_mtx;
 	struct cv ctrlreq_cv;
 	struct cv ref_cv;
+#if (USB_HAVE_FIXED_IFACE == 0)
 	struct usb_interface *ifaces;
+#else
+	struct usb_interface ifaces[USB_IFACE_MAX];
+#endif
 	struct usb_endpoint ctrl_ep;	/* Control Endpoint 0 */
+#if (USB_HAVE_FIXED_ENDPOINT == 0)
 	struct usb_endpoint *endpoints;
+#else
+	struct usb_endpoint endpoints[USB_MAX_EP_UNITS];
+#endif
 	struct usb_power_save pwr_save;/* power save data */
 	struct usb_bus *bus;		/* our USB BUS */
 	device_t parent_dev;		/* parent device */
@@ -265,6 +274,10 @@
 	uint32_t clear_stall_errors;	/* number of clear-stall failures */
 
 	union usb_device_scratch scratch;
+
+#if (USB_HAVE_FIXED_CONFIG != 0)
+	uint32_t config_data[(USB_CONFIG_MAX + 3) / 4];
+#endif
 };
 
 /* globals */

Modified: trunk/sys/dev/usb/usb_dynamic.c
===================================================================
--- trunk/sys/dev/usb/usb_dynamic.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_dynamic.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_dynamic.c 273889 2014-10-31 08:06:21Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_dynamic.c 250207 2013-05-03 11:10:04Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -50,6 +54,8 @@
 #include <dev/usb/usb_process.h>
 #include <dev/usb/usb_device.h>
 #include <dev/usb/usb_dynamic.h>
+#include <dev/usb/usb_request.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 /* function prototypes */
 static usb_handle_req_t usb_temp_get_desc_w;
@@ -94,12 +100,8 @@
 static void
 usb_temp_unsetup_w(struct usb_device *udev)
 {
-	if (udev->usb_template_ptr) {
-
-		free(udev->usb_template_ptr, M_USB);
-
-		udev->usb_template_ptr = NULL;
-	}
+	usbd_free_config_desc(udev, udev->usb_template_ptr);
+	udev->usb_template_ptr = NULL;
 }
 
 void

Modified: trunk/sys/dev/usb/usb_dynamic.h
===================================================================
--- trunk/sys/dev/usb/usb_dynamic.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_dynamic.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_dynamic.h 225469 2011-09-10 15:55:36Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_dynamic.h 225469 2011-09-10 15:55:36Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *

Modified: trunk/sys/dev/usb/usb_endian.h
===================================================================
--- trunk/sys/dev/usb/usb_endian.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_endian.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_endian.h 196219 2009-08-14 20:03:53Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_endian.h 246122 2013-01-30 15:26:04Z hselasky $ */
 /*
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -27,8 +28,10 @@
 #ifndef _USB_ENDIAN_H_
 #define	_USB_ENDIAN_H_
 
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <sys/stdint.h>
 #include <sys/endian.h>
+#endif
 
 /*
  * Declare the basic USB record types. USB records have an alignment

Modified: trunk/sys/dev/usb/usb_error.c
===================================================================
--- trunk/sys/dev/usb/usb_error.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_error.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_error.c 217265 2011-01-11 13:59:06Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_error.c 246122 2013-01-30 15:26:04Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -45,6 +49,7 @@
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 static const char* usb_errstr_table[USB_ERR_MAX] = {
 	[USB_ERR_NORMAL_COMPLETION]	= "USB_ERR_NORMAL_COMPLETION",

Modified: trunk/sys/dev/usb/usb_freebsd.h
===================================================================
--- trunk/sys/dev/usb/usb_freebsd.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_freebsd.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_freebsd.h 277363 2015-01-19 07:03:40Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_freebsd.h 277364 2015-01-19 07:06:15Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -42,6 +43,14 @@
 #define	USB_HAVE_POWERD 1
 #define	USB_HAVE_MSCTEST 1
 #define	USB_HAVE_PF 1
+#define	USB_HAVE_ROOT_MOUNT_HOLD 1
+#define	USB_HAVE_ID_SECTION 1
+#define	USB_HAVE_PER_BUS_PROCESS 1
+#define	USB_HAVE_FIXED_ENDPOINT 0
+#define	USB_HAVE_FIXED_IFACE 0
+#define	USB_HAVE_FIXED_CONFIG 0
+#define	USB_HAVE_FIXED_PORT 0
+#define	USB_HAVE_DISABLE_ENUM 1
 
 /* define zero ticks callout value */
 #define	USB_CALLOUT_ZERO_TICKS 1
@@ -52,8 +61,12 @@
 #if (!defined(USB_HOST_ALIGN)) || (USB_HOST_ALIGN <= 0)
 /* Use default value. */
 #undef USB_HOST_ALIGN
+#if defined(__arm__) || defined(__mips__) || defined(__powerpc__)
+#define USB_HOST_ALIGN	32		/* Arm and MIPS need at least this much, if not more */
+#else
 #define	USB_HOST_ALIGN    8		/* bytes, must be power of two */
 #endif
+#endif
 /* Sanity check for USB_HOST_ALIGN: Verify power of two. */
 #if ((-USB_HOST_ALIGN) & USB_HOST_ALIGN) != USB_HOST_ALIGN
 #error "USB_HOST_ALIGN is not power of two."
@@ -61,8 +74,12 @@
 #define	USB_FS_ISOC_UFRAME_MAX 4	/* exclusive unit */
 #define	USB_BUS_MAX 256			/* units */
 #define	USB_MAX_DEVICES 128		/* units */
+#define	USB_CONFIG_MAX 65535		/* bytes */
 #define	USB_IFACE_MAX 32		/* units */
 #define	USB_FIFO_MAX 128		/* units */
+#define	USB_MAX_EP_STREAMS 8		/* units */
+#define	USB_MAX_EP_UNITS 32		/* units */
+#define	USB_MAX_PORTS 255		/* units */
 
 #define	USB_MAX_FS_ISOC_FRAMES_PER_XFER (120)	/* units */
 #define	USB_MAX_HS_ISOC_FRAMES_PER_XFER (8*120)	/* units */
@@ -79,5 +96,6 @@
 typedef uint32_t usb_size_t;		/* bytes */
 typedef uint32_t usb_ticks_t;		/* system defined */
 typedef uint16_t usb_power_mask_t;	/* see "USB_HW_POWER_XXX" */
+typedef uint16_t usb_stream_t;		/* stream ID */
 
 #endif	/* _USB_FREEBSD_H_ */

Added: trunk/sys/dev/usb/usb_freebsd_loader.h
===================================================================
--- trunk/sys/dev/usb/usb_freebsd_loader.h	                        (rev 0)
+++ trunk/sys/dev/usb/usb_freebsd_loader.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -0,0 +1,96 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_freebsd_loader.h 277364 2015-01-19 07:06:15Z hselasky $ */
+/*-
+ * Copyright (c) 2013 Hans Petter Selasky. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Including this file is mandatory for all USB related c-files in the loader.
+ */
+
+#ifndef _USB_FREEBSD_LOADER_H_
+#define	_USB_FREEBSD_LOADER_H_
+
+/* Default USB configuration */
+#define	USB_HAVE_UGEN 0
+#define	USB_HAVE_DEVCTL 0
+#define	USB_HAVE_BUSDMA 1
+#define	USB_HAVE_COMPAT_LINUX 0
+#define	USB_HAVE_USER_IO 0
+#define	USB_HAVE_MBUF 0
+#define	USB_HAVE_TT_SUPPORT 1
+#define	USB_HAVE_POWERD 1
+#define	USB_HAVE_MSCTEST 0
+#define	USB_HAVE_PF 0
+#define	USB_HAVE_ROOT_MOUNT_HOLD 0
+#define	USB_HAVE_ID_SECTION 0
+#define	USB_HAVE_PER_BUS_PROCESS 0
+#define	USB_HAVE_FIXED_ENDPOINT 0
+#define	USB_HAVE_FIXED_IFACE 0
+#define	USB_HAVE_FIXED_CONFIG 0
+#define	USB_HAVE_FIXED_PORT 0
+#define	USB_HAVE_DISABLE_ENUM 0
+
+#define	USB_CALLOUT_ZERO_TICKS 1
+
+#define	USB_TD_GET_PROC(td) (td)->td_proc
+#define	USB_PROC_GET_GID(td) (td)->p_pgid
+
+#if (!defined(USB_HOST_ALIGN)) || (USB_HOST_ALIGN <= 0)
+/* Use default value. */
+#undef USB_HOST_ALIGN
+#define	USB_HOST_ALIGN    8		/* bytes, must be power of two */
+#endif
+/* Sanity check for USB_HOST_ALIGN: Verify power of two. */
+#if ((-USB_HOST_ALIGN) & USB_HOST_ALIGN) != USB_HOST_ALIGN
+#error "USB_HOST_ALIGN is not power of two."
+#endif
+#define	USB_FS_ISOC_UFRAME_MAX 4	/* exclusive unit */
+#define	USB_BUS_MAX 256			/* units */
+#define	USB_MAX_DEVICES 128		/* units */
+#define	USB_CONFIG_MAX 65535		/* bytes */
+#define	USB_IFACE_MAX 32		/* units */
+#define	USB_FIFO_MAX 128		/* units */
+#define	USB_MAX_EP_UNITS 32		/* units */
+#define	USB_MAX_EP_STREAMS 8		/* units */
+#define	USB_MAX_PORTS 255		/* units */
+
+#define	USB_MAX_FS_ISOC_FRAMES_PER_XFER (120)	/* units */
+#define	USB_MAX_HS_ISOC_FRAMES_PER_XFER (8*120)	/* units */
+
+#define	USB_HUB_MAX_DEPTH	5
+#define	USB_EP0_BUFSIZE		1024	/* bytes */
+#define	USB_CS_RESET_LIMIT	20	/* failures = 20 * 50 ms = 1sec */
+
+#define	USB_MAX_AUTO_QUIRK	8	/* maximum number of dynamic quirks */
+
+typedef uint32_t usb_timeout_t;		/* milliseconds */
+typedef uint32_t usb_frlength_t;	/* bytes */
+typedef uint32_t usb_frcount_t;		/* units */
+typedef uint32_t usb_size_t;		/* bytes */
+typedef uint32_t usb_ticks_t;		/* system defined */
+typedef uint16_t usb_power_mask_t;	/* see "USB_HW_POWER_XXX" */
+typedef uint16_t usb_stream_t;		/* stream ID */
+
+#endif					/* _USB_FREEBSD_LOADER_H_ */


Property changes on: trunk/sys/dev/usb/usb_freebsd_loader.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/dev/usb/usb_generic.c
===================================================================
--- trunk/sys/dev/usb/usb_generic.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_generic.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_generic.c 305735 2016-09-12 10:20:44Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_generic.c 305734 2016-09-12 10:17:25Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -67,6 +71,7 @@
 
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 #if USB_HAVE_UGEN
 
@@ -252,6 +257,7 @@
 
 	usb_config[0].type = ed->bmAttributes & UE_XFERTYPE;
 	usb_config[0].endpoint = ed->bEndpointAddress & UE_ADDR;
+	usb_config[0].stream_id = 0;	/* XXX support more stream ID's */
 	usb_config[0].direction = UE_DIR_TX;
 	usb_config[0].interval = USB_DEFAULT_INTERVAL;
 	usb_config[0].flags.proxy_buffer = 1;
@@ -320,6 +326,7 @@
 
 	usb_config[0].type = ed->bmAttributes & UE_XFERTYPE;
 	usb_config[0].endpoint = ed->bEndpointAddress & UE_ADDR;
+	usb_config[0].stream_id = 0;	/* XXX support more stream ID's */
 	usb_config[0].direction = UE_DIR_RX;
 	usb_config[0].interval = USB_DEFAULT_INTERVAL;
 	usb_config[0].flags.proxy_buffer = 1;
@@ -675,18 +682,21 @@
 	if ((ugd->ugd_config_index == USB_UNCONFIG_INDEX) ||
 	    (ugd->ugd_config_index == udev->curr_config_index)) {
 		cdesc = usbd_get_config_descriptor(udev);
-		if (cdesc == NULL) {
+		if (cdesc == NULL)
 			return (ENXIO);
-		}
 		free_data = 0;
 
 	} else {
+#if (USB_HAVE_FIXED_CONFIG == 0)
 		if (usbd_req_get_config_desc_full(udev,
-		    NULL, &cdesc, M_USBDEV,
-		    ugd->ugd_config_index)) {
+		    NULL, &cdesc, ugd->ugd_config_index)) {
 			return (ENXIO);
 		}
 		free_data = 1;
+#else
+		/* configuration descriptor data is shared */
+		return (EINVAL);
+#endif
 	}
 
 	len = UGETW(cdesc->wTotalLength);
@@ -700,9 +710,9 @@
 
 	error = copyout(cdesc, ugd->ugd_data, len);
 
-	if (free_data) {
-		free(cdesc, M_USBDEV);
-	}
+	if (free_data)
+		usbd_free_config_desc(udev, cdesc);
+
 	return (error);
 }
 
@@ -1388,6 +1398,7 @@
 		struct usb_fs_start *pstart;
 		struct usb_fs_stop *pstop;
 		struct usb_fs_open *popen;
+		struct usb_fs_open_stream *popen_stream;
 		struct usb_fs_close *pclose;
 		struct usb_fs_clear_stall_sync *pstall;
 		void   *addr;
@@ -1452,6 +1463,7 @@
 		break;
 
 	case USB_FS_OPEN:
+	case USB_FS_OPEN_STREAM:
 		if (u.popen->ep_index >= f->fs_ep_max) {
 			error = EINVAL;
 			break;
@@ -1503,6 +1515,8 @@
 		usb_config[0].frames = u.popen->max_frames;
 		usb_config[0].bufsize = u.popen->max_bufsize;
 		usb_config[0].usb_mode = USB_MODE_DUAL;	/* both modes */
+		if (cmd == USB_FS_OPEN_STREAM)
+			usb_config[0].stream_id = u.popen_stream->stream_id;
 
 		if (usb_config[0].type == UE_CONTROL) {
 			if (f->udev->flags.usb_mode != USB_MODE_HOST) {

Modified: trunk/sys/dev/usb/usb_generic.h
===================================================================
--- trunk/sys/dev/usb/usb_generic.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_generic.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_generic.h 196219 2009-08-14 20:03:53Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_generic.h 196219 2009-08-14 20:03:53Z jhb $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *

Modified: trunk/sys/dev/usb/usb_handle_request.c
===================================================================
--- trunk/sys/dev/usb/usb_handle_request.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_handle_request.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_handle_request.c 247090 2013-02-21 07:48:07Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_handle_request.c 246759 2013-02-13 12:35:17Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -61,6 +65,7 @@
 
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 /* function prototypes */
 

Modified: trunk/sys/dev/usb/usb_hid.c
===================================================================
--- trunk/sys/dev/usb/usb_hid.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_hid.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,8 +1,6 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_hid.c 296444 2016-03-07 09:37:07Z hselasky $ */
 /*	$NetBSD: hid.c,v 1.17 2001/11/13 06:24:53 lukem Exp $	*/
-
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: stable/9/sys/dev/usb/usb_hid.c 296445 2016-03-07 09:39:35Z hselasky $");
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -33,6 +31,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -64,6 +65,7 @@
 #include <dev/usb/usb_process.h>
 #include <dev/usb/usb_device.h>
 #include <dev/usb/usb_request.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 static void hid_clear_local(struct hid_item *);
 static uint8_t hid_get_byte(struct hid_data *s, const uint16_t wSize);

Modified: trunk/sys/dev/usb/usb_hub.c
===================================================================
--- trunk/sys/dev/usb/usb_hub.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_hub.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_hub.c 279637 2015-03-05 09:35:15Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_hub.c 324798 2017-10-20 10:01:21Z hselasky $ */
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
@@ -30,6 +31,9 @@
  * USB spec: http://www.usb.org/developers/docs/usbspec.zip 
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -68,6 +72,7 @@
 
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 #define	UHUB_INTR_INTERVAL 250		/* ms */
 enum {
@@ -94,6 +99,20 @@
     &usb_power_timeout, 0, "USB power timeout");
 #endif
 
+#if USB_HAVE_DISABLE_ENUM
+static int usb_disable_enumeration = 0;
+SYSCTL_INT(_hw_usb, OID_AUTO, disable_enumeration, CTLFLAG_RWTUN,
+    &usb_disable_enumeration, 0, "Set to disable all USB device enumeration. "
+	"This can secure against USB devices turning evil, "
+	"for example a USB memory stick becoming a USB keyboard.");
+TUNABLE_INT("hw.usb.disable_enumeration", &usb_disable_enumeration);
+
+static int usb_disable_port_power = 0;
+SYSCTL_INT(_hw_usb, OID_AUTO, disable_port_power, CTLFLAG_RWTUN,
+    &usb_disable_port_power, 0, "Set to disable all USB port power.");
+TUNABLE_INT("hw.usb.disable_port_power", &usb_disable_port_power);
+#endif
+
 struct uhub_current_state {
 	uint16_t port_change;
 	uint16_t port_status;
@@ -101,13 +120,19 @@
 
 struct uhub_softc {
 	struct uhub_current_state sc_st;/* current state */
+#if (USB_HAVE_FIXED_PORT != 0)
+	struct usb_hub sc_hub;
+#endif
 	device_t sc_dev;		/* base device */
 	struct mtx sc_mtx;		/* our mutex */
 	struct usb_device *sc_udev;	/* USB device */
 	struct usb_xfer *sc_xfer[UHUB_N_TRANSFER];	/* interrupt xfer */
+#if USB_HAVE_DISABLE_ENUM
+	int sc_disable_enumeration;
+	int sc_disable_port_power;
+#endif
 	uint8_t	sc_flags;
 #define	UHUB_FLAG_DID_EXPLORE 0x01
-	char	sc_name[32];
 };
 
 #define	UHUB_PROTO(sc) ((sc)->sc_udev->ddesc.bDeviceProtocol)
@@ -179,7 +204,7 @@
 	DEVMETHOD(bus_child_location_str, uhub_child_location_string),
 	DEVMETHOD(bus_child_pnpinfo_str, uhub_child_pnpinfo_string),
 	DEVMETHOD(bus_driver_added, uhub_driver_added),
-	{0, 0}
+	DEVMETHOD_END
 };
 
 static driver_t uhub_driver = {
@@ -327,7 +352,7 @@
 	}
 	up->req_reset_tt = req;
 	/* get reset transfer started */
-	usb_proc_msignal(&udev->bus->non_giant_callback_proc,
+	usb_proc_msignal(USB_BUS_TT_PROC(udev->bus),
 	    &hub->tt_msg[0], &hub->tt_msg[1]);
 }
 #endif
@@ -613,9 +638,9 @@
 	err = usbd_req_clear_port_feature(udev, NULL,
 	    portno, UHF_C_PORT_CONNECTION);
 
-	if (err) {
+	if (err)
 		goto error;
-	}
+
 	/* check if there is a child */
 
 	if (child != NULL) {
@@ -628,14 +653,22 @@
 	/* get fresh status */
 
 	err = uhub_read_port_status(sc, portno);
-	if (err) {
+	if (err)
 		goto error;
+
+#if USB_HAVE_DISABLE_ENUM
+	/* check if we should skip enumeration from this USB HUB */
+	if (usb_disable_enumeration != 0 ||
+	    sc->sc_disable_enumeration != 0) {
+		DPRINTF("Enumeration is disabled!\n");
+		goto error;
 	}
+#endif
 	/* check if nothing is connected to the port */
 
-	if (!(sc->sc_st.port_status & UPS_CURRENT_CONNECT_STATUS)) {
+	if (!(sc->sc_st.port_status & UPS_CURRENT_CONNECT_STATUS))
 		goto error;
-	}
+
 	/* check if there is no power on the port and print a warning */
 
 	switch (udev->speed) {
@@ -1183,9 +1216,13 @@
 	struct usb_hub *hub;
 	struct usb_hub_descriptor hubdesc20;
 	struct usb_hub_ss_descriptor hubdesc30;
+#if USB_HAVE_DISABLE_ENUM
+	struct sysctl_ctx_list *sysctl_ctx;
+	struct sysctl_oid *sysctl_tree;
+#endif
 	uint16_t pwrdly;
+	uint16_t nports;
 	uint8_t x;
-	uint8_t nports;
 	uint8_t portno;
 	uint8_t removable;
 	uint8_t iface_index;
@@ -1196,9 +1233,6 @@
 
 	mtx_init(&sc->sc_mtx, "USB HUB mutex", NULL, MTX_DEF);
 
-	snprintf(sc->sc_name, sizeof(sc->sc_name), "%s",
-	    device_get_nameunit(dev));
-
 	device_set_usb_desc(dev);
 
 	DPRINTFN(2, "depth=%d selfpowered=%d, parent=%p, "
@@ -1332,12 +1366,19 @@
 		DPRINTFN(0, "portless HUB\n");
 		goto error;
 	}
+	if (nports > USB_MAX_PORTS) {
+		DPRINTF("Port limit exceeded\n");
+		goto error;
+	}
+#if (USB_HAVE_FIXED_PORT == 0)
 	hub = malloc(sizeof(hub[0]) + (sizeof(hub->ports[0]) * nports),
 	    M_USBDEV, M_WAITOK | M_ZERO);
 
-	if (hub == NULL) {
+	if (hub == NULL)
 		goto error;
-	}
+#else
+	hub = &sc->sc_hub;
+#endif
 	udev->hub = hub;
 
 	/* initialize HUB structure */
@@ -1376,6 +1417,34 @@
 	/* wait with power off for a while */
 	usb_pause_mtx(NULL, USB_MS_TO_TICKS(USB_POWER_DOWN_TIME));
 
+#if USB_HAVE_DISABLE_ENUM
+	/* Add device sysctls */
+
+	sysctl_ctx = device_get_sysctl_ctx(dev);
+	sysctl_tree = device_get_sysctl_tree(dev);
+
+	if (sysctl_ctx != NULL && sysctl_tree != NULL) {
+		char path[128];
+
+		snprintf(path, sizeof(path), "dev.uhub.%d.disable_enumeration",
+		    device_get_unit(dev));
+		TUNABLE_INT_FETCH(path, &sc->sc_disable_enumeration);
+
+		(void) SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
+		    OID_AUTO, "disable_enumeration", CTLFLAG_RWTUN,
+		    &sc->sc_disable_enumeration, 0,
+		    "Set to disable enumeration on this USB HUB.");
+
+		snprintf(path, sizeof(path), "dev.uhub.%d.disable_port_power",
+		    device_get_unit(dev));
+		TUNABLE_INT_FETCH(path, &sc->sc_disable_port_power);
+
+		(void) SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
+		    OID_AUTO, "disable_port_power", CTLFLAG_RWTUN,
+		    &sc->sc_disable_port_power, 0,
+		    "Set to disable USB port power on this USB HUB.");
+	}
+#endif
 	/*
 	 * To have the best chance of success we do things in the exact same
 	 * order as Windoze98.  This should not be necessary, but some
@@ -1430,13 +1499,27 @@
 			removable++;
 			break;
 		}
-		if (!err) {
-			/* turn the power on */
-			err = usbd_req_set_port_feature(udev, NULL,
-			    portno, UHF_PORT_POWER);
+		if (err == 0) {
+#if USB_HAVE_DISABLE_ENUM
+			/* check if we should disable USB port power or not */
+			if (usb_disable_port_power != 0 ||
+			    sc->sc_disable_port_power != 0) {
+				/* turn the power off */
+				DPRINTFN(2, "Turning port %d power off\n", portno);
+				err = usbd_req_clear_port_feature(udev, NULL,
+				    portno, UHF_PORT_POWER);
+			} else {
+#endif
+				/* turn the power on */
+				DPRINTFN(2, "Turning port %d power on\n", portno);
+				err = usbd_req_set_port_feature(udev, NULL,
+				    portno, UHF_PORT_POWER);
+#if USB_HAVE_DISABLE_ENUM
+			}
+#endif
 		}
-		if (err) {
-			DPRINTFN(0, "port %d power on failed, %s\n",
+		if (err != 0) {
+			DPRINTFN(0, "port %d power on or off failed, %s\n",
 			    portno, usbd_errstr(err));
 		}
 		DPRINTF("turn on port %d power\n",
@@ -1465,10 +1548,10 @@
 error:
 	usbd_transfer_unsetup(sc->sc_xfer, UHUB_N_TRANSFER);
 
-	if (udev->hub) {
-		free(udev->hub, M_USBDEV);
-		udev->hub = NULL;
-	}
+#if (USB_HAVE_FIXED_PORT == 0)
+	free(udev->hub, M_USBDEV);
+#endif
+	udev->hub = NULL;
 
 	mtx_destroy(&sc->sc_mtx);
 
@@ -1512,11 +1595,14 @@
 #if USB_HAVE_TT_SUPPORT
 	/* Make sure our TT messages are not queued anywhere */
 	USB_BUS_LOCK(bus);
-	usb_proc_mwait(&bus->non_giant_callback_proc,
+	usb_proc_mwait(USB_BUS_TT_PROC(bus),
 	    &hub->tt_msg[0], &hub->tt_msg[1]);
 	USB_BUS_UNLOCK(bus);
 #endif
+
+#if (USB_HAVE_FIXED_PORT == 0)
 	free(hub, M_USBDEV);
+#endif
 	sc->sc_udev->hub = NULL;
 
 	mtx_destroy(&sc->sc_mtx);
@@ -1611,11 +1697,19 @@
 		}
 		goto done;
 	}
-	snprintf(buf, buflen, "bus=%u hubaddr=%u port=%u devaddr=%u interface=%u"
-	    " ugen=%s",
-	    (res.udev->parent_hub != NULL) ? res.udev->parent_hub->device_index : 0,
-	    res.portno, device_get_unit(res.udev->bus->bdev),
-	    res.udev->device_index, res.iface_index, res.udev->ugen_name);
+	snprintf(buf, buflen, "bus=%u hubaddr=%u port=%u devaddr=%u"
+	    " interface=%u"
+#if USB_HAVE_UGEN
+	    " ugen=%s"
+#endif
+	    , device_get_unit(res.udev->bus->bdev)
+	    , (res.udev->parent_hub != NULL) ?
+	    res.udev->parent_hub->device_index : 0
+	    , res.portno, res.udev->device_index, res.iface_index
+#if USB_HAVE_UGEN
+	    , res.udev->ugen_name
+#endif
+	    );
 done:
 	mtx_unlock(&Giant);
 
@@ -2041,9 +2135,11 @@
 			data_len += len;
 		}
 
-		/* check double buffered transfers */
-
-		TAILQ_FOREACH(pipe_xfer, &xfer->endpoint->endpoint_q.head,
+		/*
+		 * Check double buffered transfers. Only stream ID
+		 * equal to zero is valid here!
+		 */
+		TAILQ_FOREACH(pipe_xfer, &xfer->endpoint->endpoint_q[0].head,
 		    wait_entry) {
 
 			/* skip self, if any */
@@ -2179,6 +2275,11 @@
 
 	DPRINTF("\n");
 
+	if (cold != 0) {
+		DPRINTF("Cold\n");
+		return;
+	}
+
 	if (bus == NULL) {
 		DPRINTF("No bus pointer!\n");
 		return;
@@ -2197,7 +2298,7 @@
 	if (do_probe) {
 		bus->do_probe = 1;
 	}
-	if (usb_proc_msignal(&bus->explore_proc,
+	if (usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus),
 	    &bus->explore_msg[0], &bus->explore_msg[1])) {
 		/* ignore */
 	}
@@ -2244,6 +2345,26 @@
 }
 
 /*------------------------------------------------------------------------*
+ *	usb_needs_explore_init
+ *
+ * This function will ensure that the USB controllers are not enumerated
+ * until the "cold" variable is cleared.
+ *------------------------------------------------------------------------*/
+static void
+usb_needs_explore_init(void *arg)
+{
+	/*
+	 * The cold variable should be cleared prior to this function
+	 * being called:
+	 */
+	if (cold == 0)
+		usb_needs_explore_all();
+	else
+		DPRINTFN(-1, "Cold variable is still set!\n");
+}
+SYSINIT(usb_needs_explore_init, SI_SUB_KICK_SCHEDULER, SI_ORDER_SECOND, usb_needs_explore_init, NULL);
+
+/*------------------------------------------------------------------------*
  *	usb_bus_power_update
  *
  * This function will ensure that all USB devices on the given bus are

Modified: trunk/sys/dev/usb/usb_hub.h
===================================================================
--- trunk/sys/dev/usb/usb_hub.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_hub.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_hub.h 267350 2014-06-11 06:45:52Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_hub.h 267347 2014-06-11 05:39:08Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -54,7 +55,11 @@
 	uint16_t portpower;		/* mA per USB port */
 	uint8_t	isoc_last_time;
 	uint8_t	nports;
+#if (USB_HAVE_FIXED_PORT == 0)
 	struct usb_port ports[0];
+#else
+	struct usb_port ports[USB_MAX_PORTS];
+#endif
 };
 
 /* function prototypes */

Modified: trunk/sys/dev/usb/usb_if.m
===================================================================
--- trunk/sys/dev/usb/usb_if.m	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_if.m	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 #-
 # Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
 #
@@ -24,7 +25,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
-# $FreeBSD: stable/9/sys/dev/usb/usb_if.m 229096 2011-12-31 14:22:02Z hselasky $
+# $FreeBSD: stable/10/sys/dev/usb/usb_if.m 228483 2011-12-14 00:28:54Z hselasky $
 #
 
 # USB interface description


Property changes on: trunk/sys/dev/usb/usb_if.m
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/dev/usb/usb_ioctl.h
===================================================================
--- trunk/sys/dev/usb/usb_ioctl.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_ioctl.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_ioctl.h 254566 2013-08-20 14:19:00Z emaste $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_ioctl.h 269922 2014-08-13 08:21:52Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
@@ -29,6 +30,7 @@
 #ifndef _USB_IOCTL_H_
 #define	_USB_IOCTL_H_
 
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <sys/ioccom.h>
 #include <sys/cdefs.h>
 
@@ -36,6 +38,7 @@
 
 #include <dev/usb/usb_endian.h>
 #include <dev/usb/usb.h>
+#endif
 
 #define	USB_DEVICE_NAME "usbctl"
 #define	USB_DEVICE_DIR "usb"
@@ -62,6 +65,7 @@
 	USB_TEMP_AUDIO,		/* USB Audio */
 	USB_TEMP_KBD,		/* USB Keyboard */
 	USB_TEMP_MOUSE,		/* USB Mouse */
+	USB_TEMP_PHONE,		/* USB Phone */
 	USB_TEMP_MAX,
 };
 
@@ -329,6 +333,7 @@
 #define	USB_FS_OPEN		_IOWR('U', 197, struct usb_fs_open)
 #define	USB_FS_CLOSE		_IOW ('U', 198, struct usb_fs_close)
 #define	USB_FS_CLEAR_STALL_SYNC _IOW ('U', 199, struct usb_fs_clear_stall_sync)
+#define	USB_FS_OPEN_STREAM	_IOWR('U', 200, struct usb_fs_open_stream)
 
 /* USB quirk system interface */
 #define	USB_DEV_QUIRK_GET	_IOWR('Q', 0, struct usb_gen_quirk)

Modified: trunk/sys/dev/usb/usb_lookup.c
===================================================================
--- trunk/sys/dev/usb/usb_lookup.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_lookup.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_lookup.c 223538 2011-06-25 15:51:44Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_lookup.c 246194 2013-02-01 07:05:43Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -47,6 +51,7 @@
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 /*------------------------------------------------------------------------*
  *	usbd_lookup_id_by_info
@@ -174,7 +179,7 @@
 #define	MFL_SIZE "0"
 #endif
 
-#ifdef KLD_MODULE
+#if defined(KLD_MODULE) && (USB_HAVE_ID_SECTION != 0)
 static const char __section("bus_autoconf_format") __used usb_id_format[] = {
 
 	/* Declare that three different sections use the same format */

Modified: trunk/sys/dev/usb/usb_mbuf.c
===================================================================
--- trunk/sys/dev/usb/usb_mbuf.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_mbuf.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_mbuf.c 217265 2011-01-11 13:59:06Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_mbuf.c 246122 2013-01-30 15:26:04Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -47,6 +51,7 @@
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usb_dev.h>
 #include <dev/usb/usb_mbuf.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 /*------------------------------------------------------------------------*
  *      usb_alloc_mbufs - allocate mbufs to an usbd interface queue

Modified: trunk/sys/dev/usb/usb_mbuf.h
===================================================================
--- trunk/sys/dev/usb/usb_mbuf.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_mbuf.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_mbuf.h 196219 2009-08-14 20:03:53Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_mbuf.h 196219 2009-08-14 20:03:53Z jhb $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *

Modified: trunk/sys/dev/usb/usb_msctest.c
===================================================================
--- trunk/sys/dev/usb/usb_msctest.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_msctest.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_msctest.c 283174 2015-05-21 06:53:55Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_msctest.c 283173 2015-05-21 06:47:20Z hselasky $ */
 /*-
  * Copyright (c) 2008,2011 Hans Petter Selasky. All rights reserved.
  *
@@ -32,6 +33,9 @@
  * mass storage quirks for not supported SCSI commands!
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -66,6 +70,7 @@
 #include <dev/usb/usb_request.h>
 #include <dev/usb/usb_util.h>
 #include <dev/usb/quirk/usb_quirk.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 enum {
 	ST_COMMAND,

Modified: trunk/sys/dev/usb/usb_msctest.h
===================================================================
--- trunk/sys/dev/usb/usb_msctest.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_msctest.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_msctest.h 283174 2015-05-21 06:53:55Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_msctest.h 283173 2015-05-21 06:47:20Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *

Modified: trunk/sys/dev/usb/usb_parse.c
===================================================================
--- trunk/sys/dev/usb/usb_parse.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_parse.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_parse.c 217265 2011-01-11 13:59:06Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_parse.c 250204 2013-05-03 09:23:06Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -47,7 +51,12 @@
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdi_util.h>
 
+#define	USB_DEBUG_VAR usb_debug
 
+#include <dev/usb/usb_core.h>
+#include <dev/usb/usb_debug.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
+
 /*------------------------------------------------------------------------*
  *	usb_desc_foreach
  *
@@ -139,7 +148,7 @@
 	}
 
 	if (ps->desc == NULL) {
-		/* first time */
+		/* first time or zero descriptors */
 	} else if (new_iface) {
 		/* new interface */
 		ps->iface_index ++;
@@ -148,6 +157,14 @@
 		/* new alternate interface */
 		ps->iface_index_alt ++;
 	}
+#if (USB_IFACE_MAX <= 0)
+#error "USB_IFACE_MAX must be defined greater than zero"
+#endif
+	/* check for too many interfaces */
+	if (ps->iface_index >= USB_IFACE_MAX) {
+		DPRINTF("Interface limit reached\n");
+		id = NULL;
+	}
 
 	/* store and return current descriptor */
 	ps->desc = (struct usb_descriptor *)id;

Modified: trunk/sys/dev/usb/usb_pci.h
===================================================================
--- trunk/sys/dev/usb/usb_pci.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_pci.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_pci.h 196219 2009-08-14 20:03:53Z jhb $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_pci.h 246122 2013-01-30 15:26:04Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -31,9 +32,11 @@
  * We don't want the following files included everywhere, that's why
  * they are in a separate file.
  */
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
 
 #include <sys/rman.h>
+#endif
 
 #endif					/* _USB_PCI_H_ */

Modified: trunk/sys/dev/usb/usb_pf.c
===================================================================
--- trunk/sys/dev/usb/usb_pf.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_pf.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,3 +1,5 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_pf.c 287272 2015-08-29 06:11:50Z hselasky $ */
 /*-
  * Copyright (c) 1990, 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -32,8 +34,9 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: stable/9/sys/dev/usb/usb_pf.c 287273 2015-08-29 06:17:39Z hselasky $");
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/bus.h>
@@ -44,8 +47,10 @@
 #include <sys/sockio.h>
 #include <net/if.h>
 #include <net/if_types.h>
+#include <net/if_clone.h>
 #include <net/bpf.h>
 #include <sys/sysctl.h>
+#include <net/route.h>
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -57,36 +62,146 @@
 #include <dev/usb/usb_bus.h>
 #include <dev/usb/usb_pf.h>
 #include <dev/usb/usb_transfer.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
-static int usb_no_pf;
+static void usbpf_init(void *);
+static void usbpf_uninit(void *);
+static int usbpf_ioctl(struct ifnet *, u_long, caddr_t);
+static int usbpf_clone_match(struct if_clone *, const char *);
+static int usbpf_clone_create(struct if_clone *, char *, size_t, caddr_t);
+static int usbpf_clone_destroy(struct if_clone *, struct ifnet *);
+static struct usb_bus *usbpf_ifname2ubus(const char *);
+static uint32_t usbpf_aggregate_xferflags(struct usb_xfer_flags *);
+static uint32_t usbpf_aggregate_status(struct usb_xfer_flags_int *);
+static int usbpf_xfer_frame_is_read(struct usb_xfer *, uint32_t);
+static uint32_t usbpf_xfer_precompute_size(struct usb_xfer *, int);
 
-SYSCTL_INT(_hw_usb, OID_AUTO, no_pf, CTLFLAG_RW,
-    &usb_no_pf, 0, "Set to disable USB packet filtering");
+static struct if_clone *usbpf_cloner;
+static const char usbusname[] = "usbus";
 
-TUNABLE_INT("hw.usb.no_pf", &usb_no_pf);
+SYSINIT(usbpf_init, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, usbpf_init, NULL);
+SYSUNINIT(usbpf_uninit, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, usbpf_uninit, NULL);
 
-void
-usbpf_attach(struct usb_bus *ubus)
+static void
+usbpf_init(void *arg)
 {
-	struct ifnet *ifp;
 
-	if (usb_no_pf != 0) {
-		ubus->ifp = NULL;
+	usbpf_cloner = if_clone_advanced(usbusname, 0, usbpf_clone_match,
+	    usbpf_clone_create, usbpf_clone_destroy);
+}
+
+static void
+usbpf_uninit(void *arg)
+{
+	int devlcnt;
+	device_t *devlp;
+	devclass_t dc;
+	struct usb_bus *ubus;
+	int error;
+	int i;
+	
+	if_clone_detach(usbpf_cloner);
+
+	dc = devclass_find(usbusname);
+	if (dc == NULL)
 		return;
+	error = devclass_get_devices(dc, &devlp, &devlcnt);
+	if (error)
+		return;
+	for (i = 0; i < devlcnt; i++) {
+		ubus = device_get_softc(devlp[i]);
+		if (ubus != NULL && ubus->ifp != NULL)
+			usbpf_clone_destroy(usbpf_cloner, ubus->ifp);
 	}
+	free(devlp, M_TEMP);
+}
 
+static int
+usbpf_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+{
+	
+	/* No configuration allowed. */
+	return (EINVAL);
+}
+
+static struct usb_bus *
+usbpf_ifname2ubus(const char *ifname)
+{
+	device_t dev;
+	devclass_t dc;
+	int unit;
+	int error;
+
+	if (strncmp(ifname, usbusname, sizeof(usbusname) - 1) != 0)
+		return (NULL);
+	error = ifc_name2unit(ifname, &unit);
+	if (error || unit < 0)
+		return (NULL);
+	dc = devclass_find(usbusname);
+	if (dc == NULL)
+		return (NULL);
+	dev = devclass_get_device(dc, unit);
+	if (dev == NULL)
+		return (NULL);
+
+	return (device_get_softc(dev));
+}
+
+static int
+usbpf_clone_match(struct if_clone *ifc, const char *name)
+{
+	struct usb_bus *ubus;
+
+	ubus = usbpf_ifname2ubus(name);
+	if (ubus == NULL)
+		return (0);
+	if (ubus->ifp != NULL)
+		return (0);
+
+	return (1);
+}
+
+static int
+usbpf_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
+{
+	int error;
+	int unit;
+	struct ifnet *ifp;
+	struct usb_bus *ubus;
+
+	error = ifc_name2unit(name, &unit);
+	if (error)
+		return (error);
+ 	if (unit < 0)
+		return (EINVAL);
+
+	ubus = usbpf_ifname2ubus(name);
+	if (ubus == NULL)
+		return (1);
+	if (ubus->ifp != NULL)
+		return (1);
+
+	error = ifc_alloc_unit(ifc, &unit);
+	if (error) {
+		device_printf(ubus->parent, "usbpf: Could not allocate "
+		    "instance\n");
+		return (error);
+	}
 	ifp = ubus->ifp = if_alloc(IFT_USB);
 	if (ifp == NULL) {
+		ifc_free_unit(ifc, unit);
 		device_printf(ubus->parent, "usbpf: Could not allocate "
 		    "instance\n");
-		return;
+		return (ENOSPC);
 	}
-
-	if_initname(ifp, "usbus", device_get_unit(ubus->bdev));
-	ifp->if_flags = IFF_CANTCONFIG;
+	strlcpy(ifp->if_xname, name, sizeof(ifp->if_xname));
+	ifp->if_softc = ubus;
+	ifp->if_dname = usbusname;
+	ifp->if_dunit = unit;
+	ifp->if_ioctl = usbpf_ioctl;
 	if_attach(ifp);
-	if_up(ifp);
-
+	ifp->if_flags |= IFF_UP;
+	rt_ifmsg(ifp);
 	/*
 	 * XXX According to the specification of DLT_USB, it indicates
 	 * packets beginning with USB setup header. But not sure all
@@ -94,27 +209,51 @@
 	 */
 	bpfattach(ifp, DLT_USB, USBPF_HDR_LEN);
 
-	if (bootverbose)
-		device_printf(ubus->parent, "usbpf: Attached\n");
+	return (0);
 }
 
-void
-usbpf_detach(struct usb_bus *ubus)
+static int
+usbpf_clone_destroy(struct if_clone *ifc, struct ifnet *ifp)
 {
-	struct ifnet *ifp = ubus->ifp;
+	struct usb_bus *ubus;
+	int unit;
 
+	ubus = ifp->if_softc;
+	unit = ifp->if_dunit;
+
+	/*
+	 * Lock USB before clearing the "ifp" pointer, to avoid
+	 * clearing the pointer in the middle of a TAP operation:
+	 */
 	USB_BUS_LOCK(ubus);
 	ubus->ifp = NULL;
 	USB_BUS_UNLOCK(ubus);
+	bpfdetach(ifp);
+	if_detach(ifp);
+	if_free(ifp);
+	ifc_free_unit(ifc, unit);
+	
+	return (0);
+}
 
-	if (ifp != NULL) {
-		bpfdetach(ifp);
-		if_down(ifp);
-		if_detach(ifp);
-		if_free(ifp);
-	}
+void
+usbpf_attach(struct usb_bus *ubus)
+{
+
+	if (bootverbose)
+		device_printf(ubus->parent, "usbpf: Attached\n");
 }
 
+void
+usbpf_detach(struct usb_bus *ubus)
+{
+
+	if (ubus->ifp != NULL)
+		usbpf_clone_destroy(usbpf_cloner, ubus->ifp);
+	if (bootverbose)
+		device_printf(ubus->parent, "usbpf: Detached\n");
+}
+
 static uint32_t
 usbpf_aggregate_xferflags(struct usb_xfer_flags *flags)
 {
@@ -262,8 +401,6 @@
 	bus = xfer->xroot->bus;
 
 	/* sanity checks */
-	if (usb_no_pf != 0)
-		return;
 	if (bus->ifp == NULL || bus->ifp->if_bpf == NULL)
 		return;
 	if (!bpf_peers_present(bus->ifp->if_bpf))

Modified: trunk/sys/dev/usb/usb_pf.h
===================================================================
--- trunk/sys/dev/usb/usb_pf.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_pf.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990, 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -31,7 +32,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: stable/9/sys/dev/usb/usb_pf.h 220301 2011-04-03 20:03:45Z hselasky $
+ * $FreeBSD: stable/10/sys/dev/usb/usb_pf.h 220301 2011-04-03 20:03:45Z hselasky $
  */
 
 #ifndef _DEV_USB_PF_H

Modified: trunk/sys/dev/usb/usb_process.c
===================================================================
--- trunk/sys/dev/usb/usb_process.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_process.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_process.c 273889 2014-10-31 08:06:21Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_process.c 311799 2017-01-09 17:13:35Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -55,6 +59,7 @@
 #include <sys/proc.h>
 #include <sys/kthread.h>
 #include <sys/sched.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 #if (__FreeBSD_version < 700000)
 #define	thread_lock(td) mtx_lock_spin(&sched_lock)
@@ -67,13 +72,17 @@
 #define	USB_THREAD_CREATE(f, s, p, ...) \
 		kproc_kthread_add((f), (s), &usbproc, (p), RFHIGHPID, \
 		    0, "usb", __VA_ARGS__)
+#if (__FreeBSD_version >= 900000)
 #define	USB_THREAD_SUSPEND_CHECK() kthread_suspend_check()
+#else
+#define	USB_THREAD_SUSPEND_CHECK() kthread_suspend_check(curthread)
+#endif
 #define	USB_THREAD_SUSPEND(p)   kthread_suspend(p,0)
 #define	USB_THREAD_EXIT(err)	kthread_exit()
 #else
 #define	USB_THREAD_CREATE(f, s, p, ...) \
 		kthread_create((f), (s), (p), RFHIGHPID, 0, __VA_ARGS__)
-#define	USB_THREAD_SUSPEND_CHECK() kthread_suspend_check()
+#define	USB_THREAD_SUSPEND_CHECK() kthread_suspend_check(curproc)
 #define	USB_THREAD_SUSPEND(p)   kthread_suspend(p,0)
 #define	USB_THREAD_EXIT(err)	kthread_exit(err)
 #endif
@@ -447,8 +456,8 @@
 			up->up_csleep = 0;
 			cv_signal(&up->up_cv);
 		}
+#ifndef EARLY_AP_STARTUP
 		/* Check if we are still cold booted */
-
 		if (cold) {
 			USB_THREAD_SUSPEND(up->up_ptr);
 			printf("WARNING: A USB process has "
@@ -455,6 +464,7 @@
 			    "been left suspended\n");
 			break;
 		}
+#endif
 		cv_wait(&up->up_cv, up->up_mtx);
 	}
 	/* Check if someone is waiting - should not happen */

Modified: trunk/sys/dev/usb/usb_process.h
===================================================================
--- trunk/sys/dev/usb/usb_process.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_process.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_process.h 263800 2014-03-27 07:03:50Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_process.h 287274 2015-08-29 06:23:40Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -27,11 +28,14 @@
 #ifndef _USB_PROCESS_H_
 #define	_USB_PROCESS_H_
 
+#ifndef USB_GLOBAL_INCLUDE_FILE
 #include <sys/interrupt.h>
 #include <sys/priority.h>
 #include <sys/runq.h>
+#endif
 
 /* defines */
+#define	USB_PRI_HIGHEST	PI_SWI(SWI_TTY)
 #define	USB_PRI_HIGH	PI_SWI(SWI_NET)
 #define	USB_PRI_MED	PI_SWI(SWI_CAMBIO)
 

Modified: trunk/sys/dev/usb/usb_request.c
===================================================================
--- trunk/sys/dev/usb/usb_request.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_request.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_request.c 305735 2016-09-12 10:20:44Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_request.c 305734 2016-09-12 10:17:25Z hselasky $ */
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
@@ -26,6 +27,9 @@
  * SUCH DAMAGE.
  */ 
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -65,6 +69,7 @@
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
 #include <sys/ctype.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 static int usb_no_cs_fail;
 
@@ -224,6 +229,7 @@
 	struct usb_endpoint *ep;
 	struct usb_endpoint *ep_end;
 	struct usb_endpoint *ep_first;
+	usb_stream_t x;
 	uint8_t to;
 
 	udev = xfer->xroot->udev;
@@ -251,9 +257,11 @@
 			ep->is_stalled = 0;
 			/* some hardware needs a callback to clear the data toggle */
 			usbd_clear_stall_locked(udev, ep);
-			/* start up the current or next transfer, if any */
-			usb_command_wrapper(&ep->endpoint_q,
-			    ep->endpoint_q.curr);
+			for (x = 0; x != USB_MAX_EP_STREAMS; x++) {
+				/* start the current or next transfer, if any */
+				usb_command_wrapper(&ep->endpoint_q[x],
+				    ep->endpoint_q[x].curr);
+			}
 		}
 		ep++;
 
@@ -1254,10 +1262,49 @@
 }
 
 /*------------------------------------------------------------------------*
+ *	usbd_alloc_config_desc
+ *
+ * This function is used to allocate a zeroed configuration
+ * descriptor.
+ *
+ * Returns:
+ * NULL: Failure
+ * Else: Success
+ *------------------------------------------------------------------------*/
+void *
+usbd_alloc_config_desc(struct usb_device *udev, uint32_t size)
+{
+	if (size > USB_CONFIG_MAX) {
+		DPRINTF("Configuration descriptor too big\n");
+		return (NULL);
+	}
+#if (USB_HAVE_FIXED_CONFIG == 0)
+	return (malloc(size, M_USBDEV, M_ZERO | M_WAITOK));
+#else
+	memset(udev->config_data, 0, sizeof(udev->config_data));
+	return (udev->config_data);
+#endif
+}
+
+/*------------------------------------------------------------------------*
+ *	usbd_alloc_config_desc
+ *
+ * This function is used to free a configuration descriptor.
+ *------------------------------------------------------------------------*/
+void
+usbd_free_config_desc(struct usb_device *udev, void *ptr)
+{
+#if (USB_HAVE_FIXED_CONFIG == 0)
+	free(ptr, M_USBDEV);
+#endif
+}
+
+/*------------------------------------------------------------------------*
  *	usbd_req_get_config_desc_full
  *
  * This function gets the complete USB configuration descriptor and
- * ensures that "wTotalLength" is correct.
+ * ensures that "wTotalLength" is correct. The returned configuration
+ * descriptor is freed by calling "usbd_free_config_desc()".
  *
  * Returns:
  *    0: Success
@@ -1265,12 +1312,11 @@
  *------------------------------------------------------------------------*/
 usb_error_t
 usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx,
-    struct usb_config_descriptor **ppcd, struct malloc_type *mtype,
-    uint8_t index)
+    struct usb_config_descriptor **ppcd, uint8_t index)
 {
 	struct usb_config_descriptor cd;
 	struct usb_config_descriptor *cdesc;
-	uint16_t len;
+	uint32_t len;
 	usb_error_t err;
 
 	DPRINTFN(4, "index=%d\n", index);
@@ -1278,23 +1324,25 @@
 	*ppcd = NULL;
 
 	err = usbd_req_get_config_desc(udev, mtx, &cd, index);
-	if (err) {
+	if (err)
 		return (err);
-	}
+
 	/* get full descriptor */
 	len = UGETW(cd.wTotalLength);
-	if (len < sizeof(*cdesc)) {
+	if (len < (uint32_t)sizeof(*cdesc)) {
 		/* corrupt descriptor */
 		return (USB_ERR_INVAL);
+	} else if (len > USB_CONFIG_MAX) {
+		DPRINTF("Configuration descriptor was truncated\n");
+		len = USB_CONFIG_MAX;
 	}
-	cdesc = malloc(len, mtype, M_WAITOK);
-	if (cdesc == NULL) {
+	cdesc = usbd_alloc_config_desc(udev, len);
+	if (cdesc == NULL)
 		return (USB_ERR_NOMEM);
-	}
 	err = usbd_req_get_desc(udev, mtx, NULL, cdesc, len, len, 0,
 	    UDESC_CONFIG, index, 3);
 	if (err) {
-		free(cdesc, mtype);
+		usbd_free_config_desc(udev, cdesc);
 		return (err);
 	}
 	/* make sure that the device is not fooling us: */
@@ -1904,9 +1952,9 @@
 		break;
 
 	default:
-		DPRINTF("Minimum MaxPacketSize is large enough "
+		DPRINTF("Minimum bMaxPacketSize is large enough "
 		    "to hold the complete device descriptor or "
-		    "only once MaxPacketSize choice\n");
+		    "only one bMaxPacketSize choice\n");
 
 		/* get the full device descriptor */
 		err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc);

Modified: trunk/sys/dev/usb/usb_request.h
===================================================================
--- trunk/sys/dev/usb/usb_request.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_request.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_request.h 236898 2012-06-11 17:27:53Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_request.h 250207 2013-05-03 11:10:04Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -44,7 +45,7 @@
 		    struct usb_config_descriptor *d, uint8_t conf_index);
 usb_error_t usbd_req_get_config_desc_full(struct usb_device *udev,
 		    struct mtx *mtx, struct usb_config_descriptor **ppcd,
-		    struct malloc_type *mtype, uint8_t conf_index);
+		    uint8_t conf_index);
 usb_error_t usbd_req_get_desc(struct usb_device *udev, struct mtx *mtx,
 		    uint16_t *actlen, void *desc, uint16_t min_len,
 		    uint16_t max_len, uint16_t id, uint8_t type,
@@ -94,4 +95,7 @@
 usb_error_t usbd_req_set_lpm_info(struct usb_device *udev, struct mtx *mtx,
 		    uint8_t port, uint8_t besl, uint8_t addr, uint8_t rwe);
 
+void *	usbd_alloc_config_desc(struct usb_device *, uint32_t);
+void	usbd_free_config_desc(struct usb_device *, void *);
+
 #endif					/* _USB_REQUEST_H_ */

Modified: trunk/sys/dev/usb/usb_transfer.c
===================================================================
--- trunk/sys/dev/usb/usb_transfer.c	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_transfer.c	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_transfer.c 305735 2016-09-12 10:20:44Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_transfer.c 305734 2016-09-12 10:17:25Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -24,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifdef USB_GLOBAL_INCLUDE_FILE
+#include USB_GLOBAL_INCLUDE_FILE
+#else
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -61,6 +65,7 @@
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
 #include <dev/usb/usb_pf.h>
+#endif			/* USB_GLOBAL_INCLUDE_FILE */
 
 struct usb_std_packet_size {
 	struct {
@@ -181,6 +186,10 @@
  * according to "size", "align" and "count" arguments. "ppc" is
  * pointed to a linear array of USB page caches afterwards.
  *
+ * If the "align" argument is equal to "1" a non-contiguous allocation
+ * can happen. Else if the "align" argument is greater than "1", the
+ * allocation will always be contiguous in memory.
+ *
  * Returns:
  *    0: Success
  * Else: Failure
@@ -195,6 +204,7 @@
 	struct usb_page *pg;
 	void *buf;
 	usb_size_t n_dma_pc;
+	usb_size_t n_dma_pg;
 	usb_size_t n_obj;
 	usb_size_t x;
 	usb_size_t y;
@@ -201,7 +211,7 @@
 	usb_size_t r;
 	usb_size_t z;
 
-	USB_ASSERT(align > 1, ("Invalid alignment, 0x%08x\n",
+	USB_ASSERT(align > 0, ("Invalid alignment, 0x%08x\n",
 	    align));
 	USB_ASSERT(size > 0, ("Invalid size = 0\n"));
 
@@ -217,24 +227,43 @@
 	 * Try multi-allocation chunks to reduce the number of DMA
 	 * allocations, hence DMA allocations are slow.
 	 */
-	if (size >= USB_PAGE_SIZE) {
+	if (align == 1) {
+		/* special case - non-cached multi page DMA memory */
 		n_dma_pc = count;
+		n_dma_pg = (2 + (size / USB_PAGE_SIZE));
 		n_obj = 1;
+	} else if (size >= USB_PAGE_SIZE) {
+		n_dma_pc = count;
+		n_dma_pg = 1;
+		n_obj = 1;
 	} else {
 		/* compute number of objects per page */
+#ifdef USB_DMA_SINGLE_ALLOC
+		n_obj = 1;
+#else
 		n_obj = (USB_PAGE_SIZE / size);
+#endif
 		/*
 		 * Compute number of DMA chunks, rounded up
 		 * to nearest one:
 		 */
 		n_dma_pc = ((count + n_obj - 1) / n_obj);
+		n_dma_pg = 1;
 	}
 
+	/*
+	 * DMA memory is allocated once, but mapped twice. That's why
+	 * there is one list for auto-free and another list for
+	 * non-auto-free which only holds the mapping and not the
+	 * allocation.
+	 */
 	if (parm->buf == NULL) {
-		/* for the future */
-		parm->dma_page_ptr += n_dma_pc;
+		/* reserve memory (auto-free) */
+		parm->dma_page_ptr += n_dma_pc * n_dma_pg;
 		parm->dma_page_cache_ptr += n_dma_pc;
-		parm->dma_page_ptr += count;
+
+		/* reserve memory (no-auto-free) */
+		parm->dma_page_ptr += count * n_dma_pg;
 		parm->xfer_page_cache_ptr += count;
 		return (0);
 	}
@@ -249,8 +278,11 @@
 		    &parm->curr_xfer->xroot->dma_parent_tag;
 	}
 
-	if (ppc) {
-		*ppc = parm->xfer_page_cache_ptr;
+	if (ppc != NULL) {
+		if (n_obj != 1)
+			*ppc = parm->xfer_page_cache_ptr;
+		else
+			*ppc = parm->dma_page_cache_ptr;
 	}
 	r = count;			/* set remainder count */
 	z = n_obj * size;		/* set allocation size */
@@ -257,7 +289,22 @@
 	pc = parm->xfer_page_cache_ptr;
 	pg = parm->dma_page_ptr;
 
-	for (x = 0; x != n_dma_pc; x++) {
+	if (n_obj == 1) {
+	    /*
+	     * Avoid mapping memory twice if only a single object
+	     * should be allocated per page cache:
+	     */
+	    for (x = 0; x != n_dma_pc; x++) {
+		if (usb_pc_alloc_mem(parm->dma_page_cache_ptr,
+		    pg, z, align)) {
+			return (1);	/* failure */
+		}
+		/* Make room for one DMA page cache and "n_dma_pg" pages */
+		parm->dma_page_cache_ptr++;
+		pg += n_dma_pg;
+	    }
+	} else {
+	    for (x = 0; x != n_dma_pc; x++) {
 
 		if (r < n_obj) {
 			/* compute last remainder */
@@ -270,11 +317,11 @@
 		}
 		/* Set beginning of current buffer */
 		buf = parm->dma_page_cache_ptr->buffer;
-		/* Make room for one DMA page cache and one page */
+		/* Make room for one DMA page cache and "n_dma_pg" pages */
 		parm->dma_page_cache_ptr++;
-		pg++;
+		pg += n_dma_pg;
 
-		for (y = 0; (y != n_obj); y++, r--, pc++, pg++) {
+		for (y = 0; (y != n_obj); y++, r--, pc++, pg += n_dma_pg) {
 
 			/* Load sub-chunk into DMA */
 			if (usb_pc_dmamap_create(pc, size)) {
@@ -290,6 +337,7 @@
 			}
 			mtx_unlock(pc->tag_parent->mtx);
 		}
+	    }
 	}
 
 	parm->xfer_page_cache_ptr = pc;
@@ -359,7 +407,8 @@
 		switch (type) {
 		case UE_ISOCHRONOUS:
 		case UE_INTERRUPT:
-			xfer->max_packet_count += (xfer->max_packet_size >> 11) & 3;
+			xfer->max_packet_count +=
+			    (xfer->max_packet_size >> 11) & 3;
 
 			/* check for invalid max packet count */
 			if (xfer->max_packet_count > 3)
@@ -388,7 +437,8 @@
 			if (ecomp != NULL) {
 				uint8_t mult;
 
-				mult = (ecomp->bmAttributes & 3) + 1;
+				mult = UE_GET_SS_ISO_MULT(
+				    ecomp->bmAttributes) + 1;
 				if (mult > 3)
 					mult = 3;
 
@@ -699,12 +749,30 @@
 	 */
 
 	if (!xfer->flags.ext_buffer) {
+#if USB_HAVE_BUSDMA
+		struct usb_page_search page_info;
+		struct usb_page_cache *pc;
 
+		if (usbd_transfer_setup_sub_malloc(parm,
+		    &pc, parm->bufsize, 1, 1)) {
+			parm->err = USB_ERR_NOMEM;
+		} else if (parm->buf != NULL) {
+
+			usbd_get_page(pc, 0, &page_info);
+
+			xfer->local_buffer = page_info.buffer;
+
+			usbd_xfer_set_frame_offset(xfer, 0, 0);
+
+			if ((type == UE_CONTROL) && (n_frbuffers > 1)) {
+				usbd_xfer_set_frame_offset(xfer, REQ_SIZE, 1);
+			}
+		}
+#else
 		/* align data */
 		parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
 
-		if (parm->buf) {
-
+		if (parm->buf != NULL) {
 			xfer->local_buffer =
 			    USB_ADD_BYTES(parm->buf, parm->size[0]);
 
@@ -718,6 +786,7 @@
 
 		/* align data again */
 		parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
+#endif
 	}
 	/*
 	 * Compute maximum buffer size
@@ -804,6 +873,19 @@
 	}
 }
 
+static uint8_t
+usbd_transfer_setup_has_bulk(const struct usb_config *setup_start,
+    uint16_t n_setup)
+{
+	while (n_setup--) {
+		uint8_t type = setup_start[n_setup].type;
+		if (type == UE_BULK || type == UE_BULK_INTR ||
+		    type == UE_TYPE_ANY)
+			return (1);
+	}
+	return (0);
+}
+
 /*------------------------------------------------------------------------*
  *	usbd_transfer_setup - setup an array of USB transfers
  *
@@ -940,14 +1022,17 @@
 			 * deadlock!
 			 */
 			if (setup_start == usb_control_ep_cfg)
-				info->done_p = 
-				    &udev->bus->control_xfer_proc;
+				info->done_p =
+				    USB_BUS_CONTROL_XFER_PROC(udev->bus);
 			else if (xfer_mtx == &Giant)
-				info->done_p = 
-				    &udev->bus->giant_callback_proc;
+				info->done_p =
+				    USB_BUS_GIANT_PROC(udev->bus);
+			else if (usbd_transfer_setup_has_bulk(setup_start, n_setup))
+				info->done_p =
+				    USB_BUS_NON_GIANT_BULK_PROC(udev->bus);
 			else
-				info->done_p = 
-				    &udev->bus->non_giant_callback_proc;
+				info->done_p =
+				    USB_BUS_NON_GIANT_ISOC_PROC(udev->bus);
 		}
 		/* reset sizes */
 
@@ -966,7 +1051,20 @@
 			ep = usbd_get_endpoint(udev,
 			    ifaces[setup->if_index], setup);
 
-			if ((ep == NULL) || (ep->methods == NULL)) {
+			/*
+			 * Check that the USB PIPE is valid and that
+			 * the endpoint mode is proper.
+			 *
+			 * Make sure we don't allocate a streams
+			 * transfer when such a combination is not
+			 * valid.
+			 */
+			if ((ep == NULL) || (ep->methods == NULL) ||
+			    ((ep->ep_mode != USB_EP_MODE_STREAMS) &&
+			    (ep->ep_mode != USB_EP_MODE_DEFAULT)) ||
+			    (setup->stream_id != 0 &&
+			    (setup->stream_id >= USB_MAX_EP_STREAMS ||
+			    (ep->ep_mode != USB_EP_MODE_STREAMS)))) {
 				if (setup->flags.no_pipe_ok)
 					continue;
 				if ((setup->usb_mode != USB_MODE_DUAL) &&
@@ -1010,6 +1108,9 @@
 			/* set transfer endpoint pointer */
 			xfer->endpoint = ep;
 
+			/* set transfer stream ID */
+			xfer->stream_id = setup->stream_id;
+
 			parm->size[0] += sizeof(xfer[0]);
 			parm->methods = xfer->endpoint->methods;
 			parm->curr_xfer = xfer;
@@ -1080,9 +1181,12 @@
 		 * The number of DMA tags required depends on
 		 * the number of endpoints. The current estimate
 		 * for maximum number of DMA tags per endpoint
-		 * is two.
+		 * is three:
+		 * 1) for loading memory
+		 * 2) for allocating memory
+		 * 3) for fixing memory [UHCI]
 		 */
-		parm->dma_tag_max += 2 * MIN(n_setup, USB_EP_MAX);
+		parm->dma_tag_max += 3 * MIN(n_setup, USB_EP_MAX);
 
 		/*
 		 * DMA tags for QH, TD, Data and more.
@@ -1630,7 +1734,8 @@
 			USB_BUS_LOCK(bus);
 			xfer->flags_int.can_cancel_immed = 1;
 			/* start the transfer */
-			usb_command_wrapper(&xfer->endpoint->endpoint_q, xfer);
+			usb_command_wrapper(&xfer->endpoint->
+			    endpoint_q[xfer->stream_id], xfer);
 			USB_BUS_UNLOCK(bus);
 			return;
 		}
@@ -1751,7 +1856,7 @@
 	}
 
 	/* start the transfer */
-	usb_command_wrapper(&ep->endpoint_q, xfer);
+	usb_command_wrapper(&ep->endpoint_q[xfer->stream_id], xfer);
 	USB_BUS_UNLOCK(xfer->xroot->bus);
 }
 
@@ -1872,8 +1977,9 @@
 		 * If the current USB transfer is completing we need
 		 * to start the next one:
 		 */
-		if (ep->endpoint_q.curr == xfer) {
-			usb_command_wrapper(&ep->endpoint_q, NULL);
+		if (ep->endpoint_q[xfer->stream_id].curr == xfer) {
+			usb_command_wrapper(
+			    &ep->endpoint_q[xfer->stream_id], NULL);
 		}
 	}
 
@@ -2191,10 +2297,8 @@
 	         * will have a Lock Order Reversal, LOR, if we try to
 	         * proceed !
 	         */
-		if (usb_proc_msignal(info->done_p,
-		    &info->done_m[0], &info->done_m[1])) {
-			/* ignore */
-		}
+		(void) usb_proc_msignal(info->done_p,
+		    &info->done_m[0], &info->done_m[1]);
 	} else {
 		/* clear second recurse flag */
 		pq->recurse_2 = 0;
@@ -2218,23 +2322,26 @@
 	struct usb_xfer_root *info = xfer->xroot;
 
 	USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
-	if (!mtx_owned(info->xfer_mtx) && !SCHEDULER_STOPPED()) {
+	if ((pq->recurse_3 != 0 || mtx_owned(info->xfer_mtx) == 0) &&
+	    SCHEDULER_STOPPED() == 0) {
 		/*
 	       	 * Cases that end up here:
 		 *
 		 * 5) HW interrupt done callback or other source.
+		 * 6) HW completed transfer during callback
 		 */
-		DPRINTFN(3, "case 5\n");
+		DPRINTFN(3, "case 5 and 6\n");
 
 		/*
 	         * We have to postpone the callback due to the fact we
 	         * will have a Lock Order Reversal, LOR, if we try to
-	         * proceed !
+	         * proceed!
+		 *
+		 * Postponing the callback also ensures that other USB
+		 * transfer queues get a chance.
 	         */
-		if (usb_proc_msignal(info->done_p,
-		    &info->done_m[0], &info->done_m[1])) {
-			/* ignore */
-		}
+		(void) usb_proc_msignal(info->done_p,
+		    &info->done_m[0], &info->done_m[1]);
 		return;
 	}
 	/*
@@ -2604,11 +2711,11 @@
 
 			if (udev->flags.usb_mode == USB_MODE_DEVICE) {
 				(udev->bus->methods->set_stall) (
-				    udev, NULL, ep, &did_stall);
+				    udev, ep, &did_stall);
 			} else if (udev->ctrl_xfer[1]) {
 				info = udev->ctrl_xfer[1]->xroot;
 				usb_proc_msignal(
-				    &info->bus->non_giant_callback_proc,
+				    USB_BUS_CS_PROC(info->bus),
 				    &udev->cs_msg[0], &udev->cs_msg[1]);
 			} else {
 				/* should not happen */
@@ -2887,10 +2994,11 @@
 	 * next one:
 	 */
 	USB_BUS_LOCK(bus);
-	if (ep->endpoint_q.curr == xfer) {
-		usb_command_wrapper(&ep->endpoint_q, NULL);
+	if (ep->endpoint_q[xfer->stream_id].curr == xfer) {
+		usb_command_wrapper(&ep->endpoint_q[xfer->stream_id], NULL);
 
-		if (ep->endpoint_q.curr || TAILQ_FIRST(&ep->endpoint_q.head)) {
+		if (ep->endpoint_q[xfer->stream_id].curr != NULL ||
+		    TAILQ_FIRST(&ep->endpoint_q[xfer->stream_id].head) != NULL) {
 			/* there is another USB transfer waiting */
 		} else {
 			/* this is the last USB transfer */
@@ -2932,9 +3040,11 @@
 
 	if (!pq->recurse_1) {
 
+		/* clear third recurse flag */
+		pq->recurse_3 = 0;
+
 		do {
-
-			/* set both recurse flags */
+			/* set two first recurse flags */
 			pq->recurse_1 = 1;
 			pq->recurse_2 = 1;
 
@@ -2953,6 +3063,12 @@
 			(pq->command) (pq);
 			DPRINTFN(6, "cb %p (leave)\n", pq->curr);
 
+			/*
+			 * Set third recurse flag to indicate
+			 * recursion happened:
+			 */
+			pq->recurse_3 = 1;
+
 		} while (!pq->recurse_2);
 
 		/* clear first recurse flag */
@@ -3225,10 +3341,11 @@
 		}
 
 		/* Make sure cv_signal() and cv_broadcast() is not called */
-		udev->bus->control_xfer_proc.up_msleep = 0;
-		udev->bus->explore_proc.up_msleep = 0;
-		udev->bus->giant_callback_proc.up_msleep = 0;
-		udev->bus->non_giant_callback_proc.up_msleep = 0;
+		USB_BUS_CONTROL_XFER_PROC(udev->bus)->up_msleep = 0;
+		USB_BUS_EXPLORE_PROC(udev->bus)->up_msleep = 0;
+		USB_BUS_GIANT_PROC(udev->bus)->up_msleep = 0;
+		USB_BUS_NON_GIANT_ISOC_PROC(udev->bus)->up_msleep = 0;
+		USB_BUS_NON_GIANT_BULK_PROC(udev->bus)->up_msleep = 0;
 
 		/* poll USB hardware */
 		(udev->bus->methods->xfer_poll) (udev->bus);

Modified: trunk/sys/dev/usb/usb_transfer.h
===================================================================
--- trunk/sys/dev/usb/usb_transfer.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_transfer.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_transfer.h 213435 2010-10-04 23:18:05Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_transfer.h 228056 2011-11-28 09:54:41Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -28,6 +29,120 @@
 #define	_USB_TRANSFER_H_
 
 /*
+ * Definition of internal USB transfer states:
+ * ===========================================
+ *
+ * The main reason there are many USB states is that we are allowed to
+ * cancel USB transfers, then start the USB transfer again and that
+ * this state transaction cannot always be done in a single atomic
+ * operation without blocking the calling thread. One reason for this
+ * is that the USB hardware sometimes needs to wait for DMA
+ * controllers to finish which is done asynchronously and grows the
+ * statemachine.
+ *
+ * When extending the following statemachine there are basically two
+ * things you should think about: Which states should be executed or
+ * modified in case of USB transfer stop and which states should be
+ * executed or modified in case of USB transfer start. Also respect
+ * the "can_cancel_immed" flag which basically tells if you can go
+ * directly from a wait state to the cancelling states.
+ */
+
+enum {
+	/* XFER start execute state */
+
+	/* USB_ST_SETUP = 0 (already defined) */
+
+	/* XFER transferred execute state */
+
+	/* USB_ST_TRANSFERRED = 1 (already defined) */
+
+	/* XFER error execute state */
+
+	/* USB_ST_ERROR = 2 (already defined) */
+
+	/* XFER restart after error execute state */
+
+	USB_ST_RESTART = 8,
+
+	/* XFER transfer idle state */
+
+	USB_ST_WAIT_SETUP,
+
+	/* Other XFER execute states */
+
+	USB_ST_PIPE_OPEN = 16,
+	USB_ST_PIPE_OPEN_ERROR,
+	USB_ST_PIPE_OPEN_RESTART,
+
+	USB_ST_BDMA_LOAD,
+	USB_ST_BDMA_LOAD_ERROR,
+	USB_ST_BDMA_LOAD_RESTART,
+
+	USB_ST_IVAL_DLY,
+	USB_ST_IVAL_DLY_ERROR,
+	USB_ST_IVAL_DLY_RESTART,
+
+	USB_ST_PIPE_STALL,
+	USB_ST_PIPE_STALL_ERROR,
+	USB_ST_PIPE_STALL_RESTART,
+
+	USB_ST_ENTER,
+	USB_ST_ENTER_ERROR,
+	USB_ST_ENTER_RESTART,
+
+	USB_ST_START,
+	USB_ST_START_ERROR,
+	USB_ST_START_RESTART,
+
+	USB_ST_PIPE_CLOSE,
+	USB_ST_PIPE_CLOSE_ERROR,
+	USB_ST_PIPE_CLOSE_RESTART,
+
+	USB_ST_BDMA_DLY,
+	USB_ST_BDMA_DLY_ERROR,
+	USB_ST_BDMA_DLY_RESTART,
+
+	/* XFER transfer wait states */
+
+	USB_ST_WAIT_PIPE_OPEN = 64,
+	USB_ST_WAIT_PIPE_OPEN_ERROR,
+	USB_ST_WAIT_PIPE_OPEN_RESTART,
+
+	USB_ST_WAIT_BDMA_LOAD,
+	USB_ST_WAIT_BDMA_LOAD_ERROR,
+	USB_ST_WAIT_BDMA_LOAD_RESTART,
+
+	USB_ST_WAIT_IVAL_DLY,
+	USB_ST_WAIT_IVAL_DLY_ERROR,
+	USB_ST_WAIT_IVAL_DLY_RESTART,
+
+	USB_ST_WAIT_PIPE_STALL,
+	USB_ST_WAIT_PIPE_STALL_ERROR,
+	USB_ST_WAIT_PIPE_STALL_RESTART,
+
+	USB_ST_WAIT_ENTER,
+	USB_ST_WAIT_ENTER_ERROR,
+	USB_ST_WAIT_ENTER_RESTART,
+
+	USB_ST_WAIT_START,
+	USB_ST_WAIT_START_ERROR,
+	USB_ST_WAIT_START_RESTART,
+
+	USB_ST_WAIT_PIPE_CLOSE,
+	USB_ST_WAIT_PIPE_CLOSE_ERROR,
+	USB_ST_WAIT_PIPE_CLOSE_RESTART,
+
+	USB_ST_WAIT_BDMA_DLY,
+	USB_ST_WAIT_BDMA_DLY_ERROR,
+	USB_ST_WAIT_BDMA_DLY_RESTART,
+
+	USB_ST_WAIT_TRANSFERRED,
+	USB_ST_WAIT_TRANSFERRED_ERROR,
+	USB_ST_WAIT_TRANSFERRED_RESTART,
+};
+
+/*
  * The following structure defines the messages that is used to signal
  * the "done_p" USB process.
  */

Modified: trunk/sys/dev/usb/usb_util.h
===================================================================
--- trunk/sys/dev/usb/usb_util.h	2018-05-27 22:45:35 UTC (rev 10055)
+++ trunk/sys/dev/usb/usb_util.h	2018-05-27 22:50:50 UTC (rev 10056)
@@ -1,4 +1,5 @@
-/* $FreeBSD: stable/9/sys/dev/usb/usb_util.h 229118 2011-12-31 15:31:34Z hselasky $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/usb/usb_util.h 227701 2011-11-19 10:11:50Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *



More information about the Midnightbsd-cvs mailing list