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

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun May 27 19:37:23 EDT 2018


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

Modified Paths:
--------------
    trunk/sys/dev/jme/if_jme.c
    trunk/sys/dev/jme/if_jmereg.h
    trunk/sys/dev/jme/if_jmevar.h
    trunk/sys/dev/joy/joy.c
    trunk/sys/dev/joy/joy_isa.c
    trunk/sys/dev/joy/joy_pccard.c
    trunk/sys/dev/joy/joyvar.h
    trunk/sys/dev/kbd/kbd.c
    trunk/sys/dev/kbd/kbdreg.h
    trunk/sys/dev/kbd/kbdtables.h
    trunk/sys/dev/le/am7990.c
    trunk/sys/dev/le/am79900.c
    trunk/sys/dev/le/am79900reg.h
    trunk/sys/dev/le/am79900var.h
    trunk/sys/dev/le/am7990reg.h
    trunk/sys/dev/le/am7990var.h
    trunk/sys/dev/le/if_le_cbus.c
    trunk/sys/dev/le/if_le_isa.c
    trunk/sys/dev/le/if_le_lebuffer.c
    trunk/sys/dev/le/if_le_ledma.c
    trunk/sys/dev/le/if_le_pci.c
    trunk/sys/dev/le/lance.c
    trunk/sys/dev/le/lancereg.h
    trunk/sys/dev/le/lancevar.h
    trunk/sys/dev/le/lebuffer_sbus.c
    trunk/sys/dev/lge/if_lge.c
    trunk/sys/dev/lge/if_lgereg.h
    trunk/sys/dev/lmc/if_lmc.c
    trunk/sys/dev/lmc/if_lmc.h
    trunk/sys/dev/malo/if_malo.c
    trunk/sys/dev/malo/if_malo.h
    trunk/sys/dev/malo/if_malo_pci.c
    trunk/sys/dev/malo/if_malohal.c
    trunk/sys/dev/malo/if_malohal.h
    trunk/sys/dev/malo/if_maloioctl.h
    trunk/sys/dev/mca/mca_bus.c
    trunk/sys/dev/mca/mca_busreg.h
    trunk/sys/dev/mca/mca_busvar.h
    trunk/sys/dev/mcd/mcd.c
    trunk/sys/dev/mcd/mcd_isa.c
    trunk/sys/dev/mcd/mcdreg.h
    trunk/sys/dev/mcd/mcdvar.h
    trunk/sys/dev/md/md.c
    trunk/sys/dev/mem/memdev.c
    trunk/sys/dev/mem/memutil.c
    trunk/sys/dev/mfi/mfi.c
    trunk/sys/dev/mfi/mfi_cam.c
    trunk/sys/dev/mfi/mfi_debug.c
    trunk/sys/dev/mfi/mfi_disk.c
    trunk/sys/dev/mfi/mfi_ioctl.h
    trunk/sys/dev/mfi/mfi_linux.c
    trunk/sys/dev/mfi/mfi_pci.c
    trunk/sys/dev/mfi/mfi_syspd.c
    trunk/sys/dev/mfi/mfi_tbolt.c
    trunk/sys/dev/mfi/mfireg.h
    trunk/sys/dev/mfi/mfivar.h
    trunk/sys/dev/mge/if_mge.c
    trunk/sys/dev/mge/if_mgevar.h

Added Paths:
-----------
    trunk/sys/dev/mii/smscphy.c

Modified: trunk/sys/dev/jme/if_jme.c
===================================================================
--- trunk/sys/dev/jme/if_jme.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/jme/if_jme.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008, Pyun YongHyeon <yongari at FreeBSD.org>
  * All rights reserved.
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/jme/if_jme.c 312362 2017-01-18 02:16:17Z yongari $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -803,7 +804,7 @@
 	}
 	/* Create coalescing sysctl node. */
 	jme_sysctl_node(sc);
-	if ((error = jme_dma_alloc(sc) != 0))
+	if ((error = jme_dma_alloc(sc)) != 0)
 		goto fail;
 
 	ifp = sc->jme_ifp = if_alloc(IFT_ETHER);
@@ -1690,7 +1691,7 @@
 	struct mbuf *m;
 	bus_dma_segment_t txsegs[JME_MAXTXSEGS];
 	int error, i, nsegs, prod;
-	uint32_t cflags, tso_segsz;
+	uint32_t cflags, tsosegsz;
 
 	JME_LOCK_ASSERT(sc);
 
@@ -1808,10 +1809,10 @@
 
 	m = *m_head;
 	cflags = 0;
-	tso_segsz = 0;
+	tsosegsz = 0;
 	/* Configure checksum offload and TSO. */
 	if ((m->m_pkthdr.csum_flags & CSUM_TSO) != 0) {
-		tso_segsz = (uint32_t)m->m_pkthdr.tso_segsz <<
+		tsosegsz = (uint32_t)m->m_pkthdr.tso_segsz <<
 		    JME_TD_MSS_SHIFT;
 		cflags |= JME_TD_TSO;
 	} else {
@@ -1830,7 +1831,7 @@
 
 	desc = &sc->jme_rdata.jme_tx_ring[prod];
 	desc->flags = htole32(cflags);
-	desc->buflen = htole32(tso_segsz);
+	desc->buflen = htole32(tsosegsz);
 	desc->addr_hi = htole32(m->m_pkthdr.len);
 	desc->addr_lo = 0;
 	sc->jme_cdata.jme_tx_cnt++;

Modified: trunk/sys/dev/jme/if_jmereg.h
===================================================================
--- trunk/sys/dev/jme/if_jmereg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/jme/if_jmereg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008, Pyun YongHyeon <yongari at FreeBSD.org>
  * All rights reserved.
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/jme/if_jmereg.h 216551 2010-12-18 23:52:50Z yongari $
  */
 
 #ifndef	_IF_JMEREG_H

Modified: trunk/sys/dev/jme/if_jmevar.h
===================================================================
--- trunk/sys/dev/jme/if_jmevar.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/jme/if_jmevar.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008, Pyun YongHyeon <yongari at FreeBSD.org>
  * All rights reserved.
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/jme/if_jmevar.h 264442 2014-04-14 04:51:59Z yongari $
  */
 
 #ifndef	_IF_JMEVAR_H
@@ -49,7 +50,7 @@
 #define	JME_RX_RING_ALIGN	16
 #define	JME_TSO_MAXSEGSIZE	4096
 #define	JME_TSO_MAXSIZE		(65535 + sizeof(struct ether_vlan_header))
-#define	JME_MAXTXSEGS		32
+#define	JME_MAXTXSEGS		35
 #define	JME_RX_BUF_ALIGN	sizeof(uint64_t)
 #define	JME_SSB_ALIGN		16
 

Modified: trunk/sys/dev/joy/joy.c
===================================================================
--- trunk/sys/dev/joy/joy.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/joy/joy.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1995 Jean-Marc Zucconi
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/joy/joy.c 191054 2009-04-14 11:23:09Z ed $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/joy/joy_isa.c
===================================================================
--- trunk/sys/dev/joy/joy_isa.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/joy/joy_isa.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1995 Jean-Marc Zucconi
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/joy/joy_isa.c 119418 2003-08-24 17:55:58Z obrien $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/joy/joy_pccard.c
===================================================================
--- trunk/sys/dev/joy/joy_pccard.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/joy/joy_pccard.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1995 Jean-Marc Zucconi
  * All rights reserved.
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/joy/joy_pccard.c 150396 2005-09-20 19:54:11Z imp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/joy/joyvar.h
===================================================================
--- trunk/sys/dev/joy/joyvar.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/joy/joyvar.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1995 Jean-Marc Zucconi
  * All rights reserved.
@@ -25,7 +26,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.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/joy/joyvar.h 130585 2004-06-16 09:47:26Z phk $
  */
 
 struct joy_softc {

Modified: trunk/sys/dev/kbd/kbd.c
===================================================================
--- trunk/sys/dev/kbd/kbd.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/kbd/kbd.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 Kazutaka YOKOTA <yokota at zodiac.mech.utsunomiya-u.ac.jp>
  * All rights reserved.
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/kbd/kbd.c 312352 2017-01-17 22:02:22Z lifanov $");
 
 #include "opt_kbd.h"
 
@@ -884,11 +885,11 @@
 			omapp->key[i].spcl = mapp->key[i].spcl;
 			omapp->key[i].flgs = mapp->key[i].flgs;
 		}
-		return (0);
+		break;
 	case PIO_KEYMAP:	/* set keyboard translation table */
 	case OPIO_KEYMAP:	/* set keyboard translation table (compat) */
 #ifndef KBD_DISABLE_KEYMAP_LOAD
-		mapp = malloc(sizeof *mapp, M_TEMP, M_NOWAIT);
+		mapp = malloc(sizeof *mapp, M_TEMP, M_WAITOK);
 		if (cmd == OPIO_KEYMAP) {
 			omapp = (okeymap_t *)arg;
 			mapp->n_keys = omapp->n_keys;

Modified: trunk/sys/dev/kbd/kbdreg.h
===================================================================
--- trunk/sys/dev/kbd/kbdreg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/kbd/kbdreg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 Kazutaka YOKOTA <yokota at zodiac.mech.utsunomiya-u.ac.jp>
  * All rights reserved.
@@ -23,7 +24,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.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/kbd/kbdreg.h 190870 2009-04-09 19:11:08Z emax $
  */
 
 #ifndef _DEV_KBD_KBDREG_H_

Modified: trunk/sys/dev/kbd/kbdtables.h
===================================================================
--- trunk/sys/dev/kbd/kbdtables.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/kbd/kbdtables.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992-1998 Sen Schmidt
  * All rights reserved.
@@ -25,7 +26,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.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/kbd/kbdtables.h 146138 2005-05-12 13:39:31Z nyan $
  */
 
 #ifndef KBD_DFLT_KEYMAP

Modified: trunk/sys/dev/le/am7990.c
===================================================================
--- trunk/sys/dev/le/am7990.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/am7990.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: am7990.c,v 1.68 2005/12/11 12:21:25 christos Exp $	*/
 
 /*-
@@ -16,13 +17,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the NetBSD
- *	Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -72,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/am7990.c 263687 2014-03-24 13:48:04Z emaste $");
 
 #include <sys/param.h>
 #include <sys/bus.h>

Modified: trunk/sys/dev/le/am79900.c
===================================================================
--- trunk/sys/dev/le/am79900.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/am79900.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: am79900.c,v 1.17 2005/12/24 20:27:29 perry Exp $	*/
 
 /*-
@@ -15,13 +16,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the NetBSD
- *	Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -110,7 +104,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/am79900.c 263687 2014-03-24 13:48:04Z emaste $");
 
 #include <sys/param.h>
 #include <sys/bus.h>

Modified: trunk/sys/dev/le/am79900reg.h
===================================================================
--- trunk/sys/dev/le/am79900reg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/am79900reg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: am79900reg.h,v 1.8 2005/12/11 12:21:25 christos Exp $	*/
 
 /*-
@@ -15,13 +16,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -70,7 +64,7 @@
  *	@(#)if_lereg.h	8.1 (Berkeley) 6/10/93
  */
 
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/le/am79900reg.h 263687 2014-03-24 13:48:04Z emaste $ */
 
 #ifndef _DEV_LE_AM79900REG_H_
 #define	_DEV_LE_AM79900REG_H_

Modified: trunk/sys/dev/le/am79900var.h
===================================================================
--- trunk/sys/dev/le/am79900var.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/am79900var.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: am79900var.h,v 1.4 2005/12/11 12:21:25 christos Exp $	*/
 
 /*-
@@ -30,7 +31,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/le/am79900var.h 204646 2010-03-03 17:55:51Z joel $ */
 
 #ifndef _DEV_LE_AM79900VAR_H_
 #define	_DEV_LE_AM79900VAR_H_

Modified: trunk/sys/dev/le/am7990reg.h
===================================================================
--- trunk/sys/dev/le/am7990reg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/am7990reg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: am7990reg.h,v 1.11 2005/12/11 12:21:25 christos Exp $	*/
 
 /*-
@@ -15,13 +16,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -70,7 +64,7 @@
  *	@(#)if_lereg.h	8.1 (Berkeley) 6/10/93
  */
 
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/le/am7990reg.h 263687 2014-03-24 13:48:04Z emaste $ */
 
 #ifndef _DEV_LE_AM7990REG_H_
 #define	_DEV_LE_AM7990REG_H_

Modified: trunk/sys/dev/le/am7990var.h
===================================================================
--- trunk/sys/dev/le/am7990var.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/am7990var.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: am7990var.h,v 1.23 2005/12/11 12:21:25 christos Exp $	*/
 
 /*-
@@ -30,7 +31,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/le/am7990var.h 204646 2010-03-03 17:55:51Z joel $ */
 
 #ifndef _DEV_LE_AM7990VAR_H_
 #define	_DEV_LE_AM7990VAR_H_

Modified: trunk/sys/dev/le/if_le_cbus.c
===================================================================
--- trunk/sys/dev/le/if_le_cbus.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/if_le_cbus.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1994-2000
  *	Paul Richards. All rights reserved.
@@ -33,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/if_le_cbus.c 183337 2008-09-24 21:26:46Z marius $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/le/if_le_isa.c
===================================================================
--- trunk/sys/dev/le/if_le_isa.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/if_le_isa.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: if_le_isa.c,v 1.41 2005/12/24 20:27:41 perry Exp $	*/
 
 /*-
@@ -16,13 +17,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the NetBSD
- *	Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -72,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/if_le_isa.c 263687 2014-03-24 13:48:04Z emaste $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/le/if_le_lebuffer.c
===================================================================
--- trunk/sys/dev/le/if_le_lebuffer.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/if_le_lebuffer.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 Marius Strobl <marius at FreeBSD.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/if_le_lebuffer.c 183337 2008-09-24 21:26:46Z marius $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/le/if_le_ledma.c
===================================================================
--- trunk/sys/dev/le/if_le_ledma.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/if_le_ledma.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: if_le_ledma.c,v 1.26 2005/12/11 12:23:44 christos Exp $	*/
 
 /*-
@@ -31,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/if_le_ledma.c 204646 2010-03-03 17:55:51Z joel $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/le/if_le_pci.c
===================================================================
--- trunk/sys/dev/le/if_le_pci.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/if_le_pci.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: if_le_pci.c,v 1.43 2005/12/11 12:22:49 christos Exp $	*/
 
 /*-
@@ -16,13 +17,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the NetBSD
- *	Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -72,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/if_le_pci.c 263687 2014-03-24 13:48:04Z emaste $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/le/lance.c
===================================================================
--- trunk/sys/dev/le/lance.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/lance.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: lance.c,v 1.34 2005/12/24 20:27:30 perry Exp $	*/
 
 /*-
@@ -16,13 +17,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the NetBSD
- *	Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -72,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/lance.c 263687 2014-03-24 13:48:04Z emaste $");
 
 #include <sys/param.h>
 #include <sys/bus.h>

Modified: trunk/sys/dev/le/lancereg.h
===================================================================
--- trunk/sys/dev/le/lancereg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/lancereg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: lancereg.h,v 1.12 2005/12/11 12:21:27 christos Exp $	*/
 
 /*-
@@ -15,13 +16,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -120,7 +114,7 @@
  * valid on the LANCE.
  */
 
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/le/lancereg.h 263687 2014-03-24 13:48:04Z emaste $ */
 
 #ifndef _DEV_LE_LANCEREG_H_
 #define	_DEV_LE_LANCEREG_H_

Modified: trunk/sys/dev/le/lancevar.h
===================================================================
--- trunk/sys/dev/le/lancevar.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/lancevar.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: lancevar.h,v 1.10 2005/12/11 12:21:27 christos Exp $	*/
 
 /*-
@@ -30,7 +31,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/dev/le/lancevar.h 204646 2010-03-03 17:55:51Z joel $ */
 
 #ifndef _DEV_LE_LANCEVAR_H_
 #define	_DEV_LE_LANCEVAR_H_

Modified: trunk/sys/dev/le/lebuffer_sbus.c
===================================================================
--- trunk/sys/dev/le/lebuffer_sbus.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/le/lebuffer_sbus.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 Marius Strobl <marius at FreeBSD.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/le/lebuffer_sbus.c 225931 2011-10-02 23:22:38Z marius $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/lge/if_lge.c
===================================================================
--- trunk/sys/dev/lge/if_lge.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/lge/if_lge.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 Wind River Systems
  * Copyright (c) 1997, 1998, 1999, 2000, 2001
@@ -32,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/lge/if_lge.c 254842 2013-08-25 10:57:09Z andre $");
 
 /*
  * Level 1 LXT1001 gigabit ethernet driver for FreeBSD. Public
@@ -122,7 +123,7 @@
 static int lge_alloc_jumbo_mem(struct lge_softc *);
 static void lge_free_jumbo_mem(struct lge_softc *);
 static void *lge_jalloc(struct lge_softc *);
-static void lge_jfree(void *, void *);
+static int lge_jfree(struct mbuf *, void *, void *);
 
 static int lge_newbuf(struct lge_softc *, struct lge_rx_desc *, struct mbuf *);
 static int lge_encap(struct lge_softc *, struct mbuf *, u_int32_t *);
@@ -536,7 +537,6 @@
 	}
 	ifp->if_softc = sc;
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
-	ifp->if_mtu = ETHERMTU;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 	ifp->if_ioctl = lge_ioctl;
 	ifp->if_start = lge_start;
@@ -847,10 +847,8 @@
 /*
  * Release a jumbo buffer.
  */
-static void
-lge_jfree(buf, args)
-	void			*buf;
-	void			*args;
+static int
+lge_jfree(struct mbuf *m, void *buf, void *args)
 {
 	struct lge_softc	*sc;
 	int		        i;
@@ -876,7 +874,7 @@
 	SLIST_REMOVE_HEAD(&sc->lge_jinuse_listhead, jpool_entries);
 	SLIST_INSERT_HEAD(&sc->lge_jfree_listhead, entry, jpool_entries);
 
-	return;
+	return (EXT_FREE_OK);
 }
 
 /*

Modified: trunk/sys/dev/lge/if_lgereg.h
===================================================================
--- trunk/sys/dev/lge/if_lgereg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/lge/if_lgereg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 Wind River Systems
  * Copyright (c) 1997, 1998, 1999, 2000, 2001
@@ -30,7 +31,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/lge/if_lgereg.h 226270 2011-10-11 21:52:24Z marius $
  */
 
 

Modified: trunk/sys/dev/lmc/if_lmc.c
===================================================================
--- trunk/sys/dev/lmc/if_lmc.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/lmc/if_lmc.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/lmc/if_lmc.c 255471 2013-09-11 09:19:44Z glebius $
  *
  * Copyright (c) 2002-2004 David Boggs. <boggs at boggs.palo-alto.ca.us>
  * All rights reserved.
@@ -4480,7 +4481,6 @@
 # if (defined(__FreeBSD__) && defined(DEVICE_POLLING))  /* XXX necessary? */
     case SIOCSIFCAP:
 # endif
-    case SIOCSIFDSTADDR:
     case SIOCAIFADDR:
     case SIOCSIFFLAGS:
 #if 0
@@ -4587,7 +4587,7 @@
 /* Called from a syscall (user context; no spinlocks). */
 static int
 lmc_raw_output(struct ifnet *ifp, struct mbuf *m,
- struct sockaddr *dst, struct route *ro)
+ const struct sockaddr *dst, struct route *ro)
   {
   softc_t *sc = IFP2SC(ifp);
   int error = 0;
@@ -4946,7 +4946,9 @@
   /* Detach from the ifnet kernel interface. */
   if_detach(sc->ifp);
 
-# if (__FreeBSD_version >= 600000)
+# if (defined(__FreeBSD__) && __FreeBSD_version >= 800082)
+  if_free(sc->ifp);
+# elif (defined(__FreeBSD__) && __FreeBSD_version >= 600000)
   if_free_type(sc->ifp, NSPPP ? IFT_PPP : IFT_OTHER);
 # endif
   }

Modified: trunk/sys/dev/lmc/if_lmc.h
===================================================================
--- trunk/sys/dev/lmc/if_lmc.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/lmc/if_lmc.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/lmc/if_lmc.h 249925 2013-04-26 12:50:32Z glebius $
  *
  * Copyright (c) 2002-2004 David Boggs. (boggs at boggs.palo-alto.ca.us)
  * All rights reserved.
@@ -1595,7 +1596,7 @@
 static int lmc_ifnet_ioctl(struct ifnet *, u_long, caddr_t);
 static void lmc_ifnet_start(struct ifnet *);
 static int lmc_raw_output(struct ifnet *, struct mbuf *,
- struct sockaddr *, struct route *);
+ const struct sockaddr *, struct route *);
 # ifdef __OpenBSD__
 static int ifmedia_change(struct ifnet *);
 static void ifmedia_status(struct ifnet *, struct ifmediareq *);

