From nobody@FreeBSD.org  Thu May 26 21:08:08 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 50BCB16A41C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 May 2005 21:08:08 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0EBB943D48
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 May 2005 21:08:08 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j4QL87Oc087355
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 May 2005 21:08:07 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j4QL87T2087354;
	Thu, 26 May 2005 21:08:07 GMT
	(envelope-from nobody)
Message-Id: <200505262108.j4QL87T2087354@www.freebsd.org>
Date: Thu, 26 May 2005 21:08:07 GMT
From: Darren Pilgrim <dmp@bitfreak.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /usr/sbin/usbd has MAXUSBDEV set too low, resulting not all /dev/usb* being opened and subsequent attach failures.
X-Send-Pr-Version: www-2.3

>Number:         81533
>Category:       bin
>Synopsis:       [patch] /usr/sbin/usbd has MAXUSBDEV set too low, resulting not all /dev/usb* being opened and subsequent attach failures.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 26 21:10:01 GMT 2005
>Closed-Date:    Mon Jul 11 17:41:04 GMT 2005
>Last-Modified:  Mon Jul 11 17:41:04 GMT 2005
>Originator:     Darren Pilgrim
>Release:        6.0-CURRENT
>Organization:
n/a
>Environment:
FreeBSD Smiley.Blackthornes.LAN 6.0-CURRENT FreeBSD 6.0-CURRENT #0: Sun May 22 18:51:16 PDT 2005 root@Sonomago.loki.lan:/usr/obj/usr/src/sys/Sonomago  i386
>Description:
In order to watch for events, usbd opens the /dev/usb* devices.  usbd uses a #define called MAXUSBDEV to size arrays used in opening the USB bus devices.  As the name of the constant implies, usbd will not open more than MAXUSBDEV /dev/usb* devices.  Presently, MAXUSBDEV is set to 4.  Modern hardware is trending toward four or more USB 2.0 ports using a one-hub-per-port configuration on the motherboard to increase performance.  As such, the current value for MAXUSBDEV is no longer sufficient.

When a device is plugged into a bus not being watched by usbd, the event is not caught and the attach procedure it not performed.  This is further complicated by the dual-hub nature of USB 2.0.  Because of this odd design, it is possible for usbd to be watching the USB 1.1 hub for a port, but not the USB 2.0 hub or vice versa.  When a USB device is connected to such a port, the results are unpredicatable.  The author was able to reliably produce panics in this scenario by plugging and unplugging an external USB 2.0 hub.
>How-To-Repeat:
The problem can be observed on any machine with at least four USB 2.0 ports or five USB 1.1 ports or any other combination that would produce at least five /dev/usb* devices.  Use fstat to look at the files usbd has open and note that only /dev/usb0, /dev/usb1, /dev/usb2 and /dev/usb3 are open despite the presence of /dev/usb4 and (possibly) higher-numbered devices.  Plugging devices into the unwatched or partially-watched hubs will result in missing or erroneous attach behavior.

WARNING: You may panic your system trying this!

>Fix:
Increasing MAXUSBDEV to at least the number of USB hubs present results in proper operation of usbd for all USB busses.  The following patch to src/usr.sbin/usbd/usbd.c v1.31 increases MAXUSBDEV to 40:

--- usbd.c.orig	Mon Jan  3 22:45:41 2005
+++ usbd.c	Wed May 25 20:52:01 2005
@@ -81,7 +81,7 @@
 /* Maximum number of USB busses expected to be in a system
  * XXX should be replaced by dynamic allocation.
  */
-#define MAXUSBDEV	4
+#define MAXUSBDEV	40
 
 /* Sometimes a device does not respond in time for interrupt
  * driven explore to find it.  Therefore we run an exploration

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Fri Jul 1 15:50:21 GMT 2005 
State-Changed-Why:  
Patch applied to HEAD, will be MFC'd in a week or so.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81533 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Mon Jul 11 17:23:47 GMT 2005 
State-Changed-Why:  
Commited to RELENG_5.  Thanks! 

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