Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3513828rdb; Wed, 13 Sep 2023 14:37:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqo0an+hYn6WDgXjOG8vE+kL3cTop5TKXRRrqFSxCSgPBoQf0CyIi6+H+pkY9pXeJTEfXc X-Received: by 2002:a17:90b:33cd:b0:26b:280b:d24c with SMTP id lk13-20020a17090b33cd00b0026b280bd24cmr3318790pjb.42.1694641039768; Wed, 13 Sep 2023 14:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694641039; cv=none; d=google.com; s=arc-20160816; b=0UVtLRE4ZpnCtNqTWbEkphRYBZmJ7Rh1H/NpmNJEICXbaEserdFMMNc72zKWj7Nv7+ st6QWfCBfqVcYDHzviMNIbZl2eNJYOpNNgpM9jZknCJgEXBNDkrrz1bjp6xlrTTGa22E neQp0R8H9KsPD8b+HdwDSx1Gm4lJdhaO36W1By2S8u8cQFkCZApJ4f+faBm2xsCTIZYA +K5L1bvGCA/dn9vZBUTss4tQ1T2lnF+IPgp2DcGdcwe7k9L4Fcl0RvYJxuvq3jFGBLcC k6kZLJIYoTql3lT5r5pvhoHsSkmNpbBYfTwlX3/zjU+8aYiBLDPxz8hCpXQ/jfNULkn7 cW9A== 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:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=uWpCbMkAZ+yN3xZvZrPbOIdmYivh0fJfWEN/JR2wzTc=; fh=IB2e9pH3A5OyWyo0u7UT27tfQSQujk9NJWGrEA/bm1w=; b=bTM6wdYwXuUm2qJ/EUbVNTqRZ6w3X6v7sMMAu/tgK9yQuGhAX5muivpVFzDGNKTizh 7eIN6moBxwRr9RPLNBoDX1PBjx88TyvE07OLTOL1NCq0ZDRqPPS7XIG/Ec6uQTemJZMt NkUpg18NJm5QLysJFmfPvNcgDpf/3VW4dNZVod5cKa9WorwxrXVPr3fl5Gcwmp3olonV rBfM46+tEWaiTD4I9rPH3p0NNfUcXg3teMJolfY1MXSp1WOQc92N1OVCdBkxCitcQLPf yt/IEe4ZsGJ583NoN3kjmx9MZLta8LXsCnVHqejp4AgtqZuRpQCI7h2fMx27oUAUWFkN GG0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cqws+xpR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h22-20020a17090acf1600b0026cab818aa2si2298449pju.100.2023.09.13.14.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:37:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cqws+xpR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 096B480310D4; Wed, 13 Sep 2023 07:20:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241236AbjIMOUc (ORCPT + 99 others); Wed, 13 Sep 2023 10:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241408AbjIMOUV (ORCPT ); Wed, 13 Sep 2023 10:20:21 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47812CD8; Wed, 13 Sep 2023 07:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694614814; x=1726150814; h=message-id:date:mime-version:to:cc:references:from: subject:in-reply-to:content-transfer-encoding; bh=5jPY8v6Vag2va/ECGzDgocqpjhEHew/KUS5KSoroMjk=; b=Cqws+xpRq552LLkHRWZbBbvs20iAMKD/idsez5LWbhZjCpS5pDPTZiNg 89bZQTWWFHPrKHIZVNqAvAgBQf2lVzPgCH7qbpsVsWGYqW5Z+ASPArGSq gmxShBw3q+cwy+PQFOvNaTv4+WFVDq8QXv1I3VDCWoBixTqvqgQrKKGun /yNIJuntF6k6dsF4w+v5hAtISrZfvG7rBgtpTRldcqKRizDpRAdVtmaQ8 L+2DGhOj5FtN8YEM9pAaOW0K1g+1NHRq0Wa4XXn6ZfoYwAjWa+3/eBC6t 25jRNAP6b5nRm4THhZvShafITPtwxUlFO+XqgjrpkHBz9lHIuDubhPYXm g==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="363705890" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="363705890" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 07:20:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="693853121" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="693853121" Received: from mattu-haswell.fi.intel.com (HELO [10.237.72.199]) ([10.237.72.199]) by orsmga003.jf.intel.com with ESMTP; 13 Sep 2023 07:20:11 -0700 Message-ID: Date: Wed, 13 Sep 2023 17:21:32 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.13.0 Content-Language: en-US To: Wesley Cheng , mathias.nyman@intel.com, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, quic_jackp@quicinc.com References: <20230901001518.25403-1-quic_wcheng@quicinc.com> <8dd86cf5-6337-b8f5-34d5-dcd290dc2d38@linux.intel.com> From: Mathias Nyman Subject: Re: [PATCH v2] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 (lipwig.vger.email [0.0.0.0]); Wed, 13 Sep 2023 07:20:47 -0700 (PDT) X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 lipwig.vger.email Hi On 13.9.2023 0.51, Wesley Cheng wrote: > Hi Mathias, > >>> 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(). I think you found a bug. We should clear suspended_ports bit if link state in portsc is anything other than U3, Resume or Recovery. Not doing so might cause USB_PORT_STAT_C_SUSPEND bit to be set incorrectly in a USB2 get port status request. So we want something like: if (suspended_ports bit is set) { if (U3 || Resume || Recovery) { don't touch anything } else { clear suspended_port bit if ((U2 || U0) && USB2) set bus_state->port_c_suspend bit } I'll look into it -Mathias