From patchwork Tue Jun 25 06:10: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: 807260 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp2200110wrt; Mon, 24 Jun 2024 23:12:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWBeIpy23giqV3PSeTdYwOsQACsaNNLR9e6Z57n46xY7sgO15tGY0Lw58EW8Z8ueVUGM3DFqQKmjPqFuObrHgoZ X-Google-Smtp-Source: AGHT+IFdRfgQyhJfXYBCeUQdkDj18i25a7XAPoExdELmHCFNmlP1e3XXePgOiEjvAgqacM0nGswP X-Received: by 2002:ad4:4581:0:b0:6b0:6711:851e with SMTP id 6a1803df08f44-6b53635e01emr79786186d6.7.1719295934394; Mon, 24 Jun 2024 23:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719295934; cv=none; d=google.com; s=arc-20160816; b=PNkqa+BG30QHv4qrJc2qDYDbOFFFK5/fGpm/Bs1PXoUPf927Up13pNPG9ONe219wMZ HTO0yF7MGCMmtB5LnCxOCwhdguzVWAwRTorXrh/PsZe1/21usyK3Lm47S75Hwh65QmpI 0fFidVLgeV/XUPS4XJruWyE8yom//EX1wVhkZ9gBXA4FoKbwv8ZxJxqIibKYpla4rwIg yIpu7cZsneSiUQSZ4u65Ncs9exuqkkrGDxvii6l00aSighqhzAnTf29+/1lEIwnmCAWq cyLGgeUfq3itts8b3je2Nqehmjk2igj9W9T5jtXkntsHZtBUh0zChIUFaIY0KiHXVGnt Gixg== 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=WXyQ3ONsL6quYLnxVI/IWP+VnsFMKTPDSRWLpcs4CQU=; fh=/JlK2oR+rOwYm4wA2OuQV1gEZ6kNvrQcYuDHZ182k9M=; b=Ru8WDzEe70WyUKyj0xGojp121TzSy1nrXZlEyWwHk/psW5r6ePxb9PY+vvc3Kvus6x e/FbvTRo8LInV4vEA53aMkjAoDoohrQPS2HWwktcaSJd4WlMrtEib1GJGkeFWC0CFe2H LCJ7WOgjyuJ1catDYVMe1LglpIzXUryRwT7+3v/b3/nUn2W0LFafciAcx7LCEGRJAm/2 Lrr1hDt04a35Ouri0OcAdhqFkS2OGeo7Fg17eyi9sPWMk+lc7bzNM1kjXnfVom6/c2qu +Lw1aJOH2jDA24Xjvo6w2pA1Wm5fqetcuNQoTQjLhVuKjbcAILiAuxOhtyNxw8g1F8c5 13GQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OerGHbpW; 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 6a1803df08f44-6b5265bc8e6si90764786d6.454.2024.06.24.23.12.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Jun 2024 23:12:14 -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=OerGHbpW; 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 1sLzOR-0000op-Ds; Tue, 25 Jun 2024 02:11: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 1sLzOP-0000gu-5q for qemu-devel@nongnu.org; Tue, 25 Jun 2024 02:11:01 -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 1sLzOM-0005eJ-Lp for qemu-devel@nongnu.org; Tue, 25 Jun 2024 02:11:00 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4248ea53493so14996465e9.3 for ; Mon, 24 Jun 2024 23:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719295856; x=1719900656; 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=WXyQ3ONsL6quYLnxVI/IWP+VnsFMKTPDSRWLpcs4CQU=; b=OerGHbpWiNXKdkfeK2U3ADPObM4NAF5xbI+0WTHssPGw4YGD7287cB6T4CPxsBCC67 TY+Yk5mliZEvJr8jfcI63zkp5WAnohNvEMlUj3jyFRt1zUM9V3PsvLt/VLN8oHuAUDH+ dtd7nArmYrVMhcMjUKfcecKtqGg1UtDaWfWCheqIsINncFdRje1p+LJIUAU7j5WD6Vrf BUZIt8K12kQZj5elSxksl6nD6Fxd3gILvKHluLBilCQuyMqyglf0wzO4Wh0PvxDkfWtH VT2oFO/DEGOt6RE2DDt81HZa8zEDLD/QMmVLJOW7c/x9jpLKawSqmxpmC1revtJU8Nt/ 1R5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719295856; x=1719900656; 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=WXyQ3ONsL6quYLnxVI/IWP+VnsFMKTPDSRWLpcs4CQU=; b=licyLiFetNF0hA2MD0r6x2ajHpgKuW2Goi4wYY363IWfAlnCaFOrna4Z/l29snZi2V 1SxdiSZVg3v8p6m1DtiWTeBObHWO8ygvOB6t7STvf2eYCw+jrMVixwqQI2TUPo3V6B3c aiQLj03MkWT+T3fAtWzgi0/WG/ZE7zvKm5DYpc/ZBh1iqADadHxbibDnpiXswuiTp7Tb c3HQap8/pCkVin9WuPNqR0+qLtyxevPMRnOALR46B25oSkBHNvKzJ3Jacw33D5DLql3y /QMEJanqeDUy7SOUHTI4A6VKvUxyDue7kW0PtGnGD8JfhtTRzh5ZDdIoZjo/shiEfMJB w2Kg== X-Gm-Message-State: AOJu0YwWGivix9f05DCaPptA5tyz0aXzgDMOn2fePcTrJyAvXSVxCVuo N+J2CrNhDZj/UBFs7PWhupGN9MYCkKHcjDRp8L3dINOkxSvlSrWKMYh2Jh+HAKm038HpLZqL5hR U X-Received: by 2002:a05:600c:434c:b0:424:7e68:99ff with SMTP id 5b1f17b1804b1-4248cc2a78dmr50826455e9.15.1719295856204; Mon, 24 Jun 2024 23:10:56 -0700 (PDT) Received: from m1x-phil.lan (bd137-h02-176-184-46-22.dsl.sta.abo.bbox.fr. [176.184.46.22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424819224fasm163677795e9.46.2024.06.24.23.10.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 23:10:55 -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?= , qemu-block@nongnu.org, Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 06/11] hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19) Date: Tue, 25 Jun 2024 08:10:10 +0200 Message-ID: <20240625061015.24095-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240625061015.24095-1-philmd@linaro.org> References: <20240625061015.24095-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=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+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 6af7b3f034..3d341495e9 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -562,6 +562,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]; @@ -1139,14 +1154,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 */ @@ -2078,20 +2088,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 */ @@ -2120,6 +2116,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; @@ -2154,13 +2151,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 ++];