From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: patches@linaro.org
Subject: [Qemu-devel] [PATCH 05/10] hw/sd.c: Handle illegal commands in sd_do_command
Date: Sun, 18 Dec 2011 20:37:55 +0000 [thread overview]
Message-ID: <1324240680-26905-6-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1324240680-26905-1-git-send-email-peter.maydell@linaro.org>
Add an extra sd_illegal value to the sd_rsp_type_t enum so that
sd_app_command() and sd_normal_command() can tell sd_do_command()
that the command was illegal. This is needed so we can do things
like reset certain status bits only on receipt of a valid command.
For the moment, just use it to pull out the setting of the
ILLEGAL_COMMAND status bit into sd_do_command().
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/sd.c | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/hw/sd.c b/hw/sd.c
index dd28061..57925af 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -51,6 +51,7 @@ typedef enum {
sd_r6 = 6, /* Published RCA response */
sd_r7, /* Operating voltage */
sd_r1b = -1,
+ sd_illegal = -2,
} sd_rsp_type_t;
struct SDState {
@@ -679,8 +680,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
break;
case 5: /* CMD5: reserved for SDIO cards */
- sd->card_status |= ILLEGAL_COMMAND;
- return sd_r0;
+ return sd_illegal;
case 6: /* CMD6: SWITCH_FUNCTION */
if (sd->spi)
@@ -1115,8 +1115,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
* on stderr, as some OSes may use these in their
* probing for presence of an SDIO card.
*/
- sd->card_status |= ILLEGAL_COMMAND;
- return sd_r0;
+ return sd_illegal;
/* Application specific commands (Class 8) */
case 55: /* CMD55: APP_CMD */
@@ -1145,21 +1144,17 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
default:
bad_cmd:
- sd->card_status |= ILLEGAL_COMMAND;
-
fprintf(stderr, "SD: Unknown CMD%i\n", req.cmd);
- return sd_r0;
+ return sd_illegal;
unimplemented_cmd:
/* Commands that are recognised but not yet implemented in SPI mode. */
- sd->card_status |= ILLEGAL_COMMAND;
fprintf(stderr, "SD: CMD%i not implemented in SPI mode\n", req.cmd);
- return sd_r0;
+ return sd_illegal;
}
- sd->card_status |= ILLEGAL_COMMAND;
fprintf(stderr, "SD: CMD%i in a wrong state\n", req.cmd);
- return sd_r0;
+ return sd_illegal;
}
static sd_rsp_type_t sd_app_command(SDState *sd,
@@ -1321,6 +1316,10 @@ int sd_do_command(SDState *sd, SDRequest *req,
} else
rtype = sd_normal_command(sd, *req);
+ if (rtype == sd_illegal) {
+ sd->card_status |= ILLEGAL_COMMAND;
+ }
+
sd->current_cmd = req->cmd;
switch (rtype) {
@@ -1356,14 +1355,12 @@ int sd_do_command(SDState *sd, SDRequest *req,
break;
case sd_r0:
+ case sd_illegal:
default:
rsplen = 0;
break;
}
- if (sd->card_status & ILLEGAL_COMMAND)
- rsplen = 0;
-
#ifdef DEBUG_SD
if (rsplen) {
int i;
--
1.7.5.4
next prev parent reply other threads:[~2011-12-18 20:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-18 20:37 [Qemu-devel] [PATCH 00/10] hw/sd.c: Fix various status related bugs Peter Maydell
2011-12-18 20:37 ` [Qemu-devel] [PATCH 01/10] hw/sd.c: Fix the set of commands which are failed when card is locked Peter Maydell
2011-12-18 20:37 ` [Qemu-devel] [PATCH 02/10] hw/sd.c: Add comment regarding CARD_STATUS_* defines Peter Maydell
2011-12-18 20:37 ` [Qemu-devel] [PATCH 03/10] hw/sd.c: On CRC error, set CRC error status bit rather than clearing it Peter Maydell
2011-12-18 20:37 ` [Qemu-devel] [PATCH 04/10] hw/sd.c: When setting ADDRESS_ERROR bit, don't clear everything else Peter Maydell
2011-12-18 20:37 ` Peter Maydell [this message]
2011-12-18 20:37 ` [Qemu-devel] [PATCH 06/10] hw/sd.c: Handle CRC and locked-card errors in normal code path Peter Maydell
2011-12-18 20:37 ` [Qemu-devel] [PATCH 07/10] hw/sd.c: Set ILLEGAL_COMMAND for ACMDs in invalid state Peter Maydell
2011-12-18 20:37 ` [Qemu-devel] [PATCH 08/10] hw/sd.c: Correct handling of type B SD status bits Peter Maydell
2011-12-18 20:37 ` [Qemu-devel] [PATCH 09/10] hw/sd.c: Correct handling of APP_CMD status bit Peter Maydell
2011-12-18 20:38 ` [Qemu-devel] [PATCH 10/10] hw/sd.c: Clear status bits when read via response r6 Peter Maydell
2011-12-21 3:54 ` [Qemu-devel] [PATCH 00/10] hw/sd.c: Fix various status related bugs andrzej zaborowski
2011-12-21 11:13 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1324240680-26905-6-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=patches@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).