From nobody Sun May 19 03:12:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164247347255639.12795532300743; Mon, 17 Jan 2022 18:37:52 -0800 (PST) Received: from localhost ([::1]:57332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n9eNb-0006lA-5N for importer@patchew.org; Mon, 17 Jan 2022 21:37:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n9eL9-0005ml-Vo for qemu-devel@nongnu.org; Mon, 17 Jan 2022 21:35:20 -0500 Received: from [2607:f8b0:4864:20::52e] (port=36674 helo=mail-pg1-x52e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n9eL7-0005pT-FW for qemu-devel@nongnu.org; Mon, 17 Jan 2022 21:35:19 -0500 Received: by mail-pg1-x52e.google.com with SMTP id e9so2042080pgb.3 for ; Mon, 17 Jan 2022 18:35:16 -0800 (PST) Received: from hsinchu16.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id h5sm15037482pfi.46.2022.01.17.18.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jan 2022 18:35:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9VA+CPBaVlIXQJIjd2n3KCqK1vK4vBHKaZ5Iduz6fOo=; b=dqM5mBfGw3+SJnu4Znq/dEl9cBFj5MR/VoslvxINMAHhz3B0n4K+j5H3oTMPtT0CXr hr23Sqgt+tS6dAdueiLBrhvUm4HLhYm14cZTwpv6okMWbH2xQCszftUdJBV44RhUzKZF GmARhip8+jrpkLsfWbYHWdVD/JklVfPTPxXdY9w8JAiTqAQvEmcvjKo+icAef8uYZoi/ SZaZLYTfbsL4Y2TXKEcg6ftFzsVXrKK0Eg07DKz1ir6ttEAIOSIMK7b4LrSDhIB2yHYq b/J8lmUtGv+J4lvotUqH2Cifu84Rsz9jkc46qrelt87tDLZqa5iZXjWtiyvdQS8cfoE8 S4mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9VA+CPBaVlIXQJIjd2n3KCqK1vK4vBHKaZ5Iduz6fOo=; b=GQPOs53oqqxMpTuFs17gnFkGZvtfwUZ6kIw/tXPTJy5Gd7gwuYxX0n/0g+0immoqP5 og1C1LrLjfxKUN+zYS7eZ3N4x9aWNUWn0ZSjyWg0mFDrvEIS8BZTOt7eCtAXTD3JLJsw dJTGPxcoIc2nzwcThsjgKKi2QhGwOOna8e95lmTOoJdBqszHaZaUzaRd9VWjhQaxH5hk /4zZBMMX2IxqFfCpmwZbtDHsL249Ksb2in1XloUHlw9QVpwSiWR/DN3DUArvuKub4DZd X1fS19Hl5WQ+EPApSLulkxeipbayc1LrKkV99VmbhDkP6Lcpwg6LjYYjJhyaGBEFV2/a 6fWA== X-Gm-Message-State: AOAM530it5FVcBjK3XpFgnDsgVJ5IX1ty/GuyVgw+9MIrd/MFQe3yKEZ SUy27ZRaCNTxeNwMs9ybOSimZl8526pth54l X-Google-Smtp-Source: ABdhPJwFTNMq7vuFHJ2SUvWxqf/wyqp6HaxE3DUlLGEcvlVJPidD4BYrpfDoXqiwPyfH7CrS3/EgmA== X-Received: by 2002:a05:6a00:a20:b0:4bb:95f6:93b3 with SMTP id p32-20020a056a000a2000b004bb95f693b3mr23871373pfh.77.1642473315012; Mon, 17 Jan 2022 18:35:15 -0800 (PST) From: frank.chang@sifive.com To: qemu-devel@nongnu.org Subject: [PATCH] hw/sd: Correct the CURRENT_STATE bits in SPI-mode response Date: Tue, 18 Jan 2022 10:35:05 +0800 Message-Id: <20220118023509.14496-1-frank.chang@sifive.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52e (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=frank.chang@sifive.com; helo=mail-pg1-x52e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, Frank Chang , Bin Meng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexander Bulekov , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642473474767100001 Content-Type: text/plain; charset="utf-8" From: Frank Chang In SPI-mode, type B ("cleared on valid command") clear condition is not supported, and as the "In idle state" bit in SPI-mode has type A ("according to current state") clear condition, the CURRENT_STATE bits in an SPI-mode response should be the SD card's state after the command is executed, instead of the state when it received the preceding command. Also, we don't need to clear the type B ("clear on valid command") status bits after the response is updated in SPI-mode. Signed-off-by: Frank Chang --- hw/sd/sd.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index cd67a7bac8..9736b8912d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1757,12 +1757,20 @@ int sd_do_command(SDState *sd, SDRequest *req, if (rtype =3D=3D sd_illegal) { sd->card_status |=3D ILLEGAL_COMMAND; } else { - /* Valid command, we can update the 'state before command' bits. - * (Do this now so they appear in r1 responses.) - */ sd->current_cmd =3D req->cmd; sd->card_status &=3D ~CURRENT_STATE; - sd->card_status |=3D (last_state << 9); + + if (!sd->spi) { + /* Valid command, we can update the 'state before command' bit= s. + * (Do this now so they appear in r1 responses.) + */ + sd->card_status |=3D (last_state << 9); + } else { + /* Type B ("clear on valid command") is not supported + * in SPI-mode. + */ + sd->card_status |=3D (sd->state << 9); + } } =20 send_response: @@ -1808,10 +1816,12 @@ send_response: trace_sdcard_response(sd_response_name(rtype), rsplen); =20 if (rtype !=3D sd_illegal) { - /* Clear the "clear on valid command" status bits now we've - * sent any response - */ - sd->card_status &=3D ~CARD_STATUS_B; + if (!sd->spi) { + /* Clear the "clear on valid command" status bits now we've + * sent any response + */ + sd->card_status &=3D ~CARD_STATUS_B; + } } =20 #ifdef DEBUG_SD --=20 2.31.1