Skip to content

Commit eadb789

Browse files
committed
mmc: sdricoh_cs: Throttle polling rate for data transfers
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 <[email protected]> Signed-off-by: Ulf Hansson <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 85a3f77 commit eadb789

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

drivers/mmc/host/sdricoh_cs.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/module.h>
1616
#include <linux/pci.h>
1717
#include <linux/ioport.h>
18+
#include <linux/iopoll.h>
1819
#include <linux/scatterlist.h>
1920

2021
#include <pcmcia/cistpl.h>
@@ -59,7 +60,7 @@ static unsigned int switchlocked;
5960

6061
/* timeouts */
6162
#define CMD_TIMEOUT 100000
62-
#define TRANSFER_TIMEOUT 100000
63+
#define SDRICOH_DATA_TIMEOUT_US 1000000
6364

6465
/* list of supported pcmcia devices */
6566
static const struct pcmcia_device_id pcmcia_ids[] = {
@@ -123,21 +124,24 @@ static inline unsigned int sdricoh_readb(struct sdricoh_host *host,
123124
return value;
124125
}
125126

127+
static bool sdricoh_status_ok(struct sdricoh_host *host, unsigned int status,
128+
unsigned int wanted)
129+
{
130+
sdricoh_writel(host, R2E4_STATUS_RESP, status);
131+
return status & wanted;
132+
}
133+
126134
static int sdricoh_query_status(struct sdricoh_host *host, unsigned int wanted)
127135
{
128-
unsigned int loop;
136+
int ret;
129137
unsigned int status = 0;
130-
unsigned int timeout = TRANSFER_TIMEOUT;
131138
struct device *dev = host->dev;
132139

133-
for (loop = 0; loop < timeout; loop++) {
134-
status = sdricoh_readl(host, R21C_STATUS);
135-
sdricoh_writel(host, R2E4_STATUS_RESP, status);
136-
if (status & wanted)
137-
break;
138-
}
139-
140-
if (loop == timeout) {
140+
ret = read_poll_timeout(sdricoh_readl, status,
141+
sdricoh_status_ok(host, status, wanted),
142+
32, SDRICOH_DATA_TIMEOUT_US, false,
143+
host, R21C_STATUS);
144+
if (ret) {
141145
dev_err(dev, "query_status: timeout waiting for %x\n", wanted);
142146
return -ETIMEDOUT;
143147
}

0 commit comments

Comments
 (0)