CVS commit: src

2018-09-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep 18 05:37:54 UTC 2018

Modified Files:
src/share/man/man4: usb.4
src/sys/dev/usb: usb.c

Log Message:
remove usb(4)'s "flags 1" code.  it has been dead for a while,
as it runs during the interrupts part of configuration now,
and all the devices try attach as early as possible, including
any root or boot required disk or keyboard device, which is
what this flag was for.


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/share/man/man4/usb.4
cvs rdiff -u -r1.173 -r1.174 src/sys/dev/usb/usb.c

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

Modified files:

Index: src/share/man/man4/usb.4
diff -u src/share/man/man4/usb.4:1.109 src/share/man/man4/usb.4:1.110
--- src/share/man/man4/usb.4:1.109	Sat Sep 30 13:39:41 2017
+++ src/share/man/man4/usb.4	Tue Sep 18 05:37:54 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: usb.4,v 1.109 2017/09/30 13:39:41 wiz Exp $
+.\" $NetBSD: usb.4,v 1.110 2018/09/18 05:37:54 mrg Exp $
 .\"
 .\" Copyright (c) 1999-2014 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -43,10 +43,10 @@
 .Cd "slhci*  at pcmcia? function ?"
 .Cd "uhci*   at cardbus? function ?"
 .Cd "uhci*   at pci? dev ? function ?"
-.Cd "usb*at ehci? flags X"
-.Cd "usb*at ohci? flags X"
-.Cd "usb*at uhci? flags X"
-.Cd "usb*at slhci? flags X"
+.Cd "usb*at ehci?"
+.Cd "usb*at ohci?"
+.Cd "usb*at uhci?"
+.Cd "usb*at slhci?"
 .Cd "uhub*   at usb?"
 .Cd "uhub*   at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
 .Cd "XX* at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
@@ -82,26 +82,6 @@ The
 device controls USB hubs and must always be present since there is
 at least a root hub in any USB system.
 .Pp
-The
-.Va flags
-argument to the
-.Va usb
-device affects the order in which the device detection happens
-during cold boot.
-Normally, only the USB host controller and the
-.Va usb
-device are detected during the autoconfiguration when the
-machine is booted.
-The rest of the devices are detected once
-the system becomes functional and the kernel thread for the
-.Va usb
-device is started.
-Sometimes it is desirable to have a device detected early in the
-boot process, e.g., the console keyboard.
-To achieve this use a
-.Va flags
-value of 1.
-.Pp
 .Nx
 supports the following machine-independent USB drivers:
 .Ss Storage devices

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.173 src/sys/dev/usb/usb.c:1.174
--- src/sys/dev/usb/usb.c:1.173	Tue Sep 18 05:24:10 2018
+++ src/sys/dev/usb/usb.c	Tue Sep 18 05:37:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.173 2018/09/18 05:24:10 mrg Exp $	*/
+/*	$NetBSD: usb.c,v 1.174 2018/09/18 05:37:54 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.173 2018/09/18 05:24:10 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.174 2018/09/18 05:37:54 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -368,15 +368,6 @@ usb_doattach(device_t self)
 		}
 		sc->sc_bus->ub_roothub = dev;
 		usb_create_event_thread(self);
-#if 1
-		/*
-		 * Turning this code off will delay attachment of USB devices
-		 * until the USB event thread is running, which means that
-		 * the keyboard will not work until after cold boot.
-		 */
-		if (cold && (device_cfdata(self)->cf_flags & 1))
-			dev->ud_hub->uh_explore(sc->sc_bus->ub_roothub);
-#endif
 	} else {
 		aprint_error("%s: root hub problem, error=%s\n",
 			 device_xname(self), usbd_errstr(err));



CVS commit: src/sys/dev

2018-09-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep 18 05:24:10 UTC 2018

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

Log Message:
deal with partial attach failures in usb_attach vs usb_detach aka PR 53598.

- make sure xhci's sc->sc_ios is NULL if failure happens.
- rearrange usb_attach() / usb_doattach() to make it simpler to clean up.
- move usb_async_intr softint into usb_once_init().  previously, each USB
  controller would start a new one, and leave the old one leaked.
- handle controller interrupts without a bus attached


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/pci/xhci_pci.c
cvs rdiff -u -r1.172 -r1.173 src/sys/dev/usb/usb.c

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

Modified files:

Index: src/sys/dev/pci/xhci_pci.c
diff -u src/sys/dev/pci/xhci_pci.c:1.13 src/sys/dev/pci/xhci_pci.c:1.14
--- src/sys/dev/pci/xhci_pci.c:1.13	Fri Jun 29 17:48:24 2018
+++ src/sys/dev/pci/xhci_pci.c	Tue Sep 18 05:24:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci_pci.c,v 1.13 2018/06/29 17:48:24 msaitoh Exp $	*/
+/*	$NetBSD: xhci_pci.c,v 1.14 2018/09/18 05:24:10 mrg Exp $	*/
 /*	OpenBSD: xhci_pci.c,v 1.4 2014/07/12 17:38:51 yuo Exp	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.13 2018/06/29 17:48:24 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.14 2018/09/18 05:24:10 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_xhci_pci.h"
@@ -143,6 +143,7 @@ xhci_pci_attach(device_t parent, device_
 	printf("%s: csr: %08x\n", __func__, csr);
 #endif
 	if ((csr & PCI_COMMAND_MEM_ENABLE) == 0) {
+		sc->sc_ios = 0;
 		aprint_error_dev(self, "memory access is disabled\n");
 		return;
 	}
@@ -160,6 +161,7 @@ xhci_pci_attach(device_t parent, device_
 		}
 		break;
 	default:
+		sc->sc_ios = 0;
 		aprint_error_dev(self, "BAR not 64 or 32-bit MMIO\n");
 		return;
 	}

Index: src/sys/dev/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.172 src/sys/dev/usb/usb.c:1.173
--- src/sys/dev/usb/usb.c:1.172	Sun Sep 16 20:21:56 2018
+++ src/sys/dev/usb/usb.c	Tue Sep 18 05:24:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.172 2018/09/16 20:21:56 mrg Exp $	*/
+/*	$NetBSD: usb.c,v 1.173 2018/09/18 05:24:10 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.172 2018/09/16 20:21:56 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.173 2018/09/18 05:24:10 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -138,6 +138,7 @@ struct usb_softc {
 	struct lwp	*sc_event_thread;
 
 	char		sc_dying;
+	bool		sc_pmf_registered;
 };
 
 struct usb_taskq {
@@ -189,6 +190,7 @@ Static int usb_nevents = 0;
 Static struct selinfo usb_selevent;
 Static kmutex_t usb_event_lock;
 Static kcondvar_t usb_event_cv;
+/* XXX this is gross and broken */
 Static proc_t *usb_async_proc;  /* process that wants USB SIGIO */
 Static void *usb_async_sih;
 Static int usb_dev_open = 0;
@@ -239,6 +241,9 @@ usb_attach(device_t parent, device_t sel
 	sc->sc_bus = aux;
 	usbrev = sc->sc_bus->ub_revision;
 
+	cv_init(>sc_bus->ub_needsexplore_cv, "usbevt");
+	sc->sc_pmf_registered = false;
+
 	aprint_naive("\n");
 	aprint_normal(": USB revision %s", usbrev_str[usbrev]);
 	switch (usbrev) {
@@ -307,6 +312,11 @@ usb_once_init(void)
 		 * end up using them in usb_doattach().
 		 */
 	}
+
+	KASSERT(usb_async_sih == NULL);
+	usb_async_sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE,
+	   usb_async_intr, NULL);
+
 	return 0;
 }
 
@@ -342,8 +352,6 @@ usb_doattach(device_t self)
 		panic("usb_doattach");
 	}
 
-	cv_init(>sc_bus->ub_needsexplore_cv, "usbevt");
-
 	ue = usb_alloc_event();
 	ue->u.ue_ctrlr.ue_bus = device_unit(self);
 	usb_add_event(USB_EVENT_CTRLR_ATTACH, ue);
@@ -383,9 +391,8 @@ usb_doattach(device_t self)
 
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
-
-	usb_async_sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE,
-	   usb_async_intr, NULL);
+	else
+		sc->sc_pmf_registered = true;
 
 	return;
 }
@@ -1179,6 +1186,10 @@ usb_schedsoftintr(struct usbd_bus *bus)
 
 	DPRINTFN(10, "polling=%jd", bus->ub_usepolling, 0, 0, 0);
 
+	/* In case the bus never finished setting up. */
+	if (__predict_false(bus->ub_soft == NULL))
+		return;
+
 	if (bus->ub_usepolling) {
 		bus->ub_methods->ubm_softint(bus);
 	} else {
@@ -1231,7 +1242,8 @@ usb_detach(device_t self, int flags)
 	(rc = usb_disconnect_port(>sc_port, self, flags)) != 0)
 		return rc;
 
