Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5591288ybi; Tue, 28 May 2019 15:58:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5qxqza1VPQJm7L12WClyc7W/8u+A78zHDP7mryp/4pK8HkdyELjSFS/+i1i6vih+ABNE1 X-Received: by 2002:a17:902:8d94:: with SMTP id v20mr64430765plo.99.1559084337135; Tue, 28 May 2019 15:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559084337; cv=none; d=google.com; s=arc-20160816; b=AQIlgbWrSJwlMUFXWVwkOMA/pNKKKijLUiTaugBo9s4fG2Fi5AK42Efy83l/Rrvi2+ WOpGi3ltbOqafQ1ld/NR6rBWdPb7h7XrGM7Ne5AXvs4O1rlZXLNrCjVT5lFRaPrrIUBO nCWuIfhQlCzvBaVvNHGX2kXTnYbRSpnMJKdw7g1nf7FmjDm87TCd7FY9QBvNsAXWfNq3 uz/O0WblKsl1FdBOxzB7lCMBYXqF84Pr2L9M9efjcoteeqtTmUcefwrmTx2JxjbRY3vN X88p0BD2ol82+rHmAgTFv5G4nsHIocaGhGSd55dcqgITBshbsb1RitGzWszsQ8Ct/TAt 10dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=sHhWRG5GPF0tvidqRSCNkdcMvjw5zPCw4zzwfMQUnUU=; b=ZoMdYLQ7b1eLU8EWrdkHvu0SQXChOV6GnE+r5sF32UFFt64ssnLVk7fBeuPDl4/KJ+ NS2V2YfNzFjzIQWBdqh6ZCnY/kCmhw78/Ary4msT80ZACdYe8XuUvMUy+0S5aSrg5WLK PR94RkaFVE3N6DJPvTdE9rzZvv4mZ8M/Gzy+e5OzV4Afc2nuQR7baX3IGXxElZdTo4tj EnB2tPwtWRYh09neS6L85CJ6wkgSoWtyq8YX2PGUulEDRBBfYrGGhf9MCnu2uummkxFA m2cvbCZ311jF6b8Yb5I5hLisr8ezwGke6ZFktZr3mOPmavHinmfx4Z671t3UfGxsVuLe jDHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WoM+oqlx; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p7si12067063pgh.497.2019.05.28.15.58.25; Tue, 28 May 2019 15:58:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WoM+oqlx; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727379AbfE1Wtt (ORCPT + 99 others); Tue, 28 May 2019 18:49:49 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:32839 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbfE1Wtt (ORCPT ); Tue, 28 May 2019 18:49:49 -0400 Received: by mail-yb1-f195.google.com with SMTP id w127so66313yba.0 for ; Tue, 28 May 2019 15:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sHhWRG5GPF0tvidqRSCNkdcMvjw5zPCw4zzwfMQUnUU=; b=WoM+oqlxfd+/VhoBHQmtOJC1XA63Zq9dmvl9RPpg4ebmrvwPWRdjy26/FxfV8nC/7g fhsk0tLyYpKEc6YdYTMWKLurwe4UU1lZ/Fo+HFx8l14uD/UM/ThOMkRZWphu6EBBZy9+ XR3Wyup9ZfZw1cq9rhcV7HPH/MPFtYKRLg7VA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sHhWRG5GPF0tvidqRSCNkdcMvjw5zPCw4zzwfMQUnUU=; b=mNcWzqrAnjlmsMDX0of0WuSJWfAViUm7fs1KbKQphTaPfH1jX7oYTuQLoHJubpIVnt 7LSWDcarjOMpmTteA+Z/i7+BL86iOOybio5PXMEaOVCs6SUQ3nn+zZPEQZj/2f9pSttr vKEe3+5Nnx0zJq2xytwQrbWyQJ+kNbWkIHDOTyBdl+ccsj6TauZC/IeFCwb0sM09m/Ij F2uWV/p4TFe+WkEmoybuVPHUmc47sayNW3uNZPO14pd3nB0y57znj3xGLYTvZ9qtkyOn T6RKv6rc5JdHFN4Wu31Ae/4fsucyb7tv21Pf8EhABGDUVlUFRmiROCoJYyfeaSNl8vPF RZfg== X-Gm-Message-State: APjAAAUTjR0k5C9e5EGmGWAlCl94nfo93I4IQwef9l6X882ptjtXLBCJ r0DfG2PI33khSyUstJYWd+f44+jqdek= X-Received: by 2002:a25:bccc:: with SMTP id l12mr27520873ybm.380.1559083787678; Tue, 28 May 2019 15:49:47 -0700 (PDT) Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com. [209.85.219.173]) by smtp.gmail.com with ESMTPSA id f81sm4270552ywb.26.2019.05.28.15.49.45 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 28 May 2019 15:49:46 -0700 (PDT) Received: by mail-yb1-f173.google.com with SMTP id x187so41399ybc.11 for ; Tue, 28 May 2019 15:49:45 -0700 (PDT) X-Received: by 2002:a25:25c4:: with SMTP id l187mr19641708ybl.345.1559083785254; Tue, 28 May 2019 15:49:45 -0700 (PDT) MIME-Version: 1.0 References: <20190429204040.18725-1-dianders@chromium.org> In-Reply-To: From: Doug Anderson Date: Tue, 28 May 2019 15:49:28 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] mmc: dw_mmc: Disable SDIO interrupts while suspended to fix suspend/resume To: Ulf Hansson Cc: Jaehoon Chung , Shawn Lin , Kalle Valo , Heiko Stuebner , "open list:ARM/Rockchip SoC..." , Guenter Roeck , Brian Norris , linux-wireless , Sonny Rao , Emil Renner Berthing , Matthias Kaehlcke , Ryan Case , "# 4.0+" , "linux-mmc@vger.kernel.org" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Hi, On Tue, May 28, 2019 at 12:22 PM Ulf Hansson wrote: > > On Mon, 29 Apr 2019 at 22:41, Douglas Anderson wrote: > > > > Processing SDIO interrupts while dw_mmc is suspended (or partly > > suspended) seems like a bad idea. We really don't want to be > > processing them until we've gotten ourselves fully powered up. > > I fully agree. > > Although, this is important not only from the host driver/controller > perspective, but also from the SDIO card (managed by mmc core) point > of view. > > In $subject patch you mange the driver/controller issue, but only for > one specific host driver (dw_mmc). I am thinking that this problem may > be a rather common problem, so perhaps we should try to address this > from the core in a way that it affects all host drivers. Did you > consider that? I did wonder that. See below, but in general I don't have massive experience with all the host controllers out there. Looking at sdhci code, though, it might not have the same problems? At least in some cases it fully turns off the interrupts. In other cases it seems like the controller itself keeps power and so maybe getting the SDIO interrupts early is OK? > The other problem I refer to, is in principle a way to prevent > sdio_run_irqs() from being executed before the SDIO card has been > resumed, via mmc_sdio_resume(). It's a separate problem, but certainly > related. This may need some more thinking to address properly, let's > just keep this in mind and discuss this in a separate thread. Actually, I think if we could figure out how to do this well it might solve my particular problem. Specifically I don't believe that running dw_mmc's interrupt handler itself is causing the problem (though it does seem pretty odd to run it while we're in the middle of initting the host), I think it's the SDIO driver calling back into us that's causing the problems. > > You might be wondering how it's even possible to become suspended when > > an SDIO interrupt is active. As can be seen in > > dw_mci_enable_sdio_irq(), we explicitly keep dw_mmc out of runtime > > suspend when the SDIO interrupt is enabled. ...but even though we > > stop normal runtime suspend transitions when SDIO interrupts are > > enabled, the dw_mci_runtime_suspend() can still get called for a full > > system suspend. > > > > Let's handle all this by explicitly masking SDIO interrupts in the > > suspend call and unmasking them later in the resume call. To do this > > cleanly I'll keep track of whether the client requested that SDIO > > interrupts be enabled so that we can reliably restore them regardless > > of whether we're masking them for one reason or another. > > > > It should be noted that if dw_mci_enable_sdio_irq() is never called > > (for instance, if we don't have an SDIO card plugged in) that > > "client_sdio_enb" will always be false. In those cases this patch > > adds a tiny bit of overhead to suspend/resume (a spinlock and a > > read/write of INTMASK) but other than that is a no-op. The > > SDMMC_INT_SDIO bit should always be clear and clearing it again won't > > hurt. > > Thanks for the detailed problem description. In general your approach > sounds okay to me, but I have a few questions. > > 1) As kind of stated above, did you consider a solution where the core > simply disables the SDIO IRQ in case it isn't enabled for system > wakeup? In this way all host drivers would benefit. I can give it a shot if you can give me a bunch of specific advice, but I only have access to a few devices doing anything with SDIO and they are all using Marvell or Broadcom on dw_mmc. In general I have no idea how SDIO wakeup (plumbed through the SD controller) would work. As per below the only way I've seen it done is totally out-of-band. ...and actually, I'm not sure I've actually ever seen even the out of band stuff truly work on a system myself. It's always been one of those "we should support wake on WiFi" but never made it all the way to implementation. In any case, if there are examples of people plumbing wakeup through the SD controller I'd need to figure out how to not break them. Just doing a solution for dw_mmc means I don't have to worry about this since dw_mmc definitely doesn't support SDIO wakeup. Maybe one way to get a more generic solution is if you had an idea for a patch that would work for many host controllers then you could post it and I could test to confirm that it's happy on dw_mmc? ...similar to when you switched dw_mmc away from the old kthread-based SDIO stuff? > 2) dw_mmc isn't calling device_init_wakeup() during ->probe(), hence I > assume it doesn't support the SDIO IRQ being configured as system > wakeup. Correct? I understand this is platform specific, but still it > would be good to know your view. Right, currently dw_mmc doesn't support the SDIO IRQ being configured as a system wakeup. I'm kinda curious how this works in general. Don't you need a clock running to get an SDIO interrupt? How does that work for suspend? ...I do know that I've seen some dw_mmc host controllers have an "SDIO IRQ" line that could be pinned out and that line would also assert the same SDIO interrupt, but the mainline driver has never supported it. Whenever I asked Marvell about it in the past they were always confused about what to do with that line and (if I remember correctly) we never hooked it up. I always though it would be super interesting because it seemed like it would let us disable the card clock when the slot was idle. ...as far as I was ever able to discern the pin was officially "non-standard". As far as I know SDIO cards that want to be able to wakeup the device end up using some sort of out of band mechanism. For instance "marvell,wakeup-pin" or Broadcom's "host-wake" interrupt. As per above, I don't have tons of experience here. I see that "rk3399-gru-kevin" has "marvell,wakeup-pin" defined, but that's PCIe not SDIO. Downstream in our Chrome OS kernel it seems like "mt8173-oak.dtsi" and "mt8176-rowan.dtsi" have this for SDIO but they are are devices I didn't work on and don't have much familiarity with. > 3) Because of 2) The below code in dw_mci_runtime_suspend(), puzzles me: > "if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER)" > dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios); > > Why is 3) needed at all in case system wakeup isn't supported? That code has been in there for a really long time, dating back to commit ab269128a2cf ("mmc: dw_mmc: Add sdio power bindings"). ...but, in general, I know that we always keep power to the SDIO card in suspend time. This doesn't take a whole lot of power and speeds up WiFi acquisition after resume by a whole lot (because otherwise we'd have to fully re-load the WiFi firmware). In fact, I believe that the Marvell WiFi driver requires it. Ah yes, search for "MMC_PM_KEEP_POWER" in "marvell/mwifiex/sdio.c" and you'll see that it gets yells if power isn't kept. If we are keeping power during suspend/resume then presumably the card will expect that communication resumes as normal upon resume. AKA: the clock should come up at the expected rate / voltage level and we should resume as normal. > A note; the current support in the mmc core for the SDIO IRQ being > used as system wakeup, really needs some re-work. For example, we > should convert to use common wakeup interfaces, as to allow the PM > core to behave correctly during system suspend/resume. These are > changes that have been scheduled on my TODO list since long time ago, > I hope I can get some time to look into them soon. Personally my knowledge of SD / SDIO is mostly acquired by trying to make the dw_mmc driver do what we've needed it to over the years, so I don't actually have a ton of broad understanding of the SDIO spec and what is generally done for host controllers / SDIO cards. If you're aware of standard ways to get an SDIO IRQ to work in suspend time then that'd be interesting. > > Without this fix it can be seen that rk3288-veyron Chromebooks with > > Marvell WiFi would sometimes fail to resume WiFi even after picking my > > recent mwifiex patch [1]. Specifically you'd see messages like this: > > mwifiex_sdio mmc1:0001:1: Firmware wakeup failed > > mwifiex_sdio mmc1:0001:1: PREP_CMD: FW in reset state > > > > ...and tracing through the resume code in the failing cases showed > > that we were processing a SDIO interrupt really early in the resume > > call. > > > > NOTE: downstream in Chrome OS 3.14 and 3.18 kernels (both of which > > support the Marvell SDIO WiFi card) we had a patch ("CHROMIUM: sdio: > > Defer SDIO interrupt handling until after resume") [2]. Presumably > > this is the same problem that was solved by that patch. > > Seems reasonable. Anyway, let me know what you think the next set of steps ought to be. It would be sorta nice to get suspend/resume working reliably and land this patch, but if you think that will impede our ability to come up with a more generic solution then I guess we don't need to land it... -Doug