Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1234353rdb; Wed, 6 Dec 2023 12:22:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdygB7aXh4kDWS2JcX+z3Ie9cHZxRsGzBrBx2it6YfJinRoaDUSvAntxYGVqJG4TJThDst X-Received: by 2002:a17:90b:3912:b0:286:73b5:b388 with SMTP id ob18-20020a17090b391200b0028673b5b388mr1292670pjb.38.1701894143754; Wed, 06 Dec 2023 12:22:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701894143; cv=none; d=google.com; s=arc-20160816; b=w101jrsGgahzh/CMRvgXGrMxtUeJS6WN75SyG2fNdc8SCBOmjEX/SFMXZEiPnJejyf EL6iQQ969T8xPNIfCGh+XDxQJ+N6aNGSBK4Id+qAtfHV4T5ufZeBaNwb39ELDfmUcxUx CPPbV8aEjtBi4iNZRAuOwo+10kFid1+WoyBst27UWmUNYVEue0sToqUR5AR/zm5Ozw4r lIx5KOKqGd+8aYGadxvkgaOieVD7bSNRaQQZKVQXrfeacjhYQNfyHxzWtt5es0aS6OC6 PdG8fqpsNx0AlZfFH5tSqyqLwpnlUImR86zM3NEQw13KcjH6mp03OnMc6Jl5P/1vXJE8 9i0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=sRFsmyZ5qCKqzCrtUBDojqShJ00B0aVgG3aZXs2KlE4=; fh=u9v36QFHZKEaZ5rEMkDmbUiSIzu33X5+2gcDs+jkGIA=; b=kQvMGcIK1/idEPNV7zN4JT6A85xt5ovpX5GyYnAcwm9TcWvMhbAFDwOKVyLWkaSw5X UBkH2VuKRvWYTMonmCRADYszssIoKgeXRIT5NhTE7iFIt4f6yMsN6Kr/Zt79xB5NaB93 Ak6xbXsaFjDQ3OSnx25vz6nViJAYR6+sHsoS8TJwzOsskHpJF9+CBi0+7J/pnatoEx6v IWaIw89WR0GJoE96Mjh5w9ZTS86dUWCvrTRTc2eabk7vrjM4HCGW/m91aqvr+tYcxtw5 HrBSj4xqiXy7p3rEG2xEplAfDxMf709OhCWhwURKHeiF7gBv7RmHyysPCBuSCXkV0K1B sCLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ESVOeUxW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t7-20020a170902e84700b001cfb834d371si338263plg.113.2023.12.06.12.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 12:22:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ESVOeUxW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 1352280263A7; Wed, 6 Dec 2023 12:22:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442850AbjLFUWD (ORCPT + 99 others); Wed, 6 Dec 2023 15:22:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379461AbjLFUWC (ORCPT ); Wed, 6 Dec 2023 15:22:02 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68CC512F; Wed, 6 Dec 2023 12:22:08 -0800 (PST) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B6KFAIB010863; Wed, 6 Dec 2023 20:22:06 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=sRFsmyZ5qCKqzCrtUBDojqShJ00B0aVgG3aZXs2KlE4=; b=ESVOeUxWTe6/3ftOvnw6+zTd3QKLab5VKiNWeeKoyuC0T/jvSRech3W4Fv9YddMUj8zL 7/N+9JzA/t44EFIh6dzSXC7Z//Q5pRwvQnLm8vFlNphxZy4vP6SkiPoaxZBAe4XngedH qoqxQxOXm2LQkapvVheSUYP5OPAGIG2046xTq0fGQycWM9P70ChWXpctwW2bkXRXuBoB 5rHDHmtF9kyj91zc93kFGy6tA/edaIUeTlNEGeTP4QgGW/VUue6e7XjS3rzntE6vzhzb gG1eIMUc9retXWF3tsuYCJpN3mrUCi/bwvSz5yvywmOCoEorOfHeR+pNyp3lFFxKcbLl jQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ute972sxq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Dec 2023 20:22:05 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3B6KM4qm020081 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 20:22:04 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; Wed, 6 Dec 2023 12:18:23 -0800 From: Wesley Cheng To: , CC: , , Wesley Cheng Subject: [PATCH v2] usb: dwc3: gadget: Handle EP0 request dequeuing properly Date: Wed, 6 Dec 2023 12:18:14 -0800 Message-ID: <20231206201814.32664-1-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.49.16.6] 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: PNCx_rXno8R_zFuD3BpWwxveGnampAtT X-Proofpoint-ORIG-GUID: PNCx_rXno8R_zFuD3BpWwxveGnampAtT 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-06_16,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 adultscore=0 impostorscore=0 suspectscore=0 mlxscore=0 malwarescore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060140 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Wed, 06 Dec 2023 12:22:20 -0800 (PST) Current EP0 dequeue path will share the same as other EPs. However, there are some special considerations that need to be made for EP0 transfers: - EP0 transfers never transition into the started_list - EP0 only has one active request at a time In case there is a vendor specific control message for a function over USB FFS, then there is no guarantee on the timeline which the DATA/STATUS stage is responded to. While this occurs, any attempt to end transfers on non-control EPs will end up having the DWC3_EP_DELAY_STOP flag set, and defer issuing of the end transfer command. If the USB FFS application decides to timeout the control transfer, or if USB FFS AIO path exits, the USB FFS driver will issue a call to usb_ep_dequeue() for the ep0 request. In case of the AIO exit path, the AIO FS blocks until all pending USB requests utilizing the AIO path is completed. However, since the dequeue of ep0 req does not happen properly, all non-control EPs with the DWC3_EP_DELAY_STOP flag set will not be handled, and the AIO exit path will be stuck waiting for the USB FFS data endpoints to receive a completion callback. Fix is to utilize dwc3_ep0_reset_state() in the dequeue API to ensure EP0 is brought back to the SETUP state, and ensures that any deferred end transfer commands are handled. This also will end any active transfers on EP0, compared to the previous implementation which directly called giveback only. Fixes: fcd2def66392 ("usb: dwc3: gadget: Refactor dwc3_gadget_ep_dequeue") Signed-off-by: Wesley Cheng --- Changes from v1: - Added fixes tag drivers/usb/dwc3/gadget.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 858fe4c299b7..88d8d589f014 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2103,7 +2103,17 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, list_for_each_entry(r, &dep->pending_list, list) { if (r == req) { - dwc3_gadget_giveback(dep, req, -ECONNRESET); + /* + * Explicitly check for EP0/1 as dequeue for those + * EPs need to be handled differently. Control EP + * only deals with one USB req, and giveback will + * occur during dwc3_ep0_stall_and_restart(). EP0 + * requests are never added to started_list. + */ + if (dep->number > 1) + dwc3_gadget_giveback(dep, req, -ECONNRESET); + else + dwc3_ep0_reset_state(dwc); goto out; } }