public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
* mmc_core: question on mmc_do_erase function
@ 2010-10-12 13:11 Dong, Chuanxiao
  2010-10-13  7:55 ` Adrian Hunter
  0 siblings, 1 reply; 5+ messages in thread
From: Dong, Chuanxiao @ 2010-10-12 13:11 UTC (permalink / raw)
  To: adrian.hunter@nokia.com; +Cc: linux-mmc@vger.kernel.org, Gao, Yunpeng

Hi adrian

I got some questions about MMC driver erase function. Help you can give me some suggestion. My host controller is a kind of SDHCI host controller. And testing below code by using HD micro SD card.
+	memset(&cmd, 0, sizeof(struct mmc_command));
+	cmd.opcode = MMC_ERASE;
+	cmd.arg = arg;
+	cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
+	mmc_set_erase_timeout(card, &cmd, arg, qty);
+	err = mmc_wait_for_cmd(card->host, &cmd, 0);
+	if (err) {
+		printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
+		       err, cmd.resp[0]);
+		err = -EIO;
+		goto out;
+	}
As MMC 4.4 standard said, CMD38 need R1B response. So when SDHCI host controller got a SDHCI_INT_RESPONSE interrupt, driver will ignore this and keep on waiting for a SDHCI_INT_DATA_END interrupt to finish MMC_ERASE command. Then I got problems....My host controller will got a DATA_TIMEOUT interrupt if host controller cannot generate any interrupt during its waiting time, unfortunately the max waiting time for my SDHCI host controller is 5s. So if any ERASE operation need more than 5s seconds to finish, my controller will not finish the ERASE operation and only generate a DATA_TIMEOUT interrupt. The ERASE will be failed. Another, MMC driver also has a 10s timer to keep watch over the interrupt, if ERASE operation need more than 10s to finish, this timer also can report a TIMEOUT error.
I think cmd->erase_timeout can help to set the timer expires, but how to deal with this issue for SDHCI host controller? How about split ERASE groups to be smaller ones?

+	if (mmc_host_is_spi(card->host))
+		goto out;
+
+	do {
+		memset(&cmd, 0, sizeof(struct mmc_command));
+		cmd.opcode = MMC_SEND_STATUS;
+		cmd.arg = card->rca << 16;
+		cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+		/* Do not retry else we can't see errors */
+		err = mmc_wait_for_cmd(card->host, &cmd, 0);
+		if (err || (cmd.resp[0] & 0xFDF92000)) {
+			printk(KERN_ERR "error %d requesting status %#x\n",
+				err, cmd.resp[0]);
+			err = -EIO;
+			goto out;
+		}
+	} while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
+		 R1_CURRENT_STATE(cmd.resp[0]) == 7);
+out:
+	return err;
+}
And can this code guarantee the card will finish the ERASE operation? If it can, what about send CMD38 with R1 response?(although doing this is against with MMC 4.4 standard....)

Best Regards
Chuanxiao Dong


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

* Re: mmc_core: question on mmc_do_erase function
  2010-10-12 13:11 mmc_core: question on mmc_do_erase function Dong, Chuanxiao
@ 2010-10-13  7:55 ` Adrian Hunter
  2010-10-13  8:35   ` Dong, Chuanxiao
  0 siblings, 1 reply; 5+ messages in thread
From: Adrian Hunter @ 2010-10-13  7:55 UTC (permalink / raw)
  To: Dong, Chuanxiao; +Cc: linux-mmc@vger.kernel.org, Gao, Yunpeng

On 12/10/10 16:11, Dong, Chuanxiao wrote:
> Hi adrian
>
> I got some questions about MMC driver erase function. Help you can
> give me some suggestion. My host controller is a kind of SDHCI host
> controller. And testing below code by using HD micro SD card.
> +	memset(&cmd, 0, sizeof(struct mmc_command));
> +	cmd.opcode = MMC_ERASE;
> +	cmd.arg = arg;
> +	cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
> +	mmc_set_erase_timeout(card,&cmd, arg, qty);
> +	err = mmc_wait_for_cmd(card->host,&cmd, 0);
> +	if (err) {
> +		printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
> +		       err, cmd.resp[0]);
> +		err = -EIO;
> +		goto out;
> +	}
> As MMC 4.4 standard said, CMD38 need R1B response. So when SDHCI host
> controller got a SDHCI_INT_RESPONSE interrupt, driver will ignore
> this and keep on waiting for a SDHCI_INT_DATA_END interrupt to finish
> MMC_ERASE command. Then I got problems....My host controller will got
> a DATA_TIMEOUT interrupt if host controller cannot generate any
> interrupt during its waiting time, unfortunately the max waiting time
> for my SDHCI host controller is 5s.

I don't know SDHCI.  Can you disable the timeout altogether and use a
timer?

> So if any ERASE operation need
> more than 5s seconds to finish, my controller will not finish the
> ERASE operation and only generate a DATA_TIMEOUT interrupt. The ERASE
> will be failed. Another, MMC driver also has a 10s timer to keep
> watch over the interrupt, if ERASE operation need more than 10s to
> finish, this timer also can report a TIMEOUT error. I think
> cmd->erase_timeout can help to set the timer expires, but how to deal
> with this issue for SDHCI host controller? How about split ERASE
> groups to be smaller ones?

Where is the erase coming from?  A file system?  The discard ioctl?

It is possible to set a maximum size for the discard but it pays
no attention to alignment, so you can get very sub-optimal erases.

>
> +	if (mmc_host_is_spi(card->host))
> +		goto out;
> +
> +	do {
> +		memset(&cmd, 0, sizeof(struct mmc_command));
> +		cmd.opcode = MMC_SEND_STATUS;
> +		cmd.arg = card->rca<<  16;
> +		cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
> +		/* Do not retry else we can't see errors */
> +		err = mmc_wait_for_cmd(card->host,&cmd, 0);
> +		if (err || (cmd.resp[0]&  0xFDF92000)) {
> +			printk(KERN_ERR "error %d requesting status %#x\n",
> +				err, cmd.resp[0]);
> +			err = -EIO;
> +			goto out;
> +		}
> +	} while (!(cmd.resp[0]&  R1_READY_FOR_DATA) ||
> +		 R1_CURRENT_STATE(cmd.resp[0]) == 7);
> +out:
> +	return err;
> +}
> And can this code guarantee the card will finish the ERASE operation?
> If it can, what about send CMD38 with R1 response?(although doing
> this is against with MMC 4.4 standard....)
>
> Best Regards
> Chuanxiao Dong
>
>


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

* RE: mmc_core: question on mmc_do_erase function
  2010-10-13  7:55 ` Adrian Hunter
