From patchwork Sun Jun 19 21:17:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Per Forlin X-Patchwork-Id: 2063 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2FDEF23E02 for ; Sun, 19 Jun 2011 21:20:15 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id F2C2CA18082 for ; Sun, 19 Jun 2011 21:20:14 +0000 (UTC) Received: by mail-vw0-f52.google.com with SMTP id 16so3010065vws.11 for ; Sun, 19 Jun 2011 14:20:14 -0700 (PDT) Received: by 10.52.98.97 with SMTP id eh1mr6345881vdb.7.1308518414767; Sun, 19 Jun 2011 14:20:14 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs1333vdc; Sun, 19 Jun 2011 14:20:14 -0700 (PDT) Received: by 10.204.101.73 with SMTP id b9mr3492273bko.85.1308518414041; Sun, 19 Jun 2011 14:20:14 -0700 (PDT) Received: from mail-bw0-f50.google.com (mail-bw0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id k28si13663452bku.77.2011.06.19.14.20.12 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 19 Jun 2011 14:20:14 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of per.forlin@linaro.org) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of per.forlin@linaro.org) smtp.mail=per.forlin@linaro.org Received: by mail-bw0-f50.google.com with SMTP id 2so4353466bwz.37 for ; Sun, 19 Jun 2011 14:20:12 -0700 (PDT) Received: by 10.204.36.134 with SMTP id t6mr3279815bkd.57.1308518412613; Sun, 19 Jun 2011 14:20:12 -0700 (PDT) Received: from localhost.localdomain (c-3c7b71d5.029-82-6c756e10.cust.bredbandsbolaget.se [213.113.123.60]) by mx.google.com with ESMTPS id k16sm3870514bks.1.2011.06.19.14.20.11 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 19 Jun 2011 14:20:11 -0700 (PDT) From: Per Forlin To: linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Nicolas Pitre , linaro-dev@lists.linaro.org, Venkatraman S Cc: Chris Ball , Per Forlin Subject: [PATCH v6 08/11] mmc: move error code in mmc_block_issue_rw_rq to a separate function. Date: Sun, 19 Jun 2011 23:17:34 +0200 Message-Id: <1308518257-9783-9-git-send-email-per.forlin@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1308518257-9783-1-git-send-email-per.forlin@linaro.org> References: <1308518257-9783-1-git-send-email-per.forlin@linaro.org> Break out code without functional changes. This simplifies the code and makes way for handle two parallel request. Signed-off-by: Per Forlin --- drivers/mmc/card/block.c | 246 ++++++++++++++++++++++++++------------------- 1 files changed, 142 insertions(+), 104 deletions(-) diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 144d435..6a84a75 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -106,6 +106,13 @@ struct mmc_blk_data { static DEFINE_MUTEX(open_lock); +enum mmc_blk_status { + MMC_BLK_SUCCESS = 0, + MMC_BLK_RETRY, + MMC_BLK_DATA_ERR, + MMC_BLK_CMD_ERR, +}; + module_param(perdev_minors, int, 0444); MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device"); @@ -661,6 +668,112 @@ static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq, } } +static enum mmc_blk_status mmc_blk_err_check(struct mmc_blk_request *brq, + struct request *req, + struct mmc_card *card, + struct mmc_blk_data *md) +{ + struct mmc_command cmd; + u32 status = 0; + enum mmc_blk_status ret = MMC_BLK_SUCCESS; + + /* + * Check for errors here, but don't jump to cmd_err + * until later as we need to wait for the card to leave + * programming mode even when things go wrong. + */ + if (brq->sbc.error || brq->cmd.error || + brq->data.error || brq->stop.error) { + if (brq->data.blocks > 1 && rq_data_dir(req) == READ) { + /* Redo read one sector at a time */ + printk(KERN_WARNING "%s: retrying using single " + "block read\n", req->rq_disk->disk_name); + ret = MMC_BLK_RETRY; + goto out; + } + status = get_card_status(card, req); + } + + if (brq->sbc.error) { + printk(KERN_ERR "%s: error %d sending SET_BLOCK_COUNT " + "command, response %#x, card status %#x\n", + req->rq_disk->disk_name, brq->sbc.error, + brq->sbc.resp[0], status); + } + + if (brq->cmd.error) { + printk(KERN_ERR "%s: error %d sending read/write " + "command, response %#x, card status %#x\n", + req->rq_disk->disk_name, brq->cmd.error, + brq->cmd.resp[0], status); + } + + if (brq->data.error) { + if (brq->data.error == -ETIMEDOUT && brq->mrq.stop) + /* 'Stop' response contains card status */ + status = brq->mrq.stop->resp[0]; + printk(KERN_ERR "%s: error %d transferring data," + " sector %u, nr %u, card status %#x\n", + req->rq_disk->disk_name, brq->data.error, + (unsigned)blk_rq_pos(req), + (unsigned)blk_rq_sectors(req), status); + } + + if (brq->stop.error) { + printk(KERN_ERR "%s: error %d sending stop command, " + "response %#x, card status %#x\n", + req->rq_disk->disk_name, brq->stop.error, + brq->stop.resp[0], status); + } + + if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { + do { + int err; + + cmd.opcode = MMC_SEND_STATUS; + cmd.arg = card->rca << 16; + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; + err = mmc_wait_for_cmd(card->host, &cmd, 5); + if (err) { + printk(KERN_ERR "%s: error %d requesting status\n", + req->rq_disk->disk_name, err); + ret = MMC_BLK_CMD_ERR; + goto out; + } + /* + * Some cards mishandle the status bits, + * so make sure to check both the busy + * indication and the card state. + */ + } while (!(cmd.resp[0] & R1_READY_FOR_DATA) || + (R1_CURRENT_STATE(cmd.resp[0]) == 7)); + +#if 0 + if (cmd.resp[0] & ~0x00000900) + printk(KERN_ERR "%s: status = %08x\n", + req->rq_disk->disk_name, cmd.resp[0]); + if (mmc_decode_status(cmd.resp)) { + ret = MMC_BLK_CMD_ERR; + goto out; + } +#endif + } + + if (brq->cmd.error || brq->stop.error || brq->data.error) { + if (rq_data_dir(req) == READ) + /* + * After an error, we redo I/O one sector at a + * time, so we only reach here after trying to + * read a single sector. + */ + ret = MMC_BLK_DATA_ERR; + else + ret = MMC_BLK_DATA_ERR; + } +out: + return ret; +} + static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, struct mmc_card *card, int disable_multi, @@ -797,119 +910,44 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req) struct mmc_card *card = md->queue.card; struct mmc_blk_request *brq = &mq->mqrq_cur->brq; int ret = 1, disable_multi = 0; - - mmc_claim_host(card->host); + enum mmc_blk_status status; do { - struct mmc_command cmd; - u32 status = 0; - mmc_blk_rw_rq_prep(mq->mqrq_cur, card, disable_multi, mq); mmc_wait_for_req(card->host, &brq->mrq); mmc_queue_bounce_post(mq->mqrq_cur); + status = mmc_blk_err_check(brq, req, card, md); - /* - * Check for errors here, but don't jump to cmd_err - * until later as we need to wait for the card to leave - * programming mode even when things go wrong. - */ - if (brq->sbc.error || brq->cmd.error || - brq->data.error || brq->stop.error) { - if (brq->data.blocks > 1 && rq_data_dir(req) == READ) { - /* Redo read one sector at a time */ - printk(KERN_WARNING "%s: retrying using single " - "block read\n", req->rq_disk->disk_name); - disable_multi = 1; - continue; - } - status = get_card_status(card, req); - } - - if (brq->sbc.error) { - printk(KERN_ERR "%s: error %d sending SET_BLOCK_COUNT " - "command, response %#x, card status %#x\n", - req->rq_disk->disk_name, brq->sbc.error, - brq->sbc.resp[0], status); - } - - if (brq->cmd.error) { - printk(KERN_ERR "%s: error %d sending read/write " - "command, response %#x, card status %#x\n", - req->rq_disk->disk_name, brq->cmd.error, - brq->cmd.resp[0], status); - } - - if (brq->data.error) { - if (brq->data.error == -ETIMEDOUT && brq->mrq.stop) - /* 'Stop' response contains card status */ - status = brq->mrq.stop->resp[0]; - printk(KERN_ERR "%s: error %d transferring data," - " sector %u, nr %u, card status %#x\n", - req->rq_disk->disk_name, brq->data.error, - (unsigned)blk_rq_pos(req), - (unsigned)blk_rq_sectors(req), status); - } - - if (brq->stop.error) { - printk(KERN_ERR "%s: error %d sending stop command, " - "response %#x, card status %#x\n", - req->rq_disk->disk_name, brq->stop.error, - brq->stop.resp[0], status); - } - - if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { - do { - int err; - - cmd.opcode = MMC_SEND_STATUS; - cmd.arg = card->rca << 16; - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; - err = mmc_wait_for_cmd(card->host, &cmd, 5); - if (err) { - printk(KERN_ERR "%s: error %d requesting status\n", - req->rq_disk->disk_name, err); - goto cmd_err; - } - /* - * Some cards mishandle the status bits, - * so make sure to check both the busy - * indication and the card state. - */ - } while (!(cmd.resp[0] & R1_READY_FOR_DATA) || - (R1_CURRENT_STATE(cmd.resp[0]) == 7)); - -#if 0 - if (cmd.resp[0] & ~0x00000900) - printk(KERN_ERR "%s: status = %08x\n", - req->rq_disk->disk_name, cmd.resp[0]); - if (mmc_decode_status(cmd.resp)) - goto cmd_err; -#endif - } - - if (brq->cmd.error || brq->stop.error || brq->data.error) { - if (rq_data_dir(req) == READ) { - /* - * After an error, we redo I/O one sector at a - * time, so we only reach here after trying to - * read a single sector. - */ - spin_lock_irq(&md->lock); - ret = __blk_end_request(req, -EIO, - brq->data.blksz); - spin_unlock_irq(&md->lock); - continue; - } + switch (status) { + case MMC_BLK_CMD_ERR: goto cmd_err; - } + break; + case MMC_BLK_RETRY: + disable_multi = 1; + ret = 1; + break; + case MMC_BLK_DATA_ERR: + /* + * After an error, we redo I/O one sector at a + * time, so we only reach here after trying to + * read a single sector. + */ + spin_lock_irq(&md->lock); + ret = __blk_end_request(req, -EIO, + brq->data.blksz); + spin_unlock_irq(&md->lock); - /* - * A block was successfully transferred. - */ - spin_lock_irq(&md->lock); - ret = __blk_end_request(req, 0, brq->data.bytes_xfered); - spin_unlock_irq(&md->lock); + break; + case MMC_BLK_SUCCESS: + /* + * A block was successfully transferred. + */ + spin_lock_irq(&md->lock); + ret = __blk_end_request(req, 0, brq->data.bytes_xfered); + spin_unlock_irq(&md->lock); + break; + } } while (ret); return 1;