From t.ichinoseki@nifty.com  Fri May 10 08:15:37 2002
Return-Path: <t.ichinoseki@nifty.com>
Received: from mail504.nifty.com (mail504.nifty.com [202.248.37.212])
	by hub.freebsd.org (Postfix) with ESMTP id 21A5337B409
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 10 May 2002 08:15:35 -0700 (PDT)
Received: from localhost
	by mail504.nifty.com (8.12.3/3.7W-02/25/02) with ESMTP id g4AFFADM025799
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 11 May 2002 00:15:10 +0900
Message-Id: <20020511.001016.74758161.toshi@altair.weganet.jp>
Date: Sat, 11 May 2002 00:10:16 +0900 (JST)
From: Toshikazu ICHINOSEKI <t.ichinoseki@nifty.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] can't go single user mode after usb mouse attached

>Number:         37928
>Category:       kern
>Synopsis:       [PATCH] can't go single user mode after usb mouse attached
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    joe
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 10 08:20:01 PDT 2002
>Closed-Date:    Wed Oct 02 11:10:20 PDT 2002
>Last-Modified:  Wed Oct 02 11:10:20 PDT 2002
>Originator:     Toshikazu Ichinoseki
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD altair 5.0-CURRENT FreeBSD 5.0-CURRENT #33: Fri May 10 21:22:34 JST 2002 toshi@altair:/usr/src/sys/i386/compile/ALTAIR  i386

Machine: Aopen AX59pro + AMD K6-2 450MHz + 512MB Mem
	     (Chip set is Apollo MVP3, uhci0: <VIA 83C572 USB controller>)

>Description:
	When I try to go single user mode after usb mouse attached, I get
	following message on console:

	init: some process would not die; ps axl advised
	init: can't get /dev/console for controlling terminal: Operation not permitted.
	<This message repeats until I reboot with ctrl+alt+delete.>

	In DDB, ps shows that moused sleeps with wmesg "uhciab". This
	means uhci driver sleeps in uhci_abort_xfer() and is not waken
	up.


>How-To-Repeat:
	Whenever I try to go single user mode, after usb mouse is attached .

>Fix:
	Following patch fixes this problem. And I can use HP Diskjet 957c
	USB printer after this patch applied. Before I apply this patch,
	lpr fails to open /dev/ulpt0, so I can print nothing.

	I don't have a FreeBSD box which has ohci device, so patch to
	ohci.c and ohciver.h is not tested.

	On recent change to usb_port.h, USB_USE_SOFTINTR is	defined.
	Patched uhci driver works whether USB_USE_SOFTINTR is defined or
	not.

------------------------------------------------------------
Index: ohci.c
===================================================================
RCS file: /local/cvsroot/src/sys/dev/usb/ohci.c,v
retrieving revision 1.104
diff -u -r1.104 ohci.c
--- ohci.c	29 Apr 2002 16:23:14 -0000	1.104
+++ ohci.c	9 May 2002 15:05:30 -0000
@@ -140,6 +140,7 @@
 #endif
 Static usbd_status	ohci_open(usbd_pipe_handle);
 Static void		ohci_poll(struct usbd_bus *);
+Static void		ohci_softintr_do_wakeup(void *ident);
 Static void		ohci_softintr(void *);
 Static void		ohci_waitintr(ohci_softc_t *, usbd_xfer_handle);
 Static void		ohci_add_done(ohci_softc_t *, ohci_physaddr_t);
@@ -891,6 +892,7 @@
 #endif
 
 	usb_callout_init(sc->sc_tmo_rhsc);
+	usb_callout_init(sc->sc_softintr_handle);
 
 	return (USBD_NORMAL_COMPLETION);
 
@@ -1301,9 +1303,24 @@
 }
 
 void
+ohci_softintr_do_wakeup(void *ident)
+{
+	int		s;
+
+	s = splusb();
+	wakeup(ident);
+	splx(s);
+}
+
+void
 ohci_softintr(void *v)
 {
+#if defined(__FreeBSD__)
+	struct usbd_bus	*bus = v;
+	ohci_softc_t *sc = device_get_ivars(bus->bdev);
+#else
 	ohci_softc_t *sc = v;
+#endif
 	ohci_soft_itd_t *sitd, *sidone, *sitdnext;
 	ohci_soft_td_t  *std,  *sdone,  *stdnext;
 	usbd_xfer_handle xfer;
@@ -1456,7 +1473,9 @@
 
 	if (sc->sc_softwake) {
 		sc->sc_softwake = 0;
-		wakeup(&sc->sc_softwake);
+		/* wake up after 1 tick */
+		usb_callout(sc->sc_softintr_handle, 1,
+					ohci_softintr_do_wakeup, &sc->sc_softwake);
 	}
 
 	sc->sc_bus.intr_context--;
Index: ohcivar.h
===================================================================
RCS file: /local/cvsroot/src/sys/dev/usb/ohcivar.h,v
retrieving revision 1.32
diff -u -r1.32 ohcivar.h
--- ohcivar.h	7 Apr 2002 15:16:31 -0000	1.32
+++ ohcivar.h	9 May 2002 14:37:17 -0000
@@ -141,6 +141,8 @@
 
 	device_ptr_t sc_child;
 	char sc_dying;
+
+	usb_callout_t sc_softintr_handle;
 } ohci_softc_t;
 
 struct ohci_xfer {
Index: uhci.c
===================================================================
RCS file: /local/cvsroot/src/sys/dev/usb/uhci.c,v
retrieving revision 1.120
diff -u -r1.120 uhci.c
--- uhci.c	26 Apr 2002 22:48:22 -0000	1.120
+++ uhci.c	9 May 2002 15:04:11 -0000
@@ -247,6 +247,7 @@
 
 Static usbd_status	uhci_open(usbd_pipe_handle);
 Static void		uhci_poll(struct usbd_bus *);
+Static void		uhci_softintr_do_wakeup(void *ident);
 Static void		uhci_softintr(void *);
 
 Static usbd_status	uhci_device_request(usbd_xfer_handle xfer);
@@ -506,6 +507,7 @@
 	SIMPLEQ_INIT(&sc->sc_free_xfers);
 
 	usb_callout_init(sc->sc_poll_handle);
+	usb_callout_init(sc->sc_softintr_handle);
 
 	/* Set up the bus struct. */
 	sc->sc_bus.methods = &uhci_bus_methods;
@@ -1262,9 +1264,24 @@
 }
 
 void
