Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2392435rda; Wed, 25 Oct 2023 01:03:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbP0cwxTlgYtf+dfnd99MmvkP8m4bQvlDNewoonDogxNdqv6JP4FVThOuDE0bax6n23vY2 X-Received: by 2002:a05:6808:311:b0:3b2:ec6d:e17e with SMTP id i17-20020a056808031100b003b2ec6de17emr13202185oie.9.1698220982719; Wed, 25 Oct 2023 01:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698220982; cv=none; d=google.com; s=arc-20160816; b=PG2jeH2aTidzZWtCI52zs4JIvlvQPhyRaoaLEyYpHPZQ+mI6nvvy+QJRNli1i+CDop RdZEHPy7FctLSZWW4Os8vEXS5SoZJqhpPgz44imKukfbeL15aZkgdbCqjCyzot223cUN 4kfZ+YffX3EWh9BtgWIozSxYwo/PUUagkJl0O7NL7B/r80COQpBMAjJzXavG2GkGd/Um lky45rTVR3gaW98+9b4dQPi5jQOiv9L6OyVV+674RuhvaaRZg7Gg6qUzYDVinsM62FLv wr2RlSi45lxPEeFDzbTFAF3L189dPpX4kkW9D4D81AwlfvHa6PsGaCsf0XWL7eJgljeD SfqA== 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:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=sh59dS//avy/5dWrZZuoYNGcTsB7U5WCcXjJCX9K60I=; fh=9II8U/Pg8p6BVi4LHv1BMEU4+kyD7t68BOCBoTLZeok=; b=y+l6FfrhzGHasapmdxDiGov7MyVjO+SbadXg1Z02XCnJ1yBf8YXmIJ85+hc+rg+iu/ 1r0DoehqSxvT9i9xzJvEaq6afAxYPeiurA9HB0tAYafg3tccpWfXl6k3LmXmS4dH5LpS Ap/40h1JjbG0I8AjFwc7TEjvEGX2rb7ny2JqFd4TjJwbqWBZgD7JizhMyWGDEMVgKaGI opgLne6o7fIJaw3gZtZRl1d1sZ4C63bTOr4vITtoFsFu0HyQrZ05P/m2Nhe+KQ6mPHTi X3yrcvYM8VFo3ZepdB9H/69zFFd6szWjdU1x+v/nqvNZuXaCEoyRQFQxXKa6ZbeIaVHk 9c5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jb1iyz1K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id n194-20020a25d6cb000000b00d9ac41bbe9bsi9529041ybg.390.2023.10.25.01.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 01:03:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jb1iyz1K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 598C08032074; Wed, 25 Oct 2023 01:02:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232864AbjJYICr (ORCPT + 99 others); Wed, 25 Oct 2023 04:02:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjJYICq (ORCPT ); Wed, 25 Oct 2023 04:02:46 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C179899 for ; Wed, 25 Oct 2023 01:02:42 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD7CFC433C9; Wed, 25 Oct 2023 08:02:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698220962; bh=jQc7NqI/yKjks8Vc9GC6S3bk6T8WV+i0v/+4jkcKVwo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Jb1iyz1KC38E0Q355lenhDghCvpYJXOEQWWFzT1di4TLfSm3Y0fWQh+BuGwHKymEi MHoX68UU1FjZK5VfuRkcF60v+Yc8CYFsMs6ox7OrXfsP1H3frwlW2+5drXu1+M+n/5 xkdQlYdvjOxK4iaq+acHv9oh+WSLumYjojZLeTUT9Ml1TZYUQdNYoM6Lf1z37r8ZzP vNaPz58MLgyvjQmtqTzh+mvLUlAiI4df/vDLbNEBG2hJIkgx2oHrz4ig1LHe6FPfgi mAzaWjQVT2VRAiguPbTN4UtR5chnBrLBfvNhLev6ZgOshxN7axRTuSDRKj5Y4cVzOw n2wnb5R0JBz3w== Message-ID: <0dee3bec-d49f-4808-a2f8-7a4205303e1f@kernel.org> Date: Wed, 25 Oct 2023 11:02:36 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/3] usb: dwc3: Modify runtime pm ops to handle bus suspend To: Elson Serrao , gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org References: <20230814185043.9252-1-quic_eserrao@quicinc.com> <20230814185043.9252-4-quic_eserrao@quicinc.com> <9be9fae5-f6f2-42fe-bd81-78ab50aafa06@kernel.org> Content-Language: en-US From: Roger Quadros In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, 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 agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 01:02:58 -0700 (PDT) On 24/10/2023 21:41, Elson Serrao wrote: > > > On 10/24/2023 3:14 AM, Roger Quadros wrote: >> Hi Elson, >> >> On 14/08/2023 21:50, Elson Roy Serrao wrote: >>> The current implementation blocks the runtime pm operations when cable >>> is connected. This would block dwc3 to enter a low power state during >>> bus suspend scenario. Modify the runtime pm ops to handle bus suspend >>> case for such platforms where the controller low power mode entry/exit >>> is handled by the glue driver. This enablement is controlled through a >>> dt property and platforms capable of detecting bus resume can benefit >>> from this feature. Also modify the remote wakeup operations to trigger >>> runtime resume before sending wakeup signal. >>> >>> Signed-off-by: Elson Roy Serrao >>> --- >>>   drivers/usb/dwc3/core.c   | 28 ++++++++++++++++++++++++++-- >>>   drivers/usb/dwc3/core.h   |  3 +++ >>>   drivers/usb/dwc3/gadget.c | 32 +++++++++++++++++++++++++------- >>>   3 files changed, 54 insertions(+), 9 deletions(-) >>> >>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >>> index 9c6bf054f15d..9bfd9bb18caf 100644 >>> --- a/drivers/usb/dwc3/core.c >>> +++ b/drivers/usb/dwc3/core.c >>> @@ -1518,6 +1518,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) >>>       dwc->dis_split_quirk = device_property_read_bool(dev, >>>                   "snps,dis-split-quirk"); >>>   +    dwc->runtime_suspend_on_usb_suspend = device_property_read_bool(dev, >>> +                "snps,runtime-suspend-on-usb-suspend"); >>> + >>>       dwc->lpm_nyet_threshold = lpm_nyet_threshold; >>>       dwc->tx_de_emphasis = tx_de_emphasis; >>>   @@ -2029,6 +2032,9 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) >>>         switch (dwc->current_dr_role) { >>>       case DWC3_GCTL_PRTCAP_DEVICE: >>> +        /* runtime resume on bus resume scenario */ >>> +        if (PMSG_IS_AUTO(msg) && dwc->connected) >>> +            break; >>>           ret = dwc3_core_init_for_resume(dwc); >>>           if (ret) >>>               return ret; >>> @@ -2090,8 +2096,13 @@ static int dwc3_runtime_checks(struct dwc3 *dwc) >>>   { >>>       switch (dwc->current_dr_role) { >>>       case DWC3_GCTL_PRTCAP_DEVICE: >>> -        if (dwc->connected) >>> +        if (dwc->connected) { >>> +            /* bus suspend scenario */ >>> +            if (dwc->runtime_suspend_on_usb_suspend && >>> +                dwc->suspended) >> >> If dwc is already suspended why do we return -EBUSY? >> Should this be !dwc->suspended? >> > > Hi Roger > > Thank you for reviewing. > If dwc->suspended is true (i.e suspend event due to U3/L2 is received), I am actually breaking from this switch statement and returning 0. Of course. I missed the break :) > >>> +                break; >>>               return -EBUSY; >>> +        } >>>           break; >>>       case DWC3_GCTL_PRTCAP_HOST: >>>       default: >>> @@ -2107,9 +2118,22 @@ static int dwc3_runtime_suspend(struct device *dev) >>>       struct dwc3     *dwc = dev_get_drvdata(dev); >>>       int        ret; >>>   -    if (dwc3_runtime_checks(dwc)) >>> +    ret = dwc3_runtime_checks(dwc); >>> +    if (ret) >>>           return -EBUSY; >>>   +    switch (dwc->current_dr_role) { >>> +    case DWC3_GCTL_PRTCAP_DEVICE: >>> +        /* bus suspend case */ >>> +        if (!ret && dwc->connected) >> >> No need to check !ret again as it will never happen because >> we are returning -EBUSY earlier if (ret); >> > Thanks for this catch. I will remove !ret check in v5. > >>> +            return 0; >>> +        break; >>> +    case DWC3_GCTL_PRTCAP_HOST: >>> +    default: >>> +        /* do nothing */ >>> +        break; >>> +    } >>> + >> >> While this takes care of runtime suspend case, what about system_suspend? >> Should this check be moved to dwc3_suspend_common() instead? >> > > Sure I can move these checks to dwc3_suspend_common to make it generic. Before you do that let's first decide how we want the gadget driver to behave in system_suspend case. Current behavior is to Disconnect from the Host. Earlier I was thinking on the lines that we prevent system suspend if we are not already in USB suspend. But I'm not sure if that is the right thing to do anymore. Mainly because, system suspend is a result of user request and it may not be nice to not to meet his/her request. Maybe best to leave this policy handling to user space? i.e. if user wants USB gadget operation to be alive, he will not issue system suspend? > Will rename this patch to "Modify pm ops to handle bus suspend" since this is now not limited to only runtime suspend/resume. Will also rename dwc->runtime_suspend_on_usb_suspend to dwc->delegate_wakeup_interrupt based on earlier feedback. > > I am still working on a clean way to enable/disable this feature (i.e set dwc->delegate_wakeup_interrupt flag) from the glue driver based on Thinh's feedback . > I will accommodate above feedback as well and upload v5. > > Thanks > Elson -- cheers, -roger