NetBSD Problem Report #46696

From www@NetBSD.org  Thu Jul 12 18:30:28 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id BA22B63BF87
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 12 Jul 2012 18:30:28 +0000 (UTC)
Message-Id: <20120712183018.6B9C263BA6C@www.NetBSD.org>
Date: Thu, 12 Jul 2012 18:30:18 +0000 (UTC)
From: mishka@NetBSD.org
Reply-To: mishka@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: uhub disables port where USB keyboard attached
X-Send-Pr-Version: www-1.0

>Number:         46696
>Category:       kern
>Synopsis:       uhub disables port where USB keyboard attached
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    skrll
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 12 18:35:00 +0000 2012
>Closed-Date:    Sat Dec 14 20:26:21 +0000 2013
>Last-Modified:  Sat Dec 14 20:26:21 +0000 2013
>Originator:     Mike M. Volokhov
>Release:        NetBSD 6.0_BETA2, CVS 20120712
>Organization:
>Environment:
NetBSD nostromo.od5.lohika.com 6.0_BETA2 NetBSD 6.0_BETA2 (GENERIC) #0: Thu Jul 12 05:39:46 EEST 2012  mishka@nostromo.od5.lohika.com:/home/build/ab/obj-amd64-6.0_BETA2-20120712/sys/arch/amd64/compile/GENERIC amd64

>Description:
After reboot it may often happen that kernel cannot attach USB
keyboard with "uhubX: device problem, disabling port Y" message.
I tried different USB keyboards - effect the same. Sometimes keyboard
attaches successfully. NetBSD 5.1_STABLE just works.

The *working* dmesg output:

Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    2006, 2007, 2008, 2009, 2010, 2011, 2012
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 6.0_BETA2 (GENERIC) #0: Thu Jul 12 05:39:46 EEST 2012
        mishka@nostromo.od5.lohika.com:/home/build/ab/obj-amd64-6.0_BETA2-20120712/sys/arch/amd64/compile/GENERIC
total memory = 8172 MB
avail memory = 7919 MB
timecounter: Timecounters tick every 10.000 msec
timecounter: Timecounter "i8254" frequency 1193182 Hz quality 100
Hewlett-Packard HP Elite 7300 Series MT (1.01)
mainbus0 (root)
cpu0 at mainbus0 apid 0: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz, id 0x206a7
cpu1 at mainbus0 apid 2: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz, id 0x206a7
cpu2 at mainbus0 apid 4: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz, id 0x206a7
cpu3 at mainbus0 apid 6: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz, id 0x206a7
ioapic0 at mainbus0 apid 0: pa 0xfec00000, version 20, 24 pins
acpi0 at mainbus0: Intel ACPICA 20110623
acpi0: X/RSDT: OemId <HPQOEM,SLIC-CPC,01072009>, AslId <AMI ,00010013>
acpi0: SCI interrupting at int 9
timecounter: Timecounter "ACPI-Fast" frequency 3579545 Hz quality 1000
hpet0 at acpi0: high precision event timer (mem 0xfed00000-0xfed00400)
timecounter: Timecounter "hpet0" frequency 14318180 Hz quality 2000
MCH (PNP0C01) at acpi0 not configured
SIO1 (PNP0C02) at acpi0 not configured
attimer1 at acpi0 (TMR, PNP0100): io 0x40-0x43 irq 0
pcppi1 at acpi0 (SPKR, PNP0800): io 0x61
midi0 at pcppi1: PC speaker
sysbeep0 at pcppi1
RMSC (PNP0C02) at acpi0 not configured
PCH (PNP0C01) at acpi0 not configured
CWDT (INT3F0D) at acpi0 not configured
acpibut0 at acpi0 (PWRB, PNP0C0C-170): ACPI Power Button
RMEM (PNP0C01) at acpi0 not configured
acpiwmi0 at acpi0 (WMID, PNP0C14-0): ACPI WMI Interface
wmihp0 at acpiwmi0: HP WMI mappings
OMSC (PNP0C02) at acpi0 not configured
attimer1: attached to pcppi1
pci0 at mainbus0 bus 0: configuration mode 1
pci0: i/o space, memory space enabled, rd/line, rd/mult, wr/inv ok
pchb0 at pci0 dev 0 function 0: vendor 0x8086 product 0x0100 (rev. 0x09)
ppb0 at pci0 dev 1 function 0: vendor 0x8086 product 0x0101 (rev. 0x09)
ppb0: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci1 at ppb0 bus 1
pci1: i/o space, memory space enabled, rd/line, wr/inv ok
vga0 at pci1 dev 0 function 0: vendor 0x1002 product 0x95c5 (rev. 0x00)
wsdisplay0 at vga0 kbdmux 1: console (80x25, vt100 emulation)
wsmux1: connecting to wsdisplay0
radeondrm0 at vga0: ATI Radeon HD 3450
radeondrm0: Initialized radeon 1.29.0 20080613
hdaudio0 at pci1 dev 0 function 1: HD Audio Controller
hdaudio0: interrupting at ioapic0 pin 17
hdafg0 at hdaudio0: ATI R6xx HDMI
hdafg0: HDMI00 2ch: Digital Out [Jack]
hdafg0: 2ch/0ch 48000Hz PCM16 AC3
vendor 0x8086 product 0x1c3a (miscellaneous communications, revision 0x04) at pci0 dev 22 function 0 not configured
ehci0 at pci0 dev 26 function 0: vendor 0x8086 product 0x1c2d (rev. 0x05)
ehci0: interrupting at ioapic0 pin 16
ehci0: BIOS has given up ownership
ehci0: EHCI version 1.0
usb0 at ehci0: USB revision 2.0
hdaudio1 at pci0 dev 27 function 0: HD Audio Controller
hdaudio1: interrupting at ioapic0 pin 22
hdafg1 at hdaudio1: Sigmatel product 76c7
hdafg1: DAC00 8ch: Speaker [Jack], HP Out [Jack]
hdafg1: ADC01 2ch: Mic In [Jack]
hdafg1: ADC02 2ch: Line In [Built-In]
hdafg1: DIG03 2ch: SPDIF Out [Jack]
hdafg1: 8ch/2ch 44100Hz 48000Hz 88200Hz 96000Hz 192000Hz PCM16 PCM20 PCM24 AC3
audio0 at hdafg1: full duplex, playback, capture, independent
ppb1 at pci0 dev 28 function 0: vendor 0x8086 product 0x1c10 (rev. 0xb5)
ppb1: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci2 at ppb1 bus 2
pci2: i/o space, memory space enabled, rd/line, wr/inv ok
ppb2 at pci0 dev 28 function 1: vendor 0x8086 product 0x1c12 (rev. 0xb5)
ppb2: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci3 at ppb2 bus 3
pci3: i/o space, memory space enabled, rd/line, wr/inv ok
ppb3 at pci0 dev 28 function 2: vendor 0x8086 product 0x1c14 (rev. 0xb5)
ppb3: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci4 at ppb3 bus 4
pci4: i/o space, memory space enabled, rd/line, wr/inv ok
ppb4 at pci0 dev 28 function 3: vendor 0x8086 product 0x1c16 (rev. 0xb5)
ppb4: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci5 at ppb4 bus 5
pci5: i/o space, memory space enabled, rd/line, wr/inv ok
ppb5 at pci0 dev 28 function 4: vendor 0x8086 product 0x1c18 (rev. 0xb5)
ppb5: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci6 at ppb5 bus 6
pci6: i/o space, memory space enabled, rd/line, wr/inv ok
re0 at pci6 dev 0 function 0: RealTek 8168/8111 PCIe Gigabit Ethernet (rev. 0x06)
re0: interrupting at ioapic0 pin 16
re0: Ethernet address e0:69:95:f9:a9:5e
re0: using 256 tx descriptors
rgephy0 at re0 phy 7: RTL8169S/8110S/8211 1000BASE-T media interface, rev. 4
rgephy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT, 1000baseT-FDX, auto
ppb6 at pci0 dev 28 function 5: vendor 0x8086 product 0x1c1a (rev. 0xb5)
ppb6: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci7 at ppb6 bus 7
pci7: i/o space, memory space enabled, rd/line, wr/inv ok
vendor 0x104c product 0x8241 (USB serial bus, interface 0x30, revision 0x02) at pci7 dev 0 function 0 not configured
ppb7 at pci0 dev 28 function 6: vendor 0x8086 product 0x1c1c (rev. 0xb5)
ppb7: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci8 at ppb7 bus 8
pci8: i/o space, memory space enabled, rd/line, wr/inv ok
ppb8 at pci0 dev 28 function 7: vendor 0x8086 product 0x1c1e (rev. 0xb5)
ppb8: PCI Express 2.0 <Root Port of PCI-E Root Complex>
pci9 at ppb8 bus 9
pci9: i/o space, memory space enabled, rd/line, wr/inv ok
ehci1 at pci0 dev 29 function 0: vendor 0x8086 product 0x1c26 (rev. 0x05)
ehci1: interrupting at ioapic0 pin 23
ehci1: BIOS has given up ownership
ehci1: EHCI version 1.0
usb1 at ehci1: USB revision 2.0
ichlpcib0 at pci0 dev 31 function 0: vendor 0x8086 product 0x1c4a (rev. 0x05)
timecounter: Timecounter "ichlpcib0" frequency 3579545 Hz quality 1000
ichlpcib0: 24-bit timer
ichlpcib0: TCO (watchdog) timer configured.
ahcisata0 at pci0 dev 31 function 2: vendor 0x8086 product 0x1c02 (rev. 0x05)
ahcisata0: interrupting at ioapic0 pin 19
ahcisata0: 64-bit DMA
ahcisata0: AHCI revision 1.30, 6 ports, 32 slots, CAP 0xe730ff45<EMS,PSC,SSC,PMD,ISS=0x3=Gen3,SCLO,SAL,SALP,SSNTF,SNCQ,S64A>
atabus0 at ahcisata0 channel 0
atabus1 at ahcisata0 channel 1
atabus2 at ahcisata0 channel 2
atabus3 at ahcisata0 channel 3
atabus4 at ahcisata0 channel 4
atabus5 at ahcisata0 channel 5
ichsmb0 at pci0 dev 31 function 3: vendor 0x8086 product 0x1c22 (rev. 0x05)
ichsmb0: interrupting at ioapic0 pin 18
iic0 at ichsmb0: I2C bus
isa0 at ichlpcib0
pckbc0 at isa0 port 0x60-0x64
acpicpu0 at cpu0: ACPI CPU
acpicpu0: C1: FFH, lat   1 us, pow  1000 mW
acpicpu0: C3: FFH, lat 104 us, pow   350 mW, bus master check
acpicpu0: P0: FFH, lat  10 us, pow 95000 mW, 3401 MHz, turbo boost
acpicpu0: P1: FFH, lat  10 us, pow 95000 mW, 3400 MHz
acpicpu0: P2: FFH, lat  10 us, pow 87000 mW, 3200 MHz
acpicpu0: P3: FFH, lat  10 us, pow 80000 mW, 3000 MHz
acpicpu0: P4: FFH, lat  10 us, pow 73000 mW, 2800 MHz
acpicpu0: P5: FFH, lat  10 us, pow 66000 mW, 2600 MHz
acpicpu0: P6: FFH, lat  10 us, pow 60000 mW, 2400 MHz
acpicpu0: P7: FFH, lat  10 us, pow 54000 mW, 2200 MHz
acpicpu0: P8: FFH, lat  10 us, pow 48000 mW, 2000 MHz
acpicpu0: P9: FFH, lat  10 us, pow 42000 mW, 1800 MHz
acpicpu0: P10: FFH, lat  10 us, pow 36000 mW, 1600 MHz
acpicpu0: T0: FFH, lat   1 us, pow  1000 mW, 100 %
acpicpu0: T1: FFH, lat   1 us, pow   875 mW,  88 %
acpicpu0: T2: FFH, lat   1 us, pow   750 mW,  75 %
acpicpu0: T3: FFH, lat   1 us, pow   625 mW,  63 %
acpicpu0: T4: FFH, lat   1 us, pow   500 mW,  50 %
acpicpu0: T5: FFH, lat   1 us, pow   375 mW,  38 %
acpicpu0: T6: FFH, lat   1 us, pow   250 mW,  25 %
acpicpu0: T7: FFH, lat   1 us, pow   125 mW,  13 %
coretemp0 at cpu0: thermal sensor, 1 C resolution
acpicpu1 at cpu1: ACPI CPU
coretemp1 at cpu1: thermal sensor, 1 C resolution
acpicpu2 at cpu2: ACPI CPU
coretemp2 at cpu2: thermal sensor, 1 C resolution
acpicpu3 at cpu3: ACPI CPU
coretemp3 at cpu3: thermal sensor, 1 C resolution
timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0
timecounter: Timecounter "TSC" frequency 3392412040 Hz quality 3000
uhub0 at usb0: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
uhub0: 2 ports with 2 removable, self powered
uhub1 at usb1: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
uhub1: 2 ports with 2 removable, self powered
ahcisata0 port 0: device present, speed: 3.0Gb/s
ahcisata0 port 1: device present, speed: 3.0Gb/s
ahcisata0 port 4: device present, speed: 1.5Gb/s
ahcisata0 port 2: PHY offline
ahcisata0 port 3: PHY offline
ahcisata0 port 5: PHY offline
wd0 at atabus0 drive 0
wd0: <ST31500341AS>
wd0: drive supports 16-sector PIO transfers, LBA48 addressing
wd0: 1397 GB, 2907021 cyl, 16 head, 63 sec, 512 bytes/sect x 2930277168 sectors
wd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100)
wd0(ahcisata0:0:0): using PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100) (using DMA)
wd1 at atabus1 drive 0
wd1: <ST31500341AS>
wd1: drive supports 16-sector PIO transfers, LBA48 addressing
wd1: 1397 GB, 2907021 cyl, 16 head, 63 sec, 512 bytes/sect x 2930277168 sectors
wd1: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100)
wd1(ahcisata0:1:0): using PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100) (using DMA)
atapibus0 at atabus4: 1 targets
cd0 at atapibus0 drive 0: <hp      DVD RW AD-7251H5, 2966433L21, 1H8D> cdrom removable
cd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100)
cd0(ahcisata0:4:0): using PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100) (using DMA)
uhub2 at uhub1 port 1: vendor 0x8087 product 0x0024, class 9/0, rev 2.00/0.00, addr 2
uhub2: single transaction translator
uhub3 at uhub0 port 1: vendor 0x8087 product 0x0024, class 9/0, rev 2.00/0.00, addr 2
uhub3: single transaction translator
uhub3: 6 ports with 6 removable, self powered
uhub2: 8 ports with 8 removable, self powered
umass0 at uhub3 port 6 configuration 1 interface 0
umass0: Generic Mass Storage Device, rev 2.00/1.00, addr 3
umass0: using SCSI over Bulk-Only
uhidev0 at uhub2 port 1 configuration 1 interface 0
scsibus0 at umass0: 2 targets, 4 luns per target
sd0 at scsibus0 target 0 lun 0: <Generic-, SD/MMC, 1.00> disk removable
uhidev0: vendor 0x0461 USB Optical Mouse, rev 2.00/2.00, addr 3, iclass 3/1
sd0: drive offline
ums0 at uhidev0: 3 buttons, W and Z dirs
wsmouse0 at ums0 mux 0
sd0: unable to open device, error = 19
sd1 at scsibus0 target 0 lun 1: <Generic-, Compact Flash, 1.01> disk removable
sd1: drive offline
sd1: unable to open device, error = 19
sd2 at scsibus0 target 0 lun 2: <Generic-, SM/xD-Picture, 1.02> disk removable
sd2: drive offline
sd2: unable to open device, error = 19
sd3 at scsibus0 target 0 lun 3: <Generic-, MS/MS-Pro, 1.03> disk removable
sd3: drive offline
sd3: unable to open device, error = 19
uhidev1 at uhub2 port 2 configuration 1 interface 0
uhidev1: LITEON Technology USB Multimedia Keyboard, rev 1.10/1.01, addr 4, iclass 3/1
ukbd0 at uhidev1: 8 modifier keys, 6 key codes
wskbd0 at ukbd0: console keyboard, using wsdisplay0
Kernelized RAIDframe activated
pad0: outputs: 44100Hz, 16-bit, stereo
audio1 at pad0: half duplex, playback, capture
raid0: RAID Level 1
raid0: Components: /dev/wd0e /dev/wd1e
raid0: Total Sectors: 2930276992 (1430799 MB)
boot device: raid0
root on raid0a dumps on raid0b
root on raid0a dumps on raid0b
root file system type: ffs
wsdisplay0: screen 1 added (80x25, vt100 emulation)
wsdisplay0: screen 2 added (80x25, vt100 emulation)
wsdisplay0: screen 3 added (80x25, vt100 emulation)
wsdisplay0: screen 4 added (80x25, vt100 emulation)
info: [drm] Setting GART location based on new memory map
info: [drm] Loading RV620 Microcode
info: [drm] Resetting GPU
info: [drm] writeback test succeeded in 1 usecs
radeondrm0: interrupting at ioapic0 pin 16

After reboot (including remote shutdown, when nobody touches the
keyboard), the following difference may happen which leads to
*defunct* keyboard:

--- dmesg+kbd   2012-07-12 21:08:23.000000000 +0300
+++ dmesg-kbd   2012-07-12 21:14:21.000000000 +0300
@@ -163,7 +163,7 @@
 acpicpu3 at cpu3: ACPI CPU
 coretemp3 at cpu3: thermal sensor, 1 C resolution
 timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0
-timecounter: Timecounter "TSC" frequency 3392412040 Hz quality 3000
+timecounter: Timecounter "TSC" frequency 3392513720 Hz quality 3000
 uhub0 at usb0: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
 uhub0: 2 ports with 2 removable, self powered
 uhub1 at usb1: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
@@ -199,8 +199,8 @@
 umass0 at uhub3 port 6 configuration 1 interface 0
 umass0: Generic Mass Storage Device, rev 2.00/1.00, addr 3
 umass0: using SCSI over Bulk-Only
-uhidev0 at uhub2 port 1 configuration 1 interface 0
 scsibus0 at umass0: 2 targets, 4 luns per target
+uhidev0 at uhub2 port 1 configuration 1 interface 0
 sd0 at scsibus0 target 0 lun 0: <Generic-, SD/MMC, 1.00> disk removable
 uhidev0: vendor 0x0461 USB Optical Mouse, rev 2.00/2.00, addr 3, iclass 3/1
 sd0: drive offline
@@ -216,10 +216,7 @@
 sd3 at scsibus0 target 0 lun 3: <Generic-, MS/MS-Pro, 1.03> disk removable
 sd3: drive offline
 sd3: unable to open device, error = 19
-uhidev1 at uhub2 port 2 configuration 1 interface 0
-uhidev1: LITEON Technology USB Multimedia Keyboard, rev 1.10/1.01, addr 4, iclass 3/1
-ukbd0 at uhidev1: 8 modifier keys, 6 key codes
-wskbd0 at ukbd0: console keyboard, using wsdisplay0
+uhub2: device problem, disabling port 2
 Kernelized RAIDframe activated
 pad0: outputs: 44100Hz, 16-bit, stereo
 audio1 at pad0: half duplex, playback, capture

>How-To-Repeat:
Use HP Elite 7300, install stock NetBSD 6.0_BETA, reboot.
>Fix:

>Release-Note:

>Audit-Trail:
From: Andreas Gustafsson <gson@gson.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Tue, 4 Sep 2012 12:26:21 +0300

 I tried to upgrade a machine running NetBSD 5.1 to 6.0_RC1 and found
 that the USB keyboard no longer worked.  A quick search of the PR
 database turned up this PR (kern/46696) describing the same
 symptoms.

 With 5.1, dmesg shows:

   uhidev0 at uhub3 port 2 configuration 1 interface 0
   uhidev0: vendor 0x1267 product 0x0103, rev 1.10/1.01, addr 3, iclass 3/1
   ukbd0 at uhidev0
   wskbd1 at ukbd0 mux 1
   wskbd1: connecting to wsdisplay0
   uhidev1 at uhub3 port 2 configuration 1 interface 1
   uhidev1: vendor 0x1267 product 0x0103, rev 1.10/1.01, addr 3, iclass 3/0
   uhidev1: 2 report ids
   uhid0 at uhidev1 reportid 1: input=2, output=0, feature=0
   uhid1 at uhidev1 reportid 2: input=1, output=0, feature=0

 With 6.0_RC1, there is just:

    uhub3: device problem, disabling port 2

 The machine in case has an Intel DH67CLB3 motherboard with BIOS
 version BLH6710H.86A.0131.2011.0926.1945.  I have tried two different
 keyboards, and they both work with 5.1 and fail with 6.0_RC1.

 IMO, this is a rather serious regression.
 -- 
 Andreas Gustafsson, gson@gson.org

From: Andreas Gustafsson <gson@gson.org>
To: gnats-bugs@netbsd.org, mishka@NetBSD.org, drochner@NetBSD.org
Cc: 
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Sat, 15 Sep 2012 16:40:05 +0300

 Mike, Matthias,

 I have now identified the commit where kern/46696 appeared (on my
 machine, at least) by means of a semi-automated binary search.  It was
 src/sys/dev/usb/usb_subr.c 1.172, committed by Matthias more than two
 years ago:

   revision 1.172
   date: 2010/07/20 20:56:06;  author: drochner;  state: Exp;  lines: +43 -14
   another iteration in the eternal device enumeration struggle:
   use a request of 64 bytes for the initial device descriptor fetch.
   This is what windows does, and I've seen USB device firmware which
   really depends on this. (sends 8 bytes if 64 are requested and
   the full descriptor which is more than NetBSD's USB_MAX_IPACKET
   otherwise) This is the world...

 For testing, I have prepared a patch which effectively reverts this commit:

   http://www.gson.org/netbsd/bugs/46696/usb.patch

 Mike, can you try this patch and see if it fixes the problem for you?

 Matthias, can you identify the USB device that prompted the above
 commit?  And if it is a full-speed device, would it be possible
 to use the 64-byte request size for full-speed devices but not
 low-speed ones?
 -- 
 Andreas Gustafsson, gson@gson.org

From: Matthias Drochner <m.drochner@googlemail.com>
To: Andreas Gustafsson <gson@gson.org>
Cc: <gnats-bugs@netbsd.org>, <mishka@NetBSD.org>
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Tue, 18 Sep 2012 09:53:41 +0200

 On Sat, 15 Sep 2012 16:40:05 +0300
 Andreas Gustafsson <gson@gson.org> wrote:
 > I have now identified the commit where kern/46696 appeared (on my
 > machine, at least) by means of a semi-automated binary search.
 > For testing, I have prepared a patch which effectively reverts this
 > commit:
 > 
 >   http://www.gson.org/netbsd/bugs/46696/usb.patch

 I just got a (my first, actually) USB3 device and it triggers an error
 on first descriptor fetch too:
 ehci0: handing over full speed device on port 5 to uhci2
 usbd_new_device: addr=2, getting first desc failed: 17
 uhub_explore: usbd_new_device failed, error=STALLED
 uhub0: device problem, disabling port 1

 This happens with and without your patch.

 It is also strange that it hands over the device to USB1 at all,
 should better stay on ehci... Need to check specs for compatibility
 requirements.

 > Matthias, can you identify the USB device that prompted the above
 > commit?  And if it is a full-speed device, would it be possible
 > to use the 64-byte request size for full-speed devices but not
 > low-speed ones?

 I'm not 100% sure. Probably some Atmel-based embedded design.
 This is most certainly a full speed one, so it is better to
 restrict the effect of your patch to low-speed.

 But in any case -- as my problem shows, the whole thing
 needs more research.

 best regards
 Matthias

