From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89656C433B4 for ; Fri, 16 Apr 2021 21:17:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60118613CF for ; Fri, 16 Apr 2021 21:17:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236046AbhDPVRh (ORCPT ); Fri, 16 Apr 2021 17:17:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235807AbhDPVRg (ORCPT ); Fri, 16 Apr 2021 17:17:36 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32C08C061574; Fri, 16 Apr 2021 14:17:10 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id sd23so35411144ejb.12; Fri, 16 Apr 2021 14:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=tgAlkeYe9S3kJtH/aeUf7aQuoGVLf0jhMMrqc8LYA4Q=; b=sxzGAkxRPSQyxMsX2UTfYGPUq+kKJi0lBLyUF7efGyvUQGqsGGCllLU3dMYZ/Lnmo+ /nhZjuL7yyr9Y0s316LqCbZHrSnixWfW7y0hcFHpWXhsExR75niADVLjwv/UqN9fg7x4 sMhs7yTQSwuaLfPMZN9uJ+kPImdBfSBQ2Czf19QC1UM3uHvHYlHweQwvN5rVr+m1qEqt A3FM3EFGlTFrrjsN9LsalmbIvGUq7ZEsgJRl898T942rsyf05AfU7TNmVo6gEOCNr67u WObnRPGWtQWs0pt1HlRKdlgUBkTR2i6LB2mHnjdGbg64UGlEno1lb/0w9h5dNyplst5D 05fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=tgAlkeYe9S3kJtH/aeUf7aQuoGVLf0jhMMrqc8LYA4Q=; b=LXuhehjfyBPUXhWiwfpcg5tUb7TCTDs1df9RiHyXuS7Fovli5lZgg0tKWUq342FKCj a55sivZq4B9i91G7kYv/HX4u7UsEdMnwoLCrc1e5ZrkWcr1F4X7Kf/61R8FfsWyC5SWJ 63o4cr94y4XTCiBCP8VP2RopMo/YfBwDAcvl/CJxSAYeeLuDkqQ3+f2ktU7GVeh8En/U OrRzcH3xImvuIop076IYwbTRwFNYc4cKEbRi3KL4uUZpXi/85KoXgleRHIa1oj9e92v7 cD+doDj+1Kekk1y8b2W3cZd0YMe/iovJoRVltuwr5+gsIvEBlJhRXTDw/KslpuMOMThf OuCw== X-Gm-Message-State: AOAM5332oVE0+lfnvKeeUQCHZ2JWHm2NFYdKibeNQjN63SgI0Ru2tRgC TFNYQowf2XaUXoFeTmtINuSIwZaX8lEhvg== X-Google-Smtp-Source: ABdhPJwhyINxQp1T8zAa9d65tJGcgJNCLjaBMMTJyB/rZMIm2zPhbQ0nLxWTtRYHMRXUu0q9MGeCyQ== X-Received: by 2002:a17:906:4746:: with SMTP id j6mr10413056ejs.39.1618607828964; Fri, 16 Apr 2021 14:17:08 -0700 (PDT) Received: from ?IPv6:2001:981:6fec:1:2df7:4096:cb95:c5e4? ([2001:981:6fec:1:2df7:4096:cb95:c5e4]) by smtp.gmail.com with ESMTPSA id hc43sm5169884ejc.97.2021.04.16.14.17.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Apr 2021 14:17:08 -0700 (PDT) Subject: Re: [PATCH v3] usb: dwc3: core: Do core softreset when switch mode To: Thinh Nguyen , John Stultz Cc: John Youn , "stable@vger.kernel.org" , Andy Shevchenko , Wesley Cheng , Yu Chen , Felipe Balbi , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" References: <2cb4e704b059a8cc91f37081c8ceb95c6492e416.1618503587.git.Thinh.Nguyen@synopsys.com> <374440f8dcd4f06c02c2caf4b1efde86774e02d9.1618521663.git.Thinh.Nguyen@synopsys.com> From: Ferry Toth Message-ID: <0882cfae-4708-a67a-f112-c1eb0c7e6f51@gmail.com> Date: Fri, 16 Apr 2021 23:17:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Hi Op 16-04-2021 om 00:23 schreef Thinh Nguyen: > Thinh Nguyen wrote: >> From: Yu Chen >> From: John Stultz >> >> According to the programming guide, to switch mode for DRD controller, >> the driver needs to do the following. >> >> To switch from device to host: >> 1. Reset controller with GCTL.CoreSoftReset >> 2. Set GCTL.PrtCapDir(host mode) >> 3. Reset the host with USBCMD.HCRESET >> 4. Then follow up with the initializing host registers sequence >> >> To switch from host to device: >> 1. Reset controller with GCTL.CoreSoftReset >> 2. Set GCTL.PrtCapDir(device mode) >> 3. Reset the device with DCTL.CSftRst >> 4. Then follow up with the initializing registers sequence >> >> Currently we're missing step 1) to do GCTL.CoreSoftReset and step 3) of >> switching from host to device. John Stult reported a lockup issue seen >> with HiKey960 platform without these steps[1]. Similar issue is observed >> with Ferry's testing platform[2]. >> >> So, apply the required steps along with some fixes to Yu Chen's and John >> Stultz's version. The main fixes to their versions are the missing wait >> for clocks synchronization before clearing GCTL.CoreSoftReset and only >> apply DCTL.CSftRst when switching from host to device. >> >> [1] https://urldefense.com/v3/__https://lore.kernel.org/linux-usb/20210108015115.27920-1-john.stultz@linaro.org/__;!!A4F2R9G_pg!PW9Jbs4wv4a_zKGgZHN0FYrIpfecPX0Ouq9V3d16Yz-9-GSHqZWsfBAF-WkeqLhzN4i3$ >> [2] https://urldefense.com/v3/__https://lore.kernel.org/linux-usb/0ba7a6ba-e6a7-9cd4-0695-64fc927e01f1@gmail.com/__;!!A4F2R9G_pg!PW9Jbs4wv4a_zKGgZHN0FYrIpfecPX0Ouq9V3d16Yz-9-GSHqZWsfBAF-WkeqGeZStt4$ >> >> Cc: Andy Shevchenko >> Cc: Ferry Toth >> Cc: Wesley Cheng >> Cc: >> Fixes: 41ce1456e1db ("usb: dwc3: core: make dwc3_set_mode() work properly") >> Signed-off-by: Yu Chen >> Signed-off-by: John Stultz >> Signed-off-by: Thinh Nguyen >> --- >> Changes in v3: >> - Check if the desired mode is OTG, then keep the old flow >> - Remove condition for OTG support only since the device can still be >> configured DRD host/device mode only >> - Remove redundant hw_mode check since __dwc3_set_mode() only applies when >> hw_mode is DRD >> Changes in v2: >> - Initialize mutex per device and not as global mutex. >> - Add additional checks for DRD only mode >> >> drivers/usb/dwc3/core.c | 27 +++++++++++++++++++++++++++ >> drivers/usb/dwc3/core.h | 5 +++++ >> 2 files changed, 32 insertions(+) >> > Hi John, > > If possible, can you run a test with this version on your platform? > > Thanks, > Thinh > I tested this on edison-arduino with this patch on top of usb-next (5.12-rc7 + "increase BESL baseline to 6" to prevent throttling"). On this platform there is a physical switch to switch roles. With this patch I find: - switch to host mode always works fine - switch to gadget mode I need to flip the switch 3x (gadget-host-gadget). An error message appears on the gadget side "dwc3 dwc3.0.auto: timed out waiting for SETUP phase" appears, but then the device connects to my PC, no throttling. - alternatively I can switch to gadget 1x and then unplug/replug the cable. No error message and connects fine. - if I flip the switch only once, on the PC side I get: kernel: usb 1-5: new high-speed USB device number 18 using xhci_hcd kernel: usb 1-5: New USB device found, idVendor=1d6b, idProduct=0104, bcdDevice= 1.00 kernel: usb 1-5: New USB device strings: Mfr=1, Product=2, SerialNumber=3 kernel: usb 1-5: Product: USBArmory Gadget kernel: usb 1-5: Manufacturer: USBArmory kernel: usb 1-5: SerialNumber: 0123456789abcdef kernel: usb 1-5: can't set config #1, error -110 Then if I wait long enough on the gadget side I get: root@yuna:~# ifconfig usb0: flags=-28605 mtu 1500 inet 169.254.119.239 netmask 255.255.0.0 broadcast 169.254.255.255 inet6 fe80::a8bb:ccff:fedd:eef1 prefixlen 64 scopeid 0x20 ether aa:bb:cc:dd:ee:f1 txqueuelen 1000 (Ethernet) RX packets 490424 bytes 735146578 (701.0 MiB) RX errors 0 dropped 191 overruns 0 frame 0 TX packets 35279 bytes 2532746 (2.4 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 (correct would be: inet 10.42.0.221 netmask 255.255.255.0 broadcast 10.42.0.255) So much improved now, but it seems I am still missing something on plug.