From owner-svn-src-all@freebsd.org Tue Aug 18 15:44:04 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 541173C0092; Tue, 18 Aug 2020 15:44:04 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BWFZX1Yhzz4Gky; Tue, 18 Aug 2020 15:44:04 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 18A92140C0; Tue, 18 Aug 2020 15:44:04 +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 07IFi3Ag052581; Tue, 18 Aug 2020 15:44:03 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07IFi3CH052580; Tue, 18 Aug 2020 15:44:03 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202008181544.07IFi3CH052580@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 18 Aug 2020 15:44:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r364347 - head/sys/dev/usb/controller X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/sys/dev/usb/controller X-SVN-Commit-Revision: 364347 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Aug 2020 15:44:04 -0000 Author: hselasky Date: Tue Aug 18 15:44:03 2020 New Revision: 364347 URL: https://svnweb.freebsd.org/changeset/base/364347 Log: Check the XHCI endpoint state before issuing XHCI endpoint commands. Differential Revision: https://reviews.freebsd.org/D26064 Reviewed by: kp@ and bz@ MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/dev/usb/controller/xhci.c Modified: head/sys/dev/usb/controller/xhci.c ============================================================================== --- head/sys/dev/usb/controller/xhci.c Tue Aug 18 14:17:14 2020 (r364346) +++ head/sys/dev/usb/controller/xhci.c Tue Aug 18 15:44:03 2020 (r364347) @@ -3808,6 +3808,28 @@ alloc_dma_set: } } +static uint8_t +xhci_get_endpoint_state(struct usb_device *udev, uint8_t epno) +{ + struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); + struct usb_page_search buf_dev; + struct xhci_hw_dev *hdev; + struct xhci_dev_ctx *pdev; + uint32_t temp; + + MPASS(epno != 0); + + hdev = &sc->sc_hw.devs[udev->controller_slot_id]; + + usbd_get_page(&hdev->device_pc, 0, &buf_dev); + pdev = buf_dev.buffer; + usb_pc_cpu_invalidate(&hdev->device_pc); + + temp = xhci_ctx_get_le32(sc, &pdev->ctx_ep[epno - 1].dwEpCtx0); + + return (XHCI_EPCTX_0_EPSTATE_GET(temp)); +} + static usb_error_t xhci_configure_reset_endpoint(struct usb_xfer *xfer) { @@ -3861,16 +3883,20 @@ xhci_configure_reset_endpoint(struct usb_xfer *xfer) * Get the endpoint into the stopped state according to the * endpoint context state diagram in the XHCI specification: */ - - err = xhci_cmd_stop_ep(sc, 0, epno, index); - - if (err != 0) - DPRINTF("Could not stop endpoint %u\n", epno); - - err = xhci_cmd_reset_ep(sc, 0, epno, index); - - if (err != 0) - DPRINTF("Could not reset endpoint %u\n", epno); + switch (xhci_get_endpoint_state(udev, epno)) { + case XHCI_EPCTX_0_EPSTATE_STOPPED: + break; + case XHCI_EPCTX_0_EPSTATE_HALTED: + err = xhci_cmd_reset_ep(sc, 0, epno, index); + if (err != 0) + DPRINTF("Could not reset endpoint %u\n", epno); + break; + default: + err = xhci_cmd_stop_ep(sc, 0, epno, index); + if (err != 0) + DPRINTF("Could not stop endpoint %u\n", epno); + break; + } err = xhci_cmd_set_tr_dequeue_ptr(sc, (pepext->physaddr + (stream_id * sizeof(struct xhci_trb) *