From: Matthias Drochner <m.drochner@googlemail.com>
To: 
Cc: Andreas Gustafsson <gson@gson.org>, <gnats-bugs@netbsd.org>,
 <mishka@NetBSD.org>
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Sat, 22 Sep 2012 14:28:54 +0200

 On Tue, 18 Sep 2012 09:53:41 +0200
 Matthias Drochner <m.drochner@gmail.com> wrote:
 > It is also strange that it hands over the device to USB1 at all,
 > should better stay on ehci... Need to check specs for compatibility
 > requirements.

 I've identified the problem. Out reset is too long. It collides
 with a timeout in the USB3 spec.

 > > Matthias, can you identify the USB device that prompted the above
 > > commit?  And if it is a full-speed device, would it be possible
 > > to use the 64-byte request size for full-speed devices but not
 > > low-speed ones?
 > 
 > I'm not 100% sure. Probably some Atmel-based embedded design.
 > This is most certainly a full speed one, so it is better to
 > restrict the effect of your patch to low-speed.

 Here is a citation which confirms what I said about the 64-byte
 request:
 http://www.usbmadesimple.co.uk/ums_4.htm

 best regards
 Matthias

From: "Jonathan A. Kollasch" <jakllsch@kollasch.net>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Sat, 22 Sep 2012 14:21:48 -0500

 Which timeout is that?

 Also, USB 3.0 doesn't cover USB 2.0 physical layer timings at all.

