Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp762253rwb; Mon, 26 Sep 2022 05:39:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM68y9wXsM1hax4ntkV8ouxx1vI45ccJ3sYhmr0+tnwh7L88BgYahBFq4f86OVjyCSzKkcjj X-Received: by 2002:a17:902:b616:b0:178:2321:8dbb with SMTP id b22-20020a170902b61600b0017823218dbbmr22732839pls.47.1664195961852; Mon, 26 Sep 2022 05:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664195961; cv=none; d=google.com; s=arc-20160816; b=N44x1QZy+LPcx/A+9u7SAV8mti3N/1ID3gUOLyd0+Yo5TNtnJbN/5HZf/jGhYWgdJm +uqK/sDLy0qUJHxaaYSLfBGBmn7N8f/7NgG5R5/zEH7rHwW0Kpq60pMVrp2urU4j0dcI rtWjNKw8iHtDwqp3eqqKz41Xd7HS5RYoreXg0Tr5e+oJojAeTVDjBuaSpgXXhy1kLRHX PCf/xAwX52N9W6vP8XU84YXaBU86Fz6r4l3BoIujKbZQ2WRctN5y1R065RdK0D7xeSst bFTyreH8T0icgsIhZvgVZPXsWI9TF0Pon4iPWglfCG+2hiozLWIA08MZ8W9k8Ca8i9Ge xChw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6qN0+JwSpZl294NDYGZGaT+Rfnqf5mwuQ4DCOnCJdyU=; b=arGRR+cYAuwyaONOccykTpkxxH2xEjL+dBI7Eb0LgVug7zplTdNv6FgDPFuq0cilIb oMEPG0xbzKNz/tkXl1OQABuhayCCc4S0LKRk81rYWJtX4QTOX69qfSnidcehN1D1/+b4 365EiYg+ZPyDe/6cNRRnnEt8vhP9LYjdYhPxkHWx9TBPkPWMBMk0dbPlMA6d9zqmOmPg v72cAsBNOVB0wSxqO3diH7gOMAz9iH5Ae6wgyd9ywLnRl7DhEC9cE90wK+O/YD7enqYb 2Q3PTAdfQChzy/8ZFhwB/fT/3cPhIYs9lrZFsxxcO7OhkBZ8c+d6MRtr1NmMwFIrGyG8 XcPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=saTwwQoB; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 5-20020a630f45000000b00439dcdd3cfdsi17690969pgp.825.2022.09.26.05.39.10; Mon, 26 Sep 2022 05:39:21 -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=@linuxfoundation.org header.s=korg header.b=saTwwQoB; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237468AbiIZLOt (ORCPT + 99 others); Mon, 26 Sep 2022 07:14:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234739AbiIZLN1 (ORCPT ); Mon, 26 Sep 2022 07:13:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 095E961B16; Mon, 26 Sep 2022 03:35:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04DED60A36; Mon, 26 Sep 2022 10:34:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1648BC433C1; Mon, 26 Sep 2022 10:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188479; bh=J+i3uIyUow+pCvGzmYuES05Gg1KKRPPsHx6A5185svk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=saTwwQoBCRhigDXuWQt8ibvEdwOgRcng/TRZANHZuMYI9fdqu1e8mZGbppHEEYZlp zC+t59263c2xBzAX+tclra1j1YWVyI8kw32xTTiAUSmhJMweTsNtjmMHbzaJTLmCrk dq/Uf09jFsR+qzOZnqHM/8WpWHR2+Vp5Cmna5Rqg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen , Sasha Levin Subject: [PATCH 5.15 009/148] usb: dwc3: gadget: Dont modify GEVNTCOUNT in pullup() Date: Mon, 26 Sep 2022 12:10:43 +0200 Message-Id: <20220926100756.389392498@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Thinh Nguyen [ Upstream commit 8f8034f493b5eb1ad21ff392fd30c0cf9e71f73f ] If the GEVNTCOUNT indicates events in the event buffer, the driver needs to acknowledge them before the controller can halt. Simply let the interrupt handler acknowledges the remaining event generated by the controller while polling for DSTS.DEVCTLHLT. This avoids disabling irq and taking care of race condition between the interrupt handlers and pullup(). Signed-off-by: Thinh Nguyen Link: https://lore.kernel.org/r/ea306ec93c41ccafbdb5d16404ff3b6eca299613.1650593829.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman Stable-dep-of: 040f2dbd2010 ("usb: dwc3: gadget: Avoid duplicate requests to enable Run/Stop") Signed-off-by: Sasha Levin --- drivers/usb/dwc3/gadget.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index cdc03ee439f8..484b5e1d921a 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2437,8 +2437,9 @@ static int __dwc3_gadget_start(struct dwc3 *dwc); static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) { - u32 count; + unsigned long flags; + spin_lock_irqsave(&dwc->lock, flags); dwc->connected = false; /* @@ -2450,29 +2451,21 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) */ dwc3_stop_active_transfers(dwc); __dwc3_gadget_stop(dwc); + spin_unlock_irqrestore(&dwc->lock, flags); /* - * In the Synopsys DesignWare Cores USB3 Databook Rev. 3.30a - * Section 1.3.4, it mentions that for the DEVCTRLHLT bit, the - * "software needs to acknowledge the events that are generated - * (by writing to GEVNTCOUNTn) while it is waiting for this bit - * to be set to '1'." + * Note: if the GEVNTCOUNT indicates events in the event buffer, the + * driver needs to acknowledge them before the controller can halt. + * Simply let the interrupt handler acknowledges and handle the + * remaining event generated by the controller while polling for + * DSTS.DEVCTLHLT. */ - count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); - count &= DWC3_GEVNTCOUNT_MASK; - if (count > 0) { - dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); - dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) % - dwc->ev_buf->length; - } - return dwc3_gadget_run_stop(dwc, false, false); } static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) { struct dwc3 *dwc = gadget_to_dwc(g); - unsigned long flags; int ret; is_on = !!is_on; @@ -2516,14 +2509,6 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) return 0; } - /* - * Synchronize and disable any further event handling while controller - * is being enabled/disabled. - */ - disable_irq(dwc->irq_gadget); - - spin_lock_irqsave(&dwc->lock, flags); - if (!is_on) { ret = dwc3_gadget_soft_disconnect(dwc); } else { @@ -2533,16 +2518,12 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) * device-initiated disconnect requires a core soft reset * (DCTL.CSftRst) before enabling the run/stop bit. */ - spin_unlock_irqrestore(&dwc->lock, flags); dwc3_core_soft_reset(dwc); - spin_lock_irqsave(&dwc->lock, flags); dwc3_event_buffers_setup(dwc); __dwc3_gadget_start(dwc); ret = dwc3_gadget_run_stop(dwc, true, false); } - spin_unlock_irqrestore(&dwc->lock, flags); - enable_irq(dwc->irq_gadget); pm_runtime_put(dwc->dev); -- 2.35.1