From patchwork Fri May 8 09:52:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 186319 Delivered-To: patches@linaro.org Received: by 2002:a92:8d81:0:0:0:0:0 with SMTP id w1csp4001720ill; Fri, 8 May 2020 02:52:15 -0700 (PDT) X-Received: by 2002:a2e:a417:: with SMTP id p23mr1215397ljn.19.1588931535763; Fri, 08 May 2020 02:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588931535; cv=none; d=google.com; s=arc-20160816; b=wcuWlgmHA6KB1uL9o7MFHKxrFMGYeG1zyOWEmYs3W+iJOKby6V/EL9sLyDgnmSFPzO KVoppfL3sEY3ZmnWadtET/4zeFsce8wv+/cakftbS3iTgO8o5yeMwhwf+EIUPclP9oIM VIB/0zAyDjwQga8t0DGeVzZhp95A+gCkaP29jU8STM4GGFhYKZ/nKfgBg6r2adb55dm3 i/pQA4oqsbL+4ho2uZPMtuLqDhzqyU0f7z0JWChgAG2iSPNfqaTlZ2Fubz1KHg3RUIIr db2h75VWYGBa69Br701AM7x+V7dBd9sf8KXtoZmIxDYDum0MyJkj91r8VhNvGz1tF8s9 w3GA== 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=Kj0gLXRuliK3KdID/M87B7g/98tNYDKPX2QUn3XOTQs=; b=pWJzXuSzU2xfkbs63Mf6KIQGfANumPvEhb4LIBR3W4q0rr110finEMdeXGABvelU+D xRmq2an7R9rHamXO4YpAQxMiqAtXGQ4A/sZpNMdwAKeLOM/0AowBc99u5pZY2H9imNId KuslWLWF/LfyZPDsnSHHDq2kX/7iHnqtFwkZdBj7W6CE2isHQV/zKV38GfUM7q8UCPVv Ww2lvGbe1X78PjB5B1JNZwH59/uuKC3gOOc11iSyqJ2BwRZnLEDsqAWSLrl8Gl6Rub4+ N2/TmbWhcyGvQ+8qgvhEN8lcoIqAlXigmH3lQTMbkmonhFl5bxTFUZ2avll9q3/QdeOl FOSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OZhK7txA; 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 o6sor751233lja.22.2020.05.08.02.52.15 for (Google Transport Security); Fri, 08 May 2020 02:52:15 -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=OZhK7txA; 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=Kj0gLXRuliK3KdID/M87B7g/98tNYDKPX2QUn3XOTQs=; b=OZhK7txAGLD+FSfIpWbIoCZ0NEyJBgp/BtS++3PsuU1LgWgEHgTWM4a3k4nF2Q6Yw7 oYFe1+dnKTQNn7bUOSbVdXydIta7K+DEKKgIVrH719Fx3KeUR4rGn/+8B8wHr/nIxxxd aE7L8xJHuwYiJcOeHPhLL+5Z1IcpW/5Neuz/e3sF7pIENLRs6Xot5alcb5mjxHJilxiW UAfuBKJgGZH/+6nEGSp4gCImy1IwFnUJwqjLEtTEJXCvrwYyjSSNo8dl0hX6gG0AASpD gkjdyK29xioHXidw1lt6uK1jR3KWISfPCN1HkxggdzBzQ1rpLnnFSNUm+37GBd1ZDuQk vzyg== 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=Kj0gLXRuliK3KdID/M87B7g/98tNYDKPX2QUn3XOTQs=; b=KIlk9JZCAMlzyrn1tkIogYC5EPRXi+6jBj+DQks8bn/mrCqkKV4Gor80bgtadWi/h1 rBG1Xq6t2fDo79e9TcRSS/r2Uhle2+a5pKZA6gRAb/TrYPgIlcuUjCUYQN1Ptn7kr4lX CQlQcmQBsn/54YNMXd2MELzWfwKHY+vNzi3Z1T1RG9+C9nhK3Q3DmX7eCnd1caZfS3Hp 3pzQR5wiaC0wk/VVYigfq6lY8gus+O67on0WLy5VquFL3s3xGVqsfcKlOvQPnSOMzsmt zRDWm11G2blamrEj0YQCWVQXfKtr0S67TFulW6m2M9NQhk6imqkz29ou4yu50BzLeQWo 1gWQ== X-Gm-Message-State: AOAM5316xvIZ+sajMoCf6/JrRSW2vmorUh/0QjiUw/t4l0aQlNbgsYN+ LbHMJes8znTwUyPomiBckmDXW8dp X-Google-Smtp-Source: ABdhPJwKJB8uOVbN/pIbEuDd4HOoQ+C6BSyPbgNfn+VuvpOjHLllMfAT7oWr8g3IVoR3TkCia0SmRQ== X-Received: by 2002:a2e:2c11:: with SMTP id s17mr1136801ljs.119.1588931535130; Fri, 08 May 2020 02:52:15 -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 x24sm804019lji.52.2020.05.08.02.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2020 02:52:13 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Sascha Sommer Subject: [PATCH v2 12/19] mmc: sdricoh_cs: Throttle polling rate for data transfers Date: Fri, 8 May 2020 11:52:10 +0200 Message-Id: <20200508095210.14123-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 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c index 97ef7d71375a..8392158e2e9f 100644 --- a/drivers/mmc/host/sdricoh_cs.c +++ b/drivers/mmc/host/sdricoh_cs.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ static unsigned int switchlocked; /* timeouts */ #define CMD_TIMEOUT 100000 -#define TRANSFER_TIMEOUT 100000 +#define SDRICOH_DATA_TIMEOUT_US 1000000 /* list of supported pcmcia devices */ static const struct pcmcia_device_id pcmcia_ids[] = { @@ -123,21 +124,24 @@ static inline unsigned int sdricoh_readb(struct sdricoh_host *host, return value; } +static bool sdricoh_status_ok(struct sdricoh_host *host, unsigned int status, + unsigned int wanted) +{ + sdricoh_writel(host, R2E4_STATUS_RESP, status); + return status & wanted; +} + static int sdricoh_query_status(struct sdricoh_host *host, unsigned int wanted) { - unsigned int loop; + int ret; unsigned int status = 0; - unsigned int timeout = TRANSFER_TIMEOUT; struct device *dev = host->dev; - for (loop = 0; loop < timeout; loop++) { - status = sdricoh_readl(host, R21C_STATUS); - sdricoh_writel(host, R2E4_STATUS_RESP, status); - if (status & wanted) - break; - } - - if (loop == timeout) { + ret = read_poll_timeout(sdricoh_readl, status, + sdricoh_status_ok(host, status, wanted), + 32, SDRICOH_DATA_TIMEOUT_US, false, + host, R21C_STATUS); + if (ret) { dev_err(dev, "query_status: timeout waiting for %x\n", wanted); return -ETIMEDOUT; }