Modified: trunk/sys/dev/malo/if_malo.c
===================================================================
--- trunk/sys/dev/malo/if_malo.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/malo/if_malo.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008 Weongyo Jeong <weongyo at freebsd.org>
  * Copyright (c) 2007 Marvell Semiconductor, Inc.
@@ -31,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __FreeBSD__
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/malo/if_malo.c 278808 2015-02-15 20:02:29Z marius $");
 #endif
 
 #include "opt_malo.h"
@@ -169,7 +170,7 @@
 malo_bar0_write4(struct malo_softc *sc, bus_size_t off, uint32_t val)
 {
 	DPRINTF(sc, MALO_DEBUG_FW, "%s: off 0x%jx val 0x%x\n",
-	    __func__, (intmax_t)off, val);
+	    __func__, (uintmax_t)off, val);
 
 	bus_space_write_4(sc->malo_io0t, sc->malo_io0h, off, val);
 }
@@ -521,9 +522,10 @@
 	
 	ds = dd->dd_desc;
 	memset(ds, 0, dd->dd_desc_len);
-	DPRINTF(sc, MALO_DEBUG_RESET, "%s: %s DMA map: %p (%lu) -> %p (%lu)\n",
+	DPRINTF(sc, MALO_DEBUG_RESET,
+	    "%s: %s DMA map: %p (%lu) -> 0x%jx (%lu)\n",
 	    __func__, dd->dd_name, ds, (u_long) dd->dd_desc_len,
-	    (caddr_t) dd->dd_desc_paddr, /*XXX*/ (u_long) dd->dd_desc_len);
+	    (uintmax_t) dd->dd_desc_paddr, /*XXX*/ (u_long) dd->dd_desc_len);
 
 	return 0;
 fail2:
@@ -891,10 +893,9 @@
 	const struct malo_rxdesc *ds = bf->bf_desc;
 	uint32_t status = le32toh(ds->status);
 	
