Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp196149imw; Tue, 12 Jul 2022 17:37:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vNVfOOsGMF50SndATw22PSB5s60n44TbwbPqNQ+s5eYhUiB8oVyJ/6QiTFyDnma9J2a69i X-Received: by 2002:a17:907:1c12:b0:72b:4a03:2290 with SMTP id nc18-20020a1709071c1200b0072b4a032290mr790123ejc.163.1657672658186; Tue, 12 Jul 2022 17:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657672658; cv=none; d=google.com; s=arc-20160816; b=hk/OXFQ9EEZXIpqIJhZlG2k/R4USjU35u7ZRIsnfqEQywiBkUpixxGXGjQZuFZseMd AINkioYrsLGbLJpisAsrj7XLDmxWMbptbkeTGWleADVb6hWeZa7QRF9K5XNaNZo7F4v7 jmiX6JhqhOsKRNINPfd3wipX/SY44rs7W9lqi9p/rR1rWev6LrlTmCQ4HiBcOf+XiZpX h3UIpo1bRQY5TPsK57pO+hZ2BQXs/T5RWyssVHrKuMMx70X2u6yA/DxjfVjyth9G+gFU 9fLW64Fi2opsu90wvHkSxk7VyuDIxB4HYHyzBBEZ+KA+d6wNS+t/SvetoDaFlCfLTCMe w6rQ== 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=kRQQcr5nf/l/o/aOOg0X2bOqskjPesWaQ3V0BgVyFiA=; b=zgG9e0XuG249iZm+orPMi/sd8Z3zwCxW3FvLFYGc0hf2KOihB11DExBklCGPqNmACq ype4tVCWGS4dX90ps8mWaggnACGgupFjlprVrHzcldvtyi/wkeFZhMBWe59otDVphjAP A99qMlNf7pm1/VSE2nQ3/QH8SB9AoxVCYnOmuIf18IvHZsi/a920YSH/S3Q8V2bODVv0 PP5Q3+MLJoFzY5xVEwhwY5FI95FC6WsZ/Bq5hizS8u8zSAN7pl/RiFn7Pwg5Ww/15viu MwNJp9tUAeB3Z4qGZslZ61ATD0Jl9leb5tcg6y/6xXuPd45se2cya/0ruhBn3nteYb8G 2akQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=y7Yx3wRp; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc36-20020a1709078a2400b0072b53e673bbsi11811248ejc.913.2022.07.12.17.37.13; Tue, 12 Jul 2022 17:37:38 -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=qcdkim header.b=y7Yx3wRp; 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 S230500AbiGMAf5 (ORCPT + 99 others); Tue, 12 Jul 2022 20:35:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbiGMAf4 (ORCPT ); Tue, 12 Jul 2022 20:35:56 -0400 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E58528D5C7; Tue, 12 Jul 2022 17:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1657672554; x=1689208554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=kRQQcr5nf/l/o/aOOg0X2bOqskjPesWaQ3V0BgVyFiA=; b=y7Yx3wRpE+9lyB8w39fO8CuzjL6pBze8KPDB5FN01RM4sXtWbtH6NLZp CqgJbtPjimLPhpyEREO3JzShC5foOWRrWONAbf20rpZi+Zrti0pjtFq2p X8LlbytyyDQP3c2Wy4Ck8bIk2GTFxOaHfHWZRski23WG8hD7RdBcls0sy k=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 12 Jul 2022 17:35:53 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2022 17:35:53 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 12 Jul 2022 17:35:36 -0700 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.22; Tue, 12 Jul 2022 17:35:36 -0700 From: Wesley Cheng To: , CC: , , , , Wesley Cheng Subject: [PATCH v2 1/5] usb: dwc3: Do not service EP0 and conndone events if soft disconnected Date: Tue, 12 Jul 2022 17:35:19 -0700 Message-ID: <20220713003523.29309-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220713003523.29309-1-quic_wcheng@quicinc.com> References: <20220713003523.29309-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 There are some operations that need to be ignored if there is a soft disconnect in progress. This is to avoid having a pending EP0 transfer in progress while attempting to stop active transfers and halting the controller. There were several instances seen where a soft disconnect was able to occur during early link negotiation, i.e. bus reset/conndone, which leads to the conndone handler re-configuring EPs while attempting to halt the controller, as DEP flags are cleared as part of the soft disconnect path. ep0out: cmd 'Start New Configuration' ep0out: cmd 'Set Endpoint Transfer Resource' ep0in: cmd 'Set Endpoint Transfer Resource' ep1out: cmd 'Set Endpoint Transfer Resource' ... event (00030601): Suspend [U3] event (00000101): Reset [U0] ep0out: req ffffff87e5c9e100 length 0/0 zsI ==> 0 event (00000201): Connection Done [U0] ep0out: cmd 'Start New Configuration' ep0out: cmd 'Set Endpoint Transfer Resource' In addition, if a soft disconnect occurs, EP0 events are still allowed to process, however, it will stall/restart during the SETUP phase. The host is still able to query for the DATA phase, leading to a xfernotready(DATA) event. Since none of the SETUP transfer parameters are populated, the xfernotready is treated as a "wrong direction" error, leading to a duplicate stall/restart routine. Add the proper softconnect/connected checks in sequences that are potentially involved during soft disconnect processing. Fixes: 861c010a2ee1 ("usb: dwc3: gadget: Refactor pullup()") Signed-off-by: Wesley Cheng --- drivers/usb/dwc3/ep0.c | 6 ++++-- drivers/usb/dwc3/gadget.c | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 2a510e84eef4..506ef717fdc0 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -197,7 +197,7 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, int ret; spin_lock_irqsave(&dwc->lock, flags); - if (!dep->endpoint.desc || !dwc->pullups_connected) { + if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { dev_err(dwc->dev, "%s: can't queue to disabled endpoint\n", dep->name); ret = -ESHUTDOWN; @@ -813,7 +813,7 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, int ret = -EINVAL; u32 len; - if (!dwc->gadget_driver || !dwc->connected) + if (!dwc->gadget_driver || !dwc->softconnect || !dwc->connected) goto out; trace_dwc3_ctrl_req(ctrl); @@ -1116,6 +1116,8 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc, { switch (event->status) { case DEPEVT_STATUS_CONTROL_DATA: + if (!dwc->softconnect || !dwc->connected) + return; /* * We already have a DATA transfer in the controller's cache, * if we receive a XferNotReady(DATA) we will ignore it, unless diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 4366c45c28cf..d1d7a5e5bd7c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3865,6 +3865,9 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) u8 lanes = 1; u8 speed; + if (!dwc->softconnect) + return; + reg = dwc3_readl(dwc->regs, DWC3_DSTS); speed = reg & DWC3_DSTS_CONNECTSPD; dwc->speed = speed;