Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp332822pxb; Fri, 16 Apr 2021 06:53:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6vBnuvJckVRkGcIcp4l7Xm31BzfhbRz4cZYW1cK15kGtvrimx2UkfLcf7TE8rxk7isOAk X-Received: by 2002:a17:907:270f:: with SMTP id w15mr8485928ejk.462.1618581215258; Fri, 16 Apr 2021 06:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618581215; cv=none; d=google.com; s=arc-20160816; b=BiwjmfA1QVOox8bwyMLAH+izawVdWOBUHvKnXVrSSX3S3ECjOh1hyX/pLvbkLSc6hA 8xOstiqoJA2cMjoTvwMjX8JYuoiSD4IBn2dydgDQnrDIPCchCEaFEPUY96DgiKpwjp0o N8jPSgVOzofBacnMxqgKPOk98kW8T5a2XwkKLHFLVvJAbki5Lfzbbe+cR9xClebmSnjo mMwcH1cURV+J7bPVOf3X1cyJFow5+EuQ59wT4yGerlsytRIU/skhnYBrgstXA3FfzGoT 2kbFNt9cweewlOGdeokxIZBE6sxVX7W6ynNW3wjENzMg2j8vNKoZKiFAExxxQuIya0ZP isRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:cc:to:subject:from:references :in-reply-to:date:dkim-signature; bh=F85UXBRuH70k/Qed/Ti0FZMPNHSf01DoxMKjn85/NHs=; b=foq6nZgF3i4ca2Bq1b8temEYZwyy7hjizwY2Rv31QN4S3lAvKtIUwzjVOlhifos2+B dAsC/7+fl5TN6mbDQnnY0kPX2JDpsTrdGWGbHstkTQTi+wZhfKiJWpd/YQeJsoBiIevt a2qgM624NXck5GQ3r3oRaHxZUzQSFdXe5AblZfReJac3n2O9H54NGUveJpLBfD15saz5 hjXb18qQ3js3CzkSMF/68lXfbndKxej8RRoeeWErtIgjflsBPsrMsD8T6C1XOxJXkn+x Ke8+UtbrlesVjW7r8131iblA/dLUIQ3s8AzfHM2q006JTXQUqS2ZF3TVfp5XXMiEEvjk rECg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=kgK7BEaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz18si4399966edb.100.2021.04.16.06.53.12; Fri, 16 Apr 2021 06:53:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=kgK7BEaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243677AbhDPMsF (ORCPT + 99 others); Fri, 16 Apr 2021 08:48:05 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:42246 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243675AbhDPMr7 (ORCPT ); Fri, 16 Apr 2021 08:47:59 -0400 Received: from mailhost.synopsys.com (mdc-mailhost2.synopsys.com [10.225.0.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id C36CFC06B9; Fri, 16 Apr 2021 12:47:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1618577255; bh=uQ2IGh1zNa806XuJ0Ij3ORBvTUnpJ5SKdAn2kXmH6mU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=kgK7BEaXBp2gDp3IT4Ri6qh/FjFoBUlfbGKpnZQxW2WB1AvsgykmlUX35spLprqht hmNpa9KUiAWNJecTNjObMd5JFIpAhhieAj3YOpVESlK3TbQsx3rhjFvMgGXKT9tZL0 WZfzCIYGm/OjHpjhhP79wd+akFAChsOrFUOTJ6ZoBy62F02EysTwtNMgsjhR6i7Jh6 ecCIz5sA3+n+x5WZXCe9orlYGEHUk3r+f9jcJuM4dhVUHYPgb82wt+7urfJPIS5d2L yog5MZrmldXGeSmPxDAVZmPC0jsSJtpyHazL00VAbIyO6SeiQnptKNPKulY1Uscvxf UjjDB4e+LvmJQ== Received: from razpc-HP (razpc-hp.internal.synopsys.com [10.116.126.207]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id C500AA005D; Fri, 16 Apr 2021 12:47:31 +0000 (UTC) Received: by razpc-HP (sSMTP sendmail emulation); Fri, 16 Apr 2021 16:47:30 +0400 Date: Fri, 16 Apr 2021 16:47:30 +0400 In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Artur Petrosyan Subject: [PATCH v2 06/15] usb: dwc2: Clear fifo_map when resetting core. To: Felipe Balbi , Greg Kroah-Hartman , Minas Harutyunyan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: John Youn , Artur Petrosyan , Minas Harutyunyan Message-Id: <20210416124731.C500AA005D@mailhost.synopsys.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switching from device mode to host mode by disconnecting device cable core enters and exits form hibernation. However, the fifo map remains not cleared. It results to a WARNING (WARNING: CPU: 5 PID: 0 at drivers/usb/dwc2/ gadget.c:307 dwc2_hsotg_init_fifo+0x12/0x152 [dwc2]) if in host mode we disconnect the micro a to b host cable. Because core reset occurs. To avoid the WARNING, fifo_map should be cleared in dwc2_core_reset() function by taking into account configs. fifo_map must be cleared only if driver is configured in "CONFIG_USB_DWC2_PERIPHERAL" or "CONFIG_USB_DWC2_DUAL_ROLE" mode. - Added "static inline void dwc2_clear_fifo_map()" helper function to clear fifo_map with peripheral or dual role mode. - Added a dummy version of "dwc2_clear_fifo_map()" helper for host-only mode. Signed-off-by: Artur Petrosyan Acked-by: Minas Harutyunyan --- drivers/usb/dwc2/core.c | 16 ++++++++++++++++ drivers/usb/dwc2/core.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index cb65f7f60573..eccd96fa164e 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -470,6 +470,22 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool skip_wait) dwc2_writel(hsotg, greset, GRSTCTL); } + /* + * Switching from device mode to host mode by disconnecting + * device cable core enters and exits form hibernation. + * However, the fifo map remains not cleared. It results + * to a WARNING (WARNING: CPU: 5 PID: 0 at drivers/usb/dwc2/ + * gadget.c:307 dwc2_hsotg_init_fifo+0x12/0x152 [dwc2]) + * if in host mode we disconnect the micro a to b host + * cable. Because core reset occurs. + * To avoid the WARNING, fifo_map should be cleared + * in dwc2_core_reset() function by taking into account configs. + * fifo_map must be cleared only if driver is configured in + * "CONFIG_USB_DWC2_PERIPHERAL" or "CONFIG_USB_DWC2_DUAL_ROLE" + * mode. + */ + dwc2_clear_fifo_map(hsotg); + /* Wait for AHB master IDLE state */ if (dwc2_hsotg_wait_bit_set(hsotg, GRSTCTL, GRSTCTL_AHBIDLE, 10000)) { dev_warn(hsotg->dev, "%s: HANG! AHB Idle timeout GRSTCTL GRSTCTL_AHBIDLE\n", diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 8c12b3061f7f..e1f432095565 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -1423,6 +1423,8 @@ int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg); int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg); void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg); void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg); +static inline void dwc2_clear_fifo_map(struct dwc2_hsotg *hsotg) +{ hsotg->fifo_map = 0; } #else static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2) { return 0; } @@ -1467,6 +1469,7 @@ static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg) { return 0; } static inline void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) {} static inline void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg) {} +static inline void dwc2_clear_fifo_map(struct dwc2_hsotg *hsotg) {} #endif #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) -- 2.25.1