From patchwork Tue Feb 4 08:54:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 183066 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064358ile; Tue, 4 Feb 2020 00:55:24 -0800 (PST) X-Received: by 2002:a2e:809a:: with SMTP id i26mr17075721ljg.108.1580806524069; Tue, 04 Feb 2020 00:55:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806524; cv=none; d=google.com; s=arc-20160816; b=O+ep1WWn8Q6C6o3B4FugovopsGErSmYW/lgSG2lUON/b+pNq+twMw1t4WSckUyPxhW lv2Rfg2f7Oz19G4/JxDtyYsk5cwgDy+McktxOUVTK7QVzYuP8eBj+8kGLg0/W8N30hy2 VrIsCZs64gVSFYtbkXSQvMQUM15xlWFVUHaToh+EN3Iz2abHfRTd+goCoDt1NT4Q7ftc +rcBI04YhxruABc0dqdFOo3MnNWRIsU8GsGl0EZ/Vd32DGIXzX6LJq7CbCcCecgMc+RV /jhzs7yZiqszHHSU4qpK6nKNYXRfEmHCEid41VCvbHxJ6Luunt0nIfBPzEtt/bQ+G31a kfPw== 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=76qzmT2N+APJISrybQoaQycmewwxQpEPkoOAn/iBjYI=; b=utXE+1a9browOKOsK2PaCvoZirDH/cyphVF+zjHGDJUfo5ZlREKNRcuq4Lsyaf/VW/ 2G/hJiZc0w/11jzZ9anin9/fTC9j0iGnx6dWiFZsuLpeiKx+6Rf7VXKJpnGPW0iFVhZW bGefwttQQRT059GWwxgYj0ocJ1CBGGwTKp37mm9VMBO/LOycjFj1gzso47Ug3K0ABEEw xbgiO66Dbwh/iyaS/AH4P2CPFJa16nXcB4569iVg8SNQVWCMTvji2vzgPEMUPoVyHqdW /NotaWRtFKgc5Lrpr2a29pVY+XDZ6mopqk3t/qvBfz3y5RJXLP4giY/mTFi+MIC7WYfa TpFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mRTuBhRB; 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 h18sor12302687ljj.14.2020.02.04.00.55.23 for (Google Transport Security); Tue, 04 Feb 2020 00:55:24 -0800 (PST) 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=mRTuBhRB; 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=76qzmT2N+APJISrybQoaQycmewwxQpEPkoOAn/iBjYI=; b=mRTuBhRBZ82PkPR7LXi/V9bxQp3U2BR2gSjOJVux+AEKQNVsxPOp1fXrgaQWGUBvRs FPuJfvGjDQeUpv+X2frr21Oz/3aiaXuIGiqznJF7edUyw1w3hEYX2XTFV2Z9UA8wd/4D mU6OHbfHnKKoPwXdA6h+GVJSbcjaxNFuOu6yC5bYNtZxqQ7KwGiOgLMt0xHxn2fvCt+6 ZjgwTrGw7UVMvVMoYjSStHvKUKRBEO2odeGKXsRK/biDa33GRLWKpGfe2cBAQqAKMBxC Qt97cO9ASTdzjFpCN/mltO51UOc58eKmA9CfkuLW7vXKTQNAGb5Tof+mQlWl7LWkgLz5 AFdw== 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=76qzmT2N+APJISrybQoaQycmewwxQpEPkoOAn/iBjYI=; b=X9tzTaQlxM0P+XpZ5Uc8K31JcTOQWEuXkGdWY8E71pseXYhS738bMmnvZrGCEYREgb 0E1/T7zVuTpcgxjq2Eo57F0LvgZZdr/Hlvgf7UWLNSLGsPL2OB4gPc9Vxf7XM3XRsuaF VTT7nTTTNfl30BmGhQNUOn4R7d6RrpbMwsYSN0DNGdtbMdi+dG0okcK88ki4fJvdE7JH bPjrgtN+wrOBdqL4Q6kwJCIqRAjdz5pNWqiXhdePY+90MEfW7PjomuovbaEtGtGZY2yx k8ZypAJ79Ml5J4bkvn59HeSLrZKyJt+E2m1uWZV+Po1szdc3SiAbIgwkMzsnkFY3nFgC mjlQ== X-Gm-Message-State: APjAAAVz5WlpPGgwT1o8VTcxEo5Dm/xyUKYpWKjeNwQ+RJwT1msjDeaK m5PTf9jWDp9noCbQlbKPRChYOxyqD618eg== X-Google-Smtp-Source: APXvYqyk36ZqUcx/HJiF7kdli1JGrsdOSnZT4EvHE34Z+OOUynosTyy8bF3k69/OJn9iK5jum8m1XQ== X-Received: by 2002:a2e:9b05:: with SMTP id u5mr16835282lji.59.1580806523679; Tue, 04 Feb 2020 00:55:23 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:23 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 11/12] mmc: core: Fixup support for HW busy detection for HPI commands Date: Tue, 4 Feb 2020 09:54:48 +0100 Message-Id: <20200204085449.32585-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> In case the host specify a max_busy_timeout, we need to validate that the needed timeout for the HPI command conforms to that requirement. If that's not the case, let's convert from a R1B response to a R1 response, as to instruct the host to avoid HW busy detection. Additionally, when R1B is used we must also inform the host about the busy timeout for the command, so let's do that via updating cmd.busy_timeout. Finally, when R1B is used and in case the host supports HW busy detection, there should be no need for doing polling, so then skip that. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 87d54a559b31..aa0cab190cd8 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -832,27 +832,41 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width) static int mmc_send_hpi_cmd(struct mmc_card *card) { unsigned int busy_timeout_ms = card->ext_csd.out_of_int_time; + struct mmc_host *host = card->host; + bool use_r1b_resp = true; struct mmc_command cmd = {}; - unsigned int opcode; int err; - opcode = card->ext_csd.hpi_cmd; - if (opcode == MMC_STOP_TRANSMISSION) + cmd.opcode = card->ext_csd.hpi_cmd; + cmd.arg = card->rca << 16 | 1; + + /* + * Make sure the host's max_busy_timeout fit the needed timeout for HPI. + * In case it doesn't, let's instruct the host to avoid HW busy + * detection, by using a R1 response instead of R1B. + */ + if (host->max_busy_timeout && busy_timeout_ms > host->max_busy_timeout) + use_r1b_resp = false; + + if (cmd.opcode == MMC_STOP_TRANSMISSION && use_r1b_resp) { cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; - else if (opcode == MMC_SEND_STATUS) + cmd.busy_timeout = busy_timeout_ms; + } else { cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; + use_r1b_resp = false; + } - cmd.opcode = opcode; - cmd.arg = card->rca << 16 | 1; - - err = mmc_wait_for_cmd(card->host, &cmd, 0); + err = mmc_wait_for_cmd(host, &cmd, 0); if (err) { - pr_warn("%s: error %d interrupting operation. " - "HPI command response %#x\n", mmc_hostname(card->host), - err, cmd.resp[0]); + pr_warn("%s: HPI error %d. Command response %#x\n", + mmc_hostname(host), err, cmd.resp[0]); return err; } + /* No need to poll when using HW busy detection. */ + if (host->caps & MMC_CAP_WAIT_WHILE_BUSY && use_r1b_resp) + return 0; + /* Let's poll to find out when the HPI request completes. */ return mmc_poll_for_busy(card, busy_timeout_ms, MMC_BUSY_HPI); }