Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp35681rdh; Wed, 25 Oct 2023 15:21:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKr8VY8Iamcg99bGYXVDP2i4AEovB+uRmvYh0d1u6PnrFOuvrGudEEJdAPyMZMYuWh+HM4 X-Received: by 2002:a25:d214:0:b0:da0:a651:e220 with SMTP id j20-20020a25d214000000b00da0a651e220mr492849ybg.7.1698272502501; Wed, 25 Oct 2023 15:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698272502; cv=none; d=google.com; s=arc-20160816; b=eMs5DnUSkC47vRNa9Q/Pg/TI7bxD5Z/bdguZRu8dQDpAIVwe7z+hAy6kaBh7idvaaV Q3LmUgZc044fENwxU1L3/fKr24NCFovb2T+Z7JTbqEhAC2k0VkOGsEzMhjVSAfPNVAe4 wOo2ebg+0XenM1TqAWOu6NycDExzJqqja2j1ke93dIx8UyYk5MgLCeO4iid9mS2d0JNZ JVtwx9ZCeXxuJQIPxHPTUJzxA7gKn0w287e8zf9km9PiM1zVtz9IYNFKOuHJdM4ym3NQ iAIe/0rYsevaMSrfiWlkAZ2PZlbuybrsdhJNYRdM/Jv4Hk7k5Dmr+HP1mbkxuAh3YVuY 8l2A== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=frd7X+b4+QqkmgA1UT/vTe4tnMvePCr2JwVMf31XUok=; fh=UrXK8MNEMHIn8pKym+PxbNELK4rL/snal4oYZ2U0Oho=; b=goRCO5h4LZFcUtL7RNDlpB/3tRINgM1L1I7skFfqHvAowQoT8u5dRWw79TRsnQEPvL V0qpmlgNPqNzWXX0LtZZir1oEolDDMbt6qK81uaqNHl5MQwdQyzO/ODTl+LCD7/ILJ8f WMAPFLb0O2a/8R98IeDEwlVz06m0n/5R+mzoWgDAdqzYLWpUzIxXKlaysxutVCJbKlmy VZZrBePV3Eqw007Rz5jlc2wtYXbjOTMJSz1wJeJ+GsBXttc8qhHpiHTmS0xOV5Wr3B8x ExevmS+OK152plNk39wfEO3JX2xcpOe69MqJzTqVend/kzUqJISxEepcKYAo40s++xqX qUZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=cB2uTwOD; 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=quicinc.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id v5-20020a25fc05000000b00d8184353dcdsi12284978ybd.342.2023.10.25.15.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 15:21:42 -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=@quicinc.com header.s=qcppdkim1 header.b=cB2uTwOD; 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=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E8D6080A3116; Wed, 25 Oct 2023 15:21:38 -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 S229978AbjJYWV2 (ORCPT + 99 others); Wed, 25 Oct 2023 18:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjJYWV0 (ORCPT ); Wed, 25 Oct 2023 18:21:26 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283C8137; Wed, 25 Oct 2023 15:21:24 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39PMBhSt011435; Wed, 25 Oct 2023 22:21:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=qcppdkim1; bh=frd7X+b4+QqkmgA1UT/vTe4tnMvePCr2JwVMf31XUok=; b=cB2uTwODOxmgZw2DZwdojT2lNNCRSV0zPqLb+HosHK6D8TFu+wRUS1DNdoT5rp12CTyw 5DZMmjdHJuuSd0Uei4Ju8G0kdzu/xo7FPgXum35ShQUw0lVgP1uXtzwsXPZ6g8QLPIDY ftb4LRgtNflP10HpNiA8LZM+W6gXE9+pHXMR8vioMDxQiVR0qYDh+XDGemc6GdqMeBgr sELUtxbFcwV14eqtUfzhd4vYX5Zp17lULDOnwQtTb++cu7gtQcboMK1bw9riVor6UmcB AFLlZqA8brzKgaRisniAJAa4cZTyHX5/QCcr7Qe50+zErpeUwWJJsK0+HhO2FjoPOvvv Pg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ty5wdrub5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Oct 2023 22:21:17 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39PMLHRk012370 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Oct 2023 22:21:17 GMT Received: from [10.110.113.199] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 25 Oct 2023 15:21:16 -0700 Message-ID: Date: Wed, 25 Oct 2023 15:21:15 -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 v4 3/3] usb: dwc3: Modify runtime pm ops to handle bus suspend Content-Language: en-US To: Roger Quadros , , , , , , CC: , References: <20230814185043.9252-1-quic_eserrao@quicinc.com> <20230814185043.9252-4-quic_eserrao@quicinc.com> <9be9fae5-f6f2-42fe-bd81-78ab50aafa06@kernel.org> <0dee3bec-d49f-4808-a2f8-7a4205303e1f@kernel.org> From: Elson Serrao In-Reply-To: <0dee3bec-d49f-4808-a2f8-7a4205303e1f@kernel.org> 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 nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Mf4O9_ePsbzvPaMKt_MargIae0JXDtBK X-Proofpoint-ORIG-GUID: Mf4O9_ePsbzvPaMKt_MargIae0JXDtBK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-25_12,2023-10-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 spamscore=0 mlxscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310250192 X-Spam-Status: No, score=-4.2 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 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 15:21:39 -0700 (PDT) On 10/25/2023 1:02 AM, Roger Quadros wrote: > > > 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. Agree. Irrespective of whether USB is suspended or not it is better to honor the system suspend request from user. > 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? > Sure. So below two cases Case1: User doesn't care if gadget operation is alive and triggers system suspend irrespective of USB suspend. Like you mentioned, current behavior already takes care of this and initiates a DISCONNECT Case2: User wants gadget to stay alive and hence can trigger system suspend only when USB is suspended (there are already user space hooks that read cdev->suspended bit to tell whether USB is suspended or not for user to decide). Attempts to request system suspend when USB is not suspended, would result in a DISCONNECT. For supporting Case2 from gadget driver point of view, we need to extend this series by having relevant checks in suspend_common() Also, is it better to provide separate flags to control the gadget driver behavior for runtime suspend Vs system suspend when USB is suspended ? For example, what if we want to enable bus suspend handling for runtime suspend only and not for system suspend (Case1). Thanks Elson > >> 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 >