From owner-svn-src-stable@freebsd.org Tue Mar 14 15:27:40 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2E4B4D0C466; Tue, 14 Mar 2017 15:27:40 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0662512EC; Tue, 14 Mar 2017 15:27:39 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2EFRdqO003935; Tue, 14 Mar 2017 15:27:39 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2EFRcD7003932; Tue, 14 Mar 2017 15:27:38 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703141527.v2EFRcD7003932@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 14 Mar 2017 15:27:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r315251 - stable/11/sys/dev/usb/controller X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 15:27:40 -0000 Author: hselasky Date: Tue Mar 14 15:27:38 2017 New Revision: 315251 URL: https://svnweb.freebsd.org/changeset/base/315251 Log: MFC r312424: Fix problem with suspend and resume when using Skylake chipsets. Make sure the XHCI controller is reset after halting it. The problem is clearly a BIOS bug as the suspend and resume is failing without loading the XHCI driver. The same happens when using Linux and the XHCI driver is not loaded. Submitted by: Yanko Yankulov PR: 216261 Modified: stable/11/sys/dev/usb/controller/xhci.c stable/11/sys/dev/usb/controller/xhci.h stable/11/sys/dev/usb/controller/xhci_pci.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/usb/controller/xhci.c ============================================================================== --- stable/11/sys/dev/usb/controller/xhci.c Tue Mar 14 15:25:49 2017 (r315250) +++ stable/11/sys/dev/usb/controller/xhci.c Tue Mar 14 15:27:38 2017 (r315251) @@ -347,6 +347,7 @@ xhci_start_controller(struct xhci_softc struct usb_page_search buf_res; struct xhci_hw_root *phwr; struct xhci_dev_ctx_addr *pdctxa; + usb_error_t err; uint64_t addr; uint32_t temp; uint16_t i; @@ -358,22 +359,9 @@ xhci_start_controller(struct xhci_softc sc->sc_command_ccs = 1; sc->sc_command_idx = 0; - /* Reset controller */ - XWRITE4(sc, oper, XHCI_USBCMD, XHCI_CMD_HCRST); - - for (i = 0; i != 100; i++) { - usb_pause_mtx(NULL, hz / 100); - temp = (XREAD4(sc, oper, XHCI_USBCMD) & XHCI_CMD_HCRST) | - (XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_CNR); - if (!temp) - break; - } - - if (temp) { - device_printf(sc->sc_bus.parent, "Controller " - "reset timeout.\n"); - return (USB_ERR_IOERROR); - } + err = xhci_reset_controller(sc); + if (err) + return (err); /* set up number of device slots */ DPRINTF("CONFIG=0x%08x -> 0x%08x\n", @@ -521,6 +509,33 @@ xhci_halt_controller(struct xhci_softc * } usb_error_t +xhci_reset_controller(struct xhci_softc *sc) +{ + uint32_t temp = 0; + uint16_t i; + + DPRINTF("\n"); + + /* Reset controller */ + XWRITE4(sc, oper, XHCI_USBCMD, XHCI_CMD_HCRST); + + for (i = 0; i != 100; i++) { + usb_pause_mtx(NULL, hz / 100); + temp = (XREAD4(sc, oper, XHCI_USBCMD) & XHCI_CMD_HCRST) | + (XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_CNR); + if (!temp) + break; + } + + if (temp) { + device_printf(sc->sc_bus.parent, "Controller " + "reset timeout.\n"); + return (USB_ERR_IOERROR); + } + return (0); +} + +usb_error_t xhci_init(struct xhci_softc *sc, device_t self, uint8_t dma32) { uint32_t temp; @@ -671,10 +686,12 @@ xhci_set_hw_power_sleep(struct usb_bus * case USB_HW_POWER_SUSPEND: DPRINTF("Stopping the XHCI\n"); xhci_halt_controller(sc); + xhci_reset_controller(sc); break; case USB_HW_POWER_SHUTDOWN: DPRINTF("Stopping the XHCI\n"); xhci_halt_controller(sc); + xhci_reset_controller(sc); break; case USB_HW_POWER_RESUME: DPRINTF("Starting the XHCI\n"); Modified: stable/11/sys/dev/usb/controller/xhci.h ============================================================================== --- stable/11/sys/dev/usb/controller/xhci.h Tue Mar 14 15:25:49 2017 (r315250) +++ stable/11/sys/dev/usb/controller/xhci.h Tue Mar 14 15:27:38 2017 (r315251) @@ -525,6 +525,7 @@ struct xhci_softc { uint8_t xhci_use_polling(void); usb_error_t xhci_halt_controller(struct xhci_softc *); +usb_error_t xhci_reset_controller(struct xhci_softc *); usb_error_t xhci_init(struct xhci_softc *, device_t, uint8_t); usb_error_t xhci_start_controller(struct xhci_softc *); void xhci_interrupt(struct xhci_softc *); Modified: stable/11/sys/dev/usb/controller/xhci_pci.c ============================================================================== --- stable/11/sys/dev/usb/controller/xhci_pci.c Tue Mar 14 15:25:49 2017 (r315250) +++ stable/11/sys/dev/usb/controller/xhci_pci.c Tue Mar 14 15:27:38 2017 (r315251) @@ -348,6 +348,7 @@ xhci_pci_detach(device_t self) usb_callout_drain(&sc->sc_callout); xhci_halt_controller(sc); + xhci_reset_controller(sc); pci_disable_busmaster(self);