Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2271179pxb; Mon, 11 Jan 2021 05:42:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvLLOGUx3R9XHiai8LbzhOB4u80WKDvxGwEp9ymKfHYOPJWz1kWwq0AjRoE3LP+ln1eiev X-Received: by 2002:a50:9354:: with SMTP id n20mr14562546eda.231.1610372524573; Mon, 11 Jan 2021 05:42:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610372524; cv=none; d=google.com; s=arc-20160816; b=i5JaCQvoiDRlag27sF6ksQPJsTZX9UNr0zcZd5ELn4+stN18vE8BDQY1yjmlPk9dqZ kS2RU8+2/iYgeSxVOyWIqlnnrVKRNbayHD3pwqsnO/IxNqDnU1oj2zPOb+EVzZ+T48gS FV7VMKzBvpslHDAXYojkTGseMppcpR3Dg5jvwdKsT5Q+kMj17mSALXvKoBXuNL9nH3yV 5AD6zMW2eLn8VOzRYgh90+VKE7sZAssV37xZYveUgF00z8JGA70s4KqA9aexxRlkjjJX H7eMEmPPpq49Uu1zKxrbBuJZWhr5hOLM4o8ZnIbnQ7VsQUU6zuyHEY8MWszgxwzQ2znn 9Ujg== 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=vKM+13Avh3Jdjm8EvZfvIIKlf8VJVy0al2+RJUf6EQ4=; b=xpUkLPVHwooDteL/AtbyGbONyyEV2mUuGhJ6EX/4IDGAQDXDE3OOW7tU5MqCywtnMR AezUS0iBfoaNsSMLwf0RSu3Lqx/VIRQHjfAUOO8ON0Y0ihZanQNisP0LjxoUXGKWNq5F 8EHk8I5rxgRuTHoOqhu3XnYZTUQWyMpIgZFrkUIc3M2ll03/zXlt9GwD7SMgilAqBU54 z1CjU2AXz396/hjbbAYJ1cRAfOG4zVNYaSW/4AE0G1s43XmblJLQN4gEk0hmb+/ckFrz oRfvskQ5DeDe5suqwNV/MN1qi0Eu/6rBUDm0yHKBofCybOdZ/bIZBoyJ8FX5l+4A1arB lJfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zAvgMgwr; 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 j5si6720169ejb.653.2021.01.11.05.41.40; Mon, 11 Jan 2021 05:42:04 -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=zAvgMgwr; 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 S1731661AbhAKNNN (ORCPT + 99 others); Mon, 11 Jan 2021 08:13:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:59412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730952AbhAKNMU (ORCPT ); Mon, 11 Jan 2021 08:12:20 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 24E6222BE9; Mon, 11 Jan 2021 13:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370699; bh=q3SHbNjSzqmp65jcj52ew86tKxWmzZ1+P7pG1RDWHIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zAvgMgwrsz9SLu0kOtNMDoHQYtDaqrRe9K4ZivqRj1yJcEYVH/yj0wY9q69+6MR0B Pbx8IXh6RLiRYqyB7+xVQlRHajAjjJIFwtlE7uqYTSkH6MBH1Kqwxbc3h6dsR1sWJc TYm5Ehjcbex1CDp5Lj1p++Zjz676nUrc/JuCJgj4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Grzeschik Subject: [PATCH 5.4 58/92] USB: xhci: fix U1/U2 handling for hardware with XHCI_INTEL_HOST quirk set Date: Mon, 11 Jan 2021 14:02:02 +0100 Message-Id: <20210111130041.942865164@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130039.165470698@linuxfoundation.org> References: <20210111130039.165470698@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 @@ -4642,19 +4642,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. */ @@ -4706,19 +4706,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