Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp18954pxb; Thu, 7 Jan 2021 17:54:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2s6yV0bJ90AMWOb1Ojk1GGu27/lXNriTRV3nXl1KibBsyCAoH89b7ULvX552H0VKZE2Wq X-Received: by 2002:a17:907:429d:: with SMTP id ny21mr1142308ejb.290.1610070892162; Thu, 07 Jan 2021 17:54:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610070892; cv=none; d=google.com; s=arc-20160816; b=MXY1RvKPvXLE/Z4HWdh0wZNjtl3zUDLPZhc77wQ1qSDUgSI2mIuvcW5lc6cxahShLz 45p8SjNvo2f3yJK9uYCyQtMrTOL0YKIHCROuwTu5qOUvo1PN7TSZy3FZFk7/as2/0IeG uphwI21tJ7fBc4o0TYBHct3fGgSRxYF5X+jln+XH6ik5RGBknJ11Hn8PT26SCXVTTKFN 6iV2LKBwj2U8zQj7x3+QCbzevLt8Oa207StTO2KbKarh2N63bmLCyOn0tPH9H9tsO9MM 0nTCZx8kmtnSQROluWujx8SvHEJlmTBR7B9AUjgyeh5VvuUMBirl3E9nXEo9xD72gU/Q pu7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=/9yRUK3ifPn4jWkGqxydFEM9X/uNu0aPyF+TlRNBzFw=; b=0XoJH6oNoo+YPsP4wigBF5DO7FHUiFbMpoIkHyPal2E+HVdhkO1+2TOVo7EvIQqbDJ CCgojarKAA4YaHxtQxWR+CiVD2by7Ni8aaapfkADRceLwNRQQXVKt0EcEMUiBuncI2HI 0VnXwrw7h43Cw0QUdZ/6rsyPZSlN2fCeuQgJdE/8IbdAQCY+uXZqnKZkJ+qQ16mBUmBp Harj5BsRJdZ8nFHHRdQ/1EB/+XDQyvvOxIditGa3FQyC7oU83yvPpy5TOLQHaiEJW7Rv BnVXLBfQGKnJ1l0fp7HSNBwZ8gP5HUJkISrSuAUO0i8Ix655tkUr2Qc6zeb6bN1++jXG DD1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qaEUGAlh; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si2955828ejc.573.2021.01.07.17.54.28; Thu, 07 Jan 2021 17:54:52 -0800 (PST) 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=@linaro.org header.s=google header.b=qaEUGAlh; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729794AbhAHBwD (ORCPT + 99 others); Thu, 7 Jan 2021 20:52:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729778AbhAHBwD (ORCPT ); Thu, 7 Jan 2021 20:52:03 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15C27C0612F5 for ; Thu, 7 Jan 2021 17:51:23 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id c12so5228566pfo.10 for ; Thu, 07 Jan 2021 17:51:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=/9yRUK3ifPn4jWkGqxydFEM9X/uNu0aPyF+TlRNBzFw=; b=qaEUGAlhSBJJz0k547jBxG2kJxrjPzoD7C87YteZVKHStDtMmN+mdXS7ljLfYPMX8D bSfj32/jzcvyHmod0BtAVPfUIQR7Jz5xH9mvv+Uizi9FK6+zV0hPsVt96gGUcmc4FtJZ /TQB7biXj6E5+tSYoP6WPTU/pAqBQSjUZob4Ciy2Jy6lqvV5fPH0DrlRVs0g5sX4ZcJS qS0XxVbe9MD2W35BDeRfnD3FiWiGGS65C4IOpt1HOhfxDWL+RE/ONCaxy0oXkSV6ce5G ThoJmGcKGaO4Ygo8wBftsDtjGcCi2RnUSxD6GTPHOcEa+LGu2V/mPoyK7Sfo7jvK/1hB IRFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/9yRUK3ifPn4jWkGqxydFEM9X/uNu0aPyF+TlRNBzFw=; b=VseW/tG5PtuChmk+mKsDejXwW9omjd1yQKEkz7hRPK8LhXEVYTxBLOg0R1jVNvURsI USJFRSY6JMTqZ7JiCdNhKtfKmCJT6ZLSnHltFS/IO6qZn60tO7GaODBLHzl+UI4wjmnX vNALGy/w3ezk5FaNb0hn2iqOGEVreIK6VfBJo7wSeVe693YiKmO54pvJu6KHEHbSZjws ZL9wPsgcfd57AF7PxH/7JX3Wzo3sOXghz7i5KaLoekHjnAkLmRQENyuhdlxUP2da1+vi cNvD2k8KFfOGbcc0opv/pLGIZ2wHeV7rmQIc1/PO11mcNwfwZr/PwNVkDqniBUDF65E/ P30A== X-Gm-Message-State: AOAM533gyUECmlBKMYsM3WGSBlP18Td87mj78e+qnYDDIoiaS6rq6CHc OUEnFN+OY4hD8FoduknHbFlvuJKXgJAj9Q== X-Received: by 2002:a62:5844:0:b029:1a8:b9dc:77bf with SMTP id m65-20020a6258440000b02901a8b9dc77bfmr1422210pfb.39.1610070682061; Thu, 07 Jan 2021 17:51:22 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id fw12sm6142756pjb.43.2021.01.07.17.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 17:51:20 -0800 (PST) From: John Stultz To: lkml Cc: Yu Chen , Felipe Balbi , Tejas Joglekar , Yang Fei , YongQin Liu , Andrzej Pietrasiewicz , Thinh Nguyen , Jun Li , Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-usb@vger.kernel.org, John Stultz Subject: [PATCH v3 1/2] usb: dwc3: Trigger a GCTL soft reset when switching modes in DRD Date: Fri, 8 Jan 2021 01:51:14 +0000 Message-Id: <20210108015115.27920-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu Chen Just resending this, as discussion died out a bit and I'm not sure how to make further progress. See here for debug data that was requested last time around: https://lore.kernel.org/lkml/CALAqxLXdnaUfJKx0aN9xWwtfWVjMWigPpy2aqsNj56yvnbU80g@mail.gmail.com/ With the current dwc3 code on the HiKey960 we often see the COREIDLE flag get stuck off in __dwc3_gadget_start(), which seems to prevent the reset irq and causes the USB gadget to fail to initialize. We had seen occasional initialization failures with older kernels but with recent 5.x era kernels it seemed to be becoming much more common, so I dug back through some older trees and realized I dropped this quirk from Yu Chen during upstreaming as I couldn't provide a proper rational for it and it didn't seem to be necessary. I now realize I was wrong. After resubmitting the quirk, Thinh Nguyen pointed out that it shouldn't be a quirk at all and it is actually mentioned in the programming guide that it should be done when switching modes in DRD. So, to avoid these !COREIDLE lockups seen on HiKey960, this patch issues GCTL soft reset when switching modes if the controller is in DRD mode. Cc: Felipe Balbi Cc: Tejas Joglekar Cc: Yang Fei Cc: YongQin Liu Cc: Andrzej Pietrasiewicz Cc: Thinh Nguyen Cc: Jun Li Cc: Mauro Carvalho Chehab Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Signed-off-by: Yu Chen Signed-off-by: John Stultz --- v2: * Rework to always call the GCTL soft reset in DRD mode, rather then using a quirk as suggested by Thinh Nguyen v3: * Move GCTL soft reset under the spinlock as suggested by Thinh Nguyen --- drivers/usb/dwc3/core.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 841daec70b6e..b6a6b90eb2d5 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -114,10 +114,24 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) dwc->current_dr_role = mode; } +static void dwc3_gctl_core_soft_reset(struct dwc3 *dwc) +{ + int reg; + + reg = dwc3_readl(dwc->regs, DWC3_GCTL); + reg |= (DWC3_GCTL_CORESOFTRESET); + dwc3_writel(dwc->regs, DWC3_GCTL, reg); + + reg = dwc3_readl(dwc->regs, DWC3_GCTL); + reg &= ~(DWC3_GCTL_CORESOFTRESET); + dwc3_writel(dwc->regs, DWC3_GCTL, reg); +} + static void __dwc3_set_mode(struct work_struct *work) { struct dwc3 *dwc = work_to_dwc(work); unsigned long flags; + int hw_mode; int ret; u32 reg; @@ -156,6 +170,11 @@ static void __dwc3_set_mode(struct work_struct *work) spin_lock_irqsave(&dwc->lock, flags); + /* Execute a GCTL Core Soft Reset when switch mode in DRD*/ + hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); + if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD) + dwc3_gctl_core_soft_reset(dwc); + dwc3_set_prtcap(dwc, dwc->desired_dr_role); spin_unlock_irqrestore(&dwc->lock, flags); -- 2.17.1