qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, Guenter Roeck <linux@roeck-us.net>,
	qemu-riscv@nongnu.org, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
	Bin Meng <bmeng.cn@gmail.com>,
	Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	Weiwei Li <liwei1518@gmail.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	qemu-block@nongnu.org
Subject: Re: [PATCH-for-10.1 1/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected
Date: Tue, 12 Aug 2025 15:27:38 +0200	[thread overview]
Message-ID: <681ecca9-272b-4851-8726-9daf7630b5ac@linaro.org> (raw)
In-Reply-To: <87o6skad76.fsf@draig.linaro.org>

On 12/8/25 15:20, Alex Bennée wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card
>> code") exposed a bug in the SPI adapter: if no SD card is plugged,
>> we shouldn't return any particular packet response, but the noise
>> shifted on the MISO line. Return the dummy byte, otherwise we get:
>>
>>    qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed.
>>
>> Reported-by: Guenter Roeck <linux@roeck-us.net>
>> Fixes: 775616c3ae8 ("Partial SD card SPI mode support")
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/sd/ssi-sd.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
>> index 594dead19ee..3aacbd03871 100644
>> --- a/hw/sd/ssi-sd.c
>> +++ b/hw/sd/ssi-sd.c
>> @@ -89,6 +89,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
>>       SDRequest request;
>>       uint8_t longresp[5];
>>   
>> +    if (!sdbus_get_inserted(&s->sdbus)) {
>> +        return SSI_DUMMY;
>> +    }
>> +
> 
> Seems fair although it's hard to track what is consuming this value. I
> think we end up in ssi_transfer() which a surprising number of calls
> don't even bother checking the return value, other just seem to | the
> result when iterating across devices.

A SPI transaction consists of shifting bit in sync the CLK line,
writing on the MOSI (output) line / and reading MISO (input) line.

IOW, each time you write a word, you also read it at the same time.

When a driver just wants to write, it is OK to ignore the returned
values.

In this case, we don't want to return "There is a card with error"
because there is no card. We shift the request on the MOSI line,
but nothing replies on the MISO line.

Should I reword the commit description?

> 
> We should probably improve on the definitions of transfer/transfer_raw
> and explain what the return value is.

Agreed.

> 
> Anyway:
> 
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

Thanks!


  reply	other threads:[~2025-08-12 13:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 13:51 [PATCH-for-10.1 0/2] hw/sd/ssi-sd: Return noise (dummy byte) when no card connected Philippe Mathieu-Daudé
2025-08-08 13:51 ` [PATCH-for-10.1 1/2] " Philippe Mathieu-Daudé
2025-08-08 20:12   ` Guenter Roeck
2025-08-12 13:20   ` Alex Bennée
2025-08-12 13:27     ` Philippe Mathieu-Daudé [this message]
2025-08-08 13:51 ` [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD " Philippe Mathieu-Daudé
2025-08-12 13:24   ` Alex Bennée
2025-08-12 13:28     ` Philippe Mathieu-Daudé

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=681ecca9-272b-4851-8726-9daf7630b5ac@linaro.org \
    --to=philmd@linaro.org \
    --cc=Alistair.Francis@wdc.com \
    --cc=alex.bennee@linaro.org \
    --cc=bmeng.cn@gmail.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=linux@roeck-us.net \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=zhiwei_liu@linux.alibaba.com \
    /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).