-	printf("R[%2u] (DS.V:%p DS.P:%p) NEXT:%08x DATA:%08x RC:%02x%s\n"
+	printf("R[%2u] (DS.V:%p DS.P:0x%jx) NEXT:%08x DATA:%08x RC:%02x%s\n"
 	    "      STAT:%02x LEN:%04x SNR:%02x NF:%02x CHAN:%02x"
-	    " RATE:%02x QOS:%04x\n",
-	    ix, ds, (const struct malo_desc *)bf->bf_daddr,
+	    " RATE:%02x QOS:%04x\n", ix, ds, (uintmax_t)bf->bf_daddr,
 	    le32toh(ds->physnext), le32toh(ds->physbuffdata),
 	    ds->rxcontrol, 
 	    ds->rxcontrol != MALO_RXD_CTRL_DRIVER_OWN ?
@@ -910,8 +911,7 @@
 	uint32_t status = le32toh(ds->status);
 	
 	printf("Q%u[%3u]", qnum, ix);
-	printf(" (DS.V:%p DS.P:%p)\n",
-	    ds, (const struct malo_txdesc *)bf->bf_daddr);
+	printf(" (DS.V:%p DS.P:0x%jx)\n", ds, (uintmax_t)bf->bf_daddr);
 	printf("    NEXT:%08x DATA:%08x LEN:%04x STAT:%08x%s\n",
 	    le32toh(ds->physnext),
 	    le32toh(ds->pktptr), le16toh(ds->pktlen), status,
@@ -1101,7 +1101,7 @@
 	uint16_t qos;
 
 	wh = mtod(m0, struct ieee80211_frame *);
-	iswep = wh->i_fc[1] & IEEE80211_FC1_WEP;
+	iswep = wh->i_fc[1] & IEEE80211_FC1_PROTECTED;
 	ismcast = IEEE80211_IS_MULTICAST(wh->i_addr1);
 	copyhdrlen = hdrlen = ieee80211_anyhdrsize(wh);
 	pktlen = m0->m_pkthdr.len;

Modified: trunk/sys/dev/malo/if_malo.h
===================================================================
--- trunk/sys/dev/malo/if_malo.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/malo/if_malo.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2007 Marvell Semiconductor, Inc.
  * Copyright (c) 2007 Sam Leffler, Errno Consulting
@@ -28,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGES.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/malo/if_malo.h 199559 2009-11-19 22:06:40Z jhb $
  */
 
 /*

Modified: trunk/sys/dev/malo/if_malo_pci.c
===================================================================
--- trunk/sys/dev/malo/if_malo_pci.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/malo/if_malo_pci.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2007 Marvell Semiconductor, Inc.
  * Copyright (c) 2007 Sam Leffler, Errno Consulting
@@ -31,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __FreeBSD__
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/malo/if_malo_pci.c 278418 2015-02-08 22:29:57Z marius $");
 #endif
 
 /*
@@ -223,9 +224,9 @@
 			       BUS_SPACE_MAXADDR_32BIT,	/* lowaddr */
 			       BUS_SPACE_MAXADDR,	/* highaddr */
 			       NULL, NULL,		/* filter, filterarg */
-			       BUS_SPACE_MAXADDR,	/* maxsize */
+			       BUS_SPACE_MAXSIZE,	/* maxsize */
 			       0,			/* nsegments */
-			       BUS_SPACE_MAXADDR,	/* maxsegsize */
+			       BUS_SPACE_MAXSIZE,	/* maxsegsize */
 			       0,			/* flags */
 			       NULL,			/* lockfunc */
 			       NULL,			/* lockarg */

Modified: trunk/sys/dev/malo/if_malohal.c
===================================================================
--- trunk/sys/dev/malo/if_malohal.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/malo/if_malohal.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2007 Marvell Semiconductor, Inc.
  * Copyright (c) 2007 Sam Leffler, Errno Consulting
@@ -31,7 +32,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __FreeBSD__
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/malo/if_malohal.c 190550 2009-03-30 11:23:14Z weongyo $");
 #endif
 
 #include <sys/param.h>

Modified: trunk/sys/dev/malo/if_malohal.h
===================================================================
--- trunk/sys/dev/malo/if_malohal.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/malo/if_malohal.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2007 Marvell Semiconductor, Inc.
  * Copyright (c) 2007 Sam Leffler, Errno Consulting
@@ -28,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGES.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/malo/if_malohal.h 218909 2011-02-21 09:01:34Z brucec $
  */
 
 #ifndef _DEV_MALOHAL_H

Modified: trunk/sys/dev/malo/if_maloioctl.h
===================================================================
--- trunk/sys/dev/malo/if_maloioctl.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/malo/if_maloioctl.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2007 Marvell Semiconductor, Inc.
  * Copyright (c) 2007 Sam Leffler, Errno Consulting
@@ -28,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGES.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/malo/if_maloioctl.h 177595 2008-03-25 06:32:33Z weongyo $
  */
 
 /*

Modified: trunk/sys/dev/mca/mca_bus.c
===================================================================
--- trunk/sys/dev/mca/mca_bus.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mca/mca_bus.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 Matthew N. Dodd <winter at jurai.net>
  * All rights reserved.
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mca/mca_bus.c 227843 2011-11-22 21:28:20Z marius $");
 
 /*
  * References:

Modified: trunk/sys/dev/mca/mca_busreg.h
===================================================================
--- trunk/sys/dev/mca/mca_busreg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mca/mca_busreg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 Matthew N. Dodd <winter at jurai.net>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/mca/mca_busreg.h 50825 1999-09-03 03:40:00Z mdodd $
  */
 
 /*

Modified: trunk/sys/dev/mca/mca_busvar.h
===================================================================
--- trunk/sys/dev/mca/mca_busvar.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mca/mca_busvar.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 Matthew N. Dodd <winter at jurai.net>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/mca/mca_busvar.h 51674 1999-09-26 07:02:05Z mdodd $
  */
 
 typedef u_int16_t mca_id_t;

Modified: trunk/sys/dev/mcd/mcd.c
===================================================================
--- trunk/sys/dev/mcd/mcd.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mcd/mcd.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright 1993 by Holger Veit (data part)
  * Copyright 1993 by Brian Moore (audio part)
@@ -43,8 +44,8 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
-static const char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";
+__FBSDID("$FreeBSD: stable/10/sys/dev/mcd/mcd.c 320923 2017-07-12 22:16:54Z jhb $");
+static const char __used COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -206,6 +207,8 @@
 				 UID_ROOT, GID_OPERATOR, 0640, "mcd%d", unit);
 
 	sc->mcd_dev_t->si_drv1 = (void *)sc;
+	device_printf(sc->dev,
+	    "WARNING: This driver is deprecated and will be removed.\n");
 
 	return (0);
 }
@@ -289,7 +292,6 @@
 mcdstrategy(struct bio *bp)
 {
 	struct mcd_softc *sc;
-	int s;
 
 	sc = (struct mcd_softc *)bp->bio_dev->si_drv1;
 
@@ -318,9 +320,7 @@
 	bp->bio_resid = 0;
 
 	/* queue it */
-	s = splbio();
 	bioq_disksort(&sc->data.head, bp);
-	splx(s);
 
 	/* now check whether we can perform processing */
 	mcd_start(sc);
@@ -338,10 +338,8 @@
 mcd_start(struct mcd_softc *sc)
 {
 	struct bio *bp;
-	int s = splbio();
 
 	if (sc->data.flags & MCDMBXBSY) {
-		splx(s);
 		return;
 	}
 
@@ -350,10 +348,8 @@
 		/* block found to process, dequeue */
 		/*MCD_TRACE("mcd_start: found block bp=0x%x\n",bp,0,0,0);*/
 		sc->data.flags |= MCDMBXBSY;
-		splx(s);
 	} else {
 		/* nothing to do */
-		splx(s);
 		return;
 	}
 

Modified: trunk/sys/dev/mcd/mcd_isa.c
===================================================================
--- trunk/sys/dev/mcd/mcd_isa.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mcd/mcd_isa.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,8 +1,9 @@
+/* $MidnightBSD$ */
 /*
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mcd/mcd_isa.c 146734 2005-05-29 04:42:30Z nyan $");
 
 #include <sys/param.h>
 #include <sys/systm.h>

Modified: trunk/sys/dev/mcd/mcdreg.h
===================================================================
--- trunk/sys/dev/mcd/mcdreg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mcd/mcdreg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright 1993 by Holger Veit (data part)
  * Copyright 1993 by Brian Moore (audio part)
@@ -41,7 +42,7 @@
  * the manufacturer or anyone else might provide better documentation,
  * so this file (and the driver) will then have a better quality.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/mcd/mcdreg.h 143063 2005-03-02 21:33:29Z joerg $
  */
 
 #ifndef MCD_H

Modified: trunk/sys/dev/mcd/mcdvar.h
===================================================================
--- trunk/sys/dev/mcd/mcdvar.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mcd/mcdvar.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/mcd/mcdvar.h 130585 2004-06-16 09:47:26Z phk $
  */
 
 struct mcd_mbx {

Modified: trunk/sys/dev/md/md.c
===================================================================
--- trunk/sys/dev/md/md.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/md/md.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * ----------------------------------------------------------------------------
  * "THE BEER-WARE LICENSE" (Revision 42):
@@ -6,7 +7,7 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/md/md.c 320154 2017-06-20 17:03:06Z markj $
  *
  */
 
@@ -18,11 +19,16 @@
  * Copyright (c) 1988 University of Utah.
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
+ * Portions of this software were developed by Konstantin Belousov
+ * under sponsorship from the FreeBSD Foundation.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -59,6 +65,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/bio.h>
+#include <sys/buf.h>
 #include <sys/conf.h>
 #include <sys/devicestat.h>
 #include <sys/fcntl.h>
@@ -75,6 +82,7 @@
 #include <sys/namei.h>
 #include <sys/proc.h>
 #include <sys/queue.h>
+#include <sys/rwlock.h>
 #include <sys/sbuf.h>
 #include <sys/sched.h>
 #include <sys/sf_buf.h>
@@ -82,6 +90,7 @@
 #include <sys/vnode.h>
 
 #include <geom/geom.h>
+#include <geom/geom_int.h>
 
 #include <vm/vm.h>
 #include <vm/vm_param.h>
@@ -91,6 +100,8 @@
 #include <vm/swap_pager.h>
 #include <vm/uma.h>
 
+#include <machine/bus.h>
+
 #define MD_MODVER 1
 
 #define MD_SHUTDOWN	0x10000		/* Tell worker thread to terminate. */
@@ -104,10 +115,16 @@
 static MALLOC_DEFINE(M_MDSECT, "md_sectors", "Memory Disk Sectors");
 
 static int md_debug;
-SYSCTL_INT(_debug, OID_AUTO, mddebug, CTLFLAG_RW, &md_debug, 0, "");
+SYSCTL_INT(_debug, OID_AUTO, mddebug, CTLFLAG_RW, &md_debug, 0,
+    "Enable md(4) debug messages");
 static int md_malloc_wait;
-SYSCTL_INT(_vm, OID_AUTO, md_malloc_wait, CTLFLAG_RW, &md_malloc_wait, 0, "");
+SYSCTL_INT(_vm, OID_AUTO, md_malloc_wait, CTLFLAG_RW, &md_malloc_wait, 0,
+    "Allow malloc to wait for memory allocations");
 
+#if defined(MD_ROOT) && !defined(MD_ROOT_FSTYPE)
+#define	MD_ROOT_FSTYPE	"ufs"
+#endif
+
 #if defined(MD_ROOT) && defined(MD_ROOT_SIZE)
 /*
  * Preloaded image gets put here.
@@ -162,6 +179,8 @@
 #define NMASK	(NINDIR-1)
 static int nshift;
 
+static int md_vnode_pbuf_freecnt;
+
 struct indir {
 	uintptr_t	*array;
 	u_int		total;
@@ -174,6 +193,7 @@
 	LIST_ENTRY(md_s) list;
 	struct bio_queue_head bio_queue;
 	struct mtx queue_mtx;
+	struct mtx stat_mtx;
 	struct cdev *dev;
 	enum md_types type;
 	off_t mediasize;
@@ -400,8 +420,11 @@
 	struct md_s *sc;
 
 	sc = bp->bio_to->geom->softc;
-	if ((bp->bio_cmd == BIO_READ) || (bp->bio_cmd == BIO_WRITE))
+	if ((bp->bio_cmd == BIO_READ) || (bp->bio_cmd == BIO_WRITE)) {
+		mtx_lock(&sc->stat_mtx);
 		devstat_start_transaction_bio(sc->devstat, bp);
+		mtx_unlock(&sc->stat_mtx);
+	}
 	mtx_lock(&sc->queue_mtx);
 	bioq_disksort(&sc->bio_queue, bp);
 	mtx_unlock(&sc->queue_mtx);
@@ -408,11 +431,161 @@
 	wakeup(sc);
 }
 
+#define	MD_MALLOC_MOVE_ZERO	1
+#define	MD_MALLOC_MOVE_FILL	2
+#define	MD_MALLOC_MOVE_READ	3
+#define	MD_MALLOC_MOVE_WRITE	4
+#define	MD_MALLOC_MOVE_CMP	5
+
 static int
+md_malloc_move_ma(vm_page_t **mp, int *ma_offs, unsigned sectorsize,
+    void *ptr, u_char fill, int op)
+{
+	struct sf_buf *sf;
+	vm_page_t m, *mp1;
+	char *p, first;
+	off_t *uc;
+	unsigned n;
+	int error, i, ma_offs1, sz, first_read;
+
+	m = NULL;
+	error = 0;
+	sf = NULL;
+	/* if (op == MD_MALLOC_MOVE_CMP) { gcc */
+		first = 0;
+		first_read = 0;
+		uc = ptr;
+		mp1 = *mp;
+		ma_offs1 = *ma_offs;
+	/* } */
+	sched_pin();
+	for (n = sectorsize; n != 0; n -= sz) {
+		sz = imin(PAGE_SIZE - *ma_offs, n);
+		if (m != **mp) {
+			if (sf != NULL)
+				sf_buf_free(sf);
+			m = **mp;
+			sf = sf_buf_alloc(m, SFB_CPUPRIVATE |
+			    (md_malloc_wait ? 0 : SFB_NOWAIT));
+			if (sf == NULL) {
+				error = ENOMEM;
+				break;
+			}
+		}
+		p = (char *)sf_buf_kva(sf) + *ma_offs;
+		switch (op) {
+		case MD_MALLOC_MOVE_ZERO:
+			bzero(p, sz);
+			break;
+		case MD_MALLOC_MOVE_FILL:
+			memset(p, fill, sz);
+			break;
+		case MD_MALLOC_MOVE_READ:
+			bcopy(ptr, p, sz);
+			cpu_flush_dcache(p, sz);
+			break;
+		case MD_MALLOC_MOVE_WRITE:
+			bcopy(p, ptr, sz);
+			break;
+		case MD_MALLOC_MOVE_CMP:
+			for (i = 0; i < sz; i++, p++) {
+				if (!first_read) {
+					*uc = (u_char)*p;
+					first = *p;
+					first_read = 1;
+				} else if (*p != first) {
+					error = EDOOFUS;
+					break;
+				}
+			}
+			break;
+		default:
+			KASSERT(0, ("md_malloc_move_ma unknown op %d\n", op));
+			break;
+		}
+		if (error != 0)
+			break;
+		*ma_offs += sz;
+		*ma_offs %= PAGE_SIZE;
+		if (*ma_offs == 0)
+			(*mp)++;
+		ptr = (char *)ptr + sz;
+	}
+
+	if (sf != NULL)
+		sf_buf_free(sf);
+	sched_unpin();
+	if (op == MD_MALLOC_MOVE_CMP && error != 0) {
+		*mp = mp1;
+		*ma_offs = ma_offs1;
+	}
+	return (error);
+}
+
+static int
+md_malloc_move_vlist(bus_dma_segment_t **pvlist, int *pma_offs,
+    unsigned len, void *ptr, u_char fill, int op)
+{
+	bus_dma_segment_t *vlist;
+	uint8_t *p, *end, first;
+	off_t *uc;
+	int ma_offs, seg_len;
+
+	vlist = *pvlist;
+	ma_offs = *pma_offs;
+	uc = ptr;
+
+	for (; len != 0; len -= seg_len) {
+		seg_len = imin(vlist->ds_len - ma_offs, len);
+		p = (uint8_t *)(uintptr_t)vlist->ds_addr + ma_offs;
+		switch (op) {
+		case MD_MALLOC_MOVE_ZERO:
+			bzero(p, seg_len);
+			break;
+		case MD_MALLOC_MOVE_FILL:
+			memset(p, fill, seg_len);
+			break;
+		case MD_MALLOC_MOVE_READ:
+			bcopy(ptr, p, seg_len);
+			cpu_flush_dcache(p, seg_len);
+			break;
+		case MD_MALLOC_MOVE_WRITE:
+			bcopy(p, ptr, seg_len);
+			break;
+		case MD_MALLOC_MOVE_CMP:
+			end = p + seg_len;
+			first = *uc = *p;
+			/* Confirm all following bytes match the first */
+			while (++p < end) {
+				if (*p != first)
+					return (EDOOFUS);
+			}
+			break;
+		default:
+			KASSERT(0, ("md_malloc_move_vlist unknown op %d\n", op));
+			break;
+		}
+
+		ma_offs += seg_len;
+		if (ma_offs == vlist->ds_len) {
+			ma_offs = 0;
+			vlist++;
+		}
+		ptr = (uint8_t *)ptr + seg_len;
+	}
+	*pvlist = vlist;
+	*pma_offs = ma_offs;
+
+	return (0);
+}
+
+static int
 mdstart_malloc(struct md_s *sc, struct bio *bp)
 {
-	int i, error;
 	u_char *dst;
+	vm_page_t *m;
+	bus_dma_segment_t *vlist;
+	int i, error, error1, ma_offs, notmapped;
 	off_t secno, nsec, uc;
 	uintptr_t sp, osp;
 
@@ -425,9 +598,23 @@
 		return (EOPNOTSUPP);
 	}
 
+	notmapped = (bp->bio_flags & BIO_UNMAPPED) != 0;
+	vlist = (bp->bio_flags & BIO_VLIST) != 0 ?
+	    (bus_dma_segment_t *)bp->bio_data : NULL;
+	if (notmapped) {
+		m = bp->bio_ma;
+		ma_offs = bp->bio_ma_offset;
+		dst = NULL;
+		KASSERT(vlist == NULL, ("vlists cannot be unmapped"));
+	} else if (vlist != NULL) {
+		ma_offs = bp->bio_ma_offset;
+		dst = NULL;
+	} else {
+		dst = bp->bio_data;
+	}
+
 	nsec = bp->bio_length / sc->sectorsize;
 	secno = bp->bio_offset / sc->sectorsize;
-	dst = bp->bio_data;
 	error = 0;
 	while (nsec--) {
 		osp = s_read(sc->indir, secno);
@@ -435,21 +622,63 @@
 			if (osp != 0)
 				error = s_write(sc->indir, secno, 0);
 		} else if (bp->bio_cmd == BIO_READ) {
-			if (osp == 0)
-				bzero(dst, sc->sectorsize);
-			else if (osp <= 255)
-				memset(dst, osp, sc->sectorsize);
-			else {
-				bcopy((void *)osp, dst, sc->sectorsize);
-				cpu_flush_dcache(dst, sc->sectorsize);
+			if (osp == 0) {
+				if (notmapped) {
+					error = md_malloc_move_ma(&m, &ma_offs,
+					    sc->sectorsize, NULL, 0,
+					    MD_MALLOC_MOVE_ZERO);
+				} else if (vlist != NULL) {
+					error = md_malloc_move_vlist(&vlist,
+					    &ma_offs, sc->sectorsize, NULL, 0,
+					    MD_MALLOC_MOVE_ZERO);
+				} else
+					bzero(dst, sc->sectorsize);
+			} else if (osp <= 255) {
+				if (notmapped) {
+					error = md_malloc_move_ma(&m, &ma_offs,
+					    sc->sectorsize, NULL, osp,
+					    MD_MALLOC_MOVE_FILL);
+				} else if (vlist != NULL) {
+					error = md_malloc_move_vlist(&vlist,
+					    &ma_offs, sc->sectorsize, NULL, osp,
+					    MD_MALLOC_MOVE_FILL);
+				} else
+					memset(dst, osp, sc->sectorsize);
+			} else {
+				if (notmapped) {
+					error = md_malloc_move_ma(&m, &ma_offs,
+					    sc->sectorsize, (void *)osp, 0,
+					    MD_MALLOC_MOVE_READ);
+				} else if (vlist != NULL) {
+					error = md_malloc_move_vlist(&vlist,
+					    &ma_offs, sc->sectorsize,
+					    (void *)osp, 0,
+					    MD_MALLOC_MOVE_READ);
+				} else {
+					bcopy((void *)osp, dst, sc->sectorsize);
+					cpu_flush_dcache(dst, sc->sectorsize);
+				}
 			}
 			osp = 0;
 		} else if (bp->bio_cmd == BIO_WRITE) {
 			if (sc->flags & MD_COMPRESS) {
-				uc = dst[0];
-				for (i = 1; i < sc->sectorsize; i++)
-					if (dst[i] != uc)
-						break;
+				if (notmapped) {
+					error1 = md_malloc_move_ma(&m, &ma_offs,
+					    sc->sectorsize, &uc, 0,
+					    MD_MALLOC_MOVE_CMP);
+					i = error1 == 0 ? sc->sectorsize : 0;
+				} else if (vlist != NULL) {
+					error1 = md_malloc_move_vlist(&vlist,
+					    &ma_offs, sc->sectorsize, &uc, 0,
+					    MD_MALLOC_MOVE_CMP);
+					i = error1 == 0 ? sc->sectorsize : 0;
+				} else {
+					uc = dst[0];
+					for (i = 1; i < sc->sectorsize; i++) {
+						if (dst[i] != uc)
+							break;
+					}
+				}
 			} else {
 				i = 0;
 				uc = 0;
@@ -466,10 +695,36 @@
 						error = ENOSPC;
 						break;
 					}
-					bcopy(dst, (void *)sp, sc->sectorsize);
+					if (notmapped) {
+						error = md_malloc_move_ma(&m,
+						    &ma_offs, sc->sectorsize,
+						    (void *)sp, 0,
+						    MD_MALLOC_MOVE_WRITE);
+					} else if (vlist != NULL) {
+						error = md_malloc_move_vlist(
+						    &vlist, &ma_offs,
+						    sc->sectorsize, (void *)sp,
+						    0, MD_MALLOC_MOVE_WRITE);
+					} else {
+						bcopy(dst, (void *)sp,
+						    sc->sectorsize);
+					}
 					error = s_write(sc->indir, secno, sp);
 				} else {
-					bcopy(dst, (void *)osp, sc->sectorsize);
+					if (notmapped) {
+						error = md_malloc_move_ma(&m,
+						    &ma_offs, sc->sectorsize,
+						    (void *)osp, 0,
+						    MD_MALLOC_MOVE_WRITE);
+					} else if (vlist != NULL) {
+						error = md_malloc_move_vlist(
+						    &vlist, &ma_offs,
+						    sc->sectorsize, (void *)osp,
+						    0, MD_MALLOC_MOVE_WRITE);
+					} else {
+						bcopy(dst, (void *)osp,
+						    sc->sectorsize);
+					}
 					osp = 0;
 				}
 			}
@@ -481,25 +736,78 @@
 		if (error != 0)
 			break;
 		secno++;
-		dst += sc->sectorsize;
+		if (!notmapped && vlist == NULL)
+			dst += sc->sectorsize;
 	}
 	bp->bio_resid = 0;
 	return (error);
 }
 
