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: 809052 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp116593wru; Tue, 2 Jul 2024 02:23:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXudZdBxFxuQU3phk4vCXpfLIOFkIPu8A5/2IN+NavjDb7UlHWqT2n2eOH7cR94iUrkLveQq4oN7rT0lqG50CNM X-Google-Smtp-Source: AGHT+IEfwnU4PGIiXfdQpv85CtTy9Vkgvqd/Rp1Dx85VwbjyVSqapodzKXa7EZ45/9B6g4S0oDFZ X-Received: by 2002:a05:620a:4441:b0:79d:654b:7611 with SMTP id af79cd13be357-79d7b9ee831mr1124563185a.12.1719912191363; Tue, 02 Jul 2024 02:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719912191; cv=none; d=google.com; s=arc-20160816; b=ltx6zG9W9ZkQ0fWK6Q4H/pk1V+5fzBdDkOqeopC1MeG2qq2hVSycC4YXTu9hifQNfm je8nvzFBRFMZR7jbeMe6JExPBM4rhBUdZUBsJ6q8dtY+pQH1rJ48hBIPhok+J3SjrO11 c6gU8jv95f1uHmWF90aHsnoNijDvUL4iHHJNLLNmfpr8Ug5MntHlWp39NAhLH+llOe1U mt1DHsEJwujWXTLgHaELqbt1w/Ya3z7gM2QTf7wgcXaTE4klx6Hj3cwWUFhtFqEH+wuW IwCA3u8kz6vcarqVrjy1SmZRCkxxsdAs/tnF2OF074lHbG8bPlSWGXdqEQXD9+VjXEfd Eefg== 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=TBkJoq7dOcnQq6fmt+Em92zeZnpvlQPX8gCdahknyqk=; fh=SWrD6ZzKChsLNd0MI2/W9aN13/YqYpoy69YA//3JWDk=; b=M+Zd9MsBku9wVg6CdF0yp4PfGOXviczAIUbaA4A4YgkSx6V610BZYHQVdDR/ZXvAKG hQjiKuBLAyjlQDzn3TCFNxRhoY8/Yzt/MMViNcdE0LmZJGuPmFaeGRdufM1lulxm53K+ 9+j3t/2hhlOFnAmFG/x+yhI63G0VnEBInod5yM2Jvmt0LM2le0lQfvL+WG1rVQbEIUGt fZIFn6LSH9onY7YxtHUrKUeYUk5j0KhbTZ9SoVV9DN/VS0n7wbLK1/i7v4gdI7CVj/ib TVgQ/15p7gNmQhvNxFt2jZ7Zwqt0mXUmUqOi2UTNESSBq9heg3jJcifp1lBfIxHeiS2t qejw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kzuPDa3Z; 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-79d6933b10csi964129085a.641.2024.07.02.02.23.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2024 02:23:11 -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=kzuPDa3Z; 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 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 ++];