From vova@sw.ru  Mon Dec 23 01:41:33 2002
Return-Path: <vova@sw.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 67FB537B401
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 23 Dec 2002 01:41:33 -0800 (PST)
Received: from vbook.express.ru (asplinux.ru [195.133.213.194])
	by mx1.FreeBSD.org (Postfix) with ESMTP id E5A1043EDA
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 23 Dec 2002 01:41:31 -0800 (PST)
	(envelope-from vova@sw.ru)
Received: from vova by vbook.express.ru with local (Exim 4.10)
	id 18QP5V-0000GD-00
	for FreeBSD-gnats-submit@freebsd.org; Mon, 23 Dec 2002 12:41:29 +0300
Message-Id: <E18QP5V-0000GD-00@vbook.express.ru>
Date: Mon, 23 Dec 2002 12:41:29 +0300
From: Vladimir B.Grebenschikov <vova@sw.ru>
Sender: "Vladimir B. Grebenschikov" <vova@sw.ru>
Reply-To: Vladimir B.Grebenschikov <vova@sw.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: usb driver do not send detach events on SOVY VAIO Z505S
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         46488
>Category:       kern
>Synopsis:       usb driver do not send detach events on SOVY VAIO Z505S
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jmg
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 23 01:50:02 PST 2002
>Closed-Date:    Tue Aug 17 15:12:09 GMT 2004
>Last-Modified:  Tue Aug 17 15:12:09 GMT 2004
>Originator:     Vladimir B. Grebenschikov
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
SWsoft
>Environment:
System: FreeBSD vbook.express.ru 5.0-CURRENT FreeBSD 5.0-CURRENT #13: Mon Dec 23 11:06:09 MSK 2002 root@vbook.express.ru:/usr/obj/usr/local/src/sys/VBOOK i386
Kernel just from CVS (after 5.0-RC2)

usbd.conf:
-----------------------------------------------------------------
# Configuration file the USB daemon.
#

device "Sony DSC-P50 Dicatal Photo Camera"
	vendor  0x054c
	product 0x0010
	attach "/sbin/camcontrol rescan bus 0; /sbin/mount /m/cam"
	detach "/sbin/umount -f /m/cam"

device "UMass storage (floppy)"
	devname "umass0"
	attach "/sbin/camcontrol rescan bus 0; /sbin/mount /m/A"
	detach "/sbin/umount -f /m/A"

#
device "Keyboard with Mouse"
	vendor  0x046e 
	product 0x6782
	release 0x0100
	attach "/usr/sbin/kbdcontrol -k /dev/kbd1 -r fast < /dev/ttyv0"
	detach "/usr/sbin/kbdcontrol -k /dev/kbd0 -r fast < /dev/ttyv0"

#
device "Mouse"
	devname "ums[0-9]+"
	attach "/usr/sbin/moused -p /dev/${DEVNAME} -I /var/run/moused.${DEVNAME}.pid -m 6=4 -m 7=5"
	detach "kill /var/run/moused.${DEVNAME}.pid"
#
device "Keyboard"
	devname "ukbd[0-9]+"
	attach "/usr/sbin/kbdcontrol -k /dev/kbd1"
	detach "/usr/sbin/kbdcontrol -k /dev/kbd0"

#
device "USB device"
-----------------------------------------------------------------

>Description:
Events executed during USB device attach and do not executed during device
detach. 

See log:
attach:
# usbd -dv
usbd: opened /dev/usb0
usbd: reading configuration file /etc/usbd.conf
usbd: opened /dev/usb
>How-To-Repeat:

# usbd -dv
and unplug usb device

I have already seen such effect about year ago), but then it was cured (I do not know
how).

>Fix:

Do not know
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->joe 
Responsible-Changed-By: kris 
Responsible-Changed-When: Thu Jul 17 17:36:40 PDT 2003 
Responsible-Changed-Why:  
Assign to USB maintainer 

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

From: Johny Mattsson <lonewolf-freebsd@earthmagic.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc: vova@sw.ru, joe@freebsd.org
Subject: [PATCH] Re: kern/46488: usb driver do not send detach events on SOVY
 VAIO Z505S
Date: Fri, 24 Oct 2003 17:06:26 +1000

 This is a multi-part message in MIME format.
 --------------050008030306020000060407
 Content-Type: text/plain; charset=us-ascii; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Hello,
 
 The attached patches correct the issue described in kern/46488. See my 
 original email to freebsd-current@ on Oct 21 2003, titled "USB device 
 detach events [PATCH - please test]", for the discussion behind these 
 patches.
 Thanks to Vladimir for confirming that the patches work on more systems 
 than my own =)
 
 Regards,
 /Johny
 -- 
 Johny Mattsson - System Designer ,-.   ,-.   ,-.  There is no truth.
 http://www.earthmagic.org     _.'  `-'   `-'  There is only perception.
 
 --------------050008030306020000060407
 Content-Type: text/plain;
  name="usb.c.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="usb.c.patch"
 
 --- usb.c.org	Tue Oct 21 16:51:25 2003
 +++ usb.c	Tue Oct 21 19:42:00 2003
 @@ -781,7 +781,8 @@
  		for (ueqi = TAILQ_FIRST(&usb_events); ueqi; ueqi = ueqi_next) {
  			ueqi_next = TAILQ_NEXT(ueqi, next);
  			if (ueqi->ue.u.ue_driver.ue_cookie.cookie ==
 -			    uep->u.ue_device.udi_cookie.cookie) {
 +			    uep->u.ue_device.udi_cookie.cookie &&
 +			    !USB_EVENT_IS_DETACH(ueqi->ue.ue_type)) {
  				TAILQ_REMOVE(&usb_events, ueqi, next);
  				free(ueqi, M_USBDEV);
  				usb_nevents--;
 
 --------------050008030306020000060407
 Content-Type: text/plain;
  name="usb_subr.c.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="usb_subr.c.patch"
 
 --- usb_subr.c.org	Tue Oct 21 17:44:48 2003
 +++ usb_subr.c	Tue Oct 21 19:40:44 2003
 @@ -1353,6 +1353,8 @@
  	}
  #endif
  
 +	usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev);
 +
  	if (dev->subdevs != NULL) {
  		DPRINTFN(3,("usb_disconnect_port: disconnect subdevs\n"));
  		for (i = 0; dev->subdevs[i]; i++) {
 @@ -1365,7 +1367,6 @@
  		}
  	}
  
 -	/*usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev);*/
  	dev->bus->devices[dev->address] = NULL;
  	up->device = NULL;
  	usb_free_device(dev);
 
 --------------050008030306020000060407--
 
