From patchwork Tue Apr 14 16:14:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 185415 Delivered-To: patches@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp1601806ilf; Tue, 14 Apr 2020 09:14:40 -0700 (PDT) X-Received: by 2002:a2e:854e:: with SMTP id u14mr542329ljj.182.1586880880488; Tue, 14 Apr 2020 09:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586880880; cv=none; d=google.com; s=arc-20160816; b=k0NebV58OZd3aKa6zjxRkvkcctZCR/MDjcfWETx268qfRyN/xDIpAzbVXONsuiL66j Wzs8QZZiyEO6SjMI4JnCJZAPOsGpnby0GvjBIZEVGOrlUTJQwQ9Ff+966/c6gzmUQrM7 fdAatlFVIIvPm5qufEvKvTau8Mp6sLek0d3T8lza2ABIX4Elykmj5LjN5SEH7bEobvkA +RAfTI1S1v+lrorWmLalg0CPyBQJ18R/uV1TzNTPAQoaoHw9onQoDcV9gaZRaDIBeCr9 1c6wqqK2fhxU/AaDiOMWcNb1iMkL1C4grKPMj0ay9U3SGZCEy6LiIP35n7H9KqfKA9GG Xn6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=2fc7WtOqZOvMpJU85RcRGqqZ+8XJc5IQ4CJNIRP5fnM=; b=AHxG31bOY/tA/qzIB60H9ysBQDBCPS2i+fSlgYA5yjGV+En0SuebC7++gG/sHl9gCj gb2E2ZG+/USeGxOfsmvAm4em2D018B3l7uWg2UfChHKzPYIU/ANniT5XUO1yYlO5XE6N 4pnbKKwVAKBoYCsLHmDJZJhF9VlD84pCHN3q3e4m3tACEBNjw0G8+j/gjIAwfY4kfskT Qj+FPv/vJvmvxG2ZwJ3B+NcJ+gNFSKdqZdL2rE9b0L9ED1PYqVvVgIG4W+f7Hkovd++S 9JRCSHN8opzdXVo50q59wkQXYauqVXTTMIEkvjra5JkLW4Koh0N0NMzzwBgY/Ven5imQ PV8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pOF2huuq; 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 c5sor7994994ljk.42.2020.04.14.09.14.40 for (Google Transport Security); Tue, 14 Apr 2020 09:14:40 -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=pOF2huuq; 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 :mime-version:content-transfer-encoding; bh=2fc7WtOqZOvMpJU85RcRGqqZ+8XJc5IQ4CJNIRP5fnM=; b=pOF2huuqut38BoNJgj0iOYHBXyCNVmoo9Yvh5FawG3zltJ7ZPfJZswslJFAnENYA7I K77MbbC9Gi1SC5G5YVdIRTlOr2zirST1v410eFUzxYy17hn1x2HqOHhbjwVGjJR0Yqbk hBTyl3BG4QEEkY2qRK+s0uubn2UtmOXJt2Q2sTNOSgCs3QmyuwYEfP70KFEDyJ1Wlowy ojbQWIDSi8aa2W7HCCo7Ev0yE4FkG8iQ/+l3jWNhSKoezJ2t2IQ8cwQ7zoMpChk8JnVj CIt8FqrJU+d4afqIhJQBMtlycUzfc2gIuHm389R2Z4N30MUPXMIAACffm+w+4mKJVDcF oMSQ== 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:mime-version:content-transfer-encoding; bh=2fc7WtOqZOvMpJU85RcRGqqZ+8XJc5IQ4CJNIRP5fnM=; b=S4wjApv7RTWLZ6GFIO6CeuOcc0jn8Go/j1WI7DVNUudRxIOQfZbMqY7YkO18E0cSYF /7Oyq7jnRjGqjx7Feh8V7418qbBGpTfpgeUIYOJVPXGtbWD0zKrYAk1E4ngoEs9MEBWs LLc8iuzRv+e/rqniP39dvdiBCoGQvrrcQdjVqVL5B9d5AF+bBHEOJr5jNh4JcrodDUO7 50vkiROBl3STv4OfniOkcp/sQon480ZjN12gBJyRUm3Gn9qLcly7QaTGcH3aGhYohOXf pUel0xVXz2A1YaHrx8nH3jSsUCzYGgacgXEwcfWJZEUnt/7TVX9Y/EhkcYrP6AoZgZyJ r2iw== X-Gm-Message-State: AGi0PuZm2tLYtmOcifrsL+D8XpgUx8JcQ7afmhwC4lyUgj6H1FkZpEXZ Xc/2dCh7V6OtW39GpRUMQt4VwnFo X-Google-Smtp-Source: APiQypLAkI1rn94043/JUBbLE/tcZ4krtmAWvBc1ranLU7T14jnbHyK/ZMTiWUw5X6G6bsDXUS/mPg== X-Received: by 2002:a2e:a584:: with SMTP id m4mr573350ljp.194.1586880880086; Tue, 14 Apr 2020 09:14:40 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-131.NA.cust.bahnhof.se. [98.128.181.131]) by smtp.gmail.com with ESMTPSA id a26sm9330669ljn.22.2020.04.14.09.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 09:14:39 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Linus Walleij , Rui Miguel Silva , Johan Hovold , Alex Elder , Greg Kroah-Hartman , =?utf-8?q?Jonathan_Neusch=C3=A4fer?= , Bruce Chang , Harald Welte , Alex Dubov , Sascha Sommer , Manivannan Sadhasivam , mirq-linux@rere.qmqm.pl, Jesper Nilsson , Lars Persson , Paul Cercueil , Ludovic Desroches , Nicolas Ferre Subject: [PATCH 13/19] mmc: sdricoh_cs: Throttle polling rate for commands Date: Tue, 14 Apr 2020 18:14:07 +0200 Message-Id: <20200414161413.3036-14-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200414161413.3036-1-ulf.hansson@linaro.org> References: <20200414161413.3036-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Rather than to poll in a busy-loop, let's convert into using readl_poll_timeout() and insert a small delay between each polling attempts. In particular, this avoids hogging the CPU. Additionally, to convert to readl_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 --- drivers/mmc/host/sdricoh_cs.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c index 7e407fb6dab8..d7a191f14337 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 */ @@ -157,8 +157,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? */ @@ -174,24 +173,23 @@ 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 = readl_poll_timeout(host->iobase + R21C_STATUS, status, + sdricoh_status_ok(host, status, STATUS_CMD_FINISHED), + 32, SDRICOH_CMD_TIMEOUT_US); - 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)