From patchwork Mon Feb 27 23:20:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 62195 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2708968wrd; Mon, 27 Feb 2023 15:50:46 -0800 (PST) X-Google-Smtp-Source: AK7set9FLlFH5J7MzmXJbXryzM1+kCnZCOx7QXGzEVs0BRPRWg0bXTwYhqlBzBHc61J+AhGi678H X-Received: by 2002:aa7:dbc6:0:b0:4ac:c690:d637 with SMTP id v6-20020aa7dbc6000000b004acc690d637mr1543421edt.31.1677541845911; Mon, 27 Feb 2023 15:50:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677541845; cv=none; d=google.com; s=arc-20160816; b=Fkvp5atcRt9xXE3F3oZ/ktZUA7VuCTMzpLexdHOefdwt82ROH+7ciQHO5WPHiLXf4z dI7rzjaeDl8gxQ2bCiSwUVC31SHe+h9Djr+9ZNwfFHJfaP8w2L/+OanD/Jt3NgUZiX1k 0lMkaNrLIGVgbwsmCT+AZeUytKPrEMqHvYg454vTvF9zMvlbeZqxcXApfCSy2tfx0Uhx ljW0vyHIiumS+nlopp9qoRfHpVZdQ12q03iV9BXoJ4dahgQXuklK4MVhZPoY3gLtzwIi 1MqaKvbPpUgLWeyz5ooufZrztefhKJ/IbbzAK/cidlz2kbcd0vaTgNH2+Vx4du4TcgnN NOVg== 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=e/5+7AwQGL46bVz4ybl5pWLY3xCLSybzysKgF3CQVeI=; b=ZRzrHMb6xIBDs4qAMBpoXVLf8S0BkFoSmEAcuixFw8Y7P+MkVUmZb3Vdm8uFy0WcSD qwgjazdygR2SOb2NmFhWylh+14rSdjfctO7Ap71A+wzdj9DpGEiypFg37KGgZ/ztGtjm tTlmN5BP9Q2KvXGUMrx1oTfHaX+DqMySaBOJzKwQF2qNyVtGiTjlGSchcZX212/1JoOc nVJvp3ueK2hm14mtKIT8zR8PECJ+0oZiDRPuSOsCqTuJhdgFCRn7p0Cz6auFawuKd+ZN 0k7XbEH6IoetKk8Ko6D+eAKeq5Ywer3sh6sAXWUOc3GSxTeZK3v7vpZgL42U7DzYaNeb 3Jew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Zo8ApJgs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be5-20020a0564021a2500b004accbbd8e80si8944935edb.652.2023.02.27.15.50.22; Mon, 27 Feb 2023 15:50:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Zo8ApJgs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbjB0XU5 (ORCPT + 99 others); Mon, 27 Feb 2023 18:20:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjB0XUy (ORCPT ); Mon, 27 Feb 2023 18:20:54 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 893E02195A; Mon, 27 Feb 2023 15:20:52 -0800 (PST) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31RJD2Oo013766; Mon, 27 Feb 2023 23:20:50 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=e/5+7AwQGL46bVz4ybl5pWLY3xCLSybzysKgF3CQVeI=; b=Zo8ApJgsyw6BV+tBjjEupn1n0URupuLJBQNn/CJBQpaM5SjOePYtj8PU8i5Nr2cMJ22X PDlfZN7iUgxbg9zSLVkBf08r9PZnVjnJ4Zbpe3CoLnE5c+onVM7+Z7Pdf0MGFQ8KbtvH wkeTM1/pL4rR6crg3w+7csQwGeeJ6wjXwZokXGWUL8vj5vLLa856S5Q+jUL2IRs11mdJ JiAtfoCNJkvTc0GPZfuxcOMUPJOgdIM3LCWvSisnUq7LeZrvhfAjjk+MQpfJSaet3UXT kWI+ljtjFjtNl/hapOCQPgHz8+vVjN5RhtKqrw2ntETG42mkQHNNdy78WHViXp1e+bZg 9w== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3nybgue9wx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Feb 2023 23:20:49 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 31RNKmu7021748 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Feb 2023 23:20:48 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.986.41; Mon, 27 Feb 2023 15:20:48 -0800 From: Wesley Cheng To: , CC: , , , Wesley Cheng Subject: [PATCH] usb: dwc3: gadget: Add 100uS delay after end transfer command without IOC Date: Mon, 27 Feb 2023 15:20:35 -0800 Message-ID: <20230227232035.13759-1-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) 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: fEq-p8KukAdKcPlVBtAPUyP8dzqSns2Y X-Proofpoint-ORIG-GUID: fEq-p8KukAdKcPlVBtAPUyP8dzqSns2Y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-27_17,2023-02-27_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 bulkscore=0 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 mlxlogscore=461 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302270187 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759030118665563345?= X-GMAIL-MSGID: =?utf-8?q?1759030118665563345?= Previously, there was a 100uS delay inserted after issuing an end transfer command for specific controller revisions. This was due to the fact that there was a GUCTL2 bit field which enabled synchronous completion of the end transfer command once the CMDACT bit was cleared in the DEPCMD register. Since this bit does not exist for all controller revisions, add the delay back in. An issue was seen where the USB request buffer was unmapped while the DWC3 controller was still accessing the TRB. However, it was confirmed that the end transfer command was successfully submitted. (no end transfer timeout) In situations, such as dwc3_gadget_soft_disconnect() and __dwc3_gadget_ep_disable(), the dwc3_remove_request() is utilized, which will issue the end transfer command, and follow up with dwc3_gadget_giveback(). At least for the USB ep disable path, it is required for any pending and started requests to be completed and returned to the function driver in the same context of the disable call. Without the GUCTL2 bit, it is not ensured that the end transfer is completed before the buffers are unmapped. Signed-off-by: Wesley Cheng --- drivers/usb/dwc3/gadget.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 3c63fa97a680..a4c02e4f7f7c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1699,6 +1699,7 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc) */ static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool interrupt) { + struct dwc3 *dwc = dep->dwc; struct dwc3_gadget_ep_cmd_params params; u32 cmd; int ret; @@ -1722,10 +1723,13 @@ static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool int WARN_ON_ONCE(ret); dep->resource_index = 0; - if (!interrupt) + if (!interrupt) { + if (DWC3_IP_IS(DWC31) || DWC3_VER_IS_PRIOR(DWC3, 310A)) + udelay(100); dep->flags &= ~DWC3_EP_TRANSFER_STARTED; - else if (!ret) + } else if (!ret) { dep->flags |= DWC3_EP_END_TRANSFER_PENDING; + } dep->flags &= ~DWC3_EP_DELAY_STOP; return ret; @@ -3774,7 +3778,11 @@ void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, * enabled, the EndTransfer command will have completed upon * returning from this function. * - * This mode is NOT available on the DWC_usb31 IP. + * This mode is NOT available on the DWC_usb31 IP. In this + * case, if the IOC bit is not set, then delay by 100uS + * after issuing the EndTransfer command. This allows for the + * controller to handle the command completely before DWC3 + * remove requests attempts to unmap USB request buffers. */ __dwc3_stop_active_transfer(dep, force, interrupt);