From patchwork Wed Jan 3 02:30:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 184574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4796798dyb; Tue, 2 Jan 2024 18:34:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfNQIhqrj7/ais2sbtDmdWWwGsctJcnUOdSdfZWBX8u0wOfSByU+Xq1e9OlQRZtKCHEFRU X-Received: by 2002:a17:906:3891:b0:a23:6059:89a3 with SMTP id q17-20020a170906389100b00a23605989a3mr6940336ejd.42.1704249263628; Tue, 02 Jan 2024 18:34:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704249263; cv=none; d=google.com; s=arc-20160816; b=OpP4rgX+52EWaDxVqfQ8UdCeiYZhAi8LAMt3wRwS0WrwJoOu1tvQHJp7UsdRJbUcRF 2GxvVNMp0gTkhwAPniq5i7JOhOm8sjr0S/N4JECjBtLfw2LVUTxkFNmyhVpHV6YzuilF EiQWPZBfpp5aLuWNWThJGd3t9N4DIz8PBm4kaqcvD2HfXynC0h002IOmcBkn1HafsK5V e/vhAHnccMPYPgPXmCuIgzDA6QXjnu+7rwydPExFOwQO488TC+ik3f+LnPLw/SIs5/S9 i7vKhLde4XS9moMh4f27YjEpw9f+efDnLzK4i9qhRfNdNhzZKX+/OEmC6vyrvK9iWTRP YmXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from:dkim-signature; bh=TeoqcCu0R0XQqlWPgePXuiwWmbLaaaXtjL/Yq6d0TEM=; fh=xFDRp41PEU4DAB+5FMkSSKTia6e84ALok8SFVNFQrQ0=; b=1K/QEkTG6jjQcLiYZo8tmwQ04Icroy0fiv88tR/ihNZY0DiVbp8IjS73MzD1H+4w3g ynZ3AgcKC2/xHxPijSq93O9Zo4e+r0xiZkjQtaLr0PovdqNS8O8yJvfjKEC8O5kuFYzc LIXx0uZLUstseI3VEZkRvQ1Ohs+D3dUmp8IQsU3GfPeu8D4dJ9qPB2e5TJtGaiefBspV 3fPzaZb7rb3tfad+9cJD+ccce5GIUts+mdF89Kxje2XRnzf1akcaK0tv7NxFT/VO4yH0 yKXT0mVsPXTQrKzMAKpmF/lezpdi6+TCKtUNybe6JgGXBZTKWHSNZfAE2KAdeUEBMlju 3ekQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VaYo0Eyr; spf=pass (google.com: domain of linux-kernel+bounces-15082-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15082-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id zj3-20020a170907338300b00a233c68ee0dsi11087694ejb.899.2024.01.02.18.34.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 18:34:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15082-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VaYo0Eyr; spf=pass (google.com: domain of linux-kernel+bounces-15082-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15082-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 20C5B1F212BC for ; Wed, 3 Jan 2024 02:34:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32CE918C3B; Wed, 3 Jan 2024 02:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="VaYo0Eyr" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0019A1100; Wed, 3 Jan 2024 02:30:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 4032JMOA018992; Wed, 3 Jan 2024 02:30:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:mime-version:content-type; s= qcppdkim1; bh=TeoqcCu0R0XQqlWPgePXuiwWmbLaaaXtjL/Yq6d0TEM=; b=Va Yo0EyrHWr0iWTb4LlK/QA5jP67Uo+USFWemXMtbM/+NSSpeSl/LY5IJkMPKhhbm3 Zf1OZ/73Ts9P9yZhYq/hG2pLoXs4jxB0KH2e8BvWPdtnhu3XiDy2KIiIrLbzTBcF TMDm1p4DwkZGF4Wy/NSKn+bOJg9FT5l8RfjcoeNiF26I7HCq/iB5rk8zPtA0iyP3 shwDcJQRONko6DOV5BwUVV5somSGQ1TobFBbyFfggNq72nZ23h4OWGaCsZFvm8Zo Irnp9CrmVCdTWt/BHlzIQAGpaZbvi6ucd2zPq5Hkc1OmRYz8IIIDxDtGihnE3y6B hPMML4B+APTXcTxnda3w== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vc9nn2c1f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 03 Jan 2024 02:30:33 +0000 (GMT) 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 4032UWMw032413 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 02:30:32 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) 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.40; Tue, 2 Jan 2024 18:30:32 -0800 From: Wesley Cheng To: , CC: , , Wesley Cheng Subject: [PATCH] usb: dwc3: gadget: Queue PM runtime idle on disconnect event Date: Tue, 2 Jan 2024 18:30:23 -0800 Message-ID: <20240103023023.477-1-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: RUc8TLnOzwmEioHIxDIuRIb_wh5RcHgc X-Proofpoint-ORIG-GUID: RUc8TLnOzwmEioHIxDIuRIb_wh5RcHgc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=950 phishscore=0 mlxscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 spamscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401030018 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787034876236276115 X-GMAIL-MSGID: 1787034876236276115 There is a scenario where DWC3 runtime suspend is blocked due to the dwc->connected flag still being true while PM usage_count is zero after DWC3 giveback is completed and the USB gadget session is being terminated. This leads to a case where nothing schedules a PM runtime idle for the device. The exact condition is seen with the following sequence: 1. USB bus reset is issued by the host 2. Shortly after, or concurrently, a USB PD DR SWAP request is received (sink->source) 3. USB bus reset event handler runs and issues dwc3_stop_active_transfers(), and pending transfer are stopped 4. DWC3 usage_count decremented to 0, and runtime idle occurs while dwc->connected == true, returns -EBUSY 5. DWC3 disconnect event seen, dwc->connected set to false due to DR swap handling 6. No runtime idle after this point Address this by issuing an asynchronous PM runtime idle call after the disconnect event is completed, as it modifies the dwc->connected flag, which is what blocks the initial runtime idle. Fixes: fc8bb91bc83e ("usb: dwc3: implement runtime PM") Signed-off-by: Wesley Cheng --- drivers/usb/dwc3/gadget.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 858fe4c299b7..de6056277f94 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3973,6 +3973,13 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); dwc3_ep0_reset_state(dwc); + + /* + * Request PM idle to address condition where usage count is + * already decremented to zero, but waiting for the disconnect + * interrupt to set dwc->connected to FALSE. + */ + pm_request_idle(dwc->dev); } static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)