Skip to content

Commit 84bb8d8

Browse files
linuswstorulf
authored andcommitted
Revert "mmc: moxart-mmc: Use sg_miter for PIO"
This reverts commit 3ee0e7c. The patch is not working for unknown reasons and I would need access to the hardware to fix the bug. This shouldn't matter anyway: the Moxa Art is not expected to use highmem, and sg_miter() is only necessary to have to properly deal with highmem. Reported-by: Sergei Antonov <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Fixes: 3ee0e7c ("mmc: moxart-mmc: Use sg_miter for PIO") Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent d77dc38 commit 84bb8d8

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

drivers/mmc/host/moxart-mmc.c

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ 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;
134135
struct completion dma_complete;
135136
struct completion pio_complete;
136137

137-
struct sg_mapping_iter sg_miter;
138+
u32 num_sg;
139+
u32 data_remain;
138140
u32 data_len;
139141
u32 fifo_width;
140142
u32 timeout;
@@ -146,6 +148,35 @@ struct moxart_host {
146148
bool is_removed;
147149
};
148150

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+
149180
static int moxart_wait_for_status(struct moxart_host *host,
150181
u32 mask, u32 *status)
151182
{
@@ -278,29 +309,14 @@ static void moxart_transfer_dma(struct mmc_data *data, struct moxart_host *host)
278309

279310
static void moxart_transfer_pio(struct moxart_host *host)
280311
{
281-
struct sg_mapping_iter *sgm = &host->sg_miter;
282312
struct mmc_data *data = host->mrq->cmd->data;
283313
u32 *sgp, len = 0, remain, status;
284314

285315
if (host->data_len == data->bytes_xfered)
286316
return;
287317

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;
303-
sgm->consumed = 0;
318+
sgp = sg_virt(host->cur_sg);
319+
remain = host->data_remain;
304320

305321
if (data->flags & MMC_DATA_WRITE) {
306322
while (remain > 0) {
@@ -315,7 +331,6 @@ static void moxart_transfer_pio(struct moxart_host *host)
315331
sgp++;
316332
len += 4;
317333
}
318-
sgm->consumed += len;
319334
remain -= len;
320335
}
321336

@@ -332,22 +347,22 @@ static void moxart_transfer_pio(struct moxart_host *host)
332347
sgp++;
333348
len += 4;
334349
}
335-
sgm->consumed += len;
336350
remain -= len;
337351
}
338352
}
339353

340-
data->bytes_xfered += sgm->consumed;
341-
if (host->data_len == data->bytes_xfered) {
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
342360
complete(&host->pio_complete);
343-
return;
344-
}
345361
}
346362

347363
static void moxart_prepare_data(struct moxart_host *host)
348364
{
349365
struct mmc_data *data = host->mrq->cmd->data;
350-
unsigned int flags = SG_MITER_ATOMIC; /* Used from IRQ */
351366
u32 datactrl;
352367
int blksz_bits;
353368

@@ -358,19 +373,15 @@ static void moxart_prepare_data(struct moxart_host *host)
358373
blksz_bits = ffs(data->blksz) - 1;
359374
BUG_ON(1 << blksz_bits != data->blksz);
360375

376+
moxart_init_sg(host, data);
377+
361378
datactrl = DCR_DATA_EN | (blksz_bits & DCR_BLK_SIZE);
362379

363-
if (data->flags & MMC_DATA_WRITE) {
364-
flags |= SG_MITER_FROM_SG;
380+
if (data->flags & MMC_DATA_WRITE)
365381
datactrl |= DCR_DATA_WRITE;
366-
} else {
367-
flags |= SG_MITER_TO_SG;
368-
}
369382

370383
if (moxart_use_dma(host))
371384
datactrl |= DCR_DMA_EN;
372-
else
373-
sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
374385

375386
writel(DCR_DATA_FIFO_RESET, host->base + REG_DATA_CONTROL);
376387
writel(MASK_DATA | FIFO_URUN | FIFO_ORUN, host->base + REG_CLEAR);
@@ -443,9 +454,6 @@ static void moxart_request(struct mmc_host *mmc, struct mmc_request *mrq)
443454
}
444455

445456
request_done:
446-
if (!moxart_use_dma(host))
447-
sg_miter_stop(&host->sg_miter);
448-
449457
spin_unlock_irqrestore(&host->lock, flags);
450458
mmc_request_done(host->mmc, mrq);
451459
}

0 commit comments

Comments
 (0)