Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2936436rdb; Tue, 12 Sep 2023 17:53:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRxfRYmO63KaVixJieGUwx1PW3Oq/1xv3PtjRIlwaPvhXGIcHf8vB4fzf1CcWoEVahSCPi X-Received: by 2002:a17:902:d4d2:b0:1b9:e9b2:124b with SMTP id o18-20020a170902d4d200b001b9e9b2124bmr1423855plg.64.1694566392218; Tue, 12 Sep 2023 17:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694566392; cv=none; d=google.com; s=arc-20160816; b=aM51T5Hw28ncZoSv1KpTjLLqnGXaiNtFGH/gUIWMT6kC6XeclRLN9SO7jEnmNsTU8C 9Jew8CPZZu+EVYOOlpjY0dujxCtjaScN4YTV68E8JL5aJjUW2WqjGS3lSQU6le5iwcmo rSR8GnHV4ndsRFjaxlZBIibzquMgB9BJk6Obp7x/OiTaThIAhBDA61y0Q2n71JJ4tD+T 0Q5WPyQSuadZj6LmEftpt9oh/VsNcmQmdDsfylRAYWYdRnp0fdCkbv21BuCt8UtQgyoP MsttIeUMxDS/lf00FWWLE8fI7aaLNyZpqAeD79XjeBkuQ7CHktJhDsrLSfLV06wM2huo nzZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=eHXVCyPaKtscWd6OatiAUnCF33+lL86aGfQqeLeSQjQ=; fh=/1rBLbR6k1T6dGnQsbjTTAcre9Wq3+leMgadlGl6zBA=; b=L4138qEUjtXqQk/NxkqjxhfGCezd7tn/ZleVW/fKBj1BWL4j2gZb7Ui+rzJ264cjRk dfN2dS1SxlNLfUGsMg/+/vP0jprPO/Ke2dULkiVFx9sGlnP5LSE9acM8cSXQC+KgKnhY zTjYV2IX9auJiiaw159qC6bOy2ELho/cTQqlFf/SwJVYPQKzKJp5EfrkXYL+rhV+ILpG fl5fwTGr+24Gxt8G5WKrd1yBoZuTelL3rCAuIhY36Rn44LSLctPwmas/Pbpu3I907uI3 MJI/ARyGperUFNbZqalKK9HzidjMNclu0G9HjYXd40lXnzNRUIXhBnRkw5lpst0h4e7t 5wjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=jspYczqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id i3-20020a170902c94300b001bf223b6595si9251503pla.484.2023.09.12.17.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 17:53:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=jspYczqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 56BE180FC14A; Tue, 12 Sep 2023 14:52:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233634AbjILVwD (ORCPT + 99 others); Tue, 12 Sep 2023 17:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230453AbjILVwC (ORCPT ); Tue, 12 Sep 2023 17:52:02 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB96B10CC; Tue, 12 Sep 2023 14:51:58 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38CLlB4U009709; Tue, 12 Sep 2023 21:51:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=message-id : date : mime-version : subject : from : to : cc : references : in-reply-to : content-type : content-transfer-encoding; s=qcppdkim1; bh=eHXVCyPaKtscWd6OatiAUnCF33+lL86aGfQqeLeSQjQ=; b=jspYczqgdr8FRWQtUfr5uVlUcGTVhNCGsL7B8RojZstzm4n5iOt3A/mqJXK/4kfmRxES /RVAziO1NNz5KB/WRH0MWJW6tX0BmtmskCjrQ7asUUU96Lf4OVdW+aE8X8dMh/zwDgFa MtHPem79L3hli8MjAKLdkoSzeMex1sJ4LNnAMxkf9yKvNPSaesANZiv4YcKew4o/v0li lCaLgG5XtX6G/y/foks8PB+fKCQZGufaBv9UmtWI2cfk+jDcFqofIxR4NXrWJxdjzjue kh1M57IeuN4RINATU+zeq7ONNqopSa9AesKeFruhWR01gs6qmz7p3Yk8FRaSVAi3RvIK Aw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t2y7q83n3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Sep 2023 21:51:52 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 38CLppCI011190 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Sep 2023 21:51:51 GMT Received: from [10.110.43.192] (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Tue, 12 Sep 2023 14:51:51 -0700 Message-ID: Date: Tue, 12 Sep 2023 14:51:50 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH v2] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present Content-Language: en-US From: Wesley Cheng To: Mathias Nyman , , CC: , , References: <20230901001518.25403-1-quic_wcheng@quicinc.com> <8dd86cf5-6337-b8f5-34d5-dcd290dc2d38@linux.intel.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: LR4R7ND1D1UpC4D5TGvwaW9gMyTc8zFA X-Proofpoint-ORIG-GUID: LR4R7ND1D1UpC4D5TGvwaW9gMyTc8zFA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-12_21,2023-09-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 clxscore=1015 spamscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309120185 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 12 Sep 2023 14:52:13 -0700 (PDT) X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Hi Mathias, On 9/11/2023 5:15 PM, Wesley Cheng wrote: > Hi Mathias, > > On 9/11/2023 6:50 AM, Mathias Nyman wrote: >> On 1.9.2023 3.15, Wesley Cheng wrote: >>> There is a 120ms delay implemented for allowing the XHCI host >>> controller to >>> detect a U3 wakeup pulse.  The intention is to wait for the device to >>> retry >>> the wakeup event if the USB3 PORTSC doesn't reflect the RESUME link >>> status >>> by the time it is checked.  As per the USB3 specification: >>> >>>    tU3WakeupRetryDelay ("Table 7-12. LTSSM State Transition Timeouts") >>> >>> This would allow the XHCI resume sequence to determine if the root hub >>> needs to be also resumed.  However, in case there is no device >>> connected, >>> or if there is only a HSUSB device connected, this delay would still >>> affect >>> the overall resume timing. >>> >>> Since this delay is solely for detecting U3 wake events (USB3 specific) >>> then ignore this delay for the disconnected case and the HSUSB connected >>> only case. >> >> Thanks, makes sense >> >>> >>> Signed-off-by: Wesley Cheng >>> --- >>>   drivers/usb/host/xhci.c | 26 +++++++++++++++++++++++++- >>>   1 file changed, 25 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c >>> index e1b1b64a0723..640db6a4e686 100644 >>> --- a/drivers/usb/host/xhci.c >>> +++ b/drivers/usb/host/xhci.c >>> @@ -805,6 +805,24 @@ static void xhci_disable_hub_port_wake(struct >>> xhci_hcd *xhci, >>>       spin_unlock_irqrestore(&xhci->lock, flags); >>>   } >>> +static bool xhci_usb3_dev_connected(struct xhci_hcd *xhci) >>> +{ >>> +    struct xhci_port    **ports; >>> +    int            port_index; >>> +    u32            portsc; >>> + >>> +    port_index = xhci->usb3_rhub.num_ports; >>> +    ports = xhci->usb3_rhub.ports; >>> + >>> +    while (port_index--) { >>> +        portsc = readl(ports[port_index]->addr); >>> +        if (portsc & (portsc & PORT_CONNECT)) >>> +            return true; >>> +    } >>> + >>> +    return false; >>> +} >>> + >> >> This is one way, but we can probably avoid re-reading all the usb3 >> portsc registers >> by checking if any bit is set in either: >> >>   // bitfield, set if xhci usb3 port neatly set to U3 with a hub request >> xhci->usb3_rhub.bus_state.suspended_ports >> >> // bitfield, set if xhci usb3 port is forced to U3 during xhci suspend. >> xhci->usb3_rhub.bus_state.bus_suspended >> >> But haven't checked this works in all corner cases. >> > Thanks for the suggestion.  I think I also looked at seeing if we could > use the suspended_ports param, and it was missing one of the use cases > we had.  I haven't thought on combining it with the bus_suspend param > also to see if it could work.  Let me give it a try, and I'll get back > to you. > So in one of our normal use cases, which is to use an USB OTG adapter with our devices, we can have this connected with no device. In this situation, the XHCI HCD and root hub are enumerated, and is in a state where nothing is connected to the port. I added a print to the xhci_resume() path to check the status of "suspended_ports" and "bus_suspended" and they seem to reflect the same status as when there is something connected (to a device that supports autosuspend). Here's some pointers I've found on why these parameters may not work: 1. bus_suspended is only set (for the bus) if we reach the bus_suspend() callback from USB HCD if the link is still in U0. If USB autosuspend is enabled, then the suspending of the root hub udev, would have caused a call to suspend the port (usb_port_suspend()), and that would set "suspended_ports" and placed the link in U3 already. 2. "suspended_ports" can't differentiate if a device is connected or not after plugging in a USB3 device that has autosuspend enabled. It looks like on device disconnection, the suspended_ports isn't cleared for that port number. It is only cleared during the resume path where a get port status is queried: static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status, u32 portsc) { ... /* USB3 specific wPortStatus bits */ if (portsc & PORT_POWER) { *status |= USB_SS_PORT_STAT_POWER; /* link state handling */ if (link_state == XDEV_U0) bus_state->suspended_ports &= ~(1 << portnum); } IMO, this seems kind of weird, because the PLS shows that the port is in the RxDetect state, so it technically isn't suspended. If you think we should clear suspended_ports on disconnect, then I think we can also change the logic to rely on it for avoiding the unnecessary delay in xhci_resume(). Thanks Wesley Cheng