From 4dc853afcdfbcac39e022815824006ce044f458a Mon Sep 17 00:00:00 2001 From: hselasky Date: Thu, 16 Jan 2020 08:53:59 +0000 Subject: [PATCH] MFC r356545: Fix a XHCI driver issue with Intel's Gemini Lake SOC. Do not configure any endpoint twice, but instead keep track of which endpoints are configured on a per device basis, and use an evaluate endpoint context command instead. When changing the configuration make sure all endpoints get deconfigured and the configured endpoint mask is reset. This fixes an issue where an endpoint might stop working if there is an error and the endpoint needs to be reconfigured as a part of the error recovery mechanism in the FreeBSD USB stack. Tested by: Shichun.Ma@dell.com Sponsored by: Mellanox Technologies git-svn-id: svn://svn.freebsd.org/base/stable/10@356783 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/usb/controller/xhci.c | 31 +++++++++++++++++++++++-------- sys/dev/usb/controller/xhci.h | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c index af1861282..519090d55 100644 --- a/sys/dev/usb/controller/xhci.c +++ b/sys/dev/usb/controller/xhci.c @@ -3841,6 +3841,7 @@ xhci_configure_reset_endpoint(struct usb_xfer *xfer) struct usb_page_cache *pcinp; usb_error_t err; usb_stream_t stream_id; + uint32_t mask; uint8_t index; uint8_t epno; @@ -3906,16 +3907,20 @@ xhci_configure_reset_endpoint(struct usb_xfer *xfer) * endpoint context state diagram in the XHCI specification: */ - xhci_configure_mask(udev, (1U << epno) | 1U, 0); + mask = (1U << epno); + xhci_configure_mask(udev, mask | 1U, 0); - if (epno > 1) + if (!(sc->sc_hw.devs[index].ep_configured & mask)) { + sc->sc_hw.devs[index].ep_configured |= mask; err = xhci_cmd_configure_ep(sc, buf_inp.physaddr, 0, index); - else + } else { err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index); + } - if (err != 0) - DPRINTF("Could not configure endpoint %u\n", epno); - + if (err != 0) { + DPRINTF("Could not configure " + "endpoint %u at slot %u.\n", epno, index); + } XHCI_CMD_UNLOCK(sc); return (0); @@ -4276,6 +4281,7 @@ xhci_device_state_change(struct usb_device *udev) /* set default state */ sc->sc_hw.devs[index].state = XHCI_ST_DEFAULT; + sc->sc_hw.devs[index].ep_configured = 3U; /* reset number of contexts */ sc->sc_hw.devs[index].context_num = 0; @@ -4293,6 +4299,7 @@ xhci_device_state_change(struct usb_device *udev) break; sc->sc_hw.devs[index].state = XHCI_ST_ADDRESSED; + sc->sc_hw.devs[index].ep_configured = 3U; /* set configure mask to slot only */ xhci_configure_mask(udev, 1, 0); @@ -4307,11 +4314,19 @@ xhci_device_state_change(struct usb_device *udev) break; case USB_STATE_CONFIGURED: - if (sc->sc_hw.devs[index].state == XHCI_ST_CONFIGURED) - break; + if (sc->sc_hw.devs[index].state == XHCI_ST_CONFIGURED) { + /* deconfigure all endpoints, except EP0 */ + err = xhci_cmd_configure_ep(sc, 0, 1, index); + + if (err) { + DPRINTF("Failed to deconfigure " + "slot %u.\n", index); + } + } /* set configured state */ sc->sc_hw.devs[index].state = XHCI_ST_CONFIGURED; + sc->sc_hw.devs[index].ep_configured = 3U; /* reset number of contexts */ sc->sc_hw.devs[index].context_num = 0; diff --git a/sys/dev/usb/controller/xhci.h b/sys/dev/usb/controller/xhci.h index ab70ee2cf..b95461b0d 100644 --- a/sys/dev/usb/controller/xhci.h +++ b/sys/dev/usb/controller/xhci.h @@ -406,6 +406,8 @@ struct xhci_hw_dev { struct xhci_endpoint_ext endp[XHCI_MAX_ENDPOINTS]; + uint32_t ep_configured; + uint8_t state; uint8_t nports; uint8_t tt; -- 2.42.0