From patchwork Mon Apr 10 23:19:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 81672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2213177vqo; Mon, 10 Apr 2023 16:26:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YU5LAaE3jbjFbx4uZ23VN8IVH+GsiHhJs3nX/we2FuhoZngDLdoDK0B9QfxujGhW8Tb0rB X-Received: by 2002:a50:ed05:0:b0:504:9a52:ea52 with SMTP id j5-20020a50ed05000000b005049a52ea52mr6161613eds.35.1681169165297; Mon, 10 Apr 2023 16:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681169165; cv=none; d=google.com; s=arc-20160816; b=Pi9+Xq4ERVk+9dD7ZB61kNGfSyDnyLNM/r8VW4tl0R8IqWcckgS4QRt1pQGcDrhc/y chzZh+pcRR/qv496LPxls7zQErQ/AgoFPbj7X5XkqAyP139QH7hXgF+hPXHXFWXF42hl sbIoUBTQzj3kG/DQksH6wmlOfEVHpI5T0M/cZ/NkYYdRESADR1nUmjThDDTTYxUvqIqV o8oz40vro5h5T4YzwRAV8K81JYUMzKTL0lS0RSnru95HeKZ2IkyB4Ds7ZfYoK7w6pYcv 8r2DZN/EBcpcn63BNK5bk5fIdH+KIq+cmPXzEKSubvOeTpRB/8JiB2RoTtXx19cbx5bD dq5w== 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=f1b+1tX/53/H9yA0GV+5zd3AKuZiGEfcPCqLPKH8vUU=; b=mewXHhjgMyTBNcUCQYVfDl5iIS3U642jvK7NtmyrKmRjWQoYttcNGMaJr3yIQpso9S qUDy/TShEufGeAtLs8NSNfYuQFrlpybOAfVEZtgIxJ3uOAaH7nJex6mK++IHkihrM+m9 W8KAysf5ds2U5/QI3PX+xg5MSo0EztCN5K7nKAfG2qXaBOC7tS2Ian8TdEpGtSve7VMt Ln5F1W3K76euWiM87TXL8JFImBhDlmQkyVWHUdQe8Cit+VI7Pyx889+8yA/90rdan0yU j/rJnIXGzdUIwR1bwMZ2SH6EtCYCXmMF+qulWfLWgzZNmMgFnEFFWfDh3yVv6UR0Tb79 6meQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SXw0TJw2; 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 h17-20020aa7de11000000b005048c65e064si6504854edv.452.2023.04.10.16.25.41; Mon, 10 Apr 2023 16:26:05 -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=SXw0TJw2; 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 S229977AbjDJXUY (ORCPT + 99 others); Mon, 10 Apr 2023 19:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbjDJXUP (ORCPT ); Mon, 10 Apr 2023 19:20:15 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F132698; Mon, 10 Apr 2023 16:20:14 -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 33ANJTol011253; Mon, 10 Apr 2023 23:20:06 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=f1b+1tX/53/H9yA0GV+5zd3AKuZiGEfcPCqLPKH8vUU=; b=SXw0TJw2zMCbXNH0FzBmGwVc221qO7t7NYSNFIrOWBroEcvZkUlV4szwjHrYSIEDFNAb 7aavv3tlCCrmrD/kWJ8wXVbxOKBL98+MB24Q9r/ttF9shQpzDEhxFjE9UXW49xNQjBpQ 1Zdyc24wCvv2nUUXqFiPoemQED9WPPWSufajgeF4BQhkmTiZvcyJx85DXE3HoepsdzT1 egJdj1/WP5G6U1X4Bz5eOhJ7DYqGq8Jkxe0++8maco8vD8DKuQ9TTGfPXGgq16ZxSb1j z3hsLhVTQ6TmK6T7Uc/jjPtvMiDqqMq47S3lHLLYSfH7RfXWuPWycfPnaBzounABbNxC VQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3pvgmesf8b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Apr 2023 23:20:06 +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 33ANK6e5029460 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Apr 2023 23:20:06 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; Mon, 10 Apr 2023 16:20:05 -0700 From: Wesley Cheng To: , CC: , , , , Wesley Cheng Subject: [PATCH v3 1/3] usb: dwc3: gadget: Refactor EP0 forced stall/restart into a separate API Date: Mon, 10 Apr 2023 16:19:52 -0700 Message-ID: <20230410231954.437-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230410231954.437-1-quic_wcheng@quicinc.com> References: <20230410231954.437-1-quic_wcheng@quicinc.com> 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: EoaxhN6av2paU6HFxRuoZ9b_k0S9HHQK X-Proofpoint-ORIG-GUID: EoaxhN6av2paU6HFxRuoZ9b_k0S9HHQK 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-10_16,2023-04-06_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 phishscore=0 priorityscore=1501 mlxlogscore=905 impostorscore=0 adultscore=0 mlxscore=0 malwarescore=0 clxscore=1015 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304100205 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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 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?1762833638159701956?= X-GMAIL-MSGID: =?utf-8?q?1762833638159701956?= 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 Acked-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 44 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 3c63fa97a680..320e30476c88 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. @@ -3821,16 +3839,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) @@ -3884,20 +3893,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