From patchwork Fri May 8 09:52:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 186320 Delivered-To: patches@linaro.org Received: by 2002:a92:8d81:0:0:0:0:0 with SMTP id w1csp4001796ill; Fri, 8 May 2020 02:52:23 -0700 (PDT) X-Received: by 2002:a05:651c:1055:: with SMTP id x21mr1118492ljm.210.1588931542914; Fri, 08 May 2020 02:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588931542; cv=none; d=google.com; s=arc-20160816; b=YGT8lRUko0e4jYyQj7GWN6GKwcF4Zlkyj7J71amLtswg/aHFDqH9GgyvriAszVN1oX 2bl5ZLY+j45SU0nJf7mx9+dYV2ThXhHiz/26fTe08or9phgycjZm5+HdkRWOCXJ+vQXq VgKNEbRsvKJ7Dq5CrYnesEkllAcFAL78o07xT+n7gp/J+KbAqSqOp97rRKk1DiYXt1Ih M0dwl9ejLtKR7Ljawt134cKr5EZFBNrYJbL2Tli72J47Z2HYnbaRLYz3Mk1nxYHDBfGE MUKKJZqgXuPoSFoZQTm81Q8djhvktho3e/As1cAOWKFnp0zvh4ktLveJA6607W9S1cIg A9Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=oGYd9AQdlcl1pmEoCpIEqwK9BJV8M5Www8GEN3oe3Ig=; b=r10CpaCHyu2/FowBlE8WnzdIzZ5+fDxMDq+RmtpnpJyruiGLfPsGnTRDwCKfILS29/ J1YL4jyy+kbHHfMscusYkDDgm3jlQs0ip/t65NZXgXS0MvfjGMkRoA675Gq+4lMck0WW 1AV4X8gE8uXZ1BYleESVA1g+IXQFisKDnG7NaOdQV7vHd6ZZeHSqWxvyGzeXdAaxzOeQ AH5r2sK/ZiExFKtAKi/ehha0CYJovtvNKCaKOeYcLyvUeoXbH2TvXK5QDItmd1Ly4Tw3 gVLW8Jsjs+TJD0PIjuIwQosfXMXvamuma0zgoMyGwS9q040F1VIY9xctrkvGWrXCduO2 CRHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NMJTr4se; 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 c20sor735214ljd.44.2020.05.08.02.52.22 for (Google Transport Security); Fri, 08 May 2020 02:52:22 -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=NMJTr4se; 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:mime-version :content-transfer-encoding; bh=oGYd9AQdlcl1pmEoCpIEqwK9BJV8M5Www8GEN3oe3Ig=; b=NMJTr4seavNIw4MU48DBNqlL2h3DmB9iiou0clJEgkDlBHjlexF0pA4JwH2dtezgNj qzN5yqpjoYCuEklNGZun92vnduKttdI8mQVj3zygoS4PsCBZfuddQxgJUriLuVnPSWG4 gOKf+WINBzHRjlC28YLZ+J5tnTeD4bTVTrolmIiLwbloDsAmjoJQ/DimqFjOLrARIGe/ qKhE13cy5BM32+8URt2LgIN69y14RjRB1evcfBPSHtBBf3fXUUqYxv8i0AYmywFPFqbt Z0BfwYaX/LMeQ8dpNEvX5wf/sSFijmpkFM4/OV7GRED8Zx+fx9tTp0UcaS34EPBV5LQu PWSg== 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:mime-version :content-transfer-encoding; bh=oGYd9AQdlcl1pmEoCpIEqwK9BJV8M5Www8GEN3oe3Ig=; b=he7wKwbiSERWWSYmBgaVdeL4l2wjNPu2AeVtfyjuD4uqcbsitTlW02uTGsRIZpKAyd fEDvG/i92J5vjBqn57wbqmTJlwENfAXyaUMkytnIpd5b3YYrHdMSWDddVkrTdxU7agzV ZWmmx8/ZQnWXivA9mzQmopPTtv0W+MUWG6XzyvDjl0LYx1T2ErPBXoDY853VN9cyOQZd ZJrJPiE+1xG/U4Wbj6gMxV3mtnK2c0rm3iw2JWqrtHNFaaCpge8RRnmmFD5EU6fBoJ/r xYQoEvd/f5PqKPGcgh0C+nGHid7ATlXl7yI4UsLuziTcMHN9j1YhQZVM48uWRXM56MPT AvnA== X-Gm-Message-State: AOAM530uZppLZBefaI04VUITutORxXfJ2kM1Wp1lyV9EUTABhYpbeCWc spPitVUo+DPGlKBB6UyUbBqt82vaktcB2g== X-Google-Smtp-Source: ABdhPJwCCb++sgF0Td/juhrOMNNZRkLd9l8oaoFT7HL2UEXXsKf8Y5+u0M/vD6BBBablFsIbR883Cw== X-Received: by 2002:a2e:8017:: with SMTP id j23mr1094276ljg.22.1588931542491; Fri, 08 May 2020 02:52:22 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id j29sm902171lfp.90.2020.05.08.02.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 02:52:21 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Sascha Sommer Subject: [PATCH v2 13/19] mmc: sdricoh_cs: Throttle polling rate for commands Date: Fri, 8 May 2020 11:52:18 +0200 Message-Id: <20200508095218.14177-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Rather than to poll in a busy-loop, let's convert into using read_poll_timeout() and insert a small delay between each polling attempts. In particular, this avoids hogging the CPU. Additionally, to convert to read_poll_timeout() we also need to switch from using a specific number of polling attempts, into a specific timeout in us instead. The previous 100000 attempts, is translated into a total timeout of total 1s, as that seemed like reasonable value to pick. Cc: Sascha Sommer Signed-off-by: Ulf Hansson --- Changes in v2: - Use read_poll_timeout() instead of readl_poll_timeout(), as to preserve the debug print in sdricoh_readl(). --- drivers/mmc/host/sdricoh_cs.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c index 8392158e2e9f..0594b5ffe151 100644 --- a/drivers/mmc/host/sdricoh_cs.c +++ b/drivers/mmc/host/sdricoh_cs.c @@ -59,7 +59,7 @@ static unsigned int switchlocked; #define STATUS_BUSY 0x40000000 /* timeouts */ -#define CMD_TIMEOUT 100000 +#define SDRICOH_CMD_TIMEOUT_US 1000000 #define SDRICOH_DATA_TIMEOUT_US 1000000 /* list of supported pcmcia devices */ @@ -158,8 +158,7 @@ static int sdricoh_query_status(struct sdricoh_host *host, unsigned int wanted) static int sdricoh_mmc_cmd(struct sdricoh_host *host, struct mmc_command *cmd) { unsigned int status; - int result = 0; - unsigned int loop = 0; + int ret; unsigned char opcode = cmd->opcode; /* reset status reg? */ @@ -175,24 +174,24 @@ static int sdricoh_mmc_cmd(struct sdricoh_host *host, struct mmc_command *cmd) /* fill parameters */ sdricoh_writel(host, R204_CMD_ARG, cmd->arg); sdricoh_writel(host, R200_CMD, (0x10000 << 8) | opcode); + /* wait for command completion */ - if (opcode) { - for (loop = 0; loop < CMD_TIMEOUT; loop++) { - status = sdricoh_readl(host, R21C_STATUS); - sdricoh_writel(host, R2E4_STATUS_RESP, status); - if (status & STATUS_CMD_FINISHED) - break; - } - /* don't check for timeout in the loop it is not always - reset correctly - */ - if (loop == CMD_TIMEOUT || status & STATUS_CMD_TIMEOUT) - result = -ETIMEDOUT; + if (!opcode) + return 0; - } + ret = read_poll_timeout(sdricoh_readl, status, + sdricoh_status_ok(host, status, STATUS_CMD_FINISHED), + 32, SDRICOH_CMD_TIMEOUT_US, false, + host, R21C_STATUS); - return result; + /* + * Don't check for timeout status in the loop, as it's not always reset + * correctly. + */ + if (ret || status & STATUS_CMD_TIMEOUT) + return -ETIMEDOUT; + return 0; } static int sdricoh_reset(struct sdricoh_host *host)