@ 2010-10-13  8:35   ` Dong, Chuanxiao
  2010-10-13  8:57     ` Adrian Hunter
  0 siblings, 1 reply; 5+ messages in thread
From: Dong, Chuanxiao @ 2010-10-13  8:35 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: linux-mmc@vger.kernel.org, Gao, Yunpeng

> -----Original Message-----
> From: Adrian Hunter [mailto:adrian.hunter@nokia.com]
> Sent: Wednesday, October 13, 2010 3:56 PM
> To: Dong, Chuanxiao
> Cc: linux-mmc@vger.kernel.org; Gao, Yunpeng
> Subject: Re: mmc_core: question on mmc_do_erase function
> 
> On 12/10/10 16:11, Dong, Chuanxiao wrote:
> > Hi adrian
> >
> > I got some questions about MMC driver erase function. Help you can
> > give me some suggestion. My host controller is a kind of SDHCI host
> > controller. And testing below code by using HD micro SD card.
> > +	memset(&cmd, 0, sizeof(struct mmc_command));
> > +	cmd.opcode = MMC_ERASE;
> > +	cmd.arg = arg;
> > +	cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
> > +	mmc_set_erase_timeout(card,&cmd, arg, qty);
> > +	err = mmc_wait_for_cmd(card->host,&cmd, 0);
> > +	if (err) {
> > +		printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
> > +		       err, cmd.resp[0]);
> > +		err = -EIO;
> > +		goto out;
> > +	}
> > As MMC 4.4 standard said, CMD38 need R1B response. So when SDHCI host
> > controller got a SDHCI_INT_RESPONSE interrupt, driver will ignore
> > this and keep on waiting for a SDHCI_INT_DATA_END interrupt to finish
> > MMC_ERASE command. Then I got problems....My host controller will got
> > a DATA_TIMEOUT interrupt if host controller cannot generate any
> > interrupt during its waiting time, unfortunately the max waiting time
> > for my SDHCI host controller is 5s.
> 
> I don't know SDHCI.  Can you disable the timeout altogether and use a
> timer?
> 
OK, thanks. If hardware can disable the timeout interrupt, I will try use a timer. But if the host controllers cannot disable the their timeout interrupt, what should they do?

