From patchwork Sun Sep 8 10:12:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 173343 Delivered-To: patches@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp3003124ilq; Sun, 8 Sep 2019 03:12:53 -0700 (PDT) X-Received: by 2002:ac2:43c5:: with SMTP id u5mr12827345lfl.47.1567937572919; Sun, 08 Sep 2019 03:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567937572; cv=none; d=google.com; s=arc-20160816; b=fK1YMSKl6/E9EYCAQ7NZQmwzHXZCadiy0b/uzfhDWYP6xTWORw2R+2nTEIUCppv4pp w2FdTd//z+2uBxl1sREJKc09m3F5mWtXXccrsI/X0m9aKlw9iGiUkVjWUuaRtjmz0+my vjtCNayYKVjOTBE+LnUIJDRlTrWUVrMShnsOpt/cXuZS6OQMkqeUWb6ORvjXEI+1phVF ayJoYQM7+oHpmRWSCPLmHmqjkaU70M+545Df/oYp4xWE12PGF3hZdUo/Wz4EqLqeYO7i 0NVvhHxl2xLlop6PI0xj5BRhNbKpBw6C3UnN5bAzBsJ3Kn48kpsUWsE/uI6p61k9P/yM cNhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IS0lVdK7iQppkNRcA/eyYIxzfqUhjc4kqGnbAO0Nu8w=; b=f67Fb+MjC+RgSnLAQm6E2xQLw7j4B2DVCm/ytCvYFt5J6ytYrtUU0b/s1U4G4/m1b/ sF8/hsh1Uu+okI3lDE/OHU3bivRziYIW2ECPukqFXmQE2ACOC83+Wa56G1a0xUNMd8OC bBnHJYPffNFXfgxzp1FKEVT7IwJdq8ZCJ3hTd+tOaWhtaRwnyYWtpWhdwdBPuS5QijFE 4HJNyFN2y5hvnnQWNU8+KluhZDxCNBnFTl4zGmchRbHk/+XEMo2lA5xpX66tTb8TyEVB ZJXoOTeOJjtOgLh1dtCmBPaK75a6zAXzVC9cf8VB8Z/RPreE+6lXqS2ebHUrrQgHyyXA onMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XFSAECu6; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a3sor3291640ljh.8.2019.09.08.03.12.52 for (Google Transport Security); Sun, 08 Sep 2019 03:12:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XFSAECu6; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IS0lVdK7iQppkNRcA/eyYIxzfqUhjc4kqGnbAO0Nu8w=; b=XFSAECu6eOchqjUmGfyiFNgZMWo+bvmAT0zhqDXFcxcLzZrltHNIhcmRSv6/JryE1v O7KAHIvW8AEktgkrl5abCIN6g137fTZuN4+UmVwn4Dj2e2sNi9d2vV/hsiwPd60aQTFH XvqkGnJe7W7dOLIGZdBWH4Hh8IqcxzSxuI6G+wN6mcnHoOlW2p6DxoTimAa2YJiDD9gc j3GVp5WR9XwBthfZyvCewUxTDky7uxpl5uaHcw0fRYk5TMEe4Mdm00mLfgPWbaVLnGc9 kLxXihevliSWwN6eOghy0521aMhpFk72hI395y5Jn7kPWbXKLcP4MaCBH2xufp3mlztK VoTA== 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:in-reply-to :references; bh=IS0lVdK7iQppkNRcA/eyYIxzfqUhjc4kqGnbAO0Nu8w=; b=OMiC+OFoHcFYashnPcBtShnRz38OL/C2RHK/6N7kxITrYHxSFED9KNBX1juaFYZ3e2 CNRS9QXEVC0KLG6jh36ZIYKlexVMlK56qFpmv09Qi6BCCZkEiLpSoOpF5uk5ye3bo2LU jeFpMA06aMscj1hAPkYRfJVZFvO0ayiUDSEzLQVPjFNKJU/LVDv2vuEVvDzHsToAAVcE pChGvjByMoVolO+hQ8YFNHrNZHq8jdKAKMu4Z06AU0G1K6KjySonFL5OumQP6SbB41CV sJLJIhSUy1KfjXllbghNz7Z0FUUSSzHfTMrHER3Yk+ZjNAIZuMOY7tJ0eDaqkPFR5daL WIJg== X-Gm-Message-State: APjAAAWSiZk8F6gTeNjBGFDs16/S0HNctiaZXRGD6gY23rK7l5avnIR2 GBTxwbzuLKCCR6Mr89IJ6RftIh5M X-Google-Smtp-Source: APXvYqzGa5ufeqoMMCyIUrEeU7LqbusZnxDO1ItjP4toDSXg19lvkKmBEh9+NqDHY2u1hfysc1HBJg== X-Received: by 2002:a2e:b1c4:: with SMTP id e4mr12099214lja.101.1567937572577; Sun, 08 Sep 2019 03:12:52 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([185.122.190.73]) by smtp.gmail.com with ESMTPSA id h25sm2444849lfj.81.2019.09.08.03.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Sep 2019 03:12:52 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter , Douglas Anderson , Matthias Kaehlcke Cc: Shawn Lin , Jaehoon Chung , Yong Mao , Chaotian Jing , linux-kernel@vger.kernel.org Subject: [PATCH v2 08/11] mmc: core: Fixup processing of SDIO IRQs during system suspend/resume Date: Sun, 8 Sep 2019 12:12:33 +0200 Message-Id: <20190908101236.2802-9-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190908101236.2802-1-ulf.hansson@linaro.org> References: <20190908101236.2802-1-ulf.hansson@linaro.org> System suspend/resume of SDIO cards, with SDIO IRQs enabled and when using MMC_CAP2_SDIO_IRQ_NOTHREAD is unfortunate still suffering from a fragile behaviour. Some problems have been taken care of so far, but more issues remains. For example, calling the ->ack_sdio_irq() callback to let host drivers re-enable the SDIO IRQs is a bad idea, unless the IRQ have been consumed, which may not be the case during system suspend/resume. This may lead to that a host driver re-signals the same SDIO IRQ over and over again, causing a storm of IRQs and gives a ping-pong effect towards the sdio_irq_work(). Moreover, calling the ->enable_sdio_irq() callback at system resume to re-enable already enabled SDIO IRQs for the host, causes the runtime PM count for some host drivers to become in-balanced. This then leads to the host to remain runtime resumed, no matter if it's needed or not. To fix these problems, let's check if process_sdio_pending_irqs() actually consumed the SDIO IRQ, before we continue to ack the IRQ by invoking the ->ack_sdio_irq() callback. Additionally, there should be no need to re-enable SDIO IRQs as the host driver already knows if they were enabled at system suspend, thus also whether it needs to re-enable them at system resume. For this reason, drop the call to ->enable_sdio_irq() during system resume. In regards to these changes there is yet another issue, which is when there is an SDIO IRQ being signaled by the host driver, but after the SDIO card has been system suspended. Currently these IRQs are just thrown away, while we should at least make sure to try to consume them when the SDIO card has been system resumed. Fix this by queueing a sdio_irq_work() after we system resumed the SDIO card. Tested-by: Matthias Kaehlcke Reviewed-by: Matthias Kaehlcke Signed-off-by: Ulf Hansson --- Changes in v2: - Queue a sdio_irq_work() rather using sdio_signal_irq(). --- drivers/mmc/core/sdio.c | 2 +- drivers/mmc/core/sdio_irq.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Douglas Anderson diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index c557f1519b77..26cabd53ddc5 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -1015,7 +1015,7 @@ static int mmc_sdio_resume(struct mmc_host *host) if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) wake_up_process(host->sdio_irq_thread); else if (host->caps & MMC_CAP_SDIO_IRQ) - host->ops->enable_sdio_irq(host, 1); + queue_delayed_work(system_wq, &host->sdio_irq_work, 0); } out: diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c index d7965b53a6d2..900871073bd7 100644 --- a/drivers/mmc/core/sdio_irq.c +++ b/drivers/mmc/core/sdio_irq.c @@ -115,7 +115,8 @@ static void sdio_run_irqs(struct mmc_host *host) mmc_claim_host(host); if (host->sdio_irqs) { process_sdio_pending_irqs(host); - host->ops->ack_sdio_irq(host); + if (!host->sdio_irq_pending) + host->ops->ack_sdio_irq(host); } mmc_release_host(host); }