From patchwork Thu Jun 27 16:27: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: 807831 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp891345wrn; Thu, 27 Jun 2024 09:29:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV/BqfLXYcGJpflxhi3/tXIL7ZoB5dzP0KFAH7XE1NYBgWUqG9mCLOrr/Fz50HCdxEMNb/lsATyRX/sQbdaQkR2 X-Google-Smtp-Source: AGHT+IGoK0FLvTNJnn6ehyEyqtHarZCvWfcGSVT8qMct81QJicWcgLLQZ8z4tE5TWL+7E9n4eClX X-Received: by 2002:a9d:744e:0:b0:700:b1aa:bea6 with SMTP id 46e09a7af769-700b1aabf46mr14899957a34.23.1719505743648; Thu, 27 Jun 2024 09:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719505743; cv=none; d=google.com; s=arc-20160816; b=MVhtJBL32EcCk5uqXwu+as33Ib8eNsnbS1lVojX5yE7wW7FoM/novuCA7pFvGfxQFi KidXQnwctMI2SiBXHqMTPQ04I0aXwT/tiuSnxj469avXd726cT60XZ0uOyxooY/YoCbi 7aoZR8AkhOH9eNIpzSUC6ULR5Ms6syvOZh3ZgGgiuiEMbZfuql08UMNFEH8U9uA/iE9U 5n+DIA6ZNyXW51ScXLoLGmURDXNXFyQTujnBLOgAnUoI4GBUkDvKF7X7+COAeHmktTq8 RYFHcYXIsKy7gzYjSH5j8ZNtsTvwVT8VsbhojNxcY6E4bcCb+MERhV6GIHoTX8seR0OW AmPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xyhvw/6qmXFus9eORwXzq1Iu5gU3BghWHGLoDUVW4O4=; fh=CQ9QAhiPZZ1APu1JLxgbtxAnzrroUJn9RCDrjAjVXrk=; b=mCRF4kV1YGv+iT6ttaa1G/AIgP8FXmLAG4DabUedojBUyk4sDniehu0Xx0ttWqzSaS Se6e3Gw0f7G+hRZU4H9SLymMCjITqwbyML3o4sr/HyFbPcnyJekf2KDmu7XRJMuXLx0G eG4xgOMdJe7FFlHXvzQx8nNdILv6fMarohoQ83cog8BfKGL6u/I4YZ2tlZYf8PLzzbjn 3KhEENTbhjtSSX5BA60+bW+HSoYMCJJPrmUdG5BssEruktmSZXSHgdGY4ySKfH335S/A fh5Na0487IsibKoq0gy3ai8aYh3gzyBkG3GelqcdxKriPJY8yCQy5fMObdsvAIBL7p/R SFNw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G7uzp2qr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-79d5c789d96si164892085a.12.2024.06.27.09.29.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:29:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G7uzp2qr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMrzI-0002lX-R5; Thu, 27 Jun 2024 12:28:45 -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 1sMrzD-0002fK-2J for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:28:39 -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 1sMrzB-0003UK-BL for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:28:38 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4248ff53f04so35300975e9.0 for ; Thu, 27 Jun 2024 09:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719505715; x=1720110515; 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=Xyhvw/6qmXFus9eORwXzq1Iu5gU3BghWHGLoDUVW4O4=; b=G7uzp2qrNIcGqlouSW4SF+VIDuGX6y1EmnUeCs3txzGzI2//5IRpo67FvokbnB0Fs8 6NxCybFLaT/4R0rXbv2ZBo45E0GF1UrKcQtosQ8DKGQZw2rmtsnJ07QwBIEQFv/2jyb5 mtZEmNmUgsi/E+WJvboTV/+bdjGrUzeGdDssc7OWGVLkioTGQedmRZfmiOO+m6RxrBfR UllzfeIr482v3SSEdCrSNzhrhm2ee2ALsA62yzpXqkqKBgdrA7z7QZVOnujo52mo1O86 KQC2HK5UTpNmMMIdciIjWDXbNUmB0iA2UDTDdb0VEKPuuR/hDnIuIbcT9GtAzTOYKSUl 1ltw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719505715; x=1720110515; 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=Xyhvw/6qmXFus9eORwXzq1Iu5gU3BghWHGLoDUVW4O4=; b=M39DxUq9ufK4J/qJWo6ID3BIX3hqOC4VARmKy1tpH2RAT+vsGRR148H1OdHL4c0L68 2W9bMfaX0vdtofKVS6RbJ0j9ta2Q5cehIIa8hCv5VeBgBxBXlGfbTAuODs4yOCeQzW75 jBAy8xmPDzAgJhaZKU5U9PkzcQHGqTr3Zlrqj5yIeA57N2N5YOBD/XefM/fVrza0/0wQ YkDNF52ppiJJbPslM7UIzdtOiimoAAV+y/L67XOia6xggyS8ET8TSrG6FZas+d3bEYUB Yyz9qr35yRUUTOQYaznTrZtFz6g/F4tDP3l+3jvykFlFxXMmCj6VBGkSoQgzaJMH9x5s m/zA== X-Gm-Message-State: AOJu0Yyi5DVSIJBmVX7gGc8NhG3lnP3zYsynJEutQuOdf/QkVSfNxYXS 1QwGkc1zIo2LNWTJsq1PFH2NiTj5GGtMnZa3cboo9YbQkR8Du/A6W4tS1QO+6QvWQCa1vX/K+T/ V2xE= X-Received: by 2002:a05:600c:25a:b0:425:6001:6637 with SMTP id 5b1f17b1804b1-4256001679fmr30535685e9.1.1719505715590; Thu, 27 Jun 2024 09:28:35 -0700 (PDT) Received: from localhost.localdomain (33.red-95-127-46.staticip.rima-tde.net. [95.127.46.33]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424c8246828sm76479825e9.5.2024.06.27.09.28.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:28:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Francisco Iglesias , Bin Meng , Sai Pavan Boddu , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Luc Michel Subject: [PATCH v2 06/11] hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19) Date: Thu, 27 Jun 2024 18:27:24 +0200 Message-ID: <20240627162729.80909-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627162729.80909-1-philmd@linaro.org> References: <20240627162729.80909-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- 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 605269163d..eece33194a 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -568,6 +568,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]; @@ -1161,14 +1176,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 */ @@ -2100,20 +2110,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 */ @@ -2142,6 +2138,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; @@ -2176,13 +2173,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 ++];