+static void
+mdcopyto_vlist(void *src, bus_dma_segment_t *vlist, off_t offset, off_t len)
+{
+	off_t seg_len;
+
+	while (offset >= vlist->ds_len) {
+		offset -= vlist->ds_len;
+		vlist++;
+	}
+
+	while (len != 0) {
+		seg_len = omin(len, vlist->ds_len - offset);
+		bcopy(src, (void *)(uintptr_t)(vlist->ds_addr + offset),
+		    seg_len);
+		offset = 0;
+		src = (uint8_t *)src + seg_len;
+		len -= seg_len;
+		vlist++;
+	}
+}
+
+static void
+mdcopyfrom_vlist(bus_dma_segment_t *vlist, off_t offset, void *dst, off_t len)
+{
+	off_t seg_len;
+
+	while (offset >= vlist->ds_len) {
+		offset -= vlist->ds_len;
+		vlist++;
+	}
+
+	while (len != 0) {
+		seg_len = omin(len, vlist->ds_len - offset);
+		bcopy((void *)(uintptr_t)(vlist->ds_addr + offset), dst,
+		    seg_len);
+		offset = 0;
+		dst = (uint8_t *)dst + seg_len;
+		len -= seg_len;
+		vlist++;
+	}
+}
+
 static int
 mdstart_preload(struct md_s *sc, struct bio *bp)
 {
+	uint8_t *p;
 
+	p = sc->pl_ptr + bp->bio_offset;
 	switch (bp->bio_cmd) {
 	case BIO_READ:
-		bcopy(sc->pl_ptr + bp->bio_offset, bp->bio_data,
-		    bp->bio_length);
+		if ((bp->bio_flags & BIO_VLIST) != 0) {
+			mdcopyto_vlist(p, (bus_dma_segment_t *)bp->bio_data,
+			    bp->bio_ma_offset, bp->bio_length);
+		} else {
+			bcopy(p, bp->bio_data, bp->bio_length);
+		}
 		cpu_flush_dcache(bp->bio_data, bp->bio_length);
 		break;
 	case BIO_WRITE:
-		bcopy(bp->bio_data, sc->pl_ptr + bp->bio_offset,
-		    bp->bio_length);
+		if ((bp->bio_flags & BIO_VLIST) != 0) {
+			mdcopyfrom_vlist((bus_dma_segment_t *)bp->bio_data,
+			    bp->bio_ma_offset, p, bp->bio_length);
+		} else {
+			bcopy(bp->bio_data, p, bp->bio_length);
+		}
 		break;
 	}
 	bp->bio_resid = 0;
@@ -509,18 +817,26 @@
 static int
 mdstart_vnode(struct md_s *sc, struct bio *bp)
 {
-	int error, vfslocked;
+	int error;
 	struct uio auio;
 	struct iovec aiov;
+	struct iovec *piov;
 	struct mount *mp;
 	struct vnode *vp;
+	struct buf *pb;
+	bus_dma_segment_t *vlist;
 	struct thread *td;
-	off_t end, zerosize;
+	off_t iolen, len, zerosize;
+	int ma_offs, npages;
 
 	switch (bp->bio_cmd) {
 	case BIO_READ:
+		auio.uio_rw = UIO_READ;
+		break;
 	case BIO_WRITE:
 	case BIO_DELETE:
+		auio.uio_rw = UIO_WRITE;
+		break;
 	case BIO_FLUSH:
 		break;
 	default:
@@ -529,6 +845,10 @@
 
 	td = curthread;
 	vp = sc->vnode;
+	pb = NULL;
+	piov = NULL;
+	ma_offs = bp->bio_ma_offset;
+	len = bp->bio_length;
 
 	/*
 	 * VNODE I/O
@@ -539,76 +859,81 @@
 	 */
 
 	if (bp->bio_cmd == BIO_FLUSH) {
-		vfslocked = VFS_LOCK_GIANT(vp->v_mount);
 		(void) vn_start_write(vp, &mp, V_WAIT);
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 		error = VOP_FSYNC(vp, MNT_WAIT, td);
 		VOP_UNLOCK(vp, 0);
 		vn_finished_write(mp);
-		VFS_UNLOCK_GIANT(vfslocked);
 		return (error);
 	}
 
-	bzero(&auio, sizeof(auio));
+	auio.uio_offset = (vm_ooffset_t)bp->bio_offset;
+	auio.uio_resid = bp->bio_length;
+	auio.uio_segflg = UIO_SYSSPACE;
+	auio.uio_td = td;
 
-	/*
-	 * Special case for BIO_DELETE.  On the surface, this is very
-	 * similar to BIO_WRITE, except that we write from our own
-	 * fixed-length buffer, so we have to loop.  The net result is
-	 * that the two cases end up having very little in common.
-	 */
 	if (bp->bio_cmd == BIO_DELETE) {
+		/*
+		 * Emulate BIO_DELETE by writing zeros.
+		 */
 		zerosize = ZERO_REGION_SIZE -
 		    (ZERO_REGION_SIZE % sc->sectorsize);
+		auio.uio_iovcnt = howmany(bp->bio_length, zerosize);
+		piov = malloc(sizeof(*piov) * auio.uio_iovcnt, M_MD, M_WAITOK);
+		auio.uio_iov = piov;
+		while (len > 0) {
+			piov->iov_base = __DECONST(void *, zero_region);
+			piov->iov_len = len;
+			if (len > zerosize)
+				piov->iov_len = zerosize;
+			len -= piov->iov_len;
+			piov++;
+		}
+		piov = auio.uio_iov;
+	} else if ((bp->bio_flags & BIO_VLIST) != 0) {
+		piov = malloc(sizeof(*piov) * bp->bio_ma_n, M_MD, M_WAITOK);
+		auio.uio_iov = piov;
+		vlist = (bus_dma_segment_t *)bp->bio_data;
+		while (len > 0) {
+			piov->iov_base = (void *)(uintptr_t)(vlist->ds_addr +
+			    ma_offs);
+			piov->iov_len = vlist->ds_len - ma_offs;
+			if (piov->iov_len > len)
+				piov->iov_len = len;
+			len -= piov->iov_len;
+			ma_offs = 0;
+			vlist++;
+			piov++;
+		}
+		auio.uio_iovcnt = piov - auio.uio_iov;
+		piov = auio.uio_iov;
+	} else if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
+		pb = getpbuf(&md_vnode_pbuf_freecnt);
+		bp->bio_resid = len;
+unmapped_step:
+		npages = atop(min(MAXPHYS, round_page(len + (ma_offs &
+		    PAGE_MASK))));
+		iolen = min(ptoa(npages) - (ma_offs & PAGE_MASK), len);
+		KASSERT(iolen > 0, ("zero iolen"));
+		pmap_qenter((vm_offset_t)pb->b_data,
+		    &bp->bio_ma[atop(ma_offs)], npages);
+		aiov.iov_base = (void *)((vm_offset_t)pb->b_data +
+		    (ma_offs & PAGE_MASK));
+		aiov.iov_len = iolen;
 		auio.uio_iov = &aiov;
 		auio.uio_iovcnt = 1;
-		auio.uio_offset = (vm_ooffset_t)bp->bio_offset;
-		auio.uio_segflg = UIO_SYSSPACE;
-		auio.uio_rw = UIO_WRITE;
-		auio.uio_td = td;
-		end = bp->bio_offset + bp->bio_length;
-		vfslocked = VFS_LOCK_GIANT(vp->v_mount);
-		(void) vn_start_write(vp, &mp, V_WAIT);
-		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-		error = 0;
-		while (auio.uio_offset < end) {
-			aiov.iov_base = __DECONST(void *, zero_region);
-			aiov.iov_len = end - auio.uio_offset;
-			if (aiov.iov_len > zerosize)
-				aiov.iov_len = zerosize;
-			auio.uio_resid = aiov.iov_len;
-			error = VOP_WRITE(vp, &auio,
-			    sc->flags & MD_ASYNC ? 0 : IO_SYNC, sc->cred);
-			if (error != 0)
-				break;
-		}
-		VOP_UNLOCK(vp, 0);
-		vn_finished_write(mp);
-		bp->bio_resid = end - auio.uio_offset;
-		VFS_UNLOCK_GIANT(vfslocked);
-		return (error);
+		auio.uio_resid = iolen;
+	} else {
+		aiov.iov_base = bp->bio_data;
+		aiov.iov_len = bp->bio_length;
+		auio.uio_iov = &aiov;
+		auio.uio_iovcnt = 1;
 	}
-
-	aiov.iov_base = bp->bio_data;
-	aiov.iov_len = bp->bio_length;
-	auio.uio_iov = &aiov;
-	auio.uio_iovcnt = 1;
-	auio.uio_offset = (vm_ooffset_t)bp->bio_offset;
-	auio.uio_segflg = UIO_SYSSPACE;
-	if (bp->bio_cmd == BIO_READ)
-		auio.uio_rw = UIO_READ;
-	else if (bp->bio_cmd == BIO_WRITE)
-		auio.uio_rw = UIO_WRITE;
-	else
-		panic("wrong BIO_OP in mdstart_vnode");
-	auio.uio_resid = bp->bio_length;
-	auio.uio_td = td;
 	/*
 	 * When reading set IO_DIRECT to try to avoid double-caching
 	 * the data.  When writing IO_DIRECT is not optimal.
 	 */
-	vfslocked = VFS_LOCK_GIANT(vp->v_mount);
-	if (bp->bio_cmd == BIO_READ) {
+	if (auio.uio_rw == UIO_READ) {
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 		error = VOP_READ(vp, &auio, IO_DIRECT, sc->cred);
 		VOP_UNLOCK(vp, 0);
@@ -620,19 +945,43 @@
 		VOP_UNLOCK(vp, 0);
 		vn_finished_write(mp);
 	}
-	VFS_UNLOCK_GIANT(vfslocked);
-	bp->bio_resid = auio.uio_resid;
+
+	if (pb != NULL) {
+		pmap_qremove((vm_offset_t)pb->b_data, npages);
+		if (error == 0) {
+			len -= iolen;
+			bp->bio_resid -= iolen;
+			ma_offs += iolen;
+			if (len > 0)
+				goto unmapped_step;
+		}
+		relpbuf(pb, &md_vnode_pbuf_freecnt);
+	}
+
+	free(piov, M_MD);
+	if (pb == NULL)
+		bp->bio_resid = auio.uio_resid;
 	return (error);
 }
 
+static void
+md_swap_page_free(vm_page_t m)
+{
+
+	vm_page_xunbusy(m);
+	vm_page_lock(m);
+	vm_page_free(m);
+	vm_page_unlock(m);
+}
+
 static int
 mdstart_swap(struct md_s *sc, struct bio *bp)
 {
-	struct sf_buf *sf;
-	int rv, offs, len, lastend;
-	vm_pindex_t i, lastp;
 	vm_page_t m;
 	u_char *p;
+	vm_pindex_t i, lastp;
+	bus_dma_segment_t *vlist;
+	int rv, ma_offs, offs, len, lastend;
 
 	switch (bp->bio_cmd) {
 	case BIO_READ:
@@ -644,6 +993,10 @@
 	}
 
 	p = bp->bio_data;
+	ma_offs = (bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0 ?
+	    bp->bio_ma_offset : 0;
+	vlist = (bp->bio_flags & BIO_VLIST) != 0 ?
+	    (bus_dma_segment_t *)bp->bio_data : NULL;
 
 	/*
 	 * offs is the offset at which to start operating on the
@@ -657,17 +1010,11 @@
 	lastend = (bp->bio_offset + bp->bio_length - 1) % PAGE_SIZE + 1;
 
 	rv = VM_PAGER_OK;
-	VM_OBJECT_LOCK(sc->object);
+	VM_OBJECT_WLOCK(sc->object);
 	vm_object_pip_add(sc->object, 1);
 	for (i = bp->bio_offset / PAGE_SIZE; i <= lastp; i++) {
 		len = ((i == lastp) ? lastend : PAGE_SIZE) - offs;
-
-		m = vm_page_grab(sc->object, i,
-		    VM_ALLOC_NORMAL|VM_ALLOC_RETRY);
-		VM_OBJECT_UNLOCK(sc->object);
-		sched_pin();
-		sf = sf_buf_alloc(m, SFB_CPUPRIVATE);
-		VM_OBJECT_LOCK(sc->object);
+		m = vm_page_grab(sc->object, i, VM_ALLOC_SYSTEM);
 		if (bp->bio_cmd == BIO_READ) {
 			if (m->valid == VM_PAGE_BITS_ALL)
 				rv = VM_PAGER_OK;
@@ -674,9 +1021,7 @@
 			else
 				rv = vm_pager_get_pages(sc->object, &m, 1, 0);
 			if (rv == VM_PAGER_ERROR) {
-				sf_buf_free(sf);
-				sched_unpin();
-				vm_page_wakeup(m);
+				vm_page_xunbusy(m);
 				break;
 			} else if (rv == VM_PAGER_FAIL) {
 				/*
@@ -685,63 +1030,101 @@
 				 * valid. Do not set dirty, the page
 				 * can be recreated if thrown out.
 				 */
-				bzero((void *)sf_buf_kva(sf), PAGE_SIZE);
+				pmap_zero_page(m);
 				m->valid = VM_PAGE_BITS_ALL;
 			}
-			bcopy((void *)(sf_buf_kva(sf) + offs), p, len);
-			cpu_flush_dcache(p, len);
+			if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
+				pmap_copy_pages(&m, offs, bp->bio_ma,
+				    ma_offs, len);
+			} else if ((bp->bio_flags & BIO_VLIST) != 0) {
+				physcopyout_vlist(VM_PAGE_TO_PHYS(m) + offs,
+				    vlist, ma_offs, len);
+				cpu_flush_dcache(p, len);
+			} else {
+				physcopyout(VM_PAGE_TO_PHYS(m) + offs, p, len);
+				cpu_flush_dcache(p, len);
+			}
 		} else if (bp->bio_cmd == BIO_WRITE) {
-			if (len != PAGE_SIZE && m->valid != VM_PAGE_BITS_ALL)
+			if (len == PAGE_SIZE || m->valid == VM_PAGE_BITS_ALL)
+				rv = VM_PAGER_OK;
+			else
 				rv = vm_pager_get_pages(sc->object, &m, 1, 0);
-			else
-				rv = VM_PAGER_OK;
 			if (rv == VM_PAGER_ERROR) {
-				sf_buf_free(sf);
-				sched_unpin();
-				vm_page_wakeup(m);
+				vm_page_xunbusy(m);
 				break;
+			} else if (rv == VM_PAGER_FAIL)
+				pmap_zero_page(m);
+
+			if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
+				pmap_copy_pages(bp->bio_ma, ma_offs, &m,
+				    offs, len);
+			} else if ((bp->bio_flags & BIO_VLIST) != 0) {
+				physcopyin_vlist(vlist, ma_offs,
+				    VM_PAGE_TO_PHYS(m) + offs, len);
+			} else {
+				physcopyin(p, VM_PAGE_TO_PHYS(m) + offs, len);
 			}
-			bcopy(p, (void *)(sf_buf_kva(sf) + offs), len);
+
 			m->valid = VM_PAGE_BITS_ALL;
+			vm_page_dirty(m);
+			vm_pager_page_unswapped(m);
 		} else if (bp->bio_cmd == BIO_DELETE) {
-			if (len != PAGE_SIZE && m->valid != VM_PAGE_BITS_ALL)
+			if (len == PAGE_SIZE || m->valid == VM_PAGE_BITS_ALL)
+				rv = VM_PAGER_OK;
+			else
 				rv = vm_pager_get_pages(sc->object, &m, 1, 0);
-			else
-				rv = VM_PAGER_OK;
 			if (rv == VM_PAGER_ERROR) {
-				sf_buf_free(sf);
-				sched_unpin();
-				vm_page_wakeup(m);
+				vm_page_xunbusy(m);
 				break;
+			} else if (rv == VM_PAGER_FAIL) {
+				md_swap_page_free(m);
+				m = NULL;
+			} else {
+				/* Page is valid. */
+				if (len != PAGE_SIZE) {
+					pmap_zero_page_area(m, offs, len);
+					vm_page_dirty(m);
+				}
+				vm_pager_page_unswapped(m);
+				if (len == PAGE_SIZE) {
+					md_swap_page_free(m);
+					m = NULL;
+				}
 			}
-			if (len != PAGE_SIZE) {
-				bzero((void *)(sf_buf_kva(sf) + offs), len);
-				vm_page_clear_dirty(m, offs, len);
-				m->valid = VM_PAGE_BITS_ALL;
-			} else
-				vm_pager_page_unswapped(m);
 		}
-		sf_buf_free(sf);
-		sched_unpin();
-		vm_page_wakeup(m);
-		vm_page_lock(m);
-		if (bp->bio_cmd == BIO_DELETE && len == PAGE_SIZE)
-			vm_page_free(m);
-		else
+		if (m != NULL) {
+			vm_page_xunbusy(m);
+			vm_page_lock(m);
 			vm_page_activate(m);
-		vm_page_unlock(m);
-		if (bp->bio_cmd == BIO_WRITE)
-			vm_page_dirty(m);
+			vm_page_unlock(m);
+		}
 
 		/* Actions on further pages start at offset 0 */
 		p += PAGE_SIZE - offs;
 		offs = 0;
+		ma_offs += len;
 	}
 	vm_object_pip_subtract(sc->object, 1);
-	VM_OBJECT_UNLOCK(sc->object);
+	VM_OBJECT_WUNLOCK(sc->object);
 	return (rv != VM_PAGER_ERROR ? 0 : ENOSPC);
 }
 
