From nobody Mon Nov 25 03:58:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719506684; cv=none; d=zohomail.com; s=zohoarc; b=JOPv3gDE+es30lXJwc1CGCiltQqQ0JXOz1xZyLwkf8f5zltNX166cAsDfHGSxCLTyZhpIHOBVmNkP2TmrTp3USBdM2JmxLvmFJX4/+VbfLSVrhOtkjXVwEBPx8oSEXQoH3Of4lAeUIKkvMLyIp71+8AfHGVloFAdJGxpglomYA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719506684; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Jc7tRSVNH3DRf6qJ+0mDK79EZ4kJyviqTLrANC5etLY=; b=ar297kFDwJ/u9YMfd7F2eHA/HwZc7FFMg6dEqxd6cCeCez90c+K7YQqgDOB9cqOArHpb6hQW+07oxGjwGYGBxt8BCCdwyW7yXN5IO2+2qySWehgUfh3+EIb6qiqgNF+byUVU2Joxmcuz9PMxGKwacudC68Dsjo6dSTNndsvRQcE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719506684298920.1954213664937; Thu, 27 Jun 2024 09:44:44 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: AGHT+IGQD55REmzYWv+7IymkGTRx1MyLJbRyZ39xNnWJwQDmwHylYsF13ycPguaANLllCA0d9gjD8g== 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) From: =?UTF-8?q?Philippe=20Mathieu-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?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1719506684630100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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] =3D { - [7] =3D "SELECT/DESELECT_C= ARD", [8] =3D "SEND_IF_COND", [9] =3D "SEND_CSD", [10] =3D "SEND_CID", [12] =3D "STOP_TRANSMISSION", [13] =3D "SEND_STATUS", @@ -558,6 +557,11 @@ static uint16_t sd_req_get_rca(SDState *s, SDRequest r= eq) } } =20 +static bool sd_req_rca_same(SDState *s, SDRequest req) +{ + return sd_req_get_rca(s, req) =3D=3D s->rca; +} + /* Card Status register */ =20 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); } =20 +/* CMD7 */ +static sd_rsp_type_t sd_cmd_DE_SELECT_CARD(SDState *sd, SDRequest req) +{ + bool same_rca =3D sd_req_rca_same(sd, req); + + switch (sd->state) { + case sd_standby_state: + if (!same_rca) { + return sd_r0; + } + sd->state =3D sd_transfer_state; + return sd_r1b; + + case sd_transfer_state: + case sd_sendingdata_state: + if (same_rca) { + break; + } + sd->state =3D sd_standby_state; + return sd_r1b; + + case sd_disconnect_state: + if (!same_rca) { + return sd_r0; + } + sd->state =3D sd_programming_state; + return sd_r1b; + + case sd_programming_state: + if (same_rca) { + break; + } + sd->state =3D 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) =20 switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ - case 7: /* CMD7: SELECT/DESELECT_CARD */ - rca =3D sd_req_get_rca(sd, req); - switch (sd->state) { - case sd_standby_state: - if (sd->rca !=3D rca) - return sd_r0; - - sd->state =3D sd_transfer_state; - return sd_r1b; - - case sd_transfer_state: - case sd_sendingdata_state: - if (sd->rca =3D=3D rca) - break; - - sd->state =3D sd_standby_state; - return sd_r1b; - - case sd_disconnect_state: - if (sd->rca !=3D rca) - return sd_r0; - - sd->state =3D sd_programming_state; - return sd_r1b; - - case sd_programming_state: - if (sd->rca =3D=3D rca) - break; - - sd->state =3D 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 =3D { [4] =3D {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] =3D {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [6] =3D {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, + [7] =3D {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [11] =3D {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] =3D {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLO= CK}, [20] =3D {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, --=20 2.41.0