mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 10:57:46 +00:00
mmc: block: add handling for two parallel block requests in issue_rw_rq
Change mmc_blk_issue_rw_rq() to become asynchronous. The execution flow looks like this: * The mmc-queue calls issue_rw_rq(), which sends the request to the host and returns back to the mmc-queue. * The mmc-queue calls issue_rw_rq() again with a new request. * This new request is prepared in issue_rw_rq(), then it waits for the active request to complete before pushing it to the host. * When the mmc-queue is empty it will call issue_rw_rq() with a NULL req to finish off the active request without starting a new request. Signed-off-by: Per Forlin <per.forlin@linaro.org> Acked-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Venkatraman S <svenkatr@ti.com> Tested-by: Sourav Poddar <sourav.poddar@ti.com> Tested-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Chris Ball <cjb@laptop.org>
This commit is contained in:
parent
04296b7bfd
commit
ee8a43a51c
3 changed files with 83 additions and 19 deletions
|
@ -822,12 +822,14 @@ static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
|
||||||
R1_CC_ERROR | /* Card controller error */ \
|
R1_CC_ERROR | /* Card controller error */ \
|
||||||
R1_ERROR) /* General/unknown error */
|
R1_ERROR) /* General/unknown error */
|
||||||
|
|
||||||
int mmc_blk_err_check(struct mmc_blk_request *brq,
|
static int mmc_blk_err_check(struct mmc_card *card,
|
||||||
struct request *req,
|
struct mmc_async_req *areq)
|
||||||
struct mmc_card *card,
|
|
||||||
struct mmc_blk_data *md)
|
|
||||||
{
|
{
|
||||||
int ret = MMC_BLK_SUCCESS;
|
enum mmc_blk_status ret = MMC_BLK_SUCCESS;
|
||||||
|
struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req,
|
||||||
|
mmc_active);
|
||||||
|
struct mmc_blk_request *brq = &mq_mrq->brq;
|
||||||
|
struct request *req = mq_mrq->req;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sbc.error indicates a problem with the set block count
|
* sbc.error indicates a problem with the set block count
|
||||||
|
@ -1038,24 +1040,41 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
|
||||||
brq->data.sg_len = i;
|
brq->data.sg_len = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mqrq->mmc_active.mrq = &brq->mrq;
|
||||||
|
mqrq->mmc_active.err_check = mmc_blk_err_check;
|
||||||
|
|
||||||
mmc_queue_bounce_pre(mqrq);
|
mmc_queue_bounce_pre(mqrq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
|
static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
|
||||||
{
|
{
|
||||||
struct mmc_blk_data *md = mq->data;
|
struct mmc_blk_data *md = mq->data;
|
||||||
struct mmc_card *card = md->queue.card;
|
struct mmc_card *card = md->queue.card;
|
||||||
struct mmc_blk_request *brq = &mq->mqrq_cur->brq;
|
struct mmc_blk_request *brq = &mq->mqrq_cur->brq;
|
||||||
int ret = 1, disable_multi = 0, retry = 0;
|
int ret = 1, disable_multi = 0, retry = 0;
|
||||||
enum mmc_blk_status status;
|
enum mmc_blk_status status;
|
||||||
|
struct mmc_queue_req *mq_rq;
|
||||||
|
struct request *req;
|
||||||
|
struct mmc_async_req *areq;
|
||||||
|
|
||||||
|
if (!rqc && !mq->mqrq_prev->req)
|
||||||
|
return 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
mmc_blk_rw_rq_prep(mq->mqrq_cur, card, disable_multi, mq);
|
if (rqc) {
|
||||||
mmc_wait_for_req(card->host, &brq->mrq);
|
mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
|
||||||
|
areq = &mq->mqrq_cur->mmc_active;
|
||||||
|
} else
|
||||||
|
areq = NULL;
|
||||||
|
areq = mmc_start_req(card->host, areq, (int *) &status);
|
||||||
|
if (!areq)
|
||||||
|
return 0;
|
||||||
|
|
||||||
mmc_queue_bounce_post(mq->mqrq_cur);
|
mq_rq = container_of(areq, struct mmc_queue_req, mmc_active);
|
||||||
|
brq = &mq_rq->brq;
|
||||||
|
req = mq_rq->req;
|
||||||
|
mmc_queue_bounce_post(mq_rq);
|
||||||
|
|
||||||
status = mmc_blk_err_check(brq, req, card, md);
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case MMC_BLK_SUCCESS:
|
case MMC_BLK_SUCCESS:
|
||||||
case MMC_BLK_PARTIAL:
|
case MMC_BLK_PARTIAL:
|
||||||
|
@ -1066,6 +1085,19 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
|
||||||
ret = __blk_end_request(req, 0,
|
ret = __blk_end_request(req, 0,
|
||||||
brq->data.bytes_xfered);
|
brq->data.bytes_xfered);
|
||||||
spin_unlock_irq(&md->lock);
|
spin_unlock_irq(&md->lock);
|
||||||
|
if (status == MMC_BLK_SUCCESS && ret) {
|
||||||
|
/*
|
||||||
|
* The blk_end_request has returned non zero
|
||||||
|
* even though all data is transfered and no
|
||||||
|
* erros returned by host.
|
||||||
|
* If this happen it's a bug.
|
||||||
|
*/
|
||||||
|
printk(KERN_ERR "%s BUG rq_tot %d d_xfer %d\n",
|
||||||
|
__func__, blk_rq_bytes(req),
|
||||||
|
brq->data.bytes_xfered);
|
||||||
|
rqc = NULL;
|
||||||
|
goto cmd_abort;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MMC_BLK_CMD_ERR:
|
case MMC_BLK_CMD_ERR:
|
||||||
goto cmd_err;
|
goto cmd_err;
|
||||||
|
@ -1087,9 +1119,19 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
|
||||||
ret = __blk_end_request(req, -EIO,
|
ret = __blk_end_request(req, -EIO,
|
||||||
brq->data.blksz);
|
brq->data.blksz);
|
||||||
spin_unlock_irq(&md->lock);
|
spin_unlock_irq(&md->lock);
|
||||||
|
if (!ret)
|
||||||
|
goto start_new_req;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
/*
|
||||||
|
* In case of a none complete request
|
||||||
|
* prepare it again and resend.
|
||||||
|
*/
|
||||||
|
mmc_blk_rw_rq_prep(mq_rq, card, disable_multi, mq);
|
||||||
|
mmc_start_req(card->host, &mq_rq->mmc_active, NULL);
|
||||||
|
}
|
||||||
} while (ret);
|
} while (ret);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1124,6 +1166,12 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
|
||||||
ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
|
ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
|
||||||
spin_unlock_irq(&md->lock);
|
spin_unlock_irq(&md->lock);
|
||||||
|
|
||||||
|
start_new_req:
|
||||||
|
if (rqc) {
|
||||||
|
mmc_blk_rw_rq_prep(mq->mqrq_cur, card, 0, mq);
|
||||||
|
mmc_start_req(card->host, &mq->mqrq_cur->mmc_active, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1133,26 +1181,34 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
|
||||||
struct mmc_blk_data *md = mq->data;
|
struct mmc_blk_data *md = mq->data;
|
||||||
struct mmc_card *card = md->queue.card;
|
struct mmc_card *card = md->queue.card;
|
||||||
|
|
||||||
mmc_claim_host(card->host);
|
if (req && !mq->mqrq_prev->req)
|
||||||
|
/* claim host only for the first request */
|
||||||
|
mmc_claim_host(card->host);
|
||||||
|
|
||||||
ret = mmc_blk_part_switch(card, md);
|
ret = mmc_blk_part_switch(card, md);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->cmd_flags & REQ_DISCARD) {
|
if (req && req->cmd_flags & REQ_DISCARD) {
|
||||||
|
/* complete ongoing async transfer before issuing discard */
|
||||||
|
if (card->host->areq)
|
||||||
|
mmc_blk_issue_rw_rq(mq, NULL);
|
||||||
if (req->cmd_flags & REQ_SECURE)
|
if (req->cmd_flags & REQ_SECURE)
|
||||||
ret = mmc_blk_issue_secdiscard_rq(mq, req);
|
ret = mmc_blk_issue_secdiscard_rq(mq, req);
|
||||||
else
|
else
|
||||||
ret = mmc_blk_issue_discard_rq(mq, req);
|
ret = mmc_blk_issue_discard_rq(mq, req);
|
||||||
} else if (req->cmd_flags & REQ_FLUSH) {
|
} else if (req && req->cmd_flags & REQ_FLUSH) {
|
||||||
ret = mmc_blk_issue_flush(mq, req);
|
ret = mmc_blk_issue_flush(mq, req);
|
||||||
} else {
|
} else {
|
||||||
ret = mmc_blk_issue_rw_rq(mq, req);
|
ret = mmc_blk_issue_rw_rq(mq, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
mmc_release_host(card->host);
|
if (!req)
|
||||||
|
/* release host only when there are no more requests */
|
||||||
|
mmc_release_host(card->host);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ static int mmc_queue_thread(void *d)
|
||||||
down(&mq->thread_sem);
|
down(&mq->thread_sem);
|
||||||
do {
|
do {
|
||||||
struct request *req = NULL;
|
struct request *req = NULL;
|
||||||
|
struct mmc_queue_req *tmp;
|
||||||
|
|
||||||
spin_lock_irq(q->queue_lock);
|
spin_lock_irq(q->queue_lock);
|
||||||
set_current_state(TASK_INTERRUPTIBLE);
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
|
@ -59,7 +60,10 @@ static int mmc_queue_thread(void *d)
|
||||||
mq->mqrq_cur->req = req;
|
mq->mqrq_cur->req = req;
|
||||||
spin_unlock_irq(q->queue_lock);
|
spin_unlock_irq(q->queue_lock);
|
||||||
|
|
||||||
if (!req) {
|
if (req || mq->mqrq_prev->req) {
|
||||||
|
set_current_state(TASK_RUNNING);
|
||||||
|
mq->issue_fn(mq, req);
|
||||||
|
} else {
|
||||||
if (kthread_should_stop()) {
|
if (kthread_should_stop()) {
|
||||||
set_current_state(TASK_RUNNING);
|
set_current_state(TASK_RUNNING);
|
||||||
break;
|
break;
|
||||||
|
@ -67,11 +71,14 @@ static int mmc_queue_thread(void *d)
|
||||||
up(&mq->thread_sem);
|
up(&mq->thread_sem);
|
||||||
schedule();
|
schedule();
|
||||||
down(&mq->thread_sem);
|
down(&mq->thread_sem);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
set_current_state(TASK_RUNNING);
|
|
||||||
|
|
||||||
mq->issue_fn(mq, req);
|
/* Current request becomes previous request and vice versa. */
|
||||||
|
mq->mqrq_prev->brq.mrq.data = NULL;
|
||||||
|
mq->mqrq_prev->req = NULL;
|
||||||
|
tmp = mq->mqrq_prev;
|
||||||
|
mq->mqrq_prev = mq->mqrq_cur;
|
||||||
|
mq->mqrq_cur = tmp;
|
||||||
} while (1);
|
} while (1);
|
||||||
up(&mq->thread_sem);
|
up(&mq->thread_sem);
|
||||||
|
|
||||||
|
@ -97,7 +104,7 @@ static void mmc_request(struct request_queue *q)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mq->mqrq_cur->req)
|
if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
|
||||||
wake_up_process(mq->thread);
|
wake_up_process(mq->thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct mmc_queue_req {
|
||||||
char *bounce_buf;
|
char *bounce_buf;
|
||||||
struct scatterlist *bounce_sg;
|
struct scatterlist *bounce_sg;
|
||||||
unsigned int bounce_sg_len;
|
unsigned int bounce_sg_len;
|
||||||
|
struct mmc_async_req mmc_active;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mmc_queue {
|
struct mmc_queue {
|
||||||
|
|
Loading…
Reference in a new issue