Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp432163ybk; Wed, 20 May 2020 03:22:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbZkq11yc9OpgU8CLrsRsUYxsAk/5lHXr3hKwrgY3p99zVE8zeAJ+nySw6d4Z6ycPXvtI4 X-Received: by 2002:a05:6402:783:: with SMTP id d3mr2714372edy.295.1589970141763; Wed, 20 May 2020 03:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589970141; cv=none; d=google.com; s=arc-20160816; b=0ytSqupYGucdoGIcbbaaIgwUIEexDbXZWczZLp7s24j113Wkwi35yjaFuPbRLMdDDO vNh/YRcFhv1s1Jr38DItzk5jqJA72H5UdZdtte/Bfcua+ZAloMXgNDf6aDf3it5ZefMr bnmCwAIKjhl6/cvklBDnyVDDSs/2n2E0ex3NgfJkiEYL8n6ri6BzYh5N4Xowj9h3birY yDiH4LeLjq8epyWyzRV4PtYH4XdgtXbkXcxmuz/E1YG6kuA9wcN6GCMYktAMT1hDTMpB +ZbsJIb4Z+LPUhxSHIltCAOhiHjuRplWFxMaP9+GUtI0LiQfKPDpmlqlKMxteLr+9kna OMsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Ebu8fT+vrSXms/i1vPal3JJpwZV8vc8/oNo+8Q/9Djo=; b=KrfCpvA28j2bzY9bfCjKEnnOVg5oCuPvE0vUcdJzgt1A3P54/9LoBoUBdL455mIIRT k4cM0veOm+5MRkMvZ4zvivdYIMCbL4u++NIY0okgH8ZWqtVwwXHbJP1pygoaDYGx1mn8 jkURS740t/AbpTGtckxeg/o0pCBWwFsYtU70abeLrSGeP1l/FswLPaRUfJj4c7wh2ohT tj9NWsXb2mIvGj5JoCxN58Ae7Ml/MXvEDW+i77s1ecbA8zQy0uO6QiknpCNmG0atMKQH dnyDXn3wuz58fFOaPTT0QbhtqYL53k22PBqvlVGsmr5Npf9r7IesddozIWK0bbgUIOuZ tJzw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si1217293eda.480.2020.05.20.03.21.59; Wed, 20 May 2020 03:22:21 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726812AbgETKS0 (ORCPT + 99 others); Wed, 20 May 2020 06:18:26 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:56499 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbgETKSZ (ORCPT ); Wed, 20 May 2020 06:18:25 -0400 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jbLnp-0001JH-UI; Wed, 20 May 2020 10:18:22 +0000 From: Kai-Heng Feng To: mathias.nyman@intel.com Cc: Kai-Heng Feng , Greg Kroah-Hartman , linux-usb@vger.kernel.org (open list:USB XHCI DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/2] xhci: Poll for U0 after disabling USB2 LPM Date: Wed, 20 May 2020 18:18:11 +0800 Message-Id: <20200520101811.2623-2-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200520101811.2623-1-kai.heng.feng@canonical.com> References: <20200520101811.2623-1-kai.heng.feng@canonical.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org USB2 devices with LPM enabled may interrupt the system suspend: [ 932.510475] usb 1-7: usb suspend, wakeup 0 [ 932.510549] hub 1-0:1.0: hub_suspend [ 932.510581] usb usb1: bus suspend, wakeup 0 [ 932.510590] xhci_hcd 0000:00:14.0: port 9 not suspended [ 932.510593] xhci_hcd 0000:00:14.0: port 8 not suspended .. [ 932.520323] xhci_hcd 0000:00:14.0: Port change event, 1-7, id 7, portsc: 0x400e03 .. [ 932.591405] PM: pci_pm_suspend(): hcd_pci_suspend+0x0/0x30 returns -16 [ 932.591414] PM: dpm_run_callback(): pci_pm_suspend+0x0/0x160 returns -16 [ 932.591418] PM: Device 0000:00:14.0 failed to suspend async: error -16 During system suspend, USB core will let HC suspends the device if it doesn't have remote wakeup enabled and doesn't have any children. However, from the log above we can see that the usb 1-7 doesn't get bus suspended due to not in U0. After a while the port finished U2 -> U0 transition, interrupts the suspend process. The observation is that after disabling LPM, port doesn't transit to U0 immediately and can linger in U2. xHCI spec 4.23.5.2 states that the maximum exit latency for USB2 LPM should be BESL + 10us. The BESL for the affected device is advertised as 400us, which is still not enough based on my testing result. So let's use the maximum permitted latency, 10000, to poll for U0 status to solve the issue. Signed-off-by: Kai-Heng Feng --- drivers/usb/host/xhci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 14181a7ea375..1058f604975b 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4474,6 +4474,9 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, mutex_lock(hcd->bandwidth_mutex); xhci_change_max_exit_latency(xhci, udev, 0); mutex_unlock(hcd->bandwidth_mutex); + readl_poll_timeout(ports[port_num]->addr, pm_val, + (pm_val & PORT_PLS_MASK) == XDEV_U0, + 100, 10000); return 0; } } -- 2.17.1