Responsible-Changed-From-To: joe->jmg 
Responsible-Changed-By: jmg 
Responsible-Changed-When: Sat Oct 25 15:09:54 PDT 2003 
Responsible-Changed-Why:  
I'll look at this shortly, but looks good.. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=46488 
State-Changed-From-To: open->feedback 
State-Changed-By: jmg 
State-Changed-When: Mon Aug 9 04:01:56 GMT 2004 
State-Changed-Why:  
could you verify that this is still a problem... julian appears to have 
reenabled part of this in v1.60 of sys/dev/usb/usb_subr.c on March 19th... 
Though I can't find the commit julian mentions in his commit log... 

http://www.freebsd.org/cgi/query-pr.cgi?pr=46488 
State-Changed-From-To: feedback->closed 
State-Changed-By: jmg 
State-Changed-When: Tue Aug 17 15:10:48 GMT 2004 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=46488 
State-Changed-From-To: closed->feedback 
State-Changed-By: jmg 
State-Changed-When: Tue Aug 17 15:11:19 GMT 2004 
State-Changed-Why:  
need to add a message why it was closed.. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=46488 
State-Changed-From-To: feedback->closed 
State-Changed-By: jmg 
State-Changed-When: Tue Aug 17 15:11:41 GMT 2004 
State-Changed-Why:  
Vladimir confirms that the problem no longer exists in -current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=46488 
>Unformatted:
 >....  (I've plugged USB hub with mice & kbd)
 usbd: driver-attach event cookie=3217028524 devname=uhub1
 USB_EVENT_DRIVER_DETACH
 usbd: device-attach event at 1040635809.160556000, UT-USB41 hub, Texas
 Instruments:
   vndr=0x0451 prdct=0x1446 rlse=0x0110 clss=0x0009 subclss=0x0000
 prtcl=0x0000
   device names: uhub1
 usbd: Found action 'USB device' for UT-USB41 hub, Texas Instruments at uhub1
 usbd: device-attach event at 1040635809.938419000, Microsoft IntelliMouse
 Explorer, Microsoft:
   vndr=0x045e prdct=0x001e rlse=0x0114 clss=0x0000 subclss=0x0000
 prtcl=0x0000
   device names: ums0
 usbd: Found action 'Mouse' for Microsoft IntelliMouse Explorer, Microsoft
 at ums0
 usbd: Executing '/usr/sbin/moused -p /dev/${DEVNAME} -I
 /var/run/moused.${DEVNAME}.pid -m 6=4 -m 7=5'
 usbd: device-attach event at 1040635810.752549000, Keyboard with mouse port,
 Behavior Tech. Computer:
   vndr=0x046e prdct=0x6782 rlse=0x0100 clss=0x0000 subclss=0x0000
 prtcl=0x0000
   device names: ukbd0,ums1
 usbd: Found action 'Keyboard with Mouse' for Keyboard with mouse port,
 Behavior Tech. Computer
 usbd: Executing '/usr/sbin/kbdcontrol -k /dev/kbd1 -r fast < /dev/ttyv0'
 kbd1
     ukbd0, type:generic (0)
 >.... all seems well there, all actions executed
 >.... now I am unplugging USB hub
 usbd: driver-detach event cookie=3217028524 devname=uhub1
 USB_EVENT_DRIVER_DETACH
 >.... No more messages, actions do not executed, I have loose keyboard
 >.... (no "/usr/sbin/kbdcontrol -k /dev/kbd0 < /dev/ttyv0")
 
 
 dmesg messages
 plugging:
 ---------------------
 uhub1: Texas Instruments UT-USB41 hub, class 9/0, rev 1.10/1.10, addr 2
 uhub1: 4 ports with 4 removable, self powered
 ums0: Microsoft Microsoft IntelliMouse Explorer, rev 1.10/1.14, addr 3,
 iclass 3/1
 ums0: 5 buttons and Z dir.
 ukbd0: Behavior Tech. Computer Keyboard with mouse port, rev 1.00/1.00, addr
 4, iclass 3/1
 kbd1 at ukbd0
 ums1: Behavior Tech. Computer Keyboard with mouse port, rev 1.00/1.00, addr
 4, iclass 3/1
 ums1: 3 buttons
 ---------------------
 unplugging:
 uhub1: at uhub0 port 1 (addr 2) disconnected
 ums0: detached
 ukbd0: detached
 ums1: detached
 uhub1: detached
 ---------------------
 
 
 Problem 100% repeatable, it is applied to all my USB devices (mouse,
 keyboard, floppy, camera). 
 
 I have ACPI turned on now.
 