+uhci_softintr_do_wakeup(void *ident)
+{
+	int		s;
+
+	s = splusb();
+	wakeup(ident);
+	splx(s);
+}
+
+void
 uhci_softintr(void *v)
 {
+#if defined(__FreeBSD__)
+	struct usbd_bus	*bus = v;
+	uhci_softc_t *sc = device_get_ivars(bus->bdev);
+#else
 	uhci_softc_t *sc = v;
+#endif
 	uhci_intr_info_t *ii;
 
 	DPRINTFN(10,("%s: uhci_softintr (%d)\n", USBDEVNAME(sc->sc_bus.bdev),
@@ -1288,7 +1305,9 @@
 
 	if (sc->sc_softwake) {
 		sc->sc_softwake = 0;
-		wakeup(&sc->sc_softwake);
+		/* wake up after 1 tick */
+		usb_callout(sc->sc_softintr_handle, 1,
+					uhci_softintr_do_wakeup, &sc->sc_softwake);
 	}
 
 	sc->sc_bus.intr_context--;
Index: uhcivar.h
===================================================================
RCS file: /local/cvsroot/src/sys/dev/usb/uhcivar.h,v
retrieving revision 1.33
diff -u -r1.33 uhcivar.h
--- uhcivar.h	7 Apr 2002 18:06:34 -0000	1.33
+++ uhcivar.h	9 May 2002 14:22:29 -0000
@@ -188,6 +188,8 @@
 #endif
 
 	device_ptr_t sc_child;		/* /dev/usb# device */
+
+	usb_callout_t sc_softintr_handle;
 } uhci_softc_t;
 
 usbd_status	uhci_init(uhci_softc_t *);
---------------------------------------------------------------
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->joe 
Responsible-Changed-By: joe 
Responsible-Changed-When: Mon Sep 30 10:51:48 PDT 2002 
Responsible-Changed-Why:  
I'll take this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37928 

From: Josef Karthauser <joe@FreeBSD.org>
To: Toshikazu ICHINOSEKI <t.ichinoseki@nifty.com>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/37928: [PATCH] can't go single user mode after usb mouse attached
Date: Mon, 30 Sep 2002 18:53:15 +0100

 --oLBj+sq0vYjzfsbl
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 > 	When I try to go single user mode after usb mouse attached, I get
 > 	following message on console:
 >=20
 > 	init: some process would not die; ps axl advised
 > 	init: can't get /dev/console for controlling terminal: Operation not per=
 mitted.
 > 	<This message repeats until I reboot with ctrl+alt+delete.>
 >=20
 > 	In DDB, ps shows that moused sleeps with wmesg "uhciab". This
 > 	means uhci driver sleeps in uhci_abort_xfer() and is not waken
 > 	up.
 
 I've just committed a USB_USE_SOFTINTR fix to the -current tree.  Would
 you mind trying it to see whether it fixes the problems that you were
 having?
 
 Thanks.
 Joe
 --=20
 "As far as the laws of mathematics refer to reality, they are not certain;
 and as far as they are certain, they do not refer to reality." - Albert
 Einstein, 1921
 
 --oLBj+sq0vYjzfsbl
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.7 (FreeBSD)
 
 iEYEARECAAYFAj2Yj4kACgkQXVIcjOaxUBbkQACeObv11PBNXuESWHpsXQsEKThz
 CVkAn3b+ZKmXzZWNjgEH+5IjkHGCh8wj
 =FIg5
 -----END PGP SIGNATURE-----
 
 --oLBj+sq0vYjzfsbl--

From: Toshikazu ICHINOSEKI <t.ichinoseki@nifty.com>
To: joe@FreeBSD.org
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/37928: [PATCH] can't go single user mode after usb mouse
 attached
Date: Thu, 03 Oct 2002 01:54:14 +0900 (JST)

 On Mon, 30 Sep 2002 18:53:15 +0100
  Josef Karthauser <joe@FreeBSD.org> wrote:
 joe> 
 joe> I've just committed a USB_USE_SOFTINTR fix to the -current tree.  Would
 joe> you mind trying it to see whether it fixes the problems that you were
 joe> having?
 
 I tested by Oct. 1st kernel with either USB_USE_SOFTINTR is enabled or
 not. And I tested using modules only. My -current box goes single user
 mode in both cases with no ploblem. It works fine.
 
 Thanks.
 Ichinoseki
 --
State-Changed-From-To: open->closed 
State-Changed-By: joe 
State-Changed-When: Wed Oct 2 11:09:55 PDT 2002 
State-Changed-Why:  
The submitter reports that we've fixed his problem. :) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37928 
>Unformatted:
