Bug 181159 - [ugen] Problem attaching USB device
Summary: [ugen] Problem attaching USB device
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-usb mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-09 13:00 UTC by Antonios Anastasiadis
Modified: 2019-07-15 10:26 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antonios Anastasiadis 2013-08-09 13:00:00 UTC
Using 9.2-RC1 system compiled with clang. The system is installed on a Hetzner EX40-SSD server.

The problem is that a USB device cannot be attached. The device is from the company Peppercon/Raritan that allows the remote control of a server. It is connected to the VGA, keyboard and mouse ports of the server.

The exact error from the kernel output is:

usb_alloc_device: device init 2 failed (USB_ERR_IOERROR, ignored)
ugen0.2: <Unknown> at usbus0 (disconnected)
uhub_reattach_port: could not allocate new device

I've managed to boot with an older 9.1-RELEASE kernel, which correctly attaches the USB device, so I can gather more information. The full dmesg output follows:

Copyright (c) 1992-2012 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
	The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 9.1-RELEASE #3 r243710M: Tue Apr 23 10:52:10 CEST 2013
    root@FreeBSD:/usr/obj/usr/src/sys/GENERIC amd64
module vtnet already present!
CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz (3400.07-MHz K8-class CPU)
  Origin = "GenuineIntel"  Id = 0x306c3  Family = 6  Model = 3c  Stepping = 3
  Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
  Features2=0x7ffafbff<SSE3,PCLMULQDQ,DTES64,MON,DS_CPL,VMX,SMX,EST,TM2,SSSE3,<b11>,FMA,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,TSCDLT,AESNI,XSAVE,OSXSAVE,AVX,F16C,RDRAND>
  AMD Features=0x2c100800<SYSCALL,NX,Page1GB,RDTSCP,LM>
  AMD Features2=0x21<LAHF,ABM>
  TSC: P-state invariant, performance statistics
real memory  = 34359738368 (32768 MB)
avail memory = 32882135040 (31358 MB)
Event timer "LAPIC" quality 600
ACPI APIC Table: <ALASKA A M I>
FreeBSD/SMP: Multiprocessor System Detected: 8 CPUs
FreeBSD/SMP: 1 package(s) x 4 core(s) x 2 SMT threads
 cpu0 (BSP): APIC ID:  0
 cpu1 (AP): APIC ID:  1
 cpu2 (AP): APIC ID:  2
 cpu3 (AP): APIC ID:  3
 cpu4 (AP): APIC ID:  4
 cpu5 (AP): APIC ID:  5
 cpu6 (AP): APIC ID:  6
 cpu7 (AP): APIC ID:  7
ACPI Warning: FADT (revision 5) is longer than ACPI 2.0 version, truncating length 268 to 244 (20110527/tbfadt-320)
ioapic0 <Version 2.0> irqs 0-23 on motherboard
kbd1 at kbdmux0
acpi0: <ALASKA A M I> on motherboard
acpi0: Power Button (fixed)
acpi0: reservation of 67, 1 (4) failed
cpu0: <ACPI CPU> on acpi0
cpu1: <ACPI CPU> on acpi0
cpu2: <ACPI CPU> on acpi0
cpu3: <ACPI CPU> on acpi0
cpu4: <ACPI CPU> on acpi0
cpu5: <ACPI CPU> on acpi0
cpu6: <ACPI CPU> on acpi0
cpu7: <ACPI CPU> on acpi0
hpet0: <High Precision Event Timer> iomem 0xfed00000-0xfed003ff on acpi0
Timecounter "HPET" frequency 14318180 Hz quality 950
Event timer "HPET" frequency 14318180 Hz quality 550
atrtc0: <AT realtime clock> port 0x70-0x77 irq 8 on acpi0
atrtc0: Warning: Couldn't map I/O.
Event timer "RTC" frequency 32768 Hz quality 0
attimer0: <AT timer> port 0x40-0x43,0x50-0x53 irq 0 on acpi0
Timecounter "i8254" frequency 1193182 Hz quality 0
Event timer "i8254" frequency 1193182 Hz quality 100
Timecounter "ACPI-fast" frequency 3579545 Hz quality 900
acpi_timer0: <24-bit timer at 3.579545MHz> port 0x1808-0x180b on acpi0
pcib0: <ACPI Host-PCI bridge> port 0xcf8-0xcff on acpi0
pci0: <ACPI PCI bus> on pcib0
vgapci0: <VGA-compatible display> port 0xf000-0xf03f mem 0xf7800000-0xf7bfffff,0xe0000000-0xefffffff irq 16 at device 2.0 on pci0
xhci0: <XHCI (generic) USB 3.0 controller> mem 0xf7c00000-0xf7c0ffff irq 16 at device 20.0 on pci0
xhci0: 32 byte context size.
usbus0 on xhci0
pci0: <simple comms> at device 22.0 (no driver attached)
ehci0: <EHCI (generic) USB 2.0 controller> mem 0xf7c14000-0xf7c143ff irq 16 at device 26.0 on pci0
usbus1: EHCI version 1.0
usbus1 on ehci0
pcib1: <ACPI PCI-PCI bridge> irq 16 at device 28.0 on pci0
pci1: <ACPI PCI bus> on pcib1
pcib2: <ACPI PCI-PCI bridge> irq 17 at device 28.1 on pci0
pci2: <ACPI PCI bus> on pcib2
re0: <RealTek 8168/8111 B/C/CP/D/DP/E/F PCIe Gigabit Ethernet> port 0xe000-0xe0ff mem 0xf0004000-0xf0004fff,0xf0000000-0xf0003fff irq 17 at device 0.0 on pci2
re0: Using 1 MSI-X message
re0: ASPM disabled
re0: Chip rev. 0x2c800000
re0: MAC rev. 0x00000000
miibus0: <MII bus> on re0
rgephy0: <RTL8169S/8110S/8211 1000BASE-T media interface> PHY 1 on miibus0
rgephy0:  none, 10baseT, 10baseT-FDX, 10baseT-FDX-flow, 100baseTX, 100baseTX-FDX, 100baseTX-FDX-flow, 1000baseT, 1000baseT-master, 1000baseT-FDX, 1000baseT-FDX-master, 1000baseT-FDX-flow, 1000baseT-FDX-flow-master, auto, auto-flow
re0: Ethernet address: d4:3d:7e:be:d6:b7
pcib3: <ACPI PCI-PCI bridge> irq 19 at device 28.3 on pci0
pci3: <ACPI PCI bus> on pcib3
pcib4: <ACPI PCI-PCI bridge> irq 19 at device 0.0 on pci3
pci4: <ACPI PCI bus> on pcib4
ehci1: <EHCI (generic) USB 2.0 controller> mem 0xf7c13000-0xf7c133ff irq 23 at device 29.0 on pci0
usbus2: EHCI version 1.0
usbus2 on ehci1
isab0: <PCI-ISA bridge> at device 31.0 on pci0
isa0: <ISA bus> on isab0
ahci0: <AHCI SATA controller> port 0xf0b0-0xf0b7,0xf0a0-0xf0a3,0xf090-0xf097,0xf080-0xf083,0xf060-0xf07f mem 0xf7c12000-0xf7c127ff irq 19 at device 31.2 on pci0
ahci0: AHCI v1.30 with 6 6Gbps ports, Port Multiplier not supported
ahcich0: <AHCI channel> at channel 0 on ahci0
ahcich1: <AHCI channel> at channel 1 on ahci0
pci0: <serial bus, SMBus> at device 31.3 (no driver attached)
acpi_button0: <Power Button> on acpi0
acpi_tz0: <Thermal Zone> on acpi0
acpi_tz1: <Thermal Zone> on acpi0
atkbdc0: <Keyboard controller (i8042)> port 0x60,0x64 irq 1 on acpi0
atkbd0: <AT Keyboard> irq 1 on atkbdc0
kbd0 at atkbd0
atkbd0: [GIANT-LOCKED]
uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 on acpi0
ppc0: <Parallel port> port 0x378-0x37f irq 5 on acpi0
ppc0: Generic chipset (NIBBLE-only) in COMPATIBLE mode
ppbus0: <Parallel port bus> on ppc0
plip0: <PLIP network interface> on ppbus0
lpt0: <Printer> on ppbus0
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0
orm0: <ISA Option ROM> at iomem 0xcf000-0xcffff on isa0
sc0: <System console> on isa0
sc0: VGA <16 virtual consoles, flags=0x300>
vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0
ctl: CAM Target Layer loaded
est0: <Enhanced SpeedStep Frequency Control> on cpu0
p4tcc0: <CPU Frequency Thermal Control> on cpu0
est1: <Enhanced SpeedStep Frequency Control> on cpu1
p4tcc1: <CPU Frequency Thermal Control> on cpu1
est2: <Enhanced SpeedStep Frequency Control> on cpu2
p4tcc2: <CPU Frequency Thermal Control> on cpu2
est3: <Enhanced SpeedStep Frequency Control> on cpu3
p4tcc3: <CPU Frequency Thermal Control> on cpu3
est4: <Enhanced SpeedStep Frequency Control> on cpu4
p4tcc4: <CPU Frequency Thermal Control> on cpu4
est5: <Enhanced SpeedStep Frequency Control> on cpu5
p4tcc5: <CPU Frequency Thermal Control> on cpu5
est6: <Enhanced SpeedStep Frequency Control> on cpu6
p4tcc6: <CPU Frequency Thermal Control> on cpu6
est7: <Enhanced SpeedStep Frequency Control> on cpu7
p4tcc7: <CPU Frequency Thermal Control> on cpu7
Timecounters tick every 1.000 msec
md0: Preloaded image </mfsroot> 43638784 bytes at 0xffffffff81549d48
usbus0: 5.0Gbps Super Speed USB v3.0
usbus1: 480Mbps High Speed USB v2.0
usbus2: 480Mbps High Speed USB v2.0
ugen0.1: <0x8086> at usbus0
uhub0: <0x8086 XHCI root HUB, class 9/0, rev 3.00/1.00, addr 1> on usbus0
ugen1.1: <Intel> at usbus1
uhub1: <Intel EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1> on usbus1
ugen2.1: <Intel> at usbus2
uhub2: <Intel EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1> on usbus2
uhub1: 2 ports with 2 removable, self powered
uhub2: 2 ports with 2 removable, self powered
uhub0: 21 ports with 21 removable, self powered
ugen1.2: <vendor 0x8087> at usbus1
uhub3: <vendor 0x8087 product 0x8008, class 9/0, rev 2.00/0.04, addr 2> on usbus1
ugen2.2: <vendor 0x8087> at usbus2
uhub4: <vendor 0x8087 product 0x8000, class 9/0, rev 2.00/0.04, addr 2> on usbus2
uhub3: 6 ports with 6 removable, self powered
uhub4: 8 ports with 8 removable, self powered
ugen2.3: <CHESEN> at usbus2
ukbd0: <CHESEN PS2 to USB Converter, class 0/0, rev 1.10/0.10, addr 3> on usbus2
kbd2 at ukbd0
ums0: <CHESEN PS2 to USB Converter, class 0/0, rev 1.10/0.10, addr 3> on usbus2
ums0: 5 buttons and [XYZ] coordinates ID=1
ugen2.4: <Peppercon AG> at usbus2
ukbd1: <Peppercon AG Multidevice, class 0/0, rev 2.00/0.01, addr 4> on usbus2
kbd3 at ukbd1
uhid0: <Peppercon AG Multidevice, class 0/0, rev 2.00/0.01, addr 4> on usbus2
umass0: <Peppercon AG Multidevice, class 0/0, rev 2.00/0.01, addr 4> on usbus2
umass0:  SCSI over Bulk-Only; quirks = 0x0000
umass0:3:0:-1: Attached to scbus3
ada0 at ahcich0 bus 0 scbus0 target 0 lun 0
ada0: <INTEL SSDSC2CW240A3 400i> ATA-9 SATA 3.x device
ada0: 600.000MB/s transfers (SATA 3.x, UDMA6, PIO 8192bytes)
ada0: Command Queueing enabled
ada0: 228936MB (468862128 512 byte sectors: 16H 63S/T 16383C)
ada0: Previously was known as ad4
ada1 at ahcich1 bus 0 scbus1 target 0 lun 0
ada1: <INTEL SSDSC2CW240A3 400i> ATA-9 SATA 3.x device
ada1: 600.000MB/s transfers (SATA 3.x, UDMA6, PIO 8192bytes)
ada1: Command Queueing enabled
ada1: 228936MB (468862128 512 byte sectors: 16H 63S/T 16383C)
ada1: Previously was known as ad6
SMP: AP CPU #1 Launched!
cd0 at umass-sim0 bus 0 scbus3 target 0 lun 0
cd0: <PepperC Virtual Disc 1 0.01> Removable CD-ROM SCSI-3 device 
cd0: 1.000MB/s transfers
cd0: Attempt to query device size failed: NOT READY, Medium not present
SMP: AP CPU #6 Launched!
SMP: AP CPU #3 Launched!
SMP: AP CPU #7 Launched!
SMP: AP CPU #2 Launched!
SMP: AP CPU #4 Launched!
SMP: AP CPU #5 Launched!
Timecounter "TSC-low" frequency 13281512 Hz quality 1000
Trying to mount root from ufs:/dev/md0 []...

How-To-Repeat: Boot the system with an 9.2-RC1 kernel.
Comment 1 HPS 2013-08-09 21:25:31 UTC
On 08/09/13 13:58, Antonis Anastasiadis wrote:
>
>> Number:         181159
>> Category:       usb
>> Synopsis:       Problem attaching USB device
>> Confidential:   no
>> Severity:       non-critical
>> Priority:       low
>> Responsible:    freebsd-usb
>> State:          open
>> Quarter:
>> Keywords:
>> Date-Required:
>> Class:          sw-bug
>> Submitter-Id:   current-users
>> Arrival-Date:   Fri Aug 09 12:00:00 UTC 2013
>> Closed-Date:
>> Last-Modified:
>> Originator:     Antonis Anastasiadis
>> Release:        9.2-RC1
>> Organization:
>> Environment:
>> Description:
> Using 9.2-RC1 system compiled with clang. The system is installed on a Hetzner EX40-SSD server.
>
> The problem is that a USB device cannot be attached. The device is from the company Peppercon/Raritan that allows the remote control of a server.
 > It is connected to the VGA, keyboard and mouse ports of the server.
>

Hi,

There are some debug parameters under:

sysctl hw.usb.timings

Which might affect the behavior of your device. Make sure you have the 
XHCI patch for 9.2-RC1 which was in a big late, if you compiled the code 
yourself.

> The exact error from the kernel output is:
>
> usb_alloc_device: device init 2 failed (USB_ERR_IOERROR, ignored)
> ugen0.2: <Unknown> at usbus0 (disconnected)
> uhub_reattach_port: could not allocate new device
>

Could you show the dmesg about which USB controller is at usbus0 in the 
non-working case?

--HPS
Comment 2 Antonios Anastasiadis 2013-08-10 11:31:32 UTC
Thank you for your quick response.

=D3=F4=E9=F2 9 =C1=F5=E3 2013, 11:25 =EC.=EC., =EF/=E7 Hans Petter =
Selasky <hps@bitfrost.no> =DD=E3=F1=E1=F8=E5:

> Hi,
>=20
> There are some debug parameters under:
>=20
> sysctl hw.usb.timings

I've got no idea how to tune those.

> Which might affect the behavior of your device. Make sure you have the =
XHCI patch for 9.2-RC1 which was in a big late, if you compiled the code =
yourself.

The source was ~2 days old. I just updated and recompiled the kernel =
today. The issue persists.

> Could you show the dmesg about which USB controller is at usbus0 in =
the non-working case?

usbus0 on xhci0
usbus0: 5.0Gbps Super Speed USB v3.0

The m/b is an MSI MS-7816 with the Intel=AE Z87 Express Chipset.=
Comment 3 HPS 2013-08-10 14:52:39 UTC
On 08/10/13 12:31, Antonis Anastasiadis wrote:
> Thank you for your quick response.
>
> Óôéò 9 Áõã 2013, 11:25 ì.ì., ï/ç Hans Petter Selasky <hps@bitfrost.no> Ýãñáøå:
>
>> Hi,
>>
>> There are some debug parameters under:
>>
>> sysctl hw.usb.timings
>
> I've got no idea how to tune those.

Try to double the values one by one.

Any change?

Need to reboot or re-plug the device before testing.

--HPS
>
>> Which might affect the behavior of your device. Make sure you have the XHCI patch for 9.2-RC1 which was in a big late, if you compiled the code yourself.
>
> The source was ~2 days old. I just updated and recompiled the kernel today. The issue persists.
>
>> Could you show the dmesg about which USB controller is at usbus0 in the non-working case?
>
> usbus0 on xhci0
> usbus0: 5.0Gbps Super Speed USB v3.0
>
> The m/b is an MSI MS-7816 with the Intel® Z87 Express Chipset.
>
Comment 4 Antonios Anastasiadis 2013-08-10 15:53:47 UTC
=D3=F4=E9=F2 10 =C1=F5=E3 2013, 4:52 =EC.=EC., =EF/=E7 Hans Petter =
Selasky <hps@bitfrost.no> =DD=E3=F1=E1=F8=E5:
>=20
> Try to double the values one by one.
>=20
> Any change?
>=20
> Need to reboot or re-plug the device before testing.
>=20

I've managed to up them until the following values, rebooting after each =
change.

hw.usb.timings.port_reset_delay: 800
hw.usb.timings.port_root_reset_delay: 4000
hw.usb.timings.port_reset_recovery: 4000
hw.usb.timings.port_powerup_delay: 300
hw.usb.timings.port_resume_delay: 640
hw.usb.timings.set_address_settle: 160
hw.usb.timings.resume_delay: 4000
hw.usb.timings.resume_wait: 800
hw.usb.timings.resume_recovery: 800
hw.usb.timings.extra_power_up_time: 320

The problem still persists, although the dmesg flood rate is =
considerably smaller now. I guess this is to be expected.

Unfortunately, this USB device is allocated by request for =
troubleshooting purposes, and I cannot have access to it for more than a =
few hours at a time.=
Comment 5 HPS 2013-08-10 15:57:58 UTC
On 08/10/13 16:53, Antonis Anastasiadis wrote:
>
> Óôéò 10 Áõã 2013, 4:52 ì.ì., ï/ç Hans Petter Selasky <hps@bitfrost.no> Ýãñáøå:
>>
>> Try to double the values one by one.
>>
>> Any change?
>>
>> Need to reboot or re-plug the device before testing.
>>
>
> I've managed to up them until the following values, rebooting after each change.
>
> hw.usb.timings.port_reset_delay: 800
> hw.usb.timings.port_root_reset_delay: 4000
> hw.usb.timings.port_reset_recovery: 4000
> hw.usb.timings.port_powerup_delay: 300
> hw.usb.timings.port_resume_delay: 640
> hw.usb.timings.set_address_settle: 160
> hw.usb.timings.resume_delay: 4000
> hw.usb.timings.resume_wait: 800
> hw.usb.timings.resume_recovery: 800
> hw.usb.timings.extra_power_up_time: 320
>
> The problem still persists, although the dmesg flood rate is considerably smaller now. I guess this is to be expected.
>
> Unfortunately, this USB device is allocated by request for troubleshooting purposes, and I cannot have access to it for more than a few hours at a time.
>

Hi,

I'll check the code a bit later today or tomorrow. What you could try is 
to identify the parent HUB or RootHUB and then set config 255 , then 
config 0. Maybe the device will enumerate then.

usbconfig -d X.1 set_config 255
usbconfig -d X.1 set_config 0

--HPS
Comment 6 Antonios Anastasiadis 2013-08-12 13:42:41 UTC
2013/8/10 Hans Petter Selasky <hps@bitfrost.no>:
<snip>
> What you could try is to
> identify the parent HUB or RootHUB and then set config 255 , then config 0.
> Maybe the device will enumerate then.

No change. The HUB is reset as I can see from the dmesg, but the
device refuses to enumerate.
Comment 7 dfilter service freebsd_committer 2013-09-21 22:41:05 UTC
Author: hselasky
Date: Sat Sep 21 21:40:57 2013
New Revision: 255768
URL: http://svnweb.freebsd.org/changeset/base/255768

Log:
  Stability fixes for Intel LynxPoint XHCI controllers. Disable XHCI port
  routing if we get certain errors. Poll for command completion upon
  command timeouts. The XHCI error events might not generate interrupts.
  
  MFC after:	1 week
  Reported by:	Daniel Gerzo <danger@rulez.sk>, Antonis Anastasiadis <anastasiadis@datalive.gr>
  PR:		usb/181159
  Approved by:	re (gjb)

Modified:
  head/sys/dev/usb/controller/xhci.c
  head/sys/dev/usb/controller/xhci.h
  head/sys/dev/usb/controller/xhci_pci.c

Modified: head/sys/dev/usb/controller/xhci.c
==============================================================================
--- head/sys/dev/usb/controller/xhci.c	Sat Sep 21 21:36:09 2013	(r255767)
+++ head/sys/dev/usb/controller/xhci.c	Sat Sep 21 21:40:57 2013	(r255768)
@@ -108,6 +108,8 @@ TUNABLE_INT("hw.usb.xhci.xhci_port_route
 SYSCTL_INT(_hw_usb_xhci, OID_AUTO, use_polling, CTLFLAG_RW | CTLFLAG_TUN,
     &xhcipolling, 0, "Set to enable software interrupt polling for XHCI controller");
 TUNABLE_INT("hw.usb.xhci.use_polling", &xhcipolling);
+#else
+#define	xhciroute 0
 #endif
 
 #define	XHCI_INTR_ENDPT 1
@@ -194,16 +196,6 @@ xhci_dump_device(struct xhci_softc *sc, 
 }
 #endif
 
-uint32_t
-xhci_get_port_route(void)
-{
-#ifdef USB_DEBUG
-	return (0xFFFFFFFFU ^ ((uint32_t)xhciroute));
-#else
-	return (0xFFFFFFFFU);
-#endif
-}
-
 uint8_t
 xhci_use_polling(void)
 {
@@ -505,6 +497,11 @@ xhci_start_controller(struct xhci_softc 
 	/* catch any lost interrupts */
 	xhci_do_poll(&sc->sc_bus);
 
+	if (sc->sc_port_route != NULL) {
+		/* Route all ports to the XHCI by default */
+		sc->sc_port_route(sc->sc_bus.parent,
+		    ~xhciroute, xhciroute);
+	}
 	return (0);
 }
 
@@ -951,7 +948,7 @@ xhci_check_transfer(struct xhci_softc *s
 	}
 }
 
-static void
+static int
 xhci_check_command(struct xhci_softc *sc, struct xhci_trb *trb)
 {
 	if (sc->sc_cmd_addr == trb->qwTrb0) {
@@ -959,16 +956,19 @@ xhci_check_command(struct xhci_softc *sc
 		sc->sc_cmd_result[0] = trb->dwTrb2;
 		sc->sc_cmd_result[1] = trb->dwTrb3;
 		cv_signal(&sc->sc_cmd_cv);
+		return (1);	/* command match */
 	}
+	return (0);
 }
 
-static void
+static int
 xhci_interrupt_poll(struct xhci_softc *sc)
 {
 	struct usb_page_search buf_res;
 	struct xhci_hw_root *phwr;
 	uint64_t addr;
 	uint32_t temp;
+	int retval = 0;
 	uint16_t i;
 	uint8_t event;
 	uint8_t j;
@@ -1008,7 +1008,7 @@ xhci_interrupt_poll(struct xhci_softc *s
 			xhci_check_transfer(sc, &phwr->hwr_events[i]);
 			break;
 		case XHCI_TRB_EVENT_CMD_COMPLETE:
-			xhci_check_command(sc, &phwr->hwr_events[i]);
+			retval |= xhci_check_command(sc, &phwr->hwr_events[i]);
 			break;
 		default:
 			DPRINTF("Unhandled event = %u\n", event);
@@ -1045,6 +1045,8 @@ xhci_interrupt_poll(struct xhci_softc *s
 
 	XWRITE4(sc, runt, XHCI_ERDP_LO(0), (uint32_t)addr);
 	XWRITE4(sc, runt, XHCI_ERDP_HI(0), (uint32_t)(addr >> 32));
+
+	return (retval);
 }
 
 static usb_error_t
@@ -1132,7 +1134,15 @@ xhci_do_command(struct xhci_softc *sc, s
 	err = cv_timedwait(&sc->sc_cmd_cv, &sc->sc_bus.bus_mtx,
 	    USB_MS_TO_TICKS(timeout_ms));
 
-	if (err) {
+	/*
+	 * In some error cases event interrupts are not generated.
+	 * Poll one time to see if the command has completed.
+	 */
+	if (err != 0 && xhci_interrupt_poll(sc) != 0) {
+		DPRINTF("Command was completed when polling\n");
+		err = 0;
+	}
+	if (err != 0) {
 		DPRINTFN(0, "Command timeout!\n");
 		err = USB_ERR_TIMEOUT;
 		trb->dwTrb2 = 0;
@@ -1311,6 +1321,14 @@ xhci_set_address(struct usb_device *udev
 		    (address == 0), index);
 
 		if (err != 0) {
+			temp = le32toh(sc->sc_cmd_result[0]);
+			if (address == 0 && sc->sc_port_route != NULL &&
+			    XHCI_TRB_2_ERROR_GET(temp) ==
+			    XHCI_TRB_ERROR_PARAMETER) {
+				/* LynxPoint XHCI - ports are not switchable */
+				/* Un-route all ports from the XHCI */
+				sc->sc_port_route(sc->sc_bus.parent, 0, ~0);
+			}
 			DPRINTF("Could not set address "
 			    "for slot %u.\n", index);
 			if (address != 0)

Modified: head/sys/dev/usb/controller/xhci.h
==============================================================================
--- head/sys/dev/usb/controller/xhci.h	Sat Sep 21 21:36:09 2013	(r255767)
+++ head/sys/dev/usb/controller/xhci.h	Sat Sep 21 21:40:57 2013	(r255768)
@@ -431,6 +431,8 @@ union xhci_hub_desc {
 	uint8_t				temp[128];
 };
 
+typedef int (xhci_port_route_t)(device_t, uint32_t, uint32_t);
+
 struct xhci_softc {
 	struct xhci_hw_softc	sc_hw;
 	/* base device */
@@ -440,6 +442,8 @@ struct xhci_softc {
 
 	struct usb_callout	sc_callout;
 
+	xhci_port_route_t	*sc_port_route;
+
 	union xhci_hub_desc	sc_hub_desc;
 
 	struct cv		sc_cmd_cv;
@@ -502,7 +506,6 @@ struct xhci_softc {
 
 /* prototypes */
 
-uint32_t	xhci_get_port_route(void);
 uint8_t 	xhci_use_polling(void);
 usb_error_t xhci_halt_controller(struct xhci_softc *);
 usb_error_t xhci_init(struct xhci_softc *, device_t);

Modified: head/sys/dev/usb/controller/xhci_pci.c
==============================================================================
--- head/sys/dev/usb/controller/xhci_pci.c	Sat Sep 21 21:36:09 2013	(r255767)
+++ head/sys/dev/usb/controller/xhci_pci.c	Sat Sep 21 21:40:57 2013	(r255768)
@@ -146,6 +146,25 @@ xhci_interrupt_poll(void *_sc)
 }
 
 static int
+xhci_pci_port_route(device_t self, uint32_t set, uint32_t clear)
+{
+	uint32_t temp;
+
+	temp = pci_read_config(self, PCI_XHCI_INTEL_USB3_PSSEN, 4) |
+	    pci_read_config(self, PCI_XHCI_INTEL_XUSB2PR, 4);
+
+	temp |= set;
+	temp &= ~clear;
+
+	pci_write_config(self, PCI_XHCI_INTEL_USB3_PSSEN, temp, 4);
+	pci_write_config(self, PCI_XHCI_INTEL_XUSB2PR, temp, 4);
+
+	device_printf(self, "Port routing mask set to 0x%08x\n", temp);
+
+	return (0);
+}
+
+static int
 xhci_pci_attach(device_t self)
 {
 	struct xhci_softc *sc = device_get_softc(self);
@@ -189,7 +208,7 @@ xhci_pci_attach(device_t self)
 	    &sc->sc_irq_rid, RF_SHAREABLE | RF_ACTIVE);
 	if (sc->sc_irq_res == NULL) {
 		device_printf(self, "Could not allocate IRQ\n");
-		goto error;
+		/* goto error; FALLTHROUGH - use polling */
 	}
 	sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
 	if (sc->sc_bus.bdev == NULL) {
@@ -216,6 +235,16 @@ xhci_pci_attach(device_t self)
 		USB_BUS_UNLOCK(&sc->sc_bus);
 	}
 
+	/* On Intel chipsets reroute ports from EHCI to XHCI controller. */
+	switch (pci_get_devid(self)) {
+	case 0x1e318086:	/* Panther Point */
+	case 0x8c318086:	/* Lynx Point */
+		sc->sc_port_route = &xhci_pci_port_route;
+		break;
+	default:
+		break;
+	}
+
 	xhci_pci_take_controller(self);
 
 	err = xhci_halt_controller(sc);
@@ -284,7 +313,6 @@ static int
 xhci_pci_take_controller(device_t self)
 {
 	struct xhci_softc *sc = device_get_softc(self);
-	uint32_t device_id = pci_get_devid(self);
 	uint32_t cparams;
 	uint32_t eecp;
 	uint32_t eec;
@@ -325,13 +353,5 @@ xhci_pci_take_controller(device_t self)
 			usb_pause_mtx(NULL, hz / 100);	/* wait 10ms */
 		}
 	}
-
-	/* On Intel chipsets reroute ports from EHCI to XHCI controller. */
-	if (device_id == 0x1e318086 /* Panther Point */ ||
-	    device_id == 0x8c318086 /* Lynx Point */) {
-		uint32_t temp = xhci_get_port_route();
-		pci_write_config(self, PCI_XHCI_INTEL_USB3_PSSEN, temp, 4);
-		pci_write_config(self, PCI_XHCI_INTEL_XUSB2PR, temp, 4);
-	}
 	return (0);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 8 dfilter service freebsd_committer 2013-10-01 09:39:01 UTC
Author: hselasky
Date: Tue Oct  1 08:38:47 2013
New Revision: 255965
URL: http://svnweb.freebsd.org/changeset/base/255965

Log:
  MFC r255768:
  Stability fixes for Intel LynxPoint XHCI controllers. Disable XHCI port
  routing if we get certain errors. Poll for command completion upon
  command timeouts. The XHCI error events might not generate interrupts.
  
  PR:		usb/181159

Modified:
  stable/9/sys/dev/usb/controller/xhci.c
  stable/9/sys/dev/usb/controller/xhci.h
  stable/9/sys/dev/usb/controller/xhci_pci.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/dev/   (props changed)

Modified: stable/9/sys/dev/usb/controller/xhci.c
==============================================================================
--- stable/9/sys/dev/usb/controller/xhci.c	Tue Oct  1 07:22:04 2013	(r255964)
+++ stable/9/sys/dev/usb/controller/xhci.c	Tue Oct  1 08:38:47 2013	(r255965)
@@ -94,6 +94,8 @@ TUNABLE_INT("hw.usb.xhci.debug", &xhcide
 SYSCTL_INT(_hw_usb_xhci, OID_AUTO, xhci_port_route, CTLFLAG_RW | CTLFLAG_TUN,
     &xhciroute, 0, "Routing bitmap for switching EHCI ports to XHCI controller");
 TUNABLE_INT("hw.usb.xhci.xhci_port_route", &xhciroute);
+#else
+#define	xhciroute 0
 #endif
 
 #define	XHCI_INTR_ENDPT 1
@@ -179,16 +181,6 @@ xhci_dump_device(struct xhci_softc *sc, 
 }
 #endif
 
-uint32_t
-xhci_get_port_route(void)
-{
-#ifdef USB_DEBUG
-	return (0xFFFFFFFFU ^ ((uint32_t)xhciroute));
-#else
-	return (0xFFFFFFFFU);
-#endif
-}
-
 static void
 xhci_iterate_hw_softc(struct usb_bus *bus, usb_bus_mem_sub_cb_t *cb)
 {
@@ -480,6 +472,11 @@ xhci_start_controller(struct xhci_softc 
 	/* catch any lost interrupts */
 	xhci_do_poll(&sc->sc_bus);
 
+	if (sc->sc_port_route != NULL) {
+		/* Route all ports to the XHCI by default */
+		sc->sc_port_route(sc->sc_bus.parent,
+		    ~xhciroute, xhciroute);
+	}
 	return (0);
 }
 
@@ -917,7 +914,7 @@ xhci_check_transfer(struct xhci_softc *s
 	}
 }
 
-static void
+static int
 xhci_check_command(struct xhci_softc *sc, struct xhci_trb *trb)
 {
 	if (sc->sc_cmd_addr == trb->qwTrb0) {
@@ -925,16 +922,19 @@ xhci_check_command(struct xhci_softc *sc
 		sc->sc_cmd_result[0] = trb->dwTrb2;
 		sc->sc_cmd_result[1] = trb->dwTrb3;
 		cv_signal(&sc->sc_cmd_cv);
+		return (1);	/* command match */
 	}
+	return (0);
 }
 
-static void
+static int
 xhci_interrupt_poll(struct xhci_softc *sc)
 {
 	struct usb_page_search buf_res;
 	struct xhci_hw_root *phwr;
 	uint64_t addr;
 	uint32_t temp;
+	int retval = 0;
 	uint16_t i;
 	uint8_t event;
 	uint8_t j;
@@ -974,7 +974,7 @@ xhci_interrupt_poll(struct xhci_softc *s
 			xhci_check_transfer(sc, &phwr->hwr_events[i]);
 			break;
 		case XHCI_TRB_EVENT_CMD_COMPLETE:
-			xhci_check_command(sc, &phwr->hwr_events[i]);
+			retval |= xhci_check_command(sc, &phwr->hwr_events[i]);
 			break;
 		default:
 			DPRINTF("Unhandled event = %u\n", event);
@@ -1011,6 +1011,8 @@ xhci_interrupt_poll(struct xhci_softc *s
 
 	XWRITE4(sc, runt, XHCI_ERDP_LO(0), (uint32_t)addr);
 	XWRITE4(sc, runt, XHCI_ERDP_HI(0), (uint32_t)(addr >> 32));
+
+	return (retval);
 }
 
 static usb_error_t
@@ -1098,7 +1100,15 @@ xhci_do_command(struct xhci_softc *sc, s
 	err = cv_timedwait(&sc->sc_cmd_cv, &sc->sc_bus.bus_mtx,
 	    USB_MS_TO_TICKS(timeout_ms));
 
-	if (err) {
+	/*
+	 * In some error cases event interrupts are not generated.
+	 * Poll one time to see if the command has completed.
+	 */
+	if (err != 0 && xhci_interrupt_poll(sc) != 0) {
+		DPRINTF("Command was completed when polling\n");
+		err = 0;
+	}
+	if (err != 0) {
 		DPRINTFN(0, "Command timeout!\n");
 		err = USB_ERR_TIMEOUT;
 		trb->dwTrb2 = 0;
@@ -1277,6 +1287,14 @@ xhci_set_address(struct usb_device *udev
 		    (address == 0), index);
 
 		if (err != 0) {
+			temp = le32toh(sc->sc_cmd_result[0]);
+			if (address == 0 && sc->sc_port_route != NULL &&
+			    XHCI_TRB_2_ERROR_GET(temp) ==
+			    XHCI_TRB_ERROR_PARAMETER) {
+				/* LynxPoint XHCI - ports are not switchable */
+				/* Un-route all ports from the XHCI */
+				sc->sc_port_route(sc->sc_bus.parent, 0, ~0);
+			}
 			DPRINTF("Could not set address "
 			    "for slot %u.\n", index);
 			if (address != 0)

Modified: stable/9/sys/dev/usb/controller/xhci.h
==============================================================================
--- stable/9/sys/dev/usb/controller/xhci.h	Tue Oct  1 07:22:04 2013	(r255964)
+++ stable/9/sys/dev/usb/controller/xhci.h	Tue Oct  1 08:38:47 2013	(r255965)
@@ -421,6 +421,8 @@ union xhci_hub_desc {
 	uint8_t				temp[128];
 };
 
+typedef int (xhci_port_route_t)(device_t, uint32_t, uint32_t);
+
 struct xhci_softc {
 	struct xhci_hw_softc	sc_hw;
 	/* base device */
@@ -429,6 +431,8 @@ struct xhci_softc {
 	struct usb_process	sc_config_proc;
 	struct usb_bus_msg	sc_config_msg[2];
 
+	xhci_port_route_t	*sc_port_route;
+
 	union xhci_hub_desc	sc_hub_desc;
 
 	struct cv		sc_cmd_cv;
@@ -491,7 +495,6 @@ struct xhci_softc {
 
 /* prototypes */
 
-uint32_t	xhci_get_port_route(void);
 usb_error_t xhci_halt_controller(struct xhci_softc *);
 usb_error_t xhci_init(struct xhci_softc *, device_t);
 usb_error_t xhci_start_controller(struct xhci_softc *);

Modified: stable/9/sys/dev/usb/controller/xhci_pci.c
==============================================================================
--- stable/9/sys/dev/usb/controller/xhci_pci.c	Tue Oct  1 07:22:04 2013	(r255964)
+++ stable/9/sys/dev/usb/controller/xhci_pci.c	Tue Oct  1 08:38:47 2013	(r255965)
@@ -136,6 +136,25 @@ static int xhci_use_msi = 1;
 TUNABLE_INT("hw.usb.xhci.msi", &xhci_use_msi);
 
 static int
+xhci_pci_port_route(device_t self, uint32_t set, uint32_t clear)
+{
+	uint32_t temp;
+
+	temp = pci_read_config(self, PCI_XHCI_INTEL_USB3_PSSEN, 4) |
+	    pci_read_config(self, PCI_XHCI_INTEL_XUSB2PR, 4);
+
+	temp |= set;
+	temp &= ~clear;
+
+	pci_write_config(self, PCI_XHCI_INTEL_USB3_PSSEN, temp, 4);
+	pci_write_config(self, PCI_XHCI_INTEL_XUSB2PR, temp, 4);
+
+	device_printf(self, "Port routing mask set to 0x%08x\n", temp);
+
+	return (0);
+}
+
+static int
 xhci_pci_attach(device_t self)
 {
 	struct xhci_softc *sc = device_get_softc(self);
@@ -200,6 +219,16 @@ xhci_pci_attach(device_t self)
 		sc->sc_intr_hdl = NULL;
 		goto error;
 	}
+	/* On Intel chipsets reroute ports from EHCI to XHCI controller. */
+	switch (pci_get_devid(self)) {
+	case 0x1e318086:	/* Panther Point */
+	case 0x8c318086:	/* Lynx Point */
+		sc->sc_port_route = &xhci_pci_port_route;
+		break;
+	default:
+		break;
+	}
+
 	xhci_pci_take_controller(self);
 
 	err = xhci_halt_controller(sc);
@@ -266,7 +295,6 @@ static int
 xhci_pci_take_controller(device_t self)
 {
 	struct xhci_softc *sc = device_get_softc(self);
-	uint32_t device_id = pci_get_devid(self);
 	uint32_t cparams;
 	uint32_t eecp;
 	uint32_t eec;
@@ -307,13 +335,5 @@ xhci_pci_take_controller(device_t self)
 			usb_pause_mtx(NULL, hz / 100);	/* wait 10ms */
 		}
 	}
-
-	/* On Intel chipsets reroute ports from EHCI to XHCI controller. */
-	if (device_id == 0x1e318086 /* Panther Point */ ||
-	    device_id == 0x8c318086 /* Lynx Point */) {
-		uint32_t temp = xhci_get_port_route();
-		pci_write_config(self, PCI_XHCI_INTEL_USB3_PSSEN, temp, 4);
-		pci_write_config(self, PCI_XHCI_INTEL_XUSB2PR, temp, 4);
-	}
 	return (0);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 9 dfilter service freebsd_committer 2013-10-01 09:41:43 UTC
Author: hselasky
Date: Tue Oct  1 08:41:28 2013
New Revision: 255966
URL: http://svnweb.freebsd.org/changeset/base/255966

Log:
  MFC r255768:
  Stability fixes for Intel LynxPoint XHCI controllers. Disable XHCI port
  routing if we get certain errors. Poll for command completion upon
  command timeouts. The XHCI error events might not generate interrupts.
  
  PR:		usb/181159

Modified:
  stable/8/sys/dev/usb/controller/xhci.c
  stable/8/sys/dev/usb/controller/xhci.h
  stable/8/sys/dev/usb/controller/xhci_pci.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/dev/   (props changed)
  stable/8/sys/dev/usb/   (props changed)

Modified: stable/8/sys/dev/usb/controller/xhci.c
==============================================================================
--- stable/8/sys/dev/usb/controller/xhci.c	Tue Oct  1 08:38:47 2013	(r255965)
+++ stable/8/sys/dev/usb/controller/xhci.c	Tue Oct  1 08:41:28 2013	(r255966)
@@ -94,6 +94,8 @@ TUNABLE_INT("hw.usb.xhci.debug", &xhcide
 SYSCTL_INT(_hw_usb_xhci, OID_AUTO, xhci_port_route, CTLFLAG_RW | CTLFLAG_TUN,
     &xhciroute, 0, "Routing bitmap for switching EHCI ports to XHCI controller");
 TUNABLE_INT("hw.usb.xhci.xhci_port_route", &xhciroute);
+#else
+#define	xhciroute 0
 #endif
 
 #define	XHCI_INTR_ENDPT 1
@@ -179,16 +181,6 @@ xhci_dump_device(struct xhci_softc *sc, 
 }
 #endif
 
-uint32_t
-xhci_get_port_route(void)
-{
-#ifdef USB_DEBUG
-	return (0xFFFFFFFFU ^ ((uint32_t)xhciroute));
-#else
-	return (0xFFFFFFFFU);
-#endif
-}
-
 static void
 xhci_iterate_hw_softc(struct usb_bus *bus, usb_bus_mem_sub_cb_t *cb)
 {
@@ -480,6 +472,11 @@ xhci_start_controller(struct xhci_softc 
 	/* catch any lost interrupts */
 	xhci_do_poll(&sc->sc_bus);
 
+	if (sc->sc_port_route != NULL) {
+		/* Route all ports to the XHCI by default */
+		sc->sc_port_route(sc->sc_bus.parent,
+		    ~xhciroute, xhciroute);
+	}
 	return (0);
 }
 
@@ -917,7 +914,7 @@ xhci_check_transfer(struct xhci_softc *s
 	}
 }
 
-static void
+static int
 xhci_check_command(struct xhci_softc *sc, struct xhci_trb *trb)
 {
 	if (sc->sc_cmd_addr == trb->qwTrb0) {
@@ -925,16 +922,19 @@ xhci_check_command(struct xhci_softc *sc
 		sc->sc_cmd_result[0] = trb->dwTrb2;
 		sc->sc_cmd_result[1] = trb->dwTrb3;
 		cv_signal(&sc->sc_cmd_cv);
+		return (1);	/* command match */
 	}
+	return (0);
 }
 
-static void
+static int
 xhci_interrupt_poll(struct xhci_softc *sc)
 {
 	struct usb_page_search buf_res;
 	struct xhci_hw_root *phwr;
 	uint64_t addr;
 	uint32_t temp;
+	int retval = 0;
 	uint16_t i;
 	uint8_t event;
 	uint8_t j;
@@ -974,7 +974,7 @@ xhci_interrupt_poll(struct xhci_softc *s
 			xhci_check_transfer(sc, &phwr->hwr_events[i]);
 			break;
 		case XHCI_TRB_EVENT_CMD_COMPLETE:
-			xhci_check_command(sc, &phwr->hwr_events[i]);
+			retval |= xhci_check_command(sc, &phwr->hwr_events[i]);
 			break;
 		default:
 			DPRINTF("Unhandled event = %u\n", event);
@@ -1011,6 +1011,8 @@ xhci_interrupt_poll(struct xhci_softc *s
 
 	XWRITE4(sc, runt, XHCI_ERDP_LO(0), (uint32_t)addr);
 	XWRITE4(sc, runt, XHCI_ERDP_HI(0), (uint32_t)(addr >> 32));
+
+	return (retval);
 }
 
 static usb_error_t
@@ -1098,7 +1100,15 @@ xhci_do_command(struct xhci_softc *sc, s
 	err = cv_timedwait(&sc->sc_cmd_cv, &sc->sc_bus.bus_mtx,
 	    USB_MS_TO_TICKS(timeout_ms));
 
-	if (err) {
+	/*
+	 * In some error cases event interrupts are not generated.
+	 * Poll one time to see if the command has completed.
+	 */
+	if (err != 0 && xhci_interrupt_poll(sc) != 0) {
+		DPRINTF("Command was completed when polling\n");
+		err = 0;
+	}
+	if (err != 0) {
 		DPRINTFN(0, "Command timeout!\n");
 		err = USB_ERR_TIMEOUT;
 		trb->dwTrb2 = 0;
@@ -1277,6 +1287,14 @@ xhci_set_address(struct usb_device *udev
 		    (address == 0), index);
 
 		if (err != 0) {
+			temp = le32toh(sc->sc_cmd_result[0]);
+			if (address == 0 && sc->sc_port_route != NULL &&
+			    XHCI_TRB_2_ERROR_GET(temp) ==
+			    XHCI_TRB_ERROR_PARAMETER) {
+				/* LynxPoint XHCI - ports are not switchable */
+				/* Un-route all ports from the XHCI */
+				sc->sc_port_route(sc->sc_bus.parent, 0, ~0);
+			}
 			DPRINTF("Could not set address "
 			    "for slot %u.\n", index);
 			if (address != 0)

Modified: stable/8/sys/dev/usb/controller/xhci.h
==============================================================================
--- stable/8/sys/dev/usb/controller/xhci.h	Tue Oct  1 08:38:47 2013	(r255965)
+++ stable/8/sys/dev/usb/controller/xhci.h	Tue Oct  1 08:41:28 2013	(r255966)
@@ -421,6 +421,8 @@ union xhci_hub_desc {
 	uint8_t				temp[128];
 };
 
+typedef int (xhci_port_route_t)(device_t, uint32_t, uint32_t);
+
 struct xhci_softc {
 	struct xhci_hw_softc	sc_hw;
 	/* base device */
@@ -429,6 +431,8 @@ struct xhci_softc {
 	struct usb_process	sc_config_proc;
 	struct usb_bus_msg	sc_config_msg[2];
 
+	xhci_port_route_t	*sc_port_route;
+
 	union xhci_hub_desc	sc_hub_desc;
 
 	struct cv		sc_cmd_cv;
@@ -490,7 +494,6 @@ struct xhci_softc {
 
 /* prototypes */
 
-uint32_t	xhci_get_port_route(void);
 usb_error_t xhci_halt_controller(struct xhci_softc *);
 usb_error_t xhci_init(struct xhci_softc *, device_t);
 usb_error_t xhci_start_controller(struct xhci_softc *);

Modified: stable/8/sys/dev/usb/controller/xhci_pci.c
==============================================================================
--- stable/8/sys/dev/usb/controller/xhci_pci.c	Tue Oct  1 08:38:47 2013	(r255965)
+++ stable/8/sys/dev/usb/controller/xhci_pci.c	Tue Oct  1 08:41:28 2013	(r255966)
@@ -130,6 +130,25 @@ xhci_pci_probe(device_t self)
 }
 
 static int
+xhci_pci_port_route(device_t self, uint32_t set, uint32_t clear)
+{
+	uint32_t temp;
+
+	temp = pci_read_config(self, PCI_XHCI_INTEL_USB3_PSSEN, 4) |
+	    pci_read_config(self, PCI_XHCI_INTEL_XUSB2PR, 4);
+
+	temp |= set;
+	temp &= ~clear;
+
+	pci_write_config(self, PCI_XHCI_INTEL_USB3_PSSEN, temp, 4);
+	pci_write_config(self, PCI_XHCI_INTEL_XUSB2PR, temp, 4);
+
+	device_printf(self, "Port routing mask set to 0x%08x\n", temp);
+
+	return (0);
+}
+
+static int
 xhci_pci_attach(device_t self)
 {
 	struct xhci_softc *sc = device_get_softc(self);
@@ -184,6 +203,16 @@ xhci_pci_attach(device_t self)
 		sc->sc_intr_hdl = NULL;
 		goto error;
 	}
+	/* On Intel chipsets reroute ports from EHCI to XHCI controller. */
+	switch (pci_get_devid(self)) {
+	case 0x1e318086:	/* Panther Point */
+	case 0x8c318086:	/* Lynx Point */
+		sc->sc_port_route = &xhci_pci_port_route;
+		break;
+	default:
+		break;
+	}
+
 	xhci_pci_take_controller(self);
 
 	err = xhci_halt_controller(sc);
@@ -247,7 +276,6 @@ static int
 xhci_pci_take_controller(device_t self)
 {
 	struct xhci_softc *sc = device_get_softc(self);
-	uint32_t device_id = pci_get_devid(self);
 	uint32_t cparams;
 	uint32_t eecp;
 	uint32_t eec;
@@ -288,13 +316,5 @@ xhci_pci_take_controller(device_t self)
 			usb_pause_mtx(NULL, hz / 100);	/* wait 10ms */
 		}
 	}
-
-	/* On Intel chipsets reroute ports from EHCI to XHCI controller. */
-	if (device_id == 0x1e318086 /* Panther Point */ ||
-	    device_id == 0x8c318086 /* Lynx Point */) {
-		uint32_t temp = xhci_get_port_route();
-		pci_write_config(self, PCI_XHCI_INTEL_USB3_PSSEN, temp, 4);
-		pci_write_config(self, PCI_XHCI_INTEL_XUSB2PR, temp, 4);
-	}
 	return (0);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 10 Sergei Arefiev 2013-10-04 10:28:22 UTC
Hi everyone,

I'm using FreeBSD 9.2-Release and facing the same issue. Today I got
patches from this revision:
http://svnweb.freebsd.org/changeset/base/255965and applied them to
9.2-Release sources, then rebuilt the kernel.

So, after reboot I still can see the same errors in dmesg, but my USB mouse
is successfully recognized and I confirm that it works. I didn't try other
USB devices yet though.

My Motherboard is Asus Z87-PRO. I posted additional information with dmesg
and usbconfig output to
http://forums.freebsd.org/showpost.php?p=235125&postcount=8

Thank you for patches, I can use my new hardware now :) Please let me know
if you need more testing, I could try to help with that.
Comment 11 Roland Behme 2013-11-06 15:02:10 UTC
I think I have a similar problem with an ASRock H87 Pro4 mainboard here.
First I tried with FreeBSD 9.2 RELEASE, then after I found this PR I
switched to 9.2 STABLE in order to try the patch mentioned above.
Unfortunately unlike for my fellow poster, it doesn't help in my case.

When I enable the USB 3.0 feature in UEFI BIOS, the plugged in devices
are not attached.

This is what I get from dmesg:

xhci0: <Intel Lynx Point USB 3.0 controller> mem 0xf0420000-0xf042ffff
irq 16 at device 20.0 on pci0
xhci0: 32 byte context size.
xhci0: Port routing mask set to 0xffffffff
usbus0 on xhci0
[...]
usbus0: 5.0Gbps Super Speed USB v3.0
ugen0.1: <0x8086> at usbus0
uhub0: <0x8086 XHCI root HUB, class 9/0, rev 3.00/1.00, addr 1> on usbus0
[...]
Root mount waiting for: usbus0
uhub0: 21 ports with 21 removable, self powered
Root mount waiting for: usbus0
xhci0: Port routing mask set to 0x00000000
usb_alloc_device: device init 2 failed (USB_ERR_IOERROR, ignored)
ugen0.2: <Unknown> at usbus0 (disconnected)
uhub_reattach_port: could not allocate new device



At least I'm able to use my USB devices when I disable USB 3.0 in UEFI
BIOS. Then dmesg looks like this:

ehci0: <EHCI (generic) USB 2.0 controller> mem 0xf0424000-0xf04243ff irq
16 at device 26.0 on pci0
usbus0: EHCI version 1.0
usbus0 on ehci0
[...]
ehci1: <EHCI (generic) USB 2.0 controller> mem 0xf0423000-0xf04233ff irq
23 at device 29.0 on pci0
usbus1: EHCI version 1.0
usbus1 on ehci1
[...]
usbus0: 480Mbps High Speed USB v2.0
usbus1: 480Mbps High Speed USB v2.0
ugen0.1: <Intel> at usbus0
uhub0: <Intel EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1> on usbus0
ugen1.1: <Intel> at usbus1
uhub1: <Intel EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1> on usbus1
[...]
Root mount waiting for: usbus1 usbus0
uhub0: 2 ports with 2 removable, self powered
uhub1: 2 ports with 2 removable, self powered
Root mount waiting for: usbus1 usbus0
ugen0.2: <vendor 0x8087> at usbus0
uhub2: <vendor 0x8087 product 0x8008, class 9/0, rev 2.00/0.05, addr 2>
on usbus0
ugen1.2: <vendor 0x8087> at usbus1
uhub3: <vendor 0x8087 product 0x8000, class 9/0, rev 2.00/0.05, addr 2>
on usbus1
uhub2: 6 ports with 6 removable, self powered
uhub3: 8 ports with 8 removable, self powered
ugen1.3: <American Power Conversion> at usbus1
Root mount waiting for: usbus1
ugen1.4: <Sunplus Technology Inc.> at usbus1
umass0: <Bulk Only Interface> on usbus1
umass0:  SCSI over Bulk-Only; quirks = 0x4101
umass0:6:0:-1: Attached to scbus6


So in EHCI mode everything is running, XHCI fails to attach the devices.
Any suggestions?
Comment 12 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:46:51 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 13 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-20 03:56:08 UTC
Is this PR still valid for currently supported versions?

Thanks
Comment 14 Denis 2019-07-15 09:59:23 UTC
(In reply to Oleksandr Tymoshenko from comment #13)
Can't say anything about PR but problem is still persist.
I have ASROCK J4205-ITX and FreeBSD 12.0-p7
Can mount a flash drive (sometimes not at the first time) but failed to connect with other hardware. A real problem is UPS with USB cable. I have try APC and CyberPower. Both connected to Windows PC without problems and failed with my 12.0

No mater with port to use: USB 2.0 or USB 3.0

I can't even disable XHCI cause Motherboard BIOS do not have such option.
Comment 15 Denis 2019-07-15 10:26:20 UTC
(In reply to Denis from comment #14)
According to my prev comment there was a question. Does make sense comment out
device		xhci
in  kernel config file, install kernel, reboot and make command kldunload xhci ?
Does all other subsystems will operate in EHCI mode or not?