From patchwork Tue Jun 25 05:53:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD60CC41513 for ; Tue, 25 Jun 2024 05:55:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz83-0001bA-Qg; Tue, 25 Jun 2024 01:54:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz82-0001aQ-7z for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:06 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz80-0001Wb-GP for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:05 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-424a2ad06f1so1798535e9.1 for ; Mon, 24 Jun 2024 22:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294843; x=1719899643; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FRec2147tzGGJgDwnAFCM7MdLQrzjYCwJA0fQ2k29gM=; b=lbXzn8zCEM/eFhv9FQbcfblXmtgXwrTwVOnwN/0y0nzt2U0J8Rr1YaQAjKRMaSBX4s zEHh0IUOk2Q4vRDE39zXnoW/g6XoLCR2sZ8OUqakcyI+0MeT/e77ISrl5ChETnyfUupI jwp4YFLhQ0j5QBKcrc0o6nAxegIdE9GtewtkxaSlnD1ATUb4S4LoDhDCQ9dSNGomSFEs o4G0Kqn8MXlPGd6wUquyT+ntBVuiYhGYsloNtKZ+lY5kNtElQWWQ/UZle+F3B1+Xlzxo fNV1a9ego3cYth8kOwr7dxhCH7P0dsB2pVOIpCBRiYgu/j2QXaJm2BPqd2ys62WcWOVc PhAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294843; x=1719899643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FRec2147tzGGJgDwnAFCM7MdLQrzjYCwJA0fQ2k29gM=; b=F9jDbat2ooKc60dqo26UA2BJEAwEp7nD3IRsrODrK25E/SyxPnV9bON5oEY+OzK0Lr oZO9kRmFFx3g98h9dL2isUSdMGbPjqLogLEd5gHMjI24wR+y3BVVcR8nMiqnz8brfHEq ue1PxtTJNtqR/4Om1MsZ2zMb6DmoZop8d6ySj2ONs3fqiXa2ICcsXqWJ/hjtsOx9JoaQ GnRhCtbmGwTkn2N8am/5G1VvdDnO0EZT345ytthExQY+qgF3+Kon8VjBjIfvp3oB3LGA MJuLwG3+WasmGh1Zy6YRINlIdYOzCkD1fFeGE+9/jpw47ygnKMP1PLcVYItViEVe8d1G 38yA== X-Gm-Message-State: AOJu0Yz4PeIP4HYjvcZx6o7P38K4r//gV7AaisesmN1uShBFAqbqpqiK jybN4deIPAMPnrTZe9n9UMH2epSkxok2oAQS6rJqPU8rx7gFgef5at+rHlPTSZf9qK5zj03bWWG 0 X-Google-Smtp-Source: AGHT+IGjpxv8iQ5xIystXJEUsQL/JE9wFc/LepnYZUbDyhJjLg2KVeXtDurTLf42/0131WswwlFmsQ== X-Received: by 2002:a05:600c:3c91:b0:424:8fe1:41f9 with SMTP id 5b1f17b1804b1-4248fe14320mr36673165e9.11.1719294842831; Mon, 24 Jun 2024 22:54:02 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424a49d6112sm4561375e9.6.2024.06.24.22.54.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:02 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng , Hao Wu , Shengtan Mao , Tyrone Ting Subject: [PATCH v2 01/12] tests/qtest: Disable npcm7xx_sdhci tests using hardcoded RCA Date: Tue, 25 Jun 2024 07:53:42 +0200 Message-ID: <20240625055354.23273-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Disable tests using 0x4567 hardcoded RCA otherwise when using random RCA we get: ERROR:../../tests/qtest/npcm7xx_sdhci-test.c:69:write_sdread: assertion failed: (ret == len) not ok /arm/npcm7xx_sdhci/read_sd - ERROR:../../tests/qtest/npcm7xx_sdhci-test.c:69:write_sdread: assertion failed: (ret == len) Bail out! See https://lore.kernel.org/qemu-devel/37f83be9-deb5-42a1-b704-14984351d803@linaro.org/ Signed-off-by: Philippe Mathieu-Daudé --- Cc: Hao Wu Cc: Shengtan Mao Cc: Tyrone Ting --- tests/qtest/npcm7xx_sdhci-test.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/qtest/npcm7xx_sdhci-test.c b/tests/qtest/npcm7xx_sdhci-test.c index 5d68540e52..6a42b142ad 100644 --- a/tests/qtest/npcm7xx_sdhci-test.c +++ b/tests/qtest/npcm7xx_sdhci-test.c @@ -44,6 +44,7 @@ static QTestState *setup_sd_card(void) sdhci_cmd_regs(qts, NPCM7XX_MMC_BA, 0, 0, 0x41200000, 0, (41 << 8)); sdhci_cmd_regs(qts, NPCM7XX_MMC_BA, 0, 0, 0, 0, SDHC_ALL_SEND_CID); sdhci_cmd_regs(qts, NPCM7XX_MMC_BA, 0, 0, 0, 0, SDHC_SEND_RELATIVE_ADDR); + g_test_skip("hardcoded 0x4567 card address"); sdhci_cmd_regs(qts, NPCM7XX_MMC_BA, 0, 0, 0x45670000, 0, SDHC_SELECT_DESELECT_CARD); @@ -76,6 +77,9 @@ static void test_read_sd(void) { QTestState *qts = setup_sd_card(); + g_test_skip("hardcoded 0x4567 card address used in setup_sd_card()"); + return; + write_sdread(qts, "hello world"); write_sdread(qts, "goodbye"); @@ -108,6 +112,9 @@ static void test_write_sd(void) { QTestState *qts = setup_sd_card(); + g_test_skip("hardcoded 0x4567 card address used in setup_sd_card()"); + return; + sdwrite_read(qts, "hello world"); sdwrite_read(qts, "goodbye"); From patchwork Tue Jun 25 05:53:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 938A8C3064D for ; Tue, 25 Jun 2024 05:55:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8A-0001cL-CF; Tue, 25 Jun 2024 01:54:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz88-0001bY-0N for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:12 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz86-0001Yw-El for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:11 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-52cdd03d6aaso2934485e87.0 for ; Mon, 24 Jun 2024 22:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294848; x=1719899648; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MsF8niTdQH3Vk+tuBHzzhdAif0xIcoOBVyM8lpmJF7M=; b=Ons9rj7YfM1tfAl1ZK0cfaA9xpYUfWSjT13aoDvi/whcoiglKyLplYWCtNgMXKj8df fpU+4XJzmpjfSpsDUNlnBONaP1Rbwcz652iJxLjlC8US9PWi/MLxvUHQyZIyg4m/cCwq HknRNt7TPytOZFvQttx8m6NgOCIeemxO9A5juuzLGzcjBKiFiCSlpMSq6xNwIi2ebnBI Cq2phsfgluMSh5htyZHGlruBYd5rAQNCn+0J5TNAeUQj45KC4ZnM067ZMkLPbvh14tLz Nxx9hrHBbP17+lxHVgpIdTSCmuApPGoNoWsfH1zFx7e+R7pZymBHGVa9gl7c6Sl8Bjop yfQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294848; x=1719899648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MsF8niTdQH3Vk+tuBHzzhdAif0xIcoOBVyM8lpmJF7M=; b=JO8tK69Bqra2pEGviOp+iE2jWzlKXL214+K2BVWkMjEvD4no/MX76KoVKSt9xFJxwL VEcN+AZ20qlDs3zXPSTXmSUDwmPDDTdcaPMCwHmXhIkAnz4EDNEUaCETdqic4G6L90gl P7Shpcdz43uL33xXHvXn4u0FLYlW8xpufnhqZ2kAgeuHHPvtD1dr0K/Spn/zGV8hwsps PSG0D/QXqPQ9VNwzQBLU1remeDl4yR7y2DohKPtjLHU0kATnk5s+jBaRlJ44KHYYrq2b +jHTpVw9uBcTipjrVXLgiUqa23PGjtNyGflx2T4guprhh446StIYDWI256kNlY+N4Srw R2MQ== X-Gm-Message-State: AOJu0YyQTRD0X5EnlVyfCwK+Gujjxx/EU960VRw8fT7Ew8dMAuGWcFj3 zUcCNVkUNYqRcE+zhYrc0laMKq+C5yfM0kzDPkzZR/+1Bbw/WMVc/DrerC+0BVxsYRVyCgAo6ZY e X-Google-Smtp-Source: AGHT+IGvqlpcBAAgPCq2HKYN0WZCmyEAd/sYOAR+YRP8vYT3iViMv0GadfmQ5K+XVux0OqzR+kR1Tg== X-Received: by 2002:a05:6512:3e0c:b0:52c:89b5:27bc with SMTP id 2adb3069b0e04-52ce0673582mr4629523e87.42.1719294848316; Mon, 24 Jun 2024 22:54:08 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4248191fac8sm156993215e9.42.2024.06.24.22.54.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:07 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 02/12] hw/sd/sdcard: Generate random RCA value Date: Tue, 25 Jun 2024 07:53:43 +0200 Message-ID: <20240625055354.23273-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=philmd@linaro.org; helo=mail-lf1-x136.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Rather than using the obscure 0x4567 magic value, use a real random one. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater --- hw/sd/sd.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index a48010cfc1..ec58c5e2a6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -46,6 +46,7 @@ #include "qemu/error-report.h" #include "qemu/timer.h" #include "qemu/log.h" +#include "qemu/guest-random.h" #include "qemu/module.h" #include "sdmmc-internal.h" #include "trace.h" @@ -490,11 +491,6 @@ static void sd_set_csd(SDState *sd, uint64_t size) /* Relative Card Address register */ -static void sd_set_rca(SDState *sd) -{ - sd->rca += 0x4567; -} - static uint16_t sd_req_get_rca(SDState *s, SDRequest req) { if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc) { @@ -1107,7 +1103,7 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) case sd_identification_state: case sd_standby_state: sd->state = sd_standby_state; - sd_set_rca(sd); + qemu_guest_getrandom_nofail(&sd->rca, sizeof(sd->rca)); return sd_r6; default: From patchwork Tue Jun 25 05:53:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3BD4C30659 for ; Tue, 25 Jun 2024 05:55:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8F-0001dO-0a; Tue, 25 Jun 2024 01:54:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8D-0001cR-2q for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:17 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8B-0001Zn-Hb for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:16 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-424720e73e1so42223355e9.1 for ; Mon, 24 Jun 2024 22:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294854; x=1719899654; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+Dw7TbCqvf3FA5r7Q8Kk2fU8m/vY/FUcBZ3OzTc5F+s=; b=GMg2j5T+iuAn33zVveDz8E0MOwz3R5bgqXy3vVap0o62HLsN48KXttFPRLoVLZSUul ivGdt8fSmxfGyIp0udlgFDCEV3unvIPZMUDQdZP5zGKJpPTk31ZpSAaZJ1sicfemxJYc JkhrtvOulzloU2Onc9gb9/mjh3jOwn1zXMP5yxI7fTIrftiBS5bD0Wp5KlaUYXUgxigj yM7jC9Upmv+Hb6JAmR+ioRjYdeFbYpQcmKf0wC8muejCeqYHRmyccJMWYJBfZjyqlcxG 36sKdp76QohsJyOyDxnGYO/erBzNHDmpzRFwaAYPjh/G024AkOsWvWCgS9tYQqZ/EPwH D1pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294854; x=1719899654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Dw7TbCqvf3FA5r7Q8Kk2fU8m/vY/FUcBZ3OzTc5F+s=; b=uJdGIUCITS9JzulK8+HrReizvAL1oxfQIS2Nv+qlDyS+KAAWvHF6WdoRVeTi/88uA5 /kqSf942C8Ec+vaKLRswqlgPmmDOFWgRvO0PIOAskODpqzv83Cbh3BAGVAxnI7r2511B Y9D9Rmt4o/Bx6niNt8ykMtCNzo0/b17BvVoBHsWAZblMhHkQpujmWlBDl8/+nxSXKsoA xPaAcpc9umQzh2WXqTTUkYlw5ZcplsAcbEA8Q+rbi6h+NuKOwklg1gUDeQdnsjI5RYdR H7W/twG12VTOFD8AvwWz+mqmZRNkMhh0xlWraZpbX4XeCkpYGeP/YE+MwwC1QprSqts5 qGqA== X-Gm-Message-State: AOJu0Yw0XW6ePdd8UkBBqmdIT6d6NWvbX27gyO451wi94VKDM3Qm+Sz0 6LWfc9R7ZsH2Y+HeM3u+eCeJs9MVyhbPlkRHQ4bIYZ7v7kPH13PWAC6wOYrFOwFXwk0lK6/M99F c X-Google-Smtp-Source: AGHT+IEI8xOUGeZGlT9TyChqUUcjFvnX3GyPQxcmgCZc27chblJKDReheB16/IsA16iqACR+edGizQ== X-Received: by 2002:a05:600c:2d05:b0:421:82ed:28d1 with SMTP id 5b1f17b1804b1-4248cc73e25mr42975115e9.41.1719294853895; Mon, 24 Jun 2024 22:54:13 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3666dc46d50sm11549452f8f.67.2024.06.24.22.54.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:13 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 03/12] hw/sd/sdcard: Track last command used to help logging Date: Tue, 25 Jun 2024 07:53:44 +0200 Message-ID: <20240625055354.23273-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The command is selected on the I/O lines, and further processing might be done on the DAT lines via the sd_read_byte() and sd_write_byte() handlers. Since these methods can't distinct between normal and APP commands, keep the name of the current command in the SDState and use it in the DAT handlers. This fixes a bug that all normal commands were displayed as APP commands. Fixes: 2ed61fb57b ("sdcard: Display command name when tracing CMD/ACMD") Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater --- hw/sd/sd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ec58c5e2a6..14bfcc5d6b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -134,6 +134,7 @@ struct SDState { uint32_t pwd_len; uint8_t function_group[6]; uint8_t current_cmd; + const char *last_cmd_name; /* True if we will handle the next command as an ACMD. Note that this does * *not* track the APP_CMD status bit! */ @@ -1150,12 +1151,13 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) uint16_t rca; uint64_t addr; + sd->last_cmd_name = sd_cmd_name(req.cmd); /* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular case. */ if (req.cmd != 55 || sd->expecting_acmd) { trace_sdcard_normal_command(sd_proto(sd)->name, - sd_cmd_name(req.cmd), req.cmd, + sd->last_cmd_name, req.cmd, req.arg, sd_state_name(sd->state)); } @@ -1616,7 +1618,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { - trace_sdcard_app_command(sd_proto(sd)->name, sd_acmd_name(req.cmd), + sd->last_cmd_name = sd_acmd_name(req.cmd); + trace_sdcard_app_command(sd_proto(sd)->name, sd->last_cmd_name, req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |= APP_CMD; @@ -1909,7 +1912,7 @@ void sd_write_byte(SDState *sd, uint8_t value) return; trace_sdcard_write_data(sd_proto(sd)->name, - sd_acmd_name(sd->current_cmd), + sd->last_cmd_name, sd->current_cmd, value); switch (sd->current_cmd) { case 24: /* CMD24: WRITE_SINGLE_BLOCK */ @@ -2065,7 +2068,7 @@ uint8_t sd_read_byte(SDState *sd) io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; trace_sdcard_read_data(sd_proto(sd)->name, - sd_acmd_name(sd->current_cmd), + sd->last_cmd_name, sd->current_cmd, io_len); switch (sd->current_cmd) { case 6: /* CMD6: SWITCH_FUNCTION */ @@ -2210,6 +2213,7 @@ static void sd_instance_init(Object *obj) { SDState *sd = SD_CARD(obj); + sd->last_cmd_name = "UNSET"; sd->enable = true; sd->ocr_power_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sd_ocr_powerup, sd); } From patchwork Tue Jun 25 05:53:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41E53C2BBCA for ; Tue, 25 Jun 2024 05:56:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8K-0001ek-C5; Tue, 25 Jun 2024 01:54:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8I-0001dx-UU for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:22 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8H-0001am-FD for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:22 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42172ed3597so29971895e9.0 for ; Mon, 24 Jun 2024 22:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294859; x=1719899659; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QasiI5Og3o+xZHl0uXbjz82y8xzUq9DKLys9TXhovwY=; b=B+fGnjib6o/XAH2VhPr4Lw38NqLOqdkWhpfNVqwvZLcyI/5jxfvmOyQ7mWxen7la36 S2B/Qr09hyXOgXH5/JFY/omSaEjJNfxeju3DquYWqBwBLCHHJREtfCuW/Rkh5NQR75mK X4XkYA71u8PgKHg29r0f6NmFqg0W8r7iVjTUbB3ETpEFP1C0q/gHr/3IT8n5Xsyqqfa1 iTtHHNFkX3UfNXblN7DrNRnb8BPGKDwYdOx+isiVz3k9tV18dcvyra1mgcye/oSMVxGF yUb52XPWwoyOx447vvcOwXjAp51TwEDRXeMgemUh3WAk0ulMYzcllnT/imJIeFoOQp16 8TaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294859; x=1719899659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QasiI5Og3o+xZHl0uXbjz82y8xzUq9DKLys9TXhovwY=; b=kna4C42r0RP1634s+pXovDzzRFZ0IiO2fUz6PmJItegpYppkKMsL6MluhrXYmxUOEG rIJh48PMDv2Y6yp6JyLUFmwZ4F2HAkUwSRdAgPUjyX2kbv8Sia0nKkz1b1PBCqRA+y4L 0n4Lb81SqfS+B5qxASfGgArPuycfkHcwOM3kmsaqM/Njez/u5202sCWsrl/gUvxaowL2 EEYkiA7oij2MI/b+PaaUVrt3TzdKfVlUKqvgJEb/NEf2qjPY+QlxbryW40vgBrnLVR54 PN6lER7Qv1UZbUojKBAk2HXp8w2CGr2Q3gPNVCkr5BAGrWz0rUXNSXUlru14/6yg19A/ G/oA== X-Gm-Message-State: AOJu0Ywc9T2j2Rx9kb10lqn3YysaeDbSgvqgZKdXwPxg0o3YuGG9wvw9 Kpyb3b3MNRoSybHKxPd7T1yOQtfJAiQk/pWqTgYE4VcZOI9V2gkjTyAUxLTiwKwozlEKHf5ddAg q X-Google-Smtp-Source: AGHT+IGJ2iGh40wc+Wrh3XkSL/ES4e48IN3SlmKtpk24PfBEdRlEC2owMIdrI2JYmi90uGmsa0kb7g== X-Received: by 2002:a05:600c:2e04:b0:424:86fe:ac99 with SMTP id 5b1f17b1804b1-424895eaf2dmr72866125e9.14.1719294859638; Mon, 24 Jun 2024 22:54:19 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0c54c9sm199933385e9.27.2024.06.24.22.54.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:19 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 04/12] hw/sd/sdcard: Trace block offset in READ/WRITE data accesses Date: Tue, 25 Jun 2024 07:53:45 +0200 Message-ID: <20240625055354.23273-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=philmd@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Useful to detect out of bound accesses. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater --- hw/sd/sd.c | 4 ++-- hw/sd/trace-events | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 14bfcc5d6b..e4587a0a37 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1913,7 +1913,7 @@ void sd_write_byte(SDState *sd, uint8_t value) trace_sdcard_write_data(sd_proto(sd)->name, sd->last_cmd_name, - sd->current_cmd, value); + sd->current_cmd, sd->data_offset, value); switch (sd->current_cmd) { case 24: /* CMD24: WRITE_SINGLE_BLOCK */ sd->data[sd->data_offset ++] = value; @@ -2069,7 +2069,7 @@ uint8_t sd_read_byte(SDState *sd) trace_sdcard_read_data(sd_proto(sd)->name, sd->last_cmd_name, - sd->current_cmd, io_len); + sd->current_cmd, sd->data_offset, io_len); switch (sd->current_cmd) { case 6: /* CMD6: SWITCH_FUNCTION */ ret = sd->data[sd->data_offset ++]; diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 724365efc3..0eee98a646 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -52,8 +52,8 @@ sdcard_lock(void) "" sdcard_unlock(void) "" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" -sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint8_t value) "%s %20s/ CMD%02d value 0x%02x" -sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t length) "%s %20s/ CMD%02d len %" PRIu32 +sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x" +sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint32_t length) "%s %20s/ CMD%02d ofs %"PRIu32" len %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" # pxa2xx_mmci.c From patchwork Tue Jun 25 05:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34B28C2BBCA for ; Tue, 25 Jun 2024 05:55:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8P-0001fs-R4; Tue, 25 Jun 2024 01:54:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8O-0001fP-TI for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:28 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8N-0001bl-9P for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:28 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3636c572257so4373476f8f.0 for ; Mon, 24 Jun 2024 22:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294865; x=1719899665; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jx8nddqay2J5qb2F3WGg5BgvSRB/NLqHqQ/hS1TB/ro=; b=BHgf19KFSS35ocGMl5MjIlgWSey0IrQlkmrvZVEQI7itULuEjgpaCyKzgvGIVqTyce fmk9a0ZOVbieokPHS9d5DNQ2cUjZA7pYuD4DDJieHkgFvXTSgIh/NTCBe4PmjRtdVpVx kNu1JW9X26TsvZozqD0XDZk7x8jYSCkLynsmA8PI8kF51g1VpGHF0C+cJ0YwbZCGEUnL 3Mu2o+tptn1xNJlH9Q7X04yz3dt6Y/0JUT936PdlpsTDl7Ny8V+TNYbd0DQ9MfYJvojI QTi5hS9xTVoDdE4+xnmay60kxpO3JIrdkv6uQERK8luydxHTKCTm7cTYibFFpUezRFBG EvIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294865; x=1719899665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jx8nddqay2J5qb2F3WGg5BgvSRB/NLqHqQ/hS1TB/ro=; b=l1sZtTdpMOiF/cW2bI5Wxo3f9ymEN9+cDszYRmnTpl+Y4D+yxhWRxUXpNaV+UggtBZ rIYfQxFEUp66K+mE/hzFu8MazfAPHX7pcRaL69yUnbxjpwbvBxW4Ok+ySUF++O1n+NYn 3TUpvNuLG1DvgMzby68ognRHcjG/YGBcRy4EBn0aEea4qKmkoik1JCnMvCIvCaOC5v7W CVfjltcfREoPIQzFQPoTwvEL72A/yYwzgaoG1lgkFzTigh/rxSydYt77CGgcYBvzRRtc 7Ptlvfwoib6Jdr/LaXwJPOAvVS4sG+yoYeboAiO9JQ55/4LTandHTYL250YVaQNavkBl 3USA== X-Gm-Message-State: AOJu0YxxPtUmUG3qfU8qQ2m68OPF1NGi74OzQFN33AzM/Wpocxkb+ptK LtRjvond+c7nP3aVkPKqpT4s6QskvN7G6eizzKc0maQGLUrJuk42ZwEqWYqN4C7iDSBZbJIiwqT j X-Google-Smtp-Source: AGHT+IHFXhdXxP7UQ/eJnv5ppGcrgkC88yZHp35w9j0TvL7sbB31jFVa1rEMIclc953ODSLvxbciKw== X-Received: by 2002:adf:f450:0:b0:360:9a40:3dd8 with SMTP id ffacd0b85a97d-366e96567cemr5210858f8f.65.1719294865378; Mon, 24 Jun 2024 22:54:25 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208e13sm195345575e9.36.2024.06.24.22.54.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng , Peter Xu , Fabiano Rosas Subject: [PATCH v2 05/12] hw/sd/sdcard: Do not store vendor data on block drive (CMD56) Date: Tue, 25 Jun 2024 07:53:46 +0200 Message-ID: <20240625055354.23273-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=philmd@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org "General command" (GEN_CMD, CMD56) is described as: GEN_CMD is the same as the single block read or write commands (CMD24 or CMD17). The difference is that [...] the data block is not a memory payload data but has a vendor specific format and meaning. Thus this block must not be stored overwriting data block on underlying storage drive. Keep it in a dedicated 'vendor_data[]' array. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater --- RFC: Is it safe to reuse VMSTATE_UNUSED_V() (which happens to be the same size)? Cc: Peter Xu Cc: Fabiano Rosas --- hw/sd/sd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e4587a0a37..0f8440efcc 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -143,6 +143,8 @@ struct SDState { uint64_t data_start; uint32_t data_offset; uint8_t data[512]; + uint8_t vendor_data[512]; + qemu_irq readonly_cb; qemu_irq inserted_cb; QEMUTimer *ocr_power_timer; @@ -647,6 +649,7 @@ static void sd_reset(DeviceState *dev) sd->wp_switch = sd->blk ? !blk_is_writable(sd->blk) : false; sd->wp_group_bits = sect; sd->wp_group_bmap = bitmap_new(sd->wp_group_bits); + memset(sd->vendor_data, 0xec, sizeof(sd->vendor_data)); memset(sd->function_group, 0, sizeof(sd->function_group)); sd->erase_start = INVALID_ADDRESS; sd->erase_end = INVALID_ADDRESS; @@ -762,7 +765,7 @@ static const VMStateDescription sd_vmstate = { VMSTATE_UINT64(data_start, SDState), VMSTATE_UINT32(data_offset, SDState), VMSTATE_UINT8_ARRAY(data, SDState, 512), - VMSTATE_UNUSED_V(1, 512), + VMSTATE_UINT8_ARRAY(vendor_data, SDState, 512), VMSTATE_BOOL(enable, SDState), VMSTATE_END_OF_LIST() }, @@ -2020,9 +2023,8 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 56: /* CMD56: GEN_CMD */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sd->blk_len) { - APP_WRITE_BLOCK(sd->data_start, sd->data_offset); + sd->vendor_data[sd->data_offset ++] = value; + if (sd->data_offset >= sizeof(sd->vendor_data)) { sd->state = sd_transfer_state; } break; @@ -2156,12 +2158,11 @@ uint8_t sd_read_byte(SDState *sd) break; case 56: /* CMD56: GEN_CMD */ - if (sd->data_offset == 0) - APP_READ_BLOCK(sd->data_start, sd->blk_len); - ret = sd->data[sd->data_offset ++]; + ret = sd->vendor_data[sd->data_offset ++]; - if (sd->data_offset >= sd->blk_len) + if (sd->data_offset >= sizeof(sd->vendor_data)) { sd->state = sd_transfer_state; + } break; default: From patchwork Tue Jun 25 05:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710658 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96ED7C30659 for ; Tue, 25 Jun 2024 05:55:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8U-0001ha-WF; Tue, 25 Jun 2024 01:54:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8U-0001hP-9N for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:34 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8S-0001d3-Pv for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:34 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-366edce6493so1544176f8f.3 for ; Mon, 24 Jun 2024 22:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294871; x=1719899671; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ee/yL80E0AWtVNbCxQaoN9WZIZ5QGojNiR7WBNpSOHo=; b=XzBJdxLrNJSWQg8q1FGJcRJsNq+nwT/g8qQpaxeyOM+4Xjkplyex/5elNlXI5rjsVc GJxpQN4ldxDvDcttUD2RlYk2PuvmnWSe3BnEbnP8+hHeCWApT+6uWhan6t0Lw4fF+Ja5 NA17v22c0eslrn6qTl3YE5m3o6VQdCFn1BO4dTmUuIS8/wkfpazXRBTLZWN70GfUeFXa feqCpq7TkSEsy58sexDd0wFyuhMfXvCPo9Af2uUbrAvblkSNjaCqy3/c3SbEDkCc818t vN6xGFZfasLRZZFquGSJrEAHTg2mx/+Y+zzXnEI/GDVf2KiuZ3XcxKD5h8zQdwwArwJy a7GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294871; x=1719899671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ee/yL80E0AWtVNbCxQaoN9WZIZ5QGojNiR7WBNpSOHo=; b=sJWNQNIOGmT0duw3bhGh5fcuJuabfbLCYEQnI6awpl6C2tJvg48/yns6kfLlo8GIyC nUdN6uR/BjVxht5vEKPzbm3buNE3+inULvksSrD6kjzYS5ii0EvVMNEJXwM4NNX3rI/T fCPNL+Q67cEk9SqYkd3mGvOsrUJsEUUuEq5KosU/b7565WiwhNlFHRS2yoWdmDZ4lF/v wyOZoOVdGApkEwZKi6rO12iQUf7W/2HkJG42P/GOdywAH2oD50dI2qvA6EoIEZFpJyfQ JnY+bSlbSMwrWoDzOhVaLigu4JRX9CygUbxW/k7FKOSX7OCb+5Vlr40bW+XRoa24eSVK H3Dg== X-Gm-Message-State: AOJu0YxJ2yCmy0DDAU8Cp3B6/3+QTcNJ/x/8u34f1n12fno2JCIjXoos IKTHJOunN9NvPyKQA2PVxkV684r7rc3eve0ul0vjU296EyKkku2sDRe1sjxtb0kF3dEYJulciWr I X-Google-Smtp-Source: AGHT+IHaxOnTR0qfrHvwJsYldlxw76lZ/cNtNe0hLV2cTKCz/mmcrh/siw2jO+8amfctlOBdlevAvg== X-Received: by 2002:a05:6000:178a:b0:360:7092:728 with SMTP id ffacd0b85a97d-366e95ddf7cmr5466388f8f.55.1719294871034; Mon, 24 Jun 2024 22:54:31 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367003b1fc8sm846275f8f.57.2024.06.24.22.54.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:30 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng , Peter Maydell Subject: [PATCH v2 06/12] hw/sd/sdcard: Send WRITE_PROT bits MSB first (CMD30) Date: Tue, 25 Jun 2024 07:53:47 +0200 Message-ID: <20240625055354.23273-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philmd@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Per sections 3.6.1 (SD Bus Protocol) and 7.3.2 (Responses): In the CMD line the Most Significant Bit is transmitted first. Use the stl_be_p() helper to store the value in big-endian. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater --- RFC because I'm surprised this has been unnoticed for 17 years (commit a1bb27b1e9 "initial SD card emulation", April 2007). Cc: Peter Maydell --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 0f8440efcc..b604b8e71f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1498,7 +1498,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } sd->state = sd_sendingdata_state; - *(uint32_t *) sd->data = sd_wpbits(sd, req.arg); + stl_be_p(sd->data, sd_wpbits(sd, req.arg)); sd->data_start = addr; sd->data_offset = 0; return sd_r1; From patchwork Tue Jun 25 05:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD212C3065B for ; Tue, 25 Jun 2024 05:55:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8c-0001yT-03; Tue, 25 Jun 2024 01:54:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8Z-0001tG-UZ for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:39 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8Y-0001dz-Du for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:39 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4248ea53493so14912805e9.3 for ; Mon, 24 Jun 2024 22:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294876; x=1719899676; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UJN6KVZ4KFMiBqbYHgPGiBcO7JIk6P/og2YV9T7n/3A=; b=u5Wt2HsQpuXTs4R8DmoC9v0oQst0mwNwc0oj6NTwYKSyBpoNycK+d5ROAbT9pujyLV wo/TW6JTcLqvt3hWdFJgVrlmXZojVxSG3e46ewTPzKAXbXN9XiKa2tQg8fCdjpbqD73K Fi+6hpvFqPKS1QOa7tE8oKx9lL7kuL2CKo9DVROcwCtAI2ULb11p/vXKujJgTyvpiO1R tS6qpiOx8tqUbY8KvJMhPAqveiuiuSrlE7B+FNTrmfPSp+NrNloE5JAXTZPiNlXOLLss 3PvF8sHTznWobzvX0gw/BWGROrZH+mTHhZ3jieiPxgEFgcs3O8n/B3MdOUDFEJD3LL2A hqDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294876; x=1719899676; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UJN6KVZ4KFMiBqbYHgPGiBcO7JIk6P/og2YV9T7n/3A=; b=mpVSjSzBCyeGM9MEY6CZa82fcPk+OSut1aexuT4E4apZ4TfM5Pnx/bC9aSahVuhv7r dAWpKR1sOZTpRka7O8eywOGf9b+g5uV8GVO68C85FSnWWujHPpNxrEHRffUkwkaWinlh OcHBoUtqzFYl+KqHBVynJzdn1g3/ETldupKImVC0zIS2s3fBtsQDSOa5febv1JYFYxsE BI5Cb/aEBpIFzXXg9csylMnN0I5vN/oQ7S1Bfa3JkbxUbuMxMYAa3DC1r6fHyR+KRZ7j 8+p1w2c88I72iUbX33qVDLyfERAC5vSccxRj97E3DxGVQaSR22XKdfkmp7iM66yxiEqA gEIw== X-Gm-Message-State: AOJu0YwqE/sGGxYpDJv/pimZPmDH2lyWwYQXQN4agE6oj/Np6rWeZNJQ CxR3gYIGxVI8962BK2dPzuDE3ZtBObjb8ixFzfeoJAD51ZidJJW6BgJZBCgNLWotByANBaXDVNR u X-Google-Smtp-Source: AGHT+IHuxLstUDVxqnxVGRENFW9vyjN6tmlRxuUk5mCLINYKrFbok9v/HmXGaPauWitRJ5X5Rmop2Q== X-Received: by 2002:a05:600c:4da1:b0:424:8e88:a6a6 with SMTP id 5b1f17b1804b1-4248e88a753mr53922045e9.8.1719294876771; Mon, 24 Jun 2024 22:54:36 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366383f6355sm11849035f8f.17.2024.06.24.22.54.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:36 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng , Peter Maydell Subject: [PATCH v2 07/12] hw/sd/sdcard: Send NUM_WR_BLOCKS bits MSB first (ACMD22) Date: Tue, 25 Jun 2024 07:53:48 +0200 Message-ID: <20240625055354.23273-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Per sections 3.6.1 (SD Bus Protocol), 4.3.4 "Data Write" and 7.3.2 (Responses): In the CMD line the Most Significant Bit is transmitted first. Use the stl_be_p() helper to store the value in big-endian. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater --- RFC because I'm surprised this has been unnoticed for 17 years (commit a1bb27b1e9 "initial SD card emulation", April 2007). Cc: Peter Maydell --- hw/sd/sd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b604b8e71f..0742ba8b38 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1659,8 +1659,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) { case sd_transfer_state: - *(uint32_t *) sd->data = sd->blk_written; - + stl_be_p(sd->data, sd->blk_written); sd->state = sd_sendingdata_state; sd->data_start = 0; sd->data_offset = 0; From patchwork Tue Jun 25 05:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8043DC3064D for ; Tue, 25 Jun 2024 05:55:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8h-0002GI-SZ; Tue, 25 Jun 2024 01:54:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8f-0002DZ-Ol for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:45 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8e-0001f1-8v for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:45 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-421a1b834acso42172975e9.3 for ; Mon, 24 Jun 2024 22:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294882; x=1719899682; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DSh3z/dbSRZy4hlbUrmDOZ6ZGH/UkGencdxAnicUEVY=; b=ek6BuXH12R2UURVh7SCD/ZV+v7CXyLk94XCMJ5H0xfwUAZFhn3ZD+K71MiUzgnhby/ VuOAElUTC/DLbyyp0Om8k9ZORIRpp6aio1ULXPR3+VA1O8qqr74DlQL/KqOic/rIMNtv jhi4gKGQi/+6DOavXot09m8u75107WBTC5jhTafdTHw2u/RGbI2AY2R29QmuxAn0TcJ3 dACecCQJAOAA1RSwAxYFW9ik1JSTuSwUT8/nf4QtpzUrdaNYdnoqrzB1krpa/jFRrOjP ChzQx7bJEfkgJb2Q1xwkAogJSzvUeex5usVPL/jGiKUgHPYTYbtnNIl1D0FjGfdQGcfo p13A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294882; x=1719899682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DSh3z/dbSRZy4hlbUrmDOZ6ZGH/UkGencdxAnicUEVY=; b=cAiXXkIgjlN4V3L9+LX2ATK4bZiZ6MB4fkM2txf0tsdGVyL+9e7/t+/3Rtk41pXiyC ZcQ3EG8eeOYuREqCQWUuHKT43ncbOa4mlw7ppYzIMrDQN2owxMuU75tTLp//yB69y3PF e7GHckokDXE5aUWdbKWm/bBW9V0UCPNsy/MFAW3JX6Q+N0YPSJb79FGCuPoKnVTeTPjJ 6SDQMyJEI8xtTPDR1gCPcwPSp/IRRAvKDbCIFDmqrG5USFqirVu2Hl7OvXaOppfZKkXz WCS4lBgU2MMhmjFlCksQQyhrMjp0ftNdw8WI4cSRFXH1tboJFfBnBzgZ6B5zflS8KL3p hFiQ== X-Gm-Message-State: AOJu0YyonwLAxnv5u/H5g4kugnFOd2A+q9znDgTkLqkSODSDhhLR+ukH P5Syf/Y2fEid2EuthcUYQ8DRcHLWdlqS0QcuMZpqfp0PsYFbRUSJtgpNZrNWBHVtaFkb6ehpOB8 3 X-Google-Smtp-Source: AGHT+IGzJaLUcpGW6stykPVGFUOjtDyS1SM1TYU8/7Dv9+8rED77ui/ZV03612BKGtTfNyXRdDiZCw== X-Received: by 2002:a05:600c:4f4d:b0:424:8f0d:c07f with SMTP id 5b1f17b1804b1-4248f0dce13mr33943175e9.4.1719294882495; Mon, 24 Jun 2024 22:54:42 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424817a9975sm155739065e9.14.2024.06.24.22.54.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:42 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 08/12] hw/sd/sdcard: Use READY_FOR_DATA definition instead of magic value Date: Tue, 25 Jun 2024 07:53:49 +0200 Message-ID: <20240625055354.23273-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 0742ba8b38..8816bd6671 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -557,7 +557,7 @@ FIELD(CSR, OUT_OF_RANGE, 31, 1) static void sd_set_cardstatus(SDState *sd) { - sd->card_status = 0x00000100; + sd->card_status = READY_FOR_DATA; } static void sd_set_sdstatus(SDState *sd) From patchwork Tue Jun 25 05:53:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710666 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8552C2BBCA for ; Tue, 25 Jun 2024 05:56:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8n-0002XI-1N; Tue, 25 Jun 2024 01:54:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8l-0002UK-Mm for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:51 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8k-0001g6-3i for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:51 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-35f090093d8so3462651f8f.0 for ; Mon, 24 Jun 2024 22:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294888; x=1719899688; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rePHr36mkrTbTL5WwJD6QrkkFRWrQAZ68gdScQGNuYc=; b=ebDp/fvXtDRbOhsy16ZxMhNSsUUS8POT6ouUdiyzY8vFn7y7WmY9M0zM5hoby4KTz5 gZM2V+me5ERHr1W0wf98gRObk5bR5tjHLerN4HucD9fqzPoEh4O4hLjhu6FSrhX5A+I2 Nd4wZShLIGXuphkxwkpiX/o21b5/pKdp5u1NRzPspuPCjwdnZSOof7AZZYmiQi/bhDfo 4ZdNEC/2Mk49AjzPdUfylvlZbqceVKHMaSUkcQ+VKZu/fIhqSgO495jM3CV6n4EzNWQT feoCIIUO/d51MXBTJ6J00k+CkGbOgNXqcRIBgOwN/dct78ecguwYKPWzjPVxs4gRaSoa AtPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294888; x=1719899688; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rePHr36mkrTbTL5WwJD6QrkkFRWrQAZ68gdScQGNuYc=; b=BKZVuEqiB4UC94NrtbmIZ+7f8SdzZpbTVHkoiaJlp+7o2mx+p8rHgQyyCNKc3uBXA9 1x+qMQlWfqiVCRCIlzdBeVe7j30y8xLEJHl0woqH61oFQ0gvT9iEgyj6ELhO4j9tSLfe tT+UEKphVNNGYVGfdW8/KNN94u8ZlG973bQmXb/hXL+00uHu0i3/NB8waXnitvOUiG/g m+rMjkUClfDiHgPi/Tl8s+rxhAreu+GmBK7dfd6B5hN925aHd7Qu8M+sY0gHgg42Vz5p KNEgUJWv6xlG8STqTVuuQb5Q2Dp830FOiSaazQGnvi3yEcveh9TMyVrWkl4A0CiOVON5 9L6Q== X-Gm-Message-State: AOJu0YzwHTcBuiGkl4QotPzqJxXWLfuiXGHoJkVKFq/0Pgd91PukM90E 25I3kfcpXvICFjVvImpqT7m9pVd8GPBIX2wyOV4cSB14OYyOHwL3LFk1zZ6LuQSF6fbMzCyLmFw b X-Google-Smtp-Source: AGHT+IGfjfo4xhAxXI7RAYjdwG8Khrx1F3ZlWhbeLi/Q1CIcgkLO3YA63Au0ugQgE7fu3UgCRBuMmg== X-Received: by 2002:adf:f7cb:0:b0:35f:cd7:5ba1 with SMTP id ffacd0b85a97d-366e7a6367amr4875249f8f.60.1719294888263; Mon, 24 Jun 2024 22:54:48 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36638d9c1d1sm11898372f8f.51.2024.06.24.22.54.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:47 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 09/12] hw/sd/sdcard: Assign SDCardStates enum values Date: Tue, 25 Jun 2024 07:53:50 +0200 Message-ID: <20240625055354.23273-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=philmd@linaro.org; helo=mail-wr1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org SDCardStates enum values are specified, so assign them correspondingly. It will be useful later when we add states from later specs, which might not be continuous. See CURRENT_STATE bits in section 4.10.1 "Card Status". Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8816bd6671..36955189e8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -76,16 +76,16 @@ enum SDCardModes { }; enum SDCardStates { - sd_inactive_state = -1, - sd_idle_state = 0, - sd_ready_state, - sd_identification_state, - sd_standby_state, - sd_transfer_state, - sd_sendingdata_state, - sd_receivingdata_state, - sd_programming_state, - sd_disconnect_state, + sd_inactive_state = -1, + sd_idle_state = 0, + sd_ready_state = 1, + sd_identification_state = 2, + sd_standby_state = 3, + sd_transfer_state = 4, + sd_sendingdata_state = 5, + sd_receivingdata_state = 6, + sd_programming_state = 7, + sd_disconnect_state = 8, }; typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); From patchwork Tue Jun 25 05:53:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 599BEC2BBCA for ; Tue, 25 Jun 2024 05:56:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8t-0002hL-AO; Tue, 25 Jun 2024 01:54:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8r-0002ZK-2S for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:57 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8p-0001gy-HQ for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:54:56 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-362f62ae4c5so2925350f8f.1 for ; Mon, 24 Jun 2024 22:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294894; x=1719899694; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5P7HyM7CLqMyqYOTJNfxbyYOLKZqsQ3trYZWJFhWDzE=; b=jUxo+UMRrb4lQQJOA1iKG8vA2k7OE0McSg16cyQRGH+1+H5Md9XTIrKFhWTCxvoLyV kXwPTFiGFI3ItGHq1B0mzAIhpPNzpA33/znaQq9PjrOnTOgBPL4V2vgYkY8Vr4sZJCPV 198lvfcNO65oumKNZXtKj5NtijfAyZA3IKKOY+Tlah6JkqF7joS++UGEsNWgmmPkCspZ YAa4abh71wSTaamug3R0u4vLILfbrzaCRafdK5JwdM1PMpL+dJch7xQVv8LyWfrHViiy lYhpcxQGiQgPbZ7DOh8oI8bOUNQS/Mv4bhdyKctnopFX8XvTTA3D/QZPTE+JnR9CB6Gs rgdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294894; x=1719899694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5P7HyM7CLqMyqYOTJNfxbyYOLKZqsQ3trYZWJFhWDzE=; b=VWeSlgYHBoIUFMDM5ICNwZmy1GC+FQLFJ/iz7sAHetQhKckY3zRatP5ViXA4B6ap7h ztBrHpTB/Moj2lqqUMxp2+nzs7lbtfUn0X4fpfMZ9VHwzcrCOjPU7DlQFSdshI9uEFEq PSnN8qB8i9dbi++4wWc1BLLE8CvVuZR2n1gi4+ev3EgqNXUqbdeCXEd4zgxCKHdEz+lU i+Ae5R4rq/pnQKAgLIEIJZjZvOIh34lTau5n3zw0QtsboldA7KwKDUoFR9byK9fQdOjP 6doz7geRbVu3t/jta6Z2OUAtN+gt/+EDqJaOUb8TtejBMPBeN4V62ut8CDcvnpK2yibf NiNQ== X-Gm-Message-State: AOJu0YxRO6xpaHdLCKCI33yYxAoV3EdzGPqvV1GYAcWqF1g24EAWHEH6 R8FR96BACp/LZUsEJrTuXNYaho4NAxlmVCVIgsFz/4KotSSQToavlVtZCEfI6drEcLV+44IX7FS y X-Google-Smtp-Source: AGHT+IEAlgGMpHRcV9j43LCtCz2MJYI2Au6h0fZSPqtRVLGMXc/0FJ3cHCluLTMK6HzHOlQ+UjboVw== X-Received: by 2002:a05:6000:b0c:b0:366:dfc4:3790 with SMTP id ffacd0b85a97d-366e34a3d7dmr6074472f8f.0.1719294893836; Mon, 24 Jun 2024 22:54:53 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366e88c0c38sm7509752f8f.32.2024.06.24.22.54.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:53 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 10/12] hw/sd/sdcard: Simplify sd_inactive_state handling Date: Tue, 25 Jun 2024 07:53:51 +0200 Message-ID: <20240625055354.23273-11-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=philmd@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Card entering sd_inactive_state powers off, and won't respond anymore. Handle that once when entering sd_do_command(). Remove condition always true in sd_cmd_GO_IDLE_STATE(). Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 36955189e8..fce99d655d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1072,10 +1072,8 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) /* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { - if (sd->state != sd_inactive_state) { - sd->state = sd_idle_state; - sd_reset(DEVICE(sd)); - } + sd->state = sd_idle_state; + sd_reset(DEVICE(sd)); return sd_is_spi(sd) ? sd_r1 : sd_r0; } @@ -1570,7 +1568,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (sd->state) { case sd_ready_state: case sd_identification_state: - case sd_inactive_state: return sd_illegal; case sd_idle_state: if (rca) { @@ -1791,6 +1788,11 @@ int sd_do_command(SDState *sd, SDRequest *req, return 0; } + if (sd->state == sd_inactive_state) { + rtype = sd_illegal; + goto send_response; + } + if (sd_req_crc_validate(req)) { sd->card_status |= COM_CRC_ERROR; rtype = sd_illegal; From patchwork Tue Jun 25 05:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91592C2BBCA for ; Tue, 25 Jun 2024 05:55:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz8y-0002ts-Os; Tue, 25 Jun 2024 01:55:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz8x-0002tK-6N for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:55:03 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz8v-0001i0-H2 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:55:02 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-363bd55bcc2so4213353f8f.2 for ; Mon, 24 Jun 2024 22:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294899; x=1719899699; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YAYGjbFJNuy9OHUJ805jrPNXsWJBhB1UqPytiuUZXwI=; b=H/vF1o+bAUQ7usNqJVvrFJDQXQIdCn9NqVcABKWJ8wnAsksNvH93KZPJZbbWqDimxC JG9YOxtPlWTmtUFe1q20dtLWwWsqsE0gKXlRmegWim5hXEwKEaneeMmWpwdqwh2PXZQY sJKXt3iedv2l+OJyy0yuG0V8x01JiRpDUFNDCws1hg8DUSg7hGRQCHRWdf8LGNp/ZvO4 gmdgKVJcQ3lJ8DNb8N11ug5Kg7f9A/nY+UeHy12VPbz/bmJsKwt8FrjP17iLisBxHtjN EyXRIccDnvJPHIo9SBRL1K+sRDA8/yGSUBu1pE86Q7a2f4t/v2H6esqnRA81DMosm7ih SibA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294899; x=1719899699; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YAYGjbFJNuy9OHUJ805jrPNXsWJBhB1UqPytiuUZXwI=; b=RkpXsUdN573ncezqXLzy21wVMZv+OsbwvZanHolJHBZK8DdhZqWnzHuOrOECkxtAtF kyJNix7LpBBtNjD1z0Kk4I19JJhYZSLsBWwMNW2AfftmscLEswpTNA7J8nmozTXHzXhg 66N3zjwce/3Wk+CelduyqeudgjnsrWmNbInZVNtHW7oZEP917rumnfZhLXfSU6iyMdsU Fy+9mvB101XbzL16/aKOINFdRy+6o5EOinIuqaShGKvsuCvKl7CREcq4kERZxWSTrqCF CUYr4ddRqjzvHt1zkiTsX7tZmO6MqmHDtlq5uvBIi1jWcR5Nh+h0MRsosCEIJ2vPLFjl 5Vtw== X-Gm-Message-State: AOJu0YwYzNZqeof3Q9XOdWzCBGISY0I5VF3tjFx/ztAVQ5lhXAsa/EJg qYLjKaG4YHXNXt5mr/WB+P8fVw1uTHnEsbVKSLn0J6KR8G0o6Ix9z1LLx7K2uq1EilEmWO5L3si O X-Google-Smtp-Source: AGHT+IEsE/HIBKeNcn1vxBxHhO61D3zn56j7hnUxGgUpyjM5wvGdrO22BtQ0nIqpxfJc6IrbEe6vRA== X-Received: by 2002:adf:a21a:0:b0:362:8918:1830 with SMTP id ffacd0b85a97d-366e94ee0d8mr3348812f8f.42.1719294899468; Mon, 24 Jun 2024 22:54:59 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-366f624cdacsm3996960f8f.70.2024.06.24.22.54.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:54:59 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 11/12] hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6) Date: Tue, 25 Jun 2024 07:53:52 +0200 Message-ID: <20240625055354.23273-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=philmd@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org SWITCH_FUNCTION is only allowed in TRANSFER state (See 4.8 "Card State Transition Table). Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fce99d655d..3b885ba8a0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1196,6 +1196,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (sd->mode != sd_data_transfer_mode) { return sd_invalid_mode_for_cmd(sd, req); } + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + sd_function_switch(sd, req.arg); sd->state = sd_sendingdata_state; sd->data_start = 0; From patchwork Tue Jun 25 05:53:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13710661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42B1BC2BBCA for ; Tue, 25 Jun 2024 05:55:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLz96-000341-RW; Tue, 25 Jun 2024 01:55:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sLz94-0002wc-B6 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:55:10 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLz91-0001vk-Vy for qemu-devel@nongnu.org; Tue, 25 Jun 2024 01:55:10 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-35f06861ae6so3994464f8f.2 for ; Mon, 24 Jun 2024 22:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719294905; x=1719899705; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rEDUclqNQG81lYieISPwXKSAxhsKsmBHUM+5O9kJWv4=; b=Njinapm9RlueUbmV1cpGwt2JFT/J5NyDZxbDLynDAU4K0d2/df4vxkMlNSAJSzoPZ+ PgC2Ikt7GnHEZ5I8IiUfLI4TTP8JlxirT7hFRfkFVwmk0WbZqExS5vPWFUvwpTk73ERn h1Nji7B7srKSx5Cru0uBYVdTQd4RdZAlcl9+IS598qbxdtDHlGXF3ZfCbSIZmrq1BcLA P2EtmiTUJ26JqgezuuOBI6ePGFOOumPDh9woPMBw18UBZ30UqZkzBFVZM78uwiPYbQWs 8WG4QMlaiu8zUkZKI8r1tGKnAHf4aBkdHc+VSNqCIVkQPvXV3bj68e2HnD7VZWqrok5Y t0rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719294905; x=1719899705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rEDUclqNQG81lYieISPwXKSAxhsKsmBHUM+5O9kJWv4=; b=pbb0df6xmFS93h5sQJHpFc7mA3ZomgG9QburJ0xabvW9UtzYGg4WoZY326o0wHSkQe oB5c1PF3PDr+CKTvVJg/3iWbGMsNZCbI46UaT7ghyfWQbxoPhwj1U5A2NLvc57fpsfzV wMQRNQMlVl0MKmYYT2anojUKuF2fUEA/5Keegelo4+vd4iyTrndo86b9/Zm6sxrelgrv twslqdbtOF7FvTkXS+YFoRA5MhCQRwE2wxBNeNc954iY2r9MwHjn9Uq4tTuElK7rLHQL kNUtlrCHWTneetTK0fHY7NuoWOCSVCuSPQJzBiama6GAPwSbB1wu2WPvTfzrSOjB1Laa M9SQ== X-Gm-Message-State: AOJu0YxfwAY7/qPYzTuL+h/BEOSZXkbet9e5VovpC6qlOXh18w0ZytO5 uhmNZ7VVGo+weAWNFIofXdY8O/FGKDLzO64B/XdqBYOWfYxExQjYdhgyaxfC+XiwLQRnsW2h5pJ 1 X-Google-Smtp-Source: AGHT+IGA5w17y7EplleBEtnMBka1o1erlsC/vBQ8Ti2+86XQ5ej/pIKoM/SVNouJ5xtrTajwrGMMHg== X-Received: by 2002:adf:e806:0:b0:35f:1161:e1a3 with SMTP id ffacd0b85a97d-366e94db399mr4136006f8f.5.1719294905408; Mon, 24 Jun 2024 22:55:05 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208b4asm196304145e9.29.2024.06.24.22.55.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 22:55:04 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH v2 12/12] hw/sd/sdcard: Add direct reference to SDProto in SDState Date: Tue, 25 Jun 2024 07:53:53 +0200 Message-ID: <20240625055354.23273-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625055354.23273-1-philmd@linaro.org> References: <20240625055354.23273-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Keep direct reference to SDProto in SDState, remove then unnecessary sd_proto(). Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3b885ba8a0..6685fba4bb 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -117,6 +117,8 @@ struct SDState { uint8_t spec_version; BlockBackend *blk; + const SDProto *proto; + /* Runtime changeables */ uint32_t mode; /* current card mode, one of SDCardModes */ @@ -155,18 +157,11 @@ struct SDState { static void sd_realize(DeviceState *dev, Error **errp); -static const struct SDProto *sd_proto(SDState *sd) -{ - SDCardClass *sc = SD_CARD_GET_CLASS(sd); - - return sc->proto; -} - static const SDProto sd_proto_spi; static bool sd_is_spi(SDState *sd) { - return sd_proto(sd) == &sd_proto_spi; + return sd->proto == &sd_proto_spi; } static const char *sd_version_str(enum SDPhySpecificationVersion version) @@ -1035,7 +1030,7 @@ static bool address_in_range(SDState *sd, const char *desc, static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) { qemu_log_mask(LOG_GUEST_ERROR, "%s: CMD%i in a wrong state: %s (spec %s)\n", - sd_proto(sd)->name, req.cmd, sd_state_name(sd->state), + sd->proto->name, req.cmd, sd_state_name(sd->state), sd_version_str(sd->spec_version)); return sd_illegal; @@ -1044,7 +1039,7 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) static sd_rsp_type_t sd_invalid_mode_for_cmd(SDState *sd, SDRequest req) { qemu_log_mask(LOG_GUEST_ERROR, "%s: CMD%i in a wrong mode: %s (spec %s)\n", - sd_proto(sd)->name, req.cmd, sd_mode_name(sd->mode), + sd->proto->name, req.cmd, sd_mode_name(sd->mode), sd_version_str(sd->spec_version)); return sd_illegal; @@ -1053,7 +1048,7 @@ static sd_rsp_type_t sd_invalid_mode_for_cmd(SDState *sd, SDRequest req) static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) { qemu_log_mask(LOG_GUEST_ERROR, "%s: Unknown CMD%i for spec %s\n", - sd_proto(sd)->name, req.cmd, + sd->proto->name, req.cmd, sd_version_str(sd->spec_version)); return sd_illegal; @@ -1064,7 +1059,7 @@ __attribute__((unused)) static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) { qemu_log_mask(LOG_UNIMP, "%s: CMD%i not implemented\n", - sd_proto(sd)->name, req.cmd); + sd->proto->name, req.cmd); return sd_illegal; } @@ -1157,7 +1152,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) * However there is no ACMD55, so we want to trace this particular case. */ if (req.cmd != 55 || sd->expecting_acmd) { - trace_sdcard_normal_command(sd_proto(sd)->name, + trace_sdcard_normal_command(sd->proto->name, sd->last_cmd_name, req.cmd, req.arg, sd_state_name(sd->state)); } @@ -1176,8 +1171,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_illegal; } - if (sd_proto(sd)->cmd[req.cmd]) { - return sd_proto(sd)->cmd[req.cmd](sd, req); + if (sd->proto->cmd[req.cmd]) { + return sd->proto->cmd[req.cmd](sd, req); } switch (req.cmd) { @@ -1623,12 +1618,12 @@ static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { sd->last_cmd_name = sd_acmd_name(req.cmd); - trace_sdcard_app_command(sd_proto(sd)->name, sd->last_cmd_name, + trace_sdcard_app_command(sd->proto->name, sd->last_cmd_name, req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |= APP_CMD; - if (sd_proto(sd)->acmd[req.cmd]) { - return sd_proto(sd)->acmd[req.cmd](sd, req); + if (sd->proto->acmd[req.cmd]) { + return sd->proto->acmd[req.cmd](sd, req); } switch (req.cmd) { @@ -1919,7 +1914,7 @@ void sd_write_byte(SDState *sd, uint8_t value) if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) return; - trace_sdcard_write_data(sd_proto(sd)->name, + trace_sdcard_write_data(sd->proto->name, sd->last_cmd_name, sd->current_cmd, sd->data_offset, value); switch (sd->current_cmd) { @@ -2074,7 +2069,7 @@ uint8_t sd_read_byte(SDState *sd) io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; - trace_sdcard_read_data(sd_proto(sd)->name, + trace_sdcard_read_data(sd->proto->name, sd->last_cmd_name, sd->current_cmd, sd->data_offset, io_len); switch (sd->current_cmd) { @@ -2218,7 +2213,9 @@ static const SDProto sd_proto_sd = { static void sd_instance_init(Object *obj) { SDState *sd = SD_CARD(obj); + SDCardClass *sc = SD_CARD_GET_CLASS(sd); + sd->proto = sc->proto; sd->last_cmd_name = "UNSET"; sd->enable = true; sd->ocr_power_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sd_ocr_powerup, sd);