From nobody Mon Nov 25 04:46:48 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=1718957322; cv=none; d=zohomail.com; s=zohoarc; b=AY1d6voHp/2xVAwSsl0lDih8oY80IY+6NHunulQw3Wzq3Gk/xC6Si1eR2oRb3Flgi2mVKLRkj9V/ud7gyfxsjsB2Y7tzE3tW/vGUi2JOMwnfqNpOHbIPoxKng8UMlQ5Szo64R5BLIH7B419xKttFBIiTGsvRFKLXUtf+GpL4Mu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718957322; 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=SZVdw7g4FFY2EyPpj/GEhmJmZqJuSFbYAj+AqUiDdB4=; b=Dk5f8OUI+jemE4cXRn+YbToREypuDmid+MqFL3nZXvLyEA9DxNsV066iUNtrneMCWj261Yl5s2K2njZG67ZZtWfHRrp27L/0BzZ7aHCWMinKtdfpusW6UCozFSW2twv7cj9iTGwgEpMMmwan5FUW/V3wYjPMPCMwiZUfjcIW/Os= 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 1718957322130172.7396270414854; Fri, 21 Jun 2024 01:08:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKZJH-0000r5-Sk; Fri, 21 Jun 2024 04:07:52 -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 1sKZJF-0000iH-Ac for qemu-devel@nongnu.org; Fri, 21 Jun 2024 04:07:49 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKZJD-00007E-PP for qemu-devel@nongnu.org; Fri, 21 Jun 2024 04:07:49 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4218180a122so12903105e9.1 for ; Fri, 21 Jun 2024 01:07:47 -0700 (PDT) Received: from m1x-phil.lan ([176.176.128.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36638d9c158sm977420f8f.56.2024.06.21.01.07.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 21 Jun 2024 01:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718957266; x=1719562066; 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=SZVdw7g4FFY2EyPpj/GEhmJmZqJuSFbYAj+AqUiDdB4=; b=ThyGybpkX6USi5XO9h/o3RA9MADSAZd2ZkiNEQB3/if2BMuWtkRt/cz6oTf/7GDuvh idk2jRYd7J384BNqB6sEXJxdpopYCufPk0C8wLq7EXtDe1GvVXw/3H5jGljCGaGCo96x tj9fE2OA9ntLW/oiC2fTL5v5mV7tmoup2EGiCLYu7pVYMrlwo1CwQt45NwAeqT6WpvjT Nt7RDvCqm+k+p0L+EBXaNdhWalIq602mGkZ8q37JyfTwF5vbe4UODQHa1LCCXnMq+g2y YIQFLJ4Ji4xOa5ikWQSXWTauojChSKiRNNHW3E+DWgc0Zk5riLjoHV87As44ZtawWC+z 1xEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718957266; x=1719562066; 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=SZVdw7g4FFY2EyPpj/GEhmJmZqJuSFbYAj+AqUiDdB4=; b=I0KEEQ5ZGykww3uG6Jze3p4F96toCjs49YTHCgCAI3W6PwwMXzwzocTT7OujYK7CL6 RjjCpeJH6n4Yd+QuMPd1N6+SrW64nK3oQ6R0TZ11Hap9z5Jg3Rl4QESaDJGjyDtoskFU JW9/idgOTkfX+HURlFWGgRuZLb6JLSPZlDApnL74T32isn5nBlkkeLLt77ev0HcLoIed UkgvcHgHiKewNXVEoumV5xUdNHyOK87sW9G9IrYJNygi5VAJQGIdGDLwE1H39NW9Y9wl YZX+fpqSfFf7sfF5eFbooLgZ/2qx6TAktQoIZANsf5VB/5/g/39HgihrRuuwQ5lc40MZ HJGg== X-Gm-Message-State: AOJu0YzxsqFttmPSGMKbDncuhXSLw2yb4d9boz4LjJD/GFiWmiWLasgP GYopGeoNhCK1+mMEvR9H1rpHXxds26TfHG1Cbo0+LlnMvyhRTkEMF2FEhZmAjfqG+ku6an7YOup z X-Google-Smtp-Source: AGHT+IHhVh1/7gwxlIA1WJjOQSjlj/YTHTc0qn/ahDv3YxqFUhtRDOs82oiAy2kjym8Z5BhM3g+MCA== X-Received: by 2002:adf:f6c5:0:b0:360:93d4:c4e0 with SMTP id ffacd0b85a97d-363171e1995mr6478167f8f.5.1718957265914; Fri, 21 Jun 2024 01:07:45 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Joel Stanley , Bin Meng , Sai Pavan Boddu , qemu-block@nongnu.org Subject: [PATCH 18/23] hw/sd/sdcard: Add sd_invalid_mode_for_cmd to report invalid mode switch Date: Fri, 21 Jun 2024 10:05:49 +0200 Message-ID: <20240621080554.18986-19-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240621080554.18986-1-philmd@linaro.org> References: <20240621080554.18986-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::332; envelope-from=philmd@linaro.org; helo=mail-wm1-x332.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1718957322636100011 Having the mode switch displayed help to track incomplete command implementations. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater --- hw/sd/sd.c | 75 +++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 1df16ce6a2..8d63a39a54 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -180,6 +180,17 @@ static const char *sd_version_str(enum SDPhySpecificat= ionVersion version) return sdphy_version[version]; } =20 +static const char *sd_mode_name(enum SDCardModes mode) +{ + static const char *mode_name[] =3D { + [sd_inactive] =3D "inactive", + [sd_card_identification_mode] =3D "identification", + [sd_data_transfer_mode] =3D "transfer", + }; + assert(mode < ARRAY_SIZE(mode_name)); + return mode_name[mode]; +} + static const char *sd_state_name(enum SDCardStates state) { static const char *state_name[] =3D { @@ -1015,6 +1026,15 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDStat= e *sd, SDRequest req) return sd_illegal; } =20 +static sd_rsp_type_t sd_invalid_mode_for_cmd(SDState *sd, SDRequest req) +{ + qemu_log_mask(LOG_GUEST_ERROR, "%s: CMD%i in a wrong mode: %s (spec %s= )\n", + sd_proto(sd)->name, req.cmd, sd_mode_name(sd->mode), + sd_version_str(sd->spec_version)); + + return sd_illegal; +} + static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) { qemu_log_mask(LOG_GUEST_ERROR, "%s: Unknown CMD%i for spec %s\n", @@ -1154,18 +1174,14 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) break; =20 case 6: /* CMD6: SWITCH_FUNCTION */ - switch (sd->mode) { - case sd_data_transfer_mode: - sd_function_switch(sd, req.arg); - sd->state =3D sd_sendingdata_state; - sd->data_start =3D 0; - sd->data_offset =3D 0; - return sd_r1; - - default: - break; + if (sd->mode !=3D sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + sd_function_switch(sd, req.arg); + sd->state =3D sd_sendingdata_state; + sd->data_start =3D 0; + sd->data_offset =3D 0; + return sd_r1; =20 case 7: /* CMD7: SELECT/DESELECT_CARD */ rca =3D sd_req_get_rca(sd, req); @@ -1289,33 +1305,24 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) =20 case 13: /* CMD13: SEND_STATUS */ rca =3D sd_req_get_rca(sd, req); - switch (sd->mode) { - case sd_data_transfer_mode: - if (!sd_is_spi(sd) && sd->rca !=3D rca) { - return sd_r0; - } - - return sd_r1; - - default: - break; + if (sd->mode !=3D sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + if (!sd_is_spi(sd) && sd->rca !=3D rca) { + return sd_r0; + } + + return sd_r1; =20 case 15: /* CMD15: GO_INACTIVE_STATE */ - rca =3D sd_req_get_rca(sd, req); - switch (sd->mode) { - case sd_data_transfer_mode: - if (sd->rca !=3D rca) - return sd_r0; - - sd->state =3D sd_inactive_state; - return sd_r0; - - default: - break; + if (sd->mode !=3D sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + rca =3D sd_req_get_rca(sd, req); + if (sd->rca =3D=3D rca) { + sd->state =3D sd_inactive_state; + } + return sd_r0; =20 /* Block read commands (Class 2) */ case 16: /* CMD16: SET_BLOCKLEN */ --=20 2.41.0