Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2836529pxb; Mon, 11 Jan 2021 22:52:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqshe5WifThYkyrBCfi6EBi0J0kyoI61zsreqtF0GT3ukZ1I0bl+2lKwlN5VlbBy9KC/kf X-Received: by 2002:a17:906:2ccb:: with SMTP id r11mr2216546ejr.39.1610434346881; Mon, 11 Jan 2021 22:52:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610434346; cv=none; d=google.com; s=arc-20160816; b=Deyc0XyU8pdVSIroXFIwjCE6y8QwFq2vjkgrq1tEVJy439qdtVTWksMyzfXLwGZ+uW 1hXPKdSEGQTBAZ2c7p8SVlPOfwgff7O9qWhuFLJ29PacdfRDiQqMKENRcgRv4GQxojRm TTcNtEF7yL4KsKN2xORV2CFagv14gG2BevobkE9gbOXj3MDNe4WVQ5PwxGYqGw6vsCRY gMbc56UZvUIBgcz7KAzMAZD2dCYn4eQBKZI6WwIN/ne0ZqSpP/faaI/78qk6IcMmpxl4 4WRStSoGlNpgDdVRds/aGe8w+t6lz9YqKUumvEkwIV4TvjC3cATp2RM5Zj9I/hbB6pnu zngw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Uy9a7r+RfyYZE/zwbtzg+v9fNmM+MyEut+H4fhHPTkM=; b=jty+EVgtB5ZzvWuizVZsLLJEi2stbOO+F+WklzV/kc7fImOHXUrbA+jZeQjvH6eO3a 2QrdbKP9vqD5LX2U1bDKp85WXegsErryNbGppGR6FdX+/14FvP8yoFBVc0yrYLS5cnko ugLF5KsWY7+CB5pTR5oYUQzmtYUA8SFpzMopZSVEapC2pdEbEVStnB8EpCAv+uYz1SYg mwppnckNOmdsxZQZyOJ1f0O1Qo8QRbkMa0kMezPD5JwRXlQajnz3cU0PQqW7FLunTzI1 uMBWZW8V7Cb+FilSuWVHUz+/iGHse2fqHc4lAVIqTa2C3+h8I4PdeaelKXeRvgMaof3C aRqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tfpXw9Dx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z5si797221ejj.425.2021.01.11.22.52.03; Mon, 11 Jan 2021 22:52:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tfpXw9Dx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729985AbhAKOHw (ORCPT + 99 others); Mon, 11 Jan 2021 09:07:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:50206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729989AbhAKNDp (ORCPT ); Mon, 11 Jan 2021 08:03:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7838D2225E; Mon, 11 Jan 2021 13:03:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370207; bh=aWKlDIZ5Xp3hU1zZXBXm8HYj9H7GwLskIjASad7RF9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tfpXw9Dxs661d4VH0AZcbaFT7vhcz+vXdm6NwuB7kwfjIQbVILtG6Dlxvf6M/oOB4 UzKML6Dw+PN1RpljN0SaZ76PPgY+AL3Cq136AIDPtKHJeSk4JMzWMOzxU+yYz2HhH0 6oak3AXPv9Z54SizKWmELC+/MyQ+vfoN7iyk4iM8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Grzeschik Subject: [PATCH 4.9 25/45] USB: xhci: fix U1/U2 handling for hardware with XHCI_INTEL_HOST quirk set Date: Mon, 11 Jan 2021 14:01:03 +0100 Message-Id: <20210111130034.873366517@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130033.676306636@linuxfoundation.org> References: <20210111130033.676306636@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Grzeschik commit 5d5323a6f3625f101dbfa94ba3ef7706cce38760 upstream. The commit 0472bf06c6fd ("xhci: Prevent U1/U2 link pm states if exit latency is too long") was constraining the xhci code not to allow U1/U2 sleep states if the latency to wake up from the U-states reached the service interval of an periodic endpoint. This fix was not taking into account that in case the quirk XHCI_INTEL_HOST is set, the wakeup time will be calculated and configured differently. It checks for u1_params.mel/u2_params.mel as a limit. But the code could decide to write another MEL into the hardware. This leads to broken cases where not enough bandwidth is available for other devices: usb 1-2: can't set config #1, error -28 This patch is fixing that case by checking for timeout_ns after the wakeup time was calculated depending on the quirks. Fixes: 0472bf06c6fd ("xhci: Prevent U1/U2 link pm states if exit latency is too long") Signed-off-by: Michael Grzeschik Cc: stable Link: https://lore.kernel.org/r/20201215193147.11738-1-m.grzeschik@pengutronix.de Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4409,19 +4409,19 @@ static u16 xhci_calculate_u1_timeout(str { unsigned long long timeout_ns; + if (xhci->quirks & XHCI_INTEL_HOST) + timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc); + else + timeout_ns = udev->u1_params.sel; + /* Prevent U1 if service interval is shorter than U1 exit latency */ if (usb_endpoint_xfer_int(desc) || usb_endpoint_xfer_isoc(desc)) { - if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { + if (xhci_service_interval_to_ns(desc) <= timeout_ns) { dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); return USB3_LPM_DISABLED; } } - if (xhci->quirks & XHCI_INTEL_HOST) - timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc); - else - timeout_ns = udev->u1_params.sel; - /* The U1 timeout is encoded in 1us intervals. * Don't return a timeout of zero, because that's USB3_LPM_DISABLED. */ @@ -4473,19 +4473,19 @@ static u16 xhci_calculate_u2_timeout(str { unsigned long long timeout_ns; + if (xhci->quirks & XHCI_INTEL_HOST) + timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc); + else + timeout_ns = udev->u2_params.sel; + /* Prevent U2 if service interval is shorter than U2 exit latency */ if (usb_endpoint_xfer_int(desc) || usb_endpoint_xfer_isoc(desc)) { - if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { + if (xhci_service_interval_to_ns(desc) <= timeout_ns) { dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); return USB3_LPM_DISABLED; } } - if (xhci->quirks & XHCI_INTEL_HOST) - timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc); - else - timeout_ns = udev->u2_params.sel; - /* The U2 timeout is encoded in 256us intervals */ timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000); /* If the necessary timeout value is bigger than what we can set in the