From patchwork Thu Apr 13 19:53:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 83079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1290595vqo; Thu, 13 Apr 2023 13:05:45 -0700 (PDT) X-Google-Smtp-Source: AKy350adQ6epCPyrzOCvt72kPR6eOpwrIg5jk8Ffa2Mx2CkDpI2FBR0A089p22POoBdemccxCm0K X-Received: by 2002:a05:6a00:17a4:b0:633:3954:986e with SMTP id s36-20020a056a0017a400b006333954986emr4956848pfg.28.1681416344752; Thu, 13 Apr 2023 13:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681416344; cv=none; d=google.com; s=arc-20160816; b=sgWqzKFx8wMvHdas+hdirmunDAA+sRoOrSu3bSiNmretb1/WnwBPsVni4DCqDlhx4l JcS6uABPNTyjnchnzvwwWdxPlZUFP0FCr/CA7nG24L/ohtapk9ZMN/nxT5FiuJO21DFE SotWHpuGo9BKyXQq5ftPZo1C8D6M2M0g0BCOkpQ0WuD6nlqGKLZdg5eSecN2jyhDPx8u XlAPOONWOjoXQT2MPT+hDXA6KWq6t4wFNt3Utkfol2tzHuORYRGZLhn7ErSMZfpi1oC3 UP1CsPeZUIBbOELfzmbeDq55LxNzRGaM1+cEIBx8P6mMibY2rmvsbeGGN3mJRRj6kBZG wKoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=785MwKS2iQyp2XbJLbbqFpGyH2DA45lwssNOf53Znf0=; b=DIGUuzzwtBIc/J1s/OzJuppcj7bXchm8xQ1KHx9J8z5B8wmTxsOAFjhE5x9iL6Z+U4 bZ/FntVmnz61QQihY8mIe51km/J1QIPeI1UYP3subYoFS/rNq9d9MtOGuGSj+Jc3Y7xI 51ROADk7yIFqOiWICG3XxXaK1vKfxdpSpGnLTGc3/B9P79QBqzlBuWGg7ph4Cs7U0iYE IWG6So85fB/wl/8oiraj2AiYFflSDT4ZQAloMaHLluH6boFlrWmh69H21GJ52Y4dFgDh 7+BJ19D6jlWGfljGWGryYIbrl7E6qUNaeYJMmcbRVQ1nkP5DI0w/ignzlsrV69ZILB2k a22g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=pr7zWFoP; 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 n9-20020a635909000000b00519858f0ac3si2720081pgb.157.2023.04.13.13.05.29; Thu, 13 Apr 2023 13:05:44 -0700 (PDT) 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=pr7zWFoP; 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 S230028AbjDMTxs (ORCPT + 99 others); Thu, 13 Apr 2023 15:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbjDMTxo (ORCPT ); Thu, 13 Apr 2023 15:53:44 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 855CE65BD; Thu, 13 Apr 2023 12:53:43 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33DJljN6002936; Thu, 13 Apr 2023 19:53:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=785MwKS2iQyp2XbJLbbqFpGyH2DA45lwssNOf53Znf0=; b=pr7zWFoPihJga3FCCcEe/VAAmsADVmpaBdIxiXf6MdhBH8XXIXa20kfW6ObwlDt+mVf5 qAUorE/0Mgk65fLmiW+Xz7Fpfa1xrIU+sSIcrWrqqsBP/otWqNpfLDJ/NTkdPa1zYMKC ooq4uSy2BTJrpIhnS9c/PVcMIf0aZUEi2r2X/vgTMBXu+sKpVL7B4TNNYRYtdy3RwFbu xofnpsyt/d6bFavIUHun8iaRROa5c8rMIYIGjpkiqQ9wbZFVHYHzp73+7tO5Qt+vMZTt D/eM5Y/ZL9cP3bGxnu17rOwxsPwz96tpMWQ7NAplQpNfWnGBgCp6E0UaxmXfD1WD6FEx Gw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3pxdtehfxa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Apr 2023 19:53:41 +0000 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 33DJrfRP008818 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Apr 2023 19:53:41 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.42; Thu, 13 Apr 2023 12:53:40 -0700 From: Wesley Cheng To: , CC: , , Wesley Cheng Subject: [PATCH v4 3/3] usb: dwc3: gadget: Refactor EP0 forced stall/restart into a separate API Date: Thu, 13 Apr 2023 12:53:17 -0700 Message-ID: <20230413195317.7468-4-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230413195317.7468-1-quic_wcheng@quicinc.com> References: <20230413195317.7468-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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-ORIG-GUID: k918EoJDH2M2yJQXHGlkY2GkwdZquI-S X-Proofpoint-GUID: k918EoJDH2M2yJQXHGlkY2GkwdZquI-S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-13_14,2023-04-13_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=918 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 bulkscore=0 malwarescore=0 mlxscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304130176 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,URIBL_BLOCKED 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?1763092825320072136?= X-GMAIL-MSGID: =?utf-8?q?1763092825320072136?= Several sequences utilize the same routine for forcing the control endpoint back into the SETUP phase. This is required, because those operations need to ensure that EP0 is back in the default state. Signed-off-by: Wesley Cheng --- drivers/usb/dwc3/gadget.c | 53 ++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 0bb4926933b6..9715de8e99bc 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -139,6 +139,24 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state) return -ETIMEDOUT; } +static void dwc3_ep0_reset_state(struct dwc3 *dwc) +{ + unsigned int dir; + + if (dwc->ep0state != EP0_SETUP_PHASE) { + dir = !!dwc->ep0_expect_in; + if (dwc->ep0state == EP0_DATA_PHASE) + dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); + else + dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); + + dwc->eps[0]->trb_enqueue = 0; + dwc->eps[1]->trb_enqueue = 0; + + dwc3_ep0_stall_and_restart(dwc); + } +} + /** * dwc3_ep_inc_trb - increment a trb index. * @index: Pointer to the TRB index to increment. @@ -2563,16 +2581,9 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) ret = wait_for_completion_timeout(&dwc->ep0_in_setup, msecs_to_jiffies(DWC3_PULL_UP_TIMEOUT)); if (ret == 0) { - unsigned int dir; - dev_warn(dwc->dev, "wait for SETUP phase timed out\n"); spin_lock_irqsave(&dwc->lock, flags); - dir = !!dwc->ep0_expect_in; - if (dwc->ep0state == EP0_DATA_PHASE) - dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); - else - dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); - dwc3_ep0_stall_and_restart(dwc); + dwc3_ep0_reset_state(dwc); spin_unlock_irqrestore(&dwc->lock, flags); } } @@ -3847,16 +3858,7 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) dwc->setup_packet_pending = false; usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); - if (dwc->ep0state != EP0_SETUP_PHASE) { - unsigned int dir; - - dir = !!dwc->ep0_expect_in; - if (dwc->ep0state == EP0_DATA_PHASE) - dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); - else - dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); - dwc3_ep0_stall_and_restart(dwc); - } + dwc3_ep0_reset_state(dwc); } static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) @@ -3910,20 +3912,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) * phase. So ensure that EP0 is in setup phase by issuing a stall * and restart if EP0 is not in setup phase. */ - if (dwc->ep0state != EP0_SETUP_PHASE) { - unsigned int dir; - - dir = !!dwc->ep0_expect_in; - if (dwc->ep0state == EP0_DATA_PHASE) - dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); - else - dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); - - dwc->eps[0]->trb_enqueue = 0; - dwc->eps[1]->trb_enqueue = 0; - - dwc3_ep0_stall_and_restart(dwc); - } + dwc3_ep0_reset_state(dwc); /* * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a