From: kato@wide.ad.jp
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Fri, 18 Jan 2013 17:57:37 +0900 (JST)

 >Submitter-Id:	net
 >Originator:	Akira Kato
 >Organization:	WIDE Project
 >Confidential:	no
 >Synopsis:	USB keyboard may not be usable
 >Severity:	serious
 >Priority:	medium
 >Category:	kern
 >Class:		change-request
 >Release:	NetBSD 6.0_STABLE
 >Environment:
 System: NetBSD r420.kmd.keio.ac.jp 6.0_STABLE NetBSD 6.0_STABLE (DIAGNOSTIC) #1: Fri Jan 18 08:34:16 JST 2013  root@r420.kmd.keio.ac.jp:/usr/src/sys/arch/amd64/compile/DIAGNOSTIC amd64
 Architecture: amd64
 Machine: amd64
 >Description:
 	On a Dell PowerEdge R-420 1U server and on a Shuttle DS61 compact
 	PC, the USB keyboard may not be recognized correctly (the possibility
 	was roughly at around 80% with a dmesg line of the following:
 	(the number changes in different platforms)
 		uhub2: device problem, disabling port 8
 	Sometimes the machine booted without the line above and in this
 	case the USB keyboard worked well. In order to make the USB keyboard
 	work when the corresponding port was disabled, the USB keyboard cable
 	must be removed once and plugged in to other USB port.
 >How-To-Repeat:
 	Just reboot the machine.
 >Fix:
 	A patch posted by Andreas Gustafsson in about 4 months ago fixes
 	this problem:

 	* To: kern-bug-people%netbsd.org@localhost,gnats-admin%netbsd.org@localhost,netbsd-bugs%netbsd.org@localhost,mishka%NetBSD.org@localhost
     	* Subject: Re: kern/46696: uhub disables port where USB keyboard attached
 	* From: Andreas Gustafsson <gson%gson.org@localhost>
 	* Date: Sat, 15 Sep 2012 13:45:03 +0000 (UTC)

 	The patch is accessible as follows:

 	http://www.gson.org/netbsd/bugs/46696/usb.patch

 	After applying the patch, I rebooted both machines more than 10 times
 	each and the USB keyboard worked well in all cases. I would recommend
 	to apply the patch to the netbsd-6 source tree and possibly the HEAD
 	tree as well.

From: Nick Hudson <skrll@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: kato@wide.ad.jp, kern-bug-people@netbsd.org, gnats-admin@netbsd.org, 
 netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Tue, 19 Mar 2013 08:37:25 +0000

 This is a multi-part message in MIME format.
 --------------010405020704010007000106
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit

 Does this patch against -current fix the problem?

 Thanks,
 Nick

 --------------010405020704010007000106
 Content-Type: text/plain; charset=us-ascii;
  name="usb_subr.c.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="usb_subr.c.diff"

 Index: sys/dev/usb/usb_subr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/usb_subr.c,v
 retrieving revision 1.189
 diff -u -p -u -r1.189 usb_subr.c
 --- sys/dev/usb/usb_subr.c	22 Jan 2013 14:01:19 -0000	1.189
 +++ sys/dev/usb/usb_subr.c	19 Mar 2013 08:03:03 -0000
 @@ -1133,7 +1133,12 @@ usbd_new_device(device_t parent, usbd_bu
  	 * (which uses 64 bytes so it shouldn't be less),
  	 * highspeed devices must support 64 byte packets anyway
  	 */
 -	USETW(dev->def_ep_desc.wMaxPacketSize, 64);
 +
 +	if (speed == USB_SPEED_HIGH || speed == USB_SPEED_FULL)
 +		USETW(dev->def_ep_desc.wMaxPacketSize, 64);
 +	else
 +		USETW(dev->def_ep_desc.wMaxPacketSize, USB_MAX_IPACKET);
 + 	
  	dev->def_ep_desc.bInterval = 0;

  	/* doesn't matter, just don't let it uninitialized */

 --------------010405020704010007000106--

State-Changed-From-To: open->feedback
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Wed, 20 Mar 2013 12:55:34 +0000
State-Changed-Why:
Please try today's -current. Thanks, Nick


From: "Nick Hudson" <skrll@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/46696 CVS commit: src/sys/dev/usb
Date: Wed, 20 Mar 2013 11:14:53 +0000

 Module Name:	src
 Committed By:	skrll
 Date:		Wed Mar 20 11:14:52 UTC 2013

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

 Log Message:
 Only set wMaxPacketSize to 64 for HS/FS and set to 8 for LS to be within
 the USB spec.

 Should help PR/46696.

 Requesting 64 bytes via wLength is indeed common, but fallback to 8
 would probably help.


 To generate a diff of this commit:
 cvs rdiff -u -r1.189 -r1.190 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.

From: kato@wide.ad.jp
To: skrll@netbsd.org
Cc: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Mon, 25 Mar 2013 11:27:12 +0900 (JST)

 Dear Nick,

 Sorry for a late response. I applied your patch to my NetBSD-6 (6.1_RC2,
 sync'ed with CVS tree just now). The patch was applied successfully with
 30 lines offset.

 I rebooted the machine with the patched kernel 8 times, and in 5 trials
 out of 8, the USB keyboard worked fine. But unfortunately in 3 trials,
 the USB keyboard didn't work at all. When I unplug the USB keyboard,
 and re-plug it with the same USB port, it started to work well. So the
 patch improves the situation but doesn't solve the issue, at least with
 NetBSD-6.1_RC2.

 The alternate patch
 	http://www.gson.org/netbsd/bugs/46696/usb.patch
 works well even with NetBSD-6.

 The diff of dmesg in these cases are:

 *** dmesg.ok	Mon Mar 25 11:23:07 2013
 --- dmesg.bad	Mon Mar 25 11:23:36 2013
 ***************
 *** 151,157 ****
   acpicpu1 at cpu1: ACPI CPU
   coretemp1 at cpu1: thermal sensor, 1 C resolution
   timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0
 ! timecounter: Timecounter "TSC" frequency 3093152640 Hz quality 3000
   uhub0 at usb0: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
   uhub0: 2 ports with 2 removable, self powered
   uhub1 at usb1: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
 --- 151,157 ----
   acpicpu1 at cpu1: ACPI CPU
   coretemp1 at cpu1: thermal sensor, 1 C resolution
   timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0
 ! timecounter: Timecounter "TSC" frequency 3093079200 Hz quality 3000
   uhub0 at usb0: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
   uhub0: 2 ports with 2 removable, self powered
   uhub1 at usb1: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
 ***************
 *** 174,189 ****
   uhub3: single transaction translator
   uhub2: 4 ports with 4 removable, self powered
   uhub3: 6 ports with 6 removable, self powered
 ! uhidev0 at uhub3 port 2 configuration 1 interface 0
 ! uhidev0: vendor 0x04f3 product 0x0103, rev 1.10/1.07, addr 3, iclass 3/1
 ! ukbd0 at uhidev0
 ! wskbd1 at ukbd0 mux 1
 ! wskbd1: connecting to wsdisplay0
 ! uhidev1 at uhub3 port 2 configuration 1 interface 1
 ! uhidev1: vendor 0x04f3 product 0x0103, rev 1.10/1.07, addr 3, iclass 3/0
 ! uhidev1: 2 report ids
 ! uhid0 at uhidev1 reportid 1: input=2, output=0, feature=0
 ! uhid1 at uhidev1 reportid 2: input=1, output=0, feature=0
   Kernelized RAIDframe activated
   pad0: outputs: 44100Hz, 16-bit, stereo
   audio1 at pad0: half duplex, playback, capture
 --- 174,180 ----
   uhub3: single transaction translator
   uhub2: 4 ports with 4 removable, self powered
   uhub3: 6 ports with 6 removable, self powered
 ! uhub3: device problem, disabling port 2
   Kernelized RAIDframe activated
   pad0: outputs: 44100Hz, 16-bit, stereo
   audio1 at pad0: half duplex, playback, capture



 From: Nick Hudson <skrll@netbsd.org>
 Subject: Re: kern/46696: uhub disables port where USB keyboard attached
 Date: Tue, 19 Mar 2013 08:37:25 +0000

 > Does this patch against -current fix the problem?
 > 
 > Thanks,
 > Nick

From: Nick Hudson <nick.hudson@gmx.co.uk>
To: gnats-bugs@NetBSD.org
Cc: kato@wide.ad.jp, kern-bug-people@netbsd.org, gnats-admin@netbsd.org, 
 netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Mon, 25 Mar 2013 07:46:40 +0000

 This is a multi-part message in MIME format.
 --------------080504070601060102070209
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit

 On 03/25/13 02:30, kato@wide.ad.jp wrote:
 >   Dear Nick,
 Hi,

 >   Sorry for a late response. I applied your patch to my NetBSD-6 (6.1_RC2,
 >   sync'ed with CVS tree just now). The patch was applied successfully with
 >   30 lines offset.
 >   
 >   I rebooted the machine with the patched kernel 8 times, and in 5 trials
 >   out of 8, the USB keyboard worked fine. But unfortunately in 3 trials,
 >   the USB keyboard didn't work at all. When I unplug the USB keyboard,
 >   and re-plug it with the same USB port, it started to work well. So the
 >   patch improves the situation but doesn't solve the issue, at least with
 >   NetBSD-6.1_RC2.

 Here's something else to try. I've provided patches against -current and 
 netbsd-6.

 >   The alternate patch
 >   	http://www.gson.org/netbsd/bugs/46696/usb.patch
 >   works well even with NetBSD-6.

 I don't think reverting the previous patch is the right thing to do. A 
 quick poll of how other
 OSes handle this suggest that the initial query of 64 bytes is very common.

 Thanks,
 Nick


 --------------080504070601060102070209
 Content-Type: text/plain; charset=us-ascii;
  name="netbsd-6.usb_subr.c.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="netbsd-6.usb_subr.c.diff"

 Index: sys/dev/usb/usb_subr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/usb_subr.c,v
 retrieving revision 1.180
 diff -u -p -u -r1.180 usb_subr.c
 --- sys/dev/usb/usb_subr.c	9 Jun 2011 19:08:33 -0000	1.180
 +++ sys/dev/usb/usb_subr.c	25 Mar 2013 07:41:51 -0000
 @@ -1033,6 +1033,9 @@ usbd_reattach_device(device_t parent, us
   * Do as Windows does: try to read 64 bytes -- there are devices which
   * recognize the initial descriptor fetch (before the control endpoint's
   * MaxPacketSize is known by the host) by exactly this length.
 + *
 + * If the 64 bytes request fails try for just the 8 that the USB 2.0
 + * specification says should be requested.
   */
  static usbd_status
  usbd_get_initial_ddesc(usbd_device_handle dev, usb_device_descriptor_t *desc)
 @@ -1046,13 +1049,23 @@ usbd_get_initial_ddesc(usbd_device_handl
  	USETW2(req.wValue, UDESC_DEVICE, 0);
  	USETW(req.wIndex, 0);
  	USETW(req.wLength, 64);
 +	DPRINTF(("%s asking for 64 bytes\n", __func__));
 +
  	res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
  		&actlen, USBD_DEFAULT_TIMEOUT);
 -	if (res)
 -		return res;
 +	if (res) {
 +		DPRINTF(("%s asking for 8 bytes\n", __func__));
 +		USETW(req.wLength, 8);
 +		res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
 +			&actlen, USBD_DEFAULT_TIMEOUT);
 +		if (res)
 +			return res;
 +	}
  	if (actlen < 8)
  		return USBD_SHORT_XFER;
  	memcpy(desc, buf, 8);
 +	DPRINTF(("%s got info\n", __func__));
 +
  	return USBD_NORMAL_COMPLETION;
  }

 @@ -1103,7 +1116,11 @@ usbd_new_device(device_t parent, usbd_bu
  	 * (which uses 64 bytes so it shouldn't be less),
  	 * highspeed devices must support 64 byte packets anyway
  	 */
 -	USETW(dev->def_ep_desc.wMaxPacketSize, 64);
 +	if (speed == USB_SPEED_HIGH || speed == USB_SPEED_FULL)
 +		USETW(dev->def_ep_desc.wMaxPacketSize, 64);
 +	else
 +		USETW(dev->def_ep_desc.wMaxPacketSize, USB_MAX_IPACKET);
 +
  	dev->def_ep_desc.bInterval = 0;

  	/* doesn't matter, just don't let it uninitialized */



 --------------080504070601060102070209
 Content-Type: text/plain; charset=us-ascii;
  name="usb_subr.c.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="usb_subr.c.diff"

 Index: sys/dev/usb/usb_subr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/usb_subr.c,v
 retrieving revision 1.190
 diff -u -p -u -r1.190 usb_subr.c
 --- sys/dev/usb/usb_subr.c	20 Mar 2013 11:14:51 -0000	1.190
 +++ sys/dev/usb/usb_subr.c	25 Mar 2013 07:38:41 -0000
 @@ -1063,6 +1063,9 @@ usbd_reattach_device(device_t parent, us
   * Do as Windows does: try to read 64 bytes -- there are devices which
   * recognize the initial descriptor fetch (before the control endpoint's
   * MaxPacketSize is known by the host) by exactly this length.
 + *
 + * If the 64 bytes request fails try for just the 8 that the USB 2.0
 + * specification says should be requested.
   */
  static usbd_status
  usbd_get_initial_ddesc(usbd_device_handle dev, usb_device_descriptor_t *desc)
 @@ -1076,13 +1079,23 @@ usbd_get_initial_ddesc(usbd_device_handl
  	USETW2(req.wValue, UDESC_DEVICE, 0);
  	USETW(req.wIndex, 0);
  	USETW(req.wLength, 64);
 +	DPRINTF(("%s asking for 64 bytes\n", __func__));
 +
  	res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
  		&actlen, USBD_DEFAULT_TIMEOUT);
 -	if (res)
 -		return res;
 +	if (res) {
 +		DPRINTF(("%s asking for 8 bytes\n", __func__));
 +		USETW(req.wLength, 8);
 +		res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
 +			&actlen, USBD_DEFAULT_TIMEOUT);
 +		if (res)
 +			return res;
 +	}
  	if (actlen < 8)
  		return USBD_SHORT_XFER;
  	memcpy(desc, buf, 8);
 +	DPRINTF(("%s got info\n", __func__));
 +
  	return USBD_NORMAL_COMPLETION;
  }



 --------------080504070601060102070209--

From: kato@wide.ad.jp
To: nick.hudson@gmx.co.uk
Cc: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Tue, 26 Mar 2013 14:28:23 +0900 (JST)

 Nick,

 I tested your patch for netbsd-6. 4 times out of 20 times reboot, the
 USB keyboard didn't recognized correctly.

 -- Akira Kato

 *** dmesg.nb6-patch.ok	Tue Mar 26 14:19:08 2013
 --- dmesg.nb6-patch.bad	Tue Mar 26 14:16:33 2013
 ***************
 *** 151,157 ****
   acpicpu1 at cpu1: ACPI CPU
   coretemp1 at cpu1: thermal sensor, 1 C resolution
   timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0
 ! timecounter: Timecounter "TSC" frequency 3093118000 Hz quality 3000
   uhub0 at usb0: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
   uhub0: 2 ports with 2 removable, self powered
   uhub1 at usb1: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
 --- 151,157 ----
   acpicpu1 at cpu1: ACPI CPU
   coretemp1 at cpu1: thermal sensor, 1 C resolution
   timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0
 ! timecounter: Timecounter "TSC" frequency 3093109560 Hz quality 3000
   uhub0 at usb0: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
   uhub0: 2 ports with 2 removable, self powered
   uhub1 at usb1: vendor 0x8086 EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
 ***************
 *** 174,189 ****
   uhub3: single transaction translator
   uhub2: 4 ports with 4 removable, self powered
   uhub3: 6 ports with 6 removable, self powered
 ! uhidev0 at uhub3 port 2 configuration 1 interface 0
 ! uhidev0: vendor 0x04f3 product 0x0103, rev 1.10/1.07, addr 3, iclass 3/1
 ! ukbd0 at uhidev0
 ! wskbd1 at ukbd0 mux 1
 ! wskbd1: connecting to wsdisplay0
 ! uhidev1 at uhub3 port 2 configuration 1 interface 1
 ! uhidev1: vendor 0x04f3 product 0x0103, rev 1.10/1.07, addr 3, iclass 3/0
 ! uhidev1: 2 report ids
 ! uhid0 at uhidev1 reportid 1: input=2, output=0, feature=0
 ! uhid1 at uhidev1 reportid 2: input=1, output=0, feature=0
   Kernelized RAIDframe activated
   pad0: outputs: 44100Hz, 16-bit, stereo
   audio1 at pad0: half duplex, playback, capture
 --- 174,180 ----
   uhub3: single transaction translator
   uhub2: 4 ports with 4 removable, self powered
   uhub3: 6 ports with 6 removable, self powered
 ! uhub3: device problem, disabling port 2
   Kernelized RAIDframe activated
   pad0: outputs: 44100Hz, 16-bit, stereo
   audio1 at pad0: half duplex, playback, capture

From: Nick Hudson <skrll@netbsd.org>
To: kato@wide.ad.jp
Cc: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org, 
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Fri, 29 Mar 2013 16:52:16 +0000

 This is a multi-part message in MIME format.
 --------------070609000900090003060700
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit

 On 03/26/13 05:28, kato@wide.ad.jp wrote:
 > Nick,
 >
 > I tested your patch for netbsd-6. 4 times out of 20 times reboot, the
 > USB keyboard didn't recognized correctly.


 Not sure if that is an improvement on -current. Can you try this patch 
 on it's own and with the 8 bytes read patch.

 usbdebug output from a failure would be useful.

 Thanks,
 Nick


 --------------070609000900090003060700
 Content-Type: text/plain; charset=us-ascii;
  name="patch2"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="patch2"

 Index: sys/dev/usb/usb_subr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/usb_subr.c,v
 retrieving revision 1.190
 diff -u -p -u -r1.190 usb_subr.c
 --- sys/dev/usb/usb_subr.c	20 Mar 2013 11:14:51 -0000	1.190
 +++ sys/dev/usb/usb_subr.c	29 Mar 2013 16:48:02 -0000
 @@ -1253,14 +1266,6 @@ usbd_new_device(device_t parent, usbd_bu
  	dev->address = addr;	/* new device address now */
  	bus->devices[addr] = dev;

 -	err = usbd_reload_device_desc(dev);
 -	if (err) {
 -		DPRINTFN(-1, ("usbd_new_device: addr=%d, getting full desc "
 -			      "failed\n", addr));
 -		usbd_remove_device(dev, up);
 -		return (err);
 -	}
 -
  	/* Re-establish the default pipe with the new address. */
  	usbd_kill_pipe(dev->default_pipe);
  	err = usbd_setup_pipe_flags(dev, 0, &dev->def_ep, USBD_DEFAULT_INTERVAL,
 @@ -1271,6 +1276,14 @@ usbd_new_device(device_t parent, usbd_bu
  		return err;
  	}

 +	err = usbd_reload_device_desc(dev);
 +	if (err) {
 +		DPRINTFN(-1, ("usbd_new_device: addr=%d, getting full desc "
 +			      "failed\n", addr));
 +		usbd_remove_device(dev, up);
 +		return (err);
 +	}
 +
  	/* Assume 100mA bus powered for now. Changed when configured. */
  	dev->power = USB_MIN_POWER;
  	dev->self_powered = 0;
 Index: sys/dev/usb/ehci.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/ehci.c,v
 retrieving revision 1.205
 diff -u -p -u -r1.205 ehci.c
 --- sys/dev/usb/ehci.c	1 Feb 2013 12:53:47 -0000	1.205
 +++ sys/dev/usb/ehci.c	29 Mar 2013 16:48:04 -0000
 @@ -3377,6 +3377,7 @@ ehci_device_request(usbd_xfer_handle xfe

  	sqh = epipe->sqh;

 +#if 0
  	/*
  	 * Update device address and length since they may have changed
  	 * during the setup of the control pipe in usbd_new_device().
 @@ -3389,7 +3390,7 @@ ehci_device_request(usbd_xfer_handle xfe
  	     EHCI_QH_SET_ADDR(addr) |
  	     EHCI_QH_SET_MPL(UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize))
  	    );
 -
 +#endif
  	/* Set up data transaction */
  	if (len != 0) {
  		ehci_soft_qtd_t *end;


 --------------070609000900090003060700--

From: kato@wide.ad.jp
To: skrll@netbsd.org
Cc: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Tue, 02 Apr 2013 15:39:44 +0900 (JST)

 Dear Nick,

 When applied with netbsd-6 tree, in 11 trials, the USB keyboard didn't
 recognize correctly out of 20 trials. The diff was as follows:

 Index: usb_subr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/usb_subr.c,v
 retrieving revision 1.180
 diff -u -p -u -r1.180 usb_subr.c
 --- usb_subr.c	9 Jun 2011 19:08:33 -0000	1.180
 +++ usb_subr.c	2 Apr 2013 06:37:13 -0000
 @@ -1219,14 +1219,6 @@ usbd_new_device(device_t parent, usbd_bu
  	dev->address = addr;	/* new device address now */
  	bus->devices[addr] = dev;

 -	err = usbd_reload_device_desc(dev);
 -	if (err) {
 -		DPRINTFN(-1, ("usbd_new_device: addr=%d, getting full desc "
 -			      "failed\n", addr));
 -		usbd_remove_device(dev, up);
 -		return (err);
 -	}
 -
  	/* Re-establish the default pipe with the new address. */
  	usbd_kill_pipe(dev->default_pipe);
  	err = usbd_setup_pipe(dev, 0, &dev->def_ep, USBD_DEFAULT_INTERVAL,
 @@ -1237,6 +1229,14 @@ usbd_new_device(device_t parent, usbd_bu
  		return err;
  	}

 +	err = usbd_reload_device_desc(dev);
 +	if (err) {
 +		DPRINTFN(-1, ("usbd_new_device: addr=%d, getting full desc "
 +			      "failed\n", addr));
 +		usbd_remove_device(dev, up);
 +		return (err);
 +	}
 +
  	/* Assume 100mA bus powered for now. Changed when configured. */
  	dev->power = USB_MIN_POWER;
  	dev->self_powered = 0;
 Index: ehci.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/ehci.c,v
 retrieving revision 1.183
 diff -u -p -u -r1.183 ehci.c
 --- ehci.c	23 Dec 2011 00:51:43 -0000	1.183
 +++ ehci.c	2 Apr 2013 06:37:28 -0000
 @@ -3271,7 +3271,9 @@ ehci_device_request(usbd_xfer_handle xfe
  	usb_device_request_t *req = &xfer->request;
  	usbd_device_handle dev = epipe->pipe.device;
  	ehci_softc_t *sc = dev->bus->hci_private;
 +#if 0
  	int addr = dev->address;
 +#endif
  	ehci_soft_qtd_t *setup, *stat, *next;
  	ehci_soft_qh_t *sqh;
  	int isread;
 @@ -3302,6 +3304,7 @@ ehci_device_request(usbd_xfer_handle xfe
  	sqh = epipe->sqh;
  	epipe->u.ctl.length = len;

 +#if 0
  	/* Update device address and length since they may have changed
  	   during the setup of the control pipe in usbd_new_device(). */
  	/* XXX This only needs to be done once, but it's too early in open. */
 @@ -3312,6 +3315,7 @@ ehci_device_request(usbd_xfer_handle xfe
  	     EHCI_QH_SET_ADDR(addr) |
  	     EHCI_QH_SET_MPL(UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize))
  	    );
 +#endif

  	/* Set up data transaction */
  	if (len != 0) {

From: Nick Hudson <nick.hudson@gmx.co.uk>
To: gnats-bugs@NetBSD.org
Cc: kato@wide.ad.jp, kern-bug-people@netbsd.org, gnats-admin@netbsd.org, 
 netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696: uhub disables port where USB keyboard attached
Date: Tue, 02 Apr 2013 07:48:36 +0100

 On 02/04/2013 07:40, kato@wide.ad.jp wrote:
 > The following reply was made to PR kern/46696; it has been noted by GNATS.
 >
 > From: kato@wide.ad.jp
 > To: skrll@netbsd.org
 > Cc: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
 >   gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, mishka@NetBSD.org
 > Subject: Re: kern/46696: uhub disables port where USB keyboard attached
 > Date: Tue, 02 Apr 2013 15:39:44 +0900 (JST)
 >
 >   Dear Nick,
 >   
 >   When applied with netbsd-6 tree, in 11 trials, the USB keyboard didn't
 >   recognize correctly out of 20 trials.

 Did you manage to get a log of how it fails?

 Thanks,
 Nick

Responsible-Changed-From-To: kern-bug-people->skrll
Responsible-Changed-By: skrll@NetBSD.org
Responsible-Changed-When: Mon, 02 Sep 2013 08:57:06 +0000
Responsible-Changed-Why:
Take


From: Nick Hudson <skrll@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: skrll@NetBSD.org, kern-bug-people@netbsd.org, netbsd-bugs@netbsd.org, 
 gnats-admin@netbsd.org, mishka@NetBSD.org, kato@wide.ad.jp, 
 Andreas Gustafsson <gson@gson.org>
Subject: Re: kern/46696 (uhub disables port where USB keyboard attached)
Date: Thu, 12 Sep 2013 10:05:40 +0100

 This is a multi-part message in MIME format.
 --------------070807020102050203040702
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit

 Can you test today's -current again and then try -current with this 
 patch and report results.

 Thanks,
 Nick


 --------------070807020102050203040702
 Content-Type: text/plain; charset=us-ascii;
  name="pr.46696.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="pr.46696.diff"

 Index: sys/dev/usb/usb_subr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/usb_subr.c,v
 retrieving revision 1.192
 diff -u -p -r1.192 usb_subr.c
 --- sys/dev/usb/usb_subr.c	7 Sep 2013 16:39:15 -0000	1.192
 +++ sys/dev/usb/usb_subr.c	12 Sep 2013 09:01:29 -0000
 @@ -1059,34 +1059,6 @@ usbd_reattach_device(device_t parent, us
  }

  /*
 - * Get the first 8 bytes of the device descriptor.
 - * Do as Windows does: try to read 64 bytes -- there are devices which
 - * recognize the initial descriptor fetch (before the control endpoint's
 - * MaxPacketSize is known by the host) by exactly this length.
 - */
 -static usbd_status
 -usbd_get_initial_ddesc(usbd_device_handle dev, usb_device_descriptor_t *desc)
 -{
 -	usb_device_request_t req;
 -	char buf[64];
 -	int res, actlen;
 -
 -	req.bmRequestType = UT_READ_DEVICE;
 -	req.bRequest = UR_GET_DESCRIPTOR;
 -	USETW2(req.wValue, UDESC_DEVICE, 0);
 -	USETW(req.wIndex, 0);
 -	USETW(req.wLength, 64);
 -	res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
 -		&actlen, USBD_DEFAULT_TIMEOUT);
 -	if (res)
 -		return res;
 -	if (actlen < 8)
 -		return USBD_SHORT_XFER;
 -	memcpy(desc, buf, 8);
 -	return USBD_NORMAL_COMPLETION;
 -}
 -
 -/*
   * Called when a new device has been put in the powered state,
   * but not yet in the addressed state.
   * Get initial descriptor, set the address, get full descriptor,
 @@ -1130,7 +1102,6 @@ usbd_new_device(device_t parent, usbd_bu
  	dev->def_ep_desc.bmAttributes = UE_CONTROL;
  	/*
  	 * temporary, will be fixed after first descriptor fetch
 -	 * (which uses 64 bytes so it shouldn't be less),
  	 * highspeed devices must support 64 byte packets anyway
  	 */
  	if (speed == USB_SPEED_HIGH || speed == USB_SPEED_FULL)
 @@ -1183,14 +1154,44 @@ usbd_new_device(device_t parent, usbd_bu
  	}

  	dd = &dev->ddesc;
 -	/* Try a few times in case the device is slow (i.e. outside specs.) */
 -	for (i = 0; i < 10; i++) {
 -		/* Get the first 8 bytes of the device descriptor. */
 -		err = usbd_get_initial_ddesc(dev, dd);
 +
 +	/*
 +	 * Get the first 8 bytes of the device descriptor.
 +	 *
 +	 * Try a few times in case the device is slow (i.e. outside specs.),
 +	 * and alternate between read lengths.
 +	 *
 +	 * Do as Windows does: try to read 64 bytes -- there are devices
 +	 * which recognize the initial descriptor fetch (before the
 +	 * control endpoint's MaxPacketSize is known by the host) by
 +	 * exactly this length.
 +	 *
 +	 * If this doesn't work, then attempt to read just the 8 bytes.
 +	 *
 +	 * Throw in a reset after 3 read attempts so that the device
 +	 * will see an initial read after reset of both 64 and 8 over
 +	 * time.
 +	 */
 +	for (i = 0; i < 12; i++) {
 +		usb_device_request_t req;
 +		char buf[64];
 +		int actlen;
 +
 +		req.bmRequestType = UT_READ_DEVICE;
 +		req.bRequest = UR_GET_DESCRIPTOR;
 +		USETW2(req.wValue, UDESC_DEVICE, 0);
 +		USETW(req.wIndex, 0);
 +		USETW(req.wLength, (i % 2 == 0 ? 64 : 8));
 +		err = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
 +			&actlen, USBD_DEFAULT_TIMEOUT);
 +		if (actlen < 8)
 +			continue;
 +		memcpy(dd, buf, 8);
 +
  		if (!err)
  			break;
  		usbd_delay_ms(dev, 200);
 -		if ((i & 3) == 3)
 +		if ((i % 3) == 2)
  			usbd_reset_port(up->parent, port, &ps);
  	}
  	if (err) {

 --------------070807020102050203040702--

From: Andreas Gustafsson <gson@gson.org>
To: Nick Hudson <skrll@netbsd.org>
Cc: gnats-bugs@NetBSD.org,
    kern-bug-people@netbsd.org,
    netbsd-bugs@netbsd.org,
    gnats-admin@netbsd.org,
    mishka@NetBSD.org,
    kato@wide.ad.jp
Subject: Re: kern/46696 (uhub disables port where USB keyboard attached)
Date: Sat, 14 Sep 2013 12:06:49 +0300

 Nick Hudson wrote:
 > Can you test today's -current again and then try -current with this 
 > patch and report results.

 I have now tested this using -current sources from 2013.09.12.07.26.13.

 With the unmodified -current soruces (without your patch), I got
 "uhub2: device problem, disabling port 2" in 4 boots out of 10.

 With your patch, I got "uhub2: device problem, disabling port 2"
 in 5 boots out of 10.  In other words, the patch made no statistically
 significant difference.

 Here is a diff between the relevant parts of the dmesg output from a
 successful boot and an unsuccessful one:

   < uhidev0 at uhub2 port 2 configuration 1 interface 0
   < uhidev0: Belkin Components USB-PS2 Adapter, rev 1.10/1.20, addr 3, iclass 3/1
   < ukbd0 at uhidev0: 8 modifier keys, 6 key codes
   < wskbd0 at ukbd0: console keyboard, using wsdisplay0
   < uhidev1 at uhub2 port 2 configuration 1 interface 1
   < uhidev1: Belkin Components USB-PS2 Adapter, rev 1.10/1.20, addr 3, iclass 3/1
   < ums0 at uhidev1: 5 buttons and Z dir
   < wsmouse0 at ums0 mux 0
   ---
   > uhub2: device problem, disabling port 2

 Thank you for looking into this, and if there are any more tests I can
 run, I will be happy to do so.
 -- 
 Andreas Gustafsson, gson@gson.org

From: Andreas Gustafsson <gson@gson.org>
To: Nick Hudson <skrll@netbsd.org>
Cc: gnats-bugs@NetBSD.org,
    kern-bug-people@netbsd.org,
    netbsd-bugs@netbsd.org,
    gnats-admin@netbsd.org,
    mishka@NetBSD.org,
    kato@wide.ad.jp
Subject: Re: kern/46696 (uhub disables port where USB keyboard attached)
Date: Sat, 14 Sep 2013 16:59:18 +0300

 Nick,

 I also updated http://www.gson.org/netbsd/bugs/46696/usb.patch
 so that it applies against -current sources.  The new version is:

   http://www.gson.org/netbsd/bugs/46696/usb-kb-2013.09.12.07.26.13.patch

 With that patch, the  "uhub2: device problem, disabling port 2"
 message appeared in 0 (zero) out of 10 boots.
 -- 
 Andreas Gustafsson, gson@gson.org

From: Nick Hudson <skrll@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: Andreas Gustafsson <gson@gson.org>, gnats-admin@netbsd.org, 
 netbsd-bugs@netbsd.org, mishka@NetBSD.org
Subject: Re: kern/46696 (uhub disables port where USB keyboard attached)
Date: Sun, 15 Sep 2013 19:37:12 +0100

 On 09/14/13 10:10, Andreas Gustafsson wrote:
 >   
 >   Thank you for looking into this, and if there are any more tests I can
 >   run, I will be happy to do so.

 Hi,

 What's your full dmesg?

 The output from usbdebug and uhubdebug set to 11 would be helpful.

 Thanks,
 Nick

From: Andreas Gustafsson <gson@gson.org>
To: Nick Hudson <skrll@netbsd.org>
Cc: gnats-bugs@NetBSD.org,
    Andreas Gustafsson <gson@gson.org>,
    gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org,
    mishka@NetBSD.org
Subject: Re: kern/46696 (uhub disables port where USB keyboard attached)
Date: Mon, 16 Sep 2013 00:19:05 +0300

 Hi Nick,

 You wrote:
 > What's your full dmesg?

 The one in http://gnats.netbsd.org/48214 will do (same machine, same
 -current, and even happened to hit this bug in that particular boot).

 > The output from usbdebug and uhubdebug set to 11 would be helpful.

 I changed the initializations of usbdebug and uhubdebug to 11 in usb.c
 and uhub.c, respectively, and built a kernel with options USB_DEBUG
 and MSGBUFSIZE=262144 (but not UHUB_DEBUG, an oversight on my part).
 Your patch was applied.

 This kernel booted successfully 25 times in a row without problems.
 Looks like we are dealing with a Heisenbug.

 To double-check, I set usbdebug and uhubdebug back to 0 by patching
 the kernel binary and rebooted again, and the problem was back.  The
 output was now a bit more verbose than without the USB_DEBUG option
 (despite usbdebug being 0):

   uhub3: 8 ports with 8 removable, self powered
   usbd_new_device: set address 3 failed
   uhub_explore: usbd_new_device failed, error=SET_ADDR_FAILED
   uhub2: device problem, disabling port 3

 I'm not including the usbdebug=11 output here since it doesn't show
 the problem happening, but if you want it anyway, let me know.
 -- 
 Andreas Gustafsson, gson@gson.org

From: "Nick Hudson" <skrll@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/46696 CVS commit: src/sys/dev/usb
Date: Sun, 1 Dec 2013 07:34:16 +0000

 Module Name:	src
 Committed By:	skrll
 Date:		Sun Dec  1 07:34:16 UTC 2013

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

 Log Message:
 In ehci_check_qh_intr don't treat a short control transfer as done if the
 status phase is still inflight.  Let the hardware complete it.

 PR/48358: Repeated low-speed USB control transfers returning short data
 	  fail on EHCI

 PR/46696: uhub disables port where USB keyboard attached


 To generate a diff of this commit:
 cvs rdiff -u -r1.220 -r1.221 src/sys/dev/usb/ehci.c

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

State-Changed-From-To: feedback->pending-pullups
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Sun, 01 Dec 2013 14:18:56 +0000
State-Changed-Why:
pullup-6 #990


From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/46696 CVS commit: [netbsd-6] src/sys/dev/usb
Date: Sat, 14 Dec 2013 19:26:39 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Sat Dec 14 19:26:39 UTC 2013

 Modified Files:
 	src/sys/dev/usb [netbsd-6]: ehci.c

 Log Message:
 Pull up following revision(s) (requested by skrll in ticket #990):
 	sys/dev/usb/ehci.c: revision 1.221
 In ehci_check_qh_intr don't treat a short control transfer as done if the
 status phase is still inflight.  Let the hardware complete it.
 PR/48358: Repeated low-speed USB control transfers returning short data
 	  fail on EHCI
 PR/46696: uhub disables port where USB keyboard attached


 To generate a diff of this commit:
 cvs rdiff -u -r1.183.2.1 -r1.183.2.2 src/sys/dev/usb/ehci.c

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

State-Changed-From-To: pending-pullups->closed
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Sat, 14 Dec 2013 20:26:21 +0000
State-Changed-Why:
pullup complete


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.