From patchwork Tue Jul 2 09:19: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: 13719254 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 4D428C41513 for ; Tue, 2 Jul 2024 09:23:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZhQ-00013p-0x; Tue, 02 Jul 2024 05:21:20 -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 1sOZhK-000138-Dz for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:14 -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 1sOZhH-0006MT-P3 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:13 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4256eec963eso27749145e9.1 for ; Tue, 02 Jul 2024 02:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912060; x=1720516860; 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=cnrpgaba+viPx04OXDYFrUGjYb7FyAmcjVlf/y5TLg0=; b=Se7sgW/8/xFjnSfrFqKP66hNIrboEBT3Icew00IcMVU5iBcOw88GMBNG+SpGS8a21c MvrWJjdrW3jljhGWvcSgIneLaj4gjlNWH+UBtTp+j9cff+UrNsCA/9eKXUtCPjq+OIzr LgkdFXKld/9WH/U1p5hDT5x74K7+pgTyB/zKrJc0aCqtqQQbWrKsz0Ra1obnUZLCFZzm NWNKPSSv3BWXWPRLbDtOkfRmI/6jraxXd93DD7ZYW1LsCVu8EEMIBE6fRBlnMHLB9gCV SwWFukWD7m45N8FCul2bXcoN0elWGpeHL1+jOoYKd1Q0x29dWJqWRdh5H/HoL98vW30B N7aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912060; x=1720516860; 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=cnrpgaba+viPx04OXDYFrUGjYb7FyAmcjVlf/y5TLg0=; b=llogNf55xGtUxxwzy3I+x1zF4kpo/GZT3ePHVwyt9LTCE3P3q3gexesG996OYy3iLE +nMyfaLPId1ZxHUcYvmn+6A0lkMh4NAuEhCHVoFaVmM6Ld2f0w8FOlxVPUSw04AztoDj 8LasGUvb1gWFy5yXzkL6nbLXcnVweDsU8g64Ruzzb0sHglDQTCZ2+1Qpl4DQk0wH4wdI uD35phVoIRpPOOZyNhMdP2k0T46dhwMkXJZwsuKn5umjHeVY9NoGJ8BrX72kcsjzhisz 9olCelZMgJGCfJQxtzSF5oUghOCnV/ukl7GDRm0JLyegn4G4kiC9W/jurx52mtovTigw By0g== X-Gm-Message-State: AOJu0Yxts+EWZqYeh1y6Xzvn0SLFigDi5i9ErlgIZ/lXhjFiGMj/oMZd GOtDmq9XgCDtqPH6pBu/u3C2S7SpwXbae0T/U+EV+Ujs4EAqH8Nz8HQU8h3gXUbM6VHlc3WXXQw C X-Google-Smtp-Source: AGHT+IHPxlhz7r6hSMhYoxgitvfI9+nOoTze2Jc1cL/pyPJoZZ/vEextPI7QLr68ZFhmtJHj4d4pmQ== X-Received: by 2002:a05:600c:3501:b0:424:a3d7:2a89 with SMTP id 5b1f17b1804b1-4257a02c817mr49545515e9.4.1719912060238; Tue, 02 Jul 2024 02:21:00 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5b91bsm190794595e9.20.2024.07.02.02.20.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:20:59 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 01/67] hw/sd/sdcard: Deprecate support for spec v1.10 Date: Tue, 2 Jul 2024 11:19:44 +0200 Message-ID: <20240702092051.45754-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We use the v2.00 spec by default since commit 2f0939c234 ("sdcard: Add a 'spec_version' property, default to Spec v2.00"). Time to deprecate the v1.10 which doesn't bring much, and is not tested. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240627071040.36190-2-philmd@linaro.org> --- docs/about/deprecated.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index ff3da68208..02cdef14aa 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -362,6 +362,12 @@ recommending to switch to their stable counterparts: - "Zve64f" should be replaced with "zve64f" - "Zve64d" should be replaced with "zve64d" +``-device sd-card,spec_version=1`` (since 9.1) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +SD physical layer specification v2.00 supersedes the v1.10 one. +v2.00 is the default since QEMU 3.0.0. + Block device options '''''''''''''''''''' From patchwork Tue Jul 2 09:19: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: 13719249 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 EF97DC3064D for ; Tue, 2 Jul 2024 09:22:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZhR-00014A-7F; Tue, 02 Jul 2024 05:21:21 -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 1sOZhK-00013A-EL for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:14 -0400 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZhH-0006Mp-SN for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:14 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ebe40673d8so52306031fa.3 for ; Tue, 02 Jul 2024 02:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912066; x=1720516866; 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=9WSx0o0NoRwLFVmVIU2eDisxkgWjS2aVMQINVCuPfpI=; b=XMIHQ1Pc3lsDySUScGW8Qxm8t0/LEgjWpzGCoHUzLO91eVKq3QF/8VwBVTSuU5pjSs tbDH2FSAX8sRAja6rWnJq1p/uXLHdpFG/1kPaqvrhhfg4wFAANq6nKVUNzEABi4niHuH GbqGwmyuj++0i1Bw0bscBGK2d0f1d1I8F+sDHAuIKGFNnuvUIxtfGL9fjLay0wo+t5Bi P97lQTmbyJL9rq6uy5Ik8n+3GbwY5mdi/8l6Z52/iwXtNxORMOXkTqSzhHO+v3JOyctS vDK/fubtDPpBJYM02T+Qv5tPsx6cWpgmfzPX/L0gOFWoqZ9fRonELV99wAHpO0K2LdA1 Pxyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912066; x=1720516866; 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=9WSx0o0NoRwLFVmVIU2eDisxkgWjS2aVMQINVCuPfpI=; b=olVby9j+t9KRiNOsVJ+BRUvFUgaexy0og8RZLYlp1ZV1EWHjwWgsGPjV3PB5ykEe6K tRWV0+dJqKR/JBNOkNv2xFXYwhlyyi5RGcZHby9R8qjk7G3hw1xXSL8VoUAGuSy4GMXm U1yH301mNh/R1H5i+KZtd/b8AyqRty4J0IP7SNcRJ1r+7RltlpZeDVdhU7xv3ga9A2I/ q2SJp8W8p1cAcwEL3ukupu1/8ejapPOQhBaAgboQyPVl1FlInqbPMwolBgdOaMV7n3py VSTpDHIelF0QuQB9IFe64THr8gTm5hvTkeGOoH3iTM91gElTuEUV6W8r71cJfEWVS+7V Hd7A== X-Gm-Message-State: AOJu0Yy1ZQkfRw41dmjeLhibBh8Eryc3ZQUDdNPMBJarZ+ja9qrlsY76 8hJKFuAP8LIeKQksYsl/CQJD+6UFFfSGr7dSpRESdsf5mrBCSZYU3D3VhcROkxsjqIAG29qyI65 2 X-Google-Smtp-Source: AGHT+IHWVJWzLgH3m+hxe0oGMnEVH2MvcI2sJFuqkgD1m+lAutDZ5QDdR4yHVUI7nJGAMNFqrsE1FA== X-Received: by 2002:a05:651c:88a:b0:2ee:6cda:637b with SMTP id 38308e7fff4ca-2ee6cda6515mr35005801fa.35.1719912065944; Tue, 02 Jul 2024 02:21:05 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257cdf4982sm110219655e9.47.2024.07.02.02.21.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:05 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 02/67] hw/sd/sdcard: Track last command used to help logging Date: Tue, 2 Jul 2024 11:19:45 +0200 Message-ID: <20240702092051.45754-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::233; envelope-from=philmd@linaro.org; helo=mail-lj1-x233.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+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 Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-4-philmd@linaro.org> --- 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 a48010cfc1..aa011fc892 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -133,6 +133,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! */ @@ -1154,12 +1155,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)); } @@ -1620,7 +1622,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; @@ -1913,7 +1916,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 */ @@ -2069,7 +2072,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 */ @@ -2214,6 +2217,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 Jul 2 09:19: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: 13719247 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 59DF9C3065C for ; Tue, 2 Jul 2024 09:22:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZhY-00015L-BC; Tue, 02 Jul 2024 05:21: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 1sOZhN-00013k-3x for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:18 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZhK-0006NH-HQ for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:16 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a6fe81a5838so373974966b.3 for ; Tue, 02 Jul 2024 02:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912072; x=1720516872; 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=1tcC9Y5NWB8z03lpw+6038sronrJ1UL/8sqiqucfx+g=; b=Ud2BNiOFIdpDOAG4pBHaguQ199Wx4x7NgK1eREkyW1oBVCtNJHvx4400Q/3S9KrYR1 b+EQWh9+IlVQOZZSuQnefXCQ3o0utRHAZKhz1uEJDZQsnrjDQehThqZFbpwHOMarnFHo Q2U+zV9s0JhRKiSHPkA+qx6EeSYzpyf/whJrYcGFHU4jcwGPFG6f7nMpjy/kYskJMJL9 q927LBelfEOnm3ENx2DzDMwUXBf0osXPyDiW2fqKFiECjYA9ibNMtUMmdJEoJh6VBfYw Y+IO8+4pgVSyruFqsEhnIwm9Li06nxbNjspo/C0GgY//pH9fDX0awYRPfnat5ieSfgAE 44yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912072; x=1720516872; 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=1tcC9Y5NWB8z03lpw+6038sronrJ1UL/8sqiqucfx+g=; b=xLuATznzid2rR4/wnhvVVsfW0drMC+ik8TFxFVHD9vmtlL15ozc1c963wvUhuIfMEF mDQCahWqIX+V6I30AP4jUbseuS6vSHFcryPKLBUgXCAppDGACI3LVg6m8ohUIqCBa3KL UMO4Tz0bEOo+T3vtLcdQvZk6Z3AXm5WEAPhDvjMG9GQOhwsURX8lNUhaoWyPsSxqnvmr Gir8xERsdrYrVqhZuS8Roo8AGuymgzOBFCwIUgrTcrTzvPAUiHqG71gsooG2g66taCyY 8oszY7O+Cd/Y5zuhUM8g21TRHCfgNnc4BiY56f9gcd8A6D/jyi4jXWWFEz5MDiB+4s6h z54g== X-Gm-Message-State: AOJu0YzTnAXjRWV4lAykM0VJ7PS3+sb2pHh48UqNTY6pA+XtmB95bmuk yp3D1fou+Idad/V2gf9JnVOzsNHtWBMFSnZhLzLDj8miZPYQUZauJ3k2Ubk40ddX10USC3BNTx4 4 X-Google-Smtp-Source: AGHT+IGU/aJ6GrLp7nonzauh+bQHgQa5y5ziOOSJJVSf/Tjb/X8OrbFvDLhJ/fskfLFB8GTFJ3RhMA== X-Received: by 2002:a17:906:a02:b0:a72:840d:9ecd with SMTP id a640c23a62f3a-a75145120ffmr465071966b.64.1719912071705; Tue, 02 Jul 2024 02:21:11 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0e16b3sm12563292f8f.61.2024.07.02.02.21.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:11 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 03/67] hw/sd/sdcard: Trace block offset in READ/WRITE data accesses Date: Tue, 2 Jul 2024 11:19:46 +0200 Message-ID: <20240702092051.45754-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=philmd@linaro.org; helo=mail-ej1-x636.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+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é Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240628070216.92609-5-philmd@linaro.org> --- 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 aa011fc892..bed5966ea7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1917,7 +1917,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; @@ -2073,7 +2073,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 Jul 2 09:19: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: 13719246 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 D274EC3064D for ; Tue, 2 Jul 2024 09:22:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZhe-00015k-Uz; Tue, 02 Jul 2024 05:21:37 -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 1sOZhR-00014Q-GR for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:21 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZhP-0006PP-PQ for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:21 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-52e8cdc6a89so1784596e87.3 for ; Tue, 02 Jul 2024 02:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912077; x=1720516877; 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=iQfrPXIVuGN0oE79GXpdgy4bI5RsbRBBNBkn9X4U1bk=; b=FNKx9hpylo872ESTWUhp+xvNhIA53R05exbCosIliovQ3FRqVF4MCkjOoxSV9zHjlH 60gd2er+5KuilRgvYxAAtHB3JC2Wgp+RgkKWK2pYVtLI7pARleawAEoiaKgUPRI1y1v1 LAwv30CBFBdZi5K4DWUIzzGXPEWP7XO4SSvGsTA2BEoyhdBRxPQPp/DwjLWwHi6s12YO rSxqSQB7IkQngiRzISFbcQB9U5btQhsUhl1qXd5wm4n8DY3/n1JRPx3f2nFYNvSJL86e zmLqKL4Kf6x9fMvbR6t9MCVq04GxSCf8fDWSatFFPdvUy2du/lDPHCwShqU9TMA7BRbr rFBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912077; x=1720516877; 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=iQfrPXIVuGN0oE79GXpdgy4bI5RsbRBBNBkn9X4U1bk=; b=T66nwAErTHEZ3gCEaJbLIIrqsJzJEyNtDd7ZgsPG7CmZjFhQoA+Cc6yomjJW3HN7cm bbJ+m5yBzfOHhSwMSg7s51zcpcggE0pqJQnRRWGxI773NuOfsB3xyTxa16nyza0BOluD IqhyTbYkjuKJnzDebz6JodWtDLgV7YqcvhK0cA52JywYTCZuK7N1u5MJt1J7W7e3lgqQ Iax0JX7LIMHccEr6QsrJnyCFCKM2KSePzUCZCi4pAZ3EJqwyHlFLaGntKlg6Aru0dpaT Vt2gRZytqT9UH1jm3hZESh/gp/d2iWBmwvPK0vX6ClUsDAb/4+NO5DPYeKos6iLWxVhH DpgA== X-Gm-Message-State: AOJu0YyEMMoahrOIs0fK13FH02CfCqWEt91S2SNvPC+c2M4I9mVJMfq5 M/NloFrStegPOi9h3DCUl3Cx9+8WK7uWi0jqdT95zxlNcqM5CJ5oF72OoqDoYfBi5aJUgoF9RYt y X-Google-Smtp-Source: AGHT+IGOxIw7ouZ79tIYf9ewE5M1amNlwXiC6EHNhyETStwMt9tPgTM3Q64Bm56JtxyOkAa4BBikrg== X-Received: by 2002:a05:6512:3d1d:b0:52e:767a:ada3 with SMTP id 2adb3069b0e04-52e8270ea83mr6302268e87.47.1719912077534; Tue, 02 Jul 2024 02:21:17 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b065316sm186926295e9.26.2024.07.02.02.21.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Luc Michel Subject: [PULL 04/67] hw/sd/sdcard: Trace requested address computed by sd_req_get_address() Date: Tue, 2 Jul 2024 11:19:47 +0200 Message-ID: <20240702092051.45754-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=philmd@linaro.org; helo=mail-lf1-x12a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Luc Michel Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-6-philmd@linaro.org> --- hw/sd/sd.c | 9 +++++++-- hw/sd/trace-events | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index bed5966ea7..396185f240 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -608,10 +608,15 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response) static uint64_t sd_req_get_address(SDState *sd, SDRequest req) { + uint64_t addr; + if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { - return (uint64_t) req.arg << HWBLOCK_SHIFT; + addr = (uint64_t) req.arg << HWBLOCK_SHIFT; + } else { + addr = req.arg; } - return req.arg; + trace_sdcard_req_addr(req.arg, addr); + return addr; } static inline uint64_t sd_addr_to_wpnum(uint64_t addr) diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 0eee98a646..43eaeba149 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -50,6 +50,7 @@ sdcard_ejected(void) "" sdcard_erase(uint32_t first, uint32_t last) "addr first 0x%" PRIx32" last 0x%" PRIx32 sdcard_lock(void) "" sdcard_unlock(void) "" +sdcard_req_addr(uint32_t req_arg, uint64_t addr) "req 0x%" PRIx32 " addr 0x%" PRIx64 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, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x" From patchwork Tue Jul 2 09:19: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: 13719255 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 D4003C3064D for ; Tue, 2 Jul 2024 09:23:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZht-00017z-Ae; Tue, 02 Jul 2024 05:21:49 -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 1sOZhn-00017F-23 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:44 -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 1sOZhY-0006QB-9V for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:42 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4256f102e89so26449405e9.0 for ; Tue, 02 Jul 2024 02:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912083; x=1720516883; 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=c2posFVIHwJJjgAbr7iDjUeWrApT5m+MP8zp28Zi0QY=; b=wnU6ueupR7UviJVu5I+ll/Mp37YvmIKMeTcxNrwzSH7TGnw+1IGYWx9bI+rbMdLAqV /orqb7tba2FmrNvKCyjuaDDcDmso0epaamgDmJB71BNHkQIhD3ufkd0HaPWY7lzFcYzm S7tbDWA9aGKZg63Y9IFQj9RZrVR64vfLHkPqZYxoNL/mOSfBl5xcAdrXyKpCNTFOBcFd 4au5a2SrpC8IoNAShFVFB68l1fqra0DuxEVfgxINUWuCdjocREB96RYo1THIBhFr2x8X jJZ3H+4lMB7fdTiiJA5LMNrANKBLc/N7zQzrzf8MPobd6H4wyklt0hDEmTfLOsqNM8Ei ES4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912083; x=1720516883; 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=c2posFVIHwJJjgAbr7iDjUeWrApT5m+MP8zp28Zi0QY=; b=KynFcKJFZC39byPyl/ePPDcyBfkPrfeguTFP+1eKZ2ogizbcjIcRLdVVJZZjeZQLc4 5qO9WVNCLi8mxCTjDKK9mT5/tPBxwxXbS48NX9wiik/NbpNO6P5U2xqgAO8H0QC93ELP Ls3obVXswhv9SMRmQEpejX2EqWHOOAIOWjguLaonQM0w9rm+FpCMYiUW6vfsYR0rKd7R g+3hN1kC9KPnv5Ui7WulypXlPLCjDq1JNZypLxQ0eszuyJoBhWs2yKSp3GjWUXqwLsaL EV+qdQdfBgsasxHbp8KDP+fXF+hOkQM08ucmrCAmDgH1LuxDRLkZwxV+g+pyfh8ZDiXv SqMw== X-Gm-Message-State: AOJu0YxXw+LKmK0iOY/JYACHB7Pq697DYf9wrk067QZ4AKkajpycMJ4F O/DryTlN2dHysauPW4VqygNg+CGSNN+2McM7LdLO6iBzh39uXCX1Z6LOi9wob6MfH9cUaEMoLQX P X-Google-Smtp-Source: AGHT+IGte9R6xiYW5SqkLbrW+IB8qetJEeYTqv9WUgIcE2IVzrYUR9SueKv5F136tgSoL07NMqI+tg== X-Received: by 2002:a05:600c:5cb:b0:424:a4c1:6ee7 with SMTP id 5b1f17b1804b1-4257a010baamr52164595e9.18.1719912083293; Tue, 02 Jul 2024 02:21:23 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a102bc5sm12637966f8f.92.2024.07.02.02.21.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:22 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 05/67] hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6) Date: Tue, 2 Jul 2024 11:19:48 +0200 Message-ID: <20240702092051.45754-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+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). Fixes: a1bb27b1e9 ("Initial SD card emulation") Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-13-philmd@linaro.org> --- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 396185f240..b5d002e6d7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1204,6 +1204,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 Jul 2 09:19: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: 13719263 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 B78A0C3064D for ; Tue, 2 Jul 2024 09:23:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZhu-000185-4J; Tue, 02 Jul 2024 05:21:50 -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 1sOZhq-00017Y-Ur for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:48 -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 1sOZhk-0006QR-1A for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:44 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42138eadf64so28144995e9.3 for ; Tue, 02 Jul 2024 02:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912089; x=1720516889; 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=ZmproyIzBvgthgzgc+ED5AQDlzk9eDrpZD0ggY0YeFY=; b=FY0qDnMcAh/sB3kwJNrEV+Rvx34EV8btGzMGUWyfDjOyGWOfPWju8ZR9OfkKNZp2En Fdd8L1ZU+ypsw5hioN7wT2pAEq6b9xRtAvte9yKm55fBgFGozCDU/AERYFaqLhQ0vL4P kG5KR4uXgHfkaa0sxveqs9hm4OUw3iau5SRRDTbImxLfdsO7eE37I19e5MK2DAoLSM4y 85S9t/0xzAm2Ctz5lC8Lo1n83lc0jdQVf39GS8j2d5lMQ1dnnjgiBIdjhUj8t/heQ34h fDVYe7HBVWcL5lecr4tV07mu/CteGTtQJ6hmmeXYuZKKvfSZ/pjPhUoWArWxUBIwx2fz dnQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912089; x=1720516889; 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=ZmproyIzBvgthgzgc+ED5AQDlzk9eDrpZD0ggY0YeFY=; b=f2RCZhp9+uIbWjVcXDHEnf7nkPGVz3wt26hNI9AqU9Y5v4VnvE0S8GwmKTYjGDRnFo XOP0O+9I2D4zn9Aweb2EPOVeJVPv8NOYCcypV6kBjQI68ujAoqHfO2b0r5P61e6ixINH 0iAkl5dnd5B/PESkqbQcNIyVR12ZdSksHItN1JUlu15tu5rNg6iyqF3stjqXucZKve2B vEqKBkl4erNBFs8IlAOAAEfYFZWy8cuwpbsjM5o3CEtQ5IkqLj6CslmyXOMCP1cE93cu jhWZxpOrf5gsZqSBJNze24WruGUPxSDSQ4+XBC13orHpQnwj2hoSv0X9L5u3z5+A2r+l qsjw== X-Gm-Message-State: AOJu0YwNGGg3+z6bp06Ukx+XqJ3BFxS0vInrA6YCQDqfRUtU0T74NtxJ 9AMMaHDJCny1c4BwRegN7IUZdp0YwrEyZWbB4vsuJYgcoq24kX7ZHJXKlALC6m+YAlDuRCQAIC6 E X-Google-Smtp-Source: AGHT+IHFNxXTD0/30qhzbq21YUuPH9Yct0X7Umm3cpEfcUCir90HhmG7zaAd9h6xfOrKzLzotcp+fw== X-Received: by 2002:a05:600c:491d:b0:425:6d66:e432 with SMTP id 5b1f17b1804b1-4257a03a6c8mr54270855e9.22.1719912089186; Tue, 02 Jul 2024 02:21:29 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af55c0asm188276115e9.15.2024.07.02.02.21.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:28 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Peter Maydell Subject: [PULL 06/67] hw/sd/sdcard: Send WRITE_PROT bits MSB first (CMD30) Date: Tue, 2 Jul 2024 11:19:49 +0200 Message-ID: <20240702092051.45754-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+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. Fixes: a1bb27b1e9 ("Initial SD card emulation") Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Peter Maydell Message-Id: <20240628070216.92609-8-philmd@linaro.org> --- 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 b5d002e6d7..1e9530f9ae 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1508,7 +1508,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 Jul 2 09:19: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: 13719258 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 780CAC3064D for ; Tue, 2 Jul 2024 09:23:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZhu-000187-Bh; Tue, 02 Jul 2024 05:21:50 -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 1sOZhq-00017X-Sq for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:48 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZhm-0006R6-8M for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:45 -0400 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2ebe785b234so40005991fa.1 for ; Tue, 02 Jul 2024 02:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912095; x=1720516895; 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=+BJVqbuDB73td3icnKEL+Hn1IcWwELHqxD1Mx9jzZME=; b=SN9ZqQb2ehnCRFlBL5bHkWdxGBIhpsiuuNYFscBAzs1Fd+JisZiijgV/OR8iAe2YP3 rqSOyMpXj3va7W3GCmZhEQAQjfySW37nppdZdmxb38cTLC1OB1W/9ApwTtAJ+kIJMSS7 qfbgYueMvXnt8pjIKAmt2CoolVcBVwb/GOj7pspDZCO8Ex8MOM+NuNiIkYpE147D929D eFR5F2mKLFMCrl40zNDbSzHsTUZMSbQS7RRi9f2Tbkdoe77ePHVqxiFZ24op+OZrQiVQ Df53Ko84p/Q41zsfarf1LkAN4aGKtwZB6QX0fOb4z9xMnHsamKsOlScFtwwB5+/SJKBp Z0bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912095; x=1720516895; 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=+BJVqbuDB73td3icnKEL+Hn1IcWwELHqxD1Mx9jzZME=; b=htDGm6ISl4Es3h7u3bAffGLD8kEDQaIbP1XW47QhWhQy8iADKiqcREOkB7JupYlJNe uyBKJ2MaK6U6/AWcmQ2oNoEZkAVSNrTkx153b8o6npX4pAVK196sEosKDmyAWr28ZPRn OtbGDOfPRpiBSnIGkNo3RuIRwLTEM4KX3Y/2Pz01M5rwQJ+AnmCi5FI9L4ErpkGJBZVB WXXo+t/5NzNRhTkByPmV2ZhZafiDoHc65hTScgXGXbc1uMQcqe8rDnq5wOfwyQj3iwtO 6PmOcTOdBH0qXCGKkQEYl7+Op8IPzkxxrxDAJsgnruw77mxCyzpxgiQ0dkkhOIJhTDSA fYVg== X-Gm-Message-State: AOJu0YzbPNETf2VL8/EVj+nMo2uLILqgVKzKPvy4JSnmtaNNGMVA72Cp yvNPmiBp4MINhiKpTHBVlVhoe7c+aTBikIEuc7OvazE4Po1asIN2daaeX224S6zl5uXjiqUTeEU T X-Google-Smtp-Source: AGHT+IFl4hgc/yNQvJmQgunSI2cYavv9Ubr3AySMQQr/t3A4wpxrrHGW7+Yf3Ylnz+5pjaauUWC1uw== X-Received: by 2002:a2e:9793:0:b0:2ec:5518:9550 with SMTP id 38308e7fff4ca-2ee5e390c38mr55097991fa.10.1719912095005; Tue, 02 Jul 2024 02:21:35 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b09a2bcsm187830895e9.36.2024.07.02.02.21.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Peter Maydell Subject: [PULL 07/67] hw/sd/sdcard: Send NUM_WR_BLOCKS bits MSB first (ACMD22) Date: Tue, 2 Jul 2024 11:19:50 +0200 Message-ID: <20240702092051.45754-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22f; envelope-from=philmd@linaro.org; helo=mail-lj1-x22f.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+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. Fixes: a1bb27b1e9 ("Initial SD card emulation") Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Peter Maydell Message-Id: <20240628070216.92609-9-philmd@linaro.org> --- 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 1e9530f9ae..54bb0ff1c9 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1669,8 +1669,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 Jul 2 09:19: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: 13719281 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 325E3C30658 for ; Tue, 2 Jul 2024 09:27:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZhv-00018E-Ck; Tue, 02 Jul 2024 05:21:51 -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 1sOZhq-00017Z-VL for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:48 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZhm-0006RG-Oz for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:45 -0400 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2ebeefb9a7fso44908401fa.0 for ; Tue, 02 Jul 2024 02:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912101; x=1720516901; 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=YMu0JsqJ0+r4fsG0B6FCI0Tvxg5Vyf5673gOlduh3A4=; b=jQYZFj+uVo+5j4n/xXlgwk41bH0Yj23Og0CzQMTuLa9jqGSwWlhrfkoATlGfkms/jf r4xx3XGGz4imNC04eUni6RytnCyL/RGxvJgVShygZNw0pIsk+lAgn4LTSFvgVNV3I08u ImAulvZWhNoDFlRXk96qMd/DimPrHZazPu/jnJjhccBi8jUfcN8jlRkBot4JWdqa7509 /BK1342PINeN9xA0utQio1kxct2A/ubOxamf5+oVPq9ZKdKXCt2UDOOF8I/EMeZw8ZiU B0o2dCisBnn4k+vOGjUvn0tb7CEFMyahNkDATWTJRwITSt3l54zCMapcD18K2jmnnLcA TEYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912101; x=1720516901; 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=YMu0JsqJ0+r4fsG0B6FCI0Tvxg5Vyf5673gOlduh3A4=; b=gC8pk/ewTYHH2b01ATZ3BoCN++R2BtfpsL7D1tpVWiLbIRfBEcB08pVpP+NrLW0A1U jLpXOE1bgCaUMkgE0uM1IUjj9iwt0faocRLS5CbUKk5v016aUZCb3S4Z1nBtHqgQ3urR z8BpRC3fk3loaiJjIPqlZBP0ZJic62/8PgscPjFmtbjtgR4jN4xSH12t7qKgSJL60eiZ LZxix16HNx8+7VoajyAq7xMMCpIYf5HTX6b+hrzwwLfvDF5TaL0qDIlrjyRI4qvnNjZA 2Ed2FkIIy6gyQcSCp37njwFphzA0FrmWjGcoTQJpcJopZ4boK21WDR2dfaM2S2K3bXHW wXhQ== X-Gm-Message-State: AOJu0YxmJZc9UVLZ3be8PiN6JWGu0xBtwzlXjF9UX0AI3GrV1EKx7b0z fJjVIOaqgxgNOzO5MdiOlDm1IgyHYK1JbHX/koYJD/ATNADQSNvTRDwaW1/cAVrD/Tg1IzHs/hl Z X-Google-Smtp-Source: AGHT+IGTFyBDZeJPw+gvfFHQBWO49c5VRJeaK2/vCzHi8dXwV7K2qqIFzsbKrFaSgYtqTDn5VYU+lw== X-Received: by 2002:a2e:9dd4:0:b0:2ec:4e59:a3de with SMTP id 38308e7fff4ca-2ee5e3811eemr50130121fa.10.1719912100813; Tue, 02 Jul 2024 02:21:40 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257c4e10d6sm117669665e9.30.2024.07.02.02.21.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:40 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 08/67] hw/sd/sdcard: Use READY_FOR_DATA definition instead of magic value Date: Tue, 2 Jul 2024 11:19:51 +0200 Message-ID: <20240702092051.45754-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22f; envelope-from=philmd@linaro.org; helo=mail-lj1-x22f.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-10-philmd@linaro.org> --- 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 54bb0ff1c9..04ca895645 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -559,7 +559,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 Jul 2 09:19: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: 13719265 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 EFE8FC30658 for ; Tue, 2 Jul 2024 09:24:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZi7-0001Bf-5H; Tue, 02 Jul 2024 05:22:03 -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 1sOZi3-0001B8-4e for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:59 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZhs-0006Rv-Qv for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:58 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3626c29d3f0so2001288f8f.1 for ; Tue, 02 Jul 2024 02:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912106; x=1720516906; 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=VFi1L5rHZo7v36UetRUIEpZ+be6zBjT18RH5cfq/7Gg=; b=c04R2OBLwAdRAp7Nu2BSr46oWCvvpqAK+LMr4dgjMbXGFmj6UtsqdokCA+h12EP8Ft 5p7x0iMAhjaFe3WJpdVqI3cC7pFi8s3YcrLsDkEIqK61ok12yGMxZZcfphc/EYyUopSa cvLrORWx/5t01x2wzfWAM9t++wNUllM76BA6gI3jjai98HbP81XQKwehe35ddLc/Fmdy YkOOkL+7rNPkU6MLIW7KRlDKq4wRBS8Ub6lefVXKpXE+7SqdWKkV+Mqv7HmQ8REQexHK GO2u32lY3/DkDebEPAs+Vp268Knadj7CsXfIjxMWEH+CQTrvwlvm5QcKZxIEixGGzRwi 9EkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912106; x=1720516906; 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=VFi1L5rHZo7v36UetRUIEpZ+be6zBjT18RH5cfq/7Gg=; b=q2Q00cghyY9VgcV914DBMtIHUyjG3Sx2CiFguSl+txirczVkMa//rj87oXR36bQBI3 azu0xyM0j4cCyAXpVRD4SI8+ihr1BeHl2kSL8YN3TVeJGcd3e437CNwYNmQhbvZSgzly xwx2HixS3AMd8eVg3oaHs35qeYZ7c3oLjC7jHTlMt6BwuGPrw9WxiV8KMWGHF4ACg5N5 4UJQWSKC4Zfak5j/UnwGceOHt8IIVCCr360knPXuQS/SnpPQVytPo0qeOLNk9b1i9GGE cZY1trTSAybLwz3i6IrbSOP35pyMB7LizhC9JvvjWpUjUEgbC7h1XL+ooA5K8TW18Hqu 3PZQ== X-Gm-Message-State: AOJu0YxZyD6GV9wrtGaQAuqzB8pqkBapv5xH8lgSa2NgiPq8JDm4khPW oMMnsBl5KmhSdcDOx8REuCr0a9o7ZQzD/bc7SfxiIKB9Lv/I9bhOrfK2SQHPnIOnme9IFl7LSr2 E X-Google-Smtp-Source: AGHT+IEjxuGo1JugIYNt9Bdp0vjfFoKrw5zuqh/q78SNC2KYw6irvDg96k7GUTKIOea8ekxX2syeBQ== X-Received: by 2002:a5d:4043:0:b0:366:f8c3:ddcb with SMTP id ffacd0b85a97d-36775725c6emr5347764f8f.52.1719912106566; Tue, 02 Jul 2024 02:21:46 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fba2dsm12653980f8f.73.2024.07.02.02.21.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:46 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 09/67] hw/sd/sdcard: Assign SDCardStates enum values Date: Tue, 2 Jul 2024 11:19:52 +0200 Message-ID: <20240702092051.45754-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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+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é Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-11-philmd@linaro.org> --- 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 04ca895645..824cb47856 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -75,16 +75,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 Jul 2 09:19: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: 13719250 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 A7DDAC3064D for ; Tue, 2 Jul 2024 09:22:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZi9-0001CT-96; Tue, 02 Jul 2024 05:22:05 -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 1sOZi3-0001B7-4e for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:59 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZhy-0006SF-Fn for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:21:58 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-424ad289949so28596435e9.2 for ; Tue, 02 Jul 2024 02:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912112; x=1720516912; 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=VGAqlXXmWHNhTh9vgnZWCBaKbJgiHWhA9edkrjy7PcE=; b=Ak49Db7zbTHvDl8yDot8XOnyehNXcLQNBGbjbwYuqSuBk4DWQIF/mE4Mc59MgU/5aT 2Dww1kBNkTQGrkXWhvER05zKobR9Gh0pEK2FlUIeNeVnzMDvqcZ5lftDhIyeFNDpeVa0 VPcmzB7pRksBQUfv6atbHZn2OmxJ1tt88q527+XLniC/GRhQctDariVb5Zq9BrKRhMAS 4G92+lUEgrODE1wh+wcP0us2nOBqiPW8aTBN82US4kTRutqtr5kpp9fClXup2vA7aCih GB80jxj/y4rFJFn8ox4p15vapOeHHKyfOhQrowwb7WCIjoVrtPDCwk07E+J/N+WMKB9Z 0Vrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912112; x=1720516912; 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=VGAqlXXmWHNhTh9vgnZWCBaKbJgiHWhA9edkrjy7PcE=; b=VaZys4X3z21yRy8Mwd+PsqvGQm9lXeI8XDEKJD2SgLy285Apn+uA5k6OYYMAi/T8Rq bW7/SXwyuq7fQTyT7sXSVYmjxsA/GSdIUBZ+LFYdcmTeGVfVtp7rOpHDkqsOjfdKnPI5 JZydVybksNxF5Ad678T+zvWLjEuHV3oqxnuIGOV1Ej5HqjNPHDYOq+8os8y7bETHpqL5 a2OvWcUODhQNfBWwrgmwbTnWQu0irIKRZCJ5KoLSpiD+yAlrkCavO1wJE4//VeHFC7gG w9huUaB4mQYgvz6s3d9cnaQfRc5TpfvB9t/+ewEGrrsApPDOh09csMW0cPibK1qHy8cb dz5A== X-Gm-Message-State: AOJu0YyiqFWaBi9DVQTNefCNWXie+vheSwat2A+DMqu5INtIDK52SuXM TfizepVBGVneSlx2bJC5yM77IsOVZiHWNwrMzWd3V2U2KVqBxyungRONG2t2WQuX3TO9Oz8ffAT S X-Google-Smtp-Source: AGHT+IHQJifoKcqTa8dDVQmj1rRhk+XofTXeCiT3xFEJviYT9/2UvnbYF49qTp76g8ymgpcGDuZLJQ== X-Received: by 2002:a7b:cbd2:0:b0:425:5eec:d261 with SMTP id 5b1f17b1804b1-4257a02805dmr62707875e9.34.1719912112410; Tue, 02 Jul 2024 02:21:52 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257a2f7451sm132918665e9.0.2024.07.02.02.21.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:52 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 10/67] hw/sd/sdcard: Simplify sd_inactive_state handling Date: Tue, 2 Jul 2024 11:19:53 +0200 Message-ID: <20240702092051.45754-11-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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+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é Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-12-philmd@linaro.org> --- 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 824cb47856..30c1d299d4 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1078,10 +1078,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; } @@ -1580,7 +1578,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) { @@ -1801,6 +1798,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 Jul 2 09:19:54 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: 13719256 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 EB5CAC41513 for ; Tue, 2 Jul 2024 09:23:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZiD-0001D2-RM; Tue, 02 Jul 2024 05:22:09 -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 1sOZiA-0001Cb-UO for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:06 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZi4-0006T4-Vx for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:06 -0400 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52ce01403f6so4485385e87.0 for ; Tue, 02 Jul 2024 02:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912118; x=1720516918; 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=E+5gh8hAsErYp4RFAc5dc/YmikXj+fQzAy2bjo6tyAE=; b=sZd72Xofb7JNwg5WXV63oFK9qFXkO6+I5w5srUOL2wsyAnLpiGxwnJgX3/wZaoz3GC hF9EZb+h9IceG5DOjLxpAt4p7soNvxosW8+y4Eh65VTYZhyF4sBChj1VtLSLCHqEDEet kkUh75ALRwYhVcsj89jmO7grd+I+rRJo4iYNhlMukTvg2SvcejfFdV4mwgeHZCxV2RQM Toqxk+sc/TD2q9DkNNT/SOB+XPz461hCAkxAwz+m20Ez9f/9sLmLMY+YvETdVEUKR3WE UlfgQpV4JY027i71TLadRM+Q6M6kPzLCkBkAf2neLAamSVf10hQ11AXREw+ytK4y0EW6 SGXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912118; x=1720516918; 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=E+5gh8hAsErYp4RFAc5dc/YmikXj+fQzAy2bjo6tyAE=; b=sLEJgAk8p30AtIhe2EGyAhE7nD77uM8MyhDioyXWFhF4jXbCe3EF/yfhM14r8fPZhw 4li0VKURYS8ecHvz8QjMQ3vA/756+fZ3ry+MR8XszLTx28Ya5IGeKurbq8qkmgQWOrXq SYFbesuTruLECDUAHl6nm6WmO7NyJjB5KuACkn5d10QWdj3oz6I8TtjVqB3IP+nOlQER f7sKFcZdNyWWY9vixLshmmXFjy2jin2HgYNOtT93qXJefHi+F69il9vzJfK24njz6U0q PT6alyyXN/a2zd6tMTZ039XiL3lvJtvy3PIoQZyPGtLdWVBVmZkGgBeBNJL8y2aJi0mt B0PQ== X-Gm-Message-State: AOJu0YxhTbGb+USPhiYy5mujj+uyMIXZaRW/lhM5w5+GT+iRng7uQKJF bQ7mx0/NDiMfXisR4ylA/I1j7ZXKGKqLYsUwdj9iiY1uWohHuem8Y53FkgoQXvQ0j9+2jC3wQIb X X-Google-Smtp-Source: AGHT+IFZs43bdbE9ypnEpwVwEfr3iKDwxS8qh9AFYj5Jo2NLmRIGnZyBN1E4MPkrpaFrvFpxymb3IQ== X-Received: by 2002:a05:6512:acd:b0:52c:caa6:13b4 with SMTP id 2adb3069b0e04-52e8264e4ecmr5958184e87.3.1719912118085; Tue, 02 Jul 2024 02:21:58 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b09aa32sm189743195e9.34.2024.07.02.02.21.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:21:57 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 11/67] hw/sd/sdcard: Add direct reference to SDProto in SDState Date: Tue, 2 Jul 2024 11:19:54 +0200 Message-ID: <20240702092051.45754-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=philmd@linaro.org; helo=mail-lf1-x134.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, T_SPF_TEMPERROR=0.01 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+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é Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-14-philmd@linaro.org> --- 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 30c1d299d4..d06e670024 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -116,6 +116,8 @@ struct SDState { uint8_t spec_version; BlockBackend *blk; + const SDProto *proto; + /* Runtime changeables */ uint32_t mode; /* current card mode, one of SDCardModes */ @@ -152,18 +154,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) @@ -1041,7 +1036,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; @@ -1050,7 +1045,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; @@ -1059,7 +1054,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; @@ -1070,7 +1065,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; } @@ -1163,7 +1158,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)); } @@ -1182,8 +1177,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) { @@ -1629,12 +1624,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) { @@ -1925,7 +1920,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) { @@ -2081,7 +2076,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) { @@ -2226,7 +2221,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); From patchwork Tue Jul 2 09:19:55 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: 13719275 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 75293C3064D for ; Tue, 2 Jul 2024 09:26:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZiM-0001aV-47; Tue, 02 Jul 2024 05:22:18 -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 1sOZiE-0001DD-Me for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:10 -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 1sOZiB-0006TZ-2o for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:10 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-36701e6c6e8so2081742f8f.1 for ; Tue, 02 Jul 2024 02:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912124; x=1720516924; 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=UnOllaloZd2LpX3vFv80SvvLh9z9PQTQVpVybu389fk=; b=a4nUkmHvgRvGHnwTeZpyIPn5DxWLPUvquPd9JG0OIBdM0Ogcx8IBcfB07jRpJeL47o aOYiz2OWyVttxh9qmV8nWZr44BWpNenywbfH9Ux4HTJwYViNLcMchda2dHMdfi1HQfzQ XWY+5bxudzsu6VQZmV8AMJLV1ObaEneeAHtGl2Uti2Jo2NJ0gu5IOMzGNy+g68FqnlMm RJF/f9kN/IvO5dgy2atb2C+7oK5zo6bmmqaExQaKC8dlN0q7z4x6KGCjkzqYQpTn9s12 7vpSEIbey4ZkIT2xhdEKLRaby5aVU/G9w2OpHjNA+djUOZt66Ei/F49HfmegH/CHM5j4 6BoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912124; x=1720516924; 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=UnOllaloZd2LpX3vFv80SvvLh9z9PQTQVpVybu389fk=; b=DdwCfvBeEim6Qm0KW6wqfOcTpGMixrn+Bj9ojEMh0VkA841FZ90Kbd3ik32VjBtuWs gS9AoH9/urnZ38w/zhR62M7qXYid1EPHrKvBwkSK7cfskZnEjttSOICqjkVODtgX3QkM yFNub/rOK8dty3bW8g6Sw1QXWwuwneQ84rDQuy9MnVLMCcowymoEWyRibz5F0GbvwGyz ksGxgibyMTwj1oV7PDCz6pSJOQrp+zHXaCaH+Jm0SKUblGoXYsT41p2mz+J9jUSizQ0G zvMrjCylud8qcFnRMNd3+hPGwmSsb+Db6lyxxglG+HTzGo1fcXIAe0Yf1twc+xHeDkBK VpoA== X-Gm-Message-State: AOJu0Yy/kGA8BzABWZ/SFMqGbA1ZAGREg/PC4rjvA+I9G38/4v33Mgi/ 5CDXNjBazrh4YdtjDJBCz1APKs+aAUziajwAY1HqZXGFIb7Iu3DZ/+NNxanPO+FOcsUbNaseKii x X-Google-Smtp-Source: AGHT+IHju5XOnoUEOYhXnMrBJVLUIy4u17BDJpufv7ADzH4D1RqV0gz4w2Cs6Ws53fE83wn1OjM7CA== X-Received: by 2002:a5d:6d8c:0:b0:367:1a39:e323 with SMTP id ffacd0b85a97d-367756bb528mr6296189f8f.31.1719912124237; Tue, 02 Jul 2024 02:22:04 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0e13d4sm12852900f8f.56.2024.07.02.02.22.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:03 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 12/67] hw/sd/sdcard: Extract sd_blk_len() helper Date: Tue, 2 Jul 2024 11:19:55 +0200 Message-ID: <20240702092051.45754-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Extract sd_blk_len() helper, use definitions instead of magic values. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-15-philmd@linaro.org> --- hw/sd/sd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d06e670024..18bb2f9fd8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -601,6 +601,14 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response) stl_be_p(response, sd->vhs); } +static uint32_t sd_blk_len(SDState *sd) +{ + if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { + return 1 << HWBLOCK_SHIFT; + } + return sd->blk_len; +} + static uint64_t sd_req_get_address(SDState *sd, SDRequest req) { uint64_t addr; @@ -2074,7 +2082,7 @@ uint8_t sd_read_byte(SDState *sd) if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) return 0x00; - io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; + io_len = sd_blk_len(sd); trace_sdcard_read_data(sd->proto->name, sd->last_cmd_name, From patchwork Tue Jul 2 09:19:56 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: 13719278 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 293CAC41513 for ; Tue, 2 Jul 2024 09:26:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZiM-0001eU-Hw; Tue, 02 Jul 2024 05:22: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 1sOZiJ-0001QQ-0z for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:16 -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 1sOZiH-0006UE-4b for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:14 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-362f62ae4c5so2250208f8f.1 for ; Tue, 02 Jul 2024 02:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912130; x=1720516930; 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=XqX6iaUQgzL1offrhP+HrFxeqPqsVcUC+AhsVlpqm/g=; b=p1t6KJV70eZsL15wNHuZpbnL3b11zlNsYJEATh/eGjHZcv04hEFe/sumsaFSwvNr78 UxVQv8YYeCSyhrHhvSK+Mt+7nmxUVIICOPvje7rgkaDisa7c7sjuJcIx3ICiRaKclN4/ dMhQW/g5YzSkwBET2pNqfvMteZh9jKuLRhwO0W5RYfDgboeYX84UWTp5c3fRhFCHOAAU OpjP2dR10LoROusD5U/9hgz9T5R73S85fWwix98CbrjLSNgVZqNgNAtPHTC4JvgDZrDH RkHHqsuOQ5bmmI3W0Qxjju+521XWxveQVOZTYv17LfKUsdW3uj4rpIxZjACaCnwEBxFT qZ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912130; x=1720516930; 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=XqX6iaUQgzL1offrhP+HrFxeqPqsVcUC+AhsVlpqm/g=; b=FntdBzXJTFVLP+hL69Mb19ZTjahzEuvsaC008n6Ch+edJpbfh2Fzz+40Ta4cgygEvD qbo0vpyROgAH/a+aoYrtofAFLfoeA+u72PypwUjZm8Rdlz/zAxVRO84ZYKC9rf3Pj6fJ ng78PQGjUBJBiL2Gtois8l81VYHnIwUic+/ViYsKwrCtyGLlTGZpOBh+cenO4ajsXvxx hBebOj7yZoCJCZCMa/6jB+LYBQLOnAP2PxTziC87XYYNEWmGxGqiUX3BX82pJ0gT4gU1 Qc5kboHpkwRvp9dVSSXwzbfIMrZwoFlKcSZm7OWi7EKOU+i3TplbIOxF3ElA8aTxXFYC 96tA== X-Gm-Message-State: AOJu0YxCc/wfAFQwd9cTOkNeNZ/r382sIj6TlIUYpVSah7dYDBbJjKCl b3dFzviEL+DMgbnFaSOtOkWt/dzvAHRQ5QeeLAIalNR3FN2921AJSs6PMmpBpx2sNePX+xpGXc3 b X-Google-Smtp-Source: AGHT+IH/Y9BwftBzWc3gClvIqL5hK62V0hzPkVAdId21uR+VecvKVtyAi/xBI3OOdHofyZUB1v4yMQ== X-Received: by 2002:a05:6000:b01:b0:363:ac4d:c44f with SMTP id ffacd0b85a97d-36774f6cabdmr7104281f8f.17.1719912130181; Tue, 02 Jul 2024 02:22:10 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a103d00sm12665190f8f.99.2024.07.02.02.22.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 13/67] hw/sd/sdcard: Introduce definitions for EXT_CSD register Date: Tue, 2 Jul 2024 11:19:56 +0200 Message-ID: <20240702092051.45754-14-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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, UPPERCASE_50_75=0.008 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Cédric Le Goater Signed-off-by: Cédric Le Goater Signed-off-by: Cédric Le Goater Co-Developed-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20240628070216.92609-18-philmd@linaro.org> --- hw/sd/sdmmc-internal.h | 108 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h index d8bf17d204..936c75cace 100644 --- a/hw/sd/sdmmc-internal.h +++ b/hw/sd/sdmmc-internal.h @@ -11,6 +11,114 @@ #ifndef SDMMC_INTERNAL_H #define SDMMC_INTERNAL_H +/* + * EXT_CSD Modes segment + * + * Define the configuration the Device is working in. + * These modes can be changed by the host by means of the SWITCH command. + */ +#define EXT_CSD_CMDQ_MODE_EN 15 /* R/W */ +#define EXT_CSD_FLUSH_CACHE 32 /* W */ +#define EXT_CSD_CACHE_CTRL 33 /* R/W */ +#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */ +#define EXT_CSD_PACKED_FAILURE_INDEX 35 /* RO */ +#define EXT_CSD_PACKED_CMD_STATUS 36 /* RO */ +#define EXT_CSD_EXP_EVENTS_STATUS 54 /* RO, 2 bytes */ +#define EXT_CSD_EXP_EVENTS_CTRL 56 /* R/W, 2 bytes */ +#define EXT_CSD_CLASS_6_CTRL 59 +#define EXT_CSD_INI_TIMEOUT_EMU 60 +#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ +#define EXT_CSD_USE_NATIVE_SECTOR 62 +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 +#define EXT_CSD_VENDOR_SPECIFIC_FIELD 64 /* 64 bytes */ +#define EXT_CSD_PROGRAM_CID_CSD_DDR_SUPPORT 130 +#define EXT_CSD_PERIODIC_WAKEUP 131 +#define EXT_CSD_TCASE_SUPPORT 132 +#define EXT_CSD_SEC_BAD_BLK_MGMNT 134 +#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ +#define EXT_CSD_PARTITION_SETTING_COMPLETED 155 /* R/W */ +#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ +#define EXT_CSD_MAX_ENH_SIZE_MULT 157 /* RO, 3 bytes */ +#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ +#define EXT_CSD_HPI_MGMT 161 /* R/W */ +#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ +#define EXT_CSD_BKOPS_EN 163 /* R/W */ +#define EXT_CSD_BKOPS_START 164 /* W */ +#define EXT_CSD_SANITIZE_START 165 /* W */ +#define EXT_CSD_WR_REL_PARAM 166 /* RO */ +#define EXT_CSD_WR_REL_SET 167 +#define EXT_CSD_RPMB_MULT 168 /* RO */ +#define EXT_CSD_FW_CONFIG 169 /* R/W */ +#define EXT_CSD_USER_WP 171 +#define EXT_CSD_BOOT_WP 173 /* R/W */ +#define EXT_CSD_BOOT_WP_STATUS 174 +#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ +#define EXT_CSD_BOOT_BUS_CONDITIONS 177 +#define EXT_CSD_BOOT_CONFIG_PROT 178 +#define EXT_CSD_PART_CONFIG 179 /* R/W */ +#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ +#define EXT_CSD_BUS_WIDTH 183 /* R/W */ +#define EXT_CSD_STROBE_SUPPORT 184 /* RO */ +#define EXT_CSD_HS_TIMING 185 /* R/W */ +#define EXT_CSD_POWER_CLASS 187 /* R/W */ +#define EXT_CSD_CMD_SET_REV 189 +#define EXT_CSD_CMD_SET 191 +/* + * EXT_CSD Properties segment + * + * Define the Device capabilities, cannot be modified by the host. + */ +#define EXT_CSD_REV 192 +#define EXT_CSD_STRUCTURE 194 +#define EXT_CSD_CARD_TYPE 196 +#define EXT_CSD_DRIVER_STRENGTH 197 +#define EXT_CSD_OUT_OF_INTERRUPT_TIME 198 +#define EXT_CSD_PART_SWITCH_TIME 199 +#define EXT_CSD_PWR_CL_52_195 200 +#define EXT_CSD_PWR_CL_26_195 201 +#define EXT_CSD_PWR_CL_52_360 202 +#define EXT_CSD_PWR_CL_26_360 203 +#define EXT_CSD_SEC_CNT 212 /* 4 bytes */ +#define EXT_CSD_S_A_TIMEOUT 217 +#define EXT_CSD_S_C_VCCQ 219 +#define EXT_CSD_S_C_VCC 220 +#define EXT_CSD_REL_WR_SEC_C 222 +#define EXT_CSD_HC_WP_GRP_SIZE 221 +#define EXT_CSD_ERASE_TIMEOUT_MULT 223 +#define EXT_CSD_HC_ERASE_GRP_SIZE 224 +#define EXT_CSD_ACC_SIZE 225 +#define EXT_CSD_BOOT_MULT 226 +#define EXT_CSD_BOOT_INFO 228 +#define EXT_CSD_SEC_FEATURE_SUPPORT 231 +#define EXT_CSD_TRIM_MULT 232 +#define EXT_CSD_INI_TIMEOUT_PA 241 +#define EXT_CSD_BKOPS_STATUS 246 +#define EXT_CSD_POWER_OFF_LONG_TIME 247 +#define EXT_CSD_GENERIC_CMD6_TIME 248 +#define EXT_CSD_CACHE_SIZE 249 /* 4 bytes */ +#define EXT_CSD_EXT_SUPPORT 494 +#define EXT_CSD_LARGE_UNIT_SIZE_M1 495 +#define EXT_CSD_CONTEXT_CAPABILITIES 496 +#define EXT_CSD_TAG_RES_SIZE 497 +#define EXT_CSD_TAG_UNIT_SIZE 498 +#define EXT_CSD_DATA_TAG_SUPPORT 499 +#define EXT_CSD_MAX_PACKED_WRITES 500 +#define EXT_CSD_MAX_PACKED_READS 501 +#define EXT_CSD_BKOPS_SUPPORT 502 +#define EXT_CSD_HPI_FEATURES 503 +#define EXT_CSD_S_CMD_SET 504 + +#define EXT_CSD_WR_REL_PARAM_EN (1 << 2) +#define EXT_CSD_WR_REL_PARAM_EN_RPMB_REL_WR (1 << 4) + +#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) +#define EXT_CSD_PART_CONFIG_ACC_DEFAULT (0x0) +#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) + +#define EXT_CSD_PART_CONFIG_EN_MASK (0x7 << 3) +#define EXT_CSD_PART_CONFIG_EN_BOOT0 (0x1 << 3) +#define EXT_CSD_PART_CONFIG_EN_USER (0x7 << 3) + #define SDMMC_CMD_MAX 64 /** From patchwork Tue Jul 2 09:19:57 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: 13719262 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 040CDC41513 for ; Tue, 2 Jul 2024 09:23:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZiT-0001nf-6j; Tue, 02 Jul 2024 05:22:25 -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 1sOZiR-0001mR-Cf for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:23 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZiN-0006W7-JC for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:23 -0400 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2ec6635aa43so39465971fa.1 for ; Tue, 02 Jul 2024 02:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912136; x=1720516936; 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=HcI1AN4c5MSHGXZPNCWGySksYQ9YOF7GAxwDscUWZ8U=; b=MwFvQXNqENgQtAsJnCbQWRX6M6uHlffU+hI0YWLUvupAKqSdDcJBPPo6v1sa6+Hb6F w7cMCedlgleuexUB9mCXT5Ep/+GBi7YDaJMhBIXBHsxsbCZegul5c6xf5b3ynSCA+aSQ rlbqfzAJQBqL6376WTnuX4theKN1mDBBOKQz2vvVDoXO8nRdDEvj/ZeAqQ7+3+n3l5Ws F0KVTiWcDwrpeuLx0hbaf4MZkq10luCIX9hQHD5y6ty70VzNvbU0+uzOgcVjWcWPE/nK YL/wnYd1TL8Q85X9OCT5k4r4WpJT2sLCt+TSEHCPJgQq9bbG3h85x/SEjfEZQcnjN8oX vwWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912136; x=1720516936; 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=HcI1AN4c5MSHGXZPNCWGySksYQ9YOF7GAxwDscUWZ8U=; b=jMU1nGQ+2Osrs6svH6YCqFFCjUKnnVhx3z1wGLEsWHxvhqHBwFi1w27S3tCHA3DU7S UedxUyAqXlJQrLCshVKLmQlnYcDSMnTVbeawWFqpm5bjT5WHxV3BNt3kAo1jvUfBHORT eRbRLNA1wHkHMAKqdauwFEr6GPOIgX97iu/cCSvk998eiNpgFiLNwbq0eeyqsBJ8iJ75 525tTey5hCY8EB+AHQfXJpGWMy5AhfWNZFi/l5IFVSlvzmLJi5OxgB0fYSkexZdm2+VH Lj2Fmv0yd74mgxYjHuIxJhVRhAzdJeLs4x0g18Gje7IV2JzAazMKv9XLB8KgPqOvNJbr 8yMA== X-Gm-Message-State: AOJu0YzIbLEIj+xfrcKpiG05l9rZNu0SBD7PB7asUapTCo40jMnZtvyO 06cQ5E71R5bkzuNV+3TJ//Y/E2+IYMWLhmZN0Nhdai5hFW2Bnhvgw4gH8tBxM2hU5ijPCAjqzVj w X-Google-Smtp-Source: AGHT+IGiO4CUlDHbuLXJ+NRX6B61NabAteRlq+FZUzCAfH3LrRJEZNrQ9AoDOIjHut3HR1HxhniLlw== X-Received: by 2002:a05:651c:244:b0:2ee:7255:5047 with SMTP id 38308e7fff4ca-2ee7255541cmr20237461fa.50.1719912136338; Tue, 02 Jul 2024 02:22:16 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b061006sm187723585e9.22.2024.07.02.02.22.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 14/67] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte Date: Tue, 2 Jul 2024 11:19:57 +0200 Message-ID: <20240702092051.45754-15-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22a; envelope-from=philmd@linaro.org; helo=mail-lj1-x22a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers: - sd_cmd_to_sendingdata() on the I/O line setup the data to be transferred, - sd_generic_read_byte() on the DAT lines to fetch the data. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <4c9f7f51-83ee-421a-8690-9af2e80b134b@linaro.org> --- hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 18bb2f9fd8..60235d3898 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -141,8 +141,10 @@ struct SDState { */ bool expecting_acmd; uint32_t blk_written; + uint64_t data_start; uint32_t data_offset; + size_t data_size; uint8_t data[512]; qemu_irq readonly_cb; qemu_irq inserted_cb; @@ -1078,6 +1080,29 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, + uint64_t start, + const void *data, size_t size) +{ + if (sd->state != sd_transfer_state) { + sd_invalid_state_for_cmd(sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset = 0; + if (data) { + assert(size > 0 && size <= sizeof(sd->data)); + memcpy(sd->data, data, size); + } + if (size) { + sd->data_size = size; + } + return sd_r1; +} + /* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { @@ -1912,6 +1937,20 @@ send_response: return rsplen; } +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ +__attribute__((unused)) +static bool sd_generic_read_byte(SDState *sd, uint8_t *value) +{ + *value = sd->data[sd->data_offset]; + + if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; + return true; + } + + return false; +} + void sd_write_byte(SDState *sd, uint8_t value) { int i; From patchwork Tue Jul 2 09:19:58 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: 13719251 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 C357FC3064D for ; Tue, 2 Jul 2024 09:22:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZib-0002GL-Pt; Tue, 02 Jul 2024 05:22:34 -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 1sOZiX-0001vP-5S for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:29 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZiS-0006Wf-92 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:28 -0400 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-52cdcd26d61so4431993e87.2 for ; Tue, 02 Jul 2024 02:22:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912142; x=1720516942; 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=00CPRUcf9kqsnaJEo5PoDWaoJdXP5EBP+kdhrOAEpVg=; b=g8JDhn083tRCZOOZFJncHu6VEEb7MBas+6U01vp8iZ21i6l2bvCl2b48ioMqvRUXWE nlSy5fuEmo75I36ooKedHLpZuqMUVg6do4A3b7UUj4F5bKPfEC0/FFLjdYyPHkD1drp8 6UvoWMU69p3or8WyPiTXmSr7g+CVDcbddQQL8j3OwUJ3JaWapizYyMMSNliZe+S6swQU Lfe7mW4xkvjoPTIyFBmRNKng//BqVYkgUh9ZGdGYilRiR4rFLyCJugV/VHnGsXeRBDkl ++rhZdPc5tNxRv+AtMd0nycuyR+QXo+b3Hjssl4u9eygUyDVgEc8cPDinZhmdfUJJk/v FBZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912142; x=1720516942; 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=00CPRUcf9kqsnaJEo5PoDWaoJdXP5EBP+kdhrOAEpVg=; b=m3APZoudO30uwF6NM2rkC3qECEMvvQ54pk9mMmzi8x8aUigphX16O0rD0GK8Ly9pKr YAFv9shjYXBsAHTqaO8zUNOa+/BKO/8hgK/KRROZiaTGtATrl/P5HRK3KqlV82mFXmZq OpxEckkRnWpIAkRBcgGxbVCWh3pV21BHhsOYgm9D0hPPuKrjq/RnmJVqqyT1Fw2vmjTM Oj8i5/V0GEsbQhoDznb4Ge64hthXVqLBbyjel2z1wVOyz97PLru8tDANT2joGY19m8ca IQCEn2sfeuJAOyg1BKusTar5L/P+yIoBRnVaZi6dV4o4xMy/IxELI4yd8A+wo9P7YqMV syMg== X-Gm-Message-State: AOJu0YwgwdyNec58vQ8OuB46hwjeRGqhVEzD/q7MglpLTS5q+WbKzVN5 HmDdXY1ukEVsVXJZJIKPm67nIwtLz31eGH3TcVDacMmYGJzwtcp/oxgJhGRD/PMMksFzGWyMheP F X-Google-Smtp-Source: AGHT+IEYqGysloQ+ZPEVXlYj7v7gJ5ypQZ+Rv7mCI9l97RKyJr6p6KvAP8kjZCJBdKlCZOqdvrtmLw== X-Received: by 2002:a05:6512:b84:b0:52c:820e:a7e7 with SMTP id 2adb3069b0e04-52e826fb7bcmr5301284e87.50.1719912142153; Tue, 02 Jul 2024 02:22:22 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36784e3e0f5sm1416879f8f.11.2024.07.02.02.22.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 15/67] hw/sd/sdcard: Convert SWITCH_FUNCTION to generic_read_byte (CMD6) Date: Tue, 2 Jul 2024 11:19:58 +0200 Message-ID: <20240702092051.45754-16-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=philmd@linaro.org; helo=mail-lf1-x133.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-20-philmd@linaro.org> --- hw/sd/sd.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 60235d3898..b073700180 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1081,7 +1081,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) } /* Configure fields for following sd_generic_read_byte() calls */ -__attribute__((unused)) static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, uint64_t start, const void *data, size_t size) @@ -1235,10 +1234,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } sd_function_switch(sd, req.arg); - sd->state = sd_sendingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; + return sd_cmd_to_sendingdata(sd, req, 0, NULL, 64); case 7: /* CMD7: SELECT/DESELECT_CARD */ rca = sd_req_get_rca(sd, req); @@ -1938,7 +1934,6 @@ send_response: } /* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ -__attribute__((unused)) static bool sd_generic_read_byte(SDState *sd, uint8_t *value) { *value = sd->data[sd->data_offset]; @@ -2128,10 +2123,7 @@ uint8_t sd_read_byte(SDState *sd) sd->current_cmd, sd->data_offset, io_len); switch (sd->current_cmd) { case 6: /* CMD6: SWITCH_FUNCTION */ - ret = sd->data[sd->data_offset ++]; - - if (sd->data_offset >= 64) - sd->state = sd_transfer_state; + sd_generic_read_byte(sd, &ret); break; case 9: /* CMD9: SEND_CSD */ From patchwork Tue Jul 2 09:19:59 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: 13719252 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 3F513C3065C for ; Tue, 2 Jul 2024 09:22:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZid-0002Q4-Fl; Tue, 02 Jul 2024 05:22: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 1sOZia-0002Aa-EI for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:32 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZiY-0006XL-Ej for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:31 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52ce674da85so4260900e87.2 for ; Tue, 02 Jul 2024 02:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912148; x=1720516948; 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=pum4FAVUTjoo+qizzaMYQ9jJ7vnP2diemnQewFpOPU0=; b=wKiZhuflJZNOvfwwMtQRds6slGjwZWQXrAoDs0d2Kt8pl/b8CGg5nvZVgwVg4RdUhl CzVUNkVF0xTA1jo/hxSWchlFUJDbpCWe2srNlneVL4RZagkKfuH9sSQa+n6DXOOu2UbF wmwQDUBAXky9uvLqs3kv9sXciar+g2GN/q0zTAOdHnayfo9BlLNH5X5yIjWz8fY+hbg0 oSKZ8jcLm+OIQE3zm4eNgdo+yuqeoGOcznk2tQLDrzA8QmchszxkLOVxCJg22AXtNqQL 6GUgDT9S61ucQ+1xWtFn4thRxl9J8B/cp3ojzpWTDRoHmZ+hjHBF0kh7uYM61sn9aWAp chiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912148; x=1720516948; 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=pum4FAVUTjoo+qizzaMYQ9jJ7vnP2diemnQewFpOPU0=; b=RoTYbiYkJXW00jPfsALoOr4Kzg9Y59uh70qlXAIjTLp6gYbTQwJyG0rKiWYo7AphKV mAAO+tMy7HQ0FFtSevChISUBJW0uVgfS3cLyZ+SkxboP81I2Stm/970EwLD+XDsse6Sl 4lfHfPJhuU3Sshf0gxBcYspREJdroYIaTgbjyPekQ0pA02Ti0Ajw8ARqX7YbKzVRmmKZ hkDtTYggZ1hmGs22rYaRbekEdc65+v/dVvpIhZyCvPkyHnjT01UGsBe1Y0xmZ5bzyJEb FcOwj+8m26+gaESAEFraVk5p44HS0nVbL7S/jvZFbSdj05K0TM4fqfyM6z7qecnK840q baJQ== X-Gm-Message-State: AOJu0YzqsicqpRG41DV6Bww0vU92pqgeQp8DNjpDwUMQlCUXMud7U0Lm GzhD2ZuL1Qec4JZAwl7m8VujgQwEZROkiHD6BwB3TA7bDWe35EvAtz6JqOQ8wKMtA05sa5XtJVV e X-Google-Smtp-Source: AGHT+IFJgcAe3DIvQsOfxG94XrNmSIkmejKtyruqKeTUYigY5t7KLUTDd61pKZc/HMUK+4sfT2KgIg== X-Received: by 2002:a05:6512:398f:b0:52c:e4bf:d55d with SMTP id 2adb3069b0e04-52e8264d9fdmr6743732e87.8.1719912147962; Tue, 02 Jul 2024 02:22:27 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0cd623sm12678718f8f.16.2024.07.02.02.22.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 16/67] hw/sd/sdcard: Convert SEND_CSD/SEND_CID to generic_read_byte (CMD9 & 10) Date: Tue, 2 Jul 2024 11:19:59 +0200 Message-ID: <20240702092051.45754-17-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=philmd@linaro.org; helo=mail-lf1-x129.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-21-philmd@linaro.org> --- hw/sd/sd.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b073700180..6b02e0a178 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1304,11 +1304,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (!sd_is_spi(sd)) { break; } - sd->state = sd_sendingdata_state; - memcpy(sd->data, sd->csd, 16); - sd->data_start = sd_req_get_address(sd, req); - sd->data_offset = 0; - return sd_r1; + return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), + sd->csd, 16); default: break; @@ -1328,11 +1325,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (!sd_is_spi(sd)) { break; } - sd->state = sd_sendingdata_state; - memcpy(sd->data, sd->cid, 16); - sd->data_start = sd_req_get_address(sd, req); - sd->data_offset = 0; - return sd_r1; + return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), + sd->cid, 16); default: break; @@ -2123,15 +2117,9 @@ uint8_t sd_read_byte(SDState *sd) sd->current_cmd, sd->data_offset, io_len); switch (sd->current_cmd) { case 6: /* CMD6: SWITCH_FUNCTION */ - sd_generic_read_byte(sd, &ret); - break; - case 9: /* CMD9: SEND_CSD */ - case 10: /* CMD10: SEND_CID */ - ret = sd->data[sd->data_offset ++]; - - if (sd->data_offset >= 16) - sd->state = sd_transfer_state; + case 10: /* CMD10: SEND_CID */ + sd_generic_read_byte(sd, &ret); break; case 13: /* ACMD13: SD_STATUS */ From patchwork Tue Jul 2 09:20:00 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: 13719259 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 25FABC3064D for ; Tue, 2 Jul 2024 09:23:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZiu-0003uI-OW; Tue, 02 Jul 2024 05:22:52 -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 1sOZis-0003kg-Fr for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:50 -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 1sOZie-0006Y5-D7 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:50 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4256eec963eso27758645e9.1 for ; Tue, 02 Jul 2024 02:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912154; x=1720516954; 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=uMKhvT1FGVOx323MVuTarj+/Z918eObPJs1bE9cIdjE=; b=y/ICYbk2DFgRAQ7/GP3L1w7BVKWdD2KDhjCMFJ7YVjKCpTCriBv/iUcnmj9ojfas70 DcxWDCgierEWzP4+iPrBiK1fIbBz4aIx9EoxjhULvCOkHOg39EI1VwwOr3Pw6An3NRI0 kycA29KrGjWY86pWlQPsTFg7QIr6WGhHc8jS6/AG5ifCEfN4u+Sz4X966y3a5U8gB03b J57nZ2+p/QpT1ohSKTYAxf8lYpOOQeDHrzjRuNgrjJYtajg7zHoWG73eKu0CLkSvsHIQ Nww/Lpxd92xtLpzjuAsIB1q7ON0AiMze2HzX+WdKEKmYdKbi/xX+M5WIV4cqxqIDLjEt hr0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912154; x=1720516954; 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=uMKhvT1FGVOx323MVuTarj+/Z918eObPJs1bE9cIdjE=; b=O571jRmKdNhcJnuy8PxcSDFK5jHLc4Zgek5lNM1JcLR1hbtS7txEbtRm2dHzQJTVat 337bn0NXt2cxVqQq/AodJ5tcV1309Y8IR6k1t8uJw71kZYBrHq+WKPDgxPK/VP3P+Sq/ dFxKd+uNq//SJB17MPD/qR/ll+p8JMaj3UCSgML9wKaLeVqModzCPHK8F7cD+bM4jeaW KC9qOJIGPcDF14mCLEc0Z9F5k4s3f2Ap2P14N0/lfRZswU1sIuZh4nXJeGhzHCSEevpk 3d8Co55QwnXnrTCMVJlZrWVQSj04emaB8MP5x7i67UCY2r7K7A75fpiA+T3pndBYHNGz jiig== X-Gm-Message-State: AOJu0YwrXEGSYkUes69RzZJp5iaskw9QnRnE81XR98sZSNGtIZdKJKNP hVLAv7euBLOOCM4VfPneYhgeltHk1iodm5uR7QjgCYa+yr4og9F/HQPzyztSzPjq87xtmV4sN9u F X-Google-Smtp-Source: AGHT+IEy/rWtSgHu0txcdpSeJYKxKSXEjbrUbRQ+9pbbq1RBLLvrY3pbwZl7EdwESn3vcNsAC2zfSw== X-Received: by 2002:a05:600c:181b:b0:421:7bed:5274 with SMTP id 5b1f17b1804b1-4257a02f7f0mr58623805e9.10.1719912153756; Tue, 02 Jul 2024 02:22:33 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257cdf4982sm110284735e9.47.2024.07.02.02.22.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:33 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 17/67] hw/sd/sdcard: Duplicate READ_SINGLE_BLOCK / READ_MULTIPLE_BLOCK cases Date: Tue, 2 Jul 2024 11:20:00 +0200 Message-ID: <20240702092051.45754-18-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In order to modify the READ_SINGLE_BLOCK case in the next commit, duplicate it first. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-22-philmd@linaro.org> --- hw/sd/sd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 6b02e0a178..43e0a2d925 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1390,6 +1390,24 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 17: /* CMD17: READ_SINGLE_BLOCK */ + addr = sd_req_get_address(sd, req); + switch (sd->state) { + case sd_transfer_state: + + if (!address_in_range(sd, "READ_SINGLE_BLOCK", addr, sd->blk_len)) { + return sd_r1; + } + + sd->state = sd_sendingdata_state; + sd->data_start = addr; + sd->data_offset = 0; + return sd_r1; + + default: + break; + } + break; + case 18: /* CMD18: READ_MULTIPLE_BLOCK */ addr = sd_req_get_address(sd, req); switch (sd->state) { From patchwork Tue Jul 2 09:20:01 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: 13719261 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 E6ED1C30658 for ; Tue, 2 Jul 2024 09:23:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZip-0003TX-Ci; Tue, 02 Jul 2024 05:22: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 1sOZil-0003B5-J9 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:43 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZij-0006Yl-F2 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:43 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42564a0d3ceso24429365e9.0 for ; Tue, 02 Jul 2024 02:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912159; x=1720516959; 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=fq0Hp2Una8Cq+xwhreR1xxCEuiahEpzKceutH3MuTZk=; b=qdt+3ZWJqTeRbVKd8w7QB40JOUqY74DrAxG+IkeApxtHylJaQEtIFRTE7jk4UZU9QJ y8HnzQRnw8rzPbuLEyQ3CBUpwgNayjK4MBEtYnuAFRuwqtzTnUpvrRzCvEV2naV7oQ2s o+uf5KHVFmagKSVaeTuWlQbIaDThUS8KM8UuSbbczhh8wBPtublHpOjwa8CjjHrxctHX BZEVDBGXl3XK9KVhMkH1PTHQ/u4H0COp2106FmqAz6ko9dQXcaWIFvMETt04mJ4nvZ9/ tfrVIDxkAO2jzCtpzXeyrx1hQchm4cGaAxVfTrt6sAm7LFE0Dcr5oER0wm0MC+yGH6ml FKZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912159; x=1720516959; 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=fq0Hp2Una8Cq+xwhreR1xxCEuiahEpzKceutH3MuTZk=; b=PKomb9TEompUIvxIA5lQPHI59X6GaAMHWFbY3AOxYMPJIvkHYZ1SxUuTNTw/A0HHCr mlWul0qbe+Uf3/oaHycd0Sdi9eG1WiklI3nHJ/hey744IKl0uCBlf43ZS00iwPGSP0nI LoDIq/Bvij1YTsZ9rHz2i7Qu8ACQC0vHvuwswb1Dp5G0VZFgFgfPBJkYvXKcpV8iiCmo s9FzYouyYAJhubmXNq66oqWZi1LhvC/z3wFcPi8pXlJI1CKQwTOjpbLBujDZno+6/jT1 I8XNOkv49gw2+oExMIRDjWdFTo0DTFv8o66dj3YiFtD755shwWeLG299atlezQyOvLY0 E2mA== X-Gm-Message-State: AOJu0YzpGD6CX34QivM5zFp/xwHk97N86gUxqNaNd67Q1qL2hMBcvZNs coqwijrbHlfmE9maam+ktaUp9A5B1BkFrIpoXSufzH51i8LLXg4FkkMsZa81tD9jFEjvzPSLEaM 6 X-Google-Smtp-Source: AGHT+IHRMv2GEE1n8Z1bFbcTuxj/Y9F+LiZgH07uCRh8Pa4rWqY1hmkZX6x+MM08LUMvMv/lY0zhjA== X-Received: by 2002:a05:600c:1d21:b0:423:394:cd28 with SMTP id 5b1f17b1804b1-4257a04fe67mr53501255e9.25.1719912159574; Tue, 02 Jul 2024 02:22:39 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0d8cd8sm12607603f8f.27.2024.07.02.02.22.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 18/67] hw/sd/sdcard: Convert READ_SINGLE_BLOCK to generic_read_byte (CMD17) Date: Tue, 2 Jul 2024 11:20:01 +0200 Message-ID: <20240702092051.45754-19-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-23-philmd@linaro.org> --- hw/sd/sd.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 43e0a2d925..8415c23e20 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1397,11 +1397,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (!address_in_range(sd, "READ_SINGLE_BLOCK", addr, sd->blk_len)) { return sd_r1; } - - sd->state = sd_sendingdata_state; - sd->data_start = addr; - sd->data_offset = 0; - return sd_r1; + sd_blk_read(sd, addr, sd->blk_len); + return sd_cmd_to_sendingdata(sd, req, addr, NULL, sd->blk_len); default: break; @@ -2137,6 +2134,7 @@ uint8_t sd_read_byte(SDState *sd) case 6: /* CMD6: SWITCH_FUNCTION */ case 9: /* CMD9: SEND_CSD */ case 10: /* CMD10: SEND_CID */ + case 17: /* CMD17: READ_SINGLE_BLOCK */ sd_generic_read_byte(sd, &ret); break; @@ -2147,16 +2145,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state; break; - case 17: /* CMD17: READ_SINGLE_BLOCK */ - if (sd->data_offset == 0) { - sd_blk_read(sd, sd->data_start, io_len); - } - ret = sd->data[sd->data_offset ++]; - - if (sd->data_offset >= io_len) - sd->state = sd_transfer_state; - break; - case 18: /* CMD18: READ_MULTIPLE_BLOCK */ if (sd->data_offset == 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK", From patchwork Tue Jul 2 09:20:02 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: 13719253 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 2991FC3064D for ; Tue, 2 Jul 2024 09:23:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZiw-000430-Ma; Tue, 02 Jul 2024 05:22:54 -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 1sOZit-0003o1-B1 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:51 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZiq-0006ZT-Em for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:50 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ebe785b234so40017701fa.1 for ; Tue, 02 Jul 2024 02:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912165; x=1720516965; 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=TBkJoq7dOcnQq6fmt+Em92zeZnpvlQPX8gCdahknyqk=; b=kzuPDa3Zz6pVKl94q0SKXxpKunVP0+WqlhrIoLJ0Z29jkWhu5XHUeouhb+sF2TDxSO Hj7HzHOsfPHd005v3l1F5Qsayc5Kh5Nx3Ss1RXneVdrtyS2/yeSiCNQAHVyX8dRFfMzL yVQ8nApTNnoWPUaTT0pATGKVAN3pTIbmCSoVyhOuPwWA6ed5ckp2nzWMNKPb0RvQnXUi HFme/vm0sYtthxSdBSovjEdS5WhIbfWcw/dkc6RFYVJxCXfcX7CHjb+ipSJXC6O9jZua KQQeOmzPZZeN72ADsNKlyBw+I5NeofBN1zaNfaDM+GjJXvoMBIIDM5KEl8locRF6OYvt A0mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912165; x=1720516965; 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=TBkJoq7dOcnQq6fmt+Em92zeZnpvlQPX8gCdahknyqk=; b=hCYsW/WBQBxCCZW6kVrDPaTPzTb/L/z4tGQj5BDEJKW6sSp6atoY5Ytkm9G7ZPwR9z 6N28oEbUQw3d9gyAopVihz1VslJbhR6aN92Cyf6oGKGaCu7a0r4qBtUpg9vTFuFQqGzw Vm1Icf6G1BrQgiLTDq7XfVB1hINm+U1SUCx4dOkl854qKhWjnpJEhJHFx7Cs4wtip2VX iB/XxK2lfcavJUm2C/pW5xpIqyO2oblVqg3lRyYJSMJfzrDMRqCqQvwphjrA3t2LmRq7 RaPaevYmynCzQLI+6LP3YPjVOKTx9T/n3eu0q+RtTmZ4vY3pkfE7YBqWadbT91G2F2nh hxpA== X-Gm-Message-State: AOJu0YxaSQpWnmjAr8cXcgmW2ys5YYefjFNCtwBiXnt4c8OjppM7ApFt JNp1sXfi8zBA8p/rKsUOd+O2Ib22/+CdAG2SGklUw61zhqsVFxPxvsYGUp9uiPXDeHLo8pvONUc 1 X-Google-Smtp-Source: AGHT+IH0bdCVU5IvAmNVnMCdlR6TZPd9sIJ7ldvg3K3wepqgr870phppDEbNxaDm8QKHOo8o/ObwiQ== X-Received: by 2002:a2e:88d1:0:b0:2ec:53a9:2037 with SMTP id 38308e7fff4ca-2ee5e6f2bcdmr50533321fa.37.1719912165465; Tue, 02 Jul 2024 02:22:45 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367898c64c1sm989990f8f.23.2024.07.02.02.22.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:45 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 19/67] hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19) Date: Tue, 2 Jul 2024 11:20:02 +0200 Message-ID: <20240702092051.45754-20-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=philmd@linaro.org; helo=mail-lj1-x22c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-24-philmd@linaro.org> --- hw/sd/sd.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8415c23e20..940cbb0d3c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -564,6 +564,21 @@ static void sd_set_sdstatus(SDState *sd) memset(sd->sd_status, 0, 64); } +static const uint8_t sd_tuning_block_pattern4[64] = { + /* + * See: Physical Layer Simplified Specification Version 3.01, + * Table 4-2. + */ + 0xff, 0x0f, 0xff, 0x00, 0x0f, 0xfc, 0xc3, 0xcc, + 0xc3, 0x3c, 0xcc, 0xff, 0xfe, 0xff, 0xfe, 0xef, + 0xff, 0xdf, 0xff, 0xdd, 0xff, 0xfb, 0xff, 0xfb, + 0xbf, 0xff, 0x7f, 0xff, 0x77, 0xf7, 0xbd, 0xef, + 0xff, 0xf0, 0xff, 0xf0, 0x0f, 0xfc, 0xcc, 0x3c, + 0xcc, 0x33, 0xcc, 0xcf, 0xff, 0xef, 0xff, 0xee, + 0xff, 0xfd, 0xff, 0xfd, 0xdf, 0xff, 0xbf, 0xff, + 0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde +}; + static int sd_req_crc_validate(SDRequest *req) { uint8_t buffer[5]; @@ -1153,14 +1168,9 @@ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) return sd_cmd_illegal(sd, req); } - if (sd->state != sd_transfer_state) { - return sd_invalid_state_for_cmd(sd, req); - } - - sd->state = sd_sendingdata_state; - sd->data_offset = 0; - - return sd_r1; + return sd_cmd_to_sendingdata(sd, req, 0, + sd_tuning_block_pattern4, + sizeof(sd_tuning_block_pattern4)); } /* CMD23 */ @@ -2093,20 +2103,6 @@ void sd_write_byte(SDState *sd, uint8_t value) } } -#define SD_TUNING_BLOCK_SIZE 64 - -static const uint8_t sd_tuning_block_pattern[SD_TUNING_BLOCK_SIZE] = { - /* See: Physical Layer Simplified Specification Version 3.01, Table 4-2 */ - 0xff, 0x0f, 0xff, 0x00, 0x0f, 0xfc, 0xc3, 0xcc, - 0xc3, 0x3c, 0xcc, 0xff, 0xfe, 0xff, 0xfe, 0xef, - 0xff, 0xdf, 0xff, 0xdd, 0xff, 0xfb, 0xff, 0xfb, - 0xbf, 0xff, 0x7f, 0xff, 0x77, 0xf7, 0xbd, 0xef, - 0xff, 0xf0, 0xff, 0xf0, 0x0f, 0xfc, 0xcc, 0x3c, - 0xcc, 0x33, 0xcc, 0xcf, 0xff, 0xef, 0xff, 0xee, - 0xff, 0xfd, 0xff, 0xfd, 0xdf, 0xff, 0xbf, 0xff, - 0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde, -}; - uint8_t sd_read_byte(SDState *sd) { /* TODO: Append CRCs */ @@ -2135,6 +2131,7 @@ uint8_t sd_read_byte(SDState *sd) case 9: /* CMD9: SEND_CSD */ case 10: /* CMD10: SEND_CID */ case 17: /* CMD17: READ_SINGLE_BLOCK */ + case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ sd_generic_read_byte(sd, &ret); break; @@ -2169,13 +2166,6 @@ uint8_t sd_read_byte(SDState *sd) } break; - case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ - if (sd->data_offset >= SD_TUNING_BLOCK_SIZE - 1) { - sd->state = sd_transfer_state; - } - ret = sd_tuning_block_pattern[sd->data_offset++]; - break; - case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ ret = sd->data[sd->data_offset ++]; From patchwork Tue Jul 2 09:20:03 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: 13719293 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 D7CA5C3064D for ; Tue, 2 Jul 2024 09:28:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZj0-0004Lh-A7; Tue, 02 Jul 2024 05:22:58 -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 1sOZix-00045t-6S for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:55 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZiv-0006et-69 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:22:54 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-363826fbcdeso2295332f8f.0 for ; Tue, 02 Jul 2024 02:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912171; x=1720516971; 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=44A7uKnrLEqCTNEeUcpB4p2VqBTe04M5aS1mgYhUgXI=; b=TOWH08fHC0LdJrKRZvZkA47y2Ja1IxkA726rpX/BlKmADnFnHHOW6AZO31jtAt1OGJ +Pp1xqJE5T4hIFkcr9pssKeb/DiGcyTveHzlsJFaOlAszFbJQeLksPyI183vFqJVSA/I UjEF8Sl+RZYOpeO5iOvzDaJ8QTUXRf5ykVllsAAwIs8e5KcBcKgoFWLd/jtuLrWAaMRz /ZYgT9r7sQyluOk4fk0e5JVACR7qjCKHkG40dSh0dKISPtd2ZlgxAC0k3JOQP8tgvXLE WWy114AGiiOsSNF3Oacx+f22UhpfquF2KtVooI6o+V9caR5l0AkzAPB4jV2YNd14qBHQ vIvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912171; x=1720516971; 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=44A7uKnrLEqCTNEeUcpB4p2VqBTe04M5aS1mgYhUgXI=; b=HKGrQomGMtsRgcsiGEuZs1R0l8zAWDBYlCmaCXip3o9Bno3EcbkSHFlW+XTRpJMRs1 N6EzAbgOHXxDgN9Jti+x9R1kvSMzJQb0zD6tcRUzHWNdp5b9pIFMRqU9X0P49eFT2UVj pjhHFDSTTw8Lx3onPL3ACAA3EW1ml+klOx4UcgWU8fpCKnKQAMnR7Onj9ye33/Y4HXmb fCkMBfeb/QxhuHK7U23b8ZSTC+onGXpCz1Lh2TXgC1E0jqJy6dt11HG3ShflliOLHx9c haJvxTQrR5a/Tl0/1N9bB44q772h5b73HjUK0hDE/eIboFPPSXW/MCQQVdsiCrHLI33V 1Xxw== X-Gm-Message-State: AOJu0YxCBsGp4Pp2QqTZkTMDGv0b0oNsuQaJjKGoAdiQ0T1LhexHUzEQ hvlirHVFtMGzyyoGcSu8xjgCUHrUDG7DOI6ABsvcBqrelpaQDQxVDeA3bBpSO1PobuEZeee5XFS b X-Google-Smtp-Source: AGHT+IFMYq1WCSvUlSlGedVZ+5rIH93F8Y5LBqjSIspPIbEkUmIDcpvE9qFeVLb3evWBAAQrFzKh3A== X-Received: by 2002:a5d:5f91:0:b0:367:83e9:b4a5 with SMTP id ffacd0b85a97d-36783e9b614mr993638f8f.49.1719912171329; Tue, 02 Jul 2024 02:22:51 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a112e19sm12631308f8f.116.2024.07.02.02.22.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 20/67] hw/sd/sdcard: Convert SEND_WRITE_PROT to generic_read_byte (CMD30) Date: Tue, 2 Jul 2024 11:20:03 +0200 Message-ID: <20240702092051.45754-21-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-25-philmd@linaro.org> --- hw/sd/sd.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 940cbb0d3c..1d6bacf885 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1194,6 +1194,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; uint64_t addr; + uint32_t data; sd->last_cmd_name = sd_cmd_name(req.cmd); /* CMD55 precedes an ACMD, so we are not interested in tracing it. @@ -1547,12 +1548,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) req.arg, sd->blk_len)) { return sd_r1; } - - sd->state = sd_sendingdata_state; - stl_be_p(sd->data, sd_wpbits(sd, req.arg)); - sd->data_start = addr; - sd->data_offset = 0; - return sd_r1; + data = sd_wpbits(sd, req.arg); + return sd_cmd_to_sendingdata(sd, req, addr, &data, sizeof(data)); default: break; @@ -2132,6 +2129,7 @@ uint8_t sd_read_byte(SDState *sd) case 10: /* CMD10: SEND_CID */ case 17: /* CMD17: READ_SINGLE_BLOCK */ case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ + case 30: /* CMD30: SEND_WRITE_PROT */ sd_generic_read_byte(sd, &ret); break; @@ -2173,13 +2171,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state; break; - case 30: /* CMD30: SEND_WRITE_PROT */ - ret = sd->data[sd->data_offset ++]; - - if (sd->data_offset >= 4) - sd->state = sd_transfer_state; - break; - case 51: /* ACMD51: SEND_SCR */ ret = sd->scr[sd->data_offset ++]; From patchwork Tue Jul 2 09:20:04 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: 13719257 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 9C031C30658 for ; Tue, 2 Jul 2024 09:23:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZj4-0004uE-Us; Tue, 02 Jul 2024 05:23:03 -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 1sOZj3-0004hr-19 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:01 -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 1sOZj1-0006lc-6q for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:00 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42574064b16so24374425e9.2 for ; Tue, 02 Jul 2024 02:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912177; x=1720516977; 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=imXLEvTuUF3KqVtejnZ3cyv6qmJ2G3srjMrqU8EXbpg=; b=ZDQprPED1gDgkUIuGnn6mnkir1X20xYVHunxECPgqZ+7RbkJtirLZjWtD5hSnDtcqC odXC/kOnw0fpINPSWxRwz+sLwg1F+8mVpSvIDN2xEGi2VaxJw/pGFYpJ/327AN4V0VsG SvyomzWD6DbmWZsT2ggCntTOPLOLch4WugED9XkSXVG7EtYll4oVjy80IlrmwVbelXL2 d0VYGKbWIKAfvGAYFcEl8uptrZCDJQ4pZGRijb4p+oqdkaoCoExzDhxnC30MedfdVdZn pSXJIZjPk02Soex04PDEJ8MmGnL/GaNZx+LNVMjfTjzdWckAa1MPJSvjMlBIsZ2KJdql zJzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912177; x=1720516977; 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=imXLEvTuUF3KqVtejnZ3cyv6qmJ2G3srjMrqU8EXbpg=; b=e0I4eV4YgIASUlXTyaEjesY36qertH+uoeBj3dETrT/NAW0+adlrKk1EjVrT4SzbsU CZ/NW1PAvAkYBdNt28FWYBTbpw9Gu99neBwU+Ax0GMUBOhgpaqjp5YmmPUlUsl4PLdOq JhtbwhAfz7I7HJTTI83uSToslLV2fwhtJSOmBYM4ECouJRtlKEW+HwzOV0Mf5NcPi3jd 8waLVpH650wTYcMSqH6uOi0mHXKwWsDGnOQCGBu0yicDS9BmHbH5mmjzkAF/I0q1L14Z rb0dV2XRKcylZt9gXv4WobdPfMNyEKRSJsXAJvZ8Tko3vURLAqdlFprPNJnZ7e90pWSA 3T5A== X-Gm-Message-State: AOJu0YzwWsu3WslE8fXg+tNSaB/U2G+qdvRPOhjUpKMc0kM+KFHwXC5i cvqp5Kp29MerhGCIpDqbRJrlTni8/xqBQhvxdHS1v4e3kuezZIeJDqK0Kh9p+5tCphI0vR39sgk Q X-Google-Smtp-Source: AGHT+IECFom1IuSHPEJ4t21gxJ3NlhLrzRKnyuELE3Fl/c3Zc09fZ7OLrIG9KPCciMjrnLPqaFYTSg== X-Received: by 2002:a5d:5f8e:0:b0:364:4b4e:9310 with SMTP id ffacd0b85a97d-367756a333amr7635174f8f.1.1719912177249; Tue, 02 Jul 2024 02:22:57 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a10302fsm12588472f8f.93.2024.07.02.02.22.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:22:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 21/67] hw/sd/sdcard: Convert SD_STATUS to generic_read_byte (ACMD13) Date: Tue, 2 Jul 2024 11:20:04 +0200 Message-ID: <20240702092051.45754-22-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-27-philmd@linaro.org> --- hw/sd/sd.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 1d6bacf885..0a65bd5a76 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1693,10 +1693,9 @@ static sd_rsp_type_t sd_app_command(SDState *sd, case 13: /* ACMD13: SD_STATUS */ switch (sd->state) { case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; + return sd_cmd_to_sendingdata(sd, req, 0, + sd->sd_status, + sizeof(sd->sd_status)); default: break; @@ -2127,19 +2126,13 @@ uint8_t sd_read_byte(SDState *sd) case 6: /* CMD6: SWITCH_FUNCTION */ case 9: /* CMD9: SEND_CSD */ case 10: /* CMD10: SEND_CID */ + case 13: /* ACMD13: SD_STATUS */ case 17: /* CMD17: READ_SINGLE_BLOCK */ case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ case 30: /* CMD30: SEND_WRITE_PROT */ sd_generic_read_byte(sd, &ret); break; - case 13: /* ACMD13: SD_STATUS */ - ret = sd->sd_status[sd->data_offset ++]; - - if (sd->data_offset >= sizeof(sd->sd_status)) - sd->state = sd_transfer_state; - break; - case 18: /* CMD18: READ_MULTIPLE_BLOCK */ if (sd->data_offset == 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK", From patchwork Tue Jul 2 09:20:05 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: 13719270 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 17655C3065C for ; Tue, 2 Jul 2024 09:25:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjC-0005uJ-PN; Tue, 02 Jul 2024 05:23:10 -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 1sOZjB-0005jZ-48 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:09 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZj7-0006lx-9u for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:08 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-424ad289949so28603775e9.2 for ; Tue, 02 Jul 2024 02:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912183; x=1720516983; 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=l/eRkmwGVDEETYZdTpz1AxWYEJ+R0hQ9lI4q9Qx8IeM=; b=bujLOGO6y3pOJon/NskHK0VJLzT29GButuLECZqVMX+ClFlDBMau/JS/2rHh2dNXtE Syrmqo9vMHp6XFOzCaQ5q1fKwWlvWFZHpHUIxFhWKwNUH+SuFdP8cSFwYoWba8B92zVZ N1UfBrHnDx/ebXR5hJNBGpRAKxMueSwa8B0dv00FqM/0AgUWB9sICZXAQXRLXRIq6bya Gh+a9y3MD0kv4UuDus3y1mn34NxheoLl/3tuPhMaAUyt22QJI4L0WeyGMhZldL2xWkVl lcrvpFacDB0/EUny50u3msOLSTOmXJIOw8msuB5WXjrB3wSN/76jA3ycQAxgxoD6TY8G RFSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912183; x=1720516983; 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=l/eRkmwGVDEETYZdTpz1AxWYEJ+R0hQ9lI4q9Qx8IeM=; b=AITvhuP6AG1MEpBdjb0rBohurLSAkgCQAXmd3sHt4mJmm6try/bI3ksn2xpiJxveMk xDpZvH85efCp82mNS1+b0MfGvkVW1+N5pXWhWo1+s/dyphSt+scsm1Stg1icMRM6/3NQ y3TCs9LOjzLbsqrmnzt9QsekBM7k1lhsVTHYCEzS/nMqd477xFufTMSMx8vVE8xjMHDv NjhTqCAxn02UpZOAZvLY3WsJQmvEuOnMTY9Bjgsrz8hOUiklNuS/dvvTzm+qf6p0RLmn NoxT9KvbofO9BXOJ5x1IW9OpQXVFsHQB0BNnlbabQcdktsghf/2RmtKGmfEQOXz6Zq58 MO5A== X-Gm-Message-State: AOJu0Yx9VJCZ0IkZuUzRErWm2mTEakE2Lvgrk/9Fje7y5XB+1hjYtVBu bwsPIe+0YmyDe201S/NfbG2zMt0HCpXVqaTNRPkOXkdmNCNeHg7bCt42272lAoFRXX2o8NH5CWO U X-Google-Smtp-Source: AGHT+IFgmHbwPPAtCQpy4pVQlM9+GYDwv/JQakQykG7kCUc/5qQlGPsMIxIGo++bQ6aekOmaFlV1mQ== X-Received: by 2002:a05:600c:3510:b0:422:384e:4365 with SMTP id 5b1f17b1804b1-42579fff40dmr53861195e9.2.1719912182993; Tue, 02 Jul 2024 02:23:02 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256aed237dsm191953365e9.0.2024.07.02.02.23.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:02 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 22/67] hw/sd/sdcard: Convert SEND_NUM_WR_BLOCKS to generic_read_byte (ACMD22) Date: Tue, 2 Jul 2024 11:20:05 +0200 Message-ID: <20240702092051.45754-23-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-28-philmd@linaro.org> --- hw/sd/sd.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 0a65bd5a76..5d5e55243e 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1705,11 +1705,9 @@ static sd_rsp_type_t sd_app_command(SDState *sd, case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) { case sd_transfer_state: - stl_be_p(sd->data, sd->blk_written); - sd->state = sd_sendingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; + return sd_cmd_to_sendingdata(sd, req, 0, + &sd->blk_written, + sizeof(sd->blk_written)); default: break; @@ -2129,6 +2127,7 @@ uint8_t sd_read_byte(SDState *sd) case 13: /* ACMD13: SD_STATUS */ case 17: /* CMD17: READ_SINGLE_BLOCK */ case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ + case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ case 30: /* CMD30: SEND_WRITE_PROT */ sd_generic_read_byte(sd, &ret); break; @@ -2157,13 +2156,6 @@ uint8_t sd_read_byte(SDState *sd) } break; - case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ - ret = sd->data[sd->data_offset ++]; - - if (sd->data_offset >= 4) - sd->state = sd_transfer_state; - break; - case 51: /* ACMD51: SEND_SCR */ ret = sd->scr[sd->data_offset ++]; From patchwork Tue Jul 2 09:20:06 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: 13719267 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 CCB4EC3064D for ; Tue, 2 Jul 2024 09:24:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjH-0006FA-0M; Tue, 02 Jul 2024 05:23:15 -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 1sOZjE-00063a-Fa for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:12 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZjC-0006ts-Nw for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:12 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-366e70d0330so2485569f8f.1 for ; Tue, 02 Jul 2024 02:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912189; x=1720516989; 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=yJKBBwll7Vgxqrd4++eiEl6JZS58Z0q7hVOL9pUOlIU=; b=bds0P/DxaoBOQXoYi44gPC/luvruztHy4rjmSkX2QDtLtOFuc/Pxyopzh6Iz4oKk5g TUxlYahlfWb2vHCmiwnlpm3ONY3NDhj/1SVHfdevVJ9ah5Yk4fCXl3FtIOBogGgbpbIh xVJVIzD8+GG53ZwI5LIkAV+oLKkZ1nE9OPQuFwGT7/1wHbGQf3T1q+oEcpeuEUUKuSyz xAg6MAiTaNBMfutadkPXvb/jrzhP1eO0uNREJoe80It89PVFXVsiHljsavAdCdxsx42W D+Bp4X4MIMdHzjQk7eBPY9q1ESB55AK0B7rSyJy7qTFLcbrp6saQWnlXcqMxbKcz8ico oEOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912189; x=1720516989; 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=yJKBBwll7Vgxqrd4++eiEl6JZS58Z0q7hVOL9pUOlIU=; b=FxFDvwJ04fV4KOpk01+FhmpvkEbZ1teF5IcN5tZwIM487h/AI79PVWFn8zPBALtKjI p9K/mEGuBI9T7galS+vdeJJBO8op1SKBa7AiDmaMSePRTz+yTrEUqsJLSfY+MNmoFY26 IiDKPg3XPWNHnZhFJ+O6Wp1iQcNCY7Oehi4U1b8EDMuQi3SqFxong5sjMP1mwa5ZW40r FAxMP/WlbFA9vkB27NgJs2pwG7tHrbviukHPZgnKEyF2oo3I2x2j73wE143rw4an57jo zHYnz9z0/du6cr+XnuZWZ/csLypfkP+y1vbkWseAldE6B5vAWiG+KDSKOjxB4l4bKfbh Hymg== X-Gm-Message-State: AOJu0YxevGlqqiIWLFWPxqdZY8ma+cJ8A7SIYvfSHD4kyTt3DsFkuyAQ tj+xVpE0hx+iymDKHcorRprVA2LySsZpGTPOPltOrzxf17aaujr1q6AIcz98pAydXYjucKoEyFF N X-Google-Smtp-Source: AGHT+IHwaICijgWASGtbxb7Ux7atkjYKB85vS9D5tOE4KGyMpGHshO9hnpBsnnQeB+w9YcLzYt8pZQ== X-Received: by 2002:adf:f406:0:b0:365:b695:ef76 with SMTP id ffacd0b85a97d-367756c71eemr5364221f8f.36.1719912188782; Tue, 02 Jul 2024 02:23:08 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fb9c1sm12717294f8f.74.2024.07.02.02.23.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:08 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 23/67] hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51) Date: Tue, 2 Jul 2024 11:20:06 +0200 Message-ID: <20240702092051.45754-24-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-29-philmd@linaro.org> --- hw/sd/sd.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5d5e55243e..78aabb65ac 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1775,10 +1775,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, case 51: /* ACMD51: SEND_SCR */ switch (sd->state) { case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; + return sd_cmd_to_sendingdata(sd, req, 0, sd->scr, sizeof(sd->scr)); default: break; @@ -2129,6 +2126,7 @@ uint8_t sd_read_byte(SDState *sd) case 19: /* CMD19: SEND_TUNING_BLOCK (SD) */ case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ case 30: /* CMD30: SEND_WRITE_PROT */ + case 51: /* ACMD51: SEND_SCR */ sd_generic_read_byte(sd, &ret); break; @@ -2156,13 +2154,6 @@ uint8_t sd_read_byte(SDState *sd) } break; - case 51: /* ACMD51: SEND_SCR */ - ret = sd->scr[sd->data_offset ++]; - - if (sd->data_offset >= sizeof(sd->scr)) - sd->state = sd_transfer_state; - break; - case 56: /* CMD56: GEN_CMD */ if (sd->data_offset == 0) APP_READ_BLOCK(sd->data_start, sd->blk_len); From patchwork Tue Jul 2 09:20:07 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: 13719260 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 994E2C3064D for ; Tue, 2 Jul 2024 09:23:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjU-0006z0-Jb; Tue, 02 Jul 2024 05:23:30 -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 1sOZjL-0006hy-La for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:21 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZjJ-0007Ay-2g for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:18 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2e72224c395so44436271fa.3 for ; Tue, 02 Jul 2024 02:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912195; x=1720516995; 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=UBCC3n87rxfV/0t7pp/Ldl4A4zhR6I/rWoz/G7mokgI=; b=X3Ot5K6+ZY2wcvUeGg/7qQACiyfhsUUhGDQpCbVhYtD78RMNQA0t+hbp+hTwtpwui8 kt0/xqD2JYORny57jgPfF/bYs0HnYFMUc7XHiganww9K5AbPbGseyRoaSjAe1IykHnly RzyL/Oxm74ipsnmHCcxyRixoj5L6jJ6g8TRduN5P4QV4pwSyPFFZVWXiCYalsUoxJzsP jh6ns/A53BoPvKNeX5I597ext0b5sBMaKxjUYU5F1VyYl2KuGYvHndMmp/4RLjvkZ37h oBk13b3oDN6fOCMLZ0KoPzfjXxwPJDv1JIJzRXtUGqrcFEC3NpHppAuiznTH2d0a5RCO AaAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912195; x=1720516995; 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=UBCC3n87rxfV/0t7pp/Ldl4A4zhR6I/rWoz/G7mokgI=; b=HXzLj3ghl2920necEOIJSH7X1da/zbaon+7G1o1L4VRmGr7OpdUqDZfEgjLYw7id5/ jgVoMhcbYsuWYc3+e06Md10KN1uGYBxtBIGDg4EQnjGGUiM1q+JCI+tIjrjkeQ9USJhe s0kbkBYRmtmYVHdA+FdPpKxYxRccQDt/iSF68PXt6vMzb9c1yU/M6x8uTJF3eIAwHcu+ 8+yyIiL1qtpZu/dn/ceYLA5iOWBmSlNOyonZ26ZkrrXJlRtqedonTT4NuAIyFOlSx4TG IIrNniaM9zPuCjroydxilUi0oQAQqHWDl2+kgvnUUGs6vRdMpMiTh/J015TfTy3uYdB1 cZUA== X-Gm-Message-State: AOJu0Yz1ClP9G3S+v32l5Lru34/l52NhyEbi4l8HUmKzj90TSliYLF/k 8a9ps/xsMBvbssLiEu4ddhFMo+ImCg1ik/tokJVZWzKEa5fnZUUOJ6zr2w5wYWCKWf2EeJv7q23 w X-Google-Smtp-Source: AGHT+IGp0AS4iSkYsSN7jIgaKF4v5PiprPD+5s5EmK+JJag37o2gu5kbQF17wOGF+NP/ZGj55y1tSA== X-Received: by 2002:a2e:99d8:0:b0:2ec:51e8:d8fe with SMTP id 38308e7fff4ca-2ee5e382b9emr53809631fa.31.1719912194894; Tue, 02 Jul 2024 02:23:14 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42577a0dda2sm83964945e9.0.2024.07.02.02.23.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 24/67] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte Date: Tue, 2 Jul 2024 11:20:07 +0200 Message-ID: <20240702092051.45754-25-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=philmd@linaro.org; helo=mail-lj1-x22e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org All commands switching from TRANSFER state to (receiving)DATA do the same: receive stream of data from the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers: - sd_cmd_to_receivingdata() on the I/O line setup the data to be received on the data[] buffer, - sd_generic_write_byte() on the DAT lines to push the data. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-30-philmd@linaro.org> --- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 78aabb65ac..990f038b79 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1095,6 +1095,22 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* Configure fields for following sd_generic_write_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_receivingdata(SDState *sd, SDRequest req, + uint64_t start, size_t size) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + sd->state = sd_receivingdata_state; + sd->data_start = start; + sd->data_offset = 0; + /* sd->data[] used as receive buffer */ + sd->data_size = size ?: sizeof(sd->data); + return sd_r1; +} + /* Configure fields for following sd_generic_read_byte() calls */ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, uint64_t start, @@ -1943,6 +1959,19 @@ send_response: return rsplen; } +/* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ +__attribute__((unused)) +static bool sd_generic_write_byte(SDState *sd, uint8_t value) +{ + sd->data[sd->data_offset] = value; + + if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; + return true; + } + return false; +} + /* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ static bool sd_generic_read_byte(SDState *sd, uint8_t *value) { From patchwork Tue Jul 2 09:20:08 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: 13719264 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 A6321C3064D for ; Tue, 2 Jul 2024 09:24:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjY-0007CT-UG; Tue, 02 Jul 2024 05:23:32 -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 1sOZjT-0006z2-Qt for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:28 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZjO-0007KA-FU for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:27 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4256788e13bso28540915e9.2 for ; Tue, 02 Jul 2024 02:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912201; x=1720517001; 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=McRtxYBX9h21CzT63G2Ji6yPLnYuFaXK4qV2KzZz24Y=; b=rWIhb1Gc5CcmEBdGvOx44czg/t2Ql88yyrz63LaRFmqzvJSwWizcVGyxXrojgd8ifX H/VryfpdbgKKgrqSDmS8i90114XfCIB/cmG1gBas41RJFd1qgkIBAtKeDrsTzBH48sYD JHt5PVS6f+RS5zqO2cksyMYXx3/guBRohtQtAjI0oxcRjoyteoHF++NRioivRP25Lj2z 28SvlasUs4Qy7sIYoH4J8/TQ2J2RuvM7ZhQEcNCOP0xWoV9BeK4vDd/61nUVvNfLU6p1 3bMRkJAiuUpGUa2mCBHhoAgDqVSNQxJqLsZ5WJYcD4c/TtNIrWKoqW4PaO6/danPLJ/O 8TKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912201; x=1720517001; 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=McRtxYBX9h21CzT63G2Ji6yPLnYuFaXK4qV2KzZz24Y=; b=EfgZaGqvO+T8QbZyWaoLZfjoQGNCnFQYsEn/THad5zMIT5+yhCw2Nz+FyRqrqTgJSP uZWihSAxgEA9wtyfMdz1TA6Pi9Ytd1s3c+wheMaDM+eLc1VZxUViiKjeU1rezo86sOb+ umSLDvR68kxPUQnwImggkwUgol0cP40h4qZ4w6EvqZj3VVHwF+Cz2T6LNgUxg0BwrPuK wmDVkbQ4zFdGXWPqDfuPhDnSmfuANyFarE0Lt4RMv2fbzzZZJkGjZ4i7MgC2ComqttrZ m3Tlywe+HKrpS/ms4FHlzZ5enTBcZRxsipXHey/O93xSFLfUCZU3Xki069CMEntZHrXq 3Npg== X-Gm-Message-State: AOJu0Yx2QDkq+tVITM2fQOFMNkEPRUfRQVMSoD5GPDf0jPYfZuE8Nynm VZRYdDH7lgO1A66Co7Km6N6ICuOp7UOg4KzS/40crDurhvoj04tOPrXFgl6h2XZAGFc6trDPilG S X-Google-Smtp-Source: AGHT+IGSOrga8o9SbO0CCtndDPhCcElW3mgyq64EtmFk4IAlsLggVlbYtBeldR8eNMLv3efKGGnmQw== X-Received: by 2002:a05:600c:5125:b0:425:672a:7683 with SMTP id 5b1f17b1804b1-4257a08ded2mr45418635e9.41.1719912200855; Tue, 02 Jul 2024 02:23:20 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5b91bsm190911205e9.20.2024.07.02.02.23.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:20 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 25/67] hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK cases Date: Tue, 2 Jul 2024 11:20:08 +0200 Message-ID: <20240702092051.45754-26-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In order to modify the WRITE_SINGLE_BLOCK case in the next commit, duplicate it first. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-31-philmd@linaro.org> --- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 990f038b79..b1acddca45 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1453,6 +1453,35 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Block write commands (Class 4) */ case 24: /* CMD24: WRITE_SINGLE_BLOCK */ + addr = sd_req_get_address(sd, req); + switch (sd->state) { + case sd_transfer_state: + + if (!address_in_range(sd, "WRITE_SINGLE_BLOCK", addr, + sd->blk_len)) { + return sd_r1; + } + + sd->state = sd_receivingdata_state; + sd->data_start = addr; + sd->data_offset = 0; + + if (sd->size <= SDSC_MAX_CAPACITY) { + if (sd_wp_addr(sd, sd->data_start)) { + sd->card_status |= WP_VIOLATION; + } + } + if (sd->csd[14] & 0x30) { + sd->card_status |= WP_VIOLATION; + } + sd->blk_written = 0; + return sd_r1; + + default: + break; + } + break; + case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ addr = sd_req_get_address(sd, req); switch (sd->state) { From patchwork Tue Jul 2 09:20:09 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: 13719266 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 B9ABCC3065C for ; Tue, 2 Jul 2024 09:24:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZja-0007kz-O6; Tue, 02 Jul 2024 05:23:34 -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 1sOZjX-0007Ci-Ki for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:32 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZjV-0007Kn-PO for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:31 -0400 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-52cdf4bc083so5980015e87.2 for ; Tue, 02 Jul 2024 02:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912207; x=1720517007; 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=fsQ5dZXMOKylcaTkeNe5NCCv+ATRu3UFQ5w5tnxMhiA=; b=pMiPF/ahxDbSmw+Z3jn67XJyeK7Fb606Ql5Z5heggJSXaSgbSQ2CRpb7tVC6PTJK0L GHMTyqEy8nsSGHqbVSiEJsqXIn5U7JuY0WPeB47pFxBh6AgK96S+qhq1tdBwGeSnmkxV t895XzR5d3Q5db3tbXIeYydUTnMnkuTT8/zk8J4ISmcx86nVhmvmdhasubifzDIcCIzE +vF/rACjZ/8MYw6fD5IPQKRlHKx+shoH35/ZhlYxY9L2UBAw4SWoEbJsgiudv4M3cdDX 60LS8rH3jywCcp18PEdEr8nl9lOVjA0ip7/zp5XD507mEaTuEjAtFaf02so/5jphLxrg vuew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912207; x=1720517007; 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=fsQ5dZXMOKylcaTkeNe5NCCv+ATRu3UFQ5w5tnxMhiA=; b=K8bUvyXqV9olXZFMNF/BA9F9WTp3hKOD2JEan1YgShENtYxugR/PCgDcJAEM/6AjbB /U+WBHCsuxsrGdLWmQZEatUNp2Y91wqM55fVPdVaPnh61v+32vvMq6yuaJwcqnATTDvm KGzS5Vb9vtGigC4I8e70+T2FzPw2sZDPm91f4JkFR4iPuJKmiFInc4t6Siz9gAf8/9qp E+XFbI9TphGgpXvbwt87EPsqbcxywTF6lG/Mfo2zYaWYCM0UcdKF+1FF/G6Utlth6XQG qF/ekLopdZKBVWrmTVQwf0rfLfQxoeirJT7o4NOZbfagzYJ32v5fSrqOSJPfdvB3VZ79 Uaqg== X-Gm-Message-State: AOJu0Yxd13qEKDj6ROAGd7w70TJ1WwtlZUcYZYbFp2uND5BEbUOja5lr p2U/dFrUMS2VOLFe5Q+TBaTPtGGU3gNQaUE1Th1DW3hfxKay0YhP+VnKDRtMq2nEcergBb9ws+v W X-Google-Smtp-Source: AGHT+IHSYdj0In9GrZnIfuyCsFynXZMlz2mFb4Zudd6ADx8FOupFAMFMxmcrSVf+HAVPBG25PuaJag== X-Received: by 2002:a05:6512:39cc:b0:52c:c8bc:74d4 with SMTP id 2adb3069b0e04-52e826f1554mr6105380e87.48.1719912206735; Tue, 02 Jul 2024 02:23:26 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0cd6d9sm12585862f8f.12.2024.07.02.02.23.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 26/67] hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24) Date: Tue, 2 Jul 2024 11:20:09 +0200 Message-ID: <20240702092051.45754-27-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12c; envelope-from=philmd@linaro.org; helo=mail-lf1-x12c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-32-philmd@linaro.org> --- hw/sd/sd.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b1acddca45..349549f801 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1096,7 +1096,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) } /* Configure fields for following sd_generic_write_byte() calls */ -__attribute__((unused)) static sd_rsp_type_t sd_cmd_to_receivingdata(SDState *sd, SDRequest req, uint64_t start, size_t size) { @@ -1462,10 +1461,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_r1; } - sd->state = sd_receivingdata_state; - sd->data_start = addr; - sd->data_offset = 0; - if (sd->size <= SDSC_MAX_CAPACITY) { if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; @@ -1475,7 +1470,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->card_status |= WP_VIOLATION; } sd->blk_written = 0; - return sd_r1; + return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); default: break; @@ -1989,7 +1984,6 @@ send_response: } /* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ -__attribute__((unused)) static bool sd_generic_write_byte(SDState *sd, uint8_t value) { sd->data[sd->data_offset] = value; @@ -2035,8 +2029,7 @@ void sd_write_byte(SDState *sd, uint8_t value) sd->current_cmd, sd->data_offset, value); switch (sd->current_cmd) { case 24: /* CMD24: WRITE_SINGLE_BLOCK */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sd->blk_len) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; sd_blk_write(sd, sd->data_start, sd->data_offset); From patchwork Tue Jul 2 09:20:10 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: 13719274 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 01A5BC3064D for ; Tue, 2 Jul 2024 09:26:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjh-0008WJ-R9; Tue, 02 Jul 2024 05:23:41 -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 1sOZjg-0008VC-9j for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:40 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZjc-0007V9-Jh for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:39 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a72459d8d6aso399480966b.0 for ; Tue, 02 Jul 2024 02:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912213; x=1720517013; 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=4VJOT5ZcN/EvCEADOgKfKYKQ9sQEErpJJZeG9rUrgf8=; b=pwCusik83OhK9oMd7E4pjMCRa79euDk5DZdx+8c89McIRwj0xXRZzJT226EFDoDL8r AFVAPiGdaicHliDvjIzeYZxqbNQNuXQjyE97omUthIu24zUHMoiiaZH85hhp4XWnEv3S 3tBLyYrakefdoN9b2gGcXrVCtxIFoIF5f5HmhPfqQASIUxnNaDKFfmCr4VTJQZvrntok OdNxyLraoWYMwU7Z9mJoaBeykd0NLELho8wxK+I1BYy27X8iC/Eg8McAcLrR2KvHaC5y nM2OYb6y5uox4Qg3nFpSzhYmYdF6DKIitiOSZVA8aEEswGoEdq3lnuVNkGDWy7ja2aQG fgDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912213; x=1720517013; 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=4VJOT5ZcN/EvCEADOgKfKYKQ9sQEErpJJZeG9rUrgf8=; b=IbNepXbiWoVpoSUVc5BCp/I+bkPPAx+co8FZoBLFPiDfNxc7sW/2GfOeNYYuKZQU1c YyiXa54o+G45hYnw0RurLZKtJLvep0udwmHvjOne4PNejQrDFwyJadReTMsqUo6XdzlM XOvlsJZdBaW1aV3uMrItdKYex/0ZdzJpRQugs5b818Zm2OszI/0NNIUPl9oU+hjw8GNU Lh1DrHCjvDoW+Weaoign1PiWqeH3MSA/3OQPkm9bHF2dISjFPjXaX6DAK2XEJnTQ73aT S7bQHgnUffWOHiVotsI1xcVa73PEz53X83MJWY0mjpnae6/iJc56hv5no4wgQE8yuK1C ZEYw== X-Gm-Message-State: AOJu0YwWZ1E0mTtdY7g/D/CbAz5TYkvtzqB1J/lXbIetpa9Lgk0/eaVb TTlBXvDQ0no+zz2P6C+rF5o64Qamb3ON8Fr5YOISnba/Y3JZ9OJkQqScwvT7rXB9E1BksEIy3hs z X-Google-Smtp-Source: AGHT+IF1qeQAMwghrfWZ1Jwegrru0Z+Ct+8pKzBl7BJ+48Fd8XV3oLJ0jNxWtQrFzI2k6TESv8JBeA== X-Received: by 2002:a17:906:db0b:b0:a6f:e819:da9c with SMTP id a640c23a62f3a-a751444dab8mr691427266b.43.1719912212642; Tue, 02 Jul 2024 02:23:32 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fb9absm12668064f8f.80.2024.07.02.02.23.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 27/67] hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26) Date: Tue, 2 Jul 2024 11:20:10 +0200 Message-ID: <20240702092051.45754-28-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=philmd@linaro.org; helo=mail-ej1-x632.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-33-philmd@linaro.org> --- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 349549f801..0aead3c866 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1507,17 +1507,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 26: /* CMD26: PROGRAM_CID */ - switch (sd->state) { - case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; - } - break; + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); case 27: /* CMD27: PROGRAM_CSD */ switch (sd->state) { @@ -2078,8 +2068,7 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 26: /* CMD26: PROGRAM_CID */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sizeof(sd->cid)) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; for (i = 0; i < sizeof(sd->cid); i ++) From patchwork Tue Jul 2 09:20:11 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: 13719276 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 DC142C30658 for ; Tue, 2 Jul 2024 09:26:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjm-0000cS-Fg; Tue, 02 Jul 2024 05:23:46 -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 1sOZjk-0000QW-VP for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:44 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZji-0007co-5m for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:44 -0400 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2e72224c395so44440061fa.3 for ; Tue, 02 Jul 2024 02:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912219; x=1720517019; 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=mik6Y+wbs8Uum7pP9/BoqNxBZgA0hVPmMXZ5DOoxW5k=; b=hHUfnrRYcGc9Zk5mCxmVVIQ1PCK3k4xSlqNS+osuDEDQr1fBJDlfUVUZHWJHS8MYN7 d4AxiIrIM9B/CbfmYN5Oc2QVQswKEl1L+sewf+CxPBzgJG3TVG5SIXuZkIRbN85ARPfl RO+pUihxeiM4yVCNbZ76CxQq9xTmOHs7w20FlVC+s/iys4aVnujDIhVFlhzvTakPw+AU 99VHPdwsFGnptxkMV6ZlSa2dOv18CNUORO6HQd7G/QOcGM9bWiJoWLGpc2d4hEeGPI2X 4/HySL+ZShDsFT4a3Z+GkVfyzJlO+davYatOOTY3q23fjZPYZGej7MGiPtsH6oBiCsEC EvzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912219; x=1720517019; 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=mik6Y+wbs8Uum7pP9/BoqNxBZgA0hVPmMXZ5DOoxW5k=; b=T+A/ECna3NV6ysq6BVxPhOVAP2x2GXQ9U1DfSKm1xmlnit9bE22sCOqdabsaZTr1pg d471Cq5l43BnVSfRM3UwFO4KtYpu0sLCn4EtanX7kixMGwsPZ3ekERUA41q0H0+vQzNt vA/htla7Ic6wlSGc80+1tKDQQo884ihJk320daSSS0P//kSnMUBgxrM3KniuMDdd20CA gYl64wV/EzPvh+Ha2lUQlyaCDdh9box65i3hEO4Pvr9BMXrzAcXvTm4zpDdxcn8BPecn 7W9QD2VPIdz9+IimSnYYWEtMGqDVLvLiS+pX07JKfxQ05HZ47vV+lskFZ5MmzBtHUvWZ O3SQ== X-Gm-Message-State: AOJu0Yxr2FATWStyWCWaAHIkha5h//C09bE1Q8bgE2AMyNANYwVcdqMC e7IQ17zf/LAfAcb7CAuZFHx1BLH5bm0IVqSKKePJ2LkUtljmJ2PzPQZoQjgg8z/mYVhCoSMTpbG K X-Google-Smtp-Source: AGHT+IGA0SdyiOq4TWFuFW5wRgxrin01ZtZgZyP9VS8gmfsvdjae8lpQX9njjx9Cktrzhr1AwySG2Q== X-Received: by 2002:a2e:b704:0:b0:2ec:5128:1850 with SMTP id 38308e7fff4ca-2ee5e35452dmr49945211fa.13.1719912219530; Tue, 02 Jul 2024 02:23:39 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b061095sm180545945e9.23.2024.07.02.02.23.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 28/67] hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27) Date: Tue, 2 Jul 2024 11:20:11 +0200 Message-ID: <20240702092051.45754-29-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22a; envelope-from=philmd@linaro.org; helo=mail-lj1-x22a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-34-philmd@linaro.org> --- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 0aead3c866..95ba4d0755 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1510,17 +1510,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); case 27: /* CMD27: PROGRAM_CSD */ - switch (sd->state) { - case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; - } - break; + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->csd)); /* Write protection (Class 6) */ case 28: /* CMD28: SET_WRITE_PROT */ @@ -2086,8 +2076,7 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 27: /* CMD27: PROGRAM_CSD */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sizeof(sd->csd)) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; for (i = 0; i < sizeof(sd->csd); i ++) From patchwork Tue Jul 2 09:20:12 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: 13719321 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 2446AC3064D for ; Tue, 2 Jul 2024 09:31:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjs-00013j-C2; Tue, 02 Jul 2024 05:23:52 -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 1sOZjq-0000vL-G3 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:50 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZjo-0007xT-Hq for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:50 -0400 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-52e743307a2so4454871e87.0 for ; Tue, 02 Jul 2024 02:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912225; x=1720517025; 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=upGfqqV5De+YauigIoBYXsU7px/Lanfz6QB2Qs40bCc=; b=FD8wuC3PgyqwYOpMrO7zBmWMq7Qj5E5N7+CPiKGpTve5v81oy5Uuk7JdudYW7q8AkA wxrtEBCVIUu246+Ab4tkvG7Si+UnN+1apL8BUkdMGUx2wTA+hLqTEkuqyIb8OiYuQQa/ apq0dWwJ4v6UsILtmRQ4l65/eRA+yIF2nXTw5XkXFAEsxOWbEHE7X8rAvWmb4vdkiteU KnYOFQhH8MrFGMT/pxHRGFRRI4hbfoPhdvG+N2w39VHv3PPt/Ww7zZUXpyUShTqCaeQL 3rg21QkwnyPh39LER7ZsrUOtgxvDpLD4TQxIhbT+AUf7icnD+a1+sfwrOiN5eBaDF2jb evdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912225; x=1720517025; 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=upGfqqV5De+YauigIoBYXsU7px/Lanfz6QB2Qs40bCc=; b=xAqos0YVF5sxmLX8h/l8Ng+A0bAn5iTlviptE0bDXZkcg59eadsgVluQheLQHHONtj sKYB5YulfK3VgDDCDezgTXjZBnCQtXP+sdoeN/5nfzr6a3yX7m1/4m99a8P6MkaXGO1b K7VtPBi3CW10mRZzVNe2quf1a0Kbjkcgg/qePgD8QFvaafHtRilKDkN3+xa7BkrS7kJA gwKeBjfUl/JqiPKjPGAQYRuJ0XqmeKDITwRydzlbDBeip0PSUOa75v0QWGuxkTsu11WG lW8+weKYtLscjhsN9yR33eNAu8arBfaawT/OC+6moAX6XAFwEdzEelf50K4HYTAZ//2C VKfg== X-Gm-Message-State: AOJu0YwxeRQ3KUMyg22WQyRy1rrwfH9N4bu0O451YPb8iTCRDOcvLCEx +YjsGsomaJ4Gbo6RVPKVXF18WYahbOpm7RIJ2L4r5hA4P0YiS3GLlLg6lHX+hr+uMbc2Z71F026 q X-Google-Smtp-Source: AGHT+IGJTCqErRVdtePtktRkF/z1HNfAwDNpU7zFEBKsByjsrE11xpFOPOJZUC1lGjRuqJ2QtJgYpQ== X-Received: by 2002:a05:6512:3d86:b0:52c:e086:7953 with SMTP id 2adb3069b0e04-52e8264df6amr6388329e87.4.1719912225359; Tue, 02 Jul 2024 02:23:45 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257fc934b2sm93124925e9.44.2024.07.02.02.23.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:44 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 29/67] hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42) Date: Tue, 2 Jul 2024 11:20:12 +0200 Message-ID: <20240702092051.45754-30-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=philmd@linaro.org; helo=mail-lf1-x132.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-35-philmd@linaro.org> --- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 95ba4d0755..822debb28b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1620,17 +1620,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Lock card commands (Class 7) */ case 42: /* CMD42: LOCK_UNLOCK */ - switch (sd->state) { - case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; - } - break; + return sd_cmd_to_receivingdata(sd, req, 0, 0); /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ @@ -2099,8 +2089,7 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 42: /* CMD42: LOCK_UNLOCK */ - sd->data[sd->data_offset ++] = value; - if (sd->data_offset >= sd->blk_len) { + if (sd_generic_write_byte(sd, value)) { /* TODO: Check CRC before committing */ sd->state = sd_programming_state; sd_lock_command(sd); From patchwork Tue Jul 2 09:20:13 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: 13719282 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 07AF2C3064D for ; Tue, 2 Jul 2024 09:27:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZjz-00025P-2s; Tue, 02 Jul 2024 05:23: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 1sOZjx-0001mI-5x for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:57 -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 1sOZju-0007yC-QX for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:23:56 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-52cf4ca8904so6414717e87.3 for ; Tue, 02 Jul 2024 02:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912232; x=1720517032; 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=w91m07KsBglNi/fQY95FCrDPhq7oOjLmVtnvRjzEoPE=; b=imieRV1jbrifcJYN2OU7wXBnZoFuboPb3i3P9TyQ5IbIuBwl8AASMTpFuiCzqGjYlf Z/Auuso9OlOBh4bmKCMkAkFpO3Grhuhoj4NoTXUfJAG4FN9sTezw7TJETQLzo54llij+ LrY581NTOoM85F7jsr9op7CM3+FzqKVdvkANZjJh8Wbhi2EISCtwQZqpOEiRjEZI2Z9g c60tvnAx+PqCiZD8L2XxwoosEFmt28aVD5RCxciBVwxhjkGuxUBJTc0xqheNBu79EUs1 EnBUJWswI/j5D/uV4aOuMSs8Jbxj1gV/nQFYH8LC3HDqUQRG6QQQ2jRvTRJaXkyltLki Q8lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912232; x=1720517032; 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=w91m07KsBglNi/fQY95FCrDPhq7oOjLmVtnvRjzEoPE=; b=uPFNTtVOD45iNrTMBz/TbMhYr7Zi2ktfZJOF8F1RbLyRh6cYm4m1Fy05jEYz74PKhe 2G4Oc5XdGjbH6OQ13OBlEid46aLeq3tZFC1w0xbVyh4Nt1nZwAd3PtqnuLN9i0sgNk/o RQX+OEBAmtCKUFPo6vSDV3fgyyu8Sq9y7ZkFvI8du94CyY1FftD/jLg4w2e1oCjCSv2X yvBdDfoKJS5ess1Y2T9LWXpDvVwgvvKVb4BSDywik5q1JX4bEEMTH6JaLi6qWmJOjpPb XddNFb00S86E7nRCr6Yh5tEAd/M5cvA4xhxB8KEaolq7at+CrML12ybQz8gFKfDgxH1e sRdA== X-Gm-Message-State: AOJu0YzxdByayqqdoZ0uYvq4cj9xz1IR96cxyUGMrdinB0pgnWLYpdNf I53k3ETfYxXv6Zk0X7P2YGuONUkyIixbSGeRKI6m7VrU080MWyp82h2f/lOrwErrOxWO/fS7aHm U X-Google-Smtp-Source: AGHT+IEI+j89+E/nFrXWefQsj2h9iKcgzGM9lfFB33BqWv3BTA2H9n3eH9qLdl3Q5JyZYXKxc/8QZA== X-Received: by 2002:a05:6512:3409:b0:52d:6673:11da with SMTP id 2adb3069b0e04-52e8273e68amr5309527e87.57.1719912231098; Tue, 02 Jul 2024 02:23:51 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257c4e1112sm117583805e9.3.2024.07.02.02.23.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 30/67] hw/sd/sdcard: Move sd_[a]cmd_name() methods to sd.c Date: Tue, 2 Jul 2024 11:20:13 +0200 Message-ID: <20240702092051.45754-31-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Merge sdmmc-internal.c into sd.c by moving sd_cmd_name() and sd_acmd_name() and updating meson.build. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-37-philmd@linaro.org> --- hw/sd/sdmmc-internal.h | 26 --------------- hw/sd/sd.c | 62 ++++++++++++++++++++++++++++++++++++ hw/sd/sdmmc-internal.c | 72 ------------------------------------------ hw/sd/meson.build | 2 +- 4 files changed, 63 insertions(+), 99 deletions(-) delete mode 100644 hw/sd/sdmmc-internal.c diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h index 936c75cace..cc0b69e834 100644 --- a/hw/sd/sdmmc-internal.h +++ b/hw/sd/sdmmc-internal.h @@ -119,30 +119,4 @@ #define EXT_CSD_PART_CONFIG_EN_BOOT0 (0x1 << 3) #define EXT_CSD_PART_CONFIG_EN_USER (0x7 << 3) -#define SDMMC_CMD_MAX 64 - -/** - * sd_cmd_name: - * @cmd: A SD "normal" command, up to SDMMC_CMD_MAX. - * - * Returns a human-readable name describing the command. - * The return value is always a static string which does not need - * to be freed after use. - * - * Returns: The command name of @cmd or "UNKNOWN_CMD". - */ -const char *sd_cmd_name(uint8_t cmd); - -/** - * sd_acmd_name: - * @cmd: A SD "Application-Specific" command, up to SDMMC_CMD_MAX. - * - * Returns a human-readable name describing the application command. - * The return value is always a static string which does not need - * to be freed after use. - * - * Returns: The application command name of @cmd or "UNKNOWN_ACMD". - */ -const char *sd_acmd_name(uint8_t cmd); - #endif diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 822debb28b..90bb47ad26 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -87,6 +87,8 @@ enum SDCardStates { sd_disconnect_state = 8, }; +#define SDMMC_CMD_MAX 64 + typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { @@ -228,6 +230,66 @@ static const char *sd_response_name(sd_rsp_type_t rsp) return response_name[rsp]; } +static const char *sd_cmd_name(uint8_t cmd) +{ + static const char *cmd_abbrev[SDMMC_CMD_MAX] = { + [0] = "GO_IDLE_STATE", [1] = "SEND_OP_COND", + [2] = "ALL_SEND_CID", [3] = "SEND_RELATIVE_ADDR", + [4] = "SET_DSR", [5] = "IO_SEND_OP_COND", + [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", + [8] = "SEND_IF_COND", [9] = "SEND_CSD", + [10] = "SEND_CID", [11] = "VOLTAGE_SWITCH", + [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", + [15] = "GO_INACTIVE_STATE", + [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", + [18] = "READ_MULTIPLE_BLOCK", [19] = "SEND_TUNING_BLOCK", + [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", + [23] = "SET_BLOCK_COUNT", + [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", + [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", + [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", + [30] = "SEND_WRITE_PROT", + [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", + [34] = "SW_FUNC_RSVD", [35] = "SW_FUNC_RSVD", + [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", + [38] = "ERASE", + [40] = "DPS_spec", + [42] = "LOCK_UNLOCK", [43] = "Q_MANAGEMENT", + [44] = "Q_TASK_INFO_A", [45] = "Q_TASK_INFO_B", + [46] = "Q_RD_TASK", [47] = "Q_WR_TASK", + [48] = "READ_EXTR_SINGLE", [49] = "WRITE_EXTR_SINGLE", + [50] = "SW_FUNC_RSVD", + [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", + [54] = "SDIO_RSVD", [55] = "APP_CMD", + [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", + [58] = "READ_EXTR_MULTI", [59] = "WRITE_EXTR_MULTI", + [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", + [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", + }; + return cmd_abbrev[cmd] ? cmd_abbrev[cmd] : "UNKNOWN_CMD"; +} + +static const char *sd_acmd_name(uint8_t cmd) +{ + static const char *acmd_abbrev[SDMMC_CMD_MAX] = { + [6] = "SET_BUS_WIDTH", + [13] = "SD_STATUS", + [14] = "DPS_spec", [15] = "DPS_spec", + [16] = "DPS_spec", + [18] = "SECU_spec", + [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", + [41] = "SD_SEND_OP_COND", + [42] = "SET_CLR_CARD_DETECT", + [51] = "SEND_SCR", + [52] = "SECU_spec", [53] = "SECU_spec", + [54] = "SECU_spec", + [56] = "SECU_spec", [57] = "SECU_spec", + [58] = "SECU_spec", [59] = "SECU_spec", + }; + + return acmd_abbrev[cmd] ? acmd_abbrev[cmd] : "UNKNOWN_ACMD"; +} + static uint8_t sd_get_dat_lines(SDState *sd) { return sd->enable ? sd->dat_lines : 0; diff --git a/hw/sd/sdmmc-internal.c b/hw/sd/sdmmc-internal.c deleted file mode 100644 index c1d5508ae6..0000000000 --- a/hw/sd/sdmmc-internal.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SD/MMC cards common helpers - * - * Copyright (c) 2018 Philippe Mathieu-Daudé - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#include "qemu/osdep.h" -#include "sdmmc-internal.h" - -const char *sd_cmd_name(uint8_t cmd) -{ - static const char *cmd_abbrev[SDMMC_CMD_MAX] = { - [0] = "GO_IDLE_STATE", [1] = "SEND_OP_COND", - [2] = "ALL_SEND_CID", [3] = "SEND_RELATIVE_ADDR", - [4] = "SET_DSR", [5] = "IO_SEND_OP_COND", - [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", - [8] = "SEND_IF_COND", [9] = "SEND_CSD", - [10] = "SEND_CID", [11] = "VOLTAGE_SWITCH", - [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", - [15] = "GO_INACTIVE_STATE", - [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", - [18] = "READ_MULTIPLE_BLOCK", [19] = "SEND_TUNING_BLOCK", - [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", - [23] = "SET_BLOCK_COUNT", - [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", - [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", - [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", - [30] = "SEND_WRITE_PROT", - [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", - [34] = "SW_FUNC_RSVD", [35] = "SW_FUNC_RSVD", - [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", - [38] = "ERASE", - [40] = "DPS_spec", - [42] = "LOCK_UNLOCK", [43] = "Q_MANAGEMENT", - [44] = "Q_TASK_INFO_A", [45] = "Q_TASK_INFO_B", - [46] = "Q_RD_TASK", [47] = "Q_WR_TASK", - [48] = "READ_EXTR_SINGLE", [49] = "WRITE_EXTR_SINGLE", - [50] = "SW_FUNC_RSVD", - [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", - [54] = "SDIO_RSVD", [55] = "APP_CMD", - [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", - [58] = "READ_EXTR_MULTI", [59] = "WRITE_EXTR_MULTI", - [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", - [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", - }; - return cmd_abbrev[cmd] ? cmd_abbrev[cmd] : "UNKNOWN_CMD"; -} - -const char *sd_acmd_name(uint8_t cmd) -{ - static const char *acmd_abbrev[SDMMC_CMD_MAX] = { - [6] = "SET_BUS_WIDTH", - [13] = "SD_STATUS", - [14] = "DPS_spec", [15] = "DPS_spec", - [16] = "DPS_spec", - [18] = "SECU_spec", - [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", - [41] = "SD_SEND_OP_COND", - [42] = "SET_CLR_CARD_DETECT", - [51] = "SEND_SCR", - [52] = "SECU_spec", [53] = "SECU_spec", - [54] = "SECU_spec", - [56] = "SECU_spec", [57] = "SECU_spec", - [58] = "SECU_spec", [59] = "SECU_spec", - }; - - return acmd_abbrev[cmd] ? acmd_abbrev[cmd] : "UNKNOWN_ACMD"; -} diff --git a/hw/sd/meson.build b/hw/sd/meson.build index abfac9e461..bbb75af0c9 100644 --- a/hw/sd/meson.build +++ b/hw/sd/meson.build @@ -1,5 +1,5 @@ system_ss.add(when: 'CONFIG_PL181', if_true: files('pl181.c')) -system_ss.add(when: 'CONFIG_SD', if_true: files('sd.c', 'core.c', 'sdmmc-internal.c')) +system_ss.add(when: 'CONFIG_SD', if_true: files('sd.c', 'core.c')) system_ss.add(when: 'CONFIG_SDHCI', if_true: files('sdhci.c')) system_ss.add(when: 'CONFIG_SDHCI_PCI', if_true: files('sdhci-pci.c')) system_ss.add(when: 'CONFIG_SSI_SD', if_true: files('ssi-sd.c')) From patchwork Tue Jul 2 09:20:14 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: 13719288 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 7EE1DC3064D for ; Tue, 2 Jul 2024 09:28:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZk5-0002l4-LA; Tue, 02 Jul 2024 05:24:05 -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 1sOZk2-0002cV-Qg for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:02 -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 1sOZk0-0007yl-34 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:02 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-36743a79dceso2868045f8f.0 for ; Tue, 02 Jul 2024 02:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912238; x=1720517038; 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=MEAedVXIwS3IcpAZnKMoyPFq95SaykgChyIuzbCP5sU=; b=mFfZmIcRb182k8XU2MSD4LLGk+E4VaawF8OEu/5/h7z6fUbUTK0griavI9r17YJnR6 xaw9J74svIT9mOCRLs5YLJa/B3MEtO2UcXEikjMXHHE8BraZR6w2TdN7Mcw8wFDaiJDW fszF3KyMzbPBDj57kSASVB6jKGDJNLaecCOy93M45QREhb0veIAAekNgTxx95eDoFCBT Qs9NFjKcCiBSQQQMdhi+qFUGszAYqp+Zui2zVe0bAh2VexlZQUsetDia3p1oW+UQ4eSF PNcQOOG+OhBZbnhpN4YQRs3hHYj8eF4Br3+DK+ceGuDQ/oMglsxkFN9AyC/fp/QKhnM3 qjFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912238; x=1720517038; 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=MEAedVXIwS3IcpAZnKMoyPFq95SaykgChyIuzbCP5sU=; b=O8GgkFqAl2OoxndHS4qIWxDTKdCElPDOZBorJu9oiecMFDdccjRKkhEalkToF2eSQx 6fFtiphIcRbKe3jwG3iaDrDbfjA48AboP591gWXfbeoKH5HAFvHRqiSal/745TCtJFNO +3xKTh65CF2ScYQVlImjIRQ7ZIlnDD2Yjv+X+LAgZ/3J0XF4itDZoqR/1/HPQ7czONnB aVbWG0AAlS4D8RCsWK0IhG0zGrOJgta3U9Q4KCzu9xzEy26ZvJFO1sPG6q7xX3FI5f6L sifK3MQA0UBR/OIsoqP4NRn17Sld/OursP1VFeMdJzm9I8AWxdgLiGcKRE05usm3QM4y 3vXg== X-Gm-Message-State: AOJu0Yx9s7Y/eIaXnDMWOomyCt3oqBK982aG2fk4uG7zbwESCEixpNed laHDW2rZHiOpHeptjnMMzAREG9ZkkFQ4UJUWVHOY5hyCeopEakG39raaPmFvtTie/NA6wmJqd9z / X-Google-Smtp-Source: AGHT+IGgBGHiqgKP1vhnRXRsamuG8T3I55KSZDSFwaWSovBXdIvQaF+YLMUtohvSIxpRzgcI4AJSqQ== X-Received: by 2002:a05:6000:154e:b0:367:42ce:f004 with SMTP id ffacd0b85a97d-36760aa2ec0mr11625731f8f.23.1719912238218; Tue, 02 Jul 2024 02:23:58 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0d8daasm12555614f8f.30.2024.07.02.02.23.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:23:57 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 31/67] hw/sd/sdcard: Pass SDState as argument to sd_[a]cmd_name() Date: Tue, 2 Jul 2024 11:20:14 +0200 Message-ID: <20240702092051.45754-32-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In order to access SDState::SDProto from sd_[a]cmd_name(), pass SDState as argument. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-38-philmd@linaro.org> --- hw/sd/sd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 90bb47ad26..5b356f0be8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -230,7 +230,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp) return response_name[rsp]; } -static const char *sd_cmd_name(uint8_t cmd) +static const char *sd_cmd_name(SDState *sd, uint8_t cmd) { static const char *cmd_abbrev[SDMMC_CMD_MAX] = { [0] = "GO_IDLE_STATE", [1] = "SEND_OP_COND", @@ -269,7 +269,7 @@ static const char *sd_cmd_name(uint8_t cmd) return cmd_abbrev[cmd] ? cmd_abbrev[cmd] : "UNKNOWN_CMD"; } -static const char *sd_acmd_name(uint8_t cmd) +static const char *sd_acmd_name(SDState *sd, uint8_t cmd) { static const char *acmd_abbrev[SDMMC_CMD_MAX] = { [6] = "SET_BUS_WIDTH", @@ -1273,7 +1273,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) uint64_t addr; uint32_t data; - sd->last_cmd_name = sd_cmd_name(req.cmd); + sd->last_cmd_name = sd_cmd_name(sd, 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. */ @@ -1740,7 +1740,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { - sd->last_cmd_name = sd_acmd_name(req.cmd); + sd->last_cmd_name = sd_acmd_name(sd, req.cmd); 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; From patchwork Tue Jul 2 09:20:15 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: 13719295 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 0E2DEC3064D for ; Tue, 2 Jul 2024 09:29:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZkN-0003Do-3L; Tue, 02 Jul 2024 05:24: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 1sOZk9-000300-Jg for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:11 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZk7-0007zq-Sc for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:09 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2ec1ac1aed2so46136821fa.3 for ; Tue, 02 Jul 2024 02:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912244; x=1720517044; 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=kI14nFtkmVuLlf2mzl5p+7UiBT46U4YhEycE/q3yJNg=; b=WYLbpYjVP3MPqj7HcQuYGd6E9nuBdcqLXrbVOrWUJ2o3uuUS1yxoaoAAaihL6ckaBy 0llCqb0rDxIMyCX1SY51ZLRKwwKwdxe8GHa/wzZD+ZpaJpOdIMJ4bkUmmtmExmlKe22u Zbu151gd3xb9Ek8Z2dyhWN7QHyKuRdEjIB369Qyp9OfDBdg8b2xvTSb2Li2kuwXWaEby CYuwcfpQE+qkr2NkFMdZ86bE++/A+ijl1tWvlwguFKP0MqiHN7Ryzo5rUa0O60f0CtHT kZwhk9kyR88vl/DkQFZwwDFpEIv3ZVEYAgMAh8+n9fODEONnI0qdzodXHRhWZY5spJ1C 4CiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912244; x=1720517044; 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=kI14nFtkmVuLlf2mzl5p+7UiBT46U4YhEycE/q3yJNg=; b=AUodriWVxWqk8CVeVzDqQL/a3exEZpXPQdWrgeqhF+XEyRtiwBv7jSrFFoDLU+ZgLR 7OcWKJToXT5iWuDkKS3djPuN7f3JMwIdHk85KA/rnLN73/ypGfz9L8z+X9KZJZTBpzPC NaPq6KHYvS5bJPyhYsDbNCqshKZNQeeV56q8eAZxrY04qAL1Z6BWHRLdOcLmnx2vOX+h UAs0kuqeWNUzkfs6IrrZjnygVarJM6KOyWtCm+v0h4LHNev9cl9h3N5elaWg8valO2RD 6URR7vYnkvNg0nXnfLh9Kes39tjUXrjjwDtrbKF9yWYhYWDPAkMeQuPtpXtpJGLtNbxa FNwA== X-Gm-Message-State: AOJu0Ywk5js3x35Cg7NBFDDfiwyRqy14EoAJZt49I8wtlx3WwwsRq0pN MbNsMc64dntQHAL/WgO7E/oB4IJ1hKLZruFFuPhFwb/ojQfPQiuOfp51nUsdfMgEgXsSyx9vdWN X X-Google-Smtp-Source: AGHT+IHu7MCC2sXjyjB8GzH1+Yq1QSSBOOgFtATuG3kI63+roFHZD0hExAfHlZWtyBObQWf0GQxkBQ== X-Received: by 2002:a2e:6817:0:b0:2ec:514f:89b3 with SMTP id 38308e7fff4ca-2ee5e3b37b2mr51963261fa.28.1719912243896; Tue, 02 Jul 2024 02:24:03 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b09aa32sm189836575e9.34.2024.07.02.02.24.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:03 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 32/67] hw/sd/sdcard: Prepare SDProto to contain more fields Date: Tue, 2 Jul 2024 11:20:15 +0200 Message-ID: <20240702092051.45754-33-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=philmd@linaro.org; helo=mail-lj1-x22e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Convert array of command handlers to array of structures. The structure contains the command handler. No logical change intended. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-39-philmd@linaro.org> --- hw/sd/sd.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5b356f0be8..fb82bc9aa3 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -93,8 +93,9 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; - sd_cmd_handler cmd[SDMMC_CMD_MAX]; - sd_cmd_handler acmd[SDMMC_CMD_MAX]; + struct { + sd_cmd_handler handler; + } cmd[SDMMC_CMD_MAX], acmd[SDMMC_CMD_MAX]; } SDProto; struct SDState { @@ -1297,8 +1298,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_illegal; } - if (sd->proto->cmd[req.cmd]) { - return sd->proto->cmd[req.cmd](sd, req); + if (sd->proto->cmd[req.cmd].handler) { + return sd->proto->cmd[req.cmd].handler(sd, req); } switch (req.cmd) { @@ -1745,8 +1746,8 @@ static sd_rsp_type_t sd_app_command(SDState *sd, req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |= APP_CMD; - if (sd->proto->acmd[req.cmd]) { - return sd->proto->acmd[req.cmd](sd, req); + if (sd->proto->acmd[req.cmd].handler) { + return sd->proto->acmd[req.cmd].handler(sd, req); } switch (req.cmd) { @@ -2269,22 +2270,22 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { - [0] = sd_cmd_GO_IDLE_STATE, - [1] = spi_cmd_SEND_OP_COND, + [0] = {sd_cmd_GO_IDLE_STATE}, + [1] = {spi_cmd_SEND_OP_COND}, }, .acmd = { - [41] = spi_cmd_SEND_OP_COND, + [41] = {spi_cmd_SEND_OP_COND}, }, }; static const SDProto sd_proto_sd = { .name = "SD", .cmd = { - [0] = sd_cmd_GO_IDLE_STATE, - [2] = sd_cmd_ALL_SEND_CID, - [3] = sd_cmd_SEND_RELATIVE_ADDR, - [19] = sd_cmd_SEND_TUNING_BLOCK, - [23] = sd_cmd_SET_BLOCK_COUNT, + [0] = {sd_cmd_GO_IDLE_STATE}, + [2] = {sd_cmd_ALL_SEND_CID}, + [3] = {sd_cmd_SEND_RELATIVE_ADDR}, + [19] = {sd_cmd_SEND_TUNING_BLOCK}, + [23] = {sd_cmd_SET_BLOCK_COUNT}, }, }; From patchwork Tue Jul 2 09:20:16 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: 13719307 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 59512C41513 for ; Tue, 2 Jul 2024 09:30:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZkW-0003O9-Dp; Tue, 02 Jul 2024 05:24:32 -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 1sOZkE-00035Y-GU for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:16 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZkC-00081b-Lw for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:14 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-52e8b27f493so2170326e87.2 for ; Tue, 02 Jul 2024 02:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912249; x=1720517049; 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=YPLvB2ZG14xjBMcX/e0G2maNGEfR8AYKqnkrhl4dPtE=; b=I7BxzGd9Bw/NJrLPONdqiiwZqZ/+nvJC/kDy9CrZoYpz1FHuCKMHOrOM1FCSlLJDnq 600Da2gxEDKfxj0NPNvY3rjJMQZDKWtTjf8Jqrfc7mNf7eycgViYxPnJU00IqUwvlS05 Ouol7IDjdBFcMoIgPORRZ3lbEd6SDNv1ExRPLNde7fP1luM+dzv53spfkYBz2K8i2RKl c8Wjwr7vd9GJNwnT6LeTyp4w6xozozlKnABlDOCvlrGoLDaCxdnxpk04u8jIeD5yVAoX rFgdFlZ98A6SdDwJkmTnu8qWkzVirUJiLb3cxAmxv3df2YMWyQX07/I97H8dMYFsQd6J yBFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912249; x=1720517049; 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=YPLvB2ZG14xjBMcX/e0G2maNGEfR8AYKqnkrhl4dPtE=; b=hrXieF71blzLyj14JUURrlOlUFSURO9Ic1qgJTU4dHMH+jTfwYmC7k5bBvWEBpxjC7 TqoGLqDXZhx7jyjwhJd/85BQBsFDSuj7ABSxqD+lb6fn/i9WZhUve1kimcz4IwJZ0QZD Bg60hT0duZ+rIEyRkqn6FV/++PAV6Vmf//A1UpRRUJFDC6AedQmYKB8dU/SVMylDVHEf B4wmR8t5ZBxsO5+jN75NaxKp6+sBhtKG+ms6ezFmSVU8ecDQswnjHwK9HzdDEb0sCKWf i/cbp3QVSoQTN1vqn26weoUfspDH6vi9dbAzYrk9va0PZcOwHXgPW0F1ON+b+V/HKVVv hdcA== X-Gm-Message-State: AOJu0YxIMcRD4Z9LSCl/i1uWjqMaGNdkF9N162SqJnaqHR143ZUVL3t5 v9UQtvf5sL9g1EOv9ebV/QNxynySTrAXGNyVWl8aJ6IWDPfnh17yW4HngqBqD34WIozZ0+rriMo F X-Google-Smtp-Source: AGHT+IEFf0KAHsrl2tz/Wxr6UNS7B3N57HJdnRmOoujSNtNZZl2R4KjnJc9j/eq7z79PdBMkPRjgXw== X-Received: by 2002:a05:6512:3ca9:b0:52e:765b:c00e with SMTP id 2adb3069b0e04-52e8264c2femr5297206e87.7.1719912249669; Tue, 02 Jul 2024 02:24:09 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b064f16sm190197265e9.27.2024.07.02.02.24.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 33/67] hw/sd/sdcard: Store command name in SDProto Date: Tue, 2 Jul 2024 11:20:16 +0200 Message-ID: <20240702092051.45754-34-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12b; envelope-from=philmd@linaro.org; helo=mail-lf1-x12b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We already have a const array where command handlers are listed. Store the command name there too. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-40-philmd@linaro.org> --- hw/sd/sd.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fb82bc9aa3..2cfba6ff60 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -94,6 +94,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; struct { + const char *name; sd_cmd_handler handler; } cmd[SDMMC_CMD_MAX], acmd[SDMMC_CMD_MAX]; } SDProto; @@ -234,8 +235,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] = { - [0] = "GO_IDLE_STATE", [1] = "SEND_OP_COND", - [2] = "ALL_SEND_CID", [3] = "SEND_RELATIVE_ADDR", [4] = "SET_DSR", [5] = "IO_SEND_OP_COND", [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", @@ -243,9 +242,8 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", - [18] = "READ_MULTIPLE_BLOCK", [19] = "SEND_TUNING_BLOCK", + [18] = "READ_MULTIPLE_BLOCK", [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", - [23] = "SET_BLOCK_COUNT", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", @@ -267,6 +265,12 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", }; + const SDProto *sdp = sd->proto; + + if (sdp->cmd[cmd].handler) { + assert(!cmd_abbrev[cmd]); + return sdp->cmd[cmd].name; + } return cmd_abbrev[cmd] ? cmd_abbrev[cmd] : "UNKNOWN_CMD"; } @@ -279,7 +283,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [16] = "DPS_spec", [18] = "SECU_spec", [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", - [41] = "SD_SEND_OP_COND", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", @@ -287,6 +290,12 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [56] = "SECU_spec", [57] = "SECU_spec", [58] = "SECU_spec", [59] = "SECU_spec", }; + const SDProto *sdp = sd->proto; + + if (sdp->acmd[cmd].handler) { + assert(!acmd_abbrev[cmd]); + return sdp->acmd[cmd].name; + } return acmd_abbrev[cmd] ? acmd_abbrev[cmd] : "UNKNOWN_ACMD"; } @@ -2270,22 +2279,22 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { - [0] = {sd_cmd_GO_IDLE_STATE}, - [1] = {spi_cmd_SEND_OP_COND}, + [0] = { "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [1] = { "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, .acmd = { - [41] = {spi_cmd_SEND_OP_COND}, + [41] = { "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; static const SDProto sd_proto_sd = { .name = "SD", .cmd = { - [0] = {sd_cmd_GO_IDLE_STATE}, - [2] = {sd_cmd_ALL_SEND_CID}, - [3] = {sd_cmd_SEND_RELATIVE_ADDR}, - [19] = {sd_cmd_SEND_TUNING_BLOCK}, - [23] = {sd_cmd_SET_BLOCK_COUNT}, + [0] = { "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [2] = { "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [3] = { "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, + [19] = { "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, + [23] = { "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, }; From patchwork Tue Jul 2 09:20:17 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: 13719286 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 1C36BC3064D for ; Tue, 2 Jul 2024 09:28:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZkY-0003eT-D3; Tue, 02 Jul 2024 05:24:34 -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 1sOZkS-0003Nk-8v for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:28 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZkI-00005H-W4 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:28 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2ee7885aa5fso3014801fa.1 for ; Tue, 02 Jul 2024 02:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912256; x=1720517056; 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=jPA9R4YCYQBkQZ2o9Ln39vUoRWjzfB1ZKjrmxeGewtg=; b=lDGu8B3YsG28PtcnU2QFl9n3tiCjVfKzwAkQqw18cUZjpagppqC4CqigLXRKG85R8o FuAa2ZlNndE7mzSkj5YgykezlQ7+cUI9xQb9bsiymmZFWg7usIiAttvt9P9XWDJfURl3 81XNVgF2hdUg66RBW8mPPfLm9Z/OnGT/BcjlPQUzOw+zD0gavq/0vI/VRKIsCbZooehK tjFapT48ldXWSjFliIryQ5K5YA4IsmkAk0u8Ia5PDrKLCx6+scMQxHr20AOj50Ma8efn nBOUJ3n+3AasMX4n5P5j1sMq8y2NmoSuOmHX1+mS63T2FhY7vQWXJdywSyywFks05rXA w+kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912256; x=1720517056; 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=jPA9R4YCYQBkQZ2o9Ln39vUoRWjzfB1ZKjrmxeGewtg=; b=P3DUPDXUSuV7vCwsxcxjPBvy6AtguQ8TglTm3FL5IROEtoTVqkE/cpqg5jW7MhFXBw 7heJ95qTOAgfPY5RTWqjI17e1AKPns/Zdcx0JbjILQBY05ikg+nJH0bMkOKcrq3/Lf03 potG6jjeq+n2n95NPewh/u+uvyRNbWSNbkPpEa/b3xxTKMtfdfL8hYt9snfHvfqS6tVD NE409n2LGoqrB4sAX0YpbFWYQW7pLFemOBq4UNcZ/hXhMJA8VUAnMniTMw4acpyYx/Ev Qo93qPw4cEXfsNRuCMay7Orjduuyg9n3fCNDqoL7+DzKRlJuZD9l+54pWYIZ7JLQyAyK peLA== X-Gm-Message-State: AOJu0YyEys06OcOj47f06G8Nz+3W6NMJ3BcgAhlPlDvygDYGo7zoMek7 Jl+UXaU3FtWCjoVNOkPaoPaCoTya71/PjN8iEjVDdjXKEf8D5+ucZPlgXvUgXSNVMHQGJFvs3Cm Y X-Google-Smtp-Source: AGHT+IFi69LS8wzhKDVdVv3BKpulOMpX36FD9hDxPqh5qaxOqnviwcImsi800fFHmEagNcO5D9c/iQ== X-Received: by 2002:a2e:2407:0:b0:2ec:839c:938e with SMTP id 38308e7fff4ca-2ee5e6d746bmr49607001fa.45.1719912255749; Tue, 02 Jul 2024 02:24:15 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af389b3sm192408485e9.1.2024.07.02.02.24.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 34/67] hw/sd/sdcard: Store command type in SDProto Date: Tue, 2 Jul 2024 11:20:17 +0200 Message-ID: <20240702092051.45754-35-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=philmd@linaro.org; helo=mail-lj1-x22e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Store the command type altogether with the command handler and name. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-41-philmd@linaro.org> --- include/hw/sd/sd.h | 5 +++-- hw/sd/sd.c | 44 ++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index 2c8748fb9b..29c76935a0 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -76,8 +76,9 @@ typedef enum { } sd_uhs_mode_t; typedef enum { - sd_none = -1, - sd_bc = 0, /* broadcast -- no response */ + sd_none = 0, + sd_spi, + sd_bc, /* broadcast -- no response */ sd_bcr, /* broadcast with response */ sd_ac, /* addressed -- no data transfer */ sd_adtc, /* addressed with data transfer */ diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2cfba6ff60..9f257906b5 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -94,6 +94,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; struct { + const sd_cmd_type_t type; const char *name; sd_cmd_handler handler; } cmd[SDMMC_CMD_MAX], acmd[SDMMC_CMD_MAX]; @@ -348,20 +349,6 @@ static void sd_set_mode(SDState *sd) } } -static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX] = { - sd_bc, sd_none, sd_bcr, sd_bcr, sd_none, sd_none, sd_none, sd_ac, - sd_bcr, sd_ac, sd_ac, sd_adtc, sd_ac, sd_ac, sd_none, sd_ac, - /* 16 */ - sd_ac, sd_adtc, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, - sd_adtc, sd_adtc, sd_adtc, sd_adtc, sd_ac, sd_ac, sd_adtc, sd_none, - /* 32 */ - sd_ac, sd_ac, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_none, - sd_none, sd_none, sd_bc, sd_none, sd_none, sd_none, sd_none, sd_none, - /* 48 */ - sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_ac, - sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, -}; - static const int sd_cmd_class[SDMMC_CMD_MAX] = { 0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, @@ -567,10 +554,19 @@ static void sd_set_rca(SDState *sd) 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) { + switch (s->proto->cmd[req.cmd].type) { + case sd_none: + /* Called from legacy code not ported to SDProto array */ + assert(!s->proto->cmd[req.cmd].handler); + /* fall-through */ + case sd_ac: + case sd_adtc: return req.arg >> 16; + case sd_spi: + g_assert_not_reached(); + default: + return 0; } - return 0; } /* Card Status register */ @@ -2279,22 +2275,22 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { - [0] = { "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [1] = { "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [0] = { sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [1] = { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, .acmd = { - [41] = { "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [41] = { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; static const SDProto sd_proto_sd = { .name = "SD", .cmd = { - [0] = { "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [2] = { "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, - [3] = { "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, - [19] = { "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, - [23] = { "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [0] = { sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [2] = { sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [3] = { sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, + [19] = { sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, + [23] = { sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, }; From patchwork Tue Jul 2 09:20:18 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: 13719284 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 7209AC3064D for ; Tue, 2 Jul 2024 09:27:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZkc-0003rW-2h; Tue, 02 Jul 2024 05:24:38 -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 1sOZkT-0003Rt-RM for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:31 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZkO-00009v-6w for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:29 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4257d5fc9b7so18826665e9.2 for ; Tue, 02 Jul 2024 02:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912261; x=1720517061; 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=NdXTl1syEL0/e8CCzGe/VrOY/+llJ3nM1VXYbHMVSR0=; b=DYwc7CYYNFvDiz9Dgt7ncebHM/JYq9uePATOHkIyREeahMg85ql0CwS1TaE2kPA96+ xwfhPCbMCltBa264HJB0qytorVKsWIAh4J7ckrO18onot9zytC36Yav9E3u2NdjvgeEM y4iaeh3mcYTbpD8Zr+azM2DtVcpIJ9nc+draIWfruVI5Mz7q8nRCKWdyId29Q9MKgTHx X/aDE0e7xpz2d4nfRNiQTAHJ81A2Gkcxla0fgLRRKShaWmGYTOZg+9pYppcVJ77QR6lW bfPR/efmF1XEwcPi9W+q18820MS/mCh/JVa0dQmTBr9dN/3NqTZoKE2vsv8ns4pukacV o2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912261; x=1720517061; 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=NdXTl1syEL0/e8CCzGe/VrOY/+llJ3nM1VXYbHMVSR0=; b=Sbxr9BWjrxqLgOHHsz0qqyr4Lozk/3RvS8AvYyternmZ4zw6jfH3H7d8QPQp+U5OFy fTHsxJtBugshTI20WU9r2DlNW1MMtHgikcLEImzmKJSkW488RBZ+H/n+08T6IAJlQhmp VxFx7/F45S667sNS0ibn4TXiikeE3pEU1NGlrL4QDFaAsWqoW/TNkRrsqtOKdAZ/S4Ra z7WqY92mb4VBaLjHhmaAjZzJrF7UZGDovdIHpQVn7o42wJG6A/b65tKB1wpCfIDgRnDD 59nyWF24hGRvGfk8pyls2x7Gap5AYRu31lLKnE6YNjsjCmGfnUVU9e0bquwat8s6pxVZ QskA== X-Gm-Message-State: AOJu0YyrP/hAeKfHUbivIWMTzKDDgHlYmjspWEHzRJcGVeKJEWooCuZH bZoSe87dC/JE4PYVz5JFRj+adazPW5+/QaLO48Jcb7DQQR1s57nZYzxf9q1MPljOf0+rPbU9dLd 7 X-Google-Smtp-Source: AGHT+IFnVf/7K/MK9YzmRLKdP4X0dYe8K/UtmoegoKop9lMclKrQAv38jwTpHLLe1tkeUDNuyfC6Qw== X-Received: by 2002:a05:600c:4a07:b0:421:29cd:5c95 with SMTP id 5b1f17b1804b1-4257a00674amr72069225e9.10.1719912261581; Tue, 02 Jul 2024 02:24:21 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af3912asm195612945e9.10.2024.07.02.02.24.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 35/67] hw/sd/sdcard: Store command class in SDProto Date: Tue, 2 Jul 2024 11:20:18 +0200 Message-ID: <20240702092051.45754-36-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=philmd@linaro.org; helo=mail-wm1-x32c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Store the command class altogether with the other command fields (handler, name and type). Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-42-philmd@linaro.org> --- hw/sd/sd.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 9f257906b5..68e6944263 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -94,6 +94,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; struct { + const unsigned class; const sd_cmd_type_t type; const char *name; sd_cmd_handler handler; @@ -349,13 +350,6 @@ static void sd_set_mode(SDState *sd) } } -static const int sd_cmd_class[SDMMC_CMD_MAX] = { - 0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, - 5, 5, 10, 10, 10, 10, 5, 9, 9, 9, 7, 7, 7, 7, 7, 7, - 7, 7, 10, 7, 9, 9, 9, 8, 8, 10, 8, 8, 8, 8, 8, 8, -}; - static uint8_t sd_crc7(const void *message, size_t width) { int i, bit; @@ -1298,7 +1292,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->multi_blk_cnt = 0; } - if (sd_cmd_class[req.cmd] == 6 && FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { + if (sd->proto->cmd[req.cmd].class == 6 && FIELD_EX32(sd->ocr, OCR, + CARD_CAPACITY)) { /* Only Standard Capacity cards support class 6 commands */ return sd_illegal; } @@ -1883,6 +1878,8 @@ static sd_rsp_type_t sd_app_command(SDState *sd, static bool cmd_valid_while_locked(SDState *sd, unsigned cmd) { + unsigned cmd_class; + /* Valid commands in locked state: * basic class (0) * lock card class (7) @@ -1897,7 +1894,12 @@ static bool cmd_valid_while_locked(SDState *sd, unsigned cmd) if (cmd == 16 || cmd == 55) { return true; } - return sd_cmd_class[cmd] == 0 || sd_cmd_class[cmd] == 7; + if (!sd->proto->cmd[cmd].handler) { + return false; + } + cmd_class = sd->proto->cmd[cmd].class; + + return cmd_class == 0 || cmd_class == 7; } int sd_do_command(SDState *sd, SDRequest *req, @@ -2275,22 +2277,22 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi = { .name = "SPI", .cmd = { - [0] = { sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [1] = { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, .acmd = { - [41] = { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; static const SDProto sd_proto_sd = { .name = "SD", .cmd = { - [0] = { sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [2] = { sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, - [3] = { sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, - [19] = { sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, - [23] = { sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [0] = {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, + [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, + [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, }; From patchwork Tue Jul 2 09:20:19 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: 13719272 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 99AC1C30658 for ; Tue, 2 Jul 2024 09:26:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZka-0003kR-3t; Tue, 02 Jul 2024 05:24:36 -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 1sOZkW-0003Ug-IT for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:32 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZkT-0000AI-8t for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:30 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42578fe58a6so19197785e9.3 for ; Tue, 02 Jul 2024 02:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912267; x=1720517067; 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=HBHa6mNek3D9ym3Q87IBUwFBzBOdC5TAXndf6AluXYE=; b=K10Y1QbVj8xLvNe0o6ZE0fwXkSTa2wJ3eFNKziO+HCLeXAi0ubXLwPaYQ23Qh0XqIq FR4KPEgqu49qZa9JiLLZdhnL3FJxWav/WEpaZgM4rQMsNtjvw3FPup9sc+pyoxrSuN8O MRMVl5CwiwVy5B994S9mjLeQySWTVuG0CZDTH1PmASkBLTBfc9SvzvTVNOlhamH10SsK 596fJDkhhaE6MbINHDQxP4s05b3tuMQdLQrsGOHgq1pDx1tfsSbSwcKWGsLM4MhnoCfO ZWWYMd6ZXw6WbBRN5Pxt+ChFM7koAwa5rEt4ZB++JTjqGf8zTExHTErwWQ6camzz9aQa taug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912267; x=1720517067; 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=HBHa6mNek3D9ym3Q87IBUwFBzBOdC5TAXndf6AluXYE=; b=cpPnFE+39DHJmM8AUSFLG74W2SvMOCfiPh2E2v/RrkqPvZAmGZ+x6xE3bbFygi3GM/ hfOiiyeujeMxmK63EGgDb4A28gN/9jxe4Zw9Yq6bSC1RfOlD6MInYJVRo72GVIQg7A8r 7AgkpC+L9LIG/DYVqGj+PpmLFjS5WZdexSYNqc7NWfAXOvU7p1nr+kQrkg4Gt/I5ZeXx bF+4dMCW64Xbcty0bC+Oy14g4HFVz+wRhbFIdckFiwrY7IXFfVeUzARNtgg2OXnNlb0b LkzJ+//MoKg6VKkHBrhi171trINIVNXevgbVdCTdx4mH9jzjqGxIF6ac82ohHRh39qED uqaQ== X-Gm-Message-State: AOJu0Yx+xBFU2b/yUj4y33u8s9Q2GPgrzky2IcqcCiRSaSPgnJKe+2pK kaPEjoJgX5ZwMQZRrgHVLzXXp/YnV027ieXu1LBf2a+ikaj1cmGITPNscVs3MLUrOLjfOFT7R/s + X-Google-Smtp-Source: AGHT+IHFkC/GD+27ERFvRsryG70pTGtkEADrgjcDrubK0lv/W0Khl8ppmFIG8qnq/jtS/TA7i4u0yg== X-Received: by 2002:a05:600c:2252:b0:424:a823:51d9 with SMTP id 5b1f17b1804b1-4257a06e036mr52075535e9.30.1719912267536; Tue, 02 Jul 2024 02:24:27 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a103d00sm12672880f8f.99.2024.07.02.02.24.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 36/67] hw/sd/sdcard: Remove SEND_DSR dead case (CMD4) Date: Tue, 2 Jul 2024 11:20:19 +0200 Message-ID: <20240702092051.45754-37-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philmd@linaro.org; helo=mail-wm1-x32b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The CSD::CSR_IMP bit defines whether the Driver Stage Register (DSR) is implemented or not. We do not set this bit in CSD: static void sd_set_csd(SDState *sd, uint64_t size) { ... if (size <= SDSC_MAX_CAPACITY) { /* Standard Capacity SD */ ... sd->csd[6] = 0xe0 | /* Partial block for read allowed */ ((csize >> 10) & 0x03); ... } else { /* SDHC */ ... sd->csd[6] = 0x00; ... } ... } The sd_normal_command() switch case for the SEND_DSR command do nothing and fallback to "illegal command". Since the command is mandatory (although the register isn't...) call the sd_cmd_unimplemented() handler. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-43-philmd@linaro.org> --- hw/sd/sd.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 68e6944263..c25e376b35 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,7 @@ 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] = { - [4] = "SET_DSR", [5] = "IO_SEND_OP_COND", + [5] = "IO_SEND_OP_COND", [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", [10] = "SEND_CID", [11] = "VOLTAGE_SWITCH", @@ -1148,7 +1148,6 @@ static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) } /* Commands that are recognised but not yet implemented. */ -__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", @@ -1304,16 +1303,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 4: /* CMD4: SEND_DSR */ - switch (sd->state) { - case sd_standby_state: - break; - - default: - break; - } - break; - case 6: /* CMD6: SWITCH_FUNCTION */ if (sd->mode != sd_data_transfer_mode) { return sd_invalid_mode_for_cmd(sd, req); @@ -2291,6 +2280,7 @@ static const SDProto sd_proto_sd = { [0] = {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, + [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, From patchwork Tue Jul 2 09:20:20 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: 13719312 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 D95C7C3065C for ; Tue, 2 Jul 2024 09:31:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZl8-0004Uj-2k; Tue, 02 Jul 2024 05:25:10 -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 1sOZkj-0004E2-5d for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:46 -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 1sOZkZ-0000Aw-9g for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:44 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-364ff42999eso1746035f8f.3 for ; Tue, 02 Jul 2024 02:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912273; x=1720517073; 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=ph442tiXvXeNCMFB68Xw+ODOVr0L1MOlNemy3MQKQw4=; b=FbVONF0AfTAufll9euSrMmC7dwo9kOVFtmdOrqVc3UeCs51oAL3AwgQK9F1P/tj+20 COKRBTBdZ0vZj6X8KJcNgt4TH//5C9G/b4lexbvFOFDA7z4HJRRF/mQettB0MUBuzITq VqSmiCo+z6+w0fThGc6AMC9hgNauPFRflrhCupzA2h5Ofr907CJScIM42m9aJtKK1SoZ EKnFZ2rUNY8fEHQJNeBz/EmkjK1Sk3vFYsNX0ukON31U2CYfsyxA8gsmbhO6BSmBcfqr hQuhsIo5TGMPgLQ/mwS3EDfX2srKmdH2gP0qKv6sEvqBL3wY2d6N53zw+uJPCbZs+ytN BxTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912273; x=1720517073; 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=ph442tiXvXeNCMFB68Xw+ODOVr0L1MOlNemy3MQKQw4=; b=fWJmGz0VnlLr/AVP+fwQXQYvAeTy6FeIQ1YkhE1vL+uph/mNIHh3KDQCLDWAMHUB3Y A5E6SqlYyDTtphQ4aeaASMiNo3G93ctXUMiFQ0ve4//2mHav3r0iH8V9hy3OwWZ5RslV Zsk3cPKzvjfWGiPif0k6C7+PySw2Ut78D2KJjwqulH56TT4gzkV0qgg91LYYC0F+N06H jA/YjoPX2+fqKqWLd4X8U+PtA8gQjMgn53TnCN8/7EC1I9P9OP7hmysOnV7VLa0IRSzK RfBhR/PvlbVxUmUn5LuMuG02NaWo71FGe0GzkfLhGJgK5LMyP3JREwZpNtd+jbvv0Bnr QpaQ== X-Gm-Message-State: AOJu0Yy31ESWTQpJotpn9v5zcOPMcQIz1+/eVnmdZq7GoVLUPghZXX9g Fg9tXqy+BX1DDHcZ2vHiegXJtYsQ6bBqlYnM0QlQ2HsPNevZ/UJrDzsFpecFakhUgnx+Lm95fnJ b X-Google-Smtp-Source: AGHT+IFFsVYnvpaOnuaG6ynniSLtIhuX//JyQ536N1m8Fv39CzYA9z3/eK6Z6MaEkuDVSvjbcXaUwQ== X-Received: by 2002:adf:ce0a:0:b0:364:29ce:b14e with SMTP id ffacd0b85a97d-367757307aemr7145020f8f.69.1719912273339; Tue, 02 Jul 2024 02:24:33 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b068e54sm192840175e9.25.2024.07.02.02.24.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 37/67] hw/sd/sdcard: Register generic optional handlers (CMD11 and CMD20) Date: Tue, 2 Jul 2024 11:20:20 +0200 Message-ID: <20240702092051.45754-38-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-44-philmd@linaro.org> --- hw/sd/sd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index c25e376b35..b4fd863189 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -240,12 +240,12 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [5] = "IO_SEND_OP_COND", [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", - [10] = "SEND_CID", [11] = "VOLTAGE_SWITCH", + [10] = "SEND_CID", [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", - [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", + [21] = "DPS_spec", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", @@ -1156,6 +1156,14 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +static sd_rsp_type_t sd_cmd_optional(SDState *sd, SDRequest req) +{ + qemu_log_mask(LOG_UNIMP, "%s: Optional CMD%i not implemented\n", + sd->proto->name, req.cmd); + + return sd_illegal; +} + /* Configure fields for following sd_generic_write_byte() calls */ static sd_rsp_type_t sd_cmd_to_receivingdata(SDState *sd, SDRequest req, uint64_t start, size_t size) @@ -2281,7 +2289,9 @@ static const SDProto sd_proto_sd = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [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}, }, }; From patchwork Tue Jul 2 09:20:21 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: 13719273 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 6D85EC3064D for ; Tue, 2 Jul 2024 09:26:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZkp-0004KV-8p; Tue, 02 Jul 2024 05:24:56 -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 1sOZkh-0004Bt-Jh for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:43 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZke-0000B8-I7 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:43 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-36532d177a0so2323182f8f.2 for ; Tue, 02 Jul 2024 02:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912279; x=1720517079; 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=kBNEOV+SuPOCA0UAQQw56j+dIx9/wiXRzt0fyiV5P8w=; b=o90qysjraVHbOFsngDjlV60Wt/wBfGVLdTAIjXX6k0OwKuif6cyunDkPjmkT/eD9VL S92k+2tOE9NRylOrZVg+8lQDSjicAc+Otm5oryBQNBdYUfiXgyDytZ2UIrcUY7BdJePY 04aIg6KYF0EJZX+7hzJQINWYgzZ/Q3c6l2pWDusEgnzu/esj5Q71+egoUn6ohhK30zkN fkSSXOer3aPa4LKUDC7/RmjhOTRJRP7elPanwsJy72nfSM8vKScLH6k8dM89wm1GJ2s+ m5P1trYMb7ymlNri1c8xcAFNEccEhAWY4vAfTIAu6WloJpoCe+p2cmylqxRwv9P0qjK3 FIcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912279; x=1720517079; 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=kBNEOV+SuPOCA0UAQQw56j+dIx9/wiXRzt0fyiV5P8w=; b=tgBZzlAadz5u+n5vLSnfzf6SHtbEj4+Nwy94E19lMIlr94ziAK/AsuM0u5+tXi6w7Y qP/kOyet0QpW9u+frMThrqMyBCWqDl0KYd5aZmS2AndyjfsayVZNTT/XtvnwX9tK1/x6 Y346Wf6LIo5fKHdt2Us8N25sADO/Y1RL6tbQxgOSVws5GDh/2QHRz3rF6ni1XU+DMndn aCXExAvXL10VgdN6tj7L04zzN21SMj8fR8qJiJ6u7qnYjLkDMLuVAfDM8cClJr4p4gTt 2p6IugvrZwntQtG7vmwXEMtg0PPT//1kT883IKq7LYdld9iXL158yChiClDGOZvmc7hB j1CQ== X-Gm-Message-State: AOJu0YxezHDkr/L1wzowU2/rBD3JUrwB1MYQGxdgAbwQD/1mknFkKT4P sy+bldbIQ+xcH3XJKrywj5Vxb05UXR7+dujZwfePEsaVEXFEiEw4UCY9O7dY6PHKN5cxYUHKDAJ a X-Google-Smtp-Source: AGHT+IFErg7G7wsPLl8W84UCWcRYiV82+zmBASthOJr/PnownlcQwvVaNPBY2S8Qgk/yRf5Nbpoe6w== X-Received: by 2002:a5d:54c9:0:b0:367:6b05:356a with SMTP id ffacd0b85a97d-367756bb441mr4604682f8f.36.1719912278951; Tue, 02 Jul 2024 02:24:38 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0cd663sm12752958f8f.3.2024.07.02.02.24.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:38 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 38/67] hw/sd/sdcard: Register optional handlers from spec v6.00 Date: Tue, 2 Jul 2024 11:20:21 +0200 Message-ID: <20240702092051.45754-39-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-45-philmd@linaro.org> --- hw/sd/sd.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b4fd863189..f8672b6603 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -255,15 +255,11 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", [38] = "ERASE", [40] = "DPS_spec", - [42] = "LOCK_UNLOCK", [43] = "Q_MANAGEMENT", - [44] = "Q_TASK_INFO_A", [45] = "Q_TASK_INFO_B", - [46] = "Q_RD_TASK", [47] = "Q_WR_TASK", - [48] = "READ_EXTR_SINGLE", [49] = "WRITE_EXTR_SINGLE", + [42] = "LOCK_UNLOCK", [50] = "SW_FUNC_RSVD", [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", - [58] = "READ_EXTR_MULTI", [59] = "WRITE_EXTR_MULTI", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", }; @@ -2293,6 +2289,15 @@ static const SDProto sd_proto_sd = { [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}, + [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, + [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, + [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional}, + [46] = {1, sd_adtc, "Q_RD_TASK", sd_cmd_optional}, + [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, + [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, + [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, + [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, }, }; From patchwork Tue Jul 2 09:20:22 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: 13719271 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 82D04C3064D for ; Tue, 2 Jul 2024 09:26:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZlA-0004qH-Rv; Tue, 02 Jul 2024 05:25: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 1sOZkn-0004Ly-DK for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:51 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZkl-0000C9-O7 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:49 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42122ac2f38so23572085e9.1 for ; Tue, 02 Jul 2024 02:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912285; x=1720517085; 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=DNA/X248tgmPgC0TxVdzd0n0o4N/WEHWfZeXeWaMVQw=; b=ByagCKsjdwfkyV+Vm9i340lQTR5n6pv4HyoSVXW32zPeK64r9BGhM+AGJ4m+Gt7wzJ 6CanE+NVIZQV09YUMePb0NQdruzG5LAXOnWHWA4yPl5fERnIA9UOvKVYg5U/fGEu9m05 VRzOA0suIqUiy+s3OG7jOEQJ457QNLALFK5AUv2LJqUlnF/UkqiHWl+QFHopXKoMXP0m J59IaarKeJ0DcwZ3rMZJm/bPU0IlwXREjq6wSi0bNWlEg3DLf6SvlzqI4AObrycIptw2 TN0UAZFJch+I9uTXsA4sz50VRuWpte0jq3XQ8UhMLXrcrFDtfqhxLVRy+yi7+GxqNmbK cCXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912285; x=1720517085; 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=DNA/X248tgmPgC0TxVdzd0n0o4N/WEHWfZeXeWaMVQw=; b=TpjJ4exkBpKZoXZOhOn//ujiWykLoCm6yCGpkgDh/ieUTBDyQyxHcln095TkHBh0o1 ddfvXroNhJoYnOME50d9CF7kUC/w4ibxPGkq3qvR2gJdVFEmtgg2CRSeHtkuuNIDv6ey CfJ8c4Kc4aKMh4V1fND9geTpzq30554q0Du2CdTKiaWzabIyNcxk9R0Rx8xrkZRo+FZP zx0hsWPFvmNRN7qzDHmQuKw+LYcwYpJODSdMIDFoy+TcmZ5g7SlTzWqsdSY2D3PPPEPE K1MBGRBtzxQIb5Hw+Dz7I7vERzjGwqL/4jNRO7I0No/YSoarK7+fX0eMyr8GTQnN6c4N j1Qg== X-Gm-Message-State: AOJu0YzSZah6LoAN51qASck4f4LidMRkMjHgB38t+uJNGTl/Oy4P5yhF 0k4Q0PHCa19doGXDob95g7yLTdnFthsw3BwMka6cnYVWHZTlbikU4oLYfVCMqrvpCMH7Y9vcOVv L X-Google-Smtp-Source: AGHT+IFDOy2D0nol22G8v++qQr49h+TJLsObC59NMG8pPQjH4YRAoSyqMERlhjpLUGxA1DuS6f8wHg== X-Received: by 2002:a05:600c:3552:b0:425:7c42:d24b with SMTP id 5b1f17b1804b1-4257c42d3a0mr62065735e9.18.1719912285154; Tue, 02 Jul 2024 02:24:45 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36789fd7a0esm830044f8f.104.2024.07.02.02.24.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:44 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 39/67] hw/sd/sdcard: Register SDIO optional handlers Date: Tue, 2 Jul 2024 11:20:22 +0200 Message-ID: <20240702092051.45754-40-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org See "SD Input/Output Card Specification" v1.00. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-46-philmd@linaro.org> --- hw/sd/sd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index f8672b6603..e050f3d5ef 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,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] = { - [5] = "IO_SEND_OP_COND", [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", [10] = "SEND_CID", @@ -257,7 +256,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [40] = "DPS_spec", [42] = "LOCK_UNLOCK", [50] = "SW_FUNC_RSVD", - [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", @@ -2272,6 +2270,9 @@ static const SDProto sd_proto_spi = { .cmd = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, + [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, }, .acmd = { [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, @@ -2285,6 +2286,7 @@ static const SDProto sd_proto_sd = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, @@ -2296,6 +2298,8 @@ static const SDProto sd_proto_sd = { [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, + [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, }, From patchwork Tue Jul 2 09:20:23 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: 13719296 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 03678C30658 for ; Tue, 2 Jul 2024 09:29:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZl9-0004kD-GH; Tue, 02 Jul 2024 05:25:11 -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 1sOZks-0004Os-Na for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:02 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZkr-0000Cu-0p for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:54 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-363826fbcdeso2296550f8f.0 for ; Tue, 02 Jul 2024 02:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912291; x=1720517091; 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=disMBuk3hJGg0W6cSmQCN+rvZQMEtFoRNmHfDWQp/Yk=; b=Um8eBSbTqfhbp1VtkcJ6W2N1BcQH0/YXDeGNEUIPx2vfiy7KrN/UW4hR0GEQuyWx1v b4thLZF1aSMUubAVpf8TuHMZhskyxEroQddpyUUF3V/fj5i3XiAOcKgifk4b8I61Ga/1 SAaLKtlov+tthvw12LApNuR3ozrMTe7FxcpTwmDVwOGSdBmFGDktQ6LJTD/WfWs3QZCk MqzjSSTAf4Qlgs4TNrRlwy1bpcdrYjuP73JYamHKj9IpWMHQAO1vmc6s7j2M2Zfgj6qc OAX7p39MZELolUaQB8lXnFVr4zr2hWSXpFqrMO7188g/qnbNl7yzUcPaDTppO7+Yclxc rMqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912291; x=1720517091; 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=disMBuk3hJGg0W6cSmQCN+rvZQMEtFoRNmHfDWQp/Yk=; b=QNhxbjVqChxkALFzy0PcHpFBMM/b3jcyrhNpz1p+qxdvBRKkaKpCCPBVhQgoJJ9GVl oolItuKJg2lTdV2SIaM2M3GbIZxEK7VMt4LaFs6HZW8CiWWRE9Q4Hs78/PX/ek7O5mse TJXOvG4BLVUfNz1OecbpQj3uI4pwd2cpK4hBAbwvoCLQO8kCHnm9WFl/06T7SX//qQ7I hYlD+EV+JCfYSEraZ2DKZUSFDivHZvu0+RdNk2nmktQD9zwq4NA4ICD4G2uehVUF8ypy k4NyhVoUnNvogevXp5Es/2nASzSJ+OkgyUaSZbyVD+E2aqnBNFn3d4/QM0e3XIUbr5bz sOFg== X-Gm-Message-State: AOJu0YzLSkwp5D0I+vyAcFSMY1D+37ZRIpAnBvqs11GO2q6ItLcDX4Wy dQUnkQ5sUfS/8VDTXRX3i8ZEAUZcXvEVGIb+CBnN6vTDz4Ywpm+QQkXrkVe1hCF5msewtUWpfWy + X-Google-Smtp-Source: AGHT+IEaz4YVrXcJ+xoMewIndu3gKf1NzhIM6+QQ4Pj1o1t3twXDzsysxjpLnJ3nTBIEHIH26Hopww== X-Received: by 2002:a5d:4982:0:b0:35e:8364:f4d4 with SMTP id ffacd0b85a97d-36775728bd6mr4888040f8f.58.1719912290993; Tue, 02 Jul 2024 02:24:50 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0e1688sm12672279f8f.60.2024.07.02.02.24.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 40/67] hw/sd/sdcard: Register Security Extension optional handlers Date: Tue, 2 Jul 2024 11:20:23 +0200 Message-ID: <20240702092051.45754-41-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org See "Advanced Security SD Extension Specification" v2.00. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-47-philmd@linaro.org> --- hw/sd/sd.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e050f3d5ef..54b9ec72e4 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -250,14 +250,11 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", - [34] = "SW_FUNC_RSVD", [35] = "SW_FUNC_RSVD", - [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK", - [50] = "SW_FUNC_RSVD", [54] = "SDIO_RSVD", [55] = "APP_CMD", - [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", + [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", }; @@ -2271,8 +2268,14 @@ static const SDProto sd_proto_spi = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [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}, + [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, + [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, }, .acmd = { [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, @@ -2291,6 +2294,10 @@ static const SDProto sd_proto_sd = { [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}, + [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, + [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, + [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, + [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional}, @@ -2298,8 +2305,10 @@ static const SDProto sd_proto_sd = { [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [50] = {10, sd_adtc, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, + [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, }, From patchwork Tue Jul 2 09:20:24 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: 13719269 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 37771C3064D for ; Tue, 2 Jul 2024 09:25:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZl7-0004X1-2U; Tue, 02 Jul 2024 05:25:09 -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 1sOZky-0004QZ-7h for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:02 -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 1sOZkw-0000Dj-Do for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:24:59 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-42574064b16so24385845e9.2 for ; Tue, 02 Jul 2024 02:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912297; x=1720517097; 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=2LarMpzFABrHElvj3cOvSN3U3cpCJlLI7z8esfggSjk=; b=OrGmEDNd822MH6A7DGmq8OKRX75lhOREqiRvseth7JjbMsaN6dXhEhcJKqEnxUPHPt HLURdfR1fFdmPSVVcgYgLdGXmljuJcRcQD3Emi+WGooCDBMrl0LSKANG3+ZWMbl7PxFA COksc+ly9ZswI5zNSPBpb015tUxf1EXA+EmCeLPr8n9Dg8IomEUCrKYsrufLwuJ4Aar+ 70R+zr68ym9t+kv1ghf0nJ9/lW/xK1SPBjaRB7bLkSFvaO7nlVQieaekpa35rO7LWGqa /XbvrcL+clCqbbf079NLt9WGogu4gmwj66xgJMQAMQKmm78kY6txpvCGIc9lh61mb+ph p97w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912297; x=1720517097; 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=2LarMpzFABrHElvj3cOvSN3U3cpCJlLI7z8esfggSjk=; b=nVcsVzqaFudC7Auimu2ZQnYa6Fj5ciMrwcBOUATIFm4zvNGfE4/4ZvtHefIdMesCol ZL4MOn/K6R8FE6r6s5X9P1nHQuLx2Y3SRGWFRoKYmw0X/zmJnGAvCfh3Ea8GiWbo7yzd eZM5IiJEi9L/GAbv0eAsb6YfTeLepXfINS453NAGSoapDsmIeTgWXlX1e8/7HJYzVx59 FqiIZW54hfohxCbPpdQj+ZUWsajeZu9CemgRbRAzRSM1xyH8Ydlr6CzClGfcrzt6e25c gH/kX79qzy7fpFHmVfcWFO6klK43KYn9LbdRz+8xsp0Dxi1Si03KyKRxo654b1BwzzcY +DUw== X-Gm-Message-State: AOJu0YzGX9e4fP9oJ88O/H3HIwM6iglmTRgRH2sNaoQv4YS0xRGWGFE5 QyhJE10WfGekbQKeVXIC0yL3/WQFXbxuDbF2/cvD14YSHhrEQhTygHohOu3depVm4kaFIc9quip g X-Google-Smtp-Source: AGHT+IEUXztbBcGE0JhzTpba+nC9tjJkmtWNOharmNNmU3m/AD+xUCngFmVFG58S+E5PcKmdNVmCIg== X-Received: by 2002:a05:600c:4814:b0:425:7693:3a38 with SMTP id 5b1f17b1804b1-4257a074b37mr57811185e9.36.1719912296856; Tue, 02 Jul 2024 02:24:56 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af59732sm190276995e9.11.2024.07.02.02.24.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:24:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9?= =?utf-8?q?dric_Le_Goater?= Subject: [PULL 41/67] hw/sd/sdcard: Add sd_cmd_SWITCH_FUNCTION handler (CMD6) Date: Tue, 2 Jul 2024 11:20:24 +0200 Message-ID: <20240702092051.45754-42-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-48-philmd@linaro.org> --- hw/sd/sd.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 54b9ec72e4..5aa63f732f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,7 @@ 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] = { - [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", + [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", [10] = "SEND_CID", [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", @@ -1236,6 +1236,20 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +/* CMD6 */ +static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(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); + return sd_cmd_to_sendingdata(sd, req, 0, NULL, 64); +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1302,17 +1316,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 6: /* CMD6: SWITCH_FUNCTION */ - 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); - return sd_cmd_to_sendingdata(sd, req, 0, NULL, 64); - case 7: /* CMD7: SELECT/DESELECT_CARD */ rca = sd_req_get_rca(sd, req); switch (sd->state) { @@ -2268,6 +2271,7 @@ static const SDProto sd_proto_spi = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [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}, @@ -2290,6 +2294,7 @@ static const SDProto sd_proto_sd = { [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, + [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:25 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: 13719302 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 E8C03C3065C for ; Tue, 2 Jul 2024 09:30:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZlB-0004qu-2L; Tue, 02 Jul 2024 05:25:13 -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 1sOZl5-0004Um-Jm for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:08 -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 1sOZl2-0000Ef-KF for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:07 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-366e70d0330so2486945f8f.1 for ; Tue, 02 Jul 2024 02:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912302; x=1720517102; 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=Zo/bpULpmegEUncNLm6vCJ+QfqrrZDPASrwEVg/COu8=; b=aJ2g79RxCsa1dDDOqTWfJ61gH3zda79vXbSDY6xigtVDNR55JTIrxLHQfyPrZc0VYA 7KgQrJfqw63Hc707nkg6g7a9XNMX7O6z1ZaQcrFkjnfrNhRkeEKSEOAZ5wlGTZe+UHU9 lFh8IHYYy9/VrPWzBZS87qp7PQfb6Whlxng0+uI6jdNc4dprGjh/DE9eswzgFJObSYLO kBVKecHeXCLiBWNnmMSFG3sBjJVSgKm4JdDS6uhrtmlHKkjhZFvGFB2JzXPRKRfHw4a2 qBz3HtZrcawZG1R/ve+psI6dW4uVvIWayXzvfZ46yuD778AeaN1UuUEURpB2v4pAPYXn 1ujw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912302; x=1720517102; 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=Zo/bpULpmegEUncNLm6vCJ+QfqrrZDPASrwEVg/COu8=; b=qtV21RWrtf+S2/nneM1SHUdija29TZJjI49humYJFdD+iM5Lb0pxqtG7ycF2VK7C+c u3cY5XcNmFhOKBQRzUHxIy7fgdfbkvcCed/Yurb09Hf/RnYL7qIYnpqVTWY1c2kO2V3u sx5BOtl/MbXkcFtE8c/mvZyc1ohvOGSbzhWZPL9LKiWdJ/YCD5dOmKnUgWPgQYD4f/kT PkyrQyTYykD8sc+Oa3Lb/eCvE+zHSj+vKsx37qsSoHpN0GnqUnExXXV6Ehx4KuRQUZtu 90Viq9SeDy9y3T+UBwV7mXo7gLgf3+Dyol+or5WaxmBlR4b0TKg7SYrCJ1XCFNtESw9O fM2Q== X-Gm-Message-State: AOJu0Yx+P6s+ocOEOFpXUS2kLEZfPI2v3qq6otstqy/EvMacXF3L6zju mDN8kZUQZ1WSLQQnov8mIFb/PqtbDu+iek0hIYZgmK/76bJMxxI2WyLq583CQF0NURDSxOHelaT b X-Google-Smtp-Source: AGHT+IFF4Lmherb6wypgMxaSxmALyoC2BPIoYQD15lNxfSxvf5wP7rwoP8iyzTAv29AXBNuk6x3I9Q== X-Received: by 2002:a05:6000:18a1:b0:366:ebf5:c6cc with SMTP id ffacd0b85a97d-367757214e0mr5316534f8f.50.1719912302643; Tue, 02 Jul 2024 02:25:02 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fc4c9sm12636424f8f.86.2024.07.02.02.25.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:02 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 42/67] hw/sd/sdcard: Add sd_cmd_DE/SELECT_CARD handler (CMD7) Date: Tue, 2 Jul 2024 11:20:25 +0200 Message-ID: <20240702092051.45754-43-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-49-philmd@linaro.org> --- hw/sd/sd.c | 85 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5aa63f732f..f83ae4ed18 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,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] = { - [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", [10] = "SEND_CID", [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", @@ -554,6 +553,11 @@ static uint16_t sd_req_get_rca(SDState *s, SDRequest req) } } +static bool sd_req_rca_same(SDState *s, SDRequest req) +{ + return sd_req_get_rca(s, req) == s->rca; +} + /* Card Status register */ FIELD(CSR, AKE_SEQ_ERROR, 3, 1) @@ -1250,6 +1254,47 @@ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req) return sd_cmd_to_sendingdata(sd, req, 0, NULL, 64); } +/* CMD7 */ +static sd_rsp_type_t sd_cmd_DE_SELECT_CARD(SDState *sd, SDRequest req) +{ + bool same_rca = sd_req_rca_same(sd, req); + + switch (sd->state) { + case sd_standby_state: + if (!same_rca) { + return sd_r0; + } + sd->state = sd_transfer_state; + return sd_r1b; + + case sd_transfer_state: + case sd_sendingdata_state: + if (same_rca) { + break; + } + sd->state = sd_standby_state; + return sd_r1b; + + case sd_disconnect_state: + if (!same_rca) { + return sd_r0; + } + sd->state = sd_programming_state; + return sd_r1b; + + case sd_programming_state: + if (same_rca) { + break; + } + sd->state = sd_disconnect_state; + return sd_r1b; + + default: + break; + } + return sd_invalid_state_for_cmd(sd, req); +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1316,43 +1361,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 7: /* CMD7: SELECT/DESELECT_CARD */ - rca = sd_req_get_rca(sd, req); - switch (sd->state) { - case sd_standby_state: - if (sd->rca != rca) - return sd_r0; - - sd->state = sd_transfer_state; - return sd_r1b; - - case sd_transfer_state: - case sd_sendingdata_state: - if (sd->rca == rca) - break; - - sd->state = sd_standby_state; - return sd_r1b; - - case sd_disconnect_state: - if (sd->rca != rca) - return sd_r0; - - sd->state = sd_programming_state; - return sd_r1b; - - case sd_programming_state: - if (sd->rca == rca) - break; - - sd->state = sd_disconnect_state; - return sd_r1b; - - default: - break; - } - break; - case 8: /* CMD8: SEND_IF_COND */ if (sd->spec_version < SD_PHY_SPECv2_00_VERS) { break; @@ -2295,6 +2303,7 @@ static const SDProto sd_proto_sd = { [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, + [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:26 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: 13719268 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 67E7DC30658 for ; Tue, 2 Jul 2024 09:25:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZlF-0005KB-83; Tue, 02 Jul 2024 05:25:17 -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 1sOZlA-0004qF-Km for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:12 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZl8-0000FQ-HB for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:12 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2ec5fad1984so55054121fa.0 for ; Tue, 02 Jul 2024 02:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912308; x=1720517108; 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=1S0cqs0T2pBpC9otbYCEZV3ST8t5p98azNZmcVeDSZg=; b=t3VxfJKJuGfF6HrYCXhMPtl4lB/9Vlm1gly4aRkRkhFhC4hk2DMIjssp72Kah0UboJ t1lwE2vbl6kDQXH+HuUS0wy5I0qxQ+4C5dmR09KudJYqmQ9ThYQ5cXVVk9NYhoodWqn1 nhyXpWm26dVuJYQOOUT5hoIQf6WFtBClZuTGgoI3+t8spDpyuB4/37SlHOTFjAiQVLnX hGtsiJnbrzpxvGikdKXWqzEndar6DkIfKpVrj6kkLKGtY9eh8MrWUMPCaJDsZ26RP4gy 9ewaHyy4vd+C57zmEWd5pzEZpQuffh13g7lxLQhzxpm0c2PqWO81gA59vsD5O2IKHdEW 6Ulg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912308; x=1720517108; 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=1S0cqs0T2pBpC9otbYCEZV3ST8t5p98azNZmcVeDSZg=; b=YgPi2Bax+q0/vr42zR0qb2BwMYbGAS9CLcURvcbrmSrSU2lzP9qXdJrcJpqbD4LpL8 tUVD7fMk8lyXlSSnd2FumLtcvdxPSi/zAoUuFAGsNIs99qY9meALo4GA84gVk6v4maq3 +x/twS27xuIPX849VPuA+A/7oZZpR6gFc4zdvizDumE51xReXx+KLNDOIEoo5IUxCsll 5dgfu7aG8Ebq2IV9KVrAA0OKsTLeQLT1LjtR0n2MlV4i6eIphb94KTiFCRoCvRi9Z53C /VUPsqbZNgUb3P35AkO0typHWQmb3q04zSlasZXHSPj1BhdjZtZXq6uMRuvDyC/Nw6Ma SU+Q== X-Gm-Message-State: AOJu0YySOhJ9iiz1iGnmyocalyDoQwXQ+aW5qU3RkIIKtMVwhOjqM4WQ ik7kMaYOsP9V11kjY9DLTVKLjySw5oUpaBJZdbGrxrYkrZ572Xsv86bnklPX9DH53XyweDAzIJf 7 X-Google-Smtp-Source: AGHT+IHGVbWUxYYq/VOG0QijueQz8Q7hW3kgfoijxPPeYt6h2INV1RB6X5flXN8wDmYQKPSlvMD/MA== X-Received: by 2002:a05:651c:a0b:b0:2ec:3e02:9737 with SMTP id 38308e7fff4ca-2ee5e3809d7mr73730801fa.2.1719912308381; Tue, 02 Jul 2024 02:25:08 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b09a94csm189496255e9.33.2024.07.02.02.25.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:07 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 43/67] hw/sd/sdcard: Add sd_cmd_SEND_IF_COND handler (CMD8) Date: Tue, 2 Jul 2024 11:20:26 +0200 Message-ID: <20240702092051.45754-44-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=philmd@linaro.org; helo=mail-lj1-x232.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-50-philmd@linaro.org> --- hw/sd/sd.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index f83ae4ed18..1bde4c9f7f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,7 @@ 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] = { - [8] = "SEND_IF_COND", [9] = "SEND_CSD", + [9] = "SEND_CSD", [10] = "SEND_CID", [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", @@ -1295,6 +1295,27 @@ static sd_rsp_type_t sd_cmd_DE_SELECT_CARD(SDState *sd, SDRequest req) return sd_invalid_state_for_cmd(sd, req); } +/* CMD8 */ +static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req) +{ + if (sd->spec_version < SD_PHY_SPECv2_00_VERS) { + return sd_cmd_illegal(sd, req); + } + if (sd->state != sd_idle_state) { + return sd_invalid_state_for_cmd(sd, req); + } + sd->vhs = 0; + + /* No response if not exactly one VHS bit is set. */ + if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) { + return sd_is_spi(sd) ? sd_r7 : sd_r0; + } + + /* Accept. */ + sd->vhs = req.arg; + return sd_r7; +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1361,24 +1382,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 8: /* CMD8: SEND_IF_COND */ - if (sd->spec_version < SD_PHY_SPECv2_00_VERS) { - break; - } - if (sd->state != sd_idle_state) { - break; - } - sd->vhs = 0; - - /* No response if not exactly one VHS bit is set. */ - if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) { - return sd_is_spi(sd) ? sd_r7 : sd_r0; - } - - /* Accept. */ - sd->vhs = req.arg; - return sd_r7; - case 9: /* CMD9: SEND_CSD */ rca = sd_req_get_rca(sd, req); switch (sd->state) { @@ -2280,6 +2283,7 @@ static const SDProto sd_proto_spi = { [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, + [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [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}, @@ -2304,6 +2308,7 @@ static const SDProto sd_proto_sd = { [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, + [8] = {0, sd_bcr, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:27 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: 13719277 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 29386C30658 for ; Tue, 2 Jul 2024 09:26:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZlJ-0005tj-MX; Tue, 02 Jul 2024 05:25:21 -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 1sOZlF-0005by-Sl for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:17 -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 1sOZlD-0000Hw-Rf for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:17 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-36786081ac8so217682f8f.0 for ; Tue, 02 Jul 2024 02:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912314; x=1720517114; 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=6+3xD1MV1Oqr8vKeJ5znDbygAt0rxvWxpBRrwLtzXO8=; b=H+6Tt3s4xAdHftTiPowqHvL7FnsI8x4whdmO2HUzPl736tqYS5+uqkN0CJbOsMYYlc kJBJfBZhSzTMMgXitm9k+/rX7m1nsHa2zBmHJdUDkJbFHf/QsuCIMV6PfgVZY2Vp+yEE Yos9Qc4f/IpRI2YmCIZow/GSZPDaOpoFgLSKTvP+PVS1trDyum/XbwLIcNaHBHolJNRI IblIzjcrhrL1dWikdwycvd7/+TfA/0Mhg/xXgG2fg2CkWhFE1lw0TvSasNRgwTOhe6cx geoEkJTcCtZiVKwgv7t6db/gKJca4yd9bANGu904oxyKDd6qp6QL08mR57ZLpRrHOsoU /LPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912314; x=1720517114; 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=6+3xD1MV1Oqr8vKeJ5znDbygAt0rxvWxpBRrwLtzXO8=; b=lUuJvSYUUXf5YHnnmK6G4ZyrtPNESh3mEHePrB0UMFA8DjIDB5wQEVJXzxDJaIWNMl 2Tc1LTLuvxHY+iF4C8GV4KHND3gNaICPm1ktfiBndaCLBVqjDtDJw0dePbYlIxKP79Vv PKb7zZSKbEfRuqsNr/6mbGcvAp2Mw3gO8ETsX8GjeHN9T2cRRAkVFfaigOQVF1+y+Uv1 P0BtkdalUppbKaE/LN9zQMwpoCFNRj+9D9PPdIlz1E6m8nB0etvn8AOh+kP4KR0tKJtl Zsz3RSWacPHAbRosQxk3LPvxOmFY51aHl3BnZHoyZ7M3EkjsvRBskrg/6E/veUANQCJ6 YhiQ== X-Gm-Message-State: AOJu0YyhLoqFQOfxQ04ROfTZELTYaSFH1+zWeDnzDDu4AKiSr8p0muVo SM4WckcksV3NDXUSvgh6AQDTovvUx8V0x/YSsj81OChtI8JQL10ndbear0I0nwrKs3xvjOGo7/m 9 X-Google-Smtp-Source: AGHT+IHyg+gQTo7k4Gzso6YixN8mZa7IdJEtZ+TWiil2fggGkPGBr9i3qolDSalVcpOHKSEbZXoyFw== X-Received: by 2002:a5d:5f4e:0:b0:35f:10ac:ea50 with SMTP id ffacd0b85a97d-367756cf30amr6092659f8f.37.1719912314122; Tue, 02 Jul 2024 02:25:14 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0d9148sm12607592f8f.34.2024.07.02.02.25.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:13 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 44/67] hw/sd/sdcard: Add sd_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) Date: Tue, 2 Jul 2024 11:20:27 +0200 Message-ID: <20240702092051.45754-45-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-51-philmd@linaro.org> --- hw/sd/sd.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 1bde4c9f7f..e372f88073 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,8 +237,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] = { - [9] = "SEND_CSD", - [10] = "SEND_CID", [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", @@ -1316,6 +1314,26 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req) return sd_r7; } +/* CMD9 */ +static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) +{ + if (sd->state != sd_standby_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + return sd_req_rca_same(sd, req) ? sd_r2_s : sd_r0; +} + +/* CMD10 */ +static sd_rsp_type_t sd_cmd_SEND_CID(SDState *sd, SDRequest req) +{ + if (sd->state != sd_standby_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + return sd_req_rca_same(sd, req) ? sd_r2_i : sd_r0; +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1385,12 +1403,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 9: /* CMD9: SEND_CSD */ rca = sd_req_get_rca(sd, req); switch (sd->state) { - case sd_standby_state: - if (sd->rca != rca) - return sd_r0; - - return sd_r2_s; - case sd_transfer_state: if (!sd_is_spi(sd)) { break; @@ -1406,12 +1418,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 10: /* CMD10: SEND_CID */ rca = sd_req_get_rca(sd, req); switch (sd->state) { - case sd_standby_state: - if (sd->rca != rca) - return sd_r0; - - return sd_r2_i; - case sd_transfer_state: if (!sd_is_spi(sd)) { break; @@ -2309,6 +2315,8 @@ static const SDProto sd_proto_sd = { [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [8] = {0, sd_bcr, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, + [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, + [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:28 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: 13719301 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 7E44EC3064D for ; Tue, 2 Jul 2024 09:29:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZlW-0007Gs-2o; Tue, 02 Jul 2024 05:25:34 -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 1sOZlU-0007Ew-6K for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:32 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZlJ-0000IQ-LR for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:31 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-425680b1d3aso27252855e9.2 for ; Tue, 02 Jul 2024 02:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912320; x=1720517120; 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=vw2vdkreXbtxIWqVAzubzR0s305Wl62ih68f1l2Fwrw=; b=UhUpUBymf3npmi5uiv2Y6fq8DsLuUDKOxW98FihlxPZ88jJToGXkJt1tRYbgsZVmTM T6XFGe76qRXULUMtRFfwIR2XPJYsqo68n6Q8VO1OmG28RX/cK4oASCcOVc/qP5q2qjyG UUO9vEgReTqwRwmL45X7uyCv+QRth8BlyPeuoMWBkJKpaNdD3hKINBw64cr6jHWFWv2G hU8yJyt78O8WtfA+5oOhQYwkxH+8xmH+I4PEk9kMVHYvdHkmDPdgKwlu20gGI5v9OnSy WLgwxd6kAoIw5UFziK5Fxhexe52N70Na5SAr4dZ/Xbya+FFaBEd74bINwMzvsbvuZIaT jfhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912320; x=1720517120; 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=vw2vdkreXbtxIWqVAzubzR0s305Wl62ih68f1l2Fwrw=; b=ILJtwksB+jAuQRoEVg3KMf3nUHHlNbFz56P0n1jSyTdx025g1XMl+De6lAV+wp4YgK GnFGW11R1VbT38ZkuAnaAj0c/KEtrxKlM6KVt4LEQjxQMqT8Pz3pXRQaF0GFyxYSTUYC Ct+I4+3nd4LNLIDi6wKKq47rnO5vwbv8Fme9U95WkYWR9ydI2xi/PXVU79v5l0kUOlsR qwULyqn064QY7ClLWJWiscvqV/kOacPaAfmKdCEL9JJDU9oNSmWFXiuPOyDvcJsPUXbc GJ8y9NEsXnFOlCnWmK/GHwnaBsEhXh690xCpnpPTFQrQJ1e6icNy+4hLMcZOxhQ33Mla qXkg== X-Gm-Message-State: AOJu0Yx1OJLldSTarm8iBKp58CHz9zF8/Wu3qIcfih1LhsdCPazPc3+i FpnROdAHE28juesOaCPbSaXIM6l9OcqxLYJse0eMCeX5t798VKW9JHuH0fy4OLrd1zTIZ/up8/J Y X-Google-Smtp-Source: AGHT+IEQJ0Jq3sd0Fl5Eufcard/r+Zfq7i4YFs/AvM3itlmSlKnjEZ6Ge6RN3+JABjIV6RbsNjZEhQ== X-Received: by 2002:a05:600c:2252:b0:424:a823:51d9 with SMTP id 5b1f17b1804b1-4257a06e036mr52088665e9.30.1719912320009; Tue, 02 Jul 2024 02:25:20 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a043a16sm12808371f8f.0.2024.07.02.02.25.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:19 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 45/67] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) Date: Tue, 2 Jul 2024 11:20:28 +0200 Message-ID: <20240702092051.45754-46-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-52-philmd@linaro.org> --- hw/sd/sd.c | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e372f88073..49fc79cf8a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1315,6 +1315,15 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req) } /* CMD9 */ +static sd_rsp_type_t spi_cmd_SEND_CSD(SDState *sd, SDRequest req) +{ + if (sd->state != sd_standby_state) { + return sd_invalid_state_for_cmd(sd, req); + } + return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), + sd->csd, 16); +} + static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) { if (sd->state != sd_standby_state) { @@ -1325,6 +1334,15 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) } /* CMD10 */ +static sd_rsp_type_t spi_cmd_SEND_CID(SDState *sd, SDRequest req) +{ + if (sd->state != sd_standby_state) { + return sd_invalid_state_for_cmd(sd, req); + } + return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), + sd->cid, 16); +} + static sd_rsp_type_t sd_cmd_SEND_CID(SDState *sd, SDRequest req) { if (sd->state != sd_standby_state) { @@ -1400,36 +1418,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 9: /* CMD9: SEND_CSD */ - rca = sd_req_get_rca(sd, req); - switch (sd->state) { - case sd_transfer_state: - if (!sd_is_spi(sd)) { - break; - } - return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), - sd->csd, 16); - - default: - break; - } - break; - - case 10: /* CMD10: SEND_CID */ - rca = sd_req_get_rca(sd, req); - switch (sd->state) { - case sd_transfer_state: - if (!sd_is_spi(sd)) { - break; - } - return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), - sd->cid, 16); - - default: - break; - } - break; - case 12: /* CMD12: STOP_TRANSMISSION */ switch (sd->state) { case sd_sendingdata_state: @@ -2290,6 +2278,8 @@ static const SDProto sd_proto_spi = { [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, + [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, + [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [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}, From patchwork Tue Jul 2 09:20: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: 13719290 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 CC1C5C3064D for ; Tue, 2 Jul 2024 09:28:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZlY-0007Iz-2j; Tue, 02 Jul 2024 05:25:36 -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 1sOZlV-0007Gp-P0 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:33 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZlR-0000Kh-Ip for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:33 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42562a984d3so27643685e9.3 for ; Tue, 02 Jul 2024 02:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912326; x=1720517126; 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=01K5Fpbyc/Wo8G4gat2aNkWhP6GApv43W9gex3KjoA4=; b=l/7ZckfmQuOxDaDpadrInrH27qXXzF7C0GsJ/Kw7hCtQ6JigmKQkxIOKE00kP8N7rU z+oNwLaqaMSAuNsYgWMRb7ysphIKUgybhrAZZD3gpO6vVtAy6JMiWJNt1U4B0nzbR2nu kU2L55MvVgbrODAnyXOqLYPrBdAr7TCI2FMJNeZdoOgx5aJdmEGDLSecvhiUlqypS2vD vpzlEJS0UrpApAwks8dcDmL89x8N+kDnz8338AaC+w3z5X8XTPxufF0fa69mlv+zOclM hUUqRitfcy8rbYfrpSwhB0JLR+WyKDuSDvVUrsNH2YfAt8iH17vHRtZb5kx/W07bBvCY GYVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912326; x=1720517126; 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=01K5Fpbyc/Wo8G4gat2aNkWhP6GApv43W9gex3KjoA4=; b=gwIWL4xvcwyP0vTp/u4nbLrigfi3TXJ7JKytX+8Sg5Xfo3AnM5hyy+ovcQ7op4/XHx gnv/ERYmwpQGH4/Ynz1LNJJY9/tP9kWGw/hetmaUzPLPA2SoWJzU9PnZgIYLDJYHm8zI iE3k9Szvdjv6wvEnkq9XFss765NCzWMzjc47ZKzGrfgFaxyXwX8ciEuuzmg7pRxbbVfO e3eJo1vXfblxGFnZNSnJBOZgT1/zfs+Qgq6hyoGxj9bFowy5u/S6MFPpd+v2usCk+NH6 lOgVLZzcEy3vRtoAE1OIE6HXRcJ2L60/cstBh5MUM2/RLuQmaiyBA2dljGczNfm4O2D+ wSBA== X-Gm-Message-State: AOJu0YzrCg3JAHHX8op5uqgfGpn6WtuwPahYcPsYQIpIYdmWmiNAWEBP k6y5M5tmCukNqEx15rGRowcNveZTrvy08Fmqv5otRFZOA1oBaqMnFh9/e8Nem3vBkgA0nX0aphX g X-Google-Smtp-Source: AGHT+IEfBQVB963G217cvWZyECBbUl5n1F1H6/fqFpesdeJB7HoL5+PyYhU+vsBNr4jMYgnpsmY3uA== X-Received: by 2002:a05:6000:2c5:b0:365:32e0:f757 with SMTP id ffacd0b85a97d-367757214bdmr4490900f8f.50.1719912325832; Tue, 02 Jul 2024 02:25:25 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675f9dfbdbsm12298117f8f.103.2024.07.02.02.25.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 46/67] hw/sd/sdcard: Add sd_cmd_STOP_TRANSMISSION handler (CMD12) Date: Tue, 2 Jul 2024 11:20:29 +0200 Message-ID: <20240702092051.45754-47-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philmd@linaro.org; helo=mail-wm1-x32b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-53-philmd@linaro.org> --- hw/sd/sd.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 49fc79cf8a..0a554d30a2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,7 @@ 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] = { - [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", + [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", @@ -1352,6 +1352,23 @@ static sd_rsp_type_t sd_cmd_SEND_CID(SDState *sd, SDRequest req) return sd_req_rca_same(sd, req) ? sd_r2_i : sd_r0; } +/* CMD12 */ +static sd_rsp_type_t sd_cmd_STOP_TRANSMISSION(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_sendingdata_state: + sd->state = sd_transfer_state; + return sd_r1b; + case sd_receivingdata_state: + sd->state = sd_programming_state; + /* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; + return sd_r1; + default: + return sd_invalid_state_for_cmd(sd, req); + } +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1418,23 +1435,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 12: /* CMD12: STOP_TRANSMISSION */ - switch (sd->state) { - case sd_sendingdata_state: - sd->state = sd_transfer_state; - return sd_r1b; - - case sd_receivingdata_state: - sd->state = sd_programming_state; - /* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; - return sd_r1b; - - default: - break; - } - break; - case 13: /* CMD13: SEND_STATUS */ rca = sd_req_get_rca(sd, req); if (sd->mode != sd_data_transfer_mode) { @@ -2280,6 +2280,7 @@ static const SDProto sd_proto_spi = { [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [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}, [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 +2309,7 @@ static const SDProto sd_proto_sd = { [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [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}, [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}, From patchwork Tue Jul 2 09:20:30 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: 13719304 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 8BFC1C41513 for ; Tue, 2 Jul 2024 09:30:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZld-0007cq-CY; Tue, 02 Jul 2024 05:25:41 -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 1sOZlb-0007X5-MZ for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:39 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZlV-0000SU-HR for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:39 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-365663f51adso2403940f8f.1 for ; Tue, 02 Jul 2024 02:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912331; x=1720517131; 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=W8u75s6/EWdwDgm8HUCe5acoVohaEm/dxjOCFeqWaIc=; b=Ti3q5STmBqozmz6qOelHkKVFAewkGkscXME5i42wQSmmEuwUxx0j2J5HCKLpUrRFmX zur3JGI0sgnoFj5HxMAgBOl8H6Vp7rosDpnAOWC/Ucm71AW2XLWVhv/D4mXNpB+vsj+s Zon8RLJtIiB5qpbhi7HlutZlcUsWyR+tP0VV6g+FVKmXOn5LUqZW+IV81HBAqSPeMN0c i16D66TKSrHBq920v8ceKrLtpDz7MMD6jguV/gf+S6dPyoCfH2va4GH+nD84XrA54W+m SYnPlI51qmEJlFlVdkF+PymO0WVksjth4y8uNQxia5ZLb6+Sis27R1vi9ulyVZCL6t/g 5G+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912331; x=1720517131; 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=W8u75s6/EWdwDgm8HUCe5acoVohaEm/dxjOCFeqWaIc=; b=asVIcVwod8UfypO/Bu3ayrru89oL0P/2+9sZ93N2KSCb7EGn68Zy1CSB7KWjwQnGZh lvBncI1vN4r3kkMN8k9LAGjkvx+jI9Kmepymtc2MANIZHx52CeV6EXHimQyDB1jpOyhm trvNGQXbV5asbeOXaVv1oJPkr8KaNPUwoEdj24YhxanrF75FR9WhhrQ7uxWFG9qoypF7 RTk2zb7OuEt1TlEimEXII/9ZPayfc8ywDUIgKpYRyxw3zjXXQfmv3USgy5j18me7+lL8 3hx6OtmQogoYTqLlrJVViCgyOdC/O710KA2aCkGQxt/aVLexC8i2uq2t75Af51O2ItsJ RT4Q== X-Gm-Message-State: AOJu0YzYVE8+1YUS063IQO/JftR8cdydk75YMNFAAcYwwzLIIA83rA3V TLkBbRWgm/xQAguhw2lMzzgPkuuvo0zj54tplwjbO+D5lw1D9P2KvNsbniFRlVZr971rs3MY7IX 0 X-Google-Smtp-Source: AGHT+IEMpVIJNhkOERdqcahe+12W9P219x8HUxqmknrIYJyPgHp5xUqUO1GEVGqsL+wJqShpydTP1w== X-Received: by 2002:a5d:61cf:0:b0:367:31e0:950c with SMTP id ffacd0b85a97d-367756bb627mr4769624f8f.37.1719912331568; Tue, 02 Jul 2024 02:25:31 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0cd60dsm12680069f8f.2.2024.07.02.02.25.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:31 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 47/67] hw/sd/sdcard: Add sd_cmd_SEND_STATUS handler (CMD13) Date: Tue, 2 Jul 2024 11:20:30 +0200 Message-ID: <20240702092051.45754-48-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=philmd@linaro.org; helo=mail-wr1-x429.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-54-philmd@linaro.org> --- 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 0a554d30a2..426144c659 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,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", @@ -1369,6 +1368,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) { @@ -1435,17 +1460,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); @@ -2281,6 +2295,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}, @@ -2310,6 +2325,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}, From patchwork Tue Jul 2 09:20:31 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: 13719285 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 1A2C6C3064D for ; Tue, 2 Jul 2024 09:27:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZly-0008Mi-Db; Tue, 02 Jul 2024 05:26: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 1sOZln-0008Dr-Km for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:52 -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 1sOZla-0000md-WC for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:51 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-425624255f3so23638235e9.0 for ; Tue, 02 Jul 2024 02:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912337; x=1720517137; 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=NsTleHfMR+jNkMLGT2+7/tT9zaWyW/qieWJj1402poE=; b=ai7gSsbeUAUQy6vTqJLuFmpcdNT4cfbH9xG19nt958Fu1zPGtHSYZoNWG3z10bI7pt 2VsgJCTHvjDOePfi2tRKj+whjmNqLz5reAq6CzOwaRL7pVsdgbNyAYiPXKa7j9NF9NUA KxBWwBZbSvfqSoLUwSPmoFTAG5QQ5z7q3n1dyWdc+66zzQLAQEkbss0MrNDsNojCI84i LiS7NgSF9sGVLX4XlOtxbX0Z8m7mxJ1jpPXodbU/8eJU97cQ38gJEYRM/Nck2JBYGoSo ilDVuQ2+75Qzdppx3pkJrS1+bNmTFTx+o5Vtl6B4jChQLCBJGzVZ1WafDQIZUVhQzp3K R3GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912337; x=1720517137; 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=NsTleHfMR+jNkMLGT2+7/tT9zaWyW/qieWJj1402poE=; b=A880bi18W3PlSNyYmPHQZSQd5y4YkFk9trh00pU9BxXHRf/gvD6wVYKQi31xf9+XX/ PcNQabNJswV4ZmQ41jBdPt6NW1PTc8QRb7c+D1TwWB+t4cVOkFD2HlJg7kiH2LgRMir2 E/tu+8sPtpEV6QUSrk0ex1r8aD1OMjxSNzuHOypJJdb8sWcddfaYR7DrS116vCsFzWCb +ePyUiIalmm+VMLnRwz+s/melU8peBeF7/xOXgObTlZqY11tI+Rmy8bAmSL98W7aqP0y ESzgXQjC0uvrx+27NC+vH2sdI4ryJIFvFoR3IVBWxkkECMyd/oByO1kchFUEuDzo+N5f Mjaw== X-Gm-Message-State: AOJu0Yx1usO15toaHnH/duZuvWabBVR3oIEW+3YSWjZS3cltpHsWVJsV slXn3zj3Gz5pED9aTvd6OWb386J0lmJZYM4YoXjmqwCe9dhJbIvgB/Ly8ovtebEo9uBEl2RO6QV M X-Google-Smtp-Source: AGHT+IFzjoPEp8O6Na1biHYX9+V4IgZCs6fFuB2Q6sZY6c4L5D1bjqvU3vxhdPq+3y3IvC4zBw7Zmw== X-Received: by 2002:a05:600c:4749:b0:425:8cc0:58b6 with SMTP id 5b1f17b1804b1-4258cc058e4mr4313835e9.14.1719912337363; Tue, 02 Jul 2024 02:25:37 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42577a0c286sm97143495e9.0.2024.07.02.02.25.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:36 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 48/67] hw/sd/sdcard: Add sd_cmd_GO_INACTIVE_STATE handler (CMD15) Date: Tue, 2 Jul 2024 11:20:31 +0200 Message-ID: <20240702092051.45754-49-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-55-philmd@linaro.org> --- hw/sd/sd.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 426144c659..56b4b274a1 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,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] = { - [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", @@ -1394,6 +1393,30 @@ static sd_rsp_type_t sd_cmd_SEND_STATUS(SDState *sd, SDRequest req) return sd_req_rca_same(sd, req) ? sd_r1 : sd_r0; } +/* CMD15 */ +static sd_rsp_type_t sd_cmd_GO_INACTIVE_STATE(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_req_rca_same(sd, req)) { + sd->state = sd_inactive_state; + } + + return sd_r0; +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1459,17 +1482,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } switch (req.cmd) { - /* Basic commands (Class 0 and Class 1) */ - case 15: /* CMD15: GO_INACTIVE_STATE */ - if (sd->mode != sd_data_transfer_mode) { - return sd_invalid_mode_for_cmd(sd, req); - } - rca = sd_req_get_rca(sd, req); - if (sd->rca == rca) { - sd->state = sd_inactive_state; - } - return sd_r0; - /* Block read commands (Class 2) */ case 16: /* CMD16: SET_BLOCKLEN */ switch (sd->state) { @@ -2326,6 +2338,7 @@ static const SDProto sd_proto_sd = { [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}, + [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, [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}, From patchwork Tue Jul 2 09:20:32 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: 13719297 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 80206C3064D for ; Tue, 2 Jul 2024 09:29:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZln-0008B5-SW; Tue, 02 Jul 2024 05:25:52 -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 1sOZlk-000837-Q2 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:48 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZli-0000vf-8g for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:48 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42565cdf99cso34784425e9.3 for ; Tue, 02 Jul 2024 02:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912343; x=1720517143; 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=LdTwu99eUQlsPY0aCQAbuEuylC9rmmKUSrJ2XBIqUJE=; b=t3dDEXFbeK4zBd3rEW3oXFsuB+PncLDZE3bDxYU+uM537pwOm+aDDnji9c3+vYDqfp D+rOJ4+bxUFruEILwGMjh8uCOAgIky7auDzY4hJpiaziq+kOkdWya8vwDO0qWAPkWluk ojJb7x/iwM1spUw2foA41G5Rx0AbGtNK9+WDl2nsSqMXCOJPQ62sD2ThBzmGUKwVlKu0 gZ6OrNqvgEtJvjHOOZAR7nLH6/wWRRa/BCl/PEMidk77Q8zX68e+G4s48tk5rt5LmQQG IKtXflKmxBHvwY0k/m5qV3eVI5UM1xzUPjTxmQ0rPW33R+Z0cQPTL/aA8VNRUuxENZWO mOFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912343; x=1720517143; 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=LdTwu99eUQlsPY0aCQAbuEuylC9rmmKUSrJ2XBIqUJE=; b=bEwcnYRgRklcO9d3vWsAH4SNMrjLoHZCz3I68chiRGn9hPvQimBqV0EF0r2RabUSnZ L/kesI6icolYUuHL5zuLe6E3BqZlD/somQZ7s6zbjdsN+yZCciMjljFgH6DHzTLaASZm uX4PAb4ZfzRprOWdpwGMYx7adrKmy7gnM1pV0cs6usIAahXcnQ9/D4OK4xe/NCpa6Su1 7wrvnmpXfbiL8F/+CFLZSCuvFBXSxlZww0JOeIJgB3lgzGHW3SQYTyL+qj1ujG5wvS3v HrKcaZq0jHruwqQwpaLO21YzwRShR4tDvBZHrMgTKNGECL+PfRCFygxjZjR688dj4ZoK 2r5A== X-Gm-Message-State: AOJu0YxOvffZnkyu9wLMDy84RyNXsYtvZlzHkMTUH6c0BLmTybahYWgP GZjywqZGNtCJVf3O0Mh5uc9fYS+VX2mqTC1Hy5zYCB19N5fbg9HV3mjivZRK7LoaWZCwooXOwG+ 8 X-Google-Smtp-Source: AGHT+IGEU+Nud7Xs+MIvPItnWhG1QYh/epmVB2HW46/JzE4C3B3EDrUcNP/MuvhJZvoU0Le5cHlbZA== X-Received: by 2002:a05:600c:19cb:b0:424:aa40:88ae with SMTP id 5b1f17b1804b1-42579ffcae6mr69016165e9.3.1719912343210; Tue, 02 Jul 2024 02:25:43 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257fb4fabdsm96398635e9.46.2024.07.02.02.25.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:42 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 49/67] hw/sd/sdcard: Add sd_cmd_SET_BLOCKLEN handler (CMD16) Date: Tue, 2 Jul 2024 11:20:32 +0200 Message-ID: <20240702092051.45754-50-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=philmd@linaro.org; helo=mail-wm1-x335.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-56-philmd@linaro.org> --- hw/sd/sd.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 56b4b274a1..335b3e03db 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,7 @@ 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] = { - [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", + [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", @@ -1417,6 +1417,22 @@ static sd_rsp_type_t sd_cmd_GO_INACTIVE_STATE(SDState *sd, SDRequest req) return sd_r0; } +/* CMD16 */ +static sd_rsp_type_t sd_cmd_SET_BLOCKLEN(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + if (req.arg > (1 << HWBLOCK_SHIFT)) { + sd->card_status |= BLOCK_LEN_ERROR; + } else { + trace_sdcard_set_blocklen(req.arg); + sd->blk_len = req.arg; + } + + return sd_r1; +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1483,23 +1499,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Block read commands (Class 2) */ - case 16: /* CMD16: SET_BLOCKLEN */ - switch (sd->state) { - case sd_transfer_state: - if (req.arg > (1 << HWBLOCK_SHIFT)) { - sd->card_status |= BLOCK_LEN_ERROR; - } else { - trace_sdcard_set_blocklen(req.arg); - sd->blk_len = req.arg; - } - - return sd_r1; - - default: - break; - } - break; - case 17: /* CMD17: READ_SINGLE_BLOCK */ addr = sd_req_get_address(sd, req); switch (sd->state) { @@ -2308,6 +2307,7 @@ static const SDProto sd_proto_spi = { [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}, + [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [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}, @@ -2339,6 +2339,7 @@ static const SDProto sd_proto_sd = { [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, + [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [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}, From patchwork Tue Jul 2 09:20:33 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: 13719300 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 B5206C3064D for ; Tue, 2 Jul 2024 09:29:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZm4-00006O-2k; Tue, 02 Jul 2024 05:26:08 -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 1sOZlp-0008GZ-2Q for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:53 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZln-0000w9-3v for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:25:52 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2ed5ac077f5so47037461fa.1 for ; Tue, 02 Jul 2024 02:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912349; x=1720517149; 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=+5p+b2GGIVB5B1uUI5bQzO6xootFfyz2SaKoSXjhZWM=; b=M7vsy5SH6Ljk8CryGjxsjsX7PLGWUBS9IF8sQZBf401amNd3Dtt+Y9lOhuB72xrvoq usCO5Qr2Tw92IcKvTs3lIk9V2Me3tSwhlAbv2fLjSgAIBouv/oafgn8l+JqZ84IxX6FZ 0wSEF4SYBso/1fhltduNMsVdgDNs8IzpMU0PyBGVuFBv++DJ++CCweZIaO7h8Ox03Sgt YyGrLcZaemmwbKzd7nXlLoLVmvdcP7+4WVg0+rw4VHtn7D+UJ05m8klGJ66us4ipienl 4298nTEap0tMqxfvhvHh65gY1mujyjT95T8HDkZ7aP+L52HnynmI1Ced8wNyVjJUz5x7 Dz1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912349; x=1720517149; 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=+5p+b2GGIVB5B1uUI5bQzO6xootFfyz2SaKoSXjhZWM=; b=ekIMdzKorFQZTEDz189ReRqVOEM3XB4DqwfXhlaFzgKDiy91IBSvbtrmaobtkzbFJG xIToROYpiF4W/sx5J3OJYTDkLve0IaSYvQXaGPMhfy6sq366LsTlFdvQbGCEjha3UML4 cxkTD5T5L9tsg65MxdGb4Z9H1Vbx9PMAvmotGyTWooDwtC/O3+XG3f9pYoNqNnN9VO1o EdFzAchGwsCKXvioq0Xnfy9M7zuWrQfym+oybrcTdu8FpAL3QxU9c65trmE+bmoLDv+f V5VLgroKHpHcBlSJgjMi6pwgDJF+C4ELGJFNprPnX3xpC21z/m5cOFFWZnDt6trPab4r nkew== X-Gm-Message-State: AOJu0YyXtHFjKgNeVRwzYLapFq6LcwGpMfb/rsrLaLrnnkd2NO2zmElu 2hDsup6qRU98hcnw8Rli5QVgjUnvQK9jeRtp3GrzsmEdhwr2xhvzp8TcjqK0X0xHPFKGJ15QR41 D X-Google-Smtp-Source: AGHT+IH3QmGxiGUz3HgOO+z8oPYesObID/Qo33axEbUDp4AJPKvyjD1mbBnpjV+nTXFzCTS0za+jRA== X-Received: by 2002:a2e:9dcf:0:b0:2ec:520d:f1dd with SMTP id 38308e7fff4ca-2ee5e3594damr49077951fa.3.1719912349094; Tue, 02 Jul 2024 02:25:49 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b097fd4sm188808705e9.29.2024.07.02.02.25.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 50/67] hw/sd/sdcard: Add sd_cmd_READ_SINGLE_BLOCK handler (CMD17) Date: Tue, 2 Jul 2024 11:20:33 +0200 Message-ID: <20240702092051.45754-51-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=philmd@linaro.org; helo=mail-lj1-x232.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-57-philmd@linaro.org> --- hw/sd/sd.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 335b3e03db..3f5cc0c55c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -237,7 +237,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] = { - [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", @@ -1433,6 +1432,24 @@ static sd_rsp_type_t sd_cmd_SET_BLOCKLEN(SDState *sd, SDRequest req) return sd_r1; } +/* CMD17 */ +static sd_rsp_type_t sd_cmd_READ_SINGLE_BLOCK(SDState *sd, SDRequest req) +{ + uint64_t addr; + + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + addr = sd_req_get_address(sd, req); + if (!address_in_range(sd, "READ_SINGLE_BLOCK", addr, sd->blk_len)) { + return sd_r1; + } + + sd_blk_read(sd, addr, sd->blk_len); + return sd_cmd_to_sendingdata(sd, req, addr, NULL, sd->blk_len); +} + /* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req) { @@ -1499,22 +1516,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (req.cmd) { /* Block read commands (Class 2) */ - case 17: /* CMD17: READ_SINGLE_BLOCK */ - addr = sd_req_get_address(sd, req); - switch (sd->state) { - case sd_transfer_state: - - if (!address_in_range(sd, "READ_SINGLE_BLOCK", addr, sd->blk_len)) { - return sd_r1; - } - sd_blk_read(sd, addr, sd->blk_len); - return sd_cmd_to_sendingdata(sd, req, addr, NULL, sd->blk_len); - - default: - break; - } - break; - case 18: /* CMD18: READ_MULTIPLE_BLOCK */ addr = sd_req_get_address(sd, req); switch (sd->state) { @@ -2308,6 +2309,7 @@ static const SDProto sd_proto_spi = { [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, + [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [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}, @@ -2340,6 +2342,7 @@ static const SDProto sd_proto_sd = { [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, + [17] = {2, sd_adtc, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [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}, From patchwork Tue Jul 2 09:20:34 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: 13719310 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 502ABC30658 for ; Tue, 2 Jul 2024 09:31:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZm6-0000QX-LA; Tue, 02 Jul 2024 05:26:10 -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 1sOZly-0008Pq-Sl for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:02 -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 1sOZls-00012E-T8 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:02 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4257a390a4eso19067455e9.0 for ; Tue, 02 Jul 2024 02:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912355; x=1720517155; 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=MYL5paPpv6jEUEf+c2iXnwTu+YdBcD9M6q75+huuwI4=; b=MIRVXuV2oDuI7C7/1sEZ4LpEVjW+vzM0VWG7hLKSNPru1P9sFvxorYvODxDOJ3YcHv lXdWek3OsqNNmwk57dBrVCc/R1EO6nb/56F0JVWGe9FIVQ9qaTSTnMfOu9Gmkupa0WCk thM04EwjWkZfB56GmuuSBs3qGiGIKR8K1T4GhXk0WDLpcfqi+tYv0Vg+uVZcbZkkAgbb /oVlS02gVtx6TPhccGyxkBmuRUSet8sbggfI8VB2P3NsbKWwqHLd3WyOQLfgUXCmHg/Z +Eep+If+S+fMkqar8O8sabtN37NbxsJcA5Rniv1N58rV22v37Si4mryjgZugbTFckrsu zAIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912355; x=1720517155; 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=MYL5paPpv6jEUEf+c2iXnwTu+YdBcD9M6q75+huuwI4=; b=wuJAB4BsPwNujAAmZfbzoR8u/1rJpl014V+UBwHhRC9eWr0Qaqkj6vEPCjsc53865L nSU/zHQ5N1aXqO+JY2rUa3ztntLFyQbwwLI7xC6D3Wo/w7pWtGU5dDnSDhSj2xRPL2SW 5PuShWEeuLnpdhgFX7CB1M3DWLnLHc4wkgo+PvOpi/4ViqRJq3Bfu9O86ZL82bO+EciK TdwTM3jVYOhbMBaBakgMYSE/9hHpvwUF+SyafMO5N7aFIXnf/4YjzdH2dnjR6zxBEWCg Gow51PuA3AIr/bGzmlBkezz4jvn6r4IgwOr60tM8cvHE+gDnEld76gYiSRzTcCKzI7S8 xREQ== X-Gm-Message-State: AOJu0YytC9oq9L/bH4EiondWUCjb75l/DfNptyR+ThfLPY7LaUXJ6S5E wa2joIkTtP/b84PYD7BC6bnP/1XR614cNN6fI8SuSenbphGMfbkAIsY5emItzF7BY9Uo8dIPMTh r X-Google-Smtp-Source: AGHT+IH2q+jd3fMCredma8Zo0CO3qFCcEuCojOXH+YoMNa5QLu49k6W7N+6Dy446tOtiG5TvVpvhhw== X-Received: by 2002:a7b:cbd2:0:b0:425:5eec:d261 with SMTP id 5b1f17b1804b1-4257a02805dmr62785395e9.34.1719912354928; Tue, 02 Jul 2024 02:25:54 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0e1430sm12682288f8f.52.2024.07.02.02.25.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:25:54 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 51/67] hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24) Date: Tue, 2 Jul 2024 11:20:34 +0200 Message-ID: <20240702092051.45754-52-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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, T_SPF_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-58-philmd@linaro.org> --- hw/sd/sd.c | 57 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 3f5cc0c55c..02a1203691 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -239,7 +239,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) static const char *cmd_abbrev[SDMMC_CMD_MAX] = { [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", - [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", + [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", @@ -1479,6 +1479,33 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req) return sd_r1; } +/* CMD24 */ +static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK(SDState *sd, SDRequest req) +{ + uint64_t addr; + + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + addr = sd_req_get_address(sd, req); + if (!address_in_range(sd, "WRITE_SINGLE_BLOCK", addr, sd->blk_len)) { + return sd_r1; + } + + if (sd->size <= SDSC_MAX_CAPACITY) { + if (sd_wp_addr(sd, addr)) { + sd->card_status |= WP_VIOLATION; + } + } + if (sd->csd[14] & 0x30) { + sd->card_status |= WP_VIOLATION; + } + + sd->blk_written = 0; + return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; @@ -1536,32 +1563,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; /* Block write commands (Class 4) */ - case 24: /* CMD24: WRITE_SINGLE_BLOCK */ - addr = sd_req_get_address(sd, req); - switch (sd->state) { - case sd_transfer_state: - - if (!address_in_range(sd, "WRITE_SINGLE_BLOCK", addr, - sd->blk_len)) { - return sd_r1; - } - - if (sd->size <= SDSC_MAX_CAPACITY) { - if (sd_wp_addr(sd, sd->data_start)) { - sd->card_status |= WP_VIOLATION; - } - } - if (sd->csd[14] & 0x30) { - sd->card_status |= WP_VIOLATION; - } - sd->blk_written = 0; - return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); - - default: - break; - } - break; - case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ addr = sd_req_get_address(sd, req); switch (sd->state) { @@ -2310,6 +2311,7 @@ static const SDProto sd_proto_spi = { [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, + [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [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}, @@ -2346,6 +2348,7 @@ static const SDProto sd_proto_sd = { [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}, + [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:35 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: 13719309 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 77E6AC3064D for ; Tue, 2 Jul 2024 09:31:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZm4-0000Ew-Ed; Tue, 02 Jul 2024 05:26:08 -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 1sOZm0-0008UD-IU for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:04 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZly-00012i-K8 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:04 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42562fde108so28356865e9.0 for ; Tue, 02 Jul 2024 02:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912360; x=1720517160; 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=z/UKK5N0qGd6voyebxVz2Nr3WQRgwbnXplKwK5vNXYE=; b=szd3ELL2cGpIPmqX5hw/lwOqF+fbb4CKnYub3mselaT46ja4t7wmHZNc47uoUqCcTo P2+QyfSYJsInW9R75L0QH1RVt0UY9k02gEHr/EWS/1lYcpk1Q4HoMbNzhWjhONXUi/m5 r4EAHk6I7iY/yAo6zJWgc9y2n3pjd2cq3Sp/ZD7ttx0R/ZVVl5eTBaVQ50TJqhAh+vZq T2l682jzNMWuq6N3eAM71SR4XIPEnmreIVnz2G7iaalsmFZc4YqtSluanttfdO+aAK/+ Fx1L4h9Z6K41Df0vKQ8zd8BKtk16sCZOR1keGn3f1wR0QjtdytRAKp9O1R0nMORNjVQB EK9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912360; x=1720517160; 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=z/UKK5N0qGd6voyebxVz2Nr3WQRgwbnXplKwK5vNXYE=; b=HK9oREaMwx8Yr5DoJkTU+QYpPmlGekcOnPPhqRmVoMC5L05gPfKp20/IHfh+YFWsdj 1icEk3ozzZ8PyYcWETIfIRgNr9T01NHrj9xmoApGdtVKOd4WchoFJF9H7qcx65+x4QHT rnCMZIO/R5DkHgwPRG/rCNKS7l0pipe3xB/yVjNlFvMPKMLVQfPAoOOuW53aMntyOMJS TVFY9izSIMCUAXrWEYFrWjrjd0xmUB4KK6gSFS0RNcRfpAWzTbgLzPR5EZQt0vnNiZed 7xr9e2yKAOwwlTwusUeyjwzXz3PGEMTaoG/HsFbPFgZkQhec+/2czk4dp+8+Qsz+nqcT R96g== X-Gm-Message-State: AOJu0Yy8RVDQI+cpf9cdsMv0ZU5z+WZpk+i4P+e2ZeouUR21VgYLr7W/ QwHOCMHuD+FMzcpRRTnjbXyAd8937EosjoUC7L92GGCF3e119xCoiKP2CSuDb5OWWIGk6CxhIVf p X-Google-Smtp-Source: AGHT+IEuEkTFKY+GsFMfDa2eaJssxS1ajtteMArpwzJzJBnHB3MRwbnfwy8O00Fm5VWiYvcIp9AicA== X-Received: by 2002:a05:600c:63c8:b0:425:7974:2266 with SMTP id 5b1f17b1804b1-4257a03a58amr55725555e9.24.1719912360730; Tue, 02 Jul 2024 02:26:00 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257dee5f2asm100810435e9.22.2024.07.02.02.25.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:00 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 52/67] hw/sd/sdcard: Add sd_cmd_PROGRAM_CSD handler (CMD27) Date: Tue, 2 Jul 2024 11:20:35 +0200 Message-ID: <20240702092051.45754-53-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-59-philmd@linaro.org> --- hw/sd/sd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 02a1203691..e1c799c117 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -240,7 +240,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", - [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", + [26] = "MANUF_RSVD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", @@ -1506,6 +1506,12 @@ static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, addr, sd->blk_len); } +/* CMD27 */ +static sd_rsp_type_t sd_cmd_PROGRAM_CSD(SDState *sd, SDRequest req) +{ + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->csd)); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; @@ -1595,9 +1601,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 26: /* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); - case 27: /* CMD27: PROGRAM_CSD */ - return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->csd)); - /* Write protection (Class 6) */ case 28: /* CMD28: SET_WRITE_PROT */ if (sd->size > SDSC_MAX_CAPACITY) { @@ -2312,6 +2315,7 @@ static const SDProto sd_proto_spi = { [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [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}, @@ -2349,6 +2353,7 @@ static const SDProto sd_proto_sd = { [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:36 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: 13719291 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 99381C30658 for ; Tue, 2 Jul 2024 09:28:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmC-0000qE-3U; Tue, 02 Jul 2024 05:26:17 -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 1sOZm8-0000ZZ-Cd for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:12 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZm4-00018H-B5 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:10 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3674e1931b7so2694159f8f.2 for ; Tue, 02 Jul 2024 02:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912366; x=1720517166; 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=AXCg3w5PVdeJgjz/MXSI7N25wc9KB2lQFNoBJeyQQpg=; b=Wo4NjNFrbZt8LAy5cJ9t/xD+9SAd3llgVHaiad0zYpPCo1rupOIoLWGnvo5HIldG4j ciVNSwEyFqyHotpYfdwAmrto9yahSenITRGTKtN7PmmmvoKy8So0IEZPSYGoRumeyLiL QYhQZs32rercr9Pg9Iop7SHmq5Yj0eyct9OWIysBEwts1Bf47IPkIOgvn/36Vdj9j/U1 DrzsN/Nk3ip/3pEZgT6u2zJFbodPnHtPOVfAX2m9mBE8ThSAWGvMFxjcFePTE0yQp/3B jJ8vkdJxnqcz9NcFlDtzLy3lpUhpHJ9sWDpGDFVAKgfiO2LSksPq0BxjHWqLVYq63ys1 pRMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912366; x=1720517166; 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=AXCg3w5PVdeJgjz/MXSI7N25wc9KB2lQFNoBJeyQQpg=; b=GaO8fjjc8rQgfDZaOMtQFQcUSLVjEryeInUNYxQReYNPrZTzHXjvKX2ldQEq6FRQVy HjQCzoQUU2JO5jkDDuWim8r+q22iGdxc2EnseTpo8RnXDBzzkVRmwjnzbmBT8Pz6cxgY 0Hn79cwNG7dDqygJ3zXHsIVq2eXwrBuE6az/8TGmQRXl128W8W/EKek0tg7u7W37Sx7/ CJ34S6ARgBBtJER6C62JF22qmtoBX6B2Sjyz+UzDjgsh8x/O6hahPAkWEyge9EGh8sfQ XGtoxtkG4kl5zmdgEIvpDCBocxLhtRqiYdq5YNCYeywedkfBEBNYrkmLbnv0L4zZQBV+ KqFg== X-Gm-Message-State: AOJu0YxtgZiXWMLXYCdPNym92DDfKAgehH6T1YJwC4aEby52FTKp+qid SZwenz4bSZffbu478ZTcR6FJ50lRq8h4Vj7Ni1mDKqC+qhziLZn+0+aOZFDxSF0Q0skm984186J R X-Google-Smtp-Source: AGHT+IGRelkJWuOrs1/KMBLz9CKBQ8J6DacU3uWDdbouPnGLVt49OPfJDWYKGCU+30pgic4jYuj5vQ== X-Received: by 2002:a5d:525c:0:b0:35f:1d40:82fa with SMTP id ffacd0b85a97d-367756ad6f5mr4253182f8f.18.1719912366443; Tue, 02 Jul 2024 02:26:06 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a103366sm12572103f8f.102.2024.07.02.02.26.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:06 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 53/67] hw/sd/sdcard: Add sd_cmd_SET/CLR_WRITE_PROT handler (CMD28 & CMD29) Date: Tue, 2 Jul 2024 11:20:36 +0200 Message-ID: <20240702092051.45754-54-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-60-philmd@linaro.org> --- hw/sd/sd.c | 91 +++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e1c799c117..384ce77b36 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -241,7 +241,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE", @@ -1512,6 +1511,48 @@ static sd_rsp_type_t sd_cmd_PROGRAM_CSD(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->csd)); } +static sd_rsp_type_t sd_cmd_SET_CLR_WRITE_PROT(SDState *sd, SDRequest req, + bool is_write) +{ + uint64_t addr; + + if (sd->size > SDSC_MAX_CAPACITY) { + return sd_illegal; + } + + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + addr = sd_req_get_address(sd, req); + if (!address_in_range(sd, is_write ? "SET_WRITE_PROT" : "CLR_WRITE_PROT", + addr, 1)) { + return sd_r1b; + } + + sd->state = sd_programming_state; + if (is_write) { + set_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap); + } else { + clear_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap); + } + /* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; + return sd_r1; +} + +/* CMD28 */ +static sd_rsp_type_t sd_cmd_SET_WRITE_PROT(SDState *sd, SDRequest req) +{ + return sd_cmd_SET_CLR_WRITE_PROT(sd, req, true); +} + +/* CMD29 */ +static sd_rsp_type_t sd_cmd_CLR_WRITE_PROT(SDState *sd, SDRequest req) +{ + return sd_cmd_SET_CLR_WRITE_PROT(sd, req, false); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; @@ -1602,50 +1643,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); /* Write protection (Class 6) */ - case 28: /* CMD28: SET_WRITE_PROT */ - if (sd->size > SDSC_MAX_CAPACITY) { - return sd_illegal; - } - addr = sd_req_get_address(sd, req); - switch (sd->state) { - case sd_transfer_state: - if (!address_in_range(sd, "SET_WRITE_PROT", addr, 1)) { - return sd_r1b; - } - - sd->state = sd_programming_state; - set_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap); - /* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; - return sd_r1b; - - default: - break; - } - break; - - case 29: /* CMD29: CLR_WRITE_PROT */ - if (sd->size > SDSC_MAX_CAPACITY) { - return sd_illegal; - } - addr = sd_req_get_address(sd, req); - switch (sd->state) { - case sd_transfer_state: - if (!address_in_range(sd, "CLR_WRITE_PROT", addr, 1)) { - return sd_r1b; - } - - sd->state = sd_programming_state; - clear_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap); - /* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; - return sd_r1b; - - default: - break; - } - break; - case 30: /* CMD30: SEND_WRITE_PROT */ if (sd->size > SDSC_MAX_CAPACITY) { return sd_illegal; @@ -2316,6 +2313,8 @@ static const SDProto sd_proto_spi = { [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, + [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, + [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [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}, @@ -2354,6 +2353,8 @@ static const SDProto sd_proto_sd = { [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, + [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, + [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:37 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: 13719298 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 C8EACC3064D for ; Tue, 2 Jul 2024 09:29:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmG-0001RG-Mr; Tue, 02 Jul 2024 05:26:20 -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 1sOZmF-0001E6-AK for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:19 -0400 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZmD-0001Ms-AG for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:19 -0400 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ec61eeed8eso49000261fa.0 for ; Tue, 02 Jul 2024 02:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912372; x=1720517172; 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=cBeUcx8Psy1taypQO+9k0SQLPvz0ZTjNS5TGwOTNSRg=; b=kroOfv6hra57WSTQe2NV5IkKK7iIWGkfVWUzeEu98k0qsc818NhemVDUJ2w1/1mMxC ZJ7FtJWtHa8ZlzctQliVYBYhxAecYj9L4IOUkke0ia8IkkTRpHwu0Py6tGiBhVp3Uzjr KtToLKekIqBDdrdtm66BLRx1ywKaxjgLadQ5gGahETWUnx4dn5ZRviUthDH1WeSW5avd WOLJZ7kWva5xrYYd/z+I5/2GMZwKA5+B6zx3XGZvXifihkvzSIdiVHJuxpTeG+k78nfL IRdFaUrqF1uKQEoLomzS1rg5lp+Af41zCJmQguRMx0Y2pOxgbXyDxgR6rPJdhO76PcK0 7c5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912372; x=1720517172; 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=cBeUcx8Psy1taypQO+9k0SQLPvz0ZTjNS5TGwOTNSRg=; b=QuOhZFtxNFfk1kn4D+yI/G+OcK1nGe/d8iQ0L7xCg8pprpXcGynYNNJpTnwOpqIhJU O+Ip5F6CJFCTMALFlsWB0/0Z3c7anmXL23EsEINMRIPRdSBJ1nX4TDsK8gb5xYqBGJg7 ANBUOPmE2PUnkayqFhyd9cgpG1WfSYnTd7n/W6GEuVWUTQHpYx3/2oil8lzmxfe208g2 vvPrlV+z2g9o08NUU+4Lw3SwUitkBcATgwXpD9l2MoYf4BI2n3eJeev2DhIucD6FB6xO xS+lvOQ9HHXsy0wkWM4Oy5iRMzP/HLbv5iggSwTm5xgxXvPVXVvfZC31AqLSicofCzlM WmHA== X-Gm-Message-State: AOJu0YysZDUt5/QvVjWyS2bmbEyDfSFSRVfwDUhT/LwOXz63bYOaHnZG KOX4wrt8aqdTQFPQIrD819505vZwpuFCwh2x3+zzJwuks4i/IxDuH2OEEGAEZ5pFc9Uuf9lFe/3 t X-Google-Smtp-Source: AGHT+IGGEVveWCeQ2w4pmDyt0FpoGY0fV+eAkgyCRjWiymeuo6H7v5CoEW5CcOcitZzWEAcUugW3gQ== X-Received: by 2002:a2e:b951:0:b0:2ec:5685:f068 with SMTP id 38308e7fff4ca-2ee5e358fa9mr43497391fa.17.1719912372257; Tue, 02 Jul 2024 02:26:12 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257fb4fabdsm96420595e9.46.2024.07.02.02.26.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:11 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 54/67] hw/sd/sdcard: Add sd_cmd_SEND_WRITE_PROT handler (CMD30) Date: Tue, 2 Jul 2024 11:20:37 +0200 Message-ID: <20240702092051.45754-55-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::233; envelope-from=philmd@linaro.org; helo=mail-lj1-x233.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-61-philmd@linaro.org> --- hw/sd/sd.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 384ce77b36..b205cc4692 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -241,7 +241,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE", [40] = "DPS_spec", @@ -1553,11 +1552,33 @@ static sd_rsp_type_t sd_cmd_CLR_WRITE_PROT(SDState *sd, SDRequest req) return sd_cmd_SET_CLR_WRITE_PROT(sd, req, false); } +/* CMD30 */ +static sd_rsp_type_t sd_cmd_SEND_WRITE_PROT(SDState *sd, SDRequest req) +{ + uint64_t addr; + uint32_t data; + + if (sd->size > SDSC_MAX_CAPACITY) { + return sd_illegal; + } + + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + addr = sd_req_get_address(sd, req); + if (!address_in_range(sd, "SEND_WRITE_PROT", addr, sd->blk_len)) { + return sd_r1; + } + + data = sd_wpbits(sd, req.arg); + return sd_cmd_to_sendingdata(sd, req, addr, &data, sizeof(data)); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; uint64_t addr; - uint32_t data; sd->last_cmd_name = sd_cmd_name(sd, req.cmd); /* CMD55 precedes an ACMD, so we are not interested in tracing it. @@ -1642,26 +1663,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 26: /* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); - /* Write protection (Class 6) */ - case 30: /* CMD30: SEND_WRITE_PROT */ - if (sd->size > SDSC_MAX_CAPACITY) { - return sd_illegal; - } - addr = sd_req_get_address(sd, req); - switch (sd->state) { - case sd_transfer_state: - if (!address_in_range(sd, "SEND_WRITE_PROT", - req.arg, sd->blk_len)) { - return sd_r1; - } - data = sd_wpbits(sd, req.arg); - return sd_cmd_to_sendingdata(sd, req, addr, &data, sizeof(data)); - - default: - break; - } - break; - /* Erase commands (Class 5) */ case 32: /* CMD32: ERASE_WR_BLK_START */ switch (sd->state) { @@ -2315,6 +2316,7 @@ static const SDProto sd_proto_spi = { [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, + [30] = {6, sd_spi, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, [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}, @@ -2355,6 +2357,7 @@ static const SDProto sd_proto_sd = { [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, + [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:38 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: 13719280 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 DE4BEC3064D for ; Tue, 2 Jul 2024 09:27:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmM-0002Gj-Ck; Tue, 02 Jul 2024 05:26:26 -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 1sOZmK-0001we-8m for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:24 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZmG-0001O5-7q for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:23 -0400 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-52ce6c8db7bso5943074e87.1 for ; Tue, 02 Jul 2024 02:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912378; x=1720517178; 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=VWCogmQ5YMxblD7fAdd5ouQjKmXVnhB0D5NSysNvar4=; b=RIezjv6RM1IZqEjzuCMphhg/sy+W2SOU1yWGDabTf8XrDUa2RPsdnIBrkLJOSfwxD1 MMqJiMUfr1N3AlSjlbn6BIPk7FnI0QZ5g48u5IY7YR0WPKUh3ur/fDwvFlzK2HpH++OE WypMMXyYq9G1yA8C0X3FzAfAYW79QecBTzFbvJsCfihk8wufWgrsdE3WbHYnR4CqF9GJ S66tZz3Lk5OQcgdsaq+fX/6gZPWLJnUbUVjEfaWoX4r/zUqntsK//xqT7Evo6NkgsfnQ 0JIlY1sapYrVKIJWLCUvX+gQwRC6a9vPIL2SuM1HbMHPXersTCzTajhl8ic8d1rqIH52 RByg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912378; x=1720517178; 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=VWCogmQ5YMxblD7fAdd5ouQjKmXVnhB0D5NSysNvar4=; b=nv4sWFYs9XJiwHftNBVKDVYIYKkZL5ZEBgCD1AeC9nJ/GJYYsPofgs3555t9z15sNb fMS8MO/Yc4G4kj0yzC4+9N0AwI6HGyXpidqedopDIUOXPJpbm0bcZ8NJ3QWKY3qlntFT 9n2xBuKFMZGVIFp9/xCWJM2a3CkF8jWzT+inXaoym4bAxzlE3oH3LF4LwXin44BPtN1r wP3ygPswlX8d6Ih0fLaFimUyg770QNgxs5Z8+h1hsU68ljJFDM544RDcki+eY5zleLx9 xsGbkxoeWgBJXLl19s+U/kDdFoH07yFTSum+evJghm475r4w76RJJ9FLTB2i8j3TijtC 7S/g== X-Gm-Message-State: AOJu0YyNvQ80u04Pwpa0rLNVahjByPbIoT/IJiWsZLO+EKVkTcdb8lv6 J+esn1SL0pBImRMCkV77RbPNf/wsqtei49mL0o4YODJRdoFw/1VM6UM71Bmsrp9MwSxYt8vJSU6 j X-Google-Smtp-Source: AGHT+IFvsQ9ePYgRzx/8fGAtfF/c/Ts5j5G5g6hHzxPKixkFgeq0OgRfAt55wxEw+h7YTDZWCS2tDg== X-Received: by 2002:a05:6512:3e28:b0:52c:d905:9645 with SMTP id 2adb3069b0e04-52e8265184bmr6522600e87.13.1719912378233; Tue, 02 Jul 2024 02:26:18 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b09abbfsm189020845e9.35.2024.07.02.02.26.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 55/67] hw/sd/sdcard: Add sd_cmd_ERASE_WR_BLK_START/END handlers (CMD32 & CMD33) Date: Tue, 2 Jul 2024 11:20:38 +0200 Message-ID: <20240702092051.45754-56-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=philmd@linaro.org; helo=mail-lf1-x132.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-62-philmd@linaro.org> --- hw/sd/sd.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b205cc4692..d517a00ee1 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -241,7 +241,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK", @@ -1575,6 +1574,26 @@ static sd_rsp_type_t sd_cmd_SEND_WRITE_PROT(SDState *sd, SDRequest req) return sd_cmd_to_sendingdata(sd, req, addr, &data, sizeof(data)); } +/* CMD32 */ +static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_START(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + sd->erase_start = req.arg; + return sd_r1; +} + +/* CMD33 */ +static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_END(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + sd->erase_end = req.arg; + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; @@ -1664,28 +1683,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); /* Erase commands (Class 5) */ - case 32: /* CMD32: ERASE_WR_BLK_START */ - switch (sd->state) { - case sd_transfer_state: - sd->erase_start = req.arg; - return sd_r1; - - default: - break; - } - break; - - case 33: /* CMD33: ERASE_WR_BLK_END */ - switch (sd->state) { - case sd_transfer_state: - sd->erase_end = req.arg; - return sd_r1; - - default: - break; - } - break; - case 38: /* CMD38: ERASE */ switch (sd->state) { case sd_transfer_state: @@ -2317,6 +2314,8 @@ static const SDProto sd_proto_spi = { [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [30] = {6, sd_spi, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [32] = {5, sd_spi, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, + [33] = {5, sd_spi, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, [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}, @@ -2358,6 +2357,8 @@ static const SDProto sd_proto_sd = { [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [32] = {5, sd_ac, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, + [33] = {5, sd_ac, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:39 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: 13719303 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 11C6FC3064D for ; Tue, 2 Jul 2024 09:30:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmZ-0002mL-Ic; Tue, 02 Jul 2024 05:26:40 -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 1sOZmS-0002fa-Di for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:32 -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 1sOZmM-0001Y4-3k for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:32 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3629c517da9so3146224f8f.2 for ; Tue, 02 Jul 2024 02:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912384; x=1720517184; 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=d8cKKzD5TFUU9UNeYz0boxlMOoI7h2YEt8SrgZwBqHs=; b=mIyh20g+FjycBxtYzV25SgsuJyyUizYxWwoQgUuboFxjNIQtM5vCsbzlxIKRryEXn0 qflbsMNwJowFBXrjhj9ssXMdVMGcb2JxZYnPmeh2xDGudqUp/Z9VKytHrOEaVk69lris AbmgF6idxRYV7s/UAI8m+qbYV65T1WLRXvDZBFv3uXRWxliQKA2TyRanMatCTB02SBbt 7JZZHRoWeXSS/BfKsaGNuggQt2O5KMpTarW2Vq9SjLP0YPEhmkTS3AwNXISD0mZMf+Wb 1/Kf1H/1uQnJwWXTbdj44ikQgpwDZJXpR4+IKsy2a17upv1j89rM71x2xGGfVmQ9JGKC fMaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912384; x=1720517184; 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=d8cKKzD5TFUU9UNeYz0boxlMOoI7h2YEt8SrgZwBqHs=; b=uu43o2uweK07hIm3dwthKLFqq12otQxNdvOGtlKtSO9TzhesTCIbnq1hBGjCmGlvSw wI4ZLO00UaB2hgDLxSJCN23O9onvZiZ5L8/6KF1gHjFD8IYvwQowrvMeK/mNoVWO7jzY 13aEi3d5NQfPzA9DloxQ0Tn1O2OJActTcYmzTZN0DOVB/29hgBguUmfU9Bhc3IQ39Eg3 HbfB/Dy6C0zbsi0gcfuNsT1bhjRf7+YMQH2xI+Lrh7C6/MMYQiwlrPKQSw1L9+C0Uf85 JE4AYuZoqpvNV3iaQ06DISNw0XGd49Qjxw3Zr0jj8/Yz7w2+aK0uXFlqJYMrJNHcvdln xVHg== X-Gm-Message-State: AOJu0YyJkjR4JsnFdW/l7kXFnsil6oxYAiCDJJMv0LpX2crYkxQdLe50 TAiX4lnIOIued0WhK3M7NY/PN3UNQP25iLsD9E3GbvRsL0gqBNiIvFaa2rZDvouCyJt+v6QnnZQ J X-Google-Smtp-Source: AGHT+IHQCXCLm6iVwJjCjW28T5HdPbdEHl5LVQbFLqH/aMEOWZYDGxZ0QBLQGT0/s5uO7plaF1geqQ== X-Received: by 2002:a5d:648f:0:b0:366:efbd:8aa3 with SMTP id ffacd0b85a97d-36775699521mr7233401f8f.2.1719912384073; Tue, 02 Jul 2024 02:26:24 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fb92fsm12755145f8f.88.2024.07.02.02.26.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 56/67] hw/sd/sdcard: Add sd_cmd_ERASE handler (CMD38) Date: Tue, 2 Jul 2024 11:20:39 +0200 Message-ID: <20240702092051.45754-57-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-63-philmd@linaro.org> --- hw/sd/sd.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index d517a00ee1..be9437141a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -241,7 +241,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK", [54] = "SDIO_RSVD", [55] = "APP_CMD", @@ -1594,6 +1593,24 @@ static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_END(SDState *sd, SDRequest req) return sd_r1; } +/* CMD38 */ +static sd_rsp_type_t sd_cmd_ERASE(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + if (sd->csd[14] & 0x30) { + sd->card_status |= WP_VIOLATION; + return sd_r1b; + } + + sd->state = sd_programming_state; + sd_erase(sd); + /* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; + return sd_r1b; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; @@ -1682,26 +1699,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 26: /* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); - /* Erase commands (Class 5) */ - case 38: /* CMD38: ERASE */ - switch (sd->state) { - case sd_transfer_state: - if (sd->csd[14] & 0x30) { - sd->card_status |= WP_VIOLATION; - return sd_r1b; - } - - sd->state = sd_programming_state; - sd_erase(sd); - /* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; - return sd_r1b; - - default: - break; - } - break; - /* Lock card commands (Class 7) */ case 42: /* CMD42: LOCK_UNLOCK */ return sd_cmd_to_receivingdata(sd, req, 0, 0); @@ -2320,6 +2317,7 @@ static const SDProto sd_proto_spi = { [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [38] = {5, sd_spi, "ERASE", sd_cmd_ERASE}, [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, @@ -2363,6 +2361,7 @@ static const SDProto sd_proto_sd = { [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:40 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: 13719289 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 35088C30658 for ; Tue, 2 Jul 2024 09:28:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmc-0002q3-PG; Tue, 02 Jul 2024 05:26:43 -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 1sOZmU-0002lv-S5 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:35 -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 1sOZmS-0001YU-8O for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:33 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-424ad991c1cso34899725e9.1 for ; Tue, 02 Jul 2024 02:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912390; x=1720517190; 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=IFulJ2oO2h99eDTEiqTYqq780MTJhbquTUdeCChl0+Y=; b=n14tGp0lWBgxOmhjjGu2zvZZGlY1qS6wucB5LzlCzyJc6Mopa2t8gVFVRV9RLys7LO 13yAYKgTSnDkZdBjEDNviaZPu7kYfND/a/71kiuWMejF7L3BFziMeEHzuCRRb/5GN5sU Qj6oC1ShciFmsfbfDCWR9xONiU73iJmjU/f/9p80aL0qk6cURLJA6HOFwZIb0OstJmqC LtfS3Dvpbshu0GfsV2sZDV7TdvyiLfs8ti87cSZoQynAifkpfxn1EY+DEdPbjiKT6glM K2e5TfQ0h1pdAOBTqt0oni9SmsMFux9XpWu67Cyzp7znVEBv0a4JwG3nKjLQ1aT26DI7 KFpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912390; x=1720517190; 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=IFulJ2oO2h99eDTEiqTYqq780MTJhbquTUdeCChl0+Y=; b=QktO8A7WJgjaqCwfFoFuSsyYYc7jkpTqmSViFoVl9g0noG+LDIEGJTXoqsbjWaUJyJ h03t4sUQXa9lFIP0wwuBTOpRZkn+/n/1/UeBDItEippR9w1uwbcKDachSiJh8k2csLP7 6mKKKGKE7m0TZb/yLdz1g541mQGwGRLOD1e0dQWCM+gmuWHUMqncLYV+mO3nZBwdyMeh +0y7l26IDu7IFPU1pzGWKOH22bANgXOpprY5yyg1itS3TBCSd+f2px6Md/a4Ua3legUf oq+E3BsXY8wvhwH/jNTGsSEkvMqI/+Y8nDkVnLC47SJ2tA3Cmi3wSVi94L0QQtIydT+h C8yQ== X-Gm-Message-State: AOJu0YxXNnEub4S4ulb6PCqWuv/EPe6cwz8d0XCDwB5c47t3iZ8Gz9ma V5wknVsSQ8GpOlqgHo3I2Sjo8wmfP+NOApiPaYIgIn1Qdmc3GpI3Sn6PadBqRVISvNsmeHcp5Ri v X-Google-Smtp-Source: AGHT+IGWpZeEh8ZZtCuVoeddHoAPB4Q99kNHb4BHL2wUwl2DzUfZDYOiJ2DuqlJQIgh/heVh8X70hg== X-Received: by 2002:a5d:4b4f:0:b0:360:9a40:3dd8 with SMTP id ffacd0b85a97d-367757301b1mr6133651f8f.65.1719912389920; Tue, 02 Jul 2024 02:26:29 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b098426sm188322325e9.32.2024.07.02.02.26.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 57/67] hw/sd/sdcard: Add sd_cmd_LOCK_UNLOCK handler (CMD42) Date: Tue, 2 Jul 2024 11:20:40 +0200 Message-ID: <20240702092051.45754-58-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-64-philmd@linaro.org> --- hw/sd/sd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index be9437141a..da344589f2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -242,7 +242,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [42] = "LOCK_UNLOCK", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", @@ -1611,6 +1610,12 @@ static sd_rsp_type_t sd_cmd_ERASE(SDState *sd, SDRequest req) return sd_r1b; } +/* CMD42 */ +static sd_rsp_type_t sd_cmd_LOCK_UNLOCK(SDState *sd, SDRequest req) +{ + return sd_cmd_to_receivingdata(sd, req, 0, 0); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint16_t rca; @@ -1699,10 +1704,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 26: /* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); - /* Lock card commands (Class 7) */ - case 42: /* CMD42: LOCK_UNLOCK */ - return sd_cmd_to_receivingdata(sd, req, 0, 0); - /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ rca = sd_req_get_rca(sd, req); @@ -2318,6 +2319,7 @@ static const SDProto sd_proto_spi = { [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [38] = {5, sd_spi, "ERASE", sd_cmd_ERASE}, + [42] = {7, sd_spi, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, @@ -2362,6 +2364,7 @@ static const SDProto sd_proto_sd = { [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, + [42] = {7, sd_adtc, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional}, From patchwork Tue Jul 2 09:20:41 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: 13719308 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 4F7C2C3064D for ; Tue, 2 Jul 2024 09:30:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmg-0002uj-5k; Tue, 02 Jul 2024 05:26:46 -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 1sOZmc-0002r6-Tl for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:42 -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 1sOZmX-0001Z9-Dz for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:42 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4256788e13bso28561295e9.2 for ; Tue, 02 Jul 2024 02:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912395; x=1720517195; 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=odaH6p2tA7JjyfEGnhEe1HDwlvnEgHVlkHIdzE6llls=; b=u3DUJtfFGVQVD1Pv3nm4O7lTx0oRlHmi1RLbxxOhObn3P50wGWrNVtDy5kXc9DOiJa DqiKkHV1WLLdQgiwqn7o0ihFogaKMJlP/WvqCgjM/ZFf9jKKs9NHdBMrkRqI5BS6ZuiS HJOesRDgyQCbZV1ttg7EXTBAnulU5ur5dR6ZPCZiIrVsaJKyBZF80+7sc4frBplHRhbw ZbnMxg73Lfxa/JCotKiPtC6Sym7t5hfzcpApY1Ryu23QMacj0CECSMG1esbbyvaitvqZ GkVp3f6fvcUrdLrosH5HDQvcfWIvciE9Y2UpC2Jyk3KtTsXRM2iEw3Yqj38dZYtSnl1H xkbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912395; x=1720517195; 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=odaH6p2tA7JjyfEGnhEe1HDwlvnEgHVlkHIdzE6llls=; b=rDPB1UMaPYSlW4Gr4jpE9H00HVbutNfSoMVCoRisRw+6G6BTJJ07bwPKKeMB3fe21z RApJDpWagfsyejIrkxBXmIJUZ63gzCvtw72ltXd75N3LuZDgdVLplEMNJhMKHnxleTTb Ugl3azpX7LIBwyPH9bZ2IbV2ExBF/ReEovu8ezgF6gxxDDcFzLKUdBkk8mz1LTVJU0iG KY/nqkd6IVHjNvdLmvUv9LYTgqrrAU63mVU0cclsuy3NoPvbD1/CYUYF90tyJdkEMqUx cxfHIt7535R+KcR6WSMCDiTo8Rdh3H3R7FDCi4LdVgS1u2mfAYpntzAxSCLvKKbQp1Rq XRcg== X-Gm-Message-State: AOJu0YyBhDA4NdaFXY+tfnjY19XTPQ4/eC3IfwQhOxf5/g+MFn5okws1 eP2J7zac3XUzSzfQ88WLasOesQRYp7vJjLj/XRaas+bQQhKA3hy2a1l75DIxBhwE5TGhyXUh8vF L X-Google-Smtp-Source: AGHT+IG45CpxWxU8/B7qH0tDNKU6nnr9s3Ed7Vm4fYU9VtM0cwaXh+0hSqoqvHbnHqjkW1dhwSKgPA== X-Received: by 2002:a05:600c:c88:b0:425:6498:3b6c with SMTP id 5b1f17b1804b1-4257a06427bmr63720605e9.26.1719912395693; Tue, 02 Jul 2024 02:26:35 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fb950sm12559263f8f.83.2024.07.02.02.26.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 58/67] hw/sd/sdcard: Add sd_cmd_APP_CMD handler (CMD55) Date: Tue, 2 Jul 2024 11:20:41 +0200 Message-ID: <20240702092051.45754-59-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-65-philmd@linaro.org> --- hw/sd/sd.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index da344589f2..f5548d5667 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -242,7 +242,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", @@ -1616,9 +1615,34 @@ static sd_rsp_type_t sd_cmd_LOCK_UNLOCK(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, 0); } +/* CMD55 */ +static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd, SDRequest req) +{ + switch (sd->state) { + case sd_ready_state: + case sd_identification_state: + case sd_inactive_state: + return sd_invalid_state_for_cmd(sd, req); + case sd_idle_state: + if (!sd_is_spi(sd) && sd_req_get_rca(sd, req) != 0x0000) { + qemu_log_mask(LOG_GUEST_ERROR, + "SD: illegal RCA 0x%04x for APP_CMD\n", req.cmd); + } + /* fall-through */ + default: + break; + } + if (!sd_is_spi(sd) && !sd_req_rca_same(sd, req)) { + return sd_r0; + } + sd->expecting_acmd = true; + sd->card_status |= APP_CMD; + + return sd_r1; +} + 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(sd, req.cmd); @@ -1705,29 +1729,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid)); /* Application specific commands (Class 8) */ - case 55: /* CMD55: APP_CMD */ - rca = sd_req_get_rca(sd, req); - switch (sd->state) { - case sd_ready_state: - case sd_identification_state: - return sd_illegal; - case sd_idle_state: - if (rca) { - qemu_log_mask(LOG_GUEST_ERROR, - "SD: illegal RCA 0x%04x for APP_CMD\n", req.cmd); - } - default: - break; - } - if (!sd_is_spi(sd)) { - if (sd->rca != rca) { - return sd_r0; - } - } - sd->expecting_acmd = true; - sd->card_status |= APP_CMD; - return sd_r1; - case 56: /* CMD56: GEN_CMD */ switch (sd->state) { case sd_transfer_state: @@ -2323,6 +2324,7 @@ static const SDProto sd_proto_spi = { [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, }, .acmd = { @@ -2375,6 +2377,7 @@ static const SDProto sd_proto_sd = { [50] = {10, sd_adtc, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, From patchwork Tue Jul 2 09:20: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: 13719287 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 5D5C8C30658 for ; Tue, 2 Jul 2024 09:28:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmm-00034r-FW; Tue, 02 Jul 2024 05:26:52 -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 1sOZmf-0002uO-MP for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:45 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZmc-0001ZT-Uk for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:45 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4256aee6e4dso28693435e9.1 for ; Tue, 02 Jul 2024 02:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912401; x=1720517201; 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=hYt9NrY8vo8112paVkmJIP0WplWJ6pspD+deTZLbMcw=; b=FdyQ2c+p6ljntTKi+3mndjpFxmxmJmebvjqHxdiBmPqiISgm6HVRIGPzPslAIaHEAt 7NQjDKHueAqj9231zCpRK8HPeKvZN3cvKdVhtAD1MJ5rLHANr8K2ny3r16h1jh/8QjC9 NHBVb0EaWfLjlOxdBD9jNS0OtMKLwtizaFC9r7EhMoZJzEwxdzUP1PbHvPx84SJf+Hpt BuslMu+7bR/Kjwf3ldNWsD1Kw4KVDtZiZwjqaZWrYbmGfgmQ4M9dO/IejnmmFCRDqdaM bbkTQxySOwdyy4yaJRFgqY6753BMhQLpLiiW81KKMSyqRG2O5kUtj6IzA7bBTrM+v2IF cu7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912401; x=1720517201; 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=hYt9NrY8vo8112paVkmJIP0WplWJ6pspD+deTZLbMcw=; b=Jd8/1a80x5C4Ae8zigv2PYi4cnkyA03ZcGJPPIWP8lCMiyqb7zFtS/2SFBw7YD1WrQ 5b0FjN+LnbCwAgJou9RVNXoNVA5SwRr7gY2VSayEh9svMDZwxeQZAfy/M8tdormjn+HM fZA0XIGXY5TdGfwaNE/Y90PnWucXR3zA3P3/llLsxIhHxkri68zHiJXJhF+vMKCh0rHu ZCG2BkCH83fbMC73dk96fnoquAk0DJNnD5YcXqNX5MXlIXluebRkYp4W5InPu8lGQPZp +FvEzIuLVMTK3o19b/guO2jDKeqIgpDyEKZjjU6MC8noXioY1CHo5h7lmmIVLxnKIPBN QoYQ== X-Gm-Message-State: AOJu0YxKGN8wkBX1yXRoRecAsKif8LdSJisr1J62+SpRbsvVCJBS/yxO Sv8ujOnYV7bzRbt9xASC+Gct+5XbY2ONyjprllIT5iqAKO1sZ1KeSpCR+Y3IeVEgIdnCaaH7Mb+ m X-Google-Smtp-Source: AGHT+IF+T9scoik84D/u8qine16/w8ayUy2hC8Vtd5HOEMgNYnwJ0XufsF9AGP0AfgY7dglsgNtrqg== X-Received: by 2002:a7b:ce83:0:b0:425:6327:f00c with SMTP id 5b1f17b1804b1-4257a00ce8emr54531615e9.22.1719912401329; Tue, 02 Jul 2024 02:26:41 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256af5901dsm190572775e9.14.2024.07.02.02.26.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:40 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 59/67] hw/sd/sdcard: Add spi_cmd_READ_OCR handler (CMD58) Date: Tue, 2 Jul 2024 11:20:42 +0200 Message-ID: <20240702092051.45754-60-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-67-philmd@linaro.org> --- hw/sd/sd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index f5548d5667..08fb3cf9d3 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1641,6 +1641,12 @@ static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd, SDRequest req) return sd_r1; } +/* CMD58 */ +static sd_rsp_type_t spi_cmd_READ_OCR(SDState *sd, SDRequest req) +{ + return sd_r3; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1744,9 +1750,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } break; - case 58: /* CMD58: READ_OCR (SPI) */ - return sd_r3; - case 59: /* CMD59: CRC_ON_OFF (SPI) */ return sd_r1; @@ -2326,6 +2329,7 @@ static const SDProto sd_proto_spi = { [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, + [58] = {0, sd_spi, "READ_OCR", spi_cmd_READ_OCR}, }, .acmd = { [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, From patchwork Tue Jul 2 09:20: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: 13719294 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 D9212C30658 for ; Tue, 2 Jul 2024 09:28:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZmw-0003TQ-Ju; Tue, 02 Jul 2024 05:27: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 1sOZmn-00037z-BP for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:54 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZmj-0001aC-Cf for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:52 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-366de090da9so1961797f8f.1 for ; Tue, 02 Jul 2024 02:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912407; x=1720517207; 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=oZj5eYp/kb8EVrafSTzyBAO6e70CoLy2x/MnndJCff4=; b=ZEaqyu4B7CZ623jBRJ7EdAJGf3xfD4S9psP8Fok95D9ySsrdruXukwmI9fEusWP2/v Oi1v55pzYRWLAlMMX28uYzfLqFBnWt003BAwyIuWByVTo77qnmN/Sh1aG8i6FdxEWA28 suDjRvlOis805xNqSjJatpEyzPj/x3jW7EuJfsOnndDDwzvnoLvaPEY3pycMkjwPCda6 hClpBxHOYxKVeVC/cy1dHK/9XqhH9U6PRxL5LWFcPaPfAaLTPTyn9Btkb+0EszPf2e1x lUN9XHzpYMkhWM9faDVugRcLXPdRsIFkIJ4Su/5/gzPyJIgYHzGZnqdTtIK31mRvzFL/ tDgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912407; x=1720517207; 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=oZj5eYp/kb8EVrafSTzyBAO6e70CoLy2x/MnndJCff4=; b=UvufVBsX0cVkKv6GlvB2rA8DR4K9eHdDYqZqfg17vMTIOecisa+bhYTkzVvVuL14CH z6iQyWxn/LqZiZ+yG1kZQCyNR+cY91vthTznxFTWoponTYsV40ta7h6Ul8ewDvFhbgOb rfC7JAQqazc3vScaeoi3lu7D/Un5WX84K1M1roy5mXsKpYFw5DNOUlo+Eu/nI0noImWC XW0FppIgKz4ewW60Lu0rK1i1mwQjSu2IGOL5ef3pCECOyTT1lJH5L6RSSVIzGbXS29uZ 8BDcSpZgN1XQAf0Hg5RUYU9LWfEg87RV38FWgWquKCEf0v11YRoKdDKXi2QfWQ9LPB12 RxcQ== X-Gm-Message-State: AOJu0YxtYWm4E4I14/ZrruoAetuRNXDrCQO5ddo8M9PBDSiB56SCCOAW 0rjE2uUlIY92X4siJAV/imfL83esxT6nQmppLLfX3FmO1V2EqJTNkFOPM8l7/E9A0FY+VyQ+gAI B X-Google-Smtp-Source: AGHT+IFcsraeTBqPQxNuI6yzv20lYVGH9/jd7ZncftZGiTWWa5mMixsZf6rLps4GzhzSiu2UNY7rUQ== X-Received: by 2002:a05:6000:2a7:b0:362:d382:2569 with SMTP id ffacd0b85a97d-3677571c841mr4911201f8f.44.1719912407081; Tue, 02 Jul 2024 02:26:47 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0e12d7sm12654967f8f.51.2024.07.02.02.26.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:46 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 60/67] hw/sd/sdcard: Add spi_cmd_CRC_ON_OFF handler (CMD59) Date: Tue, 2 Jul 2024 11:20:43 +0200 Message-ID: <20240702092051.45754-61-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philmd@linaro.org; helo=mail-wr1-x432.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-68-philmd@linaro.org> --- hw/sd/sd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 08fb3cf9d3..31cebe609c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1647,6 +1647,12 @@ static sd_rsp_type_t spi_cmd_READ_OCR(SDState *sd, SDRequest req) return sd_r3; } +/* CMD59 */ +static sd_rsp_type_t spi_cmd_CRC_ON_OFF(SDState *sd, SDRequest req) +{ + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1750,9 +1756,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } break; - case 59: /* CMD59: CRC_ON_OFF (SPI) */ - return sd_r1; - default: qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); return sd_illegal; @@ -2330,6 +2333,7 @@ static const SDProto sd_proto_spi = { [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {0, sd_spi, "READ_OCR", spi_cmd_READ_OCR}, + [59] = {0, sd_spi, "CRC_ON_OFF", spi_cmd_CRC_ON_OFF}, }, .acmd = { [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, From patchwork Tue Jul 2 09:20: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: 13719283 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 AC7FFC30658 for ; Tue, 2 Jul 2024 09:27:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZn3-0003WE-N9; Tue, 02 Jul 2024 05:27:10 -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 1sOZmt-0003RQ-2M for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:59 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZmo-0001ab-W6 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:26:58 -0400 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-52cd87277d8so4045842e87.2 for ; Tue, 02 Jul 2024 02:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912413; x=1720517213; 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=h18ZtpFi+1EoV+so/iHct3tNt9L7cd1pp1ExoGu8rMs=; b=C2GxE5xuqfGYHJyRLMvWg5Tq0e66WahRs68NIRafEyj3Hx1uLoHjmBQwsKPdC9Qksu +p4VaNYoTCIK/qoyqBOot/roZi2fL/tCMMzcw9IturaXoYSaK3SNX7jMrI/0EBdkNHjp knaqsQfjx61J4dh3koHtZBh1Lgzlhg7+RpmdX6uqhAk1LgeTh6/yD99RHXol0V0AjCDo SJB7mtehNfDfn7nrXCdELyzXU5DDciBcOX2o1w+D08e6nm6UCbOiN3/VMtbsH/gBKxSz keCjXLCtrsdbxm1sDy4pvDgyqM0EmQvWekMnhqcpg+cd8L2M62AnJHqly6SBMQgMPPyt OlLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912413; x=1720517213; 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=h18ZtpFi+1EoV+so/iHct3tNt9L7cd1pp1ExoGu8rMs=; b=L3J5CoqT9kdprcdISIBDQwnRPZtx0qCDNtjY3aZz94lRq9HOAl/dT0/6qdf9ic4UV4 remy7i8V6sK2Blu/iv3PM2UJD3aNMT6kIuIF2Cxlvvbltckfqx2zYcNM6f/0sB750sk2 LdTC/Uqeu5uADKvZAx5t7SfihJrwht6BnMZHFN/5/k20R4K5QJIRj4t3i4Kw3YBPYLrK GMt263DHjiJ+7SHFc0R+qinISvsCZ31g5buvLGf723NGqj1wQ2hhQqUmckRfzzq6LMka SFZl5z76wXS4XYjXt739nrZoGoKUlUGV4K654JMXgLXXr1xXAmN3OpO421s3RNe9+4ys uDqQ== X-Gm-Message-State: AOJu0Yz5EpJ8tT/QvsrBiMPmYI42Ij2LK6Wqw+KkOPWQifSrVobQuXQU kEEs2VokB3nM2s5IlF+WBj56ZPzZsXUb2SovaVJeKqf6bNEL2G9sRIVPGokSIWNUfnLvbULBMuu m X-Google-Smtp-Source: AGHT+IH95KeFwQt41rkKiFODOChYMkaC8QROLUSPjYZG8CzeWR5COP9wgNYXHpJc12qPd+0TvJFPxg== X-Received: by 2002:a05:6512:6c7:b0:52c:e16e:6033 with SMTP id 2adb3069b0e04-52e826513edmr5820126e87.2.1719912412816; Tue, 02 Jul 2024 02:26:52 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0d9b1dsm12716474f8f.42.2024.07.02.02.26.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:52 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 61/67] hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6) Date: Tue, 2 Jul 2024 11:20:44 +0200 Message-ID: <20240702092051.45754-62-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12d; envelope-from=philmd@linaro.org; helo=mail-lf1-x12d.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-69-philmd@linaro.org> --- hw/sd/sd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 31cebe609c..fed95563b8 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -258,7 +258,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) static const char *sd_acmd_name(SDState *sd, uint8_t cmd) { static const char *acmd_abbrev[SDMMC_CMD_MAX] = { - [6] = "SET_BUS_WIDTH", [13] = "SD_STATUS", [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", @@ -1653,6 +1652,18 @@ static sd_rsp_type_t spi_cmd_CRC_ON_OFF(SDState *sd, SDRequest req) return sd_r1; } +/* ACMD6 */ +static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + sd->sd_status[0] &= 0x3f; + sd->sd_status[0] |= (req.arg & 0x03) << 6; + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1777,18 +1788,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 6: /* ACMD6: SET_BUS_WIDTH */ - switch (sd->state) { - case sd_transfer_state: - sd->sd_status[0] &= 0x3f; - sd->sd_status[0] |= (req.arg & 0x03) << 6; - return sd_r1; - - default: - break; - } - break; - case 13: /* ACMD13: SD_STATUS */ switch (sd->state) { case sd_transfer_state: @@ -2390,6 +2389,9 @@ static const SDProto sd_proto_sd = { [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, }, + .acmd = { + [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, + }, }; static void sd_instance_init(Object *obj) From patchwork Tue Jul 2 09:20: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: 13719299 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 98B54C30658 for ; Tue, 2 Jul 2024 09:29:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZnD-0003lE-BF; Tue, 02 Jul 2024 05:27: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 1sOZmw-0003U1-Nn for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:02 -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 1sOZmu-0001ap-It for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:01 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3627ef1fc07so2285135f8f.3 for ; Tue, 02 Jul 2024 02:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912418; x=1720517218; 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=s9keY/jFkvIiFyvDvTcECImv8SUtBS1LmlJu/B1CPmg=; b=y/sFqRp3U2tafWxzAb45mUtjulRJX7UbH86PRxqwNjIeAYb//htCIfCOjkK4jHupNZ j5XPeGsyEe0HRg5ZXnyvJI9AXT7xIku2vSCgL3Gz1HiFLEydWtpRbTjyRvzlmW3b84UP 6CNDiGpzDRYrPSeFSjePp1E/nsqf/oEXnCA+Zxr34Vj/azRwI8C652wNyJmdcoHf2vm3 jWaobB1E4tcsFvELVwJzgf79gKnC+OYCQR0QkFkOxh5oUm4gLw6abeaUhbIutbDfWpuX dhitcGDEjg7rjBjrmYKb2WzRYnpaNmpqrONFHXnL7uEOfNtPiuWnhwa84Q5qyukpVvIl fu9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912418; x=1720517218; 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=s9keY/jFkvIiFyvDvTcECImv8SUtBS1LmlJu/B1CPmg=; b=SLz8BuWS8/VIlS7rv7xwiE3F55GJYwSI+beER1acX4giGxsKmV5PiJbWHa29VvyYuL wN6VwAKe8Rdje8RC5+AjAYhFNNTlUm4ArCPu6EEZQ3U7ef/CVVbnXfppvgLI2t1274T5 Bv4g5hyZ4mef2l/5ts7XyKGn9zEEeaxHI8KTEPLt/kf+5QrVDQ0mJxRvaF/PE/rwsVt4 XBqBNFxgV+RH4i2M+VwjBftfkFPY9d+zpX2nr2BUpp4S4AkAhDoeJN/iU+68n4e5wrun crgrHOoyPAp27MCOw++ZuEQkWhALsOjm5j0GF+B6EQPEcVj17IvLQJHiTpJgBYoekMT4 p2aw== X-Gm-Message-State: AOJu0YzzWVgSRHG5t9yntbJxmX7d5f2FTqsCC2o9XRxD/fr3nzoVrSN9 kkxogalsxxxvUurixGyXZmAWzEj50xpltVzB08giSnTjQTgB5hnt9Atm2qZCEwpT7DJAj+3AniL 2 X-Google-Smtp-Source: AGHT+IGvxkxSk8Eegssxrv4wxbRqzr9HwIlRLTM5alQnUdx1p6tHLij3oCUWb8vkhCg+VxgLL3vWxA== X-Received: by 2002:adf:cc81:0:b0:367:3b0:f8f6 with SMTP id ffacd0b85a97d-367756c7313mr4734925f8f.36.1719912418576; Tue, 02 Jul 2024 02:26:58 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0d9b1dsm12716767f8f.42.2024.07.02.02.26.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:26:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 62/67] hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13) Date: Tue, 2 Jul 2024 11:20:45 +0200 Message-ID: <20240702092051.45754-63-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-70-philmd@linaro.org> --- hw/sd/sd.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fed95563b8..8b31e0b41c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -258,7 +258,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) static const char *sd_acmd_name(SDState *sd, uint8_t cmd) { static const char *acmd_abbrev[SDMMC_CMD_MAX] = { - [13] = "SD_STATUS", [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", @@ -1664,6 +1663,13 @@ static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH(SDState *sd, SDRequest req) return sd_r1; } +/* ACMD13 */ +static sd_rsp_type_t sd_acmd_SD_STATUS(SDState *sd, SDRequest req) +{ + return sd_cmd_to_sendingdata(sd, req, 0, + sd->sd_status, sizeof(sd->sd_status)); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1788,18 +1794,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 13: /* ACMD13: SD_STATUS */ - switch (sd->state) { - case sd_transfer_state: - return sd_cmd_to_sendingdata(sd, req, 0, - sd->sd_status, - sizeof(sd->sd_status)); - - default: - break; - } - break; - case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) { case sd_transfer_state: @@ -2335,6 +2329,7 @@ static const SDProto sd_proto_spi = { [59] = {0, sd_spi, "CRC_ON_OFF", spi_cmd_CRC_ON_OFF}, }, .acmd = { + [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; @@ -2391,6 +2386,7 @@ static const SDProto sd_proto_sd = { }, .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, + [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, }, }; From patchwork Tue Jul 2 09:20: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: 13719311 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 71D8FC30658 for ; Tue, 2 Jul 2024 09:31:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZnF-0003x3-QB; Tue, 02 Jul 2024 05:27:21 -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 1sOZn6-0003bV-FZ for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:14 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZn0-0001bS-Hn for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:09 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-424ad991cbbso30465105e9.0 for ; Tue, 02 Jul 2024 02:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912424; x=1720517224; 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=+J0uE60QAC1qoAu1BGNiyLRNnbj4AKJfrIlOAls69nY=; b=d1RkojE2GZXXd0dT+7G/E4XwvI4oT5mW4uRxKYqvoHIGLnryxg/cI7H13mpMYUDCZY tJN4nPUXz/gazASCoquH8OSgSW3htcyW4fw4b5JMhsJTu10q0yTcZTVmHwZBM6i+UWhk B5q6QJnU81uGnPHyEXgvPOrnYWScTEOwD15es6TM49L/gxCmUpltoN35rZ7qemZxqTup CXw9QJ4i9tIwu1kJ/8iHZinGylDUPYeiMq/fOBu3Sz01e3was1USCaV/Tu9MeRdocVa2 prTN9zVTeZNTjB0SAtvpaBePe2ZVoiYKAPzZ+4kkFV/Byj1nl08m+CwnBqSk1ZSEeaUX v/qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912424; x=1720517224; 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=+J0uE60QAC1qoAu1BGNiyLRNnbj4AKJfrIlOAls69nY=; b=Pf7mm81Khyk5JcjPaKDsgRWHeiIW0gsKL2poHYTtavQLyDJnYHOdLFT8SMvYK/Bcim UIiJS8w2i5d3SuhyX9EEn+Q8U6YqU4g68WF0wrujXWen7oo6RrHJZiTuQEVa+DUvKRSN s4luGLZPEylgCykCvGVpwkXbWWt21uxE3RgKAvMxWKDHL0Jbbg7xeIX2hzYUxghN70vJ SV1LvY09MirPZkQhB0czYM5uUIXulWjvLOe4KNJIBWRBdcG++OlWaltFsqGLZnK08//9 TnjuFuZCLbBhO+04gMI/rpfTUg+IGAuma9cbZJFT1FKUkiYc8UlE9COBDjOVWJoKnvWS EYFg== X-Gm-Message-State: AOJu0YznzEaRBKBY5+u/SdW2y+K0az5Zb5ozOlwWr0ZTjlDhtWatjrzy OGNk818iVjk03h2WemDQGZdIGAcTCxMHJ0kUWsIIZMzr3E4isBNUf1rFvZlycoeufz46VhfTCnq h X-Google-Smtp-Source: AGHT+IE0GNWZsLo+UWrWMvHEuKZhvhr4acQ+G6U+ZaNdBoiiSKAWSE4s9We1O8QPZjHSVpHLwhj8HQ== X-Received: by 2002:a7b:cd92:0:b0:425:781b:9802 with SMTP id 5b1f17b1804b1-4257a02b746mr53594915e9.12.1719912424299; Tue, 02 Jul 2024 02:27:04 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b099c72sm188322485e9.37.2024.07.02.02.27.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:27:03 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 63/67] hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22) Date: Tue, 2 Jul 2024 11:20:46 +0200 Message-ID: <20240702092051.45754-64-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-71-philmd@linaro.org> --- hw/sd/sd.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8b31e0b41c..6e9ab92a1a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -261,7 +261,7 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", + [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", @@ -1670,6 +1670,13 @@ static sd_rsp_type_t sd_acmd_SD_STATUS(SDState *sd, SDRequest req) sd->sd_status, sizeof(sd->sd_status)); } +/* ACMD22 */ +static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS(SDState *sd, SDRequest req) +{ + return sd_cmd_to_sendingdata(sd, req, 0, + &sd->blk_written, sizeof(sd->blk_written)); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1794,18 +1801,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */ - switch (sd->state) { - case sd_transfer_state: - return sd_cmd_to_sendingdata(sd, req, 0, - &sd->blk_written, - sizeof(sd->blk_written)); - - default: - break; - } - break; - case 23: /* ACMD23: SET_WR_BLK_ERASE_COUNT */ switch (sd->state) { case sd_transfer_state: @@ -2330,6 +2325,7 @@ static const SDProto sd_proto_spi = { }, .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; @@ -2387,6 +2383,7 @@ static const SDProto sd_proto_sd = { .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, }, }; From patchwork Tue Jul 2 09:20: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: 13719292 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 23699C30658 for ; Tue, 2 Jul 2024 09:28:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZnE-0003tx-Ak; Tue, 02 Jul 2024 05:27:20 -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 1sOZn8-0003de-3y for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:14 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZn6-0001bf-Bc for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:13 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3636c572257so2884571f8f.0 for ; Tue, 02 Jul 2024 02:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912430; x=1720517230; 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=PRpXZ/lTgoptLk88HU8T9HvMCsCj/dqSxIEhw3vh1zM=; b=lswc24F04AUHre/zz29IdQAuPV8CngBhD2htQO6DLp7AS1uRHpZ85S5lLKrx/o7KC2 0T2z6BigeoMCxRScna7wPad7LlAfHaQwStHQjpklPtTIfK6ee+N+o900qFwvS11Q8dBm vDZphwwlbR+KEke7/riD1CdbSGTf6Q7Dps6/nvvfOFoX3eWZ2GuPjxMLsPbwL0zfryKm ynLzAE37DSjk4o+As1rSz++J8xyQkJaoUahVTclZ1ROUs3ISA+cMtUYtXeRvlnV1180/ 9nu4oigWtxi68Ad7u1XbgO8W1MZrrvgIppnLZeNmr6z8TH583ORMOGgtQRUnX4iqwERo Ir9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912430; x=1720517230; 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=PRpXZ/lTgoptLk88HU8T9HvMCsCj/dqSxIEhw3vh1zM=; b=N4ODmxOmdL0ruQNaVva3gTTjDdZOjZ+ui1qkHUVuGVGo/2NqfA5FPY7beQ4a3TXIdJ POLqzJ557SBdIx9rN0jBQTt93qnjpMHciiZiTQpX+7hwpIpzTdGKP1CoW6Oa3EZzeEZA YLBONXmcMtoN0CVn9E2nqi9AKQTKekV5Gq2pQcaooUVYDc1WZ1ui6Ma2sDkdmaS6aQFC WpDXxlihWWIRdAN91sgyevSQaDZlncs1JvXoMwPOl/8JBSIEWs3bqijHxSOo7YbzgF3e iCihcD7eUpykAEtZhHFFZsS2s/147mPQPvA8cYLGRl9g+I/D9VScEF1N7dcTIeXAgU7S 68kQ== X-Gm-Message-State: AOJu0YwSnS7nWN1GSIYfIlGz9R170VJBOyo0N7e5CMey1yNyrE+Yt4Fu T6Yv90sWg1GVCHWOzPmb2AMicZYeok5m4QrKl9kTkyCHE/oEzP7Y26KKb5fzNz2qgrUzsk9/drG m X-Google-Smtp-Source: AGHT+IEZXEHap4xri+I5Xb4g8doNQkjYmzkHuzKPHx4ovB7KZ/l44wn1OaeLXHLBQiHiuQw0QnGMCQ== X-Received: by 2002:a5d:6d04:0:b0:367:4dce:1ff4 with SMTP id ffacd0b85a97d-36775699516mr6639342f8f.14.1719912430016; Tue, 02 Jul 2024 02:27:10 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fc412sm12724646f8f.70.2024.07.02.02.27.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:27:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 64/67] hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23) Date: Tue, 2 Jul 2024 11:20:47 +0200 Message-ID: <20240702092051.45754-65-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-72-philmd@linaro.org> --- hw/sd/sd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 6e9ab92a1a..c56790f091 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -261,7 +261,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", @@ -1677,6 +1676,15 @@ static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS(SDState *sd, SDRequest req) &sd->blk_written, sizeof(sd->blk_written)); } +/* ACMD23 */ +static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1801,16 +1809,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 23: /* ACMD23: SET_WR_BLK_ERASE_COUNT */ - switch (sd->state) { - case sd_transfer_state: - return sd_r1; - - default: - break; - } - break; - case 41: /* ACMD41: SD_APP_OP_COND */ if (sd->state != sd_idle_state) { break; @@ -2326,6 +2324,7 @@ static const SDProto sd_proto_spi = { .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; @@ -2384,6 +2383,7 @@ static const SDProto sd_proto_sd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, }, }; From patchwork Tue Jul 2 09:20: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: 13719306 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 F41F0C3064D for ; Tue, 2 Jul 2024 09:30:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZnK-0003yx-Fn; Tue, 02 Jul 2024 05:27:26 -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 1sOZnH-0003xX-Lp for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:24 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZnB-0001dk-Re for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:22 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52ce6c8db7bso5944624e87.1 for ; Tue, 02 Jul 2024 02:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912436; x=1720517236; 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=lKLmaY+ITMzDV6voXczq+aWnHEY0UJpGnuJKCBTpGi4=; b=IYmr69RpYj5bWzrFg7bj+sneEJYkSHz2PcPccAcVZGLVOGRcyMZvNlP9nYI4hTtNAd hant+LvxeYEzX9qEYun/BTchsfcOdIMkcoBp+xI1oL8+CS2ETr94HzGfHCREMqiNoMlb vm4AkuOi8IjSIDkE6SaNgClsO+mlBb8pa47VsZ/NJ1uTX2RB3lANciIZifa7qx3SjF6W zhFuic1DhVRmdAwPgxmbT1ZEzxz7C3LdFzjwGHPNrSxZ9xueK9qTbNtcNSZu0HwGa5Gm iLJ5E2+s5bP3JDfuCkj6mL7wdccCfGpOU4O4yEqdikSqSX5fJP95JWe28a0A0fV2a1Sv H7pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912436; x=1720517236; 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=lKLmaY+ITMzDV6voXczq+aWnHEY0UJpGnuJKCBTpGi4=; b=R3cBaAwKMMNImi87X8N43wjoPC4344ysL0NFuT8kjVCBDr/318QYzWVwlmjUflU2bh 0jhDnjQqESD3VNwg7h5GYskHzn0sY9ugeb5B2nxf0qsTEHESs05aBmiytnmRW7XIlD0U 0X98fyeNtDOkGCp8VQIjFc3fNX1vCzOx9O79Z0uPM8K1QBW5oI2CHqUXIM+eF0aL5zU2 vTah4Bh1ObMrytG61khbzRRpJAM5oo+AU02fj+EvgI+6g4BtndXwTcJlZjFnS0nr5YUT st6o5LqsHeyuAnSSQzkRUVHIGEDtAbDGm+ph3ICP5Q2OGB9VmQ5QONn+aC3txnqE1CQl 6WIw== X-Gm-Message-State: AOJu0YwayrY0pW86as3U8ppaqxx+g8aLpQeNQ/Y/VkH0LRTh0F3utKXH 7NkOOTSbcbx7l909ygxvAAnotxPE0jOq8Tg1RCXNs93g2sYBKYOuXVRnLWvPJbYS5GZO6fc2mey U X-Google-Smtp-Source: AGHT+IH3kMT2O5M51MLz3PZLAULw6Lx4xthbIJ64f2gGfGLBc8vKJc+okJg0iAQtuWI1V9ZHAreJ9g== X-Received: by 2002:a05:6512:12d1:b0:52c:e11e:d493 with SMTP id 2adb3069b0e04-52e8267b901mr5492188e87.26.1719912435873; Tue, 02 Jul 2024 02:27:15 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b0c1018sm188560715e9.40.2024.07.02.02.27.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:27:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 65/67] hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41) Date: Tue, 2 Jul 2024 11:20:48 +0200 Message-ID: <20240702092051.45754-66-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=philmd@linaro.org; helo=mail-lf1-x129.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-73-philmd@linaro.org> --- hw/sd/sd.c | 82 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index c56790f091..207deb07e6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1685,6 +1685,50 @@ static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT(SDState *sd, SDRequest req) return sd_r1; } +/* ACMD41 */ +static sd_rsp_type_t sd_acmd_SD_APP_OP_COND(SDState *sd, SDRequest req) +{ + if (sd->state != sd_idle_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + /* + * If it's the first ACMD41 since reset, we need to decide + * whether to power up. If this is not an enquiry ACMD41, + * we immediately report power on and proceed below to the + * ready state, but if it is, we set a timer to model a + * delay for power up. This works around a bug in EDK2 + * UEFI, which sends an initial enquiry ACMD41, but + * assumes that the card is in ready state as soon as it + * sees the power up bit set. + */ + if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { + if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { + timer_del(sd->ocr_power_timer); + sd_ocr_powerup(sd); + } else { + trace_sdcard_inquiry_cmd41(); + if (!timer_pending(sd->ocr_power_timer)) { + timer_mod_ns(sd->ocr_power_timer, + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + OCR_POWER_DELAY_NS)); + } + } + } + + if (FIELD_EX32(sd->ocr & req.arg, OCR, VDD_VOLTAGE_WINDOW)) { + /* + * We accept any voltage. 10000 V is nothing. + * + * Once we're powered up, we advance straight to ready state + * unless it's an enquiry ACMD41 (bits 23:0 == 0). + */ + sd->state = sd_ready_state; + } + + return sd_r3; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1809,43 +1853,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 41: /* ACMD41: SD_APP_OP_COND */ - if (sd->state != sd_idle_state) { - break; - } - /* If it's the first ACMD41 since reset, we need to decide - * whether to power up. If this is not an enquiry ACMD41, - * we immediately report power on and proceed below to the - * ready state, but if it is, we set a timer to model a - * delay for power up. This works around a bug in EDK2 - * UEFI, which sends an initial enquiry ACMD41, but - * assumes that the card is in ready state as soon as it - * sees the power up bit set. */ - if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { - if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { - timer_del(sd->ocr_power_timer); - sd_ocr_powerup(sd); - } else { - trace_sdcard_inquiry_cmd41(); - if (!timer_pending(sd->ocr_power_timer)) { - timer_mod_ns(sd->ocr_power_timer, - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - + OCR_POWER_DELAY_NS)); - } - } - } - - if (FIELD_EX32(sd->ocr & req.arg, OCR, VDD_VOLTAGE_WINDOW)) { - /* We accept any voltage. 10000 V is nothing. - * - * Once we're powered up, we advance straight to ready state - * unless it's an enquiry ACMD41 (bits 23:0 == 0). - */ - sd->state = sd_ready_state; - } - - return sd_r3; - case 42: /* ACMD42: SET_CLR_CARD_DETECT */ switch (sd->state) { case sd_transfer_state: @@ -2384,6 +2391,7 @@ static const SDProto sd_proto_sd = { [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, + [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, }, }; From patchwork Tue Jul 2 09:20: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: 13719305 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 4EFB1C3064D for ; Tue, 2 Jul 2024 09:30:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZnP-0004Mi-4Y; Tue, 02 Jul 2024 05:27:31 -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 1sOZnM-00048m-S7 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:28 -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 1sOZnH-0001e3-Tu for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:28 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42562a984d3so27653545e9.3 for ; Tue, 02 Jul 2024 02:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912441; x=1720517241; 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=PTfJi1XXPwjhNkGNkal4TzGgTuML6EnycC4lcNZtgo8=; b=CBwQ0OZkk7/tFY46puxOCIC0bBA6X4svmNXDYNblC/AyxQCbHLoPWQNQiA/Pe02ljW lsPpBHSOh10gZkftO4eCU+Bmc0bzFi835FXF3tJFfUjAcxOCWffpFSO2fwrnPT3AEOHJ iS2n6yuf8GIgBqXd3ytRY6Vxwn+I02sk0lrEB/CyILOrwVhD1eVAPM5rDm6YnGa7/zN0 tGIQCBQHEa9y4TQ1jyhTuK8ItjBILaJHqeyYJ1nX+HqtW18D6DVhl6qUviINY59v6NiS uMSLsImFyBdchsS00hQW+/vsE4DV/DpDQDGW1xPweoHmdqrIE73mhO4KPQjK+id1QXnO i1VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912441; x=1720517241; 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=PTfJi1XXPwjhNkGNkal4TzGgTuML6EnycC4lcNZtgo8=; b=vgTkINFTR2KJ5TyE4VYJq8KkCT6DGaq93O5pObsi05OGowGmy72qRE1y2uBlG48fnv Xh/XqHZ6vQApTtMZZBxy9y+8cwU7YwO5DoxBno5ZQUJdUCSrkskpoW+my9j5uzYlKoIG pF0SB5xpYb0LJJGHAp41f3QIozwrJaeE06oLNl9Q13UFl+Xg1bL3E3ifI1inNsMNgPZf zXHsmzE31MqNWEDLXLdWDPCD+8judOHbgXfGmL7FIAuUHl9IXQN/zjUJRrot19Q7LcBb TCUyubxZLGjsIF+FsLl7nWpoRApmd/BfVe9Doog9vEVXYEdO/f41Nieu7spU9ZkF7mi1 I9CA== X-Gm-Message-State: AOJu0Yy7LhZZ4ViGIhnu9PNvWDD1M6VIqVJquduwLdlVqAC2Lvwk8S6L X9tzo6AoRxScuZ2rhPhEMGkF4IFSFav+B46Y4GW4nFx5C26h2SZe7IhF5P5rUv0p+/+27nXzfcL y X-Google-Smtp-Source: AGHT+IGOeRJgRSWkn3ykXy3d50nETswJ4Qnpj1U/l3bx2mrOEKV/8YAQpnLh1+4DPJTm7v0UXLQmew== X-Received: by 2002:a05:600c:3b07:b0:425:6979:9b5f with SMTP id 5b1f17b1804b1-4257a009c28mr54331655e9.6.1719912441249; Tue, 02 Jul 2024 02:27:21 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257d0d38bbsm106943455e9.38.2024.07.02.02.27.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:27:20 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 66/67] hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42) Date: Tue, 2 Jul 2024 11:20:49 +0200 Message-ID: <20240702092051.45754-67-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-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=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-74-philmd@linaro.org> --- hw/sd/sd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 207deb07e6..698d64d2cb 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -261,7 +261,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", [54] = "SECU_spec", @@ -1729,6 +1728,17 @@ static sd_rsp_type_t sd_acmd_SD_APP_OP_COND(SDState *sd, SDRequest req) return sd_r3; } +/* ACMD42 */ +static sd_rsp_type_t sd_acmd_SET_CLR_CARD_DETECT(SDState *sd, SDRequest req) +{ + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + + /* Bringing in the 50KOhm pull-up resistor... Done. */ + return sd_r1; +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1853,17 +1863,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 42: /* ACMD42: SET_CLR_CARD_DETECT */ - switch (sd->state) { - case sd_transfer_state: - /* Bringing in the 50KOhm pull-up resistor... Done. */ - return sd_r1; - - default: - break; - } - break; - case 51: /* ACMD51: SEND_SCR */ switch (sd->state) { case sd_transfer_state: @@ -2333,6 +2332,7 @@ static const SDProto sd_proto_spi = { [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [42] = {8, sd_spi, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, }; @@ -2392,6 +2392,7 @@ static const SDProto sd_proto_sd = { [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, + [42] = {8, sd_ac, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, }; From patchwork Tue Jul 2 09:20: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: 13719322 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 D3838C3064D for ; Tue, 2 Jul 2024 09:33:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOZnR-0004aY-0N; Tue, 02 Jul 2024 05:27:33 -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 1sOZnP-0004Mn-4P for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:31 -0400 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOZnN-0001ei-Co for qemu-devel@nongnu.org; Tue, 02 Jul 2024 05:27:30 -0400 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2eaae2a6dc1so51865291fa.0 for ; Tue, 02 Jul 2024 02:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719912446; x=1720517246; 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=iTcgACkHrUOF7g7c1kRdnSX6PuMfUGO+Z91pQ+u8tPQ=; b=z46SGOouEiNw6H4liYi/Cz1aZzyjoTbeT4AxoY+XhlER+Lllf1Ob6FsSpvWsNSsX0j 2IzHoVsEUFc+Cf5f+0NyfS7YhAL0AnNjAc1zJcLGOumr4vsl35AkzlemTqJl2WSg5DCo bPcbonWMZSUHdHFDhzzhL5WXzIHoLpcTFxw6RCvuusFKdbjvOziHR5LCh2i6X+Jz4o19 FxbZJ+nOVUve2m7ZoMpwTzQuJyV/E5spcgphVbEywHzqo9JhvQfnZnrWJ63erFFO1fL4 LIu1PH7Ad/yi+YEYqtB/WchGOvES6Ku6iP3oKaRh37L6m9Y1xQnH/s2xhlh/G1Fmcafq bayg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719912446; x=1720517246; 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=iTcgACkHrUOF7g7c1kRdnSX6PuMfUGO+Z91pQ+u8tPQ=; b=dknwdJniPTG3jiJe8fVnUdwx2Cx2dM8uOmJ59C96ExnqhPBksYKvNNfY9rTKl4R04n RRuw2ij9sgeWb+4UwGu12OworXjrVegwrTIqiSiKoIsISUteSkygL1Wc3Yw/To+YfQZT G+cBznc4VYO4I1HAlFc7T8enmkzMY4HLr1v2A/vn9PHow8N9QGOI7hf1LjlzL4cfbgEf xPYtTvXtyPHT7/iw4Sok/2bG4KvuYMwsbzJ4nVGvF++OIDaHJ4TM+/YlhZjds5qiOim5 zg946if3EZLgQJQUdojDo7COWVZB1921G+FNbXxuJ37udBR8+Y3bve0MN40Y6Qt8PRC/ WvvA== X-Gm-Message-State: AOJu0Yz/Qm174eS9P31ByEcZ/GKI351updZRq7zKTk4W8fli/5vBCM/H MqKTt8pgnTQJxiYwynbJ7VBz2YvgDnBBOhLOw5Ok3ncfpRRxbPAhuMusEMHgSFDQWDUMzdlNAxT I X-Google-Smtp-Source: AGHT+IH3w3f/eED3Us3i4A4VEWmEXfaMAHQqaoOJ5jR83tYA0xsvjDeOhkYJrqY8KCKlY7C1hsDXMQ== X-Received: by 2002:a05:651c:b14:b0:2ec:5488:cc9e with SMTP id 38308e7fff4ca-2ee5e3bbd14mr65967521fa.26.1719912446481; Tue, 02 Jul 2024 02:27:26 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4257d0d38bbsm106947395e9.38.2024.07.02.02.27.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 02:27:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 67/67] hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51) Date: Tue, 2 Jul 2024 11:20:50 +0200 Message-ID: <20240702092051.45754-68-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702092051.45754-1-philmd@linaro.org> References: <20240702092051.45754-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::235; envelope-from=philmd@linaro.org; helo=mail-lj1-x235.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-75-philmd@linaro.org> --- hw/sd/sd.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 698d64d2cb..552957b2e5 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -261,7 +261,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", [54] = "SECU_spec", [56] = "SECU_spec", [57] = "SECU_spec", @@ -1739,6 +1738,12 @@ static sd_rsp_type_t sd_acmd_SET_CLR_CARD_DETECT(SDState *sd, SDRequest req) return sd_r1; } +/* ACMD51 */ +static sd_rsp_type_t sd_acmd_SEND_SCR(SDState *sd, SDRequest req) +{ + return sd_cmd_to_sendingdata(sd, req, 0, sd->scr, sizeof(sd->scr)); +} + static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) { uint64_t addr; @@ -1863,16 +1868,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } switch (req.cmd) { - case 51: /* ACMD51: SEND_SCR */ - switch (sd->state) { - case sd_transfer_state: - return sd_cmd_to_sendingdata(sd, req, 0, sd->scr, sizeof(sd->scr)); - - default: - break; - } - break; - case 18: /* Reserved for SD security applications */ case 25: case 26: @@ -2333,6 +2328,7 @@ static const SDProto sd_proto_spi = { [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [42] = {8, sd_spi, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, + [51] = {8, sd_spi, "SEND_SCR", sd_acmd_SEND_SCR}, }, }; @@ -2393,6 +2389,7 @@ static const SDProto sd_proto_sd = { [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, [42] = {8, sd_ac, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, + [51] = {8, sd_adtc, "SEND_SCR", sd_acmd_SEND_SCR}, }, };