Skip to content

Commit 69e848c

Browse files
author
Sarah Sharp
committed
Intel xhci: Support EHCI/xHCI port switching.
The Intel Panther Point chipsets contain an EHCI and xHCI host controller that shares some number of skew-dependent ports. These ports can be switched from the EHCI to the xHCI host (and vice versa) by a hardware MUX that is controlled by registers in the xHCI PCI configuration space. The USB 3.0 SuperSpeed terminations on the xHCI ports can be controlled separately from the USB 2.0 data wires. This switchover mechanism is there to support users who do a custom install of certain non-Linux operating systems that don't have official USB 3.0 support. By default, the ports are under EHCI, SuperSpeed terminations are off, and USB 3.0 devices will show up under the EHCI controller at reduced speeds. (This was more palatable for the marketing folks than having completely dead USB 3.0 ports if no xHCI drivers are available.) Users should be able to turn on xHCI by default through a BIOS option, but users are happiest when they don't have to change random BIOS settings. This patch introduces a driver method to switchover the ports from EHCI to xHCI before the EHCI driver finishes PCI enumeration. We want to switch the ports over before the USB core has the chance to enumerate devices under EHCI, or boot from USB mass storage will fail if the boot device connects under EHCI first, and then gets disconnected when the port switches over to xHCI. Add code to the xHCI PCI quirk to switch the ports from EHCI to xHCI. The PCI quirks code will run before any other PCI probe function is called, so this avoids the issue with boot devices. Another issue is with BIOS behavior during system resume from hibernate. If the BIOS doesn't support xHCI, it may switch the devices under EHCI to allow use of the USB keyboard, mice, and mass storage devices. It's supposed to remember the value of the port routing registers and switch them back when the OS attempts to take control of the xHCI host controller, but we all know not to trust BIOS writers. Make both the xHCI driver and the EHCI driver attempt to switchover the ports in their PCI resume functions. We can't guarantee which PCI device will be resumed first, so this avoids any race conditions. Writing a '1' to an already set port switchover bit or a '0' to a cleared port switchover bit should have no effect. The xHCI PCI configuration registers will be documented in the EDS-level chipset spec, which is not public yet. I have permission from legal and the Intel chipset group to release this patch early to allow good Linux support at product launch. I've tried to document the registers as much as possible, so please let me know if anything is unclear. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
1 parent 7fe4fc8 commit 69e848c

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

Diff for: drivers/usb/host/ehci-pci.c

+39
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,50 @@ static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
348348
return rc;
349349
}
350350

