Skip to content

Commit 90c2143

Browse files
Seungwon Jeoncjb
authored andcommitted
mmc: dw_mmc: guarantee stop-abort cmd in data errors
In error cases, DTO interrupt may or may not be generated depending on remained data. Stop/Abort command ensures DTO generation for that situation. Currently if 'stop' field of data is empty, there is no stop/abort command. So, it could hang waiting DTO. This change reinforces these cases. Signed-off-by: Seungwon Jeon <tgih.jun@samsung.com> Tested-by: Alim Akhtar <alim.akhtar@samsung.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 71abb13 commit 90c2143

2 files changed

Lines changed: 66 additions & 20 deletions

File tree

‎drivers/mmc/host/dw_mmc.c‎

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/irq.h>
3030
#include <linux/mmc/host.h>
3131
#include <linux/mmc/mmc.h>
32+
#include <linux/mmc/sdio.h>
3233
#include <linux/mmc/dw_mmc.h>
3334
#include <linux/bitops.h>
3435
#include <linux/regulator/consumer.h>
@@ -246,10 +247,15 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
246247

247248
cmdr = cmd->opcode;
248249

249-
if (cmdr == MMC_STOP_TRANSMISSION)
250+
if (cmd->opcode == MMC_STOP_TRANSMISSION ||
251+
cmd->opcode == MMC_GO_IDLE_STATE ||
252+
cmd->opcode == MMC_GO_INACTIVE_STATE ||
253+
(cmd->opcode == SD_IO_RW_DIRECT &&
254+
((cmd->arg >> 9) & 0x1FFFF) == SDIO_CCCR_ABORT))
250255
cmdr |= SDMMC_CMD_STOP;
251256
else
252-
cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
257+
if (cmd->opcode != MMC_SEND_STATUS && cmd->data)
258+
cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
253259

254260
if (cmd->flags & MMC_RSP_PRESENT) {
255261
/* We expect a response, so set this bit */
@@ -276,6 +282,40 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
276282
return cmdr;
277283
}
278284

285+
static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
286+
{
287+
struct mmc_command *stop;
288+
u32 cmdr;
289+
290+
if (!cmd->data)
291+
return 0;
292+
293+
stop = &host->stop_abort;
294+
cmdr = cmd->opcode;
295+
memset(stop, 0, sizeof(struct mmc_command));
296+
297+
if (cmdr == MMC_READ_SINGLE_BLOCK ||
298+
cmdr == MMC_READ_MULTIPLE_BLOCK ||
299+
cmdr == MMC_WRITE_BLOCK ||
300+
cmdr == MMC_WRITE_MULTIPLE_BLOCK) {
301+
stop->opcode = MMC_STOP_TRANSMISSION;
302+
stop->arg = 0;
303+
stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
304+
} else if (cmdr == SD_IO_RW_EXTENDED) {
305+
stop->opcode = SD_IO_RW_DIRECT;
306+
stop->arg |= (1 << 31) | (0 << 28) | (SDIO_CCCR_ABORT << 9) |
307+
((cmd->arg >> 28) & 0x7);
308+
stop->flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
309+
} else {
310+
return 0;
311+
}
312+
313+
cmdr = stop->opcode | SDMMC_CMD_STOP |
314+
SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP;
315+
316+
return cmdr;
317+
}
318+
279319
static void dw_mci_start_command(struct dw_mci *host,
280320
struct mmc_command *cmd, u32 cmd_flags)
281321
{
@@ -290,9 +330,10 @@ static void dw_mci_start_command(struct dw_mci *host,
290330
mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
291331
}
292332

293-
static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data)
333+
static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data)
294334
{
295-
dw_mci_start_command(host, data->stop, host->stop_cmdr);
335+
struct mmc_command *stop = data->stop ? data->stop : &host->stop_abort;
336+
dw_mci_start_command(host, stop, host->stop_cmdr);
296337
}
297338

