Skip to content

Commit 3ee0e7c

Browse files
linuswstorulf
authored andcommitted
mmc: moxart-mmc: Use sg_miter for PIO
Use the scatterlist memory iterator instead of just dereferencing virtual memory using sg_virt(). This make highmem references work properly. Suggested-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/linux-mmc/[email protected]/ Signed-off-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 54fd8cd commit 3ee0e7c

File tree

1 file changed

+34
-43
lines changed

1 file changed

+34
-43
lines changed

drivers/mmc/host/moxart-mmc.c

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ struct moxart_host {
131131
struct dma_async_tx_descriptor *tx_desc;
132132
struct mmc_host *mmc;
133133
struct mmc_request *mrq;
134-
struct scatterlist *cur_sg;
135134
struct completion dma_complete;
136135
struct completion pio_complete;
137136

138-
u32 num_sg;
139-
u32 data_remain;
137+
struct sg_mapping_iter sg_miter;
140138
u32 data_len;
141139
u32 fifo_width;
142140
u32 timeout;
@@ -148,35 +146,6 @@ struct moxart_host {
148146
bool is_removed;
149147
};
150148

151-
static inline void moxart_init_sg(struct moxart_host *host,
152-
struct mmc_data *data)
153-
{
154-
host->cur_sg = data->sg;
155-
host->num_sg = data->sg_len;
156-
host->data_remain = host->cur_sg->length;
157-
158-
if (host->data_remain > host->data_len)
159-
host->data_remain = host->data_len;
160-
}
161-
162-
static inline int moxart_next_sg(struct moxart_host *host)
163-
{
164-
int remain;
165-
struct mmc_data *data = host->mrq->cmd->data;
166-
167-
host->cur_sg++;
168-
host->num_sg--;
169-
170-
if (host->num_sg > 0) {
171-
host->data_remain = host->cur_sg->length;
172-
remain = host->data_len - data->bytes_xfered;
173-
if (remain > 0 && remain < host->data_remain)
174-
host->data_remain = remain;
175-
}
176-
177-
return host->num_sg;
178-
}
179-
180149
static int moxart_wait_for_status(struct moxart_host *host,
181150
u32 mask, u32 *status)
182151
{
@@ -309,14 +278,28 @@ static void moxart_transfer_dma(struct mmc_data *data, struct moxart_host *host)
309278

310279
static void moxart_transfer_pio(struct moxart_host *host)
311280
{
281+
struct sg_mapping_iter *sgm = &host->sg_miter;
312282
struct mmc_data *data = host->mrq->cmd->data;
313283
u32 *sgp, len = 0, remain, status;
314284

315285
if (host->data_len == data->bytes_xfered)
316286
return;
317287

318-
sgp = sg_virt(host->cur_sg);
319-
remain = host->data_remain;
288+
/*
289+
* By updating sgm->consumes this will get a proper pointer into the
290+
* buffer at any time.
291+
*/
292+
if (!sg_miter_next(sgm)) {
293+
/* This shold not happen */
294+
dev_err(mmc_dev(host->mmc), "ran out of scatterlist prematurely\n");
295+
data->error = -EINVAL;
296+
complete(&host->pio_complete);
297+
return;
298+
}
299+
sgp = sgm->addr;
300+
remain = sgm->length;
301+
if (remain > host->data_len)
302+
remain = host->data_len;
320303

321304
if (data->flags & MMC_DATA_WRITE) {
322305
while (remain > 0) {
@@ -331,6 +314,7 @@ static void moxart_transfer_pio(struct moxart_host *host)
331314
sgp++;
332315
len += 4;
333316
}
317+
sgm->consumed += len;
334318
remain -= len;
335319
}
336320

@@ -347,22 +331,22 @@ static void moxart_transfer_pio(struct moxart_host *host)
347331
sgp++;
348332
len += 4;
349333
}
334+
sgm->consumed += len;
350335
remain -= len;
351336
}
352337
}
353338

354-
data->bytes_xfered += host->data_remain - remain;
355-
host->data_remain = remain;
356-
357-
if (host->data_len != data->bytes_xfered)
358-
moxart_next_sg(host);
359-
else
339+
data->bytes_xfered += sgm->consumed;
340+
if (host->data_len == data->bytes_xfered) {
360341
complete(&host->pio_complete);
342+
return;
343+
}
361344
}
362345

363346
static void moxart_prepare_data(struct moxart_host *host)
364347
{
365348
struct mmc_data *data = host->mrq->cmd->data;
349+
unsigned int flags = SG_MITER_ATOMIC; /* Used from IRQ */
366350
u32 datactrl;
367351
int blksz_bits;
368352

@@ -373,15 +357,19 @@ static void moxart_prepare_data(struct moxart_host *host)
373357
blksz_bits = ffs(data->blksz) - 1;
374358
BUG_ON(1 << blksz_bits != data->blksz);
375359

376-
moxart_init_sg(host, data);
377-
378360
datactrl = DCR_DATA_EN | (blksz_bits & DCR_BLK_SIZE);
379361

380-
if (data->flags & MMC_DATA_WRITE)
362+
if (data->flags & MMC_DATA_WRITE) {
363+
flags |= SG_MITER_FROM_SG;
381364
datactrl |= DCR_DATA_WRITE;
365+
} else {
366+
flags |= SG_MITER_TO_SG;
367+
}
382368

383369
if (moxart_use_dma(host))
384370
datactrl |= DCR_DMA_EN;
371+
else
372+
sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
385373

386374
writel(DCR_DATA_FIFO_RESET, host->base + REG_DATA_CONTROL);
387375
writel(MASK_DATA | FIFO_URUN | FIFO_ORUN, host->base + REG_CLEAR);
@@ -454,6 +442,9 @@ static void moxart_request(struct mmc_host *mmc, struct mmc_request *mrq)
454442
}
455443

456444
request_done:
445+
if (!moxart_use_dma(host))
446+
sg_miter_stop(&host->sg_miter);
447+
457448
spin_unlock_irqrestore(&host->lock, flags);
458449
mmc_request_done(host->mmc, mrq);
459450
}

0 commit comments

Comments
 (0)