From patchwork Thu Jun 27 16:43: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: 807859 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp898753wrn; Thu, 27 Jun 2024 09:44:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXXJhW/os4XyzlqOyUU1aiRS/m3a022fPwoPANJVyPwKPO7N0sJxRDTeFRdiuJMAZRNIuEO9QAyU4DJ7XNF0tFx X-Google-Smtp-Source: AGHT+IEoE/V4Dsdh4DuhEknCGwH3D48shYBt0ryKwZ7UJs/Ul8sPVugxz3X4j4gYpSsKePkueuiz X-Received: by 2002:a05:6808:151f:b0:3d5:64f3:df63 with SMTP id 5614622812f47-3d564f3fae2mr5072094b6e.17.1719506683963; Thu, 27 Jun 2024 09:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719506683; cv=none; d=google.com; s=arc-20160816; b=j3X0/5Cxr+R5LqCP9DKI+RTtN4C2d3txpxQDi+Z4dOW85Qu30MfoL6yGZXxX6gwq4F HcbWNqEcQCeTvDbadCpsEyK2j/9EkEnqYrzjk3KISOh3STE9up9gDpWugEWLHAbjxCdq Jiac1gXm4wK38jRNw1Ek33oOd8xSnCdcIIca5doi0+iVPSCRWXu7jZB5Uk9E+HORSn5M q030eJlr4wNeRt8ObY9OsCjJg+d6c5NB/D06lBw4ZhPmoULwMjEjl3D9k3ii26ZsBGwL TspA/AXoTIJX6i7Yg+Rkl3yYUUOge+azcb1VNayE9NcnknZv3RA1pWatP4EUHjo897JV MpCA== 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=Jc7tRSVNH3DRf6qJ+0mDK79EZ4kJyviqTLrANC5etLY=; fh=v4x9Oqm5dSIIGNwhX3iTRsusFrFNP2dDaR6uZLPgHBY=; b=FuEWWOWgGOYYuwxIox0eADsLLchUgMpJXLMWqwAWx5js2q/arW/+AuPH09Frv5mtSJ SWgXgOESbxh6Y5UFtwWdoLTgRghqLY0FHJDmvBbRcaX5PT4lD6Ld36a881KJfpF0kObX 0bUTOejmfmk8Ejed/5mIGz0vxAsZgKRyGgxcOin00k/DPduJopYdgvCxi5FhQcwaiVuP jmMqhlQmVABMRKIwdLvMlBIR6qocnQBtg9v8r3YPxtoKmtoJWLdalTmgDQHo4RGJf7Hi pff8wdePw8OjdCuHfLh+v0KnCaDXQ04bXAA96KO/xShrncGdtdnJoAOOGR+B+Qbexbjq WDGQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DeROVQRI; 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 d75a77b69052e-4464205f6f5si16117621cf.447.2024.06.27.09.44.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Jun 2024 09:44:43 -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=DeROVQRI; 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 1sMsEQ-0001GZ-Op; Thu, 27 Jun 2024 12:44:22 -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 1sMsEJ-0001Ba-KO for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:44:17 -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 1sMsEH-000897-5I for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:44:14 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-364cdfdaf91so5711219f8f.1 for ; Thu, 27 Jun 2024 09:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506651; x=1720111451; 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=Jc7tRSVNH3DRf6qJ+0mDK79EZ4kJyviqTLrANC5etLY=; b=DeROVQRInWWHS2lugoLkHBgCEcdo8VxLNzIP8fbcUBHGX0mZn8n0MklV5MC952HFxf 23WziK6PVoht1PtNshCyEAweQ5fELKIMySn9O0KBe71MOxTSpZxQx+kh9OuGnMkXEA7u 5VLyBEGXah8lolFvcSkzxF7jo7hPh9ZiMmnLDBUn9smwpwG6lUOH6B15+3im7IfhH8s2 mygtQEMg3WE7XtyNzKu0DcqjYXCMAdN41x8jsHzrXxXfFrlJdeR2b3CtPIyB+dSoLrWp xb/62Cs7pQa7nlENS8CCjKKvS2efLqu07W65VTg6bNbPCM/Nz+UK1He5mQd+l4fKcExn XqQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506651; x=1720111451; 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=Jc7tRSVNH3DRf6qJ+0mDK79EZ4kJyviqTLrANC5etLY=; b=QQa2rIc6Ynd8qYza7gdspEw4RxCtBjZ8D1k0YxCg15V7tABeFV7tDCSQYDp8dMUKd6 IjgUFKjeYjyiBdcRFTQ0iiLo5o9RFpyvV38Etap/RLHnCT48v3Tz6y9Fsk2fS8lI/xFt ZFj1xtv37mt6oeW5V3e2HDGOohuAiigDN604x7ys5eG+d9BXo84e/FBHoNX1n4v9OiPS q5v9ieXJn6+jfIccmkMeOjqd4eJbPmOEspob6IQgME/yO53azzPiqEAkIrsXRlcMIHD1 Ep4jCYTSs95JgBa8SB47WWU0Yr0UzPcN0ewaABrHHaeh7dbfpS84loAYRjjIAKK3CvOS Y0iQ== X-Gm-Message-State: AOJu0YzpgWYlCq8AFx1kjEd5XpVgyFR1yaP0KIsGY8r9kU13lsNgGiDM sMEWtQvPvzVOmh01xKqmVHYwRLshw/tGdaVs7zptLMTAhPKEXxl/UH2oKCR52OX8UlFca2cLPMi YFjQ= X-Received: by 2002:a05:6000:1448:b0:367:4e05:bb7b with SMTP id ffacd0b85a97d-3674e05bca5mr1734006f8f.53.1719506651290; Thu, 27 Jun 2024 09:44:11 -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 ffacd0b85a97d-36743699ae0sm2370485f8f.66.2024.06.27.09.44.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:44:10 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Sai Pavan Boddu , Francisco Iglesias , Joel Stanley , Luc Michel , =?utf-8?q?P?= =?utf-8?q?hilippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Bin Meng Subject: [PATCH 02/21] hw/sd/sdcard: Add sd_cmd_DE/SELECT_CARD handler (CMD7) Date: Thu, 27 Jun 2024 18:43:25 +0200 Message-ID: <20240627164345.82192-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627164345.82192-1-philmd@linaro.org> References: <20240627164345.82192-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- 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 61c9aff2fb..6ad98db981 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -240,7 +240,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", @@ -558,6 +557,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) @@ -1258,6 +1262,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) { @@ -1324,43 +1369,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; @@ -2293,6 +2301,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},