From patchwork Tue Jun 25 07:34: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: 13710741 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 ABD21C41513 for ; Tue, 25 Jun 2024 07:36:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0hb-0004W1-Fm; Tue, 25 Jun 2024 03:34:55 -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 1sM0hZ-0004Sx-GY for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:53 -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 1sM0hX-0003kM-TZ for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:53 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4248ff53f04so13660965e9.0 for ; Tue, 25 Jun 2024 00:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300890; x=1719905690; 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=wcx7yYRM3PiZ4d5mUpewwCNROsxhQ8qYk6qnzFU22vI=; b=VIVVz+6tah2WqfeqZ2rlKCJZf85jNV5owBvqisWraic+RVlJg1sfSp3v2y8NAw42VR BNSX8aqvL4CLAxnQW2jPzTE3K7hThUdZClksvgN/OhOFevVdPS2KAkmqarNtGcMlrWQi x1C9A+MzPSzGSNfxs3wohWKSWtrplF4jcj8BIigDUHwrH6l9UJKCUcmV4Gk0AGXDd2Ii +1krkDEEEB99JhJtIedTBYaF56TWrRNOeEwdSo1MXGVTP1O3I+kz1ewmFxqWkr0OFVOq RmUuCmxNwLBLIl+G6vIZVcioxTot1uMU6gPOSEf36HrsQc2+KohZW2QmYIvwN2kb5EdK 2MLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300890; x=1719905690; 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=wcx7yYRM3PiZ4d5mUpewwCNROsxhQ8qYk6qnzFU22vI=; b=ffNvHdRhGmX72tuLka8cluQ+kRAe+eTyaHrE0uz/dvc30zfPD3bKt6GnWNxiByuR7I bgeuPaPhspNgJnP4mh9xV1idP7JWwQrl0uIsBlarR5WVTef62fheNNn3BnNBt7bnVLPd 36b5WX3XbZ/feVfbw7TreGvK4bLtkoHh57+m4XoAY6avzRpyDpE+xf7fVseAX4NpyqwE QrKFW7GTT2zFpz59pIjE3RxqU7ygCmQZ9krm8F1f55Flf/t9KaN82MAB2Tlrmj2vviPf xS9q5z6ffdcYD6uZr+2gI0O13rt6RoMQQmj2lMTzegMfPoaFppDU663drW3AFsrp9IZK 2qhw== X-Gm-Message-State: AOJu0YyaOOFWv+PWQaU+r2l/Takxz6bmeoIx6oPfW6HaImQ4oDnUo8Xh CBYcicWxzo0CcfB8jjuO8WlqnI1hwTlrflryd41TujySonpp+Adbt2pI9cmmS5uznwC+Qgrjaio + X-Google-Smtp-Source: AGHT+IFZ3RQujMgIOcd1i/ugunHPeymXsSTsdekah51oceNQtA9OZZ+w6h5Ni5ONggNX2e9MNd17FQ== X-Received: by 2002:a1c:7711:0:b0:424:816e:872d with SMTP id 5b1f17b1804b1-4248b95c94emr50128615e9.9.1719300889916; Tue, 25 Jun 2024 00:34:49 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208b3dsm204176865e9.34.2024.06.25.00.34.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:34:49 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 1/7] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte Date: Tue, 25 Jun 2024 09:34:35 +0200 Message-ID: <20240625073441.34203-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-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 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é --- hw/sd/sd.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2df3c28cb7..7fea0afb62 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1081,6 +1081,21 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +__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; +} + static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, uint64_t start, const void *data, size_t size) @@ -1930,6 +1945,19 @@ send_response: return rsplen; } +/* Return true when buffer consumed */ +__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 consumed */ static bool sd_generic_read_byte(SDState *sd, uint8_t *value) { From patchwork Tue Jun 25 07:34: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: 13710740 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 84562C30653 for ; Tue, 25 Jun 2024 07:36:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0hh-0004XB-71; Tue, 25 Jun 2024 03:35:01 -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 1sM0hf-0004Wp-Jm for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:59 -0400 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0hd-0003kj-V1 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:34:59 -0400 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2eaa89464a3so60313641fa.3 for ; Tue, 25 Jun 2024 00:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300896; x=1719905696; 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=MFRKHAqO647KOdwqqDJufJ/DZoqjTVohRrJvslLGVMw=; b=JaFdkVuNjkwxcVhuSofUzbSLP6bLTa8eUJp3tAzdIHzh7VjidthKPCzWVYLr+ACLGt jvEWyLVon0Bb20iCgH20QYWuX0pzvcS67tg4tIh1cjQIXSD/+oof2q4u1qKEnBCm1V6Q vip0msazKJBcfJYLbc84wJdbZhJUCILy8elPALQ3SLnQ0EPJRnLWlULIrFUukfaN+dVG og2kDzyRGfuH+zUVu9I4NpDMN3Ix9k4/VaBhAFVHaJen/hBvnla2d+/S4gUA0xEjWxzl mY+y9Y3Rro0IkTmhZC/y+iJ0G1yTueyrc2o42zrzKUwwfy2l/bUOVdS9Gyj4pGQVVaS0 gurw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300896; x=1719905696; 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=MFRKHAqO647KOdwqqDJufJ/DZoqjTVohRrJvslLGVMw=; b=KQ4dqdaoeyy+B8aMfSX/LgShTDKjvu5LCcDinoce3eGMXY4O7IF+n78aiYWEVefBIv 1xPlQmqjgS5D2KNKOWK7QaxzRo2uAgoz/bdl/myNaUZNCgubcoDQJsVVuL3+fFMr4uGF EQnCrWdk0TaPBXMs9He2DGCPhfCnzwQYA99HGv+fMifp3hz0ZpdFzb+yX+x7y1agfX7y 4RULhMVAvo08JIaHMKynmoQ/qXeIjTgcB+qBdSzKE2N4m6mtiGz5gfF8pbCPoBcqwxZk rzrt/HfUobZR3wOLHL3LflyZyjNhpXxnTcrAsQdjY2+sB7Nday7Elg+tE1TaU/7TArIE E3hg== X-Gm-Message-State: AOJu0YwQtvBqVkyPrnD4kbcOKUY4vIKTjuZKlnEp5KKvxGqP9D0nqWLL f3p59Tyvcs70Q6ubdCv89D+WrunZcyvpQ8vfuYf5hg5Yf2ipXcTWRww9cEdlx6tHmpJEuKb1W1y E X-Google-Smtp-Source: AGHT+IHzyoKWzlJJfBt6rltmTYltKRM5OwQibKHRgMKwPABjCmCOuXhxLCWaYBJ/i4H4up1u4JzwNQ== X-Received: by 2002:a2e:8617:0:b0:2ec:561d:dee1 with SMTP id 38308e7fff4ca-2ec57967b7fmr46632371fa.8.1719300895562; Tue, 25 Jun 2024 00:34:55 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0be818sm200163415e9.15.2024.06.25.00.34.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:34:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 2/7] hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK cases Date: Tue, 25 Jun 2024 09:34:36 +0200 Message-ID: <20240625073441.34203-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::231; envelope-from=philmd@linaro.org; helo=mail-lj1-x231.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In order to modify the WRITE_SINGLE_BLOCK case in the next commit, duplicate it first. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 7fea0afb62..8c30826754 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1437,6 +1437,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 Jun 25 07:34: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: 13710744 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 D62DBC2BBCA for ; Tue, 25 Jun 2024 07:36:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0ho-0004bX-7Z; Tue, 25 Jun 2024 03:35: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 1sM0hl-0004ap-8h for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:05 -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 1sM0hj-0003lI-G8 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:04 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ebed33cb65so57158391fa.2 for ; Tue, 25 Jun 2024 00:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300901; x=1719905701; 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=wK0X2J7xkzuOoEV+SXxI0L9Mdx2I1sNaqE4cl4V+Wxc=; b=M54iHxNN8SiAkNkVpD+eR/6SRzLjI7VrrwRmAlnkT8lvXMnJA3vEAJrOcXbOEDBSnZ xXo0fzjYLS8Dvcyp8HECvlUdIFhsVtw8Z9Ynf1ouwLrXkuQCN69Zxzls/dFBiNyJsXrI bF//SXHnZjSWBV16eYWmXD7b61PTlSXEAbmV/ZhnwfcG8yPeL6kjsKnIUwtWRlrC/PSu 5/cF8DVqzKUremXGJsuXUZKdhyRc8SgKpTnqiu95SfYpgr4V981BiQqPemQuO/9bqrlN 7vTz960Z9ge4jLneELiIKsZXLzMRHZRb2py3neIPOteD4A5Eu56k2Wifsq/TDQWV/kFr qgQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300901; x=1719905701; 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=wK0X2J7xkzuOoEV+SXxI0L9Mdx2I1sNaqE4cl4V+Wxc=; b=D/veaiJVlIfdtUZRynHXt7y0XUAREuEp3uugzTCaNri5zkso+iNmUa2QR21pRwAYp7 phArVbRYuuMthrzboJnzaHgxPeYuRG8+V6hWiJkjiMESf/OEaSXT53smWc/LIIthaD8x ysSvIpijoW2XobeldR8aoTuC5GonqfV46nvg/pyQraC6KQZkhiQ6d/vPe8uxHSynNeeZ S1AYXXBJpAqapMl0RVyqjh5rKc3efcBQ6Uh5KgXlmontEl8Gnm4MH0Nyaixz/i3e4E4y YVk5NrF9yYkxbDcN3ED/LqZa3K5JMU2c8/pNL0NHpJ++UezYJNA1RGgu+TW7cTLfyT97 cHaA== X-Gm-Message-State: AOJu0YxrC1MnOqL3FRbKzANBarIr5CNCQH1qpbf4N58xKuojPq0qiIzc acLmCR06McneRCrM/q+eVjUcehBssnw9RHEzkN7deEx6+4i+H+yOPFQQljlYaU4Dvgn5mjkxPH/ E X-Google-Smtp-Source: AGHT+IGuRSy70bJPO/kwhQjWcT141lShqWP5LKL6mWY1oHOl1qksvHIrcJojUI+iXTXNS8+NyDDyqg== X-Received: by 2002:a2e:9859:0:b0:2eb:f0ed:a36d with SMTP id 38308e7fff4ca-2ec5931d44cmr56284711fa.19.1719300901360; Tue, 25 Jun 2024 00:35:01 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4249e48ad3dsm12591665e9.16.2024.06.25.00.35.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:00 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 3/7] hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24) Date: Tue, 25 Jun 2024 09:34:37 +0200 Message-ID: <20240625073441.34203-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-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 Signed-off-by: Philippe Mathieu-Daudé --- 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 8c30826754..fff4be3ae2 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) return sd_illegal; } -__attribute__((unused)) static sd_rsp_type_t sd_cmd_to_receivingdata(SDState *sd, SDRequest req, uint64_t start, size_t size) { @@ -1446,10 +1445,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; @@ -1459,7 +1454,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; @@ -1975,7 +1970,6 @@ send_response: } /* Return true when buffer consumed */ -__attribute__((unused)) static bool sd_generic_write_byte(SDState *sd, uint8_t value) { sd->data[sd->data_offset] = value; @@ -2021,8 +2015,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 Jun 25 07:34: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: 13710743 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 2660BC2BBCA for ; Tue, 25 Jun 2024 07:36:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0hr-0004dE-PT; Tue, 25 Jun 2024 03:35: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 1sM0hq-0004cz-NN for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:10 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0hp-0003xt-7w for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:10 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3627ef1fc07so3909790f8f.3 for ; Tue, 25 Jun 2024 00:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300907; x=1719905707; 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=VA5f/N1mW7Z/7ENwZP3WQRg2cxqQYBPog8kTusH9efU=; b=GbyCTq02YFrWzrmaf6cniUn+zZ6b3uaVHqN0CzkVeHUEQCs7Jx8JTVfM663+Xa67n6 Wj0BHkPR2d3ypVu81lsh0hdeTY+w2LS+8/EcorXqwOjG8q9A6cgNnfZYisoNqJCU5ra2 MalYVqBwL4A0NkeH4acjDt9ggvg45A0ZUbm1C0XQUXOVsazFERXhKdJNlCUJo1qMhO5/ SGyTab+v4AE18q84pjFXpcmA4TzTpKkF678rom0xrv1sYBbN3DpCluml9hczICvVn0gF sZceInfL3UWWzOZP8ujD9BvqYd+uK2klk6vAVa/CPWlydW/4H6YOkDTZmIAZNkxzVt+h JEmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300907; x=1719905707; 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=VA5f/N1mW7Z/7ENwZP3WQRg2cxqQYBPog8kTusH9efU=; b=tKAbTMW2vpGlDREVO82nVBKEnSgi4mzK3RD5JLVuOwLfSHRUThvxgWaDgxSqDUgJOf JNmFPkcVIc1fn9XPPzP42AMdKowKvpC9z6Bd0KBUAk58AihzpQrg5EYAm1i1LvUfmiVs BmavLKJvl5pz8wIHzlVf29YIOEpNYANPi1PvAafzwfcPdICBJhbiTa/jR18KlSeoupng enq+vPsqdy+PvQOclhRhYXqu0a8a0BP4/RKukwCQrX7p/jLv6Dra4O/m8Q7lZSriwpPG 06C90U0UGqQ9VAQbP7jbK58xQZBkkMjb4GJxrbUG4+78IAjZ4ZDsYR+aF4bxZbrkJz9E CQrQ== X-Gm-Message-State: AOJu0YyFY+uccSsHRSJNuqwROKtm1FyTVY7GUxw4pK8USr8YFyeB+DYr SgnQqFs/ikPqex64sjSdUHfbUG6JqpLau4I8dbZz1TKKKqKpliBYJ1bsCrQQO1+gmnhn6XXQGkQ V X-Google-Smtp-Source: AGHT+IFaV2nELuj9RPYhb56fhfRIckdrkrVT3yqTI6WKrXRVgvMzkG05Mwx5rMBz6Fk6cYJOMxhG7Q== X-Received: by 2002:adf:fdc7:0:b0:360:81f8:698 with SMTP id ffacd0b85a97d-366e96be4dcmr4311067f8f.58.1719300906944; Tue, 25 Jun 2024 00:35:06 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36647e7eb4fsm12112264f8f.18.2024.06.25.00.35.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:06 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 4/7] hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26) Date: Tue, 25 Jun 2024 09:34:38 +0200 Message-ID: <20240625073441.34203-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- 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 fff4be3ae2..9db3b32b0b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1491,17 +1491,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) { @@ -2064,8 +2054,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 Jun 25 07:34: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: 13710737 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 C0A83C41513 for ; Tue, 25 Jun 2024 07:35:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0hx-0004er-Kv; Tue, 25 Jun 2024 03:35: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 1sM0hw-0004eU-62 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:16 -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 1sM0hu-0003yS-Do for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:15 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-421eab59723so39061615e9.3 for ; Tue, 25 Jun 2024 00:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300912; x=1719905712; 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=qb2qfxjBpxYILlILF5IkDh+mD4sc48rfhXmjHKKwuZ4=; b=a7VOfH2EFYw45itsza6Ow8skCBh7gBVitnTzDtjQsS3vddTLfgfvPeWr4LpnMam7rT SagxSnFUxTgSo9+ZvRSL3sSPKO8kSGxOP3mV12JNgVSxpm1le6dFb0YFB07lYrqaExUx ojA3SHJYHLF6jVXBjwV+giS2n7gz1TI0WNaxNQUm1WWZt3nN57H+d7m4uUK3FVsco7lH EuQ9jEO/7WgqJV04UuQGNXnFosiaAkJyQJ0wGHz4nlvwIcrD4Bs4+hGub5ue/2h+K4PV 4GXc8Q3Ckl0Th6jnSsdiwQrW2lZ68BFf9DO+JtisZyn1NidTCf4r1Y9OprMvJ0LSo/m8 eZbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300912; x=1719905712; 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=qb2qfxjBpxYILlILF5IkDh+mD4sc48rfhXmjHKKwuZ4=; b=p+ke/026zrzAlMYVxY7hCMFbSnKfsmpcf6lho76U3OjkvyDfX+n6nP7FAaNK9U4wkA Ksp+rBxPXwFUgvqwHc3P98ZdCRKFqY1wPywsdhspupftTbhRbn4bzsBrNC5yEuQcFD+U Q0TtNVFczGMG9acu1SBUV8aFeynlsBn1ZYiAHYUgzFbJH/+UoF7j9WmKra8UtOsr4oNL PlUbt3aBhPViiY07N+HnejpTIgA3fXnFIBsaG96OMxTxnM1pF/JDT9A9mjgLK02f19rR m2rf7/MZnh/0kPWDfc40nzfjqxaiFqtLFsXoX8jTar5NIdRt1zV4uG0Vg/2EpX88uESI nqdA== X-Gm-Message-State: AOJu0Yzl9Pcizn2btwApiVfOnEhkzEWPiX7qMnxjafeK3c2Xff/CR5t5 5Lxejyb2gvKM6YjOekvnDgmznxZR7rezyydh6Sjox+0BufBT8xTshDPpMrvgWIkd7q8mNB3eJAE g X-Google-Smtp-Source: AGHT+IHjRWkYjBp9nOHPeREXvDg6hjhWtRfLknO3y12fQE4OPz7NhFTF+03Vve11pSmGoeoLGtaLVA== X-Received: by 2002:adf:e6c6:0:b0:35f:2725:f6cd with SMTP id ffacd0b85a97d-366e4f0bf67mr4989189f8f.59.1719300912648; Tue, 25 Jun 2024 00:35:12 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36638e911b8sm11991956f8f.62.2024.06.25.00.35.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:12 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 5/7] hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27) Date: Tue, 25 Jun 2024 09:34:39 +0200 Message-ID: <20240625073441.34203-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-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é --- 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 9db3b32b0b..b0f29034c0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1494,17 +1494,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 */ @@ -2072,8 +2062,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 Jun 25 07:34: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: 13710742 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 D5977C2BBCA for ; Tue, 25 Jun 2024 07:36:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0i3-0004pC-MQ; Tue, 25 Jun 2024 03:35:23 -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 1sM0i2-0004oi-5h for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:22 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sM0i0-0003zQ-Ad for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:21 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4218180a122so39272015e9.1 for ; Tue, 25 Jun 2024 00:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300918; x=1719905718; 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=pU2MPUHXpvnSU498pOire3lRQStnRBiAG9dQFz8I0B4=; b=azfw5UmsPcTm5jDYxm4cB5pZsdyyIz0YaRLI9eAUrOkLyijjFJG7fYnhJFOhG9gAWu VlbMKTyUjXXtWLYeGFyDm6O0CuUuECt6BzQJ0bFKhErq8mCBk5YTvd/bmZJDnWdCWrk5 j1j/A/wMHusYTGRPZlepDTUpQqSUOgBMSFBNXbfjsEzrOcRJZkg9e5OtqhPM5Rui8urh 8qE9NZDrloMCW3GnjrCA8aoYTuUJFbf+PmbwwcupElAcHggDUwR8xAXWb1nl2KgT/Mxp lBZ53dvHSW5zVNUmsaO8rl4Arxs9CCpWdKYnlHrcgewf5AnxZLtFSjv6yEDMsHMTXYBG +IZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300918; x=1719905718; 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=pU2MPUHXpvnSU498pOire3lRQStnRBiAG9dQFz8I0B4=; b=d/ApCp6LQwuxHkdnC3DFNSdYU4vnuRTOZSl3Rm0fpj+gvUw7E/LRhBWnM3UPrK+P4q LjjWhhgI9HrySFuXC2hHVGpxLo3wd52YlJLZmd5sBUvwPnOOaQ9Sg+CWI/dXgQI74v2E yOn8E26J50D7PeL6iSw4amkbPUw6U5hQh2JexasGEPAt256EQyyI133Q9m7GkQxCe5bd LnsB+PDaf9RhgY650ior02dkiWw/BuqwHTsQCqwP4Tf8xkacoXQ9ITUD4IJVZqSgmAbL tRo8hnfDlHH55HD8UFoMWmxHjuVowQZRSBhcJL64+fR/n8TPayERDpDkoQQUIf6lP3Ye P9sg== X-Gm-Message-State: AOJu0YxLYYGs09sClvRfDBJC8bNAN0kQk0u+ZOdnZepRoVKBSoNh0tHX Q29W8FgkJ2ytOjeJR95YVkL60AIMYv92QDTxO+9j/6tYQu3DkU3YPcUQCSL9IsKKUDASMuPPhbT 0 X-Google-Smtp-Source: AGHT+IEvOrjnqYHK4x9lighrOwd4xp9d50/saPkcR3jqnJCldYnuNiBh3hpEtASeG+ZnLJPNG1JG7w== X-Received: by 2002:a05:600c:4fd0:b0:424:74ed:dbfc with SMTP id 5b1f17b1804b1-4248cc66abbmr49931405e9.35.1719300918307; Tue, 25 Jun 2024 00:35:18 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208b4asm199313845e9.29.2024.06.25.00.35.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 6/7] hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42) Date: Tue, 25 Jun 2024 09:34:40 +0200 Message-ID: <20240625073441.34203-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=philmd@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index b0f29034c0..82b44b65e0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1604,17 +1604,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 */ @@ -2085,8 +2075,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 Jun 25 07:34: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: 13710739 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 34B3AC30653 for ; Tue, 25 Jun 2024 07:35:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sM0i8-0004sT-OM; Tue, 25 Jun 2024 03:35:28 -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 1sM0i7-0004r7-7i for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:27 -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 1sM0i5-00042o-M9 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 03:35:26 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-424798859dfso43620855e9.0 for ; Tue, 25 Jun 2024 00:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719300924; x=1719905724; 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=dkL+F609blkCP7YhkbDtjFQ52Ff3yQ68oguPONbJIG8=; b=XhjLj5bRAIS9pow3Ewos9Vqixrh/KdJ3/zW010ce7gV05yssSWIg15Wow+eYIQj73R soQKvnhLNK9Me9MawxbuHlVfxvDbdo8Is9RzbtXEZHvdE1Wvn7ej7c8KUHVgBAksIH5L MvfrrUszAAnAf/yrS/YWKyDUNcxD9KNugFT1z6ds1aEf/yzTS94etiLaLOxkqlm9T4qg ftGD7yYzurTfQvcqGcwCRLxeERngqQqSFdMcKAtp7zpmxHh0TO8T8XTtIF4aM8iEOXj9 ATwxKmRuUUsDo9P34S5ulQHXwGMPBdSB9EjMyCBz2X4EbW8vsGHFiXBObgJs+8tG07Zz Aygg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719300924; x=1719905724; 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=dkL+F609blkCP7YhkbDtjFQ52Ff3yQ68oguPONbJIG8=; b=RWDB/HbLe+odQMZiGMWDK6w73Llr3/mYEyq+/lQKXv+gjLN0LfCeeirdtJiBIUOkE/ Ezl5cBNNG8VIHUyxINyn7bCIsDiqf5/J+6GAJlTRh/MgPcCsdgMymUBCyW2slWoQKc49 aSavk4kVkNez4okKyHH1yOtqH03oiVGSo3HCg7XjuIyPwc5Ytn1Pqo7nCLFEpP4u6eSz oiv0GiqY2LVzdppXCpcgoNVLcelRLq4Hdz67HrhGb3TRrI+AGHm0Z7dae7bJXPVSknDi zctcBRrWQSJ5fH+r2omILOk5f9Im428Wo0y7NSbZQqyXqhBpe0BNBDxTfwERuSau/fBN 1WUA== X-Gm-Message-State: AOJu0YwgpPzl/e2vtAHGUQdX6kS6I5hSCiOm4TkgQ2cj/aTjbPT5MSbv f0RPjGkn8KbHiN6+2pI4qOF0Y0ViOGjoLDO73uCt1Kg1GMx1DHra7MSxiLr/gnU4X3i/1OcpVB5 t X-Google-Smtp-Source: AGHT+IGY2ql7Ry5epaD/h9fSFRPKqIjlbP6VVZa0yJxSpdUOj45HiIiVylLL5WrJPaz6Ko5hNxu0TQ== X-Received: by 2002:a05:600c:470a:b0:421:7fb6:511e with SMTP id 5b1f17b1804b1-4248cc5931bmr43876865e9.30.1719300923941; Tue, 25 Jun 2024 00:35:23 -0700 (PDT) Received: from m1x-phil.lan (mau49-h01-176-184-41-129.dsl.sta.abo.bbox.fr. [176.184.41.129]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d208e13sm198393945e9.36.2024.06.25.00.35.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Jun 2024 00:35:23 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 7/7] hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56) Date: Tue, 25 Jun 2024 09:34:41 +0200 Message-ID: <20240625073441.34203-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625073441.34203-1-philmd@linaro.org> References: <20240625073441.34203-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 82b44b65e0..fe2210d65a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1633,14 +1633,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 56: /* CMD56: GEN_CMD */ switch (sd->state) { case sd_transfer_state: - sd->data_offset = 0; if (req.arg & 1) { return sd_cmd_to_sendingdata(sd, req, 0, sd->vendor_data, sizeof(sd->vendor_data)); } - sd->state = sd_receivingdata_state; - return sd_r1; + return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->vendor_data)); default: break; @@ -2085,9 +2083,8 @@ void sd_write_byte(SDState *sd, uint8_t value) break; case 56: /* CMD56: GEN_CMD */ - sd->vendor_data[sd->data_offset ++] = value; - if (sd->data_offset >= sizeof(sd->vendor_data)) { - sd->state = sd_transfer_state; + if (sd_generic_write_byte(sd, value)) { + memcpy(sd->vendor_data, sd->data, sizeof(sd->vendor_data)); } break;