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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no 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 B9D4DC48BE5 for ; Wed, 23 Jun 2021 13:59:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D8BA6024A for ; Wed, 23 Jun 2021 13:59:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbhFWOBf (ORCPT ); Wed, 23 Jun 2021 10:01:35 -0400 Received: from netrider.rowland.org ([192.131.102.5]:45973 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S230274AbhFWOBe (ORCPT ); Wed, 23 Jun 2021 10:01:34 -0400 Received: (qmail 492480 invoked by uid 1000); 23 Jun 2021 09:59:15 -0400 Date: Wed, 23 Jun 2021 09:59:15 -0400 From: Alan Stern To: Claudiu.Beznea@microchip.com Cc: gregkh@linuxfoundation.org, Nicolas.Ferre@microchip.com, alexandre.belloni@bootlin.com, Ludovic.Desroches@microchip.com, Cristian.Birsan@microchip.com, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: host: ohci-at91: suspend/resume ports after/before OHCI accesses Message-ID: <20210623135915.GB491169@rowland.harvard.edu> References: <20210609121027.70951-1-claudiu.beznea@microchip.com> <20210609230735.GA1861855@rowland.harvard.edu> <0621eaba-db4d-a174-1b15-535e804b52ac@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0621eaba-db4d-a174-1b15-535e804b52ac@microchip.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 23, 2021 at 12:47:56PM +0000, Claudiu.Beznea@microchip.com wrote: > On 10.06.2021 02:07, Alan Stern wrote: > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe > > > > On Wed, Jun 09, 2021 at 03:10:27PM +0300, Claudiu Beznea wrote: > >> On SAMA7G5 suspending ports will cut the access to OHCI registers and > >> any subsequent access to them will lead to CPU being blocked trying to > >> access that memory. Same thing happens on resume: if OHCI memory is > >> accessed before resuming ports the CPU will block on that access. The > >> OCHI memory is accessed on suspend/resume though > >> ohci_suspend()/ohci_resume(). > > > > That sounds very strange. > > The clock scheme for OHCI and EHCI IPs on SAMA7G5 is as follows > (I hope it is readable): > > Main Xtal > | > +-------------+ > | | > +---------------------------+ \ / | > | +------+ | 60MHz +--------------------+ | > | | | | | |------+ > | | Port |<----------| UTMI Transceiver A | | | > | | | | | |----+ | > | USB 2.0 EHCI |Router| | +--------------------+ | | | > | Host Controller | | | 60MHz +--------------------+ | | | > | | |<----------| UTMI Transceiver B |<-+ | | > | | | | +--------------------+ | | | > | | | | 60MHz +--------------------+ | | | > | | |<----------| UTMI Transceiver C |<-+ | | > | | | | +--------------------+ | | > | +------+ | | | > | | | | > +---------------------------+ | | > | | > +---------------------------+ | | > | +------+ | UHP48M | | > | | Root | |<---------------------------------+ | > | USB 1.1 OHCI | hub | | | > | Host Controller | and | | UHP12M | > | | host | |<-----------------------------------+ > | | SIE | | > | +------+ | > | | > +---------------------------+ > > Where UTMI transceiver A generates the 48MHz and 12MHz clocks for OHCI > full-speed operations. > > The ports control is done through AT91_SFR_OHCIICR via > ohci_at91_port_suspend() function where. Setting 0 in AT91_SFR_OHCIICR > means suspend is controlled by EHCI-OHCI and 1 forces the port suspend. > Suspending the port A will cut the clocks for OHCI. I want to mention that > AT91_SFR_OHCIICR register is not in the same memory space of OHCI, EHCI IPs > and is clocked by other clocks. > > > Suppose one of the ports is suspended, so access to the > > OHCI registers is blocked. Then how can you resume the port? > > For run-time control (via ohci_at91_hub_control()), I agree with you that > the current implemented approach is not healthy (taking into account the > clock scheme above) and the fact that we do force the ports suspend on > ohci_at91_hub_control(). For suspend/resume it should be OK as the ports > are suspended at the end of any OHCI accesses (I don't know how the Linux > USB subsystem behaves so please do correct me if I'm wrong). (I haven't checked the details recently, so I'm not certain about this.) In some -- perhaps all -- cases, we don't suspend the ports at all during system suspend. We just rely on the USB devices automatically going into suspend when the root hub stops sending packets. > > Don't you have to > > access the OHCI registers in order to tell the controller to do the port resume? > > On our implementation we control the port suspend/resume via > AT91_SFR_OHCIICR, a special kind of register, memory mapped at different > address (compared w/ OHCI, EHCI IPs), so clocked by other clocks. > > > > > What happens when there's more than one port, and one of them is suspended while > > the other one is still running? How can you communicate with the active port if > > access to the OHCI registers is blocked? > > For this kind of scenario (the run-time suspend of a port, not system > suspend/resume) a different mechanism should be implemented taking into > account the clock schema presented above. Okay, I see. It seems like the driver will need some significant changes to handle runtime power management properly. One thing you might consider changing: The name of the ohci_at91_port_suspend routine is misleading. It doesn't really handle suspending the port; instead it handles the clocks that drive the entire OHCI controller. Right? Alan Stern 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=-5.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 1394EC48BC2 for ; Wed, 23 Jun 2021 14:01:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DAF026112D for ; Wed, 23 Jun 2021 14:01:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAF026112D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=rowland.harvard.edu Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0uOpjilvyer23f2QUUEk/OR8UHWxy+2780fUMvbAVkA=; b=3HSIK15soDNqik MdBAhb/qv2MbcfWk+VQYncgYMgv8OB19qZXtWAvJjwZGHhVoKcre3E5dbqPPjMJjA6MNdvwxY6qtb 4GdBDmddvceG1LRhtDxT9oWv4A5+h/prjZgN6S//lhmANnwY0Pi/JATjftWgUmqnS0QgmCsTxKCJD TtKdcdm6XGgld5eJj7CAxPhhnjuFf0AILXiju+2X8PSZJxmMkA5+iMnpUMg9nCtlyh5czjFJKdry+ +3PLXQxJUpZO3dqE+j25AnoD9ldKPCNe/dzzu2VJ+Mw7ACntUE6TpEHO/uBuc6eO5FyfF7FDzrxhR EAbtIPcTWsFvvNP3SvHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lw3PZ-00Au6c-9t; Wed, 23 Jun 2021 13:59:25 +0000 Received: from netrider.rowland.org ([192.131.102.5]) by bombadil.infradead.org with smtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lw3PU-00Au4m-CB for linux-arm-kernel@lists.infradead.org; Wed, 23 Jun 2021 13:59:22 +0000 Received: (qmail 492480 invoked by uid 1000); 23 Jun 2021 09:59:15 -0400 Date: Wed, 23 Jun 2021 09:59:15 -0400 From: Alan Stern To: Claudiu.Beznea@microchip.com Subject: Re: [PATCH] usb: host: ohci-at91: suspend/resume ports after/before OHCI accesses Message-ID: <20210623135915.GB491169@rowland.harvard.edu> References: <20210609121027.70951-1-claudiu.beznea@microchip.com> <20210609230735.GA1861855@rowland.harvard.edu> <0621eaba-db4d-a174-1b15-535e804b52ac@microchip.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0621eaba-db4d-a174-1b15-535e804b52ac@microchip.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210623_065920_611372_C4A5E80C X-CRM114-Status: GOOD ( 30.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexandre.belloni@bootlin.com, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Ludovic.Desroches@microchip.com, linux-arm-kernel@lists.infradead.org, Cristian.Birsan@microchip.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jun 23, 2021 at 12:47:56PM +0000, Claudiu.Beznea@microchip.com wrote: > On 10.06.2021 02:07, Alan Stern wrote: > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe > > > > On Wed, Jun 09, 2021 at 03:10:27PM +0300, Claudiu Beznea wrote: > >> On SAMA7G5 suspending ports will cut the access to OHCI registers and > >> any subsequent access to them will lead to CPU being blocked trying to > >> access that memory. Same thing happens on resume: if OHCI memory is > >> accessed before resuming ports the CPU will block on that access. The > >> OCHI memory is accessed on suspend/resume though > >> ohci_suspend()/ohci_resume(). > > > > That sounds very strange. > > The clock scheme for OHCI and EHCI IPs on SAMA7G5 is as follows > (I hope it is readable): > > Main Xtal > | > +-------------+ > | | > +---------------------------+ \ / | > | +------+ | 60MHz +--------------------+ | > | | | | | |------+ > | | Port |<----------| UTMI Transceiver A | | | > | | | | | |----+ | > | USB 2.0 EHCI |Router| | +--------------------+ | | | > | Host Controller | | | 60MHz +--------------------+ | | | > | | |<----------| UTMI Transceiver B |<-+ | | > | | | | +--------------------+ | | | > | | | | 60MHz +--------------------+ | | | > | | |<----------| UTMI Transceiver C |<-+ | | > | | | | +--------------------+ | | > | +------+ | | | > | | | | > +---------------------------+ | | > | | > +---------------------------+ | | > | +------+ | UHP48M | | > | | Root | |<---------------------------------+ | > | USB 1.1 OHCI | hub | | | > | Host Controller | and | | UHP12M | > | | host | |<-----------------------------------+ > | | SIE | | > | +------+ | > | | > +---------------------------+ > > Where UTMI transceiver A generates the 48MHz and 12MHz clocks for OHCI > full-speed operations. > > The ports control is done through AT91_SFR_OHCIICR via > ohci_at91_port_suspend() function where. Setting 0 in AT91_SFR_OHCIICR > means suspend is controlled by EHCI-OHCI and 1 forces the port suspend. > Suspending the port A will cut the clocks for OHCI. I want to mention that > AT91_SFR_OHCIICR register is not in the same memory space of OHCI, EHCI IPs > and is clocked by other clocks. > > > Suppose one of the ports is suspended, so access to the > > OHCI registers is blocked. Then how can you resume the port? > > For run-time control (via ohci_at91_hub_control()), I agree with you that > the current implemented approach is not healthy (taking into account the > clock scheme above) and the fact that we do force the ports suspend on > ohci_at91_hub_control(). For suspend/resume it should be OK as the ports > are suspended at the end of any OHCI accesses (I don't know how the Linux > USB subsystem behaves so please do correct me if I'm wrong). (I haven't checked the details recently, so I'm not certain about this.) In some -- perhaps all -- cases, we don't suspend the ports at all during system suspend. We just rely on the USB devices automatically going into suspend when the root hub stops sending packets. > > Don't you have to > > access the OHCI registers in order to tell the controller to do the port resume? > > On our implementation we control the port suspend/resume via > AT91_SFR_OHCIICR, a special kind of register, memory mapped at different > address (compared w/ OHCI, EHCI IPs), so clocked by other clocks. > > > > > What happens when there's more than one port, and one of them is suspended while > > the other one is still running? How can you communicate with the active port if > > access to the OHCI registers is blocked? > > For this kind of scenario (the run-time suspend of a port, not system > suspend/resume) a different mechanism should be implemented taking into > account the clock schema presented above. Okay, I see. It seems like the driver will need some significant changes to handle runtime power management properly. One thing you might consider changing: The name of the ohci_at91_port_suspend routine is misleading. It doesn't really handle suspending the port; instead it handles the clocks that drive the entire OHCI controller. Right? Alan Stern _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel