From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966312AbcCPNQD (ORCPT ); Wed, 16 Mar 2016 09:16:03 -0400 Received: from mga03.intel.com ([134.134.136.65]:30759 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965315AbcCPNQA (ORCPT ); Wed, 16 Mar 2016 09:16:00 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,344,1455004800"; d="asc'?scan'208";a="670565081" From: Felipe Balbi To: Roger Quadros Cc: nsekhar@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Roger Quadros Subject: Re: [PATCH 2/2] usb: dwc3: gadget: usb: dwc3: run/stop metastability workaround In-Reply-To: <1458133551-3071-3-git-send-email-rogerq@ti.com> References: <1458133551-3071-1-git-send-email-rogerq@ti.com> <1458133551-3071-3-git-send-email-rogerq@ti.com> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/25.0.90.3 (x86_64-pc-linux-gnu) Date: Wed, 16 Mar 2016 15:14:58 +0200 Message-ID: <87oaaeh8dp.fsf@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Roger Quadros writes: > [ text/plain ] > The existing workaround of forcing DEVSPD to SUPER_SPEED > for HIGH_SPEED ports is causing another side effect > which causes erratic interrupts and delayed gadget > enumeration of upto 2 seconds. > > Work around the run/stop issue by detecting if > it happened using debug LTSSM state and issuing > soft reset to the device controller when changing RUN_STOP > from 0 to 1. > > We apply the workaround only if PRTCAP is DEVICE mode > as we don't yet support this workaround in OTG mode. > > Use USB RESET event as exit condition for workaround. > > Signed-off-by: Roger Quadros > --- > drivers/usb/dwc3/core.h | 1 + > drivers/usb/dwc3/gadget.c | 175 +++++++++++++++++++++++++++++++++++++---= ------ > 2 files changed, 144 insertions(+), 32 deletions(-) > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index 2bea1ac..a724c0d 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -762,6 +762,7 @@ struct dwc3 { >=20=20 > struct usb_gadget gadget; > struct usb_gadget_driver *gadget_driver; > + struct completion reset_event; /* used for run/stop workaround */ the fact that you needed a struct completion here already points to the fact this is really, really bad :-) > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > index 3ac170f..03418b8 100644 > --- a/drivers/usb/dwc3/gadget.c > +++ b/drivers/usb/dwc3/gadget.c > @@ -35,6 +35,9 @@ > #include "gadget.h" > #include "io.h" >=20=20 > +static void dwc3_gadget_disable_irq(struct dwc3 *dwc); > +static int dwc3_gadget_restart(struct dwc3 *dwc); > + > /** > * dwc3_gadget_set_test_mode - Enables USB2 Test Modes > * @dwc: pointer to our context structure > @@ -1570,13 +1573,100 @@ static int dwc3_gadget_pullup(struct usb_gadget = *g, int is_on) > struct dwc3 *dwc =3D gadget_to_dwc(g); > unsigned long flags; > int ret; > + int trys =3D 0; >=20=20 > is_on =3D !!is_on; >=20=20 > + if (is_on) > + reinit_completion(&dwc->reset_event); > + > spin_lock_irqsave(&dwc->lock, flags); > ret =3D dwc3_gadget_run_stop(dwc, is_on, false); > spin_unlock_irqrestore(&dwc->lock, flags); >=20=20 > +try: > + /** > + * WORKAROUND: DWC3 revision < 2.20a have an issue > + * which would cause metastability state on Run/Stop > + * bit if we try to force the IP to USB2-only mode. > + * > + * Because of that, we check if we hit that issue and > + * reset core and retry if we did. > + * > + * We only attempt this workaround if we are in > + * DEVICE mode (i.e. not OTG). > + * > + * Refers to: > + * > + * STAR#9000525659: Clock Domain Crossing on DCTL in > + * USB 2.0 Mode > + */ > + if (is_on && dwc->revision < DWC3_REVISION_220A && > + dwc->prtcap_mode =3D=3D DWC3_GCTL_PRTCAP_DEVICE) { > + u32 devspd, ltssm; > + unsigned long t; > + > + /* only applicable if devspd !=3D SUPERSPEED */ > + devspd =3D dwc3_readl(dwc->regs, DWC3_DCFG) & DWC3_DCFG_SPEED_MASK; > + if (devspd =3D=3D DWC3_DCFG_SUPERSPEED) > + goto done; > + > + /* get link state */ > + ltssm =3D dwc3_readl(dwc->regs, DWC3_GDBGLTSSM); > + ltssm =3D (ltssm >> 22) & 0xf; > + > + /** > + * Need to wait for 100ms and check if ltssm !=3D 4 to detect > + * metastability issue. If we got a reset event then we are > + * safe and can continue. > + */ > + t =3D wait_for_completion_timeout(&dwc->reset_event, > + msecs_to_jiffies(100)); > + if (t) > + goto done; > + > + /** > + * If link state !=3D 4 we've hit the metastability issue, soft reset. > + */ > + if (ltssm =3D=3D 4) > + goto done; > + > + dwc3_trace(trace_dwc3_gadget, > + "applying metastability workaround\n"); > + trys++; > + if (trys =3D=3D 2) { > + dev_WARN_ONCE(dwc->dev, true, > + "metastability workaround failed!\n"); > + return -ETIMEDOUT; > + } > + > + spin_lock_irqsave(&dwc->lock, flags); > + /* stop gadget */ > + dwc3_gadget_disable_irq(dwc); > + __dwc3_gadget_ep_disable(dwc->eps[0]); > + __dwc3_gadget_ep_disable(dwc->eps[1]); > + > + /* soft reset device and restart */ > + ret =3D dwc3_device_reinit(dwc); > + if (ret) { > + dev_err(dwc->dev, "device reinit failed\n"); > + return ret; > + } > + > + reinit_completion(&dwc->reset_event); > + /* restart gadget */ > + ret =3D dwc3_gadget_restart(dwc); > + if (ret) { > + dev_err(dwc->dev, "failed to re-init gadget\n"); > + return ret; > + } > + > + spin_unlock_irqrestore(&dwc->lock, flags); > + goto try; > + } holy crap dude ?!? Now ->pullup() has to reinitialize dwc3 completely ?=20 =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJW6VxTAAoJEIaOsuA1yqREuN0QAKGQSy8hLyksOltzmXYFPaNm UIbmFaqLq6EYIotiH5UrMgcXIoq3ReSN+Rm6KUpy0U1nnAcDEvrz0zKQ84KwiNnQ iG1dng0+4FD6i4zTS15MqADvZ3cyOnMm/5HDTs2OTtJbJ4B58gj6CqgH/2tnxaKK ZapRv56J0j1Kkkqn5hMiHR50Bun05PELZ+jchReDZoLmEfNGQwR0ZTZ+fennSawJ bvoPGymxYDMgexU6juudJ220tKFw69CiiWgxog0A7NJ2TM297AEUgMzkcI74zz/7 aMsDCxJRdaUy0rllGN89BTP2ICztgg/Y7qZCKWYLX3XFF9iDRDO/Dxn56vO7vgGf aA7p569NNEvgCBDqOj64/XSEmOjAPh0U4figP74oQegHumHxQwLdQTJ+gbLDQW8j 8Wl9CtMxdTuThmesivUiLe22zZB7kq1QdkGNT58KdYFWSNYoVzqV4QUJkQvKiPiT uDz2A5TBs2rzw6AOvhhz3Uzac/HikK81jzUc0nxueGEs9aVpab9cT/oKnSHGKMTB 0zRwpuJ3Pu48LndwzAaHEZpMgHYlze65ZVo0+/SJCQRoUYS9yS9Y2k+SmkbgVBlu guqNbK5p0nWCyyxWXK6l/ptvay/pA/QeC1kopUNJdyhf/2HJ3u4WqLvdczs1uBv0 fQFFwJEIjysOzhQsQ7Px =MD7j -----END PGP SIGNATURE----- --=-=-=--