> > So if any ERASE operation need
> > more than 5s seconds to finish, my controller will not finish the
> > ERASE operation and only generate a DATA_TIMEOUT interrupt. The ERASE
> > will be failed. Another, MMC driver also has a 10s timer to keep
> > watch over the interrupt, if ERASE operation need more than 10s to
> > finish, this timer also can report a TIMEOUT error. I think
> > cmd->erase_timeout can help to set the timer expires, but how to deal
> > with this issue for SDHCI host controller? How about split ERASE
> > groups to be smaller ones?
> 
> Where is the erase coming from?  A file system?  The discard ioctl?
Erase command comes from the discard ioctl.

> It is possible to set a maximum size for the discard but it pays
> no attention to alignment, so you can get very sub-optimal erases.


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

* Re: mmc_core: question on mmc_do_erase function
  2010-10-13  8:35   ` Dong, Chuanxiao
@ 2010-10-13  8:57     ` Adrian Hunter
  2010-10-13  9:18       ` Dong, Chuanxiao
  0 siblings, 1 reply; 5+ messages in thread
From: Adrian Hunter @ 2010-10-13  8:57 UTC (permalink / raw)
  To: Dong, Chuanxiao; +Cc: linux-mmc@vger.kernel.org, Gao, Yunpeng

On 13/10/10 11:35, Dong, Chuanxiao wrote:
>> -----Original Message-----
>> From: Adrian Hunter [mailto:adrian.hunter@nokia.com]
>> Sent: Wednesday, October 13, 2010 3:56 PM
>> To: Dong, Chuanxiao
>> Cc: linux-mmc@vger.kernel.org; Gao, Yunpeng
>> Subject: Re: mmc_core: question on mmc_do_erase function
>>
>> On 12/10/10 16:11, Dong, Chuanxiao wrote:
>>> Hi adrian
>>>
>>> I got some questions about MMC driver erase function. Help you can
>>> give me some suggestion. My host controller is a kind of SDHCI host
>>> controller. And testing below code by using HD micro SD card.
>>> +	memset(&cmd, 0, sizeof(struct mmc_command));
>>> +	cmd.opcode = MMC_ERASE;
>>> +	cmd.arg = arg;
>>> +	cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
>>> +	mmc_set_erase_timeout(card,&cmd, arg, qty);
>>> +	err = mmc_wait_for_cmd(card->host,&cmd, 0);
>>> +	if (err) {
>>> +		printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
>>> +		       err, cmd.resp[0]);
>>> +		err = -EIO;
>>> +		goto out;
>>> +	}
>>> As MMC 4.4 standard said, CMD38 need R1B response. So when SDHCI host
>>> controller got a SDHCI_INT_RESPONSE interrupt, driver will ignore
>>> this and keep on waiting for a SDHCI_INT_DATA_END interrupt to finish
>>> MMC_ERASE command. Then I got problems....My host controller will got
>>> a DATA_TIMEOUT interrupt if host controller cannot generate any
>>> interrupt during its waiting time, unfortunately the max waiting time
>>> for my SDHCI host controller is 5s.
>>
>> I don't know SDHCI.  Can you disable the timeout altogether and use a
>> timer?
>>
> OK, thanks. If hardware can disable the timeout interrupt, I will try
> use a timer. But if the host controllers cannot disable the their
> timeout interrupt, what should they do?

The block driver currently sets max_discard_sectors to UINT_MAX i.e.
unlimited.  This could instead be based on a value from the driver
in the same way that max_sectors is.  Refer to mmc_init_queue()
in card/queue.c

>
>>> So if any ERASE operation need
>>> more than 5s seconds to finish, my controller will not finish the
>>> ERASE operation and only generate a DATA_TIMEOUT interrupt. The ERASE
>>> will be failed. Another, MMC driver also has a 10s timer to keep
>>> watch over the interrupt, if ERASE operation need more than 10s to
>>> finish, this timer also can report a TIMEOUT error. I think
>>> cmd->erase_timeout can help to set the timer expires, but how to deal
>>> with this issue for SDHCI host controller? How about split ERASE
>>> groups to be smaller ones?
>>
>> Where is the erase coming from?  A file system?  The discard ioctl?
> Erase command comes from the discard ioctl.
>
>> It is possible to set a maximum size for the discard but it pays
>> no attention to alignment, so you can get very sub-optimal erases.
>
>


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

* RE: mmc_core: question on mmc_do_erase function
  2010-10-13  8:57     ` Adrian Hunter
