From nobody Tue Oct 28 12:37:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515015703448251.46395373192126; Wed, 3 Jan 2018 13:41:43 -0800 (PST) Received: from localhost ([::1]:37827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWqn8-0007fQ-LU for importer@patchew.org; Wed, 03 Jan 2018 16:41:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWqY7-000369-6c for qemu-devel@nongnu.org; Wed, 03 Jan 2018 16:26:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWqXy-0008P1-2D for qemu-devel@nongnu.org; Wed, 03 Jan 2018 16:26:11 -0500 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:42575) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eWqXx-0008Oa-Ol for qemu-devel@nongnu.org; Wed, 03 Jan 2018 16:26:01 -0500 Received: by mail-qk0-x244.google.com with SMTP id d202so3245064qkc.9 for ; Wed, 03 Jan 2018 13:26:01 -0800 (PST) Received: from x1.lan ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id a19sm1104402qtj.74.2018.01.03.13.25.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jan 2018 13:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0J4HA4l8dSKVXaK7FHJLAVL8cfHPn0jM2MF9wuS3FLc=; b=SKKeipz6XYsAh5DGL6TX7dz03x4h3AjQBaSe0s2OSlm3ZIGMrEEiXfNv5p6/GiBSzi sHQKS4sNDeMkEYMS0e+OYc3WTrYY1d5bjwZ0A44mNUoqyO43kVho3KKbN+GRbIFWnQBv QvNIGqsywAdKgztTwQ1LrfNQcaEUzFDJlOvuJZ9qsOiFdlz+kmh5jMProkgnr/wzGMiv DvXEMuAWAXQRChtY8y9X2YFQ+n9NiLoFALQNolzkIf5mryOTHoF5Wr3CtJFTcfBGOEsJ f7778N+1Us+CSfxVdnMYb9P8HTThGxNJ/e8aOkskFFZI3QOL2x3TCuJvwfCxVStikqgJ syYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=0J4HA4l8dSKVXaK7FHJLAVL8cfHPn0jM2MF9wuS3FLc=; b=PoKNInCbTLhhv2Q75k7mM6SpIjWjpFhmiexx5d1nk7dBYXPWT3LhiuA3rrO+Tb0N+9 vbtp6G4iqSffGdL1aCCDGhjzWtR2VwYEFhOHiRm+n1sVGiWjNUuNP+Zn57nu9ZOYRukl zDzP2YNxc9Ltv/PmNeSpPspY16L/tFUNsP6+8+LTSaaSfsv10cBH6QxjWLfykskJi8B8 /QxAQNbnQuUXx9WXF9nfcLtZ+EX9VR91crK1Sz0v8RjJAmw273+JfBK+MTb5rRvti6jM 0zbPMAWZ0hcr/gSUJ5kjxma5DuJtcAmOYkL6sU2iFJVcH1g+PLGGqZzqw6bxL9YgG+BD FudQ== X-Gm-Message-State: AKGB3mL3DXiJvgTDaSpoYkkkUES/6ox8lLcYgr7v9/z3C3F/6gd3mEhM YVS5zpl946xYxOqr2vFUYvs= X-Google-Smtp-Source: ACJfBou5KaTb37SjdSgwx+gJYM85If+fFZyY8M5lZD4LlFsbpqEPw+CQSamBc95tD1sg7e78kV2afg== X-Received: by 10.55.22.131 with SMTP id 3mr3717710qkw.22.1515014761250; Wed, 03 Jan 2018 13:26:01 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Alistair Francis , Peter Maydell , Igor Mitsyanko , Andrew Baumann , Olbrich , Andrzej Zaborowski Date: Wed, 3 Jan 2018 18:24:28 -0300 Message-Id: <20180103212436.15762-18-f4bug@amsat.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180103212436.15762-1-f4bug@amsat.org> References: <20180103212436.15762-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::244 Subject: [Qemu-devel] [RFC PATCH v2 17/25] sdcard: fix SPI response length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Edgar E . Iglesias" , Prasad J Pandit , Peter Crosthwaite , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Paul Brook , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 SPI response are often shorter than SD/MMC protocols. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index a8198ecce9..024a9fa1df 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -466,29 +466,59 @@ static size_t sd_response_r1_make(SDState *sd, uint8_= t *response) /* Clear the "clear on read" status bits */ sd->card_status &=3D ~CARD_STATUS_C; =20 - response[0] =3D (status >> 24) & 0xff; - response[1] =3D (status >> 16) & 0xff; - response[2] =3D (status >> 8) & 0xff; - response[3] =3D (status >> 0) & 0xff; + if (sd->spi) { + response[0] =3D 0xff; /* XXX */ + return 1; + } else { + response[0] =3D (status >> 24) & 0xff; + response[1] =3D (status >> 16) & 0xff; + response[2] =3D (status >> 8) & 0xff; + response[3] =3D (status >> 0) & 0xff; + return 4; + } +} + +static size_t sd_response_r1b_make(SDState *sd, uint8_t *response) +{ + /* This response token is identical to the R1 format with the + * optional addition of the busy signal. */ + if (sd->spi) { + /* The busy signal token can be any number of bytes. A zero value + * indicates card is busy. A non-zero value indicates the card is + * ready for the next command. */ + size_t sz =3D sd_response_r1_make(sd, response); + + response[sz++] =3D 0x42; =20 - return 4; + return sz; + } + return sd_response_r1_make(sd, response); } =20 static size_t sd_response_r2s_make(SDState *sd, uint8_t *response) { - memcpy(response, sd->csd, sizeof(sd->csd)); - - return 16; + if (sd->spi) { + /* TODO */ + return 2; + } else { + memcpy(response, sd->csd, sizeof(sd->csd)); + return 16; + } } =20 static size_t sd_response_r3_make(SDState *sd, uint8_t *response) { - response[0] =3D (sd->ocr >> 24) & 0xff; - response[1] =3D (sd->ocr >> 16) & 0xff; - response[2] =3D (sd->ocr >> 8) & 0xff; - response[3] =3D (sd->ocr >> 0) & 0xff; + int ofs =3D 0; + + if (sd->spi) { + ofs +=3D sd_response_r1_make(sd, response); + } + response[ofs++] =3D (sd->ocr >> 24) & 0xff; + response[ofs++] =3D (sd->ocr >> 16) & 0xff; + response[ofs++] =3D (sd->ocr >> 8) & 0xff; + response[ofs++] =3D (sd->ocr >> 0) & 0xff; =20 - return 4; + return ofs; } =20 static void sd_response_r6_make(SDState *sd, uint8_t *response) @@ -1249,7 +1279,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) *(uint32_t *) sd->data =3D sd_wpbits(sd, req.arg); sd->data_start =3D addr; sd->data_offset =3D 0; - return sd_r1b; + return sd->spi ? sd_r1 : sd_r1b; } break; =20 @@ -1306,9 +1336,11 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, = SDRequest req) =20 /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ - if (sd->rca !=3D rca) - return sd_r0; - + if (!sd->spi) { + if (sd->rca !=3D rca) { + return sd_r0; + } + } sd->expecting_acmd =3D true; sd->card_status |=3D APP_CMD; return sd_r1; @@ -1374,7 +1406,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, SDRe= quest req) sd->state =3D sd_sendingdata_state; sd->data_start =3D 0; sd->data_offset =3D 0; - return sd_r1; + return sd->spi ? sd_r2_s : sd_r1; } break; =20 @@ -1569,10 +1601,13 @@ int sd_do_command(SDState *sd, SDRequest *req, send_response: switch (rtype) { case sd_r1: - case sd_r1b: rsplen =3D sd_response_r1_make(sd, response); break; =20 + case sd_r1b: + rsplen =3D sd_response_r1b_make(sd, response); + break; + case sd_r2_i: memcpy(response, sd->cid, sizeof(sd->cid)); rsplen =3D 16; --=20 2.15.1