351+
static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
352+
{
353+
return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
354+
pdev->vendor == PCI_VENDOR_ID_INTEL &&
355+
pdev->device == 0x1E26;
356+
}
357+
358+
static void ehci_enable_xhci_companion(void)
359+
{
360+
struct pci_dev *companion = NULL;
361+
362+
/* The xHCI and EHCI controllers are not on the same PCI slot */
363+
for_each_pci_dev(companion) {
364+
if (!usb_is_intel_switchable_xhci(companion))
365+
continue;
366+
usb_enable_xhci_ports(companion);
367+
return;
368+
}
369+
}
370+
351371
static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
352372
{
353373
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
354374
struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
355375

376+
/* The BIOS on systems with the Intel Panther Point chipset may or may
377+
* not support xHCI natively. That means that during system resume, it
378+
* may switch the ports back to EHCI so that users can use their
379+
* keyboard to select a kernel from GRUB after resume from hibernate.
380+
*
381+
* The BIOS is supposed to remember whether the OS had xHCI ports
382+
* enabled before resume, and switch the ports back to xHCI when the
383+
* BIOS/OS semaphore is written, but we all know we can't trust BIOS
384+
* writers.
385+
*
386+
* Unconditionally switch the ports back to xHCI after a system resume.
387+
* We can't tell whether the EHCI or xHCI controller will be resumed
388+
* first, so we have to do the port switchover in both drivers. Writing
389+
* a '1' to the port switchover registers should have no effect if the
390+
* port was already switched over.
391+
*/
392+
if (usb_is_intel_switchable_ehci(pdev))
393+
ehci_enable_xhci_companion();
394+
356395
// maybe restore FLADJ
357396

358397
if (time_before(jiffies, ehci->next_statechange))

Diff for: drivers/usb/host/pci-quirks.c

+63
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
#define NB_PIF0_PWRDOWN_0 0x01100012
7070
#define NB_PIF0_PWRDOWN_1 0x01100013
7171

72+
#define USB_INTEL_XUSB2PR 0xD0
73+
#define USB_INTEL_USB3_PSSEN 0xD8
74+
7275
static struct amd_chipset_info {
7376
struct pci_dev *nb_dev;
7477
struct pci_dev *smbus_dev;
@@ -673,6 +676,64 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done,
673676
return -ETIMEDOUT;
674677
}
675678

679+
bool usb_is_intel_switchable_xhci(struct pci_dev *pdev)
680+
{
681+
return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
682+
pdev->vendor == PCI_VENDOR_ID_INTEL &&
683+
pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI;
684+
}
685+
EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci);
686+
687+
/*
688+
* Intel's Panther Point chipset has two host controllers (EHCI and xHCI) that
689+
* share some number of ports. These ports can be switched between either
690+
* controller. Not all of the ports under the EHCI host controller may be
691+
* switchable.
692+
*
693+
* The ports should be switched over to xHCI before PCI probes for any device
694+
* start. This avoids active devices under EHCI being disconnected during the
695+
* port switchover, which could cause loss of data on USB storage devices, or
696+
* failed boot when the root file system is on a USB mass storage device and is
697+
* enumerated under EHCI first.
698+
*
699+
* We write into the xHC's PCI configuration space in some Intel-specific
700+
* registers to switch the ports over. The USB 3.0 terminations and the USB
701+
* 2.0 data wires are switched separately. We want to enable the SuperSpeed
702+
* terminations before switching the USB 2.0 wires over, so that USB 3.0
703+
* devices connect at SuperSpeed, rather than at USB 2.0 speeds.
704+
*/
705+
void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
706+
{
707+
u32 ports_available;
708+
709+
ports_available = 0xffffffff;
710+
/* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable
711+
* Register, to turn on SuperSpeed terminations for all
712+
* available ports.
713+
*/
714+
pci_write_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
715+
cpu_to_le32(ports_available));
716+
717+
pci_read_config_dword(xhci_pdev, USB_INTEL_USB3_PSSEN,
718+
&ports_available);
719+
dev_dbg(&xhci_pdev->dev, "USB 3.0 ports that are now enabled "
720+
"under xHCI: 0x%x\n", ports_available);
721+
722+
ports_available = 0xffffffff;
723+
/* Write XUSB2PR, the xHC USB 2.0 Port Routing Register, to
724+
* switch the USB 2.0 power and data lines over to the xHCI
725+
* host.
726+
*/
727+
pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
728+
cpu_to_le32(ports_available));
729+
730+
pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
731+
&ports_available);
732+
dev_dbg(&xhci_pdev->dev, "USB 2.0 ports that are now switched over "
733+
"to xHCI: 0x%x\n", ports_available);
734+
}
735+
EXPORT_SYMBOL_GPL(usb_enable_xhci_ports);
736+
676737
/**
677738
* PCI Quirks for xHCI.
678739
*
@@ -732,6 +793,8 @@ static void __devinit quirk_usb_handoff_xhci(struct pci_dev *pdev)
732793
writel(XHCI_LEGACY_DISABLE_SMI,
733794
base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
734795

796+
if (usb_is_intel_switchable_xhci(pdev))
797+
usb_enable_xhci_ports(pdev);
735798
hc_init:
736799
op_reg_base = base + XHCI_HC_LENGTH(readl(base));
737800

Diff for: drivers/usb/host/pci-quirks.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ int usb_amd_find_chipset_info(void);
88
void usb_amd_dev_put(void);
99
void usb_amd_quirk_pll_disable(void);
1010
void usb_amd_quirk_pll_enable(void);
11+
bool usb_is_intel_switchable_xhci(struct pci_dev *pdev);
12+
void usb_enable_xhci_ports(struct pci_dev *xhci_pdev);
1113
#else
1214
static inline void usb_amd_quirk_pll_disable(void) {}
1315
static inline void usb_amd_quirk_pll_enable(void) {}

Diff for: drivers/usb/host/xhci-pci.c

+20
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,28 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
242242
static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
243243
{
244244
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
245+
struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
245246
int retval = 0;
246247

248+
/* The BIOS on systems with the Intel Panther Point chipset may or may
249+
* not support xHCI natively. That means that during system resume, it
250+
* may switch the ports back to EHCI so that users can use their
251+
* keyboard to select a kernel from GRUB after resume from hibernate.
252+
*
253+
* The BIOS is supposed to remember whether the OS had xHCI ports
254+
* enabled before resume, and switch the ports back to xHCI when the
255+
* BIOS/OS semaphore is written, but we all know we can't trust BIOS
256+
* writers.
257+
*
258+
* Unconditionally switch the ports back to xHCI after a system resume.
259+
* We can't tell whether the EHCI or xHCI controller will be resumed
260+
* first, so we have to do the port switchover in both drivers. Writing
261+
* a '1' to the port switchover registers should have no effect if the
262+
* port was already switched over.
263+
*/
264+
if (usb_is_intel_switchable_xhci(pdev))
265+
usb_enable_xhci_ports(pdev);
266+
247267
retval = xhci_resume(xhci, hibernated);
248268
return retval;
249269
}

0 commit comments

Comments
 (0)