From patchwork Fri Jun 28 07:01:29 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: 808206 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp224684wrr; Fri, 28 Jun 2024 00:13:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWvLtPIKM6Z9HkwzUn1IrlncKhOIk0CMAyf8OwP7WNNk+1owD5QtqHy5ujgAFJ8FBbRgDijskhmIuVOWu5/9qHX X-Google-Smtp-Source: AGHT+IETwRRZpbi0m4LjrNZKLjBWuHIhS2skhhC7XL+Qx09UL5Ju+1YEvY9hKzrM/yHl5eG1d427 X-Received: by 2002:a05:620a:2494:b0:79c:119e:2b36 with SMTP id af79cd13be357-79c119e5e31mr915150085a.29.1719558781064; Fri, 28 Jun 2024 00:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719558781; cv=none; d=google.com; s=arc-20160816; b=vlk87ySoi+GR0Y+RcBHWUp1B0ko02NmWaUhvaNgPw2EPnMvdRaoxEMaw8VlJ+W8Nel 0wbU30bxb5ZZd0lyekARHrCULCQ+Y88VATQvOSHWQj3hqshpNVSTsHP4y8+c73elb7Zs 6XjteEokwo83ZL6DZPhzOFp55vspahNO/feVe8k4gyHrRGx2VynBxnBo68wCvRoDjjPk jei8N5pR3nE4HWKCIwdJuRnhw4q1neTxsEQX6ewXWCkcI5Cjh8HTUHbeIt4qYSkh91Kf SWjnm8+EEErR7U8gBiAaV/tEB78G8gi0/Tb2IwdWNAwnIdq9jiY3DSKQMUf86no/pD4R YOyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=4nsIUIKAxv1jJ77cujJiWISIWdMZfiLK/guukYvkLv0=; fh=Vqz0ILX7NeXJwCG5xiS+Wtk94IhOmAmLtOfN3kRbil4=; b=Z7DisqBVoIM6NuWbis65DS3dS9OtaB4vDdpc4zk9i+iSpCiPlvJ4hMzW4Q2r5T0gFm BL0y6HujNC4OCMoE3I/2v4W4NVrk1y5rZLgajmrJX3wlBVugLN/p7mzbI4vy5tuisHPW LLxb5/ULAGfaaufem1FpQzkDu4UK2tejUgSqND4042lomEIIjJ3KiMZPs7n85uW8fetM pv+ovOR8sKHxL1UpbQTEcSPINrjqH+tBQosLkhphJ5Q67orVTif8pxs/h2KLh0/ihPhJ nCMdOd5dwwxZX9h4LmVRlPGRZjuWnIDyz0SaHvutuA3WwmmAfxf9olywAl070tyO7iA1 bzkQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q9vjo1Uo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-79d69264b55si122816185a.85.2024.06.28.00.13.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Jun 2024 00:13:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q9vjo1Uo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN5iB-0003GY-Uz; Fri, 28 Jun 2024 03:08:02 -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 1sN5i9-0003Am-1D for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:07:57 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN5i5-0003Q0-Mb for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:07:56 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-362f62ae4c5so138207f8f.1 for ; Fri, 28 Jun 2024 00:07:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719558471; x=1720163271; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4nsIUIKAxv1jJ77cujJiWISIWdMZfiLK/guukYvkLv0=; b=q9vjo1UoOac/xLcjpH3EGY1j3jl2tMm6hQ7yV/a0z0tsooqehb6iVWNWLHVt04D/q9 SoNvmJrnqFSP810Zo+NCgPK0HkHrJbnU62yqBmqZUPx6eUqwNgrXIN7DowuySIsHSNso /LkDnf/ilrmuiWVUtXFlOSbP79FAxhWjILHV9XPUc7qOAVm/r5v2xGUa3ppGinhwzi6A RZRAd65fDHT0z1z3vLOR9I8DSilApuhAbcGLbWsMBVdeSGoatiL5UyzPmZPErthjBfeM 9UB7uZ8tJmPXPz/nSOD1XiL+l1cA56zbCeBskW/3e/2tuPJ4+OlPxLXscJv9H6opOoZu 7F5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719558471; x=1720163271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4nsIUIKAxv1jJ77cujJiWISIWdMZfiLK/guukYvkLv0=; b=d1IjzxomfKwiAXVJX/pOpM5JYE7cXCgSKn9e60D5nC9ZBdlCu9Wpc3CT5/5tIGFKCc kLEyWl/7TYRYINr2RI5bs0do4Fu5hd5kUjjnnrIuGSIZkEHgBOaU7hIvZvhFRkB/HjA+ /zc5bGEGVEG4WPjS0O3jPyWANpFXY7eA1IooKvGRIrzkeVS7zWkZuvVT8AFvGDAfI57v y1Dk4IrtpXhkeoJ8/K2ef7i6bt5Z19EVoqLnPlgucTq36oFEJegHHNU8Fe+Tdg1O/xAX IDSj01lFE3WVSm3VIv+erIwCO2M/TuBg8b/vgPNunzcc//ptal2qvH0hwwjZ/HpMzmU4 KurQ== X-Gm-Message-State: AOJu0YzYvM6GHyfqwGE+RsE8lRXemPiiGld3vYMPywt3ULnGzn/1aXjn ZvagwftEMus08RapRKzeOrZ4gpANX8N8tjhPfFfrUcE+FarPyLSD56J46/pHYrmLa85IzPmOIJW RlfM= X-Received: by 2002:a5d:63d1:0:b0:362:4679:b5a with SMTP id ffacd0b85a97d-36760a7832cmr575548f8f.16.1719558471647; Fri, 28 Jun 2024 00:07:51 -0700 (PDT) Received: from m1x-phil.lan (cho94-h02-176-184-4-239.dsl.sta.abo.bbox.fr. [176.184.4.239]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0cd72asm1339592f8f.10.2024.06.28.00.07.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 00:07:51 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v42 53/98] hw/sd/sdcard: Add sd_cmd_SEND_STATUS handler (CMD13) Date: Fri, 28 Jun 2024 09:01:29 +0200 Message-ID: <20240628070216.92609-54-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240628070216.92609-1-philmd@linaro.org> References: <20240628070216.92609-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=philmd@linaro.org; helo=mail-wr1-x431.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=ham 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- hw/sd/sd.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 1c092ab43c..bb80d11f87 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp) static const char *sd_cmd_name(SDState *sd, uint8_t cmd) { static const char *cmd_abbrev[SDMMC_CMD_MAX] = { - [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", @@ -1377,6 +1376,32 @@ static sd_rsp_type_t sd_cmd_STOP_TRANSMISSION(SDState *sd, SDRequest req) } } +/* CMD13 */ +static sd_rsp_type_t sd_cmd_SEND_STATUS(SDState *sd, SDRequest req) +{ + if (sd->mode != sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); + } + + switch (sd->state) { + case sd_standby_state: + case sd_transfer_state: + case sd_sendingdata_state: + case sd_receivingdata_state: + case sd_programming_state: + case sd_disconnect_state: + break; + default: + return sd_invalid_state_for_cmd(sd, req); + } + + if (sd_is_spi(sd)) { + return sd_r2_s; + } + + return sd_req_rca_same(sd, req) ? sd_r1 : sd_r0; +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1443,17 +1468,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 13: /* CMD13: SEND_STATUS */ - rca = sd_req_get_rca(sd, req); - if (sd->mode != sd_data_transfer_mode) { - return sd_invalid_mode_for_cmd(sd, req); - } - if (!sd_is_spi(sd) && sd->rca != rca) { - return sd_r0; - } - - return sd_r1; - case 15: /* CMD15: GO_INACTIVE_STATE */ if (sd->mode != sd_data_transfer_mode) { return sd_invalid_mode_for_cmd(sd, req); @@ -2279,6 +2293,7 @@ static const SDProto sd_proto_spi = { [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, + [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, @@ -2308,6 +2323,7 @@ static const SDProto sd_proto_sd = { [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, + [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},