@ 2010-10-13  9:18       ` Dong, Chuanxiao
  0 siblings, 0 replies; 5+ messages in thread
From: Dong, Chuanxiao @ 2010-10-13  9:18 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: linux-mmc@vger.kernel.org, Gao, Yunpeng

> -----Original Message-----
> From: Adrian Hunter [mailto:adrian.hunter@nokia.com]
> Sent: Wednesday, October 13, 2010 4:58 PM
> To: Dong, Chuanxiao
> Cc: linux-mmc@vger.kernel.org; Gao, Yunpeng
> Subject: Re: mmc_core: question on mmc_do_erase function
> 
> On 13/10/10 11:35, Dong, Chuanxiao wrote:
> >> -----Original Message-----
> >> From: Adrian Hunter [mailto:adrian.hunter@nokia.com]
> >> Sent: Wednesday, October 13, 2010 3:56 PM
> >> To: Dong, Chuanxiao
> >> Cc: linux-mmc@vger.kernel.org; Gao, Yunpeng
> >> Subject: Re: mmc_core: question on mmc_do_erase function
> >>
> >> On 12/10/10 16:11, Dong, Chuanxiao wrote:
> >>> Hi adrian
> >>>
> >>> I got some questions about MMC driver erase function. Help you can
> >>> give me some suggestion. My host controller is a kind of SDHCI host
> >>> controller. And testing below code by using HD micro SD card.
> >>> +	memset(&cmd, 0, sizeof(struct mmc_command));
> >>> +	cmd.opcode = MMC_ERASE;
> >>> +	cmd.arg = arg;
> >>> +	cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
> >>> +	mmc_set_erase_timeout(card,&cmd, arg, qty);
> >>> +	err = mmc_wait_for_cmd(card->host,&cmd, 0);
> >>> +	if (err) {
> >>> +		printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
> >>> +		       err, cmd.resp[0]);
> >>> +		err = -EIO;
> >>> +		goto out;
> >>> +	}
> >>> As MMC 4.4 standard said, CMD38 need R1B response. So when SDHCI host
> >>> controller got a SDHCI_INT_RESPONSE interrupt, driver will ignore
> >>> this and keep on waiting for a SDHCI_INT_DATA_END interrupt to finish
> >>> MMC_ERASE command. Then I got problems....My host controller will got
> >>> a DATA_TIMEOUT interrupt if host controller cannot generate any
> >>> interrupt during its waiting time, unfortunately the max waiting time
> >>> for my SDHCI host controller is 5s.
> >>
> >> I don't know SDHCI.  Can you disable the timeout altogether and use a
> >> timer?
> >>
> > OK, thanks. If hardware can disable the timeout interrupt, I will try
> > use a timer. But if the host controllers cannot disable the their
> > timeout interrupt, what should they do?
> 
> The block driver currently sets max_discard_sectors to UINT_MAX i.e.
> unlimited.  This could instead be based on a value from the driver
> in the same way that max_sectors is.  Refer to mmc_init_queue()
> in card/queue.c
OK, thanks for your help, Adrian.

> >
> >>> So if any ERASE operation need
> >>> more than 5s seconds to finish, my controller will not finish the
> >>> ERASE operation and only generate a DATA_TIMEOUT interrupt. The ERASE
> >>> will be failed. Another, MMC driver also has a 10s timer to keep
> >>> watch over the interrupt, if ERASE operation need more than 10s to
> >>> finish, this timer also can report a TIMEOUT error. I think
> >>> cmd->erase_timeout can help to set the timer expires, but how to deal
> >>> with this issue for SDHCI host controller? How about split ERASE
> >>> groups to be smaller ones?
> >>
> >> Where is the erase coming from?  A file system?  The discard ioctl?
> > Erase command comes from the discard ioctl.
> >
> >> It is possible to set a maximum size for the discard but it pays
> >> no attention to alignment, so you can get very sub-optimal erases.
> >
> >


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

end of thread, other threads:[~2010-10-13  9:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-12 13:11 mmc_core: question on mmc_do_erase function Dong, Chuanxiao
2010-10-13  7:55 ` Adrian Hunter
2010-10-13  8:35   ` Dong, Chuanxiao
2010-10-13  8:57     ` Adrian Hunter
2010-10-13  9:18       ` Dong, Chuanxiao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox