linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V4] mmc: Kill block requests if card is removed
@ 2011-12-08  8:35 Sujit Reddy Thumma
  2011-12-08  9:22 ` Adrian Hunter
  0 siblings, 1 reply; 4+ messages in thread
From: Sujit Reddy Thumma @ 2011-12-08  8:35 UTC (permalink / raw)
  To: linux-mmc, adrian.hunter; +Cc: per.lkml, Sujit Reddy Thumma, cjb

Kill block requests when the host realizes that the card is
removed from the slot and is sure that subsequent requests
are bound to fail. Do this silently so that the block
layer doesn't output unnecessary error messages.

Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>

---
Changes in v4:
	- Extra check to make sure no further commands are sent
	in error case when the card is removed.
Changes in v3:
	- Dropped dependency on Per's patch and is now dependent
	on "[PATCH V4] mmc: allow upper layers to determine immediately
	if a card has been removed" by Adrian Hunter.
	- Modified commit text slightly as Adrian has
	implemented his own suggestion in a different patch.

Changes in v2:
	- Changed the implementation with further comments from Adrian
	- Set the card removed flag in bus notifier callbacks
	- This patch is now dependent on patch from Per Forlin:
	http://thread.gmane.org/gmane.linux.kernel.mmc/11128/focus=11211
---
 drivers/mmc/card/block.c |   17 ++++++++++++++++-
 drivers/mmc/card/queue.c |    5 +++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 0c959c9..0cad48a 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -121,6 +121,7 @@ enum mmc_blk_status {
 	MMC_BLK_ABORT,
 	MMC_BLK_DATA_ERR,
 	MMC_BLK_ECC_ERR,
+	MMC_BLK_NOMEDIUM,
 };
 
 module_param(perdev_minors, int, 0444);
@@ -639,6 +640,7 @@ static int get_card_status(struct mmc_card *card, u32 *status, int retries)
 	return err;
 }
 
+#define ERR_NOMEDIUM	3
 #define ERR_RETRY	2
 #define ERR_ABORT	1
 #define ERR_CONTINUE	0
@@ -706,6 +708,9 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
 	u32 status, stop_status = 0;
 	int err, retry;
 
+	if (mmc_card_removed(card))
+		return ERR_NOMEDIUM;
+
 	/*
 	 * Try to get card status which indicates both the card state
 	 * and why there was no response.  If the first attempt fails,
@@ -722,8 +727,12 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
 	}
 
 	/* We couldn't get a response from the card.  Give up. */
-	if (err)
+	if (err) {
+		/* Check if the card is removed */
+		if (mmc_detect_card_removed(card->host))
+			return ERR_NOMEDIUM;
 		return ERR_ABORT;
+	}
 
 	/* Flag ECC errors */
 	if ((status & R1_CARD_ECC_FAILED) ||
@@ -996,6 +1005,8 @@ static int mmc_blk_err_check(struct mmc_card *card,
 			return MMC_BLK_RETRY;
 		case ERR_ABORT:
 			return MMC_BLK_ABORT;
+		case ERR_NOMEDIUM:
+			return MMC_BLK_NOMEDIUM;
 		case ERR_CONTINUE:
 			break;
 		}
@@ -1329,6 +1340,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
 			if (!ret)
 				goto start_new_req;
 			break;
+		case MMC_BLK_NOMEDIUM:
+			goto cmd_abort;
 		}
 
 		if (ret) {
@@ -1345,6 +1358,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
 
  cmd_abort:
 	spin_lock_irq(&md->lock);
+	if (mmc_card_removed(card))
+		req->cmd_flags |= REQ_QUIET;
 	while (ret)
 		ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
 	spin_unlock_irq(&md->lock);
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index dcad59c..2517547 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -29,6 +29,8 @@
  */
 static int mmc_prep_request(struct request_queue *q, struct request *req)
 {
+	struct mmc_queue *mq = q->queuedata;
+
 	/*
 	 * We only like normal block requests and discards.
 	 */
@@ -37,6 +39,9 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
 		return BLKPREP_KILL;
 	}
 
+	if (mq && mmc_card_removed(mq->card))
+		return BLKPREP_KILL;
+
 	req->cmd_flags |= REQ_DONTPREP;
 
 	return BLKPREP_OK;
-- 
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] mmc: Kill block requests if card is removed
  2011-12-08  8:35 [PATCH V4] mmc: Kill block requests if card is removed Sujit Reddy Thumma
@ 2011-12-08  9:22 ` Adrian Hunter
  2011-12-21 11:06   ` Sujit Reddy Thumma
  0 siblings, 1 reply; 4+ messages in thread
From: Adrian Hunter @ 2011-12-08  9:22 UTC (permalink / raw)
  To: Sujit Reddy Thumma; +Cc: linux-mmc, per.lkml, cjb

On 08/12/11 10:35, Sujit Reddy Thumma wrote:
> Kill block requests when the host realizes that the card is
> removed from the slot and is sure that subsequent requests
> are bound to fail. Do this silently so that the block
> layer doesn't output unnecessary error messages.
> 
> Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> 
> ---
> Changes in v4:
> 	- Extra check to make sure no further commands are sent
> 	in error case when the card is removed.
> Changes in v3:
> 	- Dropped dependency on Per's patch and is now dependent
> 	on "[PATCH V4] mmc: allow upper layers to determine immediately
> 	if a card has been removed" by Adrian Hunter.
> 	- Modified commit text slightly as Adrian has
> 	implemented his own suggestion in a different patch.
> 
> Changes in v2:
> 	- Changed the implementation with further comments from Adrian
> 	- Set the card removed flag in bus notifier callbacks
> 	- This patch is now dependent on patch from Per Forlin:
> 	http://thread.gmane.org/gmane.linux.kernel.mmc/11128/focus=11211
> ---
>  drivers/mmc/card/block.c |   17 ++++++++++++++++-
>  drivers/mmc/card/queue.c |    5 +++++
>  2 files changed, 21 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 0c959c9..0cad48a 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -121,6 +121,7 @@ enum mmc_blk_status {
>  	MMC_BLK_ABORT,
>  	MMC_BLK_DATA_ERR,
>  	MMC_BLK_ECC_ERR,
> +	MMC_BLK_NOMEDIUM,
>  };
>  
>  module_param(perdev_minors, int, 0444);
> @@ -639,6 +640,7 @@ static int get_card_status(struct mmc_card *card, u32 *status, int retries)
>  	return err;
>  }
>  
> +#define ERR_NOMEDIUM	3
>  #define ERR_RETRY	2
>  #define ERR_ABORT	1
>  #define ERR_CONTINUE	0
> @@ -706,6 +708,9 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
>  	u32 status, stop_status = 0;
>  	int err, retry;
>  
> +	if (mmc_card_removed(card))
> +		return ERR_NOMEDIUM;
> +
>  	/*
>  	 * Try to get card status which indicates both the card state
>  	 * and why there was no response.  If the first attempt fails,
> @@ -722,8 +727,12 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
>  	}
>  
>  	/* We couldn't get a response from the card.  Give up. */
> -	if (err)
> +	if (err) {
> +		/* Check if the card is removed */
> +		if (mmc_detect_card_removed(card->host))
> +			return ERR_NOMEDIUM;
>  		return ERR_ABORT;
> +	}
>  
>  	/* Flag ECC errors */
>  	if ((status & R1_CARD_ECC_FAILED) ||
> @@ -996,6 +1005,8 @@ static int mmc_blk_err_check(struct mmc_card *card,
>  			return MMC_BLK_RETRY;
>  		case ERR_ABORT:
>  			return MMC_BLK_ABORT;
> +		case ERR_NOMEDIUM:
> +			return MMC_BLK_NOMEDIUM;
>  		case ERR_CONTINUE:
>  			break;
>  		}
> @@ -1329,6 +1340,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
>  			if (!ret)
>  				goto start_new_req;
>  			break;
> +		case MMC_BLK_NOMEDIUM:
> +			goto cmd_abort;
>  		}
>  
>  		if (ret) {
> @@ -1345,6 +1358,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
>  
>   cmd_abort:
>  	spin_lock_irq(&md->lock);
> +	if (mmc_card_removed(card))
> +		req->cmd_flags |= REQ_QUIET;
>  	while (ret)
>  		ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
>  	spin_unlock_irq(&md->lock);
> diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
> index dcad59c..2517547 100644
> --- a/drivers/mmc/card/queue.c
> +++ b/drivers/mmc/card/queue.c
> @@ -29,6 +29,8 @@
>   */
>  static int mmc_prep_request(struct request_queue *q, struct request *req)
>  {
> +	struct mmc_queue *mq = q->queuedata;
> +
>  	/*
>  	 * We only like normal block requests and discards.
>  	 */
> @@ -37,6 +39,9 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
>  		return BLKPREP_KILL;
>  	}
>  
> +	if (mq && mmc_card_removed(mq->card))
> +		return BLKPREP_KILL;
> +
>  	req->cmd_flags |= REQ_DONTPREP;
>  
>  	return BLKPREP_OK;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] mmc: Kill block requests if card is removed
  2011-12-08  9:22 ` Adrian Hunter
@ 2011-12-21 11:06   ` Sujit Reddy Thumma
  2011-12-25  1:58     ` Chris Ball
  0 siblings, 1 reply; 4+ messages in thread
From: Sujit Reddy Thumma @ 2011-12-21 11:06 UTC (permalink / raw)
  To: Adrian Hunter, Chris Ball; +Cc: per.lkml, linux-mmc@vger.kernel.org

On 12/8/2011 2:52 PM, Adrian Hunter wrote:
> On 08/12/11 10:35, Sujit Reddy Thumma wrote:
>> Kill block requests when the host realizes that the card is
>> removed from the slot and is sure that subsequent requests
>> are bound to fail. Do this silently so that the block
>> layer doesn't output unnecessary error messages.
>>
>> Signed-off-by: Sujit Reddy Thumma<sthumma@codeaurora.org>
>
> Acked-by: Adrian Hunter<adrian.hunter@intel.com>
>

Thanks Adrian.

Chris can you pull this patch with Adrian's ack?

Thanks,
Sujit

>>
>> ---
>> Changes in v4:
>> 	- Extra check to make sure no further commands are sent
>> 	in error case when the card is removed.
>> Changes in v3:
>> 	- Dropped dependency on Per's patch and is now dependent
>> 	on "[PATCH V4] mmc: allow upper layers to determine immediately
>> 	if a card has been removed" by Adrian Hunter.
>> 	- Modified commit text slightly as Adrian has
>> 	implemented his own suggestion in a different patch.
>>
>> Changes in v2:
>> 	- Changed the implementation with further comments from Adrian
>> 	- Set the card removed flag in bus notifier callbacks
>> 	- This patch is now dependent on patch from Per Forlin:
>> 	http://thread.gmane.org/gmane.linux.kernel.mmc/11128/focus=11211
>> ---
>>   drivers/mmc/card/block.c |   17 ++++++++++++++++-
>>   drivers/mmc/card/queue.c |    5 +++++
>>   2 files changed, 21 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>> index 0c959c9..0cad48a 100644
>> --- a/drivers/mmc/card/block.c
>> +++ b/drivers/mmc/card/block.c
>> @@ -121,6 +121,7 @@ enum mmc_blk_status {
>>   	MMC_BLK_ABORT,
>>   	MMC_BLK_DATA_ERR,
>>   	MMC_BLK_ECC_ERR,
>> +	MMC_BLK_NOMEDIUM,
>>   };
>>
>>   module_param(perdev_minors, int, 0444);
>> @@ -639,6 +640,7 @@ static int get_card_status(struct mmc_card *card, u32 *status, int retries)
>>   	return err;
>>   }
>>
>> +#define ERR_NOMEDIUM	3
>>   #define ERR_RETRY	2
>>   #define ERR_ABORT	1
>>   #define ERR_CONTINUE	0
>> @@ -706,6 +708,9 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
>>   	u32 status, stop_status = 0;
>>   	int err, retry;
>>
>> +	if (mmc_card_removed(card))
>> +		return ERR_NOMEDIUM;
>> +
>>   	/*
>>   	 * Try to get card status which indicates both the card state
>>   	 * and why there was no response.  If the first attempt fails,
>> @@ -722,8 +727,12 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
>>   	}
>>
>>   	/* We couldn't get a response from the card.  Give up. */
>> -	if (err)
>> +	if (err) {
>> +		/* Check if the card is removed */
>> +		if (mmc_detect_card_removed(card->host))
>> +			return ERR_NOMEDIUM;
>>   		return ERR_ABORT;
>> +	}
>>
>>   	/* Flag ECC errors */
>>   	if ((status&  R1_CARD_ECC_FAILED) ||
>> @@ -996,6 +1005,8 @@ static int mmc_blk_err_check(struct mmc_card *card,
>>   			return MMC_BLK_RETRY;
>>   		case ERR_ABORT:
>>   			return MMC_BLK_ABORT;
>> +		case ERR_NOMEDIUM:
>> +			return MMC_BLK_NOMEDIUM;
>>   		case ERR_CONTINUE:
>>   			break;
>>   		}
>> @@ -1329,6 +1340,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
>>   			if (!ret)
>>   				goto start_new_req;
>>   			break;
>> +		case MMC_BLK_NOMEDIUM:
>> +			goto cmd_abort;
>>   		}
>>
>>   		if (ret) {
>> @@ -1345,6 +1358,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
>>
>>    cmd_abort:
>>   	spin_lock_irq(&md->lock);
>> +	if (mmc_card_removed(card))
>> +		req->cmd_flags |= REQ_QUIET;
>>   	while (ret)
>>   		ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
>>   	spin_unlock_irq(&md->lock);
>> diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
>> index dcad59c..2517547 100644
>> --- a/drivers/mmc/card/queue.c
>> +++ b/drivers/mmc/card/queue.c
>> @@ -29,6 +29,8 @@
>>    */
>>   static int mmc_prep_request(struct request_queue *q, struct request *req)
>>   {
>> +	struct mmc_queue *mq = q->queuedata;
>> +
>>   	/*
>>   	 * We only like normal block requests and discards.
>>   	 */
>> @@ -37,6 +39,9 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
>>   		return BLKPREP_KILL;
>>   	}
>>
>> +	if (mq&&  mmc_card_removed(mq->card))
>> +		return BLKPREP_KILL;
>> +
>>   	req->cmd_flags |= REQ_DONTPREP;
>>
>>   	return BLKPREP_OK;
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V4] mmc: Kill block requests if card is removed
  2011-12-21 11:06   ` Sujit Reddy Thumma
@ 2011-12-25  1:58     ` Chris Ball
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Ball @ 2011-12-25  1:58 UTC (permalink / raw)
  To: Sujit Reddy Thumma; +Cc: Adrian Hunter, per.lkml, linux-mmc@vger.kernel.org

Hi,

On Wed, Dec 21 2011, Sujit Reddy Thumma wrote:
> On 12/8/2011 2:52 PM, Adrian Hunter wrote:
>> On 08/12/11 10:35, Sujit Reddy Thumma wrote:
>>> Kill block requests when the host realizes that the card is
>>> removed from the slot and is sure that subsequent requests
>>> are bound to fail. Do this silently so that the block
>>> layer doesn't output unnecessary error messages.
>>>
>>> Signed-off-by: Sujit Reddy Thumma<sthumma@codeaurora.org>
>>
>> Acked-by: Adrian Hunter<adrian.hunter@intel.com>
>>
>
> Thanks Adrian.
>
> Chris can you pull this patch with Adrian's ack?

Thanks, pushed to mmc-next for 3.3 with Adrian's ACK.

- Chris.
-- 
Chris Ball   <cjb@laptop.org>   <http://printf.net/>
One Laptop Per Child

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-12-25  1:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-08  8:35 [PATCH V4] mmc: Kill block requests if card is removed Sujit Reddy Thumma
2011-12-08  9:22 ` Adrian Hunter
2011-12-21 11:06   ` Sujit Reddy Thumma
2011-12-25  1:58     ` Chris Ball

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).