+static int
+mdstart_null(struct md_s *sc, struct bio *bp)
+{
+
+	switch (bp->bio_cmd) {
+	case BIO_READ:
+		bzero(bp->bio_data, bp->bio_length);
+		cpu_flush_dcache(bp->bio_data, bp->bio_length);
+		break;
+	case BIO_WRITE:
+		break;
+	}
+	bp->bio_resid = 0;
+	return (0);
+}
+
 static void
 md_kthread(void *arg)
 {
@@ -825,6 +1208,7 @@
 	sc->type = type;
 	bioq_init(&sc->bio_queue);
 	mtx_init(&sc->queue_mtx, "md bio queue", NULL, MTX_DEF);
+	mtx_init(&sc->stat_mtx, "md stat", NULL, MTX_DEF);
 	sc->unit = unit;
 	sprintf(sc->name, "md%d", unit);
 	LIST_INSERT_HEAD(&md_softc_list, sc, list);
@@ -832,6 +1216,7 @@
 	if (error == 0)
 		return (sc);
 	LIST_REMOVE(sc, list);
+	mtx_destroy(&sc->stat_mtx);
 	mtx_destroy(&sc->queue_mtx);
 	free_unr(md_uh, sc->unit);
 	free(sc, M_MD);
@@ -849,8 +1234,19 @@
 	gp = g_new_geomf(&g_md_class, "md%d", sc->unit);
 	gp->softc = sc;
 	pp = g_new_providerf(gp, "md%d", sc->unit);
+	pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
 	pp->mediasize = sc->mediasize;
 	pp->sectorsize = sc->sectorsize;
+	switch (sc->type) {
+	case MD_MALLOC:
+	case MD_VNODE:
+	case MD_SWAP:
+		pp->flags |= G_PF_ACCEPT_UNMAPPED;
+		break;
+	case MD_PRELOAD:
+	case MD_NULL:
+		break;
+	}
 	sc->gp = gp;
 	sc->pp = pp;
 	g_error_provider(pp, 0);
@@ -948,7 +1344,7 @@
 	struct vattr vattr;
 	struct nameidata nd;
 	char *fname;
-	int error, flags, vfslocked;
+	int error, flags;
 
 	/*
 	 * Kernel-originated requests must have the filename appended
@@ -967,11 +1363,10 @@
 	 * set the FWRITE mask before trying to open the backing store.
 	 */
 	flags = FREAD | ((mdio->md_options & MD_READONLY) ? 0 : FWRITE);
-	NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, sc->file, td);
+	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, sc->file, td);
 	error = vn_open(&nd, &flags, 0, NULL);
 	if (error != 0)
 		return (error);
-	vfslocked = NDHASGIANT(&nd);
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 	if (nd.ni_vp->v_type != VREG) {
 		error = EINVAL;
@@ -1007,12 +1402,10 @@
 		nd.ni_vp->v_vflag &= ~VV_MD;
 		goto bad;
 	}
-	VFS_UNLOCK_GIANT(vfslocked);
 	return (0);
 bad:
 	VOP_UNLOCK(nd.ni_vp, 0);
 	(void)vn_close(nd.ni_vp, flags, td->td_ucred, td);
-	VFS_UNLOCK_GIANT(vfslocked);
 	return (error);
 }
 
@@ -1019,7 +1412,6 @@
 static int
 mddestroy(struct md_s *sc, struct thread *td)
 {
-	int vfslocked;
 
 	if (sc->gp) {
 		sc->gp->softc = NULL;
@@ -1039,15 +1431,14 @@
 	while (!(sc->flags & MD_EXITING))
 		msleep(sc->procp, &sc->queue_mtx, PRIBIO, "mddestroy", hz / 10);
 	mtx_unlock(&sc->queue_mtx);
+	mtx_destroy(&sc->stat_mtx);
 	mtx_destroy(&sc->queue_mtx);
 	if (sc->vnode != NULL) {
-		vfslocked = VFS_LOCK_GIANT(sc->vnode->v_mount);
 		vn_lock(sc->vnode, LK_EXCLUSIVE | LK_RETRY);
 		sc->vnode->v_vflag &= ~VV_MD;
 		VOP_UNLOCK(sc->vnode, 0);
 		(void)vn_close(sc->vnode, sc->flags & MD_READONLY ?
 		    FREAD : (FREAD|FWRITE), sc->cred, td);
-		VFS_UNLOCK_GIANT(vfslocked);
 	}
 	if (sc->cred != NULL)
 		crfree(sc->cred);
@@ -1065,6 +1456,65 @@
 }
 
 static int
+mdresize(struct md_s *sc, struct md_ioctl *mdio)
+{
+	int error, res;
+	vm_pindex_t oldpages, newpages;
+
+	switch (sc->type) {
+	case MD_VNODE:
+	case MD_NULL:
+		break;
+	case MD_SWAP:
+		if (mdio->md_mediasize <= 0 ||
+		    (mdio->md_mediasize % PAGE_SIZE) != 0)
+			return (EDOM);
+		oldpages = OFF_TO_IDX(round_page(sc->mediasize));
+		newpages = OFF_TO_IDX(round_page(mdio->md_mediasize));
+		if (newpages < oldpages) {
+			VM_OBJECT_WLOCK(sc->object);
+			vm_object_page_remove(sc->object, newpages, 0, 0);
+			swap_pager_freespace(sc->object, newpages,
+			    oldpages - newpages);
+			swap_release_by_cred(IDX_TO_OFF(oldpages -
+			    newpages), sc->cred);
+			sc->object->charge = IDX_TO_OFF(newpages);
+			sc->object->size = newpages;
+			VM_OBJECT_WUNLOCK(sc->object);
+		} else if (newpages > oldpages) {
+			res = swap_reserve_by_cred(IDX_TO_OFF(newpages -
+			    oldpages), sc->cred);
+			if (!res)
+				return (ENOMEM);
+			if ((mdio->md_options & MD_RESERVE) ||
+			    (sc->flags & MD_RESERVE)) {
+				error = swap_pager_reserve(sc->object,
+				    oldpages, newpages - oldpages);
+				if (error < 0) {
+					swap_release_by_cred(
+					    IDX_TO_OFF(newpages - oldpages),
+					    sc->cred);
+					return (EDOM);
+				}
+			}
+			VM_OBJECT_WLOCK(sc->object);
+			sc->object->charge = IDX_TO_OFF(newpages);
+			sc->object->size = newpages;
+			VM_OBJECT_WUNLOCK(sc->object);
+		}
+		break;
+	default:
+		return (EOPNOTSUPP);
+	}
+
+	sc->mediasize = mdio->md_mediasize;
+	g_topology_lock();
+	g_resize_provider(sc->pp, sc->mediasize);
+	g_topology_unlock();
+	return (0);
+}
+
+static int
 mdcreate_swap(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
 {
 	vm_ooffset_t npage;
@@ -1092,7 +1542,7 @@
 	    VM_PROT_DEFAULT, 0, td->td_ucred);
 	if (sc->object == NULL)
 		return (ENOMEM);
-	sc->flags = mdio->md_options & MD_FORCE;
+	sc->flags = mdio->md_options & (MD_FORCE | MD_RESERVE);
 	if (mdio->md_options & MD_RESERVE) {
 		if (swap_pager_reserve(sc->object, 0, npage) < 0) {
 			error = EDOM;
@@ -1108,7 +1558,20 @@
 	return (error);
 }
 
+static int
+mdcreate_null(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
+{
 
+	/*
+	 * Range check.  Disallow negative sizes or any size less then the
+	 * size of a page.  Then round to a page.
+	 */
+	if (sc->mediasize <= 0 || (sc->mediasize % PAGE_SIZE) != 0)
+		return (EDOM);
+
+	return (0);
+}
+
 static int
 xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
 {
@@ -1140,6 +1603,7 @@
 		case MD_PRELOAD:
 		case MD_VNODE:
 		case MD_SWAP:
+		case MD_NULL:
 			break;
 		default:
 			return (EINVAL);
@@ -1185,6 +1649,10 @@
 			sc->start = mdstart_swap;
 			error = mdcreate_swap(sc, mdio, td);
 			break;
+		case MD_NULL:
+			sc->start = mdstart_null;
+			error = mdcreate_null(sc, mdio, td);
+			break;
 		}
 		if (error != 0) {
 			mddestroy(sc, td);
@@ -1209,6 +1677,20 @@
 		    !(mdio->md_options & MD_FORCE))
 			return (EBUSY);
 		return (mddestroy(sc, td));
+	case MDIOCRESIZE:
+		if ((mdio->md_options & ~(MD_FORCE | MD_RESERVE)) != 0)
+			return (EINVAL);
+
+		sc = mdfind(mdio->md_unit);
+		if (sc == NULL)
+			return (ENOENT);
+		if (mdio->md_mediasize < sc->sectorsize)
+			return (EINVAL);
+		if (mdio->md_mediasize < sc->mediasize &&
+		    !(sc->flags & MD_FORCE) &&
+		    !(mdio->md_options & MD_FORCE))
+			return (EBUSY);
+		return (mdresize(sc, mdio));
 	case MDIOCQUERY:
 		sc = mdfind(mdio->md_unit);
 		if (sc == NULL)
@@ -1263,7 +1745,7 @@
 	sc->start = mdstart_preload;
 #ifdef MD_ROOT
 	if (sc->unit == 0)
-		rootdevnames[0] = "ufs:/dev/md0";
+		rootdevnames[0] = MD_ROOT_FSTYPE ":/dev/md0";
 #endif
 	mdinit(sc);
 	if (name != NULL) {
@@ -1311,6 +1793,7 @@
 			sx_xunlock(&md_sx);
 		}
 	}
+	md_vnode_pbuf_freecnt = nswbuf / 10;
 	status_dev = make_dev(&mdctl_cdevsw, INT_MAX, UID_ROOT, GID_WHEEL,
 	    0600, MDCTL_NAME);
 	g_topology_lock();
@@ -1340,6 +1823,9 @@
 	case MD_SWAP:
 		type = "swap";
 		break;
+	case MD_NULL:
+		type = "null";
+		break;
 	default:
 		type = "unknown";
 		break;
@@ -1366,11 +1852,18 @@
 			    indent, (uintmax_t) mp->fwsectors);
 			sbuf_printf(sb, "%s<length>%ju</length>\n",
 			    indent, (uintmax_t) mp->mediasize);
+			sbuf_printf(sb, "%s<compression>%s</compression>\n", indent,
+			    (mp->flags & MD_COMPRESS) == 0 ? "off": "on");
+			sbuf_printf(sb, "%s<access>%s</access>\n", indent,
+			    (mp->flags & MD_READONLY) == 0 ? "read-write":
+			    "read-only");
 			sbuf_printf(sb, "%s<type>%s</type>\n", indent,
 			    type);
-			if (mp->type == MD_VNODE && mp->vnode != NULL)
-				sbuf_printf(sb, "%s<file>%s</file>\n",
-				    indent, mp->file);
+			if (mp->type == MD_VNODE && mp->vnode != NULL) {
+				sbuf_printf(sb, "%s<file>", indent);
+				g_conf_printf_escaped(sb, "%s", mp->file);
+				sbuf_printf(sb, "</file>\n");
+			}
 		}
 	}
 }

Modified: trunk/sys/dev/mem/memdev.c
===================================================================
--- trunk/sys/dev/mem/memdev.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mem/memdev.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Mark R V Murray
  * All rights reserved.
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mem/memdev.c 278746 2015-02-14 08:44:12Z kib $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -37,6 +38,7 @@
 #include <sys/memrange.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
+#include <sys/priv.h>
 #include <sys/proc.h>
 #include <sys/signalvar.h>
 #include <sys/systm.h>
@@ -51,7 +53,7 @@
 
 static struct cdevsw mem_cdevsw = {
 	.d_version =	D_VERSION,
-	.d_flags =	D_MEM|D_NEEDGIANT,
+	.d_flags =	D_MEM,
 	.d_open =	memopen,
 	.d_read =	memrw,
 	.d_write =	memrw,
@@ -67,8 +69,14 @@
 {
 	int error = 0;
 
-	if (flags & FWRITE)
-		error = securelevel_gt(td->td_ucred, 0);
+	if (flags & FREAD)
+		error = priv_check(td, PRIV_KMEM_READ);
+	if (flags & FWRITE) {
+		if (error == 0)
+			error = priv_check(td, PRIV_KMEM_WRITE);
+		if (error == 0)
+			error = securelevel_gt(td->td_ucred, 0);
+	}
 
 	return (error);
 }

Modified: trunk/sys/dev/mem/memutil.c
===================================================================
--- trunk/sys/dev/mem/memutil.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mem/memutil.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Mark R V Murray
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mem/memutil.c 217515 2011-01-17 22:58:28Z jkim $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>

Modified: trunk/sys/dev/mfi/mfi.c
===================================================================
--- trunk/sys/dev/mfi/mfi.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi.c 314667 2017-03-04 13:03:31Z avg $");
 
 #include "opt_compat.h"
 #include "opt_mfi.h"
@@ -375,6 +376,7 @@
 	int error, commsz, framessz, sensesz;
 	int frames, unit, max_fw_sge, max_fw_cmds;
 	uint32_t tb_mem_size = 0;
+	struct cdev *dev_t;
 
 	if (sc == NULL)
 		return EINVAL;
@@ -769,7 +771,8 @@
 	sc->mfi_cdev = make_dev(&mfi_cdevsw, unit, UID_ROOT, GID_OPERATOR,
 	    0640, "mfi%d", unit);
 	if (unit == 0)
-		make_dev_alias(sc->mfi_cdev, "megaraid_sas_ioctl_node");
+		make_dev_alias_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK, &dev_t,
+		    sc->mfi_cdev, "%s", "megaraid_sas_ioctl_node");
 	if (sc->mfi_cdev != NULL)
 		sc->mfi_cdev->si_drv1 = sc;
 	SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->mfi_dev),
@@ -786,7 +789,7 @@
 	bus_generic_attach(sc->mfi_dev);
 
 	/* Start the timeout watchdog */
-	callout_init(&sc->mfi_watchdog_callout, CALLOUT_MPSAFE);
+	callout_init(&sc->mfi_watchdog_callout, 1);
 	callout_reset(&sc->mfi_watchdog_callout, mfi_cmd_timeout * hz,
 	    mfi_timeout, sc);
 
@@ -1628,6 +1631,11 @@
 				sx_xunlock(&sc->mfi_config_lock);
 			}
 		}
+		if (sc->mfi_cam_rescan_cb != NULL &&
+		    (detail->code == MR_EVT_PD_INSERTED ||
+		    detail->code == MR_EVT_PD_REMOVED)) {
+			sc->mfi_cam_rescan_cb(sc, detail->args.pd.device_id);
+		}
 		break;
 	}
 }
@@ -2117,6 +2125,8 @@
 	return cdb_len;
 }
 