-	pmf_device_deregister(self);
+	if (sc->sc_pmf_registered)
+		pmf_device_deregister(self);
 	/* Kill off event thread. */
 	sc->sc_dying = 1;
 	while (sc->sc_event_thread != NULL) {



CVS commit: [pgoyette-compat] src/sys/sys

2018-09-17 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue Sep 18 03:32:35 UTC 2018

Modified Files:
src/sys/sys [pgoyette-compat]: compat_stub.h
Added Files:
src/sys/sys [pgoyette-compat]: compat_hook.h

Log Message:
Split the HOOK-related macros out from the declarations.

We'll need the macros for compat32, but won't want the declarations.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1.2.1 src/sys/sys/compat_hook.h
cvs rdiff -u -r1.1.2.24 -r1.1.2.25 src/sys/sys/compat_stub.h

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

Modified files:

Index: src/sys/sys/compat_stub.h
diff -u src/sys/sys/compat_stub.h:1.1.2.24 src/sys/sys/compat_stub.h:1.1.2.25
--- src/sys/sys/compat_stub.h:1.1.2.24	Tue Sep 18 01:15:58 2018
+++ src/sys/sys/compat_stub.h	Tue Sep 18 03:32:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.h,v 1.1.2.24 2018/09/18 01:15:58 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.h,v 1.1.2.25 2018/09/18 03:32:35 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,157 +32,7 @@
 #ifndef _SYS_COMPAT_STUB_H
 #define _SYS_COMPAT_STUB_H
 
-#include 	/* for COHERENCY_UNIT, for __cacheline_aligned */
-#include 
-#include 
-#include 
-#include 
-#include 
-
-/*
- * Macros for creating MP-safe vectored function calls, where
- * the function implementations are in modules which could be
- * unloaded.
- */
-
-#define COMPAT_HOOK(hook,args)	\
-extern struct hook ## _t {	\
-	kmutex_t		mtx;\
-	kcondvar_t		cv;\
-	struct localcount	lc;\
-	pserialize_t		psz;\
-bool			hooked;\
-	int			(*f)args;			\
-} hook __cacheline_aligned;
-
-#define COMPAT_HOOK2(hook,args1,args2)\
-extern struct hook ## _t {	\
-	kmutex_t		mtx;\
-	kcondvar_t		cv;\
-	struct localcount	lc;\
-	pserialize_t		psz;\
-bool			hooked;\
-	int			(*f1)args1;			\
-	int			(*f2)args2;			\
-} hook __cacheline_aligned;
-
-#define COMPAT_SET_HOOK(hook, waitchan, func)			\
-static void hook ## _set(void);	\
-static void hook ## _set(void)	\
-{\
-\
-	KASSERT(!hook.hooked);	\
-\
-	hook.psz = pserialize_create();\
-	mutex_init(, MUTEX_DEFAULT, IPL_NONE);		\
-	cv_init(, waitchan);\
-	localcount_init();\
-	hook.f = func;		\
-\
-	/* Make sure it's initialized before anyone uses it */	\
-	membar_producer();	\
-\
-	/* Let them use it */	\
-	hook.hooked = true;	\
-}
-
-#define COMPAT_SET_HOOK2(hook, waitchan, func1, func2)		\
-static void hook ## _set(void);	\
-static void hook ## _set(void)	\
-{\
-\
-	KASSERT(!hook.hooked);	\
-\
-	hook.psz = pserialize_create();\
-	mutex_init(, MUTEX_DEFAULT, IPL_NONE);		\
-	cv_init(, waitchan);\
-	localcount_init();\
-	hook.f1 = func1;	\
-	hook.f2 = func2;	\
-\
-	/* Make sure it's initialized before anyone uses it */	\
-	membar_producer();	\
-\
-	/* Let them use it */	\
-	hook.hooked = true;	\
-}
-
-#define COMPAT_UNSET_HOOK(hook)	\
-static void (hook ## _unset)(void);\
-static void (hook ## _unset)(void)\
-{\
-\
-	KASSERT(kernconfig_is_held());\
-	KASSERT(hook.hooked);	\
-	KASSERT(hook.f);	\
-\
-	/* Prevent new localcount_acquire calls.  */		\
-	hook.hooked = false;	\
-\
-	/* Wait for existing localcount_acquire calls to drain.  */ \
-	pserialize_perform(hook.psz);\
-\
-	/* Wait for existing localcount references to drain.  */\
-	localcount_drain(, , );	\
-\
-	localcount_fini();\
-	cv_destroy();	\
-	mutex_destroy();\
-	pserialize_destroy(hook.psz);\
-}
-
-#define COMPAT_UNSET_HOOK2(hook)\
-static void (hook ## _unset)(void);\
-static void (hook ## _unset)(void)\
-{\
-\
-	KASSERT(kernconfig_is_held());\
-	KASSERT(hook.hooked);	\
-	KASSERT(hook.f1);	\
-	KASSERT(hook.f2);	\
-\
-	/* Prevent new localcount_acquire calls.  */		\
-	hook.hooked = false;	\
-\
-	/* Wait for existing localcount_acquire calls to drain.  */ \
-	pserialize_perform(hook.psz);\
-\
-	/* Wait for existing localcount references to drain.  */\
-	localcount_drain(, , );	\
-\
-	localcount_fini();\
-	cv_destroy();	\
-	mutex_destroy();\
-	pserialize_destroy(hook.psz);\
-}
-
-#define COMPAT_CALL_HOOK_DECL(hook, which, decl, args, default)	\
-int\
-hook ## _ ## which ## _call decl;
-#define COMPAT_CALL_HOOK(hook, which, decl, args, default)	\
-int\
-hook ## _ ## which ## _call decl\
-{\
-	bool hooked;		\
-	int error, s;		\
-\
-	s = pserialize_read_enter();\
-	hooked = hook.hooked;	\
-	if (hooked) {		\
-		membar_consumer();\
-		localcount_acquire();			\
-	}			\
-	pserialize_read_exit(s);\
-\
-	if (hooked) {		\
-		error = (*hook.which)args;			\
-		

CVS commit: src/sys/dev/hpc

2018-09-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Sep 18 02:58:10 UTC 2018

Modified Files:
src/sys/dev/hpc: hpckbd.c

Log Message:
Apply workaround introduced in r1.31 to hpcmips.

Fix kernel crash when console is attached. Now, my MC/R550 boots multiuser.

Thanks Masahiko Ito for encouraging me to do bisection to find this out.

XXX pullup-8, pullup-7


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/hpc/hpckbd.c

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

Modified files:

Index: src/sys/dev/hpc/hpckbd.c
diff -u src/sys/dev/hpc/hpckbd.c:1.32 src/sys/dev/hpc/hpckbd.c:1.33
--- src/sys/dev/hpc/hpckbd.c:1.32	Mon Aug  7 23:57:40 2017
+++ src/sys/dev/hpc/hpckbd.c	Tue Sep 18 02:58:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: hpckbd.c,v 1.32 2017/08/07 23:57:40 uwe Exp $ */
+/*	$NetBSD: hpckbd.c,v 1.33 2018/09/18 02:58:10 rin Exp $ */
 
 /*-
  * Copyright (c) 1999-2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hpckbd.c,v 1.32 2017/08/07 23:57:40 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hpckbd.c,v 1.33 2018/09/18 02:58:10 rin Exp $");
 
 #include 
 #include 
@@ -261,10 +261,11 @@ hpckbd_getevent(struct hpckbd_core* hc, 
 }
 
 
-#ifdef hpcsh
+#if defined(hpcsh) || defined(hpcmips)
 /*
- * XXX: Use the old wrong code for now as hpcsh attaches console very
- * early and it's convenient to be able to do early DDB on wscons.
+ * XXX: Use the old wrong code for now as hpcsh and hpcmips attach console very
+ * early when malloc(9) is not yet available. It is convenient to be able to do
+ * early DDB on wscons.
  */
 void
 hpckbd_keymap_setup(struct hpckbd_core *hc,
@@ -278,8 +279,10 @@ hpckbd_keymap_setup(struct hpckbd_core *
 	 * XXX The way this is done is really wrong.  The __UNCONST()
 	 * is a hint as to what is wrong.  This actually ends up modifying
 	 * initialized data which is marked "const".
+	 *
 	 * The reason we get away with it here is that on sh3 kernel
-	 * is directly mapped.
+	 * is directly mapped. For mips, read-only data is mapped
+	 * read/write at the moment.
 	 */
 	desc = (struct wscons_keydesc *)__UNCONST(hpckbd_keymapdata.keydesc);
 	for (i = 0; desc[i].name != 0; i++) {



CVS commit: src/sys/dev/usb

2018-09-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep 18 02:00:07 UTC 2018

Modified Files:
src/sys/dev/usb: ehci.c ehcivar.h

Log Message:
implement a gross hack to fix "boot -a" on systems with usb keyboards on
systems with ehci handover to uhci (and maybe ohci), and fix a similar
problem for "boot -s".

there is effort to ensure that all devices attached via USB are probed
before RB_ASKNAME or RB_SINGLE attempts to ask any questions on the console,
and largely this works, often by chance, today, for USB disks and root.
i've recently pushed this more into uhub and general USB device attachment
as well, and kept a config_pending reference across the first explore of
a bus.  these fix many issues with directly attached hubs.

however, on systems where devices connected to ehci ports are handed over
to a companion uhci or ohci port, it may not be the first, or even second,
bus explore that finds the device finally before attachment, and at this
point all config_pending references are dropped.

there is no direct communication between drivers, the potentials are
looked up but their device_t is only used for generic things like the name,
so informing the correct companion to expect a device and deal with the
config_pending references is not possible without some fairly ugly layer
violations or multi-level callbacks (eg, we have "ehci0", and usually an
the relevant companion, eg, "uhci2", but it is the uhub that uhci2 has
attached that will deal with the device attachment.)

with the above fixes to generic USB code, the disown happens during the
first explore.  the hack works by, at this point, checking if (a) root
is not mounted, (b) single user or ask name are set, and (c) if the hack
as not been triggered already.  if all 3 conditions are true, then a
config_pending_incr() is called and a callback is triggered for (default)
5 seconds to call config_pending_decr().  ehci detach pauses waiting for
this callback if scheduled.

this allows enough time for the uhub and the ukbd/wskbd to attach before
the RK_ASKROOT prompts appear.  testing shows it takes between 1.5 and
2 seconds for the keyboard to appear after the disown occurs.

Index: dev/usb/ehcivar.c
- new sc_compcallout, sc_compcallout, sc_complock, and a state for th
  handover hack.

Index: dev/usb/ehci.c
ehci_init():
- use aprint_normal_dev() instead of manual device_xname().
- initialise sc_compcallout, sc_compcallout, sc_complock, and sc_comp_state.
ehci_detach():
- if there are companion controllers, tear own the above, including waiting
  if there is a callback scheduled.
ehci_disown_callback():
- new callout to call config_pending_decr() in the the future.
  schedule this ca
ehci_disown_sched_callback():
- if booting to single user or asking names, call config_pending_incr() and
  schedule the callout above, default 5 second delay.
ehci_disown():
- if disowning a port call ehci_disown_sched_callback().


To generate a diff of this commit:
cvs rdiff -u -r1.264 -r1.265 src/sys/dev/usb/ehci.c
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/usb/ehcivar.h

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

Modified files:

Index: src/sys/dev/usb/ehci.c
diff -u src/sys/dev/usb/ehci.c:1.264 src/sys/dev/usb/ehci.c:1.265
--- src/sys/dev/usb/ehci.c:1.264	Sun Sep 16 20:21:56 2018
+++ src/sys/dev/usb/ehci.c	Tue Sep 18 02:00:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ehci.c,v 1.264 2018/09/16 20:21:56 mrg Exp $ */
+/*	$NetBSD: ehci.c,v 1.265 2018/09/18 02:00:06 mrg Exp $ */
 
 /*
  * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.264 2018/09/16 20:21:56 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.265 2018/09/18 02:00:06 mrg Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -75,6 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.2
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -446,8 +447,9 @@ ehci_init(ehci_softc_t *sc)
 	}
 	if (sc->sc_ncomp > 0) {
 		KASSERT(!(sc->sc_flags & EHCIF_ETTF));
-		aprint_normal("%s: %d companion controller%s, %d port%s%s",
-		device_xname(sc->sc_dev), sc->sc_ncomp,
+		aprint_normal_dev(sc->sc_dev,
+		"%d companion controller%s, %d port%s%s",
+		sc->sc_ncomp,
 		sc->sc_ncomp!=1 ? "s" : "",
 		EHCI_HCS_N_PCC(sparams),
 		EHCI_HCS_N_PCC(sparams)!=1 ? "s" : "",
@@ -459,6 +461,11 @@ ehci_init(ehci_softc_t *sc)
 device_xname(sc->sc_comps[i]));
 		}
 		aprint_normal("\n");
+
+		mutex_init(>sc_complock, MUTEX_DEFAULT, IPL_USB);
+		callout_init(>sc_compcallout, CALLOUT_MPSAFE);
+		cv_init(>sc_compcv, "ehciccv");
+		sc->sc_comp_state = CO_EARLY;
 	}
 	sc->sc_noport = EHCI_HCS_N_PORTS(sparams);
 	sc->sc_hasppc = EHCI_HCS_PPC(sparams);
@@ -1337,6 +1344,19 @@ ehci_detach(struct ehci_softc *sc, int f
 	if (rv != 0)
 		return rv;
 
+	if (sc->sc_ncomp > 0) {
+		mutex_enter(>sc_complock);
+		/* XXX try to halt callout instead of waiting */
+		while 

CVS commit: src/sys/dev/usb

2018-09-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep 18 01:36:44 UTC 2018

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

Log Message:
add config_pending usage to uhub and general USB device attachment.

- call config_pending_incr() and config_pending_decr() around attaching
  devices against "usbdevif" attribute.

uhub:
- convert sc_explorepending and sc_running to bool.  add new sc_first_explore.
- call config_pending_incr() at the start of uhub_attach().  dropped in
  uhub_explore(), if this is the first explore.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.226 -r1.227 src/sys/dev/usb/usb_subr.c

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

Modified files:

Index: src/sys/dev/usb/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.138 src/sys/dev/usb/uhub.c:1.139
--- src/sys/dev/usb/uhub.c:1.138	Thu Feb  1 09:50:48 2018
+++ src/sys/dev/usb/uhub.c	Tue Sep 18 01:36:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.138 2018/02/01 09:50:48 msaitoh Exp $	*/
+/*	$NetBSD: uhub.c,v 1.139 2018/09/18 01:36:44 mrg Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.138 2018/02/01 09:50:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.139 2018/09/18 01:36:44 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -113,9 +113,9 @@ struct uhub_softc {
 	uint8_t			*sc_statuspend;
 	uint8_t			*sc_status;
 	size_t			 sc_statuslen;
-	int			 sc_explorepending;
-
-	u_char			 sc_running;
+	bool			 sc_explorepending;
+	bool			 sc_first_explore;
+	bool			 sc_running;
 };
 
 #define UHUB_IS_HIGH_SPEED(sc) \
@@ -263,6 +263,8 @@ uhub_attach(device_t parent, device_t se
 	usb_endpoint_descriptor_t *ed;
 	struct usbd_tt *tts = NULL;
 
+	config_pending_incr(self);
+
 	UHUBHIST_FUNC(); UHUBHIST_CALLED();
 
 	sc->sc_dev = self;
@@ -284,14 +286,14 @@ uhub_attach(device_t parent, device_t se
 	if (err) {
 		DPRINTF("configuration failed, sc %#jx error %jd",
 		(uintptr_t)sc, err, 0, 0);
-		return;
+		goto bad2;
 	}
 
 	if (dev->ud_depth > USB_HUB_MAX_DEPTH) {
 		aprint_error_dev(self,
 		"hub depth (%d) exceeded, hub ignored\n",
 		USB_HUB_MAX_DEPTH);
-		return;
+		goto bad2;
 	}
 
 	/* Get hub descriptor. */
@@ -301,7 +303,7 @@ uhub_attach(device_t parent, device_t se
 	if (err) {
 		DPRINTF("getting hub descriptor failed, uhub%jd error %jd",
 		device_unit(self), err, 0, 0);
-		return;
+		goto bad2;
 	}
 
 	for (nremov = 0, port = 1; port <= nports; port++)
@@ -365,7 +367,7 @@ uhub_attach(device_t parent, device_t se
 
 	/* force initial scan */
 	memset(sc->sc_status, 0xff, sc->sc_statuslen);
-	sc->sc_explorepending = 1;
+	sc->sc_explorepending = true;
 
 	err = usbd_open_pipe_intr(iface, ed->bEndpointAddress,
 		  USBD_SHORT_XFER_OK|USBD_MPSAFE, >sc_ipipe, sc,
@@ -450,8 +452,8 @@ uhub_attach(device_t parent, device_t se
 		usbd_delay_ms(dev, pwrdly);
 
 	/* The usual exploration will finish the setup. */
-
-	sc->sc_running = 1;
+	sc->sc_running = true;
+	sc->sc_first_explore = true;
 
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
@@ -469,7 +471,8 @@ uhub_attach(device_t parent, device_t se
 		kmem_free(hub,
 		sizeof(*hub) + (nports-1) * sizeof(struct usbd_port));
 	dev->ud_hub = NULL;
-	return;
+ bad2:
+	config_pending_decr(self);
 }
 
 usbd_status
@@ -778,7 +781,7 @@ uhub_explore(struct usbd_device *dev)
 		}
 	}
 	mutex_enter(>sc_lock);
-	sc->sc_explorepending = 0;
+	sc->sc_explorepending = false;
 	for (int i = 0; i < sc->sc_statuslen; i++) {
 		if (sc->sc_statuspend[i] != 0) {
 			memcpy(sc->sc_status, sc->sc_statuspend,
@@ -789,6 +792,10 @@ uhub_explore(struct usbd_device *dev)
 		}
 	}
 	mutex_exit(>sc_lock);
+	if (sc->sc_first_explore) {
+		config_pending_decr(sc->sc_dev);
+		sc->sc_first_explore = false;
+	}
 
 	return USBD_NORMAL_COMPLETION;
 }
@@ -943,7 +950,7 @@ uhub_intr(struct usbd_xfer *xfer, void *
 		}
 
 		if (!sc->sc_explorepending) {
-			sc->sc_explorepending = 1;
+			sc->sc_explorepending = true;
 
 			memcpy(sc->sc_status, sc->sc_statuspend,
 			sc->sc_statuslen);

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.226 src/sys/dev/usb/usb_subr.c:1.227
--- src/sys/dev/usb/usb_subr.c:1.226	Thu Aug  2 06:09:04 2018
+++ src/sys/dev/usb/usb_subr.c	Tue Sep 18 01:36:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.226 2018/08/02 06:09:04 riastradh Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.227 2018/09/18 01:36:44 mrg Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.226 2018/08/02 06:09:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.227 

CVS commit: src/sys

2018-09-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep 18 01:25:09 UTC 2018

Modified Files:
src/sys/kern: kern_drvctl.c subr_autoconf.c
src/sys/sys: device.h systm.h

Log Message:
- move export for devmon_insert_vec into sys/device.h.
- export root_is_mounted for future USB RB_ASKNAME hack.
- make some things in subr_autoconf.c static
- move device_printf() prototype out from the middle of two sets of
  aprint_*() prototypes.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/kern/kern_drvctl.c
cvs rdiff -u -r1.262 -r1.263 src/sys/kern/subr_autoconf.c
cvs rdiff -u -r1.155 -r1.156 src/sys/sys/device.h
cvs rdiff -u -r1.277 -r1.278 src/sys/sys/systm.h

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

Modified files:

Index: src/sys/kern/kern_drvctl.c
diff -u src/sys/kern/kern_drvctl.c:1.43 src/sys/kern/kern_drvctl.c:1.44
--- src/sys/kern/kern_drvctl.c:1.43	Thu Nov 30 20:25:55 2017
+++ src/sys/kern/kern_drvctl.c	Tue Sep 18 01:25:09 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_drvctl.c,v 1.43 2017/11/30 20:25:55 christos Exp $ */
+/* $NetBSD: kern_drvctl.c,v 1.44 2018/09/18 01:25:09 mrg Exp $ */
 
 /*
  * Copyright (c) 2004
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.43 2017/11/30 20:25:55 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.44 2018/09/18 01:25:09 mrg Exp $");
 
 #include 
 #include 
@@ -107,7 +107,6 @@ static const struct fileops drvctl_fileo
 
 #define MAXLOCATORS 100
 
-extern int (*devmon_insert_vec)(const char *, prop_dictionary_t);
 static int (*saved_insert_vec)(const char *, prop_dictionary_t) = NULL;
 
 static int drvctl_command(struct lwp *, struct plistref *, u_long, int);

Index: src/sys/kern/subr_autoconf.c
diff -u src/sys/kern/subr_autoconf.c:1.262 src/sys/kern/subr_autoconf.c:1.263
--- src/sys/kern/subr_autoconf.c:1.262	Tue Jun 26 06:03:57 2018
+++ src/sys/kern/subr_autoconf.c	Tue Sep 18 01:25:09 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.262 2018/06/26 06:03:57 thorpej Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.263 2018/09/18 01:25:09 mrg Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.262 2018/06/26 06:03:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.263 2018/09/18 01:25:09 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -192,17 +192,17 @@ struct deferred_config {
 
 TAILQ_HEAD(deferred_config_head, deferred_config);
 
-struct deferred_config_head deferred_config_queue =
+static struct deferred_config_head deferred_config_queue =
 	TAILQ_HEAD_INITIALIZER(deferred_config_queue);
-struct deferred_config_head interrupt_config_queue =
+static struct deferred_config_head interrupt_config_queue =
 	TAILQ_HEAD_INITIALIZER(interrupt_config_queue);
-int interrupt_config_threads = 8;
-struct deferred_config_head mountroot_config_queue =
+static int interrupt_config_threads = 8;
+static struct deferred_config_head mountroot_config_queue =
 	TAILQ_HEAD_INITIALIZER(mountroot_config_queue);
-int mountroot_config_threads = 2;
+static int mountroot_config_threads = 2;
 static lwp_t **mountroot_config_lwpids;
 static size_t mountroot_config_lwpids_size;
-static bool root_is_mounted = false;
+bool root_is_mounted = false;
 
 static void config_process_deferred(struct deferred_config_head *, device_t);
 

Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.155 src/sys/sys/device.h:1.156
--- src/sys/sys/device.h:1.155	Tue Jun 26 06:03:57 2018
+++ src/sys/sys/device.h	Tue Sep 18 01:25:09 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.155 2018/06/26 06:03:57 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.156 2018/09/18 01:25:09 mrg Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -427,6 +427,7 @@ extern int booted_partition;		/* the par
 extern daddr_t booted_startblk;		/* or the start of a wedge */
 extern uint64_t booted_nblks;		/* and the size of that wedge */
 extern char *bootspec;			/* and the device/wedge name */
+extern bool root_is_mounted;		/* true if root is mounted */
 
 struct vnode *opendisk(device_t);
 int getdisksize(struct vnode *, uint64_t *, unsigned int *);
@@ -441,6 +442,7 @@ int	config_fini_component(struct cfdrive
 void	config_init_mi(void);
 void	drvctl_init(void);
 void	drvctl_fini(void);
+extern	int (*devmon_insert_vec)(const char *, prop_dictionary_t);
 
 int	config_cfdriver_attach(struct cfdriver *);
 int	config_cfdriver_detach(struct cfdriver *);

Index: src/sys/sys/systm.h
diff -u src/sys/sys/systm.h:1.277 src/sys/sys/systm.h:1.278
--- src/sys/sys/systm.h:1.277	Fri Aug 10 21:44:59 2018
+++ src/sys/sys/systm.h	Tue Sep 18 01:25:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: systm.h,v 1.277 2018/08/10 21:44:59 pgoyette Exp $	*/
+/*	$NetBSD: systm.h,v 1.278 2018/09/18 01:25:09 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1988, 1991, 1993
@@ -196,14 +196,14 

CVS commit: [pgoyette-compat] src/sys

2018-09-17 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue Sep 18 01:15:58 UTC 2018

Modified Files:
src/sys/compat/common [pgoyette-compat]: if_43.c usb_subr_30.c
src/sys/dev [pgoyette-compat]: bio.c ccd.c clockctl.c vnd.c
src/sys/dev/raidframe [pgoyette-compat]: rf_netbsdkintf.c
src/sys/dev/sysmon [pgoyette-compat]: sysmon_power.c
src/sys/dev/usb [pgoyette-compat]: ugen.c uhid.c usb.c
src/sys/dev/wscons [pgoyette-compat]: wsevent.c
src/sys/fs/puffs [pgoyette-compat]: puffs_msgif.c
src/sys/kern [pgoyette-compat]: compat_stub.c sys_module.c
src/sys/net [pgoyette-compat]: if_spppsubr.c rtsock.c
src/sys/opencrypto [pgoyette-compat]: cryptodev.c
src/sys/sys [pgoyette-compat]: compat_stub.h

Log Message:
Split the COMPAT_CALL_HOOK to separate the declaration from the
implementation.  Some hooks are called from multiple source files,
and the old method resulted in duplicate implementations.

Implement MP-safe hooks for the usb_subr_30 code.  Pass the helper
functions as arguments to the compat code so it does not have to
determine if the kernel contains usb code.


To generate a diff of this commit:
cvs rdiff -u -r1.14.2.2 -r1.14.2.3 src/sys/compat/common/if_43.c
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/compat/common/usb_subr_30.c
cvs rdiff -u -r1.13.16.2 -r1.13.16.3 src/sys/dev/bio.c
cvs rdiff -u -r1.175.2.5 -r1.175.2.6 src/sys/dev/ccd.c
cvs rdiff -u -r1.35.14.2 -r1.35.14.3 src/sys/dev/clockctl.c
cvs rdiff -u -r1.263.2.3 -r1.263.2.4 src/sys/dev/vnd.c
cvs rdiff -u -r1.356.2.3 -r1.356.2.4 src/sys/dev/raidframe/rf_netbsdkintf.c
cvs rdiff -u -r1.58.2.2 -r1.58.2.3 src/sys/dev/sysmon/sysmon_power.c
cvs rdiff -u -r1.139.2.2 -r1.139.2.3 src/sys/dev/usb/ugen.c
cvs rdiff -u -r1.101.2.2 -r1.101.2.3 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.168.2.3 -r1.168.2.4 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.37.2.3 -r1.37.2.4 src/sys/dev/wscons/wsevent.c
cvs rdiff -u -r1.101.10.3 -r1.101.10.4 src/sys/fs/puffs/puffs_msgif.c
cvs rdiff -u -r1.1.2.18 -r1.1.2.19 src/sys/kern/compat_stub.c
cvs rdiff -u -r1.23.2.10 -r1.23.2.11 src/sys/kern/sys_module.c
cvs rdiff -u -r1.179.2.4 -r1.179.2.5 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.238.2.7 -r1.238.2.8 src/sys/net/rtsock.c
cvs rdiff -u -r1.98.2.2 -r1.98.2.3 src/sys/opencrypto/cryptodev.c
cvs rdiff -u -r1.1.2.23 -r1.1.2.24 src/sys/sys/compat_stub.h

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

Modified files:

Index: src/sys/compat/common/if_43.c
diff -u src/sys/compat/common/if_43.c:1.14.2.2 src/sys/compat/common/if_43.c:1.14.2.3
--- src/sys/compat/common/if_43.c:1.14.2.2	Mon Sep 17 11:04:30 2018
+++ src/sys/compat/common/if_43.c	Tue Sep 18 01:15:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_43.c,v 1.14.2.2 2018/09/17 11:04:30 pgoyette Exp $	*/
+/*	$NetBSD: if_43.c,v 1.14.2.3 2018/09/18 01:15:57 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.14.2.2 2018/09/17 11:04:30 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.14.2.3 2018/09/18 01:15:57 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.
 #include 
 
 /* COMPAT_HOOK for replacing the cmdcvt() function */
+COMPAT_CALL_HOOK_DECL(ieee80211_get_ostats_20_hook, f, (int cmd), (cmd), cmd);
 COMPAT_CALL_HOOK(ieee80211_get_ostats_20_hook, f, (int cmd), (cmd), cmd);
 
 u_long 

Index: src/sys/compat/common/usb_subr_30.c
diff -u src/sys/compat/common/usb_subr_30.c:1.1.2.1 src/sys/compat/common/usb_subr_30.c:1.1.2.2
--- src/sys/compat/common/usb_subr_30.c:1.1.2.1	Thu Mar 29 23:23:03 2018
+++ src/sys/compat/common/usb_subr_30.c	Tue Sep 18 01:15:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr_30.c,v 1.1.2.1 2018/03/29 23:23:03 pgoyette Exp $	*/
+/*	$NetBSD: usb_subr_30.c,v 1.1.2.2 2018/09/18 01:15:57 pgoyette Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr_30.c,v 1.1.2.1 2018/03/29 23:23:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr_30.c,v 1.1.2.2 2018/09/18 01:15:57 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -126,7 +126,10 @@ usb_copy_old_devinfo(struct usb_device_i
 
 static int
 usbd_fill_deviceinfo_old(struct usbd_device *dev,
-struct usb_device_info_old *di, int usedev)
+struct usb_device_info_old *di, int usedev,
+void (*do_devinfo_vp)(struct usbd_device *, char *, size_t, char *,
+	size_t, int, int),
+int (*do_printBCD)(char *cp, size_t l, int bcd))
 {
 	struct usbd_port *p;
 	int i, j, err;
@@ -134,9 +137,9 @@ usbd_fill_deviceinfo_old(struct usbd_dev
 	di->udi_bus = device_unit(dev->ud_bus->ub_usbctl);
 	di->udi_addr = dev->ud_addr;
 	di->udi_cookie = dev->ud_cookie;
-	(*vec_usbd_devinfo_vp)(dev, di->udi_vendor, 

CVS commit: [pgoyette-compat] src/doc

2018-09-17 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue Sep 18 01:11:33 UTC 2018

Modified Files:
src/doc [pgoyette-compat]: TODO.compat-module

Log Message:
Update for having (mostly) finished the netbsd32 module split.

Renumber so each entry is unique.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.5 -r1.1.2.6 src/doc/TODO.compat-module

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

Modified files:

Index: src/doc/TODO.compat-module
diff -u src/doc/TODO.compat-module:1.1.2.5 src/doc/TODO.compat-module:1.1.2.6
--- src/doc/TODO.compat-module:1.1.2.5	Mon Sep 17 10:06:29 2018
+++ src/doc/TODO.compat-module	Tue Sep 18 01:11:33 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: TODO.compat-module,v 1.1.2.5 2018/09/17 10:06:29 pgoyette Exp $ */
+/* $NetBSD: TODO.compat-module,v 1.1.2.6 2018/09/18 01:11:33 pgoyette Exp $ */
 
 DONE
 
@@ -46,23 +46,23 @@ DONE
 11. Implemented a MP-safe mechanism for installing and removing function
 pointers.  Thanks to riastradh@ for the template code.
 
+12. Replace version-specific parts of the compat_netbsd32 module (and
+also the compat_netbsd32_sysv module) with individual modules.  Update
+dependencies accordingly.  (Done, but see #13 below.)
+
 
 TODO - Required for branch merge
 
-1.  Replace version-specific parts of the compat_netbsd32 module (and
-also the compat_netbsd32_sysv module) with individual modules.  Update
-dependencies accordingly.
-
-2.  Need to finish cleaning up the netbsd32 machine-dependent code, since
+13.  Need to finish cleaning up the netbsd32 machine-dependent code, since
 the MI code assumes that there's MD file available.
 
-3.  Still have some work to do to split the vnd_30 and vnd_50 compat
+14. Still have some work to do to split the vnd_30 and vnd_50 compat
 code into separate modules.
 
-4.  The ieee_80211 compat code needs to be verified to make sure it is
+15. The ieee_80211 compat code needs to be verified to make sure it is
 handling the if43_20 compat routine cvtcmd() correctly.
 
-5.  There are a few function pointers in netbsd32 module that need to
+16. There are a few function pointers in netbsd32 module that need to
 be converted to the new MP-safe mechanism.  See files
 	netbsd32_mod.c
 	netbsd32_module.c
@@ -72,11 +72,11 @@ TODO - Required for branch merge
 
 TODO - Not required for branch merge
 
-1.  Audit the entire code base for any remaining embedded #ifdef's for
+17. Audit the entire code base for any remaining embedded #ifdef's for
 COMPAT_xx.  When found, move the actual compat code into the compat
 hierarchy and replace originals with indirect (vectored) calls.
 
-2.  The rtsock compat code is a disaster, with rtsock_50.c #include-ing
+18. The rtsock compat code is a disaster, with rtsock_50.c #include-ing
 the main rtsock.c code with various manipulations of the COMPAT_50
 macro.  Once rtsock is separated, compat_14 references to rtsock_50
 routines needs to be verified.
@@ -86,7 +86,7 @@ TODO - Not required for branch merge
 the compat code can be executed, neither on the branch nor on
 HEAD.
 
-3.  The compat_60 module still needs some work for XEN systems.  We
+19. The compat_60 module still needs some work for XEN systems.  We
 probably need some build infrastructure changes to ensure that
 XEN (and, for i386, XEN-PAE) modules are build with the correct
 macros defined and with -I directories specified in the same order
@@ -94,7 +94,7 @@ TODO - Not required for branch merge
 prevents loading of micro-code updates for amd64 processors running
 XEN kernels.  This limitation also exists on HEAD.
 
-4.  There seems to be quite a bit of MD compat_xx code, in the various
+20. There seems to be quite a bit of MD compat_xx code, in the various
 sys/arch/ directories.  I haven't yet looked at any of this.  But it
 seems to me that the MI compat build infrastructure should have some
 mechanism to "reach over" to the MD code, #include a Makefile.inc file,
@@ -112,13 +112,13 @@ TODO - Not required for branch merge
 into the monolithic COMPAT module on HEAD.  Thus, its absence from
 any of the version-specific modules is not a regression.
 
-5.  For compat_50, in addition to rtsock there are some things in dev/vnd,
+21. For compat_50, in addition to rtsock there are some things in dev/vnd,
 dev/gpio, and dev/wscons/wsmux that I haven't been able to cleanly
 separate.  These items are not currently included in the monolithic
 COMPAT module on HEAD, so lack of integration on the branch is not a
 regression.
 
-6.  Even though the build mechanism has been switched back to using a
+22. Even though the build mechanism has been switched back to using a
 .a compat library, it might be useful to make it work with the .o
 library.
 



CVS commit: [jdolecek-ncqfixes] src/sys/dev/ata

2018-09-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Sep 17 20:54:41 UTC 2018

Modified Files:
src/sys/dev/ata [jdolecek-ncqfixes]: TODO.ncq ata.c ata_raid.c
ata_raid_adaptec.c ata_raid_intel.c ata_raid_jmicron.c
ata_raid_nvidia.c ata_raid_promise.c ata_raid_via.c ata_subr.c
ata_wdc.c ld_ataraid.c wd.c

Log Message:
convert from malloc()/free() to kmem_zalloc()/kmem_free()


To generate a diff of this commit:
cvs rdiff -u -r1.4.2.2 -r1.4.2.3 src/sys/dev/ata/TODO.ncq
cvs rdiff -u -r1.141.6.4 -r1.141.6.5 src/sys/dev/ata/ata.c
cvs rdiff -u -r1.40 -r1.40.4.1 src/sys/dev/ata/ata_raid.c
cvs rdiff -u -r1.10 -r1.10.6.1 src/sys/dev/ata/ata_raid_adaptec.c
cvs rdiff -u -r1.8 -r1.8.6.1 src/sys/dev/ata/ata_raid_intel.c \
src/sys/dev/ata/ata_raid_via.c
cvs rdiff -u -r1.6 -r1.6.6.1 src/sys/dev/ata/ata_raid_jmicron.c
cvs rdiff -u -r1.3 -r1.3.6.1 src/sys/dev/ata/ata_raid_nvidia.c
cvs rdiff -u -r1.12 -r1.12.6.1 src/sys/dev/ata/ata_raid_promise.c
cvs rdiff -u -r1.6.2.3 -r1.6.2.4 src/sys/dev/ata/ata_subr.c
cvs rdiff -u -r1.110.4.2 -r1.110.4.3 src/sys/dev/ata/ata_wdc.c
cvs rdiff -u -r1.45 -r1.45.4.1 src/sys/dev/ata/ld_ataraid.c
cvs rdiff -u -r1.441.2.2 -r1.441.2.3 src/sys/dev/ata/wd.c

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

Modified files:

Index: src/sys/dev/ata/TODO.ncq
diff -u src/sys/dev/ata/TODO.ncq:1.4.2.2 src/sys/dev/ata/TODO.ncq:1.4.2.3
--- src/sys/dev/ata/TODO.ncq:1.4.2.2	Fri Aug 31 19:23:54 2018
+++ src/sys/dev/ata/TODO.ncq	Mon Sep 17 20:54:41 2018
@@ -1,6 +1,7 @@
 jdolecek-ncqfixes goals:
 - make ata_xfer dynamically allocated using a pool
-  - fixes: queue is allocated regardless if there are any drives, fix? 
+  - will fix: queue is allocated regardless if there are any drives, fix? 
+  - malloc() -> kmem_zalloc() in ata_queue_alloc() once this is done
 - remove limit of queued ata_xfers, allow any number of pending xfers;
   this should fix kern/52614 AKA wdc-attached ATAPI cd(4)
 - remove the wd(4) flush condition, just allocate a dynamic ata_xfer

Index: src/sys/dev/ata/ata.c
diff -u src/sys/dev/ata/ata.c:1.141.6.4 src/sys/dev/ata/ata.c:1.141.6.5
--- src/sys/dev/ata/ata.c:1.141.6.4	Mon Sep 17 19:00:43 2018
+++ src/sys/dev/ata/ata.c	Mon Sep 17 20:54:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata.c,v 1.141.6.4 2018/09/17 19:00:43 jdolecek Exp $	*/
+/*	$NetBSD: ata.c,v 1.141.6.5 2018/09/17 20:54:41 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,14 +25,13 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.141.6.4 2018/09/17 19:00:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.141.6.5 2018/09/17 20:54:41 jdolecek Exp $");
 
 #include "opt_ata.h"
 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -292,7 +291,7 @@ atabusconfig(struct atabus_softc *atabus
 	cv_broadcast(_qcv);
 	mutex_exit(_qlock);
 
-	free(atabus_initq, M_DEVBUF);
+	kmem_free(atabus_initq, sizeof(*atabus_initq));
 
 	ata_delref(chp);
 
@@ -418,7 +417,7 @@ atabusconfig_thread(void *arg)
 	cv_broadcast(_qcv);
 	mutex_exit(_qlock);
 
-	free(atabus_initq, M_DEVBUF);
+	kmem_free(atabus_initq, sizeof(*atabus_initq));
 
 	ata_delref(chp);
 
@@ -569,7 +568,7 @@ atabus_attach(device_t parent, device_t 
 
 	RUN_ONCE(_init_ctrl, atabus_init);
 
-	initq = malloc(sizeof(*initq), M_DEVBUF, M_WAITOK);
+	initq = kmem_zalloc(sizeof(*initq), KM_SLEEP);
 	initq->atabus_sc = sc;
 	mutex_enter(_qlock);
 	TAILQ_INSERT_TAIL(_initq_head, initq, atabus_initq);
@@ -716,9 +715,8 @@ atabus_alloc_drives(struct ata_channel *
 	if (chp->ch_ndrives != ndrives)
 		atabus_free_drives(chp);
 	if (chp->ch_drive == NULL) {
-		chp->ch_drive = malloc(
-		sizeof(struct ata_drive_datas) * ndrives,
-		M_DEVBUF, M_NOWAIT | M_ZERO);
+		chp->ch_drive = kmem_zalloc(
+		sizeof(struct ata_drive_datas) * ndrives, KM_NOSLEEP);
 	}
 	if (chp->ch_drive == NULL) {
 	aprint_error_dev(chp->ch_atac->atac_dev,
@@ -761,8 +759,9 @@ atabus_free_drives(struct ata_channel *c
 
 	if (chp->ch_drive == NULL)
 		return;
+	kmem_free(chp->ch_drive,
+	sizeof(struct ata_drive_datas) * chp->ch_ndrives);
 	chp->ch_ndrives = 0;
-	free(chp->ch_drive, M_DEVBUF);
 	chp->ch_drive = NULL;
 }
 
@@ -2218,7 +2217,7 @@ atabus_rescan(device_t self, const char 
 		}
 	}
 
-	initq = malloc(sizeof(*initq), M_DEVBUF, M_WAITOK);
+	initq = kmem_zalloc(sizeof(*initq), KM_SLEEP);
 	initq->atabus_sc = sc;
 	mutex_enter(_qlock);
 	TAILQ_INSERT_TAIL(_initq_head, initq, atabus_initq);

Index: src/sys/dev/ata/ata_raid.c
diff -u src/sys/dev/ata/ata_raid.c:1.40 src/sys/dev/ata/ata_raid.c:1.40.4.1
--- src/sys/dev/ata/ata_raid.c:1.40	Fri Jun 22 09:06:04 2018
+++ src/sys/dev/ata/ata_raid.c	Mon Sep 17 20:54:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata_raid.c,v 1.40 2018/06/22 09:06:04 pgoyette Exp $	*/
+/*	$NetBSD: ata_raid.c,v 1.40.4.1 2018/09/17 20:54:41 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi 

CVS commit: src/sys/dev/ic

2018-09-17 Thread Aymeric Vincent
Module Name:src
Committed By:   aymeric
Date:   Mon Sep 17 20:25:49 UTC 2018

Modified Files:
src/sys/dev/ic: dwc_gmac.c dwc_gmac_reg.h dwc_gmac_var.h

Log Message:
Add support for the enhanced descriptors feature.

This makes "recent" dwc gmac controllers, as found e.g. on the Cyclone V, work.
The change was also tested working on an Allwinner A20 which doesn't have the
feature.

No negative reaction on port-arm.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/dev/ic/dwc_gmac.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/dwc_gmac_reg.h
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/ic/dwc_gmac_var.h

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

Modified files:

Index: src/sys/dev/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.52 src/sys/dev/ic/dwc_gmac.c:1.53
--- src/sys/dev/ic/dwc_gmac.c:1.52	Wed Jul 18 23:10:27 2018
+++ src/sys/dev/ic/dwc_gmac.c	Mon Sep 17 20:25:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac.c,v 1.52 2018/07/18 23:10:27 sevan Exp $ */
+/* $NetBSD: dwc_gmac.c,v 1.53 2018/09/17 20:25:49 aymeric Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.52 2018/07/18 23:10:27 sevan Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.53 2018/09/17 20:25:49 aymeric Exp $");
 
 /* #define	DWC_GMAC_DEBUG	1 */
 
@@ -100,6 +100,53 @@ static void dwc_gmac_rx_intr(struct dwc_
 static void dwc_gmac_setmulti(struct dwc_gmac_softc *sc);
 static int dwc_gmac_ifflags_cb(struct ethercom *);
 static uint32_t	bitrev32(uint32_t x);
+static void dwc_gmac_desc_set_owned_by_dev(struct dwc_gmac_dev_dmadesc *);
+static int  dwc_gmac_desc_is_owned_by_dev(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_std_set_len(struct dwc_gmac_dev_dmadesc *, int);
+static int  dwc_gmac_desc_std_get_len(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_std_tx_init_flags(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_std_tx_set_first_frag(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_std_tx_set_last_frag(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_std_rx_init_flags(struct dwc_gmac_dev_dmadesc *);
+static int  dwc_gmac_desc_std_rx_has_error(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_enh_set_len(struct dwc_gmac_dev_dmadesc *, int);
+static int  dwc_gmac_desc_enh_get_len(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_enh_tx_init_flags(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_enh_tx_set_first_frag(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_enh_tx_set_last_frag(struct dwc_gmac_dev_dmadesc *);
+static void dwc_gmac_desc_enh_rx_init_flags(struct dwc_gmac_dev_dmadesc *);
+static int  dwc_gmac_desc_enh_rx_has_error(struct dwc_gmac_dev_dmadesc *);
+
+static const struct dwc_gmac_desc_methods desc_methods_standard = {
+	.tx_init_flags = dwc_gmac_desc_std_tx_init_flags,
+	.tx_set_owned_by_dev = dwc_gmac_desc_set_owned_by_dev,
+	.tx_is_owned_by_dev = dwc_gmac_desc_is_owned_by_dev,
+	.tx_set_len = dwc_gmac_desc_std_set_len,
+	.tx_set_first_frag = dwc_gmac_desc_std_tx_set_first_frag,
+	.tx_set_last_frag = dwc_gmac_desc_std_tx_set_last_frag,
+	.rx_init_flags = dwc_gmac_desc_std_rx_init_flags,
+	.rx_set_owned_by_dev = dwc_gmac_desc_set_owned_by_dev,
+	.rx_is_owned_by_dev = dwc_gmac_desc_is_owned_by_dev,
+	.rx_set_len = dwc_gmac_desc_std_set_len,
+	.rx_get_len = dwc_gmac_desc_std_get_len,
+	.rx_has_error = dwc_gmac_desc_std_rx_has_error
+};
+
+static const struct dwc_gmac_desc_methods desc_methods_enhanced = {
+	.tx_init_flags = dwc_gmac_desc_enh_tx_init_flags,
+	.tx_set_owned_by_dev = dwc_gmac_desc_set_owned_by_dev,
+	.tx_is_owned_by_dev = dwc_gmac_desc_is_owned_by_dev,
+	.tx_set_len = dwc_gmac_desc_enh_set_len,
+	.tx_set_first_frag = dwc_gmac_desc_enh_tx_set_first_frag,
+	.tx_set_last_frag = dwc_gmac_desc_enh_tx_set_last_frag,
+	.rx_init_flags = dwc_gmac_desc_enh_rx_init_flags,
+	.rx_set_owned_by_dev = dwc_gmac_desc_set_owned_by_dev,
+	.rx_is_owned_by_dev = dwc_gmac_desc_is_owned_by_dev,
+	.rx_set_len = dwc_gmac_desc_enh_set_len,
+	.rx_get_len = dwc_gmac_desc_enh_get_len,
+	.rx_has_error = dwc_gmac_desc_enh_rx_has_error
+};
+
 
 #define	TX_DESC_OFFSET(N)	((AWGE_RX_RING_COUNT+(N)) \
 *sizeof(struct dwc_gmac_dev_dmadesc))
@@ -122,7 +169,7 @@ static uint32_t	bitrev32(uint32_t x);
 
 #define	AWIN_DEF_MAC_INTRMASK	\
 	(AWIN_GMAC_MAC_INT_TSI | AWIN_GMAC_MAC_INT_ANEG |	\
-	AWIN_GMAC_MAC_INT_LINKCHG | AWIN_GMAC_MAC_INT_RGSMII)
+	AWIN_GMAC_MAC_INT_LINKCHG)
 
 #ifdef DWC_GMAC_DEBUG
 static void dwc_gmac_dump_dma(struct dwc_gmac_softc *sc);
@@ -194,6 +241,12 @@ dwc_gmac_attach(struct dwc_gmac_softc *s
 	aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n",
 	ether_sprintf(enaddr));
 
+	if (bus_space_read_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_DMA_HWFEATURES) &
+	GMAC_DMA_FEAT_ENHANCED_DESC)
+		sc->sc_descm = _methods_enhanced;
+	

CVS commit: [jdolecek-ncqfixes] src/sys/dev

2018-09-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Sep 17 19:30:26 UTC 2018

Modified Files:
src/sys/dev/ata [jdolecek-ncqfixes]: atavar.h
src/sys/dev/ic [jdolecek-ncqfixes]: ahcisata_core.c mvsata.c siisata.c
src/sys/dev/scsipi [jdolecek-ncqfixes]: atapi_wdc.c

Log Message:
move ATAPI-only members of ata_xfer to an union struct to further save space


To generate a diff of this commit:
cvs rdiff -u -r1.99.2.3 -r1.99.2.4 src/sys/dev/ata/atavar.h
cvs rdiff -u -r1.62.2.3 -r1.62.2.4 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.41.2.2 -r1.41.2.3 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.35.6.3 -r1.35.6.4 src/sys/dev/ic/siisata.c
cvs rdiff -u -r1.129.6.2 -r1.129.6.3 src/sys/dev/scsipi/atapi_wdc.c

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

Modified files:

Index: src/sys/dev/ata/atavar.h
diff -u src/sys/dev/ata/atavar.h:1.99.2.3 src/sys/dev/ata/atavar.h:1.99.2.4
--- src/sys/dev/ata/atavar.h:1.99.2.3	Mon Sep 17 19:00:43 2018
+++ src/sys/dev/ata/atavar.h	Mon Sep 17 19:30:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: atavar.h,v 1.99.2.3 2018/09/17 19:00:43 jdolecek Exp $	*/
+/*	$NetBSD: atavar.h,v 1.99.2.4 2018/09/17 19:30:25 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -144,8 +144,6 @@ struct ata_xfer {
 	void	*c_databuf;		/* pointer to data buffer */
 	int	c_bcount;		/* byte count left */
 	int	c_skip;			/* bytes already transferred */
-	int	c_dscpoll;		/* counter for dsc polling (ATAPI) */
-	int	c_lenoff;		/* offset to c_bcount (ATAPI) */
 #define ATACH_ERR_ST(error, status)	((error) << 8 | (status))
 #define ATACH_ERR(val)			(((val) >> 8) & 0xff)
 #define ATACH_ST(val)			(((val) >> 0) & 0xff)
@@ -153,11 +151,16 @@ struct ata_xfer {
 	union {
 		struct ata_bio	c_bio;		/* ATA transfer */
 		struct ata_command c_ata_c;	/* ATA command */ 
-		struct scsipi_xfer *c_scsipi;	/* SCSI transfer */
+		struct {
+			struct scsipi_xfer *c_scsipi;	/* SCSI transfer */
+			int	c_dscpoll; /* counter for dsc polling (ATAPI) */
+			int	c_lenoff;  /* offset to c_bcount (ATAPI) */
+		} atapi;
 	} u;
 #define c_bio	u.c_bio
 #define c_ata_c	u.c_ata_c
-#define c_scsipi u.c_scsipi
+#define c_atapi u.atapi
+#define c_scsipi c_atapi.c_scsipi
 
 	/* Link on the command queue. */
 	SIMPLEQ_ENTRY(ata_xfer) c_xferchain;

Index: src/sys/dev/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.62.2.3 src/sys/dev/ic/ahcisata_core.c:1.62.2.4
--- src/sys/dev/ic/ahcisata_core.c:1.62.2.3	Mon Sep 17 18:36:13 2018
+++ src/sys/dev/ic/ahcisata_core.c	Mon Sep 17 19:30:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.62.2.3 2018/09/17 18:36:13 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.62.2.4 2018/09/17 19:30:25 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.3 2018/09/17 18:36:13 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.4 2018/09/17 19:30:25 jdolecek Exp $");
 
 #include 
 #include 
@@ -1877,11 +1877,11 @@ ahci_atapi_scsipi_request(struct scsipi_
 			xfer->c_flags |= C_POLL;
 		xfer->c_drive = drive;
 		xfer->c_flags |= C_ATAPI;
-		xfer->c_scsipi = sc_xfer;
 		xfer->c_databuf = sc_xfer->data;
 		xfer->c_bcount = sc_xfer->datalen;
 		xfer->ops = _atapi_xfer_ops;
-		xfer->c_dscpoll = 0;
+		xfer->c_scsipi = sc_xfer;
+		xfer->c_atapi.c_dscpoll = 0;
 		s = splbio();
 		ata_exec_xfer(atac->atac_channels[channel], xfer);
 #ifdef DIAGNOSTIC

Index: src/sys/dev/ic/mvsata.c
diff -u src/sys/dev/ic/mvsata.c:1.41.2.2 src/sys/dev/ic/mvsata.c:1.41.2.3
--- src/sys/dev/ic/mvsata.c:1.41.2.2	Mon Sep 17 18:36:14 2018
+++ src/sys/dev/ic/mvsata.c	Mon Sep 17 19:30:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.41.2.2 2018/09/17 18:36:14 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.41.2.3 2018/09/17 19:30:25 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.2 2018/09/17 18:36:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.3 2018/09/17 19:30:25 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -2092,11 +2092,11 @@ mvsata_atapi_scsipi_request(struct scsip
 			xfer->c_flags |= C_POLL;
 		xfer->c_drive = drive;
 		xfer->c_flags |= C_ATAPI;
-		xfer->c_scsipi = sc_xfer;
 		xfer->c_databuf = sc_xfer->data;
 		xfer->c_bcount = sc_xfer->datalen;
 		xfer->ops = _atapi_xfer_ops;
-		xfer->c_dscpoll = 0;
+		xfer->c_scsipi = sc_xfer;
+		xfer->c_atapi.c_dscpoll = 0;
 		s = splbio();
 		ata_exec_xfer(chp, xfer);
 #ifdef DIAGNOSTIC
@@ -2444,7 +2444,7 @@ again:
 			mvsata_atapi_reset(chp, xfer);
 			return 1;
 		}
-		xfer->c_lenoff = len - xfer->c_bcount;
+		xfer->c_atapi.c_lenoff = len - xfer->c_bcount;
 		if (xfer->c_bcount < len) {
 			aprint_error_dev(atac->atac_dev, "channel %d drive %d:"
 			" warning: write only %d of %d requested bytes\n",
@@ -2456,7 +2456,7 @@ 

CVS commit: [jdolecek-ncqfixes] src/sys/dev/ata

2018-09-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Sep 17 19:00:43 UTC 2018

Modified Files:
src/sys/dev/ata [jdolecek-ncqfixes]: ata.c ata_subr.c atavar.h

Log Message:
switch from TAILQ to SIMPLEQ for ata_xfer pending queue to save
space, don't need doubly linked queue


To generate a diff of this commit:
cvs rdiff -u -r1.141.6.3 -r1.141.6.4 src/sys/dev/ata/ata.c
cvs rdiff -u -r1.6.2.2 -r1.6.2.3 src/sys/dev/ata/ata_subr.c
cvs rdiff -u -r1.99.2.2 -r1.99.2.3 src/sys/dev/ata/atavar.h

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

Modified files:

Index: src/sys/dev/ata/ata.c
diff -u src/sys/dev/ata/ata.c:1.141.6.3 src/sys/dev/ata/ata.c:1.141.6.4
--- src/sys/dev/ata/ata.c:1.141.6.3	Mon Sep 17 18:36:13 2018
+++ src/sys/dev/ata/ata.c	Mon Sep 17 19:00:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata.c,v 1.141.6.3 2018/09/17 18:36:13 jdolecek Exp $	*/
+/*	$NetBSD: ata.c,v 1.141.6.4 2018/09/17 19:00:43 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.141.6.3 2018/09/17 18:36:13 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.141.6.4 2018/09/17 19:00:43 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -1062,10 +1062,10 @@ ata_exec_xfer(struct ata_channel *chp, s
 	 * recovery commands must be run immediatelly.
 	 */
 	if ((xfer->c_flags & C_RECOVERY) == 0)
-		TAILQ_INSERT_TAIL(>ch_queue->queue_xfer, xfer,
+		SIMPLEQ_INSERT_TAIL(>ch_queue->queue_xfer, xfer,
 		c_xferchain);
 	else
-		TAILQ_INSERT_HEAD(>ch_queue->queue_xfer, xfer,
+		SIMPLEQ_INSERT_HEAD(>ch_queue->queue_xfer, xfer,
 		c_xferchain);
 
 	/*
@@ -1073,7 +1073,7 @@ ata_exec_xfer(struct ata_channel *chp, s
 	 */
 	if ((xfer->c_flags & (C_POLL | C_WAIT)) ==  (C_POLL | C_WAIT)) {
 		while (chp->ch_queue->queue_active > 0 ||
-		TAILQ_FIRST(>ch_queue->queue_xfer) != xfer) {
+		SIMPLEQ_FIRST(>ch_queue->queue_xfer) != xfer) {
 			xfer->c_flags |= C_WAITACT;
 			cv_wait(>ch_queue->c_active, >ch_lock);
 			xfer->c_flags &= ~C_WAITACT;
@@ -1137,7 +1137,7 @@ again:
 	}
 
 	/* is there a xfer ? */
-	if ((xfer = TAILQ_FIRST(>ch_queue->queue_xfer)) == NULL) {
+	if ((xfer = SIMPLEQ_FIRST(>ch_queue->queue_xfer)) == NULL) {
 		ATADEBUG_PRINT(("%s(chp=%p): channel %d queue_xfer is empty\n",
 		__func__, chp, chp->ch_channel), DEBUG_XFERS);
 		goto out;
@@ -1207,6 +1207,8 @@ again:
 	else
 		CLR(chp->ch_flags, ATACH_NCQ);
 
+	SIMPLEQ_REMOVE_HEAD(>queue_xfer, c_xferchain);
+
 	ata_activate_xfer_locked(chp, xfer);
 
 	if (atac->atac_cap & ATAC_CAP_NOIRQ)
@@ -1275,7 +1277,6 @@ ata_activate_xfer_locked(struct ata_chan
 	KASSERT(chq->queue_active < chq->queue_openings);
 	KASSERT((chq->active_xfers_used & __BIT(xfer->c_slot)) == 0);
 
-	TAILQ_REMOVE(>queue_xfer, xfer, c_xferchain);
 	if ((xfer->c_flags & C_RECOVERY) == 0)
 		TAILQ_INSERT_TAIL(>active_xfers, xfer, c_activechain);
 	else {
@@ -1419,18 +1420,18 @@ ata_kill_pending(struct ata_drive_datas 
 {
 	struct ata_channel * const chp = drvp->chnl_softc;
 	struct ata_queue * const chq = chp->ch_queue;
-	struct ata_xfer *xfer, *xfernext;
+	struct ata_xfer *xfer;
 
 	ata_channel_lock(chp);
 
 	/* Kill all pending transfers */
-	TAILQ_FOREACH_SAFE(xfer, >queue_xfer, c_xferchain, xfernext) {
+	while ((xfer = SIMPLEQ_FIRST(>queue_xfer))) {
 		KASSERT(xfer->c_chp == chp);
 
 		if (xfer->c_drive != drvp->drive)
 			continue;
 
-		TAILQ_REMOVE(>ch_queue->queue_xfer, xfer, c_xferchain);
+		SIMPLEQ_REMOVE_HEAD(>ch_queue->queue_xfer, c_xferchain);
 
 		/*
 		 * Keep the lock, so that we get deadlock (and 'locking against

Index: src/sys/dev/ata/ata_subr.c
diff -u src/sys/dev/ata/ata_subr.c:1.6.2.2 src/sys/dev/ata/ata_subr.c:1.6.2.3
--- src/sys/dev/ata/ata_subr.c:1.6.2.2	Mon Sep 17 18:36:13 2018
+++ src/sys/dev/ata/ata_subr.c	Mon Sep 17 19:00:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata_subr.c,v 1.6.2.2 2018/09/17 18:36:13 jdolecek Exp $	*/
+/*	$NetBSD: ata_subr.c,v 1.6.2.3 2018/09/17 19:00:43 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ata_subr.c,v 1.6.2.2 2018/09/17 18:36:13 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata_subr.c,v 1.6.2.3 2018/09/17 19:00:43 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -70,7 +70,7 @@ void
 ata_queue_reset(struct ata_queue *chq)
 {
 	/* make sure that we can use polled commands */
-	TAILQ_INIT(>queue_xfer);
+	SIMPLEQ_INIT(>queue_xfer);
 	TAILQ_INIT(>active_xfers);
 	chq->queue_freeze = 0;
 	chq->queue_active = 0;

Index: src/sys/dev/ata/atavar.h
diff -u src/sys/dev/ata/atavar.h:1.99.2.2 src/sys/dev/ata/atavar.h:1.99.2.3
--- src/sys/dev/ata/atavar.h:1.99.2.2	Mon Sep 17 18:36:13 2018
+++ src/sys/dev/ata/atavar.h	Mon Sep 17 19:00:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: atavar.h,v 1.99.2.2 2018/09/17 18:36:13 jdolecek Exp $	*/
+/*	$NetBSD: atavar.h,v 1.99.2.3 2018/09/17 19:00:43 

CVS commit: [jdolecek-ncqfixes] src/sys/dev

2018-09-17 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Sep 17 18:36:14 UTC 2018

Modified Files:
src/sys/dev/ata [jdolecek-ncqfixes]: ata.c ata_subr.c ata_wdc.c
atavar.h
src/sys/dev/ic [jdolecek-ncqfixes]: ahcisata_core.c mvsata.c siisata.c
wdc.c
src/sys/dev/scsipi [jdolecek-ncqfixes]: atapi_wdc.c

Log Message:
move low-level protocol handlers hooks from ata_xfer to separate struct,
initialized statically

primarily to reduce ata_xfer struct size, but also improves readibility,
and enforces consistency


To generate a diff of this commit:
cvs rdiff -u -r1.141.6.2 -r1.141.6.3 src/sys/dev/ata/ata.c
cvs rdiff -u -r1.6.2.1 -r1.6.2.2 src/sys/dev/ata/ata_subr.c
cvs rdiff -u -r1.110.4.1 -r1.110.4.2 src/sys/dev/ata/ata_wdc.c
cvs rdiff -u -r1.99.2.1 -r1.99.2.2 src/sys/dev/ata/atavar.h
cvs rdiff -u -r1.62.2.2 -r1.62.2.3 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.41.2.1 -r1.41.2.2 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.35.6.2 -r1.35.6.3 src/sys/dev/ic/siisata.c
cvs rdiff -u -r1.288.6.1 -r1.288.6.2 src/sys/dev/ic/wdc.c
cvs rdiff -u -r1.129.6.1 -r1.129.6.2 src/sys/dev/scsipi/atapi_wdc.c

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

Modified files:

Index: src/sys/dev/ata/ata.c
diff -u src/sys/dev/ata/ata.c:1.141.6.2 src/sys/dev/ata/ata.c:1.141.6.3
--- src/sys/dev/ata/ata.c:1.141.6.2	Sat Sep  1 09:48:32 2018
+++ src/sys/dev/ata/ata.c	Mon Sep 17 18:36:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata.c,v 1.141.6.2 2018/09/01 09:48:32 jdolecek Exp $	*/
+/*	$NetBSD: ata.c,v 1.141.6.3 2018/09/17 18:36:13 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.141.6.2 2018/09/01 09:48:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.141.6.3 2018/09/17 18:36:13 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -1238,7 +1238,7 @@ ata_xfer_start(struct ata_xfer *xfer)
 
 	KASSERT(mutex_owned(>ch_lock));
 
-	rv = xfer->c_start(chp, xfer);
+	rv = xfer->ops->c_start(chp, xfer);
 	switch (rv) {
 	case ATASTART_STARTED:
 		/* nothing to do */
@@ -1250,14 +1250,14 @@ ata_xfer_start(struct ata_xfer *xfer)
 	case ATASTART_POLL:
 		/* can happen even in thread context for some ATAPI devices */
 		ata_channel_unlock(chp);
-		KASSERT(xfer->c_poll != NULL);
-		xfer->c_poll(chp, xfer);
+		KASSERT(xfer->ops != NULL && xfer->ops->c_poll != NULL);
+		xfer->ops->c_poll(chp, xfer);
 		ata_channel_lock(chp);
 		break;
 	case ATASTART_ABORT:
 		ata_channel_unlock(chp);
-		KASSERT(xfer->c_abort != NULL);
-		xfer->c_abort(chp, xfer);
+		KASSERT(xfer->ops != NULL && xfer->ops->c_abort != NULL);
+		xfer->ops->c_abort(chp, xfer);
 		ata_channel_lock(chp);
 		break;
 	}
@@ -1337,7 +1337,7 @@ ata_waitdrain_xfer_check(struct ata_chan
 	if (chp->ch_drive[drive].drive_flags & ATA_DRIVE_WAITDRAIN) {
 		ata_channel_unlock(chp);
 
-		(*xfer->c_kill_xfer)(chp, xfer, KILL_GONE);
+		xfer->ops->c_kill_xfer(chp, xfer, KILL_GONE);
 
 		ata_channel_lock(chp);
 		chp->ch_drive[drive].drive_flags &= ~ATA_DRIVE_WAITDRAIN;
@@ -1404,7 +1404,7 @@ ata_kill_active(struct ata_channel *chp,
 	KASSERT(mutex_owned(>ch_lock));
 
 	TAILQ_FOREACH_SAFE(xfer, >active_xfers, c_activechain, xfernext) {
-		(*xfer->c_kill_xfer)(xfer->c_chp, xfer, reason);
+		xfer->ops->c_kill_xfer(xfer->c_chp, xfer, reason);
 	}
 
 	if (flags & AT_RST_EMERG)
@@ -1438,7 +1438,7 @@ ata_kill_pending(struct ata_drive_datas 
 		 * data corruption, if the hook tries to call back into
 		 * middle layer for inactive xfer.
 		 */
-		(*xfer->c_kill_xfer)(chp, xfer, KILL_GONE_INACTIVE);
+		xfer->ops->c_kill_xfer(chp, xfer, KILL_GONE_INACTIVE);
 	}
 
 	/* Wait until all active transfers on the drive finish */

Index: src/sys/dev/ata/ata_subr.c
diff -u src/sys/dev/ata/ata_subr.c:1.6.2.1 src/sys/dev/ata/ata_subr.c:1.6.2.2
--- src/sys/dev/ata/ata_subr.c:1.6.2.1	Fri Aug 31 19:08:03 2018
+++ src/sys/dev/ata/ata_subr.c	Mon Sep 17 18:36:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata_subr.c,v 1.6.2.1 2018/08/31 19:08:03 jdolecek Exp $	*/
+/*	$NetBSD: ata_subr.c,v 1.6.2.2 2018/09/17 18:36:13 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ata_subr.c,v 1.6.2.1 2018/08/31 19:08:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata_subr.c,v 1.6.2.2 2018/09/17 18:36:13 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -326,6 +326,7 @@ ata_free_xfer(struct ata_channel *chp, s
 		goto out;
 	}
 
+	/* XXX move PIOBM and free_gw to deactivate? */
 #if NATA_PIOBM		/* XXX wdc dependent code */
 	if (xfer->c_flags & C_PIOBM) {
 		struct wdc_softc *wdc = CHAN_TO_WDC(chp);
@@ -386,7 +387,7 @@ ata_timeout(void *v)
 
 		/* Mark as timed out. Do not print anything, wd(4) will. */
 		xfer->c_flags |= C_TIMEOU;
-		xfer->c_intr(xfer->c_chp, xfer, 0);
+		xfer->ops->c_intr(xfer->c_chp, xfer, 0);
 	}
 
 	splx(s);

CVS commit: src/sys/arch/pmax/pmax

2018-09-17 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Mon Sep 17 16:52:29 UTC 2018

Modified Files:
src/sys/arch/pmax/pmax: dec_3min.c

Log Message:
Fix hangup after framebuffers are attached on 3MIN.  PR port-pmax/53611

Ok'ed by mrg@.  Should be pulled up to netbsd-7 and netbsd-8.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/pmax/pmax/dec_3min.c

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

Modified files:

Index: src/sys/arch/pmax/pmax/dec_3min.c
diff -u src/sys/arch/pmax/pmax/dec_3min.c:1.73 src/sys/arch/pmax/pmax/dec_3min.c:1.74
--- src/sys/arch/pmax/pmax/dec_3min.c:1.73	Mon Mar 24 19:31:40 2014
+++ src/sys/arch/pmax/pmax/dec_3min.c	Mon Sep 17 16:52:28 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_3min.c,v 1.73 2014/03/24 19:31:40 christos Exp $ */
+/* $NetBSD: dec_3min.c,v 1.74 2018/09/17 16:52:28 tsutsui Exp $ */
 
 /*
  * Copyright (c) 1998 Jonathan Stone.  All rights reserved.
@@ -70,7 +70,7 @@
 #define	__INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.73 2014/03/24 19:31:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.74 2018/09/17 16:52:28 tsutsui Exp $");
 
 #include 
 #include 
@@ -292,12 +292,7 @@ dec_3min_intr_establish(device_t dev, vo
 	case SYS_DEV_OPT0:
 	case SYS_DEV_OPT1:
 	case SYS_DEV_OPT2:
-		/* it's an option slot */
-		{
-		int s = splhigh();
-		s |= mask;
-		splx(s);
-		}
+		/* it's an option slot and handled via MIPS_INT_MASK_[012] */
 		break;
 	default:
 		/* it's a baseboard device going via the IOASIC */



CVS commit: src/sys/arch/x86/x86

2018-09-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Sep 17 15:53:06 UTC 2018

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Reduce the noise, reorder and rename some things for clarity.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/x86/x86/fpu.c

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

Modified files:

Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.46 src/sys/arch/x86/x86/fpu.c:1.47
--- src/sys/arch/x86/x86/fpu.c:1.46	Sun Jul  1 08:32:41 2018
+++ src/sys/arch/x86/x86/fpu.c	Mon Sep 17 15:53:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.46 2018/07/01 08:32:41 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.47 2018/09/17 15:53:06 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.46 2018/07/01 08:32:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.47 2018/09/17 15:53:06 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -121,9 +121,6 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.46
 #include 
 #include 
 
-/* Check some duplicate definitions match */
-#include 
-
 #ifdef XEN
 #define clts() HYPERVISOR_fpu_taskswitch(0)
 #define stts() HYPERVISOR_fpu_taskswitch(1)
@@ -134,108 +131,25 @@ bool x86_fpu_eager __read_mostly = false
 static uint32_t x86_fpu_mxcsr_mask __read_mostly = 0;
 
 static inline union savefpu *
-process_fpframe(struct lwp *lwp)
+lwp_fpuarea(struct lwp *l)
 {
-	struct pcb *pcb = lwp_getpcb(lwp);
+	struct pcb *pcb = lwp_getpcb(l);
 
 	return >pcb_savefpu;
 }
 
-/*
- * The following table is used to ensure that the FPE_... value
- * that is passed as a trapcode to the signal handler of the user
- * process does not have more than one bit set.
- *
- * Multiple bits may be set if SSE simd instructions generate errors
- * on more than one value or if the user process modifies the control
- * word while a status word bit is already set (which this is a sign
- * of bad coding).
- * We have no choise than to narrow them down to one bit, since we must
- * not send a trapcode that is not exactly one of the FPE_ macros.
- *
- * The mechanism has a static table with 127 entries.  Each combination
- * of the 7 FPU status word exception bits directly translates to a
- * position in this table, where a single FPE_... value is stored.
- * This FPE_... value stored there is considered the "most important"
- * of the exception bits and will be sent as the signal code.  The
- * precedence of the bits is based upon Intel Document "Numerical
- * Applications", Chapter "Special Computational Situations".
- *
- * The code to choose one of these values does these steps:
- * 1) Throw away status word bits that cannot be masked.
- * 2) Throw away the bits currently masked in the control word,
- *assuming the user isn't interested in them anymore.
- * 3) Reinsert status word bit 7 (stack fault) if it is set, which
- *cannot be masked but must be preserved.
- *'Stack fault' is a sub-class of 'invalid operation'.
- * 4) Use the remaining bits to point into the trapcode table.
- *
- * The 6 maskable bits in order of their preference, as stated in the
- * above referenced Intel manual:
- * 1  Invalid operation (FP_X_INV)
- * 1a   Stack underflow
- * 1b   Stack overflow
- * 1c   Operand of unsupported format
- * 1d   SNaN operand.
- * 2  QNaN operand (not an exception, irrelevant here)
- * 3  Any other invalid-operation not mentioned above or zero divide
- *  (FP_X_INV, FP_X_DZ)
- * 4  Denormal operand (FP_X_DNML)
- * 5  Numeric over/underflow (FP_X_OFL, FP_X_UFL)
- * 6  Inexact result (FP_X_IMP)
- *
- * NB: the above seems to mix up the mxscr error bits and the x87 ones.
- * They are in the same order, but there is no EN_SW_STACK_FAULT in the mmx
- * status.
- *
- * The table is nearly, but not quite, in bit order (ZERODIV and DENORM
- * are swapped).
- *
- * This table assumes that any stack fault is cleared - so that an INVOP
- * fault will only be reported as FLTSUB once.
- * This might not happen if the mask is being changed.
- */
-#define FPE_xxx1(f) (f & EN_SW_INVOP \
-		? (f & EN_SW_STACK_FAULT ? FPE_FLTSUB : FPE_FLTINV) \
-	: f & EN_SW_ZERODIV ? FPE_FLTDIV \
-	: f & EN_SW_DENORM ? FPE_FLTUND \
-	: f & EN_SW_OVERFLOW ? FPE_FLTOVF \
-	: f & EN_SW_UNDERFLOW ? FPE_FLTUND \
-	: f & EN_SW_PRECLOSS ? FPE_FLTRES \
-	: f & EN_SW_STACK_FAULT ? FPE_FLTSUB : 0)
-#define	FPE_xxx2(f)	FPE_xxx1(f),	FPE_xxx1((f + 1))
-#define	FPE_xxx4(f)	FPE_xxx2(f),	FPE_xxx2((f + 2))
-#define	FPE_xxx8(f)	FPE_xxx4(f),	FPE_xxx4((f + 4))
-#define	FPE_xxx16(f)	FPE_xxx8(f),	FPE_xxx8((f + 8))
-#define	FPE_xxx32(f)	FPE_xxx16(f),	FPE_xxx16((f + 16))
-static const uint8_t fpetable[128] = {
-	FPE_xxx32(0), FPE_xxx32(32), FPE_xxx32(64), FPE_xxx32(96)
-};
-#undef FPE_xxx1
-#undef FPE_xxx2
-#undef FPE_xxx4
-#undef FPE_xxx8
-#undef FPE_xxx16
-#undef FPE_xxx32
-
-/*
- * Init the FPU.
- *
- * This 

CVS commit: src/usr.sbin/sysinst/arch/sgimips

2018-09-17 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Mon Sep 17 15:19:29 UTC 2018

Modified Files:
src/usr.sbin/sysinst/arch/sgimips: md.c

Log Message:
Make sure to install a bootloader even on upgrade installation.

Fixes another part of port-sgimips/53583.
Should be pulled up (with rev 1.5) to netbsd-7 and netbsd-8.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/sysinst/arch/sgimips/md.c

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

Modified files:

Index: src/usr.sbin/sysinst/arch/sgimips/md.c
diff -u src/usr.sbin/sysinst/arch/sgimips/md.c:1.5 src/usr.sbin/sysinst/arch/sgimips/md.c:1.6
--- src/usr.sbin/sysinst/arch/sgimips/md.c:1.5	Sat Sep  8 18:10:35 2018
+++ src/usr.sbin/sysinst/arch/sgimips/md.c	Mon Sep 17 15:19:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.c,v 1.5 2018/09/08 18:10:35 martin Exp $	*/
+/*	$NetBSD: md.c,v 1.6 2018/09/17 15:19:29 tsutsui Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -220,7 +220,7 @@ md_pre_update(void)
 int
 md_update(void)
 {
-	md_post_newfs();
+	md_post_disklabel();
 	return 1;
 }
 



CVS commit: [pgoyette-compat] src/sys

2018-09-17 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Sep 17 11:04:31 UTC 2018

Modified Files:
src/sys/compat/common [pgoyette-compat]: bio_30.c clockctl_50.c if_43.c
if_spppsubr50.c kern_mod_80.c rtsock_14.c sysmon_power_40.c
vnd_30.c
src/sys/compat/net [pgoyette-compat]: if.h
src/sys/dev [pgoyette-compat]: bio.c clockctl.c vnd.c
src/sys/dev/raidframe [pgoyette-compat]: rf_compat50.c rf_compat80.c
rf_netbsdkintf.c
src/sys/dev/sysmon [pgoyette-compat]: sysmon_power.c
src/sys/dev/wscons [pgoyette-compat]: wsevent.c wsevent_50.c
src/sys/fs/puffs [pgoyette-compat]: puffs_compat.c puffs_msgif.c
puffs_sys.h
src/sys/kern [pgoyette-compat]: compat_stub.c sys_module.c
src/sys/net [pgoyette-compat]: if_spppsubr.c rtsock.c
src/sys/opencrypto [pgoyette-compat]: cryptodev.c ocryptodev.c
src/sys/sys [pgoyette-compat]: compat_stub.h

Log Message:
Adapt (most of) the indirect function pointers to the new MP-safe
mechanism.  Still remaining are the compat_netbsd32 stuff, and
some usb subroutines.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/compat/common/bio_30.c \
src/sys/compat/common/clockctl_50.c src/sys/compat/common/if_spppsubr50.c \
src/sys/compat/common/sysmon_power_40.c src/sys/compat/common/vnd_30.c
cvs rdiff -u -r1.14.2.1 -r1.14.2.2 src/sys/compat/common/if_43.c
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/sys/compat/common/kern_mod_80.c
cvs rdiff -u -r1.5.14.1 -r1.5.14.2 src/sys/compat/common/rtsock_14.c
cvs rdiff -u -r1.4 -r1.4.14.1 src/sys/compat/net/if.h
cvs rdiff -u -r1.13.16.1 -r1.13.16.2 src/sys/dev/bio.c
cvs rdiff -u -r1.35.14.1 -r1.35.14.2 src/sys/dev/clockctl.c
cvs rdiff -u -r1.263.2.2 -r1.263.2.3 src/sys/dev/vnd.c
cvs rdiff -u -r1.3.2.2 -r1.3.2.3 src/sys/dev/raidframe/rf_compat50.c
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/raidframe/rf_compat80.c
cvs rdiff -u -r1.356.2.2 -r1.356.2.3 src/sys/dev/raidframe/rf_netbsdkintf.c
cvs rdiff -u -r1.58.2.1 -r1.58.2.2 src/sys/dev/sysmon/sysmon_power.c
cvs rdiff -u -r1.37.2.2 -r1.37.2.3 src/sys/dev/wscons/wsevent.c
cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/sys/dev/wscons/wsevent_50.c
cvs rdiff -u -r1.4.16.1 -r1.4.16.2 src/sys/fs/puffs/puffs_compat.c
cvs rdiff -u -r1.101.10.2 -r1.101.10.3 src/sys/fs/puffs/puffs_msgif.c
cvs rdiff -u -r1.90.16.1 -r1.90.16.2 src/sys/fs/puffs/puffs_sys.h
cvs rdiff -u -r1.1.2.17 -r1.1.2.18 src/sys/kern/compat_stub.c
cvs rdiff -u -r1.23.2.9 -r1.23.2.10 src/sys/kern/sys_module.c
cvs rdiff -u -r1.179.2.3 -r1.179.2.4 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.238.2.6 -r1.238.2.7 src/sys/net/rtsock.c
cvs rdiff -u -r1.98.2.1 -r1.98.2.2 src/sys/opencrypto/cryptodev.c
cvs rdiff -u -r1.11.2.1 -r1.11.2.2 src/sys/opencrypto/ocryptodev.c
cvs rdiff -u -r1.1.2.22 -r1.1.2.23 src/sys/sys/compat_stub.h

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

Modified files:

Index: src/sys/compat/common/bio_30.c
diff -u src/sys/compat/common/bio_30.c:1.1.2.1 src/sys/compat/common/bio_30.c:1.1.2.2
--- src/sys/compat/common/bio_30.c:1.1.2.1	Wed Mar 28 04:18:24 2018
+++ src/sys/compat/common/bio_30.c	Mon Sep 17 11:04:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bio_30.c,v 1.1.2.1 2018/03/28 04:18:24 pgoyette Exp $ */
+/*	$NetBSD: bio_30.c,v 1.1.2.2 2018/09/17 11:04:30 pgoyette Exp $ */
 /*	$OpenBSD: bio.c,v 1.9 2007/03/20 02:35:55 marco Exp $	*/
 
 /*
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bio_30.c,v 1.1.2.1 2018/03/28 04:18:24 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bio_30.c,v 1.1.2.2 2018/09/17 11:04:30 pgoyette Exp $");
 
 #include 
 #include 
@@ -88,16 +88,19 @@ compat_30_bio(void *cookie, u_long cmd, 
 	}
 }
 
+COMPAT_SET_HOOK(compat_bio_30_hook, "bio_30", compat_30_bio);
+COMPAT_UNSET_HOOK(compat_bio_30_hook);
+
 void
 bio_30_init(void)
 {
 
-	compat_bio_30 = compat_30_bio;
+	compat_bio_30_hook_set();
 }
 
 void
 bio_30_fini(void)
 {
 
-	compat_bio_30 = (void *)enosys;
+	compat_bio_30_hook_unset();
 }
Index: src/sys/compat/common/clockctl_50.c
diff -u src/sys/compat/common/clockctl_50.c:1.1.2.1 src/sys/compat/common/clockctl_50.c:1.1.2.2
--- src/sys/compat/common/clockctl_50.c:1.1.2.1	Wed Mar 21 04:48:31 2018
+++ src/sys/compat/common/clockctl_50.c	Mon Sep 17 11:04:30 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: clockctl_50.c,v 1.1.2.1 2018/03/21 04:48:31 pgoyette Exp $ */
+/*  $NetBSD: clockctl_50.c,v 1.1.2.2 2018/09/17 11:04:30 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clockctl_50.c,v 1.1.2.1 2018/03/21 04:48:31 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clockctl_50.c,v 1.1.2.2 2018/09/17 11:04:30 pgoyette Exp $");
 
 #include 
 #include 
@@ -122,16 +122,19 @@ compat50_clockctlioctl(dev_t dev, u_long
 	return (error);
 }
 
+COMPAT_SET_HOOK(clockctl_ioctl_50_hook, "clk_50", 

CVS commit: [pgoyette-compat] src/doc

2018-09-17 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Sep 17 10:06:29 UTC 2018

Modified Files:
src/doc [pgoyette-compat]: TODO.compat-module

Log Message:
Update for recent work and recent discoveries


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/doc/TODO.compat-module

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

Modified files:

Index: src/doc/TODO.compat-module
diff -u src/doc/TODO.compat-module:1.1.2.4 src/doc/TODO.compat-module:1.1.2.5
--- src/doc/TODO.compat-module:1.1.2.4	Fri Sep 14 06:21:17 2018
+++ src/doc/TODO.compat-module	Mon Sep 17 10:06:29 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: TODO.compat-module,v 1.1.2.4 2018/09/14 06:21:17 pgoyette Exp $ */
+/* $NetBSD: TODO.compat-module,v 1.1.2.5 2018/09/17 10:06:29 pgoyette Exp $ */
 
 DONE
 
@@ -43,6 +43,9 @@ DONE
 10. Separated COMPAT_BSDPTY stuff, allowing the COMPAT_60 module to be
 built regardless.
 
+11. Implemented a MP-safe mechanism for installing and removing function
+pointers.  Thanks to riastradh@ for the template code.
+
 
 TODO - Required for branch merge
 
@@ -50,10 +53,21 @@ TODO - Required for branch merge
 also the compat_netbsd32_sysv module) with individual modules.  Update
 dependencies accordingly.
 
-2.  Wherever we have vectors function calls, we need to protect all uses
-of the vector using localcount(9).  And when unloading a module, we
-need to localcount_drain() after replacing the function pointer but
-before letting the module disappear.
+2.  Need to finish cleaning up the netbsd32 machine-dependent code, since
+the MI code assumes that there's MD file available.
+
+3.  Still have some work to do to split the vnd_30 and vnd_50 compat
+code into separate modules.
+
+4.  The ieee_80211 compat code needs to be verified to make sure it is
+handling the if43_20 compat routine cvtcmd() correctly.
+
+5.  There are a few function pointers in netbsd32 module that need to
+be converted to the new MP-safe mechanism.  See files
+	netbsd32_mod.c
+	netbsd32_module.c
+	netbsd32_compat_80.[ch]
+	amd64's machdep.c and machdep_16.c
 
 
 TODO - Not required for branch merge



CVS commit: src/sys/dev/usb

2018-09-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep 17 08:27:42 UTC 2018

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

Log Message:
reorder some struct members to remove holes.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/usb/uhcivar.h

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

Modified files:

Index: src/sys/dev/usb/uhcivar.h
diff -u src/sys/dev/usb/uhcivar.h:1.55 src/sys/dev/usb/uhcivar.h:1.56
--- src/sys/dev/usb/uhcivar.h:1.55	Thu Aug  9 06:26:47 2018
+++ src/sys/dev/usb/uhcivar.h	Mon Sep 17 08:27:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhcivar.h,v 1.55 2018/08/09 06:26:47 mrg Exp $	*/
+/*	$NetBSD: uhcivar.h,v 1.56 2018/09/17 08:27:41 mrg Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -170,8 +170,8 @@ typedef struct uhci_softc {
 
 	pool_cache_t sc_xferpool;	/* free xfer pool */
 
-	uint8_t sc_saved_sof;
 	uint16_t sc_saved_frnum;
+	uint8_t sc_saved_sof;
 
 	char sc_isreset;
 	char sc_suspend;



CVS commit: src/sys/netinet

2018-09-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Sep 17 08:11:27 UTC 2018

Modified Files:
src/sys/netinet: ip_reass.c

Log Message:
Kick fragments that would introduce several !MFFs in a reassembly chain.

The problem arises if we receive three fragments of the kind

3.  A -> has MFF
1.  B -> doesn't have MFF
2.  C -> doesn't have MFF

Because of the received order B->C->A, we don't see that B is !MFF, and
therefore that there is a problem in this chain.

Now we do two checks, and drop us if:

 * there is a fragment preceding us, and this fragment is !MFF, or
 * there is a fragment following us, and we are !MFF

Spotted a long time ago.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netinet/ip_reass.c

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

Modified files:

Index: src/sys/netinet/ip_reass.c
diff -u src/sys/netinet/ip_reass.c:1.19 src/sys/netinet/ip_reass.c:1.20
--- src/sys/netinet/ip_reass.c:1.19	Mon Sep 17 06:01:36 2018
+++ src/sys/netinet/ip_reass.c	Mon Sep 17 08:11:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $	*/
+/*	$NetBSD: ip_reass.c,v 1.20 2018/09/17 08:11:27 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.20 2018/09/17 08:11:27 maxv Exp $");
 
 #include 
 #include 
@@ -287,9 +287,13 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	}
 
 	/*
-	 * If there is a preceding segment, it may provide some of our
-	 * data already.  If so, drop the data from the incoming segment.
-	 * If it provides all of our data, drop us.
+	 * Look at the preceding segment.
+	 *
+	 * If it provides some of our data already, in part or entirely, trim
+	 * us or drop us.
+	 *
+	 * If a preceding segment exists, and was marked as the last segment,
+	 * drop us.
 	 */
 	if (p != NULL) {
 		i = p->ipqe_off + p->ipqe_len - ipqe->ipqe_off;
@@ -302,10 +306,17 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 			ipqe->ipqe_len = ipqe->ipqe_len - i;
 		}
 	}
+	if (p != NULL && !p->ipqe_mff) {
+		goto dropfrag;
+	}
 
 	/*
-	 * While we overlap succeeding segments trim them or, if they are
-	 * completely covered, dequeue them.
+	 * Look at the segments that follow.
+	 *
+	 * If we cover them, in part or entirely, trim them or dequeue them.
+	 *
+	 * If a following segment exists, and we are marked as the last
+	 * segment, drop us.
 	 */
 	while (q != NULL) {
 		i = ipqe->ipqe_off + ipqe->ipqe_len - q->ipqe_off;
@@ -326,6 +337,9 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 		ip_nfrags--;
 		q = nq;
 	}
+	if (q != NULL && !ipqe->ipqe_mff) {
+		goto dropfrag;
+	}
 
 insert:
 	/*



CVS commit: src/sys/netinet

2018-09-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Sep 17 06:01:36 UTC 2018

Modified Files:
src/sys/netinet: ip_reass.c

Log Message:
Hold ip_off and ip_len in the fragment entry, instead of always reading
the associated mbuf (and converting to host order). This reduces the
cache/TLB misses when processing long lists.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/netinet/ip_reass.c

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

Modified files:

Index: src/sys/netinet/ip_reass.c
diff -u src/sys/netinet/ip_reass.c:1.18 src/sys/netinet/ip_reass.c:1.19
--- src/sys/netinet/ip_reass.c:1.18	Tue Jul 10 15:46:58 2018
+++ src/sys/netinet/ip_reass.c	Mon Sep 17 06:01:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_reass.c,v 1.18 2018/07/10 15:46:58 maxv Exp $	*/
+/*	$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.18 2018/07/10 15:46:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $");
 
 #include 
 #include 
@@ -80,6 +80,8 @@ typedef struct ipfr_qent {
 	struct ip *		ipqe_ip;
 	struct mbuf *		ipqe_m;
 	bool			ipqe_mff;
+	uint16_t		ipqe_off;
+	uint16_t		ipqe_len;
 } ipfr_qent_t;
 
 TAILQ_HEAD(ipfr_qent_head, ipfr_qent);
@@ -215,7 +217,7 @@ ip_nmbclusters_changed(void)
 static struct mbuf *
 ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t *fp, const u_int hash)
 {
-	struct ip *ip = ipqe->ipqe_ip, *qip;
+	struct ip *ip = ipqe->ipqe_ip;
 	const int hlen = ip->ip_hl << 2;
 	struct mbuf *m = ipqe->ipqe_m, *t;
 	int ipsecflags = m->m_flags & (M_DECRYPTED|M_AUTHIPHDR);
@@ -230,16 +232,6 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	m->m_data += hlen;
 	m->m_len -= hlen;
 
-#ifdef	notyet
-	/* Make sure fragment limit is up-to-date. */
-	CHECK_NMBCLUSTER_PARAMS();
-
-	/* If we have too many fragments, drop the older half. */
-	if (ip_nfrags >= ip_maxfrags) {
-		ip_reass_drophalf(void);
-	}
-#endif
-
 	/*
 	 * We are about to add a fragment; increment frag count.
 	 */
@@ -255,9 +247,9 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 		 * never accept fragments  b) if maxfrag is -1, accept
 		 * all fragments without limitation.
 		 */
-		if (ip_maxfragpackets < 0)
-			;
-		else if (ip_nfragpackets >= ip_maxfragpackets) {
+		if (ip_maxfragpackets < 0) {
+			/* no limit */
+		} else if (ip_nfragpackets >= ip_maxfragpackets) {
 			goto dropfrag;
 		}
 		fp = malloc(sizeof(ipfr_queue_t), M_FTABLE, M_NOWAIT);
@@ -285,7 +277,7 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	 * Find a segment which begins after this one does.
 	 */
 	TAILQ_FOREACH(q, >ipq_fragq, ipqe_q) {
-		if (ntohs(q->ipqe_ip->ip_off) > ntohs(ip->ip_off))
+		if (q->ipqe_off > ipqe->ipqe_off)
 			break;
 	}
 	if (q != NULL) {
@@ -300,15 +292,14 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	 * If it provides all of our data, drop us.
 	 */
 	if (p != NULL) {
-		i = ntohs(p->ipqe_ip->ip_off) + ntohs(p->ipqe_ip->ip_len) -
-		ntohs(ip->ip_off);
+		i = p->ipqe_off + p->ipqe_len - ipqe->ipqe_off;
 		if (i > 0) {
-			if (i >= ntohs(ip->ip_len)) {
+			if (i >= ipqe->ipqe_len) {
 goto dropfrag;
 			}
 			m_adj(ipqe->ipqe_m, i);
-			ip->ip_off = htons(ntohs(ip->ip_off) + i);
-			ip->ip_len = htons(ntohs(ip->ip_len) - i);
+			ipqe->ipqe_off = ipqe->ipqe_off + i;
+			ipqe->ipqe_len = ipqe->ipqe_len - i;
 		}
 	}
 
@@ -317,17 +308,13 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	 * completely covered, dequeue them.
 	 */
 	while (q != NULL) {
-		size_t end;
-
-		qip = q->ipqe_ip;
-		end = ntohs(ip->ip_off) + ntohs(ip->ip_len);
-		if (end <= ntohs(qip->ip_off)) {
+		i = ipqe->ipqe_off + ipqe->ipqe_len - q->ipqe_off;
+		if (i <= 0) {
 			break;
 		}
-		i = end - ntohs(qip->ip_off);
-		if (i < ntohs(qip->ip_len)) {
-			qip->ip_len = htons(ntohs(qip->ip_len) - i);
-			qip->ip_off = htons(ntohs(qip->ip_off) + i);
+		if (i < q->ipqe_len) {
+			q->ipqe_off = q->ipqe_off + i;
+			q->ipqe_len = q->ipqe_len - i;
 			m_adj(q->ipqe_m, i);
 			break;
 		}
@@ -351,12 +338,11 @@ insert:
 	}
 	next = 0;
 	TAILQ_FOREACH(q, >ipq_fragq, ipqe_q) {
-		qip = q->ipqe_ip;
-		if (ntohs(qip->ip_off) != next) {
+		if (q->ipqe_off != next) {
 			mutex_exit(_lock);
 			return NULL;
 		}
-		next += ntohs(qip->ip_len);
+		next += q->ipqe_len;
 	}
 	p = TAILQ_LAST(>ipq_fragq, ipfr_qent_head);
 	if (p->ipqe_mff) {
@@ -652,13 +638,6 @@ ip_reass_packet(struct mbuf **m0)
 		return EINVAL;
 	}
 
-	/*
-	 * Adjust total IP length to not reflect header and convert
-	 * offset of this to bytes.  XXX: clobbers struct ip.
-	 */
-	ip->ip_len = htons(flen);
-	ip->ip_off = htons(off);
-
 	/* Look for queue of fragments of this datagram. */
 	mutex_enter(_lock);
 	hash = IPREASS_HASH(ip->ip_src.s_addr, ip->ip_id);
@@ -703,6 +682,8 @@ ip_reass_packet(struct mbuf **m0)
 	ipqe->ipqe_mff = mff;
 	ipqe->ipqe_m = m;
 	ipqe->ipqe_ip = ip;
+