From patchwork Fri Jun 28 07:00:47 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: 808169 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp222901wrr; Fri, 28 Jun 2024 00:07:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVD3JtV4D5LNjkDD4bWLS3YjKLZim9/qnX/ZjUQhT3XWFdfkZXtKmuT3Orf/bbBApq6CTahw9dhKSqYRxWvM/QT X-Google-Smtp-Source: AGHT+IFu3Fvr3aD7Ny8y1YlOPMr4coW59Jnq+fn98R1YoUg9f9L8V6O3vjkqohV9JW3QpE3uRFBj X-Received: by 2002:a05:620a:430d:b0:798:1dd6:b6f6 with SMTP id af79cd13be357-79be7047736mr1392040485a.76.1719558443951; Fri, 28 Jun 2024 00:07:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719558443; cv=none; d=google.com; s=arc-20160816; b=t8tbGsg4/qb9DJqoJmC/Q3VB8q02iMN/u1AJh2/HAgscmxMPTK9SHSW9fXYt8B5Bu/ CWZDFRgjcwV5YlDKmaF1DeC3COmYEgBjfWAa2iBoT/R+cM6Gjy5ixHBKovvwSZRVQqxF 4a8soq0hn8kRkmb6V6H6YEyiObnGqkEh1LpuCS9pMBqf/RatMqg+iovCZO4WzYIO/6pr 8MopceJhnMJMrQTX11/KWA1u31QdR8qYdbKHoIB6h4tu6ymp0bg6Aat8sU2LjyxoQPLX TYiIl4h1KGY6cScD2LIl+VhhA5zW0YsTJ3x1J/He7Yw8/Qgyj0JxAu3oWW1TAh3T+bx8 g98w== 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:to:from :dkim-signature; bh=wrQTXcopwoxdy2+QKjolzASBZvpHRSjsIoJ+STiyvF8=; fh=Vqz0ILX7NeXJwCG5xiS+Wtk94IhOmAmLtOfN3kRbil4=; b=AV6pE1mw8fXxtsSuLDhEjOYhHfUFP/pyIK6Q+FSQzqBS9vyS+eFvsq00jBbldhwr4A fegsees3AyPXtSHIRkK+mlJkbFFGVwiR0VJCiYdyfXV3iNA/P3qvxVpzU6ednPk/dGNW jYmAsSAfG9eGvJ41QN/7+1kFEmzH1QZy2DDMxZTsL7wfB1/VlqrGBCyPB3yjSzb759Se NOcK3dbNnr6REuFc7YD0lgY5Mf/BfMqeeIWSZNeCJYQd1OXZMEhwb3phYdnfVmIx/8VB ruWA/EaXGLRebDyCygwSk3OU6nvr89yrBQDTu1EdsalsN/dsiSKurSC3QT6G/F1LBHHV IIsg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LoB9XCW+; 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-79d69262d1asi131101085a.5.2024.06.28.00.07.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Jun 2024 00:07:23 -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=LoB9XCW+; 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 1sN5e6-0000qP-Vh; Fri, 28 Jun 2024 03:03:49 -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 1sN5dj-0000Ld-CE for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:03:23 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN5df-0006jG-Vj for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:03:22 -0400 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2ec50a5e230so2316481fa.0 for ; Fri, 28 Jun 2024 00:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719558197; x=1720162997; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wrQTXcopwoxdy2+QKjolzASBZvpHRSjsIoJ+STiyvF8=; b=LoB9XCW+JhMGw7rC3LBCM7D8Csjqx7yuWLihE/466MM6cpUtt+a4SfezSMy8SreN5v iVsuEDZ+Cv3yWgEoW9fltFB4OxqIJsfZCS7TSNKV0TvIDSWo4/47c0B7WJkIx+KAfyvh w2hstY35HD0AMXvw3yslJpnGL72UAOU7F6a/yiHBBzf4bD8CKeum+qWKvfB3DxwD3azN VUSDUbte7YqlqZ8bWbLPO5utx5EAYooDhRNrNL3j8gDAmjPXfpRVlaEyYTTDA+HwyrYT v9rXFVsuJeIyBDZn+vm2iR/ZYSX8hvWqni1jqTH9SA1r+ShOJjALbnWzPPRpKuWVl74e jGwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719558197; x=1720162997; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wrQTXcopwoxdy2+QKjolzASBZvpHRSjsIoJ+STiyvF8=; b=EEAsUj87pV/ADNHTA1eu/oxQNJrhmmJa8AxGinjmkiiq1K8z0wSf7JBFuXIh4gmPTE cHZQhisXutSS9bEmAzX3l1DlCC49nwBYPoiuJUzsKIPDwmgEkuhwNfD+o6+LDQX9q0VG kv7kMZdyL3C2xVy4eC1oSf20AjOdoUKfzMhU56kjxqSk32DuIiNnkaoU1zSuNggn0K1W GHNXlXsAOnQ1VY9NczIRmYQKg9pgoSFERaprQWoetwgrPqXVLz09Pk4Cr/ubVgo/kRKr xzmX6TrEdpKC+cdMswUn0tb0B4uYceJ3EQefHVwGXxOD0kTK+/TmmOyn9S3VPjmqukFT nfLQ== X-Gm-Message-State: AOJu0YyE6nNYjY5hkTm6ygNOeechf2Q3Aokq0AvUzp+dRfhPMVGkJpUZ oXx8KdCzC33caT3dwPAzOUSFxqqmfNCAI7cNmdUuDDBP0p+0YfcaVknBOsBmhg6I0SBTUkgBODx bhS8= X-Received: by 2002:a2e:8242:0:b0:2ec:50ed:b59f with SMTP id 38308e7fff4ca-2ec5b2dd950mr90208531fa.34.1719558197248; Fri, 28 Jun 2024 00:03:17 -0700 (PDT) Received: from m1x-phil.lan (cho94-h02-176-184-4-239.dsl.sta.abo.bbox.fr. [176.184.4.239]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b0c0fb3sm21184995e9.40.2024.06.28.00.03.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 00:03:16 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH v42 11/98] hw/sd/sdcard: Simplify sd_inactive_state handling Date: Fri, 28 Jun 2024 09:00:47 +0200 Message-ID: <20240628070216.92609-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240628070216.92609-1-philmd@linaro.org> References: <20240628070216.92609-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::234; envelope-from=philmd@linaro.org; helo=mail-lj1-x234.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 Card entering sd_inactive_state powers off, and won't respond anymore. Handle that once when entering sd_do_command(). Remove condition always true in sd_cmd_GO_IDLE_STATE(). Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater --- hw/sd/sd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index fbdfafa3a6..7533a78cf6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1081,10 +1081,8 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) /* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) { - if (sd->state != sd_inactive_state) { - sd->state = sd_idle_state; - sd_reset(DEVICE(sd)); - } + sd->state = sd_idle_state; + sd_reset(DEVICE(sd)); return sd_is_spi(sd) ? sd_r1 : sd_r0; } @@ -1579,7 +1577,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) switch (sd->state) { case sd_ready_state: case sd_identification_state: - case sd_inactive_state: return sd_illegal; case sd_idle_state: if (rca) { @@ -1800,6 +1797,11 @@ int sd_do_command(SDState *sd, SDRequest *req, return 0; } + if (sd->state == sd_inactive_state) { + rtype = sd_illegal; + goto send_response; + } + if (sd_req_crc_validate(req)) { sd->card_status |= COM_CRC_ERROR; rtype = sd_illegal;