+extern char *unmapped_buf;
+
 static struct mfi_command *
 mfi_build_syspdio(struct mfi_softc *sc, struct bio *bio)
 {
@@ -2140,11 +2150,11 @@
 	pass->header.cmd = MFI_CMD_PD_SCSI_IO;
 	switch (bio->bio_cmd & 0x03) {
 	case BIO_READ:
-		flags = MFI_CMD_DATAIN;
+		flags = MFI_CMD_DATAIN | MFI_CMD_BIO;
 		readop = 1;
 		break;
 	case BIO_WRITE:
-		flags = MFI_CMD_DATAOUT;
+		flags = MFI_CMD_DATAOUT | MFI_CMD_BIO;
 		readop = 0;
 		break;
 	default:
@@ -2169,7 +2179,7 @@
 	pass->sense_addr_hi = (uint32_t)((uint64_t)cm->cm_sense_busaddr >> 32);
 	cm->cm_complete = mfi_bio_complete;
 	cm->cm_private = bio;
-	cm->cm_data = bio->bio_data;
+	cm->cm_data = unmapped_buf;
 	cm->cm_len = bio->bio_bcount;
 	cm->cm_sg = &pass->sgl;
 	cm->cm_total_frame_size = MFI_PASS_FRAME_SIZE;
@@ -2200,11 +2210,11 @@
 	switch (bio->bio_cmd & 0x03) {
 	case BIO_READ:
 		io->header.cmd = MFI_CMD_LD_READ;
-		flags = MFI_CMD_DATAIN;
+		flags = MFI_CMD_DATAIN | MFI_CMD_BIO;
 		break;
 	case BIO_WRITE:
 		io->header.cmd = MFI_CMD_LD_WRITE;
-		flags = MFI_CMD_DATAOUT;
+		flags = MFI_CMD_DATAOUT | MFI_CMD_BIO;
 		break;
 	default:
 		/* TODO: what about BIO_DELETE??? */
@@ -2225,7 +2235,7 @@
 	io->lba_lo = bio->bio_pblkno & 0xffffffff;
 	cm->cm_complete = mfi_bio_complete;
 	cm->cm_private = bio;
-	cm->cm_data = bio->bio_data;
+	cm->cm_data = unmapped_buf;
 	cm->cm_len = bio->bio_bcount;
 	cm->cm_sg = &io->sgl;
 	cm->cm_total_frame_size = MFI_IO_FRAME_SIZE;
@@ -2307,8 +2317,18 @@
 
 	if ((cm->cm_data != NULL) && (cm->cm_frame->header.cmd != MFI_CMD_STP )) {
 		polled = (cm->cm_flags & MFI_CMD_POLLED) ? BUS_DMA_NOWAIT : 0;
-		error = bus_dmamap_load(sc->mfi_buffer_dmat, cm->cm_dmamap,
-		    cm->cm_data, cm->cm_len, mfi_data_cb, cm, polled);
+		if (cm->cm_flags & MFI_CMD_CCB)
+			error = bus_dmamap_load_ccb(sc->mfi_buffer_dmat,
+			    cm->cm_dmamap, cm->cm_data, mfi_data_cb, cm,
+			    polled);
+		else if (cm->cm_flags & MFI_CMD_BIO)
+			error = bus_dmamap_load_bio(sc->mfi_buffer_dmat,
+			    cm->cm_dmamap, cm->cm_private, mfi_data_cb, cm,
+			    polled);
+		else
+			error = bus_dmamap_load(sc->mfi_buffer_dmat,
+			    cm->cm_dmamap, cm->cm_data, cm->cm_len,
+			    mfi_data_cb, cm, polled);
 		if (error == EINPROGRESS) {
 			sc->mfi_flags |= MFI_FLAGS_QFRZN;
 			return (0);
@@ -3762,12 +3782,15 @@
 				MFI_PRINT_CMD(cm);
 				MFI_VALIDATE_CMD(sc, cm);
 				/*
-				 * Fail the command instead of leaving it on
-				 * the queue where it could remain stuck forever
+				 * While commands can get stuck forever we do
+				 * not fail them as there is no way to tell if
+				 * the controller has actually processed them
+				 * or not.
+				 *
+				 * In addition its very likely that force
+				 * failing a command here would cause a panic
+				 * e.g. in UFS.
 				 */
-				mfi_remove_busy(cm);
-				cm->cm_error = ETIMEDOUT;
-				mfi_complete(sc, cm);
 				timedout++;
 			}
 		}

Modified: trunk/sys/dev/mfi/mfi_cam.c
===================================================================
--- trunk/sys/dev/mfi/mfi_cam.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_cam.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright 2007 Scott Long
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_cam.c 315813 2017-03-23 06:41:13Z mav $");
 
 #include "opt_mfi.h"
 
@@ -50,7 +51,9 @@
 #include <cam/cam.h>
 #include <cam/cam_ccb.h>
 #include <cam/cam_debug.h>
+#include <cam/cam_periph.h>
 #include <cam/cam_sim.h>
+#include <cam/cam_xpt_periph.h>
 #include <cam/cam_xpt_sim.h>
 #include <cam/scsi/scsi_all.h>
 #include <cam/scsi/scsi_message.h>
@@ -63,6 +66,12 @@
 #include <dev/mfi/mfi_ioctl.h>
 #include <dev/mfi/mfivar.h>
 
+enum mfip_state {
+	MFIP_STATE_NONE,
+	MFIP_STATE_DETACH,
+	MFIP_STATE_RESCAN
+};
+
 struct mfip_softc {
 	device_t	dev;
 	struct mfi_softc *mfi_sc;
@@ -69,6 +78,7 @@
 	struct cam_devq *devq;
 	struct cam_sim	*sim;
 	struct cam_path	*path;
+	enum mfip_state	state;
 };
 
 static int	mfip_probe(device_t);
@@ -76,6 +86,7 @@
 static int	mfip_detach(device_t);
 static void	mfip_cam_action(struct cam_sim *, union ccb *);
 static void	mfip_cam_poll(struct cam_sim *);
+static void	mfip_cam_rescan(struct mfi_softc *, uint32_t tid);
 static struct mfi_command * mfip_start(void *);
 static void	mfip_done(struct mfi_command *cm);
 
@@ -89,7 +100,8 @@
 	DEVMETHOD(device_probe,		mfip_probe),
 	DEVMETHOD(device_attach,	mfip_attach),
 	DEVMETHOD(device_detach,	mfip_detach),
-	{0, 0}
+
+	DEVMETHOD_END
 };
 static driver_t mfip_driver = {
 	"mfip",
@@ -122,6 +134,7 @@
 
 	mfisc = device_get_softc(device_get_parent(dev));
 	sc->dev = dev;
+	sc->state = MFIP_STATE_NONE;
 	sc->mfi_sc = mfisc;
 	mfisc->mfi_cam_start = mfip_start;
 
@@ -138,6 +151,8 @@
 		return (EINVAL);
 	}
 
+	mfisc->mfi_cam_rescan_cb = mfip_cam_rescan;
+
 	mtx_lock(&mfisc->mfi_io_lock);
 	if (xpt_bus_register(sc->sim, dev, 0) != 0) {
 		device_printf(dev, "XPT bus registration failed\n");
@@ -162,6 +177,16 @@
 	if (sc == NULL)
 		return (EINVAL);
 
+	mtx_lock(&sc->mfi_sc->mfi_io_lock);
+	if (sc->state == MFIP_STATE_RESCAN) {
+		mtx_unlock(&sc->mfi_sc->mfi_io_lock);
+		return (EBUSY);
+	}
+	sc->state = MFIP_STATE_DETACH;
+	mtx_unlock(&sc->mfi_sc->mfi_io_lock);
+
+	sc->mfi_sc->mfi_cam_rescan_cb = NULL;
+
 	if (sc->sim != NULL) {
 		mtx_lock(&sc->mfi_sc->mfi_io_lock);
 		xpt_bus_deregister(cam_sim_path(sc->sim));
@@ -192,16 +217,16 @@
 		struct ccb_pathinq *cpi = &ccb->cpi;
 
 		cpi->version_num = 1;
-		cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
+		cpi->hba_inquiry = PI_TAG_ABLE;
 		cpi->target_sprt = 0;
-		cpi->hba_misc = PIM_NOBUSRESET|PIM_SEQSCAN;
+		cpi->hba_misc = PIM_NOBUSRESET | PIM_SEQSCAN | PIM_UNMAPPED;
 		cpi->hba_eng_cnt = 0;
 		cpi->max_target = MFI_SCSI_MAX_TARGETS;
 		cpi->max_lun = MFI_SCSI_MAX_LUNS;
 		cpi->initiator_id = MFI_SCSI_INITIATOR_ID;
-		strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
-		strncpy(cpi->hba_vid, "LSI", HBA_IDLEN);
-		strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
+		strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+		strlcpy(cpi->hba_vid, "LSI", HBA_IDLEN);
+		strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
 		cpi->unit_number = cam_sim_unit(sim);
 		cpi->bus_id = cam_sim_bus(sim);
 		cpi->base_transfer_speed = 150000;
@@ -220,6 +245,8 @@
 		break;
 	case XPT_GET_TRAN_SETTINGS:
 	{
+		struct ccb_trans_settings_scsi *scsi =
+		    &ccb->cts.proto_specific.scsi;
 		struct ccb_trans_settings_sas *sas =
 		    &ccb->cts.xport_specific.sas;
 
@@ -228,6 +255,9 @@
 		ccb->cts.transport = XPORT_SAS;
 		ccb->cts.transport_version = 0;
 
+		scsi->valid = CTS_SCSI_VALID_TQ;
+		scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
+
 		sas->valid &= ~CTS_SAS_VALID_SPEED;
 		sas->bitrate = 150000;
 
@@ -247,17 +277,6 @@
 			ccbh->status = CAM_REQ_INVALID;
 			break;
 		}
-		if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
-			if (ccbh->flags & CAM_DATA_PHYS) {
-				ccbh->status = CAM_REQ_INVALID;
-				break;
-			}
-			if (ccbh->flags & CAM_SCATTER_VALID) {
-				ccbh->status = CAM_REQ_INVALID;
-				break;
-			}
-		}
-
 		ccbh->ccb_mfip_ptr = sc;
 		TAILQ_INSERT_TAIL(&mfisc->mfi_cam_ccbq, ccbh, sim_links.tqe);
 		mfi_startio(mfisc);
@@ -272,6 +291,53 @@
 	return;
 }
 
+static void
+mfip_cam_rescan(struct mfi_softc *sc, uint32_t tid)
+{
+	union ccb *ccb;
+	struct mfip_softc *camsc;
+	struct cam_sim *sim;
+	device_t mfip_dev;
+
+	mtx_lock(&Giant);
+	mfip_dev = device_find_child(sc->mfi_dev, "mfip", -1);
+	mtx_unlock(&Giant);
+	if (mfip_dev == NULL) {
+		device_printf(sc->mfi_dev, "Couldn't find mfip child device!\n");
+		return;
+	}
+
+	mtx_lock(&sc->mfi_io_lock);
+	camsc = device_get_softc(mfip_dev);
+	if (camsc->state == MFIP_STATE_DETACH) {
+		mtx_unlock(&sc->mfi_io_lock);
+		return;
+	}
+	camsc->state = MFIP_STATE_RESCAN;
+
+	ccb = xpt_alloc_ccb_nowait();
+	if (ccb == NULL) {
+		mtx_unlock(&sc->mfi_io_lock);
+		device_printf(sc->mfi_dev,
+		    "Cannot allocate ccb for bus rescan.\n");
+		return;
+	}
+
+	sim = camsc->sim;
+	if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(sim),
+	    tid, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
+		xpt_free_ccb(ccb);
+		mtx_unlock(&sc->mfi_io_lock);
+		device_printf(sc->mfi_dev,
+		    "Cannot create path for bus rescan.\n");
+		return;
+	}
+	xpt_rescan(ccb);
+
+	camsc->state = MFIP_STATE_NONE;
+	mtx_unlock(&sc->mfi_io_lock);
+}
+
 static struct mfi_command *
 mfip_start(void *data)
 {
@@ -314,14 +380,14 @@
 	cm->cm_private = ccb;
 	cm->cm_sg = &pt->sgl;
 	cm->cm_total_frame_size = MFI_PASS_FRAME_SIZE;
-	cm->cm_data = csio->data_ptr;
+	cm->cm_data = ccb;
 	cm->cm_len = csio->dxfer_len;
 	switch (ccbh->flags & CAM_DIR_MASK) {
 	case CAM_DIR_IN:
-		cm->cm_flags = MFI_CMD_DATAIN;
+		cm->cm_flags = MFI_CMD_DATAIN | MFI_CMD_CCB;
 		break;
 	case CAM_DIR_OUT:
-		cm->cm_flags = MFI_CMD_DATAOUT;
+		cm->cm_flags = MFI_CMD_DATAOUT | MFI_CMD_CCB;
 		break;
 	case CAM_DIR_NONE:
 	default:

Modified: trunk/sys/dev/mfi/mfi_debug.c
===================================================================
--- trunk/sys/dev/mfi/mfi_debug.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_debug.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_debug.c 249257 2013-04-08 17:46:45Z markj $");
 
 #include "opt_mfi.h"
 

Modified: trunk/sys/dev/mfi/mfi_disk.c
===================================================================
--- trunk/sys/dev/mfi/mfi_disk.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_disk.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_disk.c 267084 2014-06-05 00:43:32Z kib $");
 
 #include "opt_mfi.h"
 
@@ -169,6 +170,7 @@
 		sc->ld_disk->d_fwheads = 64;
 		sc->ld_disk->d_fwsectors = 32;
 	}
+	sc->ld_disk->d_flags = DISKFLAG_UNMAPPED_BIO;
 	disk_create(sc->ld_disk, DISK_VERSION);
 
 	return (0);

Modified: trunk/sys/dev/mfi/mfi_ioctl.h
===================================================================
--- trunk/sys/dev/mfi/mfi_ioctl.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_ioctl.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_ioctl.h 233805 2012-04-02 19:13:02Z ambrisko $");
 
 #include <dev/mfi/mfireg.h>
 

Modified: trunk/sys/dev/mfi/mfi_linux.c
===================================================================
--- trunk/sys/dev/mfi/mfi_linux.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_linux.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -25,11 +26,11 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_linux.c 280258 2015-03-19 13:37:36Z rwatson $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/capability.h>
+#include <sys/capsicum.h>
 #include <sys/conf.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
@@ -84,6 +85,7 @@
 static int
 mfi_linux_ioctl(struct thread *p, struct linux_ioctl_args *args)
 {
+	cap_rights_t rights;
 	struct file *fp;
 	int error;
 	u_long cmd = args->cmd;
@@ -97,7 +99,8 @@
 		break;
 	}
 
-	if ((error = fget(p, args->fd, CAP_IOCTL, &fp)) != 0)
+	error = fget(p, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
+	if (error != 0)
 		return (error);
 	error = fo_ioctl(fp, cmd, (caddr_t)args->arg, p->td_ucred, p);
 	fdrop(fp, p);

Modified: trunk/sys/dev/mfi/mfi_pci.c
===================================================================
--- trunk/sys/dev/mfi/mfi_pci.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_pci.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_pci.c 270732 2014-08-27 21:11:19Z markj $");
 
 /* PCI/PCI-X/PCIe bus interface for the LSI MegaSAS controllers */
 
@@ -112,6 +113,11 @@
 SYSCTL_INT(_hw_mfi, OID_AUTO, msi, CTLFLAG_RDTUN, &mfi_msi, 0,
     "Enable use of MSI interrupts");
 
+static int	mfi_mrsas_enable = 0;
+TUNABLE_INT("hw.mfi.mrsas_enable", &mfi_mrsas_enable);
+SYSCTL_INT(_hw_mfi, OID_AUTO, mrsas_enable, CTLFLAG_RDTUN, &mfi_mrsas_enable,
+     0, "Allow mrasas to take newer cards");
+
 struct mfi_ident {
 	uint16_t	vendor;
 	uint16_t	device;
@@ -120,17 +126,19 @@
 	int		flags;
 	const char	*desc;
 } mfi_identifiers[] = {
-	{0x1000, 0x005b, 0x1028, 0x1f2d, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H810 Adapter"},
-	{0x1000, 0x005b, 0x1028, 0x1f30, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H710 Embedded"},
-	{0x1000, 0x005b, 0x1028, 0x1f31, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H710P Adapter"},
-	{0x1000, 0x005b, 0x1028, 0x1f33, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H710P Mini (blades)"},
-	{0x1000, 0x005b, 0x1028, 0x1f34, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H710P Mini (monolithics)"},
-	{0x1000, 0x005b, 0x1028, 0x1f35, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H710 Adapter"},
-	{0x1000, 0x005b, 0x1028, 0x1f37, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H710 Mini (blades)"},
-	{0x1000, 0x005b, 0x1028, 0x1f38, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Dell PERC H710 Mini (monolithics)"},
-	{0x1000, 0x005b, 0x8086, 0x9265, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Intel (R) RAID Controller RS25DB080"},
-	{0x1000, 0x005b, 0x8086, 0x9285, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "Intel (R) RAID Controller RS25NB008"},
-	{0x1000, 0x005b, 0xffff, 0xffff, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT, "ThunderBolt"},
+	{0x1000, 0x005b, 0x1028, 0x1f2d, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H810 Adapter"},
+	{0x1000, 0x005b, 0x1028, 0x1f30, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H710 Embedded"},
+	{0x1000, 0x005b, 0x1028, 0x1f31, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H710P Adapter"},
+	{0x1000, 0x005b, 0x1028, 0x1f33, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H710P Mini (blades)"},
+	{0x1000, 0x005b, 0x1028, 0x1f34, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H710P Mini (monolithics)"},
+	{0x1000, 0x005b, 0x1028, 0x1f35, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H710 Adapter"},
+	{0x1000, 0x005b, 0x1028, 0x1f37, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H710 Mini (blades)"},
+	{0x1000, 0x005b, 0x1028, 0x1f38, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Dell PERC H710 Mini (monolithics)"},
+	{0x1000, 0x005b, 0x8086, 0x9265, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Intel (R) RAID Controller RS25DB080"},
+	{0x1000, 0x005b, 0x8086, 0x9285, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "Intel (R) RAID Controller RS25NB008"},
+	{0x1000, 0x005b, 0xffff, 0xffff, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS, "ThunderBolt"},
+	{0x1000, 0x005d, 0xffff, 0xffff, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS| MFI_FLAGS_INVADER, "Invader"},
+	{0x1000, 0x005f, 0xffff, 0xffff, MFI_FLAGS_SKINNY| MFI_FLAGS_TBOLT| MFI_FLAGS_MRSAS| MFI_FLAGS_FURY, "Fury"},
 	{0x1000, 0x0060, 0x1028, 0xffff, MFI_FLAGS_1078,  "Dell PERC 6"},
 	{0x1000, 0x0060, 0xffff, 0xffff, MFI_FLAGS_1078,  "LSI MegaSAS 1078"},
 	{0x1000, 0x0071, 0xffff, 0xffff, MFI_FLAGS_SKINNY, "Drake Skinny"},
@@ -177,7 +185,13 @@
 
 	if ((id = mfi_find_ident(dev)) != NULL) {
 		device_set_desc(dev, id->desc);
-		return (BUS_PROBE_DEFAULT);
+
+		/* give priority to mrsas if tunable set */
+		TUNABLE_INT_FETCH("hw.mfi.mrsas_enable", &mfi_mrsas_enable);
+		if ((id->flags & MFI_FLAGS_MRSAS) && mfi_mrsas_enable)
+			return (BUS_PROBE_LOW_PRIORITY);
+		else
+			return (BUS_PROBE_DEFAULT);
 	}
 	return (ENXIO);
 }
@@ -187,7 +201,6 @@
 {
 	struct mfi_softc *sc;
 	struct mfi_ident *m;
-	uint32_t command;
 	int count, error;
 
 	sc = device_get_softc(dev);
@@ -196,19 +209,8 @@
 	m = mfi_find_ident(dev);
 	sc->mfi_flags = m->flags;
 
-	/* Verify that the adapter can be set up in PCI space */
-	command = pci_read_config(dev, PCIR_COMMAND, 2);
-	command |= PCIM_CMD_BUSMASTEREN;
-	pci_write_config(dev, PCIR_COMMAND, command, 2);
-	command = pci_read_config(dev, PCIR_COMMAND, 2);
-	if ((command & PCIM_CMD_BUSMASTEREN) == 0) {
-		device_printf(dev, "Can't enable PCI busmaster\n");
-		return (ENXIO);
-	}
-	if ((command & PCIM_CMD_MEMEN) == 0) {
-		device_printf(dev, "PCI memory window not available\n");
-		return (ENXIO);
-	}
+	/* Ensure busmastering is enabled */
+	pci_enable_busmaster(dev);
 
 	/* Allocate PCI registers */
 	if ((sc->mfi_flags & MFI_FLAGS_1064R) ||

Modified: trunk/sys/dev/mfi/mfi_syspd.c
===================================================================
--- trunk/sys/dev/mfi/mfi_syspd.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_syspd.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_syspd.c 267084 2014-06-05 00:43:32Z kib $");
 
 #include "opt_mfi.h"
 
@@ -126,7 +127,8 @@
 		      sectors / (1024 * 1024 / secsize), sectors, sc->pd_id);
 	sc->pd_disk = disk_alloc();
 	sc->pd_disk->d_drv1 = sc;
-	sc->pd_disk->d_maxsize = sc->pd_controller->mfi_max_io * secsize;
+	sc->pd_disk->d_maxsize = min(sc->pd_controller->mfi_max_io * secsize,
+		(sc->pd_controller->mfi_max_sge - 1) * PAGE_SIZE);
 	sc->pd_disk->d_name = "mfisyspd";
 	sc->pd_disk->d_open = mfi_syspd_open;
 	sc->pd_disk->d_close = mfi_syspd_close;
@@ -142,6 +144,7 @@
 		sc->pd_disk->d_fwheads = 64;
 		sc->pd_disk->d_fwsectors = 32;
 	}
+	sc->pd_disk->d_flags = DISKFLAG_UNMAPPED_BIO;
 	disk_create(sc->pd_disk, DISK_VERSION);
 
 	device_printf(dev, " SYSPD volume attached\n");

Modified: trunk/sys/dev/mfi/mfi_tbolt.c
===================================================================
--- trunk/sys/dev/mfi/mfi_tbolt.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfi_tbolt.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
  /*-
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,7 +32,7 @@
 
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfi_tbolt.c 262967 2014-03-10 02:31:50Z markj $");
 
 #include "opt_mfi.h"
 
@@ -850,7 +851,8 @@
 	io_request = cmd->io_request;
 	io_request->RaidContext.TargetID = device_id;
 	io_request->RaidContext.Status = 0;
-	io_request->RaidContext.exStatus =0;
+	io_request->RaidContext.exStatus = 0;
+	io_request->RaidContext.regLockFlags = 0;
 
 	start_lba_lo = mfi_cmd->cm_frame->io.lba_lo;
 	start_lba_hi = mfi_cmd->cm_frame->io.lba_hi;
@@ -945,6 +947,7 @@
 	uint8_t i, sg_processed, sg_to_process;
 	uint8_t sge_count, sge_idx;
 	union mfi_sgl *os_sgl;
+	pMpi25IeeeSgeChain64_t sgl_end;
 
 	/*
 	 * Return 0 if there is no data transfer
@@ -968,6 +971,11 @@
 	else
 		sge_idx = sge_count;
 
+	if (sc->mfi_flags & (MFI_FLAGS_INVADER | MFI_FLAGS_FURY)) {
+		sgl_end = sgl_ptr + (sc->max_SGEs_in_main_message - 1);
+		sgl_end->Flags = 0;
+	}
+
 	for (i = 0; i < sge_idx; i++) {
 		/*
 		 * For 32bit BSD we are getting 32 bit SGL's from OS
@@ -981,7 +989,11 @@
 			sgl_ptr->Length = os_sgl->sg32[i].len;
 			sgl_ptr->Address = os_sgl->sg32[i].addr;
 		}
-		sgl_ptr->Flags = 0;
+		if (i == sge_count - 1 &&
+		    (sc->mfi_flags & (MFI_FLAGS_INVADER | MFI_FLAGS_FURY)))
+			sgl_ptr->Flags = MPI25_IEEE_SGE_FLAGS_END_OF_LIST;
+		else
+			sgl_ptr->Flags = 0;
 		sgl_ptr++;
 		cmd->io_request->ChainOffset = 0;
 	}
@@ -996,8 +1008,11 @@
 		sg_chain = sgl_ptr;
 		/* Prepare chain element */
 		sg_chain->NextChainOffset = 0;
-		sg_chain->Flags = (MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT |
-		    MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
+		if (sc->mfi_flags & (MFI_FLAGS_INVADER | MFI_FLAGS_FURY))
+			sg_chain->Flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT;
+		else
+			sg_chain->Flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT |
+			    MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
 		sg_chain->Length =  (sizeof(MPI2_SGE_IO_UNION) *
 		    (sge_count - sg_processed));
 		sg_chain->Address = cmd->sg_frame_phys_addr;
@@ -1010,7 +1025,13 @@
 				sgl_ptr->Length = os_sgl->sg32[i].len;
 				sgl_ptr->Address = os_sgl->sg32[i].addr;
 			}
-			sgl_ptr->Flags = 0;
+			if (i == sge_count - 1 &&
+			    (sc->mfi_flags &
+			    (MFI_FLAGS_INVADER | MFI_FLAGS_FURY)))
+				sgl_ptr->Flags =
+				    MPI25_IEEE_SGE_FLAGS_END_OF_LIST;
+			else
+				sgl_ptr->Flags = 0;
 			sgl_ptr++;
 		}
 	}

Modified: trunk/sys/dev/mfi/mfireg.h
===================================================================
--- trunk/sys/dev/mfi/mfireg.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfireg.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -54,7 +55,7 @@
 #define _MFIREG_H
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfireg.h 255806 2013-09-22 23:48:41Z sbruno $");
 
 /*
  * MegaRAID SAS MFI firmware definitions
@@ -192,6 +193,8 @@
 	MFI_DCMD_CTRL_MFC_DEFAULTS_GET =0x010e0201,
 	MFI_DCMD_CTRL_MFC_DEFAULTS_SET =0x010e0202,
 	MFI_DCMD_CTRL_FLUSHCACHE =	0x01101000,
+	MFI_DCMD_CTRL_GET_PROPS =       0x01020100,
+	MFI_DCMD_CTRL_SET_PROPS =       0x01020200,
 	MFI_DCMD_CTRL_SHUTDOWN =	0x01050000,
 	MFI_DCMD_CTRL_EVENT_GETINFO =	0x01040100,
 	MFI_DCMD_CTRL_EVENT_GET =	0x01040300,
@@ -230,7 +233,11 @@
 	MFI_DCMD_CFG_CLEAR =		0x04030000,
 	MFI_DCMD_CFG_MAKE_SPARE =	0x04040000,
 	MFI_DCMD_CFG_REMOVE_SPARE =	0x04050000,
+	MFI_DCMD_CFG_FOREIGN_SCAN =     0x04060100,
+	MFI_DCMD_CFG_FOREIGN_DISPLAY =  0x04060200,
+	MFI_DCMD_CFG_FOREIGN_PREVIEW =  0x04060300,
 	MFI_DCMD_CFG_FOREIGN_IMPORT =	0x04060400,
+	MFI_DCMD_CFG_FOREIGN_CLEAR =    0x04060500,
 	MFI_DCMD_BBU_GET_STATUS =	0x05010000,
 	MFI_DCMD_BBU_GET_CAPACITY_INFO =0x05020000,
 	MFI_DCMD_BBU_GET_DESIGN_INFO =	0x05030000,

Modified: trunk/sys/dev/mfi/mfivar.h
===================================================================
--- trunk/sys/dev/mfi/mfivar.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mfi/mfivar.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 IronPort Systems
  * All rights reserved.
@@ -54,7 +55,7 @@
 #define _MFIVAR_H
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mfi/mfivar.h 270732 2014-08-27 21:11:19Z markj $");
 
 #include <sys/lock.h>
 #include <sys/sx.h>
@@ -104,10 +105,11 @@
 #define MFI_CMD_POLLED		(1<<4)
 #define MFI_CMD_SCSI		(1<<5)
 #define MFI_CMD_CCB		(1<<6)
-#define MFI_CMD_TBOLT		(1<<7)
-#define MFI_ON_MFIQ_FREE	(1<<8)
-#define MFI_ON_MFIQ_BUSY	(1<<9)
+#define	MFI_CMD_BIO		(1<<7)
+#define MFI_CMD_TBOLT		(1<<8)
+#define MFI_ON_MFIQ_FREE	(1<<9)
 #define MFI_ON_MFIQ_READY	(1<<10)
+#define MFI_ON_MFIQ_BUSY	(1<<11)
 #define MFI_ON_MFIQ_MASK	(MFI_ON_MFIQ_FREE | MFI_ON_MFIQ_READY| \
     MFI_ON_MFIQ_BUSY)
 #define MFI_CMD_FLAGS_FMT	"\20" \
@@ -117,10 +119,11 @@
     "\4COMPLETED" \
     "\5POLLED" \
     "\6SCSI" \
-    "\7TBOLT" \
-    "\10Q_FREE" \
-    "\11Q_READY" \
-    "\12Q_BUSY"
+    "\7BIO" \
+    "\10TBOLT" \
+    "\11Q_FREE" \
+    "\12Q_READY" \
+    "\13Q_BUSY"
 	uint8_t			retry_for_fw_reset;
 	void			(* cm_complete)(struct mfi_command *cm);
 	void			*cm_private;
@@ -199,6 +202,9 @@
 #define MFI_FLAGS_GEN2		(1<<6)
 #define MFI_FLAGS_SKINNY	(1<<7)
 #define MFI_FLAGS_TBOLT		(1<<8)
+#define MFI_FLAGS_MRSAS		(1<<9)
+#define MFI_FLAGS_INVADER	(1<<10)
+#define MFI_FLAGS_FURY		(1<<11)
 	// Start: LSIP200113393
 	bus_dma_tag_t			verbuf_h_dmat;
 	bus_dmamap_t			verbuf_h_dmamap;
@@ -313,6 +319,8 @@
 
 	TAILQ_HEAD(, ccb_hdr)		mfi_cam_ccbq;
 	struct mfi_command *		(* mfi_cam_start)(void *);
+	void				(*mfi_cam_rescan_cb)(struct mfi_softc *,
+					    uint32_t);
 	struct callout			mfi_watchdog_callout;
 	struct mtx			mfi_io_lock;
 	struct sx			mfi_config_lock;

Modified: trunk/sys/dev/mge/if_mge.c
===================================================================
--- trunk/sys/dev/mge/if_mge.c	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mge/if_mge.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2008 MARVELL INTERNATIONAL LTD.
  * All rights reserved.
@@ -34,7 +35,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/mge/if_mge.c 266152 2014-05-15 16:11:06Z ian $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -104,7 +105,10 @@
 static void mge_ver_params(struct mge_softc *sc);
 
 static void mge_intrs_ctrl(struct mge_softc *sc, int enable);
+static void mge_intr_rxtx(void *arg);
 static void mge_intr_rx(void *arg);
+static void mge_intr_rx_check(struct mge_softc *sc, uint32_t int_cause,
+    uint32_t int_cause_ext);
 static int mge_intr_rx_locked(struct mge_softc *sc, int count);
 static void mge_intr_tx(void *arg);
 static void mge_intr_tx_locked(struct mge_softc *sc);
@@ -171,8 +175,6 @@
 	{ SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE },
 	{ SYS_RES_IRQ, 1, RF_ACTIVE | RF_SHAREABLE },
 	{ SYS_RES_IRQ, 2, RF_ACTIVE | RF_SHAREABLE },
-	{ SYS_RES_IRQ, 3, RF_ACTIVE | RF_SHAREABLE },
-	{ SYS_RES_IRQ, 4, RF_ACTIVE | RF_SHAREABLE },
 	{ -1, 0 }
 };
 
@@ -179,7 +181,8 @@
 static struct {
 	driver_intr_t *handler;
 	char * description;
-} mge_intrs[MGE_INTR_COUNT] = {
+} mge_intrs[MGE_INTR_COUNT + 1] = {
+	{ mge_intr_rxtx,"GbE aggregated interrupt" },
 	{ mge_intr_rx,	"GbE receive interrupt" },
 	{ mge_intr_tx,	"GbE transmit interrupt" },
 	{ mge_intr_misc,"GbE misc interrupt" },
@@ -258,8 +261,11 @@
 	uint32_t d, r;
 
 	soc_id(&d, &r);
-	if (d == MV_DEV_88F6281 || d == MV_DEV_MV78100 ||
-	    d == MV_DEV_MV78100_Z0) {
+	if (d == MV_DEV_88F6281 || d == MV_DEV_88F6781 ||
+	    d == MV_DEV_88F6282 ||
+	    d == MV_DEV_MV78100 ||
+	    d == MV_DEV_MV78100_Z0 ||
+	    (d & MV_DEV_FAMILY_MASK) == MV_DEV_DISCOVERY) {
 		sc->mge_ver = 2;
 		sc->mge_mtu = 0x4e8;
 		sc->mge_tfut_ipg_max = 0xFFFF;
@@ -276,6 +282,15 @@
 		sc->mge_tx_tok_cfg = 0x3FFFFFFF;
 		sc->mge_tx_tok_cnt = 0x3FFFFFFF;
 	}
+	if (d == MV_DEV_88RC8180)
+		sc->mge_intr_cnt = 1;
+	else
+		sc->mge_intr_cnt = 2;
+
+	if (d == MV_DEV_MV78160 || d == MV_DEV_MV78260 || d == MV_DEV_MV78460)
+		sc->mge_hw_csum = 0;
+	else
+		sc->mge_hw_csum = 1;
 }
 
 static void
@@ -440,7 +455,7 @@
 
 	/* Allocate a busdma tag for mbufs. */
 	error = bus_dma_tag_create(bus_get_dma_tag(sc->dev),	/* parent */
-	    8, 0,				/* alignment, boundary */
+	    1, 0,				/* alignment, boundary */
 	    BUS_SPACE_MAXADDR_32BIT,		/* lowaddr */
 	    BUS_SPACE_MAXADDR,			/* highaddr */
 	    NULL, NULL,				/* filtfunc, filtfuncarg */
@@ -679,9 +694,12 @@
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
 	ifp->if_softc = sc;
 	ifp->if_flags = IFF_SIMPLEX | IFF_MULTICAST | IFF_BROADCAST;
-	ifp->if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_MTU;
+	ifp->if_capabilities = IFCAP_VLAN_MTU;
+	if (sc->mge_hw_csum) {
+		ifp->if_capabilities |= IFCAP_HWCSUM;
+		ifp->if_hwassist = MGE_CHECKSUM_FEATURES;
+	}
 	ifp->if_capenable = ifp->if_capabilities;
-	ifp->if_hwassist = MGE_CHECKSUM_FEATURES;
 
 #ifdef DEVICE_POLLING
 	/* Advertise that polling is supported */
@@ -715,13 +733,15 @@
 	MGE_WRITE(sc, MGE_REG_PHYDEV, miisc->mii_phy);
 
 	/* Attach interrupt handlers */
-	for (i = 0; i < 2; ++i) {
-		error = bus_setup_intr(dev, sc->res[1 + i],
-		    INTR_TYPE_NET | INTR_MPSAFE, NULL, *mge_intrs[i].handler,
-		    sc, &sc->ih_cookie[i]);
+	/* TODO: review flags, in part. mark RX as INTR_ENTROPY ? */
+	for (i = 1; i <= sc->mge_intr_cnt; ++i) {
+		error = bus_setup_intr(dev, sc->res[i],
+		    INTR_TYPE_NET | INTR_MPSAFE,
+		    NULL, *mge_intrs[(sc->mge_intr_cnt == 1 ? 0 : i)].handler,
+		    sc, &sc->ih_cookie[i - 1]);
 		if (error) {
 			device_printf(dev, "could not setup %s\n",
-			    mge_intrs[i].description);
+			    mge_intrs[(sc->mge_intr_cnt == 1 ? 0 : i)].description);
 			mge_detach(dev);
 			return (error);
 		}
@@ -746,7 +766,7 @@
         callout_drain(&sc->wd_callout);
 
 	/* Stop and release all interrupts */
-	for (i = 0; i < 2; ++i) {
+	for (i = 0; i < sc->mge_intr_cnt; ++i) {
 		if (!sc->ih_cookie[i])
 			continue;
 
@@ -753,7 +773,7 @@
 		error = bus_teardown_intr(dev, sc->res[1 + i], sc->ih_cookie[i]);
 		if (error)
 			device_printf(dev, "could not release %s\n",
-			    mge_intrs[i].description);
+			    mge_intrs[(sc->mge_intr_cnt == 1 ? 0 : i + 1)].description);
 	}
 
 	/* Detach network interface */
@@ -981,6 +1001,41 @@
 }
 
 static void
+mge_intr_rxtx(void *arg)
+{
+	struct mge_softc *sc = arg;
+	uint32_t int_cause, int_cause_ext;
+
+	MGE_GLOBAL_LOCK(sc);
+
+#ifdef DEVICE_POLLING
+	if (sc->ifp->if_capenable & IFCAP_POLLING) {
+		MGE_GLOBAL_UNLOCK(sc);
+		return;
+	}
+#endif
+
+	/* Get interrupt cause */
+	int_cause = MGE_READ(sc, MGE_PORT_INT_CAUSE);
+	int_cause_ext = MGE_READ(sc, MGE_PORT_INT_CAUSE_EXT);
+
+	/* Check for Transmit interrupt */
+	if (int_cause_ext & (MGE_PORT_INT_EXT_TXBUF0 |
+	    MGE_PORT_INT_EXT_TXUR)) {
+		MGE_WRITE(sc, MGE_PORT_INT_CAUSE_EXT, ~(int_cause_ext &
+		    (MGE_PORT_INT_EXT_TXBUF0 | MGE_PORT_INT_EXT_TXUR)));
+		mge_intr_tx_locked(sc);
+	}
+
+	MGE_TRANSMIT_UNLOCK(sc);
+
+	/* Check for Receive interrupt */
+	mge_intr_rx_check(sc, int_cause, int_cause_ext);
+
+	MGE_RECEIVE_UNLOCK(sc);
+}
+
+static void
 mge_intr_err(void *arg)
 {
 	struct mge_softc *sc = arg;
@@ -1018,11 +1073,20 @@
 	int_cause = MGE_READ(sc, MGE_PORT_INT_CAUSE);
 	int_cause_ext = MGE_READ(sc, MGE_PORT_INT_CAUSE_EXT);
 
+	mge_intr_rx_check(sc, int_cause, int_cause_ext);
+
+	MGE_RECEIVE_UNLOCK(sc);
+}
+
+static void
+mge_intr_rx_check(struct mge_softc *sc, uint32_t int_cause,
+    uint32_t int_cause_ext)
+{
 	/* Check for resource error */
 	if (int_cause & MGE_PORT_INT_RXERRQ0) {
 		mge_reinit_rx(sc);
 		MGE_WRITE(sc, MGE_PORT_INT_CAUSE,
-		    int_cause & ~MGE_PORT_INT_RXERRQ0);
+		    ~(int_cause & MGE_PORT_INT_RXERRQ0));
 	}
 
 	int_cause &= MGE_PORT_INT_RXQ0;
@@ -1033,11 +1097,8 @@
 		MGE_WRITE(sc, MGE_PORT_INT_CAUSE_EXT, ~int_cause_ext);
 		mge_intr_rx_locked(sc, -1);
 	}
-
-	MGE_RECEIVE_UNLOCK(sc);
 }
 
-
 static int
 mge_intr_rx_locked(struct mge_softc *sc, int count)
 {
@@ -1128,8 +1189,8 @@
 
 	/* Ack the interrupt */
 	int_cause_ext = MGE_READ(sc, MGE_PORT_INT_CAUSE_EXT);
-	MGE_WRITE(sc, MGE_PORT_INT_CAUSE_EXT,
-	    int_cause_ext & ~MGE_PORT_INT_EXT_TXBUF0);
+	MGE_WRITE(sc, MGE_PORT_INT_CAUSE_EXT, ~(int_cause_ext &
+	    (MGE_PORT_INT_EXT_TXBUF0 | MGE_PORT_INT_EXT_TXUR)));
 
 	mge_intr_tx_locked(sc);
 
@@ -1326,6 +1387,9 @@
 mge_probe(device_t dev)
 {
 
+	if (!ofw_bus_status_okay(dev))
+		return (ENXIO);
+
 	if (!ofw_bus_is_compatible(dev, "mrvl,ge"))
 		return (ENXIO);
 
@@ -1399,12 +1463,12 @@
 		dw->mge_desc->byte_count = segs[seg].ds_len;
 		dw->mge_desc->buffer = segs[seg].ds_addr;
 		dw->buffer = m0;
-		dw->mge_desc->cmd_status = MGE_TX_LAST | MGE_TX_FIRST |
+		dw->mge_desc->cmd_status = 0;
+		if (seg == 0)
+			mge_offload_setup_descriptor(sc, dw);
+		dw->mge_desc->cmd_status |= MGE_TX_LAST | MGE_TX_FIRST |
 		    MGE_TX_ETH_CRC | MGE_TX_EN_INT | MGE_TX_PADDING |
 		    MGE_DMA_OWNED;
-
-		if (seg == 0)
-			mge_offload_setup_descriptor(sc, dw);
 	}
 
 	bus_dmamap_sync(sc->mge_desc_dtag, dw->desc_dmap,
@@ -1643,9 +1707,7 @@
 
 		ip = (struct ip *)(m0->m_data + ehlen);
 		cmd_status |= MGE_TX_IP_HDR_SIZE(ip->ip_hl);
-
-		if ((m0->m_flags & M_FRAG) == 0)
-			cmd_status |= MGE_TX_NOT_FRAGMENT;
+		cmd_status |= MGE_TX_NOT_FRAGMENT;
 	}
 
 	if (csum_flags & CSUM_IP)

Modified: trunk/sys/dev/mge/if_mgevar.h
===================================================================
--- trunk/sys/dev/mge/if_mgevar.h	2018-05-27 23:36:47 UTC (rev 10097)
+++ trunk/sys/dev/mge/if_mgevar.h	2018-05-27 23:37:22 UTC (rev 10098)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2008 MARVELL INTERNATIONAL LTD.
  * All rights reserved.
@@ -28,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/mge/if_mgevar.h 261455 2014-02-04 03:36:42Z eadler $
  */
 
 #ifndef __IF_MGE_H__
@@ -103,6 +104,8 @@
 	uint32_t	mge_tx_tok_cnt;
 	uint16_t	mge_mtu;
 	int		mge_ver;
+	int		mge_intr_cnt;
+	uint8_t		mge_hw_csum;
 
 	struct mge_softc *phy_sc;
 };
@@ -260,7 +263,7 @@
 #define MGE_PORT_INT_RXQ0	(1 << 2)
 #define MGE_PORT_INT_RXERR	(1 << 10)
 #define MGE_PORT_INT_RXERRQ0	(1 << 11)
-#define MGE_PORT_INT_SUM	(1 << 31)
+#define MGE_PORT_INT_SUM	(1U << 31)
 
 #define MGE_PORT_INT_CAUSE_EXT	0x464
 #define MGE_PORT_INT_MASK_EXT	0x46C
@@ -271,7 +274,7 @@
 #define MGE_PORT_INT_EXT_TXUR	(1 << 19)
 #define MGE_PORT_INT_EXT_LC	(1 << 20)
 #define MGE_PORT_INT_EXT_IAR	(1 << 23)
-#define MGE_PORT_INT_EXT_SUM	(1 << 31)
+#define MGE_PORT_INT_EXT_SUM	(1U << 31)
 
 #define MGE_RX_FIFO_URGENT_TRSH		0x470
 #define MGE_TX_FIFO_URGENT_TRSH		0x474
@@ -328,7 +331,7 @@
 #define MGE_RX_DESC_FIRST	(1 << 27)
 #define MGE_RX_ENABLE_INT	(1 << 29)
 #define MGE_RX_L4_CSUM_OK	(1 << 30)
-#define MGE_DMA_OWNED		(1 << 31)
+#define MGE_DMA_OWNED		(1U << 31)
 
 #define MGE_RX_IP_FRAGMENT	(1 << 2)
 

Added: trunk/sys/dev/mii/smscphy.c
===================================================================
--- trunk/sys/dev/mii/smscphy.c	                        (rev 0)
+++ trunk/sys/dev/mii/smscphy.c	2018-05-27 23:37:22 UTC (rev 10098)
@@ -0,0 +1,236 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Benno Rice.  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 ``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 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/mii/smscphy.c 240851 2012-09-23 08:44:12Z kevlo $");
+
+/*
+ * Driver for the SMSC LAN8710A
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/malloc.h>
+
+#include <machine/bus.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include "miidevs.h"
+
+#include "miibus_if.h"
+
+static int	smscphy_probe(device_t);
+static int	smscphy_attach(device_t);
+
+static int	smscphy_service(struct mii_softc *, struct mii_data *, int);
+static void	smscphy_auto(struct mii_softc *, int);
+static void	smscphy_status(struct mii_softc *);
+
+static device_method_t smscphy_methods[] = {
+	/* device interface */
+	DEVMETHOD(device_probe,		smscphy_probe),
+	DEVMETHOD(device_attach,	smscphy_attach),
+	DEVMETHOD(device_detach,	mii_phy_detach),
+	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
+	DEVMETHOD_END
+};
+
+static devclass_t smscphy_devclass;
+
+static driver_t smscphy_driver = {
+	"smscphy",
+	smscphy_methods,
+	sizeof(struct mii_softc)
+};
+
+DRIVER_MODULE(smscphy, miibus, smscphy_driver, smscphy_devclass, 0, 0);
+
+static const struct mii_phydesc smscphys[] = {
+	MII_PHY_DESC(SMC, LAN8710A),
+	MII_PHY_END
+};
+
+static const struct mii_phy_funcs smscphy_funcs = {
+	smscphy_service,
+	smscphy_status,
+	mii_phy_reset
+};
+
+static int
+smscphy_probe(device_t dev)
+{
+
+	return (mii_phy_dev_probe(dev, smscphys, BUS_PROBE_DEFAULT));
+}
+
+static int
+smscphy_attach(device_t dev)
+{
+	struct mii_softc *sc;
+	const struct mii_phy_funcs *mpf;
+
+	sc = device_get_softc(dev);
+	mpf = &smscphy_funcs;
+	mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE, mpf, 1);
+	mii_phy_setmedia(sc);
+
+	return (0);
+}
+
+static int
+smscphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
+{
+        struct	ifmedia_entry *ife;
+        int	reg;
+
+	ife = mii->mii_media.ifm_cur;
+
+        switch (cmd) {
+        case MII_POLLSTAT:
+                break;
+
+        case MII_MEDIACHG:
+                /*
+                 * If the interface is not up, don't do anything.
+                 */
+                if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+                        break;
+
+		switch (IFM_SUBTYPE(ife->ifm_media)) {
+		case IFM_AUTO:
+			smscphy_auto(sc, ife->ifm_media);
+			break;
+
+		default:
+                	mii_phy_setmedia(sc);
+			break;
+		}
+
+                break;
+
+        case MII_TICK:
+		if ((mii->mii_ifp->if_flags & IFF_UP) == 0) {
+			return (0);
+		}
+
+		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) {
+			break;
+		}
+
+		/* I have no idea why BMCR_ISO gets set. */
+		reg = PHY_READ(sc, MII_BMCR);
+		if (reg & BMCR_ISO) {
+			PHY_WRITE(sc, MII_BMCR, reg & ~BMCR_ISO);
+		}
+
+		reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
+		if (reg & BMSR_LINK) {
+			sc->mii_ticks = 0;
+			break;
+		}
+
+		if (++sc->mii_ticks <= MII_ANEGTICKS) {
+			break;
+		}
+
+		sc->mii_ticks = 0;
+		PHY_RESET(sc);
+		smscphy_auto(sc, ife->ifm_media);
+                break;
+        }
+
+        /* Update the media status. */
+        PHY_STATUS(sc);
+
+        /* Callback if something changed. */
+        mii_phy_update(sc, cmd);
+        return (0);
+}
+
+static void
+smscphy_auto(struct mii_softc *sc, int media)
+{
+	uint16_t	anar;
+
+	anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
+	if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0)
+		anar |= ANAR_FC;
+	PHY_WRITE(sc, MII_ANAR, anar);
+	/* Apparently this helps. */
+	anar = PHY_READ(sc, MII_ANAR);
+	PHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG);
+}
+
+static void
+smscphy_status(struct mii_softc *sc)
+{
+	struct mii_data *mii;
+	uint32_t bmcr, bmsr, status;
+
+	mii = sc->mii_pdata;
+	mii->mii_media_status = IFM_AVALID;
+	mii->mii_media_active = IFM_ETHER;
+
+	bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
+	if ((bmsr & BMSR_LINK) != 0)
+		mii->mii_media_status |= IFM_ACTIVE;
+
+	bmcr = PHY_READ(sc, MII_BMCR);
+	if ((bmcr & BMCR_ISO) != 0) {
+		mii->mii_media_active |= IFM_NONE;
+		mii->mii_media_status = 0;
+		return;
+	}
+
+	if ((bmcr & BMCR_LOOP) != 0)
+		mii->mii_media_active |= IFM_LOOP;
+
+	if ((bmcr & BMCR_AUTOEN) != 0) {
+		if ((bmsr & BMSR_ACOMP) == 0) {
+			/* Erg, still trying, I guess... */
+			mii->mii_media_active |= IFM_NONE;
+			return;
+		}
+	}
+
+	status = PHY_READ(sc, 0x1F);
+	if (status & 0x0008)
+		mii->mii_media_active |= IFM_100_TX;
+	else
+		mii->mii_media_active |= IFM_10_T;
+	if (status & 0x0010)
+		mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc);
+	else
+		mii->mii_media_active |= IFM_HDX;
+}


Property changes on: trunk/sys/dev/mii/smscphy.c
___________________________________________________________________
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


More information about the Midnightbsd-cvs mailing list