298339
/* DMA interface functions */
@@ -828,6 +869,8 @@ static void __dw_mci_start_request(struct dw_mci *host,
828869

829870
if (mrq->stop)
830871
host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
872+
else
873+
host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
831874
}
832875

833876
static void dw_mci_start_request(struct dw_mci *host,
@@ -1190,13 +1233,9 @@ static void dw_mci_tasklet_func(unsigned long priv)
11901233

11911234
if (cmd->data && cmd->error) {
11921235
dw_mci_stop_dma(host);
1193-
if (data->stop) {
1194-
send_stop_cmd(host, data);
1195-
state = STATE_SENDING_STOP;
1196-
break;
1197-
} else {
1198-
host->data = NULL;
1199-
}
1236+
send_stop_abort(host, data);
1237+
state = STATE_SENDING_STOP;
1238+
break;
12001239
}
12011240

12021241
if (!host->mrq->data || cmd->error) {
@@ -1211,8 +1250,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
12111250
if (test_and_clear_bit(EVENT_DATA_ERROR,
12121251
&host->pending_events)) {
12131252
dw_mci_stop_dma(host);
1214-
if (data->stop)
1215-
send_stop_cmd(host, data);
1253+
send_stop_abort(host, data);
12161254
state = STATE_DATA_ERROR;
12171255
break;
12181256
}
@@ -1272,7 +1310,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
12721310
data->error = 0;
12731311
}
12741312

1275-
if (!data->stop) {
1313+
if (!data->stop && !data->error) {
12761314
dw_mci_request_end(host, host->mrq);
12771315
goto unlock;
12781316
}
@@ -1284,8 +1322,10 @@ static void dw_mci_tasklet_func(unsigned long priv)
12841322
}
12851323

12861324
prev_state = state = STATE_SENDING_STOP;
1287-
if (!data->error)
1288-
send_stop_cmd(host, data);
1325+
if (data->stop && !data->error) {
1326+
/* stop command for open-ended transfer*/
1327+
send_stop_abort(host, data);
1328+
}
12891329
/* fall through */
12901330

12911331
case STATE_SENDING_STOP:
@@ -1304,7 +1344,12 @@ static void dw_mci_tasklet_func(unsigned long priv)
13041344

13051345
host->cmd = NULL;
13061346
host->data = NULL;
1307-
dw_mci_command_complete(host, host->mrq->stop);
1347+
1348+
if (host->mrq->stop)
1349+
dw_mci_command_complete(host, host->mrq->stop);
1350+
else
1351+
host->cmd_status = 0;
1352+
13081353
dw_mci_request_end(host, host->mrq);
13091354
goto unlock;
13101355

@@ -1888,11 +1933,10 @@ static void dw_mci_work_routine_card(struct work_struct *work)
18881933
case STATE_DATA_ERROR:
18891934
if (mrq->data->error == -EINPROGRESS)
18901935
mrq->data->error = -ENOMEDIUM;
1891-
if (!mrq->stop)
1892-
break;
18931936
/* fall through */
18941937
case STATE_SENDING_STOP:
1895-
mrq->stop->error = -ENOMEDIUM;
1938+
if (mrq->stop)
1939+
mrq->stop->error = -ENOMEDIUM;
18961940
break;
18971941
}
18981942

‎include/linux/mmc/dw_mmc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LINUX_MMC_DW_MMC_H
1616

1717
#include <linux/scatterlist.h>
18+
#include <linux/mmc/core.h>
1819

1920
#define MAX_MCI_SLOTS 2
2021

@@ -129,6 +130,7 @@ struct dw_mci {
129130
struct mmc_request *mrq;
130131
struct mmc_command *cmd;
131132
struct mmc_data *data;
133+
struct mmc_command stop_abort;
132134
unsigned int prev_blksz;
133135
unsigned char timing;
134136
struct workqueue_struct *card_workqueue;

0 commit comments

Comments
 (0)